@sdsrs/code-graph 0.177.0 → 0.178.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/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/claude-plugin/scripts/pre-edit-guide.js +17 -5
- package/claude-plugin/scripts/pre-grep-guide.js +3 -2
- package/claude-plugin/scripts/pre-read-guide.js +4 -3
- package/claude-plugin/scripts/project-root.js +39 -1
- package/claude-plugin/scripts/stop-impact.js +28 -10
- package/claude-plugin/templates/code-graph-snapshot.yml +1 -1
- package/package.json +6 -6
|
@@ -22,7 +22,7 @@ const fs = require('fs');
|
|
|
22
22
|
const path = require('path');
|
|
23
23
|
const { findBinary } = require('./find-binary');
|
|
24
24
|
const { cgTmpDir, cwdHash } = require('./tmp-dir');
|
|
25
|
-
const { resolveProjectRoot, indexBuildInProgress } = require('./project-root');
|
|
25
|
+
const { resolveProjectRoot, indexKey, indexBuildInProgress } = require('./project-root');
|
|
26
26
|
const { recordRecommendation } = require('./recommendation-log');
|
|
27
27
|
const { formatCoveringTests } = require('./covering-tests');
|
|
28
28
|
const { emitPreToolContext } = require('./hook-emit');
|
|
@@ -203,8 +203,10 @@ if (indexBuildInProgress(cwd)) process.exit(0);
|
|
|
203
203
|
// short generic symbol names (open, new, create, parse, from, init) resolve
|
|
204
204
|
// to a unique node instead of triggering the CLI's "Ambiguous symbol" error
|
|
205
205
|
// path, which previously caused silent exits for the most common edit cases.
|
|
206
|
+
// D#560 — in a linked worktree the index knows the file by its path from the
|
|
207
|
+
// worktree, not from the main checkout `cwd` resolved to.
|
|
206
208
|
const editedFile = (input.tool_input && input.tool_input.file_path) || '';
|
|
207
|
-
const relFile = editedFile ? path.relative(cwd, editedFile) : '';
|
|
209
|
+
const relFile = editedFile ? indexKey(cwd, path.relative(cwd, editedFile)) : '';
|
|
208
210
|
// Whatever is left of the registered 4 s, capped at this call's own 2500 ms.
|
|
209
211
|
// `null` = the candidate loop above already spent the budget; running anyway is
|
|
210
212
|
// what got the hook killed by Claude Code mid-Edit (audit 2026-09-05 JS-03).
|
|
@@ -234,16 +236,26 @@ function runImpact(args) {
|
|
|
234
236
|
// the old_string is not in the file (the Edit will fail) or no candidate fits.
|
|
235
237
|
// The CLI lists at most five, in source order, and says how many exist in
|
|
236
238
|
// `total`: past the last listed one an unlisted definition may start, so an
|
|
237
|
-
// edit there is not guessed at (pre-tag review 2026-09-29).
|
|
239
|
+
// edit there is not guessed at (pre-tag review 2026-09-29). The line is
|
|
240
|
+
// counted in the copy the index describes, whose start lines the candidates
|
|
241
|
+
// carry: in a worktree, the main checkout's. Counted in the worktree's copy, a
|
|
242
|
+
// header whose lines had moved named another same-named definition's callers
|
|
243
|
+
// (review of D#560). A copy without the edited text gets no guess, and in a
|
|
244
|
+
// worktree nor does one that holds it twice: the main checkout's copy is not
|
|
245
|
+
// the edited one, so which occurrence matches the edited definition cannot be
|
|
246
|
+
// told (review of 0.178.0). In the main checkout that is a `replace_all` Edit,
|
|
247
|
+
// and the first occurrence is one of the definitions it changes.
|
|
238
248
|
function editedNodeId(suggestions, fileKey, total) {
|
|
249
|
+
const indexedKey = indexKey(cwd, fileKey);
|
|
239
250
|
let text;
|
|
240
|
-
try { text = fs.readFileSync(path.join(cwd,
|
|
251
|
+
try { text = fs.readFileSync(path.join(cwd, indexedKey), 'utf8'); } catch { return null; }
|
|
241
252
|
const at = text.indexOf(oldStr);
|
|
242
253
|
if (at === -1) return null;
|
|
254
|
+
if (indexedKey !== fileKey && text.indexOf(oldStr, at + 1) !== -1) return null;
|
|
243
255
|
const line = text.slice(0, at + symbolAt).split('\n').length;
|
|
244
256
|
let best = null;
|
|
245
257
|
for (const c of suggestions) {
|
|
246
|
-
if (!c || c.file_path !==
|
|
258
|
+
if (!c || c.file_path !== indexedKey || !Number.isInteger(c.node_id) || !Number.isInteger(c.start_line)) continue;
|
|
247
259
|
if (c.start_line <= line && (best === null || c.start_line > best.start_line)) best = c;
|
|
248
260
|
}
|
|
249
261
|
const lastListed = Math.max(...suggestions.map((c) => (c && Number.isInteger(c.start_line) ? c.start_line : -Infinity)));
|
|
@@ -751,7 +751,7 @@ function rootOnlyInSearchPath(cmd, cwd, target) {
|
|
|
751
751
|
|
|
752
752
|
// v0.48 — subdir-cwd fix; v0.49 — extracted to project-root.js so the read
|
|
753
753
|
// hook shares it. Re-exported below for test/back-compat.
|
|
754
|
-
const { resolveProjectRoot } = require('./project-root');
|
|
754
|
+
const { resolveProjectRoot, indexKey } = require('./project-root');
|
|
755
755
|
|
|
756
756
|
// v0.48 — companion to resolveProjectRoot: when the shell sits in a subdir,
|
|
757
757
|
// bare relative path args (`app --include=*.py` from backend/) are
|
|
@@ -2293,7 +2293,8 @@ function runMain() {
|
|
|
2293
2293
|
for (const t of sedTargets) {
|
|
2294
2294
|
if (!readGuide.isSourceFile(t)) continue;
|
|
2295
2295
|
const abs = path.isAbsolute(t) ? t : path.resolve(shellCwd, t);
|
|
2296
|
-
|
|
2296
|
+
// D#560 — a linked worktree's copy counts toward the indexed directory.
|
|
2297
|
+
const dir = readGuide.trackRead(root, indexKey(root, path.relative(root, abs)));
|
|
2297
2298
|
if (dir !== null) firedDirs.push(dir); // a dir fires once: markHint starts its cooldown
|
|
2298
2299
|
}
|
|
2299
2300
|
if (firedDirs.length > 0) {
|
|
@@ -36,7 +36,7 @@ const path = require('path');
|
|
|
36
36
|
const crypto = require('crypto');
|
|
37
37
|
const { cgTmpDir } = require('./tmp-dir');
|
|
38
38
|
const { recordRecommendation } = require('./recommendation-log');
|
|
39
|
-
const { resolveProjectRoot, indexBuildInProgress } = require('./project-root');
|
|
39
|
+
const { resolveProjectRoot, indexKey, indexBuildInProgress } = require('./project-root');
|
|
40
40
|
const { runOverviewAnswer } = require('./cg-answer');
|
|
41
41
|
const { emitPreToolAllowContext } = require('./hook-emit');
|
|
42
42
|
|
|
@@ -255,10 +255,11 @@ function runMain() {
|
|
|
255
255
|
if (!isSourceFile(filePath)) return;
|
|
256
256
|
|
|
257
257
|
// Normalize to a root-relative path. Read sends absolute paths; files
|
|
258
|
-
// outside the project (other repos, ~/.claude/) stay silent.
|
|
258
|
+
// outside the project (other repos, ~/.claude/) stay silent. A linked
|
|
259
|
+
// worktree's copy counts toward the directory the index knows (D#560).
|
|
259
260
|
let rel;
|
|
260
261
|
try {
|
|
261
|
-
rel = path.relative(root, filePath);
|
|
262
|
+
rel = indexKey(root, path.relative(root, filePath));
|
|
262
263
|
} catch { return; }
|
|
263
264
|
|
|
264
265
|
const hint = trackReadAndMaybeHint(root, rel);
|
|
@@ -124,6 +124,44 @@ function resolveProjectRoot(startDir, opts = {}) {
|
|
|
124
124
|
return null;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
function samePath(a, b) {
|
|
128
|
+
if (path.resolve(a) === path.resolve(b)) return true;
|
|
129
|
+
try { return fs.realpathSync(a) === fs.realpathSync(b); } catch { return false; }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// The part of `key` (a path from `root`) that leads to the top of a linked
|
|
133
|
+
// worktree of `root` the key is in, separator included; '' when there is none.
|
|
134
|
+
// Only a worktree under a hidden directory counts (Claude Code's
|
|
135
|
+
// `.claude/worktrees/<slug>`): the indexer skips hidden directories, so the
|
|
136
|
+
// index holds none of its files under their path from `root`. A worktree
|
|
137
|
+
// elsewhere in the project is indexed under that path unless ignored, and
|
|
138
|
+
// stripping it asked for the main checkout's copy instead (review of D#560).
|
|
139
|
+
// Only worktrees inside `root` are seen: a key leaving it (`../wt/…`) is
|
|
140
|
+
// outside the project to the hooks.
|
|
141
|
+
function worktreePrefix(root, key) {
|
|
142
|
+
if (!root || !key || key.startsWith('..') || path.isAbsolute(key)) return '';
|
|
143
|
+
const sep = path.sep === '\\' ? /[\\/]/g : /\//g;
|
|
144
|
+
const ends = [...key.matchAll(sep)].map((m) => m.index).concat(key.length);
|
|
145
|
+
for (const end of ends) {
|
|
146
|
+
const dir = key.slice(0, end);
|
|
147
|
+
if (!dir.split(sep).some((part) => part.startsWith('.'))) continue;
|
|
148
|
+
const main = worktreeMainRoot(path.join(root, dir));
|
|
149
|
+
if (main && samePath(main, root)) return end < key.length ? key.slice(0, end + 1) : `${key}/`;
|
|
150
|
+
}
|
|
151
|
+
return '';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// The key the index knows a file by, given its key from `root`. A worktree
|
|
155
|
+
// with no index of its own resolves to its main checkout (above), whose index
|
|
156
|
+
// stores the main checkout's layout, so a worktree's copy is known by its path
|
|
157
|
+
// from the worktree's top. Built from `root`, every such key carried the
|
|
158
|
+
// worktree's prefix: `impact --file .claude/worktrees/x/src/a.js` was refused,
|
|
159
|
+
// and the pre-edit impact went silent for every edit in an isolated agent's
|
|
160
|
+
// worktree (D#560). Any other key comes back unchanged, separators included.
|
|
161
|
+
function indexKey(root, key) {
|
|
162
|
+
return key ? key.slice(worktreePrefix(root, key).length) : key;
|
|
163
|
+
}
|
|
164
|
+
|
|
127
165
|
// True while the MCP server's startup index is still being written for `root`.
|
|
128
166
|
// The server writes `.code-graph/indexing-status.json` ({s, d, t}) and heartbeats
|
|
129
167
|
// it per batch and per finalize phase, then removes it. Until then the index is
|
|
@@ -163,4 +201,4 @@ function writerAlive(p) {
|
|
|
163
201
|
}
|
|
164
202
|
}
|
|
165
203
|
|
|
166
|
-
module.exports = { resolveProjectRoot, indexBuildInProgress, writerAlive, INDEXING_STALE_MS };
|
|
204
|
+
module.exports = { resolveProjectRoot, indexKey, worktreePrefix, indexBuildInProgress, writerAlive, INDEXING_STALE_MS };
|
|
@@ -413,8 +413,14 @@ function findCallSiteLine(text, symbol, startLine) {
|
|
|
413
413
|
* @param {(file:string)=>string|null} a.workText file in the working tree
|
|
414
414
|
* @param {(symbol:string,file:string)=>({file:string,line:number,name:string}[]|null)} a.callers
|
|
415
415
|
* @param {(file:string)=>number|null} a.mtimeMs
|
|
416
|
+
* @param {(file:string)=>string} [a.indexKeyOf] the key the index knows a
|
|
417
|
+
* file by: a linked worktree's copy drops the worktree's prefix (D#560)
|
|
418
|
+
* @param {(file:string)=>string} [a.displayOf] a file as the reader names it:
|
|
419
|
+
* a session working in a worktree reads paths from there (D#560 review)
|
|
416
420
|
*/
|
|
417
|
-
function computeStopReport({
|
|
421
|
+
function computeStopReport({
|
|
422
|
+
edits, state, now, workText, callers, mtimeMs, indexKeyOf = (f) => f, displayOf = (f) => f,
|
|
423
|
+
}) {
|
|
418
424
|
const lastStopAt = state.lastStopAt;
|
|
419
425
|
const turn = edits.filter((e) => lastStopAt === null || e.ts > lastStopAt);
|
|
420
426
|
const next = { lastStopAt: now, reported: [...state.reported] };
|
|
@@ -471,12 +477,12 @@ function computeStopReport({ edits, state, now, workText, callers, mtimeMs }) {
|
|
|
471
477
|
// text from the repository, and the model may paste it into a command.
|
|
472
478
|
const shown = untouched.slice(0, MAX_CALLERS_LISTED).map((r) => {
|
|
473
479
|
const name = r.name && r.name !== '<module>' ? ' (' + shellQuoteArg(r.name) + ')' : '';
|
|
474
|
-
return shellQuoteArg(r.file) + ':' + r.line + name;
|
|
480
|
+
return shellQuoteArg(displayOf(r.file)) + ':' + r.line + name;
|
|
475
481
|
});
|
|
476
|
-
let line = ' ' + shellQuoteArg(c.symbol) + '() in ' + shellQuoteArg(c.file) + ': ' + shown.join(', ');
|
|
482
|
+
let line = ' ' + shellQuoteArg(c.symbol) + '() in ' + shellQuoteArg(displayOf(c.file)) + ': ' + shown.join(', ');
|
|
477
483
|
if (untouched.length > MAX_CALLERS_LISTED) {
|
|
478
484
|
line += ', and ' + (untouched.length - MAX_CALLERS_LISTED) + ' more (' +
|
|
479
|
-
formatCgCommand(['refs', c.symbol, '--file', c.file]) + ')';
|
|
485
|
+
formatCgCommand(['refs', c.symbol, '--file', indexKeyOf(c.file)]) + ')';
|
|
480
486
|
}
|
|
481
487
|
lines.push(line);
|
|
482
488
|
next.reported.push(c.key);
|
|
@@ -488,7 +494,7 @@ function computeStopReport({ edits, state, now, workText, callers, mtimeMs }) {
|
|
|
488
494
|
const unchecked = changed.slice(MAX_SYMBOLS_CHECKED);
|
|
489
495
|
if (unchecked.length > 0) {
|
|
490
496
|
lines.push(' ' + unchecked.length + ' more changed, callers not checked: ' +
|
|
491
|
-
unchecked.map((c) => shellQuoteArg(c.symbol) + '() in ' + shellQuoteArg(c.file)).join(', '));
|
|
497
|
+
unchecked.map((c) => shellQuoteArg(c.symbol) + '() in ' + shellQuoteArg(displayOf(c.file))).join(', '));
|
|
492
498
|
}
|
|
493
499
|
// `symbols` / `files`: what the report names, for its telemetry and its
|
|
494
500
|
// follow-up (D#163). Not part of `state`.
|
|
@@ -562,9 +568,13 @@ function runMain() {
|
|
|
562
568
|
const input = readStdinJson();
|
|
563
569
|
if (!input || !input.session_id) return;
|
|
564
570
|
|
|
565
|
-
const { resolveProjectRoot } = require('./project-root');
|
|
566
|
-
const
|
|
571
|
+
const { resolveProjectRoot, indexKey, worktreePrefix } = require('./project-root');
|
|
572
|
+
const cwd = typeof input.cwd === 'string' && input.cwd ? input.cwd : process.cwd();
|
|
573
|
+
const root = resolveProjectRoot(cwd);
|
|
567
574
|
if (root === null) return;
|
|
575
|
+
// A session working in a linked worktree (EnterWorktree) reads the report
|
|
576
|
+
// from there; files in that worktree are named from its top.
|
|
577
|
+
const shownFrom = worktreePrefix(root, path.relative(root, cwd).split(path.sep).join('/'));
|
|
568
578
|
|
|
569
579
|
const sessionEdits = require('./session-edits');
|
|
570
580
|
const { recordRecommendation } = require('./recommendation-log');
|
|
@@ -620,8 +630,13 @@ function runMain() {
|
|
|
620
630
|
workText: (file) => {
|
|
621
631
|
try { return fs.readFileSync(path.join(root, file), 'utf8'); } catch { return null; }
|
|
622
632
|
},
|
|
633
|
+
// D#560 — an isolated agent's edits are logged by their path through its
|
|
634
|
+
// worktree. The index is asked by the key it knows, and the callers it
|
|
635
|
+
// names are that worktree's copies: the ones the agent's change reaches.
|
|
623
636
|
callers: (symbol, file) => {
|
|
624
|
-
const
|
|
637
|
+
const key = indexKey(root, file);
|
|
638
|
+
const worktree = file.slice(0, file.length - key.length);
|
|
639
|
+
const raw = run(binary, ['refs', symbol, '--file', key, '--relation', 'calls',
|
|
625
640
|
'--min-confidence', 'inferred', '--json'], 1500);
|
|
626
641
|
if (raw === null) return null;
|
|
627
642
|
let parsed;
|
|
@@ -630,12 +645,15 @@ function runMain() {
|
|
|
630
645
|
return parsed.references
|
|
631
646
|
.filter((r) => r && typeof r.file_path === 'string')
|
|
632
647
|
.map((r) => {
|
|
648
|
+
const caller = worktree + r.file_path;
|
|
633
649
|
let text = null;
|
|
634
|
-
try { text = fs.readFileSync(path.join(root,
|
|
635
|
-
return { file:
|
|
650
|
+
try { text = fs.readFileSync(path.join(root, caller), 'utf8'); } catch { /* gone */ }
|
|
651
|
+
return { file: caller, name: r.name, line: findCallSiteLine(text, symbol, r.start_line) };
|
|
636
652
|
});
|
|
637
653
|
},
|
|
638
654
|
mtimeMs,
|
|
655
|
+
indexKeyOf: (file) => indexKey(root, file),
|
|
656
|
+
displayOf: (file) => (shownFrom && file.startsWith(shownFrom) ? file.slice(shownFrom.length) : file),
|
|
639
657
|
});
|
|
640
658
|
}
|
|
641
659
|
const rec = reportRecords(report);
|
|
@@ -41,7 +41,7 @@ jobs:
|
|
|
41
41
|
# refuses a snapshot that has no checksum sidecar.
|
|
42
42
|
- name: Build snapshot
|
|
43
43
|
run: |
|
|
44
|
-
npx -y -p @sdsrs/code-graph@0.
|
|
44
|
+
npx -y -p @sdsrs/code-graph@0.178.0 code-graph-mcp snapshot create --out "code-graph-snapshot-${GITHUB_SHA:0:7}.db.zst"
|
|
45
45
|
- name: Upload to release
|
|
46
46
|
env:
|
|
47
47
|
GH_TOKEN: ${{ github.token }}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdsrs/code-graph",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.178.0",
|
|
4
4
|
"description": "MCP server that indexes codebases into an AST knowledge graph with semantic search, call graph traversal, and HTTP route tracing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"node": ">=16"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@sdsrs/code-graph-linux-x64": "0.
|
|
39
|
-
"@sdsrs/code-graph-linux-arm64": "0.
|
|
40
|
-
"@sdsrs/code-graph-darwin-x64": "0.
|
|
41
|
-
"@sdsrs/code-graph-darwin-arm64": "0.
|
|
42
|
-
"@sdsrs/code-graph-win32-x64": "0.
|
|
38
|
+
"@sdsrs/code-graph-linux-x64": "0.178.0",
|
|
39
|
+
"@sdsrs/code-graph-linux-arm64": "0.178.0",
|
|
40
|
+
"@sdsrs/code-graph-darwin-x64": "0.178.0",
|
|
41
|
+
"@sdsrs/code-graph-darwin-arm64": "0.178.0",
|
|
42
|
+
"@sdsrs/code-graph-win32-x64": "0.178.0"
|
|
43
43
|
}
|
|
44
44
|
}
|