#!/usr/bin/env python3
from __future__ import annotations
import json
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
SITE = ROOT / "site"
PROOF_ID = "rsi-capability-governance-twin-proof"

REQUIRED_PAGE_SNIPPETS = [
    "Skills Used",
    "Governance Twin Construction",
    "Policy-as-Code Compilation",
    "Permission Boundary Mapping",
    "Shadow Route Simulation",
    "Verifier Coverage Allocation",
    "Policy Violation Detection",
    "Rollback Path Planning",
    "Incident Counterfactual Replay",
    "SLA Stress Testing",
    "Control Plane Release Gating",
    "Executive Twin Receipt Rendering",
]

def require(path: Path, snippet: str | None = None) -> None:
    if not path.exists():
        raise SystemExit(f"Missing required file: {path}")
    if snippet and snippet not in path.read_text(encoding="utf-8", errors="ignore"):
        raise SystemExit(f"Missing snippet {snippet!r} in {path}")

def main() -> None:
    page=SITE/f"{PROOF_ID}.html"
    require(page, "Capability Governance Twin")
    for snippet in REQUIRED_PAGE_SNIPPETS:
        require(page, snippet)
    require(SITE/"data"/f"{PROOF_ID}.json", "PASSED_AUTONOMOUS_RSI_CAPABILITY_GOVERNANCE_TWIN_PROOF")
    require(SITE/"docs"/f"{PROOF_ID}.md", "Autonomous RSI Capability Governance Twin Proof")
    require(SITE/"badges"/f"{PROOF_ID}.svg", "capability governance twin")
    require(SITE/"index.html", PROOF_ID)
    require(SITE/"proof-registry.json", PROOF_ID)
    raw=json.loads((SITE/"proof-registry.json").read_text(encoding="utf-8"))
    proofs=raw.get("proofs",[]) if isinstance(raw,dict) else raw
    if not any(isinstance(p,dict) and p.get("id")==PROOF_ID for p in proofs):
        raise SystemExit("Proof registry does not contain capability governance twin proof")
    print(json.dumps({"status":"SITE_VERIFIED","proof":PROOF_ID,"skills_display_verified":True}, indent=2))

if __name__=="__main__":
    main()
