diff --git a/.claude/gbrain-setup.md b/.claude/gbrain-setup.md new file mode 100644 index 000000000..bcf996102 --- /dev/null +++ b/.claude/gbrain-setup.md @@ -0,0 +1,251 @@ +# GBrain Setup for Open-Generative-AI + +## What Was Installed + +This project now has GBrain integrated for persistent agent memory. + +### Installation Summary + +| Component | Status | Details | +|-----------|--------|---------| +| **Brain Engine** | ✅ PGLite | Local Postgres (WASM), zero-config at `~/.gbrain/brain.pglite` | +| **Memory Verbs** | ✅ Enabled | 7-verb protocol: remember, recall, entity, synthesize, forget, context_pack, delta | +| **Memory Writeback** | ✅ Enabled | Ambient capture mode (salient) — automatically saves important decisions | +| **MCP Integration** | ✅ Ready | Stdio MCP server configured in `.claude/mcp/gbrain.json` | +| **Search** | ✅ Keyword-only | Vector embeddings optional (requires API key) | +| **Team Brain** | ⏳ Optional | Can upgrade to Supabase multi-user later | + +### Files Added + +``` +├── .claude/mcp/gbrain.json # MCP configuration +├── docs/GBRAIN_INTEGRATION.md # Full integration guide +├── docs/GBRAIN_QUICKSTART.md # 5-minute quick start +└── ~/.gbrain/ # Brain home (user's directory) + ├── brain.pglite # PGLite database + ├── config.json # Brain configuration + └── brain-repo/ # Optional markdown pages dir +``` + +### What It Does + +**Cross-Session Memory** +- Tell Claude Code to remember something in one session +- Restart Claude Code +- Ask it back → it knows the answer (from brain, not chat history) + +**Automatic Capture** +- Important decisions, commitments, and insights are automatically saved +- Skips: greetings, questions, tool output, code snippets + +**Knowledge Retrieval** +- `gbrain search "topic"` — fast keyword search +- `gbrain think "question?"` — synthesized answer with gaps +- CLI, MCP, or Claude Code tools — your choice + +## How to Use + +### Quick Start (5 minutes) + +```bash +# 1. Restart Claude Code — MCP loads at startup + +# 2. In Claude Code, tell it to remember something: +remember: "I'm refactoring the API response caching" + +# 3. Restart Claude Code (clear chat, no context) + +# 4. Ask it back: +recall: "what am I working on?" +# → It knows! (from brain, not chat history) + +# 5. Capture a note: +gbrain capture "Redis TTL tuning reduced lookup time 50ms → 2ms" + +# 6. Search what you know: +gbrain search "caching strategy" +``` + +### Claude Code Tools Available + +When connected via MCP, Claude Code has access to: + +- **`remember(fact, entity, provenance)`** — save a memory +- **`recall(entity)`** — retrieve by topic/entity +- **`synthesize(question)`** — get answer with sources + gaps +- **`entity(slug)`** — query specific page +- **`forget(slug)`** — remove memory +- **`context_pack()`** — summary of everything +- **`delta(since_slug)`** — what changed since last recall + +### CLI (No MCP) + +```bash +gbrain capture "note here" +gbrain search "query" +gbrain think "analytical question?" +gbrain remember "fact" --entity people/alice +gbrain recall people/alice +gbrain doctor # health check +``` + +## Configuration + +### Current Settings + +```bash +gbrain config show +``` + +Key settings: +- `memory.auto_writeback: salient` — automatic capture enabled +- `search.mode: conservative` — keyword-only (embeddings optional) +- Engine: PGLite (local, zero-cost) + +### Enable Semantic Search (Optional) + +Requires an embedding API key: + +```bash +# Option 1: Voyage (recommended) +export VOYAGE_API_KEY="pa-..." +gbrain init --force --embedding-model voyage:voyage-4 + +# Option 2: OpenAI +export OPENAI_API_KEY="sk-..." +gbrain init --force --embedding-model openai:text-embedding-3-small + +# Sync after setup +gbrain sync +``` + +Then queries like "Who is working on RAG?" actually work (semantic search). + +### Upgrade to Team Brain (Optional) + +When ready for multi-user: + +```bash +# Follow company-brain tutorial: https://github.com/garrytan/gbrain/blob/master/docs/tutorials/company-brain.md +# Upgrades to Supabase with OAuth role-scoping +``` + +## Architecture + +### Trust Boundary + +- **Local only**: PGLite runs locally, all data stays on machine +- **API calls**: Only if you set API keys (embeddings, synthesis) +- **No defaults**: Nothing phones home unless explicitly configured + +### Storage + +``` +~/.gbrain/ +├── brain.pglite # Postgres database (WASM) +├── config.json # Configuration +├── brain-repo/ # Optional git repo with markdown pages +└── audit/ # Audit logs +``` + +Delete `~/.gbrain/` to reset completely. + +### Data Model + +Pages have: +- **Type**: person, company, project, meeting, note, etc. +- **Content**: markdown body + frontmatter +- **Timeline**: captures + edits + synthesis events +- **Graph edges**: auto-linked references (works_at, attended, etc.) +- **Visibility**: shared by default; `visibility: private` for local-only + +## Testing + +### Verify Installation + +```bash +# Health check +gbrain doctor + +# List what's in brain +gbrain search "Open-Generative-AI" + +# Check MCP is ready +claude mcp list # Should show gbrain with ✓ +``` + +### Test Cross-Session Memory + +**Session 1:** +```bash +# In Claude Code +remember: "Testing cross-session memory on Open-Generative-AI" +``` + +**Session 2** (restart Claude Code, new session): +```bash +# In Claude Code +recall: "What was I testing?" +# Expected: "Testing cross-session memory on Open-Generative-AI" +``` + +## Troubleshooting + +### Brain not working in Claude Code? + +1. Restart Claude Code — MCP loads at startup +2. Check: `gbrain doctor` +3. Verify: `claude mcp list` should show `gbrain` + +### Search returns no results? + +- Normal in keyword-only mode +- Add API key for embeddings: `export VOYAGE_API_KEY=... && gbrain init --force --embedding-model voyage:voyage-4` + +### Memory not persisting? + +- Verify using `gbrain recall ` from CLI +- If CLI works but Claude Code doesn't: MCP connection issue (restart Claude Code) + +### Brain file corrupted? + +```bash +gbrain pglite-repair --dry-run # Check +gbrain pglite-repair --yes # Fix in place +``` + +## Next Steps + +1. **✅ Setup complete** — you have working brain right now +2. **Restart Claude Code** — MCP wiring loads at startup +3. **Test memory** — follow "Quick Start" above +4. **Enable embeddings** (optional) — `export VOYAGE_API_KEY=... && gbrain init --force ...` +5. **Explore skills** (optional) — `gbrain advisor` lists 73 available skills +6. **Team setup** (optional) — follow company-brain tutorial for multi-user + +## Resources + +- **Quick Start**: `docs/GBRAIN_QUICKSTART.md` +- **Full Integration Guide**: `docs/GBRAIN_INTEGRATION.md` +- **GBrain Docs**: https://github.com/garrytan/gbrain +- **Protocol**: https://github.com/garrytan/gbrain/blob/master/docs/protocol/MEMORY_VERBS_v1.md +- **Troubleshooting**: `gbrain doctor` + +## Stats + +``` +Brain Home: ~/.gbrain/ +Engine: PGLite (Postgres 17 via WASM) +Pages: 1 (project overview) +Embeddings: Not configured (keyword-only search) +Memory Verbs: 7 (recall, remember, synthesize, entity, forget, context_pack, delta) +Skills: 73 available +Cost: $0/month (with embeddings: ~$40/mo @ 10K queries) +``` + +--- + +**Status: 🟢 Ready to use** + +Last updated: 2026-09-12 +Setup by: Claude Code Integration diff --git a/.claude/mcp/gbrain.json b/.claude/mcp/gbrain.json new file mode 100644 index 000000000..147e04afe --- /dev/null +++ b/.claude/mcp/gbrain.json @@ -0,0 +1,15 @@ +{ + "mcpServers": { + "gbrain": { + "command": "gbrain", + "args": [ + "serve", + "--surface", + "verbs" + ], + "env": { + "GBRAIN_HOME": "/root/.gbrain" + } + } + } +} diff --git a/docs/GBRAIN_INTEGRATION.md b/docs/GBRAIN_INTEGRATION.md new file mode 100644 index 000000000..3035f791d --- /dev/null +++ b/docs/GBRAIN_INTEGRATION.md @@ -0,0 +1,221 @@ +# GBrain Integration Guide + +## Overview + +GBrain is a persistent knowledge brain for AI agents. This project has been configured with GBrain to provide: + +- **Cross-session memory** — Claude Code remembers what you tell it across sessions +- **Keyword-based retrieval** — Search through captured notes and memories +- **Persistent facts** — Automatic capture of important decisions and learnings +- **Graph-based knowledge** — Entity relationships and connections + +## Setup Status + +✅ **Initialized**: PGLite local brain at `~/.gbrain/brain.pglite` +✅ **Memory writeback**: Enabled (salient mode) — captures important decisions automatically +⏳ **Embeddings**: Not yet configured (optional but recommended for semantic search) + +## How to Use + +### 1. Enable MCP in Claude Code + +Add gbrain to Claude Code's MCP servers: + +```bash +claude mcp add gbrain -- gbrain serve --surface verbs +``` + +Then restart Claude Code. You'll have access to the 7-verb memory protocol: +- `remember` — save a fact for future sessions +- `recall` — retrieve remembered facts by topic +- `entity` — query information about a specific person/company/project +- `synthesize` — get a summary with citations and gaps +- `forget` — remove a memory +- `context_pack` — get a summary of context for this brain +- `delta` — get what's changed since last recall + +### 2. Quick Test + +In a Claude Code session: + +``` +remember: "My preferred Python style is list comprehensions over loops" +``` + +Then restart Claude Code and ask: + +``` +recall: "my Python style" +``` + +It will remember across sessions — the answer comes from gbrain, not chat history. + +### 3. Capturing Knowledge + +**Manually capture a note:** +```bash +gbrain capture "Built the API response caching layer. Key insight: Redis TTL management is the bottleneck, not the cache hit rate." +``` + +**Capture from a file:** +```bash +gbrain capture --file ./notes/2026-09-12-meeting.md +``` + +**Via stdin (from scripts/pipes):** +```bash +echo "Completed the performance audit" | gbrain capture --stdin +``` + +### 4. Querying Your Brain + +**Keyword search (fast, works now):** +```bash +gbrain search "API performance" +``` + +**Synthesis with gaps (recommended for decisions):** +```bash +gbrain think "What's our current strategy on caching?" +``` + +Returns a synthesized answer with sources and an honest note on what the brain doesn't know yet. + +## Architecture + +### Two Engines, One Contract + +- **PGLite** (current): Embedded Postgres via WASM, zero-config, local-only +- **Postgres + Supabase**: For team deployments (100+ users, 10K+ pages) + +### Storage Location + +All brain data lives in `~/.gbrain/`: +- `brain.pglite` — Postgres database (WASM-based) +- `config.json` — Brain configuration +- `brain-repo/` — Git repo with markdown pages (optional) + +### Memory Writeback + +When enabled (salient mode), Claude Code automatically captures: +- Direct statements ("I decided to refactor X") +- Commitments ("I'll ship this by Friday") +- Insights ("Learned that Y requires Z") + +Excludes: greetings, questions, tool output, code snippets + +## Advanced Setup + +### Enable Semantic Search (Recommended) + +Requires an embedding API key. Pick one: + +**Option 1: Voyage (recommended, $0.04/M tokens)** +```bash +export VOYAGE_API_KEY="pa-..." +gbrain init --force --embedding-model voyage:voyage-4 --path ~/.gbrain/brain.pglite +``` + +**Option 2: OpenAI** +```bash +export OPENAI_API_KEY="sk-..." +gbrain init --force --embedding-model openai:text-embedding-3-small --path ~/.gbrain/brain.pglite +``` + +After setup: +```bash +gbrain sync # re-embed existing pages +``` + +### Team Brain (Multi-User) + +Upgrade to Postgres + Supabase for team access with role-scoped privacy: + +```bash +gbrain init --supabase +# Guides you through Supabase setup +# Adds OAuth scoping so team members only see allowed pages +``` + +See [company-brain tutorial](https://github.com/garrytan/gbrain/blob/master/docs/tutorials/company-brain.md) for full setup. + +### Bulk Import + +Import existing notes: + +```bash +gbrain import ~/Notes ~/Documents --no-embed +``` + +After setting up embeddings: + +```bash +gbrain sync +``` + +## CLI Cheat Sheet + +```bash +# Memory +gbrain remember "fact here" --entity people/alice --provenance meeting +gbrain recall people/alice +gbrain forget slug/inbox/2026-09-12-xyz + +# Query +gbrain search "what did Alice say about pricing?" +gbrain think "should we use Redis for caching?" + +# Capture +gbrain capture "note here" +gbrain capture --file ./notes.md +echo "from pipe" | gbrain capture --stdin + +# Admin +gbrain doctor # Health check +gbrain config show # View current config +gbrain search modes # Show search cost matrix +gbrain schema active # What page types are available +gbrain sources list # Manage knowledge sources +``` + +## FAQ + +**Q: Does this send data to external servers?** +A: No. PGLite runs locally. Only API keys you explicitly set (embedding providers) connect externally. + +**Q: Can I switch to a team brain later?** +A: Yes. Start with PGLite, graduate to Supabase when you're ready. Pages migrate automatically. + +**Q: What if I forget to enable MCP?** +A: The brain still works via CLI (`gbrain search`, `gbrain remember`), but Claude Code won't have memory access. Re-run `claude mcp add gbrain -- gbrain serve --surface verbs`. + +**Q: Can multiple agents share one brain?** +A: Yes (with OAuth scoping). Agents on the same PGLite brain see all pages. With Supabase, you can scope per agent. + +**Q: Does GBrain work in Claude Code cloud sessions?** +A: Yes. The cloud sandbox has disk space for PGLite. Queries might be slightly slower than on your laptop. + +## Next Steps + +1. ✅ **Restart Claude Code** — MCP wiring loads on startup +2. **Test memory** — tell Claude Code something, restart, ask it back +3. **Enable embeddings** (optional) — for semantic search +4. **Import notes** (optional) — bulk-load your knowledge +5. **Tune search mode** — `gbrain config set search.mode balanced` if desired (costs more, better results) + +## Resources + +- **Docs**: https://github.com/garrytan/gbrain +- **Protocol**: `docs/protocol/MEMORY_VERBS_v1.md` (in gbrain repo) +- **Troubleshooting**: `gbrain doctor` catches most issues +- **Contrib Guide**: https://github.com/garrytan/gbrain/blob/master/CONTRIBUTING.md + +--- + +**Health Check:** +```bash +gbrain doctor +gbrain search "test" # Should show "No results" (keyword-only mode, expected) +``` + +Happy remembering! 🧠 diff --git a/docs/GBRAIN_QUICKSTART.md b/docs/GBRAIN_QUICKSTART.md new file mode 100644 index 000000000..b77d992e3 --- /dev/null +++ b/docs/GBRAIN_QUICKSTART.md @@ -0,0 +1,148 @@ +# GBrain Quick Start + +GBrain is now integrated with this project. This guide gets you using it in 5 minutes. + +## What You Have + +✅ Local brain initialized at `~/.gbrain/brain.pglite` +✅ Memory writeback enabled (auto-captures decisions) +✅ MCP configuration ready (`.claude/mcp/gbrain.json`) +✅ 7-verb memory protocol loaded + +## Step 1: Restart Claude Code + +The MCP wiring loads at startup. Restart Claude Code (desktop or CLI) after the integration is complete. + +## Step 2: Test Memory Across Sessions + +**In your first Claude Code session:** + +Tell Claude Code to remember something: +``` +remember: "I'm working on the API caching layer for Open-Generative-AI" +``` + +Close Claude Code completely. + +**In a new session (clear chat history, no context window):** + +Ask it back: +``` +recall: "what am I working on?" +``` + +**Expected result:** Claude Code knows the answer even though chat history was cleared. The brain persisted it across sessions. + +## Step 3: Capture Knowledge + +As you work, capture insights: + +```bash +# From terminal +gbrain capture "Redis TTL tuning is the bottleneck, not cache hit rate. Reduces lookup time from 50ms to 2ms." + +# Or pipe from script +echo "Implemented batch API response caching" | gbrain capture --stdin + +# Or from a file +gbrain capture --file ./session-notes.md +``` + +## Step 4: Query What You Know + +Ask the brain questions: + +```bash +# Keyword search (fast) +gbrain search "caching strategy" + +# Synthesis with gaps (for decisions) +gbrain think "What's our current approach to API performance?" +``` + +## The 7 Memory Verbs + +When Claude Code is connected, use these tools: + +| Verb | Use Case | Example | +|------|----------|---------| +| `remember` | Save a fact for future sessions | "remember: I use async/await in this project" | +| `recall` | Retrieve facts by topic | "recall: our API performance strategy" | +| `entity` | Query about a specific person/company | "entity: people/alice" | +| `synthesize` | Get an answer with sources and gaps | "synthesize: what do we know about the user auth system?" | +| `forget` | Remove a memory | "forget: the old caching approach" | +| `context_pack` | Get a summary of all context | "context_pack: summarize everything about this project" | +| `delta` | What changed since last recall | "delta: show me what's new about the API" | + +## CLI Cheat Sheet + +```bash +# Capture & retrieve +gbrain capture "My note" +gbrain search "topic" +gbrain think "analytical question?" + +# View what you have +gbrain doctor # Health check +gbrain config show # Current settings +gbrain sources list # Knowledge sources + +# Memory management (no encoding yet, keyword only) +gbrain remember "fact" --entity people/alice +gbrain recall people/alice +gbrain forget inbox/2026-09-12-xyz123 +``` + +## Troubleshooting + +**Brain not working in Claude Code?** +- Restart Claude Code — MCP loads at startup +- Check: `gbrain doctor` +- Verify: `claude mcp list` should show `gbrain` with ✓ + +**Search returns no results?** +- Normal — keyword-only mode until embeddings configured +- To enable semantic search: set `VOYAGE_API_KEY` and run `gbrain init --force --embedding-model voyage:voyage-4` + +**Can't remember things across sessions?** +- Make sure you're using `remember` tool, not just telling Claude Code +- Verify: `gbrain recall ` should return it + +## Next: Enable Semantic Search (Optional) + +For richer queries, enable embeddings: + +```bash +export VOYAGE_API_KEY="pa-..." # Get from https://www.voyageai.com +gbrain init --force --embedding-model voyage:voyage-4 +gbrain sync # Re-embeds existing pages +``` + +Then queries like "Who from our portfolio is working on RAG?" actually work. + +## Next: Team Brain (Optional) + +To share brain across team members with role-scoped access: + +1. Follow [company-brain tutorial](https://github.com/garrytan/gbrain/blob/master/docs/tutorials/company-brain.md) +2. Upgrade from PGLite to Supabase +3. Set up OAuth scoping + +## Resources + +- **Full docs**: `docs/GBRAIN_INTEGRATION.md` +- **GBrain repo**: https://github.com/garrytan/gbrain +- **Health check**: `gbrain doctor` +- **Config**: `~/.gbrain/config.json` + +--- + +**Status:** 🟢 Ready to use. You have cross-session memory + keyword search working now. + +**Quick test:** +```bash +gbrain search "Open-Generative-AI" +# Should find the project overview we captured +``` + +Happy remembering! 🧠