Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

fix: review findings (ruby precision, rescue tiebreak, LSP in-repo check)

Shrish Dwivedib47be3575070
diff --git a/src/ask/fuse.ts b/src/ask/fuse.ts
index 37ce8729..3e627634 100644
--- a/src/ask/fuse.ts
+++ b/src/ask/fuse.ts
@@ -224,13 +224,15 @@ export function rankScopesAndFuse(
// Per-scope raw best + strength, computed once so we can pick survivors and,
// if the gate would exclude EVERY scope, rescue the strongest one (below).
- const meta = new Map<string, { lex: Map<string, number>; maxLex: number; bestId: string; passes: boolean }>();
+ const meta = new Map<string, { lex: Map<string, number>; maxLex: number; bestId: string; strength: number; passes: boolean }>();
for (const [scope, lex] of lexByScope) {
let maxLex = 0, bestId = "";
for (const [id, v] of lex) if (v > maxLex || (v === maxLex && id < bestId)) { maxLex = v; bestId = id; }
if (maxLex <= 0) continue;
const { coverage, coverageStrong } = ops.strength(scope, bestId);
- meta.set(scope, { lex, maxLex, bestId, passes: coverageStrong >= STRONG_FLOOR || coverage >= HIGH_FLOOR });
+ // strength is the scale-INVARIANT [0,1] match share (name vs name+path+body);
+ // used to pick the rescue scope fairly across corpora, unlike raw maxLex.
+ meta.set(scope, { lex, maxLex, bestId, strength: Math.max(coverage, coverageStrong), passes: coverageStrong >= STRONG_FLOOR || coverage >= HIGH_FLOOR });
}
const survivors = [...meta.entries()].filter(([, m]) => m.passes).map(([s]) => s);
@@ -243,7 +245,15 @@ export function rankScopesAndFuse(
// abstaining. The gate still does its real job — suppressing a weak scope
// beside a strong one — whenever any scope passes.
if (survivors.length === 0 && meta.size > 0) {
- survivors.push([...meta.entries()].sort((a, b) => b[1].maxLex - a[1].maxLex || a[0].localeCompare(b[0]))[0][0]);
+ // Tiebreak on scale-invariant match STRENGTH (not raw per-corpus maxLex,
+ // which would let the biggest scope's numerically-larger score win — the very
+ // cross-corpus scale bias RRF exists to avoid). Fall back to maxLex only when
+ // strength ties (e.g. all zero), then scope name for determinism.
+ survivors.push(
+ [...meta.entries()].sort(
+ (a, b) => b[1].strength - a[1].strength || b[1].maxLex - a[1].maxLex || a[0].localeCompare(b[0]),
+ )[0][0],
+ );
}
for (const [scope, m] of meta) if (!survivors.includes(scope)) alsoMatched.push({ scope, bestId: m.bestId });
diff --git a/src/graph/lsp/enrich.ts b/src/graph/lsp/enrich.ts
index d73e6002..a53a14e5 100644
--- a/src/graph/lsp/enrich.ts
+++ b/src/graph/lsp/enrich.ts
@@ -10,7 +10,7 @@
* a timeout / an error → the graph is returned unchanged.
*/
import { join } from "node:path";
-import { readFileSync } from "node:fs";
+import { readFileSync, realpathSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { relPosix } from "../../util/paths.js";
import { languageLabelOf } from "../extract.js";
@@ -42,6 +42,13 @@ export async function enrichWithLsp(
const server = pickServer(languagesPresent);
if (!server) return { added: 0, queried: 0, server: null };
+ // Canonicalize the root: servers (rust-analyzer/clangd) report callee URIs
+ // against the REAL path, so under a symlinked checkout (macOS /tmp →
+ // /private/tmp, common in CI) an un-resolved root would fail the in-repo test
+ // for every callee and silently zero out enrichment.
+ const realRoot = (() => { try { return realpathSync(root); } catch { return root; } })();
+ root = realRoot;
+
// Index nodes by file for both source selection and callee→node mapping.
const byId = new Map(graph.nodes.map((n) => [n.id, n]));
const spansByFile = new Map<string, Span[]>();
@@ -115,8 +122,10 @@ export async function enrichWithLsp(
for (const callee of callees) {
let calleeAbs: string;
try { calleeAbs = fileURLToPath(callee.uri); } catch { continue; }
- if (!calleeAbs.startsWith(root)) continue; // external/dependency — skip
const rel = relPosix(root, calleeAbs);
+ // In-repo iff the repo-relative path doesn't escape the root. (A raw
+ // `startsWith(root)` is separator-unsafe: root=/a/foo matches /a/foo-bar.)
+ if (rel.startsWith("..") || rel.startsWith("/")) continue; // external/dependency
const target = nodeAt(rel, (callee.selectionRange?.start.line ?? callee.range.start.line) + 1);
if (!target || target.id === src.id) continue;
const key = `${src.id}\0calls\0${target.id}`;
diff --git a/src/graph/queries/ruby.scm b/src/graph/queries/ruby.scm
index 47ba1eb5..82a33f76 100644
--- a/src/graph/queries/ruby.scm
+++ b/src/graph/queries/ruby.scm
@@ -54,11 +54,12 @@
)
; Calls
+; NB: only explicit call nodes — the upstream tags.scm also tags bare
+; [(identifier)(constant)] as @reference.call gated by (#is-not? local), but that
+; predicate needs the paired @local.* captures (from locals.scm, which graft does
+; not load) to mean anything. Without them it's a no-op, so bare *variable reads*
+; that share a name with a same-file/unique method become bogus `calls` edges
+; (resolve.ts can't tell a var read from a zero-arg call). Dropped for precision —
+; consistent with every other breadth-tier query (all use explicit call nodes).
(call method: (identifier) @name) @reference.call
-
-(
- [(identifier) (constant)] @name @reference.call
- (#is-not? local)
- (#not-match? @name "^(lambda|load|require|require_relative|__FILE__|__LINE__)$")
-)
diff --git a/test/generic-extract.test.ts b/test/generic-extract.test.ts
index 39ccb7ef..82edb9f8 100644
--- a/test/generic-extract.test.ts
+++ b/test/generic-extract.test.ts
@@ -82,8 +82,11 @@ const SNIPPETS: Array<{ lang: string; file: string; src: string; defs: string[];
defs: ["class:A", "method:helper", "method:run"], call: ["run", "helper"],
},
{
+ // Explicit call (`self.draw`), not a parenless bareword: graft's ruby query
+ // captures only real call nodes — the upstream bareword @reference.call
+ // needs locals-tracking graft doesn't run, so it's dropped for precision.
lang: "ruby", file: "a.rb",
- src: `class Widget\n def render\n draw\n end\n def draw\n 1\n end\nend\n`,
+ src: `class Widget\n def render\n self.draw\n end\n def draw\n 1\n end\nend\n`,
defs: ["class:Widget", "method:draw", "method:render"], call: ["render", "draw"],
},
{