Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): gate find_bot_capabilities plugin sentence on cindy
zqchrisefee08fa2780
diff --git a/packages/lizi-mcps/src/__tests__/botCapabilitiesTool.test.ts b/packages/lizi-mcps/src/__tests__/botCapabilitiesTool.test.tsindex bbe1b41cd2..9c2bcd8bc2 100644--- a/packages/lizi-mcps/src/__tests__/botCapabilitiesTool.test.ts+++ b/packages/lizi-mcps/src/__tests__/botCapabilitiesTool.test.ts@@ -1,6 +1,10 @@import { describe, expect, it, vi } from 'vitest';import { XdtHelperToolRegistry } from '../lizi_xdtHelperToolRegistry.js';-import { registerBotCapabilityTools } from '../xdt-helper/bot_capabilities.js';+import {+ buildFindBotCapabilitiesDescription,+ registerBotCapabilityTools,+ withCindyGatedBotToolDescriptions,+} from '../xdt-helper/bot_capabilities.js';function fixture(sessionId: string | undefined = 'current-bot') {const registry = new XdtHelperToolRegistry();@@ -39,4 +43,42 @@ describe('Bot capability tools', () => {expect(callbacks.list).not.toHaveBeenCalled();expect(callbacks.select).not.toHaveBeenCalled();});++ it('keeps plugin discovery in the default find_bot_capabilities description', () => {+ const description = buildFindBotCapabilitiesDescription();+ expect(description).toContain('ghost_list');+ expect(description).toContain('ghost_info');+ expect(buildFindBotCapabilitiesDescription(true)).toBe(description);+ const { registry } = fixture();+ expect(registry.list('bots').find((tool) => tool.name === 'find_bot_capabilities')?.description).toBe(description);+ });++ it('omits ghost tools when cindy is unavailable', () => {+ const description = buildFindBotCapabilitiesDescription(false);+ expect(description).toContain('Skill');+ expect(description).not.toMatch(/ghost_list|ghost_info|ghost_call/);+ const registry = new XdtHelperToolRegistry();+ registerBotCapabilityTools(registry, {+ getSessionContext: () => ({ sessionId: 'current-bot', agentKind: 'codex', workingDir: '/w' }),+ callbacks: {+ list: vi.fn(async () => ({ ok: true as const, capabilities: [] })),+ select: vi.fn(async () => ({ ok: true as const, effective: 'next-turn' as const, joined: true })),+ },+ cindyAvailable: false,+ });+ expect(registry.list('bots').find((tool) => tool.name === 'find_bot_capabilities')?.description).toBe(description);+ expect(registry.list('bots').find((tool) => tool.name === 'set_bot_capability')?.description).not.toMatch(/ghost_list|ghost_info|ghost_call/);+ });++ it('rewrites only find_bot_capabilities at list time', () => {+ const tools = [+ { name: 'find_bot_capabilities', description: buildFindBotCapabilitiesDescription() },+ { name: 'set_bot_capability', description: 'join or leave' },+ ];+ expect(withCindyGatedBotToolDescriptions(tools, true)).toEqual(tools);+ const remote = withCindyGatedBotToolDescriptions(tools, false);+ expect(remote[0]?.description).toBe(buildFindBotCapabilitiesDescription(false));+ expect(remote[0]?.description).not.toMatch(/ghost_list|ghost_info|ghost_call/);+ expect(remote[1]?.description).toBe('join or leave');+ });});diff --git a/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts b/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.tsindex d93ee4525f..f9d1612c31 100644--- a/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts+++ b/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts@@ -633,6 +633,84 @@ describe("cindy_helper MCP server", () => {});describe("direct Bot MCP tools", () => {+ it.each(["claude-code", "codex"] as const)("omits ghost plugin guidance from find_bot_capabilities on remote %s", async (agentKind) => {+ let remoteHostId: string | undefined;+ const server = createXdtHelperMcpServer({+ resolveSurface: async () => "bot",+ botCapabilities: {+ list: vi.fn(async () => ({ ok: true as const, capabilities: [] })),+ select: vi.fn(async () => ({ ok: true as const, effective: "next-turn" as const, joined: true })),+ },+ }, {+ agentKind,+ workingDir: "",+ getSessionContext: () => ({+ agentKind,+ workingDir: "/bot",+ sessionId: "bot-parent",+ ...(remoteHostId ? { remoteHostId } : {}),+ }),+ });+ const [ct, st] = InMemoryTransport.createLinkedPair();+ const client = new Client({ name: "remote-bot-capability-desc", version: "0.0.0" });+ await Promise.all([server.connect(st), client.connect(ct)]);+ try {+ const localTool = (await client.listTools()).tools.find((tool) => tool.name === "find_bot_capabilities");+ expect(localTool?.description).toContain("ghost_list");+ const localDiscovered = parsePayload(await client.callTool({+ name: "list_tools",+ arguments: { category: "bots" },+ })).tools as Array<{ name: string; description: string }>;+ expect(localDiscovered.find((tool) => tool.name === "find_bot_capabilities")?.description).toContain("ghost_list");++ remoteHostId = "ssh-host";+ const remoteTool = (await client.listTools()).tools.find((tool) => tool.name === "find_bot_capabilities");+ expect(remoteTool?.description).toContain("Skill");+ expect(remoteTool?.description).not.toMatch(/ghost_list|ghost_info|ghost_call/);+ const remoteDiscovered = parsePayload(await client.callTool({+ name: "list_tools",+ arguments: { category: "bots" },+ })).tools as Array<{ name: string; description: string }>;+ expect(remoteDiscovered.find((tool) => tool.name === "find_bot_capabilities")?.description).not.toMatch(+ /ghost_list|ghost_info|ghost_call/,+ );+ } finally {+ await client.close();+ await server.close();+ }+ });++ it("omits ghost plugin guidance from Pi helper discovery on remote sessions", async () => {+ const server = createXdtHelperMcpServer({+ resolveSurface: async () => "bot",+ botCapabilities: {+ list: vi.fn(async () => ({ ok: true as const, capabilities: [] })),+ select: vi.fn(async () => ({ ok: true as const, effective: "next-turn" as const, joined: true })),+ },+ }, {+ agentKind: "pi",+ workingDir: "/bot",+ sessionId: "bot-parent",+ remoteHostId: "ssh-host",+ });+ const [ct, st] = InMemoryTransport.createLinkedPair();+ const client = new Client({ name: "remote-pi-capability-desc", version: "0.0.0" });+ await Promise.all([server.connect(st), client.connect(ct)]);+ try {+ expect((await client.listTools()).tools.map((tool) => tool.name).sort()).toEqual(["call_tool", "list_tools"]);+ const discovered = parsePayload(await client.callTool({+ name: "list_tools",+ arguments: { category: "bots" },+ })).tools as Array<{ name: string; description: string }>;+ const find = discovered.find((tool) => tool.name === "find_bot_capabilities");+ expect(find?.description).toContain("Skill");+ expect(find?.description).not.toMatch(/ghost_list|ghost_info|ghost_call/);+ } finally {+ await client.close();+ await server.close();+ }+ });+it.each(["claude-code", "codex"] as const)("exposes and executes tasks on %s without discovery", async (agentKind) => {let sessionId: string | undefined = "bot-parent";const start = vi.fn(async () => ({ ok: true as const, taskId: "task-1" }));diff --git a/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts b/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.tsindex ed0770296a..cf10c9017f 100644--- a/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts+++ b/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts@@ -1,4 +1,3 @@-import { registerBotCapabilityTools, type BotCapabilityCallbacks } from './xdt-helper/bot_capabilities.js';/*** lizi_xdtHelperMcpServer.ts* ---------------------------------------------------------------------------@@ -63,6 +62,11 @@ import {registerBotSkillTools,type BotSkillCallbacks,} from './xdt-helper/bot_skills.js';+import {+ registerBotCapabilityTools,+ withCindyGatedBotToolDescriptions,+ type BotCapabilityCallbacks,+} from './xdt-helper/bot_capabilities.js';import type { XdtHelperHistoryDeps } from './xdt-helper/_history_types.js';import type { SessionQueueDeps } from './xdt-helper/list_session_queue.js';import type { SessionControlDeps } from './xdt-helper/session_control.js';@@ -157,10 +161,15 @@ interface BotMessagingCallbacks {// ── Entry tool registration ──────────────────────────────────────────────────+function cindyAvailableForSession(sessionCtx: XdtHelperMcpSessionCtx): boolean {+ return !resolveLiziMcpSessionContext(sessionCtx).remoteHostId;+}+function registerListToolsEntry(server: McpServer,registry: XdtHelperToolRegistry,allowedCategories: () => Promise<ReadonlySet<string> | null>,+ sessionCtx: XdtHelperMcpSessionCtx,): void {server.tool('list_tools',@@ -172,7 +181,10 @@ function registerListToolsEntry(if (allowed && !allowed.has(category)) {return errorPayload('CAPABILITY_NOT_AVAILABLE', '这个类目不属于当前任务的能力面。');}- const tools = registry.list(category as (typeof CATEGORY_ENUM)[number]);+ const tools = withCindyGatedBotToolDescriptions(+ registry.list(category as (typeof CATEGORY_ENUM)[number]),+ cindyAvailableForSession(sessionCtx),+ );return {content: [{@@ -707,7 +719,7 @@ export function createXdtHelperMcpServer(callbacks: deps.botProfiles,});}- registerListToolsEntry(server, registry, allowedCategories);+ registerListToolsEntry(server, registry, allowedCategories, sessionCtx);registerCallToolEntry(server, registry, {logger: deps.logger,// per-call 解析:codex HTTP bridge 的 server factory 阶段 ctx 是空的,@@ -745,8 +757,12 @@ export function createXdtHelperMcpServer(const botTools: Tool[] = directTools.map((definition) => ({name: definition.name, description: definition.description, inputSchema: schema(definition.inputShape),}));+ // Codex/remote Claude share one helper factory; rewrite ghost guidance from+ // the request-time session, not the empty factory ctx.server.server.setRequestHandler(ListToolsRequestSchema, async () => ({- tools: (await allowedCategories())?.has('bots') ? [...entryTools, ...botTools] : entryTools,+ tools: (await allowedCategories())?.has('bots')+ ? [...entryTools, ...withCindyGatedBotToolDescriptions(botTools, cindyAvailableForSession(sessionCtx))]+ : entryTools,}));}return server;diff --git a/packages/lizi-mcps/src/xdt-helper/bot_capabilities.ts b/packages/lizi-mcps/src/xdt-helper/bot_capabilities.tsindex c266c37eac..233ba4717d 100644--- a/packages/lizi-mcps/src/xdt-helper/bot_capabilities.ts+++ b/packages/lizi-mcps/src/xdt-helper/bot_capabilities.ts@@ -32,20 +32,48 @@ export interface BotCapabilityCallbacks {>;}+const FIND_BOT_CAPABILITIES_CORE =+ "按需查找 Cindy 已有的 Skill、MCP 连接或内置工具集,返回可用性和当前伙伴是否已加入。";+const FIND_BOT_CAPABILITIES_PLUGIN_SENTENCE =+ "插件用 cindy 的 ghost_list / ghost_info 发现并直接按现有授权调用。";++/**+ * Local Cindy sessions keep the plugin/`ghost_*` sentence byte-identical.+ * SSH Claude/Codex mount `cindy_helper` but not the `cindy` gateway, so that+ * sentence must be omitted or the model is told to call unreachable tools.+ */+export function buildFindBotCapabilitiesDescription(cindyAvailable = true): string {+ return cindyAvailable+ ? `${FIND_BOT_CAPABILITIES_CORE}${FIND_BOT_CAPABILITIES_PLUGIN_SENTENCE}`+ : FIND_BOT_CAPABILITIES_CORE;+}++export function withCindyGatedBotToolDescriptions<T extends { name: string; description?: string }>(+ tools: readonly T[],+ cindyAvailable: boolean,+): T[] {+ if (cindyAvailable) return [...tools];+ return tools.map((tool) =>+ tool.name === "find_bot_capabilities"+ ? { ...tool, description: buildFindBotCapabilitiesDescription(false) }+ : tool,+ );+}+/** Shared capability discovery keeps schemas out of the companion's initial context. */export function registerBotCapabilityTools(registry: XdtHelperToolRegistry,deps: {getSessionContext: () => LiziMcpSessionContext;callbacks: BotCapabilityCallbacks;+ cindyAvailable?: boolean;},): void {const kind = z.enum(["skill", "mcp", "toolset"]);registry.register({name: "find_bot_capabilities",category: "bots",- description:- "按需查找 Cindy 已有的 Skill、MCP 连接或内置工具集,返回可用性和当前伙伴是否已加入。插件用 cindy 的 ghost_list / ghost_info 发现并直接按现有授权调用。",+ description: buildFindBotCapabilitiesDescription(deps.cindyAvailable !== false),inputShape: { kind, query: z.string().max(200).optional() },handler: async (input) => {const callerSessionId = deps.getSessionContext().sessionId;diff --git a/packages/lizi-mcps/src/xdt-helper/index.ts b/packages/lizi-mcps/src/xdt-helper/index.tsindex 8b5ccd2cda..e10d578b70 100644--- a/packages/lizi-mcps/src/xdt-helper/index.ts+++ b/packages/lizi-mcps/src/xdt-helper/index.ts@@ -142,6 +142,12 @@ export {registerCreateTeammateTool,type CreateTeammateCallbacks,} from './create_teammate.js';+export {+ registerBotCapabilityTools,+ buildFindBotCapabilitiesDescription,+ withCindyGatedBotToolDescriptions,+ type BotCapabilityCallbacks,+} from './bot_capabilities.js';export {registerSubmitGithubIssueTool,type SubmitGithubIssueDeps,