Set up GBrain with auto-provision Supabase or PGLite, AGENTS.md injection, first import
Set up GBrain from scratch. Target: working brain in under 5 minutes.
gbrain doctor --json (all checks OK).~/.gbrain/update-state.json so future upgrades know what the user adopted or declined.bun add github:garrytan/gbrain
GBrain connects directly to Postgres over the wire protocol. NOT through the
Supabase REST API. You need the database connection string (a postgresql:// URI),
not the project URL or anon key. The password is embedded in the connection string.
Use the Shared Pooler connection string (port 6543), not the direct connection (port 5432). The direct hostname resolves to IPv6 only, which many environments can't reach. Find it: go to the project, click Get Connected next to the project URL, then Direct Connection String > Session Pooler, and copy the Shared Pooler connection string.
Do NOT ask for the Supabase anon key. GBrain doesn't use it.
Supabase gives you managed Postgres + pgvector (vector search built in) for $25/mo:
gbrain init --supabase -- interactive wizard (prompts for connection string)gbrain init --url <connection_string> -- direct, no promptsgbrain init --non-interactive --url <connection_string> -- for scripts/agentsgbrain doctor --json -- health check after initThere is no --local, --sqlite, or offline mode. GBrain requires Postgres + pgvector.
Guide the user through creating a Supabase project:
gbraingbrain init --non-interactive --url "postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres"
gbrain doctor --jsonOpenClaw/Hermes agent instructions: Store the Supabase access token in your persistent
env as SUPABASE_ACCESS_TOKEN. gbrain doesn't store it, you need it for future
gbrain doctor runs. Generate at: https://supabase.com/dashboard/account/tokens
If the user already has Postgres with pgvector:
gbrain init --non-interactive --url "<connection_string>"gbrain doctor --jsonIf the connection fails with ECONNREFUSED and the URL contains supabase.co,
the user probably pasted the direct connection (IPv6 only). Guide them to the
Session pooler string instead (see Phase A step 4).
echo "=== GBrain Environment Discovery ==="
for dir in /data/* ~/git/* ~/Documents/* 2>/dev/null; do
if [ -d "$dir/.git" ]; then
md_count=$(find "$dir" -name "*.md" -not -path "*/node_modules/*" -not -path "*/.git/*" 2>/dev/null | wc -l | tr -d ' ')
if [ "$md_count" -gt 10 ]; then
total_size=$(du -sh "$dir" 2>/dev/null | cut -f1)
echo " $dir ($total_size, $md_count .md files)"
fi
fi
done
echo "=== Discovery Complete ==="
Import the best candidate. For large imports (>1000 files), use nohup to survive session timeouts:
nohup gbrain import <dir> --no-embed --workers 4 > /tmp/gbrain-import.log 2>&1 &
Then check progress: tail -1 /tmp/gbrain-import.log
For smaller imports, run directly:
gbrain import <dir> --no-embed
Prove search works. Pick a semantic query based on what you imported:
gbrain search "<topic from the imported data>"
This is the magical moment: the user sees search finding things grep couldn't.
Start embeddings. Refresh stale embeddings (runs in background). Keyword search works NOW, semantic search improves as embeddings complete.
Backfill the knowledge graph. Populate typed links and structured timeline from the imported pages. Auto-link maintains both going forward, but historical pages need a one-time backfill.
gbrain extract links --source db --dry-run | head -20 # preview
gbrain extract links --source db # commit
gbrain extract timeline --source db # dated events
gbrain stats # verify links > 0
After this, gbrain graph-query <slug> --depth 2 works and search ranks
well-connected entities higher. Idempotent — safe to re-run anytime.
Supports --since YYYY-MM-DD for incremental runs on huge brains.
Skip if Phase C imported zero pages (auto-link handles new writes).
Offer file migration. If the repo has binary files (.raw/ directories with images, PDFs, audio):
"You have N binary files (X GB) in your brain repo. Want to move them to cloud storage? Your git repo will drop from X GB to Y MB. All links keep working."
If the user agrees, configure storage and run migration:
# Configure storage backend (Supabase Storage recommended)
gbrain config set storage.backend supabase
gbrain config set storage.bucket brain-files
gbrain config set storage.projectUrl <supabase-url>
gbrain config set storage.serviceRoleKey <service-role-key>
# Migrate binary files to cloud (3-step lifecycle)
gbrain files mirror <brain-dir> # Upload to cloud, keep local
gbrain files redirect <brain-dir> # Replace local with .redirect.yaml pointers
# (optional) gbrain files clean <brain-dir> --yes # Remove pointers too
After migration, gbrain files upload-raw handles new files automatically:
small text/PDFs stay in git, large/media files go to cloud with .redirect.yaml
pointers. Files >= 100 MB use TUS resumable upload for reliability.
If no markdown repos are found, create a starter brain with a few template pages (a person page, a company page, a concept page) from docs/GBRAIN_RECOMMENDED_SCHEMA.md.
Run the migration runner once, then install autopilot. Two commands, done:
gbrain apply-migrations --yes # applies any pending migrations; idempotent on healthy installs
gbrain autopilot --install # supervises itself + forks the Minions worker; env-aware
What gbrain autopilot --install does:
~/Library/LaunchAgents/com.gbrain.autopilot.plist.~/.config/systemd/user/gbrain-autopilot.service
with Restart=on-failure.~/.gbrain/start-autopilot.sh and prints the one-line your agent's
bootstrap should source to launch autopilot on every container start.
Auto-injects into OpenClaw's hooks/bootstrap/ensure-services.sh if
detected (use --no-inject to opt out).Autopilot then supervises the Minions worker as a child process. Users get
sync + extract + embed + backlinks + durable Postgres-backed job processing
from ONE install step. No separate gbrain jobs work daemon to manage.
On PGLite, autopilot runs inline (PGLite's exclusive file lock blocks a separate worker process). Everything else still works.
If apply-migrations prints "N host-specific items need your agent's
attention," read ~/.gbrain/migrations/pending-host-work.jsonl + walk
skills/migrations/v0.11.0.md + docs/guides/plugin-handlers.md to
register host-specific handlers. Re-run apply-migrations after each
batch.
Inject the brain-first lookup protocol into the project's AGENTS.md (or equivalent). This replaces grep-based knowledge lookups with structured gbrain queries.
| Task | Before (grep) | After (gbrain) |
|---|---|---|
| Find a person | grep -r "Pedro" brain/ | gbrain search "Pedro" |
| Understand a topic | grep -rl "deal" brain/ | head -5 && cat ... | gbrain query "what's the status of the deal" |
| Read a known page | cat brain/people/pedro.md | gbrain get people/pedro |
| Find connections | grep -rl "Brex" brain/ | xargs grep "Pedro" | gbrain query "Pedro Brex relationship" |
gbrain search "name" -- keyword match, fast, works without embeddingsgbrain query "what do we know about name" -- hybrid search, needs embeddingsgbrain get <slug> -- direct page read when you know the slug from steps 1-2grep fallback -- only if gbrain returns zero results AND the file may exist outside the indexed brainStop at the first step that gives you what you need. Most lookups resolve at step 1.
After creating or updating any brain page in the repo, sync immediately so the index stays current:
gbrain sync --no-pull --no-embed
This indexes new/changed files without pulling from git or regenerating embeddings.
Embeddings can be refreshed later in batch (gbrain embed --stale).
| Layer | What it stores | When to use |
|---|---|---|
| gbrain | World knowledge: people, companies, deals, meetings, concepts, media | "Who is Pedro?", "What happened at the board meeting?" |
| memory_search | Agent operational state: preferences, decisions, session context | "How does the user like formatting?", "What did we decide about X?" |
Both should be checked. gbrain for facts about the world. memory_search for how the agent should behave.
Read docs/GBRAIN_SKILLPACK.md. This is the reference architecture for how a
production agent uses gbrain: the brain-agent loop, entity detection, enrichment
pipeline, meeting ingestion, cron schedules, and the five operational disciplines.
Inject the key patterns into the agent's system context or AGENTS.md:
[Source: ...]Tell the user: "The production agent guide is at docs/GBRAIN_SKILLPACK.md. It covers the brain-agent loop, entity detection, enrichment, meeting ingestion, and cron schedules. Read it when you're ready to go from 'search works' to 'the brain maintains itself.'"
Run gbrain doctor --json and report the results. Every check should be OK.
If any check fails, the doctor output tells you exactly what's wrong and how to fix it.
If any gbrain command fails, run gbrain doctor --json first. Report the full
output. It checks connection, pgvector, RLS, schema version, and embeddings.
| What You See | Why | Fix |
|---|---|---|
| Connection refused | Supabase project paused, IPv6, or wrong URL | Use Session pooler (port 6543), or supabase.com/dashboard > Restore |
| Password authentication failed | Wrong password | Project Settings > Database > Reset password |
| pgvector not available | Extension not enabled | Run CREATE EXTENSION vector; in SQL Editor |
| OpenAI key invalid | Expired or wrong key | platform.openai.com/api-keys > Create new |
| No pages found | Query before import | Import files into gbrain first |
| RLS not enabled | Security gap | Run gbrain init again (auto-enables RLS) |
If the user's install did NOT include setting up auto-update checks (e.g., they used the manual install path or an older version of the OpenClaw/Hermes paste), offer it:
"Would you like daily GBrain update checks? I'll let you know when there's a new version worth upgrading to — including new skills and schema recommendations. You'll always be asked before anything is installed."
If they agree:
gbrain check-update --jsonIf already configured or user declines, skip.
The brain repo is the source of truth. If sync doesn't run automatically, the vector DB falls behind and gbrain returns stale answers. This phase is not optional.
Read docs/GBRAIN_SKILLPACK.md Section 18 for the full reference. Key points:
Check the connection pooler first. Sync uses transactions on every import.
If DATABASE_URL uses Supabase's Transaction mode pooler, sync will throw
.begin() is not a function and silently skip most pages. Verify the connection
string uses Session mode (port 6543, Session mode) or direct (port 5432).
Set up automatic sync. Choose the approach that fits your environment:
gbrain sync --repo /data/brain && gbrain embed --stalegbrain sync --watch --repo /data/brain under a process
manager. Pair with a cron fallback (watch exits after 5 consecutive failures).Verify sync works. Don't just check that the command ran. Check that it worked:
gbrain stats should show page count close to syncable file count in the repo.gbrain search.Chain sync + embed. Always run both: gbrain sync --repo <path> && gbrain embed --stale. For small syncs, embeddings are generated inline. The embed --stale is a safety net for any stale chunks.
Tell the user: "Live sync is configured. The brain will stay current automatically. I'll verify it's working in the next phase."
Run the full verification runbook to confirm the entire installation is working.
docs/GBRAIN_VERIFY.mdEvery check in the runbook should pass. The most important one is check 4 (live sync actually works): push a change, wait for sync, search for the corrected text. "Sync ran" is not the same as "sync worked."
Tell the user: "I've verified the full GBrain installation. Here's the status of each check: [list results]. Everything is working / [specific item] needs attention."
If already configured or user declines, skip.
After presenting the recommended directories (Phase C/E) and the user selects which
ones to create, write ~/.gbrain/update-state.json recording:
schema_version_applied: current gbrain versionskillpack_version_applied: current gbrain versionschema_choices.adopted: directories the user createdschema_choices.declined: directories the user explicitly skippedschema_choices.custom: directories the user added that aren't in the recommended schemaThis file enables future upgrades to suggest new schema additions without re-suggesting things the user already declined.
.begin() is not a function errors and silently skips pages. Always use Session mode (port 6543).GBRAIN SETUP COMPLETE
=====================
Engine: [PGLite / Supabase Postgres]
Connection: [verified / pooler mode confirmed]
Pages imported: N
Embeddings: N/N (keyword search active, semantic improving)
Live sync: [configured / method]
Health check: all OK / [specific failures]
Verification: [GBRAIN_VERIFY.md results]
Next steps:
- Read docs/GBRAIN_SKILLPACK.md for production agent patterns
- [any pending items]
gbrain init --non-interactive --url ... -- create braingbrain import <dir> --no-embed [--workers N] -- import filesgbrain search <query> -- search braingbrain doctor --json -- health checkgbrain check-update --json -- check for updatesgbrain embed refresh -- generate embeddingsgbrain embed --stale -- backfill missing embeddingsgbrain sync --repo <path> -- one-shot sync from brain repogbrain sync --watch --repo <path> -- continuous sync pollinggbrain config get sync.last_run -- check last sync timestampgbrain stats -- page count + embed coverage