ai-expert
Version:
AI Expert CLI - Advanced management system for specialized Claude assistants
123 lines ⢠4.82 kB
JavaScript
import { Command } from 'commander';
import inquirer from 'inquirer';
import chalk from 'chalk';
import { v4 as uuidv4 } from 'uuid';
export function systemCommand(storage) {
const system = new Command('system');
system
.description('Manage system templates')
.alias('s');
system
.command('create <name>')
.description('Create a new system template')
.option('-d, --description <desc>', 'System description')
.option('-c, --category <category>', 'System category')
.option('-t, --tags <tags...>', 'System tags')
.action(async (name, options) => {
try {
const config = await storage.getConfig();
const answers = await inquirer.prompt([
{
type: 'input',
name: 'description',
message: 'System description:',
default: options.description,
when: !options.description
},
{
type: 'list',
name: 'category',
message: 'Select category:',
choices: config.categories.systems,
default: options.category || 'general'
},
{
type: 'editor',
name: 'content',
message: 'Enter system prompt content:'
}
]);
const systemTemplate = {
id: `system-${uuidv4()}`,
name,
description: options.description || answers.description,
content: answers.content,
category: options.category || answers.category,
tags: options.tags || [],
created: new Date().toISOString()
};
await storage.saveSystem(systemTemplate);
console.log(chalk.green('ā
System template created successfully!'));
console.log(chalk.cyan(`ID: ${systemTemplate.id}`));
}
catch (error) {
console.error(chalk.red('ā Error:'), error.message);
}
});
system
.command('list')
.description('List all system templates')
.option('-c, --category <category>', 'Filter by category')
.option('--json', 'Output as JSON')
.action(async (options) => {
try {
const systems = await storage.listSystems(options.category);
if (options.json) {
console.log(JSON.stringify(systems, null, 2));
return;
}
if (systems.length === 0) {
console.log(chalk.yellow('No system templates found.'));
return;
}
console.log(chalk.bold('\nš System Templates:\n'));
for (const system of systems) {
console.log(chalk.cyan(`š ${system.name}`));
console.log(` ID: ${chalk.gray(system.id)}`);
console.log(` ${system.description}`);
console.log(chalk.gray(` Category: ${system.category}`));
if (system.tags?.length) {
console.log(chalk.gray(` Tags: ${system.tags.join(', ')}`));
}
console.log();
}
}
catch (error) {
console.error(chalk.red('ā Error:'), error.message);
}
});
system
.command('show <id>')
.description('Show system template details')
.option('--json', 'Output as JSON')
.action(async (id, options) => {
try {
const system = await storage.getSystem(id);
if (!system) {
console.error(chalk.red(`ā System template '${id}' not found`));
return;
}
if (options.json) {
console.log(JSON.stringify(system, null, 2));
return;
}
console.log(chalk.bold(`\nš System Template: ${system.name}\n`));
console.log(`ID: ${chalk.cyan(system.id)}`);
console.log(`Description: ${system.description}`);
console.log(`Category: ${system.category}`);
if (system.tags?.length) {
console.log(`Tags: ${system.tags.join(', ')}`);
}
console.log(`Created: ${new Date(system.created).toLocaleString()}`);
console.log(chalk.bold('\nContent:'));
console.log(chalk.gray('ā'.repeat(60)));
console.log(system.content);
console.log(chalk.gray('ā'.repeat(60)));
}
catch (error) {
console.error(chalk.red('ā Error:'), error.message);
}
});
return system;
}
//# sourceMappingURL=system.js.map