@stdiobus/workers-registry 1.3.7

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.
Files changed (57) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +932 -0
  3. package/out/dist/workers/acp-registry/registry-launcher-client.js +52 -0
  4. package/out/dist/workers/acp-registry/registry-launcher-client.js.map +7 -0
  5. package/out/dist/workers/acp-registry/registry-launcher-config.json +31 -0
  6. package/out/dist/workers/acp-worker/index.js +5 -0
  7. package/out/dist/workers/acp-worker/index.js.map +7 -0
  8. package/out/dist/workers/echo-worker/echo-worker-config.json +21 -0
  9. package/out/dist/workers/echo-worker/echo-worker.js +3 -0
  10. package/out/dist/workers/echo-worker/echo-worker.js.map +7 -0
  11. package/out/dist/workers/index.d.ts +15 -0
  12. package/out/dist/workers/index.js +33 -0
  13. package/out/dist/workers/mcp-echo-server/index.js +3 -0
  14. package/out/dist/workers/mcp-echo-server/index.js.map +7 -0
  15. package/out/dist/workers/mcp-echo-server/mcp-echo-server-config.json +21 -0
  16. package/out/dist/workers/mcp-to-acp-proxy/proxy.js +3 -0
  17. package/out/dist/workers/mcp-to-acp-proxy/proxy.js.map +7 -0
  18. package/out/tsc/workers/acp-worker/src/acp/client-capabilities.d.ts +131 -0
  19. package/out/tsc/workers/acp-worker/src/acp/content-mapper.d.ts +95 -0
  20. package/out/tsc/workers/acp-worker/src/acp/index.d.ts +13 -0
  21. package/out/tsc/workers/acp-worker/src/acp/tools.d.ts +119 -0
  22. package/out/tsc/workers/acp-worker/src/agent.d.ts +113 -0
  23. package/out/tsc/workers/acp-worker/src/index.d.ts +1 -0
  24. package/out/tsc/workers/acp-worker/src/mcp/connection.d.ts +54 -0
  25. package/out/tsc/workers/acp-worker/src/mcp/index.d.ts +10 -0
  26. package/out/tsc/workers/acp-worker/src/mcp/manager.d.ts +178 -0
  27. package/out/tsc/workers/acp-worker/src/mcp/types.d.ts +114 -0
  28. package/out/tsc/workers/acp-worker/src/mcp-proxy/connection.d.ts +80 -0
  29. package/out/tsc/workers/acp-worker/src/mcp-proxy/converter.d.ts +156 -0
  30. package/out/tsc/workers/acp-worker/src/mcp-proxy/index.d.ts +2 -0
  31. package/out/tsc/workers/acp-worker/src/mcp-proxy/state.d.ts +165 -0
  32. package/out/tsc/workers/acp-worker/src/mcp-proxy/types.d.ts +163 -0
  33. package/out/tsc/workers/acp-worker/src/registry-launcher/config/api-keys.d.ts +41 -0
  34. package/out/tsc/workers/acp-worker/src/registry-launcher/config/config.d.ts +17 -0
  35. package/out/tsc/workers/acp-worker/src/registry-launcher/config/index.d.ts +10 -0
  36. package/out/tsc/workers/acp-worker/src/registry-launcher/config/types.d.ts +15 -0
  37. package/out/tsc/workers/acp-worker/src/registry-launcher/index.d.ts +2 -0
  38. package/out/tsc/workers/acp-worker/src/registry-launcher/log.d.ts +77 -0
  39. package/out/tsc/workers/acp-worker/src/registry-launcher/registry/index.d.ts +109 -0
  40. package/out/tsc/workers/acp-worker/src/registry-launcher/registry/resolver.d.ts +67 -0
  41. package/out/tsc/workers/acp-worker/src/registry-launcher/registry/types.d.ts +105 -0
  42. package/out/tsc/workers/acp-worker/src/registry-launcher/router/index.d.ts +8 -0
  43. package/out/tsc/workers/acp-worker/src/registry-launcher/router/message-router.d.ts +150 -0
  44. package/out/tsc/workers/acp-worker/src/registry-launcher/runtime/agent-runtime.d.ts +58 -0
  45. package/out/tsc/workers/acp-worker/src/registry-launcher/runtime/index.d.ts +11 -0
  46. package/out/tsc/workers/acp-worker/src/registry-launcher/runtime/manager.d.ts +82 -0
  47. package/out/tsc/workers/acp-worker/src/registry-launcher/runtime/types.d.ts +20 -0
  48. package/out/tsc/workers/acp-worker/src/registry-launcher/stream/index.d.ts +8 -0
  49. package/out/tsc/workers/acp-worker/src/registry-launcher/stream/ndjson-handler.d.ts +119 -0
  50. package/out/tsc/workers/acp-worker/src/registry-launcher/test-utils/index.d.ts +234 -0
  51. package/out/tsc/workers/acp-worker/src/session/index.d.ts +12 -0
  52. package/out/tsc/workers/acp-worker/src/session/manager.d.ts +63 -0
  53. package/out/tsc/workers/acp-worker/src/session/session.d.ts +86 -0
  54. package/out/tsc/workers/acp-worker/src/session/types.d.ts +33 -0
  55. package/out/tsc/workers/acp-worker/src/test-utils/test-harness.d.ts +80 -0
  56. package/out/tsc/workers/mcp-echo-server/mcp-echo-server.d.ts +2 -0
  57. package/package.json +77 -0
package/README.md ADDED
@@ -0,0 +1,932 @@
1
+ # @stdiobus/workers-registry
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@stdiobus/workers-registry.svg)](https://www.npmjs.com/package/@stdiobus/workers-registry)
4
+ [![License](https://img.shields.io/npm/l/@stdiobus/workers-registry.svg)](https://github.com/stdiobus/workers-registry/blob/main/LICENSE)
5
+ [![Node.js Version](https://img.shields.io/node/v/@stdiobus/workers-registry.svg)](https://nodejs.org)
6
+ [![Downloads](https://img.shields.io/npm/dm/@stdiobus/workers-registry.svg)](https://www.npmjs.com/package/@stdiobus/workers-registry)
7
+
8
+ Worker implementations for [stdio Bus kernel](https://github.com/stdiobus/stdiobus) - a high-performance message routing daemon for agent protocols.
9
+
10
+ **Features:**
11
+ - Full ACP (Agent Client Protocol) implementation
12
+ - MCP (Model Context Protocol) server integration
13
+ - Protocol bridges (MCP ↔ ACP)
14
+ - Ready-to-use binary commands
15
+ - TypeScript support with full type definitions
16
+ - High-performance NDJSON protocol
17
+ - Docker-ready
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @stdiobus/workers-registry
23
+ ```
24
+
25
+ **Requirements:**
26
+ - Node.js ≥20.0.0
27
+ - [stdio Bus kernel](https://github.com/stdiobus/stdiobus) (Docker or binary)
28
+
29
+ **Keywords:** `stdiobus`, `protocol`, `acp`, `mcp`, `agent`, `transport`, `json-rpc`, `stdio-bus`, `worker`
30
+
31
+ ---
32
+
33
+ ## Overview
34
+
35
+ stdio Bus kernel provides the core protocol and message routing infrastructure. This package contains the worker implementations that run as child processes of stdio Bus kernel, handling various agent protocols and use cases.
36
+
37
+ ## Architecture
38
+
39
+ ```mermaid
40
+ graph TB
41
+ Client[Client Application] -->|TCP/Unix Socket| Kernel[stdio Bus kernel]
42
+ Kernel -->|NDJSON stdin/stdout| ACP[ACP Worker]
43
+ Kernel -->|NDJSON stdin/stdout| Registry[Registry Launcher]
44
+ Kernel -->|NDJSON stdin/stdout| Echo[Echo Worker]
45
+ Kernel -->|NDJSON stdin/stdout| Proxy[MCP-to-ACP Proxy]
46
+
47
+ Registry -->|Spawns| Claude[Claude Agent]
48
+ Registry -->|Spawns| Goose[Goose Agent]
49
+ Registry -->|Spawns| Cline[Cline Agent]
50
+ Registry -->|Spawns| Other[Other ACP Agents]
51
+
52
+ ACP -->|Connects to| MCP[MCP Servers]
53
+
54
+ IDE[IDE] -->|MCP Protocol| Proxy
55
+ Proxy -->|ACP Protocol| Kernel
56
+
57
+ style Kernel fill:#4a90e2,stroke:#2e5c8a,stroke-width:3px,color:#fff
58
+ style Registry fill:#50c878,stroke:#2d7a4a,stroke-width:2px,color:#fff
59
+ style ACP fill:#9b59b6,stroke:#6c3483,stroke-width:2px,color:#fff
60
+ style Proxy fill:#e67e22,stroke:#a04000,stroke-width:2px,color:#fff
61
+ ```
62
+
63
+ **Architecture layers:**
64
+ ```
65
+ stdio Bus kernel ← https://github.com/stdiobus/stdiobus
66
+ ↓ (spawns workers via stdin/stdout NDJSON)
67
+ Workers Registry (this repo)
68
+ ├── ACP Worker (Agent Client Protocol)
69
+ ├── Registry Launcher (ACP Registry integration)
70
+ ├── MCP-to-ACP Proxy (protocol bridge)
71
+ └── Echo Worker (testing/examples)
72
+ ```
73
+
74
+ ## Prerequisites
75
+
76
+ - stdio Bus kernel - available via [Docker](https://hub.docker.com/r/stdiobus/stdiobus) or [build from source](https://github.com/stdiobus/stdiobus)
77
+ - Node.js 20.0.0 or later (for building workers)
78
+
79
+ ## Workers
80
+
81
+ | Worker | Description | Protocol | Command |
82
+ |--------|-------------|----------|---------|
83
+ | `acp-worker` | Full ACP protocol implementation using official SDK | ACP | `stdiobus-acp-worker` |
84
+ | `registry-launcher` | Routes messages to any agent in the ACP Registry | ACP | `stdiobus-registry-launcher` |
85
+ | `mcp-to-acp-proxy` | Bridges MCP clients (like IDEs) to ACP agents | MCP → ACP | `stdiobus-mcp-to-acp-proxy` |
86
+ | `echo-worker` | Simple echo worker for testing NDJSON protocol | NDJSON | `stdiobus-echo-worker` |
87
+ | `mcp-echo-server` | MCP server example for testing | MCP | `stdiobus-mcp-echo-server` |
88
+
89
+ ## Package API
90
+
91
+ ### Binary Commands
92
+
93
+ After installation, the following commands are available:
94
+
95
+ ```bash
96
+ stdiobus-acp-worker # ACP Worker
97
+ stdiobus-registry-launcher # Registry Launcher
98
+ stdiobus-mcp-to-acp-proxy # MCP-to-ACP Proxy
99
+ stdiobus-echo-worker # Echo Worker
100
+ stdiobus-mcp-echo-server # MCP Echo Server
101
+ ```
102
+
103
+ ### Module Imports
104
+
105
+ ```javascript
106
+ // Import ACP worker (default export)
107
+ import worker from '@stdiobus/workers-registry';
108
+
109
+ // Import specific workers
110
+ import acpWorker from '@stdiobus/workers-registry/workers/acp-worker';
111
+ import echoWorker from '@stdiobus/workers-registry/workers/echo-worker';
112
+ import mcpEchoServer from '@stdiobus/workers-registry/workers/mcp-echo-server';
113
+ import mcpToAcpProxy from '@stdiobus/workers-registry/workers/mcp-to-acp-proxy';
114
+
115
+ // Import workers metadata
116
+ import { workers } from '@stdiobus/workers-registry/workers';
117
+ console.log(workers['acp-worker'].entrypoint);
118
+ ```
119
+
120
+ ### TypeScript Support
121
+
122
+ Full TypeScript definitions are included:
123
+
124
+ ```typescript
125
+ import type { ACPAgent } from '@stdiobus/workers-registry/workers/acp-worker';
126
+ import type { MCPServer } from '@stdiobus/workers-registry/workers/mcp-echo-server';
127
+ ```
128
+
129
+ ## Quick Start
130
+
131
+ ### 1. Install Package
132
+
133
+ ```bash
134
+ npm install @stdiobus/workers-registry
135
+ ```
136
+
137
+ ### 2. Get stdio Bus kernel
138
+
139
+ **Option A: Using Docker (recommended)**
140
+
141
+ ```bash
142
+ docker pull stdiobus/stdiobus:latest
143
+ ```
144
+
145
+ **Option B: Build from source**
146
+
147
+ See [stdio Bus kernel repository](https://github.com/stdiobus/stdiobus) for build instructions.
148
+
149
+ ### 3. Run with ACP Worker
150
+
151
+ **Create config.json:**
152
+ ```json
153
+ {
154
+ "pools": [{
155
+ "id": "acp-worker",
156
+ "command": "node",
157
+ "args": ["@stdiobus/workers-registry/workers/acp-worker"],
158
+ "instances": 1
159
+ }]
160
+ }
161
+ ```
162
+
163
+ **Run with Docker:**
164
+ ```bash
165
+ docker run -p 9000:9000 \
166
+ -v $(pwd)/node_modules/@stdiobus/workers-registry:/workers:ro \
167
+ -v $(pwd)/config.json:/config.json:ro \
168
+ stdiobus/stdiobus:latest \
169
+ --config /config.json --tcp 0.0.0.0:9000
170
+ ```
171
+
172
+ **Or with binary:**
173
+ ```bash
174
+ ./stdio_bus --config config.json --tcp 0.0.0.0:9000
175
+ ```
176
+
177
+ ### 4. Test Connection
178
+
179
+ ```bash
180
+ echo '{"jsonrpc":"2.0","id":"1","method":"initialize","params":{"clientInfo":{"name":"test","version":"1.0"}}}' | nc localhost 9000
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Usage Examples
186
+
187
+ ### Using as Binary Commands
188
+
189
+ The package provides executable commands for each worker:
190
+
191
+ ```bash
192
+ # Run ACP worker directly
193
+ stdiobus-acp-worker
194
+
195
+ # Run Registry Launcher with API keys
196
+ stdiobus-registry-launcher ./api-keys.json
197
+
198
+ # Run MCP-to-ACP Proxy
199
+ ACP_HOST=localhost ACP_PORT=9000 AGENT_ID=claude-acp stdiobus-mcp-to-acp-proxy
200
+
201
+ # Run Echo worker for testing
202
+ stdiobus-echo-worker
203
+ ```
204
+
205
+ ### Using in stdio Bus Configuration
206
+
207
+ **Basic ACP Worker:**
208
+ ```json
209
+ {
210
+ "pools": [{
211
+ "id": "acp-worker",
212
+ "command": "node",
213
+ "args": ["@stdiobus/workers-registry/workers/acp-worker"],
214
+ "instances": 1
215
+ }]
216
+ }
217
+ ```
218
+
219
+ **Registry Launcher with API Keys:**
220
+ ```json
221
+ {
222
+ "pools": [{
223
+ "id": "registry-launcher",
224
+ "command": "node",
225
+ "args": ["@stdiobus/workers-registry/workers/registry-launcher", "./api-keys.json"],
226
+ "instances": 1
227
+ }]
228
+ }
229
+ ```
230
+
231
+ **Multiple Workers:**
232
+ ```json
233
+ {
234
+ "pools": [
235
+ {
236
+ "id": "acp-worker",
237
+ "command": "node",
238
+ "args": ["@stdiobus/workers-registry/workers/acp-worker"],
239
+ "instances": 2
240
+ },
241
+ {
242
+ "id": "echo-worker",
243
+ "command": "node",
244
+ "args": ["@stdiobus/workers-registry/workers/echo-worker"],
245
+ "instances": 1
246
+ }
247
+ ]
248
+ }
249
+ ```
250
+
251
+ ### Using with Kiro IDE (MCP Client)
252
+
253
+ Configure MCP-to-ACP Proxy in Kiro's MCP settings:
254
+
255
+ ```json
256
+ {
257
+ "mcpServers": {
258
+ "stdio-bus-acp": {
259
+ "command": "stdiobus-mcp-to-acp-proxy",
260
+ "env": {
261
+ "ACP_HOST": "localhost",
262
+ "ACP_PORT": "9000",
263
+ "AGENT_ID": "claude-acp"
264
+ }
265
+ }
266
+ }
267
+ }
268
+ ```
269
+
270
+ ---
271
+
272
+ ## Worker Documentation
273
+
274
+ ### ACP Worker
275
+
276
+ Full implementation of the Agent Client Protocol using the official `@agentclientprotocol/sdk`.
277
+
278
+ **Location:** `workers-registry/acp-worker/`
279
+
280
+ **Features:**
281
+ - Complete ACP protocol support (initialize, session management, prompts)
282
+ - MCP server integration for tool execution
283
+ - Session-based routing
284
+ - Graceful shutdown handling
285
+
286
+ **Build:**
287
+ ```bash
288
+ cd workers-registry/acp-worker
289
+ npm install
290
+ npm run build
291
+ ```
292
+
293
+ **Run with stdio Bus:**
294
+
295
+ Using Docker:
296
+ ```bash
297
+ docker run \
298
+ --name stdiobus-acp \
299
+ -p 9000:9000 \
300
+ -v $(pwd)/workers-registry:/workers-registry:ro \
301
+ -v $(pwd)/workers-registry/acp-worker/acp-worker-config.json:/config.json:ro \
302
+ stdiobus/stdiobus:latest \
303
+ --config /config.json --tcp 0.0.0.0:9000
304
+ ```
305
+
306
+ Using binary:
307
+ ```bash
308
+ ./stdio_bus --config workers-registry/acp-worker/acp-worker-config.json --tcp 0.0.0.0:9000
309
+ ```
310
+
311
+ **Configuration:** See `workers-registry/acp-worker/src/` for implementation details.
312
+
313
+ ---
314
+
315
+ ### Registry Launcher
316
+
317
+ Routes messages to any agent in the [ACP Registry](https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json).
318
+
319
+ **Location:** `workers-registry/acp-worker/src/registry-launcher/`
320
+
321
+ **Features:**
322
+ - Automatic agent discovery from ACP Registry
323
+ - Dynamic agent process management
324
+ - API key injection from configuration
325
+ - Session affinity routing
326
+
327
+ **Available Agents:**
328
+ - `claude-acp` - Claude Agent
329
+ - `goose` - Goose
330
+ - `cline` - Cline
331
+ - `github-copilot` - GitHub Copilot
332
+ - And many more from the registry
333
+
334
+ **Configuration:**
335
+ ```json
336
+ {
337
+ "pools": [{
338
+ "id": "registry-launcher",
339
+ "command": "node",
340
+ "args": ["@stdiobus/workers-registry/workers/registry-launcher", "./api-keys.json"],
341
+ "instances": 1
342
+ }]
343
+ }
344
+ ```
345
+
346
+ **Run:**
347
+
348
+ Using Docker:
349
+ ```bash
350
+ docker run \
351
+ --name stdiobus-registry \
352
+ -p 9000:9000 \
353
+ -v $(pwd)/workers-registry:/workers-registry:ro \
354
+ -v $(pwd)/workers-registry/acp-registry/registry-launcher-config.json:/config.json:ro \
355
+ -v $(pwd)/api-keys.json:/api-keys.json:ro \
356
+ stdiobus/stdiobus:latest \
357
+ --config /config.json --tcp 0.0.0.0:9000
358
+ ```
359
+
360
+ Using binary:
361
+ ```bash
362
+ ./stdio_bus --config workers-registry/acp-registry/registry-launcher-config.json --tcp 0.0.0.0:9000
363
+ ```
364
+
365
+ ---
366
+
367
+ ### MCP-to-ACP Proxy
368
+
369
+ Bridges MCP clients (like IDE) to ACP agents through stdio Bus.
370
+
371
+ **Location:** `workers-registry/mcp-to-acp-proxy/`
372
+
373
+ **Architecture:**
374
+ ```
375
+ IDE (MCP Client) → MCP-to-ACP Proxy → stdio Bus → Registry Launcher → ACP Agent
376
+ ```
377
+
378
+ **Configuration for IDE:**
379
+ ```json
380
+ {
381
+ "mcpServers": {
382
+ "stdio-bus-acp": {
383
+ "command": "node",
384
+ "args": ["@stdiobus/workers-registry/workers/mcp-to-acp-proxy"],
385
+ "env": {
386
+ "ACP_HOST": "0.0.0.0",
387
+ "ACP_PORT": "9000",
388
+ "AGENT_ID": "claude-acp"
389
+ }
390
+ }
391
+ }
392
+ }
393
+ ```
394
+
395
+ **Documentation:** See [workers-registry/mcp-to-acp-proxy/README.md](workers-registry/mcp-to-acp-proxy/README.md)
396
+
397
+ ---
398
+
399
+ ### Echo Worker
400
+
401
+ Simple reference implementation demonstrating the NDJSON worker protocol.
402
+
403
+ **Location:** `workers-registry/echo-worker/`
404
+
405
+ **Purpose:**
406
+ - Testing stdio Bus kernel functionality
407
+ - Reference implementation for custom workers
408
+ - Protocol documentation through code
409
+
410
+ **Run standalone:**
411
+ ```bash
412
+ echo '{"jsonrpc":"2.0","id":"1","method":"test","params":{"foo":"bar"}}' | node workers-registry/echo-worker/echo-worker.js
413
+ ```
414
+
415
+ **Run with stdio Bus:**
416
+
417
+ Using Docker:
418
+ ```bash
419
+ docker run \
420
+ --name stdiobus-echo \
421
+ -p 9000:9000 \
422
+ -v $(pwd)/workers-registry:/workers-registry:ro \
423
+ -v $(pwd)/workers-registry/echo-worker/echo-worker-config.json:/config.json:ro \
424
+ stdiobus/stdiobus:latest \
425
+ --config /config.json --tcp 0.0.0.0:9000
426
+ ```
427
+
428
+ Using binary:
429
+ ```bash
430
+ ./stdio_bus --config workers-registry/echo-worker/echo-worker-config.json --tcp 0.0.0.0:9000
431
+ ```
432
+
433
+ ---
434
+
435
+ ### MCP Echo Server
436
+
437
+ TypeScript MCP server example for testing MCP integration.
438
+
439
+ **Location:** `workers-registry/mcp-echo-server/`
440
+
441
+ **Tools provided:**
442
+ - `echo` - Echoes input text
443
+ - `reverse` - Reverses input text
444
+ - `uppercase` - Converts to uppercase
445
+ - `delay` - Echoes after a delay (for testing cancellation)
446
+ - `error` - Always returns an error (for testing error handling)
447
+
448
+ **Build:**
449
+ ```bash
450
+ cd workers-registry/mcp-echo-server
451
+ npm install
452
+ npm run build
453
+ ```
454
+
455
+ **Run:**
456
+ ```bash
457
+ node workers-registry/mcp-echo-server/dist/mcp-echo-server.js
458
+ ```
459
+
460
+ ---
461
+
462
+ ## stdio Bus Configuration
463
+
464
+ stdio Bus kernel is configured via JSON files. This repository includes example configurations for each worker.
465
+
466
+ ### Configuration File Structure
467
+
468
+ ```json
469
+ {
470
+ "pools": [
471
+ {
472
+ "id": "worker-id",
473
+ "command": "/path/to/executable",
474
+ "args": ["arg1", "arg2"],
475
+ "instances": 1
476
+ }
477
+ ],
478
+ "limits": {
479
+ "max_input_buffer": 1048576,
480
+ "max_output_queue": 4194304,
481
+ "max_restarts": 5,
482
+ "restart_window_sec": 60,
483
+ "drain_timeout_sec": 30,
484
+ "backpressure_timeout_sec": 60
485
+ }
486
+ }
487
+ ```
488
+
489
+ ### Pool Configuration
490
+
491
+ | Field | Type | Required | Description |
492
+ |-------|------|----------|-------------|
493
+ | `id` | string | Yes | Unique identifier for this worker pool |
494
+ | `command` | string | Yes | Path to the executable |
495
+ | `args` | string[] | No | Command-line arguments |
496
+ | `instances` | number | Yes | Number of worker instances (≥ 1) |
497
+
498
+ ### Limits Configuration
499
+
500
+ | Field | Type | Default | Description |
501
+ |-------|------|---------|-------------|
502
+ | `max_input_buffer` | number | 1048576 (1 MB) | Maximum input buffer size per connection |
503
+ | `max_output_queue` | number | 4194304 (4 MB) | Maximum output queue size per connection |
504
+ | `max_restarts` | number | 5 | Maximum worker restarts within restart window |
505
+ | `restart_window_sec` | number | 60 | Time window for counting restarts |
506
+ | `drain_timeout_sec` | number | 30 | Timeout for graceful shutdown |
507
+ | `backpressure_timeout_sec` | number | 60 | Timeout before closing connection when queue is full |
508
+
509
+ ### Example Configurations
510
+
511
+ **Minimal Configuration:**
512
+ ```json
513
+ {
514
+ "pools": [{
515
+ "id": "echo-worker",
516
+ "command": "node",
517
+ "args": ["@stdiobus/workers-registry/workers/echo-worker"],
518
+ "instances": 1
519
+ }]
520
+ }
521
+ ```
522
+
523
+ **High-Throughput Configuration:**
524
+ ```json
525
+ {
526
+ "pools": [{
527
+ "id": "acp-worker",
528
+ "command": "node",
529
+ "args": ["@stdiobus/workers-registry/workers/acp-worker"],
530
+ "instances": 4
531
+ }],
532
+ "limits": {
533
+ "max_input_buffer": 4194304,
534
+ "max_output_queue": 16777216,
535
+ "backpressure_timeout_sec": 120
536
+ }
537
+ }
538
+ ```
539
+
540
+ **Multiple Worker Pools:**
541
+ ```json
542
+ {
543
+ "pools": [
544
+ {
545
+ "id": "acp-worker",
546
+ "command": "node",
547
+ "args": ["@stdiobus/workers-registry/workers/acp-worker"],
548
+ "instances": 2
549
+ },
550
+ {
551
+ "id": "echo-worker",
552
+ "command": "node",
553
+ "args": ["@stdiobus/workers-registry/workers/echo-worker"],
554
+ "instances": 1
555
+ }
556
+ ]
557
+ }
558
+ ```
559
+
560
+ ---
561
+
562
+ ## NDJSON Protocol
563
+
564
+ Workers communicate with stdio Bus kernel via stdin/stdout using NDJSON (Newline-Delimited JSON).
565
+
566
+ ### Protocol Rules
567
+
568
+ 1. **Input (stdin):** stdio Bus sends JSON-RPC messages, one per line
569
+ 2. **Output (stdout):** Workers write JSON-RPC responses, one per line
570
+ 3. **Errors (stderr):** All logging and debug output goes to stderr
571
+ 4. **Never write non-JSON to stdout** - it will break the protocol
572
+
573
+ ### Message Types
574
+
575
+ **Request** (requires response):
576
+ ```json
577
+ {"jsonrpc":"2.0","id":"1","method":"test","params":{"foo":"bar"}}
578
+ ```
579
+
580
+ **Response:**
581
+ ```json
582
+ {"jsonrpc":"2.0","id":"1","result":{"status":"ok"}}
583
+ ```
584
+
585
+ **Notification** (no response):
586
+ ```json
587
+ {"jsonrpc":"2.0","method":"notify","params":{"event":"started"}}
588
+ ```
589
+
590
+ ### Session Affinity
591
+
592
+ Messages with the same `sessionId` are routed to the same worker instance:
593
+
594
+ ```json
595
+ {"jsonrpc":"2.0","id":"1","method":"test","sessionId":"sess-123","params":{}}
596
+ ```
597
+
598
+ Workers must preserve `sessionId` in responses for proper routing.
599
+
600
+ ### Graceful Shutdown
601
+
602
+ Workers must handle SIGTERM for graceful shutdown:
603
+ 1. Stop accepting new messages
604
+ 2. Complete in-flight processing
605
+ 3. Exit with code 0
606
+
607
+ stdio Bus sends SIGTERM during shutdown or worker restarts.
608
+
609
+ ---
610
+
611
+ ## Testing
612
+
613
+ ### Unit Tests
614
+
615
+ ```bash
616
+ # Run all tests
617
+ npm test
618
+
619
+ # Run specific test suites
620
+ npm run test:unit
621
+ npm run test:integration
622
+ npm run test:property
623
+ ```
624
+
625
+ ### Manual Testing
626
+
627
+ **Test echo worker:**
628
+ ```bash
629
+ # Start stdio Bus with Docker
630
+ docker run \
631
+ --name stdiobus-test \
632
+ -p 9000:9000 \
633
+ -v $(pwd)/workers-registry:/workers-registry:ro \
634
+ -v $(pwd)/workers-registry/echo-worker/echo-worker-config.json:/config.json:ro \
635
+ stdiobus/stdiobus:latest \
636
+ --config /config.json --tcp 0.0.0.0:9000
637
+
638
+ # Send test message
639
+ echo '{"jsonrpc":"2.0","id":"1","method":"echo","params":{"test":true}}' | nc localhost 9000
640
+
641
+ # Cleanup
642
+ docker stop stdiobus-test && docker rm stdiobus-test
643
+ ```
644
+
645
+ **Test ACP worker:**
646
+ ```bash
647
+ # Start stdio Bus with ACP worker
648
+ docker run \
649
+ --name stdiobus-acp-test \
650
+ -p 9000:9000 \
651
+ -v $(pwd)/workers-registry:/workers-registry:ro \
652
+ -v $(pwd)/workers-registry/acp-worker/acp-worker-config.json:/config.json:ro \
653
+ stdiobus/stdiobus:latest \
654
+ --config /config.json --tcp 0.0.0.0:9000
655
+
656
+ # Send initialize request
657
+ echo '{"jsonrpc":"2.0","id":"1","method":"initialize","params":{"clientInfo":{"name":"test","version":"1.0"}}}' | nc localhost 9000
658
+
659
+ # Cleanup
660
+ docker stop stdiobus-acp-test && docker rm stdiobus-acp-test
661
+ ```
662
+
663
+ **Test Registry Launcher:**
664
+ ```bash
665
+ # Start stdio Bus with Registry Launcher
666
+ docker run \
667
+ --name stdiobus-registry-test \
668
+ -p 9000:9000 \
669
+ -v $(pwd)/workers-registry:/workers-registry:ro \
670
+ -v $(pwd)/workers-registry/acp-registry/registry-launcher-config.json:/config.json:ro \
671
+ -v $(pwd)/api-keys.json:/api-keys.json:ro \
672
+ stdiobus/stdiobus:latest \
673
+ --config /config.json --tcp 0.0.0.0:9000
674
+
675
+ # Send message with agentId
676
+ echo '{"jsonrpc":"2.0","id":"1","method":"initialize","params":{"agentId":"claude-acp","clientInfo":{"name":"test"}}}' | nc localhost 9000
677
+
678
+ # Cleanup
679
+ docker stop stdiobus-registry-test && docker rm stdiobus-registry-test
680
+ ```
681
+
682
+ ---
683
+
684
+ ## Development
685
+
686
+ ### Creating a Custom Worker
687
+
688
+ 1. Workers must read NDJSON from stdin and write NDJSON to stdout
689
+ 2. All logging goes to stderr
690
+ 3. Handle SIGTERM for graceful shutdown
691
+ 4. Preserve `sessionId` in responses when present in requests
692
+
693
+ **Minimal worker template (Node.js):**
694
+
695
+ ```javascript
696
+ #!/usr/bin/env node
697
+ import readline from 'readline';
698
+
699
+ const rl = readline.createInterface({
700
+ input: process.stdin,
701
+ output: process.stdout,
702
+ terminal: false
703
+ });
704
+
705
+ rl.on('line', (line) => {
706
+ try {
707
+ const msg = JSON.parse(line);
708
+
709
+ if (msg.id !== undefined) {
710
+ // Request - send response
711
+ const response = {
712
+ jsonrpc: '2.0',
713
+ id: msg.id,
714
+ result: { /* your result */ }
715
+ };
716
+
717
+ if (msg.sessionId) {
718
+ response.sessionId = msg.sessionId;
719
+ }
720
+
721
+ console.log(JSON.stringify(response));
722
+ }
723
+ } catch (err) {
724
+ console.error('Parse error:', err.message);
725
+ }
726
+ });
727
+
728
+ process.on('SIGTERM', () => {
729
+ console.error('Shutting down...');
730
+ rl.close();
731
+ });
732
+
733
+ rl.on('close', () => process.exit(0));
734
+ ```
735
+
736
+ ### Project Structure
737
+
738
+ ```
739
+ workers-registry/
740
+ ├── acp-worker/ # Full ACP protocol implementation
741
+ │ ├── src/
742
+ │ │ ├── agent.ts # ACP Agent implementation
743
+ │ │ ├── index.ts # Main entry point
744
+ │ │ ├── mcp/ # MCP server integration
745
+ │ │ ├── session/ # Session management
746
+ │ │ └── registry-launcher/ # Registry Launcher implementation
747
+ │ └── tests/ # Test suites
748
+ ├── acp-registry/ # Registry Launcher configs
749
+ ├── echo-worker/ # Simple echo worker example
750
+ ├── mcp-echo-server/ # MCP server example
751
+ └── mcp-to-acp-proxy/ # MCP-to-ACP protocol bridge
752
+ ```
753
+
754
+ ---
755
+
756
+ ## API Reference
757
+
758
+ ### Package Exports
759
+
760
+ The package provides the following exports:
761
+
762
+ ```javascript
763
+ // Default export - ACP Worker
764
+ import worker from '@stdiobus/workers-registry';
765
+
766
+ // Named exports for specific workers
767
+ import {
768
+ acpWorker,
769
+ echoWorker,
770
+ mcpEchoServer,
771
+ mcpToAcpProxy,
772
+ workers // Metadata object
773
+ } from '@stdiobus/workers-registry/workers';
774
+ ```
775
+
776
+ ### Binary Commands
777
+
778
+ | Command | Description | Usage |
779
+ |---------|-------------|-------|
780
+ | `stdiobus-acp-worker` | ACP protocol worker | `stdiobus-acp-worker` |
781
+ | `stdiobus-registry-launcher` | Registry launcher | `stdiobus-registry-launcher <api-keys.json>` |
782
+ | `stdiobus-mcp-to-acp-proxy` | MCP-to-ACP proxy | `ACP_HOST=host ACP_PORT=port stdiobus-mcp-to-acp-proxy` |
783
+ | `stdiobus-echo-worker` | Echo worker | `stdiobus-echo-worker` |
784
+ | `stdiobus-mcp-echo-server` | MCP echo server | `stdiobus-mcp-echo-server` |
785
+
786
+ ### Environment Variables
787
+
788
+ **MCP-to-ACP Proxy:**
789
+ - `ACP_HOST` - stdio Bus host (default: `localhost`)
790
+ - `ACP_PORT` - stdio Bus port (default: `9000`)
791
+ - `AGENT_ID` - Target agent ID (e.g., `claude-acp`)
792
+
793
+ ---
794
+
795
+ ## Versioning
796
+
797
+ This package follows [Semantic Versioning](https://semver.org/):
798
+
799
+ - **MAJOR** version for incompatible API changes
800
+ - **MINOR** version for backwards-compatible functionality additions
801
+ - **PATCH** version for backwards-compatible bug fixes
802
+
803
+ Current version: `0.1.0` (pre-release)
804
+
805
+ ---
806
+
807
+ ## Troubleshooting
808
+
809
+ ### Installation Issues
810
+
811
+ **Node.js version mismatch:**
812
+ ```bash
813
+ node --version # Must be ≥20.0.0
814
+ nvm install 20 # If using nvm
815
+ ```
816
+
817
+ **Permission errors:**
818
+ ```bash
819
+ npm install -g @stdiobus/workers-registry # Global install (may need sudo)
820
+ # Or use npx
821
+ npx stdiobus-acp-worker
822
+ ```
823
+
824
+ ### Runtime Issues
825
+
826
+ **Command not found:**
827
+ ```bash
828
+ # Verify installation
829
+ npm list @stdiobus/workers-registry
830
+
831
+ # Check binary paths
832
+ which stdiobus-acp-worker
833
+
834
+ # Use npx as fallback
835
+ npx stdiobus-acp-worker
836
+ ```
837
+
838
+ **Worker crashes:**
839
+ ```bash
840
+ # Check stdio Bus logs
841
+ docker logs <container-name>
842
+
843
+ # Increase restart limits in config
844
+ {
845
+ "limits": {
846
+ "max_restarts": 10,
847
+ "restart_window_sec": 120
848
+ }
849
+ }
850
+ ```
851
+
852
+ **Connection refused:**
853
+ ```bash
854
+ # Verify stdio Bus is running
855
+ netstat -an | grep 9000
856
+
857
+ # Check Docker container status
858
+ docker ps | grep stdiobus
859
+ ```
860
+
861
+ ---
862
+
863
+ ## Contributing
864
+
865
+ Contributions are welcome! Please:
866
+
867
+ 1. Fork the repository
868
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
869
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
870
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
871
+ 5. Open a Pull Request
872
+
873
+ **Development setup:**
874
+ ```bash
875
+ git clone https://github.com/stdiobus/workers-registry
876
+ cd workers-registry
877
+ npm install
878
+ npm run build
879
+ npm test
880
+ ```
881
+
882
+ **Before submitting:**
883
+ - All tests pass (`npm test`)
884
+ - Code follows existing style
885
+ - Documentation is updated
886
+ - Workers handle SIGTERM gracefully
887
+ - No output to stdout except NDJSON protocol messages
888
+
889
+ ---
890
+
891
+ ## Resources
892
+
893
+ - [stdio Bus kernel](https://github.com/stdiobus/stdiobus) - Core protocol and daemon (source code)
894
+ - [stdio Bus on Docker Hub](https://hub.docker.com/r/stdiobus/stdiobus) - Docker images for easy deployment
895
+ - [stdio Bus Full Documentation](https://stdiobus.com) – Core protocol documentation
896
+ - [ACP Registry](https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json) - Available ACP agents
897
+ - [Agent Client Protocol SDK](https://www.npmjs.com/package/@agentclientprotocol/sdk) - Official ACP SDK
898
+ - [Model Context Protocol SDK](https://www.npmjs.com/package/@modelcontextprotocol/sdk) - Official MCP SDK
899
+ - [npm package](https://www.npmjs.com/package/@stdiobus/workers-registry) - Package on npm registry
900
+
901
+ ## Worker Documentation
902
+
903
+ - [ACP Worker](https://github.com/stdiobus/workers-registry/tree/main/workers-registry/acp-worker) - Full ACP protocol implementation
904
+ - [Registry Launcher](https://github.com/stdiobus/workers-registry/tree/main/workers-registry/acp-registry) - ACP Registry integration
905
+ - [Echo Worker](https://github.com/stdiobus/workers-registry/tree/main/workers-registry/echo-worker) - Reference implementation
906
+ - [MCP Echo Server](https://github.com/stdiobus/workers-registry/tree/main/workers-registry/mcp-echo-server) - MCP server example
907
+ - [MCP-to-ACP Proxy](https://github.com/stdiobus/workers-registry/tree/main/workers-registry/mcp-to-acp-proxy) - Protocol bridge
908
+ - [FAQ](https://github.com/stdiobus/workers-registry/blob/main/docs/FAQ.md) - Frequently asked questions
909
+
910
+ ---
911
+
912
+ ## Support
913
+
914
+ - **Issues:** [GitHub Issues](https://github.com/stdiobus/workers-registry/issues)
915
+ - **Discussions:** [GitHub Discussions](https://github.com/stdiobus/workers-registry/discussions)
916
+ - **Repository:** [github.com/stdiobus/workers-registry](https://github.com/stdiobus/workers-registry)
917
+
918
+ ---
919
+
920
+ ## License
921
+
922
+ Apache License 2.0
923
+
924
+ Copyright (c) 2025–present Raman Marozau, Target Insight Function.
925
+
926
+ See [LICENSE](https://github.com/stdiobus/workers-registry/blob/main/LICENSE) file for details.
927
+
928
+ ---
929
+
930
+ ## Changelog
931
+
932
+ See [CHANGELOG.md](https://github.com/stdiobus/workers-registry/blob/main/CHANGELOG.md) for version history and release notes.