Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(plugins): $ 指令不再显示企业 slug,同名时企业版标「团队共享」 (#5960)
fattycat3312cc699369
diff --git a/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts b/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.tsindex 3e6e154bc9..e22ff4a0ca 100644--- a/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts@@ -361,8 +361,17 @@ describe('Pi package executable-code boundary', () => {runtime.listOutput = `${entries.join('\n')}\n`;const store = await import('../pi-package-store.js');- const result = await store.listPiPackages();+ // 本用例只验证超长元数据的截断与总量上限;固定时钟,避免慢速 runner 触发+ // 单包检查时限后降级成 inspection-limit 投影(名称即来源、不截断)。+ const clock = vi.spyOn(Date, 'now').mockReturnValue(Date.now());+ let result: Awaited<ReturnType<typeof store.listPiPackages>>;+ try {+ result = await store.listPiPackages();+ } finally {+ clock.mockRestore();+ }expect(result.packages).toHaveLength(128);+ expect(result.packages.filter((pkg) => pkg.warning === 'inspection-limit')).toEqual([]);expect(result.packages.every((pkg) => pkg.name.endsWith('…'))).toBe(true);expect(result.packages.every((pkg) => pkg.version?.endsWith('…'))).toBe(true);expect(Buffer.byteLength(JSON.stringify(result), 'utf8')).toBeLessThan(128 * 1_024);diff --git a/apps/desktop/src/renderer/__tests__/chatInputGhostSnapshot.test.ts b/apps/desktop/src/renderer/__tests__/chatInputGhostSnapshot.test.tsindex bc4209afe4..7615644183 100644--- a/apps/desktop/src/renderer/__tests__/chatInputGhostSnapshot.test.ts+++ b/apps/desktop/src/renderer/__tests__/chatInputGhostSnapshot.test.ts@@ -19,7 +19,7 @@ describe('ChatInput Ghost snapshot contract', () => {expect(source).toContain('const ghostCommandItems = useMemo(() => {\n if (!isGhostSigil) return [];\n return ghostsForCommand',);- expect(source).toContain('}, [ghostsForCommand, isGhostSigil, t]);');+ expect(source).toContain('}, [ghostSourceLabels, ghostsForCommand, isGhostSigil, t]);');});it('uses the latest installed snapshot and workdir at send time', () => {diff --git a/apps/desktop/src/renderer/__tests__/ghostCommand.test.ts b/apps/desktop/src/renderer/__tests__/ghostCommand.test.tsindex dba00bb67b..8aa78d0201 100644--- a/apps/desktop/src/renderer/__tests__/ghostCommand.test.ts+++ b/apps/desktop/src/renderer/__tests__/ghostCommand.test.ts@@ -77,11 +77,15 @@ describe('parseGhostCommandWord', () => {});describe('formatGhostCommandToken', () => {- it('qualifies organization instances and leaves root unqualified', () => {+ it('leaves a unique command bare and qualifies only a shared one', () => {+ const org = ghost('draw', true, { namespace: 'acme' });expect(formatGhostCommandToken(ghost('draw'))).toBe('draw');expect(formatGhostCommandToken(ghost('draw', true, { namespace: null }))).toBe('draw');- expect(formatGhostCommandToken(ghost('draw', true, { namespace: 'acme' }))).toBe('draw/acme');- expect(formatGhostCommandInsertion(ghost('draw', true, { namespace: 'acme' }))).toBe('$draw/acme');+ expect(formatGhostCommandInsertion(org, [org, ghost('write', true, { namespace: null })])).toBe('$draw');+ // A disabled duplicate still counts, so re-enabling it cannot make the token ambiguous.+ const sleepingRoot = ghost('DRAW', false, { namespace: null });+ expect(formatGhostCommandInsertion(org, [org, sleepingRoot])).toBe('$draw/acme');+ expect(expandGhostCommand('$draw a cat', [org])).toContain('namespace: acme');});});diff --git a/apps/desktop/src/renderer/__tests__/ghostCommandDecoration.test.ts b/apps/desktop/src/renderer/__tests__/ghostCommandDecoration.test.tsindex bccae71492..dc1712f4f1 100644--- a/apps/desktop/src/renderer/__tests__/ghostCommandDecoration.test.ts+++ b/apps/desktop/src/renderer/__tests__/ghostCommandDecoration.test.ts@@ -214,6 +214,67 @@ describe('createGhostCommandPlugin — roster meta 与 decoration 生命周期','data-ghost-cmd': 'ghost-画图',});});++ it('歧义裸指令:胶囊与发送期不亮,只有放置替换显式开启时才识别位置', () => {+ const root = makeGhost('sites', { id: 'sites', namespace: null });+ const org = makeGhost('sites', { id: 'sites', namespace: 'xd' });+ const d = doc(p(txt('$sites 发布')));+ expect(findGhostCommandMatch(d, [root, org])).toBeNull();+ expect(findGhostCommandMatch(d, [root, org], { includeDisabled: true })).toBeNull();+ expect(findGhostCommandMatch(d, [root, org], { includeDisabled: true, ambiguousBareToken: true }))+ .toMatchObject({ from: 1, to: 7 });+ });++ it('同名限定符渲染层收起:企业实例标「团队共享」,root 只收起不加标签;标签未就绪时照常显示', () => {+ const plugin = createGhostCommandPlugin();+ const root = makeGhost('sites', { id: 'sites', namespace: null });+ const org = makeGhost('sites', { id: 'sites', namespace: 'xd' });+ const labels = { team: 'label:team' };+ const specs = (state: EditorState) => (plugin.getState(state)?.decorations.find() ?? [])+ .map((d) => {+ const attrs = (d as unknown as { type: { attrs: Record<string, string> } }).type.attrs;+ return [d.from, d.to, attrs.class, attrs['data-ghost-cmd-origin']];+ });+ const withText = (text: string, sourceLabels: typeof labels | null) => {+ const state = EditorState.create({ schema, doc: doc(p(txt(text))), plugins: [plugin] });+ return state.apply(state.tr.setMeta(META_KEY, [root, org]).setMeta('ghostCommandSourceLabels', sourceLabels));+ };++ expect(specs(withText('$sites/xd 发布', labels))).toEqual([+ [1, 2, 'ghost-cmd-sigil', undefined],+ [2, 7, 'ghost-cmd-pill', 'label:team'],+ [7, 10, 'ghost-cmd-qualifier', undefined],+ ]);+ expect(specs(withText('$sites/@root 发布', labels))).toEqual([+ [1, 2, 'ghost-cmd-sigil', undefined],+ [2, 7, 'ghost-cmd-pill', undefined],+ [7, 13, 'ghost-cmd-qualifier', undefined],+ ]);+ expect(globalsSource).toMatch(/\.ghost-cmd-qualifier\s*\{\s*display:\s*none/);+ expect(globalsSource).toMatch(/\.ghost-cmd-pill\[data-ghost-cmd-origin\]::after\s*\{[^}]*attr\(data-ghost-cmd-origin\)/);++ // 标签未就绪:不收起,避免两颗同名胶囊无从区分+ expect(specs(withText('$sites/xd 发布', null)).map(([from, to]) => [from, to])).toEqual([[1, 2], [2, 10]]);+ });++ it('同名实例里有 namespace 未知的旧安装时,root 保留 /@root 不收起', () => {+ const plugin = createGhostCommandPlugin();+ const root = makeGhost('sites', { id: 'sites', namespace: null });+ const legacy = makeGhost('sites', { id: 'sites-legacy' });+ let state = EditorState.create({ schema, doc: doc(p(txt('$sites/@root 发布'))), plugins: [plugin] });+ state = state.apply(state.tr+ .setMeta(META_KEY, [root, legacy])+ .setMeta('ghostCommandSourceLabels', { team: 'label:team' }));+ const specs = (plugin.getState(state)?.decorations.find() ?? []).map((d) => {+ const attrs = (d as unknown as { type: { attrs: Record<string, string> } }).type.attrs;+ return [d.from, d.to, attrs.class];+ });+ // The legacy row renders a bare command, so hiding /@root would make the two identical.+ expect(specs).toEqual([+ [1, 2, 'ghost-cmd-sigil'],+ [2, 13, 'ghost-cmd-pill'],+ ]);+ });});describe('applyGhostCommandBackspace — 整体删除的接管边界', () => {diff --git a/apps/desktop/src/renderer/__tests__/ghostCommandSourceLabel.dom.test.ts b/apps/desktop/src/renderer/__tests__/ghostCommandSourceLabel.dom.test.tsnew file mode 100644index 0000000000..5d35f1bcf4--- /dev/null+++ b/apps/desktop/src/renderer/__tests__/ghostCommandSourceLabel.dom.test.ts@@ -0,0 +1,62 @@+// @vitest-environment jsdom+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import { afterEach, describe, expect, it } from 'vitest';+import { Editor } from '@tiptap/core';+import Document from '@tiptap/extension-document';+import Paragraph from '@tiptap/extension-paragraph';+import Text from '@tiptap/extension-text';+import HardBreak from '@tiptap/extension-hard-break';++import { CjkPunctDecoration } from '@/components/new-chat/CjkPunctDecoration';+import {+ GhostCommandDecoration,+ setGhostCommandRoster,+} from '@/components/new-chat/GhostCommandDecoration';+import type { GhostCommandSource } from '../../shared/ghostComposer';++/**+ * 同名插件胶囊的来源标签在真实 DOM 里只出现一次:指令词含 CJK 标点时,+ * CjkPunctDecoration 会把同一颗胶囊切成多段,每段都带 data-ghost-cmd-origin,+ * 标签必须只由最后一段的 ::after 渲染(jsdom 不算伪元素,按 globals.css 的+ * 选择器在 DOM 上复核)。+ */++const globalsSource = readFileSync(resolve(__dirname, '..', 'styles', 'globals.css'), 'utf8');+let editor: Editor | null = null;++afterEach(() => {+ editor?.destroy();+ editor = null;+});++const ghost = (namespace: string | null): GhostCommandSource => ({+ manifest: { id: 'sites', name: 'Sites', command: '画(图)' },+ enabled: true,+ namespace,+});++describe('ghost command source label in the rendered pill', () => {+ it('renders the label once when CJK punctuation splits the pill', () => {+ editor = new Editor({+ element: document.createElement('div'),+ extensions: [Document, Paragraph, Text, HardBreak, GhostCommandDecoration, CjkPunctDecoration],+ content: { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: '$画(图)/xd 发布' }] }] },+ });+ setGhostCommandRoster(editor, [ghost(null), ghost('xd')], { team: '团队共享' });++ const segments = Array.from(+ editor.view.dom.querySelectorAll<HTMLElement>('.ghost-cmd-pill[data-ghost-cmd-origin]'),+ );+ // The fixture really splits: otherwise this test would pass without exercising the rule.+ expect(segments.length).toBeGreaterThan(1);+ expect(segments.every((el) => el.dataset.ghostCmdOrigin === '团队共享')).toBe(true);++ expect(globalsSource).toMatch(+ /\.ghost-cmd-pill\[data-ghost-cmd-origin\]:has\(\+ \.ghost-cmd-pill\)::after\s*\{\s*content:\s*none;?\s*\}/,+ );+ const labelled = segments.filter((el) => !el.matches('.ghost-cmd-pill:has(+ .ghost-cmd-pill)'));+ expect(labelled).toHaveLength(1);+ expect(labelled[0]).toBe(segments.at(-1));+ });+});diff --git a/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts b/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.tsindex a6a1db4d4c..c1054d457f 100644--- a/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts+++ b/apps/desktop/src/renderer/__tests__/ghostComposerPlacement.test.ts@@ -86,13 +86,36 @@ describe('placeGhostAtComposerStart', () => {expect(editor.state.selection.to).toBe(editor.state.doc.content.size - 1);});- it('qualifies a namespaced Plugin command', () => {+ it('qualifies a namespaced Plugin command only when its command is shared', () => {const editor = editorWith('keep going');const selected = ghost('draw', 'art');selected.namespace = 'acme';selected.dir = '/tmp/_ns/acme/art';expect(placeGhostAtComposerStart(editor, selected, [selected])).toBe(true);- expect(editor.getText()).toBe('$draw/acme keep going');+ expect(editor.getText()).toBe('$draw keep going');++ const sharedEditor = editorWith('keep going');+ const root = ghost('draw', 'art');+ root.namespace = null;+ expect(placeGhostAtComposerStart(sharedEditor, selected, [root, selected])).toBe(true);+ expect(sharedEditor.getText()).toBe('$draw/acme keep going');+ });++ it('replaces a bare command that became ambiguous after a same-name install', () => {+ // `$draw` was inserted while the organization instance was unique; a root sibling arrived later.+ const org = ghost('draw', 'art');+ org.namespace = 'acme';+ org.dir = '/tmp/_ns/acme/art';+ const root = ghost('draw', 'art');+ root.namespace = null;++ const pickRoot = editorWith('$draw keep going');+ expect(placeGhostAtComposerStart(pickRoot, root, [org, root])).toBe(true);+ expect(pickRoot.getText()).toBe('$draw/@root keep going');++ const pickOrg = editorWith('$draw keep going');+ expect(placeGhostAtComposerStart(pickOrg, org, [org, root])).toBe(true);+ expect(pickOrg.getText()).toBe('$draw/acme keep going');});it('replaces an existing Plugin command instead of stacking commands', () => {diff --git a/apps/desktop/src/renderer/__tests__/newMakerCreateAgentVisualContract.test.ts b/apps/desktop/src/renderer/__tests__/newMakerCreateAgentVisualContract.test.tsindex 90e6fae072..5d65818f94 100644--- a/apps/desktop/src/renderer/__tests__/newMakerCreateAgentVisualContract.test.ts+++ b/apps/desktop/src/renderer/__tests__/newMakerCreateAgentVisualContract.test.ts@@ -204,17 +204,21 @@ describe('NewMakerDraftRoute CREATE AGENT visual contract', () => {// 悬停预览只走 ChatInput 的只读 overlay,不写草稿。expect(source).toContain('previewPrompt={suggestionPreview}');expect(source).toContain('onPreviewChange={handleSuggestionPreview}');- // 视觉预览与读屏描述共用同一个「点击后会填入的文字」计算。- expect(source).toContain('composerTextFor={suggestionComposerText}');+ // 视觉预览与读屏描述共用同一个显示投影(收起同名限定符),点击填入仍用带限定符的文字。+ expect(source).toContain('composerTextFor={suggestionDescriptionText}');expect(suggestionBlock).toContain(- 'setSuggestionPreview(suggestion ? suggestionComposerText(suggestion) : null)',+ 'setSuggestionPreview(suggestion ? suggestionDisplayText(suggestion, false) : null)',);- // 语音占用 / 发送中时不填入,且预览与填入共用同一份插件文字计算。+ expect(suggestionBlock).toContain(+ 'fillComposerWithSuggestion(pluginSuggestionComposerText(suggestion.prompt, ghost, t, installedGhosts))',+ );+ // 语音占用 / 发送中时不填入,预览与填入各走一次插件文字计算。expect(suggestionBlock).toContain('if (sendInFlightRef.current || composerMutationLockedRef.current) return false;',);expect(source).toContain('onMutationLockChange={handleComposerMutationLockChange}');- expect(suggestionBlock.match(/pluginSuggestionComposerText\(/g)).toHaveLength(2);+ expect(suggestionBlock.match(/pluginSuggestionComposerText\(/g)).toHaveLength(1);+ expect(suggestionBlock.match(/pluginSuggestionDisplayText\(/g)).toHaveLength(1);// 普通发送直接使用输入内容,不再经过可能残留推荐内容的中转 ref。expect(source).toContain('onSend={handleSend}');expect(source).not.toContain('pendingHomePromptRef');diff --git a/apps/desktop/src/renderer/__tests__/pluginRecommendationRecovery.test.tsx b/apps/desktop/src/renderer/__tests__/pluginRecommendationRecovery.test.tsxindex 47c4795a6f..3c3a3e5ebf 100644--- a/apps/desktop/src/renderer/__tests__/pluginRecommendationRecovery.test.tsx+++ b/apps/desktop/src/renderer/__tests__/pluginRecommendationRecovery.test.tsx@@ -107,6 +107,40 @@ describe('plugin recommendation recovery', () => {toast: { error: vi.fn() },});await run({ suggestion, ownerId: 'owner', targetKey: 'local', workingDir: '/project' });+ expect(fillComposerWithSuggestion).toHaveBeenCalledWith('$org Org task');+ expect(markUsed).toHaveBeenCalledWith('_ns__acme__helper');+ });++ it('keeps the qualifier when a disabled root plugin shares the selected command', async () => {+ const source = readFileSync(resolve(__dirname, '../features/cc-agent/NewMakerDraftRoute.tsx'), 'utf8');+ const block = source.slice(source.indexOf(' const runPluginSuggestion ='), source.indexOf(' const handlePluginSuggestion ='));+ const suggestion = { id: 'plugin:_ns__acme__helper:task', pluginId: '_ns__acme__helper', prompt: 'Org task' };+ // A disabled sibling cannot be chosen, but re-enabling it before send must not make the fill ambiguous.+ const root = { manifest: { id: 'helper', name: 'Root', command: 'org' }, dir: '/ghosts/helper', namespace: null, enabled: false };+ const org = { manifest: { id: 'helper', name: 'Org', command: 'org' }, dir: '/ghosts/_ns/acme/helper', namespace: 'acme', enabled: true };+ const fillComposerWithSuggestion = vi.fn(() => true);+ const markUsed = vi.fn(async () => ({ ids: ['_ns__acme__helper'] }));+ Object.assign(window, { electronAPI: { ghosts: { listSync: () => ({ ghosts: [root, org] }), markUsed } } });+ const run = compile(block + String.fromCharCode(10) + 'return runPluginSuggestion;', {+ useCallback: (callback: unknown) => callback,+ sendInFlightRef: { current: false },+ pluginSuggestionFlight: { current: false },+ pluginSuggestionMounted: { current: true },+ currentPluginSuggestionContext: { current: { generation: 1, dataOwnerId: 'owner', targetKey: 'local' } },+ readPluginRecommendationSnapshot: () => ({ ownerId: 'owner' }),+ buildHomeTaskCatalog: () => [suggestion],+ filterGhostsForWorkdir: (ghosts: unknown[]) => ghosts,+ fillComposerWithSuggestion,+ pluginSuggestionComposerText,+ installedGhostStoragePart,+ i18n: { language: 'en' },+ t: () => 'Use Org',+ isRemoteProjectDraft: false,+ isDeviceLinkDraft: false,+ navigate: vi.fn(),+ toast: { error: vi.fn() },+ });+ await run({ suggestion, ownerId: 'owner', targetKey: 'local', workingDir: '/project' });expect(fillComposerWithSuggestion).toHaveBeenCalledWith('$org/acme Org task');expect(markUsed).toHaveBeenCalledWith('_ns__acme__helper');});diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex 2b73b882cb..2319f2fdbb 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -62,7 +62,9 @@ import { MentionDragCaretDecoration, setMentionDragCaret } from './MentionDragCaimport {applyGhostCommandBackspace,GhostCommandDecoration,+ ghostQualifierDisplay,setGhostCommandRoster,+ type GhostSourceLabels,} from './GhostCommandDecoration';import {replaceSlashCommandRunWithText,@@ -3153,9 +3155,13 @@ export function ChatInput({};});}, [deviceLinkDeviceId, pluginsForMenu, pluginAvailableIds, remoteHostId, t]);+ const ghostSourceLabels = useMemo<GhostSourceLabels>(+ () => ({ team: t('settings.ghosts.commandPaletteSource.team') }),+ [t],+ );useEffect(() => {- setGhostCommandRoster(editor, ghostsForCommand);- }, [editor, ghostsForCommand]);+ setGhostCommandRoster(editor, ghostsForCommand, ghostSourceLabels);+ }, [editor, ghostsForCommand, ghostSourceLabels]);const handleVoiceInputPermissionRequired = useCallback(async () => {const confirmed = await confirmDialog({@@ -4414,15 +4420,27 @@ export function ChatInput({if (!isGhostSigil) return [];return ghostsForCommand.filter((g) => g.enabled && g.manifest.command !== undefined)- .map(- (g) =>- ({- kind: 'desktop',- name: formatGhostCommandToken(g, ghostsForCommand)!,- description: `${g.manifest.name} · ${t('settings.ghosts.commandPaletteTag')}${g.namespace ? ` · ${g.namespace}` : ''}`,- }) as UnifiedCommand,- );- }, [ghostsForCommand, isGhostSigil, t]);+ .map((g) => {+ const token = formatGhostCommandToken(g, ghostsForCommand)!;+ const team = typeof g.namespace === 'string' ? ` · ${ghostSourceLabels.team}` : '';+ // 同名冲突时 token 带 `/slug` 或 `/@root` 限定符:插入文本保留它供发送期消歧,+ // 菜单只显示指令词,企业实例在右侧标「团队共享」(与输入框胶囊同一条判定)。+ const qualifier = ghostQualifierDisplay(+ g,+ token !== g.manifest.command,+ ghostSourceLabels,+ ghostsForCommand,+ );+ return {+ kind: 'desktop',+ name: token,+ description: `${g.manifest.name} · ${t('settings.ghosts.commandPaletteTag')}${team}`,+ ...(qualifier+ ? { label: g.manifest.command, ...(qualifier.label ? { meta: qualifier.label } : {}) }+ : {}),+ } as UnifiedCommand;+ });+ }, [ghostSourceLabels, ghostsForCommand, isGhostSigil, t]);// 面板显示与键盘导航共用同一份命令源:$ 只列意识,/ 只列技能/命令。const paletteCommands = isGhostSigil ? ghostCommandItems : composerSlashCommands;const filteredCommands = useMemo(diff --git a/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts b/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.tsindex bf3eeceffd..b84d3e4a1e 100644--- a/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts+++ b/apps/desktop/src/renderer/components/new-chat/GhostCommandDecoration.ts@@ -31,12 +31,20 @@ import {parseGhostCommandToken,} from '@/cindy-brain/ghostCommand';import type { GhostCommandSource } from '../../../shared/ghostComposer';+import { listGhostsByCommand } from '../../../shared/pluginIdentity';const PLUGIN_KEY = new PluginKey<GhostCommandPluginState>('ghostCommandDecoration');const META_KEY = 'ghostCommandDecoration';+const SOURCE_LABELS_META_KEY = 'ghostCommandSourceLabels';++/** Localized 团队共享 label; supplied by ChatInput so a locale change re-renders. */+export interface GhostSourceLabels {+ team: string;+}interface GhostCommandPluginState {ghosts: GhostCommandSource[];+ sourceLabels: GhostSourceLabels | null;decorations: DecorationSet;}@@ -53,7 +61,9 @@ const SAFE_ICON_DATA_URL_RE = /^data:image\/[a-z0-9.+-]+;base64,[a-z0-9+/=]+$/i;export interface GhostCommandMatch {/** 触发符字符的 doc 位置。 */from: number;- /** 指令词结束后的 doc 位置(decoration 区间 [from, to))。 */+ /** 指令词(不含 `/限定符`)结束后的 doc 位置。 */+ wordEnd: number;+ /** 整个指令(含限定符)结束后的 doc 位置(decoration 区间 [from, to))。 */to: number;ghost: GhostCommandSource;}@@ -66,7 +76,15 @@ export interface GhostCommandMatch {export function findGhostCommandMatch(doc: PMNode,ghosts: GhostCommandSource[],- options: { includeDisabled?: boolean } = {},+ options: {+ includeDisabled?: boolean;+ /**+ * 仅供放置替换使用:裸指令词同时命中多个实例(唯一时插入的裸 `$draw`,之后又装了+ * 同名实例)仍识别为消息头指令,好让新选择替换它而不是叠在前面。胶囊与发送期+ * 判定不传此项,歧义时照旧不亮、不展开。+ */+ ambiguousBareToken?: boolean;+ } = {},): GhostCommandMatch | null {if (ghosts.length === 0) return null;let paraPos = 0;@@ -104,11 +122,19 @@ export function findGhostCommandMatch(const next = ci + 1 < para.childCount ? para.child(ci + 1) : null;if (next && next.type.name !== 'hardBreak') return null;}- const ghost = options.includeDisabled+ const ghost = (options.includeDisabled? findGhostByCommandIncludingDisabled(ghosts, token.word, token.namespace)- : findGhostByCommand(ghosts, token.word, token.namespace);+ : findGhostByCommand(ghosts, token.word, token.namespace))+ ?? (options.ambiguousBareToken && token.namespace === null+ ? listGhostsByCommand(ghosts, token.word, !options.includeDisabled)[0]+ : undefined);if (!ghost) return null;- return { from: childPos + i, to: childPos + after, ghost };+ return {+ from: childPos + i,+ wordEnd: childPos + i + 1 + token.word.length,+ to: childPos + after,+ ghost,+ };}// 全空白文本,继续找}@@ -139,17 +165,63 @@ export function ghostPillAttrs(ghost: GhostCommandSource): Record<string, stringreturn attrs;}+/** 同名冲突时限定符的展示:收起 `/slug`、`/@root`,企业实例另挂「团队共享」标签。 */+export interface GhostQualifierDisplay {+ /** 企业实例为「团队共享」;root 实例为 null(只收起 `/@root`,不加标签)。 */+ label: string | null;+}++/**+ * 同一插件最多一份 root 加一份企业实例,按 namespace 即可区分:企业实例标+ * 「团队共享」,root 不加标签(默认即个人)。$ 菜单与输入框胶囊共用这一条判定;+ * 未冲突、标签未就绪,或当前项 / 任一同名实例的 namespace 未知(旧端、迁移中的+ * 旧安装)时返回 null,限定符照常显示:root 不带标签,只有在每个同名实例都能被+ * 区分时才可以收起 `/@root`,否则会和未知实例的裸指令一模一样。+ */+export function ghostQualifierDisplay(+ ghost: { namespace?: string | null; manifest: { command?: string } },+ qualified: boolean,+ labels: GhostSourceLabels | null,+ roster: readonly { namespace?: string | null; manifest: { command?: string } }[],+): GhostQualifierDisplay | null {+ if (!qualified || !labels || ghost.namespace === undefined) return null;+ const command = ghost.manifest.command?.toLowerCase();+ const unknownSibling = roster.some((other) =>+ other !== ghost &&+ other.namespace === undefined &&+ other.manifest.command?.toLowerCase() === command);+ if (unknownSibling) return null;+ return { label: ghost.namespace === null ? null : labels.team };+}+/** 由匹配结果构建胶囊 decoration(未命中 → 空集)。 */-function buildDecorations(doc: PMNode, ghosts: GhostCommandSource[]): DecorationSet {+function buildDecorations(+ doc: PMNode,+ ghosts: GhostCommandSource[],+ sourceLabels: GhostSourceLabels | null,+): DecorationSet {const match = findGhostCommandMatch(doc, ghosts);if (!match) return DecorationSet.empty;- return DecorationSet.create(doc, [+ const decorations = [// 触发符($ 及全角变体)只做识别不做展示:胶囊头像已点明"这是意识",// 字符本身渲染层隐藏(doc 里仍在,编辑/发送/复制都不受影响;改坏词// 导致胶囊消失时它自然重新显形)。Decoration.inline(match.from, match.from + 1, { class: 'ghost-cmd-sigil' }),- Decoration.inline(match.from + 1, match.to, ghostPillAttrs(match.ghost)),- ]);+ ];+ // 限定符是给发送期消歧的机器字符,与触发符一样只在渲染层隐藏。+ const display = ghostQualifierDisplay(match.ghost, match.to > match.wordEnd, sourceLabels, ghosts);+ if (display) {+ decorations.push(+ Decoration.inline(match.from + 1, match.wordEnd, {+ ...ghostPillAttrs(match.ghost),+ ...(display.label ? { 'data-ghost-cmd-origin': display.label } : {}),+ }),+ Decoration.inline(match.wordEnd, match.to, { class: 'ghost-cmd-qualifier' }),+ );+ } else {+ decorations.push(Decoration.inline(match.from + 1, match.to, ghostPillAttrs(match.ghost)));+ }+ return DecorationSet.create(doc, decorations);}/** 词尾后面紧跟的分隔空白(不含换行——换行在 doc 里是 hardBreak,不是文本)。 */@@ -193,11 +265,17 @@ export function applyGhostCommandBackspace(view: EditorView): boolean {* 推送最新意识清单(装/卸/唤醒/沉睡即时反映)。同引用去重——* 清单的 state 引用只在数据更新时变化。*/-export function setGhostCommandRoster(editor: Editor | null, ghosts: GhostCommandSource[]): void {+export function setGhostCommandRoster(+ editor: Editor | null,+ ghosts: GhostCommandSource[],+ sourceLabels: GhostSourceLabels | null = null,+): void {if (!editor || editor.isDestroyed) return;const current = PLUGIN_KEY.getState(editor.state);- if (current && current.ghosts === ghosts) return;- editor.view.dispatch(editor.state.tr.setMeta(META_KEY, ghosts));+ if (current && current.ghosts === ghosts && current.sourceLabels === sourceLabels) return;+ editor.view.dispatch(+ editor.state.tr.setMeta(META_KEY, ghosts).setMeta(SOURCE_LABELS_META_KEY, sourceLabels),+ );}/** 导出供测试直接在 ProseMirror state 层实例化(同 VoiceInputDraftDecoration)。 */@@ -207,14 +285,18 @@ export function createGhostCommandPlugin(): Plugin<GhostCommandPluginState> {state: {init(_config, state: EditorState): GhostCommandPluginState {// 清单由 ChatInput 挂载后经 meta 推入,首帧空集(用户尚未输入)。- return { ghosts: [], decorations: buildDecorations(state.doc, []) };+ return { ghosts: [], sourceLabels: null, decorations: buildDecorations(state.doc, [], null) };},apply(tr: Transaction, old: GhostCommandPluginState): GhostCommandPluginState {const roster = tr.getMeta(META_KEY) as GhostCommandSource[] | undefined;- if (roster) return { ghosts: roster, decorations: buildDecorations(tr.doc, roster) };+ if (roster) {+ const labelsMeta = tr.getMeta(SOURCE_LABELS_META_KEY) as GhostSourceLabels | null | undefined;+ const sourceLabels = labelsMeta === undefined ? old.sourceLabels : labelsMeta;+ return { ghosts: roster, sourceLabels, decorations: buildDecorations(tr.doc, roster, sourceLabels) };+ }if (!tr.docChanged) return old;// 只扫消息头部的指令 run,输入量级下全量重算成本可忽略(同 CjkPunct)。- return { ghosts: old.ghosts, decorations: buildDecorations(tr.doc, old.ghosts) };+ return { ...old, decorations: buildDecorations(tr.doc, old.ghosts, old.sourceLabels) };},},props: {diff --git a/apps/desktop/src/renderer/components/new-chat/SlashCommandPalette.tsx b/apps/desktop/src/renderer/components/new-chat/SlashCommandPalette.tsxindex bc2d4f670d..b36fd79e2d 100644--- a/apps/desktop/src/renderer/components/new-chat/SlashCommandPalette.tsx+++ b/apps/desktop/src/renderer/components/new-chat/SlashCommandPalette.tsx@@ -75,7 +75,16 @@ interface SlashCommandPaletteProps {function metaLabel(cmd: UnifiedCommand): string | null {if (cmd.kind === 'agent-skill') return cmd.source; // 'user' | 'skill'if (cmd.kind === 'agent-builtin') return 'agent-cmd';- return null; // 'desktop' 不显示标签 (内置默认)+ return cmd.meta ?? null; // 'desktop' 默认不显示标签,插件同名时显示来源+}++function displayName(cmd: UnifiedCommand): string {+ return cmd.kind === 'desktop' && cmd.label ? cmd.label : cmd.name;+}++/** 同名插件的两行显示名相同,读屏要连同「团队共享」标签一起报出才能区分。 */+function accessibleName(cmd: UnifiedCommand): string {+ return cmd.kind === 'desktop' && cmd.meta ? `${displayName(cmd)} ${cmd.meta}` : displayName(cmd);}export function SlashCommandPalette({@@ -277,7 +286,7 @@ export function SlashCommandPalette({ref={focused ? focusedRef : undefined}type="button"aria-disabled={unavailable}- aria-label={unavailable ? `${cmd.name}: ${t('commandPalette.projectSkillNotLoaded')}` : cmd.name}+ aria-label={unavailable ? `${accessibleName(cmd)}: ${t('commandPalette.projectSkillNotLoaded')}` : accessibleName(cmd)}title={unavailable ? t('commandPalette.projectSkillNotLoaded') : undefined}// `onMouseDown` instead of `onClick` so the textarea// keeps focus — click would fire after blur.@@ -297,7 +306,7 @@ export function SlashCommandPalette({unavailable && 'cursor-not-allowed opacity-50',)}>- {withMenuLabels(<span className="truncate">{cmd.name}</span>)}+ {withMenuLabels(<span className="truncate">{displayName(cmd)}</span>)}{official ? (<OfficialSkillBadge />) : metaLabel(cmd) && (@@ -333,7 +342,7 @@ export function SlashCommandPalette({}}><div className="flex items-center gap-1 text-14 font-medium text-[var(--cmd-palette-item-text)]">- <span className="min-w-0 truncate">{focusedCmd.name}</span>+ <span className="min-w-0 truncate">{displayName(focusedCmd)}</span>{onOpenSkillDetails && focusedCmd.kind === 'agent-skill'&& focusedCmd.source === 'skill' && focusedCmd.path && focusedCmd.origin !== 'package'&& (allowProjectSkillDetails || focusedCmd.scope === 'global' || focusedCmd.scope === 'user') && (diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/SlashCommandPalette.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/SlashCommandPalette.test.tsxindex 9f5a021e3c..14282da27f 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/SlashCommandPalette.test.tsx+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/SlashCommandPalette.test.tsx@@ -245,3 +245,33 @@ describe('SlashCommandPalette project Skill rows', () => {expect(screen.queryByText('skillhub.builtIn.official')).toBeNull();});});++describe('SlashCommandPalette plugin rows', () => {+ it('shows the personal sibling without a qualifier or tag', () => {+ const root: UnifiedCommand = {+ kind: 'desktop', name: 'xd-sites/@root', description: 'XD Sites', label: 'xd-sites',+ };+ const onSelect = vi.fn();+ render(<SlashCommandPalette query="" commands={[root]} focusedIndex={-1}+ onFocusedIndexChange={vi.fn()} onSelect={onSelect} onClose={vi.fn()} />);+ const row = screen.getByRole('button', { name: 'xd-sites' });+ expect(row.textContent).toBe('xd-sites');+ fireEvent.mouseDown(row);+ expect(onSelect).toHaveBeenCalledWith(root);+ });++ it('shows the display label and source tag but selects the qualified token', () => {+ const qualified: UnifiedCommand = {+ kind: 'desktop', name: 'xd-sites/xd', description: 'XD Sites', label: 'xd-sites', meta: '团队共享',+ };+ const onSelect = vi.fn();+ render(<SlashCommandPalette query="" commands={[qualified]} focusedIndex={-1}+ onFocusedIndexChange={vi.fn()} onSelect={onSelect} onClose={vi.fn()} />);+ // The accessible name carries the source tag so same-name rows stay distinguishable.+ const row = screen.getByRole('button', { name: 'xd-sites 团队共享' });+ expect(row.textContent).toContain('团队共享');+ expect(row.textContent).not.toContain('/xd');+ fireEvent.mouseDown(row);+ expect(onSelect).toHaveBeenCalledWith(qualified);+ });+});diff --git a/apps/desktop/src/renderer/components/new-chat/ghostComposerPlacement.ts b/apps/desktop/src/renderer/components/new-chat/ghostComposerPlacement.tsindex 7677b9e70e..2f1062a3c5 100644--- a/apps/desktop/src/renderer/components/new-chat/ghostComposerPlacement.ts+++ b/apps/desktop/src/renderer/components/new-chat/ghostComposerPlacement.ts@@ -33,7 +33,12 @@ export function placeGhostAtComposerStart(// 替换识别看完整已安装命令集:旧 Plugin 即使已停用或被当前// 工作目录禁用,它在草稿头的 `$old` 仍应被新选择替换。能否发送// 仍由可用 roster / 发送期闸门单独决定。- const match = findGhostCommandMatch(doc, [...installedRoster], { includeDisabled: true });+ // 唯一时插入的裸 `$draw` 在之后装了同名实例后会有歧义,仍按消息头指令替换,+ // 不叠成 `$draw/acme $draw`。+ const match = findGhostCommandMatch(doc, [...installedRoster], {+ includeDisabled: true,+ ambiguousBareToken: true,+ });const transaction = editor.state.tr;if (match) {diff --git a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsxindex efc157926e..95f40b828f 100644--- a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx@@ -188,6 +188,7 @@ import { type HomeSuggestionId, homeSuggestionPromptKey } from './homeSuggestionimport {buildHomeTaskCatalog,pluginSuggestionComposerText,+ pluginSuggestionDisplayText,readPluginRecommendationSnapshot,type HomeTaskSuggestion,} from './pluginHomeSuggestions';@@ -5337,9 +5338,9 @@ export function NewMakerDraftRoute() {});return true;}, []);- // 一条建议「点击后会填入的文字」的唯一计算:视觉预览与读屏描述都用它,点击填入走同一个- // pluginSuggestionComposerText。插件可用时带 $指令(或插件调用说明);需要先安装的插件- // 点击后走安装引导、不会立即填入,只显示建议本身。插件清单变化时随之重算。+ // 一条建议的预览与读屏描述:内容与点击填入的 pluginSuggestionComposerText 一致,+ // 只是同名限定符按输入框胶囊的规则收起。插件可用时带 $指令(或插件调用说明);需要+ // 先安装的插件点击后走安装引导、不会立即填入,只显示建议本身。插件清单变化时随之重算。// 可用插件表按插件清单与工作目录缓存:filterGhostsForWorkdir 会同步查询目录禁用表,// 不能在每次渲染 / 每条建议上重复调用。const installedGhosts = useInstalledGhosts(!isDeviceLinkDraft);@@ -5352,19 +5353,33 @@ export function NewMakerDraftRoute() {),[isDeviceLinkDraft, effectiveWorkingDir, installedGhosts],);- const suggestionComposerText = useCallback(- (suggestion: HomeTaskSuggestion) => {+ const suggestionSourceLabels = useMemo(+ () => ({ team: t('settings.ghosts.commandPaletteSource.team') }),+ [t],+ );+ // 悬停预览与读屏描述是纯文本,不经过输入框胶囊:按与胶囊同一条判定收起同名+ // 限定符(读屏另补「团队共享」);点击填入仍走 pluginSuggestionComposerText,+ // 保留限定符供发送期消歧。同名判定用完整安装清单(含停用实例),填入后再启用+ // 同名插件,已插入的指令仍能精确命中;能否选择仍只看 usableSuggestionGhosts。+ const suggestionDisplayText = useCallback(+ (suggestion: HomeTaskSuggestion, withTag: boolean) => {const ghost = suggestion.pluginId? usableSuggestionGhosts.get(suggestion.pluginId): undefined;- return ghost ? pluginSuggestionComposerText(suggestion.prompt, ghost, t, [...usableSuggestionGhosts.values()]) : suggestion.prompt;+ return ghost+ ? pluginSuggestionDisplayText(suggestion.prompt, ghost, t, installedGhosts, suggestionSourceLabels, withTag)+ : suggestion.prompt;},- [t, usableSuggestionGhosts],+ [installedGhosts, suggestionSourceLabels, t, usableSuggestionGhosts],+ );+ const suggestionDescriptionText = useCallback(+ (suggestion: HomeTaskSuggestion) => suggestionDisplayText(suggestion, true),+ [suggestionDisplayText],);const handleSuggestionPreview = useCallback((suggestion: HomeTaskSuggestion | null) =>- setSuggestionPreview(suggestion ? suggestionComposerText(suggestion) : null),- [suggestionComposerText],+ setSuggestionPreview(suggestion ? suggestionDisplayText(suggestion, false) : null),+ [suggestionDisplayText],);const handleHomeSuggestion = useCallback(@@ -5462,7 +5477,7 @@ export function NewMakerDraftRoute() {// 填进输入框而不是直接发送;ChatInput 发送时会自己展开 $command。无指令插件发送时// 识别不出所用插件,所以选中插件建议并成功填入即记一次最近使用(有指令的插件发送时// 还会再记一次,只刷新时间,不影响排序语义)。- if (fillComposerWithSuggestion(pluginSuggestionComposerText(suggestion.prompt, ghost, t, usableGhosts))) {+ if (fillComposerWithSuggestion(pluginSuggestionComposerText(suggestion.prompt, ghost, t, installedGhosts))) {void window.electronAPI.ghosts.markUsed(installedGhostStoragePart(ghost)).catch(() => undefined);}} catch {@@ -5936,7 +5951,7 @@ export function NewMakerDraftRoute() {includePlugins={!isRemoteProjectDraft && !isDeviceLinkDraft}onPluginSelect={handlePluginSuggestion}onPreviewChange={handleSuggestionPreview}- composerTextFor={suggestionComposerText}+ composerTextFor={suggestionDescriptionText}/>)}{/* 首页「新建目标」弹窗:无 sessionId → onCreate 建会话并 setGoal(见 handleCreateGoal)。diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/pluginHomeSuggestions.test.ts b/apps/desktop/src/renderer/features/cc-agent/__tests__/pluginHomeSuggestions.test.tsindex c72ec44d3f..ffdce902f4 100644--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/pluginHomeSuggestions.test.ts+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/pluginHomeSuggestions.test.ts@@ -4,6 +4,8 @@ import {buildHomeTaskCatalog,nextHomeTaskBatch,pluginSuggestionCategory,+ pluginSuggestionComposerText,+ pluginSuggestionDisplayText,type HomeTaskBatch,} from '../pluginHomeSuggestions';@@ -130,3 +132,30 @@ describe('host plugin recommendation selection', () => {expect(next.items.every((x) => !x.pluginId)).toBe(true);});});++describe('pluginSuggestionDisplayText', () => {+ const t = (key: string) => key;+ const labels = { team: '团队共享' };+ const plugin = (namespace?: string | null) => ({+ manifest: { id: 'sites', name: 'Sites', command: 'draw' },+ ...(namespace !== undefined ? { namespace } : {}),+ });++ it('hides a same-name qualifier like the composer pill and keeps it in the inserted text', () => {+ const org = plugin('acme');+ const root = plugin(null);+ const roster = [org, root];+ expect(pluginSuggestionComposerText('go', org, t, roster)).toBe('$draw/acme go');+ expect(pluginSuggestionDisplayText('go', org, t, roster, labels, false)).toBe('$draw go');+ expect(pluginSuggestionDisplayText('go', org, t, roster, labels, true)).toBe('$draw 团队共享 go');+ expect(pluginSuggestionDisplayText('go', root, t, roster, labels, true)).toBe('$draw go');+ });++ it('keeps unique commands bare and shows the qualifier when a sibling is not yet identifiable', () => {+ const org = plugin('acme');+ expect(pluginSuggestionDisplayText('go', org, t, [org], labels, true)).toBe('$draw go');+ const root = plugin(null);+ const legacy = plugin();+ expect(pluginSuggestionDisplayText('go', root, t, [root, legacy], labels, true)).toBe('$draw/@root go');+ });+});diff --git a/apps/desktop/src/renderer/features/cc-agent/pluginHomeSuggestions.ts b/apps/desktop/src/renderer/features/cc-agent/pluginHomeSuggestions.tsindex 5842741481..26b549fab7 100644--- a/apps/desktop/src/renderer/features/cc-agent/pluginHomeSuggestions.ts+++ b/apps/desktop/src/renderer/features/cc-agent/pluginHomeSuggestions.ts@@ -1,7 +1,11 @@import { localizeGhostRecommendation, type GhostRecommendation } from '@cindy/plugin-protocol';import type { HomePluginRecommendationsSnapshot } from '../../../shared/homePluginRecommendations';import { hasDeliveryNamespace } from '../../../shared/pluginIdentity';-import { formatGhostCommandInsertion } from '../../cindy-brain/ghostCommand';+import { formatGhostCommandInsertion, formatGhostCommandToken } from '../../cindy-brain/ghostCommand';+import {+ ghostQualifierDisplay,+ type GhostSourceLabels,+} from '../../components/new-chat/GhostCommandDecoration';import {HOME_SUGGESTION_CATALOG,homeSuggestionLabelKey,@@ -170,9 +174,10 @@ export function nextHomeTaskBatch(}/**- * Composer text for a plugin suggestion whose plugin is usable here. Hover preview and click- * fill share this so the preview always shows exactly what lands in the composer; `$command`- * stays as typed text and ChatInput expands it on send.+ * Composer text for a plugin suggestion whose plugin is usable here: what the click fill+ * inserts. `$command` stays as typed text and ChatInput expands it on send. The hover preview+ * and description use `pluginSuggestionDisplayText`, which differs only by hiding a same-name+ * qualifier the way the composer pill does.*/export function pluginSuggestionComposerText(prompt: string,@@ -189,3 +194,27 @@ export function pluginSuggestionComposerText(: ghost.manifest.id,})}`;}++/**+ * What the hover preview and the screen-reader description show for a suggestion. The+ * inserted text may carry a `/slug` or `/@root` qualifier for send-time disambiguation;+ * like the composer pill, these plain-text surfaces hide it whenever the pill would+ * (same `ghostQualifierDisplay` rule). `withTag` appends 团队共享 for an organization+ * sibling so screen readers can still tell same-name plugins apart.+ */+export function pluginSuggestionDisplayText(+ prompt: string,+ ghost: { manifest: { id: string; name: string; command?: string }; dir?: string; namespace?: string | null },+ t: (key: string, options?: Record<string, unknown>) => string,+ roster: readonly { manifest: { command?: string }; namespace?: string | null }[],+ sourceLabels: GhostSourceLabels,+ withTag: boolean,+): string {+ const command = ghost.manifest.command;+ if (!command) return pluginSuggestionComposerText(prompt, ghost, t, roster);+ const token = formatGhostCommandToken(ghost, roster) ?? command;+ const display = ghostQualifierDisplay(ghost, token !== command, sourceLabels, roster);+ if (!display) return `$${token} ${prompt}`;+ const tag = withTag && display.label ? ` ${display.label}` : '';+ return `$${command}${tag} ${prompt}`;+}diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex e939628204..fa94de22e6 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -6561,6 +6561,9 @@"slotWorkspace": "Workspace sessions"},"commandPaletteTag": "Plugin command",+ "commandPaletteSource": {+ "team": "Team shared"+ },"library": {"title": "Durable library","loading": "Loading library info…",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex a792a77050..f2ed087ff4 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -6536,6 +6536,9 @@"slotWorkspace": "ワークスペースセッション"},"commandPaletteTag": "プラグインコマンド",+ "commandPaletteSource": {+ "team": "チーム共有"+ },"library": {"title": "永続ライブラリ","loading": "ライブラリ情報を読み込み中…",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 4bb5e0680b..0bcf938c70 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -6536,6 +6536,9 @@"slotWorkspace": "워크스페이스 세션"},"commandPaletteTag": "플러그인 명령",+ "commandPaletteSource": {+ "team": "팀 공유"+ },"library": {"title": "영구 라이브러리","loading": "라이브러리 정보를 불러오는 중…",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 2e035355b3..4ce33eafd0 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -6536,6 +6536,9 @@"slotWorkspace": "工作区任务"},"commandPaletteTag": "插件指令",+ "commandPaletteSource": {+ "team": "团队共享"+ },"library": {"title": "持久作品库","loading": "正在读取库信息…",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex b8f87b7da7..6915aaa774 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -6536,6 +6536,9 @@"slotWorkspace": "工作區任務"},"commandPaletteTag": "插件指令",+ "commandPaletteSource": {+ "team": "團隊共享"+ },"library": {"title": "持久作品庫","loading": "正在讀取庫資訊…",diff --git a/apps/desktop/src/renderer/lib/__tests__/slashCommands.test.ts b/apps/desktop/src/renderer/lib/__tests__/slashCommands.test.tsindex 70ee0e9cec..20dc5058d7 100644--- a/apps/desktop/src/renderer/lib/__tests__/slashCommands.test.ts+++ b/apps/desktop/src/renderer/lib/__tests__/slashCommands.test.ts@@ -176,6 +176,22 @@ describe('rewriteAgentSkillInvocationForDispatch', () => {});describe('filterSlashCommands', () => {+ it('ranks a plugin command by its display label so hidden qualifiers keep exact matches on top', () => {+ const prefixed = Array.from({ length: 30 }, (_, i) => ({+ kind: 'desktop' as const, name: `draw-${i}`, description: '',+ }));+ const shared = [+ { kind: 'desktop' as const, name: 'draw/@root', description: '', label: 'draw' },+ { kind: 'desktop' as const, name: 'draw/acme', description: '', label: 'draw', meta: '团队共享' },+ ];+ const commands = [...prefixed, ...shared];++ expect(filterSlashCommands(commands, 'draw').slice(0, 2).map((command) => command.name))+ .toEqual(['draw/@root', 'draw/acme']);+ // The full qualified token still matches what will be inserted.+ expect(filterSlashCommands(commands, 'draw/acme').map((command) => command.name)).toEqual(['draw/acme']);+ });+it('places Cindy official entries before ordinary commands in the initial palette', () => {const commands = [{ kind: 'desktop' as const, name: 'help', description: 'Help' },diff --git a/apps/desktop/src/renderer/lib/slashCommands.ts b/apps/desktop/src/renderer/lib/slashCommands.tsindex cef71df9b9..893a887477 100644--- a/apps/desktop/src/renderer/lib/slashCommands.ts+++ b/apps/desktop/src/renderer/lib/slashCommands.ts@@ -296,10 +296,18 @@ export function filterSlashCommands(limit = 25,): UnifiedCommand[] {const q = query.trim().toLowerCase();+ const rankOf = (text: string): number => {+ const value = text.toLowerCase();+ return value === q ? 0 : value.startsWith(q) ? 1 : value.includes(q) ? 2 : -1;+ };const filtered = commands.map((command, index) => {- const name = command.name.toLowerCase();- const rank = q ? (name === q ? 0 : name.startsWith(q) ? 1 : name.includes(q) ? 2 : -1) : 0;+ // 插件指令同名时 name 带隐藏的 `/slug`,菜单只显示 label:按两者中更好的一个排序,+ // 输入显示名算精确匹配,输入完整限定指令也照常命中。+ const ranks = [rankOf(command.name)];+ if (command.kind === 'desktop' && command.label) ranks.push(rankOf(command.label));+ const matched = ranks.filter((r) => r >= 0);+ const rank = q ? (matched.length > 0 ? Math.min(...matched) : -1) : 0;const officialPriority = isCindyOfficialSlashCommand(command) ? 0 : 1;return { command, index, rank, officialPriority };})diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.cssindex f03e2beadf..59127ef179 100644--- a/apps/desktop/src/renderer/styles/globals.css+++ b/apps/desktop/src/renderer/styles/globals.css@@ -795,6 +795,20 @@ html:lang(ko) {.ProseMirror .ghost-cmd-pill + .ghost-cmd-pill::before {content: none;}+/* 同名冲突的 `/slug`、`/@root` 限定符:字符留在 doc 里供发送期消歧,渲染层+ 收起;企业实例在同一颗胶囊尾部显示「团队共享」标签。 */+.ProseMirror .ghost-cmd-qualifier {+ display: none;+}+.ProseMirror .ghost-cmd-pill[data-ghost-cmd-origin]::after {+ content: attr(data-ghost-cmd-origin);+ margin-left: 6px;+ color: var(--text-tertiary);+}+/* CJK 标点会把胶囊切成多段、每段都带来源属性:只在最后一段显示标签。 */+.ProseMirror .ghost-cmd-pill[data-ghost-cmd-origin]:has(+ .ghost-cmd-pill)::after {+ content: none;+}/* F-FI-3: Scrollbar-hide utility for thumbnail strip */.scrollbar-hide {diff --git a/packages/maker-core/src/types/palette.ts b/packages/maker-core/src/types/palette.tsindex aec83502a7..c493f3192f 100644--- a/packages/maker-core/src/types/palette.ts+++ b/packages/maker-core/src/types/palette.ts@@ -44,8 +44,13 @@ export type CommandKind = 'desktop' | 'agent-builtin' | 'agent-skill';/** A desktop-side command. Execution is performed in the main process. */export interface DesktopCommandMeta {kind: 'desktop';+ /** Inserted text and identity key. */name: string;description: string;+ /** Display text when it differs from the inserted `name` (e.g. a hidden `/slug` qualifier). */+ label?: string;+ /** Trailing tag in the row, e.g. a plugin's source. */+ meta?: string;}/** A command baked into the agent (e.g. /compact for Claude Code). */diff --git a/packages/maker-shared/src/ghostCommand.ts b/packages/maker-shared/src/ghostCommand.tsindex b054d7fd5b..5dc5b8d5fd 100644--- a/packages/maker-shared/src/ghostCommand.ts+++ b/packages/maker-shared/src/ghostCommand.ts@@ -95,20 +95,24 @@ export function parseGhostCommandWord(text: string): string | null {return parseGhostCommandToken(text)?.word ?? null;}-/** Palette / insertion token: `draw` or `draw/acme`. */+/**+ * Palette / insertion token. A unique command stays bare (`draw`); only a+ * command shared with another installed instance is qualified as+ * `draw/@root` or `draw/acme`, so the org slug is not shown without need.+ * The roster must cover every instance send-time resolution can see; the+ * composer also passes disabled ones so re-enabling cannot make it ambiguous.+ */export function formatGhostCommandToken(ghost: {manifest: { command?: string };namespace?: string | null;}, roster: readonly { manifest: { command?: string }; namespace?: string | null }[] = []): string | null {const command = ghost.manifest.command;if (!command) return null;- if (ghost.namespace === null && roster.some((other) =>- other !== ghost && other.manifest.command?.toLowerCase() === command.toLowerCase())) {- return command + '/@root';- }- return hasDeliveryNamespace(ghost) && ghost.namespace- ? `${command}/${ghost.namespace}`- : command;+ if (!hasDeliveryNamespace(ghost)) return command;+ const shared = roster.some((other) =>+ other !== ghost && other.manifest.command?.toLowerCase() === command.toLowerCase());+ if (!shared) return command;+ return ghost.namespace === null ? command + '/@root' : `${command}/${ghost.namespace}`;}export function formatGhostCommandInsertion(ghost: {