Skip to content

fix:solved the copy issue in TUI#14101

Open
shrutsureja wants to merge 1 commit intoanomalyco:devfrom
shrutsureja:fix/copy
Open

fix:solved the copy issue in TUI#14101
shrutsureja wants to merge 1 commit intoanomalyco:devfrom
shrutsureja:fix/copy

Conversation

@shrutsureja
Copy link

Summary

Fixes the copy issue in the TUI (Terminal User Interface).

Changes

  • Commit: ae7cd4cfix: solved the copy issue in TUI

Problem

There was a bug in the TUI where the copy functionality was not working correctly. This fix addresses the root cause and ensures copy works as expected in the TUI.

Related PRs

There are several open PRs in this repo related to copy/clipboard functionality:

This PR specifically targets the TUI copy bug.

How to Test

  1. Open opencode in TUI mode
  2. Attempt to copy content (e.g., code blocks, assistant responses)
  3. Verify that the copy operation completes successfully without errors or silent failures

Environment Tested

Checklist

  • Bug fix (no breaking changes)
  • Targets TUI copy functionality
  • Branch: shrutsureja:fix/copyanomalyco/opencode:dev
  • Solved using opencode + oh-my-opencode (Hephaestus) + Claude Sonnet 4.5
  • Tested locally on Ubuntu 24.04 LTS

Copilot AI review requested due to automatic review settings February 18, 2026 13:26
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, I found several related PRs that deal with TUI copy functionality:

Related PRs Found:

  1. fix(tui): don't clear selection when OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT is enabled #10897 - Directly addresses TUI copy behavior with selection clearing issues.

  2. feat(tui): add copy shortcut in code method #10543 - Adds copy functionality to TUI, may be related to the same copy issue being fixed.

  3. feat(tui): add double-click to copy word #6285 - Another TUI copy feature that could be affected by or related to the copy bug.

  4. fix(clipboard): improve OSC 52 escape sequence for SSH compatibility #9008 - Clipboard-related fix that could interact with TUI copy functionality.

  5. fix(tui): fix Ctrl+V paste on Windows/WSL2 #8626 - Related clipboard/paste functionality in TUI.

  6. fix(clipboard): add OSC 52 fallback for SSH/tmux environments #7028 - Clipboard fallback implementation relevant to copy operations.

These PRs are related to copy/clipboard functionality in the TUI, though they appear to address different aspects or specific scenarios rather than being direct duplicates of PR #14101.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes TUI clipboard copy reliability by introducing multi-backend copy methods with explicit exit-code/error handling and surfacing failures to the user/logs.

Changes:

  • Refactor TUI clipboard copy to try multiple platform-specific backends (with stderr/exit-code handling) and throw a descriptive error if all fail.
  • Show a toast error when “Copy message” fails in the session message dialog.
  • Add error handling when copying the issue-report URL from the TUI fatal error screen.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/opencode/src/cli/cmd/tui/util/clipboard.ts Adds multi-method clipboard copy pipeline (osascript/wl-copy/xclip/xsel/powershell/clip.exe + fallback) and improved failure reporting.
packages/opencode/src/cli/cmd/tui/routes/session/dialog-message.tsx Wraps message copy action with toast-based error handling and avoids closing the dialog on failure.
packages/opencode/src/cli/cmd/tui/app.tsx Ensures issue URL copy failures are caught and logged instead of silently ignored.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +190 to +195
list.push({
name: "clipboardy",
copy: async (text: string) => {
await clipboardy.write(text)
},
})
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clipboardy is always added as a copy method, even when a native method (wl-copy/xclip/xsel/powershell/etc.) is enabled. Since clipboardy typically shells out to the same underlying tools, this can cause redundant attempts (and duplicated errors) before failing, and can add extra latency. Consider only adding the clipboardy fallback when no OS-specific methods were added, or otherwise de-duplicating so each backend is tried at most once.

Suggested change
list.push({
name: "clipboardy",
copy: async (text: string) => {
await clipboardy.write(text)
},
})
if (list.length === 0) {
list.push({
name: "clipboardy",
copy: async (text: string) => {
await clipboardy.write(text)
},
})
}

Copilot uses AI. Check for mistakes.
const escaped = text.replace(/\\/g, "\\\\").replace(/"/g, '\\"')
const result = await $`osascript -e 'set the clipboard to "${escaped}"'`.nothrow().quiet()
if (result.exitCode === 0) return
throw new Error("osascript failed")
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When osascript fails, the thrown error message is always just "osascript failed". This loses useful context (exit code and stderr) that would help users/debugging when copy fails. Consider including result.exitCode and any stderr output in the error message (similar to spawnCopy).

Suggested change
throw new Error("osascript failed")
const stderr =
result.stderr && result.stderr.length
? new TextDecoder().decode(result.stderr).trim()
: ""
throw new Error(
`osascript exited with code ${result.exitCode}${stderr ? `: ${stderr}` : ""}`,
)

Copilot uses AI. Check for mistakes.
setCopied(true)
})
.catch((error) => {
console.error(`Failed to copy issue URL to clipboard: ${error}`)
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch branch logs ${error} which often becomes "[object Object]" and drops stack traces. Consider normalizing the error (e.g., error instanceof Error ? error.stack ?? error.message : String(error)) so clipboard failures are diagnosable from logs.

Suggested change
console.error(`Failed to copy issue URL to clipboard: ${error}`)
const normalizedError =
error instanceof Error ? error.stack ?? error.message : String(error)
console.error(`Failed to copy issue URL to clipboard: ${normalizedError}`)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments