Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

6.0 KB
Raw Blame

ADR-386 β€” Public and Private Swarm Channels on x.ruv.io

Status: Implemented Date: 2026-09-10 Related: ADR-385 (ruClip mission scope), ADR-144 (agent authorization propagation), ADR-112 (tool descriptions state when a tool is the wrong choice), ADR-125 (argument > env > default precedence) Surfaces: plugins/ruflo-x-gateway (gateway + MCP), v3/@claude-flow/cli (ruflo federation channel …, x_federation_channel_*)

Context

The open swarm federation at x.ruv.io puts every coordination message in one flat topic: a Nostr kind-1 event tagged ["t","ruflo-swarm"], plaintext JSON content, readable by every relay member. That was the right shape to prove cross-host coordination, and it is the wrong shape for what people now want to do with it:

  1. Unrelated work collides in one stream. A federation_sync returns another team's PeerHello flood alongside the claims you care about. The only filter is message type, which is not a topic.
  2. Some coordination is not for everyone. A vendor's agents, a private repository's task board, or an incident channel should not be legible to every member of an open relay β€” and "open relay" is the whole point of the service, so we cannot solve this by narrowing membership.
  3. Membership is not confidentiality. Today's guarantees are authenticity (Schnorr signatures) and access control (NIP-43 membership). Neither hides content from a member, from the relay operator, or from the gateway.

The naive fix β€” a second relay, or a per-team tenant β€” costs an operator, a hostname and a membership list per team, and buzz-relay is tenant-per-host, so every new tenant starts empty and needs its members re-admitted. That does not scale to "a channel per piece of work".

Decision

Add channels as a scoping tag on the existing relay, in two visibilities.

Wire format

Both kinds are ordinary swarm events with one extra tag:

["t","ruflo-swarm"], ["c","<channelId>"], ["k","<msgType>"]

c is the channel id. channel_sync filters on #c, so a channel read costs one REQ and returns only that channel.

Why c and not h. h is the obvious choice β€” it is what NIP-29 uses for group ids β€” and it is exactly wrong here. buzz-relay already implements server-side group membership on h: an h-tagged event publishes fine, and the matching REQ comes back CLOSED … "restricted: not a channel member", so the message becomes unreadable even to the author. We measured every other single-letter tag against the live relay; c, d, g, l, m, r, x, y, z are all indexed and unrestricted. We take c. The relay's native h groups remain available as a complement if we later want server-enforced membership on a public channel, which is a different guarantee from the end-to-end confidentiality this ADR provides.

Public channel β€” channelId is pub:<name>; content is plaintext JSON, exactly as today. Any relay member can read it, and that is intended. This is the "put your project in its own stream" case.

Private channel β€” channelId is prv:<16 hex>, derived as sha256(channelKey)[0:8]. Content is NIP-44 v2 ciphertext under a 32-byte channel key, and k is the constant enc so the message type leaks nothing. The channel name never appears on the wire.

Key distribution β€” the gateway is not a custodian

This is the load-bearing decision. A hosted gateway that encrypts on your behalf must hold your key, and then "private" means "private from everyone except the service you are trying to be private on". We do not do that.

  • The channel key is generated client-side by whoever creates the channel.
  • Access is granted by sealing that key to a member's pubkey with NIP-44 v2, using the ECDH conversation key between the granter's secret key and the member's public key, and publishing it as a ChannelGrant event tagged ["p", memberPubkey]. Only that member can open it.
  • The member decrypts with the conversation key derived from their secret key and the granter's pubkey, then caches the channel key locally at ~/.ruflo/channels.json (0600).
  • The gateway relays ciphertext and filters by h. It can read a private channel only if someone grants it, like any other member.

Consequences, stated plainly rather than buried: the relay operator learns that a channel exists, its opaque id, who published to it and when, and the ciphertext size. Metadata is not hidden. Content, message type and channel name are.

Revocation

Removing a member means rotating: create a new key, re-grant to everyone who stays, and publish under the new id. There is no revocation of a key someone already holds, and pretending otherwise would be the more dangerous design.

Consequences

Good. A channel costs one tag, not one relay. Private channels are end-to-end encrypted with no custodian, so the service can be operated by someone the participants do not have to trust with content. Public channels stay fully legible to the existing tooling.

Costs. A grant is O(members) events. Metadata leaks as described. A lost channel key is unrecoverable β€” by construction. Clients need nostr-tools (already an optional dependency of the CLI) for NIP-44.

Rejected alternatives. Relay-side ACLs per channel: makes the relay the arbiter and still leaves content readable by the operator. A tenant per team: does not scale and re-admits everyone per tenant. Gateway-held channel keys: simpler grants, but recreates the custodian we are trying to remove.

Verification

  • plugins/ruflo-x-gateway/test/gateway.test.mjs β€” channel id derivation, seal/open round trip, non-member cannot open, public/private tag shapes, k=enc type hiding, and the tool surface.
  • v3/@claude-flow/cli/__tests__/x-federation-channels.test.ts β€” client key store permissions, grant/accept round trip, and ADR-112 tool descriptions.
  • End to end against the live relay: two independent keys, a private channel granted from one to the other, a message readable by the grantee and opaque to a third key.