Skip to content

fix(tui): improve clipboard copy fallbacks#15963

Closed
bjianhang wants to merge 1 commit into
NousResearch:mainfrom
bjianhang:pr/tui-clipboard-copy-fallback
Closed

fix(tui): improve clipboard copy fallbacks#15963
bjianhang wants to merge 1 commit into
NousResearch:mainfrom
bjianhang:pr/tui-clipboard-copy-fallback

Conversation

@bjianhang

Copy link
Copy Markdown
Contributor

Summary

  • add native clipboard write fallbacks for Windows, WSL, Wayland, and X11 before falling back to OSC52
  • update /copy to prefer native clipboard writes and show clearer status messages
  • cover the new backend order and fallback behavior in clipboard tests

Problem

In the TUI, /copy currently relies on OSC52 for assistant-message copies. That works in some terminals, but it often fails or feels broken in common setups such as Linux/X11, Wayland, Windows, and WSL, especially when terminal clipboard integration is disabled or partial.

What changed

  • writeClipboardText() now tries platform-native backends in order:
    • macOS: pbcopy
    • Windows: powershell Set-Clipboard
    • WSL / WSLg: powershell.exe Set-Clipboard
    • Wayland: wl-copy
    • X11: xclip, then xsel
  • /copy now:
    • keeps the existing in-terminal selection copy path unchanged
    • tries native clipboard write first for assistant-message copies
    • falls back to OSC52 only if no native backend succeeds
    • reports clearer user-facing status for success / fallback / empty history
  • WSL detection is aligned on both clipboard read and write paths with WSL_DISTRO_NAME

Verification

  • cd ui-tui && npm test -- src/__tests__/clipboard.test.ts src/__tests__/createSlashHandler.test.ts
  • cd ui-tui && npm test

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Apr 26, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #15856 — both add native clipboard fallbacks (pbcopy/wl-copy/xclip/xsel) when OSC 52 fails. Please coordinate to avoid merge conflicts.

@bjianhang

Copy link
Copy Markdown
Contributor Author

Thanks — I checked #15856 in detail.

This PR is not literally the same patch, but it does overlap in acceptance surface:

So the duplicate concern is understandable because both solve “OSC 52 alone is not enough; use native clipboard helpers too”, and both cover similar backend families (pbcopy, wl-copy, xclip, xsel).

The main differences in #15963 are:

  • TUI-specific implementation in ui-tui/src/lib/clipboard.ts
  • /copy integration in ui-tui/src/app/slash/commands/core.ts
  • WSL / WSLg handling (powershell.exe, WSL_DISTRO_NAME, WSLg ordering)
  • TUI-specific tests under ui-tui/src/__tests__/clipboard.test.ts

That said, I agree we should avoid landing two diverging clipboard fallback implementations if the maintainers prefer a unified direction. I’m happy to coordinate and either:

  1. keep this PR only if they want the TUI follow-up here, or
  2. close this PR and rebase the TUI-specific pieces onto fix(cli): /copy falls back to native clipboard on OSC 52-blind terminals #15856 / a follow-up if they prefer a single clipboard track.

I’ll wait for maintainer preference before pushing further changes here.

@teknium1

teknium1 commented May 5, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #20159 (#20159). Your commit was cherry-picked onto current main with authorship preserved via rebase-merge. Thanks for the fix — /copy now hits the real system clipboard on GNOME Terminal, Wayland, X11, WSL, and Windows instead of relying on OSC52 which VTE-based terminals don't support. Closes #18308.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants