File size: 1,411 Bytes
4a9362b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import json
import os
from pathlib import Path
from typing import Any
from e_jepa_ttc.artifacts.hashing import verify_artifact_hash
def get_repo_root() -> Path:
return Path(__file__).resolve().parent.parent.parent.parent
def load_frozen_protocol() -> dict[str, Any]:
"""
Loads the frozen protocol from artifacts/audit/recovery_v3/frozen_protocol.json.
Raises ValueError if it doesn't exist or if its signature is invalid.
"""
override = os.environ.get("E_JEPA_TTC_FROZEN_PROTOCOL")
frozen_path = (
Path(override).resolve()
if override
else get_repo_root() / "artifacts" / "audit" / "recovery_v3" / "frozen_protocol.json"
)
if not frozen_path.exists():
raise FileNotFoundError(
f"Frozen protocol not found at {frozen_path}. Run scripts/freeze_protocol.py first."
)
with open(frozen_path, encoding="utf-8") as f:
data = json.load(f)
if not verify_artifact_hash(data):
raise ValueError("Frozen protocol signature mismatch (artifact_sha256).")
return data
def get_current_protocol_identity() -> tuple[str, str]:
"""
Returns (protocol_version, protocol_sha256) from the frozen protocol.
Used by all producers to ensure they reference a verified, static protocol.
"""
protocol = load_frozen_protocol()
return protocol["protocol_version"], protocol["protocol_sha256"]
|