#!/usr/bin/env python3
from __future__ import annotations

import argparse
import json
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
REQUIRED = {
    "ops:validate",
    "ops:render",
    "ops:release",
    "ops:package",
    "ops:audit",
}


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--package", default="package.json")
    args = ap.parse_args()
    data = json.loads((ROOT / args.package).read_text(encoding="utf-8"))
    scripts = data.get("scripts") if isinstance(data, dict) else {}
    present = {k for k in REQUIRED if isinstance(scripts, dict) and k in scripts}
    ok = present == REQUIRED
    payload = {
        "formula_id": "OPERATOR_ENTRYPOINTS_V1",
        "gate": "PASS" if ok else "FAIL",
        "required_count": len(REQUIRED),
        "present_count": len(present),
        "missing": sorted(REQUIRED - present),
    }
    print(json.dumps(payload, ensure_ascii=True, indent=2))
    return 0 if ok else 1


if __name__ == "__main__":
    raise SystemExit(main())
