Skip to content

Conversation

@ibehnam
Copy link

@ibehnam ibehnam commented Dec 25, 2025

Problem

The list tool had a fundamental design issue that caused unpredictable and confusing behavior:

  1. Recursive scanning: Used ripgrep to recursively scan all files in a directory tree
  2. Arbitrary 100-file limit: Stopped after collecting 100 files from anywhere in the tree
  3. Unpredictable output: Only directories containing those first 100 files would appear in the output

Example of the bug:

In a directory with 41 subdirectories:

$ ls -d */ | wc -l
41

But the list tool would only show 2 directories:

/Users/user/Downloads/LLM/
  ooba/
  anti-llm-review/

The other 39 directories were invisible because ripgrep's first 100 files happened to all be in those 2 directories.

Solution

Changed the list tool to behave like a standard directory listing command (ls, os.listdir(), etc.):

  • No recursion: Only lists immediate children of the requested directory
  • No arbitrary limits: Shows all entries at the current level
  • Predictable: Always shows the same output for the same directory
  • Efficient: Uses fs.readdir() instead of recursive ripgrep scanning

Changes:

  • ✅ Removed ripgrep dependency for this tool
  • ✅ Removed 100-file limit
  • ✅ Switched to fs.readdir() with withFileTypes for direct, non-recursive listing
  • ✅ Maintained ignore pattern functionality
  • ✅ Enhanced metadata to show directory/file counts separately
  • ✅ Directories now consistently shown with trailing / for clarity

After the fix:

Same directory now correctly shows all 41 subdirectories plus files:

/Users/user/Downloads/LLM/
  __pycache__/
  agents/
  anti-llm-review/
  asky/
  AutoCisco/
  better_brew/
  BetterOllama/
  browser_use/
  ... (all 41 directories)
  ... (all files at this level)

Benefits

  1. Predictable: Tool now behaves like standard ls command
  2. Complete: Shows all immediate children without arbitrary limits
  3. Fast: No recursive scanning needed
  4. Clear separation of concerns:
    • list → show immediate children (like ls)
    • glob → find files by pattern (like find)
    • grep → search file contents

Testing

Tested with:

  • Directories with 40+ subdirectories ✅
  • Directories with hundreds of files ✅
  • Empty directories ✅
  • Directories with ignore patterns ✅

All cases now show complete, predictable output.

…listing

The list tool was using ripgrep to recursively scan directories and had a 100-file limit, causing unpredictable behavior where only some directories would appear in the output.

Changes:
- Removed recursive directory scanning (now lists immediate children only)
- Removed arbitrary 100-file limit
- Switched from ripgrep to fs.readdir for simple, direct directory listing
- Maintained ignore pattern functionality
- Added metadata showing count of directories vs files
- Directories now consistently shown with trailing slash

This makes the tool behave like standard 'ls' command - predictable and showing all immediate children of the requested directory.

Fixes the issue where directories with many files would show incomplete/random subdirectory listings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant