fix(tools): skip --exclude-dir when search path contains hidden directories - #18487
Closed
luyao618 wants to merge 1 commit into
Closed
fix(tools): skip --exclude-dir when search path contains hidden directories#18487luyao618 wants to merge 1 commit into
luyao618 wants to merge 1 commit into
Conversation
This was referenced May 2, 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
force-pushed
the
fix/search-content-hidden-dir-exclude
branch
from
May 5, 2026 10:40
f39cdfb to
3a0b165
Compare
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. |
This was referenced Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
search_fileswithtarget='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-dirmatches 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 bytarget='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-dirin_search_with_grep()Testing
search_files(pattern='test', path='/tmp/.hidden_dir/', target='content')now returns correct resultsFixes #18473