Files
zCode-CLI-X/.zcode/agents/coordinator/hierarchical.cjs
admin 68cfeb5cba feat: add zCode Swarm — multi-agent orchestration system
- 6 agent skills: code-review, performance, security, architecture, test, git
- 4 coordinator modes: hierarchical, mesh, gossip, consensus
- Federated memory system (6 namespaces)
- Neural network agent recommendation
- Agent marketplace (plugin discovery/install)
- Real-time dashboard + performance metrics
- CRDT-based sync for decentralized modes
- 22 files, ~1400 lines total

Inspired by ruflo distributed multi-agent patterns.
2026-05-06 07:59:19 +00:00

86 lines
2.0 KiB
JavaScript

/**
* Hierarchical Coordinator
* Queen-led multi-agent coordination
*/
const SwarmUtils = require('./swarm-utils.cjs');
class HierarchicalCoordinator {
constructor(swarm) {
this.swarm = swarm;
this.queen = null;
this.scouts = [];
}
initialize() {
console.log('👑 Initializing hierarchical coordinator...');
this.swarm.log('info', 'Hierarchical coordination mode activated');
}
async coordinate(task) {
this.swarm.log('info', `Processing task: ${task}`);
// Queen makes decision
const agent = await this.queenDecide(task);
// Dispatch to scouts
const result = await this.dispatchToScouts(agent, task);
return result;
}
async queenDecide(task) {
// Queen analyzes task and selects optimal agent
this.swarm.log('debug', 'Queen analyzing task complexity...');
const agentType = this.selectAgentByTask(task);
this.swarm.log('success', `Queen selected: ${agentType}`);
return { agent: agentType, confidence: 0.85 };
}
selectAgentByTask(task) {
// Simple rule-based selection
const taskType = task.type || 'general';
const agentMap = {
'code-review-swarm': 'code-review-swarm',
'performance-optimizer': 'performance-optimizer',
'security-auditor': 'security-auditor',
'architecture-analyzer': 'architecture-analyzer',
'test-orchestrator': 'test-orchestrator',
'git-swarm': 'git-swarm'
};
return agentMap[taskType] || 'code-review-swarm';
}
async dispatchToScouts(agent, task) {
this.swarm.log('debug', `Dispatching to scouts: ${agent.agent}`);
// Simulate scout execution
const result = {
agent: agent.agent,
success: true,
timestamp: Date.now(),
findings: [
'Analysis completed',
'Results generated',
'Report compiled'
]
};
this.swarm.log('success', 'Task completed successfully');
return result;
}
async stopSync() {
this.swarm.log('info', 'Hierarchical coordinator stopped');
}
}
module.exports = HierarchicalCoordinator;