From 3990837635d5d0115efcf631bdf7541429a172b1 Mon Sep 17 00:00:00 2001 From: Mahesh Pujari Date: Sun, 9 Nov 2025 16:58:44 +0530 Subject: [PATCH 1/2] fix: paste images in WSl with ctrl+v --- .../src/cli/cmd/tui/util/clipboard.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts index aac172141a1..c62630e0cdc 100644 --- a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts +++ b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts @@ -1,5 +1,5 @@ import { $ } from "bun" -import { platform } from "os" +import { platform, release } from "os" import clipboardy from "clipboardy" import { lazy } from "../../../../util/lazy.js" import { tmpdir } from "os" @@ -29,6 +29,18 @@ export namespace Clipboard { } } + if (os === "win32" || release().includes("WSL")) { + const script = + "Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }" + const base64 = await $`powershell.exe -command "${script}"`.nothrow().text() + if (base64) { + const imageBuffer = Buffer.from(base64.trim(), "base64") + if (imageBuffer.length > 0) { + return { data: imageBuffer.toString("base64"), mime: "image/png" } + } + } + } + if (os === "linux") { const wayland = await $`wl-paste -t image/png`.nothrow().arrayBuffer() if (wayland && wayland.byteLength > 0) { @@ -40,18 +52,6 @@ export namespace Clipboard { } } - if (os === "win32") { - const script = - "Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }" - const base64 = await $`powershell -command "${script}"`.nothrow().text() - if (base64) { - const imageBuffer = Buffer.from(base64.trim(), "base64") - if (imageBuffer.length > 0) { - return { data: imageBuffer.toString("base64"), mime: "image/png" } - } - } - } - const text = await clipboardy.read().catch(() => {}) if (text) { return { data: text, mime: "text/plain" } From 9bf724ed9f02788988f0bfe26f3e477367f62433 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 9 Nov 2025 11:30:40 +0000 Subject: [PATCH 2/2] chore: format code --- packages/plugin/package.json | 2 +- packages/sdk/js/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 77ecaa70df8..2bec58c3c21 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -24,4 +24,4 @@ "typescript": "catalog:", "@typescript/native-preview": "catalog:" } -} \ No newline at end of file +} diff --git a/packages/sdk/js/package.json b/packages/sdk/js/package.json index 89d0abe3434..b32463519f6 100644 --- a/packages/sdk/js/package.json +++ b/packages/sdk/js/package.json @@ -26,4 +26,4 @@ "publishConfig": { "directory": "dist" } -} \ No newline at end of file +}