Repository navigation
feat(terminal): opt-in OSC 52 clipboard writes from TUIs - #952
Merged
Merged
Conversation
xterm.js ships with no OSC 52 handler, so tmux, Neovim, fzf, and ripgrep running inside Orca — locally or over SSH — silently fail to copy to the system clipboard. Add an opt-in handler gated behind a new setting `terminalAllowOsc52Clipboard` (default off because untrusted output piped into the terminal can silently overwrite the clipboard). Implementation mirrors the DEC 2031 wiring from PR #896: extract parsing into a pure helper (parseOsc52) with a full unit-test suite, register the handler in onPaneCreated and dispose it symmetrically in onPaneClosed, and read the gate from settingsRef at fire time so the toggle takes effect without recreating panes. Clipboard *queries* (Pd = "?") are intentionally dropped — answering them would leak the user's clipboard to any process writing to the PTY — along with malformed payloads, oversized payloads (>128KB), and payloads using unknown selection letters.
3 of 4 tasks
nwparker
added a commit
that referenced
this pull request
Apr 22, 2026
…956) Wire the two escape sequences that TUIs and modern shells use to tell the terminal about state that xterm.js doesn't handle natively: - OSC 7 — shell emits its current working directory on every `cd`. - OSC 133 — FinalTerm / iTerm semantic prompt marks (A/B/C/D with optional exit code on D). Parsing lives in a new pure `shell-integration.ts` helper with 21 unit tests covering URI decoding, Windows UNC / drive-letter paths, all four OSC 133 letters, the `key=value` hint suffix some emitters append, and the ring-buffer cap on recorded marks. Wiring follows the DEC 2031 / OSC 52 pattern from #896 and #952: - Handlers registered per-pane in onPaneCreated, disposed symmetrically in onPaneClosed. - Two new refs (`paneCwdRef`, `paneSemanticMarksRef`) live on TerminalPane and are passed through UseTerminalPaneLifecycleDeps. - Semantic marks record the absolute buffer row (`baseY + cursorY`) so future block-navigation consumers can scroll to them. - A 10 000-entry ring buffer caps per-pane memory. Shipped consumer: the terminal context menu grows a platform-aware "Reveal in Finder / Show in Explorer / Open Folder" item that opens the shell's current directory in the native file manager. The item is hidden when no OSC 7 has been received, consistent with how other terminal emulators surface shell-integration-dependent features. No consumer yet for OSC 133 — recording is cheap and the consumer UX (block-nav keybinds, exit-code gutters) deserves its own design pass.
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
xterm.js ships with no OSC 52 handler, so tmux, Neovim, fzf, and ripgrep running inside Orca — locally or over SSH — silently fail to copy to the system clipboard. Add an opt-in handler gated behind a new setting `terminalAllowOsc52Clipboard` (default off because untrusted output piped into the terminal can silently overwrite the clipboard). Implementation mirrors the DEC 2031 wiring from PR stablyai#896: extract parsing into a pure helper (parseOsc52) with a full unit-test suite, register the handler in onPaneCreated and dispose it symmetrically in onPaneClosed, and read the gate from settingsRef at fire time so the toggle takes effect without recreating panes. Clipboard *queries* (Pd = "?") are intentionally dropped — answering them would leak the user's clipboard to any process writing to the PTY — along with malformed payloads, oversized payloads (>128KB), and payloads using unknown selection letters.
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…tablyai#956) Wire the two escape sequences that TUIs and modern shells use to tell the terminal about state that xterm.js doesn't handle natively: - OSC 7 — shell emits its current working directory on every `cd`. - OSC 133 — FinalTerm / iTerm semantic prompt marks (A/B/C/D with optional exit code on D). Parsing lives in a new pure `shell-integration.ts` helper with 21 unit tests covering URI decoding, Windows UNC / drive-letter paths, all four OSC 133 letters, the `key=value` hint suffix some emitters append, and the ring-buffer cap on recorded marks. Wiring follows the DEC 2031 / OSC 52 pattern from stablyai#896 and stablyai#952: - Handlers registered per-pane in onPaneCreated, disposed symmetrically in onPaneClosed. - Two new refs (`paneCwdRef`, `paneSemanticMarksRef`) live on TerminalPane and are passed through UseTerminalPaneLifecycleDeps. - Semantic marks record the absolute buffer row (`baseY + cursorY`) so future block-navigation consumers can scroll to them. - A 10 000-entry ring buffer caps per-pane memory. Shipped consumer: the terminal context menu grows a platform-aware "Reveal in Finder / Show in Explorer / Open Folder" item that opens the shell's current directory in the native file manager. The item is hidden when no OSC 7 has been received, consistent with how other terminal emulators surface shell-integration-dependent features. No consumer yet for OSC 133 — recording is cheap and the consumer UX (block-nav keybinds, exit-code gutters) deserves its own design pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
xterm.js doesn't ship an OSC 52 handler, so tmux, Neovim, fzf, and ripgrep running inside Orca — locally or over SSH — silently fail when they try to copy to the system clipboard. This is one of the most-requested workflows for users who SSH into remote hosts and expect "yank in vim, paste in my browser" to just work.
Add an opt-in handler gated behind a new setting
terminalAllowOsc52Clipboard(default off because OSC 52 is a classic data-exfil / clipboard-overwrite vector — piping an attacker-controlled log into the terminal could silently replace what the user has copied).Design
Mirrors the DEC 2031 wiring from #896:
osc52-clipboard.ts :: parseOsc52) with a full unit-test suite — no xterm dependency, no IPC, so it's trivially testable.onPaneCreated, disposed inonPaneClosedalongside the existing mode-2031 and selection disposables.settingsRef.currentat fire time so toggling it takes effect without recreating panes.OSC 52 ; c ; ?) are intentionally dropped — answering them would leak clipboard contents to any process writing to the PTY. Same for malformed payloads, unknown selection letters, and payloads over 128 KB.Files
src/shared/types.ts,src/shared/constants.ts— add setting.src/renderer/src/components/terminal-pane/osc52-clipboard.ts— pure parser.src/renderer/src/components/terminal-pane/osc52-clipboard.test.ts— 11 tests covering the happy path, multi-byte UTF-8, combined selectors, queries, whitespace tolerance, and all five invalid-payload cases.src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts— register + dispose.src/renderer/src/components/settings/TerminalPane.tsx— settings UI toggle with keywords for search.GlobalSettingsobjects still typecheck.Testing
pnpm lintpnpm typecheckosc52-clipboard.test.ts— 11/11 passing