opus-reconcile-15avr

This commit is contained in:
Yanis Mahboub
2026-04-15 02:30:29 +02:00
parent a736d5d9b2
commit 2127eaaf04
7 changed files with 304 additions and 253 deletions

View File

@@ -22,8 +22,8 @@
*/
header("Content-Type: application/json; charset=utf-8");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
// CORS handled by nginx
// CORS handled by nginx
if ($_SERVER["REQUEST_METHOD"] === "OPTIONS") { http_response_code(200); exit; }
// Load dependencies
@@ -104,7 +104,7 @@ CTX
$action = null;
if (isset($_GET['status'])) $action = 'status';
elseif (isset($_GET['history'])) $action = 'history';
elseif (isset($_GET['run'])) $action = 'run';
elseif (isset($_GET['run'])) { set_time_limit(60); if (!isset($_GET['bg'])) { header('Content-Type: application/json'); $cmd = 'timeout 55 php8.4 ' . __FILE__ . ' run_bg > /dev/null 2>&1 &'; exec($cmd); echo json_encode(['status'=>'launched','duration_ms'=>0,'observations'=>new stdClass(),'plan'=>[],'actions'=>[],'report'=>'Cycle lance en background. Tapez status dans 30s.']); exit; } $action = 'run'; }
elseif (isset($_GET['health'])) $action = 'health';
elseif ($_SERVER['REQUEST_METHOD'] === 'POST') $action = 'run';

View File

@@ -1,53 +1,44 @@
<?php
// WEVIA Dynamic Tool Resolver — auto-matches tools from registry
// No more hardcoded intents needed. Just add tools to wevia-tool-registry.json
function wevia_dynamic_resolve($msg) {
$reg = @json_decode(@file_get_contents("/opt/wevia-brain/tool-registry-v2.json"), true);
if (!$reg || empty($reg["tools"])) return null;
foreach ($reg["tools"] as $t) {
if (!@preg_match("/" . $t["kw"] . "/i", $msg)) continue;
// Match found — execute
if ($t["api"] === "master") {
$ch = curl_init("https://weval-consulting.com/api/wevia-master-api.php");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(["message" => $t["msg"]]),
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_TIMEOUT => 20, CURLOPT_SSL_VERIFYPEER => false
]);
$r = curl_exec($ch);
$d = @json_decode($r, true);
if ($d && strlen($d["content"] ?? "") > 10) {
return ["content" => $d["content"], "tool" => $t["id"], "source" => "dynamic-resolver"];
function wevia_resolve($msg) {
$registry = __DIR__ . '/wevia-tool-registry.json';
if (!file_exists($registry)) return null;
$data = json_decode(file_get_contents($registry), true);
if (!is_array($data)) return null;
$tools = $data['tools'] ?? $data;
$msg_lower = mb_strtolower(trim($msg));
$best = null;
$best_score = 0;
foreach ($tools as $tool) {
if (empty($tool['kw'])) continue;
$score = 0;
if (@preg_match('/' . $tool['kw'] . '/i', $msg_lower)) {
$score = 10;
} else {
$keywords = preg_split('/[|.*()]+/', $tool['kw']);
foreach ($keywords as $kw) {
$kw = trim($kw);
if ($kw && mb_strpos($msg_lower, $kw) !== false) $score += 2;
}
} elseif (strpos($t["api"], "GET:") === 0) {
$url = "https://weval-consulting.com" . substr($t["api"], 4);
$ctx = stream_context_create(["ssl" => ["verify_peer" => false], "http" => ["timeout" => 12]]);
$r = @file_get_contents($url, false, $ctx);
$d = @json_decode($r, true);
if ($d) {
return ["content" => json_encode($d, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), "tool" => $t["id"], "source" => "dynamic-resolver"];
}
} elseif ($t["api"] === "exec" && !empty($t["cmd"])) {
// Direct shell exec — sovereign tool
$r = trim(@shell_exec($t["cmd"] . " 2>&1"));
if ($r) return ["content" => $r, "tool" => $t["id"], "source" => "dynamic-resolver-exec"];
} elseif (strpos($t["api"], "POST:") === 0) {
$url = "https://weval-consulting.com" . substr($t["api"], 5);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(["message" => $msg, "task" => $msg]),
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => false
]);
$r = curl_exec($ch);
$d = @json_decode($r, true);
if ($d) return ["content" => json_encode($d, JSON_PRETTY_PRINT), "tool" => $t["id"], "source" => "dynamic-resolver"];
}
if ($score > 0 && mb_strlen($msg_lower) > 60 && preg_match("/reconcil|diagnostic|bilan|test_global/", $tool["id"] ?? "")) $score += 1; if ($score > $best_score || ($score == $best_score && !empty($tool["cmd"]) && empty($best["cmd"]))) {
$best_score = $score;
$best = $tool;
}
}
return null; // No match — let LLM handle
if (!$best || $best_score < 3) return null;
$result = '';
// EXEC with sudo + timeout 15s to avoid CF 520
if (!empty($best['cmd'])) {
$result = shell_exec('sudo timeout 15 bash -c ' . escapeshellarg($best['cmd']) . ' 2>&1') ?? '';
if (trim($result) === '') $result = '[timeout 15s] Commande lente. Essayez plus ciblé.';
} elseif (strpos($best['api'] ?? '', 'GET:') === 0) {
$ctx = stream_context_create(['http' => ['timeout' => 4]]);
$result = @file_get_contents('http://127.0.0.1' . substr($best['api'], 4), false, $ctx) ?? '';
} elseif (strpos($best['api'] ?? '', 'POST:') === 0) {
$ctx = stream_context_create(['http' => ['method' => 'POST', 'timeout' => 4]]);
$result = @file_get_contents('http://127.0.0.1' . substr($best['api'], 5), false, $ctx) ?? '';
}
if (!$result) return ["provider"=>"dynamic-resolver","content"=>"[" . ($best["id"] ?? "tool") . "] pas de reponse (timeout ou service down)","tool"=>$best["id"]??"unknown"];
return ['provider' => 'dynamic-resolver', 'content' => trim($result), 'tool' => $best['id'] ?? 'unknown'];
}
function wevia_dynamic_resolve($msg) { return wevia_resolve($msg); }

View File

@@ -0,0 +1,59 @@
<?php
// WEVIA Dynamic Tool Resolver — auto-matches tools from registry
// No more hardcoded intents needed. Just add tools to wevia-tool-registry.json
function wevia_dynamic_resolve($msg) {
$reg = @json_decode(@file_get_contents("/opt/wevia-brain/tool-registry-v2.json"), true);
if (!$reg || empty($reg["tools"])) return null;
// CONVERSATIONAL GUARD: if message is long and looks like a question, skip broad keywords
$isConversational = mb_strlen($msg) > 60 && preg_match("/\b(comment|propose|donne|explique|rédige|aide|conseils|idées|plan|analyse|compare|résume)\b/iu", $msg);
foreach ($reg["tools"] as $t) {
if (!@preg_match("/" . $t["kw"] . "/i", $msg)) continue;
// Skip broad tools for conversational messages — let LLM handle
if ($isConversational && in_array($t["id"] ?? "", ["ethica_status","ethica_enrichment","diagnostic_system","system","diagnostic","hubsuite","gmail_hub","calendar_hub","drive_hub","strategie_q2","reconcilie_tout","reconcile_check"])) continue;
// Match found — execute
if ($t["api"] === "master") {
$ch = curl_init("https://weval-consulting.com/api/wevia-master-api.php");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(["message" => $t["msg"]]),
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_TIMEOUT => 20, CURLOPT_SSL_VERIFYPEER => false
]);
$r = curl_exec($ch);
$d = @json_decode($r, true);
if ($d && strlen($d["content"] ?? "") > 10) {
return ["content" => $d["content"], "tool" => $t["id"], "source" => "dynamic-resolver"];
}
} elseif (strpos($t["api"], "GET:") === 0) {
$url = "https://weval-consulting.com" . substr($t["api"], 4);
$ctx = stream_context_create(["ssl" => ["verify_peer" => false], "http" => ["timeout" => 12]]);
$r = @file_get_contents($url, false, $ctx);
$d = @json_decode($r, true);
if ($d) {
return ["content" => json_encode($d, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), "tool" => $t["id"], "source" => "dynamic-resolver"];
}
} elseif ($t["api"] === "exec" && !empty($t["cmd"])) {
// Direct shell exec — sovereign tool
$r = trim(@shell_exec($t["cmd"] . " 2>&1"));
if ($r) return ["content" => $r, "tool" => $t["id"], "source" => "dynamic-resolver-exec"];
} elseif (strpos($t["api"], "POST:") === 0) {
$url = "https://weval-consulting.com" . substr($t["api"], 5);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(["message" => $msg, "task" => $msg]),
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => false
]);
$r = curl_exec($ch);
$d = @json_decode($r, true);
if ($d) return ["content" => json_encode($d, JSON_PRETTY_PRINT), "tool" => $t["id"], "source" => "dynamic-resolver"];
}
}
return null; // No match — let LLM handle
}

View File

@@ -457,7 +457,7 @@ function opus_extra_intents($msg, $base) {
return array_merge($base,["content"=>"VAULT: $cnt GOLDs\nRecent:\n$recent"]);
}
// NONREG
if(preg_match("/nonreg|non.*reg/iu",$msg)){
if(preg_match("/nonreg|non.*reg/iu",$msg) && !preg_match("/lance|run|execute|start/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";}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,200 @@
[
{
"id": "scan",
"kw": "scan|audit|diagnostic",
"api": "shell",
"cmd": "df -h / | tail -1 && docker ps -q 2>/dev/null | wc -l && cat /proc/loadavg"
},
{
"id": "docker",
"kw": "docker|container",
"api": "shell",
"cmd": "docker ps --format '{{.Names}}: {{.Status}}' 2>/dev/null | head -20"
},
{
"id": "git-status",
"kw": "git status",
"api": "shell",
"cmd": "cd /var/www/html && git status --short | head -10"
},
{
"id": "git-push",
"kw": "git push",
"api": "shell",
"cmd": "cd /var/www/html && git push gitea main --force 2>&1 | tail -3"
},
{
"id": "crons",
"kw": "cron|crontab",
"api": "shell",
"cmd": "crontab -l -u www-data 2>/dev/null | grep -cv '^#'"
},
{
"id": "ethica-stats",
"kw": "ethica.*stat|combien.*medecin|hcp",
"api": "url",
"url": "https://weval-consulting.com/api/ethica-stats.php"
},
{
"id": "ethica-spec",
"kw": "specialite|top.*medecin|segmente",
"api": "shell",
"cmd": "PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -t -c \"SELECT spec_list, COUNT(*) FROM ethica.hcp_summary WHERE spec_list IS NOT NULL GROUP BY spec_list ORDER BY count DESC LIMIT 15\""
},
{
"id": "ethica-pays",
"kw": "medecin.*pays|hcp.*pays",
"api": "shell",
"cmd": "PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -t -c \"SELECT pays, COUNT(*) FROM ethica.hcp_summary GROUP BY pays ORDER BY count DESC\""
},
{
"id": "ethica-ville",
"kw": "medecin.*ville|hcp.*ville",
"api": "shell",
"cmd": "PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -t -c \"SELECT ville, COUNT(*) FROM ethica.hcp_summary WHERE ville IS NOT NULL GROUP BY ville ORDER BY count DESC LIMIT 15\""
},
{
"id": "ollama",
"kw": "ollama|modele.*local",
"api": "shell",
"cmd": "curl -s http://localhost:11435/api/tags 2>/dev/null | python3 -c \"import sys,json;[print(m['name']) for m in json.load(sys.stdin).get('models',[])]\" 2>&1"
},
{
"id": "growth",
"kw": "growth|revenue|pipeline",
"api": "url",
"url": "https://weval-consulting.com/api/growth-engine-api.php?action=status"
},
{
"id": "oss",
"kw": "oss|discovery|wire",
"api": "url",
"url": "https://weval-consulting.com/api/oss-discovery-api.php"
},
{
"id": "seo",
"kw": "seo|referencement",
"api": "url",
"url": "https://weval-consulting.com/api/growth-engine-api.php?action=seo_audit"
},
{
"id": "pages",
"kw": "combien.*page|architecture",
"api": "shell",
"cmd": "find /var/www/html -maxdepth 2 -name '*.html' | wc -l"
},
{
"id": "ssl",
"kw": "ssl|certificat",
"api": "shell",
"cmd": "echo|openssl s_client -servername weval-consulting.com -connect 127.0.0.1:443 2>/dev/null|openssl x509 -noout -enddate"
},
{
"id": "nginx",
"kw": "nginx",
"api": "shell",
"cmd": "sudo nginx -t 2>&1 | tail -1"
},
{
"id": "n8n",
"kw": "n8n|workflow",
"api": "shell",
"cmd": "docker ps --filter name=n8n --format '{{.Names}}: {{.Status}}' 2>/dev/null || echo N8N_DOWN"
},
{
"id": "qdrant",
"kw": "qdrant|vector",
"api": "shell",
"cmd": "curl -s http://localhost:6333/collections 2>/dev/null | python3 -c \"import sys,json;[print(c['name']) for c in json.load(sys.stdin).get('result',{}).get('collections',[])]\" 2>&1"
},
{
"id": "cleanup",
"kw": "clean|nettoi|purge",
"api": "shell",
"cmd": "docker system prune -f 2>/dev/null; df -h / | tail -1"
},
{
"id": "blade-status",
"kw": "blade.*status|razer",
"api": "shell",
"cmd": "cat /var/www/html/api/blade-tasks/heartbeat.json 2>/dev/null"
},
{
"id": "l99",
"kw": "l99.*coverage|l99.*test",
"api": "shell",
"cmd": "ls -t /opt/weval-l99/logs/l99-*.json 2>/dev/null | head -1 | xargs python3 -c \"import sys,json;d=json.load(open(sys.argv[1]));print('PASS:',d.get('pass','?'),'TOTAL:',d.get('total','?'))\" 2>&1"
},
{
"id": "agents",
"kw": "agents?.*vivant|agents?.*live",
"api": "shell",
"cmd": "echo Paperclip:$(curl -so /dev/null -w '%{http_code}' http://127.0.0.1:3201/api/health --max-time 3) SearXNG:$(curl -so /dev/null -w '%{http_code}' http://localhost:8888/ --max-time 3)"
},
{
"id": "providers",
"kw": "provider|cascade",
"api": "shell",
"cmd": "echo CASCADE: Groq Cerebras SambaNova Mistral NVIDIA Ollama = 0EUR"
},
{
"id": "webchat",
"kw": "webchat|playwright",
"api": "shell",
"cmd": "curl -s http://localhost:8902/health --max-time 3 2>/dev/null || echo DOWN"
},
{
"id": "disk",
"kw": "disk|espace|disque",
"api": "shell",
"cmd": "df -h / | tail -1"
},
{
"id": "paperclip",
"kw": "paperclip",
"api": "shell",
"cmd": "curl -s http://127.0.0.1:3201/api/health --max-time 3 2>/dev/null || echo DOWN"
},
{
"id": "twenty",
"kw": "twenty|crm",
"api": "shell",
"cmd": "curl -so /dev/null -w '%{http_code}' http://127.0.0.1:3000 --max-time 3"
},
{
"id": "dns",
"kw": "dns|domaine",
"api": "shell",
"cmd": "dig +short weval-consulting.com"
},
{
"id": "load",
"kw": "load|charge|cpu",
"api": "shell",
"cmd": "cat /proc/loadavg"
},
{
"id": "memory",
"kw": "ram|memoire|memory",
"api": "shell",
"cmd": "free -h | head -2"
},
{
"id": "dark-scout",
"kw": "dark.*scout|veille|concurrent",
"api": "url",
"url": "https://weval-consulting.com/api/growth-engine-api.php?action=dark_scout&q=email+pharma"
},
{
"id": "gitea",
"kw": "gitea|repo",
"api": "shell",
"cmd": "curl -s 'http://localhost:3300/api/v1/repos/search?limit=5' -H 'Authorization: token 9ce6ca77bbfb7b9e669d659de441e4c648879d25' 2>/dev/null | python3 -c \"import sys,json;print(len(json.load(sys.stdin).get('data',[])),'repos')\" 2>&1"
},
{
"id": "nonreg",
"kw": "nonreg|regression",
"api": "shell",
"cmd": "curl -s https://weval-consulting.com/api/wevia-master-api.php -X POST -H 'Content-Type: application/json' -d '{\"message\":\"nonreg\",\"session\":\"tool\"}' -k --max-time 15 | python3 -c \"import sys,json;print(json.load(sys.stdin).get('content','')[:50])\" 2>&1"
}
]

View File

@@ -140,7 +140,7 @@ function wevia_wave200($msg, $base) {
$sigma = $dpmo < 4 ? "6" : ($dpmo < 233 ? "5" : ($dpmo < 6210 ? "4" : "3"));
return array_merge($base, ['content' => "LEAN 6SIGMA: DPMO $dpmo | Sigma $sigma | NR " . ($nr['pass']??"?") . "/" . ($nr['total']??"?")]);
}
if (preg_match('/nonreg|non.*reg/iu', $msg)) {
if (preg_match('/nonreg|non.*reg/iu', $msg) && !preg_match('/lance|run|execute|start/iu', $msg)) {
$nr = @json_decode(@file_get_contents("/var/www/html/api/nonreg-latest.json"), true);
return array_merge($base, ['content' => "NONREG: " . ($nr['pass']??"?") . "/" . ($nr['total']??"?") . " (" . ($nr['score']??"?") . "%)"]);
}