UNPKG

@every-env/cli

Version:

Multi-agent orchestrator for AI-powered development workflows

108 lines 3.86 kB
import { PatternLoader } from '../patterns/registry/pattern-loader.js'; export class CommandRegistry { commands = new Map(); aliases = new Map(); patternLoader; constructor() { this.patternLoader = new PatternLoader(); } register(command) { if (this.commands.has(command.name)) { throw new Error(`Command '${command.name}' is already registered`); } this.commands.set(command.name, command); // Register aliases if (command.aliases) { for (const alias of command.aliases) { if (this.aliases.has(alias)) { throw new Error(`Alias '${alias}' is already registered`); } this.aliases.set(alias, command.name); } } } get(nameOrAlias) { const commandName = this.aliases.get(nameOrAlias) || nameOrAlias; return this.commands.get(commandName); } has(nameOrAlias) { return this.commands.has(nameOrAlias) || this.aliases.has(nameOrAlias); } list() { return Array.from(this.commands.values()); } async getPatternsForCommand(commandName, config) { const command = this.get(commandName); if (!command) { throw new Error(`Unknown command: ${commandName}`); } // Load patterns from all sources const patterns = await this.patternLoader.loadForCommand(commandName, config); // Add default patterns if no patterns found if (patterns.length === 0 && command.defaultPatterns) { return command.defaultPatterns; } return patterns; } getCommandVariables(commandName) { const command = this.get(commandName); return command?.variables || {}; } validateCommand(commandName, config) { const command = this.get(commandName); if (!command) { return [`Unknown command: ${commandName}`]; } const errors = []; // Run command-specific validation if (command.validateConfig) { errors.push(...command.validateConfig(config)); } // Validate patterns for the command const patterns = config.patterns.filter(p => p.command === commandName || p.namespace === commandName); if (patterns.length === 0 && !command.defaultPatterns) { errors.push(`No patterns defined for command '${commandName}'`); } return errors; } clear() { this.commands.clear(); this.aliases.clear(); } // Built-in command definitions static createBuiltInCommands() { const registry = new CommandRegistry(); // Register docs command registry.register({ name: 'docs', description: 'Generate documentation using AI agents', aliases: ['doc', 'documentation'], variables: { outputDir: 'docs', outputPrefix: 'generated', }, validateConfig: (config) => { const errors = []; if (!config.patterns || config.patterns.length === 0) { errors.push('At least one pattern must be defined for docs command'); } return errors; }, }); // Register plan command (for future implementation) registry.register({ name: 'plan', description: 'Create implementation plans and work breakdowns', aliases: ['planning', 'breakdown'], variables: { outputDir: 'plans', outputPrefix: 'plan', includeTimeline: true, includeResources: true, }, }); return registry; } } //# sourceMappingURL=command-registry.js.map