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 queue edit cleanup and mentions
DavidShenb9f76de351eb
diff --git a/apps/desktop/src/renderer/__tests__/pendingQueueDefer.test.ts b/apps/desktop/src/renderer/__tests__/pendingQueueDefer.test.tsindex 93385682c6..c7965386b9 100644--- a/apps/desktop/src/renderer/__tests__/pendingQueueDefer.test.ts+++ b/apps/desktop/src/renderer/__tests__/pendingQueueDefer.test.ts@@ -435,6 +435,34 @@ describe('renderer input queue facade', () => {);});+ it('uses the editor mentions when visible text is unchanged', async () => {+ const sid = 'same-text-mentions-' + Math.random().toString(36).slice(2, 8);+ const item = queued('q-same-text-mentions', 'keep @src/app.ts');+ item.mentions = [{ type: 'file', name: 'app.ts', path: 'src/app.ts' }];++ makerChatStore.initGlobalListeners();+ projectionHandler?.(projection(sid, { pendingQueue: [item] }));++ const saved = await makerChatStore.updateQueueItemContent(sid, item.clientId, {+ content: {+ text: item.text,+ mentions: [],+ hasQuotes: false,+ agentReferences: [],+ pastedTextRanges: [],+ slashCommandRanges: [],+ },+ files: [],+ });++ expect(saved).toBe(true);+ expect(input.updateContent).toHaveBeenCalledWith(+ sid,+ item.clientId,+ expect.objectContaining({ mentions: [] }),+ );+ });+it('falls back to update-text when an old device-link target lacks update-content', async () => {const sid = `legacy-content-${Math.random().toString(36).slice(2, 8)}`;const item = queued('q-legacy-content', 'old text');diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsxindex 08a7d2ae98..d02d995ad7 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx@@ -1450,6 +1450,10 @@ export function CCAgentSessionView({const currentSessionIdRef = useRef(sessionId);currentSessionIdRef.current = sessionId;const queueComposerEditSavingRef = useRef(false);+ const queueComposerEditCleanupRef = useRef<{+ edit: QueueComposerEditState;+ files: readonly AttachedFile[];+ } | null>(null);const composerDraftKey = activeQueueComposerEdit?.draftKey ?? sessionId;const attachmentState = useAttachments(sessionId, composerDraftKey);const queueComposerEditAttachmentsRef = useRef<readonly AttachedFile[]>([]);@@ -1820,6 +1824,16 @@ export function CCAgentSessionView({},[],);+ const clearQueueComposerEditDraftWithFiles = useCallback(+ (edit: QueueComposerEditState, files: readonly AttachedFile[]) => {+ const filesById = new Map(files.map((file) => [file.id, file]));+ for (const file of getComposerDraft(edit.draftKey)?.attachments ?? []) {+ filesById.set(file.id, file);+ }+ clearQueueComposerEditDraft(edit, [...filesById.values()]);+ },+ [clearQueueComposerEditDraft],+ );const beginQueueComposerEdit = useCallback((entry: QueuedMessage) => {@@ -1859,6 +1873,7 @@ export function CCAgentSessionView({if (!edit || edit.clientId !== clientId || queueComposerEditSavingRef.current) return false;queueComposerEditSavingRef.current = true;let rowDisappeared = false;+ let updateSucceeded = false;try {const updated = await updateQueueItemContent(clientId, { content, files });if (!updated) {@@ -1867,6 +1882,7 @@ export function CCAgentSessionView({.pendingQueue.some((entry) => entry.clientId === clientId);return false;}+ updateSucceeded = true;clearComposerDraftAndNotify(edit.draftKey);if (!isCurrentQueueComposerEdit(edit)) return true;attachmentState.clearFiles();@@ -1875,15 +1891,22 @@ export function CCAgentSessionView({return true;} finally {queueComposerEditSavingRef.current = false;- if (rowDisappeared) {+ const pendingCleanup =+ queueComposerEditCleanupRef.current?.edit.draftKey === edit.draftKey+ ? queueComposerEditCleanupRef.current+ : null;+ if (pendingCleanup) queueComposerEditCleanupRef.current = null;+ if (!updateSucceeded && pendingCleanup) {+ queueMicrotask(() =>+ clearQueueComposerEditDraftWithFiles(edit, [...pendingCleanup.files, ...files]),+ );+ } else if (rowDisappeared && !pendingCleanup) {queueMicrotask(() => {if (isCurrentQueueComposerEdit(edit)) {cancelQueueComposerEdit();return;}- const draftFiles = getComposerDraft(edit.draftKey)?.attachments ?? [];- const filesById = new Map([...draftFiles, ...files].map((file) => [file.id, file]));- clearQueueComposerEditDraft(edit, [...filesById.values()]);+ clearQueueComposerEditDraftWithFiles(edit, files);});}}@@ -1893,6 +1916,7 @@ export function CCAgentSessionView({attachmentState,cancelQueueComposerEdit,clearQueueComposerEditDraft,+ clearQueueComposerEditDraftWithFiles,isCurrentQueueComposerEdit,updateQueueItemContent,],@@ -1900,19 +1924,17 @@ export function CCAgentSessionView({useEffect(() => {return () => {- if (queueComposerEditSavingRef.current) return;const edit = queueComposerEditRef.current;if (!edit || edit.sessionId !== sessionId) return;- const filesById = new Map(- queueComposerEditAttachmentsRef.current.map((file) => [file.id, file]),- );- for (const file of getComposerDraft(edit.draftKey)?.attachments ?? []) {- filesById.set(file.id, file);+ const files = [...queueComposerEditAttachmentsRef.current];+ if (queueComposerEditSavingRef.current) {+ queueComposerEditCleanupRef.current = { edit, files };+ return;}- clearQueueComposerEditDraft(edit, [...filesById.values()]);+ clearQueueComposerEditDraftWithFiles(edit, files);queueComposerEditRef.current = null;};- }, [clearQueueComposerEditDraft, sessionId]);+ }, [clearQueueComposerEditDraftWithFiles, sessionId]);useEffect(() => {if (queueComposerEdit && queueComposerEdit.sessionId !== sessionId) {diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex d0da651908..858952ab75 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -13760,7 +13760,7 @@ async function updateQueueItemContent(queued.permissionMode,queued.workingDir,preparedFiles,- textUnchanged ? queued.mentions : content.mentions,+ content.mentions,{...(queued.vendorOptions ? { vendorOptions: queued.vendorOptions } : {}),...((textUnchanged ? queued.chatMessage.quotesEncoded === true : content.hasQuotes)