🔌 Zenoh P2P

Multi-instance auto-discovery and communication

Auto-Discovery Peer-to-Peer Real-time Streaming
🌐

DevDuck Swarm

Multiple DevDuck instances automatically find each other and communicate. Broadcast commands to all, or send to specific peers. No configuration needed.

🔄 How It Works

Zenoh uses multicast scouting to automatically discover peers on the same network. No central server required.

┌─────────────────────────────────────────────────────────────────────┐
│                     Zenoh Peer Network                              │
│                   (Multicast: 224.0.0.224:7446)                     │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   🦆 DevDuck-A  ◄──────────────────────►  🦆 DevDuck-B            │
│   (Terminal 1)        heartbeat           (Terminal 2)            │
│        │                                        │                   │
│        │    ┌──────────────────────────────┐    │                   │
│        └───►│  devduck/broadcast           │◄───┘                   │
│             │  "git pull && npm install"  │                        │
│             └──────────────────────────────┘                        │
│                          │                                          │
│                          ▼                                          │
│             ┌──────────────────────────────┐                        │
│             │  devduck/response/A/*       │                        │
│             │  streaming chunks...        │                        │
│             └──────────────────────────────┘                        │
│                                                                     │
│   🦆 DevDuck-C  ◄─────────  auto-discovered  ─────────►  ...        │
│   (Remote)                                                          │
└─────────────────────────────────────────────────────────────────────┘

⚡ Quick Start

Terminal 1 - Start First Instance

Terminal 1 — devduck
$ devduck
🦆 ✓ Zenoh peer: hostname-abc123
🦆 zenoh_peer(action="status")
🆔 Instance: hostname-abc123
👥 Peers: 0

Terminal 2 - Auto-Discovery

Terminal 2 — devduck
$ devduck
🦆 ✓ Zenoh peer: hostname-def456
🦆 zenoh_peer(action="list_peers")
👥 Discovered Peers (1):
🦆 hostname-abc123
Host: mycomputer
Seen: 2.1s ago

Broadcast to All Peers

Terminal 1 — broadcast
🦆 zenoh_peer(action="broadcast", message="what directory are you in?")
🦆 [hostname-def456] Processing...
I'm currently in /Users/cagatay/project-b
✅ [hostname-def456] Complete (12 chunks)

📡 Key Expressions

Zenoh uses key expressions for pub/sub messaging:

devduck/presence/{id} Heartbeat announcements (every 5s)
devduck/broadcast Commands to ALL peers
devduck/cmd/{id} Direct commands to specific peer
devduck/response/{requester}/{turn_id} Streaming responses back to requester

📋 Actions Reference

Action Description Parameters
start Start Zenoh networking (auto-joins peer mesh) connect, listen
stop Stop Zenoh networking
status Show current status and peer count
list_peers List all discovered peers
broadcast Send command to ALL peers message, wait_time
send Send command to specific peer peer_id, message, wait_time

🌍 Remote Connections

Connect DevDuck instances across different networks using TCP endpoints.

Connect to Remote Peer/Router

# Via environment variable
ZENOH_CONNECT="tcp/remote-host.example.com:7447" devduck

# Via tool parameter
zenoh_peer(action="start", connect="tcp/192.168.1.100:7447")

Listen for Remote Connections

# Via environment variable
ZENOH_LISTEN="tcp/0.0.0.0:7447" devduck

# Via tool parameter
zenoh_peer(action="start", listen="tcp/0.0.0.0:7447")

Zenoh Router (for complex topologies)

# Start a Zenoh router on a server
zenohd --listen tcp/0.0.0.0:7447

# Connect DevDuck instances to the router
ZENOH_CONNECT="tcp/router.example.com:7447" devduck

✨ Features

🔍

Auto-Discovery

Multicast scouting finds peers automatically on local network. Zero configuration.

📡

Real-time Streaming

Responses stream chunk-by-chunk as they're generated. Same experience as local.

🔄

Heartbeat & Cleanup

Peers announce presence every 5s. Stale peers auto-removed after 15s timeout.

🛡️

Isolated Execution

Each command spawns a fresh DevDuck instance. No concurrent invocation conflicts.

🌐

Cross-Network

Use TCP endpoints to connect peers across different networks or data centers.

📊

Context Injection

Zenoh peer status automatically injected into agent system prompt for awareness.

⚙️ Configuration

Variable Default Description
DEVDUCK_ENABLE_ZENOH true Auto-start Zenoh on DevDuck launch
ZENOH_CONNECT Remote endpoint(s) to connect to
ZENOH_LISTEN Endpoint(s) to listen on for remote connections

💡 Use Cases

🖥️

Multi-Terminal

Coordinate multiple DevDuck instances across terminal windows.

🚀

Distributed Tasks

Broadcast "git pull && npm install" to all development machines.

👀

Peer Monitoring

See all active DevDuck instances and their status.

🎯

Direct Messaging

Send specific tasks to specific instances by peer ID.

🐍 Python API

# Check Zenoh status
zenoh_peer(action="status")

# List discovered peers
zenoh_peer(action="list_peers")

# Broadcast to all peers
zenoh_peer(
    action="broadcast",
    message="run the test suite",
    wait_time=120.0  # Wait up to 2 minutes for responses
)

# Send to specific peer
zenoh_peer(
    action="send",
    peer_id="hostname-abc123",
    message="what files have you modified?",
    wait_time=60.0
)

# Start with remote connection
zenoh_peer(
    action="start",
    connect="tcp/192.168.1.100:7447",
    listen="tcp/0.0.0.0:7447"
)