nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] search_file_contents returns 0 matches when ripgrep kills early on gitignored directory matches

Open akramcodez opened this issue 2 months ago • 2 comments

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

  1. Create a project containing a gitignored directory like dist/ or coverage/ with compiled output containing a common term (e.g. export function initialize).
  2. Have matching source files inside source/ that also contain export function initialize.
  3. Call search_file_contents with query "export function initialize" and maxResults: 20.
  4. 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 avatar Sep 16 '26 09:09 akramcodez

@akramcodez can you assign this issue to me

tusharui avatar Sep 16 '26 11:09 tusharui

sure @tusharui 👍

akramcodez avatar Sep 16 '26 15:09 akramcodez