@claude-flow/swarm 3.0.0-alpha.1

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.
Files changed (190) hide show
  1. package/.agentic-flow/intelligence.json +16 -0
  2. package/MIGRATION.md +472 -0
  3. package/README.md +634 -0
  4. package/__tests__/consensus.test.ts +577 -0
  5. package/__tests__/coordinator.test.ts +501 -0
  6. package/__tests__/queen-coordinator.test.ts +1335 -0
  7. package/__tests__/topology.test.ts +621 -0
  8. package/dist/agent-pool.d.ts +52 -0
  9. package/dist/agent-pool.d.ts.map +1 -0
  10. package/dist/agent-pool.js +365 -0
  11. package/dist/agent-pool.js.map +1 -0
  12. package/dist/application/commands/create-task.command.d.ts +64 -0
  13. package/dist/application/commands/create-task.command.d.ts.map +1 -0
  14. package/dist/application/commands/create-task.command.js +77 -0
  15. package/dist/application/commands/create-task.command.js.map +1 -0
  16. package/dist/application/commands/spawn-agent.command.d.ts +63 -0
  17. package/dist/application/commands/spawn-agent.command.d.ts.map +1 -0
  18. package/dist/application/commands/spawn-agent.command.js +74 -0
  19. package/dist/application/commands/spawn-agent.command.js.map +1 -0
  20. package/dist/application/index.d.ts +9 -0
  21. package/dist/application/index.d.ts.map +1 -0
  22. package/dist/application/index.js +11 -0
  23. package/dist/application/index.js.map +1 -0
  24. package/dist/application/services/swarm-application-service.d.ts +112 -0
  25. package/dist/application/services/swarm-application-service.d.ts.map +1 -0
  26. package/dist/application/services/swarm-application-service.js +153 -0
  27. package/dist/application/services/swarm-application-service.js.map +1 -0
  28. package/dist/attention-coordinator.d.ts +212 -0
  29. package/dist/attention-coordinator.d.ts.map +1 -0
  30. package/dist/attention-coordinator.js +667 -0
  31. package/dist/attention-coordinator.js.map +1 -0
  32. package/dist/consensus/byzantine.d.ts +63 -0
  33. package/dist/consensus/byzantine.d.ts.map +1 -0
  34. package/dist/consensus/byzantine.js +316 -0
  35. package/dist/consensus/byzantine.js.map +1 -0
  36. package/dist/consensus/gossip.d.ts +69 -0
  37. package/dist/consensus/gossip.d.ts.map +1 -0
  38. package/dist/consensus/gossip.js +378 -0
  39. package/dist/consensus/gossip.js.map +1 -0
  40. package/dist/consensus/index.d.ts +49 -0
  41. package/dist/consensus/index.d.ts.map +1 -0
  42. package/dist/consensus/index.js +203 -0
  43. package/dist/consensus/index.js.map +1 -0
  44. package/dist/consensus/raft.d.ts +62 -0
  45. package/dist/consensus/raft.d.ts.map +1 -0
  46. package/dist/consensus/raft.js +324 -0
  47. package/dist/consensus/raft.js.map +1 -0
  48. package/dist/coordination/agent-registry.d.ts +68 -0
  49. package/dist/coordination/agent-registry.d.ts.map +1 -0
  50. package/dist/coordination/agent-registry.js +412 -0
  51. package/dist/coordination/agent-registry.js.map +1 -0
  52. package/dist/coordination/index.d.ts +8 -0
  53. package/dist/coordination/index.d.ts.map +1 -0
  54. package/dist/coordination/index.js +8 -0
  55. package/dist/coordination/index.js.map +1 -0
  56. package/dist/coordination/swarm-hub.d.ts +150 -0
  57. package/dist/coordination/swarm-hub.d.ts.map +1 -0
  58. package/dist/coordination/swarm-hub.js +617 -0
  59. package/dist/coordination/swarm-hub.js.map +1 -0
  60. package/dist/coordination/task-orchestrator.d.ts +96 -0
  61. package/dist/coordination/task-orchestrator.d.ts.map +1 -0
  62. package/dist/coordination/task-orchestrator.js +412 -0
  63. package/dist/coordination/task-orchestrator.js.map +1 -0
  64. package/dist/domain/entities/agent.d.ts +151 -0
  65. package/dist/domain/entities/agent.d.ts.map +1 -0
  66. package/dist/domain/entities/agent.js +280 -0
  67. package/dist/domain/entities/agent.js.map +1 -0
  68. package/dist/domain/entities/task.d.ts +133 -0
  69. package/dist/domain/entities/task.d.ts.map +1 -0
  70. package/dist/domain/entities/task.js +261 -0
  71. package/dist/domain/entities/task.js.map +1 -0
  72. package/dist/domain/index.d.ts +11 -0
  73. package/dist/domain/index.d.ts.map +1 -0
  74. package/dist/domain/index.js +11 -0
  75. package/dist/domain/index.js.map +1 -0
  76. package/dist/domain/repositories/agent-repository.interface.d.ts +57 -0
  77. package/dist/domain/repositories/agent-repository.interface.d.ts.map +1 -0
  78. package/dist/domain/repositories/agent-repository.interface.js +9 -0
  79. package/dist/domain/repositories/agent-repository.interface.js.map +1 -0
  80. package/dist/domain/repositories/task-repository.interface.d.ts +61 -0
  81. package/dist/domain/repositories/task-repository.interface.d.ts.map +1 -0
  82. package/dist/domain/repositories/task-repository.interface.js +9 -0
  83. package/dist/domain/repositories/task-repository.interface.js.map +1 -0
  84. package/dist/domain/services/coordination-service.d.ts +84 -0
  85. package/dist/domain/services/coordination-service.d.ts.map +1 -0
  86. package/dist/domain/services/coordination-service.js +231 -0
  87. package/dist/domain/services/coordination-service.js.map +1 -0
  88. package/dist/federation-hub.d.ts +284 -0
  89. package/dist/federation-hub.d.ts.map +1 -0
  90. package/dist/federation-hub.js +692 -0
  91. package/dist/federation-hub.js.map +1 -0
  92. package/dist/index.d.ts +107 -0
  93. package/dist/index.d.ts.map +1 -0
  94. package/dist/index.js +142 -0
  95. package/dist/index.js.map +1 -0
  96. package/dist/message-bus.d.ts +48 -0
  97. package/dist/message-bus.d.ts.map +1 -0
  98. package/dist/message-bus.js +499 -0
  99. package/dist/message-bus.js.map +1 -0
  100. package/dist/queen-coordinator.d.ts +576 -0
  101. package/dist/queen-coordinator.d.ts.map +1 -0
  102. package/dist/queen-coordinator.js +1307 -0
  103. package/dist/queen-coordinator.js.map +1 -0
  104. package/dist/shared/events.d.ts +63 -0
  105. package/dist/shared/events.d.ts.map +1 -0
  106. package/dist/shared/events.js +203 -0
  107. package/dist/shared/events.js.map +1 -0
  108. package/dist/shared/types.d.ts +212 -0
  109. package/dist/shared/types.d.ts.map +1 -0
  110. package/dist/shared/types.js +22 -0
  111. package/dist/shared/types.js.map +1 -0
  112. package/dist/topology-manager.d.ts +62 -0
  113. package/dist/topology-manager.d.ts.map +1 -0
  114. package/dist/topology-manager.js +538 -0
  115. package/dist/topology-manager.js.map +1 -0
  116. package/dist/types.d.ts +353 -0
  117. package/dist/types.d.ts.map +1 -0
  118. package/dist/types.js +43 -0
  119. package/dist/types.js.map +1 -0
  120. package/dist/unified-coordinator.d.ts +260 -0
  121. package/dist/unified-coordinator.d.ts.map +1 -0
  122. package/dist/unified-coordinator.js +1460 -0
  123. package/dist/unified-coordinator.js.map +1 -0
  124. package/dist/workers/index.d.ts +29 -0
  125. package/dist/workers/index.d.ts.map +1 -0
  126. package/dist/workers/index.js +49 -0
  127. package/dist/workers/index.js.map +1 -0
  128. package/dist/workers/worker-dispatch.d.ts +234 -0
  129. package/dist/workers/worker-dispatch.d.ts.map +1 -0
  130. package/dist/workers/worker-dispatch.js +842 -0
  131. package/dist/workers/worker-dispatch.js.map +1 -0
  132. package/package.json +33 -0
  133. package/src/agent-pool.ts +476 -0
  134. package/src/application/commands/create-task.command.ts +124 -0
  135. package/src/application/commands/spawn-agent.command.ts +122 -0
  136. package/src/application/index.ts +30 -0
  137. package/src/application/services/swarm-application-service.ts +200 -0
  138. package/src/attention-coordinator.ts +1000 -0
  139. package/src/consensus/byzantine.ts +431 -0
  140. package/src/consensus/gossip.ts +513 -0
  141. package/src/consensus/index.ts +267 -0
  142. package/src/consensus/raft.ts +443 -0
  143. package/src/coordination/agent-registry.ts +544 -0
  144. package/src/coordination/index.ts +23 -0
  145. package/src/coordination/swarm-hub.ts +776 -0
  146. package/src/coordination/task-orchestrator.ts +605 -0
  147. package/src/domain/entities/agent.d.ts +151 -0
  148. package/src/domain/entities/agent.d.ts.map +1 -0
  149. package/src/domain/entities/agent.js +280 -0
  150. package/src/domain/entities/agent.js.map +1 -0
  151. package/src/domain/entities/agent.ts +370 -0
  152. package/src/domain/entities/task.d.ts +133 -0
  153. package/src/domain/entities/task.d.ts.map +1 -0
  154. package/src/domain/entities/task.js +261 -0
  155. package/src/domain/entities/task.js.map +1 -0
  156. package/src/domain/entities/task.ts +319 -0
  157. package/src/domain/index.ts +41 -0
  158. package/src/domain/repositories/agent-repository.interface.d.ts +57 -0
  159. package/src/domain/repositories/agent-repository.interface.d.ts.map +1 -0
  160. package/src/domain/repositories/agent-repository.interface.js +9 -0
  161. package/src/domain/repositories/agent-repository.interface.js.map +1 -0
  162. package/src/domain/repositories/agent-repository.interface.ts +69 -0
  163. package/src/domain/repositories/task-repository.interface.d.ts +61 -0
  164. package/src/domain/repositories/task-repository.interface.d.ts.map +1 -0
  165. package/src/domain/repositories/task-repository.interface.js +9 -0
  166. package/src/domain/repositories/task-repository.interface.js.map +1 -0
  167. package/src/domain/repositories/task-repository.interface.ts +75 -0
  168. package/src/domain/services/coordination-service.ts +320 -0
  169. package/src/federation-hub.d.ts +284 -0
  170. package/src/federation-hub.d.ts.map +1 -0
  171. package/src/federation-hub.js +692 -0
  172. package/src/federation-hub.js.map +1 -0
  173. package/src/federation-hub.ts +979 -0
  174. package/src/index.ts +348 -0
  175. package/src/message-bus.ts +607 -0
  176. package/src/queen-coordinator.ts +2024 -0
  177. package/src/shared/events.ts +285 -0
  178. package/src/shared/types.ts +389 -0
  179. package/src/topology-manager.ts +656 -0
  180. package/src/types.ts +545 -0
  181. package/src/unified-coordinator.ts +1844 -0
  182. package/src/workers/index.ts +65 -0
  183. package/src/workers/worker-dispatch.d.ts +234 -0
  184. package/src/workers/worker-dispatch.d.ts.map +1 -0
  185. package/src/workers/worker-dispatch.js +842 -0
  186. package/src/workers/worker-dispatch.js.map +1 -0
  187. package/src/workers/worker-dispatch.ts +1072 -0
  188. package/tsconfig.json +9 -0
  189. package/tsconfig.tsbuildinfo +1 -0
  190. package/vitest.config.ts +20 -0
package/src/types.ts ADDED
@@ -0,0 +1,545 @@
1
+ /**
2
+ * V3 Unified Swarm Coordinator Types
3
+ * Consolidated type definitions for the unified swarm coordination system
4
+ */
5
+
6
+ import { EventEmitter } from 'events';
7
+
8
+ // ===== CORE IDENTIFIERS =====
9
+
10
+ export interface SwarmId {
11
+ id: string;
12
+ namespace: string;
13
+ version: string;
14
+ createdAt: Date;
15
+ }
16
+
17
+ export interface AgentId {
18
+ id: string;
19
+ swarmId: string;
20
+ type: AgentType;
21
+ instance: number;
22
+ }
23
+
24
+ export interface TaskId {
25
+ id: string;
26
+ swarmId: string;
27
+ sequence: number;
28
+ priority: TaskPriority;
29
+ }
30
+
31
+ // ===== TOPOLOGY TYPES =====
32
+
33
+ export type TopologyType = 'mesh' | 'hierarchical' | 'centralized' | 'hybrid';
34
+
35
+ export interface TopologyConfig {
36
+ type: TopologyType;
37
+ maxAgents: number;
38
+ replicationFactor?: number;
39
+ partitionStrategy?: 'hash' | 'range' | 'round-robin';
40
+ failoverEnabled?: boolean;
41
+ autoRebalance?: boolean;
42
+ }
43
+
44
+ export interface TopologyState {
45
+ type: TopologyType;
46
+ nodes: TopologyNode[];
47
+ edges: TopologyEdge[];
48
+ leader?: string;
49
+ partitions: TopologyPartition[];
50
+ }
51
+
52
+ export interface TopologyNode {
53
+ id: string;
54
+ agentId: string;
55
+ role: 'queen' | 'worker' | 'coordinator' | 'peer';
56
+ status: 'active' | 'inactive' | 'syncing' | 'failed';
57
+ connections: string[];
58
+ metadata: Record<string, unknown>;
59
+ }
60
+
61
+ export interface TopologyEdge {
62
+ from: string;
63
+ to: string;
64
+ weight: number;
65
+ bidirectional: boolean;
66
+ latencyMs?: number;
67
+ }
68
+
69
+ export interface TopologyPartition {
70
+ id: string;
71
+ nodes: string[];
72
+ leader: string;
73
+ replicaCount: number;
74
+ }
75
+
76
+ // ===== AGENT TYPES =====
77
+
78
+ export type AgentType =
79
+ | 'coordinator'
80
+ | 'researcher'
81
+ | 'coder'
82
+ | 'analyst'
83
+ | 'architect'
84
+ | 'tester'
85
+ | 'reviewer'
86
+ | 'optimizer'
87
+ | 'documenter'
88
+ | 'monitor'
89
+ | 'specialist'
90
+ | 'queen'
91
+ | 'worker';
92
+
93
+ export type AgentStatus =
94
+ | 'initializing'
95
+ | 'idle'
96
+ | 'busy'
97
+ | 'paused'
98
+ | 'error'
99
+ | 'offline'
100
+ | 'terminating'
101
+ | 'terminated';
102
+
103
+ export interface AgentCapabilities {
104
+ codeGeneration: boolean;
105
+ codeReview: boolean;
106
+ testing: boolean;
107
+ documentation: boolean;
108
+ research: boolean;
109
+ analysis: boolean;
110
+ coordination: boolean;
111
+ languages: string[];
112
+ frameworks: string[];
113
+ domains: string[];
114
+ tools: string[];
115
+ maxConcurrentTasks: number;
116
+ maxMemoryUsage: number;
117
+ maxExecutionTime: number;
118
+ reliability: number;
119
+ speed: number;
120
+ quality: number;
121
+ }
122
+
123
+ export interface AgentMetrics {
124
+ tasksCompleted: number;
125
+ tasksFailed: number;
126
+ averageExecutionTime: number;
127
+ successRate: number;
128
+ cpuUsage: number;
129
+ memoryUsage: number;
130
+ messagesProcessed: number;
131
+ lastActivity: Date;
132
+ responseTime: number;
133
+ health: number;
134
+ }
135
+
136
+ export interface AgentState {
137
+ id: AgentId;
138
+ name: string;
139
+ type: AgentType;
140
+ status: AgentStatus;
141
+ capabilities: AgentCapabilities;
142
+ metrics: AgentMetrics;
143
+ currentTask?: TaskId;
144
+ workload: number;
145
+ health: number;
146
+ lastHeartbeat: Date;
147
+ topologyRole?: TopologyNode['role'];
148
+ connections: string[];
149
+ }
150
+
151
+ // ===== TASK TYPES =====
152
+
153
+ export type TaskType =
154
+ | 'research'
155
+ | 'analysis'
156
+ | 'coding'
157
+ | 'testing'
158
+ | 'review'
159
+ | 'documentation'
160
+ | 'coordination'
161
+ | 'consensus'
162
+ | 'custom';
163
+
164
+ export type TaskStatus =
165
+ | 'created'
166
+ | 'queued'
167
+ | 'assigned'
168
+ | 'running'
169
+ | 'paused'
170
+ | 'completed'
171
+ | 'failed'
172
+ | 'cancelled'
173
+ | 'timeout';
174
+
175
+ export type TaskPriority = 'critical' | 'high' | 'normal' | 'low' | 'background';
176
+
177
+ export interface TaskDefinition {
178
+ id: TaskId;
179
+ type: TaskType;
180
+ name: string;
181
+ description: string;
182
+ priority: TaskPriority;
183
+ status: TaskStatus;
184
+ assignedTo?: AgentId;
185
+ dependencies: TaskId[];
186
+ input: unknown;
187
+ output?: unknown;
188
+ createdAt: Date;
189
+ startedAt?: Date;
190
+ completedAt?: Date;
191
+ timeoutMs: number;
192
+ retries: number;
193
+ maxRetries: number;
194
+ metadata: Record<string, unknown>;
195
+ }
196
+
197
+ // ===== CONSENSUS TYPES =====
198
+
199
+ export type ConsensusAlgorithm = 'raft' | 'byzantine' | 'gossip' | 'paxos';
200
+
201
+ export interface ConsensusConfig {
202
+ algorithm: ConsensusAlgorithm;
203
+ threshold: number;
204
+ timeoutMs: number;
205
+ maxRounds: number;
206
+ requireQuorum: boolean;
207
+ }
208
+
209
+ export interface ConsensusProposal {
210
+ id: string;
211
+ proposerId: string;
212
+ value: unknown;
213
+ term: number;
214
+ timestamp: Date;
215
+ votes: Map<string, ConsensusVote>;
216
+ status: 'pending' | 'accepted' | 'rejected' | 'expired';
217
+ }
218
+
219
+ export interface ConsensusVote {
220
+ voterId: string;
221
+ approve: boolean;
222
+ confidence: number;
223
+ timestamp: Date;
224
+ reason?: string;
225
+ }
226
+
227
+ export interface ConsensusResult {
228
+ proposalId: string;
229
+ approved: boolean;
230
+ approvalRate: number;
231
+ participationRate: number;
232
+ finalValue: unknown;
233
+ rounds: number;
234
+ durationMs: number;
235
+ }
236
+
237
+ // ===== MESSAGE BUS TYPES =====
238
+
239
+ export type MessageType =
240
+ | 'task_assign'
241
+ | 'task_complete'
242
+ | 'task_fail'
243
+ | 'heartbeat'
244
+ | 'status_update'
245
+ | 'consensus_propose'
246
+ | 'consensus_vote'
247
+ | 'consensus_commit'
248
+ | 'topology_update'
249
+ | 'agent_join'
250
+ | 'agent_leave'
251
+ | 'broadcast'
252
+ | 'direct';
253
+
254
+ export interface Message {
255
+ id: string;
256
+ type: MessageType;
257
+ from: string;
258
+ to: string | 'broadcast';
259
+ payload: unknown;
260
+ timestamp: Date;
261
+ priority: 'urgent' | 'high' | 'normal' | 'low';
262
+ requiresAck: boolean;
263
+ ttlMs: number;
264
+ correlationId?: string;
265
+ }
266
+
267
+ export interface MessageAck {
268
+ messageId: string;
269
+ from: string;
270
+ received: boolean;
271
+ processedAt: Date;
272
+ error?: string;
273
+ }
274
+
275
+ export interface MessageBusConfig {
276
+ maxQueueSize: number;
277
+ processingIntervalMs: number;
278
+ ackTimeoutMs: number;
279
+ retryAttempts: number;
280
+ enablePersistence: boolean;
281
+ compressionEnabled: boolean;
282
+ }
283
+
284
+ export interface MessageBusStats {
285
+ totalMessages: number;
286
+ messagesPerSecond: number;
287
+ avgLatencyMs: number;
288
+ queueDepth: number;
289
+ ackRate: number;
290
+ errorRate: number;
291
+ }
292
+
293
+ // ===== COORDINATOR TYPES =====
294
+
295
+ export interface CoordinatorConfig {
296
+ topology: TopologyConfig;
297
+ consensus: ConsensusConfig;
298
+ messageBus: MessageBusConfig;
299
+ maxAgents: number;
300
+ maxTasks: number;
301
+ heartbeatIntervalMs: number;
302
+ healthCheckIntervalMs: number;
303
+ taskTimeoutMs: number;
304
+ autoScaling: boolean;
305
+ autoRecovery: boolean;
306
+ }
307
+
308
+ export interface CoordinatorState {
309
+ id: SwarmId;
310
+ status: SwarmStatus;
311
+ topology: TopologyState;
312
+ agents: Map<string, AgentState>;
313
+ tasks: Map<string, TaskDefinition>;
314
+ metrics: CoordinatorMetrics;
315
+ startedAt?: Date;
316
+ }
317
+
318
+ export type SwarmStatus =
319
+ | 'initializing'
320
+ | 'running'
321
+ | 'paused'
322
+ | 'recovering'
323
+ | 'shutting_down'
324
+ | 'stopped'
325
+ | 'failed';
326
+
327
+ export interface CoordinatorMetrics {
328
+ uptime: number;
329
+ activeAgents: number;
330
+ totalTasks: number;
331
+ completedTasks: number;
332
+ failedTasks: number;
333
+ avgTaskDurationMs: number;
334
+ messagesPerSecond: number;
335
+ consensusSuccessRate: number;
336
+ coordinationLatencyMs: number;
337
+ memoryUsageBytes: number;
338
+ }
339
+
340
+ // ===== EVENT TYPES =====
341
+
342
+ export type SwarmEventType =
343
+ | 'swarm.initialized'
344
+ | 'swarm.started'
345
+ | 'swarm.paused'
346
+ | 'swarm.resumed'
347
+ | 'swarm.stopped'
348
+ | 'swarm.failed'
349
+ | 'agent.joined'
350
+ | 'agent.left'
351
+ | 'agent.status_changed'
352
+ | 'agent.heartbeat'
353
+ | 'agent.domain_assigned'
354
+ | 'task.created'
355
+ | 'task.assigned'
356
+ | 'task.started'
357
+ | 'task.completed'
358
+ | 'task.failed'
359
+ | 'task.queued'
360
+ | 'topology.updated'
361
+ | 'topology.rebalanced'
362
+ | 'consensus.proposed'
363
+ | 'consensus.achieved'
364
+ | 'consensus.failed'
365
+ | 'message.sent'
366
+ | 'message.received'
367
+ | 'parallel.execution.completed'
368
+ | 'hierarchy.spawned';
369
+
370
+ export interface SwarmEvent {
371
+ id: string;
372
+ type: SwarmEventType;
373
+ source: string;
374
+ timestamp: Date;
375
+ data: Record<string, unknown>;
376
+ correlationId?: string;
377
+ }
378
+
379
+ // ===== POOL TYPES =====
380
+
381
+ export interface AgentPoolConfig {
382
+ name: string;
383
+ type: AgentType;
384
+ minSize: number;
385
+ maxSize: number;
386
+ scaleUpThreshold: number;
387
+ scaleDownThreshold: number;
388
+ cooldownMs: number;
389
+ healthCheckIntervalMs: number;
390
+ }
391
+
392
+ export interface AgentPoolState {
393
+ id: string;
394
+ config: AgentPoolConfig;
395
+ agents: Map<string, AgentState>;
396
+ availableAgents: string[];
397
+ busyAgents: string[];
398
+ pendingScale: number;
399
+ lastScaleOperation?: Date;
400
+ }
401
+
402
+ // ===== UTILITY TYPES =====
403
+
404
+ export interface HealthCheck {
405
+ agentId: string;
406
+ timestamp: Date;
407
+ healthy: boolean;
408
+ latencyMs: number;
409
+ details: Record<string, unknown>;
410
+ }
411
+
412
+ export interface PerformanceReport {
413
+ timestamp: Date;
414
+ window: number;
415
+ coordinationLatencyP50: number;
416
+ coordinationLatencyP99: number;
417
+ messagesPerSecond: number;
418
+ taskThroughput: number;
419
+ agentUtilization: number;
420
+ consensusSuccessRate: number;
421
+ }
422
+
423
+ // ===== CONSTANTS =====
424
+
425
+ export const SWARM_CONSTANTS = {
426
+ DEFAULT_HEARTBEAT_INTERVAL_MS: 5000,
427
+ DEFAULT_HEALTH_CHECK_INTERVAL_MS: 10000,
428
+ DEFAULT_TASK_TIMEOUT_MS: 300000,
429
+ DEFAULT_CONSENSUS_TIMEOUT_MS: 30000,
430
+ DEFAULT_MESSAGE_TTL_MS: 60000,
431
+ DEFAULT_MAX_AGENTS: 100,
432
+ DEFAULT_MAX_TASKS: 1000,
433
+ DEFAULT_CONSENSUS_THRESHOLD: 0.66,
434
+ MAX_QUEUE_SIZE: 10000,
435
+ MAX_RETRIES: 3,
436
+ COORDINATION_LATENCY_TARGET_MS: 100,
437
+ MESSAGES_PER_SECOND_TARGET: 1000,
438
+ } as const;
439
+
440
+ // ===== TYPE GUARDS =====
441
+
442
+ export function isAgentId(obj: unknown): obj is AgentId {
443
+ return (
444
+ typeof obj === 'object' &&
445
+ obj !== null &&
446
+ 'id' in obj &&
447
+ 'swarmId' in obj &&
448
+ 'type' in obj
449
+ );
450
+ }
451
+
452
+ export function isTaskId(obj: unknown): obj is TaskId {
453
+ return (
454
+ typeof obj === 'object' &&
455
+ obj !== null &&
456
+ 'id' in obj &&
457
+ 'swarmId' in obj &&
458
+ 'sequence' in obj
459
+ );
460
+ }
461
+
462
+ export function isMessage(obj: unknown): obj is Message {
463
+ return (
464
+ typeof obj === 'object' &&
465
+ obj !== null &&
466
+ 'id' in obj &&
467
+ 'type' in obj &&
468
+ 'from' in obj &&
469
+ 'to' in obj
470
+ );
471
+ }
472
+
473
+ // ===== INTERFACES FOR COMPONENTS =====
474
+
475
+ export interface ITopologyManager {
476
+ initialize(config: TopologyConfig): Promise<void>;
477
+ getState(): TopologyState;
478
+ addNode(agentId: string, role: TopologyNode['role']): Promise<TopologyNode>;
479
+ removeNode(agentId: string): Promise<void>;
480
+ updateNode(agentId: string, updates: Partial<TopologyNode>): Promise<void>;
481
+ getLeader(): string | undefined;
482
+ electLeader(): Promise<string>;
483
+ rebalance(): Promise<void>;
484
+ getNeighbors(agentId: string): string[];
485
+ findOptimalPath(from: string, to: string): string[];
486
+ }
487
+
488
+ export interface IConsensusEngine {
489
+ initialize(config: ConsensusConfig): Promise<void>;
490
+ propose(value: unknown, proposerId: string): Promise<ConsensusProposal>;
491
+ vote(proposalId: string, vote: ConsensusVote): Promise<void>;
492
+ getProposal(proposalId: string): ConsensusProposal | undefined;
493
+ awaitConsensus(proposalId: string): Promise<ConsensusResult>;
494
+ getActiveProposals(): ConsensusProposal[];
495
+ }
496
+
497
+ export interface IMessageBus {
498
+ initialize(config: MessageBusConfig): Promise<void>;
499
+ send(message: Omit<Message, 'id' | 'timestamp'>): Promise<string>;
500
+ broadcast(message: Omit<Message, 'id' | 'timestamp' | 'to'>): Promise<string>;
501
+ subscribe(agentId: string, callback: (message: Message) => void): void;
502
+ unsubscribe(agentId: string): void;
503
+ acknowledge(ack: MessageAck): Promise<void>;
504
+ getStats(): MessageBusStats;
505
+ getQueueDepth(): number;
506
+ }
507
+
508
+ export interface IAgentPool {
509
+ initialize(config: AgentPoolConfig): Promise<void>;
510
+ acquire(): Promise<AgentState | undefined>;
511
+ release(agentId: string): Promise<void>;
512
+ add(agent: AgentState): Promise<void>;
513
+ remove(agentId: string): Promise<void>;
514
+ scale(delta: number): Promise<void>;
515
+ getState(): AgentPoolState;
516
+ getAvailableCount(): number;
517
+ }
518
+
519
+ export interface IUnifiedSwarmCoordinator {
520
+ initialize(): Promise<void>;
521
+ shutdown(): Promise<void>;
522
+ pause(): Promise<void>;
523
+ resume(): Promise<void>;
524
+
525
+ // Agent management
526
+ registerAgent(agent: Omit<AgentState, 'id'>): Promise<string>;
527
+ unregisterAgent(agentId: string): Promise<void>;
528
+ getAgent(agentId: string): AgentState | undefined;
529
+ getAllAgents(): AgentState[];
530
+
531
+ // Task management
532
+ submitTask(task: Omit<TaskDefinition, 'id' | 'status' | 'createdAt'>): Promise<string>;
533
+ cancelTask(taskId: string): Promise<void>;
534
+ getTask(taskId: string): TaskDefinition | undefined;
535
+ getAllTasks(): TaskDefinition[];
536
+
537
+ // Coordination
538
+ proposeConsensus(value: unknown): Promise<ConsensusResult>;
539
+ broadcastMessage(payload: unknown, priority?: Message['priority']): Promise<void>;
540
+
541
+ // Monitoring
542
+ getState(): CoordinatorState;
543
+ getMetrics(): CoordinatorMetrics;
544
+ getPerformanceReport(): PerformanceReport;
545
+ }