Skip to content

Commit b986b78

Browse files
colbymchenryclaude
andcommitted
fix: Increase explore traversal depth and support qualified symbol lookups
Two fixes discovered while benchmarking Swift (Alamofire): 1. codegraph_explore traversalDepth 2→3: Deep call chains (e.g., Alamofire's 9-step Session.request()→URLSession flow) couldn't be followed in a single explore call, forcing agents to fall back to file reads. 2. findSymbol/findAllSymbols now support "Parent.child" notation (e.g., "Session.request") by matching against qualified names (::Parent::child). Previously only checked node.name === symbol, which never matched qualified queries since node names are unqualified. Also adds Alamofire Swift benchmark data to README (91% fewer tool calls, 78% faster with CodeGraph). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0d6f460 commit b986b78

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ We tested the same exploration queries across 4 real-world codebases in differen
4444
| **Excalidraw** | TypeScript | "How does collaborative editing and real-time sync work?" | 3 calls, 29s | 47 calls, 1m 45s | **94% fewer** | **72% faster** |
4545
| **Claude Code** | Python + Rust | "How does tool execution work end to end?" | 3 calls, 39s | 40 calls, 1m 8s | **93% fewer** | **43% faster** |
4646
| **Claude Code** | Java | "How does tool execution work end to end?" | 1 call, 19s | 26 calls, 1m 22s | **96% fewer** | **77% faster** |
47+
| **Alamofire** | Swift | "Trace how a request flows from Session.request() through to the URLSession layer" | 3 calls, 22s | 32 calls, 1m 39s | **91% fewer** | **78% faster** |
4748

4849
<details>
4950
<summary><strong>Full benchmark details</strong></summary>
@@ -57,6 +58,7 @@ All tests used Claude Opus 4.6 (1M context) with Claude Code v2.1.91. Each test
5758
| Excalidraw (TypeScript) | 626 | 9,859 | 3 | 57.1k | 29s | 0 |
5859
| Claude Code (Python+Rust) | 115 | 3,080 | 3 | 67.1k | 39s | 0 |
5960
| Claude Code (Java) ||| 1 | 40.8k | 19s | 0 |
61+
| Alamofire (Swift) | 102 | 2,624 | 3 | 57.3k | 22s | 0 |
6062

6163
**Without CodeGraph — the agent uses grep, find, ls, and Read extensively:**
6264
| Codebase | Tool Uses | Tokens | Time | File Reads |
@@ -65,12 +67,14 @@ All tests used Claude Opus 4.6 (1M context) with Claude Code v2.1.91. Each test
6567
| Excalidraw (TypeScript) | 47 | 77.9k | 1m 45s | ~20 |
6668
| Claude Code (Python+Rust) | 40 | 69.3k | 1m 8s | ~15 |
6769
| Claude Code (Java) | 26 | 73.3k | 1m 22s | ~15 |
70+
| Alamofire (Swift) | 32 | 52.4k | 1m 39s | ~10 |
6871

6972
**Key observations:**
7073
- With CodeGraph, the agent **never fell back to reading files** — it trusted the codegraph_explore results completely
7174
- Without CodeGraph, agents spent most of their time on discovery (find, ls, grep) before they could even start reading relevant code
7275
- The Java codebase needed only **1 codegraph_explore call** to answer the entire question
7376
- Cross-language queries (Python+Rust) worked seamlessly — CodeGraph's graph traversal found connections across language boundaries
77+
- The Swift benchmark (Alamofire) traced a **9-step call chain** from `Session.request()` to `URLSession.dataTask()` — CodeGraph's graph traversal at depth 3 captured the full chain in one explore call
7478

7579
</details>
7680

src/mcp/tools.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ export class ToolHandler {
622622
// Step 1: Find relevant context with generous parameters
623623
const subgraph = await cg.findRelevantContext(query, {
624624
searchLimit: 8,
625-
traversalDepth: 2,
625+
traversalDepth: 3,
626626
maxNodes: 80,
627627
minScore: 0.2,
628628
});
@@ -1113,15 +1113,38 @@ export class ToolHandler {
11131113
* Find a symbol by name, handling disambiguation when multiple matches exist.
11141114
* Returns the best match and a note about alternatives if any.
11151115
*/
1116+
/**
1117+
* Check if a node matches a symbol query, supporting both simple names and
1118+
* qualified "Parent.child" notation (e.g., "Session.request" matches a method
1119+
* named "request" inside a class named "Session").
1120+
*/
1121+
private matchesSymbol(node: Node, symbol: string): boolean {
1122+
// Simple name match
1123+
if (node.name === symbol) return true;
1124+
// File basename match (e.g., "product-card" matches "product-card.liquid")
1125+
if (node.kind === 'file' && node.name.replace(/\.[^.]+$/, '') === symbol) return true;
1126+
1127+
// Qualified name match: "Parent.child" → look for "::Parent::child" in qualified_name
1128+
if (symbol.includes('.')) {
1129+
const parts = symbol.split('.');
1130+
const qualifiedSuffix = parts.join('::');
1131+
if (node.qualifiedName.includes(qualifiedSuffix)) return true;
1132+
}
1133+
1134+
return false;
1135+
}
1136+
11161137
private findSymbol(cg: CodeGraph, symbol: string): { node: Node; note: string } | null {
1117-
const results = cg.searchNodes(symbol, { limit: 10 });
1138+
// Use higher limit for qualified lookups (e.g., "Session.request") since the
1139+
// target may rank lower in FTS when there are many partial matches
1140+
const limit = symbol.includes('.') ? 50 : 10;
1141+
const results = cg.searchNodes(symbol, { limit });
11181142

11191143
if (results.length === 0 || !results[0]) {
11201144
return null;
11211145
}
11221146

1123-
// If only one result, or first is an exact name match, use it directly
1124-
const exactMatches = results.filter(r => r.node.name === symbol);
1147+
const exactMatches = results.filter(r => this.matchesSymbol(r.node, symbol));
11251148

11261149
if (exactMatches.length === 1) {
11271150
return { node: exactMatches[0]!.node, note: '' };
@@ -1152,12 +1175,7 @@ export class ToolHandler {
11521175
return { nodes: [], note: '' };
11531176
}
11541177

1155-
// Match by exact name, OR by file basename without extension
1156-
// (e.g., "product-card" matches file node named "product-card.liquid")
1157-
const exactMatches = results.filter(r =>
1158-
r.node.name === symbol ||
1159-
(r.node.kind === 'file' && r.node.name.replace(/\.[^.]+$/, '') === symbol)
1160-
);
1178+
const exactMatches = results.filter(r => this.matchesSymbol(r.node, symbol));
11611179

11621180
if (exactMatches.length <= 1) {
11631181
const node = exactMatches[0]?.node ?? results[0]!.node;

0 commit comments

Comments
 (0)