@claude-flow/cli 3.0.0-alpha.123 → 3.0.0-alpha.125
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/bin/mcp-server.js +7 -0
- package/dist/src/commands/hive-mind.d.ts +3 -0
- package/dist/src/commands/hive-mind.d.ts.map +1 -1
- package/dist/src/commands/hive-mind.js +376 -6
- package/dist/src/commands/hive-mind.js.map +1 -1
- package/dist/src/mcp-server.d.ts.map +1 -1
- package/dist/src/mcp-server.js +7 -0
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/embeddings-tools.js +1 -1
- package/dist/src/mcp-tools/embeddings-tools.js.map +1 -1
- package/dist/src/memory/sona-optimizer.js +3 -3
- package/dist/src/memory/sona-optimizer.js.map +1 -1
- package/dist/src/plugins/store/discovery.js +1 -1
- package/dist/src/plugins/store/discovery.js.map +1 -1
- package/dist/src/ruvector/moe-router.js +6 -6
- package/dist/src/ruvector/moe-router.js.map +1 -1
- package/dist/src/ruvector/q-learning-router.js +3 -3
- package/dist/src/ruvector/q-learning-router.js.map +1 -1
- package/dist/src/transfer/ipfs/client.js +2 -2
- package/dist/src/transfer/ipfs/client.js.map +1 -1
- package/dist/src/transfer/ipfs/upload.js +12 -12
- package/dist/src/transfer/ipfs/upload.js.map +1 -1
- package/dist/src/transfer/serialization/cfp.js +1 -1
- package/dist/src/transfer/serialization/cfp.js.map +1 -1
- package/dist/src/transfer/store/discovery.js +5 -5
- package/dist/src/transfer/store/discovery.js.map +1 -1
- package/dist/src/transfer/store/download.js +2 -2
- package/dist/src/transfer/store/download.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/bin/mcp-server.js
CHANGED
|
@@ -169,6 +169,13 @@ async function handleMessage(message) {
|
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
default:
|
|
172
|
+
// Silently ignore unknown notifications (no id = notification per JSON-RPC spec)
|
|
173
|
+
// This prevents -32601 errors that cause some clients to disconnect
|
|
174
|
+
if (!message.id || message.method.startsWith('notifications/')) {
|
|
175
|
+
console.error(`[${new Date().toISOString()}] DEBUG [claude-flow-mcp] Ignored notification: ${message.method}`);
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
// Only return error for actual RPC calls (with id)
|
|
172
179
|
return {
|
|
173
180
|
jsonrpc: '2.0',
|
|
174
181
|
id: message.id,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* V3 CLI Hive Mind Command
|
|
3
3
|
* Queen-led consensus-based multi-agent coordination
|
|
4
|
+
*
|
|
5
|
+
* Updated to support --claude flag for launching interactive Claude Code sessions
|
|
6
|
+
* PR: Fix #955 - Implement --claude flag for hive-mind spawn command
|
|
4
7
|
*/
|
|
5
8
|
import type { Command } from '../types.js';
|
|
6
9
|
export declare const hiveMindCommand: Command;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hive-mind.d.ts","sourceRoot":"","sources":["../../../src/commands/hive-mind.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hive-mind.d.ts","sourceRoot":"","sources":["../../../src/commands/hive-mind.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAiC,MAAM,aAAa,CAAC;AA+uC1E,eAAO,MAAM,eAAe,EAAE,OAiD7B,CAAC;AAqEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* V3 CLI Hive Mind Command
|
|
3
3
|
* Queen-led consensus-based multi-agent coordination
|
|
4
|
+
*
|
|
5
|
+
* Updated to support --claude flag for launching interactive Claude Code sessions
|
|
6
|
+
* PR: Fix #955 - Implement --claude flag for hive-mind spawn command
|
|
4
7
|
*/
|
|
5
8
|
import { output } from '../output.js';
|
|
6
9
|
import { select, confirm, input } from '../prompt.js';
|
|
7
10
|
import { callMCPTool, MCPClientError } from '../mcp-client.js';
|
|
11
|
+
import { spawn as childSpawn, execSync } from 'child_process';
|
|
12
|
+
import { mkdir, writeFile } from 'fs/promises';
|
|
13
|
+
import { join } from 'path';
|
|
8
14
|
// Hive topologies
|
|
9
15
|
const TOPOLOGIES = [
|
|
10
16
|
{ value: 'hierarchical', label: 'Hierarchical', hint: 'Queen-led with worker agents' },
|
|
@@ -20,6 +26,284 @@ const CONSENSUS_STRATEGIES = [
|
|
|
20
26
|
{ value: 'crdt', label: 'CRDT', hint: 'Conflict-free replicated data' },
|
|
21
27
|
{ value: 'quorum', label: 'Quorum', hint: 'Simple majority voting' }
|
|
22
28
|
];
|
|
29
|
+
/**
|
|
30
|
+
* Group workers by their type for prompt generation
|
|
31
|
+
*/
|
|
32
|
+
function groupWorkersByType(workers) {
|
|
33
|
+
const groups = {};
|
|
34
|
+
for (const worker of workers) {
|
|
35
|
+
const type = worker.type || worker.role || 'worker';
|
|
36
|
+
if (!groups[type]) {
|
|
37
|
+
groups[type] = [];
|
|
38
|
+
}
|
|
39
|
+
groups[type].push(worker);
|
|
40
|
+
}
|
|
41
|
+
return groups;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Generate comprehensive Hive Mind prompt for Claude Code
|
|
45
|
+
* Ported from v2.7.47 with enhancements for v3
|
|
46
|
+
*/
|
|
47
|
+
function generateHiveMindPrompt(swarmId, swarmName, objective, workers, workerGroups, flags) {
|
|
48
|
+
const currentTime = new Date().toISOString();
|
|
49
|
+
const workerTypes = Object.keys(workerGroups);
|
|
50
|
+
const queenType = flags.queenType || 'strategic';
|
|
51
|
+
const consensusAlgorithm = flags.consensus || 'byzantine';
|
|
52
|
+
const topology = flags.topology || 'hierarchical-mesh';
|
|
53
|
+
return `🧠 HIVE MIND COLLECTIVE INTELLIGENCE SYSTEM
|
|
54
|
+
═══════════════════════════════════════════════
|
|
55
|
+
|
|
56
|
+
You are the Queen coordinator of a Hive Mind swarm with collective intelligence capabilities.
|
|
57
|
+
|
|
58
|
+
HIVE MIND CONFIGURATION:
|
|
59
|
+
📌 Swarm ID: ${swarmId}
|
|
60
|
+
📌 Swarm Name: ${swarmName}
|
|
61
|
+
🎯 Objective: ${objective}
|
|
62
|
+
👑 Queen Type: ${queenType}
|
|
63
|
+
🐝 Worker Count: ${workers.length}
|
|
64
|
+
🔗 Topology: ${topology}
|
|
65
|
+
🤝 Consensus Algorithm: ${consensusAlgorithm}
|
|
66
|
+
⏰ Initialized: ${currentTime}
|
|
67
|
+
|
|
68
|
+
WORKER DISTRIBUTION:
|
|
69
|
+
${workerTypes.map(type => `• ${type}: ${workerGroups[type].length} agents`).join('\n')}
|
|
70
|
+
|
|
71
|
+
🔧 AVAILABLE MCP TOOLS FOR HIVE MIND COORDINATION:
|
|
72
|
+
|
|
73
|
+
1️⃣ **COLLECTIVE INTELLIGENCE**
|
|
74
|
+
mcp__claude-flow__hive-mind_consensus - Democratic decision making
|
|
75
|
+
mcp__claude-flow__hive-mind_memory - Share knowledge across the hive
|
|
76
|
+
mcp__claude-flow__hive-mind_broadcast - Broadcast to all workers
|
|
77
|
+
mcp__claude-flow__neural_patterns - Neural pattern recognition
|
|
78
|
+
|
|
79
|
+
2️⃣ **QUEEN COORDINATION**
|
|
80
|
+
mcp__claude-flow__hive-mind_status - Monitor swarm health
|
|
81
|
+
mcp__claude-flow__task_create - Create and delegate tasks
|
|
82
|
+
mcp__claude-flow__task_orchestrate - Orchestrate task distribution
|
|
83
|
+
mcp__claude-flow__agent_spawn - Spawn additional workers
|
|
84
|
+
|
|
85
|
+
3️⃣ **WORKER MANAGEMENT**
|
|
86
|
+
mcp__claude-flow__agent_list - List all active agents
|
|
87
|
+
mcp__claude-flow__agent_status - Check agent status
|
|
88
|
+
mcp__claude-flow__agent_metrics - Track worker performance
|
|
89
|
+
mcp__claude-flow__hive-mind_join - Add agent to hive
|
|
90
|
+
mcp__claude-flow__hive-mind_leave - Remove agent from hive
|
|
91
|
+
|
|
92
|
+
4️⃣ **TASK ORCHESTRATION**
|
|
93
|
+
mcp__claude-flow__task_create - Create hierarchical tasks
|
|
94
|
+
mcp__claude-flow__task_status - Track task progress
|
|
95
|
+
mcp__claude-flow__task_complete - Mark tasks complete
|
|
96
|
+
mcp__claude-flow__workflow_create - Create workflows
|
|
97
|
+
|
|
98
|
+
5️⃣ **MEMORY & LEARNING**
|
|
99
|
+
mcp__claude-flow__memory_store - Store collective knowledge
|
|
100
|
+
mcp__claude-flow__memory_retrieve - Access shared memory
|
|
101
|
+
mcp__claude-flow__memory_search - Search memory patterns
|
|
102
|
+
mcp__claude-flow__neural_train - Learn from experiences
|
|
103
|
+
mcp__claude-flow__hooks_intelligence_pattern-store - Store patterns
|
|
104
|
+
|
|
105
|
+
📋 HIVE MIND EXECUTION PROTOCOL:
|
|
106
|
+
|
|
107
|
+
1. **INITIALIZATION PHASE**
|
|
108
|
+
- Verify all workers are online and responsive
|
|
109
|
+
- Establish communication channels
|
|
110
|
+
- Load previous session state if available
|
|
111
|
+
- Initialize shared memory space
|
|
112
|
+
|
|
113
|
+
2. **TASK DISTRIBUTION PHASE**
|
|
114
|
+
- Analyze the objective and decompose into subtasks
|
|
115
|
+
- Assign tasks based on worker specializations
|
|
116
|
+
- Set up task dependencies and ordering
|
|
117
|
+
- Monitor parallel execution
|
|
118
|
+
|
|
119
|
+
3. **COORDINATION PHASE**
|
|
120
|
+
- Use consensus for critical decisions
|
|
121
|
+
- Aggregate results from workers
|
|
122
|
+
- Resolve conflicts using ${consensusAlgorithm} consensus
|
|
123
|
+
- Share learnings across the hive
|
|
124
|
+
|
|
125
|
+
4. **COMPLETION PHASE**
|
|
126
|
+
- Verify all subtasks are complete
|
|
127
|
+
- Consolidate results
|
|
128
|
+
- Store learnings in collective memory
|
|
129
|
+
- Report final status
|
|
130
|
+
|
|
131
|
+
🎯 YOUR OBJECTIVE:
|
|
132
|
+
${objective}
|
|
133
|
+
|
|
134
|
+
💡 COORDINATION TIPS:
|
|
135
|
+
• Use mcp__claude-flow__hive-mind_broadcast for swarm-wide announcements
|
|
136
|
+
• Check worker status regularly with mcp__claude-flow__hive-mind_status
|
|
137
|
+
• Store important decisions in shared memory for persistence
|
|
138
|
+
• Use consensus for any decisions affecting multiple workers
|
|
139
|
+
• Monitor task progress and reassign if workers are blocked
|
|
140
|
+
|
|
141
|
+
🚀 BEGIN HIVE MIND COORDINATION NOW!
|
|
142
|
+
Start by checking the current hive status and then proceed with the objective.
|
|
143
|
+
`;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Spawn Claude Code with Hive Mind coordination instructions
|
|
147
|
+
* Ported from v2.7.47 spawnClaudeCodeInstances function
|
|
148
|
+
*/
|
|
149
|
+
async function spawnClaudeCodeInstance(swarmId, swarmName, objective, workers, flags) {
|
|
150
|
+
output.writeln();
|
|
151
|
+
output.writeln(output.bold('🚀 Launching Claude Code with Hive Mind Coordination'));
|
|
152
|
+
output.writeln(output.dim('─'.repeat(60)));
|
|
153
|
+
const spinner = output.createSpinner({ text: 'Preparing Hive Mind coordination prompt...', spinner: 'dots' });
|
|
154
|
+
spinner.start();
|
|
155
|
+
try {
|
|
156
|
+
// Generate comprehensive Hive Mind prompt
|
|
157
|
+
const workerGroups = groupWorkersByType(workers);
|
|
158
|
+
const hiveMindPrompt = generateHiveMindPrompt(swarmId, swarmName, objective, workers, workerGroups, flags);
|
|
159
|
+
spinner.succeed('Hive Mind coordination prompt ready!');
|
|
160
|
+
// Display coordination summary
|
|
161
|
+
output.writeln();
|
|
162
|
+
output.writeln(output.bold('🧠 Hive Mind Configuration'));
|
|
163
|
+
output.writeln(output.dim('─'.repeat(60)));
|
|
164
|
+
output.printList([
|
|
165
|
+
`Swarm ID: ${output.highlight(swarmId)}`,
|
|
166
|
+
`Objective: ${output.highlight(objective)}`,
|
|
167
|
+
`Queen Type: ${output.highlight(flags.queenType || 'strategic')}`,
|
|
168
|
+
`Worker Count: ${output.highlight(String(workers.length))}`,
|
|
169
|
+
`Worker Types: ${output.highlight(Object.keys(workerGroups).join(', '))}`,
|
|
170
|
+
`Consensus: ${output.highlight(flags.consensus || 'byzantine')}`,
|
|
171
|
+
`MCP Tools: ${output.success('Full Claude-Flow integration enabled')}`
|
|
172
|
+
]);
|
|
173
|
+
// Ensure sessions directory exists
|
|
174
|
+
const sessionsDir = join('.hive-mind', 'sessions');
|
|
175
|
+
await mkdir(sessionsDir, { recursive: true });
|
|
176
|
+
const promptFile = join(sessionsDir, `hive-mind-prompt-${swarmId}.txt`);
|
|
177
|
+
await writeFile(promptFile, hiveMindPrompt, 'utf8');
|
|
178
|
+
output.writeln();
|
|
179
|
+
output.printSuccess(`Hive Mind prompt saved to: ${promptFile}`);
|
|
180
|
+
// Check if claude command exists
|
|
181
|
+
let claudeAvailable = false;
|
|
182
|
+
try {
|
|
183
|
+
execSync('which claude', { stdio: 'ignore' });
|
|
184
|
+
claudeAvailable = true;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
output.writeln();
|
|
188
|
+
output.printWarning('Claude Code CLI not found in PATH');
|
|
189
|
+
output.writeln(output.dim('Install it with: npm install -g @anthropic-ai/claude-code'));
|
|
190
|
+
output.writeln(output.dim('Falling back to displaying instructions...'));
|
|
191
|
+
}
|
|
192
|
+
const dryRun = flags.dryRun || flags['dry-run'];
|
|
193
|
+
if (claudeAvailable && !dryRun) {
|
|
194
|
+
// Build arguments - flags first, then prompt
|
|
195
|
+
const claudeArgs = [];
|
|
196
|
+
// Check for non-interactive mode
|
|
197
|
+
const isNonInteractive = flags['non-interactive'] || flags.nonInteractive;
|
|
198
|
+
if (isNonInteractive) {
|
|
199
|
+
claudeArgs.push('-p'); // Print mode
|
|
200
|
+
claudeArgs.push('--output-format', 'stream-json');
|
|
201
|
+
claudeArgs.push('--verbose');
|
|
202
|
+
output.printInfo('Running in non-interactive mode');
|
|
203
|
+
}
|
|
204
|
+
// Add auto-permission flag unless explicitly disabled
|
|
205
|
+
const skipPermissions = flags['dangerously-skip-permissions'] !== false && !flags['no-auto-permissions'];
|
|
206
|
+
if (skipPermissions) {
|
|
207
|
+
claudeArgs.push('--dangerously-skip-permissions');
|
|
208
|
+
if (!isNonInteractive) {
|
|
209
|
+
output.printWarning('Using --dangerously-skip-permissions for seamless hive-mind execution');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Add the prompt as the LAST argument
|
|
213
|
+
claudeArgs.push(hiveMindPrompt);
|
|
214
|
+
output.writeln();
|
|
215
|
+
output.printInfo('Launching Claude Code...');
|
|
216
|
+
output.writeln(output.dim('Press Ctrl+C to pause the session'));
|
|
217
|
+
// Spawn claude with properly ordered arguments
|
|
218
|
+
const claudeProcess = childSpawn('claude', claudeArgs, {
|
|
219
|
+
stdio: 'inherit',
|
|
220
|
+
shell: false,
|
|
221
|
+
});
|
|
222
|
+
// Set up SIGINT handler for session management
|
|
223
|
+
let isExiting = false;
|
|
224
|
+
const sigintHandler = () => {
|
|
225
|
+
if (isExiting)
|
|
226
|
+
return;
|
|
227
|
+
isExiting = true;
|
|
228
|
+
output.writeln();
|
|
229
|
+
output.writeln();
|
|
230
|
+
output.printWarning('Pausing session and terminating Claude Code...');
|
|
231
|
+
if (claudeProcess && !claudeProcess.killed) {
|
|
232
|
+
claudeProcess.kill('SIGTERM');
|
|
233
|
+
}
|
|
234
|
+
output.writeln();
|
|
235
|
+
output.printSuccess('Session paused');
|
|
236
|
+
output.writeln(output.dim(`Prompt file saved at: ${promptFile}`));
|
|
237
|
+
output.writeln(output.dim('To resume, run claude with the saved prompt file'));
|
|
238
|
+
process.exit(0);
|
|
239
|
+
};
|
|
240
|
+
process.on('SIGINT', sigintHandler);
|
|
241
|
+
process.on('SIGTERM', sigintHandler);
|
|
242
|
+
// Handle process exit
|
|
243
|
+
claudeProcess.on('exit', (code) => {
|
|
244
|
+
// Clean up signal handlers
|
|
245
|
+
process.removeListener('SIGINT', sigintHandler);
|
|
246
|
+
process.removeListener('SIGTERM', sigintHandler);
|
|
247
|
+
if (code === 0) {
|
|
248
|
+
output.writeln();
|
|
249
|
+
output.printSuccess('Claude Code completed successfully');
|
|
250
|
+
}
|
|
251
|
+
else if (code !== null) {
|
|
252
|
+
output.writeln();
|
|
253
|
+
output.printError(`Claude Code exited with code ${code}`);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
output.writeln();
|
|
257
|
+
output.printSuccess('Claude Code launched with Hive Mind coordination');
|
|
258
|
+
output.printInfo('The Queen coordinator will orchestrate all worker agents');
|
|
259
|
+
output.writeln(output.dim(`Prompt file saved at: ${promptFile}`));
|
|
260
|
+
return { success: true, promptFile };
|
|
261
|
+
}
|
|
262
|
+
else if (dryRun) {
|
|
263
|
+
output.writeln();
|
|
264
|
+
output.printInfo('Dry run - would execute Claude Code with prompt:');
|
|
265
|
+
output.writeln(output.dim(`Prompt length: ${hiveMindPrompt.length} characters`));
|
|
266
|
+
output.writeln();
|
|
267
|
+
output.writeln(output.dim('First 500 characters of prompt:'));
|
|
268
|
+
output.writeln(output.highlight(hiveMindPrompt.substring(0, 500) + '...'));
|
|
269
|
+
output.writeln();
|
|
270
|
+
output.writeln(output.dim(`Full prompt saved to: ${promptFile}`));
|
|
271
|
+
return { success: true, promptFile };
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
// Claude not available - show instructions
|
|
275
|
+
output.writeln();
|
|
276
|
+
output.writeln(output.bold('📋 Manual Execution Instructions:'));
|
|
277
|
+
output.writeln(output.dim('─'.repeat(50)));
|
|
278
|
+
output.printList([
|
|
279
|
+
'Install Claude Code: npm install -g @anthropic-ai/claude-code',
|
|
280
|
+
`Run with saved prompt: claude < ${promptFile}`,
|
|
281
|
+
`Or copy manually: cat ${promptFile} | claude`,
|
|
282
|
+
`With auto-permissions: claude --dangerously-skip-permissions < ${promptFile}`
|
|
283
|
+
]);
|
|
284
|
+
return { success: true, promptFile };
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
spinner.fail('Failed to prepare Claude Code coordination');
|
|
289
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
290
|
+
output.printError(`Error: ${errorMessage}`);
|
|
291
|
+
// Try to save prompt as fallback
|
|
292
|
+
try {
|
|
293
|
+
const promptFile = `hive-mind-prompt-${swarmId}-fallback.txt`;
|
|
294
|
+
const workerGroups = groupWorkersByType(workers);
|
|
295
|
+
const hiveMindPrompt = generateHiveMindPrompt(swarmId, swarmName, objective, workers, workerGroups, flags);
|
|
296
|
+
await writeFile(promptFile, hiveMindPrompt, 'utf8');
|
|
297
|
+
output.writeln();
|
|
298
|
+
output.printSuccess(`Prompt saved to: ${promptFile}`);
|
|
299
|
+
output.writeln(output.dim('You can run Claude Code manually with the saved prompt'));
|
|
300
|
+
return { success: false, promptFile, error: errorMessage };
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return { success: false, error: errorMessage };
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
23
307
|
// Init subcommand
|
|
24
308
|
const initCommand = {
|
|
25
309
|
name: 'init',
|
|
@@ -114,6 +398,7 @@ const initCommand = {
|
|
|
114
398
|
output.writeln();
|
|
115
399
|
output.printInfo('Queen agent is ready to coordinate worker agents');
|
|
116
400
|
output.writeln(output.dim(' Use "claude-flow hive-mind spawn" to add workers'));
|
|
401
|
+
output.writeln(output.dim(' Use "claude-flow hive-mind spawn --claude" to launch Claude Code'));
|
|
117
402
|
return { success: true, data: result };
|
|
118
403
|
}
|
|
119
404
|
catch (error) {
|
|
@@ -128,10 +413,10 @@ const initCommand = {
|
|
|
128
413
|
}
|
|
129
414
|
}
|
|
130
415
|
};
|
|
131
|
-
// Spawn subcommand
|
|
416
|
+
// Spawn subcommand - UPDATED with --claude flag
|
|
132
417
|
const spawnCommand = {
|
|
133
418
|
name: 'spawn',
|
|
134
|
-
description: 'Spawn worker agents into the hive',
|
|
419
|
+
description: 'Spawn worker agents into the hive (use --claude to launch Claude Code)',
|
|
135
420
|
options: [
|
|
136
421
|
{
|
|
137
422
|
name: 'count',
|
|
@@ -161,12 +446,51 @@ const spawnCommand = {
|
|
|
161
446
|
description: 'Prefix for worker IDs',
|
|
162
447
|
type: 'string',
|
|
163
448
|
default: 'hive-worker'
|
|
449
|
+
},
|
|
450
|
+
// NEW: --claude flag for launching Claude Code
|
|
451
|
+
{
|
|
452
|
+
name: 'claude',
|
|
453
|
+
description: 'Launch Claude Code with hive-mind coordination prompt',
|
|
454
|
+
type: 'boolean',
|
|
455
|
+
default: false
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
name: 'objective',
|
|
459
|
+
short: 'o',
|
|
460
|
+
description: 'Objective for the hive mind (used with --claude)',
|
|
461
|
+
type: 'string'
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
name: 'dangerously-skip-permissions',
|
|
465
|
+
description: 'Skip permission prompts in Claude Code (use with caution)',
|
|
466
|
+
type: 'boolean',
|
|
467
|
+
default: true
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: 'no-auto-permissions',
|
|
471
|
+
description: 'Disable automatic permission skipping',
|
|
472
|
+
type: 'boolean',
|
|
473
|
+
default: false
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
name: 'dry-run',
|
|
477
|
+
description: 'Show what would be done without launching Claude Code',
|
|
478
|
+
type: 'boolean',
|
|
479
|
+
default: false
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: 'non-interactive',
|
|
483
|
+
description: 'Run Claude Code in non-interactive mode',
|
|
484
|
+
type: 'boolean',
|
|
485
|
+
default: false
|
|
164
486
|
}
|
|
165
487
|
],
|
|
166
488
|
examples: [
|
|
167
489
|
{ command: 'claude-flow hive-mind spawn -n 5', description: 'Spawn 5 workers' },
|
|
168
490
|
{ command: 'claude-flow hive-mind spawn -n 3 -r specialist', description: 'Spawn 3 specialists' },
|
|
169
|
-
{ command: 'claude-flow hive-mind spawn -t coder -p my-coder', description: 'Spawn coder with custom prefix' }
|
|
491
|
+
{ command: 'claude-flow hive-mind spawn -t coder -p my-coder', description: 'Spawn coder with custom prefix' },
|
|
492
|
+
{ command: 'claude-flow hive-mind spawn --claude -o "Build a REST API"', description: 'Launch Claude Code with objective' },
|
|
493
|
+
{ command: 'claude-flow hive-mind spawn -n 5 --claude -o "Research AI patterns"', description: 'Spawn workers and launch Claude Code' }
|
|
170
494
|
],
|
|
171
495
|
action: async (ctx) => {
|
|
172
496
|
// Parse count with fallback to default
|
|
@@ -174,6 +498,8 @@ const spawnCommand = {
|
|
|
174
498
|
const role = ctx.flags.role || 'worker';
|
|
175
499
|
const agentType = ctx.flags.type || 'worker';
|
|
176
500
|
const prefix = ctx.flags.prefix || 'hive-worker';
|
|
501
|
+
const launchClaude = ctx.flags.claude;
|
|
502
|
+
let objective = ctx.flags.objective || ctx.args.join(' ');
|
|
177
503
|
output.printInfo(`Spawning ${count} ${role} agent(s)...`);
|
|
178
504
|
try {
|
|
179
505
|
const result = await callMCPTool('hive-mind/spawn', {
|
|
@@ -187,7 +513,7 @@ const spawnCommand = {
|
|
|
187
513
|
output.printError(result.error || 'Failed to spawn workers');
|
|
188
514
|
return { success: false, exitCode: 1 };
|
|
189
515
|
}
|
|
190
|
-
if (ctx.flags.format === 'json') {
|
|
516
|
+
if (ctx.flags.format === 'json' && !launchClaude) {
|
|
191
517
|
output.printJson(result);
|
|
192
518
|
return { success: true, data: result };
|
|
193
519
|
}
|
|
@@ -211,6 +537,44 @@ const spawnCommand = {
|
|
|
211
537
|
output.writeln();
|
|
212
538
|
output.printSuccess(`Spawned ${result.spawned} agent(s)`);
|
|
213
539
|
output.writeln(output.dim(` Total workers in hive: ${result.totalWorkers}`));
|
|
540
|
+
// NEW: Handle --claude flag
|
|
541
|
+
if (launchClaude) {
|
|
542
|
+
// Get objective if not provided
|
|
543
|
+
if (!objective && ctx.interactive) {
|
|
544
|
+
objective = await input({
|
|
545
|
+
message: 'Enter the objective for the hive mind:',
|
|
546
|
+
validate: (v) => v.length > 0 || 'Objective is required when using --claude'
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
if (!objective) {
|
|
550
|
+
output.writeln();
|
|
551
|
+
output.printWarning('No objective provided. Using default objective.');
|
|
552
|
+
objective = 'Coordinate the hive mind workers to complete tasks efficiently.';
|
|
553
|
+
}
|
|
554
|
+
// Get hive status for swarm info
|
|
555
|
+
let swarmId = result.hiveId || 'default';
|
|
556
|
+
let swarmName = 'Hive Mind Swarm';
|
|
557
|
+
try {
|
|
558
|
+
const statusResult = await callMCPTool('hive-mind/status', { includeWorkers: false });
|
|
559
|
+
swarmId = statusResult.hiveId || swarmId;
|
|
560
|
+
}
|
|
561
|
+
catch {
|
|
562
|
+
// Use defaults if status call fails
|
|
563
|
+
}
|
|
564
|
+
// Convert workers to expected format
|
|
565
|
+
const workers = (result.workers || []).map(w => ({
|
|
566
|
+
agentId: w.agentId,
|
|
567
|
+
role: w.role,
|
|
568
|
+
type: agentType,
|
|
569
|
+
joinedAt: w.joinedAt
|
|
570
|
+
}));
|
|
571
|
+
// Launch Claude Code with hive mind prompt
|
|
572
|
+
const claudeResult = await spawnClaudeCodeInstance(swarmId, swarmName, objective, workers, ctx.flags);
|
|
573
|
+
if (!claudeResult.success) {
|
|
574
|
+
return { success: false, exitCode: 1, data: { spawn: result, claude: claudeResult } };
|
|
575
|
+
}
|
|
576
|
+
return { success: true, data: { spawn: result, claude: claudeResult } };
|
|
577
|
+
}
|
|
214
578
|
return { success: true, data: result };
|
|
215
579
|
}
|
|
216
580
|
catch (error) {
|
|
@@ -759,6 +1123,7 @@ export const hiveMindCommand = {
|
|
|
759
1123
|
examples: [
|
|
760
1124
|
{ command: 'claude-flow hive-mind init -t hierarchical-mesh', description: 'Initialize hive' },
|
|
761
1125
|
{ command: 'claude-flow hive-mind spawn -n 5', description: 'Spawn workers' },
|
|
1126
|
+
{ command: 'claude-flow hive-mind spawn --claude -o "Build a feature"', description: 'Launch Claude Code with hive mind' },
|
|
762
1127
|
{ command: 'claude-flow hive-mind task -d "Build feature"', description: 'Submit task' }
|
|
763
1128
|
],
|
|
764
1129
|
action: async () => {
|
|
@@ -770,7 +1135,7 @@ export const hiveMindCommand = {
|
|
|
770
1135
|
output.writeln('Subcommands:');
|
|
771
1136
|
output.printList([
|
|
772
1137
|
`${output.highlight('init')} - Initialize hive mind`,
|
|
773
|
-
`${output.highlight('spawn')} - Spawn worker agents`,
|
|
1138
|
+
`${output.highlight('spawn')} - Spawn worker agents (use --claude to launch Claude Code)`,
|
|
774
1139
|
`${output.highlight('status')} - Show hive status`,
|
|
775
1140
|
`${output.highlight('task')} - Submit task to hive`,
|
|
776
1141
|
`${output.highlight('join')} - Join an agent to the hive`,
|
|
@@ -788,8 +1153,13 @@ export const hiveMindCommand = {
|
|
|
788
1153
|
'Byzantine fault tolerant consensus',
|
|
789
1154
|
'HNSW-accelerated pattern matching',
|
|
790
1155
|
'Cross-session memory persistence',
|
|
791
|
-
'Automatic load balancing'
|
|
1156
|
+
'Automatic load balancing',
|
|
1157
|
+
output.success('NEW: --claude flag to launch interactive Claude Code sessions')
|
|
792
1158
|
]);
|
|
1159
|
+
output.writeln();
|
|
1160
|
+
output.writeln('Quick Start with Claude Code:');
|
|
1161
|
+
output.writeln(output.dim(' claude-flow hive-mind init'));
|
|
1162
|
+
output.writeln(output.dim(' claude-flow hive-mind spawn -n 5 --claude -o "Your objective here"'));
|
|
793
1163
|
return { success: true };
|
|
794
1164
|
}
|
|
795
1165
|
};
|