diff --git a/plugins/stewards/DESIGN.md b/plugins/stewards/DESIGN.md index 1cb9f805..bb4a0c6e 100644 --- a/plugins/stewards/DESIGN.md +++ b/plugins/stewards/DESIGN.md @@ -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 (`` and the wording) @@ -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 ` 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 ` + 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 ` in the diff --git a/plugins/stewards/README.md b/plugins/stewards/README.md index 73086ab5..450ea79d 100644 --- a/plugins/stewards/README.md +++ b/plugins/stewards/README.md @@ -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 ` 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 ` 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. @@ -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 diff --git a/plugins/stewards/app.test.tsx b/plugins/stewards/app.test.tsx index fbe5ca40..ec6db391 100644 --- a/plugins/stewards/app.test.tsx +++ b/plugins/stewards/app.test.tsx @@ -34,6 +34,7 @@ type Question = { url: string | null; escalationId: string | null; createdAt: number; + rationaleWanted: string | null; }; const need = (over: Partial = {}): Need => ({ @@ -64,6 +65,7 @@ const question = (over: Partial = {}): Question => ({ url: null, escalationId: null, createdAt: 1_000, + rationaleWanted: null, ...over, }); @@ -91,6 +93,7 @@ const renderBoard = async (needs: Need[], questions: Question[]): Promise { }); }); +// 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. @@ -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: [] }, }; }, }, diff --git a/plugins/stewards/app.tsx b/plugins/stewards/app.tsx index 376f8452..ffc6ce4d 100644 --- a/plugins/stewards/app.tsx +++ b/plugins/stewards/app.tsx @@ -486,30 +486,6 @@ function ProjectBoard({ board: b, refetch }: { board: Board; refetch: () => void )} -
- {b.lessons.length === 0 ? ( - No lessons are waiting to be landed. - ) : ( - - {b.lessons.map((l) => ( -
  • -

    - {l.scope} - {l.file} - {l.key !== null ? : null} - {ago(l.createdAt, now)} -

    -

    {l.text}

    -

    - {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}` : ""} -

    -
  • - ))} -
    - )} -
    -
    {b.stewards.length === 0 ? ( No open stewards. Label a Linear ticket or pull request to adopt it. @@ -586,10 +562,53 @@ function ProjectBoard({ board: b, refetch }: { board: Board; refetch: () => void )}
    + + ); } +/** + * 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 ( +
    + + Lessons {total} + + candidate {counts.candidate} · trial {counts.trial} · promoted {counts.promoted} · retired {counts.retired} + + + {lessons.length === 0 ? ( +

    No lessons yet.

    + ) : ( +
      + {lessons.map((l) => ( +
    • +

      + {l.scope} + {l.tier} + {l.file} + {l.key !== null ? {l.key} : null} + {ago(l.createdAt, now)} +

      +

      {l.text}

      +

      + {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}` : ""} +

      +
    • + ))} +
    + )} +
    + ); +} + /** * 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 @@ -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(); 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 ( @@ -735,6 +765,16 @@ function QuestionRow({ question: q, now, onClosed }: { question: Board["question

    {q.question}

    {q.context !== null ?

    {q.context}

    : null} + {q.rationaleWanted !== null ? ( +