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 claude;
59#[cfg(test)]
60mod claude_tests;
61pub mod codex;
62#[cfg(test)]
63mod codex_tests;
64pub mod deduplication;
65pub mod delta_display;
66mod event_queue;
67pub mod gemini;
68#[cfg(test)]
69mod gemini_tests;
70pub mod health;
71mod incremental_parser;
72pub mod opencode;
73#[cfg(test)]
74mod opencode_tests;
75pub mod printer;
76mod stream_classifier;
77pub mod streaming_state;
78pub mod terminal;
79pub mod types;
80
81pub use claude::ClaudeParser;
82pub use codex::CodexParser;
83pub use gemini::GeminiParser;
84pub use opencode::OpenCodeParser;
85pub use terminal::TerminalMode;
86
87#[cfg(test)]
88mod tests;