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): 未映射内置工具在有归类前必须用户确认
Chris3f74866f002f
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/auto-review-policy.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/auto-review-policy.test.tsindex 9e5c41e228..89e5976caf 100644--- a/packages/maker-core/src/agents/claude-code/__tests__/auto-review-policy.test.ts+++ b/packages/maker-core/src/agents/claude-code/__tests__/auto-review-policy.test.ts@@ -259,9 +259,14 @@ describe('classifyBuiltinToolForAutoReview — 外发与未知', () => {expect(verdict('WebFetch', { url: 'https://x' })).toBe('prompt');expect(verdict('WebSearch', { query: 'x' })).toBe('prompt');});- it('未知工具 → prompt(fail-closed)', () => {- expect(verdict('SomeFutureTool', { anything: 1 })).toBe('prompt');- expect(verdict('mcp__srv__tool', {})).toBe('prompt'); // 理论上不会传 MCP 进来,兜底也 fail-closed+ it('未知工具 → prompt-each-time(没有入参映射就不能 allow)', () => {+ // 形状+指纹进 description,但审阅器仍分不清工作区/系统路径。未映射内置工具在有+ // 显式归类之前必须用户确认,不能交给灰区 reviewer 静默 allow(codex 报)。+ expect(verdict('SomeFutureTool', { anything: 1 })).toBe('prompt-each-time');+ expect(verdict('SomeFutureTool', { path: '/etc/passwd' })).toBe('prompt-each-time');+ expect(verdict('SomeFutureTool', { path: '/repo/a.ts' })).toBe('prompt-each-time');+ expect(verdict('SomeFutureTool', {})).toBe('prompt-each-time');+ expect(verdict('mcp__srv__tool', {})).toBe('prompt-each-time');});});@@ -477,6 +482,8 @@ describe('工具映射漏项不得变成静默拒绝', () => {expect(action.kind === 'other' && action.description?.trim()).toBeTruthy();// 描述里带工具名,便于审阅器判断这类动作。expect(action.kind === 'other' && action.description).toContain('SomeFutureTool');+ // 未映射内置工具必须用户确认:形状进 description 不等于审阅器可以 allow。+ expect(action.kind === 'other' && action.requireConsent).toBe(true);});it('兜底 description 不得泄漏入参内容', () => {diff --git a/packages/maker-core/src/agents/claude-code/auto-review-policy.ts b/packages/maker-core/src/agents/claude-code/auto-review-policy.tsindex 039b6a0c51..f1b35cc19b 100644--- a/packages/maker-core/src/agents/claude-code/auto-review-policy.ts+++ b/packages/maker-core/src/agents/claude-code/auto-review-policy.ts@@ -272,7 +272,13 @@ export function normalizeBuiltinToolForAutoReview(// (shared/auto-review-decision.ts)被判为「证据不足」→ 在调模型**之前**直接// block。那不是「fail-closed 升级」而是静默拒绝:用户既看不到卡也没有理由,// 而 SDK 每加一个内置工具就会复发一次(实测 PowerShell 已中)。- return { kind: 'other', description: describeUnknownTool(toolName, input) };+ return {+ kind: 'other',+ description: describeUnknownTool(toolName, input),+ // 形状+指纹能分缓存桶,但不能让审阅器区分工作区/系统路径或测试/生产目标。+ // 未映射工具在有显式归类之前必须用户确认,不能 allow(codex 报)。+ requireConsent: true,+ };}/**@@ -286,8 +292,8 @@ export function normalizeBuiltinToolForAutoReview(* 于是「先一次无害调用拿到 allow、后续任意参数复用该 allow」(codex 报)。* 带上入参指纹让不同参数各自成键。*- * 指纹用长度 + 字符和,不可逆(拿不回原文)但对内容变化敏感 —— 目的只是分桶,- * 不是密码学承诺。真正的安全判断由审阅器基于键名与形状做。+ * 形状与指纹**不是**安全证据:审阅器看不见路径是工作区还是系统目录。未映射+ * 工具另标 `requireConsent`,确定性必问,不把 allow 交给审阅器。*/function describeUnknownTool(toolName: string, input: unknown): string {const shape = describeInputShape(input);diff --git a/packages/maker-core/src/agents/shared/auto-review-decision.test.ts b/packages/maker-core/src/agents/shared/auto-review-decision.test.tsindex d2482a46fe..38ab8791ec 100644--- a/packages/maker-core/src/agents/shared/auto-review-decision.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review-decision.test.ts@@ -40,6 +40,11 @@ function request(action: AutoReviewRequest['action']): AutoReviewRequest {describe('resolveAutoReviewDecision', () => {it('names the legacy prompt result as an internal needs-review tier, not a UI prompt', () => {expect(classifyLocalAutoReviewTier(request({ kind: 'other' }))).toBe('needs-review');+ expect(classifyLocalAutoReviewTier(request({+ kind: 'other',+ description: 'unmapped built-in',+ requireConsent: true,+ }))).toBe('prompt-each-time');expect(classifyLocalAutoReviewTier(request({ kind: 'read' }))).toBe('auto-approve');});@@ -109,6 +114,16 @@ describe('resolveAutoReviewDecision', () => {expect(delegate).toHaveBeenCalledOnce();});+ it('does not let the reviewer allow unmapped tools that require consent', async () => {+ const delegate = vi.fn(async () => ({ verdict: 'allow' as const }));+ await expect(resolveAutoReviewDecision(request({+ kind: 'other',+ description: 'unmapped built-in with path-shaped args',+ requireConsent: true,+ }), delegate)).resolves.toEqual({ verdict: 'ask' });+ expect(delegate).not.toHaveBeenCalled();+ });+it.each([{ kind: 'file-write', path: undefined } as const,{ kind: 'exec', command: ' ' } as const,diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex 853f5cc4dd..6f3cc24783 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -24,8 +24,11 @@ describe('reviewAction — 非 shell 动作', () => {it('network → prompt(exfil 面)', () => {expect(reviewAction({ kind: 'network' }, roots)).toBe('prompt');});- it('other / 未知 → prompt(fail-closed)', () => {+ it('other / 未知 → prompt;标了 requireConsent 则每次必问', () => {expect(reviewAction({ kind: 'other' }, roots)).toBe('prompt');+ expect(reviewAction({ kind: 'other', description: 'mcp tool' }, roots)).toBe('prompt');+ expect(reviewAction({ kind: 'other', description: 'unmapped', requireConsent: true }, roots))+ .toBe('prompt-each-time');});});diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 86714cc579..71e6138d61 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -63,7 +63,7 @@ export type ReviewableAction =// 必须按未知处理:相对破坏目标不可证明在区内(copidot 报 `params.cwd || workingDir` 把空串当区内)。| { kind: 'exec'; command: string; cwd?: string; cwdUnknown?: boolean }| { kind: 'network'; target?: string; operation?: string }- | { kind: 'other'; description?: string };+ | { kind: 'other'; description?: string; requireConsent?: boolean };/*** 核心裁决。纯函数、确定性、无副作用(不触文件系统 —— 探文件存在性会变侧信道,且对远端@@ -132,6 +132,10 @@ export function reviewAction(if (action.target && isInternalFetchTarget(action.target)) return 'prompt-each-time';return 'prompt';case 'other':+ // 未映射内置工具的安全性取决于入参(路径/收件人/部署目标),而 description 只带形状和+ // 指纹、看不到值 —— 审阅器 allow 等于主动断言安全(codex 报)。`requireConsent` 把它+ // 留在用户确认,不交灰区。Pi MCP 等已有完整证据的 other 不加这个标记,仍走审阅器。+ return action.requireConsent ? 'prompt-each-time' : 'prompt';default:return 'prompt';}