Expand description
JSON Stream Parsing Module
Functions for parsing NDJSON (newline-delimited JSON) streams from Claude, Codex, Gemini, and OpenCode CLI tools.
NDJSON is a format where each line contains a complete JSON object. Agent CLIs emit NDJSON streams for real-time event processing.
This module uses serde for JSON parsing, which is ~100x faster than spawning jq for each event.
§Key Types
ClaudeParser- Parser for Claude CLI NDJSON outputCodexParser- Parser for OpenAI Codex CLI NDJSON outputGeminiParser- Parser for Google Gemini CLI NDJSON outputOpenCodeParser- Parser for OpenCode CLI NDJSON output
Parser selection is controlled by crate::agents::JsonParserType.
§Module Structure
types- Shared types and event structuresclaude- Claude CLI output parser (with streaming support)codex- OpenAI Codex CLI output parser (with streaming support)gemini- Google Gemini CLI output parser (with streaming support)opencode- OpenCode CLI output parser (with streaming support)health- Parser health monitoring and graceful degradationprinter- Test utilities for output verification (test-utilsfeature)
§Streaming Support
All parsers now support delta streaming for real-time content display:
- Claude: Full streaming with
DeltaAccumulatorfor text and thinking deltas - Gemini: Streaming with delta flag support for message content
- Codex: Streaming for
agent_messageand reasoning item types OpenCode: Streaming for text events
In verbose mode, parsers show full accumulated content. In normal mode, they show real-time deltas for immediate feedback.
§Verbosity Levels
The parsers respect the configured verbosity level:
- Quiet (0): Minimal output, aggressive truncation
- Normal (1): Balanced output with moderate truncation, shows real-time deltas
- Verbose (2): Default - shows more detail including tool inputs and full accumulated text
- Full (3): No truncation, show all content
- Debug (4): Maximum verbosity, includes raw JSON output
§Internal Modules
The stream_classifier module is internal and handles automatic detection
of streaming vs. non-streaming output. It is not exposed in the public API.
For detailed streaming contract documentation, see README.md in this directory.
Re-exports§
pub use claude::ClaudeParser;pub use codex::CodexParser;pub use gemini::GeminiParser;pub use opencode::OpenCodeParser;pub use terminal::TerminalMode;
Modules§
- claude
- Claude CLI JSON parser.
- codex
- Codex CLI JSON parser.
- deduplication
- Delta deduplication using KMP and Rolling Hash algorithms.
- delta_
display - Unified delta display system for streaming content.
- gemini
- Gemini CLI JSON parser.
- health
- Parser health monitoring and graceful degradation.
- opencode
OpenCodeevent parser implementation- printer
- Printer abstraction for testable output.
- streaming_
state - Unified streaming state tracking module.
- terminal
- Terminal mode detection for streaming output.
- types
- Shared types and utilities for NDJSON stream parsers.