pub struct ClaudeParser { /* private fields */ }Expand description
Claude event parser
Note: This parser is designed for single-threaded use only.
The internal state uses Rc<RefCell<>> for convenience, not for thread safety.
Do not share this parser across threads.
Implementations§
Source§impl ClaudeParser
impl ClaudeParser
Sourcepub fn new(colors: Colors, verbosity: Verbosity) -> Self
pub fn new(colors: Colors, verbosity: Verbosity) -> Self
Create a new ClaudeParser with the given colors and verbosity.
§Arguments
colors- Colors for terminal outputverbosity- Verbosity level for output
§Returns
A new ClaudeParser instance
§Example
use ralph_workflow::json_parser::ClaudeParser;
use ralph_workflow::logger::Colors;
use ralph_workflow::config::Verbosity;
let parser = ClaudeParser::new(Colors::new(), Verbosity::Normal);Sourcepub fn with_printer(
colors: Colors,
verbosity: Verbosity,
printer: SharedPrinter,
) -> Self
pub fn with_printer( colors: Colors, verbosity: Verbosity, printer: SharedPrinter, ) -> Self
Sourcepub fn with_display_name(self, display_name: &str) -> Self
pub fn with_display_name(self, display_name: &str) -> Self
Sourcepub fn printer(&self) -> SharedPrinter
pub fn printer(&self) -> SharedPrinter
Get a shared reference to the printer.
This allows tests, monitoring, and other code to access the printer after parsing to verify output content, check for duplicates, or capture output for analysis.
§Returns
A clone of the shared printer reference (Rc<RefCell<dyn Printable>>)
§Example
use ralph_workflow::json_parser::{ClaudeParser, printer::TestPrinter};
use std::rc::Rc;
use std::cell::RefCell;
let printer = Rc::new(RefCell::new(TestPrinter::new()));
let parser = ClaudeParser::with_printer(colors, verbosity, Rc::clone(&printer));
// Parse events...
// Now access the printer to verify output
let printer_ref = parser.printer().borrow();
assert!(!printer_ref.has_duplicate_consecutive_lines());Sourcepub fn streaming_metrics(&self) -> StreamingQualityMetrics
pub fn streaming_metrics(&self) -> StreamingQualityMetrics
Get streaming quality metrics from the current session.
This provides insight into the deduplication and streaming quality of the parsing session, including:
- Number of snapshot repairs (when the agent sent accumulated content as a delta)
- Number of large deltas (potential protocol violations)
- Total deltas processed
Useful for testing, monitoring, and debugging streaming behavior.
§Returns
A copy of the streaming quality metrics from the internal StreamingSession.
§Example
use ralph_workflow::json_parser::{ClaudeParser, printer::TestPrinter};
use std::rc::Rc;
use std::cell::RefCell;
let printer = Rc::new(RefCell::new(TestPrinter::new()));
let parser = ClaudeParser::with_printer(colors, verbosity, Rc::clone(&printer));
// Parse events...
// Verify deduplication logic triggered
let metrics = parser.streaming_metrics();
assert!(metrics.snapshot_repairs_count > 0, "Snapshot repairs should occur");Sourcepub fn parse_event(&self, line: &str) -> Option<String>
pub fn parse_event(&self, line: &str) -> Option<String>
Parse and display a single Claude JSON event
Returns Some(formatted_output) for valid events, or None for:
- Malformed JSON (logged at debug level)
- Unknown event types
- Empty or whitespace-only output
Sourcepub fn parse_stream<R: BufRead>(&self, reader: R) -> Result<()>
pub fn parse_stream<R: BufRead>(&self, reader: R) -> Result<()>
Parse a stream of Claude NDJSON events
Auto Trait Implementations§
impl !Freeze for ClaudeParser
impl !RefUnwindSafe for ClaudeParser
impl !Send for ClaudeParser
impl !Sync for ClaudeParser
impl Unpin for ClaudeParser
impl !UnwindSafe for ClaudeParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more