@sdsrs/code-graph 0.5.33 → 0.5.35

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.5.33",
7
+ "version": "0.5.35",
8
8
  "keywords": [
9
9
  "code-graph",
10
10
  "ast",
@@ -17,8 +17,8 @@ try {
17
17
  fs.writeFileSync(flag, '');
18
18
  process.stdout.write(
19
19
  '[code-graph] For code structure understanding, try code-graph first (one call vs many):\n' +
20
- ' project_map full architecture overview\n' +
21
- ' module_overview(path) module structure, exports, hot paths\n' +
22
- ' get_call_graph(symbol) trace call chains\n' +
20
+ ' project_map(compact=true) \u2192 full architecture overview\n' +
21
+ ' module_overview(path, compact=true) \u2192 module structure, exports, hot paths\n' +
22
+ ' get_call_graph(symbol, compact=true) \u2192 trace call chains\n' +
23
23
  'Explore agents remain best for: non-code files, runtime behavior, open-ended investigation.\n'
24
24
  );
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
  // PreToolUse hook: On FIRST Glob call per session window, suggest
4
- // code-graph tools when exploring project structure (not finding specific files).
4
+ // code-graph tools — but only when exploring project structure,
5
+ // NOT finding specific files by name.
5
6
  const fs = require('fs');
6
7
  const path = require('path');
7
8
  const os = require('os');
@@ -14,10 +15,24 @@ try {
14
15
  if (Date.now() - stat.mtimeMs < WINDOW_MS) process.exit(0);
15
16
  } catch { /* first time */ }
16
17
 
18
+ // Parse tool input to detect intent — skip for specific file lookups
19
+ try {
20
+ const input = JSON.parse(fs.readFileSync('/dev/stdin', 'utf8'));
21
+ const pattern = (input && input.tool_input && input.tool_input.pattern) || '';
22
+ // Skip suggestion for: specific file patterns (has extension), config files, specific names
23
+ if (/\.(json|yaml|yml|toml|md|txt|env|lock|config|rc)$/i.test(pattern)) {
24
+ process.exit(0);
25
+ }
26
+ // Skip for patterns with specific filenames (not just wildcards like **/*.ts)
27
+ if (!pattern.includes('*') && /[\w-]+\.\w{1,5}$/.test(pattern)) {
28
+ process.exit(0);
29
+ }
30
+ } catch { /* stdin not available or parse error — show guide anyway */ }
31
+
17
32
  fs.writeFileSync(flag, '');
18
33
  process.stdout.write(
19
34
  '[code-graph] If exploring project structure (not finding specific files):\n' +
20
- ' project_map all modules, their files, key symbols, and dependencies\n' +
21
- ' module_overview(path) files and exports within a module\n' +
35
+ ' project_map(compact=true) \u2192 all modules, files, key symbols, dependencies\n' +
36
+ ' module_overview(path, compact=true) \u2192 files and exports within a module\n' +
22
37
  'Glob remains best for: finding specific files, configs, non-code assets.\n'
23
38
  );
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
  // PreToolUse hook: On FIRST Grep call per session window, suggest
4
- // code-graph tools as complementary options for code understanding.
4
+ // code-graph tools but only when the pattern looks like code understanding
5
+ // (function names, module patterns), NOT exact string/constant searches.
5
6
  const fs = require('fs');
6
7
  const path = require('path');
7
8
  const os = require('os');
@@ -14,11 +15,25 @@ try {
14
15
  if (Date.now() - stat.mtimeMs < WINDOW_MS) process.exit(0);
15
16
  } catch { /* first time */ }
16
17
 
18
+ // Parse tool input to detect intent — skip for literal/constant searches
19
+ try {
20
+ const input = JSON.parse(fs.readFileSync('/dev/stdin', 'utf8'));
21
+ const pattern = (input && input.tool_input && input.tool_input.pattern) || '';
22
+ // Skip suggestion for: quoted strings, TODO/FIXME, constants, exact literals, error messages
23
+ if (/^["']|^(TODO|FIXME|HACK|WARN|ERROR|const )|^\w+[=:]/i.test(pattern)) {
24
+ process.exit(0);
25
+ }
26
+ // Skip for very short patterns (likely exact match)
27
+ if (pattern.length <= 3) {
28
+ process.exit(0);
29
+ }
30
+ } catch { /* stdin not available or parse error — show guide anyway */ }
31
+
17
32
  fs.writeFileSync(flag, '');
18
33
  process.stdout.write(
19
34
  '[code-graph] For understanding code relationships, these tools complement Grep:\n' +
20
- ' get_call_graph(symbol) who calls X / what X calls (vs Grep + Read ×N)\n' +
21
- ' module_overview(path) module exports, structure, hot paths\n' +
22
- ' semantic_code_search(query) find code by concept across indexed files\n' +
35
+ ' get_call_graph(symbol, compact=true) \u2192 who calls X / what X calls\n' +
36
+ ' semantic_code_search(query, compact=true) \u2192 find code by concept\n' +
37
+ ' module_overview(path, compact=true) \u2192 module exports and structure\n' +
23
38
  'Grep remains best for: exact strings, regex, constants, non-code files.\n'
24
39
  );
@@ -1,30 +1,35 @@
1
1
  ---
2
2
  name: code-navigation
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).
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 5-20x tokens. Especially critical before modifying functions (impact_analysis first).
4
4
  ---
5
5
 
6
6
  # Code Navigation Rules
7
7
 
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.**
8
+ This project has a code-graph MCP server. The MCP instructions (injected at session start) are the authoritative decision table.
10
9
 
11
- ## Decision Rules
10
+ **Key principle: code-graph tools SUPERSEDE Grep/Agent for code understanding. Use compact=true for browsing, full when you need signatures or will edit.**
12
11
 
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 |
12
+ ## Quick Reference
13
+
14
+ | Task | Tool | Savings |
15
+ |---|---|---|
16
+ | Architecture overview | `project_map(compact=true)` | 20x vs Read multiple |
17
+ | Who calls X / what X calls | `get_call_graph(symbol, compact=true)` | 13x vs Grep+Read |
18
+ | Understand module/directory | `module_overview(path, compact=true)` | 20x vs Read files |
19
+ | **Before modifying a function** | `impact_analysis(symbol)` FIRST | prevents breakage |
20
+ | Find code by concept | `semantic_code_search(query, compact=true)` | 10x vs Grep |
21
+ | Trace HTTP request flow | `trace_http_chain(route)` | 10x vs Read |
22
+ | Symbol signature+relations | `get_ast_node(node_id)` | 10x vs Read file |
23
+ | File dependencies | `dependency_graph(file)` | 5x vs Grep |
24
+
25
+ ## Workflow Patterns
26
+
27
+ 1. **Quick lookup**: `semantic_code_search(compact=true)` → `get_ast_node(node_id=N)`
28
+ 2. **Before edit**: `impact_analysis(symbol)` → Edit
29
+ 3. **Understand**: `project_map(compact=true)` → `module_overview(path, compact=true)` → `get_call_graph(symbol)`
24
30
 
25
31
  ## When to use native tools instead
26
32
 
27
33
  - **Grep**: exact string match, constants, regex patterns, literal text search
28
34
  - **Glob**: find files by name/path pattern
29
35
  - **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.33",
3
+ "version": "0.5.35",
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.33",
37
- "@sdsrs/code-graph-linux-arm64": "0.5.33",
38
- "@sdsrs/code-graph-darwin-x64": "0.5.33",
39
- "@sdsrs/code-graph-darwin-arm64": "0.5.33",
40
- "@sdsrs/code-graph-win32-x64": "0.5.33"
36
+ "@sdsrs/code-graph-linux-x64": "0.5.35",
37
+ "@sdsrs/code-graph-linux-arm64": "0.5.35",
38
+ "@sdsrs/code-graph-darwin-x64": "0.5.35",
39
+ "@sdsrs/code-graph-darwin-arm64": "0.5.35",
40
+ "@sdsrs/code-graph-win32-x64": "0.5.35"
41
41
  }
42
42
  }