Skip to content

feat(terminal): libghostty alone parses on a phone or tablet by default - #4760

Merged
devswha merged 1 commit into
mainfrom
feat/ghostty-only-phone
Nov 25, 2026
Merged

devswha merged 1 commit into
mainfrom
feat/ghostty-only-phone

Conversation

@devswha

@devswha devswha commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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.

Both engines (before) libghostty only (now the phone default)
Main thread 5326 ms 2141 ms (2.49x)
Browser CPU 10600 ms 3660 ms (2.90x)
Total blocking time 315 ms 60 ms
Long tasks over 50 ms 14 5

Android emulator (Chrome 133, measured at an earlier head with pictures off):

  • main thread: 889 ms -> 381 ms (2.33x)
  • browser CPU: 2550 ms -> 980 ms

Tests

capture.test.ts checks two things:

  • The default is on only for a coarse pointer.
  • A stored choice decides over the default.

Validation

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.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Behavior
    • Terminal parsing now defaults to libghostty on coarse-pointer devices. Your saved preference remains in control: choosing “on” or “off” overrides the default. Devices without a coarse pointer continue to default to the existing behavior.

The change exports ghosttyOnly(coarse) and uses the coarse-pointer media query as its default. Stored on and off values still override that default. Tests cover the default and both stored overrides.

Changes: Ghostty parsing default

Layer / File(s) Summary
Default, override, and capture wiring
src/lib/ghostty/capture.ts, src/lib/ghostty/capture.test.ts
captureForGhostty passes the coarse-pointer match to ghosttyOnly. The function uses stored on or off choices when present, and otherwise returns the coarse-pointer value. Tests cover the default behavior and stored overrides.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Refactor

Possibly related PRs

  • devswha/ovis#4759: Adds the local-storage flag and libghostty-only parsing path used by this change.
Merge Risk: Minimal · up to e5c4a

Phones and tablets now default to libghostty-only parsing, and a stored on or off choice still overrides that default. Desktop behavior is unchanged. No concrete defect was found, and the change can be reverted or overridden per user, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: libghostty alone parses by default on phones and tablets. The raw summary confirms ghosttyOnly now defaults from a coarse-pointer flag, and the description and objecti…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the template. It has a Change section that explains the problem and the resulting behavior: the libghostty-only path turns on by default for coarse pointers, and the localStora…
Full details: Title check

Explanation

The title names the main change: libghostty alone parses by default on phones and tablets. The raw summary confirms ghosttyOnly now defaults from a coarse-pointer flag, and the description and objectives describe the same behavior. The title is specific and concise, and it matches the changeset.

Full details: Description check

Explanation

The description follows the template. It has a Change section that explains the problem and the resulting behavior: the libghostty-only path turns on by default for coarse pointers, and the localStorage override still applies. It has a Validation section that lists the checks run (bun run check fast, plus named CI suites) with results. It links step 5 (#4759) and the #4688 case. The template asks for an issue link where a maintainer agreed to the feature, and the description does not link one for this step. Validation does not state which checks were skipped. These gaps are minor.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 937c526 and e5c4add.

Files selected for processing: 2

  • src/lib/ghostty/capture.test.ts
  • src/lib/ghostty/capture.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@devswha
devswha merged commit bc6d5d3 into main Nov 25, 2026
16 checks passed
@devswha
devswha deleted the feat/ghostty-only-phone branch November 25, 2026 19:54
@devswha

devswha commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head e5c4adda7. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit reviewed this head.

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.

devswha added a commit that referenced this pull request Nov 25, 2026
#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.
devswha added a commit that referenced this pull request Nov 26, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant