[Bug] list_directory fails to ignore directories when .gitignore patterns contain a trailing slash
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
- Add
build/ordist/to.gitignore. - Create directory
dist/containing multiple files (dist/bundle.js,dist/index.html). - Call
list_directoryon.withrecursive: true. - 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
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.
Picking this up - a fix will follow shortly.