-
Notifications
You must be signed in to change notification settings - Fork 382
feat: .gitignore file will handle ** pattern properly in Glob. #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
879d7d4 to
c48ab7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR modifies the glob tool to allow recursive ** patterns when a .gitignore file exists in the search directory. The assumption is that .gitignore will constrain the search to prevent performance issues from scanning large directories like node_modules.
Key Changes:
- Modified pattern validation to check for
.gitignorefile presence before rejecting**patterns - Updated error messages to explain why
**patterns are blocked (when no.gitignoreexists) - Added test coverage for the new behavior allowing
**patterns with.gitignore
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/kimi_cli/tools/file/glob.py | Added .gitignore check in _validate_pattern to allow ** patterns when .gitignore exists; updated parameter signature and error messages |
| tests/test_glob.py | Added new test case verifying that ** patterns are allowed when .gitignore file is present |
Comments suppressed due to low confidence (2)
src/kimi_cli/tools/file/glob.py:90
- The pattern validation is checking for
.gitignoreinself._work_dir, but this happens before determining the actual search directory (dir_path). If a user specifies a subdirectory with its own.gitignorefile, the validation won't find it because it's only looking in the work directory.
Consider this scenario:
- Work dir:
/project(no .gitignore) - Search dir:
/project/subdir(has .gitignore) - Pattern:
**/*.py
The current code will reject the pattern because it checks /project/.gitignore before determining that the actual search directory is /project/subdir.
The validation should check for .gitignore in the directory that will actually be searched. Move the pattern validation after determining dir_path, and pass dir_path instead of self._work_dir to _validate_pattern.
pattern_error = await self._validate_pattern(params.pattern, self._work_dir)
if pattern_error:
return pattern_error
dir_path = KaosPath(params.directory) if params.directory else self._work_dir
src/kimi_cli/tools/file/glob.py:61
- The error message says "the working directory does not contain a .gitignore" but this may be inaccurate if the user is searching a subdirectory. The message should refer to "the search directory" instead to be accurate in all cases.
Suggested change:
f"Pattern `{pattern}` starts with '**' which is not allowed because "
"the search directory does not contain a .gitignore to constrain the search. "Additionally, line 61 mentions "working directory" but should refer to "search directory" to match the actual directory being listed.
f"Pattern `{pattern}` starts with '**' which is not allowed because "
"the working directory does not contain a .gitignore to constrain the search. "
"This would recursively search all directories and may include large "
"directories like `node_modules`. Use more specific patterns instead. "
"For your convenience, a list of all files and directories in the "
"top level of the working directory is provided below."
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d838e79 to
c8f986f
Compare
3e2fa40 to
1c6b0da
Compare
|
I really appreciate your effort and passion but the tool you changed is Glob, not Grep.🤣 |
|
Yeah, just realize the AI recognized |
90cfa20 to
d4285b2
Compare
4cc9ac0 to
f4a0a32
Compare
|
@stdrc Kindly take a look and feel free to implement your version. Glade to know the kosong and pykao now part of the repo. |
f4a0a32 to
1837c93
Compare
…turn ToolError Unsafe pattern if can not finding the .gitignore file.
Implemented a method to load and apply .gitignore specifications during the glob search, allowing for exclusion of matches based on the patterns defined in the .gitignore file.
…ored directories are pruned during traversal instead of after the fact. Added helpers to normalize gitignore checks and filter matches consistently.
…tched the glob tool to call it, so the matching logic lives in packages/kaos rather than being inlined in Kimi CLI. This removes the local matching implementation while keeping the same behavior. Updated packages/kaos/src/kaos/__init__.py and src/kimi_cli/tools/file/glob.py.
1837c93 to
a587f5d
Compare
Related Issue
Resolve #368
Description
ripgrep will handle .gitignore properly, so no need extra limit here.