Expand description
Shell drawer HTTP handlers and the agent shell lock. Split out of server/mod.rs unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md §4.1).
Structs§
- Secret
Runtime 🔒 - What the Vault secrets given to the command leave for its runner to hold.
Constants§
- AGENT_
LOCK_ 🔒WINDOW_ MS - META_
KEY_ 🔒AGENT_ LOCK_ UNTIL - The block meta key holding the lease’s expiry (ms since the epoch).
server::http_shellre-exports it:server::websocket’scontrollerinputhandler also reads it. - META_
KEY_ 🔒PTYSHELL_ BOOT_ ID - Block meta on a
PtyShellblock: the srv boot id of the run that created it. - META_
KEY_ 🔒SHELL_ SUBBLOCK_ ID - On an agent block: the block id of its shell drawer, the headless terminal the drawer, the agent’s PtyShell and a paired device’s pane list share.
Functions§
- apply_
injected 🔒 - Puts the injected Vault values into
env(after the caller’s, so the agent can’t name a value of its own over one) and their private files in a folder of their own, removed when the runner ends (or at the next start). - base_
env 🔒 - Env parity with the agent CLI: start from the agent block’s stored cmd:env (the per-agent env the agent process is launched with — same shape app_api/agent_io.rs / agent_handlers/input.rs read), then let the caller-supplied req.env override on top (explicit Shell env wins).
- broadcast_
meta_ 🔒update - Merge
meta_updateintoblock_id’s meta and broadcast awaveobj:updateWS event so every subscribed frontend (the drawer, if open) picks it up immediately — the same two steps thesetmetaWS handler performs (websocket.rs’sCOMMAND_SET_METAhandler), factored out sinceptyshell/*needs the identical pattern from a plain HTTP handler with noWshRpcEnginein scope. - calling_
pane 🔒 - The pane a shell call acts for: the caller’s own, from its token or, without one, its signed identity, never a
field of the request.
Erris the refusal to send. - clear_
shell_ 🔒pointer_ if - Clear the agent block’s shell pointer, if it still names
id(see the exited-shell branch oftry_attach_to_existing_shellfor why it is compare-before-clear), so the next create claims a fresh shell. - connection_
conflict 🔒 - 409 when the pane’s running shell is on another connection than
wanted. PtyShellStop releases the keyboard lock and leaves the shell running, so ending the shell is the way to switch. - create_
shell 🔒 - Starts a shell for
req.preapproved: the person approved its secrets with a rotation (Vaultrotate), which runs its commands through here. - drop_
exited_ 🔒shell - Treating an exited shell like a stale pointer (the caller returns
None) reuses the existing “create a fresh one” fallback in both callers instead of inventing a new response shape. - effective_
cwd 🔒 - Where the command starts. If cwd wasn’t supplied by the caller, fall back to the agent block’s cmd:cwd — the working directory the agent pane was launched with. Without this, ShellNodeRunner would inherit agentmux-srv’s cwd (typically the portable runtime/ dir) instead of the project dir.
- handle_
shell_ 🔒create POST /api/v1/shell/create— start a persistent background shell.- handle_
shell_ 🔒input POST /api/v1/shell/input— write text to a running shell’s stdin (Phase 3b).- handle_
shell_ 🔒output POST /api/v1/shell/output- the cleaned output of a job that was given Vault secrets, to the agent whose pane started it (spec section 7.1). Any other job has no kept output, and another agent’s pane is refused.- handle_
shell_ 🔒status POST /api/v1/shell/status— query a shell’s running state (Phase 3b).- handle_
shell_ 🔒stop POST /api/v1/shell/stop— stop a running persistent shell.- is_
owned_ 🔒by_ agent - Whether
shell_idis a realview:"term"sub-block PARENTED TOagent_block_id— the actual safety property Codex asked for (PR #3177):shell_idlives in the same block-id namespace as every other pane, andLayoutexposes block ids for ordinary panes, so without this check an agent could pointPtyShellInput/PtyShellStop/etc. at any controller-backed block (another agent’s own CLI pane, a human’s terminal pane) and inject input into it or tear it down. Framed as parentage rather than “didPtyShellcreate it” (the original, narrower check) specifically so it also covers the reuse case above: a shell the HUMAN created via the drawer is just as legitimate a target as onePtyShellcreated itself, as long as it’s this agent’s own pane. - launch_
for 🔒 - The program and arguments that run the command on the other side of a WSL or SSH
target(Noneruns it here), and for SSH the askpass secret its prompts are answered through. - own_
pane 🔒 calling_panefor a request that also names a pane: the proven pane, or the response that refuses the call (the caller could not be proven, or the request names another pane).- prepare_
secrets 🔒 - Asks for the Vault secrets a command is given and checks the values its output goes into the Vault as, together, so the whole asking fits the Terminal tool’s wait. The agent says why first (a rotation’s own commands carry the rotation’s): a missing reason is refused before anything is asked or run.
- refuse 🔒
- A JSON
{ "error": .. }reply withstatus. - refuse_
foreign_ 🔒shell - The refusal when
shell_idis a shell another pane started;Nonefor the caller’s own shell, and for an id no shell holds (there is nothing there to act on). - reserve_
agent_ 🔒env - The values a Shell command’s env takes from the server, applied after
the request’s
envand the injected secrets so neither can set them: the agent’s current identity over a persisted or requested one, as its own spawn has it (identity_env), the plain-ghguard the agent itself gets, and no account cloud login. - resolve_
target 🔒 - Where the command runs, and for an SSH host the agent that asked. Checked before anything is published, so a refused connection (no ssh, a distro that isn’t installed, a bad name) fails the call with its reason instead of running the command here.
- resync_
existing_ 🔒shell - settle_
connection_ 🔒conflict - Settled before the resync, which would otherwise start a shell on the block’s own connection: a running shell on another connection is refused and left as it is, and so is one this srv run created and is still starting (a concurrent create won the claim). One with no controller from an earlier run (before a srv restart) is replaced, like an exited one, rather than revived on the old connection. An exited one is replaced whatever its connection was.
- shell_
wslenv 🔒 WSLENVfor a Shell command in a distro: the caller’s own variables and the reserved identityreserve_agent_envset, so the command names the agent there as it would on Windows (wsl::AGENT_IDENTITY_ENV).- try_
attach_ 🔒to_ existing_ shell - Shared by both the top-level reuse check and the “lost the atomic
claim” fallback in
handle_pty_shell_create: resyncid’s controller and reply, or returnNoneifiddoesn’t resolve to a real block (stale pointer), OR if its shell has already exited, so the caller falls through to creating a fresh one. A pane has one agent shell: asking for it, while it runs, on another connection than its own is refused (409), not answered with the shell on the wrong machine. An exited one is replaced whatever its connection was.
Type Aliases§
- Prepared 🔒
- What a command’s Vault entries come to once checked and asked for: the values it is given, and what its output is stored as (with the labels of the entries nobody answered for).