@sdsrs/code-graph 0.7.13 → 0.7.14

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.7.13",
7
+ "version": "0.7.14",
8
8
  "keywords": [
9
9
  "code-graph",
10
10
  "ast",
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Analyze impact scope before modifying a symbol
2
+ description: Analyze blast radius before modifying a symbol. Use when about to edit/rename/remove a function, or asked about change risk and affected callers.
3
3
  argument-hint: <symbol_name>
4
4
  ---
5
5
 
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Force a full code-graph index rebuild
2
+ description: Force code-graph index rebuild. Use when search results seem stale or wrong, after major codebase restructuring, or when index health check reports issues.
3
3
  ---
4
4
 
5
5
  Run via Bash: `code-graph-mcp incremental-index`
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Show code-graph index status
2
+ description: Show code-graph index health and coverage. Use when search returns unexpected results, checking if index is current, or diagnosing code-graph issues.
3
3
  ---
4
4
 
5
5
  !`code-graph-mcp health-check --format json 2>/dev/null || echo '{"error":"No index found"}'`
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Trace call flow from a handler or route
2
+ description: Trace call flow from a handler or route. Use when debugging API behavior, understanding request processing flow, or asked how an endpoint works.
3
3
  argument-hint: <handler_or_route>
4
4
  ---
5
5
 
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Deep dive into a module or file's architecture
2
+ description: Deep dive into a module's architecture. Use when starting work in an unfamiliar area, asked to explain how code works, or before implementing changes in a module.
3
3
  argument-hint: <file_or_dir_path>
4
4
  ---
5
5
 
@@ -47,6 +47,45 @@ for (const pat of fnPatterns) {
47
47
  }
48
48
  }
49
49
 
50
+ // Fallback: if old_string is inside a function body (not a definition),
51
+ // extract a unique identifier from the code and grep for it to find the containing function
52
+ if (!symbol || symbol.length < 3) {
53
+ const filePath = (input.tool_input && input.tool_input.file_path) || '';
54
+ if (filePath && oldStr.length >= 10) {
55
+ try {
56
+ // Extract identifiers from old_string, try the most specific one first
57
+ const identifiers = (oldStr.match(/\b([a-z]\w*(?:_\w+)+|[a-z]\w*(?:[A-Z]\w*)+|[A-Z]\w+\.\w+|[A-Z]\w+::\w+)\b/g) || [])
58
+ .filter(id => id.length >= 6);
59
+ const skipWords = new Set(['return', 'function', 'default', 'require', 'module', 'exports', 'import', 'console']);
60
+ // Sort by length descending (longer = more specific = fewer matches)
61
+ const candidates = [...new Set(identifiers)]
62
+ .filter(id => !skipWords.has(id.toLowerCase()))
63
+ .sort((a, b) => b.length - a.length);
64
+ for (const candidate of candidates.slice(0, 5)) {
65
+ try {
66
+ const raw = execFileSync('code-graph-mcp', ['grep', candidate, filePath, '--json'], {
67
+ cwd, timeout: 2000, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'],
68
+ });
69
+ const grepResult = JSON.parse(raw);
70
+ // Pick this candidate if it has few matches (precise location)
71
+ const withContainer = (grepResult || []).filter(m => m.container && m.container.name);
72
+ if (withContainer.length > 0 && withContainer.length <= 5) {
73
+ // If multiple containers, vote for the most common one
74
+ const votes = {};
75
+ for (const m of withContainer) {
76
+ const cn = m.container.name;
77
+ votes[cn] = (votes[cn] || 0) + 1;
78
+ }
79
+ const best = Object.entries(votes).sort((a, b) => b[1] - a[1])[0][0];
80
+ symbol = best.includes('.') ? best.split('.').pop() : best.includes('::') ? best.split('::').pop() : best;
81
+ break;
82
+ }
83
+ } catch { /* try next candidate */ }
84
+ }
85
+ } catch { /* grep failed or no match — fall through */ }
86
+ }
87
+ }
88
+
50
89
  if (!symbol || symbol.length < 3) process.exit(0);
51
90
 
52
91
  // Skip common patterns that aren't real function names
@@ -95,12 +95,20 @@ if (/^(修复|优化|实施|执行|开始|按|实测|帮我|进入|用|重新)/.
95
95
  const filePaths = (message.match(/(?:src|lib|test|pkg|cmd|internal|app|components?)\/[\w/.-]+/g) || [])
96
96
  .slice(0, 2);
97
97
 
98
- // Extract potential symbol names (camelCase, snake_case, PascalCase, qualified like Foo::bar)
99
- const symbolCandidates = (message.match(/\b(?:[A-Z]\w*(?:::\w+)+|[a-z]\w*(?:_\w+){1,}|[a-z]\w*(?:[A-Z]\w*)+|[A-Z][a-z]+(?:[A-Z][a-z]+)+)\b/g) || [])
98
+ // Extract potential symbol names (camelCase, snake_case, PascalCase, qualified like Foo::bar, Foo.bar, Foo::bar::baz)
99
+ const symbolCandidates = (message.match(/\b(?:[A-Z]\w*(?:(?:::|\.)\w+)+|[a-z]\w*(?:_\w+){1,}|[a-z]\w*(?:[A-Z]\w*)+|[A-Z][a-z]+(?:[A-Z][a-z]+)+)\b/g) || [])
100
100
  .filter(s => s.length > 4)
101
101
  .filter(s => !STOP_WORDS.has(s.toLowerCase()))
102
102
  .slice(0, 3);
103
103
 
104
+ // Fallback: extract backtick-quoted symbols (common in mixed Chinese+code: "修改 `parse_code` 函数")
105
+ if (symbolCandidates.length === 0) {
106
+ const backtickSymbols = (message.match(/`([a-zA-Z_]\w{2,})`/g) || [])
107
+ .map(s => s.replace(/`/g, ''))
108
+ .filter(s => s.length >= 3 && !STOP_WORDS.has(s.toLowerCase()));
109
+ symbolCandidates.push(...backtickSymbols.slice(0, 3));
110
+ }
111
+
104
112
  // Fallback: plain lowercase words (8+ chars) likely to be function/type names.
105
113
  // Only when strict patterns found nothing — avoids false positives from English prose.
106
114
  // Minimum 8 chars filters most common English words while keeping technical terms
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdsrs/code-graph",
3
- "version": "0.7.13",
3
+ "version": "0.7.14",
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": {
@@ -34,10 +34,10 @@
34
34
  "node": ">=16"
35
35
  },
36
36
  "optionalDependencies": {
37
- "@sdsrs/code-graph-linux-x64": "0.7.13",
38
- "@sdsrs/code-graph-linux-arm64": "0.7.13",
39
- "@sdsrs/code-graph-darwin-x64": "0.7.13",
40
- "@sdsrs/code-graph-darwin-arm64": "0.7.13",
41
- "@sdsrs/code-graph-win32-x64": "0.7.13"
37
+ "@sdsrs/code-graph-linux-x64": "0.7.14",
38
+ "@sdsrs/code-graph-linux-arm64": "0.7.14",
39
+ "@sdsrs/code-graph-darwin-x64": "0.7.14",
40
+ "@sdsrs/code-graph-darwin-arm64": "0.7.14",
41
+ "@sdsrs/code-graph-win32-x64": "0.7.14"
42
42
  }
43
43
  }