Skip to content

fix: add Grep tool HTML rendering#101

Open
zhouxuan009 wants to merge 1 commit intodaaain:mainfrom
zhouxuan009:fix/grep-html-rendering
Open

fix: add Grep tool HTML rendering#101
zhouxuan009 wants to merge 1 commit intodaaain:mainfrom
zhouxuan009:fix/grep-html-rendering

Conversation

@zhouxuan009
Copy link

@zhouxuan009 zhouxuan009 commented Mar 12, 2026

Summary

  • Grep tool was missing title and input formatters, rendering as plain "Grep" with empty body
  • Added title_GrepInput showing 🔎 Grep <pattern> in header
  • Added format_GrepInput showing all fields (pattern, path, glob, type, mode, multiline) on separate lines

Test plan

  • Unit tests (694 passed)
  • Snapshot tests (5 passed)
  • Browser tests (29 passed, 1 skipped)

Summary by CodeRabbit

  • New Features
    • Added support for rendering Grep tool inputs with HTML formatting, enabling proper display of search patterns, file paths, and filtering options.

@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

This pull request adds support for rendering Grep tool inputs in HTML format. The change introduces a new formatter (format_grep_input) in the tool_formatters module, integrates it into the HtmlRenderer with corresponding dispatch methods, and exposes it through the public API.

Changes

Cohort / File(s) Summary
Grep Input Formatter
claude_code_log/html/tool_formatters.py
New format_grep_input function renders grep parameters (pattern, path, glob, type, mode, multiline) into HTML format; GrepInput imported from models and added to __all__.
Renderer Integration
claude_code_log/html/renderer.py
Integrated GrepInput support via two new methods: format_GrepInput (delegates to formatter) and title_GrepInput (generates title); follows existing tool input pattern.
Public API Export
claude_code_log/html/__init__.py
Re-exports format_grep_input in __all__ to expose the new formatter in the public API.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A grep tool arrives with pattern and flair,
Formatted to HTML with expert care,
Through renderer pipes it elegantly flows,
Following patterns that everyone knows,
The search is now visible, shiny, and new! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding HTML rendering support for the Grep tool, which is demonstrated across all three modified files in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

Copy link

@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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@claude_code_log/html/tool_formatters.py`:
- Around line 283-294: The current formatter in tool_formatters.py (inside
format_GrepInput / the Grep HTML rendering) only prints a hand-picked subset of
GrepInput fields and hides explicit False values; update the formatter to render
all actual GrepInput attributes (including head_limit, offset and any extra grep
flags defined on GrepInput in claude_code_log/models.py) by iterating the
model's fields (e.g., dataclasses.fields or vars(grep_input)/asdict(grep_input))
and emitting a row for each key/value where None is omitted but booleans are
rendered as true/false explicitly; ensure values are run through escape_html and
preserve the existing label/value HTML structure so the HTML accurately reflects
the real tool invocation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2efb6965-797c-43e7-a38a-84f777d3ea4b

📥 Commits

Reviewing files that changed from the base of the PR and between 5d1cf46 and b9a9675.

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

Comment on lines +283 to +294
html_parts = ["<div class='grep-tool-content'>"]
html_parts.append(f"<div class='grep-tool-field'><span class='grep-tool-label'>pattern:</span> <code>{escape_html(grep_input.pattern)}</code></div>")
if grep_input.path:
html_parts.append(f"<div class='grep-tool-field'><span class='grep-tool-label'>path:</span> <code>{escape_html(grep_input.path)}</code></div>")
if grep_input.glob:
html_parts.append(f"<div class='grep-tool-field'><span class='grep-tool-label'>glob:</span> <code>{escape_html(grep_input.glob)}</code></div>")
if grep_input.type:
html_parts.append(f"<div class='grep-tool-field'><span class='grep-tool-label'>type:</span> <code>{escape_html(grep_input.type)}</code></div>")
if grep_input.output_mode:
html_parts.append(f"<div class='grep-tool-field'><span class='grep-tool-label'>mode:</span> <code>{escape_html(grep_input.output_mode)}</code></div>")
if grep_input.multiline:
html_parts.append(f"<div class='grep-tool-field'><span class='grep-tool-label'>multiline:</span> <code>true</code></div>")
Copy link

@coderabbitai coderabbitai bot Mar 12, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Render the full GrepInput, not just this hand-picked subset.

GrepInput in claude_code_log/models.py (Lines 782-797) also carries head_limit, offset, and extra allowed grep flags, but this formatter drops all of them. Because HtmlRenderer.format_GrepInput() now routes Grep rendering here, those inputs disappear from the transcript entirely, and the if grep_input.multiline: check also hides an explicit False. Please derive the rendered rows from the actual provided fields so the HTML stays faithful to the tool invocation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@claude_code_log/html/tool_formatters.py` around lines 283 - 294, The current
formatter in tool_formatters.py (inside format_GrepInput / the Grep HTML
rendering) only prints a hand-picked subset of GrepInput fields and hides
explicit False values; update the formatter to render all actual GrepInput
attributes (including head_limit, offset and any extra grep flags defined on
GrepInput in claude_code_log/models.py) by iterating the model's fields (e.g.,
dataclasses.fields or vars(grep_input)/asdict(grep_input)) and emitting a row
for each key/value where None is omitted but booleans are rendered as true/false
explicitly; ensure values are run through escape_html and preserve the existing
label/value HTML structure so the HTML accurately reflects the real tool
invocation.

Copy link
Owner

@daaain daaain Mar 18, 2026

Choose a reason for hiding this comment

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

Hey @zhouxuan009, thanks a lot for this PR! Can you please check if this comment from Coderabbit is true? Also, please make sure that linting and tests pass.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for pointing it out. I will take a look.

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

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