$ show yogthos/chiasmus
Chiasmus is a neurosymbolic verification engine packaged as a TypeScript library and Model Context Protocol (MCP) server. It bridges LLMs with formal solvers — Z3 (SMT) and SWI-Prolog (WASM) — by translating natural-language problems into template-based formal specifications that are verified with mathematical certainty. It also performs static code analysis: tree-sitter-based extraction of call graphs for TypeScript/JavaScript, Python, Go, Rust, Clojure, Scheme, Racket, and Common Lisp, followed by 16 analyses (reachability, dead code, impact, cycles, layer violations, community detection, hubs, bridges, diffs). Architecturally, the repo is a modular ESM library with an MCP server entry point (src/mcp-server.ts) exposing 11 tools over stdio (chiasmus_graph, chiasmus_map, chiasmus_formalize, chiasmus_verify, chiasmus_search, chiasmus_review, chiasmus_learn, etc.). Core subsystems: graph extraction with per-file content-hash caching and snapshot diffing; a formalization engine that selects from 8 built-in skill templates via BM25/embedding retrieval and runs an LLM-driven correction loop against the solvers; a SQLite-backed skill library that learns new templates from verified solutions; and pluggable LLM adapters (Anthropic, OpenAI-compatible, Azure, local via node-llama-cpp). Data flows: source files are parsed by tree-sitter into a CodeGraph, which can be emitted as Prolog facts for symbolic queries or analyzed natively with O(V+E) algorithms (Tarjan SCC, BFS). For verification, a problem statement is embedded, matched to a template, slot-filled by an LLM, linted, and iteratively corrected until the Z3/Prolog solver confirms the property or finds a counterexample. The benchmark suite compares Chiasmus against traditional implementations across RBAC, dependency resolution, taint analysis, workflow validation, and validation consistency. Maintenance is active (v0.1.28, CI on Node 22/24, 70+ test files covering graph extraction, solvers, MCP tools, search, and skills). The codebase is well-engineered with several genuinely reusable components — native graph algorithms, an LRU extraction cache, a BM25 index, and a tsconfig alias resolver — though some coupling exists between the extractor and the TypeScript type environment, and the vendored WASM grammars require periodic upstream syncs.
The LLM identified 5 files worth highlighting for reuse:
O(V+E) native implementations of Tarjan's strongly-connected components, BFS reachability/path, impact, and dead-code analysis, deliberately replacing slower Prolog rules that timed out on mid-size codebases. Self-contained graph algorithms that can be extracted into any code-analysis or dependency-analysis tool.
Per-file extraction cache keyed by SHA-256 content hash with LRU eviction, per-file cost tracking, schema versioning, and named snapshots for graph diffing. Uses proper-lockfile for concurrency safety. A reusable caching pattern for any tree-sitter-based analysis pipeline.
Lightweight incremental BM25 full-text ranking index used for template retrieval, with an addToIndex API for incremental updates. Standalone and dependency-free, it can be extracted into any retrieval or search-ranking task.
Resolves TypeScript path aliases following tsconfig extends chains, handling both glob and exact aliases. Solves a recurring problem for any TS tooling that needs import resolution without a bundler.
Generic iterative correction loop that wraps any solver (Z3 or Prolog) with LLM-based spec fixing, converging when the property passes or max rounds are exceeded. A reusable pattern for neurosymbolic systems that need LLM-generated formal specs repaired against solver feedback.