import { Command } from 'commander';
import path from 'path';
import fs from 'fs';
import chalk from 'chalk';
import { scanSkillsRegistry } from '@fpf/skill-core';
export const listCommand = new Command('list')
.description('List available Agent Skills')
.action(async () => {
// Locate registry
let registryRoot = path.resolve('contexts/Skills/src');
if (!fs.existsSync(registryRoot)) {
// Fallback for tests/dev
registryRoot = process.cwd();
if (!fs.existsSync(path.join(registryRoot, 'SKILL.md'))) {
// Maybe we are in tools/cli
const alt = path.resolve('../../contexts/Skills/src');
if (fs.existsSync(alt)) registryRoot = alt;
}
}
console.log(chalk.dim(`Scanning registry at: ${registryRoot}`));
const skills = await scanSkillsRegistry(registryRoot);
if (skills.length === 0) {
console.log(chalk.yellow('No skills found.'));
return;
}
console.log(chalk.bold('\nFound Skills:'));
console.log('--------------------------------------------------');
for (const skill of skills) {
if (!skill.isValid) {
console.log(chalk.red(`[INVALID] ${path.relative(registryRoot, skill.path)}: ${skill.errors?.join(', ')}`));
continue;
}
const { name, description, allowed_tools } = skill.result.boundary;
const toolCount = allowed_tools ? allowed_tools.length : 0;
console.log(`${chalk.green(name)} ${chalk.dim(`(${toolCount} tools)`)}`);
console.log(` ${description}`);
console.log('');
}
});