File size: 2,247 Bytes
9ec4919
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Ensure README resource entries carry a visible resource type label."""

from __future__ import annotations

import argparse
import re
import sys
from pathlib import Path


RESOURCE_SECTIONS = {
    "Canonical Definition",
    "Concept Guides",
    "Maintainer Picks",
    "Start Here",
    "Core Loop Primitives",
    "Official Runtime Guides",
    "Research Foundations",
    "Agent Workflow Patterns",
    "Coding-Agent Loop Systems",
    "Verification And Feedback Gates",
    "Securing Unattended Loops",
    "State, Memory, And Context Persistence",
    "Orchestration And Multi-Agent Delegation",
    "Benchmarks And Evaluation",
    "Operations Playbooks",
    "Templates And Patterns",
    "Examples And Schema",
    "Community Gallery",
    "Pattern Library",
    "Discovery And Distribution",
    "Roadmap And Discussion",
    "Critiques, Risks, And Limitations",
    "Adjacent Awesome Lists",
}

LABEL_RE = re.compile(
    r"^- (📄|📝|📚|🧰|🧪|🔁|🧾|🧭|⚠️) "
    r"\*\*(Paper|Blog|Docs|Tool|Benchmark|Pattern|Template|List|Critique)\*\* "
)


def check_readme(path: Path) -> list[tuple[int, str]]:
    failures: list[tuple[int, str]] = []
    current_section = ""

    for line_number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
        if line.startswith("## "):
            current_section = line.removeprefix("## ").strip()
            continue

        if current_section not in RESOURCE_SECTIONS:
            continue

        if not line.startswith("- "):
            continue

        if "](http" not in line and "](" not in line:
            continue

        if not LABEL_RE.match(line):
            failures.append((line_number, line))

    return failures


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("readme", type=Path, default=Path("README.md"), nargs="?")
    args = parser.parse_args()

    failures = check_readme(args.readme)
    if not failures:
        return 0

    print("Resource entries missing type labels:", file=sys.stderr)
    for line_number, line in failures:
        print(f"- line {line_number}: {line}", file=sys.stderr)
    return 1


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