Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(maker-core): Claude Auto 确认未送达时发出纠正提示
MagicLizi40917dc8fdd2
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.tsindex 8eea18aefb..29e5e74c54 100644--- a/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts+++ b/packages/maker-core/src/agents/claude-code/__tests__/auto-review-wiring.test.ts@@ -22,7 +22,11 @@ import type {McpToolApprovalContext,McpToolApprovalPolicy,} from '../../base-agent.js';-import type { AutoReviewRequest } from '../../shared/auto-review-decision.js';+import {+ AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE,+ AUTO_REVIEW_UNAVAILABLE_CODE,+ type AutoReviewRequest,+} from '../../shared/auto-review-decision.js';import type { PermissionMode } from '../../../types/common.js';import type { AuthAdapter } from '../../../interfaces/auth-adapter.js';import type { InteractionDecision, InteractionRequest } from '../../../types/events.js';@@ -584,9 +588,11 @@ describe('Auto-review wiring: reviewer outages surface once per session', () =>expect(second.behavior).toBe('deny');await settle();- // 两次都被拒,但只说一次 —— 逐条提示会把 Auto 退化成比 Ask 更烦的东西。- expect(notices).toHaveLength(1);- expect(notices[0]).toContain('[AUTO_REVIEW_UNAVAILABLE]');+ // 两次都被拒,但每种提示只说一次 —— 逐条提示会把 Auto 退化成比 Ask 更烦的东西。+ // 没有 resolver 时确认卡也送不出去,所以还会有一条未送达纠正,同样去重。+ expect(notices.filter((message) => message.includes('[AUTO_REVIEW_UNAVAILABLE]'))).toHaveLength(1);+ expect(notices.filter((message) => message.includes(`[${AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE}]`))).toHaveLength(1);+ expect(notices).toHaveLength(2);await handle.close();});@@ -603,6 +609,65 @@ describe('Auto-review wiring: reviewer outages surface once per session', () =>await handle.close();});+ it.each([+ 'timeout',+ 'hook_interaction_timeout',+ 'no_resolver_attached',+ 'resolver_threw',+ 'card send failed: slack timeout',+ ] as const)('does not treat a missing confirmation as a user rejection after auto-review fails (%s)', async (reason) => {+ const { handle, canUseTool } = await startSession('auto', {+ reviewer: async () => {+ throw new Error('reviewer offline');+ },+ attachResolver: false,+ });+ handle.setInteractionResolver(async () => ({+ kind: 'permission',+ behavior: 'deny',+ reason,+ }));+ const { notices } = startNoticeCollector(handle);++ const result = await canUseTool(+ 'Bash',+ { command: 'npx tsc --noEmit' },+ { toolUseID: `undelivered-${reason}` },+ );+ expect(result.behavior).toBe('deny');+ await settle();++ expect(notices.some((message) => message.includes(`[${AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE}]`))).toBe(true);+ expect(notices.some((message) => message.includes('not a user rejection'))).toBe(true);+ await handle.close();+ });++ it('keeps a real user deny distinct from a missing confirmation', async () => {+ const { handle, canUseTool } = await startSession('auto', {+ reviewer: async () => {+ throw new Error('reviewer offline');+ },+ attachResolver: false,+ });+ handle.setInteractionResolver(async () => ({+ kind: 'permission',+ behavior: 'deny',+ reason: 'User denied',+ }));+ const { notices } = startNoticeCollector(handle);++ const result = await canUseTool(+ 'Bash',+ { command: 'npx tsc --noEmit' },+ { toolUseID: 'user-deny' },+ );+ expect(result.behavior).toBe('deny');+ await settle();++ expect(notices.some((message) => message.includes(`[${AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE}]`))).toBe(false);+ await handle.close();+ });+/*** 裁决缓存的 key 不含 permissionMode。用户切离 Auto、等审阅器恢复、再切回 Auto 时,* 同一个动作会命中先前那条 `unavailable` block —— 审阅器早就好了,动作还是被拒@@ -652,12 +717,14 @@ describe('Auto-review wiring: reviewer outages surface once per session', () =>await canUseTool('Write', { file_path: '/tmp/t1.conf' }, { toolUseID: 'turn1-a' });await canUseTool('Write', { file_path: '/tmp/t2.conf' }, { toolUseID: 'turn1-b' });await settle();- expect(notices).toHaveLength(1); // 同一轮内两次被拒 → 仍只一条+ expect(notices.filter((message) => message.includes(`[${AUTO_REVIEW_UNAVAILABLE_CODE}]`))).toHaveLength(1);+ expect(notices.filter((message) => message.includes(`[${AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE}]`))).toHaveLength(1);await handle.send({ type: 'user', content: 'Try something else then.' });await canUseTool('Write', { file_path: '/tmp/t3.conf' }, { toolUseID: 'turn2-a' });await settle();- expect(notices).toHaveLength(2); // 新一轮 → 重新武装+ expect(notices.filter((message) => message.includes(`[${AUTO_REVIEW_UNAVAILABLE_CODE}]`))).toHaveLength(2);+ expect(notices.filter((message) => message.includes(`[${AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE}]`))).toHaveLength(2);await handle.close();});@@ -672,14 +739,16 @@ describe('Auto-review wiring: reviewer outages surface once per session', () =>await canUseTool('Write', { file_path: '/tmp/c.conf' }, { toolUseID: 'n4' });await settle();- expect(notices).toHaveLength(1);+ expect(notices.filter((message) => message.includes(`[${AUTO_REVIEW_UNAVAILABLE_CODE}]`))).toHaveLength(1);+ expect(notices.filter((message) => message.includes(`[${AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE}]`))).toHaveLength(1);// 用户自己动过档位之后又回到 Auto、又不可用 → 有权再看到一次。await handle.setPermissionMode?.('ask');await handle.setPermissionMode?.('auto');await canUseTool('Write', { file_path: '/tmp/d.conf' }, { toolUseID: 'n5' });await settle();- expect(notices).toHaveLength(2);+ expect(notices.filter((message) => message.includes(`[${AUTO_REVIEW_UNAVAILABLE_CODE}]`))).toHaveLength(2);+ expect(notices.filter((message) => message.includes(`[${AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE}]`))).toHaveLength(2);await handle.close();});});diff --git a/packages/maker-core/src/agents/claude-code/index.ts b/packages/maker-core/src/agents/claude-code/index.tsindex acebabe2ab..fca28c7415 100644--- a/packages/maker-core/src/agents/claude-code/index.ts+++ b/packages/maker-core/src/agents/claude-code/index.ts@@ -120,8 +120,10 @@ import {annotatePermissionRequestForUnavailableReview,composeAutoReviewIntentWithApprovedPlan,composeAutoReviewIntentWithClarification,+ createAutoReviewConfirmUndeliveredNotice,createAutoReviewUnavailableNotice,extractAutoReviewUserIntent,+ isSystemPermissionDenialReason,resolveAutoReviewDecision,type AutoReviewDecision,} from '../shared/auto-review-decision.js';@@ -1967,6 +1969,7 @@ export class ClaudeCodeAgent extends BaseAgent {: permissionRequest,{ forcePrompt },);+ notifyIfAutoReviewConfirmUndelivered(unavailableHandoff, decision);if (decision.kind !== 'permission') {log.warn('permission got mismatched decision', { tool: toolName, decKind: decision.kind });return { behavior: 'deny', message: 'resolver kind mismatch' };@@ -2107,16 +2110,33 @@ export class ClaudeCodeAgent extends BaseAgent {// 会让用户在后续轮次里完全看不到;改为每轮至多一条 —— 不刷屏,又保证每一轮遇到时// 都有机会看见。持久呈现需要一条真正的会话级 notice 通道,见 issue 外推。autoReviewUnavailableNotice.reset();+ autoReviewConfirmUndeliveredNotice.reset();};// 「自动审核不可用」的会话级一次性提示(issue #1574)。走既有的非终止 error 事件 +// `[CODE]` 约定,不新增事件类型;逐条提示会把 Auto 退化成比 Ask 更烦的东西,所以去重。- const autoReviewUnavailableNotice = createAutoReviewUnavailableNotice((message) => {+ const emitAutoReviewRuntimeNotice = (message: string): void => {eventQueue.push({type: 'error',data: { message, isTerminal: false },source: 'claude-code',});- });+ };+ const autoReviewUnavailableNotice = createAutoReviewUnavailableNotice(emitAutoReviewRuntimeNotice);+ const autoReviewConfirmUndeliveredNotice =+ createAutoReviewConfirmUndeliveredNotice(emitAutoReviewRuntimeNotice);+ const notifyIfAutoReviewConfirmUndelivered = (+ unavailableHandoff: boolean,+ decision: InteractionDecision,+ ): void => {+ if (!unavailableHandoff) return;+ if (decision.kind !== 'permission') {+ autoReviewConfirmUndeliveredNotice.notify();+ return;+ }+ if (decision.behavior === 'deny' && isSystemPermissionDenialReason(decision.reason)) {+ autoReviewConfirmUndeliveredNotice.notify();+ }+ };const reviewAutoAction = (action: ReviewableAction,workspaceRoots: string[],@@ -3005,12 +3025,19 @@ export class ClaudeCodeAgent extends BaseAgent {: this.normalizeSessionPermissionSuggestions(params.suggestions),metadata: params.metadata ?? {},};- const decision = await dispatchWithTimeout(- remoteUnavailableHandoff- ? annotatePermissionRequestForUnavailableReview(remotePermissionRequest)- : remotePermissionRequest,- { forcePrompt: remoteForcePrompt },- );+ let decision: InteractionDecision;+ try {+ decision = await dispatchWithTimeout(+ remoteUnavailableHandoff+ ? annotatePermissionRequestForUnavailableReview(remotePermissionRequest)+ : remotePermissionRequest,+ { forcePrompt: remoteForcePrompt },+ );+ } catch {+ if (remoteUnavailableHandoff) autoReviewConfirmUndeliveredNotice.notify();+ return { kind: 'permission', behavior: 'deny', reason: 'approval_timeout' };+ }+ notifyIfAutoReviewConfirmUndelivered(remoteUnavailableHandoff, decision);if (decision.kind !== 'permission') {return { kind: 'permission', behavior: 'deny', reason: 'resolver kind mismatch' };}@@ -5835,6 +5862,7 @@ export class ClaudeCodeAgent extends BaseAgent {// 换模型 / 换路由可能正好修掉了审阅器不可用的原因(目录解析失败、provider 被停用// 等);若换完又不可用,值得再提醒一次。autoReviewUnavailableNotice.reset();+ autoReviewConfirmUndeliveredNotice.reset();if (!isControlBlocked&& mutablePermissionMode === 'auto'@@ -5939,6 +5967,7 @@ export class ClaudeCodeAgent extends BaseAgent {if (newMode !== mutablePermissionMode) {autoReviewDecisionCache.clear();autoReviewUnavailableNotice.reset();+ autoReviewConfirmUndeliveredNotice.reset();}// 计划模式武装中 / 本轮 plan turn 进行中 SDK 恒在 plan 档: 只记录底层权限档// (循环收尾切回时生效), 不 push SDK、不动挂起交互(挂着的多半是 plan_review)。diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex d9bc49071f..5b247255ea 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -11795,6 +11795,7 @@ describe('CodexAgent MCP thread context hooks', () => {'timeout','hook_interaction_timeout','interaction_route_released',+ 'interaction_resolver_error','card send failed: slack timeout','pending failed: channel closed',] as const)('does not treat a missing confirmation as a user rejection after auto-review fails (%s)', async (reason) => {@@ -11844,6 +11845,50 @@ describe('CodexAgent MCP thread context hooks', () => {await handle.close();});+ it('does not treat a thrown confirmation resolver as a user rejection after auto-review fails', async () => {+ const reviewAutoPermissionAction = vi.fn<AutoReviewDelegate>(async () => null);+ const agent = new CodexAgent(createDeps({}, { reviewAutoPermissionAction }));+ const host = installFakeHost(agent);+ const handle = await agent.startSession({+ sessionId: 'session-auto-unavailable-resolver-throw',+ model: 'gpt-5.5',+ providerId: 'openai',+ workingDir: '/repo',+ permissionMode: 'auto',+ });+ const handlers = host.getThreadHandlers();+ if (!handlers?.commandExecutionApproval) throw new Error('expected commandExecutionApproval handler');+ handle.setInteractionResolver(async () => {+ throw new Error('session interaction listener crashed');+ });+ const notices: string[] = [];+ void (async () => {+ for await (const event of handle.events()) {+ if (+ event.type === 'error'+ && typeof event.data === 'object'+ && event.data !== null+ && 'message' in event.data+ && typeof event.data.message === 'string'+ ) {+ notices.push(event.data.message);+ }+ }+ })().catch(() => {});++ await expect(handlers.commandExecutionApproval({+ threadId: 'start-thread-id',+ turnId: 'turn-unavailable-resolver-throw',+ itemId: 'cmd-unavailable-resolver-throw',+ command: 'npx tsc --noEmit',+ cwd: '/repo',+ })).resolves.toEqual({ decision: 'decline' });+ await new Promise((resolve) => setTimeout(resolve, 20));++ expect(notices.some((message) => message.includes(`[${AUTO_REVIEW_CONFIRM_UNDELIVERED_CODE}]`))).toBe(true);+ await handle.close();+ });+it('keeps a real user deny distinct from a missing confirmation', async () => {const reviewAutoPermissionAction = vi.fn<AutoReviewDelegate>(async () => null);const agent = new CodexAgent(createDeps({}, { reviewAutoPermissionAction }));diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex bb7fbcc3ba..405c88b615 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -5666,6 +5666,7 @@ export class CodexAgent extends BaseAgent {}).catch((e) => {log.error('dispatchInteraction threw → decline', { requestId, message: (e as Error).message });+ if (unavailableHandoff) autoReviewConfirmUndeliveredNotice.notify();finalize('decline');});});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 69a19858c6..72f1dfb13c 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@@ -338,6 +338,9 @@ describe('isSystemPermissionDenialReason', () => {it('treats router and timeout codes as system denials, not user clicks', () => {expect(isSystemPermissionDenialReason('timeout')).toBe(true);expect(isSystemPermissionDenialReason('no_interaction_resolver')).toBe(true);+ expect(isSystemPermissionDenialReason('no_resolver_attached')).toBe(true);+ expect(isSystemPermissionDenialReason('resolver_threw')).toBe(true);+ expect(isSystemPermissionDenialReason('approval_timeout')).toBe(true);expect(isSystemPermissionDenialReason('stale_turn')).toBe(true);expect(isSystemPermissionDenialReason('hook_interaction_timeout')).toBe(true);expect(isSystemPermissionDenialReason('interaction_route_released')).toBe(true);diff --git a/packages/maker-core/src/agents/shared/auto-review-decision.ts b/packages/maker-core/src/agents/shared/auto-review-decision.tsindex 63021e4083..9c84e2eb6d 100644--- a/packages/maker-core/src/agents/shared/auto-review-decision.ts+++ b/packages/maker-core/src/agents/shared/auto-review-decision.ts@@ -134,9 +134,12 @@ export function createAutoReviewConfirmUndeliveredNotice(*/export const SYSTEM_PERMISSION_DENIAL_REASONS: ReadonlySet<string> = new Set(['no_interaction_resolver',+ 'no_resolver_attached','no_interaction_route','no_listener_attached','interaction_resolver_error',+ 'resolver_threw',+ 'approval_timeout','interaction_handler_failed','interaction_timeout','hook_interaction_timeout',