Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge #8989 stamped head 56c092dd (v0.60.624.0) into capy/gbra416-severe-hotfix (Q5 stack)
garrytand7dffded479e
diff --cc CHANGELOG.mdindex b56f35741e,921e55e888..88d53091e7--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -9,21 -9,64 +9,78 @@@ archival labels, not supported configurcredits are retained; no result has been reassigned to another provider. Originalidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).++## [Unreleased]++**`gbrain upgrade` no longer consults the ClawHub registry; a large Google address book, and a large source's removal, can now finish.** Advisory: an unofficial package on the ClawHub registry shares the name gbrain. `gbrain upgrade`, and autopilot's unattended self-upgrade, treated any install it could not otherwise classify (for example a release binary run under its published file name, `gbrain-linux-x64`) as a ClawHub install whenever the `clawhub` CLI was on the host, and ran `clawhub update gbrain`, which installs whatever the registry resolves for that name from any publisher. Upgrade now never runs it: a compiled binary is recognised whatever its file name, and an install it cannot classify prints the manual steps. When Google's People sync token expires, the contacts re-list now checkpoints after every page and resumes there, so a large address book no longer restarts from page one in every sync job and Calendar and Gmail sync again. A managed `gbrain sources remove` or `purge` of a large source now deletes its pages in bounded batches under the 5-second statement bound instead of one cascading statement that could never finish, and a rerun resumes. The secret scanner also catches keys right after terminal color codes, `\xNN` and `\UXXXXXXXX` escapes and quoted-printable `=3D`, and redacts a bearer token containing an escaped slash in full.++### Itemized changes++- `src/commands/upgrade.ts`: `detectInstallMethod` drops the `clawhub` method and its `clawhub --version` probe; a process whose `argv[1]` is Bun's compiled entrypoint (`/$bunfs/`, `B:\~BUN\`) is `binary`; the `clawhub` upgrade branch and hint are gone. `src/core/self-upgrade.ts`: `canSelfUpdate` no longer accepts `clawhub`. `src/commands/check-update.ts`: no `clawhub update` hint (#8464).+- `src/core/google/people-calendar-sweep.ts`, `google-clients.ts`: a full contacts re-list goes page by page (`listConnectionsPage`), saves `contacts_relist` (next page token and field mask) after each page lands through the same state store as Gmail's checkpoints (no git, so repo-less brains work), resumes there, restarts once from page 1 when Google rejects a saved page token (400/410), and lists at most 10 pages per run so Calendar and Gmail still run (#8906).+- `src/core/persistence/source-lifecycle.ts`: managed `remove`/`purge` deletes pages 500 at a time, each batch its own bounded transaction that first rechecks the final transaction's preconditions (including the CLI writer registration and the receipt quotas, `assertTopologyChangeCapacity`) and halves its size when it hits the statement bound; a refusal after committed batches says how many pages that run deleted. `topology-transaction.ts`: the `write_pending` hint says a retry resumes (#7702, #8905).+- `src/core/secret-scan.ts`: the escape-boundary twins also fire after `ESC[…m` (raw or written `\u001b[`, `\x1b[`, `\033[`), `\xNN`, `\UXXXXXXXX` and `=3D`; the `bearer` value accepts `\/` (#8266).+- Tests: `test/upgrade.serial.test.ts`, `test/self-upgrade.test.ts` (a renamed binary or an unclassified install with a working `clawhub` CLI never runs it); `test/contacts-relist-checkpoint-8906.slow.test.ts`, `test/contacts-relist-checkpoint-managed-8906.test.ts`; `test/source-retire-batched.test.ts`, `test/e2e/source-retire-batched-postgres.test.ts` (60,000 pages); `test/secret-scan-encoded-boundary-8266.test.ts`.++Reported and first fixed by @javieraldape (#8910, #8764) and @Masashi-Ono0611 (#7704, #8907, #8908).+ ## [0.60.624.0] - 2026-11-09++ **`gbrain doctor` now ends on its `--budget-ms` deadline when a local probe hangs, and the cheap incident checks keep their share of the budget.** The `home_dir_in_worktree` entry, which runs before the connection checks, ran `npm root -g`, `which -a gbrain` and `crontab -l` synchronously, with 5-second limits on the first and last and none on `which`. While one of them hung, nothing else in the process could run, the deadline included. So a 2500 ms run took about 5100 ms, and every later check, `links_extraction_lag` and `persistence_capacity` included, came back unknown with `elapsed_ms: 0`. Those probes now run asynchronously and are killed with SIGKILL at the entry's deadline (5 s at most, less the 250 ms report reserve), so none of them outlives the run. The entries before the connection checks may use at most half of the time left when the check run starts, so the ops sections and the cheap incident checks keep the other half. `--only`, `--fast` and a run with no database connection still give those entries the whole budget. This was the flaky `#6803 doctor deadlines (postgres)` E2E case (#8979). It failed on every backend-matrix job that ran on the 20261026.1 runner image, where a probe ran into its 5 s limit.++ ### Itemized changes++ - `src/commands/doctor/checks/local-audits.ts`: `localProbe` runs a local command asynchronously, bounded by `scanDeadline` (5 s, clipped to the entry deadline read when the entry starts). At that bound it kills the probe with SIGKILL, on POSIX its whole process group so a wrapper's children die too. A probe the entry deadline cuts short marks the entry expired, so its checks report unknown instead of absent. `npm_squat` (`npm root -g`, `which -a gbrain`) and `cron_gbrain_home` (`crontab -l`) use it, and a probe that fails or times out reads as absent, as before.+ - `src/commands/doctor/checks/cron-gbrain-home.ts`: the synchronous `readCrontab` is gone.+ - `src/commands/doctor/registry.ts`: with an engine and without `--fast` or `--only`, an entry before the connection lane runs to the overall deadline less half the time left when the check run starts.+ - Tests: `test/doctor-entry-deadline-6803.test.ts`. One test puts stand-ins for `npm`, `crontab` and `which` on PATH. They ignore SIGTERM and wait on a 6 s child of their own, yet a 1000 ms run finishes within its budget, `npm_squat` reports unknown, and neither the wrappers nor their children are still running afterwards. Another checks that a probe that answers in time still feeds `cron_gbrain_home`. In the second (PGLite and Postgres), an entry before the connection lane that outlives a 2000 ms budget still leaves `links_extraction_lag` and `persistence_capacity` reporting. A third checks that under `--fast` such an entry keeps the whole budget. The first two fail on the previous code.++ ## [0.60.623.0] - 2026-11-09++ **The brain owner's own agents now read the whole personal brain, and pages stamped `access: private` by default can be cleared in reviewed batches.** On a single-user brain, writer templates stamped `access: private` on ordinary research and ops pages, and every remote caller got `not_found` for them, the owner's own agent included. `gbrain access owner set <member>` now names the owner (config `access.owner_member`, database state, so repo-less brains work the same). Every token, OAuth client or stdio server bound to that member reads `visibility: private` pages, privacy-alias pages, derived and pinned-question pages and private facts through `get_page`, `search`, `query`, `recall` and the other page reads, within its source grant. `readable_by` and folder rules still bind it, a shared-room audience gets no relaxation, and other members, unbound and public callers read exactly as before. `gbrain repair private-labels` previews the existing labels with counts per category, keeps real restrictions, and clears the over-stamped ones in reviewed, recorded, reversible batches. The bulk-ingestion page template no longer writes an `access:` line, and docs/guides/access-designations.md defines every designation.++ ### Itemized changes++ - `src/core/access/owner.ts` (new), `src/commands/access.ts`: `gbrain access owner [set <member>|clear]`; the member must be enabled; `gbrain access check --token <name>` reports `owner`.+ - `src/core/access/caller.ts`, `src/core/search/private-visibility.ts`: `CallerAccess.owner`, set when the credential's live member is the owner and no audience other than the owner is asserted; the owner reads with privacy relaxed (member access stays mandatory); the request's config snapshot carries the owner key; `_meta.access.relaxation` gains `owner`.+ - `src/core/ops/facts.ts`: remote `recall` returns private facts to the owner.+ - `src/cli/as-preview.ts`: `--as <owner>` previews the owner's view.+ - `src/core/repair/private-labels.ts` (new), `src/commands/repair-private-labels.ts` (new): `gbrain repair private-labels`, explicit-only and preview-bound; classes `alias`, `alias-and-visibility`, `git-publish` (named only) and `restore`; a ledger under the gbrain home records each change.+ - Skills and docs: `skills/conventions/page-privacy.md` (new), `skills/bulk-ingestion` (template), `skills/brain-ops`, `skills/_AGENT_README.md`, `skills/frontmatter-guard`; `docs/guides/access-designations.md` (new), linked from multi-source brains, company brain, page anatomy and brains-and-sources; `docs/protocol/MCP_META_CHANNELS.md`.+ - `src/core/persistence/page-visibility.ts`, `src/core/persistence/page-prepare.ts`, `src/core/persistence/upload-streamed.ts`: a new `default` page the enabled owner's credential creates through `put_page` or a streamed upload is not kept to the owner (no `readable_by: [member:<id>]`); a rewrite keeps its stored readers, and `POST /ingest` still refuses the owner.+ - `src/core/persistence/page-prepare.ts`: on a git-canonical source, a page that was private from its first write (no file ever recorded) writes its file for the first time when it stops being private, so `--class git-publish` and an ordinary edit no longer refuse it as a removed canonical file.+ - `src/core/repair/private-labels.ts`: restore plans from each page's latest clear and its current labels, so a restore that was accepted but never landed stays restorable; a ledger line that fails to save after a write reports the values to undo by hand; a git-publish clear is called one-way, since Git history keeps the page.+ - Tests: `test/access-owner-reads.test.ts`, `test/access-owner-default-writes.test.ts`, `test/repair-private-labels.test.ts`.++ ## [0.60.622.0] - 2026-11-09++ **`think` keeps an entity's trajectory when the question names a month.** A question such as "What was the MRR of acme-example in April 2026?" bounds think's evidence to April (PR #5086), and that window used to cost the trajectory block twice over: a metric whose readings fall before and after April (March and June) injected nothing, although the March reading was the value in force all April; and an entity page last edited outside April was dropped from the gathered pages, so when the question's noun phrase ("the acme-example team") did not resolve on its own, no entity was found. Each metric's latest reading before the window now joins the readings inside it, unless its `valid_until` ended by the time the window opens, and pages the window drops still name the entities whose trajectory is read; they stay out of the evidence. BrainBench Cat 25's hermetic gate goes from 4 of 6 probes (FAIL) to 6 of 6 (PASS).++ **A purge no longer waits behind a refresh.** With `persistence.refresh_barrier` on, a write that arrives during a `gbrain sources refresh` is held as `deferred`. When that write would publish a staged body holding the claim being purged, `gbrain forget <id> --purge` refused `purge_blocked_pending_recovery` ("is publishing") until the refresh released or the barrier expired, up to 15 minutes, so leaked content stayed in the brain that long. A deferred write has not been claimed, so the purge now cancels it with `purged_content`, as it already did a queued one; a running or recovering write still refuses.++ ### Itemized changes++ - `src/core/think/temporal-window.ts`: `trajectoryPointsInWindow` keeps the points inside the window plus each metric's latest point before its start when that point is still valid at the start (events are not carried); `filterPagesToWindow` also returns the dropped pages.+ - `src/core/think/gather.ts`: `ThinkGatherResult.outsideWindowSlugs` lists the pages the window dropped.+ - `src/core/engine-sql/facts.ts`, `src/core/engine.ts`: `findTrajectory` points carry `valid_until` (the MCP `find_trajectory` wire shape is unchanged).+ - `src/core/think/index.ts`: the trajectory step filters through `trajectoryPointsInWindow`, and its candidate entities come from the gathered pages plus the pages the window dropped.+ - `src/core/persistence/intent-redaction.ts`: `cancelRequestsHoldingStagings` treats a `deferred` request like a `queued` one (GST-1602).+ - Tests: `test/refresh-barrier-purge-gst1602.test.ts` (PGLite and Postgres: a put_page deferred behind a real paused refresh, publishing a staged body that holds the claim; the purge commits, the write ends `cancelled`/`purged_content`, the staging is aborted and its parts deleted, and after the refresh releases the write stays cancelled with its counters released; it fails `purge_blocked_pending_recovery` with the fix reverted); `test/think-trajectory-window.test.ts` (a month with no reading of its own gets the March reading and not January's or June's; an entity page dated outside the month still routes its trajectory). Each test fails with its own fix reverted.++ ## [0.60.621.0] - 2026-11-09++ **A page a member-bound credential creates in the `default` source is now readable only by that member.** A token bound with `gbrain auth rescope --member <id>` and no `--sources` writes to `default`, the source every credential without a source grant reads, and so does a token granted `--sources default` and an OAuth client left at its registration default. Its `put_page` (and every page write through the same path) used to create an ordinary page there, which another member and an unbound token read through `get_page`, `search`, `query`, `recall` and `list_pages`; its `remember` facts were already kept on the member's own page. A page such a credential creates is now written with `readable_by: [member:<id>]`, in the database row on a repo-less brain and in the file on a repo brain; rewriting it without `readable_by` keeps the stored readers, and the member widens it by naming readers. An edit to an existing page that names no readers leaves it shared, and `POST /ingest`, which cannot keep a page to a member, refuses such a credential with `permission_denied`. Member-bound credentials whose write source is another source (the documented `--sources private-<member>,default` shape) and unbound credentials write exactly as before, apart from slugs a member now creates. Pages derived from such a page (extracted atoms, chronicle events, `derived_from` pages, and a synthesized concept that uses it) follow the rule for pages with readers and are readable by no remote caller, the writer included. A page that teammates should read, such as a shared `people/` or `companies/` entity page or a page in a folder a rule already scopes to a group, names its readers when it is created; otherwise the first member to create a slug keeps it, and every other remote credential writing that slug (another member, an unbound token, a shared agent) gets `page_not_found`. The operator widens such a page from the brain host by adding `readable_by` to it (the local CLI is not member-scoped). A member-bound `put_page` over a page deleted within the last 72 hours is a create, so it is kept to the member too. Pages written before this release keep whatever readers they have: `gbrain access who-can-read <slug>` shows who reads one.++ ### Itemized changes++ - `src/core/persistence/page-visibility.ts`: `defaultSourceMemberWriter` reads, live from the stored principal, whether a remote write to `default` comes from a token or OAuth client bound to an enabled member (never for a local, unbound, attested or audience write); `defaultSourceWriterReaders` gives a page such a writer sends without `readable_by` the stored page's readers, or the writer alone when the write creates the page.+ - `src/core/persistence/page-prepare.ts`: page preparation applies it to the frontmatter before the content hash, the rendered file and the stored row are made (restores and reverts excluded).+ - `src/core/persistence/upload-streamed.ts`: a page uploaded over the single-string ceiling gets the same readers.+ - The binding is read straight from the token or client row, so a lookup that fails refuses the write instead of publishing the page shared, and a write bound to a disabled member is refused (`readable_by_invalid`).+ - `src/commands/serve-http-webhooks.ts`: `POST /ingest` refuses a member-bound credential whose write source is `default` before anything is queued.+ - Docs: `docs/guides/multi-source-brains.md`, `docs/tutorials/company-brain.md` (Model C), `docs/mcp/ADMIN.md`.+ - Tests: `test/access-ungranted-member-writes.test.ts` (repo-less PGLite and Postgres, plus a repo brain: tokens with no grant and with `--sources default` and an OAuth client at its registration default; another member and an unbound token read nothing of a new page over `get_page`, `search`, `query`, `recall` and `list_pages`; the writer reads, rewrites and widens it; a shared page stays shared; `remember` unchanged; the documented shape unchanged and unstamped; `POST /ingest` refused with nothing queued).+## [0.60.620.0] - 2026-11-09**A diverged managed checkout now publishes its local commits on refresh by default when Git durability is on, after a secret scan of those commits.** Commits a script made with plain `git commit` in a managed checkout used to strand there whenever the remote moved: every `gbrain sources refresh` refused `refresh_diverged` and asked the user, unless `sources.refresh_publish_diverged` was set to `true`. With the setting unset, a worktree whose Git durability is on (`gbrain sources writer git-durability <source> --enable`, or the legacy hook) now publishes them itself: the local commits merged with the upstream in memory, never a rebase or force-push, then the fast-forward. The publish child scans, under its publish lock and for the exact commits it pushes, what they add: commit messages, added lines (including a value a later commit removed) and merge-commit conflict resolutions. A value that looks like a secret, added text too large to scan, or a commit that changes `.gbrain-scan-allow` or a `.gitattributes` refuses the new `publish_secret_found` naming the file, line, rule and commit, never the value, with nothing pushed; commits the scan cannot read in full refuse `publish_scan_unreadable` instead. The rewritten-upstream refusal and the `--expect-remote` bound are unchanged. `false` turns it off; `true` still publishes with durability off.