#!/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}") # Monorepo root hygiene & cross-doc consistency monorepo = ROOT.parent forbidden_files = ( ".cleanup-github-only.sh", ".finalize-remaining.sh", ".finalize-report.txt", ".finalize-workflow.sh", ".finish-cleanup.sh", ".gh-push-switch-request", "hf/.publish-request", "hf/_do_publish.py", "hf/_publish_inline.py", "hf/_run_publish_and_push.sh", "studies/models/registry.yaml", "studies/models/kimi-k3/reference/facts.yaml", "studies/.github/workflows/check.yml", ) for rel in forbidden_files: if (monorepo / rel).exists(): errors.append(f"hygiene: obsolete/scratch file present: {rel}") ci_wf = monorepo / ".github" / "workflows" / "check.yml" if not ci_wf.exists(): errors.append("hygiene: missing root .github/workflows/check.yml") elif "pip install" in ci_wf.read_text(encoding="utf-8"): errors.append("hygiene: .github/workflows/check.yml must not use pip install") # Every registered model must be referenced in top-level docs model_ids = [p.name for p in packages] for doc_rel in ( "README.md", "START_HERE.md", "OFFLINE.md", "CITATION.cff", "CHECKLIST.md", "index.html", "hf/dataset/README.md", "hf/space/index.html", ): doc_path = monorepo / doc_rel if not doc_path.exists(): errors.append(f"hygiene: missing {doc_rel}") continue content = doc_path.read_text(encoding="utf-8").lower() for mid in model_ids: short = mid.split("-")[0] if mid not in content and short not in content: errors.append(f"{doc_rel}: missing model reference for '{mid}'") ds_readme = (monorepo / "hf" / "dataset" / "README.md").read_text(encoding="utf-8") if "studies/models/inkling|kimi-k3/" in ds_readme: errors.append("hf/dataset/README.md: contents tree omits laguna-s-2.1") if "Poolside" not in ds_readme.split("## limitations")[-1]: errors.append("hf/dataset/README.md: limitations section omits Poolside") # Check relative links in authored markdown and HTML files import re for md_path in sorted(monorepo.rglob("*.md")): if any(part in md_path.parts for part in (".git", ".hf-stage", "reference")): continue text = md_path.read_text(encoding="utf-8", errors="ignore") for m in re.finditer(r"\[([^\]]*)\]\(([^)]+)\)", text): target = m.group(2).split("#")[0].strip() if not target or target.startswith(("http://", "https://", "mailto:")): continue if not (md_path.parent / target).resolve().exists(): rel_src = md_path.relative_to(monorepo) errors.append(f"broken link in {rel_src}: {target}") for html_path in sorted(monorepo.rglob("*.html")): if any(part in html_path.parts for part in (".git", ".hf-stage")): continue text = html_path.read_text(encoding="utf-8", errors="ignore") for m in re.finditer(r'href="([^"]+)"', text): target = m.group(1).split("#")[0].strip() if not target or target.startswith(("http://", "https://", "mailto:")): continue if not (html_path.parent / target).resolve().exists(): rel_src = html_path.relative_to(monorepo) errors.append(f"broken link in {rel_src}: {target}") # Check STUDY.md ordered list numbering in Laguna section study_md = ROOT / "STUDY.md" if study_md.exists(): s_txt = study_md.read_text(encoding="utf-8") if "8. [code-study/04-chat-and-tools.md]" in s_txt and "\n7. benches + limits:" in s_txt: errors.append("STUDY.md: out-of-order list item '7. benches + limits' after item 8") 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())