"""Shared paths and provenance helpers for the M2 validation runs.""" from __future__ import annotations import hashlib import json from datetime import datetime, timedelta, timezone from pathlib import Path import yaml from volve_dia import paths CONFIG = paths.REPO_ROOT / "configs" VALIDATION = CONFIG / "m2_validation.yaml" PROTOCOL = CONFIG / "protocol_v1.yaml" def directory() -> Path: return paths.outputs_dir() / "audit" / "m2_300" def spec() -> dict: return yaml.safe_load(VALIDATION.read_text(encoding="utf-8")) def repeatability_gap() -> timedelta: protocol = yaml.safe_load(PROTOCOL.read_text(encoding="utf-8")) return timedelta(days=protocol["validation"]["llm_raters"]["audit_1"]["second_pass_after_days"]) def digest(path: Path) -> str: with path.open("rb") as stream: return hashlib.file_digest(stream, "sha256").hexdigest() def read_json(path: Path) -> dict: return json.loads(path.read_text(encoding="utf-8")) def write_json(path: Path, obj: dict) -> None: tmp = path.with_suffix(".tmp") tmp.write_text(json.dumps(obj, indent=2, ensure_ascii=False, allow_nan=False) + "\n", encoding="utf-8") tmp.replace(path) def utc_now() -> datetime: return datetime.now(timezone.utc)