* fix(wave): 4 hot issues + 3 scope expansions (v0.13.1) Addresses four user-filed regressions after v0.13.0 plus three adjacent footgun closures. * #170 — CREATE INDEX [CONCURRENTLY] IF NOT EXISTS idx_pages_updated_at_desc on pages (updated_at DESC). Engine-aware migration v12 with invalid-index cleanup on Postgres, plain CREATE on PGLite. ~700x on 30k+ row brains. Contributed by @fuleinist (#215). * #219 — Minions schema default max_stalled 1 -> 5. v13 migration ALTERs the default and UPDATEs existing non-terminal rows (waiting/active/ delayed/waiting-children/paused) so live queues get rescued on upgrade. Adds MinionJobInput.max_stalled with [1,100] clamp. New --max-stalled CLI flag on `jobs submit`. Reported by @macbotmini-eng. * #218 — package.json postinstall surfaces errors instead of silencing. trustedDependencies whitelists @electric-sql/pglite. doctor schema_version check fails loudly when migrations never ran and links to #218. README + INSTALL_FOR_AGENTS warn against `bun install -g`. Reported by @gopalpatel. * #223 — @electric-sql/pglite pinned to exactly 0.4.3 (was ^0.4.4). PGLiteEngine.connect() wraps PGlite.create() errors with a message pointing at the issue + gbrain doctor. Does NOT suggest 'missing migrations' as a cause (create-time abort happens before migrations run). Pin is unverified against macOS 26.3; error-wrap is the safety net. Reported by @AndreLYL. * Scope: `gbrain jobs submit` gains --backoff-type/--backoff-delay/ --backoff-jitter/--timeout-ms/--idempotency-key (MinionJobInput audit). * Scope: `gbrain jobs smoke --sigkill-rescue` regression case (opt-in, CI-only) that simulates a killed worker and asserts the new default rescues. * Scope: `gbrain doctor --index-audit` reports zero-scan Postgres indexes as drop candidates (informational; no auto-drop). Infrastructure: * Migration interface extended with sqlFor: { postgres?, pglite? } and transaction: boolean. Runner picks the engine-specific branch and bypasses engine.transaction() when transaction:false (required for CONCURRENTLY). BrainEngine.kind readonly discriminator added. * scripts/check-jsonb-pattern.sh CI guard extended to block `max_stalled DEFAULT 1` from regressing. Tests: * 15 new unit tests: v12/v13 structural + behavioral assertions, max_stalled default/clamp/backfill, PGLite error-wrap source guard, engine kind discriminator. * 3 regression tests pinned by IRON RULE. * Full unit suite: 1416 pass. * Full E2E suite against Postgres 16 + pgvector: 126 pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: bump version and changelog (v0.13.1) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * docs: sync documentation for v0.13.1 CLAUDE.md "Key files" and "Commands" sections refreshed to match the v0.13.1 fix wave: - Note `BrainEngine.kind` discriminator on engine.ts - Document v0.13.1 connect() error-wrap on pglite-engine.ts - Refresh src/core/minions/ layout (no shell handler, no protected-names, no quiet-hours/stagger — that was v0.13-development scaffolding that did not ship) - Add src/core/migrate.ts entry with `Migration` interface extensions (`sqlFor`, `transaction: false`) - Document new `gbrain jobs submit` flags (--max-stalled, --backoff-type, --backoff-delay, --backoff-jitter, --timeout-ms, --idempotency-key) - Document `gbrain jobs smoke --sigkill-rescue` regression guard - Document `gbrain doctor --index-audit` and the schema_version=0 surface that catches #218 postinstall failures - Extend check-jsonb-pattern.sh note with the max_stalled DEFAULT 1 regression guard - Touch up test file blurbs for migrate.test.ts, pglite-engine.test.ts, minions.test.ts with v0.13.1 coverage Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * test(e2e): run files sequentially to eliminate shared-DB race The E2E suite was flaky. ~3 of every 5 runs had 4-10 failures clustered in Links, Timeline, Versions, Minions resilience, Parallel Import, and Page CRUD tests. Symptoms included "expected 16 pages, got 8" (half), "expected 1 link inserted, got 0", timeline entries missing after round-trip, and similar data-shape mismatches. Root cause: bun test runs test FILES in parallel (each in a worker process). 13 E2E files share one DATABASE_URL, and `setupDB()` in `test/e2e/helpers.ts` does `TRUNCATE ... CASCADE` on all tables before each file's `importFixtures()`. File A's TRUNCATE would race with file B's in-flight INSERT stream, producing the observed half-populated or wrong-count states. An earlier attempt used a Postgres advisory lock held on a dedicated single-connection client for the lifetime of each file's run. It broke because bun's default 5000 ms hook timeout fires on queued beforeAll() calls: with 13 files serializing through the lock, files 2-13 would time out waiting for file 1 to finish. This commit switches to sequential file execution at the harness level via scripts/run-e2e.sh, which loops through test/e2e/*.test.ts one at a time, tracks aggregate pass/fail counts, and exits non-zero on the first failing file. No lock, no timeout issues, no changes to any test file. package.json test:e2e points at the new script. Verified: 5 back-to-back runs against the same Postgres container, each completing in ~5 min. Every run: 13 files, 138 tests, 0 fails. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: bump version to 0.15.1 (fix wave locked to MINOR line) Master v0.14.2 was the last /investigate root-cause wave on the v0.14.x line. This fix wave opens v0.15.x: four hot issues (#170, #218, #219, #223) close v0.13.x regressions that v0.14.x didn't cover, so the MINOR bump reflects the semantic shift — new schema migrations (v14, v15), a new CLI surface (`--max-stalled`, `--sigkill-rescue`, `--index-audit`), a new BrainEngine contract (`kind` discriminator + extended `Migration` interface), and a new install-time contract (PGLite 0.4.3 pin + `trustedDependencies`). Locked to 0.15.1 in advance: other work may land before/after this PR, but the version is fixed so reviewers can cite a stable number. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
171 lines
6.7 KiB
Markdown
171 lines
6.7 KiB
Markdown
# 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
|
|
|
|
```bash
|
|
git clone https://github.com/garrytan/gbrain.git ~/gbrain && cd ~/gbrain
|
|
curl -fsSL https://bun.sh/install | bash
|
|
export PATH="$HOME/.bun/bin:$PATH"
|
|
bun install && bun link
|
|
```
|
|
|
|
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.
|
|
|
|
> **Do NOT use `bun install -g github:garrytan/gbrain`.** Bun blocks the top-level
|
|
> postinstall hook on global installs, so schema migrations never run and the CLI
|
|
> aborts with `Aborted()` when it opens PGLite. Use the `git clone + bun link` path
|
|
> above. Tracking issue: [#218](https://github.com/garrytan/gbrain/issues/218).
|
|
|
|
## Step 2: API Keys
|
|
|
|
Ask the user for these:
|
|
|
|
```bash
|
|
export OPENAI_API_KEY=sk-... # required for vector search
|
|
export ANTHROPIC_API_KEY=sk-ant-... # optional, improves search quality
|
|
```
|
|
|
|
Save to shell profile or `.env`. Without OpenAI, keyword search still works.
|
|
Without Anthropic, search works but skips query expansion.
|
|
|
|
## Step 3: Create the Brain
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
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 4: Import and Index
|
|
|
|
```bash
|
|
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.
|
|
|
|
```bash
|
|
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
|
|
|
|
Read `~/gbrain/skills/RESOLVER.md`. This is the skill dispatcher. It 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):
|
|
|
|
- **Live sync** (every 15 min): `gbrain sync --repo ~/brain && gbrain embed --stale`
|
|
- **Auto-update** (daily): `gbrain check-update --json` (tell user, never auto-install)
|
|
- **Dream cycle** (nightly): read `docs/guides/cron-schedule.md` for the full protocol.
|
|
Entity sweep, citation fixes, memory consolidation. This is what makes the brain
|
|
compound. Do not skip it.
|
|
- **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
|
|
|
|
```bash
|
|
cd ~/gbrain && git pull origin master && bun install
|
|
gbrain init # 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.
|
|
|
|
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.
|