Skip to main content

Module shell

Module shell 

Source
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):

  1. PTY read loop: process stdout → FileStore + MPS event
  2. Input loop: input channel → process stdin
  3. 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.md P0.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
ShellController struct + inner state definitions, constructor, and the small accessor / lock / meta helpers. The Controller trait impl and the spawn/IO orchestration live in super::lifecycle.
file_ops
Block-file append helpers for terminal output. The agent transcript writes live in backend/transcript/append.rs.
indexing
output.idx rebuild: a lazily-built, self-validating line-offset cache.
lifecycle
The impl Controller for ShellController block: 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 sibling pty, file_ops, and translation modules.
post_spawn
What start does 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.tsidx sidecar — without loading the sidecar whole.
start_io
The steps of start that 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 start takes 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 term file 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 last term:storedoutputmb megabytes (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.