From 9a3530fe66c64e34416380f8febcd3a4dd33aba0 Mon Sep 17 00:00:00 2001 From: Warren Wong Date: Wed, 12 Nov 2025 18:09:39 +0000 Subject: [PATCH] Fix directory structure: outputs/ for logs, runfiles/ for codex execution --- run.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/run.php b/run.php index 450d1c3..a564521 100644 --- a/run.php +++ b/run.php @@ -27,8 +27,12 @@ if ($argc > 2 && is_numeric($argv[2])) { } } -// NEW: Use runfiles subdirectory -$baseOutputDir = 'runfiles'; +// NEW: Create runfiles subdirectory for codex execution +$runfilesDir = 'runfiles'; +is_dir($runfilesDir) || mkdir($runfilesDir, 0777, true); + +// Outputs directory for logs and summaries (as before) +$baseOutputDir = 'outputs'; is_dir($baseOutputDir) || mkdir($baseOutputDir, 0777, true); $runIdentifier = date('Ymd_His'); $runDir = sprintf('%s/run_%s', $baseOutputDir, $runIdentifier); @@ -49,10 +53,15 @@ $logCli = function ($message, $channel = 'global') use (&$logFiles, $rawLogsDir) echo $message; }; $logCli(sprintf("[%s] Run initialized in %s%s", date('Y-m-d H:i:s'), $runDir, PHP_EOL), 'startup'); +$logCli(sprintf("[%s] Codex execution directory: %s%s", date('Y-m-d H:i:s'), realpath($runfilesDir), PHP_EOL), 'startup'); if ($startFrom > 1) { $logCli(sprintf("[%s] Starting from input line %d%s", date('Y-m-d H:i:s'), $startFrom, PHP_EOL), 'startup'); } -$runCommand = function ($command, $channel = 'global') use ($logCli) { +$runCommand = function ($command, $channel = 'global') use ($logCli, $runfilesDir) { + // Change to runfiles directory for execution + $originalDir = getcwd(); + chdir($runfilesDir); + $descriptorSpec = [ 0 => ['pipe', 'r'], 1 => ['pipe', 'w'], @@ -60,6 +69,7 @@ $runCommand = function ($command, $channel = 'global') use ($logCli) { ]; $process = proc_open($command, $descriptorSpec, $pipes); if (!is_resource($process)) { + chdir($originalDir); $logCli(sprintf("Failed to start command: %s%s", $command, PHP_EOL), $channel); return ['', '', 1]; } @@ -126,6 +136,10 @@ $runCommand = function ($command, $channel = 'global') use ($logCli) { } $exitCode = proc_close($process); + + // Change back to original directory + chdir($originalDir); + return [$stdout, $stderr, $exitCode]; };