Merge main into the terminal flow-control branch

Conflicts resolved keeping both sides: main's active-client rules, input
lane, reply marking and key input, and this branch's flow control,
acknowledgements, subscriptions and sliced emulator feed. terminal_ack
joins the terminal lane; the feed marks each live slice it writes as
drawing, so the emulator's answers still go to onReply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 00:03:20 +00:00
148 changed files with 18443 additions and 153 deletions
+64 -8
View File
@@ -25,14 +25,20 @@ tmux inside it for work that must survive that).
own login and asks for the password again.
- **Shortcuts** (`terminal_shortcuts.dart`, handled by the surface as a
`FocusManager` early key handler, so they work wherever focus is, including
inside the terminal and in the chat composer, and neither receives the key):
in the chat composer, which does not receive the key):
- **Alt+T** (Option+T), **Ctrl+T**, **Cmd+T** (Meta+T) and **Ctrl+`**
show or hide the terminal in the selected mode; on a narrow window they
open and close the full-screen page. Only the one modifier counts
(Ctrl+Shift+T, Ctrl+Alt+T pass through); Option+T, which types † on a
Mac, is also matched by key position. Cmd+` stays the macOS window
switcher. **The shell's own Ctrl+T (transpose-chars) no longer reaches
it** while this binding is on.
switcher.
- **Inside a focused terminal** (any `TypingSurface`, i.e. a terminal
view) only **Cmd+T** and **Ctrl+`** toggle: **Ctrl+T** reaches the shell
as `^T` (transpose-chars) and **Alt+T** as `ESC t` (transpose-words).
A held chord that opened the terminal from outside keeps its repeats
swallowed after the terminal takes the keyboard, so nothing is typed.
The ⋮ menu and the shortcut cheatsheet say so
(`TerminalShortcutLabels.inTerminalNote`).
- **Ctrl+Tab / Ctrl+Shift+Tab**, while the terminal is shown (panel,
window or narrow page), select the next / previous terminal tab, wrapping,
and focus it. This deliberately overrides the chat's Ctrl+Tab pane
@@ -89,9 +95,16 @@ tmux inside it for work that must survive that).
from its retained output. A dropped connection resumes after the last
byte held. A restarted server lists the terminals as ended, with why.
- **Keyboard:** a focused terminal gets every key (Ctrl-C, Esc, Tab, arrows,
Ctrl-letters) except the shortcuts above (Ctrl+T, Alt+T, Cmd+T, Ctrl+`,
and Ctrl+Tab while shown); paste is Cmd-V (Apple) or Ctrl-V/Ctrl-Shift-V. Clicking
elsewhere moves focus away normally.
Ctrl-letters, Ctrl+T, Alt+T) except Cmd+T, Ctrl+` and Ctrl+Tab while
shown; paste is Cmd-V (Apple) or Ctrl-V/Ctrl-Shift-V. Clicking elsewhere
moves focus away normally. Keys are encoded as xterm does; see
`chat-interactive-terminal.md` (Keys). **Option as Meta** (Settings →
Appearance → Terminal, Macs only, saved with the layout, default on): a
Mac's Option sends `ESC` + the key's character (Option+B = `ESC b`)
instead of typing its symbol (∫). On by default because the shell's
Meta bindings (word motion, transpose, yank-last-arg) are used far more
in a terminal than Option's symbols; turn it off to type them. Other
platforms' Alt is always Meta.
- No terminal request is sent until the terminal is first shown (or a
terminal is opened): each connection sends one request at a time, so the
first screen's read is never queued behind `terminal_list`.
@@ -107,8 +120,28 @@ data?, after?}`.
when the login cannot ask for a password (below).
- `terminal_list` → `terminals` (running and ended, oldest first; live
records carry their current title, size and `stream`).
- `terminal_input {terminal_id, data}` (UTF-8, ≤ 16 KiB, 64-request queue),
`terminal_resize {terminal_id, cols, rows}` (clamped 20–500 × 4–200).
- `terminal_input {terminal_id, data, reply?, cols?, rows?}` (UTF-8,
≤ 16 KiB, 64-request queue), `terminal_resize {terminal_id, cols, rows,
activate?}` (clamped 20–500 × 4–200).
- **Several clients on one terminal** (`terminal_viewers.go`,
`terminal_active.go`; chat terminal commands too): one *active* client
owns the PTY size and is the only one whose emulator's automatic answers
(`reply: true`: cursor position, device attributes) reach the shell, so
a query gets one answer, not one per client. The opener starts active;
typing (carrying the typist's `cols`/`rows`, applied before the input)
or focusing a terminal view (`terminal_resize` with `activate`) makes a
client active. Others' sizes are kept, not applied; when the active
connection closes the next most recent client's size is applied. The
client marks answers by what the emulator emits while drawing output
(`ChatShellTerminalSession.onReply`).
- **Input latency**: `PipelinesClient.call` sends `terminal_input`,
`terminal_resize`, `chat_shell_input` and `chat_shell_resize` at once
instead of behind the previous request's reply; the server reads them
onto a per-connection terminal lane (`terminal_lane.go`) handled in
order beside the ordinary loop, and `terminal_open` runs off the read
loop. `ChatShellInputPipe` still keeps one request in flight per
terminal (typing during it is coalesced; answers go in their own
requests).
- `terminal_output {terminal_id, after}` → `terminal` with `output`,
`output_start`, `output_end`, `stream`; subscribes the connection.
- `terminal_close {terminal_id}` → the closed record (runs off the read
@@ -438,3 +471,26 @@ The tmux results above (restart survival, client replacement, the
service outlived it and was killed by hand.
- Not verified: logging in for real (needs the operator's password), Linux
su, and the app against a live server in a browser (widget tests only).
### Terminal input and resize fixes, round 1 (2026-11-25)
- Resize: live terminals run with `reflowEnabled: false`; the old
blank-row-trimming `resize` override now applies only to finished
(reflowing) output, and narrowing erases cells past the new width.
Tests: `test/features/chat/shell/chat_shell_terminal_resize_test.dart`
(long lines shrink/grow with the prompt on the cursor row, shell redraw
and command output after shrinking, no stale text after widening, cleared
screen and scrollback stay cleared, a view whose box shrinks and grows).
- Keys: xterm encoding for Alt/Meta, Ctrl symbols, modified special keys,
DECCKM and DECKPAM (`chat-interactive-terminal.md`, Keys); Option as Meta
setting. Tests: `chat_shell_terminal_input_test.dart` (key event to
bytes, Linux and macOS variants, setting on and off, toolbar `keyInput`),
`chat_shell_terminal_test.dart` (keys through the real view, Ctrl-V paste
intact), `terminal_surface_test.dart` (setting saved and restored, hidden
off Apple platforms).
- Shortcuts: inside a terminal Alt+T and Ctrl+T reach the shell; Cmd+T
and Ctrl+` still toggle (`terminal_shortcuts_test.dart`).
- Not verified: bytes against a real PTY in a browser or native build after
the change (widget tests only), real macOS Option events (native and
browser logical-key shapes are assumed as the tests model them), AltGr on
a real non-US Linux/Windows layout.