@colbymchenry/codegraph 0.9.6 → 0.9.8
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.
- package/README.md +122 -57
- package/dist/bin/codegraph.d.ts +25 -0
- package/dist/bin/node-version-check.d.ts +37 -0
- package/dist/bin/uninstall.d.ts +14 -0
- package/dist/context/formatter.d.ts +30 -0
- package/dist/context/index.d.ts +110 -0
- package/dist/db/index.d.ts +101 -0
- package/dist/db/migrations.d.ts +44 -0
- package/dist/db/queries.d.ts +344 -0
- package/dist/db/sqlite-adapter.d.ts +46 -0
- package/dist/directory.d.ts +57 -0
- package/dist/errors.d.ts +136 -0
- package/dist/extraction/dfm-extractor.d.ts +31 -0
- package/dist/extraction/generated-detection.d.ts +30 -0
- package/dist/extraction/grammars.d.ts +100 -0
- package/dist/extraction/index.d.ts +138 -0
- package/dist/extraction/languages/c-cpp.d.ts +4 -0
- package/dist/extraction/languages/csharp.d.ts +3 -0
- package/dist/extraction/languages/dart.d.ts +3 -0
- package/dist/extraction/languages/go.d.ts +3 -0
- package/dist/extraction/languages/index.d.ts +10 -0
- package/dist/extraction/languages/java.d.ts +3 -0
- package/dist/extraction/languages/javascript.d.ts +3 -0
- package/dist/extraction/languages/kotlin.d.ts +3 -0
- package/dist/extraction/languages/lua.d.ts +3 -0
- package/dist/extraction/languages/luau.d.ts +3 -0
- package/dist/extraction/languages/objc.d.ts +3 -0
- package/dist/extraction/languages/pascal.d.ts +3 -0
- package/dist/extraction/languages/php.d.ts +3 -0
- package/dist/extraction/languages/python.d.ts +3 -0
- package/dist/extraction/languages/ruby.d.ts +3 -0
- package/dist/extraction/languages/rust.d.ts +3 -0
- package/dist/extraction/languages/scala.d.ts +3 -0
- package/dist/extraction/languages/swift.d.ts +3 -0
- package/dist/extraction/languages/typescript.d.ts +3 -0
- package/dist/extraction/liquid-extractor.d.ts +52 -0
- package/dist/extraction/mybatis-extractor.d.ts +48 -0
- package/dist/extraction/parse-worker.d.ts +8 -0
- package/dist/extraction/svelte-extractor.d.ts +56 -0
- package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
- package/dist/extraction/tree-sitter-types.d.ts +193 -0
- package/dist/extraction/tree-sitter.d.ts +291 -0
- package/dist/extraction/vue-extractor.d.ts +36 -0
- package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
- package/dist/graph/index.d.ts +8 -0
- package/dist/graph/queries.d.ts +106 -0
- package/dist/graph/traversal.d.ts +127 -0
- package/dist/index.d.ts +492 -0
- package/dist/installer/config-writer.d.ts +28 -0
- package/dist/installer/index.d.ts +100 -0
- package/dist/installer/instructions-template.d.ts +18 -0
- package/dist/installer/targets/antigravity.d.ts +57 -0
- package/dist/installer/targets/claude.d.ts +56 -0
- package/dist/installer/targets/codex.d.ts +18 -0
- package/dist/installer/targets/cursor.d.ts +35 -0
- package/dist/installer/targets/gemini.d.ts +26 -0
- package/dist/installer/targets/hermes.d.ts +18 -0
- package/dist/installer/targets/kiro.d.ts +27 -0
- package/dist/installer/targets/opencode.d.ts +30 -0
- package/dist/installer/targets/registry.d.ts +35 -0
- package/dist/installer/targets/shared.d.ts +77 -0
- package/dist/installer/targets/toml.d.ts +52 -0
- package/dist/installer/targets/types.d.ts +101 -0
- package/dist/mcp/daemon-paths.d.ts +46 -0
- package/dist/mcp/daemon.d.ts +161 -0
- package/dist/mcp/engine.d.ts +105 -0
- package/dist/mcp/index.d.ts +112 -0
- package/dist/mcp/proxy.d.ts +81 -0
- package/dist/mcp/server-instructions.d.ts +19 -0
- package/dist/mcp/session.d.ts +77 -0
- package/dist/mcp/tools.d.ts +423 -0
- package/dist/mcp/transport.d.ts +188 -0
- package/dist/mcp/version.d.ts +19 -0
- package/dist/resolution/callback-synthesizer.d.ts +10 -0
- package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
- package/dist/resolution/frameworks/csharp.d.ts +8 -0
- package/dist/resolution/frameworks/drupal.d.ts +51 -0
- package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
- package/dist/resolution/frameworks/express.d.ts +8 -0
- package/dist/resolution/frameworks/fabric.d.ts +3 -0
- package/dist/resolution/frameworks/go.d.ts +8 -0
- package/dist/resolution/frameworks/index.d.ts +48 -0
- package/dist/resolution/frameworks/java.d.ts +8 -0
- package/dist/resolution/frameworks/laravel.d.ts +13 -0
- package/dist/resolution/frameworks/nestjs.d.ts +26 -0
- package/dist/resolution/frameworks/play.d.ts +19 -0
- package/dist/resolution/frameworks/python.d.ts +10 -0
- package/dist/resolution/frameworks/react-native.d.ts +3 -0
- package/dist/resolution/frameworks/react.d.ts +8 -0
- package/dist/resolution/frameworks/ruby.d.ts +8 -0
- package/dist/resolution/frameworks/rust.d.ts +8 -0
- package/dist/resolution/frameworks/svelte.d.ts +9 -0
- package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
- package/dist/resolution/frameworks/swift.d.ts +10 -0
- package/dist/resolution/frameworks/vue.d.ts +9 -0
- package/dist/resolution/go-module.d.ts +26 -0
- package/dist/resolution/import-resolver.d.ts +68 -0
- package/dist/resolution/index.d.ts +116 -0
- package/dist/resolution/lru-cache.d.ts +24 -0
- package/dist/resolution/name-matcher.d.ts +32 -0
- package/dist/resolution/path-aliases.d.ts +68 -0
- package/dist/resolution/strip-comments.d.ts +27 -0
- package/dist/resolution/swift-objc-bridge.d.ts +134 -0
- package/dist/resolution/types.d.ts +209 -0
- package/dist/search/query-parser.d.ts +57 -0
- package/dist/search/query-utils.d.ts +53 -0
- package/dist/sync/git-hooks.d.ts +45 -0
- package/dist/sync/index.d.ts +19 -0
- package/dist/sync/watch-policy.d.ts +48 -0
- package/dist/sync/watcher.d.ts +191 -0
- package/dist/sync/worktree.d.ts +54 -0
- package/dist/types.d.ts +369 -0
- package/dist/ui/glyphs.d.ts +42 -0
- package/dist/ui/shimmer-progress.d.ts +11 -0
- package/dist/ui/shimmer-worker.d.ts +2 -0
- package/dist/ui/types.d.ts +17 -0
- package/dist/utils.d.ts +205 -0
- package/npm-sdk.js +75 -0
- 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
|
-
**~
|
|
7
|
+
**~25% cheaper · ~62% 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
|

|
|
@@ -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
|
|
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-05-29), on the build with per-symbol adaptive `codegraph_explore` sizing._
|
|
85
87
|
|
|
86
|
-
> **Average:
|
|
88
|
+
> **Average: 25% cheaper · 57% fewer tokens · 23% faster · 62% fewer tool calls**
|
|
87
89
|
|
|
88
90
|
| Codebase | Language | Cost | Tokens | Time | Tool calls |
|
|
89
91
|
|----------|----------|------|--------|------|------------|
|
|
90
|
-
| **VS Code** | TypeScript · ~10k files |
|
|
91
|
-
| **Excalidraw** | TypeScript · ~640 |
|
|
92
|
-
| **Django** | Python · ~3k |
|
|
93
|
-
| **Tokio** | Rust · ~790 |
|
|
94
|
-
| **OkHttp** | Java · ~645 |
|
|
95
|
-
| **Gin** | Go · ~110 |
|
|
96
|
-
| **Alamofire** | Swift · ~110 |
|
|
92
|
+
| **VS Code** | TypeScript · ~10k files | 33% cheaper | 70% fewer | 27% faster | 80% fewer |
|
|
93
|
+
| **Excalidraw** | TypeScript · ~640 | 27% cheaper | 61% fewer | 26% faster | 70% fewer |
|
|
94
|
+
| **Django** | Python · ~3k | 23% cheaper | 70% fewer | 28% faster | 77% fewer |
|
|
95
|
+
| **Tokio** | Rust · ~790 | 35% cheaper | 70% fewer | 37% faster | 79% fewer |
|
|
96
|
+
| **OkHttp** | Java · ~645 | 11% cheaper | 48% fewer | 26% faster | 70% fewer |
|
|
97
|
+
| **Gin** | Go · ~110 | 15% cheaper | 35% fewer | 9% faster | 47% fewer |
|
|
98
|
+
| **Alamofire** | Swift · ~110 | 28% cheaper | 46% fewer | 7% faster | 13% fewer |
|
|
99
|
+
|
|
100
|
+
CodeGraph cuts **cost, tokens, tool calls, and time on every repo** — across small, medium, and large codebases — and answers most of them with **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. The cost margin is narrowest on the smallest repos, where a modern model's native search is already cheap, but it stays solidly positive across the board.
|
|
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 37s | 2m 13s | 27% faster |
|
|
109
|
+
| File Reads | 0 | 9 | −9 |
|
|
110
|
+
| Grep/Bash | 0 | 11 | −11 |
|
|
111
|
+
| Tool calls | 4 | 21 | 80% fewer |
|
|
112
|
+
| Total tokens | 545k | 1.79M | 70% fewer |
|
|
113
|
+
| Cost | $0.55 | $0.83 | 33% cheaper |
|
|
114
|
+
|
|
115
|
+
**Excalidraw** · ~640 files
|
|
116
|
+
| Metric | WITH cg | WITHOUT cg | Δ |
|
|
117
|
+
|---|---|---|---|
|
|
118
|
+
| Time | 1m 34s | 2m 6s | 26% faster |
|
|
119
|
+
| File Reads | 0 | 7 | −7 |
|
|
120
|
+
| Grep/Bash | 0 | 8 | −8 |
|
|
121
|
+
| Tool calls | 5 | 15 | 70% fewer |
|
|
122
|
+
| Total tokens | 651k | 1.69M | 61% fewer |
|
|
123
|
+
| Cost | $0.57 | $0.78 | 27% cheaper |
|
|
124
|
+
|
|
125
|
+
**Django** · ~3k files
|
|
126
|
+
| Metric | WITH cg | WITHOUT cg | Δ |
|
|
127
|
+
|---|---|---|---|
|
|
128
|
+
| Time | 1m 25s | 1m 58s | 28% faster |
|
|
129
|
+
| File Reads | 0 | 9 | −9 |
|
|
130
|
+
| Grep/Bash | 0 | 5 | −5 |
|
|
131
|
+
| Tool calls | 3 | 13 | 77% fewer |
|
|
132
|
+
| Total tokens | 419k | 1.41M | 70% fewer |
|
|
133
|
+
| Cost | $0.48 | $0.62 | 23% cheaper |
|
|
134
|
+
|
|
135
|
+
**Tokio** · ~790 files
|
|
136
|
+
| Metric | WITH cg | WITHOUT cg | Δ |
|
|
137
|
+
|---|---|---|---|
|
|
138
|
+
| Time | 1m 28s | 2m 20s | 37% faster |
|
|
139
|
+
| File Reads | 0 | 8 | −8 |
|
|
140
|
+
| Grep/Bash | 0 | 6 | −6 |
|
|
141
|
+
| Tool calls | 3 | 14 | 79% fewer |
|
|
142
|
+
| Total tokens | 522k | 1.73M | 70% fewer |
|
|
143
|
+
| Cost | $0.53 | $0.82 | 35% cheaper |
|
|
144
|
+
|
|
145
|
+
**OkHttp** · ~645 files
|
|
146
|
+
| Metric | WITH cg | WITHOUT cg | Δ |
|
|
147
|
+
|---|---|---|---|
|
|
148
|
+
| Time | 1m 6s | 1m 29s | 26% faster |
|
|
149
|
+
| File Reads | 1 | 4 | −3 |
|
|
150
|
+
| Grep/Bash | 0 | 6 | −6 |
|
|
151
|
+
| Tool calls | 3 | 10 | 70% fewer |
|
|
152
|
+
| Total tokens | 572k | 1.10M | 48% fewer |
|
|
153
|
+
| Cost | $0.48 | $0.55 | 11% cheaper |
|
|
154
|
+
|
|
155
|
+
**Gin** · ~110 files
|
|
156
|
+
| Metric | WITH cg | WITHOUT cg | Δ |
|
|
157
|
+
|---|---|---|---|
|
|
158
|
+
| Time | 1m 28s | 1m 37s | 9% faster |
|
|
159
|
+
| File Reads | 0 | 6 | −6 |
|
|
160
|
+
| Grep/Bash | 0 | 2 | −2 |
|
|
161
|
+
| Tool calls | 5 | 9 | 47% fewer |
|
|
162
|
+
| Total tokens | 552k | 847k | 35% fewer |
|
|
163
|
+
| Cost | $0.48 | $0.57 | 15% cheaper |
|
|
164
|
+
|
|
165
|
+
**Alamofire** · ~110 files
|
|
166
|
+
| Metric | WITH cg | WITHOUT cg | Δ |
|
|
167
|
+
|---|---|---|---|
|
|
168
|
+
| Time | 2m 11s | 2m 21s | 7% faster |
|
|
169
|
+
| File Reads | 3 | 9 | −6 |
|
|
170
|
+
| Grep/Bash | 2 | 4 | −2 |
|
|
171
|
+
| Tool calls | 11 | 12 | 13% fewer |
|
|
172
|
+
| Total tokens | 1.13M | 2.10M | 46% fewer |
|
|
173
|
+
| Cost | $0.69 | $0.95 | 28% cheaper |
|
|
97
174
|
|
|
98
|
-
|
|
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.
|
|
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-05-29 on the build with per-symbol adaptive `codegraph_explore` sizing. 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
|
-
**
|
|
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 — `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 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
|
|
|
@@ -236,7 +302,7 @@ The installer will:
|
|
|
236
302
|
- Ask which agent(s) to configure — auto-detects installed ones from: **Claude Code**, **Cursor**, **Codex CLI**, **opencode**, **Hermes Agent**, **Gemini CLI**, **Antigravity IDE**, **Kiro**
|
|
237
303
|
- Prompt to install `codegraph` on your PATH (so agents can launch the MCP server)
|
|
238
304
|
- Ask whether configs apply to all your projects or just this one
|
|
239
|
-
- Write each chosen agent's MCP server config
|
|
305
|
+
- Write each chosen agent's MCP server config (the codegraph usage guide is delivered by the MCP server itself, so no instructions file is added to `CLAUDE.md` / `AGENTS.md` / etc.)
|
|
240
306
|
- Set up auto-allow permissions when Claude Code is one of the targets
|
|
241
307
|
- Initialize your current project (local installs only)
|
|
242
308
|
|
|
@@ -268,7 +334,7 @@ cd your-project
|
|
|
268
334
|
codegraph init -i
|
|
269
335
|
```
|
|
270
336
|
|
|
271
|
-
Builds the per-project knowledge graph index.
|
|
337
|
+
Builds the per-project knowledge graph index. A single global `codegraph install` works in every project you open — no need to re-run the installer per project.
|
|
272
338
|
|
|
273
339
|
That's it — your agent will use CodeGraph tools automatically when a `.codegraph/` directory exists.
|
|
274
340
|
|
|
@@ -314,39 +380,16 @@ npm install -g @colbymchenry/codegraph
|
|
|
314
380
|
</details>
|
|
315
381
|
|
|
316
382
|
<details>
|
|
317
|
-
<summary><strong>
|
|
383
|
+
<summary><strong>Agent Tool Guidance</strong></summary>
|
|
318
384
|
|
|
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
|
-
|
|
322
|
-
|
|
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.
|
|
388
|
+
- **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.
|
|
389
|
+
- **Trust the results — don't re-verify with grep**, and check the staleness banner after edits.
|
|
390
|
+
- If `.codegraph/` doesn't exist yet, offer to run `codegraph init -i`.
|
|
323
391
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
### If `.codegraph/` exists in the project
|
|
327
|
-
|
|
328
|
-
**Answer directly with CodeGraph — don't delegate exploration to a file-reading sub-agent or a grep/read loop.** CodeGraph *is* the pre-built search index; re-deriving its answers with grep + Read repeats work it already did and costs more for the same result. For "how does X work?", architecture, trace, or where-is-X questions, answer in a handful of CodeGraph calls and stop — typically with **zero file reads**. The returned source is complete and authoritative: treat it as already read and do not re-open those files. Reach for raw Read/Grep only to confirm a specific detail CodeGraph didn't cover.
|
|
329
|
-
|
|
330
|
-
**Tool selection by intent:**
|
|
331
|
-
|
|
332
|
-
| Tool | Use For |
|
|
333
|
-
|------|---------|
|
|
334
|
-
| `codegraph_context` | Map a task / feature / area first — composes search + node + callers + callees in one call |
|
|
335
|
-
| `codegraph_trace` | "How does X reach Y" — the call path, each hop's body inline (follows dynamic-dispatch hops grep can't) |
|
|
336
|
-
| `codegraph_explore` | Survey several related symbols' source in ONE budget-capped call |
|
|
337
|
-
| `codegraph_search` | Find a symbol by name |
|
|
338
|
-
| `codegraph_callers` / `codegraph_callees` | Walk call flow one hop at a time |
|
|
339
|
-
| `codegraph_impact` | Check what's affected before editing |
|
|
340
|
-
| `codegraph_node` | Get a single symbol's source / signature |
|
|
341
|
-
|
|
342
|
-
A direct CodeGraph answer is a handful of calls; a grep/read exploration is dozens.
|
|
343
|
-
|
|
344
|
-
### If `.codegraph/` does NOT exist
|
|
345
|
-
|
|
346
|
-
At the start of a session, ask the user if they'd like to initialize CodeGraph:
|
|
347
|
-
|
|
348
|
-
"I notice this project doesn't have CodeGraph initialized. Would you like me to run `codegraph init -i` to build a code knowledge graph?"
|
|
349
|
-
```
|
|
392
|
+
The exact text is `src/mcp/server-instructions.ts` — the single source of truth.
|
|
350
393
|
|
|
351
394
|
</details>
|
|
352
395
|
|
|
@@ -457,8 +500,14 @@ When running as an MCP server, CodeGraph exposes these tools to Claude Code:
|
|
|
457
500
|
|
|
458
501
|
## Library Usage
|
|
459
502
|
|
|
503
|
+
CodeGraph can be embedded directly. The npm package re-exports its programmatic
|
|
504
|
+
API, so both `import` and `require` resolve the `CodeGraph` class in your own
|
|
505
|
+
process — handy for embedding it in an app (e.g. an Electron main process).
|
|
506
|
+
|
|
460
507
|
```typescript
|
|
461
508
|
import CodeGraph from '@colbymchenry/codegraph';
|
|
509
|
+
// CommonJS works too:
|
|
510
|
+
// const { CodeGraph } = require('@colbymchenry/codegraph');
|
|
462
511
|
|
|
463
512
|
const cg = await CodeGraph.init('/path/to/project');
|
|
464
513
|
// Or: const cg = await CodeGraph.open('/path/to/project');
|
|
@@ -477,6 +526,21 @@ cg.unwatch(); // stop watching
|
|
|
477
526
|
cg.close();
|
|
478
527
|
```
|
|
479
528
|
|
|
529
|
+
Lower-level building blocks are exported from the same entry point for callers
|
|
530
|
+
that drive the graph directly: `DatabaseConnection`, `QueryBuilder`,
|
|
531
|
+
`getDatabasePath`, `initGrammars` / `loadGrammarsForLanguages`, and `FileLock`.
|
|
532
|
+
|
|
533
|
+
**Embedding requirements**
|
|
534
|
+
|
|
535
|
+
- Install from npm (`npm i @colbymchenry/codegraph`) so the matching
|
|
536
|
+
per-platform package — which carries the compiled library and its
|
|
537
|
+
dependencies — is fetched alongside the shim.
|
|
538
|
+
- The API runs on **your** runtime, so it needs **Node 22.5+** for the built-in
|
|
539
|
+
`node:sqlite` (Electron qualifies when its bundled Node is 22.5+). The CLI and
|
|
540
|
+
MCP server are unaffected — they run on the self-contained bundled runtime.
|
|
541
|
+
- TypeScript types ship with the package. As with any Node-targeting library,
|
|
542
|
+
keep `@types/node` available and `skipLibCheck: true` (the common default).
|
|
543
|
+
|
|
480
544
|
---
|
|
481
545
|
|
|
482
546
|
## Configuration
|
|
@@ -517,7 +581,8 @@ See [Get Started](#get-started) for the one-line install commands.
|
|
|
517
581
|
## Supported Agents
|
|
518
582
|
|
|
519
583
|
The interactive installer auto-detects and configures each of these — wiring up
|
|
520
|
-
the MCP server
|
|
584
|
+
the MCP server (which delivers its own usage guidance, so no instructions file
|
|
585
|
+
is written):
|
|
521
586
|
|
|
522
587
|
- **Claude Code**
|
|
523
588
|
- **Cursor**
|
|
@@ -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,110 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Context Builder
|
|
12
|
+
*
|
|
13
|
+
* Coordinates semantic search and graph traversal to build
|
|
14
|
+
* comprehensive context for tasks.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ContextBuilder {
|
|
17
|
+
private projectRoot;
|
|
18
|
+
private queries;
|
|
19
|
+
private traverser;
|
|
20
|
+
constructor(projectRoot: string, queries: QueryBuilder, traverser: GraphTraverser);
|
|
21
|
+
/**
|
|
22
|
+
* Build context for a task
|
|
23
|
+
*
|
|
24
|
+
* Pipeline:
|
|
25
|
+
* 1. Parse task input (string or {title, description})
|
|
26
|
+
* 2. Run semantic search to find entry points
|
|
27
|
+
* 3. Expand graph around entry points
|
|
28
|
+
* 4. Extract code blocks for key nodes
|
|
29
|
+
* 5. Format output for Claude
|
|
30
|
+
*
|
|
31
|
+
* @param input - Task description or object with title/description
|
|
32
|
+
* @param options - Build options
|
|
33
|
+
* @returns TaskContext (structured) or formatted string
|
|
34
|
+
*/
|
|
35
|
+
buildContext(input: TaskInput, options?: BuildContextOptions): Promise<TaskContext | string>;
|
|
36
|
+
/**
|
|
37
|
+
* Surface short call-paths among the symbols this context already found,
|
|
38
|
+
* derived in-memory from the subgraph's `calls` edges (no extra queries).
|
|
39
|
+
*
|
|
40
|
+
* This bakes the value of path-finding INTO the always-loaded `context` tool.
|
|
41
|
+
* Agents reliably read context's output but do NOT discover/adopt a standalone
|
|
42
|
+
* trace tool (in deferred-MCP harnesses they only ToolSearch-select tools they
|
|
43
|
+
* already know). Delivering the flow here means "how does X reach Y" is
|
|
44
|
+
* answered without the agent needing to find, load, or choose a new tool.
|
|
45
|
+
* Chains stop where the static call graph ends (e.g. dynamic dispatch) — that
|
|
46
|
+
* truncation is honest, and the agent can codegraph_node the last hop to bridge.
|
|
47
|
+
*/
|
|
48
|
+
private buildCallPathsSection;
|
|
49
|
+
/**
|
|
50
|
+
* Find relevant subgraph for a query
|
|
51
|
+
*
|
|
52
|
+
* Uses hybrid search combining exact symbol lookup with semantic search:
|
|
53
|
+
* 1. Extract potential symbol names from query
|
|
54
|
+
* 2. Look up exact matches for those symbols (high confidence)
|
|
55
|
+
* 3. Use semantic search for concept matching
|
|
56
|
+
* 4. Merge results, prioritizing exact matches
|
|
57
|
+
* 5. Traverse graph from entry points
|
|
58
|
+
*
|
|
59
|
+
* @param query - Natural language query
|
|
60
|
+
* @param options - Search and traversal options
|
|
61
|
+
* @returns Subgraph of relevant nodes and edges
|
|
62
|
+
*/
|
|
63
|
+
findRelevantContext(query: string, options?: FindRelevantContextOptions): Promise<Subgraph>;
|
|
64
|
+
/**
|
|
65
|
+
* Get the source code for a node
|
|
66
|
+
*
|
|
67
|
+
* Reads the file and extracts the code between startLine and endLine.
|
|
68
|
+
*
|
|
69
|
+
* @param nodeId - ID of the node
|
|
70
|
+
* @returns Code string or null if not found
|
|
71
|
+
*/
|
|
72
|
+
getCode(nodeId: string): Promise<string | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Extract code from a node's source file
|
|
75
|
+
*/
|
|
76
|
+
private extractNodeCode;
|
|
77
|
+
/**
|
|
78
|
+
* Get entry points from a subgraph (the root nodes)
|
|
79
|
+
*/
|
|
80
|
+
private getEntryPoints;
|
|
81
|
+
/**
|
|
82
|
+
* Extract code blocks for key nodes in the subgraph
|
|
83
|
+
*/
|
|
84
|
+
private extractCodeBlocks;
|
|
85
|
+
/**
|
|
86
|
+
* Get unique files from a subgraph
|
|
87
|
+
*/
|
|
88
|
+
private getRelatedFiles;
|
|
89
|
+
/**
|
|
90
|
+
* Generate a summary of the context
|
|
91
|
+
*/
|
|
92
|
+
private generateSummary;
|
|
93
|
+
/**
|
|
94
|
+
* Resolve import/export nodes to their actual definitions
|
|
95
|
+
*
|
|
96
|
+
* When search returns `import { TerminalPanel }`, users want the TerminalPanel
|
|
97
|
+
* class definition, not the import statement. This follows the `imports` edge
|
|
98
|
+
* to find and return the actual definition instead.
|
|
99
|
+
*
|
|
100
|
+
* @param results - Search results that may include import/export nodes
|
|
101
|
+
* @returns Results with imports resolved to definitions where possible
|
|
102
|
+
*/
|
|
103
|
+
private resolveImportsToDefinitions;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Create a context builder
|
|
107
|
+
*/
|
|
108
|
+
export declare function createContextBuilder(projectRoot: string, queries: QueryBuilder, traverser: GraphTraverser): ContextBuilder;
|
|
109
|
+
export { formatContextAsMarkdown, formatContextAsJson } from './formatter';
|
|
110
|
+
//# sourceMappingURL=index.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
|