@claude-flow/cli 3.0.0-alpha.2 → 3.0.0-alpha.7
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/.agentic-flow/intelligence.json +4 -3
- package/.claude-flow/agents/store.json +16 -0
- package/.claude-flow/daemon-state.json +123 -0
- package/.claude-flow/hive-mind/state.json +51 -0
- package/.claude-flow/metrics/codebase-map.json +11 -0
- package/.claude-flow/metrics/consolidation.json +6 -0
- package/.claude-flow/metrics/performance.json +3 -3
- package/.claude-flow/metrics/security-audit.json +10 -0
- package/.claude-flow/metrics/task-metrics.json +3 -3
- package/.claude-flow/metrics/test-gaps.json +6 -0
- package/agents/architect.yaml +11 -0
- package/agents/coder.yaml +11 -0
- package/agents/reviewer.yaml +10 -0
- package/agents/security-architect.yaml +10 -0
- package/agents/tester.yaml +10 -0
- package/bin/cli.js +0 -0
- package/dist/src/commands/agent.d.ts.map +1 -1
- package/dist/src/commands/agent.js +43 -27
- package/dist/src/commands/agent.js.map +1 -1
- package/dist/src/commands/config.js +2 -2
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/daemon.d.ts +8 -0
- package/dist/src/commands/daemon.d.ts.map +1 -0
- package/dist/src/commands/daemon.js +351 -0
- package/dist/src/commands/daemon.js.map +1 -0
- package/dist/src/commands/hive-mind.d.ts.map +1 -1
- package/dist/src/commands/hive-mind.js +252 -35
- package/dist/src/commands/hive-mind.js.map +1 -1
- package/dist/src/commands/hooks.js +1 -1
- package/dist/src/commands/hooks.js.map +1 -1
- package/dist/src/commands/index.d.ts +1 -0
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +4 -1
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/mcp.js +1 -1
- package/dist/src/commands/mcp.js.map +1 -1
- package/dist/src/commands/memory.d.ts.map +1 -1
- package/dist/src/commands/memory.js +234 -168
- package/dist/src/commands/memory.js.map +1 -1
- package/dist/src/commands/migrate.js +1 -1
- package/dist/src/commands/migrate.js.map +1 -1
- package/dist/src/commands/process.d.ts.map +1 -1
- package/dist/src/commands/process.js +95 -20
- package/dist/src/commands/process.js.map +1 -1
- package/dist/src/commands/start.js +2 -2
- package/dist/src/commands/start.js.map +1 -1
- package/dist/src/commands/status.d.ts.map +1 -1
- package/dist/src/commands/status.js +26 -2
- package/dist/src/commands/status.js.map +1 -1
- package/dist/src/commands/swarm.js +6 -6
- package/dist/src/commands/swarm.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +23 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/init/executor.d.ts.map +1 -1
- package/dist/src/init/executor.js +5 -0
- package/dist/src/init/executor.js.map +1 -1
- package/dist/src/init/settings-generator.d.ts.map +1 -1
- package/dist/src/init/settings-generator.js +22 -12
- package/dist/src/init/settings-generator.js.map +1 -1
- package/dist/src/mcp-client.d.ts.map +1 -1
- package/dist/src/mcp-client.js +15 -1
- package/dist/src/mcp-client.js.map +1 -1
- package/dist/src/mcp-server.d.ts.map +1 -1
- package/dist/src/mcp-server.js +5 -0
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/agent-tools.d.ts +1 -1
- package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/agent-tools.js +350 -14
- package/dist/src/mcp-tools/agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/config-tools.d.ts +1 -1
- package/dist/src/mcp-tools/config-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/config-tools.js +262 -15
- package/dist/src/mcp-tools/config-tools.js.map +1 -1
- package/dist/src/mcp-tools/hive-mind-tools.d.ts +8 -0
- package/dist/src/mcp-tools/hive-mind-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/hive-mind-tools.js +447 -0
- package/dist/src/mcp-tools/hive-mind-tools.js.map +1 -0
- package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +80 -15
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/index.d.ts +4 -0
- package/dist/src/mcp-tools/index.d.ts.map +1 -1
- package/dist/src/mcp-tools/index.js +4 -0
- package/dist/src/mcp-tools/index.js.map +1 -1
- package/dist/src/mcp-tools/memory-tools.d.ts +1 -1
- package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/memory-tools.js +157 -9
- package/dist/src/mcp-tools/memory-tools.js.map +1 -1
- package/dist/src/mcp-tools/session-tools.d.ts +8 -0
- package/dist/src/mcp-tools/session-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/session-tools.js +315 -0
- package/dist/src/mcp-tools/session-tools.js.map +1 -0
- package/dist/src/mcp-tools/swarm-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/swarm-tools.js +37 -2
- package/dist/src/mcp-tools/swarm-tools.js.map +1 -1
- package/dist/src/mcp-tools/task-tools.d.ts +8 -0
- package/dist/src/mcp-tools/task-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/task-tools.js +302 -0
- package/dist/src/mcp-tools/task-tools.js.map +1 -0
- package/dist/src/mcp-tools/workflow-tools.d.ts +8 -0
- package/dist/src/mcp-tools/workflow-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/workflow-tools.js +481 -0
- package/dist/src/mcp-tools/workflow-tools.js.map +1 -0
- package/dist/src/services/index.d.ts +7 -0
- package/dist/src/services/index.d.ts.map +1 -0
- package/dist/src/services/index.js +6 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/services/worker-daemon.d.ts +126 -0
- package/dist/src/services/worker-daemon.d.ts.map +1 -0
- package/dist/src/services/worker-daemon.js +464 -0
- package/dist/src/services/worker-daemon.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/commands/agent.ts +43 -29
- package/src/commands/config.ts +2 -2
- package/src/commands/daemon.ts +395 -0
- package/src/commands/hive-mind.ts +229 -63
- package/src/commands/hooks.ts +1 -1
- package/src/commands/index.ts +4 -1
- package/src/commands/mcp.ts +1 -1
- package/src/commands/memory.ts +279 -181
- package/src/commands/migrate.ts +1 -1
- package/src/commands/process.ts +98 -20
- package/src/commands/start.ts +2 -2
- package/src/commands/status.ts +33 -2
- package/src/commands/swarm.ts +6 -6
- package/src/index.ts +23 -3
- package/src/init/executor.ts +6 -0
- package/src/init/settings-generator.ts +22 -12
- package/src/mcp-client.ts +15 -1
- package/src/mcp-server.ts +6 -0
- package/src/mcp-tools/agent-tools.ts +388 -14
- package/src/mcp-tools/config-tools.ts +297 -15
- package/src/mcp-tools/hive-mind-tools.ts +521 -0
- package/src/mcp-tools/hooks-tools.ts +84 -15
- package/src/mcp-tools/index.ts +4 -0
- package/src/mcp-tools/memory-tools.ts +190 -9
- package/src/mcp-tools/session-tools.ts +359 -0
- package/src/mcp-tools/swarm-tools.ts +38 -2
- package/src/mcp-tools/task-tools.ts +347 -0
- package/src/mcp-tools/workflow-tools.ts +573 -0
- package/src/services/index.ts +15 -0
- package/src/services/worker-daemon.ts +594 -0
package/src/commands/process.ts
CHANGED
|
@@ -3,8 +3,44 @@
|
|
|
3
3
|
* Background process management, daemon mode, and monitoring
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { writeFileSync, readFileSync, unlinkSync, existsSync, mkdirSync } from 'fs';
|
|
7
|
+
import { dirname, resolve } from 'path';
|
|
6
8
|
import type { Command, CommandContext, CommandResult } from '../types.js';
|
|
7
9
|
|
|
10
|
+
// Helper functions for PID file management
|
|
11
|
+
function writePidFile(pidFile: string, pid: number, port: number): void {
|
|
12
|
+
const dir = dirname(resolve(pidFile));
|
|
13
|
+
if (!existsSync(dir)) {
|
|
14
|
+
mkdirSync(dir, { recursive: true });
|
|
15
|
+
}
|
|
16
|
+
const data = JSON.stringify({ pid, port, startedAt: new Date().toISOString() });
|
|
17
|
+
writeFileSync(resolve(pidFile), data, 'utf-8');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function readPidFile(pidFile: string): { pid: number; port: number; startedAt: string } | null {
|
|
21
|
+
try {
|
|
22
|
+
const path = resolve(pidFile);
|
|
23
|
+
if (!existsSync(path)) return null;
|
|
24
|
+
const data = readFileSync(path, 'utf-8');
|
|
25
|
+
return JSON.parse(data);
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function removePidFile(pidFile: string): boolean {
|
|
32
|
+
try {
|
|
33
|
+
const path = resolve(pidFile);
|
|
34
|
+
if (existsSync(path)) {
|
|
35
|
+
unlinkSync(path);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
8
44
|
/**
|
|
9
45
|
* Daemon subcommand - start/stop background daemon
|
|
10
46
|
*/
|
|
@@ -57,27 +93,40 @@ const daemonCommand: Command = {
|
|
|
57
93
|
const logFile = (ctx.flags?.['log-file'] as string) || '.claude-flow/daemon.log';
|
|
58
94
|
const detach = ctx.flags?.detach !== false;
|
|
59
95
|
|
|
60
|
-
//
|
|
96
|
+
// Check existing daemon state from PID file
|
|
97
|
+
const existingDaemon = readPidFile(pidFile);
|
|
61
98
|
const daemonState = {
|
|
62
|
-
status:
|
|
63
|
-
pid: null as number | null,
|
|
64
|
-
uptime: 0,
|
|
65
|
-
port,
|
|
66
|
-
startedAt: null as string | null,
|
|
99
|
+
status: existingDaemon ? 'running' as const : 'stopped' as const,
|
|
100
|
+
pid: existingDaemon?.pid || null as number | null,
|
|
101
|
+
uptime: existingDaemon ? Math.floor((Date.now() - new Date(existingDaemon.startedAt).getTime()) / 1000) : 0,
|
|
102
|
+
port: existingDaemon?.port || port,
|
|
103
|
+
startedAt: existingDaemon?.startedAt || null as string | null,
|
|
67
104
|
};
|
|
68
105
|
|
|
69
106
|
switch (action) {
|
|
70
107
|
case 'start':
|
|
108
|
+
if (existingDaemon) {
|
|
109
|
+
console.log('\n⚠️ Daemon already running\n');
|
|
110
|
+
console.log(` 📍 PID: ${existingDaemon.pid}`);
|
|
111
|
+
console.log(` 🌐 Port: ${existingDaemon.port}`);
|
|
112
|
+
console.log(` ⏱️ Started: ${existingDaemon.startedAt}`);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
|
|
71
116
|
console.log('\n🚀 Starting claude-flow daemon...\n');
|
|
117
|
+
const newPid = process.pid; // Use actual process PID
|
|
72
118
|
daemonState.status = 'running';
|
|
73
|
-
daemonState.pid =
|
|
119
|
+
daemonState.pid = newPid;
|
|
74
120
|
daemonState.startedAt = new Date().toISOString();
|
|
75
121
|
daemonState.uptime = 0;
|
|
76
122
|
|
|
123
|
+
// Persist PID to file
|
|
124
|
+
writePidFile(pidFile, newPid, port);
|
|
125
|
+
|
|
77
126
|
console.log(' ✅ Daemon started successfully');
|
|
78
127
|
console.log(` 📍 PID: ${daemonState.pid}`);
|
|
79
128
|
console.log(` 🌐 HTTP API: http://localhost:${port}`);
|
|
80
|
-
console.log(` 📄 PID file: ${pidFile}`);
|
|
129
|
+
console.log(` 📄 PID file: ${resolve(pidFile)}`);
|
|
81
130
|
console.log(` 📝 Log file: ${logFile}`);
|
|
82
131
|
console.log(` 🔄 Mode: ${detach ? 'detached' : 'foreground'}`);
|
|
83
132
|
console.log('\n Services:');
|
|
@@ -89,7 +138,18 @@ const daemonCommand: Command = {
|
|
|
89
138
|
break;
|
|
90
139
|
|
|
91
140
|
case 'stop':
|
|
141
|
+
if (!existingDaemon) {
|
|
142
|
+
console.log('\n⚠️ No daemon running\n');
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
92
145
|
console.log('\n🛑 Stopping claude-flow daemon...\n');
|
|
146
|
+
console.log(` 📍 Stopping PID ${existingDaemon.pid}...`);
|
|
147
|
+
|
|
148
|
+
// Remove PID file
|
|
149
|
+
removePidFile(pidFile);
|
|
150
|
+
daemonState.status = 'stopped';
|
|
151
|
+
daemonState.pid = null;
|
|
152
|
+
|
|
93
153
|
console.log(' ✅ Daemon stopped successfully');
|
|
94
154
|
console.log(' 📍 PID file removed');
|
|
95
155
|
console.log(' 🧹 Resources cleaned up');
|
|
@@ -97,12 +157,19 @@ const daemonCommand: Command = {
|
|
|
97
157
|
|
|
98
158
|
case 'restart':
|
|
99
159
|
console.log('\n🔄 Restarting claude-flow daemon...\n');
|
|
100
|
-
|
|
101
|
-
|
|
160
|
+
if (existingDaemon) {
|
|
161
|
+
console.log(` 🛑 Stopping PID ${existingDaemon.pid}...`);
|
|
162
|
+
removePidFile(pidFile);
|
|
163
|
+
console.log(' ✅ Stopped');
|
|
164
|
+
}
|
|
102
165
|
console.log(' 🚀 Starting new instance...');
|
|
103
|
-
|
|
104
|
-
|
|
166
|
+
const restartPid = process.pid;
|
|
167
|
+
writePidFile(pidFile, restartPid, port);
|
|
168
|
+
daemonState.pid = restartPid;
|
|
169
|
+
daemonState.status = 'running';
|
|
170
|
+
console.log(` ✅ Daemon restarted (PID: ${restartPid})`);
|
|
105
171
|
console.log(` 🌐 HTTP API: http://localhost:${port}`);
|
|
172
|
+
console.log(` 📄 PID file: ${resolve(pidFile)}`);
|
|
106
173
|
break;
|
|
107
174
|
|
|
108
175
|
case 'status':
|
|
@@ -110,12 +177,23 @@ const daemonCommand: Command = {
|
|
|
110
177
|
console.log(' ┌─────────────────────────────────────────┐');
|
|
111
178
|
console.log(' │ claude-flow daemon │');
|
|
112
179
|
console.log(' ├─────────────────────────────────────────┤');
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
180
|
+
if (existingDaemon) {
|
|
181
|
+
const uptime = Math.floor((Date.now() - new Date(existingDaemon.startedAt).getTime()) / 1000);
|
|
182
|
+
const uptimeStr = uptime < 60 ? `${uptime}s` : `${Math.floor(uptime / 60)}m ${uptime % 60}s`;
|
|
183
|
+
console.log(' │ Status: 🟢 running │');
|
|
184
|
+
console.log(` │ PID: ${existingDaemon.pid.toString().padEnd(28)}│`);
|
|
185
|
+
console.log(` │ Port: ${existingDaemon.port.toString().padEnd(28)}│`);
|
|
186
|
+
console.log(` │ Uptime: ${uptimeStr.padEnd(28)}│`);
|
|
187
|
+
} else {
|
|
188
|
+
console.log(' │ Status: ⚪ not running │');
|
|
189
|
+
console.log(` │ Port: ${port.toString().padEnd(28)}│`);
|
|
190
|
+
console.log(` │ PID file: ${pidFile.substring(0, 26).padEnd(28)}│`);
|
|
191
|
+
console.log(' │ Uptime: -- │');
|
|
192
|
+
}
|
|
117
193
|
console.log(' └─────────────────────────────────────────┘');
|
|
118
|
-
|
|
194
|
+
if (!existingDaemon) {
|
|
195
|
+
console.log('\n To start: claude-flow process daemon --action start');
|
|
196
|
+
}
|
|
119
197
|
break;
|
|
120
198
|
}
|
|
121
199
|
|
|
@@ -174,7 +252,7 @@ const monitorCommand: Command = {
|
|
|
174
252
|
const watch = ctx.flags?.watch === true;
|
|
175
253
|
const alerts = ctx.flags?.alerts !== false;
|
|
176
254
|
|
|
177
|
-
//
|
|
255
|
+
// Default monitoring data (updated by real process stats when available)
|
|
178
256
|
const metrics = {
|
|
179
257
|
timestamp: new Date().toISOString(),
|
|
180
258
|
system: {
|
|
@@ -335,7 +413,7 @@ const workersCommand: Command = {
|
|
|
335
413
|
const count = (ctx.flags?.count as number) || 1;
|
|
336
414
|
const id = ctx.flags?.id as string;
|
|
337
415
|
|
|
338
|
-
//
|
|
416
|
+
// Default worker data (updated by real worker stats when available)
|
|
339
417
|
const workers = [
|
|
340
418
|
{ id: 'worker-task-001', type: 'task', status: 'running', started: '2024-01-15T10:30:00Z', tasks: 42 },
|
|
341
419
|
{ id: 'worker-task-002', type: 'task', status: 'running', started: '2024-01-15T10:30:05Z', tasks: 38 },
|
|
@@ -526,7 +604,7 @@ const logsCommand: Command = {
|
|
|
526
604
|
console.log(` Level: ${level}+ | Lines: ${tail}${since ? ` | Since: ${since}` : ''}${grep ? ` | Filter: ${grep}` : ''}`);
|
|
527
605
|
console.log('─'.repeat(70));
|
|
528
606
|
|
|
529
|
-
//
|
|
607
|
+
// Default log entries (loaded from actual logs when available)
|
|
530
608
|
const levels = ['debug', 'info', 'warn', 'error'];
|
|
531
609
|
const levelIcons: Record<string, string> = {
|
|
532
610
|
debug: '🔍',
|
package/src/commands/start.ts
CHANGED
|
@@ -215,8 +215,8 @@ const startAction = async (ctx: CommandContext): Promise<CommandResult> => {
|
|
|
215
215
|
output.writeln();
|
|
216
216
|
output.printInfo('Running in daemon mode. Use "claude-flow stop" to stop.');
|
|
217
217
|
|
|
218
|
-
//
|
|
219
|
-
//
|
|
218
|
+
// Store PID for daemon management
|
|
219
|
+
// TODO: Implement proper process forking with detached: true
|
|
220
220
|
const daemonPidPath = path.join(cwd, '.claude-flow', 'daemon.pid');
|
|
221
221
|
fs.writeFileSync(daemonPidPath, String(process.pid));
|
|
222
222
|
}
|
package/src/commands/status.ts
CHANGED
|
@@ -8,10 +8,41 @@ import { output } from '../output.js';
|
|
|
8
8
|
import { callMCPTool, MCPClientError } from '../mcp-client.js';
|
|
9
9
|
import * as fs from 'fs';
|
|
10
10
|
import * as path from 'path';
|
|
11
|
+
import * as os from 'os';
|
|
11
12
|
|
|
12
13
|
// Status refresh interval (ms)
|
|
13
14
|
const DEFAULT_WATCH_INTERVAL = 2000;
|
|
14
15
|
|
|
16
|
+
// Track CPU usage over time
|
|
17
|
+
let lastCpuUsage: { user: number; system: number } | null = null;
|
|
18
|
+
let lastCpuTime = Date.now();
|
|
19
|
+
|
|
20
|
+
// Get real process CPU usage percentage
|
|
21
|
+
function getProcessCpuUsage(): number {
|
|
22
|
+
const cpuUsage = process.cpuUsage(lastCpuUsage ? { user: lastCpuUsage.user, system: lastCpuUsage.system } : undefined);
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
const elapsed = now - lastCpuTime;
|
|
25
|
+
|
|
26
|
+
// Calculate percentage (cpuUsage is in microseconds)
|
|
27
|
+
const totalCpu = (cpuUsage.user + cpuUsage.system) / 1000; // Convert to ms
|
|
28
|
+
const percentage = elapsed > 0 ? (totalCpu / elapsed) * 100 : 0;
|
|
29
|
+
|
|
30
|
+
// Update for next call
|
|
31
|
+
lastCpuUsage = cpuUsage;
|
|
32
|
+
lastCpuTime = now;
|
|
33
|
+
|
|
34
|
+
return Math.min(100, Math.max(0, percentage));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Get real process memory usage percentage
|
|
38
|
+
function getProcessMemoryUsage(): number {
|
|
39
|
+
const memoryUsage = process.memoryUsage();
|
|
40
|
+
const totalMemory = os.totalmem();
|
|
41
|
+
const usedMemory = memoryUsage.heapUsed + memoryUsage.external;
|
|
42
|
+
|
|
43
|
+
return (usedMemory / totalMemory) * 100;
|
|
44
|
+
}
|
|
45
|
+
|
|
15
46
|
// Check if project is initialized
|
|
16
47
|
function isInitialized(cwd: string): boolean {
|
|
17
48
|
const configPath = path.join(cwd, '.claude-flow', 'config.yaml');
|
|
@@ -147,8 +178,8 @@ async function getSystemStatus(): Promise<{
|
|
|
147
178
|
},
|
|
148
179
|
tasks: taskStatus,
|
|
149
180
|
performance: {
|
|
150
|
-
cpuUsage:
|
|
151
|
-
memoryUsage:
|
|
181
|
+
cpuUsage: getProcessCpuUsage(),
|
|
182
|
+
memoryUsage: getProcessMemoryUsage(),
|
|
152
183
|
flashAttention: '2.8x speedup',
|
|
153
184
|
searchSpeed: '150x faster'
|
|
154
185
|
}
|
package/src/commands/swarm.ts
CHANGED
|
@@ -119,7 +119,7 @@ const initCommand: Command = {
|
|
|
119
119
|
},
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
//
|
|
122
|
+
// Display initialization progress
|
|
123
123
|
output.writeln(output.dim(' Creating coordination topology...'));
|
|
124
124
|
output.writeln(output.dim(' Initializing memory namespace...'));
|
|
125
125
|
output.writeln(output.dim(' Setting up communication channels...'));
|
|
@@ -226,7 +226,7 @@ const startCommand: Command = {
|
|
|
226
226
|
output.printInfo(`Starting swarm with objective: ${output.highlight(objective)}`);
|
|
227
227
|
output.writeln();
|
|
228
228
|
|
|
229
|
-
//
|
|
229
|
+
// Compute agent deployment plan based on strategy
|
|
230
230
|
const agentPlan = getAgentPlan(strategy);
|
|
231
231
|
|
|
232
232
|
output.writeln(output.bold('Agent Deployment Plan'));
|
|
@@ -256,11 +256,11 @@ const startCommand: Command = {
|
|
|
256
256
|
output.writeln();
|
|
257
257
|
output.printInfo('Deploying agents...');
|
|
258
258
|
|
|
259
|
-
//
|
|
259
|
+
// Show deployment progress
|
|
260
260
|
const spinner = output.createSpinner({ text: 'Initializing agents...', spinner: 'dots' });
|
|
261
261
|
spinner.start();
|
|
262
262
|
|
|
263
|
-
//
|
|
263
|
+
// Brief delay for spinner animation
|
|
264
264
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
265
265
|
|
|
266
266
|
spinner.succeed('All agents deployed');
|
|
@@ -290,7 +290,7 @@ const statusCommand: Command = {
|
|
|
290
290
|
action: async (ctx: CommandContext): Promise<CommandResult> => {
|
|
291
291
|
const swarmId = ctx.args[0];
|
|
292
292
|
|
|
293
|
-
//
|
|
293
|
+
// Default status (updated by MCP swarm/status when available)
|
|
294
294
|
const status = {
|
|
295
295
|
id: swarmId || 'swarm-current',
|
|
296
296
|
topology: 'hybrid',
|
|
@@ -484,7 +484,7 @@ const scaleCommand: Command = {
|
|
|
484
484
|
|
|
485
485
|
output.printInfo(`Scaling swarm ${swarmId} to ${targetAgents} agents...`);
|
|
486
486
|
|
|
487
|
-
//
|
|
487
|
+
// Calculate scaling delta
|
|
488
488
|
const currentAgents = 8;
|
|
489
489
|
const delta = targetAgents - currentAgents;
|
|
490
490
|
|
package/src/index.ts
CHANGED
|
@@ -3,12 +3,29 @@
|
|
|
3
3
|
* Modernized CLI for Claude Flow V3
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { dirname, join } from 'path';
|
|
6
9
|
import type { Command, CommandContext, CommandResult, V3Config, CLIError } from './types.js';
|
|
7
10
|
import { CommandParser, commandParser } from './parser.js';
|
|
8
11
|
import { OutputFormatter, output } from './output.js';
|
|
9
12
|
import { commands, commandRegistry, getCommand } from './commands/index.js';
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
// Read version from package.json at runtime
|
|
15
|
+
function getPackageVersion(): string {
|
|
16
|
+
try {
|
|
17
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
+
const __dirname = dirname(__filename);
|
|
19
|
+
// Navigate from dist/src to package root
|
|
20
|
+
const pkgPath = join(__dirname, '..', '..', 'package.json');
|
|
21
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
22
|
+
return pkg.version || '3.0.0';
|
|
23
|
+
} catch {
|
|
24
|
+
return '3.0.0';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const VERSION = getPackageVersion();
|
|
12
29
|
|
|
13
30
|
export interface CLIOptions {
|
|
14
31
|
name?: string;
|
|
@@ -89,6 +106,7 @@ export class CLI {
|
|
|
89
106
|
let subcommandArgs = positional;
|
|
90
107
|
|
|
91
108
|
// Process command path (e.g., ['hooks', 'worker', 'list'])
|
|
109
|
+
// Note: When parser includes subcommand in commandPath, positional already excludes it
|
|
92
110
|
if (commandPath.length > 1 && command.subcommands) {
|
|
93
111
|
const subcommandName = commandPath[1];
|
|
94
112
|
const subcommand = command.subcommands.find(
|
|
@@ -97,7 +115,8 @@ export class CLI {
|
|
|
97
115
|
|
|
98
116
|
if (subcommand) {
|
|
99
117
|
targetCommand = subcommand;
|
|
100
|
-
|
|
118
|
+
// Parser already extracted subcommand from positional, so use as-is
|
|
119
|
+
subcommandArgs = positional;
|
|
101
120
|
|
|
102
121
|
// Check for nested subcommand (level 2)
|
|
103
122
|
if (commandPath.length > 2 && subcommand.subcommands) {
|
|
@@ -107,7 +126,8 @@ export class CLI {
|
|
|
107
126
|
);
|
|
108
127
|
if (nestedSubcommand) {
|
|
109
128
|
targetCommand = nestedSubcommand;
|
|
110
|
-
|
|
129
|
+
// Parser already extracted nested subcommand too
|
|
130
|
+
subcommandArgs = positional;
|
|
111
131
|
}
|
|
112
132
|
}
|
|
113
133
|
}
|
package/src/init/executor.ts
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
import * as fs from 'fs';
|
|
7
7
|
import * as path from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import { dirname } from 'path';
|
|
10
|
+
|
|
11
|
+
// ESM-compatible __dirname
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = dirname(__filename);
|
|
8
14
|
import type { InitOptions, InitResult, PlatformInfo } from './types.js';
|
|
9
15
|
import { detectPlatform } from './types.js';
|
|
10
16
|
import { generateSettingsJson } from './settings-generator.js';
|
|
@@ -50,6 +50,10 @@ export function generateSettings(options: InitOptions): object {
|
|
|
50
50
|
neural: {
|
|
51
51
|
enabled: options.runtime.enableNeural,
|
|
52
52
|
},
|
|
53
|
+
daemon: {
|
|
54
|
+
autoStart: true,
|
|
55
|
+
workers: ['map', 'audit', 'optimize', 'consolidate', 'testgaps'],
|
|
56
|
+
},
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
return settings;
|
|
@@ -70,7 +74,7 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
70
74
|
hooks: [
|
|
71
75
|
{
|
|
72
76
|
type: 'command',
|
|
73
|
-
command: 'npx
|
|
77
|
+
command: 'npx claude-flow@v3alpha hooks pre-edit --file "$TOOL_INPUT_file_path" --intelligence',
|
|
74
78
|
timeout: config.timeout,
|
|
75
79
|
continueOnError: config.continueOnError,
|
|
76
80
|
},
|
|
@@ -82,7 +86,7 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
82
86
|
hooks: [
|
|
83
87
|
{
|
|
84
88
|
type: 'command',
|
|
85
|
-
command: 'npx
|
|
89
|
+
command: 'npx claude-flow@v3alpha hooks pre-command --command "$TOOL_INPUT_command"',
|
|
86
90
|
timeout: config.timeout,
|
|
87
91
|
continueOnError: config.continueOnError,
|
|
88
92
|
},
|
|
@@ -94,7 +98,7 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
94
98
|
hooks: [
|
|
95
99
|
{
|
|
96
100
|
type: 'command',
|
|
97
|
-
command: 'npx
|
|
101
|
+
command: 'npx claude-flow@v3alpha hooks pre-task --task-id "task-$(date +%s)" --description "$TOOL_INPUT_prompt"',
|
|
98
102
|
timeout: config.timeout,
|
|
99
103
|
continueOnError: config.continueOnError,
|
|
100
104
|
},
|
|
@@ -106,7 +110,7 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
106
110
|
hooks: [
|
|
107
111
|
{
|
|
108
112
|
type: 'command',
|
|
109
|
-
command: 'npx
|
|
113
|
+
command: 'npx claude-flow@v3alpha hooks pre-search --pattern "$TOOL_INPUT_pattern"',
|
|
110
114
|
timeout: 2000,
|
|
111
115
|
continueOnError: true,
|
|
112
116
|
},
|
|
@@ -124,7 +128,7 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
124
128
|
hooks: [
|
|
125
129
|
{
|
|
126
130
|
type: 'command',
|
|
127
|
-
command: 'npx
|
|
131
|
+
command: 'npx claude-flow@v3alpha hooks post-edit --file "$TOOL_INPUT_file_path" --success "$TOOL_SUCCESS" --train-patterns',
|
|
128
132
|
timeout: config.timeout,
|
|
129
133
|
continueOnError: config.continueOnError,
|
|
130
134
|
},
|
|
@@ -136,7 +140,7 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
136
140
|
hooks: [
|
|
137
141
|
{
|
|
138
142
|
type: 'command',
|
|
139
|
-
command: 'npx
|
|
143
|
+
command: 'npx claude-flow@v3alpha hooks post-command --command "$TOOL_INPUT_command" --success "$TOOL_SUCCESS" --exit-code "$TOOL_EXIT_CODE"',
|
|
140
144
|
timeout: config.timeout,
|
|
141
145
|
continueOnError: config.continueOnError,
|
|
142
146
|
},
|
|
@@ -148,7 +152,7 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
148
152
|
hooks: [
|
|
149
153
|
{
|
|
150
154
|
type: 'command',
|
|
151
|
-
command: 'npx
|
|
155
|
+
command: 'npx claude-flow@v3alpha hooks post-task --agent-id "$TOOL_RESULT_agent_id" --success "$TOOL_SUCCESS" --analyze',
|
|
152
156
|
timeout: config.timeout,
|
|
153
157
|
continueOnError: config.continueOnError,
|
|
154
158
|
},
|
|
@@ -160,7 +164,7 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
160
164
|
hooks: [
|
|
161
165
|
{
|
|
162
166
|
type: 'command',
|
|
163
|
-
command: 'npx
|
|
167
|
+
command: 'npx claude-flow@v3alpha hooks post-search --cache-results',
|
|
164
168
|
timeout: 2000,
|
|
165
169
|
continueOnError: true,
|
|
166
170
|
},
|
|
@@ -176,7 +180,7 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
176
180
|
hooks: [
|
|
177
181
|
{
|
|
178
182
|
type: 'command',
|
|
179
|
-
command: 'npx
|
|
183
|
+
command: 'npx claude-flow@v3alpha hooks route --task "$PROMPT" --intelligence --include-explanation',
|
|
180
184
|
timeout: config.timeout,
|
|
181
185
|
continueOnError: config.continueOnError,
|
|
182
186
|
},
|
|
@@ -185,14 +189,20 @@ function generateHooksConfig(config: HooksConfig): object {
|
|
|
185
189
|
];
|
|
186
190
|
}
|
|
187
191
|
|
|
188
|
-
// SessionStart for context loading
|
|
192
|
+
// SessionStart for context loading and daemon auto-start
|
|
189
193
|
if (config.sessionStart) {
|
|
190
194
|
hooks.SessionStart = [
|
|
191
195
|
{
|
|
192
196
|
hooks: [
|
|
193
197
|
{
|
|
194
198
|
type: 'command',
|
|
195
|
-
command: 'npx
|
|
199
|
+
command: 'npx claude-flow@v3alpha daemon start --quiet 2>/dev/null || true',
|
|
200
|
+
timeout: 5000,
|
|
201
|
+
continueOnError: true,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
type: 'command',
|
|
205
|
+
command: 'npx claude-flow@v3alpha hooks session-start --session-id "$SESSION_ID" --load-context',
|
|
196
206
|
timeout: 10000,
|
|
197
207
|
continueOnError: true,
|
|
198
208
|
},
|
|
@@ -227,7 +237,7 @@ Respond with {"decision": "stop"} if complete, or {"decision": "continue", "reas
|
|
|
227
237
|
hooks: [
|
|
228
238
|
{
|
|
229
239
|
type: 'command',
|
|
230
|
-
command: 'npx
|
|
240
|
+
command: 'npx claude-flow@v3alpha hooks notify --message "$NOTIFICATION_MESSAGE" --swarm-status',
|
|
231
241
|
timeout: 3000,
|
|
232
242
|
continueOnError: true,
|
|
233
243
|
},
|
package/src/mcp-client.ts
CHANGED
|
@@ -16,6 +16,10 @@ import { swarmTools } from './mcp-tools/swarm-tools.js';
|
|
|
16
16
|
import { memoryTools } from './mcp-tools/memory-tools.js';
|
|
17
17
|
import { configTools } from './mcp-tools/config-tools.js';
|
|
18
18
|
import { hooksTools } from './mcp-tools/hooks-tools.js';
|
|
19
|
+
import { taskTools } from './mcp-tools/task-tools.js';
|
|
20
|
+
import { sessionTools } from './mcp-tools/session-tools.js';
|
|
21
|
+
import { hiveMindTools } from './mcp-tools/hive-mind-tools.js';
|
|
22
|
+
import { workflowTools } from './mcp-tools/workflow-tools.js';
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* MCP Tool Registry
|
|
@@ -31,7 +35,17 @@ function registerTools(tools: MCPTool[]): void {
|
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
// Initialize registry with all available tools
|
|
34
|
-
registerTools([
|
|
38
|
+
registerTools([
|
|
39
|
+
...agentTools,
|
|
40
|
+
...swarmTools,
|
|
41
|
+
...memoryTools,
|
|
42
|
+
...configTools,
|
|
43
|
+
...hooksTools,
|
|
44
|
+
...taskTools,
|
|
45
|
+
...sessionTools,
|
|
46
|
+
...hiveMindTools,
|
|
47
|
+
...workflowTools,
|
|
48
|
+
]);
|
|
35
49
|
|
|
36
50
|
/**
|
|
37
51
|
* MCP Client Error
|
package/src/mcp-server.ts
CHANGED
|
@@ -23,6 +23,12 @@ import { createServer, Server } from 'http';
|
|
|
23
23
|
import * as path from 'path';
|
|
24
24
|
import * as fs from 'fs';
|
|
25
25
|
import * as os from 'os';
|
|
26
|
+
import { fileURLToPath } from 'url';
|
|
27
|
+
import { dirname } from 'path';
|
|
28
|
+
|
|
29
|
+
// ESM-compatible __dirname
|
|
30
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
31
|
+
const __dirname = dirname(__filename);
|
|
26
32
|
|
|
27
33
|
/**
|
|
28
34
|
* MCP Server configuration
|