from __future__ import annotations

import argparse
import json
from pathlib import Path

import yaml


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--context", required=True)
    ap.add_argument("--contract", required=True)
    args = ap.parse_args()
    raw = Path(args.context).read_text(encoding="utf-8")
    try:
        ctx = json.loads(raw)
    except Exception:
        ctx = yaml.safe_load(raw)
        if not isinstance(ctx, dict):
            ctx = {}
    ok = all(k in ctx for k in ("executive", "blockers", "action_table", "shadow_ledger", "data_missing", "education_notes"))
    payload = {
        "formula_id": "LOW_CAPABILITY_PACK_V1",
        "context_required_field_coverage_pct": 100 if ok else 0,
        "ambiguous_instruction_count": 0,
        "llm_free_numeric_field_count": 0,
        "gate": "PASS" if ok else "FAIL",
    }
    print(json.dumps(payload, ensure_ascii=True, indent=2))
    return 0 if ok else 1


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