File size: 3,617 Bytes
44dc2da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Minimal public validator for an OpenAI-compatible skill folder."""

from __future__ import annotations

import re
import sys
from pathlib import Path
from urllib.parse import unquote

import yaml


def fail(message: str) -> None:
    print(f"ERROR: {message}", file=sys.stderr)
    raise SystemExit(1)


def main() -> None:
    if len(sys.argv) != 2:
        fail("usage: quick_validate.py <skill-folder>")

    skill_dir = Path(sys.argv[1])
    skill_file = skill_dir / "SKILL.md"
    if not skill_file.is_file():
        fail("SKILL.md is missing")

    text = skill_file.read_text(encoding="utf-8")
    match = re.match(r"\A---\r?\n(.*?)\r?\n---\r?\n", text, re.DOTALL)
    if not match:
        fail("SKILL.md must begin with YAML frontmatter")

    data = yaml.safe_load(match.group(1))
    if not isinstance(data, dict):
        fail("frontmatter must be a mapping")
    if set(data) != {"name", "description"}:
        fail("frontmatter must contain only name and description")

    name = data.get("name")
    if not isinstance(name, str) or not re.fullmatch(r"[a-z0-9-]{1,64}", name):
        fail("name must use lowercase letters, digits, and hyphens")
    if skill_dir.name != name:
        fail("folder name must match skill name")

    description = data.get("description")
    if not isinstance(description, str) or not description.strip():
        fail("description must be a non-empty string")

    required = [
        "agents/openai.yaml",
        "references/agent-runbook.md",
        "scripts/install-shortcut.ps1",
        "scripts/pair-android-wireless.ps1",
        "scripts/start-agent-phone-use.ps1",
        "scripts/start-hidden.vbs",
    ]
    missing = [relative for relative in required if not (skill_dir / relative).is_file()]
    if missing:
        fail("required files are missing: " + ", ".join(missing))

    forbidden = [path.name for path in skill_dir.iterdir() if path.name.lower() == "readme.md"]
    if forbidden:
        fail("README.md belongs at the repository root, not inside the skill")

    interface_data = yaml.safe_load((skill_dir / "agents/openai.yaml").read_text(encoding="utf-8"))
    interface = interface_data.get("interface") if isinstance(interface_data, dict) else None
    if not isinstance(interface, dict):
        fail("agents/openai.yaml must contain an interface mapping")
    for key in ("display_name", "short_description", "default_prompt"):
        if not isinstance(interface.get(key), str) or not interface[key].strip():
            fail(f"agents/openai.yaml is missing interface.{key}")

    markdown_link = re.compile(r"\[[^\]]+\]\(([^)]+)\)")
    for markdown_file in skill_dir.rglob("*.md"):
        markdown_text = markdown_file.read_text(encoding="utf-8")
        if "TODO" in markdown_text or "[TODO" in markdown_text:
            fail(f"unfinished TODO in {markdown_file.relative_to(skill_dir)}")
        for raw_target in markdown_link.findall(markdown_text):
            target = raw_target.strip("<>")
            if re.match(r"^(?:https?://|mailto:|#)", target):
                continue
            path_text = unquote(target.split("#", 1)[0])
            if not path_text:
                continue
            resolved = (markdown_file.parent / path_text).resolve()
            if not resolved.exists():
                fail(
                    f"broken relative link in {markdown_file.relative_to(skill_dir)}: {target}"
                )

    print("Skill is valid!")


if __name__ == "__main__":
    main()