File size: 3,463 Bytes
0bcd139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2353a55
0bcd139
 
 
 
2353a55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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())