Skip to content

Commit 5f73963

Browse files
sylvansysclaude
andcommitted
fix: Add multi-strategy JSON extraction for reviewer output
The requirements reviewer was failing to extract JSON when Claude didn't wrap the output in ```json blocks. This adds fallback strategies: 1. Try ```json block extraction (existing behavior) 2. Fallback: grep for raw JSON object with "checks" key 3. Fallback: perl range extraction for {"checks":[ pattern Fixes requirements reviewer showing "0 passed • 0 failed • 0 skipped" Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 69992ab commit 5f73963

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

.github/actions/code-quality-reviewer/action.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,19 @@ runs:
160160
if [ -f "$EXEC" ]; then
161161
# Get ALL text from assistant messages, joined together
162162
ALL_TEXT=$(jq -r '[.[] | select(.type=="assistant") | .message.content[]? | select(.type=="text") | .text] | join("\n")' "$EXEC" 2>/dev/null || echo "")
163-
# Extract JSON block from anywhere in the combined text
163+
# Strategy 1: Extract from ```json block
164164
JSON=$(echo "$ALL_TEXT" | sed -n '/```json/,/```/{/```/d;p;}' | head -100)
165+
166+
# Strategy 2: If no json block, try to find raw JSON object with "checks" key
167+
if ! echo "$JSON" | jq . >/dev/null 2>&1; then
168+
JSON=$(echo "$ALL_TEXT" | grep -oP '\{"checks":\s*\[.*\]\s*(,"message":[^}]*)?\}' | head -1)
169+
fi
170+
171+
# Strategy 3: Extract any JSON object starting with {"checks"
172+
if ! echo "$JSON" | jq . >/dev/null 2>&1; then
173+
JSON=$(echo "$ALL_TEXT" | perl -ne 'print if /\{"checks":\[/.../"message":/' | tr '\n' ' ')
174+
fi
175+
165176
if echo "$JSON" | jq . >/dev/null 2>&1; then
166177
# Count checks by status
167178
CHECKS_PASSED=$(echo "$JSON" | jq '[.checks[]? | select(.status == "passed")] | length')

.github/actions/requirements-reviewer/action.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,19 @@ runs:
194194
if [ -f "$EXEC" ]; then
195195
# Get ALL text from assistant messages, joined together
196196
ALL_TEXT=$(jq -r '[.[] | select(.type=="assistant") | .message.content[]? | select(.type=="text") | .text] | join("\n")' "$EXEC" 2>/dev/null || echo "")
197-
# Extract JSON block from anywhere in the combined text
197+
# Strategy 1: Extract from ```json block
198198
JSON=$(echo "$ALL_TEXT" | sed -n '/```json/,/```/{/```/d;p;}' | head -100)
199+
200+
# Strategy 2: If no json block, try to find raw JSON object with "checks" key
201+
if ! echo "$JSON" | jq . >/dev/null 2>&1; then
202+
JSON=$(echo "$ALL_TEXT" | grep -oP '\{"checks":\s*\[.*\]\s*(,"message":[^}]*)?\}' | head -1)
203+
fi
204+
205+
# Strategy 3: Extract any JSON object starting with {"checks"
206+
if ! echo "$JSON" | jq . >/dev/null 2>&1; then
207+
JSON=$(echo "$ALL_TEXT" | perl -ne 'print if /\{"checks":\[/.../"message":/' | tr '\n' ' ')
208+
fi
209+
199210
if echo "$JSON" | jq . >/dev/null 2>&1; then
200211
# Count checks by status
201212
CHECKS_PASSED=$(echo "$JSON" | jq '[.checks[]? | select(.status == "passed")] | length')

0 commit comments

Comments
 (0)