$url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => $timeout, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTPHEADER => ["Host: weval-consulting.com"] ]); $body = curl_exec($ch); curl_close($ch); return $body ? json_decode($body, true) : null; } function safe_json($path) { if (!is_readable($path)) return null; return json_decode(@file_get_contents($path), true); } if ($action === "summary") { $dormants = http_json_internal("http://127.0.0.1/api/oss-discovery.php?k=WEVADS2026&action=dormants"); $skills = http_json_internal("http://127.0.0.1/api/oss-discovery.php?k=WEVADS2026&action=skills"); $registry = safe_json("/var/www/html/api/wevia-tool-registry.json"); $tools = $registry["tools"] ?? $registry ?? []; $products = glob("/var/www/html/products/*.html") ?: []; $stubs = array_merge(glob("/var/www/html/api/agent-stubs/agent_*.php") ?: [], glob("/var/www/html/api/agent-stubs-v57/*.php") ?: []); $wiki_v = glob("/var/www/html/wiki/V*.md") ?: []; $doctrines = glob("/opt/obsidian-vault/doctrines/*") ?: []; echo json_encode([ "ok" => true, "version" => "V75-orchestration", "ts" => date("c"), "dormants" => [ "total" => $dormants["total"] ?? 0, "by_status" => $dormants["by_status"] ?? [], "top_needs" => array_slice($dormants["by_need"] ?? [], 0, 10, true) ], "skills" => [ "total" => $skills["total"] ?? 0, "active" => $skills["active"] ?? 0, "dormant" => $skills["dormant"] ?? 0 ], "tools" => [ "total" => count($tools), "resolvers" => count(array_filter($tools, function($t){ return isset($t["id"]); })) ], "products" => [ "total_pages" => count($products), "sample" => array_slice(array_map(function($p){return basename($p, ".html");}, $products), 0, 10) ], "agent_stubs" => count($stubs), "wiki" => count($wiki_v), "doctrines" => count($doctrines), "grand_total_assets" => count($tools) + ($skills["total"] ?? 0) + ($dormants["total"] ?? 0) + count($products) + count($stubs) ], JSON_PRETTY_PRINT); exit; } if ($action === "dormants") { $d = http_json_internal("http://127.0.0.1/api/oss-discovery.php?k=WEVADS2026&action=dormants"); if (!$d) { echo json_encode(["ok" => false, "error" => "dormants api down"]); exit; } $result = [ "ok" => true, "total" => $d["total"] ?? 0, "by_status" => $d["by_status"] ?? [], "by_need" => $d["by_need"] ?? [], "priority_order" => [] ]; // Rank by need count (most needed first) $by_need = $d["by_need"] ?? []; arsort($by_need); foreach ($by_need as $need => $count) { $result["priority_order"][] = ["need" => $need, "count" => $count]; } echo json_encode($result, JSON_PRETTY_PRINT); exit; } if ($action === "skills") { $s = http_json_internal("http://127.0.0.1/api/oss-discovery.php?k=WEVADS2026&action=skills"); if (!$s) { echo json_encode(["ok" => false, "error" => "skills api down"]); exit; } // Get skills list if available $skills_list = http_json_internal("http://127.0.0.1/api/oss-discovery.php?k=WEVADS2026&action=list&limit=" . $limit); echo json_encode([ "ok" => true, "total" => $s["total"] ?? 0, "active" => $s["active"] ?? 0, "dormant" => $s["dormant"] ?? 0, "sample" => array_slice($skills_list["skills"] ?? [], 0, 20), "activation_rate" => round(100.0 * ($s["active"] ?? 0) / max(1, $s["total"] ?? 1), 2) . "%" ], JSON_PRETTY_PRINT); exit; } if ($action === "tools") { $registry = safe_json("/var/www/html/api/wevia-tool-registry.json"); $tools = $registry["tools"] ?? $registry ?? []; $by_prefix = []; foreach ($tools as $t) { if (!isset($t["id"])) continue; $id = $t["id"]; $prefix = explode("_", $id)[0]; $by_prefix[$prefix] = ($by_prefix[$prefix] ?? 0) + 1; } arsort($by_prefix); $sample = []; if ($filter) { foreach ($tools as $t) { if (!isset($t["id"])) continue; if (stripos($t["id"], $filter) !== false) { $sample[] = ["id" => $t["id"], "kw" => substr($t["kw"] ?? "", 0, 80)]; if (count($sample) >= $limit) break; } } } else { $sample = array_slice(array_map(function($t){ return ["id" => $t["id"] ?? "?", "kw" => substr($t["kw"] ?? "", 0, 80)]; }, array_filter($tools, function($t){ return isset($t["id"]); })), 0, 20); } echo json_encode([ "ok" => true, "total_tools" => count($tools), "by_prefix" => $by_prefix, "sample" => $sample, "filter" => $filter ], JSON_PRETTY_PRINT); exit; } if ($action === "products") { $products = glob("/var/www/html/products/*.html") ?: []; $names = array_map(function($p){ return basename($p, ".html"); }, $products); sort($names); if ($filter) { $names = array_values(array_filter($names, function($n) use ($filter) { return stripos($n, $filter) !== false; })); } echo json_encode([ "ok" => true, "total" => count($products), "matched" => count($names), "filter" => $filter, "products" => array_slice($names, 0, $limit) ], JSON_PRETTY_PRINT); exit; } if ($action === "wire") { // WEVIA Master command: WIRE all assets under unified catalog // Returns a manifest of everything WEVIA controls $dormants = http_json_internal("http://127.0.0.1/api/oss-discovery.php?k=WEVADS2026&action=dormants"); $skills = http_json_internal("http://127.0.0.1/api/oss-discovery.php?k=WEVADS2026&action=skills"); $mega = http_json_internal("http://127.0.0.1/api/wevia-mega-agents.php?action=counts"); $registry = safe_json("/var/www/html/api/wevia-tool-registry.json"); $tools = $registry["tools"] ?? $registry ?? []; $products = glob("/var/www/html/products/*.html") ?: []; $stubs = array_merge(glob("/var/www/html/api/agent-stubs/agent_*.php") ?: [], glob("/var/www/html/api/agent-stubs-v57/*.php") ?: []); $wiki_v = glob("/var/www/html/wiki/V*.md") ?: []; $doctrines = glob("/opt/obsidian-vault/doctrines/*") ?: []; echo json_encode([ "ok" => true, "version" => "V75-wire-manifest", "ts" => date("c"), "wevia_master_controls" => [ "agents" => [ "structured" => $mega["total_aggregated"] ?? 0, "declared_live" => $mega["manifest_total_live"] ?? 0, "sources" => count($mega["by_source"] ?? []) ], "skills" => [ "total" => $skills["total"] ?? 0, "active" => $skills["active"] ?? 0 ], "dormants" => [ "total" => $dormants["total"] ?? 0, "prioritizable" => array_sum($dormants["by_need"] ?? []) ], "tools_resolvers" => count($tools), "product_pages" => count($products), "agent_stubs" => count($stubs), "wiki_V_files" => count($wiki_v), "doctrines" => count($doctrines) ], "grand_total" => [ "addressable" => ($mega["total_aggregated"] ?? 0) + ($skills["total"] ?? 0) + ($dormants["total"] ?? 0) + count($tools) + count($products) + count($stubs) ], "endpoints_for_chat" => [ "summary" => "/api/wevia-orchestration-v75.php?action=summary", "dormants" => "/api/wevia-orchestration-v75.php?action=dormants", "skills" => "/api/wevia-orchestration-v75.php?action=skills", "tools" => "/api/wevia-orchestration-v75.php?action=tools&filter=XXX", "products" => "/api/wevia-orchestration-v75.php?action=products&filter=XXX", "wire" => "/api/wevia-orchestration-v75.php?action=wire" ] ], JSON_PRETTY_PRINT); exit; } echo json_encode(["ok" => false, "error" => "unknown action", "valid" => ["summary","dormants","skills","tools","products","wire"]]);