validate-package.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python3
  2. """Check Humanizer's package files without external dependencies."""
  3. from __future__ import annotations
  4. import json
  5. import re
  6. from pathlib import Path
  7. ROOT = Path(__file__).resolve().parent.parent
  8. SKILL = (ROOT / "SKILL.md").read_text(encoding="utf-8")
  9. README = (ROOT / "README.md").read_text(encoding="utf-8")
  10. AGENTS = (ROOT / "AGENTS.md").read_text(encoding="utf-8")
  11. PLUGIN = json.loads((ROOT / ".claude-plugin" / "plugin.json").read_text(encoding="utf-8"))
  12. PLUGIN_SKILL = ROOT / "skills" / "humanizer" / "SKILL.md"
  13. def require_match(match: re.Match[str] | None, message: str) -> re.Match[str]:
  14. if match is None:
  15. raise SystemExit(message)
  16. return match
  17. yaml_metadata = require_match(
  18. re.match(r"\A---\n(.*?)\n---\n", SKILL, re.DOTALL),
  19. "SKILL.md must begin with YAML metadata",
  20. ).group(1)
  21. for unsupported_field in ("compatibility:", "allowed-tools:"):
  22. if re.search(rf"(?m)^{re.escape(unsupported_field)}", yaml_metadata):
  23. raise SystemExit(f"Remove unsupported YAML field: {unsupported_field[:-1]}")
  24. skill_version = require_match(
  25. re.search(r'(?m)^\s+version:\s*["\']([^"\']+)["\']\s*$', yaml_metadata),
  26. "Add metadata.version to SKILL.md",
  27. ).group(1)
  28. readme_version = require_match(
  29. re.search(r"(?m)^- \*\*([0-9]+\.[0-9]+\.[0-9]+)\*\*", README),
  30. "Add a version entry to README.md",
  31. ).group(1)
  32. package_versions = {skill_version, readme_version, str(PLUGIN.get("version", ""))}
  33. if len(package_versions) != 1:
  34. raise SystemExit(
  35. f"Use one package version in all files: {sorted(package_versions)}"
  36. )
  37. if not PLUGIN_SKILL.is_symlink():
  38. raise SystemExit("Link skills/humanizer/SKILL.md to the root SKILL.md")
  39. if PLUGIN_SKILL.resolve() != (ROOT / "SKILL.md").resolve():
  40. raise SystemExit("Make skills/humanizer/SKILL.md point to the root SKILL.md")
  41. plain_language_rules = (
  42. "## Writing style",
  43. "Lead with the main point.",
  44. "Use common words and active voice.",
  45. "Keep sentences and paragraphs short.",
  46. "Use `must` for requirements.",
  47. "Keep the full technical meaning.",
  48. )
  49. missing_plain_language_rules = [
  50. rule for rule in plain_language_rules if rule not in AGENTS
  51. ]
  52. if missing_plain_language_rules:
  53. raise SystemExit(
  54. "Add the missing Plain Language rules to AGENTS.md: "
  55. + ", ".join(missing_plain_language_rules)
  56. )
  57. pattern_numbers = [
  58. int(number)
  59. for number in re.findall(r"(?m)^### ([0-9]+)\. ", SKILL)
  60. ]
  61. if pattern_numbers != list(range(1, 36)):
  62. raise SystemExit(f"Number SKILL.md patterns from 1 through 35: {pattern_numbers}")
  63. readme_numbers = {
  64. int(number) for number in re.findall(r"(?m)^\| ([0-9]+) \|", README)
  65. }
  66. if readme_numbers != set(range(1, 36)):
  67. raise SystemExit("List patterns 1 through 35 in the README table")
  68. if len(SKILL.splitlines()) > 500:
  69. raise SystemExit("Keep SKILL.md at 500 lines or fewer")
  70. print(f"Humanizer package v{skill_version} is valid")