@colbymchenry/codegraph 0.9.7 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/README.md +116 -32
  2. package/dist/bin/codegraph.d.ts +25 -0
  3. package/dist/bin/node-version-check.d.ts +37 -0
  4. package/dist/bin/uninstall.d.ts +14 -0
  5. package/dist/context/formatter.d.ts +30 -0
  6. package/dist/context/index.d.ts +119 -0
  7. package/dist/context/markers.d.ts +19 -0
  8. package/dist/db/index.d.ts +101 -0
  9. package/dist/db/migrations.d.ts +44 -0
  10. package/dist/db/queries.d.ts +344 -0
  11. package/dist/db/sqlite-adapter.d.ts +46 -0
  12. package/dist/directory.d.ts +57 -0
  13. package/dist/errors.d.ts +136 -0
  14. package/dist/extraction/dfm-extractor.d.ts +31 -0
  15. package/dist/extraction/generated-detection.d.ts +30 -0
  16. package/dist/extraction/grammars.d.ts +100 -0
  17. package/dist/extraction/index.d.ts +138 -0
  18. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  19. package/dist/extraction/languages/csharp.d.ts +3 -0
  20. package/dist/extraction/languages/dart.d.ts +3 -0
  21. package/dist/extraction/languages/go.d.ts +3 -0
  22. package/dist/extraction/languages/index.d.ts +10 -0
  23. package/dist/extraction/languages/java.d.ts +3 -0
  24. package/dist/extraction/languages/javascript.d.ts +3 -0
  25. package/dist/extraction/languages/kotlin.d.ts +3 -0
  26. package/dist/extraction/languages/lua.d.ts +3 -0
  27. package/dist/extraction/languages/luau.d.ts +3 -0
  28. package/dist/extraction/languages/objc.d.ts +3 -0
  29. package/dist/extraction/languages/pascal.d.ts +3 -0
  30. package/dist/extraction/languages/php.d.ts +3 -0
  31. package/dist/extraction/languages/python.d.ts +3 -0
  32. package/dist/extraction/languages/ruby.d.ts +3 -0
  33. package/dist/extraction/languages/rust.d.ts +3 -0
  34. package/dist/extraction/languages/scala.d.ts +3 -0
  35. package/dist/extraction/languages/swift.d.ts +3 -0
  36. package/dist/extraction/languages/typescript.d.ts +3 -0
  37. package/dist/extraction/liquid-extractor.d.ts +52 -0
  38. package/dist/extraction/mybatis-extractor.d.ts +48 -0
  39. package/dist/extraction/parse-worker.d.ts +8 -0
  40. package/dist/extraction/svelte-extractor.d.ts +56 -0
  41. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  42. package/dist/extraction/tree-sitter-types.d.ts +193 -0
  43. package/dist/extraction/tree-sitter.d.ts +317 -0
  44. package/dist/extraction/vue-extractor.d.ts +36 -0
  45. package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
  46. package/dist/graph/index.d.ts +8 -0
  47. package/dist/graph/queries.d.ts +106 -0
  48. package/dist/graph/traversal.d.ts +127 -0
  49. package/dist/index.d.ts +498 -0
  50. package/dist/installer/config-writer.d.ts +28 -0
  51. package/dist/installer/index.d.ts +100 -0
  52. package/dist/installer/instructions-template.d.ts +18 -0
  53. package/dist/installer/targets/antigravity.d.ts +57 -0
  54. package/dist/installer/targets/claude.d.ts +56 -0
  55. package/dist/installer/targets/codex.d.ts +18 -0
  56. package/dist/installer/targets/cursor.d.ts +35 -0
  57. package/dist/installer/targets/gemini.d.ts +26 -0
  58. package/dist/installer/targets/hermes.d.ts +18 -0
  59. package/dist/installer/targets/kiro.d.ts +27 -0
  60. package/dist/installer/targets/opencode.d.ts +30 -0
  61. package/dist/installer/targets/registry.d.ts +35 -0
  62. package/dist/installer/targets/shared.d.ts +77 -0
  63. package/dist/installer/targets/toml.d.ts +52 -0
  64. package/dist/installer/targets/types.d.ts +101 -0
  65. package/dist/mcp/daemon-paths.d.ts +46 -0
  66. package/dist/mcp/daemon.d.ts +161 -0
  67. package/dist/mcp/engine.d.ts +105 -0
  68. package/dist/mcp/index.d.ts +112 -0
  69. package/dist/mcp/proxy.d.ts +81 -0
  70. package/dist/mcp/server-instructions.d.ts +19 -0
  71. package/dist/mcp/session.d.ts +77 -0
  72. package/dist/mcp/tools.d.ts +413 -0
  73. package/dist/mcp/transport.d.ts +188 -0
  74. package/dist/mcp/version.d.ts +19 -0
  75. package/dist/resolution/callback-synthesizer.d.ts +10 -0
  76. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  77. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  78. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  79. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  80. package/dist/resolution/frameworks/express.d.ts +8 -0
  81. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  82. package/dist/resolution/frameworks/go.d.ts +8 -0
  83. package/dist/resolution/frameworks/index.d.ts +48 -0
  84. package/dist/resolution/frameworks/java.d.ts +8 -0
  85. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  86. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  87. package/dist/resolution/frameworks/play.d.ts +19 -0
  88. package/dist/resolution/frameworks/python.d.ts +10 -0
  89. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  90. package/dist/resolution/frameworks/react.d.ts +8 -0
  91. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  92. package/dist/resolution/frameworks/rust.d.ts +8 -0
  93. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  94. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  95. package/dist/resolution/frameworks/swift.d.ts +10 -0
  96. package/dist/resolution/frameworks/vue.d.ts +9 -0
  97. package/dist/resolution/go-module.d.ts +26 -0
  98. package/dist/resolution/import-resolver.d.ts +68 -0
  99. package/dist/resolution/index.d.ts +116 -0
  100. package/dist/resolution/lru-cache.d.ts +24 -0
  101. package/dist/resolution/name-matcher.d.ts +32 -0
  102. package/dist/resolution/path-aliases.d.ts +68 -0
  103. package/dist/resolution/strip-comments.d.ts +27 -0
  104. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  105. package/dist/resolution/types.d.ts +209 -0
  106. package/dist/search/query-parser.d.ts +57 -0
  107. package/dist/search/query-utils.d.ts +71 -0
  108. package/dist/sync/git-hooks.d.ts +45 -0
  109. package/dist/sync/index.d.ts +19 -0
  110. package/dist/sync/watch-policy.d.ts +48 -0
  111. package/dist/sync/watcher.d.ts +191 -0
  112. package/dist/sync/worktree.d.ts +54 -0
  113. package/dist/types.d.ts +377 -0
  114. package/dist/ui/glyphs.d.ts +42 -0
  115. package/dist/ui/shimmer-progress.d.ts +11 -0
  116. package/dist/ui/shimmer-worker.d.ts +2 -0
  117. package/dist/ui/types.d.ts +17 -0
  118. package/dist/utils.d.ts +205 -0
  119. package/npm-sdk.js +75 -0
  120. package/package.json +18 -7
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ### Supercharge Claude Code, Cursor, Codex, OpenCode, Hermes Agent, Gemini, Antigravity, and Kiro with Semantic Code Intelligence
6
6
 
7
- **~35% cheaper · ~70% fewer tool calls · 100% local**
7
+ **~16% cheaper · ~58% fewer tool calls · 100% local**
8
8
 
9
9
  ### [Documentation & Website →](https://colbymchenry.github.io/codegraph/)
10
10
 
@@ -55,6 +55,8 @@ cd your-project
55
55
  codegraph init -i
56
56
  ```
57
57
 
58
+ <sub>`codegraph init` just creates the local `.codegraph/` index directory; adding `-i` (`--index`) also builds the initial graph in the same step. Without `-i`, run `codegraph index` afterwards to populate it.</sub>
59
+
58
60
  <div align="center">
59
61
 
60
62
  ![1_C_VYnhpys0UHrOuOgpgoyw](https://github.com/user-attachments/assets/f168182f-4d9a-44e0-94d7-08d018cc8a3a)
@@ -81,26 +83,101 @@ When Claude Code explores a codebase, it spawns **Explore agents** that scan fil
81
83
 
82
84
  ### Benchmark Results
83
85
 
84
- Tested across **7 real-world open-source codebases** spanning 7 languages, comparing an agent (Claude Code, headless) answering one architecture question **with** and **without** CodeGraph. Each cell is the savings at the **median of 4 runs per arm**. _Re-validated on **v0.9.4** (2026-05-24)._
86
+ Tested across **7 real-world open-source codebases** spanning 7 languages, comparing an agent (Claude Code, headless) answering one architecture question **with** and **without** CodeGraph. Each cell is the savings at the **median of 4 runs per arm**. _Re-validated on Opus 4.8 (2026-06-02), on the current build (`codegraph_explore` as the primary tool)._
85
87
 
86
- > **Average: 35% cheaper · 57% fewer tokens · 46% faster · 71% fewer tool calls**
88
+ > **Average: 16% cheaper · 47% fewer tokens · 22% faster · 58% fewer tool calls**
87
89
 
88
90
  | Codebase | Language | Cost | Tokens | Time | Tool calls |
89
91
  |----------|----------|------|--------|------|------------|
90
- | **VS Code** | TypeScript · ~10k files | 26% cheaper | 78% fewer | 52% faster | 85% fewer |
91
- | **Excalidraw** | TypeScript · ~640 | 52% cheaper | 90% fewer | 73% faster | 96% fewer |
92
- | **Django** | Python · ~3k | 12% cheaper | 36% fewer | 19% faster | 53% fewer |
93
- | **Tokio** | Rust · ~790 | 82% cheaper | 86% fewer | 71% faster | 92% fewer |
94
- | **OkHttp** | Java · ~645 | 2% cheaper | 13% fewer | 31% faster | 45% fewer |
95
- | **Gin** | Go · ~110 | 21% cheaper | 34% fewer | 27% faster | 40% fewer |
96
- | **Alamofire** | Swift · ~110 | 47% cheaper | 64% fewer | 48% faster | 83% fewer |
92
+ | **VS Code** | TypeScript · ~10k files | 18% cheaper | 64% fewer | 11% faster | 81% fewer |
93
+ | **Excalidraw** | TypeScript · ~640 | even | 25% fewer | 27% faster | 40% fewer |
94
+ | **Django** | Python · ~3k | 8% cheaper | 60% fewer | 13% faster | 77% fewer |
95
+ | **Tokio** | Rust · ~790 | even | 38% fewer | 18% faster | 57% fewer |
96
+ | **OkHttp** | Java · ~645 | 25% cheaper | 54% fewer | 31% faster | 50% fewer |
97
+ | **Gin** | Go · ~110 | 19% cheaper | 23% fewer | 24% faster | 44% fewer |
98
+ | **Alamofire** | Swift · ~110 | 40% cheaper | 64% fewer | 33% faster | 58% fewer |
99
+
100
+ CodeGraph cuts **tokens, tool calls, and wall-clock time on every repo** — across small, medium, and large codebases — and answers them with **near-zero file reads**, while the no-CodeGraph agent spends its budget on grep/find/Read discovery. `codegraph_explore` shows the answer in full — the mechanism plus the exact methods you asked about, even when they're buried in a multi-thousand-line file — while collapsing redundant interchangeable implementations to signatures, so the response is sized to the *answer* rather than the file count. **Cost stays flat-to-cheaper everywhere** — largest on the small repos (Alamofire, OkHttp), roughly break-even on the most response-heavy ones (Excalidraw, Tokio), where CodeGraph trades the no-CodeGraph agent's many small grep/read round-trips for a few large, cache-heavy tool responses.
101
+
102
+ <details>
103
+ <summary><strong>Per-repo breakdown — WITH vs WITHOUT (median of 4)</strong></summary>
104
+
105
+ **VS Code** · ~10k files
106
+ | Metric | WITH cg | WITHOUT cg | Δ |
107
+ |---|---|---|---|
108
+ | Time | 1m 59s | 2m 13s | 11% faster |
109
+ | File Reads | 0 | 9 | −9 |
110
+ | Grep/Bash | 0 | 11 | −11 |
111
+ | Tool calls | 4 | 21 | 81% fewer |
112
+ | Total tokens | 640k | 1.79M | 64% fewer |
113
+ | Cost | $0.68 | $0.83 | 18% cheaper |
114
+
115
+ **Excalidraw** · ~640 files
116
+ | Metric | WITH cg | WITHOUT cg | Δ |
117
+ |---|---|---|---|
118
+ | Time | 1m 32s | 2m 6s | 27% faster |
119
+ | File Reads | 0 | 7 | −7 |
120
+ | Grep/Bash | 1 | 8 | −7 |
121
+ | Tool calls | 9 | 15 | 40% fewer |
122
+ | Total tokens | 1.27M | 1.69M | 25% fewer |
123
+ | Cost | $0.78 | $0.78 | even |
124
+
125
+ **Django** · ~3k files
126
+ | Metric | WITH cg | WITHOUT cg | Δ |
127
+ |---|---|---|---|
128
+ | Time | 1m 43s | 1m 58s | 13% faster |
129
+ | File Reads | 0 | 9 | −9 |
130
+ | Grep/Bash | 0 | 5 | −5 |
131
+ | Tool calls | 3 | 13 | 77% fewer |
132
+ | Total tokens | 559k | 1.41M | 60% fewer |
133
+ | Cost | $0.57 | $0.62 | 8% cheaper |
134
+
135
+ **Tokio** · ~790 files
136
+ | Metric | WITH cg | WITHOUT cg | Δ |
137
+ |---|---|---|---|
138
+ | Time | 1m 55s | 2m 20s | 18% faster |
139
+ | File Reads | 0 | 8 | −8 |
140
+ | Grep/Bash | 0 | 6 | −6 |
141
+ | Tool calls | 6 | 14 | 57% fewer |
142
+ | Total tokens | 1.08M | 1.73M | 38% fewer |
143
+ | Cost | $0.82 | $0.82 | even |
144
+
145
+ **OkHttp** · ~645 files
146
+ | Metric | WITH cg | WITHOUT cg | Δ |
147
+ |---|---|---|---|
148
+ | Time | 1m 1s | 1m 29s | 31% faster |
149
+ | File Reads | 0 | 4 | −4 |
150
+ | Grep/Bash | 2 | 6 | −4 |
151
+ | Tool calls | 5 | 10 | 50% fewer |
152
+ | Total tokens | 502k | 1.10M | 54% fewer |
153
+ | Cost | $0.41 | $0.55 | 25% cheaper |
154
+
155
+ **Gin** · ~110 files
156
+ | Metric | WITH cg | WITHOUT cg | Δ |
157
+ |---|---|---|---|
158
+ | Time | 1m 14s | 1m 37s | 24% faster |
159
+ | File Reads | 1 | 6 | −5 |
160
+ | Grep/Bash | 1 | 2 | −1 |
161
+ | Tool calls | 5 | 9 | 44% fewer |
162
+ | Total tokens | 651k | 847k | 23% fewer |
163
+ | Cost | $0.46 | $0.57 | 19% cheaper |
164
+
165
+ **Alamofire** · ~110 files
166
+ | Metric | WITH cg | WITHOUT cg | Δ |
167
+ |---|---|---|---|
168
+ | Time | 1m 35s | 2m 21s | 33% faster |
169
+ | File Reads | 0 | 9 | −9 |
170
+ | Grep/Bash | 0 | 4 | −4 |
171
+ | Tool calls | 5 | 12 | 58% fewer |
172
+ | Total tokens | 766k | 2.10M | 64% fewer |
173
+ | Cost | $0.57 | $0.95 | 40% cheaper |
97
174
 
98
- The gains scale with codebase size: on large repos the agent answers from the index in a handful of calls with **zero file reads**, while the no-CodeGraph agent fans out across grep/find/Read (and the sub-agents it spawns). On a small repo like Gin (~150 files) native search is already cheap, so the margin narrows.
175
+ </details>
99
176
 
100
177
  <details>
101
178
  <summary><strong>Full benchmark details</strong></summary>
102
179
 
103
- **Methodology.** Each arm is `claude -p` (Claude Opus 4.7) run headlessly against the repo with `--strict-mcp-config`: **WITH** = CodeGraph's MCP server enabled, **WITHOUT** = an empty MCP config. Built-in Read/Grep/Bash stay available to both. Same question per repo, **4 runs per arm, median reported**. Cost = the run's `total_cost_usd`; Tokens = total tokens processed (input incl. cached + output); Time = wall-clock; Tool calls = every tool invocation, including those inside any sub-agents the model spawns. Repos cloned at `--depth 1` and indexed by the same CodeGraph build that served them. Re-validated on codegraph **v0.9.4** (2026-05-24); per-repo numbers move run-to-run with how hard the without-arm thrashes (the median-of-4 smooths it, but tails remain — e.g. Tokio's without-arm hit $2.41/3m one batch).
180
+ **Methodology.** Each arm is `claude -p` (Claude Opus 4.8) run headlessly against the repo with `--strict-mcp-config`: **WITH** = CodeGraph's MCP server enabled, **WITHOUT** = an empty MCP config. Built-in Read/Grep/Bash stay available to both. Same question per repo, **4 runs per arm, median reported**. Cost = the run's `total_cost_usd`; Tokens = total tokens processed (input incl. cached + output); Time = wall-clock; Tool calls = every tool invocation, including those inside any sub-agents the model spawns. Repos cloned at `--depth 1` and indexed by the same CodeGraph build that served them. Re-validated 2026-06-02 on the current build. These numbers are lower than the prior Opus 4.7 validation — not a CodeGraph regression but a stronger native baseline: Opus 4.8 greps/reads efficiently on the main thread instead of fanning out into large Explore-subagent sweeps, so the no-CodeGraph arm is leaner than it used to be. Per-repo numbers move run-to-run with how hard the without-arm thrashes (the median-of-4 smooths it, but tails remain — e.g. Django's without-arm hit $2.71/14m one batch).
104
181
 
105
182
  **Queries:**
106
183
  | Codebase | Query |
@@ -113,18 +190,7 @@ The gains scale with codebase size: on large repos the agent answers from the in
113
190
  | Gin | "How does gin route requests through its middleware chain?" |
114
191
  | Alamofire | "How does Alamofire build, send, and validate a request?" |
115
192
 
116
- **Raw mediansWITH WITHOUT:**
117
- | Codebase | Cost | Tokens | Time | Tool calls |
118
- |----------|------|--------|------|------------|
119
- | VS Code | $0.60 → $0.80 | 601k → 2.8M | 1m 10s → 2m 26s | 8 → 55 |
120
- | Excalidraw | $0.43 → $0.90 | 344k → 3.5M | 48s → 2m 58s | 3 → 79 |
121
- | Django | $0.59 → $0.67 | 739k → 1.2M | 1m 19s → 1m 38s | 9 → 19 |
122
- | Tokio | $0.42 → $2.41 | 379k → 2.6M | 53s → 3m 2s | 4 → 53 |
123
- | OkHttp | $0.47 → $0.47 | 636k → 730k | 42s → 1m 1s | 6 → 11 |
124
- | Gin | $0.37 → $0.47 | 444k → 675k | 44s → 1m 0s | 6 → 10 |
125
- | Alamofire | $0.61 → $1.14 | 1.0M → 2.8M | 1m 17s → 2m 27s | 12 → 69 |
126
-
127
- **Why CodeGraph wins:** with the index available, the agent answers directly — `codegraph_context` to map the area, then one `codegraph_explore` for the relevant source — and stops, usually with zero file reads. Without it, the agent (and the Explore sub-agents it spawns) spends most of its budget on discovery (find/ls/grep) before reading the right code. CodeGraph only helps when queried *directly*, so its instructions steer agents to answer directly rather than delegate exploration to file-reading sub-agents — otherwise a sub-agent reads files regardless and CodeGraph becomes overhead.
193
+ **Why CodeGraph wins:** with the index available, the agent answers directly usually one `codegraph_explore` returns the relevant source — and stops, usually with zero file reads. Without it, the agent spends most of its budget on discovery (find/ls/grep) before reading the right code. CodeGraph only helps when queried *directly*, so its instructions steer agents to answer directly rather than delegate exploration to file-reading sub-agents — otherwise a sub-agent reads files regardless and CodeGraph becomes overhead.
128
194
 
129
195
  </details>
130
196
 
@@ -299,7 +365,7 @@ npm install -g @colbymchenry/codegraph
299
365
  "permissions": {
300
366
  "allow": [
301
367
  "mcp__codegraph__codegraph_search",
302
- "mcp__codegraph__codegraph_context",
368
+ "mcp__codegraph__codegraph_explore",
303
369
  "mcp__codegraph__codegraph_callers",
304
370
  "mcp__codegraph__codegraph_callees",
305
371
  "mcp__codegraph__codegraph_impact",
@@ -319,7 +385,7 @@ npm install -g @colbymchenry/codegraph
319
385
  CodeGraph's MCP server delivers its usage guidance to your agent **automatically**, in the MCP `initialize` response — there's no instructions file to manage and nothing is added to your `CLAUDE.md` / `AGENTS.md` / `GEMINI.md`. In short, it tells the agent to:
320
386
 
321
387
  - **Answer structural questions directly with CodeGraph** — it *is* the pre-built index, so a grep/read loop just repeats work it already did. Treat the returned source as already read.
322
- - **Pick the tool by intent:** `codegraph_context` to map an area, `codegraph_trace` for "how does X reach Y", `codegraph_explore` to survey several symbols, `codegraph_search` to find a symbol, `codegraph_callers`/`codegraph_callees` to walk call flow, `codegraph_impact` before editing, `codegraph_node` for one symbol's source.
388
+ - **Pick the tool by intent:** `codegraph_explore` for almost anything "how does X work", a flow/"how does X reach Y", or surveying an area (one call returns the relevant symbols' source grouped by file); `codegraph_search` to just locate a symbol; `codegraph_callers`/`codegraph_callees` to walk call flow; `codegraph_impact` before editing; `codegraph_node` for one specific symbol's full source (it returns every overload for an ambiguous name).
323
389
  - **Trust the results — don't re-verify with grep**, and check the staleness banner after edits.
324
390
  - If `.codegraph/` doesn't exist yet, offer to run `codegraph init -i`.
325
391
 
@@ -344,7 +410,7 @@ The exact text is `src/mcp/server-instructions.ts` — the single source of trut
344
410
  ┌───────────────────────────────────────────────────────────────────┐
345
411
  │ CodeGraph MCP Server │
346
412
  │ │
347
- context · trace · explore · callers · callees · impact
413
+ explore · search · callers · callees · impact · node
348
414
  │ │ │
349
415
  │ ▼ │
350
416
  │ SQLite knowledge graph │
@@ -375,7 +441,6 @@ codegraph sync [path] # Incremental update
375
441
  codegraph status [path] # Show statistics
376
442
  codegraph query <search> # Search symbols (--kind, --limit, --json)
377
443
  codegraph files [path] # Show file structure (--format, --filter, --max-depth, --json)
378
- codegraph context <task> # Build context for AI (--format, --max-nodes)
379
444
  codegraph callers <symbol> # Find what calls a function/method (--limit, --json)
380
445
  codegraph callees <symbol> # Find what a function/method calls (--limit, --json)
381
446
  codegraph impact <symbol> # Analyze what code is affected by changing a symbol (--depth, --json)
@@ -419,14 +484,12 @@ When running as an MCP server, CodeGraph exposes these tools to Claude Code:
419
484
 
420
485
  | Tool | Purpose |
421
486
  |------|---------|
487
+ | `codegraph_explore` | **Primary.** Answer almost any question in one call — "how does X work", a flow ("how does X reach Y"), or surveying an area — returning the relevant symbols' verbatim source grouped by file, plus a relationship map and blast radius. Surfaces dynamic-dispatch hops (callbacks, React re-render, interface→impl) grep can't follow. |
422
488
  | `codegraph_search` | Find symbols by name across the codebase |
423
- | `codegraph_context` | Build relevant code context for a task |
424
- | `codegraph_trace` | Trace the call path between two symbols ("how does X reach Y") in one call — each hop with its body inline, following dynamic-dispatch hops (callbacks, React re-render, interface→impl) that grep can't |
425
489
  | `codegraph_callers` | Find what calls a function |
426
490
  | `codegraph_callees` | Find what a function calls |
427
491
  | `codegraph_impact` | Analyze what code is affected by changing a symbol |
428
- | `codegraph_node` | Get details about a specific symbol (optionally with source code) |
429
- | `codegraph_explore` | Return source for several related symbols grouped by file, plus a relationship map, in one call |
492
+ | `codegraph_node` | Get one specific symbol's details + full source (returns every overload for an ambiguous name) |
430
493
  | `codegraph_files` | Get indexed file structure (faster than filesystem scanning) |
431
494
  | `codegraph_status` | Check index health and statistics |
432
495
 
@@ -434,8 +497,14 @@ When running as an MCP server, CodeGraph exposes these tools to Claude Code:
434
497
 
435
498
  ## Library Usage
436
499
 
500
+ CodeGraph can be embedded directly. The npm package re-exports its programmatic
501
+ API, so both `import` and `require` resolve the `CodeGraph` class in your own
502
+ process — handy for embedding it in an app (e.g. an Electron main process).
503
+
437
504
  ```typescript
438
505
  import CodeGraph from '@colbymchenry/codegraph';
506
+ // CommonJS works too:
507
+ // const { CodeGraph } = require('@colbymchenry/codegraph');
439
508
 
440
509
  const cg = await CodeGraph.init('/path/to/project');
441
510
  // Or: const cg = await CodeGraph.open('/path/to/project');
@@ -454,6 +523,21 @@ cg.unwatch(); // stop watching
454
523
  cg.close();
455
524
  ```
456
525
 
526
+ Lower-level building blocks are exported from the same entry point for callers
527
+ that drive the graph directly: `DatabaseConnection`, `QueryBuilder`,
528
+ `getDatabasePath`, `initGrammars` / `loadGrammarsForLanguages`, and `FileLock`.
529
+
530
+ **Embedding requirements**
531
+
532
+ - Install from npm (`npm i @colbymchenry/codegraph`) so the matching
533
+ per-platform package — which carries the compiled library and its
534
+ dependencies — is fetched alongside the shim.
535
+ - The API runs on **your** runtime, so it needs **Node 22.5+** for the built-in
536
+ `node:sqlite` (Electron qualifies when its bundled Node is 22.5+). The CLI and
537
+ MCP server are unaffected — they run on the self-contained bundled runtime.
538
+ - TypeScript types ship with the package. As with any Node-targeting library,
539
+ keep `@types/node` available and `skipLibCheck: true` (the common default).
540
+
457
541
  ---
458
542
 
459
543
  ## Configuration
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CodeGraph CLI
4
+ *
5
+ * Command-line interface for CodeGraph code intelligence.
6
+ *
7
+ * Usage:
8
+ * codegraph Run interactive installer (when no args)
9
+ * codegraph install Run interactive installer
10
+ * codegraph uninstall Remove CodeGraph from your agents
11
+ * codegraph init [path] Initialize CodeGraph in a project
12
+ * codegraph uninit [path] Remove CodeGraph from a project
13
+ * codegraph index [path] Index all files in the project
14
+ * codegraph sync [path] Sync changes since last index
15
+ * codegraph status [path] Show index status
16
+ * codegraph query <search> Search for symbols
17
+ * codegraph files [options] Show project file structure
18
+ * codegraph context <task> Build context for a task
19
+ * codegraph callers <symbol> Find what calls a function/method
20
+ * codegraph callees <symbol> Find what a function/method calls
21
+ * codegraph impact <symbol> Analyze what code is affected by changing a symbol
22
+ * codegraph affected [files] Find test files affected by changes
23
+ */
24
+ export {};
25
+ //# sourceMappingURL=codegraph.d.ts.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Node.js version compatibility check.
3
+ *
4
+ * Node 25.x has a V8 turboshaft WASM JIT Zone allocator bug that
5
+ * reliably crashes CodeGraph with `Fatal process out of memory: Zone`
6
+ * during tree-sitter grammar compilation. This module owns the
7
+ * user-facing banner shown before exit. Kept side-effect-free so it's
8
+ * safe to import from tests without triggering CLI bootstrap.
9
+ */
10
+ /**
11
+ * Build the bordered banner shown when CodeGraph detects an
12
+ * unsupported Node.js major version (currently 25+). Pinned via unit
13
+ * test so the recovery commands and override instructions can't be
14
+ * silently stripped by future edits.
15
+ *
16
+ * Uses ASCII glyphs to stay readable on Windows OEM-codepage consoles
17
+ * (see ../ui/glyphs.ts for the rationale).
18
+ */
19
+ export declare function buildNode25BlockBanner(nodeVersion: string): string;
20
+ /**
21
+ * Lowest supported Node.js major version. Matches the `engines` floor in
22
+ * package.json. Below this, CodeGraph relies on language features / native APIs
23
+ * that aren't present, and the combination is untested. `engines` alone only
24
+ * *warns* on install (unless the user set `engine-strict`), so the CLI bootstrap
25
+ * also hard-blocks here to actually enforce the floor.
26
+ */
27
+ export declare const MIN_NODE_MAJOR = 20;
28
+ /**
29
+ * Build the bordered banner shown when CodeGraph detects a Node.js major below
30
+ * {@link MIN_NODE_MAJOR}. Pinned via unit test so the recovery commands and the
31
+ * override env var can't be silently stripped by future edits.
32
+ *
33
+ * Uses ASCII glyphs to stay readable on Windows OEM-codepage consoles
34
+ * (see ../ui/glyphs.ts for the rationale).
35
+ */
36
+ export declare function buildNodeTooOldBanner(nodeVersion: string): string;
37
+ //# sourceMappingURL=node-version-check.d.ts.map
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CodeGraph preuninstall cleanup script
4
+ *
5
+ * Runs automatically when `npm uninstall -g @colbymchenry/codegraph`
6
+ * is called. Loops over every known agent target's `uninstall(loc)`
7
+ * for the global location only — local-location entries live inside
8
+ * project working trees and aren't ours to nuke at npm-uninstall
9
+ * time.
10
+ *
11
+ * This script must never throw — a failed cleanup must not block
12
+ * uninstall.
13
+ */
14
+ //# sourceMappingURL=uninstall.d.ts.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Context Formatter
3
+ *
4
+ * Formats TaskContext as markdown or JSON for consumption by Claude.
5
+ */
6
+ import { Node, TaskContext, Subgraph } from '../types';
7
+ /**
8
+ * Format context as markdown
9
+ *
10
+ * Creates a compact markdown document optimized for Claude with minimal context usage:
11
+ * - Brief summary
12
+ * - Entry points with locations
13
+ * - Code blocks only for key symbols
14
+ */
15
+ export declare function formatContextAsMarkdown(context: TaskContext): string;
16
+ /**
17
+ * Format context as JSON
18
+ *
19
+ * Returns a structured JSON representation suitable for programmatic use.
20
+ */
21
+ export declare function formatContextAsJson(context: TaskContext): string;
22
+ /**
23
+ * Format a subgraph as an ASCII tree structure
24
+ */
25
+ export declare function formatSubgraphTree(subgraph: Subgraph, entryPoints: Node[]): string;
26
+ /**
27
+ * Format bytes as human-readable string
28
+ */
29
+ export declare function formatBytes(bytes: number): string;
30
+ //# sourceMappingURL=formatter.d.ts.map
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Context Builder
3
+ *
4
+ * Builds rich context for tasks by combining FTS search with graph traversal.
5
+ * Outputs structured context ready to inject into Claude.
6
+ */
7
+ import { Subgraph, TaskContext, TaskInput, BuildContextOptions, FindRelevantContextOptions } from '../types';
8
+ import { QueryBuilder } from '../db/queries';
9
+ import { GraphTraverser } from '../graph';
10
+ export { LOW_CONFIDENCE_MARKER } from './markers';
11
+ /**
12
+ * Context Builder
13
+ *
14
+ * Coordinates semantic search and graph traversal to build
15
+ * comprehensive context for tasks.
16
+ */
17
+ export declare class ContextBuilder {
18
+ private projectRoot;
19
+ private queries;
20
+ private traverser;
21
+ constructor(projectRoot: string, queries: QueryBuilder, traverser: GraphTraverser);
22
+ /**
23
+ * Build context for a task
24
+ *
25
+ * Pipeline:
26
+ * 1. Parse task input (string or {title, description})
27
+ * 2. Run semantic search to find entry points
28
+ * 3. Expand graph around entry points
29
+ * 4. Extract code blocks for key nodes
30
+ * 5. Format output for Claude
31
+ *
32
+ * @param input - Task description or object with title/description
33
+ * @param options - Build options
34
+ * @returns TaskContext (structured) or formatted string
35
+ */
36
+ buildContext(input: TaskInput, options?: BuildContextOptions): Promise<TaskContext | string>;
37
+ /**
38
+ * Honest handoff appended when retrieval confidence is low (the query matched
39
+ * mostly common words). Instead of the usual "this covers the surface" framing
40
+ * — which, when wrong, sends the agent off to Read/Grep — it admits the
41
+ * uncertainty and routes the agent to the precise tools (explore with real
42
+ * symbol names, search, or files to browse the closest areas we *did* surface).
43
+ */
44
+ private buildLowConfidenceNote;
45
+ /**
46
+ * Surface short call-paths among the symbols this context already found,
47
+ * derived in-memory from the subgraph's `calls` edges (no extra queries).
48
+ *
49
+ * This bakes the value of path-finding INTO the always-loaded `context` tool.
50
+ * Agents reliably read context's output but do NOT discover/adopt a standalone
51
+ * trace tool (in deferred-MCP harnesses they only ToolSearch-select tools they
52
+ * already know). Delivering the flow here means "how does X reach Y" is
53
+ * answered without the agent needing to find, load, or choose a new tool.
54
+ * Chains stop where the static call graph ends (e.g. dynamic dispatch) — that
55
+ * truncation is honest, and the agent can codegraph_node the last hop to bridge.
56
+ */
57
+ private buildCallPathsSection;
58
+ /**
59
+ * Find relevant subgraph for a query
60
+ *
61
+ * Uses hybrid search combining exact symbol lookup with semantic search:
62
+ * 1. Extract potential symbol names from query
63
+ * 2. Look up exact matches for those symbols (high confidence)
64
+ * 3. Use semantic search for concept matching
65
+ * 4. Merge results, prioritizing exact matches
66
+ * 5. Traverse graph from entry points
67
+ *
68
+ * @param query - Natural language query
69
+ * @param options - Search and traversal options
70
+ * @returns Subgraph of relevant nodes and edges
71
+ */
72
+ findRelevantContext(query: string, options?: FindRelevantContextOptions): Promise<Subgraph>;
73
+ /**
74
+ * Get the source code for a node
75
+ *
76
+ * Reads the file and extracts the code between startLine and endLine.
77
+ *
78
+ * @param nodeId - ID of the node
79
+ * @returns Code string or null if not found
80
+ */
81
+ getCode(nodeId: string): Promise<string | null>;
82
+ /**
83
+ * Extract code from a node's source file
84
+ */
85
+ private extractNodeCode;
86
+ /**
87
+ * Get entry points from a subgraph (the root nodes)
88
+ */
89
+ private getEntryPoints;
90
+ /**
91
+ * Extract code blocks for key nodes in the subgraph
92
+ */
93
+ private extractCodeBlocks;
94
+ /**
95
+ * Get unique files from a subgraph
96
+ */
97
+ private getRelatedFiles;
98
+ /**
99
+ * Generate a summary of the context
100
+ */
101
+ private generateSummary;
102
+ /**
103
+ * Resolve import/export nodes to their actual definitions
104
+ *
105
+ * When search returns `import { TerminalPanel }`, users want the TerminalPanel
106
+ * class definition, not the import statement. This follows the `imports` edge
107
+ * to find and return the actual definition instead.
108
+ *
109
+ * @param results - Search results that may include import/export nodes
110
+ * @returns Results with imports resolved to definitions where possible
111
+ */
112
+ private resolveImportsToDefinitions;
113
+ }
114
+ /**
115
+ * Create a context builder
116
+ */
117
+ export declare function createContextBuilder(projectRoot: string, queries: QueryBuilder, traverser: GraphTraverser): ContextBuilder;
118
+ export { formatContextAsMarkdown, formatContextAsJson } from './formatter';
119
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Stable sentinel strings shared between the context builder (which emits them
3
+ * into its markdown) and the MCP layer (which detects them to adjust framing).
4
+ *
5
+ * Intentionally a dependency-free leaf module: the MCP tool layer imports this
6
+ * to recognise a low-confidence response, and routing that recognition through
7
+ * the full context module would drag its dependencies onto the cold-start path.
8
+ * Keep this file import-free.
9
+ */
10
+ /**
11
+ * Heading that leads the honest low-confidence handoff appended to a context
12
+ * response when the query resolved only to weak/isolated matches. The MCP layer
13
+ * checks for it to suppress the contradictory "this is comprehensive, don't call
14
+ * explore" small-repo footer. Changing the text is a breaking sentinel change —
15
+ * both the emitter (`ContextBuilder`) and the detector (`src/mcp/tools.ts`)
16
+ * import this constant, so they stay in sync automatically.
17
+ */
18
+ export declare const LOW_CONFIDENCE_MARKER = "### \u26A0\uFE0F Low-confidence match";
19
+ //# sourceMappingURL=markers.d.ts.map
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Database Layer
3
+ *
4
+ * Handles SQLite database initialization and connection management.
5
+ */
6
+ import { SqliteDatabase, SqliteBackend } from './sqlite-adapter';
7
+ import { SchemaVersion } from '../types';
8
+ export { SqliteDatabase, SqliteBackend } from './sqlite-adapter';
9
+ /**
10
+ * Database connection wrapper with lifecycle management
11
+ */
12
+ export declare class DatabaseConnection {
13
+ private db;
14
+ private dbPath;
15
+ private backend;
16
+ private constructor();
17
+ /**
18
+ * Initialize a new database at the given path
19
+ */
20
+ static initialize(dbPath: string): DatabaseConnection;
21
+ /**
22
+ * Open an existing database
23
+ */
24
+ static open(dbPath: string): DatabaseConnection;
25
+ /**
26
+ * Get the underlying database instance
27
+ */
28
+ getDb(): SqliteDatabase;
29
+ /**
30
+ * Get the SQLite backend serving this connection. Per-instance so
31
+ * MCP cross-project queries report the right backend even when
32
+ * multiple project DBs are open in the same process.
33
+ */
34
+ getBackend(): SqliteBackend;
35
+ /**
36
+ * Get database file path
37
+ */
38
+ getPath(): string;
39
+ /**
40
+ * The journal mode actually in effect (e.g. 'wal', 'delete').
41
+ *
42
+ * SQLite silently keeps the prior mode if WAL can't be enabled — e.g. on
43
+ * filesystems without shared-memory support (some network/virtualized mounts,
44
+ * WSL2 /mnt), and always on the wasm backend. So the effective mode can differ
45
+ * from what `configureConnection` requested. Surfaced in `codegraph status` so
46
+ * a "database is locked" report is triageable: 'wal' ⇒ readers never block on a
47
+ * writer; anything else ⇒ they can. See issue #238.
48
+ */
49
+ getJournalMode(): string;
50
+ /**
51
+ * Get current schema version
52
+ */
53
+ getSchemaVersion(): SchemaVersion | null;
54
+ /**
55
+ * Execute a function within a transaction
56
+ */
57
+ transaction<T>(fn: () => T): T;
58
+ /**
59
+ * Get database file size in bytes
60
+ */
61
+ getSize(): number;
62
+ /**
63
+ * Optimize database (vacuum and analyze)
64
+ */
65
+ optimize(): void;
66
+ /**
67
+ * Lightweight, non-blocking maintenance to run after bulk writes
68
+ * (indexAll, sync). Two operations:
69
+ *
70
+ * - `PRAGMA optimize` — incremental ANALYZE; SQLite only re-analyzes
71
+ * tables whose row counts changed materially since the last
72
+ * ANALYZE. Without it, the query planner has no statistics on the
73
+ * freshly-bulk-loaded tables and can pick suboptimal indexes.
74
+ *
75
+ * - `PRAGMA wal_checkpoint(PASSIVE)` — fold pending WAL pages back
76
+ * into the main database file so the WAL file doesn't grow
77
+ * unboundedly between automatic checkpoints (auto-fires at 1000
78
+ * pages by default; large indexAll runs blow past that).
79
+ *
80
+ * Both operations are silently swallowed on failure — they're a
81
+ * best-effort optimization, never load-bearing for correctness.
82
+ */
83
+ runMaintenance(): void;
84
+ /**
85
+ * Close the database connection
86
+ */
87
+ close(): void;
88
+ /**
89
+ * Check if the database connection is open
90
+ */
91
+ isOpen(): boolean;
92
+ }
93
+ /**
94
+ * Default database filename
95
+ */
96
+ export declare const DATABASE_FILENAME = "codegraph.db";
97
+ /**
98
+ * Get the default database path for a project
99
+ */
100
+ export declare function getDatabasePath(projectRoot: string): string;
101
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Database Migrations
3
+ *
4
+ * Schema versioning and migration support.
5
+ */
6
+ import { SqliteDatabase } from './sqlite-adapter';
7
+ /**
8
+ * Current schema version
9
+ */
10
+ export declare const CURRENT_SCHEMA_VERSION = 4;
11
+ /**
12
+ * Migration definition
13
+ */
14
+ interface Migration {
15
+ version: number;
16
+ description: string;
17
+ up: (db: SqliteDatabase) => void;
18
+ }
19
+ /**
20
+ * Get the current schema version from the database
21
+ */
22
+ export declare function getCurrentVersion(db: SqliteDatabase): number;
23
+ /**
24
+ * Run all pending migrations
25
+ */
26
+ export declare function runMigrations(db: SqliteDatabase, fromVersion: number): void;
27
+ /**
28
+ * Check if the database needs migration
29
+ */
30
+ export declare function needsMigration(db: SqliteDatabase): boolean;
31
+ /**
32
+ * Get list of pending migrations
33
+ */
34
+ export declare function getPendingMigrations(db: SqliteDatabase): Migration[];
35
+ /**
36
+ * Get migration history from database
37
+ */
38
+ export declare function getMigrationHistory(db: SqliteDatabase): Array<{
39
+ version: number;
40
+ appliedAt: number;
41
+ description: string | null;
42
+ }>;
43
+ export {};
44
+ //# sourceMappingURL=migrations.d.ts.map