Skip to content

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

fix(composer): guard draft clearing with revisions

vastsaee8dc11670cb
diff --git a/apps/desktop/src/components/Composer.tsx b/apps/desktop/src/components/Composer.tsx
index 153264d16..68325433c 100644
--- a/apps/desktop/src/components/Composer.tsx
+++ b/apps/desktop/src/components/Composer.tsx
@@ -184,6 +184,7 @@ export function Composer({
applyEditorDraft,
snapshotReferences,
draftSnapshot,
+ draftRevision,
clearDraftForKey,
restoreDraftForKey,
persistDraft,
@@ -426,6 +427,7 @@ export function Composer({
draft: {
ref,
draftSnapshot,
+ draftRevision,
clearDraftForKey,
restoreDraftForKey,
setValue,
diff --git a/apps/desktop/src/features/chat/composer/hooks/useComposerDraft.ts b/apps/desktop/src/features/chat/composer/hooks/useComposerDraft.ts
index 46e046541..eb50e1988 100644
--- a/apps/desktop/src/features/chat/composer/hooks/useComposerDraft.ts
+++ b/apps/desktop/src/features/chat/composer/hooks/useComposerDraft.ts
@@ -23,9 +23,11 @@ import {
draftOwnerSessionId,
flushScheduledHomeDraftAdopt,
pruneComposerDrafts,
- snapshotComposerDraft,
readComposerDraft,
+ readComposerDraftRevision,
+ snapshotComposerDraft,
writeComposerDraft,
+ markComposerDraftEdited,
} from "../../../../lib/composer-draft-cache";
import {
editorSelectionRange,
@@ -81,10 +83,15 @@ export type ComposerDraftController = {
) => void;
snapshotReferences: (sourceSessionId: string) => ComposerDraftSnapshot["fileReferences"];
draftSnapshot: (text: string) => ComposerDraftSnapshot;
- clearDraftForKey: (key: string, submitted?: ComposerDraftSnapshot) => void;
+ draftRevision: (key: string) => number;
+ clearDraftForKey: (
+ key: string,
+ expectedRevision?: number,
+ submitted?: ComposerDraftSnapshot,
+ ) => void;
restoreDraftForKey: (key: string, snapshot: ComposerDraftSnapshot) => void;
-};
+};
type UseComposerDraftOptions = {
variant: "home" | "docked";
activeSessionId: string | null | undefined;
@@ -155,6 +162,32 @@ export function useComposerDraft({
valueRef.current = value;
const fileReferencesRef = useRef(fileReferences);
fileReferencesRef.current = fileReferences;
+
+ // Expose React-compatible setters while recording only real content changes.
+ const setDraftValue: Dispatch<SetStateAction<string>> = (action) => {
+ const current = valueRef.current;
+ const next = typeof action === "function" ? action(current) : action;
+ if (next !== current) {
+ markComposerDraftEdited(draftKeyRef.current);
+ valueRef.current = next;
+ }
+ setValue(next);
+ };
+ const setDraftFileReferences: Dispatch<SetStateAction<ComposerFileReference[]>> = (action) => {
+ const current = fileReferencesRef.current;
+ const next = typeof action === "function" ? action(current) : action;
+ const currentOwned = current.filter((reference) => reference.sessionId === referenceSessionId);
+ const nextOwned = next.filter((reference) => reference.sessionId === referenceSessionId);
+ const changed = currentOwned.length !== nextOwned.length || currentOwned.some((reference, index) => {
+ const nextReference = nextOwned[index];
+ return !nextReference || reference.path !== nextReference.path ||
+ reference.name !== nextReference.name || reference.kind !== nextReference.kind ||
+ reference.mimeType !== nextReference.mimeType || reference.token !== nextReference.token;
+ });
+ if (changed) markComposerDraftEdited(draftKeyRef.current);
+ fileReferencesRef.current = next;
+ setFileReferences(next);
+ };
const activeFileReferences = fileReferences.filter(
(fileReference) => fileReference.sessionId === referenceSessionId,
);
@@ -279,6 +312,7 @@ export function useComposerDraft({
const index = source.indexOf(token);
if (index === -1) return;
const next = source.slice(0, index) + source.slice(index + 1);
+ markComposerDraftEdited(draftKeyRef.current);
invalidatePromptEnhancement();
// Leave the DOM value stale so the layout effect removes the chip.
pendingEditorCaretRef.current = index;
@@ -296,6 +330,7 @@ export function useComposerDraft({
valueRef.current === ""
? rewriteIdeographicCommaTrigger(source)
: source;
+ markComposerDraftEdited(draftKeyRef.current);
invalidatePromptEnhancement();
if (nextValue === source) {
editorValueRef.current = nextValue;
@@ -317,6 +352,7 @@ export function useComposerDraft({
if (!element) return;
const nextValue = readEditorValue(element);
const { start } = editorSelectionRange(element);
+ markComposerDraftEdited(draftKeyRef.current);
invalidatePromptEnhancement();
editorValueRef.current = nextValue;
valueRef.current = nextValue;
@@ -428,6 +464,7 @@ export function useComposerDraft({
isPersistedScratchReference(fileReference.path),
);
if (kept.length === current.length) return;
+ markComposerDraftEdited(draftKeyRef.current);
const droppedTokens = new Set(
current
.filter((fileReference) => !isPersistedScratchReference(fileReference.path))
@@ -460,6 +497,7 @@ export function useComposerDraft({
useEffect(() => {
if (!composerPrefill || composerPrefill.sessionId !== activeSessionId) return;
+ markComposerDraftEdited(draftKeyForSession(composerPrefill.sessionId));
setValue(composerPrefill.text);
setFileReferences((current) => [
...current.filter(
@@ -480,6 +518,7 @@ export function useComposerDraft({
useEffect(() => {
if (!prefill?.text) return;
+ markComposerDraftEdited(draftKeyRef.current);
setValue(prefill.text);
setFileReferences([]);
requestAnimationFrame(() => {
@@ -499,6 +538,7 @@ export function useComposerDraft({
nextText = detached.text;
nextReferences = detached.references;
caret = detached.caret;
+ markComposerDraftEdited(draftKeyRef.current);
// A token may now refer to a different attachment even when text is equal.
editorValueRef.current = null;
pendingEditorCaretRef.current = caret;
@@ -573,8 +613,13 @@ export function useComposerDraft({
...(token ? { token } : {}),
}));
- const clearDraftForKey = (key: string, submitted?: ComposerDraftSnapshot) => {
+ const clearDraftForKey = (
+ key: string,
+ expectedRevision?: number,
+ submitted?: ComposerDraftSnapshot,
+ ) => {
const currentKey = draftKeyForSession(useAppStore.getState().activeSessionId);
+ if (expectedRevision !== undefined && readComposerDraftRevision(key) !== expectedRevision) return;
// Command completion owns only its submitted draft, including when the
// user has left this session and its newer draft now lives in the cache.
if (submitted) {
@@ -610,11 +655,15 @@ export function useComposerDraft({
const currentKey = draftKeyForSession(currentActiveSessionId);
if (currentKey !== key) {
const cached = readComposerDraft(key);
- if (!cached?.text && !cached?.fileReferences.length) writeComposerDraft(key, snapshot);
+ if (!cached?.text && !cached?.fileReferences.length) {
+ markComposerDraftEdited(key);
+ writeComposerDraft(key, snapshot);
+ }
return;
}
if (valueRef.current.trim()) return;
if (fileReferencesRef.current.some((reference) => reference.sessionId === (currentActiveSessionId ?? ""))) return;
+ markComposerDraftEdited(key);
const sessionId = currentActiveSessionId ?? "";
setValue(snapshot.text);
setFileReferences((current) => [
@@ -647,14 +696,14 @@ export function useComposerDraft({
removeImage: (id) => {
if (inputBlocked) return;
invalidatePromptEnhancement();
- setFileReferences((current) => current.filter((reference) => reference.id !== id));
+ setDraftFileReferences((current) => current.filter((reference) => reference.id !== id));
ref.current?.focus();
},
ref,
draftKey,
referenceSessionId,
value,
- setValue,
+ setValue: setDraftValue,
valueRef,
cursor,
setCursor,
@@ -664,7 +713,7 @@ export function useComposerDraft({
setInputFocused,
placeholderIndex,
fileReferences,
- setFileReferences,
+ setFileReferences: setDraftFileReferences,
activeFileReferences,
referenceByToken,
fileReferencesRef,
@@ -680,6 +729,7 @@ export function useComposerDraft({
applyEditorDraft,
snapshotReferences,
draftSnapshot,
+ draftRevision: readComposerDraftRevision,
clearDraftForKey,
restoreDraftForKey,
};
diff --git a/apps/desktop/src/features/chat/composer/hooks/useComposerSubmit.ts b/apps/desktop/src/features/chat/composer/hooks/useComposerSubmit.ts
index 7fd58ebde..d6c8c8dfc 100644
--- a/apps/desktop/src/features/chat/composer/hooks/useComposerSubmit.ts
+++ b/apps/desktop/src/features/chat/composer/hooks/useComposerSubmit.ts
@@ -40,6 +40,7 @@ type UseComposerSubmitOptions = {
ComposerDraftController,
| "ref"
| "draftSnapshot"
+ | "draftRevision"
| "clearDraftForKey"
| "restoreDraftForKey"
| "setValue"
@@ -207,6 +208,7 @@ export function useComposerSubmit({
}
invalidatePromptEnhancement();
const submittedDraftKey = draftKey;
+ const submittedDraftRevision = draft.draftRevision(submittedDraftKey);
const submittedDraft = draft.draftSnapshot(text);
// Slash dispatch stays local for builtin and extension commands, while
// templates, skills, and unknown aliases continue as normal prompt text. A
@@ -248,7 +250,7 @@ export function useComposerSubmit({
),
draft.draftSnapshot(visibleCommandBody),
);
- if (accepted) draft.clearDraftForKey(submittedDraftKey, submittedDraft);
+ if (accepted) draft.clearDraftForKey(submittedDraftKey, submittedDraftRevision, submittedDraft);
} catch (error) {
showToast(error instanceof Error ? error.message : String(error), {
variant: "error",
@@ -259,7 +261,7 @@ export function useComposerSubmit({
if (command.kind === "extension") {
try {
await runExtensionCommand(command.name, commandBody);
- draft.clearDraftForKey(submittedDraftKey, submittedDraft);
+ draft.clearDraftForKey(submittedDraftKey, submittedDraftRevision, submittedDraft);
} catch (error) {
showToast(error instanceof Error ? error.message : String(error), {
variant: "error",
@@ -271,7 +273,7 @@ export function useComposerSubmit({
try {
if (command.kind === "builtin") await runPaletteCommand(command.id);
else await api.executeCommand(command.id);
- draft.clearDraftForKey(submittedDraftKey, submittedDraft);
+ draft.clearDraftForKey(submittedDraftKey, submittedDraftRevision, submittedDraft);
} catch (error) {
showToast(error instanceof Error ? error.message : String(error), {
variant: "error",
@@ -285,7 +287,7 @@ export function useComposerSubmit({
showToast(t("errors.MODEL_NOT_CONFIGURED"), { variant: "error" });
return;
}
- draft.clearDraftForKey(submittedDraftKey, submittedDraft);
+ draft.clearDraftForKey(submittedDraftKey, submittedDraftRevision, submittedDraft);
const accepted = steering
? await steerPrompt(inlineContent, submittedDraft)
: await sendPrompt(inlineContent, submittedDraft);
diff --git a/apps/desktop/src/lib/composer-draft-cache.ts b/apps/desktop/src/lib/composer-draft-cache.ts
index 13ece819f..fce998c92 100644
--- a/apps/desktop/src/lib/composer-draft-cache.ts
+++ b/apps/desktop/src/lib/composer-draft-cache.ts
@@ -26,6 +26,8 @@ export type ComposerDraftFileInput = {
};
const cache = new Map<string, CachedComposerDraft>();
+const revisions = new Map<string, number>();
+let revisionCounter = 0;
export function draftKeyForSession(sessionId: string | null | undefined): string {
return sessionId ?? HOME_DRAFT_KEY;
@@ -63,6 +65,23 @@ export function readComposerDraft(key: string): CachedComposerDraft | undefined
return cache.get(key);
}
+/** Read a stable per-key version, assigning a unique baseline when first seen. */
+export function readComposerDraftRevision(key: string): number {
+ let revision = revisions.get(key);
+ if (revision === undefined) {
+ revision = ++revisionCounter;
+ revisions.set(key, revision);
+ }
+ return revision;
+}
+
+/** Mark a real draft edit with a globally unique, monotonically increasing version. */
+export function markComposerDraftEdited(key: string): number {
+ const revision = ++revisionCounter;
+ revisions.set(key, revision);
+ return revision;
+}
+
export function writeComposerDraft(
key: string,
snapshot: ComposerDraftSnapshot,
@@ -140,10 +159,14 @@ export function pruneComposerDrafts(keep: Iterable<string>): void {
for (const key of cache.keys()) {
if (!retain.has(key)) cache.delete(key);
}
+ for (const key of revisions.keys()) {
+ if (!retain.has(key)) revisions.delete(key);
+ }
}
/** Test-only: drop every slot so cases cannot leak into one another. */
export function resetComposerDraftCache(): void {
cache.clear();
+ revisions.clear();
scheduledHomeAdoptSessionId = null;
}
diff --git a/apps/desktop/test/composer-draft-cache.test.mjs b/apps/desktop/test/composer-draft-cache.test.mjs
index 1ad9d1eba..9bba60786 100644
--- a/apps/desktop/test/composer-draft-cache.test.mjs
+++ b/apps/desktop/test/composer-draft-cache.test.mjs
@@ -11,12 +11,14 @@ import {
captureComposerDraft,
deleteComposerDraft,
draftKeyForSession,
- flushScheduledHomeDraftAdopt,
- scheduleHomeDraftAdopt,
draftOwnerSessionId,
+ flushScheduledHomeDraftAdopt,
+ markComposerDraftEdited,
pruneComposerDrafts,
readComposerDraft,
+ readComposerDraftRevision,
resetComposerDraftCache,
+ scheduleHomeDraftAdopt,
snapshotComposerDraft,
writeComposerDraft,
} from "../src/lib/composer-draft-cache.ts";
@@ -36,6 +38,26 @@ test("draft keys isolate the home slot from a session id", () => {
assert.equal(draftOwnerSessionId("sess-1"), "sess-1");
});
+test("draft revisions distinguish edit-and-restore and remain isolated by key", () => {
+ const submitted = readComposerDraftRevision("session-a");
+ const edited = markComposerDraftEdited("session-a");
+ const restored = markComposerDraftEdited("session-a");
+ const otherSession = readComposerDraftRevision("session-b");
+ assert.notEqual(edited, submitted);
+ assert.notEqual(restored, edited);
+ assert.notEqual(otherSession, restored);
+ assert.equal(readComposerDraftRevision("session-a"), restored);
+});
+
+test("prune and reset discard revision entries without reusing old versions", () => {
+ const pruned = markComposerDraftEdited("pruned");
+ pruneComposerDrafts([]);
+ assert.notEqual(readComposerDraftRevision("pruned"), pruned);
+ const reset = markComposerDraftEdited("reset");
+ resetComposerDraftCache();
+ assert.notEqual(readComposerDraftRevision("reset"), reset);
+});
+
test("home snapshots keep file references owned by the empty session id", () => {
const snapshot = snapshotComposerDraft(
"see this",
@@ -146,10 +168,11 @@ test("composer hydrates from the shared cache and persists across unmount and hi
test("composer handles home drafts, deleted sessions, and async sends by key", () => {
assert.match(composer, /pruneComposerDrafts\(\[/);
assert.match(composer, /HOME_DRAFT_KEY,/);
- assert.match(composer, /const clearDraftForKey = \(key: string, submitted\?: ComposerDraftSnapshot\)/);
+ assert.match(composer, /const clearDraftForKey = \(\s*key: string,\s*expectedRevision\?: number,\s*submitted\?: ComposerDraftSnapshot/);
assert.match(composer, /deleteComposerDraft\(key\)/);
assert.match(composer, /draftKeyForSession\(useAppStore\.getState\(\)\.activeSessionId\)/);
assert.match(composer, /const submittedDraftKey = draftKey/);
- assert.match(composer, /clearDraftForKey\(submittedDraftKey, submittedDraft\)/);
+ assert.match(composer, /clearDraftForKey\(submittedDraftKey, submittedDraftRevision, submittedDraft\)/);
+ assert.match(composer, /readComposerDraftRevision\(key\) !== expectedRevision/);
assert.doesNotMatch(composer, /if \(accepted\) clearDraft\(\);/);
});
diff --git a/apps/desktop/test/composer-send-state.test.mjs b/apps/desktop/test/composer-send-state.test.mjs
index 037447970..f4100faba 100644
--- a/apps/desktop/test/composer-send-state.test.mjs
+++ b/apps/desktop/test/composer-send-state.test.mjs
@@ -248,10 +248,10 @@ test("send clears the composer before the round trip and restores a rejected dra
/if \(!steering && !modelReady\) \{\s*showToast\(t\("errors\.MODEL_NOT_CONFIGURED"\), \{ variant: "error" \}\);\s*return;\s*\}/,
);
// Optimistic clear, restore on rejection. The clear must precede the await.
- const clearAt = submit.indexOf("draft.clearDraftForKey(submittedDraftKey, submittedDraft);\n const accepted = steering");
+ const clearAt = submit.indexOf("draft.clearDraftForKey(submittedDraftKey, submittedDraftRevision, submittedDraft);\n const accepted = steering");
assert.ok(clearAt > 0, "draft must be cleared before awaiting sendPrompt");
assert.match(submit, /if \(!accepted\) draft\.restoreDraftForKey\(submittedDraftKey, submittedDraft\);/);
- assert.doesNotMatch(submit, /if \(accepted\) draft\.clearDraftForKey\(submittedDraftKey, submittedDraft\);\s*\};/);
+ assert.doesNotMatch(submit, /if \(accepted\) draft\.clearDraftForKey\(submittedDraftKey, submittedDraftRevision, submittedDraft\);\s*\};/);
const restore = draftHook.match(
/const restoreDraftForKey = \(key: string, snapshot: ComposerDraftSnapshot\) => \{[\s\S]*?\n \};/,
)?.[0] ?? "";
@@ -273,7 +273,7 @@ test("mode slash prefixes send the trailing prompt and retain failed drafts", ()
assert.match(submit, /const isModeCommand =/);
assert.match(
submit,
- /if \(isModeCommand && commandBody\)[\s\S]*?await runPaletteCommand\(command\.id\);[\s\S]*?const accepted = await sendPrompt\([\s\S]*?draft\.draftSnapshot\(visibleCommandBody\)[\s\S]*?if \(accepted\) draft\.clearDraftForKey\(submittedDraftKey, submittedDraft\);/,
+ /if \(isModeCommand && commandBody\)[\s\S]*?await runPaletteCommand\(command\.id\);[\s\S]*?const accepted = await sendPrompt\([\s\S]*?draft\.draftSnapshot\(visibleCommandBody\)[\s\S]*?if \(accepted\) draft\.clearDraftForKey\(submittedDraftKey, submittedDraftRevision, submittedDraft\);/,
);
assert.match(
submit,
@@ -281,7 +281,7 @@ test("mode slash prefixes send the trailing prompt and retain failed drafts", ()
);
assert.match(
submit,
- /const submittedDraft = draft\.draftSnapshot\(text\);[\s\S]*?draft\.clearDraftForKey\(submittedDraftKey, submittedDraft\);\s*const accepted = steering[\s\S]*?await steerPrompt\(inlineContent, submittedDraft\)[\s\S]*?await sendPrompt\(inlineContent, submittedDraft\);\s*if \(!accepted\) draft\.restoreDraftForKey\(submittedDraftKey, submittedDraft\);/,
+ /const submittedDraftRevision = draft\.draftRevision\(submittedDraftKey\);\s*const submittedDraft = draft\.draftSnapshot\(text\);[\s\S]*?draft\.clearDraftForKey\(submittedDraftKey, submittedDraftRevision, submittedDraft\);\s*const accepted = steering[\s\S]*?await steerPrompt\(inlineContent, submittedDraft\)[\s\S]*?await sendPrompt\(inlineContent, submittedDraft\);\s*if \(!accepted\) draft\.restoreDraftForKey\(submittedDraftKey, submittedDraft\);/,
);
assert.match(store, /draft\?: ComposerDraftSnapshot/);
const sendPrompt = queueSlice.slice(
diff --git a/docs/spec/04-ux/04-builtin-commands.md b/docs/spec/04-ux/04-builtin-commands.md
index 43f4b52c3..3edb54b04 100644
--- a/docs/spec/04-ux/04-builtin-commands.md
+++ b/docs/spec/04-ux/04-builtin-commands.md
@@ -98,10 +98,11 @@ the composer draft. Former builtin aliases are no longer resolved and are
handled as ordinary unknown slash text unless supplied by another command
source.
-When a command completes, it clears only the draft submitted with that command.
-Text or attachments edited while it runs remain available, including when the
-user switches sessions before completion. An unchanged command draft still
-clears on success; failed dispatch preserves the draft.
+When a command completes, it clears only the submitted draft if that draft has
+not been edited since submission. Any newer edit remains—even if the user
+changes the text or attachments back to exactly the submitted values—including
+when the user switches sessions before completion. An unchanged command draft
+still clears on success; failed dispatch preserves the draft.
## 8. Composer skill entries
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 59f18155f..7891c549f 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1389,13 +1389,18 @@ identify the platform validation still needed.
#### E2E-011c-1: Preserve newer drafts after command completion
-- **Steps**: In session A, submit `/compact` and hold the local model response.
- Replace the command text with a new draft, then release the response. Repeat
- with an image added to the unchanged command text, and with navigation to B
- before completion. Finally run the command without editing its draft.
-- **Expected**: Completion preserves the newer text and image attachments in A;
- B's draft is untouched. Returning to A restores its newer draft. An unchanged
- submitted command draft clears after success.
+- **Preconditions**: Sessions A and B exist; the `/compact` API response can be held pending.
+- **Steps**: In A, submit `/compact` and hold its response. Replace the command
+ text with a new draft, then release the response. Repeat with an image added
+ to the unchanged command text, and with navigation to B before completion.
+ For the `reentered` variant, while compact is pending replace the editor text
+ with temporary text and dispatch `input`, then type the exact `/compact`
+ again and dispatch `input` before releasing the response. Finally run the
+ command without editing its draft.
+- **Expected**: Completion preserves newer text and image attachments in A;
+ B's draft is untouched, and returning to A restores its newer draft. The
+ `reentered` case still displays `/compact` after success even though its final
+ text equals the submitted value. An unchanged submitted command draft clears.
- **Coverage**: `scripts/e2e/composer-submission.tsx`, executed by
`pnpm test:e2e:composer-paste`; real desktop recording uses isolated data and
a local model with a controlled response delay.
@@ -8250,6 +8255,7 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.
| A / C / F / Quality — Tray session navigation | E2E-TRAY-bounded-session-navigation |
| B — Model config | E2E-005, E2E-006, E2E-007, E2E-038, E2E-050, E2E-052, E2E-055, E2E-066, E2E-080, E2E-082, E2E-102c, E2E-102d, E2E-102e, E2E-151, E2E-154, E2E-163, E2E-166, E2E-172, E2E-174, E2E-197, E2E-005G, E2E-005J, E2E-199, E2E-201, E2E-202, E2E-203, E2E-205, E2E-206, E2E-209 |
| C — Conversation & stream | E2E-CHAT-running-status-survives-output-pauses, E2E-008, E2E-008d, E2E-008e, E2E-008a, E2E-009, E2E-010, E2E-011, E2E-011a, E2E-011b, E2E-011d, E2E-011e, E2E-011g, E2E-031, E2E-040, E2E-047, E2E-048, E2E-048A, E2E-049, E2E-052, E2E-053, E2E-054, E2E-055, E2E-059, E2E-059a, E2E-060c, E2E-060d, E2E-061, E2E-061a, E2E-062, E2E-064, E2E-065, E2E-068, E2E-071, E2E-073, E2E-074, E2E-075, E2E-081, E2E-083, E2E-084, E2E-086, E2E-087, E2E-088, E2E-088b, E2E-089, E2E-090, E2E-COMPOSER-narrow-controls, E2E-094, E2E-095, E2E-096, E2E-097, E2E-098, E2E-099, E2E-102, E2E-102a, E2E-102b, E2E-102c, E2E-102d, E2E-102g, E2E-106, E2E-109, E2E-111, E2E-114, E2E-116, E2E-117, E2E-118, E2E-119, E2E-120, E2E-121, E2E-218, E2E-259, E2E-219, E2E-AGENTS-001, E2E-142, E2E-144, E2E-145, E2E-146, E2E-146a, E2E-147, E2E-151, E2E-154, E2E-155, E2E-158, E2E-159, E2E-161, E2E-162, E2E-166, E2E-172, E2E-173, E2E-174, E2E-177, E2E-178, E2E-179, E2E-180, E2E-182, E2E-183, E2E-187, E2E-198, E2E-199, E2E-202, E2E-203, E2E-207, E2E-208, E2E-CHAT-content-width-handles, E2E-250, E2E-102i, E2E-PLUGIN-session-orchestrator-real-workers, E2E-SUBAGENT-settlement-updates-before-parent-poll, E2E-SUBAGENT-resume-a-settled-delegation |
+| C — Conversation & stream (composer drafts) | E2E-011c, E2E-011c-1 |
| D — Workspace | E2E-012, E2E-013, E2E-022B, E2E-024I, E2E-047, E2E-049, E2E-057, E2E-058, E2E-060, E2E-068, E2E-075, E2E-078, E2E-153, E2E-158, E2E-182, E2E-187, E2E-252 |
| D — Workspace (project ordering) | E2E-253 |
| E — Tools & permissions | E2E-008a, E2E-014, E2E-015, E2E-016, E2E-017, E2E-018, E2E-019, E2E-024I, E2E-024K, E2E-040, E2E-049, E2E-074, E2E-093, E2E-097, E2E-099, E2E-100, E2E-101, E2E-102, E2E-102d, E2E-102e, E2E-102g, E2E-103, E2E-105, E2E-106, E2E-107, E2E-111, E2E-112, E2E-113, E2E-114, E2E-115, E2E-116, E2E-119, E2E-121, E2E-122, E2E-142, E2E-145, E2E-147, E2E-155, E2E-158, E2E-166, E2E-181, E2E-PLUGIN-imported-pi-package-skills |
diff --git a/docs/zh-CN/spec/04-ux/04-builtin-commands.md b/docs/zh-CN/spec/04-ux/04-builtin-commands.md
index 9bd8c0059..4c9d6e1aa 100644
--- a/docs/zh-CN/spec/04-ux/04-builtin-commands.md
+++ b/docs/zh-CN/spec/04-ux/04-builtin-commands.md
@@ -83,8 +83,9 @@ type CommandExecutionResult =
只执行本地切换。提示正文仍是可见的用户回合;dispatch 失败不会清除输入框草稿。
旧的内置别名不再解析,除非由其他命令来源提供,否则会作为普通未知斜杠文本处理。
-命令完成时,只清除该命令提交时的草稿。执行期间新写的文字或新改的附件必须保留,
-即使用户在完成前切换了会话。未发生变化的命令草稿仍在成功后清空;执行失败时保留草稿。
+命令完成时,只清除提交时的草稿,且前提是该草稿此后没有被编辑。之后发生的任何编辑都必须保留,
+即使文字或附件后来又恢复成与提交时完全相同的内容;用户在完成前切换会话也一样。未编辑的命令草稿
+仍会在成功后清空;执行失败时保留草稿。
## 8. 输入框中的 Skill 项
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index aef460368..4da9bfde0 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -647,14 +647,15 @@ task-candidate E2E 从请求工作树运行,但使用主工作区已经准备
#### E2E-011c-1:命令完成后保留新草稿
-- **步骤**:在会话 A 发送 `/compact`,暂缓本地模型响应。将命令文字替换为新草稿,
- 然后释放响应。分别重复测试:在未修改的命令文字旁添加图片、在完成前切换至 B,
- 以及执行期间不修改草稿。
-- **预期**:命令完成后,A 的新文字与图片附件仍然保留;B 的草稿不受影响。返回 A
- 仍可看到新草稿。没有变化的命令草稿在成功后正常清空。
+- **先决条件**:会话 A、B 均存在;可暂停 `/compact` API 响应。
+- **步骤**:在 A 发送 `/compact` 并暂停响应。将命令文字替换为新草稿后释放响应;
+ 分别重复测试:在未修改的命令文字旁添加图片,以及完成前切换至 B。测试 `reentered` 变体时,
+ 在 compact pending 期间先将编辑器改为临时文字并 dispatch `input`,再输入完全相同的 `/compact`
+ 并再次 dispatch `input`,然后释放响应。最后运行一次完全未编辑的命令。
+- **预期**:完成后 A 的新文字和图片附件仍保留,B 的草稿不受影响,返回 A 后可恢复其新草稿。
+ `reentered` 即使最终文字与提交值相同,成功后仍显示 `/compact`;未编辑的提交草稿则正常清空。
- **覆盖**:`scripts/e2e/composer-submission.tsx`,由
- `pnpm test:e2e:composer-paste` 执行;真实桌面录屏使用隔离数据,以及响应时间受控的
- 本地模型。
+ `pnpm test:e2e:composer-paste` 执行;真实桌面录屏使用隔离数据,以及响应时间受控的本地模型。
### 对话顶部栏
@@ -5299,6 +5300,7 @@ eleven-tool-round desktop paths are verified by
| A — 应用程序启动 | E2E-001、E2E-002、E2E-003、E2E-004、E2E-067、E2E-076、E2E-079、E2E-092、E2E-097、E2E-143、E2E-150、E2E-168、E2E-204、E2E-217 |
| B——模型配置 | E2E-005、E2E-005G、E2E-006、E2E-007、E2E-038、E2E-050、E2E-052、E2E-055、E2E-066、E2E-080、E2E-082、E2E-151、E2E-005J、E2E-199、E2E-201、E2E-202、E2E-203、E2E-209、E2E-166 |
| C — 对话和直播 | E2E-CHAT-running-status-survives-output-pauses、E2E-008、E2E-008d、E2E-008a、E2E-009、E2E-010、E2E-011、E2E-011a、E2E-011b、E2E-031、E2E-040、E2E-047、E2E-048、E2E-048A、E2E-049、E2E-052、 E2E-053、E2E-054、E2E-055、E2E-059、E2E-059a、E2E-060c、E2E-060d、E2E-061、E2E-061a、E2E-062、E2E-064、E2E-065、E2E-068、E2E-071、 E2E-073、E2E-074、E2E-075、E2E-081、E2E-083、E2E-084、E2E-086、E2E-087、E2E-088、E2E-088b、E2E-089、E2E-090、E2E-094、E2E-095、E2E-096、 E2E-097、E2E-098、E2E-099、E2E-102、E2E-102a、E2E-102b、E2E-106、E2E-109、E2E-111、E2E-114、E2E-116、E2E-117、E2E-118、E2E-119、 E2E-120、E2E-121、E2E-代理-001、E2E-142、E2E-144、E2E-145、E2E-146、E2E-147、E2E-151、E2E-199、E2E-250、E2E-166、E2E-SUBAGENT-resume-a-settled-delegation |
+| C — 对话和直播(输入框草稿) | E2E-011c、E2E-011c-1 |
| A / C / F / Quality — Tray session navigation | E2E-TRAY-bounded-session-navigation |
| D——工作区 | E2E-012、E2E-013、E2E-022B、E2E-024I、E2E-047、E2E-049、E2E-057、E2E-058、E2E-060、E2E-068、E2E-075、E2E-078、E2E-153 |
| D——工作区(项目排序) | E2E-253 |
diff --git a/scripts/e2e/composer-submission.tsx b/scripts/e2e/composer-submission.tsx
index ab7822b6f..b3c6e6192 100644
--- a/scripts/e2e/composer-submission.tsx
+++ b/scripts/e2e/composer-submission.tsx
@@ -119,7 +119,7 @@ export async function verifyComposerSubmission(imagePath: string, i18n: i18n) {
id: "builtin.agent.compact", name: "compact", title: "Compact", kind: "builtin",
}] });
try {
- for (const change of ["text", "attachment", "switch", "unchanged"] as const) {
+ for (const change of ["text", "attachment", "switch", "unchanged", "reentered"] as const) {
let finish!: () => void;
let started!: () => void;
const entered = new Promise<void>((resolve) => { started = resolve; });
@@ -136,6 +136,11 @@ export async function verifyComposerSubmission(imagePath: string, i18n: i18n) {
await painted();
if (change === "attachment") {
prefill("/compact", [attachment]);
+ } else if (change === "reentered") {
+ editor().textContent = "Temporary draft during compaction";
+ flushSync(() => editor().dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertText" })));
+ editor().textContent = "/compact";
+ flushSync(() => editor().dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertText" })));
} else if (change !== "unchanged") {
editor().textContent = "Next message written during compaction";
flushSync(() => editor().dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertText" })));
@@ -155,8 +160,13 @@ export async function verifyComposerSubmission(imagePath: string, i18n: i18n) {
flushSync(() => useAppStore.setState({ activeSessionId: sessionId }));
await painted();
}
- assert(editor().textContent === (change === "unchanged" ? "" : change === "attachment" ? "/compact" : "Next message written during compaction"),
- `completed command must preserve a newer ${change} draft: ${JSON.stringify(editor().textContent)}`);
+ const expectedDraft = change === "unchanged"
+ ? ""
+ : change === "attachment" || change === "reentered"
+ ? "/compact"
+ : "Next message written during compaction";
+ assert(editor().textContent === expectedDraft,
+ `completed command must preserve the expected ${change} draft: ${JSON.stringify(editor().textContent)}`);
if (change === "attachment") assert(host.querySelectorAll(".composer-image-attachment").length === 1,
"completed command must preserve an image added while it was running");
}