Skip to content

Add Grep tool renderer with pattern in title#107

Merged
cboos merged 3 commits intomainfrom
fix/grep-tool-renderer
Apr 12, 2026
Merged

Add Grep tool renderer with pattern in title#107
cboos merged 3 commits intomainfrom
fix/grep-tool-renderer

Conversation

@cboos
Copy link
Copy Markdown
Collaborator

@cboos cboos commented Apr 11, 2026

Summary

  • Show search pattern in the tool title (🔎 Grep <pattern>) instead of buried in the body
  • Render remaining parameters (path, glob, type, output_mode, -A, -B, etc.) using the existing generic render_params_table() — empty body when pattern is the only parameter
  • Add 12 tests covering model creation, formatting, title rendering, HTML escaping, and markdown compatibility

Rationale

Alternative approach to #101, which identified a real issue (Grep shows no parameters and pattern isn't in the title). Rather than hand-coding each Grep field with custom CSS classes (grep-tool-content, grep-tool-field, grep-tool-label), this reuses the existing render_params_table() infrastructure — keeping it consistent with how other tools with many parameters are displayed, while still putting the pattern front and center in the title.

The key insight: GrepInput.model_dump(exclude={"pattern"}, exclude_none=True) gives us exactly the remaining params to pass to the generic table, with zero custom HTML needed.

Test plan

  • 12 new tests in test/test_grep_rendering.py all pass
  • Full unit test suite (706 passed, 0 failures)
  • just render-test-data produces correct output
  • Visual check of rendered Grep tool calls in HTML output

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added Grep tool rendering: titles show a search emoji plus the pattern (HTML/Markdown). Parameters render as a safe, escaped HTML table and deliberately exclude the raw pattern from the params body; unknown/additional parameters are shown.
  • Tests

    • Added tests for Grep input validation, parameter preservation, HTML escaping, and title/content rendering in both HTML and Markdown.

Show the search pattern in the tool title (🔎 Grep <pattern>) and render
remaining parameters (path, glob, type, output_mode, -A, -B, etc.) using
the existing generic params table. Returns empty body when pattern is the
only parameter.

Alternative approach to #101 — reuses render_params_table() instead of
hand-coding each field with custom CSS classes, keeping it consistent
with how other tools with many parameters are displayed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b1e17482-d0a1-49ba-9ccf-bf4f8ba99ad7

📥 Commits

Reviewing files that changed from the base of the PR and between 23d9623 and d7dae27.

📒 Files selected for processing (1)
  • test/test_grep_rendering.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/test_grep_rendering.py

📝 Walkthrough

Walkthrough

Added HTML formatting and title support for the GrepInput tool: a new HTML parameter formatter (omitting the pattern), HtmlRenderer methods to format GrepInput title/body, and tests covering model validation, HTML/Markdown rendering, escaping, and title output.

Changes

Cohort / File(s) Summary
Renderer Integration
claude_code_log/html/renderer.py
Added HtmlRenderer.format_GrepInput(...) and HtmlRenderer.title_GrepInput(...) to render GrepInput titles (emoji + pattern) and to delegate body rendering to the grep parameter formatter.
Formatter Implementation
claude_code_log/html/tool_formatters.py
Added format_grep_input(grep_input: GrepInput) -> str, registered in __all__ and the formatter dispatcher; renders grep parameters as an HTML parameters table while excluding the pattern field (returns "" when no other params).
Tests
test/test_grep_rendering.py
New tests validating GrepInput model behavior (defaults, extra params), HTML formatter output (parameter table presence/absence, escaping, inclusion of unknown fields), and title rendering in HTML/Markdown.

Sequence Diagram(s)

(Skipped)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniff the grep and find the trace,
Parameters tucked in a tidy place,
Titles wink with a searching eye,
Escaped and safe, no scripts go by,
Hops, tests, and tables — off I race! 🔎

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add Grep tool renderer with pattern in title' clearly and specifically summarizes the main change: implementing a Grep tool renderer that prominently displays the search pattern in the tool title.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/grep-tool-renderer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/test_grep_rendering.py (1)

124-140: Optional: add a markdown “no glob => empty body” assertion.

You already test the positive glob path; adding the empty-body case would lock down markdown symmetry.

Suggested test addition
 class TestGrepMarkdown:
@@
     def test_markdown_format_with_glob(self):
         inp = GrepInput(pattern="test", glob="*.py")
         msg = _make_grep_message(inp)
         renderer = MarkdownRenderer()
         body = renderer.format_GrepInput(inp, msg)
         assert "*.py" in body
+
+    def test_markdown_format_without_glob_returns_empty(self):
+        inp = GrepInput(pattern="test")
+        msg = _make_grep_message(inp)
+        renderer = MarkdownRenderer()
+        assert renderer.format_GrepInput(inp, msg) == ""
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/test_grep_rendering.py` around lines 124 - 140, Add a test that verifies
when GrepInput has no glob the Markdown body is empty: in
test/test_grep_rendering.py create a new test (e.g.,
test_markdown_format_without_glob) that builds inp = GrepInput(pattern="test")
(no glob), msg = _make_grep_message(inp), renderer = MarkdownRenderer(), then
call body = renderer.format_GrepInput(inp, msg) and assert that body == "" (or
otherwise assert it contains no glob info). This targets the
MarkdownRenderer.format_GrepInput behavior for GrepInput without a glob.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/test_grep_rendering.py`:
- Around line 124-140: Add a test that verifies when GrepInput has no glob the
Markdown body is empty: in test/test_grep_rendering.py create a new test (e.g.,
test_markdown_format_without_glob) that builds inp = GrepInput(pattern="test")
(no glob), msg = _make_grep_message(inp), renderer = MarkdownRenderer(), then
call body = renderer.format_GrepInput(inp, msg) and assert that body == "" (or
otherwise assert it contains no glob info). This targets the
MarkdownRenderer.format_GrepInput behavior for GrepInput without a glob.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1cad0d0c-2470-412e-8d0d-e33a9e72a5d6

📥 Commits

Reviewing files that changed from the base of the PR and between f38e228 and 201e4a7.

📒 Files selected for processing (3)
  • claude_code_log/html/renderer.py
  • claude_code_log/html/tool_formatters.py
  • test/test_grep_rendering.py

cboos and others added 2 commits April 11, 2026 16:30
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cboos cboos merged commit 2f8b1e4 into main Apr 12, 2026
11 checks passed
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.

1 participant