fix(coding-agent): use native clipboard text copy on desktop closes #2347

This commit is contained in:
Mario Zechner
2026-03-18 22:41:43 +01:00
parent fd385ecf06
commit ce15f40769
3 changed files with 15 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import { createRequire } from "module";
export type ClipboardModule = {
setText: (text: string) => Promise<void>;
hasImage: () => boolean;
getImageBinary: () => Promise<Array<number>>;
};

View File

@@ -1,6 +1,7 @@
import { execSync, spawn } from "child_process";
import { platform } from "os";
import { isWaylandSession } from "./clipboard-image.js";
import { clipboard } from "./clipboard-native.js";
type NativeClipboardExecOptions = {
input: string;
@@ -16,11 +17,20 @@ function copyToX11Clipboard(options: NativeClipboardExecOptions): void {
}
}
export function copyToClipboard(text: string): void {
export async function copyToClipboard(text: string): Promise<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`);
try {
if (clipboard) {
await clipboard.setText(text);
return;
}
} catch {
// Fall through to platform-specific clipboard tools.
}
// Also try native tools (best effort for local sessions)
const p = platform();
const options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: ["pipe", "ignore", "ignore"] };