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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions plugins/stewards/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14690,6 +14690,19 @@ describe("the stand-up (BB-300)", () => {
return { ...t, project, steward };
}

/** A bound ticket with one linked, gate-met pull request and its approve-pr need (BB-309). */
async function adoptedWithPull() {
const t = await setup();
const head = "aaaaaaa1";
const marker = comment({ id: "m1", author: "trotterdylan", body: `<!-- bb-review round=1 sha=${head} verdict=approved lane=owner-reviewed approver=owner -->`, signedBy: "thr_reviewer", createdAt: "2026-10-14T16:00:00Z" });
t.entities.set("uuid-12", issue({ linkedPulls: [{ key: "acme/web#7", url: "https://github.com/acme/web/pull/7" }] }));
t.entities.set("acme/web#7", pull({ comments: [marker] }, { head: "bb/eng-12-retry", checks: { state: "success", failing: [] } }));
await t.ring("linear", "uuid-12");
await t.flush();
const [project, steward] = t.spawns.map((x) => x.id) as [string, string];
return { ...t, project, steward };
}

it("reports a stand-up as available on the board when the voice plugin is ready", async () => {
const t = await adopted();
const board = (await t.harness.callRpc("stewardsBoard", { projectId: "p1" })) as { board: { standup?: { available: boolean; message: string | null } } };
Expand Down Expand Up @@ -14792,6 +14805,34 @@ describe("the stand-up (BB-300)", () => {
expect(retracted).toContain("No note");
});

it("resolves a pull request key to the ticket binding that holds its gate need (BB-309)", async () => {
const t = await adoptedWithPull();
const b = t.hooks.store.find("ENG-12")!;
const need = t.hooks.store.openNeeds(b.id).find((n) => n.kind === "approve-pr");
expect(need, "the ticket should hold an approve-pr need").toBeDefined();
const started = (await t.harness.callRpc("stewardsStandupStart", { projectId: "p1" }, client)) as { sessionId: string; standupId: string };
// steward_status by the pull key the brief shows resolves to the ticket.
const status = (await t.harness.callRpc("stewardsStandupTool", { sessionId: started.sessionId, name: "steward_status", arguments: JSON.stringify({ key: "acme/web#7" }) }, voice)) as string;
expect(status).toContain("ENG-12");
expect(status).not.toContain("No steward");
// entity_snapshot by the pull URL renders the pull's own snapshot.
const entity = (await t.harness.callRpc("stewardsStandupTool", { sessionId: started.sessionId, name: "entity_snapshot", arguments: JSON.stringify({ key: "https://github.com/acme/web/pull/7" }) }, voice)) as string;
expect(entity).toContain("Add login retry");
expect(entity).not.toContain("No steward");
// take_note by the pull key binds to the open need, recording the resolved
// ticket key so the confirmation path's `store.find` finds it later.
await t.harness.callRpc("stewardsStandupTool", { sessionId: started.sessionId, name: "take_note", arguments: JSON.stringify({ type: "gate", text: "Looks good", binding: "acme/web#7", action: "approve" }) }, voice);
const note = t.hooks.store.standup(started.standupId)!.notes[0]!;
expect(note).toMatchObject({ binding: "ENG-12", need: need!.id });
// Confirming applies it through the need-action path, exactly as the page does.
const confirmed = await t.harness.callRpc("stewardsStandupConfirm", { standupId: started.standupId, noteId: note.id }, client);
expect(confirmed).toMatchObject({ ok: true, applied: true });
expect(t.hooks.store.need(need!.id)!.status).toBe("done");
// A pull key with no open gate item still answers "No steward".
const unknown = (await t.harness.callRpc("stewardsStandupTool", { sessionId: started.sessionId, name: "steward_status", arguments: JSON.stringify({ key: "acme/web#999" }) }, voice)) as string;
expect(unknown).toContain("No steward for acme/web#999");
});

it("scrubs a pasted credential from a tool result before it reaches the model", async () => {
const t = await adopted();
// A ticket body can carry a pasted token; it must not reach OpenAI.
Expand Down Expand Up @@ -15384,6 +15425,8 @@ describe("the stand-up (BB-300)", () => {
const prompt = String(delegate.prompt);
expect(prompt).toContain("Read only");
expect(prompt).toContain("one-line verdict first");
// BB-309: the answer is spoken, so the standing instructions ask for plain prose.
expect(prompt).toContain("Write plain prose only");
expect(prompt).toContain("Are the bb-server builds still stalling?");
expect(prompt).toContain("ENG-12");
await t.idle(delegate.id, "Yes, the builds are still stalling.");
Expand Down
24 changes: 21 additions & 3 deletions plugins/stewards/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import { MULTI_REPO_ENVIRONMENT_PROVIDER_ID, MULTI_REPO_PLUGIN_ID, multiRepoEnvi
import { KUBECTL_VERBS, createKubectlReader, kubectlRefusal, type KubectlResult, type OpsAccess, type OpsReader } from "./kubectl.js";
import { HOOKS_URL_ENV, createHooksLoop, type Lease, type Rejection } from "./hooks-client.js";
import { createBriefing, nightlyDue, stillNight, toDigestRecords } from "./nightly.js";
import { STANDUP_TOOLS, buildStandupInstructions, readbackLine, runStandupTool, STANDUP_DELEGATE_ANSWER_MAX_CHARS, type StandupAskOutcome, type StandupDelegation, type StandupEndOutcome, type StandupNote, type StandupNoteType, type StandupRecord, type StandupToolReply } from "./standup.js";
import { STANDUP_TOOLS, buildStandupInstructions, readbackLine, runStandupTool, samePullRef, STANDUP_DELEGATE_ANSWER_MAX_CHARS, type StandupAskOutcome, type StandupDelegation, type StandupEndOutcome, type StandupNote, type StandupNoteType, type StandupRecord, type StandupToolReply } from "./standup.js";
import { classify, hasFingerprintLine, lookChanges, opsTargetKey, parseOpsTargetKey, redactLine, scrubCredentials, ticketResolved, type DependabotTarget, type FingerprintRow, type K8sTarget, type OpsLook, type OpsTarget, type SentryTarget, type Sighting, type TicketState } from "./ops.js";
import { EVENTS_PER_LOOK, NO_TOKEN, RECENT_PER_LOOK, SENTRY_API_URL, TOKEN_SCOPES, createSentryReader, emptySentryLook, issueInOrg, recentLine, sentryChanges, sentryResolveTargets, sentrySightings, sentrySummary, type SentryFinding, type SentryLook, type SentryReader } from "./sentry.js";
import { advanced, answerDiffers, anyWorkerInFlight, asksForOpenApproval, commentDiffersFromRecommendation, compactDue, deploymentSettled, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, hasLabel, IDLE_WAKE_TEXT, idleInActiveStage, isCommentNews, isOwnStageChange, lifecycle, mechanicalStatus, namesUserAsBlocker, newHumanComments, newestCommentAt, openUserFacingItems, ownChecksFinished, ownPullClosed, ownPullMerged, phaseAndStage, productGateOptions, runningWorkerReason, newestEditComment, specDiff, specHash, specText, stuckDue, unheardWait, workerInFlight, workerReportedTerminal, type Change, type MechanicalEvent, type OpenUserItem } from "./reconcile.js";
Expand Down Expand Up @@ -1543,6 +1543,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
"Do not comment on any ticket or pull request, and do not run `bb stewards done`, `escalate` or `merge`, or make any Linear write.",
"",
"Reply with a one-line verdict first, then the evidence, under 200 words.",
"Write plain prose only: no Markdown, no headings, no bullet points, no bold or italics, no code fences. Your answer is read aloud.",
].join("\n");

/** `bb stewards show <key>` output for the delegate's context, or null when the key has no steward here. */
Expand Down Expand Up @@ -1719,6 +1720,23 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
await wakeProject(row.projectId, "the owner held a stand-up", { digestDue: false, notes: lines });
}

/**
* BB-309: the stand-up's key reader. A ticket key resolves as before; a
* pull-request key or URL that names no binding of its own resolves to the
* open binding holding an open approve-pr or merge need for it, so the key
* the brief shows works in every read tool, gate note and confirmation.
*/
function standupBindingFor(projectId: string, key: string): Binding | null {
const direct = store.find(key, projectId);
if (direct !== null) return direct;
if (parsePullRef(key) === null) return null;
for (const b of store.open(projectId)) {
const held = store.openNeeds(b.id).some((n) => (n.kind === "approve-pr" || n.kind === "merge") && samePullRef(n.url, key));
if (held) return b;
}
return null;
}

/**
* Apply one confirmed note through the path its shape already uses: a gate
* item through the need-action RPC the Approve and Decline buttons use,
Expand All @@ -1731,7 +1749,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
async function applyStandupNote(standup: StandupRow, note: StandupNoteRow): Promise<{ ok: boolean; applied: boolean; message: string }> {
const type = note.type as StandupNoteType;
const text = scrubCredentials(note.text);
const binding = note.binding === null ? null : store.find(note.binding, standup.projectId);
const binding = note.binding === null ? null : standupBindingFor(standup.projectId, note.binding);
let applied = false;
let message = "Confirmed.";

Expand Down Expand Up @@ -9622,7 +9640,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
const result = await runStandupTool(name, args, {
projectId: standupProjectId,
now,
binding: (key) => store.find(key, standupProjectId),
binding: (key) => standupBindingFor(standupProjectId, key),
openEscalations: (bindingId) => store.openEscalations(bindingId),
escalation: (id) => store.escalation(id),
lessons: (bindingId) => store.allLessons(standupProjectId).filter((l) => l.bindingId === bindingId),
Expand Down
Loading
Loading