@every-env/cli
Version:
Multi-agent orchestrator for AI-powered development workflows
85 lines • 3.6 kB
JavaScript
import { PatternLoader } from '../patterns/registry/pattern-loader.js';
import { CommandPatternExecutor } from '../patterns/command-pattern-executor.js';
import { logger } from '../utils/logger.js';
import chalk from 'chalk';
export class BasePatternCommand {
name;
description;
commandRegistry;
patternLoader;
executor;
constructor(options) {
this.name = options.name;
this.description = options.description;
this.commandRegistry = options.commandRegistry;
this.patternLoader = new PatternLoader();
this.executor = new CommandPatternExecutor();
}
async executeCommand(config, patternNames = [], options = {}) {
try {
// Get command definition
const commandDef = this.commandRegistry.get(this.name);
if (!commandDef) {
throw new Error(`Command '${this.name}' not registered`);
}
// Load patterns for this command
const patterns = await this.patternLoader.loadForCommand(this.name, config);
// Filter patterns if specific names provided
let selectedPatterns = patterns;
if (patternNames.length > 0) {
selectedPatterns = patterns.filter(p => patternNames.includes(p.name));
if (selectedPatterns.length === 0) {
throw new Error(`No patterns found matching: ${patternNames.join(', ')}`);
}
}
// Create command context
const context = {
command: this.name,
commandVariables: commandDef.variables || {},
globalVariables: config.variables || {},
config,
};
// Execute patterns
return await this.executor.executePatternsForCommand(selectedPatterns, context, options);
}
catch (error) {
logger.error(`Failed to execute ${this.name} command:`, error);
throw error;
}
}
async listPatterns(config) {
const patterns = await this.patternLoader.loadForCommand(this.name, config);
console.log(chalk.bold(`\nAvailable patterns for '${this.name}' command:\n`));
if (patterns.length === 0) {
console.log(chalk.gray(' No patterns found'));
return;
}
for (const pattern of patterns) {
const source = pattern.builtIn ? chalk.gray('[built-in]') : chalk.blue('[user]');
console.log(` ${chalk.bold(pattern.name)} ${source}`);
if (pattern.description) {
console.log(` ${chalk.gray(pattern.description)}`);
}
}
console.log();
}
async validatePatterns(config, patternNames) {
const errors = [];
const patterns = await this.patternLoader.loadForCommand(this.name, config);
for (const name of patternNames) {
if (!patterns.some(p => p.name === name)) {
errors.push(`Pattern '${name}' not found for '${this.name}' command`);
}
}
return errors;
}
handleCommonOptions(command) {
command
.option('-d, --dry-run', 'Show what would be executed without making changes')
.option('-f, --force', 'Force execution without confirmation')
.option('--only <items...>', 'Only process specific items')
.option('--max-agents <number>', 'Maximum parallel agents', parseInt)
.option('-l, --list', 'List available patterns');
}
}
//# sourceMappingURL=base-command.js.map