Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 保留队列 Pi 技能别名
DavidShen9c15da2c6422
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsxindex 564cc5cbf2..9a37598021 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx@@ -245,6 +245,7 @@ import { cleanupStagedChatAttachmentFiles } from '@/lib/chatAttachmentStageCleanimport {isQueueComposerEditCurrent,queueMessageToComposerEditDraft,+ rebaseQueueComposerEditContentAfterSlashCommandRewrite,type QueueComposerEditState,} from '@/lib/queueComposerEdit';import type { SerializedComposerContent } from '@/components/new-chat/composerContentSerialization';@@ -1867,61 +1868,6 @@ export function CCAgentSessionView({isCurrentQueueComposerEdit,]);- const submitQueueComposerEdit = useCallback(- async (clientId: string, content: SerializedComposerContent, files: AttachedFile[]) => {- const edit = activeQueueComposerEdit;- 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) {- rowDisappeared = !makerChatStore- .getSnapshot(edit.sessionId)- .pendingQueue.some((entry) => entry.clientId === clientId);- return false;- }- updateSucceeded = true;- clearComposerDraftAndNotify(edit.draftKey);- if (!isCurrentQueueComposerEdit(edit)) return true;- attachmentState.clearFiles();- queueComposerEditRef.current = null;- setQueueComposerEdit(null);- return true;- } finally {- queueComposerEditSavingRef.current = false;- 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;- }- clearQueueComposerEditDraftWithFiles(edit, files);- });- }- }- },- [- activeQueueComposerEdit,- attachmentState,- cancelQueueComposerEdit,- clearQueueComposerEditDraft,- clearQueueComposerEditDraftWithFiles,- isCurrentQueueComposerEdit,- updateQueueItemContent,- ],- );-useEffect(() => {return () => {const edit = queueComposerEditRef.current;@@ -3393,6 +3339,69 @@ export function CCAgentSessionView({],);+ const submitQueueComposerEdit = useCallback(+ async (clientId: string, content: SerializedComposerContent, files: AttachedFile[]) => {+ const edit = activeQueueComposerEdit;+ if (!edit || edit.clientId !== clientId || queueComposerEditSavingRef.current) return false;+ queueComposerEditSavingRef.current = true;+ let rowDisappeared = false;+ let updateSucceeded = false;+ try {+ const slashDispatch = await maybeDispatchDesktopSlashCommand(content.text, files, {+ allowDesktopDispatch: false,+ piRuntimeRetryDelaysMs: PI_RUNTIME_SKILL_RETRY_DELAYS_MS,+ });+ const contentForSave = rebaseQueueComposerEditContentAfterSlashCommandRewrite(+ content,+ slashDispatch.message,+ );+ const updated = await updateQueueItemContent(clientId, { content: contentForSave, files });+ if (!updated) {+ rowDisappeared = !makerChatStore+ .getSnapshot(edit.sessionId)+ .pendingQueue.some((entry) => entry.clientId === clientId);+ return false;+ }+ updateSucceeded = true;+ clearComposerDraftAndNotify(edit.draftKey);+ if (!isCurrentQueueComposerEdit(edit)) return true;+ attachmentState.clearFiles();+ queueComposerEditRef.current = null;+ setQueueComposerEdit(null);+ return true;+ } finally {+ queueComposerEditSavingRef.current = false;+ 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;+ }+ clearQueueComposerEditDraftWithFiles(edit, files);+ });+ }+ }+ },+ [+ activeQueueComposerEdit,+ attachmentState,+ cancelQueueComposerEdit,+ clearQueueComposerEditDraftWithFiles,+ isCurrentQueueComposerEdit,+ maybeDispatchDesktopSlashCommand,+ updateQueueItemContent,+ ],+ );+const handleWorkingDirChange = useCallback((newDir: string | null) => {// ChatInput already persists workingDir to server; we just refresh our local copy.diff --git a/apps/desktop/src/renderer/lib/__tests__/queueComposerEdit.test.ts b/apps/desktop/src/renderer/lib/__tests__/queueComposerEdit.test.tsindex 86f0abda91..8d1c44f4c1 100644--- a/apps/desktop/src/renderer/lib/__tests__/queueComposerEdit.test.ts+++ b/apps/desktop/src/renderer/lib/__tests__/queueComposerEdit.test.ts@@ -5,6 +5,7 @@ import {isQueueComposerEditCurrent,queueComposerEditDraftKey,queueMessageToComposerEditDraft,+ rebaseQueueComposerEditContentAfterSlashCommandRewrite,} from '@/lib/queueComposerEdit';function queuedMessage(): QueuedMessage {@@ -212,3 +213,35 @@ describe('isQueueComposerEditCurrent', () => {expect(isQueueComposerEditCurrent(edit, 'session-1', edit)).toBe(true);});});++describe('rebaseQueueComposerEditContentAfterSlashCommandRewrite', () => {+ it('preserves Pi runtime skill aliases and rebases inline ranges before saving', () => {+ const content = {+ text: '/git inspect pasted',+ mentions: [],+ hasQuotes: false,+ agentReferences: [{+ kind: 'session' as const,+ start: 13,+ end: 19,+ href: 'cindy://session/source',+ sessionId: 'source',+ }],+ pastedTextRanges: [{ start: 13, end: 19, display: 'selection' }],+ slashCommandRanges: [{ start: 0, end: 4 }],+ };++ expect(+ rebaseQueueComposerEditContentAfterSlashCommandRewrite(+ content,+ '/skill:git inspect pasted',+ ),+ ).toEqual({+ ...content,+ text: '/skill:git inspect pasted',+ agentReferences: [{ ...content.agentReferences[0], start: 19, end: 25 }],+ pastedTextRanges: [{ start: 19, end: 25, display: 'selection' }],+ slashCommandRanges: [{ start: 0, end: 10 }],+ });+ });+});diff --git a/apps/desktop/src/renderer/lib/queueComposerEdit.ts b/apps/desktop/src/renderer/lib/queueComposerEdit.tsindex e8a6fbb13b..0c9d615897 100644--- a/apps/desktop/src/renderer/lib/queueComposerEdit.ts+++ b/apps/desktop/src/renderer/lib/queueComposerEdit.ts@@ -6,7 +6,8 @@ import { formatQuoteForSend, parseChatQuoteSegments, type ChatQuoteSegment } froimport { COMPOSER_QUOTE_NODE_TYPE } from '@/lib/composerQuoteDocument';import { normalizeComposerDocumentJSON } from '@/lib/composerListDocument';import { extractExt, getMimeType, type AttachedFile } from '@/lib/fileTypes';-import type { QueuedMessage } from '@/lib/makerChatStore';+import type { QueuedMessage, QueueItemContentUpdate } from '@/lib/makerChatStore';+import { rebaseInlineRangesAfterSlashCommandRewrite } from '@/lib/slashCommands';import { formatMentionRef } from '@/lib/mentionRefFormat';import type { AgentInputMention, AgentInputReference } from '../../shared/agentInputQueue';@@ -23,6 +24,31 @@ export interface QueueComposerEditState {originalAttachmentIds: string[];}+export function rebaseQueueComposerEditContentAfterSlashCommandRewrite<+ T extends QueueItemContentUpdate['content'],+>(content: T, rewrittenText: string): T {+ if (rewrittenText === content.text) return content;+ return {+ ...content,+ text: rewrittenText,+ agentReferences: rebaseInlineRangesAfterSlashCommandRewrite(+ content.agentReferences,+ content.text,+ rewrittenText,+ ),+ pastedTextRanges: rebaseInlineRangesAfterSlashCommandRewrite(+ content.pastedTextRanges,+ content.text,+ rewrittenText,+ ),+ slashCommandRanges: rebaseInlineRangesAfterSlashCommandRewrite(+ content.slashCommandRanges,+ content.text,+ rewrittenText,+ ),+ };+}+export function isQueueComposerEditCurrent(current: QueueComposerEditState | null,sessionId: string | undefined,