"""Shared filesystem roots for the static compilation pipeline.""" from __future__ import annotations from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[2] PROFILE_RESULTS_ROOT = PROJECT_ROOT / "results" / "static-opimization" / "profiles" MODEL_PREFERENCE_PROFILE_ROOT = PROFILE_RESULTS_ROOT / "model-preference" FINAL_PROFILE_ROOT = PROFILE_RESULTS_ROOT / "models" def model_path_parts(model_identifier: str) -> tuple[str, ...]: """Validate a provider-qualified model identifier for filesystem use.""" parts = tuple(model_identifier.strip().strip("/").split("/")) if len(parts) < 2 or any(part in {"", ".", ".."} for part in parts): raise ValueError( "model must use provider/model-id format without empty or relative segments" ) return parts def model_directory(root: Path, model_identifier: str) -> Path: return root.joinpath(*model_path_parts(model_identifier)) def model_profile_path(root: Path, model_identifier: str) -> Path: canonical = model_directory(root, model_identifier) / "profile.json" legacy = root / model_identifier.strip().strip("/").replace("/", "_") / "profile.json" return legacy if legacy.is_file() and not canonical.is_file() else canonical