nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] list_directory fails to ignore directories when .gitignore patterns contain a trailing slash

Open akramcodez opened this issue 2 months ago • 2 comments

Description

Standard .gitignore patterns frequently end with a trailing slash to designate directory-only matches (e.g. dist/, build/, .venv/, coverage/). When list_directory traverses items, it checks if (ig.ignores(relative(root, fullPath))) continue;. The ignore npm package strictly requires a trailing slash when evaluating paths against trailing-slash rules. Because list_directory passes directory paths without a trailing slash (e.g. 'dist'), ig.ignores('dist') evaluates to false. Consequently, list_directory fails to ignore these directories, enters them, and leaks all their contents into context.

Environment

  • OS: Linux / macOS / Windows
  • Node version: v22.14.0
  • Nanocoder version: 1.30.0
  • Provider: Any
  • Model: Any

Steps to Reproduce

  1. Add build/ or dist/ to .gitignore.
  2. Create directory dist/ containing multiple files (dist/bundle.js, dist/index.html).
  3. Call list_directory on . with recursive: true.
  4. Observe that dist/ and all its children are listed in the output.

Expected Behavior

Directories matching .gitignore patterns with trailing slashes should be ignored and excluded from directory listings.

Actual Behavior

dist/ is not ignored and all generated files inside it are printed, consuming large amounts of context window tokens.

Logs/Screenshots

Verification in Node REPL:

const ignore = require('ignore');
const ig = ignore().add('dist/');
console.log(ig.ignores('dist'));   // false (current nanocoder check)
console.log(ig.ignores('dist/'));  // true

In source/tools/list-directory.tsx:

const relativePath = relative(root, fullPath);
const matchPath = item.isDirectory() ? `${relativePath}/` : relativePath;
if (ig.ignores(matchPath)) continue;

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

Hi @akramcodez I'd like to pick this up if it's still open. Could you assign it to me?

The ignore package only matches directory-only patterns like dist/ when the path it checks ends with /. My plan is to add a trailing slash to directory paths before calling ig.ignores() in list_directory, and add tests for dist/, .venv/ and nested directories.

macjayz avatar Sep 17 '26 08:09 macjayz

Picking this up - a fix will follow shortly.

awhite0030 avatar Sep 20 '26 00:09 awhite0030