file-search: exact-term edit target mis-ranked due to case-sensitive confidence re-check

Author: thejesh23Created Jul 20, 2026Updated Jul 20, 2026

Summary

In the edit-intent file search, an exact search-term hit is meant to get high confidence so the best edit line sorts first. But the confidence re-check is case-sensitive while the original term match is case-insensitive, so on any casing difference the real target is left at medium — and an unrelated line that merely contains return/export/function gets promoted to high above it.

Location

lib/file-search-executor.ts:106-114 (performSearch)

typescript
// term is matched case-insensitively at line 78:
if (line.toLowerCase().includes(term.toLowerCase())) { ... matchedTerm = term; }

// ...but the confidence check at line 110 re-tests case-sensitively:
if (matchedTerm && line.includes(matchedTerm)) {
  confidence = 'high';
} else if (line.includes('function') || line.includes('export') || line.includes('return')) {
  confidence = 'high';
}

Root cause

matchedTerm was found with toLowerCase() on both sides, so a match can differ in case from the raw line. The line.includes(matchedTerm) re-check does not lowercase, so a casing mismatch skips the exact-match branch. The line then falls through to the return/export/function heuristic — which, for the actual target, is usually false, leaving it at medium, while an unrelated comment/line containing one of those keywords is promoted to high and sorts above the real target.

Reproduction

searchTerms: ["Sign Up"], file contains:

javascript
<button>sign up</button>            // the real edit target
// return to sign up page           // unrelated comment
  • <button>sign up</button>matchedTerm = "Sign Up", line.includes("Sign Up") is false (case mismatch) → stays medium.
  • // return to sign up page → contains return → promoted to high.

The comment sorts first, so selectTargetFile / the recommended action points the model at the comment instead of the button.

Suggested fix

Make the re-check case-insensitive, consistent with the original match at line 78:

diff
-if (matchedTerm && line.includes(matchedTerm)) {
+if (matchedTerm && line.toLowerCase().includes(matchedTerm.toLowerCase())) {
   confidence = 'high';

With the fix the <button>sign up</button> line is correctly high.

I have a fix ready and will open a PR referencing this issue.