@claude-flow/cli 3.0.0-alpha.1 → 3.0.0-alpha.6
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/metrics/performance.json +3 -3
- package/.claude-flow/metrics/task-metrics.json +3 -3
- 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.js +1 -1
- 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/hooks.js +1 -1
- package/dist/src/commands/hooks.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/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 +18 -1
- 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/helpers-generator.d.ts.map +1 -1
- package/dist/src/init/helpers-generator.js +1 -1
- package/dist/src/init/helpers-generator.js.map +1 -1
- package/dist/src/init/types.d.ts.map +1 -1
- package/dist/src/init/types.js +2 -2
- package/dist/src/init/types.js.map +1 -1
- package/dist/src/mcp-client.d.ts.map +1 -1
- package/dist/src/mcp-client.js +3 -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/hooks-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +34 -8
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/index.d.ts +2 -0
- package/dist/src/mcp-tools/index.d.ts.map +1 -1
- package/dist/src/mcp-tools/index.js +2 -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 +100 -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 +100 -0
- package/dist/src/mcp-tools/task-tools.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/commands/agent.ts +1 -1
- package/src/commands/config.ts +2 -2
- package/src/commands/hooks.ts +1 -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/status.ts +33 -2
- package/src/commands/swarm.ts +6 -6
- package/src/index.ts +18 -1
- package/src/init/executor.ts +6 -0
- package/src/init/helpers-generator.ts +1 -1
- package/src/init/types.ts +3 -3
- package/src/mcp-client.ts +3 -1
- package/src/mcp-server.ts +6 -0
- package/src/mcp-tools/hooks-tools.ts +38 -8
- package/src/mcp-tools/index.ts +2 -0
- package/src/mcp-tools/memory-tools.ts +190 -9
- package/src/mcp-tools/session-tools.ts +102 -0
- package/src/mcp-tools/swarm-tools.ts +38 -2
- package/src/mcp-tools/task-tools.ts +102 -0
- package/tmp.json +0 -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/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;
|
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';
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { InitOptions } from './types.js';
|
|
7
|
+
import { generateStatuslineScript, generateStatuslineHook } from './statusline-generator.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Generate pre-commit hook script
|
|
@@ -619,7 +620,6 @@ export function generateHelpers(options: InitOptions): Record<string, string> {
|
|
|
619
620
|
}
|
|
620
621
|
|
|
621
622
|
if (options.components.statusline) {
|
|
622
|
-
const { generateStatuslineScript, generateStatuslineHook } = require('./statusline-generator.js');
|
|
623
623
|
helpers['statusline.js'] = generateStatuslineScript(options);
|
|
624
624
|
helpers['statusline-hook.sh'] = generateStatuslineHook(options);
|
|
625
625
|
}
|
package/src/init/types.ts
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* Configuration options for initializing Claude Code integration
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import os from 'os';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* Components that can be initialized
|
|
8
11
|
*/
|
|
@@ -187,9 +190,6 @@ export interface PlatformInfo {
|
|
|
187
190
|
* Detect current platform
|
|
188
191
|
*/
|
|
189
192
|
export function detectPlatform(): PlatformInfo {
|
|
190
|
-
const os = require('os');
|
|
191
|
-
const path = require('path');
|
|
192
|
-
|
|
193
193
|
const platform = os.platform();
|
|
194
194
|
const arch = os.arch();
|
|
195
195
|
const homeDir = os.homedir();
|
package/src/mcp-client.ts
CHANGED
|
@@ -16,6 +16,8 @@ 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';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* MCP Tool Registry
|
|
@@ -31,7 +33,7 @@ function registerTools(tools: MCPTool[]): void {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
// Initialize registry with all available tools
|
|
34
|
-
registerTools([...agentTools, ...swarmTools, ...memoryTools, ...configTools, ...hooksTools]);
|
|
36
|
+
registerTools([...agentTools, ...swarmTools, ...memoryTools, ...configTools, ...hooksTools, ...taskTools, ...sessionTools]);
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
39
|
* 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
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* Provides intelligent hooks functionality via MCP protocol
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { mkdirSync, writeFileSync, existsSync } from 'fs';
|
|
7
|
+
import { join, resolve } from 'path';
|
|
6
8
|
import type { MCPTool } from './types.js';
|
|
7
9
|
|
|
8
|
-
//
|
|
10
|
+
// Agent routing configuration - maps file types to recommended agents
|
|
9
11
|
const AGENT_PATTERNS: Record<string, string[]> = {
|
|
10
12
|
'.ts': ['coder', 'architect', 'tester'],
|
|
11
13
|
'.tsx': ['coder', 'architect', 'reviewer'],
|
|
@@ -568,19 +570,21 @@ export const hooksBuildAgents: MCPTool = {
|
|
|
568
570
|
outputDir: { type: 'string', description: 'Output directory for configs' },
|
|
569
571
|
focus: { type: 'string', description: 'Focus area (v3-implementation, security, performance, all)' },
|
|
570
572
|
format: { type: 'string', description: 'Config format (yaml, json)' },
|
|
573
|
+
persist: { type: 'boolean', description: 'Write configs to disk' },
|
|
571
574
|
},
|
|
572
575
|
},
|
|
573
576
|
handler: async (params: Record<string, unknown>) => {
|
|
574
|
-
const outputDir = (params.outputDir as string) || './agents';
|
|
577
|
+
const outputDir = resolve((params.outputDir as string) || './agents');
|
|
575
578
|
const focus = (params.focus as string) || 'all';
|
|
576
579
|
const format = (params.format as string) || 'yaml';
|
|
580
|
+
const persist = params.persist !== false; // Default to true
|
|
577
581
|
|
|
578
582
|
const agents = [
|
|
579
|
-
{ type: 'coder', configFile:
|
|
580
|
-
{ type: 'architect', configFile:
|
|
581
|
-
{ type: 'tester', configFile:
|
|
582
|
-
{ type: 'security-architect', configFile:
|
|
583
|
-
{ type: 'reviewer', configFile:
|
|
583
|
+
{ type: 'coder', configFile: join(outputDir, `coder.${format}`), capabilities: ['code-generation', 'refactoring', 'debugging'], optimizations: ['flash-attention', 'token-reduction'] },
|
|
584
|
+
{ type: 'architect', configFile: join(outputDir, `architect.${format}`), capabilities: ['system-design', 'api-design', 'documentation'], optimizations: ['context-caching', 'memory-persistence'] },
|
|
585
|
+
{ type: 'tester', configFile: join(outputDir, `tester.${format}`), capabilities: ['unit-testing', 'integration-testing', 'coverage'], optimizations: ['parallel-execution'] },
|
|
586
|
+
{ type: 'security-architect', configFile: join(outputDir, `security-architect.${format}`), capabilities: ['threat-modeling', 'vulnerability-analysis', 'security-review'], optimizations: ['pattern-matching'] },
|
|
587
|
+
{ type: 'reviewer', configFile: join(outputDir, `reviewer.${format}`), capabilities: ['code-review', 'quality-analysis', 'best-practices'], optimizations: ['incremental-analysis'] },
|
|
584
588
|
];
|
|
585
589
|
|
|
586
590
|
const filteredAgents = focus === 'all' ? agents :
|
|
@@ -588,9 +592,35 @@ export const hooksBuildAgents: MCPTool = {
|
|
|
588
592
|
focus === 'performance' ? agents.filter(a => ['coder', 'tester'].includes(a.type)) :
|
|
589
593
|
agents;
|
|
590
594
|
|
|
595
|
+
// Persist configs to disk if requested
|
|
596
|
+
if (persist) {
|
|
597
|
+
// Ensure output directory exists
|
|
598
|
+
if (!existsSync(outputDir)) {
|
|
599
|
+
mkdirSync(outputDir, { recursive: true });
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// Write each agent config
|
|
603
|
+
for (const agent of filteredAgents) {
|
|
604
|
+
const config = {
|
|
605
|
+
type: agent.type,
|
|
606
|
+
capabilities: agent.capabilities,
|
|
607
|
+
optimizations: agent.optimizations,
|
|
608
|
+
version: '3.0.0',
|
|
609
|
+
createdAt: new Date().toISOString(),
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
const content = format === 'json'
|
|
613
|
+
? JSON.stringify(config, null, 2)
|
|
614
|
+
: `# ${agent.type} agent configuration\ntype: ${agent.type}\nversion: "3.0.0"\ncapabilities:\n${agent.capabilities.map(c => ` - ${c}`).join('\n')}\noptimizations:\n${agent.optimizations.map(o => ` - ${o}`).join('\n')}\ncreatedAt: "${config.createdAt}"\n`;
|
|
615
|
+
|
|
616
|
+
writeFileSync(agent.configFile, content, 'utf-8');
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
591
620
|
return {
|
|
592
621
|
outputDir,
|
|
593
622
|
focus,
|
|
623
|
+
persisted: persist,
|
|
594
624
|
agents: filteredAgents,
|
|
595
625
|
stats: {
|
|
596
626
|
configsGenerated: filteredAgents.length,
|
|
@@ -699,7 +729,7 @@ export const hooksSessionEnd: MCPTool = {
|
|
|
699
729
|
},
|
|
700
730
|
handler: async (params: Record<string, unknown>) => {
|
|
701
731
|
const saveState = params.saveState !== false;
|
|
702
|
-
const sessionId = `session-${Date.now() - 3600000}`; //
|
|
732
|
+
const sessionId = `session-${Date.now() - 3600000}`; // Default session (1 hour ago)
|
|
703
733
|
|
|
704
734
|
return {
|
|
705
735
|
sessionId,
|
package/src/mcp-tools/index.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { swarmTools } from './swarm-tools.js';
|
|
|
10
10
|
export { memoryTools } from './memory-tools.js';
|
|
11
11
|
export { configTools } from './config-tools.js';
|
|
12
12
|
export { hooksTools } from './hooks-tools.js';
|
|
13
|
+
export { taskTools } from './task-tools.js';
|
|
14
|
+
export { sessionTools } from './session-tools.js';
|