Back to Ruflo

ADR-058: Self-Contained Ruflo RVF Appliance — Linux Kernel + Claude Code + ruvLLM

v3/implementation/adrs/ADR-058-self-contained-ruflo-rvf-appliance.md

3.6.3026.7 KB
Original Source

ADR-058: Self-Contained Ruflo RVF Appliance — Linux Kernel + Claude Code + ruvLLM

FieldValue
StatusProposed
Date2026-02-28
AuthorsClaude Flow Team
Supersedes
RelatedADR-057 (RVF Native Storage), ADR-054 (RVF Plugin Marketplace), ADR-056 (agentic-flow v3 Integration), ADR-017 (RuVector Integration)

1. Context

The Problem

Ruflo v3.5 requires the user to have Node.js 20+, npm, Claude Code CLI, API keys, and a properly configured OS environment. This means:

  • 10+ setup steps before a user can run their first agent swarm
  • Network dependency at runtime for API calls, npm installs, MCP server downloads
  • Environment drift between dev, CI, staging, and production
  • No offline capability — the system is unusable without internet
  • Reproducibility gaps — "works on my machine" across OS, Node, and npm versions

The Vision

A single ruflo.rvf file that contains everything needed to run the full Ruflo platform:

ruflo.rvf (self-contained appliance)
├── Linux microkernel (Alpine-based, ~5MB)
├── Node.js 22 runtime (~30MB stripped)
├── Claude Code CLI
├── Ruflo v3.5+ (all packages)
├── ruvLLM local inference OR API key vault
├── AgentDB with HNSW indexes
├── Pre-trained SONA patterns
├── 60+ agent definitions
├── MCP server (pre-configured)
└── Capability verification suite

One file. No install. No dependencies. Works offline with ruvLLM, or connects to cloud APIs.

Why RVF as the Container Format

The RVF (RuVector Format) binary format from ADR-057 already provides:

RVF FeatureAppliance Use
Magic bytes (RVF\0, RVEC, RVFL, RVLS)Section identification within appliance
Header + payload binary layoutMetadata + compressed filesystem layers
Atomic write (tmp + rename)Safe appliance updates
CRC32/SHA256 integrityAppliance verification
Streaming readsBoot without full decompression

Extending RVF to RVFA (RuVector Format Appliance) creates a unified format that Ruflo already understands natively.


2. Decision

2.1 Appliance Format: RVFA (RuVector Format Appliance)

┌─────────────────────────────────────────────────┐
│ Magic: RVFA (4 bytes)                           │
│ Version: u32 (4 bytes)                          │
│ Header Length: u32 (4 bytes)                     │
├─────────────────────────────────────────────────┤
│ Header (JSON):                                  │
│   name, version, created, arch, platform        │
│   sections: [{ id, type, offset, size, sha256 }]│
│   boot: { entrypoint, args, env }               │
│   models: { provider, engine, config }          │
│   capabilities: [list of verified caps]         │
├─────────────────────────────────────────────────┤
│ Section 0: KERNEL (compressed rootfs)           │
│   Alpine Linux 3.23 minimal + busybox           │
│   /sbin/init → ruflo-init (PID 1)              │
├─────────────────────────────────────────────────┤
│ Section 1: RUNTIME (compressed)                 │
│   Node.js 22 (stripped, no npm)                 │
│   Claude Code CLI binary                        │
├─────────────────────────────────────────────────┤
│ Section 2: RUFLO (compressed)                   │
│   @claude-flow/cli + shared + guidance           │
│   All 26 commands, 140+ subcommands             │
│   60+ agent definitions                         │
│   17 hooks + 12 workers                         │
│   MCP server (pre-configured, stdio + SSE)      │
├─────────────────────────────────────────────────┤
│ Section 3: MODELS (compressed, optional)        │
│   ruvLLM engine (GGUF quantized models)          │
│   OR: encrypted API key vault (.env.enc)        │
│   OR: hybrid (local small + cloud large)        │
├─────────────────────────────────────────────────┤
│ Section 4: DATA (RVF native)                    │
│   AgentDB with pre-built HNSW indexes           │
│   Pre-trained SONA patterns                     │
│   Plugin registry snapshot                      │
│   Capability verification checksums             │
├─────────────────────────────────────────────────┤
│ Section 5: VERIFY (plaintext)                   │
│   Built-in capability test suite                │
│   Expected results manifest                     │
│   Self-test entrypoint                          │
├─────────────────────────────────────────────────┤
│ Footer: SHA256 of all sections (32 bytes)       │
└─────────────────────────────────────────────────┘

2.2 Model Strategy: ruvLLM + API Key Vault

Three model configurations, selected at build time:

ProfileModels IncludedSizeOfflineUse Case
offlineruvLLM + Qwen2.5-Coder-3B-Q4 + Phi-3-mini-Q4~4GBFullAir-gapped, edge, demos
hybridruvLLM + Phi-3-mini-Q4 + API vault~2GBPartialLocal routing + cloud for complex tasks
cloudAPI key vault only (no local models)~80MBNoMinimal size, full cloud

ruvLLM is the local language model inference engine from the RuVector ecosystem. It extends the existing @ruvector packages (core, router, sona, attention) with on-device LLM inference:

ruvLLM Architecture (extends @ruvector):
├── @ruvector/core — vector database, Q-learning router, AST analysis
├── @ruvector/router — ML-based intelligent task routing (~80% accuracy)
├── @ruvector/sona — Self-Optimizing Neural Architecture (<0.05ms)
├── @ruvector/attention — Flash Attention (2.49x-7.47x speedup)
├── @ruvector/micro-hnsw-wasm — HNSW vector search (WASM)
└── ruvLLM (new):
    ├── GGUF model loader (llama.cpp compatible)
    ├── KV-cache with RVF persistence
    ├── Token streaming over stdio/SSE
    ├── Automatic model selection by task complexity
    │   ├── Tier 1: Agent Booster (WASM, <1ms) — simple transforms
    │   ├── Tier 2: Phi-3-mini-Q4 (local, ~200ms) — routing, classification
    │   └── Tier 3: Qwen2.5-Coder-3B-Q4 (local, ~2s) — code generation
    └── Fallback to cloud API if local confidence < threshold

ruvLLM bridges the gap between RuVector's vector intelligence (search, routing, learning) and full language model inference, keeping everything in the same ecosystem.

API Key Vault (for cloud profiles):

.env.enc (AES-256-GCM encrypted)
├── ANTHROPIC_API_KEY → Claude Sonnet/Opus
├── OPENAI_API_KEY → GPT-4/Codex (dual-mode)
├── GOOGLE_API_KEY → Gemini (fallback)
└── Decryption: passphrase at boot OR hardware key

2.3 Boot Sequence

1. ruflo-appliance load ruflo.rvf
2. Verify RVFA magic bytes + footer SHA256
3. Extract KERNEL section → mount as rootfs
4. Extract RUNTIME section → /usr/local/bin/
5. Extract RUFLO section → /opt/ruflo/
6. Mount DATA section (read-write overlay)
7. Load MODELS section:
   - If ruvLLM: start inference server on unix socket
   - If API vault: decrypt keys, set env vars
   - If hybrid: start local + configure cloud fallback
8. Run VERIFY section → self-test all capabilities
9. Start MCP server (stdio or SSE based on config)
10. Ready for agent orchestration

2.4 Execution Modes

ModeCommandDescription
Runruflo-appliance run ruflo.rvfBoot and enter interactive CLI
MCPruflo-appliance mcp ruflo.rvfBoot as MCP server (stdio)
Verifyruflo-appliance verify ruflo.rvfRun full capability test suite
Extractruflo-appliance extract ruflo.rvf ./out/Unpack all sections
Buildruflo-appliance build --profile offlineCreate new appliance
Updateruflo-appliance update ruflo.rvf --section RUFLOHot-patch one section
Inspectruflo-appliance inspect ruflo.rvfShow header + section manifest

2.5 Runtime Isolation

The appliance runs in one of three isolation levels:

LevelTechnologyOverheadSecurity
ContainerOCI/Docker (default)~50MB RAMNamespace + cgroup isolation
MicroVMFirecracker/Cloud Hypervisor~128MB RAMFull VM isolation
NativeDirect execution (dev only)~30MB RAMProcess-level only

Container mode (default):

bash
# The .rvf file IS the container image
ruflo-appliance run ruflo.rvf
# Equivalent to:
# docker run --rm -it ruflo:self-contained

3. Capability Verification Suite

The appliance includes a built-in verification suite that tests every capability of Ruflo + Claude Flow. This runs automatically at boot (Section 5: VERIFY) and can be triggered manually.

3.1 Test Categories (25 Categories, 80+ Checks)

#CategoryCritical ChecksWhat It Proves
1CLI Core--version, --help, version matchBinary integrity
2Doctor14 health checks, --fixSystem diagnostics
3Init Systemsettings.json, helpers, agent teams configProject scaffolding
4Memory Operationsstore, list, search, retrieve, delete, TTLAgentDB + RVF backend
5Config Managementshow, get, set, listConfiguration system
6Session Managementstart, status, end, listSession persistence
7Agent Systemlist, spawn, status, poolAgent lifecycle
8Swarm Coordinationinit, status, topologiesMulti-agent orchestration
9Task Systemcreate, list, assignTask management
10Hooks Systemlist, route, pre-task, workers, statuslineSelf-learning pipeline
11Securityscan, audit, validateInput validation, CVE checks
12Performancemetrics, benchmarkProfiling
13Neural/Intelligencestatus, patternsSONA + MoE
14Embeddingsembed, searchVector generation
15Workflow Systemlist, templatesWorkflow engine
16Daemonstatus, startBackground workers
17Claims Authorizationlist, checkRBAC
18MigrationstatusV2→V3 migration
19PluginslistPlugin registry
20MCP Serverhelp, list, stdio transportMCP protocol
21Completionsbash, zshShell integration
22Statussystem statusHealth monitoring
23Hive-MindstatusByzantine consensus
24Process ManagementlistBackground processes
25Cross-Feature Integrationstore→search→retrieve→delete cycleEnd-to-end data flow

3.2 Appliance-Specific Tests (Additional)

#CategoryChecksWhat It Proves
26RVF Formatmagic bytes, header parse, section integrityBinary format correctness
27ruvLLM Inferencemodel load, tokenize, generate, streamLocal LLM works offline
28API Vaultdecrypt, key validation, provider connectivityCloud API access
29Boot IntegritySHA256 verification, section checksumsTamper detection
30Isolationnamespace check, cgroup limits, filesystemSecurity boundaries
31Agent Swarm E2Espawn 4 agents → coordinate → produce outputFull orchestration
32MCP E2EJSON-RPC init → tool call → responseProtocol compliance
33Persistencewrite data → reboot → verify data survivesRVF durability
34Offline Modedisconnect network → run full workflowAir-gap capability
35Hot Updatepatch RUFLO section → verify new versionLive update

3.3 Test Output Format

╔══════════════════════════════════════════════════════════╗
║  Ruflo Appliance v3.5.2 — Full Capability Verification  ║
║  Format: RVFA v1 | Profile: offline | Arch: x86_64      ║
║  Kernel: Alpine 3.23 | Node: 22.22.0 | ruvLLM: 0.1.0    ║
╚══════════════════════════════════════════════════════════╝

═══ 1. CLI Core ═══
  ✓ ruflo --version
  ✓ ruflo --help
  ✓ version is 3.5.2

═══ 2. Doctor ═══
  ✓ doctor runs (14/14 checks)
  ...

═══ 26. RVF Format ═══
  ✓ RVFA magic bytes valid
  ✓ header JSON parses correctly
  ✓ all 6 sections present
  ✓ section SHA256 checksums match
  ✓ footer hash matches computed hash

═══ 27. ruvLLM Inference ═══
  ✓ model loaded (Phi-3-mini-Q4, 2.3GB)
  ✓ tokenizer functional (32000 vocab)
  ✓ generation produces valid output
  ✓ streaming tokens arrive in <100ms
  ✓ KV-cache persists across calls

══════════════════════════════════════════════════
  RESULTS: 95/95 passed, 0 failed, 3 warnings
  ★ APPLIANCE FULLY VERIFIED
══════════════════════════════════════════════════

4. Build Pipeline

4.1 Build Command

bash
# Build offline appliance (includes local models)
ruflo-appliance build \
  --profile offline \
  --arch x86_64 \
  --models "phi-3-mini-q4,qwen2.5-coder-3b-q4" \
  --output ruflo-offline.rvf

# Build cloud appliance (API keys only)
ruflo-appliance build \
  --profile cloud \
  --api-keys .env \
  --output ruflo-cloud.rvf

# Build hybrid appliance
ruflo-appliance build \
  --profile hybrid \
  --models "phi-3-mini-q4" \
  --api-keys .env \
  --output ruflo-hybrid.rvf

4.2 Build Stages

Stage 1: KERNEL
  ├── Pull alpine:3.23 rootfs
  ├── Install busybox, dumb-init
  ├── Strip to <5MB
  └── Compress with zstd -19

Stage 2: RUNTIME
  ├── Download Node.js 22 (linux-x64-musl)
  ├── Strip debug symbols, remove npm/corepack
  ├── Include Claude Code CLI binary
  └── Compress (~30MB → ~12MB)

Stage 3: RUFLO
  ├── npm pack ruflo@latest --omit=optional
  ├── Include all CLI commands + agent defs
  ├── Pre-configure MCP server
  └── Compress (~9MB → ~3MB)

Stage 4: MODELS (profile-dependent)
  ├── offline: Download GGUF models, build ruvLLM
  ├── hybrid: Download small model + encrypt keys
  └── cloud: Encrypt API keys only

Stage 5: DATA
  ├── Initialize AgentDB with RVF backend
  ├── Build HNSW indexes for default patterns
  ├── Snapshot pre-trained SONA weights
  └── Cache plugin registry

Stage 6: VERIFY
  ├── Bundle test script (sh, no dependencies)
  ├── Generate expected-results manifest
  └── Include checksum of all sections

Final: Assemble RVFA
  ├── Write magic + version + header
  ├── Append all sections with offsets
  ├── Compute and append footer SHA256
  └── Output: ruflo.rvf

4.3 Size Targets

ProfileSectionsCompressed Size
cloudKernel + Runtime + Ruflo + Data + Verify~60MB
hybridAll + Phi-3-mini-Q4~2GB
offlineAll + Phi-3 + Qwen2.5-Coder-3B~4GB

5. Architecture

5.1 Component Diagram

┌──────────────────────────────────────────────────────────────┐
│                    ruflo.rvf (RVFA)                           │
│  ┌────────────────────────────────────────────────────────┐  │
│  │  KERNEL: Alpine Linux 3.23 (~5MB)                      │  │
│  │  ┌──────────────────────────────────────────────────┐  │  │
│  │  │  RUNTIME: Node.js 22 + Claude Code CLI           │  │  │
│  │  │  ┌──────────────────────────────────────────────┐│  │  │
│  │  │  │  RUFLO v3.5+                                 ││  │  │
│  │  │  │  ├── 26 CLI commands (140+ subcommands)      ││  │  │
│  │  │  │  ├── 60+ agent definitions                   ││  │  │
│  │  │  │  ├── 17 hooks + 12 workers                   ││  │  │
│  │  │  │  ├── MCP server (215 tools)                  ││  │  │
│  │  │  │  ├── AgentDB + HNSW (RVF backend)            ││  │  │
│  │  │  │  └── Security + Claims + Plugins             ││  │  │
│  │  │  └──────────────────────────────────────────────┘│  │  │
│  │  │  ┌──────────────────────────────────────────────┐│  │  │
│  │  │  │  MODELS                                      ││  │  │
│  │  │  │  ├── ruvLLM inference engine                  ││  │  │
│  │  │  │  ├── Local: Phi-3 / Qwen2.5-Coder (GGUF)    ││  │  │
│  │  │  │  └── Cloud: encrypted API key vault          ││  │  │
│  │  │  └──────────────────────────────────────────────┘│  │  │
│  │  └──────────────────────────────────────────────────┘  │  │
│  └────────────────────────────────────────────────────────┘  │
│  ┌────────────────────────────────────────────────────────┐  │
│  │  DATA: AgentDB + SONA patterns + Plugin registry       │  │
│  └────────────────────────────────────────────────────────┘  │
│  ┌────────────────────────────────────────────────────────┐  │
│  │  VERIFY: 95-check capability suite + checksums         │  │
│  └────────────────────────────────────────────────────────┘  │
└──────────────────────────────────────────────────────────────┘
         │                    │                    │
    ┌────┴────┐         ┌────┴────┐         ┌────┴────┐
    │Container│         │MicroVM  │         │ Native  │
    │ (OCI)   │         │(Firecrk)│         │ (dev)   │
    └─────────┘         └─────────┘         └─────────┘

5.2 Model Routing Flow

User Task
    │
    ▼
┌─────────────────┐
│ Complexity Check │
│ (hooks route)   │
└────────┬────────┘
         │
    ┌────┴────────────────────────┐
    │                             │
    ▼                             ▼
 Simple (<30%)              Complex (>30%)
    │                             │
    ▼                             ▼
┌──────────┐              ┌─────────────┐
│ Tier 1:  │              │ ruvLLM local?│
│ Agent    │              └──────┬──────┘
│ Booster  │                Yes  │  No
│ (WASM)   │                ┌────┴────┐
│ <1ms, $0 │                │         │
└──────────┘                ▼         ▼
                     ┌──────────┐ ┌──────────┐
                     │ Tier 2:  │ │ Tier 3:  │
                     │ Phi-3    │ │ Cloud API│
                     │ (local)  │ │ (Sonnet/ │
                     │ ~200ms   │ │  Opus)   │
                     │ $0       │ │ 2-5s     │
                     └──────────┘ └──────────┘

6. Security

6.1 Appliance Integrity

MechanismPurpose
RVFA footer SHA256Tamper detection for entire appliance
Per-section SHA256Integrity of individual sections
Code signing (Ed25519)Verify publisher identity
API key vault (AES-256-GCM)Protect cloud credentials
Read-only rootfsPrevent runtime modification of system files
Namespace isolationContainer/VM boundary enforcement
Seccomp profileRestrict syscalls to minimum required

6.2 Key Management

Boot:
  1. User provides passphrase OR hardware key
  2. Derive AES key via Argon2id (memory-hard)
  3. Decrypt .env.enc → load API keys into memory
  4. Keys exist only in process memory (never on disk)
  5. On shutdown: zero memory, drop keys

6.3 Update Security

Hot Update Flow:
  1. Download signed patch (.rvfp)
  2. Verify Ed25519 signature against pinned public key
  3. Verify patch targets correct appliance version
  4. Apply patch to target section
  5. Recompute section SHA256 + footer hash
  6. Run VERIFY suite to confirm no regression
  7. Atomic swap (old → .bak, new → active)

7. Implementation Plan

Phase 1: RVFA Format + Builder (Week 1-2)

TaskDescription
Define RVFA binary specMagic bytes, header schema, section table
ruflo-appliance buildMulti-stage builder with profile selection
ruflo-appliance inspectHeader + section manifest viewer
ruflo-appliance extractUnpack all sections to directory
Cloud profileKernel + Runtime + Ruflo + encrypted keys

Phase 2: Runtime + Verification (Week 3-4)

TaskDescription
ruflo-appliance runBoot sequence with container isolation
ruflo-appliance verify95-check capability suite
ruflo-appliance mcpMCP server mode (stdio + SSE)
DATA sectionPre-built AgentDB + HNSW + SONA
CI integrationBuild appliance on every release

Phase 3: ruvLLM Integration (Week 5-8)

TaskDescription
ruvLLM engineGGUF model loader + KV-cache + streaming
Model routing3-tier routing (Booster → local → cloud)
Hybrid profileSmall local model + cloud fallback
Offline profileFull local inference, no network
Offline verificationAll 95 checks pass without network

Phase 4: Distribution + Updates (Week 9-10)

TaskDescription
ruflo-appliance updateHot-patch individual sections
Ed25519 signingCode signing for appliance + patches
IPFS distributionPublish appliances to decentralized storage
MicroVM supportFirecracker/Cloud Hypervisor isolation
DocumentationUser guide, API reference, examples

8. Consequences

Positive

  • Zero-install deployment: One file, no Node.js/npm/Claude Code prerequisites
  • Offline-capable: Full agent orchestration without internet (offline profile)
  • Reproducible: Same binary = same behavior everywhere
  • Secure: Encrypted keys, signed updates, container isolation
  • Fast boot: <5s from cold start (vs 35s for npx ruflo@latest)
  • Verifiable: Built-in 95-check suite proves every capability works
  • Updatable: Hot-patch sections without rebuilding entire appliance

Negative

  • Larger artifact: 60MB-4GB depending on profile (vs ~9MB npm package)
  • Build complexity: Multi-stage builder with cross-compilation
  • Model storage: Local models consume significant disk (2-4GB per model)
  • Update latency: Section-level patches still require verification pass

Mitigations

  • Cloud profile keeps size at ~60MB (comparable to a Docker image)
  • Builder is automated and reproducible via CI
  • Model quantization (Q4_K_M) reduces size while maintaining quality
  • Verification suite runs in parallel (~10s for full 95-check pass)

9. Alternatives Considered

AlternativeReason Rejected
Docker image onlyRequires Docker installed; no offline model support; not a single file
Flatpak/SnapLinux-only packaging; no custom binary format; no model bundling
AppImageLinux-only; no Windows/macOS; limited isolation
WebAssembly bundleNo filesystem access; can't run Claude Code CLI; no local models
Nix derivationRequires Nix; steep learning curve; no model bundling
VM image (qcow2)Too large; requires hypervisor; not portable

RVFA provides the best balance of portability, size, isolation, and integration with the existing RVF ecosystem.


10. References