#!/usr/bin/env python3 """Phase 0 entrypoint: run Gate 0, write the report, HALT. Usage: python run_phase0.py [configs/phase0.yaml] Reads HF_TOKEN from the environment (or the vault .env via load_env) for the manifest download. Never prints or persists the token. """ from __future__ import annotations import os import sys from pathlib import Path import yaml ROOT = Path(__file__).resolve().parent sys.path.insert(0, str(ROOT)) from eval.gates import run_gate0, write_report # noqa: E402 def load_env_token() -> None: """Load HF_TOKEN from the vault .env if not already set. Token is never logged.""" if os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN"): return env_path = ROOT.parent / ".env" if env_path.exists(): for line in env_path.read_text().splitlines(): line = line.strip() if line.startswith("HF_TOKEN") and "=" in line: val = line.split("=", 1)[1].strip().strip('"').strip("'") os.environ["HF_TOKEN"] = val os.environ["HUGGING_FACE_HUB_TOKEN"] = val break def main() -> int: cfg_path = sys.argv[1] if len(sys.argv) > 1 else str(ROOT / "configs" / "phase0.yaml") with open(cfg_path) as f: cfg = yaml.safe_load(f) load_env_token() report = run_gate0(cfg) out = write_report(report, cfg["gate0"]["report_path"]) print(f"\n=== Gate 0: {report['status']} ===") for m in report["metrics"]: flag = "PASS" if m["passed"] else ("GAP" if m["name"] == "token_bank_size" else "FAIL") print(f" [{flag}] {m['name']}: {m['detail']}") if report["data_gaps"]: print(" data gaps:") for g in report["data_gaps"]: print(f" - {g}") print(f"\nReport written to {out}") print("HALT. A human must set human_signoff='GO' before Phase 1.") return 0 if __name__ == "__main__": raise SystemExit(main())