Files
zCode-CLI-X/.zcode/agents/swarm-utils.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

106 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Swarm Utils - Core Utilities
* Shared utilities for zCode Swarm
*/
class SwarmUtils {
constructor(configPath = '.zcode/config/coordinator.yaml') {
this.config = this.loadConfig(configPath);
this.performanceReport = {};
this.memory = new Map();
}
loadConfig(path) {
try {
const fs = require('fs');
const yaml = require('js-yaml');
const config = yaml.load(fs.readFileSync(path, 'utf8'));
return config;
} catch (err) {
console.error('❌ Error loading config:', err.message);
process.exit(1);
}
}
// Monitor swarm performance
monitorSwarm() {
return setInterval(() => {
this.collectMetrics();
}, this.config.performance?.metrics?.collection_interval || 60000);
}
collectMetrics() {
// Simulate metrics collection
this.performanceReport = {
timestamp: Date.now(),
agents: {
total: this.config.agents?.enabled?.length || 0,
active: Math.floor(Math.random() * 3) + 1,
idle: this.config.agents?.enabled?.length - 2
},
memory: {
used: Math.floor(Math.random() * 100) + 'MB',
total: '512MB',
usage: (Math.random() * 30 + 10).toFixed(1) + '%'
},
cpu: {
usage: (Math.random() * 40 + 20).toFixed(1) + '%'
},
coordination: {
mode: this.config.coordination?.mode || 'hierarchical'
}
};
}
getPerformanceReport() {
return this.performanceReport;
}
// Memory management
store(namespace, key, value) {
if (!this.memory.has(namespace)) {
this.memory.set(namespace, new Map());
}
this.memory.get(namespace).set(key, {
value,
timestamp: Date.now()
});
}
get(namespace, key) {
if (this.memory.has(namespace)) {
return this.memory.get(namespace).get(key);
}
return null;
}
// Log message with type
log(type, message, data = null) {
const timestamp = new Date().toISOString();
const logEntry = { timestamp, type, message, data };
switch (type) {
case 'info':
console.log(` [${timestamp}] ${message}`);
break;
case 'success':
console.log(`✅ [${timestamp}] ${message}`);
break;
case 'warning':
console.log(`⚠️ [${timestamp}] ${message}`);
break;
case 'error':
console.log(`❌ [${timestamp}] ${message}`);
break;
case 'debug':
console.log(`🔍 [${timestamp}] ${message}`, data || '');
break;
default:
console.log(`📝 [${timestamp}] ${message}`, data || '');
}
}
}
module.exports = SwarmUtils;