Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

merge: resolve composer regressions against latest main

yuxinof60e4989e024
diff --cc docs/spec/04-ux/08-component-spec.md
index b2cf5d729,c8855a6d6..7b928813f
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@@ -2721,11 -2741,10 +2741,12 @@@ reasoning-level control
session (D301). The cache is module-scoped, not instance state, so a remount
— empty-home ↔ docked, chat ↔ Settings/Plugins/other pages, or the window
hiding and showing — restores the same slot. Switching sessions saves the
- source draft and restores the target draft; an uncached target and every
- 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 has
+ source draft and restores the target draft. Restoring a composer in the same
+ workspace must retain relative `@` file references as well as absolute scratch
+ attachments; workspace-reference cleanup runs only when the workspace changes.
- An uncached target and every
- newly created session start empty. The no-active-session home composer has
++ An uncached target and every 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 has
its own slot. A successful send clears only the submitting session's slot,
including when navigation occurs while the request is in flight, and
deleting a session drops its slot. If the contenteditable DOM is wiped while
diff --cc scripts/e2e/composer-paste.tsx
index de3867c8f,a47c0c747..806aed972
--- a/scripts/e2e/composer-paste.tsx
+++ b/scripts/e2e/composer-paste.tsx
@@@ -190,32 -190,37 +190,63 @@@ globalThis.composerPasteProbe = async (
selection.addRange(range);
};
try {
+ // Settings replaces ChatSurface, then remounts the composer in the same
+ // workspace. Exercise the real draft hook and DOM across that lifecycle.
+ render("paste-a", "/project-a");
+ const referenceDraft = "Check \uE001 and \uE002";
+ const references = [
+ createFileReference("src/main.ts", "main.ts", "paste-a", { token: "\uE001" }),
+ createFileReference("/scratch/paste-a/notes.txt", "notes.txt", "paste-a", { token: "\uE002" }),
+ ];
+ flushSync(() => controller.applyEditorDraft(referenceDraft, references, referenceDraft.length));
+ await new Promise(requestAnimationFrame);
+ flushSync(() => root.render(null));
+ render("paste-a", "/project-a");
+ await new Promise(requestAnimationFrame);
+ assert(readEditorValue(controller.ref.current!) === referenceDraft,
+ "Settings round-trip lost a workspace file reference from the draft");
+ assert(controller.fileReferences.length === 2 && controller.ref.current!.textContent!.includes("main.ts"),
+ "Settings round-trip must restore both workspace and scratch chips");
+ render("paste-a", "/project-b");
+ await new Promise(requestAnimationFrame);
+ assert(readEditorValue(controller.ref.current!) === "Check and \uE002",
+ "changing workspace must still remove the previous workspace's chip");
+ assert(controller.fileReferences.length === 1 && controller.fileReferences[0].path === references[1].path,
+ "changing workspace must preserve scratch references");
+ flushSync(() => root.render(null));
+ resetComposerDraftCache();
+
+ // 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!,
);
@@@ -691,7 -696,7 +722,8 @@@
imageZoomFocusAndRecovery: true,
nativeMultipleFiles: true,
selectionAndSessionDrafts: true,
+ workspaceReferencesAcrossRemount: true,
+ pendingPasteAcrossSessionSwitch: true,
};
} finally {
flushSync(() => root.unmount());