@claude-flow/swarm 3.0.0-alpha.7 → 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.
- package/dist/agent-pool.d.ts.map +1 -1
- package/dist/agent-pool.js +10 -2
- package/dist/agent-pool.js.map +1 -1
- package/dist/attention-coordinator.d.ts +5 -4
- package/dist/attention-coordinator.d.ts.map +1 -1
- package/dist/attention-coordinator.js +17 -10
- package/dist/attention-coordinator.js.map +1 -1
- package/dist/consensus/byzantine.d.ts +2 -1
- package/dist/consensus/byzantine.d.ts.map +1 -1
- package/dist/consensus/byzantine.js +34 -8
- package/dist/consensus/byzantine.js.map +1 -1
- package/dist/consensus/gossip.d.ts +2 -1
- package/dist/consensus/gossip.d.ts.map +1 -1
- package/dist/consensus/gossip.js +27 -8
- package/dist/consensus/gossip.js.map +1 -1
- package/dist/consensus/index.d.ts +1 -1
- package/dist/consensus/index.d.ts.map +1 -1
- package/dist/consensus/index.js +2 -2
- package/dist/consensus/index.js.map +1 -1
- package/dist/consensus/raft.d.ts +2 -1
- package/dist/consensus/raft.d.ts.map +1 -1
- package/dist/consensus/raft.js +25 -9
- package/dist/consensus/raft.js.map +1 -1
- package/dist/coordination/agent-registry.d.ts +2 -2
- package/dist/coordination/agent-registry.d.ts.map +1 -1
- package/dist/coordination/agent-registry.js +1 -1
- package/dist/coordination/agent-registry.js.map +1 -1
- package/dist/coordination/swarm-hub.d.ts +5 -5
- package/dist/coordination/swarm-hub.d.ts.map +1 -1
- package/dist/coordination/swarm-hub.js +5 -5
- package/dist/coordination/swarm-hub.js.map +1 -1
- package/dist/coordination/task-orchestrator.d.ts +3 -3
- package/dist/coordination/task-orchestrator.d.ts.map +1 -1
- package/dist/coordination/task-orchestrator.js +1 -1
- package/dist/coordination/task-orchestrator.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/message-bus.d.ts.map +1 -1
- package/dist/message-bus.js +13 -4
- package/dist/message-bus.js.map +1 -1
- package/dist/queen-coordinator.d.ts +1 -1
- package/dist/queen-coordinator.d.ts.map +1 -1
- package/dist/queen-coordinator.js +10 -3
- package/dist/queen-coordinator.js.map +1 -1
- package/dist/topology-manager.d.ts.map +1 -1
- package/dist/topology-manager.js +26 -1
- package/dist/topology-manager.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/unified-coordinator.d.ts +1 -1
- package/dist/unified-coordinator.d.ts.map +1 -1
- package/dist/unified-coordinator.js +85 -29
- package/dist/unified-coordinator.js.map +1 -1
- package/package.json +7 -2
- package/.claude-flow/data/pending-insights.jsonl +0 -12
- package/__tests__/byzantine-transport.test.ts +0 -147
- package/__tests__/consensus-failure-injection.test.ts +0 -161
- package/__tests__/consensus-transport.test.ts +0 -200
- package/__tests__/consensus.test.ts +0 -577
- package/__tests__/coordinator.test.ts +0 -501
- package/__tests__/federation-transport.test.ts +0 -145
- package/__tests__/gossip-transport.test.ts +0 -81
- package/__tests__/queen-coordinator.test.ts +0 -1335
- package/__tests__/raft-transport.test.ts +0 -121
- package/__tests__/topology.test.ts +0 -621
- package/ruvector.db +0 -0
- package/src/agent-pool.ts +0 -476
- package/src/application/commands/create-task.command.ts +0 -124
- package/src/application/commands/spawn-agent.command.ts +0 -122
- package/src/application/index.ts +0 -30
- package/src/application/services/swarm-application-service.ts +0 -200
- package/src/attention-coordinator.ts +0 -1000
- package/src/consensus/byzantine.ts +0 -514
- package/src/consensus/federation-transport.ts +0 -185
- package/src/consensus/gossip.ts +0 -599
- package/src/consensus/index.ts +0 -296
- package/src/consensus/raft.ts +0 -561
- package/src/consensus/transport.ts +0 -284
- package/src/coordination/agent-registry.ts +0 -544
- package/src/coordination/index.ts +0 -23
- package/src/coordination/swarm-hub.ts +0 -776
- package/src/coordination/task-orchestrator.ts +0 -605
- package/src/domain/entities/agent.d.ts +0 -151
- package/src/domain/entities/agent.d.ts.map +0 -1
- package/src/domain/entities/agent.js +0 -280
- package/src/domain/entities/agent.js.map +0 -1
- package/src/domain/entities/agent.ts +0 -370
- package/src/domain/entities/task.d.ts +0 -133
- package/src/domain/entities/task.d.ts.map +0 -1
- package/src/domain/entities/task.js +0 -261
- package/src/domain/entities/task.js.map +0 -1
- package/src/domain/entities/task.ts +0 -319
- package/src/domain/index.ts +0 -41
- package/src/domain/repositories/agent-repository.interface.d.ts +0 -57
- package/src/domain/repositories/agent-repository.interface.d.ts.map +0 -1
- package/src/domain/repositories/agent-repository.interface.js +0 -9
- package/src/domain/repositories/agent-repository.interface.js.map +0 -1
- package/src/domain/repositories/agent-repository.interface.ts +0 -69
- package/src/domain/repositories/task-repository.interface.d.ts +0 -61
- package/src/domain/repositories/task-repository.interface.d.ts.map +0 -1
- package/src/domain/repositories/task-repository.interface.js +0 -9
- package/src/domain/repositories/task-repository.interface.js.map +0 -1
- package/src/domain/repositories/task-repository.interface.ts +0 -75
- package/src/domain/services/coordination-service.ts +0 -320
- package/src/federation-hub.d.ts +0 -284
- package/src/federation-hub.d.ts.map +0 -1
- package/src/federation-hub.js +0 -692
- package/src/federation-hub.js.map +0 -1
- package/src/federation-hub.ts +0 -979
- package/src/index.ts +0 -348
- package/src/message-bus.ts +0 -607
- package/src/queen-coordinator.ts +0 -2025
- package/src/shared/events.ts +0 -285
- package/src/shared/types.ts +0 -389
- package/src/topology-manager.ts +0 -656
- package/src/types.ts +0 -545
- package/src/unified-coordinator.ts +0 -1844
- package/src/workers/index.ts +0 -65
- package/src/workers/worker-dispatch.d.ts +0 -234
- package/src/workers/worker-dispatch.d.ts.map +0 -1
- package/src/workers/worker-dispatch.js +0 -842
- package/src/workers/worker-dispatch.js.map +0 -1
- package/src/workers/worker-dispatch.ts +0 -1076
- package/tmp.json +0 -0
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -20
package/src/consensus/index.ts
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* V3 Consensus Engine Factory
|
|
3
|
-
* Unified interface for different consensus algorithms
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { EventEmitter } from 'events';
|
|
7
|
-
import {
|
|
8
|
-
ConsensusAlgorithm,
|
|
9
|
-
ConsensusConfig,
|
|
10
|
-
ConsensusProposal,
|
|
11
|
-
ConsensusVote,
|
|
12
|
-
ConsensusResult,
|
|
13
|
-
IConsensusEngine,
|
|
14
|
-
SWARM_CONSTANTS,
|
|
15
|
-
} from '../types.js';
|
|
16
|
-
import { RaftConsensus, createRaftConsensus, RaftConfig } from './raft.js';
|
|
17
|
-
import { ByzantineConsensus, createByzantineConsensus, ByzantineConfig } from './byzantine.js';
|
|
18
|
-
import { GossipConsensus, createGossipConsensus, GossipConfig } from './gossip.js';
|
|
19
|
-
|
|
20
|
-
export { RaftConsensus, ByzantineConsensus, GossipConsensus };
|
|
21
|
-
export type { RaftConfig, ByzantineConfig, GossipConfig };
|
|
22
|
-
|
|
23
|
-
// ADR-095 G2 — pluggable consensus transport. Replaces the implicit
|
|
24
|
-
// single-process EventEmitter messaging in the consensus protocols.
|
|
25
|
-
// LocalTransport is the default (matches current behavior); FederationTransport
|
|
26
|
-
// (separate file, ADR-104 wire) is the multi-host one.
|
|
27
|
-
export {
|
|
28
|
-
LocalTransport,
|
|
29
|
-
LocalTransportRegistry,
|
|
30
|
-
defaultLocalRegistry,
|
|
31
|
-
generateNodeKeyPair,
|
|
32
|
-
signMessage,
|
|
33
|
-
verifyMessage,
|
|
34
|
-
canonicalizeForSigning,
|
|
35
|
-
messageDigest,
|
|
36
|
-
} from './transport.js';
|
|
37
|
-
export type {
|
|
38
|
-
ConsensusTransport,
|
|
39
|
-
ConsensusMessage,
|
|
40
|
-
ConsensusReply,
|
|
41
|
-
ConsensusMessageHandler,
|
|
42
|
-
NodeKeyPair,
|
|
43
|
-
LocalTransportOptions,
|
|
44
|
-
} from './transport.js';
|
|
45
|
-
|
|
46
|
-
// ADR-095 G2 — FederationTransport: ConsensusTransport over the federation
|
|
47
|
-
// plugin's ADR-104 WS wire (agentic-flow/transport/loader). Structural —
|
|
48
|
-
// swarm doesn't import agentic-flow; the caller passes a transport instance.
|
|
49
|
-
export { FederationTransport } from './federation-transport.js';
|
|
50
|
-
export type { AgenticFlowTransportLike, FederationTransportOptions } from './federation-transport.js';
|
|
51
|
-
|
|
52
|
-
type ConsensusImplementation = RaftConsensus | ByzantineConsensus | GossipConsensus;
|
|
53
|
-
|
|
54
|
-
export class ConsensusEngine extends EventEmitter implements IConsensusEngine {
|
|
55
|
-
private config: ConsensusConfig;
|
|
56
|
-
private nodeId: string;
|
|
57
|
-
private implementation?: ConsensusImplementation;
|
|
58
|
-
private proposals: Map<string, ConsensusProposal> = new Map();
|
|
59
|
-
|
|
60
|
-
constructor(nodeId: string, config: Partial<ConsensusConfig> = {}) {
|
|
61
|
-
super();
|
|
62
|
-
this.nodeId = nodeId;
|
|
63
|
-
this.config = {
|
|
64
|
-
algorithm: config.algorithm ?? 'raft',
|
|
65
|
-
threshold: config.threshold ?? SWARM_CONSTANTS.DEFAULT_CONSENSUS_THRESHOLD,
|
|
66
|
-
timeoutMs: config.timeoutMs ?? SWARM_CONSTANTS.DEFAULT_CONSENSUS_TIMEOUT_MS,
|
|
67
|
-
maxRounds: config.maxRounds ?? 10,
|
|
68
|
-
requireQuorum: config.requireQuorum ?? true,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async initialize(config?: ConsensusConfig): Promise<void> {
|
|
73
|
-
if (config) {
|
|
74
|
-
this.config = { ...this.config, ...config };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Create implementation based on algorithm
|
|
78
|
-
switch (this.config.algorithm) {
|
|
79
|
-
case 'raft':
|
|
80
|
-
this.implementation = createRaftConsensus(this.nodeId, {
|
|
81
|
-
threshold: this.config.threshold,
|
|
82
|
-
timeoutMs: this.config.timeoutMs,
|
|
83
|
-
maxRounds: this.config.maxRounds,
|
|
84
|
-
requireQuorum: this.config.requireQuorum,
|
|
85
|
-
});
|
|
86
|
-
break;
|
|
87
|
-
|
|
88
|
-
case 'byzantine':
|
|
89
|
-
this.implementation = createByzantineConsensus(this.nodeId, {
|
|
90
|
-
threshold: this.config.threshold,
|
|
91
|
-
timeoutMs: this.config.timeoutMs,
|
|
92
|
-
maxRounds: this.config.maxRounds,
|
|
93
|
-
requireQuorum: this.config.requireQuorum,
|
|
94
|
-
});
|
|
95
|
-
break;
|
|
96
|
-
|
|
97
|
-
case 'gossip':
|
|
98
|
-
this.implementation = createGossipConsensus(this.nodeId, {
|
|
99
|
-
threshold: this.config.threshold,
|
|
100
|
-
timeoutMs: this.config.timeoutMs,
|
|
101
|
-
maxRounds: this.config.maxRounds,
|
|
102
|
-
requireQuorum: this.config.requireQuorum,
|
|
103
|
-
});
|
|
104
|
-
break;
|
|
105
|
-
|
|
106
|
-
case 'paxos':
|
|
107
|
-
// Fall back to Raft for Paxos (similar guarantees)
|
|
108
|
-
this.implementation = createRaftConsensus(this.nodeId, {
|
|
109
|
-
threshold: this.config.threshold,
|
|
110
|
-
timeoutMs: this.config.timeoutMs,
|
|
111
|
-
maxRounds: this.config.maxRounds,
|
|
112
|
-
requireQuorum: this.config.requireQuorum,
|
|
113
|
-
});
|
|
114
|
-
break;
|
|
115
|
-
|
|
116
|
-
default:
|
|
117
|
-
throw new Error(`Unknown consensus algorithm: ${this.config.algorithm}`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
await this.implementation.initialize();
|
|
121
|
-
|
|
122
|
-
// Forward events
|
|
123
|
-
this.implementation.on('consensus.achieved', (data) => {
|
|
124
|
-
this.emit('consensus.achieved', data);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
this.implementation.on('leader.elected', (data) => {
|
|
128
|
-
this.emit('leader.elected', data);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
this.emit('initialized', {
|
|
132
|
-
nodeId: this.nodeId,
|
|
133
|
-
algorithm: this.config.algorithm
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async shutdown(): Promise<void> {
|
|
138
|
-
if (this.implementation) {
|
|
139
|
-
await this.implementation.shutdown();
|
|
140
|
-
}
|
|
141
|
-
this.emit('shutdown');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
addNode(nodeId: string, options?: { isPrimary?: boolean }): void {
|
|
145
|
-
if (!this.implementation) {
|
|
146
|
-
throw new Error('Consensus engine not initialized');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (this.implementation instanceof RaftConsensus) {
|
|
150
|
-
this.implementation.addPeer(nodeId);
|
|
151
|
-
} else if (this.implementation instanceof ByzantineConsensus) {
|
|
152
|
-
this.implementation.addNode(nodeId, options?.isPrimary);
|
|
153
|
-
} else if (this.implementation instanceof GossipConsensus) {
|
|
154
|
-
this.implementation.addNode(nodeId);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
removeNode(nodeId: string): void {
|
|
159
|
-
if (!this.implementation) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (this.implementation instanceof RaftConsensus) {
|
|
164
|
-
this.implementation.removePeer(nodeId);
|
|
165
|
-
} else if (this.implementation instanceof ByzantineConsensus) {
|
|
166
|
-
this.implementation.removeNode(nodeId);
|
|
167
|
-
} else if (this.implementation instanceof GossipConsensus) {
|
|
168
|
-
this.implementation.removeNode(nodeId);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
async propose(value: unknown, proposerId?: string): Promise<ConsensusProposal> {
|
|
173
|
-
if (!this.implementation) {
|
|
174
|
-
throw new Error('Consensus engine not initialized');
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const proposal = await this.implementation.propose(value);
|
|
178
|
-
this.proposals.set(proposal.id, proposal);
|
|
179
|
-
return proposal;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async vote(proposalId: string, vote: ConsensusVote): Promise<void> {
|
|
183
|
-
if (!this.implementation) {
|
|
184
|
-
throw new Error('Consensus engine not initialized');
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
await this.implementation.vote(proposalId, vote);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
getProposal(proposalId: string): ConsensusProposal | undefined {
|
|
191
|
-
return this.proposals.get(proposalId);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async awaitConsensus(proposalId: string): Promise<ConsensusResult> {
|
|
195
|
-
if (!this.implementation) {
|
|
196
|
-
throw new Error('Consensus engine not initialized');
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return this.implementation.awaitConsensus(proposalId);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
getActiveProposals(): ConsensusProposal[] {
|
|
203
|
-
return Array.from(this.proposals.values()).filter(
|
|
204
|
-
p => p.status === 'pending'
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Algorithm-specific queries
|
|
209
|
-
isLeader(): boolean {
|
|
210
|
-
if (this.implementation instanceof RaftConsensus) {
|
|
211
|
-
return this.implementation.isLeader();
|
|
212
|
-
}
|
|
213
|
-
if (this.implementation instanceof ByzantineConsensus) {
|
|
214
|
-
return this.implementation.isPrimary();
|
|
215
|
-
}
|
|
216
|
-
return false; // Gossip has no leader
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
getLeaderId(): string | undefined {
|
|
220
|
-
if (this.implementation instanceof RaftConsensus) {
|
|
221
|
-
return this.implementation.getLeaderId();
|
|
222
|
-
}
|
|
223
|
-
return undefined;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
getAlgorithm(): ConsensusAlgorithm {
|
|
227
|
-
return this.config.algorithm;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
getConfig(): ConsensusConfig {
|
|
231
|
-
return { ...this.config };
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Metrics
|
|
235
|
-
getStats(): {
|
|
236
|
-
algorithm: ConsensusAlgorithm;
|
|
237
|
-
totalProposals: number;
|
|
238
|
-
pendingProposals: number;
|
|
239
|
-
acceptedProposals: number;
|
|
240
|
-
rejectedProposals: number;
|
|
241
|
-
expiredProposals: number;
|
|
242
|
-
} {
|
|
243
|
-
const proposals = Array.from(this.proposals.values());
|
|
244
|
-
|
|
245
|
-
return {
|
|
246
|
-
algorithm: this.config.algorithm,
|
|
247
|
-
totalProposals: proposals.length,
|
|
248
|
-
pendingProposals: proposals.filter(p => p.status === 'pending').length,
|
|
249
|
-
acceptedProposals: proposals.filter(p => p.status === 'accepted').length,
|
|
250
|
-
rejectedProposals: proposals.filter(p => p.status === 'rejected').length,
|
|
251
|
-
expiredProposals: proposals.filter(p => p.status === 'expired').length,
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Factory function
|
|
257
|
-
export function createConsensusEngine(
|
|
258
|
-
nodeId: string,
|
|
259
|
-
algorithm: ConsensusAlgorithm = 'raft',
|
|
260
|
-
config?: Partial<ConsensusConfig>
|
|
261
|
-
): ConsensusEngine {
|
|
262
|
-
return new ConsensusEngine(nodeId, { ...config, algorithm });
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Helper to select optimal algorithm based on requirements
|
|
266
|
-
export function selectOptimalAlgorithm(requirements: {
|
|
267
|
-
faultTolerance: 'crash' | 'byzantine';
|
|
268
|
-
consistency: 'strong' | 'eventual';
|
|
269
|
-
networkScale: 'small' | 'medium' | 'large';
|
|
270
|
-
latencyPriority: 'low' | 'medium' | 'high';
|
|
271
|
-
}): ConsensusAlgorithm {
|
|
272
|
-
const { faultTolerance, consistency, networkScale, latencyPriority } = requirements;
|
|
273
|
-
|
|
274
|
-
// Byzantine fault tolerance required
|
|
275
|
-
if (faultTolerance === 'byzantine') {
|
|
276
|
-
return 'byzantine';
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Eventual consistency acceptable and large scale
|
|
280
|
-
if (consistency === 'eventual' && networkScale === 'large') {
|
|
281
|
-
return 'gossip';
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// Low latency priority with medium scale
|
|
285
|
-
if (latencyPriority === 'high' && networkScale !== 'large') {
|
|
286
|
-
return 'raft';
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Strong consistency with small/medium scale
|
|
290
|
-
if (consistency === 'strong') {
|
|
291
|
-
return 'raft';
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// Default to Raft
|
|
295
|
-
return 'raft';
|
|
296
|
-
}
|