Files
weval-l99/v135_intent.py
2026-04-24 04:38:58 +02:00

59 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""V135 - Add 'screens health' intent to wevia-opus46-intents.php
Reads /var/www/html/api/screens-health.json and returns summary via chat.
"""
path = "/var/www/html/api/wevia-opus46-intents.php"
with open(path, "r", encoding="utf-8") as f:
c = f.read()
if "V135-SCREENS-HEALTH" in c:
print("ALREADY")
exit(0)
# Find a safe anchor: the first intent start ("// INTENT: css_overlap_fix")
# Insert new intent BEFORE it (so triggers early in pipeline)
anchor = ' // INTENT: css_overlap_fix'
intent_code = ''' // INTENT: screens_health · V135-SCREENS-HEALTH
if (preg_match("/\\\\b(screens?\\\\s*health|pages?\\\\s*cass[eé]es|broken\\\\s*pages?|health\\\\s*scan|platform\\\\s*health)\\\\b/iu", $m)) {
$json_path = "/var/www/html/api/screens-health.json";
if (!file_exists($json_path)) {
return ["provider"=>"opus46","content"=>"SCREENS HEALTH: scan non disponible (/api/screens-health.json absent). Lance le cron de scan.","tool"=>"screens_health"];
}
$d = json_decode(file_get_contents($json_path), true);
if (!$d || !isset($d["counts"])) {
return ["provider"=>"opus46","content"=>"SCREENS HEALTH: JSON illisible.","tool"=>"screens_health"];
}
$c = $d["counts"];
$total = $d["total"] ?? 0;
$ts = $d["generated_at"] ?? "n/a";
$summary = "SCREENS HEALTH (scan {$ts}, total {$total} URLs):\\n";
$summary .= " UP: " . ($c["UP"] ?? 0) . "\\n";
$summary .= " SLOW: " . ($c["SLOW"] ?? 0) . "\\n";
$summary .= " BROKEN: " . ($c["BROKEN"] ?? 0) . "\\n";
$summary .= " DOWN: " . ($c["DOWN"] ?? 0) . "\\n";
$summary .= " PHANTOM: " . ($c["PHANTOM"] ?? 0) . "\\n";
// List first 10 broken URLs
$broken = [];
foreach (($d["by_url"] ?? []) as $url => $info) {
$st = $info["status"] ?? "";
if ($st === "BROKEN" || $st === "DOWN") {
$broken[] = " - " . $st . " " . ($info["code"] ?? "?") . " " . $url;
if (count($broken) >= 10) break;
}
}
if ($broken) {
$summary .= "\\nBroken/Down (top 10):\\n" . implode("\\n", $broken);
}
return ["provider"=>"opus46","content"=>$summary,"tool"=>"screens_health"];
}
'''
assert anchor in c, "anchor css_overlap_fix missing"
c = c.replace(anchor, intent_code + anchor, 1)
with open(path, "w", encoding="utf-8") as f:
f.write(c)
print(f"PATCHED size={len(c)}")