claude-flow 1.0.0
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/LICENSE +21 -0
- package/README.md +612 -0
- package/bin/claude-flow +0 -0
- package/bin/claude-flow-simple +0 -0
- package/bin/claude-flow-typecheck +0 -0
- package/deno.json +84 -0
- package/package.json +45 -0
- package/scripts/check-links.ts +274 -0
- package/scripts/check-performance-regression.ts +168 -0
- package/scripts/claude-sparc.sh +562 -0
- package/scripts/coverage-report.ts +692 -0
- package/scripts/demo-task-system.ts +224 -0
- package/scripts/install.js +72 -0
- package/scripts/test-batch-tasks.ts +29 -0
- package/scripts/test-coordination-features.ts +238 -0
- package/scripts/test-mcp.ts +251 -0
- package/scripts/test-runner.ts +571 -0
- package/scripts/validate-examples.ts +288 -0
- package/src/cli/cli-core.ts +273 -0
- package/src/cli/commands/agent.ts +83 -0
- package/src/cli/commands/config.ts +442 -0
- package/src/cli/commands/help.ts +765 -0
- package/src/cli/commands/index.ts +963 -0
- package/src/cli/commands/mcp.ts +191 -0
- package/src/cli/commands/memory.ts +74 -0
- package/src/cli/commands/monitor.ts +403 -0
- package/src/cli/commands/session.ts +595 -0
- package/src/cli/commands/start.ts +156 -0
- package/src/cli/commands/status.ts +345 -0
- package/src/cli/commands/task.ts +79 -0
- package/src/cli/commands/workflow.ts +763 -0
- package/src/cli/completion.ts +553 -0
- package/src/cli/formatter.ts +310 -0
- package/src/cli/index.ts +211 -0
- package/src/cli/main.ts +23 -0
- package/src/cli/repl.ts +1050 -0
- package/src/cli/simple-cli.js +211 -0
- package/src/cli/simple-cli.ts +211 -0
- package/src/coordination/README.md +400 -0
- package/src/coordination/advanced-scheduler.ts +487 -0
- package/src/coordination/circuit-breaker.ts +366 -0
- package/src/coordination/conflict-resolution.ts +490 -0
- package/src/coordination/dependency-graph.ts +475 -0
- package/src/coordination/index.ts +63 -0
- package/src/coordination/manager.ts +460 -0
- package/src/coordination/messaging.ts +290 -0
- package/src/coordination/metrics.ts +585 -0
- package/src/coordination/resources.ts +322 -0
- package/src/coordination/scheduler.ts +390 -0
- package/src/coordination/work-stealing.ts +224 -0
- package/src/core/config.ts +627 -0
- package/src/core/event-bus.ts +186 -0
- package/src/core/json-persistence.ts +183 -0
- package/src/core/logger.ts +262 -0
- package/src/core/orchestrator-fixed.ts +312 -0
- package/src/core/orchestrator.ts +1234 -0
- package/src/core/persistence.ts +276 -0
- package/src/mcp/auth.ts +438 -0
- package/src/mcp/claude-flow-tools.ts +1280 -0
- package/src/mcp/load-balancer.ts +510 -0
- package/src/mcp/router.ts +240 -0
- package/src/mcp/server.ts +548 -0
- package/src/mcp/session-manager.ts +418 -0
- package/src/mcp/tools.ts +180 -0
- package/src/mcp/transports/base.ts +21 -0
- package/src/mcp/transports/http.ts +457 -0
- package/src/mcp/transports/stdio.ts +254 -0
- package/src/memory/backends/base.ts +22 -0
- package/src/memory/backends/markdown.ts +283 -0
- package/src/memory/backends/sqlite.ts +329 -0
- package/src/memory/cache.ts +238 -0
- package/src/memory/indexer.ts +238 -0
- package/src/memory/manager.ts +572 -0
- package/src/terminal/adapters/base.ts +29 -0
- package/src/terminal/adapters/native.ts +504 -0
- package/src/terminal/adapters/vscode.ts +340 -0
- package/src/terminal/manager.ts +308 -0
- package/src/terminal/pool.ts +271 -0
- package/src/terminal/session.ts +250 -0
- package/src/terminal/vscode-bridge.ts +242 -0
- package/src/utils/errors.ts +231 -0
- package/src/utils/helpers.ts +476 -0
- package/src/utils/types.ts +493 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inter-agent messaging system
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Message, CoordinationConfig, SystemEvents } from '../utils/types.ts';
|
|
6
|
+
import { IEventBus } from '../core/event-bus.ts';
|
|
7
|
+
import { ILogger } from '../core/logger.ts';
|
|
8
|
+
import { CoordinationError } from '../utils/errors.ts';
|
|
9
|
+
import { generateId, timeout as timeoutHelper } from '../utils/helpers.ts';
|
|
10
|
+
|
|
11
|
+
interface MessageQueue {
|
|
12
|
+
messages: Message[];
|
|
13
|
+
handlers: Map<string, (message: Message) => void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface PendingResponse {
|
|
17
|
+
resolve: (response: unknown) => void;
|
|
18
|
+
reject: (error: Error) => void;
|
|
19
|
+
timeout: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Message router for inter-agent communication
|
|
24
|
+
*/
|
|
25
|
+
export class MessageRouter {
|
|
26
|
+
private queues = new Map<string, MessageQueue>(); // agentId -> queue
|
|
27
|
+
private pendingResponses = new Map<string, PendingResponse>();
|
|
28
|
+
private messageCount = 0;
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
private config: CoordinationConfig,
|
|
32
|
+
private eventBus: IEventBus,
|
|
33
|
+
private logger: ILogger,
|
|
34
|
+
) {}
|
|
35
|
+
|
|
36
|
+
async initialize(): Promise<void> {
|
|
37
|
+
this.logger.info('Initializing message router');
|
|
38
|
+
|
|
39
|
+
// Set up periodic cleanup
|
|
40
|
+
setInterval(() => this.cleanup(), 60000); // Every minute
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async shutdown(): Promise<void> {
|
|
44
|
+
this.logger.info('Shutting down message router');
|
|
45
|
+
|
|
46
|
+
// Reject all pending responses
|
|
47
|
+
for (const [id, pending] of this.pendingResponses) {
|
|
48
|
+
pending.reject(new Error('Message router shutdown'));
|
|
49
|
+
clearTimeout(pending.timeout);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.queues.clear();
|
|
53
|
+
this.pendingResponses.clear();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async send(from: string, to: string, payload: unknown): Promise<void> {
|
|
57
|
+
const message: Message = {
|
|
58
|
+
id: generateId('msg'),
|
|
59
|
+
type: 'agent-message',
|
|
60
|
+
payload,
|
|
61
|
+
timestamp: new Date(),
|
|
62
|
+
priority: 0,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
await this.sendMessage(from, to, message);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async sendWithResponse<T = unknown>(
|
|
69
|
+
from: string,
|
|
70
|
+
to: string,
|
|
71
|
+
payload: unknown,
|
|
72
|
+
timeoutMs?: number,
|
|
73
|
+
): Promise<T> {
|
|
74
|
+
const message: Message = {
|
|
75
|
+
id: generateId('msg'),
|
|
76
|
+
type: 'agent-request',
|
|
77
|
+
payload,
|
|
78
|
+
timestamp: new Date(),
|
|
79
|
+
priority: 1,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Create response promise
|
|
83
|
+
const responsePromise = new Promise<T>((resolve, reject) => {
|
|
84
|
+
const timeout = setTimeout(() => {
|
|
85
|
+
this.pendingResponses.delete(message.id);
|
|
86
|
+
reject(new Error(`Message response timeout: ${message.id}`));
|
|
87
|
+
}, timeoutMs || this.config.messageTimeout);
|
|
88
|
+
|
|
89
|
+
this.pendingResponses.set(message.id, {
|
|
90
|
+
resolve: resolve as (response: unknown) => void,
|
|
91
|
+
reject,
|
|
92
|
+
timeout: timeout as unknown as number,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Send message
|
|
97
|
+
await this.sendMessage(from, to, message);
|
|
98
|
+
|
|
99
|
+
// Wait for response
|
|
100
|
+
return await responsePromise;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async broadcast(from: string, payload: unknown): Promise<void> {
|
|
104
|
+
const message: Message = {
|
|
105
|
+
id: generateId('broadcast'),
|
|
106
|
+
type: 'broadcast',
|
|
107
|
+
payload,
|
|
108
|
+
timestamp: new Date(),
|
|
109
|
+
priority: 0,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Send to all agents
|
|
113
|
+
const agents = Array.from(this.queues.keys()).filter(id => id !== from);
|
|
114
|
+
|
|
115
|
+
await Promise.all(
|
|
116
|
+
agents.map(to => this.sendMessage(from, to, message)),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
subscribe(agentId: string, handler: (message: Message) => void): void {
|
|
121
|
+
const queue = this.ensureQueue(agentId);
|
|
122
|
+
queue.handlers.set(generateId('handler'), handler);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
unsubscribe(agentId: string, handlerId: string): void {
|
|
126
|
+
const queue = this.queues.get(agentId);
|
|
127
|
+
if (queue) {
|
|
128
|
+
queue.handlers.delete(handlerId);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async sendResponse(
|
|
133
|
+
originalMessageId: string,
|
|
134
|
+
response: unknown,
|
|
135
|
+
): Promise<void> {
|
|
136
|
+
const pending = this.pendingResponses.get(originalMessageId);
|
|
137
|
+
if (!pending) {
|
|
138
|
+
this.logger.warn('No pending response found', { messageId: originalMessageId });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
clearTimeout(pending.timeout);
|
|
143
|
+
this.pendingResponses.delete(originalMessageId);
|
|
144
|
+
pending.resolve(response);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async getHealthStatus(): Promise<{
|
|
148
|
+
healthy: boolean;
|
|
149
|
+
error?: string;
|
|
150
|
+
metrics?: Record<string, number>;
|
|
151
|
+
}> {
|
|
152
|
+
const totalQueues = this.queues.size;
|
|
153
|
+
let totalMessages = 0;
|
|
154
|
+
let totalHandlers = 0;
|
|
155
|
+
|
|
156
|
+
for (const queue of this.queues.values()) {
|
|
157
|
+
totalMessages += queue.messages.length;
|
|
158
|
+
totalHandlers += queue.handlers.size;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
healthy: true,
|
|
163
|
+
metrics: {
|
|
164
|
+
activeQueues: totalQueues,
|
|
165
|
+
pendingMessages: totalMessages,
|
|
166
|
+
registeredHandlers: totalHandlers,
|
|
167
|
+
pendingResponses: this.pendingResponses.size,
|
|
168
|
+
totalMessagesSent: this.messageCount,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private async sendMessage(
|
|
174
|
+
from: string,
|
|
175
|
+
to: string,
|
|
176
|
+
message: Message,
|
|
177
|
+
): Promise<void> {
|
|
178
|
+
this.logger.debug('Sending message', {
|
|
179
|
+
from,
|
|
180
|
+
to,
|
|
181
|
+
messageId: message.id,
|
|
182
|
+
type: message.type,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Ensure destination queue exists
|
|
186
|
+
const queue = this.ensureQueue(to);
|
|
187
|
+
|
|
188
|
+
// Add to queue
|
|
189
|
+
queue.messages.push(message);
|
|
190
|
+
this.messageCount++;
|
|
191
|
+
|
|
192
|
+
// Emit event
|
|
193
|
+
this.eventBus.emit(SystemEvents.MESSAGE_SENT, { from, to, message });
|
|
194
|
+
|
|
195
|
+
// Process message immediately if handlers exist
|
|
196
|
+
if (queue.handlers.size > 0) {
|
|
197
|
+
await this.processMessage(to, message);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private async processMessage(agentId: string, message: Message): Promise<void> {
|
|
202
|
+
const queue = this.queues.get(agentId);
|
|
203
|
+
if (!queue) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Remove message from queue
|
|
208
|
+
const index = queue.messages.indexOf(message);
|
|
209
|
+
if (index !== -1) {
|
|
210
|
+
queue.messages.splice(index, 1);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Call all handlers
|
|
214
|
+
const handlers = Array.from(queue.handlers.values());
|
|
215
|
+
await Promise.all(
|
|
216
|
+
handlers.map(handler => {
|
|
217
|
+
try {
|
|
218
|
+
handler(message);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
this.logger.error('Message handler error', {
|
|
221
|
+
agentId,
|
|
222
|
+
messageId: message.id,
|
|
223
|
+
error,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// Emit received event
|
|
230
|
+
this.eventBus.emit(SystemEvents.MESSAGE_RECEIVED, {
|
|
231
|
+
from: '', // Would need to track this
|
|
232
|
+
to: agentId,
|
|
233
|
+
message,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private ensureQueue(agentId: string): MessageQueue {
|
|
238
|
+
if (!this.queues.has(agentId)) {
|
|
239
|
+
this.queues.set(agentId, {
|
|
240
|
+
messages: [],
|
|
241
|
+
handlers: new Map(),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
return this.queues.get(agentId)!;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async performMaintenance(): Promise<void> {
|
|
248
|
+
this.logger.debug('Performing message router maintenance');
|
|
249
|
+
this.cleanup();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private cleanup(): void {
|
|
253
|
+
const now = Date.now();
|
|
254
|
+
|
|
255
|
+
// Clean up old messages
|
|
256
|
+
for (const [agentId, queue] of this.queues) {
|
|
257
|
+
const filtered = queue.messages.filter(msg => {
|
|
258
|
+
const age = now - msg.timestamp.getTime();
|
|
259
|
+
const maxAge = msg.expiry
|
|
260
|
+
? msg.expiry.getTime() - msg.timestamp.getTime()
|
|
261
|
+
: this.config.messageTimeout;
|
|
262
|
+
|
|
263
|
+
if (age > maxAge) {
|
|
264
|
+
this.logger.warn('Dropping expired message', {
|
|
265
|
+
agentId,
|
|
266
|
+
messageId: msg.id,
|
|
267
|
+
age,
|
|
268
|
+
});
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
queue.messages = filtered;
|
|
275
|
+
|
|
276
|
+
// Remove empty queues
|
|
277
|
+
if (queue.messages.length === 0 && queue.handlers.size === 0) {
|
|
278
|
+
this.queues.delete(agentId);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Clean up timed out responses
|
|
283
|
+
for (const [id, pending] of this.pendingResponses) {
|
|
284
|
+
// This is handled by the timeout, but double-check
|
|
285
|
+
clearTimeout(pending.timeout);
|
|
286
|
+
pending.reject(new Error('Response timeout during cleanup'));
|
|
287
|
+
}
|
|
288
|
+
this.pendingResponses.clear();
|
|
289
|
+
}
|
|
290
|
+
}
|