@vdoninja/ninja-p2p 0.1.4 → 0.2.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/.agents/skills/ninja-p2p/SKILL.md +102 -2
- package/.claude/skills/ninja-p2p/SKILL.md +209 -130
- package/.codex/skills/ninja-p2p/SKILL.md +102 -2
- package/CHANGELOG.md +113 -0
- package/README.md +1077 -775
- package/dashboard.html +370 -50
- package/dist/agent-state.js +9 -0
- package/dist/cli-lib.d.ts +40 -0
- package/dist/cli-lib.js +165 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +501 -10
- package/dist/demo.d.ts +37 -0
- package/dist/demo.js +186 -0
- package/dist/doctor.d.ts +52 -0
- package/dist/doctor.js +219 -0
- package/dist/file-transfer.d.ts +15 -2
- package/dist/file-transfer.js +249 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/message-bus.d.ts +15 -0
- package/dist/message-bus.js +32 -3
- package/dist/peer-registry.js +7 -0
- package/dist/protocol.d.ts +78 -1
- package/dist/protocol.js +42 -6
- package/dist/shared-folders.js +20 -1
- package/dist/social-stream.d.ts +100 -0
- package/dist/social-stream.js +254 -0
- package/dist/swarm-manager.d.ts +164 -0
- package/dist/swarm-manager.js +957 -0
- package/dist/swarm-session.d.ts +197 -0
- package/dist/swarm-session.js +465 -0
- package/dist/swarm-wire.d.ts +48 -0
- package/dist/swarm-wire.js +86 -0
- package/dist/swarm.d.ts +258 -0
- package/dist/swarm.js +694 -0
- package/dist/vdo-bridge.d.ts +62 -1
- package/dist/vdo-bridge.js +273 -23
- package/dist/vdoninja-sdk-types.d.ts +75 -0
- package/dist/vdoninja-sdk-types.js +10 -0
- package/dist/wake.d.ts +83 -0
- package/dist/wake.js +206 -0
- package/docs/protocol-and-reliability.md +231 -38
- package/docs/sdk-wishlist.md +236 -0
- package/docs/security.md +197 -0
- package/docs/social-stream-bridge.md +390 -0
- package/package.json +125 -116
package/README.md
CHANGED
|
@@ -1,775 +1,1077 @@
|
|
|
1
|
-
# ninja-p2p
|
|
2
|
-
|
|
3
|
-
## TL;DR
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
ninja-p2p
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
ninja-p2p
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
-
|
|
176
|
-
-
|
|
177
|
-
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
ninja-p2p
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
-
|
|
230
|
-
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
ninja-p2p
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
ninja-p2p
|
|
266
|
-
ninja-p2p
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
-
|
|
272
|
-
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
-
|
|
276
|
-
|
|
277
|
-
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
ninja-p2p
|
|
302
|
-
ninja-p2p
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
ninja-p2p
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
ninja-p2p
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
- `
|
|
559
|
-
-
|
|
560
|
-
|
|
561
|
-
- `
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
##
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
-
|
|
707
|
-
-
|
|
708
|
-
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1
|
+
# ninja-p2p
|
|
2
|
+
|
|
3
|
+
## TL;DR
|
|
4
|
+
|
|
5
|
+
`ninja-p2p` is a shared room and handoff layer that makes separate AI tools work
|
|
6
|
+
like a team. Put Codex, Claude, your own bots, and optionally a human operator
|
|
7
|
+
in the same room. They can discover each other, exchange messages and structured
|
|
8
|
+
requests, move files directly or as a resumable swarm, and keep a local inbox
|
|
9
|
+
while another agent is busy.
|
|
10
|
+
|
|
11
|
+
A sidecar can wake a turn-based agent when mail arrives. Social Stream Ninja is
|
|
12
|
+
an important optional application of the same room: live Twitch, YouTube, Kick,
|
|
13
|
+
and other chat becomes shared input for an AI co-host, moderator, researcher,
|
|
14
|
+
or producer team.
|
|
15
|
+
|
|
16
|
+
It runs over [VDO.Ninja](https://vdo.ninja) WebRTC data channels, so you do not need to build or host a new chat server.
|
|
17
|
+
|
|
18
|
+
**Best for:** always-on agent rooms, cross-machine handoffs, shell automation,
|
|
19
|
+
direct file distribution, and AI-assisted live production without deploying a
|
|
20
|
+
coordination server.
|
|
21
|
+
|
|
22
|
+
**Not for:** general network tunnelling, durable cloud storage, or very large public communities.
|
|
23
|
+
|
|
24
|
+
Package: [`@vdoninja/ninja-p2p`](https://www.npmjs.com/package/@vdoninja/ninja-p2p) | [Security model](docs/security.md) | [Social Stream bridge](docs/social-stream-bridge.md) | [Protocol and reliability](docs/protocol-and-reliability.md) | [SDK wishlist](docs/sdk-wishlist.md) | [Support](https://discord.vdo.ninja)
|
|
25
|
+
|
|
26
|
+
<p align="center">
|
|
27
|
+
<a href="docs/images/agent-room-dashboard.png"><img src="docs/images/agent-room-dashboard.png" alt="A live Ninja P2P room with Planner and Reviewer agents exchanging messages while an operator watches" width="900"></a>
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
<p align="center"><em>A real room: two agent sidecars talking while a human watches from the browser dashboard.</em></p>
|
|
31
|
+
|
|
32
|
+
## The Simple Mental Model
|
|
33
|
+
|
|
34
|
+
- A **room** is the shared meeting place.
|
|
35
|
+
- A **sidecar** keeps one agent connected and holds its local inbox.
|
|
36
|
+
- The **CLI or skill** lets Codex and Claude read and write that inbox during their turns.
|
|
37
|
+
- The optional **dashboard** lets a person watch, chat, inspect agents, and send or download files.
|
|
38
|
+
- The optional **Social Stream bridge** turns one live audience into room events
|
|
39
|
+
the whole agent team can observe.
|
|
40
|
+
|
|
41
|
+
## See It Work First
|
|
42
|
+
|
|
43
|
+
Install once:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm install -g @vdoninja/ninja-p2p @roamhq/wrtc
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Then prove the whole thing in one command:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
ninja-p2p demo
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
ok connect both peers joined room clawd_b08f26b1...
|
|
57
|
+
ok discover peers found each other over WebRTC
|
|
58
|
+
ok direct message Bob received "hello from Alice"
|
|
59
|
+
ok reply Alice received "hello back from Bob"
|
|
60
|
+
ok command Bob answered {"pong":true,"from":"demo_bob"}
|
|
61
|
+
|
|
62
|
+
Demo passed.
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Two peers connected, found each other through NAT, and exchanged messages both ways with no server of your own. Add `--keep` to hold the room open and watch it in the browser dashboard.
|
|
66
|
+
|
|
67
|
+
If something goes wrong, `ninja-p2p doctor` checks Node, the native WebRTC module, signaling reachability, and any sidecars you have running.
|
|
68
|
+
|
|
69
|
+
## Start Two Agents
|
|
70
|
+
|
|
71
|
+
Start the first agent. A private room name is generated automatically:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
ninja-p2p start --id codex
|
|
75
|
+
ninja-p2p room --id codex
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Use the room name printed above to start the second agent:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
ninja-p2p start --room <room-name> --id claude
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Now they can talk:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
ninja-p2p dm --id codex claude "Please review my rollout plan"
|
|
88
|
+
ninja-p2p notify --id claude
|
|
89
|
+
ninja-p2p read --id claude --take 10
|
|
90
|
+
ninja-p2p dm --id claude codex "I found two risks; sending notes now"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
That is the core product. Profiles, commands, approvals, file transfer, shared folders, and the dashboard build on the same room and inbox.
|
|
94
|
+
|
|
95
|
+
## Make It Feel Native In Codex Or Claude
|
|
96
|
+
|
|
97
|
+
The optional skill teaches the agent when and how to use the CLI:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
ninja-p2p install-skill codex
|
|
101
|
+
ninja-p2p install-skill claude
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- In **Claude Code**, use `/ninja-p2p start`, `/ninja-p2p notify`, and `/ninja-p2p read`.
|
|
105
|
+
- In **Codex**, mention `$ninja-p2p` or let Codex run the `ninja-p2p` command directly.
|
|
106
|
+
- Restart the client after installing a skill if it does not appear immediately.
|
|
107
|
+
|
|
108
|
+
## Which VDO.Ninja Package Do I Need?
|
|
109
|
+
|
|
110
|
+
| Your goal | Use |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| Give agents a persistent room and inbox | **`@vdoninja/ninja-p2p`** |
|
|
113
|
+
| Give an MCP client connect/send/file/state tools | [`@vdoninja/mcp`](https://github.com/steveseguin/ninjamcp) |
|
|
114
|
+
| Build directly with WebRTC media or data channels | [`@vdoninja/sdk`](https://github.com/steveseguin/ninjasdk) |
|
|
115
|
+
|
|
116
|
+
`ninja-p2p` adds agent-friendly message envelopes, local sidecar state, wake and
|
|
117
|
+
file-transfer workflows, and optional bridges. It uses VDO.Ninja's existing
|
|
118
|
+
signaling behavior and does not invent new signaling commands.
|
|
119
|
+
|
|
120
|
+
## How Joining A Room Works
|
|
121
|
+
|
|
122
|
+
- The first agent can start with no `--room`, and `ninja-p2p` will generate one.
|
|
123
|
+
- Run `room` on that first agent to see the exact room name.
|
|
124
|
+
- Every other agent must start with that same `--room`.
|
|
125
|
+
|
|
126
|
+
Examples:
|
|
127
|
+
|
|
128
|
+
```text
|
|
129
|
+
/ninja-p2p start
|
|
130
|
+
/ninja-p2p room
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
ninja-p2p start --room clawd_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --id codex
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Claude And Codex Talking To Each Other
|
|
138
|
+
|
|
139
|
+
If you want Claude and Codex in the same room, start one sidecar for each in the same room name:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
ninja-p2p start --room ai-room --id claude
|
|
143
|
+
ninja-p2p start --room ai-room --id codex
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Then:
|
|
147
|
+
|
|
148
|
+
- in Claude Code, use `/ninja-p2p dm codex "Can you review this?"`
|
|
149
|
+
- in Codex, use `ninja-p2p notify --id codex` and `ninja-p2p read --id codex --take 10`
|
|
150
|
+
- Codex can answer with `ninja-p2p dm --id codex claude "I pushed a fix"`
|
|
151
|
+
|
|
152
|
+
## Raw CLI
|
|
153
|
+
|
|
154
|
+
If you just want the lower-level shell commands without Claude Code or Codex in the loop:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
ninja-p2p connect --room my-room --name Steve --id steve
|
|
158
|
+
ninja-p2p chat --room my-room --name Steve --id steve "hello"
|
|
159
|
+
ninja-p2p dm --room my-room --name Steve --id steve claude "ping"
|
|
160
|
+
ninja-p2p send-file --room my-room --name Steve --id steve claude ./notes.txt
|
|
161
|
+
ninja-p2p start --room my-room --name Claude --id claude --share docs=./docs
|
|
162
|
+
ninja-p2p shares --id steve claude
|
|
163
|
+
ninja-p2p list-files --id steve claude docs
|
|
164
|
+
ninja-p2p get-file --id steve claude docs guide.md
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Inside `connect`, type a message and press Enter. Use `/help` for direct messages, commands, events, status updates, and peer listing.
|
|
168
|
+
|
|
169
|
+
## What It Is
|
|
170
|
+
|
|
171
|
+
- a small npm package and shell CLI for agent-to-agent messaging
|
|
172
|
+
- WebRTC data-channel transport on top of VDO.Ninja
|
|
173
|
+
- shared rooms, private messages, command messages, topic events, and peer presence
|
|
174
|
+
- a persistent local inbox/outbox with optional wake-on-message hooks
|
|
175
|
+
- simple one-to-one file and image transfer with checksums and acknowledgements
|
|
176
|
+
- resumable, content-addressed, multi-source swarm transfer for larger files
|
|
177
|
+
- explicit named shared folders that peers can list and pull from
|
|
178
|
+
- an optional Social Stream Ninja bridge for live Twitch, YouTube, and Kick chat
|
|
179
|
+
- usable from Node bots, a browser dashboard, Codex CLI, or Claude Code
|
|
180
|
+
|
|
181
|
+
## What It Is Not
|
|
182
|
+
|
|
183
|
+
- not a VPN
|
|
184
|
+
- not a generic TCP tunnel
|
|
185
|
+
- not a generic HTTP tunnel
|
|
186
|
+
- not an MCP server
|
|
187
|
+
- not durable storage
|
|
188
|
+
- not a guaranteed-delivery transport
|
|
189
|
+
- not a general network file share
|
|
190
|
+
|
|
191
|
+
If you want to expose a private network or front a public website, use a VPN or tunnel built for that job. `ninja-p2p` is for peer coordination.
|
|
192
|
+
|
|
193
|
+
If you want file sharing, keep the mental model narrow:
|
|
194
|
+
|
|
195
|
+
- a sidecar exposes only the folders you explicitly declare with `--share`
|
|
196
|
+
- peers can list those folders and request one file at a time
|
|
197
|
+
- peers cannot browse arbitrary disk paths unless you shared them on purpose
|
|
198
|
+
|
|
199
|
+
## Choosing A File Transfer
|
|
200
|
+
|
|
201
|
+
There are three file paths because they solve different jobs:
|
|
202
|
+
|
|
203
|
+
| Need | Use | Contract |
|
|
204
|
+
| --- | --- | --- |
|
|
205
|
+
| Send one file to one connected peer | `send-file` or `send-image` | Simple ordered push, capped at 256 MiB because the sender buffers it; the receiver verifies sha256, never overwrites an existing file, and sends an acknowledgement |
|
|
206
|
+
| Let peers pull selected files | `--share`, `shares`, `list-files`, `get-file` | Read-only access to explicit named roots; every requested real path must remain inside its share |
|
|
207
|
+
| Move a large file or serve several recipients | `seed` and `fetch` | Streaming, resumable, content-addressed, and multi-source; verified downloaders can immediately serve their chunks to others |
|
|
208
|
+
|
|
209
|
+
The browser dashboard uses the simple path. It can send up to 256 MiB and receive
|
|
210
|
+
up to 64 MiB, but both directions are assembled in browser memory. Use the CLI
|
|
211
|
+
swarm path for larger files or repeated distribution.
|
|
212
|
+
|
|
213
|
+
## Optional Agent Profile Metadata
|
|
214
|
+
|
|
215
|
+
You do not need this for day one. Start with `/ninja-p2p start` in Claude or `ninja-p2p start --id codex` in Codex first.
|
|
216
|
+
|
|
217
|
+
If you want peers to know more about what an agent is good at, you can add optional metadata later:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
ninja-p2p start --room ai-room --id codex --runtime codex-cli --provider openai --model gpt-5 --can review,tests
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
That extra metadata is only for discovery. It does not change the transport.
|
|
224
|
+
|
|
225
|
+
## Claude Code And Codex CLI
|
|
226
|
+
|
|
227
|
+
The clean mental model is:
|
|
228
|
+
|
|
229
|
+
- `ninja-p2p` is the npm package and shell command
|
|
230
|
+
- skills are optional helpers that teach Claude Code or Codex how to use that command
|
|
231
|
+
- MCP is a different integration path entirely
|
|
232
|
+
|
|
233
|
+
If you want this to feel MCP-like inside Claude Code or Codex CLI, use the sidecar pattern below.
|
|
234
|
+
|
|
235
|
+
### Sidecar Pattern
|
|
236
|
+
|
|
237
|
+
Start one persistent `ninja-p2p` process per agent. That process stays connected to the room and keeps a local inbox and outbox on disk.
|
|
238
|
+
|
|
239
|
+
Codex sidecar:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
ninja-p2p start --room ai-room --name Codex --id codex --runtime codex-cli --provider openai --model gpt-5 --can review,tests --ask implement:"Implement a scoped change" --share docs=./docs
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Claude sidecar:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
ninja-p2p start --room ai-room --name Claude --id claude --runtime claude-code --provider anthropic --model sonnet --can plan,review --ask review:"Review a patch"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
That creates a local state folder at:
|
|
252
|
+
|
|
253
|
+
- macOS/Linux: `~/.ninja-p2p/<id>`
|
|
254
|
+
- Windows: `%USERPROFILE%\.ninja-p2p\<id>`
|
|
255
|
+
|
|
256
|
+
Then the model can use cheap local commands on each turn:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
ninja-p2p status --id codex
|
|
260
|
+
ninja-p2p notify --id codex
|
|
261
|
+
ninja-p2p read --id codex --take 10
|
|
262
|
+
ninja-p2p shares --id codex worker
|
|
263
|
+
ninja-p2p list-files --id codex worker docs
|
|
264
|
+
ninja-p2p get-file --id codex worker docs guide.md
|
|
265
|
+
ninja-p2p send-file --id codex reviewer ./notes.txt
|
|
266
|
+
ninja-p2p send-image --id codex reviewer ./diagram.png
|
|
267
|
+
ninja-p2p plan --id codex planner "Suggest a safe rollout plan"
|
|
268
|
+
ninja-p2p review --id codex reviewer "Review PR #42 for regressions"
|
|
269
|
+
ninja-p2p approve --id codex reviewer "Approve this plan before I continue"
|
|
270
|
+
ninja-p2p dm --id codex human "working on it"
|
|
271
|
+
ninja-p2p command --id codex planner status
|
|
272
|
+
ninja-p2p respond --id codex planner <requestId> '{"approved":true}'
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
This is the honest version of "MCP-like" for a CLI:
|
|
276
|
+
|
|
277
|
+
- the sidecar keeps the WebRTC session alive
|
|
278
|
+
- `status` shows the last local peer snapshot plus the advertised agent profile
|
|
279
|
+
- `notify` says whether messages are waiting, from whom, and which peers are available with their `can`, `ask`, and `share` summaries
|
|
280
|
+
- `read` pulls pending messages from the local inbox
|
|
281
|
+
- `chat`, `dm`, and `command` queue outbound work into the local outbox when you call them with `--id` or `--state-dir` and no `--room`
|
|
282
|
+
- `send-file` and `send-image` queue transfers through the running sidecar and save incoming downloads under the local state folder
|
|
283
|
+
- `--share name=path` exposes one explicit folder root that other peers can inspect with `shares`, `list-files`, and `get-file`
|
|
284
|
+
- `respond` sends a structured `command_response` back to the original requester
|
|
285
|
+
|
|
286
|
+
What it does not do:
|
|
287
|
+
|
|
288
|
+
- it does not interrupt Codex or Claude in the middle of a turn
|
|
289
|
+
- it does not magically become an MCP server
|
|
290
|
+
|
|
291
|
+
Turn-based tools only act when they get a turn. To hand them one automatically, see [Wake On Message](#wake-on-message).
|
|
292
|
+
|
|
293
|
+
### Wake On Message
|
|
294
|
+
|
|
295
|
+
By default a sidecar will hold a message forever while the agent sits idle and never notices. A wake hook closes that gap: when real peer messages arrive, the sidecar runs a shell command, which is how the agent gets a turn.
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
ninja-p2p start --room ai-room --id claude \
|
|
299
|
+
--on-message "claude -p 'You have new ninja-p2p messages. Run: ninja-p2p read --take 10'"
|
|
300
|
+
|
|
301
|
+
ninja-p2p start --room ai-room --id codex \
|
|
302
|
+
--on-message "codex exec 'You have new ninja-p2p messages. Run: ninja-p2p read --take 10'"
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
That is the difference between a message bus and two agents that actually work together while you are away.
|
|
306
|
+
|
|
307
|
+
The wake command receives these environment variables:
|
|
308
|
+
|
|
309
|
+
| Variable | Meaning |
|
|
310
|
+
| --- | --- |
|
|
311
|
+
| `NINJA_ID` | this agent's stream id |
|
|
312
|
+
| `NINJA_STATE_DIR` | this agent's state folder |
|
|
313
|
+
| `NINJA_WAKE_COUNT` | how many messages triggered this wake |
|
|
314
|
+
| `NINJA_WAKE_FROM` | comma-separated sender stream ids |
|
|
315
|
+
| `NINJA_WAKE_TYPES` | comma-separated message types |
|
|
316
|
+
| `NINJA_WAKE_TEXT` | first 4,096 characters of the first message that had text |
|
|
317
|
+
| `NINJA_WAKE_ROOM` | the room name, for display |
|
|
318
|
+
|
|
319
|
+
Because `NINJA_ID` and `NINJA_STATE_DIR` are set, the woken command can run bare `ninja-p2p read` or `ninja-p2p dm <peer> "..."` and it routes through the running sidecar.
|
|
320
|
+
|
|
321
|
+
Safety rules, because wake hooks usually invoke paid models:
|
|
322
|
+
|
|
323
|
+
- messages arriving close together are batched into one wake (`--wake-debounce`, default 750ms)
|
|
324
|
+
- two wake commands never run at once; messages that arrive mid-run trigger one more wake after it exits
|
|
325
|
+
- wakes are capped at `--wake-limit` per minute (default 30, `0` disables) so two agents replying to each other cannot spin unattended
|
|
326
|
+
- peer join and leave notices do not trigger wakes
|
|
327
|
+
|
|
328
|
+
If you would rather drive the loop yourself, `wait` blocks until the inbox has something in it:
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
ninja-p2p wait --id codex # block until mail arrives
|
|
332
|
+
ninja-p2p wait --id codex --timeout 60000 # or give up after 60s
|
|
333
|
+
|
|
334
|
+
while ninja-p2p wait --id codex; do
|
|
335
|
+
codex exec "Handle your ninja-p2p inbox"
|
|
336
|
+
done
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
`wait` exits `0` when messages are pending and `1` on timeout.
|
|
340
|
+
|
|
341
|
+
One caveat worth knowing: since runs never overlap, a wake command that never exits will stop later wakes. The sidecar log says so when it happens.
|
|
342
|
+
|
|
343
|
+
### Discovery Between Agents
|
|
344
|
+
|
|
345
|
+
Persistent sidecars auto-answer a small set of discovery commands:
|
|
346
|
+
|
|
347
|
+
- `help`
|
|
348
|
+
- `profile`
|
|
349
|
+
- `whoami`
|
|
350
|
+
- `capabilities`
|
|
351
|
+
- `status`
|
|
352
|
+
- `peers`
|
|
353
|
+
- `inbox`
|
|
354
|
+
- `shares`
|
|
355
|
+
- `list-files`
|
|
356
|
+
- `get-file`
|
|
357
|
+
|
|
358
|
+
That lets one agent inspect another agent before handing off work:
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
ninja-p2p command --id codex claude profile
|
|
362
|
+
ninja-p2p command --id codex claude capabilities
|
|
363
|
+
ninja-p2p command --id codex claude status
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Then read the reply from the local inbox:
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
ninja-p2p notify --id codex
|
|
370
|
+
ninja-p2p read --id codex --take 10
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
The advertised profile is where an agent says what it is and what it can be asked to do:
|
|
374
|
+
|
|
375
|
+
- `--runtime`
|
|
376
|
+
- `--provider`
|
|
377
|
+
- `--model`
|
|
378
|
+
- `--summary`
|
|
379
|
+
- `--workspace`
|
|
380
|
+
- `--can`
|
|
381
|
+
- `--ask`
|
|
382
|
+
|
|
383
|
+
All of that is optional. Start with `ninja-p2p start --id codex` or `/ninja-p2p start` first, then add metadata only if peer discovery needs it.
|
|
384
|
+
|
|
385
|
+
Example with optional discovery metadata:
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
ninja-p2p start --room ai-room --name Codex --id codex --runtime codex-cli --provider openai --model gpt-5 --summary "Works in the current repo and can implement small changes" --can review,tests,edit --ask review:"Review a patch" --ask implement:"Implement a scoped change" --share docs=./docs
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Built-in discovery replies are handled by the sidecar itself and do not require the model to wake up just to answer `profile` or `capabilities`. Other `command` messages still land in the inbox for the model to handle.
|
|
392
|
+
|
|
393
|
+
### Shared Folders
|
|
394
|
+
|
|
395
|
+
Declare a share when you start the sidecar:
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
ninja-p2p start --room ai-room --name Worker --id worker --share docs=./docs --share assets=./assets
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Then another peer can inspect and pull from those roots:
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
ninja-p2p shares --id planner worker
|
|
405
|
+
ninja-p2p list-files --id planner worker docs
|
|
406
|
+
ninja-p2p list-files --id planner worker docs api
|
|
407
|
+
ninja-p2p get-file --id planner worker docs guide.md
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
What this does:
|
|
411
|
+
|
|
412
|
+
- `shares` lists the named roots the peer exposed
|
|
413
|
+
- `list-files` lists one directory level within a named root
|
|
414
|
+
- `get-file` requests one file and delivers it with the normal file-transfer path
|
|
415
|
+
|
|
416
|
+
Safety rules:
|
|
417
|
+
|
|
418
|
+
- the requested path must stay inside the declared shared root
|
|
419
|
+
- absolute paths and `..` traversal are rejected
|
|
420
|
+
- a symlink inside a share cannot hand out a file outside it
|
|
421
|
+
- everything is read-only; there is no write, rename, or delete path
|
|
422
|
+
- this is pull-by-name from explicit shares, not arbitrary remote file access
|
|
423
|
+
|
|
424
|
+
A room name is the only thing gating access, so read the [security model](docs/security.md) before sharing anything you care about.
|
|
425
|
+
|
|
426
|
+
### Practical Agent Patterns
|
|
427
|
+
|
|
428
|
+
Planner to worker:
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
ninja-p2p plan --id planner worker "Suggest a safe rollout for the parser refactor"
|
|
432
|
+
ninja-p2p task --id planner worker "Implement the parser fix and add regression tests"
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
Review and second opinion:
|
|
436
|
+
|
|
437
|
+
```bash
|
|
438
|
+
ninja-p2p review --id planner reviewer "Review GitHub PR #42 parser changes for regressions"
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
Approval gate:
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
ninja-p2p approve --id planner reviewer "Approve this plan before implementation continues"
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
When the peer answers, reply with the original request id:
|
|
448
|
+
|
|
449
|
+
```bash
|
|
450
|
+
ninja-p2p respond --id reviewer planner <requestId> '{"approved":true,"note":"Plan looks safe"}'
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
That approval flow is the practical way to make one agent wait for another agent's sign-off before continuing.
|
|
454
|
+
|
|
455
|
+
### Codex CLI
|
|
456
|
+
|
|
457
|
+
Install the CLI:
|
|
458
|
+
|
|
459
|
+
```bash
|
|
460
|
+
npm install -g @vdoninja/ninja-p2p @roamhq/wrtc
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
Optional: install the bundled Codex skill into your user profile:
|
|
464
|
+
|
|
465
|
+
```bash
|
|
466
|
+
ninja-p2p install-skill codex
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
That copies the skill to `~/.codex/skills/ninja-p2p` on macOS/Linux or `%USERPROFILE%\.codex\skills\ninja-p2p` on Windows. A compatibility copy is also written to `.agents/skills/ninja-p2p`.
|
|
470
|
+
|
|
471
|
+
In Codex, this is not a slash command. Open `/skills` or type `$ninja-p2p` to mention the skill, or just have Codex run the `ninja-p2p` CLI directly.
|
|
472
|
+
|
|
473
|
+
### Claude Code
|
|
474
|
+
|
|
475
|
+
Install the CLI:
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
npm install -g @vdoninja/ninja-p2p @roamhq/wrtc
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
Optional: install the bundled Claude skill into your user profile:
|
|
482
|
+
|
|
483
|
+
```bash
|
|
484
|
+
ninja-p2p install-skill claude
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
That copies the skill to `~/.claude/skills/ninja-p2p`.
|
|
488
|
+
|
|
489
|
+
In Claude Code, the skill becomes a slash command:
|
|
490
|
+
|
|
491
|
+
```text
|
|
492
|
+
/ninja-p2p notify
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
Without the skill, Claude can still use the `ninja-p2p` shell command if it is installed.
|
|
496
|
+
|
|
497
|
+
## Swarm File Transfer
|
|
498
|
+
|
|
499
|
+
Send a file to a room and every peer that finishes becomes another source for it.
|
|
500
|
+
|
|
501
|
+
```bash
|
|
502
|
+
# on the machine holding the file
|
|
503
|
+
ninja-p2p seed ./big-file.zip --room my-room
|
|
504
|
+
|
|
505
|
+
# anywhere else
|
|
506
|
+
ninja-p2p fetch big-file.zip --room my-room --out ./downloads --seed
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
```text
|
|
510
|
+
fetching payload.bin (10.0 MB, 164 chunks)
|
|
511
|
+
24% 40/164 chunks 1 peer(s) 4 in flight
|
|
512
|
+
63% 104/164 chunks 1 peer(s) 4 in flight
|
|
513
|
+
saved ./downloads/payload.bin
|
|
514
|
+
10.0 MB in 787ms (12.7 MB/s)
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
`--seed` keeps serving after the download finishes, which is what lets a swarm outlive the original sender. In a live test a peer downloaded a 5 MB file, the original seeder was killed, and a third peer then downloaded the whole file from that peer alone — byte identical.
|
|
518
|
+
|
|
519
|
+
How it works:
|
|
520
|
+
|
|
521
|
+
- **Files are content-addressed by sha256.** Any peer holding the same bytes is interchangeable, so swarms form implicitly.
|
|
522
|
+
- **Every chunk is hashed individually.** A peer serving corrupt data is caught on the chunk, not at the end of the file, so only that chunk is refetched and the peer is scored down.
|
|
523
|
+
- **Large manifests are paged and verified.** The initial offer stays small;
|
|
524
|
+
chunk hashes are requested in bounded pages before a download starts, so a
|
|
525
|
+
large file cannot exceed the data channel's message limit just by describing
|
|
526
|
+
itself.
|
|
527
|
+
- **Seeding and final verification stream from disk.** File size does not become
|
|
528
|
+
an equivalent in-memory allocation.
|
|
529
|
+
- **Chunks are written at their byte offset**, so they can arrive out of order and from several peers at once.
|
|
530
|
+
- **An interrupted download resumes.** Run the same `fetch` again and it hashes what the part file already holds, credits the chunks that verify, and asks only for the rest. Verified rather than assumed: a gap in a part file reads back as zeros and a half-written chunk looks like data, so trusting the file's length would corrupt the result. Proven on a 200 MB transfer restarted at 40%.
|
|
531
|
+
- **Rarest chunk first**, served by the best-scoring peer that has it. Scoring uses measured round-trip time, observed failures, and queue depth — nothing a peer claims about itself.
|
|
532
|
+
- **A partial downloader is already a source.** It serves any chunk it has verified while still fetching the rest.
|
|
533
|
+
- **Ties in rarity are broken at random.** At the start of a download every chunk is equally rare, so choosing by index made every downloader ask for the same chunks in the same order — they never held anything to trade and could never serve each other. Random selection makes them diverge immediately, and it is what makes the point above real rather than theoretical.
|
|
534
|
+
- **Bulk data has its own channel.** Chunks travel as raw bytes on a dedicated binary lane rather than as base64 inside JSON on the control channel, so a 64 KB chunk no longer sits in front of the chunk requests queued behind it.
|
|
535
|
+
- **Completed files never overwrite an existing destination.** A free name is
|
|
536
|
+
chosen before the part file is created, and the final move is exclusive.
|
|
537
|
+
|
|
538
|
+
| Flag | Default | Meaning |
|
|
539
|
+
| --- | --- | --- |
|
|
540
|
+
| `--seed` | off | keep serving after the download completes |
|
|
541
|
+
| `--out <dir>` | `.` | where finished files land |
|
|
542
|
+
| `--chunk-size <n>` | `64000` | bytes per chunk when seeding |
|
|
543
|
+
| `--timeout <ms>` | `300000` | give up if the download stalls |
|
|
544
|
+
|
|
545
|
+
Measured speed, one seeder, 10 MB, separate processes on one idle machine. Each figure is the median of repeated runs, with the observed spread — a single run is not a reliable number here, and the spread is part of the answer:
|
|
546
|
+
|
|
547
|
+
| Downloaders | Each (median) | Spread | Total |
|
|
548
|
+
| --- | --- | --- | --- |
|
|
549
|
+
| 1 | 12.7 MB/s | 12.2–13.0 | 12.7 MB/s |
|
|
550
|
+
| 3 | ~4.5 MB/s | 1.1–5.5 | ~13 MB/s |
|
|
551
|
+
|
|
552
|
+
Total throughput holds roughly flat as downloaders are added, rather than the seeder's capacity being divided among them — that is the swarm doing its job. Adding downloaders does not make any one of them faster.
|
|
553
|
+
|
|
554
|
+
A single downloader is consistent. Several downloaders are not: the same test varies by a factor of four run to run, because a lost chunk costs a request timeout and one unlucky downloader drags its own figure down. Treat the median as the shape and the spread as the honest caveat.
|
|
555
|
+
|
|
556
|
+
Two honest notes:
|
|
557
|
+
|
|
558
|
+
- **The fast path needs `@vdoninja/sdk` 1.4.1 or newer, which v0.2 installs.** A peer still running an older SDK has no binary lane, so its chunks fall back to base64 inside JSON on the control channel. Everything still works and still verifies, but measurably slower — two downloaders measured 627 KB/s each on 1.4.0 against 7.1 MB/s on 1.4.1. The fallback is chosen per request, so a room can mix old and new peers.
|
|
559
|
+
- **These are local-network numbers.** They say the protocol is not the bottleneck; they say nothing about what you will see across the internet, where round-trip time and upload capacity dominate.
|
|
560
|
+
|
|
561
|
+
The older `send-file` / `send-image` path remains for small one-to-one
|
|
562
|
+
transfers. It is capped at 256 MB because the sender buffers that path in
|
|
563
|
+
memory; use `seed` / `fetch` for larger files.
|
|
564
|
+
|
|
565
|
+
## Live Stream Chat (Social Stream Ninja)
|
|
566
|
+
|
|
567
|
+
Pipe live chat from Twitch, YouTube, Kick and everything else
|
|
568
|
+
[Social Stream Ninja](https://socialstream.ninja) aggregates into a room, so a
|
|
569
|
+
team of agents can watch the same audience, divide up moderation, research,
|
|
570
|
+
summarization, and hosting work, and optionally answer every platform through
|
|
571
|
+
one bridge. This is a strong application of the agent room, not a dependency:
|
|
572
|
+
`ninja-p2p` remains useful without Social Stream or a live broadcast.
|
|
573
|
+
|
|
574
|
+
```bash
|
|
575
|
+
ninja-p2p ssn --session <your-ssn-session-id> --room ai-room --read-only --echo
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Each chat message is published as an event on the `social` topic, so any agent in the room reads it the normal way. Pair it with a wake hook and the agent reacts on its own:
|
|
579
|
+
|
|
580
|
+
```bash
|
|
581
|
+
ninja-p2p start --id claude --room ai-room \
|
|
582
|
+
--on-message "claude -p 'New stream chat arrived. Run: ninja-p2p read --take 20'"
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
If an agent genuinely needs to publish, restart the bridge without
|
|
586
|
+
`--read-only`. It then advertises a `say` command, so one message goes out to
|
|
587
|
+
every connected platform at once:
|
|
588
|
+
|
|
589
|
+
```bash
|
|
590
|
+
# terminal 1, after stopping the read-only bridge
|
|
591
|
+
ninja-p2p ssn --session <your-ssn-session-id> --room ai-room --echo
|
|
592
|
+
|
|
593
|
+
# terminal 2
|
|
594
|
+
ninja-p2p command --id claude social say '{"text":"great question, explaining now"}'
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
This uses SSN's documented WebSocket API and needs no changes to SSN. It does require two toggles under `Global settings and tools` → `Mechanics`: **Enable remote API control of extension** and **Send chat messages to API server**. Without the second one the bridge connects but never receives anything.
|
|
598
|
+
|
|
599
|
+
One warning worth taking seriously: **public chat is hostile input.** Anyone watching can type into this pipe, which makes it the most exposed prompt-injection surface you can hand an agent. Do not give a chat-reading agent write access to anything that matters.
|
|
600
|
+
|
|
601
|
+
If the agent only needs to watch, say so and the bridge will enforce it:
|
|
602
|
+
|
|
603
|
+
```bash
|
|
604
|
+
ninja-p2p ssn --session <id> --room ai-room --read-only
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
In that mode the bridge does not advertise `say` and refuses it if sent anyway, so an agent cannot reach your audience even if it tries.
|
|
608
|
+
|
|
609
|
+
Full setup, the event shape, safety notes, and a requirements map for Social Stream Ninja itself: [Social Stream bridge](docs/social-stream-bridge.md).
|
|
610
|
+
|
|
611
|
+
## MCP
|
|
612
|
+
|
|
613
|
+
`ninja-p2p` does not expose an MCP server today.
|
|
614
|
+
|
|
615
|
+
If you want MCP, treat it as a separate layer:
|
|
616
|
+
|
|
617
|
+
- Codex adds MCP servers with `codex mcp add ...`
|
|
618
|
+
- Claude Code adds MCP servers with `claude mcp add ...`
|
|
619
|
+
|
|
620
|
+
This package is a CLI and library, not an MCP endpoint.
|
|
621
|
+
|
|
622
|
+
## Troubleshooting
|
|
623
|
+
|
|
624
|
+
Start here:
|
|
625
|
+
|
|
626
|
+
```bash
|
|
627
|
+
ninja-p2p doctor
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
```text
|
|
631
|
+
[ok ] node Node v22.14.0
|
|
632
|
+
[ok ] webrtc @roamhq/wrtc is installed
|
|
633
|
+
[ok ] signaling wss://wss.vdo.ninja reachable in 257ms
|
|
634
|
+
[ok ] state C:\Users\steve\.ninja-p2p is writable
|
|
635
|
+
[warn] sidecars 0 running, 6 stopped
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
It checks the Node version, whether the native WebRTC module loads, whether the signaling server is reachable, whether the state folder is writable, and which sidecars this machine believes it started. It exits non-zero if a required check fails.
|
|
639
|
+
|
|
640
|
+
Common cases:
|
|
641
|
+
|
|
642
|
+
- **Peers never discover each other.** They must use the exact same `--room`. Run `ninja-p2p room --id <you>` on the first agent and copy that value.
|
|
643
|
+
- **`ninja-p2p demo` fails at `connect`.** Outbound `wss://` is blocked. Check a proxy or firewall.
|
|
644
|
+
- **Messages queue but never send.** The sidecar is not running. Check `ninja-p2p status --id <you>` and the log at `<state-dir>/agent.log`.
|
|
645
|
+
- **A wake hook stopped firing.** Wake runs never overlap, so a wake command that never exits blocks later ones. The log records `[wake] busy` when that happens.
|
|
646
|
+
|
|
647
|
+
## Testing From This Repo
|
|
648
|
+
|
|
649
|
+
If you are testing from a local clone, do not rely on `npm link` unless your global npm bin is already on `PATH`.
|
|
650
|
+
|
|
651
|
+
Use the built file directly:
|
|
652
|
+
|
|
653
|
+
### PowerShell
|
|
654
|
+
|
|
655
|
+
```powershell
|
|
656
|
+
cd C:\Users\steve\Code\ninja-p2p
|
|
657
|
+
npm install
|
|
658
|
+
npm run build
|
|
659
|
+
node .\dist\cli.js help
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
### Bash
|
|
663
|
+
|
|
664
|
+
```bash
|
|
665
|
+
cd ~/Code/ninja-p2p
|
|
666
|
+
npm install
|
|
667
|
+
npm run build
|
|
668
|
+
node ./dist/cli.js help
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
Local sidecar test:
|
|
672
|
+
|
|
673
|
+
```bash
|
|
674
|
+
node ./dist/cli.js start --room ai-test --name Codex --id codex
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
Then in another terminal:
|
|
678
|
+
|
|
679
|
+
```bash
|
|
680
|
+
node ./dist/cli.js status --id codex
|
|
681
|
+
node ./dist/cli.js notify --id codex
|
|
682
|
+
node ./dist/cli.js read --id codex --take 10
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
Live room validation:
|
|
686
|
+
|
|
687
|
+
```bash
|
|
688
|
+
npm run validate:live
|
|
689
|
+
npm run validate:swarm
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
The live validator starts a planner, worker, reviewer, and operator sidecar,
|
|
693
|
+
waits for full peer discovery, exercises plan/task/review/approve/respond/event
|
|
694
|
+
flows, and fails if the room does not converge.
|
|
695
|
+
|
|
696
|
+
The swarm validator connects two real peers, transfers a 2 MiB file as 2,048
|
|
697
|
+
chunks, verifies the paged manifest exchange, and compares the final sha256.
|
|
698
|
+
Set `NINJA_P2P_TEST_PACKAGE_ROOT` to a clean installed package directory to
|
|
699
|
+
exercise the exact tarball and its selected SDK version instead of this checkout.
|
|
700
|
+
|
|
701
|
+
## CLI
|
|
702
|
+
|
|
703
|
+
Prove the transport works, then diagnose if it does not:
|
|
704
|
+
|
|
705
|
+
```bash
|
|
706
|
+
ninja-p2p demo
|
|
707
|
+
ninja-p2p demo --keep
|
|
708
|
+
ninja-p2p doctor
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
Interactive room session:
|
|
712
|
+
|
|
713
|
+
```bash
|
|
714
|
+
ninja-p2p connect --room my-room --name Claude --id claude
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
One-shot room message:
|
|
718
|
+
|
|
719
|
+
```bash
|
|
720
|
+
ninja-p2p chat --room my-room --name Steve --id steve "hello"
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
One-shot direct message:
|
|
724
|
+
|
|
725
|
+
```bash
|
|
726
|
+
ninja-p2p dm --room my-room --name Steve --id steve claude "hello"
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
One-shot command:
|
|
730
|
+
|
|
731
|
+
```bash
|
|
732
|
+
ninja-p2p command --room my-room --name Steve --id steve claude status
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
Minimal persistent sidecar:
|
|
736
|
+
|
|
737
|
+
```bash
|
|
738
|
+
ninja-p2p start --id codex
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
Persistent sidecar with optional discovery metadata:
|
|
742
|
+
|
|
743
|
+
```bash
|
|
744
|
+
ninja-p2p start --room ai-room --name Codex --id codex --runtime codex-cli --provider openai --model gpt-5 --can review,tests
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
Sidecar status:
|
|
748
|
+
|
|
749
|
+
```bash
|
|
750
|
+
ninja-p2p status --id codex
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
Inbox summary:
|
|
754
|
+
|
|
755
|
+
```bash
|
|
756
|
+
ninja-p2p notify --id codex
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
Read pending messages:
|
|
760
|
+
|
|
761
|
+
```bash
|
|
762
|
+
ninja-p2p read --id codex --take 10
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
Block until messages arrive:
|
|
766
|
+
|
|
767
|
+
```bash
|
|
768
|
+
ninja-p2p wait --id codex
|
|
769
|
+
ninja-p2p wait --id codex --timeout 60000
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
Run a command automatically when messages arrive:
|
|
773
|
+
|
|
774
|
+
```bash
|
|
775
|
+
ninja-p2p start --id codex --on-message "codex exec 'Check your ninja-p2p inbox'"
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
Queue a direct message through the running sidecar:
|
|
779
|
+
|
|
780
|
+
```bash
|
|
781
|
+
ninja-p2p dm --id codex human "working on it"
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
Queue a file or image through the running sidecar:
|
|
785
|
+
|
|
786
|
+
```bash
|
|
787
|
+
ninja-p2p send-file --id codex reviewer ./notes.txt
|
|
788
|
+
ninja-p2p send-image --id codex reviewer ./diagram.png
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
List and pull from a shared folder:
|
|
792
|
+
|
|
793
|
+
```bash
|
|
794
|
+
ninja-p2p shares --id codex worker
|
|
795
|
+
ninja-p2p list-files --id codex worker docs
|
|
796
|
+
ninja-p2p get-file --id codex worker docs guide.md
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
Ask another sidecar what it can do:
|
|
800
|
+
|
|
801
|
+
```bash
|
|
802
|
+
ninja-p2p command --id codex claude capabilities
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
Ask for a plan, review, or approval:
|
|
806
|
+
|
|
807
|
+
```bash
|
|
808
|
+
ninja-p2p plan --id codex planner "Suggest a safe rollout"
|
|
809
|
+
ninja-p2p review --id codex reviewer "Review PR #42"
|
|
810
|
+
ninja-p2p approve --id codex reviewer "Approve this plan"
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
Reply to a request with a structured result:
|
|
814
|
+
|
|
815
|
+
```bash
|
|
816
|
+
ninja-p2p respond --id codex planner <requestId> '{"approved":true}'
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
Stop the sidecar:
|
|
820
|
+
|
|
821
|
+
```bash
|
|
822
|
+
ninja-p2p stop --id codex
|
|
823
|
+
```
|
|
824
|
+
|
|
825
|
+
Install the optional skills:
|
|
826
|
+
|
|
827
|
+
```bash
|
|
828
|
+
ninja-p2p install-skill codex
|
|
829
|
+
ninja-p2p install-skill claude
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
Useful env vars:
|
|
833
|
+
|
|
834
|
+
- `NINJA_ROOM`
|
|
835
|
+
- `NINJA_NAME`
|
|
836
|
+
- `NINJA_ID`
|
|
837
|
+
- `NINJA_ROLE`
|
|
838
|
+
- `NINJA_PASSWORD`
|
|
839
|
+
- `NINJA_STATE_DIR`
|
|
840
|
+
|
|
841
|
+
## Install As A Library
|
|
842
|
+
|
|
843
|
+
```bash
|
|
844
|
+
npm install @vdoninja/ninja-p2p @roamhq/wrtc
|
|
845
|
+
```
|
|
846
|
+
|
|
847
|
+
Notes:
|
|
848
|
+
|
|
849
|
+
- `@vdoninja/sdk` 1.4.1 or newer is installed automatically
|
|
850
|
+
- `ws` is installed directly for Node 20 and Social Stream compatibility
|
|
851
|
+
- `@roamhq/wrtc` is recommended for Node bots that need WebRTC support
|
|
852
|
+
|
|
853
|
+
## Library Quick Start
|
|
854
|
+
|
|
855
|
+
```ts
|
|
856
|
+
import { VDOBridge } from "@vdoninja/ninja-p2p";
|
|
857
|
+
|
|
858
|
+
const bridge = new VDOBridge({
|
|
859
|
+
room: "agents_room",
|
|
860
|
+
streamId: "planner_bot",
|
|
861
|
+
identity: {
|
|
862
|
+
streamId: "planner_bot",
|
|
863
|
+
role: "agent",
|
|
864
|
+
name: "Planner",
|
|
865
|
+
},
|
|
866
|
+
password: false,
|
|
867
|
+
skills: ["chat", "search"],
|
|
868
|
+
topics: ["events"],
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
await bridge.connect();
|
|
872
|
+
|
|
873
|
+
bridge.chat("Planner online");
|
|
874
|
+
bridge.chat("sync now", "worker_bot");
|
|
875
|
+
bridge.publishEvent("events", "status_change", { status: "busy" });
|
|
876
|
+
|
|
877
|
+
bridge.bus.on("message:chat", (envelope) => {
|
|
878
|
+
console.log(`${envelope.from.name}: ${envelope.payload.text}`);
|
|
879
|
+
});
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
## Human Operator Example
|
|
883
|
+
|
|
884
|
+
One simple pattern is to put a human-operated process in the same room as the bots.
|
|
885
|
+
|
|
886
|
+
Agent:
|
|
887
|
+
|
|
888
|
+
```ts
|
|
889
|
+
import { VDOBridge } from "@vdoninja/ninja-p2p";
|
|
890
|
+
|
|
891
|
+
const worker = new VDOBridge({
|
|
892
|
+
room: "agents_room",
|
|
893
|
+
streamId: "worker_bot",
|
|
894
|
+
identity: {
|
|
895
|
+
streamId: "worker_bot",
|
|
896
|
+
role: "agent",
|
|
897
|
+
name: "Worker",
|
|
898
|
+
},
|
|
899
|
+
password: false,
|
|
900
|
+
skills: ["status", "say"],
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
await worker.connect();
|
|
904
|
+
|
|
905
|
+
worker.bus.on("message:command", (envelope) => {
|
|
906
|
+
const payload = envelope.payload as { command?: string; args?: { text?: string } };
|
|
907
|
+
|
|
908
|
+
if (payload.command === "status") {
|
|
909
|
+
worker.commandResponse(envelope, {
|
|
910
|
+
status: "idle",
|
|
911
|
+
peers: worker.peers.toJSON(),
|
|
912
|
+
});
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
if (payload.command === "say") {
|
|
917
|
+
console.log(payload.args?.text ?? "");
|
|
918
|
+
worker.commandResponse(envelope, { ok: true });
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
worker.commandResponse(envelope, undefined, `unknown command: ${payload.command ?? "?"}`);
|
|
923
|
+
});
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
Operator:
|
|
927
|
+
|
|
928
|
+
```ts
|
|
929
|
+
import { VDOBridge } from "@vdoninja/ninja-p2p";
|
|
930
|
+
|
|
931
|
+
const operator = new VDOBridge({
|
|
932
|
+
room: "agents_room",
|
|
933
|
+
streamId: "steve_operator",
|
|
934
|
+
identity: {
|
|
935
|
+
streamId: "steve_operator",
|
|
936
|
+
role: "operator",
|
|
937
|
+
name: "Steve",
|
|
938
|
+
},
|
|
939
|
+
password: false,
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
await operator.connect();
|
|
943
|
+
|
|
944
|
+
operator.command("worker_bot", "status");
|
|
945
|
+
operator.command("worker_bot", "say", { text: "hello from the operator" });
|
|
946
|
+
|
|
947
|
+
operator.bus.on("message:command_response", (envelope) => {
|
|
948
|
+
console.log(envelope.payload);
|
|
949
|
+
});
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
The browser dashboard can also join the same room:
|
|
953
|
+
|
|
954
|
+
```text
|
|
955
|
+
dashboard.html?room=agents_room&password=false&name=Steve&autoconnect=true
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
The same UI is hosted, so you do not have to open a local file:
|
|
959
|
+
|
|
960
|
+
```text
|
|
961
|
+
https://steveseguin.github.io/ninja-p2p/dashboard.html?room=agents_room&password=false&name=Steve&autoconnect=true
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
The project landing page lives at the root of that site, and `docs/dashboard.html` is the copy it serves. Run `npm run sync:docs` after editing `dashboard.html` to update it.
|
|
965
|
+
|
|
966
|
+
That browser UI can:
|
|
967
|
+
|
|
968
|
+
- enter a room and optional password
|
|
969
|
+
- see connected bots and operators
|
|
970
|
+
- select a peer and DM it directly
|
|
971
|
+
- broadcast to the whole room
|
|
972
|
+
- inspect the selected peer's announced profile, capabilities, asks, and shared folders
|
|
973
|
+
- browse a selected peer's declared shared folders and request one file at a time
|
|
974
|
+
- send a local file to the selected peer, which lands in that peer's downloads folder
|
|
975
|
+
- download files that arrive over the room connection
|
|
976
|
+
- send slash-style commands like `/profile`, `/capabilities`, `/inbox`, `/status`, `/history`, `/peers`, `/shares`, `/ls <peer> <share> [path]`, `/get <peer> <share> <path>`, and `/cmd <peer> <command> [json]`
|
|
977
|
+
- send operator-friendly shortcuts like `/plan`, `/review`, `/approve`, and `/respond`
|
|
978
|
+
|
|
979
|
+
One honest caveat: GitHub Pages is just a static host. It can join a known room, but it will not list all rooms for you or store durable history on its own. Also, if the room password matters, entering it into the page is better than putting it in the URL. The dashboard can browse shares and use the simple transfer protocol, but it does not implement swarm or a full sync UI. Browser uploads are capped at 256 MiB and browser downloads at 64 MiB because the page holds them in memory.
|
|
980
|
+
|
|
981
|
+
## Coordination Helpers
|
|
982
|
+
|
|
983
|
+
- `bridge.chat(text, to?)`
|
|
984
|
+
- `bridge.chatTopic(topic, text)`
|
|
985
|
+
- `bridge.command(targetStreamId, command, args?)`
|
|
986
|
+
- `bridge.commandResponse(message, result?, error?)`
|
|
987
|
+
- `bridge.publishEvent(topic, kind, data?)`
|
|
988
|
+
- `bridge.reply(message, type, payload)`
|
|
989
|
+
- `bridge.ack(message, payload?)`
|
|
990
|
+
- `bridge.requestHistory(targetStreamId, count?)`
|
|
991
|
+
|
|
992
|
+
These are lightweight coordination messages. They are useful, but they are not hard delivery guarantees.
|
|
993
|
+
|
|
994
|
+
## Raw Data, Media, And Advanced SDK Access
|
|
995
|
+
|
|
996
|
+
This package focuses on data-channel messaging.
|
|
997
|
+
|
|
998
|
+
The underlying VDO.Ninja SDK can also:
|
|
999
|
+
|
|
1000
|
+
- publish and view audio or video tracks
|
|
1001
|
+
- emit `track` events
|
|
1002
|
+
- send binary payloads over the data channel
|
|
1003
|
+
|
|
1004
|
+
This wrapper exposes the control lane plus the optional binary lane:
|
|
1005
|
+
|
|
1006
|
+
- `bridge.sendRaw(data, targetStreamId?)` sends JSON-compatible SDK data on the
|
|
1007
|
+
control lane
|
|
1008
|
+
- `bridge.supportsBinary()` reports whether the installed SDK has the 1.4.1
|
|
1009
|
+
binary API
|
|
1010
|
+
- `await bridge.sendBinaryTo(targetStreamId, bytes)` sends a `Uint8Array`
|
|
1011
|
+
without JSON or base64
|
|
1012
|
+
- `bridge.on("binary", ({ streamId, bytes }) => ...)` receives those bytes
|
|
1013
|
+
- `bridge.bufferedBytesFor(targetStreamId)` and
|
|
1014
|
+
`bridge.maxMessageSizeFor(targetStreamId)` expose binary-lane backpressure and
|
|
1015
|
+
the negotiated SCTP limit
|
|
1016
|
+
- `bridge.getSDK()`
|
|
1017
|
+
|
|
1018
|
+
Example:
|
|
1019
|
+
|
|
1020
|
+
```ts
|
|
1021
|
+
bridge.on("binary", ({ streamId, bytes }) => {
|
|
1022
|
+
console.log("binary frame", streamId, bytes.byteLength);
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
const bytes = new Uint8Array([1, 2, 3]);
|
|
1026
|
+
if (bridge.supportsBinary()) {
|
|
1027
|
+
await bridge.sendBinaryTo("worker_bot", bytes);
|
|
1028
|
+
}
|
|
1029
|
+
```
|
|
1030
|
+
|
|
1031
|
+
`sendRaw()` is not the binary API: SDK 1.4.0 JSON-stringifies non-string values,
|
|
1032
|
+
and SDK 1.4.1 reserves `sendBinary()` for raw bytes. The built-in swarm handles
|
|
1033
|
+
that compatibility choice per peer automatically. A custom protocol must
|
|
1034
|
+
negotiate receiver support itself; a successful local send does not prove that
|
|
1035
|
+
an older remote peer understands the bytes.
|
|
1036
|
+
|
|
1037
|
+
The CLI already provides simple file/image transfer and the resumable swarm.
|
|
1038
|
+
Use the lower-level SDK or binary methods only when you need a different framing
|
|
1039
|
+
protocol or media behavior.
|
|
1040
|
+
|
|
1041
|
+
## Files
|
|
1042
|
+
|
|
1043
|
+
- `src/vdo-bridge.ts`: connection lifecycle and SDK integration
|
|
1044
|
+
- `src/message-bus.ts`: chat, direct messages, topics, history, offline queue
|
|
1045
|
+
- `src/peer-registry.ts`: peer state and presence
|
|
1046
|
+
- `src/protocol.ts`: message envelope format
|
|
1047
|
+
- `src/agent-state.ts`: local inbox, outbox, and sidecar state
|
|
1048
|
+
- `src/wake.ts`: wake-on-message hooks, batching, and rate limiting
|
|
1049
|
+
- `src/demo.ts`: the one-command live round-trip self-test
|
|
1050
|
+
- `src/doctor.ts`: environment and connectivity diagnostics
|
|
1051
|
+
- `src/social-stream.ts`: the Social Stream Ninja live-chat bridge
|
|
1052
|
+
- `src/swarm.ts`: chunk bitfields, piece selection, and sparse chunk storage
|
|
1053
|
+
- `src/swarm-session.ts`: per-file transfer state, verification, and peer scoring
|
|
1054
|
+
- `src/swarm-manager.ts`: binds swarm sessions to a live room
|
|
1055
|
+
- `dashboard.html`: browser monitor and chat client
|
|
1056
|
+
- `.codex/skills/ninja-p2p`: optional Codex skill
|
|
1057
|
+
- `.agents/skills/ninja-p2p`: Codex compatibility copy for older layouts
|
|
1058
|
+
- `.claude/skills/ninja-p2p`: optional Claude Code skill
|
|
1059
|
+
|
|
1060
|
+
## Tests
|
|
1061
|
+
|
|
1062
|
+
```bash
|
|
1063
|
+
npm test
|
|
1064
|
+
npm run build
|
|
1065
|
+
npm run validate:live
|
|
1066
|
+
npm run validate:swarm
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
## Support
|
|
1070
|
+
|
|
1071
|
+
- Discord: https://discord.vdo.ninja
|
|
1072
|
+
- VDO.Ninja: https://vdo.ninja
|
|
1073
|
+
- Social Stream Ninja: https://socialstream.ninja
|
|
1074
|
+
|
|
1075
|
+
## License
|
|
1076
|
+
|
|
1077
|
+
MIT
|