Skip to main content

Module http_shell

Module http_shell 

Source
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§

SecretRuntime 🔒
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_shell re-exports it: server::websocket’s controllerinput handler also reads it.
META_KEY_PTYSHELL_BOOT_ID 🔒
Block meta on a PtyShell block: 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_update into block_id’s meta and broadcast a waveobj:update WS event so every subscribed frontend (the drawer, if open) picks it up immediately — the same two steps the setmeta WS handler performs (websocket.rs’s COMMAND_SET_META handler), factored out since ptyshell/* needs the identical pattern from a plain HTTP handler with no WshRpcEngine in 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. Err is 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 of try_attach_to_existing_shell for 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 (Vault rotate), 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_id is a real view:"term" sub-block PARENTED TO agent_block_id — the actual safety property Codex asked for (PR #3177): shell_id lives in the same block-id namespace as every other pane, and Layout exposes block ids for ordinary panes, so without this check an agent could point PtyShellInput/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 “did PtyShell create 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 one PtyShell created 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 (None runs it here), and for SSH the askpass secret its prompts are answered through.
own_pane 🔒
calling_pane for 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 with status.
refuse_foreign_shell 🔒
The refusal when shell_id is a shell another pane started; None for 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 env and 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-gh guard 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 🔒
WSLENV for a Shell command in a distro: the caller’s own variables and the reserved identity reserve_agent_env set, 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: resync id’s controller and reply, or return None if id doesn’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).