Skip to content

The open source coding agent.

TypeScript

fix: correct clipboard image encoding and binary handling (#3817)

frankdierolf2c3aa330b92b
diff --git a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts
index 7603b4c3899..aac172141a1 100644
--- a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts
+++ b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts
@@ -30,13 +30,13 @@ export namespace Clipboard {
}
if (os === "linux") {
- const wayland = await $`wl-paste -t image/png`.nothrow().text()
- if (wayland) {
- return { data: Buffer.from(wayland).toString("base64url"), mime: "image/png" }
+ const wayland = await $`wl-paste -t image/png`.nothrow().arrayBuffer()
+ if (wayland && wayland.byteLength > 0) {
+ return { data: Buffer.from(wayland).toString("base64"), mime: "image/png" }
}
- const x11 = await $`xclip -selection clipboard -t image/png -o`.nothrow().text()
- if (x11) {
- return { data: Buffer.from(x11).toString("base64url"), mime: "image/png" }
+ const x11 = await $`xclip -selection clipboard -t image/png -o`.nothrow().arrayBuffer()
+ if (x11 && x11.byteLength > 0) {
+ return { data: Buffer.from(x11).toString("base64"), mime: "image/png" }
}
}
@@ -47,7 +47,7 @@ export namespace Clipboard {
if (base64) {
const imageBuffer = Buffer.from(base64.trim(), "base64")
if (imageBuffer.length > 0) {
- return { data: imageBuffer.toString("base64url"), mime: "image/png" }
+ return { data: imageBuffer.toString("base64"), mime: "image/png" }
}
}
}