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

95 lines
2.2 KiB
JavaScript

/**
* Federated Memory System
* 6-namespace persistent memory for swarm agents
*/
class FederatedMemory {
constructor(swarm) {
this.swarm = swarm;
this.namespaces = new Map();
this.defaultNamespaces = [
'coordination', 'project-context', 'patterns',
'knowledge', 'session', 'metrics'
];
this.initialize();
}
initialize() {
for (const ns of this.defaultNamespaces) {
this.namespaces.set(ns, new Map());
}
this.swarm.log('success', `Federated memory initialized: ${this.defaultNamespaces.length} namespaces`);
}
store(namespace, key, value) {
if (!this.namespaces.has(namespace)) {
this.namespaces.set(namespace, new Map());
}
this.namespaces.get(namespace).set(key, {
value,
timestamp: Date.now(),
version: 1
});
}
get(namespace, key) {
const ns = this.namespaces.get(namespace);
return ns ? ns.get(key) : null;
}
query(namespace, pattern) {
const ns = this.namespaces.get(namespace);
if (!ns) return [];
const results = [];
for (const [key, entry] of ns.entries()) {
if (key.includes(pattern)) {
results.push({ key, ...entry });
}
}
return results;
}
delete(namespace, key) {
const ns = this.namespaces.get(namespace);
if (ns) ns.delete(key);
}
clear(namespace) {
if (namespace) {
this.namespaces.get(namespace)?.clear();
} else {
for (const ns of this.namespaces.values()) ns.clear();
}
}
stats() {
const stats = {};
for (const [name, ns] of this.namespaces.entries()) {
stats[name] = ns.size;
}
return stats;
}
exportAll() {
const data = {};
for (const [name, ns] of this.namespaces.entries()) {
data[name] = Object.fromEntries(ns);
}
return data;
}
importData(data) {
for (const [name, entries] of Object.entries(data)) {
if (!this.namespaces.has(name)) {
this.namespaces.set(name, new Map());
}
for (const [key, value] of Object.entries(entries)) {
this.namespaces.get(name).set(key, value);
}
}
this.swarm.log('success', 'Memory data imported');
}
}
module.exports = FederatedMemory;