Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(composer): preserve existing attachments during pending paste
yuxino623d5261f3dc
diff --git a/apps/desktop/src/features/chat/composer/hooks/useComposerAttachments.ts b/apps/desktop/src/features/chat/composer/hooks/useComposerAttachments.tsindex 55d4f0ed1..f0afce4a7 100644--- a/apps/desktop/src/features/chat/composer/hooks/useComposerAttachments.ts+++ b/apps/desktop/src/features/chat/composer/hooks/useComposerAttachments.ts@@ -173,6 +173,7 @@ export function useComposerAttachments({const sourceValue = readEditorValue(editor);const sourceSessionId = activeSessionId;const sourceDraftKey = draftKey;+ const previousReferences = snapshotReferences(sourceSessionId ?? "");setPasting(true);try {const payload = files.length@@ -218,7 +219,6 @@ export function useComposerAttachments({sourceValue.slice(0, selectionStart) +inserted +sourceValue.slice(selectionEnd);- const previousReferences = snapshotReferences(sourceSessionId ?? "");const nextReferences = [...previousReferences.map((reference) =>createFileReference(reference.path, reference.name, sessionId!, reference),diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex e45b35364..c0256dedb 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -2722,7 +2722,9 @@ reasoning-level control.— empty-home ↔ docked, chat ↔ Settings/Plugins/other pages, or the windowhiding and showing — restores the same slot. Switching sessions saves thesource draft and restores the target draft; an uncached target and every- newly created session start empty. The no-active-session home composer has+ newly created session start empty. A pending paste retains the source+ draft's existing file references even if saving finishes after a session switch.+ The no-active-session home composer hasits own slot. A successful send clears only the submitting session's slot,including when navigation occurs while the request is in flight, anddeleting a session drops its slot. If the contenteditable DOM is wiped whilediff --git a/scripts/e2e/composer-paste.tsx b/scripts/e2e/composer-paste.tsxindex 122b55a71..a47c0c747 100644--- a/scripts/e2e/composer-paste.tsx+++ b/scripts/e2e/composer-paste.tsx@@ -190,6 +190,37 @@ globalThis.composerPasteProbe = async () => {selection.addRange(range);};try {+ // Keep the source attachment snapshot when a paste finishes in another session.+ await reset("keep \uE010 ", 7, 7);+ const originalReference = createFileReference("/scratch/paste-a/original.txt", "original.txt", "paste-a", { token: "\uE010", kind: "file" });+ flushSync(() => controller.applyEditorDraft("keep \uE010 ", [originalReference], 7));+ await new Promise(requestAnimationFrame);+ const originalPasteFiles = api.pasteFiles;+ let releasePaste!: () => void;+ const responseGate = new Promise<void>((resolve) => { releasePaste = resolve; });+ let started = false;+ api.pasteFiles = async () => {+ started = true;+ await responseGate;+ return { files: [{ path: "/scratch/paste-a/new.txt", name: "new.txt", kind: "file", mimeType: "text/plain" }] };+ };+ try {+ const pendingPaste = dispatchPaste(controller.ref.current!, "", [new File(["new"], "new.txt", {type: "text/plain"})]);+ while (!started) await new Promise(requestAnimationFrame);+ render("paste-b");+ await new Promise(requestAnimationFrame);+ releasePaste();+ await pendingPaste;+ assert(controller.value === "", "pending paste changed the destination draft");+ render("paste-a");+ await new Promise(requestAnimationFrame);+ const names = controller.fileReferences.map((r) => r.name);+ assert(names.includes("original.txt") && names.includes("new.txt"),+ "PENDING_PASTE_SESSION_SWITCH lost original attachment: " + JSON.stringify({ names, text: readEditorValue(controller.ref.current!), visible: controller.ref.current!.textContent }));+ } finally {+ releasePaste();+ api.pasteFiles = originalPasteFiles;+ }const nativeFiles = Array.from((document.getElementById("native-files") as HTMLInputElement).files!,);@@ -665,6 +696,7 @@ globalThis.composerPasteProbe = async () => {imageZoomFocusAndRecovery: true,nativeMultipleFiles: true,selectionAndSessionDrafts: true,+ pendingPasteAcrossSessionSwitch: true,};} finally {flushSync(() => root.unmount());