Repository navigation
fix(composer): attach pasted image files as images - #2533
Merged
Tioit-Wang merged 1 commit intoNov 24, 2026
Merged
Conversation
Screenshot tools such as PixPin put a temporary PNG file, not a bitmap, on the clipboard. Since native disk-file pastes became live path references, those images reached the model as a path plus size, so vision models never saw the pixels and the source could vanish once the tool cleaned its temp directory. Native clipboard raster images within the existing import bounds are now copied into session scratch like picker imports, so they attach as image chips and are stored as content-addressed attachments on send. Other files, SVGs and images beyond the bounds keep the reference flow. fixes vastsa#2529
2 tasks done
Collaborator
|
Review: the PR reaches the regression root and has strong coverage, including a native pasteboard user-path E2E that verifies the model receives the image after the temporary source is deleted. I compared #2532 and recommend this implementation because it keeps clipboard classification/reference-vs-import work behind the main-process helper and covers the full paste-to-prompt path. I did not merge: this head is based on 7254a04 and is 15 commits behind/diverged from current |
This was referenced Nov 24, 2026
Closed
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
修复 #2316 引入的回归:PixPin 等截图工具复制到剪贴板的是一个临时 PNG 文件,而不是位图。#2316 之后,原生剪贴板里的磁盘文件一律走"路径引用",图片只以「路径 + 大小」发给模型——视觉模型拿不到像素;而且 PixPin 清理临时目录后,源文件也就没了。
改动
apps/desktop/electron/main/composer-file-references.ts新增pasteComposerClipboardFiles):在现有导入上限内的位图图片(单文件 ≤ 64 MiB、单批 ≤ 128 MiB、≤ 20 个;不含 SVG)和文件选择器导入一样复制到会话 scratch(importComposerFiles)→ 显示为图片附件,发送时作为图片内联给模型,会话记录里存为按内容寻址的attachments/<sha256>。这与 ZCode、Codex(
clipboard_paste.rs:复制的文件优先于其预览,按图片解码)以及 Zed(#51575,同一个 bug)对"复制的图片文件"的处理方式一致。需求关联
验证
apps/desktop/test/composer-file-references.test.mjs覆盖图片/引用拆分与顺序、大小/数量/SVG 边界、无项目/远程工作区、IPC handler。修复前失败(does not provide an export named 'pasteComposerClipboardFiles'),修复后通过;相关用例 39/39。pnpm --filter @pi-desktop/desktop typecheck、pnpm lint、node scripts/check-architecture.mjs、git diff --check:通过。file-manager-git-timeout、image-model-disclosure-user-path、reviewed-file-open),这几个在未修改的upstream/main7254a04 上同样失败,与本 PR 无关。新增真实 E2E
pnpm test:e2e:composer-paste-image-file(macOS):使用构建后的 Desktop + 真实 Host + agent sidecar + preload IPC,把项目外PixPin/Temp目录下的 PNG 以文件 URL 形式写入真实的NSPasteboard再粘贴;只有模型接口是本地 Chat Completions 假服务。断言:出现图片附件;发送前删除源文件后,视觉模型仍收到与原 PNG 完全一致的image_url,且没有本地文件引用上下文;会话记录存储attachments/<sha256>。未验证:Windows 真机 + PixPin(本 PR 未改动 Windows 剪贴板路径读取),以及真实付费模型接口。