Expand description
Block controller: manages lifecycle of each block (terminal, command, web app). Port of Go’s pkg/blockcontroller/blockcontroller.go.
Architecture:
- Global controller registry maps block_id → Controller
- Each controller manages the lifecycle of one block
- ShellController handles “shell” and “cmd” block types
- Controllers dispatch I/O between the user and the process/service
Modules§
- acp
- AcpController: manages agent CLIs that speak the Agent Client Protocol (ACP).
- health
- Agent health/liveness monitoring.
- persistent
- PersistentSubprocessController: manages agent CLI as a long-running process with bidirectional NDJSON streaming via stdin/stdout.
- pidregistry
- Block PID registry: maps blockId → OS process ID for per-pane metrics collection. Used by the sysinfo loop to query per-process CPU/memory stats.
- process_
tree - Process tree traversal: BFS from a root PID to collect all descendant PIDs. Used by the sysinfo loop to aggregate CPU/memory across entire process trees.
- session_
recovery - Session recovery after unclean shutdown (Phase 4.2 — ultra-long-sessions).
- session_
stats - Session metadata tracking for agent panes (Phase 1.4 — ultra-long-sessions).
- shell
- ShellController: manages lifecycle of shell and command blocks. Port of Go’s pkg/blockcontroller/shellcontroller.go.
- subprocess
- SubprocessController: manages agent CLI as stateless per-turn subprocess invocations.
- watchdog
- Agent process watchdog: kills agent panes that exceed max-runtime or idle-output limits.
Structs§
- Block
Controller Runtime Status - Runtime status of a block controller, sent to the UI.
- Block
Input Union - Input sent to a block controller. Can be raw terminal data, a signal, or a resize event.
Constants§
- BLOCK_
CONTROLLER_ ACP - BLOCK_
CONTROLLER_ CMD - BLOCK_
CONTROLLER_ PERSISTENT - BLOCK_
CONTROLLER_ SHELL - BLOCK_
CONTROLLER_ SUBPROCESS - BLOCK_
CONTROLLER_ TSUNAMI - DEFAULT_
GRACEFUL_ KILL_ WAIT_ MS - Grace period before forceful kill in milliseconds.
- DEFAULT_
TIMEOUT_ MS - Default controller operation timeout in milliseconds.
- META_
KEY_ CMD - META_
KEY_ CMD_ ARGS - META_
KEY_ CMD_ CLEAR_ ON_ START - META_
KEY_ CMD_ CLOSE_ ON_ EXIT - META_
KEY_ CMD_ CLOSE_ ON_ EXIT_ DELAY - META_
KEY_ CMD_ CLOSE_ ON_ EXIT_ FORCE - META_
KEY_ CMD_ CWD - META_
KEY_ CMD_ ENV - META_
KEY_ CMD_ INIT_ SCRIPT - META_
KEY_ CMD_ INIT_ SCRIPT_ BASH - META_
KEY_ CMD_ INIT_ SCRIPT_ FISH - META_
KEY_ CMD_ INIT_ SCRIPT_ PWSH - META_
KEY_ CMD_ INIT_ SCRIPT_ ZSH - META_
KEY_ CMD_ JWT - META_
KEY_ CMD_ RUN_ ONCE - META_
KEY_ CMD_ RUN_ ON_ START - META_
KEY_ CMD_ SHELL - META_
KEY_ CONNECTION - META_
KEY_ CONTROLLER - META_
KEY_ TERM_ LOCAL_ SHELL_ OPTS - META_
KEY_ TERM_ LOCAL_ SHELL_ PATH - STATUS_
DONE - STATUS_
INIT - STATUS_
RUNNING
Statics§
- CONTROLLER_
REGISTRY 🔒 - Thread-safe global controller registry.
Maps block_id → Arc
.
Traits§
- Controller
- Trait for block controllers. Each block type has its own implementation.
Port of Go’s
blockcontroller.Controllerinterface.
Functions§
- delete_
controller - Unregister (delete) a controller by block ID, stopping it first. Removes from the registry before calling stop() so no new callers can reach it.
- get_
all_ controllers - Get all controllers (snapshot).
- get_
block_ controller_ status - Get the runtime status for a block’s controller. Returns None if no controller is registered.
- get_
controller - Get a controller by block ID.
- is_
false 🔒 - publish_
controller_ status - Publish a controller status event via WPS broker.
- register_
controller - Register a controller, stopping any previous one for the same block.
- resync_
controller - Resync a block’s controller — the main entry point for starting/restarting blocks.
Port of Go’s
ResyncController. - send_
input - Send input to a block’s controller.
- stop_
all_ controllers - Stop all running controllers gracefully.
- stop_
block_ controller - Stop a block’s controller gracefully.