Skip to content

Latest commit

 

History

History
463 lines (333 loc) · 126 KB

wrap.md

File metadata and controls

463 lines (333 loc) · 126 KB

wrap: which verb for which situation

wrap is the landing subsystem. The entrypoint is bin/wrap in this repo, or ~/.claude/dwarves-kit/bin/wrap once installed. It forwards to lib/wrap/wrap.sh, which owns the verb grammar. The commands/wrap.md file is the session-close playbook that calls these verbs; this page is the lookup.

Each row below was read from the verb's source in lib/wrap/.

Rules that apply to every verb

  • wrap --help prints the whole usage. wrap <verb> --help prints that verb's usage lines and exits 0.
  • A <repo> or <worktree> argument is a filesystem path, resolved from the current directory. A bare repo name that is not a directory there fails with is not a git repo. Pass an absolute path.
  • A bad call exits 64. A write that fails inside a verb exits non-zero and names the step.
  • A verb never switches a branch in the shared checkout and never force-pushes.

Verb by situation

Situation Run What the code does
Start work on a new branch, main checkout is dirty or shared wrap start <repo> <branch> Fetches the default branch, creates <repo>/.claude/worktrees/<slug> on the new branch, prints only the worktree path on stdout. <slug> is the branch name after its last /.
Same, and move my uncommitted edits across wrap start <repo> <branch> --carry [<path>...] Stashes the main checkout's edits under a unique name, applies them in the new worktree, drops that stash on a clean apply. With paths, only changes under them land; files staged outside them stay in the main checkout only. A failed stash push prints git's error and exits 2; a conflict keeps the stash and exits 2.
Ship a small docs or content change from a dirty shared checkout in one call wrap ship <repo> <branch> --carry <path>... --message-file <file> [--title T] [--body-file F] [--proof-override "<reason>"] [--no-pull] Runs start --carry, stages exactly the named paths, commits with the file as the message, logs a proof override only when --proof-override gives the reason, then runs land. Every refusal start and land make still stops it, with their exit code. It refuses a bare --carry, an absolute or .. or glob path, a missing or empty message file, and --draft, --with-ci, --verify and --pick (64). It refuses before any write on an unusable gh, a PR template with no --body-file, or nothing dirty under the carried paths (1). It checks the HEAD is the new branch and not the default before the commit, and that the committed files stay inside the carried paths. It ends on one SHIP: line after land's LAND: line.
Add commits to a branch already on origin (an open PR's) wrap start <repo> <branch> --existing Fetches origin/<branch>, creates the worktree on a local <branch> tracking it at that tip, prints only the worktree path. A plain git push then extends the PR. Refuses a branch absent on origin, an existing local branch or path, a held index.lock and a failed fetch.
The branch already exists, locally or on origin none Without --existing, wrap start refuses with branch <name> already exists. An existing local branch refuses either way.
The worktree path already exists none wrap start refuses with <path> already exists.
The branch name is the default branch, main, or master none wrap start refuses. land and rebase refuse the same names.
An open PR of mine conflicts with the default branch wrap merge --apply --pr <N> <repo> Tries one re-merge of the default branch into the PR head and pushes it. It resolves a conflict only in a file the repo declares merge=union, or in CHANGELOG.md or a <repo>/docs/proof-of-done.md (or */docs/proof-of-done.md) that both sides purely appended to (no .gitattributes needed), and refuses any other conflict by name, pushing nothing. It uses a scratch detached worktree when no checkout holds the branch. If the head already holds the base, it opens a <branch>-squash replacement PR. Without --apply it only prints a note.
A stacked child PR conflicts after its parent squash-merged and was retargeted to the default branch wrap merge --apply --pr <N> --rebase-stacked [--verify <cmd>] <repo> Opt-in, the one history rewrite merge owns. Finds the merged PR whose last head sits under the child, runs git rebase --onto origin/<default> <that head> in the checkout that holds the branch (clean, at the PR head) or a scratch worktree, runs --verify, then pushes the PR's own branch with --force-with-lease at the head the gates read. It refuses by name and touches nothing on a rebase conflict (the conflicting files are printed, the rebase is aborted), a fork PR, an armed auto-merge, open dependents on the branch, a moved head, or a default-named branch. Then it gates and merges as usual.
A PR's new head reports no checks on a repo with a ci label wrap merge --apply --pr <N> <repo> Labels the PR with the same _ci_label_sync and _ci_checks_wait that land uses (remove and add again when the label predates the head), waits for the runs, re-reads, and gates. A repo without the exact ci label is untouched. A label that will not set exits 2 and merges nothing. Without --pr the label step stays behind --with-ci.
Merge only after every check finished wrap land <worktree> --with-ci, wrap merge --apply --with-ci --pr <N> <repo> On a repo with no ci label it still waits: it holds while GitHub registers the runs (300s for a workflow that runs on every PR, 30s for a filtered one), then until none is pending, and merges only when none failed or was cancelled. A failed, cancelled or timed-out check, or no check at all where a workflow runs on every PR, exits 2 with the PR left open. A repo with no pull_request workflow has no CI and merges at once. merge also waits for a PR the sweep read with a check still running and none failing (a head seconds old, a rebase just pushed): it prints waiting for the pending checks on #<N>, holds to KIT_WRAP_CARRY_CHECKS_SECS, then re-reads and gates the same head; a head that moved refuses, a bound that runs out prints SKIP #<N>: checks still pending after <N>s; left open and exits as any other skip does (4 under --pr, 0 for the bare sweep), and a PR with a failing check skips at once with no wait, as it does without --with-ci.
My branch sits in a worktree and is behind the default branch wrap rebase <worktree> Rebases onto origin/<default>. It resolves only a regenerated file, or a CHANGELOG or <repo>/docs/proof-of-done.md (or */docs/proof-of-done.md) both sides added to, and aborts on any other conflict. It never pushes; the history changed, so the push needs --force-with-lease.
The worktree branch is committed and I want it merged wrap land <worktree> Pushes the named branch, opens or adopts the PR, squash-merges, verifies the tree, fast-forwards the main checkout, removes the worktree, deletes the branch. With no PR under the branch's name it adopts your one open PR whose head commit equals the worktree tip (nothing pushed, adopted #<n> by head sha (branch <name>), that branch deleted on origin) and refuses when two or more match. There is no dry run. Every run ends on one LAND: line on stdout (read it with | tail -1): merged #<n> (<sha7>) pull=<ok|blocked|skipped> worktree=<removed|kept>, already landed (<proof>) pull=.. worktree=.., draft #<n> opened, or refused (<step>, exit <rc>). The refusal text stays on stderr and the exit codes are unchanged.
The branch already has an open PR wrap land <worktree> Adopts that PR and keeps its title and body. It refuses with 2 or more open PRs, a PR by another author, or a base other than the default.
Land a branch while another session is live in the main checkout wrap land <worktree> --no-pull Same promise as merge --no-pull and apply --no-pull: never writes the main checkout. It still merges, verifies the tree, deletes the origin branch, and removes the worktree and local branch. It prints SKIP pull: --no-pull in place of the fast-forward.
Land a branch but do not merge wrap land <worktree> --draft [--title T] [--body-file F] Pushes the named branch, opens or adopts a draft PR, prints the URL and the proof block, and stops. It never marks the PR ready, merges, tidies, pulls or writes a Ship record, and the worktree stays. It refuses an already-landed branch, an open non-draft PR, a new PR with no proof and no --body-file, and a ship-gate block. It exits 64 with --with-ci, --verify or --no-pull.
Land several finished worktrees wrap land <worktree> <worktree>... [--with-ci] [--no-pull] [--verify C] Lands them strictly one at a time, in argument order, each through the same single-worktree path. Before every land after the first, a never-pushed branch is rebased with wrap rebase (a branch already on origin is left alone, and a CONFLICTING PR takes land's own merge-in). It stops at the first non-zero land, prints STOPPED at <worktree> with the LAND: line, lists the worktrees not run, and exits with that land's code. It ends on a == land summary table, one <worktree> LAND: ... row each (LAND: not run for the rest), so | tail reads the outcome. --verify applies to each worktree as for one. --title, --body-file and --draft exit 64, naming the flag, as does an unusable path (checked before any land). One worktree behaves exactly as before.
See what merge would do wrap merge <repo> Dry run. Prints eligible #N or SKIP #N <reason> for each of my open PRs, then dry run; pass --apply to merge one PR.
Merge one green PR of mine wrap merge --apply [--pr <N>] <repo> Squash-merges exactly one PR per call, pinned to the head it gated. It takes exactly one <repo> path. Only PRs I authored count; --pr naming another author's PR is refused. With --pr, exit 0 means that PR merged; a SKIP or nothing eligible exits 4. After a merge it fast-forwards the checkout it was handed the way land does (_land_ff_pull, ff-only, never forced): pulled <repo>: <sha subject>. --no-pull skips it and prints SKIP pull: --no-pull; <repo> not pulled, run: wrap apply --apply --pull-only <repo>; a checkout off the default branch, or a pull that cannot fast-forward, prints PULL BLOCKED: ... with the same command. None of these changes the exit code. A dry run, --repo <owner>/<name> (no checkout) and a call that merged nothing never pull.
The PR is a draft wrap merge --apply --pr <N> <repo> Runs gh pr ready first. Without --pr, a draft is skipped.
Report repo state wrap scan <repo> [<repo>...] Prints ahead and behind counts, dirty files, worktrees, local branches, and my open PRs. It refreshes with git fetch --prune, so it is report-only for the worktree, not a no-write gather.
Gather the session-close facts as JSON or summary wrap session --json|--summary [--transcript <jsonl>] [--prs <owner/name#n>,...] [--mark-dir <dir> [--since <epoch>] [--self <worktree>]...] [--follow-mode lanes|all] [<repo>...] Read-only (except --mark-dir, which writes writer marks into the scratch directory before reading each repo). --json prints one wrap-session/1 document; --summary prints the same facts one per line. --transcript reads the target session and its subagent transcripts for repos, PR URLs, acted PRs, and the opening epoch; --prs adds named PRs read live in one batched GraphQL call. Per repo it gathers checkout state, active board rows, handoffs, origin and GitHub slug, own open PRs with check totals and gates, recent merge deploy state, sweep report, and planned writes. Neither sweep path fetches.
Re-check whether another writer is active wrap session --writers --check-mark STATE [--self WT]... [--text] <repo> Prints one wrap-writers/1 document: one row per worktree other than the session's own, except the main checkout, which is never excluded. Each row carries that worktree's index.lock state and HEAD-reflog identity compared with the mark. wrap session --writers --mark STATE [--self WT]... <repo> records the mark in scratch state. --since EPOCH remains the stateless fallback. --text prints the same facts as text.
Tidy a repo, preview first wrap apply <repo> Dry run by default. Prints WOULD ... lines. Add --apply to write.
Remove merged worktrees, all sessions wrap apply --apply --worktrees <repo> Removes every clean, non-detached worktree whose branch is proven merged, then deletes the branch. Other sessions' worktrees qualify too. A worktree holding uncommitted work (including untracked files when status.showUntrackedFiles=no), skip-worktree or assume-unchanged entries (including sparse checkouts), an initialized submodule, a gitlink with a .git on disk, or a non-empty git-dir modules/ directory, a non-regenerable ignored path (anything outside the build-cache list or an identical .claude/ copy under non-symlinked directories in the main checkout), an odd path, a status that fails or changes right before removal, or an unreadable check is kept with its branch.
Sweep every repo under one or more roots wrap sweep [--apply] [--worktrees] [--json] [--no-fetch] [<root>...] Discovers every repo at the root or depth 1 to 2 (<root>/*/ and <root>/*/*/), or reads wrap.sweep_roots when no root is given, locks each repo (${XDG_STATE_HOME:-$HOME/.local/state}/wrap/locks/<sha1>), and runs the apply cleanup logic in parallel. Dry run by default; --json emits wrap-sweep/1 on stdout and human lines on stderr, with deleted_tip carrying the full SHA of each deleted branch tip on removed rows (null otherwise). Runs wrap.workspace_rm (<cmd> <worktree> <repo>) after each worktree removal under --apply. --no-fetch (dry run only) skips the fetch and reads the refs on disk, for read-only callers such as wrap session. Exit 0 ok, 1 usage error, 2 repo error, 3 all locked.
Remove only my own worktrees wrap apply --apply --own <worktree> <repo> --own is repeatable and implies the worktree opt-in, so --worktrees is not needed. Unnamed worktrees are skipped. The local all-branches sweep and --archive-unmerged are skipped. The origin merged-branch sweep is scoped to the branches the named worktrees held (-- origin branches (own scope: N named branches):); plain apply and --worktrees sweep origin repo-wide. Stray carry and pull still run.
Tidy without pulling the shared checkout wrap apply --apply --no-pull --own <worktree> <repo> --no-pull without --own skips both the worktree sweep and the branch sweep.
Pull the default branch and nothing else wrap apply --apply --pull-only <repo> Cannot combine with --worktrees, --own, --archive-unmerged, --archive-worktrees, --tips-file, or --no-pull.
Archive stale unmerged or detached worktrees wrap apply [--apply] --archive-worktrees <repo> Opt-in, never with --own or --no-pull. A worktree idle at least wrap.archive_worktree_min_age_hours (default 72), unlocked, not busy, and holding nothing a removal would lose goes to origin refs/archive/<slug>-<date> (uncommitted files as a snapshot commit, create-only lease), then is removed with its branch. Needs lsof.
Adopt a repo into the kit contract wrap adopt [--apply] <repo> [<repo>...] Dry run by default. --body-file takes exactly one repo.
Write the activity line wrap log "<slug>: <one sentence>" Writes immediately and warns over 300 characters. One log serves every repo I wrap, so a call from a git repo other than the log's still writes the one log and prints wrap log: wrote <abs path> (repo <log repo>), outside the current repo <repo> on stderr, so the line is not taken for one in the current repo. From the log's own repo, its worktrees, or outside any git repo it prints nothing extra.
Get the step 7b flick second opinion wrap flick-7b < pairs Reads one <candidate-slug> <hit-name> <existing-verdict> pair per line on stdin, calls bin/flick once, and prints one line: the text of the report's STATE row. It prints flick wrap-7b: off when decide.points lacks wrap-7b, and no pairs on empty input. It exits 0 on every path.
Wait for a push-deploy check wrap deploy-wait <owner>/<name> <sha> [--check S]... [--timeout N] Polls the commit's check runs. Exit 0 all success, 1 a run failed, 124 timeout.

Which verbs preview first

Dry run by default Writes at once
apply, merge, adopt (add --apply) start, land, rebase, log, stage

session writes no repository state at any setting; --mark writes only the scratch state file it is handed. scan writes no working-tree or branch state, but its refresh does run git fetch --prune; do not use it as a read-only gather.

Source files

Verb File
scan lib/wrap/wrap-scan.sh
session lib/wrap/wrap-session.sh
apply lib/wrap/wrap-apply.sh
merge lib/wrap/wrap-merge.sh
land lib/wrap/wrap-land.sh
start lib/wrap/wrap-start.sh
rebase lib/wrap/wrap-rebase.sh
adopt lib/wrap/wrap-adopt.sh
log, stage, knowledge-root lib/wrap/wrap-log.sh
deploy-wait, default-branch, follow-mode lib/wrap/wrap-deploy.sh
flick-7b lib/wrap/wrap-flick.sh

wrap.sh sources these helper files, which own no verb: wrap-common.sh (shared state), wrap-carry.sh (stray-line and autoland carry), wrap-pull.sh (the pull and union carry-back), and wrap-ci.sh (the ci label sync and checks wait). report-lint.sh is a separate lint for the wrap report's Needs you section.


Session command reference

The operational detail below is the reference form of /kit:wrap. The command file keeps only the execution path; read this when changing a rule or diagnosing a verb.

Process

Bracket the phase for timing before starting: bash lib/gate/gate-ledger.sh outcome <rid> wrap start.

Run the steps below once per repo the session touched (the current repo when the operator names none). Positional repo arguments; wrap never discovers touched repos on its own (Out of Scope). Three arguments are not repos: the word distill (or --distill) is the distill switch below; the word wide (or --wide) widens the report's Left alone section from this pass's own residue to the full scan residue (step 9); and the word follow (or --follow-through) runs step 10 in lanes mode for this run, or in all mode when the word all directly follows it (/kit:wrap follow all). all is an argument only right after follow; anywhere else it is a repo name. All of them are consumed, wherever they appear, before the repo list is read. bin/wrap scan/apply also take a repeatable --under <root> that appends every immediate git child of <root>; a bare --under with no directory expands to every root in the wrap.roots knob instead, or exits 64 naming the knob when it is empty.

The distill switch. This command has two halves. The LANDING half is steps 0 through 6, 8, and 9: board rows, commit, merge, deploy check, tidy, pull, activity line, retro, report. The DISTILL half is the pre-step-0 candidate scan, both seams of step -1, and all of step 7 (DEBT marker, candidates, memory notes, and the drain). Resolve the switch once, first:

. lib/config/kit-config.sh
kit_config_get_root wrap.distill true

The distill half runs when that value is true, or when the invocation carries distill, or when the operator's ask says to distill. It does not run only when the operator's own kit.toml sets distill = false and the invocation names neither distill nor an ask to distill: then skip the scan, skip both seams, skip step 7, report **Built:** SKIPPED: distill off and **Seam:** SKIPPED: distill off, and put one FYI bullet of the STATE kind naming the knob and the argument that turns it back on (the operator meets the same skip next wrap, which is what that lane is for). Distill runs by default because operators asked for it every session, not as a special-cased extra. /kit:wrap with no distill word still lands the session (the LANDING half, steps 0 through 6, 8, 9), whatever the switch resolves to; the switch decides only whether the DISTILL half also runs this pass. An operator who wants landing-only every time sets distill = false in their own kit.toml. The retro at step 8 is landing, not distill: it fires only when a spec cycle shipped, and it reads the run ledger rather than the session. The knob resolves root-only, same as the autonomy knobs below, because the distill half writes to home repos.

A third value, harvest, hands the distill half to the transcript harvest sweep, per host. The knob may sync across machines through the operator kit.toml, so it resolves against the host's own sweep marker -- the sweep is active only where <state>/sweep/installed exists AND harvest.enable is true (both read root-only, never from a project .kit.toml):

_sweep_state="${HARVEST_STATE_DIR:-$(bash "${DWARVES_KIT:-$HOME/.claude/dwarves-kit}/lib/config/data-path.sh" path state harvest)}"
_sweep_active=0
if [ -f "$_sweep_state/sweep/installed" ]; then
  case "$(kit_config_get_root harvest.enable false | tr 'A-Z' 'a-z')" in
    true|1|yes|on) _sweep_active=1 ;;
  esac
fi

With harvest and _sweep_active=1: the LANDING half still runs end to end, but the DISTILL half is the sweep's job on this host -- read no seam key, skip the scan, skip step 7, report **Built:** SKIPPED: distill runs in the harvest sweep and **Seam:** SKIPPED: distill runs in the harvest sweep, and add two FYI STATE rows: one naming the knob (STATE wrap.distill resolves to harvest on this host; in phase 1 the sweep reports candidates and builds none), and one carrying the sweep's own status so the newest report gets seen, from python3 hooks/harvest_sweep.py --status (STATE newest sweep report: <path>, candidates=<n>, queued=<m>, or STATE newest sweep report: none when the sweep has written no report yet). With harvest and _sweep_active=0: the knob resolves as true for this host -- the distill half runs as usual -- and the report carries a STATE row saying the harvest sweep is not installed on this host. The explicit word still wins: an invocation carrying distill runs the distill half even on an active host, and its FYI carries a STATE row saying the harvest sweep will also see this session (it is harvested on the next scheduled run, so the distillation is a bonus, not a duplicate).

Scan for candidates before step 0, act on them at step 7b. (Distill half; skip when the switch is off.) Step 7b's scan reads the target session and nothing else (the next paragraph covers a target that is another session), and it is the one step whose input degrades with every step that runs before it: six steps of scan, merge, and pull output later, the model is reasoning about branches and has lost what it did four times by hand at 14:00. So the scan runs FIRST, ahead of even the seams: write the candidate list (label, what was repeated or written, how many times) to the scratch file the step 9 report will use. Step 7b then runs precedent and acts on that list, never on a fresh recollection. The old standalone closeout ran this scan as its first move, before any landing, and produced an enhancement to an existing tool most sessions; the same scan at step 7 produced none across its first two weeks, because by then there was nothing left in context to scan.

Wrapping another session. The operator often runs this command from a fresh session to land another session whose context is full. A typical ask is "the session 'X' is full, help me run kit:wrap for it". The invocation targets another session when it names a session, a chat or tab name, or a session id. It also targets one when it says the session is full or asks to wrap it for another session. Then "the session" in every step below means the target and its pickups, never the wrapper. The wrapper's own context is nearly empty. A scan of it reports NOTHING: no candidates for hours of real work. Two of three such wraps on 2026-11-15 and 2026-11-16 did exactly that. In one, after the operator pushed back, a transcript miner found 8 candidates in the 180 MB transcript. So the scan, and every step that needs session memory, reads the target's transcripts:

  1. Resolve the target. A name from /rename lives only in the target's own transcript. So run bin/session recall --name "<name>" --all --json first. Each row's file is a lead transcript, newest first. A plain query never finds a session by that name, because it matches only prompts that quote it, and those are the wrappers. With no name, or no hit, run bin/session recall "<distinctive work terms>" --project <repo-name> --sessions --json. A chat tab name often appears only in the pickup or handoff prompt. So also search by the repo, branch, or PR the session worked on. Confirm with bin/session recall --tail <id>, and check its hint against git or gh.
  2. Collect the transcripts. A lead transcript is ~/.claude/projects/<project-slug>/<id>.jsonl. Its subagent transcripts sit beside it as <id>/subagents/agent-<agent-id>.jsonl, each with a .meta.json description. bin/session recall --subagents <id> lists them with absolute paths. A session that picked up from the target is part of the same work. Search its id prefix and its handoff file name the same way as step 1. Then add that session's transcripts and subagents.
  3. Dispatch one read-only miner. Use a Sonnet subagent that writes nothing and hand it every transcript path. It mines with jq and rg, streaming each file and never loading one whole. It returns the candidates of the three kinds step 7b defines: a procedure run three or more times by the lead or its subagents, a one-off general script, and a deferred enhancement. It adds repeated tool errors. Each candidate carries a label, what repeated, a count, and the transcript line as evidence. It also returns the landing facts: the repos, branches, worktrees, and PRs the target opened or touched. The brief quotes transcript text as data, and the report carries no secret-shaped string.
  4. Keep the transcript out of the lead. The lead writes the miner's candidate list to the scratch file as above. The lead never reads a transcript into its own context. Only the miner's report enters it.
  5. Derive the landing from the same facts. The What happened bullets, step 1's board rows, step 3's PR list, and step 5's --own worktrees come from the miner's landing facts and bin/wrap scan <repo>. They never come from the wrapper's recollection. Confirm each PR with gh pr view and each branch with git log. Name each repo in the facts as a positional argument.

With the distill switch off, still run steps 1 to 3 for the landing facts and leave the candidate kinds out of the brief.

Step -1: the seams

(Distill half. With the switch off, read no seam key, run no seam, and report **Seam:** SKIPPED: distill off; the autonomy knobs below are still read.) An operator can hang one skill on each side of this command. Read both keys first:

. lib/config/kit-config.sh
kit_config_get_root wrap.before ""
kit_config_get_root wrap.after ""

An empty value means no skill runs on that side, which is the default for both. A named skill runs at its side's position and its report lines fold into step 9's report after the FYI line. Both keys resolve with kit_config_get_root, so each comes from the operator kit.toml or the kit-root kit.toml and never from a project .kit.toml: they name code this command runs, and a project toml rides inside an untrusted PR.

Pick the side by what the skill needs. wrap.before runs ahead of step 0, so it sees the session's uncommitted state; a skill that must read a working tree before wrap commits or tidies it belongs there. wrap.after runs after step 8 and before the step 9 report, so the landing is already done; a skill that only reads what the session produced belongs there. after is the right side for a knowledge flush, and the reason is the operator's time: a flush on the before side greps every note store while the git work waits behind it, so the landing an operator asked for arrives last. Nothing in a flush informs a board flip or a merge, so nothing is gained by paying for it first. A seam skill that writes a file into a repo obeys step 2's rule: no commit on a checkout sitting on the default branch, leave the write for the next feature PR.

Report the outcome, whichever side ran. Step 9 owes a **Seam:** line and the lint fails without it. A seam that never ran because no key was set, and a seam that was silently skipped, are different facts; the **Built:** line exists for exactly this reason at step 7b, and the same hole is here. A named skill that fails to run is SKIPPED: <why>, never silence.

Read the autonomy knobs in the same call, once, and carry the values through the pass:

. lib/config/kit-config.sh
kit_config_get_root wrap.merge_own_prs true
kit_config_get_root wrap.tidy_worktrees true
kit_config_get_root wrap.delete_merged_remote_branches true
kit_config_get_root wrap.carry_stray_lines true
kit_config_get_root wrap.autoland_carry false
kit_config_get_root wrap.build_candidates true
kit_config_get_root wrap.build_lanes "tiny"
bin/wrap follow-mode [lanes|all]   # lanes when the invocation says follow, all for follow all

Each governs exactly one step: merge_own_prs step 3, tidy_worktrees, delete_merged_remote_branches, carry_stray_lines and autoland_carry step 5, build_candidates step 7b, follow_through step 10. build_candidates, build_lanes, and drain_staged size a step inside the distill half, so they govern nothing while the distill switch is off. The shipped defaults are true for the first five, so wherever those steps run, wrap acts. autoland_carry ships false: it merges wrap's own carry branches into the default branch, so the operator turns it on. follow_through ships "off" because step 10 starts new work after the operator has their report; bin/wrap follow-mode resolves it with the invocation override and prints <mode> <lanes>, and any value but off, lanes, or all prints one line naming the knob and the allowed values and runs as off. Every one of them authorizes a write, which is why each resolves with kit_config_get_root and never from a project .kit.toml. A false turns that step's action into a report line; it never turns the step off, and it never relaxes a refusal the tools make on their own. Name every knob read as false in the report's FYI, as a STATE row, so a step that stayed its hand says why.

wrap.build_lanes sizes step 7b rather than authorizing it: a space-separated list of the lanes step 7b builds inline. Step 10 reads the same list, without full, as the lanes it builds after the report. The default "tiny" is today's behavior. full is the one lane the list cannot buy an inline build for; it is reported instead. It resolves root-only for the same reason as the three above, because widening it widens what wrap writes.

Step 0: concurrent-writer check

Foreign activity in a repo's checkout means either signal is present: a worktree reflog identity changed since the session's writer mark, or an index.lock present on a row. Record the mark before the start gather reads the repo with bin/wrap session --writers --mark <state> [--self <wt>]... <repo>, passing one --self for every worktree the session owns. Re-check before every write with --check-mark <state>, and record the mark again after each own write. The main checkout is never excluded, even when the wrap runs there; its lock always counts, and its reflog is judged against the mark. A missing, invalid, or unwritable mark is foreign activity. --since remains the stateless fallback. Run bin/wrap scan <repo> for the checkout, ahead/behind count, dirty files, worktrees, branch verdicts, and the operator's own open PRs.

  • bin/wrap scan <repo> is report only; it never writes.
  • On foreign activity: STOP every write to that repo's MAIN CHECKOUT for the rest of the pass, and report what was found. The stop protects the checkout's working tree, index, and HEAD, so it covers exactly the steps that write one of those: the board flip (step 1), the commit (step 2), bin/wrap land without --no-pull (its closing fast-forward pull writes the checkout), the pull in step 5 with its wrap.pull_past_dirty stash and pop, the stray-commits move of the default branch, the activity line (step 6), and a seam write into that checkout. Do not touch a dirty file this session did not write.
  • The stop does NOT cover the merge or the own-worktree tidy, because with --no-pull neither writes the checkout (merge without it fast-forwards the checkout after a verified merge). Step 3 still merges, one call per session PR, as bin/wrap merge --apply --no-pull --pr <n> <repo>: the merge is server-side and verified by fetch, and --no-pull is the verb's promise never to write the main checkout. It SKIPs any PR whose head branch the main checkout holds, whatever its state (SKIP #<n>: head <branch> is checked out in the main checkout (--no-pull)), because that branch is the live foreign session's own work: a re-merge of it would write the main checkout's HEAD and tree, and merging it at all lands mid-iteration work. Such a PR stays OPEN. Do not name a draft with --pr: --pr on a draft marks it ready and merges it, which lands a full-lane draft with no design review.
  • A hand-made worktree in a stopped repo lands as bin/wrap land <wt> --no-pull: --no-pull is the same promise merge and apply make, never write the main checkout. It still pushes, opens or adopts the PR, merges, verifies the tree, deletes the origin branch, removes the worktree and deletes the local branch, but skips the closing fast-forward with SKIP pull: --no-pull, so the main checkout's HEAD and tree stay as they were and the scan's behind count shows it stayed behind. It does not wait for checks the way merge does, so use it only for a branch whose own checks the session already read.
  • Step 5 still removes the session's own worktrees and branches and sweeps the origin branches those worktrees held, as bin/wrap apply --apply --own <wt>... --no-pull <repo> (dry run first). The tidy under a stop is --own only: without --own, --no-pull skips the worktree sweep and the all-branches sweep (SKIP worktree sweep: --no-pull needs --own, SKIP branch sweep: --no-pull needs --own), because an unscoped sweep reaches other sessions' merged worktrees and branches. --no-pull skips the pull and the stray-commits move (SKIP pull: --no-pull, SKIP stray commits: --no-pull) and pushes nothing for stray lines: it prints SKIP stray lines: --no-pull (N lines in <file> stay local), makes no wrap/stray-* branch, and leaves the lines for the next unstopped wrap, because the dirty lines may be another live session's in-flight work. A session that never had a worktree has nothing to name, so it skips the tidy under a stop. Two more limits: a held index.lock still makes apply skip every local removal (the verb guards each one on that lock), so the tidy runs past the reflog signal only; and a branch in a hand-made worktree waits for bin/wrap land until the writer clears, so list that worktree and branch under Left alone.
  • The stop does NOT cover a build in an isolated worktree: step 7b and step 10 create theirs with bin/wrap start <home> <branch> off origin/<default>, and such a build never writes the main checkout's working tree, index, or HEAD, which is all the stop protects. A foreign writer in the main checkout is no reason to leave an in-lane candidate REPORTED; two real sessions did exactly that and the operator had to ask for the builds by hand. wrap start still refuses by name while an index.lock is held, so that signal blocks the build through the verb's own refusal. The PR such a build opens merges as in step 3, under the rules above.
  • The check runs again, repo by repo, immediately before every write step. A repo that goes foreign between checks drops out of the stopped writes above for that repo only; its merge and own-worktree tidy keep running.

Step 1: board rows

For every backlog row whose source of truth this session closed, flip it through THAT repo's board wrapper, <repo>/_meta/board set <ID> shipped|parked|dropped "<PR or SHA>" (or <repo>/board set where the wrapper lives at the root); with no wrapper, bin/board set <ID> <state> --backlog-file <repo>/_meta/BACKLOG.md. A bare bin/board set without --backlog-file targets the kit's own board, never the wrapped repo's. A row this session merely touched, without closing its source of truth, stays where it is.

Step 1b: handoffs

For each handoff this session started from or worked, and each handoff bash lib/session/handoffs.sh list --repo <repo> --limit 0 marks DEAD: check every open item against git log and gh pr view, never memory. A DEAD handoff skips the check, because the board already says it is closed.

  • Every item landed, decided, or tracked in a durable home (a merged PR, a roadmap, a board row): archive it with bash lib/session/handoffs.sh archive --repo <worktree> <file>. A tracked file moves with git mv inside the session's feature-branch worktree, so the move rides step 2's commit and the PR; the verb refuses a tracked file on the default branch. An untracked file moves with mv -n inside the checkout that holds it. The commit body names the evidence per item, such as the PR that landed it.
  • Any item left (a credential, a paid top-up, a judgment call, a dated check that has not run): leave the file open and update its State section on the same branch.
  • Nothing to carry the move (no session branch, or a step 0 stop on the main checkout): leave the file open and say so in the report. Never delete a handoff.

Step 2: commit by name

Commit any of the operator's own outstanding work under its own name and message. This step is a command-layer judgment call, not a verb: wrap owns no commit write. Skip it when nothing of the operator's own is outstanding.

Never commit on a checkout that has the repo's default branch checked out. Nobody can push that commit through a PR, so it sits on a local main until someone drains it by hand; one measured machine had accumulated 29 such commits. Leave the file uncommitted for the next feature PR to carry, or move the change onto a branch and commit it there. The same rule binds every file the pass writes: a board row at step 1, an activity line at step 6, anything a seam skill flushes. board set, wrap log and wrap stage each print one warning line when they write into such a checkout; that line is this rule firing, not an error, and the file they wrote is correct.

Step 3: merge the operator's own PRs

wrap.merge_own_prs false: merge nothing, report every own open PR as OPEN under Shipped, and say in FYI, as a STATE row, that the knob is off. Steps 4 onward still run.

Otherwise re-run the step 0 check first. Then merge only THIS SESSION's PRs, one call per PR: bin/wrap merge --apply --pr <n> <repo>. The session's PRs are the ones it opened: from its own branches and worktrees, its step 7b and step 10 builds, and its own stray carries. Never run the bare bin/wrap merge --apply <repo> by default: it merges the first green PR the operator authored in the repo, which can be another live session's work. The bare form runs only when the operator asks to merge all of their PRs. Every other own open PR is listed under Shipped as OPEN and left alone. A repo that is stopped adds --no-pull to each call (bin/wrap merge --apply --no-pull --pr <n> <repo>) (step 0 says what it skips); a hand-made worktree lands through bin/wrap land <wt> --no-pull.

  • wrap merge never runs twice for the same PR in one call; call it again for the next PR.
  • After a merge that verified, bin/wrap merge --apply fast-forwards the checkout it was handed, the same pull land makes (pulled <repo>: <sha subject>). A stopped repo's --no-pull skips it, and a checkout off the default branch or a pull that cannot fast-forward is left as found; each prints one line ending run: wrap apply --apply --pull-only <repo> and none changes the exit code. A dry run, --repo <owner>/<name> and a call that merged nothing never pull.
  • With --with-ci (or KIT_WRAP_CI_ON_MERGE=1) a PR whose only blocker is a check still running is waited for, not skipped: waiting for the pending checks on #<n>, then the same head is gated again. A wait that runs out prints SKIP #<n>: checks still pending after <N>s; left open and exits like any SKIP (4 under --pr, 0 for the bare form); the autoland carry, which waits itself, never gets a second wait; a failing check skips at once.
  • In the session landing pass, a PR left OPEN for pending checks has those checks named in the first report. It enters step 10 as an OPEN-PR item, so the handoff is work follow-through owns rather than prose.
  • bin/wrap merge --apply --pr <n> exits 0 only when that PR merged; a SKIP, a refusal or nothing eligible to merge. leaves it open and exits 4, so a chained && <deploy> never fires on an unmerged PR (the bare form, with no --pr, and a dry run still exit 0 on nothing to merge).
  • A repo whose committed .kit.toml sets [merge] command merges through that command (<command> <pr>, run in the checkout) instead of the plain squash, in wrap merge, wrap land, mega-merge and stack-merge alike. Its refusal is final: report its own message under Needs you, leave the PR open, and never merge it another way. By --repo <slug> there is no checkout, so the verb refuses.
  • A repo with no local checkout merges as bin/wrap merge --apply --pr <n> --repo <owner>/<name>: the same gate, the settle wait and the squash through gh alone, verified by gh (state MERGED, merge commit on the default branch via gh api); it skips the re-merge push, the squash fallback, the tree verify and the pull and says so, and it never marks a draft ready.
  • After its own re-merge push, merge waits for GitHub to recompute mergeability on the pushed head (up to KIT_WRAP_SETTLE_SECS, default 60) before it judges CONFLICTING, and refuses a head it did not push. A branch no local checkout holds re-merges in a scratch detached worktree that is removed afterwards. When the wait ends with GitHub still on the pre-push head and origin holding exactly the pushed commit, merge closes and reopens its own PR once so GitHub re-reads the head, then waits and gates again; it never does this for a draft, a fork PR, a PR that is not OPEN, a PR with auto-merge armed, or when dependents are open. The close fires the repo's pull_request closed workflows and webhooks, and the reopen fires reopened, so CI may restart. A failed reopen, or a failed close whose state cannot be read, exits 2 with the exact gh pr reopen command; an interrupt inside the close window reopens the PR and exits 130. With both waits the worst case is about twice KIT_WRAP_SETTLE_SECS plus 15s (about 135s at the default), longer than a 120s tool-call timeout, so run it with a longer timeout or in the background.
  • A conflicting own PR whose pushed head already carries the default branch (GitHub reports CONFLICTING even though git merge resolved the union-marked files locally) recovers through a squash-equivalent fallback: wrap commit-trees the merged tree onto origin/<default>, pushes it to a <branch>-squash branch, opens a replacement PR under the original title and body, and merges it through the same squash + tree-verify path. The report names the superseded PR, which stays open for a manual close.
  • A branch committed in a HAND-MADE worktree (one the EnterWorktree tool did not create, typically a foreign repo) lands through bin/wrap land <worktree> instead, in a stopped repo as bin/wrap land <worktree> --no-pull, which skips the closing fast-forward pull (SKIP pull: --no-pull) because that pull writes the main checkout and still removes the worktree and branch: it pushes the named branch, then opens the PR with --head, or adopts the operator's own already-open PR for that branch, or, when no PR carries the branch's name, adopts the operator's own open PR in the same repo whose head commit equals the worktree's tip (a subagent that pushed under a renamed branch while its worktree kept the default name): exactly one match is adopted with nothing pushed, prints adopted #<n> by head sha (branch <name>), lands through the same gates, and at the tidy deletes that adopted branch on origin and no other; two or more matches refuse by name with nothing touched (exit 2); a match by branch name always wins, a fork's PR or another author's never counts, and a by-head PR that turns CONFLICTING is left open for wrap merge --apply --pr <n> <repo> because the merge-in cycle would push the wrong branch; on a repo carrying a ci label adds it (or removes and re-adds it when it predates the head) and waits for the runs the label starts, since label-gated CI runs nothing for an unlabeled PR, before that merge, on a repo whose workflows trigger on pull_request, waits for the PR's checks to register (30s, or KIT_WRAP_LAND_REGISTER_SECS (300) when no paths or labeled filter guarantees a run) and finish (the completion bound is KIT_WRAP_CARRY_CHECKS_SECS, else the target repo's [wrap] checks_secs, else 300) and refuses the merge (PR left open, exit 2) when one failed, is still pending at the bound, or cannot be read, and a NEW PR on a repo carrying a GitHub PR template refuses before the push unless --body-file is given, with no --body-file the PR body is built from the branch's proof-of-done file (the title, then ## Proof of done with the file's content, image links pinned to the head sha; an adopted PR keeps a body of its own and takes this one only when it has none), a land that merged ends on a PROOF OF DONE block (the proof file, the PR link, the captured output lines) and then one LAND: line (merged #<n> (<sha7>) pull=<ok|blocked|skipped> worktree=<removed|kept>; already landed (<proof>), draft #<n> opened and refused (<step>, exit <rc>) for the other outcomes), so | tail -1 reads the result, then squash-merges it as its own call, verifies the tree the same way, fast-forwards the main checkout (skipped under --no-pull), then removes the worktree and deletes the branch. A branch whose content is already on the default branch (its own PR squash-merged, or the same net change landed under another commit) is recognized before anything is pushed: land reads the same proof apply's worktree tidy trusts, reports already landed: <proof>; nothing to push, no PR opened, and tidies (the origin branch delete, the pull, the worktree and branch removal) without opening a second PR; a branch re-pushed with commits past what merged has no proof and lands as usual. That path refuses by name, touching nothing, when origin's copy of the branch differs from the proven local tip or cannot be read, when the tree or tip changed while the proof was read, or when an open PR for the branch still exists (reported next to the proof, never closed). bin/wrap land (and wrap adopt, which calls it) also refuses, before anything is pushed or opened, when the worktree holds a gitignored file under a directory the branch touches, because a clean checkout will not have it and tests that read it pass only here. An ignored directory that holds no file at any depth passes. It prints each path with LAND REFUSED and exits 1. Build output, tool caches, local config, and the kit's own state are always allowed; wrap.land_ignored_allow (root-only, the operator or kit-root kit.toml) adds entries, and a project .kit.toml is never read for it. A secret-shaped path (.env*, a key, a credential, a token) never gets a commit hint. An unattended loop (a wrap step 10 worker, a /goal loop, a mega-goal wave) stops on this refusal and reports it to a human: it never retries, commits the file, deletes it, or adds an allow entry by itself. Every land re-reads the tree and tip immediately before removing the worktree and leaves both in place on a mismatch, and an origin branch GitHub already deleted reports already gone from origin. A land whose own PR comes back CONFLICTING does not stop there: it merges origin/<default> into the branch inside the worktree, resolving a generated file through its generator and a pure-addition CHANGELOG union but refusing any other conflict, then re-gates and squash-merges the recovered PR. --verify <cmd> runs one caller command in the worktree between that merge commit and its push, only inside this cycle, and the string echoes as typed so a secret belongs in the environment, not the flag. A refusal names its reason and writes nothing; a PULL BLOCKED line means the main checkout stayed behind and the tidy still ran. With no --title given and no PR to adopt, land titles a fresh PR from the branch's first non-merge commit ahead of the default branch whose subject is not a docs/chore/test conventional type, oldest first -- never the branch tip -- falling back to the oldest non-merge commit ahead when every one is housekeeping; an adopted PR always keeps its own title regardless. Once the tree is verified, land also deletes that same branch on origin, leased to the SHA it pushed, unless an open PR still bases off it or wrap.delete_merged_remote_branches is false, either of which it reports on its own line without failing the land. Once the tree is verified, land also derives the landed branch's rid (the same rule gate-ledger.sh rid uses) and, only when that rid already has a run ledger (a grill/spec/etc already recorded for it) with no ship gate line yet, appends | GATE | ship | ran | shipping pr=#<n> via=land -- the via=land tag distinguishes it from a line hooks/ship-gate.sh itself gated (a literal push/PR-create), while step 8 below's anchored shipping pr=#<n> grep still matches it, so a spec cycle shipped through land still gets its retro. A hand-made land with no prior ledger writes nothing. A rid whose ledger already names this same PR skips as idempotent (e.g. /kit:ship already recorded it); a rid whose ledger names a different PR skips too and says so (a reused slug shared by an unrelated branch is never overwritten). A record failure prints one line, the captured error, and the exact manual command to run instead; none of these ever fail the land.
  • Several finished hand-made worktrees in one repo land as bin/wrap land <wt> <wt>... [--no-pull] [--with-ci] [--verify <cmd>], never in parallel (each land waits for CI, so parallel merges race). They land in argument order, each through the single-worktree path above; before every land after the first, a never-pushed branch is rebased with bin/wrap rebase. The run stops at the first non-zero land, prints STOPPED at <wt> and not run: ..., exits with that land's code, and ends on a == land summary table of LAND: lines. --title, --body-file and --draft refuse with 64 when given with more than one worktree. A rebase that moved HEAD is not re-tested by land; pass --verify or run the suite between the worktrees yourself.
  • The opening half of that same shape is bin/wrap start <repo> <branch>: it resolves the repo's detected default branch, fetches it, and creates <repo>/.claude/worktrees/<branch-slug> at origin/<default> on a new local <branch>, printing the worktree path as its only stdout line so a caller captures it directly. A dirty main checkout is never a refusal (the worktree is isolated; that is the point), but an existing path, an existing local or origin branch of the name, an unresolved default branch, and a failed fetch each refuse by name before any write. --carry [<path>...] moves the main checkout's own uncommitted edits, tracked and untracked, into that same worktree once it exists: a named git stash push -u (restricted to the given paths, or everything with none given), found by its own message and applied inside the worktree, dropped on a clean apply. With paths given, only changes under those paths land: a file staged in the main checkout outside them stays staged there and stays out of the worktree and the carried: line. Nothing dirty in scope prints nothing to carry and exits 0, the worktree already made; a failed git stash push (an unmerged index entry, say) prints git's own error and exits 2 with nothing carried; an index.lock held by another writer refuses by name and leaves the worktree in place; an apply conflict keeps the stash entry and names it instead of guessing which side is right. --existing starts from a branch already on origin (an open PR's branch) instead of refusing it: it fetches origin/<branch> and creates the worktree on a local <branch> tracking origin/<branch> at that tip, so a plain git push extends the PR. A branch absent on origin refuses by name, and an existing path, an existing local branch, a held index.lock and a failed fetch refuse as before; without the flag nothing changes. --pick <branch> (repeatable) folds worker branches into the new worktree: each branch's commits past its merge base with origin/<default> are cherry-picked in argument order before any --carry, a missing branch refuses by name before any pick, a branch with nothing to pick prints nothing to pick, and a conflict aborts that pick, names the files and the commits already picked, keeps the earlier picks, never resolves anything, and exits 2.
  • bin/wrap ship <repo> <branch> --carry <path>... --message-file <file> [--title T] [--body-file F] [--proof-override "<reason>"] [--no-pull] is the whole hand sequence for a small docs or content change out of a shared dirty checkout: wrap start --carry, git add of exactly the named paths, a commit with the file as its message, a logged proof override, wrap land. The override is logged only when --proof-override carries a reason; without it the ship-gate decides at the push. Every refusal start and land make still stops the run with that verb's exit code, and the verb removes nothing a refusal leaves. It refuses a bare --carry, a commit whose HEAD is not the new branch, and a committed file outside the carried paths. The run ends on one SHIP: line after land's LAND: line (SHIP: shipped #<n> (<sha7>) pull=.. worktree=.., or SHIP: refused (<step>, exit <rc>) worktree=<path|none>). Use start and land directly for --draft, --with-ci, --verify and --pick.
  • bin/wrap adopt [--apply] [--body-file <file>] <repo>... adopts one or more repos into the kit contract and lands each adoption. Per repo it composes adopt.sh with start (a chore/kit-adopt worktree) and land, with a logged proof-of-done override before the land. It writes nothing without --apply: the dry run reads every repo and prints would adopt or the refusal, with no fetch, worktree, branch, or ledger line. It refuses a repo by name when gh is not usable, the path is not a main checkout, the main checkout is dirty under an adoption path, a sequencer op or unmerged path is in progress, a chore/kit-adopt branch or worktree is left over, the checkout is off the default branch, an adoption path is gitignored, a PR template exists with no --body-file, or adopt.sh --dry-run refuses. An already-adopted repo prints skip: already adopted. --body-file takes exactly one repo. Repos run one at a time in argument order; a failure never stops the next repo, and an interrupt in land stops the batch with not run rows. Each repo prints one == <repo> block ending in result: <#n or -> <row>, and the run ends with an ADOPT SUMMARY table (repo, PR, result); the exit is 1 when any row is not would adopt, skip: already adopted, or adopted. A failure that leaves a resumable worktree prints resume: wrap land <wt>; the verb never removes what a failure leaves. --apply is operator-only: an agent runs the dry run and hands the operator the --apply command line, never running it.
  • When the session's open PRs form a chain, retarget every dependent onto its grandparent's target first, then merge parent-first, oldest ancestor first.
  • Never merge a PR the operator did not open.
  • After gh reports the PR MERGED, wrap merge fetches the default branch and verifies that the merge commit gh names is on it and applied exactly the PR's own net change (path by path, so another PR that merged in between never counts) before reporting success; a TREE MISMATCH means gh's word and the tree disagree (a stale head SHA or a late push outran the gate) and the merge exits 3 without deleting the branch, so treat it as a merge that did not really land and re-check the PR by hand.

Step 4: deploy check

A merged PR is not a deployed one. A repo deploys in one of two shapes, and each has its own check.

  • Dispatch deploy (workflow_dispatch): dispatch it and confirm headSha == merge SHA before the report claims DEPLOYED.
  • Push deploy (the deploy is a check run GitHub records on the merge commit, for example Cloudflare Workers Builds: <name>): run bin/wrap deploy-wait <owner>/<name> <merge-sha> --check "<deploy check name>", one --check per deploy check the repo runs. It polls the commit's check runs every 10s until each --check value matches a run and every matching run is completed, prints <conclusion> <name> per run, and exits 0 only when every one concluded success. The report claims DEPLOYED only after it exits 0. Exit 1 prints FAILED <sha7>: <names>: report the deploy as failed with those names. Exit 124 is the timeout (--timeout <secs>, default 600): report it as not yet deployed, naming the open or unmatched checks it printed. Exit 2 is a gh or read error: report the deploy as unverified, quote the ERROR line, never DEPLOYED. Always pass --check: without it, a CI run that finishes before the deploy check registers ends the wait early. Take the deploy check name from the repo's docs, or from one read of gh api repos/<owner>/<name>/commits/<sha>/check-runs --jq '.check_runs[].name'; the rule below forbids polling by hand, not that one lookup. Never poll gh api .../check-runs in a loop by hand. The wait can outlast a tool call's own time limit (a Bash tool call stops at 120s by default, 600s at most), so run the verb in the background and read its exit code when it finishes, or pass a --timeout well under the limit; a call killed by its caller prints no final line and proves nothing.
  • A repo with neither shape has nothing to check here; say so plainly rather than guessing at a deploy that does not exist.
  • The command checks a deploy; it never dispatches one on its own initiative (Out of Scope). Dispatching happens only when the operator asked for this repo's deploy as part of landing the session. deploy-wait dispatches nothing; it only reads check runs, so run it for every push-deploy repo whose PR this pass merged.

Step 5: branches, worktrees, pull

Re-run the step 0 check first. Then, in this order: remove the session's own worktree (the bullet below), bin/wrap scan <repo> again to see the current branch verdicts, bin/wrap apply --own <wt>... <repo> as a dry run naming every worktree this session created, read every SKIP line, then bin/wrap apply --apply --own <wt>... <repo> to execute. The repo-wide --worktrees sweep runs only when the operator asks for it this pass ("clean up all worktrees", "dọn hết worktree"). A stopped repo runs the same order as bin/wrap apply --own <wt>... --no-pull <repo> (dry run, then --apply), --own only: <wt> may be the path the first action already removed, and apply reports it as not registered; its branch is then no origin candidate, because the sweep is scoped to branches the named worktrees still held. A session that never had a worktree skips the tidy. The pull and stray-line bullets below are the stopped writes and do not run there. Close the step by re-running bin/wrap scan <repo>: that final scan, not memory, is what step 9's Left alone reports.

  • <repo> is the MAIN checkout path, never the session's cwd. Resolve it once: main=$(git -C <cwd> rev-parse --path-format=absolute --git-common-dir) then strip the trailing /.git. Off the main checkout apply sees the feature branch as current and never pulls, which is how a repo stays behind while the report claims it landed.
  • The default scope is the session's own worktrees: pass --own <wt> for each one, dry run and apply alike, unless wrap.tidy_worktrees is false. The session's own set is every worktree it created: its bin/wrap start worktrees, its EnterWorktree worktree, and the agent-<id> worktrees of subagents it dispatched with isolation: "worktree". Another session's worktree is never a default candidate, even when proven merged: an unscoped sweep has removed a live session's fresh worker worktree as ancestor of origin/main. --worktrees (the repo-wide sweep) runs only when the operator asks for it this pass. When it does run, apply still refuses a dirty, detached, checked-out or unproven worktree on its own. A branch held by a worktree outside the set stays with that worktree (held by a worktree). With the knob false, drop the flags, leave every worktree, report them under Left alone per its scope rule, and name the knob in FYI as a STATE row; the session's own worktree bullet below is unaffected, because that removal is proven per worktree rather than swept.
  • apply also sweeps ORIGIN on a GitHub remote: every apply call runs it. Without --own (plain apply, --worktrees) it is repo-wide. Under --own the scope is the current session only: it considers just the branches the named worktrees held, read before the worktree is removed, and prints -- origin branches (own scope: N named branches):. Another session's merged head stays on origin until the operator asks for a repo-wide run. A named path that is no registered worktree adds no branch. An origin branch is deleted only when a same-repo MERGED PR has its exact origin tip, it is not the default branch, and no OPEN PR uses it as head or as base; every other branch is kept without a line. The dry run prints WOULD delete N merged branches on origin: and the names; --apply deletes them in one git push per 100 names, each leased to the tip it read, and prints deleted K of N; a branch pushed to after the read is refused, not lost. This pass exists because merge never passes --delete-branch, so nothing else ever clears a merged head from origin. When the remote has more than wrap.origin_sweep_max heads (root-only, default 500), the sweep prints SKIP origin sweep: N remote heads over cap and emits no origin rows; the cap only adds keeps. wrap.delete_merged_remote_branches false: apply prints N merged branches left on origin (wrap.delete_merged_remote_branches=false), deletes nothing, and the report names the knob in FYI as a STATE row. A refused push (branch protection, permissions) is FAILED and the rest of apply still runs.
  • --worktrees sweeps every proven-merged worktree in the repo, including other sessions'. That is why --own <path> per worktree is the default (bin/wrap apply --own <wt> [--own <wt>...] <repo>), naming only the worktrees this session created; --own implies the worktree opt-in for the named set, reports a named path that is no registered worktree, skips the all-branches sweep, and scopes the origin sweep to the named worktrees' branches, so nothing outside the session's own set is a candidate. Every refusal --worktrees applies still applies to a named worktree. wrap.sh refuses (exit 64) a single argument that packs flags, such as --own <path> from an unsplit shell variable, so pass each flag and path as its own word.
  • bin/wrap apply without --apply changes nothing; always read its dry-run SKIP lines before adding --apply.
  • --archive-unmerged is opt-in and never runs as part of this step's own default flow (it is never passed alongside --own). When the operator asks to clear out real, unmerged work a branch sweep would otherwise leave forever, bin/wrap apply --archive-unmerged <repo> previews it: every local branch that is not current, default, or worktree-held, and carries at least one commit git cherry origin/<default> <branch> shows as a + (origin lacks its patch), prints WOULD archive <branch> -> origin refs/archive/<branch-slug>-<YYYYMMDD> (<n> unique commits). --apply pushes it there (no force; an existing archive ref refuses the push and reports FAILED archive <branch>: <first error line>, branch kept) and deletes the local branch only once that push lands, printing archived <branch> -> <ref>. A branch with no unique commit is left alone for the merged-branch sweep above.
  • --archive-worktrees is opt-in and never part of this step's default flow (it is never passed alongside --own or --no-pull, and each prints a section SKIP). It runs only when the operator names it, to clear out stale worktrees --worktrees never removes: a branch-held one whose branch is unmerged, a detached one with a commit origin lacks, or a dirty one. bin/wrap apply --archive-worktrees <repo> previews each with WOULD archive worktree <wt> [<branch>|detached, <n> unique commits, <k> uncommitted paths, idle <h>h] -> origin refs/archive/<slug>-<YYYYMMDD>, then remove it. A worktree qualifies only when it is stale (idle at least wrap.archive_worktree_min_age_hours, root-only, default 72, read from the newest reflog entry, the admin HEAD, commondir and locked mtimes, and every uncommitted path), not locked by a live pid, not busy in lsof, and holds no embedded repository, initialized submodule, secret-shaped uncommitted path, unmerged index, unborn HEAD, in-progress merge or rebase, or ignored path a removal would lose (build output and .claude/ copies identical to the main checkout's are regenerable; anything else, .env included, blocks). The sweep needs the busy check: with no lsof the whole section skips. --apply snapshots uncommitted files into a commit built from a temporary index (the worktree's own index, HEAD and files are never written), pushes the tip with a create-only lease (--force-with-lease=refs/heads/<ref>:, never forced; an existing ref is FAILED ... already exists), reads the ref back, re-reads the worktree, and only then removes it and deletes its branch, leased to the HEAD it read: archived worktree <wt> -> <ref> (<sha7>); removed[, <branch> deleted]. A change during the push prints kept <wt>: ... and keeps it. Origin receives every uncommitted, non-ignored byte of an archived worktree, so the operator names the flag knowing that. Restore one with git fetch origin refs/archive/<slug>-<date>:refs/heads/<slug>-<date> then git worktree add <path> <slug>-<date>: uncommitted work returns as one or two commits on top, the branch returns under the archive name, and regenerable ignored paths do not return.
  • Pull on the default branch is --ff-only; off the default branch, apply fetches the default branch into itself instead and reports a refusal as FAILED, never forced. That fetch refuses outright when the default branch is checked out in another worktree, which is the second way a repo stays behind; the main-checkout rule above is what avoids both.
  • wrap.pull_past_dirty (default false) governs the third way a repo stays behind: a sibling session's dirty TRACKED file that git refuses to overwrite. false reports FAILED and leaves the checkout behind. true stashes only the blocking files under a run-named stash, pulls, and pops that stash by ref; a pop conflict prints PULLED, POP CONFLICT: <files>, stash <name> kept and exits 2, leaving the markers and the stash for the operator. Whether a dirty file reaches that conflict at all is the repo's own call: a file .gitattributes declares merge=union never blocks the pull in the first place (its local lines are carried across, below the --- anchor, or by git's union driver when the file has no anchor), and one that rides in the stash resolves during the pop. This repo declares its board and its implementation notes union for exactly that reason. Untracked files, a dirty index, and pre-existing stashes are out of its reach at either setting. Name the knob in FYI, as a STATE row, whenever it changed what the pull did. If a run is interrupted between the stash and the pop, the blocking files are still in the stash: git -C <repo> stash list | grep wrap-pull-past-dirty names it and git stash pop <ref> finishes the restore.
  • apply reports STRAY LINES on the main checkout, whatever branch it has checked out: for each dirty merge=union file, the lines neither origin/ nor HEAD holds. A session that ran board set or wrap log in the shared checkout leaves exactly these, and the pull carry keeps them local forever. The dry run prints WOULD carry N stray lines in <file> onto a branch. --apply commits origin's version plus those lines (on a kanban board a flipped row replaces origin's row of that id in place, then dedupe-all runs) to a new wrap/stray-<file-slug>-<YYYYMMDD-HHMM> branch in a scratch worktree, pushes it, and prints gh pr create --head <branch>; it opens no PR and never touches the working copy. Relay that command under Needs you. An origin wrap/stray-<file-slug>-* branch that already exists skips the file. wrap.autoland_carry (default false, and off whenever wrap.merge_own_prs is false) true replaces the printed command: apply opens the branch's PR (or adopts its one open own non-draft PR), waits up to KIT_WRAP_CARRY_CHECKS_SECS (300) for pending checks, and merges it through wrap merge --apply --pr <n> <repo>, the same gate, re-merge and tree verify step 3 uses; the merge lines print indented under the carry. An existing carry branch is landed the same way, but only when its name is the exact wrap/stray-<file-slug>-<YYYYMMDD-HHMM>, its diff touches that file alone, and every line it adds is in the working copy; otherwise SKIP land <branch>: not a carry of <file> alone, or adds lines this checkout lacks and the file skips as before. Once every existing branch lands, the lines origin still lacks carry and land too, or <file>: the landed carry held every stray line prints. A gate refusal prints PR #<n> left open; wrap merge --apply --pr <n> merges it once green (step 3 picks it up; exit unchanged); a failed merge or TREE MISMATCH exits 2. Nothing goes under Needs you for a landed carry. wrap.carry_stray_lines (default true) false reports the count and carries nothing; name it in FYI as a STATE row. Under --no-pull (a step 0 stop) the carry also pushes nothing, whatever the knobs say: it prints SKIP stray lines: --no-pull (N lines in <file> stay local).
  • apply also reports STRAY COMMITS when the main checkout is on the default branch and ahead of origin/: a session committed there and never pushed, and every later pull --ff-only refuses as diverging, so the report says PULL BLOCKED run after run. The dry run prints WOULD carry N stray commits on <default> onto a branch: with one <sha> <subject> line per commit, then WOULD move <default> back to origin/<default> or <default> would stay ahead: dirty tracked files block the move: <files>. --apply creates wrap/stray-commits-<YYYYMMDD-HHMM> at HEAD (a local branch of that name stays too), pushes it, and prints gh pr create --head <branch>; it opens no PR and merges nothing. Relay that command under Needs you. With wrap.autoland_carry true the branch lands through wrap merge --apply --pr as in the bullet above, before the move, but only when nothing blocks the move and the origin branch holds exactly HEAD; otherwise the command prints with not landed: <reason>. Then it moves the local default branch back with git reset --keep (never --hard) to the commit where it left origin/, and the pull that follows fast-forwards it the rest of the way. The move runs only when every dirty tracked file is an unstaged merge=union file the stray commits do not change (the pull carries those) and origin holds the commits; it prints moved <default> back to origin/<default>; the N commits live on <branch> (or names the fork-point sha when origin moved since). A dirty non-union tracked file prints <default> left ahead: dirty tracked files block the move and the branch is still pushed. A dirty union file the stray commits themselves change prints <default> left ahead: dirty files the stray commits change block the move: <files> (reset --keep would refuse it), and the pull then fails as before. An origin wrap/stray-commits-* branch that already holds HEAD is reused, not pushed again, and its PR command prints again. When the commits' combined change already sits on origin/ as one commit (their carry PR squash-merged and the sweeps deleted the branch), nothing is pushed: it prints the N stray commits on <default> already landed on origin/<default> as <sha> and moves. A refused push (protection, permissions) is FAILED and the rest of apply continues. The same knob, wrap.carry_stray_lines, governs it: false prints N stray commits on <default> stay local and touches nothing. The commits are never lost: they sit on origin before the local ref moves.
  • When the operator wants the pull alone, for example right after merging one PR while other sessions still own the other open branches in a shared checkout, bin/wrap apply --pull-only [--apply] <repo> runs exactly fetch --prune, default-branch resolution, and the pull section above (the union carry and wrap.pull_past_dirty both still apply); it skips every worktree, branch, archive, origin-branch, stray-line, and stray-commit step and prints no section for any of them. It refuses to combine with --worktrees, --archive-unmerged, --own, or --tips-file (exit 64, naming the flag). It skips the stray-commits step, so it names what it leaves: a default branch ahead of origin prints NOTE: <default> is N commits ahead of origin/<default>; --pull-only never carries them, plain apply --apply does in the pull section. Merely AHEAD (origin's own tip unmoved), the pull is a no-op, exit 0. DIVERGED (origin's tip also moved), the pull still fails, FAILED pull --ff-only, exit 2. Either way, plain apply --apply (no --pull-only) is what carries stray commits onto a branch and moves the default branch back so a diverged pull can land. The pull is the whole job here, so a repo whose default branch does not resolve exits 2, dry run or not, and a pull skipped because index.lock stays held exits 2 under --apply (a dry run still exits 0). Plain apply exits 0 on both. It also skips the tip snapshot and the gh auth status probe, since only the skipped sweeps read them. Relay a NOTE: ... ahead line under FYI. --no-pull is its opposite and refuses --pull-only (exit 64, naming --no-pull).
  • The session's own EnterWorktree worktree goes FIRST, before wrap apply runs, so the harness records the removal instead of finding the directory gone. It writes no main-checkout state, so it runs under a step 0 stop too. Once wrap scan proves its branch squash-merged (tip matches the PR head) and the worktree is clean, remove it: ExitWorktree remove with discard_changes: true (the squashed commits are not ancestors of the default branch, so the tool asks; the proof is the confirmation), then git branch -D <branch>. The operator gave that confirmation once, as a standing rule, and a worktree whose PR merged this session is finished work, never something to keep. ExitWorktree keep only when the worktree is dirty, the branch is not proven merged, or the proof is unavailable (no gh); say which in Left alone. A plain secondary worktree of this session routes through wrap apply --own <wt> <repo>, which skips it when dirty, detached, held by the checked-out branch, or on a branch no merge proof covers, and otherwise removes it and deletes that branch. A merge proof is one of three: the branch is an ancestor of origin/<default> and not a never-used branch created off that default line, its content is ABSORBED (every path it changed since its merge base is byte-identical on origin/<default>, the shape of a subagent branch whose lead re-committed the work under its own PR; a tree comparison, so no merge driver can fake it), or gh shows a squash merge whose head is the branch tip. A LOCK is not a skip reason there: the Agent tool locks every worktree it creates, so apply overrides the lock once the merge proof holds, then confirms the path is gone and reports FAILED when it is not.
  • Never remove a dirty or foreign worktree, under --worktrees or otherwise. The one exception is --archive-worktrees, which the operator names: it removes a stale dirty worktree only after a snapshot of its uncommitted files is on origin and read back.
  • Never remove a worktree a live process still holds: apply (--worktrees, --own and --archive-worktrees) and land check, right before the removal, for any process outside the wrap run whose cwd or open file sits inside it (a background subagent's headless browser, a blocked cp -i, a test loop). A holder prints SKIP <wt>: busy, held by pid <pid> (<command>) (plus and N more), keeps the worktree and its branch, and the rest of the pass continues; land still reports its merge as done and says the worktree stayed. The | tail reader of wrap land <wt> | tail -6 (stdin a pipe, in wrap's process group or its shell's, so timeout 120 wrap land <wt> | tail too) is the caller's own and never counts. Relay the line under Left alone, and re-run once the holder exits. Without lsof one NOTE: busy check unavailable (no lsof) prints and removal proceeds as before. Local branch deletes after a merge proof are leased to the tip wrap verified (refused if the branch moved).
  • Never force-push and never rewrite history to make a delete or a pull succeed. The stray-commit move is the one local ref apply moves, and only after origin holds every commit it moves away from. bin/wrap merge --apply --pr <n> --rebase-stacked <repo> is the one opt-in rewrite, for a child PR whose parent squash-merged: it is never part of a default flow and runs only when the operator names the flag.

Step 6: activity line

Re-run the step 0 check first. Then: bin/wrap log "<slug>: <one sentence>". When the current directory is a git worktree of the repo that holds the configured file, the same repo-relative file inside that worktree is written instead, so the line is committable on the session's branch; the main checkout's copy is left alone. With no wrap.activity_log key in the kit-root kit.toml, it prints the line and says where it did not land; that is a clean result, not a failure. From a git repo other than the log's (a foreign repo's worktree), the line still lands in the one log, and stderr says so: wrap log: wrote <abs path> (repo <log repo>), outside the current repo <repo>; it is not in the current repo, so do not look for it there or commit it there. When the written file lands in a checkout sitting on the repo's default branch, the verb says so on stderr: leave the line uncommitted for the next feature PR, per step 2.

Step 7: understand

(Distill half. With the switch off, none of a, b, c, or the drain runs; report **Built:** SKIPPED: distill off and go to step 8.) The process half of distill: a DEBT marker for the run, new-tool candidates checked against precedent, and one memory note per incident this session caused. Three lettered sub-steps, each prints one line when idle.

Sub-step b BUILDS what it can rather than proposing it, and it builds through the lane, never around it. wrap.build_lanes names which lanes build and verify here, and it defaults to tiny: a wrong call in a listed lane costs one revert. Every candidate not built here is REPORTED in the step 9 report and written nowhere else: no board row, no staging block, no goal draft. A spec or a review does not fit in the minutes an operator gave you to close the session, and a row minted as a side effect is a queue entry nobody decided on; one estate board grew 13 to 25 rows a day that way while its staging file held dozens of undrained blocks. The operator reads the report and decides. A board row happens only when the operator asks for one, or when the work is blocked on something outside the session; then it goes through the operator's own intake, never through this step. A candidate whose scope is a judgment with different irreversible outcomes is reported too, and also earns a Needs you item under the admission test. Sub-step c writes one memory note and never a board row.

a. DEBT marker.

rid_out="$(bash lib/gate/gate-ledger.sh rid 2>&1)"; rid_rc=$?

Every skip in this sub-step skips ONLY this sub-step. a is the DEBT marker and nothing else; b and c do not depend on a run id, a run log, or the classifier, and they run whatever a reported. A real session on 2026-09-09 read skipped: no run id as "step 7 does not apply" and never ran b, which is the step that builds rather than proposes. If a skips, say so and go straight to b.

A non-zero rid_rc is a STRUCTURAL skip, not a clean one. This is gate-ledger.sh rid refusing outright: landing from master/main, a detached HEAD, or a branch whose slug strips empty. There is no branch to key a ledger entry to, so the DEBT marker was never reachable this run, which is a different fact than "nothing to record." Print skipped (structural): DEBT marker impossible this run (<rid_out>), quoting the tool's own reason. Do not synthesize a rid from anything other than the branch: the ledger's rid is the SAME key hooks/ship-gate.sh checks at push, so a rid tied to the session instead of the branch would write an entry the ship-gate can never find and no other reader can trace back to a branch, a second failure mode worse than the skip it would replace.

Otherwise rid="$rid_out" and resolve the log dir with logdir=$(bash -c 'source lib/telemetry/kit-log-dir.sh; kit_resolve_log_dir') (the file is source-only and prints nothing when run as a command); a missing runs/<rid>.log prints skipped: no run log; a | DEBT | line already in it prints skipped: DEBT marker present. Otherwise bash lib/classify/significance-classify.sh record <rid> "<one-line session description>"; a non-zero exit prints skipped: classifier failed (rc N) and the step continues to b. These three remain plain skips: the rid exists, so the marker was reachable and simply had nothing to add.

The teacher seam. Once the marker is written (or found already present), run bash lib/gate/quiz-gate.sh teacher (the one resolver every seam-adjacent site cites; never read understand.teach any other way). Empty: print skipped: no teacher plus the path to the material a teacher would need (<logdir>/runs/<rid>.log, the DEBT line itself) and stop there, sub-step a is done. Named: invoke that skill through the Skill tool, handing it the rid, the DEBT row just written, and the run's diff (git diff <base>..<rid's head> where derivable). The engine never decides what the teaching looks like; it writes the record and, when a teacher is configured, hands the record over. This sub-step never names a skill itself.

b. Candidates. Act on the list the pre-step-0 scan wrote. A candidate is one of three things, and the first two are what the scan looks for: a manual multi-step procedure this session ran three or more times, or the operator called recurring (the same jq over transcripts, the same mutate/test/restore loop, the same board flip by hand); a one-off script or snippet written this session that solves a problem more general than the session's (a probe, a helper, a check that a tool over there should own); or an enhancement the operator asked for and the session deferred. What the session BUILT as its task is NOT a candidate: that is the deliverable, Shipped already carries it, and listing it here is how a wrap reports Built: every time and enhances nothing. That exclusion covers the OUTPUT, never the METHOD. When the deliverable IS manual labour (a triage pass, an audit done by hand, a migration walked file by file), the procedure that produced it is the candidate the scan most needs, and excluding it removes the only one worth having. The question to ask of the session is whether the operator got a result or a mechanism: a result plus a repeated method is a candidate, every time. Repetition the session DELEGATED counts too. A procedure run three times by three subagents appears once in the lead's own tool history, so the scan reads one dispatch and misses it; count what the session CAUSED to happen, not what the lead typed. Both holes were found the same way on 2026-09-10, by the operator asking twice why a four hour manual cleanup produced no candidate. The check runs on the first candidate, not the third, because a single-purpose script written next to an existing tool is the fragment this step exists to prevent. wrap.build_candidates false: run the precedent check AND the lane classifier anyway, then report every candidate, quote the top hit in the FYI STATE row where one came back, and close each Built: item as (lane=<lane>, reported: build_candidates off). Building is what the knob governs; checking precedent and sizing the work are not optional at either setting, because a reported candidate that names neither the tool it should have joined nor the lane it owes recreates the fragment one release later.

Otherwise, for each candidate run bin/precedent find --surface inventory --json "<two or three words>". The answer decides the HOME and the report token, and it decides nothing else:

  • nothing_matched false, a hit came back. The candidate is an enhancement to something that already exists, which is the whole reason this check runs. Its home is that hit and its token is ENHANCE. Open the hit before you fold work into it: a query of three or more words also returns rows that match all but one word, so a hit can share the words and not the job. Do not write a sibling beside a hit that does the job. A single-purpose script written next to an existing tool is the fragment this step exists to prevent, and quoting the tool it should have joined prevents nothing.
  • nothing_matched true. The candidate is new. Its home is the repo that would own it and its token is NEW (precedent: nothing matched).

Then size it, and the size decides where the build happens. A build that lands from inside wrap is still a change in a real repo, so it owes the same lane discipline as any other change; an inline edit-and-commit at session close is how an unreviewed, undocumented change enters an estate:

bash lib/classify/lane-classify.sh risk "<the candidate in one line>"
bash lib/classify/lane-classify.sh risk --files "<paths>" "<the candidate in one line>"   # when the touched files are known

wrap.build_lanes decides which lanes build inline. Split the classifier's answer against that list:

  • The lane is in wrap.build_lanes. BUILD IT NOW in the home repo, on its own branch, in a worktree at <home>/.claude/worktrees/<slug> created with bin/wrap start <home> <type>/<slug>, never on that repo's default branch. A step 0 stop on the home repo does not block this build (step 0 says why). Dispatch the build to a worker rather than editing inline (Sonnet by default, Opus when the candidate touches security, money, or a data model, per the tier paragraph below). Run one verification command before the commit (the home repo's own test for the file you touched, or the smallest command that fails if the edit is wrong) and QUOTE its output in your report; a kit:task-verifier against the candidate's intent stands in where the repo has no such command. Commit under its own name only after the check is green. A tiny candidate ends at that commit; steps 3 and 5 already ran, so its branch stays in Left alone unless step 10 lands it. Any heavier lane also opens a PR and leaves it for step 3's own-PR merge path, which merges only what is green; the home repo's ship-gate proof still applies to that PR and wrap never overrides it. Report it with (lane=<lane>, verified: <check>, <PR or commit>).
  • full, whatever the list says, and any other lane not in the list. Do not build it here and do not write it anywhere: no board row, no staging block, no goal draft. REPORT it in step 9 with one line saying why it did not fit the session, (lane=<lane>, reported: <one-line why>), for example owes a spec and a review for a full lane. The operator decides from the report whether it becomes work. When they ask for a row, or when the candidate is blocked on something outside the session, their own intake files it (the board's capture verb or an intake skill), and that is a separate, explicit act.

Model tier for any worker you dispatch, at either size. Sonnet is the default worker. Opus takes the verification arm, and takes the build too when the candidate touches security, money, or a data model. Haiku takes mechanical fan-out only (grep, read, a flat transform). Never dispatch a worker on the session's own model by default.

Open the top hit rather than trusting its name: bin/precedent find --explain '<label as printed>'. A hit that covers half the candidate still means ENHANCE that home, a verb, a flag, or a step in the existing skill, never a sibling next to it. The cases this gate was built from, so none is re-derived: a python board-flip written five times while board set existed; a merge helper one .gitattributes line replaced; two lessons filed as new memory notes while a note and a skill section already held them; kit features proposed that already existed as /kit:* commands; a session that hand-rolled jq over the session transcripts four times while session recall existed, and the mutate/test/restore loop four times while proof-ledger.sh was the home. Two first rungs came out of those: "which session did X" is session recall <terms> --project <repo-name> --sessions, and a proof's negative control is bash lib/gate/negctl.sh <root> "<test-cmd>" "<mutate-cmd>" after the change is committed. Once --sessions names a peer's id, "what is that session doing now" is the next rung, session recall --tail <id>, and its output is a hint to confirm with git or gh, never a reason to skip work on its own.

Shadow second opinion (wrap-7b). Run it every wrap, even with no candidate, after the session has judged every precedent hit itself: bin/wrap flick-7b reads one pair per stdin line, <candidate-slug> <hit-name> <your own verdict>, sends ALL of them to bin/flick in ONE call (so an outage costs at most one timeout), ignores the answers, and prints the one STATE row for FYI. With no candidate, give it empty stdin (bin/wrap flick-7b </dev/null). It reads decide.points itself and prints flick wrap-7b: off when the point is unlisted: then add no row and skip the rest of this paragraph. When the point is on, report-lint.sh fails a report with no flick wrap-7b: row, so a skipped call shows up at step 9 and never reads as nothing. The verdict is enhance for a hit that covers or partly covers the candidate, new for an unrelated hit, none for no basis to decide. In each line, the candidate is a slug you write (^[a-z0-9-]{3,40}$), never copied session text. flick sends only pairs whose hit is a name this kit publishes and whose candidate clears the operator's decide.deny_words and whose every hyphen segment is a dictionary word, a built-in dev word, or a kit-public name (decide.word_gate, on by default); every other pair comes back egress_denied and is counted. With an empty decide.deny_words it sends nothing: every pair comes back egress_denied. Nothing it returns changes a verdict, a lane, or a closure: it only writes a log line beside yours for later comparison (the exit criterion is in the flick spec under docs/specs/). Put the printed line in FYI as a STATE row, verbatim: flick wrap-7b: <answered> answered, <denied> denied, <error> error (<backend>). The verb exits 0 and prints an error row when flick is missing or fails, so a failure is a visible row, never a silent skip.

A hit that covers the WHOLE candidate is a NOTE, never REPORTED. Nothing is missing in the tool. The missing piece is the path to it: no skill or doc pointed the session at the tool when it needed one, so it hand-rolled the job. 7b writes that pointer in-session and names the file. Pick the first that fits: a trigger line in the skill that fires for that task, then the tool's README or quick-ref entry the session would have read, then a memory note. A memory-note pointer also carries PROSE-ONLY: <why>, like any note. Close the item as NOTE ... (lane=tiny, verified: <check>, <commit>). REPORTED is wrong here: a reported item with no work in it gives step 10 nothing to build, and the next session hand-rolls the same code again. The case that taught this: a session sent its own Discord API calls and signed event-bridge posts by hand while tools/discord-pull and _meta/eb-post --stream already did both jobs. The lint rejects a REPORTED item whose reported: reason says the tool already covers it.

A hit on a memory note or a research file is NOT the home for the build. bin/precedent indexes prose as a hit kind, so a note often tops the list. A note is where the lesson goes AFTER the build, or instead of the build only when no mechanism exists. When the hit list holds a prose home and a code home, the CODE home wins. That rule was learned by taking the first line of a hit list whose second line named lib/wrap/wrap.sh, the file the fix eventually went into, while the session wrote three markdown files and shipped no mechanism. When nothing mechanical was possible, say so in the report: add PROSE-ONLY: <reason> as its own bullet, or append the token to the inline item. It is honest when the work is one human judgment per run, and dishonest when you repeated a procedure and wrote a note about it.

Never grep or Read across repos, notes, or research to answer the overlap question yourself. The scan is sub-second and costs no tokens; the model scanning the estate is the spend this gate removes.

No candidates: NOTHING: no candidates, and that word is NOTHING, never SKIPPED. SKIPPED is reserved for the step not running (the distill switch was off, the scan never ran, a tool refused); an empty scan is a result, and SKIPPED: nothing to build is the one line that says both and means neither, which the lint now rejects. Nothing here reaches a public repo or an outward-facing surface; a candidate that would (a publish, a send, a charge) is never built here, it goes to Needs you under the admission test.

Draining what was staged. Read kit_config_get_root wrap.drain_staged false. Step 7b stages nothing, so this pass owns no staged rows and the drain has nothing to run at either setting. False, the default, reports nothing. True drains only rows the operator staged by hand this session with bin/wrap stage, and only those carrying a goal pointer: write a tsv of slug<TAB>repo<TAB>pointer for them, then bash lib/queue/queue.sh run <tsv> --sanitize-prompt --max-megas <count>, never --from-boards, and report the tsv, the row count, and the journal path in FYI as a STATE row. The default stays off because queue run drives a real interactive claude under QUEUE_CLAUDE_FLAGS (default --dangerously-skip-permissions) for up to QUEUE_TIMEOUT_SECS per row, which starts work nobody has decided on at the moment the operator said to stop.

c. Incidents. For every docs/incidents/*.md written this session whose ## Root cause names our own mistake, bin/wrap knowledge-root <repo> gives the directory. A note already there naming the incident id in its first heading: skipped: note exists. Otherwise write one note, how to work here and what to do differently, plus its MEMORY.md index line, in that directory. An empty ## Root cause writes nothing. A knowledge-root: fallback line on stderr becomes an FYI INCIDENT bullet, not a skip. No incidents: skipped: no incidents.

For each note this sub-step actually wrote, run bash lib/gate/quiz-gate.sh teacher (same resolver as a, one read per note is fine, it never changes mid-run). Empty: print skipped: no teacher plus the note's path and stop. Named: invoke that skill through the Skill tool, handing it the note's path and the incident file it was written from. As in a, this sub-step never names which skill runs; it only decides whether one does.

Step 8: reflect

Resolve the kit log dir (bash -c 'source lib/telemetry/kit-log-dir.sh; kit_resolve_log_dir' prints it) and grep the run ledgers under it for a | GATE | ship | ran | shipping pr=#<n> line naming any PR number merged in step 3. Anchor the number so #7 never matches #71: grep -rE "shipping pr=#<n>([^0-9]|$)" "<log dir>". Any hit means run /kit:retro now, before the report. No hit means no spec cycle shipped this session; skip retro and say so as a SKIPPED bullet in the report's FYI.

Step 8b: the after seam

Invoke the skill named by wrap.after, read back in step -1, through the Skill tool now. The landing is finished, so this skill reads what the session produced rather than racing it. Its report lines fold into step 9 after the FYI line, and its outcome is what the **Seam:** line names. An empty key runs nothing and reports NOTHING: no seam configured.

Step 9: report

Print the skim-first block below. It is the single reply for this command's landing; there is no separate per-step report. Step 10 alone prints a second, ## Follow-through: report after background work, and only when it runs.

## Wrap: session wrap follow-ups

**Result:** Landed the session PR, flipped DK-101, and kept foreign worktrees untouched.

✅ **Needs you:** NOTHING (walked: digest 4 replies, miner 2 actions)

**What happened**
- **wrap-session**: Added one-call gather flags. Proof: `test-wrap-session: all 159 passed`.

**Shipped**
| Repo | PR | Merge | Deploy |
|---|---|---|---|
| devkit | #1257 | 74475fb1 | DEPLOYED push-main |
| devkit | #1261 | 64ca6ef7 | 🟡 MERGED, NOT DEPLOYED |
| devkit | #1262 | | OPEN |

**Left alone:**
| Repo | Item | Owner | Why |
|---|---|---|---|
| devkit | feat/follow-up | this pass | PULL BLOCKED |
| devkit | 2 foreign worktrees, 1 foreign branch, 0 dirty files | other sessions | untouched (`/kit:wrap wide` lists them) |

**Built:** BUILT wrap-hint ENHANCE devkit: lib/wrap/wrap.sh usage (lane=tiny, verified: bash tests/test-wrap-session.sh, a1b2c3d)

**Seam:** NOTHING: no seam configured

**FYI:**
| Tag | Fact | Home |
|---|---|---|
| SKIPPED | Retro skipped because no spec cycle shipped. | |
| STATE | Handoffs archived `done.md` and kept `open.md` with 1 item open. | `_meta/handoffs/open.md` |
| INCIDENT | Pull hit a stale lock and cleared on retry. | |

Variant shapes for sections with alternatives:

  • Needs you when operator action is required: 🔴 **Needs you:** followed by a. DECIDE | RUN | REVIEW | UNBLOCK <what>. <why it sits with the operator>. <the one command or the decision>.

  • Shipped, Left alone, or FYI when empty: replace the whole table with - NOTHING.

  • Built: whole-outcome inline forms are NOTHING: no candidates, SKIPPED: distill off, or SKIPPED: <why>. Multiple candidates use a bare **Built:** header followed by - bullets:

    • BUILT <label> ENHANCE <home>: <file, insertion point> (lane=tiny|normal, verified: <check>, <commit or PR>)
    • REPORTED <label> NEW (precedent: nothing matched): <path> (lane=<lane>, reported: <one-line why>)
    • NOTE <label> ENHANCE <home>: PROSE-ONLY: <why no mechanism was missing>, <memory note or doc written>
    • NOTE <label> ENHANCE <home>: covered, pointer added at <file> (lane=tiny, verified: <check>, <commit>)
  • Seam: <side> <skill name> ran: <its one-line outcome>, NOTHING: no seam configured, SKIPPED: distill off, or SKIPPED: <why>.

  • Needs you leads and is always present, even as NOTHING. It is a lettered action list; it sits at the top, ahead of every other section, because this report is read from the top and the items are the whole point.

  • Admission test, run it on every drafted item before the report prints. An item earns a place in Needs you only when the operator is the ONLY one who can do it. Three classes qualify: it needs a human credential or presence (a root password, a GUI, 2FA, a physical device); it is irreversible and outward-facing (send the email, charge the card, terminate the host, delete in production); or it is a judgment whose options carry different irreversible outcomes. Step 10's second report adds one more: REVIEW #<pr> for a full-lane draft PR step 10 built and never merges. Everything else fails the test. For each failing item, RUN IT NOW, then move it to What happened in the past tense. Merging your own green PR, pulling the default branch, installing what you just merged, dispatching an established deploy, and rerunning a check all fail the test: they are work, and the report is written after the work, not instead of it.

  • The failure mode this test exists to stop: a finished build parked behind "say go and I will merge it". That reads as diligence and costs the operator a round trip to type "ok". Landing the change is part of finishing it. When something genuinely blocks, Needs you names the blocker, never the permission.

  • Run the lint before printing. Write the drafted report to a scratch file and check it: bash lib/wrap/report-lint.sh <file>. Exit 1 names a Needs you item that asks permission instead of stating a blocker; go do that item, move it to What happened, and re-run until the lint is clean. A warn line names an item built around a command the kit can run with no blocker stated: read it again, and either state the blocker or do the work. The lint judges phrasing, not reversibility, so it catches the one shape that is always wrong and leaves the judgment calls to the admission test above.

  • Exactly two emoji, no others: ✅ or 🔴 leads Needs you (green only when it says NOTHING), and 🟡 marks a MERGED, NOT DEPLOYED PR, the one Shipped state that still needs a hand. Nothing on section headers, lettered items, or in prose.

  • Status words stay UPPERCASE tokens, always the same ones: NOTHING, DEPLOYED, MERGED, NOT DEPLOYED, OPEN, PULL BLOCKED, and a leading verb on each Needs you item from DECIDE, RUN, REVIEW, UNBLOCK. Prose stays lowercase.

  • Prose is STE-lite. In Needs you items, What happened bullets, FYI Fact cells, Left alone Why cells, and Built: reasons: sentences of 20 words or fewer, no semicolons, active voice, no contractions, one topic per bullet, plain words, no filler or hedges. Inline code spans, paths, commands, and quoted output are exempt. report-lint.sh fails a semicolon or a sentence over 20 words outside backticks, and warns on a contraction. Step 10's report follows the same rule.

  • What happened is one bullet per workstream, two to four sentences: the problem as the operator saw it, the root cause, what changed, how it was proven. "How it was proven" quotes the captured output, never only "tests pass": the | lines of wrap land's PROOF OF DONE block (or the proof file's Output: lines, or the image path for visual work), and the bullet's Shipped row carries the PR link. A ten-minute session earns one bullet; a long one earns five or six.

  • Shipped, Left alone, and FYI are markdown tables with the header rows shown above, one row per PR, item, or fact. Never pack two items into one row with ;, and never fall back to bullets or |-joined prose. The - NOTHING sentinel replaces the whole table, header included. Needs you stays a lettered list, What happened stays prose, and Built keeps its inline or bullet shape because report-lint.sh parses that one.

  • Left alone is derived from step 5's closing bin/wrap scan, never written from memory of what the steps intended, and it is scoped to this pass by default. A worktree, branch, or dirty file that THIS pass owns or touched and could not finish (a kept worktree, an unmerged branch, a file this pass wrote, a PULL BLOCKED checkout) gets its own row with the reason. Everything else the scan still reports (other sessions' worktrees, branches, and dirty files) collapses into one count row per repo, so the operator still knows the repo is not fully clean without reading residue they never asked about. The wide switch replaces that count with the full listing, one row per item with its owner and the reason. A pull skipped by --no-pull is a PULL BLOCKED row with the reason step 0 stop: the scan's behind count shows the checkout stayed behind and the SKIP pull: --no-pull line gives the reason. A single - NOTHING line only when that final scan came back clean.

  • FYI closes the message: one row per fact that changes what the operator will MEET next time but owes them nothing right now. Two kinds qualify, and only two. A STATE that shifted under them: a default that changed, a file that moved, a job that will fire. Or a FOLLOW-UP this session did not finish: an unproven claim, a parked question, a deferred enhancement. The second kind is future work, often the most interesting work in the report, and saying so is the point of the lane.

  • A follow-up lives in the report, and the report is its home. The session either finishes the follow-up or drops it here; it never mints a board row or a staging block to give the row a home. The Home column NAMES ITS HOME only when one already exists (a proof file, an existing board row, a spec); otherwise it stays empty, and that is correct. A board row happens only when the operator asks for one or the work is blocked outside the session. A row that needs a decision, a command, or a review FROM THE OPERATOR was misfiled and belongs in Needs you instead.

  • Every FYI row OPENS WITH ITS TAG in caps in the Tag column, one of SKIPPED (a step that did not run, and where its output went instead), STATE (a fact the operator meets next time: a knob value, a dirty checkout, a file that exists only on this machine), or INCIDENT (something that went wrong during this pass, and how it was resolved). The block used to mix all three kinds under one header, so an operator told to "follow the FYI" read nine ambiguous lines and picked their own meaning. The tag says which kind before the reader parses the sentence, the same way each **Built:** item opens with its verdict. The - NOTHING sentinel carries no tag.

  • FYI carries no ask. A line that tells the operator to do, decide, or consider something is a Needs you item with its DECIDE, RUN, REVIEW or UNBLOCK tag, never an FYI line; the lint rejects it. "the knob is false, turning it on now works cleanly" and "the doc test fails on two pre-existing scripts" are both asks in STATE clothing: one wants a decision, the other wants a fix. Move them up, or drop the ask and report only the fact.

  • The lane is read-and-move-on, never do-nothing-forever. The operator picks the follow-up back up from its home, not from a report they would have to remember. A single - NOTHING bullet when there is nothing to report.

  • A handoff archived or kept at step 1b is one STATE row naming each file, as in the template.

  • A filed memory note from step 7 is a STATE row naming the file; a knowledge-root fallback from that step is an INCIDENT bullet naming the reason.

  • **Built:** is REQUIRED, and the lint fails without it. After FYI, reporting step 7b's outcome as exactly one of three states: named, NOTHING: no candidates when the scan ran and found none, or SKIPPED: <why> when the step did not run. NOTHING and SKIPPED stay on the header line always; they are whole-outcome states, never a bullet, and never mixed with bullets. A named outcome takes either shape: INLINE keeps one candidate on the **Built:** line itself, <label> ENHANCE <home>: <file, insertion point> or <label> NEW (precedent: nothing matched): <path>, each followed by its LANE and how it closed; LIST is a bare **Built:** header followed by one - bullet per candidate in that same per-item grammar, for two or more candidates a single joined line cannot hold legibly. Every candidate, inline or in a bullet, STARTS with its verdict in caps, one of BUILT (landed, with the commit or PR), REPORTED (nothing built and nothing written; the report is where it lives), NOTE (no mechanism was missing; a memory note or doc was written instead). STAGED and FILED are retired and the lint rejects them: step 7b never writes a staging block or mints a board row, so the reader sees what happened before reading what it was. A line whose verdict is missing reads as built when it was not, which is how two unbuilt candidates passed for shipped work on 2026-09-16. Every candidate also owes the ENHANCE or NEW token: it is the slot that forces naming the existing tool the candidate joins, and it is checked per item, not per line, so one bare path (commit) buried among two good bullets still fails and the lint names which bullet. A Built: item with no ENHANCE or NEW is the session's own deliverable wearing 7b's label. Every item also carries the LANE it was sized at and how it closed, one of (lane=<lane>, verified: <the check that ran>, <commit or PR>) for one built here, or (lane=<lane>, reported: <one-line why>) for one left in the report, including reported: build_candidates off when the knob stayed wrap's hand: a candidate built at session close is invisible everywhere else, so naming the lane says which discipline it passed and naming the check says the build was proven rather than asserted. The lint enforces that pairing: an item naming a lane owes a verified: check or a reported: why, because a lane token alone says the work was sized and never says what became of it. The retired closures (staged, filed:, capture failed:) no longer count. SKIPPED: nothing to build collapses two states into one and still fails. A skipped 7b and an empty 7b used to look identical, which is how the step that builds instead of proposing got silently dropped from a whole session. This line is the trace every other step already leaves. The lint also WARNS (never fails), on any candidate whether inline or a bullet, when a NEW (precedent: nothing matched) item's path exists and its files speak CDP (session.Runtime.evaluate and siblings): that candidate already has a home in browser-harness-js's learnings, not a sibling script here. The lint REFUSES a **Built:** whose every item targets prose (a memory note, a research file, a handoff), because a precedent hit on a note is not a build; PROSE-ONLY: <reason> as its own bullet, or appended to the inline item, is how a session says no mechanism was possible and why.

  • **Seam:** is REQUIRED, and the lint fails without it. One line, after **Built:**, reporting step -1's seams as exactly one of three: which side ran which skill and its outcome, NOTHING: no seam configured when neither key was set, or SKIPPED: <why> when a named skill did not run. It carries the same three-state rule as **Built:** and for the same reason: a seam that was never configured and a seam that was silently dropped read identically without it, and the seam is where an operator's whole distill half lives.

  • An overlay (a consumer's own routing, distill, or knowledge-capture step) appends its own labelled sections after FYI, in the same shape: a bold label line followed by bullets, one item per note, candidate, or queue entry; the kit's grammar stops there. A wrap.before skill's report lines fold in at that same place.

  • No table beyond the three fixed ones above. No restating what each step did.

Record the run, one line: bash lib/gate/gate-ledger.sh record <rid> wrap ran "<summary>". Close the timing bracket: bash lib/gate/gate-ledger.sh outcome <rid> wrap end caught=<true if a repo hit step 0's foreign-activity STOP, else false>.

Step 10: follow-through

Two real sessions ended the same way: the report listed in-lane candidates as REPORTED and FYI rows the session could finish, and the operator typed "proceed all the built and also check if we need to do anything re. FYI". That prompt carried no decision, so this step does what it asked without it.

Switch. The mode is what bin/wrap follow-mode printed at step -1: off, lanes, or all, followed by the lanes this step builds. off does nothing here, and step 9 drafts one FYI row whenever the work set below would not be empty: | STATE | wrap.follow_through is off, <n> in-lane items stay REPORTED; /kit:wrap follow builds them | |, the same shape as the distill-off row. lanes and all start only after the step 9 report is printed, its lint is clean, and the step 9 ledger line is written; the first report is the operator's landing and never waits on this step.

The work set, drafted from the first report, never from a fresh recollection:

  • (a) BUILD: every **Built:** item with verdict REPORTED whose lane= is in the printed lanes and is not full, including one reported because of a step 0 stop. An item reported with build_candidates off stays reported: that knob keeps wrap's hand at every mode. LAND only: every step 7b BUILT branch with no merged PR yet.
  • (b) FINISH: every FYI row that names work this pass left undone in a repo it touched, sized with bash lib/classify/lane-classify.sh risk "<the row in one line>" into one of the printed lanes other than full. A STATE row that says "the doc test now fails on the line this pass renamed" is work; one that says "wrap.pull_past_dirty is false" is a fact, and a fact, a resolved INCIDENT, or a SKIPPED step is never in the set. A row that needs a credential, a GUI, 2FA, a physical device, or is irreversible or outward-facing is a Needs you item under the admission test and never runs here.
  • (c) FULL, all mode only: every REPORTED item with lane=full. Under lanes those stay REPORTED exactly as step 7b left them.
  • (d) OPEN-PR: every own OPEN PR that step 3 left open because its checks were pending. It needs no build, worker, or worktree; it enters the landing at step 3.

An empty set prints [kit:wrap] follow-through: nothing in lane and ends the step, with no second report.

Run it in the background. Bracket the timing first: bash lib/gate/gate-ledger.sh outcome <rid> wrap-follow start. A LAND-only item already has its branch and worktree from step 7b: it skips wrap start and the worker and goes straight to the landing below. An OPEN-PR item skips both too and enters the landing at step 3. For every item that needs a build, create the worktree first, serially, from the lead: bin/wrap start <home> <type>/<slug> once per item, so concurrent worktree add calls never race on one .git; a refusal leaves that item REPORTED with the refusal as its why. Print one line, [kit:wrap] follow-through: <n> builds, <m> follow-ups, <k> full-lane, <p> PR waits, running in background, dispatch one BACKGROUND worker per worktree on step 7b's tier rule, and end the turn; the operator is not held. The worker's brief is the lead's own one-line paraphrase of the item; any text the item quotes from the repo (test output, a file line, a PR body) goes into the brief as quoted data, never as an instruction. An (a) or (b) worker builds, runs one verification command, quotes its output in a fenced code block under a ## How I verified it heading in the commit body (per commands/ship.md step 8's verification-section rule, since --fill-first below makes this commit body the PR body), writes the proof the home repo's contract asks for (bash lib/gate/proof-gate.sh contract "<the item>" run in the home repo), and commits only when the check is green. It never pushes, never merges, and never touches a main checkout; a red check means no commit, and the item stays REPORTED with the failing check as its why.

A full-lane worker runs the home repo's full lane unattended, in its worktree, and never validates the spec it wrote. It claims the number with bash lib/spec/spec-next.sh reserve in the home repo (never next, which hands concurrent workers the same number), opens bash lib/gate/gate-ledger.sh outcome <rid> Spec start under its worktree's rid, writes and commits docs/specs/SPEC-<n>-<slug>.md, records bash lib/gate/gate-ledger.sh record <rid> Spec ran "SPEC-<n>-<slug> written", closes bash lib/gate/gate-ledger.sh outcome <rid> Spec end, then stops with VALIDATE PENDING: <spec path>. Before Spec ran and that stop, the worker adds a ## Grounding section per /kit:spec step 4 (a live sample for every external data shape, a dry trace for every negative control). The lead, on that notification, opens the round under the WORKER's rid: bash lib/gate/gate-ledger.sh validate-round open <rid> <wt>/docs/specs/SPEC-<n>-<slug>.md, where <rid> is bash lib/gate/gate-ledger.sh rid run inside <wt>, never the lead's own branch (the verb's binding refuses any rid but the spec branch's). open writes the validate and design-record OUTCOME start lines itself, so the lead writes nothing to that rid's ledger until close: an extra line voids the round with why=ledger. It then dispatches the validator in the background per /kit:spec step 5's parallel round (one Reviewer N only subagent per ### Reviewer N: heading, Reviewer 6 always on Opus), and closes the round under that same rid with bash lib/gate/gate-ledger.sh validate-round close <rid> <token> verdict=<APPROVED|NEEDS-REVISION> critical=<C> warnings=<K> agents=<N> r6='<Reviewer 6 design-bearing= line>' [summary='<criticals>']. The verb exits per /kit:spec step 5. Override: incomplete <rid> --stale "<reason>" here is a stop, not a re-open: the item stays REPORTED. On the report:

  • APPROVED: after close exits 0, the lead resumes the worker with SendMessage to build; the warnings go to docs/implementation-notes/<slug>.md for the builder, not into the spec.
  • NEEDS-REVISION, the first time: the lead resumes the worker to fold the findings, commit, and stop again with VALIDATE PENDING, then validates once more.
  • NEEDS-REVISION on the re-run, with operator_directed_build: true in the brief (set only when the operator directed the build): the lead resumes the worker to fold, commit, and stop with VALIDATE PENDING, then re-validates once more (all reviewers), then stops either way; a NEEDS-REVISION on that last round follows the REPORTED bullet below.
  • An incomplete round (a reviewer dead twice, or the restart budget spent): the lead runs validate-round incomplete <rid> <token> "<reason>" and the item stays REPORTED with reported: spec-validate incomplete: <reason>; the worker is not resumed. Validation fan-outs run one round at a time across items, so a rate limit cannot kill every reviewer at once.
  • A Reviewer 6 BLOCK, or NEEDS-REVISION on the re-run without operator_directed_build: true: the lead runs validate-round close with verdict=NEEDS-REVISION and the item stays REPORTED with reported: spec-validate BLOCK|NEEDS-REVISION: <criticals>; the worker is not resumed, and the committed spec stays on the branch for the operator.

A worker that cannot be resumed is replaced by a fresh builder on the same worktree, given the committed spec and the report. The resumed worker (or fresh builder) builds, keeps docs/implementation-notes/<slug>.md (its deltas from the spec, or the one line No deviations; matches the spec verbatim; the ship-gate refuses a full-lane push without it, and a subagent never receives the prompt-level notes rule, so the brief is where it arrives), runs a negative control with lib/gate/negctl.sh, writes the proof-of-done, records the remaining gate-ledger entries the home repo's ship-gate expects, and commits. Before the draft push, the lead runs bin/wrap rebase <wt> (the branch has never been pushed, so rewriting it is safe) and, when it printed rebased (HEAD moved), re-runs the worker's verification command in <wt>, the same rule as landing step 2 below. The lead then opens the PR as a DRAFT with the verb: bin/wrap land --draft <wt> --title "<the feature commit subject the worker reported>" --body-file <wt>/docs/verification/<slug>.md. The verb runs the refusals land runs before its push, calls the ship-gate with the worktree as its cwd (so it checks the home repo, not the session's), pushes the branch, opens the draft, and stops: no merge, no tidy. Run the installed bin/wrap from the session cwd, never the worktree's copy: a kit branch must not gate itself with its own hooks/ship-gate.sh. The --body-file path is absolute for the same reason. The branch's first commit is the spec, so no fill flag gives the feature title. Once the draft is open, the lead removes the clean worktree with git -C <home> worktree remove <wt>; the branch lives on origin.

Wrap never merges a full-lane PR, green or not. A full lane marks an architecture, auth, data-model, or contract change, and its design is the one thing the operator must see before it lands: an unattended validator checks the spec, not the direction, and cannot stand in for the operator's direction call (AGENTS.md "Pause if"). Two things hold that line after this pass ends: wrap merge --apply skips a draft, and no worktree is left for a later wrap's step 3 to hand to wrap land, which would mark the draft ready and merge it. Plain wrap land and wrap merge never run on it here (wrap land --draft is the one land form allowed, because it never merges); the second report lists it OPEN under Shipped and adds REVIEW #<pr>: <why it needs design review> to Needs you. The operator marks it ready after the review.

Land, one repo at a time, after the last worker reports. An OPEN-PR item has no worker and enters at step 3 below; a set of only OPEN-PR items starts landing at once. Per built (a) or (b) branch, one at a time:

  1. Size the real diff: bash lib/classify/lane-classify.sh risk --files "$(git -C <wt> diff --name-only origin/<default>...HEAD)" "<the item>". A branch that now sizes full (it touched auth, a hook, a data model, a contract) takes the full-lane path above instead: draft PR, worktree removed, REVIEW #<pr> in Needs you, never merged. This holds in lanes mode too.
  2. Run bin/wrap rebase <wt> first. rebase is the never-pushed path only: once a branch sits on origin a divergence is never rewritten, and a PR that reads CONFLICTING there takes the same merge cycle wrap land runs (origin/<default> merged in, not a rebase). It prints nothing to rebase when the branch already holds origin/<default>. When it prints rebased ... instead (HEAD moved), re-run the worker's verification command in <wt>. A red re-run keeps the item REPORTED with the failing check as its why. So does a refusal: REFUSED, MARKERS, GENERATOR FAILED, STOP BOUND or ABORT FAILED mean the rebase stopped (the verb restored the old tip, except after ABORT FAILED), and a line starting AFTER REBASE means the branch is rebased but its final regeneration is not committed. The worktree stays under Left alone in every case. Then push and open the PR from inside the worktree, so the home repo's ship-gate judges it: cd <wt> && git push -u origin HEAD:<branch>, then cd <wt> && gh pr create --head <branch> --fill-first. A ship-gate refusal (a missing proof, a missing gate) is never overridden here: the item stays REPORTED with the gate's reason, and the worktree stays under Left alone.
  3. Re-run the step 0 check for the repo. wrap.merge_own_prs false: stop here; Shipped lists the PR OPEN and Left alone lists the worktree. A foreign-activity stop does not end the landing: step 4 merges with --no-pull added, under the step 0 rules, and a PR the main checkout holds stays OPEN the same way.
  4. Wait for the PR's checks: gh pr checks <n> --watch. Then bin/wrap merge --apply --pr <n> <repo> (a stopped repo adds --no-pull): it merges only an own PR that _pr_gate calls green, then verifies the default branch holds the PR head. Never wrap land here, because land merges right after it opens a PR and never reads the checks. A SKIP (checks red, changes requested, not mergeable; exit 4) or a TREE MISMATCH (exit 3) is reported by name and the PR stays OPEN.
  5. Tidy through step 5's own-scope path once the merge is proven: bin/wrap apply --own <wt> <repo>, the dry run, then --apply; a stopped repo adds --no-pull.

No timer runs here: a worker is bounded by the Agent tool's own lifecycle, and the lead lands whatever reported. A worker that never reports (the session closed, the agent died) leaves its worktree; the next wrap's scan lists it under Left alone, and wrap apply never removes a branch no merge proof covers. Every refusal above step 10 still holds: never merge a PR the operator did not open, never force-push, never remove a dirty or foreign worktree, and a TREE MISMATCH is a merge that did not land.

The second report. When the landing ends, print it in step 9's grammar under its own heading, and lint it with bash lib/wrap/report-lint.sh <file> before printing:

## Follow-through: <session slug, the same as the first report>

✅ **Needs you:** NOTHING
   -- or, with a full-lane PR or a new blocker --
🔴 **Needs you:**
a. REVIEW #<pr>: <why it needs design review>.

**What happened**
- <each FYI follow-up finished, past tense>

**Shipped**
| Repo | PR | Merge | Deploy |

**Built:**
- BUILT <label> ENHANCE <home>: <file> (lane=normal, verified: <check>, #<pr>)
- BUILT <label> NEW (precedent: nothing matched): <path> (lane=full, verified: <check>, #<pr> DRAFT)
- REPORTED <label> ... (lane=<lane>, reported: <why it still did not land>)

**FYI:**
| Tag | Fact | Home |

Its Needs you lists only what step 10 produced (a REVIEW item, a new blocker); the first report's items were printed once and are not repeated. The first ## line decides which report it is. A follow-through report carries no **Seam:** line, because the seams ran in the first report, and the lint exempts it from that one rule; **Built:**, Needs you, and FYI keep every rule. A lane=full item closed with verified: passes only in a follow-through report, only as #<pr> DRAFT, and only when a lettered Needs you item opening with REVIEW names the same #<pr>, so a full-lane build can never read as landed. Record it and close the bracket: bash lib/gate/gate-ledger.sh record <rid> wrap-follow ran "<n> built, <m> finished, <k> full-lane drafts", then bash lib/gate/gate-ledger.sh outcome <rid> wrap-follow end caught=<true if any item stayed REPORTED, else false>, with the rid from step 7a; a refused rid prints skipped (structural): wrap-follow record impossible this run (<reason>) instead, the same as the DEBT marker.

What this command does NOT do

  • Never force-pushes.
  • Never rewrites history. The one exception is the operator-named merge --pr <n> --rebase-stacked, which pushes the PR's own non-default branch with --force-with-lease at the head it gated and refuses on any conflict.
  • Never merges a PR the operator did not open.
  • Never merges a full-lane PR that step 10 built; it opens as a draft and goes to Needs you as REVIEW #<pr>.
  • Never touches a dirty file.
  • Never removes a dirty or foreign worktree, except a stale one under the operator-named --archive-worktrees, after its snapshot is on origin.
  • Never dispatches a deploy on its own initiative; it checks one the operator already dispatched or asked it to dispatch as part of this pass.