fix(file_read): skip hidden directories during os.walk traversal#440
Open
dosvk wants to merge 1 commit intostrands-agents:mainfrom
Open
fix(file_read): skip hidden directories during os.walk traversal#440dosvk wants to merge 1 commit intostrands-agents:mainfrom
dosvk wants to merge 1 commit intostrands-agents:mainfrom
Conversation
Filter directories starting with '.' in-place during os.walk to prevent descending into .venv, .git, .mypy_cache, etc. This matches the existing hidden file filter and prevents token explosion when file_read is called on directories containing large hidden trees. Closes strands-agents#405
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.
Description using their template:
Filter directories starting with '.' in-place during os.walk to
prevent descending into .venv, .git, .mypy_cache, etc. This matches
the existing hidden file filter and prevents token explosion when
file_read is called on directories containing large hidden trees.
Closes #405
Description
find_files()usesos.walk()and filters hidden files but not hiddendirectories. This causes traversal into
.venv,.git,.mypy_cache, etc.,collecting thousands of irrelevant files and exploding the context window.
The fix modifies
dirsin-place duringos.walk(the standard Pythonapproach for pruning traversal) to skip directories starting with
.,consistent with the existing hidden file filter on the same line.
Before: 13,769 files (97% from hidden dirs)
After: 1,257 files (hidden dirs skipped)
Related Issues
Closes #405
Type of Change
Bug fix
Testing
All 17 existing file_read tests pass
Verified manually: hidden directory files no longer returned
I ran
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.