Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): let terminal programs copy with OSC 52 #25051

Closedmaria-rckswants to merge 2 commits intomain frommaria/takeover-pr-22470opened View on GitHub

maria-rckscommented

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:changed passed 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 printf followed by composer paste produced old clipboard on main and osc52 works with 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 244bd4fb31 with 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.

main: terminal OSC 52 leaves the old clipboard in the composer

fix: the same command pastes osc52 works into the composer

terminal OSC 52 copying and composer paste in Chrome

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. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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 44df3360165ba96a6902496812feca2b60c7fcc9 and 244bd4fb31d927823edaaa4027854e4db657dfde.

      Files selected for processing: 4
      • apps/web/src/components/ThreadTerminalDrawer.tsx
      • apps/web/src/terminal/ghostty/osc52.ts
      • apps/web/src/terminal/ghostty/surface.test.ts
      • apps/web/src/terminal/ghostty/surface.ts

      Included 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

      Layer / File(s)Summary
      OSC 52 scanning and decoding
      apps/web/src/terminal/ghostty/osc52.ts
      Adds a stateful scanner for OSC 52 writes across terminal output chunks. It validates selections and decoded text, recognizes BEL and ST terminators, handles cancellation, and discards bodies over 1 MiB.
      Surface integration and validation
      apps/web/src/terminal/ghostty/surface.ts, apps/web/src/terminal/ghostty/surface.test.ts
      Adds the optional clipboard callback. The surface scans only when a callback is configured and forwards decoded text only when focused, visible, and the document has focus. Tests cover fragmented, malformed, cancelled, and oversized sequences.
      Drawer clipboard handling
      apps/web/src/components/ThreadTerminalDrawer.tsx
      Adds clipboard copying with an error toast on failure and connects the handler to the terminal surface.
      Priority: Normal

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant GhosttyTerminalSurface
        participant Osc52Scanner
        participant ThreadTerminalDrawer
        participant Clipboard
        GhosttyTerminalSurface->>Osc52Scanner: Scan terminal output
        Osc52Scanner-->>GhosttyTerminalSurface: Return decoded clipboard text
        GhosttyTerminalSurface->>ThreadTerminalDrawer: Invoke callback when focused and visible
        ThreadTerminalDrawer->>Clipboard: Copy text
        Clipboard-->>ThreadTerminalDrawer: Return copy failure for error toast

      Possibly related issues

      • pingdotgg/t3code#8361: Reports that terminal-initiated OSC 52 writes leave the clipboard unchanged; this change adds OSC 52 clipboard-write handling to the Ghostty terminal surface.

      Possibly related PRs

      • pingdotgg/t3code#23819: Both changes process OSC 52 terminal output, including chunked sequences; that PR addresses server sanitization, while this one handles browser clipboard writes.

      Suggested reviewers: t3dotgg, juliusmarminge

      Merge Risk: Minimal · up to 244bd

      Terminal-program clipboard writes appear ready to merge after normal checks. Clipboard permission failures are handled with an error toast.

      Pre-merge checks: Passed 3 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Description checkWarningThe 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 concr…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…
      Passed Passed checks: 3 passed
      Check nameStatusExplanation
      Title checkPassedThe title is concise, specific, and accurately describes the primary change: enabling terminal programs to copy through OSC 52.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      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 #22470 and 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 #22470 was the prior attempt and link the maintainer approval for the takeover if one exists.

      Finishing Touches
      📝 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
      Comment `@coderabbitai help` to get the list of available commands.
    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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 244bd4f. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Thread transfer impact

      ⚠️ The latest CI run did not produce a thread transfer result for aecd962.

      This comment will update automatically after the next completed run.

    4. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      Verified unchanged head 244bd4fb31d927823edaaa4027854e4db657dfde on 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 and vp i / background vp run dev.
      • Used the repository's Playwright with /usr/bin/google-chrome against the real dev web app. Added /home/user/t3code through Add project, created threads, selected Codex gpt-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 pasted osc52 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 sentinel unchanged. Reloading/reconnecting and focusing the terminal left history sentinel unchanged. A focused Unicode write with an ST terminator copied hé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.ts passed 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.

      main: OSC 52 leaves old clipboard in the composer

      PR: the same terminal command pastes osc52 verified

      PR: live terminal OSC 52 copy followed by composer paste

      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 /copy were 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.

    5. 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.

    6. juliusmarminge closed this

Sign in to join this conversation.