V3 CLI Modernization
What This Skill Does
Modernizes claude-flow v3 CLI with interactive prompts, intelligent command decomposition, enhanced hooks integration, performance optimization, and comprehensive workflow automation capabilities.
Quick Start
# Initialize CLI modernization analysis
Task("CLI architecture", "Analyze current CLI structure and identify optimization opportunities", "cli-hooks-developer")
# Modernization implementation (parallel)
Task("Command decomposition", "Break down large CLI files into focused modules", "cli-hooks-developer")
Task("Interactive prompts", "Implement intelligent interactive CLI experience", "cli-hooks-developer")
Task("Hooks enhancement", "Deep integrate hooks with CLI lifecycle", "cli-hooks-developer")
CLI Architecture Modernization
Current State Analysis
Current CLI Issues:
├── index.ts: 108KB monolithic file
├── enterprise.ts: 68KB feature module
├── Limited interactivity: Basic command parsing
├── Hooks integration: Basic pre/post execution
└── No intelligent workflows: Manual command chaining
Target Architecture:
├── Modular Commands: <500 lines per command
├── Interactive Prompts: Smart context-aware UX
├── Enhanced Hooks: Deep lifecycle integration
├── Workflow Automation: Intelligent command orchestration
└── Performance: <200ms command response time
Modular Command Architecture
// src/cli/core/command-registry.ts
interface CommandModule {
name: string;
description: string;
category: CommandCategory;
handler: CommandHandler;
middleware: MiddlewareStack;
permissions: Permission[];
examples: CommandExample[];
}
export class ModularCommandRegistry {
private commands = new Map<string, CommandModule>();
private categories = new Map<CommandCategory, CommandModule[]>();
private aliases = new Map<string, string>();
registerCommand(command: CommandModule): void {
this.commands.set(command.name, command);
// Register in category index
if (!this.categories.has(command.category)) {
this.categories.set(command.category, []);
}
this.categories.get(command.category)!.push(command);
}
async executeCommand(name: string, args: string[]): Promise<CommandResult> {
const command = this.resolveCommand(name);
if (!command) {
throw new CommandNotFoundError(name, this.getSuggestions(name));
}
// Execute middleware stack
const context = await this.buildExecutionContext(command, args);
const result = await command.middleware.execute(context);
return result;
}
private resolveCommand(name: string): CommandModule | undefined {
// Try exact match first
if (this.commands.has(name)) {
return this.commands.get(name);
}
// Try alias
const aliasTarget = this.aliases.get(name);
if (aliasTarget) {
return this.commands.get(aliasTarget);
}
// Try fuzzy match
return this.findFuzzyMatch(name);
}
}
Command Decomposition Strategy
Swarm Commands Module
// src/cli/commands/swarm/swarm.command.ts
@Command({
name: 'swarm',
description: 'Swarm coordination and management',
category: 'orchestration'
})
export class SwarmCommand {
constructor(
private swarmCoordinator: UnifiedSwarmCoordinator,
private promptService: InteractivePromptService
) {}
@SubCommand('init')
@Option('--topology', 'Swarm topology (mesh|hierarchical|adaptive)', 'hierarchical')
@Option('--agents', 'Number of agents to spawn', 5)
@Option('--interactive', 'Interactive agent configuration', false)
async init(
@Arg('projectName') projectName: string,
options: SwarmInitOptions
): Promise<CommandResult> {
if (options.interactive) {
return this.interactiveSwarmInit(projectName);
}
return this.quickSwarmInit(projectName, options);
}
private async interactiveSwarmInit(projectName: string): Promise<CommandResult> {
console.log(`🚀 Initializing Swarm for ${projectName}`);
// Interactive topology selection
const topology = await this.promptService.select({
message: 'Select swarm topology:',
choices: [
{ name: 'Hierarchical (Queen-led coordination)', value: 'hierarchical' },
{ name: 'Mesh (Peer-to-peer collaboration)', value: 'mesh' },
{ name: 'Adaptive (Dynamic topology switching)', value: 'adaptive' }
]
});
// Agent configuration
const agents = await this.promptAgentConfiguration();
// Initialize with configuration
const swarm = await this.swarmCoordinator.initialize({
name: projectName,
topology,
agents,
hooks: {
onAgentSpawn: this.handleAgentSpawn.bind(this),
onTaskComplete: this.handleTaskComplete.bind(this),
onSwarmComplete: this.handleSwarmComplete.bind(this)
}
});
return CommandResult.success({
message: `✅ Swarm ${projectName} initialized with ${agents.length} agents`,
data: { swarmId: swarm.id, topology, agentCount: agents.length }
});
}
@SubCommand('status')
async status(): Promise<CommandResult> {
const swarms = await this.swarmCoordinator.listActiveSwarms();
if (swarms.length === 0) {
return CommandResult.info('No active swarms found');
}
// Interactive swarm selection if multiple
const selectedSwarm = swarms.length === 1
? swarms[0]
: await this.promptService.select({
message: 'Select swarm to inspect:',
choices: swarms.map(s => ({
name: `${s.name} (${s.agents.length} agents, ${s.topology})`,
value: s
}))
});
return this.displaySwarmStatus(selectedSwarm);
}
}
Learning Commands Module
// src/cli/commands/learning/learning.command.ts
@Command({
name: 'learning',
description: 'Learning system management and optimization',
category: 'intelligence'
})
export class LearningCommand {
constructor(
private learningService: IntegratedLearningService,
private promptService: InteractivePromptService
) {}
@SubCommand('start')
@Option('--algorithm', 'RL algorithm to use', 'auto')
@Option('--tier', 'Learning tier (basic|standard|advanced)', 'standard')
async start(options: LearningStartOptions): Promise<CommandResult> {
// Auto-detect optimal algorithm if not specified
if (options.algorithm === 'auto') {
const taskContext = await this.analyzeCurrentContext();
options.algorithm = this.learningService.selectOptimalAlgorithm(taskContext);
console.log(`🧠 Auto-selected ${options.algorithm} algorithm based on context`);
}
const session = await this.learningService.startSession({
algorithm: options.algorithm,
tier: options.tier,
userId: await this.getCurrentUser()
});
return CommandResult.success({
message: `🚀 Learning session started with ${options.algorithm}`,
data: { sessionId: session.id, algorithm: options.algorithm, tier: options.tier }
});
}
@SubCommand('feedback')
@Arg('reward', 'Reward value (0-1)', 'number')
async feedback(
@Arg('reward') reward: number,
@Option('--context', 'Additional context for learning')
context?: string
): Promise<CommandResult> {
const activeSession = await this.learningService.getActiveSession();
if (!activeSession) {
return CommandResult.error('No active learning session found. Start one with `learning start`');
}
await this.learningService.submitFeedback({
sessionId: activeSession.id,
reward,
context,
timestamp: new Date()
});
return CommandResult.success({
message: `📊 Feedback recorded (reward: ${reward})`,
data: { reward, sessionId: activeSession.id }
});
}
@SubCommand('metrics')
async metrics(): Promise<CommandResult> {
const metrics = await this.learningService.getMetrics();
// Interactive metrics display
await this.displayInteractiveMetrics(metrics);