Skip to main content

Module http_pty_shell

Module http_pty_shell 

Source
Expand description

PTY shell HTTP handlers. Split out of server/mod.rs unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md §4.1).

Modules§

create_steps 🔒
The steps of handle_pty_shell_create, one function each, in the order the handler runs them: where the shell runs, the SSH consent, the reuse of the pane’s existing shell, the new shell’s block, the atomic claim of the pane’s one shell pointer, the controller start and its rollback. Moved out of the handler without a change in behaviour. A child module of http_pty_shell.rs.

Macros§

own_pane_handler 🔒
A ptyshell handler that acts for the caller’s own pane: the pane comes from the caller’s token (or signed identity), a pane named in the request that differs is refused, and the rest of the handler runs on the proven one.

Functions§

answer_conpty_handshake_if_seen 🔒
Answer Windows ConPTY’s own startup handshake, if seen, before the caller proceeds. Discovered live (not assumed): the moment a Windows ConPTY is created, it queries the cursor position (ESC[6n, Device Status Report) and blocks its own internal state — and therefore every later write — until it sees a ESC[<row>;<col>R reply. A human-facing term pane gets this for free because xterm.js, running in the browser, answers real cursor queries as part of being an actual terminal emulator; this headless facility has nothing playing that role, so without this the PTY would sit permanently stuck before printing even its first prompt — confirmed by a live round trip that hung indefinitely until this was added. ESC[1;1R (cursor at row 1, col 1) is a plausible-enough fixed answer: nothing here has rendered anything yet, so “top-left” is as true as any other coordinate, and ConPTY only wants to reconcile its internal buffer, not validate the value against anything a person would see.
handle_pty_shell_create 🔒
POST /api/v1/ptyshell/create — attach to (creating if needed) “this pane’s one shell.”
handle_pty_shell_input 🔒
handle_pty_shell_read 🔒
handle_pty_shell_resize 🔒
handle_pty_shell_status 🔒
handle_pty_shell_stop 🔒
incomplete_tail 🔒
How many bytes at the end of bytes begin a UTF-8 character that isn’t complete yet.
lock_shell_for_agent 🔒
Lock shell_id out from human keyboard input for AGENT_LOCK_WINDOW_MS from now — called BEFORE every agent write (input/resize), not after (see the call sites’ own comment for why the ordering matters). Best-effort: a failure to write the lock meta just means the human’s input isn’t blocked this time, not that the agent’s write itself failed.
pty_shell_input 🔒
POST /api/v1/ptyshell/input — write raw text to the PTY, as if typed. Unlike /api/v1/shell/input, no newline is appended: a real terminal doesn’t add one either, and PTY programs (readline, Sharprompt) expect the caller to send exactly what a keyboard would (e.g. "y\n" to answer a prompt and press Enter, or "\x03" for Ctrl+C — the OS PTY layer translates that raw byte into a real interrupt delivered to the foreground process, same as a human pressing Ctrl+C in a real terminal, without ending the shell).
pty_shell_read 🔒
POST /api/v1/ptyshell/read — read back the shell’s raw output tail.
pty_shell_resize 🔒
POST /api/v1/ptyshell/resize — resize the PTY. Some TUIs render differently or wrap badly at the fallback geometry (25x200).
pty_shell_status 🔒
POST /api/v1/ptyshell/status — query whether the shell is still running.
pty_shell_stop 🔒
POST /api/v1/ptyshell/stop — release the agent’s lock immediately, without waiting for AGENT_LOCK_WINDOW_MS to lapse on its own.
running_shell_conflict 🔒
The 409 for a pane whose agent shell is running (or starting, created by this run) on another connection than connection, checked without touching the shell; the same cases try_attach_to_existing_shell refuses.
since_slice 🔒
Where to start reading len bytes that begin at start_idx in the whole log, for a reader that has seen everything before since; and the log’s absolute end, the next since. Offsets are absolute, so they keep growing even when a circular file drops its oldest bytes. A since before what is still held reads all of it; one past the end (a cleared log) reads it all again. The range holds whole characters only: it starts past any continuation bytes (a wrapped log can begin mid-character) and stops before a character still being written, which the next read returns.