Skip to content

Conversation

@Eric-Guo
Copy link
Contributor

@Eric-Guo Eric-Guo commented Dec 4, 2025

Related Issue

Resolve #368

Description

ripgrep will handle .gitignore properly, so no need extra limit here.

Copilot AI review requested due to automatic review settings December 4, 2025 15:47
@Eric-Guo Eric-Guo force-pushed the loose_doulbe_star_patterns branch from 879d7d4 to c48ab7e Compare December 4, 2025 15:49
Copy link
Contributor

Copilot AI left a 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 .gitignore file presence before rejecting ** patterns
  • Updated error messages to explain why ** patterns are blocked (when no .gitignore exists)
  • 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 .gitignore in self._work_dir, but this happens before determining the actual search directory (dir_path). If a user specifies a subdirectory with its own .gitignore file, 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.

@Eric-Guo Eric-Guo force-pushed the loose_doulbe_star_patterns branch 4 times, most recently from d838e79 to c8f986f Compare December 4, 2025 16:06
@Eric-Guo Eric-Guo force-pushed the loose_doulbe_star_patterns branch 3 times, most recently from 3e2fa40 to 1c6b0da Compare December 7, 2025 14:27
@stdrc
Copy link
Collaborator

stdrc commented Dec 8, 2025

I really appreciate your effort and passion but the tool you changed is Glob, not Grep.🤣

@Eric-Guo
Copy link
Contributor Author

Eric-Guo commented Dec 8, 2025

Yeah, just realize the AI recognized async for match in dir_path.glob(params.pattern): in glob.py to rg.glob in grep_local.py, actually it should be kaos package, will continue dig the rabbit hole.

@Eric-Guo Eric-Guo force-pushed the loose_doulbe_star_patterns branch 10 times, most recently from 90cfa20 to d4285b2 Compare December 15, 2025 11:42
@Eric-Guo Eric-Guo force-pushed the loose_doulbe_star_patterns branch 4 times, most recently from 4cc9ac0 to f4a0a32 Compare December 27, 2025 02:50
@Eric-Guo
Copy link
Contributor Author

@stdrc Kindly take a look and feel free to implement your version.

Glade to know the kosong and pykao now part of the repo.

@Eric-Guo Eric-Guo changed the title feat: .gitignore file will handle ** pattern properly in ripgrep. feat: .gitignore file will handle ** pattern properly in Glob. Dec 27, 2025
@Eric-Guo Eric-Guo force-pushed the loose_doulbe_star_patterns branch from f4a0a32 to 1837c93 Compare December 27, 2025 14:17
…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.
@Eric-Guo Eric-Guo force-pushed the loose_doulbe_star_patterns branch from 1837c93 to a587f5d Compare December 30, 2025 09:36
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.

Remove limit: pattern **/file_name.rb starts with '**' which is not allowed

2 participants