model_hint.py
python
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
12 hours ago
| 1 | """Resolve reviewer model labels to provider hints (§K5.3).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from functools import lru_cache |
| 6 | from pathlib import Path |
| 7 | |
| 8 | import yaml |
| 9 | |
| 10 | from adapters.errors import ConfigError |
| 11 | |
| 12 | DEFAULT_KIT_ROOT = Path(__file__).resolve().parents[3] |
| 13 | |
| 14 | |
| 15 | @lru_cache(maxsize=4) |
| 16 | def _load_reviewer_model_hints(kit_root: str) -> dict[str, str]: |
| 17 | """Load ``reviewer_models[].id`` → ``cursor_model_hint`` from kit policy.""" |
| 18 | root = Path(kit_root) |
| 19 | path = root / "policy" / "model-labels.yaml" |
| 20 | if not path.is_file(): |
| 21 | raise ConfigError("reviewer model registry missing", str(path)) |
| 22 | raw = yaml.safe_load(path.read_text(encoding="utf-8")) |
| 23 | if not isinstance(raw, dict): |
| 24 | raise ConfigError("model-labels.yaml root must be a mapping", str(path)) |
| 25 | models = raw.get("reviewer_models") |
| 26 | if not isinstance(models, list) or not models: |
| 27 | raise ConfigError("reviewer_models must be a non-empty list", str(path)) |
| 28 | hints: dict[str, str] = {} |
| 29 | for entry in models: |
| 30 | if not isinstance(entry, dict): |
| 31 | raise ConfigError("reviewer_models entries must be mappings", str(path)) |
| 32 | model_id = entry.get("id") |
| 33 | hint = entry.get("cursor_model_hint") |
| 34 | if not isinstance(model_id, str) or not model_id.strip(): |
| 35 | raise ConfigError("reviewer_models[].id must be a non-empty string", str(path)) |
| 36 | if not isinstance(hint, str) or not hint.strip(): |
| 37 | raise ConfigError( |
| 38 | f"reviewer_models[{model_id!r}].cursor_model_hint must be a non-empty string", |
| 39 | str(path), |
| 40 | ) |
| 41 | hints[model_id] = hint.strip() |
| 42 | return hints |
| 43 | |
| 44 | |
| 45 | def resolve_model_hint(model_label: str, *, kit_root: Path | None = None) -> str: |
| 46 | """Return the cursor_model_hint for a reviewer model label.""" |
| 47 | root = kit_root or DEFAULT_KIT_ROOT |
| 48 | hints = _load_reviewer_model_hints(str(root.resolve())) |
| 49 | try: |
| 50 | return hints[model_label] |
| 51 | except KeyError as exc: |
| 52 | raise ConfigError( |
| 53 | f"unknown reviewer.model label {model_label!r} (allowed: {sorted(hints)})" |
| 54 | ) from exc |
File History
2 commits
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
12 hours ago
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439
feat: K1-P1 complete — agent provenance, build-verification…
Sonnet 4.6
patch
52 days ago