Skip to main content

Module terminal

Module terminal 

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

Known 🔒
Log 🔒
State 🔒

Enums§

Kind 🔒
What a terminal id names: a PTY shell (the drawer) or a background job (a pipe).
ShellFamily 🔒
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 run with secrets waits 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: wait and read say 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 to out. Nothing for another job, or if srv can’t say.
after_first_line 🔒
after_lines 🔒
text after its first n lines (all of it for 0, none if it has fewer).
at_any_prompt 🔒
at_prompt for 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’s PS 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 run can’t work with, found before it runs anything.
chunks 🔒
Splits s into pieces of at most max characters, on char boundaries.
classify_probe 🔒
The family the probe’s output (after the echo of the probe line) shows, or None while it hasn’t arrived.
clear_line 🔒
The key that clears a half-typed input line before run types: 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 run touches Vault values: gives the command some (secrets, stdin_secret, secret_files) or keeps what it prints (capture).
in_dir 🔒
command run in cwd: the drawer is a long-lived shell, so run’s cwd is a cd in front of the command (cmd’s /d changes 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 s that hasn’t ended yet: an ESC, 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 🔒
keys as 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, $SHELL elsewhere); None for a remote one, which is probed.
open 🔒
open_ending 🔒
How command ends 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, so run refuses 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 terminal an action names (shell_id is accepted too), else the agent’s drawer, opened if this process hasn’t opened it yet.
run_action 🔒
run_background 🔒
run with background: true: starts the job and returns at once.
run_with_secrets 🔒
run with secrets, 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 outlasts timeout_ms keeps 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 by run_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 (type with text).
with_exit_marker 🔒
The command with an exit-code marker after it, in the shell’s own syntax, tagged with this run’s nonce so no earlier run’s marker is taken for it. cmd expands %ERRORLEVEL% when it reads the line, before the command runs, so call with %^ERRORLEVEL% defers it; fish has $status for $?; PowerShell reports a native command’s code in $LASTEXITCODE and a cmdlet’s success in $?. The typed line itself never matches exit_marker: it has %^ERRORLEVEL%, $?, $status or a $(...) expression, not digits.
without_trailing_comment 🔒
command without 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 🔒
command without a trailing ; (a POSIX shell, fish, PowerShell): the marker starts with its own ;, and bash refuses ;; outside a case. cmd has no ; separator, so its command is unchanged.
write 🔒