|
|
b1b95a4560
|
feat(M7): implement headless mode with JSON and stream-JSON output formats
Milestone M7 implementation adds programmatic output formats for automation
and machine consumption.
New features:
- --output-format flag with three modes:
* text (default): Human-readable streaming output
* json: Single JSON object with session_id, messages, and stats
* stream-json: NDJSON format with event stream (session_start, chunk, session_end)
- Session tracking:
* Unique session ID generation (timestamp-based)
* Duration tracking (ms)
* Token count estimation (chars / 4 approximation)
- Output structures:
* SessionOutput: Complete session with messages and stats
* StreamEvent: Individual events for NDJSON streaming
* Stats: Token counts (total, prompt, completion) and duration
- Tool result formatting:
* All tool commands (Read, Write, Edit, Glob, Grep, Bash, SlashCommand)
support all three output formats
* JSON mode wraps results with session metadata
* Stream-JSON mode emits event sequences
- Chat streaming:
* Text mode: Real-time character streaming (unchanged behavior)
* JSON mode: Collects full response, outputs once with stats
* Stream-JSON mode: Emits chunk events as they arrive
Tests added (5 new tests):
1. print_json_has_session_id_and_stats - Verifies JSON output structure
2. stream_json_sequence_is_well_formed - Verifies NDJSON event sequence
3. text_format_is_default - Verifies default behavior unchanged
4. json_format_with_tool_execution - Verifies tool result formatting
5. stream_json_includes_chunk_events - Verifies streaming chunks
All 68 tests passing (up from 63).
This enables programmatic usage for automation, CI/CD, and integration
with other tools.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
2025-11-01 20:05:23 +01:00 |
|