Skip to main content

Module json_parser

Module json_parser 

Source
Expand description

JSON Stream Parsing Module

Functions for parsing NDJSON (newline-delimited JSON) streams from Claude, Codex, Gemini, and OpenCode CLI tools.

This module uses serde for JSON parsing, which is ~100x faster than spawning jq for each event.

§Module Structure

  • types - Shared types and event structures
  • [stream_classifier] - Algorithmic detection of partial vs complete events
  • claude - 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 degradation

§Streaming Support

All parsers now support delta streaming for real-time content display:

  • Claude: Full streaming with DeltaAccumulator for text and thinking deltas
  • Gemini: Streaming with delta flag support for message content
  • Codex: Streaming for agent_message and 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

Re-exports§

pub use claude::ClaudeParser;
pub use codex::CodexParser;
pub use gemini::GeminiParser;
pub use opencode::OpenCodeParser;

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
OpenCode event 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 JSON parsers.