Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(chat): preserve legacy summon fulfillment states
shenjiachengb74ec613d7d8
diff --git a/apps/desktop/src/renderer/__tests__/ghostSummonChip.test.tsx b/apps/desktop/src/renderer/__tests__/ghostSummonChip.test.tsxindex ea5ba132cd..581ee91826 100644--- a/apps/desktop/src/renderer/__tests__/ghostSummonChip.test.tsx+++ b/apps/desktop/src/renderer/__tests__/ghostSummonChip.test.tsx@@ -14,16 +14,24 @@import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { MemoryRouter } from 'react-router-dom';import '@/i18n';import i18n from '@/i18n';import { GhostFulfillmentContext, GhostSummonCard } from '@/components/chat/GhostSummonCard';import { expandCollapsedMessages, stripMessageSources } from '@/lib/shareConversationImage';-import type { GhostDirectiveDisplay } from '@/cindy-brain/ghostCommand';+import {+ commandDirectiveSegments,+ mentionDirectiveSegments,+ type GhostDirectiveDisplay,+} from '@/cindy-brain/ghostCommand';import type { HostCapabilityDirectiveDisplay } from '@/cindy-brain/hostCapabilityInvocation';import type { InstalledGhost } from '../../shared/ghost';import { collectGhostCallsByUserTurn } from '@/components/chat/MessageStream';import type { ChatMessage } from '@/lib/makerChatStore';+import { UserMessage } from '@/components/chat/UserMessage';+import { ConfirmDialogProvider } from '@/components/ui/confirm-dialog-provider';+import { Tooltip } from '@/components/ui/tooltip';const { installedGhostsMock } = vi.hoisted(() => ({installedGhostsMock: vi.fn(() => [] as InstalledGhost[]),@@ -90,6 +98,256 @@ const ROOT_ICON = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACconst ORG_ICON = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAFklEQVR4nGOYbPyKJMQwqmFUw/DVAABSy7AQ0SGg2gAAAABJRU5ErkJggg==';describe('GhostSummonCard(chip 形态)', () => {+ // PR #6392 P2 reviews: existing coverage starts with a prebuilt directive and+ // misses persisted directives through UserMessage's pill/chip decision.+ // Unit tier: one user message plus root/org ghost_call messages are parsed and+ // projected by production code; only the installed-list hook is replaced.+ describe('legacy directive fulfillment compatibility', () => {+ const legacyCommand = {+ kind: 'command',+ command: 'draw',+ name: 'Saved Helper',+ ghostId: 'helper',+ raw: '',+ } as const;+ const legacyMention = {+ kind: 'mention',+ ghosts: [{ name: 'Saved Helper', ghostId: 'helper' }],+ raw: '',+ } satisfies GhostDirectiveDisplay;+ const rootCall = { ghost_id: 'helper', namespace: null };+ const orgCall = { ghost_id: 'helper', namespace: 'acme' };+ const mixedMention = {+ kind: 'mention',+ ghosts: [+ { name: 'Saved Helper', ghostId: 'helper' },+ { name: 'Saved Organization', ghostId: '_ns__acme__helper' },+ ],+ raw: '',+ } satisfies GhostDirectiveDisplay;++ it.each<{+ label: string;+ directive: GhostDirectiveDisplay;+ body: string;+ calls: Record<string, unknown>[];+ called: boolean;+ icon: string | null;+ names?: string;+ }>([+ {+ label: 'old unqualified command / explicit root call',+ directive: legacyCommand,+ body: '$draw help',+ calls: [rootCall],+ called: true,+ icon: null,+ },+ {+ label: 'old unqualified command / encoded root call',+ directive: legacyCommand,+ body: '$draw help',+ calls: [{ ghost_id: '_root__helper' }],+ called: true,+ icon: null,+ },+ {+ label: 'old unqualified command / bare call',+ directive: legacyCommand,+ body: '$draw help',+ calls: [{ ghost_id: 'helper' }],+ called: true,+ icon: null,+ },+ {+ label: 'old unqualified command / organization only',+ directive: legacyCommand,+ body: '$draw help',+ calls: [orgCall],+ called: false,+ icon: null,+ },+ {+ label: 'old command with root suffix',+ directive: legacyCommand,+ body: '$draw/@root help',+ calls: [rootCall],+ called: true,+ icon: ROOT_ICON,+ },+ {+ label: 'old command with organization suffix / root only',+ directive: legacyCommand,+ body: '$draw/acme help',+ calls: [rootCall],+ called: false,+ icon: ORG_ICON,+ },+ {+ label: 'old command with organization suffix / organization',+ directive: legacyCommand,+ body: '$draw/acme help',+ calls: [orgCall],+ called: true,+ icon: ORG_ICON,+ },+ {+ label: 'explicit null command',+ directive: { ...legacyCommand, namespace: null },+ body: '$draw help',+ calls: [rootCall],+ called: true,+ icon: ROOT_ICON,+ },+ {+ label: 'explicit organization command / root only',+ directive: { ...legacyCommand, namespace: 'acme' },+ body: '$draw help',+ calls: [rootCall],+ called: false,+ icon: ORG_ICON,+ },+ {+ label: 'explicit organization command / organization',+ directive: { ...legacyCommand, namespace: 'acme' },+ body: '$draw help',+ calls: [orgCall],+ called: true,+ icon: ORG_ICON,+ },+ {+ label: 'old mention / explicit root call',+ directive: legacyMention,+ body: 'help',+ calls: [rootCall],+ called: true,+ icon: null,+ },+ {+ label: 'old mention / encoded root call',+ directive: legacyMention,+ body: 'help',+ calls: [{ ghost_id: '_root__helper' }],+ called: true,+ icon: null,+ },+ {+ label: 'old mention / bare call',+ directive: legacyMention,+ body: 'help',+ calls: [{ ghost_id: 'helper' }],+ called: true,+ icon: null,+ },+ {+ label: 'old mention / organization only',+ directive: legacyMention,+ body: 'help',+ calls: [orgCall],+ called: false,+ icon: null,+ },+ {+ label: 'mixed mentions / organization only',+ directive: mixedMention,+ body: 'help',+ calls: [orgCall],+ called: true,+ icon: ORG_ICON,+ names: 'Saved Organization',+ },+ {+ label: 'mixed mentions / both instances',+ directive: mixedMention,+ body: 'help',+ calls: [rootCall, orgCall],+ called: true,+ icon: null,+ names: 'Saved Helper、Saved Organization',+ },+ ])(+ '$label preserves status separately from installed identity',+ async ({ directive, body, calls, called, icon, names }) => {+ stubMatchMedia(true);+ installedGhostsMock.mockReturnValue([+ {+ manifest: { id: 'helper', name: 'Installed Root', version: '1' },+ dir: '/tmp/_ns/_root/helper',+ instanceKey: '_root__helper',+ namespace: null,+ iconDataUrl: ROOT_ICON,+ },+ {+ manifest: {+ id: 'helper',+ name: 'Installed Organization',+ version: '2',+ },+ dir: '/tmp/_ns/acme/helper',+ instanceKey: '_ns__acme__helper',+ namespace: 'acme',+ iconDataUrl: ORG_ICON,+ },+ ] as InstalledGhost[]);+ const raw = (+ directive.kind === 'command'+ ? commandDirectiveSegments(directive)+ : mentionDirectiveSegments(directive.ghosts)+ )+ .map((segment) => segment.text)+ .join('');+ const content = body + '\n\n' + raw;+ const messages = [+ { clientId: 'm1', role: 'user', content },+ ...calls.map((input, index) => ({+ clientId: 'call-' + index,+ role: 'tool_use',+ toolName: 'mcp__cindy__ghost_call',+ toolInput: { ...input, tool: 'run' },+ })),+ ] as ChatMessage[];+ let container!: HTMLElement;+ await act(async () => {+ const view = render(+ <GhostFulfillmentContext.Provider+ value={collectGhostCallsByUserTurn(messages)}+ >+ <ConfirmDialogProvider>+ <MemoryRouter>+ <Tooltip.Provider>+ <UserMessage+ content={content}+ messageClientId="m1"+ isLastUserMessage+ sessionRunning={false}+ />+ </Tooltip.Provider>+ </MemoryRouter>+ </ConfirmDialogProvider>+ </GhostFulfillmentContext.Provider>,+ );+ container = view.container;+ });+ if (directive.kind === 'mention' && !called) {+ expect(screen.getByText(/提及插件/)).toBeTruthy();+ expect(screen.queryByText('已调用')).toBeNull();+ } else {+ expect(screen.getByText(called ? '已调用' : '已完成')).toBeTruthy();+ expect(screen.queryByText(called ? '已完成' : '已调用')).toBeNull();+ expect(screen.getByText(names ?? 'Saved Helper')).toBeTruthy();+ expect(screen.queryByText(/提及插件/)).toBeNull();+ }+ expect(+ [...container.querySelectorAll('img')].map((img) =>+ img.getAttribute('src'),+ ),+ ).toEqual(icon ? [icon] : []);+ expect(screen.queryByText('Installed Root')).toBeNull();+ expect(screen.queryByText('Installed Organization')).toBeNull();+ },+ );+ });+// #6386: existing tests covered org calls and ambiguous bare history, but not// explicit root messages through the production projection into this chip.// Unit tier: only the installed-list hook is replaced; no runtime/credentials.diff --git a/apps/desktop/src/renderer/components/chat/GhostSummonCard.tsx b/apps/desktop/src/renderer/components/chat/GhostSummonCard.tsxindex 48b468f20c..c751dde259 100644--- a/apps/desktop/src/renderer/components/chat/GhostSummonCard.tsx+++ b/apps/desktop/src/renderer/components/chat/GhostSummonCard.tsx@@ -70,6 +70,19 @@ export const GhostFulfillmentContext = createContext<ReadonlyMap<string, Readonlnew Map(),);+/** Match call status only; legacy bare directives must not acquire a live install's identity. */+export function hasGhostSummonFulfillment(+ fulfilledIds: ReadonlySet<string> | undefined,+ ghostId: string,+): boolean {+ if (!fulfilledIds) return false;+ if (fulfilledIds.has(ghostId)) return true;+ return (+ isValidGhostId(ghostId) &&+ fulfilledIds.has(pluginInstallStoragePart(pluginNewInstallRelId({ namespace: null, ghostId })))+ );+}+/*** 召唤标注展示数据:发送期追加段解析出的 command / mention 之外,再加一种* semantic——消息没有任何追加段、AI 纯靠语义自主召唤(只有 ghostId 清单,@@ -317,14 +330,14 @@ export function GhostSummonCard({return Boolean(match && fulfilledIds.has(commandIdentity.ghostId) &&installedGhostLogicalIdentity(match).namespace === commandIdentity.namespace);}- if (fulfilledIds.has(ghostId)) return true;+ if (hasGhostSummonFulfillment(fulfilledIds, ghostId)) return true;const ghost = ghostForDirective(ghostId);return ghost ? fulfilledIds.has(pluginStoragePart(installedGhostLogicalIdentity(ghost))) : false;};// 软提示的兑现子集(方案 2):AI 真调了才算,只提及没调的不升级(不撒谎)。const fulfilled =directive.kind === 'mention' && fulfilledIds- ? directive.ghosts.filter((g) => fulfilledIds.has(g.ghostId))+ ? directive.ghosts.filter((g) => hasGhostSummonFulfillment(fulfilledIds, g.ghostId)): [];if (directive.kind === 'mention' && fulfilled.length === 0) {diff --git a/apps/desktop/src/renderer/components/chat/UserMessage.tsx b/apps/desktop/src/renderer/components/chat/UserMessage.tsxindex 4b45bf5a90..01a71ae890 100644--- a/apps/desktop/src/renderer/components/chat/UserMessage.tsx+++ b/apps/desktop/src/renderer/components/chat/UserMessage.tsx@@ -114,6 +114,7 @@ import { splitHostCapabilityDirective } from '@/cindy-brain/hostCapabilityInvocaimport {GhostFulfillmentContext,GhostSummonCard,+ hasGhostSummonFulfillment,type GhostSummonDisplay,} from './GhostSummonCard';import { MessageSourceLabels } from './MessageSourceLabels';@@ -971,7 +972,7 @@ export function UserMessage({const ghostMentionFulfilled =ghostDirective?.kind === 'mention' &&Boolean(- ghostFulfilledIds && ghostDirective.ghosts.some((g) => ghostFulfilledIds.has(g.ghostId)),+ ghostDirective.ghosts.some((g) => hasGhostSummonFulfillment(ghostFulfilledIds, g.ghostId)),);// 语义自主召唤:消息一个触发词都没命中(无任何追加段),AI 本轮仍真调了// ghost_call → 合成 semantic 展示数据,渲染同一行召唤标注(与硬指令/兑现