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 explicit root plugin names and icons
shenjiachengc0810054b8e8
diff --git a/apps/desktop/src/renderer/__tests__/collectGhostCallsByUserTurn.test.ts b/apps/desktop/src/renderer/__tests__/collectGhostCallsByUserTurn.test.tsindex fe56e30659..694e610baa 100644--- a/apps/desktop/src/renderer/__tests__/collectGhostCallsByUserTurn.test.ts+++ b/apps/desktop/src/renderer/__tests__/collectGhostCallsByUserTurn.test.ts@@ -29,7 +29,7 @@ describe('collectGhostCallsByUserTurn', () => {const root = { ...ghostCall('t1', 'helper'), toolInput: { ghost_id: 'helper', namespace: null, tool: 'run' } };const organization = { ...ghostCall('t2', 'helper'), toolInput: { ghost_id: 'helper', namespace: 'acme', tool: 'run' } };const map = collectGhostCallsByUserTurn([user('u1'), root, organization]);- expect([...(map.get('u1') ?? [])].sort()).toEqual(['_ns__acme__helper', 'helper']);+ expect([...(map.get('u1') ?? [])].sort()).toEqual(['_ns__acme__helper', '_root__helper']);});it('keeps legacy unqualified calls and ignores malformed namespace inputs', () => {diff --git a/apps/desktop/src/renderer/__tests__/ghostSummonChip.test.tsx b/apps/desktop/src/renderer/__tests__/ghostSummonChip.test.tsxindex ae0b620d1e..ea5ba132cd 100644--- a/apps/desktop/src/renderer/__tests__/ghostSummonChip.test.tsx+++ b/apps/desktop/src/renderer/__tests__/ghostSummonChip.test.tsx@@ -86,7 +86,105 @@ afterEach(() => {delete (window as { matchMedia?: unknown }).matchMedia;});+const ROOT_ICON = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAFklEQVR4nGOwbvpGEmIY1TCqYfhqAACHB7MQtEO1oAAAAABJRU5ErkJggg==';+const ORG_ICON = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAFklEQVR4nGOYbPyKJMQwqmFUw/DVAABSy7AQ0SGg2gAAAABJRU5ErkJggg==';+describe('GhostSummonCard(chip 形态)', () => {+ // #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.+ it.each([+ {+ label: 'explicit root',+ input: { ghost_id: 'helper', namespace: null },+ name: 'Root',+ icon: ROOT_ICON,+ },+ { label: 'encoded root', input: { ghost_id: '_root__helper' }, name: 'Root', icon: ROOT_ICON },+ {+ label: 'explicit organization',+ input: { ghost_id: 'helper', namespace: 'acme' },+ name: 'Organization',+ icon: ORG_ICON,+ },+ {+ label: 'legacy unqualified history',+ input: { ghost_id: 'helper' },+ name: 'helper',+ icon: null,+ },+ ])(+ 'keeps $label name and icon together while running, settled and reloaded',+ ({ input, name, icon }) => {+ stubMatchMedia(true);+ installedGhostsMock.mockReturnValue([+ {+ manifest: { id: 'helper', name: 'Root', version: '1' },+ dir: '/tmp/_ns/_root/helper',+ instanceKey: '_root__helper',+ namespace: null,+ iconDataUrl: ROOT_ICON,+ },+ {+ manifest: { id: 'helper', name: 'Organization', version: '2' },+ dir: '/tmp/_ns/acme/helper',+ instanceKey: '_ns__acme__helper',+ namespace: 'acme',+ iconDataUrl: ORG_ICON,+ },+ ] as InstalledGhost[]);+ const messages = [+ { clientId: 'm1', role: 'user', content: 'help' },+ {+ clientId: 'call',+ role: 'tool_use',+ toolUseId: 'call-1',+ toolName: 'mcp__cindy__ghost_call',+ toolInput: { ...input, tool: 'run' },+ },+ ] as ChatMessage[];+ const chip = (history: ChatMessage[], running: boolean) => {+ const fulfilled = collectGhostCallsByUserTurn(history);+ return (+ <GhostFulfillmentContext.Provider value={fulfilled}>+ <GhostSummonCard+ directive={{ kind: 'semantic', ghostIds: [...(fulfilled.get('m1') ?? [])] }}+ messageClientId="m1"+ running={running}+ />+ </GhostFulfillmentContext.Provider>+ );+ };+ const assertIdentity = (container: HTMLElement) => {+ expect(screen.getByText(name)).toBeTruthy();+ const images = [...container.querySelectorAll('img')].map((img) => img.getAttribute('src'));+ expect(images).toEqual(icon ? [icon] : []);+ for (const other of ['Root', 'Organization'].filter((value) => value !== name)) {+ expect(screen.queryByText(other)).toBeNull();+ }+ };+ const view = render(chip(messages, true));+ assertIdentity(view.container);+ expect(screen.getByText('调用中…')).toBeTruthy();+ const settled = [+ ...messages,+ {+ clientId: 'result',+ role: 'tool_result',+ toolUseId: 'call-1',+ content: 'ok',+ } as ChatMessage,+ ];+ view.rerender(chip(settled, false));+ assertIdentity(view.container);+ expect(screen.getByText('已调用')).toBeTruthy();+ view.unmount();+ const reloaded = render(chip(JSON.parse(JSON.stringify(settled)) as ChatMessage[], false));+ assertIdentity(reloaded.container);+ expect(screen.getByText('已调用')).toBeTruthy();+ },+ );+it('does not attach a newly installed root version to an ambiguous historical bare id', () => {installedGhostsMock.mockReturnValue([{ manifest: { id: 'helper', name: 'New Root', version: '99' },@@ -99,6 +197,57 @@ describe('GhostSummonCard(chip 形态)', () => {expect(container.querySelector('img[src="data:image/png;base64,AAAA"]')).toBeNull();});+ it.each([undefined, '@root'])(+ 'keeps an explicit root command fulfilled with namespace token %s',+ (commandNamespace) => {+ installedGhostsMock.mockReturnValue([+ {+ manifest: { id: 'helper', name: 'Root', version: '1' },+ dir: '/tmp/_ns/_root/helper',+ instanceKey: '_root__helper',+ namespace: null,+ iconDataUrl: ROOT_ICON,+ },+ {+ manifest: { id: 'helper', name: 'Organization', version: '2' },+ dir: '/tmp/_ns/acme/helper',+ namespace: 'acme',+ iconDataUrl: ORG_ICON,+ },+ ] as InstalledGhost[]);+ const directive = {+ kind: 'command',+ command: 'draw',+ name: 'Root',+ ghostId: 'helper',+ namespace: null,+ raw: '',+ } as const;+ const messages = [+ { clientId: 'm1', role: 'user', content: 'draw' },+ {+ clientId: 'call',+ role: 'tool_use',+ toolName: 'mcp__cindy__ghost_call',+ toolInput: { ghost_id: 'helper', namespace: null, tool: 'run' },+ },+ ] as ChatMessage[];+ const { container } = render(+ <GhostFulfillmentContext.Provider value={collectGhostCallsByUserTurn(messages)}>+ <GhostSummonCard+ directive={directive}+ commandNamespace={commandNamespace}+ messageClientId="m1"+ />+ </GhostFulfillmentContext.Provider>,+ );+ expect(screen.getByText('已调用')).toBeTruthy();+ expect(container.querySelector('img')?.getAttribute('src')).toBe(ROOT_ICON);+ fireEvent.click(screen.getByRole('button', { expanded: false }));+ expect(screen.getByText('v1')).toBeTruthy();+ },+ );+it('renders an organization semantic call instead of its same-id root neighbor', () => {installedGhostsMock.mockReturnValue([{ manifest: { id: 'helper', name: 'Root', version: '1' }, dir: '/tmp/helper', namespace: null },diff --git a/apps/desktop/src/renderer/components/chat/GhostSummonCard.tsx b/apps/desktop/src/renderer/components/chat/GhostSummonCard.tsxindex 8c397753cb..48b468f20c 100644--- a/apps/desktop/src/renderer/components/chat/GhostSummonCard.tsx+++ b/apps/desktop/src/renderer/components/chat/GhostSummonCard.tsx@@ -55,6 +55,8 @@ import {findInstalledGhostByInstanceId,installedGhostLogicalIdentity,parsePluginInstanceId,+ pluginInstallStoragePart,+ pluginNewInstallRelId,pluginStoragePart,} from '../../../shared/pluginIdentity';@@ -282,12 +284,20 @@ export function GhostSummonCard({const identity = parsePluginInstanceId(ghostId);return identity ? findInstalledGhostByIdentity(installedGhosts, identity) : undefined;};- const commandIdentity = directive.kind === 'command' &&- typeof commandNamespace === 'string' &&- (commandNamespace === '@root' || isValidPluginNamespace(commandNamespace)) &&+ const directiveNamespace =+ directive.kind === 'command' && directive.namespace !== undefined+ ? directive.namespace+ : commandNamespace === '@root'+ ? null+ : commandNamespace;+ const commandIdentity =+ directive.kind === 'command' &&+ (directiveNamespace === null ||+ (typeof directiveNamespace === 'string' && isValidPluginNamespace(directiveNamespace))) &&isValidGhostId(directive.ghostId)- ? { namespace: commandNamespace === '@root' ? null : commandNamespace, ghostId: directive.ghostId }- : null;+ ? { namespace: directiveNamespace, ghostId: directive.ghostId }+ : null;+const commandInstanceId = commandIdentity ? pluginStoragePart(commandIdentity) : null;const ghostForDirective = (ghostId: string) => commandIdentity && ghostId === commandIdentity.ghostId? findInstalledGhostByIdentity(installedGhosts, commandIdentity)@@ -301,6 +311,7 @@ export function GhostSummonCard({if (!fulfilledIds) return false;if (commandIdentity && commandInstanceId) {if (fulfilledIds.has(commandInstanceId)) return true;+ if (fulfilledIds.has(pluginInstallStoragePart(pluginNewInstallRelId(commandIdentity)))) return true;const matches = installedGhosts.filter((ghost) => ghost.manifest.id === commandIdentity.ghostId);const match = matches.length === 1 ? matches[0] : undefined;return Boolean(match && fulfilledIds.has(commandIdentity.ghostId) &&diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsxindex c0ac045a54..37ac9c242a 100644--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx@@ -138,7 +138,12 @@ import {isShareableToolMedia,useShareSelectionActive,} from './shareSelectionStore';-import { parsePluginInstanceId, pluginStoragePart } from '../../../shared/pluginIdentity';+import {+ parsePluginInstanceId,+ pluginInstallStoragePart,+ pluginNewInstallRelId,+ pluginStoragePart,+} from '../../../shared/pluginIdentity';import { isValidGhostId } from '../../../shared/ghost';import { isValidPluginNamespace } from '@cindy/plugin-protocol';@@ -801,7 +806,7 @@ export function collectGhostCallsByUserTurn(typeof (m.toolInput as Record<string, unknown>).ghost_id === 'string') {const input = m.toolInput as Record<string, unknown>;- const gid = ghostCardInstanceId(input.ghost_id as string, input.namespace);+ const gid = ghostSummonInstanceId(input.ghost_id as string, input.namespace);if (!gid) continue;const set = out.get(currentUserClientId) ?? new Set<string>();set.add(gid);@@ -1494,6 +1499,20 @@ function ghostCardInstanceId(ghostId: string, namespace: unknown): string | null: null;}+/** Summon labels retain explicit root identity; card/media anchoring keeps its existing keys. */+function ghostSummonInstanceId(ghostId: string, namespace: unknown): string | null {+ const id = ghostCardInstanceId(ghostId, namespace);+ if (!id) return null;+ const explicitRoot =+ namespace === null ||+ (namespace === undefined &&+ !isValidGhostId(ghostId) &&+ parsePluginInstanceId(ghostId)?.namespace === null);+ return explicitRoot+ ? pluginInstallStoragePart(pluginNewInstallRelId({ namespace: null, ghostId: id }))+ : id;+}+export function buildRenderItems(allMessages: ChatMessage[],taskUpdates?: ReadonlyMap<string, AgentTaskUpdate>,