from __future__ import annotations

import argparse
import json
from pathlib import Path

import yaml


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--packet", required=True)
    ap.add_argument("--out", required=True)
    args = ap.parse_args()
    packet = json.loads(Path(args.packet).read_text(encoding="utf-8"))
    context = {
        "formula_id": "FINAL_CONTEXT_FOR_LLM_V4",
        "executive": {"display_value": packet.get("meta", {}).get("builder_version", "UNKNOWN"), "source_key": "meta.builder_version"},
        "blockers": [],
        "action_table": [],
        "shadow_ledger": packet.get("shadow_ledger", {}),
        "data_missing": [],
        "education_notes": [],
    }
    Path(args.out).write_text(yaml.safe_dump(context, sort_keys=False, allow_unicode=True), encoding="utf-8")
    print(json.dumps({"formula_id": context["formula_id"], "section_count": 6}, ensure_ascii=True))
    return 0


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