Skip to content

fix: handle JSON object output without spurious jq warning (#242)#363

Open
sethdford wants to merge 94 commits intomainfrom
fix/misleading-jq-not-available-warning-when-242
Open

fix: handle JSON object output without spurious jq warning (#242)#363
sethdford wants to merge 94 commits intomainfrom
fix/misleading-jq-not-available-warning-when-242

Conversation

@sethdford
Copy link
Copy Markdown
Owner

@sethdford sethdford commented Apr 4, 2026

Summary

Fixes #242 — the _extract_text_from_json function in sw-loop.sh now handles both JSON arrays [...] and objects {...} from Claude's --output-format json output.

Changes

  • Extended JSON extraction to handle object format (not just arrays)
  • Fixed misleading "jq not available" warning — now correctly says "unexpected format"
  • Fixed cost dashboard context efficiency display when no cost entries exist
  • Fixed pipeline sandbox compatibility (TMPDIR-based mktemp)
  • Fixed loop test sandbox compatibility

Pipeline Proof

Test plan

  • npm test — all tests pass
  • bash scripts/sw-pipeline-test.sh — 58/58 pass
  • bash scripts/sw-e2e-smoke-test.sh — 19/19 pass
  • bash 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

    • Enhanced JSON parsing to correctly handle both array and object formats in output processing.
    • Improved loop convergence detection with refined stalled progress criteria.
  • Tests

    • Added test coverage for JSON parsing edge cases and token accumulation validation.
  • Chores

    • Updated internal caching and state tracking metadata.

Seth Ford and others added 30 commits March 10, 2026 10:14
…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>
Seth Ford and others added 28 commits March 10, 2026 20:50
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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 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: 46793556-4d7b-40b2-ac4c-064360197fb5

📥 Commits

Reviewing files that changed from the base of the PR and between 9222aa8 and 42bd0ca.

⛔ Files ignored due to path filters (90)
  • .claude/loop-logs/audit-iter-10.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-11.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-12.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-13.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-14.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-15.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-16.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-17.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-18.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-19.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-20.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-21.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-22.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-23.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-24.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-25.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-26.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-27.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-28.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-29.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-30.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-31.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-32.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-33.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-34.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-35.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-6.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-7.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-8.log is excluded by !**/*.log
  • .claude/loop-logs/audit-iter-9.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-10.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-11.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-12.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-13.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-14.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-15.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-16.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-17.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-18.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-19.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-20.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-21.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-22.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-23.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-24.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-25.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-26.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-27.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-28.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-29.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-30.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-31.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-32.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-33.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-34.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-35.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-6.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-7.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-8.log is excluded by !**/*.log
  • .claude/loop-logs/iteration-9.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-10.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-11.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-12.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-13.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-14.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-15.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-16.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-17.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-18.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-19.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-20.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-21.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-22.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-23.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-24.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-25.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-26.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-27.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-28.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-29.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-30.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-31.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-32.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-33.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-34.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-35.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-6.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-7.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-8.log is excluded by !**/*.log
  • .claude/loop-logs/tests-iter-9.log is excluded by !**/*.log
📒 Files selected for processing (5)
  • .claude/intelligence-cache.json
  • .claude/loop-state.md
  • scripts/lib/convergence.sh
  • scripts/sw-loop-test.sh
  • scripts/sw-loop.sh

📝 Walkthrough

Walkthrough

The 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 LOOP_COMPLETE signaled.

Changes

Cohort / File(s) Summary
JSON Output Format Support
scripts/sw-loop.sh, scripts/sw-loop-test.sh
Extended accumulate_loop_tokens() and _extract_text_from_json() to detect and handle both JSON arrays and objects via first-character inspection. Added Test 23 (object text extraction) and Test 24 (object token accumulation) validating correct parsing and absence of misleading "jq not available" warnings.
Convergence Logic Updates
scripts/lib/convergence.sh
Modified convergence_detect() to treat small score deltas (≤3) as stalled progress instead of only exact zeros. Added early-exit in convergence_integrate() when tests pass and LOOP_COMPLETE detected, returning converged status without computing score transitions.
State & Metadata
.claude/loop-state.md, .claude/intelligence-cache.json
Updated loop-state from ping-command task to jq-warning fix with expanded task tracking and implementation checklist. Updated intelligence-cache timestamp from 1772984911 to 1773215387.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 JSON arrays danced, but objects knocked,
Now both are parsed, no warnings mocked,
Convergence crept with smaller strides,
Early exits when completion guides,
The loop runs true, no jq deride! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix addressing issue #242: handling JSON object output without spurious jq warnings.
Description check ✅ Passed The PR description includes summary, changes, test plan with checkboxes, and pipeline proof; however, it is missing the Shipwright Standards Checklist required by the template.
Linked Issues check ✅ Passed The PR fully addresses issue #242 by extending JSON extraction to handle both arrays and objects, and correcting the misleading 'jq not available' warning as proposed in Option A.
Out of Scope Changes check ✅ Passed All code changes are in scope: JSON extraction fixes (#242), cost dashboard display, pipeline sandbox compatibility, and loop test updates directly support the primary objective.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/misleading-jq-not-available-warning-when-242
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch fix/misleading-jq-not-available-warning-when-242

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.

sethdford pushed a commit that referenced this pull request Apr 4, 2026
Autonomous pipeline E2E proof: Issue #242 → Spec → Build (3 sessions,
10 commits) → Test → Quality → PR #363

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Misleading "jq not available" warning when Claude outputs JSON object instead of array

1 participant