File size: 7,361 Bytes
0bcd139 2353a55 0bcd139 2353a55 0bcd139 a71b406 0bcd139 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | #!/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())
|