Skip to main content

Module frame

Module frame 

Source
Expand description

Two framings over a byte stream, sharing the JSON-RPC codec in the parent module (crate::rpc).

  • NDJSON (read_line / write_line): one JSON value per line, no embedded newlines. The MCP stdio transport framing.
  • Length-prefix (read_frame / write_frame): a 4-byte big-endian length followed by that many payload bytes. The private supervisor↔ subagent control channel — robust to payloads (instructions, context seeds, distilled results) that legitimately contain newlines.

Both are generic over Read/Write so they drop onto pipes, unix sockets, TLS streams, and vsock alike.

Constants§

MAX_FRAME
Hard cap on a single frame/line, for both framings. A peer claiming more is a protocol error, not an allocation. 16 MiB matches the MCP-side cap.

Functions§

read_frame
Read one length-prefixed frame. Returns Ok(None) on clean EOF before the length prefix (orderly shutdown). A declared length over MAX_FRAME is rejected before allocation.
read_line
Read one newline-delimited frame. Returns Ok(None) on clean EOF (the peer closed the stream between messages — an orderly shutdown signal). A line longer than MAX_FRAME is an error.
write_frame
Write a 4-byte big-endian length prefix followed by the JSON payload.
write_line
Serialize value as compact JSON plus a trailing \n. Errors if the encoded form contains a newline (it cannot for valid compact JSON, but we assert the invariant the transport relies on).