"""Check a skill directory has valid frontmatter and no dangling references.
Usage: check_skill.py <skill-dir>
print("Usage: check_skill.py <skill-dir>", file=sys.stderr)
skill_dir = Path(sys.argv[1])
skill_md = skill_dir / "SKILL.md"
if not skill_md.exists():
print(f"❌ no SKILL.md found in {skill_dir}")
text = skill_md.read_text(encoding="utf-8")
fm = re.match(r"^---\n(.*?)\n---\n", text, re.DOTALL)
print("❌ no YAML frontmatter found")
frontmatter = fm.group(1)
name_match = re.search(r"^name:\s*(.+)$", frontmatter, re.MULTILINE)
desc_match = re.search(r"^description:\s*(.+)$", frontmatter, re.MULTILINE | re.DOTALL)
print("❌ frontmatter missing 'name'")
elif name_match.group(1).strip() != skill_dir.name:
print(f"❌ frontmatter name '{name_match.group(1).strip()}' does not match directory name '{skill_dir.name}'")
print(f"✅ name matches directory: {skill_dir.name}")
print("❌ frontmatter missing 'description'")
desc_len = len(desc_match.group(1))
print(f"❌ description is {desc_len} chars — too long to trigger reliably, tighten it")
print(f"✅ description present ({desc_len} chars)")
referenced = re.findall(r"`(references/[\w./-]+|scripts/[\w./-]+|templates/[\w./-]+)`", text)
missing = [r for r in referenced if not (skill_dir / r).exists()]
print(f"❌ SKILL.md references path(s) that don't exist on disk: {missing}")
print(f"✅ all {len(referenced)} referenced references/scripts/templates paths exist")
if __name__ == "__main__":