Expand description
ShellController: manages lifecycle of shell and command blocks. Port of Go’s pkg/blockcontroller/shellcontroller.go.
State machine: INIT ─(start)─> RUNNING ─(exit/stop)─> DONE DONE ─(resync+force)─> RUNNING
I/O model (3 async tasks when running):
- PTY read loop: process stdout → FileStore + WPS event
- Input loop: input channel → process stdin
- Wait loop: monitor process exit, update status
Structs§
- Shell
Controller - ShellController manages one shell or command block.
- Shell
Controller 🔒Inner
Constants§
- AGENT_
LINE_ 🔒BUFFER_ CAP - Append data to a block’s terminal output file, publish a WPS event, Maximum size of the per-block line buffer used by the agent-event translation path. Past this, the buffer is reset (a producer that never emits a newline can’t grow it unboundedly). 1 MiB is far beyond any plausible stream-json frame size.
- KILL_
GRACE_ 🔒SECS - Inner state protected by mutex. Grace period (seconds) between SIGTERM and SIGKILL during stop().
- OUTPUT_
IDX_ 🔒HEADER_ LEN - Magic header size for
output.idx: the first 8 bytes are theoutputbyte-size the index was built for. The index is valid iff this equalsoutput’s current size; otherwise it is stale and must be rebuilt. - PTY_
READ_ 🔒BUF_ SIZE - PTY read buffer size (matches Go’s 4096).
- SHELL_
INPUT_ 🔒CH_ SIZE - Cap on the out-of-order input reorder buffer (
input_seq_buf).
Functions§
- accumulate_
and_ 🔒translate - Publish the events
extract_agent_eventsproduced on the WPS scopeagent_event:<block_id>. Phase 1.5 PR 1 hook for agent panes. Called only whenis_agentis true at spawn time (see read-task closure instart()). - detect_
local_ 🔒shell_ path_ windows - Detect the best available interactive shell on Windows.
- extract_
agent_ 🔒events - Append
chunktoline_buf, drain complete lines, JSON-parse each, and run successful parses throughtranslator. Returns the events the translator emitted. Caller is responsible for publishing them. - handle_
append_ block_ file - Port of Go’s
HandleAppendBlockFile. - handle_
truncate_ block_ file - Truncate a block’s terminal output file and publish a WPS event.
Port of Go’s
HandleTruncateBlockFile. - mirror_
append_ 🔒to_ global - Append
datato the global transcript zone’soutputfile, creating it lazily on first write. Mirrors the per-channel write-through inhandle_append_block_file; all errors are logged and swallowed so the hot stdout path is never blocked by the global store. - persist_
to_ blockfile_ silent - and write-through to FileStore (if provided).
Persist
datato the block’s output file and the global transcript zone without publishing a WPS event. Used by the persistent controller to record user-message lines for future history loads (so thatparseHistoryLinescan reconstructuser_messagenodes on reopen) without triggering a live-stream append that would produce a duplicate node alongside theagent-message-acceptedUUID node. Same lazy-create semantics ashandle_append_block_file. - rebuild_
output_ 🔒idx - Rebuild
output.idxfromoutputin a single streaming scan and atomically replace it. The index is the byte offset of every non-blank line, matching the reader’s line addressing (String::lines().filter(!trim().is_empty())). - resolve_
global_ 🔒output_ zone - Resolve a block’s GLOBAL transcript zone (
agent:<defId>:current) from itsagentIdmeta, looking the block up inwstore. ReturnsNonefor non-agent blocks, when there’s no store, or when the block can’t be loaded — the caller then passesNoneand no global mirror happens. Shared by the subprocess / persistent / acp agent controllers.
Type Aliases§
- Conn
Factory - Factory function type for creating ConnInterface instances. This allows dependency injection for testing.