Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge commit '76179f77b992e0e1e86a460cce5babcb52ebb2ac' into capy/no-re-judge-of
garrytan2f5892f58077
diff --cc CHANGELOG.mdindex 96d10d35c6,1ae1b71814..91c481b0fb--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,22 -10,102 +10,118 @@@ credits are retained; no result has beeidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [Unreleased]++**A long conversation that keeps growing is no longer re-extracted, and re-paid for, on every new message.** Automatic event extraction reads a page's title, date, attendees and the first 12,000 characters of its body. On a conversation longer than that, each new message recorded a new revision, and each revision paid for another extraction call on exactly the same text. The model words each event a little differently every time, event pages are named after that wording, and an extraction of a page longer than 12,000 characters never retired the previous one, so every run added a fresh copy of every event. One page could collect dozens of paid calls and hundreds of duplicate events. Now a revision that changes nothing extraction reads (text, title, date, attendees, privacy) makes no call and writes nothing (it records `judge_input_unchanged`); a window the judge keeps failing on is paid for at most the page's attempt limit across all revisions, then records `judge_input_failed` until the text changes or a backfill asks again; and a re-extraction that re-read all the text the page's live events came from (for example after a title change, or the first time a conversation grows past 12,000 characters) replaces those events instead of adding to them. A page whose opening text was edited still keeps its earlier events, as before. Text past the first 12,000 characters is still not extracted; incremental coverage of the tail is tracked in #9013. Reported by @andreineacsu.++**Doctor counts the duplicates earlier releases left.** The new `chronicle_duplicate_events` check (info) reports how many pages hold live events from earlier extraction runs beside their newest run's, and how many such events. It changes nothing; a preview-first repair that retires them is tracked in #9012.++### Itemized changes++- `src/core/chronicle/execute.ts`: before the daily reservation, a row whose judge input digest equals that of the page's latest decided extracted generation (no ineligible revision or chronicle retirement since) finishes `skipped` / `judge_input_unchanged` with no call; an automatic row whose input already used the attempt limit on earlier revisions without publishing finishes `failed` / `judge_input_failed` (a refused input stays `judge_refused`), with no call; a truncated generation replaces the previous one only when every live chronicle event of the page is recorded by a ledger row whose judged window the new window starts with. Ended-invite projections and held results never count as judged.+- `src/core/chronicle/extract-events.ts`: `chronicleJudgedInput` (digest of the judge input with the body cut to `JUDGE_BODY_CHARS`, the extractor version and the depth page's visibility and source incarnation; the window and its sha256).+- Migration `v297` `chronicle_judge_window` (number restamped at the slot): `chronicle_page_state.judge_input_hash`, `judge_window_chars`, `judge_window_hash`; nullable, no backfill. A row recorded before it has no window, so that page's next revision is judged once more and stays additive.+- `src/core/chronicle/reasons.ts`, `src/core/error-registry.ts`: reason codes `judge_input_unchanged` and `judge_input_failed`.+- `src/core/chronicle/ledger-stats.ts`, `src/commands/doctor/checks/auto-chronicle.ts`: `readChronicleDuplicateEvents` and the `chronicle_duplicate_events` doctor check.+- Docs: `docs/guides/life-chronicle.md`, `docs/guides/error-codes.md`.+- Tests: `test/chronicle-long-conversation-8972.test.ts` with its Postgres arm `test/e2e/chronicle-long-conversation-8972-postgres.test.ts`; schema, migration and doctor goldens regenerated for the new columns and check.++ ## [0.60.630.0] - 2026-11-09++ **`gbrain git commit-push` and `scripts/brain-commit-push.sh` no longer report success when git left a named path uncommitted.** `git add` stages nothing and still exits 0 for a modified file flagged assume-unchanged or skip-worktree and for a file inside a nested Git repository, so the helper answered "nothing to commit" (or pushed the other paths) with exit 0, and the write sat uncommitted with nothing in any log. Now the other named paths are still committed (and, on a classic checkout, pushed), and the run exits 1 naming each skipped path and its reason: `writer_coordinator_required` for a page in a managed canonical worktree, which belongs to the persistence owner (save it through `put_page`), and the new `commit_paths_skipped` for anything else. The helper's own managed-checkout refusal now prints the operator contract (code, why, fix, next) instead of one line.++ | Situation | Before | After |+ | --- | --- | --- |+ | A named file is flagged assume-unchanged (or skip-worktree under a named directory) and modified | `nothing to commit`, exit 0; the edit stays uncommitted | `commit_paths_skipped` (reason `assume_unchanged` / `skip_worktree`), exit 1; fix (ask the user): `git update-index --no-assume-unchanged -- <paths>`, and a separate `git update-index --no-skip-worktree -- <paths>` (given both flags, git clears only the first) |+ | A named file sits inside an untracked nested repository | exit 0 with nothing committed; beside other paths, `git_unavailable` and nothing committed | the other paths are committed, then `commit_paths_skipped` (reason `not_staged`), exit 1 |+ | The same on a managed canonical worktree, for a page | `nothing to commit; not pushed`, exit 0 | `writer_coordinator_required`, exit 1, naming each page; fix (ask the user): save it through `put_page` |+ | `scripts/brain-commit-push.sh` without gbrain on the machine | `nothing to commit`, push, exit 0 | the push still runs, then `Error [commit_paths_skipped]` with each path, exit 1 |+ | `scripts/brain-commit-push.sh` on a checkout marked managed | one line, `writer_coordinator_required: submit managed changes through persistence`, exit 1 | `Error [writer_coordinator_required]` with `Why:`, `Fix:` (put_page; `gbrain git commit-push` for files that are not pages) and `Next: ask_user`, exit 1 |++ A skip-worktree file absent from disk (a sparse checkout) and ignored files under a named directory are not reported; a named ignored file was already refused by `git add` (`commit_paths_invalid`). Existing brains get the new helper on the next `gbrain sources harden`.++ ### Itemized changes++ - `src/core/git/commit-push.ts`: after the commit step, `commitPaths` reads which named paths HEAD still lacks (flagged entries whose bytes on disk differ from HEAD, named files git did not index, and status entries with unstaged changes) and leaves an unindexed file out of `commit --only`, so it no longer fails the other paths. `commitAndPush` (classic, managed and remoteless) throws `commit_paths_skipped` or, for a page in a managed worktree, `writer_coordinator_required`, after committing and publishing the rest; `detail` carries the skipped paths, the commit and the pushed head.+ - `src/core/brain-repo-durability.ts`: the rendered `scripts/brain-commit-push.sh` prints the operator contract on its managed refusal, and its fallback (no gbrain) runs the same check after its commit (NUL-separated listings, so a non-ASCII or quoted name is read exactly; a symlink is compared by its link text), leaves a file git did not index out of `commit --only`, and exits 1 with `commit_paths_skipped` after the push.+ - `src/commands/git.ts`: when the run fails after the other paths were pushed, the push log still records that push.+ - `src/core/error-registry.ts`: new code `commit_paths_skipped` (reasons `assume_unchanged`, `skip_worktree`, `not_staged`).+ - Docs: `docs/guides/shared-checkout-git.md` (the `commit_paths_skipped` row, the `writer_coordinator_required` row, the fallback paragraph), `docs/guides/error-codes.md` (regenerated).+ - Tests: `test/git-commit-push-skipped-paths-gst2116.test.ts` (the real CLI and the rendered helper against temp repositories, a bare remote and a managed-root registry: an assume-unchanged page, a nested-repository page beside a committable one, a skip-worktree entry under a named directory, a managed page and a managed non-page file, a remoteless checkout, a named directory inside a nested repository, a run with both flags, the helper's fallback (a non-ASCII path, a nested-repository file beside a committable page, a clean flagged symlink), the helper handing over to gbrain on a managed root, its managed refusal; a named directory beside a sparse entry and an ignored draft still commits with exit 0). Twelve of its thirteen cases fail on master; the one that passes there is the control.++ ## [0.60.629.0] - 2026-11-09++ **`gbrain repair file-drift` now agrees with sync on a held origin-twin page.** A legacy page left as an origin twin with no recorded file (no import record) could be held `file_drift` by sync while `repair file-drift --slug <slug>` reported `no_drift`. The hold's own suggested fix couldn't clear it, and scripts that use the preview as a drift check passed falsely. The preview now reads such a twin against its slug-path file, the same way sync imports it, and lists it with an apply command.++ ### Itemized changes++ - `src/core/persistence/drift-conflicts.ts`: `liveFileDrift` reads an adoptable origin twin with no recorded file against its slug-path file. A twin in a read-only mirror source, or whose slug path no file can import as, keeps `database_only`. A twin under a declared db_only path, which sync holds but no repair can adopt, reads `unknown` (`db_only_slug_path`) instead of passing as `no_drift`.+ - `src/core/persistence/reconcile-state.ts`: the slug-path adoption check moves into one exported `adoptableSlugOrigin`, which reconcile and the drift preview now share. Reconcile's behaviour is unchanged.+ - Applying either side to such a twin binds the slug-path file as its `source_path` and clears `origin_twin`. Maintenance writes to a twin whose slug-path file differs are now refused as drift, like any drifted page.+ - Tests: `test/repair-file-drift-origin-twin-gbra108.test.ts` (PGLite, managed source, real git): a legacy page with no import record held by sync, previewed and applied for both `--prefer database` and `--prefer file`, after which a re-sync clears the hold; also mirror-read-only, db_only, non-importable slug path, missing file and shared-origin cases.++ ## [0.60.628.0] - 2026-11-09++ **A page a member-bound credential creates in a federated source is now readable only by that member.** A token or OAuth client bound to a member (`gbrain auth rescope --member <id>`) and granted `--sources <id>` for a federated source wrote its pages there with no readers. Every credential without a source grant reads `default` plus every federated source, so another member's no-grant token and an unbound token read those pages over `get_page`, `search`, `query`, `recall` and `list_pages`. Such a page is now written with `readable_by: [member:<id>]`, as a page the credential writes to `default` already was, and `POST /ingest` refuses the credential. A write source that is not federated keeps the audience its grants give it. Pages written before the upgrade keep their readers: check them with `gbrain access who-can-read <slug>`.++ ### Itemized changes++ - `src/core/source-resolver.ts`: `noGrantFloorReads` says whether a caller with no source grant reads a source unqualified: `default`, or a source in the federated set `noGrantFederatedScope` threads for that floor. It throws when the sources cannot be read.+ - `src/core/persistence/page-visibility.ts`: `defaultSourceMemberWriter` keys on `noGrantFloorReads` instead of the literal `default`, so a member-bound write to a federated source is stamped too. A source table it cannot read refuses the write instead of publishing the page shared.+ - `src/commands/serve-http-webhooks.ts`: the `POST /ingest` refusal names the credential's write source.+ - Docs: `docs/guides/multi-source-brains.md`, `docs/tutorials/company-brain.md` (Model C), `docs/mcp/ADMIN.md`.+ - Tests: `test/access-federated-member-writes.test.ts` (PGLite, and Postgres with `DATABASE_URL`): a member-bound token or OAuth client granted a federated source creates a page that another member and an unbound token, reading the federated set as the HTTP transports do, cannot read; with `default` isolated the floor is `default` alone and nothing is stamped; a streamed upload over the 24 MiB ceiling is kept to its member too; a write whose source config cannot be read is refused, not published unstamped; a non-federated source stays unstamped and out of unbound reads; a member-bound write cannot leave its granted source; `POST /ingest` refuses with nothing queued.++ ## [0.60.627.0] - 2026-11-09++ **A webhook capture can no longer drop a page's readers (GST-2112).** `POST /ingest` wrote through a trusted local path whose only check was that the sender could read the page, so a member-bound token granted a source could replace a page whose `readable_by` named it with a body that named no readers, and every caller could then read the page. The route and the `ingest_capture` job now apply the remote `put_page` readers rule: a body that drops `readable_by` from a page that names readers, or names readers that leave out the sender, is refused `readable_by_invalid` (403 at the route, nothing queued; at write time for a job already queued). The job binds its write to the revision it checked, so readers added between the check and the write refuse the write with `revision_conflict` and the retry refuses `readable_by_invalid`. A capture already queued from a member-bound credential whose write source is `default` is refused `permission_denied` at write time, as the route refuses it before queueing. Bodies that keep the readers, and pages without readers, import as before.++ ### Itemized changes++ - `src/commands/serve-http-webhooks.ts`: the route applies the remote readers rule to the capture body before anything is queued.+ - `src/core/minions/handlers/ingest-capture.ts`, `src/core/import-file.ts`: the job reads the page snapshot before the visibility check, applies the same rule at write time, binds its write to the checked revision (`revision_conflict` when it moved; a page that did not exist stays a create), and refuses a member-bound `default` writer `permission_denied`.+ - `src/core/behavior-change-notice.ts`: one row for the changed capture behavior.+ - Docs: `docs/guides/write-refusals.md`.+ - Tests: `test/ingest-capture-keeps-readers.test.ts` (PGLite and Postgres).++ ## [0.60.626.0] - 2026-11-09++ **`gbrain sources record-origin --remote` now locks down the existing checkout too, and on a managed brain it can no longer report success while a reclone still clones with git-lfs on.** On a managed brain the record took only the source row lock, so a reclone that had already read the source, or held its worktree locks, could clone with git-lfs downloads and hooks on after the command said the source was recorded. The record now takes the worktree locks and rows a reclone takes (refusing the id `source_busy` while one runs), and the reclone reads the record under its own locks. `--remote --apply` now also turns git-lfs downloads and hooks off in the existing checkout's `.git/config`, because a reclone only happens when a checkout is lost or replaced, and until then doctor read green while the checkout still fetched git-lfs objects and ran hooks. The git-lfs check now reads a committed `.gitattributes` under a directory whose name holds a tab (it was cut at the tab and skipped), ignores commented-out `filter=lfs` lines, says "declares a git-lfs filter" when a rule only declares one, and records a clone of an empty repository instead of telling the operator to restore an intact checkout. A failed write is reported for its own id instead of ending the run without saying which ids were recorded.++ ### Itemized changes++ - `src/core/url-source-origin.ts`: on a managed brain each apply runs inside `withTopologyLocks` and `lockTopologyRows` (a held lock or a running refresh refuses `source_busy`); `--remote --apply` writes the clone-time lock-down (`lfs.fetchexclude=*`, `core.hooksPath=/dev/null`, `lfs.locksverify=false`) into the checkout's `.git/config` with `git config --file` before the row, into the repository's shared config (`--git-common-dir`, so a linked worktree is covered), then reads back the values Git uses there and refuses `write_failed`, naming the key, when a worktree-scoped or included setting overrides one; a source already recorded as remote whose checkout lacks the lock-down gets it (`recorded`, with no `lfs_tracked` refusal even when its files now use git-lfs), and one that has it stays `already_recorded`; each key's existing values are removed before its one value is written, so one that holds several values gets the one clone-time value; a throw is reported per id as `write_failed`, saying whether the checkout already got all or part of the lock-down, and the batch continues. The committed-attributes read splits each `ls-tree -z` record at its first tab, reads only blobs, and ignores comment lines; a declared-only filter refuses `lfs_tracked` with its own wording. An unborn HEAD with an empty index counts as no committed attributes. The top-level comparison realpath-normalizes both sides. `lfs_unknown` reasons name the cause from Git's own error: checkout missing, not its own repository's top level (an enclosing repository, or none), owned by another user (`safe.directory`), or a Git read failed (for example a corrupt `.git`).+ - `src/core/hardened-git.ts`: `rev-parse --git-common-dir` joins the read-only allow-list, so the lock-down finds a linked worktree's shared config.+ - `src/core/persistence/topology-clone.ts`: a managed clone or reclone takes the source config it clones with from its locked admission read, not from the read before it took its locks.+ - `src/core/behavior-change-notice.ts`: one row for the changed `record-origin` behavior.+ - Docs: `docs/guides/repair.md#url-source-origin` (checkout lock-down and why, `source_busy`, `write_failed`, `lfs_tracked` and `lfs_unknown` causes), the key-files row in `docs/architecture/key-files/files-and-sync-2.md`, `docs/architecture/canonical-writers.tsv`.+ - Tests: `test/url-source-origin.test.ts` (PGLite and Postgres): a record attempted while a reclone holds its locks is refused and writes nothing; a reclone that read the source before a record landed clones with the recorded settings; the existing checkout gets the lock-down on apply and not on preview; a tab-named directory's `.gitattributes` is read; commented rules are ignored and a declared-only rule is worded as declared; an empty-repository clone records; each `lfs_unknown` cause is named; a mid-batch write failure is reported for its id while the others record; a record during an active refresh is refused `source_busy`; a lock-down that fails part way is reported as a partial change; a worktree-scoped override is refused `write_failed` naming the key; a linked worktree gets the lock-down where Git reads it; a source recorded as remote before the lock-down existed gets it on the next apply; a corrupt `.git` and a `safe.directory` refusal each get their own `lfs_unknown` reason; a source recorded as remote whose files now use git-lfs still gets the lock-down, and a key that already holds several values gets the one clone-time value.++ ## [0.60.625.0] - 2026-11-09++ **`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.