Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.
TypeScript ai-agentsanthropicclaude-codeclicode-graphcodexcontext-engineeringcursordeveloper-toolsgeminiknowledge-graphllmmcpmcp-serveropen-sourceopenaitree-sitter
fix: strip mint-time ordinal suffixes when matching qualified symbol queries
Alex Matthews42d6f8129670
diff --git a/src/graph/traverse.ts b/src/graph/traverse.tsindex cfa339ab..6554a534 100644--- a/src/graph/traverse.ts+++ b/src/graph/traverse.ts@@ -85,6 +85,19 @@ export function resolveSymbol(graph: GraphV1, query: string, opts: ResolveSymbolreturn matches;}+/** Strips extract.ts's mint-time disambiguation ordinals (`~2`, `~3`, ...)+ * from segment ends in a dotted id-tail — the same shape extract.ts mints+ * when a document-order duplicate definition would otherwise collide with an+ * already-minted id (see extract.ts's mint-time uniqueness comment). Without+ * this, a qualified query like `C.m` only ever matches the bare id (`#C.m`),+ * silently hiding the `~2` duplicate from callers/ask/MCP lookups. The+ * ordinal can land on any segment, not just the tail (a reopened class shows+ * up as `C~2.m`), so this strips at every segment boundary (`.` or end of+ * string), not just the very end of the string. */+function stripOrdinals(idTail: string): string {+ return idTail.replace(/~\d+(?=\.|$)/g, "");+}+function symbolMatches(nodes: NodeV1[], lowerQuery: string): NodeV1[] {const suffixHash = "#" + lowerQuery;const suffixDot = "." + lowerQuery;@@ -92,7 +105,9 @@ function symbolMatches(nodes: NodeV1[], lowerQuery: string): NodeV1[] {if (n.kind === "file") return false;if (n.name.toLowerCase() === lowerQuery) return true;const lowerId = n.id.toLowerCase();- return lowerId.endsWith(suffixHash) || lowerId.endsWith(suffixDot);+ const hashIdx = lowerId.indexOf("#");+ const candidateId = hashIdx === -1 ? lowerId : lowerId.slice(0, hashIdx + 1) + stripOrdinals(lowerId.slice(hashIdx + 1));+ return candidateId.endsWith(suffixHash) || candidateId.endsWith(suffixDot);});}diff --git a/test/graph-traverse.test.ts b/test/graph-traverse.test.tsindex f4d17760..ebd6c11d 100644--- a/test/graph-traverse.test.ts+++ b/test/graph-traverse.test.ts@@ -156,6 +156,35 @@ test("resolveSymbol: unknown symbol returns empty array", () => {assert.deepEqual(resolveSymbol(g, "NoSuchSymbol"), []);});+test("resolveSymbol: qualified query matches both the bare and ordinal-suffixed ids of a duplicated definition (A3)", () => {+ // extract.ts mints `~2`, `~3`, ... on a document-order duplicate definition+ // (same name reopened) rather than shadowing the first — see extract.ts's+ // mint-time uniqueness comment. Before this fix, a qualified query like+ // "C.m" only ever matched the bare id (`#C.m`), silently hiding the `~2`+ // duplicate from callers/ask/MCP lookups.+ const dupFirst = nodeStub({ id: "src/dup.ts#C.m", name: "m", kind: "method", path: "src/dup.ts" });+ const dupSecond = nodeStub({ id: "src/dup.ts#C.m~2", name: "m", kind: "method", path: "src/dup.ts" });+ const g = graphOf([dupFirst, dupSecond], []);+ const matches = resolveSymbol(g, "C.m");+ assert.deepEqual(+ matches.map((n) => n.id).sort(),+ ["src/dup.ts#C.m", "src/dup.ts#C.m~2"].sort(),+ );+});++test("resolveSymbol: ordinal suffix stripped mid-path too, so a qualified query stays precise rather than falling back to an over-broad bare-name match", () => {+ // The ordinal can land on any segment, not only the tail — a class itself+ // reopened would put `~2` on the scope segment (`C~2.m`), not the method+ // name. Without stripping it there, the direct id-suffix check finds+ // nothing and resolveSymbol falls through to its last-segment bare-name+ // fallback, which would incorrectly sweep in every unrelated `m` method+ // (here, D.m) instead of precisely matching only the C-scoped one.+ const cScoped = nodeStub({ id: "src/dup.ts#C~2.m", name: "m", kind: "method", path: "src/dup.ts" });+ const dScoped = nodeStub({ id: "src/dup.ts#D.m", name: "m", kind: "method", path: "src/dup.ts" });+ const g = graphOf([cScoped, dScoped], []);+ assert.deepEqual(resolveSymbol(g, "C.m").map((n) => n.id), ["src/dup.ts#C~2.m"]);+});+// ── callersOf / calleesOf ────────────────────────────────────────────────test("calleesOf: walks outgoing walk-relation edges, keeping unresolved targets", () => {