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 + MPS event
- Input loop: input channel → process stdin
- Wait loop: monitor process exit, update status
§Module layout
This was one 2,394-line file; it is now a submodule directory (pure
reorganization, no logic changes). The impl Controller for ShellController
block is kept whole in lifecycle — a trait impl cannot be split across
files — and it calls the free-function helpers extracted into pty,
file_ops, indexing, and translation. The struct definitions,
constructor, and small accessor/meta helpers live in controller.
The pub use re-exports below preserve the pre-split flat paths
(shell::<item>) that callers elsewhere in the crate already import, so the
reorganization changed no call site.
Re-exports§
pub use controller::ShellController;pub use file_ops::handle_append_block_file;pub use indexing::extend_output_idx;pub use indexing::lines_before_byte;pub use indexing::output_index;pub use indexing::output_now;pub use indexing::read_via_index;pub use indexing::read_via_stale_index;
Modules§
- agent_
identity - A terminal-tier agent (a provider whose CLI runs in a term pane) starts
from its block’s own
cmd:env, written when the pane was opened. After a rename that snapshot names the old id, so the spawn takes the agent’s canonical identity over it, as every other agent spawn does (SPEC_FORK_SLUG_MIGRATION_2026_10_22.mdP0.3,spawn_env::identity), and realigns the workspace.mcp.json. - container_
pane - A container agent’s Shell drawer runs in its container, never on the host.
- controller
ShellControllerstruct + inner state definitions, constructor, and the small accessor / lock / meta helpers. TheControllertrait impl and the spawn/IO orchestration live insuper::lifecycle.- file_
ops - Block-file append helpers for terminal output. The agent transcript writes
live in
backend/transcript/append.rs. - indexing
output.idxrebuild: a lazily-built, self-validating line-offset cache.- lifecycle
- The
impl Controller for ShellControllerblock: start/stop/send_input/ get_runtime_status. Kept whole in one file (a trait impl cannot be split across modules); it orchestrates the helpers extracted into the siblingpty,file_ops, andtranslationmodules. - post_
spawn - What
startdoes once the shell’s PTY child exists: records it, registers the pane with jekt and seeds its working directory. - pty
- PTY geometry resolution and platform-specific shell detection.
- pty_
tasks - The two small tasks around a shell’s PTY: the blocking reader that turns its output into chunks for the flusher, and the input task that feeds it keystrokes, resizes and signals.
- spawn_
command - What a shell pane runs: the command (WSL, SSH, container, a program or the login shell) and the environment every one of them gets.
- spawn_
cwd - ssh_
pane - How a plain SSH pane ends (remote terminals spec §5.2; #4513).
- stamps
- Receive-time stamps for a range of transcript lines, from the
output.tsidxsidecar — without loading the sidecar whole. - start_
io - The steps of
startthat open and wire the PTY: marking the pane running with its input channel, opening the PTY, spawning the child, taking the reader and writer, and starting the output reader and flusher. - start_
steps - The steps
starttakes before it opens a PTY: refusing a connection AgentMux cannot run, the test-only mock connection, whether the pane closes when its process exits, the memory gate for a new agent, and what a WSL or SSH pane needs. - term_
cap - The size cap on what a terminal pane keeps of its output (the
termfile in the pane’s zone). A command that prints without end (yes) was stored whole: 2.5 GB and a 4.3 GB write-ahead log in 100 s. The file is now circular: it holds the lastterm:storedoutputmbmegabytes (50 by default, 0 for no limit), offsets stay absolute so readers that remember where they were keep working, and the parts below the window are deleted as the file grows (FileStore::trim_circular_head). Agent transcripts are a different file and are not touched. - translation
- Agent-event extraction and translation (Phase 1.5 PR 1). Feeds agent-pane
stdout through the Claude stream-json translator and publishes
AgentEvents. - wait_
task - The task that watches a shell’s PTY child: it reaps the child, lets the output flusher drain, hands the pane back (status, run lock, registrations) and, if the pane was set to close on exit, closes it.