Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

docs: contributor audit quickstart and fix-wave gate process (maintainer-override, required-check step)

garrytana3157df7c5c2
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c21c6fa9e4..c7090c94a3 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -238,6 +238,18 @@ Vacuous-assertion shapes to avoid (they recur):
- asserting a substring that would also appear in the broken output —
assert parsed structure instead.
+For a whole range of merged changes or open PRs, the contributor audit runs
+the same check per change without the helper's whole-file revert: it reverses
+only that change's product hunks at the audited head, so later fixes stay in
+place. Try it on the offline fixture first:
+
+```bash
+bun scripts/contributor-audit-fixture.ts /tmp/audit-demo # prints the audit command for the fixture range
+bun run audit:contributors <base>..<head> [--prs <manifest>] [--json]
+```
+
+Details, exit codes and the scrubbed sandbox: [Contributor audit](docs/TESTING.md#contributor-audit).
+
Before adding a test, answer the four questions in the
[authoring gate](docs/TESTING.md#authoring-gate); before deleting one, follow
[Retiring a test](docs/TESTING.md#retiring-a-test) and record its evidence
@@ -663,6 +675,27 @@ Community PRs are batched into release waves rather than merged one-by-one;
contributor attribution stays attached via `Co-Authored-By:` trailers and every
accepted contribution is credited in `CHANGELOG.md`.
+### How a contributor PR lands
+
+Contributor PRs are never merged into master as-is. A maintainer folds the
+change into a fix-wave PR, revises it there (tests, agent-facing errors,
+conventions) and lands it with credit: the commit says `Contributed by @handle`
+and carries a `Co-Authored-By:` trailer. Your PR stays open until then.
+
+The **Fix-wave gate** check enforces this. It fails every PR into master whose
+head branch is not in `garrytan/gbrain` itself, and posts one comment saying
+so when the PR opens. A red gate on a contributor PR is expected and is not a
+judgment of the work. Maintainers' own branches (`capy/*`, `garrytan/*`) pass.
+
+`maintainer-override` label: a human on the maintainer allowlist in
+`scripts/fix-wave-gate.ts` (it starts as `garrytan`) may apply it to pass the
+gate for one PR a maintainer has decided may land from its fork (for example a
+fix wave a maintainer opened from a fork); record the reason in a PR comment.
+Bots never count, and the label only counts when the most recent
+`labeled` event was made by an allowlisted human. Every override is written to
+the check's run log and step summary with who applied it and when. Process and
+settings: [docs/RELEASING.md](docs/RELEASING.md#fix-wave-gate).
+
## Welcome PRs
- Additional engine implementations (see [`docs/ENGINES.md`](docs/ENGINES.md))
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index 680704a661..08785f03ae 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -537,7 +537,13 @@ Never merge external PRs directly into master. Instead, use the "fix wave" workf
or manually re-implement the best fixes from each PR. Do NOT merge PR branches directly —
read the diff, understand the fix, and write it yourself if needed.
4. **Test the wave** — verify with `bun test && bun run test:e2e` (full E2E lifecycle).
- Every fix in the wave must have test coverage.
+ Every fix in the wave must have test coverage. Run
+ `bun run audit:contributors <base>..<collector-head> --prs <manifest>` to re-prove,
+ per merged change and per open PR (trial-merged), that its tests fail with its product
+ hunks reversed; the tool pins the PR heads into `prs.pinned.json` so a rerun tests the
+ same code, and its Markdown table keeps mechanical results apart from your verdicts
+ (see [Contributor audit](TESTING.md#contributor-audit)). Paste the table into the wave
+ PR body.
5. **Security review** — run `bun run wave-security-scan <base>..<collector-head>` over the
collector branch (the repeatable mechanical sweep). It ALARMS on newly-introduced
obfuscation/eval in code, secrets found by gitleaks **with the test/skills allowlist
@@ -559,6 +565,45 @@ Never merge external PRs directly into master. Instead, use the "fix wave" workf
- Never auto-merge PRs that remove YC references or "neutralize" the founder perspective.
- Preserve contributor attribution in commit messages.
+### Fix-wave gate
+
+`.github/workflows/fix-wave-gate.yml` (job `contributor-gate`) fails every PR into
+master unless its head repository is `garrytan/gbrain` or the `maintainer-override`
+label counts. Only maintainers can push to `garrytan/gbrain`, so GBRA thread PRs
+(`capy/*`) and `garrytan/*` branches pass; fork PRs fail whatever their branch is
+called. When a contributor PR opens, a second job posts one comment with the same
+text as the failure: the work is welcome and the PR stays open, it lands through a
+fix wave with credit (`Contributed by @handle` plus a `Co-Authored-By:` trailer), and
+CONTRIBUTING.md "Where does my change go?" explains where changes belong.
+
+The workflow uses `pull_request_target`, so the workflow and
+`scripts/fix-wave-gate.ts` always come from the default branch: a PR that edits
+either cannot change its own result. It reads only the event payload and the PR
+timeline, never PR code, with `permissions: {}` at the top, `pull-requests: read`
+for the gate and `pull-requests: write` only for the comment job. A null head
+repository (deleted fork) fails closed. The check re-runs on `opened`, `edited`,
+`reopened`, `synchronize`, `labeled` and `unlabeled`.
+
+**`maintainer-override` label.** Who: a human on `MAINTAINERS` in
+`scripts/fix-wave-gate.ts` (starts as `garrytan`; changing it is a reviewed PR to
+master). When: only for a PR a maintainer has decided may land from its fork, such as
+a fix wave a maintainer opened from a fork; record the reason in a PR comment. How it
+is checked: the label counts only when the most recent `labeled` timeline event for it
+was made by an allowlisted `User`; bots (`capy-ai[bot]`, `github-actions[bot]`, any
+`[bot]` login) never qualify, and removing the label fails the PR again. Audit: the run
+log prints a `notice` naming who applied the label, when, and the timeline event id,
+and the step summary repeats it.
+
+**Turning it on (repository settings, maintainer only).** The guard is active only
+after this step; until then the check is advisory. Settings → Rules → Rulesets (or
+Settings → Branches → the `master` protection rule) → Require status checks to pass →
+add `contributor-gate` with GitHub Actions as the source → save. The check must have
+run once on any PR before GitHub offers it in the picker.
+
+**Residual risk.** A same-repo branch (`capy/*` or `garrytan/*`) that carries
+contributor commits passes by design. Keeping contributor work inside a revised fix
+wave on those branches stays a policy rule, enforced by review, not by this check.
+
## Checking out PRs from garrytan-agents
`garrytan-agents` is the AI-authored PR account and is NOT a collaborator on
diff --git a/docs/TESTING.md b/docs/TESTING.md
index 80bfe91d57..d3105afdc0 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -317,6 +317,42 @@ Bad: a test that reads `src/commands/remote.ts` and asserts it contains
`job.status`. It passes when the loop is broken in a way that keeps the token,
fails on a harmless rename, and duplicates the behavioral test above.
+### Contributor audit
+
+`bun run audit:contributors <base>..<head> [--prs <manifest>] [--json]`
+(`scripts/contributor-audit.ts`) re-proves discrimination for every
+first-parent commit in the range and for each PR head in `--prs`, trial-merged
+onto `<head>`. In an isolated worktree of `<head>` it runs the change's test
+files (green baseline required), reverses only that change's product hunks
+(`git diff M^1 M -- <product files> | git apply -R`; tests and docs stay),
+reruns, restores, checks the tree is identical and re-verifies green. Hunks
+that no longer apply at `<head>` are audited at the merge commit itself.
+
+Results use the helper's vocabulary (`discriminates`, `does_not_discriminate`,
+`vacuous_failure`) plus `setup_failed`, `conflict` and `not_audited`, with a
+reason. Human verdicts (`accept`, `rework`, `reject`, `not_yet_proven`) live in
+a separate `--verdicts` file and print in their own column. It also runs
+`wave-security-scan` (range and each PR) and `check:postgres-lanes` (head and
+each trial merge) from the trusted checkout; `--skip-security` and
+`--skip-lanes` opt out.
+
+Preflight checks Bun against `engines.bun`, the refs, gitleaks and python3,
+and a `--postgres` database (which must be test-shaped). PR heads are pinned
+into `<run-dir>/prs.pinned.json`; state and per-step logs live in the run dir
+(default `.git/contributor-audit/<base>-<head>/`), so `--resume` skips finished
+cases and refuses when refs or pins differ. `--step-timeout` (default 900s)
+bounds each step. Exit: 0 clean, 1 needs a human look, 2 usage or preflight
+refusal (an agent-contract envelope), 130 interrupted.
+
+Untrusted code (install with `--ignore-scripts`, tests) runs under `env -i`
+with an allowlist: temporary `HOME` and `GBRAIN_HOME`, no credential files,
+`DATABASE_URL` and `GBRAIN_DATABASE_URL` empty unless `--postgres` is given,
+`bun --no-env-file`. For stronger isolation, run the unit audit on an
+ephemeral Ubicloud VM with outbound network blocked after `bun install`
+(optional). First run: `bun scripts/contributor-audit-fixture.ts <dir>` builds
+an offline range covering each result. Tests:
+`test/scripts/contributor-audit.test.ts`.
+
### Retiring a test
Delete or merge a test only with evidence, recorded in the PR body:
diff --git a/docs/architecture/KEY_FILES.md b/docs/architecture/KEY_FILES.md
index d9b819739d..2cad19ff00 100644
--- a/docs/architecture/KEY_FILES.md
+++ b/docs/architecture/KEY_FILES.md
@@ -68,7 +68,7 @@ boundary and add its link here rather than raising the cap.
| [Shared brain skills](key-files/shared-skills.md) | Canonical catalog, enrollment, migration, publication and harness integration |
| [Skills](key-files/skills.md) | `src/core/audit-skill-brain-first.ts` through `src/core/skills-integrity.ts` |
| [Tooling And Tests](key-files/tooling-and-tests.md) | `.github/workflows/test.yml` through `test/remote-privacy-sweep.test.ts` |
-| [CI Health And Test Guards](key-files/ci-health-and-test-guards.md) | `.github/workflows/nightly-watch.yml` through `scripts/check-image-decoders-embedded.sh` |
+| [CI Health And Test Guards](key-files/ci-health-and-test-guards.md) | `.github/workflows/nightly-watch.yml` through `scripts/check-image-decoders-embedded.sh`, plus the contributor audit and the fix-wave gate |
| [BrainBench — in a sibling repo](key-files/brainbench.md) | Cross-file subsystem contract |
| [Hindsight calibration (key files cluster)](key-files/hindsight.md) | Cross-file subsystem contract |
| [Schema packs: mutation surface (key files cluster)](key-files/schema-mutation.md) | Cross-file subsystem contract |
diff --git a/docs/architecture/key-files/ci-health-and-test-guards.md b/docs/architecture/key-files/ci-health-and-test-guards.md
index a226ea6c90..5a900594a0 100644
--- a/docs/architecture/key-files/ci-health-and-test-guards.md
+++ b/docs/architecture/key-files/ci-health-and-test-guards.md
@@ -17,3 +17,5 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `test/helpers/brain-template.ts` — disk-backed PGLite brains cloned from one initialized template per process and embedding shape. The template is captured right after `initSchema` with no source, writer or physical-root reservation (asserted); only the data directory is copied; each clone regenerates `brain_id`, the default source incarnation and the shared-skill token secret and serving epoch. Used by `test/helpers/connector-fixture.ts`. Tests: `test/helpers/brain-template.test.ts`.
- `scripts/test-agent-voice.sh` — `bun run test:agent-voice`: the agent-voice recipe's vitest unit suite (`recipes/agent-voice/tests/unit`), with pinned vitest and ws installed into a temporary prefix linked as the recipe's `node_modules`. Needs node, npm and registry access; CI runs it in test.yml's verify job.
- `scripts/check-image-decoders-embedded.sh` — `check:image-decoders` (in `verify`): compiles a smoke binary and proves HEIC and AVIF decode inside a `bun --compile` artifact; a failure prints the bun build error with Why/Fix.
+- `scripts/contributor-audit.ts` + `scripts/contributor-audit-fixture.ts` — `bun run audit:contributors <base>..<head> [--prs <manifest>] [--json]`. Per first-parent commit in the range and per pinned PR head trial-merged onto `<head>`: green baseline of the change's test files, reverse only its product hunks (non-test, non-doc) with `git apply -R` in an isolated worktree of `<head>` (falling back to the merge commit when the hunks no longer apply), classify (`discriminates`, `does_not_discriminate`, `vacuous_failure`, `setup_failed`, `conflict`, `not_audited` with a reason), restore, verify the tree is identical and green again. Untrusted install and tests run under `env -i` with `sandboxEnv()`'s allowlist (temporary `HOME`/`GBRAIN_HOME`, empty `DATABASE_URL`/`GBRAIN_DATABASE_URL` unless `--postgres` names a test-shaped database). Runs the trusted `wave-security-scan.sh` and `check-postgres-lane-coverage.ts` (`GBRAIN_GUARD_ROOT` = audited tree). State, logs and `prs.pinned.json` live in `<git-dir>/contributor-audit/<base>-<head>/`; `--resume` refuses on changed refs or pins (`preview_changed`). Human verdicts come only from the verdicts file. Exit 0 clean, 1 review, 2 refusal envelope, 130 interrupted. The fixture builds the offline demo range. Tests: `test/scripts/contributor-audit.test.ts`. Docs: `docs/TESTING.md#contributor-audit`.
+- `.github/workflows/fix-wave-gate.yml` + `scripts/fix-wave-gate.ts` — the contributor gate. `pull_request_target` on master (`opened`, `edited`, `reopened`, `synchronize`, `labeled`, `unlabeled`); sparse-checks-out only the script from the default branch and never PR code. `decide()` (pure) passes a head repository equal to `TRUSTED_HEAD_REPO` with the base repository's id, or a present `maintainer-override` label whose latest `labeled` timeline event was made by a `User` on `MAINTAINERS` (no `[bot]` login); a null head repository, a missing label or any other labeler fails. Overrides print a `notice` and step-summary line naming the actor, time and event id. `--comment` (the `welcome-comment` job, `pull-requests: write`, `opened` only) posts `gateMessage()` once per PR, keyed by `COMMENT_MARKER`. The script imports only `node:` modules. Tests: `test/scripts/fix-wave-gate.test.ts` (fixture payloads in `test/fixtures/fix-wave-gate/`). Process and the required-check settings step: `docs/RELEASING.md#fix-wave-gate`.