Skip to content

Commit cc2067a

Browse files
sdsrssclaude
andcommitted
fix(plugin): slug regex + script path resolution for npm install (v0.8.2)
Two critical bugs discovered during real-user flow simulation — both block adopt/doctor from working in any non-dev install layout. **Bug 1 — slug regex** (adopt.js): memoryDir used `cwd.replace(/\//g, '-')` which only handled forward slashes. Claude Code's actual slug convention is every non-alphanumeric-non-hyphen char → `-`. For the common dev path `/mnt/data_ssd/...` this caused the underscore to be preserved, producing `-mnt-data_ssd-...` instead of the actual `-mnt-data-ssd-...` dir name. Result: adopt always reported "Memory dir not found" for the user's own project. Test coverage gap: existing tests used underscore-free paths. Fix: cwd.replace(/[^a-zA-Z0-9-]/g, '-'). Added 1 test covering underscores, dots (double-dash from `/.`), case preservation, trailing version numbers. All 77 tests pass (was 76). **Bug 2 — script path resolution** (main.rs): run_node_script looked only at exe_dir/../../ and exe_dir/../ for claude-plugin/scripts/. In npm install layout, the binary lives in node_modules/@sdsrs/code-graph-<plat>/ but claude-plugin/ is in the sibling main pkg node_modules/@sdsrs/code-graph/ — unreachable via relative-from-exe. Same issue for auto-update-cache binaries at ~/.cache/code-graph/bin/. Affected adopt/unadopt (new) AND the pre-existing doctor subcommand. Fix: first consult $_FIND_BINARY_ROOT env var (set by bin/cli.js npm wrapper to main pkg root) before relative-from-exe. Dev mode still works via candidate 2 (exe_dir/../../). Error message now lists all candidates searched so users can self-diagnose install issues. E2E verification: - Direct binary from repo root: adopt succeeds for actual user cwd - cli.js wrapper + auto-update-cache binary: adopt.js located via $_FIND_BINARY_ROOT, slug correct, flow reaches memoryDir check - Quiet mode MCP instructions: 338 chars (unchanged from v0.8.1) - session-init.js quiet: mapInjected=false (unchanged) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fbb0e6e commit cc2067a

File tree

13 files changed

+63
-22
lines changed

13 files changed

+63
-22
lines changed

.claude-plugin/marketplace.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
},
66
"metadata": {
77
"description": "AST knowledge graph plugin for Claude Code — semantic search, call graph, HTTP tracing, impact analysis",
8-
"version": "0.8.1"
8+
"version": "0.8.2"
99
},
1010
"plugins": [
1111
{
1212
"name": "code-graph-mcp",
1313
"source": "./claude-plugin",
1414
"description": "AST knowledge graph for intelligent code navigation — auto-indexes your codebase and provides semantic search, call graph traversal, HTTP route tracing, and impact analysis via MCP tools",
15-
"version": "0.8.1",
15+
"version": "0.8.2",
1616
"author": {
1717
"name": "sdsrs"
1818
},

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "code-graph-mcp"
3-
version = "0.8.1"
3+
version = "0.8.2"
44
edition = "2021"
55

66
[features]

claude-plugin/.claude-plugin/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": {
55
"name": "sdsrs"
66
},
7-
"version": "0.8.1",
7+
"version": "0.8.2",
88
"keywords": [
99
"code-graph",
1010
"ast",

claude-plugin/scripts/adopt.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ const INDEX_LINE = '- [code-graph-mcp](plugin_code_graph_mcp.md) — "谁调 X /
1313
const TEMPLATE_PATH = path.resolve(__dirname, '..', 'templates', 'plugin_code_graph_mcp.md');
1414
const TARGET_NAME = 'plugin_code_graph_mcp.md';
1515

16+
// Claude Code slug convention: every non-alphanumeric-non-hyphen char → `-`.
17+
// `/mnt/data_ssd/dev/proj` → `-mnt-data-ssd-dev-proj`
18+
// `/home/sds/.claude/x` → `-home-sds--claude-x` (double-dash from `/.`)
1619
function memoryDir(cwd = process.cwd(), home = os.homedir()) {
17-
const slug = cwd.replace(/\//g, '-');
20+
const slug = cwd.replace(/[^a-zA-Z0-9-]/g, '-');
1821
return path.join(home, '.claude', 'projects', slug, 'memory');
1922
}
2023

claude-plugin/scripts/adopt.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ test('memoryDir slugifies cwd path', () => {
2626
assert.strictEqual(dir, '/home/alice/.claude/projects/-home-alice-proj/memory');
2727
});
2828

29+
test('memoryDir replaces underscores and dots (Claude Code slug convention)', () => {
30+
// Real-world bug: /mnt/data_ssd/... needs data-ssd slug, not data_ssd
31+
assert.strictEqual(
32+
memoryDir('/mnt/data_ssd/dev/projects/code-graph-mcp', '/home/u'),
33+
'/home/u/.claude/projects/-mnt-data-ssd-dev-projects-code-graph-mcp/memory'
34+
);
35+
// Hidden dirs: /home/sds/.claude/x → -home-sds--claude-x (double-dash)
36+
assert.strictEqual(
37+
memoryDir('/home/sds/.claude/x', '/home/sds'),
38+
'/home/sds/.claude/projects/-home-sds--claude-x/memory'
39+
);
40+
// Preserves case and hyphens
41+
assert.strictEqual(
42+
memoryDir('/Users/Alice/my-Project_v2.1', '/'),
43+
'/.claude/projects/-Users-Alice-my-Project-v2-1/memory'
44+
);
45+
});
46+
2947
test('adopt writes template and appends sentinel block when index absent', () => {
3048
const sb = makeSandbox();
3149
try {

npm/darwin-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sdsrs/code-graph-darwin-arm64",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"description": "code-graph-mcp binary for macOS ARM64",
55
"license": "MIT",
66
"repository": {

npm/darwin-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sdsrs/code-graph-darwin-x64",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"description": "code-graph-mcp binary for macOS x64",
55
"license": "MIT",
66
"repository": {

npm/linux-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sdsrs/code-graph-linux-arm64",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"description": "code-graph-mcp binary for Linux ARM64",
55
"license": "MIT",
66
"repository": {

npm/linux-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sdsrs/code-graph-linux-x64",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"description": "code-graph-mcp binary for Linux x64",
55
"license": "MIT",
66
"repository": {

0 commit comments

Comments
 (0)