Expand description
Claude Code stream-json envelope shapes + the pixie→Claude event mapper.
Each line of Claude’s stream-json output is a JSON object externally
tagged by type. Pixie (and other claude integrations) drive a turn by
reading NDJSON lines off stdout until a result line ends the turn. This
module maps pixie-pi’s AgentEvents onto those four envelope types:
| Claude line | Emitted from |
|---|---|
system | once at process start (system_init; not an event) |
assistant | AgentEvent::MessageEnd of an assistant message |
user | AgentEvent::MessageEnd of a tool-result message |
result | AgentEvent::AgentEnd (exactly one per turn) |
Structs§
- MapCtx
- Per-process / per-turn state the mapper accumulates as events flow through
map_events. The immutable fields (session_id,model, …) describe the run; the rest are updated in place so the finalresultline can report totals (usage, cost, turn count, duration, …).
Enums§
- Claude
Line - One NDJSON line of Claude’s
stream-jsonoutput.
Functions§
- map_
events - Map one pixie
AgentEventto zero or more ClaudeClaudeLines, advancingctxin place (accumulating usage, turn count, final text, …). - system_
init - Build the one-time
systeminit line (emitted at process start, before any event).toolsis the list of active tool names. - to_
ndjson - Serialize a
ClaudeLineto a single NDJSON line (no trailing newline).