bus-agent 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKILL.md ADDED
@@ -0,0 +1,314 @@
1
+ # MCP CoCo — Universal Agent Communication Hub
2
+
3
+ ## Overview
4
+
5
+ MCP CoCo is an **Agent Communication Hub** — an MCP server that lets **any MCP-compatible agent** talk to any other.
6
+
7
+ ```
8
+ OpenClaw (Andul) ──┐
9
+ ├──▶ MCP CoCo (Agent Bus) ◀──▶ Claude Desktop
10
+ Hermes Agent ──────┘ Cursor
11
+ │ Any MCP agent
12
+ ├─ message_send(to, msg)
13
+ ├─ message_wait(timeout)
14
+ ├─ channel_send(channel, msg)
15
+ └─ agent_list()
16
+ ```
17
+
18
+ ## Location
19
+
20
+ ```
21
+ E:\_system\.openclaw\workspace\repos\mcp-coco\
22
+ GitHub: https://github.com/ClewCode/mcp-coco
23
+ ```
24
+
25
+ ## Running
26
+
27
+ ```bash
28
+ # Stdio mode (via mcporter)
29
+ mcporter add coco --stdio "node E:\_system\.openclaw\workspace\repos\mcp-coco\index.js"
30
+
31
+ # Daemon mode
32
+ node E:\_system\.openclaw\workspace\repos\mcp-coco\index.js --daemon
33
+
34
+ # Health check
35
+ node E:\_system\.openclaw\workspace\repos\mcp-coco\index.js --health
36
+ ```
37
+
38
+ ## Tools (43 total)
39
+
40
+ ### Hermes Bridge (legacy)
41
+
42
+ | Tool | Description |
43
+ |------|-------------|
44
+ | `ask_hermes(prompt, session_key?)` | Talk to Hermes Agent (multi-turn) |
45
+ | `hermes_send(target, message)` | Send via Hermes to chat platform |
46
+ | `hermes_channels(platform?)` | List Hermes channels |
47
+ | `coco_health()` | Health check (CLI + gateway) |
48
+
49
+ ### Agent Bus (new)
50
+
51
+ | Tool | Description |
52
+ |------|-------------|
53
+ | `agent_register(name, description?, metadata?)` | Register your agent on the bus |
54
+ | `agent_list(online_only?)` | List all registered agents |
55
+ | `agent_heartbeat(name)` | Ping to show online status |
56
+ | `message_send(from, to, message, metadata?)` | Send DM to another agent |
57
+ | `message_broadcast(from, message)` | Send to ALL agents |
58
+ | `message_fetch(agent_name, limit?)` | Read your inbox |
59
+ | `message_wait(agent_name, timeout_ms?)` | Long-poll for new messages (up to 60s) |
60
+ | `channel_create(channel_id, topic?, created_by?)` | Create a shared channel |
61
+ | `channel_join(channel_id, agent_name)` | Join a channel |
62
+ | `channel_send(channel_id, from, message)` | Send to channel (all members) |
63
+ | `channel_history(channel_id, limit?)` | Read channel log |
64
+
65
+ ### Memory Tools
66
+
67
+ Agent memory with TF-IDF keyword search (built-in) and optional vector search via Ollama/OpenAI.
68
+
69
+ | Tool | Description |
70
+ |------|-------------|
71
+ | `memory_store` | Store a memory. Auto-embeds if provider configured. |
72
+ | `memory_search` | Search — vector ANN with TF-IDF fallback |
73
+ | `memory_recall` | Recall by ID or key |
74
+ | `memory_list` | List with namespace filter, pagination |
75
+ | `memory_forget` | Delete by ID |
76
+ | `memory_stats` | Count, namespaces, vectors, size |
77
+ | `memory_archive` | Move old inbox messages into memory |
78
+ | `memory_clear` | Clear all or by namespace |
79
+ | `memory_configure` | Set provider (keyword/ollama/openai/custom) |
80
+ | `memory_rebuild` | Regenerate vector embeddings |
81
+
82
+ **Dual-mode search:** Vector (cosine similarity) → TF-IDF fallback. Stored in `.bus/memory/{agent}/` as JSONL + vectors.json.
83
+
84
+ ```bash
85
+ coco memory store andul "content" --key k --namespace preferences
86
+ coco memory search andul "query" --limit 5
87
+ coco memory configure --provider ollama --endpoint http://localhost:11434
88
+ coco memory rebuild andul
89
+ ```
90
+
91
+ ## Communication Patterns
92
+
93
+ ### 1. Register → Send → Fetch (async)
94
+
95
+ ```bash
96
+ # Agent A registers
97
+ mcporter call coco.agent_register name="alice"
98
+
99
+ # Agent A sends to B
100
+ mcporter call coco.message_send from="alice" to="bob" message="Hello!"
101
+
102
+ # Agent B fetches later
103
+ mcporter call coco.message_fetch agent_name="bob"
104
+ ```
105
+
106
+ ### 2. Register → Wait (long-poll, real-time)
107
+
108
+ ```bash
109
+ # Agent B waits for messages (blocks up to 30s)
110
+ mcporter call coco.message_wait agent_name="bob" timeout_ms=60000
111
+
112
+ # Agent A sends → B gets the message immediately
113
+ mcporter call coco.message_send from="alice" to="bob" message="Ping!"
114
+ ```
115
+
116
+ ### 3. Channel (multi-agent chat)
117
+
118
+ ```bash
119
+ # Create
120
+ mcporter call coco.channel_create channel_id="dev" topic="Dev chat"
121
+
122
+ # Join
123
+ mcporter call coco.channel_join channel_id="dev" agent_name="alice"
124
+
125
+ # Chat (sent to all members)
126
+ mcporter call coco.channel_send channel_id="dev" from="alice" message="Hey team!"
127
+ ```
128
+
129
+ ## Webhook Gateway (port 8080)
130
+
131
+ HTTP server that receives external webhooks (GitHub, GitLab, Slack, generic) and posts them to bus channels.
132
+
133
+ ```bash
134
+ node webhook-gateway.js 8080
135
+ ```
136
+
137
+ **Endpoints:**
138
+ - `POST /webhook/github/:channel` — GitHub push/PR events
139
+ - `POST /webhook/gitlab/:channel` — GitLab events
140
+ - `POST /webhook/slack/:channel` — Slack messages
141
+ - `POST /hook/:channel` — Any JSON `{"text":"..."}` payload
142
+ - `GET /health` — Health check
143
+
144
+ **Example (GitHub → dev channel):**
145
+ ```bash
146
+ curl -X POST http://localhost:8080/webhook/github/dev \
147
+ -H "Content-Type: application/json" \
148
+ -d '{"ref":"refs/heads/main","repository":{"name":"mcp-coco"},"pusher":{"name":"jonus"},"commits":[{"message":"feat: new feature"}]}'
149
+ ```
150
+
151
+ ## Hermes Auto-Forwarder
152
+
153
+ Any DM sent to agent `hermes` on the bus is automatically forwarded to Hermes CLI (`ask_hermes`) and the reply is posted back to the sender's inbox. No manual `ask_hermes` call needed.
154
+
155
+ ```
156
+ andul ──DM──▶ hermes → Hermes CLI → reply DM back to andul
157
+ ```
158
+
159
+ Run:
160
+ ```bash
161
+ node hermes-forwarder.js
162
+ ```
163
+
164
+ ## Scheduled Tasks (Windows)
165
+
166
+ All CoCo services can run as Windows Scheduled Tasks (auto-start on boot, auto-restart on crash):
167
+
168
+ | Task | Purpose | Port |
169
+ |------|---------|------|
170
+ | `MCP_CoCo_Daemon` | CoCo MCP server (agent bus) | stdio |
171
+ | `MCP_CoCo_Webhook` | Webhook Gateway | :8080 |
172
+ | `MCP_CoCo_HermesFwd` | Hermes Auto-Forwarder | — |
173
+
174
+ Install:
175
+ ```powershell
176
+ powershell -File scripts\install.ps1
177
+ ```
178
+
179
+ ## CLI Access for OpenCode & Terminal Agents
180
+
181
+ CLI agents (OpenCode, Claude Code, shell scripts) can access the message bus **directly** — no MCP server needed. Just read/write JSON files in `.bus/`.
182
+
183
+ ```bash
184
+ # Set your agent name (optional, defaults to $USER)
185
+ export COCO_AGENT=opencode
186
+
187
+ # List agents
188
+ node coco-cli.js agents
189
+
190
+ # Check inbox
191
+ node coco-cli.js inbox
192
+
193
+ # Send a message
194
+ node coco-cli.js send andul "Hello from OpenCode!"
195
+
196
+ # Reply to a specific message
197
+ node coco-cli.js reply <message-id> "Thanks!"
198
+
199
+ # Watch for new messages (poll every 2s)
200
+ node coco-cli.js watch
201
+
202
+ # Or use the shorter wrapper
203
+ node coco.js agents
204
+ node coco.js inbox
205
+ node coco.js send andul "Hey!"
206
+ ```
207
+
208
+ ## One-liner for OpenCode
209
+
210
+ Set this in your shell profile:
211
+ ```bash
212
+ # ~/.bashrc or ~/.zshrc or $PROFILE (PowerShell)
213
+ export COCO_AGENT=opencode
214
+ alias coco='node E:\_system\.openclaw\workspace\repos\mcp-coco\coco.js'
215
+ ```
216
+
217
+ Then just:
218
+ ```bash
219
+ coco agents
220
+ coco inbox
221
+ coco send andul "Hello world!"
222
+ ```
223
+
224
+ When you run `coco send`, it auto-registers your agent on the bus. Other agents (Andul, Hermes) will see you online and can message you back.
225
+
226
+ ## Windows Notes
227
+
228
+ - Uses `cmd.exe /c` wrapper for prompt_toolkit TTY crash fix
229
+ - All commands wrapped with `2>&1` (session_id on stderr)
230
+ - Timeout: 180s per hermes call, 60s max for message_wait
231
+ - Bus data stored in `.bus/` directory (agents, messages, channels)
232
+ - ANSI output stripped automatically
233
+
234
+ ## Integration with Hermes
235
+
236
+ MCP CoCo auto-registers itself as `coco` agent. Hermes can connect via:
237
+ ```bash
238
+ mcporter add hermes --stdio "hermes mcp serve --accept-hooks"
239
+ ```
240
+
241
+ Then OpenClaw and Hermes can DM through CoCo's message bus — no need for direct subprocess calls.
242
+
243
+ ## Troubleshooting
244
+
245
+ | Symptom | Fix |
246
+ |---------|-----|
247
+ | `"sent": true` but no message received | Recipient hasn't registered yet — register first, then fetch |
248
+ | `message_wait` times out | No messages in 30s — increase `timeout_ms` or send a ping |
249
+ | Agent not showing in list | Call `agent_register` first |
250
+ | Channel not found on join | Check `channel_id` is exact (case-sensitive) |
251
+ | `Error: Exit code 2` | Hermes stderr quirk — retry, usually transient |
252
+
253
+ ## Bus Data
254
+
255
+ ```
256
+ .bus/
257
+ ├── agents.json # Agent registry
258
+ ├── messages/
259
+ │ ├── <agent>/ # Per-agent inbox
260
+ │ └── <agent>_outbox/ # Sender outbox
261
+ ├── channels/
262
+ │ ├── <id>.json # Channel metadata
263
+ │ └── <id>/log/ # Channel messages
264
+ └── memory/
265
+ └── <agent>/ # Per-agent memories (JSONL + vectors.json + config.json)
266
+ ```
267
+
268
+ All data is JSON. Back up `.bus/` to preserve conversations.
269
+
270
+ ## Utility Tools
271
+
272
+ ### Bus Doctor
273
+
274
+ Diagnostics and health checks for the CoCo bus:
275
+
276
+ ```bash
277
+ node doctor.js [--quick] [--fix] [--report] [--watch]
278
+ # or via CLI
279
+ node coco-cli.js doctor [--quick] [--fix]
280
+ ```
281
+
282
+ Performs 18 checks: bus directory, permissions, agent registry (profiles, stale agents), orphaned agents, message integrity, channels, scheduler validity, auto-reply rules, workflows, disk usage, stale PIDs, event logs. With `--fix`, auto-creates missing directories, removes stale PID files, deletes corrupted messages.
283
+
284
+ ### CoCo Tunnel
285
+
286
+ Cross-machine bus proxy. Expose your local bus to remote agents:
287
+
288
+ ```bash
289
+ node tunnel.js server --port 9090 --secret ***
290
+ node tunnel.js client --host <ip> --port 9090 --secret ***
291
+ node tunnel.js sync --remote http://<ip>:9090
292
+ node tunnel.js ssh --remote user@host
293
+ # or via CLI
294
+ node coco-cli.js tunnel server --port 9090 --secret ***
295
+ ```
296
+
297
+ Server exposes HTTP endpoints: `/health`, `/bus/agents`, `/bus/send`, `/bus/register`. Client pushes local agents and recent messages at configurable interval. Sync mode merges agent registries bidirectionally.
298
+
299
+ ### Backup & Restore
300
+
301
+ Gzip-compressed backup of the entire `.bus/` directory:
302
+
303
+ ```bash
304
+ node backup.js # Create backup
305
+ node backup.js --list # List backups
306
+ node backup.js --restore <file> # Restore (auto pre-backup first)
307
+ node backup.js --diff <file> # Compare with current state
308
+ node backup.js --cleanup 30 # Remove old backups
309
+ node backup.js --watch 60 # Auto-backup every 60 min
310
+ # or via CLI
311
+ node coco-cli.js backup --list
312
+ ```
313
+
314
+ Backups stored in `.backups/` directory. Each backup includes checksum verification. Diff shows added/removed/modified files.
package/backup.js ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CoCo Backup & Restore — Bus State Management CLI Wrapper
4
+ *
5
+ * Thin wrapper around lib/backup.js
6
+ * Usage: see --help
7
+ */
8
+ const path = require('path');
9
+ const { createBackup, restoreBackup, listBackups, backupInfo, diffBackup, cleanupBackups, autoBackup, watchMode } = require('./lib/backup');
10
+
11
+ const BUS_DIR = path.join(__dirname, '.bus');
12
+ const args = process.argv.slice(2);
13
+ const cmd = args[0];
14
+
15
+ function help() {
16
+ console.log(`\n╔═══════════════════════════════════════════════╗\n║ CoCo — Backup & Restore ║\n╚═══════════════════════════════════════════════╝\n`);
17
+ console.log('Usage:');
18
+ console.log(' node backup.js Create backup (timestamped name)');
19
+ console.log(' node backup.js --out <file> Create backup with custom path');
20
+ console.log(' node backup.js --list List available backups');
21
+ console.log(' node backup.js --info <file> Show backup metadata');
22
+ console.log(' node backup.js --restore <file> Restore bus from backup');
23
+ console.log(' node backup.js --diff <file> Compare backup with current state');
24
+ console.log(' node backup.js --cleanup [days] Remove backups older than N days');
25
+ console.log(' node backup.js --auto Backup only if changes detected');
26
+ console.log(' node backup.js --watch <minutes> Auto-backup every N minutes\n');
27
+ console.log('Examples:');
28
+ console.log(' node backup.js');
29
+ console.log(' node backup.js --restore .backups/coco-bus-2026-06-24.coco');
30
+ console.log(' node backup.js --diff .backups/coco-bus-2026-06-24.coco');
31
+ console.log(' node backup.js --cleanup 30');
32
+ console.log(' node backup.js --watch 60\n');
33
+ }
34
+
35
+ function main() {
36
+ if (!cmd) { createBackup(BUS_DIR); return; }
37
+ if (cmd === '--help') { help(); return; }
38
+
39
+ try {
40
+ switch (cmd) {
41
+ case '--list': listBackups(BUS_DIR); break;
42
+ case '--info': backupInfo(path.resolve(args[1])); break;
43
+ case '--restore': restoreBackup(path.resolve(args[1]), BUS_DIR); break;
44
+ case '--diff': diffBackup(path.resolve(args[1]), BUS_DIR); break;
45
+ case '--cleanup': cleanupBackups(BUS_DIR, parseInt(args[1], 10) || 30); break;
46
+ case '--out': createBackup(BUS_DIR, path.resolve(args[1])); break;
47
+ case '--auto': autoBackup(BUS_DIR); break;
48
+ case '--watch': watchMode(BUS_DIR, parseInt(args[1], 10) || 30); break;
49
+ default: createBackup(BUS_DIR);
50
+ }
51
+ } catch (err) {
52
+ console.error('Error:', err.message);
53
+ process.exit(1);
54
+ }
55
+ }
56
+
57
+ main();
package/bin/cli.js ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * MCP Bus CLI — command-line entry point
4
+ *
5
+ * Usage:
6
+ * bus-agent # stdio MCP server
7
+ * bus-agent --daemon # start background daemon
8
+ * bus-agent --health # one-shot health check
9
+ * bus-agent --help # show help
10
+ */
11
+ const path = require('path');
12
+
13
+ const args = process.argv.slice(2);
14
+
15
+ if (args.includes('--help') || args.includes('-h')) {
16
+ console.log(`
17
+ MCP Bus — MCP Bridge: OpenClaw ↔ Hermes Agent
18
+
19
+ Usage:
20
+ bus-agent Run as stdio MCP server (for mcporter)
21
+ bus-agent --daemon Start background daemon
22
+ bus-agent --health Quick health check (exit 0 = ok)
23
+ bus-agent --help Show this help
24
+
25
+ Examples:
26
+ # Run as stdio server (connect via mcporter):
27
+ mcporter add coco --stdio "node path/to/index.js"
28
+
29
+ # Start as background daemon:
30
+ bus-agent --daemon
31
+
32
+ # Call from OpenClaw:
33
+ mcporter call coco.ask_hermes prompt="Hello Hermes"
34
+
35
+ # Check health:
36
+ bus-agent --health
37
+ `);
38
+ process.exit(0);
39
+ }
40
+
41
+ require(path.join(__dirname, '..', 'index.js'));