@sdsrs/code-graph 0.5.1 → 0.5.3
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/commands/rebuild.md +6 -0
- package/claude-plugin/commands/status.md +8 -0
- package/claude-plugin/hooks/hooks.json +24 -0
- package/claude-plugin/scripts/pre-edit-guide.js +21 -0
- package/claude-plugin/scripts/pre-search-guide.js +25 -0
- package/claude-plugin/scripts/session-init.js +8 -0
- package/claude-plugin/skills/code-navigation.md +23 -22
- package/package.json +6 -6
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"hooks": {
|
|
3
|
+
"PreToolUse": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "tool == \"Grep\"",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/pre-search-guide.js\"",
|
|
10
|
+
"timeout": 2
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"description": "Suggest code-graph alternatives on first Grep call"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"matcher": "tool == \"Edit\" || tool == \"Write\"",
|
|
17
|
+
"hooks": [
|
|
18
|
+
{
|
|
19
|
+
"type": "command",
|
|
20
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/pre-edit-guide.js\"",
|
|
21
|
+
"timeout": 2
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"description": "Remind about impact_analysis before first code modification"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
3
27
|
"PostToolUse": [
|
|
4
28
|
{
|
|
5
29
|
"matcher": "tool == \"Write\" || tool == \"Edit\"",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// PreToolUse hook: On FIRST Edit/Write call per session window, remind Claude
|
|
4
|
+
// to check impact_analysis before modifying functions. Fast and non-blocking.
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
|
|
9
|
+
const flag = path.join(os.tmpdir(), '.code-graph-edit-guided');
|
|
10
|
+
const WINDOW_MS = 2 * 60 * 60 * 1000; // 2 hours
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const stat = fs.statSync(flag);
|
|
14
|
+
if (Date.now() - stat.mtimeMs < WINDOW_MS) process.exit(0);
|
|
15
|
+
} catch { /* first time */ }
|
|
16
|
+
|
|
17
|
+
fs.writeFileSync(flag, '');
|
|
18
|
+
process.stdout.write(
|
|
19
|
+
'[code-graph] Before modifying functions, consider running impact_analysis(symbol_name) ' +
|
|
20
|
+
'to check blast radius (callers, affected routes, risk level).\n'
|
|
21
|
+
);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// PreToolUse hook: On FIRST Grep call per session window, remind Claude
|
|
4
|
+
// about code-graph alternatives. Runs fast (<10ms) and only outputs once.
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
|
|
9
|
+
const flag = path.join(os.tmpdir(), '.code-graph-search-guided');
|
|
10
|
+
const WINDOW_MS = 2 * 60 * 60 * 1000; // 2 hours (approximate session window)
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const stat = fs.statSync(flag);
|
|
14
|
+
if (Date.now() - stat.mtimeMs < WINDOW_MS) process.exit(0);
|
|
15
|
+
} catch { /* flag doesn't exist — first time */ }
|
|
16
|
+
|
|
17
|
+
fs.writeFileSync(flag, '');
|
|
18
|
+
process.stdout.write(
|
|
19
|
+
'[code-graph] For code understanding, prefer code-graph tools over Grep:\n' +
|
|
20
|
+
' project_map → full project architecture overview (call FIRST)\n' +
|
|
21
|
+
' semantic_code_search → find code by concept (10x fewer tokens)\n' +
|
|
22
|
+
' get_call_graph → who calls X / what X calls (13x fewer tokens)\n' +
|
|
23
|
+
' module_overview → understand a module (20x fewer tokens)\n' +
|
|
24
|
+
'Use Grep only for exact strings, constants, or regex patterns.\n'
|
|
25
|
+
);
|
|
@@ -18,6 +18,14 @@ if (BIN) {
|
|
|
18
18
|
} catch { /* timeout — silent */ }
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
// --- 1b. Suggest project_map as first action ---
|
|
22
|
+
if (BIN) {
|
|
23
|
+
process.stdout.write(
|
|
24
|
+
'\n[code-graph] TIP: Call project_map first to get a full architecture overview ' +
|
|
25
|
+
'(modules, dependencies, hot functions, entry points) in one call.\n'
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
// --- 2. Scope conflict warning ---
|
|
22
30
|
const conflict = checkScopeConflict();
|
|
23
31
|
if (conflict) {
|
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: code-navigation
|
|
3
|
-
description:
|
|
3
|
+
description: PROACTIVE code-graph tool selection. Triggers automatically when you need to explore, understand, trace, or modify code. Use BEFORE choosing Grep/Read for code understanding tasks — code-graph tools save 10-40x tokens. Especially critical before modifying functions (impact_analysis first).
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Code Navigation
|
|
6
|
+
# Code Navigation Rules
|
|
7
7
|
|
|
8
|
-
This project has a code-graph MCP server
|
|
9
|
-
|
|
10
|
-
PRIMARY navigation method for code understanding tasks.
|
|
8
|
+
This project has a code-graph MCP server. These tools return structured, token-efficient results.
|
|
9
|
+
**Use them as your PRIMARY navigation method. Fall back to Grep/Read only for exact-match or file editing.**
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|---|---|---|
|
|
14
|
-
| Find code by concept/meaning | `semantic_code_search` | Grep multiple patterns |
|
|
15
|
-
| Understand who calls what | `get_call_graph` | Grep function name + Read files |
|
|
16
|
-
| Trace HTTP request flow | `trace_http_chain` | Read router -> handler -> service |
|
|
17
|
-
| Find route handler | `find_http_route` | Grep route string |
|
|
18
|
-
| Get symbol signature + relations | `get_ast_node` | Read entire file |
|
|
19
|
-
| Read specific code after search | `read_snippet` (by node_id) | Read entire file |
|
|
20
|
-
| Analyze change impact | `impact_analysis` | Manual call graph tracing |
|
|
21
|
-
| Understand a module | `module_overview` | Read all files in directory |
|
|
22
|
-
| Map dependencies | `dependency_graph` | Grep import statements |
|
|
23
|
-
| Find similar code | `find_similar_code` | Grep partial function names |
|
|
11
|
+
## Decision Rules
|
|
24
12
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
| Task | MUST use | NOT this | Token savings |
|
|
14
|
+
|---|---|---|---|
|
|
15
|
+
| Who calls X / what X calls | `get_call_graph` | Grep + Read ×5 | 13x |
|
|
16
|
+
| Understand module/directory | `module_overview` | Read multiple files | 20x |
|
|
17
|
+
| **Before modifying a function** | `impact_analysis` FIRST | Just Edit | prevents breakage |
|
|
18
|
+
| Find code by concept/meaning | `semantic_code_search` | Grep multiple patterns | 10x |
|
|
19
|
+
| Trace HTTP request flow | `trace_http_chain` | Read router→handler→service | 10x |
|
|
20
|
+
| One symbol's signature+relations | `get_ast_node` | Read entire file | 10x |
|
|
21
|
+
| File import/export dependencies | `dependency_graph` | Grep import statements | 5x |
|
|
22
|
+
| Find similar/duplicate code | `find_similar_code` | Grep partial names | 5x |
|
|
23
|
+
| Read code of a search result | `get_ast_node` (by node_id) | Read entire file | 3x |
|
|
24
|
+
|
|
25
|
+
## When to use native tools instead
|
|
26
|
+
|
|
27
|
+
- **Grep**: exact string match, constants, regex patterns, literal text search
|
|
28
|
+
- **Glob**: find files by name/path pattern
|
|
29
|
+
- **Read**: specific file you already know and need to edit
|
|
30
|
+
- **Write/Edit**: creating or modifying files
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdsrs/code-graph",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
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": {
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"node": ">=16"
|
|
34
34
|
},
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@sdsrs/code-graph-linux-x64": "0.5.
|
|
37
|
-
"@sdsrs/code-graph-linux-arm64": "0.5.
|
|
38
|
-
"@sdsrs/code-graph-darwin-x64": "0.5.
|
|
39
|
-
"@sdsrs/code-graph-darwin-arm64": "0.5.
|
|
40
|
-
"@sdsrs/code-graph-win32-x64": "0.5.
|
|
36
|
+
"@sdsrs/code-graph-linux-x64": "0.5.3",
|
|
37
|
+
"@sdsrs/code-graph-linux-arm64": "0.5.3",
|
|
38
|
+
"@sdsrs/code-graph-darwin-x64": "0.5.3",
|
|
39
|
+
"@sdsrs/code-graph-darwin-arm64": "0.5.3",
|
|
40
|
+
"@sdsrs/code-graph-win32-x64": "0.5.3"
|
|
41
41
|
}
|
|
42
42
|
}
|