Repository navigation
feat(terminal): libghostty alone parses on a phone or tablet by default - #4760
Conversation
Step 7: the libghostty-only path (step 5) is on by default on a coarse
pointer (phone, tablet), where parsing every byte twice cost the most.
The choice is made before the first byte, when the server's kind may not
be known yet, so it holds on herdr-core and herdr alike. localStorage
"ovis:ghostty-only" ("on"/"off") decides over the default.
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
|
Merged through Reviews: step 7 flips the default of the step 5 path (reviewed there: gate reviewer, Codex adversarial, CodeRabbit with 16 threads fixed) for coarse pointers; CodeRabbit on this PR. On the lane brief's word. |
#4761) ## Summary Step 8 of moving the terminal from xterm to libghostty. It builds on step 7 (#4760), which turned the libghostty-only path on by default for phones and tablets. This turns that path on by default on every device, on herdr-core and herdr alike. One exception keeps xterm's full parse: a mirrored pane. That is a Windows PC's pane, or one on a machine without a PTY host, which is repainted from `pane.read`. Its folded view stands the IME's preedit on xterm's rows. The choice is made before the first byte, and a pane not yet known to be mirrored counts as attached. localStorage `ovis:ghostty-only` (`on` / `off`) still decides over the default. Nothing on screen is meant to change. Rows, the cursor, selections, links, pictures and the scroll position are drawn by the same libghostty layer as before. Only xterm's second, hidden parse is dropped. ## Speed All runs used the same recording, a 1.56 MB Claude Code session, with 5 runs per arm. All 10 runs got identical bytes. Desktop (1280x800, no CPU throttle): | | Both engines (before) | libghostty only (default after this) | |---|---|---| | Main thread | 491 ms | 340 ms (1.44x) | | Browser CPU | 4160 ms | 1660 ms (2.51x) | | Start to settled | 582 ms | 457 ms | | Heap growth | 2.2 MB | 3.4 MB (the 8 MiB kept for a handover) | Phone emulation (390x844, 4x CPU throttle), for reference from step 7: - main thread: 5326 ms -> 2141 ms (2.49x) - browser CPU: 10600 ms -> 3660 ms (2.90x) ## Also in this PR Default-on brought three browser scripts to fail on the first CI run: - **The outputProbe** in `useTerminalMount` counted bytes reaching xterm. xterm now gets controls only, so the probe counts each output frame where it enters the terminal, whichever engine parses it. This fixes sidebar-activity and terminal-release-no-watch. - **A real difference:** an OSC 52 whose ST was split between ESC and the backslash was copied one frame late. xterm ends a string at its ESC, so the picture writer and the control scanner now pass that ESC on with the write it ends, and send only the backslash after it. Unit tests in `controls.test.ts` and `itermPictureWriter.test.ts` cover it; both fail without the fix. - **replay-clipboard** reads xterm's own OSC parse state, so it runs with the libghostty-only path off. That is the path mirrored panes and every fallback still take. ## Tests - `capture.test.ts`: the default is on unless the pane is mirrored, and a stored choice decides over it. - `overlay-fallback.test.ts`: the case without the flag now sets "off", since the default is on. ## Validation - `bun run check fast` at this head: pass. - CI runner image, default as shipped: - core-history-scroll, including the #4688 case - terminal-ghostty, terminal-images and mirror-scroll - ui-terminal, ui-regression, ui-ime, ui-access and ui-contexts All 9 pass, with no error lines in their logs.
…scrolling through its history (#4768) ## Summary On herdr-core, opening a terminal or switching to one in Terminal view showed its history scrolling down before it settled at the newest rows. The owner saw it when switching between sessions. Cause: hc replays an attach's history (`TERMINAL_HISTORY_LINES`, 2000 lines) in 16 KiB frames, all within about 5 ms. The server passed each one to the browser as its own `pty-data` frame. The browser parses each frame in its own task and draws between them, so the rows it shows climb through the history. This happens with `ovis:ghostty-only` on and off, and at the main from before #4759/#4760/#4761 (22abe50). It is not new from last night. Fix (`server/core/attach-batch.ts`): the server holds a herdr-core attach's first output until hc has been quiet for 15 ms, then passes it on as one frame. A program that never goes quiet does not hold the pane longer than 150 ms. A batch is sent every 256 KiB (`OUTPUT_HIGH_BYTES`), so it stays under the viewer's output window. Output after the first gap goes on as it comes, and held output goes out before an exit. Input readiness is unchanged: `input-ready` still goes on the first byte. Because the change is in the server, phone app builds that carry an older client get it too. The HTTP/WS contract does not change: there are fewer and larger `pty-data` frames, and nothing else. ## Measured Real herdr-core (isolated hc 0.1.18 core, `isolatedHcEnv`), two tabs that each printed 3000 lines. The probe switched between them four times per arm and counted the distinct row ranges the page drew in each animation frame after the click. | | Before | After | |---|---|---| | `pty-data` frames for the history | 12 (137 KB) | 1 | | Desktop, ghostty-only on: frames between the click and the newest rows | 1-3 | 0 | | Desktop, ghostty-only off | 3-4 | 0 | | Phone (390x844), on and off | (not run before) | 0 | Server-side timing of hc's frames during a replay: 16 KiB frames 0.1-4.7 ms apart, then the attach's replies 10-100 ms later. ## Tests `server/core/terminals.test.ts`: - The history comes as one frame once hc is quiet, and later output goes on as it comes. - A program that never goes quiet is passed on by the 150 ms deadline. - Held output is passed on at the attach's exit. All three fail on main. With `history?.end()` removed from the exit path, the exit test fails (mutation check). The existing core isolation test now advances the quiet window before it reads. ## Validation - `bun run check fast`: workflow syntax, generated types and themes, typecheck, build and actionlint pass. Unit tests: 28424 pass, 1 fail. The failure is `server/ssh-account-add.test.ts`, which also fails on unchanged main in this checkout: its SSH forward socket path under the long `TMPDIR` is refused (`Bad local forwarding specification`). It is unrelated to this change. - `bun test server/core/terminals.test.ts`: 47 pass. - Not run: the browser regressions in the CI runner image (CI runs them).
Summary
Step 7 of moving the terminal from xterm to libghostty. It builds on step 5 (#4759), which added the libghostty-only path behind a flag.
This turns that path on by default on a phone or tablet (a coarse pointer), where parsing every byte twice cost the most. Since step 5 the choice is made before the first byte, when the server's kind may not be known yet, so it holds on herdr-core and herdr alike. A desktop browser is unchanged.
localStorage
ovis:ghostty-only(on/off) still decides over the default, so a user or a test can turn it off.Nothing on screen is meant to change. Rows, the cursor, selections, links, pictures and the scroll position are drawn by the same libghostty layer as before. Only xterm's second, hidden parse is dropped.
Speed
Phone emulation (390x844, 4x CPU throttle), on a 1.56 MB Claude Code recording, 5 runs per arm. All 10 runs got identical bytes and showed the same final screen.
Android emulator (Chrome 133, measured at an earlier head with pictures off):
Tests
capture.test.tschecks two things:Validation
bun run check fastat this head: pass.