Repository navigation
fix(terminal): let a terminal app's OSC 52 copy reach the clipboard in iOS Safari - #2925
Conversation
…OSC 52 copy lands in iOS Safari Safari writes the clipboard only within a user gesture, and a pane program's OSC 52 answers the click a round trip later. The click forwarded to a mouse-reporting program now starts navigator.clipboard.write with a pending ClipboardItem, and the next valid live OSC 52 of that pane fills it within 1 s; otherwise it is given up and the clipboard is left alone.
…ame after it Only frames received after the click can fill its reservation; a selection, observing, disabled stdin or a newer press cancels or prevents it; an OpenCode press arms one too; a reserved write that fails is not retried outside the click.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 22 minutes. View limit details
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. |
…ite; a newer press cancels it An OSC opened in a frame before the click and ended after it no longer fills the reservation, an older copy leaves the reservation waiting instead of cancelling it, and any new press in the terminal cancels the last click's pending write.
|
Review notes (Codex adversarial review, gpt-6.1-terra xhigh, two passes) Pass 1 (on 4812638), all fixed in e076a49:
Pass 2 (on e076a49), the one fix round in 4cfbee4:
Real-device runs on the final code (4cfbee4 build, 3308540 only merges main): see the PR body; updated there when the run completes. |
Deploying ovis with
|
| Latest commit: |
3308540
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://370dd465.ovis.pages.dev |
| Branch Preview URL: | https://fix-osc52-safari-gesture.ovis.pages.dev |
|
Local merge gate (owner-approved): |
…#2976) ## What Settings > Terminal > Draw with libghostty (#2908) is on by default. - It still only draws on a herdr-core server (`terminal-history`, as the desktop app runs); on herdr and mirrored panes xterm.js draws exactly as before. - The setting stays, per device. A device that turned it off stays off: a stored `false` is kept, only a missing or invalid value means on. Note: since #2908 every settings save writes this key, so a device that saved any setting on a main build after #2908 also has `false` stored and stays off; released versions never had the key, so their users get the new default. ## Gates (step 1 checklist, measured on isolated hc 0.1.17 + this stack) | Gate | Result | |---|---| | Phone first load (slow 4G 1.6 Mbps/150 ms, CPU x4, fresh profile, median of 5) | off 7,510 ms / on 7,918 ms: +408 ms, within +0.5 s (wasm served br since #2953: 1.11 MB -> 345 KB, re-open fetches no wasm) | | Low-end phone frames (CPU x6, `seq 1 200000`, ABBA) | after #2959 on is at or below off: median finish 10.5 s vs 10.8 s, stalls > 50 ms 4 vs 7 | | Screen reader (real NVDA 2026.2, Windows 11 VM, Edge 156) | on: NVDA reads new output; off (xterm, screen reader mode off): reads nothing. Known follow-ups in #2963 | | iOS long-press copy (iOS 27 Simulator, Safari) | **provisionally equal**: neither xterm nor libghostty shows a selection/copy menu on a 1.6 s long-press (driven with simctl + AXe touch). Pending one manual check once Simulator components are installed on the test Mac. Copy keeps working through the key bar's copy button and OSC 52 (#2925) | ## Validation - `bun test src/lib/settings`: pass (the two tests that pinned the old default now pin the new one: missing/invalid means on, a stored `false` stays off, the key stays out of the whole-record save). - `bun scripts/terminal-ghostty-demo-regression.ts`: pass (herdr-core pane drawn with libghostty, herdr's own and off stay xterm). - `bun run check fast`: pass (exit 0) on this head
… which selects and scrolls its own history (#2384) (#3126) ## Change A new per-device setting, off by default: **Settings > Terminal > Experimental > Codex panes: let Codex select and scroll** (`codexDrag`). With it on, a plain drag in a Codex pane goes to Codex, the way it already does in an OpenCode pane (#2368). Codex selects through its whole history, keeps scrolling that history while the drag is held past the top or bottom edge, and copies the selection on Ctrl+C or Enter. With it off, which is the default, every pane behaves exactly as on main. With the setting on: - Shift+drag (Option+drag on a Mac) still makes Ovis's own selection, which copies on release and offers **Quote in message**, as before. - On herdr, a note appears where the drag ended: "Codex selected this: Shift+drag copies or quotes it here" ("Option+drag" on a Mac). herdr drops Codex's copy (OSC 52), and Ovis cannot read Codex's selection to quote it, so the note names the way that does both. - On herdr-core, Codex's OSC 52 copy reaches the page, so no note appears. This was checked with a real Codex 0.167 through Ovis on hc 0.1.14 in headless Chrome: after a drag, Ctrl+C sent Codex's OSC 52, and the selected rows landed on the browser clipboard. - The note appears only after a press that left its cell (a drag), never after a click. It is shown in the current language. Every other pane, and links, observe mode, a held pane and touch, keep their paths. Refs #2384. The default stays main's behaviour, so this does not close the issue for everyone. Thanks @matiemer for the report and the alternate-screen diagnosis. ## Why a setting Checked on herdr 0.9.5 in an isolated session: - herdr reports no scroll history for a program on the alternate screen. A shell after `seq 1 500` reports `max_offset_from_bottom: 462`; after `ESC[?1049h`, it reports `0`. Ovis's own edge scroll (#634) moves herdr's viewport, so it has nothing to move there. - Codex (0.166.0 in a raw pty, and 0.167.0 through Ovis) runs on the alternate screen with `?1000/1002/1003/1006`. It selects a drag on its own and scrolls its transcript while the drag is held at the top row. Through Ovis on herdr with this branch, a real Codex pane scrolled up to the start of `seq`'s output while the drag was held still past the top edge. - Codex copies only with OSC 52, and herdr's attach drops OSC 52: a shell's `printf '\033]52;c;…\a'` left the browser clipboard unchanged. Handing every Codex drag to Codex would turn the most common copy on herdr into one that silently does nothing on another device. Reviewers flagged that on the first version of this PR, so the hand-over is opt-in. - Claude Code (2.1.318) runs on the main screen without mouse reporting, and its herdr pane keeps its history (`max_offset_from_bottom: 134`). Ovis's existing edge scroll covers it, so it is not changed here. - herdr reports which agent runs, never a program's mouse mode, so the rule keys on the reported agent, as the OpenCode one does. Design reference: the xterm.js / VS Code / iTerm2 convention, already followed for OpenCode. A program that reads the mouse gets the drag, and Shift (Option on macOS) forces the terminal's own selection. Rebuilding Codex's history inside Ovis from wheel reports was rejected: it would mean guessing, from screen text, how far Codex had scrolled. ## Known limit (follow-up #3128) On herdr-core, the drag reaches Codex, and Ctrl+C's OSC 52 copy reaches the browser clipboard (checked with a real Codex through Ovis on hc 0.1.14). The edge scroll does not happen there yet. While the drag is held, the pane's stream delivers `ESC[!p` with the mouse and focus modes off, plus colour and DA queries, two or three times, and Codex stops scrolling. The same reports sent through `hc attach` in a pty do scroll, so this is filed as #3128 with the frames. ## Tests - New `scripts/codex-drag-demo-regression.ts` (demo fixtures, no herdr or hc), run against both a herdr server and a herdr-core server, with the setting off and on: - Off: a plain drag is Ovis's selection, Codex reads no press or release, and no note appears. This is main's behaviour. - On: press, motions and release reach Codex in order, and Ovis selects nothing. On herdr the Shift+drag note shows; on herdr-core it does not. Shift (Option on a Mac)+drag still makes Ovis's selection and sends Codex no press, and a plain drag after it is Codex's again and clears that selection. - With origin/main's `useTerminalMount.ts`, the "on" cases fail: `herdr, Codex panes on: the drag never reached Codex`. - `src/lib/settings.test.ts`: `codexDrag` defaults to off, accepts only a boolean `true`, and is device-scoped, not shared. - Translations (ko, ja, zh) for the row and both notes. `src/lib/i18n.test.ts` passes. ## Screenshots Taken from the demo build: the Settings row at 1280 and 390, light and dark, and the herdr note after a drag. The images are attached to the lane report. ## Validation - `bun run check fast` at this head: ok, with 12617 unit tests passing. - In the CI runner image (`herdr-ci-runner:local`): `codex-drag-demo-regression.ts`, `settings-pages-demo-regression.ts`, `terminal-arrows-clicks-regression.ts`, `terminal-copy-regression.ts` and `terminal-copy-off-regression.ts`. - Not run: the full integration and browser suites. ## Reviews - First version (`51f39ba5`, hand-over always on): omo BLOCK and Codex Terra (xhigh) 4×MEDIUM, all about the same point: on herdr, a plain drag in a Codex pane would no longer copy on another device. The lead chose an opt-in setting with the note. That is this head. - Fix round on `501d43ba`: - Codex Terra LOWs, fixed: a blur now forgets the program's press, so a later click gets no stale note; the note follows a press that left its cell, not just press-versus-release cells; and it takes the current language (`tRef`). - omo LOW, fixed: the Shift/Option+drag case is now in the regression. - omo MEDIUM: this PR body described the first version. It is rewritten here, and `Fixes` became `Refs`. - Left as known limits, not changed: - Codex Terra MEDIUM, Safari on herdr-core: Codex copies on Ctrl+C or Enter, not on release, so the 1 s clipboard reservation a release starts (#2925) has expired by then. Desktop Chrome writes the clipboard without it (checked above); Safari may refuse. Shift/Option+drag stays the copy that works everywhere. - Edge scroll on herdr-core: #3128.
Fixes #1620
What
A terminal app that reads the mouse copies by sending OSC 52 after its Copy button is clicked. iOS Safari writes the clipboard only during a user gesture, and the OSC 52 comes back a round trip after the tap ended, so
navigator.clipboard.writeTextwas refused ("clipboard write blocked by the browser") and nothing was copied.Now the click Ovis hands to the program starts the clipboard write itself:
navigator.clipboard.writewith aClipboardItemwhosetext/plainis still a promise (src/lib/osc52Clipboard.ts). The next valid live OSC 52 from that pane fills it in. Nothing filling it within 1 s, or a cancel, rejects the promise, and the clipboard keeps what it had.forwardClickpath, which already requires no selection and the same pane, plus an OpenCode press, which xterm reports as is), with Settings > pane clipboard on, and the pane neither observed, held nor with stdin disabled. One reservation at a time; a newer click replaces it.retireOutput), unmount, a selection being made, a switch to observing, and when the copy arrives for another pane or output.c;?) and oversized OSC 52 never fill it (the existing replay-provenance andparseOsc52checks run first).ClipboardItem), the existingwriteTextpath is unchanged. A reserved write that fails is not retried later (that would be a write outside the click).Why now
The issue's first measurement found that herdr 0.9.5's attach stream drops OSC 52 entirely (herdrdev/herdr#4612). herdr-core (
hc0.1.17) forwards it onterminal.attach(checked on an isolated core: both BEL and ST forms arrive), so on a herdr-core server the gesture limit is what blocks the copy.Evidence (real browsers, real input, real clipboard)
Setup: Ovis server from this branch / from main on 127.0.0.1 with
OVIS_RUNTIME=herdr-coreon an isolated hc 0.1.17 core (ownHC_SESSION, XDG dirs, socket, mktemp state), reached from the test MacBook Air through an ssh reverse tunnel (localhost = secure context). Fixture pane: SGR mouse reporting on, every left release sendsESC ] 52 ; c ; base64("OVIS1620-<run>-<n>-<ms>") BELand logs it.pbpasteNegative cases on this branch, clipboard preseeded before each try (3 tries per case per browser):
c;!!!not-base64!!!)c;?)writeTextpath that main already uses (macOS Safari accepts it without a gesture)Replayed output, Settings off, observing, a selection, and a pane switch or reconnect follow the code paths listed above; the replay-provenance browser regression (
scripts/replay-clipboard-demo-regression.ts) covers the replay part unchanged.Note: on iOS one tap reaches the program as two releases (already seen in the issue), so the fixture sends two payloads per tap; the first fills the reservation and the second takes the old path, whose refusal shows the "blocked" note although the copy landed. That double release is pre-existing and left for a follow-up.
Validation
bun run check fastat 3308540 (contains origin/main): pass (typecheck, build, 11819 unit tests).bun test src/lib/osc52Clipboard.test.ts src/lib/osc52.test.ts: pass; the new test file fails withoutosc52Clipboard.ts.bun scripts/replay-clipboard-demo-regression.ts: pass (replayed OSC 52 still never writes; live copies still once each).bun run check full(CI runs it).Design reference: a native terminal (iTerm2, Ghostty) writes the system clipboard on OSC 52 directly; a browser cannot without a gesture, so this follows the issue's proposal of a gesture-started write with a promised
ClipboardItemrather than any app's after-the-fact fallback.