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
27 changes: 21 additions & 6 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1270,12 +1270,27 @@ component joins them to `experimental_useSidebarThreads` and polls
`thread-list/thread-list`". Registering the slot therefore makes the stewards
list active on every client that has not pinned a provider, and
`bb settings ui get sidebar.threadListProvider` on the dev server reads
`__automatic__`. **This PR must not land alone:** it lands with the toggle
ticket, whose server-side pin keeps bb's own list for clients that have not
opted in. Until that lands, the list is opt-in only in code, not in effect.

The "Needs you" block and the tab badge are a separate ticket, as is the
footer toggle.
`__automatic__`. **The guard was needed:** without it the list would win by
default. On load the plugin (`server.ts`, `pinSidebarThreadListProvider`)
reads the preference and, when it is unset or `__automatic__`, sets it to
`thread-list/thread-list`; an explicit value is left alone, and a failure is
logged, never thrown. `bb.onInstall` is not usable here — it does not run for
plugins baked into the `bb-server` image — so the pin is on load. BB-44 and
BB-45 are one landing; BB-44 must not land alone.

**The footer toggle (BB-45).** `app.tsx` registers a
`experimental_sidebarFooter` disclosure (`id: "sidebar"`, `icon:
"ShieldCheck"`): a switch that writes the same preference. On sets
`<pluginId>/sidebar`, the id BB-44 registers; off sets
`thread-list/thread-list`. It lists the preference when the disclosure opens
and, on an HTTP 409 revision conflict, re-lists and retries once with the
fresh revision. `__automatic__` (or a missing entry) reads as on, because it
means the stewards list is the effective provider until the pin makes the
choice explicit. The preference is server-synced, so a flip is per server:
every window of one bb server shows the same list. Each developer has their
own server behind bb-gate, so it is per developer in practice.

The "Needs you" block and the tab badge are a separate ticket.

## Known limits

Expand Down
39 changes: 39 additions & 0 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,45 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
put its own binding on hold for this, but only its parent or the project
steward lifts a hold.

## The sidebar thread list and its toggle

BB-44 registers a replacement for bb's own sidebar thread list through the
exclusive `experimental_threadList` slot: one tab per stewarded project,
in-flight efforts grouped by the steward relationship, and collapsed Watches
and Recently ended rows. BB-45 makes it switchable from where you are.

**The footer toggle.** A `ShieldCheck` icon in the sidebar footer (next to
Settings) opens a small panel above the footer row with a **Stewards
sidebar** switch and one line of help. On writes `sidebar.threadListProvider`
= `stewards/sidebar` (the list BB-44 registers); off writes it back to bb's
own `thread-list/thread-list`. The sidebar's list swaps without a reload. The
footer is host-rendered and stays in place under either list, so the icon is
reachable in both states. Hide it like any footer item through bb's footer
preferences (Settings → Appearance → Sidebar → footer items, or
`sidebar.hiddenFooterItems`).

**The Appearance page alternative.** The same choice is Settings → Appearance
→ Sidebar → the thread-list provider; the toggle is a shortcut to it, not a
second setting. Both write the one UI preference.

**The default-provider pin.** bb resolves an unset (`__automatic__`)
provider to the first installed thread list other than the bundled
`thread-list/thread-list` — the stewards list — so without a guard BB-44
would change everyone's sidebar the moment it landed. On load the plugin
reads the preference and, when it is unset or `__automatic__`, sets it to
`thread-list/thread-list`. An explicit value, including `stewards/sidebar`,
is left alone. The write is best-effort: a failure is logged and the sidebar
keeps working. (`bb.onInstall` is not usable here; it does not run for
plugins baked into the `bb-server` image.)

**Per client or per server?** Checked on a dev server: the preference is
**server-synced**, so a flip is per server, not per browser. Every open
window of that bb server shows the same list, and the choice survives a
reload. `bb settings ui get sidebar.threadListProvider` — a different client —
sees the value the toggle wrote, and bb tells the other clients the preference
changed. Each developer has their own server behind bb-gate, so in practice
the choice is per developer.

## Configuration

In the project's `.bb` (the multi-repo project repo), read from committed
Expand Down
104 changes: 103 additions & 1 deletion plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// BB-20: the Stewards page renders a decide item or question with fixed
// choices as one button per choice plus Other…, and a text-only one with
// Answer rather than Done.
import { afterEach, describe, expect, it } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import { fireEvent, waitFor } from "@testing-library/react";
import { loadPluginApp, renderSlot, type CapturedPluginApp, type RenderedSlot } from "@get-bb/plugin-sdk/testing/app";

Expand Down Expand Up @@ -179,3 +179,105 @@ describe("the Stewards page's need links (BB-29)", () => {
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.
describe("the sidebar-footer toggle (BB-45)", () => {
type UiPrefEntry = { value: string; revision: number };
type SetArgs = { key: string; value: string; expectedRevision: number };

/** A `uiPreferences.list()` answer with just the one preference the toggle reads. */
const listed = (entry: UiPrefEntry | null) => ({ preferences: entry === null ? {} : { "sidebar.threadListProvider": entry } }) as never;

const renderToggle = async (options: { entry: UiPrefEntry | null; set: (args: SetArgs) => Promise<unknown> }) => {
const captured = await loadApp();
const item = captured.experimentalSidebarFooterItems[0]!;
if (item.kind !== "disclosure") throw new Error("the sidebar footer item is not a disclosure");
const list = vi.fn(async () => listed(options.entry));
const set = vi.fn(options.set);
const slot = renderSlot({ component: item.component }, { dismiss: () => {} }, { pluginId: "stewards", sdk: { system: { uiPreferences: { list, set } } } as never });
return { slot, set };
};

const echo = async (args: SetArgs) => ({ key: args.key, value: args.value, revision: args.expectedRevision + 1 });

it("registers one footer disclosure under the Stewards sidebar label", async () => {
const captured = await loadApp();
expect(captured.experimentalSidebarFooterItems).toHaveLength(1);
expect(captured.experimentalSidebarFooterItems[0]).toMatchObject({ kind: "disclosure", id: "sidebar", label: "Stewards sidebar", icon: "ShieldCheck" });
});

it("shows the switch off for bb's list and on for the stewards list", async () => {
const off = await renderToggle({ entry: { value: "thread-list/thread-list", revision: 7 }, set: echo });
const offSwitch = await waitFor(() => off.slot.getByRole("switch", { name: "Stewards sidebar" }));
expect(offSwitch.getAttribute("aria-checked")).toBe("false");
off.slot.lifecycle.unmount();

const on = await renderToggle({ entry: { value: "stewards/sidebar", revision: 7 }, set: echo });
const onSwitch = await waitFor(() => on.slot.getByRole("switch", { name: "Stewards sidebar" }));
expect(onSwitch.getAttribute("aria-checked")).toBe("true");
on.slot.lifecycle.unmount();
});

it("reads an unpinned provider as on, the effective stewards list", async () => {
for (const entry of [null, { value: "__automatic__", revision: 0 }]) {
const { slot } = await renderToggle({ entry, set: echo });
const toggle = await waitFor(() => slot.getByRole("switch", { name: "Stewards sidebar" }));
expect(toggle.getAttribute("aria-checked")).toBe("true");
slot.lifecycle.unmount();
}
});

it("turns the stewards list on with the stewards list id and the listed revision", async () => {
const { slot, set } = await renderToggle({ entry: { value: "thread-list/thread-list", revision: 7 }, set: echo });
fireEvent.click(await waitFor(() => slot.getByRole("switch", { name: "Stewards sidebar" })));
await waitFor(() => expect(set).toHaveBeenCalledTimes(1));
expect(set.mock.calls[0]![0]).toEqual({ key: "sidebar.threadListProvider", value: "stewards/sidebar", expectedRevision: 7 });
await waitFor(() => expect(slot.getByRole("switch", { name: "Stewards sidebar" }).getAttribute("aria-checked")).toBe("true"));
slot.lifecycle.unmount();
});

it("turns the stewards list off by setting bb's own list", async () => {
const { slot, set } = await renderToggle({ entry: { value: "stewards/sidebar", revision: 3 }, set: echo });
fireEvent.click(await waitFor(() => slot.getByRole("switch", { name: "Stewards sidebar" })));
await waitFor(() => expect(set).toHaveBeenCalledTimes(1));
expect(set.mock.calls[0]![0]).toEqual({ key: "sidebar.threadListProvider", value: "thread-list/thread-list", expectedRevision: 3 });
await waitFor(() => expect(slot.getByRole("switch", { name: "Stewards sidebar" }).getAttribute("aria-checked")).toBe("false"));
slot.lifecycle.unmount();
});

it("re-lists and retries once when the set hits a revision conflict", async () => {
let sets = 0;
let lists = 0;
const captured = await loadApp();
const item = captured.experimentalSidebarFooterItems[0]!;
if (item.kind !== "disclosure") throw new Error("the sidebar footer item is not a disclosure");
const slot = renderSlot({ component: item.component }, { dismiss: () => {} }, {
pluginId: "stewards",
sdk: {
system: {
uiPreferences: {
list: async () => {
lists += 1;
return listed({ value: "thread-list/thread-list", revision: lists === 1 ? 7 : 9 });
},
set: async (args: SetArgs) => {
sets += 1;
if (sets === 1) throw Object.assign(new Error("revision conflict"), { status: 409 });
return { key: args.key, value: args.value, revision: args.expectedRevision + 1 };
},
},
},
} as never,
});
fireEvent.click(await waitFor(() => slot.getByRole("switch", { name: "Stewards sidebar" })));
await waitFor(() => expect(sets).toBe(2));
expect(slot.inspection.sdkCalls.filter((c) => c.method === "system.uiPreferences.set")).toEqual([
{ method: "system.uiPreferences.set", args: [{ key: "sidebar.threadListProvider", value: "stewards/sidebar", expectedRevision: 7 }] },
{ method: "system.uiPreferences.set", args: [{ key: "sidebar.threadListProvider", value: "stewards/sidebar", expectedRevision: 9 }] },
]);
expect(lists).toBe(2);
slot.lifecycle.unmount();
});
});
122 changes: 122 additions & 0 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
experimental_Icon as Icon,
experimental_ThreadActionsContextMenu as ThreadActionsContextMenu,
experimental_ThreadStatusGlyph as ThreadStatusGlyph,
experimental_usePluginId,
experimental_useSidebarThreads,
useBbNavigate,
useRpc,
useSdk,
useSidebarThreadDraft,
useSidebarThreadRowStatus,
type PluginSidebarThread,
Expand Down Expand Up @@ -1062,6 +1064,117 @@ function StewardsSidebar({ activeProjectId, isCompactViewport, onNavigate }: Plu
);
}

// ---- The sidebar-footer toggle -----------------------------------------------------------------
//
// BB-45: an icon in the sidebar footer that opens a small panel above the
// footer row with a switch for the stewards list BB-44 registers. The footer
// is host-rendered and stays in place under either list, so the toggle is
// reachable in both states. The preference it writes is the one Settings →
// Appearance → Sidebar sets; the value is the plugin id plus the `sidebar`
// slot id BB-44 registers.

/** The value that turns the stewards list on (BB-44's `experimental_threadList` slot). */
function stewardsThreadListId(pluginId: string): string {
return `${pluginId}/sidebar`;
}
/** bb's bundled thread list: the value that turns the stewards list off. */
const BUILTIN_THREAD_LIST_ID = "thread-list/thread-list";
/** What `sidebar.threadListProvider` reads while nothing is pinned. */
const AUTOMATIC_THREAD_LIST_PROVIDER = "__automatic__";
const THREAD_LIST_PROVIDER_KEY = "sidebar.threadListProvider";

/** bb answers a stale `expectedRevision` with HTTP 409. */
function isRevisionConflict(error: unknown): boolean {
const status = typeof error === "object" && error !== null && "status" in error ? (error as { status?: unknown }).status : null;
return status === 409 || /\bHTTP\s*409\b/u.test(String(error));
}

type ThreadListProviderState = { status: "loading" } | { status: "ready"; on: boolean; revision: number } | { status: "error"; message: string };

/**
* The disclosure's body: a switch that writes `sidebar.threadListProvider`.
* The preference is read when the disclosure opens (the component mounts) and
* again after a conflict. `__automatic__` (the value while nothing is pinned)
* means bb picks the stewards list, so it reads as on until the load-time pin
* has made the choice explicit.
*/
function SidebarToggle() {
const sdk = useSdk();
const pluginId = experimental_usePluginId();
const onId = stewardsThreadListId(pluginId);
const [state, setState] = useState<ThreadListProviderState>({ status: "loading" });
const [busy, setBusy] = useState(false);

const read = useCallback(async (): Promise<{ on: boolean; revision: number }> => {
const { preferences } = await sdk.system.uiPreferences.list();
const entry = preferences[THREAD_LIST_PROVIDER_KEY];
const value = entry?.value;
return { on: value === onId || value === undefined || value === AUTOMATIC_THREAD_LIST_PROVIDER, revision: entry?.revision ?? 0 };
}, [sdk, onId]);

useEffect(() => {
let live = true;
read().then(
(next) => {
if (live) setState({ status: "ready", ...next });
},
(error: unknown) => {
if (live) setState({ status: "error", message: message(error) });
},
);
return () => {
live = false;
};
}, [read]);

const flip = useCallback(async () => {
if (state.status !== "ready" || busy) return;
const next = !state.on;
const value = next ? onId : BUILTIN_THREAD_LIST_ID;
setBusy(true);
try {
let revision: number;
try {
revision = (await sdk.system.uiPreferences.set({ key: THREAD_LIST_PROVIDER_KEY, value, expectedRevision: state.revision })).revision;
} catch (error) {
// Another window changed the preference between our list and our set:
// re-list and retry once with the fresh revision. Anything else is a
// real failure.
if (!isRevisionConflict(error)) throw error;
const fresh = await read();
revision = (await sdk.system.uiPreferences.set({ key: THREAD_LIST_PROVIDER_KEY, value, expectedRevision: fresh.revision })).revision;
}
setState({ status: "ready", on: next, revision });
} catch (error) {
setState({ status: "error", message: message(error) });
} finally {
setBusy(false);
}
}, [state, busy, onId, read, sdk]);

const on = state.status === "ready" && state.on;
return (
<div className="flex flex-col gap-1 p-2 text-sm">
<div className="flex items-center justify-between gap-3">
<span className="font-medium">Stewards sidebar</span>
<button
type="button"
role="switch"
aria-checked={on}
aria-label="Stewards sidebar"
disabled={state.status !== "ready" || busy}
className={`relative h-5 w-9 shrink-0 rounded-full border transition-colors disabled:opacity-50 ${on ? "border-success bg-success/70" : "border-input bg-state-hover"}`}
onClick={() => void flip()}
>
<span aria-hidden="true" className={`absolute top-0.5 size-3.5 rounded-full bg-background transition-all ${on ? "left-4" : "left-0.5"}`} />
</button>
</div>
<p className="text-xs text-muted-foreground">Show the stewards list of threads grouped by project and effort. Off shows bb's own list.</p>
{state.status === "error" ? <p className="text-xs text-destructive">Could not change the sidebar: {state.message}</p> : null}
</div>
);
}

export default definePluginApp((app) => {
app.slots.navPanel({
id: "board",
Expand All @@ -1078,6 +1191,15 @@ export default definePluginApp((app) => {
description: "Threads grouped by project and in-flight effort, with stages, workers and reviewers.",
component: StewardsSidebar,
});
// The footer disclosure that writes the provider preference, so the list
// above can be turned on and off without Settings → Appearance.
app.experimental_sidebarFooter.register({
kind: "disclosure",
id: "sidebar",
label: "Stewards sidebar",
icon: "ShieldCheck",
component: SidebarToggle,
});
app.slots.settingsSection({
id: "status",
title: "Status",
Expand Down
Loading
Loading