Files
gbrain/INSTALL_FOR_AGENTS.md
T
3aedffadc0 fix(docs): comprehensive drift audit — contradictions, broken links, stale refs (#1201)
A community member reported docs 'have quite a bit of drift and some broken
links' and contradictions like 'says don't use bun but also to use bun.' This
PR is a top-to-bottom audit + fix across every doc file at the repo root and
under docs/. Where docs disagreed with each other, the code was the tie-breaker.

## Categories of fix

### 1. Stale CLI commands (skillpack install → scaffold)

`gbrain skillpack install` was retired in v0.36.0.0 (replaced by the
scaffold/reference/migrate-fence model). The CLI now errors out with a hint:

    $ gbrain skillpack install
    Error: 'gbrain skillpack install' was removed in v0.33.
    Use 'gbrain skillpack scaffold <name>' instead.

But the docs still recommended it:

- README.md line 29 — primary install path
- docs/INSTALL.md lines 12 — primary install path

Both updated to `gbrain skillpack scaffold --all` with the v0.36.0.0 retirement
explained inline + the migrate-fence escape hatch for users upgrading from older
releases.

### 2. The 'bun install -g vs bun link' contradiction

The community member's exact complaint. The drift:

- README.md + docs/INSTALL.md: recommended `bun install -g github:garrytan/gbrain`
- INSTALL_FOR_AGENTS.md line 29: 'Do NOT use `bun install -g github:garrytan/gbrain`.'

Reading the code + CHANGELOG: `bun install -g` IS the canonical path. Bun
occasionally blocks the top-level postinstall hook on global installs (issue #218),
but the postinstall now prints a loud recovery hint when that happens, and
`gbrain doctor` flags `schema_version: 0` and routes users to
`gbrain apply-migrations --yes`. The 'do not use' warning was correct in 2024
when the postinstall silently swallowed errors with `|| true`; it's stale now.

Reconciled:

- INSTALL_FOR_AGENTS.md Step 1: now recommends `bun install -g` as the primary
  path, documents #218 as a known issue with the recovery command, and keeps
  `git clone + bun link` as a documented fallback.
- AGENTS.md Install (5 min): same reconciliation; clone path is the fallback,
  not the default.
- docs/INSTALL.md CLI standalone: added the #218 callout so the deterministic
  fallback is one click away when the default fails.

### 3. Broken internal links

- README.md → `docs/integrations/voice.md` (file doesn't exist). The real voice
  recipe lives at `recipes/twilio-voice-brain.md` (Twilio + OpenAI Realtime).
  Fixed to point there with an accurate one-line summary.
- CONTRIBUTING.md → `docs/SQLITE_ENGINE.md` (file doesn't exist; superseded by
  PGLite per docs/ENGINES.md). Replaced with a paragraph explaining the
  supersession and pointing at the live ENGINES.md.
- docs/GBRAIN_V0.md → `docs/SQLITE_ENGINE.md` (2 references; same supersession).
  Added a historical-doc banner at the top + rewrote both references to point at
  the current ENGINES.md.

### 4. Stale API key recommendations

INSTALL_FOR_AGENTS.md Step 2 only mentioned OpenAI + Anthropic. As of v0.36.2.0
ZeroEntropy is the default embedding + reranker stack (README opens with this);
the agent install guide didn't reflect it. Added `ZEROENTROPY_API_KEY` as the
default, kept OpenAI/Voyage as documented fallbacks, noted that keys can live in
`~/.gbrain/config.json` (file plane) or env.

### 5. Stale upgrade workflow

INSTALL_FOR_AGENTS.md 'Upgrade' section assumed the clone+bun-install model
(`cd ~/gbrain && git pull && bun install && gbrain init && gbrain post-upgrade`)
and didn't mention `gbrain upgrade` (the single-command path that exists in the
CLI today: binary self-update + schema migrations + post-upgrade prompts in one).
Split into two paths — `gbrain upgrade` for the bun-install-g case (now the
default per Step 1), clone-path for the fallback case.

Also fixed AGENTS.md 'Migrate' bullet (was `gbrain apply-migrations` only;
now leads with `gbrain upgrade` and keeps apply-migrations as the manual
schema-only path).

### 6. Stale cron-workflow

INSTALL_FOR_AGENTS.md Step 7 referenced cron docs but didn't mention
`gbrain autopilot --install` (the built-in self-maintaining daemon that
exists in the CLI today) or `gbrain sync --watch` (continuous loop). Added
both as alternatives to platform-cron glue.

### 7. ZeroEntropy version typo

docs/INSTALL.md said 'the v0.36.0.0 ZE switch' — ZE landed in v0.36.2.0
(v0.36.0.0 was the skillpack-scaffold retirement). Fixed.

## What I did NOT change

- CHANGELOG.md, CLAUDE.md, TODOS.md prose mentions of historical commands like
  `gbrain skillpack install` are correct as history — they're documenting what
  was true in past releases. Only forward-looking docs got updated.
- The 'broken link' false-positive matches in CHANGELOG / CLAUDE / TODOS are
  inside code-fence examples or regex patterns (`[Name](people/slug)`,
  `[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])`, `[--json](interrupted)`); they're
  illustrative syntax, not real links. Leaving alone.
- llms.txt / llms-full.txt regenerated via `bun run build:llms` so the
  agent-fetch documentation map matches the new content.

## Verification

- `bun run src/cli.ts --help` cross-checked against every command/flag the
  install docs reference: init, doctor, apply-migrations, upgrade, post-upgrade,
  skillpack scaffold/reference/migrate-fence, embed --stale, sync --watch,
  autopilot --install, dream, integrations list, extract links/timeline,
  graph-query, query, search modes — all real, all current.
- `bun run src/cli.ts skillpack install` confirmed to error out with the
  retirement hint pointing at scaffold (proves the README guidance was actively
  misleading users into a dead-end).
- Re-ran the broken-internal-link scanner across all root .md + docs/**/*.md;
  zero real broken links remain (5 residual matches are illustrative syntax
  inside prose, not actionable links).

Co-authored-by: garrytan-agents <agents@garrytan-agents.local>
2026-05-19 05:32:24 -07:00

11 KiB
Raw Blame History

GBrain Installation Guide for AI Agents

Read this entire file, then follow the steps. Ask the user for API keys when needed. Target: ~30 minutes to a fully working brain.

Step 0: If you are not Claude Code

Read AGENTS.md at the repo root first. It's the non-Claude-agent operating protocol (install, read order, trust boundary, common tasks). Claude Code reads CLAUDE.md automatically and can skip ahead.

If you fetched this file by URL without cloning yet, the companion files live at:

  • https://raw.githubusercontent.com/garrytan/gbrain/master/AGENTS.md — start here
  • https://raw.githubusercontent.com/garrytan/gbrain/master/llms.txt — full doc map
  • https://raw.githubusercontent.com/garrytan/gbrain/master/llms-full.txt — same map, inlined

Step 1: Install GBrain

Default path (Bun is required — gbrain is a Bun + TypeScript runtime):

curl -fsSL https://bun.sh/install | bash
export PATH="$HOME/.bun/bin:$PATH"
bun install -g github:garrytan/gbrain

Verify: gbrain --version should print a version number. If gbrain is not found, restart the shell or add the PATH export to the shell profile.

If bun install -g aborts or gbrain doctor reports schema_version: 0 (Bun occasionally blocks the top-level postinstall hook on global installs, so schema migrations don't run automatically), the CLI prints a recovery hint pointing at #218. Run gbrain apply-migrations --yes to recover. If that doesn't work, fall back to the deterministic install path:

git clone https://github.com/garrytan/gbrain.git ~/gbrain && cd ~/gbrain
bun install && bun link

Step 2: API Keys

Ask the user for these. gbrain defaults to the ZeroEntropy embedding + reranker stack (as of v0.36.2.0); OpenAI/Voyage are still supported as fallbacks via gbrain config set embedding_model <provider:model>.

export ZEROENTROPY_API_KEY=ze-...     # default embedding + reranker (v0.36.2.0+)
export OPENAI_API_KEY=sk-...          # fallback for vector search; also used for chat models
export ANTHROPIC_API_KEY=sk-ant-...   # optional, improves search quality via query expansion

Save to shell profile or .env. Keys are picked up by gbrain config set automatically or can be stored in ~/.gbrain/config.json (file plane). Without any embedding provider, keyword search still works. Without Anthropic, search works but skips query expansion.

Step 3: Create the Brain

gbrain init                           # PGLite, no server needed
gbrain doctor --json                  # verify all checks pass

The user's markdown files (notes, docs, brain repo) are SEPARATE from this tool repo. Ask the user where their files are, or create a new brain repo:

mkdir -p ~/brain && cd ~/brain && git init

Read ~/gbrain/docs/GBRAIN_RECOMMENDED_SCHEMA.md and set up the MECE directory structure (people/, companies/, concepts/, etc.) inside the user's brain repo, NOT inside ~/gbrain.

Step 3.5: Confirm search mode with the user (DO NOT SKIP)

gbrain init auto-applied a default search mode (tokenmax unless your subagent tier is Haiku-class or no OpenAI key is configured). The init output included the cost matrix below preceded by [AGENT] markers. You must NOT silently accept the default. Stop and ask the operator.

Present this matrix verbatim:

Per-query cost @ 10K queries/mo (typical single-user volume):

                  Haiku 4.5     Sonnet 4.6    Opus 4.7
                  ($1/M)        ($3/M)        ($5/M)
  conservative    $40/mo        $120/mo       $200/mo
  balanced        $100/mo       $300/mo       $500/mo
  tokenmax        $200/mo       $600/mo       $1,000/mo

(scales linearly: ×10 for 100K/mo, ÷10 for 1K. 25x corner-to-corner spread.
 Natural diagonal pairings — cheap/cheap → frontier/frontier — span ~4x.)

Ask the operator (paraphrase if needed):

Your gbrain just installed with search mode <auto-applied default>. This is a one-time setup decision that controls retrieval payload size. Which mode do you want?

  1. conservative — tight 4K budget, no LLM expansion, 10 chunks max. Best for Haiku subagents, cost-sensitive setups, high-volume loops.

  2. balanced — 12K budget, no expansion, 25 chunks. Sonnet-tier sweet spot.

  3. tokenmax (recommended default — preserves v0.31.x retrieval shape) — no budget, LLM expansion ON, 50 chunks. Best for Opus/frontier models.

Cost depends on BOTH the mode AND the downstream model you run. See the matrix above for the 9-cell breakdown.

If the operator picks a non-default mode, run:

gbrain config set search.mode <mode>

If they pick tokenmax AND want to preserve the literal v0.31.x default (limit=20 instead of tokenmax's 50), also run:

gbrain config set search.searchLimit 20

Verify the choice with gbrain search modes before continuing.

Why this matters: the cost spread between corners of the matrix is 25x. An agent that silently accepts the default and starts running queries against a user who didn't expect tokenmax-class context loads can rack up surprise spend. Confirm before continuing.

Step 4: Import and Index

gbrain import ~/brain/ --no-embed     # import markdown files
gbrain embed --stale                  # generate vector embeddings
gbrain query "key themes across these documents?"

Step 4.5: Wire the Knowledge Graph

If the user already had a brain repo (Step 3 imported existing markdown), backfill the typed-link graph and structured timeline. This populates the links and timeline_entries tables that future writes will maintain automatically.

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

For brand-new empty brains, skip this step — auto-link populates the graph as the agent writes pages going forward. There is nothing to backfill yet.

After this step:

  • gbrain graph-query <slug> --depth 2 works (relationship traversal)
  • Search ranks well-connected entities higher (backlink boost)
  • Every future put_page auto-creates typed links and reconciles stale ones

If a user has a very large brain (>10K pages), extract --source db is idempotent and supports --since YYYY-MM-DD for incremental runs.

Step 5: Load Skills

If you're running an agent platform (OpenClaw, Hermes, or any repo with a workspace), scaffold the bundled skills into it:

cd /path/to/agent/workspace
gbrain skillpack scaffold --all       # copy 43 curated skills + RESOLVER.md

Scaffolded skills are first-class files in your repo. Edit freely; re-running scaffold refuses to overwrite anything that exists. Use gbrain skillpack reference <name> to diff against gbrain's bundle when you want upstream improvements. (The legacy gbrain skillpack install managed-block model was retired in v0.36.0.0 — run gbrain skillpack migrate-fence once if upgrading from an older release.)

Whether you scaffolded or not, read skills/RESOLVER.md (in your workspace, or the bundled copy at ~/gbrain/skills/RESOLVER.md when running from the cloned repo). It's the skill dispatcher — tells you which skill to read for any task. Save this to your memory permanently.

The three most important skills to adopt immediately:

  1. Signal detector (skills/signal-detector/SKILL.md) — fire this on EVERY inbound message. It captures ideas and entities in parallel. The brain compounds.

  2. Brain-ops (skills/brain-ops/SKILL.md) — brain-first lookup on every response. Check the brain before any external API call.

  3. Conventions (skills/conventions/quality.md) — citation format, back-linking iron law, source attribution. These are non-negotiable quality rules.

Step 6: Identity (optional)

Run the soul-audit skill to customize the agent's identity:

Read skills/soul-audit/SKILL.md and follow it.

This generates SOUL.md (agent identity), USER.md (user profile), ACCESS_POLICY.md (who sees what), and HEARTBEAT.md (operational cadence) from the user's answers.

If skipped, minimal defaults are installed automatically.

Step 7: Recurring Jobs

Set up using your platform's scheduler (OpenClaw cron, Railway cron, crontab), or skip the platform glue entirely with gbrain autopilot --install (built-in self-maintaining daemon):

  • Live sync (every 15 min): gbrain sync --repo ~/brain && gbrain embed --stale — or gbrain sync --watch for a continuous loop.
  • Auto-update (daily): gbrain check-update --json (tell user, never auto-install).
  • Dream cycle (nightly): gbrain dream runs the 8-phase overnight maintenance cycle. Entity sweep, citation fixes, memory consolidation, plus (v0.23+) overnight conversation synthesis and cross-session pattern detection. One cron-friendly command. This is what makes the brain compound. Do not skip it. See docs/guides/cron-schedule.md for the full protocol.
  • Weekly: gbrain doctor --json && gbrain embed --stale

Step 8: Integrations

Run gbrain integrations list. Each recipe in ~/gbrain/recipes/ is a self-contained installer. It tells you what credentials to ask for, how to validate, and what cron to register. Ask the user which integrations they want (email, calendar, voice, Twitter).

Verify: gbrain integrations doctor (after at least one is configured)

Step 9: Verify

Read docs/GBRAIN_VERIFY.md and run all 7 verification checks. Check #4 (live sync actually works) is the most important.

Upgrade

If you installed via bun install -g:

gbrain upgrade                        # self-updates the binary, runs schema migrations,
                                      # and prints post-upgrade notes for the version range

If you installed via git clone + bun link:

cd ~/gbrain && git pull origin master && bun install
gbrain apply-migrations --yes         # apply schema migrations (idempotent)
gbrain post-upgrade                   # show migration notes for the version range

Then read ~/gbrain/skills/migrations/v<NEW_VERSION>.md (and any intermediate versions you skipped) and run any backfill or verification steps it lists. Skipping this is how features ship in the binary but stay dormant in the user's brain.

v0.32.3 search modes (one-time upgrade prompt): if the user's brain was created before v0.32.3, gbrain post-upgrade prints a banner including the 9-cell cost matrix (mode × downstream model) preceded by [AGENT] markers. Do NOT silently move past the banner. Present the matrix to the operator verbatim, ask which mode they want (recommended default: tokenmax to preserve v0.31.x retrieval shape), then run gbrain config set search.mode <mode>. See Step 3.5 above for the full ask-the-user protocol — the upgrade path uses the same matrix and same default.

For v0.12.0+ specifically: if your brain was created before v0.12.0, run gbrain extract links --source db && gbrain extract timeline --source db to backfill the new graph layer (see Step 4.5 above).

For v0.12.2+ specifically: if your brain is Postgres- or Supabase-backed and predates v0.12.2, the v0_12_2 migration runs gbrain repair-jsonb automatically during gbrain post-upgrade to fix the double-encoded JSONB columns. PGLite brains no-op. If wiki-style imports were truncated by the old splitBody bug, run gbrain sync --full after upgrading to rebuild compiled_truth from source markdown.