fix(web): let terminal programs copy with OSC 52 #25051
Problem#
Terminal programs send OSC 52 to copy text, but T3 ignored it and left the previous clipboard contents in place.
Change#
Reuse @SunkenInTime's bounded streaming scanner for write-only OSC 52 support in the thread terminal. Copies require a focused terminal, visible surface, and focused browser window; history replay resets the scanner without copying. Clipboard failures use the existing error toast. Web and desktop share this path; provider sign-in terminals and native mobile are unchanged.
Coverage stays in the existing surface test file. No new test files or dependencies.
Verification#
- Regression test failed on main before the fix. Blacksmith on merge head:
vp run check:changedpassed format, lint, both knip checks, affected typechecks and all 34 adjacent tests. The earlier surface/core run passed 46 tests. - System Chrome, real dev server and terminal: the same
printffollowed by composer paste producedold clipboardon main andosc52 workswith this branch. Unfocused live output and reconnect history left the clipboard unchanged. - All 31 CI checks passed on merge head
244bd4fb31, including lint, build/typecheck and web/server tests. Macroscope still flags the clipboard side effect and VT-control regex lint suppression for human review. - Two independent GPT-6.1-Sol follow-up source reviews approved merge head
244bd4fb31with no findings. The automatic CodeRabbit review reported no actionable comments. - Unverified: Safari, Electron, native mobile, and the emitting programs themselves (tmux, Vim, Claude
/copy). Browser permission or secure-context restrictions can reject writes and report an error. The existing 512 KiB output buffer can trim very large copies/bursts before parsing; the scanner itself caps buffered OSC bodies at 1 MiB. Clipboard reads are never answered.



Takeover#
Replaces #22470, with thanks to @SunkenInTime for the original implementation.
Built with GPT-6.1-Sol in the Codex harness on T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This PR adds OSC 52 parsing and automatic clipboard writes to the live web terminal, including a new stateful scanner and browser clipboard integration. It also introduces a line-level lint suppression, so the production behavior and static-analysis exception warrant human review.
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).244bd4f. Prior analysis still applies.Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
Verified unchanged head
244bd4fb31d927823edaaa4027854e4db657dfdeon a disposable Linux Boat VM. No code changes or pushes were needed.- Installed and ran
github/main(a4e1986585) in/home/user/main, reproduced the bug, then stopped that captured server process before starting the exact PR head. Both used isolated state andvp i/ backgroundvp run dev. - Used the repository's Playwright with
/usr/bin/google-chromeagainst the real dev web app. Added/home/user/t3codethrough Add project, created threads, selected Codexgpt-6.1-sol, and completed real provider turns on both revisions. No mocks, fixtures, replay provider, or demo data. - In the thread terminal, sent the same OSC 52 sequence below. On main, Ctrl+V in the composer pasted
old clipboard. On this head, it pastedosc52 verified. Browser clipboard permission was granted; the actual OS/browser clipboard was read and pasted, without replacing the clipboard API. - Delayed live output while the composer held focus left
unfocused sentinelunchanged. Reloading/reconnecting and focusing the terminal lefthistory sentinelunchanged. A focused Unicode write with an ST terminator copiedhéllo 👋. Normal terminal command execution, output, composer paste, and Codex responses remained usable. - Blacksmith:
vp test run apps/web/src/terminal/ghostty/surface.test.ts apps/web/src/terminal/ghostty/core.test.tspassed all 47 tests. Existing head CI reports 31 successful, 0 failing, 0 pending. These supplement the live checks above.
Command and observed results:
printf '\033]52;c;b3NjNTIgdmVyaWZpZWQ=\007'; echo 'OSC 52 sent' # main: clipboard and composer paste = old clipboard # PR: clipboard and composer paste = osc52 verified # unfocused output: unchanged # reconnect/history replay: unchanged # Unicode + ST: héllo 👋Inspected both screenshots and the full 7-second recording. Verified uploaded images match the inspected files and uploaded video playback/seeking in T3's browser.



Not verified#
Electron/native desktop, macOS/Windows, iOS/Android, Safari/Firefox, remote/relay/tunnel connections, denied clipboard permissions, large-output limits, and specific emitting programs such as tmux/Vim/Claude
/copywere not exercised. This Linux pass covers the web thread-terminal path using real shell output and real Codex threads. Provider sign-in terminals and native mobile are outside this diff. No merge, rebase, force-push, label change, or other PR modification was performed.- Installed and ran
Thanks @maria-rcks. This is carried forward in pingdotgg/t3code#25243, which keeps your bounded OSC 52 scanner and wires it into the thread terminal with focus gating and regression tests. Closing this one in favour of that PR.
juliusmarminge closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review.
30d1a9af-947c-4422-9298-1a9c1b46b5c6Reviewing files that changed from the base of the PR and between 44df3360165ba96a6902496812feca2b60c7fcc9 and 244bd4fb31d927823edaaa4027854e4db657dfde.
apps/web/src/components/ThreadTerminalDrawer.tsxapps/web/src/terminal/ghostty/osc52.tsapps/web/src/terminal/ghostty/surface.test.tsapps/web/src/terminal/ghostty/surface.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Walkthrough
The terminal surface now scans output for OSC 52 clipboard writes. It forwards valid decoded text to a clipboard handler only when the surface and document are focused and the surface is visible.
Changes: OSC 52 Clipboard Writes
apps/web/src/terminal/ghostty/osc52.tsapps/web/src/terminal/ghostty/surface.ts,apps/web/src/terminal/ghostty/surface.test.tsapps/web/src/components/ThreadTerminalDrawer.tsxEstimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)#
Possibly related issues
Possibly related PRs
Suggested reviewers:
t3dotgg,juliusmarmingeMerge Risk:
Minimal · up to
244bdTerminal-program clipboard writes appear ready to merge after normal checks. Clipboard permission failures are handled with an error toast.
Pre-merge checks:
3 · 
1
Full details: Description check
Explanation
The description follows the template's Problem, Change, and Verification sections with substantive content. The Problem and Change sections are clear and specific. The Verification section lists concrete tests, CI results, a manual Chrome check with observed output, and unverified areas, and it includes before/after screenshots and a recording. The Scope and approval section is missing. It does not link a triaged bug issue or maintainer-approved discussion. It also does not explain why the change qualifies as a small, obvious bug fix without a prior issue. The description instead says it replaces
#22470and credits its original author, but that is not the approval evidence the template asks for. The description also includes a note on the model and harness, which the template asks for.Resolution
Add a Scope and approval section. Link the triaged bug issue or the discussion where a maintainer approved the direction and scope, and include the approval comment. If no prior issue exists, explain why this is a very small, focused fix of an obvious bug that qualifies without prior approval. Also note that
#22470was the prior attempt and link the maintainer approval for the takeover if one exists.Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.