Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge remote-tracking branch 'origin/master' into capy/d8-setup-claude-code

garrytan696d9e021ace
diff --cc .claude-plugin/plugin.json
index b98700cf76,cd068bb72b..29a6cf70c7
--- a/.claude-plugin/plugin.json
+++ b/.claude-plugin/plugin.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "gbrain",
- "version": "0.60.152.0",
- "version": "0.60.155.0",
++ "version": "0.60.156.0",
"description": "Personal knowledge brain for your coding agent — hybrid search, synthesis, graph traversal, and durable cross-session memory over Postgres/PGLite with pgvector, plus a curated brain-first skill set.",
"author": {
"name": "Garry Tan",
diff --cc .codex-plugin/plugin.json
index c908e5cfb3,3c4974202e..2d95980924
--- a/.codex-plugin/plugin.json
+++ b/.codex-plugin/plugin.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "gbrain",
- "version": "0.60.152.0",
- "version": "0.60.155.0",
++ "version": "0.60.156.0",
"description": "Personal knowledge brain for your coding agent — hybrid search, synthesis, graph traversal, and durable cross-session memory over Postgres/PGLite with pgvector, plus a curated brain-first skill set.",
"author": {
"name": "Garry Tan",
diff --cc BOOTSTRAP_FOR_AGENTS.md
index a56187b931,125a65d9c5..769b3509c5
--- a/BOOTSTRAP_FOR_AGENTS.md
+++ b/BOOTSTRAP_FOR_AGENTS.md
@@@ -1,4 -1,4 +1,4 @@@
- <!-- gbrain-runbook-stamp: 0.60.152.0 -->
-<!-- gbrain-runbook-stamp: 0.60.155.0 -->
++<!-- gbrain-runbook-stamp: 0.60.156.0 -->
<!-- This stamp must equal the VERSION file at every release; CI enforces it
(scripts/check-bootstrap-tag.sh). `gbrain bootstrap status` compares it to
the installed binary and warns on skew. -->
diff --cc CHANGELOG.md
index 857fec8296,d4236ca120..c847cbced5
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -10,25 -10,81 +10,100 @@@ credits are retained; no result has bee
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
- ## [0.60.152.0] - 2026-10-10
++## [0.60.156.0] - 2026-10-10
+
+**`gbrain setup claude-code` gives Claude Code memory in one command.** It finds or creates your brain, wires the MCP server and the read-context hooks, and checks that they answer. A second run changes nothing, and `--remove` takes out only what setup wrote.
+
+### What you get
+
+- **One command after install.** `bun install -g github:garrytan/gbrain`, then `gbrain setup claude-code`. With no brain configured it creates a keyless local one (`gbrain init --pglite --no-embedding`). It then writes the stdio MCP entry to `~/.claude.json` and the `SessionStart` and `UserPromptSubmit` hooks to `~/.claude/settings.json`, and runs the same stdio smoke as `gbrain doctor --only harness_wiring`.
+- **Target first.** Before any write, setup prints the brain, source, launcher, MCP surface and registration owner it chose. `--dry-run` stops there; `--json` prints one document.
+- **Three separate decisions.** Wiring scope (`--scope user|project`, `--no-hooks`), automatic capture (`--capture` adds the `Stop` and `SessionEnd` hooks) and provider use (`--providers`). Capture and providers are off unless you accept them. An existing `memory.auto_writeback: off` or `GBRAIN_HOOKS=0` wins over a flag.
+- **Owned by hash.** A connection receipt beside `~/.claude.json` records the exact hash of each entry setup wrote. An entry you edited afterwards is kept and reported, never overwritten or removed. An interrupted run resumes without duplicating anything. Two installs on one machine each remove only their own entries.
+- **Refuses instead of guessing.** A hosted brain is never shadowed by a new local one (`setup_hosted_connection`). A live PGLite server, an MCP entry setup did not write, another install's receipt or an existing `bootstrap harness` wiring refuses with `setup_owner_conflict` and the exact next step. `codex`, `openclaw` and `hermes` print their per-harness guide (`setup_harness_unsupported`). `gbrain errors <code>` explains each.
+- **Honest states.** Setup reports `configured`, `connection-verified` and `native-pending` separately; it never claims that memory reaches a fresh session on its own until that is observed.
+
+### For contributors
+
+- `writeClaudeHooksAt` and `removeClaudeHooksAt` accept an opt-in `ownedEntryHashes` set (`hookEntryHash`: sha256 over type, command and timeout). With it, a marker match alone never replaces or removes an entry, and edited entries come back in `preserved`. Existing callers are unchanged.
+- `src/core/setup/capabilities.ts` is the versioned harness × transport capability table that setup reads.
+- Guide: `docs/guides/setup.md`. Refusals: `docs/guides/repair.md#setup-refusals`.
+
+ ## [0.60.155.0] - 2026-10-10
+
+ **The Postgres E2E test for filtered HNSW recall under iterative scan no longer fails at random. It averages four index builds instead of trusting one.** Product code is unchanged.
+
+ `test/e2e/hnsw-iterative-scan-recall-postgres.test.ts` builds a deliberately sparse HNSW index (m 4, ef_construction 8, 20k vectors) and asserts that default recall stays at or above 0.6. pgvector draws each element's graph level from the server's own unseeded random generator, so every build is a different graph. One build failed on CI with 0.5825.
+
+ | measure (local pg16, pgvector 0.8.7) | one build | mean of four builds |
+ |---|---|---|
+ | default recall: mean / sd / min (200 builds) | 0.714 / 0.037 / 0.629 | 0.714 / 0.018 / 0.674 (50 groups) |
+ | forced probe: runs failing at a 0.67 bar, 30 fresh runs each | 3 / 30 | 0 / 30 |
+
+ Both bounds are unchanged (default ≥ 0.6, default − strict ≥ 0.1). The test takes about 5 s instead of 3 s.
+
+ ## [0.60.154.0] - 2026-10-10
+
+ **`gbrain serve` answers while a large effects backlog drains.** A big import followed by `gbrain embed --stale` left tens of thousands of queued page embedding effects whose chunks already had current vectors. The serve consumer ran each one through a claim, a guard, a projection read and a completion, and PGLite resolves its queries as one microtask chain, so stdin waited for the whole drain: on a 47k-page brain the first tool call took 432 to 489 s. It now answers in about 2 s, and the same backlog settles in about 18 s.
+
+ Nothing needs doing after you upgrade. A drain longer than 5 s prints one progress line on serve's stderr.
+
+ ### Itemized changes
+
+ - **No-op embedding effects settle in bulk** (`src/core/persistence/embedding-noop-settle.ts`). The serve drain first settles queued page embedding effects that have nothing left to embed, one statement per window of 200. An effect settles there only if the effect runner would find nothing to embed: never attempted, claimable by this host, its source unchanged, its page live and sealed at the effect's revision, and every chunk carrying a vector for the current signature, write column and model. The row ends exactly as the runner's own completion leaves it. Everything else, including any effect the settle passes over, still runs through the runner.
+ - **A per-process cursor** keeps a backlog that cannot settle (stale vectors, an unconfigured provider) from being rescanned on every drain: on a 40k stale backlog the first sweep takes about 2 s and every later drain costs one indexed read.
+ - **The drain yields to the event loop** between settle windows and between effect batches, never inside a Git group or while a worktree lock is held.
+ - **The PGLite checkpoint guard reuses a WAL probe for up to 50 ms** while the reading leaves a full window of headroom at a bound well above the measured peak WAL rate, so a run of small writes no longer probes once per statement.
+ - **Progress line.** `[persistence] phase=effects_drain state=running|done settled_noop_embeddings=… ran=… elapsed_s=…` on serve's stderr (never on CLI output), and `status()` reports the drain in progress.
+
+ ### For contributors
+
+ - `test/persistence-drain-latency.serial.test.ts` is the forced probe: a tool call every 50 ms while 8,000 no-op effects drain must answer, and the event loop must not stall, within 2,000 ms (master: no call answers during the drain, worst gap 30.9 s).
+ - `test/persistence-embedding-noop-settle.test.ts` (PGLite and Postgres) covers a mixed queue, Git rows untouched, row and request parity with the runner, a crash inside the settle (fault point `effect:embedding:settle`), guard refusals, the cursor, numeric id order and the runner fallback for passed effects.
+ - `test/pglite-checkpoint-guard.test.ts` covers the probe reuse window, including WAL crossing the threshold inside it; `test/persistence-git-coalescing-5530.slow.test.ts` adds a write behind a Git backlog and a no-op embedding backlog.
+
+ ## [0.60.153.0] - 2026-10-10
+
+ **A repeated query in a long-running `gbrain serve` no longer waits on the embedding provider: about 110–150 ms faster per repeat, and 75 of 100 provider embed calls avoided on a realistic mix. Cold `search`, `query` and `stats` start 100–175 ms faster on both engines. Doctor's `eval_drift` stops paying 0.2–0.4 s per run on a freshly cloned or just-pulled source checkout. Rankings and output are unchanged.**
+
+ Efficiency wave 11 (GBRA-75). Base is master at wave 10 (c8d513eeb). Measured on 4-vCPU / 16 GiB cloud machines with synthetic brains, base and branch interleaved in one session, p50 / p95.
+
+ | Path | Engine, brain, N | Before | After |
+ |---|---|---|---|
+ | MCP `query`, repeat of an earlier query (live Voyage embed + rerank) | Postgres 5k, N=25 | 483 / 530 ms | 370 / 427 ms |
+ | same | Postgres 50k, N=25 | 504 / 557 ms | 359 / 441 ms |
+ | same | PGLite 5k, N=25 | 462 / 531 ms | 312 / 399 ms |
+ | provider embed calls, 100-query Zipf mix of 40 queries | all three brains | 100 | 25 |
+ | cold `gbrain search` | PGLite 5k / 50k, N=20 | 704 / 754, 739 / 769 ms | 604 / 642, 622 / 655 ms |
+ | same | Postgres 5k / 50k, N=20 | 477 / 550, 515 / 579 ms | 355 / 429, 392 / 442 ms |
+ | cold `gbrain stats` | PGLite 50k / Postgres 50k, N=20 | 987 / 1061, 584 / 633 ms | 855 / 902, 437 / 499 ms |
+ | modules loaded before connect, `search` | PGLite 5k | 1021 | 667 |
+ | `eval_drift` probe, racy index (fresh 10.5k-file clone) | 3 clones × 6 runs | 224–457 ms every run | one 400–1045 ms run, then 18–35 ms |
+ | same, settled index | 6 runs | 22–32 ms | 17–28 ms |
+
+ PGLite cold start stays about 170–200 ms above Postgres: `PGlite.create` boots the WASM backend and its vector and pg_trgm extensions on the main thread, and the catalog needs those extensions at boot.
+
+ ### Itemized changes
+
+ - **Query-embedding cache** (`ai/query-embed-cache.ts`, `gateway.ts` `embedQuery`). Identical query embeds within one process reuse the vector: a 512-entry LRU with a 10-minute TTL, keyed by recipe, resolved model id, `base_urls` override, effective dimensions and the exact string sent (query prefix + text). Only resolved vectors are stored, as copies; aborts and failures are never cached. Every gateway reconfigure clears it, and a caller under an AI invocation guard (minion spend authorization, delegated spend) always goes through its guard. Document-side embeds are uncached. A deterministic-provider fixture shows byte-identical ranked lists with and without the cache on both engines. Expansion variants never repeat within one call (deduped already); across calls the expansion LLM output is not cached, so a variant embed is reused only when the LLM returns the same string.
+ - **Cold start** (`operation-load.ts`, `operation-loaders.generated.ts`, `remote-mcp-error.ts`, `embedding-disabled.ts`, `ai/gateway.ts`, `ops/admin.ts`). The CLI loads only the module that defines the op it runs, finalized by the same area-and-redaction step the registry uses; the MCP client, evidence delivery, the `ai` SDK and `page-mutations` load on first use. Trust proposal decisions load their handlers at the reader, and a test classifies every load-time registry and diffs it per op against the full registry.
+ - **`eval_drift`** (`eval/drift-watch.ts`). A working-tree diff that takes 75 ms or more means racily-clean index entries, which git re-hashes on every diff until the index is rewritten; the probe then runs `git update-index -q --refresh` once. A settled checkout skips it. The answer is unchanged, and a held `index.lock` is ignored.
+
+ ## [0.60.152.0] - 2026-10-10
+
+ **Remote fact writes apply the same visibility filter as reads.**
+
+ `forget` and `remember` called by a remote agent now apply the same visibility filter as remote fact reads. The trusted local CLI is unchanged, and nothing needs doing after you upgrade.
+
+ ### Itemized changes
+
+ - Remote `forget` applies the same visibility filter as reads, through its trust guard, the withdrawal it records and the similar facts it lists.
+ - Remote `remember` applies the same visibility filter in its duplicate checks and in `replaces`.
+
+ ### For contributors
+
+ - `test/remote-fact-write-private-provenance.test.ts` covers the fix on PGLite, and on Postgres through `test/e2e/remote-fact-write-private-provenance-postgres.test.ts`.
+
## [0.60.151.0] - 2026-10-10
**A visibility filter fix for remote fact reads.**
diff --cc VERSION
index 3912113ff4,972b022299..2551fe6862
--- a/VERSION
+++ b/VERSION
@@@ -1,1 -1,1 +1,1 @@@
- 0.60.152.0
-0.60.155.0
++0.60.156.0
diff --cc openclaw.plugin.json
index d80a39910e,c202ba0be9..6c1f0a3955
--- a/openclaw.plugin.json
+++ b/openclaw.plugin.json
@@@ -1,7 -1,7 +1,7 @@@
{
"id": "gbrain-context-engine",
"name": "gbrain",
- "version": "0.60.152.0",
- "version": "0.60.155.0",
++ "version": "0.60.156.0",
"description": "Personal knowledge brain with Postgres + pgvector hybrid search",
"family": "bundle-plugin",
"kind": "context-engine",
diff --cc package.json
index ca7527b33f,6ffd3f0b36..393f0c314d
--- a/package.json
+++ b/package.json
@@@ -230,7 -231,7 +231,7 @@@
"bun": ">=1.4.0"
},
"license": "MIT",
- "version": "0.60.152.0",
- "version": "0.60.155.0",
++ "version": "0.60.156.0",
"overrides": {
"@ai-sdk/provider-utils": "4.0.56",
"@hono/node-server": "^2.0.5",
diff --cc plugin-variants/gbrain-coding/.claude-plugin/plugin.json
index 046607f23c,4eb8631fa7..9932756bab
--- a/plugin-variants/gbrain-coding/.claude-plugin/plugin.json
+++ b/plugin-variants/gbrain-coding/.claude-plugin/plugin.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "gbrain-coding",
- "version": "0.60.152.0",
- "version": "0.60.155.0",
++ "version": "0.60.156.0",
"description": "Brain-first coding agent working inside a repo: retrieval, routing, ingest discipline, correction hygiene. Default persona for the claude-code harness bridge; also published as the gbrain-coding marketplace variant. (persona variant of the gbrain plugin — 21 skills)",
"author": {
"name": "Garry Tan",
diff --cc plugin-variants/gbrain-coding/.codex-plugin/plugin.json
index 9220e07b5c,5a4bd7b120..300da5c8ab
--- a/plugin-variants/gbrain-coding/.codex-plugin/plugin.json
+++ b/plugin-variants/gbrain-coding/.codex-plugin/plugin.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "gbrain-coding",
- "version": "0.60.152.0",
- "version": "0.60.155.0",
++ "version": "0.60.156.0",
"description": "Brain-first coding agent working inside a repo: retrieval, routing, ingest discipline, correction hygiene. Default persona for the claude-code harness bridge; also published as the gbrain-coding marketplace variant. (persona variant of the gbrain plugin — 21 skills)",
"author": {
"name": "Garry Tan",
diff --cc plugin-variants/gbrain-coding/README.md
index 9dc4ece04b,d1295231c5..4b7f03a19f
--- a/plugin-variants/gbrain-coding/README.md
+++ b/plugin-variants/gbrain-coding/README.md
@@@ -1,4 -1,4 +1,4 @@@
- <!-- gbrain-plugin-tree-stamp: 0.60.152.0 -->
-<!-- gbrain-plugin-tree-stamp: 0.60.155.0 -->
++<!-- gbrain-plugin-tree-stamp: 0.60.156.0 -->
# gbrain-coding (generated persona variant — do not hand-edit)
Brain-first coding agent working inside a repo: retrieval, routing, ingest discipline, correction hygiene. Default persona for the claude-code harness bridge; also published as the gbrain-coding marketplace variant.
diff --cc plugin-variants/gbrain-daily/.claude-plugin/plugin.json
index 028a69566d,3406a3eece..8f0058438b
--- a/plugin-variants/gbrain-daily/.claude-plugin/plugin.json
+++ b/plugin-variants/gbrain-daily/.claude-plugin/plugin.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "gbrain-daily",
- "version": "0.60.152.0",
- "version": "0.60.155.0",
++ "version": "0.60.156.0",
"description": "Personal knowledge-brain daily use: meetings, tasks, briefings, reading, research. Published as the gbrain-daily marketplace variant. (persona variant of the gbrain plugin — 20 skills)",
"author": {
"name": "Garry Tan",
diff --cc plugin-variants/gbrain-daily/.codex-plugin/plugin.json
index 6bd3b1ef04,d523b5994e..720afe2427
--- a/plugin-variants/gbrain-daily/.codex-plugin/plugin.json
+++ b/plugin-variants/gbrain-daily/.codex-plugin/plugin.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "gbrain-daily",
- "version": "0.60.152.0",
- "version": "0.60.155.0",
++ "version": "0.60.156.0",
"description": "Personal knowledge-brain daily use: meetings, tasks, briefings, reading, research. Published as the gbrain-daily marketplace variant. (persona variant of the gbrain plugin — 20 skills)",
"author": {
"name": "Garry Tan",
diff --cc plugin-variants/gbrain-daily/README.md
index b62230d353,e19d473977..0e000483c4
--- a/plugin-variants/gbrain-daily/README.md
+++ b/plugin-variants/gbrain-daily/README.md
@@@ -1,4 -1,4 +1,4 @@@
- <!-- gbrain-plugin-tree-stamp: 0.60.152.0 -->
-<!-- gbrain-plugin-tree-stamp: 0.60.155.0 -->
++<!-- gbrain-plugin-tree-stamp: 0.60.156.0 -->
# gbrain-daily (generated persona variant — do not hand-edit)
Personal knowledge-brain daily use: meetings, tasks, briefings, reading, research. Published as the gbrain-daily marketplace variant.
diff --cc plugin/README.md
index a25be9a24d,2bfc8ea542..f4292f7f08
--- a/plugin/README.md
+++ b/plugin/README.md
@@@ -1,4 -1,4 +1,4 @@@
- <!-- gbrain-plugin-tree-stamp: 0.60.152.0 -->
-<!-- gbrain-plugin-tree-stamp: 0.60.155.0 -->
++<!-- gbrain-plugin-tree-stamp: 0.60.156.0 -->
# gbrain plugin skill tree (generated — do not hand-edit)
This tree is the curated skill set for the gbrain Codex and Claude Code
diff --cc templates/bootstrap/template-repo/README.md
index b129f8a882,d1bbfe62da..738f6298ab
--- a/templates/bootstrap/template-repo/README.md
+++ b/templates/bootstrap/template-repo/README.md
@@@ -1,6 -1,6 +1,6 @@@
# gbrain agent workspace — template
- <!-- gbrain-template-stamp: 0.60.152.0 -->
-<!-- gbrain-template-stamp: 0.60.155.0 -->
++<!-- gbrain-template-stamp: 0.60.156.0 -->
This repository is the **"Use this template"** distribution artifact for a
[gbrain](https://github.com/garrytan/gbrain) personal-agent workspace — the same