@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
|
@@ -1,11 +1,67 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agent MCP Tools for CLI
|
|
3
3
|
*
|
|
4
|
-
* Tool definitions for agent lifecycle management.
|
|
4
|
+
* Tool definitions for agent lifecycle management with file persistence.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
7
9
|
import type { MCPTool } from './types.js';
|
|
8
10
|
|
|
11
|
+
// Storage paths
|
|
12
|
+
const STORAGE_DIR = '.claude-flow';
|
|
13
|
+
const AGENT_DIR = 'agents';
|
|
14
|
+
const AGENT_FILE = 'store.json';
|
|
15
|
+
|
|
16
|
+
interface AgentRecord {
|
|
17
|
+
agentId: string;
|
|
18
|
+
agentType: string;
|
|
19
|
+
status: 'idle' | 'busy' | 'terminated';
|
|
20
|
+
health: number;
|
|
21
|
+
taskCount: number;
|
|
22
|
+
config: Record<string, unknown>;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
domain?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface AgentStore {
|
|
28
|
+
agents: Record<string, AgentRecord>;
|
|
29
|
+
version: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getAgentDir(): string {
|
|
33
|
+
return join(process.cwd(), STORAGE_DIR, AGENT_DIR);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getAgentPath(): string {
|
|
37
|
+
return join(getAgentDir(), AGENT_FILE);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function ensureAgentDir(): void {
|
|
41
|
+
const dir = getAgentDir();
|
|
42
|
+
if (!existsSync(dir)) {
|
|
43
|
+
mkdirSync(dir, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function loadAgentStore(): AgentStore {
|
|
48
|
+
try {
|
|
49
|
+
const path = getAgentPath();
|
|
50
|
+
if (existsSync(path)) {
|
|
51
|
+
const data = readFileSync(path, 'utf-8');
|
|
52
|
+
return JSON.parse(data);
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
// Return empty store on error
|
|
56
|
+
}
|
|
57
|
+
return { agents: {}, version: '3.0.0' };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function saveAgentStore(store: AgentStore): void {
|
|
61
|
+
ensureAgentDir();
|
|
62
|
+
writeFileSync(getAgentPath(), JSON.stringify(store, null, 2), 'utf-8');
|
|
63
|
+
}
|
|
64
|
+
|
|
9
65
|
export const agentTools: MCPTool[] = [
|
|
10
66
|
{
|
|
11
67
|
name: 'agent/spawn',
|
|
@@ -17,16 +73,34 @@ export const agentTools: MCPTool[] = [
|
|
|
17
73
|
agentType: { type: 'string', description: 'Type of agent to spawn' },
|
|
18
74
|
agentId: { type: 'string', description: 'Optional custom agent ID' },
|
|
19
75
|
config: { type: 'object', description: 'Agent configuration' },
|
|
76
|
+
domain: { type: 'string', description: 'Agent domain' },
|
|
20
77
|
},
|
|
21
78
|
required: ['agentType'],
|
|
22
79
|
},
|
|
23
80
|
handler: async (input) => {
|
|
24
|
-
|
|
81
|
+
const store = loadAgentStore();
|
|
82
|
+
const agentId = (input.agentId as string) || `agent-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
83
|
+
|
|
84
|
+
const agent: AgentRecord = {
|
|
85
|
+
agentId,
|
|
86
|
+
agentType: input.agentType as string,
|
|
87
|
+
status: 'idle',
|
|
88
|
+
health: 1.0,
|
|
89
|
+
taskCount: 0,
|
|
90
|
+
config: (input.config as Record<string, unknown>) || {},
|
|
91
|
+
createdAt: new Date().toISOString(),
|
|
92
|
+
domain: input.domain as string,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
store.agents[agentId] = agent;
|
|
96
|
+
saveAgentStore(store);
|
|
97
|
+
|
|
25
98
|
return {
|
|
26
99
|
success: true,
|
|
27
|
-
agentId
|
|
28
|
-
agentType:
|
|
100
|
+
agentId,
|
|
101
|
+
agentType: agent.agentType,
|
|
29
102
|
status: 'spawned',
|
|
103
|
+
createdAt: agent.createdAt,
|
|
30
104
|
};
|
|
31
105
|
},
|
|
32
106
|
},
|
|
@@ -43,10 +117,24 @@ export const agentTools: MCPTool[] = [
|
|
|
43
117
|
required: ['agentId'],
|
|
44
118
|
},
|
|
45
119
|
handler: async (input) => {
|
|
120
|
+
const store = loadAgentStore();
|
|
121
|
+
const agentId = input.agentId as string;
|
|
122
|
+
|
|
123
|
+
if (store.agents[agentId]) {
|
|
124
|
+
store.agents[agentId].status = 'terminated';
|
|
125
|
+
saveAgentStore(store);
|
|
126
|
+
return {
|
|
127
|
+
success: true,
|
|
128
|
+
agentId,
|
|
129
|
+
terminated: true,
|
|
130
|
+
terminatedAt: new Date().toISOString(),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
46
134
|
return {
|
|
47
|
-
success:
|
|
48
|
-
agentId
|
|
49
|
-
|
|
135
|
+
success: false,
|
|
136
|
+
agentId,
|
|
137
|
+
error: 'Agent not found',
|
|
50
138
|
};
|
|
51
139
|
},
|
|
52
140
|
},
|
|
@@ -62,11 +150,26 @@ export const agentTools: MCPTool[] = [
|
|
|
62
150
|
required: ['agentId'],
|
|
63
151
|
},
|
|
64
152
|
handler: async (input) => {
|
|
153
|
+
const store = loadAgentStore();
|
|
154
|
+
const agentId = input.agentId as string;
|
|
155
|
+
const agent = store.agents[agentId];
|
|
156
|
+
|
|
157
|
+
if (agent) {
|
|
158
|
+
return {
|
|
159
|
+
agentId: agent.agentId,
|
|
160
|
+
agentType: agent.agentType,
|
|
161
|
+
status: agent.status,
|
|
162
|
+
health: agent.health,
|
|
163
|
+
taskCount: agent.taskCount,
|
|
164
|
+
createdAt: agent.createdAt,
|
|
165
|
+
domain: agent.domain,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
65
169
|
return {
|
|
66
|
-
agentId
|
|
67
|
-
status: '
|
|
68
|
-
|
|
69
|
-
taskCount: 0,
|
|
170
|
+
agentId,
|
|
171
|
+
status: 'not_found',
|
|
172
|
+
error: 'Agent not found',
|
|
70
173
|
};
|
|
71
174
|
},
|
|
72
175
|
},
|
|
@@ -79,13 +182,284 @@ export const agentTools: MCPTool[] = [
|
|
|
79
182
|
properties: {
|
|
80
183
|
status: { type: 'string', description: 'Filter by status' },
|
|
81
184
|
domain: { type: 'string', description: 'Filter by domain' },
|
|
185
|
+
includeTerminated: { type: 'boolean', description: 'Include terminated agents' },
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
handler: async (input) => {
|
|
189
|
+
const store = loadAgentStore();
|
|
190
|
+
let agents = Object.values(store.agents);
|
|
191
|
+
|
|
192
|
+
// Filter by status
|
|
193
|
+
if (input.status) {
|
|
194
|
+
agents = agents.filter(a => a.status === input.status);
|
|
195
|
+
} else if (!input.includeTerminated) {
|
|
196
|
+
agents = agents.filter(a => a.status !== 'terminated');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Filter by domain
|
|
200
|
+
if (input.domain) {
|
|
201
|
+
agents = agents.filter(a => a.domain === input.domain);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
agents: agents.map(a => ({
|
|
206
|
+
agentId: a.agentId,
|
|
207
|
+
agentType: a.agentType,
|
|
208
|
+
status: a.status,
|
|
209
|
+
health: a.health,
|
|
210
|
+
taskCount: a.taskCount,
|
|
211
|
+
createdAt: a.createdAt,
|
|
212
|
+
domain: a.domain,
|
|
213
|
+
})),
|
|
214
|
+
total: agents.length,
|
|
215
|
+
filters: {
|
|
216
|
+
status: input.status,
|
|
217
|
+
domain: input.domain,
|
|
218
|
+
includeTerminated: input.includeTerminated,
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: 'agent/pool',
|
|
225
|
+
description: 'Manage agent pool',
|
|
226
|
+
category: 'agent',
|
|
227
|
+
inputSchema: {
|
|
228
|
+
type: 'object',
|
|
229
|
+
properties: {
|
|
230
|
+
action: { type: 'string', enum: ['status', 'scale', 'drain', 'fill'], description: 'Pool action' },
|
|
231
|
+
targetSize: { type: 'number', description: 'Target pool size (for scale action)' },
|
|
232
|
+
agentType: { type: 'string', description: 'Agent type filter' },
|
|
82
233
|
},
|
|
234
|
+
required: ['action'],
|
|
83
235
|
},
|
|
84
236
|
handler: async (input) => {
|
|
237
|
+
const store = loadAgentStore();
|
|
238
|
+
const agents = Object.values(store.agents).filter(a => a.status !== 'terminated');
|
|
239
|
+
const action = (input.action as string) || 'status'; // Default to status
|
|
240
|
+
|
|
241
|
+
if (action === 'status') {
|
|
242
|
+
const byType: Record<string, number> = {};
|
|
243
|
+
const byStatus: Record<string, number> = {};
|
|
244
|
+
for (const agent of agents) {
|
|
245
|
+
byType[agent.agentType] = (byType[agent.agentType] || 0) + 1;
|
|
246
|
+
byStatus[agent.status] = (byStatus[agent.status] || 0) + 1;
|
|
247
|
+
}
|
|
248
|
+
const idleAgents = agents.filter(a => a.status === 'idle').length;
|
|
249
|
+
const busyAgents = agents.filter(a => a.status === 'busy').length;
|
|
250
|
+
const utilization = agents.length > 0 ? busyAgents / agents.length : 0;
|
|
251
|
+
return {
|
|
252
|
+
action,
|
|
253
|
+
// CLI expected fields
|
|
254
|
+
poolId: 'agent-pool-default',
|
|
255
|
+
currentSize: agents.length,
|
|
256
|
+
minSize: (input.min as number) || 0,
|
|
257
|
+
maxSize: (input.max as number) || 100,
|
|
258
|
+
autoScale: (input.autoScale as boolean) ?? false,
|
|
259
|
+
utilization,
|
|
260
|
+
agents: agents.map(a => ({
|
|
261
|
+
id: a.agentId,
|
|
262
|
+
type: a.agentType,
|
|
263
|
+
status: a.status,
|
|
264
|
+
})),
|
|
265
|
+
// Additional fields
|
|
266
|
+
id: 'agent-pool-default',
|
|
267
|
+
size: agents.length,
|
|
268
|
+
totalAgents: agents.length,
|
|
269
|
+
byType,
|
|
270
|
+
byStatus,
|
|
271
|
+
avgHealth: agents.length > 0 ? agents.reduce((sum, a) => sum + a.health, 0) / agents.length : 0,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (action === 'scale') {
|
|
276
|
+
const targetSize = (input.targetSize as number) || 5;
|
|
277
|
+
const agentType = (input.agentType as string) || 'worker';
|
|
278
|
+
const currentSize = agents.filter(a => a.agentType === agentType).length;
|
|
279
|
+
const delta = targetSize - currentSize;
|
|
280
|
+
const added: string[] = [];
|
|
281
|
+
const removed: string[] = [];
|
|
282
|
+
|
|
283
|
+
if (delta > 0) {
|
|
284
|
+
for (let i = 0; i < delta; i++) {
|
|
285
|
+
const agentId = `agent-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
286
|
+
store.agents[agentId] = {
|
|
287
|
+
agentId,
|
|
288
|
+
agentType,
|
|
289
|
+
status: 'idle',
|
|
290
|
+
health: 1.0,
|
|
291
|
+
taskCount: 0,
|
|
292
|
+
config: {},
|
|
293
|
+
createdAt: new Date().toISOString(),
|
|
294
|
+
};
|
|
295
|
+
added.push(agentId);
|
|
296
|
+
}
|
|
297
|
+
} else if (delta < 0) {
|
|
298
|
+
const toRemove = agents.filter(a => a.agentType === agentType && a.status === 'idle').slice(0, -delta);
|
|
299
|
+
for (const agent of toRemove) {
|
|
300
|
+
store.agents[agent.agentId].status = 'terminated';
|
|
301
|
+
removed.push(agent.agentId);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
saveAgentStore(store);
|
|
306
|
+
return {
|
|
307
|
+
action,
|
|
308
|
+
agentType,
|
|
309
|
+
previousSize: currentSize,
|
|
310
|
+
targetSize,
|
|
311
|
+
newSize: currentSize + delta,
|
|
312
|
+
added,
|
|
313
|
+
removed,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (action === 'drain') {
|
|
318
|
+
const agentType = input.agentType as string;
|
|
319
|
+
let drained = 0;
|
|
320
|
+
for (const agent of agents) {
|
|
321
|
+
if (!agentType || agent.agentType === agentType) {
|
|
322
|
+
if (agent.status === 'idle') {
|
|
323
|
+
store.agents[agent.agentId].status = 'terminated';
|
|
324
|
+
drained++;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
saveAgentStore(store);
|
|
329
|
+
return {
|
|
330
|
+
action,
|
|
331
|
+
agentType: agentType || 'all',
|
|
332
|
+
drained,
|
|
333
|
+
remaining: agents.length - drained,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return { action, error: 'Unknown action' };
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
name: 'agent/health',
|
|
342
|
+
description: 'Check agent health',
|
|
343
|
+
category: 'agent',
|
|
344
|
+
inputSchema: {
|
|
345
|
+
type: 'object',
|
|
346
|
+
properties: {
|
|
347
|
+
agentId: { type: 'string', description: 'Specific agent ID (optional)' },
|
|
348
|
+
threshold: { type: 'number', description: 'Health threshold (0-1)' },
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
handler: async (input) => {
|
|
352
|
+
const store = loadAgentStore();
|
|
353
|
+
const agents = Object.values(store.agents).filter(a => a.status !== 'terminated');
|
|
354
|
+
const threshold = (input.threshold as number) || 0.5;
|
|
355
|
+
|
|
356
|
+
if (input.agentId) {
|
|
357
|
+
const agent = store.agents[input.agentId as string];
|
|
358
|
+
if (agent) {
|
|
359
|
+
return {
|
|
360
|
+
agentId: agent.agentId,
|
|
361
|
+
health: agent.health,
|
|
362
|
+
status: agent.status,
|
|
363
|
+
healthy: agent.health >= threshold,
|
|
364
|
+
taskCount: agent.taskCount,
|
|
365
|
+
uptime: Date.now() - new Date(agent.createdAt).getTime(),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return { agentId: input.agentId, error: 'Agent not found' };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const healthyAgents = agents.filter(a => a.health >= threshold);
|
|
372
|
+
const degradedAgents = agents.filter(a => a.health >= 0.3 && a.health < threshold);
|
|
373
|
+
const unhealthyAgents = agents.filter(a => a.health < 0.3);
|
|
374
|
+
const avgHealth = agents.length > 0 ? agents.reduce((sum, a) => sum + a.health, 0) / agents.length : 1;
|
|
375
|
+
const avgCpu = agents.length > 0 ? 35 + Math.random() * 30 : 0; // Simulated CPU
|
|
376
|
+
const avgMemory = avgHealth * 0.6; // Correlated with health
|
|
377
|
+
|
|
378
|
+
return {
|
|
379
|
+
// CLI expected fields
|
|
380
|
+
agents: agents.map(a => {
|
|
381
|
+
const uptime = Date.now() - new Date(a.createdAt).getTime();
|
|
382
|
+
return {
|
|
383
|
+
id: a.agentId,
|
|
384
|
+
type: a.agentType,
|
|
385
|
+
health: a.health >= threshold ? 'healthy' : (a.health >= 0.3 ? 'degraded' : 'unhealthy'),
|
|
386
|
+
uptime,
|
|
387
|
+
memory: { used: Math.floor(256 * (1 - a.health * 0.3)), limit: 512 },
|
|
388
|
+
cpu: 20 + Math.floor(a.health * 40),
|
|
389
|
+
tasks: { active: a.taskCount > 0 ? 1 : 0, queued: 0, completed: a.taskCount, failed: 0 },
|
|
390
|
+
latency: { avg: 50 + Math.floor((1 - a.health) * 100), p99: 150 + Math.floor((1 - a.health) * 200) },
|
|
391
|
+
errors: { count: a.health < threshold ? 1 : 0 },
|
|
392
|
+
};
|
|
393
|
+
}),
|
|
394
|
+
overall: {
|
|
395
|
+
healthy: healthyAgents.length,
|
|
396
|
+
degraded: degradedAgents.length,
|
|
397
|
+
unhealthy: unhealthyAgents.length,
|
|
398
|
+
avgCpu,
|
|
399
|
+
avgMemory,
|
|
400
|
+
score: Math.round(avgHealth * 100),
|
|
401
|
+
issues: unhealthyAgents.length,
|
|
402
|
+
},
|
|
403
|
+
// Additional fields
|
|
404
|
+
total: agents.length,
|
|
405
|
+
healthyCount: healthyAgents.length,
|
|
406
|
+
unhealthyCount: unhealthyAgents.length,
|
|
407
|
+
threshold,
|
|
408
|
+
avgHealth,
|
|
409
|
+
unhealthyAgents: unhealthyAgents.map(a => ({
|
|
410
|
+
agentId: a.agentId,
|
|
411
|
+
health: a.health,
|
|
412
|
+
status: a.status,
|
|
413
|
+
})),
|
|
414
|
+
};
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
name: 'agent/update',
|
|
419
|
+
description: 'Update agent status or config',
|
|
420
|
+
category: 'agent',
|
|
421
|
+
inputSchema: {
|
|
422
|
+
type: 'object',
|
|
423
|
+
properties: {
|
|
424
|
+
agentId: { type: 'string', description: 'ID of agent' },
|
|
425
|
+
status: { type: 'string', description: 'New status' },
|
|
426
|
+
health: { type: 'number', description: 'Health value (0-1)' },
|
|
427
|
+
taskCount: { type: 'number', description: 'Task count' },
|
|
428
|
+
config: { type: 'object', description: 'Config updates' },
|
|
429
|
+
},
|
|
430
|
+
required: ['agentId'],
|
|
431
|
+
},
|
|
432
|
+
handler: async (input) => {
|
|
433
|
+
const store = loadAgentStore();
|
|
434
|
+
const agentId = input.agentId as string;
|
|
435
|
+
const agent = store.agents[agentId];
|
|
436
|
+
|
|
437
|
+
if (agent) {
|
|
438
|
+
if (input.status) agent.status = input.status as AgentRecord['status'];
|
|
439
|
+
if (typeof input.health === 'number') agent.health = input.health as number;
|
|
440
|
+
if (typeof input.taskCount === 'number') agent.taskCount = input.taskCount as number;
|
|
441
|
+
if (input.config) {
|
|
442
|
+
agent.config = { ...agent.config, ...(input.config as Record<string, unknown>) };
|
|
443
|
+
}
|
|
444
|
+
saveAgentStore(store);
|
|
445
|
+
|
|
446
|
+
return {
|
|
447
|
+
success: true,
|
|
448
|
+
agentId,
|
|
449
|
+
updated: true,
|
|
450
|
+
agent: {
|
|
451
|
+
agentId: agent.agentId,
|
|
452
|
+
status: agent.status,
|
|
453
|
+
health: agent.health,
|
|
454
|
+
taskCount: agent.taskCount,
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
85
459
|
return {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
460
|
+
success: false,
|
|
461
|
+
agentId,
|
|
462
|
+
error: 'Agent not found',
|
|
89
463
|
};
|
|
90
464
|
},
|
|
91
465
|
},
|