Skip to main content

Module browser_terminal

Module browser_terminal 

Source
Expand description

Browser’s terminal action: typing and running commands in a web terminal on a site the person granted (docs/specs/SPEC_BROWSER_WEB_TERMINAL_TYPING_2026_10_23.md §4).

The host does the typing (browser_api/terminal.rs: real key events into xterm.js); this module decides whether it may happen and what comes back:

  • the agent needs a live grant with the terminal power on this pane, and the page and the terminal’s own frame must be on the granted sites;
  • a line that looks like a credential is never typed, and neither is anything while the terminal is asking for a password or a code;
  • text goes in small chunks, and the grant, the pause and Stop are checked between them, so a brake pressed mid-script ends it within a moment;
  • what the terminal prints goes back to the agent only, as untrusted page content, and is never written to the Log or the host log.

Structs§

HostFailure 🔒
The host could not type a chunk, after sent keys had gone in.
KeyStep 🔒
One key for the host: the fields of a CDP key event.
Typing 🔒
How far typing a script got, and why it stopped short, if it did.

Enums§

Refusal 🔒
Why the terminal can’t be typed into right now.

Constants§

CHUNK 🔒
Keys per call to the host. A brake is checked between calls.
CTRL_LETTERS 🔒
The Ctrl combinations a shell uses (spec D6): interrupt, end of input, suspend, clear, history search, and the line-editing set.
DEFAULT_WAIT_SECS 🔒
How long to wait for output when the agent didn’t say.
LINE_SETTLE 🔒
The longest to wait for the rows to catch up with a line before reading them for a prompt and sending the next one.
MAX_CHARS 🔒
Most characters one call types, so a script fits and a runaway can’t.
MAX_LINES 🔒
Lines (Enter presses) per call. Each one after the first waits for the rows to catch up and is checked again, about a second and a half apiece, so this keeps a call well inside the MCP client’s timeout.
MAX_ROWS 🔒
Rows of output given back, from the bottom of the terminal.
MAX_WAIT_SECS 🔒
The longest an agent may ask to wait for output.
POLL 🔒
How often the rows are read while waiting.
QUIET 🔒
Output counts as settled once it hasn’t changed for this long (a little over ROWS_LAG, so the rows have caught up with what it printed).
ROWS_LAG 🔒
How long xterm.js’s screen-reader rows can trail the screen: it redraws them at most once a second, so a line’s output (a password prompt) may not be in the rows for up to this long after the line ran.
SECRET_NAMES 🔒
Names whose assignment (NAME=value) puts a secret on the command line.
SECRET_PROMPT_WORDS 🔒
Words a terminal prompt uses when it asks for something only the person should type.
TYPE_BUDGET 🔒
The longest a call spends typing before it stops and says how far it got. Lines are capped, but a long line is many pieces, each checked again; this keeps any call inside the MCP client’s 120 s (plus the output wait), so a client that gave up never leaves the handler typing with nobody waiting.

Functions§

auth_header 🔒
An Authorization: header, or Bearer followed by a long token.
budget_stop 🔒
check_target 🔒
Looks at the page, at the frame that holds the terminal, and at the last line the terminal shows, and says whether the grant lets the agent type there now. Run before the first key and again before every later line: a page can navigate, and a command can open a prompt, between two keys.
credential_line 🔒
Does text look like it holds a credential (a key, a token, a private key, a header value, a password in an assignment or a URL)? It is then never typed: it would land in the shell’s history and the process list. The key and token shapes are the ones the app redacts logs with; the rest is for a command line. Errs towards refusing: the person can type it, or the agent can use a value the shell already has.
detail_for_log 🔒
What the Log keeps for a call: the text (shortened), else the keys. Empty when the text looks like a credential, on every path including a call that is refused for another reason: the Log is the person’s record, and a key or a token has no place in it.
enter 🔒
finish_typing 🔒
Reads what the terminal printed, once it settles, logs the call and answers it.
handle_ui_browser_terminal 🔒
POST /api/v1/ui/browser/terminal — backs Browser’s terminal action.
is_token_char 🔒
jwt 🔒
A JSON web token: eyJ… and two more dot-separated parts.
let_screen_catch_up 🔒
Before the next line goes in, let what the last one did reach the rows: wait out ROWS_LAG, then read until two reads in a row agree, for at most LINE_SETTLE, so a prompt a command opened is showing when it is checked.
log_how 🔒
How the Log records the call: typed under the grant, or, when not one key went in, refused. A prompt’s text is never what the Log keeps.
look 🔒
Ask the host what the page’s terminal looks like now.
output_fields 🔒
What a call tells the agent about the terminal’s output: the rows when they could be read (page content, untrusted), else why not.
over_budget 🔒
Whether a call has typed for as long as one call may.
pieces 🔒
The keys in the order they go out, in pieces. A piece ends after an Enter (the end of a line, so the screen can be read before the next line goes in: a command may have opened a password prompt) or at max keys, whichever comes first.
rows_of 🔒
secret_assignment 🔒
NAME=value with a secret-looking NAME and a literal value (not $VAR, a <placeholder> or a short word like none).
secret_prompt 🔒
Is the terminal’s last line asking for a password, passphrase, code or token? The line must end like a prompt (a colon or a question mark) and name one, so a path or a project called token-service doesn’t count. Echo is usually off at such a prompt, so the person types there anyway (spec §4.3).
settle 🔒
Read the terminal until its rows stop changing for QUIET, or until shows in them, or wait is up.
step_for_char 🔒
The key for one typed character: what a keyboard would send for it. The code and the virtual key are best effort for punctuation and non-ASCII text: xterm.js acts on key, and Chrome raises the character from text.
step_for_key 🔒
A named key from the keys list.
steps_for_request 🔒
The keys a call types: its text, then an Enter (default: yes when text is given) unless the text ended in one, then its named keys. Checked before anything is typed.
steps_for_text 🔒
The keys that type text: each line break is a real Enter, a tab is Tab. Other control characters are refused (a stray escape sequence is not text the agent meant to type).
stop_before 🔒
Whether the call must stop before typing chunk n of parts, and why (with whether it is a secret prompt): over the time one call may type, the person paused the pane or ended the grant, or, from the second chunk, the page or terminal no longer passes (after a line, once the screen has caught up with it).
terminal_grant 🔒
The grant that lets agent type on pane: this agent, this pane, the terminal power, and this page. The person’s standing grant for the agent on the page’s site makes one when the pane has none.
tidy_rows 🔒
The terminal’s rows as the agent gets them: trailing blank rows dropped, the bottom MAX_ROWS kept.
type_steps 🔒
Types steps a line at a time (or a chunk of a long one), with the brakes, the grant, the page and the prompt checked between pieces.
typed_for_log 🔒
What the Log keeps of what was typed: the line itself when short, else its first and last lines and its length. Masked and cut again by the Log.
url_password 🔒
A password in a URL: scheme://user:password@host.
wait_for 🔒
How long a call waits for the terminal’s output: what the agent asked, at most MAX_WAIT_SECS.