diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 3a26e6cf..4d97bf3e 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - Added "none" option to `doubleEscapeAction` setting to disable double-escape behavior entirely ([#973](https://github.com/badlogic/pi-mono/issues/973) by [@juanibiapina](https://github.com/juanibiapina)) +- Added OSC 52 clipboard support for SSH/mosh sessions. `/copy` now works over remote connections. ([#1069](https://github.com/badlogic/pi-mono/issues/1069) by [@gturkoglu](https://github.com/gturkoglu)) ### Fixed diff --git a/packages/coding-agent/src/utils/clipboard.ts b/packages/coding-agent/src/utils/clipboard.ts index 33e5bc2c..edfe8944 100644 --- a/packages/coding-agent/src/utils/clipboard.ts +++ b/packages/coding-agent/src/utils/clipboard.ts @@ -3,6 +3,11 @@ import { platform } from "os"; import { isWaylandSession } from "./clipboard-image.js"; export function copyToClipboard(text: string): void { + // Always emit OSC 52 - works over SSH/mosh, harmless locally + const encoded = Buffer.from(text).toString("base64"); + process.stdout.write(`\x1b]52;c;${encoded}\x07`); + + // Also try native tools (best effort for local sessions) const p = platform(); const options = { input: text, timeout: 5000 }; @@ -42,12 +47,7 @@ export function copyToClipboard(text: string): void { } } } - } catch (error) { - const msg = error instanceof Error ? error.message : String(error); - if (p === "linux") { - const tools = isWaylandSession() ? "wl-copy, xclip, or xsel" : "xclip or xsel"; - throw new Error(`Failed to copy to clipboard. Install ${tools}: ${msg}`); - } - throw new Error(`Failed to copy to clipboard: ${msg}`); + } catch { + // Ignore - OSC 52 already emitted as fallback } }