61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Generate skills_index.json from all skills in the repository.
|
|
"""
|
|
|
|
import os
|
|
import json
|
|
import re
|
|
|
|
def generate_index(skills_dir, output_file):
|
|
print(f"generating index from: {skills_dir}\n")
|
|
skills = []
|
|
|
|
for entry in sorted(os.listdir(skills_dir)):
|
|
skill_path = os.path.join(skills_dir, entry)
|
|
skill_file = os.path.join(skill_path, "SKILL.md")
|
|
|
|
if not os.path.isdir(skill_path) or not os.path.exists(skill_file):
|
|
continue
|
|
|
|
with open(skill_file, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
skill_info = {
|
|
"id": entry,
|
|
"name": entry.replace("-", " ").title(),
|
|
"description": "",
|
|
"path": f"skills/{entry}"
|
|
}
|
|
|
|
# Extract from frontmatter
|
|
fm_match = re.search(r'^---\s*\n(.*?)\n---', content, re.DOTALL)
|
|
if fm_match:
|
|
fm_content = fm_match.group(1)
|
|
|
|
name_match = re.search(r'^name:\s*(.+)$', fm_content, re.MULTILINE)
|
|
if name_match:
|
|
skill_info["name"] = name_match.group(1).strip()
|
|
|
|
desc_match = re.search(r'^description:\s*(.+)$', fm_content, re.MULTILINE)
|
|
if desc_match:
|
|
skill_info["description"] = desc_match.group(1).strip()
|
|
|
|
skills.append(skill_info)
|
|
print(f" {skill_info['id']}: {skill_info['description'][:60]}...")
|
|
|
|
# Write index
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
json.dump(skills, f, indent=2)
|
|
|
|
print(f"\ngenerated index with {len(skills)} skills at: {output_file}")
|
|
return skills
|
|
|
|
|
|
if __name__ == "__main__":
|
|
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
skills_path = os.path.join(base_dir, "skills")
|
|
output_path = os.path.join(base_dir, "skills_index.json")
|
|
|
|
generate_index(skills_path, output_path)
|