labels.py
python
sha256:0e9549ec7b463911bc08b7d586dc320b1ac9b1f5c943ee7e3865dcc6cb0f6f83
chore(governance): sync handover+roadmap to 84db8c8 (drift:…
Human
1 day ago
| 1 | """Reviewer model label registry (§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 | VENDOR_SLUG_MARKERS = ("gpt-", "claude-", "composer-", "o1-", "o3-") |
| 13 | |
| 14 | |
| 15 | @lru_cache(maxsize=4) |
| 16 | def load_reviewer_model_ids(kit_root: Path) -> frozenset[str]: |
| 17 | """Load allowed ``reviewer_models[].id`` values from kit-carried policy.""" |
| 18 | path = kit_root / "policy" / "model-labels.yaml" |
| 19 | if not path.is_file(): |
| 20 | raise ConfigError("reviewer model registry missing", str(path)) |
| 21 | raw = yaml.safe_load(path.read_text(encoding="utf-8")) |
| 22 | if not isinstance(raw, dict): |
| 23 | raise ConfigError("model-labels.yaml root must be a mapping", str(path)) |
| 24 | models = raw.get("reviewer_models") |
| 25 | if not isinstance(models, list) or not models: |
| 26 | raise ConfigError("reviewer_models must be a non-empty list", str(path)) |
| 27 | ids: list[str] = [] |
| 28 | for entry in models: |
| 29 | if not isinstance(entry, dict): |
| 30 | raise ConfigError("reviewer_models entries must be mappings", str(path)) |
| 31 | model_id = entry.get("id") |
| 32 | if not isinstance(model_id, str) or not model_id.strip(): |
| 33 | raise ConfigError("reviewer_models[].id must be a non-empty string", str(path)) |
| 34 | ids.append(model_id) |
| 35 | return frozenset(ids) |
| 36 | |
| 37 | |
| 38 | def is_vendor_slug(model: str) -> bool: |
| 39 | """Return True when ``model`` looks like a vendor slug rather than a label.""" |
| 40 | lowered = model.lower() |
| 41 | return any(marker in lowered for marker in VENDOR_SLUG_MARKERS) |
| 42 | |
| 43 | |
| 44 | def validate_reviewer_model(model: str, kit_root: Path) -> None: |
| 45 | """Fail closed on vendor slugs or unknown labels.""" |
| 46 | if is_vendor_slug(model): |
| 47 | raise ConfigError( |
| 48 | f"reviewer.model must be a label from reviewer_models, not a vendor slug: {model!r}" |
| 49 | ) |
| 50 | allowed = load_reviewer_model_ids(kit_root) |
| 51 | if model not in allowed: |
| 52 | raise ConfigError( |
| 53 | f"unknown reviewer.model label {model!r} (allowed: {sorted(allowed)})" |
| 54 | ) |
File History
1 commit
sha256:6abcf1fa82a7a621ccbc945f19acdba5bc0db54569599404a1452fb4a096a199
fix(ISR): default require_independent_second_reviewer to require
Human
minor
⚠
1 day ago