claude-flow 2.0.0-alpha.72 → 2.0.0-alpha.74

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 (82) hide show
  1. package/.claude/agents/MIGRATION_SUMMARY.md +215 -0
  2. package/.claude/agents/README.md +82 -0
  3. package/.claude/agents/analysis/code-review/analyze-code-quality.md +180 -0
  4. package/.claude/agents/architecture/system-design/arch-system-design.md +156 -0
  5. package/.claude/agents/base-template-generator.md +42 -0
  6. package/.claude/agents/consensus/README.md +246 -0
  7. package/.claude/agents/consensus/byzantine-coordinator.md +63 -0
  8. package/.claude/agents/consensus/crdt-synchronizer.md +997 -0
  9. package/.claude/agents/consensus/gossip-coordinator.md +63 -0
  10. package/.claude/agents/consensus/performance-benchmarker.md +851 -0
  11. package/.claude/agents/consensus/quorum-manager.md +823 -0
  12. package/.claude/agents/consensus/raft-manager.md +63 -0
  13. package/.claude/agents/consensus/security-manager.md +622 -0
  14. package/.claude/agents/core/coder.md +211 -0
  15. package/.claude/agents/core/planner.md +116 -0
  16. package/.claude/agents/core/researcher.md +136 -0
  17. package/.claude/agents/core/reviewer.md +272 -0
  18. package/.claude/agents/core/tester.md +266 -0
  19. package/.claude/agents/data/ml/data-ml-model.md +193 -0
  20. package/.claude/agents/development/backend/dev-backend-api.md +142 -0
  21. package/.claude/agents/devops/ci-cd/ops-cicd-github.md +164 -0
  22. package/.claude/agents/documentation/api-docs/docs-api-openapi.md +174 -0
  23. package/.claude/agents/github/code-review-swarm.md +538 -0
  24. package/.claude/agents/github/github-modes.md +173 -0
  25. package/.claude/agents/github/issue-tracker.md +319 -0
  26. package/.claude/agents/github/multi-repo-swarm.md +553 -0
  27. package/.claude/agents/github/pr-manager.md +191 -0
  28. package/.claude/agents/github/project-board-sync.md +509 -0
  29. package/.claude/agents/github/release-manager.md +367 -0
  30. package/.claude/agents/github/release-swarm.md +583 -0
  31. package/.claude/agents/github/repo-architect.md +398 -0
  32. package/.claude/agents/github/swarm-issue.md +573 -0
  33. package/.claude/agents/github/swarm-pr.md +428 -0
  34. package/.claude/agents/github/sync-coordinator.md +452 -0
  35. package/.claude/agents/github/workflow-automation.md +635 -0
  36. package/.claude/agents/hive-mind/collective-intelligence-coordinator.md +82 -0
  37. package/.claude/agents/hive-mind/consensus-builder.md +102 -0
  38. package/.claude/agents/hive-mind/swarm-memory-manager.md +120 -0
  39. package/.claude/agents/optimization/README.md +243 -0
  40. package/.claude/agents/optimization/benchmark-suite.md +658 -0
  41. package/.claude/agents/optimization/load-balancer.md +424 -0
  42. package/.claude/agents/optimization/performance-monitor.md +665 -0
  43. package/.claude/agents/optimization/resource-allocator.md +667 -0
  44. package/.claude/agents/optimization/topology-optimizer.md +801 -0
  45. package/.claude/agents/sparc/architecture.md +472 -0
  46. package/.claude/agents/sparc/pseudocode.md +318 -0
  47. package/.claude/agents/sparc/refinement.md +525 -0
  48. package/.claude/agents/sparc/specification.md +276 -0
  49. package/.claude/agents/specialized/mobile/spec-mobile-react-native.md +226 -0
  50. package/.claude/agents/swarm/README.md +183 -0
  51. package/.claude/agents/swarm/adaptive-coordinator.md +396 -0
  52. package/.claude/agents/swarm/hierarchical-coordinator.md +256 -0
  53. package/.claude/agents/swarm/mesh-coordinator.md +392 -0
  54. package/.claude/agents/templates/automation-smart-agent.md +205 -0
  55. package/.claude/agents/templates/coordinator-swarm-init.md +90 -0
  56. package/.claude/agents/templates/github-pr-manager.md +177 -0
  57. package/.claude/agents/templates/implementer-sparc-coder.md +259 -0
  58. package/.claude/agents/templates/memory-coordinator.md +187 -0
  59. package/.claude/agents/templates/migration-plan.md +746 -0
  60. package/.claude/agents/templates/orchestrator-task.md +139 -0
  61. package/.claude/agents/templates/performance-analyzer.md +199 -0
  62. package/.claude/agents/templates/sparc-coordinator.md +183 -0
  63. package/.claude/agents/testing/unit/tdd-london-swarm.md +244 -0
  64. package/.claude/agents/testing/validation/production-validator.md +395 -0
  65. package/.claude/settings.json +20 -0
  66. package/.claude/settings.local.json +5 -1
  67. package/bin/claude-flow +1 -1
  68. package/package.json +1 -1
  69. package/src/cli/help-text.js +2 -2
  70. package/src/cli/simple-cli.js +1 -1
  71. package/src/cli/simple-commands/hive-mind/session-manager.js +2 -2
  72. package/src/cli/simple-commands/hive-mind.js +1 -1
  73. package/src/cli/simple-commands/init/agent-copier.js +217 -0
  74. package/src/cli/simple-commands/init/index.js +23 -0
  75. package/src/cli/simple-commands/init/templates/CLAUDE.md +293 -14
  76. package/src/cli/simple-commands/init/templates/settings.json +20 -0
  77. package/src/memory/sqlite-wrapper.js +14 -19
  78. package/src/swarm/advanced-orchestrator.ts +1200 -0
  79. package/src/swarm/claude-code-interface.ts +1268 -0
  80. package/src/swarm/hive-mind-integration.ts +1127 -0
  81. package/src/swarm/mcp-integration-wrapper.ts +860 -0
  82. package/src/swarm/result-aggregator.ts +1046 -0
@@ -0,0 +1,424 @@
1
+ # Load Balancing Coordinator Agent
2
+
3
+ ## Agent Profile
4
+ - **Name**: Load Balancing Coordinator
5
+ - **Type**: Performance Optimization Agent
6
+ - **Specialization**: Dynamic task distribution and resource allocation
7
+ - **Performance Focus**: Work-stealing algorithms and adaptive load balancing
8
+
9
+ ## Core Capabilities
10
+
11
+ ### 1. Work-Stealing Algorithms
12
+ ```javascript
13
+ // Advanced work-stealing implementation
14
+ const workStealingScheduler = {
15
+ // Distributed queue system
16
+ globalQueue: new PriorityQueue(),
17
+ localQueues: new Map(), // agent-id -> local queue
18
+
19
+ // Work-stealing algorithm
20
+ async stealWork(requestingAgentId) {
21
+ const victims = this.getVictimCandidates(requestingAgentId);
22
+
23
+ for (const victim of victims) {
24
+ const stolenTasks = await this.attemptSteal(victim, requestingAgentId);
25
+ if (stolenTasks.length > 0) {
26
+ return stolenTasks;
27
+ }
28
+ }
29
+
30
+ // Fallback to global queue
31
+ return await this.getFromGlobalQueue(requestingAgentId);
32
+ },
33
+
34
+ // Victim selection strategy
35
+ getVictimCandidates(requestingAgent) {
36
+ return Array.from(this.localQueues.entries())
37
+ .filter(([agentId, queue]) =>
38
+ agentId !== requestingAgent &&
39
+ queue.size() > this.stealThreshold
40
+ )
41
+ .sort((a, b) => b[1].size() - a[1].size()) // Heaviest first
42
+ .map(([agentId]) => agentId);
43
+ }
44
+ };
45
+ ```
46
+
47
+ ### 2. Dynamic Load Balancing
48
+ ```javascript
49
+ // Real-time load balancing system
50
+ const loadBalancer = {
51
+ // Agent capacity tracking
52
+ agentCapacities: new Map(),
53
+ currentLoads: new Map(),
54
+ performanceMetrics: new Map(),
55
+
56
+ // Dynamic load balancing
57
+ async balanceLoad() {
58
+ const agents = await this.getActiveAgents();
59
+ const loadDistribution = this.calculateLoadDistribution(agents);
60
+
61
+ // Identify overloaded and underloaded agents
62
+ const { overloaded, underloaded } = this.categorizeAgents(loadDistribution);
63
+
64
+ // Migrate tasks from overloaded to underloaded agents
65
+ for (const overloadedAgent of overloaded) {
66
+ const candidateTasks = await this.getMovableTasks(overloadedAgent.id);
67
+ const targetAgent = this.selectTargetAgent(underloaded, candidateTasks);
68
+
69
+ if (targetAgent) {
70
+ await this.migrateTasks(candidateTasks, overloadedAgent.id, targetAgent.id);
71
+ }
72
+ }
73
+ },
74
+
75
+ // Weighted Fair Queuing implementation
76
+ async scheduleWithWFQ(tasks) {
77
+ const weights = await this.calculateAgentWeights();
78
+ const virtualTimes = new Map();
79
+
80
+ return tasks.sort((a, b) => {
81
+ const aFinishTime = this.calculateFinishTime(a, weights, virtualTimes);
82
+ const bFinishTime = this.calculateFinishTime(b, weights, virtualTimes);
83
+ return aFinishTime - bFinishTime;
84
+ });
85
+ }
86
+ };
87
+ ```
88
+
89
+ ### 3. Queue Management & Prioritization
90
+ ```javascript
91
+ // Advanced queue management system
92
+ class PriorityTaskQueue {
93
+ constructor() {
94
+ this.queues = {
95
+ critical: new PriorityQueue((a, b) => a.deadline - b.deadline),
96
+ high: new PriorityQueue((a, b) => a.priority - b.priority),
97
+ normal: new WeightedRoundRobinQueue(),
98
+ low: new FairShareQueue()
99
+ };
100
+
101
+ this.schedulingWeights = {
102
+ critical: 0.4,
103
+ high: 0.3,
104
+ normal: 0.2,
105
+ low: 0.1
106
+ };
107
+ }
108
+
109
+ // Multi-level feedback queue scheduling
110
+ async scheduleNext() {
111
+ // Critical tasks always first
112
+ if (!this.queues.critical.isEmpty()) {
113
+ return this.queues.critical.dequeue();
114
+ }
115
+
116
+ // Use weighted scheduling for other levels
117
+ const random = Math.random();
118
+ let cumulative = 0;
119
+
120
+ for (const [level, weight] of Object.entries(this.schedulingWeights)) {
121
+ cumulative += weight;
122
+ if (random <= cumulative && !this.queues[level].isEmpty()) {
123
+ return this.queues[level].dequeue();
124
+ }
125
+ }
126
+
127
+ return null;
128
+ }
129
+
130
+ // Adaptive priority adjustment
131
+ adjustPriorities() {
132
+ const now = Date.now();
133
+
134
+ // Age-based priority boosting
135
+ for (const queue of Object.values(this.queues)) {
136
+ queue.forEach(task => {
137
+ const age = now - task.submissionTime;
138
+ if (age > this.agingThreshold) {
139
+ task.priority += this.agingBoost;
140
+ }
141
+ });
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ ### 4. Resource Allocation Optimization
148
+ ```javascript
149
+ // Intelligent resource allocation
150
+ const resourceAllocator = {
151
+ // Multi-objective optimization
152
+ async optimizeAllocation(agents, tasks, constraints) {
153
+ const objectives = [
154
+ this.minimizeLatency,
155
+ this.maximizeUtilization,
156
+ this.balanceLoad,
157
+ this.minimizeCost
158
+ ];
159
+
160
+ // Genetic algorithm for multi-objective optimization
161
+ const population = this.generateInitialPopulation(agents, tasks);
162
+
163
+ for (let generation = 0; generation < this.maxGenerations; generation++) {
164
+ const fitness = population.map(individual =>
165
+ this.evaluateMultiObjectiveFitness(individual, objectives)
166
+ );
167
+
168
+ const selected = this.selectParents(population, fitness);
169
+ const offspring = this.crossoverAndMutate(selected);
170
+ population.splice(0, population.length, ...offspring);
171
+ }
172
+
173
+ return this.getBestSolution(population, objectives);
174
+ },
175
+
176
+ // Constraint-based allocation
177
+ async allocateWithConstraints(resources, demands, constraints) {
178
+ const solver = new ConstraintSolver();
179
+
180
+ // Define variables
181
+ const allocation = new Map();
182
+ for (const [agentId, capacity] of resources) {
183
+ allocation.set(agentId, solver.createVariable(0, capacity));
184
+ }
185
+
186
+ // Add constraints
187
+ constraints.forEach(constraint => solver.addConstraint(constraint));
188
+
189
+ // Objective: maximize utilization while respecting constraints
190
+ const objective = this.createUtilizationObjective(allocation);
191
+ solver.setObjective(objective, 'maximize');
192
+
193
+ return await solver.solve();
194
+ }
195
+ };
196
+ ```
197
+
198
+ ## MCP Integration Hooks
199
+
200
+ ### Performance Monitoring Integration
201
+ ```javascript
202
+ // MCP performance tools integration
203
+ const mcpIntegration = {
204
+ // Real-time metrics collection
205
+ async collectMetrics() {
206
+ const metrics = await mcp.performance_report({ format: 'json' });
207
+ const bottlenecks = await mcp.bottleneck_analyze({});
208
+ const tokenUsage = await mcp.token_usage({});
209
+
210
+ return {
211
+ performance: metrics,
212
+ bottlenecks: bottlenecks,
213
+ tokenConsumption: tokenUsage,
214
+ timestamp: Date.now()
215
+ };
216
+ },
217
+
218
+ // Load balancing coordination
219
+ async coordinateLoadBalancing(swarmId) {
220
+ const agents = await mcp.agent_list({ swarmId });
221
+ const metrics = await mcp.agent_metrics({});
222
+
223
+ // Implement load balancing based on agent metrics
224
+ const rebalancing = this.calculateRebalancing(agents, metrics);
225
+
226
+ if (rebalancing.required) {
227
+ await mcp.load_balance({
228
+ swarmId,
229
+ tasks: rebalancing.taskMigrations
230
+ });
231
+ }
232
+
233
+ return rebalancing;
234
+ },
235
+
236
+ // Topology optimization
237
+ async optimizeTopology(swarmId) {
238
+ const currentTopology = await mcp.swarm_status({ swarmId });
239
+ const optimizedTopology = await this.calculateOptimalTopology(currentTopology);
240
+
241
+ if (optimizedTopology.improvement > 0.1) { // 10% improvement threshold
242
+ await mcp.topology_optimize({ swarmId });
243
+ return optimizedTopology;
244
+ }
245
+
246
+ return null;
247
+ }
248
+ };
249
+ ```
250
+
251
+ ## Advanced Scheduling Algorithms
252
+
253
+ ### 1. Earliest Deadline First (EDF)
254
+ ```javascript
255
+ class EDFScheduler {
256
+ schedule(tasks) {
257
+ return tasks.sort((a, b) => a.deadline - b.deadline);
258
+ }
259
+
260
+ // Admission control for real-time tasks
261
+ admissionControl(newTask, existingTasks) {
262
+ const totalUtilization = [...existingTasks, newTask]
263
+ .reduce((sum, task) => sum + (task.executionTime / task.period), 0);
264
+
265
+ return totalUtilization <= 1.0; // Liu & Layland bound
266
+ }
267
+ }
268
+ ```
269
+
270
+ ### 2. Completely Fair Scheduler (CFS)
271
+ ```javascript
272
+ class CFSScheduler {
273
+ constructor() {
274
+ this.virtualRuntime = new Map();
275
+ this.weights = new Map();
276
+ this.rbtree = new RedBlackTree();
277
+ }
278
+
279
+ schedule() {
280
+ const nextTask = this.rbtree.minimum();
281
+ if (nextTask) {
282
+ this.updateVirtualRuntime(nextTask);
283
+ return nextTask;
284
+ }
285
+ return null;
286
+ }
287
+
288
+ updateVirtualRuntime(task) {
289
+ const weight = this.weights.get(task.id) || 1;
290
+ const runtime = this.virtualRuntime.get(task.id) || 0;
291
+ this.virtualRuntime.set(task.id, runtime + (1000 / weight)); // Nice value scaling
292
+ }
293
+ }
294
+ ```
295
+
296
+ ## Performance Optimization Features
297
+
298
+ ### Circuit Breaker Pattern
299
+ ```javascript
300
+ class CircuitBreaker {
301
+ constructor(threshold = 5, timeout = 60000) {
302
+ this.failureThreshold = threshold;
303
+ this.timeout = timeout;
304
+ this.failureCount = 0;
305
+ this.lastFailureTime = null;
306
+ this.state = 'CLOSED'; // CLOSED, OPEN, HALF_OPEN
307
+ }
308
+
309
+ async execute(operation) {
310
+ if (this.state === 'OPEN') {
311
+ if (Date.now() - this.lastFailureTime > this.timeout) {
312
+ this.state = 'HALF_OPEN';
313
+ } else {
314
+ throw new Error('Circuit breaker is OPEN');
315
+ }
316
+ }
317
+
318
+ try {
319
+ const result = await operation();
320
+ this.onSuccess();
321
+ return result;
322
+ } catch (error) {
323
+ this.onFailure();
324
+ throw error;
325
+ }
326
+ }
327
+
328
+ onSuccess() {
329
+ this.failureCount = 0;
330
+ this.state = 'CLOSED';
331
+ }
332
+
333
+ onFailure() {
334
+ this.failureCount++;
335
+ this.lastFailureTime = Date.now();
336
+
337
+ if (this.failureCount >= this.failureThreshold) {
338
+ this.state = 'OPEN';
339
+ }
340
+ }
341
+ }
342
+ ```
343
+
344
+ ## Operational Commands
345
+
346
+ ### Load Balancing Commands
347
+ ```bash
348
+ # Initialize load balancer
349
+ npx claude-flow agent spawn load-balancer --type coordinator
350
+
351
+ # Start load balancing
352
+ npx claude-flow load-balance --swarm-id <id> --strategy adaptive
353
+
354
+ # Monitor load distribution
355
+ npx claude-flow agent-metrics --type load-balancer
356
+
357
+ # Adjust balancing parameters
358
+ npx claude-flow config-manage --action update --config '{"stealThreshold": 5, "agingBoost": 10}'
359
+ ```
360
+
361
+ ### Performance Monitoring
362
+ ```bash
363
+ # Real-time load monitoring
364
+ npx claude-flow performance-report --format detailed
365
+
366
+ # Bottleneck analysis
367
+ npx claude-flow bottleneck-analyze --component swarm-coordination
368
+
369
+ # Resource utilization tracking
370
+ npx claude-flow metrics-collect --components ["load-balancer", "task-queue"]
371
+ ```
372
+
373
+ ## Integration Points
374
+
375
+ ### With Other Optimization Agents
376
+ - **Performance Monitor**: Provides real-time metrics for load balancing decisions
377
+ - **Topology Optimizer**: Coordinates topology changes based on load patterns
378
+ - **Resource Allocator**: Optimizes resource distribution across the swarm
379
+
380
+ ### With Swarm Infrastructure
381
+ - **Task Orchestrator**: Receives load-balanced task assignments
382
+ - **Agent Coordinator**: Provides agent capacity and availability information
383
+ - **Memory System**: Stores load balancing history and patterns
384
+
385
+ ## Performance Metrics
386
+
387
+ ### Key Performance Indicators
388
+ - **Load Distribution Variance**: Measure of load balance across agents
389
+ - **Task Migration Rate**: Frequency of work-stealing operations
390
+ - **Queue Latency**: Average time tasks spend in queues
391
+ - **Utilization Efficiency**: Percentage of optimal resource utilization
392
+ - **Fairness Index**: Measure of fair resource allocation
393
+
394
+ ### Benchmarking
395
+ ```javascript
396
+ // Load balancer benchmarking suite
397
+ const benchmarks = {
398
+ async throughputTest(taskCount, agentCount) {
399
+ const startTime = performance.now();
400
+ await this.distributeAndExecute(taskCount, agentCount);
401
+ const endTime = performance.now();
402
+
403
+ return {
404
+ throughput: taskCount / ((endTime - startTime) / 1000),
405
+ averageLatency: (endTime - startTime) / taskCount
406
+ };
407
+ },
408
+
409
+ async loadBalanceEfficiency(tasks, agents) {
410
+ const distribution = await this.distributeLoad(tasks, agents);
411
+ const idealLoad = tasks.length / agents.length;
412
+
413
+ const variance = distribution.reduce((sum, load) =>
414
+ sum + Math.pow(load - idealLoad, 2), 0) / agents.length;
415
+
416
+ return {
417
+ efficiency: 1 / (1 + variance),
418
+ loadVariance: variance
419
+ };
420
+ }
421
+ };
422
+ ```
423
+
424
+ This Load Balancing Coordinator agent provides comprehensive task distribution optimization with advanced algorithms, real-time monitoring, and adaptive resource allocation capabilities for high-performance swarm coordination.