Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugins): explain namespace mismatches without hiding installed plugins
Zhao Dengfengb846d6d81e57
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostVisibility.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostVisibility.test.tsindex b67e4f1cd4..2eec00a890 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostVisibility.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostVisibility.test.ts@@ -44,6 +44,27 @@ describe('classifyGhostVisibility namespace', () => {});});+ it.each([+ { installed: root, requested: 'null', target: { ghost_id: 'helper', namespace: null } },+ { installed: enterprise, requested: null, target: { ghost_id: 'helper', namespace: 'acme' } },+ ])('reports an installed identity instead of absence for namespace $requested', ({ installed, requested, target }) => {+ const result = classifyGhostVisibility('helper', null, { ...deps, listGhosts: () => [installed] }, requested);+ expect(result).toMatchObject({ ok: false, errorCode: 'GHOST_NAMESPACE_MISMATCH' });+ if (result.ok) return;+ expect(result.message).toContain(JSON.stringify(target));+ expect(result.message).toContain('JSON null');+ });++ it('keeps the literal organization slug null distinct from JSON null', () => {+ const namedNull = ghost('helper', 'null');+ const stageDeps = { ...deps, listGhosts: () => [root, namedNull] };+ expect(classifyGhostVisibility('helper', null, stageDeps, 'null')).toMatchObject({ ok: true, ghost: namedNull });+ expect(classifyGhostVisibility('helper', null, stageDeps, null)).toMatchObject({ ok: true, ghost: root });+ expect(classifyGhostVisibility('missing', null, stageDeps, 'null')).toMatchObject({+ ok: false, errorCode: 'GHOST_NOT_FOUND',+ });+ });+it('checks workdir disable against the physical storage part', () => {const org = ghost('helper', 'acme');const inPlace = { ...ghost('xd-feishu', 'xd'), dir: '/tmp/xd-feishu' };@@ -85,8 +106,11 @@ describe('classifyGhostVisibility namespace', () => {const stageDeps = { ...deps, listGhosts: () => [pending] };expect(classifyGhostVisibility('xd-feishu', null, stageDeps)).toMatchObject({ ok: true, ghost: pending });expect(classifyGhostVisibility('xd-feishu', null, stageDeps, null)).toMatchObject({- ok: false, errorCode: 'GHOST_NOT_FOUND',+ ok: false, errorCode: 'GHOST_NAMESPACE_MISMATCH',});+ const result = classifyGhostVisibility('xd-feishu', null, stageDeps, null);+ if (result.ok) return;+ expect(result.message).toContain('{"ghost_id":"xd-feishu"}');});diff --git a/apps/desktop/src/main/cindy-brain/ghostSetupCoordinator.ts b/apps/desktop/src/main/cindy-brain/ghostSetupCoordinator.tsindex 819a8865bb..247bbd28c9 100644--- a/apps/desktop/src/main/cindy-brain/ghostSetupCoordinator.ts+++ b/apps/desktop/src/main/cindy-brain/ghostSetupCoordinator.ts@@ -34,6 +34,7 @@ export type GhostSetupEnsureResult =| 'TIMEOUT'| 'INTERNAL'| 'GHOST_NOT_FOUND'+ | 'GHOST_NAMESPACE_MISMATCH'| 'GHOST_RETIRED'| 'GHOST_ASLEEP'| 'GHOST_DISABLED_IN_WORKDIR'@@ -49,6 +50,7 @@ export type GhostSetupTargetValidation =ok: false;errorCode:| 'GHOST_NOT_FOUND'+ | 'GHOST_NAMESPACE_MISMATCH'| 'GHOST_RETIRED'| 'GHOST_ASLEEP'| 'GHOST_DISABLED_IN_WORKDIR'diff --git a/apps/desktop/src/main/cindy-brain/ghostVisibility.ts b/apps/desktop/src/main/cindy-brain/ghostVisibility.tsindex bff3d349b2..411b9bc51f 100644--- a/apps/desktop/src/main/cindy-brain/ghostVisibility.ts+++ b/apps/desktop/src/main/cindy-brain/ghostVisibility.ts@@ -25,7 +25,7 @@ export type GhostVisibilityResult =| { ok: true; ghost: InstalledGhost }| {ok: false;- errorCode: 'GHOST_NOT_FOUND' | 'GHOST_ASLEEP' | 'GHOST_DISABLED_IN_WORKDIR' | 'GHOST_RETIRED' | 'GHOST_AMBIGUOUS';+ errorCode: 'GHOST_NOT_FOUND' | 'GHOST_NAMESPACE_MISMATCH' | 'GHOST_ASLEEP' | 'GHOST_DISABLED_IN_WORKDIR' | 'GHOST_RETIRED' | 'GHOST_AMBIGUOUS';message: string;candidates?: Array<{ ghostId: string; namespace: string | null }>;};@@ -56,6 +56,25 @@ export function classifyGhostVisibility(: { status: 'missing' as const };})();if (resolved.status === 'missing') {+ const sameName = namespace === undefined ? [] : listed.filter((ghost) => ghost.manifest.id === ghostId);+ if (sameName.length > 0) {+ // A model may quote JSON null as the valid organization slug "null".+ // Preserve exact addressing: explain the mismatch, never redirect a call+ // or change the namespace of a pending legacy installation.+ const targets = sameName.map((ghost) => ({+ ghost_id: ghost.manifest.id,+ ...deliveryNamespaceFields(ghost),+ }));+ return {+ ok: false,+ errorCode: 'GHOST_NAMESPACE_MISMATCH',+ message: `插件已安装,但 namespace=${JSON.stringify(namespace)} 未匹配该插件的安装身份。` ++ 'JSON null(不带引号)表示 root;字符串 "null" 表示名为 null 的企业,两者不同。' ++ `已安装身份:${JSON.stringify(targets)}。` ++ '请核对目标后按对应身份原样传参,保留 namespace 的类型;身份未提供 namespace 时省略该字段。' ++ '不要原样重试错误参数,也不要自动改选其他实例。',+ };+ }return {ok: false,errorCode: 'GHOST_NOT_FOUND',diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.tsindex 7f3e16077a..150356da49 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/ghostWorkdirGate.test.ts@@ -335,7 +335,7 @@ function makeDeps(function clearAllPrefs(): void {// 把测试涉及的目录 × id 全部清一遍(幂等;清空后 store 自动删文件)。for (const dir of [WORKDIR, `${WORKDIR} `, '/proj/beta', 'E:/Repo']) {- for (const id of ['art', 'other', 'missing', 'sleeping', 'account', 'workflow-guide']) {+ for (const id of ['art', '_root__art', 'other', 'missing', 'sleeping', 'account', 'workflow-guide']) {setGhostDisabledForWorkdir(dir, id, false);}}@@ -1369,6 +1369,54 @@ describe('connect_account ordinary task entry', () => {});describe('花名册 / ghost_list 过滤', () => {+ // Regression: a listed root was repeatedly addressed with the string "null".+ // Exercise the real MCP handlers and host resolver with the same session deps;+ // a rejected address must never reach setup, attachment grants or dispatch.+ it.each(['claude-code', 'codex', 'pi'] as const)(+ '%s recovers in the same session after correcting a quoted null namespace', async (agentKind) => {+ listMock.mockReturnValue([{+ ...(chipGhost('art', ['tool'], {+ manual: { items: [{ dir: 'docs', name: 'guide', description: 'Usage guide' }] },+ }) as object),+ namespace: null,+ dir: path.join(tmpUserData, '_ns', '_root', 'art'),+ }]);+ const deps = makeDeps(agentKind);+ const listed = JSON.parse((await handleGhostList(deps)).content[0].text).ghosts[0];+ expect(listed).toMatchObject({ id: 'art', namespace: null });+ const wrong = { ghost_id: listed.id, namespace: 'null' };+ const results = [+ await handleGhostInfo(deps, wrong),+ await handleGhostManual(deps, wrong),+ await handleGhostCall(deps, { ...wrong, tool: 'run', attachments: ['cindy-media://blobs/example.png'] }),+ ];+ const target = { ghost_id: listed.id, namespace: listed.namespace };+ for (const result of results) {+ expect(result.isError).toBe(true);+ const payload = JSON.parse(result.content[0].text);+ expect(payload).toMatchObject({ ok: false, errorCode: 'GHOST_NAMESPACE_MISMATCH' });+ expect(payload.message).toContain(JSON.stringify(target));+ }+ await expect(deps.connectAccount!({ kind: 'plugin', id: 'art', namespace: 'null' }))+ .resolves.toMatchObject({ ok: false, errorCode: 'GHOST_NAMESPACE_MISMATCH' });+ expect(ensureReadyMock).not.toHaveBeenCalled();+ expect(grantAttachmentsMock).not.toHaveBeenCalled();+ expect(dispatchMock).not.toHaveBeenCalled();+ expect(JSON.parse((await handleGhostInfo(deps, target)).content[0].text))+ .toMatchObject({ ok: true, ghost: { id: 'art', namespace: null } });+ expect(JSON.parse((await handleGhostManual(deps, target)).content[0].text))+ .toMatchObject({ ok: true, manual: [{ name: 'guide' }] });+ expect(JSON.parse((await handleGhostCall(deps, { ...target, tool: 'run' })).content[0].text))+ .toMatchObject({ ok: true, result: 'done' });+ expect(dispatchMock).toHaveBeenCalledOnce();+ expect(dispatchMock).toHaveBeenCalledWith(expect.objectContaining({ ghostId: '_root__art' }));+ setGhostDisabledForWorkdir(WORKDIR, '_root__art', true);+ expect(JSON.parse((await handleGhostCall(deps, { ...target, tool: 'run' })).content[0].text))+ .toMatchObject({ ok: false, errorCode: 'GHOST_DISABLED_IN_WORKDIR' });+ expect(dispatchMock).toHaveBeenCalledOnce();+ },+ );+it.each((['claude-code', 'codex', 'pi'] as const).flatMap((agentKind) => [true, false].map((pending) => ({ agentKind, pending })),))(@@ -1399,7 +1447,7 @@ describe('花名册 / ghost_list 过滤', () => {expect(deps.getRosterItems?.()[0]).not.toHaveProperty('namespace');expect(getGhostRosterPrompt({ workingDir: WORKDIR })).not.toContain('"namespace"');if (isPending) {- await expect(deps.getAwakeGhost('art', null)).resolves.toMatchObject({ ok: false, errorCode: 'GHOST_NOT_FOUND' });+ await expect(deps.getAwakeGhost('art', null)).resolves.toMatchObject({ ok: false, errorCode: 'GHOST_NAMESPACE_MISMATCH' });}expect(dispatchMock).toHaveBeenCalledTimes(2);},diff --git a/docs/ghost-progressive-discovery.md b/docs/ghost-progressive-discovery.mdindex 0f03457531..b227c14e1a 100644--- a/docs/ghost-progressive-discovery.md+++ b/docs/ghost-progressive-discovery.md@@ -77,6 +77,15 @@ frontmatter `name + description` 的召回作用;`manual.items` 只是插件- `null`:已确认的 root。不能用来点名唯一的待迁移旧安装。- 字符串:该企业的 orgSlug。+调用参数必须保留发现结果中的 JSON 类型:`null` 与字符串 `"null"` 不同,后者是合法的+企业 slug,不能自动转成 root。插件名已安装但显式 namespace 不匹配时,共用可见性入口返回+`GHOST_NAMESPACE_MISMATCH`,消息列出保留 namespace 缺省/null/字符串三态的安装身份,+供 Agent 核对目标后修正参数;原调用不进入 Setup、文件交接或插件派发,也不自动改选实例。+修正参数后同一任务即可重新查询/调用,无需重新安装或新建任务。完全没有该插件名时仍返回+`GHOST_NOT_FOUND`。此错误码只增补 MCP 工具结果,不改变安装数据、权限、实例解析或跨设备协议;+旧 Host 仍返回原错误,旧查看端可照常显示文本。实现与回归见 `ghostVisibility.ts`、+`ghostVisibility.test.ts` 和 `ghostWorkdirGate.test.ts`。+同名多实例返回 `GHOST_AMBIGUOUS`,`candidates` 是 `{ ghostId, namespace }`。已确认 root 的 namespace 为 null,企业实例为 orgSlug。待迁移旧安装没有 namespace 字段;它和另一个实例同名时,候选里的 null 可以点到这个待迁移实例。`/命令` 对没有 namespace 字段的旧安装不写 namespace,沿用 `(id: <ghostId>)`。已确认 root 写 `namespace: null`,企业实例写 `namespace: <orgSlug>`。## 3. 花名册(roster)diff --git a/packages/cindy-tools/src/ghost/mcpServer.ts b/packages/cindy-tools/src/ghost/mcpServer.tsindex e81af2d8c9..8edd006757 100644--- a/packages/cindy-tools/src/ghost/mcpServer.ts+++ b/packages/cindy-tools/src/ghost/mcpServer.ts@@ -32,7 +32,7 @@ const ghostNamespaceInput = z.union([z.string().min(1).max(128), z.null()]).optional().describe(- "插件企业身份。字符串为企业 orgSlug。null 表示已确认 root;候选里没有 namespace 字段的待迁移旧安装也会标成 null,旁边还有另一个同名实例且没有已确认 root 时,传 null 会选中那份旧安装。省略时仅当同名实例唯一才兼容解析;多个同名实例返回 GHOST_AMBIGUOUS 并列出候选。",+ '插件企业身份。字符串为企业 orgSlug。JSON null(不带引号)表示已确认 root;字符串 "null" 表示名为 null 的企业,不是 root。按发现结果保留类型,不要把 null 转成字符串。候选里没有 namespace 字段的待迁移旧安装也会标成 null,旁边还有另一个同名实例且没有已确认 root 时,传 null 会选中那份旧安装。省略时仅当同名实例唯一才兼容解析;多个同名实例返回 GHOST_AMBIGUOUS 并列出候选。',);const D_GHOST_LIST = [@@ -56,6 +56,7 @@ const D_GHOST_INFO = ["返回单条完整形态:id、namespace(null=root,字符串=企业 orgSlug)、name、command、recall、setup、tools 与可选 manual 轻量索引。示例:ghost_info({ghost_id:\"helper\", namespace:\"acme\"});省略 namespace 仅当同名实例唯一。拿到目标工具后用 ghost_call,需要长文时用 ghost_manual。","tools 可能为空:Manual-only 插件仍返回完整详情与 manual 索引,通过 ghost_manual 读取;这不授予任何 ghost_call 工具能力。","查询实时反映安装、启用、账号与当前工作目录状态,不要缓存或依赖会话早前的结果。",+ "GHOST_NAMESPACE_MISMATCH 表示插件已安装但 namespace 不匹配;按返回身份核对并修正参数,保留 JSON 类型,不能据此判断插件已卸载或自动改选其他实例。","结构化错误:GHOST_NOT_FOUND / GHOST_AMBIGUOUS(同名多实例,candidates 为 {ghostId, namespace}。已确认 root 的 namespace 是 null;没有 namespace 字段的待迁移旧安装在候选里也会标成 null。旁边还有另一个同名实例、且没有已确认 root 时,传 namespace:null 会选中那份旧安装。按候选补 namespace 后重试,不要改选公开版) / GHOST_ASLEEP / GHOST_DISABLED_IN_WORKDIR / INTERNAL。升级普查中的旧插件没有 namespace 字段,省略 namespace 且同名唯一时才能解析。",].join("\n");@@ -73,6 +74,7 @@ const D_GHOST_CALL = ["调用某个插件(Ghost)提供的工具。ghost_id 与 tool 来自 ghost_info 或 ghost_list 的返回,","或用户消息[插件指令]附带的工具清单;","args 按该工具声明的参数 schema 传 JSON 对象。",+ 'namespace 按发现结果原样传入;root 使用 JSON null,不是字符串 "null"。GHOST_NAMESPACE_MISMATCH 表示地址不匹配、插件未执行;核对目标后修正参数,不要原样重试或自动改选其他实例。',"邮件默认先创建并展示 Cindy 草稿卡,供用户核对收件人和内容,等确认后再发送。只有用户已明确确认这封邮件,或有效的用户/任务指令明确授权该范围内直接发送时,才可不再询问;‘帮我写/回一封邮件’、修改草稿、自动审批或完全访问模式本身不等于确认发送。","即使明确授权直接发送,也必须通过同一草稿卡的公共发送流程,使用最新编辑内容,并保留 10 秒倒计时、撤销和立即发送;不能用底层直发、CLI 或其他旁路跳过。卡片发送点击即为确认,不重复询问;等待最终回执才报告已发送,撤销后不得自动重试。","伙伴中需要授权时,Host 发出独立持久卡并立即返回 SETUP_REQUIRED;结束本轮,等 Host 授权成功后自动续接,不要轮询或重复调用。普通任务仍沿用原调用等待。",@@ -692,7 +694,7 @@ export async function handleGhostList(ghosts,hint:ghosts.length > 0- ? "按 manual 索引用 ghost_manual 读取手册;有工具时用 ghost_call({ghost_id, namespace, tool, args}) 调用已声明工具。同名插件必须带 namespace(null=root)。清单实时,勿缓存。"+ ? '按 manual 索引用 ghost_manual 读取手册;有工具时用 ghost_call({ghost_id, namespace, tool, args}) 调用已声明工具。namespace 按条目原样保留类型:JSON null(不带引号)=root,字符串 "null" 是企业名;条目未提供该字段时省略。同名插件须按返回身份区分。清单实时,勿缓存。': "当前没有已启用的插件。用户可在主界面侧边栏「插件」中安装或启用插件。",});} catch (err) {diff --git a/packages/cindy-tools/src/types.ts b/packages/cindy-tools/src/types.tsindex 176d4c7a4c..c5771c7410 100644--- a/packages/cindy-tools/src/types.ts+++ b/packages/cindy-tools/src/types.ts@@ -144,6 +144,7 @@ export interface CindyGhostInfo {export type CindyGhostCallErrorCode =| 'GHOST_NOT_FOUND' // 未装入或已抽离| 'GHOST_AMBIGUOUS' // 同名多实例,需指定 namespace+ | 'GHOST_NAMESPACE_MISMATCH' // 插件已安装,但指定的 namespace 不匹配;按返回身份修正参数| 'GHOST_ASLEEP' // 沉睡中(用户可在主界面侧边栏「插件」中唤醒)| 'GHOST_RETIRED' // 功能已下线,不可唤醒或重试| 'GHOST_DISABLED_IN_WORKDIR' // 用户在当前工作目录停用了该意识(不要重试)@@ -158,7 +159,7 @@ export type CindyGhostCallErrorCode =export type CindyGhostInfoErrorCode = Extract<CindyGhostCallErrorCode,- 'GHOST_NOT_FOUND' | 'GHOST_AMBIGUOUS' | 'GHOST_ASLEEP' | 'GHOST_DISABLED_IN_WORKDIR' | 'GHOST_RETIRED'+ 'GHOST_NOT_FOUND' | 'GHOST_AMBIGUOUS' | 'GHOST_NAMESPACE_MISMATCH' | 'GHOST_ASLEEP' | 'GHOST_DISABLED_IN_WORKDIR' | 'GHOST_RETIRED'>;/** host 可见性判序回调(getAwakeGhost)的返回:只产可见性错误,不产 INTERNAL。 */