Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Create, test, and iteratively improve Claude skills with eval benchmarks and description optimization
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/package_skill.py
1#!/usr/bin/env python32"""3Skill Packager - Creates a distributable .skill file of a skill folder45Usage:6python utils/package_skill.py <path/to/skill-folder> [output-directory]78Example:9python utils/package_skill.py skills/public/my-skill10python utils/package_skill.py skills/public/my-skill ./dist11"""1213import fnmatch14import sys15import zipfile16from pathlib import Path17from scripts.quick_validate import validate_skill1819# Patterns to exclude when packaging skills.20EXCLUDE_DIRS = {"__pycache__", "node_modules"}21EXCLUDE_GLOBS = {"*.pyc"}22EXCLUDE_FILES = {".DS_Store"}23# Directories excluded only at the skill root (not when nested deeper).24ROOT_EXCLUDE_DIRS = {"evals"}252627def should_exclude(rel_path: Path) -> bool:28"""Check if a path should be excluded from packaging."""29parts = rel_path.parts30if any(part in EXCLUDE_DIRS for part in parts):31return True32# rel_path is relative to skill_path.parent, so parts[0] is the skill33# folder name and parts[1] (if present) is the first subdir.34if len(parts) > 1 and parts[1] in ROOT_EXCLUDE_DIRS:35return True36name = rel_path.name37if name in EXCLUDE_FILES:38return True39return any(fnmatch.fnmatch(name, pat) for pat in EXCLUDE_GLOBS)404142def package_skill(skill_path, output_dir=None):43"""44Package a skill folder into a .skill file.4546Args:47skill_path: Path to the skill folder48output_dir: Optional output directory for the .skill file (defaults to current directory)4950Returns:51Path to the created .skill file, or None if error52"""53skill_path = Path(skill_path).resolve()5455# Validate skill folder exists56if not skill_path.exists():57print(f"โ Error: Skill folder not found: {skill_path}")58return None5960if not skill_path.is_dir():61print(f"โ Error: Path is not a directory: {skill_path}")62return None6364# Validate SKILL.md exists65skill_md = skill_path / "SKILL.md"66if not skill_md.exists():67print(f"โ Error: SKILL.md not found in {skill_path}")68return None6970# Run validation before packaging71print("๐ Validating skill...")72valid, message = validate_skill(skill_path)73if not valid:74print(f"โ Validation failed: {message}")75print(" Please fix the validation errors before packaging.")76return None77print(f"โ {message}\n")7879# Determine output location80skill_name = skill_path.name81if output_dir:82output_path = Path(output_dir).resolve()83output_path.mkdir(parents=True, exist_ok=True)84else:85output_path = Path.cwd()8687skill_filename = output_path / f"{skill_name}.skill"8889# Create the .skill file (zip format)90try:91with zipfile.ZipFile(skill_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:92# Walk through the skill directory, excluding build artifacts93for file_path in skill_path.rglob('*'):94if not file_path.is_file():95continue96arcname = file_path.relative_to(skill_path.parent)97if should_exclude(arcname):98print(f" Skipped: {arcname}")99continue100zipf.write(file_path, arcname)101print(f" Added: {arcname}")102103print(f"\nโ Successfully packaged skill to: {skill_filename}")104return skill_filename105106except Exception as e:107print(f"โ Error creating .skill file: {e}")108return None109110111def main():112if len(sys.argv) < 2:113print("Usage: python utils/package_skill.py <path/to/skill-folder> [output-directory]")114print("\nExample:")115print(" python utils/package_skill.py skills/public/my-skill")116print(" python utils/package_skill.py skills/public/my-skill ./dist")117sys.exit(1)118119skill_path = sys.argv[1]120output_dir = sys.argv[2] if len(sys.argv) > 2 else None121122print(f"๐ฆ Packaging skill: {skill_path}")123if output_dir:124print(f" Output directory: {output_dir}")125print()126127result = package_skill(skill_path, output_dir)128129if result:130sys.exit(0)131else:132sys.exit(1)133134135if __name__ == "__main__":136main()137