feat(coding-agent): add OSC 52 clipboard support for SSH/mosh sessions
Fixes #1069
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user