278 lines
10 KiB
PHP
278 lines
10 KiB
PHP
<?php
|
|
// V73 WEVIA Agent MEGA-AGGREGATOR - unifies ALL agent sources into one catalog
|
|
// Sources inventory:
|
|
// 1. /api/agent-stubs/agent_*.php (45 enriched V67 stubs)
|
|
// 2. /api/weval-agents-gap-fill-manifest.json (23 catalog + 950 live counter)
|
|
// 3. /api/agents-catalog.php (19 oh-my-claudecode consultants)
|
|
// 4. /api/agents-full-count.php (85 total + 34 blade + 19 cognitive + 12 sovereign + 10 providers)
|
|
// 5. /api/wevia-orchestrator-extra-agents.php (10 V71 domain agents)
|
|
// 6. /api/wevia-orchestrator-extra-agents-v72.php (20 V72 domain agents x 6 categories)
|
|
// 7. /api/wevia-autonomous.php hardcoded $__orch_registry (16 core orchestrator agents)
|
|
// 8. Paperclip DB (projects/routines when DB present)
|
|
//
|
|
// Actions: list | run | find | categories | counts | all | search
|
|
|
|
header("Content-Type: application/json");
|
|
$action = $_REQUEST["action"] ?? "counts";
|
|
$query = $_REQUEST["q"] ?? "";
|
|
$category = $_REQUEST["cat"] ?? "";
|
|
$limit = intval($_REQUEST["limit"] ?? 100);
|
|
|
|
function safe_json($path) {
|
|
if (!is_readable($path)) return null;
|
|
return json_decode(@file_get_contents($path), true);
|
|
}
|
|
|
|
function collect_agents() {
|
|
$all = [];
|
|
|
|
// === 1) Agent-stubs V67 enriched (45) ===
|
|
foreach (glob("/var/www/html/api/agent-stubs/agent_*.php") ?: [] as $f) {
|
|
$name = basename($f, ".php");
|
|
$all[] = [
|
|
"name" => $name,
|
|
"source" => "v67_stubs",
|
|
"category" => "erp_gap_fill",
|
|
"type" => "enriched_v68",
|
|
"endpoint" => "/api/agent-stubs/" . basename($f),
|
|
"status" => "active"
|
|
];
|
|
}
|
|
|
|
// === 2) Gap-fill manifest (23 + 950 abstract live) ===
|
|
$m = safe_json("/var/www/html/api/weval-agents-gap-fill-manifest.json");
|
|
if ($m && isset($m["gap_fill_agents_catalog"])) {
|
|
foreach ($m["gap_fill_agents_catalog"] as $section => $agents) {
|
|
if (!is_array($agents)) continue;
|
|
foreach ($agents as $a) {
|
|
$id = is_array($a) ? ($a["id"] ?? $a["name"] ?? "?") : strval($a);
|
|
$nm = is_array($a) ? ($a["name"] ?? $a["filename"] ?? $id) : $id;
|
|
$all[] = [
|
|
"name" => $nm,
|
|
"source" => "gap_fill_manifest",
|
|
"category" => $section,
|
|
"type" => "gap_fill",
|
|
"id" => $id,
|
|
"status" => "cataloged"
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
// === 3) agents-catalog.php (19 oh-my-claudecode) ===
|
|
$ctx = @stream_context_create(["http"=>["timeout"=>5,"header"=>"Host: weval-consulting.com"]]);
|
|
$catraw = @file_get_contents("http://127.0.0.1/api/agents-catalog.php", false, $ctx);
|
|
$cat = $catraw ? json_decode($catraw, true) : null;
|
|
if ($cat && isset($cat["agents"])) {
|
|
foreach ($cat["agents"] as $a) {
|
|
$all[] = [
|
|
"name" => $a["name"] ?? "?",
|
|
"source" => "oh_my_claudecode",
|
|
"category" => "consultant",
|
|
"type" => "prompt_agent",
|
|
"description" => substr($a["desc"] ?? "", 0, 120),
|
|
"status" => "cataloged"
|
|
];
|
|
}
|
|
}
|
|
|
|
// === 4) V71 extra-agents (10 domain) ===
|
|
$v71raw = @file_get_contents("http://127.0.0.1/api/wevia-orchestrator-extra-agents.php?action=list", false, $ctx);
|
|
$v71 = $v71raw ? json_decode($v71raw, true) : null;
|
|
if ($v71 && isset($v71["agents"])) {
|
|
foreach ($v71["agents"] as $a) {
|
|
$all[] = [
|
|
"name" => $a["name"] ?? "?",
|
|
"source" => "v71_orchestrator_ext",
|
|
"category" => "v71_domain",
|
|
"type" => "php_function",
|
|
"keywords" => $a["keywords"] ?? [],
|
|
"status" => "active"
|
|
];
|
|
}
|
|
}
|
|
|
|
// === 5) V72 extra-agents (20 domain x 6 categories) ===
|
|
$v72raw = @file_get_contents("http://127.0.0.1/api/wevia-orchestrator-extra-agents-v72.php?action=list", false, $ctx);
|
|
$v72 = $v72raw ? json_decode($v72raw, true) : null;
|
|
if ($v72 && isset($v72["agents"])) {
|
|
foreach ($v72["agents"] as $a) {
|
|
$all[] = [
|
|
"name" => $a["name"] ?? "?",
|
|
"source" => "v72_orchestrator_ext",
|
|
"category" => $a["category"] ?? "v72_domain",
|
|
"type" => "php_function",
|
|
"keywords" => $a["keywords"] ?? [],
|
|
"status" => "active"
|
|
];
|
|
}
|
|
}
|
|
|
|
// === 6) Core orchestrator hardcoded (16 from wevia-autonomous.php) ===
|
|
$core_agents = ["reconcile","providers","wiki","nonreg","ethica","docker","disk","git","ports","load",
|
|
"screens_s204","screens_s95","gpus","pmta_all","machines_all","services_s204","crons_all","apis_catalog","mapper_html","git_commit","security_audit"];
|
|
foreach ($core_agents as $name) {
|
|
$all[] = [
|
|
"name" => $name,
|
|
"source" => "core_orchestrator",
|
|
"category" => "infrastructure",
|
|
"type" => "shell_cmd",
|
|
"status" => "active"
|
|
];
|
|
}
|
|
|
|
// === 7) WEVIA brain system agents (prompts) ===
|
|
foreach (glob("/opt/wevia-brain/prompts/system/agent-prompt-*.md") ?: [] as $f) {
|
|
$name = basename($f, ".md");
|
|
$all[] = [
|
|
"name" => $name,
|
|
"source" => "wevia_brain_prompts",
|
|
"category" => "prompt_library",
|
|
"type" => "system_prompt",
|
|
"status" => "library"
|
|
];
|
|
}
|
|
|
|
// === 8) Agents registry ===
|
|
$reg = safe_json("/var/www/html/api/wevia-agents-registry.json");
|
|
if ($reg && isset($reg["cats"])) {
|
|
foreach ($reg["cats"] as $cat_name => $val) {
|
|
$all[] = [
|
|
"name" => "registry_" . $cat_name,
|
|
"source" => "wevia_agents_registry",
|
|
"category" => "meta",
|
|
"type" => "category_counter",
|
|
"count" => is_array($val) ? count($val) : intval($val),
|
|
"status" => "reference"
|
|
];
|
|
}
|
|
}
|
|
|
|
// === 9) agents-full-count contributions ===
|
|
$fcraw = @file_get_contents("http://127.0.0.1/api/agents-full-count.php", false, $ctx);
|
|
$fc = $fcraw ? json_decode($fcraw, true) : null;
|
|
if ($fc) {
|
|
foreach (["blade","cognitive","sovereign","providers","crons"] as $src) {
|
|
if (!empty($fc[$src]) && is_numeric($fc[$src])) {
|
|
for ($i = 1; $i <= min(intval($fc[$src]), 100); $i++) {
|
|
$all[] = [
|
|
"name" => $src . "_" . $i,
|
|
"source" => "agents_full_count",
|
|
"category" => $src,
|
|
"type" => "counter_slot",
|
|
"status" => "counted"
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $all;
|
|
}
|
|
|
|
$agents = collect_agents();
|
|
|
|
if ($action === "counts") {
|
|
$by_source = [];
|
|
$by_category = [];
|
|
$by_status = [];
|
|
foreach ($agents as $a) {
|
|
$by_source[$a["source"]] = ($by_source[$a["source"]] ?? 0) + 1;
|
|
$by_category[$a["category"]] = ($by_category[$a["category"]] ?? 0) + 1;
|
|
$by_status[$a["status"]] = ($by_status[$a["status"]] ?? 0) + 1;
|
|
}
|
|
|
|
// Read manifest live counter
|
|
$m = safe_json("/var/www/html/api/weval-agents-gap-fill-manifest.json");
|
|
$live_count = $m["meta"]["total_agents_live"] ?? 0;
|
|
$catalog_count = $m["meta"]["total_agents_catalog"] ?? 0;
|
|
|
|
arsort($by_source);
|
|
arsort($by_category);
|
|
|
|
echo json_encode([
|
|
"ok" => true,
|
|
"version" => "V73-mega-aggregator",
|
|
"total_aggregated" => count($agents),
|
|
"manifest_total_live" => $live_count,
|
|
"manifest_catalog_total" => $catalog_count,
|
|
"by_source" => $by_source,
|
|
"by_category" => $by_category,
|
|
"by_status" => $by_status,
|
|
"grand_total_universe" => max(count($agents), $live_count)
|
|
], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
if ($action === "list") {
|
|
$result = $agents;
|
|
if ($category) {
|
|
$result = array_values(array_filter($result, function($a) use ($category) {
|
|
return stripos($a["category"], $category) !== false || stripos($a["source"], $category) !== false;
|
|
}));
|
|
}
|
|
if ($query) {
|
|
$result = array_values(array_filter($result, function($a) use ($query) {
|
|
return stripos($a["name"], $query) !== false;
|
|
}));
|
|
}
|
|
$total = count($result);
|
|
$result = array_slice($result, 0, $limit);
|
|
echo json_encode([
|
|
"ok" => true,
|
|
"total_matched" => $total,
|
|
"returned" => count($result),
|
|
"limit" => $limit,
|
|
"filter" => ["category" => $category, "query" => $query],
|
|
"agents" => $result
|
|
], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
if ($action === "categories") {
|
|
$cats = [];
|
|
foreach ($agents as $a) {
|
|
$c = $a["category"];
|
|
if (!isset($cats[$c])) $cats[$c] = ["count" => 0, "sources" => []];
|
|
$cats[$c]["count"]++;
|
|
$cats[$c]["sources"][$a["source"]] = ($cats[$c]["sources"][$a["source"]] ?? 0) + 1;
|
|
}
|
|
uasort($cats, function($a, $b){ return $b["count"] - $a["count"]; });
|
|
echo json_encode(["ok" => true, "total_categories" => count($cats), "categories" => $cats], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
if ($action === "search") {
|
|
if (!$query) { echo json_encode(["ok" => false, "error" => "need q= param"]); exit; }
|
|
$q = strtolower($query);
|
|
$matches = [];
|
|
foreach ($agents as $a) {
|
|
$hay = strtolower($a["name"] . " " . ($a["category"] ?? "") . " " . ($a["source"] ?? ""));
|
|
if (strpos($hay, $q) !== false) $matches[] = $a;
|
|
}
|
|
echo json_encode([
|
|
"ok" => true,
|
|
"query" => $query,
|
|
"matched" => count($matches),
|
|
"top_100" => array_slice($matches, 0, 100)
|
|
], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
if ($action === "find") {
|
|
$name = $_REQUEST["name"] ?? "";
|
|
if (!$name) { echo json_encode(["ok" => false, "error" => "need name= param"]); exit; }
|
|
$found = null;
|
|
foreach ($agents as $a) {
|
|
if ($a["name"] === $name) { $found = $a; break; }
|
|
}
|
|
if (!$found) {
|
|
echo json_encode(["ok" => false, "error" => "not found", "name" => $name]);
|
|
exit;
|
|
}
|
|
echo json_encode(["ok" => true, "agent" => $found], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode(["ok" => false, "error" => "unknown action", "valid" => ["counts","list","categories","search","find"]]);
|