Skip to content

About

Offline repository knowledge compiler in Rust: builds a deterministic, evidence-backed semantic graph of a codebase (tree-sitter parsing, 29 relation kinds, Cypher-like queries), generates a C4-oriented Markdown wiki and ADR store, and exposes it all to agents over MCP.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Lithograph

Pre-alpha. Version 0.1.0, not published to crates.io, no releases and no stability guarantees. CLI flags, MCP tool shapes, and on-disk formats (graph snapshot, manifest, caches, indexes) all change without notice. The graph snapshot carries a schema version and a migration hook, but only v1 has ever existed and no data migrations are written yet — expect to re-run init from scratch after upgrading. Everything documented below is implemented and covered by tests.

Lithograph turns a source tree into a queryable knowledge base: a typed semantic graph, evidence-backed architecture documentation, and a set of deterministic tools for search, drift detection, and agent integration — all running locally, offline by default, with no code ever leaving your machine unless you explicitly configure a model.

Point it at a repository and init produces a durable graph, a C4-oriented Markdown wiki under docs/lithograph/, and a store of architecture decision records — then update keeps all of it current as the repository changes, regenerating only what actually went stale.

Why Lithograph

  • Deterministic by default. Without a model API key, init/update run on a built-in mock model — scans, graph construction, caching, tests, and every inspection command are fully offline and reproducible. Point Lithograph at DeepInfra or any OpenAI-compatible endpoint and the same manifest, graph, evidence, and validation flow runs against a real model instead.
  • Evidence-backed, not hallucinated. Every generated page and answer is tied to source evidence; architecture layer detection and confidence scoring report Low/Unknown rather than guessing when there isn't real signal.
  • A real graph, not a text index. 36 typed relation kinds (calls, imports, inheritance, type references, data flow, cross-service protocol edges, near-clone similarity, and more) and a Cypher-like query subset over a deterministic, versioned graph snapshot.
  • Built for agents. 45 MCP tools cover graph queries, four search modes, tag/taxonomy lookups, trace/impact analysis, dead-code detection, drift detection, ADR CRUD, and subsystem doc generation — wired into Codex, Claude, Gemini, and Zed via integrate-mcp.

What It Produces

Running lithograph init <repo> creates:

  • docs/lithograph/*.md: a C4-oriented wiki — overview, quickstart, architecture, workflows, boundaries, configuration, database, key modules, and an ADR-and-drift page, plus a modules/ tree with per-module pages grouped by kind (directories, configuration, documentation, infrastructure, language packages/crates).
  • .lithograph/graph/current.json: the deterministic semantic graph as a versioned snapshot envelope (compact JSON, used for loading, migration, and portable graph artifact exports). Graphs written before this snapshot existed used a flat .lithograph/graph.json, which load still reads as a fallback.
  • .lithograph/manifest.json: page/task manifest with dependencies, evidence, prompt versions, context schema versions, input hashes, and output hashes.
  • .lithograph/research/*.json: deterministic research summaries backing repository-level pages.
  • .lithograph/adrs/*.json: architecture decision records, one file per record, managed through the adr command or MCP tools.
  • .lithograph/run.json / .lithograph/snapshot.json: run metadata and incremental-change state.
  • .lithograph/cache/analysis/: content-addressed analysis cache backing incremental update runs.
  • .lithograph/derived/code-search.json and .lithograph/fts-index.json: incrementally maintained code-chunk and full-text search indexes.
  • .lithograph/layout/: cached graph layouts served by serve.
  • .lithograph/subsystem-docs/ and .lithograph/graph-document.json: deterministic subsystem and graph documents written by the MCP tools.

Generated docs and .lithograph/ state are excluded from later scans so a second run never documents its own output.

Language Coverage

Lithograph parses with tree-sitter and resolves with per-language hybrid resolvers, at three honestly-reported tiers rather than one blanket claim:

Tier Languages What you get
Hybrid resolved Python, Rust Full parse plus cross-file/package symbol resolution
Deep syntax TypeScript, TSX Specialized declaration/import analyzer (aliases, barrels, re-export propagation); full hybrid resolution still a target
Syntax indexed JavaScript, Go, Java, Kotlin, C#, PHP, C, C++ Real tree-sitter AST extraction; cross-file resolution not yet wired
Structured formats Markdown, YAML, JSON, TOML, Dockerfile, docker-compose, GitHub Actions, SQL, HTML, CSS, GraphQL, Protobuf Fully indexed structured/config/protocol data

Beyond these, the language registry carries roadmap entries toward parity with broader multi-language tools — those are recognized by name/extension today and fall back to generic text analysis until wired up.

Requirements

  • Rust toolchain managed by rustup (pinned in rust-toolchain.toml).
  • just for the documented development commands.
  • Optional: Node.js for building the graph explorer UI (ui/) and for validate-mermaid --node-validator. Nothing else needs it.
  • Optional: cargo-llvm-cov only for coverage reports.
  • Optional: sccache for local Rust compiler caching.

The justfile prefers the cargo resolved through ~/.cargo/bin/rustup so the pinned toolchain is used even when another Rust installation is present.

Quickstart

From this directory:

just toolchain
cargo run -- --help
cargo run -- init fixtures/polyglot
cargo run -- inspect modules fixtures/polyglot
cargo run -- ask fixtures/polyglot "source evidence"

After init, open the generated Markdown directly:

ls fixtures/polyglot/docs/lithograph

Or generate the static browser viewer:

cargo run -- viewer fixtures/polyglot
open fixtures/polyglot/.lithograph/viewer/index.html

Core Workflow

Generate documentation for a repository:

cargo run -- init /path/to/repo

Rescan and selectively regenerate only stale pages:

cargo run -- update /path/to/repo

Use deterministic semantic grouping when planning modules:

cargo run -- init /path/to/repo --semantic-grouping
cargo run -- update /path/to/repo --semantic-grouping

Stamp a prompt version into page/task metadata. Changing it forces affected pages to regenerate on update:

cargo run -- update /path/to/repo --prompt-version v2

Poll a repository for staleness against its last recorded snapshot, and optionally re-run update automatically when it drifts:

cargo run -- watch /path/to/repo
cargo run -- watch /path/to/repo --auto-index

Exchange a compressed, team-shareable graph artifact instead of rebuilding it:

cargo run -- graph export /path/to/repo --output graph.bundle
cargo run -- graph import /path/to/repo graph.bundle

Inspection, Search, and Graph Queries

These commands are deterministic and never call a model.

cargo run -- inspect artifacts /path/to/repo
cargo run -- inspect graph /path/to/repo --hide-unresolved
cargo run -- inspect env /path/to/repo        # env reads, definitions, config links
cargo run -- inspect modules /path/to/repo --semantic-grouping
cargo run -- inspect dsm /path/to/repo        # module dependency matrix + cycles
cargo run -- inspect metrics /path/to/repo    # last-run timings, graph size, cache hit rate
cargo run -- graph report /path/to/repo       # deterministic graph report

Walk the graph directly — shortest connecting chain, one node's evidence and neighbors, and what breaks when given nodes or changed files move:

cargo run -- path --path /path/to/repo SomeCaller SomeCallee
cargo run -- explain --path /path/to/repo SomeSymbol
git diff --name-only | cargo run -- affected --path /path/to/repo --stdin --depth 2

Search raw code with graph-scoped filters, ranked over an incrementally maintained chunk index:

cargo run -- search-code --path /path/to/repo "retry backoff" --language python
cargo run -- search-code --path /path/to/repo "cache key" --node-id <id> --expand-hops 2

Record how an answer actually landed, then fold those outcomes into reusable lessons:

cargo run -- research save-result /path/to/repo \
  --question "Where is auth enforced?" --answer "..." --node <id> --outcome useful
cargo run -- research reflect /path/to/repo

Scan existing Markdown for likely documentation drift against the current repository and graph:

cargo run -- drift /path/to/repo

Beyond CLI inspection, the graph supports 36 typed relation kinds (imports, calls, inheritance, type references, data flow, HTTP routes, config bindings, near-clone similarity, cross-service protocol edges, and more), a deliberately narrow Cypher-like query subset (src/retrieval/query.rs) exposed as the query_graph MCP tool, four search layers — BM25 full-text (src/retrieval/fts.rs), pluggable semantic/embedding search behind a swappable provider trait (src/retrieval/semantic_search.rs), graph-scoped node search (src/retrieval/search.rs), and hybrid code-chunk search (src/retrieval/chunk_*.rs, src/retrieval/code_index.rs) — plus deterministic architecture layer detection, tension scoring, and typed tagging (src/docs/architecture.rs, src/graph/tensions.rs, src/graph/tags.rs).

Architecture Decision Records

Create, read, update, delete, and list ADRs from the CLI (mirrored 1:1 by MCP tools for agent access):

cargo run -- adr create /path/to/repo \
  --title "Use versioned JSON snapshots for graph storage" \
  --context "Need a deterministic, portable on-disk projection of the semantic graph" \
  --decision "Adopt versioned JSON snapshots as the on-disk graph store"
cargo run -- adr list /path/to/repo

Generated Wiki Tools

Ask a deterministic local question against generated docs:

cargo run -- ask /path/to/repo "How does configuration work?"
cargo run -- ask /path/to/repo "How does configuration work?" --format json

Export generated wiki data in an MCP-style JSON shape:

cargo run -- mcp-export /path/to/repo
cargo run -- mcp-export /path/to/repo --question "Which modules own the API?"

Serve deterministic JSON-line requests over stdin/stdout:

cargo run -- mcp-server /path/to/repo

mcp-server exposes 45 tools spanning wiki access, graph queries and schema introspection, budgeted/positioned graph layout, all four search modes, tag/taxonomy lookups, trace-path and impact analysis, dead-code detection, change detection, drift detection, architecture layer reporting, ADR CRUD, subsystem document generation and refinement, research memory/lessons, and run metrics. See MCP_TOOLS in src/agent/mcp.rs for the full list.

Generate a lightweight static viewer with navigation, local search, and Mermaid-ready code blocks:

cargo run -- viewer /path/to/repo

Serve the graph explorer UI and read-only graph API locally (binds 127.0.0.1 only; see docs/dev/security.md for the full threat model):

cd ui && npm install && npm run build && cd ..
cargo run -- serve /path/to/repo --assets ui/dist
cargo run -- serve /path/to/repo --assets ui/dist --project other=/path/to/other

Additional repositories are served only when explicitly allowlisted with --project ID=PATH; no parent directory is ever scanned.

The explorer (ui/, React + TypeScript + react-three-fiber -- see ui/README.md) renders the live graph in 3D with cluster, radial, and matrix layout modes, drag-persisted node positions, cluster convex-hull overlays, node-kind/edge-kind filtering and stats, and side panels for analytics, architecture, tags, traces, saved investigations, a query workbench, and a docs workspace — all backed by the real MCP tool APIs above. Bookmarkable via URL state (project, focused node, layout mode, node budget, tag expression, and unresolved/unproven filters).

Agent Integration

Wire Lithograph's MCP server into a coding agent's config. Without --target, every supported agent is detected and reported; nothing is written unless --apply is passed with a specific --target:

cargo run -- integrate-mcp /path/to/repo
cargo run -- integrate-mcp /path/to/repo --target claude --apply

Targets that get an MCP config written: codex, claude, gemini, zed. aider is detected and reported too, but has no native MCP server support — it is reported as unsupported and pointed at integrate-agents instead.

integrate-agents is the only Lithograph command that edits top-level AGENTS.md or CLAUDE.md files. It adds or refreshes a Lithograph reference section and is idempotent:

cargo run -- integrate-agents /path/to/repo

Output Quality and Regression Checks

Update golden snapshots for generated docs, manifest, and research artifacts:

cargo run -- golden fixtures/polyglot --golden-dir tests/golden/polyglot --update

Check generated output against snapshots:

cargo run -- golden fixtures/polyglot --golden-dir tests/golden/polyglot

Inspect generated wiki quality — missing page evidence, unresolved questions, empty Mermaid sections, weak module coverage, missing source links, and broken generated-doc links:

cargo run -- quality /path/to/repo

Validate Mermaid fences structurally, optionally through a local Node/ mermaid.js validator:

cargo run -- validate-mermaid /path/to/repo
cargo run -- validate-mermaid /path/to/repo --node-validator ./my-validator.mjs

--node-validator runs node <script> per fence with the fence body on stdin, treating a non-zero exit as an issue. No such script ships with the repository; supply your own if you want mermaid.js parsing.

Normal tests and just check-all do not require Node or network access.

Model Configuration

Backend selection is environment-driven:

  1. DeepInfra when LITHOGRAPH_DEEPINFRA_API_KEY is set.
  2. OpenAI-compatible API when LITHOGRAPH_OPENAI_API_KEY is set.
  3. Deterministic mock model when neither API key is set.

DeepInfra:

export LITHOGRAPH_DEEPINFRA_API_KEY=...
export LITHOGRAPH_DEEPINFRA_MODEL=deepseek-ai/DeepSeek-R1
# optional
export LITHOGRAPH_DEEPINFRA_BASE_URL=https://api.deepinfra.com/v1/openai
export LITHOGRAPH_DEEPINFRA_REASONING_EFFORT=medium

OpenAI-compatible:

export LITHOGRAPH_OPENAI_API_KEY=...
# optional
export LITHOGRAPH_OPENAI_BASE_URL=https://api.openai.com/v1
export LITHOGRAPH_OPENAI_MODEL=gpt-4o-mini
export LITHOGRAPH_OPENAI_REASONING_EFFORT=medium

Only init and update generate page content through the selected model. Every other command — inspection, drift, quality, golden, Mermaid validation, ask, search, graph queries, ADRs, MCP export/server, and viewer generation — operates on local files only, with zero network access.

Development

Use these commands from this directory:

just toolchain
just fmt
just fmt-check
just lint
just test
just unit-test
just integration-test
just check-all
just baseline-pr

just check-all is the default pre-handoff validation path. It runs formatting checks, clippy with warnings denied, and the complete test suite (794 test functions across unit and integration coverage):

just check-all

The deterministic baseline lab adds deep graph, clustering, clone, classification, semantic-ranking, metamorphic, differential, and incremental regression coverage. just baseline-pr is hermetic and offline. Fetch pinned external repositories explicitly before the broader suites:

just baseline-fetch merge
just baseline-merge

See the baseline lab guide for run inspection, agent/MCP tools, replay, baseline governance, and nightly performance reports.

Coverage is intentionally separate because it requires cargo-llvm-cov:

cargo install cargo-llvm-cov
just coverage

Repository Layout

  • src/domain/: stable IDs, artifacts, evidence, and confidence types.
  • src/inventory/: repository walking, classification, language registry, and safety policy.
  • src/analysis/: deterministic analyzers for supported file types, plus the content-addressed analysis cache.
  • src/resolve/: per-language hybrid import/symbol resolvers, TS path aliases, barrels, and re-export propagation.
  • src/graph/: semantic graph model, builder, validation, versioned JSON store, analytics, communities, tensions, tags, layout, and the read indexes (src/graph/index/: architecture, clusters, dead code, dependency matrix, schema, search, trace).
  • src/retrieval/: the Cypher-like graph query subset (query.rs), full-text (fts.rs), semantic (semantic_search.rs), graph-scoped (search.rs), and hybrid code-chunk search with incremental indexing.
  • src/docs/: architecture layer detection, ADR storage, C4-oriented documentation modeling, subsystem docs, and Mermaid validation.
  • src/knowledge/: research summaries, research feedback/lessons, documentation drift, and generated-wiki quality checks.
  • src/agent/: ask, the MCP server (mcp.rs), per-agent MCP integration (mcp_targets.rs), and the typed research agent.
  • src/commands/: CLI command handlers, one module per command group.
  • src/plan.rs: deterministic and optional semantic module planning.
  • src/generation/: context construction, model adapters, evidence validation, and page rendering.
  • src/orchestrate.rs: init and update pipeline.
  • src/manifest.rs: page/task manifest and version invalidation metadata.
  • src/serve.rs, src/viewer.rs, src/watch.rs: local graph server with multi-project allowlisting, static viewer, and staleness polling.
  • src/golden.rs: deterministic golden snapshots for generated output.
  • src/fingerprint.rs, src/reconcile.rs, src/explain.rs: content fingerprints, component-owned target-state reconciliation, and the machine-readable invalidation explain plans behind incremental runs.
  • src/lab/: the deterministic baseline lab behind lithograph-lab.
  • fixtures/polyglot/: representative fixture repository used by tests.
  • fixtures/diagnostic/, lab/: authored baseline truth, pinned corpus configuration, curated expectations, and accepted summaries.
  • tests/: integration and snapshot coverage.
  • docs/dev/: design notes — parser spike decisions, prompt/context versioning, type-aware resolution, plus distribution and security posture.

Distribution and Security

Ships as a single static Rust binary with no runtime dependencies; tested on macOS (aarch64/x86_64) and Linux (x86_64/aarch64), with Windows supported on a best-effort basis. Not yet published to crates.io — install via cargo install --path . --locked from a pinned revision. See docs/dev/distribution.md for the full pre-release checklist.

Lithograph reads only within the canonicalized repository root and honors .gitignore. Secrets and credentials (.env, private keys, and similar) are classified metadata-only — their path and category are recorded, but their content is never sent to a model or written to disk, with private-key markers redacted line-by-line even in otherwise-safe files. Only init and update ever call a model, only when an API key is configured, and only with bounded, evidence-scoped excerpts — never a whole-repo dump. See docs/dev/security.md for the complete guarantees that keep just test and just check-all offline and deterministic.

Current Status

Pre-alpha: usable day to day on real repositories, but nothing is frozen.

Lithograph's local CLI, C4-oriented generated wiki, versioned JSON graph, incremental update path with content-addressed caching, four search modes, graph query language, graph navigation (path/explain/affected), ADR store, research feedback loop, drift/quality checks, 45-tool MCP server, a local embedded server (serve) with a budgeted/cached graph layout API and explicit multi-project allowlisting, and per-agent integration are implemented and covered by 794 Rust tests. The browser graph explorer frontend (ui/, tracked under the LIT-24 backlog epic) renders the live graph in 3D with cluster/radial/matrix layout modes, drag-persisted positions, cluster hulls, filtering, URL state, and the analytics, saved investigations, query workbench, tag explorer, and docs workspace panels, covered by 178 frontend tests. Cross-file hybrid resolution is live for Python and Rust only; TypeScript/TSX and the other syntax-indexed languages still resolve within-file. Prefer just check-all (Rust) and npm run check-all (ui/) before handoff, and keep generated output changes reviewable with golden, quality, and validate-mermaid.

About

Offline repository knowledge compiler in Rust: builds a deterministic, evidence-backed semantic graph of a codebase (tree-sitter parsing, 29 relation kinds, Cypher-like queries), generates a C4-oriented Markdown wiki and ADR store, and exposes it all to agents over MCP.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages