Skip to main content

Module control_socket

Module control_socket 

Source
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§

ControlClient
The client half of the control transport: connects to the daemon’s control socket (resolved from a ControlId), sends one ControlRequest, and reads back its ControlResponse. A fresh connection per request keeps it simple and stateless.
ControlListener
A bound control listener wrapping a Unix-domain socket.
ControlToken
A shared secret that proves a control-channel caller is this same user.
WorldEventStream
A reader over a Subscribe connection, yielding WorldEvents the daemon pushes.

Enums§

ControlRequest
A control request over the wire. Agents are addressed by run id (the stable id), except Message, which targets an agent id.
ControlResponse
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_SECS is 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 --socket override into a ControlId (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 an Error response 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_SECS overrides it; 0 disables the deadline (for debugging a daemon that is legitimately slow). An unparseable value falls back to the default.

Type Aliases§

ClientStream
The client end of a control connection.
ControlId
Identifies a control socket: the filesystem path of the Unix-domain socket.
ServerStream
The server end of an accepted control connection.