import { Command } from 'commander';
import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
export const newCommand = new Command('new')
.description('Create a new Agent Skill')
.argument('<name>', 'Name of the skill (e.g., "my-skill" or "domain/my-skill")')
.action(async (name: string) => {
console.log(chalk.blue(`Scaffolding new skill: ${name}...`));
// Determine target directory
// Default to resolving from the root of the repo if possible, or fallback to relative
// For now, let's assume we are running from repo root or try to find it.
// Simplifying: Create in ./contexts/Skills/src/[name] if it exists, else ./[name]
let targetRoot = path.resolve('contexts/Skills/src');
if (!fs.existsSync(targetRoot)) {
// Fallback: check if we are in tools/*
const alt = path.resolve('../../contexts/Skills/src');
if (fs.existsSync(alt)) {
targetRoot = alt;
} else {
targetRoot = process.cwd();
console.log(chalk.yellow(`Warning: Could not find contexts/Skills/src, creating in current directory: ${targetRoot}`));
}
}
const skillDir = path.join(targetRoot, name);
if (fs.existsSync(skillDir)) {
console.error(chalk.red(`Error: Directory already exists at ${skillDir}`));
process.exit(1);
}
const skillName = `fpf-skill:${name.replace(/\//g, '-')}`;
const template = `---
name: ${skillName}
description: Generated skill for ${name}.
version: 0.1.0
allowed_tools: []
---
# ${name} Kernel
## Instructions
Describe how this skill should perform its task.
`;
fs.mkdirSync(skillDir, { recursive: true });
fs.writeFileSync(path.join(skillDir, 'SKILL.md'), template);
console.log(chalk.green(`✓ Created skill at ${skillDir}`));
console.log(`Edit ${chalk.bold(path.join(skillDir, 'SKILL.md'))} to define your skill.`);
});