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.
This commit is contained in:
76
.zcode/agents/marketplace.cjs
Normal file
76
.zcode/agents/marketplace.cjs
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Agent Marketplace
|
||||
* Plugin-based agent discovery and installation
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
class AgentMarketplace {
|
||||
constructor() {
|
||||
this.marketplacePath = path.join(__dirname, '../../marketplace');
|
||||
this.installedPath = path.join(__dirname, '../../installed');
|
||||
this.agents = new Map();
|
||||
this.installedAgents = new Map();
|
||||
}
|
||||
|
||||
initialize() {
|
||||
if (!fs.existsSync(this.marketplacePath)) fs.mkdirSync(this.marketplacePath, { recursive: true });
|
||||
if (!fs.existsSync(this.installedPath)) fs.mkdirSync(this.installedPath, { recursive: true });
|
||||
this.loadAgents();
|
||||
this.swarm?.log?.('success', `Marketplace initialized: ${this.agents.size} available`);
|
||||
}
|
||||
|
||||
loadAgents() {
|
||||
try {
|
||||
const files = fs.readdirSync(this.marketplacePath).filter(f => f.endsWith('.json'));
|
||||
for (const file of files) {
|
||||
const data = JSON.parse(fs.readFileSync(path.join(this.marketplacePath, file), 'utf8'));
|
||||
this.agents.set(data.id, data);
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
search(query = '', capabilities = []) {
|
||||
let results = Array.from(this.agents.values());
|
||||
if (query) {
|
||||
results = results.filter(a =>
|
||||
a.name.toLowerCase().includes(query.toLowerCase()) ||
|
||||
a.description.toLowerCase().includes(query.toLowerCase())
|
||||
);
|
||||
}
|
||||
if (capabilities.length) {
|
||||
results = results.filter(a => capabilities.some(c => a.capabilities?.includes(c)));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
installAgent(agentId) {
|
||||
const agent = this.agents.get(agentId);
|
||||
if (!agent) throw new Error(`Agent not found: ${agentId}`);
|
||||
if (this.installedAgents.has(agentId)) throw new Error(`Already installed: ${agentId}`);
|
||||
|
||||
const installDir = path.join(this.installedPath, agentId);
|
||||
fs.mkdirSync(installDir, { recursive: true });
|
||||
|
||||
this.installedAgents.set(agentId, { ...agent, installedAt: Date.now() });
|
||||
fs.writeFileSync(
|
||||
path.join(this.installedPath, 'installed.json'),
|
||||
JSON.stringify(Object.fromEntries(this.installedAgents), null, 2)
|
||||
);
|
||||
return { ...agent, installedAt: Date.now() };
|
||||
}
|
||||
|
||||
uninstallAgent(agentId) {
|
||||
if (!this.installedAgents.has(agentId)) throw new Error(`Not installed: ${agentId}`);
|
||||
const dir = path.join(this.installedPath, agentId);
|
||||
if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true, force: true });
|
||||
this.installedAgents.delete(agentId);
|
||||
}
|
||||
|
||||
listAvailable() { return Array.from(this.agents.values()); }
|
||||
listInstalled() { return Array.from(this.installedAgents.values()); }
|
||||
isInstalled(agentId) { return this.installedAgents.has(agentId); }
|
||||
}
|
||||
|
||||
module.exports = AgentMarketplace;
|
||||
Reference in New Issue
Block a user