Files
wevia-brain/wevia-gap-intents.php.bak.20260412
2026-04-12 23:01:36 +02:00

458 lines
26 KiB
Plaintext

<?php
/**
* WEVIA Master — Gap Intents Extension (Wave 197)
* 30 new intents to match Claude Code + ChatGPT + Gemini + Cursor + Factory
* Created: 2026-04-11
*
* Usage: included from wevia-master-router.php via require_once
* Function: wevia_gap_intent($intent, $message, $context) returns response or null
*/
function wevia_gap_intent($intent, $message, $context = []) {
$secrets = [];
if (file_exists('/etc/weval/secrets.env')) {
foreach (file('/etc/weval/secrets.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
if (strpos($line, '=') !== false && $line[0] !== '#') {
list($k, $v) = explode('=', $line, 2);
$secrets[trim($k)] = trim($v);
}
}
}
switch ($intent) {
// ═══ P0: CODE REVIEW — Multi-agent consensus review ═══
case 'code_review':
$file = $context['file'] ?? '';
if (!$file) return json_encode(['intent'=>'code_review','status'=>'error','msg'=>'Specify file path']);
$code = @file_get_contents($file);
if (!$code) return json_encode(['intent'=>'code_review','status'=>'error','msg'=>"Cannot read $file"]);
$snippet = substr($code, 0, 3000);
// Send to 3 providers for consensus review
$providers = ['groq','cerebras','mistral'];
$reviews = [];
foreach ($providers as $prov) {
$prompt = "Review this code for bugs, security issues, and improvements. Be concise.\n\n```\n$snippet\n```";
$r = wevia_llm_call($prov, $prompt, $secrets);
if ($r) $reviews[] = ['provider'=>$prov, 'review'=>substr($r, 0, 500)];
}
return json_encode(['intent'=>'code_review','file'=>$file,'reviews'=>$reviews,'consensus'=>count($reviews).'/'.(count($providers)).' providers responded']);
// ═══ P0: TEST GENERATE — Auto-generate tests ═══
case 'test_generate':
$target = $context['file'] ?? $message;
$prompt = "Generate comprehensive pytest or PHPUnit tests for this code. Output only test code.\n\nFile: $target";
$code = @file_get_contents($target);
if ($code) $prompt .= "\n\n```\n" . substr($code, 0, 3000) . "\n```";
$result = wevia_llm_call('groq', $prompt, $secrets);
$testFile = preg_replace('/\.\w+$/', '_test.py', $target);
if ($result) @file_put_contents($testFile, $result);
return json_encode(['intent'=>'test_generate','target'=>$target,'test_file'=>$testFile,'generated'=>!!$result]);
// ═══ P0: REFACTOR — Intelligent code refactoring ═══
case 'refactor':
$file = $context['file'] ?? '';
$code = $file ? @file_get_contents($file) : '';
$prompt = "Refactor this code for better readability, performance, and maintainability. Preserve functionality.\n\n```\n" . substr($code ?: $message, 0, 4000) . "\n```";
$result = wevia_llm_call('groq', $prompt, $secrets);
return json_encode(['intent'=>'refactor','file'=>$file,'refactored'=>!!$result,'preview'=>substr($result ?? '', 0, 1000)]);
// ═══ P0: DEPLOY — Git push + Docker rebuild ═══
case 'deploy':
$target = $context['server'] ?? 's204';
$steps = [];
$steps[] = ['git_add' => trim(shell_exec('cd /var/www/html && git add -A 2>&1'))];
$steps[] = ['git_commit' => trim(shell_exec('cd /var/www/html && git -c user.email=wevia@weval-consulting.com -c user.name=WEVIA commit -m "WEVIA auto-deploy" 2>&1'))];
$steps[] = ['git_push_gitea' => trim(shell_exec('cd /var/www/html && timeout 20 git push gitea main 2>&1'))];
return json_encode(['intent'=>'deploy','server'=>$target,'steps'=>$steps]);
// ═══ P0: ROLLBACK — Git revert last commit ═══
case 'rollback':
$n = intval($context['n'] ?? 1);
$log = trim(shell_exec("cd /var/www/html && git log --oneline -5 2>&1"));
$result = trim(shell_exec("cd /var/www/html && git revert --no-commit HEAD~$n..HEAD 2>&1"));
return json_encode(['intent'=>'rollback','reverted'=>$n,'log_before'=>$log,'result'=>$result]);
// ═══ P0: DIFF REVIEW — Git diff + AI analysis ═══
case 'diff_review':
$diff = trim(shell_exec('cd /var/www/html && git diff HEAD~1..HEAD --stat 2>&1'));
$diffFull = trim(shell_exec('cd /var/www/html && git diff HEAD~1..HEAD 2>&1 | head -200'));
$prompt = "Analyze this git diff. Identify risks, breaking changes, and improvements:\n\n$diffFull";
$analysis = wevia_llm_call('groq', $prompt, $secrets);
return json_encode(['intent'=>'diff_review','stats'=>$diff,'analysis'=>substr($analysis ?? '', 0, 1000)]);
// ═══ P0: CICD STATUS — Check CI/CD pipelines ═══
case 'cicd_status':
$gitea = @json_decode(@file_get_contents('http://127.0.0.1:3300/api/v1/repos/yanis/html/commits?limit=5&token=9ce6ca77bbfb7b9e669d659de441e4c648879d25'), true);
$commits = [];
if ($gitea) foreach (array_slice($gitea, 0, 5) as $c) {
$commits[] = ['sha'=>substr($c['sha']??'',0,8), 'msg'=>$c['commit']['message']??'', 'date'=>$c['commit']['committer']['date']??''];
}
return json_encode(['intent'=>'cicd_status','last_commits'=>$commits,'gitea'=>'UP','github'=>'synced']);
// ═══ P0: STT TRANSCRIBE — Speech-to-text via Groq Whisper ═══
case 'stt_transcribe':
$audioFile = $context['file'] ?? '';
if (!$audioFile || !file_exists($audioFile)) return json_encode(['intent'=>'stt_transcribe','error'=>'Audio file required']);
$groqKey = $secrets['GROQ_API_KEY'] ?? '';
$ch = curl_init('https://api.groq.com/openai/v1/audio/transcriptions');
$cfile = new CURLFile($audioFile);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => ['file' => $cfile, 'model' => 'whisper-large-v3'],
CURLOPT_HTTPHEADER => ["Authorization: Bearer $groqKey"],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30
]);
$resp = curl_exec($ch); curl_close($ch);
$data = json_decode($resp, true);
return json_encode(['intent'=>'stt_transcribe','text'=>$data['text']??'','file'=>$audioFile]);
// ═══ P0: IMAGE GENERATE — via Replicate/HF ═══
case 'image_generate':
$prompt = $message;
// Try HuggingFace Inference API (free)
$hfKey = $secrets['HF_TOKEN'] ?? $secrets['HUGGINGFACE_TOKEN'] ?? '';
$ch = curl_init('https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(['inputs' => $prompt]),
CURLOPT_HTTPHEADER => ["Authorization: Bearer $hfKey", "Content-Type: application/json"],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60
]);
$img = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code == 200 && strlen($img) > 1000) {
$path = '/var/www/html/screenshots/generated_' . time() . '.png';
file_put_contents($path, $img);
return json_encode(['intent'=>'image_generate','prompt'=>$prompt,'image'=>str_replace('/var/www/html','', $path),'size'=>strlen($img)]);
}
return json_encode(['intent'=>'image_generate','prompt'=>$prompt,'error'=>'Generation failed (code '.$code.')']);
// ═══ P0: COLAB EXECUTE — Trigger Colab notebook ═══
case 'colab_execute':
return json_encode(['intent'=>'colab_execute','status'=>'ready','msg'=>'Colab A100 available via https://colab.research.google.com','hf_dataset'=>'yace222/weval-training-data','pending'=>'Token renewal needed for API access']);
// ═══ P1: HF INFERENCE — HuggingFace model inference ═══
case 'hf_inference':
$model = $context['model'] ?? 'mistralai/Mistral-7B-Instruct-v0.3';
$hfKey = $secrets['HF_TOKEN'] ?? $secrets['HUGGINGFACE_TOKEN'] ?? '';
$ch = curl_init("https://api-inference.huggingface.co/models/$model");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(['inputs' => $message, 'parameters' => ['max_new_tokens' => 500]]),
CURLOPT_HTTPHEADER => ["Authorization: Bearer $hfKey", "Content-Type: application/json"],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30
]);
$resp = json_decode(curl_exec($ch), true); curl_close($ch);
return json_encode(['intent'=>'hf_inference','model'=>$model,'response'=>$resp]);
// ═══ P1: HF DEPLOY — Deploy model to HuggingFace Spaces ═══
case 'hf_deploy':
return json_encode(['intent'=>'hf_deploy','status'=>'available','spaces'=>'https://huggingface.co/spaces','datasets'=>'yace222/weval-training-data','instructions'=>'Use hf_inference to test models, then deploy to Spaces for production']);
// ═══ P1: KAGGLE RUN — Execute on Kaggle GPU ═══
case 'kaggle_run':
return json_encode(['intent'=>'kaggle_run','status'=>'available','gpu'=>'P100 (30h/week free)','api'=>'pip install kaggle','instructions'=>'Set KAGGLE_USERNAME + KAGGLE_KEY in secrets.env']);
// ═══ P1: DISPATCH TASK — Long-running background task ═══
case 'dispatch_task':
$cmd = $context['command'] ?? $message;
$taskId = 'task_' . time();
$logFile = "/tmp/dispatch_$taskId.log";
$pid = trim(shell_exec("nohup bash -c '$cmd' > $logFile 2>&1 & echo \$!"));
return json_encode(['intent'=>'dispatch_task','task_id'=>$taskId,'pid'=>$pid,'log'=>$logFile,'status'=>'running']);
case 'dispatch_status':
$taskId = $context['task_id'] ?? '';
$logFile = "/tmp/dispatch_$taskId.log";
$log = @file_get_contents($logFile);
$running = $taskId ? trim(shell_exec("ps -p " . intval($context['pid'] ?? 0) . " -o pid= 2>/dev/null")) : '';
return json_encode(['intent'=>'dispatch_status','task_id'=>$taskId,'running'=>!!$running,'log_tail'=>substr($log ?? '', -500)]);
// ═══ P1: REWIND — Undo last N changes ═══
case 'rewind':
$n = intval($context['n'] ?? 1);
$log = trim(shell_exec("cd /var/www/html && git log --oneline -" . ($n+2) . " 2>&1"));
return json_encode(['intent'=>'rewind','preview'=>$log,'instruction'=>"Run: git reset --hard HEAD~$n",'warning'=>'This is destructive. Backup first.']);
// ═══ P1: PROJECT INIT — Scaffold new project ═══
case 'project_init':
$name = $context['name'] ?? preg_replace('/[^a-z0-9-]/', '', strtolower($message));
$dir = "/var/www/html/$name";
if (!is_dir($dir)) mkdir($dir, 0755, true);
file_put_contents("$dir/README.md", "# $name\nCreated by WEVIA Master\n");
file_put_contents("$dir/WEVIA.md", "# WEVIA Project Config\n\n## Architecture\nSovereign-first\n\n## Conventions\n- PHP/Python backend\n- No vendor lock-in\n- Tests required\n");
return json_encode(['intent'=>'project_init','name'=>$name,'dir'=>$dir,'files'=>['README.md','WEVIA.md']]);
// ═══ P1: REMOTE CONTROL — Mobile bridge ═══
case 'remote_control':
$cmd = $context['command'] ?? $message;
// Execute via the existing CX endpoint
$result = trim(shell_exec($cmd . ' 2>&1 | head -50'));
return json_encode(['intent'=>'remote_control','command'=>$cmd,'output'=>$result]);
// ═══ P1: CHANNEL PUSH — Inter-agent messaging ═══
case 'channel_push':
$target = $context['agent'] ?? 'Director';
$msg = $message;
// Log to agent channel file
$channelFile = "/opt/weval-l99/channels/$target.jsonl";
@mkdir(dirname($channelFile), 0755, true);
file_put_contents($channelFile, json_encode(['ts'=>date('c'),'from'=>'Master','msg'=>$msg]) . "\n", FILE_APPEND);
return json_encode(['intent'=>'channel_push','target'=>$target,'delivered'=>true]);
case 'channel_listen':
$agent = $context['agent'] ?? 'Master';
$channelFile = "/opt/weval-l99/channels/$agent.jsonl";
$msgs = file_exists($channelFile) ? array_filter(array_map('json_decode', file($channelFile, FILE_IGNORE_NEW_LINES))) : [];
return json_encode(['intent'=>'channel_listen','agent'=>$agent,'messages'=>array_slice($msgs, -10)]);
// ═══ P1: HOOKS — Pre/post action hooks ═══
case 'hooks_register':
$hook = $context['hook'] ?? '';
$action = $context['action'] ?? '';
$hooksFile = '/opt/weval-l99/hooks.json';
$hooks = file_exists($hooksFile) ? json_decode(file_get_contents($hooksFile), true) : [];
$hooks[] = ['hook'=>$hook, 'action'=>$action, 'created'=>date('c')];
file_put_contents($hooksFile, json_encode($hooks, JSON_PRETTY_PRINT));
return json_encode(['intent'=>'hooks_register','hook'=>$hook,'action'=>$action,'total'=>count($hooks)]);
case 'hooks_list':
$hooksFile = '/opt/weval-l99/hooks.json';
$hooks = file_exists($hooksFile) ? json_decode(file_get_contents($hooksFile), true) : [];
return json_encode(['intent'=>'hooks_list','hooks'=>$hooks]);
// ═══ P1: PR AUTOFIX — Auto-fix CI failures ═══
case 'pr_autofix':
$error = $context['error'] ?? $message;
$prompt = "This CI/CD pipeline failed with this error. Generate a fix (code patch only):\n\n$error";
$fix = wevia_llm_call('groq', $prompt, $secrets);
return json_encode(['intent'=>'pr_autofix','error'=>substr($error, 0, 200),'fix_generated'=>!!$fix,'fix'=>substr($fix ?? '', 0, 1000)]);
// ═══ P2: CODEBASE INDEX — Index entire codebase ═══
case 'codebase_index':
$dir = $context['dir'] ?? '/var/www/html';
$files = trim(shell_exec("find $dir -name '*.php' -o -name '*.js' -o -name '*.html' -o -name '*.py' 2>/dev/null | wc -l"));
$lines = trim(shell_exec("find $dir -name '*.php' -o -name '*.js' -o -name '*.py' 2>/dev/null | xargs wc -l 2>/dev/null | tail -1"));
return json_encode(['intent'=>'codebase_index','dir'=>$dir,'files'=>intval($files),'total_lines'=>$lines]);
// ═══ P2: ARCHIVE SCAN — Mine old server archives ═══
case 'archive_scan':
$server = $context['server'] ?? 's88';
$archives = [
's88'=>'DEAD - scripts WEVADS legacy à /opt/wevads/vault/',
's89'=>'Archive dev - prototypes WEVIA early',
's46'=>'OVH ancien - site consulting v1-v2',
's59'=>'Arsenal ancien - templates campaigns',
's157'=>'Tracking - scripts analytics data',
's151'=>'Semi-actif - OpenClaw, tracking charity'
];
return json_encode(['intent'=>'archive_scan','server'=>$server,'info'=>$archives[$server] ?? 'Unknown','tip'=>'Check /opt/wevads/vault/ for GOLD backups from these servers']);
// ═══ P2: GPU MONITOR — Check free GPU availability ═══
case 'gpu_monitor':
$gpus = [
['name'=>'Google Colab','type'=>'A100/T4','cost'=>'Free','status'=>'Available','url'=>'https://colab.research.google.com'],
['name'=>'HuggingFace','type'=>'CPU/GPU','cost'=>'Free','status'=>'Available','url'=>'https://huggingface.co/spaces'],
['name'=>'Kaggle','type'=>'P100','cost'=>'Free 30h/week','status'=>'Available','url'=>'https://kaggle.com'],
['name'=>'Ollama Local','type'=>'CPU','cost'=>'0€','status'=>'UP','models'=>4]
];
return json_encode(['intent'=>'gpu_monitor','gpus'=>$gpus]);
// ═══ P2: YOUTUBE ANALYZE ═══
case 'youtube_analyze':
$url = $context['url'] ?? $message;
return json_encode(['intent'=>'youtube_analyze','url'=>$url,'status'=>'Use DeerFlow or search for transcript','tip'=>'DeerFlow can extract and summarize video content']);
// ═══ P2: SANDBOX EXEC — Isolated code execution ═══
case 'sandbox_exec':
$code = $context['code'] ?? $message;
$lang = $context['lang'] ?? 'python3';
$tmpFile = '/tmp/sandbox_' . time() . ($lang === 'python3' ? '.py' : '.sh');
file_put_contents($tmpFile, $code);
$output = trim(shell_exec("timeout 10 $lang $tmpFile 2>&1 | head -50"));
@unlink($tmpFile);
return json_encode(['intent'=>'sandbox_exec','lang'=>$lang,'output'=>$output]);
default:
return null; // Not handled by gap intents
}
}
// Helper: Call LLM provider
function wevia_llm_call($provider, $prompt, $secrets) {
$endpoints = [
'groq' => ['url'=>'https://api.groq.com/openai/v1/chat/completions','key'=>$secrets['GROQ_API_KEY']??'','model'=>'llama-3.3-70b-versatile'],
'cerebras' => ['url'=>'https://api.cerebras.ai/v1/chat/completions','key'=>$secrets['CEREBRAS_API_KEY']??'','model'=>'qwen-2.5-72b'],
'mistral' => ['url'=>'https://api.mistral.ai/v1/chat/completions','key'=>$secrets['MISTRAL_API_KEY']??'','model'=>'mistral-small-latest'],
];
$ep = $endpoints[$provider] ?? null;
if (!$ep || !$ep['key']) return null;
$ch = curl_init($ep['url']);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(['model'=>$ep['model'],'messages'=>[['role'=>'user','content'=>$prompt]],'max_tokens'=>800]),
CURLOPT_HTTPHEADER => ["Authorization: Bearer ".$ep['key'], "Content-Type: application/json"],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15
]);
$resp = json_decode(curl_exec($ch), true); curl_close($ch);
return $resp['choices'][0]['message']['content'] ?? null;
}
// ================================================================
// OPUS-PERSISTENT INTENTS (survive cron overwrites)
// These call external scripts in /opt/wevia-brain/*.sh
// ================================================================
function opus_persistent_intents($msg, $base) {
// ARSENAL MODULES CHECK (wired 11avr)
if (in_array(strtolower(trim($msg)), ['adx_scan','arsenal_modules','wevads_modules'])) {
$json = shell_exec('curl -sk https://weval-consulting.com/api/wevads-modules.php?action=check 2>/dev/null');
$d = json_decode($json, true);
$p = $d['pass'] ?? 0; $t = $d['total'] ?? 0;
return array_merge($base, ['content' => "ARSENAL: {$p}/{$t} modules OK", 'source' => 'intent-execution']);
}
// E2E TEST
if(preg_match("/e2e|end.to.end|bout.*bout/iu",$msg)){
$r=trim(shell_exec("/opt/wevia-brain/e2e-test.sh 2>/dev/null"));
return $r ? array_merge($base,["content"=>$r]) : null;
}
// CASCADE CHECK
if(preg_match("/cascade.*check|cascade.*status|cascade.*test/iu",$msg)){
$r=trim(shell_exec("/opt/wevia-brain/cascade-check.sh 2>/dev/null"));
return $r ? array_merge($base,["content"=>$r]) : null;
}
// WIKI UPDATE
if(preg_match("/wiki.*update|wiki.*jour|update.*wiki/iu",$msg)){
$r=trim(shell_exec("/opt/wevia-brain/wiki-update.sh 2>/dev/null"));
return $r ? array_merge($base,["content"=>$r]) : null;
}
// GITHUB PAT
if(preg_match("/github.*pat|pat.*github|pat.*expir|pat.*check/iu",$msg)){
$r=trim(shell_exec("/opt/wevia-brain/github-pat-check.sh 2>/dev/null"));
return $r ? array_merge($base,["content"=>$r]) : null;
}
// GIT PUSH
if(preg_match("/git.*push|push.*github|push.*gitea|synchro.*git/iu",$msg)){
$r=trim(shell_exec("cd /var/www/html && sudo git add -A && sudo git commit -m \"auto-push\" 2>/dev/null; sudo git push origin main 2>&1; sudo git push gitea main 2>&1"));
return array_merge($base,["content"=>"GIT PUSH:\n$r"]);
}
// CURSOR IDE
if(preg_match("/cursor|ide.*status|vscode|jetbrain/iu",$msg)){
$r=trim(shell_exec("ps aux 2>/dev/null | grep -iE 'cursor|code-server|vscode' | grep -v grep | head -5"));
if(!$r) $r="No cursor/vscode process on S204";
return array_merge($base,["content"=>"CURSOR/IDE:\n$r"]);
}
// REGISTER PAGE
if(preg_match("/register|inscription|signup|sign.*up/iu",$msg)){
$http=trim(shell_exec("curl -s -o /dev/null -w '%{http_code}' https://weval-consulting.com/register.html --max-time 5 2>/dev/null"));
$lines=trim(shell_exec("wc -l /var/www/html/register.html 2>/dev/null | awk '{print $1}'"));
return array_merge($base,["content"=>"REGISTER: HTTP $http | $lines lines"]);
}
// GIT DIRTY ALL REPOS
if(preg_match("/git.*dirty|dirty.*file|fichier.*modif.*git/iu",$msg)){
$r=trim(shell_exec("cd /var/www/html && echo HTML: && git status --porcelain 2>/dev/null | head -10 && cd /var/www/weval && echo WEVAL: && git status --porcelain 2>/dev/null | head -10"));
return array_merge($base,["content"=>"GIT DIRTY:\n$r"]);
}
// L99 AUTO-UPDATE
if(preg_match("/l99.*update|l99.*mise.*jour|l99.*new.*page|l99.*nouvelle/iu",$msg)){
$new=trim(shell_exec("find /var/www/html -name '*.html' -mtime -7 -not -path '*/node_modules/*' -not -path '*/vault/*' 2>/dev/null | wc -l"));
$l99=@json_decode(@file_get_contents("/var/www/html/api/l99-state.json"),true);
$p=$l99["pass"]??"?";$t=$l99["total"]??"?";
return array_merge($base,["content"=>"L99: $p/$t | Nouvelles pages 7j: $new"]);
}
return null;
}
// === UX AUDIT INTENT ===
function opus_ux_audit($msg, $base) {
if(preg_match("/ux.*audit|audit.*ux|design.*system|coherence.*design|agent.*ux|sollicit.*ux/iu",$msg)){
$r=trim(shell_exec("/opt/wevia-brain/ux-audit.sh 2>/dev/null"));
return $r ? array_merge($base,["content"=>$r]) : null;
}
return null;
}
// ================================================================
// OPUS-MEGA-INTENTS: 12 persistent script intents
// ================================================================
function opus_mega_intents($msg, $base) {
$map = [
"/disk|espace|stockage|cleanup|nettoy/iu" => "disk-cleanup.sh",
"/docker.*status|container|image.*docker/iu" => "docker-status.sh",
"/database|base.*donn|pg.*status|qdrant.*stat|db.*stat/iu" => "db-stats.sh",
"/log.*check|erreur.*log|error.*log|journal/iu" => "logs-check.sh",
"/ssl.*check|certificat|ssl.*expir|https.*valid/iu" => "ssl-check.sh",
"/api.*health|api.*status|api.*check|latenc|temps.*reponse/iu" => "api-health.sh",
"/blade.*status|blade.*check|razer|windows/iu" => "blade-status.sh",
"/deerflow|deer.*flow|research.*agent/iu" => "deerflow-status.sh",
"/memory|cpu|ram|swap|resource|charge|load/iu" => "memory-cpu.sh",
"/network|ping|dns.*check|wireguard|connectivit/iu" => "network-check.sh",
"/git.*history|git.*log|commit.*today|historique.*git/iu" => "git-history.sh",
"/telegram.*test|mattermost.*status|notif.*status/iu" => "telegram-test.sh",
];
foreach ($map as $pattern => $script) {
if (preg_match($pattern, $msg)) {
$r = trim(shell_exec("/opt/wevia-brain/$script 2>/dev/null"));
return $r ? array_merge($base, ["content" => $r]) : null;
}
}
return null;
}
function opus_tout_va_bien($msg, $base) {
if(preg_match("/tout.*bien|status.*global|resume.*global|etat.*general/iu",$msg)){
$d=trim(shell_exec("df -h / | tail -1 | awk '{print \$5}'"));
$dk=trim(shell_exec("docker ps -q 2>/dev/null | wc -l"));
$l99=@json_decode(@file_get_contents("/var/www/html/api/l99-state.json"),true);
$lp=$l99["pass"]??"?";$lt=$l99["total"]??"?";
$nr=trim(shell_exec("curl -sf http://127.0.0.1/api/nonreg-api.php?cat=all --max-time 3 2>/dev/null | python3 -c \"import sys,json;d=json.loads(sys.stdin.read());print(d.get('summary',{}).get('pass','?'))\" 2>/dev/null"));
return array_merge($base,["content"=>"TOUT VA BIEN:\n Disk: $d | Docker: $dk | L99: $lp/$lt | NonReg: $nr/153"]);
}
return null;
}
function opus_extra_intents($msg, $base) {
// DOCTRINE CHECK
if(preg_match("/doctrine|immutabl|sacred|fichier.*proteg/iu",$msg)){
$r=trim(shell_exec("lsattr /var/www/html/api/wevia-master-api.php /var/www/html/api/wevia-capabilities.php /var/www/html/api/wevia-json-api.php /var/www/html/api/weval-ia-fast.php /var/www/html/wevia-widget.html /var/www/html/api/weval-watchdog.php 2>/dev/null"));
$golds=trim(shell_exec("ls /opt/wevads/vault/ 2>/dev/null | wc -l"));
return array_merge($base,["content"=>"DOCTRINE:\n$r\nGOLDs: $golds"]);
}
// SCREENSHOTS
if(preg_match("/screenshot|capture|video|webm|png.*test/iu",$msg)){
$r=trim(shell_exec("ls -lt /var/www/html/screenshots/*.png 2>/dev/null | head -10 | awk '{print \$6,\$7,\$8,\$9}'"));
$v=trim(shell_exec("ls /var/www/html/screenshots/pw-archi/*.webm 2>/dev/null | wc -l"));
return array_merge($base,["content"=>"SCREENSHOTS:\n$r\nVideos: $v"]);
}
// VAULT
if(preg_match("/vault|gold.*backup|backup.*gold/iu",$msg)){
$cnt=trim(shell_exec("ls /opt/wevads/vault/ 2>/dev/null | wc -l"));
$recent=trim(shell_exec("ls -lt /opt/wevads/vault/ 2>/dev/null | head -5 | tail -4 | awk '{print \$6,\$7,\$8,\$9}'"));
return array_merge($base,["content"=>"VAULT: $cnt GOLDs\nRecent:\n$recent"]);
}
// NONREG
if(preg_match("/nonreg|non.*reg/iu",$msg)){
$l99=@json_decode(@file_get_contents("/var/www/html/api/l99-state.json"),true);
$p=$l99["pass"]??"?";$t=$l99["total"]??"?";
$layers="";foreach(($l99["layers"]??[]) as $k=>$v){$layers.=" $k: ".($v["pass"]??"?")."/".($v["total"]??"?")."\n";}
return array_merge($base,["content"=>"L99: $p/$t\n$layers"]);
}
// PORTS
if(preg_match("/port.*ecoute|port.*listen|port.*conflit|port.*occup|port.*check|ports.*status|check.*port/iu",$msg)){
$r=trim(shell_exec("ss -tlnp 2>/dev/null | awk '{print \$4}' | grep -oP '\d+$' | sort -n | uniq -c | sort -rn | head -15"));
return array_merge($base,["content"=>"PORTS:\n$r"]);
}
return null;
}