Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
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:
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. |
There was a problem hiding this comment.
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.
| list.push({ | ||
| name: "clipboardy", | ||
| copy: async (text: string) => { | ||
| await clipboardy.write(text) | ||
| }, | ||
| }) |
There was a problem hiding this comment.
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.
| 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) | |
| }, | |
| }) | |
| } |
| 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") |
There was a problem hiding this comment.
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).
| 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}` : ""}`, | |
| ) |
| setCopied(true) | ||
| }) | ||
| .catch((error) => { | ||
| console.error(`Failed to copy issue URL to clipboard: ${error}`) |
There was a problem hiding this comment.
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.
| 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}`) |
Summary
Fixes the copy issue in the TUI (Terminal User Interface).
Changes
ae7cd4c—fix: solved the copy issue in TUIProblem
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
Environment Tested
Checklist
shrutsureja:fix/copy→anomalyco/opencode:dev