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
4 changes: 2 additions & 2 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ listed under "Waiting on you" on the Stewards page, in the digest, and by
| kind | filed by | link | done when | one-click action |
| -- | -- | -- | -- | -- |
| `approve-spec` | plugin, when the ready gate waits and the playbook's approver is `me` | the ticket | gate approval recorded | **Approve** / **Decline** (with an optional note); Approve records the approval on the gate, as BB-13 does from any surface |
| `approve-pr` | plugin, when a linked pull request is in the owner-reviewed lane, the reviewer's marker on the head is `approved`, checks are green, and no owner approval exists | the pull request | owner approval seen in the snapshot | **Approve**: posts the unsigned comment "Approved <sha> from the Stewards page" as the connected user |
| `approve-pr` | plugin, when a linked pull request is in the owner-reviewed lane, the reviewer's latest marker is `approved`, checks are green, and no owner approval exists | the pull request | owner approval seen in the snapshot | **Approve**: posts the unsigned comment "Approved <sha> from the Stewards page" as the connected user |
| `merge` | plugin, when the lane gate is met and no worker is running, or by a steward whose worker reported a refused merge | the pull request | the pull request merged | **Merge**: the server re-checks the gate itself, squash-merges through the server's `gh` login, posts the "Merged: …" comment, and wakes the steward |
| `decide` | project steward (today's forwarded question) | the entity | answered | **Answer** (the question record's text box) |
| `provide-secret` | steward, with the variable name and purpose | the worker thread | the worker's `bb secret request` completes | **Provide**: opens the worker thread named in the item, or wakes the steward to start the worker that will request it |
Expand All @@ -840,7 +840,7 @@ listed under "Waiting on you" on the Stewards page, in the digest, and by
The rules that hold:

- **One gate function.** `prGate` in `reconcile.ts` is the build-tickets lane
gate: the reviewer's latest marker names the current head with `approved`,
gate: the reviewer's latest marker has verdict `approved`,
every check has passed, and, in the owner-reviewed lane, the owner has
approved — an unsigned approving comment or an APPROVED review by the
connected user; a signed comment is a thread's, never the owner's. The merge
Expand Down
11 changes: 11 additions & 0 deletions plugins/stewards/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ describe("playbooks", () => {
expect(phaseInstructions(reviews.value, "open")).toMatch(/escalated as a `decision`/u);
});

it("tells the PR playbooks that an approval survives small follow-ups and when a human must approve", () => {
const prs = parsePlaybook(GITHUB_PRS, "github-prs");
if (!prs.ok) throw new Error(prs.error);
expect(phaseInstructions(prs.value, "open")).toMatch(/small follow-up push after an approval/u);
expect(phaseInstructions(prs.value, "open")).toMatch(/needs the owner's approval/u);
const reviews = parsePlaybook(GITHUB_REVIEWS, "github-reviews");
if (!reviews.ok) throw new Error(reviews.error);
expect(reviews.value.general).toMatch(/short check of the new commits/u);
expect(reviews.value.general).toMatch(/then a human approves/u);
});

it("maps states to phases and stages, ignoring case, and splits sections", () => {
const parsed = parsePlaybook(LINEAR_TICKETS, "linear-tickets");
if (!parsed.ok) throw new Error(parsed.error);
Expand Down
21 changes: 19 additions & 2 deletions plugins/stewards/reconcile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,32 @@ describe("the pull request gate (build-tickets)", () => {
expect(gate).toMatchObject({ lane: "no-review", checksGreen: true, ownerApproved: false, gateMet: true, needsOwnerApproval: false, missing: null });
});

it("honours an approved marker on an earlier sha, in both lanes, until a later verdict or failing checks", () => {
const earlier = "bbbbbbb2";
// Approved on A with the head at B: the no-review gate is met, and the owner lane waits only on the owner.
const met = prGate(pull({ comments: [marker(earlier, "approved", "no-review")] }, green));
expect(met).toMatchObject({ lane: "no-review", checksGreen: true, gateMet: true, needsOwnerApproval: false, missing: null });
expect(met.marker?.sha).toBe(earlier);
expect(met.headSha).toBe(head);
const waiting = prGate(pull({ comments: [marker(earlier, "approved", "owner-reviewed")] }, green));
expect(waiting).toMatchObject({ gateMet: false, needsOwnerApproval: true, missing: "owner approval needed" });
const approved = prGate(pull({ comments: [marker(earlier, "approved", "owner-reviewed"), owner("LGTM")] }, green));
expect(approved).toMatchObject({ gateMet: true, needsOwnerApproval: false });
// The latest marker wins: a later changes-requested on any sha blocks the gate.
const later = comment({ id: "m-later", author: "trotterdylan", body: "<!-- bb-review round=2 sha=ccccccc3 verdict=changes-requested lane=no-review -->", signedBy: "thr_reviewer", createdAt: "2026-10-14T16:30:00Z" });
expect(prGate(pull({ comments: [marker(earlier, "approved", "no-review"), later] }, green)).missing).toMatch(/reviewer verdict: changes-requested/u);
// Checks failing on the head close it whatever the marker says.
expect(prGate(pull({ comments: [marker(earlier, "approved", "no-review")] }, { checks: { state: "failure", failing: ["ci"] } })).missing).toMatch(/checks failure/u);
});

it("waits on the owner in the owner-reviewed lane, and closes once they approve", () => {
const waiting = prGate(pull({ comments: [marker(head, "approved", "owner-reviewed")] }, green));
expect(waiting).toMatchObject({ gateMet: false, needsOwnerApproval: true, missing: "owner approval needed" });
const approved = prGate(pull({ comments: [marker(head, "approved", "owner-reviewed"), owner("LGTM")] }, green));
expect(approved).toMatchObject({ gateMet: true, ownerApproved: true, needsOwnerApproval: false });
});

it("is not met while the marker is on another sha, the verdict is not approved, or checks are not green", () => {
expect(prGate(pull({ comments: [marker("bbbbbbb2", "approved", "no-review")] }, green)).missing).toMatch(/reviewer round 1 is on bbbbbbb; the head is aaaaaaa/u);
it("is not met when the verdict is not approved, checks are not green, or there is no round", () => {
expect(prGate(pull({ comments: [marker(head, "changes-requested", "no-review")] }, green)).missing).toMatch(/reviewer verdict: changes-requested/u);
expect(prGate(pull({ comments: [marker(head, "approved", "no-review")] }, { checks: { state: "pending", failing: [] } })).missing).toMatch(/checks pending/u);
expect(prGate(pull({ comments: [] })).missing).toMatch(/no reviewer round/u);
Expand Down
35 changes: 17 additions & 18 deletions plugins/stewards/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,14 @@ export function ownerApproval(entity: EntitySnapshot): { approved: boolean; at:

/**
* The lane gate from the build-tickets skill, in one place: the reviewer's
* latest marker names the current head with verdict `approved`, every check has
* passed, and, in the owner-reviewed lane, the owner has approved. It is used
* by the merge button, by the item the plugin files, and by the wake text that
* tells a steward whether a pull request's gate is met.
* latest marker has verdict `approved`, every check has passed, and, in the
* owner-reviewed lane, the owner has approved. The marker need not name the
* current head: an approval is of the pull request, not of a commit, so it
* survives a rebase, a merge of the base branch and the worker's own small
* follow-ups; only a later marker with another verdict, or checks failing on
* the current head, closes the gate. It is used by the merge button, by the
* item the plugin files, and by the wake text that tells a steward whether a
* pull request's gate is met.
*/
export type PrGate = {
headSha: string | null;
Expand All @@ -288,12 +292,10 @@ export type PrGate = {
gateMet: boolean;
/** What is missing, in words; null when the gate is met. */
missing: string | null;
/** The plugin's `approve-pr` condition: owner lane, marker approved on the head, checks green, no owner approval yet. */
/** The plugin's `approve-pr` condition: owner lane, marker approved, checks green, no owner approval yet. */
needsOwnerApproval: boolean;
};

const short = (sha: string | null | undefined) => (sha === null || sha === undefined ? "?" : sha.slice(0, 7));

export function prGate(entity: EntitySnapshot): PrGate {
const pull = entity.pull;
const headSha = pull?.headSha ?? null;
Expand All @@ -302,8 +304,7 @@ export function prGate(entity: EntitySnapshot): PrGate {
const checksState = pull?.checks?.state ?? null;
const checksGreen = pull !== null && (pull.checks === null || pull.checks.state === "success");
const owner = ownerApproval(entity);
const markerOnHead = marker !== null && headSha !== null && marker.sha === headSha;
const markerApproved = markerOnHead && marker.verdict === "approved";
const markerApproved = marker !== null && marker.verdict === "approved";
const ownerLane = lane === "owner-reviewed";
const gateMet = pull !== null && markerApproved && checksGreen && (!ownerLane || owner.approved);
const missing = gateMet
Expand All @@ -312,15 +313,13 @@ export function prGate(entity: EntitySnapshot): PrGate {
? "not a pull request"
: marker === null
? "no reviewer round yet"
: !markerOnHead
? `reviewer round ${marker.round} is on ${short(marker.sha)}; the head is ${short(headSha)}`
: marker.verdict !== "approved"
? `reviewer verdict: ${marker.verdict}`
: !checksGreen
? `checks ${checksState ?? "not run"}`
: ownerLane && !owner.approved
? "owner approval needed"
: "not met";
: marker.verdict !== "approved"
? `reviewer verdict: ${marker.verdict}`
: !checksGreen
? `checks ${checksState ?? "not run"}`
: ownerLane && !owner.approved
? "owner approval needed"
: "not met";
return {
headSha,
marker,
Expand Down
21 changes: 21 additions & 0 deletions plugins/stewards/skills/stewards/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,27 @@ Two tools are yours; everything else you do with the tools every thread has.
approved by the project steward unless the playbook says the user. Once
you report the checklist met, the plugin asks the approver itself (an
`approval` escalation): wait for it, and do not escalate for it.
- **An approval is of the pull request, not of a commit** (default; the
project's guidance overrides it). Once the owner or the reviewer approves,
a small follow-up push needs no fresh approval and no new full round:
addressing a non-blocking comment (including the change the approval asked
for, "LGTM once X"), wording, docs, tests, lint or type fixes, and
rebasing onto or merging the base branch. A fresh approval is needed when,
against the approved commit, a push changes behaviour beyond what was
approved, adds scope, or brings in something the project's guidance says
needs the approver; judge it from `git diff <approved-sha> <head>`
(`git range-diff` across a rebase) and ask when unsure. The merge comment
names the approved commit and, when newer commits landed after it, says in
a line what they changed. A review steward treats a small follow-up push
to a pull request it already approved as a short check of the new commits,
not a full round, and does not turn the approval into a new verdict.
- **When a human must approve** (default; the project's guidance overrides
it). A change that significantly modifies or removes existing behaviour,
or is risky in kind — a cross-repo contract, auth, a migration, a secret,
production infrastructure, or one of the project's `bigDecisions` — is
approved by the user before it merges. Strictly additive changes and
tweaks are not, and that a change needs a deploy or restart is not, on its
own, a reason.
- **Waiting on the user is a needs item.** A `blockedOn` that names the
project steward or the user reaches nobody; with no open escalation it is
flagged in `bb stewards list` and the digest. A `blockedOn` naming the
Expand Down
29 changes: 23 additions & 6 deletions plugins/stewards/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,18 @@ ${buildBlocker("the work")}
## open

Answer review comments with a worker, one round at a time, and re-request
review after each round. When it is approved and checks pass, merge it if the
project's guidance says its author may; otherwise say so in a comment.
review after each round. A small follow-up push after an approval — a
non-blocking comment addressed, wording, docs, tests, lint or type fixes, or a
rebase or merge of the base branch — needs no fresh approval and no new round;
judge it from \`git diff <approved-sha> <head>\`, and ask for a new round when
a push changes behaviour beyond what was approved, adds scope, or brings in
something the project's guidance says needs the approver. A change that
significantly modifies or removes existing behaviour, or is risky in kind (a
contract, auth, a migration, a secret, production infrastructure, a big
decision), needs the owner's approval before it merges. When it is approved
and checks pass, merge it if the project's guidance says its author may;
otherwise say so in a comment. The merge comment names the approved commit
and, when newer commits landed after it, one line on what they changed.

${buildBlocker("the work")}
`;
Expand All @@ -177,16 +187,23 @@ Each round is one review worker with fresh context; you post what it finds
with \`gh pr review\`, signed.

A round is due when the pull request is new to you, when the author pushes
after your last review, or when your review is re-requested. Start a review
after your last review, or when your review is re-requested. A small follow-up
push after you approved — a non-blocking comment addressed, wording, docs,
tests, lint or type fixes, or a rebase or merge of the base branch — gets a
short check of the new commits, not a full round, and does not turn your
approval into a new verdict; judge it from \`git diff <approved-sha> <head>\`
and run a full round when a push changes behaviour beyond what you approved or
adds scope. Start a review
worker with the task: "Review <url> against the project's guidance
(AGENTS.md, design docs). Check it out with gh pr checkout. Return findings as
a list of { path, line, body }, each marked blocking or not, and a
one-paragraph summary. Cover only what changed since <sha> when given."

Request changes when a finding is blocking; comment otherwise. Approve when
nothing blocking is left, unless the change is one of the project's big
decisions: then escalate a decision and let the project steward take it
further.
nothing blocking is left, unless the change significantly modifies or removes
existing behaviour, or is risky in kind (a contract, auth, a migration, a
secret, production infrastructure, a big decision): then a human approves, so
escalate a decision and let the project steward take it further.

## open

Expand Down
9 changes: 8 additions & 1 deletion plugins/stewards/wake.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Database from "better-sqlite3";
import { describe, expect, it } from "vitest";
import { parsePlaybook } from "./config.js";
import { issue } from "./fixtures.js";
import { comment, issue, pull } from "./fixtures.js";
import { gateState } from "./reconcile.js";
import { MIGRATIONS, createStore } from "./store.js";
import { LINEAR_TICKETS } from "./templates.js";
Expand Down Expand Up @@ -75,6 +75,13 @@ describe("a steward's wake", () => {
expect(wake).toContain("counts like a missed report toward `stuck`");
});

it("names the reviewer's sha and the head when the approval is on an earlier commit", () => {
const marker = comment({ id: "m1", author: "trotterdylan", body: "<!-- bb-review round=1 sha=bbbbbbb2 verdict=approved lane=no-review -->", signedBy: "thr_reviewer", createdAt: "2026-10-18T04:00:00Z" });
const entity = pull({ comments: [marker] }, { headSha: "aaaaaaa1", checks: { state: "success", failing: [] } });
const wake = formatWake(wakeInput({ observed: { entity, pulls: [] } }));
expect(wake).toContain("- Lane gate: met (reviewer approved bbbbbbb, head aaaaaaa, checks green, lane no-review)");
});

it("takes a worker's closing question, but not one it resolved later in the message", () => {
expect(workerQuestion("Pushed the fix.\nShould I bring the reviewer back?")).toBe("Should I bring the reviewer back?");
// A question buried above the last few lines is not what the message ended with.
Expand Down
10 changes: 9 additions & 1 deletion plugins/stewards/wake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,15 @@ function entityLines(e: EntitySnapshot, cursor: string, own: ReadonlySet<string>
lines.push(`- Checks: ${p.checks === null ? "none" : `${p.checks.state}${p.checks.failing.length > 0 ? ` — failing: ${p.checks.failing.join(", ")}` : ""}`}`);
lines.push(`- Review decision: ${p.reviewDecision ?? "(none)"}; requested: ${p.requestedReviewers.join(", ") || "(none)"}`);
const gate = prGate(e);
lines.push(`- Lane gate: ${gate.gateMet ? "met" : `not met — ${gate.missing}`}${gate.lane === null ? "" : ` (lane ${gate.lane})`}`);
const lane = gate.lane === null ? "" : `lane ${gate.lane}`;
if (gate.gateMet) {
const approved = gate.marker === null ? "?" : gate.marker.sha.slice(0, 7);
const head = gate.headSha === null ? "?" : gate.headSha.slice(0, 7);
const detail = [`reviewer approved ${approved}`, ...(approved === head ? [] : [`head ${head}`]), "checks green", ...(lane === "" ? [] : [lane])];
lines.push(`- Lane gate: met (${detail.join(", ")})`);
} else {
lines.push(`- Lane gate: not met — ${gate.missing}${lane === "" ? "" : ` (${lane})`}`);
}
const latest = new Map<string, string>();
for (const r of p.reviews) latest.set(r.author, `${r.state}${r.commit === null ? "" : ` at ${r.commit.slice(0, 7)}`}`);
if (latest.size > 0) lines.push(`- Latest reviews: ${[...latest].map(([a, s]) => `${a} ${s}`).join("; ")}`);
Expand Down
Loading