fix(headless): complete debug diagnostics parity for json and stream-json

This commit is contained in:
Dmitry Lyalin
2026-02-25 10:23:16 -08:00
parent 8fb2f1e7f8
commit 96aa6004fb
8 changed files with 401 additions and 9 deletions
+21 -1
View File
@@ -17,8 +17,22 @@ You can specify the output format using the `--output-format` flag.
Returns a single JSON object containing the response and usage statistics.
- **Schema:**
- `session_id`: (string, optional) Session ID.
- `auth_method`: (string, optional) Authentication method. Emitted with
`--debug`.
- `user_tier`: (string, optional) User tier name. Emitted with `--debug`.
- `response`: (string) The model's final answer.
- `stats`: (object) Token usage and API latency metrics.
- `stats.api_requests`: (number, optional) Total API requests. Emitted with
`--debug`.
- `stats.api_errors`: (number, optional) Total API errors. Emitted with
`--debug`.
- `stats.retry_count`: (number, optional) Total retries. Emitted with
`--debug`.
- `stats.loop_detected`: (boolean, optional) Whether a loop was detected.
Emitted with `--debug`.
- `stats.loop_type`: (string, optional) Loop classification. Emitted with
`--debug`.
- `error`: (object, optional) Error details if the request failed.
#### Streaming JSON output
@@ -26,13 +40,19 @@ Returns a single JSON object containing the response and usage statistics.
Returns a stream of newline-delimited JSON (JSONL) events.
- **Event types:**
- `init`: Session metadata (session ID, model).
- `init`: Session metadata (session ID, model). Includes `auth_method` and
`user_tier` with `--debug`.
- `message`: User and assistant message chunks.
- `tool_use`: Tool call requests with arguments.
- `tool_result`: Output from executed tools.
- `error`: Non-fatal warnings and system errors.
- `retry`: Retry attempt diagnostics. Emitted with `--debug`.
- `loop_detected`: Loop detection diagnostics. Emitted with `--debug`.
- `result`: Final outcome with aggregated statistics.
In debug mode (`--debug`), `result.stats` also includes `api_requests`,
`api_errors`, and `retry_count`.
## Exit codes
The CLI returns standard exit codes to indicate the result of the headless