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
26 changes: 23 additions & 3 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,23 @@ A **lesson** makes the answer a record and, for most of them, lands it.
`complete` a trial by hand, which promotes it at once and bypasses
`promoted.maxPerFile`; that is an explicit override, and the nightly pass is
the mechanical path, not the only one.
- **The rationale box (BB-35 step 4).** The plugin sets `rationaleWanted` on
an escalation only when the page should ask the user why, and the page shows
the box only then, with a one-line placeholder naming the reason. It asks
when the project steward forwards a routine decision the guidance did not
settle — a forward with no `entry` naming a decide-list entry — and when the
nightly pass clusters a question with an earlier one under the same playbook
(`clusterKey` normalises the wording; the playbook keeps kinds apart). It
never asks on a `bigDecisions` kind the project could never decide, on a
credential or a plain step, or on a gate item (`approve-pr`, `merge`,
`approve-spec`); and one cluster is never asked twice — a supplied rationale
(`rationale_given`) settles it for good, while an empty box leaves it open
for a later repeat. An empty box is always accepted, and the answer rides
with the lesson candidate the project steward is woken for. When the user's answer
contradicts the recommendation, the plugin sets the after-the-fact ask and
the project steward is woken once, in its thread, to ask why — one follow-up,
never repeated. Only the owner's words (the page answer or an unsigned
comment) or this project's own steward or worker threads reach it.
- **The promotion and retirement write only the lesson's own anchored text.**
A promotion the nightly pass queues is listed under `## Lessons to land`;
the project steward adds the block (`<!-- lesson:<id> -->` and the wording)
Expand Down Expand Up @@ -1361,9 +1378,12 @@ A **lesson** makes the answer a record and, for most of them, lands it.
refused. The digest carries nothing about lessons: the merged-lessons
section is gone, and `bb stewards lessons --all` is where their state is
read.
- **Surfaces.** Pending lessons are on the Stewards page's Lessons section
and in `bb stewards list`; `bb stewards lessons [--all]` lists them,
`bb stewards drop-lesson <id>` drops one.
- **Surfaces.** Every lesson is in one collapsed details block at the bottom
of the Stewards page's project tab, with counts by tier and the rows behind
the disclosure (no buttons of its own; the boundary Merge / Drop stays the
need in "Waiting on you"); `bb stewards list` names the pending ones and
`bb stewards lessons [--all]` lists them all, `bb stewards drop-lesson <id>`
drops one.
- **Undo.** A merged procedure lesson is an ordinary commit on `.bb` HEAD;
`bb stewards lessons --all` names its `mergeSha` and branch. To undo it,
revert that commit in the canonical checkout (`git revert <sha>` in the
Expand Down
20 changes: 15 additions & 5 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,18 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
it is a general judgement the playbook should carry, the project steward
records it as a lesson. A resolve carries `cites: [lesson ids]` — the
lessons it rested on — and the plugin counts `hits` (once per distinct
binding), `corrections` and `lastCitedAt`. `bb stewards lessons [--all]`
lists tiers and counts, `bb stewards drop-lesson <id>` drops one. The
digest carries nothing about lessons. DESIGN.md §20.
binding), `corrections` and `lastCitedAt`. A forwarded escalation the
guidance did not settle (one the project steward did not name with `entry`)
asks you why on the page, and so does a repeat the nightly pass clusters
under one playbook; the box's one-line placeholder says which. It never
appears on a `bigDecisions` kind, a credential or a gate item, and one
cluster is asked once. An empty box is always accepted, and only the owner's
words — the page answer or an unsigned comment — or this project's own
steward or worker threads teach. When your answer contradicts the
recommendation, the project steward is woken once, in its thread, to ask why.
`bb stewards lessons [--all]` lists tiers and counts, `bb stewards
drop-lesson <id>` drops one. The digest carries nothing about lessons.
DESIGN.md §20.
- **The nightly pass** (01:00 in the project's time zone by default, done by
02:45 so bb-gate's 03:00 restarts do not cut a turn) gives every open
binding a turn, then wakes the project steward for the morning digest.
Expand All @@ -309,8 +318,9 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
buttons, questions the project steward put to you, which you can answer
and close there, forwarded escalations and approval requests), what is in
flight by stage with each status record and running workers, what is stuck
or held, what ended in the last two weeks, and the latest digest with its
date.
or held, what ended in the last two weeks, the latest digest with its date,
and one collapsed lessons details block at the bottom (counts by tier, rows
behind the disclosure, no buttons of its own).
- **Questions and asks to you** are escalations with `route: me`, kept in
the store from the moment the project steward asks
(`steward_update { ask }`, or forwarding an escalation) until it records
Expand Down
77 changes: 76 additions & 1 deletion plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Question = {
url: string | null;
escalationId: string | null;
createdAt: number;
rationaleWanted: string | null;
};

const need = (over: Partial<Need> = {}): Need => ({
Expand Down Expand Up @@ -64,6 +65,7 @@ const question = (over: Partial<Question> = {}): Question => ({
url: null,
escalationId: null,
createdAt: 1_000,
rationaleWanted: null,
...over,
});

Expand Down Expand Up @@ -91,6 +93,7 @@ const renderBoard = async (needs: Need[], questions: Question[]): Promise<Render
withUser: [],
needs,
lessons: [],
lessonCounts: { candidate: 0, trial: 0, promoted: 0, retired: 0 },
stewards: [],
stuck: [],
ended: [],
Expand Down Expand Up @@ -181,6 +184,78 @@ describe("the Stewards page's need links (BB-29)", () => {
});
});

// BB-35 step 4: the rationale box on an escalation, shown only when the plugin
// set `rationaleWanted`, and the collapsed lessons details block at the bottom
// of the project tab.
describe("the rationale box and lessons block (BB-35 step 4)", () => {
const renderBoardWith = async (over: { questions?: Question[]; lessons?: unknown[]; lessonCounts?: unknown }) => {
const captured = await loadApp();
const panel = captured.navPanels[0]!;
return renderSlot(panel, { subPath: "" }, {
rpc: {
stewardsBoard: () => ({
projects: [{ projectId: "p1", name: "Acme" }],
board: {
projectId: "p1",
name: "Acme",
paused: false,
projectStewardThreadId: null,
stages: [],
digest: null,
questions: over.questions ?? [],
withUser: [],
needs: [],
lessons: over.lessons ?? [],
lessonCounts: over.lessonCounts ?? { candidate: 0, trial: 0, promoted: 0, retired: 0 },
stewards: [],
stuck: [],
ended: [],
},
}),
stewardsAnswerQuestion: () => ({ ok: true, message: "closed" }),
stewardsNeedAction: () => ({ ok: true, message: "done" }),
} as never,
});
};

it("shows the box only when rationaleWanted is set, with its one-line why", async () => {
const none = await renderBoardWith({ questions: [question()] });
await waitFor(() => expect(none.getByRole("button", { name: "Answer" })).toBeTruthy());
expect(none.queryByLabelText(/^Why:/u)).toBeNull();
none.lifecycle.unmount();

const boxed = await renderBoardWith({ questions: [question({ rationaleWanted: "The guidance did not settle this." })] });
const box = (await waitFor(() => boxed.getByLabelText(/^Why:/u))) as HTMLTextAreaElement;
expect(box.placeholder).toBe("The guidance did not settle this.");
boxed.lifecycle.unmount();
});

it("sends the rationale with the answer, and an empty box is accepted", async () => {
const slot = await renderBoardWith({ questions: [question({ rationaleWanted: "Why?" })] });
const box = await waitFor(() => slot.getByLabelText(/^Why:/u));
fireEvent.change(box, { target: { value: "Because the plugin owns auth." } });
fireEvent.click(slot.getByRole("button", { name: "Answer" }));
await waitFor(() => expect(slot.inspection.rpcCalls).toContainEqual({ method: "stewardsAnswerQuestion", input: { questionId: "qst_1", answer: null, rationale: "Because the plugin owns auth." } }));
slot.lifecycle.unmount();

const empty = await renderBoardWith({ questions: [question({ rationaleWanted: "Why?" })] });
fireEvent.click(await waitFor(() => empty.getByRole("button", { name: "Answer" })));
await waitFor(() => expect(empty.inspection.rpcCalls).toContainEqual({ method: "stewardsAnswerQuestion", input: { questionId: "qst_1", answer: null } }));
empty.lifecycle.unmount();
});

it("is a collapsed details block with the tier counts and no action buttons", async () => {
const lesson = { id: "lsn_1", bindingId: null, key: null, file: "AGENTS.md", text: "A rule.", scope: "procedure", status: "pending", tier: "trial", hits: 2, corrections: 0, lastCitedAt: null, branch: null, mergeSha: null, note: null, escalationId: null, createdAt: 1_000 };
const slot = await renderBoardWith({ lessons: [lesson], lessonCounts: { candidate: 0, trial: 1, promoted: 0, retired: 0 } });
await waitFor(() => expect(slot.getByText(/candidate 0 · trial 1 · promoted 0 · retired 0/u)).toBeTruthy());
const details = slot.container.querySelector("details")!;
expect(details.open).toBe(false);
expect(slot.getByText("A rule.")).toBeTruthy();
expect(slot.queryByRole("button")).toBeNull();
slot.lifecycle.unmount();
});
});

// BB-45: the sidebar-footer disclosure writes the `sidebar.threadListProvider`
// UI preference, so the stewards list BB-44 registers can be turned on and off
// from the footer instead of Settings → Appearance.
Expand Down Expand Up @@ -502,7 +577,7 @@ describe("the stewards sidebar's needs you block (BB-46)", () => {
calls += 1;
return {
projects: [{ projectId: "p1", name: "Acme" }],
board: { projectId: "p1", name: "Acme", paused: false, projectStewardThreadId: null, stages: [], digest: null, questions: [], withUser: [], needs: [], lessons: [], stewards: [], stuck: [], ended: [] },
board: { projectId: "p1", name: "Acme", paused: false, projectStewardThreadId: null, stages: [], digest: null, questions: [], withUser: [], needs: [], lessons: [], lessonCounts: { candidate: 0, trial: 0, promoted: 0, retired: 0 }, stewards: [], stuck: [], ended: [] },
};
},
},
Expand Down
102 changes: 71 additions & 31 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -486,30 +486,6 @@ function ProjectBoard({ board: b, refetch }: { board: Board; refetch: () => void
)}
</Section>

<Section title="Lessons" count={b.lessons.length}>
{b.lessons.length === 0 ? (
<None>No lessons are waiting to be landed.</None>
) : (
<List>
{b.lessons.map((l) => (
<li key={l.id} className="flex flex-col gap-1 p-3">
<p className="flex flex-wrap items-center gap-2">
<Badge tone={l.scope === "boundary" ? "bad" : "muted"}>{l.scope}</Badge>
<span className="font-medium">{l.file}</span>
{l.key !== null ? <EntityLink entityKey={l.key} url={null} /> : null}
<span className="text-xs text-muted-foreground">{ago(l.createdAt, now)}</span>
</p>
<p>{l.text}</p>
<p className="text-xs text-muted-foreground">
{l.scope === "boundary" ? "Waiting on your Merge or Drop above." : "The project steward applies, commits and self-merges this."}
{l.note !== null ? ` Last attempt: ${l.note}` : ""}
</p>
</li>
))}
</List>
)}
</Section>

<Section title="In flight" count={b.stewards.length}>
{b.stewards.length === 0 ? (
<None>No open stewards. Label a Linear ticket or pull request to adopt it.</None>
Expand Down Expand Up @@ -586,10 +562,53 @@ function ProjectBoard({ board: b, refetch }: { board: Board; refetch: () => void
</div>
)}
</Section>

<LessonsBlock lessons={b.lessons} counts={b.lessonCounts} now={now} />
</>
);
}

/**
* BB-35 step 4: one collapsed details block at the bottom of the project tab,
* counts by tier and the rows behind a disclosure. No buttons of its own: the
* boundary Merge / Drop stays the need in "Waiting on you".
*/
function LessonsBlock({ lessons, counts, now }: { lessons: Board["lessons"]; counts: Board["lessonCounts"]; now: number }) {
const total = counts.candidate + counts.trial + counts.promoted + counts.retired;
return (
<details className="rounded-lg border border-border">
<summary className="cursor-pointer px-3 py-2 text-base font-medium">
Lessons <span className="text-sm font-normal text-muted-foreground">{total}</span>
<span className="ml-2 text-xs font-normal text-muted-foreground">
candidate {counts.candidate} · trial {counts.trial} · promoted {counts.promoted} · retired {counts.retired}
</span>
</summary>
{lessons.length === 0 ? (
<p className="border-t border-border p-3 text-muted-foreground">No lessons yet.</p>
) : (
<ul className="flex flex-col divide-y divide-border border-t border-border">
{lessons.map((l) => (
<li key={l.id} className="flex flex-col gap-1 p-3">
<p className="flex flex-wrap items-center gap-2">
<Badge tone={l.scope === "boundary" ? "bad" : "muted"}>{l.scope}</Badge>
<Badge>{l.tier}</Badge>
<span className="font-medium">{l.file}</span>
{l.key !== null ? <span className="text-muted-foreground">{l.key}</span> : null}
<span className="text-xs text-muted-foreground">{ago(l.createdAt, now)}</span>
</p>
<p>{l.text}</p>
<p className="text-xs text-muted-foreground">
{l.hits} citation{l.hits === 1 ? "" : "s"} · {l.corrections} correction{l.corrections === 1 ? "" : "s"} · last cited {ago(l.lastCitedAt, now)}
{l.note !== null ? ` · ${l.note}` : ""}
</p>
</li>
))}
</ul>
)}
</details>
);
}

/**
* One "needs you" item with its buttons. A button is offered only when the
* server can verify the item's preconditions now; otherwise the item says why
Expand Down Expand Up @@ -711,19 +730,30 @@ function NeedRow({ need: n, now, onDone }: { need: Board["needs"][number]; now:
function QuestionRow({ question: q, now, onClosed }: { question: Board["questions"][number]; now: number; onClosed: () => void }) {
const rpc = useRpc<typeof rpcContract>();
const [answer, setAnswer] = useState("");
// BB-35 step 4: the rationale box appears only when the plugin set
// `rationaleWanted`, with its one-line why as the placeholder. An empty box
// is always accepted.
const [rationale, setRationale] = useState("");
// With choices, the text box is the choice's note until Other… turns it
// into the free-text answer.
const [other, setOther] = useState(false);
const [state, setState] = useState<"idle" | "closing" | { error: string }>("idle");
const close = (choice?: string) => {
setState("closing");
rpc.call("stewardsAnswerQuestion", { questionId: q.id, answer: answer.trim() === "" ? null : answer.trim(), ...(choice === undefined ? {} : { choice }) }).then(
(r) => {
if (r.ok) onClosed();
else setState({ error: r.message });
},
(e: unknown) => setState({ error: message(e) }),
);
rpc
.call("stewardsAnswerQuestion", {
questionId: q.id,
answer: answer.trim() === "" ? null : answer.trim(),
...(choice === undefined ? {} : { choice }),
...(q.rationaleWanted === null || rationale.trim() === "" ? {} : { rationale: rationale.trim() }),
})
.then(
(r) => {
if (r.ok) onClosed();
else setState({ error: r.message });
},
(e: unknown) => setState({ error: message(e) }),
);
};
const button = "rounded-md border border-input px-3 py-1 text-xs hover:bg-state-hover disabled:opacity-50";
return (
Expand All @@ -735,6 +765,16 @@ function QuestionRow({ question: q, now, onClosed }: { question: Board["question
</p>
<p>{q.question}</p>
{q.context !== null ? <p className="text-muted-foreground">{q.context}</p> : null}
{q.rationaleWanted !== null ? (
<textarea
value={rationale}
onChange={(e) => setRationale(e.target.value)}
rows={2}
placeholder={q.rationaleWanted}
aria-label={`Why: ${q.question}`}
className="min-w-0 rounded-md border border-input bg-transparent px-2 py-1"
/>
) : null}
<div className="flex flex-wrap items-start gap-2">
<textarea
value={answer}
Expand Down
31 changes: 31 additions & 0 deletions plugins/stewards/rationale.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, expect, it } from "vitest";
import { AFTER_THE_FACT_RATIONALE_WHY, REPEAT_RATIONALE_WHY, ROUTINE_RATIONALE_WHY, clusterKey, routineRationaleWanted } from "./rationale.js";

describe("the rationale rules (BB-35 step 4)", () => {
it("asks on a routine decision the guidance did not settle", () => {
expect(routineRationaleWanted({ kind: "decision", resolutionKind: "text", entry: null })).toBe(true);
expect(routineRationaleWanted({ kind: "decision", resolutionKind: "choice" })).toBe(true);
// A named decide-list entry means the project steward forwarded a big
// decision: the project could never decide it, so it never asks.
expect(routineRationaleWanted({ kind: "decision", resolutionKind: "text", entry: "New vendors, services or spending" })).toBe(false);
// The gate items, a credential and a plain step never ask.
expect(routineRationaleWanted({ kind: "approval", resolutionKind: "text" })).toBe(false);
expect(routineRationaleWanted({ kind: "approval", resolutionKind: "approve-decline" })).toBe(false);
expect(routineRationaleWanted({ kind: "decision", resolutionKind: "secret" })).toBe(false);
expect(routineRationaleWanted({ kind: "decision", resolutionKind: "done" })).toBe(false);
});

it("keeps the three one-line whys distinct", () => {
expect(new Set([ROUTINE_RATIONALE_WHY, REPEAT_RATIONALE_WHY, AFTER_THE_FACT_RATIONALE_WHY]).size).toBe(3);
for (const why of [ROUTINE_RATIONALE_WHY, REPEAT_RATIONALE_WHY, AFTER_THE_FACT_RATIONALE_WHY]) expect(why.length).toBeGreaterThan(0);
});
});

describe("the escalation cluster key", () => {
it("drops case, punctuation and spacing, and keeps the playbook apart", () => {
expect(clusterKey("linear-tickets", "Include SSO?")).toBe(clusterKey("linear-tickets", "include sso"));
expect(clusterKey("linear-tickets", "Include SSO?")).not.toBe(clusterKey("github-prs", "Include SSO?"));
// No playbook is its own bucket, so two unbound questions still cluster.
expect(clusterKey(null, "Include SSO?")).toBe(clusterKey(null, "include sso"));
});
});
Loading
Loading