mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
chore: make claude json parsing robust to both output shapes
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 <paul@basicmachines.co>
This commit is contained in:
committed by
Paul Hernandez
parent
c717d9997e
commit
d8901efb46
@@ -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")" </dev/null > "$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
|
||||
|
||||
Reference in New Issue
Block a user