Files
gbrain/INSTALL_FOR_AGENTS.md
T
Garry TanandClaude Fable 5 6411150071 v0.45.11.0 feat(bootstrap): OOBE hand-off (own the brain + cold-start) + DX polish waves (#4047)
* feat(bootstrap): TTY DX exploration harness + Krug onboarding fix wave

Add a real-PTY exploration harness and land 16 verified "Don't Make Me
Think" fixes on the paste-in install experience for Claude Code and Codex.

Harness:
- test/helpers/tty-harness.ts — spawns any CLI (gbrain/claude/codex) under a
  real pseudo-terminal (Bun terminal: spawn), timestamps every output burst,
  and turns silence windows into a measurable stall report. Hermetic; pure
  helpers unit-tested in test/tty-harness.test.ts.
- scripts/dx-explore.ts — drives the fresh-user funnel (help / init / real
  claude-install / real codex-install / manual drive mode), writing
  transcripts to .context/dx-runs/ (gitignored).

Fixes (all adversarially verified against the code first):
- Keyless bare `gbrain init` completes in keyless mode instead of exit 1;
  multi-key non-TTY auto-picks the canonical default; typo stays fail-loud.
- Provider picker probe-gates ollama (daemon-up != model-pulled) and offers
  an explicit "continue keyless" option that is the bare-Enter default.
- Fresh-brain init prints one schema-setup line instead of ~240 migration
  names (GBRAIN_MIGRATE_VERBOSE=1 restores detail).
- Init epilogue: memory-verbs funnel is last-on-screen; skills advisory
  compacted for init; Mod Status trimmed.
- PGLite live-serve lock error names the fix (close the agent session).
- Mode-picker banner interpolates the applied mode; expansion-key gate is
  Anthropic/OpenAI/Google, not OpenAI-only.
- Missing `claude` binary skips MCP but still installs hooks; honest copy.
- Foreign MCP-registration removal targets the conflicting scope and fails
  loud if it does not land.
- Upgrade marker compares the running binary to latest and self-spawns via
  execPath, so a current/newer binary no longer nags from a stale cache.
- interview --set/--skip after --confirm warns it voided the confirmation.
- init --help matches behavior; init --supabase fails loud on non-TTY.
- Provider capabilities attributed per provider across README / runbook /
  questions bank / bootstrap.md.
- First-run tour: restart-first, prompt 3 true on day one, withheld on FAIL;
  README gives Codex the same scripted magic moment.
- Empty-brain "0 takes" onboard nudge suppressed.
- Broken settings.local.json aborts the hooks write fail-closed instead of
  silently dropping the user's permissions.

Regenerated cli-flag-registry.generated.ts and llms-full.txt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(bootstrap): second DX polish wave — clean the success screen + honest copy (F17-F21)

Follow-up to the DX fix wave, closing the top-5 remaining gaps the scorecard
flagged (all human-facing polish, not survival):

F17 — machine markers no longer leak to humans:
- verify report drops the `[D3.6]` plan-tag from the first_run_tour detail.
- the raw `UPGRADE_AVAILABLE <cur> <latest>` marker line prints ONLY on a
  non-TTY stderr (parsers still get it); an interactive human sees just the
  "gbrain X -> Y available" sentence.
- per-migration "what changed" notices (v123/v124, incl. the #2704 ref) are
  suppressed on a FRESH-install replay via a module quiet flag; upgrades still
  narrate. (GBRAIN_MIGRATE_VERBOSE=1 restores them.)

F18 — one obvious next action on the init success screen: the memory-verbs
demo is the single "→ Do this next" hero, last on screen; import/migrate/doctor
collapse into one terse "More:" footer; the graph block only shows for a
non-empty brain.

F19 — README "moment it clicks" is now the genuine cross-session brain
round-trip (remember → restart → recall), explicitly distinguished from the
identity-file recall, on both the Codex and Claude Code paths.

F20 — the compact init skills advisory is human-voiced (no `[AGENT]`
stage-direction on the human-facing success screen; the mode-picker's
agent-directed block stays gated to the non-TTY channel).

F21 — time promise reconciled: headline is ~15 min (personal-agent path) /
~30 min (always-on OpenClaw/Hermes); the runbook's search-mode line no longer
claims "balanced" when keyless applies "conservative". README hooks copy says
"on by default, with an opt-out" to match the runbook.

Regenerated llms-full.txt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(bootstrap): address two-model adversarial review of the DX wave

Fixes the regressions the 5-specialist + red-team + Claude/Codex adversarial
pass found in the F1–F21 changes, each with a test:

- Keyless upgrade hint pointed at `config set embedding_model`, which config.ts
  hard-refuses as a schema-sizing no-op — now names the working re-init recipe
  (`gbrain init --force --pglite --embedding-model <id>`), zero-key AND multi-key
  paths.
- Multi-key TTY picker offered "continue keyless" but the caller aborted on it —
  now honors keyless like the zero-key path.
- Detached update-refresh spawn used a `/gbrain$/` basename check that misfires
  for a renamed/official-named compiled binary (`gbrain-darwin-arm64`) and
  prepends the /$bunfs entrypoint — now detects dev-vs-compiled by the runtime
  basename (bun|node) so the refresh always runs.
- `bootstrap status` reported the wire phase "done" on a hooks-only receipt
  (host CLI missing at wire time) — now "partial" with a re-run hint, so a
  resuming agent doesn't trust a false complete.
- Post-repair MCP mismatch re-verifies and aborts instead of blessing a
  registration a racing writer may have re-claimed.
- probeOpenAICompat's abort timer now spans the body read (was cleared before
  it), so a stalled `/v1/models` body can't hang init past the 1s cap.
- Centralized the 4-copy stale-cache upgrade predicate into
  `pendingUpgradeVersion`; UPGRADE_AVAILABLE gains a GBRAIN_FORCE_UPGRADE_MARKER
  override for PTY-based agent harnesses.
- Mode picker's expansion-key gate adds GEMINI_API_KEY; picker prompt is
  article-aware ("an embedding" / "a chat"); dead `!brainEmpty` clause removed;
  migrate.ts try/finally widened + stamp failures named in quiet mode.
- DX harness: credential copies scrubbed even on SIGINT/interrupt (+chmod 600),
  child process TREE reaped on teardown, advisory made fail-open, KEY_MAP typed
  as a literal union.

New tests: migrate quiet-replay, self-upgrade pending predicate + negative
cache cases, bootstrap 127/scoped-remove/broken-settings dispatch, interview
invalidation flag, verify tour-withheld-on-FAIL, init keyless/supabase/multi-key,
init-nudge branches, ai-probes model parsing. Regenerated flag registry +
template-repo.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* v0.45.8.0 fix(bootstrap): onboarding DX polish wave (F17-F21) + review fixes

DX fix wave on the paste-in install/first-run experience for Claude Code and
Codex, driven by a new real-PTY exploration harness. Keyless init completes
instead of erroring, the migration wall collapses to one line, the success
screen leads with one action, and the "magic moment" copy points at the genuine
cross-session round-trip. Full detail in CHANGELOG.

Version trio + openclaw manifest + runbook stamp bumped to 0.45.8.0; CHANGELOG
release entry; TODOS onboarding-DX follow-ups filed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(bootstrap): OOBE hand-off — you own the brain, cold-start is skill #1

A working install now ends by making the two facts that matter actually land:

- `gbrain bootstrap verify` prints (and returns as `handoff` in --json) an
  ownership block — the actual private-repo URL with what owning it means
  (read it, `gbrain bootstrap attach` on machine two, delete it and the brain
  is gone), or the local-only variant pointing at `gbrain bootstrap repo` —
  followed by the ONE next action: run the cold-start skill (Gmail/calendar/
  contacts via ClawVisor, an OAuth vault so the agent never holds raw tokens;
  or offline archives), one consented phase at a time. Withheld on FAIL like
  the tour; shape stays unconditional for machine consumers.
- cold-start ships in the downstream bundle (61 skills): its plugin exclusion
  ("host onboarding flow") predated the v0.45 personal-agent bootstrap and is
  deliberately reversed — the paste-in audience is exactly who day-one
  onboarding is for. It now LEADS the recommended set (ahead of book-mirror:
  every flagship skill only becomes magical once the brain holds the user's
  real life).
- New drift guard: every recommended slug must be scaffoldable from the
  plugin bundle — recommended-but-unscaffoldable is a dead-end CTA and now
  fails the suite.
- Runbook Hand off rewritten around the two must-land facts + the on-the-spot
  cold-start offer; README's Codex and Claude Code paths carry the same two
  follow-ups.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* v0.45.10.0 feat(bootstrap): the OOBE hand-off release

Version trio + runbook stamp + template tree to 0.45.10.0; CHANGELOG entry;
llms bundles regenerated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(ci): stop memory-verbs-conformance leaking a fake-keyed gateway into shard-mates

The deterministic-embedder helper configures the MODULE-GLOBAL gateway with a
fake OpenAI key; the file's afterAll never reset it. The bunfig preload's
per-test restore only fires when the gateway is UNCONFIGURED, so the fake-keyed
config persisted for every later file in the shard process — turn-context's
corpus writes then embedded against real OpenAI and 401'd (CI shard-8 failure;
shard re-binning from this branch's new test files exposed it).

Fix both sides: conformance's afterAll now resetGateway()s back to the preload
baseline and nulls both test transports; turn-context's beforeAll does the same
defensively so it stays hermetic regardless of shard composition.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-13 15:35:05 -07:00

17 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.

Scope note: this guide installs the BRAIN (for agent platforms like OpenClaw and Hermes, or a standalone brain). If you are Claude Code or Codex and the human asked you to become their persistent personal agent — identity + memory + private repo — follow BOOTSTRAP_FOR_AGENTS.md instead.

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

NEVER install from the npm registry. GBrain is not distributed on npm; the npm package named gbrain is an unrelated package. Do NOT run npm install -g gbrain or bun add -g gbrain (note the missing github: prefix — that's the trap). The only supported sources are github:garrytan/gbrain (optionally pinned as github:garrytan/gbrain#latest-stable, the form the bootstrap flow mandates) and a git clone, exactly as shown below. If an unrelated npm install is already present, remove it first (npm uninstall -g gbrain / bun remove -g gbrain); gbrain doctor also detects this.

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 expansion-capable API key — Anthropic, OpenAI, or Google — 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.

If the user imported an Obsidian or Notion vault that uses bare [[note-name]] wikilinks — where [[struktura]] written in one folder means the page that lives at projects/struktura.md in another — GBrain does NOT connect those by default. Out of the box it only resolves path-qualified refs like [[projects/struktura]], so a vault full of bare links shows up as a thin, broken graph. Turn on basename resolution so the cross-folder links connect:

gbrain config set link_resolution.global_basename true
gbrain extract links --source db          # re-run so the new edges land

gbrain doctor surfaces a link_resolution_opportunity hint with the exact count ("47 of 60 bare wikilinks would resolve") so you know whether it's worth enabling before you flip it. When a bare name matches more than one page ([[struktura]] → both projects/struktura and archive/struktura), GBrain emits one edge to each rather than guessing a winner — review and prune the duplicates with gbrain graph-query <slug>. The mode is also honored on the filesystem-walk path (gbrain extract links with no --source db) and by auto-link on every future put_page.

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 the 50+ bundled 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 removed in v0.33 — 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. Safe on keyless brains: a bare gbrain embed --stale exits 0 with a stderr note when embeddings are disabled, so the chain doesn't break.
  • Health gate (daily): gbrain autopilot --status — exit 0 fresh (or nothing installed), 1 needs attention (stale heartbeat, never ran, or paused), 2 the daemon took itself out of rotation. Filesystem-only, so it works during DB outages.
  • 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 every verification check in it. Check #4 (live sync actually works) is the most important.

Once verification passes and the brain has content, run the activation probe:

gbrain onboard --check --json

See "The onboard surface" below for what the recommendations mean and the consent gates around unattended remediation.

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.

The onboard surface

gbrain onboard is the activation surface gbrain did not have before. Once your brain has any content, run gbrain onboard --check --json to see structured recommendations across 5 brain-health axes (orphans, stale embeddings, entity link coverage, timeline coverage, takes count).

On first connect (after gbrain init):

gbrain onboard --check --json

The JSON envelope (schema_version: 1) carries recommendations[] with apply_policy per item: auto_apply (safe to run unattended), prompt_required (needs explicit user consent), or manual_only (LLM-bearing, user must run themselves).

After every gbrain upgrade:

gbrain onboard --check --json

New versions may surface new opportunities. The post-upgrade banner nudges the user when it runs, but agents should re-probe as a hygiene step regardless.

Unattended remediation (cron / autopilot):

gbrain onboard --auto --max-usd 5

Refuses without --max-usd N. Runs auto-eligible items only. The autopilot daemon also consults onboard recommendations on its tick — no explicit agent action needed for the autonomous path.

Remote / federated brain installs (MCP): The run_onboard MCP op (admin scope) lets thin-client agents probe brain health + drive remediation over OAuth-authenticated MCP. Protected LLM-bearing handlers (synthesize, patterns, consolidate, takes-bootstrap, contextual_reindex_per_chunk) require the additional run_protected_onboard scope — admin alone is insufficient. The MCP op returns skipped_missing_scope[] listing what would have run with the right grants.

Privacy + consent gates:

  • gbrain takes extract --from-pages sends concept/atom/lore/briefing/ writing/originals page content to your configured chat model (default Anthropic Haiku). Refuses to run unless takes.bootstrap_enabled=true is set in config AND --yes is passed. Two-gate opt-in by design.
  • Autopilot's auto-apply tier for takes-bootstrap stays manual_only until v0.42.1's eval gate (do not bypass).

Suppress nudges in CI / scripted environments:

export GBRAIN_NO_ONBOARD_NUDGE=1

Init + upgrade banners auto-skip in non-TTY too.