Skip to content

fix(terminal): fold a mirrored pane wider than a phone to the screen - #1961

Merged
devswha merged 6 commits into
mainfrom
fix/terminal-clipped
Oct 26, 2026
Merged

devswha merged 6 commits into
mainfrom
fix/terminal-clipped

Conversation

@devswha

@devswha devswha commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Problem

Beta testers of the iOS and Android apps said the terminal looks "a bit cut off". The owner's screenshots show which kind: an omp pane in the terminal lens has every line cut off on the right, and the pane keeps the PC's width. Collie, on the same phone and the same pane, wraps the lines to the phone's width.

The PC is a Windows PC. herdr has no terminal attach there yet (herdrdev/herdr#4821), so the bridge mirrors a pane: it repaints pane.read at the pane's own size on that PC (pane-geometry with fixed: true, server/mirror.ts). A phone cannot resize that pane, and drew the grid 1:1 with the rest panned off to the right. Panes of Linux and macOS PCs are attached and take the phone's width, so they were not affected.

Fix

Client only; the server, herdr and the way devices share a pane's size are unchanged, so this does not wait on the 0.4.17 release hold for server/ and shared/.

  • src/lib/terminalFold.ts draws a mirrored grid wider than its mount again as text that wraps at the screen's width: each row's cells as coloured SGR runs in a white-space: pre-wrap block over the grid. The xterm grid stays at the pane's size, unseen, so everything that reads it (the masked-prompt detector, the input row reader, Find) still reads what herdr drew. Colours follow the theme (xterm's own sixteen where a theme names none) and the grid's minimum contrast. Korean words fold whole (word-break: keep-all).
  • The folded rows keep the grid cursor's row in view, as the grid does: at the top while it fits, else at the bottom of the view. The hidden grid moves down under them until its cursor row lies on theirs, so xterm's helper textarea and an IME preedit stand where the typed text will show.
  • A tap on a web address or a file path opens it through the grid's own link policy; any other tap focuses the terminal (the soft keyboard comes up as before). A wheel past the folded rows' edges scrolls the mirror's history at the chosen speed. A font change (Settings, a pinch) folds or unfolds at once. Find's highlight boxes, drawn for the grid's cells, are hidden while folded; Find still steps through matches.
  • It applies only to a mirror wider than its mount, for an interacting or a watching device. An attached pty, a split's following half and a mirror the screen fits are drawn as before.
  • A full-screen program's boxes fold with the text, so the pane menu (on a phone: the tab's ⋯ sheet) offers Original width, the grid as it is, panned sideways, and Wrap to screen. The choice is this device's (terminalMirrorWrap, a device setting, not collected by telemetry). Until the user chooses, a narrow screen (a touch screen, or 768 px and under) folds and a desktop keeps the original width.

Design precedent: the apps this repo compares against (Codex, Claude, Zed, Warp…) all size their terminal to the window, which a mirror cannot do. This follows Collie (AltanS/collie, web/src/components/ansi-output.tsx), which draws herdr's pane read as SGR runs in a pre-wrap block and never resizes the pane. No code is taken from it. DESIGN.md has the entry beside the existing mirrored-grid one.

Validation

  • bun scripts/mirror-fold-demo-regression.ts (new, in the browser lane), a 120x40 fixed mirror on demo fixtures with its PC flagged as a mirror the way a Windows PC is:
    • every row's end marker inside the screen at 390 and 360 px and at 844 px landscape; the folded rows hold the grid's rows in order; a coloured run keeps its colour;
    • the cursor's row is in view, and so is the hidden grid's cursor row (where xterm's input stands); a cleared shell's prompt on the first row stays in view on a short screen;
    • a Korean preedit composed on the cursor's row is in view and is the topmost element where it is drawn (with the grid moved by a transform instead of top, this fails: topmost: terminal-fold-row);
    • a tap on the right half of a URL's last character opens it; wheeling up pans the folded rows without touching herdr's history, and one more wheel at their top scrolls history 6 lines at speed 2;
    • Original width pans and survives a reload, Wrap to screen comes back; a watching phone folds;
    • a 1000 px desktop keeps the original width until Wrap to screen; a 1440 px desktop the grid fits is unfolded; an attached PC's pane on a phone is never folded and fits.
    • On origin/main it fails: 390px phone: rows cut off on the right ["END1 at 911-943 of 0-390", ...]. On this branch's first commit (before the review fixes) it fails: the grid's cursor row stays in view under the folded rows {"top":-1227,"bottom":-1210,"viewTop":97,"viewBottom":796}.
  • src/lib/terminalFold.test.ts: palette and grey ramp, the contrast lift, dim, row runs without herdr's padding, wide glyphs, escaping, bold-bright, link and column lookup for taps.
  • Unchanged and green: scripts/mirror-scroll-demo-regression.ts, scripts/narrow-pane-demo-regression.ts, settings, wheel and conventions tests; bun run check fast green on the head commit (unit 7147 pass, 0 fail).
  • Real apps against an isolated test herdr with Ovis servers forced to mirror (no PTY host, as on Windows): origin/main and this branch, the same pane (an omp-like screen with Korean text and a box status line, and btop) in a 144-column herdr window.
Device (app) Screen origin/main This branch
Android 1.0 (3), WebView 145, 412x915 dp, gesture nav, portrait omp-like (Korean text, box status line) grid 1131 px in a 411 px pane, 10 rows cut on the right folded, 0 rows cut, nothing to pan sideways, status line in view
same, landscape (pane 546 px) omp-like 10 rows cut folded, 0 rows cut
Android 1.0 (3), 360x800 dp, 3-button nav, portrait omp-like 10 rows cut folded, 0 rows cut; Korean folds at word boundaries, colours kept
Android 1.0 (3), 412x915 dp, keyboard up (real tap on the folded rows) omp-like - soft keyboard up (pane 706 -> 430 px), status line above the key bar, xterm's input inside the view
Android 1.0 (3), 412x915 dp, keyboard up a cleared shell (prompt on row 1) - the prompt stays at the top of the view, xterm's input on its row
Android 1.0 (3), 412x915 dp btop 47 rows cut folded, every glyph inside the pane (layout scrambled, as in Collie); the tab's ⋯ sheet offers Original width between Rename pane and Close pane, which brings the panned grid back and is kept (terminalMirrorWrap=false)
iOS Simulator app (built from main), iPhone 17e 390x844, iPhone 17 402x874, iPhone 18 Pro Max 440x956, portrait omp-like rows cut on the right folded

Screenshots and the Korean summary for the maintainer: (shared privately with the maintainer)

Reviews

An omo-native-code-reviewer pass (approve with notes) and a Codex (gpt-6.1-sol, xhigh) adversarial pass ran on the first commit, and a second Codex pass on the follow-up. Every finding below is resolved, the regression checking each behaviour:

Finding Resolution
Codex HIGH: folded rows always scrolled to their bottom, hiding a cleared shell's prompt on row 1 follow the grid cursor's folded row
Codex HIGH: a fold much taller than the grid scrolled the hidden grid (xterm's input, an IME preedit) out of view the grid moves down under the folded rows to the folded cursor row
Both, MEDIUM: links dead while folded taps open web addresses and file paths through the existing link policy
Reviewer MEDIUM: a watching phone was left cut off watching devices fold too
Reviewer MEDIUM: desktop selection/copy path lost while folded desktops keep the original width unless the user picks Wrap to screen
Both: a font change did not refold; a split half made active did not refold; forwarded wheels lost the chosen speed screen resize observer; the follow effect refolds fixed grids; forwarded wheels keep the real wheel's speed
Reviewer LOW: dim faded the background; any page selection blocked the tap dim fades the text colour; only a selection inside the folded rows counts
Codex (2nd pass) HIGH: moving the grid by a transform made it a stacking context, so a preedit drew under the folded rows the grid moves by top (.xterm is already relative); the regression's preedit check fails with the transform
Codex (2nd pass) MEDIUM: a tap on a glyph's right half missed links; a URL's own closing parenthesis was dropped the tapped glyph is resolved from the caret both ways; balanced parentheses stay

Known limits

  • A full-screen TUI (btop, vim) is hard to read folded; that is what Original width is for.
  • A long line the PC already wrapped stays broken at the PC's width and folds again, as in Collie.
  • Text selection in the folded rows is the browser's own (a long press), not xterm's.
  • The iOS Simulator cannot be rotated headless, so iOS was checked in portrait; Android covered landscape.

mp added 3 commits October 26, 2026 12:48
A Windows PC's herdr has no terminal attach, so the bridge mirrors a pane at
its own size on that PC (pane-geometry fixed: true) and a phone drew that grid
1:1: every row ran off the right edge. The grid now stays as it is, unseen, for
its input and readers, and lib/terminalFold.ts draws its rows again as coloured
text that wraps at the screen's width, as Collie draws a pane read. The pane
menu's Original width (terminalMirrorWrap, this device's) draws the grid as it
is again. Observers, attached ptys and a mirror the mount fits are unchanged.
…grid's

Review follow-up. The folded rows now keep the grid cursor's row in view
instead of their bottom, so a cleared shell's prompt on the first row stays
in sight, and the hidden grid moves down under them until its cursor row lies
on theirs, so an IME preedit shows where its text will. A tap on a web
address or a file path opens it as the grid's links do, a font change folds
or unfolds at once, a split half made active folds again, and a wheel past
the folded rows scrolls history at the chosen speed. A watching phone folds
too. Until the pane menu says otherwise, a narrow screen folds and a desktop
keeps the original width.
Second review round. The hidden grid now moves down by `top` rather than a
transform: a transform made it a stacking context, and an IME preedit drawn
by xterm's helpers went under the folded rows. A tap on the right half of a
link's last character opens it, and a web address keeps a closing
parenthesis it opened. The browser regression composes a Korean word and
checks the preedit is the topmost thing where it is drawn; with the
transform it fails.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d518b71 and 47b60e4.

Files selected for processing: 20
  • DESIGN.md
  • changelog.d/mirror-fold-phone.md
  • docs/development.md
  • docs/remote-pcs.md
  • scripts/ci-browser.sh
  • scripts/mirror-fold-demo-regression.ts
  • src/App.tsx
  • src/components/PaneCanvas.tsx
  • src/components/PaneTerminal.css
  • src/components/PaneTerminal.tsx
  • src/lib/i18n/terminal.ja.ts
  • src/lib/i18n/terminal.ko.ts
  • src/lib/i18n/terminal.zh.ts
  • src/lib/settings.legacy-fixture.ts
  • src/lib/settings.ts
  • src/lib/terminalFold.test.ts
  • src/lib/terminalFold.ts
  • src/lib/terminalWheel.ts
  • src/lib/useTerminalMount.ts
  • src/lib/useTerminalRefits.ts

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

📝 Summary

Summary by CodeRabbit

  • New Features
    • Oversized mirrored terminals now wrap to the screen width by default on touch devices and screens 768px wide or narrower, preserving colors and link activation.
    • Choose Wrap to screen or Original width from the pane menu; your choice is saved on this device. Desktops keep the original width by default.
    • Folded mirrors keep the cursor row visible and route wheel scrolling to mirror history.
  • Bug Fixes
    • Attached terminals and mirrored terminals that fit their pane remain unchanged.

Oversized mirrored terminal grids can fold into wrapped rows at screen width. A device-specific setting controls folding, with narrow screens defaulting to folded output and desktop screens to original width. The change also adds terminal interaction handling and browser regression coverage.

Changes: Mirrored terminal folding

Layer / File(s) Summary
Display preference and pane controls
src/lib/settings.ts, src/lib/settings.legacy-fixture.ts, src/App.tsx, src/components/PaneCanvas.tsx, src/components/PaneTerminal.tsx, src/lib/i18n/terminal.*.ts
Adds the device-specific terminalMirrorWrap setting and uses it, or the screen-width default, to select the mirrored pane display mode. The pane menu toggles between “Wrap to screen” and “Original width.”
Folded terminal rendering
src/lib/terminalFold.ts, src/components/PaneTerminal.css, src/lib/terminalFold.test.ts
Adds wrapped-row rendering with terminal styling, link and cell hit testing, cursor-row alignment, and fold lifecycle handling. Styles the overlay and tests color, text, URL, and column rendering.
Terminal interactions and fold lifecycle
src/lib/useTerminalMount.ts, src/lib/terminalWheel.ts, src/lib/useTerminalRefits.ts
Connects folding to mirror state, cursor following, link handling, focus, panning, wheel input, geometry changes, and cleanup. Forwarded trusted wheel events follow the real-event path for history scrolling and mouse reporting.
Browser regression and supporting documentation
scripts/mirror-fold-demo-regression.ts, scripts/ci-browser.sh, DESIGN.md, changelog.d/mirror-fold-phone.md, docs/development.md
Adds browser checks for phone and desktop layouts, menu persistence, links, history scrolling, focus, IME preedit, and attached panes. Adds the regression to browser CI and documents the behavior and command.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

  • devswha/herdr-web-ui#871: Describes a Windows mirrored fixed-grid pane being cut off on phones; this PR folds oversized mirrors to screen width.

Possibly related PRs

  • devswha/ovis#1800: Both changes address terminal input and IME preedit behavior on narrow layouts; this PR synchronizes the input viewport while rendering folded mirrors.
Merge Risk: Minimal · up to 47b60

The display choice updates the folded terminal as intended. No identified issue prevents merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 15 files. (5 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "fix(terminal): fold a mirrored pane wider than a phone to the screen" names the main change. The changeset adds folding of mirrored terminal grids wider than the mount (src/lib/terminalFold…
Description check Passed The description follows the repository template. It has a Change section that describes the problem, the fix, and the resulting behavior, and it links the related herdr issue (herdrdev/herdr#4821). It…
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.
Full details: Title check

Explanation

The title "fix(terminal): fold a mirrored pane wider than a phone to the screen" names the main change. The changeset adds folding of mirrored terminal grids wider than the mount (src/lib/terminalFold.ts, useTerminalMount.ts, PaneCanvas, PaneTerminal) so they wrap to the screen width on phones. It is concise, specific, and follows a conventional commit style. The title omits the per-device Original width/Wrap to screen setting, which is secondary.

Full details: Description check

Explanation

The description follows the repository template. It has a Change section that describes the problem, the fix, and the resulting behavior, and it links the related herdr issue (herdrdev/herdr#4821). It has a Validation section that lists the new regression script, unit tests, the full check run, and real-device results. The template asks for a maintainer-agreed issue link for features, and this is a fix, so no issue link is required. The description is thorough and includes known limits, so it passes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 15 files. (5 skipped: 5 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 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

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review of 47b60e4: changes requested.

  • omo-native-code-reviewer (claude-opus-5-5): passed it.
  • Codex Sol (gpt-6.1-sol, xhigh): found four MAJORs.

What holds, per the code reviewer and my own QA:

  • HTML safety. Pane text is escaped before innerHTML in rowHtml/run. Style values come only from the theme or from hex built from numbers. A tapped link must match https?:// and pass isWebLink again in onLink, so javascript: and data: cannot get through.
  • Gating. The fold requires the wrap setting, a fixed grid and no follow mode. A pane switch resets the fixed grid.
  • Cost and cleanup. Only rows xterm reports as changed are redrawn, and dispose() removes every listener and observer.
  • Tests. terminalFold.test.ts passes 86/86, and typecheck is clean. scripts/mirror-fold-demo-regression.ts passes locally. With useTerminalMount.ts reverted to main, it fails with "rows cut off on the right". The code reviewer's mutations also failed the tests: removing the escaping, a fold that never turns off, and dropping fold.sync().

MAJOR (Codex):

  1. An older tab's save erases the width preference (src/lib/settings.ts:497). Codex saved terminalMirrorWrap: false, then wrote unrelated settings through the legacy sanitizer and writer. Loading then returned null, and changing the fixture's type does not protect against this. Keep the preference under its own key, and add a test that it survives an old writer's round trip.
  2. A default foreground skips the minimum contrast (src/lib/terminalFold.ts:87). With foreground #d8d0c3 and an SGR background of the same colour, the style is only background:#d8d0c3;, so the text is invisible at 1:1. Resolve the default foreground before checking contrast.
  3. The contrast fix can pick a direction that can't reach the ratio (src/lib/terminalFold.ts:72). readableColor("#aaaaaa", "#aaaaaa", 4.5) returns white, at 2.32:1, though black gives 9.04:1. Try the other direction when the first can't reach the target.
  4. Folded OSC 8 links never open (src/lib/useTerminalMount.ts:419). A labelled hyperlink such as "Open docs" has no visible URL for webLinkAt, and terminalFileLinks scans only text paths, so tapping it only focuses the terminal. Look up OSC 8 targets through the grid, and keep the scheme checks.

MINOR (Codex): bold brightening happens before inversion (terminalFold.ts:83). For SGR 1;7;31;44 this draws normal blue on bright red, where xterm draws bright blue on normal red. Invert first, then brighten the resulting foreground.

MEDIUM (code reviewer): the &fold=off attached-pane case in the browser script uses a pane that already fits the phone. So nothing would catch a phone folding an attached pane that is wider than the screen, which is what the wanted: gate in useTerminalMount.ts prevents. Add a case with an attached pane whose grid is wider than the phone.

LOW (code reviewer, optional):

  • The pane menu offers Wrap to screen / Original width even for a mirrored pane that fits, where it does nothing.
  • Two negative checks in the script wait two animation frames instead of for a state.
  • The rowHtml tests pin exact inline-style strings, and the new setting's sanitizer has no direct test.

The re-review will cover only the new commits.

… links as the grid's

Merge pass follow-up. Wrap to screen / Original width now has a key of its
own (ovis:mirror-wrap), so an older tab's whole-record save no longer erases
it. A default foreground on a background of the program's own colour now gets
the minimum contrast, and the contrast search tries the other direction when
the first cannot reach it. Inverse swaps the colours before bold brightens
the foreground, as xterm draws them. A tap on a labelled OSC 8 hyperlink
opens its target through the grid's own link policy. The browser regression
adds an OSC 8 label and an attached pane wider than the phone, watched, which
must not fold.
@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Thanks for the review. Every point is addressed in 00e4378; each one has a check that fails without its fix.

MAJOR (Codex)

  1. Width preference erased by an older tab's save. terminalMirrorWrap now lives in its own key, ovis:mirror-wrap, written and read the way ovis:ui-font is (loadSettings / saveSettings), so it never enters ovis:settings. New test in settings.test.ts: save false, let the pinned old sanitizer and writer rewrite the record whole, and loadSettings() still returns false. It then checks true, back to null, and that a non-boolean sanitizes to null.
  2. Default foreground skipped the minimum contrast. cellStyle now resolves a default foreground to the theme's before the contrast check whenever the cell has a colour of its own. Unit test: default fg #d8d0c3 on an SGR background #d8d0c3 gets a colour at 4.5:1 or better.
  3. One-way contrast search. readableColor tries the other direction when the first cannot reach the ratio, then falls back to whichever of white or black is higher. Unit test: #aaaaaa on #aaaaaa reaches 4.5:1.
  4. Folded OSC 8 links did nothing. A tap on a cell with no visible address now reads that cell's OSC 8 target (hyperlinkAt) and opens it through the same handler as the grid's linkHandler (openHyperlink, shared now): http(s) opens as a web link, file:// in the viewer, anything else is ignored. xterm 5.5 exposes no public lookup, so hyperlinkAt reads _core._oscLinkService and the cell's extended.urlId, and returns nothing if either is missing. The browser regression now has a labelled OSC 8 row and taps its label.

MINOR (Codex): inverse now swaps first and bold brightens the resulting foreground, as xterm does. Unit test: SGR 1;7;31;44 draws bright blue (#729fcf) on red (#cc0000).

MEDIUM (code reviewer): new case ?fold=attached, an attached PC whose pane's pty grid (120 columns) is wider than a 390px phone. The phone watches it and adopts that grid: it pans as before and is never folded. With the wanted: gate's fixedGridRef check removed, the script fails right there ("folded":true).

LOW

  • The two negative checks now wait for a state: the unfolded, adopted grid with room to pan sideways.
  • Waits that time out now report where they were and what the pane showed.
  • Not done: the menu item still shows for a mirrored pane that fits. Hiding it would mean tracking each pane's fit in the menu, and the choice still decides what happens when that pane grows past the screen. rowHtml's exact-string assertions are kept on purpose: the inline style is the output.

Verification on 00e4378: bun run check fast green (unit 7151 pass, 0 fail); scripts/mirror-fold-demo-regression.ts, scripts/mirror-scroll-demo-regression.ts and scripts/narrow-pane-demo-regression.ts pass. CodeRabbit had no actionable comments on the previous head.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Merge pass re-review of 00e4378 (Codex Sol, gpt-6.1-sol, xhigh): one item left.

Fixed, re-checked against the earlier reproductions:

  • The wrap preference survives a save from the legacy sanitizer and writer, and the regression test passes.
  • A default foreground now reaches 5.01:1, where it was 1:1 before.
  • The readableColor("#aaaaaa", "#aaaaaa", 4.5) case now reaches 5.44:1.
  • "Open docs" style OSC 8 labels open their target through the grid, and javascript: / data: are still rejected.
  • Inverse is applied before bold brightening.
  • The browser script now checks that an attached pane wider than the phone stays unfolded.
  • Unit tests pass 90/90. mirror-fold-demo-regression.ts passes locally, including the new OSC 8, reload and wider-attached-pane cases.

MEDIUM, still open: a URL-shaped OSC 8 label skips the grid lookup (src/lib/useTerminalMount.ts:420, src/lib/terminalFold.ts:391).

  • Repro: a link targets https://example.com/real-target, and its label reads https://example.org/display-label.
  • What happens: a folded tap opens the label's URL, because the textual URL is chosen first. The unfolded grid opens the target.
  • Fix: resolve the cell's OSC 8 target first, and fall back to textual links only when there is none.

Only this change will be re-reviewed.

…ts label shows

Merge pass re-review. A tap on the folded rows now resolves the cell's own
target (an OSC 8 hyperlink, then a file path) before an address its text
shows, as the grid ranks its links: a hyperlink labelled with another URL
opened the label's address. The browser regression taps such a label.
@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Fixed in d0dbc7d. A tap on the folded rows now resolves the cell's own target first: its OSC 8 hyperlink, then a file path. Only when the cell has neither does it fall back to an address its text shows, which matches how the grid ranks its links (terminalFold.ts tap handler).

The browser regression now taps an OSC 8 link labelled https://example.org/display-label that targets https://example.com/real-target, and waits for the target to open. Run on 00e4378, the same script fails at that step (waitForURL times out on the label's page). On d0dbc7d it passes.

bun run check fast is green on d0dbc7d (unit 7151 pass, 0 fail).

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

The code review is done: Codex approved d0dbc7d, and the code reviewer passed the PR earlier. CI is red on the PR's own new script, though, so it can't merge yet.

  • Where it fails: scripts/mirror-fold-demo-regression.ts failed twice in run 40272238786 ("Browser regression (other scripts)", GitHub-hosted ubuntu-24.04, Bun 1.4.2) with TimeoutError: waitForEvent: Timeout 30000ms exceeded while waiting for event "page".
  • What the timing shows: attempt 1 failed after 32.6 s, so the very first link tap timed out: opened at line 313, page.mouse.click(linkRect.right - 1, …) on the link's last glyph. No tab opened at all.
  • Locally it passes: on the same head, here (Bun 1.4.3), it covers the plain link, the OSC 8 label and the address-shaped label.
  • The two runs for the earlier heads were cancelled, so this is the first full CI result for the script.

I suspect the click lands one cell off because the runner has different font metrics. A tap on the right half of the last glyph then falls outside the link that webLinkAt finds from the caret position. If so, the same thing could happen to users with other fonts. Please either make the tap target robust to font metrics (and the link lookup, if it's the feature), or hit the glyph's centre in the script if only the test is fragile. The CI artifact browser-other-40272238786-1 has the full log.

…opened

The fold regression failed on the GitHub runner: the first link tap opened
no tab. It tapped fixed page coordinates measured a moment before, and the
folded rows can move in between (a resize settling, the rows following the
cursor). Each tap is now measured against the row that holds the text and
Playwright clicks that row once it holds still. When no tab opens, the
script reports what the tap reached and which links the page tried to open.
@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

I looked into the red mirror-fold-demo-regression.ts in run 40272238786; the change is pushed as 9ca1f71 (test only).

  • Reproduction: I could not reproduce it locally. Run the way CI runs it, the script passes: the lockfile's Playwright Chromium (chromium-1243), CI=1, and the shared demo build from scripts/demo-build.ts. It also passes on Google Chrome, and with Chromium's CPU throttled 6×. The CI log has nothing past the timeout.
  • Likely cause: the script tapped fixed page coordinates it had measured a moment earlier. Between the two, the folded rows can move: a resize settling after the viewport change, or the rows following the cursor. The tap then lands on another row and opens nothing. A user's tap is unaffected, because it lands where the finger is when it lands. The link lookup tolerates font metrics: the tapped glyph is resolved from the caret on either side and checked against the glyph's own rectangle.
  • Change: each folded tap is now measured against the row that holds the text, three quarters across the glyph, and Playwright clicks that row once it holds still. When no tab opens, the script reports which taps it saw, which links the page tried to open, the selection and the scroll position, so another CI failure explains itself.

bun run check fast is green on 9ca1f71 (unit 7151 pass, 0 fail).

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

CI is green on 9ca1f71 (run 40275951384). scripts/mirror-fold-demo-regression.ts passed on the GitHub runner on its first attempt (9.6 s), and "Integration and browser" passed. Merge state is CLEAN.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review report. Overall: PASSED. This is an ordinary client change. Reviewers: Codex Sol (gpt-6.1-sol, xhigh), omo-native-code-reviewer (claude-opus-5-5) and my own QA.

Review history:

  • 47b60e4: the code reviewer passed it. Codex found 4 MAJORs and 1 MINOR, and the code reviewer added a MEDIUM.
  • 00e4378: fixed all of them except one MEDIUM.
  • d0dbc7d: fixed that MEDIUM, and Codex approved.

What holds:

  • HTML safety. Pane text is escaped before innerHTML in rowHtml/run, and style values come only from the theme or from hex built from numbers. A tapped link must match https?:// and pass isWebLink again in onLink, so javascript: and data: are rejected. OSC 8 links go through the same checks.
  • When the fold applies. It needs the wrap setting, a fixed grid (pane-geometry with fixed: true) and no follow mode. A pane switch resets the fixed grid, and an attached pane wider than the phone stays unfolded (covered by the browser script).
  • Rendering. Wide-glyph continuation cells and combining marks are handled, and inverse is applied before bold brightening. The cursor row and preedit stay in view. Prompt and input-row reading still use the hidden grid.
  • Cost and cleanup. Only rows xterm reports as changed are redrawn, and dispose() removes every listener and observer.

Findings and how each was resolved:

  • Wrap preference lost (MAJOR): an older tab's save erased terminalMirrorWrap. It now survives a legacy sanitizer and writer round trip, and a regression test covers it.
  • Default foreground contrast (MAJOR): a default foreground skipped the minimum contrast. The 1:1 case now reaches 5.01:1.
  • Contrast direction (MAJOR): readableColor picked a direction that could not reach the target. #aaaaaa on #aaaaaa at 4.5 now reaches 5.44:1.
  • Folded OSC 8 links (MAJOR): they never opened. Labelled links now open their target through the grid. A URL-shaped label now opens the OSC 8 target first, not the address the label shows (d0dbc7d).
  • Bold vs inverse (MINOR): brightening happened before inversion. Inverse now comes first.
  • Attached pane test (MEDIUM, code reviewer): the browser script now checks that an attached pane wider than the phone stays unfolded.

Tests:

  • terminalFold.test.ts and settings.test.ts pass 90/90, and typecheck is clean.
  • scripts/mirror-fold-demo-regression.ts passes locally. It covers 390, 360 and 844 px, the cursor and preedit, OSC 8 labels, the wheel, Original width surviving a reload, and attached panes left unfolded. With useTerminalMount.ts reverted to main, it fails with "rows cut off on the right".
  • The code reviewer's mutations (removing the escaping, a fold that never turns off, dropping fold.sync()) each fail the tests.

CI fix 9ca1f71 (test only):

  • What failed: the first folded-link tap in the new script opened no tab on the GitHub runner, failing twice.
  • The fix: each tap is now measured against the row that holds the text and made with row.click({ position }) once the row holds still. When no tab opens, the script reports what the tap reached.
  • Review: omo-native-code-reviewer passed it. It fixes a real race (rows moving between the measurement and the tap), and the test still asserts what it did: the last glyph opens LINK, an OSC 8 label opens its target, and an address-shaped label opens the real target, not the shown URL. It adds no fixed sleeps, and its diagnostics stay inside the test's browser context.
  • Check: passed 2/2 locally. The GitHub-runner CI is the deciding run.

Left as follow-ups (LOW):

  • In tapFolded, .first() would quietly pick the top row if the text appeared twice, and a missing text does not throw. Neither can happen with the current fixture.
  • The pane menu offers Wrap to screen even for a mirrored pane that already fits.
  • Two negative checks in the script wait two animation frames instead of waiting for a state.

This PR shares files only with outside PRs #1639 and #1911, which already conflict with main, and with #1952 on DESIGN.md, where there is no conflict.

@devswha
devswha merged commit 84d7011 into main Oct 26, 2026
11 checks passed
@devswha
devswha deleted the fix/terminal-clipped branch October 26, 2026 06:15
aNNdii added a commit to aNNdii/herdr-web-ui that referenced this pull request Oct 26, 2026
Merge upstream/main (352 commits up to devswha#1961) into next
devswha added a commit that referenced this pull request Oct 26, 2026
…1963)

## Problem

#1961 folds a mirrored pane (a Windows PC) that is wider than a phone.
An attached pane (a Linux or
macOS PC) gets cut off in the same way whenever the phone is not the one
sizing the pty:

- **A device paired to watch** draws the pty's grid, and a desktop sized
that grid. In QA a desktop
held the pane at 174x53. On a 390 px phone every row ran off the right
edge, with 1365 px to pan
  sideways.
- **A driving phone with its soft keyboard up** keeps the grid it shows
until the keyboard goes
(#1045). If a desktop takes the pty in the meantime, the phone draws the
desktop's grid. The same
happens when the terminal lens comes back from Chat with the keyboard
still up.

When the phone drives the pty, the program redraws at the phone's width,
so there is nothing to fold.
The Collie comparison (lane collie-research, section 8 item 1)
recommended this reading view for
these cases.

## Fix

The change is client only. `server/`, `shared/`, herdr and the way
devices share a pane's size are
unchanged.

- `lib/terminalFold.ts`: whether to fold is now decided by `foreign()`
(this browser does not size
the grid) and `wrap()` (the user's choice). The fold also reports when a
foreign grid is wider than
  its mount.
- `lib/useTerminalMount.ts`: a grid counts as foreign when it is a
mirror, a watched grid, or a grid
held under the keyboard. A split's following half never counts. The
folded rows come from the xterm
buffer the attach stream wrote: there is no `pane.read`, scrollback
stays 0, and nothing resizes,
takes over or refocuses the pane. Cursor, IME and hidden-input handling
is #1961's: the hidden grid
  still moves under the folded cursor row.
- **Pane menu**: a small `wideGrids` store, fed by the fold, lets the
tab's ⋯ sheet offer **Original
width** / **Wrap to screen** for such panes, as it already did for
mirrors. It uses the same device
setting (`terminalMirrorWrap`, key `ovis:mirror-wrap`), which is not
renamed, so choices already
  saved still apply. A driving phone's menu does not show the item.
- **Under the keyboard** the grid is not adopted, so its mount had
`overflow: hidden`. Every fold now
scrolls up and down, and a finger pans the folded rows before it scrolls
the pane at their edges.
- **Pane switch**: switching panes decides the fold again, so the menu
stops offering the width
  choice for the pane left behind.
- **Taps**: a tap on folded rows opens a link or focuses the terminal,
as on a mirror. It does not
send a mouse click to the program. herdr's attach turns on mouse
reporting for every pane
(`?1000h ?1002h ?1003h ?1006h`, seen on a plain bash pane and on btop),
so the client cannot tell
which program wants clicks. Original width still passes clicks through.
DESIGN.md says so.

**Design precedent:** the same as #1961. The apps this repo compares
against size their terminal to
the window, which a watching device cannot do. This follows Collie
(AltanS/collie,
`ansi-output.tsx`), which never resizes a pane. No code was copied.
DESIGN.md extends #1961's entry.

## Validation

`scripts/mirror-fold-demo-regression.ts` (browser lane) now covers an
attached pane whose pty grid
(120x40) is wider than the phone. The fixture replays herdr's mouse
modes, as a real attach does.

- **Driving:** the grid is the phone's own and fitted, nothing is
folded, and the menu has no
  Original width.
- **Watching:** folded whole at 390, 412, 915x412 and 844x390. The
folded rows are the stream's rows
  in order, and the Korean words fold whole.
- **Toggle:** the menu offers Original width. Original width shows a
btop-like box at full width,
and **real swipes** pan it to its right edge. Wrap to screen folds it
again. Both choices are kept
  in `ovis:mirror-wrap`.
- **Back to driving:** the grid is fitted again and unfolded.
- **Under the keyboard at another device's grid:** folded, cursor row in
view, a Korean preedit
drawn over the folded rows, panned by wheel and by swipe. Once the
keyboard goes, the catch-up fit
  unfolds it.

What fails without the change:

- On origin/main the script fails at `foldState(watching)`:
`{"folded":false}`.
- Each mutation of the change fails at the assertion that names it:
dropping the keyboard case,
showing the menu item only for mirrors, gating the keyboard fold on "no
mouse reporting", and the
first commit without the scroll fixes (`scrollTop` stuck under the
keyboard).
- All of #1961's mirror assertions still pass, including the
preedit-topmost check.

Other checks:

- `src/lib/terminalFold.test.ts`: the `wideGrids` store keeps a pane
wide while any terminal that
  draws it says so.
- `bun run check fast` is green on a091b37 (unit tests: 7176 pass, 0
fail).

Real apps were run against an isolated test herdr (`bun run check run`)
with an omp-like pane (long
Korean lines, a status box) and btop. A 1700 px desktop client held the
pane at 174x53. The phone was
a device paired to watch: the server reported `via: device, role:
watch`. "Before" is an origin/main
server and "after" is this branch's.

| Device | origin/main | This branch |
|---|---|---|
| Headless Chrome, watching, 390x844, 412x915, 915x412, 844x390 | 174
columns, every row end cut, 1365 px to pan | folded, every row end in
view, nothing to pan sideways |
| Android app 1.0 (3), WebView 145, 412x915 dp portrait and 957x411
landscape, watching | omp and btop cut off | folded. A real tap on the
tab ⋯ opens Original width; an adb swipe pans it (scrollLeft 535); Wrap
to screen folds it again |
| Android app, driving with the keyboard up, then the desktop takes the
pty back | the desktop's 174 columns, cut off | folded. Text typed with
adb reaches the pane and shows in the fold. With the keyboard gone the
phone takes the pane back at 50x49, unfolded |
| iOS Simulator app (built from main), iPhone 17e, watching | - | folded
|
| Headless Chrome, driving, 412x915 | redrawn at 50 columns | the same:
50x44, not folded, no menu item |

Screenshots and the Korean summary for the maintainer (tailnet):
http://100.123.228.51:7593/

## Reviews

An `omo-native-code-reviewer` pass approved with notes, and a Codex
(gpt-6.1-sol, xhigh) pass ran on
the first commit. Neither found anything HIGH.

| Finding | Resolution |
|---|---|
| Codex MEDIUM: a keyboard-held fold kept `overflow: hidden`, so a wheel
could not pan it | overflow-y on every fold; the regression wheels it,
and the first commit fails there |
| Codex MEDIUM: a touch on a keyboard-held fold scrolled the pane
instead of panning the folded rows | a touch pans the folded rows up to
their edges first; covered by a real swipe |
| Codex LOW: "pans sideways" set `scrollLeft` directly | real swipes and
wheels |
| Reviewer MEDIUM: a keyboard-held fold eats taps meant for a mouse
program | tried gating on mouse reporting. The real Android app then
showed that herdr's attach reports the mouse for every pane, so the gate
turned the fold off everywhere. Reverted and documented as a trade-off
(Original width keeps clicks); the fixture now replays herdr's modes,
and the gate makes the script fail |
| Reviewer MEDIUM: the first "driving is never folded" checks only test
the fit | relabelled as fit checks; driving→unfolded is covered after
watching and after the keyboard |
| Reviewer LOW: stale `wideGrids` key after a pane switch; comments; the
geometry push before the keyboard step; try/finally in the unit test |
fixed |

## Known limits

- A line the PC program already wrapped at the pane's width folds again
(as in #1961 and Collie).
- A full-screen TUI is hard to read folded. Original width is there for
it.
- The iOS Simulator runs headless on the test MacBook Air, with no taps
or rotation, so iOS was
  checked in portrait only. Android covered the toggle and landscape.

---------

Co-authored-by: mp <mp@local>
devswha added a commit that referenced this pull request Oct 28, 2026
Refs #1537 (item 2; item 1 was fixed by #1749).

## Change

- **`.github/workflows/windows-terminal-qa.yml`** runs
`scripts/windows-terminal-browser-qa.ts`, the native Windows
mirrored-terminal check (PowerShell history under the wheel, touch drag
and tap, horizontal panning across output, text and IME input at a
phone's width), which ran in no workflow:
- GitHub-hosted `windows-latest` only, `contents: read`, no secrets: a
fork's PR never reaches the self-hosted runners.
- herdr 0.9.3 from its release zip, checked against a pinned SHA-256
(CI's herdr everywhere else); Bun through `./.github/actions/setup-ci`;
the lockfile's Playwright Chromium (cached).
  - Every external action pinned by commit SHA, like the rest.
- Runs on PRs that touch the mirror, the terminal components,
gesture/viewport helpers, settings, the xterm patch or `setup-ci`;
weekly on main; and on a manual dispatch. Not a required check. The test
herdr's log is kept as an artifact when it fails.
- **The script itself was broken on current main**: since #1961 a
mirrored pane wider than a phone folds to the screen by default, so its
390 px panning steps had nothing to pan. It now picks Original width
(`ovis:mirror-wrap` = false) before loading, and waits until the grid
overflows before panning, so a folded grid fails with that message
instead of a 15 s timeout.
- **Two more script fixes the first runner runs found**: cleanup no
longer replaces the run's own error (the closed pane's PowerShell holds
the test folder for a moment: EBUSY, now waited for, bounded at 15 s),
and the IME edge check places its caret by the measured cell width
instead of a fixed 52 columns, which on the runner's font put the caret
cell across the phone's edge (the xterm patch rightly treats a cut cell
as off screen).
- `docs/development.md`, the script's header, `ci-browser.test.ts`'s
manual-list comment and a changelog fragment say where it runs.

## Not changed (items 3-5 of #1537)

- **3, hidden pane gets a 1 px textarea width**: only when the host has
no box (`display: none` or zero size), where nothing can be typed. Panes
the canvas hides use `visibility: hidden` (`PaneCanvas.css:24`), keep
their box and get real bounds; the `.xterm-screen` ResizeObserver
resyncs when a box returns. No observable defect found.
- **4, the bounds type written inline in the xterm patch**: a tidy-up
with no behaviour change; left out to keep this PR to the workflow.
- **5, a layout read per host scroll event while bounds apply**:
scrolling leaves layout clean, so the read does not force a reflow; only
a scroll during composition does. Not measured; no defect found.

## Verification

- **Windows terminal QA green on 5f80b63, all four PASS lines:
https://github.com/devswha/ovis/actions/runs/40647753903** (and on
ef4c78d: https://github.com/devswha/ovis/actions/runs/40646709409).
Earlier runs on this PR (40645679178, 40646211178) failed on the two
script issues above. The same script also passed 4/4 on the maintainer's
Windows 11 PC in a fresh clone.
- `bun run check fast` green on 953e43f and again on ef4c78d (workflow
syntax/actionlint, typecheck, build, unit tests, incl.
`scripts/ci-setup.test.ts` pin checks).
- Reviews: omo-native-code-reviewer PASS on 2dd4acd (MEDIUM: trigger
list too narrow - fixed in 953e43f; MEDIUM: workflow not yet run - this
PR's run). Codex Sol 6.1 Fast xhigh BLOCK on 2dd4acd (HIGH: the mirror
fold above; MEDIUM: trigger list) - both fixed in 953e43f; its
re-review of 953e43f: PASS; its review of the two script fixes
(953e43f..ef4c78d): PASS.

## Merge

This changes `.github/workflows`: **the merge waits for the owner's
go**, which Dori will ask for with this PR's link.
devswha added a commit that referenced this pull request Oct 29, 2026
…ith main (#2253)

Fixes the **Native Windows mirrored terminal** check
(`windows-terminal-qa.yml`, from #2211) failing on #2243 and #2242 at
`Timed out: new native output after wheel pan` (and an `EBUSY` that hid
the error), while it passed on #2246.

## Root cause

The workflow checked out `github.event.pull_request.head.sha`. A branch
cut before #2211 (524273e) ran **its own old copy** of
`scripts/windows-terminal-browser-qa.ts`, against an app that already
folds a wide mirrored pane to a phone's width (#1961). #2211 fixed that
script in four places: it chooses Original width (`ovis:mirror-wrap` =
false), waits for the grid to overflow, places the IME caret by the
measured cell width, and retries the EBUSY cleanup. The old copy still
has all of them. #2243 (base b48c66a) and #2242 (base 615c92b) predate
#2211; #2246 (base 84824f1) does not. The workflow file itself comes
from the merge ref, so the job ran on those PRs anyway. Nothing in the
product is wrong: the failing PRs tested a stale script.

## Change

- `windows-terminal-qa.yml` checks out `${{ github.sha }}`: the pull
request's merge with its base, as every job in `ci.yml` does. Schedule
and dispatch runs are unchanged (they already fell back to
`github.sha`). `windows-install.yml` keeps the head SHA for its own
reason (`install.ps1 -Ref` must name the checked-out commit); this
workflow builds and runs the checkout in place.
- `scripts/ci-setup.test.ts`: the QA job's checkout ref must be `${{
github.sha }}`. It fails on main (`Received: "${{
github.event.pull_request.head.sha || github.sha }}"`) and passes with
the change.
- `docs/development.md` and a changelog fragment say so.

## Verification

Native Windows 11 VM (`winvm`, herdr 0.9.3, Bun 1.4.2), fresh `%TEMP%`
clones, through `dori heavy`:

| Checkout | Script | Result |
| --- | --- | --- |
| #2243 head 457f187 | its own (pre-#2211), plus diagnostics | **0/3**:
all time out at `new native output after wheel pan` (one hides it behind
EBUSY, as on #2242). Diagnostics: herdr's pane shows `PPP…> Q`, while
the host has `scrollWidth 390 == clientWidth 390`, so the grid is
folded, not at Original width |
| #2243 head 457f187 | its own plus only `ovis:mirror-wrap = false` |
wheel-pan step **3/3 PASS**; then each run fails at `a visible cursor
keeps its composition anchor`, the fixed-52-column bug #2211 also fixed
|
| `refs/pull/2243/merge` 3493d80 (what this workflow now checks out) |
current | **3/3 PASS**, all four PASS lines |
| main 5c20a88 | current | **10/10 PASS** in a row, all four PASS lines
each |

- GitHub runner, all green with four PASS lines:
- this PR's own run, which checked out `Merge d1bea76 into adfdef6`
(7e74dbd), i.e. the merge:
https://github.com/devswha/ovis/actions/runs/40688443672
- a manual dispatch on this branch:
https://github.com/devswha/ovis/actions/runs/40688514345
- a manual dispatch on main adfdef6:
https://github.com/devswha/ovis/actions/runs/40688525315
- `bun run check fast` green (workflow syntax/actionlint, typecheck,
build, unit tests: 8163 pass, 0 fail) on this head, d1bea76.

## Reviews

- omo-native-code-reviewer: **PASS**, no CRITICAL/HIGH/MEDIUM. LOW
notes, left as is: "Re-run jobs" reuses the original merge commit (as in
`ci.yml`; a push or reopen picks up a newer base); "merge with main" is
strictly the merge with the base branch (PRs here target main); the
test's `!` would throw a TypeError instead of a clean failure if the
checkout step were removed, as in its neighbours.
- Codex Sol 6.1 Fast xhigh: **PASS**, no findings. Its note: the step
still depends on echo and mirror delivery within 15 s, so the same
timeout label on a current-base PR would be a new cause (a real
regression or a starved runner), not this one.
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