Add contree grep -- server-side ripgrep search over the session image - #14
Open
mosquito wants to merge 1 commit into
Open
Add contree grep -- server-side ripgrep search over the session image#14mosquito wants to merge 1 commit into
mosquito wants to merge 1 commit into
Conversation
Wraps contree-client's new inspect_image_grep() (0.2.0, so the pinned dependency is bumped from >=0.1.3): a free, no-VM search over the image filesystem, alongside ls/cat. - Defaults PATH to the session cwd (pass / to search the whole image); --glob/--max-count/--max-total/--case forward directly to the API. - Default format prints classic `path:line:text` lines like ripgrep itself, colorized (path/line number/matched span) when stdout is a terminal. Structured formats (-o json/csv/table/...) get one row per match instead; --raw preserves submatches/patterns/truncated as JSON for jq pipelines. - Exits 1 on zero matches (POSIX grep semantics), logs a warning when the server truncated results. - Registered in arguments.py, wired into shell tab-completion, and documented in docs/commands/grep.md, manual.md, agent.md, and the coding-agent skill_body.md. Also makes the test suite deterministic regardless of the ambient FORCE_COLOR/NO_COLOR/PYTHON_COLORS environment: Python 3.13+'s own argparse coloring and contree_cli's Colors enum are two independent mechanisms, and some help text is rendered once at import time and cached, so conftest.py now pins the color env vars before any contree_cli import in addition to patching contree_cli.types.IS_A_TTY per test.
There was a problem hiding this comment.
Pull request overview
Adds a new contree grep subcommand to search file contents inside the current session image via the server-side /inspect/ ripgrep API (no instance/sandbox spawn), aligning it with existing read-only filesystem commands like ls and cat.
Changes:
- Introduces
contree grep PATTERN [PATH]with defaultPATH= session cwd (or/fallback), plus--glob,--max-count,--max-total,--case, and--raw. - Bumps
contree-clientdependency to>=0.2.0and updates lockfile accordingly. - Adds comprehensive tests and updates docs, manual/agent guidance, and shell completion arg-mapping/tab-completion wiring.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Updates the locked contree-client version to 0.2.0 artifacts. |
| pyproject.toml | Bumps pinned runtime dependency to contree-client>=0.2.0. |
| contree_cli/cli/grep.py | Implements the new grep command, default output, and --raw behavior. |
| contree_cli/arguments.py | Registers the grep subcommand and updates help text examples. |
| contree_cli/types.py | Adds standardized flag mappings for grep options. |
| contree_cli/shell/argmap.py | Enables shell path completion for grep’s path argument. |
| tests/test_grep.py | Adds unit tests covering argument forwarding, output modes, exit codes, and match highlighting. |
| tests/conftest.py | Adds grep fixtures and makes color behavior deterministic across environments before imports. |
| docs/commands/index.md | Adds grep to the command index. |
| docs/commands/grep.md | Documents usage, output formats, and behavior of the new command. |
| contree_cli/manual.md | Adds grep to the quickstart/manual command examples. |
| contree_cli/agent.md | Adds grep to the agent “inspect first” read-only command sequence. |
| contree_cli/skill_body.md | Updates agent skill guidance to include grep in read-only inspection workflows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+154
to
+161
| for match in data["matches"]: | ||
| line_text = match["line_text"].rstrip("\n") | ||
| path, line_number = match["path"], match["line_number"] | ||
| if STDOUT_IS_A_TTY: | ||
| line_text = highlight_match(line_text, match["submatches"]) | ||
| path = Colors.MAGENTA(path) | ||
| line_number = Colors.GREEN(str(line_number)) | ||
| sys.stdout.write(f"{path}:{line_number}:{line_text}\n") |
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
contree grep PATTERN [PATH], wrappingcontree-client's newinspect_image_grep()(0.2.0 -- bumps the pinned dependency from>=0.1.3): a free, no-VM search over the session image's filesystem, alongsidels/cat.PATHto the session cwd (pass/to search the whole image);--glob/--max-count/--max-total/--caseforward directly to the API.path:line:textlines like ripgrep itself, colorized (path/line number/matched span) when stdout is a terminal. Structured formats (-o json/csv/table/...) get one row per match instead;--rawpreservessubmatches/patterns/truncatedas JSON forjqpipelines.1on zero matches (POSIXgrepsemantics), logs a warning when the server truncated results.arguments.py, wired into shell tab-completion, documented indocs/commands/grep.md,manual.md,agent.md, and the coding-agentskill_body.md.FORCE_COLOR/NO_COLOR/PYTHON_COLORSenvironment: Python 3.13+'s ownargparsecoloring andcontree_cli'sColorsenum are two independent mechanisms, and some help text is rendered once at import time and cached, soconftest.pynow pins the color env vars before anycontree_cliimport in addition to patchingcontree_cli.types.IS_A_TTYper test.Test plan
uv run pytest -q-- 1914 passed, 5 skippedFORCE_COLOR=1andPYTHON_COLORS=1-- all passmake check(ruff + mypy) cleancontree grep --helprenders correctly; manual smoke-checked the Sphinx docs build