Expand description
Terminal: one tool for the agent’s terminals, with an action
(docs/specs/SPEC_MUXAPI_TOOL_CONSOLIDATION_2026_10_15.md §4.2, slice S1;
docs/specs/SPEC_AGENT_TERMINAL_DRIVING_2026_10_15.md P1). It replaces
Shell*, PtyShell* and ConnList. Their handlers (shell.rs, pty_shell.rs)
still make the srv calls whose answer needs no structure; this file does
the rest: keys by name, Enter as CR on every platform, reads without ANSI
from a cursor, waits, and run’s exit code.
Structs§
Enums§
- Kind 🔒
- What a terminal id names: a PTY shell (the drawer) or a background job (a pipe).
- Shell
Family 🔒 - Until 🔒
Constants§
- ACTIONS 🔒
- CHUNK_
CHARS 🔒 - Per call to the PTY input endpoint: under cmd.exe’s console line limit (a 3,000-character line reads back as 511 there), with room for keys.
- CHUNK_
GAP 🔒 - DEFAULT_
TIMEOUT_ 🔒MS - MAX_
RUN_ 🔒LINES - MAX_
TIMEOUT_ 🔒MS - NEVER_
STARTED 🔒 - How long
runwithsecretswaits for srv to know the job before saying it may not have started. - POLL 🔒
- PROBE_
EXPR 🔒 - What the probe line asks each shell to expand.
- READ_
ALL_ 🔒LINES - Enough to cover a whole run’s output; the result is cut to
MAX_RUN_LINES.
Statics§
- CAPTURES 🔒
- Background jobs started with
capture:waitandreadsay what their capture came to once they end. - STATE 🔒
Functions§
- add_
capture_ 🔒outcome - A capture job’s outcome once it has ended: the entries it stored
(
captured) and why its output is withheld (withheld), added toout. Nothing for another job, or if srv can’t say. - after_
first_ 🔒line - after_
lines 🔒 textafter its firstnlines (all of it for 0, none if it has fewer).- at_
any_ 🔒prompt at_promptfor a known family, or any shell’s prompt when it isn’t known.- at_
prompt 🔒 - Whether the last non-empty line looks like the shell’s prompt: cmd’s
C:\path>, PowerShell’sPS C:\path>, or a Unix prompt ending in $ # % > ❯. - await_
prompt 🔒 - Waits briefly for the terminal to show a shell prompt, and refuses if it doesn’t: something else is running in it.
- call 🔒
- captures 🔒
- check_
run_ 🔒arguments - What a
runcan’t work with, found before it runs anything. - chunks 🔒
- Splits
sinto pieces of at mostmaxcharacters, on char boundaries. - classify_
probe 🔒 - The family the probe’s output (after the echo of the probe line) shows,
or
Nonewhile it hasn’t arrived. - clear_
line 🔒 - The key that clears a half-typed input line before
runtypes: Esc in cmd and PowerShell, Ctrl+U in a Unix shell (readline, zsh’s line editor, fish). - close 🔒
- exit_
marker 🔒 - Finds this run’s marker in output after the echo of the typed command: the command’s own output (between the echo and the marker) and its exit code.
- family_
of 🔒 - The terminal’s shell family: known for a local terminal, probed once for a remote one (WSL and SSH run the login shell there, which can be fish, cmd or PowerShell as well as a POSIX shell).
- gives_
secrets 🔒 - Whether
runtouches Vault values: gives the command some (secrets,stdin_secret,secret_files) or keeps what it prints (capture). - in_dir 🔒
commandrun incwd: the drawer is a long-lived shell, sorun’s cwd is acdin front of the command (cmd’s/dchanges the drive too). The path is quoted so the shell takes it literally (no variables, globs or command syntax), except a leading~, which still means home.- incomplete_
escape 🔒 - The length in bytes of an escape sequence at the end of
sthat hasn’t ended yet: anESC, a CSI (ESC [) without its final byte, or an OSC, DCS, APC or PM string without its terminator. A long one is let through: a string that never ends must not hold back everything after it. - key_
bytes 🔒 - The bytes a terminal expects for a named key. Enter is CR on every platform: Windows consoles (ConPTY) end a line only on CR, and a Unix tty maps CR to newline as it does for a Return key.
- key_
list 🔒 keysas the bytes each names. An unknown name is an error, never typed.- known 🔒
- local_
family 🔒 - The family of a local terminal, which srv starts itself (cmd.exe on
Windows,
$SHELLelsewhere);Nonefor a remote one, which is probed. - open 🔒
- open_
ending 🔒 - How
commandends if it doesn’t end a command: in the background (&), or waiting for more (a pipe,&&,||, a line continuation). The exit marker can’t follow such a line, sorunrefuses it instead of waiting out its timeout. - parse_
until 🔒 - probe_
family 🔒 - probe_
line 🔒 - One line every shell expands differently: cmd fills in
%COMSPEC%, fish$FISH_VERSION, PowerShell$PSVersionTable; a POSIX shell none of them. - read_
action 🔒 - read_
log 🔒 - remember 🔒
- resolve 🔒
- The
terminalan action names (shell_idis accepted too), else the agent’s drawer, opened if this process hasn’t opened it yet. - run_
action 🔒 - run_
background 🔒 runwithbackground: true: starts the job and returns at once.- run_
with_ 🔒secrets runwithsecrets, not in the background: starts the job (srv asks the person first), waits for it to end, and returns its output as srv cleaned it of the Vault values, with its exit code. A job that outlaststimeout_mskeeps running as a background job.- status 🔒
- strip_
ansi 🔒 - Terminal output as plain text: escape sequences (CSI, OSC, DCS, two-byte escapes) removed, a cursor move to another row read as a line break, CRLF as LF, a lone CR starting its line over (a progress bar reads as its last state), backspace applied, other control characters dropped.
- tail 🔒
- target 🔒
- The platform and shell a terminal runs on, so an agent that needs shell syntax reads it instead of guessing. Local: this machine; srv runs the Windows PTY shell as cmd.exe (http_pty_shell.rs).
- to_cr 🔒
- Typed text with every line break as CR, what a Return key sends: a lone LF doesn’t end a line in a Windows console.
- type_
action 🔒 - wait_
action 🔒 - wait_
for_ 🔒job - Waits for job
id, started byrun_with_secrets, and returns its output. - wait_on 🔒
- Blocks (polling srv) until the condition holds or the timeout passes.
echo_lines: the output starts with the echo of that many lines just typed, which a pattern must not match (typewithtext). - with_
exit_ 🔒marker - The command with an exit-code marker after it, in the shell’s own syntax,
tagged with this run’s
nonceso no earlier run’s marker is taken for it. cmd expands%ERRORLEVEL%when it reads the line, before the command runs, socallwith%^ERRORLEVEL%defers it; fish has$statusfor$?; PowerShell reports a native command’s code in$LASTEXITCODEand a cmdlet’s success in$?. The typed line itself never matchesexit_marker: it has%^ERRORLEVEL%,$?,$statusor a$(...)expression, not digits. - without_
trailing_ 🔒comment commandwithout a trailing comment, for the shells whose comments run from an unquoted#to the end of the line (a POSIX shell, fish, PowerShell): the exit marker goes after the command on the same line, and a comment would swallow it. Quotes and backslash escapes are respected.- without_
trailing_ 🔒semicolon commandwithout a trailing;(a POSIX shell, fish, PowerShell): the marker starts with its own;, and bash refuses;;outside acase. cmd has no;separator, so its command is unchanged.- write 🔒