aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-agent-registry.js
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-06-02 18:00:37 +0200
committerAgando <roduccomm@gmail.com>2026-06-02 18:00:37 +0200
commitaafb0fbde5289a45f9f818a00141f80b149be283 (patch)
treed4d8f588187719c99240fbaef1940c068402b892 /modules/core/module-agent-registry.js
parent6d41e590a38c73ef60f1c04beaf8f5438f350f46 (diff)
auto: 2026-06-02_18:00 changes
Diffstat (limited to 'modules/core/module-agent-registry.js')
-rw-r--r--modules/core/module-agent-registry.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/modules/core/module-agent-registry.js b/modules/core/module-agent-registry.js
new file mode 100644
index 0000000..367f8b1
--- /dev/null
+++ b/modules/core/module-agent-registry.js
@@ -0,0 +1,79 @@
+// module-agent-registry.js — VFS-backed agent directory
+// Command: agent-list, agent-register, agent-unregister, agent-status
+class AgentRegistryModule {
+ constructor() {
+ this.commands = {};
+ this.terminal = null;
+ }
+ registerCommands() {
+ this.commands['agent-list'] = () => this.listAgents();
+ this.commands['agent-status'] = (args) => this.showAgentStatus(args[0]);
+ this.commands['agent-register'] = (args) => this.registerAgent(args);
+ this.commands['agent-unregister'] = (args) => this.unregisterAgent(args[0]);
+ }
+ init(terminal) {
+ this.terminal = terminal;
+ if (!this.terminal.fs.readFile('/agents/')) {
+ this.terminal.fs.mkdir('agents');
+ }
+ this.terminal.print('📋 Agent Registry loaded', 'info');
+ }
+ listAgents() {
+ const agents = this.terminal.fs.ls('/agents/');
+ if (!agents || agents.length === 0) {
+ return this.terminal.print('No agents registered', 'info');
+ }
+ this.terminal.print(`📋 Registered Agents (${agents.length}):`, 'header');
+ agents.forEach(a => {
+ if (a.type === 'dir' && a.name !== 'configured') {
+ const data = this.terminal.fs.readFile(`/agents/${a.name}/status.json`);
+ const s = data ? JSON.parse(data) : { status: 'unknown', capabilities: [] };
+ this.terminal.print(` ${a.name} — ${s.status} (${(s.capabilities || []).length} capabilities)`, 'info');
+ }
+ });
+ }
+ registerAgent(args) {
+ const id = args[1] || `agent-${Date.now()}`;
+ const capabilities = args.slice(2).length ? args.slice(2) : ['list_files', 'read_file'];
+ const agentDir = `agents/${id}`;
+ if (!this.terminal.fs.readFile('/' + agentDir + '/')) this.terminal.fs.mkdir(agentDir);
+ this.terminal.fs.writeFile(`${agentDir}/status.json`, JSON.stringify({
+ id,
+ status: 'idle',
+ capabilities,
+ registered: new Date().toISOString(),
+ lastHeartbeat: new Date().toISOString()
+ }));
+ this.terminal.print(`✅ Agent '${id}' registered with ${capabilities.length} capabilities`, 'success');
+ }
+ unregisterAgent(id) {
+ const ok = this.terminal.fs.deleteFile(`agents/${id}`);
+ if (ok) {
+ this.terminal.print(`✅ Agent '${id}' unregistered`, 'success');
+ } else {
+ this.terminal.print(`❌ Agent '${id}' not found`, 'error');
+ }
+ }
+ showAgentStatus(id) {
+ if (!id) return this.terminal.print('Usage: agent-status <agent-id>', 'error');
+ const data = this.terminal.fs.readFile(`/agents/${id}/status.json`);
+ if (!data) return this.terminal.print(`❌ Agent '${id}' not found`, 'error');
+ const s = JSON.parse(data);
+ this.terminal.print(`Agent: ${s.id}`, 'header');
+ this.terminal.print(` Status: ${s.status}`, 'info');
+ this.terminal.print(` Capabilities: ${(s.capabilities || []).join(', ')}`, 'info');
+ this.terminal.print(` Registered: ${s.registered}`, 'info');
+ this.terminal.print(` Last Heartbeat: ${s.lastHeartbeat}`, 'info');
+ }
+ getAgent(id) {
+ const data = this.terminal.fs.readFile(`/agents/${id}/status.json`);
+ return data ? JSON.parse(data) : null;
+ }
+ updateHeartbeat(id) {
+ const agent = this.getAgent(id);
+ if (!agent) return false;
+ agent.lastHeartbeat = new Date().toISOString();
+ this.terminal.fs.writeFile(`agents/${id}/status.json`, JSON.stringify(agent));
+ return true;
+ }
+} \ No newline at end of file