Files
troupe-standup/wizard-work/sol/gen_sol_profile_triage_2026-11-02.py

238 lines
8.2 KiB
Python

#!/usr/bin/env python3
"""Generate a sol-profile top-level triage artifact for /root/.hermes/profiles/sol.
Classifies every entry by deterministic rules, then writes a JSON artifact plus a
human-readable MD report and a re-deriving CHECK script, under both
/root/.hermes/wizard-outputs/sol/ and /root/troupe-standup/wizard-work/sol/.
"""
import datetime
import json
import os
import shutil
PROFILE = "/root/.hermes/profiles/sol"
WIZ = "/root/.hermes/wizard-outputs/sol"
REPO = "/root/troupe-standup/wizard-work/sol"
EXACT = {
"identity": {".env", ".env.bak-20261014T165715Z"},
"soul": {"SOUL.md"},
"config": {".env.lock", "config.yaml", "config.yaml.bak-20261014T165715Z"},
"state_db": {
"state.db", "state.db-shm", "state.db-wal", "state.db.auto-maintenance.lock",
"state.db.fts_rebuild.lock", "state.db.quarantine.lock", "auth.json",
"auth.lock", ".skills_prompt_snapshot.json", "models_dev_cache.json",
"models_dev_cache.etag",
},
"cache": {"cache", "audio_cache", "image_cache"},
"sessions": {"sessions"},
"skills": {"skills"},
"plugins": {"plugins", "plugin-update-checks"},
"logs": {"logs"},
"backups": {"backups"},
"vault": {"vault"},
}
def classify(name, is_dir):
for cat, names in EXACT.items():
if name in names:
return cat
if is_dir:
return "extension_dir"
if name.endswith(".py"):
return "script"
if name.endswith((".yaml", ".json")):
return "config_data"
return "other"
def main():
names = sorted(os.listdir(PROFILE))
entries = []
for name in names:
p = os.path.join(PROFILE, name)
entries.append({
"name": name,
"path": p,
"type": "dir" if os.path.isdir(p) else "file",
"category": classify(name, os.path.isdir(p)),
})
counts = {}
for e in entries:
counts[e["category"]] = counts.get(e["category"], 0) + 1
generated = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
artifact = {
"generated_utc": generated,
"profile": PROFILE,
"type": "sol-profile-triage",
"generated_for": "2026-11-02",
"total_entries": len(entries),
"categories": counts,
"entries": entries,
"rules": {
"identity": "exact name in identity set",
"soul": "exact name SOUL.md",
"config": "exact name in config set",
"state_db": "exact name in state_db set",
"cache": "exact name in cache set",
"sessions": "exact name in sessions set",
"skills": "exact name in skills set",
"plugins": "exact name in plugins set",
"logs": "exact name in logs set",
"backups": "exact name in backups set",
"vault": "exact name in vault set",
"extension_dir": "any directory",
"script": "name ends with .py",
"config_data": "name ends with .yaml or .json",
"other": "none of the above",
},
}
json_path = os.path.join(WIZ, "sol-profile-triage-2026-11-02.json")
os.makedirs(WIZ, exist_ok=True)
with open(json_path, "w", encoding="utf-8") as fh:
json.dump(artifact, fh, indent=2)
fh.write("\n")
md_lines = [
"# Sol profile triage - 2026-11-02",
"",
"Re-derived from the live profile dir " + PROFILE + ".",
"Generated (UTC): " + generated,
"Total entries on disk: " + str(artifact["total_entries"]),
"Category counts: " + json.dumps(counts, sort_keys=True),
"",
"## Entries",
"",
]
for e in entries:
md_lines.append("- **%s** (%s) -> %s" % (e["name"], e["type"], e["category"]))
md_lines.append("")
md_path = os.path.join(WIZ, "sol-profile-triage-2026-11-02.md")
with open(md_path, "w", encoding="utf-8") as fh:
fh.write("\n".join(md_lines))
# Reflect artifact into the repo.
for src, tag in ((json_path, "json"), (md_path, "md")):
dst = os.path.join(REPO, os.path.basename(src))
shutil.copyfile(src, dst)
# CHECK script (re-derives classification from the live profile).
check_content = r'''#!/usr/bin/env bash
# CHECK -- sol: sol-profile-triage-2026-11-02 re-derives the classification
# from the live profile dir and verifies the committed JSON against it on disk.
# Exit 0 iff the re-derived categories match BOTH committed artifacts.
set -u
python3 - <<'PY'
import datetime, json, os, sys
PROFILE = "/root/.hermes/profiles/sol"
EXACT = {
"identity": {".env", ".env.bak-20261014T165715Z"},
"soul": {"SOUL.md"},
"config": {".env.lock", "config.yaml", "config.yaml.bak-20261014T165715Z"},
"state_db": {
"state.db", "state.db-shm", "state.db-wal", "state.db.auto-maintenance.lock",
"state.db.fts_rebuild.lock", "state.db.quarantine.lock", "auth.json",
"auth.lock", ".skills_prompt_snapshot.json", "models_dev_cache.json",
"models_dev_cache.etag",
},
"cache": {"cache", "audio_cache", "image_cache"},
"sessions": {"sessions"},
"skills": {"skills"},
"plugins": {"plugins", "plugin-update-checks"},
"logs": {"logs"},
"backups": {"backups"},
"vault": {"vault"},
}
def classify(name, is_dir):
for cat, names in EXACT.items():
if name in names:
return cat
if is_dir:
return "extension_dir"
if name.endswith(".py"):
return "script"
if name.endswith((".yaml", ".json")):
return "config_data"
return "other"
def load(p):
with open(p, encoding="utf-8") as fh:
return json.load(fh)
def rederived():
exp = {}
for name in os.listdir(PROFILE):
cat = classify(name, os.path.isdir(os.path.join(PROFILE, name)))
exp[cat] = exp.get(cat, 0) + 1
return exp
fails = []
wiz_json = "/root/.hermes/wizard-outputs/sol/sol-profile-triage-2026-11-02.json"
repo_json = "/root/troupe-standup/wizard-work/sol/sol-profile-triage-2026-11-02.json"
if not os.path.isfile(wiz_json):
fails.append("missing wizard-outputs artifact: " + wiz_json)
if not os.path.isfile(repo_json):
fails.append("missing repo artifact: " + repo_json)
if fails:
print("FAIL"); [print(" -", f) for f in fails]; sys.exit(1)
if not os.path.isfile(wiz_json):
fails.append("missing committed wizard-outputs copy: " + wiz_json)
if not os.path.isfile(repo_json):
fails.append("missing committed repo copy: " + repo_json)
if fails:
print("FAIL"); [print(" -", f) for f in fails]; sys.exit(1)
disk = rederived()
for label, jpath in (("wizard-outputs", wiz_json), ("repo", repo_json)):
d = load(jpath)
if d.get("total_entries") != len(os.listdir(PROFILE)):
fails.append("[" + label + "] total_entries mismatch")
if d.get("categories") != disk:
fails.append("[" + label + "] categories mismatch (got %s, want %s)"
% (json.dumps(d.get("categories"), sort_keys=True),
json.dumps(disk, sort_keys=True)))
for e in d.get("entries", []):
if e.get("category") != classify(e["name"], e.get("type") == "dir"):
fails.append("[" + label + "] entry category mismatch: " + str(e.get("name")))
elif not os.path.lexists(e.get("path", "")):
fails.append("[" + label + "] referenced path no longer exists: " + str(e.get("path")))
print("PASS" if not fails else "FAIL")
for f in fails:
print(" -", f)
sys.exit(1 if fails else 0)
PY
EXIT=$?
if [ $EXIT -ne 0 ]; then
echo "CHECK FAILED (exit $EXIT)"
fi
exit $EXIT
'''
for tag in ("wiz", "repo"):
base = WIZ if tag == "wiz" else REPO
os.makedirs(base, exist_ok=True)
cp = os.path.join(base, "check_sol_profile_triage_2026-11-02.sh")
with open(cp, "w", encoding="utf-8") as fh:
fh.write(check_content)
os.chmod(cp, 0o755)
print("TOTAL", artifact["total_entries"])
print("CATEGORIES", json.dumps(counts, sort_keys=True))
print("WROTE", json_path)
print("WROTE_MD", md_path)
print("WROTE_WIZ_CHECK", os.path.join(WIZ, "check_sol_profile_triage_2026-11-02.sh"))
print("WROTE_REPO_CHECK", os.path.join(REPO, "check_sol_profile_triage_2026-11-02.sh"))
if __name__ == "__main__":
main()