Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(codex): allow flat Review tools for xAI providers
DavidShencc8aca074f3d
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex 792446e167..157a99d62b 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -1922,17 +1922,24 @@ describe('CodexAgent permissions', () => {{ providerId: 'xai', model: 'grok-4' },{ providerId: ' xai ', model: 'grok-4' },{ providerId: undefined, model: 'xai/grok-4' },- ])('rejects unsupported Windows Review dynamic-tool routes before startup ($providerId, $model)', async ({ providerId, model }) => {+ ])('starts Windows Review with flat read tools on xAI routes ($providerId, $model)', async ({ providerId, model }) => {+ const workingDir = await fs.mkdtemp(path.join(os.tmpdir(), 'codex-review-xai-'));+ tempRoots.push(workingDir);const agent = new CodexAgent(createDeps());- const host = installFakeHost(agent, undefined, { userAgent: 'mock-codex/0.156.0' });- const realpath = vi.spyOn(fs, 'realpath');- await expect(agent.startSession({- sessionId: 'review-unsupported-provider', providerId, model,- workingDir: 'C:\\review', reviewMode: true,- })).rejects.toThrow('requires a provider that supports dynamic tools');- expect(realpath).not.toHaveBeenCalled();- expect(host.request).not.toHaveBeenCalled();- realpath.mockRestore();+ const host = installFakeHost(agent, method => method === Method.ExperimentalFeatureEnablementSet ? {} : undefined,+ { userAgent: 'mock-codex/0.156.0' });+ const handle = await agent.startSession({+ sessionId: 'review-xai', providerId, model, workingDir, reviewMode: true,+ });+ const start = host.request.mock.calls.find(([method]) => method === Method.ThreadStart)![1] as Record<string, unknown>;+ expect(start.dynamicTools).toEqual([+ expect.objectContaining({ type: 'function', name: 'review_read_file' }),+ expect.objectContaining({ type: 'function', name: 'review_list_directory' }),+ expect.objectContaining({ type: 'function', name: 'review_view_image' }),+ ]);+ expect(start.config).toMatchObject({ 'features.shell_tool': false, 'features.view_image': false });+ expect(start).toHaveProperty('permissions');+ await handle.close();});it.skipIf(process.platform !== 'win32').each([diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex 536f1d5da3..b7c72a8667 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -4831,9 +4831,6 @@ assertRouteCurrent();if (reviewMode) {try {if (process.platform === 'win32') {- if (!supportsCodexDynamicTools(opts)) {- throw new Error('Windows Cindy Review requires a provider that supports dynamic tools. Select a supported provider before retrying Review.');- }if ([opts.workingDir, ...(opts.reviewReadPaths ?? [])].some((candidate) => !isWindowsReviewLocalPath(candidate, opts.workingDir))) {throw new Error('Windows Cindy Review requires local drive paths; UNC shares, device paths and alternate data streams are not supported. Use a local copy before retrying Review.');}@@ -4914,6 +4911,8 @@ assertRouteCurrent();}const registeredHostDynamicToolKeys = new Set(hostDynamicTools.map(dynamicToolKey));const sessionDynamicTools = [+ // Windows Review requires 0.156+ and exposes flat function tools. The legacy+ // provider gate above concerns namespace tools, not these scoped reads....(reviewMode && process.platform === 'win32' ? REVIEW_READ_TOOLS : []),...(!reviewMode && shouldRegisterAskUserDynamicTool(opts) ? [ASK_USER_DYNAMIC_TOOL] : []),...(!reviewMode ? hostDynamicTools : []),diff --git a/packages/maker-core/src/agents/codex/review-start.native.test.ts b/packages/maker-core/src/agents/codex/review-start.native.test.tsindex 93f049c50c..cd10dfd73f 100644--- a/packages/maker-core/src/agents/codex/review-start.native.test.ts+++ b/packages/maker-core/src/agents/codex/review-start.native.test.ts@@ -17,14 +17,15 @@ const logger: Logger = {describe.skipIf(!binaryPath || process.platform !== 'win32')('Windows Codex Review with real app-server', () => {it.each([- { binary: binaryPath!, configuredMemory: false, compatible: true },- { binary: binaryPath!, configuredMemory: true, compatible: true },- ...(legacyBinaryPath ? [{ binary: legacyBinaryPath, configuredMemory: false, compatible: false }] : []),- ])('enforces scoped reads (configured memory: $configuredMemory, compatible runtime: $compatible)', async ({ binary, configuredMemory, compatible }) => {+ { binary: binaryPath!, configuredMemory: false, compatible: true, providerId: 'cprov-fixture', model: 'fixture-model' },+ { binary: binaryPath!, configuredMemory: true, compatible: true, providerId: 'cprov-fixture', model: 'gpt-5.4' },+ { binary: binaryPath!, configuredMemory: false, compatible: true, providerId: 'xai', model: 'grok-4' },+ { binary: binaryPath!, configuredMemory: false, compatible: true, providerId: undefined, model: 'xai/grok-4' },+ ...(legacyBinaryPath ? [{ binary: legacyBinaryPath, configuredMemory: false, compatible: false, providerId: 'cprov-fixture', model: 'fixture-model' }] : []),+ ])('enforces scoped reads (model: $model, memory: $configuredMemory, compatible: $compatible)', async ({ binary, configuredMemory, compatible, providerId, model }) => {const root = await mkdtemp(path.join(tmpdir(), 'cindy-review-start-'));const home = path.join(root, 'codex');const workingDir = path.join(root, 'work');- const model = configuredMemory ? 'gpt-5.4' : 'fixture-model';await mkdir(home);await mkdir(workingDir);await writeFile(path.join(workingDir, 'evidence.md'), 'REVIEW_EVIDENCE');@@ -34,7 +35,8 @@ describe.skipIf(!binaryPath || process.platform !== 'win32')('Windows Codex Reviconst png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC', 'base64');await writeFile(path.join(workingDir, 'evidence.png'), png);await writeFile(path.join(root, 'private.png'), png);- const requests: { tools: { name: string }[]; input: { type: string; call_id?: string; output?: unknown }[] }[] = [];+ const requests: { tools: { name: string; type: string }[]; input: { type: string; call_id?: string; output?: unknown }[] }[] = [];+ const functionOnly = providerId === 'xai' || model.startsWith('xai/');// The scripted local provider exercises tool round trips without a real// model, cloud credentials, administrator setup, or the user's Codex home.const calls = [@@ -53,6 +55,13 @@ describe.skipIf(!binaryPath || process.platform !== 'win32')('Windows Codex Reviconst chunks = [];for await (const chunk of req) chunks.push(chunk);requests.push(JSON.parse(Buffer.concat(chunks).toString()));+ // xAI Responses accepts flat function tools, not Codex namespace tools.+ // Validate the real app-server wire output, not just thread/start input.+ if (functionOnly && requests.at(-1)!.tools.some(tool => tool.type !== 'function')) {+ res.writeHead(400, { 'content-type': 'application/json' });+ res.end(JSON.stringify({ error: { message: 'Only flat function tools are supported' } }));+ return;+ }const step = requests.length - 1;const call = calls[step];res.writeHead(200, { 'content-type': 'text/event-stream', connection: 'close' });@@ -108,7 +117,7 @@ describe.skipIf(!binaryPath || process.platform !== 'win32')('Windows Codex Revi});try {const started = agent.startSession({- sessionId: `review-${configuredMemory}`, providerId: 'cprov-fixture',+ sessionId: `review-${configuredMemory}`, providerId,model, workingDir, reviewMode: true,makerMemoryEnabled: false,});@@ -130,6 +139,7 @@ describe.skipIf(!binaryPath || process.platform !== 'win32')('Windows Codex Reviawait handle.send({ type: 'user', content: 'Review the fixture' }, { throwOnStartFailure: true });await events;expect(requests).toHaveLength(calls.length + 1);+ if (functionOnly) expect(requests.every(request => request.tools.every(tool => tool.type === 'function'))).toBe(true);expect(requests[0].tools.map((tool) => tool.name).sort()).toEqual([...(configuredMemory ? ['apply_patch'] : []),'request_user_input', 'review_list_directory', 'review_read_file', 'review_view_image',