#!/usr/bin/env python3
"""V139 - Truth Registry mini-strip under breadcrumb in Hub
Shows key counts (agents/intents/skills/brains/doctrines/dashboards) from source of truth.
Click → opens /wevia-unified-hub.html (HEXA-PIVOT 6th).
"""
import sys
src, dst = sys.argv[1], sys.argv[2]
with open(src, "r", encoding="utf-8") as f:
c = f.read()
if "V139-TRUTH-STRIP" in c:
print("ALREADY", file=sys.stderr)
sys.exit(0)
# Insert mini strip right AFTER the v130-xnav closing div and BEFORE modal + tabs
# Find the v130-xnav block end: right before '
strip_html = '''
🧠 Truth Registry
· ... agents
· ... intents
· ... skills
· ... brains
· ... doctrines
· ... dashboards
open Truth Hub →
''' + marker
if marker not in c:
print("marker missing", file=sys.stderr)
sys.exit(1)
c = c.replace(marker, strip_html, 1)
# Add JS fetcher (once, on load). Insert before __v135UpdateHealthBanner
js_marker = 'async function __v135UpdateHealthBanner('
js_add = '''/* V139-TRUTH-STRIP: load source of truth registry (fire once on load) */
async function __v139LoadTruthStrip(){
try {
const r = await fetch('/api/wevia-truth-registry.json', {cache: 'no-store'});
if (!r.ok) return;
const d = await r.json();
const setN = (id, n) => { const el = document.getElementById(id); if (el && n !== undefined) el.innerHTML = '· ' + Number(n).toLocaleString('fr-FR') + ' ' + id.replace('v139-',''); };
setN('v139-agents', d.agents?.count_unique);
setN('v139-intents', d.intents?.count);
setN('v139-skills', d.skills?.TOTAL);
setN('v139-brains', d.brains?.count);
setN('v139-doctrines', d.doctrines?.count);
setN('v139-dashboards', d.dashboards?.count);
} catch (_) {}
}
__v139LoadTruthStrip();
''' + js_marker
if js_marker in c:
c = c.replace(js_marker, js_add, 1)
with open(dst, "w", encoding="utf-8") as f:
f.write(c)
print(f"OK size={len(c)}", file=sys.stderr)