Initialize a new skill directory with template SKILL.md. Args: skill_name: Name of the skill path: Path where the skill directory should be created Returns: Path to created skill directory, or None if error
(skill_name, path)
| 192 | |
| 193 | |
| 194 | def init_skill(skill_name, path): |
| 195 | """ |
| 196 | Initialize a new skill directory with template SKILL.md. |
| 197 | |
| 198 | Args: |
| 199 | skill_name: Name of the skill |
| 200 | path: Path where the skill directory should be created |
| 201 | |
| 202 | Returns: |
| 203 | Path to created skill directory, or None if error |
| 204 | """ |
| 205 | # Determine skill directory path |
| 206 | skill_dir = Path(path).resolve() / skill_name |
| 207 | |
| 208 | # Check if directory already exists |
| 209 | if skill_dir.exists(): |
| 210 | print(f"❌ Error: Skill directory already exists: {skill_dir}") |
| 211 | return None |
| 212 | |
| 213 | # Create skill directory |
| 214 | try: |
| 215 | skill_dir.mkdir(parents=True, exist_ok=False) |
| 216 | print(f"✅ Created skill directory: {skill_dir}") |
| 217 | except Exception as e: |
| 218 | print(f"❌ Error creating directory: {e}") |
| 219 | return None |
| 220 | |
| 221 | # Create SKILL.md from template |
| 222 | skill_title = title_case_skill_name(skill_name) |
| 223 | skill_content = SKILL_TEMPLATE.format( |
| 224 | skill_name=skill_name, |
| 225 | skill_title=skill_title |
| 226 | ) |
| 227 | |
| 228 | skill_md_path = skill_dir / 'SKILL.md' |
| 229 | try: |
| 230 | skill_md_path.write_text(skill_content) |
| 231 | print("✅ Created SKILL.md") |
| 232 | except Exception as e: |
| 233 | print(f"❌ Error creating SKILL.md: {e}") |
| 234 | return None |
| 235 | |
| 236 | # Create resource directories with example files |
| 237 | try: |
| 238 | # Create scripts/ directory with example script |
| 239 | scripts_dir = skill_dir / 'scripts' |
| 240 | scripts_dir.mkdir(exist_ok=True) |
| 241 | example_script = scripts_dir / 'example.py' |
| 242 | example_script.write_text(EXAMPLE_SCRIPT.format(skill_name=skill_name)) |
| 243 | example_script.chmod(0o755) |
| 244 | print("✅ Created scripts/example.py") |
| 245 | |
| 246 | # Create references/ directory with example reference doc |
| 247 | references_dir = skill_dir / 'references' |
| 248 | references_dir.mkdir(exist_ok=True) |
| 249 | example_reference = references_dir / 'api_reference.md' |
| 250 | example_reference.write_text(EXAMPLE_REFERENCE.format(skill_title=skill_title)) |
| 251 | print("✅ Created references/api_reference.md") |
no test coverage detected