#!/usr/bin/env python3 """Independent re-read of /root/.hermes/profiles, compared to the triage census artifact. Exit 0 = the artifact matches a fresh filesystem read.""" import json import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from _gen_profile_census_v4 import classify # noqa: E402 PROFILES = "/root/.hermes/profiles" ART = os.path.join(os.path.dirname(os.path.abspath(__file__)), "triage-profile-census-2026-10-26.json") def fresh_read(): out = {"ACTIVE": 0, "STALE": 0, "PLACEHOLDER": 0, "total": 0, "by": {}} for n in sorted(os.listdir(PROFILES)): p = os.path.join(PROFILES, n) if not os.path.isdir(p): continue out["total"] += 1 status, _model, _how, _n, _d = classify(n, p) out["by"][n] = status out[status] += 1 return out def main(): fresh = fresh_read() with open(ART, encoding="utf-8") as fh: art = json.load(fh) ok = True for k in ("total", "ACTIVE", "STALE", "PLACEHOLDER"): if art.get(k) != fresh[k]: ok = False print("MISMATCH %s: artifact=%r fresh=%r" % (k, art.get(k), fresh[k])) if [e["name"] for e in art.get("entries", [])] != sorted(fresh["by"].keys()): ok = False print("MISMATCH entry names") print("fresh read: %s" % fresh) print("artifact: %s" % art) print("VERDICT: %s" % ("MATCH" if ok else "MISMATCH")) sys.exit(0 if ok else 1) if __name__ == "__main__": main()