Skip to main content

Module claude

Module claude 

Source
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 lineEmitted from
systemonce at process start (system_init; not an event)
assistantAgentEvent::MessageEnd of an assistant message
userAgentEvent::MessageEnd of a tool-result message
resultAgentEvent::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 final result line can report totals (usage, cost, turn count, duration, …).

Enums§

ClaudeLine
One NDJSON line of Claude’s stream-json output.

Functions§

map_events
Map one pixie AgentEvent to zero or more Claude ClaudeLines, advancing ctx in place (accumulating usage, turn count, final text, …).
system_init
Build the one-time system init line (emitted at process start, before any event). tools is the list of active tool names.
to_ndjson
Serialize a ClaudeLine to a single NDJSON line (no trailing newline).