Terminals: flow-controlled output, immediate echo, sliced emulator writes
Machine terminals no longer skip output for live viewers. Each connection's subscription is a cursor into the 1 MiB retained tail, drained by the connection's writer as soon as the PTY reader writes (no 50 ms tick; a streaming frame gathers for at most 2 ms). A subscription opened with flow: true gets window (256 KiB) in its reply and acknowledges drawn output with terminal_ack; while one is full the reader stops reading the PTY, so the program waits. A subscription full for 3 s without acking stops holding the terminal and later sees a gap; a gone connection drops its subscriptions. Clients that never ask for flow keep the old pacing (newest 64 KiB per 50 ms). terminal_open/terminal_output replies precede the frames that follow them, which start exactly at the reply's output_end. Chat shell runs share the buffer code: output is pushed as it arrives, oldest first, while the chat's watchers keep short queues; 256 KiB unpushed stops the reader, and watchers behind for 3 s get the old pacing. The app asks for flow, takes offsets from the server (frame end, reply output_end) instead of re-encoded text length, acks per quarter window, and writes replays and bursts into the emulator in slices that yield to the event loop (ChatShellTerminalFeed, shared with chat shells). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+20
-5
@@ -1299,7 +1299,7 @@ including before the browser has opened its application websocket.
|
||||
|
||||
Interactive login shells on a server's machine, independent of chats (the
|
||||
app's terminal panel). Every request carries `terminal_request`
|
||||
`{terminal_id?, cwd?, cols?, rows?, data?, after?}`:
|
||||
`{terminal_id?, cwd?, cols?, rows?, data?, after?, flow?}`:
|
||||
|
||||
- `terminal_open {cwd, cols, rows}` starts the machine's login prompt for the
|
||||
server's own account (`su -l <user>` in a PTY; macOS and Linux) and replies
|
||||
@@ -1317,11 +1317,26 @@ app's terminal panel). Every request carries `terminal_request`
|
||||
- `terminal_list` replies with `terminals` (running and ended, oldest first).
|
||||
- `terminal_input {terminal_id, data}` writes UTF-8 input (at most 16 KiB);
|
||||
`terminal_resize {terminal_id, cols, rows}` resizes. Neither is logged.
|
||||
- `terminal_output {terminal_id, after}` replies with the retained output (1
|
||||
MiB tail) from byte `after` of the stream named `stream`. Opening or reading subscribes the connection to
|
||||
the terminal's output frames.
|
||||
- `terminal_output {terminal_id, after, flow?}` replies with the retained
|
||||
output (1 MiB tail) from byte `after` of the stream named `stream`, covering
|
||||
bytes `[output_start, output_end)`; the output frames that follow the reply
|
||||
start at `output_end`. Opening or reading subscribes the connection to the
|
||||
terminal's output frames.
|
||||
- `terminal_ack {terminal_id, after}` (flow-controlled subscriptions only):
|
||||
the connection has drawn the output up to byte `after`. Not logged.
|
||||
- `terminal_close {terminal_id}` kills the login or shell.
|
||||
- Pushed `terminal_event {terminal_id, output, offset, end}` (output) or
|
||||
`{terminal_id, terminal}` (opened, title, exited, closed).
|
||||
`{terminal_id, terminal}` (opened, title, exited, closed). Offsets are bytes
|
||||
of the terminal's stream (invalid UTF-8 is shown as U+FFFD, so a client takes
|
||||
`end`, never the text's length).
|
||||
- Output flow: an `open` or `output` with `flow: true` gets `window` in its
|
||||
reply (256 KiB). Output is pushed as soon as it is read (bursts coalesce for
|
||||
at most 2 ms), every byte in order, at most `window` bytes past the last
|
||||
`terminal_ack`; while a flow-controlled subscription is full the server stops
|
||||
reading the PTY, so the program waits. One that stays full for 3 s without
|
||||
acknowledging stops holding the terminal; after its next ack it sees a gap
|
||||
(`offset` past its end) and reads `terminal_output` again. A subscription
|
||||
without `flow` (older clients) is never waited for: one frame of the newest
|
||||
64 KiB per 50 ms, gaps re-read as before.
|
||||
|
||||
See `app/notes/terminal-panel.md`.
|
||||
|
||||
Reference in New Issue
Block a user