Expand description
The local control transport: newline-delimited JSON
ControlRequest/ControlResponse frames between clients (the TUI/CLI)
and the world host, over a platform-native local socket.
The wire protocol and its dispatch to the host are transport-agnostic and live here; the actual socket is provided per platform so each uses its native, access-controlled local IPC:
- Unix → a Unix-domain socket (a filesystem path, guarded by file perms).
- Windows → a named pipe (
\\.\pipe\…, guarded by its security descriptor).
Each platform module exposes the same small surface - ControlId,
control_id, bind_control_listener, ControlListener::accept,
connect, and is_daemon_running - over which the shared
handle_connection (generic over any AsyncRead + AsyncWrite) and
ControlClient operate. It is the default, always-on management channel
(the opt-in HTTP API that lev serve toggles is a separate surface).
Structs§
- Control
Client - The client half of the control transport: connects to the daemon’s control
socket (resolved from a
ControlId), sends oneControlRequest, and reads back itsControlResponse. A fresh connection per request keeps it simple and stateless. - Control
Listener - A bound control listener wrapping a Unix-domain socket.
- Control
Token - A shared secret that proves a control-channel caller is this same user.
- World
Event Stream - A reader over a
Subscribeconnection, yieldingWorldEvents the daemon pushes.
Enums§
- Control
Request - A control request over the wire. Agents are addressed by run id (the stable
id), except
Message, which targets an agent id. - Control
Response - A control response over the wire.
Constants§
- DEFAULT_
CONTROL_ TIMEOUT_ SECS - How long a control request waits for the daemon before giving up, when
LEVIATH_CONTROL_TIMEOUT_SECSis unset. - SPAWN_
CONTROL_ TIMEOUT_ SECS - Floor on the deadline for a
Spawn, which does more work than the other ops: the daemon connects the blueprint’s MCP servers before spawning, and each of those has its own 30s connect timeout, so a blueprint declaring several servers can legitimately outlast the ordinary deadline. Without this floor a slow-but-succeeding spawn would be reported to the user as a timeout.
Functions§
- bind_
control_ listener - Bind the daemon’s control socket at
id, enforcing a single instance. - connect
- Connect to the daemon’s control socket at
id. - control_
id - The control socket path under
base(e.g.<leviath-home>/.leviath). - control_
id_ from_ str - Parse a user-supplied
--socketoverride into aControlId(a path). - handle_
connection - Serve one accepted connection: read newline-delimited requests, dispatch each
to the host via
op_tx, and write back its response line. Returns when the client hangs up or on an I/O error. A malformed request line gets anErrorresponse and the connection continues. - is_
daemon_ running - True if a daemon is currently answering on the socket at
id. - request_
timeout - The deadline for one control request.
LEVIATH_CONTROL_TIMEOUT_SECSoverrides it;0disables the deadline (for debugging a daemon that is legitimately slow). An unparseable value falls back to the default.
Type Aliases§
- Client
Stream - The client end of a control connection.
- Control
Id - Identifies a control socket: the filesystem path of the Unix-domain socket.
- Server
Stream - The server end of an accepted control connection.