Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
Merge remote-tracking branch 'origin/main' into fix/auto-review-unavailable-user-confirm
MagicLizi67d560039ebf
diff --cc packages/maker-core/src/agents/codex/index.test.tsindex a8ee405243,70d3b492e1..55d73c9353--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@@ -11669,143 -11746,102 +11669,239 @@@ describe('CodexAgent MCP thread contexawait handle.close();});+ it('hands gray actions to the user when auto-review is unavailable, then accepts this action', 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-handoff',+ model: 'gpt-5.5',+ providerId: 'openai',+ workingDir: '/repo',+ permissionMode: 'auto',+ });+ const handlers = host.getThreadHandlers();+ if (!handlers?.commandExecutionApproval) throw new Error('expected commandExecutionApproval handler');+ const resolver = vi.fn(async (): Promise<InteractionDecision> => (+ { kind: 'permission', behavior: 'allow' }+ ));+ handle.setInteractionResolver(resolver);++ const result = await handlers.commandExecutionApproval({+ threadId: 'start-thread-id',+ turnId: 'turn-unavailable',+ itemId: 'cmd-unavailable',+ approvalId: 'approval-unavailable',+ command: 'npx tsc --noEmit',+ cwd: '/repo',+ });++ expect(result).toEqual({ decision: 'accept' });+ expect(reviewAutoPermissionAction).toHaveBeenCalledOnce();+ expect(resolver).toHaveBeenCalledOnce();+ const request = (resolver.mock.calls as unknown as Array<[InteractionRequest]>)[0]?.[0];+ expect(request).toMatchObject({+ kind: 'permission',+ description: AUTO_REVIEW_UNAVAILABLE_PROMPT_TEXT,+ metadata: { [AUTO_REVIEW_UNAVAILABLE_METADATA_KEY]: true },+ suggestions: undefined,+ });+ await handle.close();+ });++ it.each([+ 'timeout',+ 'hook_interaction_timeout',+ 'interaction_route_released',+ ] as const)('does not treat a missing confirmation as a user rejection after auto-review fails (%s)', async (reason) => {+ 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-undelivered-${reason}`,+ 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 () => ({+ kind: 'permission',+ behavior: 'deny',+ reason,+ }));+ 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-${reason}`,+ itemId: `cmd-unavailable-${reason}`,+ 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);+ 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 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-user-deny',+ 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 () => ({+ kind: 'permission',+ behavior: 'deny',+ reason: 'User denied',+ }));+ 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-user-deny',+ itemId: 'cmd-user-deny',+ 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(false);+ await handle.close();+ });++ it('asks the user when a file-change approval omits grantRoot', async () => {+ const reviewAutoPermissionAction = vi.fn<AutoReviewDelegate>(async () => ({+ verdict: 'block' as const,+ reason: 'The destination path is missing.',+ }));+ const agent = new CodexAgent(createDeps({}, { reviewAutoPermissionAction }));+ const host = installFakeHost(agent);+ const handle = await agent.startSession({+ sessionId: 'session-auto-file-change-without-root',+ model: 'gpt-5.5',+ providerId: 'xd',+ workingDir: '/repo',+ permissionMode: 'auto',+ });+ const handlers = host.getThreadHandlers();+ if (!handlers?.fileChangeApproval) throw new Error('expected fileChangeApproval handler');+ const resolver = vi.fn(async (): Promise<InteractionDecision> => (+ { kind: 'permission', behavior: 'allow' }+ ));+ handle.setInteractionResolver(resolver);++ await expect(handlers.fileChangeApproval({+ threadId: 'start-thread-id',+ turnId: 'turn-file-change-without-root',+ itemId: 'patch-without-root',+ grantRoot: null,+ })).resolves.toEqual({ decision: 'accept' });++ expect(reviewAutoPermissionAction).not.toHaveBeenCalled();+ expect(resolver).toHaveBeenCalledOnce();+ expect(resolver.mock.calls[0]?.[0]).toMatchObject({+ kind: 'permission',+ toolName: 'file_change',+ input: { grantRoot: null },+ });+ const request = resolver.mock.calls[0]?.[0];+ expect(request?.kind).toBe('permission');+ if (request?.kind !== 'permission') throw new Error('expected permission request');+ expect(request.suggestions).toBeDefined();+ await handle.close();+ });++ it('accepts a pending missing-root file approval when switching to Full access', async () => {+ const agent = new CodexAgent(createDeps());+ const host = installFakeHost(agent);+ const handle = await agent.startSession({+ sessionId: 'session-auto-file-change-without-root-mode-switch',+ model: 'gpt-5.5',+ providerId: 'xd',+ workingDir: '/repo',+ permissionMode: 'auto',+ });+ const handlers = host.getThreadHandlers();+ if (!handlers?.fileChangeApproval) throw new Error('expected fileChangeApproval handler');+ const pendingDecision = deferred<InteractionDecision>();+ const resolver = vi.fn(() => pendingDecision.promise);+ handle.setInteractionResolver(resolver);++ const approval = handlers.fileChangeApproval({+ threadId: 'start-thread-id',+ turnId: 'turn-file-change-without-root-mode-switch',+ itemId: 'patch-without-root-mode-switch',+ grantRoot: null,+ });+ await vi.waitFor(() => expect(resolver).toHaveBeenCalledOnce());++ if (!handle.setPermissionMode) throw new Error('expected setPermissionMode');+ await handle.setPermissionMode('bypassPermissions');++ await expect(approval).resolves.toEqual({ decision: 'accept' });+ pendingDecision.resolve({ kind: 'permission', behavior: 'deny' });+ await handle.close();+ });++ it('keeps Full access non-interactive when a file-change approval omits grantRoot', async () => {+ const agent = new CodexAgent(createDeps());+ const host = installFakeHost(agent);+ const handle = await agent.startSession({+ sessionId: 'session-full-file-change-without-root',+ model: 'gpt-5.5',+ providerId: 'xd',+ workingDir: '/repo',+ permissionMode: 'bypassPermissions',+ });+ const handlers = host.getThreadHandlers();+ if (!handlers?.fileChangeApproval) throw new Error('expected fileChangeApproval handler');++ await expect(handlers.fileChangeApproval({+ threadId: 'start-thread-id',+ turnId: 'turn-full-file-change-without-root',+ itemId: 'full-patch-without-root',+ grantRoot: null,+ })).resolves.toEqual({ decision: 'accept' });+ await handle.close();+ });+it('re-checks Ask and Full access after an in-flight Cindy auto-review', async () => {const askReview = deferred<{ verdict: 'allow' }>();const askReviewer = vi.fn(() => askReview.promise);diff --cc packages/maker-core/src/agents/codex/index.tsindex 3c31ece48f,eb078a34e5..bb7fbcc3ba--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@@ -5499,8 -5537,7 +5544,9 @@@ export class CodexAgent extends BaseAgeopts?.forcePrompt === true ||(req.kind === 'permission' &&forceTurnConfirmation(req.toolName, req.input));+ let unavailableHandoff = false;+ let approvalRequest = req;+ const promptInAuto = opts?.promptInAuto === true;// Full access 的普通审批不应打断用户。Auto 在已验证路由上由 app-server// auto_review 负责;fallback 路由则由 user reviewer 把越界请求发回客户端,// 再由 Cindy reviewer 静默裁决。