#!/usr/bin/env python3 """Enforce monorepo package contract for every models/*/ directory with a Makefile.""" from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] MODELS = ROOT / "models" REQUIRED_PATHS = [ "README.md", "Makefile", "book", "code-study", "reference", "derived/summary.json", "scripts/generate_derived.py", "scripts/validate.py", # refresh is online-only; not required for offline contract ] REQUIRED_SUMMARY_KEYS = [ "model_id", "display_name", "status", "context_tokens", "generated_at_utc", ] def main() -> int: import json errors: list[str] = [] packages = sorted(p for p in MODELS.iterdir() if p.is_dir() and (p / "Makefile").exists()) if not packages: print("ERROR: no model packages found") return 1 for pkg in packages: mid = pkg.name for rel in REQUIRED_PATHS: if not (pkg / rel).exists(): errors.append(f"{mid}: missing {rel}") summary_path = pkg / "derived" / "summary.json" if summary_path.exists(): try: s = json.loads(summary_path.read_text()) except json.JSONDecodeError as e: errors.append(f"{mid}: invalid summary.json ({e})") continue for k in REQUIRED_SUMMARY_KEYS: if k not in s: errors.append(f"{mid}: summary.json missing key '{k}'") if s.get("model_id") not in (None, mid) and s.get("model_id") != mid: errors.append(f"{mid}: summary.model_id={s.get('model_id')!r} != dir name") # monorepo dashboard present after check if not (ROOT / "derived" / "DASHBOARD.md").exists(): errors.append("monorepo: missing derived/DASHBOARD.md (run make dashboard)") # comparison notes for registered packages if (MODELS / "inkling").exists() and (MODELS / "kimi-k3").exists(): cmp_path = ROOT / "shared" / "comparisons" / "inkling-vs-kimi-k3.md" if not cmp_path.exists(): errors.append("missing shared/comparisons/inkling-vs-kimi-k3.md") if ( (MODELS / "laguna-s-2.1").exists() and (MODELS / "inkling").exists() and (MODELS / "kimi-k3").exists() ): tri = ROOT / "shared" / "comparisons" / "laguna-s-vs-inkling-vs-kimi.md" if not tri.exists(): errors.append("missing shared/comparisons/laguna-s-vs-inkling-vs-kimi.md") # Laguna-specific contract (weights + chat stack) lag = MODELS / "laguna-s-2.1" if lag.exists() and (lag / "Makefile").exists(): for rel in ( "reference/hub/config.json", "reference/hub/chat_template.jinja", "reference/hub/tokenizer_config.json", "reference/hub/generation_config.json", "reference/laguna-code/modeling_laguna.py", "derived/special_tokens.md", "derived/param_accounting.md", "code-study/04-chat-and-tools.md", ): if not (lag / rel).exists(): errors.append(f"laguna-s-2.1: missing {rel}") if errors: for e in errors: print(f"ERROR: {e}") print(f"\npackage check FAILED ({len(errors)} errors)") return 1 print(f"package check OK ({len(packages)} models)") return 0 if __name__ == "__main__": raise SystemExit(main())