Repository navigation
fix(composer): reference pasted disk files with sizes - #2316
Conversation
Avoid copying native clipboard files through renderer memory and session scratch. Keep trusted selection records and current byte sizes while deferring content access to normal tool permissions. Preserve reference metadata through drafts, queues, transcript storage and runtime replay; keep generated clipboard payloads on the existing byte path. Fixes vastsa#2314
Index the accepted decision and format the attachment fixture for the documentation and Rust gates. Verify that history restores live reference metadata without opening or snapshotting the source.
Exercise large and small disk references across real Composer hooks, preload IPC, selection records, dispatch and history restart. Verify metadata-only transport and refreshed source sizes. Restore the preview assertion to the actual pre-open focus target because Chromium can retain the editing host as activeElement for a nested chip.
Installing the saved selection can focus its editing host and override the original attachment control. Restore control focus last and cover the ordering plus stale-session and stale-project guards. Keep the Electron assertion strict while waiting for preview disposal and focus restoration to finish.
|
Validation completed at Local Electron validation now covers the full paste suite plus The fixture controls native clipboard URI-list metadata and external provider delivery. Manual Finder copy gestures and live external model calls were not performed. Marked Ready for review; not merged. |
vastsa
left a comment
There was a problem hiding this comment.
Reviewed head 047748de868b58f336a6a9d8ffe2eebe94c19fd4 against current main 82823a6c0.
Independently reproduced the existing production byte-paste rejection for a 64 MiB + 1 byte payload. The metadata path addresses that cost without raising transfer limits or broadening the ordinary attachment-root validator. Reviewed sender-bound one-shot selection consumption, canonical source/project registration, dispatch refresh/rejection, draft/message propagation and runtime replay. The small selection/focus ordering correction has focused coverage and passes the full paste suite.
Independent validation in an isolated worktree using reused dependencies and this candidate's freshly built shared package:
- Shared TypeScript build and whitespace check passed.
- 38 targeted reference/draft/history/directory/focus tests passed.
- Full runtime.test.ts: 421 tests passed, including live and restored reference metadata.
- Real Electron file-reference suite passed, including sparse 64 MiB + 1 source, no renderer byte reads, changed-source size refresh and second-process history recovery.
- Full real Electron paste suite passed, including screenshots/native images, preview focus, undo/redo, multiple files, draft races and second-process history restoration.
- All six current-head CI checks passed, including clean JS validation and Rust/Windows coverage. Latest main is an ancestor; fetched actual merge candidate and tested head have identical tree
c01e0ba1408227cea46d4121329eb536d1abc3a1.
Local Electron tests use controlled native clipboard metadata/provider boundaries. No manual Finder copy gesture, physical Windows UI, or live model request was performed. Initial local setup failures (missing preload and stale donor shared exports) were resolved by building candidate shared/preload; final runs above passed. No contributor source changes were needed.
Pasting a disk-backed file larger than 64 MiB currently fails after reading its bytes into the renderer. Native clipboard files now become live path references with byte sizes, so attaching them does not allocate, transfer, copy, hash, or upload their contents.
Main consumes the existing sender-bound selection token and records the canonical source/project with an opaque reference id. Composer displays the size; drafts, queued input, transcript storage, input history and runtime replay retain the metadata. Dispatch checks the registered path/project, rejects missing or redirected sources, and refreshes size. Subsequent reads use normal tool permissions, including outside-project approval.
Disk-backed images also use this lazy reference flow; an Agent can read them through normal tools. Screenshots and generated clipboard payloads retain the existing scratch/image transport. Native picker and drop behavior remain unchanged. The ADR, IPC/permission specs and E2E scenario describe the additive contract and live-file semantics.
Fixes #2314.
Validation
Base:
82823a6c0122a95d5cc3bb21e530d4b8522c61b1(freshorigin/main). Electron: lockfile-pinned43.6.0, macOS arm64. All fixtures use synthetic files and paths.All six GitHub checks passed at
047748de868b58f336a6a9d8ffe2eebe94c19fd4: Docs, latest-base ancestry, JS build/typecheck/lint/architecture/tests, Rust format/lint/tests, Windows transcript-cache E2E, and trusted-extensions Electron E2E. The PR merge candidated174a4728860c2edb8bd1ff09a4cb7d6afa2a26dhas the same executable tree as this validated head.cargo fmt --all -- --checkpassed.node scripts/e2e-composer-paste.mjs --screenshot-onlypassed, including four draft-race cases and screenshot/native-image compatibility controls.node scripts/e2e-composer-paste.mjspassed twice after correcting preview focus restoration, including keyboard/image compatibility, undo/redo, native files, session races and history restoration in a second Electron process.node scripts/e2e-composer-paste.mjs --file-references-onlypassed, exercising real disk-backed ElectronFileobjects, React Composer hooks, preload IPC, native clipboard parsing, sender-bound selection tokens, persisted registration and prompt preparation. Sparse 64 MiB + 1 byte and small outside-project files never read bytes into the renderer or use the scratch byte writer. The test verifies card size, refreshed dispatch size after editing the source, metadata-only history recall, remount and recovery/send in a second Electron process.Compatibility correction
Full paste validation exposed an existing image-preview focus ordering defect, also reproducible on the unchanged base. Restoring a saved selection after focusing the original control can refocus the editing host. This PR restores the selection first and the original control last, with a deterministic regression and the strict Electron focus check retained.
The Electron fixture controls clipboard URI-list metadata at the native OS boundary and controls external provider delivery; it does not automate a manual Finder copy gesture or make a live external provider call. Original files remain live: later reads observe edits, and moved/deleted files require a new reference.