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

docs: update ADR-076 β€” Phase 2 MCP tools, Phase 3 MicroLoRA

Reuven6ed14d6a74f3
diff --git a/v3/implementation/adrs/ADR-076-claude-code-memory-bridge.md b/v3/implementation/adrs/ADR-076-claude-code-memory-bridge.md
index fc31e11535..608352384d 100644
--- a/v3/implementation/adrs/ADR-076-claude-code-memory-bridge.md
+++ b/v3/implementation/adrs/ADR-076-claude-code-memory-bridge.md
@@ -1,67 +1,117 @@
# ADR-076: Bridge Claude Code Auto-Memory to AgentDB Vector Search
-**Status**: Implemented
+**Status**: Implemented (Phase 1: helper hook) / Proposed (Phase 2: MCP tools)
**Date**: 2026-04-07
**Branch**: `feat/claude-code-memory-bridge`
-**Related**: ADR-048 (AutoMemoryBridge), ADR-075 (learning pipeline)
+**Related**: ADR-048 (AutoMemoryBridge), ADR-075 (learning pipeline), ruDevolution
## Context
-Claude Code's auto-memory system stores project knowledge in `~/.claude/projects/*/memory/MEMORY.md` files with YAML frontmatter. Ruflo's AgentDB stores data in sql.js with ONNX embeddings (all-MiniLM-L6-v2, 384d) for semantic vector search. These two systems were disconnected β€” data in one was invisible to the other.
+Claude Code's auto-memory system stores project knowledge in `~/.claude/projects/*/memory/MEMORY.md` files with YAML frontmatter. Ruflo's AgentDB stores data in sql.js with ONNX embeddings (all-MiniLM-L6-v2, 384d) for semantic vector search. These two systems were disconnected.
-The `auto-memory-hook.mjs` (SessionStart/SessionEnd) imported MEMORY.md entries into a flat JSON file (`auto-memory-store.json`) but never vectorized them. AgentDB's intelligence module (SONA, ReasoningBank) learned patterns but never fed them back to Claude Code's memory.
+[ruDevolution](https://github.com/ruvnet/rudevolution) research (`07-context-and-session-management.md`) documents Claude Code's memory internals: auto-memory paths, env vars (`autoMemoryEnabled`, `CLAUDE_CODE_DISABLE_AUTO_MEMORY`), session persistence, dream mode, and compaction system.
## Decision
-Wire bidirectional bridge between Claude Code auto-memory and AgentDB:
+Two-phase approach:
-### SessionStart (import)
-1. `AutoMemoryBridge.importFromAutoMemory()` reads MEMORY.md files β†’ JSON backend (existing)
-2. **NEW**: Each imported entry gets stored into sql.js via `memory-initializer.storeEntry()` with `generateEmbeddingFlag: true` β†’ ONNX 384-dim vector generated
-3. Entries become searchable via AgentDB's semantic vector search
+### Phase 1: Helper Hook (Implemented)
-### SessionEnd (sync)
-1. `AutoMemoryBridge.syncToAutoMemory()` writes insights back to MEMORY.md (existing)
-2. **NEW**: `intelligence.flushPatterns()` persists SONA/ReasoningBank learned patterns to disk
-3. Patterns survive across sessions
+The existing `auto-memory-hook.mjs` (SessionStart/SessionEnd) bridges Claude Code memory to AgentDB:
+
+- **import**: Reads MEMORY.md β†’ JSON backend β†’ stores into sql.js with ONNX embeddings
+- **import-all**: Imports ALL Claude memories across ALL projects into AgentDB
+- **sync**: Writes insights back to MEMORY.md + flushes intelligence patterns
+- **status**: Shows bridge, AgentDB, SONA, patterns status
+
+**Limitation**: Only runs on session hooks. Not accessible from MCP or CLI during a session.
+
+### Phase 2: MCP Tools + CLI Commands (Proposed)
+
+Move bridge logic into proper MCP tools for real-time access:
+
+| MCP Tool | Description | Replaces |
+|----------|-------------|----------|
+| `memory_import_claude` | Import current project's Claude memories into AgentDB | `import` command |
+| `memory_import_all` | Import ALL Claude memories across ALL projects | `import-all` command |
+| `memory_bridge_status` | Show bridge status, vector counts, SONA state | `status` command |
+| `memory_bridge_sync` | Sync AgentDB insights back to MEMORY.md | `sync` command |
+| `memory_search_unified` | Search across both Claude memory and AgentDB | New |
+
+CLI equivalents:
+```bash
+ruflo memory import-claude # Import current project memories
+ruflo memory import-claude --all # Import all projects
+ruflo memory bridge-status # Show bridge status
+ruflo memory bridge-sync # Sync back to MEMORY.md
+ruflo memory search --unified # Search both stores
+```
+
+**Why MCP over helpers:**
+- Accessible during sessions (not just start/end)
+- Discoverable via ToolSearch
+- Testable via CLI
+- Works via `npx ruflo` without file path dependencies
+- Composable with other MCP tools (swarm, hooks, hive-mind)
+- Claude Code can call them directly through the MCP server
+
+### Phase 3: MicroLoRA Embedding Adaptation (Future)
+
+Once `@ruvector/learning-wasm` MicroLoRA is functional (currently identity pass-through due to zero-initialized weights), adapt the base MiniLM-L6-v2 embeddings for Claude Code's domain vocabulary:
+
+- Tool names, agent types, MCP concepts cluster closer
+- Successful trajectory patterns reinforce embedding neighborhoods
+- Contrastive loss from (anchor, positive, negative) triplets
+- ~2.6ΞΌs per adaptation step
+
+**Current blocker**: WASM binding issues in `computeContrastiveLoss` (array type mismatch) and `optimizerStep` (Buffer reference). Tracked in `@ruvector/learning-wasm`.
## Architecture
```
-Claude Code Auto-Memory AgentDB (sql.js + ONNX)
-~/.claude/projects/*/memory/*.md .swarm/memory.db
- β”‚ β–²
- β”‚ SessionStart hook β”‚
- β–Ό β”‚
-auto-memory-hook.mjs ─── import ──► JSON store ──►│ storeEntry()
- β”‚ (flat) β”‚ + generateEmbedding()
- β”‚ β”‚ β†’ 384-dim ONNX vector
- β”‚ SessionEnd hook β”‚
- β–Ό β”‚
-auto-memory-hook.mjs ─── sync ───► MEMORY.md β”‚
- β”‚ β”‚
- └── flushPatterns() β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
- Intelligence module
- (SONA + ReasoningBank)
+Phase 1 (current): Phase 2 (proposed):
+
+SessionStart hook MCP Tool: memory_import_claude
+ β””β†’ auto-memory-hook.mjs import β””β†’ memory-tools.ts handler
+ β””β†’ AutoMemoryBridge β””β†’ read MEMORY.md files
+ β””β†’ storeEntry() + ONNX β””β†’ storeEntry() + ONNX
+ β””β†’ return results to Claude
+
+SessionEnd hook MCP Tool: memory_bridge_sync
+ β””β†’ auto-memory-hook.mjs sync β””β†’ callable any time
+ β””β†’ syncToAutoMemory() β””β†’ syncToAutoMemory()
+ β””β†’ flushPatterns() β””β†’ flushPatterns()
+
+Not available mid-session MCP Tool: memory_search_unified
+ β””β†’ search both Claude + AgentDB
+ β””β†’ merged, deduplicated results
```
-## What This Enables
+## Verified Results (Phase 1)
-| Before | After |
+| Metric | Value |
|--------|-------|
-| MEMORY.md searchable by keyword only | MEMORY.md entries searchable by semantic similarity |
-| AgentDB can't see Claude Code memories | AgentDB indexes all auto-memory entries with vectors |
-| Learned patterns lost between sessions | SONA/ReasoningBank patterns flushed to disk on session end |
-| Two disconnected stores | Single query searches both stores |
+| Claude memory files found | 4 (across 3 projects) |
+| Entries imported | 5 (with section-level granularity) |
+| Embedding model | ONNX all-MiniLM-L6-v2, 384 dimensions |
+| Search "security vulnerability" | β†’ security_analysis (score: 0.435) |
+| Search "npm publish feedback" | β†’ publish workflow (score: 0.624) |
+| Search "ruvector package" | β†’ ruvector analysis (score: 0.678) |
+| Vectorization time | ~2s for 5 entries |
+
+## Files
-## Files Changed
+### Phase 1 (Implemented)
+- `.claude/helpers/auto-memory-hook.mjs` β€” vectorization bridge + import-all + pattern flush
-- `.claude/helpers/auto-memory-hook.mjs` β€” vectorization bridge + pattern flush
-- `v3/implementation/adrs/ADR-076-claude-code-memory-bridge.md` β€” this ADR
+### Phase 2 (Proposed)
+- `v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts` β€” add MCP tool handlers
+- `v3/@claude-flow/cli/src/commands/memory.ts` β€” add CLI subcommands
## References
-- [ruDevolution](https://github.com/ruvnet/rudevolution) β€” Claude Code internals analysis
-- Research doc: `07-context-and-session-management.md` β€” auto-memory paths and env vars
+- [ruDevolution](https://github.com/ruvnet/rudevolution) β€” Claude Code internals via decompilation
+- `07-context-and-session-management.md` β€” auto-memory paths, env vars, session persistence
+- `13-extension-points.md` β€” hooks, MCP, agents, skills integration catalog
- ADR-048: AutoMemoryBridge design
- ADR-075: Self-learning pipeline wiring