Skip to content

feat: v0.7.0 code graph developer preview#91

Draft
theDakshJaitly wants to merge 35 commits into
mainfrom
code-graph-preview
Draft

feat: v0.7.0 code graph developer preview#91
theDakshJaitly wants to merge 35 commits into
mainfrom
code-graph-preview

Conversation

@theDakshJaitly

@theDakshJaitly theDakshJaitly commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Status

Important

Developer preview: do not merge yet.

main and npm remain on stable v0.6.3. This PR tracks the upcoming v0.7.0 code graph while it is tested, improved through contributions, documented, and prepared for a stable release. No v0.7.0 GitHub release or npm publish should happen from the current state.

Overview

This PR adds a deterministic, local code knowledge graph beneath Mex's markdown memory scaffold. Tree-sitter extraction writes structural code facts to SQLite so scaffold memory can point at exact symbols, detect when grounded behavior changes, and survive confident renames or moves through fingerprint reconciliation.

The preview package version is 0.7.0-dev.0. The graph is additive: existing scaffolds and the original filesystem/lexical drift checks continue to work when no graph is present.

What is included

  • Tree-sitter extraction for TypeScript, TSX, JavaScript, and JSX.
  • SQLite graph storage with nodes, edges, source locations, body hashes, MinHash fingerprints, and reconciliation data.
  • Cross-file import, call, inheritance, containment, and reference edges.
  • Express route-to-handler resolution as the reference framework resolver.
  • Graph-backed grounding through frontmatter grounds_to entries and inline mex:// anchors.
  • Grounding drift detection for changed, moved, ambiguous, and removed nodes.
  • Durable grounding repair during mex sync.
  • Fresh-setup graph population and an idempotent migration path for existing populated scaffolds.
  • Source-level LanguageExtractor and FrameworkResolver contribution seams.
  • Packaged SQLite schema and Tree-sitter WASM grammar assets.

New commands

mex graph
mex graph --json
mex graph scope <task>
mex graph ground
mex graph query where-defined <symbol>
mex graph query who-calls <symbol>
mex graph query what-calls <symbol>
mex impact <symbol-or-file>

The scope, query, and impact commands emit compact JSONL intended for coding-agent retrieval and structural analysis.

Architecture

  1. Extraction: Tree-sitter grammars produce normalized nodes and syntax-level edges.
  2. Resolution: cross-file and framework resolvers add semantic relationships.
  3. Storage: SQLite persists graph facts, fingerprints, FTS data, and grounding baselines.
  4. Retrieval: scope/query/impact commands hydrate relevant symbols and neighborhoods.
  5. Grounding: scaffold prose records tight symbol pointers and fingerprints.
  6. Drift and repair: mex check detects stale grounding; mex sync repairs prose and pointers.

The identity, reconciliation, schema, and drift semantics are core behavior. Changes to those areas require discussion before implementation.

Current constraints

  • Requires Node.js 22.5 or newer because the preview uses built-in node:sqlite.
  • Language extraction currently covers only TypeScript, TSX, JavaScript, and JSX.
  • Express is the only framework-specific reference resolver.
  • Unsupported-language files are skipped.
  • Missing grammars, unavailable SQLite, or absent graph data degrade gracefully to the original checks.
  • Graph contribution interfaces are source-level seams, not public npm API exports.
  • The preview is available from source only and is not published to npm.

Testing

Validated on the preview branch with:

npm run typecheck
npm test
npm run build

Current result: 30 test files and 301 tests passing. The build also verifies that the graph schema and three grammar WASM assets are copied into dist/.

Contribution workflow

Code-graph issues must state:

Target branch: code-graph-preview

Create contribution branches from the preview branch:

git switch code-graph-preview
git pull
git switch -c <feature-or-fix-branch>

Open contributor PRs with:

  • Base: code-graph-preview
  • Compare: the contributor's feature or fix branch

Do not target main with code-graph contributions. Relevant labels include code-graph, developer-preview, language-support, tree-sitter, testing, performance, help wanted, and good first issue. Work affecting graph identity, reconciliation, schema, or drift semantics should use core / discuss-first.

Release checklist

Preview foundation

  • Deterministic graph engine and SQLite storage
  • TS/JS/TSX/JSX reference extraction
  • Express reference resolver
  • Graph CLI, retrieval, and impact commands
  • Grounding drift detection and durable repair
  • Existing-scaffold grounding migration
  • Packaged graph assets
  • Preview version set to 0.7.0-dev.0
  • Contributor branch workflow documented
  • Preview issue labels created
  • Contributor PR CI enabled for code-graph-preview
  • Preview branch protection requires CI, review, and resolved conversations
  • Full typecheck, test, and build validation

Before stable v0.7.0

  • Complete contributor testing on representative repositories
  • Triage and fix preview bugs and graph-accuracy regressions
  • Document extractor and resolver contribution walkthroughs
  • Add extractor/resolver issue and PR templates
  • Agree on and open the first bounded starter issues
  • Expand fixtures and regression coverage from real repositories
  • Review performance and graph-size behavior on larger codebases
  • Document known limitations and supported-language status
  • Validate a clean packed-install workflow
  • Complete final compatibility and migration review
  • Change package metadata from prerelease to 0.7.0
  • Approve this PR for merge into main
  • Create the GitHub v0.7.0 release
  • Publish [email protected] to npm

Release flow

code-graph-preview
        ↓
       main
        ↓
GitHub v0.7.0 release
        ↓
npm [email protected]

Until every required release item is complete, this PR should remain open and in Draft state.

Lay down the frozen interfaces, schema, types, and config for the .mex/
code-graph layer (spec §10 Phase 0). Contracts only — no engine logic,
extraction, fingerprinting, reconciliation, or checker bodies. Everything
typechecks/builds; existing eleven checkers + CLI untouched (graph is additive).

- 0.1 src/graph/schema.sql: ported CG base (nodes+body_hash, edges, files,
  unresolved_refs, nodes_fts FTS5, indexes, schema_versions, project_metadata)
  + net-new node_fingerprints, lsh_buckets, _mex_grounded_source (keyed by
  scaffold_file, the one demo->OSS adaptation).
- 0.2 Frozen TS contracts under src/graph/: LanguageExtractor (§8.1) +
  ExtractedNode/Edge + TSTree surface; FrameworkResolver + ResolutionContext;
  GraphEngine (build/sync/searchNodes/getNode/getCallers/getCallees) with
  throwing stub; Reconciler + Resolution (MOVED|GONE|AMBIGUOUS) + Fingerprint;
  GroundingChecker signature (matches checkEdges) + createGroundingChecker.
  Reader methods are sync so the grounding checker matches the existing
  synchronous drift-checker shape; build/sync async for lazy grammar loading.
- 0.3 src/types.ts: add Grounding + ScaffoldFrontmatter.grounds_to (§5,
  backward-compatible) + grounding IssueCodes (GROUNDING_GONE/DRIFT/AMBIGUOUS)
  so Track B never has to reopen this shared union.
- 0.4 src/graph/config.ts: reconciler params as named consts (HI/LO/W_BODY/
  W_NBR/MIN_TOKENS/K/BANDS/ROWS) — placeholders, eval-tuned later (§12).
- 0.5 package.json engines.node >=22.5 for node:sqlite (used by the DB adapter
  Track A ports in Phase 1). No heavy deps added yet.

Also scope vitest to exclude the gitignored .demo/ reference clone (its own
suite needs mex-engine-cg, which we don't install).
Implements the port-heavy graph engine against the frozen Phase-0
contracts (spec §10 Track A). Ports from .demo/ (never committed) and
ships the 0.7.0 base: a deterministic tree-sitter → SQLite code graph for
TypeScript/JavaScript/TSX/JSX, no LLM.

- A1  Clean, exemplary TS/JS reference extractor implementing the frozen
      LanguageExtractor seam (the copy-template every 0.7.x contributor
      language clones), plus a self-verifying test harness + fixture (§8.2).
- A2  Line-independent node id ported verbatim (Tier-1 identity).
- A3  node:sqlite adapter, schema loader (writes a schema_versions row),
      store with FTS5 search + reader queries.
- A4  Cross-file reference resolution (import-aware name binding) and
      callers/callees traversal.
- A5  Lazy web-tree-sitter grammar loading; TS/JS/TSX .wasm vendored and
      shipped in the published package, resolved from the install location.
- A6  `mex graph` command wired additively into src/cli.ts.
- GraphEngine implementation: async build/sync (lazy grammars),
  synchronous reads; engine assigns body_hash + updatedAt.

Frozen contracts (schema.sql, types, engine/extractor/resolver interfaces,
config, reconcile, grounding, drift) are unchanged; src/graph/index.ts
gains only an additive createGraphEngine export. Verified: typecheck,
build, 259 tests, and an npm pack + install-from-tarball that builds a
real graph from the installed package (WASM + schema resolve at runtime).
Merge Gate 1, part 1 of 2. Additive graph engine: extraction, db,
traversal, resolver, mex graph command. No frozen-contract signature
changes.
…rounding)

Merge Gate 1, part 2 of 2. Additive fingerprint/reconcile/grounding
layer + grounding checker body. grounding.ts stub filled behind the
unchanged createGroundingChecker signature. Resolved src/graph/index.ts
export conflict by keeping both tracks' additive exports.
@theDakshJaitly theDakshJaitly added code-graph Work related to the AST and Tree-sitter code graph developer-preview Part of an unreleased developer preview labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-graph Work related to the AST and Tree-sitter code graph developer-preview Part of an unreleased developer preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants