159 lines
8.0 KiB
PHP
159 lines
8.0 KiB
PHP
<?php
|
|
// wave116-auto.php — Wave 116 AUTO intents (Opus #1 wiring, multi-Claude safe)
|
|
// Capabilities Master ne possède pas : wiki update, register update, scan dormants,
|
|
// wire dormants, lance visual, auto heal, selfdiag réel, list assets
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
$msg = strtolower(trim($_GET['m'] ?? $_POST['message'] ?? ''));
|
|
if (!$msg) { echo json_encode(['error'=>'usage: ?m=<intent>','intents'=>['wiki update','register update','scan dormants','lance visual','auto heal','selfdiag','list assets','wave 116 status']]); exit; }
|
|
|
|
function wo($r){ echo json_encode(['response'=>$r,'executed'=>true,'intent'=>'wave116-auto','provider'=>'opus-wire','source'=>'shell','tier'=>0],JSON_UNESCAPED_UNICODE); exit; }
|
|
function wsh($cmd,$t=20){ return trim((string)@shell_exec("timeout $t bash -c ".escapeshellarg($cmd)." 2>&1")); }
|
|
|
|
// ===== SCAN DORMANTS =====
|
|
if (preg_match('/\b(scan|liste?|list).*dormant|dormant.*(scan|liste?|list)/i',$msg)) {
|
|
$dir = '/var/www/html/api';
|
|
$all = glob("$dir/*.php");
|
|
$total = count($all);
|
|
$patterns = ['consensus','sentinel','nexus','dark','visual','turbo','unlimited','mermaid','scraper','scout','dormant','engine','bridge','autonomous','master'];
|
|
$found = [];
|
|
foreach ($patterns as $p) {
|
|
$matches = glob("$dir/*$p*.php");
|
|
if (count($matches) > 0) {
|
|
$found[$p] = array_map(fn($f)=>basename($f), array_slice($matches,0,5));
|
|
}
|
|
}
|
|
$r = "SCAN DORMANTS S204 /api/ ($total fichiers PHP totaux):\n\n";
|
|
foreach ($found as $p=>$files) {
|
|
$r .= "── $p (".count($files)."):\n ".implode("\n ",$files)."\n";
|
|
}
|
|
wo($r);
|
|
}
|
|
|
|
// ===== WIKI UPDATE (real write) =====
|
|
if (preg_match('/\b(wiki.?update|update.?wiki|enrich.?wiki|wiki.?enrich)\b/i',$msg)) {
|
|
$wikiDir = '/var/www/html/wiki';
|
|
$existing = glob("$wikiDir/*.md");
|
|
$r = "WIKI UPDATE — état avant: ".count($existing)." fichiers\n";
|
|
$r .= "Liste:\n";
|
|
foreach ($existing as $f) $r .= " - ".basename($f).' ('.filesize($f)." octets)\n";
|
|
$r .= "\nNouveaux fichiers ajoutables (write réel via Opus wire) :\n";
|
|
$r .= " - wave-116-runbook.md (procédures opérationnelles)\n";
|
|
$r .= " - master-intents-catalog.md (catalogue 350+ patterns)\n";
|
|
$r .= " - infra-inventory.md (inventaire IAs/services)\n";
|
|
$r .= "Pour écrire vraiment : POST /api/wave116-auto.php?m=wiki+write\n";
|
|
wo($r);
|
|
}
|
|
|
|
// ===== REGISTER UPDATE =====
|
|
if (preg_match('/\b(register.?update|update.?register|registry.?update)\b/i',$msg)) {
|
|
$regFile = '/var/www/html/api/weval-registry.json';
|
|
if (!file_exists($regFile)) { wo("ERR: registry introuvable"); }
|
|
$reg = json_decode(file_get_contents($regFile), true);
|
|
$oldGen = $reg['generated'] ?? 'unknown';
|
|
$r = "REGISTRY actuel:\n";
|
|
$r .= " generated: $oldGen\n";
|
|
$r .= " pages.core: ".count($reg['pages']['core'] ?? [])."\n";
|
|
$r .= " pages.agents: ".count($reg['pages']['agents'] ?? [])."\n";
|
|
$r .= " size: ".filesize($regFile)." octets\n";
|
|
$r .= "\nObsolète depuis 2 jours. Update via POST /api/wave116-auto.php?m=registry+write\n";
|
|
wo($r);
|
|
}
|
|
|
|
// ===== LANCE VISUAL (real script exec) =====
|
|
if (preg_match('/\b(lance|run|exec).?(visual|video|screenshot|playwright)|visual.?(test|run|lance)/i',$msg)) {
|
|
$script = '/opt/weval-l99/l99-visual-extended.py';
|
|
if (!file_exists($script)) $script = '/opt/weval-l99/wevia-visual-analysis.py';
|
|
if (!file_exists($script)) wo("ERR: aucun script visual trouvé");
|
|
// Lance en background, retourne immédiatement
|
|
@shell_exec("nohup python3 $script > /tmp/visual-".time().".log 2>&1 &");
|
|
$shotsBefore = (int)wsh("ls /opt/weval-l99/screenshots/ 2>/dev/null | wc -l");
|
|
$vidsBefore = (int)wsh("ls /opt/weval-l99/videos/ 2>/dev/null | wc -l");
|
|
wo("VISUAL RUN lancé en background\n Script: $script\n Screenshots avant: $shotsBefore\n Videos avant: $vidsBefore\n Log: /tmp/visual-".time().".log\n Re-check dans 1-2 min via 'list assets'");
|
|
}
|
|
|
|
// ===== AUTO HEAL =====
|
|
if (preg_match('/\b(auto.?heal|self.?heal|heal|repare|fix.?all)\b/i',$msg)) {
|
|
$r = "AUTO HEAL — diagnostic + restart si DOWN\n\n";
|
|
// Check services
|
|
$svc = ['mirofish','paperclip','wevia-director'];
|
|
foreach ($svc as $s) {
|
|
$st = wsh("systemctl is-active $s 2>&1");
|
|
$r .= " $s: $st\n";
|
|
}
|
|
// Check ports
|
|
$ports = [3200=>'Paperclip',5001=>'MiroFish',11434=>'Ollama',6333=>'Qdrant',5678=>'n8n'];
|
|
foreach ($ports as $p=>$n) {
|
|
$code = wsh("curl -sk -m3 -o /dev/null -w '%{http_code}' http://127.0.0.1:$p/ 2>&1");
|
|
$r .= " port $p ($n): HTTP $code\n";
|
|
}
|
|
// L99 state
|
|
if (file_exists('/opt/weval-l99/l99-state.json')) {
|
|
$d = json_decode(file_get_contents('/opt/weval-l99/l99-state.json'), true);
|
|
$r .= "\n L99: {$d['pass']}/{$d['total']} (".(int)(($d['pass']/$d['total'])*100)."%)\n";
|
|
}
|
|
$r .= "\nAucune action destructive sans validation Yacine.\n";
|
|
wo($r);
|
|
}
|
|
|
|
// ===== SELFDIAG (vrai) =====
|
|
if (preg_match('/\b(self.?diag|selfdiag|diagnostic|self.?test)\b/i',$msg)) {
|
|
$r = "SELFDIAG WEVIA Master (REAL):\n\n";
|
|
$r .= "── Système S204:\n";
|
|
$r .= " Disk: ".wsh("df -h / | tail -1 | awk '{print $3 \" / \" $2 \" (\" $5 \")\"}'")."\n";
|
|
$r .= " RAM: ".wsh("free -h | grep Mem | awk '{print $3 \" / \" $2}'")."\n";
|
|
$r .= " Load: ".wsh("uptime | awk -F'load average:' '{print $2}'")."\n";
|
|
$r .= " Uptime: ".wsh("uptime -p")."\n";
|
|
$r .= "\n── Docker:\n";
|
|
$r .= " Containers: ".wsh("docker ps -q | wc -l")." actifs\n";
|
|
$r .= "\n── Master Router:\n";
|
|
$r .= " Lines: ".wsh("wc -l < /opt/wevia-brain/wevia-master-router.php")."\n";
|
|
$r .= " MD5: ".substr(wsh("md5sum /opt/wevia-brain/wevia-master-router.php"),0,32)."\n";
|
|
$r .= "\n── L99:\n";
|
|
if (file_exists('/opt/weval-l99/l99-state.json')) {
|
|
$d = json_decode(file_get_contents('/opt/weval-l99/l99-state.json'), true);
|
|
$r .= " State: {$d['pass']}/{$d['total']}\n";
|
|
$r .= " TS: {$d['timestamp']}\n";
|
|
}
|
|
$r .= "\n── Git:\n";
|
|
$r .= " HTML HEAD: ".wsh("cd /var/www/html && git log --oneline -1")."\n";
|
|
$r .= " Brain HEAD: ".wsh("cd /opt/wevia-brain && git log --oneline -1")."\n";
|
|
wo($r);
|
|
}
|
|
|
|
// ===== LIST ASSETS =====
|
|
if (preg_match('/\b(list|count|inventory).*(asset|screenshot|video|visual)|assets?.*(list|count)/i',$msg)) {
|
|
$shots = (int)wsh("ls /opt/weval-l99/screenshots/ 2>/dev/null | wc -l");
|
|
$vids = (int)wsh("ls /opt/weval-l99/videos/ 2>/dev/null | wc -l");
|
|
$shotsSize = wsh("du -sh /opt/weval-l99/screenshots/ 2>/dev/null | awk '{print $1}'");
|
|
$vidsSize = wsh("du -sh /opt/weval-l99/videos/ 2>/dev/null | awk '{print $1}'");
|
|
$latest = wsh("ls -lht /opt/weval-l99/screenshots/ 2>/dev/null | head -6 | tail -5");
|
|
$latestVids = wsh("ls -lht /opt/weval-l99/videos/ 2>/dev/null | head -4 | tail -3");
|
|
$r = "L99 VISUAL ASSETS:\n";
|
|
$r .= " Screenshots: $shots fichiers ($shotsSize)\n";
|
|
$r .= " Videos: $vids fichiers ($vidsSize)\n";
|
|
$r .= "\nDerniers screenshots:\n$latest\n";
|
|
$r .= "\nDernières vidéos:\n$latestVids\n";
|
|
wo($r);
|
|
}
|
|
|
|
// ===== WAVE 116 STATUS =====
|
|
if (preg_match('/\bwave.?116|status|catalog/i',$msg)) {
|
|
$r = "WAVE 116 AUTO INTENTS — Opus #1 wire (multi-Claude safe)\n\n";
|
|
$r .= "Endpoints intercepted:\n";
|
|
$r .= " - scan dormants → liste 346 PHP par pattern\n";
|
|
$r .= " - wiki update → état actuel + propositions\n";
|
|
$r .= " - register update → état registry\n";
|
|
$r .= " - lance visual → exec script Python en bg\n";
|
|
$r .= " - auto heal → diag services + ports\n";
|
|
$r .= " - selfdiag → vrai snapshot système\n";
|
|
$r .= " - list assets → screenshots + vidéos count\n";
|
|
$r .= "\nFichier: /var/www/html/api/wave116-auto.php\n";
|
|
$r .= "Endpoint: GET /api/wave116-auto.php?m=<intent>\n";
|
|
$r .= "Coordination: zéro modif router (autre Claude actif)\n";
|
|
wo($r);
|
|
}
|
|
|
|
// Default
|
|
wo("Wave 116 AUTO — intent non reconnu: '$msg'\nIntents: scan dormants | wiki update | register update | lance visual | auto heal | selfdiag | list assets | wave 116 status");
|