fix: handle JSON object output without spurious jq warning (#242)#363
fix: handle JSON object output without spurious jq warning (#242)#363
Conversation
…op_tokens (#242) When Claude CLI outputs a JSON object instead of a JSON array, the code previously fell through to a misleading "jq not available" warning because it only checked for '[' as the first character. Now both functions check for '{' as well, routing objects through the appropriate jq expressions. Adds tests for JSON object extraction, content fallback, and token accumulation to prevent regression. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…e changes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…anges Co-Authored-By: Claude Opus 4.6 <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 ignored due to path filters (90)
📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe PR extends JSON output handling to support both arrays and objects (addressing misleading "jq not available" warnings), updates convergence detection to treat small score deltas as stalled conditions, and adds early-exit logic when tests pass with Changes
Sequence DiagramsequenceDiagram
participant Claude as Claude (Agent)
participant LoopScript as sw-loop.sh
participant JQ as jq Parser
participant TextOutput as Extracted Text
Claude->>LoopScript: Output JSON (array or object)
LoopScript->>LoopScript: Read first character
alt JSON Array [...]
LoopScript->>JQ: jq '.[-1].result'
JQ->>TextOutput: Extract from last element
else JSON Object {...}
LoopScript->>JQ: jq '.result'
JQ->>TextOutput: Extract from root level
else Fallback
LoopScript->>LoopScript: Copy raw output
LoopScript->>TextOutput: Raw JSON
end
TextOutput->>LoopScript: Return extracted text
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
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 |
Summary
Fixes #242 — the
_extract_text_from_jsonfunction insw-loop.shnow handles both JSON arrays[...]and objects{...}from Claude's--output-format jsonoutput.Changes
Pipeline Proof
Test plan
npm test— all tests passbash scripts/sw-pipeline-test.sh— 58/58 passbash scripts/sw-e2e-smoke-test.sh— 19/19 passbash scripts/sw-loop-test.sh— 65/65 pass🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com
Summary by CodeRabbit
Bug Fixes
Tests
Chores