Lesson #1468

← Back to Knowledge Board
memory-context-pack-rag-stack-universal-memory-bus
ID
1468
Author
ai
Agent
agent-claude
Reviewed
✓ Yes
Source authority
75 / 100
Source
Tools and hook that let every agent (claude, codex, or-agent, gemini) reach the same memory pool via rag-stack lessons API.
Source issue
β€”
Created at
2026-05-12T10:02:19.012044+00:00
Valid until
β€”
Deprecated at
β€”
Supersedes
β€”
Obsidian path
/root/.claude/projects/-nvmetank1-projects/memory/reference_memory_context_pack.md
Obsidian hash
45331e3b072ca8cbf79c9409cf2ad4eb
Tags
claude-memory,reference

Content

**Built 2026-05-12** to close the context-gap surfaced by [[feedback_agents_md_canonical]]: external CLI agents have no access to `MEMORY.md`. Now they can pull the same auto-memories via rag-stack `/api/v1/lessons/search`.

## Tools

| Path | Purpose |
|---|---|
| `/usr/local/bin/memory-sync-to-rag` | Upsert one or all `memory/*.md` to rag-stack lessons (idempotent on `obsidian_path`). Triggers embedding via `nomic-embed-text`. |
| `/usr/local/bin/claude-context-pack` | Query rag-stack semantic search β†’ emit markdown block with top-K relevant memories. Fallback to local keyword scan if rag-stack down. |
| `/usr/local/bin/claude-memory-write-hook` | PostToolUse hook for Write/Edit/MultiEdit. Auto-syncs any save to `memory/*.md` into rag-stack. Wired in `~/.claude/settings.json`. |

## Usage

```bash
# Backfill or refresh (idempotent):
memory-sync-to-rag

# Sync just one file:
memory-sync-to-rag /root/.claude/projects/-nvmetank1-projects/memory/feedback_X.md

# Build a context-pack block for a Gitea-issue body or subagent prompt:
claude-context-pack "fix hero button on scandi mobile" --limit 5

# Raw JSON:
claude-context-pack --json "yoga deploy beta" --limit 3
```

## Integration points

- **Subagent dispatch (Pfad B):** Before `Agent(prompt=...)`, prefix the prompt with `$(claude-context-pack "<short task>")`. The subagent then sees the relevant memories despite its fresh context window.
- **Gitea-issue (Pfad A):** Append context-pack output to the issue body after `## Acceptance criteria`. The n8n `03-agent-dispatch` handler reads the body verbatim and passes it to codex/or-agent/gemini.
- **Auto-write:** Already wired via PostToolUse hook β€” every save to `memory/*.md` upserts within ~3s. No manual step needed.

## Config

- **rag-stack DB:** `/persistent/rag-stack/rag.db`, table `glug_lessons`.
- **docker-compose env (rag-stack):** `GLUG_DB_PATH=/data/rag.db`, `OLLAMA_URL=http://172.31.0.1:11434`.
- **Ollama models:** `nomic-embed-text` (768d, default), `bge-m3` (1024d).
- **All synced lessons:** `agent=agent-claude`, `tags=claude-memory,<type>`, `author=ai`, `source_authority=75`.
- **Search caveat:** synced lessons have `reviewed=0` (author=ai). `context-pack` passes `include_unreviewed=1` automatically.

## Verify

```bash
curl -s "http://localhost:8801/api/v1/lessons/recent?tags=claude-memory&limit=5&reviewed_only=0&full_content=0" | python3 -c 'import sys,json;d=json.load(sys.stdin);print(d["count"],"lessons in bus")'
```

Should return `21` (or however many `memory/*.md` exist) after a backfill.