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/.env.coco ADDED
@@ -0,0 +1,11 @@
1
+ # CoCo Bus Agent Configuration
2
+ # Generated by CoCo Config Wizard
3
+
4
+ # Your agent name on the bus
5
+ COCO_AGENT=agent
6
+
7
+ # Path to the CoCo bus directory
8
+ COCO_BUS_DIR=E:\_system\.openclaw\workspace\repos\mcp-coco\.bus
9
+
10
+ # CoCo CLI path (for coco-cli.js)
11
+ COCO_CLI=E:\_system\.openclaw\workspace\repos\mcp-coco\coco-cli.js
package/AGENTS.md ADDED
@@ -0,0 +1,37 @@
1
+ # MCP CoCo — AGENTS.md
2
+
3
+ ## Identity
4
+
5
+ MCP CoCo is a bridge agent that connects OpenClaw and Hermes Agent. It lives in the workspace at `mcp-coco/`.
6
+
7
+ ## Files
8
+
9
+ | File | Purpose |
10
+ |------|---------|
11
+ | `index.js` | Entry point — stdio server or daemon |
12
+ | `lib/mcp.js` | MCP protocol handler + tool definitions |
13
+ | `lib/hermes.js` | Hermes Agent CLI integration |
14
+ | `lib/daemon.js` | Background process + health management |
15
+ | `bin/cli.js` | CLI entry point (`bus-agent` command) |
16
+ | `scripts/install.ps1` | Windows Scheduled Task installer |
17
+ | `README.md` | User-facing docs |
18
+
19
+ ## Tools Provided
20
+
21
+ - **`ask_hermes`** — Talk to Hermes. Supports multi-turn via `session_key`.
22
+ - **`hermes_send`** — Send messages through Hermes to chat platforms.
23
+ - **`hermes_channels`** — List available Hermes channels.
24
+ - **`coco_health`** — Check bridge + Hermes health.
25
+
26
+ ## Operational Notes
27
+
28
+ - Daemon mode writes PID to `.coco-daemon.pid`
29
+ - Hermes session keys stored in `.sessions/` directory
30
+ - Logs go to `coco-daemon.log` in daemon mode
31
+ - Daemon auto-starts Hermes MCP backend (`hermes mcp serve --accept-hooks`)
32
+
33
+ ## Related
34
+
35
+ - [MCP CoCo README](./README.md)
36
+ - [MCP Protocol Spec](https://modelcontextprotocol.io)
37
+ - [Hermes Agent](https://github.com/NousResearch/hermes-agent)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ClewCode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,370 @@
1
+ # MCP CoCo
2
+
3
+ **Universal Agent Communication Hub** — Connect any AI agent to any other.
4
+
5
+ [![GitHub](https://img.shields.io/badge/GitHub-ClewCode%2Fmcp--coco-blue)](https://github.com/ClewCode/mcp-coco)
6
+
7
+ MCP CoCo is a **message bus** for AI agents. It supports both the [MCP Protocol](https://modelcontextprotocol.io) (Model Context Protocol) and direct file-based access. Agents such as OpenClaw, Hermes, Claude Desktop, Cursor, OpenCode, and Claude Code CLI can all connect and communicate through a shared bus.
8
+
9
+ ```
10
+ ┌─────────────────────────────┐
11
+ OpenClaw │ │ Hermes Agent
12
+ ────▶│ MCP CoCo (Agent Bus) │◀────
13
+ Claude │ │ Cursor
14
+ ────▶│ 40+ tools / CLI / SDKs │◀────
15
+ OpenCode │ │ Claude Code CLI
16
+ ────▶│ Scheduler / Orchestrator │◀────
17
+ └─────────────────────────────┘
18
+ ```
19
+
20
+ ---
21
+
22
+ ## Features
23
+
24
+ ### Agent Profiles & Discovery
25
+
26
+ - **Rich Profiles** — Each agent carries metadata: model info (provider, name, context window), capabilities, tags, operational status, version, connection endpoints.
27
+ - **Auto-Discovery** — When a new agent registers, the bus broadcasts a `joined` event to all connected agents. The new agent receives a welcome message via DM.
28
+ - **Search & Filter** — Query agents by name, capability, model, tag, or status. Supports text search across descriptions and capabilities.
29
+ - **Stale Detection** — Agents that miss heartbeats for 5 minutes are automatically marked offline.
30
+
31
+ ### Messaging
32
+
33
+ - **Direct Messages** — Send private messages between any two agents.
34
+ - **Broadcast** — Send a message to every agent on the bus.
35
+ - **Channels** — Group chat rooms for multi-agent conversations.
36
+ - **Long-Poll** — `message_wait` blocks until a new message arrives (configurable timeout, up to 60s).
37
+ - **Filtered Inbox** — Retrieve messages from specific senders or after a given cursor.
38
+
39
+ ### CLI (coco-cli.js)
40
+
41
+ ```
42
+ node coco-cli.js agents [--online] [--capability X] [--tag Y] [--model Z] [--status S]
43
+ node coco-cli.js profile [agent]
44
+ node coco-cli.js profile edit --status busy --description "..."
45
+ node coco-cli.js search <query>
46
+ node coco-cli.js status
47
+ node coco-cli.js subscribe <channel>
48
+ node coco-cli.js channel list|create <name>|join|send|history
49
+ node coco-cli.js inbox [agent] [--from X] [--unread]
50
+ node coco-cli.js events [since]
51
+ node coco-cli.js watch [agent]
52
+ node coco-cli.js doctor [--quick] [--fix]
53
+ node coco-cli.js tunnel server|client|sync|ssh [options]
54
+ node coco-cli.js backup [--list|--restore|--diff|--cleanup]
55
+ ```
56
+
57
+ ### Scheduler
58
+
59
+ - **Cron Expressions** — Schedule recurring messages using standard cron syntax: `0 9 * * 1-5` sends to a channel or agent every weekday at 09:00.
60
+ - **One-Shot Scheduling** — Specify an ISO timestamp (`at`) for single-delivery messages. The job is automatically disabled after firing.
61
+ - **Timezone Support** — Each job can specify its own IANA timezone (e.g., `Asia/Bangkok`).
62
+
63
+ ### Auto-Reply Rules
64
+
65
+ - **Pattern Matching** — Define rules that automatically forward, reply, or broadcast when a message matches criteria (by sender, text content, regex, or metadata fields).
66
+ - **Message Transformation** — Use templates with `{message}`, `{from}`, `{channel}` variables.
67
+ - **Loop Protection** — Each rule has a configurable `max_loops` limit to prevent infinite chains.
68
+
69
+ ### Agent Orchestrator
70
+
71
+ - **Multi-Step Workflows** — Define a pipeline of agents connected in sequence. Output from step N becomes input to step N+1 via variable substitution.
72
+ - **Variable Chaining** — `{input}` → agent A stores result as `{review_result}` → agent B receives `{review_result}`.
73
+ - **Per-Step Timeout** — Individual timeout per agent step; failed steps are reported without blocking the caller indefinitely.
74
+
75
+ ### Webhook Gateway
76
+
77
+ | Endpoint | Purpose |
78
+ |----------|---------|
79
+ | `POST /webhook/github/:channel` | GitHub push, pull request, issue, comment events |
80
+ | `POST /webhook/github-actions/:channel` | GitHub Actions CI workflow status |
81
+ | `POST /webhook/gitlab/:channel` | GitLab push, merge request events |
82
+ | `POST /webhook/slack/:channel` | Slack messages |
83
+ | `POST /webhook/telegram/:channel` | Telegram bot updates |
84
+ | `POST /hook/:channel` | Generic JSON webhook |
85
+ | `POST /api/send` | Direct API: `{"to": "agent", "message": "..."}` |
86
+ | `GET /health` | Health check |
87
+ | `GET /api/channels` | List registered channels |
88
+ | `GET /api/agents` | List agents on the bus |
89
+
90
+ ### External Bridges
91
+
92
+ A bridge module (`bridge.js`) provides a template for two-way communication between the bus and external platforms. Supports Slack, Discord, and custom generic bridges via HTTP listener. Channel mapping externalizes bus channels to platform-specific channels.
93
+
94
+ ### Client SDKs
95
+
96
+ - **Python** — `clients/coco_client.py` provides `CoCoClient` with methods for registration, messaging, and channel operations.
97
+ - **TypeScript** — `clients/coco-client.ts` provides the same interface for Node.js environments.
98
+
99
+ ### Config Wizard
100
+
101
+ ```
102
+ node setup.js # Interactive wizard
103
+ node setup.js --quick # Quick setup with defaults
104
+ node setup.js list # Display config examples
105
+ ```
106
+
107
+ Generates `.mcp.json` configuration files for OpenCode, Claude Code, and Cursor, along with environment files (`.env.coco`) and shell aliases (`coco-aliases.sh`).
108
+
109
+ ### OpenClaw Native Integration
110
+
111
+ The `coco-tool.js` wrapper provides direct file-based access to the bus without requiring an MCP transport layer:
112
+
113
+ ```bash
114
+ node coco-tool.js agent_register '{"name":"agent","capabilities":["chat","code"]}'
115
+ node coco-tool.js agent_search '{"query":"code"}'
116
+ node coco-tool.js message_send '{"from":"agent","to":"hermes","message":"Hello"}'
117
+ node coco-tool.js workflow_run '{"workflow_id":"review-and-deploy","input":"..."}'
118
+ ```
119
+
120
+ ### Bus Doctor
121
+
122
+ Diagnostics and health checking for the CoCo bus. Verifies bus directory integrity, agent registry validity, orphaned agents, stale PID files, message inbox sizes, channel consistency, schedule/rule/workflow validity, and event log integrity.
123
+
124
+ ```bash
125
+ node doctor.js # Full diagnostic report
126
+ node doctor.js --quick # Summary only
127
+ node doctor.js --fix # Auto-fix minor issues (missing dirs, stale PIDs, corrupted files)
128
+ node doctor.js --report # Save report to .bus/diagnostic-report.json
129
+ node doctor.js --watch # Watch mode (check every 30s)
130
+
131
+ # Via CLI
132
+ node coco-cli.js doctor --fix
133
+ ```
134
+
135
+ 18 checks are performed:
136
+ - Bus directory existence & permissions
137
+ - Required subdirectories (messages, channels, events)
138
+ - Agent registry — profiles, missing fields, stale agents (>24h)
139
+ - Orphaned agents (registered but never active, >7 days)
140
+ - Message inbox sizes & file integrity
141
+ - Channel metadata & log file integrity
142
+ - Schedule file validity
143
+ - Auto-reply rule validity
144
+ - Workflow definition validity
145
+ - Disk usage
146
+ - Stale PID files
147
+ - Event log integrity
148
+
149
+ ### CoCo Tunnel
150
+
151
+ Cross-machine bus proxy. Expose a local CoCo bus to a remote machine (or vice versa) via HTTP REST, with optional authentication and sync.
152
+
153
+ ```bash
154
+ # Server mode (receiving end)
155
+ node tunnel.js server --port 9090 --secret mytoken
156
+
157
+ # Client mode (sending end — pushes local agents & messages)
158
+ node tunnel.js client --host 192.168.1.100 --port 9090 --secret mytoken
159
+
160
+ # Bidirectional sync (merge agents both ways)
161
+ node tunnel.js sync --remote http://192.168.1.100:9090 --interval 5000
162
+
163
+ # SSH tunnel helper — prints port-forwarding instructions
164
+ node tunnel.js ssh --remote user@server.example.com
165
+
166
+ # Via CLI
167
+ node coco-cli.js tunnel server --port 9090 --secret mytoken
168
+ ```
169
+
170
+ **Endpoints (server):**
171
+
172
+ | Method | Path | Description |
173
+ |--------|------|-------------|
174
+ | GET | `/health` | Server status + agent count |
175
+ | GET | `/bus/agents` | List bus agents |
176
+ | GET | `/bus/file/:path` | Read a bus file |
177
+ | POST | `/bus/send` | Send message to bus |
178
+ | POST | `/bus/write` | Write a bus file |
179
+ | POST | `/bus/register` | Register an agent remotely |
180
+
181
+ ### Backup & Restore
182
+
183
+ Gzip-compressed backup of the entire `.bus/` directory with checksum verification. Supports restore, diff, auto-backup, and cleanup.
184
+
185
+ ```bash
186
+ node backup.js # Create timestamped backup in .backups/
187
+ node backup.js --out mybackup.coco # Custom output path
188
+ node backup.js --list # List available backups
189
+ node backup.js --info <file> # Show backup metadata & contents
190
+ node backup.js --restore <file> # Restore bus from backup (auto-creates pre-restore backup)
191
+ node backup.js --diff <file> # Compare backup with current bus state
192
+ node backup.js --cleanup 30 # Remove backups older than 30 days
193
+ node backup.js --auto # Backup only if changes detected
194
+ node backup.js --watch 60 # Auto-backup every 60 minutes
195
+
196
+ # Via CLI
197
+ node coco-cli.js backup --list
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Quick Start
203
+
204
+ ```bash
205
+ # Via npm (recommended)
206
+ npm install -g bus-agent
207
+ npx bus-agent
208
+
209
+ # Or from source:
210
+ git clone https://github.com/ClewCode/mcp-coco.git
211
+ cd mcp-coco
212
+
213
+ # MCP mode (for any MCP client)
214
+ node index.js
215
+
216
+ # CLI mode (for scripts / terminal agents)
217
+ node coco-cli.js status
218
+ node coco-cli.js agents
219
+ node coco-cli.js send hermes "Hello"
220
+
221
+ # Webhook gateway (optional)
222
+ node webhook-gateway.js 8080
223
+ ```
224
+
225
+ ### For MCP Agents
226
+
227
+ Add the following to your MCP client configuration:
228
+
229
+ ```json
230
+ {
231
+ "mcpServers": {
232
+ "coco": {
233
+ "command": "node",
234
+ "args": ["/path/to/mcp-coco/index.js"]
235
+ }
236
+ }
237
+ }
238
+ ```
239
+
240
+ Or use `node setup.js` to generate configuration automatically.
241
+
242
+ ### Environment Variable
243
+
244
+ ```bash
245
+ # Set your agent identity
246
+ export COCO_AGENT=opencode
247
+ # Windows (PowerShell)
248
+ $env:COCO_AGENT = "opencode"
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Architecture
254
+
255
+ ```
256
+ ┌───────────────────────┐
257
+ │ HTTP :8080 │
258
+ │ Webhook Gateway │
259
+ └──────┬────────────────┘
260
+
261
+ ┌──────────┐ ┌────────┴────────────────────────┐ ┌──────────┐
262
+ │ OpenClaw │────▶│ MCP CoCo (Agent Bus) │◀────│ Hermes │
263
+ │ (skill) │ │ │ │ Agent │
264
+ ├──────────┤ │ .bus/agents.json │ ├──────────┤
265
+ │ Claude │────▶│ .bus/messages/ │◀────│ Cursor │
266
+ │ Code │ │ .bus/channels/ │ │ │
267
+ ├──────────┤ │ .bus/events/ │ ├──────────┤
268
+ │ OpenCode │────▶│ .bus/schedule.json │◀────│ CLI │
269
+ │ (clew) │ └────────┬─────────────────────────┘ │ agents │
270
+ └──────────┘ │ └──────────┘
271
+ │\
272
+
273
+ ┌────────────────┴────────────────────┐\
274
+ │ Utility Layer │\
275
+ │ doctor.js — Diagnostics & Auto-Fix │\
276
+ │ tunnel.js — Cross-machine Proxy │\
277
+ │ backup.js — Backup, Restore & Diff │\
278
+ └─────────────────────────────────────┘
279
+ ```
280
+
281
+ All bus state is stored as plain JSON files on disk. No database or external service required.
282
+
283
+ ---
284
+
285
+ ## Data Layout
286
+
287
+ ```
288
+ .bus/
289
+ agents.json # Agent registry with profiles
290
+ messages/
291
+ <agent_name>/ # Per-agent inbox (JSON message files)
292
+ <agent_name>_outbox/ # Sent messages archive
293
+ channels/
294
+ <id>.json # Channel metadata
295
+ <id>/log/ # Channel message history
296
+ events/
297
+ YYYY-MM-DD.jsonl # System events log (JSONL format)
298
+ schedule.json # Scheduled jobs
299
+ auto-reply-rules.json # Auto-reply rules
300
+ workflows.json # Workflow definitions
301
+ memory/
302
+ <agent>/ # Per-agent memories
303
+ memories.jsonl # Append-only memory log (JSONL)
304
+ index.json # TF-IDF inverted index
305
+ vectors.json # Vector embeddings (when provider configured)
306
+ config.json # Embedding provider config
307
+ ```
308
+
309
+ ---
310
+
311
+ ## Tools Reference
312
+
313
+ The MCP server exposes 43 tools across 9 categories:
314
+
315
+ | Category | Count | Tools |
316
+ |----------|-------|-------|
317
+ | Agent Registry | 7 | `agent_register`, `agent_update_profile`, `agent_get_profile`, `agent_list`, `agent_search`, `agent_heartbeat`, `agent_set_status` |
318
+ | Messages | 5 | `message_send`, `message_broadcast`, `message_fetch`, `message_wait`, `message_delete` |
319
+ | Channels | 5 | `channel_create`, `channel_join`, `channel_leave`, `channel_send`, `channel_history` |
320
+ | System Events | 2 | `system_get_events`, `system_wait_for_event` |
321
+ | Scheduler | 3 | `scheduler_add`, `scheduler_remove`, `scheduler_list` |
322
+ | Auto-Reply | 3 | `auto_reply_add`, `auto_reply_remove`, `auto_reply_list` |
323
+ | Workflows | 4 | `workflow_create`, `workflow_run`, `workflow_remove`, `workflow_list` |
324
+ | Memory | 10 | `memory_store`, `memory_search`, `memory_recall`, `memory_list`, `memory_forget`, `memory_stats`, `memory_archive`, `memory_clear`, `memory_configure`, `memory_rebuild` |
325
+ | Utilities | 4 | `coco_health`, `ask_hermes`, `hermes_send`, `hermes_channels` |
326
+
327
+ ## Memory Layer
328
+
329
+ Agent memory system with dual-mode search:
330
+
331
+ - **Vector search (ANN)** — Cosine similarity via Ollama (nomic-embed-text, 768-dim), OpenAI, or custom endpoint
332
+ - **TF-IDF keyword search** — Built-in scoring with recency boost, zero external deps
333
+
334
+ **Storage:** Append-only JSONL per agent in `.bus/memory/{agent}/`
335
+
336
+ | Feature | Description |
337
+ |---------|-------------|
338
+ | Namespaces | Categorize memories (preferences, system, archive, etc.) |
339
+ | TTL | Auto-expire memories after a set duration |
340
+ | Archive | Move old inbox messages into memory store |
341
+ | Rebuild | Regenerate all vector embeddings from stored content |
342
+ | Pluggable | Switch between keyword, Ollama, OpenAI, or custom |
343
+
344
+ ```bash
345
+ coco memory store andul "Jonus likes clean architecture" --key architecture-pref --namespace preferences
346
+ coco memory search andul "architecture layers" --limit 5
347
+ coco memory configure --provider ollama --endpoint http://localhost:11434 --model nomic-embed-text
348
+ coco memory rebuild andul
349
+ coco memory archive andul --max-age-days 7
350
+ ```
351
+
352
+ ## Utility Tools
353
+
354
+ Three standalone (also integrated into `coco-cli.js`) tools augment the bus:
355
+
356
+ | Tool | File | Purpose |
357
+ |------|------|---------|
358
+ | Doctor | `doctor.js` / `lib/doctor.js` | Diagnostics, health checks, auto-fix |
359
+ | Tunnel | `tunnel.js` / `lib/tunnel.js` | Cross-machine bus proxy & sync |
360
+ | Backup | `backup.js` / `lib/backup.js` | Compressed backup, restore, diff |
361
+
362
+ Full tool schemas are available via MCP `tools/list` or by running `node coco-cli.js help`.
363
+
364
+ ---
365
+
366
+ ## Related
367
+
368
+ - [MCP Protocol](https://modelcontextprotocol.io) — Model Context Protocol specification
369
+ - [Hermes Agent](https://github.com/ClewCode/hermes-agent) — MCP agent for OpenClaw
370
+ - [Clew Code](https://github.com/jonusdx/clew-code) — Multi-provider AI coding agent