Skip to main content
Glama

tare.tools.specgraph

SpecGraph indexes a repository's code, specifications, architecture decisions (ADRs) and declared test links into a local SQLite graph. People and coding agents query that graph through a CLI, a Python SDK and a read-only MCP server, and get bounded answers that state which snapshot and scope they cover.

Python is analyzed with the standard ast module. TypeScript and Rust are supported through optional tree-sitter grammars. The North Star describes the intended product; it is not a statement that every capability or performance target has shipped. specgraph capabilities reports what is implemented and its limits.

Project intelligence guide · Documentation index · Canonical specification · Português

Relation to tare.tools.os

SpecGraph is one of the satellite repositories of tare.tools.os. The OS pins it as a Git submodule under satellites/tare.tools.specgraph, installs it into the same environment, and calls its Python API and CLI to give agents project context (specgraph index, specgraph ground, role context for hooks). SpecGraph does not import the OS and can be used on its own. Its optional integration tests use two other satellites: tare.tools.kernel (provider and process ports) and tare.tools.agent-runtime (the agent host).

Related MCP server: Claude Code Codegraph Harness

Requirements

  • Python 3.10 or newer, and Git.

  • Optional: the multilanguage extra (tree-sitter grammars for TypeScript and Rust) and the fast extra (ruff, used for the import graph in test impact).

  • Optional: a Rust toolchain to build rust/specgraph-core, the native symbol-impact engine used by test selection (ADR-SPECGRAPH-015). Without it, SpecGraph falls back to import-level impact.

Install from a clone

git clone https://github.com/augusto-scarvalho/tare.tools.specgraph.git
cd tare.tools.specgraph
python -m venv .venv
# Windows: .venv\Scripts\activate    Linux/macOS: source .venv/bin/activate
python -m pip install -e ".[dev]"
specgraph --version

Add the optional extras with python -m pip install -e ".[dev,multilanguage,fast]".

Index a project

specgraph --root /path/to/project init --name my-project
# Edit specgraph.yaml so it lists the project's real code, test and document paths.
specgraph --root /path/to/project index
specgraph --root /path/to/project query parse_file --format json
specgraph --root /path/to/project symbol 'src/parser.py:parse_file'
specgraph --root /path/to/project refs 'src/parser.py:parse_file'
specgraph --root /path/to/project code-context 'src/parser.py:parse_file' --max-bytes 8192
specgraph --root /path/to/project doctor
specgraph --root /path/to/project serve

init writes specgraph.yaml and a sample specification. Run index after edits. Extraction is reused only when source, configuration and parser identities match; index --full re-extracts everything. Indexing still discovers and hashes sources and assembles relations globally. Queries read the published snapshot without walking the source tree. Responses identify the revision, content and coverage, and state that the current worktree was not checked on the read path.

query, symbol, refs, neighbors, path, explain and code-context require a published index. search and resolve keep a labeled compatibility path for repositories without one. doctor reads metadata; doctor --deep runs live governance validation. sync-cache, impact and staleness keep the separate legacy JSON-cache contract, including its source validation costs.

Keep context useful after edits

specgraph reconcile observes source changes and acknowledges delivered edit hints. specgraph watch runs the periodic reconciler in the foreground; it is not installed as a service. Hooks journal edits without indexing synchronously. This repository sets hook_context.automatic_roles: [], so role context is requested explicitly instead of being repeated for ordinary reads and edits.

specgraph reconcile --format json
specgraph hook-context --role implementer --symbol 'src/parser.py:parse_file'
specgraph doctor --effectiveness-report path/to/paired-evaluation.json

Exact declarative bindings in intent_mapping_paths require the owner source, its SHA-256, the acceptance criteria and the exact target ID. They are traceability declarations, not executed coverage. See the project intelligence guide.

What the graph means

Python symbols have file and lexical identities. Static resolution preserves aliases and supported local references; ambiguous, external and dynamic occurrences stay explicit. An observed static dependency is not proof of a runtime call. The native AST analysis is not a complete code property graph, data-flow analysis or universal dynamic-dispatch resolver.

Specifications use YAML (or JSON) frontmatter with id, acceptance_criteria and optional target_symbols. Code can declare @spec SPEC-ID; tests can declare @pytest.mark.verifies("SPEC-ID", "AC-01"). ADRs declare governed_specs. These declarations establish traceability, not proof that a test ran or passed.

indexed_paths controls retrieval coverage. governed_paths controls orphan-code enforcement. Exclusions and supported languages limit negative answers: no result means no match in the reported snapshot and scope, not proof that a behavior cannot exist.

Bounded context and federation

context SPEC-ID and bundle --spec SPEC-ID return the complete selected acceptance criteria and source snippets, or refuse when the byte budget is too small. code-context retrieves code neighborhoods from persisted source ranges. The canonical context contract documents the live renderer.

ground projects selected metadata from a sources manifest that the host generates from Git (contract); metadata alone does not mean source bodies were acquired or that a Work item can run. Repository owners stay authoritative for their documents, and inferred suggestions never replace accepted specifications.

The MCP stdio server implements protocol 2025-06-18 with the read-only tools query_causal_graph, get_context_envelope and check_drift. Source freshness is reported separately from snapshot consistency.

Run the tests

From the repository root, with the virtual environment active:

python tools/check_completion_contracts.py
python -m pytest tests tools/tests

With only the dev extra, the TypeScript/Rust, Kernel and native-core tests are skipped. CI runs the complete suite on Windows and Linux with every extra, the two satellites at the revisions pinned in .github/workflows/ci.yml (KERNEL_REVISION, RUNTIME_REVISION) and the native core built:

python -m pip install -e ".[dev,multilanguage,fast]" pydantic \
  "git+https://github.com/augusto-scarvalho/tare.tools.kernel@<KERNEL_REVISION>" \
  "git+https://github.com/augusto-scarvalho/tare.tools.agent-runtime@<RUNTIME_REVISION>"
cargo test --release --locked --manifest-path rust/specgraph-core/Cargo.toml
cargo build --release --locked --manifest-path rust/specgraph-core/Cargo.toml
python -m pytest tests tools/tests

CI runs on GitHub-hosted runners. To run it on your own machines instead, set the repository variables CI_RUNNER_LINUX and CI_RUNNER_WINDOWS to a runner label list (for example ["self-hosted","Linux"]).

Changes to this repository add a bullet under ## Unreleased in CHANGELOG.md; python tools/install_git_hooks.py installs the pre-push check (policy).

Measure

specgraph --root /path/to/project bench parse_file RepositoryIndex --samples 100 --rounds 2

The benchmark measures complete SDK query calls, including opening SQLite and serializing output, and reports its repository and environment. Interpreter startup, indexing, MCP transport and agent reasoning are separate costs. Sub-50 ms retrieval and 65% context savings remain targets until measured on an agreed workload.

The completion program lists the contracts (C0–C8, X1–X5), their specifications and decisions. Earlier qualification records are no longer in the tree; docs/evidence explains how to read them from Git history.

License

Apache-2.0, as declared in pyproject.toml.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides read-only, provenance-first repository navigation for agents and humans, with ranked lexical retrieval, exact query, document handles, symbol context, and change impact analysis.
      82 npm
      Apache 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables bounded, read-only code-graph search, neighbor/impact tracing, and architecture queries through a local offline gateway, while keeping source contents and mutation operations out of model-callable tools.
      Apache 2.0
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables coding agents to perform read-only source investigation via a local SQLite index, offering status, search, backlog, context, impact, and drift tools for TypeScript, JavaScript, and Java codebases.
      -
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables AI coding agents to query a local SQLite-backed structural code graph for bounded, relevant context such as source entities, relationships, call paths, impact analysis, and recorded project mistakes before reading full files.
      24 npm
      MIT