#!/usr/bin/env python3 """Autoverificação da skill cenaforge: caminhos citados existem, comandos pnpm existem e a versão do SKILL.md bate com o topo do CHANGELOG. Sai com 1 se houver problema. Uso: python .claude/skills/cenaforge/scripts/check_skill.py """ from __future__ import annotations import re from _common import REPO_ROOT, load_json, utf8_stdout SKILL = REPO_ROOT / ".claude" / "skills" / "cenaforge" TEMPORARY = {"godot/override.cfg"} ROOTS = ("godot/", "scripts/", "config/", "doc/", ".claude/") def main() -> int: utf8_stdout() files = [*SKILL.rglob("*.md"), *(REPO_ROOT / ".claude" / "agents").glob("cenaforge-*.md"), REPO_ROOT / "CLAUDE.md"] scripts = load_json(REPO_ROOT / "package.json")["scripts"] problems: list[str] = [] for f in files: name = f.relative_to(REPO_ROOT).as_posix() text = f.read_text(encoding="utf-8") for p in re.findall(r"`([^`\s]+)`", text): if not p.startswith(ROOTS) or any(c in p for c in "<*{") or p in TEMPORARY: continue if not (REPO_ROOT / p.split(":")[0]).exists(): problems.append(f"{name}: caminho inexistente `{p}`") for link in re.findall(r"\]\(([^)#\s]+)\)", text): if not link.startswith("http") and not (f.parent / link).exists(): problems.append(f"{name}: link quebrado ({link})") for cmd in re.findall(r"`pnpm (?:run )?([a-z][a-z:-]*)", text): if cmd not in scripts and cmd not in {"install", "exec"}: problems.append(f"{name}: comando inexistente `pnpm {cmd}`") skill_text = (SKILL / "SKILL.md").read_text(encoding="utf-8") version = re.search(r"Versão da skill: ([\d.]+)", skill_text) top = re.search(r"^## ([\d.]+)", (SKILL / "CHANGELOG.md").read_text(encoding="utf-8"), re.M) if not version or not top or version.group(1) != top.group(1): problems.append(f"versão do SKILL.md ({version and version.group(1)}) diferente do topo do CHANGELOG ({top and top.group(1)})") lines = len(skill_text.splitlines()) if lines > 220: problems.append(f"SKILL.md com {lines} linhas (meta: até ~200)") if problems: print("\n".join(problems)) return 1 print(f"skill ok (versão {version.group(1)}, SKILL.md com {lines} linhas, {len(files)} arquivos conferidos)") return 0 if __name__ == "__main__": raise SystemExit(main())