Skip to content

fix(composer): import clipboard disk images within limits - #2532

Closed
skyler-developer wants to merge 1 commit into
vastsa:mainfrom
skyler-developer:fix/clipboard-image-import
Closed

skyler-developer wants to merge 1 commit into
vastsa:mainfrom
skyler-developer:fix/clipboard-image-import

Conversation

@skyler-developer

Copy link
Copy Markdown
Contributor

Summary / 概要

Native clipboard file paste (PixPin "copy as file", Finder/Explorer copies) regressed in 0.23.0: #2316 routed every clipboard disk file into a path-only live reference, so pasted disk images stopped reaching the model as visual content — the agent only saw a Local file references … (N bytes) text. Bitmap screenshots were unaffected, which is why only file-copying screenshot tools broke.

Fix: split the clipboard reference flow per file in referenceComposerFiles:

  • Image files within the picker import limits (same isImageFile decision as picker/drag imports, SVG excluded, 64 MiB per file, 128 MiB across one paste's images) materialize into session scratch via the existing importComposerFiles and return without localReference — they dispatch exactly like picker images (inline chip, image block on send, attachments/<sha256> archival). This restores the 0.22 behavior.
  • Non-image files and oversized images keep the fix(composer): reference pasted disk files with sizes #2316 no-copy live reference ([Feature] Reference pasted local files with size metadata instead of copying their contents #2314's guarantee is unchanged).
  • All-or-nothing batch cap: if one paste's images exceed the total limit, all of them fall back to references instead of copying a partial set.

The IPC layer (composer/importFiles with reference: true) is unchanged; docs synced (ADR, IPC protocol spec, E2E scenario E2E-COMPOSER-local-file-references).

Requirement link / 需求关联

  • Linked requirement issue / 已关联对应的需求 Issue:Closes #2529
  • Issue explains the background and the expected outcome / Issue 已说明需求背景和期望效果

Validation / 验证

Task candidate: branch fix/clipboard-image-import (commit b02dbc1) based on latest origin/main (7254a04, merge-base verified).

  • pnpm build:js — pass
  • pnpm --filter @pi-desktop/desktop typecheck — pass
  • pnpm lint — pass
  • node --import ./test/helpers/ts-import-hooks.mjs --test test/composer-file-references.test.mjs — 7/7 pass, including two new regression tests ([Bug] 新版本无法读取图片内容 #2529): mixed png/txt/svg paste imports the png in paste order and keeps references for the rest; an image set past the 128 MiB batch cap stays fully referenced with no scratch writes
  • Adjacent suites (composer-paste-files, composer-clipboard-directories, composer-directory-paste, composer-file-reference-draft, composer-file-reference-display, composer-inline-image-chips, prompt-inline-attachments, svg-attachments) — 75/75 pass
  • Independent CR review (subagent): APPROVE, no blocking findings; non-blocking notes — TOCTOU between the outer stat and the importer's stat fails the whole paste loudly (same race class as the picker path), and a 0-byte image falls back to a reference (degenerate input)

NOT RUN: node scripts/e2e-composer-paste.mjs (Electron binary unavailable; deps installed with --ignore-scripts). Its --file-references-only mode pastes a 64 MiB+1 binary and a text file, both of which still take the reference path after this change, so the script required no edits and its assertions remain valid. The image-import branch is covered by the new unit tests.

Platform note: verified by code trace and unit tests on macOS. The reported PixPin flow is Windows-specific; real-machine paste verification on Windows is still pending — happy to hear results from a Windows user.

Rollback / 回滚

Single commit reverting to the #2316 all-reference behavior; no schema, IPC contract, or persisted-format changes (localReference records and scratch imports already exist).

vastsa#2316 routed every native clipboard file into a path-only live reference,
so pasted screenshot-tool images (PixPin copy-as-file, Finder/Explorer
copies) stopped reaching the model as visual content (vastsa#2529). Split the
reference flow per file: images within the picker import limits (same
isImageFile decision, SVG excluded, 64 MiB per file, 128 MiB across one
paste's images) materialize into session scratch via importComposerFiles
and dispatch as regular visual attachments; non-image files and oversized
images keep the no-copy live reference, and a paste whose images exceed
the total cap falls back to references for all of them.

Fixes vastsa#2529
@Tioit-Wang

Copy link
Copy Markdown
Collaborator

Review: this fixes the confirmed #2316 regression and retains the bounded-reference path for non-images/oversized files. The branch has targeted unit coverage; however, PR #2533 adds a real built-Desktop/preload/Host/native-pasteboard E2E (with a local model fixture) and covers deleting the source before dispatch. I recommend consolidating on #2533 rather than landing two competing implementations. This PR is also based on 7254a04, 15 commits behind/diverged from current origin/main d07b742. I did not approve or merge; please coordinate with #2533 and refresh the chosen branch.

@skyler-developer

Copy link
Copy Markdown
Contributor Author

Closing in favor of #2533, which was merged and covers the same #2316 regression with the real pasteboard E2E that this PR lacked. Thanks for the review guidance.

(Posted via an AI assistant at my direction; I own the content.)

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.

2 participants