Repository navigation
feat(tools): give grep output modes, context lines, and case-insensitive search - #328
Open
raymondginger2018-sudo wants to merge 1 commit into
Open
raymondginger2018-sudo wants to merge 1 commit into
raymondginger2018-sudo wants to merge 1 commit into
Conversation
…ive search `GrepTool` returned one shape only — every matching line, 200 at most — so a caller that wanted the file list or per-file counts had to fetch and parse the lines. The tool now follows the grep contract the model already knows: `output_mode` (`content` / `files_with_matches` / `count`), `context` (with `context_before` / `context_after` overrides), `case_insensitive`, and `head_limit`. Both backends implement every mode. Ripgrep gets the native flags (`-i`, `--files-with-matches`, `--count`); the Python fallback implements the same three shapes, and the tests pin both so a machine without `rg` behaves the same as one with it. Context output is grouped per file, merged when spans overlap, and capped so a wide context cannot flood the result; protected paths are filtered in every mode exactly as before. The fallback's content shape now matches ripgrep's (`path:line:text`, no space after the second colon); the previous fallback-only space was an accidental divergence between the two backends. Tests: tests/test_grep_options.py (7 cases, both backends where rg exists); `tests/test_shell_search_tools.py -k grep` 6 passed / 6 skipped.
This branch has not been deployed
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
GrepToolrendered one shape only: every matching line, at most 200. A caller that wanted the file list or per-file counts had to fetch and parse the lines, and there was no way to ask for surrounding context or a case-insensitive match.It now follows the grep contract the model already knows:
output_mode—content(default),files_with_matches,countcontext— lines before/after each match, withcontext_before/context_afteroverridescase_insensitivehead_limit—0means the hard capChanges
core/harness/tools/search.py_Matchcarries path/line/text, so rendering is separate from searching.-i,--files-with-matches,--count; the Python fallback implements the same three shapes._MAX_CONTENT_LINES) so a wide context cannot flood the result.tests/test_grep_options.py(new) — each mode on both backends wherergexists.tests/contract/test_default_capability_compatibility.py— the shared tool contract now declares grep's new optional parameters.Compatibility
contentoutput is unchanged for ripgrep. The Python fallback now emitspath:line:textlike ripgrep (it used to insert a space after the second colon).output_mode=content, no context, case-sensitive, 200 matches.Tests
tests/test_grep_options.py7 passed;tests/test_shell_search_tools.py -k grep6 passed / 6 skipped (platform-specific).pre-commit run --files …clean.