@colbymchenry/codegraph 0.7.10 → 0.8.0
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 +48 -48
- package/dist/bin/codegraph.js +25 -0
- package/dist/bin/codegraph.js.map +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +4 -2
- package/dist/context/index.js.map +1 -1
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +63 -37
- package/dist/extraction/index.js.map +1 -1
- package/dist/installer/config-writer.d.ts.map +1 -1
- package/dist/installer/config-writer.js +3 -1
- package/dist/installer/config-writer.js.map +1 -1
- package/dist/installer/index.d.ts +12 -0
- package/dist/installer/index.d.ts.map +1 -1
- package/dist/installer/index.js +72 -4
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/instructions-template.d.ts +2 -2
- package/dist/installer/instructions-template.d.ts.map +1 -1
- package/dist/installer/instructions-template.js +3 -2
- package/dist/installer/instructions-template.js.map +1 -1
- package/dist/installer/targets/claude.d.ts +10 -6
- package/dist/installer/targets/claude.d.ts.map +1 -1
- package/dist/installer/targets/claude.js +72 -10
- package/dist/installer/targets/claude.js.map +1 -1
- package/dist/mcp/index.d.ts +8 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +116 -18
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/server-instructions.d.ts +1 -1
- package/dist/mcp/server-instructions.d.ts.map +1 -1
- package/dist/mcp/server-instructions.js +14 -2
- package/dist/mcp/server-instructions.js.map +1 -1
- package/dist/mcp/tools.d.ts +59 -2
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +384 -70
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/transport.d.ts +17 -0
- package/dist/mcp/transport.d.ts.map +1 -1
- package/dist/mcp/transport.js +63 -0
- package/dist/mcp/transport.js.map +1 -1
- package/dist/resolution/frameworks/index.d.ts +1 -0
- package/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/dist/resolution/frameworks/index.js +5 -1
- package/dist/resolution/frameworks/index.js.map +1 -1
- package/dist/resolution/frameworks/nestjs.d.ts +26 -0
- package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
- package/dist/resolution/frameworks/nestjs.js +374 -0
- package/dist/resolution/frameworks/nestjs.js.map +1 -0
- package/dist/search/query-utils.d.ts.map +1 -1
- package/dist/search/query-utils.js +29 -26
- package/dist/search/query-utils.js.map +1 -1
- package/dist/sync/git-hooks.d.ts +45 -0
- package/dist/sync/git-hooks.d.ts.map +1 -0
- package/dist/sync/git-hooks.js +223 -0
- package/dist/sync/git-hooks.js.map +1 -0
- package/dist/sync/index.d.ts +4 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +12 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/watch-policy.d.ts +48 -0
- package/dist/sync/watch-policy.d.ts.map +1 -0
- package/dist/sync/watch-policy.js +124 -0
- package/dist/sync/watch-policy.js.map +1 -0
- package/dist/sync/watcher.d.ts.map +1 -1
- package/dist/sync/watcher.js +10 -0
- package/dist/sync/watcher.js.map +1 -1
- package/package.json +3 -3
- package/scripts/agent-eval/audit.sh +68 -0
- package/scripts/agent-eval/itrun.sh +107 -0
- package/scripts/agent-eval/parse-run.mjs +45 -0
- package/scripts/agent-eval/parse-session.mjs +93 -0
- package/scripts/agent-eval/run-agent.sh +34 -0
- package/scripts/agent-eval/run-all.sh +67 -0
- package/scripts/extract-release-notes.mjs +130 -0
- package/scripts/release.sh +5 -7
|
@@ -38,16 +38,17 @@ Use codegraph for **structural** questions — what calls what, what would break
|
|
|
38
38
|
| "What would break if I changed Z?" | \`codegraph_impact\` |
|
|
39
39
|
| "Show me Y's signature / source / docstring" | \`codegraph_node\` |
|
|
40
40
|
| "Give me focused context for a task/area" | \`codegraph_context\` |
|
|
41
|
-
| "
|
|
41
|
+
| "See several related symbols' source at once" | \`codegraph_explore\` |
|
|
42
42
|
| "What files exist under path/" | \`codegraph_files\` |
|
|
43
43
|
| "Is the index healthy?" | \`codegraph_status\` |
|
|
44
44
|
|
|
45
45
|
### Rules of thumb
|
|
46
46
|
|
|
47
|
+
- **Answer directly — don't delegate exploration.** For "how does X work" / architecture / trace questions, answer with 2-3 codegraph calls: \`codegraph_context\` first, then ONE \`codegraph_explore\` for the source of the symbols it surfaces. Codegraph IS the pre-built index, so spawning a separate file-reading sub-task/agent — or running a grep + read loop — repeats work codegraph already did and costs more for the same answer.
|
|
47
48
|
- **Trust codegraph results.** They come from a full AST parse. Do NOT re-verify them with grep — that's slower, less accurate, and wastes context.
|
|
48
49
|
- **Don't grep first** when looking up a symbol by name. \`codegraph_search\` is faster and returns kind + location + signature in one call.
|
|
49
50
|
- **Don't chain \`codegraph_search\` + \`codegraph_node\`** when you just want context — \`codegraph_context\` is one call.
|
|
50
|
-
-
|
|
51
|
+
- **Don't loop \`codegraph_node\` over many symbols** — one \`codegraph_explore\` call returns several symbols' source grouped in a single capped call, while each separate node/Read call re-reads the whole context and costs far more.
|
|
51
52
|
- **Index lag**: the file watcher debounces ~500ms behind writes; don't re-query immediately after editing a file in the same turn.
|
|
52
53
|
|
|
53
54
|
### If \`.codegraph/\` doesn't exist
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions-template.js","sourceRoot":"","sources":["../../src/installer/instructions-template.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,4DAA4D;AAC/C,QAAA,uBAAuB,GAAG,0BAA0B,CAAC;AACrD,QAAA,qBAAqB,GAAG,wBAAwB,CAAC;AAE9D;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,GAAG,+BAAuB
|
|
1
|
+
{"version":3,"file":"instructions-template.js","sourceRoot":"","sources":["../../src/installer/instructions-template.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,4DAA4D;AAC/C,QAAA,uBAAuB,GAAG,0BAA0B,CAAC;AACrD,QAAA,qBAAqB,GAAG,wBAAwB,CAAC;AAE9D;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,GAAG,+BAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiC7D,6BAAqB,EAAE,CAAC;AAE1B;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,6BAAqB,CAAC"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Claude Code target
|
|
2
|
+
* Claude Code target. Writes:
|
|
3
3
|
*
|
|
4
|
-
* - MCP server entry to `~/.claude.json` (global
|
|
5
|
-
* `./.
|
|
4
|
+
* - MCP server entry to `~/.claude.json` (global = user scope, loads
|
|
5
|
+
* in every project) or `./.mcp.json` (local = project scope, the
|
|
6
|
+
* file Claude Code actually reads for a single project). See the
|
|
7
|
+
* scope table at https://code.claude.com/docs/en/mcp.
|
|
6
8
|
* - Permissions to `~/.claude/settings.json` (global) or
|
|
7
9
|
* `./.claude/settings.json` (local), gated on `autoAllow`.
|
|
8
10
|
* - Instructions to `~/.claude/CLAUDE.md` (global) or
|
|
9
11
|
* `./.claude/CLAUDE.md` (local).
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* Earlier versions wrote the local MCP entry to `./.claude.json` — a
|
|
14
|
+
* file Claude Code never reads — so the server silently never loaded
|
|
15
|
+
* until the user manually renamed it to `.mcp.json` (issue #207). We
|
|
16
|
+
* now write `./.mcp.json` and migrate any stale `./.claude.json` entry
|
|
17
|
+
* out of the way on install and uninstall.
|
|
14
18
|
*/
|
|
15
19
|
import { AgentTarget, Location, WriteResult } from './types';
|
|
16
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../../src/installer/targets/claude.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../../src/installer/targets/claude.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,EACL,WAAW,EAGX,QAAQ,EACR,WAAW,EACZ,MAAM,SAAS,CAAC;AAiKjB;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAsBzE;AAyBD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAoBjF;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CA0ClF;AAED,eAAO,MAAM,YAAY,EAAE,WAAoC,CAAC"}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Claude Code target
|
|
3
|
+
* Claude Code target. Writes:
|
|
4
4
|
*
|
|
5
|
-
* - MCP server entry to `~/.claude.json` (global
|
|
6
|
-
* `./.
|
|
5
|
+
* - MCP server entry to `~/.claude.json` (global = user scope, loads
|
|
6
|
+
* in every project) or `./.mcp.json` (local = project scope, the
|
|
7
|
+
* file Claude Code actually reads for a single project). See the
|
|
8
|
+
* scope table at https://code.claude.com/docs/en/mcp.
|
|
7
9
|
* - Permissions to `~/.claude/settings.json` (global) or
|
|
8
10
|
* `./.claude/settings.json` (local), gated on `autoAllow`.
|
|
9
11
|
* - Instructions to `~/.claude/CLAUDE.md` (global) or
|
|
10
12
|
* `./.claude/CLAUDE.md` (local).
|
|
11
13
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* Earlier versions wrote the local MCP entry to `./.claude.json` — a
|
|
15
|
+
* file Claude Code never reads — so the server silently never loaded
|
|
16
|
+
* until the user manually renamed it to `.mcp.json` (issue #207). We
|
|
17
|
+
* now write `./.mcp.json` and migrate any stale `./.claude.json` entry
|
|
18
|
+
* out of the way on install and uninstall.
|
|
15
19
|
*/
|
|
16
20
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
21
|
if (k2 === undefined) k2 = k;
|
|
@@ -62,9 +66,22 @@ function configDir(loc) {
|
|
|
62
66
|
: path.join(process.cwd(), '.claude');
|
|
63
67
|
}
|
|
64
68
|
function mcpJsonPath(loc) {
|
|
69
|
+
// global → ~/.claude.json (user scope: visible in every project).
|
|
70
|
+
// local → ./.mcp.json (project scope: the ONLY project-level MCP
|
|
71
|
+
// file Claude Code reads — NOT ./.claude.json, which it ignores).
|
|
65
72
|
return loc === 'global'
|
|
66
73
|
? path.join(os.homedir(), '.claude.json')
|
|
67
|
-
: path.join(process.cwd(), '.
|
|
74
|
+
: path.join(process.cwd(), '.mcp.json');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Where pre-#207 installers wrote the local MCP entry. Claude Code
|
|
78
|
+
* never reads a project-level `./.claude.json`, so we migrate the
|
|
79
|
+
* codegraph entry out of it on install and strip it on uninstall.
|
|
80
|
+
* Only the project-local path is legacy — global `~/.claude.json` is
|
|
81
|
+
* the correct user-scope location and is left untouched.
|
|
82
|
+
*/
|
|
83
|
+
function legacyLocalMcpPath() {
|
|
84
|
+
return path.join(process.cwd(), '.claude.json');
|
|
68
85
|
}
|
|
69
86
|
function settingsJsonPath(loc) {
|
|
70
87
|
return path.join(configDir(loc), 'settings.json');
|
|
@@ -95,6 +112,14 @@ class ClaudeCodeTarget {
|
|
|
95
112
|
const files = [];
|
|
96
113
|
// 1. MCP server entry
|
|
97
114
|
files.push(writeMcpEntry(loc));
|
|
115
|
+
// 1b. Migrate away any stale ./.claude.json left by a pre-#207
|
|
116
|
+
// local install, so the project isn't left with two competing
|
|
117
|
+
// (one dead) MCP configs.
|
|
118
|
+
if (loc === 'local') {
|
|
119
|
+
const migrated = cleanupLegacyLocalMcp();
|
|
120
|
+
if (migrated)
|
|
121
|
+
files.push(migrated);
|
|
122
|
+
}
|
|
98
123
|
// 2. Permissions (only when autoAllow)
|
|
99
124
|
if (opts.autoAllow) {
|
|
100
125
|
files.push(writePermissionsEntry(loc));
|
|
@@ -119,6 +144,13 @@ class ClaudeCodeTarget {
|
|
|
119
144
|
else {
|
|
120
145
|
files.push({ path: mcpPath, action: 'not-found' });
|
|
121
146
|
}
|
|
147
|
+
// 1b. Also strip the codegraph entry from a legacy ./.claude.json
|
|
148
|
+
// so uninstall fully reverses a pre-#207 local install.
|
|
149
|
+
if (loc === 'local') {
|
|
150
|
+
const migrated = cleanupLegacyLocalMcp();
|
|
151
|
+
if (migrated)
|
|
152
|
+
files.push(migrated);
|
|
153
|
+
}
|
|
122
154
|
// 2. Permissions
|
|
123
155
|
const settingsPath = settingsJsonPath(loc);
|
|
124
156
|
const settings = (0, shared_1.readJsonFile)(settingsPath);
|
|
@@ -174,9 +206,10 @@ function writeMcpEntry(loc) {
|
|
|
174
206
|
return { path: file, action: 'unchanged' };
|
|
175
207
|
}
|
|
176
208
|
// 'created' here means: the file itself did not exist before this
|
|
177
|
-
// write. A pre-existing
|
|
178
|
-
//
|
|
179
|
-
//
|
|
209
|
+
// write. A pre-existing MCP JSON file (`~/.claude.json` globally,
|
|
210
|
+
// `./.mcp.json` locally) containing other MCP servers (no
|
|
211
|
+
// `codegraph` key) is 'updated', not 'created' — we're adding an
|
|
212
|
+
// entry to a file that was already there. Codex uses a different
|
|
180
213
|
// idiom (empty-content => 'created') because its config.toml is
|
|
181
214
|
// ours alone to manage.
|
|
182
215
|
const action = before ? 'updated' : (fs.existsSync(file) ? 'updated' : 'created');
|
|
@@ -186,6 +219,35 @@ function writeMcpEntry(loc) {
|
|
|
186
219
|
(0, shared_1.writeJsonFile)(file, existing);
|
|
187
220
|
return { path: file, action };
|
|
188
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Strip the codegraph entry from a legacy project-local
|
|
224
|
+
* `./.claude.json` (written by pre-#207 installers, which Claude Code
|
|
225
|
+
* never read). Surgical: only our `codegraph` key is removed; sibling
|
|
226
|
+
* MCP servers and any unrelated keys are preserved, and the file is
|
|
227
|
+
* deleted only when removal leaves it completely empty. Returns the
|
|
228
|
+
* file action for reporting, or `null` when there's nothing to migrate.
|
|
229
|
+
*/
|
|
230
|
+
function cleanupLegacyLocalMcp() {
|
|
231
|
+
const file = legacyLocalMcpPath();
|
|
232
|
+
if (!fs.existsSync(file))
|
|
233
|
+
return null;
|
|
234
|
+
const config = (0, shared_1.readJsonFile)(file);
|
|
235
|
+
if (!config.mcpServers?.codegraph)
|
|
236
|
+
return null;
|
|
237
|
+
delete config.mcpServers.codegraph;
|
|
238
|
+
if (Object.keys(config.mcpServers).length === 0)
|
|
239
|
+
delete config.mcpServers;
|
|
240
|
+
if (Object.keys(config).length === 0) {
|
|
241
|
+
try {
|
|
242
|
+
fs.unlinkSync(file);
|
|
243
|
+
}
|
|
244
|
+
catch { /* ignore */ }
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
(0, shared_1.writeJsonFile)(file, config);
|
|
248
|
+
}
|
|
249
|
+
return { path: file, action: 'removed' };
|
|
250
|
+
}
|
|
189
251
|
function writePermissionsEntry(loc) {
|
|
190
252
|
const file = settingsJsonPath(loc);
|
|
191
253
|
const settings = (0, shared_1.readJsonFile)(file);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../../src/installer/targets/claude.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../../src/installer/targets/claude.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmLH,sCAsBC;AAyBD,sDAoBC;AAED,wDA0CC;AAhSD,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AAQzB,qCASkB;AAClB,oEAIkC;AAElC,SAAS,SAAS,CAAC,GAAa;IAC9B,OAAO,GA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AS;QAC9B,CAAC,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW;YACpC,CAAC,CAAC,SAAS,CAAC;IAClB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAEY,QAAA,YAAY,GAAgB,IAAI,gBAAgB,EAAE,CAAC"}
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare class MCPServer {
|
|
|
26
26
|
private toolHandler;
|
|
27
27
|
private projectPath;
|
|
28
28
|
private initPromise;
|
|
29
|
+
private clientSupportsRoots;
|
|
30
|
+
private rootsAttempted;
|
|
29
31
|
constructor(projectPath?: string);
|
|
30
32
|
/**
|
|
31
33
|
* Start the MCP server
|
|
@@ -55,6 +57,12 @@ export declare class MCPServer {
|
|
|
55
57
|
* we never open the SQLite file twice concurrently.
|
|
56
58
|
*/
|
|
57
59
|
private retryInitIfNeeded;
|
|
60
|
+
/**
|
|
61
|
+
* Resolve the project root via the MCP `roots/list` request and initialize
|
|
62
|
+
* from the first root the client reports. Falls back to the process cwd if
|
|
63
|
+
* the client returns no usable root or doesn't answer in time. See issue #196.
|
|
64
|
+
*/
|
|
65
|
+
private initFromRoots;
|
|
58
66
|
/**
|
|
59
67
|
* Start file watching on the active CodeGraph instance.
|
|
60
68
|
* Logs sync activity to stderr for diagnostics.
|
package/dist/mcp/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA6DH;;;;;GAKG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAAgB;IAGnC,OAAO,CAAC,WAAW,CAA8B;IAIjD,OAAO,CAAC,mBAAmB,CAAS;IAGpC,OAAO,CAAC,cAAc,CAAS;gBAEnB,WAAW,CAAC,EAAE,MAAM;IAOhC;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAe5B;;;;;;;;;OASG;YACW,oBAAoB;IAyBlC;;;;;;;;OAQG;YACW,iBAAiB;IA+C/B;;;;OAIG;YACW,aAAa;IAiB3B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAsCrB;;OAEG;IACH,IAAI,IAAI,IAAI;IAYZ;;OAEG;YACW,aAAa;IA6C3B;;OAEG;YACW,gBAAgB;IA6D9B;;OAEG;YACW,eAAe;IAO7B;;OAEG;YACW,eAAe;CAqC9B;AAGD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/mcp/index.js
CHANGED
|
@@ -52,6 +52,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
52
52
|
exports.ToolHandler = exports.tools = exports.StdioTransport = exports.MCPServer = void 0;
|
|
53
53
|
const path = __importStar(require("path"));
|
|
54
54
|
const index_1 = __importStar(require("../index"));
|
|
55
|
+
const sync_1 = require("../sync");
|
|
55
56
|
const transport_1 = require("./transport");
|
|
56
57
|
const tools_1 = require("./tools");
|
|
57
58
|
const server_instructions_1 = require("./server-instructions");
|
|
@@ -85,6 +86,27 @@ const SERVER_INFO = {
|
|
|
85
86
|
* MCP Protocol Version
|
|
86
87
|
*/
|
|
87
88
|
const PROTOCOL_VERSION = '2024-11-05';
|
|
89
|
+
/**
|
|
90
|
+
* How long to wait for the client's `roots/list` response before giving up
|
|
91
|
+
* and falling back to the process cwd.
|
|
92
|
+
*/
|
|
93
|
+
const ROOTS_LIST_TIMEOUT_MS = 5000;
|
|
94
|
+
/**
|
|
95
|
+
* Extract the first usable filesystem path from a `roots/list` result.
|
|
96
|
+
* Shape per MCP spec: `{ roots: [{ uri: "file:///path", name?: string }] }`.
|
|
97
|
+
* Returns null if the result is empty or malformed.
|
|
98
|
+
*/
|
|
99
|
+
function firstRootPath(result) {
|
|
100
|
+
if (!result || typeof result !== 'object')
|
|
101
|
+
return null;
|
|
102
|
+
const roots = result.roots;
|
|
103
|
+
if (!Array.isArray(roots) || roots.length === 0)
|
|
104
|
+
return null;
|
|
105
|
+
const first = roots[0];
|
|
106
|
+
if (typeof first?.uri !== 'string')
|
|
107
|
+
return null;
|
|
108
|
+
return fileUriToPath(first.uri);
|
|
109
|
+
}
|
|
88
110
|
/**
|
|
89
111
|
* MCP Server for CodeGraph
|
|
90
112
|
*
|
|
@@ -99,6 +121,13 @@ class MCPServer {
|
|
|
99
121
|
// In-flight background init kicked off from handleInitialize. Tracked so the
|
|
100
122
|
// sync retry path doesn't race against it (double-opening the SQLite file).
|
|
101
123
|
initPromise = null;
|
|
124
|
+
// Whether the client advertised the MCP `roots` capability during initialize.
|
|
125
|
+
// If so, and no explicit project path was given, we ask it for the workspace
|
|
126
|
+
// root via roots/list rather than guessing from the (often wrong) cwd.
|
|
127
|
+
clientSupportsRoots = false;
|
|
128
|
+
// Guards the one-shot deferred resolution (roots/list or cwd) so we don't
|
|
129
|
+
// re-issue roots/list on every tool call.
|
|
130
|
+
rootsAttempted = false;
|
|
102
131
|
constructor(projectPath) {
|
|
103
132
|
this.projectPath = projectPath || null;
|
|
104
133
|
this.transport = new transport_1.StdioTransport();
|
|
@@ -134,6 +163,8 @@ class MCPServer {
|
|
|
134
163
|
* are still possible.
|
|
135
164
|
*/
|
|
136
165
|
async tryInitializeDefault(projectPath) {
|
|
166
|
+
// Record where we searched so a later "not initialized" error can name it.
|
|
167
|
+
this.toolHandler.setDefaultProjectHint(projectPath);
|
|
137
168
|
// Walk up parent directories to find nearest .codegraph/
|
|
138
169
|
const resolvedRoot = (0, index_1.findNearestCodeGraphRoot)(projectPath);
|
|
139
170
|
if (!resolvedRoot) {
|
|
@@ -172,10 +203,28 @@ class MCPServer {
|
|
|
172
203
|
// Already initialized successfully
|
|
173
204
|
if (this.toolHandler.hasDefaultCodeGraph())
|
|
174
205
|
return;
|
|
175
|
-
// No
|
|
176
|
-
if
|
|
177
|
-
|
|
178
|
-
|
|
206
|
+
// No explicit path was given at initialize. Resolve it now, exactly once:
|
|
207
|
+
// ask the client via roots/list (if it advertised roots), else use cwd.
|
|
208
|
+
// Deferring to here lets a roots answer override the wrong cwd, and the
|
|
209
|
+
// one-shot guard means we never re-issue roots/list per tool call.
|
|
210
|
+
if (!this.projectPath && !this.rootsAttempted) {
|
|
211
|
+
this.rootsAttempted = true;
|
|
212
|
+
this.initPromise = (this.clientSupportsRoots
|
|
213
|
+
? this.initFromRoots()
|
|
214
|
+
: this.tryInitializeDefault(process.cwd())).finally(() => { this.initPromise = null; });
|
|
215
|
+
try {
|
|
216
|
+
await this.initPromise;
|
|
217
|
+
}
|
|
218
|
+
catch { /* fall through to last-resort below */ }
|
|
219
|
+
if (this.toolHandler.hasDefaultCodeGraph())
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// Last resort: re-walk from the best candidate we have. Picks up projects
|
|
223
|
+
// initialized after the server started, and covers clients that sent no
|
|
224
|
+
// usable initialize signal at all.
|
|
225
|
+
const candidate = this.projectPath ?? process.cwd();
|
|
226
|
+
this.toolHandler.setDefaultProjectHint(candidate);
|
|
227
|
+
const resolvedRoot = (0, index_1.findNearestCodeGraphRoot)(candidate);
|
|
179
228
|
if (!resolvedRoot)
|
|
180
229
|
return;
|
|
181
230
|
try {
|
|
@@ -196,6 +245,29 @@ class MCPServer {
|
|
|
196
245
|
// Still failing — will retry on next tool call
|
|
197
246
|
}
|
|
198
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Resolve the project root via the MCP `roots/list` request and initialize
|
|
250
|
+
* from the first root the client reports. Falls back to the process cwd if
|
|
251
|
+
* the client returns no usable root or doesn't answer in time. See issue #196.
|
|
252
|
+
*/
|
|
253
|
+
async initFromRoots() {
|
|
254
|
+
let target = process.cwd();
|
|
255
|
+
try {
|
|
256
|
+
const result = await this.transport.request('roots/list', undefined, ROOTS_LIST_TIMEOUT_MS);
|
|
257
|
+
const rootPath = firstRootPath(result);
|
|
258
|
+
if (rootPath) {
|
|
259
|
+
target = rootPath;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
process.stderr.write('[CodeGraph MCP] Client returned no workspace roots; falling back to process cwd.\n');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
267
|
+
process.stderr.write(`[CodeGraph MCP] roots/list request failed (${msg}); falling back to process cwd.\n`);
|
|
268
|
+
}
|
|
269
|
+
await this.tryInitializeDefault(target);
|
|
270
|
+
}
|
|
199
271
|
/**
|
|
200
272
|
* Start file watching on the active CodeGraph instance.
|
|
201
273
|
* Logs sync activity to stderr for diagnostics.
|
|
@@ -203,6 +275,15 @@ class MCPServer {
|
|
|
203
275
|
startWatching() {
|
|
204
276
|
if (!this.cg)
|
|
205
277
|
return;
|
|
278
|
+
// When the watcher is intentionally disabled (e.g. WSL2 /mnt drives, or
|
|
279
|
+
// CODEGRAPH_NO_WATCH=1), say so explicitly and tell the user how to keep
|
|
280
|
+
// the graph fresh — otherwise the silent staleness is hard to diagnose.
|
|
281
|
+
const disabledReason = (0, sync_1.watchDisabledReason)(this.projectPath ?? process.cwd());
|
|
282
|
+
if (disabledReason) {
|
|
283
|
+
process.stderr.write(`[CodeGraph MCP] File watcher disabled — ${disabledReason}. ` +
|
|
284
|
+
`The graph will not auto-update; run \`codegraph sync\` (or install the git sync hooks via \`codegraph init\`) to refresh.\n`);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
206
287
|
const started = this.cg.watch({
|
|
207
288
|
onSyncComplete: (result) => {
|
|
208
289
|
if (result.filesChanged > 0) {
|
|
@@ -216,6 +297,10 @@ class MCPServer {
|
|
|
216
297
|
if (started) {
|
|
217
298
|
process.stderr.write('[CodeGraph MCP] File watcher active — graph will auto-sync on changes\n');
|
|
218
299
|
}
|
|
300
|
+
else {
|
|
301
|
+
// start() can also return false when recursive fs.watch isn't supported.
|
|
302
|
+
process.stderr.write('[CodeGraph MCP] File watcher unavailable on this platform — run `codegraph sync` to refresh the graph after changes.\n');
|
|
303
|
+
}
|
|
219
304
|
}
|
|
220
305
|
/**
|
|
221
306
|
* Stop the server
|
|
@@ -273,17 +358,23 @@ class MCPServer {
|
|
|
273
358
|
*/
|
|
274
359
|
async handleInitialize(request) {
|
|
275
360
|
const params = request.params;
|
|
276
|
-
//
|
|
277
|
-
|
|
361
|
+
// Does the client support the MCP `roots` protocol? If so, and we have no
|
|
362
|
+
// explicit path, we ask it for the workspace root after the handshake
|
|
363
|
+
// instead of falling back to the (frequently wrong) cwd. See issue #196.
|
|
364
|
+
this.clientSupportsRoots = !!params?.capabilities?.roots;
|
|
365
|
+
// Explicit project signal, strongest first: a client-provided rootUri /
|
|
366
|
+
// workspaceFolders (LSP-style, non-standard but some clients send it), else
|
|
367
|
+
// the --path the server was launched with. cwd is NOT used here — we defer
|
|
368
|
+
// it so a roots/list answer can win over it.
|
|
369
|
+
let explicitPath = null;
|
|
278
370
|
if (params?.rootUri) {
|
|
279
|
-
|
|
371
|
+
explicitPath = fileUriToPath(params.rootUri);
|
|
280
372
|
}
|
|
281
373
|
else if (params?.workspaceFolders?.[0]?.uri) {
|
|
282
|
-
|
|
374
|
+
explicitPath = fileUriToPath(params.workspaceFolders[0].uri);
|
|
283
375
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
projectPath = process.cwd();
|
|
376
|
+
else if (this.projectPath) {
|
|
377
|
+
explicitPath = this.projectPath;
|
|
287
378
|
}
|
|
288
379
|
// Respond to the handshake BEFORE doing any heavy initialization. Loading
|
|
289
380
|
// the SQLite DB and the tree-sitter WASM runtime can take many seconds on
|
|
@@ -304,13 +395,20 @@ class MCPServer {
|
|
|
304
395
|
serverInfo: SERVER_INFO,
|
|
305
396
|
instructions: server_instructions_1.SERVER_INSTRUCTIONS,
|
|
306
397
|
});
|
|
307
|
-
//
|
|
308
|
-
// arrive before it finishes
|
|
309
|
-
//
|
|
310
|
-
//
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
398
|
+
// If we know the project dir, kick off init in the background now. Tool
|
|
399
|
+
// calls that arrive before it finishes fall through to `retryInitIfNeeded`,
|
|
400
|
+
// which waits for this promise rather than racing it with a second open.
|
|
401
|
+
//
|
|
402
|
+
// If we DON'T know it (no rootUri, no --path), defer: the first tool call
|
|
403
|
+
// resolves it via roots/list (when the client supports roots) or cwd. This
|
|
404
|
+
// is the fix for issue #196 — clients that launch the server outside the
|
|
405
|
+
// project and don't pass a rootUri previously got a misleading "not
|
|
406
|
+
// initialized" error on every call.
|
|
407
|
+
if (explicitPath) {
|
|
408
|
+
this.initPromise = this.tryInitializeDefault(explicitPath).finally(() => {
|
|
409
|
+
this.initPromise = null;
|
|
410
|
+
});
|
|
411
|
+
}
|
|
314
412
|
}
|
|
315
413
|
/**
|
|
316
414
|
* Handle tools/list request
|
package/dist/mcp/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2CAA6B;AAC7B,kDAA+D;AAC/D,2CAA8F;AAC9F,mCAA6C;AAC7C,+DAA4D;AAE5D;;;GAGG;AACH,SAAS,aAAa,CAAC,GAAW;IAChC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,QAAQ,GAAG,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACh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,aAAa,EACxB,mBAAmB,CACpB,CAAC;YACF,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC;QAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;QAExC,uBAAuB;QACvB,MAAM,IAAI,GAAG,aAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,OAAO,CAAC,EAAE,EACV,sBAAU,CAAC,aAAa,EACxB,iBAAiB,QAAQ,EAAE,CAC5B,CAAC;YACF,OAAO;QACT,CAAC;QAED,qEAAqE;QACrE,0EAA0E;QAC1E,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAE/B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAElE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;CACF;AAxXD,8BAwXC;AAED,wBAAwB;AACxB,yCAA6C;AAApC,2GAAA,cAAc,OAAA;AACvB,iCAA6C;AAApC,8FAAA,KAAK,OAAA;AAAE,oGAAA,WAAW,OAAA"}
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
* burn tokens. Reference only tools that exist on `main`; gate any
|
|
16
16
|
* conditional tools behind feature checks if/when they ship.
|
|
17
17
|
*/
|
|
18
|
-
export declare const SERVER_INSTRUCTIONS = "# Codegraph \u2014 code intelligence over an indexed knowledge graph\n\nCodegraph is a SQLite knowledge graph of every symbol, edge, and file\nin the workspace. Reads are sub-millisecond; the index lags writes by\nabout a second through the file watcher. Consult it BEFORE writing or\nediting code, not during.\n\n## Tool selection by intent\n\n- **\"What is the symbol named X?\"** \u2192 `codegraph_search`\n- **\"What's the deal with this task / feature / area?\"** \u2192 `codegraph_context` (PRIMARY \u2014 composes search + node + callers + callees in one call)\n- **\"What calls this?\"** \u2192 `codegraph_callers`\n- **\"What does this call?\"** \u2192 `codegraph_callees`\n- **\"What would changing this break?\"** \u2192 `codegraph_impact`\n- **\"Show me this symbol's source / signature / docstring.\"** \u2192 `codegraph_node`\n- **\"
|
|
18
|
+
export declare const SERVER_INSTRUCTIONS = "# Codegraph \u2014 code intelligence over an indexed knowledge graph\n\nCodegraph is a SQLite knowledge graph of every symbol, edge, and file\nin the workspace. Reads are sub-millisecond; the index lags writes by\nabout a second through the file watcher. Consult it BEFORE writing or\nediting code, not during.\n\n## Answer directly \u2014 don't delegate exploration\n\nFor \"how does X work\", architecture, trace, or where-is-X questions,\nanswer DIRECTLY using 2-3 codegraph calls: `codegraph_context` first,\nthen ONE `codegraph_explore` for the source of the symbols it surfaces.\nCodegraph IS the pre-built search index \u2014 so delegating the lookup to a\nseparate file-reading sub-task/agent, or running your own grep + read\nloop, repeats work codegraph already did and costs more for the same\nanswer. Reach for raw Read/Grep only to confirm a specific detail\ncodegraph didn't cover. A direct codegraph answer is typically a handful\nof calls; a grep/read exploration is dozens.\n\n## Tool selection by intent\n\n- **\"What is the symbol named X?\"** \u2192 `codegraph_search`\n- **\"What's the deal with this task / feature / area?\"** \u2192 `codegraph_context` (PRIMARY \u2014 composes search + node + callers + callees in one call)\n- **\"What calls this?\"** \u2192 `codegraph_callers`\n- **\"What does this call?\"** \u2192 `codegraph_callees`\n- **\"What would changing this break?\"** \u2192 `codegraph_impact`\n- **\"Show me this symbol's source / signature / docstring.\"** \u2192 `codegraph_node`\n- **\"Show me several related symbols' source / survey an area.\"** \u2192 `codegraph_explore` (ONE capped call; prefer over many codegraph_node/Read)\n- **\"What's in directory X?\"** \u2192 `codegraph_files`\n- **\"Is the index ready / what's its size?\"** \u2192 `codegraph_status`\n\n## Common chains\n\n- **Onboarding**: `codegraph_context` first. If still unclear, `codegraph_explore` for breadth, then `codegraph_node` on specific symbols.\n- **Refactor planning**: `codegraph_search` \u2192 `codegraph_callers` \u2192 `codegraph_impact`. The blast-radius answer comes from impact, not from walking callers manually.\n- **Debugging a regression**: `codegraph_callers` of the suspected symbol; widen with `codegraph_impact` if an unexpected call appears.\n\n## Anti-patterns\n\n- **Don't grep first** when looking up a symbol by name \u2014 `codegraph_search` is faster and returns kind + location + signature.\n- **Don't chain `codegraph_search` + `codegraph_node`** when you just want context \u2014 `codegraph_context` is one round-trip.\n- **Don't loop `codegraph_node` over many symbols** \u2014 one `codegraph_explore` call returns them all grouped by file, while each separate call re-reads the whole context and costs far more. Use `codegraph_node` for a single symbol.\n- **Don't query the index immediately after editing a file** \u2014 the watcher needs ~500ms to debounce + sync. Wait for the next turn.\n\n## Limitations\n\n- Index lags file writes by ~1 second.\n- Cross-file resolution is best-effort name matching; ambiguous calls may return multiple candidates.\n- No live correctness validation \u2014 that's still the TypeScript compiler / test suite / linter's job. Codegraph supplements those with structural context they don't have.\n";
|
|
19
19
|
//# sourceMappingURL=server-instructions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-instructions.d.ts","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"server-instructions.d.ts","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,wtGAiD/B,CAAC"}
|
|
@@ -25,6 +25,18 @@ in the workspace. Reads are sub-millisecond; the index lags writes by
|
|
|
25
25
|
about a second through the file watcher. Consult it BEFORE writing or
|
|
26
26
|
editing code, not during.
|
|
27
27
|
|
|
28
|
+
## Answer directly — don't delegate exploration
|
|
29
|
+
|
|
30
|
+
For "how does X work", architecture, trace, or where-is-X questions,
|
|
31
|
+
answer DIRECTLY using 2-3 codegraph calls: \`codegraph_context\` first,
|
|
32
|
+
then ONE \`codegraph_explore\` for the source of the symbols it surfaces.
|
|
33
|
+
Codegraph IS the pre-built search index — so delegating the lookup to a
|
|
34
|
+
separate file-reading sub-task/agent, or running your own grep + read
|
|
35
|
+
loop, repeats work codegraph already did and costs more for the same
|
|
36
|
+
answer. Reach for raw Read/Grep only to confirm a specific detail
|
|
37
|
+
codegraph didn't cover. A direct codegraph answer is typically a handful
|
|
38
|
+
of calls; a grep/read exploration is dozens.
|
|
39
|
+
|
|
28
40
|
## Tool selection by intent
|
|
29
41
|
|
|
30
42
|
- **"What is the symbol named X?"** → \`codegraph_search\`
|
|
@@ -33,7 +45,7 @@ editing code, not during.
|
|
|
33
45
|
- **"What does this call?"** → \`codegraph_callees\`
|
|
34
46
|
- **"What would changing this break?"** → \`codegraph_impact\`
|
|
35
47
|
- **"Show me this symbol's source / signature / docstring."** → \`codegraph_node\`
|
|
36
|
-
- **"
|
|
48
|
+
- **"Show me several related symbols' source / survey an area."** → \`codegraph_explore\` (ONE capped call; prefer over many codegraph_node/Read)
|
|
37
49
|
- **"What's in directory X?"** → \`codegraph_files\`
|
|
38
50
|
- **"Is the index ready / what's its size?"** → \`codegraph_status\`
|
|
39
51
|
|
|
@@ -47,7 +59,7 @@ editing code, not during.
|
|
|
47
59
|
|
|
48
60
|
- **Don't grep first** when looking up a symbol by name — \`codegraph_search\` is faster and returns kind + location + signature.
|
|
49
61
|
- **Don't chain \`codegraph_search\` + \`codegraph_node\`** when you just want context — \`codegraph_context\` is one round-trip.
|
|
50
|
-
- **Don't
|
|
62
|
+
- **Don't loop \`codegraph_node\` over many symbols** — one \`codegraph_explore\` call returns them all grouped by file, while each separate call re-reads the whole context and costs far more. Use \`codegraph_node\` for a single symbol.
|
|
51
63
|
- **Don't query the index immediately after editing a file** — the watcher needs ~500ms to debounce + sync. Wait for the next turn.
|
|
52
64
|
|
|
53
65
|
## Limitations
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-instructions.js","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,mBAAmB,GAAG
|
|
1
|
+
{"version":3,"file":"server-instructions.js","sourceRoot":"","sources":["../../src/mcp/server-instructions.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDlC,CAAC"}
|