claude-flow-multilang
Version:
Revolutionary multilingual AI orchestration framework with cultural awareness and DDD architecture
297 lines (253 loc) ⢠10.3 kB
JavaScript
import { printSuccess, printError, printWarning } from '../utils.js';
// Simple ID generator
function generateId(prefix = 'id') {
return `${prefix}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
}
export async function automationAction(subArgs, flags) {
const subcommand = subArgs[0];
const options = flags;
if (options.help || options.h || !subcommand) {
showAutomationHelp();
return;
}
try {
switch (subcommand) {
case 'auto-agent':
await autoAgentCommand(subArgs, flags);
break;
case 'smart-spawn':
await smartSpawnCommand(subArgs, flags);
break;
case 'workflow-select':
await workflowSelectCommand(subArgs, flags);
break;
default:
printError(`Unknown automation command: ${subcommand}`);
showAutomationHelp();
}
} catch (err) {
printError(`Automation command failed: ${err.message}`);
}
}
async function autoAgentCommand(subArgs, flags) {
const options = flags;
const complexity = options['task-complexity'] || options.complexity || 'medium';
const swarmId = options['swarm-id'] || options.swarmId || generateId('swarm');
console.log(`š¤ Auto-spawning agents based on task complexity...`);
console.log(`š Task complexity: ${complexity}`);
console.log(`š Swarm ID: ${swarmId}`);
// Determine optimal agent configuration based on complexity
let agentConfig;
switch (complexity.toLowerCase()) {
case 'low':
case 'simple':
agentConfig = { coordinator: 1, developer: 1, total: 2 };
break;
case 'medium':
case 'moderate':
agentConfig = { coordinator: 1, developer: 2, researcher: 1, total: 4 };
break;
case 'high':
case 'complex':
agentConfig = { coordinator: 2, developer: 3, researcher: 2, analyzer: 1, total: 8 };
break;
case 'enterprise':
case 'massive':
agentConfig = {
coordinator: 3,
developer: 5,
researcher: 3,
analyzer: 2,
tester: 2,
total: 15,
};
break;
default:
agentConfig = { coordinator: 1, developer: 2, researcher: 1, total: 4 };
}
console.log(`\nšÆ OPTIMAL AGENT CONFIGURATION:`);
Object.entries(agentConfig).forEach(([type, count]) => {
if (type !== 'total') {
console.log(` š¤ ${type}: ${count} agents`);
}
});
console.log(` š Total agents: ${agentConfig.total}`);
// Simulate auto-spawning
await new Promise((resolve) => setTimeout(resolve, 1500));
printSuccess(`ā
Auto-agent spawning completed`);
console.log(
`š ${agentConfig.total} agents spawned and configured for ${complexity} complexity tasks`,
);
console.log(`š¾ Agent configuration saved to swarm memory: ${swarmId}`);
console.log(`š Agents ready for task assignment`);
}
async function smartSpawnCommand(subArgs, flags) {
const options = flags;
const requirement = options.requirement || 'general-development';
const maxAgents = parseInt(options['max-agents'] || options.maxAgents || '10');
console.log(`š§ Smart spawning agents based on requirements...`);
console.log(`š Requirement: ${requirement}`);
console.log(`š¢ Max agents: ${maxAgents}`);
// Analyze requirements and suggest optimal agent mix
let recommendedAgents = [];
if (requirement.includes('development') || requirement.includes('coding')) {
recommendedAgents.push(
{ type: 'coordinator', count: 1, reason: 'Task orchestration' },
{ type: 'coder', count: 3, reason: 'Core development work' },
{ type: 'tester', count: 1, reason: 'Quality assurance' },
);
}
if (requirement.includes('research') || requirement.includes('analysis')) {
recommendedAgents.push(
{ type: 'researcher', count: 2, reason: 'Information gathering' },
{ type: 'analyst', count: 1, reason: 'Data analysis' },
);
}
if (requirement.includes('enterprise') || requirement.includes('production')) {
recommendedAgents.push(
{ type: 'coordinator', count: 2, reason: 'Multi-tier coordination' },
{ type: 'coder', count: 4, reason: 'Parallel development' },
{ type: 'researcher', count: 2, reason: 'Requirements analysis' },
{ type: 'analyst', count: 1, reason: 'Performance monitoring' },
{ type: 'tester', count: 2, reason: 'Comprehensive testing' },
);
}
// Default fallback
if (recommendedAgents.length === 0) {
recommendedAgents = [
{ type: 'coordinator', count: 1, reason: 'General coordination' },
{ type: 'coder', count: 2, reason: 'General development' },
{ type: 'researcher', count: 1, reason: 'Support research' },
];
}
await new Promise((resolve) => setTimeout(resolve, 1000));
printSuccess(`ā
Smart spawn analysis completed`);
console.log(`\nšÆ RECOMMENDED AGENT CONFIGURATION:`);
let totalRecommended = 0;
recommendedAgents.forEach((agent) => {
console.log(` š¤ ${agent.type}: ${agent.count} agents - ${agent.reason}`);
totalRecommended += agent.count;
});
console.log(`\nš SUMMARY:`);
console.log(` š Total recommended: ${totalRecommended} agents`);
console.log(` š¢ Max allowed: ${maxAgents} agents`);
console.log(
` ā
Configuration: ${totalRecommended <= maxAgents ? 'Within limits' : 'Exceeds limits - scaling down required'}`,
);
if (totalRecommended > maxAgents) {
printWarning(
`ā ļø Recommended configuration exceeds max agents. Consider increasing limit or simplifying requirements.`,
);
}
}
async function workflowSelectCommand(subArgs, flags) {
const options = flags;
const projectType = options['project-type'] || options.project || 'general';
const priority = options.priority || 'balanced';
console.log(`š Selecting optimal workflow configuration...`);
console.log(`š Project type: ${projectType}`);
console.log(`ā” Priority: ${priority}`);
// Define workflow templates
const workflows = {
'web-app': {
phases: ['planning', 'design', 'frontend', 'backend', 'testing', 'deployment'],
agents: { coordinator: 1, developer: 3, tester: 1, researcher: 1 },
duration: '2-4 weeks',
},
api: {
phases: ['specification', 'design', 'implementation', 'testing', 'documentation'],
agents: { coordinator: 1, developer: 2, tester: 1, researcher: 1 },
duration: '1-2 weeks',
},
'data-analysis': {
phases: ['collection', 'cleaning', 'analysis', 'visualization', 'reporting'],
agents: { coordinator: 1, researcher: 2, analyzer: 2, developer: 1 },
duration: '1-3 weeks',
},
enterprise: {
phases: [
'requirements',
'architecture',
'development',
'integration',
'testing',
'deployment',
'monitoring',
],
agents: { coordinator: 2, developer: 5, researcher: 2, analyzer: 1, tester: 2 },
duration: '2-6 months',
},
general: {
phases: ['planning', 'implementation', 'testing', 'delivery'],
agents: { coordinator: 1, developer: 2, researcher: 1 },
duration: '1-2 weeks',
},
};
const selectedWorkflow = workflows[projectType] || workflows['general'];
await new Promise((resolve) => setTimeout(resolve, 800));
printSuccess(`ā
Workflow selection completed`);
console.log(`\nš SELECTED WORKFLOW: ${projectType.toUpperCase()}`);
console.log(`ā±ļø Estimated duration: ${selectedWorkflow.duration}`);
console.log(`\nš WORKFLOW PHASES:`);
selectedWorkflow.phases.forEach((phase, index) => {
console.log(` ${index + 1}. ${phase.charAt(0).toUpperCase() + phase.slice(1)}`);
});
console.log(`\nš¤ RECOMMENDED AGENTS:`);
Object.entries(selectedWorkflow.agents).forEach(([type, count]) => {
console.log(` ⢠${type}: ${count} agent${count > 1 ? 's' : ''}`);
});
console.log(`\nā” PRIORITY OPTIMIZATIONS:`);
switch (priority) {
case 'speed':
console.log(` š Speed-optimized: +50% agents, parallel execution`);
break;
case 'quality':
console.log(` šÆ Quality-focused: +100% testing, code review stages`);
break;
case 'cost':
console.log(` š° Cost-efficient: Minimal agents, sequential execution`);
break;
default:
console.log(` āļø Balanced approach: Optimal speed/quality/cost ratio`);
}
console.log(`\nš Workflow template saved for project: ${projectType}`);
}
function showAutomationHelp() {
console.log(`
š¤ Automation Commands - Intelligent Agent & Workflow Management
USAGE:
claude-flow automation <command> [options]
COMMANDS:
auto-agent Automatically spawn optimal agents based on task complexity
smart-spawn Intelligently spawn agents based on specific requirements
workflow-select Select and configure optimal workflows for project types
AUTO-AGENT OPTIONS:
--task-complexity <level> Task complexity level (default: medium)
Options: low, medium, high, enterprise
--swarm-id <id> Target swarm ID for agent spawning
SMART-SPAWN OPTIONS:
--requirement <req> Specific requirement description
Examples: "web-development", "data-analysis", "enterprise-api"
--max-agents <n> Maximum number of agents to spawn (default: 10)
WORKFLOW-SELECT OPTIONS:
--project-type <type> Project type (default: general)
Options: web-app, api, data-analysis, enterprise, general
--priority <priority> Optimization priority (default: balanced)
Options: speed, quality, cost, balanced
EXAMPLES:
# Auto-spawn for complex enterprise task
claude-flow automation auto-agent --task-complexity enterprise --swarm-id swarm-123
# Smart spawn for web development
claude-flow automation smart-spawn --requirement "web-development" --max-agents 8
# Select workflow for API project optimized for speed
claude-flow automation workflow-select --project-type api --priority speed
# Auto-spawn for simple task
claude-flow automation auto-agent --task-complexity low
šÆ Automation benefits:
⢠Optimal resource allocation
⢠Intelligent agent selection
⢠Workflow optimization
⢠Reduced manual configuration
⢠Performance-based scaling
`);
}