Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Refresh publishes a diverged managed checkout by default when Git durability is on, after scanning its commits for secrets
garrytand2cbef8750c6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4e8b05d8ec..82dc2edbb5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,18 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [Unreleased]++**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. Before anything is pushed, every blob those commits added or changed is scanned for values that look like secrets, including one a later commit removed; a finding refuses `refresh_diverged` naming the file, line, rule and commit, never the value. The rewritten-upstream refusal and the `--expect-remote` bound are unchanged. `false` turns it off; `true` still publishes with durability off. The keep-checkout publish now runs the checkout's pre-push hook when the push is a plain fast-forward of HEAD (it still skips it for the in-memory merge it builds).++### Itemized changes++- `src/core/git/range-secret-scan.ts` (new): `scanCommitRange(root, base, head)` lists the blobs each non-merge commit in `base..head` adds or changes, skips path-allowlisted, binary and over-cap blobs, and scans each once with `scanText` and the workspace allowlist; `null` when git cannot list or read them.+- `src/core/persistence/worktree-refresh.ts`: an unset `sources.refresh_publish_diverged` publishes only when `gitDurabilityPolicy` says durable (otherwise `refresh_diverged` names the durability and the `--enable` command); every automatic publish refuses on a secret finding or an unreadable range.+- `src/core/git/commit-push.ts`: `--no-verify` only for a candidate the publish merged, not for HEAD itself.+- Docs: `docs/guides/write-refusals.md` (`refresh_diverged`), `docs/guides/live-sync.md`, `docs/guides/shared-checkout-git.md`, `docs/guides/troubleshooting.md`, `docs/architecture/canonical-writers.md`.+- Tests: `test/guarded-publish.test.ts` (the range scan: a secret added then removed is found without its value, allowlist and binary skips, an unreadable range; the pre-push hook runs and can stop a keep-checkout fast-forward); `test/refresh-publish-diverged-7686.test.ts` (unset with durability off refuses naming `--enable`, unset with durability on publishes, a secret in the local commits refuses with nothing pushed).+## [0.60.616.0] - 2026-11-08**Opt-in local-edit adoption (`persistence.adopt_local_edits`, off by default) no longer leaves an adoption commit unrecorded when the write it was made for ends early, names that commit on a failed adoption's receipt, and refuses during a bisect or an uncommitted squash merge.** An adoption whose `gbrain: adopt local edit` commit landed before its publication failed used to end `write_claim_lost` (or be cancelled) once its caller's claim ended, so the commit was never recorded and later writes to the page refused `file_database_drift` until a sync. It is now published on its replay with its receipt naming the landed commit. An adoption that ends without committing after its commit landed names that commit too (`outcome.persistence.git_commit`, `landed_before_row: true`), so `gbrain write-request` and `gbrain sources writer failures` tie the commit to the adoption. Adoption now also keeps its refusal while a `git bisect` or an uncommitted `git merge --squash` is in progress, and when Git names the checkout's git dir with anything but one absolute, existing directory in valid UTF-8.diff --git a/docs/architecture/canonical-writers.md b/docs/architecture/canonical-writers.mdindex 9546baae61..eafcd9b472 100644--- a/docs/architecture/canonical-writers.md+++ b/docs/architecture/canonical-writers.md@@ -78,8 +78,9 @@ worktree native lock while claims stop (`fenced`), verifies HEAD and runsordinary managed `--no-pull` sync that follows, so every imported page is ajournaled request. A durable `persistence_worktree_refreshes` row lets arestarted owner converge an interrupted refresh without adopting an unverified-HEAD. With `sources.refresh_publish_diverged` on (the user's standing consent,-default off), a diverged refresh first runs the keep-checkout publish, which+HEAD. With `sources.refresh_publish_diverged` on (unset means on when the+worktree's Git durability is on; `false` turns it off), a diverged refresh first scans+the local commits for secrets, then runs the keep-checkout publish, whichpushes HEAD merged with the upstream in memory and never moves the checkout orwrites the database, then fast-forwards as above. Remote sync retains theoriginal `submit_job` principal, admin/source/operation ceiling and normalizeddiff --git a/docs/guides/live-sync.md b/docs/guides/live-sync.mdindex d45d359cc8..f7b1a88b28 100644--- a/docs/guides/live-sync.md+++ b/docs/guides/live-sync.md@@ -681,13 +681,15 @@ vars — incident-time escape hatches, not everyday knobs.means something commits into the checkout outside gbrain: fix that writerinstead of forcing the checkout([scripts and the managed checkout](shared-checkout-git.md#scripts-and-the-managed-checkout)).- When local commits there are expected (automations committing alongside a- sibling checkout that pushes the same branch), the user can give standing- consent with `gbrain config set sources.refresh_publish_diverged true`- (default off): a diverged refresh then pushes the local commits merged with- the upstream in memory, the same publish as+ When the worktree's Git durability is on, a diverged refresh publishes the+ local commits itself (`sources.refresh_publish_diverged` unset; `false` turns it+ off, `true` publishes even with durability off): it scans every blob those+ commits added for values that look like secrets and refuses+ `refresh_diverged` naming the file, line and rule when it finds one, then pushes+ the local commits merged with the upstream in memory, the same publish as`gbrain git commit-push --push-only --keep-checkout` run as a child process- (it skips the checkout's pre-push hook), and fast-forwards to the merge. It never moves the checkout to merge, a conflicting file refuses+ (the checkout's pre-push hook runs when the push is a fast-forward of HEAD),+ and fast-forwards to the merge. It never moves the checkout to merge, a conflicting file refuses`integrate_conflict` naming it with nothing pushed (with `gbrain.quarantine`on, the remote's version is published, this machine's is kept under`refs/gbrain/quarantine/`, and the refresh says so), an uncommitted edit to adiff --git a/docs/guides/shared-checkout-git.md b/docs/guides/shared-checkout-git.mdindex 6f3eef4ec4..9b0430c77b 100644--- a/docs/guides/shared-checkout-git.md+++ b/docs/guides/shared-checkout-git.md@@ -288,8 +288,9 @@ commits come in. Four rules keep that checkout able to move:and retry the refresh, as the [refusal](write-refusals.md#refresh_diverged)says. Never force the checkout. When local commits there are expected(automations committing alongside a sibling checkout that pushes the same- branch), the user can turn on `sources.refresh_publish_diverged` (default- off) so each refresh runs that publish itself+ branch), each refresh runs that publish itself when the worktree's Git durability is+ on (`sources.refresh_publish_diverged` unset; `false` turns it off, `true` publishes+ with durability off too), after scanning the local commits for secrets([live sync](live-sync.md)); it never publishes over a rewritten upstream.3. **Stop syncing a source before rewriting its history.** Before aforce-push or `git filter-repo`, run `gbrain sources set-sync <id> off`diff --git a/docs/guides/troubleshooting.md b/docs/guides/troubleshooting.mdindex 64c564d3cd..bbf41baa20 100644--- a/docs/guides/troubleshooting.md+++ b/docs/guides/troubleshooting.md@@ -31,7 +31,7 @@| A command exited 3 (`confirmation_required`) | relay `user_message`; run `fix.command` only after the user agrees | agent, after the user agrees | the payload's `effects` | the fix's `verify` || A scheduled job, workspace script or hook finds nothing in the brain (every lookup empty), or its log shows `no_brain` or `GBRAIN_DB_ACCESS no_url`, while the same command works by hand | the job runs without the brain's config: call gbrain through one wrapper that sets `GBRAIN_HOME` and loads the brain's env file, and stop discarding its stderr ([the wrapper](cron-schedule.md#calling-gbrain-unattended)); `gbrain doctor --only cron_gbrain_home --json` names crontab lines that skip it | agent | none | the job's log shows results, and `gbrain engine status --json` run through the wrapper names the expected `db_url_source` || `gbrain sources refresh` refuses `refresh_not_owner` from cron or a script but works by hand | the caller resolves another gbrain home, so it is another host; the refusal names the identity file, `HOME` and `GBRAIN_HOME` it read. Set the owner's `GBRAIN_HOME` in the wrapper (not `HOME`, which also swaps git credentials); never copy or delete a `host.json` | agent | none | `gbrain sources refresh <id> --dry-run` through the wrapper |-| `gbrain sources refresh` refuses `refresh_diverged` on every run | something commits into the managed checkout outside gbrain, usually a script that writes files and runs `git commit` without pushing. `git log @{upstream}..HEAD` names the commits; move that writer to `gbrain git commit-push -- <paths>`, then publish the stray commits merged with the upstream (`gbrain git commit-push --push-only --keep-checkout --path <checkout>`) and retry, as the [refusal](write-refusals.md#refresh_diverged) says; never force ([scripts and the managed checkout](shared-checkout-git.md#scripts-and-the-managed-checkout)). When local commits there are expected, the user can instead turn on `sources.refresh_publish_diverged` (default off) so each refresh publishes them itself ([live sync](live-sync.md)) | agent; reconciling after the user agrees | `destructive` when reconciling drops local commits | `gbrain sources refresh <id> --dry-run` |+| `gbrain sources refresh` refuses `refresh_diverged` on every run | something commits into the managed checkout outside gbrain, usually a script that writes files and runs `git commit` without pushing. `git log @{upstream}..HEAD` names the commits; move that writer to `gbrain git commit-push -- <paths>`, then publish the stray commits merged with the upstream (`gbrain git commit-push --push-only --keep-checkout --path <checkout>`) and retry, as the [refusal](write-refusals.md#refresh_diverged) says; never force ([scripts and the managed checkout](shared-checkout-git.md#scripts-and-the-managed-checkout)). With the worktree's Git durability on, each refresh publishes them itself unless `sources.refresh_publish_diverged` is `false` (the refusal names a durability that is not on, or a value that looks like a secret in the local commits) ([live sync](live-sync.md)) | agent; reconciling after the user agrees | `destructive` when reconciling drops local commits | `gbrain sources refresh <id> --dry-run` || A `--json` caller fails to parse gbrain's output | something other than gbrain wrote to stdout, usually a wrapper or a hook it runs; send that output to a log file or stderr (gbrain's own notices already go to stderr) | agent | none | the same call piped to `jq .` parses || gbrain calls time out from a script or language runtime but finish by hand, or each search takes several seconds | a cold CLI start takes 3–6 s on a pooled Postgres brain: set caller timeouts of at least 10 s in both the shell and the runtime (a runtime exec timeout can override the shell's), and turn on the [warm CLI socket](cli-socket.md). If warm searches stay slow, measure the round trip to the database; one in another region dominates search time | agent; moving the database after the user agrees | none | `GBRAIN_DEBUG=1 gbrain search <query>` prints a `[cli-socket] warm:` line || After a database change some processes still use the old server, or a URL variable silently keeps its old value | a shell-sourced env file has an unquoted `&` (the assignment ends there), or a process kept the environment it started with. Quote every value, keep Postgres URLs to `?sslmode=require` (driver options as variables, such as `GBRAIN_PREPARE=false`), update every URL variable the tooling reads, restart every gbrain process, and prove the switch from the database side ([switching a database](../../INSTALL_FOR_AGENTS.md#switching-a-database)). Never paste `env` output into a transcript while debugging | agent, after the user agrees | none | a row written after the restart appears on the new server |diff --git a/docs/guides/write-refusals.md b/docs/guides/write-refusals.mdindex 3ca4d90688..ca84cc5041 100644--- a/docs/guides/write-refusals.md+++ b/docs/guides/write-refusals.md@@ -564,7 +564,7 @@ this anchor (`--json` puts them in one object on stdout); the command exits 1.| <a id="refresh_no_upstream"></a>`refresh_no_upstream` | `refresh_no_upstream` | The checkout's branch tracks no upstream, HEAD is detached, or the checkout is not a Git checkout at all (gbrain never initializes Git on its own), so there is nothing to fast-forward to. | `git -C <checkout> branch --set-upstream-to <remote>/<branch>` (the fix fills in the real values), then retry. A checkout that is not Git has nothing to refresh; making it a clone with an upstream is the user's call. || <a id="fetch_failed"></a>`fetch_failed` | `fetch_failed` | `git fetch` failed or did not finish within `sources.refresh_fetch_timeout_ms` (default 120000; `GBRAIN_REFRESH_FETCH_TIMEOUT_MS`; `--fetch-timeout-ms` wins over both). Nothing changed and no refresh record was written. | Retry. For a slow remote, raise the bound with `--fetch-timeout-ms <ms>` or `gbrain config set sources.refresh_fetch_timeout_ms <ms>`. Credentials are the user's: ask them to fix authentication rather than changing the remote. || <a id="refresh_git_unavailable"></a>`git_unavailable` | `git_unavailable` | A git command that reads the checkout's branch or remote (`symbolic-ref`, `remote`, `config --get branch.<branch>.remote` or `.merge`) failed or did not finish, so the checkout's state is unknown. The message names the command and git's first error line. A detached HEAD or an unset key is not this refusal. Nothing changed and no refresh record was written. | Run `git -C <checkout> status` to see why git cannot read the checkout, repair what it reports, then retry `gbrain sources refresh <source>`. |-| <a id="refresh_diverged"></a>`refresh_diverged` | `refresh_diverged` | The checkout has commits its upstream lacks, so a fast-forward is impossible. Nothing changed. | Ask the user, then publish the local commits merged with the upstream: `gbrain git commit-push --push-only --keep-checkout --path <checkout>` merges in memory, pushes the merge, refuses on a conflicting file and never moves the checkout (the refusal's fix fills in the real path and counts the local commits). Then retry `gbrain sources refresh <source>`, which fast-forwards to the merge. `gbrain sources reclone <source>` replaces the checkout instead and drops the local commits. With `sources.refresh_publish_diverged` set to `true` (the user's standing consent, default off), the refresh runs that publish itself, in a child process that skips the pre-push hook, and then fast-forwards; a conflicting file then refuses `integrate_conflict` (with `gbrain.quarantine` on, the remote's version is published instead, this machine's is kept under `refs/gbrain/quarantine/`, and the refresh says so), and an uncommitted edit to a file the upstream changed refuses `refresh_dirty`, both with nothing pushed. The setting never publishes over a rewritten upstream: when the checkout holds a commit the upstream held before but no longer contains (a force-push), or gbrain has no record of the upstream before the fetch, the refresh still refuses `refresh_diverged` and the user decides. |+| <a id="refresh_diverged"></a>`refresh_diverged` | `refresh_diverged` | The checkout has commits its upstream lacks, so a fast-forward is impossible. Nothing changed. | Ask the user, then publish the local commits merged with the upstream: `gbrain git commit-push --push-only --keep-checkout --path <checkout>` merges in memory, pushes the merge, refuses on a conflicting file and never moves the checkout (the refusal's fix fills in the real path and counts the local commits). Then retry `gbrain sources refresh <source>`, which fast-forwards to the merge. `gbrain sources reclone <source>` replaces the checkout instead and drops the local commits. With `sources.refresh_publish_diverged` unset on a worktree whose Git durability is on, or set to `true`, the refresh runs that publish itself, in a child process (the pre-push hook runs when the push is a fast-forward of HEAD), and then fast-forwards; it first scans every blob the local commits added and refuses `refresh_diverged` naming the file, line and rule (never the value) when one looks like a secret, and unset with durability not on refuses naming `gbrain sources writer git-durability <source> --enable`; a conflicting file then refuses `integrate_conflict` (with `gbrain.quarantine` on, the remote's version is published instead, this machine's is kept under `refs/gbrain/quarantine/`, and the refresh says so), and an uncommitted edit to a file the upstream changed refuses `refresh_dirty`, both with nothing pushed. The setting never publishes over a rewritten upstream: when the checkout holds a commit the upstream held before but no longer contains (a force-push), or gbrain has no record of the upstream before the fetch, the refresh still refuses `refresh_diverged` and the user decides. || <a id="refresh_dirty"></a>`refresh_dirty` | `refresh_dirty` | Uncommitted or untracked files overlap the incoming upstream changes (the first 20 are named), or `git merge --ff-only` refused for the same reason. HEAD did not move. The merge runs under the checkout's commit lock, so a `gbrain git commit-push` in progress is waited out (#8117); a lock held past its wait refuses as `commit_lock_busy`, and another git process holding `.git/index.lock` refuses as `git_index_locked` after brief retries. Both are retryable. Uncommitted files outside the incoming changes do not refuse; they are kept and listed as `preserved_uncommitted`. | Commit or discard the named paths, then retry. Check `gbrain sources writer status <source> --json` first: a pending Git effect may be about to commit a gbrain-published file. || <a id="sync_in_progress"></a>`sync_in_progress` | `sync_in_progress` | A managed sync of one of the checkout's sources has an unfinished cursor. Moving the checkout now would strand it, and the refresh never waits on a sync. `gbrain repair frontmatter --apply` refuses the same way while an unfinished cursor still names a selected file. | Run the printed `gbrain sync --source <source> --no-pull ...` resume command (it keeps the cursor's options), then retry (for a repair, preview again and approve the new hash). || <a id="refresh_in_progress"></a>`refresh_in_progress` | `refresh_in_progress` | Another refresh of the same checkout is active and its process is still running (the message names its holder's pid and host when the active refresh row is already readable), or a command that changes which sources share the checkout (`sources add`, `remove`, `archive`, `restore`, `reclone`) ran while one was active. A refresh whose process died is not a reason to refuse: the next refresh on the owner host finishes it first (`--dry-run` does not, so it still refuses while the orphan stands, and neither does a refresh that cannot read the checkout's HEAD: it leaves the orphan as it is and refuses until git can read HEAD again; writer status then names `git -C <checkout> status` instead of the next refresh). A refresh whose holder is recorded on another host, or whose lock file this host cannot open, is never taken over either: writer status shows its `liveness` as `unknown` (its `next` names the host to run on), and `gbrain sources refresh <source> --resume` on the owner host finishes it once that host's refresh is known to have stopped. Pending publication or topology recovery on the checkout refuses `refresh_recovery_required` first. An interrupted refresh that needs a reset decision refuses `refresh_recovery_required` instead. | Wait for the running refresh, or check it with `gbrain sources writer status <source>` (`liveness`, `holder`). `gbrain sources refresh <source> --resume` finishes an orphaned one now; then retry the source command with the same request ID. |diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsvindex 99245e61a3..556c946bfc 100644--- a/scripts/module-size-limits.tsv+++ b/scripts/module-size-limits.tsv@@ -47,4 +47,4 @@ src/commands/doctor/checks/extraction-sync.ts 1500 ratchet +7 GBRA-130 A-1: linksrc/core/search/evidence-delivery.ts 1759 ratchet +5 W5: EvidencePlan.rankCut resolved with the plan (logic in search/page-rank-cut.ts); +20 W5 whole_pages: wholeCost prices a block as delivery would emit it whole (needs the private Block/enrichBlock internals) and the cut is wired before allocate (cutWholePages lives in search/page-rank-cut.ts); new row: crossed the 1500 unlisted cap at the #6367 merge (master 1479, its explicit-budget cap) by the C1 date header threaded through every block path, cap included; pagePlanHits (search/page-plan-hits.ts) and the header loader (evidence-date.ts blockDateHeaders) were peeled first; peel candidate: allocateCapped; +8 at the #6396 merge: page evidence text cut through the fence-chunk trust overlay and the caller minTrust floor (re-summed: our 1504 + master +8); +119 Cat 40 next wave F2: the search.long_page_unit policy (withLongPagePolicy, selectLongPages size preflight with page/byte/deadline limits) and the long-page fetch and fallback in deliverEvidence, kept in the shared seam the plan names (gbrain-evals docs/plans/2026-10-11-cat40-next-wave, F2); +17 F2 rework to the frozen-comparison policy: search.long_page_min_chars (rendered-body characters, default 20,000) read in withLongPagePolicy, a character count in the preflight, the rendered-body confirmation in deliverEvidence, and the long-page row exemption in capDeliveredSnippets (re-summed at the 0.60.225.0 merge: master 1537 + F2 136); +39 Wave B PR 2 lane 2b: planSegmentedBlock joins the windows search/segmented-evidence.ts reads around a segmented page's hits into one run-marked document (needs the private Doc/Piece/buildDoc/locateAnchor internals), planBlock's unit cut split into blockFromDoc for both, sections bounded by their run, selectionCost counts a gap between runs, and the fetch skips the whole-body fence overlay for a segmented page; +4 segmented pages read at once before planning (segmentedReads; the read is search/segmented-evidence.ts, the statements page-body/read-range.ts); +17 GBRA-156: tail trim plan flag, DeliverOptions.query, DeliveryMeta.tail_trim, the trim call and the frozen-hit score/query library fields (logic in search/evidence-tail-trim.ts; interface fields cannot move); +7 GBRA-205: EvidencePlan.titleHeader and DeliveryMeta.title_header (interface fields cannot move) and the titles option on the header loader (logic in search/evidence-date.ts; the query budget key lives in search/evidence-packing.ts); +11 #7600: assemble_evidence quotes conversation rows and capEvidenceToBudget counts the quote fence (logic in search/transcript-quote.ts); +2 GBRA-156 /ship review: the cut-path admission and title room count the quote fence; +2 GBRA-156 /ship review pass 2: capEvidenceToBudget counts the fence only for the paths that fence (quote flag; recall counts the text as returned); +4 GST-687: page evidence and the extractive fallback quote below-owner-tier text for untrusted readers (untrusted flag; logic in search/transcript-quote.ts)src/commands/config.ts 1526 ratchet +1 GBRA-216: recall.* config set value refusal (facts/recall-config.ts); +1 GBRA-216: config set refuses a dream.claim_conflicts.mode other than propose|off (refusal in facts/claim-conflicts.ts); new row: crossed the 1500 unlisted cap in wave 15 P7.4 #5461: set-time validation of think.pages_budget_chars / think.excerpt_ceiling_chars (range + parser live in core/think/pages-budget.ts), mirroring the cycle.consolidate.cluster_threshold hook; +1 wave 16 G5.1 (#6495): set-time refusal hook for search.keyword_statement_timeout_ms (check lives in commands/config/keyword-timeout-value.ts); +1 wave 18b lane 5 (#5012 item 6): search.contextual_retrieval prints the existing-pages hint after the write (text lives in commands/config/contextual-mode-hint.ts); +1 #6712 PR 2: retired/rollback sync key dispatch line (logic in core/sync-config-keys.ts handleSyncKeyConfig); +1 #6865: sync.slug_conflicts.auto_remove boolean validation at set time (refusal text in repair/slug-autoheal.ts); +1 #6948: sync.origin_twins.auto_resolve boolean validation at set time (refusal text in repair/origin-twins-heal.ts); +2 #6795: config set chat_model/expansion_model help line and the model-pin import (shadow report and file-pin unset live in commands/config/model-pin-shadow.ts); +1 #6712 PR 4b: sync.admission set-time hook (value logic in commands/config/sync-admission-value.ts); +4 #7130: set-time refusal hook for sync.max_deletes / sync.max_delete_ratio (and .source.<id>) / purge.retention_hours (check lives in core/sync-reconcile.ts deleteSafetyConfigRefusal); +1 GBRA-150: sync.metafile_pages set-time route (body in config/sync-metafile-pages-value.ts); re-summed at the v0.60.330.0 merge (1520 measured); +2 #7242 minions.terminal_hook file-plane key and its set branch (logic in minions/terminal-hook.ts); +1 GBRA-161: generations.* set-time route (refusal in commands/config/generations-values.ts); +1 GBRA-207 #7630: sync.repo_path set-time refusal hook (refusal in core/sync-config-keys.ts syncRepoPathRefusal)src/commands/mcp-expose.ts 1519 ratchet hosted_option: Session carries the gbrain.io coaching notice on the first-receipt run and Tailscale/service friction exits (copy, refs and gating live in core/onboard/hosted-option.ts); +7 GBRA-199: --surface help lines, surfaceChosen option field and the advertise pass-through (registrationAdvertise in core/mcp-registration.ts)-src/core/behavior-change-notice.ts 1683 ratchet +4 train R: #7491/#7492 keyword_identifier_probe and keyword_slug_handles rows and their comment, #7175 keyword phrase row; the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +1 GBRA-156 #7593: private_pages_granted_sources row (re-summed at the 0.60.527.0 merge: 1574 + 1); +3 GBRA-200 comment, write-grant refusal and degraded-stamp rows (re-summed at the 0.60.562.0 merge: 1615 + 3); +2 GBRA-280 get_page selector-precedence row and comment (re-summed at the 0.60.569.0 merge: 1619 + 2); the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +2 GBRA-205 saved_facts_stems row and its comment (re-summed at the #7901 0.60.492.0 merge: 1541 + 2); +2 GBRA-205 search.query_facts_block default-on row and its approval comment (re-summed at the #7610 0.60.490.0 merge: 1539 + 2); +2 the #7900 content checkpoint host-move row (since TBD until the merge slot), +2 the #7897 private-hold sweep row (since TBD until the merge slot), +2 the #7880 ingest_capture and company-brain private-hold row (since TBD until the merge slot), +5 the frozen-source wave comment and four rows (#7868, #7850, #7869/#7870, #7871), +2 the #7848 visibility_noncanonical hold row (since TBD until the merge slot), +2 the #7846 extract_atoms session-source row (re-summed at the 0.60.481.0 merge: master 1524 + 2), +2 the #7805 synthesize session-source and #7841 visibility_not_applied rows (re-summed at the 0.60.480.0 merge: master 1522 + 2), +2 strict door planned-state row (#7705, re-summed at the 0.60.470.0 merge: master 1514 + 2), +2 Bun floor 1.4.4 row (#7644), the GBRA-95 RLS backfill row (+2), +3 rows for #7596 pass_interrupted, #7599 read-only serve and the --access=read-only ceiling, +1 G5 lane C trust_release row, +1 #7619 cli_flag_equals, +3 GBRA-207 #7630 relative-anchor and stalled-write rows, +2 the #7632 function search_path disclosure row and +2 the #7679 orphaned worktree refresh row (re-summed at the 0.60.471.0 merge: master 1516 + 2), +2 the #7814 retired v0.13.1 grandfather row, +2 the #7618 conversion withhold/progress/push row (master 1520 + 2); the behavior-change table split (#7607) retires this row; +4 GBRA-188 #7489: the wave comment and three rows (brain-first instructions, starter surface default, per-turn rule); +1 GBRA-188 plugin_turn_hook_gbra188 row; +1 GBRA-242 provider_key_rules_7959 row (#7959), +2 the GBRA-199 registration_lists_verbs row (since TBD until the merge slot); +2 GBRA-133 #7652: the #7611 pass_abandoned reader row and the lean read-only serve socket row (re-summed at the 0.60.503.0 merge: master 1555 + 2); +1 GBRA-243: the per-turn hook disclosure row (rows are data and cannot move); +4 GBRA-156 #7598 harness wave comment and rows (remote page cap, sources_not_readable refusal, sources add next step); +4 GBRA-156 #7601 search_quotes_transcript_rows comment and row; +1 GBRA-175 #7475 autopilot_restarts_serve_7475 row (re-summed at the #8012 merge: 1566 + 1); +3 #7997/#8014/#8015 rows (redaction markers, company db_only keep, ignored supabase_only scope); +2 #7199 (re-port of #7228) classic_drift_rescreen_7199 comment and row; +2 #7931 file_drift_agrees_7931 comment and row; +1 #7950 file_drift_slug_release_7950 row; +1 #7974 file_drift_followups_7974 row; +1 #8059 quoted_fence_marker_8059 row; +2 GBRA-247 #8009 provenance_repair_held_8009 and #7982 pass_transient_streak_7982 rows; +4 GBRA-247 #7973 plain_directory_sync_7973, #7988 managed_marker_own_directory_7988, #7985 former_binding_parked_group_7985 and settle_effects_retire_7985 rows Train S merge: 1570 base + 5 (master since the #8077 base) + 13 (#8077) = 1588.; +2 GST-687 remote_quotes_unverified_text_gst687 row and its comment (re-summed at the gate-ahead on train S 0.60.534.0: 1588 + 2); +2 #8377: the quote fence follow-ups row and its comment; +2 #8384: the quote fence follow-ups 2 row and its comment; +2 #8384 wave 3: the quote fence follow-ups 3 row and its comment; +5 GBRA-218 train M rows (A1 member_read_access_gbra218 and member_access_hatch_scope_gbra218, B shared_agent_audience_gbra231, A2 folder_access_rules_gbra218, folder_access_scoped_role_gbra218), re-summed at the train M merge of master v0.60.541.0: 1596 + 5 = 1601 measured; +3 GST-359 train C rows (C1 qm_attested_actor_gst359, C2 member_facts_gst359, D qm_memory_provider_gst359), re-summed at the train C merge of master v0.60.543.0: 1601 + 3 = 1604 measured; +2 #8424: hook_launcher_8424 row and its comment (rows are data and cannot move), re-summed at the #8418 v0.60.546.0 merge: 1604 + 2 = 1606 measured; +2 #8426: mcp_lane_launcher_8426 row and its comment (rows are data and cannot move); +2 GST-927: empty_nonstring_args_gst927 row and its comment, re-summed at the gate-ahead on master v0.60.550.0 plus #8420: 1610 measured; +2 GBRA-283 Wave A (#8460): engine_keyed_caches_gbra283 row and its comment (rows are data and cannot move); +2 GBRA-287: segmented_freeze_hold_gbra287 and segmented_reexport_gbra287 rows (rows are data and cannot move); +1 GST-1209: segmented_tiling_gst1209 row (rows are data and cannot move); +1 GST-1251: skillopt_loop_deprecated_gst1251 row (rows are data and cannot move); +1 GST-1209 follow-up: untiled_hold_repair_gst1209 row (rows are data and cannot move); +1 GBRA-283 B3a: embedded_scope_required_gbra283 row (rows are data and cannot move); re-summed at the train R merge with v0.60.574.0: 1623 + 4; +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move); re-summed at the memory train #8481 merge with v0.60.578.0 (1643 measured); +3 GBRA-253 #8109 rows (frontmatter_drift_write_8109, contacts_activity_advance_8109, contact_rows_dedupe_8109; rows are data and cannot move), re-summed at the master v0.60.581.0 merge: 1643 + 3 = 1646 measured; +3 #8123 part C rows: sync_write_through_off_writeback_7084, managed_sync_dry_run_counts_7087, frontmatter_missing_source_dir_7889 (since TBD until the merge slot; re-summed at the 0.60.583.0 merge: 1646 + 3); +4 PR B commit_ledger_prb, doctor_foreign_writers_prb and sources_guard_prb rows and their comment (rows are data and cannot move; since TBD until the merge slot); +1 PR B #8615: file_drift_held_needs_prefer_8615 row; +1 PR B #8617: refresh_source_changed_retry_8617 row; +1 PR B #8662: commit_push_checkout_not_a_source_8662 row (since TBD until the merge slot; rows are data and cannot move); +2 PR B refresh_barrier_prb and commit_push_base_prb rows (re-summed: 1658 measured); +3 convergence PR A: the wave comment and two rows (conversion_content_evidence_pr_a, git_gap_live_pages_pr_a; since TBD until the merge slot; rows are data and cannot move); re-summed at the gate-ahead on master v0.60.592.0 plus #8711: 1658 + 3 = 1661 measured; +4 GST-1094/GST-900 rows (memory_recall scope-read, member-bound acting_user, recall max_chars, unknown_param _meta-only) and +1 qm_scope_writes_gst1113 and +1 recall_question_terms_gst1304 rows (rows are data and cannot move), re-summed at the 0.60.595.0 slot merge: 1661 + 6; +1 GST-1582 refresh_barrier_import_gst1582 row (since TBD until the merge slot; rows are data and cannot move); +2 GST-1601 source_changed_origin_gst1601 and adopt_local_edits_gst1601 rows (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.596.0 merge: 1668 + 2; +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.599.0 merge: 1670 + 1; +2 GBRA-224 W1 release_channel_stable_default row and its comment; +1 GST-1623 refresh_barrier_later_write_gst1623 row (#8765; rows are data and cannot move); +5 #8766 GST-1623 items 4/6-9 and #8755: the wave comment and four rows (doctor_foreign_writers_partial_gst1623, commit_push_enclosing_repo_gst1623, owner_guard_fail_closed_gst1623, adopt_local_edits_hardening_8755) and +1 managed_sync_kind_reserved_8765 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on master v0.60.608.0 plus #8798: 1674 + 6; +1 GST-1853 refresh_barrier_aborted_refresh_sync_gst1853 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.613.0 merge: 1680 + 1; +1 GST-1674 refresh_refused_merge_recovery_gst1674 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.614.0 merge: 1681 + 1; +1 #8824/#8826/#8767: adopt_local_edits_replay_markers_8824 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8837: 1682 + 1+src/core/behavior-change-notice.ts 1684 ratchet +4 train R: #7491/#7492 keyword_identifier_probe and keyword_slug_handles rows and their comment, #7175 keyword phrase row; the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +1 GBRA-156 #7593: private_pages_granted_sources row (re-summed at the 0.60.527.0 merge: 1574 + 1); +3 GBRA-200 comment, write-grant refusal and degraded-stamp rows (re-summed at the 0.60.562.0 merge: 1615 + 3); +2 GBRA-280 get_page selector-precedence row and comment (re-summed at the 0.60.569.0 merge: 1619 + 2); the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +2 GBRA-205 saved_facts_stems row and its comment (re-summed at the #7901 0.60.492.0 merge: 1541 + 2); +2 GBRA-205 search.query_facts_block default-on row and its approval comment (re-summed at the #7610 0.60.490.0 merge: 1539 + 2); +2 the #7900 content checkpoint host-move row (since TBD until the merge slot), +2 the #7897 private-hold sweep row (since TBD until the merge slot), +2 the #7880 ingest_capture and company-brain private-hold row (since TBD until the merge slot), +5 the frozen-source wave comment and four rows (#7868, #7850, #7869/#7870, #7871), +2 the #7848 visibility_noncanonical hold row (since TBD until the merge slot), +2 the #7846 extract_atoms session-source row (re-summed at the 0.60.481.0 merge: master 1524 + 2), +2 the #7805 synthesize session-source and #7841 visibility_not_applied rows (re-summed at the 0.60.480.0 merge: master 1522 + 2), +2 strict door planned-state row (#7705, re-summed at the 0.60.470.0 merge: master 1514 + 2), +2 Bun floor 1.4.4 row (#7644), the GBRA-95 RLS backfill row (+2), +3 rows for #7596 pass_interrupted, #7599 read-only serve and the --access=read-only ceiling, +1 G5 lane C trust_release row, +1 #7619 cli_flag_equals, +3 GBRA-207 #7630 relative-anchor and stalled-write rows, +2 the #7632 function search_path disclosure row and +2 the #7679 orphaned worktree refresh row (re-summed at the 0.60.471.0 merge: master 1516 + 2), +2 the #7814 retired v0.13.1 grandfather row, +2 the #7618 conversion withhold/progress/push row (master 1520 + 2); the behavior-change table split (#7607) retires this row; +4 GBRA-188 #7489: the wave comment and three rows (brain-first instructions, starter surface default, per-turn rule); +1 GBRA-188 plugin_turn_hook_gbra188 row; +1 GBRA-242 provider_key_rules_7959 row (#7959), +2 the GBRA-199 registration_lists_verbs row (since TBD until the merge slot); +2 GBRA-133 #7652: the #7611 pass_abandoned reader row and the lean read-only serve socket row (re-summed at the 0.60.503.0 merge: master 1555 + 2); +1 GBRA-243: the per-turn hook disclosure row (rows are data and cannot move); +4 GBRA-156 #7598 harness wave comment and rows (remote page cap, sources_not_readable refusal, sources add next step); +4 GBRA-156 #7601 search_quotes_transcript_rows comment and row; +1 GBRA-175 #7475 autopilot_restarts_serve_7475 row (re-summed at the #8012 merge: 1566 + 1); +3 #7997/#8014/#8015 rows (redaction markers, company db_only keep, ignored supabase_only scope); +2 #7199 (re-port of #7228) classic_drift_rescreen_7199 comment and row; +2 #7931 file_drift_agrees_7931 comment and row; +1 #7950 file_drift_slug_release_7950 row; +1 #7974 file_drift_followups_7974 row; +1 #8059 quoted_fence_marker_8059 row; +2 GBRA-247 #8009 provenance_repair_held_8009 and #7982 pass_transient_streak_7982 rows; +4 GBRA-247 #7973 plain_directory_sync_7973, #7988 managed_marker_own_directory_7988, #7985 former_binding_parked_group_7985 and settle_effects_retire_7985 rows Train S merge: 1570 base + 5 (master since the #8077 base) + 13 (#8077) = 1588.; +2 GST-687 remote_quotes_unverified_text_gst687 row and its comment (re-summed at the gate-ahead on train S 0.60.534.0: 1588 + 2); +2 #8377: the quote fence follow-ups row and its comment; +2 #8384: the quote fence follow-ups 2 row and its comment; +2 #8384 wave 3: the quote fence follow-ups 3 row and its comment; +5 GBRA-218 train M rows (A1 member_read_access_gbra218 and member_access_hatch_scope_gbra218, B shared_agent_audience_gbra231, A2 folder_access_rules_gbra218, folder_access_scoped_role_gbra218), re-summed at the train M merge of master v0.60.541.0: 1596 + 5 = 1601 measured; +3 GST-359 train C rows (C1 qm_attested_actor_gst359, C2 member_facts_gst359, D qm_memory_provider_gst359), re-summed at the train C merge of master v0.60.543.0: 1601 + 3 = 1604 measured; +2 #8424: hook_launcher_8424 row and its comment (rows are data and cannot move), re-summed at the #8418 v0.60.546.0 merge: 1604 + 2 = 1606 measured; +2 #8426: mcp_lane_launcher_8426 row and its comment (rows are data and cannot move); +2 GST-927: empty_nonstring_args_gst927 row and its comment, re-summed at the gate-ahead on master v0.60.550.0 plus #8420: 1610 measured; +2 GBRA-283 Wave A (#8460): engine_keyed_caches_gbra283 row and its comment (rows are data and cannot move); +2 GBRA-287: segmented_freeze_hold_gbra287 and segmented_reexport_gbra287 rows (rows are data and cannot move); +1 GST-1209: segmented_tiling_gst1209 row (rows are data and cannot move); +1 GST-1251: skillopt_loop_deprecated_gst1251 row (rows are data and cannot move); +1 GST-1209 follow-up: untiled_hold_repair_gst1209 row (rows are data and cannot move); +1 GBRA-283 B3a: embedded_scope_required_gbra283 row (rows are data and cannot move); re-summed at the train R merge with v0.60.574.0: 1623 + 4; +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move); re-summed at the memory train #8481 merge with v0.60.578.0 (1643 measured); +3 GBRA-253 #8109 rows (frontmatter_drift_write_8109, contacts_activity_advance_8109, contact_rows_dedupe_8109; rows are data and cannot move), re-summed at the master v0.60.581.0 merge: 1643 + 3 = 1646 measured; +3 #8123 part C rows: sync_write_through_off_writeback_7084, managed_sync_dry_run_counts_7087, frontmatter_missing_source_dir_7889 (since TBD until the merge slot; re-summed at the 0.60.583.0 merge: 1646 + 3); +4 PR B commit_ledger_prb, doctor_foreign_writers_prb and sources_guard_prb rows and their comment (rows are data and cannot move; since TBD until the merge slot); +1 PR B #8615: file_drift_held_needs_prefer_8615 row; +1 PR B #8617: refresh_source_changed_retry_8617 row; +1 PR B #8662: commit_push_checkout_not_a_source_8662 row (since TBD until the merge slot; rows are data and cannot move); +2 PR B refresh_barrier_prb and commit_push_base_prb rows (re-summed: 1658 measured); +3 convergence PR A: the wave comment and two rows (conversion_content_evidence_pr_a, git_gap_live_pages_pr_a; since TBD until the merge slot; rows are data and cannot move); re-summed at the gate-ahead on master v0.60.592.0 plus #8711: 1658 + 3 = 1661 measured; +4 GST-1094/GST-900 rows (memory_recall scope-read, member-bound acting_user, recall max_chars, unknown_param _meta-only) and +1 qm_scope_writes_gst1113 and +1 recall_question_terms_gst1304 rows (rows are data and cannot move), re-summed at the 0.60.595.0 slot merge: 1661 + 6; +1 GST-1582 refresh_barrier_import_gst1582 row (since TBD until the merge slot; rows are data and cannot move); +2 GST-1601 source_changed_origin_gst1601 and adopt_local_edits_gst1601 rows (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.596.0 merge: 1668 + 2; +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.599.0 merge: 1670 + 1; +2 GBRA-224 W1 release_channel_stable_default row and its comment; +1 GST-1623 refresh_barrier_later_write_gst1623 row (#8765; rows are data and cannot move); +5 #8766 GST-1623 items 4/6-9 and #8755: the wave comment and four rows (doctor_foreign_writers_partial_gst1623, commit_push_enclosing_repo_gst1623, owner_guard_fail_closed_gst1623, adopt_local_edits_hardening_8755) and +1 managed_sync_kind_reserved_8765 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on master v0.60.608.0 plus #8798: 1674 + 6; +1 GST-1853 refresh_barrier_aborted_refresh_sync_gst1853 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.613.0 merge: 1680 + 1; +1 GST-1674 refresh_refused_merge_recovery_gst1674 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.614.0 merge: 1681 + 1; +1 #8824/#8826/#8767: adopt_local_edits_replay_markers_8824 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8837: 1682 + 1; +1 refresh_publish_diverged_default_gbra386 row (since TBD until the merge slot; rows are data and cannot move)diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex bca4cd210e..9e398da54b 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1485,6 +1485,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.611.0', id: 'managed_sync_kind_reserved_8765', text: 'A page write that passes a `kind` starting with `managed_sync_` (for example `capture` with `kind: managed_sync_import`) is now refused `invalid_params` and writes nothing: that prefix is reserved for managed sync, and with `persistence.refresh_barrier` on a waiting write now tells sync\'s own imports apart from later writes by the operation that wrote them, not by the kind. Use another kind, or drop `kind`.' },{ since: '0.60.614.0', id: 'refresh_barrier_aborted_refresh_sync_gst1853', text: 'While a checkout\'s last `gbrain sources refresh` ended without completing (aborted, abandoned, or rolled back after its process died), every refresh run on the owner host, including one refused `refresh_diverged`, now ends by running the managed `--no-pull` sync of each source behind the checkout HEAD, listed in its `synced` (a refusal\'s message names them). With `persistence.refresh_barrier` on, a write held behind that refresh for a commit sync had not imported is therefore decided in that run instead of waiting for a later refresh: a `put_page` with `expected_revision` ends `revision_conflict`, a blind one lands and names what it replaced in `supersedes`, and a `remember` or `add_timeline_entry` applies on top.' },{ since: '0.60.608.0', id: 'refresh_barrier_later_write_gst1623', text: 'With `persistence.refresh_barrier` on, a write that waited behind a refresh or an import (other than a `remember` or `add_timeline_entry`, which still applies on top) now ends `revision_conflict` instead of applying when a later write to the same page committed first, which a consumer from an older release can cause; read the page again and resubmit with a new `request_id`. A write held again and again behind imports now expires once it has waited four wait limits (at least 4 hours) since its admission, even when each hold is shorter than one wait limit. With the barrier on or off, a plain-git commit that lands on the start commit right before a refresh merges makes git refuse the fast-forward, and the refresh now ends `refresh_source_changed` with the fence lifted and the commit kept, instead of leaving the checkout `recovery_required`; one that lands right after the merge is recorded and synced.' },+ { since: '0.60.616.0', id: 'refresh_publish_diverged_default_gbra386', text: 'A diverged managed checkout now publishes its local commits on `gbrain sources refresh` by default when the worktree\'s Git durability is on: `sources.refresh_publish_diverged` unset now means on there (it used to mean off), merged with the upstream in memory, never rebased or forced. Every automatic publish first scans the blobs the local commits added and refuses `refresh_diverged` naming the file, line and rule when one looks like a secret. Unset with durability not on still refuses, naming `gbrain sources writer git-durability <source> --enable`; `false` turns it off. The keep-checkout publish now runs the checkout\'s pre-push hook when it pushes HEAD itself as a fast-forward.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/config-runtime-keys.ts b/src/core/config-runtime-keys.tsindex 284bebaf08..1a14786738 100644--- a/src/core/config-runtime-keys.ts+++ b/src/core/config-runtime-keys.ts@@ -20,7 +20,7 @@ export const RUNTIME_READER_CONFIG_KEYS: readonly string[] = ['context.hot_memory.session_only', // facts/meta-hook.ts, read by the turn_context and context_pack IPC handlers: hot memory never falls back to other sessions' facts, default off'serve.cli_socket', // config.ts loadConfigWithEngine (snapshot only) → serve.ts: a Postgres serve answers CLI reads over a private Unix socket, default off'sources.refresh_fetch_timeout_ms', 'sources.refresh_drain_wait_ms', // persistence/worktree-refresh.ts: refresh fetch bound (default 120 s) and drain wait (default 60 s), in ms- 'sources.refresh_publish_diverged', // persistence/worktree-refresh.ts (#7686): refresh publishes a diverged checkout's local commits merged with the upstream before fast-forwarding, default off+ 'sources.refresh_publish_diverged', // persistence/worktree-refresh.ts (#7686): refresh publishes a diverged checkout's local commits merged with the upstream before fast-forwarding; unset = on when Git durability is on'serve.vector_prewarm', // config.ts loadConfigWithEngine (snapshot only) → serve.ts: a Postgres serve prewarms the HNSW indexes into shared_buffers at start when they fit, default off'mcp.stdio_member', // access/caller.ts (GBRA-218): binds a local stdio MCP server to one member; unbound, stdio reads no page that names readers'persistence.adopt_quiet_ms', // persistence/local-edit-adoption.ts (GST-1601): how long a local edit must be quiet before it is adopted, default 5000diff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.tsindex d8ecead6a5..436380ea90 100644--- a/src/core/git/commit-push.ts+++ b/src/core/git/commit-push.ts@@ -938,7 +938,7 @@ function publish(ctx: Ctx, start: string, resolutions: Map<string, Resolution> |if (attempt) Atomics.wait(sleeper, 0, 0, Math.min(2000, 50 * 2 ** attempt) + Math.floor(Math.random() * 100));let remoteTip = bound && !isAncestor(ctx.root, bound, candidate) ? bound : null;if (!remoteTip) {- const push = remoteGit(ctx.root, 'push', [...(ctx.keepCheckout ? ['--no-verify'] : []), ...(bound ? [`--force-with-lease=${ctx.mergeRef}:${bound}`] : []), '--', ctx.remote, `${candidate}:${ctx.mergeRef}`]);+ const push = remoteGit(ctx.root, 'push', [...(ctx.keepCheckout && candidate !== start ? ['--no-verify'] : []), ...(bound ? [`--force-with-lease=${ctx.mergeRef}:${bound}`] : []), '--', ctx.remote, `${candidate}:${ctx.mergeRef}`]);if (push.code === 0) return { sha: candidate, integrated, confirmed: 'push', ...notes() };lastError = push.stderr.trim();if (remoteContains(ctx, candidate)) return onRemote();diff --git a/src/core/git/range-secret-scan.ts b/src/core/git/range-secret-scan.tsnew file mode 100644index 0000000000..d90bcf6afc--- /dev/null+++ b/src/core/git/range-secret-scan.ts@@ -0,0 +1,59 @@+/**+ * Secret scan over the commits an automatic publish would push. A push from a checkout gbrain did not write (a script's+ * plain `git commit`) never passed the write path's scan, so before refresh publishes a diverged checkout on its own every+ * blob a commit in `base..head` adds or changes is scanned once with the workspace allowlist (`.gbrain-scan-allow`).+ * Findings carry the path, line, rule and fingerprint, never the matched value. Merge commits are not listed (their+ * parents' blobs are), binary and over-cap blobs are skipped like scanFiles skips them.+ */+import { spawn } from 'node:child_process';+import { gitChildEnv } from '../git-env.ts';+import { loadWorkspaceAllowlist, pathAllowlisted } from '../secret-scan-allowlist.ts';+import { looksBinaryBuffer, scanText, SCAN_MAX_FILE_BYTES } from '../secret-scan.ts';++export interface RangeSecretFinding { path: string; commit: string; line: number; pattern: string; fingerprint: string }++function run(root: string, args: string[], input?: string): Promise<{ code: number; stdout: Buffer }> {+ return new Promise(resolve => {+ const child = spawn('git', ['-C', root, '-c', 'core.quotePath=false', ...args], { env: gitChildEnv({ GIT_TERMINAL_PROMPT: '0' }), stdio: ['pipe', 'pipe', 'ignore'] });+ const chunks: Buffer[] = [];+ child.stdout.on('data', (chunk: Buffer) => chunks.push(chunk));+ child.on('error', () => resolve({ code: -1, stdout: Buffer.alloc(0) }));+ child.on('close', code => resolve({ code: code ?? -1, stdout: Buffer.concat(chunks) }));+ child.stdin.end(input ?? '');+ });+}++/** Findings in the blobs `base..head` adds or changes; null when git cannot list or read them (callers refuse). */+export async function scanCommitRange(root: string, base: string, head: string): Promise<RangeSecretFinding[] | null> {+ const log = await run(root, ['log', '--no-renames', '--raw', '--no-abbrev', '--format=commit %H', `${base}..${head}`, '--']);+ if (log.code !== 0) return null;+ const blobs = new Map<string, { path: string; commit: string }>();+ let commit = '';+ for (const line of log.stdout.toString('utf8').split('\n')) {+ if (line.startsWith('commit ')) { commit = line.slice(7).trim(); continue; }+ const raw = /^:\d+ (\d+) [0-9a-f]+ ([0-9a-f]+) [AMT]\t(.+)$/.exec(line);+ if (raw && raw[1] !== '160000' && !/^0+$/.test(raw[2]) && !blobs.has(raw[2])) blobs.set(raw[2], { path: raw[3], commit });+ }+ if (!blobs.size) return [];+ const allowlist = loadWorkspaceAllowlist(root);+ const wanted = [...blobs].filter(([, at]) => !pathAllowlisted(at.path, allowlist));+ const sizes = await run(root, ['cat-file', '--batch-check=%(objectname) %(objectsize)'], wanted.map(([sha]) => sha).join('\n') + '\n');+ if (sizes.code !== 0) return null;+ const small = new Set(sizes.stdout.toString('utf8').split('\n').map(line => line.split(' ')).filter(([, size]) => Number(size) <= SCAN_MAX_FILE_BYTES).map(([sha]) => sha));+ const read = wanted.filter(([sha]) => small.has(sha));+ if (!read.length) return [];+ const batch = await run(root, ['cat-file', '--batch'], read.map(([sha]) => sha).join('\n') + '\n');+ if (batch.code !== 0) return null;+ const out: RangeSecretFinding[] = [];+ let at = 0;+ for (const [sha, where] of read) {+ const headerEnd = batch.stdout.indexOf(0x0a, at);+ const [name, , size] = batch.stdout.subarray(at, headerEnd).toString('utf8').split(' ');+ if (name !== sha) return null;+ const body = batch.stdout.subarray(headerEnd + 1, headerEnd + 1 + Number(size));+ at = headerEnd + 1 + Number(size) + 1;+ if (looksBinaryBuffer(body)) continue;+ for (const f of scanText(body.toString('utf8'), { allowlist })) out.push({ path: where.path, commit: where.commit, line: f.line, pattern: f.pattern, fingerprint: f.fingerprint });+ }+ return out;+}diff --git a/src/core/persistence/worktree-refresh.ts b/src/core/persistence/worktree-refresh.tsindex bc57c84065..bbf0b54742 100644--- a/src/core/persistence/worktree-refresh.ts+++ b/src/core/persistence/worktree-refresh.ts@@ -50,6 +50,8 @@ import { classifyPgAccessError } from '../pg-access-classify.ts';import { classifyOriginUniqueViolation } from './origin-guard.ts';import { refreshProgress, refreshRetryHint, seconds } from './refresh-retry-hint.ts';import { ledgerLocation, readLedger } from '../git/commit-ledger.ts';+import { scanCommitRange } from '../git/range-secret-scan.ts';+import { gitDurabilityPolicy } from './git-durability-policy.ts';export interface WorktreeRefreshRow {id: string; worktree_id: string; source_ids: string[]; principal_id: string; owner_epoch: string | number;@@ -396,11 +398,11 @@ interface Plan {overlap: string[]; preserved: string[]; incoming: number; published?: WorktreeRefreshResult['published'];}-/** #7686: standing consent, default off, to publish a diverged checkout's local commits before the fast-forward. */+/** #7686: publish a diverged checkout's local commits before the fast-forward. Unset means on when the worktree's Git durability is on; false turns it off; true publishes even with durability off. */export const REFRESH_PUBLISH_DIVERGED_KEY = 'sources.refresh_publish_diverged';/** Steps 1.3/1: refusals before any database state; fetch moves only remote-tracking refs. */-async function precheck(engine: BrainEngine, git: Git, sourceId: string, fetchTimeoutMs: number, publishDiverged = false): Promise<Plan> {+async function precheck(engine: BrainEngine, git: Git, sourceId: string, fetchTimeoutMs: number, publishDiverged: false | 'default' | 'explicit' = false): Promise<Plan> {if (!await managedPersistenceEnabled(engine)) throw refusal('refresh_not_managed','This brain is not managed, so gbrain sync pulls the checkout itself; there is no worktree fence to coordinate.', `gbrain sync --source ${sourceId}`);const binding = await getWorktreeBinding(engine, sourceId, existingHostIdFor(engine));@@ -491,6 +493,13 @@ async function precheck(engine: BrainEngine, git: Git, sourceId: string, fetchTiconst base = (await read(['merge-base', oldHead, targetHead], 1)).stdout.trim() || oldHead;const incoming = await dirtyOverlap(git, root, base, targetHead);if (incoming.overlap.length) throw dirtyRefusal(sourceId, incoming.overlap);+ if (publishDiverged === 'default' && !(await gitDurabilityPolicy(binding, root)).durable) throw await divergedRefusal(git, root, sourceId, upstreamRef, oldHead, targetHead,+ 'Git durability is not on for this worktree, so nothing leaves it through Git on its own.',+ ` To let every refresh publish it on its own, the user can turn Git durability on (gbrain sources writer git-durability ${sourceId} --enable) or run gbrain config set ${REFRESH_PUBLISH_DIVERGED_KEY} true.`);+ const secrets = await scanCommitRange(root, targetHead, oldHead);+ if (!secrets || secrets.length) throw await divergedRefusal(git, root, sourceId, upstreamRef, oldHead, targetHead, !secrets+ ? `gbrain could not read the local commits to scan them for secrets (git log or git cat-file failed).`+ : `Its local commits hold ${secrets.length} value(s) that look like secrets: ${secrets.slice(0, 10).map(s => `${s.path}:${s.line} (${s.pattern}, ${s.commit.slice(0, 7)})`).join(', ')}${secrets.length > 10 ? ', ...' : ''}. Remove them from those commits, or allowlist a false positive by its fingerprint in .gbrain-scan-allow.`);const localCommits = Number((await read(['rev-list', '--count', `${targetHead}..${oldHead}`])).stdout.trim()) || 0;const pushed = await publishInChild(root, sourceId, targetHead);const published = { sha: pushed.sha ?? targetHead, local_commits: localCommits, integrated: pushed.integrated,@@ -535,13 +544,13 @@ async function publishInChild(root: string, sourceId: string, checkedUpstream: s* upstream into HEAD in memory and pushes the merge (refusing on a conflict, never touching the checkout), after which HEAD* is an ancestor of the upstream and the refresh fast-forwards. It publishes the local commits, so the user decides.*/-async function divergedRefusal(git: Git, root: string, sourceId: string, upstreamRef: string, oldHead: string, targetHead: string, rewrite?: string): Promise<OperationError> {+async function divergedRefusal(git: Git, root: string, sourceId: string, upstreamRef: string, oldHead: string, targetHead: string, rewrite?: string, hint?: string): Promise<OperationError> {const count = Number((await git(['-C', root, 'rev-list', '--count', `${targetHead}..${oldHead}`])).stdout.trim()) || 0;const local = count ? `${count} local commit(s)` : 'the local commits';const argv = ['gbrain', 'git', 'commit-push', '--push-only', '--keep-checkout', '--path', root, '--json'];const error = refusal('refresh_diverged',`The checkout HEAD ${oldHead} is not an ancestor of ${upstreamRef} (${targetHead}); a fast-forward is impossible and nothing changed.${rewrite ? ` ${rewrite} ${REFRESH_PUBLISH_DIVERGED_KEY} does not publish it on its own.` : ''}`,- `Publish ${local} merged with ${upstreamRef}: ${argv.map(q).join(' ')} (it merges in memory, refuses on a conflict and never moves the checkout), then retry gbrain sources refresh ${sourceId}. Ask the user first, because it pushes those commits (git -C ${q(root)} log --stat ${upstreamRef}..HEAD lists them). gbrain sources reclone ${sourceId} replaces the checkout instead and drops them.${rewrite ? '' : ` To let every refresh publish a diverged checkout this way on its own, the user can run gbrain config set ${REFRESH_PUBLISH_DIVERGED_KEY} true.`}`);+ `Publish ${local} merged with ${upstreamRef}: ${argv.map(q).join(' ')} (it merges in memory, refuses on a conflict and never moves the checkout), then retry gbrain sources refresh ${sourceId}. Ask the user first, because it pushes those commits (git -C ${q(root)} log --stat ${upstreamRef}..HEAD lists them). gbrain sources reclone ${sourceId} replaces the checkout instead and drops them.${hint ?? (rewrite ? '' : ` To let every refresh publish a diverged checkout this way on its own, the user can run gbrain config set ${REFRESH_PUBLISH_DIVERGED_KEY} true.`)}`);error.fix = { argv, consent: [], actor: 'user', ask_user: true, requires_exclusive: false,why: `HEAD has ${local} that ${upstreamRef} lacks while ${upstreamRef} moved on; pushing HEAD merged with it makes HEAD an ancestor of the upstream, so the refresh can fast-forward.`,user_message: rewrite ? `The checkout of source ${sourceId} cannot be published on its own: ${rewrite} Push this checkout's history merged with the remote anyway, or replace the checkout with gbrain sources reclone ${sourceId}?`@@ -886,7 +895,8 @@ async function runRefresh(engine: BrainEngine, sourceId: string, opts: RefreshOpasync function refreshOnce(engine: BrainEngine, sourceId: string, opts: RefreshOptions, fetchTimeoutMs: number, waitDrainMs: number, syncBudgetMs: number): Promise<WorktreeRefreshResult> {let published: WorktreeRefreshResult['published'];return withGit<WorktreeRefreshResult>(async git => {- const publishDiverged = !opts.dryRun && isTruthy(await engine.getConfig(REFRESH_PUBLISH_DIVERGED_KEY));+ const configured = opts.dryRun ? 'false' : await engine.getConfig(REFRESH_PUBLISH_DIVERGED_KEY);+ const publishDiverged = configured === null || configured === undefined || configured.trim() === '' ? 'default' : isTruthy(configured) ? 'explicit' : false;const plan = await precheck(engine, git, sourceId, fetchTimeoutMs, publishDiverged);published = plan.published;const base = { refresh_id: null, worktree_id: plan.binding.worktree_id, source_ids: plan.members, old_head: plan.oldHead,diff --git a/test/guarded-publish.test.ts b/test/guarded-publish.test.tsnew file mode 100644index 0000000000..2045f2f845--- /dev/null+++ b/test/guarded-publish.test.ts@@ -0,0 +1,73 @@+/**+ * Guards on an automatic publish of commits gbrain did not write: the commit-range secret scan+ * (scanCommitRange) and the pre-push hook on a keep-checkout publish that is a plain fast-forward.+ * Protects: a value that looks like a secret in any blob a local commit added is found even when a later+ * commit removed it, with the path, line and rule but never the value; a fingerprint in .gbrain-scan-allow+ * and binary blobs are skipped; a keep-checkout publish of HEAD itself runs the checkout's pre-push hook, so+ * a refusing hook stops the push.+ * Seams: none; real repositories and a bare remote.+ */+import { afterAll, expect, test } from 'bun:test';+import { execFileSync } from 'node:child_process';+import { chmodSync, existsSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { commitAndPush } from '../src/core/git/commit-push.ts';+import { scanCommitRange } from '../src/core/git/range-secret-scan.ts';++const dir = realpathSync(mkdtempSync(join(tmpdir(), 'gbrain-guarded-publish-')));+afterAll(() => rmSync(dir, { recursive: true, force: true }));+const git = (root: string, ...args: string[]) => execFileSync('git', ['-C', root, '-c', 'user.name=Example', '-c', '[email protected]',+ '-c', 'commit.gpgsign=false', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();+const token = 'ghp_' + 'Zt4q'.repeat(9);++function repo(name: string): { remote: string; root: string; base: string } {+ const remote = join(dir, `${name}.git`), root = join(dir, name);+ execFileSync('git', ['init', '-q', '--bare', '-b', 'main', remote]);+ execFileSync('git', ['clone', '-q', remote, root], { stdio: 'ignore' });+ git(root, 'checkout', '-q', '-b', 'main');+ writeFileSync(join(root, 'readme.md'), 'start\n');+ git(root, 'add', '.'); git(root, 'commit', '-qm', 'init'); git(root, 'push', '-q', '-u', 'origin', 'main');+ return { remote, root, base: git(root, 'rev-parse', 'HEAD') };+}+const commit = (root: string, file: string, content: string | Buffer) => {+ writeFileSync(join(root, file), content); git(root, 'add', file); git(root, 'commit', '-qm', `edit ${file}`);+ return git(root, 'rev-parse', 'HEAD');+};++test('a secret a local commit added is found even after a later commit removed it, without its value', async () => {+ const r = repo('scan');+ const added = commit(r.root, 'notes.md', `line one\nDeploy token ${token}\n`);+ commit(r.root, 'notes.md', 'line one\nredacted\n');+ commit(r.root, 'clean.md', 'nothing here\n');+ const findings = await scanCommitRange(r.root, r.base, 'HEAD');+ expect(findings).toHaveLength(1);+ expect(findings![0]).toMatchObject({ path: 'notes.md', commit: added, line: 2 });+ expect(JSON.stringify(findings)).not.toContain(token);+ expect(await scanCommitRange(r.root, 'HEAD', 'HEAD')).toEqual([]);+});++test('a fingerprint in .gbrain-scan-allow and a binary blob are skipped; an unreadable range is null', async () => {+ const r = repo('allow');+ commit(r.root, 'data.bin', Buffer.concat([Buffer.from([0, 1, 2]), Buffer.from(token)]));+ commit(r.root, 'notes.md', `Deploy token ${token}\n`);+ const [finding] = (await scanCommitRange(r.root, r.base, 'HEAD'))!;+ expect(finding.path).toBe('notes.md');+ writeFileSync(join(r.root, '.gbrain-scan-allow'), `${finding.fingerprint}\n`);+ expect(await scanCommitRange(r.root, r.base, 'HEAD')).toEqual([]);+ expect(await scanCommitRange(r.root, r.base, 'no-such-ref')).toBeNull();+});++test('a keep-checkout publish of HEAD runs the pre-push hook, and a refusing hook stops the push', () => {+ const r = repo('hook');+ const marker = join(dir, 'hook-ran');+ const hook = join(r.root, '.git', 'hooks', 'pre-push');+ writeFileSync(hook, `#!/bin/sh\ntouch '${marker}'\nexit 1\n`); chmodSync(hook, 0o755);+ commit(r.root, 'page.md', 'a page\n');+ expect(() => commitAndPush({ repo: r.root, cwd: r.root, paths: [], pushOnly: true, keepCheckout: true })).toThrow(/no push to origin\/main was confirmed/);+ expect(existsSync(marker)).toBe(true);+ expect(git(r.remote, 'rev-parse', 'refs/heads/main')).toBe(r.base);+ writeFileSync(hook, '#!/bin/sh\nexit 0\n');+ expect(commitAndPush({ repo: r.root, cwd: r.root, paths: [], pushOnly: true, keepCheckout: true })).toMatchObject({ outcome: 'pushed', checkout: 'unchanged' });+ expect(git(r.remote, 'rev-parse', 'refs/heads/main')).toBe(git(r.root, 'rev-parse', 'HEAD'));+});diff --git a/test/refresh-publish-diverged-7686.test.ts b/test/refresh-publish-diverged-7686.test.tsindex 634ba1099d..616dfff846 100644--- a/test/refresh-publish-diverged-7686.test.ts+++ b/test/refresh-publish-diverged-7686.test.ts@@ -2,11 +2,13 @@* #7686: an opt-in refresh publishes a diverged managed checkout before it* fast-forwards.*- * Protects: with `sources.refresh_publish_diverged` on (standing consent, default- * off) a refresh of a checkout that has local commits while its upstream moved+ * Protects: with `sources.refresh_publish_diverged` on (explicitly, or unset on a+ * worktree whose Git durability is on) a refresh of a checkout that has local commits while its upstream moved* on pushes HEAD merged with the upstream in memory (the keep-checkout publish,* which never moves the checkout), then fast-forwards, keeping the local commits;- * with the setting off it refuses `refresh_diverged` as before; a conflicting path+ * with the setting false, or unset while Git durability is not on, it refuses+ * `refresh_diverged`; local commits holding a value that looks like a secret refuse+ * before anything is pushed; a conflicting path* refuses `integrate_conflict` naming the path and changes nothing; an uncommitted* edit on an incoming path refuses `refresh_dirty` before anything is pushed; a dry* run never publishes; with gbrain.quarantine on, the refresh names the parked@@ -84,7 +86,7 @@ function diverge(f: RefreshFixture, local = { path: 'beta/local.md', content: pareturn f.head();}-test('the setting is a registered knob, default off', () => {+test('the setting is a registered knob (unset means on when Git durability is on)', () => {expect(REFRESH_PUBLISH_DIVERGED_KEY).toBe('sources.refresh_publish_diverged');expect(KNOWN_CONFIG_KEYS).toContain(REFRESH_PUBLISH_DIVERGED_KEY);expect(KNOWN_CONFIG_KEYS).toEqual(expect.arrayContaining(['sources.refresh_fetch_timeout_ms', 'sources.refresh_drain_wait_ms']));@@ -117,19 +119,50 @@ test('setting on: the text result names the publish', () => each(async f => {expect(out.join('\n')).toContain('Refresh completed');}), 120_000);-test('setting off (unset or false): the refresh refuses refresh_diverged, pushes nothing and names the setting', () => each(async f => {+test('setting off (false, or unset while Git durability is not on): the refresh refuses refresh_diverged, pushes nothing and names the way to turn it on', () => each(async f => {const local = diverge(f);const remote = remoteHead(f);for (const value of [null, 'false']) {if (value !== null) await f.engine.setConfig(REFRESH_PUBLISH_DIVERGED_KEY, value);const error = await refusedWith(refreshWorktree(f.engine, f.alpha), 'refresh_diverged');expect(error.suggestion).toContain('gbrain config set sources.refresh_publish_diverged true');+ if (value === null) {+ expect(error.message).toContain('Git durability is not on for this worktree');+ expect(error.suggestion).toContain(`gbrain sources writer git-durability ${f.alpha} --enable`);+ }expect(remoteHead(f)).toBe(remote);expect(f.head()).toBe(local);expect(await f.refreshRows()).toEqual([]);}}), 120_000);+test('setting unset with Git durability on: a diverged refresh publishes the local commits, then fast-forwards', () => each(async f => {+ const local = diverge(f);+ await f.engine.executeRaw(`UPDATE persistence_host_bindings SET git_durability='enabled' WHERE local_path=$1`, [f.root]);+ try {+ const done = await refreshWorktree(f.engine, f.alpha);+ expect(done).toMatchObject({ status: 'completed', old_head: local, published: { local_commits: 1, integrated: 1 } });+ expect(remoteHead(f)).toBe(done.published!.sha);+ git(f.root, 'merge-base', '--is-ancestor', local, 'HEAD');+ } finally {+ await f.engine.executeRaw(`UPDATE persistence_host_bindings SET git_durability=NULL WHERE local_path=$1`, [f.root]);+ }+}), 120_000);++test('setting on: local commits holding a value that looks like a secret refuse refresh_diverged naming the file and rule, never the value, and nothing is pushed', () => each(async f => {+ const token = 'ghp_' + 'Zt4q'.repeat(9);+ const local = diverge(f, { path: 'beta/local.md', content: page('Local', `Deploy token ${token}`) });+ git(f.root, 'rm', '-q', 'beta/local.md'); git(f.root, 'commit', '-qm', 'remove it again');+ const remote = remoteHead(f);+ await f.engine.setConfig(REFRESH_PUBLISH_DIVERGED_KEY, 'true');+ const error = await refusedWith(refreshWorktree(f.engine, f.alpha), 'refresh_diverged');+ expect(error.message).toContain('look like secrets: beta/local.md:');+ expect(error.message).toContain(local.slice(0, 7));+ expect(`${error.message}${error.suggestion}`).not.toContain(token);+ expect(remoteHead(f)).toBe(remote);+ expect(await f.refreshRows()).toEqual([]);+}), 120_000);+test('setting on: a conflicting path refuses integrate_conflict naming it, and nothing is pushed, fenced or moved', () => each(async f => {const local = diverge(f, { path: 'alpha/two.md', content: page('Alpha two', 'Local side.') });const remote = remoteHead(f);