@sdsrs/code-graph 0.139.0 → 0.140.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.
@@ -4,7 +4,7 @@
4
4
  "author": {
5
5
  "name": "sdsrs"
6
6
  },
7
- "version": "0.139.0",
7
+ "version": "0.140.0",
8
8
  "keywords": [
9
9
  "code-graph",
10
10
  "ast",
@@ -33,6 +33,34 @@ function pathProbeTimeoutMs(remaining = require('./hook-fail-open').remainingMs)
33
33
  const ms = left === null ? PATH_PROBE_MIN_MS : Math.floor(left);
34
34
  return Math.max(ms, PATH_PROBE_MIN_MS);
35
35
  }
36
+
37
+ // `readBinaryVersion`'s own default. Kept here as the number this module asks
38
+ // for so the clamp below is expressed against the same figure the callee would
39
+ // have used on its own.
40
+ const VERSION_PROBE_TIMEOUT_MS = 5000;
41
+
42
+ /**
43
+ * How long ONE `--version` probe in the discovery chain may run (JS-23, audit
44
+ * 2026-09-07).
45
+ *
46
+ * The version gate execs the candidate binary, and `findBinary()` walks up to
47
+ * six candidates — so a chain of default 5 s probes is 30 s of children on the
48
+ * first thing every hook does, all of it BEFORE the hook has consulted its
49
+ * budget even once. Cold cache (first install, a version bump,
50
+ * `auto-update.clearCache()`) is exactly when the chain is longest and every
51
+ * candidate is a cold page-in.
52
+ *
53
+ * Same shape and the same two edges as `pathProbeTimeoutMs`: never 0 (node
54
+ * reads `timeout: 0` as no timeout), never fractional (ERR_OUT_OF_RANGE, which
55
+ * `readBinaryVersion`'s catch would report as "no version" → a good binary
56
+ * judged stale). With no deadline armed — doctor, statusline, the launcher —
57
+ * it returns the unchanged 5 s default.
58
+ */
59
+ function versionProbeTimeoutMs(remaining = require('./hook-fail-open').remainingMs) {
60
+ const left = remaining(VERSION_PROBE_TIMEOUT_MS);
61
+ const ms = left === null ? PATH_PROBE_MIN_MS : Math.floor(left);
62
+ return Math.max(ms, PATH_PROBE_MIN_MS);
63
+ }
36
64
  const PLATFORM_PKG = `@sdsrs/code-graph-${PLATFORM}-${ARCH}`;
37
65
 
38
66
  /**
@@ -129,9 +157,13 @@ function globalNodeModulesCandidates() {
129
157
 
130
158
  // 4. Last resort: ask npm directly. Slow (~50-200ms) but most accurate when
131
159
  // user has a non-standard prefix. Cached at the disk-cache layer above.
160
+ // Budget-aware like the sibling probes in this file (JS-23 / pre-ship review
161
+ // 2026-09-07): this runs on the same `findBinaryUncached()` chain, and every
162
+ // hook calls `findBinary()` before it consults its own budget. `remainingMs`
163
+ // returns the default unchanged when nothing armed a deadline.
132
164
  try {
133
165
  const npm = npmInvocation(['root', '-g'], {
134
- timeout: 2000,
166
+ timeout: pathProbeTimeoutMs(),
135
167
  stdio: ['pipe', 'pipe', 'pipe'],
136
168
  encoding: 'utf8',
137
169
  });
@@ -186,7 +218,9 @@ function isCachedBinaryFresh(cachedPath, pkgVersion, knownVersion) {
186
218
  // `knownVersion` lets the caller skip the `--version` spawn when the cache
187
219
  // entry already recorded it AND the file has not changed since — see
188
220
  // `readCacheEntry`. Absent, behaviour is exactly as before.
189
- const cacheVer = knownVersion || readBinaryVersion(cachedPath);
221
+ // Clamped: this fires whenever the cache stamp mismatches — i.e. right after
222
+ // an auto-update, on the hook path (JS-23 / pre-ship review 2026-09-07).
223
+ const cacheVer = knownVersion || readBinaryVersion(cachedPath, { timeoutMs: versionProbeTimeoutMs() });
190
224
  if (!cacheVer) return true;
191
225
  return compareVersions(cacheVer, pkgVersion) >= 0;
192
226
  }
@@ -243,7 +277,9 @@ function writeCacheEntry(binPath) {
243
277
  CACHE_FILE,
244
278
  JSON.stringify({
245
279
  path: binPath,
246
- version: readBinaryVersion(binPath) || null,
280
+ // Clamped: this is on the COLD-CACHE path, which is exactly the case
281
+ // JS-23 is about (pre-ship review 2026-09-07).
282
+ version: readBinaryVersion(binPath, { timeoutMs: versionProbeTimeoutMs() }) || null,
247
283
  stamp: binaryStamp(binPath),
248
284
  })
249
285
  );
@@ -396,13 +432,19 @@ function findPlatformBinary() {
396
432
  * gracefully on a slightly-old binary than on "offline", and the stale-binary
397
433
  * self-heal in auto-update.js re-downloads shortly anyway.
398
434
  */
399
- function createVersionGate(pkgVersion, { readVersion = readBinaryVersion } = {}) {
435
+ function createVersionGate(
436
+ pkgVersion,
437
+ { readVersion = readBinaryVersion, probeTimeoutMs = versionProbeTimeoutMs } = {},
438
+ ) {
400
439
  let bestStale = null;
401
440
  return {
402
441
  consider(bin) {
403
442
  if (!isNativeBinary(bin)) return null;
404
443
  if (!pkgVersion) return bin;
405
- const ver = readVersion(bin);
444
+ // Re-read per candidate, not once for the gate: the budget shrinks as the
445
+ // chain walks, and the point is that candidate six cannot still ask for a
446
+ // fresh 5 s (JS-23).
447
+ const ver = readVersion(bin, { timeoutMs: probeTimeoutMs() });
406
448
  if (!ver || compareVersions(ver, pkgVersion) >= 0) return bin;
407
449
  if (!bestStale || compareVersions(ver, bestStale.ver) > 0) bestStale = { bin, ver };
408
450
  return null;
@@ -554,6 +596,7 @@ module.exports = {
554
596
  detectLibc, unsupportedPlatformHint,
555
597
  CACHE_FILE, BINARY_NAME, PLATFORM_PKG,
556
598
  pathProbeTimeoutMs, PATH_PROBE_TIMEOUT_MS, PATH_PROBE_MIN_MS,
599
+ versionProbeTimeoutMs, VERSION_PROBE_TIMEOUT_MS,
557
600
  };
558
601
 
559
602
  // Allow direct invocation for testing
@@ -1616,8 +1616,18 @@ function uninstall({ purgeGlobal = false, unadoptAll = false, runNpm = defaultRu
1616
1616
  }
1617
1617
  }
1618
1618
 
1619
- // 6. Remove cache directory
1620
- try { fs.rmSync(CACHE_DIR, { recursive: true, force: true }); } catch { /* ok */ }
1619
+ // 6. Remove cache directory — through `removeCacheResidue()`, not a bare
1620
+ // rmSync (JS-17, audit 2026-09-07). Without `--unadopt-all` the sweep above
1621
+ // does not run, so the registry is still NON-EMPTY here and a wholesale wipe
1622
+ // strands every managed block — while step 8's own guidance, and `cli.js`,
1623
+ // tell the user their next move is `--unadopt-all`, which then reads an
1624
+ // absent registry and reports nothing to clean. `adoptedProjects` was
1625
+ // captured at 5.5 for the RETURN value; that capture never protected the
1626
+ // file. With `--unadopt-all` the sweep leaves the registry empty (or holding
1627
+ // only projects whose CLAUDE.md could not be rewritten, which is exactly what
1628
+ // must survive), and `removeCacheResidue` preserves only a non-empty one, so
1629
+ // the clean case still leaves nothing behind.
1630
+ try { removeCacheResidue(); } catch { /* ok */ }
1621
1631
 
1622
1632
  // 6.5. The shared tmp dir (cooldown flags, read-fanout state, interrupted
1623
1633
  // `update-*` staging). Nothing in it outlives an uninstall, and the periodic
@@ -1954,12 +1964,14 @@ function isPluginUninstalled(settings = readJson(settingsPath()) || {}) {
1954
1964
  // of which repos carry a managed CLAUDE.md block. Wiping it strands every block
1955
1965
  // — `uninstall({unadoptAll:true})` afterwards reads an empty registry, reports
1956
1966
  // `unadopted: []`, and the blocks stay in the user's repos with nothing left
1957
- // that knows where they are. `uninstall()` captures the list before calling
1958
- // here; `cleanupDisabledStatusline` does not, and by this function's own comment
1959
- // that is the ONE path guaranteed to run after `/plugin uninstall`. So the
1960
- // preservation belongs here, at the wipe, rather than at each caller — the same
1961
- // "fix it at the shared layer, not per surface" the <external> query filter
1962
- // needed.
1967
+ // that knows where they are. No caller can be trusted to protect it first:
1968
+ // `cleanupDisabledStatusline` cannot (it is the ONE path guaranteed to run after
1969
+ // a CC `/plugin uninstall`, and it has no list), and `uninstall()` did not —
1970
+ // it captured the list for its RETURN value and then wiped the file with a bare
1971
+ // rmSync, which is the JS-17 data loss (audit 2026-09-07); it routes through
1972
+ // here now. So the preservation belongs here, at the wipe, rather than at each
1973
+ // caller — the same "fix it at the shared layer, not per surface" the
1974
+ // <external> query filter needed.
1963
1975
  function removeCacheResidue() {
1964
1976
  // Path comes from adopt.js rather than a second spelling of the basename —
1965
1977
  // a literal here would silently stop matching the day adopt.js renames it,
@@ -8,6 +8,21 @@
8
8
  // would swallow the test's own failures.
9
9
  if (require.main === module) require('./hook-fail-open').installHookFailOpen('UserPromptSubmit');
10
10
 
11
+ // Default per-child allowance, spent through the hook budget below.
12
+ const CHILD_TIMEOUT_MS = 3000;
13
+
14
+ /**
15
+ * How long ONE child of this hook may run: the default when nothing armed a
16
+ * deadline (a test importing this module), or whatever is LEFT of the
17
+ * UserPromptSubmit budget. `null` means the budget is exhausted — do not run.
18
+ *
19
+ * Exported so the three states are testable; `run()` below is a closure over
20
+ * the resolved binary and cannot be reached from a test (JS-18).
21
+ */
22
+ function childBudgetMs() {
23
+ return require('./hook-fail-open').remainingMs(CHILD_TIMEOUT_MS);
24
+ }
25
+
11
26
  // UserPromptSubmit hook: inject relevant code-graph RESULTS based on user's intent.
12
27
  // Strategy: PUSH structural context (not suggestions) that Grep/Read cannot provide.
13
28
  // This is a CODE INDEX — only inject structural code context (impact, overview, callgraph).
@@ -518,9 +533,18 @@ function runMain() {
518
533
  if (!binary) return;
519
534
 
520
535
  function run(args) {
536
+ // JS-18 (audit 2026-09-07): spend the UserPromptSubmit budget, don't ask
537
+ // for a fresh 3 s. This file armed a deadline at line 1 and then never
538
+ // consulted it — the literal here plus the `findBinary()` chain above ran
539
+ // outside it, so a cold cache had the hook killed by Claude Code and the
540
+ // user saw a hook error on THEIR prompt. `null` means the budget is gone:
541
+ // do not run (node reads `timeout: 0` as no timeout at all). Returning ''
542
+ // lands on the same "nothing to say" path as an empty result.
543
+ const budget = childBudgetMs();
544
+ if (budget === null) return '';
521
545
  return execFileSync(binary, args, hidden({
522
546
  cwd,
523
- timeout: 3000,
547
+ timeout: budget,
524
548
  encoding: 'utf8',
525
549
  stdio: ['pipe', 'pipe', 'pipe'],
526
550
  env: buildRunEnv(),
@@ -553,4 +577,4 @@ if (require.main === module) {
553
577
  runMain();
554
578
  }
555
579
 
556
- module.exports = { COOLDOWNS, shouldSkip, extractFilePaths, extractSymbols, detectIntents, scoreIntent, INTENT_PATTERNS, INTENT_THRESHOLD, determineQueryType, computeQuietHooks, STOP_WORDS, PLAIN_WORD_EXCLUDE, hasSymptom, SYMPTOM_PATTERNS, buildRunEnv };
580
+ module.exports = { COOLDOWNS, shouldSkip, extractFilePaths, extractSymbols, detectIntents, scoreIntent, INTENT_PATTERNS, INTENT_THRESHOLD, determineQueryType, computeQuietHooks, STOP_WORDS, PLAIN_WORD_EXCLUDE, hasSymptom, SYMPTOM_PATTERNS, buildRunEnv, childBudgetMs, CHILD_TIMEOUT_MS };
@@ -35,7 +35,7 @@ jobs:
35
35
  node-version: '20'
36
36
  - name: Build snapshot
37
37
  run: |
38
- npx -y -p @sdsrs/code-graph@0.139.0 code-graph-mcp snapshot create --out snapshot.db
38
+ npx -y -p @sdsrs/code-graph@0.140.0 code-graph-mcp snapshot create --out snapshot.db
39
39
  zstd -9 snapshot.db -o snapshot.db.zst
40
40
  mv snapshot.db.zst "code-graph-snapshot-${GITHUB_SHA:0:7}.db.zst"
41
41
  - name: Upload to release
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdsrs/code-graph",
3
- "version": "0.139.0",
3
+ "version": "0.140.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.139.0",
39
- "@sdsrs/code-graph-linux-arm64": "0.139.0",
40
- "@sdsrs/code-graph-darwin-x64": "0.139.0",
41
- "@sdsrs/code-graph-darwin-arm64": "0.139.0",
42
- "@sdsrs/code-graph-win32-x64": "0.139.0"
38
+ "@sdsrs/code-graph-linux-x64": "0.140.0",
39
+ "@sdsrs/code-graph-linux-arm64": "0.140.0",
40
+ "@sdsrs/code-graph-darwin-x64": "0.140.0",
41
+ "@sdsrs/code-graph-darwin-arm64": "0.140.0",
42
+ "@sdsrs/code-graph-win32-x64": "0.140.0"
43
43
  }
44
44
  }