@nhtio/adk/batteries/llm/claude_code_cli/wire
The normalized adapter↔wrapper protocol shared by every CLI-harness LLM battery.
Remarks
Zero imports by design: this module is the seam between adapter.ts (which runs in the ADK process and imports ADK barrels freely) and wrapper.ts (which runs as a separate spawned process and must import nothing from @nhtio/adk/*). Depending on either side would break the boundary, so this file depends on neither.
The wrapper↔adapter protocol itself is deliberately harness-agnostic — WrapperRunCommand / WrapperEvent name no Claude-Code-specific concept — so a future Codex-CLI or Pi-agent battery can reuse this exact module, writing only its own wrapper.
Interfaces
| Interface | Description |
|---|---|
| ClaudeCodeCliExtraArg | One entry in a --json-schema/--effort-style extraArgs escape hatch. |
| WrapperAuth | Explicit auth credential to forward to the grandchild's environment. Exactly one of the two fields is set. |
| WrapperBridgedTool | A bridged ADK tool's JSON-Schema-rendered description, as exposed to the CLI over MCP. |
| WrapperErrorEvent | A wrapper-level failure (spawn error, unexpected exit, MCP bridge startup failure). |
| WrapperInitEvent | Mirrors Claude's own system/init stream-json event. |
| WrapperLogEvent | A generic diagnostic passthrough, never fatal. |
| WrapperMessageDeltaEvent | A streamed chunk of assistant text or reasoning. |
| WrapperReadyEvent | The bridge's HTTP listener is bound and the wrapper is about to spawn claude. |
| WrapperResultEvent | The terminal event for a dispatch iteration. |
| WrapperRetryEvent | Mirrors Claude's own system/api_retry stream-json event. Observability only. |
| WrapperRunCommand | The one command adapter.ts sends per dispatch iteration, immediately after the wrapper's ready event arrives. Exactly one run command is accepted per wrapper process lifetime — the wrapper is spawned fresh per dispatch iteration, so there is no multi-run session. |
| WrapperShutdownCommand | Graceful-stop advisory sent to the wrapper (e.g. on ctx.abortSignal firing). |
| WrapperShutdownCompleteEvent | The wrapper's bridge HTTP listener and claude grandchild have both been torn down and the wrapper is about to exit. |
| WrapperThoughtDeltaEvent | A streamed chunk of reasoning/thinking text. |
| WrapperToolCallRequestEvent | A real ADK tool the wrapper's MCP bridge is asking the adapter to execute. |
| WrapperToolCallResponseCommand | The adapter's answer to a tool_call_request — a finished CallToolResult-shaped payload the wrapper hands straight to the CLI's MCP bridge with no further interpretation. |
Type Aliases
| Type Alias | Description |
|---|---|
| WrapperCommand | The full adapter→wrapper command union. |
| WrapperEvent | The full wrapper→adapter event union. |
| WrapperToolResultContentBlock | One MCP content block a tool-call response may carry. |
Functions
| Function | Description |
|---|---|
| createNdjsonLineReader | Create an incremental, byte-oriented NDJSON line reader. Generalizes local_diffusion/protocol.ts's createFrameReader discipline (bounded memory via a hard maxLineBytes cap enforced while consuming, fatal-UTF8-decode, malformed-line-is-non-fatal) for pure JSON-per-line framing with no tag-prefixed grammar. onLine receives each decoded line and returns the parsed value, or undefined for a line that failed to parse — the reader itself never throws and never classifies content, it only frames bytes into lines. |
| encodeWrapperCommand | Encode a WrapperCommand as one NDJSON line, including its terminating newline. |
| encodeWrapperEvent | Encode a WrapperEvent as one NDJSON line, including its terminating newline. |