#!/usr/bin/env python3 """Generate document-graph object records from the object matrix.""" from __future__ import annotations import hashlib import json from pathlib import Path ROOT = Path(__file__).resolve().parents[1] source_path = ROOT / "docs/p6/object-contract-matrix.json" rows = json.loads(source_path.read_text(encoding="utf-8"))["records"] selected = [row for row in rows if row["adapterFamily"] == "document-graph"] output = {"schema": "freecad-web-document-graph-runtime-index/v1", "source": {"matrix": "docs/p6/object-contract-matrix.json", "matrixSha256": hashlib.sha256(source_path.read_bytes()).hexdigest()}, "count": len(selected), "records": [{"id": row["id"], "module": row["module"], "objectType": row["name"], "status": row["status"], "capabilities": row["capabilities"]} for row in selected], "boundaries": ["browser graph state is separate from native object/link execution", "cycles and unsupported links return structured errors"]} out = ROOT / "web/public/api/document-graph-runtime-index.json" out.parent.mkdir(parents=True, exist_ok=True) out.write_text(json.dumps(output, ensure_ascii=False, separators=(",", ":")) + "\n", encoding="utf-8") print(json.dumps({"output": str(out.relative_to(ROOT)), "count": len(selected), "bytes": out.stat().st_size, "sha256": hashlib.sha256(out.read_bytes()).hexdigest()}, ensure_ascii=False))