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 ofhttp_pty_shell.rs.
Macros§
- own_
pane_ 🔒handler - A
ptyshellhandler 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 aESC[<row>;<col>Rreply. A human-facingtermpane 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
bytesbegin a UTF-8 character that isn’t complete yet. - lock_
shell_ 🔒for_ agent - Lock
shell_idout from human keyboard input forAGENT_LOCK_WINDOW_MSfrom 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 forAGENT_LOCK_WINDOW_MSto 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 casestry_attach_to_existing_shellrefuses. - since_
slice 🔒 - Where to start reading
lenbytes that begin atstart_idxin the whole log, for a reader that has seen everything beforesince; and the log’s absolute end, the nextsince. Offsets are absolute, so they keep growing even when a circular file drops its oldest bytes. Asincebefore 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.