Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): preserve plan mode composer drafts
nothingyuancandoffa739e517ae
diff --git a/apps/desktop/src/renderer/__tests__/planModeComposerCommand.test.ts b/apps/desktop/src/renderer/__tests__/planModeComposerCommand.test.tsindex d6e641f40f..8510a59b5a 100644--- a/apps/desktop/src/renderer/__tests__/planModeComposerCommand.test.ts+++ b/apps/desktop/src/renderer/__tests__/planModeComposerCommand.test.ts@@ -6,6 +6,7 @@ import {addPlanModeComposerCommand,consumePlanModeComposerCommand,isPlanModeComposerCommandText,+ planModeComposerDraftText,shouldPreservePlanModeComposerDraft,} from '../components/new-chat/planModeComposerCommand';import type { UnifiedCommand } from '../lib/slashCommands';@@ -84,4 +85,19 @@ describe('/plan composer command', () => {expect(shouldPreservePlanModeComposerDraft(0, 1)).toBe(true);expect(shouldPreservePlanModeComposerDraft(0, 0)).toBe(false);});++ it('captures editor text before the plan command clears the editor', () => {+ const editorText = {+ type: 'doc',+ content: [{ type: 'paragraph', content: [{ type: 'text', text: 'keep me' }] }],+ };+ const storedText = {+ type: 'doc',+ content: [{ type: 'paragraph', content: [{ type: 'text', text: 'stored' }] }],+ };++ expect(planModeComposerDraftText(true, editorText, storedText)).toBe(editorText);+ expect(planModeComposerDraftText(false, null, storedText)).toBe(storedText);+ expect(planModeComposerDraftText(true, null, storedText)).toBeNull();+ });});diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex d6eff82946..c33a8e5f99 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -158,6 +158,7 @@ import {addPlanModeComposerCommand,consumePlanModeComposerCommand,isPlanModeComposerCommandText,+ planModeComposerDraftText,shouldPreservePlanModeComposerDraft,} from './planModeComposerCommand';import { PendingQueuePanel } from './PendingQueuePanel';@@ -5042,6 +5043,13 @@ export function ChatInput({editorStorageKey: storageKeyForDraftRef.current,sourceStorageKey,});+ const existingDraft = sourceStorageKey ? getComposerDraft(sourceStorageKey) : undefined;+ // Capture this before consuming `/plan`, which clears the live editor.+ const draftText = planModeComposerDraftText(+ editorOwnsSource,+ editorOwnsSource ? editor.getJSON() : null,+ existingDraft?.text,+ );if (editorOwnsSource) {planModeEntry?.onToggle(!planModeEntry.enabled);isRestoringRef.current = true;@@ -5058,11 +5066,10 @@ export function ChatInput({if (shouldPreservePlanModeComposerDraft(attachmentsForSend.length, commentsForSend.length)) {- const existingDraft = getComposerDraft(sourceStorageKey);saveComposerDraft(sourceStorageKey,{- text: editorOwnsSource ? editor.getJSON() : (existingDraft?.text ?? null),+ text: draftText,attachments: attachmentsForSend,quotes: existingDraft?.quotes ?? [],browserComments: commentsForSend,diff --git a/apps/desktop/src/renderer/components/new-chat/planModeComposerCommand.ts b/apps/desktop/src/renderer/components/new-chat/planModeComposerCommand.tsindex d143059a96..8258a98a85 100644--- a/apps/desktop/src/renderer/components/new-chat/planModeComposerCommand.ts+++ b/apps/desktop/src/renderer/components/new-chat/planModeComposerCommand.ts@@ -1,4 +1,5 @@import type { Transaction } from '@tiptap/pm/state';+import type { JSONContent } from '@tiptap/core';import type { UnifiedCommand } from '@/lib/slashCommands';@@ -56,3 +57,12 @@ export function shouldPreservePlanModeComposerDraft(): boolean {return attachmentCount > 0 || browserCommentCount > 0;}++/** Capture text before consuming `/plan` clears the live editor. */+export function planModeComposerDraftText(+ editorOwnsSource: boolean,+ editorText: JSONContent | null | undefined,+ storedText: JSONContent | null | undefined,+): JSONContent | null {+ return (editorOwnsSource ? editorText : storedText) ?? null;+}