|
| 1 | +import {LlmGenerateFilesRequestOptions, LlmRunner} from './llm-runner.js'; |
| 2 | +import {join} from 'path'; |
| 3 | +import {mkdirSync} from 'fs'; |
| 4 | +import {writeFile} from 'fs/promises'; |
| 5 | +import {BaseCliAgentRunner} from './base-cli-agent-runner.js'; |
| 6 | + |
| 7 | +const MODEL_MAPPING: Record<string, string> = { |
| 8 | + 'openai-o3': 'o3', |
| 9 | + 'openai-o4-mini': 'o4-mini', |
| 10 | + 'openai-gpt-5': 'gpt-5-codex', |
| 11 | +}; |
| 12 | + |
| 13 | +/** Runner that generates code using Codex. */ |
| 14 | +export class CodexRunner extends BaseCliAgentRunner implements LlmRunner { |
| 15 | + readonly id = 'codex'; |
| 16 | + readonly displayName = 'Codex'; |
| 17 | + readonly hasBuiltInRepairLoop = true; |
| 18 | + protected ignoredFilePatterns = ['**/AGENTS.md', '**/.codex/**']; |
| 19 | + protected binaryName = 'codex'; |
| 20 | + |
| 21 | + getSupportedModels(): string[] { |
| 22 | + return Object.keys(MODEL_MAPPING); |
| 23 | + } |
| 24 | + |
| 25 | + protected getCommandLineFlags(options: LlmGenerateFilesRequestOptions): string[] { |
| 26 | + return [ |
| 27 | + 'exec', |
| 28 | + '--model', |
| 29 | + MODEL_MAPPING[options.model], |
| 30 | + // Skip all confirmations. |
| 31 | + '--dangerously-bypass-approvals-and-sandbox', |
| 32 | + '--skip-git-repo-check', |
| 33 | + options.context.executablePrompt, |
| 34 | + ]; |
| 35 | + } |
| 36 | + |
| 37 | + protected async writeAgentFiles(options: LlmGenerateFilesRequestOptions): Promise<void> { |
| 38 | + const {context} = options; |
| 39 | + const instructionFilePath = join(context.directory, 'AGENTS.md'); |
| 40 | + const settingsDir = join(context.directory, '.codex'); |
| 41 | + |
| 42 | + mkdirSync(settingsDir); |
| 43 | + |
| 44 | + await Promise.all([ |
| 45 | + writeFile(join(settingsDir, 'config.toml'), this.getSettingsFile()), |
| 46 | + writeFile(instructionFilePath, super.getCommonInstructions(options)), |
| 47 | + ]); |
| 48 | + } |
| 49 | + |
| 50 | + private getSettingsFile(): string { |
| 51 | + return ['hide_agent_reasoning = true', ''].join('\n'); |
| 52 | + } |
| 53 | +} |
0 commit comments