Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(#6530): verify battery (fix text, doc size caps, structural manifest)
garrytanb3af41fce912
diff --git a/docs/TESTING.md b/docs/TESTING.mdindex d5c014196e..6697a4f5d2 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -1042,30 +1042,6 @@ retire another phrase, add a row to `RETIRED`. Fixtures:scanned location); every pattern and the exemptions are driven in`test/scripts/check-retired-phrases.test.ts`.-#### Shared-tree git guard--`scripts/check-shared-tree-git.sh` (`bun run check:shared-tree-git`, in-`bun run verify`, under a second) keeps agent-facing text from teaching git-commands that are unsafe in a brain checkout several agents share (#6530).-It scans `skills/`, `recipes/`, `templates/`, `docs/`, `plugin/`,-`plugin-variants/` (`*.md`, `*.template`, `*.sh`) and `AGENTS.md`,-`BOOTSTRAP_FOR_AGENTS.md` and `INSTALL_FOR_AGENTS.md`; in markdown only fenced-code and inline code spans count. It flags `git pull --rebase`,-`--autostash`, `git stash` (except `store`, `list`, `show`), `git add -A`,-`--all` or `.` without `--`, `git commit -a`, `git reset --hard`, force pushes-and any other `git push` except `--dry-run`. A line that must name one carries-`# gbrain-allow-shared-tree-git: <reason>` on the same line, an-`<!-- gbrain-allow-shared-tree-git: <reason> -->` line before it, or sits in a-`-begin: <reason>` / `-end` region; a marker without a reason fails. Not-scanned: the generated `docs/guides/error-codes.md`, the contributor docs-about the gbrain source repo (`docs/RELEASING.md`, `docs/TESTING.md`,-`docs/contributing/`) and historical records. It also requires the Multi-agent-rules block to be identical in the three agent docs. The safe replacement and-the full rules: [shared-checkout git](guides/shared-checkout-git.md).-Fixtures: `test/fixtures/guards/check-shared-tree-git.sh/`; every form, the-markers and the exemptions are driven in-`test/scripts/check-shared-tree-git.test.ts`.-#### Bash 3.2 parse guardmacOS ships GNU bash 3.2.57 as `/bin/bash`, and its parser rejects shapesdiff --git a/docs/architecture/key-files/files-and-sync-1.md b/docs/architecture/key-files/files-and-sync-1.mdindex 15503c8fd6..62fbc36298 100644--- a/docs/architecture/key-files/files-and-sync-1.md+++ b/docs/architecture/key-files/files-and-sync-1.md@@ -5,7 +5,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `src/core/audit-week-file.ts` — single source of truth for ISO-week audit JSONL filename math. Exports `isoWeek(d)`, `isoWeekFilename(prefix, now?)`, `resolveAuditDir()` (honors `GBRAIN_AUDIT_DIR`). Year-boundary correctness pinned by tests at 2020-W53 (the 53-week year), 2025-W01 rolling in from 2024-12-30 (Monday), 2026-W01. Four call sites: `src/core/minions/handlers/shell-audit.ts`, `src/core/facts/phantom-audit.ts`, `src/core/audit-slug-fallback.ts`, `src/core/cycle/budget-meter.ts`. Each keeps its `compute<X>AuditFilename` thin wrapper.-- `src/core/brain-repo-durability.ts` + `src/commands/sources-harden.ts` — brain-repo git durability. `hardenBrainRepo(opts)` makes a brain's working tree durable, idempotently: divergence-safe pull, a LOCAL untracked `.git/hooks/post-commit` auto-push safety net (never committed — a pulled commit can't rewrite executed code next to the token; installed into the active `core.hooksPath` dir and excluded via `.git/info/exclude` when that dir is tracked), a committed `scripts/brain-commit-push.sh` that delegates to `gbrain git commit-push` (`src/core/git/commit-push.ts`, #6530: path-scoped commit under the short commit lock, push under the separate publish lock, remote commits merged in memory, checkout advanced fast-forward only; never `pull --rebase`, stash or reset) and refuses to exit 0 without a confirmed push (exit 4 maps to PUSH FAILED); without a capable CLI it does only a locked path-scoped commit plus a plain push; the hook runs the CLI path captured at harden with `--push-only --require-clean` in the background (it defers to a running push instead of waiting); both carry a `# gbrain-protocol: 2` line and harden refuses to downgrade a newer one, durability rules patched into the active resolver file (`findResolverFile` → RESOLVER.md > AGENTS.md; taxonomy rendered from the bundled `_brain-filing-rules.json`), a minimal DB-free pull cron (launchd/crontab running `gbrain sources pull --path <dir>` so it never opens the PGLite single-writer lock), and a push-probe verify (no heartbeat commit). Credential is REPO-scoped (`acceptPat` from `--pat-file`/`GBRAIN_GITHUB_PAT`, warns on loose perms; reuses an existing repo-local `credential.helper`, else a `0600` store wired via repo-local config); the token is redacted everywhere via `redactSecretsInText` and never enters the repo, remote URL, logs, or `DurabilityReport`. `unhardenBrainRepo` removes the cron/hook/credential wiring (ownership-fingerprinted); `sources remove` runs it only AFTER the source row's DELETE commits (a refused or raced delete leaves the scaffolding intact; post-commit teardown failure is loud but non-fatal). CLI: `gbrain sources harden <id|--all>` / `pull <id>|--path <dir>` / `unharden <id>`; auto-harden fires on `sources add --url ... --pat-file` for managed clones (`--no-harden` opts out). `sources pull --path` is dispatched in `src/cli.ts` BEFORE `connectEngine` so the cron stays DB-free. CLI-only (writes executables + an OS cron + a credential helper on the host); never exposed over MCP. `isDurabilityHardened(repoPath)` (the durability hook banner is installed) and `commitWriteThroughFile(repoPath, absPath, slug, action = 'write-through')` are the shared helpers every write-through sink (page write/delete, facts fence, timeline, lint --fix) uses to best-effort commit ONE file path-limited on a hardened repo — never throws, false on any failure; `action` only labels the subject (`gbrain: <action> <slug>`; `'delete write-through'` for removals). `isDurabilityHardenedAsync(repoPath)` is the owners' non-blocking probe (#6210: rejects `git_unavailable` when unsure); it and the persistence Git runner (`effect-git.ts`) spawn through `execFileBounded` (defined in the import-free `src/core/bounded-child-exec.ts` and re-exported here; `git-remote.ts` `pullRepo` shares it), which settles at its deadline or on abort from its own timer because Bun can drop a child's pipe events and, before 1.3.14, its exit event (oven-sh/bun#30301) when bun:test `expect().resolves/.rejects` re-enters the event loop; an unbounded wait there stranded `disposePersistenceConsumer` and hung every later test in the file (test: `test/bounded-child-exec.test.ts`). Tests: `test/brain-repo-durability.serial.test.ts`, `test/git-remote-durable.serial.test.ts`, `test/brain-durability-hook.serial.test.ts`, `test/durability-cron.test.ts`. `brain_remote_contains_commit` checks the exact `refs/heads/<branch>` at every effective push URL, fetches each advertised tip without writing `FETCH_HEAD`, and proves ancestry of the captured commit; branch existence, a different fetch destination, or a stale tracking ref is not enough. Probe diagnostics are suppressed, ambiguous URL resolution fails closed, and recovery is skipped if local HEAD has moved since the failed push. This check runs after a rejected push and after retry failure, logging `ok-already-on-remote` on confirmation; `getLastPushOutcome` recognizes it as success. Existing unmanaged installations must rerun `gbrain sources harden <source-id>` to refresh both the local hook and committed helper; upgrading the CLI alone does not rewrite those scripts. Managed worktrees retain the persistence outbox as their Git writer; generated legacy helpers refuse to bypass it. `GBRAIN_COMMIT_LOCK_WAIT_SECONDS` (alias `GBRAIN_PUSH_LOCK_WAIT_SECONDS`, default 60) bounds the commit-lock wait and `GBRAIN_PUBLISH_LOCK_WAIT_SECONDS` (default 300) a foreground publish's wait for another push; the hook never waits on the push lock (`push_deferred`: it leaves a request the running publisher honors after release). An unresolved `integrate_conflict` is recorded per checkout (`brain-integrate-conflict.json` under the git dir) and `getLastPushOutcome(branch, repo)` reports it. Tests: `test/git-commit-push-6530.serial.test.ts`.+- `src/core/brain-repo-durability.ts` + `src/commands/sources-harden.ts` — brain-repo git durability. `hardenBrainRepo(opts)` makes a brain's working tree durable, idempotently: divergence-safe pull, a LOCAL untracked `.git/hooks/post-commit` auto-push safety net (never committed — a pulled commit can't rewrite executed code next to the token; installed into the active `core.hooksPath` dir and excluded via `.git/info/exclude` when that dir is tracked), a committed `scripts/brain-commit-push.sh` delegating to `gbrain git commit-push` (`src/core/git/commit-push.ts`, #6530; guide `docs/guides/shared-checkout-git.md`) that never exits 0 without a confirmed push, and a hook running the harden-captured CLI with `--push-only --require-clean` (both `# gbrain-protocol: 2`; harden never downgrades), durability rules patched into the active resolver file (`findResolverFile` → RESOLVER.md > AGENTS.md; taxonomy rendered from the bundled `_brain-filing-rules.json`), a minimal DB-free pull cron (launchd/crontab running `gbrain sources pull --path <dir>` so it never opens the PGLite single-writer lock), and a push-probe verify (no heartbeat commit). Credential is REPO-scoped (`acceptPat` from `--pat-file`/`GBRAIN_GITHUB_PAT`, warns on loose perms; reuses an existing repo-local `credential.helper`, else a `0600` store wired via repo-local config); the token is redacted everywhere via `redactSecretsInText` and never enters the repo, remote URL, logs, or `DurabilityReport`. `unhardenBrainRepo` removes the cron/hook/credential wiring (ownership-fingerprinted); `sources remove` runs it only AFTER the source row's DELETE commits (a refused or raced delete leaves the scaffolding intact; post-commit teardown failure is loud but non-fatal). CLI: `gbrain sources harden <id|--all>` / `pull <id>|--path <dir>` / `unharden <id>`; auto-harden fires on `sources add --url ... --pat-file` for managed clones (`--no-harden` opts out). `sources pull --path` is dispatched in `src/cli.ts` BEFORE `connectEngine` so the cron stays DB-free. CLI-only (writes executables + an OS cron + a credential helper on the host); never exposed over MCP. `isDurabilityHardened(repoPath)` (the durability hook banner is installed) and `commitWriteThroughFile(repoPath, absPath, slug, action = 'write-through')` are the shared helpers every write-through sink (page write/delete, facts fence, timeline, lint --fix) uses to best-effort commit ONE file path-limited on a hardened repo — never throws, false on any failure; `action` only labels the subject (`gbrain: <action> <slug>`; `'delete write-through'` for removals). `isDurabilityHardenedAsync(repoPath)` is the owners' non-blocking probe (#6210: rejects `git_unavailable` when unsure); it and the persistence Git runner (`effect-git.ts`) spawn through `execFileBounded` (defined in the import-free `src/core/bounded-child-exec.ts` and re-exported here; `git-remote.ts` `pullRepo` shares it), which settles at its deadline or on abort from its own timer because Bun can drop a child's pipe events and, before 1.3.14, its exit event (oven-sh/bun#30301) when bun:test `expect().resolves/.rejects` re-enters the event loop; an unbounded wait there stranded `disposePersistenceConsumer` and hung every later test in the file (test: `test/bounded-child-exec.test.ts`). Tests: `test/brain-repo-durability.serial.test.ts`, `test/git-remote-durable.serial.test.ts`, `test/brain-durability-hook.serial.test.ts`, `test/durability-cron.test.ts`. `brain_remote_contains_commit` checks the exact `refs/heads/<branch>` at every effective push URL, fetches each advertised tip without writing `FETCH_HEAD`, and proves ancestry of the captured commit; branch existence, a different fetch destination, or a stale tracking ref is not enough. Probe diagnostics are suppressed, ambiguous URL resolution fails closed, and recovery is skipped if local HEAD has moved since the failed push. This check runs after a rejected push and after retry failure, logging `ok-already-on-remote` on confirmation; `getLastPushOutcome` recognizes it as success. Existing unmanaged installations must rerun `gbrain sources harden <source-id>` to refresh both the local hook and committed helper; upgrading the CLI alone does not rewrite those scripts. Managed worktrees retain the persistence outbox as their Git writer; generated legacy helpers refuse to bypass it. Locks, waits, outcomes and the per-checkout conflict record: the guide. Tests: `test/git-commit-push-6530.serial.test.ts`.- `src/core/content-sanity-literals.ts` — operator literal-substring loader. Reads `~/.gbrain/junk-substrings.txt`, one literal per non-comment non-blank line; optional `# name=<id>` header pairs an identifier with the following literal so audit JSONL groups by site (`linkedin_auth_wall`, `reddit_blocked`, etc.). Fail-soft on ENOENT (missing file = empty array). Loaded on every ingest. Deliberately literal substrings (NOT regex) to defeat ReDoS. Pinned by `test/content-sanity-literals.test.ts`.diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsvindex 5e7683d733..f3f5abc437 100644--- a/scripts/structural-suites.tsv+++ b/scripts/structural-suites.tsv@@ -107,7 +107,7 @@ test/destructive-guard.test.ts assessDestructiveImpact 5 readFileSynctest/destructive-guard.test.ts formatters (display helpers) 4 readFileSynctest/destructive-guard.test.ts purgeExpiredSources — clone cleanup containment 1 readFileSynctest/detached-stderr.test.ts jobs.ts detach branch (source pin, #4418) 2 source-surface-helper-test/divergence-safe-pull-5429.serial.test.ts --no-autostash (#5429, bug fix) 3 readFileSync+test/divergence-safe-pull-5429.serial.test.ts --no-autostash (#5429, bug fix) 4 readFileSynctest/docs-mcp-deploy.test.ts DEPLOY.md documents the owner magic-link flow (#5007) 1 readFileSync,source-surface-helpertest/docs-navigation.test.ts primary documentation navigation 1 readFileSynctest/doctor-atom-provenance-drift.test.ts computeAtomProvenanceDriftCheck 19 doctor-source-helperdiff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.tsindex 4f09af4935..50e549bc17 100644--- a/src/core/git/commit-push.ts+++ b/src/core/git/commit-push.ts@@ -125,8 +125,8 @@ function git(root: string, args: string[], opts: { auth?: boolean; timeoutMs?: nfunction gitOk(root: string, args: string[], what: string, opts: Parameters<typeof git>[2] = {}): string {const r = git(root, args, opts);if (r.code !== 0) {- throw opError('git_unavailable', `git ${what} failed in ${root}.`,- `${r.stderr.trim().slice(0, 300) || `exit ${r.code}`}`);+ throw opError('git_unavailable', `git ${what} failed in ${root}: ${r.stderr.trim().slice(0, 300) || `exit ${r.code}`}`,+ `Run git status in ${root}, fix what git reports, then rerun the same gbrain git commit-push command.`);}return r.stdout.trim();}