fix(coding-agent): use native clipboard text copy on desktop closes #2347
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { createRequire } from "module";
|
||||
|
||||
export type ClipboardModule = {
|
||||
setText: (text: string) => Promise<void>;
|
||||
hasImage: () => boolean;
|
||||
getImageBinary: () => Promise<Array<number>>;
|
||||
};
|
||||
|
||||
@@ -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"] };
|
||||
|
||||
Reference in New Issue
Block a user