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 forOpenAICodex CLI NDJSON outputGeminiParser- Parser for Google Gemini CLI NDJSON outputOpenCodeParser- Parser forOpenCodeCLI 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-OpenAICodex CLI output parser (with streaming support)gemini- Google Gemini CLI output parser (with streaming support)opencode-OpenCodeCLI 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 terminal::TerminalMode;
Modules§
- boundary
- claude
- Claude CLI JSON parser.
This module provides the functional core implementation of the Claude parser.
The I/O boundary module at
io::claudere-exports from here. - 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.
- incremental_
parser - Incremental NDJSON parser for real-time streaming.
- opencode
OpenCodeevent parser implementation- printer
- Printer abstraction for testable output.
- stream_
classifier - Stream event classifier for algorithmic detection of partial vs complete events.
- terminal
- Terminal mode detection for streaming output.
- types
- Shared types and utilities for NDJSON stream parsers.