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(ask): don't abstain to empty on verbose multi-scope queries
Shrish Dwivedi2257d51e1e43
diff --git a/src/ask/fuse.ts b/src/ask/fuse.tsindex 3b570c19..37ce8729 100644--- a/src/ask/fuse.ts+++ b/src/ask/fuse.ts@@ -222,34 +222,39 @@ export function rankScopesAndFuse(const alsoMatched: FusionResult["alsoMatched"] = [];const scoped: ScopedDoc[] = [];+ // 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 }>();for (const [scope, lex] of lexByScope) {- // Raw best (+ its doc id) for THIS scope, score desc / id asc — same- // tiebreak fuseScopes uses, so the reported bestId is deterministic.- let maxLex = 0;- let bestId = "";- for (const [id, v] of lex) {- if (v > maxLex || (v === maxLex && id < bestId)) {- maxLex = v;- bestId = id;- }- }- if (maxLex <= 0) continue; // no positive-scoring doc — contributes nothing-+ 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);- if (coverageStrong < STRONG_FLOOR && coverage < HIGH_FLOOR) {- alsoMatched.push({ scope, bestId });- continue; // excluded from fusion — no walk, no blend- }+ meta.set(scope, { lex, maxLex, bestId, passes: coverageStrong >= STRONG_FLOOR || coverage >= HIGH_FLOOR });+ }++ const survivors = [...meta.entries()].filter(([, m]) => m.passes).map(([s]) => s);+ // Anti-abstain rescue: the strength gate is a SHARE of the whole query, so a+ // long/verbose query (a pasted issue body) can push every scope below the+ // floor and make `ask` return nothing — measurably worse than grep. When the+ // gate would exclude every scope yet real matches exist, keep the single+ // strongest scope so `ask` returns best-effort hits (the escalation nudge+ // already tells the agent to switch to grep if they look weak) instead of+ // 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]);+ }+ for (const [scope, m] of meta) if (!survivors.includes(scope)) alsoMatched.push({ scope, bestId: m.bestId });- // Pass 2: only surviving scopes pay for the graph walk + blend.+ for (const scope of survivors) {+ const { lex, maxLex } = meta.get(scope)!;const pr = ops.walk(scope, lex);const candidates = new Set(lex.keys());for (const [id, p] of pr) if (p >= rescueFloor) candidates.add(id);for (const id of candidates) {const lexN = maxLex > 0 ? (lex.get(id) ?? 0) / maxLex : 0;- const blended =- (lexN + graphWeight * (pr.get(id) ?? 0)) *- (ops.rankFactor?.(scope, id) ?? 1);+ const blended = (lexN + graphWeight * (pr.get(id) ?? 0)) * (ops.rankFactor?.(scope, id) ?? 1);if (blended > 0) scoped.push({ id, scope, score: blended });}}