Files
ruflo/plugins
rUvandReuven 22ca3b018b feat(swarm): ADR-095 G2 — pluggable ConsensusTransport + Ed25519 message signing (step 1) (#1905)
* feat(swarm): ADR-095 G2 step 1 — pluggable ConsensusTransport + Ed25519 message signing

First concrete piece of ADR-095 G2 (hive-mind multi-process). The
consensus protocols (raft/byzantine/gossip in @claude-flow/swarm) used a
local EventEmitter for *everything* — both observability events
("leader.elected", "consensus.achieved") AND inter-node messages
(append-entries, vote requests, pre-prepare/prepare/commit). The latter
never crossed a process boundary: a node "sent" a message by emitting it
locally and synthesizing the peer's reply inline. That's the single-
process limitation #G2 names.

## What lands

`v3/@claude-flow/swarm/src/consensus/transport.ts`:
- `ConsensusTransport` interface — `send` (request-response), `broadcast`,
  `onMessage`, `peers`, `close`. Separates the inter-node-message
  dimension from the observability-event dimension (events stay on each
  protocol's own EventEmitter).
- `LocalTransport` + `LocalTransportRegistry` — in-process registry,
  the default. Matches current single-process behavior so nothing breaks.
  Supports optional Ed25519 signing + per-sender monotonic-seq replay
  defense when keypairs are configured.
- Real Ed25519 helpers via Node's built-in `crypto` (no new deps):
  `generateNodeKeyPair`, `signMessage`, `verifyMessage`,
  `canonicalizeForSigning` (deep-sorted-key JSON — deterministic across
  hosts), `messageDigest`.
- Exported from `consensus/index.ts`.

## CI guard (the user's ask: "include ci guards for new capabilities")

`plugins/ruflo-core/scripts/test-consensus-transport.mjs`, wired as a step
in the `mcp-roundtrip-smoke` job:
- Static: required exports present in swarm dist; **no `return true`
  signature-stub regression** (the original #G2 bug — `verifySignature()`
  returned true unconditionally).
- Behavioral: `LocalTransport` round-trip (send → peer handler → reply);
  Ed25519 verify is real (true for right key; false for wrong key /
  tampered payload / missing sig). 30s watchdog so CI never hangs.

## Tests

14 new tests in `__tests__/consensus-transport.test.ts` (sign/verify
round-trip, tampered-payload rejection, wrong-key rejection, fail-closed
on missing sig, canonicalization stability, LocalTransport send/broadcast/
peers/timeout/closed-peer, signed-transport round-trip, unsigned-rejected,
seq monotonicity). 186/186 swarm suite passes. Build clean.

## Remaining for G2 (subsequent commits)

- FederationTransport adapter (ADR-104 WS wire)
- Wire raft/byzantine/gossip to accept an injected ConsensusTransport
- Replace byzantine-coordinator verifySignature()→true with real verifyMessage
- Per-strategy correctness: BFT f<n/3 vote counting; Raft term/log replication
- Failure-injection tests

ADR-095 G2 status section updated.

Tracks #1872

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(swarm): ADR-095 G2 step 2 — wire ByzantineConsensus to ConsensusTransport + sha256 digests

Second piece of ADR-095 G2. ByzantineConsensus now accepts an optional
`transport: ConsensusTransport` in its config:

- When set, PBFT messages (pre-prepare / prepare / commit) actually go
  over the transport (signed if the transport has a keypair) instead of
  being `emit`ted into the void. Inbound transport messages are routed
  back into `handlePrePrepare` / `handlePrepare` / `handleCommit`.
- When unset, behavior is unchanged: messages emit as `message.broadcast`
  / `message.sent` events for an external relay layer (the legacy
  single-process path). The `emit`s also stay when a transport IS wired,
  so observers don't break.
- Transport broadcast failures are non-fatal at the protocol layer — the
  proposal simply times out, which is the correct failure mode (lose
  liveness, never commit incorrectly).

Also: `computeDigest` was a 32-bit string-hash "for demonstration" —
replaced with sha256. PBFT relies on the digest uniquely identifying the
request being agreed on; a 32-bit hash has trivial collisions. Removed
the toy hash entirely (no test depended on it).

Tests: 3 new in `__tests__/byzantine-transport.test.ts` — emit-only when
no transport (legacy unchanged); broadcasts go over transport AND emit
when wired (and digests are 64-hex sha256); inbound transport messages
route into the PBFT handlers (a pre-prepare in → a prepare out over the
transport). 189/189 swarm suite passes. consensus-transport CI guard
green. Build clean.

Remaining for G2: same wiring for raft.ts + gossip.ts; FederationTransport
adapter; per-strategy correctness (BFT f<n/3 vote counting — the current
`2f+1` thresholds are right but a single node fabricates the quorum
locally; Raft term/log replication); failure-injection tests.

Tracks #1872 · branch feat/adr-095-g2-hive-mind-ws-transport

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(swarm): ADR-095 G2 step 3 — wire RaftConsensus to ConsensusTransport with real receiver rules

Third piece of ADR-095 G2. RaftConsensus now accepts an optional
`transport: ConsensusTransport`:

- Sender side: `requestVote(peerId)` / `appendEntries(peerId, entries)`
  go over the transport as real request-response RPCs (RequestVote /
  AppendEntries) instead of mutating the local fake-peer map. On a
  higher-term reply, the node steps down (§5.1).
- Receiver side (`handleInboundRaftMessage`): proper Raft rules —
    • RequestVote: grant iff `term >= currentTerm` AND (haven't voted this
      term OR voted for this candidate) AND candidate's log is at least as
      up-to-date (lastLogTerm/lastLogIndex comparison). Adopts a higher
      term, resets the election timer on grant.
    • AppendEntries: reject if `term < currentTerm`; else become follower,
      reset the election timer, append entries by index, advance
      `commitIndex` to `min(leaderCommit, lastLogIndex)`.
- Legacy no-transport path unchanged (single-process in-memory peer map).

This is the "Raft term/log replication correctness" piece from the ADR.
(Full prevLogIndex/prevLogTerm conflict resolution is the next refinement;
the current append-by-index is correct for the heartbeat + sequential-
append cases the consensus engine actually exercises.)

Tests: 5 new in `__tests__/raft-transport.test.ts` — vote granted for an
up-to-date candidate; second different candidate denied (vote-once-per-
term); stale-term candidate denied; behind-log candidate denied; valid
AppendEntries accepted + commitIndex updated; stale-term AppendEntries
rejected with the follower's term reported. 194/194 swarm suite passes.
Build clean. consensus-transport CI guard green.

Remaining for G2: same wiring for gossip.ts; FederationTransport adapter
(ADR-104 WS wire); BFT f<n/3 vote-counting correctness; failure-injection
tests; cross-host validation; build/publish.

Tracks #1872 · branch feat/adr-095-g2-hive-mind-ws-transport

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(swarm): ADR-095 G2 step 4 — FederationTransport (ConsensusTransport over the ADR-104 WS wire)

Fourth piece of ADR-095 G2 — the multi-host transport option.

`v3/@claude-flow/swarm/src/consensus/federation-transport.ts`:
- `FederationTransport implements ConsensusTransport` — backed by the
  federation plugin's ADR-104 WS wire (agentic-flow/transport/loader).
- Structural dependency, not a package dep: takes an
  `AgenticFlowTransportLike` instance by injection (the `loadQuicTransport`
  result satisfies it) plus consensus-level metadata (this node's id, how
  to address peers, who the peers are). @claude-flow/swarm stays zero-dep;
  the wiring layer (hive-mind + federation) supplies the transport.
- Layers request-response on top of fire-and-forget WS delivery via
  per-message correlation ids + a pending-replies map + per-call timeout.
  Uses ADR-104 stream-mux (`streamId='ruflo-consensus'`) so consensus
  traffic doesn't interleave with application traffic.
- Optional Ed25519 signing — outbound signed, inbound verified against the
  sender's published pubkey (resolvePeerPublicKey), per-sender monotonic-
  seq replay defense. Fail-closed: unverifiable inbound is dropped.
- Exported from `consensus/index.ts` (+ `AgenticFlowTransportLike` /
  `FederationTransportOptions` types).

Tests: 7 new in `__tests__/federation-transport.test.ts` using a mock
in-memory mesh — send→handler→reply correlation; broadcast to all peers;
no-address rejection; send timeout; peers() excludes self; signed
round-trip (seq increments, signature present); unsigned inbound dropped
at a signing-enabled node (sender's send times out, handler never runs).
201/201 swarm suite passes. Build clean. consensus-transport CI guard
extended to assert FederationTransport is exported — green.

Remaining for G2: wire gossip.ts to the transport; BFT f<n/3 vote-
counting correctness (real vote aggregation across distinct senders, not
a locally-fabricated quorum); failure-injection tests; cross-host
validation (mac↔ruvultra over tailscale, root); build/publish; then merge.

Tracks #1872 · branch feat/adr-095-g2-hive-mind-ws-transport

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(swarm): ADR-095 G2 step 5 — wire GossipConsensus to transport + BFT f-from-cluster-size

Fifth piece of ADR-095 G2 — completes the protocol-wiring trio and adds
the BFT fault-tolerance correctness fix.

## GossipConsensus transport wiring
- `GossipConfig.transport?` — when set, `sendToNeighbor` actually sends
  the gossip message over the transport (signed if signing is on) instead
  of mutating the local fake-neighbor map. Inbound gossip routes into the
  merge logic via `handleInboundGossipMessage`, deduped by message id.
- Legacy no-transport path preserved.

## BFT fault tolerance correctness
- `f` (`maxFaultyNodes`) was hardcoded to 1 in the config default, so a
  7- or 10-node cluster ran with the same `2f+1=3` quorum as a 4-node one
  — wrong. Now `byzantineF()` derives `f = floor((n-1)/3)` from the actual
  cluster size (n = self + known peers), clamped to ≥1. `config.maxFaultyNodes`,
  when set, acts as an *upper cap* (never exceed what the operator declared
  the cluster can tolerate). The three `2f+1` quorum checks (vote /
  handlePrepare / handleCommit) now use the cluster-derived `f`.
- Dropped the `?? 1` config default so an operator who doesn't pass
  `maxFaultyNodes` gets the cluster-derived behavior, not a silent cap of 1.

## Tests
- 3 new gossip-transport tests (messages go over transport with hops/path
  incremented; inbound deduped by id; non-gossip ignored).
- 5 new byzantine-f tests (f scales 4→1, 7→2, 10→3; explicit cap honored;
  no-cap follows cluster size; 3-node clamps to 1).
- 210/210 swarm suite passes. Build clean. consensus-transport CI guard green.

ADR-095 G2 status section updated — all three protocols now wired,
FederationTransport landed, Ed25519 sig verify real, BFT correctness done,
Raft receiver rules done. Remaining: failure-injection tests, cross-host
validation, merge.

Tracks #1872 · branch feat/adr-095-g2-hive-mind-ws-transport

Co-Authored-By: RuFlo <ruv@ruv.net>

* test(swarm): ADR-095 G2 step 6 — failure-injection tests (f<n/3 BFT, f<n/2 Raft)

Sixth piece of ADR-095 G2 — the failure-injection coverage the ADR calls for.

## BFT — prepare/commit quorum under f-bounded faults
`injectQuorum()` builds one ByzantineConsensus with a configured cluster
size (so byzantineF() derives f = floor((n-1)/3)), feeds it a pre-prepare
(creates the proposal), then N distinct external prepares + M distinct
external commits, and reports whether `consensus.achieved` fired. Because
the node contributes 1 prepare + 1 commit of its own, 2f external messages
of each kind hit the 2f+1 quorum.
  - 4-node (f=1): 2 ext prepares + 2 ext commits → reached; 1 ext commit → NOT
  - 7-node (f=2): 4 + 4 → reached (quorum 5); 3 ext commits → NOT
  - 10-node + maxFaultyNodes:1 cap → f stays 1, 2 ext commits suffice

## Raft — election under vote majority/minority
`tallyVotes()` drives a RequestVote round from a candidate to all voters
over LocalTransport; silenced voters never reply (their handler is a no-op)
so the candidate's `send` to them times out → no vote. Tallies grants
including the self-vote.
  - 5-node, all reply → 5 votes (≥ majority 3) → wins
  - 5-node, 2 silent → 3 votes (= majority) → wins
  - 5-node, 3 silent → 2 votes (< majority) → loses

(The full multi-node PBFT cascade over the synchronous LocalTransport is
order-sensitive and flaky as an integration test — the direct
message-injection form above tests the threshold property robustly. A
real-WS cross-host cascade test belongs in the federation cross-host
validation step, not the unit suite.)

218/218 swarm suite passes. Build clean.

This completes the per-strategy correctness + failure-injection items.
Remaining for G2: cross-host validation (mac↔ruvultra over tailscale,
root); merge PR #1905.

Tracks #1872 · branch feat/adr-095-g2-hive-mind-ws-transport

Co-Authored-By: RuFlo <ruv@ruv.net>

---------

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-05-11 09:52:46 -04:00
..

Ruflo Plugins

32 Claude Code plugins for agent-powered development workflows. Load with --plugin-dir.

Quick Start

# Load specific plugins
claude --plugin-dir plugins/ruflo-core --plugin-dir plugins/ruflo-swarm

# Load all plugins
claude $(ls -d plugins/ruflo-*/ | sed 's|^|--plugin-dir |' | tr '\n' ' ')

Plugin Catalog

Core & Coordination

Plugin Description
ruflo-core MCP server, status, doctor, coder/researcher/reviewer agents
ruflo-swarm Swarm topologies (hierarchical, mesh), Monitor streaming
ruflo-autopilot Autonomous /loop task completion with prediction
ruflo-loop-workers 12 background workers via /loop or CronCreate
ruflo-workflows Workflow templates, parallel execution, branching

Memory & Intelligence

Plugin Description
ruflo-agentdb AgentDB with HNSW vector search (150x-12,500x faster)
ruflo-rag-memory SOTA RAG — hybrid search, Graph RAG, MMR diversity, memory bridge
ruflo-rvf Portable RVF memory format, session persistence
ruflo-ruvector ruvector — FlashAttention-3, Graph RAG, hybrid search, 103 MCP tools, Brain AGI
ruflo-knowledge-graph Entity extraction, relation mapping, pathfinder traversal
ruflo-intelligence SONA neural patterns, trajectory learning, model routing
ruflo-daa Dynamic Agentic Architecture, cognitive patterns

Architecture & Methodology

Plugin Description
ruflo-adr ADR lifecycle — create, index, supersede, compliance checking
ruflo-ddd DDD scaffolding — bounded contexts, aggregates, domain events
ruflo-sparc SPARC methodology with 5 phases and quality gates

Quality & Security

Plugin Description
ruflo-security-audit CVE scanning, dependency vulnerability checks
ruflo-aidefence Prompt injection detection, PII scanning
ruflo-testgen Test gap detection, TDD London School workflow
ruflo-browser Playwright browser automation and testing

Development Tools

Plugin Description
ruflo-jujutsu Diff analysis, risk scoring, reviewer recommendations
ruflo-docs Doc generation, drift detection, API docs
ruflo-ruvllm Local LLM inference, MicroLoRA, chat formatting
ruflo-wasm WASM agent sandboxing and gallery
ruflo-plugin-creator Scaffold and validate new plugins
ruflo-migrations Database schema migration management
ruflo-observability Structured logging, tracing, metrics correlation
ruflo-cost-tracker Token usage tracking, budget alerts, cost optimization

Domain-Specific

Plugin Description
ruflo-goals GOAP planning, deep research, horizon tracking
ruflo-federation Zero-trust cross-installation agent federation
ruflo-iot-cognitum Cognitum Seed IoT — trust scoring, anomaly detection, fleet management
ruflo-neural-trader neural-trader — 4 agents, LSTM/Transformer, Rust/NAPI backtesting, 112+ MCP tools
ruflo-market-data Market data ingestion, OHLCV vectorization, pattern matching
Use Case Plugins
Feature development ruflo-core + ruflo-swarm + ruflo-testgen + ruflo-ddd
Security audit ruflo-core + ruflo-security-audit + ruflo-aidefence
Architecture work ruflo-core + ruflo-adr + ruflo-ddd + ruflo-sparc
Deep research ruflo-core + ruflo-goals + ruflo-rag-memory + ruflo-intelligence
Vector search ruflo-core + ruflo-ruvector + ruflo-rag-memory + ruflo-knowledge-graph
IoT development ruflo-core + ruflo-iot-cognitum + ruflo-agentdb
Trading systems ruflo-core + ruflo-neural-trader + ruflo-market-data + ruflo-ruvector
Full stack All 32 plugins

npm Package Integration

Several plugins wrap standalone npm packages for deeper functionality:

Plugin npm Package What It Adds
ruflo-neural-trader neural-trader 112+ MCP tools, Rust/NAPI engine, LSTM/Transformer models
ruflo-ruvector ruvector 103 MCP tools, FlashAttention-3, Graph RAG, Brain AGI
# Install backing packages
npm install neural-trader ruvector

# Add as MCP servers (optional, for direct tool access)
claude mcp add neural-trader -- npx neural-trader mcp start
claude mcp add ruvector -- npx ruvector mcp start

Plugin Structure

Each plugin follows the Claude Code plugin specification:

ruflo-<name>/
  .claude-plugin/plugin.json    # Plugin manifest
  agents/<name>.md              # Agent definitions (frontmatter: name, description, model)
  commands/<name>.md            # CLI command mappings
  skills/<name>/SKILL.md        # Interactive skills (frontmatter: name, description, argument-hint, allowed-tools)
  README.md                     # Plugin documentation

Creating a Plugin

claude --plugin-dir plugins/ruflo-plugin-creator
# Then: /create-plugin my-new-plugin

Or manually: copy any existing plugin directory and modify.

Validation

claude plugin validate plugins/ruflo-<name>

Verification & Discoverability

Every MCP tool description across the 32 plugins must answer "use this over native (Bash/Read/Grep/Glob/Task/TodoWrite) when?" per ADR-112. The rule is enforced by CI:

# Run the audit (scans all MCPTool definitions across all plugins)
node scripts/audit-tool-descriptions.mjs

# Gates: every description must include "Use when …" guidance,
# be ≥ 80 chars, and be unique. Baseline at verification/mcp-tool-baseline.json
# is monotone-decreasing — CI fails on any regression.

Combined with verification/ (Ed25519-signed witness manifest, 103+ documented fixes attested), the plugin surface is regression-protected at three layers: install smoke (npm i), behavioral smoke (paired-tool round-trips), and presence attestation (every load-bearing line of every documented fix). See verification/README.md for the full stack.

License

MIT