@claude-flow/cli 3.0.0-alpha.13 → 3.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/commands/doctor.d.ts.map +1 -1
- package/dist/src/commands/doctor.js +75 -2
- package/dist/src/commands/doctor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -4
- package/.agentic-flow/intelligence.json +0 -17
- package/.claude-flow/agents/store.json +0 -16
- package/.claude-flow/daemon-state.json +0 -123
- package/.claude-flow/daemon-test.log +0 -0
- package/.claude-flow/daemon.log +0 -0
- package/.claude-flow/daemon2.log +0 -0
- package/.claude-flow/daemon3.log +0 -0
- package/.claude-flow/hive-mind/state.json +0 -51
- package/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude-flow/metrics/codebase-map.json +0 -11
- package/.claude-flow/metrics/consolidation.json +0 -6
- package/.claude-flow/metrics/performance.json +0 -87
- package/.claude-flow/metrics/security-audit.json +0 -10
- package/.claude-flow/metrics/task-metrics.json +0 -10
- package/.claude-flow/metrics/test-gaps.json +0 -6
- package/__tests__/README.md +0 -140
- package/__tests__/TEST_SUMMARY.md +0 -144
- package/__tests__/cli.test.ts +0 -558
- package/__tests__/commands.test.ts +0 -726
- package/__tests__/config-adapter.test.ts +0 -362
- package/__tests__/config-loading.test.ts +0 -106
- package/__tests__/coverage/.tmp/coverage-0.json +0 -1
- package/__tests__/coverage/.tmp/coverage-1.json +0 -1
- package/__tests__/coverage/.tmp/coverage-2.json +0 -1
- package/__tests__/coverage/.tmp/coverage-3.json +0 -1
- package/__tests__/coverage/.tmp/coverage-4.json +0 -1
- package/__tests__/coverage/.tmp/coverage-5.json +0 -1
- package/__tests__/mcp-client.test.ts +0 -480
- package/__tests__/p1-commands.test.ts +0 -1064
- package/agents/architect.yaml +0 -11
- package/agents/coder.yaml +0 -11
- package/agents/reviewer.yaml +0 -10
- package/agents/security-architect.yaml +0 -10
- package/agents/tester.yaml +0 -10
- package/docs/CONFIG_LOADING.md +0 -236
- package/docs/IMPLEMENTATION_COMPLETE.md +0 -421
- package/docs/MCP_CLIENT_GUIDE.md +0 -620
- package/docs/REFACTORING_SUMMARY.md +0 -247
- package/scripts/publish.sh +0 -46
- package/src/commands/agent.ts +0 -955
- package/src/commands/claims.ts +0 -317
- package/src/commands/completions.ts +0 -558
- package/src/commands/config.ts +0 -452
- package/src/commands/daemon.ts +0 -621
- package/src/commands/deployment.ts +0 -323
- package/src/commands/doctor.ts +0 -382
- package/src/commands/embeddings.ts +0 -686
- package/src/commands/hive-mind.ts +0 -928
- package/src/commands/hooks.ts +0 -2603
- package/src/commands/index.ts +0 -154
- package/src/commands/init.ts +0 -597
- package/src/commands/mcp.ts +0 -753
- package/src/commands/memory.ts +0 -1161
- package/src/commands/migrate.ts +0 -447
- package/src/commands/neural.ts +0 -253
- package/src/commands/performance.ts +0 -292
- package/src/commands/plugins.ts +0 -316
- package/src/commands/process.ts +0 -695
- package/src/commands/providers.ts +0 -259
- package/src/commands/security.ts +0 -288
- package/src/commands/session.ts +0 -891
- package/src/commands/start.ts +0 -457
- package/src/commands/status.ts +0 -736
- package/src/commands/swarm.ts +0 -648
- package/src/commands/task.ts +0 -792
- package/src/commands/workflow.ts +0 -742
- package/src/config-adapter.ts +0 -210
- package/src/index.ts +0 -443
- package/src/infrastructure/in-memory-repositories.ts +0 -310
- package/src/init/claudemd-generator.ts +0 -631
- package/src/init/executor.ts +0 -762
- package/src/init/helpers-generator.ts +0 -628
- package/src/init/index.ts +0 -60
- package/src/init/mcp-generator.ts +0 -83
- package/src/init/settings-generator.ts +0 -284
- package/src/init/statusline-generator.ts +0 -211
- package/src/init/types.ts +0 -447
- package/src/mcp-client.ts +0 -241
- package/src/mcp-server.ts +0 -577
- package/src/mcp-tools/agent-tools.ts +0 -466
- package/src/mcp-tools/config-tools.ts +0 -370
- package/src/mcp-tools/hive-mind-tools.ts +0 -521
- package/src/mcp-tools/hooks-tools.ts +0 -1888
- package/src/mcp-tools/index.ts +0 -16
- package/src/mcp-tools/memory-tools.ts +0 -270
- package/src/mcp-tools/session-tools.ts +0 -359
- package/src/mcp-tools/swarm-tools.ts +0 -105
- package/src/mcp-tools/task-tools.ts +0 -347
- package/src/mcp-tools/types.ts +0 -33
- package/src/mcp-tools/workflow-tools.ts +0 -573
- package/src/output.ts +0 -639
- package/src/parser.ts +0 -417
- package/src/prompt.ts +0 -619
- package/src/services/index.ts +0 -15
- package/src/services/worker-daemon.ts +0 -726
- package/src/suggest.ts +0 -245
- package/src/types.ts +0 -287
- package/tmp.json +0 -0
- package/tsconfig.json +0 -16
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -13
package/src/config-adapter.ts
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration Adapter
|
|
3
|
-
* Converts between SystemConfig and V3Config types
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { SystemConfig } from '@claude-flow/shared';
|
|
7
|
-
import type { V3Config } from './types.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Convert SystemConfig to V3Config (CLI-specific format)
|
|
11
|
-
*/
|
|
12
|
-
export function systemConfigToV3Config(systemConfig: SystemConfig): V3Config {
|
|
13
|
-
return {
|
|
14
|
-
version: '3.0.0',
|
|
15
|
-
projectRoot: systemConfig.orchestrator?.session?.dataDir || process.cwd(),
|
|
16
|
-
|
|
17
|
-
// Agent configuration
|
|
18
|
-
agents: {
|
|
19
|
-
defaultType: 'coder',
|
|
20
|
-
autoSpawn: false, // Not in SystemConfig
|
|
21
|
-
maxConcurrent: systemConfig.orchestrator?.lifecycle?.maxConcurrentAgents ?? 15,
|
|
22
|
-
timeout: systemConfig.orchestrator?.lifecycle?.spawnTimeout ?? 300000,
|
|
23
|
-
providers: [],
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
// Swarm configuration
|
|
27
|
-
swarm: {
|
|
28
|
-
topology: normalizeTopology(systemConfig.swarm?.topology),
|
|
29
|
-
maxAgents: systemConfig.swarm?.maxAgents ?? 15,
|
|
30
|
-
autoScale: systemConfig.swarm?.autoScale?.enabled ?? false,
|
|
31
|
-
coordinationStrategy: systemConfig.swarm?.coordination?.consensusRequired ? 'consensus' : 'leader',
|
|
32
|
-
healthCheckInterval: systemConfig.swarm?.coordination?.timeoutMs ?? 10000,
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
// Memory configuration
|
|
36
|
-
memory: {
|
|
37
|
-
backend: normalizeMemoryBackend(systemConfig.memory?.type),
|
|
38
|
-
persistPath: systemConfig.memory?.path || './data/memory',
|
|
39
|
-
cacheSize: systemConfig.memory?.maxSize ?? 1000000,
|
|
40
|
-
enableHNSW: systemConfig.memory?.agentdb?.indexType === 'hnsw',
|
|
41
|
-
vectorDimension: systemConfig.memory?.agentdb?.dimensions ?? 1536,
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
// MCP configuration
|
|
45
|
-
mcp: {
|
|
46
|
-
serverHost: systemConfig.mcp?.transport?.host || 'localhost',
|
|
47
|
-
serverPort: systemConfig.mcp?.transport?.port ?? 3000,
|
|
48
|
-
autoStart: false, // Not in SystemConfig
|
|
49
|
-
transportType: systemConfig.mcp?.transport?.type || 'stdio',
|
|
50
|
-
tools: [], // Not in SystemConfig
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// CLI preferences
|
|
54
|
-
cli: {
|
|
55
|
-
colorOutput: true,
|
|
56
|
-
interactive: true,
|
|
57
|
-
verbosity: 'normal',
|
|
58
|
-
outputFormat: 'text',
|
|
59
|
-
progressStyle: 'spinner',
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
// Hooks configuration
|
|
63
|
-
hooks: {
|
|
64
|
-
enabled: false,
|
|
65
|
-
autoExecute: false,
|
|
66
|
-
hooks: [],
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Convert V3Config to SystemConfig
|
|
73
|
-
*/
|
|
74
|
-
export function v3ConfigToSystemConfig(v3Config: V3Config): Partial<SystemConfig> {
|
|
75
|
-
return {
|
|
76
|
-
orchestrator: {
|
|
77
|
-
lifecycle: {
|
|
78
|
-
maxConcurrentAgents: v3Config.agents.maxConcurrent,
|
|
79
|
-
spawnTimeout: v3Config.agents.timeout,
|
|
80
|
-
terminateTimeout: 10000,
|
|
81
|
-
maxSpawnRetries: 3,
|
|
82
|
-
},
|
|
83
|
-
session: {
|
|
84
|
-
dataDir: v3Config.projectRoot,
|
|
85
|
-
persistSessions: true,
|
|
86
|
-
sessionRetentionMs: 3600000,
|
|
87
|
-
},
|
|
88
|
-
health: {
|
|
89
|
-
checkInterval: v3Config.swarm.healthCheckInterval,
|
|
90
|
-
historyLimit: 100,
|
|
91
|
-
degradedThreshold: 1,
|
|
92
|
-
unhealthyThreshold: 2,
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
swarm: {
|
|
97
|
-
topology: denormalizeTopology(v3Config.swarm.topology),
|
|
98
|
-
maxAgents: v3Config.swarm.maxAgents,
|
|
99
|
-
autoScale: {
|
|
100
|
-
enabled: v3Config.swarm.autoScale,
|
|
101
|
-
minAgents: 1,
|
|
102
|
-
maxAgents: v3Config.swarm.maxAgents,
|
|
103
|
-
scaleUpThreshold: 0.8,
|
|
104
|
-
scaleDownThreshold: 0.3,
|
|
105
|
-
},
|
|
106
|
-
coordination: {
|
|
107
|
-
consensusRequired: v3Config.swarm.coordinationStrategy === 'consensus',
|
|
108
|
-
timeoutMs: v3Config.swarm.healthCheckInterval,
|
|
109
|
-
retryPolicy: {
|
|
110
|
-
maxRetries: 3,
|
|
111
|
-
backoffMs: 500,
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
communication: {
|
|
115
|
-
protocol: 'events',
|
|
116
|
-
batchSize: 10,
|
|
117
|
-
flushIntervalMs: 100,
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
memory: {
|
|
122
|
-
type: denormalizeMemoryBackend(v3Config.memory.backend),
|
|
123
|
-
path: v3Config.memory.persistPath,
|
|
124
|
-
maxSize: v3Config.memory.cacheSize,
|
|
125
|
-
agentdb: {
|
|
126
|
-
dimensions: v3Config.memory.vectorDimension,
|
|
127
|
-
indexType: v3Config.memory.enableHNSW ? 'hnsw' : 'flat',
|
|
128
|
-
efConstruction: 200,
|
|
129
|
-
m: 16,
|
|
130
|
-
quantization: 'none',
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
mcp: {
|
|
135
|
-
name: 'claude-flow',
|
|
136
|
-
version: '3.0.0',
|
|
137
|
-
transport: {
|
|
138
|
-
type: v3Config.mcp.transportType as 'stdio' | 'http' | 'websocket',
|
|
139
|
-
host: v3Config.mcp.serverHost,
|
|
140
|
-
port: v3Config.mcp.serverPort,
|
|
141
|
-
},
|
|
142
|
-
capabilities: {
|
|
143
|
-
tools: true,
|
|
144
|
-
resources: true,
|
|
145
|
-
prompts: true,
|
|
146
|
-
logging: true,
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Normalize topology from SystemConfig to V3Config
|
|
154
|
-
*/
|
|
155
|
-
function normalizeTopology(
|
|
156
|
-
topology: string | undefined
|
|
157
|
-
): 'hierarchical' | 'mesh' | 'ring' | 'star' | 'hybrid' {
|
|
158
|
-
switch (topology) {
|
|
159
|
-
case 'hierarchical':
|
|
160
|
-
case 'mesh':
|
|
161
|
-
case 'ring':
|
|
162
|
-
case 'star':
|
|
163
|
-
return topology;
|
|
164
|
-
case 'hierarchical-mesh':
|
|
165
|
-
case 'adaptive':
|
|
166
|
-
return 'hybrid';
|
|
167
|
-
default:
|
|
168
|
-
return 'hierarchical';
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Denormalize topology from V3Config to SystemConfig
|
|
174
|
-
*/
|
|
175
|
-
function denormalizeTopology(
|
|
176
|
-
topology: 'hierarchical' | 'mesh' | 'ring' | 'star' | 'hybrid'
|
|
177
|
-
): 'hierarchical' | 'mesh' | 'ring' | 'star' | 'adaptive' | 'hierarchical-mesh' {
|
|
178
|
-
if (topology === 'hybrid') {
|
|
179
|
-
return 'hierarchical-mesh';
|
|
180
|
-
}
|
|
181
|
-
return topology;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Normalize memory backend from SystemConfig to V3Config
|
|
186
|
-
*/
|
|
187
|
-
function normalizeMemoryBackend(
|
|
188
|
-
backend: string | undefined
|
|
189
|
-
): 'memory' | 'sqlite' | 'agentdb' | 'hybrid' {
|
|
190
|
-
switch (backend) {
|
|
191
|
-
case 'memory':
|
|
192
|
-
case 'sqlite':
|
|
193
|
-
case 'agentdb':
|
|
194
|
-
case 'hybrid':
|
|
195
|
-
return backend;
|
|
196
|
-
case 'redis':
|
|
197
|
-
return 'memory'; // Redis maps to memory for CLI purposes
|
|
198
|
-
default:
|
|
199
|
-
return 'hybrid';
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Denormalize memory backend from V3Config to SystemConfig
|
|
205
|
-
*/
|
|
206
|
-
function denormalizeMemoryBackend(
|
|
207
|
-
backend: 'memory' | 'sqlite' | 'agentdb' | 'hybrid'
|
|
208
|
-
): 'memory' | 'sqlite' | 'agentdb' | 'hybrid' | 'redis' {
|
|
209
|
-
return backend;
|
|
210
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* V3 CLI Main Entry Point
|
|
3
|
-
* Modernized CLI for Claude Flow V3
|
|
4
|
-
*
|
|
5
|
-
* Created with ❤️ by ruv.io
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { readFileSync } from 'fs';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
import { dirname, join } from 'path';
|
|
11
|
-
import type { Command, CommandContext, CommandResult, V3Config, CLIError } from './types.js';
|
|
12
|
-
import { CommandParser, commandParser } from './parser.js';
|
|
13
|
-
import { OutputFormatter, output } from './output.js';
|
|
14
|
-
import { commands, commandRegistry, getCommand, getCommandNames } from './commands/index.js';
|
|
15
|
-
import { suggestCommand } from './suggest.js';
|
|
16
|
-
|
|
17
|
-
// Read version from package.json at runtime
|
|
18
|
-
function getPackageVersion(): string {
|
|
19
|
-
try {
|
|
20
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
-
const __dirname = dirname(__filename);
|
|
22
|
-
// Navigate from dist/src to package root
|
|
23
|
-
const pkgPath = join(__dirname, '..', '..', 'package.json');
|
|
24
|
-
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
25
|
-
return pkg.version || '3.0.0';
|
|
26
|
-
} catch {
|
|
27
|
-
return '3.0.0';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const VERSION = getPackageVersion();
|
|
32
|
-
|
|
33
|
-
export interface CLIOptions {
|
|
34
|
-
name?: string;
|
|
35
|
-
description?: string;
|
|
36
|
-
version?: string;
|
|
37
|
-
interactive?: boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* V3 CLI Application
|
|
42
|
-
*/
|
|
43
|
-
export class CLI {
|
|
44
|
-
private name: string;
|
|
45
|
-
private description: string;
|
|
46
|
-
private version: string;
|
|
47
|
-
private parser: CommandParser;
|
|
48
|
-
private output: OutputFormatter;
|
|
49
|
-
private interactive: boolean;
|
|
50
|
-
|
|
51
|
-
constructor(options: CLIOptions = {}) {
|
|
52
|
-
this.name = options.name || 'claude-flow';
|
|
53
|
-
this.description = options.description || 'Claude Flow V3 - AI Agent Orchestration Platform';
|
|
54
|
-
this.version = options.version || VERSION;
|
|
55
|
-
this.parser = commandParser;
|
|
56
|
-
this.output = output;
|
|
57
|
-
this.interactive = options.interactive ?? process.stdin.isTTY ?? false;
|
|
58
|
-
|
|
59
|
-
// Register all commands
|
|
60
|
-
for (const cmd of commands) {
|
|
61
|
-
this.parser.registerCommand(cmd);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Run the CLI with given arguments
|
|
67
|
-
*/
|
|
68
|
-
async run(args: string[] = process.argv.slice(2)): Promise<void> {
|
|
69
|
-
try {
|
|
70
|
-
// Parse arguments
|
|
71
|
-
const parseResult = this.parser.parse(args);
|
|
72
|
-
const { command: commandPath, flags, positional } = parseResult;
|
|
73
|
-
|
|
74
|
-
// Handle global flags
|
|
75
|
-
if (flags.version || flags.V) {
|
|
76
|
-
this.showVersion();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (flags.noColor) {
|
|
81
|
-
this.output.setColorEnabled(false);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Set verbosity level based on flags
|
|
85
|
-
if (flags.quiet) {
|
|
86
|
-
this.output.setVerbosity('quiet');
|
|
87
|
-
} else if (flags.verbose) {
|
|
88
|
-
this.output.setVerbosity(process.env.DEBUG ? 'debug' : 'verbose');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Verbose mode: show parsed arguments
|
|
92
|
-
if (this.output.isVerbose()) {
|
|
93
|
-
this.output.printDebug(`Command: ${commandPath.join(' ') || '(none)'}`);
|
|
94
|
-
this.output.printDebug(`Positional: [${positional.join(', ')}]`);
|
|
95
|
-
this.output.printDebug(`Flags: ${JSON.stringify(Object.fromEntries(Object.entries(flags).filter(([k]) => k !== '_')))}`);
|
|
96
|
-
this.output.printDebug(`CWD: ${process.cwd()}`);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// No command - show help or suggest correction
|
|
100
|
-
if (commandPath.length === 0 || flags.help || flags.h) {
|
|
101
|
-
if (commandPath.length > 0) {
|
|
102
|
-
// Show command-specific help
|
|
103
|
-
this.showCommandHelp(commandPath[0]);
|
|
104
|
-
} else if (positional.length > 0 && !positional[0].startsWith('-')) {
|
|
105
|
-
// First positional looks like an attempted command - suggest correction
|
|
106
|
-
const attemptedCommand = positional[0];
|
|
107
|
-
this.output.printError(`Unknown command: ${attemptedCommand}`);
|
|
108
|
-
const availableCommands = Array.from(new Set(commands.map(c => c.name)));
|
|
109
|
-
const { message } = suggestCommand(attemptedCommand, availableCommands);
|
|
110
|
-
this.output.writeln(this.output.dim(` ${message}`));
|
|
111
|
-
process.exit(1);
|
|
112
|
-
} else {
|
|
113
|
-
this.showHelp();
|
|
114
|
-
}
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Find and execute command
|
|
119
|
-
const commandName = commandPath[0];
|
|
120
|
-
// First check the parser's registry (for dynamically registered commands)
|
|
121
|
-
// Then fall back to the static registry
|
|
122
|
-
const command = this.parser.getCommand(commandName) || getCommand(commandName);
|
|
123
|
-
|
|
124
|
-
if (!command) {
|
|
125
|
-
this.output.printError(`Unknown command: ${commandName}`);
|
|
126
|
-
// Smart suggestions
|
|
127
|
-
const availableCommands = Array.from(new Set(commands.map(c => c.name)));
|
|
128
|
-
const { message } = suggestCommand(commandName, availableCommands);
|
|
129
|
-
this.output.writeln(this.output.dim(` ${message}`));
|
|
130
|
-
process.exit(1);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Handle subcommand (supports nested subcommands)
|
|
134
|
-
let targetCommand = command;
|
|
135
|
-
let subcommandArgs = positional;
|
|
136
|
-
|
|
137
|
-
// Process command path (e.g., ['hooks', 'worker', 'list'])
|
|
138
|
-
// Note: When parser includes subcommand in commandPath, positional already excludes it
|
|
139
|
-
if (commandPath.length > 1 && command.subcommands) {
|
|
140
|
-
const subcommandName = commandPath[1];
|
|
141
|
-
const subcommand = command.subcommands.find(
|
|
142
|
-
sc => sc.name === subcommandName || sc.aliases?.includes(subcommandName)
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
if (subcommand) {
|
|
146
|
-
targetCommand = subcommand;
|
|
147
|
-
// Parser already extracted subcommand from positional, so use as-is
|
|
148
|
-
subcommandArgs = positional;
|
|
149
|
-
|
|
150
|
-
// Check for nested subcommand (level 2)
|
|
151
|
-
if (commandPath.length > 2 && subcommand.subcommands) {
|
|
152
|
-
const nestedName = commandPath[2];
|
|
153
|
-
const nestedSubcommand = subcommand.subcommands.find(
|
|
154
|
-
sc => sc.name === nestedName || sc.aliases?.includes(nestedName)
|
|
155
|
-
);
|
|
156
|
-
if (nestedSubcommand) {
|
|
157
|
-
targetCommand = nestedSubcommand;
|
|
158
|
-
// Parser already extracted nested subcommand too
|
|
159
|
-
subcommandArgs = positional;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
} else if (positional.length > 0 && command.subcommands) {
|
|
164
|
-
// Check if first positional is a subcommand
|
|
165
|
-
const subcommandName = positional[0];
|
|
166
|
-
const subcommand = command.subcommands.find(
|
|
167
|
-
sc => sc.name === subcommandName || sc.aliases?.includes(subcommandName)
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
if (subcommand) {
|
|
171
|
-
targetCommand = subcommand;
|
|
172
|
-
subcommandArgs = positional.slice(1);
|
|
173
|
-
|
|
174
|
-
// Check for nested subcommand (level 2 from positional)
|
|
175
|
-
if (subcommandArgs.length > 0 && subcommand.subcommands) {
|
|
176
|
-
const nestedName = subcommandArgs[0];
|
|
177
|
-
const nestedSubcommand = subcommand.subcommands.find(
|
|
178
|
-
sc => sc.name === nestedName || sc.aliases?.includes(nestedName)
|
|
179
|
-
);
|
|
180
|
-
if (nestedSubcommand) {
|
|
181
|
-
targetCommand = nestedSubcommand;
|
|
182
|
-
subcommandArgs = subcommandArgs.slice(1);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Validate flags
|
|
189
|
-
const validationErrors = this.parser.validateFlags(flags, targetCommand);
|
|
190
|
-
if (validationErrors.length > 0) {
|
|
191
|
-
for (const error of validationErrors) {
|
|
192
|
-
this.output.printError(error);
|
|
193
|
-
}
|
|
194
|
-
process.exit(1);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Build context
|
|
198
|
-
const ctx: CommandContext = {
|
|
199
|
-
args: subcommandArgs,
|
|
200
|
-
flags,
|
|
201
|
-
config: await this.loadConfig(flags.config as string),
|
|
202
|
-
cwd: process.cwd(),
|
|
203
|
-
interactive: this.interactive && !flags.quiet
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
// Execute command
|
|
207
|
-
if (targetCommand.action) {
|
|
208
|
-
if (this.output.isVerbose()) {
|
|
209
|
-
this.output.printDebug(`Executing: ${targetCommand.name}`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const startTime = Date.now();
|
|
213
|
-
const result = await targetCommand.action(ctx);
|
|
214
|
-
|
|
215
|
-
if (this.output.isVerbose()) {
|
|
216
|
-
this.output.printDebug(`Completed in ${Date.now() - startTime}ms`);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (result && !result.success) {
|
|
220
|
-
process.exit(result.exitCode || 1);
|
|
221
|
-
}
|
|
222
|
-
} else {
|
|
223
|
-
// No action - show command help
|
|
224
|
-
this.showCommandHelp(commandName);
|
|
225
|
-
}
|
|
226
|
-
} catch (error) {
|
|
227
|
-
// Don't re-handle if this is a process.exit error (from mocked tests)
|
|
228
|
-
const errorMessage = (error as Error).message;
|
|
229
|
-
if (errorMessage && errorMessage.startsWith('process.exit:')) {
|
|
230
|
-
throw error; // Re-throw so tests can capture the exit code
|
|
231
|
-
}
|
|
232
|
-
this.handleError(error as Error);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Show main help
|
|
238
|
-
*/
|
|
239
|
-
private showHelp(): void {
|
|
240
|
-
this.output.writeln();
|
|
241
|
-
this.output.writeln(this.output.bold(`${this.name} v${this.version}`));
|
|
242
|
-
this.output.writeln(this.output.dim(this.description));
|
|
243
|
-
this.output.writeln();
|
|
244
|
-
|
|
245
|
-
this.output.writeln(this.output.bold('USAGE:'));
|
|
246
|
-
this.output.writeln(` ${this.name} <command> [subcommand] [options]`);
|
|
247
|
-
this.output.writeln();
|
|
248
|
-
|
|
249
|
-
this.output.writeln(this.output.bold('COMMANDS:'));
|
|
250
|
-
for (const cmd of commands) {
|
|
251
|
-
if (cmd.hidden) continue;
|
|
252
|
-
const name = cmd.name.padEnd(12);
|
|
253
|
-
this.output.writeln(` ${this.output.highlight(name)} ${cmd.description}`);
|
|
254
|
-
}
|
|
255
|
-
this.output.writeln();
|
|
256
|
-
|
|
257
|
-
this.output.writeln(this.output.bold('GLOBAL OPTIONS:'));
|
|
258
|
-
for (const opt of this.parser.getGlobalOptions()) {
|
|
259
|
-
const flags = opt.short ? `-${opt.short}, --${opt.name}` : ` --${opt.name}`;
|
|
260
|
-
this.output.writeln(` ${flags.padEnd(25)} ${opt.description}`);
|
|
261
|
-
}
|
|
262
|
-
this.output.writeln();
|
|
263
|
-
|
|
264
|
-
this.output.writeln(this.output.bold('V3 FEATURES:'));
|
|
265
|
-
this.output.printList([
|
|
266
|
-
'15-agent hierarchical mesh coordination',
|
|
267
|
-
'AgentDB with HNSW indexing (150x-12,500x faster)',
|
|
268
|
-
'Flash Attention (2.49x-7.47x speedup)',
|
|
269
|
-
'Unified SwarmCoordinator engine',
|
|
270
|
-
'Event-sourced state management',
|
|
271
|
-
'Domain-Driven Design architecture'
|
|
272
|
-
]);
|
|
273
|
-
this.output.writeln();
|
|
274
|
-
|
|
275
|
-
this.output.writeln(this.output.bold('EXAMPLES:'));
|
|
276
|
-
this.output.writeln(` ${this.name} agent spawn -t coder # Spawn a coder agent`);
|
|
277
|
-
this.output.writeln(` ${this.name} swarm init --v3-mode # Initialize V3 swarm`);
|
|
278
|
-
this.output.writeln(` ${this.name} memory search -q "auth patterns" # Semantic search`);
|
|
279
|
-
this.output.writeln(` ${this.name} mcp start # Start MCP server`);
|
|
280
|
-
this.output.writeln();
|
|
281
|
-
|
|
282
|
-
this.output.writeln(this.output.dim('Run "claude-flow <command> --help" for command help'));
|
|
283
|
-
this.output.writeln();
|
|
284
|
-
this.output.writeln(this.output.dim('Created with ❤️ by ruv.io'));
|
|
285
|
-
this.output.writeln();
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Show command-specific help
|
|
290
|
-
*/
|
|
291
|
-
private showCommandHelp(commandName: string): void {
|
|
292
|
-
const command = getCommand(commandName);
|
|
293
|
-
|
|
294
|
-
if (!command) {
|
|
295
|
-
this.output.printError(`Unknown command: ${commandName}`);
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
this.output.writeln();
|
|
300
|
-
this.output.writeln(this.output.bold(`${this.name} ${command.name}`));
|
|
301
|
-
this.output.writeln(command.description);
|
|
302
|
-
this.output.writeln();
|
|
303
|
-
|
|
304
|
-
// Subcommands
|
|
305
|
-
if (command.subcommands && command.subcommands.length > 0) {
|
|
306
|
-
this.output.writeln(this.output.bold('SUBCOMMANDS:'));
|
|
307
|
-
for (const sub of command.subcommands) {
|
|
308
|
-
if (sub.hidden) continue;
|
|
309
|
-
const name = sub.name.padEnd(15);
|
|
310
|
-
const aliases = sub.aliases ? this.output.dim(` (${sub.aliases.join(', ')})`) : '';
|
|
311
|
-
this.output.writeln(` ${this.output.highlight(name)} ${sub.description}${aliases}`);
|
|
312
|
-
}
|
|
313
|
-
this.output.writeln();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Options
|
|
317
|
-
if (command.options && command.options.length > 0) {
|
|
318
|
-
this.output.writeln(this.output.bold('OPTIONS:'));
|
|
319
|
-
for (const opt of command.options) {
|
|
320
|
-
const flags = opt.short ? `-${opt.short}, --${opt.name}` : ` --${opt.name}`;
|
|
321
|
-
const required = opt.required ? this.output.error(' (required)') : '';
|
|
322
|
-
const defaultVal = opt.default !== undefined ? this.output.dim(` [default: ${opt.default}]`) : '';
|
|
323
|
-
this.output.writeln(` ${flags.padEnd(25)} ${opt.description}${required}${defaultVal}`);
|
|
324
|
-
}
|
|
325
|
-
this.output.writeln();
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// Examples
|
|
329
|
-
if (command.examples && command.examples.length > 0) {
|
|
330
|
-
this.output.writeln(this.output.bold('EXAMPLES:'));
|
|
331
|
-
for (const example of command.examples) {
|
|
332
|
-
this.output.writeln(` ${this.output.dim('$')} ${example.command}`);
|
|
333
|
-
this.output.writeln(` ${this.output.dim(example.description)}`);
|
|
334
|
-
}
|
|
335
|
-
this.output.writeln();
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Show version
|
|
341
|
-
*/
|
|
342
|
-
private showVersion(): void {
|
|
343
|
-
this.output.writeln(`${this.name} v${this.version}`);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Load configuration file
|
|
348
|
-
*/
|
|
349
|
-
private async loadConfig(configPath?: string): Promise<V3Config | undefined> {
|
|
350
|
-
try {
|
|
351
|
-
// Import config utilities
|
|
352
|
-
const { loadConfig: loadSystemConfig } = await import('@claude-flow/shared');
|
|
353
|
-
const { systemConfigToV3Config } = await import('./config-adapter.js');
|
|
354
|
-
|
|
355
|
-
// Load configuration
|
|
356
|
-
const loaded = await loadSystemConfig({
|
|
357
|
-
file: configPath,
|
|
358
|
-
paths: configPath ? undefined : [process.cwd()],
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
// Convert to V3Config format
|
|
362
|
-
const v3Config = systemConfigToV3Config(loaded.config);
|
|
363
|
-
|
|
364
|
-
// Log warnings if any
|
|
365
|
-
if (loaded.warnings && loaded.warnings.length > 0) {
|
|
366
|
-
for (const warning of loaded.warnings) {
|
|
367
|
-
this.output.printWarning(warning);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return v3Config;
|
|
372
|
-
} catch (error) {
|
|
373
|
-
// Config loading is optional - don't fail if it doesn't exist
|
|
374
|
-
if (process.env.DEBUG) {
|
|
375
|
-
this.output.writeln(
|
|
376
|
-
this.output.dim(`Config loading failed: ${(error as Error).message}`)
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
return undefined;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Handle errors
|
|
385
|
-
*/
|
|
386
|
-
private handleError(error: Error): void {
|
|
387
|
-
if ('code' in error) {
|
|
388
|
-
// CLIError
|
|
389
|
-
const cliError = error as CLIError;
|
|
390
|
-
this.output.printError(cliError.message);
|
|
391
|
-
|
|
392
|
-
if (cliError.details) {
|
|
393
|
-
this.output.writeln(this.output.dim(JSON.stringify(cliError.details, null, 2)));
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
process.exit(cliError.exitCode);
|
|
397
|
-
} else {
|
|
398
|
-
// Generic error
|
|
399
|
-
this.output.printError(error.message);
|
|
400
|
-
|
|
401
|
-
if (process.env.DEBUG) {
|
|
402
|
-
this.output.writeln();
|
|
403
|
-
this.output.writeln(this.output.dim(error.stack || ''));
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
process.exit(1);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// =============================================================================
|
|
412
|
-
// Module Exports
|
|
413
|
-
// =============================================================================
|
|
414
|
-
|
|
415
|
-
// Types
|
|
416
|
-
export * from './types.js';
|
|
417
|
-
|
|
418
|
-
// Parser
|
|
419
|
-
export { CommandParser, commandParser } from './parser.js';
|
|
420
|
-
|
|
421
|
-
// Output
|
|
422
|
-
export { OutputFormatter, output, Progress, Spinner, type VerbosityLevel } from './output.js';
|
|
423
|
-
|
|
424
|
-
// Prompt
|
|
425
|
-
export * from './prompt.js';
|
|
426
|
-
|
|
427
|
-
// Commands (internal use)
|
|
428
|
-
export * from './commands/index.js';
|
|
429
|
-
|
|
430
|
-
// MCP Server management
|
|
431
|
-
export {
|
|
432
|
-
MCPServerManager,
|
|
433
|
-
createMCPServerManager,
|
|
434
|
-
getServerManager,
|
|
435
|
-
startMCPServer,
|
|
436
|
-
stopMCPServer,
|
|
437
|
-
getMCPServerStatus,
|
|
438
|
-
type MCPServerOptions,
|
|
439
|
-
type MCPServerStatus,
|
|
440
|
-
} from './mcp-server.js';
|
|
441
|
-
|
|
442
|
-
// Default export
|
|
443
|
-
export default CLI;
|