fix: preserve clipboard image paths for path-based MCP tools - #36051
fix: preserve clipboard image paths for path-based MCP tools#36051hb-0 wants to merge 3 commits into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Found related PRs that may be duplicates or address similar issues:
PR #21633 appears to be the most directly related — it targets the same issue (clipboard-pasted images need temp file paths for MCP tool access). You should check if this is already merged or if #36051 is a different iteration/fix on that work. |
|
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. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Ported from upstream anomalyco#36051.
Ported from upstream anomalyco#36051.
…#35) * fix(desktop): preserve clipboard image paths for path-based MCP tools Ported from upstream anomalyco#36051. * fix(tui): stop leaking clipboard image temp files Addresses Opus review of PR #35: clipboard image reads returned a unique-named temp PNG whose cleanup only ran on the failure path, leaking one file per paste. Route them through a single per-process temp dir removed on process exit.
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #17771
Type of change
What does this PR do?
Path-based MCP tools (e.g. image readers) need a file path to access pasted images. Pasted clipboard images either had no path or lost it, so the tools received an incorrect/missing path. This PR makes pasted images reliably carry a usable path and improves temp-file management.
Desktop (
packages/desktop,packages/app):opencode-clipboard-<uuid>) removed onwill-quit, instead of scattering files inos.tmpdir()that were never cleaned up.randomUUID()filenames avoid collisions; write failures degrade gracefully (return the image without a path so the caller falls back) instead of throwing.TUI (
packages/tui):public.file-urlbut no PNGf flavor, so the PNGf read failed andpbpastereturned only the bare filename, whichreadLocalAttachmentresolved against the cwd and failed.readClipboardFilePathnow reads the file URL via«class furl»(with anfs.accesscheck to reject plain-text false positives) before trying PNGf.pasteInputTextretries throughclipboard.read()to recover the full path whenreadLocalAttachmentfails on the pasted filename.path.filenamewhen available, so the model/path-based tools receive the real path instead of a bare filename the model had to guess.How did you verify your code works?
[Image N]placeholder with the full path; an image-recognition MCP tool received the correctimage_path.[Image N]placeholder; the persisted temp path was passed to the MCP tool and read successfully.bun typecheckpasses forpackages/tuiandpackages/desktop.Screenshots / recordings
N/A — no UI change; the
[Image N]placeholder already existed for successful image attachments.Checklist
If you do not follow this template your PR will be automatically rejected.