extract_agent_events

Function extract_agent_events 

Source
fn extract_agent_events(
    line_buf: &mut Vec<u8>,
    chunk: &[u8],
    translator: &mut ClaudeTranslator,
) -> Vec<AgentEvent>
Expand description

Append chunk to line_buf, drain complete lines, JSON-parse each, and run successful parses through translator. Returns the events the translator emitted. Caller is responsible for publishing them.

Buffers RAW BYTES (not lossy-decoded strings) so a multi-byte UTF-8 character split across two PTY reads decodes cleanly when the complete line arrives. Decoding each chunk lossily would insert U+FFFD into the middle of words for non-ASCII content (CJK, emoji, accented chars), silently corrupting AssistantText/Done.response while the parallel raw-byte WPS path stays correct — drone consumers would have no way to recover. Reagent P1 + codex P2 on PR #833.

Pure function — split out from accumulate_and_translate so the line-buffering + JSON-fast-reject + translator-call logic is unit-testable without spinning up a broker.