refactor(jsonl-parser): replace _parse_tool_result if/elif with dispa…#31
refactor(jsonl-parser): replace _parse_tool_result if/elif with dispa…#31clean6378-max-it wants to merge 3 commits intomasterfrom
Conversation
…tch table Implement _TOOL_RESULT_DISPATCH as an ordered sequence of (predicate, builder) pairs with explicit _tool_result_pred_* / _tool_result_build_* helpers so new tool-result shapes register in one place. Preserve legacy branch order and unknown fallback; no intentional behavior change.
|
ℹ️ 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)
📝 WalkthroughWalkthroughRefactors tool-result parsing in ChangesTool-Result Dispatch Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
utils/jsonl_parser.py (1)
556-556: ⚡ Quick winUse explicit optional typing for
slug.
slug: str = Noneis implicitly Optional; useslug: str | None = Noneinstead for PEP 484 compliance and type-checker consistency.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@utils/jsonl_parser.py` at line 556, Update the function signature of _parse_tool_result to use an explicit optional type for the slug parameter: change the parameter annotation from slug: str = None to slug: str | None = None so the signature reads def _parse_tool_result(tool_result, slug: str | None = None) -> dict | None; this ensures PEP 484/typing consistency and satisfies type checkers for optional values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@utils/jsonl_parser.py`:
- Around line 425-431: _guard the "results" value before calling len() in
_tool_result_build_web_search: fetch results with tr.get("results"), then
compute result_count only if that value is a sized container (e.g., has __len__
or is an instance of list/tuple/set/dict); otherwise set result_count to 0;
assign that count to result["result_count"] and leave the rest of the function
unchanged so parsing won't crash on None or other non-sized types.
---
Nitpick comments:
In `@utils/jsonl_parser.py`:
- Line 556: Update the function signature of _parse_tool_result to use an
explicit optional type for the slug parameter: change the parameter annotation
from slug: str = None to slug: str | None = None so the signature reads def
_parse_tool_result(tool_result, slug: str | None = None) -> dict | None; this
ensures PEP 484/typing consistency and satisfies type checkers for optional
values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Summary
This pull request refactors
utils/jsonl_parser.py::_parse_tool_resultby replacing the longif/elifchain with an ordered dispatch table,_TOOL_RESULT_DISPATCH, of(predicate, builder)pairs. The goal is to satisfy the structural half of CCC1 (single-site registration for new tool-result shapes) without changing parsing semantics.Changes
_TOOL_RESULT_DISPATCHand fifteen_tool_result_pred_*/_tool_result_build_*helper pairs mirroring the previous branch order (bash through plan)._parse_tool_resultas: reject non-dicts, iterate dispatch until the first matching predicate, otherwise setresult_typetounknownas before.(predicate, builder)pair and why order matters.Testing
pytest(full suite): 181 passed locally.References
claude-code-chat-browser— Refactor_parse_tool_resultdispatch table (5 pt) #29_parse_tool_resultandjsonl_parser.py)claude-code-browser-eval.md§5.1 / §5.4,claude-cursor.mdSummary by CodeRabbit
Refactor
Tests