Expand description
Wire transport for wcode sessions — the socket behind the protocol.
The kernel defines the interface (wcode_harness::protocol::Frame of
Request/AgentEvent) and the in-process actor that speaks it. This
crate adds the transport:
- NDJSON framing (
read_frame/write_frame), - a
servefunction that re-exposes a sessionSessionHandleto remote clients over a Unix socket, - a
Clientthat mirrors the handle’ssend/ask/subscribeAPI, - a
Backendthat makes the local and remote paths interchangeable, - a
Registry— the in-process A2A bus (§8 #3, §10.1): an address book plus the permitted-set routing that scopes who may message whom.
The point (design: docs/interface-protocol-brainstorm.md, §8): a caller —
the REPL today, the TUI next, another session later — talks to a Backend
and never knows whether the session is in this process or across a socket.
Structs§
- Client
- A connection to a remote session, reconnecting automatically if it drops.
- Closed
- The session is gone — locally (the actor shut down) or remotely (the connection dropped).
- Define
Args - The arguments of a
wcode_harness::protocol::Request::Define, passed to aDefineHandler. Mirrors the CLI’s worker spec. - Registry
- An in-process address book and router over session mailboxes.
Enums§
- AskError
- Why a bounded
Backend::ask_withindid not get a reply.askkeeps returning the narrowerClosed, so its existing call sites don’t churn. - Backend
- A handle to a session, local or remote.
- Route
Error - Why a message could not be routed (§10.1 enforcement).
Constants§
- FLUSH_
TIMEOUT - Default bound for
Client::flushandflush_all: long enough to drain a healthy socket, short enough that an unreachable or reconnecting peer never stalls a one-shot exit.
Functions§
- bind
- Bind
path, creating its parent directory and clearing a stale socket. - connect
- Connect to a server listening at
path. - flush_
all - Best-effort flush of every live connection this process holds, so queued
fire-and-forget frames are written before a one-shot exit drops the runtime.
Each connection is bounded by
timeoutand they run concurrently, so the call returns within ~timeouteven if some peers are unreachable. The hot path (Client::send/Client::send_from) stays fire-and-forget. - read_
frame - Read one frame. Returns
Ok(None)on a clean EOF. Blank lines are skipped, so a frame boundary never depends on a caller flushing an empty line. - serve
- Bind
pathand serve the root session plusrosteruntil the listener errors. - serve_
at - Bind
path, thenserve. - serve_
stdio - Serve the frame loop over the process’s own stdin/stdout — the
--stdiotransport (docs/vscode-extension-plan.md§3.1). Exactly one client: there is no listener, so no second connection is even expressible. ReturnsOk(())when the client’s stdin reaches EOF (clean shutdown; the spawning client owns the process lifetime). - serve_
stream - Drive one connection over any byte stream: the frame loop (read → demux
→ actor), the per-session [
fan] tasks, the live roster push, and the request replies. Transport-free — the caller supplies the bytes. Returns when the peer’s stream reaches a clean EOF (read_frame→Ok(None)) or the reader/writer errors. - write_
frame - Write one frame as a single line and flush.
Type Aliases§
- Define
Handler - Builds a worker from
DefineArgsand returns its address. A socket server uses it to answerwcode_harness::protocol::Request::Define; the composition root injects one, since this crate cannot name a session factory. - Root
- A served session: the id every outbound frame carrying it is stamped with, and the handle the server reads events from / writes requests to.
- Roster
- The live roster of extra sessions served beside the root — a session is
(SessionId, SessionHandle). Empty means “root only”; the value is refreshed by acrate::Registryas sessions are registered.