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
16 changes: 16 additions & 0 deletions plugins/stewards/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ describe("playbooks", () => {
}
});

it("tells the default playbooks to get credentials through bb secret request and to escalate build-time blockers", () => {
const linear = parsePlaybook(LINEAR_TICKETS, "linear-tickets");
if (!linear.ok) throw new Error(linear.error);
expect(phaseInstructions(linear.value, "In Progress")).toMatch(/bb secret request/u);
expect(phaseInstructions(linear.value, "In Progress")).toMatch(/changes what the ticket needs/u);
expect(phaseInstructions(linear.value, "In Progress")).toMatch(/escalated as a `decision`/u);
expect(phaseInstructions(linear.value, "In Review")).toMatch(/escalated as a `decision`/u);
const prs = parsePlaybook(GITHUB_PRS, "github-prs");
if (!prs.ok) throw new Error(prs.error);
expect(phaseInstructions(prs.value, "draft")).toMatch(/escalated as a `decision`/u);
expect(phaseInstructions(prs.value, "open")).toMatch(/escalated as a `decision`/u);
const reviews = parsePlaybook(GITHUB_REVIEWS, "github-reviews");
if (!reviews.ok) throw new Error(reviews.error);
expect(phaseInstructions(reviews.value, "open")).toMatch(/escalated as a `decision`/u);
});

it("maps states to phases and stages, ignoring case, and splits sections", () => {
const parsed = parsePlaybook(LINEAR_TICKETS, "linear-tickets");
if (!parsed.ok) throw new Error(parsed.error);
Expand Down
20 changes: 19 additions & 1 deletion plugins/stewards/skills/stewards/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ Two tools are yours; everything else you do with the tools every thread has.
meanwhile } }`: it goes to your parent steward, then the project steward.
The answer comes back as guidance and wakes you. The user hears only about
the project's big decisions.
- **One ask per reply, and only what is open.** Ask the user at most one
thing, and only what the playbook, this skill or the project's guidance
leaves open. Models, flags, lanes and who merges are settled there: never
ask them. An escalation or approval request that is already open is on the
Stewards page: do not ask for it again, and a reply that does counts like a
missed report toward `stuck`.
- **A credential is a worker's, through `bb secret request`.** When the work
needs a secret, the worker obtains it with `bb secret request` (the
`secrets` skill): never paste one into a thread, and never route the user
to a script to run. You file the user-facing item for it — an escalation,
or a question as project steward — and the worker takes the value.
- **A build-time blocker is a `decision` the same turn.** A worker's finding
that would stop the feature working once it ships, or that changes what the
ticket needs (a credential, an access, a contract), is escalated as a
`decision` in the same turn, with the worker's words quoted — never
relayed as a follow-up.
- **`steward_update` saves the user's steering.** When the user tells you
something about how to handle the entity, save it as guidance; it rides on
every later wake. With a child steward, it also decides its escalations,
Expand Down Expand Up @@ -100,7 +116,9 @@ escalation, record it with `guidance` + `resolve`; if not, leave it open.
Everything you ask the user is a record. Forwarding an escalation to them
makes a question for it; anything else you ask in a reply, record first
with `steward_update { ask: { question, context } }` (with `binding` when
it concerns one). When they answer, close it with
it concerns one). Ask one thing per reply, and never ask what the playbook,
this skill or the project's guidance settles (models, flags, lanes, who
merges). When they answer, close it with
`steward_update { resolve: "<question id>", answer }`; for a forwarded one
that decides the escalation too, and resolving the escalation closes the
question. The user may also close a question on the Stewards page. Every
Expand Down
27 changes: 27 additions & 0 deletions plugins/stewards/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
// and reviewed like any other change to `.bb`.
import { DEFAULT_BIG_DECISIONS, DEFAULT_LABEL } from "./config.js";

/**
* A credential a worker needs, in the linear-tickets build section. The worker
* takes the value through the secrets skill; the steward files the item the
* user sees.
*/
const SECRET_REQUEST =
"A credential the work needs is the worker's to obtain with `bb secret request` (the `secrets` skill): put that in the task, never the secret, and never a script for the user to run. You file the user-facing item for it.";

/**
* A build-time blocker is a `decision` in the same turn, never a follow-up,
* in a playbook's build and review sections.
*/
const buildBlocker = (what: string) =>
`A worker's finding that would stop the feature working once it ships, or that changes what ${what} needs (a credential, an access, a contract), is escalated as a \`decision\` in the same turn, with the worker's words quoted; never relay it as a follow-up.`;

export function projectFileTemplate(teams: string[]): string {
return `${JSON.stringify(
{
Expand Down Expand Up @@ -89,11 +104,17 @@ repo, the branch, the acceptance criteria, and "open a draft pull request,
link it to the ticket, and stop when checks pass". When the pull requests are
ready, request review and move the ticket to In Review.

${SECRET_REQUEST}

${buildBlocker("the ticket")}

## In Review

Follow the linked pull requests. Start a worker to address change requests or
failing checks. When every linked pull request is merged, move the ticket to
Done.

${buildBlocker("the ticket")}
`;

export const GITHUB_PRS = `---
Expand Down Expand Up @@ -122,11 +143,15 @@ Get it ready: a worker fixes failing checks and finishes what the description
says is left. When checks pass, mark it ready (\`gh pr ready\`) and request
review.

${buildBlocker("the work")}

## open

Answer review comments with a worker, one round at a time, and re-request
review after each round. When it is approved and checks pass, merge it if the
project's guidance says its author may; otherwise say so in a comment.

${buildBlocker("the work")}
`;

export const GITHUB_REVIEWS = `---
Expand Down Expand Up @@ -165,6 +190,8 @@ further.

Run a round when one is due; otherwise there is nothing to do.

${buildBlocker("the work")}

## draft

The author took it back to draft. Do nothing until it is ready again.
Expand Down
61 changes: 60 additions & 1 deletion plugins/stewards/wake.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import Database from "better-sqlite3";
import { describe, expect, it } from "vitest";
import { parsePlaybook } from "./config.js";
import { issue } from "./fixtures.js";
import { gateState } from "./reconcile.js";
import { MIGRATIONS, createStore } from "./store.js";
import { formatProjectWake, type DigestRecords } from "./wake.js";
import { LINEAR_TICKETS } from "./templates.js";
import { formatProjectWake, formatWake, type DigestRecords, type WakeInput } from "./wake.js";

const T = Date.parse("2026-10-18T05:00:00Z");
const DAY = 86_400_000;
Expand All @@ -16,6 +20,61 @@ function world() {

const status = (summary: string) => ({ phase: "In Progress", summary, nextAction: "Open the PR", actor: "steward" as const, blockedOn: null, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: T });

function wakeInput(over: Partial<WakeInput> = {}): WakeInput {
const { s, bind } = world();
const binding = over.binding ?? bind("ENG-12");
const parsed = parsePlaybook(LINEAR_TICKETS, "linear-tickets");
if (!parsed.ok) throw new Error(parsed.error);
const playbook = parsed.value;
return {
reason: "changed",
binding,
playbook,
observed: { entity: issue(), pulls: [] },
gate: gateState(playbook, binding.ready, ""),
escalations: [],
routedToMe: [],
workers: [],
children: [],
workerFlags: "--provider claude-code --model claude-opus-5-5 --reasoning-level high",
changes: [],
own: new Set(),
label: "bb-managed",
now: T,
...over,
};
}

describe("a steward's wake", () => {
it("carries the standing rules: credentials through bb secret request, one ask, and build-time decisions", () => {
const wake = formatWake(wakeInput());
expect(wake).toContain("bb secret request");
expect(wake).toContain("the `secrets` skill");
expect(wake).toContain("never paste a secret");
expect(wake).toContain("One ask per reply");
expect(wake).toContain("escalated as a `decision` in the same turn");
});

it("names the worker and reviewer models as flags that are not the steward's to choose", () => {
const wake = formatWake(wakeInput());
expect(wake).toContain("--provider claude-code --model claude-opus-5-5 --reasoning-level high");
expect(wake).toContain("your workers' and reviewers' models");
expect(wake).toContain("not yours to choose");
});

it("lists an open escalation and approval request as on the Stewards page, not to be asked again", () => {
const { s, bind } = world();
const binding = bind("ENG-12");
const decision = s.escalate({ bindingId: binding.id, kind: "decision", question: "Include SSO?", meanwhile: "Wait.", route: "me", recommendation: null });
const approval = s.escalate({ bindingId: binding.id, kind: "approval", question: "Approve the spec?", meanwhile: "Waiting.", route: "me", recommendation: null });
const wake = formatWake(wakeInput({ binding, escalations: [decision, approval] }));
const note = "These are listed for the user on the Stewards page. Do not ask for them in your reply.";
// Once under the open escalations, once with the approval request in the gate.
expect(wake.split(note)).toHaveLength(3);
expect(wake).toContain("counts like a missed report toward `stuck`");
});
});

describe("the nightly prompt", () => {
it("is assembled from the records: previous digest with its date, open questions, what moved, waiting on you, stuck", () => {
const { s, bind } = world();
Expand Down
27 changes: 25 additions & 2 deletions plugins/stewards/wake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ import type { Binding, Escalation, Observed, Question, Worker } from "./store.js

/** A wake longer than this is cut in its snapshot, never in what changed or what to do. */
export const WAKE_MAX_CHARS = 30_000;

/**
* What a steward must never ask for: an open escalation or approval request is
* already on the user's Stewards page, and repeating it in a reply is noise.
*/
const OPEN_REQUESTS_NOTE = "These are listed for the user on the Stewards page. Do not ask for them in your reply.";

/**
* The rules that hold on every wake, whatever the playbook: the generic things
* a steward got wrong without them. They mirror the `stewards` skill and the
* default playbooks, so a change here belongs there too.
*/
const STANDING_RULES = [
"- **One ask per reply.** Ask the user at most one thing, and only what the playbook, the project's guidance or the `stewards` skill leaves open. Anything they settle — models, flags, lanes, who merges — is never asked.",
"- **A credential the work needs is a worker's to fetch**, with `bb secret request` (the `secrets` skill): never paste a secret, and never route the user to a script to run. You file the user-facing item for it, and the worker takes the value.",
"- **A finding that would stop the feature working once it ships**, or that changes what the ticket needs (a credential, an access, a contract), is escalated as a `decision` in the same turn, quoting the worker's words — never relayed as a follow-up.",
];
const DESCRIPTION_CHARS = 4000;
const COMMENT_CHARS = 1500;
const RESULT_CHARS = 1500;
Expand Down Expand Up @@ -147,8 +164,8 @@ function gateLines(input: WakeInput): string[] {
? ` It is asked for automatically once the checklist is met; do not escalate for it.`
: ""
: request.route === "me"
? ` Requested from the user (${request.id}): they approve in this thread, and you record it with steward_update { approve: true, quote }.`
: ` Requested from the project steward (${request.id}): wait for it; do not escalate for it.`;
? ` Requested from the user (${request.id}): they approve in this thread, and you record it with steward_update { approve: true, quote }. ${OPEN_REQUESTS_NOTE}`
: ` Requested from the project steward (${request.id}): wait for it; do not escalate for it. ${OPEN_REQUESTS_NOTE}`;
if (!gate.approvalNeeded) lines.push("- Approval: not needed");
else if (!gate.approved) lines.push(`- Approval: not given (given by ${how})${binding.ready.voidedAt === null ? "" : `; the last one was voided ${iso(binding.ready.voidedAt)}`}.${asked}`);
else lines.push(`- Approval: given ${iso(binding.ready.approval!.at)}${gate.approvalStale ? ` — the spec has changed since, so the gate needs it again.${asked}` : ""}`);
Expand Down Expand Up @@ -187,6 +204,11 @@ export function formatWake(input: WakeInput): string {
" EOF",
"",
"Follow it up with `bb thread tell <id> <message>`. You are woken when a worker finishes, with its final message.",
"Those `--provider`/`--model`/`--reasoning-level` flags are your workers' and reviewers' models, from the playbook or the project. They are not yours to choose: never ask the user for a model.",
"",
"**Standing rules.**",
"",
...STANDING_RULES,
);

out.push("", "## 2. Ready gate", "", ...gateLines(input));
Expand Down Expand Up @@ -223,6 +245,7 @@ export function formatWake(input: WakeInput): string {
out.push(`- ${x.id} from ${from.entityKey} (${x.kind}) — routed to you: ${x.question} Meanwhile: ${x.meanwhile}${x.recommendation === null ? "" : ` Recommendation: ${x.recommendation}`}`);
out.push(" Decide it with steward_update { binding, guidance, resolve }, or pass it up with steward_update { binding, forward, recommendation }.");
}
out.push("", OPEN_REQUESTS_NOTE, "Asking for one that is already open counts like a missed report toward `stuck`.");
}

const snapshot = out.splice(0);
Expand Down
Loading