Skip to main content

Module claude

Module claude 

Source
Expand description

Claude Code stream-json → AgentEvent translator.

Mirrors the frontend reference implementation at frontend/app/view/agent/providers/claude-translator.ts so the drone Agent block can consume the same stream without round-tripping through the renderer. Handled frames:

  • stream_event.content_block_start.content_block.type=text — starts a text block; subsequent text_deltas belong to it.
  • stream_event.content_block_start.content_block.type=tool_use — starts an in-flight tool_use; subsequent input_json_deltas accumulate; content_block_stop emits the finalized AgentEvent::ToolUse.
  • stream_event.content_block_delta.delta.type=text_delta — AgentEvent::AssistantText (also accumulated into the final response).
  • stream_event.content_block_delta.delta.type=input_json_delta — appends to the pending tool_use’s partial_json.
  • stream_event.content_block_stop — flushes the pending tool_use.
  • user.message.content[].type=tool_result — emits AgentEvent::ToolResult.
  • stream_event.message_start with message.role=user — same tool_result extraction as above (Anthropic sometimes carries tool results here instead of a top-level user frame; mirrors TS’s handleMessageStart).
  • result.cost_usd + result.usage — emits AgentEvent::Cost. Then, if result.is_error is true, emits AgentEvent::Error (mirrors TS’s error_result); otherwise emits AgentEvent::Done whose response is the explicit result.result field if present, otherwise the accumulated text from streamed text_deltas.
  • system.subtype=compact_boundary — emits AgentEvent::CompactionBoundary with the exact trigger/token/ duration data from compact_metadata (stdout, snake_case) or compactMetadata (transcript, camelCase). Other system subtypes are still discarded. See docs/specs/SPEC_COMPACTION_DETECTION_AND_HANDLING_2026_07_31.md §4.1 — this used to be silently dropped as an unhandled system frame.

Unknown frame types and malformed shapes produce an empty Vec rather than panicking — the runner falls back to whatever the parallel raw-byte MPS path published, so an unfamiliar frame degrades gracefully.

thinking_delta, message_delta / message_stop are discarded (the agent pane filters them too). rate_limit_event (TS: provider_waiting) is also currently discarded — surfacing it here would need a new AgentEvent variant, and types.rs explicitly reserves that decision rather than shipping it casually; left as a deliberate follow-up, not an oversight.

Structs§

ClaudeTranslator
PendingToolUse 🔒

Functions§

extract_tool_results 🔒
Shared by handle_user_message (top-level user frames) and the message_start case in handle_stream_event — both carry tool_result blocks in the same content array shape.
field 🔒
obj[snake], else obj[camel].
handle_assistant_message 🔒
handle_result 🔒
handle_stream_event 🔒
handle_system_message 🔒
type: "system" frames cover several subtypes; today we only act on compact_boundary (see docs/specs/SPEC_COMPACTION_DETECTION_AND_HANDLING_2026_07_31.md §4.1). Any other subtype — or a compact_boundary frame missing its metadata / carrying malformed fields — produces no event rather than a bad one, matching this file’s existing philosophy (see the module doc comment).
handle_user_message 🔒
parse_usage 🔒