Setting the file. One moment. Quick Validate · Skill Creator · openai/skills · Skills Docs(opens in a new tab)
scripts/quick_validate.py
Python·101 lines·3 KB
16 """Basic validation of a skill"""
17 skill_path = Path(skill_path)
18
19 skill_md = skill_path / "SKILL.md"
20 if not skill_md.exists():
21 return False, "SKILL.md not found"
22
23 content = skill_md.read_text()
24 if not content.startswith("---"):
25 return False, "No YAML frontmatter found"
26
27 match = re.match(r"^---\n(.*?)\n---", content, re.DOTALL)
28 if not match:
29 return False, "Invalid frontmatter format"
30
31 frontmatter_text = match.group(1)
32
33 try:
34 frontmatter = yaml.safe_load(frontmatter_text)
35 if not isinstance(frontmatter, dict):
36 return False, "Frontmatter must be a YAML dictionary"
37 except yaml.YAMLError as e:
38 return False, f"Invalid YAML in frontmatter: {e}"
39
40 allowed_properties = {"name", "description", "license", "allowed-tools", "metadata"}
41
42 unexpected_keys = set(frontmatter.keys()) - allowed_properties
43 if unexpected_keys:
44 allowed = ", ".join(sorted(allowed_properties))
45 unexpected = ", ".join(sorted(unexpected_keys))
46 return (
47 False,
48 f"Unexpected key(s) in SKILL.md frontmatter: {unexpected}. Allowed properties are: {allowed}",
49 )
50
51 if "name" not in frontmatter:
52 return False, "Missing 'name' in frontmatter"
53 if "description" not in frontmatter:
54 return False, "Missing 'description' in frontmatter"
55
56 name = frontmatter.get("name", "")
57 if not isinstance(name, str):
58 return False, f"Name must be a string, got {type(name).__name__}"
59 name = name.strip()
60 if name:
61 if not re.match(r"^[a-z0-9-]+$", name):
62 return (
63 False,
64 f"Name '{name}' should be hyphen-case (lowercase letters, digits, and hyphens only)",
65 )
66 if name.startswith("-") or name.endswith("-") or "--" in name:
67 return (
68 False,
69 f"Name '{name}' cannot start/end with hyphen or contain consecutive hyphens",
70 )
71 if len(name) > MAX_SKILL_NAME_LENGTH:
72 return (
73 False,
74 f"Name is too long ({len(name)} characters). "
75 f"Maximum is {MAX_SKILL_NAME_LENGTH} characters.",
76 )
77
78 description = frontmatter.get("description", "")
79 if not isinstance(description, str):
80 return False, f"Description must be a string, got {type(description).__name__}"
81 description = description.strip()
82 if description:
83 if "<" in description or ">" in description:
84 return False, "Description cannot contain angle brackets (< or >)"
85 if len(description) > 1024:
86 return (
87 False,
88 f"Description is too long ({len(description)} characters). Maximum is 1024 characters.",
89 )
90
91 return True, "Skill is valid!"
92
93
94if __name__ == "__main__":
95 if len(sys.argv) != 2:
96 print("Usage: python quick_validate.py <skill_directory>")
97 sys.exit(1)
98
99 valid, message = validate_skill(sys.argv[1])
100 print(message)
101 sys.exit(0 if valid else 1)