import { Command } from 'commander';
import path from 'path';
import fs from 'fs';
import chalk from 'chalk';
import { loadSkill } from '@fpf/skill-core';
export const inspectCommand = new Command('inspect')
.description('Inspect the details of a specific skill')
.argument('<name>', 'Name or path of the skill')
.action(async (name: string) => {
// Attempt to resolve skill path
let skillPath = path.resolve(name);
// If not a path, try to find it in registry
if (!fs.existsSync(skillPath)) {
let registryRoot = path.resolve('contexts/Skills/src');
if (!fs.existsSync(registryRoot)) {
const alt = path.resolve('../../contexts/Skills/src');
if (fs.existsSync(alt)) registryRoot = alt;
else registryRoot = process.cwd();
}
// Try direct child
let tryPath = path.join(registryRoot, name);
if (fs.existsSync(tryPath)) {
skillPath = tryPath;
} else {
// Try domain/name format (if name has slash, it might have matched above if dir existed)
// If name is just "hello-world", we might need to search?
// For now, let's assume strict path or relative to registry root.
}
}
if (!fs.existsSync(path.join(skillPath, 'SKILL.md'))) {
console.error(chalk.red(`Error: No SKILL.md found at ${skillPath}`));
return;
}
const { result, isValid, errors } = await loadSkill(skillPath);
if (!isValid) {
console.error(chalk.red('Skill is INVALID:'));
errors?.forEach(e => console.error(chalk.red(`- ${e}`)));
return;
}
const { boundary, kernel } = result;
console.log(chalk.bold('📦 Boundary (Contract):'));
console.log(chalk.blue(JSON.stringify(boundary, null, 2)));
console.log(chalk.bold('\n🧠 Kernel (Instructions):'));
console.log(chalk.gray('----------------------------------------'));
console.log(kernel.content.trim());
console.log(chalk.gray('----------------------------------------'));
});