diff --git a/plugins/stewards/DESIGN.md b/plugins/stewards/DESIGN.md index 40e864b9..acaa3816 100644 --- a/plugins/stewards/DESIGN.md +++ b/plugins/stewards/DESIGN.md @@ -1520,6 +1520,16 @@ one (omitted for ops), and the status phrase. A row that needs you adds its prompt and one-click actions under line two, in the same row, with no tinted callout box. +A **Recently ended** row is that same row (BB-88): `sidebar.ts`'s +`endedEffort` builds the ended binding as a quiet effort with no children, the +entity's final phase, and the end reason in the status-phrase slot (`terminal`, +`deleted`, `label removed` for a removed label, `no longer listed` when the +entity is gone, `no longer configured` when the project stopped stewarding +it), and the row keeps the `ended N ago` stamp +at the right, which is what distinguishes the section. The steward thread is +usually archived by then, so the title comes from the RPC and the row renders +without the thread actions menu when the thread is no longer in the live view. + The glyph is one of four shapes, in precedence order `you › blocked › running › quiet`: a solid yellow dot when it waits on you, an empty red ring when blocked (`blockedOn`, a hold or `stuck`), a blue ring that pulses slowly while @@ -1553,7 +1563,9 @@ covers every rule and the precedence. whether stewarded or `ops`; a needs-you, blockedOn, held or stuck `ops` binding leaves Monitors for Blocked. In flight holds the rest of the stewarded, non-ops efforts, running before quiet, then by recency. Pinned rows stay first within their section. -`buildSidebar` returns `blocked`, `efforts`, `threads` and `monitors` +Recently ended holds the ended bindings, newest first, each built by +`endedEffort` as a quiet effort with no children (BB-88). +`buildSidebar` returns `blocked`, `efforts`, `threads`, `monitors` and `ended` separately, and the split is unit tested in `sidebar.test.ts`. **Rows, highlighting and auto-expand (BB-85).** A stewarded effort row in diff --git a/plugins/stewards/README.md b/plugins/stewards/README.md index 197e14f5..dd2c4991 100644 --- a/plugins/stewards/README.md +++ b/plugins/stewards/README.md @@ -416,7 +416,14 @@ ring when quiet. One-off threads use the same four glyphs — yellow when unread blue animated while their agent runs, grey otherwise — except a draft, which keeps bb's own glyph. A worker or reviewer child row under an effort, and a one-off thread's children, share those glyphs and carry no role tag. An `ops` -binding that needs you or is blocked moves from Monitors into Blocked. +binding that needs you or is blocked moves from Monitors into Blocked. A +**Recently ended** row is the same two-line effort row (BB-88): the grey quiet +ring, the kind, the entity's final phase and the end reason (`terminal`, +`deleted`, `label removed` for a removed label, `no longer listed` when the +entity is gone, `no longer configured` when the project stopped stewarding it) +in place of the status phrase, no children, and the +`ended N ago` stamp on the right. Its steward thread is usually archived, so the +title comes from the server and the row still renders when the thread is gone. **Rows, highlighting and auto-expand (BB-85).** An effort row in Blocked, In flight or Monitors and a Recently ended row are real links to the effort's diff --git a/plugins/stewards/app.tsx b/plugins/stewards/app.tsx index 30c38495..d6322b9c 100644 --- a/plugins/stewards/app.tsx +++ b/plugins/stewards/app.tsx @@ -32,7 +32,7 @@ import { } from "@get-bb/plugin-sdk/app"; import type { rpcContract } from "./server"; import { NEEDS_YOU_CHANGED } from "./channels.js"; -import { buildSidebar, compareBlocked, compareEfforts, compareInflight, deploymentPhrase, effortPhrase, effortSection, effortState, effortTitle, isBusy, type EffortStatus, type SidebarChild, type SidebarChildRole, type SidebarEffort, type SidebarEffortState, type SidebarEnded, type SidebarSection, type SidebarTab } from "./sidebar.js"; +import { buildSidebar, compareBlocked, compareEfforts, compareInflight, deploymentPhrase, effortPhrase, effortSection, effortState, effortTitle, isBusy, type EffortStatus, type SidebarChild, type SidebarChildRole, type SidebarEffort, type SidebarEffortState, type SidebarSection, type SidebarTab } from "./sidebar.js"; import { AUTOMATIC_THREAD_LIST_PROVIDER, BUILTIN_THREAD_LIST_ID, THREAD_LIST_PROVIDER_KEY, stewardsThreadListId } from "./sidebar-provider.js"; type Client = ReturnType>; @@ -1401,6 +1401,7 @@ function SidebarEffortRow({ openThreads, onNavigate, onChanged, + trailing, }: { effort: SidebarEffort; needs: readonly SidebarNeedItem[]; @@ -1414,15 +1415,20 @@ function SidebarEffortRow({ openThreads: ReadonlySet; onNavigate: () => void; onChanged: () => void; + /** A right-aligned stamp after the title, for a Recently ended row's `ended N ago` (BB-88). */ + trailing?: ReactNode; }) { const root = byId.get(effort.rootThreadId); const navigate = useBbNavigate(); const pluginId = experimental_usePluginId(); const [open, setOpen] = useState(false); const key = effort.bindingKey; - if (root === undefined || key === null) return null; + if (key === null) return null; const displayKey = shortBindingKey(key); - const title = effortTitle(root.displayTitle, key); + // A Recently ended binding's steward thread is usually archived and so absent + // from the live view; its title comes from the RPC and the row renders without + // the thread actions context menu (BB-88). + const title = effortTitle(root?.displayTitle ?? effort.title, key); const count = countThreads(effort.children); const mine = needs.filter((item) => item.bindingKey !== null && item.bindingKey === key); const selected = activeKey !== null && activeKey === key; @@ -1431,50 +1437,52 @@ function SidebarEffortRow({ if (revealed) setOpen(true); }, [revealed]); const href = boardHref(pluginId, projectId, key); + const body = ( +
+
+ {count > 0 ? ( + + ) : ( + + )} + + + + { + e.preventDefault(); + navigate.toPluginPanel(BOARD_PATH, { subPath: boardSubPath(projectId, key) }); + onNavigate(); + }} + > + {displayKey} + {title} + + {trailing} +
+

+ {kindLabel(effort.kind)} + {effort.phase !== null ? ` · ${effort.phase}` : ""} + {" · "} + {effort.phrase} +

+
+ ); return (
  • - -
    - -

    - {kindLabel(effort.kind)} - {effort.phase !== null ? ` · ${effort.phase}` : ""} - {" · "} - {effort.phrase} -

    -
    -
    + {root === undefined ? body : {body}} {mine.length > 0 ? (
    {mine.map((item) => ( @@ -1614,7 +1622,7 @@ function revealThreads(tabs: readonly SidebarTab[], activeThreadId: string | nul function revealSections(tabs: readonly SidebarTab[], activeThreadId: string | null, activeKey: string | null): ReadonlySet { const open = new Set(); for (const tab of tabs) { - if ((activeThreadId !== null && tab.ended.some((e) => e.threadId === activeThreadId)) || (activeKey !== null && tab.ended.some((e) => e.key === activeKey))) open.add("Recently ended"); + if ((activeThreadId !== null && tab.ended.some((e) => e.rootThreadId === activeThreadId)) || (activeKey !== null && tab.ended.some((e) => e.key === activeKey))) open.add("Recently ended"); if (activeThreadId !== null && tab.threads.some((e) => e.rootThreadId === activeThreadId || subtreeHas(e.children, activeThreadId))) open.add("Threads"); if (tab.monitors.some((e) => (activeKey !== null && e.bindingKey === activeKey) || (activeThreadId !== null && (e.rootThreadId === activeThreadId || subtreeHas(e.children, activeThreadId))))) open.add("Monitors"); } @@ -1742,7 +1750,19 @@ function StewardsSidebarCore({
      {active.ended.map((e) => ( - + {ago(e.endedAt, now)}} + /> ))}
    @@ -1770,37 +1790,6 @@ function StewardsSidebarCore({ ); } -/** A Recently ended row: a real link to the effort's detail view (BB-85). */ -function SidebarEndedRow({ ended, projectId, activeKey, now, onNavigate }: { ended: SidebarEnded; projectId: string; activeKey: string | null; now: number; onNavigate: () => void }) { - const navigate = useBbNavigate(); - const pluginId = experimental_usePluginId(); - const selected = activeKey !== null && activeKey === ended.key; - return ( -
  • - { - e.preventDefault(); - navigate.toPluginPanel(BOARD_PATH, { subPath: boardSubPath(projectId, ended.key) }); - onNavigate(); - }} - > - - - - - {shortBindingKey(ended.key)} - {ended.title ?? ""} - {ago(ended.endedAt, now)} - -
  • - ); -} - /** The opt-in sidebar thread list (BB-44): the shared list with the route's active thread. */ function StewardsSidebar({ activeProjectId, activeThreadId, onNavigate }: PluginThreadListProps) { const navigate = useBbNavigate(); diff --git a/plugins/stewards/server.ts b/plugins/stewards/server.ts index df29cb0e..e1fd3892 100644 --- a/plugins/stewards/server.ts +++ b/plugins/stewards/server.ts @@ -509,7 +509,7 @@ export const rpcContract = defineRpcContract({ reviewers: z.array(z.object({ threadId: z.string(), workerThreadId: z.string() })), }), ), - ended: z.array(z.object({ key: z.string(), kind: z.string(), threadId: z.string().nullable(), title: z.string().nullable(), endedAt: z.number() })), + ended: z.array(z.object({ key: z.string(), kind: z.string(), threadId: z.string().nullable(), title: z.string().nullable(), phase: z.string().nullable(), endReason: z.string().nullable(), endedAt: z.number() })), }), ), }), @@ -4796,7 +4796,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P reviewers: workers.flatMap((w) => (reviewersByWorker.get(w.threadId) ?? []).map((threadId) => ({ threadId, workerThreadId: w.threadId }))), }; }), - ended: ended.map((b) => ({ key: b.entityKey, kind: b.kind, threadId: b.threadId, title: b.title, endedAt: b.endedAt! })), + ended: ended.map((b) => ({ key: b.entityKey, kind: b.kind, threadId: b.threadId, title: b.title, phase: b.phase, endReason: b.endReason, endedAt: b.endedAt! })), }; }), }; diff --git a/plugins/stewards/sidebar-app.test.tsx b/plugins/stewards/sidebar-app.test.tsx index b6eca750..64096798 100644 --- a/plugins/stewards/sidebar-app.test.tsx +++ b/plugins/stewards/sidebar-app.test.tsx @@ -334,7 +334,7 @@ describe("the stewards sidebar list (BB-44)", () => { stewardsSidebar: () => sidebarData({ bindings: [binding(), binding({ key: "acme/web", kind: "ops", stage: null, threadId: "thr_ops" })], - ended: [{ key: "ENG-0", kind: "ticket", threadId: null, title: "Old work", endedAt: 1_000 }], + ended: [{ key: "ENG-0", kind: "ticket", threadId: null, title: "Old work", phase: "Done", endReason: "terminal", endedAt: 1_000 }], }), } as never, }); @@ -344,7 +344,32 @@ describe("the stewards sidebar list (BB-44)", () => { fireEvent.click(slot.getByRole("button", { name: /Monitors/u })); await waitFor(() => expect(slot.getByText("acme/web")).toBeTruthy()); fireEvent.click(slot.getByRole("button", { name: /Recently ended/u })); - await waitFor(() => expect(slot.getByText("Old work")).toBeTruthy()); + const old = await waitFor(() => slot.getByText("Old work")); + // BB-88: the same two-line effort row as a live binding, the end reason in + // the phrase slot, the grey quiet ring, and the ended stamp on the right. + expect(lineTwo(slot, "Old work")).toBe("ticket · Done · terminal"); + expect(glyphOf(slot, "Old work")).toBe("quiet"); + expect(old.closest("li")!.textContent).toMatch(/ago/u); + expect(old.closest("a")!.getAttribute("href")).toContain("/board/p1/ENG-0"); + slot.lifecycle.unmount(); + }); + + // BB-88 criterion 1: an ended binding whose steward thread is still in the + // live view renders through SidebarEffortRow, title stripped of the key. + it("renders a Recently ended binding with a live thread as the two-line effort row", async () => { + const slot = await renderSidebar({ + sidebarThreads: { projects, threads: [thread({ id: "thr_old", displayTitle: "ENG-0: Old work" })] }, + rpc: { + stewardsSidebar: () => + sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", phase: "Done", endReason: "terminal", endedAt: Date.now() - 2 * 86_400_000 }] }), + } as never, + }); + fireEvent.click(await waitFor(() => slot.getByRole("button", { name: /Recently ended/u }))); + const old = await waitFor(() => slot.getByText("Old work")); + expect(lineTwo(slot, "Old work")).toBe("ticket · Done · terminal"); + expect(glyphOf(slot, "Old work")).toBe("quiet"); + expect(old.closest("li")!.textContent).toMatch(/2d ago/u); + expect(old.closest("a")!.getAttribute("href")).toContain("/board/p1/ENG-0"); slot.lifecycle.unmount(); }); @@ -928,7 +953,7 @@ describe("the sidebar's highlighting and auto-expand (BB-85)", () => { const ended = await renderSidebar( { sidebarThreads: { projects, threads: [] }, - rpc: { stewardsSidebar: () => sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", endedAt: 1_000 }] }) } as never, + rpc: { stewardsSidebar: () => sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", phase: "Done", endReason: "terminal", endedAt: 1_000 }] }) } as never, }, { activeThreadId: "thr_old" }, ); @@ -942,7 +967,7 @@ describe("the sidebar's highlighting and auto-expand (BB-85)", () => { const panel = captured.navPanels[0]!; const slot = renderSlot({ component: panel.experimental_sidebar! }, { subPath: "p1/ENG-0" }, { sidebarThreads: { projects, threads: [] }, - rpc: { stewardsSidebar: () => sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", endedAt: 1_000 }] }) } as never, + rpc: { stewardsSidebar: () => sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", phase: "Done", endReason: "terminal", endedAt: 1_000 }] }) } as never, }); const old = await waitFor(() => slot.getByText("Old work")); expect(old.closest("a")!.getAttribute("aria-current")).toBe("page"); diff --git a/plugins/stewards/sidebar.test.ts b/plugins/stewards/sidebar.test.ts index 3b23e258..a4248772 100644 --- a/plugins/stewards/sidebar.test.ts +++ b/plugins/stewards/sidebar.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { buildSidebar, compareBlocked, compareEfforts, compareInflight, deploymentPhrase, effortPhrase, effortSection, effortState, effortTitle, isBusy, type SidebarEffort, type SidebarLiveProject, type SidebarLiveThread, type SidebarProjectData } from "./sidebar.js"; +import { buildSidebar, compareBlocked, compareEfforts, compareInflight, deploymentPhrase, effortPhrase, effortSection, effortState, effortTitle, endReasonPhrase, endedEffort, isBusy, type SidebarEffort, type SidebarLiveProject, type SidebarLiveThread, type SidebarProjectData } from "./sidebar.js"; const thread = (over: Partial & { id: string }): SidebarLiveThread => ({ projectId: "p1", @@ -420,3 +420,56 @@ describe("stewards sidebar state, section and phrase (BB-76)", () => { expect(tabs[0]!.monitors.map((e) => `${e.key}:${e.state}:${e.phrase}`)).toEqual(["acme/web:quiet:no report yet"]); }); }); + +describe("stewards sidebar Recently ended efforts (BB-88)", () => { + const ended = (over: Partial & { key: string }): SidebarProjectData["ended"][number] => ({ + kind: "ticket", + threadId: null, + title: null, + phase: null, + endReason: null, + endedAt: 1_000, + ...over, + }); + + it("builds an ended binding as a quiet effort with the end reason as its phrase", () => { + const e = endedEffort(ended({ key: "ENG-0", title: "Old work", phase: "Done", endReason: "terminal", threadId: "thr_old" })); + expect(e).toMatchObject({ + key: "ENG-0", + bindingKey: "ENG-0", + rootThreadId: "thr_old", + title: "Old work", + kind: "ticket", + phase: "Done", + state: "quiet", + phrase: "terminal", + children: [], + endedAt: 1_000, + }); + }); + + it("tolerates a missing thread and null title, phase and reason", () => { + const e = endedEffort(ended({ key: "ENG-0" })); + expect(e.rootThreadId).toBe(""); + expect(e.title).toBe("ENG-0"); + expect(e.phase).toBeNull(); + expect(e.phrase).toBe("ended"); + }); + + it("spells the terse internal end reasons out and passes the rest through", () => { + expect(endReasonPhrase("detach")).toBe("label removed"); + expect(endReasonPhrase("gone")).toBe("no longer listed"); + expect(endReasonPhrase("unconfigured")).toBe("no longer configured"); + expect(endReasonPhrase("deleted")).toBe("deleted"); + expect(endReasonPhrase(null)).toBe("ended"); + }); + + it("puts ended bindings in the tab's ended list, built as efforts", () => { + const tabs = buildSidebar({ + projects: [project({ id: "p1" })], + threads: [], + data: [data({ projectId: "p1", ended: [ended({ key: "ENG-0", title: "Old work", phase: "Done", endReason: "terminal" })] })], + }); + expect(tabs[0]!.ended.map((e) => `${e.key}:${e.kind}:${e.phase}:${e.phrase}:${e.state}:${e.endedAt}`)).toEqual(["ENG-0:ticket:Done:terminal:quiet:1000"]); + }); +}); diff --git a/plugins/stewards/sidebar.ts b/plugins/stewards/sidebar.ts index d2df3f37..64fddb7e 100644 --- a/plugins/stewards/sidebar.ts +++ b/plugins/stewards/sidebar.ts @@ -58,6 +58,10 @@ export interface SidebarEnded { kind: string; threadId: string | null; title: string | null; + /** The entity's final phase, shown on line two; null when the binding has none (BB-88). */ + phase: string | null; + /** Why the binding ended (`terminal`, `detach`, `deleted`, ...), line two's status phrase (BB-88). */ + endReason: string | null; endedAt: number; } @@ -156,7 +160,12 @@ export interface SidebarTab { /** `ops`, Dependabot and Sentry bindings that are neither waiting on you nor blocked. */ monitors: SidebarEffort[]; projectStewardThreadId: string | null; - ended: SidebarEnded[]; + ended: SidebarEndedEffort[]; +} + +/** A Recently ended binding as a row: the same effort shape a live one uses, plus the stamp (BB-88). */ +export interface SidebarEndedEffort extends SidebarEffort { + endedAt: number; } const BUSY = new Set(["starting", "active", "stopping"]); @@ -220,6 +229,16 @@ export function deploymentPhrase(state: DeployState): string { return "deploying"; } +/** + * Line two's status phrase for an ended binding (BB-88): the end reason, with + * the terse internal reasons spelled out. A missing reason reads `ended`. + */ +export function endReasonPhrase(reason: string | null): string { + if (reason === null || reason === "") return "ended"; + const spelled: Record = { detach: "label removed", gone: "no longer listed", unconfigured: "no longer configured" }; + return spelled[reason] ?? reason; +} + /** * A pending note that a worker finished its turn quietly (BB-52 rule 3): the * one whose place a stale status summary must not keep (BB-83). @@ -276,6 +295,45 @@ function derive(e: SidebarEffort, now: number): SidebarEffort { return e; } +/** + * A Recently ended binding as the same `SidebarEffort` shape a live one uses + * (BB-88), so the row renders through `SidebarEffortRow`. There is no live + * thread to join: the title, kind and final phase come from the RPC, the glyph + * is always the grey quiet ring, there are no children, and line two's phrase + * is the end reason. The section shows `ended N ago` separately. + */ +export function endedEffort(e: SidebarEnded): SidebarEndedEffort { + return { + key: e.key, + bindingKey: e.key, + rootThreadId: e.threadId ?? "", + title: e.title ?? e.key, + kind: e.kind, + stage: null, + phase: e.phase ?? null, + hold: null, + holdBehind: [], + blockedOn: null, + needsUser: false, + stuck: false, + statusActor: null, + statusNextAction: null, + statusAt: null, + deployment: null, + pending: [], + requeueAt: null, + runningWorkers: 0, + pinned: false, + busy: false, + recency: e.endedAt, + state: "quiet", + section: "inflight", + phrase: endReasonPhrase(e.endReason ?? null), + children: [], + endedAt: e.endedAt, + }; +} + /** * The title with the key prefix stripped, so line one can show the key and the * title without repeating it. Steward threads are titled `: `, and @@ -527,6 +585,6 @@ function buildTab(project: SidebarLiveProject, data: SidebarProjectData | undefi threads: efforts.filter((e) => e.bindingKey === null).sort(compareEfforts), monitors: ops.filter((e) => e.section === "monitors").sort(compareEfforts), projectStewardThreadId: stewardThreadId, - ended: data?.ended ?? [], + ended: (data?.ended ?? []).map(endedEffort), }; }