Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Adds agora serve command to run a persistent WebSocket server that accepts incoming peer connections. Enables relay node deployments and always-on network presence.

Implementation

  • New CLI command: agora serve [--port 9473] [--name server-name]

    • Instantiates PeerServer with identity from config
    • Validates port range (1-65535)
    • Logs peer lifecycle events and received messages with timestamps
    • Graceful shutdown on SIGINT/SIGTERM
  • Event handling: Listens for peer-connected, peer-disconnected, and message-received events from PeerServer

  • Test coverage: 5 new tests covering startup, defaults, validation, and error cases with proper timeout cleanup

Usage

# Start server with defaults
agora serve

# Custom configuration
agora serve --port 8080 --name relay-node

Server output includes connection events and full message envelopes:

[2026-02-03T07:30:01.843Z] Agora server started
  Name: relay-node
  Public Key: 302a300506032b657003210032ba0a...
  WebSocket Port: 8080
  Listening for peer connections...

[2026-02-03T07:30:35.392Z] Peer connected: test-client (302a300506032b65...)
[2026-02-03T07:30:36.120Z] Message from 302a300506032b65...:
{
  "id": "abc123...",
  "type": "text",
  "sender": "302a300506032b65...",
  "payload": { "message": "Hello" }
}

Integrates with existing PeerServer without modifications. Relay/webhook modes deferred to future work.

Original prompt

This section details on the original issue you should resolve

<issue_title>feat: add 'serve' command for persistent WebSocket server</issue_title>
<issue_description>Add a CLI command to run a persistent Agora node:

agora serve --port 9473

What it should do:

  1. Start the WebSocket server (PeerServer from src/peer/server.ts already exists)
  2. Accept incoming peer connections
  3. Forward messages between connected peers
  4. Log received messages to stdout (or a file)

Integration points:

  • Use existing PeerServer class
  • Read identity from config (like other commands)
  • Auto-announce to connected peers

Stretch goals:

  • --relay mode: forward all messages between connected peers (relay server)
  • --webhook <url> mode: POST received messages to a webhook endpoint

This enables agents without public endpoints to participate in Agora by connecting to a relay, and allows OpenClaw instances to receive messages.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@rookdaemon
Copy link
Owner

@copilot Priority task. The PeerServer class already exists in src/peer/server.ts — you just need to wire it to a CLI command.

Minimal viable:

  1. Add 'serve' case to src/cli.ts
  2. Parse --port flag (default 9473)
  3. Load identity from config
  4. Create PeerServer, call start()
  5. Log 'Listening on port X'
  6. Keep process alive

The existing PeerServer handles WebSocket connections, peer announcements, and message forwarding. Just need the CLI entry point.

Test: node dist/cli.js serve --port 9999 should start a WebSocket server.

Copilot AI and others added 3 commits February 3, 2026 07:29
Co-authored-by: rookdaemon <258400181+rookdaemon@users.noreply.github.com>
… leaks

Co-authored-by: rookdaemon <258400181+rookdaemon@users.noreply.github.com>
Co-authored-by: rookdaemon <258400181+rookdaemon@users.noreply.github.com>
Copilot AI changed the title [WIP] Add serve command for persistent WebSocket server feat: add serve command for persistent WebSocket server Feb 3, 2026
Copilot AI requested a review from rookdaemon February 3, 2026 07:37
@rookdaemon rookdaemon marked this pull request as ready for review February 3, 2026 07:49
Copy link
Owner

@rookdaemon rookdaemon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serve command looks good. Tests cover startup and error cases. This enables bidirectional Agora communication.

@rookdaemon rookdaemon merged commit 8d04327 into main Feb 3, 2026
1 check passed
@rookdaemon rookdaemon deleted the copilot/add-serve-command-websocket-server branch February 3, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add 'serve' command for persistent WebSocket server

2 participants