From eaeb7ef221f74058246f2ea04d204f1a6ae3f67c Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Wed, 21 Jan 2026 11:59:54 +0000 Subject: [PATCH] feat: add create command for scaffolding new skills - Add skillkit create command to scaffold new skills with proper structure - Generate SKILL.md template with frontmatter following Agent Skills spec - Support optional directories (references, scripts, assets) - Validate skill names (lowercase alphanumeric with hyphens) - Update README with create command documentation --- README.md | 18 ++++++ src/cli.ts | 2 + src/commands/create.ts | 130 +++++++++++++++++++++++++++++++++++++++++ src/commands/index.ts | 1 + 4 files changed, 151 insertions(+) create mode 100644 src/commands/create.ts diff --git a/README.md b/README.md index 6f101dbd..3e60a219 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,9 @@ skillkit install gitlab:owner/repo # Install specific skills (CI/CD friendly) skillkit install owner/repo --skills=pdf,xlsx,docx +# Create a new skill +skillkit create my-skill + # Sync skills to your agent config skillkit sync @@ -201,6 +204,19 @@ skillkit validate ./my-skill # Validate single skill skillkit validate ./skills --all # Validate all skills in directory ``` +### `skillkit create ` + +Create a new skill with proper structure and template. + +```bash +skillkit create my-skill # Basic skill +skillkit create my-skill --full # Include all directories (references, scripts, assets) +skillkit create my-skill --scripts # Include scripts directory +skillkit create my-skill --references # Include references directory +skillkit create my-skill --assets # Include assets directory +skillkit create my-skill --dir ./skills # Create in specific directory +``` + ## Supported Agents | Agent | Config File | Project Path | Global Path | @@ -225,6 +241,8 @@ skillkit validate ./skills --all # Validate all skills in directory ## Creating Skills +Use `skillkit create ` to scaffold a new skill, or create manually: + A skill is a directory with a `SKILL.md` file: ``` diff --git a/src/cli.ts b/src/cli.ts index cf10c6b7..3369a412 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -11,6 +11,7 @@ import { RemoveCommand, InitCommand, ValidateCommand, + CreateCommand, } from './commands/index.js'; const cli = new Cli({ @@ -32,5 +33,6 @@ cli.register(UpdateCommand); cli.register(RemoveCommand); cli.register(InitCommand); cli.register(ValidateCommand); +cli.register(CreateCommand); cli.runExit(process.argv.slice(2)); diff --git a/src/commands/create.ts b/src/commands/create.ts new file mode 100644 index 00000000..d0e26c36 --- /dev/null +++ b/src/commands/create.ts @@ -0,0 +1,130 @@ +import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; +import chalk from 'chalk'; +import { Command, Option } from 'clipanion'; + +export class CreateCommand extends Command { + static override paths = [['create'], ['new']]; + + static override usage = Command.Usage({ + description: 'Create a new skill with proper structure', + examples: [ + ['Create a new skill', '$0 create my-skill'], + ['Create with all optional directories', '$0 create my-skill --full'], + ['Create with scripts directory', '$0 create my-skill --scripts'], + ], + }); + + name = Option.String({ required: true, name: 'skill-name' }); + + full = Option.Boolean('--full,-f', false, { + description: 'Include all optional directories (references, scripts, assets)', + }); + + scripts = Option.Boolean('--scripts', false, { + description: 'Include scripts directory', + }); + + references = Option.Boolean('--references', false, { + description: 'Include references directory', + }); + + assets = Option.Boolean('--assets', false, { + description: 'Include assets directory', + }); + + directory = Option.String('--dir,-d', { + description: 'Parent directory to create skill in (default: current directory)', + }); + + async execute(): Promise { + const skillName = this.name.toLowerCase(); + + if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(skillName)) { + console.error(chalk.red('Invalid skill name')); + console.error(chalk.dim('Must be lowercase alphanumeric with hyphens (e.g., my-skill)')); + return 1; + } + + const parentDir = this.directory || process.cwd(); + const skillDir = join(parentDir, skillName); + + if (existsSync(skillDir)) { + console.error(chalk.red(`Directory already exists: ${skillDir}`)); + return 1; + } + + try { + mkdirSync(skillDir, { recursive: true }); + + const skillMd = generateSkillMd(skillName); + writeFileSync(join(skillDir, 'SKILL.md'), skillMd); + + if (this.full || this.references) { + const refsDir = join(skillDir, 'references'); + mkdirSync(refsDir); + writeFileSync(join(refsDir, '.gitkeep'), ''); + } + + if (this.full || this.scripts) { + const scriptsDir = join(skillDir, 'scripts'); + mkdirSync(scriptsDir); + writeFileSync(join(scriptsDir, '.gitkeep'), ''); + } + + if (this.full || this.assets) { + const assetsDir = join(skillDir, 'assets'); + mkdirSync(assetsDir); + writeFileSync(join(assetsDir, '.gitkeep'), ''); + } + + console.log(chalk.green(`Created skill: ${skillName}`)); + console.log(); + console.log(chalk.dim('Structure:')); + console.log(chalk.dim(` ${skillDir}/`)); + console.log(chalk.dim(' ├── SKILL.md')); + if (this.full || this.references) console.log(chalk.dim(' ├── references/')); + if (this.full || this.scripts) console.log(chalk.dim(' ├── scripts/')); + if (this.full || this.assets) console.log(chalk.dim(' └── assets/')); + console.log(); + console.log(chalk.cyan('Next steps:')); + console.log(chalk.dim(' 1. Edit SKILL.md with your instructions')); + console.log(chalk.dim(' 2. Validate: skillkit validate ' + skillDir)); + console.log(chalk.dim(' 3. Test: skillkit read ' + skillName)); + + return 0; + } catch (error) { + console.error(chalk.red('Failed to create skill')); + console.error(chalk.dim(error instanceof Error ? error.message : String(error))); + return 1; + } + } +} + +function generateSkillMd(name: string): string { + const title = name + .split('-') + .map(word => word.charAt(0).toUpperCase() + word.slice(1)) + .join(' '); + + return `--- +name: ${name} +description: Describe what this skill does and when to use it. Include trigger keywords. +--- + +# ${title} + +Instructions for the AI agent on how to use this skill. + +## When to Use + +- Scenario 1 +- Scenario 2 + +## Steps + +1. First step +2. Second step +3. Third step +`; +} diff --git a/src/commands/index.ts b/src/commands/index.ts index b34d2dba..eb3cf566 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -7,3 +7,4 @@ export { UpdateCommand } from './update.js'; export { RemoveCommand } from './remove.js'; export { InitCommand } from './init.js'; export { ValidateCommand } from './validate.js'; +export { CreateCommand } from './create.js'; \ No newline at end of file