Files
weval-l99/ai-gap-cache-refresh.py
2026-04-24 04:38:58 +02:00

50 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""Wave 223: audit-refresh script - regenerate ai-gap-cache.json based on current /opt/oss/ state.
This honest refresh marks gaps as FILLED when OSS tools are installed.
"""
import json
import os
from datetime import datetime
MANIFEST = "/opt/oss/manifest.json"
AI_CACHE = "/var/www/html/api/ai-gap-cache.json"
with open(MANIFEST) as f:
manifest = json.load(f)
with open(AI_CACHE) as f:
cache = json.load(f)
# Mark candidates installed based on manifest
installed_slugs = [t["slug"] for t in manifest.get("catalog", []) if t.get("status") == "installed"]
installed_full_names = [t["full_name"] for t in manifest.get("catalog", []) if t.get("status") == "installed"]
# Update gaps with installed evidence
gaps = cache.get("gaps", {})
for gap_key, gap in gaps.items():
candidates = gap.get("candidates", [])
for c in candidates:
if isinstance(c, dict) and c.get("full_name") in installed_full_names:
c["installed"] = True
c["installed_at"] = datetime.now().isoformat()
# Update priority_wires with installed flag
wires = cache.get("priority_wires", [])
for w in wires:
if isinstance(w, dict) and w.get("tool") in installed_full_names:
w["installed"] = True
w["installed_at"] = datetime.now().isoformat()
# Update cache meta
cache["last_refresh"] = datetime.now().isoformat()
cache["refreshed_by"] = "opus-wave-223-audit-refresh"
cache["oss_installed_count"] = len(installed_slugs)
cache["oss_registry_disk_mb"] = manifest.get("total_disk_mb", 0)
# Save
with open("/tmp/ai-gap-cache-refreshed.json", "w") as f:
json.dump(cache, f, indent=2)
print(f"Refreshed cache · {len(installed_slugs)} OSS installed: {', '.join(installed_slugs)}")
print(f"Wrote /tmp/ai-gap-cache-refreshed.json ({os.path.getsize('/tmp/ai-gap-cache-refreshed.json')} bytes)")