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
+35 -4
View File
@@ -28,7 +28,30 @@ emulator. Auth flows that print a link, wait for a pasted token and continue
Android/iOS the toolbar also has a text field ("Type input, then Enter")
for the soft keyboard, with a Hide typing toggle; it is emptied when sent.
- The terminal is resized to its layout (debounced 150 ms); the process gets
SIGWINCH. New runs start at the last laid-out size.
SIGWINCH. New runs start at the last laid-out size. A live terminal does
not reflow (xterm.dart's reflow left the cursor on another line's row, so
prompts landed on old output and rows merged): narrowing cuts rows at the
new width (the cut cells are erased, so widening never brings stale text
back), fewer rows drop blank rows below the cursor and then scroll the top
into scrollback with the cursor's row at the bottom, more rows bring
scrollback back above it. Finished output still reflows to its card.
- **Keys** (`chat_shell_terminal_{input,key_input,keymap}.dart`): the view
encodes hardware keys before xterm.dart does, with the event's real
character, and a `TerminalInputHandler` chained before the package's
defaults encodes `keyInput` calls (key toolbar, soft keyboard) the same
way. Alt is Meta (ESC + the character, Shift and layout included; Macs:
the Option as Meta setting, the key's own character instead of Option's
symbol). Ctrl maps letters and `@ 2 Space`→NUL, `[ 3`→ESC, `\ 4`→0x1c,
`] 5`→0x1d, `^ 6`→0x1e, `_ / - 7`→0x1f, `? 8`→DEL. Arrows, Home/End,
Insert/Delete, PgUp/PgDn and F1–F12 carry xterm's modifier parameter
(1 + Shift 1 + Alt 2 + Ctrl 4: Shift+Up `CSI 1;2A`, Alt+Left `CSI 1;3D`,
Ctrl+Shift+Right `CSI 1;6C`, Ctrl+PgDn `CSI 6;5~`, Shift+F1 `CSI 1;2P`);
unmodified arrows and Home/End are SS3 under DECCKM. With DECKPAM the
keypad's Enter and operators send SS3 (`ESC O M`, `k`, `m`, `j`, `o`);
keypad digits keep typing (NumLock on). Alt+Backspace is `ESC DEL`,
Ctrl+Backspace `^H`, Shift+Tab `CSI Z`, Alt+Enter `ESC CR`. Ctrl+Alt
typing a composed symbol outside Apple platforms (AltGr) types it.
Cmd (Meta key) chords and plain typing are left to the emulator.
- Printed `http(s)` links open in the browser on tap (wrapped links are
joined). Other schemes are ignored.
- Finished runs are drawn read-only, shrunk to the rows their output takes
@@ -92,8 +115,16 @@ emulator. Auth flows that print a link, wait for a pasted token and continue
position) for a live run, so two open clients send two answers.
xterm.dart 4.0.0 answers DSR 6 zero-based; the app overrides it to the
correct one-based answer.
- xterm.dart 4.0.0 keeps blank rows when it rewraps; the app drops blank rows
below the cursor after a resize so the top of the output stays in view.
- xterm.dart 4.0.0 keeps blank rows when it rewraps; for finished output
(the only output that reflows) the app drops blank rows below the cursor
after a resize so the top of the output stays in view.
- A live terminal's long lines are cut, not rewrapped, when it narrows, and
stay cut when it widens again (as xterm without reflow).
- Key encoding gaps: no modifyOtherKeys / CSI u (Ctrl+Shift+letter sends the
plain control code, Ctrl+1/9/0 type the digit); Alt as Meta on Linux
assumes AltGr arrives as Ctrl+Alt or its own key; a Mac's Option as Meta
takes the character from the logical key, else the US position of the
physical key, so a non-US Mac layout's Option+key may send the US letter.
- Desktop typing uses key events (no IME composition for CJK input). Touch
platforms use the field.
- A descendant that keeps the PTY open after the command exits is read for
@@ -110,7 +141,7 @@ emulator. Auth flows that print a link, wait for a pasted token and continue
`chat_shell_plain.go`, `chat_shell_runner.go`, `chat_shell_supervise.go`,
`chat_shell_run_handlers.go`, `chat_shell_share.go`, `chat.go`,
`websocket.go`; `internal/pipeline/chat_shell_runs.go`; `go.mod`, `go.sum`.
- App: `lib/features/chat/shell/chat_shell_terminal_{session,view,keys,theme,links,page}.dart`,
- App: `lib/features/chat/shell/chat_shell_terminal_{session,view,keys,theme,links,page,input,key_input,keymap}.dart`,
`chat_shell_terminals.dart`, `chat_shell_output_view.dart`,
`chat_shell_run{,_card}.dart`, `chat_shell_card_actions.dart`,
`chat_shell_runs_{controller,repository}.dart`, `chat_shell_metrics.dart`;
+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.