← back to AgentAbrams

snippets/validate_skills.py

56 lines

#!/usr/bin/env python3
"""
validate_skills.py — validate that skills/*.json files conform to Claude tool schema.

Checks for required top-level keys: name, description, input_schema.
"""

from __future__ import annotations

import json
import sys
from pathlib import Path

REQUIRED_TOP_LEVEL = {"name", "description", "input_schema"}


def main() -> int:
    skills_dir = Path("skills")
    if not skills_dir.exists():
        print("No skills/ directory found; nothing to validate.")
        return 0

    files = sorted(skills_dir.glob("*.json"))
    if not files:
        print("No .json files in skills/; nothing to validate.")
        return 0

    failed = False
    for p in files:
        try:
            obj = json.loads(p.read_text(encoding="utf-8"))
        except Exception as e:
            print(f"FAIL {p}: invalid JSON: {e}")
            failed = True
            continue

        missing = REQUIRED_TOP_LEVEL - set(obj.keys())
        if missing:
            print(f"FAIL {p}: missing keys: {sorted(missing)}")
            failed = True
            continue

        schema = obj.get("input_schema")
        if not isinstance(schema, dict) or schema.get("type") != "object":
            print(f"FAIL {p}: input_schema must have type='object'")
            failed = True
            continue

        print(f"OK   {p}")

    return 1 if failed else 0


if __name__ == "__main__":
    raise SystemExit(main())