Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): ghost TOOL_NOT_FOUND 错误自愈,补二级分派调用指引 (#1104)
yan50b226187665
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/pipeDispatcher.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/pipeDispatcher.test.tsindex ffd5771707..4809cd0b0f 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/pipeDispatcher.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/pipeDispatcher.test.ts@@ -6,7 +6,7 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';-import { GhostPipeDispatcher, type PipeDispatcherDeps } from '../pipeDispatcher';+import { GhostPipeDispatcher, toolNotFoundMessage, type PipeDispatcherDeps } from '../pipeDispatcher';import type { GhostPipeToolCall, InstalledGhost } from '../../../shared/ghost';import type { GhostRuntimeState } from '../runtime/GhostRuntime';@@ -82,6 +82,32 @@ describe('资格审(结构化错误分类)', () => {expect(r).toMatchObject({ ok: false, errorCode: 'TOOL_NOT_FOUND' });});+ it('TOOL_NOT_FOUND 自愈文案:普通插件列出可用工具', async () => {+ const h = makeHarness();+ const r = await h.dispatcher.callGhostTool({ ...CALL, tool: 'nope' });+ if (r.ok) throw new Error('应失败');+ expect(r.message).toContain('gen_image');+ });++ it('TOOL_NOT_FOUND 自愈文案:二级分派插件回填 call_tool 正确形态', async () => {+ const base = fakeGhost();+ const dispatchGhost = fakeGhost({+ manifest: {+ ...base.manifest,+ tools: [+ { name: 'list_tools', description: '列操作' },+ { name: 'call_tool', description: '分派' },+ ],+ },+ });+ const h = makeHarness({ ghost: dispatchGhost });+ const r = await h.dispatcher.callGhostTool({ ...CALL, tool: 'create_pull_request_review' });+ if (r.ok) throw new Error('应失败');+ expect(r.errorCode).toBe('TOOL_NOT_FOUND');+ expect(r.message).toContain('call_tool');+ expect(r.message).toContain('create_pull_request_review');+ });+it('熔断中 → GHOST_CRASHED,不尝试拉起', async () => {const h = makeHarness({ state: 'fused' });const r = await h.dispatcher.callGhostTool(CALL);@@ -90,6 +116,31 @@ describe('资格审(结构化错误分类)', () => {});});+describe('toolNotFoundMessage(纯函数直测)', () => {+ it('分派型插件:回填 agent 想调的名字并给出 call_tool 形态', () => {+ const msg = toolNotFoundMessage('cindy-github', 'create_pull_request', [+ { name: 'list_tools', description: '' },+ { name: 'call_tool', description: '' },+ ]);+ expect(msg).toContain('cindy-github');+ expect(msg).toContain('create_pull_request');+ expect(msg).toContain('tool:"call_tool"');+ expect(msg).toContain('name:"create_pull_request"');+ expect(msg).toContain('list_tools');+ });++ it('普通插件:列出可用工具名', () => {+ const msg = toolNotFoundMessage('art', 'nope', [{ name: 'gen_image', description: '' }]);+ expect(msg).toContain('gen_image');+ expect(msg).not.toContain('call_tool');+ });++ it('tools 缺省/空:不崩,提示未声明任何工具', () => {+ expect(toolNotFoundMessage('art', 'nope', undefined)).toContain('(未声明任何工具)');+ expect(toolNotFoundMessage('art', 'nope', [])).toContain('(未声明任何工具)');+ });+});+describe('按需拉起', () => {it('off 状态先 spawn 再派发', async () => {const h = makeHarness({ state: 'off' });diff --git a/apps/desktop/src/main/cindy-brain/pipeDispatcher.ts b/apps/desktop/src/main/cindy-brain/pipeDispatcher.tsindex a92d807333..436e33a7ac 100644--- a/apps/desktop/src/main/cindy-brain/pipeDispatcher.ts+++ b/apps/desktop/src/main/cindy-brain/pipeDispatcher.ts@@ -23,6 +23,7 @@ import { randomUUID } from 'node:crypto';import type {GhostPipeToolCall,GhostToolCallResult,+ GhostToolDecl,InstalledGhost,} from '../../shared/ghost.js';import { GHOST_PIPE_CALL_MAX_TOTAL_MS, isGhostPluginErrorCode } from '../../shared/ghost.js';@@ -74,6 +75,32 @@ const DEFAULT_TIMEOUT_MS = 330_000;/** 代办收工(release)后留给意识做后处理与交卷的余量窗口。 */const HOLD_SETTLE_GRACE_MS = 60_000;+/**+ * TOOL_NOT_FOUND 自愈文案。只报"没有什么"会让 agent 拿同一错误形态反复重试,+ * 甚至误判"插件没有写能力"(2026-07-30 实测:二级分派型插件 cindy-github 的+ * 操作名被两个模型先后当作顶层 tool 直调,均在此卡死)。+ * 分派型插件(暴露了 call_tool)把 agent 想调的名字直接回填进正确调用形态;+ * 普通插件列出实际可用的顶层工具名。+ * 消费方:本派发器 + ghost_call 主路径预检(mcp-integrations/ghost.ts)++ * setup 恢复校验(maker-ipc/register.ts validateTarget)——所有 TOOL_NOT_FOUND+ * 返回点必须共用本函数,新增返回点不得自写文案。导出供单测直测(规则 14)。+ */+export function toolNotFoundMessage(+ ghostId: string,+ tool: string,+ declaredTools: GhostToolDecl[] | undefined,+): string {+ const names = (declaredTools ?? []).map((t) => t.name);+ if (names.includes('call_tool')) {+ return (+ `插件 ${ghostId} 没有名为 ${tool} 的顶层工具——它采用二级分派:具体操作经 call_tool 下发,` ++ `正确形态 ghost_call({ghost_id:"${ghostId}",tool:"call_tool",args:{name:"${tool}",args:{...}}});` ++ `操作名与参数先调 list_tools 查询。不要据此判定插件缺少该能力。`+ );+ }+ return `插件 ${ghostId} 没有工具 ${tool};可用工具: ${names.length > 0 ? names.join(', ') : '(未声明任何工具)'}`;+}+export class GhostPipeDispatcher {private readonly pending = new Map<string, PendingCall>();@@ -110,7 +137,7 @@ export class GhostPipeDispatcher {}const declared = ghost.manifest.tools?.some((t) => t.name === tool);if (!declared) {- return { ok: false, errorCode: 'TOOL_NOT_FOUND', message: `插件 ${ghostId} 没有工具 ${tool}` };+ return { ok: false, errorCode: 'TOOL_NOT_FOUND', message: toolNotFoundMessage(ghostId, tool, ghost.manifest.tools) };}if (this.deps.runtimeStateOf(ghostId) === 'fused') {return { ok: false, errorCode: 'GHOST_CRASHED', message: `插件 ${ghostId} 已熔断(反复崩溃),重载或重新启用后再试` };diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 003b378a6e..97eb9864c0 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -61,6 +61,7 @@ import {type GhostSetupInteractionSnapshot,} from '../cindy-brain/ghostSetupInteractionBridge.js';import { initGhostSetupCoordinator } from '../cindy-brain/ghostSetupCoordinator.js';+import { toolNotFoundMessage } from '../cindy-brain/pipeDispatcher.js';import { getGhostSetupChangeBus } from '../cindy-brain/ghostSetupChangeBus.js';import { isGhostDisabledForWorkdir } from '../cindy-brain/ghostWorkdirPrefs.js';import {@@ -1386,7 +1387,7 @@ initGhostSetupCoordinator({return {ok: false,errorCode: 'TOOL_NOT_FOUND',- message: `${t('newChat.pluginSetup.targetToolNotFound')} (${tool})`,+ message: toolNotFoundMessage(ghostId, tool, ghost.manifest.tools),};}return { ok: true };diff --git a/apps/desktop/src/main/mcp-integrations/ghost.ts b/apps/desktop/src/main/mcp-integrations/ghost.tsindex 1fe0f0bd99..e4ec837b23 100644--- a/apps/desktop/src/main/mcp-integrations/ghost.ts+++ b/apps/desktop/src/main/mcp-integrations/ghost.ts@@ -47,6 +47,7 @@ import {type GhostGrantLane,} from '../cindy-brain/ghostGrantConfirmBridge.js';import { classifyLocalAttachmentPath } from '../cindy-brain/ghostLocalPathGrant.js';+import { toolNotFoundMessage } from '../cindy-brain/pipeDispatcher.js';import { getSessionFsSnapshot } from '../localDb/ipc/sessions.js';import { deriveGhostSessionContext, type GhostSessionContextInjected } from '../../shared/ghost.js';import { withCardToken } from '../cindy-brain/cardService.js';@@ -659,7 +660,7 @@ export function getCindyGhostsMcpDeps(sessionCtx?: LiziMcpSessionContext): Cindyreturn {ok: false,errorCode: 'TOOL_NOT_FOUND',- message: `目标插件没有工具 ${tool}`,+ message: toolNotFoundMessage(ghostId, tool, target.manifest.tools),};}if (grantOnly && (!attachments || attachments.length === 0)) {@@ -708,7 +709,7 @@ export function getCindyGhostsMcpDeps(sessionCtx?: LiziMcpSessionContext): Cindy!grantOnly &&!(refreshed.manifest.tools ?? []).some((candidate) => candidate.name === tool)) {- return { ok: false, errorCode: 'TOOL_NOT_FOUND', message: `${t('newChat.pluginSetup.targetToolNotFound')} (${tool})` };+ return { ok: false, errorCode: 'TOOL_NOT_FOUND', message: toolNotFoundMessage(ghostId, tool, refreshed.manifest.tools) };}let finalAssessment;try {@@ -884,7 +885,7 @@ export function getCindyGhostsMcpDeps(sessionCtx?: LiziMcpSessionContext): Cindy};}if (!(preDispatch.manifest.tools ?? []).some((c) => c.name === tool)) {- return { ok: false, errorCode: 'TOOL_NOT_FOUND', message: `${t('newChat.pluginSetup.targetToolNotFound')} (${tool})` };+ return { ok: false, errorCode: 'TOOL_NOT_FOUND', message: toolNotFoundMessage(ghostId, tool, preDispatch.manifest.tools) };}try {const preDispatchAssessment = getGhostSetupAssessment(ghostId);@@ -923,7 +924,7 @@ export function getCindyGhostsMcpDeps(sessionCtx?: LiziMcpSessionContext): Cindyreturn { ok: false, errorCode: 'GHOST_DISABLED_IN_WORKDIR', message: t('newChat.pluginSetup.targetDisabledInWorkdir') };}if (!(postCtx.manifest.tools ?? []).some((c) => c.name === tool)) {- return { ok: false, errorCode: 'TOOL_NOT_FOUND', message: `${t('newChat.pluginSetup.targetToolNotFound')} (${tool})` };+ return { ok: false, errorCode: 'TOOL_NOT_FOUND', message: toolNotFoundMessage(ghostId, tool, postCtx.manifest.tools) };}try {const postCtxAssessment = getGhostSetupAssessment(ghostId);diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex a48b62614f..5b58999931 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -4287,8 +4287,7 @@"inlineSecretStoreFailed": "Failed to save credential","targetNotFound": "The target plugin was uninstalled or is currently unavailable","targetDisabled": "The target plugin has been disabled",- "targetDisabledInWorkdir": "The user has disabled this plugin in the current working directory; do not retry.",- "targetToolNotFound": "The target plugin no longer provides this tool"+ "targetDisabledInWorkdir": "The user has disabled this plugin in the current working directory; do not retry."},"createAgent": {"quickStart": "Quick start",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex d91f1b720a..113a1ff1e1 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -4286,8 +4286,7 @@"inlineSecretStoreFailed": "認証情報の保存に失敗しました","targetNotFound": "対象プラグインがアンインストールされたか現在利用不可です","targetDisabled": "対象プラグインが無効化されています",- "targetDisabledInWorkdir": "ユーザーが現在のワーキングディレクトリでこのプラグインを無効にしています。リトライしないでください。",- "targetToolNotFound": "対象プラグインはこのツールを提供していません"+ "targetDisabledInWorkdir": "ユーザーが現在のワーキングディレクトリでこのプラグインを無効にしています。リトライしないでください。"},"createAgent": {"quickStart": "クイックスタート",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex f22523ae0f..f37c24d47f 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -4286,8 +4286,7 @@"inlineSecretStoreFailed": "자격 증명 저장에 실패했습니다","targetNotFound": "대상 플러그인이 제거되었거나 현재 사용할 수 없습니다","targetDisabled": "대상 플러그인이 비활성화되었습니다",- "targetDisabledInWorkdir": "사용자가 현재 작업 디렉토리에서 이 플러그인을 비활성화했습니다. 재시도하지 마세요.",- "targetToolNotFound": "대상 플러그인이 더 이상 이 도구를 제공하지 않습니다"+ "targetDisabledInWorkdir": "사용자가 현재 작업 디렉토리에서 이 플러그인을 비활성화했습니다. 재시도하지 마세요."},"createAgent": {"quickStart": "빠른 시작",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex c22a115e3c..ae53dad81c 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -4286,8 +4286,7 @@"inlineSecretStoreFailed": "凭证保存失败","targetNotFound": "目标插件已卸载或当前不可用","targetDisabled": "目标插件已被停用",- "targetDisabledInWorkdir": "用户已在当前工作目录停用该插件;不要重试。",- "targetToolNotFound": "目标插件不再提供该工具"+ "targetDisabledInWorkdir": "用户已在当前工作目录停用该插件;不要重试。"},"createAgent": {"quickStart": "快速开始",diff --git a/packages/cindy-tools/src/ghost/mcpServer.ts b/packages/cindy-tools/src/ghost/mcpServer.tsindex f166347d35..0ab1f3d68d 100644--- a/packages/cindy-tools/src/ghost/mcpServer.ts+++ b/packages/cindy-tools/src/ghost/mcpServer.ts@@ -32,12 +32,18 @@ const D_GHOST_LIST = ["(例外:用户消息的[插件指令]已附带目标插件的工具清单时,可直接 ghost_call 免查)。","返回条目含 id、name、command(用户显式点名用的 $指令)与 tools(名称/说明/参数)。","调用具体工具用 ghost_call({ghost_id, tool, args})。清单为空 = 用户没有可用的插件工具。",+ "若某插件 tools 仅含 list_tools / call_tool,它是二级分派型:具体操作名须作 call_tool 的",+ "name 参数下发(args:{name:\"<操作名>\", args:{...}}),不能直接当 tool 调。",].join("\n");const D_GHOST_CALL = ["调用某个插件(Ghost)提供的工具。ghost_id 与 tool 来自 ghost_list 的返回,","或用户消息[插件指令]附带的工具清单;","args 按该工具声明的参数 schema 传 JSON 对象。",+ "部分插件(如 cindy-github / cindy-gitlab)采用二级分派:ghost_list 只暴露 list_tools 与",+ "call_tool 两个工具,具体操作(如 create_pull_request_review)不是顶层 tool,必须经 call_tool",+ '下发——ghost_call({ghost_id, tool:"call_tool", args:{name:"<操作名>", args:{...}}});',+ "把操作名当 tool 直接调会返回 TOOL_NOT_FOUND,此时按上述形态改写重试,不要判定插件无此能力。","执行发生在该插件的独立沙箱中(无文件/网络访问,用 AI 走主机统一通道)。","用户的图片/媒体文件要交给插件处理时,把其地址放进顶层 attachments","(不是塞进 args):主机会把图过户给该插件并以指纹注入 args.attachments,插件",@@ -54,7 +60,8 @@ const D_GHOST_CALL = ["——用户只需在一张卡上批一次;跳过预授权会让用户被迫一张张点允许。","结构化错误:GHOST_NOT_FOUND(未安装或已卸载)/ GHOST_ASLEEP(未启用,可提示用户到主界面侧边栏「插件」中启用)/","GHOST_DISABLED_IN_WORKDIR(用户在当前工作目录停用了该插件——不要重试,改用其它方式完成)/",- "TOOL_NOT_FOUND / GHOST_CRASHED / TIMEOUT / ATTACHMENT_INVALID(附件过户失败,查 message)/",+ "TOOL_NOT_FOUND(常见是把二级分派操作名当成了顶层 tool,按上文 call_tool 形态改写后重试)/ GHOST_CRASHED /",+ "TIMEOUT / ATTACHMENT_INVALID(附件过户失败,查 message)/","DIR_INVALID(目录过户失败,查 message)/ INTERNAL。遇到 NOT_FOUND 类错误先重新 ghost_list。",].join("\n");