---
title: "ruflo-agentdb"
url: "https://claudemods.dev/ja/builds/ruflo-agentdb-4e8c67"
source: "https://github.com/ruvnet/ruflo/tree/main/plugins/ruflo-agentdb"
source_type: "github"
repo: "https://github.com/ruvnet/ruflo/tree/main/plugins/ruflo-agentdb"
author: "ruvnet"
author_handle: "ruvnet"
stars: 82617
category: "その他"
categories: ["other"]
tags: []
permission_level: 2
scan_complete: true
install: "claude plugin marketplace add ruvnet/ruflo\nclaude plugin install ruflo-agentdb@ruflo"
added: "2026-10-05T15:42:11.297Z"
updated: "2026-11-28T23:39:59Z"
locale: "ja"
content_locale: "ja"
---

# ruflo-agentdb

Ruflo メモリ基盤のプラグイン。AgentDB コントローラーブリッジ（15 個の agentdb_* MCP ツール）、RuVector ONNX 埋め込み（RaBitQ 32x 量子化を含む 10 個の embeddings_* ツール）、WASM HNSW パターンルーター（3 個の ruvllm_hnsw_* ツール）を提供します。mod（ADR-445）として、プロンプトへの安全な任意リコール、秘密をメモリから遠ざける書き込みガード、/agentdb、コンソールが表示するステータスファイルを備えます。

## Description

# ruflo-agentdb

Ruflo のメモリ基盤用プラグインです。3 系統の CLI MCP ファミリー——`agentdb_*`（コントローラーブリッジ、15 ツール）、`embeddings_*`（RuVector ONNX エンジン、10 ツール）、`ruvllm_hnsw_*`（WASM ベースのパターンルーター、3 ツール）——を、発見可能な skills とコマンドにまとめます。他のプラグイン（`ruflo-browser`、`ruflo-rag-memory`、`ruflo-intelligence`）はこの基盤を組み合わせて使います。本プラグインは、基盤全体の名前空間規約と smoke contract を管理します。

> **ステータス：** ADR-0001 は実装済みです。プラグイン v0.3.0 は `@claude-flow/cli` v3.6.x を対象とし、`agentdb@^3.0.0-alpha.11` を同梱します。smoke contract（番号付きチェック 13 件 + ドキュメント不変条件 3 件）が検証手段です。詳しくは [docs/adrs/0001-agentdb-optimization.md](./docs/adrs/0001-agentdb-optimization.md) を参照してください。

## インストール

```
/plugin marketplace add ruvnet/ruflo
/plugin install ruflo-agentdb@ruflo
```

## 互換性

- **CLI：** `@claude-flow/cli` の v3.6 メジャー + マイナーに固定しています。v3.6 内のパッチ更新は no-op になる想定です。
- **AgentDB：** CLI は `agentdb@^3.0.0-alpha.11` を同梱します。プラグインは npm パッケージを**固定しません**。内部バージョン（alpha.11 → alpha.12 など）はプラグインの契約ではありません。
- **検証：** 同梱の smoke script が唯一の基準です（`bash plugins/ruflo-agentdb/scripts/smoke.sh`）。使用する CLI バージョンで smoke が通れば、プラグインの契約は満たされます。

## 機能

- **コントローラーブリッジ：** 15 個の `agentdb_*` MCP ツール（階層型の保存/リコール、セマンティックルーティング、パターンの保存/検索、因果エッジ、コンテキスト合成、バッチ操作、統合、フィードバック、セッション）。
- **RuVector 埋め込み：** 10 個の `embeddings_*` MCP ツール——384 次元 ONNX（all-MiniLM-L6-v2）、HNSW 検索、双曲線（Poincare）、ニューラル基盤、**RaBitQ 1-bit 量子化（メモリを 32× 削減）**。
- **HNSW パターンルーター：** 3 個の `ruvllm_hnsw_*` ツール（WASM ベース、優先度の高いパターンは最大 11 個。大規模な埋め込み HNSW 経路とは別です）。
- **因果知識グラフ：** `agentdb_causal-edge`（graph-node バックエンド。ADR-087 に基づくブリッジフォールバック付き）。

## コントローラー（実際のレジストリ、INIT_LEVELS ごとに分類）

このプラグイン内で報告される「コントローラー数」は、**ランタイムツールが実際に報告する値**です。名前の正式な一覧は `v3/@claude-flow/memory/src/controller-registry.ts:34-73` の `ControllerName` union にあります（6 つの初期化レベルにまたがる 29 名）。ランタイムでは次で確認できます。

```bash
mcp tool call agentdb_controllers --json
```

ADR-053（`controller-registry.ts:160-174`）に従った初期化順序：

| レベル | コントローラー | 役割 |
|------:|-------------|------|
| 0 | _(foundation, pre-existing)_ | ブートストラップ |
| 1 | `reasoningBank`、`hierarchicalMemory`、`learningBridge`、`hybridSearch`、`tieredCache` | コアインテリジェンス |
| 2 | `memoryGraph`、`agentMemoryScope`、`vectorBackend`、`mutationGuard`、`gnnService` | グラフ + セキュリティ |
| 3 | `skills`、`explainableRecall`、`reflexion`、`attestationLog`、`batchOperations`、`memoryConsolidation` | 特化機能 |
| 4 | `causalGraph`、`nightlyLearner`、`learningSystem`、`semanticRouter` | 因果 + ルーティング |
| 5 | `graphTransformer`、`sonaTrajectory`、`contextSynthesizer`、`rvfOptimizer`、`mmrDiversityRanker`、`guardedVectorBackend` | 高度なサービス |
| 6 | `federatedSession`、`graphAdapter` | セッション管理 |

`graphAdapter` は現在、外部 graph-DB 接続待ちのため無効です（ADR-095 で追跡中）。その他の Level-2/3 セキュリティコントローラー（`mutationGuard`、`attestationLog`、`gnnService`、`rvfOptimizer`、`guardedVectorBackend`）は、ruflo 3.6.23+ の ADR-095 G7 で有効化されました。

## G7 コントローラー（ADR-095 で有効化）

[ADR-095](../../v3/docs/adr/ADR-095-architectural-gaps-from-april-audit.md) は、以前無効だった AgentDB コントローラー 5 つを有効にしました。

| コントローラー | 役割 | ソース |
|---|---|---|
| `gnnService` | AgentDB の因果グラフ上で Graph Neural Network の埋め込みと関係スコアリングを行います。引数なしで構築します。 | `agentdb/dist/src/services/GNNService.js` |
| `rvfOptimizer` | RuVector 形式の圧縮。永続化前にベクトルブロックを量子化し、重複を除去します。 | `agentdb/dist/src/optimizations/RVFOptimizer.js` |
| `mutationGuard` | 状態変更の WASM ベースの証明生成（ADR-060）。 | `agentdb/dist/src/security/MutationGuard.js` |
| `attestationLog` | 変更のハッシュチェーン監査ログ。専用の `.swarm/attestation.db` に保存します。 | `agentdb/dist/src/security/AttestationLog.js` |
| `GuardedVectorBackend` | 既存の `vectorBackend` を `mutationGuard` + `attestationLog` で包みます。 | `agentdb/dist/src/backends/ruvector/GuardedVectorBackend.js` |

## コマンド

- `/agentdb-mod` — AgentDB のヘルス、コントローラー状態、セッション管理
- `/embeddings` — RuVector 埋め込みエンジンの状態と操作

## Skills

- `agentdb-query` — セマンティックルーティングと階層型リコールで AgentDB を検索
- `vector-search` — HNSW ベクトル検索 + RaBitQ 量子化 + 3 つのチューニングプロファイル

## 名前空間の規約

本プラグインは、下流プラグインが利用する名前空間の規約を所有します。この規約に従うことで、プラグインをまたいだ検索を発見可能に保ち、ブリッジ内の意図しないキー衝突を避けられます。

### 命名

kebab-case の `<plugin-stem>-<intent>` を使います。すでに使われている例：

| プラグイン | 名前空間 |
|---|---|
| `ruflo-browser` | `browser-sessions`、`browser-selectors`、`browser-templates`、`browser-cookies` |
| `ruflo-rag-memory` |（ブリッジのターゲット `claude-memories` を使用） |
| `ruflo-intelligence` |（フォールバック先 `pattern` を使用） |

### 予約済みの名前空間（上書きしない）

| 名前空間 | 所有者 | ソース |
|---|---|---|
| `pattern` | ReasoningBank のフォールバック書き込み先 | `agentdb-tools.ts:144` |
| `claude-memories` | Claude Code 自動メモリーブリッジのターゲット | bridge |
| `default` | `memory_store` のデフォルト | `memory-tools.ts` |

### 名前空間文字列が実際に適用される場所

名前空間は**すべての箇所に使える引数ではありません**。ルーティングをよく確認してください。

- `memory_*` と `embeddings_search` は名前空間でルーティングされるため、渡します。
- `agentdb_hierarchical-*` は `tier`（`working|episodic|semantic`）でルーティングされ、名前空間引数は無視されます。
- `agentdb_pattern-*` は ReasoningBank コントローラー経由でルーティングされ、名前空間引数は無視されます。
- `agentdb_causal-edge` は因果グラフ経由でルーティングされ、名前空間引数は無視されます。

`namespace: 'browser-cookies'` を `agentdb_pattern-store` に渡しても、フィルタリングされるとは限りません。値は静かに破棄されます。

### GC の方針

本プラグインは名前空間を GC **しません**。ライフサイクルを管理したい利用側プラグイン（たとえば `purge` 後の `browser-sessions`）が、`memory_delete` + `agentdb_consolidate` を使って自身で削除します。クリーンアップが必要ならスケジュールしてください。

### 命名上のガードレール

名前空間には `:` を含めないでください（ブリッジが使うキー内部の区切り文字と衝突します）。200 文字以下で、`validateIdentifier`（`agentdb-tools.ts:122` で使われているものと同じバリデーター）を通過する必要があります。

## Claude Code が AgentDB を埋める仕組み

予約済みの `claude-memories` 名前空間は、ユーザーが直接呼び出すのではなく、Claude Code 自身の自動メモリーブリッジが埋めます。仕組みは 2 つあります。

| 仕組み | トリガー | 書き込む内容 |
|---|---|---|
| `memory_import_claude` MCP ツール | 手動または hook 駆動 | `~/.claude/projects/*/memory/*.md` を読み、YAML frontmatter を解析し、セクションに分割して 384 次元の埋め込みとともに保存します。`allProjects: true` はすべての Claude プロジェクトからインポートします。 |
| `.claude/helpers/auto-memory-hook.mjs` | `SessionStart`（import）と `SessionEnd`（sync）。`.claude/settings.json` に接続されています | `import` → 現在のプロジェクトのブリッジを呼び出す。`sync` → AgentDB のインサイトを `~/.claude/projects/*/memory/MEMORY.md` に戻す |

調査または更新：

```
# What's in the bridge right now?
mcp tool call memory_bridge_status --json

# Force a re-import from Claude Code's project memory
mcp tool call memory_import_claude --json -- '{"allProjects": true}'

# Cross-namespace search across claude-memories + auto-memory + patterns + tasks + feedback
mcp tool call memory_search_unified --json -- '{"query": "your query"}'
```

`memory_search_unified` はデフォルトで `['default', 'claude-memories', 'auto-memory', 'patterns', 'tasks', 'feedback']` を検索します。これらはブリッジが実際に投入する名前空間です。`default` は全体の受け皿で、`auto-memory` は `claude-memories` とは別です（前者はブリッジ内部のキャッシュ、後者は解析済みの `*.md` セクションを保持します）。

> **複数形の落とし穴：** ReasoningBank のフォールバックは `pattern`（単数）に書き込みます。他の hooks（`pretrain`、ニューラルトレーニング経路）は `patterns`（複数）に書き込みます。両者は別の名前空間です。迷ったら `memory_list --namespace pattern` と `memory_list --namespace patterns` をそれぞれ実行して、どちらにデータがあるかを確認してください。実際の書き込み先を確認する前に、複数形を「修正」するために下流コードをリファクタリングしないでください。

## Hook 統合の規約

複数の Claude Code hook が AgentDB に書き込みます。利用側プラグインは、どの名前空間が自動的に状態を蓄積し、どれが明示的な呼び出しを必要とするかを把握してください。そうすれば hook システムがすでに提供する機能を作り直さずに済みます。

| Hook | 呼び出すツール | ターゲット名前空間 | 注記 |
|------|--------------|----------|-------|
| `SessionStart` | `memory_import_claude`（`auto-memory-hook.mjs` 経由） | `claude-memories` | 各セッション開始時に `~/.claude/projects/*/memory/*.md` を AgentDB にインポート |
| `SessionEnd` | `auto-memory-hook.mjs sync` | bridge → `MEMORY.md` | AgentDB のインサイトを Claude Code の MEMORY.md に戻す |
| `post-task --train-neural` | `agentdb_pattern-store`（ReasoningBank） | `pattern`（レジストリがない場合は `memory-store-fallback`） | SONA 蒸留用のタスク完了パターンを保存 |
| `pretrain`（one-shot） | `memory_store` | `patterns`（複数） | 学習コーパスをブートストラップ |
| `trajectory-begin/step/end`（ruvector hooks） | ruvector 基盤（別プラグイン） | `ruflo-ruvector` が扱う sona/agentdb 名前空間 | `plugins/ruflo-ruvector/docs/adrs/0001-pin-ruvector-0.2.25.md` を参照 |

利用側プラグインへの意味：

- **二重書き込みをしない。** すでに `hooks post-task --train-neural` を呼んでいるなら、`memory_store --namespace pattern` を手動で追加する必要はありません。1 つの経路を選んでください。
- **`claude-memories` を自分で更新しない。** 毎回の `SessionStart` で自動インポートされます。手動の `memory_import_claude` は強制更新用であり、通常運用には使いません。
- **フォールバックの応答を表に出す。** `agentdb_pattern-store` から `controller: 'memory-store-fallback'` が返ったとき、データは保存済みです。下の「Pattern-store fallback」を参照してください。

## 運用上のフォールバック

ブリッジコードには 3 つのフォールバックがあります。利用側はソフトな失敗として扱わず、これらに分岐してください。

### Pattern-store fallback（ADR-093 F4）

ReasoningBank コントローラーレジストリが null を返すと、`agentdb_pattern-store` は `memory_store` 経由で書き込み、次を返します。

```json
{
  "success": true,
  "patternId": "pattern-...",
  "controller": "memory-store-fallback",
  "note": "ReasoningBank controller registry unavailable. Pattern persisted via memory_store."
}
```

`controller: 'memory-store-fallback'` の応答は、パターンが**保存された**ことを示します。エラーではありません。ソース：`agentdb-tools.ts:138-161`。

### Causal-edge graph-node バックエンド（ADR-087）

`agentdb_causal-edge` はまずネイティブの `@ruvector/graph-node` バックエンドを試し、失敗するとブリッジにフォールバックします。ネイティブ側が処理した場合、応答には `_graphNodeBackend: true` が含まれます。ソース：`agentdb-tools.ts:267-290`。

### ブリッジが利用できない場合

`bridgeHealthCheck()` が null を返した場合（`@claude-flow/memory` パッケージがインストールされていない、または `controller-registry.ts` がない場合）、すべての `agentdb_*` ハンドラーは次を返します。

```json
{
  "success": false,
  "error": "AgentDB bridge not available — @claude-flow/memory not installed... Use memory_store/memory_search tools instead."
}
```

ブリッジ利用不可モードの置き換え表：

| 利用できない `agentdb_*` | 代わりに使うもの |
|---|---|
| `agentdb_hierarchical-store` / `_recall` | `memory_store` / `memory_search` |
| `agentdb_pattern-store` / `_search` | `memory_store --namespace pattern` / `memory_search --namespace pattern` |

## Install

```
claude plugin marketplace add ruvnet/ruflo
claude plugin install ruflo-agentdb@ruflo
```

## Original README

# ruflo-agentdb

The substrate plugin for Ruflo memory. Wraps three CLI MCP families — `agentdb_*` (controller bridge, 15 tools), `embeddings_*` (RuVector ONNX engine, 10 tools), and `ruvllm_hnsw_*` (WASM-backed pattern router, 3 tools) — into discoverable skills and commands. Other plugins (`ruflo-browser`, `ruflo-rag-memory`, `ruflo-intelligence`) compose this substrate; this plugin owns the namespace convention and the smoke contract for the substrate as a whole.

> **Status:** ADR-0001 implemented. Plugin v0.3.0 targets `@claude-flow/cli` v3.6.x with bundled `agentdb@^3.0.0-alpha.11`. The smoke contract (13 numbered checks + 3 documentation invariants) is the verification mechanism — see [docs/adrs/0001-agentdb-optimization.md](./docs/adrs/0001-agentdb-optimization.md).

## Install

```
/plugin marketplace add ruvnet/ruflo
/plugin install ruflo-agentdb@ruflo
```

## Compatibility

- **CLI:** pinned to `@claude-flow/cli` v3.6 major+minor. Patch bumps within v3.6 are expected to be no-op.
- **AgentDB:** the CLI bundles `agentdb@^3.0.0-alpha.11`. The plugin does **not** pin the npm package — internals (alpha.11 → alpha.12 etc.) are not the plugin's contract.
- **Verification:** the bundled smoke script is the source of truth (`bash plugins/ruflo-agentdb/scripts/smoke.sh`). If smoke passes against your CLI version, the plugin's contract holds.

## Features

- **Controller bridge**: 15 `agentdb_*` MCP tools (hierarchical store/recall, semantic routing, pattern store/search, causal edges, context synthesis, batch ops, consolidation, feedback, sessions).
- **RuVector embeddings**: 10 `embeddings_*` MCP tools — 384-dim ONNX (all-MiniLM-L6-v2), HNSW search, hyperbolic (Poincare), neural substrate, and **RaBitQ 1-bit quantization (32× memory reduction)**.
- **HNSW pattern router**: 3 `ruvllm_hnsw_*` tools (WASM-backed, ≤11 high-priority patterns — distinct from the large-scale embeddings HNSW path).
- **Causal knowledge graphs**: `agentdb_causal-edge` (graph-node backend with bridge fallback per ADR-087).

## Controllers (real registry, grouped by INIT_LEVELS)

The "controller count" reported anywhere in this plugin is **whatever the runtime tool reports**. The canonical list of names is the `ControllerName` union at `v3/@claude-flow/memory/src/controller-registry.ts:34-73` (29 names across 6 init levels). Inspect at runtime:

```bash
mcp tool call agentdb_controllers --json
```

Initialization order per ADR-053 (`controller-registry.ts:160-174`):

| Level | Controllers | Role |
|------:|-------------|------|
| 0 | _(foundation, pre-existing)_ | Bootstrap |
| 1 | `reasoningBank`, `hierarchicalMemory`, `learningBridge`, `hybridSearch`, `tieredCache` | Core intelligence |
| 2 | `memoryGraph`, `agentMemoryScope`, `vectorBackend`, `mutationGuard`, `gnnService` | Graph + security |
| 3 | `skills`, `explainableRecall`, `reflexion`, `attestationLog`, `batchOperations`, `memoryConsolidation` | Specialization |
| 4 | `causalGraph`, `nightlyLearner`, `learningSystem`, `semanticRouter` | Causal + routing |
| 5 | `graphTransformer`, `sonaTrajectory`, `contextSynthesizer`, `rvfOptimizer`, `mmrDiversityRanker`, `guardedVectorBackend` | Advanced services |
| 6 | `federatedSession`, `graphAdapter` | Session management |

`graphAdapter` is currently disabled pending an external graph-DB connection (tracked in ADR-095). Other Level-2/3 security controllers (`mutationGuard`, `attestationLog`, `gnnService`, `rvfOptimizer`, `guardedVectorBackend`) were activated by ADR-095 G7 in ruflo 3.6.23+.

## G7 controllers (activated by ADR-095)

[ADR-095](../../v3/docs/adr/ADR-095-architectural-gaps-from-april-audit.md) closed five previously-disabled AgentDB controllers:

| Controller | Role | Source |
|---|---|---|
| `gnnService` | Graph Neural Network embeddings + relational scoring over the AgentDB causal graph. No-arg construction. | `agentdb/dist/src/services/GNNService.js` |
| `rvfOptimizer` | RuVector format compaction — quantizes + dedupes vector blocks before persistence. | `agentdb/dist/src/optimizations/RVFOptimizer.js` |
| `mutationGuard` | WASM-backed proof generation for state mutations (ADR-060). | `agentdb/dist/src/security/MutationGuard.js` |
| `attestationLog` | Hash-chained audit log of mutations. Backed by a dedicated `.swarm/attestation.db`. | `agentdb/dist/src/security/AttestationLog.js` |
| `GuardedVectorBackend` | Wraps the existing vectorBackend with `mutationGuard` + `attestationLog`. | `agentdb/dist/src/backends/ruvector/GuardedVectorBackend.js` |

## Commands

- `/agentdb-mod` — AgentDB health, controller status, session management
- `/embeddings` — RuVector embedding engine status and operations

## Skills

- `agentdb-query` — Query AgentDB with semantic routing and hierarchical recall
- `vector-search` — HNSW vector search + RaBitQ quantization + 3 tuning profiles

## Namespace convention

This plugin owns the namespace convention that downstream plugins consume. Following it keeps cross-plugin search discoverable and avoids accidental key collisions in the bridge.

### Naming

`<plugin-stem>-<intent>` in kebab-case. Examples already in the wild:

| Plugin | Namespaces |
|---|---|
| `ruflo-browser` | `browser-sessions`, `browser-selectors`, `browser-templates`, `browser-cookies` |
| `ruflo-rag-memory` | (uses bridge target `claude-memories`) |
| `ruflo-intelligence` | (uses fallback target `pattern`) |

### Reserved namespaces (do NOT shadow)

| Namespace | Owned by | Source |
|---|---|---|
| `pattern` | ReasoningBank fallback writes here | `agentdb-tools.ts:144` |
| `claude-memories` | Claude Code auto-memory bridge target | bridge |
| `default` | `memory_store` default | `memory-tools.ts` |

### Where namespace strings actually apply

Namespace is **not** a universal parameter. Read the routing carefully:

- `memory_*` and `embeddings_search` route by namespace — pass it.
- `agentdb_hierarchical-*` routes by `tier` (`working|episodic|semantic`) — namespace argument is ignored.
- `agentdb_pattern-*` routes through the ReasoningBank controller — namespace argument is ignored.
- `agentdb_causal-edge` routes through the causal graph — namespace argument is ignored.

Don't pass `namespace: 'browser-cookies'` to `agentdb_pattern-store` and expect filtering. It will be silently dropped.

### GC posture

This plugin **does not** GC namespaces. Consumer plugins that want lifecycle (e.g., `browser-sessions` after a `purge`) own their own deletion via `memory_delete` + `agentdb_consolidate`. If you need cleanup, schedule it.

### Naming guardrails

A namespace SHOULD NOT contain `:` (collides with key-internal delimiters used in the bridge), MUST be ≤200 chars, and MUST pass `validateIdentifier` (the same validator already used in `agentdb-tools.ts:122`).

## How Claude Code populates AgentDB

The `claude-memories` reserved namespace is filled by Claude Code's own auto-memory bridge, not by direct user calls. Two mechanisms:

| Mechanism | Trigger | What it writes |
|---|---|---|
| `memory_import_claude` MCP tool | Manual or hook-driven | Reads `~/.claude/projects/*/memory/*.md`, parses YAML frontmatter, splits sections, stores with 384-dim embeddings. `allProjects: true` imports from ALL Claude projects. |
| `.claude/helpers/auto-memory-hook.mjs` | `SessionStart` (import) and `SessionEnd` (sync) — wired in `.claude/settings.json` | `import` → calls into the bridge for the current project; `sync` → flows AgentDB insights back to `~/.claude/projects/*/memory/MEMORY.md` |

To inspect or refresh:

```bash
# What's in the bridge right now?
mcp tool call memory_bridge_status --json

# Force a re-import from Claude Code's project memory
mcp tool call memory_import_claude --json -- '{"allProjects": true}'

# Cross-namespace search across claude-memories + auto-memory + patterns + tasks + feedback
mcp tool call memory_search_unified --json -- '{"query": "your query"}'
```

`memory_search_unified` defaults to searching `['default', 'claude-memories', 'auto-memory', 'patterns', 'tasks', 'feedback']` — these are the namespaces the bridge actually populates. The `default` namespace is the catch-all; `auto-memory` is distinct from `claude-memories` (auto-memory holds bridge-internal cache, claude-memories holds parsed `*.md` sections).

> **Pluralization gotcha:** the ReasoningBank fallback writes to `pattern` (singular). Other hooks (`hooks pretrain`, neural training paths) write to `patterns` (plural). They are different namespaces. When in doubt, `memory_list --namespace pattern` and `memory_list --namespace patterns` will tell you which one your data is in. Don't refactor your downstream code to "fix" the pluralization until you've confirmed which namespace was actually written.

## Hook integration convention

Several Claude Code hooks fire writes into AgentDB. Consumer plugins should know which namespaces accumulate state automatically vs. by explicit call, so they don't rebuild what the hook system already provides.

| Hook | Tool invoked | Target namespace | Notes |
|------|--------------|------------------|-------|
| `SessionStart` | `memory_import_claude` (via auto-memory-hook.mjs) | `claude-memories` | Imports `~/.claude/projects/*/memory/*.md` into AgentDB on every session start |
| `SessionEnd` | `auto-memory-hook.mjs sync` | bridge → `MEMORY.md` | Flows AgentDB insights back to Claude Code's MEMORY.md |
| `post-task --train-neural` | `agentdb_pattern-store` (ReasoningBank) | `pattern` (with `memory-store-fallback` if registry unavailable) | Stores task-completion patterns for SONA distillation |
| `pretrain` (one-shot) | `memory_store` | `patterns` (plural) | Bootstrap learning corpus |
| `trajectory-begin/step/end` (ruvector hooks) | ruvector substrate (separate plugin) | sona/agentdb namespaces handled by `ruflo-ruvector` | See `plugins/ruflo-ruvector/docs/adrs/0001-pin-ruvector-0.2.25.md` |

Implication for consumer plugins:

- **Don't double-write.** If you're already calling `hooks post-task --train-neural`, you don't also need to manually `memory_store --namespace pattern`. Pick one path.
- **Don't refresh `claude-memories` yourself.** It auto-imports on every SessionStart. Manual `memory_import_claude` is for force-refresh, not steady-state.
- **Surface fallback responses.** When `controller: 'memory-store-fallback'` comes back from `agentdb_pattern-store`, the data still landed — see "Pattern-store fallback" below.

## Operational fallbacks

Three fallbacks exist in the bridge code; consumers should branch on them rather than treat them as soft failures.

### Pattern-store fallback (ADR-093 F4)

When the ReasoningBank controller registry returns null, `agentdb_pattern-store` writes through to `memory_store` and returns:

```json
{
  "success": true,
  "patternId": "pattern-...",
  "controller": "memory-store-fallback",
  "note": "ReasoningBank controller registry unavailable. Pattern persisted via memory_store."
}
```

A `controller: 'memory-store-fallback'` response is a pattern that **was persisted** — not an error. Source: `agentdb-tools.ts:138-161`.

### Causal-edge graph-node backend (ADR-087)

`agentdb_causal-edge` tries the native `@ruvector/graph-node` backend first; on failure, falls back to the bridge. The response includes `_graphNodeBackend: true` when the native backend handled the call. Source: `agentdb-tools.ts:267-290`.

### Bridge unavailable

When `bridgeHealthCheck()` returns null (the `@claude-flow/memory` package is not installed or `controller-registry.ts` is missing), every `agentdb_*` handler returns:

```json
{
  "success": false,
  "error": "AgentDB bridge not available — @claude-flow/memory not installed... Use memory_store/memory_search tools instead."
}
```

Replacement table for bridge-unavailable mode:

| Unavailable `agentdb_*` | Use instead |
|---|---|
| `agentdb_hierarchical-store` / `_recall` | `memory_store` / `memory_search` |
| `agentdb_pattern-store` / `_search` | `memory_store --namespace pattern` / `memory_search --namespace pattern` |
| `agentdb_semantic-route` | `embeddings_search` |
| `agentdb_context-synthesize` | `memory_search_unified` |

## Verification

```bash
bash plugins/ruflo-agentdb/scripts/smoke.sh
# Expected: "10 passed, 0 failed"
```

The smoke script is the contract. It calls each documented MCP tool, exercises the RaBitQ workflow, and source-inspects the fallback path (no env-var gate exists to force the fallback live).

## As a mod (0.4.6, ADR-445)

A function-hook mod ships beside the skills. Needs a Claude Code with mods (2.1.287+); older builds ignore it.

| Piece | Default | What it does |
|---|---|---|
| **Secret guard** | on | Refuses a memory write (`agentdb_hierarchical-store`, `agentdb_pattern-store`, `agentdb_batch`, `agentdb_causal-edge`, `memory_store`, `hooks_remember`, `hooks_intelligence_pattern-store`, `agentdb_feedback`, `agentdb_session-end`, `hive-mind_memory`, `session_save`) that holds a private key, cloud/GitHub/Slack token, bearer token, JWT or key-like assignment. The secret is never echoed. The shared screen (`hooks/screen.ts`, copied to every mod by `scripts/sync-mod-screen.mjs`) judges an assignment by its value: calls, env references, identifier paths, placeholders, UUIDs, secret-manager paths and hyphenated names are not secrets; a literal needs two character classes (one a digit or symbol) and at least 2.5 bits of entropy per character. Vendor keys (Stripe, npm, HuggingFace, SendGrid, Twilio, Slack webhooks) and `scheme://user:pass@host` URLs are matched by shape; input is scanned in one pass up to 200 KB (head and tail beyond that). |
| **Import file screen** | on (with the guard) | `memory_import` takes only a path, so the guard also reads the file at `inputPath` and refuses the import when it holds a secret (same message, never echoing it). Best effort, not a gate, and it **fails open**: a file over 1 MB, a directory, a missing or unreadable file, a path outside the project root and your home, a path with `..`, a backslash or a null byte, a non-string path, or a stat/read error all let the import proceed unread. Symlinks are not resolved. `rvf_ingest` is still unguarded. |
| **Recall into prompts** | **off** | Attaches the best 1–5 memories to each prompt as framed, per-prompt context (the prompt cache is not disturbed). Read through the already-connected tools, in order: `memory_search` (semantic: the only reader that finds a paraphrase; its 60-character cut is completed with `memory_retrieve`), `agentdb_hierarchical-recall` and `agentdb_pattern-search` (substring matches, so also asked with the prompt's salient words), ruvector `hooks_recall`. A result scoring under 0.25 is noise and skipped. No CLI, no network. Skipped for slash commands, `!` lines and short prompts; gives up after `recallDeadlineMs` (800; the first recall of a fresh session takes 0.5–1.5 s, so consider 1500); cached 10 minutes. |
| **Untrusted memory** | always | A retrieved memory with a secret or an instruction-to-the-model phrase is dropped; the rest are control-character-stripped, capped (5 items, 400 chars each, 1500 total) and framed as data. |
| **`/agentdb-mod`** | — | `status`, `recall <text>`, `scan <text>`, `recent`; answered locally, no model call. |
| **Status file** | — | `.claude-flow/agentdb-mod/status.json` (counts and short snippets); the ruflo console's Memory page shows it. |

**Permissions:** the mod's reads go through Claude Code's permission rules, and a headless (`-p`) or fresh session refuses a tool nobody allowed. Allow the readers you use, e.g. `mcp__<server>__memory_search`, `memory_retrieve`, `agentdb_hierarchical-recall`, `agentdb_pattern-search`. A refusal is counted in `errors` and named in `lastError` in the status file; before 0.4.1 it read as "nothing relevant".

Options (`userConfig`): `recall` off|on, `recallLimit` 1–5, `recallDeadlineMs` 200–3000, `guard` on|off, `source` auto|agentdb|ruvector|none.

```bash
claude plugin test plugins/ruflo-agentdb      # 109 tests: screening, recall, reader fallback, guard, /agentdb-mod, deadline, cache, live-run findings
scripts/live-agentdb-recall.sh                 # live harness against a real AgentDB (haiku, about $1); results in v3/docs/validation/agentdb-recall-live-2026-10.md
node plugins/ruflo-agentdb/scripts/bench.mjs  # per-call cost of the pure paths (tens of µs)
```

## Architecture Decisions

- [`ADR-445` — AgentDB as a mod](../../v3/docs/adr/ADR-445-agentdb-as-a-mod.md)
- [`ADR-0001` — Optimize ruflo-agentdb (accurate surface, RaBitQ, namespacing, smoke contract)](./docs/adrs/0001-agentdb-optimization.md)

## Related Plugins

- `ruflo-rag-memory` — simple store/search/recall interface; consumes the `claude-memories` reserved namespace
- `ruflo-intelligence` — SONA neural patterns; consumes the `pattern` reserved namespace via ReasoningBank
- `ruflo-browser` — composes the namespace convention for `browser-sessions/-selectors/-templates/-cookies` (ADR-0001 §3 there)
- `ruflo-ruvector` — pinned ruvector CLI; sibling substrate plugin

## License

MIT
