Skip to content

Add contree grep -- server-side ripgrep search over the session image - #14

Open
mosquito wants to merge 1 commit into
masterfrom
feature/grep-command
Open

Add contree grep -- server-side ripgrep search over the session image#14
mosquito wants to merge 1 commit into
masterfrom
feature/grep-command

Conversation

@mosquito

Copy link
Copy Markdown
Collaborator

Summary

  • Adds contree grep PATTERN [PATH], wrapping contree-client's new inspect_image_grep() (0.2.0 -- bumps the pinned dependency from >=0.1.3): a free, no-VM search over the session image's 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, documented in docs/commands/grep.md, manual.md, agent.md, and the coding-agent skill_body.md.
  • 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.

Test plan

  • uv run pytest -q -- 1914 passed, 5 skipped
  • Re-ran full suite under FORCE_COLOR=1 and PYTHON_COLORS=1 -- all pass
  • make check (ruff + mypy) clean
  • contree grep --help renders correctly; manual smoke-checked the Sphinx docs build

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 default PATH = session cwd (or / fallback), plus --glob, --max-count, --max-total, --case, and --raw.
  • Bumps contree-client dependency to >=0.2.0 and 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 thread contree_cli/cli/grep.py
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")
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.

2 participants