[Bug] search_file_contents returns 0 matches when ripgrep kills early on gitignored directory matches
Description
When running search_file_contents, searches can return No matches found even when multiple matching files exist in the project. This happens because searchProjectContents runs ripgrep with --no-ignore-parent without passing project-level .gitignore rules directly to ripgrep. runRipgrep terminates the ripgrep process via child.kill() as soon as matchCount >= rgMaxCount. If the first matching files encountered during traversal are in directories ignored by .gitignore (such as dist/, build/, coverage/, or .next/), all returned matches are filtered out downstream by projectIgnore.ignores(). Because the ripgrep process was already killed, 0 matches are returned to the user or agent.
Environment
- OS: Linux / macOS / Windows
- Node version: v22.14.0
- Nanocoder version: 1.30.0
- Provider: Any
- Model: Any
Steps to Reproduce
- Create a project containing a gitignored directory like
dist/orcoverage/with compiled output containing a common term (e.g.export function initialize). - Have matching source files inside
source/that also containexport function initialize. - Call
search_file_contentswith query"export function initialize"andmaxResults: 20. - Observe that ripgrep traverses
dist/first, reaches 20 matches, and gets killed.
Expected Behavior
search_file_contents should return matches from unignored project source files (e.g. source/...).
Actual Behavior
Returns No matches found for "export function initialize" because ripgrep was killed prematurely upon finding matches in gitignored folders that were discarded downstream.
Logs/Screenshots
In source/utils/file-search.ts:
// runRipgrep kills process when matchCount reaches maxResults + contextLines
const {stdout} = await runRipgrep(args, cwd, timeoutMs, signal, rgMaxCount);
// Downstream filter discards gitignored files, but ripgrep is already dead:
const rgLines = parseRgJsonLines(stdout).filter(
line => !projectIgnore.ignores(toRelativeFile(cwd, line.file)),
);
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder
@akramcodez can you assign this issue to me
sure @tusharui 👍