claude-flow 3.0.0-alpha.10 → 3.0.0-alpha.12
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/README.md +41 -1151
- package/bin/cli.js +30 -8
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -12
- package/dist/src/commands/agent.d.ts +0 -8
- package/dist/src/commands/agent.d.ts.map +0 -1
- package/dist/src/commands/agent.js +0 -819
- package/dist/src/commands/agent.js.map +0 -1
- package/dist/src/commands/config.d.ts +0 -8
- package/dist/src/commands/config.d.ts.map +0 -1
- package/dist/src/commands/config.js +0 -406
- package/dist/src/commands/config.js.map +0 -1
- package/dist/src/commands/daemon.d.ts +0 -8
- package/dist/src/commands/daemon.d.ts.map +0 -1
- package/dist/src/commands/daemon.js +0 -545
- package/dist/src/commands/daemon.js.map +0 -1
- package/dist/src/commands/hive-mind.d.ts +0 -8
- package/dist/src/commands/hive-mind.d.ts.map +0 -1
- package/dist/src/commands/hive-mind.js +0 -844
- package/dist/src/commands/hive-mind.js.map +0 -1
- package/dist/src/commands/hooks.d.ts +0 -8
- package/dist/src/commands/hooks.d.ts.map +0 -1
- package/dist/src/commands/hooks.js +0 -2098
- package/dist/src/commands/hooks.js.map +0 -1
- package/dist/src/commands/index.d.ts +0 -52
- package/dist/src/commands/index.d.ts.map +0 -1
- package/dist/src/commands/index.js +0 -108
- package/dist/src/commands/index.js.map +0 -1
- package/dist/src/commands/init.d.ts +0 -8
- package/dist/src/commands/init.d.ts.map +0 -1
- package/dist/src/commands/init.js +0 -532
- package/dist/src/commands/init.js.map +0 -1
- package/dist/src/commands/mcp.d.ts +0 -11
- package/dist/src/commands/mcp.d.ts.map +0 -1
- package/dist/src/commands/mcp.js +0 -662
- package/dist/src/commands/mcp.js.map +0 -1
- package/dist/src/commands/memory.d.ts +0 -8
- package/dist/src/commands/memory.d.ts.map +0 -1
- package/dist/src/commands/memory.js +0 -977
- package/dist/src/commands/memory.js.map +0 -1
- package/dist/src/commands/migrate.d.ts +0 -8
- package/dist/src/commands/migrate.d.ts.map +0 -1
- package/dist/src/commands/migrate.js +0 -398
- package/dist/src/commands/migrate.js.map +0 -1
- package/dist/src/commands/process.d.ts +0 -10
- package/dist/src/commands/process.d.ts.map +0 -1
- package/dist/src/commands/process.js +0 -641
- package/dist/src/commands/process.js.map +0 -1
- package/dist/src/commands/session.d.ts +0 -8
- package/dist/src/commands/session.d.ts.map +0 -1
- package/dist/src/commands/session.js +0 -750
- package/dist/src/commands/session.js.map +0 -1
- package/dist/src/commands/start.d.ts +0 -8
- package/dist/src/commands/start.d.ts.map +0 -1
- package/dist/src/commands/start.js +0 -398
- package/dist/src/commands/start.js.map +0 -1
- package/dist/src/commands/status.d.ts +0 -8
- package/dist/src/commands/status.d.ts.map +0 -1
- package/dist/src/commands/status.js +0 -584
- package/dist/src/commands/status.js.map +0 -1
- package/dist/src/commands/swarm.d.ts +0 -8
- package/dist/src/commands/swarm.d.ts.map +0 -1
- package/dist/src/commands/swarm.js +0 -573
- package/dist/src/commands/swarm.js.map +0 -1
- package/dist/src/commands/task.d.ts +0 -8
- package/dist/src/commands/task.d.ts.map +0 -1
- package/dist/src/commands/task.js +0 -671
- package/dist/src/commands/task.js.map +0 -1
- package/dist/src/commands/workflow.d.ts +0 -8
- package/dist/src/commands/workflow.d.ts.map +0 -1
- package/dist/src/commands/workflow.js +0 -617
- package/dist/src/commands/workflow.js.map +0 -1
- package/dist/src/config-adapter.d.ts +0 -15
- package/dist/src/config-adapter.d.ts.map +0 -1
- package/dist/src/config-adapter.js +0 -185
- package/dist/src/config-adapter.js.map +0 -1
- package/dist/src/index.d.ts +0 -55
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -353
- package/dist/src/index.js.map +0 -1
- package/dist/src/infrastructure/in-memory-repositories.d.ts +0 -68
- package/dist/src/infrastructure/in-memory-repositories.d.ts.map +0 -1
- package/dist/src/infrastructure/in-memory-repositories.js +0 -264
- package/dist/src/infrastructure/in-memory-repositories.js.map +0 -1
- package/dist/src/init/claudemd-generator.d.ts +0 -15
- package/dist/src/init/claudemd-generator.d.ts.map +0 -1
- package/dist/src/init/claudemd-generator.js +0 -626
- package/dist/src/init/claudemd-generator.js.map +0 -1
- package/dist/src/init/executor.d.ts +0 -11
- package/dist/src/init/executor.d.ts.map +0 -1
- package/dist/src/init/executor.js +0 -652
- package/dist/src/init/executor.js.map +0 -1
- package/dist/src/init/helpers-generator.d.ts +0 -42
- package/dist/src/init/helpers-generator.d.ts.map +0 -1
- package/dist/src/init/helpers-generator.js +0 -613
- package/dist/src/init/helpers-generator.js.map +0 -1
- package/dist/src/init/index.d.ts +0 -12
- package/dist/src/init/index.d.ts.map +0 -1
- package/dist/src/init/index.js +0 -15
- package/dist/src/init/index.js.map +0 -1
- package/dist/src/init/mcp-generator.d.ts +0 -18
- package/dist/src/init/mcp-generator.d.ts.map +0 -1
- package/dist/src/init/mcp-generator.js +0 -71
- package/dist/src/init/mcp-generator.js.map +0 -1
- package/dist/src/init/settings-generator.d.ts +0 -14
- package/dist/src/init/settings-generator.d.ts.map +0 -1
- package/dist/src/init/settings-generator.js +0 -267
- package/dist/src/init/settings-generator.js.map +0 -1
- package/dist/src/init/statusline-generator.d.ts +0 -14
- package/dist/src/init/statusline-generator.d.ts.map +0 -1
- package/dist/src/init/statusline-generator.js +0 -206
- package/dist/src/init/statusline-generator.js.map +0 -1
- package/dist/src/init/types.d.ts +0 -240
- package/dist/src/init/types.d.ts.map +0 -1
- package/dist/src/init/types.js +0 -210
- package/dist/src/init/types.js.map +0 -1
- package/dist/src/mcp-client.d.ts +0 -92
- package/dist/src/mcp-client.d.ts.map +0 -1
- package/dist/src/mcp-client.js +0 -203
- package/dist/src/mcp-client.js.map +0 -1
- package/dist/src/mcp-server.d.ts +0 -153
- package/dist/src/mcp-server.d.ts.map +0 -1
- package/dist/src/mcp-server.js +0 -453
- package/dist/src/mcp-server.js.map +0 -1
- package/dist/src/mcp-tools/agent-tools.d.ts +0 -8
- package/dist/src/mcp-tools/agent-tools.d.ts.map +0 -1
- package/dist/src/mcp-tools/agent-tools.js +0 -426
- package/dist/src/mcp-tools/agent-tools.js.map +0 -1
- package/dist/src/mcp-tools/config-tools.d.ts +0 -8
- package/dist/src/mcp-tools/config-tools.d.ts.map +0 -1
- package/dist/src/mcp-tools/config-tools.js +0 -333
- package/dist/src/mcp-tools/config-tools.js.map +0 -1
- package/dist/src/mcp-tools/hive-mind-tools.d.ts +0 -8
- package/dist/src/mcp-tools/hive-mind-tools.d.ts.map +0 -1
- package/dist/src/mcp-tools/hive-mind-tools.js +0 -447
- package/dist/src/mcp-tools/hive-mind-tools.js.map +0 -1
- package/dist/src/mcp-tools/hooks-tools.d.ts +0 -41
- package/dist/src/mcp-tools/hooks-tools.d.ts.map +0 -1
- package/dist/src/mcp-tools/hooks-tools.js +0 -1711
- package/dist/src/mcp-tools/hooks-tools.js.map +0 -1
- package/dist/src/mcp-tools/index.d.ts +0 -16
- package/dist/src/mcp-tools/index.d.ts.map +0 -1
- package/dist/src/mcp-tools/index.js +0 -15
- package/dist/src/mcp-tools/index.js.map +0 -1
- package/dist/src/mcp-tools/memory-tools.d.ts +0 -8
- package/dist/src/mcp-tools/memory-tools.d.ts.map +0 -1
- package/dist/src/mcp-tools/memory-tools.js +0 -235
- package/dist/src/mcp-tools/memory-tools.js.map +0 -1
- package/dist/src/mcp-tools/session-tools.d.ts +0 -8
- package/dist/src/mcp-tools/session-tools.d.ts.map +0 -1
- package/dist/src/mcp-tools/session-tools.js +0 -315
- package/dist/src/mcp-tools/session-tools.js.map +0 -1
- package/dist/src/mcp-tools/swarm-tools.d.ts +0 -8
- package/dist/src/mcp-tools/swarm-tools.d.ts.map +0 -1
- package/dist/src/mcp-tools/swarm-tools.js +0 -102
- package/dist/src/mcp-tools/swarm-tools.js.map +0 -1
- package/dist/src/mcp-tools/task-tools.d.ts +0 -8
- package/dist/src/mcp-tools/task-tools.d.ts.map +0 -1
- package/dist/src/mcp-tools/task-tools.js +0 -302
- package/dist/src/mcp-tools/task-tools.js.map +0 -1
- package/dist/src/mcp-tools/types.d.ts +0 -31
- package/dist/src/mcp-tools/types.d.ts.map +0 -1
- package/dist/src/mcp-tools/types.js +0 -7
- package/dist/src/mcp-tools/types.js.map +0 -1
- package/dist/src/mcp-tools/workflow-tools.d.ts +0 -8
- package/dist/src/mcp-tools/workflow-tools.d.ts.map +0 -1
- package/dist/src/mcp-tools/workflow-tools.js +0 -481
- package/dist/src/mcp-tools/workflow-tools.js.map +0 -1
- package/dist/src/output.d.ts +0 -133
- package/dist/src/output.d.ts.map +0 -1
- package/dist/src/output.js +0 -513
- package/dist/src/output.js.map +0 -1
- package/dist/src/parser.d.ts +0 -41
- package/dist/src/parser.d.ts.map +0 -1
- package/dist/src/parser.js +0 -353
- package/dist/src/parser.js.map +0 -1
- package/dist/src/prompt.d.ts +0 -44
- package/dist/src/prompt.d.ts.map +0 -1
- package/dist/src/prompt.js +0 -501
- package/dist/src/prompt.js.map +0 -1
- package/dist/src/services/index.d.ts +0 -7
- package/dist/src/services/index.d.ts.map +0 -1
- package/dist/src/services/index.js +0 -6
- package/dist/src/services/index.js.map +0 -1
- package/dist/src/services/worker-daemon.d.ts +0 -153
- package/dist/src/services/worker-daemon.d.ts.map +0 -1
- package/dist/src/services/worker-daemon.js +0 -567
- package/dist/src/services/worker-daemon.js.map +0 -1
- package/dist/src/types.d.ts +0 -198
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -38
- package/dist/src/types.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/commands/agent.ts +0 -955
- package/src/commands/config.ts +0 -452
- package/src/commands/daemon.ts +0 -621
- package/src/commands/hive-mind.ts +0 -928
- package/src/commands/hooks.ts +0 -2603
- package/src/commands/index.ts +0 -118
- 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/process.ts +0 -695
- 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 -427
- 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/types.ts +0 -287
|
@@ -1,844 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* V3 CLI Hive Mind Command
|
|
3
|
-
* Queen-led consensus-based multi-agent coordination
|
|
4
|
-
*/
|
|
5
|
-
import { output } from '../output.js';
|
|
6
|
-
import { select, confirm, input } from '../prompt.js';
|
|
7
|
-
import { callMCPTool, MCPClientError } from '../mcp-client.js';
|
|
8
|
-
// Hive topologies
|
|
9
|
-
const TOPOLOGIES = [
|
|
10
|
-
{ value: 'hierarchical', label: 'Hierarchical', hint: 'Queen-led with worker agents' },
|
|
11
|
-
{ value: 'mesh', label: 'Mesh', hint: 'Peer-to-peer coordination' },
|
|
12
|
-
{ value: 'hierarchical-mesh', label: 'Hierarchical Mesh', hint: 'Queen + peer communication (recommended)' },
|
|
13
|
-
{ value: 'adaptive', label: 'Adaptive', hint: 'Dynamic topology based on task' }
|
|
14
|
-
];
|
|
15
|
-
// Consensus strategies
|
|
16
|
-
const CONSENSUS_STRATEGIES = [
|
|
17
|
-
{ value: 'byzantine', label: 'Byzantine Fault Tolerant', hint: '2/3 majority, handles malicious actors' },
|
|
18
|
-
{ value: 'raft', label: 'Raft', hint: 'Leader-based consensus' },
|
|
19
|
-
{ value: 'gossip', label: 'Gossip', hint: 'Eventually consistent, scalable' },
|
|
20
|
-
{ value: 'crdt', label: 'CRDT', hint: 'Conflict-free replicated data' },
|
|
21
|
-
{ value: 'quorum', label: 'Quorum', hint: 'Simple majority voting' }
|
|
22
|
-
];
|
|
23
|
-
// Init subcommand
|
|
24
|
-
const initCommand = {
|
|
25
|
-
name: 'init',
|
|
26
|
-
description: 'Initialize a hive mind',
|
|
27
|
-
options: [
|
|
28
|
-
{
|
|
29
|
-
name: 'topology',
|
|
30
|
-
short: 't',
|
|
31
|
-
description: 'Hive topology',
|
|
32
|
-
type: 'string',
|
|
33
|
-
choices: TOPOLOGIES.map(t => t.value),
|
|
34
|
-
default: 'hierarchical-mesh'
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'consensus',
|
|
38
|
-
short: 'c',
|
|
39
|
-
description: 'Consensus strategy',
|
|
40
|
-
type: 'string',
|
|
41
|
-
choices: CONSENSUS_STRATEGIES.map(s => s.value),
|
|
42
|
-
default: 'byzantine'
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: 'max-agents',
|
|
46
|
-
short: 'm',
|
|
47
|
-
description: 'Maximum agents',
|
|
48
|
-
type: 'number',
|
|
49
|
-
default: 15
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: 'persist',
|
|
53
|
-
short: 'p',
|
|
54
|
-
description: 'Enable persistent state',
|
|
55
|
-
type: 'boolean',
|
|
56
|
-
default: true
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: 'memory-backend',
|
|
60
|
-
description: 'Memory backend (agentdb, sqlite, hybrid)',
|
|
61
|
-
type: 'string',
|
|
62
|
-
default: 'hybrid'
|
|
63
|
-
}
|
|
64
|
-
],
|
|
65
|
-
examples: [
|
|
66
|
-
{ command: 'claude-flow hive-mind init -t hierarchical-mesh', description: 'Init hierarchical mesh' },
|
|
67
|
-
{ command: 'claude-flow hive-mind init -c byzantine -m 20', description: 'Init with Byzantine consensus' }
|
|
68
|
-
],
|
|
69
|
-
action: async (ctx) => {
|
|
70
|
-
let topology = ctx.flags.topology;
|
|
71
|
-
let consensus = ctx.flags.consensus;
|
|
72
|
-
if (ctx.interactive && !ctx.flags.topology) {
|
|
73
|
-
topology = await select({
|
|
74
|
-
message: 'Select hive topology:',
|
|
75
|
-
options: TOPOLOGIES,
|
|
76
|
-
default: 'hierarchical-mesh'
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
if (ctx.interactive && !ctx.flags.consensus) {
|
|
80
|
-
consensus = await select({
|
|
81
|
-
message: 'Select consensus strategy:',
|
|
82
|
-
options: CONSENSUS_STRATEGIES,
|
|
83
|
-
default: 'byzantine'
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
const config = {
|
|
87
|
-
topology: topology || 'hierarchical-mesh',
|
|
88
|
-
consensus: consensus || 'byzantine',
|
|
89
|
-
maxAgents: ctx.flags.maxAgents || 15,
|
|
90
|
-
persist: ctx.flags.persist,
|
|
91
|
-
memoryBackend: ctx.flags.memoryBackend || 'hybrid'
|
|
92
|
-
};
|
|
93
|
-
output.writeln();
|
|
94
|
-
output.writeln(output.bold('Initializing Hive Mind'));
|
|
95
|
-
const spinner = output.createSpinner({ text: 'Setting up hive infrastructure...', spinner: 'dots' });
|
|
96
|
-
spinner.start();
|
|
97
|
-
try {
|
|
98
|
-
const result = await callMCPTool('hive-mind/init', config);
|
|
99
|
-
spinner.succeed('Hive Mind initialized');
|
|
100
|
-
if (ctx.flags.format === 'json') {
|
|
101
|
-
output.printJson(result);
|
|
102
|
-
return { success: true, data: result };
|
|
103
|
-
}
|
|
104
|
-
output.writeln();
|
|
105
|
-
output.printBox([
|
|
106
|
-
`Hive ID: ${result.hiveId ?? 'default'}`,
|
|
107
|
-
`Queen ID: ${result.queenId ?? 'N/A'}`,
|
|
108
|
-
`Topology: ${result.topology ?? config.topology}`,
|
|
109
|
-
`Consensus: ${result.consensus ?? config.consensus}`,
|
|
110
|
-
`Max Agents: ${config.maxAgents}`,
|
|
111
|
-
`Memory: ${config.memoryBackend}`,
|
|
112
|
-
`Status: ${output.success(result.status ?? 'initialized')}`
|
|
113
|
-
].join('\n'), 'Hive Mind Configuration');
|
|
114
|
-
output.writeln();
|
|
115
|
-
output.printInfo('Queen agent is ready to coordinate worker agents');
|
|
116
|
-
output.writeln(output.dim(' Use "claude-flow hive-mind spawn" to add workers'));
|
|
117
|
-
return { success: true, data: result };
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
spinner.fail('Failed to initialize');
|
|
121
|
-
if (error instanceof MCPClientError) {
|
|
122
|
-
output.printError(`Init error: ${error.message}`);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
output.printError(`Unexpected error: ${String(error)}`);
|
|
126
|
-
}
|
|
127
|
-
return { success: false, exitCode: 1 };
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
// Spawn subcommand
|
|
132
|
-
const spawnCommand = {
|
|
133
|
-
name: 'spawn',
|
|
134
|
-
description: 'Spawn worker agents into the hive',
|
|
135
|
-
options: [
|
|
136
|
-
{
|
|
137
|
-
name: 'count',
|
|
138
|
-
short: 'n',
|
|
139
|
-
description: 'Number of workers to spawn',
|
|
140
|
-
type: 'number',
|
|
141
|
-
default: 1
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: 'type',
|
|
145
|
-
short: 't',
|
|
146
|
-
description: 'Agent type',
|
|
147
|
-
type: 'string',
|
|
148
|
-
default: 'worker'
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: 'capabilities',
|
|
152
|
-
short: 'c',
|
|
153
|
-
description: 'Comma-separated capabilities',
|
|
154
|
-
type: 'string'
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
name: 'priority',
|
|
158
|
-
short: 'p',
|
|
159
|
-
description: 'Agent priority (low, normal, high)',
|
|
160
|
-
type: 'string',
|
|
161
|
-
default: 'normal'
|
|
162
|
-
}
|
|
163
|
-
],
|
|
164
|
-
examples: [
|
|
165
|
-
{ command: 'claude-flow hive-mind spawn -n 5', description: 'Spawn 5 workers' },
|
|
166
|
-
{ command: 'claude-flow hive-mind spawn -t coder -c "coding,testing"', description: 'Spawn coder with capabilities' }
|
|
167
|
-
],
|
|
168
|
-
action: async (ctx) => {
|
|
169
|
-
const count = ctx.flags.count;
|
|
170
|
-
const type = ctx.flags.type;
|
|
171
|
-
const capabilities = ctx.flags.capabilities ? ctx.flags.capabilities.split(',') : [];
|
|
172
|
-
const priority = ctx.flags.priority;
|
|
173
|
-
output.printInfo(`Spawning ${count} ${type} agent(s)...`);
|
|
174
|
-
try {
|
|
175
|
-
const result = await callMCPTool('hive-mind/spawn', {
|
|
176
|
-
count,
|
|
177
|
-
agentType: type,
|
|
178
|
-
capabilities,
|
|
179
|
-
priority,
|
|
180
|
-
});
|
|
181
|
-
if (ctx.flags.format === 'json') {
|
|
182
|
-
output.printJson(result);
|
|
183
|
-
return { success: true, data: result };
|
|
184
|
-
}
|
|
185
|
-
output.writeln();
|
|
186
|
-
output.printTable({
|
|
187
|
-
columns: [
|
|
188
|
-
{ key: 'id', header: 'Agent ID', width: 20 },
|
|
189
|
-
{ key: 'type', header: 'Type', width: 12 },
|
|
190
|
-
{ key: 'status', header: 'Status', width: 12, format: formatAgentStatus },
|
|
191
|
-
{ key: 'assignedQueen', header: 'Queen', width: 15 }
|
|
192
|
-
],
|
|
193
|
-
data: result.spawned
|
|
194
|
-
});
|
|
195
|
-
output.writeln();
|
|
196
|
-
output.printSuccess(`Spawned ${result.spawned.length} agent(s)`);
|
|
197
|
-
output.writeln(output.dim(` Hive: ${result.hiveStatus.activeAgents}/${result.hiveStatus.maxAgents} agents, Queen load: ${result.hiveStatus.queenLoad}`));
|
|
198
|
-
return { success: true, data: result };
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
if (error instanceof MCPClientError) {
|
|
202
|
-
output.printError(`Spawn error: ${error.message}`);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
output.printError(`Unexpected error: ${String(error)}`);
|
|
206
|
-
}
|
|
207
|
-
return { success: false, exitCode: 1 };
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
// Status subcommand
|
|
212
|
-
const statusCommand = {
|
|
213
|
-
name: 'status',
|
|
214
|
-
description: 'Show hive mind status',
|
|
215
|
-
options: [
|
|
216
|
-
{
|
|
217
|
-
name: 'detailed',
|
|
218
|
-
short: 'd',
|
|
219
|
-
description: 'Show detailed metrics',
|
|
220
|
-
type: 'boolean',
|
|
221
|
-
default: false
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
name: 'watch',
|
|
225
|
-
short: 'w',
|
|
226
|
-
description: 'Watch for changes',
|
|
227
|
-
type: 'boolean',
|
|
228
|
-
default: false
|
|
229
|
-
}
|
|
230
|
-
],
|
|
231
|
-
action: async (ctx) => {
|
|
232
|
-
const detailed = ctx.flags.detailed;
|
|
233
|
-
try {
|
|
234
|
-
const result = await callMCPTool('hive-mind/status', {
|
|
235
|
-
includeMetrics: detailed,
|
|
236
|
-
includeWorkers: true,
|
|
237
|
-
});
|
|
238
|
-
if (ctx.flags.format === 'json') {
|
|
239
|
-
output.printJson(result);
|
|
240
|
-
return { success: true, data: result };
|
|
241
|
-
}
|
|
242
|
-
// Handle both simple and complex response formats - cast to flexible type
|
|
243
|
-
const flexResult = result;
|
|
244
|
-
const hiveId = result.hiveId ?? flexResult.id ?? 'default';
|
|
245
|
-
const status = result.status ?? (flexResult.initialized ? 'running' : 'stopped');
|
|
246
|
-
const queen = result.queen ?? { id: 'N/A', status: 'unknown', load: 0, tasksQueued: 0 };
|
|
247
|
-
const flexQueen = queen;
|
|
248
|
-
const queenId = typeof queen === 'object' ? (queen.id ?? flexQueen.agentId ?? 'N/A') : String(queen);
|
|
249
|
-
const queenLoad = typeof queen === 'object' ? (queen.load ?? 0) : 0;
|
|
250
|
-
const queenTasks = typeof queen === 'object' ? (queen.tasksQueued ?? 0) : 0;
|
|
251
|
-
const queenStatus = typeof queen === 'object' ? (queen.status ?? 'active') : 'active';
|
|
252
|
-
output.writeln();
|
|
253
|
-
output.printBox([
|
|
254
|
-
`Hive ID: ${hiveId}`,
|
|
255
|
-
`Status: ${formatHiveStatus(String(status))}`,
|
|
256
|
-
`Topology: ${result.topology ?? 'mesh'}`,
|
|
257
|
-
`Consensus: ${result.consensus ?? 'byzantine'}`,
|
|
258
|
-
'',
|
|
259
|
-
`Queen: ${queenId}`,
|
|
260
|
-
` Status: ${formatAgentStatus(queenStatus)}`,
|
|
261
|
-
` Load: ${(queenLoad * 100).toFixed(1)}%`,
|
|
262
|
-
` Queued Tasks: ${queenTasks}`
|
|
263
|
-
].join('\n'), 'Hive Mind Status');
|
|
264
|
-
// Handle workers array - could be worker objects or just IDs
|
|
265
|
-
const workers = result.workers ?? [];
|
|
266
|
-
const workerData = Array.isArray(workers) ? workers.map(w => {
|
|
267
|
-
if (typeof w === 'string') {
|
|
268
|
-
return { id: w, type: 'worker', status: 'idle', currentTask: '-', tasksCompleted: 0 };
|
|
269
|
-
}
|
|
270
|
-
const flexWorker = w;
|
|
271
|
-
return {
|
|
272
|
-
id: w.id ?? flexWorker.agentId ?? 'unknown',
|
|
273
|
-
type: w.type ?? flexWorker.agentType ?? 'worker',
|
|
274
|
-
status: w.status ?? 'idle',
|
|
275
|
-
currentTask: w.currentTask ?? '-',
|
|
276
|
-
tasksCompleted: w.tasksCompleted ?? 0
|
|
277
|
-
};
|
|
278
|
-
}) : [];
|
|
279
|
-
output.writeln();
|
|
280
|
-
output.writeln(output.bold('Worker Agents'));
|
|
281
|
-
if (workerData.length === 0) {
|
|
282
|
-
output.printInfo('No workers in hive. Use "claude-flow hive-mind spawn" to add workers.');
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
output.printTable({
|
|
286
|
-
columns: [
|
|
287
|
-
{ key: 'id', header: 'ID', width: 20 },
|
|
288
|
-
{ key: 'type', header: 'Type', width: 12 },
|
|
289
|
-
{ key: 'status', header: 'Status', width: 10, format: formatAgentStatus },
|
|
290
|
-
{ key: 'currentTask', header: 'Current Task', width: 20, format: (v) => String(v || '-') },
|
|
291
|
-
{ key: 'tasksCompleted', header: 'Completed', width: 10, align: 'right' }
|
|
292
|
-
],
|
|
293
|
-
data: workerData
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
if (detailed) {
|
|
297
|
-
const metrics = result.metrics ?? { totalTasks: 0, completedTasks: 0, failedTasks: 0, avgTaskTime: 0, consensusRounds: 0, memoryUsage: '0 MB' };
|
|
298
|
-
output.writeln();
|
|
299
|
-
output.writeln(output.bold('Metrics'));
|
|
300
|
-
output.printTable({
|
|
301
|
-
columns: [
|
|
302
|
-
{ key: 'metric', header: 'Metric', width: 20 },
|
|
303
|
-
{ key: 'value', header: 'Value', width: 15, align: 'right' }
|
|
304
|
-
],
|
|
305
|
-
data: [
|
|
306
|
-
{ metric: 'Total Tasks', value: metrics.totalTasks ?? 0 },
|
|
307
|
-
{ metric: 'Completed', value: metrics.completedTasks ?? 0 },
|
|
308
|
-
{ metric: 'Failed', value: metrics.failedTasks ?? 0 },
|
|
309
|
-
{ metric: 'Avg Task Time', value: `${(metrics.avgTaskTime ?? 0).toFixed(1)}ms` },
|
|
310
|
-
{ metric: 'Consensus Rounds', value: metrics.consensusRounds ?? 0 },
|
|
311
|
-
{ metric: 'Memory Usage', value: metrics.memoryUsage ?? '0 MB' }
|
|
312
|
-
]
|
|
313
|
-
});
|
|
314
|
-
const health = result.health ?? { overall: 'healthy', queen: 'healthy', workers: 'healthy', consensus: 'healthy', memory: 'healthy' };
|
|
315
|
-
output.writeln();
|
|
316
|
-
output.writeln(output.bold('Health'));
|
|
317
|
-
output.printList([
|
|
318
|
-
`Overall: ${formatHealth(health.overall ?? 'healthy')}`,
|
|
319
|
-
`Queen: ${formatHealth(health.queen ?? 'healthy')}`,
|
|
320
|
-
`Workers: ${formatHealth(health.workers ?? 'healthy')}`,
|
|
321
|
-
`Consensus: ${formatHealth(health.consensus ?? 'healthy')}`,
|
|
322
|
-
`Memory: ${formatHealth(health.memory ?? 'healthy')}`
|
|
323
|
-
]);
|
|
324
|
-
}
|
|
325
|
-
return { success: true, data: result };
|
|
326
|
-
}
|
|
327
|
-
catch (error) {
|
|
328
|
-
if (error instanceof MCPClientError) {
|
|
329
|
-
output.printError(`Status error: ${error.message}`);
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
output.printError(`Unexpected error: ${String(error)}`);
|
|
333
|
-
}
|
|
334
|
-
return { success: false, exitCode: 1 };
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
// Task subcommand
|
|
339
|
-
const taskCommand = {
|
|
340
|
-
name: 'task',
|
|
341
|
-
description: 'Submit tasks to the hive',
|
|
342
|
-
options: [
|
|
343
|
-
{
|
|
344
|
-
name: 'description',
|
|
345
|
-
short: 'd',
|
|
346
|
-
description: 'Task description',
|
|
347
|
-
type: 'string'
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
name: 'priority',
|
|
351
|
-
short: 'p',
|
|
352
|
-
description: 'Task priority',
|
|
353
|
-
type: 'string',
|
|
354
|
-
choices: ['low', 'normal', 'high', 'critical'],
|
|
355
|
-
default: 'normal'
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
name: 'require-consensus',
|
|
359
|
-
short: 'c',
|
|
360
|
-
description: 'Require consensus for completion',
|
|
361
|
-
type: 'boolean',
|
|
362
|
-
default: false
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
name: 'timeout',
|
|
366
|
-
description: 'Task timeout in seconds',
|
|
367
|
-
type: 'number',
|
|
368
|
-
default: 300
|
|
369
|
-
}
|
|
370
|
-
],
|
|
371
|
-
examples: [
|
|
372
|
-
{ command: 'claude-flow hive-mind task -d "Implement auth module"', description: 'Submit task' },
|
|
373
|
-
{ command: 'claude-flow hive-mind task -d "Security review" -p critical -c', description: 'Critical task with consensus' }
|
|
374
|
-
],
|
|
375
|
-
action: async (ctx) => {
|
|
376
|
-
let description = ctx.flags.description || ctx.args.join(' ');
|
|
377
|
-
if (!description && ctx.interactive) {
|
|
378
|
-
description = await input({
|
|
379
|
-
message: 'Task description:',
|
|
380
|
-
validate: (v) => v.length > 0 || 'Description is required'
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
if (!description) {
|
|
384
|
-
output.printError('Task description is required');
|
|
385
|
-
return { success: false, exitCode: 1 };
|
|
386
|
-
}
|
|
387
|
-
const priority = ctx.flags.priority;
|
|
388
|
-
const requireConsensus = ctx.flags.requireConsensus;
|
|
389
|
-
const timeout = ctx.flags.timeout;
|
|
390
|
-
output.printInfo('Submitting task to hive...');
|
|
391
|
-
try {
|
|
392
|
-
const result = await callMCPTool('hive-mind/task', {
|
|
393
|
-
description,
|
|
394
|
-
priority,
|
|
395
|
-
requireConsensus,
|
|
396
|
-
timeout,
|
|
397
|
-
});
|
|
398
|
-
if (ctx.flags.format === 'json') {
|
|
399
|
-
output.printJson(result);
|
|
400
|
-
return { success: true, data: result };
|
|
401
|
-
}
|
|
402
|
-
output.writeln();
|
|
403
|
-
output.printBox([
|
|
404
|
-
`Task ID: ${result.taskId}`,
|
|
405
|
-
`Status: ${formatAgentStatus(result.status)}`,
|
|
406
|
-
`Priority: ${formatPriority(priority)}`,
|
|
407
|
-
`Assigned: ${result.assignedTo.join(', ')}`,
|
|
408
|
-
`Consensus: ${result.requiresConsensus ? 'Yes' : 'No'}`,
|
|
409
|
-
`Est. Time: ${result.estimatedTime}`
|
|
410
|
-
].join('\n'), 'Task Submitted');
|
|
411
|
-
output.writeln();
|
|
412
|
-
output.printSuccess('Task submitted to hive');
|
|
413
|
-
output.writeln(output.dim(` Track with: claude-flow hive-mind task-status ${result.taskId}`));
|
|
414
|
-
return { success: true, data: result };
|
|
415
|
-
}
|
|
416
|
-
catch (error) {
|
|
417
|
-
if (error instanceof MCPClientError) {
|
|
418
|
-
output.printError(`Task submission error: ${error.message}`);
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
output.printError(`Unexpected error: ${String(error)}`);
|
|
422
|
-
}
|
|
423
|
-
return { success: false, exitCode: 1 };
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
// Optimize memory subcommand
|
|
428
|
-
const optimizeMemoryCommand = {
|
|
429
|
-
name: 'optimize-memory',
|
|
430
|
-
description: 'Optimize hive memory and patterns',
|
|
431
|
-
options: [
|
|
432
|
-
{
|
|
433
|
-
name: 'aggressive',
|
|
434
|
-
short: 'a',
|
|
435
|
-
description: 'Aggressive optimization',
|
|
436
|
-
type: 'boolean',
|
|
437
|
-
default: false
|
|
438
|
-
},
|
|
439
|
-
{
|
|
440
|
-
name: 'threshold',
|
|
441
|
-
description: 'Quality threshold for pattern retention',
|
|
442
|
-
type: 'number',
|
|
443
|
-
default: 0.7
|
|
444
|
-
}
|
|
445
|
-
],
|
|
446
|
-
action: async (ctx) => {
|
|
447
|
-
const aggressive = ctx.flags.aggressive;
|
|
448
|
-
const threshold = ctx.flags.threshold;
|
|
449
|
-
output.printInfo('Optimizing hive memory...');
|
|
450
|
-
const spinner = output.createSpinner({ text: 'Analyzing patterns...', spinner: 'dots' });
|
|
451
|
-
spinner.start();
|
|
452
|
-
try {
|
|
453
|
-
const result = await callMCPTool('hive-mind/optimize-memory', {
|
|
454
|
-
aggressive,
|
|
455
|
-
qualityThreshold: threshold,
|
|
456
|
-
});
|
|
457
|
-
spinner.succeed('Memory optimized');
|
|
458
|
-
if (ctx.flags.format === 'json') {
|
|
459
|
-
output.printJson(result);
|
|
460
|
-
return { success: true, data: result };
|
|
461
|
-
}
|
|
462
|
-
output.writeln();
|
|
463
|
-
output.printTable({
|
|
464
|
-
columns: [
|
|
465
|
-
{ key: 'metric', header: 'Metric', width: 20 },
|
|
466
|
-
{ key: 'before', header: 'Before', width: 15, align: 'right' },
|
|
467
|
-
{ key: 'after', header: 'After', width: 15, align: 'right' }
|
|
468
|
-
],
|
|
469
|
-
data: [
|
|
470
|
-
{ metric: 'Patterns', before: result.before.patterns, after: result.after.patterns },
|
|
471
|
-
{ metric: 'Memory', before: result.before.memory, after: result.after.memory }
|
|
472
|
-
]
|
|
473
|
-
});
|
|
474
|
-
output.writeln();
|
|
475
|
-
output.printList([
|
|
476
|
-
`Patterns removed: ${result.removed}`,
|
|
477
|
-
`Patterns consolidated: ${result.consolidated}`,
|
|
478
|
-
`Optimization time: ${result.timeMs}ms`
|
|
479
|
-
]);
|
|
480
|
-
return { success: true, data: result };
|
|
481
|
-
}
|
|
482
|
-
catch (error) {
|
|
483
|
-
spinner.fail('Optimization failed');
|
|
484
|
-
if (error instanceof MCPClientError) {
|
|
485
|
-
output.printError(`Optimization error: ${error.message}`);
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
488
|
-
output.printError(`Unexpected error: ${String(error)}`);
|
|
489
|
-
}
|
|
490
|
-
return { success: false, exitCode: 1 };
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
// Join subcommand
|
|
495
|
-
const joinCommand = {
|
|
496
|
-
name: 'join',
|
|
497
|
-
description: 'Join an agent to the hive mind',
|
|
498
|
-
options: [
|
|
499
|
-
{ name: 'agent-id', short: 'a', description: 'Agent ID to join', type: 'string' },
|
|
500
|
-
{ name: 'role', short: 'r', description: 'Agent role (worker, specialist, scout)', type: 'string', default: 'worker' }
|
|
501
|
-
],
|
|
502
|
-
action: async (ctx) => {
|
|
503
|
-
const agentId = ctx.args[0] || ctx.flags['agent-id'] || ctx.flags.agentId;
|
|
504
|
-
if (!agentId) {
|
|
505
|
-
output.printError('Agent ID is required. Use --agent-id or -a flag, or provide as argument.');
|
|
506
|
-
return { success: false, exitCode: 1 };
|
|
507
|
-
}
|
|
508
|
-
try {
|
|
509
|
-
const result = await callMCPTool('hive-mind/join', { agentId, role: ctx.flags.role });
|
|
510
|
-
if (!result.success) {
|
|
511
|
-
output.printError(result.error || 'Failed');
|
|
512
|
-
return { success: false, exitCode: 1 };
|
|
513
|
-
}
|
|
514
|
-
output.printSuccess(`Agent ${agentId} joined hive (${result.totalWorkers} workers)`);
|
|
515
|
-
return { success: true, data: result };
|
|
516
|
-
}
|
|
517
|
-
catch (error) {
|
|
518
|
-
output.printError(`Join error: ${error instanceof MCPClientError ? error.message : String(error)}`);
|
|
519
|
-
return { success: false, exitCode: 1 };
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
// Leave subcommand
|
|
524
|
-
const leaveCommand = {
|
|
525
|
-
name: 'leave',
|
|
526
|
-
description: 'Remove an agent from the hive mind',
|
|
527
|
-
options: [{ name: 'agent-id', short: 'a', description: 'Agent ID to remove', type: 'string' }],
|
|
528
|
-
action: async (ctx) => {
|
|
529
|
-
const agentId = ctx.args[0] || ctx.flags['agent-id'] || ctx.flags.agentId;
|
|
530
|
-
if (!agentId) {
|
|
531
|
-
output.printError('Agent ID required.');
|
|
532
|
-
return { success: false, exitCode: 1 };
|
|
533
|
-
}
|
|
534
|
-
try {
|
|
535
|
-
const result = await callMCPTool('hive-mind/leave', { agentId });
|
|
536
|
-
if (!result.success) {
|
|
537
|
-
output.printError(result.error || 'Failed');
|
|
538
|
-
return { success: false, exitCode: 1 };
|
|
539
|
-
}
|
|
540
|
-
output.printSuccess(`Agent ${agentId} left hive (${result.remainingWorkers} remaining)`);
|
|
541
|
-
return { success: true, data: result };
|
|
542
|
-
}
|
|
543
|
-
catch (error) {
|
|
544
|
-
output.printError(`Leave error: ${error instanceof MCPClientError ? error.message : String(error)}`);
|
|
545
|
-
return { success: false, exitCode: 1 };
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
// Consensus subcommand
|
|
550
|
-
const consensusCommand = {
|
|
551
|
-
name: 'consensus',
|
|
552
|
-
description: 'Manage consensus proposals and voting',
|
|
553
|
-
options: [
|
|
554
|
-
{ name: 'action', short: 'a', description: 'Consensus action', type: 'string', choices: ['propose', 'vote', 'status', 'list'], default: 'list' },
|
|
555
|
-
{ name: 'proposal-id', short: 'p', description: 'Proposal ID', type: 'string' },
|
|
556
|
-
{ name: 'type', short: 't', description: 'Proposal type', type: 'string' },
|
|
557
|
-
{ name: 'value', description: 'Proposal value', type: 'string' },
|
|
558
|
-
{ name: 'vote', short: 'v', description: 'Vote (yes/no)', type: 'string' },
|
|
559
|
-
{ name: 'voter-id', description: 'Voter agent ID', type: 'string' }
|
|
560
|
-
],
|
|
561
|
-
action: async (ctx) => {
|
|
562
|
-
const action = ctx.flags.action || 'list';
|
|
563
|
-
try {
|
|
564
|
-
const result = await callMCPTool('hive-mind/consensus', { action, proposalId: ctx.flags.proposalId, type: ctx.flags.type, value: ctx.flags.value, vote: ctx.flags.vote === 'yes', voterId: ctx.flags.voterId });
|
|
565
|
-
if (ctx.flags.format === 'json') {
|
|
566
|
-
output.printJson(result);
|
|
567
|
-
return { success: true, data: result };
|
|
568
|
-
}
|
|
569
|
-
if (action === 'list') {
|
|
570
|
-
output.writeln(output.bold('\nPending Proposals'));
|
|
571
|
-
const pending = result.pending || [];
|
|
572
|
-
if (pending.length === 0)
|
|
573
|
-
output.printInfo('No pending proposals');
|
|
574
|
-
else
|
|
575
|
-
output.printTable({ columns: [{ key: 'proposalId', header: 'ID', width: 30 }, { key: 'type', header: 'Type', width: 12 }], data: pending });
|
|
576
|
-
}
|
|
577
|
-
else if (action === 'propose') {
|
|
578
|
-
output.printSuccess(`Proposal created: ${result.proposalId}`);
|
|
579
|
-
}
|
|
580
|
-
else if (action === 'vote') {
|
|
581
|
-
output.printSuccess(`Vote recorded (For: ${result.votesFor}, Against: ${result.votesAgainst})`);
|
|
582
|
-
}
|
|
583
|
-
return { success: true, data: result };
|
|
584
|
-
}
|
|
585
|
-
catch (error) {
|
|
586
|
-
output.printError(`Consensus error: ${error instanceof MCPClientError ? error.message : String(error)}`);
|
|
587
|
-
return { success: false, exitCode: 1 };
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
};
|
|
591
|
-
// Broadcast subcommand
|
|
592
|
-
const broadcastCommand = {
|
|
593
|
-
name: 'broadcast',
|
|
594
|
-
description: 'Broadcast a message to all workers in the hive',
|
|
595
|
-
options: [
|
|
596
|
-
{ name: 'message', short: 'm', description: 'Message to broadcast', type: 'string', required: true },
|
|
597
|
-
{ name: 'priority', short: 'p', description: 'Message priority', type: 'string', choices: ['low', 'normal', 'high', 'critical'], default: 'normal' },
|
|
598
|
-
{ name: 'from', short: 'f', description: 'Sender agent ID', type: 'string' }
|
|
599
|
-
],
|
|
600
|
-
action: async (ctx) => {
|
|
601
|
-
const message = ctx.args.join(' ') || ctx.flags.message;
|
|
602
|
-
if (!message) {
|
|
603
|
-
output.printError('Message required. Use --message or -m flag.');
|
|
604
|
-
return { success: false, exitCode: 1 };
|
|
605
|
-
}
|
|
606
|
-
try {
|
|
607
|
-
const result = await callMCPTool('hive-mind/broadcast', { message, priority: ctx.flags.priority, fromId: ctx.flags.from });
|
|
608
|
-
if (!result.success) {
|
|
609
|
-
output.printError(result.error || 'Failed');
|
|
610
|
-
return { success: false, exitCode: 1 };
|
|
611
|
-
}
|
|
612
|
-
output.printSuccess(`Message broadcast to ${result.recipients} workers (ID: ${result.messageId})`);
|
|
613
|
-
return { success: true, data: result };
|
|
614
|
-
}
|
|
615
|
-
catch (error) {
|
|
616
|
-
output.printError(`Broadcast error: ${error instanceof MCPClientError ? error.message : String(error)}`);
|
|
617
|
-
return { success: false, exitCode: 1 };
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
};
|
|
621
|
-
// Memory subcommand
|
|
622
|
-
const memorySubCommand = {
|
|
623
|
-
name: 'memory',
|
|
624
|
-
description: 'Access hive shared memory',
|
|
625
|
-
options: [
|
|
626
|
-
{ name: 'action', short: 'a', description: 'Memory action', type: 'string', choices: ['get', 'set', 'delete', 'list'], default: 'list' },
|
|
627
|
-
{ name: 'key', short: 'k', description: 'Memory key', type: 'string' },
|
|
628
|
-
{ name: 'value', short: 'v', description: 'Value to store', type: 'string' }
|
|
629
|
-
],
|
|
630
|
-
action: async (ctx) => {
|
|
631
|
-
const action = ctx.flags.action || 'list';
|
|
632
|
-
const key = ctx.flags.key;
|
|
633
|
-
const value = ctx.flags.value;
|
|
634
|
-
if ((action === 'get' || action === 'delete') && !key) {
|
|
635
|
-
output.printError('Key required for get/delete.');
|
|
636
|
-
return { success: false, exitCode: 1 };
|
|
637
|
-
}
|
|
638
|
-
if (action === 'set' && (!key || value === undefined)) {
|
|
639
|
-
output.printError('Key and value required for set.');
|
|
640
|
-
return { success: false, exitCode: 1 };
|
|
641
|
-
}
|
|
642
|
-
try {
|
|
643
|
-
const result = await callMCPTool('hive-mind/memory', { action, key, value });
|
|
644
|
-
if (ctx.flags.format === 'json') {
|
|
645
|
-
output.printJson(result);
|
|
646
|
-
return { success: true, data: result };
|
|
647
|
-
}
|
|
648
|
-
if (action === 'list') {
|
|
649
|
-
const keys = result.keys || [];
|
|
650
|
-
output.writeln(output.bold(`\nShared Memory (${result.count} keys)`));
|
|
651
|
-
if (keys.length === 0)
|
|
652
|
-
output.printInfo('No keys in shared memory');
|
|
653
|
-
else
|
|
654
|
-
output.printList(keys.map(k => output.highlight(k)));
|
|
655
|
-
}
|
|
656
|
-
else if (action === 'get') {
|
|
657
|
-
output.writeln(output.bold(`\nKey: ${key}`));
|
|
658
|
-
output.writeln(result.exists ? `Value: ${JSON.stringify(result.value, null, 2)}` : 'Key not found');
|
|
659
|
-
}
|
|
660
|
-
else if (action === 'set') {
|
|
661
|
-
output.printSuccess(`Set ${key} in shared memory`);
|
|
662
|
-
}
|
|
663
|
-
else if (action === 'delete') {
|
|
664
|
-
output.printSuccess(result.deleted ? `Deleted ${key}` : `Key ${key} did not exist`);
|
|
665
|
-
}
|
|
666
|
-
return { success: true, data: result };
|
|
667
|
-
}
|
|
668
|
-
catch (error) {
|
|
669
|
-
output.printError(`Memory error: ${error instanceof MCPClientError ? error.message : String(error)}`);
|
|
670
|
-
return { success: false, exitCode: 1 };
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
// Shutdown subcommand
|
|
675
|
-
const shutdownCommand = {
|
|
676
|
-
name: 'shutdown',
|
|
677
|
-
description: 'Shutdown the hive mind',
|
|
678
|
-
options: [
|
|
679
|
-
{
|
|
680
|
-
name: 'force',
|
|
681
|
-
short: 'f',
|
|
682
|
-
description: 'Force shutdown',
|
|
683
|
-
type: 'boolean',
|
|
684
|
-
default: false
|
|
685
|
-
},
|
|
686
|
-
{
|
|
687
|
-
name: 'save-state',
|
|
688
|
-
short: 's',
|
|
689
|
-
description: 'Save state before shutdown',
|
|
690
|
-
type: 'boolean',
|
|
691
|
-
default: true
|
|
692
|
-
}
|
|
693
|
-
],
|
|
694
|
-
action: async (ctx) => {
|
|
695
|
-
const force = ctx.flags.force;
|
|
696
|
-
const saveState = ctx.flags.saveState;
|
|
697
|
-
if (!force && ctx.interactive) {
|
|
698
|
-
const confirmed = await confirm({
|
|
699
|
-
message: 'Shutdown the hive mind? All agents will be terminated.',
|
|
700
|
-
default: false
|
|
701
|
-
});
|
|
702
|
-
if (!confirmed) {
|
|
703
|
-
output.printInfo('Operation cancelled');
|
|
704
|
-
return { success: true };
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
output.printInfo('Shutting down hive mind...');
|
|
708
|
-
const spinner = output.createSpinner({ text: 'Graceful shutdown in progress...', spinner: 'dots' });
|
|
709
|
-
spinner.start();
|
|
710
|
-
try {
|
|
711
|
-
const result = await callMCPTool('hive-mind/shutdown', {
|
|
712
|
-
force,
|
|
713
|
-
saveState,
|
|
714
|
-
});
|
|
715
|
-
spinner.succeed('Hive mind shutdown complete');
|
|
716
|
-
output.writeln();
|
|
717
|
-
output.printList([
|
|
718
|
-
`Agents terminated: ${result.agentsTerminated}`,
|
|
719
|
-
`State saved: ${result.stateSaved ? 'Yes' : 'No'}`,
|
|
720
|
-
`Shutdown time: ${result.shutdownTime}`
|
|
721
|
-
]);
|
|
722
|
-
return { success: true, data: result };
|
|
723
|
-
}
|
|
724
|
-
catch (error) {
|
|
725
|
-
spinner.fail('Shutdown failed');
|
|
726
|
-
if (error instanceof MCPClientError) {
|
|
727
|
-
output.printError(`Shutdown error: ${error.message}`);
|
|
728
|
-
}
|
|
729
|
-
else {
|
|
730
|
-
output.printError(`Unexpected error: ${String(error)}`);
|
|
731
|
-
}
|
|
732
|
-
return { success: false, exitCode: 1 };
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
// Main hive-mind command
|
|
737
|
-
export const hiveMindCommand = {
|
|
738
|
-
name: 'hive-mind',
|
|
739
|
-
aliases: ['hive'],
|
|
740
|
-
description: 'Queen-led consensus-based multi-agent coordination',
|
|
741
|
-
subcommands: [initCommand, spawnCommand, statusCommand, taskCommand, joinCommand, leaveCommand, consensusCommand, broadcastCommand, memorySubCommand, optimizeMemoryCommand, shutdownCommand],
|
|
742
|
-
options: [],
|
|
743
|
-
examples: [
|
|
744
|
-
{ command: 'claude-flow hive-mind init -t hierarchical-mesh', description: 'Initialize hive' },
|
|
745
|
-
{ command: 'claude-flow hive-mind spawn -n 5', description: 'Spawn workers' },
|
|
746
|
-
{ command: 'claude-flow hive-mind task -d "Build feature"', description: 'Submit task' }
|
|
747
|
-
],
|
|
748
|
-
action: async () => {
|
|
749
|
-
output.writeln();
|
|
750
|
-
output.writeln(output.bold('Hive Mind - Consensus-Based Multi-Agent Coordination'));
|
|
751
|
-
output.writeln();
|
|
752
|
-
output.writeln('Usage: claude-flow hive-mind <subcommand> [options]');
|
|
753
|
-
output.writeln();
|
|
754
|
-
output.writeln('Subcommands:');
|
|
755
|
-
output.printList([
|
|
756
|
-
`${output.highlight('init')} - Initialize hive mind`,
|
|
757
|
-
`${output.highlight('spawn')} - Spawn worker agents`,
|
|
758
|
-
`${output.highlight('status')} - Show hive status`,
|
|
759
|
-
`${output.highlight('task')} - Submit task to hive`,
|
|
760
|
-
`${output.highlight('join')} - Join an agent to the hive`,
|
|
761
|
-
`${output.highlight('leave')} - Remove an agent from the hive`,
|
|
762
|
-
`${output.highlight('consensus')} - Manage consensus proposals`,
|
|
763
|
-
`${output.highlight('broadcast')} - Broadcast message to workers`,
|
|
764
|
-
`${output.highlight('memory')} - Access shared memory`,
|
|
765
|
-
`${output.highlight('optimize-memory')} - Optimize patterns and memory`,
|
|
766
|
-
`${output.highlight('shutdown')} - Shutdown the hive`
|
|
767
|
-
]);
|
|
768
|
-
output.writeln();
|
|
769
|
-
output.writeln('Features:');
|
|
770
|
-
output.printList([
|
|
771
|
-
'Queen-led hierarchical coordination',
|
|
772
|
-
'Byzantine fault tolerant consensus',
|
|
773
|
-
'HNSW-accelerated pattern matching',
|
|
774
|
-
'Cross-session memory persistence',
|
|
775
|
-
'Automatic load balancing'
|
|
776
|
-
]);
|
|
777
|
-
return { success: true };
|
|
778
|
-
}
|
|
779
|
-
};
|
|
780
|
-
// Helper functions
|
|
781
|
-
function formatAgentStatus(status) {
|
|
782
|
-
const statusStr = String(status);
|
|
783
|
-
switch (statusStr) {
|
|
784
|
-
case 'active':
|
|
785
|
-
case 'ready':
|
|
786
|
-
case 'running':
|
|
787
|
-
return output.success(statusStr);
|
|
788
|
-
case 'idle':
|
|
789
|
-
case 'waiting':
|
|
790
|
-
return output.dim(statusStr);
|
|
791
|
-
case 'busy':
|
|
792
|
-
return output.highlight(statusStr);
|
|
793
|
-
case 'error':
|
|
794
|
-
case 'failed':
|
|
795
|
-
return output.error(statusStr);
|
|
796
|
-
default:
|
|
797
|
-
return statusStr;
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
function formatHiveStatus(status) {
|
|
801
|
-
switch (status) {
|
|
802
|
-
case 'active':
|
|
803
|
-
return output.success(status);
|
|
804
|
-
case 'idle':
|
|
805
|
-
return output.dim(status);
|
|
806
|
-
case 'degraded':
|
|
807
|
-
return output.warning(status);
|
|
808
|
-
case 'offline':
|
|
809
|
-
return output.error(status);
|
|
810
|
-
default:
|
|
811
|
-
return status;
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
function formatHealth(health) {
|
|
815
|
-
switch (health) {
|
|
816
|
-
case 'healthy':
|
|
817
|
-
case 'good':
|
|
818
|
-
return output.success(health);
|
|
819
|
-
case 'warning':
|
|
820
|
-
case 'degraded':
|
|
821
|
-
return output.warning(health);
|
|
822
|
-
case 'critical':
|
|
823
|
-
case 'unhealthy':
|
|
824
|
-
return output.error(health);
|
|
825
|
-
default:
|
|
826
|
-
return health;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
function formatPriority(priority) {
|
|
830
|
-
switch (priority) {
|
|
831
|
-
case 'critical':
|
|
832
|
-
return output.error(priority.toUpperCase());
|
|
833
|
-
case 'high':
|
|
834
|
-
return output.warning(priority);
|
|
835
|
-
case 'normal':
|
|
836
|
-
return priority;
|
|
837
|
-
case 'low':
|
|
838
|
-
return output.dim(priority);
|
|
839
|
-
default:
|
|
840
|
-
return priority;
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
export default hiveMindCommand;
|
|
844
|
-
//# sourceMappingURL=hive-mind.js.map
|