Skip to content
Back to skills

Scan Sweep

ASecurity

Long-running quality sweep that walks a repository context by context, reads each area's code once, judges it through every scan lens, and lands what it can PROVE itself with atomic commits. With no arguments it runs the STABILIZE loop - bug hunting, UI perfection, performance - picking the least-covered context each round and keeping a per-context lens-coverage ledger so a codebase gets swept evenly instead of repeatedly in the same corner. Every finding climbs an evidence ladder (gate > pro...

  • 2 stars
  • 0 votes
  • 0 copies
  • 8 views
  • Added October 19, 2026
testingrustgoshellsqlnodeexpressgitapidevopssecurity

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned November 21, 2026

npx -y skills add xkazm04/ai-registry --skill scan-sweep --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Scan Sweep?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Scan Sweep
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xkazm04-scan-sweep/badge)](https://www.skillsdirectory.com/skills/xkazm04-scan-sweep)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: scan-sweep
description: "Long-running quality sweep that walks a repository context by context, reads each area's code once, judges it through every scan lens, and lands what it can PROVE itself with atomic commits. With no arguments it runs the STABILIZE loop - bug hunting, UI perfection, performance - picking the least-covered context each round and keeping a per-context lens-coverage ledger so a codebase gets swept evenly instead of repeatedly in the same corner. Every finding climbs an evidence ladder (gate > probe > experiment > simulation) before it is routed: a measured `better` with no escalation builds in-session, S or M, under any strategy; `not-better` is rejected with its figures; what a probe could not measure - a walked simulation, a named-but-unbuilt instrument, an out-of-scope seam, an M or L too large to land unread - goes to Lane B, an A/B wave of Sonnet workers in worktrees that build both arms, measure with the same instrument, seed the control red, and let the director merge `better` and throw `not-better`; only a direction, an XL, an irreversible change, a loosened policy, or an operator-only act still waits for a human. Use for a standing quality loop, a hardening milestone, or a backlog. Pass --develop for new capability, --optimize for deep hardening, --challenge for a proving ground (two critic-graded hard candidates per context), --ideas-only to change no code, --coverage for the pick list, --backlogs for what earlier passes left open, --handoff to file them into Personas Approvals (each run ends there)."
argument-hint: "[--stabilize|--develop|--optimize|--challenge] [--cohort N] [--riders N] [--until-covered] [--go] [--one <context>] [--depth N] [--ideas-only] [--lenses k1,k2] [--coverage] [--backlogs] [--ab] [--ab-only] [--workers N] [--handoff]"
category: workflow
contexts: tracked
memory: project
version: 4.13.0
tags: sweep, quality, stabilization, backlog, coverage, registry, atomic-commits
---
# Context Sweep

A **long-running sweep** that owns a repository's quality loop. It walks the
context map one area at a time, reads each area's code once, judges what it read
through every relevant lens, and lands the safe fixes itself.

The expensive part of any scan is reading the code. Do it once per context, then
judge. Depth beats breadth *within* a context; breadth comes from the loop
returning to the next-least-covered area, not from skimming.

## Invocation

```
/scan-sweep                     # the LOOP: stabilize, least-covered context first, until stopped
/scan-sweep --one <context>     # exactly one context, then stop
/scan-sweep --coverage          # the pick list; scan nothing
/scan-sweep --ideas-only        # scan and propose; change no code
/scan-sweep --backlogs          # list the open backlogs earlier passes left behind; scan nothing
/scan-sweep --challenge [--cohort N] [--go]
                                # proving ground: 2 hard candidates per context, critic, deck, build waves, scorecard
/scan-sweep --ab                # after the round's Lane A commits, dispatch Lane B (§5, references/ab-lane.md)
/scan-sweep --ab-only           # no scan: drain the existing backlog's Lane B items through the wave
/scan-sweep --workers N         # cap on concurrent Lane B workers (default 4)
/scan-sweep --handoff           # no scan: file every open backlog into Personas Approvals (§9.1), then delete it
```

**Default = the stabilize loop.** No arguments means: pick the least lens-covered
context, sweep it, land what is safe, record coverage, then pick the next one and
say so - round after round until the operator stops the session or every context
has been swept. Each round is self-contained: its commits are landed and its
snapshot is written before the next context is chosen, so an interrupted loop
loses nothing but the round in flight.

**Announce each round's boundary out loud**: `── Round <n>: <context> (lens
coverage <a>/<total>, last swept <age>) ──`. A loop whose rounds are not visible
reads as one runaway session.

**Headless runs (`claude -p`) set `CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS=0`.** Print
mode stops every background subagent 10 minutes after the session's last turn, so
a director that dispatched round-agents and ended its turn loses them mid-round
(personas 2026-10-30: four round-agents killed, no findings recorded). `0` waits
indefinitely. The ceiling is the backstop, not the rule: a headless director
**never ends a turn while a subagent it dispatched is still running** - it
dispatches in the foreground or waits for every completion before its final
message (§7, Director-run fan-out).

**Existing backlog is spoken first (§0), including `--coverage`.** A run that
starts a new scan while a previous wave still has unbuilt auto items has
forgotten its own queue.

## Strategies - pick at most one

- **`--stabilize` (DEFAULT)** - make what exists *solid*. Deep tier: bounty-hunter,
  parity-auditor, error-handler, observability-auditor, risk-assessor,
  code-optimizer, ux-reviewer, visual-craft, state-coverage, copy-auditor,
  accessibility-checker, test-strategist, security-auditor. Aim ~80% of the
  finding budget at defects, broken or unpolished UI states, and measured
  performance problems. Feature ideas and architecture proposals are recorded as
  findings only - never built under this strategy.

  **Five of those thirteen were added because the eight before them kept missing
  whole classes** (measured over two full rounds on one repo, 2026-09-04):
  `parity-auditor` because one rule with two implementations, only one fixed, was
  five of the ten defects found and no other lens is looking for it;
  `observability-auditor` because a swallowed error and a missing audit row are
  invisible to every lens that reads for correctness; and `visual-craft`,
  `state-coverage`, `copy-auditor` because this strategy's own blurb promises
  "broken or unpolished UI states" while `ux-reviewer` alone owns flow, leaving
  how a surface LOOKS, which states it can enter, and what it SAYS unassigned -
  and copy that asserts a removed behaviour ships to a human who then acts on it.
- **`--develop`** - NEW capability. Deep tier: feature-scout, innovation-catalyst,
  ux-reviewer, onboarding-designer, integration-planner, business-strategist,
  growth-hacker, monetization-advisor. ~70% of the budget at forward-building
  items. Quality lenses still run as a light pass - a real defect is never
  ignored, but marginal cleanups are dropped.

  **"New" is not a reason to write `unmeasurable`.** A capability that lives
  inside what the context already declares it does is COVERAGE, and its figure
  is a behaviour test the sweep writes first: Before = `0 of N cases pass`,
  After = `N of N`, Method = `gate`. Sized S or M, it builds (§5). What stays
  human under this strategy is a **direction** - a capability the context's
  declared scope does not name - and anything **L**. Under v2.x every
  forward-building item was `unmeasurable` on arrival and the strategy had no
  auto-build path at all; `references/evidence.md` carries the recipe per lens.
- **`--optimize`** - QUALITY of what exists, deeper than stabilize goes: adds
  tech-debt-tracker, dependency-auditor, devops-optimizer, documentation-auditor,
  mobile-specialist, observability-auditor. ~70% of the budget at hardening, debt
  and coverage.

  **Every hardening claim has a count.** Debt is duplicated sites; a dependency
  is an audit line, a version delta and a green gate; a pipeline is a duration or
  a step count; a doc is a stated rule checked against the code it describes; a
  mobile issue is a reproduced viewport. "Cleaner" or "more maintainable" with
  no figure is `not-better` (pure churn), never `unmeasurable` - the
  `unmeasurable` drawer is where this strategy's whole output went under v2.x.

- **`--challenge`** - the PROVING GROUND. High effort, high impact, moderate to
  high risk, built rather than parked. For the moment a new model (or a new
  builder setup) arrives and the question is whether it can do the hard half of
  the job: see the structural move a context needs, argue it from the tree, and
  land a multi-file risky change without breaking anything. It inverts the other
  three strategies' tuning on purpose, so it runs on its own procedure - see
  **§ Challenge mode** below and `references/challenge.md`. Lenses:
  `architecture-challenger` and `ux-elevation`, exactly **two candidates per
  context** (one per slot), M or L only.

Name the strategy in the report header and record it in the snapshot's `strategy`
field.

## Challenge mode - `--challenge`

A challenge run replaces §1, §4.4-§4.8, §5's escalation table and §7's one-at-a-
time queue with the procedure below. Everything else binds unchanged: §0 speaks the
open backlogs first, §2's never-re-propose lists apply, §4.10's card form and
`file:line` anchors apply, §7.2's asserted gates and §7's staging rules apply, and
§10 writes a per-context snapshot. The long form is `references/challenge.md`;
read it before the first scout goes out.

1. **Cohort, not a context.** `node ${CLAUDE_SKILL_DIR}/scripts/coverage.mjs
   --challenge [--cohort N] [--riders N]` picks N contexts (default 6): >= 10
   files, never challenged first, at most one per group, larger first, each
   carrying up to 3 small same-group **riders** the scout reads and records (a
   group with no large context left promotes its small ones). `--one` /
   `--group` override. `--until-covered` loops cohorts until none is left
   unchallenged, pipelining the next run's scouts behind this run's builds
   (references/challenge.md §2.1-2.2). Print the cohort and the reason for each pick.
2. **Scout - two cards per context.** One read-only subagent per context (or the
   coordinator, sequentially, when there are none) reads the context once, the
   governing registry subject (§6), and the open backlogs, then returns exactly two
   cards: slot A `architecture-challenger`, slot B `ux-elevation` (a second
   architecture card on a different seam when the context has no user surface).
   Floors: size M/L, effort >= 5, impact >= 7, risk 4-8, a declared `write_set`,
   and 3-8 `acceptance` cases a builder can write as failing tests first. A card
   under a floor is re-homed to the ordinary backlog and the slot re-scouted once.
   Every scout writes its cards to the run directory BEFORE replying.
3. **Critic - an independent reader.** A separate subagent gets the cards and the
   tree, never the scout's reasoning: re-verifies every premise, checks floors and
   never-re-propose, grades ambition / grounding / falsifiability 1-5, and returns
   `build` / `revise` / `void`. The mean is the run's `idea_score`.
4. **Deck - one human decision.** The deck approval IS the human gate for
   `architecture` and in-scope `direction` - that is what this mode exists to
   exercise. `irreversible`, `policy-loosen`, cross-repo contracts and out-of-scope
   directions are **never built** under this mode, whatever the approval says.
   Attended: ask once. `--go`, or an invocation that explicitly asks for execution,
   is the approval in advance - the report says which. Unattended without either:
   stop at the deck and register it as an open backlog (§9).
5. **Build in waves.** Waves of <= `waveSize` (default 4) builders with disjoint
   write sets; a signature change runs alone and first. Each builder: re-verify the
   premise -> write the acceptance tests and watch them fail -> build -> tests and
   the overlay's gates green by asserted exit code -> commit a short series. In a
   shared checkout: `git commit -- <paths>` only, and the shared-surface `mkdir`
   lock for locale catalogs, generated references and ratchet files. Past the
   write set or past L -> revert and return `demoted`.
6. **Integrate after every wave.** Full gate on the combined tree before the next
   wave starts. Red: one fix-forward, then `git revert` the offending series.
7. **Score the run.** One row in `.claude/scan-history/challenge-runs.jsonl`:
   models per role, cards, premise-false, void, approved, excluded, landed,
   **flawless** (landed + cases red-before/green-after + gates green at hand-off +
   no integration fix + not reverted), demoted, reverted, integration failures,
   idea score, tokens and wall-clock as reported (null, never estimated). Close the
   report with `execution_score = flawless / approved`, `idea_score`, and the delta
   against the previous challenge row.

Challenge lenses carry `Group: challenge` in `references/lenses.md`; they run only
under this strategy and are excluded from the stabilize coverage denominator, so a
challenge run can never make a context read as swept.

## 0. Open backlogs - tell the operator FIRST

**Before the round header, before scoping, before any code is read: say what
earlier passes left unworked.** A sweep is run weeks apart. An ideas-only wave, a
`--develop` pass, or a round that hit the outbox cap leaves findings that exist
nowhere but a file, and the operator who starts the next sweep has forgotten
them. Scanning for MORE findings on top of an unworked backlog is the most
expensive way to be reminded of it. (Measured 2026-09-17: one ideas-only wave
produced 1,040 findings, 30 reached the outbox, 1,010 were "held" in a scratch
directory, and the only record that they existed was a line in a report.)

Look in every one of these, and report what each holds - `none` is an answer:

1. **The open-backlog register** (overlay key `openBacklogs`, default
   `.claude/scan-history/open-backlogs.jsonl`) - every row whose `status` is
   `open`. This is the durable pointer; §9 says when a pass must write it.
2. **The outbox** (overlay key `memoryOutbox`) - if the file exists and still
   carries `"type":"finding"` lines, the last pass was never ingested. Count them.
3. **The backlog digest** (overlay key `backlogDigest`) - the `pending` count:
   findings a consumer ingested and nobody has decided.
4. **Sweep history** - rows with `mode: "ideas"` or a `note` naming held or
   unrecorded findings, newer than the last `mode: "resolve"` row for the same
   scope.
5. **Stray findings files** - `**/scan-sweep-*/all-findings.jsonl` and
   `**/scan-sweep-*/findings/*.jsonl` under the repo's scratch locations
   (`scratchpad/`, `.claude/scan-sweep/`, the overlay's own paths). A file found
   here with no register row gets one written now, `status: open`.

Then print the notice as the FIRST thing the operator reads, one line per backlog:

```
OPEN BACKLOG  <strategy> wave of <date> (<age>) - <open> of <total> findings unworked
              <path> - <built> built, <declined> declined, <descoped> descoped
              tiers: <undisputed n> ready to build, <n> need a contract/policy review, <n> need a direction call
```

and say what can be done with it: **work it down** (route it through §5 exactly as
a fresh round would: Lane A items build in-session, Lane B items drain through
the wave with `--ab-only`, Lane C - `direction` / `architecture` /
`irreversible` / `policy-loosen` / operator-only - stays for the operator),
**hand it to Approvals** (`--handoff`, §9.1: the cards go to Personas
Approvals → Backlog, the files are deleted, the row is closed), **keep sweeping
anyway**, or **close it** (the operator says the rest is not wanted; set the row `closed` with
the reason). When the operator is present, ask which. When the run is
unattended, do not block: repeat the notice at the top of every round report
and carry on with the loop.

Rules that keep the notice honest:

- **Count from the file, not from the row.** Re-read the findings file and the
  result files beside it; a register row is a pointer, and its numbers go stale
  the moment anyone builds from the backlog.
- **A missing path is reported, not skipped.** `OPEN BACKLOG ... file is gone`
  tells the operator the findings were lost; silently dropping the row tells
  them nothing was ever owed.
- **Never re-propose what an open backlog already holds.** Its titles join §2's
  never-re-propose lists for this run, exactly like the digest's.
- **A backlog older than 14 days is not carried again.** Offer the operator:
  hand it to Approvals, or delete it. A file nobody reopened in two weeks is a
  file nobody will; carrying it forward only lengthens the notice.
- **A row whose note says the hand-off was owed** (Personas was not running when
  §9.1 ran) is retried before anything else, without asking.
- `--backlogs` prints this notice and stops. `--coverage` prints it above the
  table.

## 1. Scope the round

- `--one <context>` names the context. Otherwise **pick it**: read the context map
  and the sweep history, and choose, in this order - the first context in map
  order with NO snapshot at all; else the smallest `lens_keys` union (fewest
  lenses ever applied); tie → oldest latest snapshot. `scripts/coverage.mjs
  --next` computes exactly this and is the cheapest way to ask.
  **Independent of the running app.** If the map's `provenance.git_commit` is behind `HEAD`, refresh it first with
  `node <registry>/scripts/personas-door.mjs contexts refresh` (deterministic, git-only: follows renames, drops gone files, attaches
  new files by directory, no LLM). It flags the contexts whose churn crossed their calibrated threshold; re-judge ONLY those
  (`contexts plan` -> read -> `contexts apply --file patch.json --tokens-est <n>`), which feeds the rescan-yield ledger that
  decides next time whether a rescan was worth it. `contexts sync` hands the map to the app when it is up (spooled when not).
  `<registry>` = `.ai/manifest.yaml` `registry.local`, else `$AI_REGISTRY_DIR`, else `../ai-registry`. Without a Personas DB the
  commands degrade to the map file alone; nothing here may block the run.
  **An operator-approved context-map card is a hand edit, not a rescan.** When the operator accepted a card that
  corrects the map (a retired feature's paths, a missing file, a wrong owner), the director - or the worker it
  dispatched - edits `context-map.json` for EXACTLY the approved entries and nothing else, validates it (the repo's
  context-map test where one exists, else `node -e "JSON.parse(require('fs').readFileSync('context-map.json','utf8'))"`
  plus a check that every path it names exists), commits it, then runs `personas-door contexts sync` so the app's
  copy matches the file (spooled when the app is down). A card's own text saying "an operator rescan is the only
  fix" is overruled by the operator's accept: write map cards as "edit these entries, then `contexts sync`", never
  as "rescan". (personas c2r2, 2026-10-31: three approved map cards said a rescan was the only fix; the worker
  edited the three entries by hand, and the app's copy was never synced.)

- State the choice and why in the round header ("never swept" / "lens coverage
  4/28, oldest 2026-08-11" - the denominator is `coverage.mjs`'s, derived from
  `references/lenses.md`). Coverage rotation must be auditable.
- **Size the context before you size the package.** Count its files and lines
  first. Under roughly **10 files or 200 LOC**, a full package is recording, not
  scanning: either **sweep it together with its siblings** in the same group as
  one round (preferred - it gives the lenses a real surface), or run the
  **matched tier only** and say so in the header. §4.8's yield floor assumes ten
  files or more, and §1's picker used to have no matching rule. Measured: 28
  lenses walked over a 38-line route shell.
- Stay inside the context's declared file paths for the whole round.

## 2. Load shared awareness - BEFORE reading code

- **Decision memory** - what the human decided, WITH the reason. When the
  Personas door is reachable, `node ${CLAUDE_SKILL_DIR}/scripts/door.mjs decisions
  --repo <root> --context <context> --limit 50` returns the context's recorded
  decisions newest first (`verdict`, `reason`, `decidedBy`, `decidedAt`, `lens`);
  add `--lens <id>` to narrow while judging one lens. This is what every
  finding's `predicted_verdict` leans on (§4.12): titles alone are not memory. On
  `reachable: false` (exit 3: app down, or an app that predates the endpoint) or
  exit 4 (repo not registered), fall back to the digest below and say so in the
  round header: `memory: digest only (<reason>)`. **Run `node scripts/personas-door.mjs
  contexts sync` (the registry's door CLI, or the app's own context sync) before the
  first decisions read of a run** - a context the app's map does not hold widens the
  read to the whole project. The reply then carries `widened: true` and
  `note: "scope: project (context <x> unknown to the app) ..."` (and says so on
  stderr); a widened read is NOT this context's memory - print
  `memory: project-wide (context <x> unknown to the app)` in the header and quote
  only decisions whose `contextId` or lens actually match. **Pass the context's
  NAME, not its context-map.json id** - the app mints its own ids (personas c3,
  2026-10-31: 549e67d5 in the app, 5d538a29 in the map); `door.mjs` matches the
  name case- and punctuation-folded, or the app's id. **A known context with zero
  decisions widens too**: ideas filed before the app knew the context carry
  `context_id: null`, so the script re-reads project + lens and answers
  `widened: true`, `note: "scope: project+lens (context <x> has 0 decisions ...)"`
  (personas c3: every context read returned 0, unflagged, while the project held
  29). Every reply carries `project_total`; print it in the header beside the
  scoped count (`memory: 0 in context, widened to 7 by lens, 29 project-wide`).
- **Backlog memory** (overlay key `backlogDigest`, default
  `.personas/backlog-digest.json`) - pending / accepted / rejected titles.
  **Never re-propose anything on those lists, including rephrasings of rejected
  titles.** A rejected title is a durable human "no". The decisions read above
  joins this list; a rejected decision's `reason` says what kind of rephrasing it
  also rules out. **When the digest is absent too** (door unreachable AND no file at
  the digest path), the never-re-propose list is what is local: the open-backlog
  register's findings files (§0), this context's reserve file, and the sweep
  history. Say `memory: none (door <reason>; no digest at <path>)` in the header,
  write every `predicted_why` as `no precedent (door unreachable, digest absent)`,
  and do not block - the ladder already runs at start levels (§5).
- **Trust** - `node ${CLAUDE_SKILL_DIR}/scripts/door.mjs trust --repo <root> >
  <run dir>/trust.json` returns the project's per-slice autonomy levels and their
  transition events. Keep the file even when it says `reachable: false`; §5's
  ladder routing reads it through `rank.mjs --trust`. Print the slices whose level
  changed since the last round in the header (`trust: technical|error-handler|-|S
  L2 -> L3 (agreement 0.95, n 20)`), or `trust: door unreachable - category start
  levels, autoDecide asked at most at L1`.
- **Reserve from the last round on this context** -
  `.claude/scan-sweep/reserve/<context>.jsonl`, the previous round's
  `band: reserve` findings as `rank.mjs` wrote them (§4.4). They are
  re-verified first (a premise that no longer holds is dropped and said so) and
  compete for this round's slots beside its new findings; the file is replaced
  by this round's reserve. A re-filed reserve item is a dedup hit in Approvals,
  not a new card.
- **Hard gates** (`.claude/conventions.json` when present) - a finding that
  violates a declared gate is a defect you are about to introduce, not a finding.
- **Sweep history** (`.claude/scan-history/scan-sweep.jsonl`) - prior snapshots,
  for the trend line and the lens-ordering rule.
- **The registry**, when this repo consumes one - see §6. The registry is
  KNOWLEDGE THAT FEEDS THE LENSES, not a lens of its own and not the sweep's
  primary instrument: each lens reads the governing subject's techniques that
  touch its concern and judges against them (§3). The one place where
  "registry deviation" is itself the finding is the `registry-conformance`
  lens, which runs like any other lens and is budgeted like any other lens.

## 3. Pick the lens package

- `--lenses k1,k2` uses exactly those keys.
- Otherwise the package is **ALL lenses in `references/lenses.md`** except the
  `Group: challenge` pair, which only `--challenge` runs, ordered:
  the active strategy's deep tier first, then lenses whose `Match` regex hits the
  context's name, description, keywords, stack or paths, then the rest as a
  lighter pass. Most of the tail will honestly report "nothing real" - but a
  clean verdict earns coverage only when the lens was **pointed at something**
  (§4.9); a lens with no surface in this context is recorded as having none, and
  counts for nothing.
- Within each tier, never-applied lenses (absent from prior `lens_keys`) go
  first. The package's job is to close lens coverage, not re-walk it.
- List the deep / matched / remaining keys in the round header.
- **Lenses are the instrument; the registry is what sharpens them.** A scan is
  a set of prompts applied to the code - `error-handler` asks about error
  doors, `code-optimizer` about render and query cost - and when the repo
  consumes a registry (§6), each lens FIRST reads the techniques in the
  governing subject that touch its concern, then judges the code against them
  and names the technique in the finding. A lens whose concern has no
  governing knowledge judges on the repo's own conventions and says so in the
  finding. The `registry-conformance` lens is the ONLY lens whose findings are
  the deviations themselves - the pure registry→backlog transformation - and
  every other lens leaves those to it rather than restating them.

## 4. Survey, then judge

1. Read the context's files and collect evidence FIRST - form no verdicts while
   still reading.
2. Run any cheap deterministic check that applies (type-checker, linter, existing
   script) and reconcile. Deterministic findings belong to those tools - do not
   restate them as findings.
3. Walk the lens package **sequentially**. **No lens and no tier has a cap on
   what it may report**: write down every verified finding, each grounded in
   `file:line`, and let §4.4's slot allocation decide what is ranked. (The old
   per-tier caps - deep ≤3, matched ≤2, rest ≤1 - let a 13-lens deep tier emit
   39 into a 16-item budget, so the tail lenses found things the round had no
   room to write.) Zero from one lens is a valid result - say "nothing real" and
   move on. Zero from a whole TIER is a claim about the codebase, and §4.9 is
   where you test it.

   **`file:line` means `<path>:<line>`, the path relative to the REPOSITORY
   root, exactly as `git ls-files` prints it.** A basename is not an anchor and
   an anchor that does not resolve is not evidence - in a multi-package tree
   `limiter.ts:41` is ambiguous where `src/api/limiter.ts:41` is not. This binds
   every anchor in the round: findings, evidence blocks, commit bodies, report.

4. **FIND GENEROUSLY, BUILD CONSERVATIVELY. These are different budgets and
   confusing them is the failure this clause exists to prevent.**

   How much work a round does is decided by the ROUTING RULES in §5 - S builds,
   M clears a ratio, L never builds - and not by how many findings exist. So the
   finding budget is not a work budget: raising it raises the BACKLOG, which is
   the artefact the operator triages, and leaves the build volume where §5 put
   it. A sweep that finds five things in a 24-file context has not been
   disciplined; it has been incurious, and it has left the operator a backlog
   that under-describes their own repository.

   **Ranked slots: N = 16 per context per round** (`--one`: 24, because a named
   context is a deliberate deep dive; `--depth N` or the overlay's `depth`
   overrides). **Lifetime cap per context: 40 RANKED findings** - subtract the
   `ranked` counts of prior snapshots; reserve findings do not count against it.
   N for this round is the smaller of the two. Never re-emit a finding already
   reported or present in the backlog digest.

   **Slot allocation - the contract's, in this order** (`## Finding contract`,
   "Coverage"): (1) every lens with ≥ 1 verified finding gets ONE ranked slot,
   its **MVP** - the lens's top `score`, unless the reader overrides it with
   `mvp_rule: override` and a `mvp_why`; (2) the remaining N minus MVPs slots go
   by `score` across lenses, unscored findings after every scored one; (3) every
   other verified finding is **`band: reserve`**. An MVP is never reserved: with
   more productive lenses than slots the ranked band exceeds N and the report
   says by how many. Run it, never do it by hand:

   ```
   node ${CLAUDE_SKILL_DIR}/scripts/rank.mjs --file <run dir>/findings.jsonl --cap <N> \
     --trust <run dir>/trust.json [--start technical=<n>,product=<n>] [--frozen <p1,p2>] [--strict] \
     --out <run dir>/ranked.jsonl [--tokens <lens=n,...>] [--skipped <lens,...>]
   ```

   It computes every `score` with `scripts/score.mjs`, sets `band`, `mvp`,
   `mvp_rule`, annotates the ladder fields §5 routes by, and prints the per-lens
   table §8 reports. **Reserve is filed, not dropped**: it is handed off with
   the rest (§9.1, `band: reserve`), written to
   `.claude/scan-sweep/reserve/<context>.jsonl`, and seeds the next round of this
   context (§2). Reserve findings are not built this round - they are owed to
   the next one.

   **Nothing is built before `rank.mjs` has run.** Judging finishes, `findings.jsonl`
   is ranked, and only then does §7 start - on the lines of `ranked.jsonl` that say
   `band: ranked` (and `lane_a_ok: true` for Lane A). A fix built while still
   judging cannot know its band. Measured 2026-10-30 (personas): one round-agent
   built three items before ranking, all three landed in the reserve band, and
   the director had to revert them (§9.1 files them as `disposition: reverted`).
   A round-agent's reply names its `ranked.jsonl`; a commit for an item that file
   does not rank is reverted at integration.

   **Where this meets §4.11's measured Before: an INSTRUMENT may come before rank,
   the FIX may not.** A test, probe, counter or fixture that takes the Before (or
   decides `better` / `not-better`) is measurement, and judging needs it: write it
   and run it while judging, under a scratch path (`<run dir>/instruments/`, or an
   uncommitted file the round names in its reply), and commit it only once the
   item is ranked - as the item's own `test(<context>): <instrument>` commit
   (§7.3) or not at all. The change the instrument measures waits for
   `ranked.jsonl`. personas c3 (2026-10-31): three round-agents wrote uncommitted
   instruments before ranking and each had to say so, because neither section did.

   **THE ALLOCATION MUST BE ABLE TO HEAR THE PACKAGE YOU RAN.** Under the old
   tier caps a 22-lens package against a 5-item budget was exhausted by lens
   three, and the other nineteen had nowhere to put anything - they became
   coverage RECORDING, the ledger read 22/22, and the round reported a clean
   tail it never had room to hear. Measured 2026-08-27: a 5-item budget over a
   full package yielded **0.098 findings per lens-pass** against the same
   repository's **1.63** under a 6-lens package a fortnight earlier - 17× less,
   from 3.6× more lenses. The MVP slot is the fix: a lens that found something
   is always heard, and the reserve band keeps what the cap would have thrown.
5. **Score both sides of every candidate.** *Reward* = user-visible or
   developer-measurable gain (impact 1-10). *Risk* = chance of breaking working
   code, plus churn - lines rewritten per unit of gain (1-10): the risk of MAKING
   the change, never the severity of the defect. These two numbers drive every
   routing decision in §5, so guessing them is guessing the routing; §4.12 is
   how they, and every other contract field, are assigned.
   Two hard rules learned from calibration:
   - **"Unused/dead" claims require proof.** A finding that says dead/unused MUST
     cite its zero-consumer grep in the evidence. Verified dead-code removal is
     the best reward/risk class there is; guessed dead-code removal is the worst.
     It routes one way (§5, Lane A, "Dead-code deletion").
   - **Repo-declared incremental migrations** (string extraction, token adoption
     - whatever the repo calls fix-as-you-touch) are in scope for the nearest
     lens in files you already read, never as a bulk migration, and never where a
     deterministic gate already tracks them.
6. **Hunt for pairs, not for defect shapes.** On any codebase already swept a few
   times, pattern greps yield near zero. What still hits is **two
   implementations of one rule that must agree, where only one was fixed** -
   client vs server validation, a gate vs its debit, an abstraction vs its
   un-migrated call sites, a doc's stated rule vs the code. Grep for the *shared
   symbol* and diff its call sites. The signal to abandon a grep battery is the
   *second* clean result, not the fifth.
7. **Interrogate every hand-maintained list.** Coverage lists, allow-lists,
   enumerations of tables or routes - ask *what enumerates the ground truth, and
   is the test derived from that or from the list?* A test that reads the
   implementation's own list is coverage theater, and this class produces the
   highest-impact findings a sweep can find.

8. **BEFORE you declare the round, check the yield.** A full package over a
   context of ten files or more should produce roughly **10-16** findings. Fewer
   than **8 is a signal about YOUR PASS, not about the codebase** - the usual
   cause is that you read the deep tier and let the tail report "nothing real"
   without ever pointing it at anything. Under 8, do one more pass before
   declaring: open the two largest files you only skimmed, and drive the three
   never-applied lenses at something specific rather than at the context in
   general.

   A genuinely clean round is possible and must stay reportable - but it is a
   CLAIM, so state what you did to earn it: which files you read in full, which
   hypotheses you traced and why each failed. "Nothing found" and "nothing
   looked for" produce identical reports otherwise, and only one of them is a
   result. Measured 2026-08-27: eight of thirteen rounds returned two findings
   or fewer, none hit the budget, and re-running one of them under this clause
   found the yield had been the method's, not the repository's.

9. **A clean lens is only credible once the tier around it has spoken.** If an
   entire tier reports nothing, name the three things in it you actually
   checked. The tail's job is coverage AND a lighter hunt - it is not a list of
   keys to write into the ledger.

   **So the coverage ledger records only lenses that were POINTED AT A NAMED
   ARTEFACT** - a file read, a grep run, a hypothesis traced. Each recorded lens
   says *what it checked*: `error-handler - the 3 await sites in queue.ts, all
   guarded`. A bare "clean" is not a record. A lens with no surface in this
   context (`mobile-specialist` on a CLI crate) goes to `lens_no_surface[]`
   with its one-line reason and **earns no coverage credit** - it is not a pass,
   it is an absence. Measured 2026-09-16: ~31 judge verdicts read a 28-lens
   "all clean" list as rubber-stamped, which is the padding §4.9 already
   forbids in prose and the ledger was still accepting as a key.

   **Record what each lens checked as data, when the lens finishes** - one line
   per lens to `<run dir>/coverage.jsonl`:
   `{"lens":"<key>","context":"<context>","findings":<n>,"checked":["<file, grep or hypothesis>", ...]}`,
   or `{"lens":"<key>","context":"<context>","no_surface":"<reason>"}`. §9's
   coverage nodes and §10's `lens_keys` / `lens_no_surface` are rendered from this
   file, not recalled from prose at the end: a lens with an empty `checked` list
   earns no credit. (personas 2026-10-30: the coverage bodies fell back to finding
   titles or a generic line because nothing structured existed to render from.)

10. **EVERY finding is written in the standard form - no exceptions, no prose
    dumps.** The operator decides from the deck at a glance and a cheaper model
    (Sonnet, Haiku) executes from the text alone, so a finding that is vague
    where another is precise is a finding that will be mis-decided or
    mis-built. The `body` of a finding is markdown with exactly these `## `
    sections, in this order, each present even when short:

    ```markdown
    ## Summary
    One or two sentences: what is wrong (or missing) and where. No reasoning.

    ## Description
    What the code does today, why that is a defect or a gap, and what "fixed"
    looks like. Name the technique/golden path it violates when one applies.
    `file:line` for every claim.

    ## Flow
    - the steps that reproduce or expose it, as bullets - user action -> code
      path -> observed result
    - for a proposal: the steps the fix takes, in build order

    ## Expected impact
    Who notices, what changes for them, and how it would be measured. One
    sentence on what could break.

    ## Evaluation
    Claim: quality | performance | resilience | user | other - <what the idea
      promises, one clause>
    Before: <the measurement today - a number, a count, a reproduced
      behaviour, or the sample you looked at>
    After: <the same measurement under the proposed change - from a gate run,
      a probe on a small sample, a harness, or three walked cases>
    Method: gate | test-only | probe | experiment | simulation - <what you actually did to
      get the two figures, and why the rung above was not reachable>
    Result: better | not-better | unmeasurable
    Gate: none | contract | policy-tighten | policy-loosen | irreversible |
      architecture | direction
    ```

    **The Evaluation is the routing step (§5), written down - and it is a
    MEASUREMENT, not an opinion.** "Net positive" was the previous form, and it
    let a plausible story pass for evidence: measured on this operator's deck
    (2026-08-28), 44 of 64 human-gated ideas were `uncertain` because nobody
    had checked the claim, and the executors then found premises false at the
    point of build. So: pick the benefit the idea actually promises, take the
    figure BEFORE (count the sites, time the path, reproduce the failure, read
    the sample), take the same figure AFTER by the highest rung of the ladder
    you can reach (§4.11), and write both down. `better` means the After
    figure is better on the claimed dimension without a worse figure on
    another you can see. `not-better` is a finding you are REJECTING with its
    numbers attached. `unmeasurable` is reserved for what genuinely has no
    figure - a matter of taste, a product bet - and may only be written AFTER
    the ladder was climbed and the card says which rung failed and why. It is
    the only result that goes to a human for the benefit question itself. Pure
    churn measures the same before and after and is therefore `not-better`.

11. **Climb the evidence ladder before writing `unmeasurable`.** The rungs, top
    down: **`gate`** - a test or repo gate that goes red-then-green on the
    change, or a gate's exit code on both sides; **`probe`** - the change
    applied to a small sample and the same figure taken on both sides (three
    call sites, one timed path, one reproduced flow); **`experiment`** - the
    same inputs run twice through a harness that ships nothing (a script over
    a store copy, a replayed session, a dry run of a hook); **`simulation`** -
    three concrete cases from this tree or its history walked under A and B,
    with what would falsify the prediction. Take the highest rung reachable in
    the round and say in the Method line why the one above was not. **When
    the only thing between a claim and its figure is an S-sized instrument** -
    a test file, a counter, a timing wrapper, a fixture - **build the
    instrument as its own S fix first, then measure.** A sweep that writes
    `unmeasurable` where a twenty-line test would have decided it has skipped
    its own method. `references/evidence.md` carries the rungs, the reachable
    conditions and the per-strategy recipes.

    **When the fix IS a test** (a parity, guard or pin test that passes on the
    base tree, because nothing has drifted YET), "red first" cannot mean red on
    A. The red is the **seeded control**: drift the subject the test guards
    (drop a field from the list, rename the symbol, add the forbidden import)
    and re-run the test - it must go red on its assertion. Write it as
    `Method: test-only`, `Before: drift not caught` (no test exists, the seeded
    drift passes every gate), `After: drift caught` (the new test goes red on
    the seeded drift, green on the real tree), and record the drift as
    `control_seed`. `filing.mjs` refuses a `test-only` proof claiming `better`
    without `control: red`, and `proofFromAb` writes `red` for test-only only
    when `control_seed` names the drift (personas c3, 2026-10-31: a
    PERSONA_NULLABLE_FIELDS parity test was green on base; its only red was the
    seeded control).

    `evidence` is SEPARATE from `body` and is the proof, as a code block or a
    `file:line` list - the exact lines, the grep output, the count - never a
    restatement of the Description. `title` is the Summary compressed to one
    line (≤ 80 chars, imperative for a fix, noun phrase for a defect).

    The renderer (`TriageCardBody`) splits on these headings and paints each as
    its own block; a body without them paints as one undifferentiated block
    and reads as the lower-quality item it is. Do not invent extra sections;
    put anything else under Description.

12. **Assign the scan-finding/1 fields while judging - every verified finding,
    built or not.** The finding line (§9) carries the contract's fields
    (`## Finding contract`) beside the §4.10 body; an unknown value is OMITTED,
    never `0` and never `""`. Write each finding to `<run dir>/findings.jsonl`
    as you judge it - appended the moment it is verified, never batched for the
    end or held for the final reply; §4.4 ranks that file. A round killed
    mid-package then leaves every judgement it made on disk.

    | Field | How the reader assigns it |
    | --- | --- |
    | `lens` | the lens that found it - always its own field, never folded into `skill` or a source. |
    | `category` | the lens's `Category` line in `references/lenses.md`; a technical lens's finding may be moved to `product`, a product lens's finding is never `technical` (a ux-reviewer crash stays `product`; `rank.mjs` / `filing.mjs` clamp it and report `clamped`). `filing.mjs` falls back to the lens line, never to a blind `technical`. |
    | `impact`, `impact_why` | §4.5's reward 1-10, and the one-line reason for the number (≤ 200 chars). |
    | `confidence` | the contract's evidence rule, applied to THIS tree: `high` = the quoted evidence re-read now AND reproduced or measured (a `gate` / `probe` / `experiment` figure); `medium` = the quoted evidence re-read now, nothing reproduced (`simulation`); `low` = inference - a line you did not re-read, a pattern you did not trace. |
    | `effort` | 1-10 build effort. When you only know the size, leave `effort` out and keep `size`: `score.mjs`'s `sizeToEffort` maps XS 1, S 2, M 4, L 7, XL 10. |
    | `risk` | §4.5's 1-10 risk of making the change; a low / medium / high blast radius is 2 / 5 / 8. |
    | `score`, `score_parts` | **never written by the reader.** `rank.mjs` (and `approvals.mjs` for a card that lacks one) compute them with `scripts/score.mjs`; a score typed in prose is overwritten. A finding without `impact` or effort/size is unscored and ranks last. |
    | `band`, `mvp`, `mvp_rule` | set by `rank.mjs` (§4.4). The reader only ever writes `mvp_rule: "override"` + `mvp_why` (≤ 200 chars) to name a lens's MVP that is not its top score - the root cause behind a higher-scored symptom, say. |
    | `predicted_verdict`, `predicted_why`, `predicted_by` | the reader's own verdict on the item - `accept` / `reject` / `defer` - recorded BEFORE any human sees it. `predicted_why` (≤ 300 chars) **quotes the closest precedent's reason** from §2's decisions read when one exists (`like i9, rejected: "already guarded upstream"`), and says `no precedent` when none does. `predicted_by` = `scan-sweep@<version>:<model id>`. Every handed-off finding carries all three. |
    | `subject_key` | the ONE thing the fix edits, so sibling rounds can see a collision: `symbol:<name>` (a function, constant, type), `test:<repo path>` (a new or edited test file), else `file:<repo path>`. `rank.mjs --siblings` drops a finding a sibling round already holds by this key (§7, "Cross-round"). Omitted when no single subject exists. |
    | `note` | a run-level remark the card must carry but that is not the finding (`gate unrunnable on host: test:rust - <reason>`). It is filed into `reasoning`, never the title or the body's head: the door's near-duplicate check reads title + description, and one line prepended to many bodies pulls unrelated cards together (§9.1). |
    | `proof` | only when a change was BUILT for it (a Lane B return, a Lane A attempt that was handed off): `{metric, method, unit, before, after, verdict: better\|not-better\|inconclusive, control: red\|absent, base_sha, head_sha}` - §5 Lane B and `references/ab-lane.md` say how it is filled. |

## 5. Routing - three lanes, evidence decides, four escalations stay human

Every finding leaves §4 with a size, an Evaluation (Before / After / Method /
Result / Gate) and two scores. §5 turns that into exactly one of three lanes:

| Lane | Who decides | What it holds |
| --- | --- | --- |
| **A - build now** | the measurement already taken | `better` at `gate` or `probe`, no escalation, XS/S, or M with risk ≤ 3, inside this round's paths. Built in-session, one commit each, seeded control on every instrument. |
| **B - A/B, then build or throw** | the same instrument on both arms, in isolation | everything claimable that A could not measure or should not land unread: `simulation`-only, `unmeasurable`-with-a-named-instrument, M with risk ≥ 4, L, out-of-scope seams, in-tree contracts without a verifier, carries that still lack their instrument. Dispatched to Sonnet workers (overlay `ab.workerModel` may pin another) in worktrees, in parallel; the director merges `better`, rejects `not-better` with figures, escalates the rest. `references/ab-lane.md` is the contract. |
| **C - human** | the operator, from the deck | the four escalations — `direction`, `architecture`, `irreversible`, `policy-loosen` — plus XL, contracts with consumers outside the tree, and anything Lane B returned `unmeasurable` after a real attempt. |

`not-better` is not a lane. It is a rejection, with both figures, and it leaves the
backlog. The three lanes are checked **in the order C, then A, then B**: escalations
first because a score may never overturn one; A second because what is already
measured needs no wave; B takes what is left.

The history of this section is four routing rules on one operator's deck.
Reward/risk asked "how dangerous is the edit?"; net delta asked "does it sound
better?" and passed 85 of 149 on stories; measured evaluation (v2.5) could say NO
but sent every `unmeasurable` and every contract to a human; v3.0 built what a
probe had measured and handed the rest over. Measured on gravitone 2026-09-06:
twelve backlog cards, **all five S-sized ones `Method: simulation`** — walked
cases with the instrument named and unbuilt. None was risky. Each was backlogged
because the round could not take the figure, and v3.0 had no lane whose job was
to go and take it. That lane is B (v4.0), and it is the same move `intake` made
in its Phase 7.5/7.7: the run builds both arms and reads the verdict off the
project's own gate, and the human sees only what no instrument can decide.

### Size

Classify every candidate for the build bound:

- **XS** - one line, one mechanism, no new file: a guard, a clamp, an attribute.
- **S** - localized: one file, one mechanism, plus its test.
- **M** - a few files or one subsystem seam; a normal PR.
- **L** - structural within one context: a new module, a migrated seam, an
  instrument that did not exist.
- **XL** - architecture-grade work spanning contexts or modules: new layers,
  protocol redesigns, cross-cutting migrations, an edit to the context map itself.

Size bounds the build and picks the lane's ceiling; it does not decide who
approves. XS and S may go to A; M may go to A or B; L goes to B; XL goes to C.

### Lane C - the escalations (checked first)

An escalation applies when the implementation REQUIRES it, not when the finding
mentions it. Design and feature are not escalations: a feature inside scope with a
passing test is coverage.

- **direction** - a capability the context's declared scope does not name: the
  manifest's `scope` block when the repo carries one, else the context map entry's
  description and keywords. A one-line change that creates a capability the scope
  does not name is a direction; a two-hundred-line build inside the declared
  purpose is coverage.
- **architecture** - every **XL**, and any change that alters what the product IS:
  a new layer, a protocol redesign, a cross-cutting migration, the context map.
  **Not** "a file outside my paths" — that is `out-of-scope`, and it is Lane B.
- **irreversible** - deletes user data, rewrites stored history, a migration with no
  rollback, or changes what is paid for.
- **policy-loosen** - removes or weakens a security, privacy or audit check, widens
  access, or stores or sends MORE than before. Its mirror, **`policy-tighten`**, is
  Lane A when a test pins the new behaviour: a reviewer would only ever say yes and
  the test is the review.
- **contract with consumers outside this tree** - another repository's, a public
  SDK's, a wire format with readers elsewhere. Letter (a) of the contract rule
  cannot be done, so nobody in the run can verify it.
- **an operator-only act** - an ingest, a scan, a `pip freeze` on a machine this
  session is not on. Named so the card says whose hands it needs, not "human" in
  the abstract.
- **`unmeasurable` after a Lane B attempt** - a worker built what it could and
  still has no figure. The card carries the instrument it could not build and why.

The gate column is an ESCALATION list, not a danger list. Important things that are
verifiable are exactly what a sweep is for.

### Lane A - build now (checked second)

An item is Lane A when **all** of:

- `Result: better` and `Method: gate` or `probe` — a figure was actually taken, on
  the real tree or a real sample, on both sides;
- `Gate: none`, or `policy-tighten` with a test, or `contract` with its verifier
  green and letters (a)–(d) met;
- size XS or S; or M with **risk ≤ 3**;
- every file it touches is inside this round's declared paths (or the round is a
  coordinator wave, where that veto does not bind);
- a gate exists that can see it, or one can be built at S — and if one is built,
  it is built **first**, seeded red, then the fix lands green (§4.11, §7.6);
- its slice is at **level ≥ 2** on the autonomy ladder (`lane_a_ok` from
  `rank.mjs`, below) - and it is in the **ranked** band.

**Dead-code deletion has ONE route: Lane A on a repo-wide grep probe.** Deleting
code has no honest fail-first test (nothing to assert on code that is gone), so
the instrument is the reference count: `Method: probe`, Before = the repo-wide
grep of the symbol (all files, not the context's paths; name the command), After
= **`grep: 0 hits after`** outside the deleted lines, plus the typecheck/build
gate green (the compiler is the second consumer probe). The seeded control is
restoring the deletion's export/barrel line and watching the grep (or the
typecheck) find it again. Size and risk rules apply as for any Lane A item. Why
this and not Lane B: the figure is seconds of grep the director can take and
re-read, and a worker adds nothing a re-run would not show; why not a test: one
written only to fail on the old symbol cannot fail any other way (personas cycle
2's unmeasurable verdict). When a grep cannot see every consumer - string-built
imports, reflection, a name registered in config or another repository - it is
not this route: it is a `contract` (Lane C if the readers are outside the tree).
The two personas cycle-2 agents routed it two ways; this is the one.

Lane A is executed in-session, one atomic commit per item, highest-reward first,
under §7. A Lane A item the round cannot build (budget, time, a tree that will not
take a commit) is emitted `disposition: carry` and is Lane A **first** next round —
unless it is carried for the same missing instrument twice, in which case it is B.

### Lane B - A/B, then build or throw (takes what remains)

An item is Lane B when it is neither C nor A and its Result is `better` or
`unmeasurable`. In practice that is one of:

| Trigger | Why it is B and not A |
| --- | --- |
| `Method: simulation` | three walked cases predict; nothing measured. B builds the instrument, then measures. |
| `unmeasurable` with a named S/M instrument | the round said what would decide it and lacked the budget to build it |
| `better` by probe, M with risk ≥ 4, or L | real on a sample; the whole change needs its own isolated gate run before landing |
| `out-of-scope` (the old veto 1) | the seam is in a context this round did not own; a worker that owns it can build it |
| in-tree `contract` without a verifier | letters (a)–(d) are the worker's checklist |
| `carry` lacking its instrument for the second time | approved twice and unbuilt twice is a wave item, not a third carry |

Lane B is dispatched after the round's Lane A commits have landed, one Sonnet worker (or the overlay's `ab.workerModel`)
per write-set group, in isolated worktrees, in parallel, capped by `--workers`. The
worker re-measures A, builds the instrument if the card names one, builds B within
the stated size, takes the same figure on B, runs every gate with its status
asserted, **seeds the control red**, and commits with a pathspec on its branch. The
director reviews each return against the diff, merges `better` `--no-ff`, deletes
`not-better` with both figures in the ledger, escalates `unmeasurable` to C, counts
`fp` and `demoted` against the mechanism, closes `superseded` (a card a sibling's
merge in the same group made moot) as `already_delivered` without counting it,
sends a void control (the reverted tree failed to import or compile the new
symbol) back to re-seed, and never pushes. **Every verdict ends in an outcome
post**: `node <skill>/scripts/door.mjs outcome <idea-id> --outcome
delivered|declined|already_delivered|blocked [--commit <sha>] [--figures <json>]
[--choice <json>]` (spooled when the app is down, replayed by `personas-door sync`;
`outcomeFor` in `scripts/filing.mjs` maps the verdict). A product choice an
approved Lane C card left open is the director's to make and to record:
`choice: {picked, rejected, why}` on the ab row, a `Scan-Choice:` trailer on the
merge commit, and `--choice` on the outcome post. The whole contract —
worker steps, director rules, ledger shape, prompt template — is
`references/ab-lane.md`; this section only says who goes there.

**Every Lane B verdict writes the contract's `proof`** onto the item's card, beside
its `ab.jsonl` row: `metric`, `method`, `unit`, `before` / `after` as re-measured,
`verdict` (`better`, `not-better`, or `inconclusive` for an `unmeasurable`),
`control: red` when the seeded control went red and `absent` otherwise, `base_sha`
(arm A) and `head_sha` (the worker's commit). `filing.mjs`'s `proofFromAb` maps a
worker return to it; an `fp` or `demoted` built nothing and carries no proof.
Whatever of that item is handed off (§9.1) - an `unmeasurable` escalated to C, a
`better` whose branch was kept for a red or unrunnable gate - carries the proof, so
Personas' verify state shows what was measured instead of a blank.

### The autonomy ladder - how far the machine may go on this item

The lanes say what kind of evidence an item has; the ladder says how much of the
decision the machine may take on it. Levels belong to **slices**
(`<category>|<lens>|<risk_class>|<size>`, an absent part `-`; scan-sweep has no
`risk_class`, so its slices read `technical|error-handler|-|S`) and live in
Personas, which computes them from its own decision history - see
`## Finding contract`, "Autonomy ladder". This skill never claims a level; it
reads one (§2 `door.mjs trust`) and `rank.mjs --trust` writes per item `slice`,
`level`, `lane_a_ok` and `auto_decide`:

| Slice level | What this skill does with the item |
| --- | --- |
| **≥ 2** | Lane A is open to it (`lane_a_ok`), when every Lane A condition above also holds. Otherwise it routes as below. |
| **≥ 1** | handed off with `auto_decide: true` - the door re-checks the level itself and, at L1 or above, records `predicted_verdict` as the decision (`decided_by: machine:scan-sweep`) with a 24 h veto window. |
| **0** | plain hand-off; the human decides. |

- **Start levels** are the contract's: `technical` L2, `product` L0. The overlay's
  `autonomy.start.technical` / `autonomy.start.product` may only LOWER them, and
  because the door does not read the overlay, a lowered start is also a local
  ceiling on the door's levels for that category.
- **`autonomy.frozen`** - a list of slice patterns (`*` per part, e.g.
  `product|*|*|*`, `technical|security-auditor|*|*`) the operator pins at L0 for
  this skill: no in-session build, no `auto_decide`.
- **Door unreachable** (`trust.json` says `reachable: false`): every slice is at
  its category start level; Lane A follows that start, and `auto_decide` is only
  ASKED (L1 at most) - the door decides it when the card lands. Say so in the
  header.
- **The false-positive counter stays, as a local demotion on top.** While §5's
  strict rule is on (three `fp` in the last five rounds), every slice's
  effective level is one lower for this skill - an L2 slice loses Lane A, an L1
  slice loses `auto_decide` - AND Lane A still requires `Method: gate`. The door
  is not told: it keeps its own levels from its own history, and the two meet
  only in the minimum. The counter is repo-wide and fast; the ladder is
  per-slice and earned; either can stop the machine, neither can start it.
  (`coverage.mjs --next --json` prints `strict`; pass `--strict` to `rank.mjs`.)
- **Lane B is an L2 act too.** A Lane B merge is the machine landing code on its
  own measurement - the contract's L2 auto-build - so a Lane B item is dispatched
  only when its slice reads `lane_a_ok: true` (the field is the level check alone;
  Lane A's size and path conditions do not apply to B). Below L2 - every `product`
  slice at its L0 start - it goes to the §9.1 hand-off as A/B-drainable, with
  `auto_decide` per its level. **A human accept in Approvals is the decision the
  ladder asks for**: `--ab-only` over cards the operator accepted dispatches them
  at any level.
- `secret` / `authz` / `money` never route above L1, and nothing that leaves the
  system (a publish, a message) is ever handed off with `auto_decide`. **Neither
  is a Lane C escalation** (`direction`, `architecture`, `irreversible`,
  `policy-loosen`, an operator-only act): those four are the human's by this
  skill's own law, so their cards go with `auto_decide: false` whatever the
  slice level says. **Any Lane C card is the human's**: `rank.mjs` reads the
  card's `lane: "C"` marker as well as its gate, and a handed-off `gate: contract`
  card is never `auto_decide` either (an in-tree contract with its verifier green
  may still be Lane A). Put `lane: "C"` on every Lane C card - an XL or a
  context-map edit whose gate is `none` is still Lane C.
- **Category is the lens's, one way.** A finding's `category` is its lens's
  `Category:` line in `references/lenses.md`; the reader may move a technical
  lens's finding to `product`, never a product lens's finding to `technical`.
  `rank.mjs` and `filing.mjs` clamp such a card to `product` and report it
  (`category_clamped` on the row, `clamped` in the summary and the hand-off
  reply) - relabelling must not move a card past the L0 gate.

**What Lane B is for, stated once.** Unit tests say a change did not break what was
already pinned. Lane B says the change made the figure better than it was, on the
same inputs, with an instrument that has been shown to notice the difference. That
is the harder claim, and it is the one a backlog card actually makes.

### The four vetoes - they override every route above

An item is set aside regardless of lane when it:

1. **touches a file outside this context's declared paths** (see the parallel
   rules in §7) — no longer a backlog verdict but a routing one: it goes to
   Lane B as `out-of-scope`, to a worker that owns that context. It is a veto on
   THIS session's hands only. **But a coupled doc, test, locale entry or
   generated artefact the fix REQUIRES is part of the fix**, not a second change,
   not `out-of-scope` and not an escalation: build it, stage it with the rest,
   and name the extra path and why it was coupled in the commit body. Veto 1 is
   for a change that wanders into another area, not for the file the change
   cannot land without.
2. **changes a contract whose consumers you cannot enumerate by instrument** —
   another repository's, a public SDK's, a wire format with readers outside this
   tree — Lane C. An in-tree contract with a verifier is A; without one it is B.
3. **has no gate that can verify it and none can be built at S or M** — if
   nothing can tell you the fix worked, committing it is committing a belief. A
   missing test you could write in twenty lines is not this veto; write it. Lane
   B attempts the rest; if the worker cannot build an instrument either, it
   returns `unmeasurable` and the card goes to C naming the instrument.
4. **is a foreign session's in-flight file** — a coordination call, not a triage
   call: wait, and say so in the finding. Neither lane nor human; the next session
   sees the note and knows the difference.

### The mechanism measures itself

The snapshot (§10) carries `lanes=A:<n>/B:<n>/C:<n>`,
`ab=<better>/<not-better>/<unmeasurable>/<fp>/<demoted>` and `fp=<n>`. A false
positive is a Lane A item that failed its gate at build, **or a Lane B item whose
`Before` did not reproduce on the base tree**. A `superseded` item - its Before
stopped reproducing because a sibling card's merge in the same group already did
the work - is **not** a false positive: it sits in none of the five `ab` slots,
never in `fp`, never against its lens's precision or trust, and the row carries it
as `superseded=<n>` beside them (`abTally` in `scripts/filing.mjs`). **Three `fp` across the last five
rounds and Lane A requires `Method: gate` — a probe no longer suffices — and Lane B
requires the instrument commit to land before the fix, until three consecutive
rounds at `fp=0`** - and for as long, every slice reads one level lower for this
skill (the ladder, above). Two `not-better` verdicts on one finding from two different
workers is a measurement: the finding is rejected with both, never dispatched a
third time.

**The repo's own mechanical gate binds on the SITE, not on the idea.** A ratchet — a
LOC ceiling, a bundle budget, a dependency ban, a coverage floor — can make a
`better` item unbuildable because the only file its fix belongs in is already at
the line. That is not a reason to shrink the fix until it slips through, and not a
reason to invent a new file to escape the rule. Check each candidate's site against
the declared gates before choosing a lane, and route the blocked ones to C naming
THAT gate as the blocker.

**A ratchet blocks the change that would BREACH it, and nothing else.** Measure
the headroom before deferring: if the fix fits under the ceiling, **build it**
and put the measured headroom in the commit body ("file at 284/300 after"). Only
a candidate whose own implementation site is at the line goes to C, and the
card says which gate and by how much it overshoots. Deferring on the mere
existence of a ratchet is how a proven fix goes unbuilt - ~16 judge verdicts
split on exactly this, in both directions.

**Unattended runs** (dispatched by an app or a fleet, no operator present): Lane A
builds, Lane B dispatches if `--ab` was given, Lane C waits for the deck. Nothing
asks.

**Without `--ab`, Lane B is a queue that only grows - say its size every round.**
The default loop does not dispatch the wave, so every round adds its B cards to
a pile no step of the run drains. Measured 2026-10-04 (one `--stabilize` loop,
23 contexts, 20 rounds): 208 built, 112 Lane B left open - more than half as
many as were built, and nothing in the per-round reports added them up. So:

- Every round's close-out (§8) carries the running total: `Lane B open: <n>
  (this round +<k>) - drain with /scan-sweep --ab-only`.
- When the run's open Lane B count passes **half its Lane A built count**, or
  **25** items, say so in the next round's header, once, as a choice for the
  operator: drain now (`--ab-only`), or keep sweeping. When attended, ask.
  When unattended, keep going and repeat the line.
- The loop's closing report leads with the pile, not the built count, and the
  register row's `note` (§9) names the drain command. A B card with no
  `instrument` field cannot be drained - the round that wrote it owes it one.

**What the backlog is FOR — and what never goes in it.** The Personas idea backlog
(Approvals → Backlog, the `dev_ideas` table, reached by §9.1's hand-off or the memory
outbox) is where a HUMAN decides. During a run it
holds Lane C and nothing else (at session end §9.1 adds the undrained Lane B,
tagged as drainable, and the round's `band: reserve`, tagged as such): the
escalations, the operator-only acts, and what
Lane B could not measure. A Lane A item is built. A Lane B item is built or thrown.
A backlog full of approved-but-unbuilt items is a sweep that stopped one step early
— measured 2026-08-28, 149 of 240 wave findings were auto-approvable, and measured
again 2026-09-06, every S card on the deck was one an instrument would have decided.

## 6. The registry lane - knowledge feeds the lenses, deviations are one lens, leads flow back

Skip this section entirely when the repo declares no registry. When
`.ai/manifest.yaml` carries `registry.local` (or `registry.remote`) and
`knowledge.domains`, the repo consumes a shared knowledge corpus, and a sweep is
one of the few moments that can pay into it as well as read from it.

**Read side - before you judge (§4.3).** Resolve the subject governing this
context and read its golden path plus the techniques whose `use_when` matches.
This read is what the LENSES consume (§3): each lens takes the techniques that
touch its concern into its own judging. The read is not itself a lens, and a
list of "we deviate from technique X" is not a sweep - it is the output of ONE
lens, `registry-conformance`, budgeted like every other one.

- If `.ai/registry-map.json` exists it already holds the context→subject join;
  take the subject's `file` **verbatim** from the index. Never construct a path
  from a slug - bundles are nested and depth is dynamic, so a built path points
  at a folder nobody walks.
- **The map's `paths` are a twelve-path sample, not the context.** Take the
  round's file list from the context map (`contextMap`) and use the registry
  map only for its subjects. A file missing from the map row is not
  "ungoverned", and a lead claiming the map drops files is wrong
  (`check-context-coverage.mjs` measures real reach).
- Without a map, resolve through `<registry>/knowledge/<domain>/index.json`.
- Without either, say so in the header (`registry: declared, unmapped`) and judge
  on the repo's own conventions. Degrade honestly; never invent a standard.

A finding that names the technique it violates is worth more than one that names
a smell, and it arrives with the fix already described.

**Log the consult** - append one line to `.ai/consults.jsonl`:

```json
{"ts":"<ISO>","bundle":"<domain>","subjects":["<slug>"],"techniques":["<slug>"],"deviations":<n>}
```

`deviations` counts findings in this round that a technique explicitly names as a
failure. Slugs and counts only, never paths. This is the demand signal the
registry reads to learn which knowledge is actually reached for.

**Write side — after a fix LANDS.** Most rounds produce nothing here, and that is
the expected result. A lead is owed only when a landed fix (or an L finding you
are backlogging) clears **all four** bars:

1. **General** — an unrelated team on a different stack would face the same
   problem. If it depends on this repo's file layout, it is a project lesson, not
   a lead.
2. **Rule-shaped** — it states as *"when X, do Y, because Z"*. A description with
   no trigger has not finished becoming knowledge.
3. **Novel against the corpus** — you read the governing subject this round and
   the rule is not already in it. A lead that restates a technique is noise.
4. **Earned** — it came from code you changed and verified, not from a fix you
   proposed. A sweep learns by landing things.

Append it to `.ai/registry-leads.jsonl`:

```json
{"ts":"<ISO>","bundle":"<domain>","nearest":"<subject-slug or null>","kind":"technique|application|subject","claim":"<when X, do Y, because Z - one sentence>","because":"<what this run measured or broke and fixed>","confidence":"low|medium|high","from":"scan-sweep@<version>"}
```

**This is a LEAD, not a knowledge write.** A sweep ORIGINATES a finding; it never
AUTHORIZES one. Nothing here edits a bundle — the registry's own intake triages
leads, corroborates them, and lands only what survives. Say in the report that
you filed one, and say plainly when you filed none.

## 7. Execution — land the approved list

This section is **Lane A**. Lane B's execution is a wave of workers under
`references/ab-lane.md`, dispatched after this section's commits have landed; the
director's merge rules live there too. Work the approved queue - this context's `carry` items from prior rounds
first, then this round's, highest-reward first - one finding at a time:

1. **One atomic commit per finding.** Fix, verify, commit, then start the next.
   Never stack two findings' edits in one working state. **Re-measure the
   Evaluation's After on the real change before committing**, and put the
   re-measured figure in the commit body: a probe on three sites is what
   routed the item, the gate on the whole change is what lands it. An After
   that comes back `not-better` on the real change is a demotion (§7.4) and
   a false positive for the snapshot's `fp` count.
2. **Verify before committing** with the repo's own gates for the surface you
   touched (`.claude/conventions.json` or the manifest's capabilities name them;
   else the obvious ones). A fix that fails its gate is repaired inline or fully
   reverted — never committed red, never left half-applied. **A gate you could
   not run is a gate that did not pass**: say so in the report and mark the round
   degraded.

   **Every Lane A item's gate includes the overlay's census (count / ratchet)
   gate and every other declared ratchet (`ratchets`, `structuralTests` - see
   the director's rules below)**, not only typecheck, lint and the context's tests. Read it from the
   overlay's gates (`.claude/scan-sweep/config.md`, or the repo's `## Gates`) -
   Personas: `node scripts/census/run-census.mjs` / `npm run census:check` - and
   pin it verbatim in the round-agent brief beside the others. A census rise is a
   breach (the ratchet rule below); a census drop is reported, not fixed. Measured
   personas cycle 2 (2026-10-30): §7 named tsc, eslint and tests only, two census
   rises passed those gates, and one round-agent caught them only because it ran
   census on its own. An overlay with no census gate: say `census: none declared`.

   **A ratchet that exits non-zero on a DROP is a PASS for the fix, and the
   `&&` chain below handles it without stalling.** Some ratchets (personas
   `npm run census:check`) exit 1 when a count goes DOWN until the baseline is
   re-recorded - so the shape "every gate `&&`-chained, commit last" stops on
   the very improvement the fix made (personas c3, 2026-10-31: every agent hit
   it after its first fix). Read the failure, not just the status: a DROP
   (`<key> <old> -> <new>`, new < old) on a key your change touched is green
   for the gate chain; a RISE, or a drop on a key you did not touch, is red.
   On a drop, the chain becomes: commit the fix (its other gates green), then
   lower the baseline in its OWN commit with the ratchet's update verb (personas:
   `npm run census -- --update --rule <id>`; `node
   scripts/check-agents-sub-boundaries.mjs --update`), re-run the ratchet,
   exit 0 asserted - `chore(<context>): <ratchet> baseline <key> <old> -> <new>`.
   A round-agent under a director does not run the update verb: it reports the
   drop in its reply and the director lowers the baseline (the director's
   rules below). Never raise a baseline to pass.

   **ASSERT the gate's own exit code. Reading it is not asserting it, and
   piping it away destroys it.** Three ways this rule has actually been defeated,
   all in one session, each by the shell rather than by the code:

   - `npm run typecheck | tail -3 && git commit` takes **`tail`'s** status,
     always 0. The chain commits over a red gate and the failure scrolls past in
     the output you were trimming.
   - `npm run typecheck; echo "TC=$?"; git commit` **prints** the failure and
     commits anyway. A number in the transcript is not a gate; `;` is not `&&`.
   - The gate is red for a reason that is **not yours** — see below.
   - The gate is a **composite script whose early stage failed**, so the later
     stages never ran. `check = typecheck && lint && build` with a foreign lint
     error means the build was never executed, and "the red is not mine" is only
     half the analysis: you still owe the skipped stage. Run it on its own and
     say which stages actually passed, or the round is degraded.

   The shape that holds: run each gate in its own invocation, `&&`-chained so a
   non-zero status stops everything, and let the commit be the last link.

   **This binds the COORDINATOR as hard as the builders, and the coordinator is
   where it was actually defeated.** Measured on lighttrack 2026-10-05: the first
   command of a whole challenge run was `cargo build --workspace 2>&1 | tail -15;
   echo "BUILD_EXIT=$?"`, and it printed `BUILD_EXIT=0` over a build that had failed
   on a locked output file. The baseline that twelve cards were about to be judged
   against read green only because the pipe ate the status. A coordinator runs more
   gates than any single builder - the baseline, one integration gate per wave, the
   final one - so this rule belongs in its own checklist and not only in the builder
   brief it hands out.

   **Under a concurrent session, a whole-tree gate says nothing about your
   change.** `tsc --noEmit` covers every file in the repository, so a sibling
   agent mid-write turns your verification red and a *passing* run can equally
   depend on their unfinished work. Before treating a red whole-tree gate as
   yours, get the failing paths and compare them against the files you touched;
   if none of them are yours, say so, verify what you can scope to your own
   files, and wait for the tree to settle rather than committing into it. §7's
   parallel rules cover STAGING and stopped there — verification has the same
   hazard and it is easier to miss, because the output looks like a verdict on
   you.
3. Commit message `<type>(<context>): <finding title>`, with a body line naming the
   lens — the finding's provenance survives in history. **The type follows the
   change, not the skill**: `fix` for a behaviour change, `test` for a test-only
   fix or an instrument, `docs` for a comment / doc / README fix, `refactor`
   for a change that keeps behaviour, `perf` for a measured speed-up, `chore`
   for a baseline or regen. A brief that hard-codes `fix(` mislabels every
   docs- and test-only commit (personas c3, 2026-10-31); a brief pins this rule,
   not one prefix.
4. **A fix that grows beyond its size class mid-flight is demoted, not forced.**
   If an S starts touching a third file or a shared surface, stop, revert the
   attempt, and emit it as a finding at its honest larger size. This is the
   safety valve behind auto-approving S: the class is enforced at execution time,
   not just at classification time.
5. **Contract and source-guard tests pin the OLD expression**, so a real fix
   fails them. That is correct by design. Budget for it, and *strengthen* the
   assertion in the same commit (pin the new expression AND forbid the old), or
   the fix silently loses its guard.
6. **Never author a pattern through a shell heredoc, and seed a violation to
   prove the gate still bites.** A heredoc reads `\b`, `\s`, `\n` as its own
   escapes, so a regex written that way can reach the file as control characters
   — measured: `\b` arrived as a literal `0x08`, the matcher found nothing, and
   every subject read as compliant. Use the file-writing tool for anything
   containing a backslash, and after ANY scripted edit to a checker, seed the
   thing it looks for and watch it go red. A gate that cannot match reports a
   clean codebase in a voice indistinguishable from success.

7. **Never point a build, test or package cache inside the repository.**
   `CARGO_HOME`, `UV_CACHE_DIR`, `npm_config_cache`, `PYTEST_DEBUG_TEMPROOT`, a
   scratch worktree, a downloaded toolchain: all of them go to the OS temp dir,
   never under the tree you are sweeping and never under a vault or overlay
   directory. Measured 2026-09-16: ~10 judge verdicts found 12k-file caches left
   behind, after which `git status` can no longer tell work from litter. Before
   the round's last commit, confirm `git status --porcelain` shows only files
   you meant to touch.

8. **A source-scanning gate must strip comments before it matches.** The files a
   sweep writes explain the rule in prose, directly above the code that
   implements it — so a matcher run over raw text is satisfied by a file that
   TALKS about the rule and does not follow it. Measured twice in one session: a
   probe passed against a deliberately broken subject because the word it looked
   for survived in the comment describing the fix. Strip `//` and `/* */` first,
   then match, and let the fail-before be what tells you — it is the only step
   that catches this, and it caught it both times.

9. **Run each overlay gate once before the first round, and check what it
   loaded.** A gate copied from an overlay can run without the config its
   directory depends on. Measured 2026-10-04: `uv run --project <pkg> pytest`,
   run from the repo root, picked up no pytest config. Its `live` marker was
   not deselected, so the gate made a real network ingest against a data
   source in the first round. Read the gate's header (rootdir/configfile, the
   tsconfig, the selected tests) before you trust it. A gate that can reach the
   network or spend money must refuse that from inside the test tree (a
   conftest or setup hook), not only through an ini file that a different
   working directory skips. **And again before Lane B dispatch, for the gates
   the wave's items need** (`references/ab-lane.md`, "Preflight the gates"): a
   gate this host cannot run makes its items unmeasurable before a worker is
   spent on them - hand them off naming the gate, do not dispatch them.

**Parallel-session rules** — several sweeps may share this repo, one context each:

- Edit ONLY inside your context's paths, plus their tests and any generated
  artifacts the repo REQUIRES you to regenerate for those edits. A needed change
  outside that boundary is veto 1, not a decision.
- Stage with explicit pathspecs only. Never `git add -A` / `.` / `-u`, never
  `git stash`, never reset another session's work. Before each commit confirm the
  staged list is exactly your files.
- Shared or generated surfaces other sessions also write (locale bundles,
  generated types, checksum manifests): make the edit and its regen, commit
  IMMEDIATELY, and keep that commit minimal - but never smaller than what keeps
  the committed tree compiling: a shared type change goes in with every caller it
  breaks, in the same commit. Shared files must never sit uncommitted while you
  work on the next finding.
- **A peer session on the same branch** is a coordination partner, not noise:
  ask it whose dirty paths are whose, offer it a merge window between rounds or
  waves, and never revert its lines (`references/challenge.md` §7, "A peer
  session on the same branch").

**Director-run fan-out**: one session runs the loop and hands rounds to
round-agents, all working in one checkout. The rules above cover each agent. The
director has its own job, and every rule below was paid for once (measured
2026-10-04: 20 rounds over 23 contexts, in 5 waves of 4 agents, 256 commits,
no cross-agent contamination):

- **The director owns every shared file**: the snapshot ledger (§10), the
  open-backlog register and outbox (§9), the consult and lead files (§6), and
  any ratchet baseline. Round-agents never write them. They return their
  snapshot row, consult line and lead lines in the final reply, and the
  director appends them. Each agent writes its own findings file, one per
  context or merged round (`<findingsDir>/<slug>.jsonl`), so no two agents share a
  findings file - **appending each finding the moment it is verified** (§4.12)
  and each lens's `coverage.jsonl` line as the lens finishes (§4.9). The final
  reply is a summary of those files, never their only copy: a killed agent's
  judgement must survive on disk (personas 2026-10-30: four agents killed, none
  had written a findings file, every round owed its whole package again).
- **The director never ends its turn with a round-agent still running.** Wait
  for every completion (or dispatch in the foreground) before the final
  message; under `claude -p` the harness stops live subagents after the last
  turn (Invocation, `CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS=0`).
- **The director runs EVERY ratchet the overlay declares, not only the census.**
  After each merge and in each wave's combined gate, run each command in the
  overlay's `ratchets` (default: the census gate in its `gates`, if any) and the
  tests under its `structuralTests` dir, each in its own invocation, exit
  asserted. The director's related-test scope for a merge is the touched
  surfaces' tests PLUS `structuralTests`, whatever the merge touched: a
  boundary ratchet fails on files it does not live beside. Measured personas
  c2r2 (2026-10-31): wave 1 removed one `sub_design -> sub_editor` import
  crossing, the structural ratchet `src/__tests__/structural/agents-sub-boundaries.test.ts`
  (baseline `scripts/agents-sub-boundaries.baseline.json`) failed on the drop,
  and it surfaced only because a later worker ran it - the related-test scope
  had never reached `src/__tests__/structural`.
- **Regenerate and diff after every merge.** Run the overlay's `regen` commands
  (default: none - then say `regen: none declared`) on the merged tree, then
  `git status --porcelain` must print nothing. A generated file that comes out
  dirty is a worker's missed regen: the director commits it at once as
  `chore(<context>): regen <file> after <merge sha>` and names the item in the
  wave report. Every gate can be green over a stale generated file - personas
  c2r2: a locale key landed without its per-section locale file (generated by
  `scripts/i18n/split-locales.mjs`, the `i18n-split` task of
  `scripts/run-codegen.mjs`), tsc, eslint, census and vitest all passed, and the
  app would have shipped without the string.
- **A ratchet that fails on a DROP is an improvement, not a red gate.** Some
  repos' census, count or structural ratchets fail when a count goes DOWN until
  the baseline is re-recorded (personas `census:check` /
  `scripts/census/rules.json`; `agents-sub-boundaries` /
  `scripts/agents-sub-boundaries.baseline.json` via its `--update`). The
  director updates such a baseline in a commit of its OWN,
  `chore(<context>): <ratchet> baseline <key> <old> -> <new>`, whose body traces
  the drop to the merge and item that caused it - never folded into an
  unrelated fix, never raised. For a
  round-agent that failure is a pass: it does not edit the baseline, it reports
  `ratchet: <file> <key> <old> -> <new>` in its reply, and the director lowers
  the baseline once, after the combined run (below). Where a commit hook runs
  that gate and would block the commit, the brief names the one exception: the
  agent lowers exactly that key to exactly the count its own change produced,
  in the same commit, and names it in the reply - never raises one. A ratchet
  that fails on a RISE is a breach and the agent's to fix.
- **Cross-round and cross-lane: dedup by subject before a round builds, and
  guard every deletion against open cards.** Disjoint write paths do not stop
  two rounds from building the same thing (personas c3, 2026-10-31: two sibling
  rounds built the same `PERSONA_NULLABLE_FIELDS` parity test), nor a Lane B
  deletion from removing the subject of an open Lane C card (it nearly did).
  (1) Every finding carries `subject_key` (§4.12). The brief tells each
  round-agent to rank with `rank.mjs --siblings <the sibling rounds'
  findings.jsonl, comma-separated>` - the files exist from the first verified
  finding (§4.12) - and a finding a sibling already holds is dropped from
  `ranked.jsonl` and listed as `duplicates`; the round names them in its reply,
  and the director checks the same keys across Lane B groups before dispatch.
  (2) **Before ANY commit that deletes a symbol, a file or a test**, search the
  open cards for it - the run's own findings / hand-off files (`grep -rn
  "<symbol>" <run dir> .claude/scan-sweep/`) and Approvals' pending and accepted
  rows (`node scripts/personas-door.mjs sql "SELECT id, status, title FROM
  dev_ideas WHERE project_id = '<id>' AND status IN ('pending','accepted') AND
  (title LIKE '%<symbol>%' OR description LIKE '%<symbol>%')"`, read-only). A
  hit refuses the deletion: the item is demoted (§7.4) with the card's id named,
  and the deletion waits for that card's decision.
- **A wave is ≤ 4 contexts that share no write paths.** Hold a context whose
  paths another session has reserved, and run it in a later wave once that
  session releases them. Pair the small contexts (§1) inside the wave. Each
  pair is one round with one agent.
- **One brief, written once, pins the gates verbatim** from the overlay. It
  states the asserted-exit-code rule (§7.2), the "a red whole-tree gate is
  probably not yours" rule, the pathspec commit including the form for an
  untracked file (`git add <file>` then `git commit -m … -- <paths>`), the
  never-touch list, and the reply shape. Correct the brief when a round finds
  a gate wrong. A rule told to one agent only applies to that agent.
- **Integrate after every wave, before the next starts.** Run the full
  offline gate on the combined tree. Then - after the wave's Lane B returns
  are merged or rejected, so each row's `ab` is real (§10) - commit the wave's
  ledger rows in one `chore(scan-sweep): wave <n> ledger` commit, and lower any ratchet baseline
  only after that combined run. A ratchet that drifted up during the wave
  goes back to the agents whose files caused it, with the files named. The
  director never formats the whole tree.
- **A stalled agent is resumed, not replaced.** Its committed work and its
  transcript survive. Send it a message that says what it already committed
  and what is left. A second agent spawned on the same context will rebuild
  committed fixes and fight the first for the same files.
- **Slow gates stay with the director.** Agents must not run the end-to-end
  suite, dev servers, or anything that hits the network. The director runs
  these once, when the loop closes.

## 8. Report each round

Header first:

- `Method: full (context: <name>, strategy: <s>, lenses: <n> evaluated)` — or
  `DEGRADED: <what was skipped and why>` if you sampled, skipped a lens, or could
  not run a gate. **A degraded sweep reported as complete is worse than no
  sweep.**
- `registry: <domain>/<subject>` — or `none` / `declared, unmapped`.
- `memory: decisions <n> (context|project)`, `memory: digest only (<reason>)`
  or `memory: none (<reason>)`, and the `trust:` line (§2).

Then **the per-lens table** `rank.mjs` printed (§4.4), one row per lens that
produced a finding, MVP score descending:

```
| lens | ranked | reserve | MVP | MVP score | tokens |
```

`tokens` only when the harness shows a per-lens figure - otherwise the column is
omitted, never estimated - and an unscored MVP reads `unscored`, never 0. Under
it: `<r> ranked (cap <N>[, +<k> MVPs over it]), <s> reserve`, and the
**skipped-lens list** - every lens of the package that could not run, with its
reason. A skipped lens is never reported as zero findings, and a lens with no
surface (§4.9) is listed apart from both.

Then what SHIPPED, one line each (`fixed  <title> - <sha> - <re-measured
After>`), then what was REJECTED (`rejected  <title> - <Before> vs <After>`),
then the carried and backlogged findings — each in the standard form of §4.10
(Summary / Description / Flow / Expected impact / Evaluation, evidence
separate), plus **Scores** (size + effort / impact / risk, the computed `score`,
`confidence`, the `predicted_verdict` with its precedent) and, for every
backlogged card, **the escalation or the failed rung** that put it there.

Close each round with: X built (of which carries), Y rejected, Z backlogged
(escalated / unmeasurable / vetoed / carry), lenses evaluated **and how many had
no surface** (§4.9 - the two numbers are reported separately), `auto=` and
`fp=`, leads filed, the trend for this context (`12 -> 7 -> 5 findings`), the
running **Lane B open** total when `--ab` was not given (§5), and **the next
context the loop will take**.

## 9. Emit to the memory outbox

Append to the outbox (overlay key `memoryOutbox`, default
`.personas/memory-outbox.jsonl`), ONE JSON object per line.

**A BUILT finding is a progress node, not a finding** — it must never land in the
backlog as open work:

```json
{"type":"node","kind":"progress","skill":"scan-<lens-key>","context":"<context>","title":"Fixed: <title>","body":"<sha>; <one-line gist>"}
```

A Lane B item that MERGED is the same progress node with the wave's figures:

```json
{"type":"node","kind":"progress","skill":"scan-<lens-key>","context":"<context>","title":"Fixed (A/B): <title>","body":"<merge sha>; before <..> -> after <..>; seeded red; worker sonnet"}
```

A Lane B `not-better` is never emitted - it was rejected with figures in the report
and the ab ledger. A Lane B `unmeasurable` is emitted as a BACKLOGGED finding whose
After line names the instrument the worker could not build.

Each BACKLOGGED finding (Lane C only):

```json
{"type":"finding","skill":"scan-sweep","lens":"<lens-key>","context":"<context>","title":"<title>","body":"## Summary\n...\n\n## Description\n...\n\n## Flow\n- ...\n\n## Expected impact\n...\n\n## Evaluation\nClaim: performance - ...\nBefore: ...\nAfter: ...\nMethod: probe - ...\nResult: better\nGate: none","evidence":"<code block or file:line list - the proof, not the prose>","size":"S|M|L","effort":3,"impact":7,"impact_why":"<<=200 chars>","risk":2,"confidence":"low|medium|high","category":"technical|product","score":51.7,"score_parts":{"impact":7,"confidence_w":0.95,"effort_div":1.222,"risk_factor":0.95,"formula":"scan-score/1"},"band":"ranked|reserve","mvp":true,"mvp_rule":"top-score|override","mvp_why":"<only with override>","predicted_verdict":"accept|reject|defer","predicted_why":"<<=300 chars, the precedent quoted>","predicted_by":"scan-sweep@<version>:<model>","proof":{"metric":"...","method":"gate","unit":"...","before":"...","after":"...","verdict":"better|not-better|inconclusive","control":"red|absent","base_sha":"...","head_sha":"..."},"result":"better|not-better|unmeasurable","method":"gate|test-only|probe|experiment|simulation","gate":"none|contract|policy-tighten|policy-loosen|irreversible|architecture|direction","lane":"B|C","disposition":"backlog|carry|reverted","sweep_run_id":"<run id>","subject_key":"symbol:<name>|test:<path>|file:<path>","note":"<run remark, filed into reasoning>","auto_decide":false}
```

`body` is the §4.10 form verbatim — the five `## ` sections, newline-escaped in
the JSON; `result`, `method` and `gate` repeat the Evaluation's verdict as
fields so a consumer can route without parsing prose. The scan-finding/1 fields
are §4.12's, as `rank.mjs` left them (`score`, `score_parts`, `band`, `mvp*`,
and the ladder's `auto_decide`, are the script's, never typed); a key whose
value is unknown is left out (`proof` only on a built item, `mvp_why` only on an
override). The same keys, snake_case, are what the outbox and the hand-off both
carry. A `backlog` finding is,
by construction, one whose result or gate said "human" — say which, on the
card. A `carry` finding is approved and owed to the next round on this
context, and a consumer must not present it for a decision. A `not-better`
finding is never emitted: it was rejected in the report. A finding emitted in
any other shape is rejected at review, not reformatted.

Escalation — at most one per lens, ONLY when that lens produced a critical
finding (impact >= 8) or 3 real findings in this context:

```json
{"type":"escalation","skill":"scan-sweep","lens":"<lens-key>","context":"<context>","reason":"<<=120 chars: what a deep pass should chase>"}
```

Coverage — **per-lens coverage lives in the ledger, not the outbox.** Each lens
**actually pointed at a named artefact** (§4.9) has its `coverage.jsonl` line
(`<findings> findings; checked: <checked joined by "; ">`) and its key in the
snapshot row's `lens_keys` (§10); that is the per-lens record, and it is never
written from memory. The outbox gets ONE aggregated coverage node per context
per round, its body rendered from those lines - the lenses that read something,
each with its finding count, and the clean ones with what they checked, cut to
the line's size; lenses with no surface are not listed. Plus the round node:

```json
{"type":"node","kind":"progress","skill":"scan-sweep","context":"<context>","title":"Sweep coverage: <context>","body":"<k> lenses read; error-handler 2 (src/a.ts, src/b.ts); copy-auditor 0 (checked: 14 strings in src/ui/); ..."}
{"type":"node","kind":"progress","skill":"scan-sweep","context":"<context>","title":"Sweep of <context>","body":"<n> lenses; <built> built, <open> backlogged, <e> escalations, <l> leads"}
```

Why one node, not one per lens: the outbox caps at 200 lines (below), and per-lens
nodes for a wave are ~180 lines on their own (personas c3, 2026-10-31: 158 lines
already undrained, ~180 coverage nodes owed - the director wrote only the 8 round
nodes). No script writes these nodes; the director renders them from the files.

Keep the outbox lean — ingest caps at 200 lines / 512 KB and 30 finding lines per
pass. At 16 ranked findings per context, plus reserve, that is under two rounds, so the
loop WILL meet this cap: check whether the file was drained between rounds (the
app deletes it on ingest), keep going if it was, and if it was not, emit the
round's findings ranked band first and by `score` within it, stop at the cap, and say in the report
which findings did not fit and that they are unrecorded. A finding silently
dropped for want of a line is worse than one never found, because the ledger
will claim the context was swept.

**Findings that do not reach the outbox get a register row.** Whenever a pass
leaves findings anywhere but the outbox - the cap above, an `--ideas-only` or
mass wave that wrote a findings file, a build wave that stopped early - append
or update one line in the open-backlog register (overlay key `openBacklogs`):

```json
{"id":"<strategy>-<date>","at":"<ISO-8601>","strategy":"stabilize|develop|optimize","path":"<repo-relative path to the findings file>","total":<n>,"emitted":<n>,"built":<n>,"declined":<n>,"descoped":<n>,"open":<n>,"status":"open|closed","note":"<<=160 chars: what is left and who it waits on>"}
```

`open` reaching zero, or the operator declining the rest, sets `status:
"closed"` with the reason in `note`; rows are never deleted. §0 reads this file
first on every invocation - it is how a backlog survives the weeks between
sweeps.

### 9.1 Hand-off to Approvals - the session's last act

**A run does not end with findings in repo files.** The register above kept
backlogs from being lost; it did not get them decided. Measured 2026-10-11 across
twelve fleet repos: ~940 open items sat in registers, findings files, challenge
follow-up lists, moonshot READMEs and six undrained outboxes (130 findings the
30-line ingest never reached), the oldest 36 days old, and none of them was in
front of the operator. Personas Approvals
(Overview → Approvals → Backlog, the `dev_ideas` table) is the one place the
operator decides, so every item a session leaves open goes there before the
session reports done.

**What is handed off.** Everything still open when the run stops: Lane C cards,
Lane B items the run did not drain (tagged A/B-drainable, so the operator can
bounce them to `--ab-only` instead of judging them), carries the run did not
reach (as Lane B), Lane B `unmeasurable`, and every **`band: reserve`** finding
(§4.4 - found, verified, scored, over the cap: filed, never dropped). Built items
and `not-better` rejections never are - **except an in-run Lane B item**, below. A Lane B item stays out of Approvals while the run can
still drain it - the hand-off is for what the session leaves behind, not a
shortcut past §5.

**A carry the run did not reach** is written as it stands (`disposition:
"carry"`); `filing.mjs` converts it - Lane B, `disposition: backlog`, the
A/B-drainable head - and the reply counts it under `converted`. The door refuses
`carry` itself (a carry is owed to a round, never a decision), so the conversion
is the script's, once, never the director's by hand (personas c3: carries sent
as `carry` were caught only by the dry run).

**An in-run Lane B item** - found and built inside this wave, so it never had an
idea id - still ends in an outcome post (§5: every verdict does). Hand it off
with its `proof` and `ab_result`: the worker return plus the director's `merge`
(and `superseded_by` / `commit` / `remainder` where the verdict needs them).
`approvals.mjs` files the card, then posts `outcomeFor(ab_result)` to the new id
in the same pass (`better` -> `delivered` with the merge sha; a `better` without
`merge` is refused). The result row's `outcome_posted: y` is what the ab ledger
row copies; `n` keeps the exit at 1. An in-run `not-better` stays out, as
above: it never had a card, it is rejected with figures in the report and the
ab ledger, and its ledger row says `outcome_posted: "n/a"`.

**Built, then reverted** (a change was built and measured, then taken out - a
reserve item built before ranking, §4.4, or a merge the director backed out) is
not a built item: nothing of it is in the tree. It is handed off with
`disposition: "reverted"` AND its `proof` (the contract's "a change was built";
`head_sha` = the reverted commit, which stays reachable in the branch history),
`result` as measured, and the revert sha plus the reason in the body's
Description, so the next round can cherry-pick instead of rebuilding.
`filing.mjs` refuses `reverted` without a proof - without one it is an
ordinary card claiming a build.

**How.**

1. Write the cards, one §9 finding object per line plus `"lane":"B|C"` and
   `"source":"<register id>"`, to `.claude/scan-sweep/handoff-<run id>.jsonl`.
   Cards from another shape (a challenge follow-up list, a moonshot README
   table, a `lanes.jsonl` row) are converted to it first; keep `title`, put the
   rest in `body`, and leave a scale out rather than invent it - an absent scale
   stays absent on the wire (the item files unscored), and only a missing
   `effort` with a known `size` is derived (`sizeToEffort`). Every card carries
   §4.12's fields as the round's `ranked.jsonl` holds them, including
   `predicted_verdict` / `predicted_why` / `predicted_by` and the ladder's
   `auto_decide`.
2. `node ${CLAUDE_SKILL_DIR}/scripts/approvals.mjs --file <that file> --repo
   <repo root> --run-id <run id> --out <file>.results.jsonl` (`--dry-run` first
   when the operator is present and the batch is over 50; `--register` when the
   repo is not yet a Personas project and the operator agreed to register it). It
   files each card over the app's local HTTP door (`POST /dev-tools/ideas`,
   `origin: scan_sweep`, lens-keyed so a card the outbox already filed is a dedup
   hit), with no 30-item cap: every contract field top-level, impact / effort /
   risk on their native 1-10 (the door normalizes them once), the `score`
   computed by `score.mjs` when the card lacks one, `sweepRunId`, `proof`, and
   `autoDecide`. It returns per card `created | deduped | rated |
   near_duplicate`, plus `autoDecided` / `level` when the door answered them; a
   card with a present-but-invalid field is `invalid` (not filed, exit 1).
   A dedup hit on a `rejected` row is a human "no" that already exists - it is
   reported, never re-filed with `force`.

   **`near_duplicate` is NOT landed - the door filed nothing.** It answered with
   the OTHER item (`duplicateOf`) and a note naming the similarity. The card is
   owed, counted apart (`N near-duplicate - NOT filed, still owed`), and keeps
   the exit at 1. Read each pair: the same finding -> drop the card from the
   file; a different one -> re-run with `--force <fp|id|slug,...>`, which sets
   the door's `force: true` on exactly those cards (a card may also carry
   `force: true`). personas c3 (2026-10-31): 25 unrelated cards matched at
   similarity 0.50-0.71, 12 of them onto one card; the old exit 0 would have let
   step 3 delete their only record. **Never prepend the same line to many cards**
   - "gate unrunnable on host ...", a wave banner, a shared caveat: two thirds of
   that run's matches onto the most-matched card were the Rust cards carrying one.
   A run-level remark goes in the card's `note` field (filed into `reasoning`,
   which the near-duplicate check does not read); `approvals.mjs` warns when 3+
   bodies open with the same line.
3. **Exit 0** (every card landed): delete the hand-off file and every source
   file whose cards all landed (a source that is also a ledger - a findings
   file holding built rows, `lanes.jsonl` - is kept, and its handed rows get
   `"status": "handed_off"` so the build history survives and §0 stops counting
   them), set the register row `closed` with `note:
   "handed to Personas Approvals <date>: <n> created, <m> deduped"`, and commit
   the deletions where the files were tracked. **Exit 3 or 4** (Personas not
   running, repo not registered): delete nothing; leave the row `open` with
   `note: "hand-off owed: <reason>"` and say so in the closing report - §0
   retries it next run. **Exit 1**: delete only the sources whose cards all
   landed; the rest stay with their row open and the failures named.
4. The closing report leads with the hand-off line: `Approvals: <n> filed
   (<c> created, <d> deduped, <r> already rejected, <m> machine-decided at
   L<level> - 24 h veto, <v> carry -> Lane B, <o> outcomes posted) - <k> owed
   (<q> near-duplicate)`.

The outbox (§9 above) keeps the progress, coverage and escalation lines; when
Personas is running, findings go through the hand-off instead of competing for
the outbox's 30 lines. When it is not, the outbox is still the fallback for up
to 30 findings, and the rest wait for the hand-off.

`--handoff` runs this step alone over every open backlog §0 found, oldest first,
and scans nothing.

## 10. Persist a snapshot

Append one line per round to `.claude/scan-history/scan-sweep.jsonl` (create the
directory if needed). `lens_keys` = every lens that was **pointed at a named
artefact** (§4.9) — this is the per-context coverage ledger the picker and the
lens ordering both read, so a key written for a lens that looked at nothing
inflates it permanently. `lens_no_surface` holds the rest and earns no credit.
`findings` counts built, rejected, carried and backlogged. `auto` is the
routing tally (`accepted/rejected/escalated`), `fp` the auto-accepted items
demoted at build, `carried` the approved items left for the next round, `lanes` the routing
tally and `ab` the wave's verdicts - the numbers §5's self-correction reads.
`ranked` / `reserve` are §4.4's bands (the 40-lifetime cap sums `ranked` only),
`lens_skipped` the lenses that could not run, and `run_id` the `sweepRunId` the
round's cards were filed under.

```json
{"at":"<ISO-8601>","scope":"<context>","mode":"resolve|ideas","strategy":"stabilize|develop|optimize","run_id":"<run id>","lens_keys":["<key>"],"lens_no_surface":["<key>"],"lens_skipped":["<key>"],"lenses":<n>,"findings":<n>,"ranked":<n>,"reserve":<n>,"fixed":<n>,"auto":"<a>/<r>/<e>","lanes":"A:<n>/B:<n>/C:<n>","ab":"<better>/<not-better>/<unmeasurable>/<fp>/<demoted>","superseded":<n>,"fp":<n>,"carried":<n>,"escalations":<n>,"leads":<n>,"degraded":<bool>,"note":"<<=80 chars>"}
```

**The row is committed, not left dirty.** Where `.claude/scan-history/` is
tracked, the snapshot rides in the round's **last fix commit**; if the round
built nothing, it goes in a closing `chore(<context>): scan-sweep round <n>
ledger` commit of its own. A round that ends with an uncommitted ledger row has
not recorded its coverage - the next picker reads the file from HEAD. Under a
director-run fan-out (§7), the director commits the wave's rows together after
the wave's combined gate and its Lane B returns (below), so no row sits
uncommitted while the next wave runs.

**The `ab` field is written after Lane B, never before.** Lane B is dispatched
after Lane A's commits and the combined gate, so a row written at the gate reads
`ab: 0/0/0/0/0` by construction (personas cycle 2: every row did, while the
real figures sat in `ab.jsonl`). Write - or, if the row was already appended,
rewrite - each round's `ab` and `lanes` from that round's `ab.jsonl` rows
(`better/not-better/unmeasurable/fp/demoted`, counted by `run_id` and context
with `abTally` in `scripts/filing.mjs`; `superseded` goes in its own field)
once every Lane B worker of the wave has returned and the director has merged
or rejected it; only then commit (or, where ignored, finalize) the wave's rows.
A wave whose Lane B is still running has no row yet - not a zero row.

**A lost ledger is rebuilt from git, never by hand.** When the snapshot file
died with a worktree (or was never written), run
`coverage.mjs --rebuild-from-git [--since <date>]` from the repository root:
it reconstructs one row per context per day from the round commits
(`<type>(<context>): ...`) and `sweep/*` merges, marked `reconstructed: true`
with `lens_keys: []` - history does not say which lenses read a context, so the
row claims a sweep and no lens coverage. Read the rows, then append them with
`--write` (with `--history <main ledger>` where the ledger lives in the main
checkout), and say `ledger: N reconstructed rows` in the report.

**Where the ledger is ignored, it lives in the MAIN checkout.** Check first:
`git check-ignore -q .claude/scan-history/scan-sweep.jsonl` (exit 0 = ignored -
a repo that ignores `.claude/*` does). Then "committed" cannot hold, and a
worktree's copy dies with the worktree (personas 2026-10-30). So: append every
row to the main checkout's file - the parent of
`git rev-parse --path-format=absolute --git-common-dir` - never to a worktree's,
run the picker against it (`coverage.mjs --history <main>/.claude/scan-history/scan-sweep.jsonl`),
and say `ledger: untracked (ignored), main checkout` in the round report. The
same holds for every `.claude/scan-history/*.jsonl` and the open-backlog
register. Do not un-ignore the directory from inside a sweep; that is the
repo owner's call.

## Project overlay

Everything project-specific lives in `.claude/scan-sweep/config.md` in the
consuming repo. The skill runs on the defaults without it.

| Key | Default | Meaning |
| --- | --- | --- |
| `contextMap` | `context-map.json` | The context inventory the loop walks. |
| `memoryOutbox` | `.personas/memory-outbox.jsonl` | Where findings are emitted. |
| `backlogDigest` | `.personas/backlog-digest.json` | Titles never to re-propose. |
| `openBacklogs` | `.claude/scan-history/open-backlogs.jsonl` | Register of findings files earlier passes left unworked; read first (§0), written by §9. |
| `handoff` | `on` | §9.1: file the session's open items into Personas Approvals. `off` for a repo with no Personas on the machine; the register then carries them. |
| `gates` | from `.claude/conventions.json` / manifest capabilities | Verification commands per surface. |
| `depth` | 16 (loop), 24 (`--one`) | Ranked slots N per context per round (§4.4); the 40-per-context lifetime cap counts ranked findings only. Reserve is uncapped and is handed off. |
| `autonomy.start.technical` | `2` | Ladder start level for `technical` slices (§5). May only lower the contract's L2; a lowered start is also a local ceiling on the door's levels. |
| `autonomy.start.product` | `0` | Ladder start level for `product` slices. May only lower the contract's L0 (so it is effectively fixed). |
| `autonomy.frozen` | none | Slice patterns (`<category>\|<lens>\|<risk_class>\|<size>`, `*` per part) pinned at L0 for this skill: no in-session build, no `auto_decide`. Passed to `rank.mjs --frozen`. |
| `neverSweep` | none | Contexts the loop skips (generated, vendored). |
| `challenge.cohort` | 6 | Contexts per `--challenge` run. |
| `challenge.waveSize` | 4 | Concurrent builders per wave. |
| `challenge.sharedSurfaces` | none | Files every builder may append to under the shared-surface lock (locale catalogs, generated references, ratchet ceilings). |
| `challenge.integrationGate` | the overlay's full gate list | What runs on the combined tree after each wave. |
| `challenge.worktrees` | `false` | Whether builders may take worktrees (only when the repo's gates run in one). |
| `ratchets` | the census gate in `gates`, if any | Every ratchet command the director runs after each merge and in the combined gate (§7): census, count and structural ratchets (personas: `npm run census:check`, `node scripts/check-agents-sub-boundaries.mjs`). A frontmatter list, or a `## Ratchets` section with one command per bullet. |
| `structuralTests` | none | A test directory always inside the director's related-test scope, whatever a merge touched (personas: `src/__tests__/structural`). |
| `regen` | none | Codegen commands run after each merge, followed by `git status --porcelain` (§7, "Regenerate and diff"). A frontmatter list, or a `## Regen` section with one command per bullet (personas: `node scripts/i18n/split-locales.mjs`, the section-locale task of `scripts/run-codegen.mjs`). |
| `env` | none | Environment the director sets for every gate run - its own, the round-agents' (pinned in the brief) and the Lane B workers' (pinned in the dispatch prompt). A frontmatter map. Personas: `env: {CARGO_GUARD: "off"}` while the app is running - the app holds the one-cargo-at-a-time queue, so `npm run test:rust` waits on it forever (`scripts/build/guard-concurrent-cargo.mjs`, `run-rust-tests.mjs`: `off` skips the queue only, the throttle stays). An overlay without the key: the director sets it from `references/ab-lane.md`'s preflight when it sees the guard. |
| `ab.workerModel` | `sonnet` | The Lane B worker model (§5, `references/ab-lane.md`). The one place a project may pin another; SKILL.md and ab-lane.md state the default only. |

## Coverage table

`--coverage` scans nothing. Run `node ${CLAUDE_SKILL_DIR}/scripts/coverage.mjs`
(`--all` for every context, `--next` for just the next pick, `--json` for a
machine read) and present the per-context table — lens coverage, findings vs
fixed, last strategy and age, least-covered first. Then stop.

---

<!-- clause: finding-contract v1 - stamped by scripts/apply-skill-clauses.mjs from docs/skill-clauses/finding-contract.md; edit the template, then re-stamp -->
## Finding contract

This skill is one of three backlog scanners (`scan-sweep` -> Personas, `lens-scan` -> bp, Dowser ->
Jira) that share ONE finding contract, `scan-finding/1`. Each store keeps its own column names and
casing; the meaning, the scales, the score formula and the absent-value rule are this text, and a
consumer never recomputes what the producer stored. Standards: codebase-scanning (ranked, disclosed
truncation), scoring-rubrics (a stored score with its breakdown; unmeasured is never zero),
hitl-approval (a gate on anything visible outside the system; severity ladder).

**Fields every finding carries** (canonical snake_case keys; a store maps them 1:1):

| Key | Type | Meaning |
|---|---|---|
| `lens` | string | the dimension that found it (lens id). Never collapsed into a source/origin. |
| `category` | `technical` \| `product` | technical = the codebase's own quality (bugs, perf, reliability, security, debt, docs drift, a11y); product = what users get (features, UX direction, copy, pricing). Decides the autonomy start level. **A finding's category is its lens's declared default; a judge may move it technical -> product, never product -> technical** - the store clamps a product lens's finding to `product` and reports it clamped, so relabelling cannot skip the human gate. |
| `impact` | int 1-10 | defects: how bad if left (10 = data loss, breach, outage on a main path); opportunities: value if done. |
| `impact_why` | string <=200 | the one-line reason for the number. |
| `confidence` | `low` \| `medium` \| `high` | high = quoted evidence re-read in the current tree AND reproduced or measured; medium = quoted evidence re-read; low = inference. |
| `effort` | int 1-10 | build effort. When only a size is known: XS=1, S=2, M=4, L=7, XL=10. |
| `risk` | int 1-10 | risk of MAKING THE CHANGE (blast radius x irreversibility), never the severity. A low/medium/high blast maps to 2/5/8. |
| `score` | number, 1 decimal | `scan-score/1` below. Stored by the producer; consumers sort by it. |
| `score_parts` | object | `{impact, confidence_w, effort_div, risk_factor, formula:"scan-score/1"}` - the breakdown ships with the number. |
| `band` | `ranked` \| `reserve` | `reserve` = found, verified, scored, but over the run's cap. Filed, not discarded. |
| `mvp` | bool | true on exactly one finding per lens per run: that lens's top finding. |
| `mvp_rule` | `top-score` \| `override` | `override` only with `mvp_why`. |
| `mvp_why` | string <=200 | required when `mvp_rule = override`. |
| `predicted_verdict` | `accept` \| `reject` \| `defer` | the model's verdict, recorded BEFORE any human sees the item (shadow mode). |
| `predicted_why` | string <=300 | names the precedent it leaned on when one exists. |
| `predicted_by` | string | `<skill>@<version>:<model>`. |
| `proof` | object | when a change was built: `{metric, method, unit, before, after, verdict: better|not-better|inconclusive, control: red|absent, control_value, base_sha, head_sha}`. `control_value` (the instrument's reading on the seeded control) is required when `control = red` - without it a red control is an unverifiable claim. |

**Absent-value rule.** Unknown is never `0` and never `""`. JSON wire: omit the key. SQL: `NULL`.
A finding missing `impact` or `effort` has no `score`, ranks after every scored finding, and shows
"unscored" - never a zero.

**`scan-score/1`** (one formula in all three systems; a change is `scan-score/2`, never an edit):

```
confidence_w = {low: 0.5, medium: 0.75, high: 0.95}[confidence]   (absent -> 0.5)
effort_div   = 1 + (effort - 1) / 9                                (1.0 .. 2.0)
risk_factor  = 1 - (risk - 1) / 20                                 (absent -> 0.75)
score        = round1( 10 * impact * confidence_w / effort_div * risk_factor )
```

Range about 1.4-95. Impact leads: effort at most halves a score, so a trivial impact-3 fix (28.5)
never outranks an impact-8 medium-confidence M (40.5); a high-risk change keeps at least 55 % of
its value. Reference values for every implementation's test: `(10,high,1,1) = 95.0`,
`(8,medium,4,3) = 40.5`, `(3,high,1,1) = 28.5`, `(5,low,10,10) = 6.9` (half-up rounding: `Math.round(x * 10) / 10`).

**Coverage: every lens, nothing paid-for discarded.** A sweep reads each unit once and judges it
through EVERY enabled lens. Slot allocation for a run cap N: (1) each lens with >=1 verified finding
gets one ranked slot, its MVP; (2) the remaining slots go by `score` across lenses; (3) everything
else verified is `band: reserve`. The run report prints, per lens: ranked/reserve counts, the MVP's
title and score, and tokens when the harness shows them (omitted otherwise). A lens that could not
run is reported skipped, never as zero findings.

**Autonomy ladder** (per project x slice, slice key = `<category>|<lens>|<risk_class>|<size>` as one
string, an absent part written `-`; `risk_class` is lens-scan's vocabulary
`secret|authz|money|data|llm|perf|reliability|ux|debt`). **The gate lives in the store, not in the
prompt:** the system that records decisions computes each slice's level from its own decision
history and refuses a machine decision above it; a scanner's claim of a level is never trusted.

| Level | The machine may | Proof |
|---|---|---|
| L0 propose | file; the human decides | - |
| L1 auto-triage | record its predicted verdict as the decision, `decided_by: machine:<skill>`, with a 24 h veto window shown on the item | precedent quoted |
| L2 auto-build | build in a branch/pack/worktree and land ONLY a `proof.verdict = better` with `control = red` | before/after, same method, red control |
| L3 auto-merge | merge an L2 `better` to the base without a human | as L2 + gates green |

- **Start:** `category: technical` starts at L2, `product` at L0. A project overlay may lower either.
- **Earn:** a slice moves up one level when its predicted verdicts agree with the human verdicts on
  >= 90 % of its last 20 human-decided items (min 20; a reversed machine decision counts as a disagreement).
- **Lose:** a slice drops one level, and its window resets, on any human reversal of a machine decision
  inside or after the veto window, or any landed change whose proof is later re-measured `not-better`.
- **Ceilings:** `secret|authz|money` never above L1; anything that leaves the system (a Jira issue, a
  message, a publish) is never machine-decided - the human click stays. A scanner that may not write
  into the scanned repo (Dowser) has no L2/L3: its ceiling is L1.
- **Every transition is an append-only event** `{slice, from, to, reason, agreement, n, at}`, shown
  to the human beside the slice's current level.
- **Memory feeds the verdict:** before predicting, the scanner reads the project's recorded decisions
  for the same context and lens - verdict, reason, note - and quotes the closest one in `predicted_why`.
  Titles alone are not memory.
<!-- contract: scan-finding/1 - copied byte-for-byte into dowser/docs/contracts/scan-finding-1.md -->
<!-- /clause: finding-contract -->

<!-- clause: skill-reflection v6 - stamped by scripts/apply-skill-clauses.mjs from docs/skill-clauses/skill-reflection.md; edit the template, then re-stamp -->
## Skill Reflection

After the work, record only useful observations supported by this run. No lesson is
a valid result. Reflection inherits the task's authorization; it grants no additional
permission to edit another repository, send data, commit, or publish.

**Run log.** Unlike a lesson, this is written on every run that started work - failed and
aborted runs included; skip read-only info modes and runs cancelled before any work. Append
ONE line to `.ai/skill-runs.local.jsonl` at the root of the task's MAIN checkout: local,
gitignored run output inside the task's own repository, never a write into the registry.
A run that worked in a linked worktree logs in the main checkout that worktree belongs to
(`git rev-parse --git-common-dir`, minus `/.git`) - a disposable worktree takes the line
with it when it is removed. `log-run.mjs` resolves this on its own.
The registry pulls it later (`/librarian skills` on the same machine). When a registry
checkout is reachable (`registry.local` in `.ai/manifest.yaml`), prefer its writer, which
stamps project, device and version for you:

```sh
node <registry>/scripts/log-run.mjs --skill scan-sweep --outcome <o> --difficulty <1-5> \
  --provider <claude|openai|xai|qwen|google|other> --model <your model id> [--effort <level>] \
  [--tokens-est <n>] --result "<one sentence>" --comment "<self-reflection>"
```

Otherwise write the line yourself: `{"ts":"<ISO, UTC Z>","skill":"scan-sweep","outcome":…,
"difficulty":…,"provider":…,"model":…,"effort":…|null,"tokensEst":…|null,"result":…,"comment":…}`.

- `outcome`: `shipped` (the goal landed) / `partial` / `no-op` (ran correctly, nothing to
  do) / `parked` (designed or staged, deliberately not landed) / `failed` / `aborted`.
- `difficulty` rates the task as this run met it: 1 trivial - mechanical; 2 routine - the
  method as written; 3 demanding - real judgment calls or one detour; 4 hard - dead ends,
  rework or an operator course-correction; 5 at the edge - partial or failed on the merits.
- `model`/`effort` as your harness states them (`null` effort when you cannot see it).
  `tokensEst` is the drop in the harness's remaining-token counter since this skill was
  invoked, or `null` (with `log-run.mjs`, omit `--tokens-est`); exact figures are measured
  later from transcripts - never guess one.
- `result` is one line (max 240 chars). `comment` (max 2000) is the self-reflection a
  reviewer reads: what worked, what the method made harder, where its instructions were
  wrong, missing or ignored. No filesystem paths or email addresses.
- Never read run logs during a run. They are evidence ABOUT this skill for its reviewer;
  an executor that reads its own diagnosis contaminates the next measurement.

**Project learning.** Only when this run produced an observation that would change how a
future run behaves. A run that went as the method describes writes nothing: an entry that
restates the procedure, records "no issues", or repeats the task is a defect, not a
deliverable. When there is such an observation and local edits are within scope, put one
dated line in the overlay this skill's `## Project overlay` section names, under
`## Skill improvement log`. **Write only into an overlay that already exists.** If the
project has none, put the observation in the response instead - creating a new tracked
file for a reflection is scope the task did not ask for, and a reader who never asked for
the skill has to review it. If the overlay is a structured config (YAML, TOML, JSON),
record the note as comments so the file keeps parsing, or use the response.
Use a supplied memory contract only when its destination and writes are authorized.
Keep project details out of the shared method.

**Method learning.** Identify the installation before editing anything. A local
`.ai/registry-installation.local.json` receipt can identify development versus release,
the registry revision, and selected skill versions. Verify any link's actual target;
do not assume a skill directory is a writable registry link.

- For a pinned release, marketplace cache, ordinary copy, or unknown installation,
  keep a proposal in the project overlay or response. Do not edit the installed method
  or silently relink it. Adoption and rollback are explicit installation operations.
- For a development link, edit the registry only when that checkout is already within
  the accepted task scope. Otherwise report a proposal. Authorized changes belong in
  the source checkout, followed by its gates; commit only when the task authorizes it.
- Record an actual lesson in `LESSONS.md` against the version **used**:
  `## <version-used> - <YYYY-MM-DD> - <project-name>` and concise bullets. A proposal
  must be labeled as such; structural checks are not evidence of field effectiveness.
- Applied skill changes require a version bump: patch for wording, minor for a step
  refinement, major for method redesign. A lesson alone needs no bump. Shared stamped
  clauses are edited in the registry's `docs/skill-clauses/` and regenerated with
  `scripts/apply-skill-clauses.mjs`, never patched in individual installed skills.

**Domain learning.** Follow `## Knowledge sync` when present, within the same scope
and privacy boundaries. A method lesson and a domain knowledge lead are different
artifacts; do not fabricate either to fill a reflection quota.
<!-- /clause: skill-reflection -->

## Model choice (bake-off 2026-09-01, pof / harness-autonomy)

No pin. Fable built twelve fixes including a feature (durable-sidecar status GET) and junctioned the package's node_modules to run its own gate; Opus built six, all defensive, including the two most severe defects of either run (a self-heal re-verify under a tenth of the gate's buffer; a prior session's output replayed as instruction into a permission-free session), refused to manufacture a gate it could not reproduce, and marked its snapshot degraded. The operator merged both. Fable for throughput on a `--one` round; Opus when the context is a control surface for autonomous execution.

Files in this skill

  • SKILL.md76 KB
  • references/ab-lane.md9.3 KB
  • references/challenge.md19.1 KB
  • references/evidence.md8.8 KB
  • references/lenses.md16.8 KB
  • scripts/approvals.mjs7.4 KB
  • scripts/coverage.mjs10.8 KB
  • tests/coverage.test.mjs5.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in testing →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.