Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auto-review): 第一方 Art 作图不再弹手动授权 (#4221)
Chris Zhangbb99c5cc9d9d
diff --git a/apps/desktop/src/main/maker-host/__tests__/mcpToolApprovalPolicy.test.ts b/apps/desktop/src/main/maker-host/__tests__/mcpToolApprovalPolicy.test.tsindex 16ef943886..ad4e18a141 100644--- a/apps/desktop/src/main/maker-host/__tests__/mcpToolApprovalPolicy.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/mcpToolApprovalPolicy.test.ts@@ -358,6 +358,61 @@ describe('desktop MCP approval policy', () => {);});+ it('auto-approves first-party Cindy Art media ghost_call tools without prompting', () => {+ for (const tool of ['gen_image', 'edit_image', 'gen_video', 'edit_video']) {+ expect(+ getDesktopMcpToolApprovalPolicy({+ serverName: 'cindy',+ toolName: 'ghost_call',+ toolParams: { ghost_id: 'cindy-art', tool, args: { prompt: 'a cat' } },+ }),+ `${tool} should be auto-approved`,+ ).toBe('auto-approve');+ }++ // Codex elicitation 可能省略外层 toolName,仍按内层 ghost_id / tool 判定。+ expect(+ getDesktopMcpToolApprovalPolicy({+ serverName: 'cindy',+ toolParams: { ghost_id: 'cindy-art', tool: 'gen_image', args: { prompt: 'a cat' } },+ }),+ ).toBe('auto-approve');+ expect(+ getDesktopMcpToolApprovalPolicy({+ serverName: 'cindy',+ toolName: 'ghost_call',+ toolParams: JSON.stringify({+ ghost_id: 'cindy-art',+ tool: 'gen_image',+ args: { prompt: 'a cat' },+ }),+ }),+ ).toBe('auto-approve');++ // 其它插件、未知工具、缺内层身份仍 fail closed。+ expect(+ getDesktopMcpToolApprovalPolicy({+ serverName: 'cindy',+ toolName: 'ghost_call',+ toolParams: { ghost_id: 'google-gmail', tool: 'gmail', args: { action: 'send' } },+ }),+ ).toBe('prompt');+ expect(+ getDesktopMcpToolApprovalPolicy({+ serverName: 'cindy',+ toolName: 'ghost_call',+ toolParams: { ghost_id: 'cindy-art', tool: 'unknown_tool' },+ }),+ ).toBe('prompt');+ expect(+ getDesktopMcpToolApprovalPolicy({+ serverName: 'cindy',+ toolName: 'ghost_call',+ toolParams: { tool: 'gen_image' },+ }),+ ).toBe('prompt');+ });+it('auto-approves the browser call_tool entry that Claude used to prompt for every time', () => {// 回归锚点: cindy_browser 的真实动作全部走 call_tool。Claude 侧过去只静态放行// list_tools, 于是每次 navigate / snapshot / click 都弹一次窗。diff --git a/apps/desktop/src/main/maker-host/mcp-tool-approval-policy.ts b/apps/desktop/src/main/maker-host/mcp-tool-approval-policy.tsindex a946bdfd29..b08d2016f8 100644--- a/apps/desktop/src/main/maker-host/mcp-tool-approval-policy.ts+++ b/apps/desktop/src/main/maker-host/mcp-tool-approval-policy.ts@@ -13,8 +13,9 @@* 判定顺序(从最窄到最宽):* 1. READ_ONLY_MCP_TOOLS —— 精确到工具的只读发现入口,server 未整体可信也放行* 2. cindy_contacts —— 按内层 action 细粒度判定(见 contacts/approval.ts)- * 3. TRUSTED_MCP_SERVERS —— 已 review 的第一方 server,整体静默- * 4. 其余 —— 逐次弹窗(第三方 server、cindy_ssh、插件 ghost_call…)+ * 3. cindy-art ghost_call —— 第一方作图/视频内层工具静默;其它插件仍逐次确认+ * 4. TRUSTED_MCP_SERVERS —— 已 review 的第一方 server,整体静默+ * 5. 其余 —— 逐次弹窗(第三方 server、cindy_ssh、其它 ghost_call…)*/import type {@@ -173,6 +174,29 @@ function skipsRoutelessDeviceApproval(args: unknown): boolean {return !hasIOSSimulatorInstanceRoute(parsed);}+/** 第一方 Cindy Art 的媒体生成工具。风险是额度而非越权,用户点名作图即授权。 */+const CINDY_ART_MEDIA_TOOLS: ReadonlySet<string> = new Set([+ 'gen_image',+ 'edit_image',+ 'gen_video',+ 'edit_video',+]);++/**+ * ghost_call 是聚合入口,默认逐次确认。Cindy Art 的作图/改图/视频是第一方媒体+ * 能力,用户发「画一张」即构成授权;Auto-review 下再弹卡会把常规作图变成手动授权。+ * 读不出 ghost_id / tool 时 fail closed,其它插件不受影响。+ */+function canAutoApproveCindyArtGhostCall(context: McpToolApprovalContext): boolean {+ if (context.serverName !== 'cindy') return false;+ if (context.toolName !== 'ghost_call' && context.toolName !== undefined) return false;+ const params = readJsonObject(context.toolParams);+ if (!params) return false;+ const ghostId = typeof params.ghost_id === 'string' ? params.ghost_id.trim() : '';+ const tool = typeof params.tool === 'string' ? params.tool.trim() : '';+ return ghostId === 'cindy-art' && CINDY_ART_MEDIA_TOOLS.has(tool);+}+/** Claude SDK 工具名格式固定为 `mcp__<server>__<tool>`。 */function toClaudeToolName(key: string): string {const [serverName, toolName] = key.split('::');@@ -203,6 +227,9 @@ export function getDesktopMcpToolApprovalPolicy(? 'auto-approve': 'prompt-each-time';}+ if (canAutoApproveCindyArtGhostCall(context)) {+ return 'auto-approve';+ }const iosSimulatorCall = readIOSSimulatorInnerCall(context);if (iosSimulatorCall) {const innerName = iosSimulatorCall.name;