claude-flow-novice 1.5.12 → 1.5.13
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/.claude-flow-novice/dist/mcp/auth.js +347 -0
- package/.claude-flow-novice/dist/mcp/claude-code-wrapper.js +717 -0
- package/.claude-flow-novice/dist/mcp/claude-flow-tools.js +1365 -0
- package/.claude-flow-novice/dist/mcp/client.js +201 -0
- package/.claude-flow-novice/dist/mcp/index.js +192 -0
- package/.claude-flow-novice/dist/mcp/integrate-wrapper.js +85 -0
- package/.claude-flow-novice/dist/mcp/lifecycle-manager.js +348 -0
- package/.claude-flow-novice/dist/mcp/load-balancer.js +386 -0
- package/.claude-flow-novice/dist/mcp/mcp-config-manager.js +1362 -0
- package/.claude-flow-novice/dist/mcp/mcp-server-novice-simplified.js +583 -0
- package/.claude-flow-novice/dist/mcp/mcp-server-novice.js +723 -0
- package/.claude-flow-novice/dist/mcp/mcp-server-sdk.js +649 -0
- package/.claude-flow-novice/dist/mcp/mcp-server.js +2256 -0
- package/.claude-flow-novice/dist/mcp/orchestration-integration.js +800 -0
- package/.claude-flow-novice/dist/mcp/performance-monitor.js +489 -0
- package/.claude-flow-novice/dist/mcp/protocol-manager.js +376 -0
- package/.claude-flow-novice/dist/mcp/router.js +220 -0
- package/.claude-flow-novice/dist/mcp/ruv-swarm-tools.js +671 -0
- package/.claude-flow-novice/dist/mcp/ruv-swarm-wrapper.js +254 -0
- package/.claude-flow-novice/dist/mcp/server-with-wrapper.js +32 -0
- package/.claude-flow-novice/dist/mcp/server-wrapper-mode.js +26 -0
- package/.claude-flow-novice/dist/mcp/server.js +539 -0
- package/.claude-flow-novice/dist/mcp/session-manager.js +338 -0
- package/.claude-flow-novice/dist/mcp/sparc-modes.js +455 -0
- package/.claude-flow-novice/dist/mcp/swarm-tools.js +903 -0
- package/.claude-flow-novice/dist/mcp/tools.js +426 -0
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js +23 -1
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
- package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +40 -101
- package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js +36 -0
- package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/index.js +12 -0
- package/.claude-flow-novice/dist/src/validators/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js +261 -0
- package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js +204 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-integration.js +189 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-integration.js.map +1 -0
- package/package.json +2 -2
|
@@ -220,84 +220,59 @@ npx claude-flow-novice hooks session-end --generate-summary true --persist-state
|
|
|
220
220
|
|
|
221
221
|
---
|
|
222
222
|
|
|
223
|
-
## 📋
|
|
223
|
+
## 📋 AGENT COORDINATION RULES
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
**YOU MUST adapt agent types, counts, and roles to YOUR specific task requirements.**
|
|
225
|
+
### Universal Agent Spawning Pattern
|
|
227
226
|
|
|
228
|
-
**
|
|
229
|
-
- How to structure swarm initialization before agent spawning
|
|
230
|
-
- How to spawn agents concurrently in one message
|
|
231
|
-
- How to coordinate multiple agent types effectively
|
|
232
|
-
- Topology selection based on team size
|
|
233
|
-
|
|
234
|
-
**These patterns are starting points - not rigid templates. Analyze your task and customize accordingly.**
|
|
235
|
-
|
|
236
|
-
---
|
|
237
|
-
|
|
238
|
-
### Example 1: Simple Task Pattern (2-3 agents)
|
|
239
|
-
**Illustrative pattern for basic feature implementation with coordinated validation.**
|
|
227
|
+
**EVERY multi-agent task follows this structure:**
|
|
240
228
|
|
|
241
229
|
```javascript
|
|
242
230
|
[Single Message]:
|
|
243
|
-
//
|
|
231
|
+
// Step 1: ALWAYS initialize swarm first
|
|
244
232
|
mcp__claude-flow-novice__swarm_init({
|
|
245
|
-
topology: "mesh",
|
|
246
|
-
maxAgents:
|
|
247
|
-
strategy: "balanced"
|
|
233
|
+
topology: "mesh", // or "hierarchical" for 8+ agents
|
|
234
|
+
maxAgents: X, // match your actual agent count
|
|
235
|
+
strategy: "balanced" // or "adaptive" for complex tasks
|
|
248
236
|
})
|
|
249
237
|
|
|
250
|
-
// Spawn
|
|
251
|
-
Task("
|
|
252
|
-
Task("
|
|
253
|
-
Task("
|
|
238
|
+
// Step 2: Spawn ALL agents concurrently
|
|
239
|
+
Task("Agent Name", "Specific task instructions", "agent-type")
|
|
240
|
+
Task("Agent Name", "Specific task instructions", "agent-type")
|
|
241
|
+
Task("Agent Name", "Specific task instructions", "agent-type")
|
|
242
|
+
// ... continue for all agents
|
|
254
243
|
```
|
|
255
244
|
|
|
256
|
-
###
|
|
257
|
-
**Illustrative pattern for multi-component features requiring research and architecture.**
|
|
245
|
+
### Coordination Checklist
|
|
258
246
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
})
|
|
247
|
+
**Before spawning agents, ensure:**
|
|
248
|
+
- ✅ Task analyzed and complexity assessed (Simple/Medium/Complex/Enterprise)
|
|
249
|
+
- ✅ Agent count determined from requirements table
|
|
250
|
+
- ✅ Agent types selected for specific needs (not generic roles)
|
|
251
|
+
- ✅ Topology chosen: mesh (2-7) or hierarchical (8+)
|
|
252
|
+
- ✅ All agents will spawn in SINGLE message
|
|
253
|
+
- ✅ Each agent has specific, non-overlapping instructions
|
|
267
254
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
Task("Tester", "Create unit, integration, and E2E tests", "tester")
|
|
273
|
-
Task("Security Reviewer", "Perform security audit", "security-specialist")
|
|
274
|
-
Task("Reviewer", "Final quality review", "reviewer")
|
|
275
|
-
```
|
|
255
|
+
**During execution:**
|
|
256
|
+
- ✅ Agents coordinate through SwarmMemory
|
|
257
|
+
- ✅ Self-validation runs before consensus
|
|
258
|
+
- ✅ Each agent runs Post-edit hooks execute after file changes
|
|
276
259
|
|
|
277
|
-
|
|
278
|
-
|
|
260
|
+
**After completion:**
|
|
261
|
+
- ✅ Consensus validation achieved (≥90% agreement)
|
|
262
|
+
- ✅ Results stored in memory
|
|
263
|
+
- ✅ Next steps provided with claude code continuing to the next documented phase or next steps provided to user if no todos left
|
|
279
264
|
|
|
280
|
-
|
|
281
|
-
[Single Message]:
|
|
282
|
-
// Initialize hierarchical swarm for larger teams
|
|
283
|
-
mcp__claude-flow-novice__swarm_init({
|
|
284
|
-
topology: "hierarchical",
|
|
285
|
-
maxAgents: 12,
|
|
286
|
-
strategy: "adaptive"
|
|
287
|
-
})
|
|
265
|
+
### Agent Selection Guide
|
|
288
266
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
Task("API Documenter", "API documentation", "api-docs")
|
|
299
|
-
Task("Reviewer", "Final quality gate", "reviewer")
|
|
300
|
-
```
|
|
267
|
+
**Core Development**: coder, tester, reviewer
|
|
268
|
+
**Backend**: backend-dev, api-docs, system-architect
|
|
269
|
+
**Frontend**: coder (specialized), mobile-dev
|
|
270
|
+
**Quality**: tester, reviewer, security-specialist, perf-analyzer
|
|
271
|
+
**Planning**: researcher, planner, architect
|
|
272
|
+
**Operations**: devops-engineer, cicd-engineer
|
|
273
|
+
**Documentation**: api-docs, researcher
|
|
274
|
+
|
|
275
|
+
**Select agents based on actual task needs, not predefined patterns.**
|
|
301
276
|
|
|
302
277
|
---
|
|
303
278
|
|
|
@@ -398,7 +373,7 @@ claude mcp add claude-flow-novice npx claude-flow-novice mcp start
|
|
|
398
373
|
- **PASS** →
|
|
399
374
|
1. Store results in SwarmMemory
|
|
400
375
|
2. Update documentation
|
|
401
|
-
3.
|
|
376
|
+
3. Update todos and move to next task
|
|
402
377
|
|
|
403
378
|
- **FAIL** →
|
|
404
379
|
1. Round counter++
|
|
@@ -408,7 +383,7 @@ claude mcp add claude-flow-novice npx claude-flow-novice mcp start
|
|
|
408
383
|
### 🚨 ENFORCEMENT CHECKPOINTS
|
|
409
384
|
|
|
410
385
|
**MANDATORY before proceeding:**
|
|
411
|
-
1. ✅ Agents spawned
|
|
386
|
+
1. ✅ Agents spawned
|
|
412
387
|
2. ✅ Each file edit followed by enhanced post-edit hook
|
|
413
388
|
3. ✅ Self-validation confidence scores recorded
|
|
414
389
|
4. ✅ Consensus swarm spawned for verification
|
|
@@ -425,39 +400,3 @@ claude mcp add claude-flow-novice npx claude-flow-novice mcp start
|
|
|
425
400
|
2. **📊 Validation results**: Confidence scores, test coverage, consensus approval
|
|
426
401
|
3. **🔍 Identified issues**: Any technical debt, warnings, or concerns discovered
|
|
427
402
|
4. **💡 Recommended next steps**: Prioritized suggestions for logical continuation
|
|
428
|
-
|
|
429
|
-
### Next Steps Template
|
|
430
|
-
|
|
431
|
-
```markdown
|
|
432
|
-
## Task Completion Summary
|
|
433
|
-
|
|
434
|
-
**✅ Completed**: [What was delivered]
|
|
435
|
-
**📊 Validation**:
|
|
436
|
-
- Confidence: X%
|
|
437
|
-
- Coverage: Y%
|
|
438
|
-
- Consensus: Z%
|
|
439
|
-
|
|
440
|
-
**⚠️ Identified Concerns**:
|
|
441
|
-
- [Issue 1] - Severity: [High/Medium/Low]
|
|
442
|
-
- [Issue 2] - Severity: [High/Medium/Low]
|
|
443
|
-
|
|
444
|
-
**💡 Recommended Next Steps** (in priority order):
|
|
445
|
-
|
|
446
|
-
1. **[High Priority]**: [Action item]
|
|
447
|
-
- Why: [Business/technical rationale]
|
|
448
|
-
- Effort: [Estimated time/complexity]
|
|
449
|
-
|
|
450
|
-
2. **[Medium Priority]**: [Action item]
|
|
451
|
-
- Why: [Value proposition]
|
|
452
|
-
- Effort: [Estimated time/complexity]
|
|
453
|
-
|
|
454
|
-
3. **[Low Priority]**: [Enhancement opportunity]
|
|
455
|
-
- Why: [Long-term benefit]
|
|
456
|
-
- Effort: [Estimated time/complexity]
|
|
457
|
-
|
|
458
|
-
**🤔 Questions for User**:
|
|
459
|
-
- [Decision point requiring clarification]?
|
|
460
|
-
- [Alternative approach consideration]?
|
|
461
|
-
```
|
|
462
|
-
|
|
463
|
-
**Rationale**: Proactive next steps ensure continuous progress, prevent workflow dead-ends, and help users understand logical task progression without requiring them to determine next actions.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swarm Coordinator Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides singleton access to the swarm coordinator instance.
|
|
5
|
+
* Used by validators and other components to check swarm status.
|
|
6
|
+
*
|
|
7
|
+
* @module coordination/swarm-coordinator-factory
|
|
8
|
+
*/ let swarmCoordinatorInstance = null;
|
|
9
|
+
/**
|
|
10
|
+
* Sets the global swarm coordinator instance
|
|
11
|
+
*
|
|
12
|
+
* @param coordinator - Swarm coordinator instance
|
|
13
|
+
*/ export function setSwarmCoordinator(coordinator) {
|
|
14
|
+
swarmCoordinatorInstance = coordinator;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Gets the global swarm coordinator instance
|
|
18
|
+
*
|
|
19
|
+
* @returns Swarm coordinator instance or null if not initialized
|
|
20
|
+
*/ export function getSwarmCoordinator() {
|
|
21
|
+
return swarmCoordinatorInstance;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Clears the global swarm coordinator instance
|
|
25
|
+
*/ export function clearSwarmCoordinator() {
|
|
26
|
+
swarmCoordinatorInstance = null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Checks if swarm coordinator is initialized
|
|
30
|
+
*
|
|
31
|
+
* @returns true if coordinator is initialized
|
|
32
|
+
*/ export function hasSwarmCoordinator() {
|
|
33
|
+
return swarmCoordinatorInstance !== null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=swarm-coordinator-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/coordination/swarm-coordinator-factory.ts"],"names":["swarmCoordinatorInstance","setSwarmCoordinator","coordinator","getSwarmCoordinator","clearSwarmCoordinator","hasSwarmCoordinator"],"mappings":"AAAA;;;;;;;CAOC,GAID,IAAIA,2BAAoD;AAExD;;;;CAIC,GACD,OAAO,SAASC,oBAAoBC,WAA6B;IAC/DF,2BAA2BE;AAC7B;AAEA;;;;CAIC,GACD,OAAO,SAASC;IACd,OAAOH;AACT;AAEA;;CAEC,GACD,OAAO,SAASI;IACdJ,2BAA2B;AAC7B;AAEA;;;;CAIC,GACD,OAAO,SAASK;IACd,OAAOL,6BAA6B;AACtC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validators Module
|
|
3
|
+
*
|
|
4
|
+
* Provides validation functionality for enforcing best practices and detecting anti-patterns.
|
|
5
|
+
*
|
|
6
|
+
* @module validators
|
|
7
|
+
*/ // TodoWrite Batching Validator
|
|
8
|
+
export { TodoWriteValidator, getGlobalValidator, resetGlobalValidator } from './todowrite-batching-validator';
|
|
9
|
+
// TodoWrite Integration
|
|
10
|
+
export { isValidationEnabled, getIntegrationConfig, validateTodoWrite, parseValidationFlags, displayValidationHelp, todoWriteWithValidation, createValidationMiddleware, getValidationStatus } from './todowrite-integration';
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/validators/index.ts"],"names":["TodoWriteValidator","getGlobalValidator","resetGlobalValidator","isValidationEnabled","getIntegrationConfig","validateTodoWrite","parseValidationFlags","displayValidationHelp","todoWriteWithValidation","createValidationMiddleware","getValidationStatus"],"mappings":"AAAA;;;;;;CAMC,GAED,+BAA+B;AAC/B,SACEA,kBAAkB,EAClBC,kBAAkB,EAClBC,oBAAoB,QAKf,iCAAiC;AAExC,wBAAwB;AACxB,SACEC,mBAAmB,EACnBC,oBAAoB,EACpBC,iBAAiB,EACjBC,oBAAoB,EACpBC,qBAAqB,EACrBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,mBAAmB,QAEd,0BAA0B"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swarm Initialization Validator
|
|
3
|
+
*
|
|
4
|
+
* Validates that swarm initialization is performed before spawning multiple agents.
|
|
5
|
+
* Ensures proper coordination and prevents inconsistent implementations across agents.
|
|
6
|
+
*
|
|
7
|
+
* @module validators/swarm-init-validator
|
|
8
|
+
*/ import { Logger } from '../core/logger.js';
|
|
9
|
+
const DEFAULT_CONFIG = {
|
|
10
|
+
requireSwarmForMultiAgent: true,
|
|
11
|
+
minAgentsRequiringSwarm: 2,
|
|
12
|
+
meshTopologyMaxAgents: 7,
|
|
13
|
+
hierarchicalTopologyMinAgents: 8
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Validates swarm initialization before agent spawning
|
|
17
|
+
*
|
|
18
|
+
* @param agentCount - Number of agents to spawn
|
|
19
|
+
* @param swarmStatus - Current swarm status (optional, will check environment if not provided)
|
|
20
|
+
* @param config - Validator configuration
|
|
21
|
+
* @returns Validation result with error messages and suggestions
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const result = await validateSwarmInit(3);
|
|
26
|
+
* if (!result.valid) {
|
|
27
|
+
* console.error(result.error);
|
|
28
|
+
* console.log(result.suggestion);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/ export async function validateSwarmInit(agentCount, swarmStatus, config = {}) {
|
|
32
|
+
const logger = new Logger('SwarmInitValidator');
|
|
33
|
+
const cfg = {
|
|
34
|
+
...DEFAULT_CONFIG,
|
|
35
|
+
...config
|
|
36
|
+
};
|
|
37
|
+
// Single agent spawning doesn't require swarm
|
|
38
|
+
if (agentCount < cfg.minAgentsRequiringSwarm) {
|
|
39
|
+
return {
|
|
40
|
+
valid: true
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Check if swarm is required for this agent count
|
|
44
|
+
if (!cfg.requireSwarmForMultiAgent) {
|
|
45
|
+
logger.warn('Swarm validation is disabled in configuration');
|
|
46
|
+
return {
|
|
47
|
+
valid: true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Get swarm status
|
|
51
|
+
const status = swarmStatus || await getSwarmStatus();
|
|
52
|
+
// Validate swarm is initialized
|
|
53
|
+
if (!status.initialized) {
|
|
54
|
+
const topology = agentCount <= cfg.meshTopologyMaxAgents ? 'mesh' : 'hierarchical';
|
|
55
|
+
return {
|
|
56
|
+
valid: false,
|
|
57
|
+
error: createErrorMessage(agentCount),
|
|
58
|
+
suggestion: createSuggestion(agentCount, topology),
|
|
59
|
+
topology,
|
|
60
|
+
maxAgents: agentCount
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// Validate topology matches agent count
|
|
64
|
+
const topologyValidation = validateTopology(agentCount, status, cfg);
|
|
65
|
+
if (!topologyValidation.valid) {
|
|
66
|
+
return topologyValidation;
|
|
67
|
+
}
|
|
68
|
+
// Validate max agents capacity
|
|
69
|
+
if (status.maxAgents && agentCount > status.maxAgents) {
|
|
70
|
+
return {
|
|
71
|
+
valid: false,
|
|
72
|
+
error: `Cannot spawn ${agentCount} agents. Swarm configured for maximum ${status.maxAgents} agents.`,
|
|
73
|
+
suggestion: `Reinitialize swarm with increased maxAgents:\n npx claude-flow-novice swarm init --topology ${status.topology} --max-agents ${agentCount}`
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
logger.info(`Swarm validation passed for ${agentCount} agents`);
|
|
77
|
+
return {
|
|
78
|
+
valid: true
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Validates that topology matches agent count requirements
|
|
83
|
+
*/ function validateTopology(agentCount, status, config) {
|
|
84
|
+
const expectedTopology = agentCount <= config.meshTopologyMaxAgents ? 'mesh' : 'hierarchical';
|
|
85
|
+
if (status.topology && status.topology !== expectedTopology) {
|
|
86
|
+
return {
|
|
87
|
+
valid: false,
|
|
88
|
+
error: `Topology mismatch: ${agentCount} agents require '${expectedTopology}' topology, but swarm is using '${status.topology}'.`,
|
|
89
|
+
suggestion: `Reinitialize swarm with correct topology:\n npx claude-flow-novice swarm init --topology ${expectedTopology} --max-agents ${agentCount}`,
|
|
90
|
+
topology: expectedTopology,
|
|
91
|
+
maxAgents: agentCount
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
valid: true
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates error message for missing swarm initialization
|
|
100
|
+
*/ function createErrorMessage(agentCount) {
|
|
101
|
+
return `
|
|
102
|
+
❌ SWARM INITIALIZATION REQUIRED
|
|
103
|
+
|
|
104
|
+
You are attempting to spawn ${agentCount} agents without initializing swarm.
|
|
105
|
+
|
|
106
|
+
Without swarm coordination:
|
|
107
|
+
• Agents work independently with no shared context
|
|
108
|
+
• Results may be inconsistent (e.g., 3 different JWT secret solutions)
|
|
109
|
+
• No consensus validation or Byzantine fault tolerance
|
|
110
|
+
• Memory coordination is disabled
|
|
111
|
+
|
|
112
|
+
This violates the mandatory coordination requirements in CLAUDE.md.
|
|
113
|
+
`.trim();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates suggestion message with fix command
|
|
117
|
+
*/ function createSuggestion(agentCount, topology) {
|
|
118
|
+
return `
|
|
119
|
+
Fix:
|
|
120
|
+
1. Initialize swarm first:
|
|
121
|
+
npx claude-flow-novice swarm init --topology ${topology} --max-agents ${agentCount}
|
|
122
|
+
|
|
123
|
+
2. Then spawn agents:
|
|
124
|
+
[Your agent spawning command]
|
|
125
|
+
|
|
126
|
+
Topology Selection:
|
|
127
|
+
• mesh: 2-7 agents (peer-to-peer coordination)
|
|
128
|
+
• hierarchical: 8+ agents (coordinator-led structure)
|
|
129
|
+
|
|
130
|
+
See CLAUDE.md section "Swarm Initialization" for coordination requirements.
|
|
131
|
+
`.trim();
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Gets current swarm status from environment or MCP server
|
|
135
|
+
*/ async function getSwarmStatus() {
|
|
136
|
+
const logger = new Logger('SwarmInitValidator');
|
|
137
|
+
// Check environment variables
|
|
138
|
+
const swarmId = process.env['CLAUDE_SWARM_ID'];
|
|
139
|
+
if (!swarmId) {
|
|
140
|
+
return {
|
|
141
|
+
initialized: false
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Try to get status from MCP server via swarm coordinator
|
|
145
|
+
try {
|
|
146
|
+
// Import dynamically to avoid circular dependencies
|
|
147
|
+
const { getSwarmCoordinator } = await import('../coordination/swarm-coordinator-factory.js').catch(()=>({
|
|
148
|
+
getSwarmCoordinator: null
|
|
149
|
+
}));
|
|
150
|
+
if (getSwarmCoordinator) {
|
|
151
|
+
const coordinator = getSwarmCoordinator();
|
|
152
|
+
if (coordinator) {
|
|
153
|
+
const status = coordinator.getSwarmStatus();
|
|
154
|
+
return {
|
|
155
|
+
initialized: true,
|
|
156
|
+
swarmId,
|
|
157
|
+
activeAgents: status.agents.total,
|
|
158
|
+
maxAgents: status.agents.total
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
logger.debug('Could not get swarm status from coordinator', error);
|
|
164
|
+
}
|
|
165
|
+
// If we have a swarm ID but can't get details, assume initialized
|
|
166
|
+
return {
|
|
167
|
+
initialized: true,
|
|
168
|
+
swarmId
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Validates swarm initialization and throws error if invalid
|
|
173
|
+
*
|
|
174
|
+
* This is a convenience wrapper for validateSwarmInit that throws on validation failure.
|
|
175
|
+
* Use this in CLI commands where you want to halt execution on validation errors.
|
|
176
|
+
*
|
|
177
|
+
* @param agentCount - Number of agents to spawn
|
|
178
|
+
* @param swarmStatus - Current swarm status (optional)
|
|
179
|
+
* @param config - Validator configuration
|
|
180
|
+
* @throws Error if validation fails
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* try {
|
|
185
|
+
* await requireSwarmInit(3);
|
|
186
|
+
* // Proceed with spawning agents
|
|
187
|
+
* } catch (error) {
|
|
188
|
+
* console.error(error.message);
|
|
189
|
+
* process.exit(1);
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*/ export async function requireSwarmInit(agentCount, swarmStatus, config) {
|
|
193
|
+
const result = await validateSwarmInit(agentCount, swarmStatus, config);
|
|
194
|
+
if (!result.valid) {
|
|
195
|
+
const errorMessage = `${result.error}\n\n${result.suggestion}`;
|
|
196
|
+
throw new Error(errorMessage);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Gets recommended topology for agent count
|
|
201
|
+
*
|
|
202
|
+
* @param agentCount - Number of agents
|
|
203
|
+
* @param config - Validator configuration
|
|
204
|
+
* @returns Recommended topology
|
|
205
|
+
*/ export function getRecommendedTopology(agentCount, config = {}) {
|
|
206
|
+
const cfg = {
|
|
207
|
+
...DEFAULT_CONFIG,
|
|
208
|
+
...config
|
|
209
|
+
};
|
|
210
|
+
return agentCount <= cfg.meshTopologyMaxAgents ? 'mesh' : 'hierarchical';
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Checks if swarm initialization is required for agent count
|
|
214
|
+
*
|
|
215
|
+
* @param agentCount - Number of agents
|
|
216
|
+
* @param config - Validator configuration
|
|
217
|
+
* @returns true if swarm initialization is required
|
|
218
|
+
*/ export function isSwarmRequired(agentCount, config = {}) {
|
|
219
|
+
const cfg = {
|
|
220
|
+
...DEFAULT_CONFIG,
|
|
221
|
+
...config
|
|
222
|
+
};
|
|
223
|
+
return cfg.requireSwarmForMultiAgent && agentCount >= cfg.minAgentsRequiringSwarm;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Validates swarm configuration before initialization
|
|
227
|
+
*
|
|
228
|
+
* @param topology - Requested topology
|
|
229
|
+
* @param maxAgents - Maximum number of agents
|
|
230
|
+
* @param config - Validator configuration
|
|
231
|
+
* @returns Validation result
|
|
232
|
+
*/ export function validateSwarmConfig(topology, maxAgents, config = {}) {
|
|
233
|
+
const cfg = {
|
|
234
|
+
...DEFAULT_CONFIG,
|
|
235
|
+
...config
|
|
236
|
+
};
|
|
237
|
+
// Validate topology matches max agents
|
|
238
|
+
const recommendedTopology = getRecommendedTopology(maxAgents, config);
|
|
239
|
+
if (topology !== recommendedTopology) {
|
|
240
|
+
return {
|
|
241
|
+
valid: false,
|
|
242
|
+
error: `Topology '${topology}' is not optimal for ${maxAgents} agents.`,
|
|
243
|
+
suggestion: `Recommended topology: '${recommendedTopology}'\n • mesh: 2-${cfg.meshTopologyMaxAgents} agents\n • hierarchical: ${cfg.hierarchicalTopologyMinAgents}+ agents`,
|
|
244
|
+
topology: recommendedTopology,
|
|
245
|
+
maxAgents
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
valid: true
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Factory for creating a swarm coordinator factory module
|
|
254
|
+
* This is a placeholder that will be replaced with actual implementation
|
|
255
|
+
*/ export const SwarmCoordinatorFactory = {
|
|
256
|
+
getSwarmCoordinator () {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=swarm-init-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/validators/swarm-init-validator.ts"],"names":["Logger","DEFAULT_CONFIG","requireSwarmForMultiAgent","minAgentsRequiringSwarm","meshTopologyMaxAgents","hierarchicalTopologyMinAgents","validateSwarmInit","agentCount","swarmStatus","config","logger","cfg","valid","warn","status","getSwarmStatus","initialized","topology","error","createErrorMessage","suggestion","createSuggestion","maxAgents","topologyValidation","validateTopology","info","expectedTopology","trim","swarmId","process","env","getSwarmCoordinator","catch","coordinator","activeAgents","agents","total","debug","requireSwarmInit","result","errorMessage","Error","getRecommendedTopology","isSwarmRequired","validateSwarmConfig","recommendedTopology","SwarmCoordinatorFactory"],"mappings":"AAAA;;;;;;;CAOC,GAED,SAASA,MAAM,QAAQ,oBAAoB;AAmC3C,MAAMC,iBAAiD;IACrDC,2BAA2B;IAC3BC,yBAAyB;IACzBC,uBAAuB;IACvBC,+BAA+B;AACjC;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,eAAeC,kBACpBC,UAAkB,EAClBC,WAAyB,EACzBC,SAA+B,CAAC,CAAC;IAEjC,MAAMC,SAAS,IAAIV,OAAO;IAC1B,MAAMW,MAAM;QAAE,GAAGV,cAAc;QAAE,GAAGQ,MAAM;IAAC;IAE3C,8CAA8C;IAC9C,IAAIF,aAAaI,IAAIR,uBAAuB,EAAE;QAC5C,OAAO;YACLS,OAAO;QACT;IACF;IAEA,kDAAkD;IAClD,IAAI,CAACD,IAAIT,yBAAyB,EAAE;QAClCQ,OAAOG,IAAI,CAAC;QACZ,OAAO;YACLD,OAAO;QACT;IACF;IAEA,mBAAmB;IACnB,MAAME,SAASN,eAAgB,MAAMO;IAErC,gCAAgC;IAChC,IAAI,CAACD,OAAOE,WAAW,EAAE;QACvB,MAAMC,WAAWV,cAAcI,IAAIP,qBAAqB,GAAG,SAAS;QAEpE,OAAO;YACLQ,OAAO;YACPM,OAAOC,mBAAmBZ;YAC1Ba,YAAYC,iBAAiBd,YAAYU;YACzCA;YACAK,WAAWf;QACb;IACF;IAEA,wCAAwC;IACxC,MAAMgB,qBAAqBC,iBAAiBjB,YAAYO,QAAQH;IAChE,IAAI,CAACY,mBAAmBX,KAAK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