pub struct CodexStreamParser { /* private fields */ }Expand description
Stateful per-run wrapper over parse_codex_line that resolves codex’s
preamble-vs-answer ambiguity and drops its stderr noise. One per run.
Codex emits several complete agent_message items in a turn: short
preambles before tool calls (“I’ll read the file first”) and a final
answer. Nothing on the item distinguishes them — the only signal is
position: the last agent_message before turn.completed is the answer;
every earlier one is a preamble. So we hold the latest agent_message
and classify it by what follows — another item means it was a preamble
(→ RunEvent::Activity, transient narration), turn.completed (or
stream end) means it was the answer (→ RunEvent::Text). Without this
the preambles concatenate onto the answer in the bubble.
It also drops codex’s stderr: in --json mode codex writes only tracing
logs there (“Reading additional input…”, internal ERROR codex_core::…
lines) and reports real failures as stdout error items — so stderr is
pure noise, not status.
Implementations§
Source§impl CodexStreamParser
impl CodexStreamParser
pub fn new() -> Self
Sourcepub fn on_process_event(&mut self, event: ProcessEvent) -> Vec<RunEvent>
pub fn on_process_event(&mut self, event: ProcessEvent) -> Vec<RunEvent>
Normalize one raw process event, applying the agent_message state machine to stdout and dropping stderr noise.