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
7 changes: 7 additions & 0 deletions plugins/github-watcher/source-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,13 @@ export const sourceContract = {
priority: z.enum(["none", "urgent", "high", "medium", "low"]).optional(),
parent: z.string().min(1).max(200).optional(),
assignee: z.string().min(1).max(200).optional(),
/**
* BB-361: the playbook a local ticket runs under, `ticket` (the default,
* `local-tickets`) or `initiative`. Linear and github have no playbook of
* their own and ignore it; the local source stores it and the snapshot's
* optional `playbook` field carries it back.
*/
playbook: z.string().min(1).max(200).optional(),
}),
output: z.object({ id: z.string(), key: z.string(), url: z.string().nullable() }),
},
Expand Down
7 changes: 7 additions & 0 deletions plugins/linear/source-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,13 @@ export const sourceContract = {
priority: z.enum(["none", "urgent", "high", "medium", "low"]).optional(),
parent: z.string().min(1).max(200).optional(),
assignee: z.string().min(1).max(200).optional(),
/**
* BB-361: the playbook a local ticket runs under, `ticket` (the default,
* `local-tickets`) or `initiative`. Linear and github have no playbook of
* their own and ignore it; the local source stores it and the snapshot's
* optional `playbook` field carries it back.
*/
playbook: z.string().min(1).max(200).optional(),
}),
output: z.object({ id: z.string(), key: z.string(), url: z.string().nullable() }),
},
Expand Down
15 changes: 14 additions & 1 deletion plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
of its first 96 turns on bithub, so stewards were top-level.) Grouping in
the sidebar is bb's own: its project organization, or the stewards thread
list; the plugin makes no sidebar sections (DESIGN.md §15).
- **Local tickets.** A third source, `local`, keeps a ticket in the stewards
store rather than Linear or GitHub. `ticket_file { unit: "local" }` files
one under the project's prefix (`LOCAL` by default, `localPrefix` to
override); it is adopted by state, not by label: Backlog is parked, Ready or
later non-terminal is adopted, and `bb stewards detach <key>` sets it back to
Backlog. It has no labels or priority, its children are local tickets, and a
pull request's body cites its key so the merge gate resolves the local spec's
approval. The owner's page comments and description edits form the spec; the
`bb stewards tickets list|show|file|comment|update|close|export` commands are
the by-hand surface.
- **Ops stewards.** Each namespace and Sentry project in a login's
`roles.json` `ops` entry gets an `ops` steward, reporting to the project
steward, for as long as it is listed. The plugin looks at the target with
Expand Down Expand Up @@ -1080,7 +1090,10 @@ copies drift. Sources serve `sourceSnapshot`, `sourceValidate`,
`sourceEnsureLabel` (the label create `check --create-labels` uses, optional
so a source without it is unavailable), `sourceAdoptable` and
`sourceSetInterest`; stewards serves `stewardsRing`, and `stewardsSession`
for linear's `@bb` mentions.
for linear's `@bb` mentions. The third source, `local`, is served by stewards
itself in-process (`sourceRpc("local", …)` never leaves the process), backed
by the `local_tickets` and `local_comments` tables; a local ticket is adopted
by state and a pull request cites its key.

## Develop

Expand Down
34 changes: 33 additions & 1 deletion plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ const boardSteward = (over: Record<string, unknown> = {}) => ({
...over,
});

const renderBoardWith = async (over: { subPath?: string; stewards?: unknown[]; questions?: unknown[]; withUser?: unknown[]; needs?: unknown[]; lessons?: unknown[]; lessonCounts?: unknown; digest?: unknown; ended?: unknown[]; stuck?: unknown[]; sidebarThreads?: { threads?: unknown[]; status?: "error" | "loading" | "ready" }; threadId?: string | null } = {}): Promise<RenderedSlot> => {
const renderBoardWith = async (over: { subPath?: string; stewards?: unknown[]; questions?: unknown[]; withUser?: unknown[]; needs?: unknown[]; lessons?: unknown[]; lessonCounts?: unknown; digest?: unknown; ended?: unknown[]; stuck?: unknown[]; sidebarThreads?: { threads?: unknown[]; status?: "error" | "loading" | "ready" }; threadId?: string | null; localTicket?: { ticket: Record<string, unknown>; comments?: unknown[] } } = {}): Promise<RenderedSlot> => {
const captured = await loadApp();
const panel = captured.navPanels[0]!;
return renderSlot(panel, { subPath: over.subPath ?? "" }, {
Expand All @@ -1054,6 +1054,11 @@ const renderBoardWith = async (over: { subPath?: string; stewards?: unknown[]; q
}),
stewardsAnswerQuestion: () => ({ ok: true, message: "closed" }),
stewardsNeedAction: () => ({ ok: true, message: "done", ...(over.threadId === undefined ? {} : { threadId: over.threadId }) }),
// BB-361: the local ticket detail view. Null for a non-local effort.
stewardsLocalTicket: () => ({ ticket: over.localTicket?.ticket ?? null, comments: over.localTicket?.comments ?? [] }),
stewardsLocalEditDescription: () => ({ ok: true, message: "Saved." }),
stewardsLocalComment: () => ({ ok: true, message: "Commented." }),
stewardsLocalSetState: () => ({ ok: true, message: "Done." }),
} as never,
...(over.sidebarThreads === undefined ? {} : { sidebarThreads: over.sidebarThreads }),
} as never);
Expand Down Expand Up @@ -1160,6 +1165,33 @@ describe("the Stewards page's project view and detail views (BB-85)", () => {
slot.lifecycle.unmount();
});

it("edits a local ticket's description and state, and comments as the owner (BB-361)", async () => {
const slot = await renderBoardWith({
subPath: "p1/LOCAL-1",
stewards: [boardSteward({ key: "LOCAL-1", title: "A local effort" })],
localTicket: {
ticket: { key: "LOCAL-1", title: "A local effort", description: "Old text.", state: "Backlog", parent: null, playbook: "local-tickets", createdAt: 1, updatedAt: 1 },
comments: [{ id: "c1", author: "Dana", owner: true, body: "**Spec:** owner words", createdAt: 2 }],
},
});
await waitFor(() => expect(slot.getByText("Local ticket")).toBeTruthy());
await waitFor(() => expect((slot.getByLabelText("Description of LOCAL-1") as HTMLTextAreaElement).value).toBe("Old text."));
const description = slot.getByLabelText("Description of LOCAL-1") as HTMLTextAreaElement;
fireEvent.change(description, { target: { value: "New text." } });
fireEvent.click(slot.getByRole("button", { name: "Save description" }));
await waitFor(() => expect(slot.inspection.rpcCalls).toContainEqual({ method: "stewardsLocalEditDescription", input: { key: "LOCAL-1", description: "New text." } }));
// The state control.
const stateControl = slot.container.querySelector("#local-state-LOCAL-1")!;
fireEvent.change(stateControl, { target: { value: "Ready" } });
await waitFor(() => expect(slot.inspection.rpcCalls).toContainEqual({ method: "stewardsLocalSetState", input: { key: "LOCAL-1", state: "Ready" } }));
// The owner's comment box, and the owner's earlier comment.
fireEvent.change(slot.getByLabelText("Comment on LOCAL-1"), { target: { value: "**Spec:** more" } });
fireEvent.click(slot.getByRole("button", { name: "Comment as the owner" }));
await waitFor(() => expect(slot.inspection.rpcCalls).toContainEqual({ method: "stewardsLocalComment", input: { key: "LOCAL-1", body: "**Spec:** more" } }));
expect(slot.getByText(/owner words/u)).toBeTruthy();
slot.lifecycle.unmount();
});

it("keeps the page-only controls on the detail's needs-you items: the secret form and the approve-spec note", async () => {
const slot = await renderBoardWith({
subPath: "p1/ENG-1",
Expand Down
88 changes: 88 additions & 0 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,7 @@ function EffortDetail({ board: b, effortKey, refetch }: { board: Board; effortKe
return (
<>
<EffortHeading board={b} effort={effort} />
<LocalTicketDetail effortKey={effortKey} />
<Section title="Needs you" count={effort.items.length}>
{effort.items.length === 0 ? (
<None>Nothing is waiting on you for this effort.</None>
Expand Down Expand Up @@ -1664,6 +1665,93 @@ function EffortDetail({ board: b, effortKey, refetch }: { board: Board; effortKe
);
}

/**
* BB-361: a local ticket's own controls on its detail view: the description
* editor (the spec hash covers the description, so the owner revises it before
* approving), the state control, and the owner's comment box -- the one path
* an owner-entered local comment counts as the user's own spec words.
*/
function LocalTicketDetail({ effortKey }: { effortKey: string }) {
const rpc = useRpc<typeof rpcContract>();
const { data, refetch } = usePolled(useCallback(() => rpc.call("stewardsLocalTicket", { key: effortKey }), [rpc, effortKey]));
const [description, setDescription] = useState<string | null>(null);
const [comment, setComment] = useState("");
const [busy, setBusy] = useState<"idle" | "saving" | { error: string }>("idle");
const ticket = data?.ticket ?? null;
useEffect(() => {
setDescription(ticket === null ? null : ticket.description);
}, [ticket?.key, ticket?.updatedAt]);
if (ticket === null) return null;
const run = (p: Promise<unknown>) => {
setBusy("saving");
p.then(
() => {
setBusy("idle");
refetch();
},
(e: unknown) => setBusy({ error: message(e) }),
);
};
const button = "w-fit rounded-md border border-input px-3 py-1 text-xs hover:bg-state-hover disabled:opacity-50";
return (
<Section title="Local ticket">
<div className="flex flex-col gap-2 rounded-lg border border-border p-3 text-xs">
<p className="text-muted-foreground">
{ticket.key} · playbook {ticket.playbook}
{ticket.parent === null ? "" : ` · parent ${ticket.parent}`}
</p>
<label className="text-muted-foreground" htmlFor={`local-state-${ticket.key}`}>State</label>
<select
id={`local-state-${ticket.key}`}
value={ticket.state}
disabled={busy === "saving"}
onChange={(e) => run(rpc.call("stewardsLocalSetState", { key: ticket.key, state: e.target.value }))}
className="w-fit rounded-md border border-input bg-transparent px-2 py-1"
>
{["Backlog", "Ready", "In Progress", "In Review", "Done", "Canceled"].map((s) => (
<option key={s} value={s}>{s}</option>
))}
</select>
<label className="text-muted-foreground" htmlFor={`local-description-${ticket.key}`}>Description</label>
<textarea
id={`local-description-${ticket.key}`}
value={description ?? ""}
onChange={(e) => setDescription(e.target.value)}
rows={6}
aria-label={`Description of ${ticket.key}`}
className="min-w-0 rounded-md border border-input bg-transparent px-2 py-1"
/>
<button type="button" className={button} disabled={busy === "saving" || description === null || description === ticket.description} onClick={() => run(rpc.call("stewardsLocalEditDescription", { key: ticket.key, description: description ?? "" }))}>
Save description
</button>
<label className="text-muted-foreground" htmlFor={`local-comment-${ticket.key}`}>Your comment</label>
<textarea
id={`local-comment-${ticket.key}`}
value={comment}
onChange={(e) => setComment(e.target.value)}
rows={2}
placeholder="Starts a spec comment with **Spec:**"
aria-label={`Comment on ${ticket.key}`}
className="min-w-0 rounded-md border border-input bg-transparent px-2 py-1"
/>
<button type="button" className={button} disabled={busy === "saving" || comment.trim() === ""} onClick={() => run(rpc.call("stewardsLocalComment", { key: ticket.key, body: comment.trim() }).then(() => setComment("")))}>
Comment as the owner
</button>
{typeof busy === "object" ? <span className="text-destructive">{busy.error}</span> : null}
{data !== null && data.comments.length > 0 ? (
<ul className="flex flex-col gap-1">
{data.comments.map((c) => (
<li key={c.id}>
<span className="text-muted-foreground">{c.owner ? "you" : c.author}:</span> {c.body}
</li>
))}
</ul>
) : null}
</div>
</Section>
);
}

/** The detail heading: the sidebar's two-line effort row one size up, with a crumb back. */
function EffortHeading({ board: b, effort }: { board: Board; effort: BoardEffort }) {
const navigate = useBbNavigate();
Expand Down
29 changes: 27 additions & 2 deletions plugins/stewards/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ export const DEFAULT_PLAYBOOKS: Record<BindingKind, string> = { ticket: "linear-
/** The ticket playbook a GitHub-tracked project carries; the default for a project with no Linear teams. */
export const DEFAULT_GITHUB_TICKET_PLAYBOOK = "github-issues";

/**
* BB-361: the built-in playbook a local ticket runs unless it names another,
* and the two names `ticket_file` accepts at filing. A local ticket stores the
* resolved playbook name in its `playbook` column and the snapshot's optional
* `playbook` field carries it.
*/
export const LOCAL_TICKETS_PLAYBOOK = "local-tickets";
export const LOCAL_PLAYBOOK_CHOICES: Record<string, string> = { ticket: LOCAL_TICKETS_PLAYBOOK, initiative: "initiative" };

/**
* BB-361: a local ticket's key prefix. It defaults to `LOCAL`; a project may
* override it with `localPrefix` in project.json, and a prefix equal to one of
* the project's Linear team keys is refused (the two key shapes would collide).
*/
export const DEFAULT_LOCAL_PREFIX = "LOCAL";
export const localPrefix = z.string().trim().regex(/^[A-Za-z][A-Za-z0-9]*$/u, "a prefix such as LOCAL").transform((s) => s.toUpperCase());

/** The label a GitHub issue carries to mean "todo", the phase a filed autoAdopt issue starts in (BB-234, BB-235). */
export const GITHUB_TODO_LABEL = "status:todo";

Expand Down Expand Up @@ -423,6 +440,12 @@ export const projectFileSchema = z
* for repos in the workspace that stewards should not manage.
*/
github: z.object({ exclude: z.array(z.string().trim().regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u, "a repo such as acme/web")).max(64).default([]) }).strict().default({ exclude: [] }),
/**
* BB-361: the local ticket source's key prefix. Optional; absent, `LOCAL`.
* A prefix equal to one of `linear.teams` is refused below, because the
* two key shapes would collide.
*/
localPrefix: localPrefix.optional(),
label: z.string().trim().min(1).max(100).default(DEFAULT_LABEL),
nightly: z
.object({
Expand Down Expand Up @@ -537,6 +560,8 @@ export const projectFileSchema = z
})
.strict()
.superRefine((file, ctx) => {
const prefix = file.localPrefix ?? DEFAULT_LOCAL_PREFIX;
if (file.linear.teams.some((t) => t.toUpperCase() === prefix.toUpperCase())) ctx.addIssue({ code: "custom", path: ["localPrefix"], message: `${prefix} is one of linear.teams, so a local key would collide with a Linear key; choose another prefix` });
const seen = new Set<string>();
file.ops.targets.forEach((t, i) => {
const key = t.kind === "k8s-namespace" ? `${t.kind}/${t.name}` : t.kind === "alertmanager" ? `${t.kind}/${t.namespace}` : t.kind === "dependabot" ? `${t.kind}/${t.repo.toLowerCase()}` : `${t.kind}/${t.org}/${t.project}`;
Expand Down Expand Up @@ -901,8 +926,8 @@ export const deploymentsFieldSchema = z
}
});

export const PLAYBOOK_SOURCES = ["linear", "github", "k8s", "sentry", "alertmanager"] as const;
const SOURCES_OF: Record<BindingKind, readonly (typeof PLAYBOOK_SOURCES)[number][]> = { ticket: ["linear", "github"], pr: ["github"], review: ["github"], ops: ["k8s", "github", "sentry", "alertmanager", "linear"] };
export const PLAYBOOK_SOURCES = ["linear", "github", "local", "k8s", "sentry", "alertmanager"] as const;
const SOURCES_OF: Record<BindingKind, readonly (typeof PLAYBOOK_SOURCES)[number][]> = { ticket: ["linear", "github", "local"], pr: ["github"], review: ["github"], ops: ["k8s", "github", "sentry", "alertmanager", "linear"] };

export const frontMatterSchema = z
.object({
Expand Down
Loading
Loading