Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/gate-risk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ jobs:
scripts/gate/gate risk --base "$BASE_SHA" --head "$HEAD_SHA" --author "$AUTHOR" --json > risk.json
tier=$(jq -r .tier risk.json)
ask=$(jq -r '.needs_you[0].ask // ""' risk.json)
# Label and status first, so a comment error cannot leave a stop PR
# free to merge.
# Label and status first, so a comment error still tags and classifies the PR.
if [ "$tier" = stop ]; then
# Pending, not failure: the PR cannot merge by itself, and no
# failure email goes out. The owner merges it.
# Advisory success, not pending or failure: keeps real CI honest and
# avoids failed-workflow emails while labeling and commenting on the PR.
gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels" -f "labels[]=risk:owner" > /dev/null
gh api --method POST "repos/$GITHUB_REPOSITORY/statuses/$HEAD_SHA" -f context=gate/risk -f state=pending -f description="Needed from you: ${ask:0:120}"
gh api --method POST "repos/$GITHUB_REPOSITORY/statuses/$HEAD_SHA" -f context=gate/risk -f state=success -f description="Advisory: ${ask:0:120}"
else
gh api --method DELETE "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels/risk%3Aowner" > /dev/null 2>&1 || true
gh api --method POST "repos/$GITHUB_REPOSITORY/statuses/$HEAD_SHA" -f context=gate/risk -f state=success -f description="Risk: $tier"
Expand Down
43 changes: 27 additions & 16 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,35 @@ The shared guard proposed in #531 was not built; #531 was also closed. Before yo
Rust changed, it runs `pnpm run check` and the contract snapshots instead
(about 6 minutes). When a workflow changed, it also runs zizmor. Fix what
fails. Do not use `--no-verify`.
3. Open the PR with `.github/PULL_REQUEST_TEMPLATE.md`, then run
`gh pr merge --auto --squash`.
3. Open the PR with `.github/PULL_REQUEST_TEMPLATE.md`. Run
`scripts/gate/gate risk --json` locally before enabling auto-merge, **and
re-run it after every subsequent push**:
- For `ship` or `show` PRs, or in an interactive thread when the owner
explicitly asked for that `stop` change (and did not ask to hold), enable
`gh pr merge --auto --squash` so GitHub merges when green.
- For unasked-for `stop` rules, AFK / `full send` runs hitting `stop`, or
explicit `full stop` / hold requests, do not enable `--auto` (and run
`gh pr merge --disable-auto` first if already enabled); follow
`full-stop` (`babysit-pr` until real CI is green, call
`unwatch_pull_request`, then hand off) before posting a passing
`gate/review` status.
4. Get a review from a model of another provider and post it with
`scripts/gate/gate review-status` (see `scripts/gate/README.md`). Each push
needs a new review.
5. GitHub merges when the required checks pass. Watch the PR only to fix a
failing check.
6. `gate/risk` adds the `risk:owner` label and stays pending for: a release, a
version change, deploy or secret files, a new dependency, a change to
`package.json` scripts, workflows, `.githooks/`, `.gate/` or `deny.toml`, and
policy files. The rules
are in `.gate/config.toml`. The owner merges these PRs. The workflow posts a
`Needed from you and why` comment on the PR: the decision, why a person must
make it, and the files and rule that matched. Start your reply with
`Needs you: #<number> <the one decision>`. End it with that section: link
the PR, copy the comment, and add your pick and why. Then stop. Do not wait
for the merge, use `--admin` without the owner's go-ahead in the chat, or
remove the label.
needs a new review. Before posting a passing `gate/review`, re-verify
`scripts/gate/gate risk --json` on the current head and ensure auto-merge is
disabled if an unasked `stop` rule matched.
5. Watch the PR via `babysit-pr` (`watch_pull_request`). GitHub merges `--auto`
PRs when required checks pass; if handing off unmerged, always call
`unwatch_pull_request` once real CI is green.
6. `gate/risk` is advisory (`state=success`), adding the `risk:owner` label and a
`Needed from you and why` PR comment (never `pending` or `failure`) for: a
release, a version change, deploy or secret files, a new dependency, a change
to `package.json` scripts, workflows, `.githooks/`, `.gate/` or `deny.toml`,
and policy files. The rules are in `.gate/config.toml`. When handing a
`stop` PR to the owner, end your reply with `Needed from you and why`: link
the PR, copy the risk ask/why, and add your pick and why. Never use
`--admin` without the owner's go-ahead in the chat, and never remove the
label.
7. Review rounds follow the `diff-review` skill. If the review still fails
after 2 rounds of fixes, stop and start your reply with `Needs you:` and
the disagreement. Findings still open at the end go in your
Expand Down
9 changes: 4 additions & 5 deletions scripts/gate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ command output and JSON data, so edits to CLI or MCP implementation files alone
do not stop a PR.

Tiers: **ship** and **show** PRs merge by auto-merge when CI and the review
pass. A **stop** PR gets the `risk:owner` label, its `gate/risk` status stays
pending, and the owner merges it.
pass. A **stop** PR gets the `risk:owner` label and an advisory `gate/risk = success` status; agents run `gate risk` locally to decide whether to hold for the owner (`full-stop`) or auto-merge when explicitly requested.

Each stop rule has an `[owner.<rule id>]` table with `ask` (the decision the
owner makes) and `why` (why a person must make it). `gate risk --json` returns
Expand Down Expand Up @@ -83,18 +82,18 @@ review. Run review-status only after the review is complete.

## Workflows and metrics

`gate-risk.yml` runs the `risk` job on `pull_request_target`, only for PRs to the default branch. GitHub uses base-branch YAML for this event. The job checks out the base SHA without stored credentials. It fetches the PR head as git objects and runs only base-branch scripts. For a stop tier it adds the `risk:owner` label, posts one PR comment from `comment.jq`, and posts `gate/risk = pending` with the first `ask`. Otherwise it removes that label and that comment and posts `gate/risk = success`. It never posts failure, so the risk check sends no failure email.
`gate-risk.yml` runs the `risk` job on `pull_request_target`, only for PRs to the default branch. GitHub uses base-branch YAML for this event. The job checks out the base SHA without stored credentials. It fetches the PR head as git objects and runs only base-branch scripts. For a stop tier it adds the `risk:owner` label, posts one PR comment from `comment.jq`, and posts advisory `gate/risk = success` with the first `ask`. Otherwise it removes that label and that comment and posts `gate/risk = success`. It never posts pending or failure, so real CI and email notifications stay quiet.

`gate.yml` runs `unit` and `contracts` on `pull_request` with read access only. These checks run PR code. They do not control the risk job. Both are required checks in the ruleset.

Do not execute PR code in a workflow that has write access. The owner merges a stop PR with the ruleset bypass. Agents push with the owner's account, so the label and the pending status stop agent mistakes, not an agent that uses `--admin`.
Do not execute PR code in a workflow that has write access. Agents push with the owner's account, so the label and comment surface risk while the agent checks `gate risk` locally to hold unasked `stop` PRs via `full-stop`.

`gate-update.yml` updates behind PRs that have auto-merge enabled. Supply an
optional `GATE_UPDATE_TOKEN` secret with contents and pull-request write access
so update pushes trigger CI. GitHub suppresses most workflows from pushes made
with the default workflow token. Without that secret, updates can occur but a
maintainer must trigger checks. Conflicts or head changes fail the job and leave
the PR for a maintainer. Agents enable auto-merge when they open a PR.
the PR for a maintainer. Agents enable auto-merge only when the local risk decision allows it.

`gate-metrics.yml` runs on day 1 of each month and on manual dispatch. It reports the previous calendar month in the Actions job summary. It has read access to contents, pull requests, Actions runs, and commit statuses. It does not write to the repository.

Expand Down
Loading