diff --git a/plugins/stewards/DESIGN.md b/plugins/stewards/DESIGN.md index 9ec7edfa..23c94f93 100644 --- a/plugins/stewards/DESIGN.md +++ b/plugins/stewards/DESIGN.md @@ -108,9 +108,10 @@ These were settled while designing; each changes what gets built. a later wake brings it back. A steward waiting on someone else stays in the sidebar between wakes too, and its finished workers and their reviewers stay with it (§5, "Waiting"). thread-briefs is asked, - through each thread's metadata, not to archive or rename stewards and not - to group the project steward: between wakes a steward reads done while - its entity is still open, and its title carries the entity key. (This + through each thread's metadata, to leave stewards alone entirely: between + wakes a steward reads done while its entity is still open, and its title + carries the entity key, so a brief is wrong on every count — and one is a + model call per idle. (This first left archiving to thread-briefs, which archived every steward whose brief read done, whoever was next. The plugin now decides from the status record instead.) @@ -844,13 +845,14 @@ deployment: # where a merge is confirmed live (BB-53); omi stewarded, the sweep deletes its section once nothing unarchived is left in it, since its stewards are archived as their bindings end; a thread filed there by hand keeps it. -- Stewards, the project steward included, are kept out of thread-briefs' - status sections (`group: false`), where one idle between wakes would read - done. thread-briefs only moves threads in and out of its own sections, so - it leaves the project section alone. Workers and reviewers are tagged the - same way when the `thread.created` handler files them, so thread-briefs - never moves one out of the section or auto-archives it. The project - steward is titled " project steward". +- Stewards, the project steward included, are kept out of thread-briefs + entirely (`threadBriefs: false`): no summary, no stored brief, no status + section, no ring, no auto-archive. One idle between wakes would read done, + and a summary would be a model call per idle. thread-briefs only moves + threads in and out of its own sections, so it leaves the project section + alone. Workers and reviewers are tagged the same way when the + `thread.created` handler files them. The project steward is titled + " project steward". - Workers are children of their steward, owned by it through `--lifecycle-owner-thread` and started with `bb thread spawn --project … --parent-self --parent-notifications off --lifecycle-owner-thread @@ -1560,7 +1562,9 @@ when unread, blue animated while their agent runs, grey otherwise — except a draft, which keeps bb's own `ThreadStatusGlyph`. A worker or reviewer child row under an effort, and a one-off thread's own children, use those same one-off glyphs and carry no role tag; the indent is the only sign of the role. The -project steward footer row is the grey ring. +project steward footer row is the grey ring. Steward rows carry no +thread-briefs ring at all: the single off switch leaves every steward thread +with no brief, so this list's own glyph is the only one they draw. **The status phrase (BB-76).** First match wins: `needs you`; `blocked on `; `held behind ` when `holdBehind` is non-empty, diff --git a/plugins/stewards/README.md b/plugins/stewards/README.md index 030799cf..868ea2c3 100644 --- a/plugins/stewards/README.md +++ b/plugins/stewards/README.md @@ -188,21 +188,19 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run. refuses an archived thread, so it runs `bb thread unarchive ` first, or starts a fresh worker. - **thread-briefs.** Every steward, the project steward included, is - spawned with `threadBriefs: { rename: false, group: false, archive: false }` - in this plugin's metadata namespace (see thread-briefs' "Threads a plugin - runs"). thread-briefs then never renames a steward, whose title carries - its entity key, never moves one into a status section or auto-archives - it, since between wakes it reads done while its entity is still open. + spawned with `threadBriefs: false` in this plugin's metadata namespace (see + thread-briefs' "Threads a plugin runs"). That turns thread-briefs off for + the thread entirely: no summary, no stored brief, no rename, no status + section, no ring and no auto-archive. A steward's title carries its entity + key, and between wakes it reads done while its entity is still open, so a + brief would be wrong on every count — and one is a model call per idle. Workers and reviewers a steward spawns are tagged the same way, so - thread-briefs leaves them in the project's section too. - A ticket or pull request steward's row draws the stage ring like any - thread's. The project steward also gets `ring: false`: it has no stage of - its own, so its row keeps bb's own indicators. The project steward - is titled " project steward". The sweep tags threads - spawned before this, sets parent notifications off on a steward an earlier - version parented to the project steward (keeping the parent), and renames an - older project steward once. After that, a project steward renamed by hand - keeps its name. + thread-briefs leaves them in the project's section too. The project steward + is titled " project steward". The sweep tags threads spawned + before this, sets parent notifications off on a steward an earlier version + parented to the project steward (keeping the parent), and renames an older + project steward once. After that, a project steward renamed by hand keeps + its name. - **The sidebar and the unread dot.** A steward is put in its project's section when it is spawned, and a worker or reviewer the plugin did not place is filed there by the `thread.created` handler. A finished worker diff --git a/plugins/stewards/server.test.ts b/plugins/stewards/server.test.ts index 64ab423f..17ed7800 100644 --- a/plugins/stewards/server.test.ts +++ b/plugins/stewards/server.test.ts @@ -424,7 +424,7 @@ describe("a Linear ticket steward", () => { const [project, steward] = t.spawns; expect(project).toMatchObject({ title: "Acme project steward", providerId: "claude-code", model: "claude-opus-5-5", reasoningLevel: "high" }); // thread-briefs keeps its hands off: no renames, auto-archiving or grouping for any steward, and no row ring for the project steward. - expect(project).toMatchObject({ pluginMetadata: { role: "project", threadBriefs: { rename: false, group: false, archive: false, ring: false } } }); + expect(project).toMatchObject({ pluginMetadata: { role: "project", threadBriefs: false } }); // On the project's machine, never core's "project-default" (the server's own, which may have no daemon). expect(project).toMatchObject({ environment: { type: "provider", environmentProviderId: "multi-repo-workspace", machine: { type: "existing", hostId: "host_on" } } }); // Both in the project's own sidebar section, and nothing pinned. @@ -434,7 +434,7 @@ describe("a Linear ticket steward", () => { expect(project).not.toHaveProperty("pinned"); // A child of the project steward, so the sidebar trees it there, with // notifications off so a finished steward turn does not wake the parent. - expect(steward).toMatchObject({ title: "ENG-12: Fix login", parentThreadId: project!.id, parentNotifications: "off", environment: { type: "reuse", environmentId: "env1" }, model: "claude-sonnet-5-5", pluginMetadata: { role: "steward", threadBriefs: { rename: false, group: false, archive: false } } }); + expect(steward).toMatchObject({ title: "ENG-12: Fix login", parentThreadId: project!.id, parentNotifications: "off", environment: { type: "reuse", environmentId: "env1" }, model: "claude-sonnet-5-5", pluginMetadata: { role: "steward", threadBriefs: false } }); const prompt = String(steward!.prompt); expect(prompt).toMatch(/# Steward wake: ENG-12 — Fix login/u); expect(prompt).toMatch(/You have just been bound/u); @@ -2281,8 +2281,8 @@ describe("the project steward", () => { t.hooks.forgetTags(); await t.hooks.sweep(); expect(t.threads.get(project!.id)!.title).toBe("Acme project steward"); - expect(t.metadata.get(project!.id)).toEqual({ role: "project", threadBriefs: { rename: false, group: false, archive: false, ring: false } }); - expect(t.metadata.get(steward!.id)).toEqual({ role: "steward", threadBriefs: { rename: false, group: false, archive: false } }); + expect(t.metadata.get(project!.id)).toEqual({ role: "project", threadBriefs: false }); + expect(t.metadata.get(steward!.id)).toEqual({ role: "steward", threadBriefs: false }); // A name given by hand afterwards sticks. t.threads.get(project!.id)!.title = "Acme overseer"; @@ -7121,8 +7121,8 @@ describe("steward-spawned threads and the sidebar (BB-39)", () => { const steward = t.spawns[1]!.id; await t.created("thr_w1", steward); await t.created("thr_r1", "thr_w1", "Review the pull request"); - expect(t.metadata.get("thr_w1")).toEqual({ threadBriefs: { rename: false, group: false, archive: false } }); - expect(t.metadata.get("thr_r1")).toEqual({ threadBriefs: { rename: false, group: false, archive: false } }); + expect(t.metadata.get("thr_w1")).toEqual({ threadBriefs: false }); + expect(t.metadata.get("thr_r1")).toEqual({ threadBriefs: false }); }); it("marks a steward read after a report that needs nobody, and leaves it unread when it needs the user", async () => { diff --git a/plugins/stewards/server.ts b/plugins/stewards/server.ts index f94e3a7f..0cb9aadb 100644 --- a/plugins/stewards/server.ts +++ b/plugins/stewards/server.ts @@ -103,16 +103,15 @@ export const BRIEF_MAX_CHARS = 3800; * a plugin runs"). Every steward keeps the title it was given, which carries * the entity key, and is archived by this plugin when its binding ends, or * when a wake turn ends waiting on someone else, rather than whenever its - * brief reads done between wakes. Stewards stay out of the status - * sections, where one idle between wakes would read done: the project - * steward is never finished, and a steward is finished when its binding ends. - * A ticket or pull request steward's row draws the stage ring like any - * thread's, following its entity's work. The project steward's draws none: - * it has no stage to show, and its ring would only say done about a project - * that is not. + * brief reads done between wakes. Stewards stay out of the status sections, + * where one idle between wakes would read done: the project steward is never + * finished, and a steward is finished when its binding ends. Their rows draw + * no ring either: a brief would say done about work that is still open. + * + * One switch for every thread this plugin spawns — steward, project steward, + * worker or reviewer — so thread-briefs writes no brief for any of them. */ -export const STEWARD_BRIEFS = { rename: false, group: false, archive: false } as const; -export const PROJECT_BRIEFS = { ...STEWARD_BRIEFS, ring: false } as const; +export const THREAD_BRIEFS_OFF = false; export interface Timing { /** Rings for one entity within this long are one look. */ @@ -1562,7 +1561,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P * process. A spawn seeds it; this covers threads spawned before it was. */ const tagged = new Set(); - async function tagThread(threadId: string, briefs: typeof STEWARD_BRIEFS | typeof PROJECT_BRIEFS): Promise { + async function tagThread(threadId: string, briefs: typeof THREAD_BRIEFS_OFF): Promise { if (tagged.has(threadId)) return; try { await bb.sdk.threads.updatePluginMetadata({ threadId, set: { threadBriefs: briefs } }); @@ -1764,7 +1763,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P if (row.threadId === null) return; const info = await threadInfo(row.threadId).catch(() => null); if (info === null || info.deletedAt !== null) return; - await tagThread(row.threadId, PROJECT_BRIEFS); + await tagThread(row.threadId, THREAD_BRIEFS_OFF); await placeOnce(projectId, info); if (row.title !== null && info.title !== row.title) return; const title = await projectStewardTitle(projectId); @@ -1792,7 +1791,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P title, ...modelArgs(config.file.projectSteward.model ?? null), ...(sectionId === null ? {} : { sectionId }), - pluginMetadata: { role: "project", threadBriefs: PROJECT_BRIEFS }, + pluginMetadata: { role: "project", threadBriefs: THREAD_BRIEFS_OFF }, }); tagged.add(thread.id); if (sectionId !== null) store.markPlaced(thread.id); @@ -1814,7 +1813,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P const kept = new Set(); async function keepSteward(projectId: string, threadId: string): Promise { if (kept.has(threadId)) return; - await tagThread(threadId, STEWARD_BRIEFS); + await tagThread(threadId, THREAD_BRIEFS_OFF); const info = await threadInfo(threadId).catch(() => null); if (info === null || info.deletedAt !== null) return; const parent = info.parentThreadId; @@ -1848,7 +1847,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P prompt, title: b.kind === "review" ? `Review ${b.entityKey}: ${b.title ?? ""}`.trim() : b.kind === "ops" ? (b.title ?? `Ops watch: ${b.entityKey}`) : `${b.entityKey}: ${b.title ?? ""}`.trim(), ...modelArgs(stewardModel(b, playbook)), - pluginMetadata: { role: "steward", bindingId: b.id, threadBriefs: STEWARD_BRIEFS }, + pluginMetadata: { role: "steward", bindingId: b.id, threadBriefs: THREAD_BRIEFS_OFF }, }; let thread: { id: string }; try { @@ -4385,7 +4384,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P const spawned = spawnedOwner(thread); if (spawned !== null) { await placeOnce(spawned.projectId, { id: thread.id, sectionId: thread.sectionId ?? null }); - await tagThread(thread.id, STEWARD_BRIEFS); + await tagThread(thread.id, THREAD_BRIEFS_OFF); } // A reviewer is a child of a worker. The newest round supersedes the // older ones, so they are archived as it is created (BB-47). diff --git a/plugins/thread-briefs/README.md b/plugins/thread-briefs/README.md index 4d2682a4..108eea84 100644 --- a/plugins/thread-briefs/README.md +++ b/plugins/thread-briefs/README.md @@ -478,8 +478,8 @@ screen: a fresh brief row without the stamp, so working in the thread again puts it back in the normal cycle. - **Nothing busy, hidden, deleted or already archived** is touched. -- **A thread its plugin exempted is never archived**, and neither is one - whose plugin's metadata could not be read. See +- **A thread its plugin keeps out of briefs is never archived**, and neither is + one whose plugin's metadata could not be read. See [Threads a plugin runs](#threads-a-plugin-runs). The sweep runs hourly on its own schedule rather than inside the brief sweep, @@ -490,46 +490,45 @@ so a sweep running up to an hour late is invisible. ## Threads a plugin runs Some threads are not a person's work but a plugin's: a long-lived thread that -plugin wakes and re-wakes, such as a steward. Three things this plugin does -without being asked are wrong for those. Its plugin chose the title, often +plugin wakes and re-wakes, such as a steward. Everything this plugin does +without being asked is wrong for those. Its plugin chose the title, often around a key people search for, so a 4–6 word rename loses it. Between wakes it reads done, so it greys, files under Done and is archived, only to be -brought back on its next wake. And a thread you always want where you left it, -like a project's steward, gets moved between status sections. +brought back on its next wake. A thread you always want where you left it, +like a project's steward, gets moved between status sections. And the summary +itself costs a model call on every idle and every sweep. -So the plugin that spawns a thread can turn each one off, in its own -metadata namespace on the thread: +So the plugin that spawns a thread can turn thread-briefs off for it entirely, +in its own metadata namespace on the thread: ```ts await bb.sdk.threads.spawn({ // ... - pluginMetadata: { role: "project", threadBriefs: { rename: false, group: false, archive: false, ring: false } }, + pluginMetadata: { role: "project", threadBriefs: false }, }); ``` thread-briefs reads that namespace back through the thread's `originPluginId`, which bb sets to whichever plugin seeded the metadata, so it -never has to know which plugins exist. Each key is an opt-out: only `false` -turns its behaviour off, and an absent key leaves it on. A plugin can add the -key to threads it spawned before, with `updatePluginMetadata`. - -| Key | Off means | -| --- | --- | -| `rename` | the title is never replaced with the brief's | -| `group` | the thread stays out of the status sections, in bb's Threads group (or pinned, if you pin it) | -| `archive` | the thread is never auto-archived, and its grey ring does not say "archiving soon" | -| `ring` | the sidebar row draws no ring, so bb's own running, unread and error indicators are all it shows | - -The brief is still written, and the panel, the board, the refresher and the -Stage and Status actions work as for any other thread. The rename, the grouping and the -archive sweep read the namespace live, one request per spawning plugin per -pass. When that read fails, the thread is not renamed or archived and is not -moved between sections, because each of those is something nobody asked for. -The sidebar and the board read a copy stored on the brief at each summary -(`optOut`) to decide whether to draw the ring and whether to say "archiving -soon". A summary refreshes that copy, and so does the ten-minute sweep, so a -plugin that asks for something new of an idle thread is heard within ten -minutes. +never has to know which plugins exist. `false` is the off switch; anything +else — the key absent, `true` — leaves the thread on. A plugin can add the key +to threads it spawned before, with `updatePluginMetadata`. + +Off means off: no summary, no stored brief, no rename, no status section, no +ring, no auto-archive and no re-entry refresher, and the Brief panel says the +thread's plugin keeps it out of briefs rather than offering to make one. The +thread's title is never touched, so a key stays in it. The plugin that spawned +the thread archives it, if it archives it at all. + +A thread tagged before this was a single switch carries the old +`threadBriefs: { rename, group, archive, ring }` object instead; any one of +those keys being `false` reads as off, so it needs no re-tag. That reading can +go a release later. + +The namespace is read live, one request per spawning plugin per pass. When that +read fails, the thread is treated as off for that pass — its brief is kept and +it is skipped — rather than read as on and having its brief deleted or its +title changed on a transient error. ## How it is built diff --git a/plugins/thread-briefs/app.test.tsx b/plugins/thread-briefs/app.test.tsx index dc09e65e..17036124 100644 --- a/plugins/thread-briefs/app.test.tsx +++ b/plugins/thread-briefs/app.test.tsx @@ -357,6 +357,18 @@ describe("the brief panel", () => { slot.lifecycle.unmount(); }); + it("says the thread's plugin keeps it out of briefs, with no summarize offer", async () => { + const slot = await render({ getBrief: () => ({ state: "off" }) }); + + expect( + await slot.findByText("This thread's plugin keeps it out of briefs."), + ).toBeTruthy(); + // No summary is coming and none can be asked for. + expect(slot.queryByText("Summarizing…")).toBeNull(); + expect(slot.queryByRole("button", { name: "Summarize now" })).toBeNull(); + slot.lifecycle.unmount(); + }); + it("surfaces the unconfigured message instead of an empty brief", async () => { const slot = await render({ getBrief: () => ({ state: "unconfigured", message: "Add an API key." }), diff --git a/plugins/thread-briefs/app.tsx b/plugins/thread-briefs/app.tsx index 89905d62..3ed3a6b5 100644 --- a/plugins/thread-briefs/app.tsx +++ b/plugins/thread-briefs/app.tsx @@ -448,6 +448,15 @@ function BriefBody({ if (state.state === "summarizing") { return
Summarizing…
; } + if (state.state === "off") { + // The thread's plugin keeps it out of briefs entirely: there is no brief + // and no summary coming, so explain rather than offer to make one. + return ( +
+ This thread's plugin keeps it out of briefs. +
+ ); + } if (state.state === "absent") { // Threads that were already dormant when the plugin arrived are not // backfilled, so say so and offer to make one rather than spinning. diff --git a/plugins/thread-briefs/brief.ts b/plugins/thread-briefs/brief.ts index aa669e94..8f63d1e0 100644 --- a/plugins/thread-briefs/brief.ts +++ b/plugins/thread-briefs/brief.ts @@ -268,13 +268,12 @@ export function briefCardFor(stored: StoredBrief): BriefCard { : { nextStepActor: resolved.nextStepActor }), blockedOn: resolved.blockedOn, lastSummarizedAt: resolved.lastSummarizedAt, - autoArchive: autoArchives(stored), + // Always true now: the per-key opt-out is gone, so a thread with a stored + // brief is always auto-archivable. Kept on the wire for the board's shape. + autoArchive: true, }; } -/** Whether the archive sweep may take this thread, as far as its brief knows. */ -const autoArchives = (stored: StoredBrief): boolean => !(stored.optOut?.archive ?? false); - export function rowSignalFor(stored: StoredBrief): RowSignal { const brief = resolveBrief(stored); const pinned = brief.stageOverride !== null || brief.statusOverride !== null; @@ -286,8 +285,11 @@ export function rowSignalFor(stored: StoredBrief): RowSignal { pinned, stageOverride: brief.stageOverride, statusOverride: brief.statusOverride, - autoArchive: autoArchives(stored), - ring: !(stored.optOut?.ring ?? false), + // Both always true now that the single off switch removes a thread's brief + // entirely: a stored brief is always auto-archivable and always draws a + // ring. Kept on the wire for the client's shape. + autoArchive: true, + ring: true, }; } diff --git a/plugins/thread-briefs/contract.ts b/plugins/thread-briefs/contract.ts index 0ec300d6..79e93976 100644 --- a/plugins/thread-briefs/contract.ts +++ b/plugins/thread-briefs/contract.ts @@ -324,27 +324,13 @@ export const storedBriefSchema = z */ autoArchivedAt: z.number().nullable().optional(), /** - * What the plugin that spawned this thread exempted it from, as of the - * last summary: see `optout.ts`. Absent means nothing, which is every - * thread a person started. - * - * Stored for the sidebar and the board, which draw from stored briefs - * alone: `ring` decides whether the row draws one, and `archive` whether - * "archiving soon" is true. Refreshed at each summary and by the brief - * sweep. The rename, the grouping and the archive sweep read the live - * namespace instead, so a stale copy here never decides those. - * - * `ring` is optional because rows were written before it existed. + * The per-key `optOut` that used to sit here is gone with the single + * switch (BB-101). A row written before this carries it, and `.strict()` + * makes that row fail to parse, so `readBrief` drops it. That is the + * intended one-time cleanup: the only rows that ever carried `optOut` were + * the threads whose plugin had opted them out of something, and those are + * exactly the threads this change turns off entirely. */ - optOut: z - .object({ - rename: z.boolean(), - group: z.boolean(), - archive: z.boolean(), - ring: z.boolean().optional(), - }) - .strict() - .optional(), lastSummarizedAt: z.number(), /** The thread's `conversationOutline().maxSeq` at summarize time. */ lastActivitySeen: z.number(), @@ -371,15 +357,19 @@ export type ResolvedBrief = z.infer; /** * What the frontend sees for one thread. * - * `summarizing` means work is genuinely pending — queued or in flight. `absent` means there is no brief and none is coming, which is the - * normal state for a thread that was already dormant when the plugin arrived: - * briefs are not backfilled, so the UI offers to make one on demand rather - * than claiming a summary is on its way. + * `summarizing` means work is genuinely pending — queued or in flight. `absent` + * means there is no brief and none is coming, which is the normal state for a + * thread that was already dormant when the plugin arrived: briefs are not + * backfilled, so the UI offers to make one on demand rather than claiming a + * summary is on its way. `off` means the thread's owning plugin asked for + * thread-briefs to leave it alone entirely (see `optout.ts`): there is no brief + * and there never will be, so the UI explains rather than offering a summary. */ export const briefStateSchema = z.discriminatedUnion("state", [ z.object({ state: z.literal("ready"), brief: resolvedBriefSchema }).strict(), z.object({ state: z.literal("summarizing") }).strict(), z.object({ state: z.literal("absent") }).strict(), + z.object({ state: z.literal("off") }).strict(), z.object({ state: z.literal("unconfigured"), message: z.string() }).strict(), z.object({ state: z.literal("error"), message: z.string() }).strict(), ]); diff --git a/plugins/thread-briefs/optout.test.ts b/plugins/thread-briefs/optout.test.ts index ce234557..0f33851d 100644 --- a/plugins/thread-briefs/optout.test.ts +++ b/plugins/thread-briefs/optout.test.ts @@ -1,29 +1,44 @@ import { describe, expect, it } from "vitest"; -import { NO_OPT_OUT, readOptOut } from "./optout.js"; +import { readOptOut } from "./optout.js"; describe("readOptOut", () => { - it("reads each false as an opt-out", () => { + it("reads the switch as off only for false", () => { + expect(readOptOut({ role: "steward", threadBriefs: false })).toBe(true); + expect(readOptOut({ threadBriefs: true })).toBe(false); + expect(readOptOut({ threadBriefs: "false" })).toBe(false); + expect(readOptOut({ threadBriefs: null })).toBe(false); + }); + + it("reads the legacy object as off when any one key is false", () => { expect( readOptOut({ role: "project", threadBriefs: { rename: false, group: false, archive: false, ring: false }, }), - ).toEqual({ rename: true, group: true, archive: true, ring: true }); - expect(readOptOut({ threadBriefs: { archive: false } })).toEqual({ - rename: false, - group: false, - archive: true, - ring: false, - }); + ).toBe(true); + // Any single key is enough: the four were independent, and one of them + // being off is what the old shape meant. + expect(readOptOut({ threadBriefs: { rename: false } })).toBe(true); + expect(readOptOut({ threadBriefs: { group: false } })).toBe(true); + expect(readOptOut({ threadBriefs: { archive: false } })).toBe(true); + expect(readOptOut({ threadBriefs: { ring: false } })).toBe(true); + }); + + it("leaves a legacy object with every key true on", () => { + expect( + readOptOut({ threadBriefs: { rename: true, group: true, archive: true, ring: true } }), + ).toBe(false); + // A partial object with nothing false is on too: the legacy reading is + // "off when at least one key is false", not "off when not all are true". + expect(readOptOut({ threadBriefs: { rename: true } })).toBe(false); }); - it("leaves everything on for anything but false", () => { - // A typo or a truthy string must not quietly exempt a thread. - expect(readOptOut({ threadBriefs: { rename: true, group: "no", archive: 0 } })).toEqual( - NO_OPT_OUT, - ); - expect(readOptOut({ threadBriefs: null })).toEqual(NO_OPT_OUT); - expect(readOptOut({})).toEqual(NO_OPT_OUT); - expect(readOptOut(undefined)).toEqual(NO_OPT_OUT); + it("leaves a thread with no threadBriefs value on", () => { + // The namespace exists for the plugin's own role tag; the absence of the + // key is not an opt-out. + expect(readOptOut({ role: "steward" })).toBe(false); + expect(readOptOut({})).toBe(false); + expect(readOptOut(undefined)).toBe(false); + expect(readOptOut(null)).toBe(false); }); }); diff --git a/plugins/thread-briefs/optout.ts b/plugins/thread-briefs/optout.ts index 9724798e..1e0fbacb 100644 --- a/plugins/thread-briefs/optout.ts +++ b/plugins/thread-briefs/optout.ts @@ -1,5 +1,5 @@ /** - * Which of this plugin's hands-on behaviours a thread is exempt from. + * Whether a plugin asked thread-briefs to leave a thread alone entirely. * * Pure: the lookups live in `server.ts`. The exemption is asked for by the * plugin that spawned the thread, not by this one: a plugin that runs a @@ -8,7 +8,7 @@ * the one thread you always want where you left it. So it seeds * * ```ts - * pluginMetadata: { threadBriefs: { rename: false, group: false, archive: false, ring: false } } + * pluginMetadata: { threadBriefs: false } * ``` * * in its own metadata namespace when it spawns the thread, and this plugin @@ -19,54 +19,36 @@ * `lifecycleOwnerThreadId` chain, and the tag still lives in that plugin's * namespace. This plugin never has to know which plugins exist. * - * Each key is an opt-out: `false` turns that behaviour off for the thread, - * and anything else — absent, `true`, a typo — leaves it on. The brief itself - * is still written: the panel and the board show it. What is covered is the - * three things that change the thread or the sidebar without being asked, - * and the row's ring, which for a thread that idles between wakes mostly - * says "done" about work that is not. + * Off is one switch for the whole thread: no summary, no stored brief, no + * rename, no section, no ring, no auto-archive, no re-entry refresher and no + * Stage/Status actions — the brief's absence is what makes every one of those + * skip it. + * + * The legacy per-key object is read too, and off when any one of its keys is + * `false`, so a thread tagged before the switch needs no re-tag. That reading + * can go a release later. */ /** The key a spawning plugin sets in its own metadata namespace. */ export const OPT_OUT_KEY = "threadBriefs"; -/** True means the thread is exempt from that behaviour. */ -export interface OptOut { - /** Keep the thread's title: never rename it to the brief's. */ - rename: boolean; - /** Keep the thread out of the status sections. */ - group: boolean; - /** Never auto-archive the thread. */ - archive: boolean; - /** Draw no ring on the thread's sidebar row; bb's own indicators show. */ - ring: boolean; -} - -export const NO_OPT_OUT: OptOut = { rename: false, group: false, archive: false, ring: false }; - /** - * Used when the origin plugin's namespace could not be read. Every behaviour - * here is one the user did not ask for, so not knowing is a reason to hold - * back: a thread left unrenamed or in the sidebar costs nothing, one archived - * against its plugin's wishes is the case this exists to prevent. + * Whether the owning plugin's metadata namespace turns thread-briefs off. + * + * `threadBriefs: false` is off. A legacy `{ rename, group, archive, ring }` + * object is off when at least one key is `false`. Anything else — no value at + * all, `true`, or an object with every key true — leaves the thread on. */ -export const FULL_OPT_OUT: OptOut = { rename: true, group: true, archive: true, ring: true }; - -/** The opt-out a plugin's metadata namespace asks for. */ -export function readOptOut(metadata: unknown): OptOut { - if (typeof metadata !== "object" || metadata === null) return NO_OPT_OUT; +export function readOptOut(metadata: unknown): boolean { + if (typeof metadata !== "object" || metadata === null) return false; const value = (metadata as Record)[OPT_OUT_KEY]; - if (typeof value !== "object" || value === null) return NO_OPT_OUT; + if (value === false) return true; + if (typeof value !== "object" || value === null) return false; const entry = value as Record; - return { - rename: entry.rename === false, - group: entry.group === false, - archive: entry.archive === false, - ring: entry.ring === false, - }; -} - -/** Whether an opt-out turns anything off at all. */ -export function optsOutOfAnything(optOut: OptOut): boolean { - return optOut.rename || optOut.group || optOut.archive || optOut.ring; + return ( + entry.rename === false || + entry.group === false || + entry.archive === false || + entry.ring === false + ); } diff --git a/plugins/thread-briefs/server.test.ts b/plugins/thread-briefs/server.test.ts index 76d10cd6..010970f5 100644 --- a/plugins/thread-briefs/server.test.ts +++ b/plugins/thread-briefs/server.test.ts @@ -1754,6 +1754,29 @@ describe("sidebar grouping by status", () => { await harness.lifecycle.dispose(); }); + it("takes a thread tagged with the single switch out of the sections", async () => { + const threads = [ + groupedThread({ id: "thr_plain", sectionId: null }), + // Filed before its plugin asked for thread-briefs to leave it alone. + groupedThread({ id: "thr_steward", sectionId: "sec_3", originPluginId: "stewards" }), + ]; + const { bb, harness } = groupingHost({ + threads, + listPluginMetadata: metadataFrom({ + thr_steward: { role: "project", threadBriefs: false }, + }), + }); + const done = { nextStep: "", blockedOn: "" }; + await bb.storage.kv.set("brief:thr_plain", storedBrief("thr_plain", done)); + await bb.storage.kv.set("brief:thr_steward", storedBrief("thr_steward", done)); + await plugin(bb); + + await settle(() => threads[0]!.sectionId === "sec_3"); + await settle(() => threads[1]!.sectionId === null); + + await harness.lifecycle.dispose(); + }); + it("takes a worker keyed on its steward's namespace out of the sections", async () => { const threads = [ groupedThread({ id: "thr_steward", sectionId: null, originPluginId: "stewards" }), @@ -2031,6 +2054,8 @@ describe("renaming threads", () => { ownerMetadata?: Record; /** The CLI-spawned worker's own opt-out under the owning plugin's namespace. */ workerMetadata?: Record; + /** Fail every plugin-metadata read, as a transient error would. */ + metadataFails?: boolean; }) { const ownerId = "thr_steward"; const chain = options.ownerMetadata !== undefined; @@ -2102,7 +2127,12 @@ describe("renaming threads", () => { maxSeq: seq, }), interactions: { list: async () => [] }, - experimental_listPluginMetadata: metadataFrom(metadata), + experimental_listPluginMetadata: + options.metadataFails === true + ? async () => { + throw new Error("503"); + } + : metadataFrom(metadata), }, }, }); @@ -2200,67 +2230,58 @@ describe("renaming threads", () => { await current.harness.lifecycle.dispose(); }); - it("keeps the title of a thread its plugin asked to keep", async () => { + it("writes no brief for a thread its plugin keeps out of briefs", async () => { const current = renameHost({ title: "ENG-42: Fix the flaky test", - originMetadata: { role: "steward", threadBriefs: { rename: false, archive: false } }, + originMetadata: { role: "steward", threadBriefs: false }, }); await plugin(current.bb); - await summarize(current); + await current.harness.behavior.callRpc("refresh", { threadId: "thr_1" }); + await new Promise((resolve) => setTimeout(resolve, 50)); expect(current.live.title).toBe("ENG-42: Fix the flaky test"); expect(current.harness.sdk.callsTo("threads.update")).toHaveLength(0); - // Stored, so the sidebar knows not to promise an archiving. - const stored = await current.bb.storage.kv.get("brief:thr_1"); - expect(stored?.optOut).toEqual({ rename: true, group: false, archive: true, ring: false }); - const { signals } = (await current.harness.behavior.callRpc("listRowSignals", null)) as { - signals: { autoArchive: boolean }[]; - }; - expect(signals[0]?.autoArchive).toBe(false); + expect(current.fetchMock).not.toHaveBeenCalled(); + expect(await current.bb.storage.kv.get("brief:thr_1")).toBeUndefined(); + const state = (await current.harness.behavior.callRpc("getBrief", { + threadId: "thr_1", + })) as BriefState; + expect(state.state).toBe("off"); await current.harness.lifecycle.dispose(); }); - it("keeps the title of a CLI-spawned worker whose steward asked to keep it", async () => { + it("reads the legacy per-key object as off, without a re-tag", async () => { + // A thread tagged before the single switch: any one key false is off, so + // it needs no re-tag and gets no brief. const current = renameHost({ title: "ENG-42: Fix the flaky test", - ownerMetadata: { role: "steward", threadBriefs: { rename: false, archive: false } }, - workerMetadata: { role: "worker", threadBriefs: { rename: false, archive: false } }, + originMetadata: { role: "steward", threadBriefs: { rename: false, archive: false } }, }); await plugin(current.bb); - await summarize(current); + await current.harness.behavior.callRpc("refresh", { threadId: "thr_1" }); + await new Promise((resolve) => setTimeout(resolve, 50)); - // The worker has no origin plugin of its own; the opt-out is found through - // its lifecycle owner and still keeps its title. expect(current.live.title).toBe("ENG-42: Fix the flaky test"); - expect(current.harness.sdk.callsTo("threads.update")).toHaveLength(0); + expect(current.fetchMock).not.toHaveBeenCalled(); + expect(await current.bb.storage.kv.get("brief:thr_1")).toBeUndefined(); await current.harness.lifecycle.dispose(); }); - it("brings a stored opt-out up to date in the sweep, without a summary", async () => { - // A steward idle since before its plugin asked for no ring: the sidebar - // draws from the stored copy, so the sweep has to refresh it. + it("keeps a brief when the owning plugin's namespace cannot be read", async () => { + // A read failure is off for this pass, not an opt-out: the thread is + // skipped and its existing brief kept, so a transient error never deletes + // a one-off thread's brief. const current = renameHost({ - originMetadata: { role: "steward", threadBriefs: { rename: false, archive: false } }, + originMetadata: { role: "worker" }, + metadataFails: true, }); + await current.bb.storage.kv.set("brief:thr_1", storedBrief("thr_1", {})); await plugin(current.bb); - await summarize(current); - const before = await current.bb.storage.kv.get("brief:thr_1"); - expect(before?.optOut?.ring).toBe(false); - - current.metadata.thr_1 = { - role: "steward", - threadBriefs: { rename: false, archive: false, ring: false }, - }; - await current.harness.behavior.runSchedule("brief-sweep"); + await current.harness.behavior.callRpc("refresh", { threadId: "thr_1" }); + await new Promise((resolve) => setTimeout(resolve, 50)); - const after = await current.bb.storage.kv.get("brief:thr_1"); - expect(after?.optOut).toEqual({ rename: true, group: false, archive: true, ring: true }); - // Nothing else on the row moved. - expect(after?.lastSummarizedAt).toBe(before?.lastSummarizedAt); - const { signals } = (await current.harness.behavior.callRpc("listRowSignals", null)) as { - signals: { ring: boolean }[]; - }; - expect(signals[0]?.ring).toBe(false); + expect(await current.bb.storage.kv.get("brief:thr_1")).toBeDefined(); + expect(current.fetchMock).not.toHaveBeenCalled(); await current.harness.lifecycle.dispose(); }); @@ -2270,8 +2291,6 @@ describe("renaming threads", () => { await summarize(current); expect(current.live.title).toBe("Sidebar grouping by status"); - const stored = await current.bb.storage.kv.get("brief:thr_1"); - expect(stored?.optOut).toBeUndefined(); await current.harness.lifecycle.dispose(); }); diff --git a/plugins/thread-briefs/server.ts b/plugins/thread-briefs/server.ts index 29a95a1a..f4e81470 100644 --- a/plugins/thread-briefs/server.ts +++ b/plugins/thread-briefs/server.ts @@ -46,11 +46,7 @@ import { } from "./config.js"; import { endsWithQuestion, renderTranscript, type OutlineItem } from "./transcript.js"; import { - FULL_OPT_OUT, - NO_OPT_OUT, - optsOutOfAnything, readOptOut, - type OptOut, } from "./optout.js"; import { mergeSectionOrder, @@ -408,24 +404,25 @@ export default async function plugin(bb: BbPluginApi) { const pluginOwner = new Map(); /** - * Each thread's opt-out, read from the namespace of the plugin that owns - * it: its own origin plugin, or the nearest ancestor's through the + * Whether each thread is off, read from the namespace of the plugin that + * owns it: its own origin plugin, or the nearest ancestor's through the * lifecycle-owner chain when it has none (a worker or reviewer spawned by * the CLI). See `optout.ts`. * * A thread no plugin owns costs nothing. The rest are batched per plugin, * so a pass over the whole sidebar is one request per plugin rather than one * per thread. null means that namespace could not be read, and each caller - * decides what not knowing means for it. + * decides what not knowing means for it: off for this pass, keeping the + * brief and skipping the thread rather than reading the failure as "on". */ - async function optOutsFor( + async function briefsOffFor( threads: readonly { id: string; originPluginId: string | null; lifecycleOwnerThreadId?: string | null; }[], - ): Promise> { - const result = new Map(); + ): Promise> { + const result = new Map(); const byPlugin = new Map(); // A thread's owning plugin never changes, so the answer is kept across // passes: a hidden steward is absent from some batches, and its workers @@ -476,13 +473,13 @@ export default async function plugin(bb: BbPluginApi) { else if (thread.lifecycleOwnerThreadId == null) pluginId = null; else pluginId = await ownerPlugin(thread.lifecycleOwnerThreadId); if (pluginId === undefined) { - // A read failed: unknown, which every caller treats fail-safe (see - // `FULL_OPT_OUT`), rather than opted in. + // A read failed: unknown, which every caller treats as off for this + // pass rather than opted in. result.set(thread.id, null); continue; } if (pluginId === null) { - result.set(thread.id, NO_OPT_OUT); + result.set(thread.id, false); continue; } const ids = byPlugin.get(pluginId) ?? []; @@ -651,6 +648,17 @@ export default async function plugin(bb: BbPluginApi) { await deleteBrief(threadId); return true; } + // A thread its plugin keeps out of briefs entirely: drop any stored brief + // and stop. Everything else — the panel, the board, the ring, the sections + // and the archive sweep — skips it because there is no brief. null is a + // namespace we could not read: off for this pass, so the thread is skipped + // and its brief kept rather than deleted on a read failure. + const off = (await briefsOffFor([thread])).get(thread.id) ?? null; + if (off === null) return false; + if (off) { + await deleteBrief(threadId); + return true; + } const outline = await bb.sdk.threads.conversationOutline({ threadId }); if (outline.items.length === 0) return false; @@ -667,7 +675,6 @@ export default async function plugin(bb: BbPluginApi) { const config = await completionConfig(); const { output } = await bb.sdk.threads.output({ threadId }); - const optOut = (await optOutsFor([thread])).get(threadId) ?? null; // A stage override in force is passed to the model as fixed; one the thread // has moved past is dropped here, which is what "sticks until real thread @@ -736,10 +743,8 @@ export default async function plugin(bb: BbPluginApi) { // A thread bb has already named waits for its first turn to end before this // plugin renames it; one showing nothing but its own opening prompt does - // not. See {@link summarizeThread}. A thread whose plugin keeps its title, - // or whose plugin we could not ask, is never renamed. - const appliedTitle = (beforeFirstTurn && thread.title !== null) || - (optOut ?? FULL_OPT_OUT).rename + // not. See {@link summarizeThread}. + const appliedTitle = beforeFirstTurn && thread.title !== null ? (stored?.appliedTitle ?? null) : await applyTitle({ threadId, @@ -784,65 +789,35 @@ export default async function plugin(bb: BbPluginApi) { endedWithQuestion: endsWithQuestion(output), appliedTitle, refresher, - ...exemptionsToStore(optOut, stored), lastSummarizedAt: Date.now(), lastActivitySeen: outline.maxSeq, }); return true; } - /** - * The `optOut` a fresh brief row carries: this summary's reading, or the - * last one when the namespace could not be read. Left off entirely for a - * thread exempt from nothing, which is nearly every thread. - */ - const exemptionsToStore = ( - optOut: OptOut | null, - stored: StoredBrief | null, - ): { optOut?: OptOut } => { - const kept = optOut ?? (stored?.optOut ? { ring: false, ...stored.optOut } : null); - return kept !== null && optsOutOfAnything(kept) ? { optOut: kept } : {}; - }; + // -------------------------------------------------------------- reading /** - * Bring the `optOut` stored on briefs up to date with each thread's plugin. - * - * A summary refreshes it, but a steward can sit idle for days, and a plugin - * can ask for something new of threads it spawned long ago. The sidebar - * draws from the stored copy alone, so without this a ring a plugin turned - * off would stay until the thread's next turn. Only rows that change are - * written, and the sidebar is told once. + * One thread's off switch, fetched fresh. Used by `briefState` to tell a + * thread its plugin keeps out of briefs from one that simply has none yet. + * null means the namespace could not be read, which reads as on here: the + * panel should not claim an opt-out it could not confirm. */ - async function syncStoredOptOuts( - threads: readonly { - id: string; - originPluginId: string | null; - lifecycleOwnerThreadId?: string | null; - }[], - ): Promise { - const fromPlugins = threads.filter( - (thread) => thread.originPluginId !== null || thread.lifecycleOwnerThreadId != null, - ); - if (fromPlugins.length === 0) return; - let changed = 0; - for (const [threadId, optOut] of await optOutsFor(fromPlugins)) { - if (optOut === null) continue; - const stored = await readBrief(threadId); - if (stored === null) continue; - const next = exemptionsToStore(optOut, stored).optOut; - if (JSON.stringify(next) === JSON.stringify(stored.optOut)) continue; - const { optOut: _old, ...rest } = stored; - await writeBrief(next === undefined ? rest : { ...rest, optOut: next }); - changed += 1; - } - if (changed > 0) announce(); - } - - // -------------------------------------------------------------- reading + const briefOffFor = async (threadId: string): Promise => { + const thread = await bb.sdk.threads.get({ threadId }).catch(() => null); + if (thread === null) return null; + return (await briefsOffFor([thread])).get(thread.id) ?? null; + }; const briefState = async (threadId: string): Promise => { const stored = await readBrief(threadId); if (stored === null) { + // A thread its plugin keeps out of briefs has no brief and never will, + // so say that rather than offering to summarize it. Only asked when there + // is no brief: a stale one is removed by the next summary, and checking + // the namespace on every panel read of every thread would cost a + // `threads.get` for nothing. + if ((await briefOffFor(threadId)) === true) return { state: "off" }; if (!hasApiKey(await settings.get())) { return { state: "unconfigured", @@ -1259,17 +1234,17 @@ export default async function plugin(bb: BbPluginApi) { } const threads = await listGroupableThreads(); - const optOuts = await optOutsFor(threads); + const briefsOff = await briefsOffFor(threads); const targets = await sectionIdByThreadId(sectionIds); // A thread its plugin keeps out of the grouping is planned as briefless, // which takes it out of our sections and back to bb's Threads group. One - // whose plugin we could not ask is left exactly where it is: a failed + // whose plugin we could not read is left exactly where it is: a failed // read should not shuffle the sidebar for one pass. - for (const [threadId, optOut] of optOuts) { - if (optOut === null || optOut.group) targets.delete(threadId); + for (const [threadId, off] of briefsOff) { + if (off) targets.delete(threadId); } const moves = planAssignments({ - threads: threads.filter((thread) => optOuts.get(thread.id) !== null), + threads: threads.filter((thread) => briefsOff.get(thread.id) !== null), sectionIdByThreadId: targets, ownedSectionIds: new Set(sectionIds.values()), }); @@ -1393,10 +1368,6 @@ export default async function plugin(bb: BbPluginApi) { */ bb.background.schedule("brief-sweep", SWEEP_CRON, async () => { const threads = await bb.sdk.threads.list({ limit: SWEEP_LIMIT }); - // Reads no summarizer, so it runs with or without a key. - await syncStoredOptOuts( - threads.filter((thread) => thread.archivedAt === null && thread.deletedAt === null), - ); const values = await settings.get(); if (!hasApiKey(values)) return; @@ -1449,7 +1420,7 @@ export default async function plugin(bb: BbPluginApi) { if (archiveAfterMs <= 0) return; const threads = await bb.sdk.threads.list({ limit: ARCHIVE_LIMIT }); - const optOuts = await optOutsFor( + const briefsOff = await briefsOffFor( threads.filter((thread) => thread.archivedAt === null && thread.deletedAt === null), ); const candidates: ArchiveCandidate[] = threads.map((thread) => ({ @@ -1460,8 +1431,8 @@ export default async function plugin(bb: BbPluginApi) { deletedAt: thread.deletedAt, visibility: thread.visibility, status: thread.status, - // Not knowing is a reason to keep it: see `FULL_OPT_OUT`. - optedOut: (optOuts.get(thread.id) ?? FULL_OPT_OUT).archive, + // Not knowing is a reason to keep it: a failed read is off for this pass. + optedOut: briefsOff.get(thread.id) ?? true, })); // Briefs read per candidate rather than by scanning the kv prefix: the diff --git a/plugins/thread-briefs/skills/thread-briefs/SKILL.md b/plugins/thread-briefs/skills/thread-briefs/SKILL.md index 5e708f84..21b65dad 100644 --- a/plugins/thread-briefs/skills/thread-briefs/SKILL.md +++ b/plugins/thread-briefs/skills/thread-briefs/SKILL.md @@ -446,8 +446,8 @@ Other things worth knowing: - **Turning it off does not undo anything.** bb's original title is not kept anywhere; the last name the plugin wrote stays. Rename by hand to change it. - Branch names are derived at thread creation and are unaffected. -- A thread whose spawning plugin set `threadBriefs.rename: false` in its own - metadata namespace is never renamed. See +- A thread whose spawning plugin set `threadBriefs: false` in its own + metadata namespace is left alone entirely. See [Threads a plugin exempted](#threads-a-plugin-exempted). ## Sidebar glyphs @@ -823,26 +823,25 @@ no preference writes. ## Threads a plugin exempted -A plugin that spawns a thread can exempt it from three things by setting -`threadBriefs: { rename: false, group: false, archive: false, ring: false }` (any subset) -in its own metadata namespace on that thread. thread-briefs reads it through -the thread's `originPluginId`. Stewards does this: no steward is renamed or -auto-archived, and every steward, the project steward included, is kept out of -the status sections. Ticket and pull request steward rows draw the ring; the -project steward's does not. - -- A thread kept out of the sections sits in bb's **Threads** group. Pin it to - keep it at the top. -- An exempt thread still gets a brief and a board card. With `ring: false` - its row shows only bb's own indicators; otherwise it still goes grey when - done and idle, but with `archive: false` its label does not say "archiving - soon". The stored copy the sidebar reads is refreshed by the ten-minute - sweep, so a newly asked-for opt-out shows within ten minutes. -- If the origin plugin's namespace cannot be read (the plugin is gone, or the - request fails), the thread is not renamed or archived and is not moved - between sections. The logs show `could not read 's metadata`. -- To see what a thread asked for: `optOut` on its stored brief, written at - each summary, or the origin plugin's namespace itself. +A plugin that spawns a thread can turn thread-briefs off for it entirely by +setting `threadBriefs: false` in its own metadata namespace on that thread. +thread-briefs reads it through the thread's `originPluginId`. Stewards does +this for every steward, the project steward included, and for the workers and +reviewers a steward spawns. + +- Off means no summary, no stored brief, no rename, no status section, no + ring, no auto-archive and no re-entry refresher. The Brief panel says the + thread's plugin keeps it out of briefs. The plugin that spawned the thread + archives it, if it archives it at all. +- A thread tagged before this was a single switch carries the old + `threadBriefs: { rename, group, archive, ring }` object; any one key being + `false` reads as off, so it needs no re-tag. That reading can go a release + later. +- If the owning plugin's namespace cannot be read (the plugin is gone, or the + request fails), the thread is treated as off for that pass: it is skipped + and its brief is kept, rather than read as on and deleted. The logs show + `could not read 's metadata`. +- To see what a thread asked for: the origin plugin's namespace itself. ## Diagnosing