Skip to content
3 min read · 543 words

@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

InterfaceDescription
ClaudeCodeCliExtraArgOne entry in a --json-schema/--effort-style extraArgs escape hatch.
WrapperAuthExplicit auth credential to forward to the grandchild's environment. Exactly one of the two fields is set.
WrapperBridgedToolA bridged ADK tool's JSON-Schema-rendered description, as exposed to the CLI over MCP.
WrapperErrorEventA wrapper-level failure (spawn error, unexpected exit, MCP bridge startup failure).
WrapperInitEventMirrors Claude's own system/init stream-json event.
WrapperLogEventA generic diagnostic passthrough, never fatal.
WrapperMessageDeltaEventA streamed chunk of assistant text or reasoning.
WrapperReadyEventThe bridge's HTTP listener is bound and the wrapper is about to spawn claude.
WrapperResultEventThe terminal event for a dispatch iteration.
WrapperRetryEventMirrors Claude's own system/api_retry stream-json event. Observability only.
WrapperRunCommandThe 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.
WrapperShutdownCommandGraceful-stop advisory sent to the wrapper (e.g. on ctx.abortSignal firing).
WrapperShutdownCompleteEventThe wrapper's bridge HTTP listener and claude grandchild have both been torn down and the wrapper is about to exit.
WrapperThoughtDeltaEventA streamed chunk of reasoning/thinking text.
WrapperToolCallRequestEventA real ADK tool the wrapper's MCP bridge is asking the adapter to execute.
WrapperToolCallResponseCommandThe 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 AliasDescription
WrapperCommandThe full adapter→wrapper command union.
WrapperEventThe full wrapper→adapter event union.
WrapperToolResultContentBlockOne MCP content block a tool-call response may carry.

Functions

FunctionDescription
createNdjsonLineReaderCreate 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.
encodeWrapperCommandEncode a WrapperCommand as one NDJSON line, including its terminating newline.
encodeWrapperEventEncode a WrapperEvent as one NDJSON line, including its terminating newline.