'running', 'log' => tail('/tmp/autolearn.log', 5)]); exit; } $tests = $_GET['tests'] ?? ''; $args = $tests ? implode(' ', array_map('escapeshellarg', explode(',', $tests))) : ''; $pid = trim(shell_exec("nohup python3 $script $args > $logFile 2>&1 & echo $!")); file_put_contents($pidFile, $pid); echo json_encode(['status' => 'started', 'pid' => $pid]); break; case 'status': $running = file_exists($pidFile) && file_exists('/proc/' . trim(@file_get_contents($pidFile))); echo json_encode(['status' => $running ? 'running' : 'idle', 'log' => tail($logFile, 8)]); break; case 'report': $f = "$learnDir/latest-report.json"; echo file_exists($f) ? file_get_contents($f) : json_encode(['error' => 'No report yet']); break; case 'learnings': $f = "$learnDir/learnings.json"; echo file_exists($f) ? file_get_contents($f) : json_encode(['learnings' => []]); break; case 'patches': $f = "$learnDir/prompt-patches.json"; echo file_exists($f) ? file_get_contents($f) : json_encode([]); break; default: echo json_encode(['actions' => ['run','status','report','learnings','patches']]); } function tail($f, $n = 10) { if (!file_exists($f)) return ''; return implode('', array_slice(file($f), -$n)); }