MCPcopy Create free account
hub / github.com/SpaceZephyr/myskill / package_skill

Function package_skill

skill-creator/scripts/package_skill.py:19–82  ·  view source on GitHub ↗

Package a skill folder into a .skill file. Args: skill_path: Path to the skill folder output_dir: Optional output directory for the .skill file (defaults to current directory) Returns: Path to the created .skill file, or None if error

(skill_path, output_dir=None)

Source from the content-addressed store, hash-verified

17
18
19def package_skill(skill_path, output_dir=None):
20 """
21 Package a skill folder into a .skill file.
22
23 Args:
24 skill_path: Path to the skill folder
25 output_dir: Optional output directory for the .skill file (defaults to current directory)
26
27 Returns:
28 Path to the created .skill file, or None if error
29 """
30 skill_path = Path(skill_path).resolve()
31
32 # Validate skill folder exists
33 if not skill_path.exists():
34 print(f"❌ Error: Skill folder not found: {skill_path}")
35 return None
36
37 if not skill_path.is_dir():
38 print(f"❌ Error: Path is not a directory: {skill_path}")
39 return None
40
41 # Validate SKILL.md exists
42 skill_md = skill_path / "SKILL.md"
43 if not skill_md.exists():
44 print(f"❌ Error: SKILL.md not found in {skill_path}")
45 return None
46
47 # Run validation before packaging
48 print("🔍 Validating skill...")
49 valid, message = validate_skill(skill_path)
50 if not valid:
51 print(f"❌ Validation failed: {message}")
52 print(" Please fix the validation errors before packaging.")
53 return None
54 print(f"✅ {message}\n")
55
56 # Determine output location
57 skill_name = skill_path.name
58 if output_dir:
59 output_path = Path(output_dir).resolve()
60 output_path.mkdir(parents=True, exist_ok=True)
61 else:
62 output_path = Path.cwd()
63
64 skill_filename = output_path / f"{skill_name}.skill"
65
66 # Create the .skill file (zip format)
67 try:
68 with zipfile.ZipFile(skill_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
69 # Walk through the skill directory
70 for file_path in skill_path.rglob('*'):
71 if file_path.is_file():
72 # Calculate the relative path within the zip
73 arcname = file_path.relative_to(skill_path.parent)
74 zipf.write(file_path, arcname)
75 print(f" Added: {arcname}")
76

Callers 1

mainFunction · 0.85

Calls 1

validate_skillFunction · 0.90

Tested by

no test coverage detected