From d8901efb46615483bded5a8d192c0ab2afa27361 Mon Sep 17 00:00:00 2001 From: phernandez Date: Fri, 29 May 2026 12:24:05 -0500 Subject: [PATCH] chore: make claude json parsing robust to both output shapes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up PR review claimed `claude --output-format json` emits a single object and the array form is stream-json only. Verified empirically against the installed CLI: `claude -p --output-format json` returns a JSON ARRAY of event objects (system, rate_limit_event, assistant, result), not a single object — so the reviewer's suggested fix would have broken parsing here. The portability concern is still valid (older CLIs emit a single object), so the parsing note now handles BOTH shapes: if array, take the type=='result' element; else use the object as-is; then read .result and strip the fence. Signed-off-by: phernandez --- .agents/skills/adversarial-review/SKILL.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.agents/skills/adversarial-review/SKILL.md b/.agents/skills/adversarial-review/SKILL.md index 9d91692f..e4b1be63 100644 --- a/.agents/skills/adversarial-review/SKILL.md +++ b/.agents/skills/adversarial-review/SKILL.md @@ -101,8 +101,11 @@ claude -p --permission-mode plan --output-format json \ Review the diff: $DIFF Return ONLY a JSON object matching this schema: $(cat "$SKILL_DIR/schemas/findings.schema.json")" "$RUN/other_raw.json" -# claude --output-format json emits a JSON ARRAY of events. Extract the element with -# type=='result', read its .result string, strip the ```json fence, and parse that. +# claude --output-format json output shape varies by CLI version: it may be a JSON ARRAY +# of event objects, OR a single result object. Normalize before reading: if it's an array, +# take the element with type=='result'; otherwise use the object as-is. Then read its +# .result string, strip the ```json fence if present, and parse that. +# (Verified empirically: the CLI in this environment emits the array form.) ``` > Runtime note for Codex orchestrating: `claude -p` needs network access, which Codex's