43 lines
1.3 KiB
PHP
Executable File
43 lines
1.3 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
// Minimal single-call wrapper around codex exec
|
|
if ($argc < 2) {
|
|
exit("Usage: php run.php <target_directory> [start_line]\n");
|
|
}
|
|
|
|
$targetDir = $argv[1];
|
|
$startFrom = (isset($argv[2]) && is_numeric($argv[2])) ? max(1, (int)$argv[2]) : 1;
|
|
|
|
if (!is_dir($targetDir)) {
|
|
exit("Directory '$targetDir' does not exist\n");
|
|
}
|
|
|
|
chdir($targetDir);
|
|
$prompt = trim(@file_get_contents('prompt'));
|
|
$inputs = file('input', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
if (!$inputs) exit("No inputs\n");
|
|
if ($startFrom > 1) {
|
|
$inputs = array_slice($inputs, $startFrom - 1);
|
|
}
|
|
|
|
$runRoot = 'outputs';
|
|
if (!is_dir($runRoot)) mkdir($runRoot, 0777, true);
|
|
$runDir = sprintf('%s/run_%s', $runRoot, date('Ymd_His'));
|
|
mkdir($runDir, 0777, true);
|
|
|
|
$model = getenv('MODEL_NAME') ?: 'gpt-5.1-codex-max';
|
|
|
|
foreach ($inputs as $i => $line) {
|
|
$runNo = $startFrom + $i;
|
|
$fullPrompt = trim($prompt . "\n" . $line);
|
|
$cmd = sprintf(
|
|
"codex exec --model %s --skip-git-repo-check --dangerously-bypass-approvals-and-sandbox %s 2>&1",
|
|
escapeshellarg($model),
|
|
escapeshellarg($fullPrompt)
|
|
);
|
|
$output = shell_exec($cmd);
|
|
$file = sprintf('%s/run_%02d.txt', $runDir, $runNo);
|
|
file_put_contents($file, "Input: $line\n\nPrompt:\n$fullPrompt\n\nOutput:\n$output\n");
|
|
echo "Run $runNo complete -> $file\n";
|
|
}
|