$action = $_GET['action'] ?? 'info'; // Read state file $stateFile = '/opt/weval-l99/l99-state.json'; $state = file_exists($stateFile) ? json_decode(file_get_contents($stateFile), true) : []; // Read tests results $resultsFile = '/opt/weval-l99/l99-results.json'; $tests = file_exists($resultsFile) ? json_decode(file_get_contents($resultsFile), true) : []; if ($action === 'results' || $action === 'stats') { $p = 0; $f = 0; $w = 0; foreach ($tests as $t) { if (($t['status'] ?? '') === 'P') $p++; elseif (($t['status'] ?? '') === 'F') $f++; elseif (($t['status'] ?? '') === 'W') $w++; } $total = $p + $f + $w; // Use state file counts if larger (includes NonReg + infra) $sp = $state['pass'] ?? 0; $sf = $state['fail'] ?? 0; $sw = $state['warn'] ?? 0; echo json_encode([ 'pass' => max($p, $sp), 'fail' => max($f, $sf), 'warn' => max($w, $sw), 'total' => max($total, $sp + $sf + $sw), 'score' => max($total, $sp+$sf+$sw) > 0 ? round(max($p,$sp) / max($total,$sp+$sf+$sw) * 100, 1) : 0, 'screenshots' => $state['screenshots'] ?? count(glob('/opt/weval-l99/ss/*.png') ?: []) + count(glob('/opt/weval-l99/screenshots/*.png') ?: []), 'videos' => $state['videos'] ?? count(glob('/opt/weval-l99/vid/*.webm') ?: []), 'layers' => $state['layers'] ?? 14, 'timestamp' => $state['timestamp'] ?? date('c'), 'tests' => $tests, ]); exit; } if ($action === 'run') { exec('cd /opt/weval-l99 && python3 l99-master.py > /dev/null 2>&1 &'); echo json_encode(['ok' => true, 'message' => 'L99 run triggered']); exit; } if ($action === 'videos') { $vids = glob('/opt/weval-l99/vid/*.webm') ?: []; echo json_encode(['videos' => array_map('basename', $vids), 'count' => count($vids)]); exit; } if ($action === 'screenshots') { $ss = glob('/opt/weval-l99/ss/*.png') ?: []; $ss2 = glob('/opt/weval-l99/screenshots/*.png') ?: []; echo json_encode(['screenshots' => array_merge(array_map('basename', $ss), array_map('basename', $ss2)), 'count' => count($ss) + count($ss2)]); exit; } echo json_encode([ 'framework' => 'WEVAL L99 v2.0', 'endpoints' => ['results', 'stats', 'run', 'videos', 'screenshots'], 'state' => !empty($state) ? 'loaded' : 'missing', ]);