Skip to main content

ralph_workflow/json_parser/
mod.rs

1//! JSON Stream Parsing Module
2//!
3//! Functions for parsing NDJSON (newline-delimited JSON)
4//! streams from Claude, Codex, Gemini, and `OpenCode` CLI tools.
5//!
6//! NDJSON is a format where each line contains a complete JSON object.
7//! Agent CLIs emit NDJSON streams for real-time event processing.
8//!
9//! This module uses serde for JSON parsing, which is ~100x faster
10//! than spawning jq for each event.
11//!
12//! # Key Types
13//!
14//! - [`ClaudeParser`] - Parser for Claude CLI NDJSON output
15//! - [`CodexParser`] - Parser for `OpenAI` Codex CLI NDJSON output
16//! - [`GeminiParser`] - Parser for Google Gemini CLI NDJSON output
17//! - [`OpenCodeParser`] - Parser for `OpenCode` CLI NDJSON output
18//!
19//! Parser selection is controlled by [`crate::agents::JsonParserType`].
20//!
21//! # Module Structure
22//!
23//! - [`types`] - Shared types and event structures
24//! - [`claude`] - Claude CLI output parser (with streaming support)
25//! - [`codex`] - `OpenAI` Codex CLI output parser (with streaming support)
26//! - [`gemini`] - Google Gemini CLI output parser (with streaming support)
27//! - [`opencode`] - `OpenCode` CLI output parser (with streaming support)
28//! - [`health`] - Parser health monitoring and graceful degradation
29//! - [`printer`] - Test utilities for output verification (`test-utils` feature)
30//!
31//! # Streaming Support
32//!
33//! All parsers now support delta streaming for real-time content display:
34//! - **Claude**: Full streaming with `DeltaAccumulator` for text and thinking deltas
35//! - **Gemini**: Streaming with delta flag support for message content
36//! - **Codex**: Streaming for `agent_message` and reasoning item types
37//! - **`OpenCode`**: Streaming for text events
38//!
39//! In verbose mode, parsers show full accumulated content. In normal mode,
40//! they show real-time deltas for immediate feedback.
41//!
42//! ## Verbosity Levels
43//!
44//! The parsers respect the configured verbosity level:
45//! - **Quiet (0)**: Minimal output, aggressive truncation
46//! - **Normal (1)**: Balanced output with moderate truncation, shows real-time deltas
47//! - **Verbose (2)**: Default - shows more detail including tool inputs and full accumulated text
48//! - **Full (3)**: No truncation, show all content
49//! - **Debug (4)**: Maximum verbosity, includes raw JSON output
50//!
51//! # Internal Modules
52//!
53//! The `stream_classifier` module is internal and handles automatic detection
54//! of streaming vs. non-streaming output. It is not exposed in the public API.
55//!
56//! For detailed streaming contract documentation, see `README.md` in this directory.
57
58pub mod boundary;
59pub mod claude;
60#[cfg(test)]
61mod claude_io_tests;
62pub mod codex;
63#[cfg(test)]
64mod codex_tests;
65pub mod deduplication;
66pub mod delta_display;
67mod event_queue;
68pub mod gemini;
69#[cfg(test)]
70mod gemini_tests;
71pub mod health;
72pub mod incremental_parser;
73pub mod opencode;
74#[cfg(test)]
75mod opencode_tests;
76pub mod printer;
77pub mod stream_classifier;
78mod streaming_state;
79pub mod terminal;
80pub mod types;
81
82pub use terminal::TerminalMode;
83
84pub type ClaudeParser = claude::ClaudeParser;
85pub type CodexParser = codex::CodexParser;
86pub type GeminiParser = gemini::GeminiParser;
87pub type OpenCodeParser = opencode::OpenCodeParser;
88
89#[cfg(test)]
90mod tests;