diff --git a/plugins/stewards/app.tsx b/plugins/stewards/app.tsx
index de4a21b0..1f70d2be 100644
--- a/plugins/stewards/app.tsx
+++ b/plugins/stewards/app.tsx
@@ -726,6 +726,7 @@ function StewardRow({ steward: s, now }: { steward: Steward; now: number }) {
)}
{s.waitingOn !== null && (s.waitingUntil === null || s.waitingUntil === undefined) ? Waiting on {s.waitingOn}
: null}
+ {s.wait !== null && s.wait !== undefined ? Typed wait: {s.wait.kind} {s.wait.ref}
: null}
{s.hold !== null ? On hold: {s.hold}
: null}
{s.escalations.map((x, i) => (
@@ -1560,6 +1561,7 @@ function EffortDetail({ board: b, effortKey, refetch }: { board: Board; effortKe
{s.actor === null ? "" : ` (${ACTOR_LABEL[s.actor] ?? s.actor})`}
{s.waitingOn !== null && (s.waitingUntil === null || s.waitingUntil === undefined) ? Waiting on {s.waitingOn}
: null}
+ {s.wait !== null && s.wait !== undefined ? Typed wait: {s.wait.kind} {s.wait.ref}
: null}
{s.roles !== undefined && s.roles.length > 0 ? Role: {s.roles.join(", ")}
: null}
{s.hold !== null ? On hold: {s.hold}{s.holdBehind.length > 0 ? ` (behind ${s.holdBehind.join(", ")})` : ""}
: null}
{s.stuck ? Stuck{stuck === null ? "" : `: ${stuck.why}`}
: null}
diff --git a/plugins/stewards/migrations.snapshot.json b/plugins/stewards/migrations.snapshot.json
index f4acd1a1..fe6bb5c9 100644
--- a/plugins/stewards/migrations.snapshot.json
+++ b/plugins/stewards/migrations.snapshot.json
@@ -137,5 +137,6 @@
"ad2a7b244faee5792ca77b1f36cd80488de8f787360d03f1569e60c869845beb",
"b268ed66797e2953f8b175fa1cdf506531a2fc5e30c52ef43480d81b9efb7c1b",
"c1377801bd4fe44be9cc5fc10c5aca75c9455359b3d5d646d0fb23318a032124",
- "d856f2127e2c5788a01c5ca80b216d1dc9be2a67bb273ad9082bbc69a279ce9a"
+ "d856f2127e2c5788a01c5ca80b216d1dc9be2a67bb273ad9082bbc69a279ce9a",
+ "f1636e9715f38e19e3c21cc7d3008c4f8d734ec26e03eb983961acb7d4cc8949"
]
diff --git a/plugins/stewards/server.test.ts b/plugins/stewards/server.test.ts
index 358b0bba..a2970673 100644
--- a/plugins/stewards/server.test.ts
+++ b/plugins/stewards/server.test.ts
@@ -14603,6 +14603,207 @@ describe("a dated wait (BB-247)", () => {
});
});
+// BB-333 (criterion 4 of BB-291): the typed wait on `steward_report`. PR 1
+// validates, stores and renders it; it derives nothing, so `noWakeSource` is
+// exactly today's. The four fixtures (BB-266, bb-plugins#294, bc-prod#422/
+// BCP-157 and bc-prod#430/BCP-160) pin today's result here; PR 2 asserts the
+// typed derivation, which the comments name.
+describe("a typed wait (BB-333)", () => {
+ const base = { phase: "In Progress", summary: "Waiting.", nextAction: "Wait", actor: "other" as const };
+ const noReview = comment({ id: "r1", author: "jane", body: ``, signedBy: "thr_reviewer", createdAt: "2026-10-14T15:00:00Z" });
+
+ async function ticket() {
+ const t = await setup();
+ t.entities.set("uuid-12", issue({ state: "In Progress", stateType: "started" }));
+ await t.ring("linear", "uuid-12");
+ return { t, steward: t.spawns[1]!.id, b: t.hooks.store.find("ENG-12")! };
+ }
+
+ it("stores a well-formed wait and renders it in `bb stewards show`", async () => {
+ const { t, steward } = await ticket();
+ const report = await t.tool("steward_report", { ...base, waitingOn: "the vendor's reply", wait: { kind: "external", ref: "the vendor's reply" } }, steward);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("ENG-12")!.wait).toEqual({ kind: "external", ref: "the vendor's reply" });
+ expect((await t.harness.behavior.runCli(["show", "ENG-12", "--project", "p1"])).stdout).toContain("typed wait: external the vendor's reply");
+ });
+
+ it("a report with no wait is accepted unchanged, and a later one clears the stored wait", async () => {
+ const { t, steward } = await ticket();
+ await t.tool("steward_report", { ...base, waitingOn: "the vendor's reply", wait: { kind: "external", ref: "the vendor's reply" } }, steward);
+ expect(t.hooks.store.find("ENG-12")!.wait).not.toBeNull();
+ const plain = await t.tool("steward_report", { ...base, waitingOn: "the vendor's reply" }, steward);
+ expect(plain.error).toBe(false);
+ expect(t.hooks.store.find("ENG-12")!.wait).toBeNull();
+ });
+
+ it("refuses an unknown kind, a missing ref, a malformed ref and a date with no date", async () => {
+ const { t, steward } = await ticket();
+ const cases: Array<[Record, RegExp]> = [
+ [{ wait: { kind: "nope", ref: "acme/web#7" } }, /unknown_kind/u],
+ [{ wait: { kind: "pull" } }, /missing_reference/u],
+ [{ wait: { kind: "pull", ref: "acme/web" } }, /malformed_reference/u],
+ [{ wait: { kind: "date", ref: "next Tuesday" } }, /date_wait_without_date/u],
+ ];
+ for (const [extra, pattern] of cases) {
+ const r = await t.tool("steward_report", { ...base, waitingOn: "the vendor's reply", ...extra }, steward);
+ expect(r.error, JSON.stringify(extra)).toBe(true);
+ expect(r.text).toMatch(pattern);
+ }
+ expect(t.hooks.store.find("ENG-12")!.wait).toBeNull();
+ });
+
+ it("downgrades the binding's own pull to external", async () => {
+ const t = await setup();
+ t.entities.set("acme/web#7", pull({ labels: ["bb-managed"], author: "jane" }));
+ await t.ring("github", "acme/web#7");
+ const b = t.hooks.store.find("acme/web#7")!;
+ expect(b.kind).toBe("pr");
+ const report = await t.tool("steward_report", { ...base, waitingOn: "the merge", wait: { kind: "pull", ref: "acme/web#7" } }, b.threadId!);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("acme/web#7")!.wait).toEqual({ kind: "external", ref: "acme/web#7" });
+ expect(report.text).toMatch(/reference_is_self/u);
+ });
+
+ it("downgrades a well-formed ref the plugin cannot resolve to external", async () => {
+ const { t, steward } = await ticket();
+ // The test world watches acme/web only, so a repo it does not watch is unvalidatable.
+ const report = await t.tool("steward_report", { ...base, waitingOn: "the sync PR checks", wait: { kind: "pull", ref: "bitcomplete/bc-prod#430" } }, steward);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("ENG-12")!.wait).toEqual({ kind: "external", ref: "bitcomplete/bc-prod#430" });
+ expect(report.text).toMatch(/unvalidatable_reference/u);
+ });
+
+ it("accepts a well-formed pull ref in a watched repo and leaves it as sent", async () => {
+ const { t, steward } = await ticket();
+ const report = await t.tool("steward_report", { ...base, waitingOn: "the checks", wait: { kind: "pull", ref: "acme/web#9" } }, steward);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("ENG-12")!.wait).toEqual({ kind: "pull", ref: "acme/web#9" });
+ });
+
+ it("accepts a review wait on the binding's own pull", async () => {
+ const t = await setup();
+ t.entities.set("acme/web#7", pull({ labels: ["bb-managed"], author: "jane" }));
+ await t.ring("github", "acme/web#7");
+ const b = t.hooks.store.find("acme/web#7")!;
+ const report = await t.tool("steward_report", { ...base, waitingOn: "the review", wait: { kind: "review", ref: "acme/web#7" } }, b.threadId!);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("acme/web#7")!.wait).toEqual({ kind: "review", ref: "acme/web#7" });
+ });
+
+ it("accepts a deployment wait whose named-target watch is keyed by target", async () => {
+ const { t, b, steward } = await ticket();
+ // A named-target watch is keyed `pullKey::target`, so the ref must match the watch's own key (BB-132).
+ t.hooks.store.patch(b.id, {
+ deployments: {
+ "acme/web#7::bb-gate": { key: "acme/web#7", state: "deploying", mergeSha: null, target: "bb-gate", mergedAt: null, prRepo: "acme/web", files: [], repo: "acme/web", environment: "production", deploymentId: null, deploymentState: null, ref: null, sha: null, url: null, at: t.now(), deadlineAt: null, note: null, workflowRuns: [] },
+ },
+ });
+ const report = await t.tool("steward_report", { ...base, waitingOn: "the bb-gate deploy", wait: { kind: "deployment", ref: "acme/web#7" } }, steward);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("ENG-12")!.wait).toEqual({ kind: "deployment", ref: "acme/web#7" });
+ });
+
+ it("only a valid person wait skips the user-naming waitingOn refusal", async () => {
+ const { t, b, steward } = await ticket();
+ // A question is an open page item the person wait names, and is not an open
+ // need, so only the person-wait skip lets the user-naming report through.
+ const q = t.hooks.store.ask({ projectId: "p1", bindingId: b.id, escalationId: null, question: "Which option?", context: null });
+ const person = await t.tool("steward_report", { ...base, waitingOn: "the owner's approval", wait: { kind: "person", ref: q.id } }, steward);
+ expect(person.error).toBe(false);
+ expect(t.hooks.store.find("ENG-12")!.wait).toEqual({ kind: "person", ref: q.id });
+ // An external wait does not bypass the guard: the user is named with nothing filed.
+ const external = await t.tool("steward_report", { ...base, waitingOn: "the owner's approval", wait: { kind: "external", ref: "the owner's approval" } }, steward);
+ expect(external.error).toBe(true);
+ expect(external.text).toMatch(/names the user, the owner or a human/u);
+ // A person wait that was downgraded to external does not bypass it either.
+ const downgraded = await t.tool("steward_report", { ...base, waitingOn: "the owner's approval", wait: { kind: "person", ref: "need_closed" } }, steward);
+ expect(downgraded.error).toBe(true);
+ expect(downgraded.text).toMatch(/names the user, the owner or a human/u);
+ // And no wait at all is refused as today.
+ const without = await t.tool("steward_report", { ...base, waitingOn: "the owner's approval" }, steward);
+ expect(without.error).toBe(true);
+ expect(without.text).toMatch(/names the user, the owner or a human/u);
+ });
+
+ // BB-266: a ticket with a gate-met own pull, a parked `finished` worker and a
+ // second open own pull, waiting on the plugin auto-merge. The typed ref is
+ // the own gate-met pull, so it is recorded as external (reference_is_self).
+ // TODAY the second open own pull is still a live source, so the wait is not
+ // marked; PR 2 derives the stall from the external wait despite it.
+ it("pins the BB-266 fixture: the second open own pull is a live source, so the wait is not marked", async () => {
+ const t = await setup();
+ t.entities.set(
+ "uuid-12",
+ issue({
+ state: "In Progress",
+ stateType: "started",
+ linkedPulls: [
+ { key: "acme/web#7", url: "https://github.com/acme/web/pull/7" },
+ { key: "acme/web#8", url: "https://github.com/acme/web/pull/8" },
+ ],
+ }),
+ );
+ t.entities.set("acme/web#7", pull({ comments: [noReview] }, { checks: { state: "success", failing: [] } }));
+ t.entities.set("acme/web#8", pull({ id: "acme/web#8", key: "acme/web#8", url: "https://github.com/acme/web/pull/8" }));
+ await t.ring("linear", "uuid-12");
+ // The parked `finished` worker whose branch owns both pulls (BB-266).
+ await t.created("thr_w1", t.spawns[1]!.id, "ENG-12: Implement");
+ t.hooks.store.setWorker("thr_w1", "finished", "Waiting on the owner's approval.");
+ t.hooks.store.parkWorker("thr_w1", "the owner's approval");
+ const b = t.hooks.store.find("ENG-12")!;
+ const report = await t.tool("steward_report", { ...base, waitingOn: "the plugin auto-merge", wait: { kind: "pull", ref: "acme/web#7" } }, b.threadId!);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("ENG-12")!.wait).toEqual({ kind: "external", ref: "acme/web#7" });
+ expect(t.hooks.store.find("ENG-12")!.noWakeSource).toBe(false);
+ });
+
+ // bb-plugins#294: a `pr` binding's own open pull with a free-text wait. The
+ // typed ref is its own pull, so external; a `pr` binding's own pull is never
+ // a source, so today and under PR 2 it stalls.
+ it("pins the bb-plugins#294 fixture: a pr binding's own open pull is not a source, so the wait is marked", async () => {
+ const t = await setup();
+ t.entities.set("acme/web#7", pull({ labels: ["bb-managed"], author: "jane" }));
+ await t.ring("github", "acme/web#7");
+ const b = t.hooks.store.find("acme/web#7")!;
+ expect(b.kind).toBe("pr");
+ const report = await t.tool("steward_report", { ...base, waitingOn: "the dompurify fix on main", wait: { kind: "pull", ref: "acme/web#7" } }, b.threadId!);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("acme/web#7")!.wait).toEqual({ kind: "external", ref: "acme/web#7" });
+ expect(t.hooks.store.find("acme/web#7")!.noWakeSource).toBe(true);
+ });
+
+ // bc-prod#422 / BCP-157: a ticket waiting on the owner's approval, with no
+ // open approve-pr item, beside an open linked pull. The person ref is not an
+ // open page item, so it is recorded as external. TODAY the open pull watch is
+ // a live source and masks it; PR 2 derives the stall despite the mask.
+ it("pins the bc-prod#422/BCP-157 fixture: the open pull watch masks the person wait", async () => {
+ const t = await setup();
+ t.entities.set("uuid-12", issue({ state: "In Progress", stateType: "started", linkedPulls: [{ key: "acme/web#7", url: "https://github.com/acme/web/pull/7" }] }));
+ t.entities.set("acme/web#7", pull({ id: "acme/web#7", key: "acme/web#7", url: "https://github.com/acme/web/pull/7" }));
+ await t.ring("linear", "uuid-12");
+ const b = t.hooks.store.find("ENG-12")!;
+ // `waitingOn` does not name the user: the person wait is the structured
+ // form of the owner's approval, and the guard is not the subject here.
+ const report = await t.tool("steward_report", { ...base, waitingOn: "GitHub approval of acme/web#7", wait: { kind: "person", ref: "need_approve" } }, b.threadId!);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("ENG-12")!.wait).toEqual({ kind: "external", ref: "need_approve" });
+ expect(t.hooks.store.find("ENG-12")!.noWakeSource).toBe(false);
+ });
+
+ // bc-prod#430 / BCP-160: a ticket waiting on a foreign pull's checks, not
+ // linked on the ticket. The ref is well-formed and in a watched repo, so it
+ // is accepted as `pull`. TODAY nothing leases it, so the wait is marked; PR 2
+ // leases it and derives it live, so it is not. The test world's one watched
+ // repo stands in for bc-prod.
+ it("pins the bc-prod#430/BCP-160 fixture: the foreign pull is not leased, so the wait is marked", async () => {
+ const { t, steward } = await ticket();
+ const report = await t.tool("steward_report", { ...base, waitingOn: "bc-prod#430 checks", wait: { kind: "pull", ref: "acme/web#430" } }, steward);
+ expect(report.error).toBe(false);
+ expect(t.hooks.store.find("ENG-12")!.wait).toEqual({ kind: "pull", ref: "acme/web#430" });
+ expect(t.hooks.store.find("ENG-12")!.noWakeSource).toBe(true);
+ });
+});
+
// BB-203: the plugin writes the binding's status from events it observed
// itself, before the steward's next turn, and quiets a running worker's own
// pull request activity only while nothing the user must act on is open.
diff --git a/plugins/stewards/server.ts b/plugins/stewards/server.ts
index a196a18f..a89399c9 100644
--- a/plugins/stewards/server.ts
+++ b/plugins/stewards/server.ts
@@ -137,6 +137,7 @@ import { allPullsMerged, atWork, conflictsOf, finished, normalizeTouches, openPu
import { AUTOMATIC_NAVIGATION_PROVIDER, AUTOMATIC_THREAD_LIST_PROVIDER, BUILTIN_NAVIGATION_ID, BUILTIN_THREAD_LIST_ID, NAVIGATION_PROVIDER_KEY, THREAD_LIST_PROVIDER_KEY } from "./sidebar-provider.js";
import { waitingOnNamesWorker } from "./sidebar.js";
import { advanceStall, parseUntil, pullWatchCounts, type WakeSourceInput } from "./wake-source.js";
+import { WAIT_REFUSAL_MESSAGE, waitInputSchema, waitPhrase, waitSchema, validateWait, type Wait, type WaitContext } from "./wait.js";
import { PROJECT_CHANGED } from "./channels.js";
import { LINEAR_TICKETS, PLAYBOOK_TEMPLATES, projectFileTemplate, stampedTemplate, templateHashes } from "./templates.js";
import { templateWarnings, type CheckFinding } from "./template-stamp.js";
@@ -662,6 +663,8 @@ export const rpcContract = defineRpcContract({
waitingOn: z.string().nullable(),
/** When a dated wait parks the binding, for `waiting on until ` (BB-247). */
waitingUntil: z.number().nullable(),
+ /** The typed wait from the last report (BB-333), or null; rendered on the card. */
+ wait: waitSchema.nullable(),
/** Waiting with nothing the plugin tracks to wake it (BB-154). */
noWakeSource: z.boolean(),
/** BB-255: a failed wake's phrase, `wake failed: `; null when the last wake landed. */
@@ -793,6 +796,8 @@ export const rpcContract = defineRpcContract({
waitingOn: z.string().nullable(),
/** When a dated wait parks the binding, for `waiting on until ` (BB-247). */
waitingUntil: z.number().nullable(),
+ /** The typed wait from the last report (BB-333), or null; rendered on the card. */
+ wait: waitSchema.nullable(),
/** Waiting with nothing the plugin tracks to wake it (BB-154). */
noWakeSource: z.boolean(),
/** BB-255: a failed wake's phrase, `wake failed: `; null when the last wake landed. */
@@ -903,6 +908,8 @@ export const rpcContract = defineRpcContract({
waitingOn: z.string().nullable(),
/** When a dated wait parks the binding, for `waiting on until ` (BB-247). */
waitingUntil: z.number().nullable(),
+ /** The typed wait from the last report (BB-333), or null; the sidebar row carries it for a later render. */
+ wait: waitSchema.nullable(),
/** Waiting with nothing the plugin tracks to wake it (BB-154). */
noWakeSource: z.boolean(),
/** BB-255: a failed wake's phrase, `wake failed: `; null when the last wake landed. */
@@ -9924,6 +9931,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
createdAt: b.createdAt,
workers: store.workers(b.id).filter((w) => w.status === "running").length,
waitingUntil: b.requeueUntil,
+ wait: b.wait,
escalations: store.openEscalations(b.id).map((x) => ({ kind: x.kind, route: x.route, question: x.question })),
})),
};
@@ -10029,6 +10037,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
wokeAt: b.wokeAt,
advancedAt: b.advancedAt,
waitingUntil: b.requeueUntil,
+ wait: b.wait,
workers: store.workers(b.id).filter((w) => w.status === "running").map((w) => ({ threadId: w.threadId, title: w.title })),
assumptions: store.openAssumptions(b.id).map((a) => ({ id: a.id, text: a.text, context: a.context, recordedAt: a.recordedAt, recordedBy: a.recordedBy })),
})),
@@ -10137,6 +10146,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
requeueAt: b.requeueAt,
advancedAt: b.advancedAt,
waitingUntil: b.requeueUntil,
+ wait: b.wait,
workers,
};
});
@@ -11173,6 +11183,11 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
.max(100)
.optional()
.describe('A dated wait: when the thing you wait on has a known end. A date ("2026-12-01", read as 00:00 UTC) or an ISO datetime. It requeues you then instead of requeueAfter, no stall is counted while it is ahead, and it needs waitingOn. A date in the past is ignored with a note. Beyond the playbook\'s `max-wait` (default 90d) it is accepted and noted once to the project steward.'),
+ wait: waitInputSchema
+ .optional()
+ .describe(
+ "The typed form of the wait: a closed kind (pull, review, deployment, worker, binding, date, person, external) and a ref. `pull`/`review` name a pull request (owner/repo#N); `deployment` a deployment-watch key; `worker` a worker thread id (thr_…); `binding` another binding's entity key; `date` an ISO date or datetime; `person` a page item id (need_…, esc_…, qst_…); `external` any free text. A `pull` ref that is the binding's own, or a well-formed ref the plugin cannot resolve, is recorded as `external`; a `review` wait on the binding's own pull is valid. Omit it for today's free-text `waitingOn`.",
+ ),
conditions: z.array(z.string().trim().min(1).max(200)).max(10).optional().describe("Anything else a reader of the status should know at a glance."),
ready: z
.object({
@@ -11451,6 +11466,34 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
untilAt = parsed;
}
}
+ // BB-333: the typed wait. Validated only when a wait is sent, so a
+ // report with today's free-text `waitingOn` and no kind is unchanged.
+ // The four hard refusals write nothing; a self or unvalidatable ref is
+ // accepted and recorded as `external`. Nothing derives from it yet.
+ let wait: Wait | null = null;
+ let waitNote = "";
+ if (input.wait !== undefined) {
+ const ownPulls = b.lastSnapshot === null ? new Set() : await ownPullKeys(b, store.workers(b.id), b.lastSnapshot);
+ const ownKey = lc(b.entityKey);
+ const waitContext: WaitContext = {
+ isOwnPull: (key) => lc(key) === ownKey || ownPulls.has(lc(key)),
+ // A missing config leaves the repo check open rather than
+ // downgrading a ref the plugin simply could not read.
+ isWatchedRepo: (repo) => config === null || config.repos.some((r) => lc(r) === lc(repo)),
+ // The map is keyed by watch id (`pullKey::` when the target is named or there are several), so match the watch's own pull key (BB-132).
+ hasDeployment: (key) => Object.values(b.deployments).some((w) => lc(w.key) === lc(key)),
+ hasOpenBinding: (key) => {
+ const other = store.find(key, b.projectId);
+ return other !== null && other.endedAt === null;
+ },
+ hasWorker: (threadId) => store.worker(threadId) !== null,
+ hasOpenItem: (id) => store.openNeeds(b.id).some((n) => n.id === id) || store.openEscalations(b.id).some((x) => x.id === id) || store.openQuestions(b.projectId).some((q) => q.id === id),
+ };
+ const validation = validateWait(input.wait, input.until, waitContext);
+ if (!validation.ok) return toolError(new Error(validation.message));
+ wait = validation.wait;
+ if (validation.downgraded !== null) waitNote = ` ${WAIT_REFUSAL_MESSAGE[validation.downgraded]}`;
+ }
// `until` wins over an explicit `requeueAfter` in the same report. The
// deployment-deadline min below is untouched; a dated wait is not
// capped by `requeue-default`.
@@ -11461,7 +11504,9 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
// An auto-filed need does not satisfy this: it is filed from prose,
// not the item the user acts on, so a wait naming the user still
// needs a real item or escalation (BB-213).
- if (waitingOn !== null && namesUserAsBlocker(waitingOn) && store.openNeeds(b.id).filter((n) => !isAutoFiledNeed(n)).length === 0 && (input.needs ?? []).length === 0) {
+ // Only a stored `person` wait — one that resolved to an open page item and was not downgraded — bypasses the guard: the item it names is itself what reaches the page. An `external` wait, or a `person` wait downgraded to `external`, still has to file the item.
+ const personWait = wait !== null && wait.kind === "person";
+ if (!personWait && waitingOn !== null && namesUserAsBlocker(waitingOn) && store.openNeeds(b.id).filter((n) => !isAutoFiledNeed(n)).length === 0 && (input.needs ?? []).length === 0) {
return toolError(
new Error(
`waitingOn names the user, the owner or a human, but nothing is filed for them. File it as a needs item (steward_report { needs: [{ kind, url, what, how }] }) — or, for a credential, a step outside the repos or a decision, raise it with steward_report { escalate: { kind, question, meanwhile } } — and it appears on the Stewards page; waitingOn stays for third parties.`,
@@ -11563,6 +11608,8 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
return deadline === null ? at : Math.min(at, deadline);
})(),
requeueUntil: untilAt,
+ // A report replaces the typed wait; a report without one clears it.
+ wait,
...(noteBeyondMaxWait ? { requeueUntilNoted: untilAt } : {}),
awaitingReport: false,
missedReports: 0,
@@ -11783,14 +11830,14 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
// correction: an unknown id is ignored and named, never a failure.
const citesNote = input.cites === undefined ? "" : ` ${citationLines(await countCitations(b.projectId, b.id, input.cites)).join("; ")}.`;
if (b.ending === "terminal") {
- if (b.followThrough === null) return `Reported.${untilNote}${replacedNote}${filingNote}${escalated}${deploymentNote}${citesNote} The binding ends when this turn does: running workers are stopped and the thread is archived. End the turn now.`;
- return `Reported.${untilNote}${replacedNote}${filingNote}${escalated}${deploymentNote}${citesNote} The binding stays open to follow through until ${iso(followThroughUntil!)}; running workers keep going. You will be woken when a worker finishes or something actionable changes, or ${requeuePhrase}. End the turn now.`;
+ if (b.followThrough === null) return `Reported.${untilNote}${waitNote}${replacedNote}${filingNote}${escalated}${deploymentNote}${citesNote} The binding ends when this turn does: running workers are stopped and the thread is archived. End the turn now.`;
+ return `Reported.${untilNote}${waitNote}${replacedNote}${filingNote}${escalated}${deploymentNote}${citesNote} The binding stays open to follow through until ${iso(followThroughUntil!)}; running workers keep going. You will be woken when a worker finishes or something actionable changes, or ${requeuePhrase}. End the turn now.`;
}
const recorded = opsTickets.length === 0 ? "" : ` Recorded ${opsTickets.map((t) => `${t.ticket} (${t.did})`).join(", ")} against ${opsTickets.length === 1 ? "its fingerprint" : "their fingerprints"}.`;
if (gateJustPassed && nothingPending) {
- return `Reported.${untilNote}${replacedNote}${recorded}${filingNote}${escalated}${citesNote} Ready gate: passed and nothing schedules you. Move the ticket to In Progress and start the worker now, in this turn, with the task in the In Progress instructions; do not end the turn first.`;
+ return `Reported.${untilNote}${waitNote}${replacedNote}${recorded}${filingNote}${escalated}${citesNote} Ready gate: passed and nothing schedules you. Move the ticket to In Progress and start the worker now, in this turn, with the task in the In Progress instructions; do not end the turn first.`;
}
- return `Reported.${untilNote}${replacedNote}${recorded}${filingNote}${gateNote}${escalated}${citesNote} You will be woken when something actionable changes, or ${requeuePhrase}. End the turn now.`;
+ return `Reported.${untilNote}${waitNote}${replacedNote}${recorded}${filingNote}${gateNote}${escalated}${citesNote} You will be woken when something actionable changes, or ${requeuePhrase}. End the turn now.`;
} catch (error) {
return toolError(error);
}
@@ -12665,7 +12712,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
: `looked ${iso(alertmanager.at)}: ${alertmanager.findings.length === 0 ? "nothing to do" : `${alertmanager.findings.length} alert(s) new, rung or resolved`}`;
const needs = store.openNeeds(b.id);
const flags = [b.endedAt === null ? null : `ended: ${b.endReason}`, watch, b.adoptedBy === null ? null : `adopted by ${b.adoptedBy}`, b.priority === null ? null : `priority ${b.priority}`, b.noMorePulls === true ? "no more pull requests" : null, b.hold === null ? null : `HOLD: ${b.hold}${b.holdBehind.length === 0 ? "" : ` (behind ${b.holdBehind.join(", ")})`}${b.holdStack.length === 0 ? "" : ` (stacked on ${b.holdStack.join(", ")})`}`, b.mergeBehind.length === 0 ? null : `MERGE HOLD: behind ${b.mergeBehind.join(", ")}`, b.stackedPulls.length === 0 ? null : `BASE OF: ${b.stackedPulls.join(", ")}`, ...open.map((x) => `${x.kind} escalation ${x.id} with ${x.route}`), ...needs.map((n) => `${n.kind} need ${n.id}${n.url === "" ? "" : ` (${n.url})`}`), unheardWait(s, open, needs), asksForOpenApproval(s, open, needs)].filter((f) => f !== null);
- return `${b.entityKey} — ${b.kind}, ${b.phase ?? "?"}${roles.length === 0 ? "" : `, role ${roles.join(", ")}`}${b.threadId === null ? "" : `, thread ${b.threadId}`}\n ${s === null ? "no report yet" : `${s.summary} Next: ${s.nextAction} (${s.actor})${b.noWakeSource ? "; waiting, no wake source" : s.waitingOn === null ? "" : `; waiting on ${s.waitingOn}${b.requeueUntil === null ? "" : ` until ${iso(b.requeueUntil).slice(0, 10)}`}`}`}${flags.length > 0 ? `\n [${flags.join("; ")}]` : ""}`;
+ return `${b.entityKey} — ${b.kind}, ${b.phase ?? "?"}${roles.length === 0 ? "" : `, role ${roles.join(", ")}`}${b.threadId === null ? "" : `, thread ${b.threadId}`}\n ${s === null ? "no report yet" : `${s.summary} Next: ${s.nextAction} (${s.actor})${b.noWakeSource ? "; waiting, no wake source" : s.waitingOn === null ? "" : `; waiting on ${s.waitingOn}${b.requeueUntil === null ? "" : ` until ${iso(b.requeueUntil).slice(0, 10)}`}`}`}${b.wait === null ? "" : `; typed wait: ${waitPhrase(b.wait)}`}${flags.length > 0 ? `\n [${flags.join("; ")}]` : ""}`;
})
.join("\n");
}
diff --git a/plugins/stewards/store.test.ts b/plugins/stewards/store.test.ts
index afb2ebf7..c3a432b0 100644
--- a/plugins/stewards/store.test.ts
+++ b/plugins/stewards/store.test.ts
@@ -1,7 +1,7 @@
import Database from "better-sqlite3";
import { describe, expect, it } from "vitest";
import { z } from "zod";
-import { ACTOR_MIGRATIONS, ALERTMANAGER_LOOK_MIGRATIONS, BACKLOG_LOOK_MIGRATIONS, BACKLOG_SNAPSHOT_MIGRATIONS, CHECK_FINDING_MIGRATIONS, HUDDLE_MIGRATIONS, APPROVAL_MARKER_MIGRATIONS, ASSESSMENT_MIGRATIONS, ASSUMPTION_MIGRATIONS, BASE_MIGRATIONS, CHAIN_MIGRATIONS, DATED_WAIT_MIGRATIONS, DEPS_DECISION_MIGRATIONS, ENDED_READ_MIGRATIONS, ESCALATION_ROUTE_MIGRATIONS, GUIDANCE_MIGRATIONS, IDLE_MIGRATIONS, LESSON_COUNTER_MIGRATIONS, LESSON_PR_MIGRATIONS, LESSON_TIER_MIGRATIONS, MERGE_BEHIND_MIGRATIONS, MIGRATIONS, PULL_REQUESTER_MIGRATIONS, PULL_WATCH_MIGRATIONS, RATIONALE_MIGRATIONS, RETARGET_PULLS_MIGRATIONS, REVIEWER_MODEL_MIGRATIONS, REVIEWER_REQUEST_MIGRATIONS, SERVER_SETTINGS_MIGRATIONS, STACK_MIGRATIONS, STACKED_PULLS_MIGRATIONS, VALIDATION_MIGRATIONS, WAKE_RETRY_MIGRATIONS, WAKE_SOURCE_MIGRATIONS, WORKER_CHECK_MIGRATIONS, STANDUP_MIGRATIONS, STANDUP_BINDING_MIGRATIONS, STANDUP_DELEGATION_MIGRATIONS, STANDUP_COMPLETED_MIGRATIONS, WORKER_STOP_REASON_MIGRATIONS, WORKER_PARK_MIGRATIONS, createStore, lessonScope, statusRecordSchema, type Binding } from "./store.js";
+import { ACTOR_MIGRATIONS, ALERTMANAGER_LOOK_MIGRATIONS, BACKLOG_LOOK_MIGRATIONS, BACKLOG_SNAPSHOT_MIGRATIONS, CHECK_FINDING_MIGRATIONS, HUDDLE_MIGRATIONS, TYPED_WAIT_MIGRATIONS, APPROVAL_MARKER_MIGRATIONS, ASSESSMENT_MIGRATIONS, ASSUMPTION_MIGRATIONS, BASE_MIGRATIONS, CHAIN_MIGRATIONS, DATED_WAIT_MIGRATIONS, DEPS_DECISION_MIGRATIONS, ENDED_READ_MIGRATIONS, ESCALATION_ROUTE_MIGRATIONS, GUIDANCE_MIGRATIONS, IDLE_MIGRATIONS, LESSON_COUNTER_MIGRATIONS, LESSON_PR_MIGRATIONS, LESSON_TIER_MIGRATIONS, MERGE_BEHIND_MIGRATIONS, MIGRATIONS, PULL_REQUESTER_MIGRATIONS, PULL_WATCH_MIGRATIONS, RATIONALE_MIGRATIONS, RETARGET_PULLS_MIGRATIONS, REVIEWER_MODEL_MIGRATIONS, REVIEWER_REQUEST_MIGRATIONS, SERVER_SETTINGS_MIGRATIONS, STACK_MIGRATIONS, STACKED_PULLS_MIGRATIONS, VALIDATION_MIGRATIONS, WAKE_RETRY_MIGRATIONS, WAKE_SOURCE_MIGRATIONS, WORKER_CHECK_MIGRATIONS, STANDUP_MIGRATIONS, STANDUP_BINDING_MIGRATIONS, STANDUP_DELEGATION_MIGRATIONS, STANDUP_COMPLETED_MIGRATIONS, WORKER_STOP_REASON_MIGRATIONS, WORKER_PARK_MIGRATIONS, createStore, lessonScope, statusRecordSchema, type Binding } from "./store.js";
/** MIGRATIONS without the groups appended after the ones these order tests assert. */
const beforeActorMigrations = MIGRATIONS.slice(0, MIGRATIONS.indexOf(ACTOR_MIGRATIONS[0]!));
@@ -744,8 +744,8 @@ describe("the actor rename migration (BB-97)", () => {
// and reviewer-request tables after that, BB-329 appended the worker park
// column after that, BB-334 appended the backlog look column after that,
// and BB-328 appended the check-findings table after that. BB-334's
- // snapshot column is the newest.
- const groups = [BACKLOG_SNAPSHOT_MIGRATIONS, CHECK_FINDING_MIGRATIONS, BACKLOG_LOOK_MIGRATIONS, WORKER_PARK_MIGRATIONS, REVIEWER_REQUEST_MIGRATIONS, PULL_REQUESTER_MIGRATIONS, ALERTMANAGER_LOOK_MIGRATIONS, STANDUP_COMPLETED_MIGRATIONS, STANDUP_DELEGATION_MIGRATIONS, STANDUP_BINDING_MIGRATIONS, STANDUP_MIGRATIONS, HUDDLE_MIGRATIONS, ENDED_READ_MIGRATIONS, ASSESSMENT_MIGRATIONS, STACKED_PULLS_MIGRATIONS, RETARGET_PULLS_MIGRATIONS, MERGE_BEHIND_MIGRATIONS, WAKE_RETRY_MIGRATIONS, DATED_WAIT_MIGRATIONS, ASSUMPTION_MIGRATIONS, WORKER_STOP_REASON_MIGRATIONS, DEPS_DECISION_MIGRATIONS, ESCALATION_ROUTE_MIGRATIONS, STACK_MIGRATIONS, PULL_WATCH_MIGRATIONS, SERVER_SETTINGS_MIGRATIONS, WAKE_SOURCE_MIGRATIONS, REVIEWER_MODEL_MIGRATIONS, LESSON_PR_MIGRATIONS, ACTOR_MIGRATIONS, APPROVAL_MARKER_MIGRATIONS];
+ // snapshot column followed, and BB-333's typed wait column is the newest.
+ const groups = [TYPED_WAIT_MIGRATIONS, BACKLOG_SNAPSHOT_MIGRATIONS, CHECK_FINDING_MIGRATIONS, BACKLOG_LOOK_MIGRATIONS, WORKER_PARK_MIGRATIONS, REVIEWER_REQUEST_MIGRATIONS, PULL_REQUESTER_MIGRATIONS, ALERTMANAGER_LOOK_MIGRATIONS, STANDUP_COMPLETED_MIGRATIONS, STANDUP_DELEGATION_MIGRATIONS, STANDUP_BINDING_MIGRATIONS, STANDUP_MIGRATIONS, HUDDLE_MIGRATIONS, ENDED_READ_MIGRATIONS, ASSESSMENT_MIGRATIONS, STACKED_PULLS_MIGRATIONS, RETARGET_PULLS_MIGRATIONS, MERGE_BEHIND_MIGRATIONS, WAKE_RETRY_MIGRATIONS, DATED_WAIT_MIGRATIONS, ASSUMPTION_MIGRATIONS, WORKER_STOP_REASON_MIGRATIONS, DEPS_DECISION_MIGRATIONS, ESCALATION_ROUTE_MIGRATIONS, STACK_MIGRATIONS, PULL_WATCH_MIGRATIONS, SERVER_SETTINGS_MIGRATIONS, WAKE_SOURCE_MIGRATIONS, REVIEWER_MODEL_MIGRATIONS, LESSON_PR_MIGRATIONS, ACTOR_MIGRATIONS, APPROVAL_MARKER_MIGRATIONS];
let end = MIGRATIONS.length;
for (const group of groups) {
expect(MIGRATIONS.slice(end - group.length, end)).toEqual([...group]);
@@ -842,10 +842,12 @@ describe("the escalation route rename migration (BB-209)", () => {
// flag after that, BB-314's Alertmanager look column after that,
// BB-327's delegate-set and reviewer-request tables after that, BB-329's
// worker park column after that, BB-334's backlog look column after that,
- // BB-328's check-findings table after that, and BB-334's backlog snapshot
- // column last.
- const withoutBacklogSnapshot = MIGRATIONS.slice(0, -BACKLOG_SNAPSHOT_MIGRATIONS.length);
- expect(MIGRATIONS.slice(-BACKLOG_SNAPSHOT_MIGRATIONS.length)).toEqual([...BACKLOG_SNAPSHOT_MIGRATIONS]);
+ // BB-328's check-findings table after that, BB-334's backlog snapshot
+ // column after that, and BB-333's typed wait column last.
+ const withoutTypedWait = MIGRATIONS.slice(0, -TYPED_WAIT_MIGRATIONS.length);
+ expect(MIGRATIONS.slice(-TYPED_WAIT_MIGRATIONS.length)).toEqual([...TYPED_WAIT_MIGRATIONS]);
+ const withoutBacklogSnapshot = withoutTypedWait.slice(0, -BACKLOG_SNAPSHOT_MIGRATIONS.length);
+ expect(withoutTypedWait.slice(-BACKLOG_SNAPSHOT_MIGRATIONS.length)).toEqual([...BACKLOG_SNAPSHOT_MIGRATIONS]);
const withoutCheckFindings = withoutBacklogSnapshot.slice(0, -CHECK_FINDING_MIGRATIONS.length);
expect(withoutBacklogSnapshot.slice(-CHECK_FINDING_MIGRATIONS.length)).toEqual([...CHECK_FINDING_MIGRATIONS]);
const withoutBacklogLook = withoutCheckFindings.slice(0, -BACKLOG_LOOK_MIGRATIONS.length);
diff --git a/plugins/stewards/store.ts b/plugins/stewards/store.ts
index 7b16a798..18161690 100644
--- a/plugins/stewards/store.ts
+++ b/plugins/stewards/store.ts
@@ -16,6 +16,7 @@ import { deploymentsSchema, type Deployments } from "./deploy.js";
import { backlogLookSchema, backlogSnapshotSchema, opsLookSchema, type BacklogLook, type BacklogSnapshot, type FingerprintRow, type OpsLook } from "./ops.js";
import { sentryLookSchema, type SentryLook } from "./sentry.js";
import { alertmanagerLookSchema, type AlertmanagerLook } from "./alertmanager.js";
+import { waitSchema, type Wait } from "./wait.js";
import type { GuidanceCitation } from "./guidance.js";
import { APPROVAL_MARKER_MIGRATIONS, APPROVALS_CHAIN_MIGRATIONS, createApprovalsStore, PULL_REQUESTER_MIGRATIONS, REVIEWER_REQUEST_MIGRATIONS } from "./approvals-store.js";
export type { ProjectApproval } from "./approvals-store.js";
@@ -762,7 +763,15 @@ export const CHECK_FINDING_MIGRATIONS = [
// Appended after BB-328's check-findings table, the last shipped group.
export const BACKLOG_SNAPSHOT_MIGRATIONS = [`ALTER TABLE bindings ADD COLUMN backlog_snapshot TEXT`];
-export const MIGRATIONS = [...BASE_MIGRATIONS, ...CHAIN_MIGRATIONS, ...LESSON_COUNTER_MIGRATIONS, ...WORKER_CHECK_MIGRATIONS, ...DECLINED_PR_MIGRATIONS, ...DEPLOYMENT_MIGRATIONS, ...FINISHED_AND_DIGEST_MIGRATIONS, ...LESSON_TIER_MIGRATIONS, ...RATIONALE_MIGRATIONS, ...VALIDATION_MIGRATIONS, ...GUIDANCE_MIGRATIONS, ...IDLE_MIGRATIONS, ...APPROVAL_MARKER_MIGRATIONS, ...ACTOR_MIGRATIONS, ...LESSON_PR_MIGRATIONS, ...REVIEWER_MODEL_MIGRATIONS, ...WAKE_SOURCE_MIGRATIONS, ...SERVER_SETTINGS_MIGRATIONS, ...PULL_WATCH_MIGRATIONS, ...STACK_MIGRATIONS, ...ESCALATION_ROUTE_MIGRATIONS, ...DEPS_DECISION_MIGRATIONS, ...WORKER_STOP_REASON_MIGRATIONS, ...ASSUMPTION_MIGRATIONS, ...DATED_WAIT_MIGRATIONS, ...WAKE_RETRY_MIGRATIONS, ...MERGE_BEHIND_MIGRATIONS, ...RETARGET_PULLS_MIGRATIONS, ...STACKED_PULLS_MIGRATIONS, ...ASSESSMENT_MIGRATIONS, ...ENDED_READ_MIGRATIONS, ...HUDDLE_MIGRATIONS, ...STANDUP_MIGRATIONS, ...STANDUP_BINDING_MIGRATIONS, ...STANDUP_DELEGATION_MIGRATIONS, ...STANDUP_COMPLETED_MIGRATIONS, ...ALERTMANAGER_LOOK_MIGRATIONS, ...PULL_REQUESTER_MIGRATIONS, ...REVIEWER_REQUEST_MIGRATIONS, ...WORKER_PARK_MIGRATIONS, ...BACKLOG_LOOK_MIGRATIONS, ...CHECK_FINDING_MIGRATIONS, ...BACKLOG_SNAPSHOT_MIGRATIONS];
+// BB-333: a steward's typed wait (`{kind, ref}`), the structured form of the
+// free-text `waitingOn`. Additive and nullable: an old row reads as no typed
+// wait, and a pre-migration build never reads the column. Appended after every
+// group already shipped, including BB-334's backlog columns and BB-328's
+// check-findings table, so no recorded index moves. PR 1 stores and renders
+// it; nothing derives from it yet.
+export const TYPED_WAIT_MIGRATIONS = [`ALTER TABLE bindings ADD COLUMN wait TEXT`];
+
+export const MIGRATIONS = [...BASE_MIGRATIONS, ...CHAIN_MIGRATIONS, ...LESSON_COUNTER_MIGRATIONS, ...WORKER_CHECK_MIGRATIONS, ...DECLINED_PR_MIGRATIONS, ...DEPLOYMENT_MIGRATIONS, ...FINISHED_AND_DIGEST_MIGRATIONS, ...LESSON_TIER_MIGRATIONS, ...RATIONALE_MIGRATIONS, ...VALIDATION_MIGRATIONS, ...GUIDANCE_MIGRATIONS, ...IDLE_MIGRATIONS, ...APPROVAL_MARKER_MIGRATIONS, ...ACTOR_MIGRATIONS, ...LESSON_PR_MIGRATIONS, ...REVIEWER_MODEL_MIGRATIONS, ...WAKE_SOURCE_MIGRATIONS, ...SERVER_SETTINGS_MIGRATIONS, ...PULL_WATCH_MIGRATIONS, ...STACK_MIGRATIONS, ...ESCALATION_ROUTE_MIGRATIONS, ...DEPS_DECISION_MIGRATIONS, ...WORKER_STOP_REASON_MIGRATIONS, ...ASSUMPTION_MIGRATIONS, ...DATED_WAIT_MIGRATIONS, ...WAKE_RETRY_MIGRATIONS, ...MERGE_BEHIND_MIGRATIONS, ...RETARGET_PULLS_MIGRATIONS, ...STACKED_PULLS_MIGRATIONS, ...ASSESSMENT_MIGRATIONS, ...ENDED_READ_MIGRATIONS, ...HUDDLE_MIGRATIONS, ...STANDUP_MIGRATIONS, ...STANDUP_BINDING_MIGRATIONS, ...STANDUP_DELEGATION_MIGRATIONS, ...STANDUP_COMPLETED_MIGRATIONS, ...ALERTMANAGER_LOOK_MIGRATIONS, ...PULL_REQUESTER_MIGRATIONS, ...REVIEWER_REQUEST_MIGRATIONS, ...WORKER_PARK_MIGRATIONS, ...BACKLOG_LOOK_MIGRATIONS, ...CHECK_FINDING_MIGRATIONS, ...BACKLOG_SNAPSHOT_MIGRATIONS, ...TYPED_WAIT_MIGRATIONS];
// ---- values kept as JSON ------------------------------------------------------------
@@ -998,6 +1007,8 @@ export type Binding = {
backlogLook: BacklogLook | null;
/** The issue ids as of the last digest that reported this backlog; null before the first. */
backlogSnapshot: BacklogSnapshot | null;
+ /** The typed wait from the last `steward_report` (BB-333), or null; the free-text `waitingOn` stays on the status record. */
+ wait: Wait | null;
/** Per-pull-request deployment state, keyed by the pull request's key (BB-53). Empty with no deployment target. */
deployments: Deployments;
/** When the binding became idle in an active stage, or null (BB-83). */
@@ -1095,6 +1106,7 @@ function rowToBinding(r: BindingRow): Binding {
alertmanagerLook: json(alertmanagerLookSchema.nullable(), str("alertmanager_look"), null),
backlogLook: json(backlogLookSchema.nullable(), str("backlog_look"), null),
backlogSnapshot: json(backlogSnapshotSchema.nullable(), str("backlog_snapshot"), null),
+ wait: json(waitSchema.nullable(), str("wait"), null),
deployments: json(deploymentsSchema, str("deployments"), {}),
idleSince: num("idle_since"),
idleWokenAt: num("idle_woken_at"),
@@ -1170,6 +1182,7 @@ const COLUMNS = {
alertmanagerLook: "alertmanager_look",
backlogLook: "backlog_look",
backlogSnapshot: "backlog_snapshot",
+ wait: "wait",
deployments: "deployments",
idleSince: "idle_since",
idleWokenAt: "idle_woken_at",
@@ -1221,6 +1234,8 @@ const VISIBLE_COLUMNS = [
"no_wake_source",
// BB-247: a dated wait changes line two's phrase too.
"requeue_until",
+ // BB-333: the typed wait renders on the card and in `bb stewards show`.
+ "wait",
// BB-255: a failed wake's phrase is the visible line two.
"wake_failure",
] as const satisfies ReadonlyArray<(typeof COLUMNS)[keyof typeof COLUMNS]>;
diff --git a/plugins/stewards/wait.test.ts b/plugins/stewards/wait.test.ts
new file mode 100644
index 00000000..bbe26bd8
--- /dev/null
+++ b/plugins/stewards/wait.test.ts
@@ -0,0 +1,97 @@
+// BB-333: the typed wait's pure validation. The six named cases are checked
+// here without a store: an unknown kind, a missing or malformed reference and a
+// date wait with no date are hard refusals; a self or unvalidatable reference is
+// accepted and recorded as `external`.
+import { describe, expect, it } from "vitest";
+import { WAIT_KINDS, isEntityKey, validateWait, type WaitContext } from "./wait.js";
+
+const ctx = (over: Partial = {}): WaitContext => ({
+ isOwnPull: () => false,
+ isWatchedRepo: () => true,
+ hasDeployment: () => true,
+ hasOpenBinding: () => true,
+ hasWorker: () => true,
+ hasOpenItem: () => true,
+ ...over,
+});
+
+const v = (kind: string, ref: string | undefined, over: Partial = {}, until?: string) => validateWait({ kind, ref }, until, ctx(over));
+
+/** A well-formed ref for each kind, so the loop covers the whole set. */
+const wellFormed: Record<(typeof WAIT_KINDS)[number], string> = {
+ pull: "acme/web#7",
+ review: "https://github.com/acme/web/pull/7",
+ deployment: "acme/web#7",
+ worker: "thr_w1",
+ binding: "ENG-12",
+ date: "2026-12-01",
+ person: "need_1",
+ external: "the vendor's reply",
+};
+
+describe("the typed wait: the closed kind set", () => {
+ it("accepts every kind with a well-formed ref", () => {
+ for (const kind of WAIT_KINDS) {
+ const ref = wellFormed[kind];
+ expect(v(kind, ref), kind).toMatchObject({ ok: true, wait: { kind, ref }, downgraded: null });
+ }
+ });
+
+ it("refuses an unknown kind by name", () => {
+ expect(v("nope", "acme/web#7")).toMatchObject({ ok: false, refusal: "unknown_kind" });
+ });
+
+ it("refuses a missing or empty reference by name", () => {
+ expect(v("pull", undefined)).toMatchObject({ ok: false, refusal: "missing_reference" });
+ expect(v("pull", " ")).toMatchObject({ ok: false, refusal: "missing_reference" });
+ });
+
+ it("refuses a malformed reference by name for each parsing kind", () => {
+ expect(v("pull", "acme/web")).toMatchObject({ refusal: "malformed_reference" });
+ expect(v("review", "not-a-pull")).toMatchObject({ refusal: "malformed_reference" });
+ expect(v("deployment", "acme/web")).toMatchObject({ refusal: "malformed_reference" });
+ expect(v("worker", "thr")).toMatchObject({ refusal: "malformed_reference" });
+ expect(v("binding", "not a key")).toMatchObject({ refusal: "malformed_reference" });
+ expect(v("person", "pr_1")).toMatchObject({ refusal: "malformed_reference" });
+ });
+
+ it("refuses a date wait with no date in ref and no until", () => {
+ expect(v("date", "next Tuesday")).toMatchObject({ ok: false, refusal: "date_wait_without_date" });
+ // An until in the same report supplies the date.
+ expect(v("date", "next Tuesday", {}, "2026-12-01")).toMatchObject({ ok: true, wait: { kind: "date", ref: "next Tuesday" } });
+ expect(v("date", "2026-12-01")).toMatchObject({ ok: true, wait: { kind: "date", ref: "2026-12-01" } });
+ });
+
+ it("accepts a Linear key or a pull key as a binding reference", () => {
+ expect(isEntityKey("ENG-12")).toBe(true);
+ expect(isEntityKey("acme/web#7")).toBe(true);
+ expect(isEntityKey("not a key")).toBe(false);
+ });
+
+ it("accepts a base64url page-item or worker id", () => {
+ // `newId` produces 9 random bytes as base64url, so the suffix can hold `-` and `_`.
+ expect(v("person", "qst_7bXtzENlTTc_")).toMatchObject({ ok: true, wait: { kind: "person", ref: "qst_7bXtzENlTTc_" } });
+ expect(v("person", "esc_WRoXHJxRrNPZ")).toMatchObject({ ok: true });
+ expect(v("worker", "thr_ab-cd_ef")).toMatchObject({ ok: true, wait: { kind: "worker", ref: "thr_ab-cd_ef" } });
+ });
+});
+
+describe("the typed wait: the downgrade to external", () => {
+ it("downgrades a pull ref that is the binding's own, but not a review ref", () => {
+ expect(v("pull", "acme/web#7", { isOwnPull: () => true })).toMatchObject({ ok: true, wait: { kind: "external", ref: "acme/web#7" }, downgraded: "reference_is_self" });
+ // A `review` wait on the same own pull is valid and live while unreviewed (the BB-333 design's bb-plugins#294 note).
+ expect(v("review", "acme/web#7", { isOwnPull: () => true })).toMatchObject({ ok: true, wait: { kind: "review", ref: "acme/web#7" }, downgraded: null });
+ });
+
+ it("downgrades a well-formed ref the plugin cannot resolve", () => {
+ expect(v("pull", "acme/web#7", { isWatchedRepo: () => false })).toMatchObject({ downgraded: "unvalidatable_reference", wait: { kind: "external" } });
+ expect(v("deployment", "acme/web#7", { hasDeployment: () => false })).toMatchObject({ downgraded: "unvalidatable_reference" });
+ expect(v("worker", "thr_w1", { hasWorker: () => false })).toMatchObject({ downgraded: "unvalidatable_reference" });
+ expect(v("binding", "ENG-99", { hasOpenBinding: () => false })).toMatchObject({ downgraded: "unvalidatable_reference" });
+ expect(v("person", "need_1", { hasOpenItem: () => false })).toMatchObject({ downgraded: "unvalidatable_reference" });
+ });
+
+ it("leaves an external wait alone", () => {
+ expect(v("external", "the vendor's reply")).toMatchObject({ ok: true, wait: { kind: "external", ref: "the vendor's reply" }, downgraded: null });
+ });
+});
diff --git a/plugins/stewards/wait.ts b/plugins/stewards/wait.ts
new file mode 100644
index 00000000..abd998c8
--- /dev/null
+++ b/plugins/stewards/wait.ts
@@ -0,0 +1,163 @@
+// BB-333 (criterion 4 of BB-291): the typed wait on `steward_report`. A wait is
+// a closed kind plus a reference; free text stays the human annotation. This
+// module owns the kind set, the report input schema, the named refusals and the
+// self / unvalidatable downgrade to `external`.
+//
+// It derives nothing: PR 1 only validates, stores and renders the wait. The
+// liveness, idle and stall derivation from the kind is PR 2, in the assessment
+// module beside `noWakeSource`.
+import { z } from "zod";
+import { parsePullRef } from "./github.js";
+import { parseUntil } from "./wake-source.js";
+
+/**
+ * The closed kind set. `pull` and `review` name a pull request and are leased
+ * beside the ticket's linked pulls in PR 2; `deployment`, `worker`, `binding`,
+ * `date` and `person` resolve against rows the plugin already holds; `external`
+ * is a well-formed wait nothing the plugin tracks will deliver.
+ */
+export const WAIT_KINDS = ["pull", "review", "deployment", "worker", "binding", "date", "person", "external"] as const;
+export type WaitKind = (typeof WAIT_KINDS)[number];
+const WAIT_KIND_SET: ReadonlySet = new Set(WAIT_KINDS);
+
+/** A stored typed wait: the closed kind and its reference. */
+export const waitSchema = z.object({ kind: z.enum(WAIT_KINDS), ref: z.string().trim().min(1).max(500) });
+export type Wait = z.infer;
+
+/**
+ * The `steward_report` wait input. `kind` is a plain string, not the enum, so
+ * an unknown one is the named `unknown_kind` refusal rather than a zod type
+ * error; `ref` is optional so a missing one is the named `missing_reference`
+ * refusal. Both are checked in `validateWait`, only when a `wait` is sent.
+ */
+export const waitInputSchema = z.object({
+ kind: z.string().trim().min(1).max(40),
+ ref: z.string().trim().max(500).optional(),
+});
+export type WaitInput = z.infer;
+
+/** The named validation cases. The first four are hard refusals; the last two downgrade to `external`. */
+export const WAIT_REFUSALS = ["unknown_kind", "missing_reference", "malformed_reference", "date_wait_without_date", "reference_is_self", "unvalidatable_reference"] as const;
+export type WaitRefusal = (typeof WAIT_REFUSALS)[number];
+
+const LINEAR_KEY = /^[A-Za-z][A-Za-z0-9]*-\d+$/u;
+// Plugin ids are `newId`: a prefix and 9 random bytes as base64url, so the
+// suffix may contain `-` and `_`.
+const WORKER_THREAD = /^thr_[A-Za-z0-9_-]+$/u;
+const PAGE_ITEM = /^(?:need|esc|qst)_[A-Za-z0-9_-]+$/u;
+
+/** Whether `ref` is a binding entity key: a Linear key (ENG-12) or a pull request key (owner/repo#N). */
+export function isEntityKey(ref: string): boolean {
+ return LINEAR_KEY.test(ref) || parsePullRef(ref) !== null;
+}
+
+/**
+ * The context-dependent half of the validation, read from rows the report path
+ * already holds. Each answer is a boolean, so the validation itself stays pure
+ * and testable; PR 2 adds the live reads that make `pull`/`review` live.
+ */
+export type WaitContext = {
+ /** The ref is the binding's own pull request (its entity, or an own pull). */
+ isOwnPull: (key: string) => boolean;
+ /** The project watches the repo. */
+ isWatchedRepo: (repo: string) => boolean;
+ /** A deployment watch exists for the pull request key. */
+ hasDeployment: (key: string) => boolean;
+ /** A binding with the key exists and has not ended. */
+ hasOpenBinding: (key: string) => boolean;
+ /** A worker with the thread id is known. */
+ hasWorker: (threadId: string) => boolean;
+ /** A page item (need_…, esc_…, qst_…) with the id is open. */
+ hasOpenItem: (id: string) => boolean;
+};
+
+export type WaitValidation = { ok: true; wait: Wait; downgraded: WaitRefusal | null } | { ok: false; refusal: WaitRefusal; message: string };
+
+/** The reader-facing sentence for each named case. The case name leads, so a test can match on it. */
+export const WAIT_REFUSAL_MESSAGE: Record = {
+ unknown_kind: `unknown_kind: kind must be one of ${WAIT_KINDS.join(", ")}.`,
+ missing_reference: "missing_reference: a typed wait needs a non-empty ref.",
+ malformed_reference: "malformed_reference: the ref does not parse for the kind.",
+ date_wait_without_date: "date_wait_without_date: a date wait needs a parseable date in ref, or an until.",
+ reference_is_self: "reference_is_self: a pull wait cannot name the binding's own pull request; recorded as external.",
+ unvalidatable_reference: "unvalidatable_reference: the ref does not resolve to a live source; recorded as external.",
+};
+
+/**
+ * Validate one `steward_report { wait }`. Only called when a wait is sent; a
+ * report with no wait is never refused here. An unknown kind, a missing or
+ * malformed ref, and a date wait with no date are hard refusals (nothing is
+ * written). A pull/review ref that is the binding's own, or a well-formed ref
+ * the plugin cannot resolve, is accepted and recorded as `external`.
+ */
+export function validateWait(input: WaitInput, until: string | undefined, ctx: WaitContext): WaitValidation {
+ if (!WAIT_KIND_SET.has(input.kind)) return { ok: false, refusal: "unknown_kind", message: WAIT_REFUSAL_MESSAGE.unknown_kind };
+ const kind = input.kind as WaitKind;
+ const ref = (input.ref ?? "").trim();
+ if (ref === "") return { ok: false, refusal: "missing_reference", message: WAIT_REFUSAL_MESSAGE.missing_reference };
+ switch (kind) {
+ case "pull":
+ case "review":
+ case "deployment":
+ if (parsePullRef(ref) === null) return { ok: false, refusal: "malformed_reference", message: WAIT_REFUSAL_MESSAGE.malformed_reference };
+ break;
+ case "worker":
+ if (!WORKER_THREAD.test(ref)) return { ok: false, refusal: "malformed_reference", message: WAIT_REFUSAL_MESSAGE.malformed_reference };
+ break;
+ case "binding":
+ if (!isEntityKey(ref)) return { ok: false, refusal: "malformed_reference", message: WAIT_REFUSAL_MESSAGE.malformed_reference };
+ break;
+ case "date":
+ // The structured form of `until`: the ref may carry the date, or an
+ // `until` in the same report may supply it. Nothing is derived from it.
+ if (parseUntil(ref) === null && (until === undefined || parseUntil(until) === null)) return { ok: false, refusal: "date_wait_without_date", message: WAIT_REFUSAL_MESSAGE.date_wait_without_date };
+ break;
+ case "person":
+ if (!PAGE_ITEM.test(ref)) return { ok: false, refusal: "malformed_reference", message: WAIT_REFUSAL_MESSAGE.malformed_reference };
+ break;
+ case "external":
+ break;
+ }
+ let downgraded: WaitRefusal | null = null;
+ switch (kind) {
+ case "pull": {
+ const parsed = parsePullRef(ref)!;
+ const key = `${parsed.repo}#${parsed.number}`;
+ if (ctx.isOwnPull(key)) downgraded = "reference_is_self";
+ else if (!ctx.isWatchedRepo(parsed.repo)) downgraded = "unvalidatable_reference";
+ break;
+ }
+ case "review": {
+ // A review wait on the binding's own pull is valid: the steward is
+ // waiting for its review, not for the plugin's own merge action. Only a
+ // pull wait on the binding's own pull is unobservable (BB-333 design).
+ const parsed = parsePullRef(ref)!;
+ if (!ctx.isWatchedRepo(parsed.repo)) downgraded = "unvalidatable_reference";
+ break;
+ }
+ case "deployment": {
+ const parsed = parsePullRef(ref)!;
+ if (!ctx.hasDeployment(`${parsed.repo}#${parsed.number}`)) downgraded = "unvalidatable_reference";
+ break;
+ }
+ case "worker":
+ if (!ctx.hasWorker(ref)) downgraded = "unvalidatable_reference";
+ break;
+ case "binding":
+ if (!ctx.hasOpenBinding(ref)) downgraded = "unvalidatable_reference";
+ break;
+ case "person":
+ if (!ctx.hasOpenItem(ref)) downgraded = "unvalidatable_reference";
+ break;
+ case "date":
+ case "external":
+ break;
+ }
+ const wait: Wait = downgraded === null ? { kind, ref } : { kind: "external", ref };
+ return { ok: true, wait, downgraded };
+}
+
+/** The one-line render of a stored wait, for `bb stewards show` and the card. */
+export function waitPhrase(wait: Wait | null): string | null {
+ return wait === null ? null : `${wait.kind} ${wait.ref}`;
+}