nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] list_directory and /explorer ignore .gitignore files in subdirectories

Open akramcodez opened this issue 1 week ago • 2 comments

Description

list_directory and the /explorer file tree only read the .gitignore at the project root (plus .nanocoderignore and the default ignores) through loadGitignore(root). A .gitignore inside a subdirectory is never read, so files that git ignores are listed to the model and shown in the explorer.

find_files and search_file_contents already handle this: the walker in source/utils/fs/file-search.ts reads each directory's .gitignore and prefixes its patterns. list_directory (source/tools/list-directory.tsx) and buildFileTree (source/utils/fs/file-tree.ts) do not, so the tools disagree about which files exist. This is common in monorepos, where each package has its own .gitignore for generated/, .turbo/, out/, and similar.

Environment

  • OS: macOS 27.2
  • Node version: v22.23.4
  • Nanocoder version: 1.32.0 (main at eb7dee57)
  • Provider: Not applicable
  • Model: Not applicable

Steps to Reproduce

  1. git init fx && cd fx && mkdir -p pkg/a/generated
  2. echo "generated/" > pkg/a/.gitignore && echo x > pkg/a/generated/big.js && echo y > pkg/a/index.ts
  3. git status --ignored shows pkg/a/generated/ as ignored.
  4. In nanocoder, have the model call list_directory with path: ".", recursive: true, or open /explorer.
  5. Have the model call find_files with **/*.js.

Expected Behavior

pkg/a/generated/big.js is hidden everywhere, as git and find_files treat it.

Actual Behavior

list_directory returns:

pkg/
pkg/a/
pkg/a/generated/
pkg/a/generated/big.js
pkg/a/index.ts

/explorer shows the same tree. find_files with **/*.js returns no matches.

Logs/Screenshots

Reproduced by calling buildFileTree and the list_directory tool directly against the fixture above on a build of main.

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

The nested-ignore logic in file-search.ts (prefixGitignoreLine and the per-directory read) could move into utils/fs/ and be shared by all three walkers.

akramcodez avatar Nov 23 '26 08:11 akramcodez

I'd like to take this one. Plan: move the per-directory .gitignore handling that file-search.ts already has (reading each directory's .gitignore and prefixing its patterns) into a shared helper under utils/fs/, and use it from list_directory and buildFileTree so all three walkers agree. Specs for a nested .gitignore in both, including a negation and a pattern anchored with a leading slash. PR coming shortly.

inahus99 avatar Nov 23 '26 10:11 inahus99

sure @inahus99 👍

akramcodez avatar Nov 23 '26 10:11 akramcodez