firecrawl / firecrawl/open-lovable
file-search: exact-term edit target mis-ranked due to case-sensitive confidence re-check
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 5.4k
- PR merge metrics
- No merged PRs in 30d
Description
## 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`)
```ts
// 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:
```jsx
sign up // the real edit target
// return to sign up page // unrelated comment
```
- `sign up` → `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 `sign up` line is correctly `high`.
I have a fix ready and will open a PR referencing this issue.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in lib/file-search-executor.ts at performSearch, especially lines 106-114, and reproduce the Sign Up example from the issue. Compare the case handling of the initial term match with the confidence re-check; done means the button line receives high confidence and sorts above the unrelated return comment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- search
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100