@every-env/cli
Version:
Multi-agent orchestrator for AI-powered development workflows
75 lines ⢠3.46 kB
JavaScript
import chalk from 'chalk';
import { join } from 'path';
import { LiquidEngine } from '../templates/liquid-engine.js';
import { execCommand } from '../utils/exec.js';
import { logger } from '../utils/logger.js';
import { updateLastUsedAgent } from '../utils/command-state.js';
export async function parsePlanDescription(args) {
const planDescription = args.join(' ');
if (!planDescription) {
throw new Error('Please provide a plan description. Usage: every plan "your feature description"');
}
return planDescription;
}
export async function renderPlanTemplate(baseDir, planDescription) {
const liquidEngine = new LiquidEngine(baseDir);
const planTemplatePath = '.claude/commands/workflows/plan.md';
const renderedPrompt = await liquidEngine.renderFile(planTemplatePath, {
ARGUMENTS: planDescription
});
return renderedPrompt;
}
export async function executePlanCommand(cli, renderedPrompt, args) {
// Build command: cli "prompt" args...
const commandArgs = [renderedPrompt, ...args];
// Execute command - this will take over the terminal
await execCommand(cli, commandArgs);
}
export async function runPlanCommand(args, options = {}) {
const baseDir = options.baseDir || process.cwd();
const configPath = options.configPath || join(baseDir, '.every-env', 'config.json');
try {
// Step 1: Parse plan description
const planDescription = await parsePlanDescription(args);
// Step 2: Load runtime config to get agent configurations
const { readRuntimeConfigIfExists } = await import('../utils/runtime-config.js');
const runtimeConfig = await readRuntimeConfigIfExists(configPath);
let cli = 'claude';
let configArgs = [];
if (options.agentcli) {
// Use the specified agent from config
const agentConfig = runtimeConfig?.agents?.[options.agentcli];
if (agentConfig && typeof agentConfig.cli === 'string') {
cli = agentConfig.cli;
configArgs = Array.isArray(agentConfig.args) ? agentConfig.args : [];
}
else {
// Fallback to using the agentcli as the command itself
cli = options.agentcli;
}
// Save the last used agent
updateLastUsedAgent('plan', options.agentcli);
}
else {
// Use default agent
const defaultAgent = runtimeConfig?.defaultAgent || 'claude';
const defaultConfig = runtimeConfig?.agents?.[defaultAgent];
if (defaultConfig && typeof defaultConfig.cli === 'string') {
cli = defaultConfig.cli;
configArgs = Array.isArray(defaultConfig.args) ? defaultConfig.args : [];
}
}
// Step 3: Render plan template
const renderedPrompt = await renderPlanTemplate(baseDir, planDescription);
console.log(chalk.cyan(`\nš Creating plan for: "${planDescription}"\n`));
// Step 4: Execute command with pass-through args
const allArgs = [...configArgs, ...(options.passThroughArgs || [])];
await executePlanCommand(cli, renderedPrompt, allArgs);
}
catch (error) {
logger.error('Plan command failed:', error);
console.error(chalk.red(`\nā Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
throw error;
}
}
//# sourceMappingURL=plan.js.map