@sdsrs/code-graph 0.141.0 → 0.143.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.141.0",
7
+ "version": "0.143.0",
8
8
  "keywords": [
9
9
  "code-graph",
10
10
  "ast",
@@ -844,6 +844,48 @@ function unadopt({ cwd, home } = {}) {
844
844
  };
845
845
  }
846
846
 
847
+ /**
848
+ * The `unadopt` invocation to hand the user, spelled so their shell can run it.
849
+ *
850
+ * Issue #41: the reporter drives this plugin through `/plugin install` only and
851
+ * has no `code-graph-mcp` on PATH, so every remedy printed with the bare name is
852
+ * answered by their shell with "command not found".
853
+ *
854
+ * The obvious repair — print the binary `verifyBinary()` resolved — is WRONG,
855
+ * and a pre-ship review caught it as a net regression. `unadopt` is one of the
856
+ * three JS-dispatched subcommands (`main.rs`: doctor / adopt / unadopt): the
857
+ * native binary re-execs this file, which it locates via `$_FIND_BINARY_ROOT`
858
+ * or a path relative to its own exe. The plugin's cached binary at
859
+ * ~/.cache/code-graph/bin has no such neighbour, so `<cache>/code-graph-mcp
860
+ * unadopt` exits 1 with "adopt.js not found" — reproduced. Worse, npm-global
861
+ * users reach this file today through the `bin/cli.js` shim that sets
862
+ * `_FIND_BINARY_ROOT`, so printing a resolved platform-package binary would
863
+ * BREAK a path that currently works.
864
+ *
865
+ * So point at this script. It carries its own `require.main === module` arm, and
866
+ * `__filename` is the one locator that cannot be wrong in any install layout —
867
+ * plugin cache, npm package, dev checkout. Quoted, since a plugin cache path
868
+ * under a home directory with a space is otherwise not runnable as printed.
869
+ *
870
+ * Lives here rather than in session-init.js (0.141.0's home for it) because
871
+ * BOTH printers that hand a user this command must agree, and the other one is
872
+ * `formatResult` directly below — the site 0.141.0's sweep missed.
873
+ */
874
+ function shellQuote(value) {
875
+ // SINGLE quotes, not JSON.stringify. `JSON.stringify` emits DOUBLE quotes, and
876
+ // a POSIX shell still expands `$`, backticks and `$(...)` inside those — so a
877
+ // path holding any of them would be rewritten, or executed, when the user
878
+ // pastes the line we printed. Single quotes are literal for everything except
879
+ // `'` itself, which is closed, escaped and reopened. POSIX-only is fine here:
880
+ // `platformGuard()` refuses adopt on win32, so this string never targets cmd
881
+ // or PowerShell. (CodeRabbit on PR #46; inherited from the 0.141.0 spelling.)
882
+ return `'${value.replace(/'/g, "'\\''")}'`;
883
+ }
884
+
885
+ function unadoptCommand() {
886
+ return `node ${shellQuote(__filename)} unadopt`;
887
+ }
888
+
847
889
  function formatResult(action, result) {
848
890
  if (!result.ok && result.reason === 'windows-not-supported') {
849
891
  return '[code-graph] adopt/unadopt are POSIX-only on this build. ' +
@@ -881,7 +923,7 @@ function formatResult(action, result) {
881
923
  lines.push(`[code-graph] Detail table → ${result.detailPath}`);
882
924
  lines.push('[code-graph] CLAUDE.md is git-tracked — commit the block, or gitignore');
883
925
  lines.push('[code-graph] .claude/plugin_code_graph_mcp.md (a generated copy) as you prefer.');
884
- lines.push('[code-graph] Reverse: code-graph-mcp unadopt');
926
+ lines.push(`[code-graph] Reverse: ${unadoptCommand()}`);
885
927
  lines.push('[code-graph] Opt out: CODE_GRAPH_NO_AUTO_ADOPT=1 in ~/.claude/settings.json env');
886
928
  return lines.join('\n');
887
929
  }
@@ -934,7 +976,7 @@ if (require.main === module) {
934
976
  }
935
977
 
936
978
  module.exports = {
937
- adopt, unadopt, memoryDir, formatResult, stripSentinelBlock,
979
+ adopt, unadopt, memoryDir, formatResult, unadoptCommand, shellQuote, stripSentinelBlock,
938
980
  readAdoptedProjects, readAdoptedResult, recordAdopted, removeAdopted, adoptedRegistryFile,
939
981
  isAdopted, isPluginModeInstall, maybeAutoAdopt, needsRefresh, isProjectRoot,
940
982
  detectProjectType, buildBlock, buildTriggerRows, migrateLegacyMemoryDir,
@@ -780,7 +780,24 @@ function reportUnadoptSweep(entries) {
780
780
  lines.push(' Your own text outside the block was kept; .code-graph/ index dirs are untouched.');
781
781
  }
782
782
  if (failed.length) {
783
- lines.push(`[code-graph] Could NOT clean ${failed.length} project(s) — remove the block by hand or run \`code-graph-mcp unadopt\` there:`);
783
+ // Issue #41's third printer. The other two now spend `unadoptCommand()`,
784
+ // and that IS still runnable at the instant this line prints — the reclaim
785
+ // below never touches the plugin's script dir. But this is advice acted on
786
+ // minutes or days later, in OTHER repositories, and the plugin directory is
787
+ // Claude Code's to reap once the uninstall settles. A path into it is
788
+ // correct-when-printed and possibly-stale-when-pasted, and the bare name it
789
+ // replaced was never runnable for a plugin-only install at all.
790
+ //
791
+ // So lead with the remedy that cannot go stale: the block is
792
+ // sentinel-delimited, so deleting the lines between the two markers is a
793
+ // complete instruction that needs no tooling, no network and no surviving
794
+ // install. The tool route follows it, named as optional.
795
+ const { SENTINEL_BEGIN, SENTINEL_END } = require('./adopt');
796
+ lines.push(`[code-graph] Could NOT clean ${failed.length} project(s). In each CLAUDE.md below, delete`);
797
+ lines.push(` everything from ${SENTINEL_BEGIN}`);
798
+ lines.push(` through ${SENTINEL_END}`);
799
+ lines.push(' (your own text outside those markers is not ours to remove), or run');
800
+ lines.push(' `npx -y @sdsrs/code-graph unadopt` in the project:');
784
801
  for (const p of failed.slice(0, 10)) lines.push(` ${p}`);
785
802
  }
786
803
  process.stderr.write(lines.join('\n') + '\n');
@@ -10,7 +10,7 @@ const {
10
10
  } = require('./lifecycle');
11
11
  const { UPDATE_STATE_FILE } = require('./cache-paths');
12
12
  const { readBinaryVersion, isDevMode, getNewestMtime } = require('./version-utils');
13
- const { maybeAutoAdopt, isAdopted, unadopt } = require('./adopt');
13
+ const { maybeAutoAdopt, isAdopted, unadopt, unadoptCommand } = require('./adopt');
14
14
  const { isNonProjectCwd } = require('./project-detect');
15
15
  const { hidden } = require('./proc-opts');
16
16
  const { installHookFailOpen, remainingMs } = require('./hook-fail-open');
@@ -557,34 +557,12 @@ function verifyBinary() {
557
557
  return { available: true, binary };
558
558
  }
559
559
 
560
- /**
561
- * The `unadopt` invocation to hand the user, spelled so their shell can run it.
562
- *
563
- * Issue #41: the reporter drives this plugin through `/plugin install` only and
564
- * has no `code-graph-mcp` on PATH, so every remedy this hook printed spent a
565
- * bare name their shell answers with "command not found".
566
- *
567
- * The obvious repair — print the binary `verifyBinary()` resolved — is WRONG,
568
- * and a pre-ship review caught it as a net regression. `unadopt` is one of the
569
- * three JS-dispatched subcommands (`main.rs`: doctor / adopt / unadopt): the
570
- * native binary re-execs `claude-plugin/scripts/adopt.js`, which it locates via
571
- * `$_FIND_BINARY_ROOT` or a path relative to its own exe. The plugin's cached
572
- * binary at ~/.cache/code-graph/bin has no such neighbour, so
573
- * `<cache>/code-graph-mcp unadopt` exits 1 with "adopt.js not found" —
574
- * reproduced. Worse, npm-global users reach adopt.js today through the
575
- * `bin/cli.js` shim that sets `_FIND_BINARY_ROOT`, so printing a resolved
576
- * platform-package binary would BREAK a path that currently works.
577
- *
578
- * So point at the script itself. `adopt.js` carries its own
579
- * `require.main === module` arm (`node adopt.js unadopt`), and this file is its
580
- * neighbour in every install layout — plugin cache, npm package, dev checkout —
581
- * because both are shipped inside `claude-plugin/scripts/`. `__dirname` is
582
- * therefore the one locator that cannot be wrong. Quoted, since a plugin cache
583
- * path under a home directory with a space is otherwise not runnable as printed.
584
- */
585
- function unadoptCommand() {
586
- return `node ${JSON.stringify(path.join(__dirname, 'adopt.js'))} unadopt`;
587
- }
560
+ // `unadoptCommand` now lives in adopt.js (issue #41's rationale travels with
561
+ // it). It moved because THIS file was not the only printer handing a user that
562
+ // command — adopt.js's own `formatResult` prints a `Reverse:` line too, and it
563
+ // was still spending the bare name after 0.141.0 fixed the announcement below.
564
+ // Two spellings of one remedy is what let that survive; re-exported here so the
565
+ // name stays importable from this module.
588
566
 
589
567
  /**
590
568
  * Lightweight consistency checks — called from runSessionInit().
@@ -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.141.0 code-graph-mcp snapshot create --out snapshot.db
38
+ npx -y -p @sdsrs/code-graph@0.143.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.141.0",
3
+ "version": "0.143.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.141.0",
39
- "@sdsrs/code-graph-linux-arm64": "0.141.0",
40
- "@sdsrs/code-graph-darwin-x64": "0.141.0",
41
- "@sdsrs/code-graph-darwin-arm64": "0.141.0",
42
- "@sdsrs/code-graph-win32-x64": "0.141.0"
38
+ "@sdsrs/code-graph-linux-x64": "0.143.0",
39
+ "@sdsrs/code-graph-linux-arm64": "0.143.0",
40
+ "@sdsrs/code-graph-darwin-x64": "0.143.0",
41
+ "@sdsrs/code-graph-darwin-arm64": "0.143.0",
42
+ "@sdsrs/code-graph-win32-x64": "0.143.0"
43
43
  }
44
44
  }