Skip to content

fix(tools): skip --exclude-dir when search path contains hidden directories - #18487

Closed
luyao618 wants to merge 1 commit into
NousResearch:mainfrom
luyao618:fix/search-content-hidden-dir-exclude
Closed

fix(tools): skip --exclude-dir when search path contains hidden directories#18487
luyao618 wants to merge 1 commit into
NousResearch:mainfrom
luyao618:fix/search-content-hidden-dir-exclude

Conversation

@luyao618

@luyao618 luyao618 commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

search_files with target='content' returns 0 results when the search path contains a hidden directory component (e.g. ~/.hermes/).

Root Cause

In tools/file_operations.py, _search_with_grep() unconditionally adds --exclude-dir='.*' to the grep command. GNU grep's --exclude-dir matches against every directory component in the full path, including the search root itself. When the search path contains a dot-prefixed directory like .hermes, grep excludes the entire tree and returns nothing.

This was previously fixed for target='files' in PR #16672, but _search_with_grep (used by target='content') was not updated.

Fix

Resolve the search path via os.path.realpath() and check if any component of the resolved path is a hidden directory. Only add --exclude-dir='.*' when the search root does not contain hidden components. When the user explicitly searches inside a hidden path, we skip the flag to avoid self-exclusion.

Changes

  • tools/file_operations.py: Add path component check before applying --exclude-dir in _search_with_grep()

Testing

  • All 202 existing search-related tests pass (4 skipped — SSH-only)
  • Manual verification: search_files(pattern='test', path='/tmp/.hidden_dir/', target='content') now returns correct results

Fixes #18473

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/file File tools (read, write, patch, search) labels May 1, 2026
…tories

search_files with target='content' returns 0 results when the search
path contains a hidden directory component (e.g. ~/.hermes/).

GNU grep's --exclude-dir='.*' matches against every directory component
in the full path, including the search root itself. When the search path
contains a dot-prefixed directory like .hermes, grep excludes the entire
tree and returns nothing.

Fix: resolve the search path and only add --exclude-dir='.*' when the
resolved path does not contain hidden directory components. When the
search root itself is inside a hidden directory, we skip the flag to
avoid self-exclusion — hidden subdirectories within the search tree
will still be traversed, which is acceptable since the user explicitly
requested searching inside a hidden path.

Fixes NousResearch#18473
@luyao618
luyao618 force-pushed the fix/search-content-hidden-dir-exclude branch from f39cdfb to 3a0b165 Compare May 5, 2026 10:40
@luyao618

Copy link
Copy Markdown
Contributor Author

Closing: this PR has been open for 1-2 weeks with no maintainer review and the codebase continues to evolve. Will re-submit if the fix is still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/file File tools (read, write, patch, search) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: search_files target='content' returns 0 results when search path contains hidden directories (e.g. ~/.hermes/)

2 participants