Add Grep tool renderer with pattern in title#107
Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded 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
Sequence Diagram(s)(Skipped) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 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
globpath; 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
📒 Files selected for processing (3)
claude_code_log/html/renderer.pyclaude_code_log/html/tool_formatters.pytest/test_grep_rendering.py
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
🔎 Grep <pattern>) instead of buried in the bodyrender_params_table()— empty body when pattern is the only parameterRationale
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 existingrender_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
test/test_grep_rendering.pyall passjust render-test-dataproduces correct output🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests