"""One-time snapshot of reviewed reference data into the agent's own knowledge folder. python tools/import_reference_data.py The agent owns its reference data (typical ranges by level, drill library) so it can be improved without touching the pose pipeline. This script records where the first version came from; edit src/ai_coach/knowledge/*.yaml directly afterwards. """ import re import sys from pathlib import Path import yaml KNOWLEDGE = Path(__file__).resolve().parents[1] / "src" / "ai_coach" / "knowledge" LEVELS = ("hs_jv", "hs_varsity", "college") NOTE_CHARS = 220 def status_of(evidence: str | None) -> dict[str, str]: """Per-scope evidence status from the review's free-text label, e.g. 'CONFIRMED (college) / ADJUSTED (HS ...)'.""" if not evidence: return {"hs": "unverified", "college": "unverified"} result = {"hs": None, "college": None} for part in evidence.split("/"): word = "confirmed" if "CONFIRMED" in part else "adjusted" if "ADJUSTED" in part else "unverified" scopes = [s for s, key in (("college", "college"), ("hs", "hs")) if re.search(key, part, re.I)] for scope in scopes or ["hs", "college"]: result[scope] = result[scope] or word return {k: v or "unverified" for k, v in result.items()} def band(entry: dict, tolerance: float | None) -> list[float] | None: if "low" in entry: return [float(entry["low"]), float(entry["high"])] if "value" in entry: t = float(tolerance or 0) return [round(float(entry["value"]) - t, 2), round(float(entry["value"]) + t, 2)] return None def convert_ranges(src: dict) -> dict: out: dict = { "version": 2, "source": "snapshot of the metrics team's reference_ranges.yaml after the 2026-10 evidence review; most hitting " "entries and the HS pitching entries are NOT verified. Edit this file directly from now on.", } for discipline in ("hitting", "pitching"): out[discipline] = {} for key, m in src[discipline].items(): levels = m.get("levels") out[discipline][key] = { "unit": m["unit"], "comparable": m.get("comparable", True), "placeholder": bool(m.get("placeholder", False)), "status": status_of(m.get("evidence")), "levels": None if not levels else {lv: band(levels[lv], m.get("tolerance")) for lv in LEVELS}, "note": (m.get("note") or "")[:NOTE_CHARS], } return out def convert_drills(src: dict) -> dict: keep = ( "id", "name", "discipline", "faults", "equipment", "rep_scheme", "session_type", "instructions", "cue", "counts_toward_workload", "source", ) return {"version": 1, "drills": [{k: d[k] for k in keep if k in d} for d in src["drills"]]} if __name__ == "__main__": ranges_path, drills_path = (Path(p) for p in sys.argv[1:3]) (KNOWLEDGE / "ranges.yaml").write_text( "# Typical ranges by level (agent-owned). Bands are [low, high].\n" "# `levels: null` = no default band (a coach/org supplies one).\n" "# comparable: false = the source is a 3D/frontal quantity our side-view 2D proxy cannot match: reference only.\n" + yaml.safe_dump(convert_ranges(yaml.safe_load(ranges_path.read_text())), sort_keys=False, width=110) ) (KNOWLEDGE / "drills.yaml").write_text( "# Starter drill library (agent-owned). Draft: needs coach advisor review.\n" "# The agent may only recommend drills listed here.\n" + yaml.safe_dump(convert_drills(yaml.safe_load(drills_path.read_text())), sort_keys=False, width=110) ) print("knowledge/ranges.yaml and knowledge/drills.yaml written")