@claude-flow/swarm 3.0.0-alpha.8 → 3.0.0-alpha.9

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 (117) hide show
  1. package/dist/agent-pool.d.ts.map +1 -1
  2. package/dist/agent-pool.js +10 -2
  3. package/dist/agent-pool.js.map +1 -1
  4. package/dist/attention-coordinator.d.ts +5 -4
  5. package/dist/attention-coordinator.d.ts.map +1 -1
  6. package/dist/attention-coordinator.js +17 -10
  7. package/dist/attention-coordinator.js.map +1 -1
  8. package/dist/consensus/byzantine.d.ts +2 -1
  9. package/dist/consensus/byzantine.d.ts.map +1 -1
  10. package/dist/consensus/byzantine.js +34 -8
  11. package/dist/consensus/byzantine.js.map +1 -1
  12. package/dist/consensus/gossip.d.ts +2 -1
  13. package/dist/consensus/gossip.d.ts.map +1 -1
  14. package/dist/consensus/gossip.js +27 -8
  15. package/dist/consensus/gossip.js.map +1 -1
  16. package/dist/consensus/index.d.ts +1 -1
  17. package/dist/consensus/index.d.ts.map +1 -1
  18. package/dist/consensus/index.js +2 -30
  19. package/dist/consensus/index.js.map +1 -1
  20. package/dist/consensus/raft.d.ts +2 -1
  21. package/dist/consensus/raft.d.ts.map +1 -1
  22. package/dist/consensus/raft.js +25 -9
  23. package/dist/consensus/raft.js.map +1 -1
  24. package/dist/index.js +2 -2
  25. package/dist/index.js.map +1 -1
  26. package/dist/message-bus.d.ts.map +1 -1
  27. package/dist/message-bus.js +13 -4
  28. package/dist/message-bus.js.map +1 -1
  29. package/dist/queen-coordinator.d.ts +1 -1
  30. package/dist/queen-coordinator.d.ts.map +1 -1
  31. package/dist/queen-coordinator.js +10 -3
  32. package/dist/queen-coordinator.js.map +1 -1
  33. package/dist/topology-manager.d.ts.map +1 -1
  34. package/dist/topology-manager.js +26 -1
  35. package/dist/topology-manager.js.map +1 -1
  36. package/dist/types.d.ts +3 -12
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/types.js.map +1 -1
  39. package/dist/unified-coordinator.d.ts +1 -1
  40. package/dist/unified-coordinator.d.ts.map +1 -1
  41. package/dist/unified-coordinator.js +85 -29
  42. package/dist/unified-coordinator.js.map +1 -1
  43. package/package.json +7 -2
  44. package/.claude-flow/data/pending-insights.jsonl +0 -15
  45. package/.claude-flow/hive-mind/state.json +0 -18
  46. package/__tests__/byzantine-transport.test.ts +0 -147
  47. package/__tests__/consensus-failure-injection.test.ts +0 -161
  48. package/__tests__/consensus-transport.test.ts +0 -200
  49. package/__tests__/consensus.test.ts +0 -577
  50. package/__tests__/coordinator.test.ts +0 -501
  51. package/__tests__/federation-transport.test.ts +0 -145
  52. package/__tests__/gossip-transport.test.ts +0 -81
  53. package/__tests__/queen-coordinator.test.ts +0 -1335
  54. package/__tests__/raft-transport.test.ts +0 -121
  55. package/__tests__/topology.test.ts +0 -621
  56. package/ruvector.db +0 -0
  57. package/src/agent-pool.ts +0 -476
  58. package/src/application/commands/create-task.command.ts +0 -124
  59. package/src/application/commands/spawn-agent.command.ts +0 -122
  60. package/src/application/index.ts +0 -30
  61. package/src/application/services/swarm-application-service.ts +0 -200
  62. package/src/attention-coordinator.ts +0 -1000
  63. package/src/consensus/byzantine.ts +0 -514
  64. package/src/consensus/federation-transport.ts +0 -185
  65. package/src/consensus/gossip.ts +0 -599
  66. package/src/consensus/index.ts +0 -326
  67. package/src/consensus/raft.ts +0 -561
  68. package/src/consensus/transport.ts +0 -284
  69. package/src/coordination/agent-registry.ts +0 -544
  70. package/src/coordination/index.ts +0 -23
  71. package/src/coordination/swarm-hub.ts +0 -776
  72. package/src/coordination/task-orchestrator.ts +0 -605
  73. package/src/domain/entities/agent.d.ts +0 -151
  74. package/src/domain/entities/agent.d.ts.map +0 -1
  75. package/src/domain/entities/agent.js +0 -280
  76. package/src/domain/entities/agent.js.map +0 -1
  77. package/src/domain/entities/agent.ts +0 -370
  78. package/src/domain/entities/task.d.ts +0 -133
  79. package/src/domain/entities/task.d.ts.map +0 -1
  80. package/src/domain/entities/task.js +0 -261
  81. package/src/domain/entities/task.js.map +0 -1
  82. package/src/domain/entities/task.ts +0 -319
  83. package/src/domain/index.ts +0 -41
  84. package/src/domain/repositories/agent-repository.interface.d.ts +0 -57
  85. package/src/domain/repositories/agent-repository.interface.d.ts.map +0 -1
  86. package/src/domain/repositories/agent-repository.interface.js +0 -9
  87. package/src/domain/repositories/agent-repository.interface.js.map +0 -1
  88. package/src/domain/repositories/agent-repository.interface.ts +0 -69
  89. package/src/domain/repositories/task-repository.interface.d.ts +0 -61
  90. package/src/domain/repositories/task-repository.interface.d.ts.map +0 -1
  91. package/src/domain/repositories/task-repository.interface.js +0 -9
  92. package/src/domain/repositories/task-repository.interface.js.map +0 -1
  93. package/src/domain/repositories/task-repository.interface.ts +0 -75
  94. package/src/domain/services/coordination-service.ts +0 -320
  95. package/src/federation-hub.d.ts +0 -284
  96. package/src/federation-hub.d.ts.map +0 -1
  97. package/src/federation-hub.js +0 -692
  98. package/src/federation-hub.js.map +0 -1
  99. package/src/federation-hub.ts +0 -979
  100. package/src/index.ts +0 -374
  101. package/src/message-bus.ts +0 -607
  102. package/src/queen-coordinator.ts +0 -2025
  103. package/src/shared/events.ts +0 -285
  104. package/src/shared/types.ts +0 -389
  105. package/src/topology-manager.ts +0 -656
  106. package/src/types.ts +0 -555
  107. package/src/unified-coordinator.ts +0 -1844
  108. package/src/workers/index.ts +0 -65
  109. package/src/workers/worker-dispatch.d.ts +0 -234
  110. package/src/workers/worker-dispatch.d.ts.map +0 -1
  111. package/src/workers/worker-dispatch.js +0 -842
  112. package/src/workers/worker-dispatch.js.map +0 -1
  113. package/src/workers/worker-dispatch.ts +0 -1076
  114. package/tmp.json +0 -0
  115. package/tsconfig.json +0 -9
  116. package/tsconfig.tsbuildinfo +0 -1
  117. package/vitest.config.ts +0 -20
@@ -1,285 +0,0 @@
1
- /**
2
- * @claude-flow/swarm - Standalone Event System
3
- * Event-driven communication for multi-agent swarm coordination
4
- *
5
- * This file provides a complete event system for standalone operation
6
- * without dependency on @claude-flow/shared
7
- */
8
-
9
- import type { SwarmEvent, EventType, EventHandler, AgentId } from './types.js';
10
-
11
- // =============================================================================
12
- // Event Bus Interface
13
- // =============================================================================
14
-
15
- export interface IEventBus {
16
- subscribe<T>(eventType: EventType, handler: EventHandler<T>): () => void;
17
- subscribeAll(handler: EventHandler): () => void;
18
- emit<T>(event: SwarmEvent<T>): Promise<void>;
19
- emitSync<T>(event: SwarmEvent<T>): void;
20
- getHistory(filter?: EventFilter): SwarmEvent[];
21
- clear(): void;
22
- }
23
-
24
- export interface EventFilter {
25
- types?: EventType[];
26
- sources?: (AgentId | 'swarm')[];
27
- since?: number;
28
- until?: number;
29
- limit?: number;
30
- }
31
-
32
- // =============================================================================
33
- // Event Bus Implementation
34
- // =============================================================================
35
-
36
- export class EventBus implements IEventBus {
37
- private handlers: Map<EventType | '*', Set<EventHandler>> = new Map();
38
- private history: SwarmEvent[] = [];
39
- private maxHistorySize: number;
40
-
41
- constructor(options: { maxHistorySize?: number } = {}) {
42
- this.maxHistorySize = options.maxHistorySize ?? 10000;
43
- }
44
-
45
- subscribe<T>(eventType: EventType, handler: EventHandler<T>): () => void {
46
- if (!this.handlers.has(eventType)) {
47
- this.handlers.set(eventType, new Set());
48
- }
49
-
50
- const handlers = this.handlers.get(eventType)!;
51
- handlers.add(handler as EventHandler);
52
-
53
- return () => {
54
- handlers.delete(handler as EventHandler);
55
- };
56
- }
57
-
58
- subscribeAll(handler: EventHandler): () => void {
59
- if (!this.handlers.has('*')) {
60
- this.handlers.set('*', new Set());
61
- }
62
-
63
- const handlers = this.handlers.get('*')!;
64
- handlers.add(handler);
65
-
66
- return () => {
67
- handlers.delete(handler);
68
- };
69
- }
70
-
71
- async emit<T>(event: SwarmEvent<T>): Promise<void> {
72
- this.addToHistory(event);
73
-
74
- const typeHandlers = this.handlers.get(event.type) ?? new Set();
75
- const allHandlers = this.handlers.get('*') ?? new Set();
76
-
77
- const allPromises: Promise<void>[] = [];
78
-
79
- for (const handler of typeHandlers) {
80
- allPromises.push(this.safeExecute(handler, event));
81
- }
82
-
83
- for (const handler of allHandlers) {
84
- allPromises.push(this.safeExecute(handler, event));
85
- }
86
-
87
- await Promise.all(allPromises);
88
- }
89
-
90
- emitSync<T>(event: SwarmEvent<T>): void {
91
- this.addToHistory(event);
92
-
93
- const typeHandlers = this.handlers.get(event.type) ?? new Set();
94
- const allHandlers = this.handlers.get('*') ?? new Set();
95
-
96
- for (const handler of typeHandlers) {
97
- try {
98
- const result = handler(event);
99
- if (result instanceof Promise) {
100
- result.catch(err => console.error(`Event handler error: ${err}`));
101
- }
102
- } catch (err) {
103
- console.error(`Event handler error: ${err}`);
104
- }
105
- }
106
-
107
- for (const handler of allHandlers) {
108
- try {
109
- const result = handler(event);
110
- if (result instanceof Promise) {
111
- result.catch(err => console.error(`Event handler error: ${err}`));
112
- }
113
- } catch (err) {
114
- console.error(`Event handler error: ${err}`);
115
- }
116
- }
117
- }
118
-
119
- getHistory(filter?: EventFilter): SwarmEvent[] {
120
- let events = [...this.history];
121
-
122
- if (filter?.types?.length) {
123
- events = events.filter(e => filter.types!.includes(e.type));
124
- }
125
-
126
- if (filter?.sources?.length) {
127
- events = events.filter(e => filter.sources!.includes(e.source));
128
- }
129
-
130
- if (filter?.since) {
131
- events = events.filter(e => e.timestamp >= filter.since!);
132
- }
133
-
134
- if (filter?.until) {
135
- events = events.filter(e => e.timestamp <= filter.until!);
136
- }
137
-
138
- if (filter?.limit) {
139
- events = events.slice(-filter.limit);
140
- }
141
-
142
- return events;
143
- }
144
-
145
- clear(): void {
146
- this.history = [];
147
- }
148
-
149
- private addToHistory(event: SwarmEvent): void {
150
- this.history.push(event);
151
-
152
- if (this.history.length > this.maxHistorySize) {
153
- this.history = this.history.slice(-Math.floor(this.maxHistorySize / 2));
154
- }
155
- }
156
-
157
- private async safeExecute(handler: EventHandler, event: SwarmEvent): Promise<void> {
158
- try {
159
- await handler(event);
160
- } catch (err) {
161
- console.error(`Event handler error for ${event.type}: ${err}`);
162
- }
163
- }
164
- }
165
-
166
- // =============================================================================
167
- // Event Factory Functions
168
- // =============================================================================
169
-
170
- let eventCounter = 0;
171
-
172
- export function createEvent<T>(
173
- type: EventType,
174
- source: AgentId | 'swarm',
175
- payload: T
176
- ): SwarmEvent<T> {
177
- return {
178
- id: `evt-${Date.now()}-${++eventCounter}`,
179
- type,
180
- timestamp: Date.now(),
181
- source,
182
- payload
183
- };
184
- }
185
-
186
- // Helper function to generate event IDs
187
- function generateEventId(): string {
188
- return `evt-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
189
- }
190
-
191
- // Helper function to create a base SwarmEvent
192
- function createSwarmEvent<T>(
193
- type: EventType,
194
- source: string,
195
- payload: T
196
- ): SwarmEvent<T> {
197
- return {
198
- id: generateEventId(),
199
- type,
200
- timestamp: Date.now(),
201
- source,
202
- payload,
203
- };
204
- }
205
-
206
- // Agent events
207
- export function agentSpawnedEvent(agentId: string, state: unknown): SwarmEvent<{ agentId: string; state: unknown }> {
208
- return createSwarmEvent('agent:spawned', agentId, { agentId, state });
209
- }
210
-
211
- export function agentStatusChangedEvent(
212
- agentId: AgentId,
213
- previousStatus: string,
214
- newStatus: string
215
- ): SwarmEvent {
216
- return createEvent('agent:status-changed', agentId, { previousStatus, newStatus });
217
- }
218
-
219
- export function agentTaskAssignedEvent(agentId: AgentId, taskId: string): SwarmEvent {
220
- return createEvent('agent:task-assigned', 'swarm', { agentId, taskId });
221
- }
222
-
223
- export function agentTaskCompletedEvent(agentId: AgentId, taskId: string, result: unknown): SwarmEvent {
224
- return createEvent('agent:task-completed', agentId, { taskId, result });
225
- }
226
-
227
- export function agentErrorEvent(agentId: AgentId, error: Error): SwarmEvent {
228
- return createEvent('agent:error', agentId, {
229
- message: error.message,
230
- stack: error.stack
231
- });
232
- }
233
-
234
- // Task Events
235
- export function taskCreatedEvent(taskId: string, spec: { type: string; title: string }): SwarmEvent {
236
- return createEvent('task:created', 'swarm', { taskId, type: spec.type, title: spec.title });
237
- }
238
-
239
- export function taskQueuedEvent(taskId: string, position: number): SwarmEvent {
240
- return createEvent('task:queued', 'swarm', { taskId, position });
241
- }
242
-
243
- export function taskAssignedEvent(taskId: string, agentId: AgentId): SwarmEvent {
244
- return createEvent('task:assigned', 'swarm', { taskId, agentId });
245
- }
246
-
247
- export function taskStartedEvent(taskId: string, agentId: AgentId): SwarmEvent {
248
- return createEvent('task:started', agentId, { taskId });
249
- }
250
-
251
- export function taskCompletedEvent(taskId: string, result: unknown): SwarmEvent {
252
- return createEvent('task:completed', 'swarm', { taskId, result });
253
- }
254
-
255
- export function taskFailedEvent(taskId: string, error: Error): SwarmEvent {
256
- return createEvent('task:failed', 'swarm', {
257
- taskId,
258
- error: error.message,
259
- stack: error.stack
260
- });
261
- }
262
-
263
- export function taskBlockedEvent(taskId: string, reason: string, blockingTask: string): SwarmEvent {
264
- return createEvent('task:blocked', 'swarm', { taskId, reason, blockingTask });
265
- }
266
-
267
- // Swarm Events
268
- export function swarmInitializedEvent(source: string, config: unknown): SwarmEvent {
269
- return createEvent('swarm:initialized', source, { config });
270
- }
271
-
272
- export function swarmPhaseChangedEvent(source: string, previousPhase: string, newPhase: string): SwarmEvent {
273
- return createEvent('swarm:phase-changed', source, { previousPhase, newPhase });
274
- }
275
-
276
- export function swarmMilestoneReachedEvent(milestoneId: string, name: string): SwarmEvent {
277
- return createEvent('swarm:milestone-reached', 'swarm', { milestoneId, name });
278
- }
279
-
280
- export function swarmErrorEvent(error: Error): SwarmEvent {
281
- return createEvent('swarm:error', 'swarm', {
282
- message: error.message,
283
- stack: error.stack
284
- });
285
- }
@@ -1,389 +0,0 @@
1
- /**
2
- * @claude-flow/swarm - Standalone Types
3
- * Core type definitions for multi-agent swarm coordination
4
- *
5
- * This file provides all types needed for standalone operation
6
- * without dependency on @claude-flow/shared
7
- */
8
-
9
- // =============================================================================
10
- // Agent Types
11
- // =============================================================================
12
-
13
- export type AgentId = `agent-${number}` | string;
14
-
15
- export type AgentRole =
16
- | 'queen-coordinator' // Agent #1
17
- | 'security-architect' // Agent #2
18
- | 'security-implementer' // Agent #3
19
- | 'security-tester' // Agent #4
20
- | 'core-architect' // Agent #5
21
- | 'core-implementer' // Agent #6
22
- | 'memory-specialist' // Agent #7
23
- | 'swarm-specialist' // Agent #8
24
- | 'mcp-specialist' // Agent #9
25
- | 'integration-architect' // Agent #10
26
- | 'cli-hooks-developer' // Agent #11
27
- | 'neural-learning-dev' // Agent #12
28
- | 'tdd-test-engineer' // Agent #13
29
- | 'performance-engineer' // Agent #14
30
- | 'release-engineer'; // Agent #15
31
-
32
- export type AgentStatus =
33
- | 'idle'
34
- | 'active'
35
- | 'blocked'
36
- | 'completed'
37
- | 'error';
38
-
39
- export type AgentDomain =
40
- | 'security' // Agents #2-4
41
- | 'core' // Agents #5-9
42
- | 'integration' // Agents #10-12
43
- | 'quality' // Agent #13
44
- | 'performance' // Agent #14
45
- | 'deployment'; // Agent #15
46
-
47
- export interface AgentCapability {
48
- name: string;
49
- description: string;
50
- supportedTaskTypes: TaskType[];
51
- }
52
-
53
- export interface AgentDefinition {
54
- id: AgentId;
55
- role: AgentRole;
56
- domain: AgentDomain;
57
- description: string;
58
- capabilities: AgentCapability[];
59
- dependencies: AgentId[];
60
- priority: number;
61
- }
62
-
63
- export interface AgentState {
64
- id: AgentId;
65
- role: AgentRole;
66
- status: AgentStatus;
67
- currentTask: TaskId | null;
68
- completedTasks: TaskId[];
69
- metrics: AgentMetrics;
70
- lastHeartbeat: number;
71
- }
72
-
73
- export interface AgentMetrics {
74
- tasksCompleted: number;
75
- tasksFailed: number;
76
- averageTaskDuration: number;
77
- utilization: number;
78
- startTime: number;
79
- }
80
-
81
- // =============================================================================
82
- // Task Types
83
- // =============================================================================
84
-
85
- export type TaskId = `task-${string}`;
86
-
87
- export type TaskType =
88
- | 'security-audit'
89
- | 'security-fix'
90
- | 'security-test'
91
- | 'architecture-design'
92
- | 'implementation'
93
- | 'memory-optimization'
94
- | 'swarm-coordination'
95
- | 'mcp-enhancement'
96
- | 'integration'
97
- | 'cli-development'
98
- | 'neural-training'
99
- | 'test-writing'
100
- | 'benchmark'
101
- | 'deployment'
102
- | 'documentation';
103
-
104
- export type TaskStatus =
105
- | 'pending'
106
- | 'queued'
107
- | 'assigned'
108
- | 'in-progress'
109
- | 'blocked'
110
- | 'completed'
111
- | 'failed'
112
- | 'cancelled';
113
-
114
- export type TaskPriority =
115
- | 'critical'
116
- | 'high'
117
- | 'medium'
118
- | 'low';
119
-
120
- export interface TaskDefinition {
121
- id: TaskId;
122
- type: TaskType;
123
- title: string;
124
- description: string;
125
- assignedAgent: AgentId | null;
126
- status: TaskStatus;
127
- priority: TaskPriority;
128
- dependencies: TaskId[];
129
- blockedBy: TaskId[];
130
- metadata: TaskMetadata;
131
- createdAt: number;
132
- updatedAt: number;
133
- completedAt: number | null;
134
- }
135
-
136
- export interface TaskMetadata {
137
- domain: AgentDomain;
138
- phase: PhaseId;
139
- estimatedDuration: number;
140
- actualDuration: number | null;
141
- retryCount: number;
142
- maxRetries: number;
143
- artifacts: string[];
144
- tags: string[];
145
- }
146
-
147
- export interface TaskResult {
148
- taskId: TaskId;
149
- success: boolean;
150
- output: unknown;
151
- error: Error | null;
152
- duration: number;
153
- metrics: TaskResultMetrics;
154
- }
155
-
156
- export interface TaskResultMetrics {
157
- linesOfCode: number;
158
- testsWritten: number;
159
- testsPassed: number;
160
- coveragePercent: number;
161
- performanceImpact: number;
162
- }
163
-
164
- // =============================================================================
165
- // Phase Types
166
- // =============================================================================
167
-
168
- export type PhaseId =
169
- | 'phase-1-foundation'
170
- | 'phase-2-core'
171
- | 'phase-3-integration'
172
- | 'phase-4-release';
173
-
174
- export interface PhaseDefinition {
175
- id: PhaseId;
176
- name: string;
177
- description: string;
178
- weeks: [number, number];
179
- activeAgents: AgentId[];
180
- goals: string[];
181
- milestones: MilestoneDefinition[];
182
- }
183
-
184
- export interface MilestoneDefinition {
185
- id: string;
186
- name: string;
187
- description: string;
188
- criteria: MilestoneCriteria[];
189
- status: MilestoneStatus;
190
- completedAt: number | null;
191
- }
192
-
193
- export type MilestoneStatus = 'pending' | 'in-progress' | 'completed' | 'blocked';
194
-
195
- export interface MilestoneCriteria {
196
- description: string;
197
- met: boolean;
198
- evidence: string | null;
199
- }
200
-
201
- // =============================================================================
202
- // Swarm Types
203
- // =============================================================================
204
-
205
- export type TopologyType =
206
- | 'hierarchical-mesh'
207
- | 'mesh'
208
- | 'hierarchical'
209
- | 'centralized'
210
- | 'hybrid';
211
-
212
- export interface SwarmConfig {
213
- topology: TopologyType;
214
- maxAgents: number;
215
- messageTimeout: number;
216
- retryAttempts: number;
217
- healthCheckInterval: number;
218
- loadBalancingStrategy: LoadBalancingStrategy;
219
- }
220
-
221
- export type LoadBalancingStrategy =
222
- | 'round-robin'
223
- | 'least-loaded'
224
- | 'capability-match'
225
- | 'priority-based';
226
-
227
- export interface SwarmState {
228
- initialized: boolean;
229
- topology: TopologyType;
230
- agents: Map<AgentId, AgentState>;
231
- tasks: Map<TaskId, TaskDefinition>;
232
- currentPhase: PhaseId;
233
- metrics: SwarmMetrics;
234
- }
235
-
236
- export interface SwarmMetrics {
237
- totalAgents: number;
238
- activeAgents: number;
239
- idleAgents: number;
240
- blockedAgents: number;
241
- totalTasks: number;
242
- completedTasks: number;
243
- failedTasks: number;
244
- pendingTasks: number;
245
- averageTaskDuration: number;
246
- utilization: number;
247
- startTime: number;
248
- lastUpdate: number;
249
- }
250
-
251
- // =============================================================================
252
- // Event Types
253
- // =============================================================================
254
-
255
- export type EventType =
256
- | 'agent:spawned'
257
- | 'agent:status-changed'
258
- | 'agent:task-assigned'
259
- | 'agent:task-completed'
260
- | 'agent:error'
261
- | 'task:created'
262
- | 'task:queued'
263
- | 'task:assigned'
264
- | 'task:started'
265
- | 'task:completed'
266
- | 'task:failed'
267
- | 'task:blocked'
268
- | 'swarm:initialized'
269
- | 'swarm:phase-changed'
270
- | 'swarm:milestone-reached'
271
- | 'swarm:error';
272
-
273
- export interface SwarmEvent<T = unknown> {
274
- id: string;
275
- type: EventType;
276
- timestamp: number;
277
- source: AgentId | 'swarm';
278
- payload: T;
279
- }
280
-
281
- export type EventHandler<T = unknown> = (event: SwarmEvent<T>) => void | Promise<void>;
282
-
283
- // =============================================================================
284
- // Message Types
285
- // =============================================================================
286
-
287
- export type MessageType =
288
- | 'task_assignment'
289
- | 'task_complete'
290
- | 'task_failed'
291
- | 'dependency_ready'
292
- | 'review_request'
293
- | 'status_update'
294
- | 'heartbeat'
295
- | 'broadcast';
296
-
297
- export interface SwarmMessage<T = unknown> {
298
- id: string;
299
- type: MessageType;
300
- from: AgentId;
301
- to: AgentId | 'broadcast';
302
- payload: T;
303
- timestamp: number;
304
- correlationId: string | null;
305
- }
306
-
307
- export type MessageHandler<T = unknown> = (message: SwarmMessage<T>) => void | Promise<void>;
308
-
309
- // =============================================================================
310
- // Interface Types (for dependency injection)
311
- // =============================================================================
312
-
313
- export interface IAgent {
314
- id: AgentId;
315
- role: AgentRole;
316
- status: AgentStatus;
317
- execute(task: TaskDefinition): Promise<TaskResult>;
318
- getState(): AgentState;
319
- }
320
-
321
- export interface ITask {
322
- id: TaskId;
323
- type: TaskType;
324
- status: TaskStatus;
325
- priority: TaskPriority;
326
- execute(): Promise<TaskResult>;
327
- }
328
-
329
- // =============================================================================
330
- // Performance Targets
331
- // =============================================================================
332
-
333
- export interface PerformanceTargets {
334
- flashAttention: {
335
- minSpeedup: number;
336
- maxSpeedup: number;
337
- };
338
- agentDbSearch: {
339
- minSpeedup: number;
340
- maxSpeedup: number;
341
- };
342
- memoryReduction: {
343
- minPercent: number;
344
- maxPercent: number;
345
- };
346
- codeReduction: {
347
- targetLines: number;
348
- currentLines: number;
349
- };
350
- startupTime: {
351
- targetMs: number;
352
- };
353
- sonaLearning: {
354
- targetMs: number;
355
- };
356
- }
357
-
358
- export const V3_PERFORMANCE_TARGETS: PerformanceTargets = {
359
- flashAttention: { minSpeedup: 2.49, maxSpeedup: 7.47 },
360
- agentDbSearch: { minSpeedup: 150, maxSpeedup: 12500 },
361
- memoryReduction: { minPercent: 50, maxPercent: 75 },
362
- codeReduction: { targetLines: 5000, currentLines: 15000 },
363
- startupTime: { targetMs: 500 },
364
- sonaLearning: { targetMs: 0.05 }
365
- };
366
-
367
- // =============================================================================
368
- // Utility Types
369
- // =============================================================================
370
-
371
- export type DeepPartial<T> = {
372
- [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
373
- };
374
-
375
- export type AsyncCallback<T = void> = () => Promise<T>;
376
-
377
- export interface Result<T, E = Error> {
378
- success: boolean;
379
- value?: T;
380
- error?: E;
381
- }
382
-
383
- export function success<T>(value: T): Result<T> {
384
- return { success: true, value };
385
- }
386
-
387
- export function failure<E = Error>(error: E): Result<never, E> {
388
- return { success: false, error };
389
- }