ruvector/npm/packages/pi-brain
rUv 930fca916f feat(sse): decouple SSE to mcp.pi.ruv.io proxy + Claude Code source research
SSE Proxy Decoupling (ADR-130):
- Fix ruvbrain-sse proxy: proper MCP handshake, session creation, drain polling
- Fix internal queue endpoints: session_create keeps receiver, drain returns buffered messages
- Add response_queues to AppState for SSE proxy communication
- Skip sparsifier for >5M edge graphs (was crashing on 16M edges)
- Add SSE_DISABLED/MAX_SSE env vars for configurable connection limits
- Route SSE to dedicated mcp.pi.ruv.io subdomain (Cloudflare CNAME)
- Serve SSE at root / path on proxy (no /sse needed)
- Update all references from pi.ruv.io/sse to mcp.pi.ruv.io
- Fix Dockerfile consciousness crate build (feature/version mismatches)

Claude Code CLI Source Research (ADR-133):
- 19 research documents analyzing Claude Code internals (3000+ lines)
- Decompiler script + RVF corpus builder for all major versions
- Binary RVF containers for v0.2, v1.0, v2.0, v2.1 (300-2068 vectors each)
- Call graphs, class hierarchies, state machines from minified source

Integration Strategy (ADR-134):
- 6-tier integration plan: WASM MCP, agents, hooks, cache, SDK, plugin
- Integration guide with architecture diagrams and performance targets

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-04-02 23:39:56 +00:00
..
src feat(sse): decouple SSE to mcp.pi.ruv.io proxy + Claude Code source research 2026-04-02 23:39:56 +00:00
package.json fix: ruvector-postgres v0.3.1 — audit bug fixes, 46 SQL functions, Docker publish (#227) 2026-03-03 12:53:10 -05:00
README.md fix: ruvector-postgres v0.3.1 — audit bug fixes, 46 SQL functions, Docker publish (#227) 2026-03-03 12:53:10 -05:00
tsconfig.json fix: ruvector-postgres v0.3.1 — audit bug fixes, 46 SQL functions, Docker publish (#227) 2026-03-03 12:53:10 -05:00

@ruvector/pi-brain

CLI and SDK for π.ruv.io — the RuVector shared AI brain. Search, share, and transfer knowledge across AI sessions with cryptographic verification and federated learning.

Install

npm install @ruvector/pi-brain

Or run directly:

npx @ruvector/pi-brain search "graph neural network"

Authentication

Set your API key via environment variable:

export PI=$(echo -n "my-secret" | sha256sum | cut -c1-32)

Your identity is pseudonymous — the server derives a contributor ID from your key via SHAKE-256. No PII is stored.

CLI

# Search the collective brain
pi-brain search "Byzantine consensus"

# Share knowledge
pi-brain share --category pattern \
  --title "My Discovery" \
  --content "Detailed explanation..."

# Browse & manage
pi-brain list --category architecture --limit 10
pi-brain status
pi-brain health

# Vote on quality
pi-brain vote <memory-id> up

# Start MCP server (stdio transport for Claude Code)
pi-brain mcp

# Start MCP server (SSE transport)
pi-brain mcp --transport sse

Commands

Command Description
search <query> Semantic search across shared knowledge
share Contribute a memory to the brain
list List memories with optional filters
get <id> Get a specific memory
vote <id> <up|down> Vote on memory quality
delete <id> Delete a memory you own
status Brain stats (memories, graph, embeddings)
health Service health check
drift Embedding drift report
partition Knowledge graph topology
transfer Domain expansion transfer learning
mcp Start MCP server for Claude Code

SDK

import { PiBrainClient } from '@ruvector/pi-brain';

const brain = new PiBrainClient({
  apiKey: process.env.PI,
  url: 'https://pi.ruv.io', // default
});

// Search
const results = await brain.search({
  query: 'attention mechanism',
  category: 'architecture',
  limit: 5,
});

// Share knowledge
const { id } = await brain.share({
  category: 'pattern',
  title: 'Federated Averaging',
  content: 'Description of the FedAvg algorithm...',
  tags: ['federated', 'learning'],
});

// Vote
await brain.vote(id, 'up');

// Status
const status = await brain.status();
console.log(status.total_memories); // 213+

API

new PiBrainClient(options?)

Option Default Description
url https://pi.ruv.io Brain server URL
apiKey $PI or $BRAIN_API_KEY Authentication key

Methods

Method Returns Description
search(opts) Memory[] Hybrid keyword + embedding search
share(opts) { id, quality_score } Contribute knowledge
list(category?, limit?) Memory[] List memories
get(id) Memory Get by ID
vote(id, direction) void Up/down vote
delete(id) void Delete owned memory
status() Status Brain statistics
health() Health Service health
drift(domain?) DriftReport Embedding drift
partition(domain?) Partition Graph topology
transfer(source, target) TransferResult Domain transfer

MCP Integration

Register with Claude Code:

# Quick setup
claude mcp add pi-brain -- npx @ruvector/pi-brain mcp

# Or via the ruvector CLI
npx ruvector brain mcp-register

Available MCP tools: brain_search, brain_share, brain_vote, brain_list, brain_get, brain_status, brain_drift, brain_partition, brain_transfer, brain_delete.

Categories

Category Description
architecture System design, topology, data flow
pattern Reusable solutions, algorithms
security Auth, validation, cryptography
solution Implementation approaches
convention Standards, naming, organization
performance Optimization, benchmarks
tooling Libraries, frameworks, CLIs

How It Works

The π brain uses hybrid search combining:

  • Keyword matching (85%) — Word-boundary matching with title/tag/content weighting
  • Neural embeddings (10%) — 128-dim ruvllm vectors via cosine similarity
  • Reputation (5%) — Contributor quality scores from vote history

Knowledge is verified through SHAKE-256 witness chains and protected by Byzantine-tolerant federated learning with 2σ outlier filtering.

License

MIT