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
63 changes: 53 additions & 10 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,43 @@ A **lesson** makes the answer a record and, for most of them, lands it.
Only the owner's own words, or this project's steward or worker threads,
may create, cite or correct a lesson; a signed or non-owner comment never
does.
- **Tiers and transitions (BB-35 step 3).** Every lesson carries a `tier`:
`candidate` (store only, never in a wake) → `trial` (in the store, injected
into steward and project steward wakes under `## Lessons (trial)` with its
id) → `promoted` (committed to `.bb` with a `<!-- lesson:<id> -->` anchor) →
`retired` (removed from the file; the row kept). The old `status` column is
kept and still tracks the file state (`pending`, `merged`, `dropped`); the
migration maps `pending` → `trial`, `merged` → `promoted`, `dropped` →
`retired`, once and idempotently. The nightly pass (and every sweep) applies
the thresholds under `lessons` in `project.json`, with the design's defaults
when the key is absent: trial → promoted at 3 distinct-binding hits, 0
corrections and ≥ 14 days in trial; trial → retired at 30 days uncited or
any correction; promoted → retired at 90 days uncited or 2 corrections; any
lesson → retired when a newer one in the same file supersedes it. A
citation's weight halves every `decayHalfLifeDays`, so the lowest-scoring
promoted lesson is the one displaced when a file is at `promoted.maxPerFile`.
A lesson is `trial` from the moment the project steward records it; the
nightly pass is what moves it. The thresholds and caps are the whole
mechanism — no model judges a tier. The project steward may still
`complete` a trial by hand, which promotes it at once and bypasses
`promoted.maxPerFile`; that is an explicit override, and the nightly pass is
the mechanical path, not the only one.
- **The promotion and retirement write only the lesson's own anchored text.**
A promotion the nightly pass queues is listed under `## Lessons to land`;
the project steward adds the block (`<!-- lesson:<id> -->` and the wording)
to the named file, commits, publishes with `workspace_publish_guidance`, and
completes it. A retirement is listed under `## Lessons to retire`; the
project steward replaces the block with `<!-- lesson:<id> retired -->` and
publishes, then `steward_update { lessonAction: { action: "retire" } }`
fast-forwards the canonical checkout. The same multi-repo guard applies both
ways: only the lesson's own file may change, and it must carry the anchor the
call names. A lesson's `file` may never be `stewards/project.json`, so a
lesson can never move a big decision to the project, loosen the
pull-request gate or relax an approval; the decide list, `bigDecisions` and
`prGate` are outside a lesson's reach by construction. A boundary-scope
lesson still becomes a Merge/Drop item for the user. `retireLessonAnchor`
in `lessons.ts` is the normative definition of the retirement edit; the
project steward makes it by hand and the helper is what the tests pin.
- **Procedure lessons self-merge.** Playbook procedure, sequencing and
conventions are what the project steward may already decide. It applies
the text to the file in its `.bb` checkout, commits, and publishes with
Expand Down Expand Up @@ -1314,24 +1351,30 @@ A **lesson** makes the answer a record and, for most of them, lands it.
and the revert below cover.
- **Status is observed, not assumed.** Every sweep and nightly pass reads
each pending lesson's file at `.bb` HEAD and marks it `merged` when the
normalised text is there, however it got there. `dropped` is set by the
user's Drop button, the project steward's `drop` action, or
anchored text is there, however it got there; a retired lesson is skipped so
an observation never resurrects it. `dropped` is set by the user's Drop
button, the project steward's `drop` action, a retirement, or
`bb stewards drop-lesson <id>`.
- **The nightly prompt and the digest.** The project steward's nightly wake
lists the pending lessons and asks it to apply, commit, publish and
complete them, with the last refusal reason where one was refused. The
digest lists the lessons that landed in the window with their sha, file
and source binding/escalation, and names the branch.
lists the trial lessons to decide from, the promoted ones queued to land and
the retired ones to remove, with the last refusal reason where one was
refused. The digest carries nothing about lessons: the merged-lessons
section is gone, and `bb stewards lessons --all` is where their state is
read.
- **Surfaces.** Pending lessons are on the Stewards page's Lessons section
and in `bb stewards list`; `bb stewards lessons [--all]` lists them,
`bb stewards drop-lesson <id>` drops one.
- **Undo.** A merged procedure lesson is an ordinary commit on `.bb` HEAD;
`bb stewards lessons --all` names its `mergeSha` and branch. To undo it,
revert that commit in the canonical checkout (`git revert <sha>` in the
project's `.bb`, then push) or edit the wording out and let the next pass
see it gone; the lesson row stays `merged` until it is dropped, which only
closes the record, not the file. A boundary lesson is undone the same way
once the user has merged it.
project's `.bb`, then push), or let the nightly pass retire it once it is
uncited for `promoted.retireDays` and remove the anchored block through
`## Lessons to retire`. The row is kept with `tier: retired` either way. A
boundary lesson is undone the same way once the user has merged it. A
lesson recorded by an image before this step gets the column default
`candidate`, and the remap has already run at its own index, so after a
roll-forward it is invisible to wakes; `bb stewards lessons --all` still
shows it, and re-recording it as a fresh trial is the way back.

## 21. The sidebar thread list

Expand Down
39 changes: 23 additions & 16 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,29 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
or the approval code is always yours.
- **Lessons** are a project steward's general judgements, made permanent in
`.bb` instead of being lost with the ticket that raised them. It records
one with `steward_update { lesson: { text, file, scope } }`; a `procedure`
lesson it applies, commits and publishes, then self-merges with
`steward_update { lessonAction: { id, action: "complete" } }` (multi-repo
fast-forwards the canonical `.bb`, and only that lesson's file). A
`boundary` lesson — credentials and reach, who may direct a server,
irreversible production steps — is filed on the Stewards page with
**Merge** and **Drop**, and only you merge it. A lesson is `merged` when
its text is found in its file at `.bb` HEAD. A user's answer to a forwarded
escalation on the Stewards page (or from a thread) wakes the project
steward with that answer as a lesson candidate: if it is a general
judgement the playbook should carry, the project steward records it as a
lesson. A resolve carries `cites: [lesson ids]` — the lessons it rested on
— and the plugin counts `hits` (once per distinct binding), `corrections`
and `lastCitedAt`. Counts only for now: nothing is promoted, retired or
written to `.bb` from them yet. `bb stewards lessons [--all]`
lists them, `bb stewards drop-lesson <id>` drops one. DESIGN.md §20.
one with `steward_update { lesson: { text, file, scope } }`. A lesson
moves through tiers: `candidate` → `trial` → `promoted` → `retired`. A
recorded lesson starts `trial`; the nightly pass promotes it when it is
cited on 3 distinct bindings with no corrections and has been in trial 14
days, and retires it at 30 days uncited or on any correction (a promoted
one at 90 days uncited or 2 corrections). The thresholds, caps and decay
half-life are under `lessons` in `stewards/project.json`; the design's
defaults apply when the key is absent. Trial lessons are injected into
wakes under `## Lessons (trial)`; only promoted ones reach `.bb`, with a
`<!-- lesson:<id> -->` anchor, and only that lesson's own file (multi-repo
fast-forwards the canonical `.bb`). A `boundary` lesson — credentials and
reach, who may direct a server, irreversible production steps — is filed on
the Stewards page with **Merge** and **Drop**, and only you merge it; a
lesson can never target `stewards/project.json`, so it cannot move a big
decision to the project, loosen the pull-request gate or relax an approval.
A user's answer to a forwarded escalation on the Stewards page (or from a
thread) wakes the project steward with that answer as a lesson candidate: if
it is a general judgement the playbook should carry, the project steward
records it as a lesson. A resolve carries `cites: [lesson ids]` — the
lessons it rested on — and the plugin counts `hits` (once per distinct
binding), `corrections` and `lastCitedAt`. `bb stewards lessons [--all]`
lists tiers and counts, `bb stewards drop-lesson <id>` drops one. The
digest carries nothing about lessons. DESIGN.md §20.
- **The nightly pass** (01:00 in the project's time zone by default, done by
02:45 so bb-gate's 03:00 restarts do not cut a turn) gives every open
binding a turn, then wakes the project steward for the morning digest.
Expand Down
13 changes: 13 additions & 0 deletions plugins/stewards/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ describe("the project file", () => {
if (!badDuration.ok) expect(badDuration.error).toMatch(/deps\.sla\.high/u);
});

it("fills the lesson lifecycle's defaults, and takes explicit thresholds (BB-35 step 3)", () => {
const defaults = parseProjectFile(JSON.stringify({ version: 1 }));
if (!defaults.ok) throw new Error(defaults.error);
expect(defaults.value.lessons).toEqual({ trial: { max: 5, retireDays: 30 }, promote: { hits: 3, days: 14 }, promoted: { maxPerFile: 10, retireDays: 90, corrections: 2 }, decayHalfLifeDays: 30 });

const explicit = parseProjectFile(JSON.stringify({ version: 1, lessons: { trial: { max: 2 }, promote: { hits: 5, days: 7 }, decayHalfLifeDays: 14 } }));
if (!explicit.ok) throw new Error(explicit.error);
expect(explicit.value.lessons).toEqual({ trial: { max: 2, retireDays: 30 }, promote: { hits: 5, days: 7 }, promoted: { maxPerFile: 10, retireDays: 90, corrections: 2 }, decayHalfLifeDays: 14 });

expect(parseProjectFile(JSON.stringify({ version: 1, lessons: { promote: { hits: 0 } } }))).toMatchObject({ ok: false });
expect(parseProjectFile(JSON.stringify({ version: 1, lessons: { unknown: true } }))).toMatchObject({ ok: false });
});

it("takes the standing-rules list, and rejects an unknown key (BB-54)", () => {
const defaults = parseProjectFile(JSON.stringify({ version: 1 }));
if (!defaults.ok) throw new Error(defaults.error);
Expand Down
48 changes: 48 additions & 0 deletions plugins/stewards/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,52 @@ export const depsSchema = z
.default({ sla: { critical: "asap", high: 86_400_000, medium: 7 * 86_400_000, low: 30 * 86_400_000 }, batch: { medium: 7 * 86_400_000, low: 30 * 86_400_000 }, autoAdopt: ["critical", "high"] });
export type DepsConfig = z.infer<typeof depsSchema>;

/**
* The mechanical lesson lifecycle's rules (BB-35 step 3): when a trial lesson
* is promoted or retired, how many a wake may carry, and how many promoted
* lessons a file holds. The defaults are the design's; a project overrides
* any part under `lessons` and the rest fall back. `decayHalfLifeDays`
* weights a citation by age, so an old burst of use does not keep a lesson
* alive when the lowest-scoring one has to be displaced.
*/
export const lessonRulesSchema = z
.object({
trial: z
.object({
/** At most this many trial lessons in one wake. */
max: z.number().int().min(1).max(50).default(5),
/** A trial lesson uncited this long is retired. */
retireDays: z.number().positive().max(3650).default(30),
})
.strict()
.default({ max: 5, retireDays: 30 }),
promote: z
.object({
/** Distinct bindings a trial lesson must be cited on to be promoted. */
hits: z.number().int().min(1).max(50).default(3),
/** Days a trial lesson must have been in trial before it may be promoted. */
days: z.number().positive().max(3650).default(14),
})
.strict()
.default({ hits: 3, days: 14 }),
promoted: z
.object({
/** At most this many promoted lessons in one file; a promotion into a full file displaces the lowest-scoring one. */
maxPerFile: z.number().int().min(1).max(100).default(10),
/** A promoted lesson uncited this long is retired. */
retireDays: z.number().positive().max(3650).default(90),
/** Corrections that retire a promoted lesson. */
corrections: z.number().int().min(1).max(50).default(2),
})
.strict()
.default({ maxPerFile: 10, retireDays: 90, corrections: 2 }),
/** A citation's weight halves every this many days. */
decayHalfLifeDays: z.number().positive().max(3650).default(30),
})
.strict()
.default({ trial: { max: 5, retireDays: 30 }, promote: { hits: 3, days: 14 }, promoted: { maxPerFile: 10, retireDays: 90, corrections: 2 }, decayHalfLifeDays: 30 });
export type LessonRules = z.infer<typeof lessonRulesSchema>;

export const projectFileSchema = z
.object({
version: z.literal(1),
Expand Down Expand Up @@ -283,6 +329,8 @@ export const projectFileSchema = z
.default({ targets: [], autoAdopt: [], sentry: { resolveOnDone: false } }),
/** The dependency watch: per-severity SLA, the batch window, and what auto-adopts. */
deps: depsSchema,
/** The mechanical lesson lifecycle's thresholds and caps (BB-35 step 3). */
lessons: lessonRulesSchema,
})
.strict()
.superRefine((file, ctx) => {
Expand Down
Loading
Loading