Repository Public Research preview
1"""Append-only experiment registry (JSON lines). One record per run status change."""2from __future__ import annotations34import json5from pathlib import Path6from typing import Any78from wp_ai_0001.instrumentation.provenance import PROJECT_ROOT, utc_now910REGISTRY_PATH = PROJECT_ROOT / "experiments" / "registry" / "runs.jsonl"111213def record(run_id: str, experiment_id: str, status: str, **fields: Any) -> None:14 REGISTRY_PATH.parent.mkdir(parents=True, exist_ok=True)15 rec = {"utc": utc_now(), "run_id": run_id, "experiment_id": experiment_id, "status": status, **fields}16 with open(REGISTRY_PATH, "a") as f:17 f.write(json.dumps(rec, sort_keys=True, default=str) + "\n")181920def load() -> list[dict[str, Any]]:21 if not REGISTRY_PATH.exists():22 return []23 return [json.loads(line) for line in REGISTRY_PATH.read_text().splitlines() if line.strip()]24