File size: 2,322 Bytes
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
#!/usr/bin/env python3
"""Sync root README status section from derived/STATUS.json."""
from __future__ import annotations

import json
import re
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]
README = ROOT / "README.md"
STATUS = ROOT / "derived" / "STATUS.json"

START = "<!-- status:start -->"
END = "<!-- status:end -->"


def build_block(status: dict) -> str:
    # Minimal Bellard-style list; full table lives in derived/DASHBOARD.md
    lines = [START, ""]
    for m in status.get("models") or []:
        active = m.get("active_params")
        if active is None:
            active = "undisclosed"
        total = m.get("total_params") or "?"
        lines.append(
            f"- [`{m['model_id']}`](models/{m['model_id']}/) — {m['display_name']}: "
            f"{total} / {active}, status `{m['status']}`"
        )
    lines += [
        "",
        f"[full table](derived/DASHBOARD.md) · {status.get('generated_at_utc', '')}",
        "",
        END,
    ]
    return "\n".join(lines)


def main() -> int:
    if not STATUS.exists():
        print("missing derived/STATUS.json — run make dashboard first", file=sys.stderr)
        return 1
    if not README.exists():
        return 0
    text = README.read_text()
    # Bellard-style READMEs have no status anchors — leave them alone
    if START not in text and "## Status" not in text:
        print("README has no status anchors — skip")
        return 0
    status = json.loads(STATUS.read_text())
    block = build_block(status)
    if START in text and END in text:
        new = re.sub(
            re.escape(START) + r".*?" + re.escape(END),
            block,
            text,
            count=1,
            flags=re.S,
        )
    else:
        # insert after first ## Status heading if present
        if "## Status" in text:
            new = re.sub(
                r"(## Status\n)",
                r"\1\n" + block + "\n",
                text,
                count=1,
            )
        else:
            new = text.rstrip() + "\n\n## Status\n\n" + block + "\n"

    if new != text:
        README.write_text(new)
        print("✓ README status section synced")
    else:
        print("README status already current")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())