From 81aa8670f3789f8c09d8361fd7a0e973f2fc1c4b Mon Sep 17 00:00:00 2001 From: Dylan Trotter Date: Tue, 20 Oct 2026 15:44:58 +0000 Subject: [PATCH 1/2] stewards: a forwarded spec approval becomes an approve-spec need (BB-19) When the project steward forwards an `approval` escalation to the user, the binding waits on the user's approval exactly as `approval: me` does. File an `approve-spec` need instead of a free-text question, keeping the escalation open and linked (`data.escalationId`), so the page offers Approve/Decline and no prose row. The page's Approve/Decline and `bb stewards done` run the same approve/decline path as `steward_update { approve }`: the gate verdict is recorded, the need closes and the open `approval` escalations resolve in one step. Both the ticket steward (with the closure under "What changed") and the project steward (told the forwarded escalation is resolved) are woken. A forwarded `decision` stays a question; `approval: me` is unchanged. --- plugins/stewards/DESIGN.md | 24 +++- plugins/stewards/README.md | 6 +- plugins/stewards/app.tsx | 9 +- plugins/stewards/server.test.ts | 165 ++++++++++++++++++---- plugins/stewards/server.ts | 135 +++++++++++++----- plugins/stewards/skills/stewards/SKILL.md | 14 +- plugins/stewards/wake.ts | 6 +- 7 files changed, 287 insertions(+), 72 deletions(-) diff --git a/plugins/stewards/DESIGN.md b/plugins/stewards/DESIGN.md index 86081c33..b3e44516 100644 --- a/plugins/stewards/DESIGN.md +++ b/plugins/stewards/DESIGN.md @@ -537,11 +537,14 @@ hard stop is the runaway guard (§12). - **Questions to you are records.** Whatever the project steward asks you is a row in the `questions` table, not just a sentence in its reply, so a compaction cannot lose it and an answer given elsewhere cannot leave it - listed as open. A row is made two ways: when it forwards an escalation to - you (`steward_update { forward }` with the route reaching `me`), bound to - that escalation and its binding; and when it asks you something itself - with `steward_update { ask: { question, context } }`, bound to a binding - when it names one. It closes when the project steward records your answer + listed as open. A row is made when the project steward asks you something + itself with `steward_update { ask: { question, context } }`, bound to a + binding when it names one; and when it forwards a non-approval escalation + to you (`steward_update { forward }` with the route reaching `me`), bound + to that escalation and its binding. A forwarded `approval` escalation is + not a question: it becomes an `approve-spec` need with Approve/Decline + (§18), and the escalation stays open, linked to it. A question closes when + the project steward records your answer (`steward_update { resolve: "", answer }`) or when you close it on the stewards page, with or without an answer. A question made by forwarding and its escalation close together, in one transaction, from @@ -830,7 +833,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-spec` | plugin, when the ready gate waits and the playbook's approver is `me`, or when the project steward forwards an `approval` escalation to the user | 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 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 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) | @@ -862,6 +865,15 @@ The rules that hold: changed", and the wake lists the binding's open items and says not to ask the user about them in prose. Closing an item from the page or with `bb stewards done ` does the same. +- **A forwarded approval is a need.** When the project steward forwards an + `approval` escalation to the user, the plugin files an `approve-spec` need + on the binding and keeps the escalation open, linked to it + (`data.escalationId`), instead of a free-text question: the binding is + waiting on the user's approval exactly as `approval: me` would be. The + page's Approve and Decline, and `bb stewards done` for Approve, record the + gate verdict and resolve the open `approval` escalations in the same step, + so the project steward is not left holding the request. A forwarded + `decision` escalation stays a question, answered in prose. - **Dedupe.** A need is keyed by (binding, kind, url) while open: a steward that re-reports updates the wording rather than adding a row. The store enforces it with a partial unique index. diff --git a/plugins/stewards/README.md b/plugins/stewards/README.md index 9be7c5ec..68545e75 100644 --- a/plugins/stewards/README.md +++ b/plugins/stewards/README.md @@ -151,7 +151,11 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run. escalation with the project steward, or an `approve-spec` item on the Stewards page when the approver is the user (`approval: me`), whatever the steward's report says, and closes it once approved or no longer - needed. An approval is recorded from the approver's + needed. When the project steward forwards an `approval` escalation to + you, the plugin files the same `approve-spec` item and keeps the + escalation open, linked to it, so a forwarded approval is answered with + Approve/Decline exactly as `approval: me` is; a forwarded `decision` + stays a question. An approval is recorded from the approver's words wherever they are: the project steward's guidance that resolves the request, the user's answer on the Stewards page, their message in the steward's thread, or their unsigned approving comment on the entity. A diff --git a/plugins/stewards/app.tsx b/plugins/stewards/app.tsx index 12014ecb..a212e7c2 100644 --- a/plugins/stewards/app.tsx +++ b/plugins/stewards/app.tsx @@ -386,7 +386,12 @@ function BoardPage({ subPath }: { subPath: string }) { function ProjectBoard({ board: b, refetch }: { board: Board; refetch: () => void }) { const now = Date.now(); - const waiting = b.questions.length + b.withUser.length + b.needs.length; + // An escalation a need answers is shown as that need's row, not as the raw + // escalation: a forwarded approval is answered with Approve/Decline, not by + // "approve or decline in its steward's thread". + const covered = new Set(b.needs.map((n) => n.escalationId).filter((id): id is string => id !== null)); + const withUser = b.withUser.filter((x) => !covered.has(x.id)); + const waiting = b.questions.length + withUser.length + b.needs.length; return ( <>
@@ -412,7 +417,7 @@ function ProjectBoard({ board: b, refetch }: { board: Board; refetch: () => void {b.questions.map((q) => ( ))} - {b.withUser.map((x) => ( + {withUser.map((x) => (
  • diff --git a/plugins/stewards/server.test.ts b/plugins/stewards/server.test.ts index 028e0a04..1e8e5763 100644 --- a/plugins/stewards/server.test.ts +++ b/plugins/stewards/server.test.ts @@ -1724,6 +1724,7 @@ describe("questions to the user", () => { digest: { text: string; at: number } | null; questions: Array<{ id: string; question: string; key: string | null; escalationId: string | null }>; withUser: Array<{ id: string; kind: string }>; + needs: Array<{ id: string; kind: string; escalationId: string | null }>; stewards: Array<{ key: string; stage: string | null; summary: string | null; nextAction: string | null; actor: string | null; workers: Array<{ threadId: string; title: string }> }>; stuck: Array<{ key: string; why: string }>; ended: Array<{ key: string; endReason: string | null }>; @@ -1849,22 +1850,30 @@ describe("questions to the user", () => { const t = await adopted(); await t.tool("steward_report", { ...base, ready: met }, t.steward); const esc = /(esc_[\w-]+) from ENG-12 \(approval\)/u.exec(t.sends.filter((s) => s.threadId === t.project).at(-1)!.text)![1]!; - const qst = t.qid((await t.tool("steward_update", { binding: "ENG-12", forward: esc }, t.project)).text); const stewardWakes = () => t.sends.filter((s) => s.threadId === t.steward).length; const projectWakes = () => t.sends.filter((s) => s.threadId === t.project).length; - return { ...t, esc, qst, stewardWakes, projectWakes }; + return { ...t, esc, stewardWakes, projectWakes }; } - it("records a page answer that approves, resolving the escalation in one step", async () => { + /** The same, forwarded to the user: the page's Approve/Decline answers the item it files. */ + async function forwarded() { const t = await requested(); - const answered = await t.harness.callRpc("stewardsAnswerQuestion", { questionId: t.qst, answer: "Approved" }, client); + expect((await t.tool("steward_update", { binding: "ENG-12", forward: t.esc }, t.project)).text).toMatch(/as an approve-spec item/u); + const need = t.hooks.store.openNeeds(t.hooks.store.find("ENG-12")!.id).find((n) => n.kind === "approve-spec")!; + expect(need.data.escalationId).toBe(t.esc); + return { ...t, need }; + } + + it("records the page's Approve, resolving the forwarded escalation in one step", async () => { + const t = await forwarded(); + const answered = await t.harness.callRpc("stewardsNeedAction", { needId: t.need.id, action: "approve" }, client); expect(answered).toMatchObject({ ok: true, message: expect.stringMatching(/Approved/u) }); const b = t.hooks.store.find("ENG-12")!; expect(b.ready.approval).not.toBeNull(); expect(b.ready.approval!.by).toBe("user"); expect(b.ready.declinedSpecHash).toBeNull(); expect(t.hooks.store.escalation(t.esc)).toMatchObject({ status: "resolved" }); - expect(t.hooks.store.question(t.qst)!.status).toBe("answered"); + expect(t.hooks.store.need(t.need.id)!.status).toBe("done"); expect((await t.list())[0]!.escalations).toBe(0); // No fresh request is filed for the same spec. const before = t.projectWakes(); @@ -1872,26 +1881,22 @@ describe("questions to the user", () => { expect(t.projectWakes()).toBe(before); }); - it("declines a page answer that clearly refuses", async () => { - const t = await requested(); - expect(await t.harness.callRpc("stewardsAnswerQuestion", { questionId: t.qst, answer: "No, not yet" }, client)).toMatchObject({ ok: true, message: expect.stringMatching(/Declined/u) }); + it("records the page's Decline, resolving the forwarded escalation", async () => { + const t = await forwarded(); + expect(await t.harness.callRpc("stewardsNeedAction", { needId: t.need.id, action: "decline" }, client)).toMatchObject({ ok: true, message: expect.stringMatching(/Declined/u) }); const b = t.hooks.store.find("ENG-12")!; expect(b.ready.approval).toBeNull(); expect(b.ready.declinedSpecHash).not.toBeNull(); expect(t.hooks.store.escalation(t.esc)!.status).toBe("resolved"); + expect(t.hooks.store.need(t.need.id)!.status).toBe("done"); }); - it("hands an ambiguous page answer to the project steward, not a decline", async () => { - const t = await requested(); - const before = t.projectWakes(); - expect(await t.harness.callRpc("stewardsAnswerQuestion", { questionId: t.qst, answer: "What about SSO?" }, client)).toMatchObject({ ok: true, message: expect.stringMatching(/project steward/u) }); - const b = t.hooks.store.find("ENG-12")!; - expect(b.ready.approval).toBeNull(); - expect(b.ready.declinedSpecHash).toBeNull(); - const x = t.hooks.store.escalation(t.esc)!; - expect(x).toMatchObject({ status: "open", route: "project" }); - expect(t.projectWakes()).toBeGreaterThan(before); - expect(t.sends.filter((s) => s.threadId === t.project).at(-1)!.text).toMatch(/ambiguous/u); + it("files a need, not a question, when the approval is forwarded", async () => { + const t = await forwarded(); + expect(t.hooks.store.openQuestions("p1").filter((q) => q.escalationId === t.esc)).toEqual([]); + const board = await t.board(); + expect(board.withUser).toEqual([]); + expect(board.needs).toMatchObject([{ kind: "approve-spec", escalationId: t.esc }]); }); it("records approval when the project steward resolves with approving words, no approve: true", async () => { @@ -2029,17 +2034,18 @@ describe("questions to the user", () => { expect((await t.harness.behavior.runCli(["show", "ENG-12"])).stdout).toMatch(/asks for an approval that is already open/u); }); - it("passes the BB-11 sequence: page answer, amendment, page answer again, no duplicate request", async () => { + it("passes the BB-11 sequence: page Approve, amendment, page Approve again, no duplicate request", async () => { const t = await adopted(); - const answer = async (esc: string, text: string) => { - const qst = t.qid((await t.tool("steward_update", { binding: "ENG-12", forward: esc }, t.project)).text); - await t.harness.callRpc("stewardsAnswerQuestion", { questionId: qst, answer: text }, client); + const answer = async (esc: string, action: "approve" | "decline") => { + await t.tool("steward_update", { binding: "ENG-12", forward: esc }, t.project); + const need = t.hooks.store.openNeeds(t.hooks.store.find("ENG-12")!.id).find((n) => n.kind === "approve-spec" && n.data.escalationId === esc)!; + await t.harness.callRpc("stewardsNeedAction", { needId: need.id, action }, client); }; const projectWakes = () => t.sends.filter((s) => s.threadId === t.project).length; await t.tool("steward_report", { ...base, ready: met }, t.steward); const first = /(esc_[\w-]+) from ENG-12 \(approval\)/u.exec(t.sends.filter((s) => s.threadId === t.project).at(-1)!.text)![1]!; - await answer(first, "Approved"); + await answer(first, "approve"); expect(t.hooks.store.find("ENG-12")!.ready.approval).not.toBeNull(); const afterFirst = projectWakes(); await t.tool("steward_report", { ...base, ready: met }, t.steward); @@ -2053,7 +2059,7 @@ describe("questions to the user", () => { expect(second).not.toBe(first); // And approves the amended spec on the page again. - await answer(second, "LGTM"); + await answer(second, "approve"); const b = t.hooks.store.find("ENG-12")!; expect(b.ready.approval).not.toBeNull(); expect(b.ready.declinedSpecHash).toBeNull(); @@ -2389,6 +2395,115 @@ describe("needs you items", () => { }); }); +// BB-19: a spec approval the project steward forwards to the user is the +// user's to decide, so it becomes an `approve-spec` item with Approve and +// Decline, not a free-text question. +describe("forwarded spec approvals", () => { + const client = { experimental_caller: { kind: "client" } } as const; + const met = { checklist: [1, 2, 3, 4].map((item) => ({ item, met: true })), substantial: true }; + const base = { phase: "Todo", summary: "Spec posted.", nextAction: "Wait", actor: "other" as const }; + + /** A bound ticket whose approval request is with the project steward, forwarded to the user. */ + async function forwarded() { + const t = await setup(); + t.entities.set("uuid-12", issue()); + await t.ring("linear", "uuid-12"); + const [project, steward] = t.spawns.map((x) => x.id) as [string, string]; + await t.tool("steward_report", { ...base, ready: met }, steward); + const esc = /(esc_[\w-]+) from ENG-12 \(approval\)/u.exec(t.sends.filter((s) => s.threadId === project).at(-1)!.text)![1]!; + const forwardedText = (await t.tool("steward_update", { binding: "ENG-12", forward: esc }, project)).text; + const binding = () => t.hooks.store.find("ENG-12")!; + const need = () => t.hooks.store.openNeeds(binding().id).find((n) => n.kind === "approve-spec")!; + const projectWakes = () => t.sends.filter((s) => s.threadId === project).length; + const stewardWakes = () => t.sends.filter((s) => s.threadId === steward).length; + return { ...t, project, steward, esc, forwardedText, binding, need, projectWakes, stewardWakes }; + } + + it("files exactly one approve-spec need, no question, and keeps the escalation linked", async () => { + const t = await forwarded(); + expect(t.forwardedText).toMatch(/as an approve-spec item/u); + const open = t.hooks.store.openNeeds(t.binding().id).filter((n) => n.kind === "approve-spec"); + expect(open).toHaveLength(1); + expect(open[0]!.data.escalationId).toBe(t.esc); + expect(open[0]!.filedBy).toBe("plugin"); + // No free-text question for it, and the escalation stays open with the user. + expect(t.hooks.store.openQuestions("p1")).toEqual([]); + expect(t.hooks.store.escalation(t.esc)).toMatchObject({ status: "open", route: "me" }); + // The page shows the item, not the raw escalation row. + const board = (await t.harness.callRpc("stewardsBoard", { projectId: "p1" })) as { board: { withUser: unknown[]; needs: Array<{ kind: string; escalationId: string | null }> } }; + expect(board.board.withUser).toEqual([]); + expect(board.board.needs).toMatchObject([{ kind: "approve-spec", escalationId: t.esc }]); + }); + + it("re-reporting and re-forwarding do not duplicate the need", async () => { + const t = await forwarded(); + // A re-report re-runs syncNeeds: the item is updated, not added. + await t.tool("steward_report", { ...base, ready: met }, t.steward); + expect(t.hooks.store.openNeeds(t.binding().id).filter((n) => n.kind === "approve-spec")).toHaveLength(1); + // A retry of the forward is refused (the escalation is no longer with the + // project steward), and changes nothing. + expect((await t.tool("steward_update", { binding: "ENG-12", forward: t.esc }, t.project)).error).toBe(true); + expect(t.hooks.store.openNeeds(t.binding().id).filter((n) => n.kind === "approve-spec")).toHaveLength(1); + expect(t.hooks.store.openQuestions("p1")).toEqual([]); + }); + + it("Approve records the gate approval, closes the item, resolves the escalation, and wakes both stewards", async () => { + const t = await forwarded(); + const need = t.need(); + const projectBefore = t.projectWakes(); + const stewardBefore = t.stewardWakes(); + expect(await t.harness.callRpc("stewardsNeedAction", { needId: need.id, action: "approve" }, client)).toMatchObject({ ok: true, message: expect.stringMatching(/Approved/u) }); + expect(t.binding().ready.approval).not.toBeNull(); + expect(t.binding().ready.approval!.by).toBe("user"); + expect(t.hooks.store.need(need.id)!.status).toBe("done"); + expect(t.hooks.store.escalation(t.esc)).toMatchObject({ status: "resolved" }); + await t.flush(); + expect(t.stewardWakes()).toBeGreaterThan(stewardBefore); + expect(t.sends.filter((s) => s.threadId === t.steward).at(-1)!.text).toMatch(/## 5\. What changed since your last turn[\s\S]*approved ENG-12's spec on the Stewards page/u); + expect(t.projectWakes()).toBeGreaterThan(projectBefore); + expect(t.sends.filter((s) => s.threadId === t.project).at(-1)!.text).toMatch(new RegExp(`${t.esc} is resolved`, "u")); + }); + + it("Decline records the declined spec hash, closes the item, resolves the escalation, and wakes both stewards", async () => { + const t = await forwarded(); + const need = t.need(); + const projectBefore = t.projectWakes(); + expect(await t.harness.callRpc("stewardsNeedAction", { needId: need.id, action: "decline", note: "Name the migration." }, client)).toMatchObject({ ok: true, message: expect.stringMatching(/Declined/u) }); + expect(t.binding().ready.approval).toBeNull(); + expect(t.binding().ready.declinedSpecHash).not.toBeNull(); + expect(t.hooks.store.need(need.id)!.status).toBe("done"); + expect(t.hooks.store.escalation(t.esc)).toMatchObject({ status: "resolved" }); + await t.flush(); + expect(t.sends.filter((s) => s.threadId === t.steward).at(-1)!.text).toMatch(/declined ENG-12's spec on the Stewards page/u); + expect(t.projectWakes()).toBeGreaterThan(projectBefore); + }); + + it("bb stewards done approves the spec and resolves the forwarded escalation", async () => { + const t = await forwarded(); + const need = t.need(); + const out = await t.harness.behavior.runCli(["done", need.id, "--project", "p1"]); + expect(out.exitCode).toBe(0); + expect(out.stdout).toMatch(/Approved/u); + expect(t.binding().ready.approval).not.toBeNull(); + expect(t.hooks.store.need(need.id)!.status).toBe("done"); + expect(t.hooks.store.escalation(t.esc)).toMatchObject({ status: "resolved" }); + await t.flush(); + expect(t.sends.filter((s) => s.threadId === t.steward).at(-1)!.text).toMatch(/approved ENG-12's spec from a thread/u); + }); + + it("still asks a question for a forwarded decision", async () => { + const t = await setup(); + t.entities.set("uuid-12", issue()); + await t.ring("linear", "uuid-12"); + const [project, steward] = t.spawns.map((x) => x.id) as [string, string]; + await t.tool("steward_report", { ...base, summary: "Scope unclear.", nextAction: "Wait", escalate: { kind: "decision", question: "Include SSO?", meanwhile: "Wait." } }, steward); + const esc = /(esc_[\w-]+) from ENG-12/u.exec(t.sends.filter((s) => s.threadId === project).at(-1)!.text)![1]!; + expect((await t.tool("steward_update", { binding: "ENG-12", forward: esc }, project)).text).toMatch(/to the user as question qst_/u); + expect(t.hooks.store.openQuestions("p1")).toHaveLength(1); + expect(t.hooks.store.openNeeds(t.hooks.store.find("ENG-12")!.id)).toEqual([]); + }); +}); + describe("the settings page", () => { type Overview = { paused: boolean; projects: Array<{ name: string; configured: boolean; repos: string[]; playbooks: Array<{ kind: string; version: string | null }>; problems: string[]; projectStewardThreadId: string | null; stewards: Array<{ key: string; summary: string | null; actor: string | null; escalations: Array<{ route: string; question: string }> }> }> }; diff --git a/plugins/stewards/server.ts b/plugins/stewards/server.ts index 30fce9c8..66e4e992 100644 --- a/plugins/stewards/server.ts +++ b/plugins/stewards/server.ts @@ -250,6 +250,8 @@ export const rpcContract = defineRpcContract({ key: z.string(), kind: z.string(), url: z.string().nullable(), + /** The escalation this item answers, when the project steward forwarded one. */ + escalationId: z.string().nullable(), what: z.string(), how: z.string().nullable(), threadId: z.string().nullable(), @@ -1970,6 +1972,59 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P return b.kind === "ticket" ? [...own, ...observed.pulls] : own; } + /** + * File or refresh the user's `approve-spec` need for a binding. The plugin + * files it when the gate waits and the approver is the user (`approval: me`), + * and when the project steward forwards an `approval` escalation to the user: + * a forwarded approval is the user's to decide exactly as `approval: me` is. + * Deduped by (binding, kind, url), so the escalation that asked for it is + * linked in `data.escalationId` rather than a second item filed. + */ + function fileApproveSpecNeed(b: Binding, entity: EntitySnapshot, escalationId: string | null): void { + store.fileNeed({ + bindingId: b.id, + kind: "approve-spec", + url: b.url ?? "", + what: `Approve ${b.entityKey}'s spec`, + how: "The ready checklist is met and the ticket is substantial. Approve records the approval on the gate; Decline remembers this spec as declined until it changes.", + data: { specHash: specHashFor(b, entity), ...(escalationId === null ? {} : { escalationId }) }, + filedBy: "plugin", + }); + } + + /** + * Approve or decline a binding's spec as the user, in one step: record the + * verdict on the gate and close the `approve-spec` need, which resolves the + * open `approval` escalations that asked for it (the `steward_update { approve }` + * path). Returns the closure for the steward's wake and the escalations that + * were with the user, for the project steward's wake. `where` reads as + * "on the Stewards page" or "from a thread". + */ + function recordSpecVerdict(b: Binding, action: "approve" | "decline", entity: EntitySnapshot, text: string | null, where: string): { closure: string; forwarded: Escalation[] } { + const forwarded = store.openEscalations(b.id).filter((x) => x.kind === "approval" && x.route === "me"); + const hash = specHashFor(b, entity); + const said = text === null ? "" : `: "${text}"`; + if (action === "approve") { + store.approve(b.id, { at: now(), specHash: hash, by: "user" }, `Approved by the user ${where}${said}`, "user"); + return { closure: `The user approved ${b.entityKey}'s spec ${where}${text === null ? "" : `: ${text}`}.`, forwarded }; + } + store.decline(b.id, hash, `Declined by the user ${where}${said}`, "user"); + return { closure: `The user declined ${b.entityKey}'s spec ${where}${text === null ? "" : `: ${text}`}.`, forwarded }; + } + + /** + * The project steward forwarded an escalation to the user, so it holds it + * until the user answers. Tell it when the answer lands on the page or from + * a thread, naming the closure, so it is not left holding a resolved one. + */ + async function wakeProjectOnForwardedAnswer(b: Binding, closure: string, forwarded: Escalation[]): Promise { + if (forwarded.length === 0) return; + await wakeProject(b.projectId, `${b.entityKey}'s forwarded escalation was answered`, { + digestDue: false, + notes: [`${closure} ${forwarded.map((x) => `Escalation ${x.id}`).join(", ")} ${forwarded.length === 1 ? "is" : "are"} resolved.`], + }); + } + /** * File, refresh and close the plugin's "needs you" items from a snapshot: * `approve-spec` (the user's approval of the ready gate), and, per observed @@ -1980,17 +2035,14 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P const mode = playbook.ready?.approval ?? null; const current = specHashFor(b, observed.entity); const gate = gateState(playbook, b.ready, current); - const wantsSpec = mode === "me" && approvalWanted(gate) && b.endedAt === null && b.ending === null && b.ready.declinedSpecHash !== current; + // A forwarded approval escalation is with the user, so the page's + // Approve/Decline answers it; `approval: me` is the same wait, filed by + // the plugin. Either way the need is the same item, linked to the + // escalation when one is open. + const forwarded = store.openEscalations(b.id).find((x) => x.kind === "approval" && x.route === "me") ?? null; + const wantsSpec = (mode === "me" || forwarded !== null) && approvalWanted(gate) && b.endedAt === null && b.ending === null && b.ready.declinedSpecHash !== current; if (wantsSpec) { - store.fileNeed({ - bindingId: b.id, - kind: "approve-spec", - url: b.url ?? "", - what: `Approve ${b.entityKey}'s spec`, - how: "The ready checklist is met and the ticket is substantial. Approve records the approval on the gate; Decline remembers this spec as declined until it changes.", - data: { specHash: current }, - filedBy: "plugin", - }); + fileApproveSpecNeed(b, observed.entity, forwarded?.id ?? null); } else { store.closeNeeds(b.id, "approve-spec", gate.passed ? "The spec is approved." : "The gate no longer waits on the user."); } @@ -2499,9 +2551,11 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P const all = store.all(projectId); const open = all.filter((b) => b.endedAt === null); const questions = store.openQuestions(projectId); - const asked = new Set(questions.map((q) => q.escalationId).filter((id) => id !== null)); - const withUser = open.flatMap((b) => store.openEscalations(b.id).filter((x) => x.route === "me" && !asked.has(x.id)).map((x) => ({ x, b }))); const needs = open.flatMap((b) => store.openNeeds(b.id).map((n) => needView(n, b))); + // A question or a need covers the escalation it was made for: the + // page's row is the question or the item, never the raw escalation. + const covered = new Set([...questions.map((q) => q.escalationId), ...needs.map((n) => n.escalationId)].filter((id): id is string => id !== null)); + const withUser = open.flatMap((b) => store.openEscalations(b.id).filter((x) => x.route === "me" && !covered.has(x.id)).map((x) => ({ x, b }))); const stuck = open.flatMap((b) => [ ...store.openEscalations(b.id).filter((x) => x.kind === "stuck").map((x) => ({ b, why: `Stuck, with ${x.route === "me" ? "you" : x.route === "parent" ? "the parent steward" : "the project steward"}: ${x.question}`, since: x.createdAt })), ...(b.hold === null ? [] : [{ b, why: `On hold: ${b.hold}`, since: null }]), @@ -2623,17 +2677,13 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P if (action !== "approve" && action !== "decline") return { ok: false, message: "Approve or decline the spec." }; const entity = (b.source === "ops" ? null : await snapshot(b.source, b.entityId).catch(() => null)) ?? b.lastSnapshot?.entity ?? null; if (entity === null) return { ok: false, message: "The ticket could not be read; try again." }; - const hash = specHashFor(b, entity); - if (action === "approve") { - store.approve(b.id, { at: now(), specHash: hash, by: "user" }, `Approved by the user on the stewards page${text === null ? "" : `: "${text}"`}`, "user"); - store.closeNeeds(b.id, "approve-spec", "Approved on the Stewards page."); - after(`The user approved ${b.entityKey}'s spec on the Stewards page${text === null ? "" : `: ${text}`}.`); - return { ok: true, message: `Approved; ${b.entityKey}'s steward has been told.` }; - } - store.decline(b.id, hash, `Declined by the user on the stewards page${text === null ? "" : `: "${text}"`}`, "user"); - store.closeNeeds(b.id, "approve-spec", "Declined on the Stewards page."); - after(`The user declined ${b.entityKey}'s spec on the Stewards page${text === null ? "" : `: ${text}`}.`); - return { ok: true, message: `Declined; ${b.entityKey}'s steward has been told.` }; + // The same path `steward_update { approve }` uses: the verdict is + // recorded on the gate, the need closes, and the open `approval` + // escalations (the forwarded request) are resolved in one step. + const { closure, forwarded } = recordSpecVerdict(b, action, entity, text, "on the Stewards page"); + after(closure); + await wakeProjectOnForwardedAnswer(b, closure, forwarded); + return { ok: true, message: `${action === "approve" ? "Approved" : "Declined"}; ${b.entityKey}'s steward has been told.` }; } if (need.kind === "approve-pr") { @@ -3082,7 +3132,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P }) .optional() .describe("Project steward only: record a question you are asking the user in your reply, so it is kept until answered. With binding, it is about that binding."), - forward: z.string().trim().min(1).max(100).optional().describe("An escalation that reached you and that you should not decide: pass it up. From the project steward it goes to the user — then ask them in your reply."), + forward: z.string().trim().min(1).max(100).optional().describe("An escalation that reached you and that you should not decide: pass it up. From the project steward it goes to the user — an approval becomes an Approve/Decline item on the Stewards page, so do not ask in prose; anything else asks them in your reply."), recommendation: z.string().trim().max(1500).optional().describe("Your recommendation, when forwarding."), priority: z.enum(["urgent", "high", "normal", "low"]).optional(), hold: z.string().trim().max(300).optional().describe('Why it is held; "" lifts the hold. A held steward takes no new actions and starts no workers.'), @@ -3263,10 +3313,15 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P const route = nextRoute(target, forwarding.route); const recommendation = input.recommendation ?? forwarding.recommendation; store.reroute(forwarding.id, route, recommendation); - // Kept as a question to the user too, which closes when the escalation is resolved. Made - // before the await below, so the escalation cannot be resolved in between and leave it open. + // A forwarded approval is the user's to decide exactly as + // `approval: me` is: file the page's `approve-spec` need and keep + // the escalation open, linked to it, instead of a free-text + // question. A forwarded decision stays a question. Made before the + // await below, so the escalation cannot be resolved in between and + // leave the need or question open. + const approvalToUser = route === "me" && forwarding.kind === "approval"; const q = - route !== "me" + approvalToUser || route !== "me" ? null : store.ask({ projectId: target.projectId, @@ -3275,8 +3330,10 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P question: forwarding.question, context: [`A ${forwarding.kind} escalation from ${target.entityKey}${target.title === null ? "" : ` (${target.title})`}.`, `Meanwhile: ${forwarding.meanwhile}`, recommendation === null ? null : `Recommendation: ${recommendation}`].filter((c) => c !== null).join(" "), }); + if (approvalToUser && target.lastSnapshot !== null) fileApproveSpecNeed(target, target.lastSnapshot.entity, forwarding.id); await deliver(target, store.escalation(forwarding.id)!); - if (q !== null) done.push(`forwarded ${forwarding.id} to the user as question ${q.id}: ask them in your reply, then record their answer with guidance + resolve`); + if (approvalToUser) done.push(`forwarded ${forwarding.id} to the user as an approve-spec item: they press Approve or Decline on the Stewards page, so do not ask them in prose`); + else if (q !== null) done.push(`forwarded ${forwarding.id} to the user as question ${q.id}: ask them in your reply, then record their answer with guidance + resolve`); else done.push(`forwarded ${forwarding.id} to the project steward`); } if (!directs) return `${target.entityKey}: ${done.join("; ")}.`; @@ -3340,7 +3397,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P }); /** One open "needs you" item, with whether its button can act now and why not when it cannot. */ - function needView(n: Need, b: Binding): { id: string; bindingId: string; key: string; kind: string; url: string | null; what: string; how: string | null; threadId: string | null; createdAt: number; actionable: boolean; why: string | null } { + function needView(n: Need, b: Binding): { id: string; bindingId: string; key: string; kind: string; url: string | null; escalationId: string | null; what: string; how: string | null; threadId: string | null; createdAt: number; actionable: boolean; why: string | null } { let actionable = true; let why: string | null = null; let threadId: string | null = null; @@ -3361,7 +3418,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P // the action tells the steward to start the worker that requests it. threadId = typeof n.data.workerThreadId === "string" ? n.data.workerThreadId : null; } - return { id: n.id, bindingId: b.id, key: b.entityKey, kind: n.kind, url: /^https?:\/\//iu.test(n.url) ? n.url : null, what: n.what, how: n.how, threadId, createdAt: n.createdAt, actionable, why }; + return { id: n.id, bindingId: b.id, key: b.entityKey, kind: n.kind, url: /^https?:\/\//iu.test(n.url) ? n.url : null, escalationId: typeof n.data.escalationId === "string" ? n.data.escalationId : null, what: n.what, how: n.how, threadId, createdAt: n.createdAt, actionable, why }; } function formatBindings(rows: Binding[]): string { @@ -3676,8 +3733,8 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P }), done: cliCommand({ - summary: "Close a waiting item from a thread", - description: "Closes a `needs` item (need_…) or a question to the user (qst_…), and wakes the steward with it under What changed.", + summary: "Close a waiting item from a thread, or approve a spec item", + description: "Closes a `needs` item (need_…) or a question to the user (qst_…), and wakes the steward with it under What changed. On an `approve-spec` item it records the approval on the gate, resolves the escalation that asked for it, and wakes the steward and the project steward; decline a spec on the Stewards page instead.", positionals: [{ name: "id", description: "The item id (need_…) or question id (qst_…)", required: true }], options: { project: PROJECT_OPTION }, async run(input, ctx) { @@ -3701,6 +3758,20 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P if (n === null) throw new PluginCliError(`No waiting item ${id}.`, { code: "need_not_found", hint: "bb stewards needs lists them." }); if (n.status !== "open") return { exitCode: 0, stdout: `${id} is already closed.` }; const b = store.binding(n.bindingId); + // An `approve-spec` item is a decision, not a step to tick off: + // `done` records the approval through the same path the page's + // Approve button and `steward_update { approve }` use, so the + // gate, the need and the forwarded escalation move together. + // Decline it on the Stewards page. + if (b !== null && n.kind === "approve-spec") { + const entity = b.lastSnapshot?.entity ?? null; + if (entity === null) throw new PluginCliError(`Cannot read ${b.entityKey}'s spec to approve it.`, { code: "need_not_readable", hint: "Look at it again with bb stewards pass, then retry." }); + const { closure, forwarded } = recordSpecVerdict(b, "approve", entity, null, "from a thread"); + store.note(b.id, closure); + scheduleReconcile(b.id); + await wakeProjectOnForwardedAnswer(b, closure, forwarded); + return { exitCode: 0, stdout: `Approved ${id}; ${b.entityKey}'s steward has been told.` }; + } store.closeNeed(n.id, "Closed from a thread."); if (b !== null) { store.note(b.id, `${n.kind} item ${n.id} was closed from a thread.`); diff --git a/plugins/stewards/skills/stewards/SKILL.md b/plugins/stewards/skills/stewards/SKILL.md index 82b036c1..b3485475 100644 --- a/plugins/stewards/skills/stewards/SKILL.md +++ b/plugins/stewards/skills/stewards/SKILL.md @@ -178,8 +178,10 @@ acts as the user, whose rights are broad, and nothing else stops a write. ## If you are the project steward You decide what the stewards below you escalate, from the project's own -guidance, and forward to the user (`steward_update { forward }`, then ask -them in your reply) only what the project file lists as a big decision. +guidance, and forward to the user (`steward_update { forward }`) only what +the project file lists as a big decision. A forwarded `approval` becomes an +Approve/Decline item on the Stewards page, so do not ask it in prose; +anything else you ask them in your reply. Read status with `bb stewards list` and `bb stewards show `, never transcripts. Turn the user's focus ("hold everything touching billing") into `steward_update` calls. A substantial spec whose checklist is met reaches @@ -206,8 +208,10 @@ production: adopt it when the project's guidance says it is worth working (add the label, move it to Todo with `linear_update_issue`; a ticket steward picks it up), or decline with a reason, then resolve the escalation. -Everything you ask the user is a record. Forwarding an escalation to them -makes a question for it; anything else you ask in a reply, record first +Everything you ask the user is a record. Forwarding a non-approval +escalation to them makes a question for it; a forwarded `approval` makes an +`approve-spec` item instead, and the escalation stays open linked to it. +Anything else you ask in a reply, record first with `steward_update { ask: { question, context } }` (with `binding` when it concerns one). Ask one thing per reply, and never ask what the playbook, this skill or the project's guidance settles (models, flags, lanes, who @@ -255,7 +259,7 @@ project. | `bb stewards list [--all] [--json]` | Bindings and their status records | | `bb stewards show ` | One binding in full: gate, guidance, escalations, needs, workers, fingerprints | | `bb stewards needs [--all] [--json]` | What waits on the user, with links and the action each supports | -| `bb stewards done ` | Close a waiting item from a thread; wakes the steward with it | +| `bb stewards done ` | Close a waiting item from a thread; an `approve-spec` item records the approval on the gate and resolves its escalation; wakes the steward with it | | `bb stewards detach ` | One stop turn; stays detached until the label is removed and re-added | | `bb stewards pass [--nightly]` | The mechanical sweep now, or the full nightly pass | | `bb stewards digest` | The latest morning digest | diff --git a/plugins/stewards/wake.ts b/plugins/stewards/wake.ts index 68bc757a..3f0ff413 100644 --- a/plugins/stewards/wake.ts +++ b/plugins/stewards/wake.ts @@ -800,7 +800,11 @@ export function formatRecords(r: DigestRecords, questions: Array<{ question: Que ]; out.push("### What moved", "", ...capped(moved, "Nothing moved."), ""); - const asked = new Set(questions.map(({ question: q }) => q.escalationId).filter((id) => id !== null)); + // A question or a need covers the escalation it was made for: list the + // question or the item, never the raw escalation too. + const asked = new Set( + [...questions.map(({ question: q }) => q.escalationId), ...(r.needs ?? []).map(({ need: n }) => (typeof n.data.escalationId === "string" ? n.data.escalationId : null))].filter((id): id is string => id !== null), + ); const waiting = [ ...questions.map(({ question: q, about }) => `- Question ${q.id} (since ${day(q.createdAt)}${about === null ? "" : `, about ${about.entityKey}`}): ${oneLine(q.question)}`), ...(r.needs ?? []).map(({ need: n, binding }) => `- ${n.kind} (${n.id}, since ${day(n.createdAt)}, ${binding.entityKey}): ${oneLine(n.what)}${n.url === "" ? "" : ` — ${n.url}`}`), From 58afa4f92235cb3384947725fcd85de0fcc05bc5 Mon Sep 17 00:00:00 2001 From: Dylan Trotter Date: Tue, 20 Oct 2026 15:55:03 +0000 Subject: [PATCH 2/2] stewards: address review round 1 on BB-19 - bb stewards done reads a fresh snapshot, like the page's Approve, so both surfaces pin the same spec. - syncNeeds withdraws a forwarded approval escalation when the gate stops waiting, so the page never falls back to the raw escalation's prose row. - Pin the legacy ambiguous-answer branch with a test: a pre-BB-19 question bound to an approval escalation still hands an ambiguous answer back to the project steward. --- plugins/stewards/server.test.ts | 19 +++++++++++++++++++ plugins/stewards/server.ts | 9 +++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/stewards/server.test.ts b/plugins/stewards/server.test.ts index 1e8e5763..6f50956c 100644 --- a/plugins/stewards/server.test.ts +++ b/plugins/stewards/server.test.ts @@ -2502,6 +2502,25 @@ describe("forwarded spec approvals", () => { expect(t.hooks.store.openQuestions("p1")).toHaveLength(1); expect(t.hooks.store.openNeeds(t.hooks.store.find("ENG-12")!.id)).toEqual([]); }); + + it("still interprets an ambiguous answer to a legacy forwarded approval question", async () => { + const t = await setup(); + t.entities.set("uuid-12", issue()); + await t.ring("linear", "uuid-12"); + const [project] = t.spawns.map((x) => x.id) as [string, string]; + const binding = t.hooks.store.find("ENG-12")!; + // A question forwarded before BB-19, kept for live databases: bound to an + // approval escalation and answered with words that are not a verdict. + const esc = t.hooks.store.escalate({ bindingId: binding.id, kind: "approval", question: "Approve ENG-12's spec?", meanwhile: "Waiting.", route: "me", recommendation: null }); + const q = t.hooks.store.ask({ projectId: "p1", bindingId: binding.id, escalationId: esc.id, question: esc.question, context: null }); + const projectWakes = () => t.sends.filter((s) => s.threadId === project).length; + const before = projectWakes(); + expect(await t.harness.callRpc("stewardsAnswerQuestion", { questionId: q.id, answer: "What about SSO?" }, client)).toMatchObject({ ok: true, message: expect.stringMatching(/project steward/u) }); + expect(t.hooks.store.find("ENG-12")!.ready.approval).toBeNull(); + expect(t.hooks.store.find("ENG-12")!.ready.declinedSpecHash).toBeNull(); + expect(t.hooks.store.escalation(esc.id)).toMatchObject({ status: "open", route: "project" }); + expect(projectWakes()).toBeGreaterThan(before); + }); }); describe("the settings page", () => { diff --git a/plugins/stewards/server.ts b/plugins/stewards/server.ts index 66e4e992..f27beed0 100644 --- a/plugins/stewards/server.ts +++ b/plugins/stewards/server.ts @@ -2044,7 +2044,11 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P if (wantsSpec) { fileApproveSpecNeed(b, observed.entity, forwarded?.id ?? null); } else { - store.closeNeeds(b.id, "approve-spec", gate.passed ? "The spec is approved." : "The gate no longer waits on the user."); + const why = gate.passed ? "The spec is approved." : !gate.checklistMet ? "Withdrawn: the ready checklist is no longer met." : !gate.approvalNeeded ? "Withdrawn: the ticket is not substantial." : "Withdrawn."; + store.closeNeeds(b.id, "approve-spec", why); + // The gate no longer waits, so a forwarded request is withdrawn with + // it rather than left open for the page's raw-escalation prose row. + if (forwarded !== null) store.resolve(forwarded.id, why); } for (const pull of observedPulls(b, observed)) { @@ -3764,7 +3768,8 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P // gate, the need and the forwarded escalation move together. // Decline it on the Stewards page. if (b !== null && n.kind === "approve-spec") { - const entity = b.lastSnapshot?.entity ?? null; + // Fresh like the page, so both surfaces pin the same spec. + const entity = (b.source === "ops" ? null : await snapshot(b.source, b.entityId).catch(() => null)) ?? b.lastSnapshot?.entity ?? null; if (entity === null) throw new PluginCliError(`Cannot read ${b.entityKey}'s spec to approve it.`, { code: "need_not_readable", hint: "Look at it again with bb stewards pass, then retry." }); const { closure, forwarded } = recordSpecVerdict(b, "approve", entity, null, "from a thread"); store.note(b.id, closure);