Skip to content

fix(composer): attach pasted image files as images - #2533

Merged
Tioit-Wang merged 1 commit into
vastsa:mainfrom
zszz3:fix/composer-paste-image-file-inline
Nov 24, 2026
Merged

Tioit-Wang merged 1 commit into
vastsa:mainfrom
zszz3:fix/composer-paste-image-file-inline

Conversation

@zszz3

@zszz3 zszz3 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

概要

修复 #2316 引入的回归:PixPin 等截图工具复制到剪贴板的是一个临时 PNG 文件,而不是位图。#2316 之后,原生剪贴板里的磁盘文件一律走"路径引用",图片只以「路径 + 大小」发给模型——视觉模型拿不到像素;而且 PixPin 清理临时目录后,源文件也就没了。

改动

  • Main 进程按文件拆分原生剪贴板粘贴(apps/desktop/electron/main/composer-file-references.ts 新增 pasteComposerClipboardFiles):在现有导入上限内的位图图片(单文件 ≤ 64 MiB、单批 ≤ 128 MiB、≤ 20 个;不含 SVG)和文件选择器导入一样复制到会话 scratch(importComposerFiles)→ 显示为图片附件,发送时作为图片内联给模型,会话记录里存为按内容寻址的 attachments/<sha256>。
  • 非图片文件、SVG、超出上限的图片仍走 fix(composer): reference pasted disk files with sizes #2316 的引用流程,[Feature] Reference pasted local files with size metadata instead of copying their contents #2314(大文件粘贴)不受影响。
  • 所有路径先全部校验再写入;结果保持剪贴板原顺序。IPC handler 保持薄层,渲染进程不改。
  • 远程工作区中粘贴图片现在可以正常导入;粘贴非图片文件仍和之前一样被拒绝。
  • 同步更新了 ADR、IPC 协议 spec、工具与权限 spec、E2E 场景文档。

这与 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:通过。
  • Desktop 全量测试:5359 通过 / 4 失败(file-manager-git-timeout、image-model-disclosure-user-path、reviewed-file-open),这几个在未修改的 upstream/main 7254a04 上同样失败,与本 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>。

Task candidate: 0d9d8e306
Base main:      upstream/main 7254a0452
E2E suites:     test:e2e:composer-paste-image-file(连续 5 次 + 最终 1 次通过);
                e2e-composer-paste.mjs --file-references-only(含重启)、默认模式、--screenshot-only:通过
对照:           同一个新 E2E 在 upstream/main 构建上失败:
                "pasted image file must render as an image chip, not a file reference"
Environment:    macOS,Electron 43.6.0,debug host-core

未验证:Windows 真机 + PixPin(本 PR 未改动 Windows 剪贴板路径读取),以及真实付费模型接口。

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
@Tioit-Wang

Copy link
Copy Markdown
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 origin/main d07b742, so it must be refreshed and its gates rerun first. The Windows PixPin native clipboard path remains explicitly unverified; please record a Windows result or keep that platform limitation visible.

@Tioit-Wang
Tioit-Wang merged commit 562723e into vastsa:main Nov 24, 2026
6 checks passed
@Tioit-Wang

Copy link
Copy Markdown
Collaborator

该修复已通过维护者续接 PR #2560 合并,保留了本 PR 的原始实现提交,并在最新 main 上通过 JS、Rust、Windows Host 和 Electron CI。因续接 PR 已合并,我会关闭这个重复 PR;其中 macOS 原生 pasteboard 专项 E2E 在当前 Windows 环境未运行,限制已记录在 #2560。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 新版本无法读取图片内容

2 participants