quick_validate.py raw
1 #!/usr/bin/env python3
2 """
3 Quick validation script for skills - minimal version
4 """
5
6 import sys
7 import os
8 import re
9 from pathlib import Path
10
11 def validate_skill(skill_path):
12 """Basic validation of a skill"""
13 skill_path = Path(skill_path)
14
15 # Check SKILL.md exists
16 skill_md = skill_path / 'SKILL.md'
17 if not skill_md.exists():
18 return False, "SKILL.md not found"
19
20 # Read and validate frontmatter
21 content = skill_md.read_text()
22 if not content.startswith('---'):
23 return False, "No YAML frontmatter found"
24
25 # Extract frontmatter
26 match = re.match(r'^---\n(.*?)\n---', content, re.DOTALL)
27 if not match:
28 return False, "Invalid frontmatter format"
29
30 frontmatter = match.group(1)
31
32 # Check required fields
33 if 'name:' not in frontmatter:
34 return False, "Missing 'name' in frontmatter"
35 if 'description:' not in frontmatter:
36 return False, "Missing 'description' in frontmatter"
37
38 # Extract name for validation
39 name_match = re.search(r'name:\s*(.+)', frontmatter)
40 if name_match:
41 name = name_match.group(1).strip()
42 # Check naming convention (hyphen-case: lowercase with hyphens)
43 if not re.match(r'^[a-z0-9-]+$', name):
44 return False, f"Name '{name}' should be hyphen-case (lowercase letters, digits, and hyphens only)"
45 if name.startswith('-') or name.endswith('-') or '--' in name:
46 return False, f"Name '{name}' cannot start/end with hyphen or contain consecutive hyphens"
47
48 # Extract and validate description
49 desc_match = re.search(r'description:\s*(.+)', frontmatter)
50 if desc_match:
51 description = desc_match.group(1).strip()
52 # Check for angle brackets
53 if '<' in description or '>' in description:
54 return False, "Description cannot contain angle brackets (< or >)"
55
56 return True, "Skill is valid!"
57
58 if __name__ == "__main__":
59 if len(sys.argv) != 2:
60 print("Usage: python quick_validate.py <skill_directory>")
61 sys.exit(1)
62
63 valid, message = validate_skill(sys.argv[1])
64 print(message)
65 sys.exit(0 if valid else 1)