claude-flow
Version:
Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration
359 lines • 13.1 kB
JavaScript
/**
* V3 CLI Commands Index
* Central registry for all CLI commands
*
* OPTIMIZATION: Uses lazy loading for commands to reduce CLI startup time by ~200ms
* Commands are loaded on-demand when first accessed, not at module load time.
*/
/**
* Command loaders - commands are only imported when needed
* This reduces initial bundle parse time by ~200ms
*/
const commandLoaders = {
// P1 Core Commands (frequently used - load first)
init: () => import('./init.js'),
start: () => import('./start.js'),
status: () => import('./status.js'),
task: () => import('./task.js'),
session: () => import('./session.js'),
// Original Commands
agent: () => import('./agent.js'),
swarm: () => import('./swarm.js'),
memory: () => import('./memory.js'),
mcp: () => import('./mcp.js'),
config: () => import('./config.js'),
migrate: () => import('./migrate.js'),
hooks: () => import('./hooks.js'),
workflow: () => import('./workflow.js'),
'hive-mind': () => import('./hive-mind.js'),
process: () => import('./process.js'),
daemon: () => import('./daemon.js'),
// V3 Advanced Commands (less frequently used - lazy load)
neural: () => import('./neural.js'),
security: () => import('./security.js'),
performance: () => import('./performance.js'),
providers: () => import('./providers.js'),
plugins: () => import('./plugins.js'),
deployment: () => import('./deployment.js'),
claims: () => import('./claims.js'),
embeddings: () => import('./embeddings.js'),
// P0 Commands
completions: () => import('./completions.js'),
doctor: () => import('./doctor.js'),
// Analysis Commands
analyze: () => import('./analyze.js'),
// Q-Learning Routing Commands
route: () => import('./route.js'),
// Progress Commands
progress: () => import('./progress.js'),
// Issue Claims Commands (ADR-016)
issues: () => import('./issues.js'),
// Auto-update System (ADR-025)
update: () => import('./update.js'),
// RuVector PostgreSQL Bridge
ruvector: () => import('./ruvector/index.js'),
// Benchmark Suite (Pre-training, Neural, Memory)
benchmark: () => import('./benchmark.js'),
// Guidance Control Plane
guidance: () => import('./guidance.js'),
};
// Cache for loaded commands
const loadedCommands = new Map();
/**
* Load a command lazily
*/
async function loadCommand(name) {
if (loadedCommands.has(name)) {
return loadedCommands.get(name);
}
const loader = commandLoaders[name];
if (!loader)
return undefined;
try {
const module = await loader();
// Try to find the command export (either default or named)
const command = (module.default || module[`${name}Command`] || Object.values(module).find((v) => typeof v === 'object' && v !== null && 'name' in v && 'description' in v));
if (command) {
loadedCommands.set(name, command);
return command;
}
}
catch (error) {
// Silently fail for missing optional commands
if (process.env.DEBUG) {
console.error(`Failed to load command ${name}:`, error);
}
}
return undefined;
}
// =============================================================================
// Synchronous Imports for Core Commands (needed immediately at startup)
// These are the most commonly used commands that need instant access
// =============================================================================
import { initCommand } from './init.js';
import { startCommand } from './start.js';
import { statusCommand } from './status.js';
import { taskCommand } from './task.js';
import { sessionCommand } from './session.js';
import { agentCommand } from './agent.js';
import { swarmCommand } from './swarm.js';
import { memoryCommand } from './memory.js';
import { mcpCommand } from './mcp.js';
import { hooksCommand } from './hooks.js';
import { daemonCommand } from './daemon.js';
import { doctorCommand } from './doctor.js';
import { embeddingsCommand } from './embeddings.js';
import { neuralCommand } from './neural.js';
import { performanceCommand } from './performance.js';
import { securityCommand } from './security.js';
import { ruvectorCommand } from './ruvector/index.js';
import { hiveMindCommand } from './hive-mind.js';
// Additional commands for categorized help display
import { configCommand } from './config.js';
import { completionsCommand } from './completions.js';
import { migrateCommand } from './migrate.js';
import { workflowCommand } from './workflow.js';
import { analyzeCommand } from './analyze.js';
import { routeCommand } from './route.js';
import { progressCommand } from './progress.js';
import { providersCommand } from './providers.js';
import { pluginsCommand } from './plugins.js';
import { deploymentCommand } from './deployment.js';
import { claimsCommand } from './claims.js';
import { issuesCommand } from './issues.js';
import updateCommand from './update.js';
import { processCommand } from './process.js';
import { guidanceCommand } from './guidance.js';
// Pre-populate cache with core commands
loadedCommands.set('init', initCommand);
loadedCommands.set('start', startCommand);
loadedCommands.set('status', statusCommand);
loadedCommands.set('task', taskCommand);
loadedCommands.set('session', sessionCommand);
loadedCommands.set('agent', agentCommand);
loadedCommands.set('swarm', swarmCommand);
loadedCommands.set('memory', memoryCommand);
loadedCommands.set('mcp', mcpCommand);
loadedCommands.set('hooks', hooksCommand);
loadedCommands.set('daemon', daemonCommand);
loadedCommands.set('doctor', doctorCommand);
loadedCommands.set('embeddings', embeddingsCommand);
loadedCommands.set('neural', neuralCommand);
loadedCommands.set('performance', performanceCommand);
loadedCommands.set('security', securityCommand);
loadedCommands.set('ruvector', ruvectorCommand);
loadedCommands.set('hive-mind', hiveMindCommand);
loadedCommands.set('guidance', guidanceCommand);
// =============================================================================
// Exports (maintain backwards compatibility)
// =============================================================================
// Export synchronously loaded commands
export { initCommand } from './init.js';
export { startCommand } from './start.js';
export { statusCommand } from './status.js';
export { taskCommand } from './task.js';
export { sessionCommand } from './session.js';
export { agentCommand } from './agent.js';
export { swarmCommand } from './swarm.js';
export { memoryCommand } from './memory.js';
export { mcpCommand } from './mcp.js';
export { hooksCommand } from './hooks.js';
export { daemonCommand } from './daemon.js';
export { doctorCommand } from './doctor.js';
export { embeddingsCommand } from './embeddings.js';
export { neuralCommand } from './neural.js';
export { performanceCommand } from './performance.js';
export { securityCommand } from './security.js';
export { ruvectorCommand } from './ruvector/index.js';
export { hiveMindCommand } from './hive-mind.js';
export { guidanceCommand } from './guidance.js';
// Lazy-loaded command re-exports (for backwards compatibility, but async-only)
export async function getConfigCommand() { return loadCommand('config'); }
export async function getMigrateCommand() { return loadCommand('migrate'); }
export async function getWorkflowCommand() { return loadCommand('workflow'); }
export async function getHiveMindCommand() { return loadCommand('hive-mind'); }
export async function getProcessCommand() { return loadCommand('process'); }
export async function getTaskCommand() { return loadCommand('task'); }
export async function getSessionCommand() { return loadCommand('session'); }
export async function getNeuralCommand() { return loadCommand('neural'); }
export async function getSecurityCommand() { return loadCommand('security'); }
export async function getPerformanceCommand() { return loadCommand('performance'); }
export async function getProvidersCommand() { return loadCommand('providers'); }
export async function getPluginsCommand() { return loadCommand('plugins'); }
export async function getDeploymentCommand() { return loadCommand('deployment'); }
export async function getClaimsCommand() { return loadCommand('claims'); }
export async function getEmbeddingsCommand() { return loadCommand('embeddings'); }
export async function getCompletionsCommand() { return loadCommand('completions'); }
export async function getAnalyzeCommand() { return loadCommand('analyze'); }
export async function getRouteCommand() { return loadCommand('route'); }
export async function getProgressCommand() { return loadCommand('progress'); }
export async function getIssuesCommand() { return loadCommand('issues'); }
export async function getRuvectorCommand() { return loadCommand('ruvector'); }
export async function getGuidanceCommand() { return loadCommand('guidance'); }
/**
* Core commands loaded synchronously (available immediately)
* Advanced commands loaded on-demand for faster startup
*/
export const commands = [
// Core commands (synchronously loaded)
initCommand,
startCommand,
statusCommand,
taskCommand,
sessionCommand,
agentCommand,
swarmCommand,
memoryCommand,
mcpCommand,
hooksCommand,
daemonCommand,
doctorCommand,
embeddingsCommand,
neuralCommand,
performanceCommand,
securityCommand,
ruvectorCommand,
hiveMindCommand,
guidanceCommand,
];
/**
* Commands organized by category for help display
*/
export const commandsByCategory = {
primary: [
initCommand,
startCommand,
statusCommand,
agentCommand,
swarmCommand,
memoryCommand,
taskCommand,
sessionCommand,
mcpCommand,
hooksCommand,
],
advanced: [
neuralCommand,
securityCommand,
performanceCommand,
embeddingsCommand,
hiveMindCommand,
ruvectorCommand,
guidanceCommand,
],
utility: [
configCommand,
doctorCommand,
daemonCommand,
completionsCommand,
migrateCommand,
workflowCommand,
],
analysis: [
analyzeCommand,
routeCommand,
progressCommand,
],
management: [
providersCommand,
pluginsCommand,
deploymentCommand,
claimsCommand,
issuesCommand,
updateCommand,
processCommand,
],
};
/**
* Command registry map for quick lookup
* Supports both sync (core commands) and async (lazy-loaded) commands
*/
export const commandRegistry = new Map();
// Register core commands and their aliases
for (const cmd of commands) {
commandRegistry.set(cmd.name, cmd);
if (cmd.aliases) {
for (const alias of cmd.aliases) {
commandRegistry.set(alias, cmd);
}
}
}
/**
* Get command by name (sync for core commands, returns undefined for lazy commands)
* Use getCommandAsync for lazy-loaded commands
*/
export function getCommand(name) {
return loadedCommands.get(name) || commandRegistry.get(name);
}
/**
* Get command by name (async - supports lazy loading)
*/
export async function getCommandAsync(name) {
// Check already-loaded commands first
const cached = loadedCommands.get(name);
if (cached)
return cached;
// Check sync registry
const synced = commandRegistry.get(name);
if (synced)
return synced;
// Try lazy loading
return loadCommand(name);
}
/**
* Check if command exists (sync check for core commands)
*/
export function hasCommand(name) {
return loadedCommands.has(name) || commandRegistry.has(name) || name in commandLoaders;
}
/**
* Get all command names (including aliases and lazy-loadable)
*/
export function getCommandNames() {
const names = new Set([
...Array.from(commandRegistry.keys()),
...Array.from(loadedCommands.keys()),
...Object.keys(commandLoaders),
]);
return Array.from(names);
}
/**
* Get all unique commands (excluding aliases)
*/
export function getUniqueCommands() {
return commands.filter(cmd => !cmd.hidden);
}
/**
* Load all commands (populates lazy-loaded commands)
* Use this when you need all commands available synchronously
*/
export async function loadAllCommands() {
const allCommands = [...commands];
for (const name of Object.keys(commandLoaders)) {
if (!loadedCommands.has(name)) {
const cmd = await loadCommand(name);
if (cmd && !allCommands.includes(cmd)) {
allCommands.push(cmd);
}
}
}
return allCommands;
}
/**
* Setup commands in a CLI instance
*/
export function setupCommands(cli) {
for (const cmd of commands) {
cli.command(cmd);
}
}
/**
* Setup all commands including lazy-loaded (async)
*/
export async function setupAllCommands(cli) {
const allCommands = await loadAllCommands();
for (const cmd of allCommands) {
cli.command(cmd);
}
}
//# sourceMappingURL=index.js.map