The open source coding agent.
TypeScript
Use opentui OSC52 clipboard, again (#11744)
Sebastian3982c7d99a1f
diff --git a/bun.lock b/bun.lockindex 0857283634a..c98144251c6 100644--- a/bun.lock+++ b/bun.lock@@ -298,8 +298,8 @@"@opencode-ai/sdk": "workspace:*","@opencode-ai/util": "workspace:*","@openrouter/ai-sdk-provider": "1.5.4",- "@opentui/core": "0.1.75",- "@opentui/solid": "0.1.75",+ "@opentui/core": "0.1.77",+ "@opentui/solid": "0.1.77","@parcel/watcher": "2.5.1","@pierre/diffs": "catalog:","@solid-primitives/event-bus": "1.1.2",@@ -1227,21 +1227,21 @@"@opentelemetry/api": ["@opentelemetry/[email protected]", "", {}, "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg=="],- "@opentui/core": ["@opentui/[email protected]", "", { "dependencies": { "bun-ffi-structs": "0.1.2", "diff": "8.0.2", "jimp": "1.6.0", "marked": "17.0.1", "yoga-layout": "3.2.1" }, "optionalDependencies": { "@dimforge/rapier2d-simd-compat": "^0.17.3", "@opentui/core-darwin-arm64": "0.1.75", "@opentui/core-darwin-x64": "0.1.75", "@opentui/core-linux-arm64": "0.1.75", "@opentui/core-linux-x64": "0.1.75", "@opentui/core-win32-arm64": "0.1.75", "@opentui/core-win32-x64": "0.1.75", "bun-webgpu": "0.1.4", "planck": "^1.4.2", "three": "0.177.0" }, "peerDependencies": { "web-tree-sitter": "0.25.10" } }, "sha512-8ARRZxSG+BXkJmEVtM2DQ4se7DAF1ZCKD07d+AklgTr2mxCzmdxxPbOwRzboSQ6FM7qGuTVPVbV4O2W9DpUmoA=="],+ "@opentui/core": ["@opentui/[email protected]", "", { "dependencies": { "bun-ffi-structs": "0.1.2", "diff": "8.0.2", "jimp": "1.6.0", "marked": "17.0.1", "yoga-layout": "3.2.1" }, "optionalDependencies": { "@dimforge/rapier2d-simd-compat": "^0.17.3", "@opentui/core-darwin-arm64": "0.1.77", "@opentui/core-darwin-x64": "0.1.77", "@opentui/core-linux-arm64": "0.1.77", "@opentui/core-linux-x64": "0.1.77", "@opentui/core-win32-arm64": "0.1.77", "@opentui/core-win32-x64": "0.1.77", "bun-webgpu": "0.1.4", "planck": "^1.4.2", "three": "0.177.0" }, "peerDependencies": { "web-tree-sitter": "0.25.10" } }, "sha512-lE3kabm6jdqK3AuBq+O0zZrXdxt6ulmibTc57sf+AsPny6cmwYHnWI4wD6hcreFiYoQVNVvdiJchVgPtowMlEg=="],- "@opentui/core-darwin-arm64": ["@opentui/[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-gGaGZjkFpqcXJk6321JzhRl66pM2VxBlI470L8W4DQUW4S6iDT1R9L7awSzGB4Cn9toUl7DTV8BemaXZYXV4SA=="],+ "@opentui/core-darwin-arm64": ["@opentui/[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-SNqmygCMEsPCW7xWjzCZ5caBf36xaprwVdAnFijGDOuIzLA4iaDa6um8cj3TJh7awenN3NTRsuRc7OuH42UH+g=="],- "@opentui/core-darwin-x64": ["@opentui/[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-tPlvqQI0whZ76amHydpJs5kN+QeWAIcFbI8RAtlAo9baj2EbxTDC+JGwgb9Fnt0/YQx831humbtaNDhV2Jt1bw=="],+ "@opentui/core-darwin-x64": ["@opentui/[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-/8fsa03swEHTQt/9NrGm98kemlU+VuTURI/OFZiH53vPDRrOYIYoa4Jyga/H7ZMcG+iFhkq97zIe+0Kw95LGmA=="],- "@opentui/core-linux-arm64": ["@opentui/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-nVxIQ4Hqf84uBergDpWiVzU6pzpjy6tqBHRQpySxZ2flkJ/U6/aMEizVrQ1jcgIdxZtvqWDETZhzxhG0yDx+cw=="],+ "@opentui/core-linux-arm64": ["@opentui/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-QfUXZJPc69OvqoMu+AlLgjqXrwu4IeqcBuUWYMuH8nPTeLsVUc3CBbXdV2lv9UDxWzxzrxdS4ALPaxvmEv9lsQ=="],- "@opentui/core-linux-x64": ["@opentui/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-1CnApef4kxA+ORyLfbuCLgZfEjp4wr3HjFnt7FAfOb73kIZH82cb7JYixeqRyy9eOcKfKqxLmBYy3o8IDkc4Rg=="],+ "@opentui/core-linux-x64": ["@opentui/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-Kmfx0yUKnPj67AoXYIgL7qQo0QVsUG5Iw8aRtv6XFzXqa5SzBPhaKkKZ9yHPjOmTalZquUs+9zcCRNKpYYuL7A=="],- "@opentui/core-win32-arm64": ["@opentui/[email protected]", "", { "os": "win32", "cpu": "arm64" }, "sha512-j0UB95nmkYGNzmOrs6GqaddO1S90R0YC6IhbKnbKBdjchFPNVLz9JpexAs6MBDXPZwdKAywMxtwG2h3aTJtxng=="],+ "@opentui/core-win32-arm64": ["@opentui/[email protected]", "", { "os": "win32", "cpu": "arm64" }, "sha512-HGTscPXc7gdd23Nh1DbzUNjog1I+5IZp95XPtLftGTpjrWs60VcetXcyJqK2rQcXNxewJK5yDyaa5QyMjfEhCQ=="],- "@opentui/core-win32-x64": ["@opentui/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-ESpVZVGewe3JkB2TwrG3VRbkxT909iPdtvgNT7xTCIYH2VB4jqZomJfvERPTE0tvqAZJm19mHECzJFI8asSJgQ=="],+ "@opentui/core-win32-x64": ["@opentui/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-c7GijsbvVgnlzd2murIbwuwrGbcv76KdUw6WlVv7a0vex50z6xJCpv1keGzpe0QfxrZ/6fFEFX7JnwGLno0wjA=="],- "@opentui/solid": ["@opentui/[email protected]", "", { "dependencies": { "@babel/core": "7.28.0", "@babel/preset-typescript": "7.27.1", "@opentui/core": "0.1.75", "babel-plugin-module-resolver": "5.0.2", "babel-preset-solid": "1.9.9", "s-js": "^0.4.9" }, "peerDependencies": { "solid-js": "1.9.9" } }, "sha512-WjKsZIfrm29znfRlcD9w3uUn/+uvoy2MmeoDwTvg1YOa0OjCTCmjZ43L9imp0m9S4HmVU8ma6o2bR4COzcyDdg=="],+ "@opentui/solid": ["@opentui/[email protected]", "", { "dependencies": { "@babel/core": "7.28.0", "@babel/preset-typescript": "7.27.1", "@opentui/core": "0.1.77", "babel-plugin-module-resolver": "5.0.2", "babel-preset-solid": "1.9.9", "s-js": "^0.4.9" }, "peerDependencies": { "solid-js": "1.9.9" } }, "sha512-JY+hUbXVV+XCk6bC8dvcwawWCEmC3Gid6GDs23AJWBgHZ3TU2kRKrgwTdltm45DOq2cZXrYCt690/yE8bP+Gxg=="],"@oslojs/asn1": ["@oslojs/[email protected]", "", { "dependencies": { "@oslojs/binary": "1.0.0" } }, "sha512-zw/wn0sj0j0QKbIXfIlnEcTviaCzYOY3V5rAyjR6YtOByFtJiT574+8p9Wlach0lZH9fddD4yb9laEAIl4vXQA=="],diff --git a/packages/opencode/package.json b/packages/opencode/package.jsonindex 4afb7243006..c86aa734d8f 100644--- a/packages/opencode/package.json+++ b/packages/opencode/package.json@@ -82,8 +82,8 @@"@opencode-ai/sdk": "workspace:*","@opencode-ai/util": "workspace:*","@openrouter/ai-sdk-provider": "1.5.4",- "@opentui/core": "0.1.75",- "@opentui/solid": "0.1.75",+ "@opentui/core": "0.1.77",+ "@opentui/solid": "0.1.77","@parcel/watcher": "2.5.1","@pierre/diffs": "catalog:","@solid-primitives/event-bus": "1.1.2",diff --git a/packages/opencode/src/cli/cmd/tui/app.tsx b/packages/opencode/src/cli/cmd/tui/app.tsxindex 713def2e5af..c5f88a7c672 100644--- a/packages/opencode/src/cli/cmd/tui/app.tsx+++ b/packages/opencode/src/cli/cmd/tui/app.tsx@@ -169,6 +169,7 @@ export function tui(input: {gatherStats: false,exitOnCtrlC: false,useKittyKeyboard: {},+ autoFocus: false,consoleOptions: {keyBindings: [{ name: "y", ctrl: true, action: "copy-selection" }],onCopySelection: (text) => {@@ -186,6 +187,7 @@ function App() {const route = useRoute()const dimensions = useTerminalDimensions()const renderer = useRenderer()+ Clipboard.setRenderer(renderer)renderer.disableStdoutInterception()const dialog = useDialog()const local = useLocal()diff --git a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts b/packages/opencode/src/cli/cmd/tui/util/clipboard.tsindex 0e287fbc41a..5c27a26cd03 100644--- a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts+++ b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts@@ -1,24 +1,12 @@import { $ } from "bun"+import type { CliRenderer } from "@opentui/core"import { platform, release } from "os"import clipboardy from "clipboardy"import { lazy } from "../../../../util/lazy.js"import { tmpdir } from "os"import path from "path"-/**- * Writes text to clipboard via OSC 52 escape sequence.- * This allows clipboard operations to work over SSH by having- * the terminal emulator handle the clipboard locally.- */-function writeOsc52(text: string): void {- if (!process.stdout.isTTY) return- const base64 = Buffer.from(text).toString("base64")- const osc52 = `\x1b]52;c;${base64}\x07`- // tmux and screen require DCS passthrough wrapping- const passthrough = process.env["TMUX"] || process.env["STY"]- const sequence = passthrough ? `\x1bPtmux;\x1b${osc52}\x1b\\` : osc52- process.stdout.write(sequence)-}+const rendererRef = { current: undefined as CliRenderer | undefined }export namespace Clipboard {export interface Content {@@ -26,6 +14,10 @@ export namespace Clipboard {mime: string}+ export function setRenderer(renderer: CliRenderer | undefined): void {+ rendererRef.current = renderer+ }+export async function read(): Promise<Content | undefined> {const os = platform()@@ -154,7 +146,11 @@ export namespace Clipboard {})export async function copy(text: string): Promise<void> {- writeOsc52(text)+ const renderer = rendererRef.current+ if (renderer) {+ const copied = renderer.copyToClipboardOSC52(text)+ if (copied) return+ }await getCopyMethod()(text)}}