(options: {
targetDir: string;
targetRepo: string;
sha: string;
baseSha: string;
metadata: CommitMetadata;
model: string;
reasoningEffort: string;
sandboxMode: string;
serviceTier: string;
timeoutMs: number;
workDir: string;
additionalPrompt: string;
extraCodexConfig?: readonly string[];
})
| 279 | } |
| 280 | |
| 281 | function runCodex(options: { |
| 282 | targetDir: string; |
| 283 | targetRepo: string; |
| 284 | sha: string; |
| 285 | baseSha: string; |
| 286 | metadata: CommitMetadata; |
| 287 | model: string; |
| 288 | reasoningEffort: string; |
| 289 | sandboxMode: string; |
| 290 | serviceTier: string; |
| 291 | timeoutMs: number; |
| 292 | workDir: string; |
| 293 | additionalPrompt: string; |
| 294 | extraCodexConfig?: readonly string[]; |
| 295 | }): string { |
| 296 | ensureDir(options.workDir); |
| 297 | const promptPath = join(options.workDir, `${options.sha}.prompt.md`); |
| 298 | const outputPath = join(options.workDir, `${options.sha}.md`); |
| 299 | writeFileSync( |
| 300 | promptPath, |
| 301 | promptForCommit({ |
| 302 | targetDir: options.targetDir, |
| 303 | targetRepo: options.targetRepo, |
| 304 | sha: options.sha, |
| 305 | baseSha: options.baseSha, |
| 306 | metadata: options.metadata, |
| 307 | additionalPrompt: options.additionalPrompt, |
| 308 | }), |
| 309 | "utf8", |
| 310 | ); |
| 311 | const codexConfig = [ |
| 312 | `model_reasoning_effort="${options.reasoningEffort}"`, |
| 313 | codexLoginConfig(), |
| 314 | 'approval_policy="never"', |
| 315 | ...(options.extraCodexConfig ?? []), |
| 316 | ]; |
| 317 | if (options.serviceTier) codexConfig.splice(1, 0, `service_tier="${options.serviceTier}"`); |
| 318 | const result = runCodexProcess({ |
| 319 | args: [ |
| 320 | "exec", |
| 321 | ...codexModelArgs(options.model), |
| 322 | ...codexConfig.flatMap((config) => ["-c", config]), |
| 323 | "-C", |
| 324 | options.targetDir, |
| 325 | "--output-last-message", |
| 326 | outputPath, |
| 327 | "--sandbox", |
| 328 | options.sandboxMode, |
| 329 | "-", |
| 330 | ], |
| 331 | cwd: options.targetDir, |
| 332 | env: codexEnv({ ghToken: process.env.COMMIT_SWEEPER_TARGET_GH_TOKEN }), |
| 333 | input: readFileSync(promptPath, "utf8"), |
| 334 | timeoutMs: options.timeoutMs, |
| 335 | }); |
| 336 | if (result.error || result.status !== 0 || !existsSync(outputPath)) { |
| 337 | const timeout = codexProcessErrorCode(result.error) === "ETIMEDOUT"; |
| 338 | const detail = |
no test coverage detected