wendkeep 0.78.0 → 0.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.en.md +58 -3
  3. package/README.md +58 -3
  4. package/docs/en/commands/changes-and-verification.md +116 -1
  5. package/docs/en/commands/operating-profiles.md +49 -5
  6. package/docs/en/commands/sessions-and-import.md +6 -0
  7. package/docs/en/commands/verify.md +54 -0
  8. package/docs/en/commands/worktrees.md +39 -4
  9. package/docs/pt-BR/commands/changes-and-verification.md +115 -1
  10. package/docs/pt-BR/commands/operating-profiles.md +51 -5
  11. package/docs/pt-BR/commands/sessions-and-import.md +7 -0
  12. package/docs/pt-BR/commands/verify.md +53 -0
  13. package/docs/pt-BR/commands/worktrees.md +38 -3
  14. package/hooks/active-context-store.mjs +530 -2
  15. package/hooks/change-core.mjs +220 -123
  16. package/hooks/obsidian-common.mjs +175 -9
  17. package/hooks/session-stop.mjs +40 -1
  18. package/hooks/spec-core.mjs +93 -29
  19. package/package.json +2 -2
  20. package/packages/cli/src/index.mjs +7 -0
  21. package/packages/vault/src/memory-handoff.mjs +15 -0
  22. package/schema/artifact-manifest-v1.schema.json +35 -0
  23. package/schema/handoff-contract-v1.schema.json +37 -0
  24. package/schema/task-contract-v1.schema.json +57 -0
  25. package/schema/wendkeep.provenance-receipt-v2.schema.json +66 -0
  26. package/src/archive-operation-lock.mjs +235 -0
  27. package/src/change.mjs +1780 -79
  28. package/src/delivery.mjs +724 -67
  29. package/src/memory.mjs +2 -1
  30. package/src/provenance-gate.mjs +575 -0
  31. package/src/provenance-sources.mjs +547 -0
  32. package/src/receipt-ledger.mjs +841 -0
  33. package/src/release-provenance.mjs +48 -0
  34. package/src/task-contracts.mjs +510 -0
  35. package/src/task-leases.mjs +105 -0
  36. package/src/task.mjs +115 -0
  37. package/src/verify.mjs +32 -0
  38. package/src/worktree-cleanup.mjs +1733 -118
  39. package/src/worktree.mjs +94 -5
package/CHANGELOG.md CHANGED
@@ -4,6 +4,73 @@ All notable changes to **wendkeep** are documented here. Format based on
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); this project follows
5
5
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.80.0] — 2026-08-24
8
+
9
+ ### Added
10
+
11
+ - **Task Contract v1.** `wendkeep task list/show/evaluate/claim/release` deriva contratos tipados
12
+ da change e do active context, com IDs estáveis, hashes de HEAD/tarefas/spec/manifesto,
13
+ diagnósticos estruturados e leases exclusivos recuperáveis sob o lock do `SESSION_REGISTRY`.
14
+ - **Artifact gates bounded.** Manifestos v1 suportam `name`, `path`, `glob` e `file-count`, com
15
+ fallback de filesystem explícito, ignores seguros, limites de tempo/quantidade e bloqueio de
16
+ path escape, symlink ou junction externo.
17
+ - **Handoff Contract v1.** SessionStop publica handoff causal com task, artifacts, Evidence
18
+ Envelope, decisões, próximas ações, blockers e hashes; ASSURE exige contrato verificado e
19
+ handoffs históricos permanecem `legacy-reported`.
20
+ - **Schemas e guias bilíngues.** Schemas públicos de task/handoff/artifacts, README e guias PT-BR/EN
21
+ documentam comandos, erros, recovery, autoridade e compatibilidade.
22
+
23
+ ### Changed
24
+
25
+ - **Execute → Verify machine-checkable.** `verify` preserva o Evidence Envelope recém-capturado,
26
+ grava `task-evaluation.json` e bloqueia sucesso/pacote deep quando checkbox, requisito, sensor,
27
+ artifact, dependência ou binding causal ainda estiver aberto; `[phase:verify]` separa a tarefa
28
+ final de revisão/arquivo sem enfraquecer o gate de archive.
29
+ - **Memória e Observer sem autoridade duplicada.** `handoff.latest` passa a transportar o contrato
30
+ estruturado verificado pela mesma outbox sanitizada; resumos heurísticos continuam apenas como
31
+ projeção reportada.
32
+
33
+ ## [0.79.0] — 2026-08-23
34
+
35
+ ### Added
36
+
37
+ - **Gate único de proveniência.** Archive, delivery, release e cleanup rederivam a autoridade no
38
+ subject atual com a taxonomia `verified`, `reported`, `legacy-unbound`, `stale`, `conflict` e
39
+ `unproven`; somente `verified` satisfaz prova obrigatória, com códigos e recovery sanitizados.
40
+ - **Fontes verificáveis.** Adapters injetáveis ligam Git, CI, tag, NPM e GitHub Release ao
41
+ repositório, target commit, package/version, integrity e notas esperados sem confiar em URL/claim
42
+ fornecida nem na worktree incidental.
43
+ - **Receipt Ledger v2.** Autorizações de archive e receipts de delivery/cleanup ganham sequência,
44
+ `previous_hash`, `receipt_hash`, lock, publicação atômica e checkpoint separado, com schema
45
+ público e replay idempotente.
46
+
47
+ ### Changed
48
+
49
+ - **Archive fail-closed.** Evidence Envelope v2, pacote deep e verdict completos/canônicos agora
50
+ são exigidos mesmo sem sensores; uma autorização v2 é encadeada antes da mutação e `--force`
51
+ continua limitado a tarefa aberta, sem pular proveniência.
52
+ - **Delivery e release ligadas ao destino.** Merge/push observam `<remote>/<branch>`, exigem
53
+ ancestralidade e preservam origin/worktree/branch do start; tag/publish derivam package e artefato
54
+ do target e verificam CI → commit → tag → versão/integrity → GitHub Release. Offline
55
+ permanece `reported` e não grava completion receipt.
56
+ - **Cleanup retomável e causal.** Finish/remove/prune validam o ledger antes da mutação, vinculam
57
+ todos os contextos, PR/head/merge e ator disponível, e retomam o mesmo operation ID após crash
58
+ antes/depois do append ou finalize; texto e `--json` preservam códigos e recovery sanitizados.
59
+ - **Compatibilidade explícita.** Ledgers v1 permanecem read-only como prefixo `legacy-unbound`;
60
+ no Windows com Node 18–22, receipts e operation locks tratam `st_dev=0` como metadado
61
+ indisponível quando o inode continua idêntico, sem aceitar identificadores de dispositivo
62
+ não-zero conflitantes; aquisições e liberações concorrentes relêem rotações e sharing
63
+ violations transitórias com limite estrito, e o release fecha e revalida o marker antes do
64
+ unlink nas runtimes antigas;
65
+ README, contrato do harness e guias de changes/verify/profiles/worktrees foram atualizados em
66
+ PT-BR/EN.
67
+
68
+ ### Security
69
+
70
+ - Adulteração intermediária, JSON parcial, cauda/checkpoint removidos, colisão de ID, locks
71
+ trocados por outro owner, writer concorrente e escape por symlink/junction passam a bloquear antes
72
+ da mutação; diagnósticos não persistem tokens nem paths privados.
73
+
7
74
  ## [0.78.0] — 2026-08-22
8
75
 
9
76
  ### Added
package/README.en.md CHANGED
@@ -239,10 +239,10 @@ The README is the map; the guides provide syntax, options, exit codes, examples,
239
239
  | Group | Use it for | Detailed guide |
240
240
  |---|---|---|
241
241
  | **Installation and updates** | `init`, `sync`, companions, and the first project↔vault binding | [Installation and first use](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/getting-started.md) |
242
- | **Managed worktrees** | `worktree create/list/status/open/finish/cleanup/remove/prune`, merge proof, preflight, and receipts | [Managed worktrees](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/worktrees.md) |
242
+ | **Managed worktrees** | `worktree create/list/status/open/finish/cleanup/remove/prune`, merge proof, preflight, crash-safe cleanup/common gate, and receipts | [Managed worktrees](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/worktrees.md) |
243
243
  | **Active context** | `active_contexts` by `repository_id`/`worktree_id`/`work_session_id`, causal transition, quarantine, and explicit recovery | [Active context](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/context.md) |
244
244
  | **Operating profiles** | `profile`, `flow`, always-on Keep Core, and Wend Runtime governance | [Operating profiles](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/operating-profiles.md) |
245
- | **Changes and verification** | `change`, specs, sensors, TDD, evidence, and archive | [Changes and verification](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/changes-and-verification.md) |
245
+ | **Changes and verification** | `change`, specs, sensors, TDD, evidence, Task Contracts, and archive | [Changes and verification](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/changes-and-verification.md) |
246
246
  | **Shared memory** | CORE, SHARED, status, validation, repair, and curation | [Memory](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/memory.md) |
247
247
  | **Sessions and import** | causal hooks, observability reconciliation, and Claude/Codex backfill | [Sessions and import](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/sessions-and-import.md) |
248
248
  | **Notes and knowledge** | BUG/APR/ADR, repairs, renumbering, lessons, and dashboard | [Notes and knowledge](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/notes-and-knowledge.md) |
@@ -352,9 +352,28 @@ an initialized registry never copies a global authorization without proven ident
352
352
  ```bash
353
353
  npx wendkeep delivery start release-0-74-0 --allow git:merge --allow git:push --allow publish --source-change <slug> --source-commit <sha> --session <id>
354
354
  npx wendkeep delivery status release-0-74-0 --session <id>
355
- npx wendkeep delivery finish release-0-74-0 --target main --ci-url <url> --version 0.74.0 --npm-integrity <sha512> --release-url <url> --session <id>
355
+ npx wendkeep delivery finish release-0-74-0 --target origin/main --ci-url <url> --version 0.74.0 --npm-integrity <sha512> --release-url <url> --session <id>
356
356
  ```
357
357
 
358
+ For `git:merge` and `git:push` capabilities, `delivery finish` requires
359
+ `--target <remote>/<branch>` (for example, `--target origin/main`). `delivery start` binds the
360
+ `origin` remote to the expected `repository`; during finish, the target is resolved again with
361
+ `git ls-remote`. If the target cannot be resolved or the origin/repository binding diverges, the
362
+ delivery is blocked before provenance adapters run.
363
+
364
+ The provenance gate re-derives authority against the current subject before archive, delivery,
365
+ release, or cleanup. Its single taxonomy is `verified`, `reported`, `legacy-unbound`, `stale`,
366
+ `conflict`, and `unproven`; only `verified` authorizes required proof. Evidence, a verdict, or a
367
+ receipt captured before amend/rebase, from another branch/worktree/session, or backed only by a
368
+ reported/offline external claim fails closed with objective recovery. New receipts use schema v2,
369
+ `previous_hash`, `receipt_hash`, and a separate checkpoint to detect tampering and truncation.
370
+ Stable codes are `WENDKEEP_PROVENANCE_GATE_BLOCKED`, `WENDKEEP_RECEIPT_LEDGER_BUSY`,
371
+ `WENDKEEP_RECEIPT_LEDGER_CONFLICT`, `WENDKEEP_RECEIPT_LEDGER_CORRUPT`, and
372
+ `WENDKEEP_RECEIPT_LEDGER_TRUNCATED`. Safe recovery reads `state`, `reasonCodes`, `diagnostics`,
373
+ and `repair.command` in `--json` output, runs `npx --no-install wendkeep verify --deep --json` or
374
+ the indicated status command, and recaptures proof; it never prints raw stderr, tokens, private URLs,
375
+ or Vault paths, and never edits the ledger/checkpoint.
376
+
358
377
  If the harness does not record a lease, a small fix remains under the configured profile —
359
378
  `GOVERN` by default. `OFF` does not mean “simple task”: it is a persistent human choice that hands
360
379
  governance to the native harness. The LLM may temporarily elevate an `OFF` base to a Wend route,
@@ -536,6 +555,42 @@ explore → propose → apply (TDD) → verify → archive
536
555
 
537
556
  > The gate blocks unless the scaffold is filled, no task is open, evidence is fresh, and every declared requirement is covered. **`--force` waives exactly one of those — the open-task check — and is the human's call, never the agent's.** An unfilled scaffold, a red critical sensor, stale evidence, an orphan requirement or a missing verdict block regardless.
538
557
 
558
+ After the fix, archive requires a **final** recapture with
559
+ `wendkeep verify --deep --change <slug>`. The package is complete and canonical; the verdict must
560
+ also be complete and canonical, with both bound to the same checkout, change, tasks, spec, and sensors. Before any mutation, the command
561
+ writes an authorization receipt to the separate `change-archive-receipts-v2` ledger; only after
562
+ that receipt is valid may it promote the spec/ADR or move the change. `change archive --json`
563
+ returns the serializable `state`, `reason_codes`, `diagnostics`, and `repair` fields. Corruption
564
+ or truncation in any ledger fails closed before mutation. `--force` does not bypass provenance,
565
+ integrity, package, verdict, corruption, or truncation; the exact recovery is the recapture above.
566
+
567
+ Archive sealing uses the runtime lock and a private ASCII transaction at
568
+ `.brain/runtime/archive-transactions/<uuid>/{original,authorized}`: it atomically renames the live
569
+ change to `original`, checks the digest, and promotes only `authorized`. On a seal or divergence
570
+ failure, it removes the snapshot and restores `original` without partial promotion. Multi-spec
571
+ promotion is one atomic unit: it captures before-images/digests, rolls back before/after writes,
572
+ and permits retry only after reconciliation and fresh verification. The post-release finalizer
573
+ validates original/destination digests, but the `completed` journal keeps the `original` retained;
574
+ no destructive cleanup is automatic. A failure leaves `published-recovery-required`. Text and --json
575
+ keep the same sanitized diagnostic (code, operation, state, blocker, expected, observed, recovery).
576
+
577
+ The archive uses a `directory lock` with a token-specific marker and lease: acquisition prepares a
578
+ sibling `.pending` directory and publishes it by atomic rename, uses no hardlink, and allows at most
579
+ 3 topology attempts. A live owner returns `WENDKEEP_ARCHIVE_BUSY`, a dead owner is safely reaped,
580
+ an invalid marker returns `WENDKEEP_ARCHIVE_LOCK_UNAVAILABLE`, and ownership loss returns
581
+ `WENDKEEP_ARCHIVE_LOCK_OWNERSHIP_LOST`. The transaction keeps `archive-transaction.json` with
582
+ phases `prepared` → `isolated` → `copied` → `sealed` → `published` → `promotion-prepared` →
583
+ `promotion-applied` → `completed` or `recovery-required`. A pending journal blocks a new archive for
584
+ the same slug before the gate. On
585
+ a collision/post-publication failure, `original` is retained and the state is
586
+ `published-recovery-required`; `operation_id` and `transaction_phase` are sanitized. Inspect it
587
+ with `wendkeep change archive recover <operation-id> --change <slug> [--spec-action rollback|resume] [--json]`:
588
+ without `--spec-action`, this is a read-only, fail-closed, idempotent operation that returns
589
+ sanitized actions without promoting or deleting. `rollback` restores before-images and `resume`
590
+ converges after-images for a `promotion-prepared` promotion, while retaining the journal for
591
+ reconciliation. When an operation ID exists, `repair.command` points to that recovery; do not treat
592
+ `command:null` as the normal flow.
593
+
539
594
  `wendkeep init` seeds process skills into the vault's `.brain/skills` and delivers identical copies to `.claude/skills/` and `.agents/skills/`; Codex gets the agent definitions (`.brain/agents/*.toml` → `.codex/agents/`) plus a managed section in `AGENTS.md` that indexes the skills. Every skill carries source hash/version metadata; `doctor` warns when reseed + agent restart is required.
540
595
 
541
596
  ### The loop in five minutes
package/README.md CHANGED
@@ -239,10 +239,10 @@ The README is the map; the guides provide syntax, options, exit codes, examples,
239
239
  | Group | Use it for | Detailed guide |
240
240
  |---|---|---|
241
241
  | **Installation and updates** | `init`, `sync`, companions, and the first project↔vault binding | [Installation and first use](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/getting-started.md) |
242
- | **Managed worktrees** | `worktree create/list/status/open/finish/cleanup/remove/prune`, merge proof, preflight, and receipts | [Managed worktrees](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/worktrees.md) |
242
+ | **Managed worktrees** | `worktree create/list/status/open/finish/cleanup/remove/prune`, merge proof, preflight, crash-safe cleanup/common gate, and receipts | [Managed worktrees](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/worktrees.md) |
243
243
  | **Active context** | `active_contexts` by `repository_id`/`worktree_id`/`work_session_id`, causal transition, quarantine, and explicit recovery | [Active context](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/context.md) |
244
244
  | **Operating profiles** | `profile`, `flow`, always-on Keep Core, and Wend Runtime governance | [Operating profiles](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/operating-profiles.md) |
245
- | **Changes and verification** | `change`, specs, sensors, TDD, evidence, and archive | [Changes and verification](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/changes-and-verification.md) |
245
+ | **Changes and verification** | `change`, specs, sensors, TDD, evidence, Task Contracts, and archive | [Changes and verification](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/changes-and-verification.md) |
246
246
  | **Shared memory** | CORE, SHARED, status, validation, repair, and curation | [Memory](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/memory.md) |
247
247
  | **Sessions and import** | causal hooks, observability reconciliation, and Claude/Codex backfill | [Sessions and import](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/sessions-and-import.md) |
248
248
  | **Notes and knowledge** | BUG/APR/ADR, repairs, renumbering, lessons, and dashboard | [Notes and knowledge](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/notes-and-knowledge.md) |
@@ -352,9 +352,28 @@ an initialized registry never copies a global authorization without proven ident
352
352
  ```bash
353
353
  npx wendkeep delivery start release-0-74-0 --allow git:merge --allow git:push --allow publish --source-change <slug> --source-commit <sha> --session <id>
354
354
  npx wendkeep delivery status release-0-74-0 --session <id>
355
- npx wendkeep delivery finish release-0-74-0 --target main --ci-url <url> --version 0.74.0 --npm-integrity <sha512> --release-url <url> --session <id>
355
+ npx wendkeep delivery finish release-0-74-0 --target origin/main --ci-url <url> --version 0.74.0 --npm-integrity <sha512> --release-url <url> --session <id>
356
356
  ```
357
357
 
358
+ For `git:merge` and `git:push` capabilities, `delivery finish` requires
359
+ `--target <remote>/<branch>` (for example, `--target origin/main`). `delivery start` binds the
360
+ `origin` remote to the expected `repository`; during finish, the target is resolved again with
361
+ `git ls-remote`. If the target cannot be resolved or the origin/repository binding diverges, the
362
+ delivery is blocked before provenance adapters run.
363
+
364
+ The provenance gate re-derives authority against the current subject before archive, delivery,
365
+ release, or cleanup. Its single taxonomy is `verified`, `reported`, `legacy-unbound`, `stale`,
366
+ `conflict`, and `unproven`; only `verified` authorizes required proof. Evidence, a verdict, or a
367
+ receipt captured before amend/rebase, from another branch/worktree/session, or backed only by a
368
+ reported/offline external claim fails closed with objective recovery. New receipts use schema v2,
369
+ `previous_hash`, `receipt_hash`, and a separate checkpoint to detect tampering and truncation.
370
+ Stable codes are `WENDKEEP_PROVENANCE_GATE_BLOCKED`, `WENDKEEP_RECEIPT_LEDGER_BUSY`,
371
+ `WENDKEEP_RECEIPT_LEDGER_CONFLICT`, `WENDKEEP_RECEIPT_LEDGER_CORRUPT`, and
372
+ `WENDKEEP_RECEIPT_LEDGER_TRUNCATED`. Safe recovery reads `state`, `reasonCodes`, `diagnostics`,
373
+ and `repair.command` in `--json` output, runs `npx --no-install wendkeep verify --deep --json` or
374
+ the indicated status command, and recaptures proof; it never prints raw stderr, tokens, private URLs,
375
+ or Vault paths, and never edits the ledger/checkpoint.
376
+
358
377
  If the harness does not record a lease, a small fix remains under the configured profile —
359
378
  `GOVERN` by default. `OFF` does not mean “simple task”: it is a persistent human choice that hands
360
379
  governance to the native harness. The LLM may temporarily elevate an `OFF` base to a Wend route,
@@ -536,6 +555,42 @@ explore → propose → apply (TDD) → verify → archive
536
555
 
537
556
  > The gate blocks unless the scaffold is filled, no task is open, evidence is fresh, and every declared requirement is covered. **`--force` waives exactly one of those — the open-task check — and is the human's call, never the agent's.** An unfilled scaffold, a red critical sensor, stale evidence, an orphan requirement or a missing verdict block regardless.
538
557
 
558
+ After the fix, archive requires a **final** recapture with
559
+ `wendkeep verify --deep --change <slug>`. The package is complete and canonical; the verdict must
560
+ also be complete and canonical, with both bound to the same checkout, change, tasks, spec, and sensors. Before any mutation, the command
561
+ writes an authorization receipt to the separate `change-archive-receipts-v2` ledger; only after
562
+ that receipt is valid may it promote the spec/ADR or move the change. `change archive --json`
563
+ returns the serializable `state`, `reason_codes`, `diagnostics`, and `repair` fields. Corruption
564
+ or truncation in any ledger fails closed before mutation. `--force` does not bypass provenance,
565
+ integrity, package, verdict, corruption, or truncation; the exact recovery is the recapture above.
566
+
567
+ Archive sealing uses the runtime lock and a private ASCII transaction at
568
+ `.brain/runtime/archive-transactions/<uuid>/{original,authorized}`: it atomically renames the live
569
+ change to `original`, checks the digest, and promotes only `authorized`. On a seal or divergence
570
+ failure, it removes the snapshot and restores `original` without partial promotion. Multi-spec
571
+ promotion is one atomic unit: it captures before-images/digests, rolls back before/after writes,
572
+ and permits retry only after reconciliation and fresh verification. The post-release finalizer
573
+ validates original/destination digests, but the `completed` journal keeps the `original` retained;
574
+ no destructive cleanup is automatic. A failure leaves `published-recovery-required`. Text and --json
575
+ keep the same sanitized diagnostic (code, operation, state, blocker, expected, observed, recovery).
576
+
577
+ The archive uses a `directory lock` with a token-specific marker and lease: acquisition prepares a
578
+ sibling `.pending` directory and publishes it by atomic rename, uses no hardlink, and allows at most
579
+ 3 topology attempts. A live owner returns `WENDKEEP_ARCHIVE_BUSY`, a dead owner is safely reaped,
580
+ an invalid marker returns `WENDKEEP_ARCHIVE_LOCK_UNAVAILABLE`, and ownership loss returns
581
+ `WENDKEEP_ARCHIVE_LOCK_OWNERSHIP_LOST`. The transaction keeps `archive-transaction.json` with
582
+ phases `prepared` → `isolated` → `copied` → `sealed` → `published` → `promotion-prepared` →
583
+ `promotion-applied` → `completed` or `recovery-required`. A pending journal blocks a new archive for
584
+ the same slug before the gate. On
585
+ a collision/post-publication failure, `original` is retained and the state is
586
+ `published-recovery-required`; `operation_id` and `transaction_phase` are sanitized. Inspect it
587
+ with `wendkeep change archive recover <operation-id> --change <slug> [--spec-action rollback|resume] [--json]`:
588
+ without `--spec-action`, this is a read-only, fail-closed, idempotent operation that returns
589
+ sanitized actions without promoting or deleting. `rollback` restores before-images and `resume`
590
+ converges after-images for a `promotion-prepared` promotion, while retaining the journal for
591
+ reconciliation. When an operation ID exists, `repair.command` points to that recovery; do not treat
592
+ `command:null` as the normal flow.
593
+
539
594
  `wendkeep init` seeds process skills into the vault's `.brain/skills` and delivers identical copies to `.claude/skills/` and `.agents/skills/`; Codex gets the agent definitions (`.brain/agents/*.toml` → `.codex/agents/`) plus a managed section in `AGENTS.md` that indexes the skills. Every skill carries source hash/version metadata; `doctor` warns when reseed + agent restart is required.
540
595
 
541
596
  ### The loop in five minutes
@@ -29,8 +29,11 @@ npx wendkeep change new <slug> [--simple|--guide] [--session <id>]
29
29
  npx wendkeep change status [slug] [--session <id>]
30
30
  npx wendkeep spec effective [--change <slug>] [--session <id>]
31
31
  npx wendkeep sensors list
32
+ npx wendkeep task list [--change <slug>] [--session <id>] [--json]
33
+ npx wendkeep task evaluate <task-id> [--change <slug>] [--session <id>] [--json]
32
34
  npx wendkeep verify [--deep] [--change <slug>] [--session <id>]
33
- npx wendkeep change archive <slug> [--session <id>]
35
+ npx wendkeep change archive <slug> [--json] [--session <id>]
36
+ npx wendkeep change archive recover <operation-id> --change <slug> [--spec-action rollback|resume] [--json]
34
37
  ```
35
38
 
36
39
  ## Options and exit codes
@@ -47,6 +50,12 @@ npx wendkeep change archive <slug> [--session <id>]
47
50
  only one unambiguous active context for the worktree is accepted; ambiguity returns exit `2`.
48
51
  - `change relink [--apply]` and `change backlink [--apply]` repair graph links; preview is default.
49
52
  - `change abandon <slug>` drops work without an ADR; `archive --force` needs explicit human choice.
53
+ - `task list/show/evaluate` derives read-only contracts from change authorship. `task claim/release`
54
+ controls owner/lease in the causal active context.
55
+ - `change archive recover <operation-id> --change <slug> [--spec-action rollback|resume]` inspects a
56
+ pending transaction by default; with `rollback` or `resume`, it converges only the spec
57
+ promotion prepared in the journal, under the operation lock and validation. It never promotes the
58
+ change, deletes the journal, or invents reconciliation.
50
59
  - `wendkeep spec list|show|effective|migrate|rebase` manages living contracts and deltas.
51
60
  - `wendkeep sensors list|add` manages executable proof.
52
61
  - Exit `0` means completion; gates use exit `1` for red proof and exit `2` for invalid
@@ -83,6 +92,112 @@ proven checkout. On a mismatch, return to the correct worktree/session and rerun
83
92
  `verify --deep`, and `wk-verify`. Fields, text/binary normalization, error codes, and recovery are
84
93
  detailed in the [verify guide](verify.md).
85
94
 
95
+ The common gate reclassifies the envelope, package, and verdict as `verified`, `reported`,
96
+ `legacy-unbound`, `stale`, `conflict`, or `unproven`; only `verified` permits archive. A block
97
+ returns `WENDKEEP_PROVENANCE_GATE_BLOCKED`: stabilize/recover the context, run `verify`, then
98
+ `verify --deep`, and request a fresh `wk-verify` pass. `--force` may waive only an open task; for
99
+ provenance, integrity, package, and verdict it does **not** change the result or promote a spec/ADR.
100
+ Ledger errors are `WENDKEEP_RECEIPT_LEDGER_BUSY`, `WENDKEEP_RECEIPT_LEDGER_CONFLICT`,
101
+ `WENDKEEP_RECEIPT_LEDGER_CORRUPT`, and `WENDKEEP_RECEIPT_LEDGER_TRUNCATED`. On a block, use the
102
+ sanitized `--json` output (`state`, `reasonCodes`, `diagnostics`, `repair.command`), execute the
103
+ indicated recovery, and run `npx --no-install wendkeep verify --deep --json`; preserve and recapture
104
+ proof without editing the ledger/checkpoint or exposing stderr, tokens, private URLs, or Vault paths.
105
+
106
+ ### Post-fix archive contract
107
+
108
+ Before mutation, perform the final recapture with `wendkeep verify --deep --change <slug>`. The
109
+ package and verdict must be complete and canonical, bound to the same checkout, change, tasks,
110
+ spec, and sensors. Archive first writes an authorization receipt to the separate
111
+ `change-archive-receipts-v2` ledger; only after it validates may it promote the spec/ADR or move
112
+ the change. `change archive --json` returns the serializable `state`, `reason_codes`,
113
+ `diagnostics`, and `repair` fields. Corruption or truncation in the proof or archive ledger fails
114
+ closed before any write. `--force` does not bypass provenance or integrity, package/verdict,
115
+ corruption, or truncation. The exact recovery is to repeat
116
+ `wendkeep verify --deep --change <slug>` in the correct checkout.
117
+
118
+ The mutation acquires the runtime lock `.brain/runtime/change-archive-operation.lock` and opens a
119
+ private ASCII transaction at `.brain/runtime/archive-transactions/<uuid>/{original,authorized}`.
120
+ It atomically renames the live change to `original`, checks the digest, and promotes only the
121
+ `authorized` copy; the public namespace is never a publication source. On a seal or divergence
122
+ failure with `WENDKEEP_ARCHIVE_INPUT_CHANGED` before promotion, the `authorized` snapshot is
123
+ removed and `original` is restored without partial promotion. A successful archive keeps the
124
+ `completed` journal; the post-release finalizer validates the digests of `original` and the
125
+ published destination but retains `original` and the transaction, with no automatic destructive
126
+ cleanup.
127
+
128
+ The archive lock is a `directory lock`: the canonical directory contains a token-specific marker
129
+ and lease. Acquisition prepares a sibling `.pending` directory, writes owner/lease, and publishes
130
+ it by atomic rename; it uses no hardlink and re-observes collisions for at most 3 topology attempts.
131
+ A live owner returns `WENDKEEP_ARCHIVE_BUSY`; a dead owner may be safely reaped without deleting a
132
+ successor. Invalid structure or marker returns `WENDKEEP_ARCHIVE_LOCK_UNAVAILABLE`; ownership loss
133
+ returns `WENDKEEP_ARCHIVE_LOCK_OWNERSHIP_LOST`.
134
+
135
+ Each operation keeps an `archive-transaction.json` manifest with phases `prepared` → `isolated` →
136
+ `copied` → `sealed` → `published` → `promotion-prepared` → `promotion-applied` → `completed` or
137
+ `recovery-required`. A pending journal blocks a new archive for the same slug before the gate. On a
138
+ collision or post-publication failure, `original` is retained and the state is
139
+ `published-recovery-required`. Use the fail-closed, idempotent inspection
140
+ `wendkeep change archive recover <operation-id> --change <slug> [--spec-action rollback|resume] [--json]`;
141
+ without `--spec-action` it only returns sanitized actions. `rollback` converges before-images and
142
+ `resume` converges after-images for a `promotion-prepared` promotion; both retain the journal for
143
+ further reconciliation.
144
+
145
+ Multi-spec promotion is one atomic unit: it captures before-images/digests for every capability,
146
+ rolls back every target (including state/README) on a before- or after-write failure, and permits a
147
+ retry only after journal reconciliation and fresh verification. The post-release finalizer validates
148
+ the original/destination digests but retains the `completed` journal and `original`; no destructive
149
+ cleanup is automatic. Sanitized `operation_id` and
150
+ `transaction_phase` fields accompany the diagnostic; `repair.command` points to
151
+ `wendkeep change archive recover <operation-id> --change <slug>` when an operation is identified.
152
+ Text and --json use the same sanitized diagnostic with code, operation, state, blocker, expected,
153
+ observed, recovery, reason_codes, diagnostics, and repair.
154
+
155
+ ## Task Contracts, artifacts, and handoffs
156
+
157
+ Task Contract v1 is a rebuildable projection whose authorship remains in `tarefas.md`, the
158
+ effective spec, and the change's `artifacts.json`. The contract neither copies spec text nor infers
159
+ a requirement from chat. Project, active context, HEAD, and tasks/spec/manifest hashes bind the
160
+ projection; any mismatch yields `stale`.
161
+
162
+ ```markdown
163
+ - [ ] 2.3 produce report [req:REP-1] [sensor:tests] [depends:2.2] [artifact:report]
164
+ - [ ] 9.1 review the deep package and archive [req:REP-1] [phase:verify]
165
+ ```
166
+
167
+ ```powershell
168
+ npx wendkeep task list --session <id> [--change <slug>] [--json]
169
+ npx wendkeep task show 2.3 --session <id> [--json]
170
+ npx wendkeep task evaluate 2.3 --session <id> [--json]
171
+ npx wendkeep task claim 2.3 --session <id> [--lease-seconds 900] [--json]
172
+ npx wendkeep task release 2.3 --session <id> [--json]
173
+ ```
174
+
175
+ `list`, `show`, and `evaluate` do not write. `claim` and `release` use the atomic
176
+ `SESSION_REGISTRY` lock, are scoped by repository/worktree/work session/change/task, and reject a
177
+ concurrent owner. An expired lease can be recovered; release by a non-owner fails with
178
+ `TASK_LEASE_NOT_OWNER`.
179
+
180
+ An artifact manifest uses `schema_version: 1` and an `artifacts` list; each named entry may use
181
+ type `name`, `path`, `glob`, or `file-count`. The `fromFilesystem` fallback is explicit, never reads
182
+ content, ignores `.git`, `.worktrees`, `node_modules`, and `dist`, has time/entry limits, and fails
183
+ closed on path escape or an external symlink/junction.
184
+
185
+ A checkbox is an authored signal, not proof. `task evaluate` returns `can_complete`, missing
186
+ requirements, sensors, artifacts, dependencies, and `blocking_findings`. In a causal active
187
+ context, `verify` may write `evidencia.json`, but it cannot report success or create the deep
188
+ package while any default `execute` task is blocked; diagnostics live in `task-evaluation.json`.
189
+ Use `[phase:verify]` only for the review/archive task that necessarily runs after the deep package:
190
+ it does not participate in the Execute → Verify gate, remains blocked in individual evaluation,
191
+ and must still be completed before `change archive`.
192
+
193
+ SessionStop binds source/target, task, artifacts, Evidence Envelope, decisions, next actions,
194
+ blockers, and HEAD/tasks/spec hashes. ASSURE requires a verified Handoff Contract v1; it is optional
195
+ in other profiles. Historical summaries remain `legacy-reported`. Shared memory, brain injection,
196
+ and Observer consume the same sanitized projection.
197
+
198
+ Public schemas: `schema/task-contract-v1.schema.json`,
199
+ `schema/artifact-manifest-v1.schema.json`, and `schema/handoff-contract-v1.schema.json`.
200
+
86
201
  ## Tool-scope fence
87
202
 
88
203
  `change-guard` is also projected to Codex `PreToolUse`. Before a Git mutation or supported writing
@@ -59,7 +59,7 @@ npx wendkeep flow finish <id> [--session <id>]
59
59
  npx wendkeep flow promote <id> [--change-slug <slug>] [--session <id>]
60
60
  npx wendkeep delivery start [id] --allow <capability> [--source-change <slug>] [--source-commit <sha>] [--session <id>]
61
61
  npx wendkeep delivery status [id] [--session <id>]
62
- npx wendkeep delivery finish [id] [--target <ref>] [--ci-url <url>] [--version <x.y.z>] [--npm-integrity <sha512>] [--release-url <url>] [--session <id>]
62
+ npx wendkeep delivery finish [id] [--target <remote>/<branch>] [--ci-url <url>] [--version <x.y.z>] [--npm-integrity <sha512>] [--release-url <url>] [--session <id>]
63
63
  npx wendkeep delivery abandon [id] --reason <text> [--session <id>]
64
64
  ```
65
65
 
@@ -180,13 +180,36 @@ ownership to the native LLM harness.
180
180
  `contract_impact`, and `operation_risk` are independent dimensions. `delivery start` captures
181
181
  repo, branch/worktree, SHA, source change, and capabilities in `.brain/runtime/deliveries/`;
182
182
  it creates no `08-Changes` folder, delta, spec, or ADR.
183
- - `delivery finish` requires a clean worktree, proves that the target contains the source commit,
184
- and for `publish` requires CI, version, npm integrity, and GitHub Release evidence. Receipts are
185
- append-only in `.brain/runtime/delivery-receipts.jsonl`. If code/config must change, delivery
186
- stops with `WENDKEEP_DELIVERY_IMPLEMENTATION_REQUIRED` and work returns to implementation.
183
+ - For `git:merge` and `git:push` capabilities, `delivery finish` requires `--target
184
+ <remote>/<branch>` (for example, `--target origin/main`). `delivery start` binds the `origin`
185
+ remote to the expected `repository`; `finish` resolves the target with `git ls-remote` and blocks
186
+ the delivery before provenance adapters if the target cannot be resolved or the binding diverges.
187
+ - `delivery finish` requires a clean worktree and re-derives source/target. Merge/push proves
188
+ ancestry; tag proves package/version and the target tag; `publish` queries CI, NPM, and GitHub
189
+ Release bound to the same commit, version, integrity, and notes. Offline, a claim remains
190
+ `reported` and never becomes `verified`; completion blocks without writing a receipt. New
191
+ receipts form `.brain/runtime/delivery-receipts-v2.jsonl`, with a hash chain and checkpoint; v1
192
+ is only `legacy-unbound`. `WENDKEEP_PROVENANCE_GATE_BLOCKED` provides recovery. If code/config
193
+ must change, `WENDKEEP_DELIVERY_IMPLEMENTATION_REQUIRED` returns work to implementation.
194
+ The gate uses the same taxonomy: `verified`, `reported`, `legacy-unbound`, `stale`, `conflict`, and
195
+ `unproven`. Ledger errors are `WENDKEEP_RECEIPT_LEDGER_BUSY`,
196
+ `WENDKEEP_RECEIPT_LEDGER_CONFLICT`, `WENDKEEP_RECEIPT_LEDGER_CORRUPT`, and
197
+ `WENDKEEP_RECEIPT_LEDGER_TRUNCATED`; inspect sanitized `state`, `reasonCodes`, `diagnostics`, and
198
+ `repair.command` in `--json`, execute the indicated recovery, and recapture proof without editing
199
+ the ledger/checkpoint or exposing stderr, tokens, private URLs, or Vault paths.
187
200
  - In a multi-context Vault, `active_contexts[].delivery_id` is authoritative. `--session <id>`
188
201
  selects the work session explicitly; without it, only one unambiguous active context for the
189
202
  worktree may be used. Implicit status, finish, and abandon resolve that binding, not a global pointer.
203
+ - `delivery` failures expose the same PROV-8 diagnostic in text and in `delivery --json`: a stable
204
+ `code`, `operation`, `state`, first `blocker`, sanitized `expected`/`observed`, and an objective
205
+ `recovery`. Git stderr, tokens, private URLs, and private paths are not propagated.
206
+ - `delivery.completed` and `delivery.abandoned` receipts bind `repository_id`, the public
207
+ `repository` in `owner/repo` form, `worktree_id`, `work_session_id`, `change_slug`, and `branch`.
208
+ The private worktree path never enters the receipt. During contextual finalization, the receipt
209
+ enters the ledger and durable state is written before clearing `active_contexts[].delivery_id`.
210
+ A retry converges to the same receipt whether the binding is already clear or still bound. For
211
+ `delivery abandon`, the free-form reason becomes `reason_digest`; raw text does not enter the
212
+ ledger or state.
190
213
  - `CURRENT_DELIVERY` is only a derived projection: it contains the ID for one single, unambiguous
191
214
  active context with delivery and stays empty with zero or multiple contexts.
192
215
  `WENDKEEP_DELIVERY_CONTEXT_MISMATCH` means the explicit ID belongs to another context; neither
@@ -275,6 +298,27 @@ remain available and run their own contracts. A completed FLOW leaves a durable,
275
298
  receipt; a promoted FLOW enters the normal change lifecycle. Completed delivery leaves a receipt
276
299
  without an ADR; compact GUIDE archives its result without artificial spec/design/ADR.
277
300
 
301
+ For archive in GOVERN/ASSURE, the `directory lock` uses a token-specific marker and lease:
302
+ acquisition prepares a sibling `.pending` directory and publishes it by atomic rename, uses no
303
+ hardlink, and allows at most 3 topology attempts. A live owner returns `WENDKEEP_ARCHIVE_BUSY`, a
304
+ dead owner may be safely reaped, an invalid marker returns `WENDKEEP_ARCHIVE_LOCK_UNAVAILABLE`, and
305
+ ownership loss returns `WENDKEEP_ARCHIVE_LOCK_OWNERSHIP_LOST`. The `archive-transaction.json`
306
+ journal moves through `prepared` → `isolated` → `copied` → `sealed` → `published` →
307
+ `promotion-prepared` → `promotion-applied` → `completed` or `recovery-required`; a pending journal
308
+ blocks a new archive for the same slug before the gate.
309
+ `original` is retained on collision/post-publication failure and `published-recovery-required`
310
+ requires inspection. `operation_id` and `transaction_phase` appear only sanitized. Use
311
+ `wendkeep change archive recover <operation-id> --change <slug> [--spec-action rollback|resume] [--json]`:
312
+ without `--spec-action`, read-only, fail-closed, idempotent inspection with no promotion, deletion,
313
+ or invented reconciliation; `rollback` restores before-images and `resume` converges after-images
314
+ for `promotion-prepared`, retaining the journal. When an operation ID exists, `repair.command` points
315
+ to that recovery; do not treat `command:null` as the normal flow.
316
+
317
+ Multi-spec promotion is atomic, with before-images/digests, rollback of targets before/after writes,
318
+ and retry only after reconciliation and fresh verification. The post-release finalizer validates
319
+ original/destination digests, but the `completed` journal keeps the `original` retained; no
320
+ destructive cleanup is automatic.
321
+
278
322
  ## Common errors and diagnosis
279
323
 
280
324
  - Unknown profile: use exactly `OFF`, `FLOW`, `GUIDE`, `GOVERN`, or `ASSURE`.
@@ -142,3 +142,9 @@ from a busy lock or skipped path without reopening the original session.
142
142
 
143
143
  Read [Operating profiles](operating-profiles.md), [retroactive import](retroactive-import.md),
144
144
  [costs and observability](costs-and-observability.md), and [notes](notes-and-knowledge.md).
145
+ # Handoff Contract v1
146
+
147
+ In a causal active context, SessionStop projects a typed handoff with task, artifacts, Evidence
148
+ Envelope, decisions, next actions, blockers, and HEAD/tasks/spec hashes. ASSURE blocks publication
149
+ when that verified contract cannot be produced; other profiles preserve the optional fallback.
150
+ Historical handoffs remain `legacy-reported`. See [Changes and verification](changes-and-verification.md).
@@ -90,6 +90,44 @@ reviewer must preserve both.
90
90
  V1 evidence remains readable as `legacy-unbound`, never as equivalent authority. Run
91
91
  `wendkeep change status <slug>` to inspect `bound`, `stale`, or `context-mismatch`.
92
92
 
93
+ The provenance gate normalizes that legacy view into one taxonomy: `verified` when every required
94
+ proof is fresh and bound; `reported` for a recorded claim without an authoritative observation;
95
+ `legacy-unbound` for v1; `stale` for an earlier snapshot; `conflict` for incompatible identity or
96
+ content; and `unproven` for missing or insufficient proof. Precedence is `conflict` > `stale` >
97
+ `legacy-unbound` > `unproven` > `reported` > `verified`, and only `verified` closes the gate.
98
+
99
+ For post-fix archive, the final pass is `wendkeep verify --deep --change <slug>`. It must leave a
100
+ complete and canonical package and verdict bound to the same checkout, change, tasks, spec, and
101
+ sensors. Archive writes the authorization receipt before mutation to the separate
102
+ `change-archive-receipts-v2` ledger. Its `change archive --json` output is serializable and
103
+ exposes `state`, `reason_codes`, `diagnostics`, and `repair`; ledger corruption or truncation
104
+ fails closed. `--force` does not bypass provenance or integrity. The exact recovery is to repeat
105
+ `wendkeep verify --deep --change <slug>` after stabilizing the context.
106
+
107
+ Archive uses a `directory lock` with a token-specific marker and lease. Acquisition prepares a
108
+ sibling `.pending` directory and publishes it by atomic rename, uses no hardlink, and allows at most
109
+ 3 topology attempts. A live owner produces `WENDKEEP_ARCHIVE_BUSY`; a dead owner is reaped only
110
+ after safe observation; invalid marker/structure produces `WENDKEEP_ARCHIVE_LOCK_UNAVAILABLE`;
111
+ ownership loss produces `WENDKEEP_ARCHIVE_LOCK_OWNERSHIP_LOST`. The `archive-transaction.json`
112
+ manifest records `prepared` → `isolated` → `copied` → `sealed` → `published` → `promotion-prepared` →
113
+ `promotion-applied` → `completed` or `recovery-required`. A pending journal blocks a new archive for
114
+ the same slug before the gate. On a
115
+ collision or post-publication failure, `original` is retained and the
116
+ `published-recovery-required` state blocks destructive retry. `operation_id` and `transaction_phase`
117
+ are sanitized fields. Inspect it with
118
+ `wendkeep change archive recover <operation-id> --change <slug> [--spec-action rollback|resume] [--json]`:
119
+ without `--spec-action`, this is a read-only, fail-closed, idempotent operation with no promotion,
120
+ deletion, or invented reconciliation. `rollback` restores before-images and `resume` converges
121
+ after-images for a `promotion-prepared` promotion while retaining the journal for reconciliation.
122
+ When an operation ID exists, `repair.command` points to `wendkeep change archive recover <operation-id>
123
+ --change <slug>`; do not treat `command:null` as the normal flow.
124
+
125
+ Multi-spec promotion is one atomic unit: it captures before-images/digests for every capability,
126
+ rolls back every target (including state/README) on a before- or after-write failure, and permits a
127
+ retry only after journal reconciliation and fresh verification. The post-release finalizer validates
128
+ original/destination digests, but the `completed` journal keeps the `original` retained; no
129
+ destructive cleanup is automatic. A failure retains `published-recovery-required`.
130
+
93
131
  ## Common errors and diagnosis
94
132
 
95
133
  - `no change`: this is exit 2 and a valid idle state; create/use a change or skip verify.
@@ -102,6 +140,13 @@ V1 evidence remains readable as `legacy-unbound`, never as equivalent authority.
102
140
  The previous evidence was not replaced.
103
141
  - `legacy-unbound`, `stale`, or `context-mismatch`: return to the correct worktree/session, recover
104
142
  the context when needed, and rerun `verify` plus `verify --deep`.
143
+ - `WENDKEEP_PROVENANCE_GATE_BLOCKED`: inspect `state`, `reasonCodes`, and `repair`; do not reuse
144
+ proof from another branch/worktree/session. Run the proposed command and recapture the envelope.
145
+ - `WENDKEEP_RECEIPT_LEDGER_BUSY`, `WENDKEEP_RECEIPT_LEDGER_CONFLICT`,
146
+ `WENDKEEP_RECEIPT_LEDGER_CORRUPT`, and `WENDKEEP_RECEIPT_LEDGER_TRUNCATED` require preserving
147
+ the ledger/checkpoint and executing the objective recovery in `repair.command` (or
148
+ `npx --no-install wendkeep verify --deep --json` for fresh proof); text/JSON output remains
149
+ sanitized and contains no raw stderr, tokens, private URLs, or Vault paths.
105
150
  - Surviving mutants: strengthen the discriminating test; after three rounds, review manually.
106
151
 
107
152
  ## Next steps
@@ -109,3 +154,12 @@ V1 evidence remains readable as `legacy-unbound`, never as equivalent authority.
109
154
  Return to the [change lifecycle](changes-and-verification.md) for archive, review
110
155
  [Operating profiles](operating-profiles.md), or use [maintenance](maintenance-and-diagnostics.md)
111
156
  when no change exists.
157
+ # Task Contract gate
158
+
159
+ After running sensors and writing the current Evidence Envelope, `verify` evaluates Task Contracts
160
+ for the causal active context. An open checkbox, missing requirement/sensor/artifact, open
161
+ dependency, or stale binding returns exit `1`, preserves `evidencia.json`, writes
162
+ `task-evaluation.json`, and does not create the deep package. Tasks explicitly authored with
163
+ `[phase:verify]` are excluded only from this transition because they depend on the deep package;
164
+ they remain open for the archive gate. See
165
+ [Changes and verification](changes-and-verification.md).
@@ -58,6 +58,31 @@ idempotent; when the directory vanished between steps, the interrupted reservati
58
58
  the proven head; divergence or an unavailable network blocks the operation. An already-absent branch
59
59
  is idempotent success. `--open-main` opens the main worktree only after completion.
60
60
 
61
+ ### Post-fix cleanup: crash-safe resume
62
+
63
+ Cleanup is **crash-safe** and resumable before the receipt, after the receipt and before
64
+ finalize, and after finalize: a crash at any boundary preserves operation/state and lets the same
65
+ proof be retried without duplicating removal or a receipt. Every operation subject includes all
66
+ active contexts, actor, pr, head, and merge. The canonical PR authority is the PR resolved by the
67
+ GitHub adapter; caller-provided text cannot replace that authority.
68
+
69
+ HEAD is re-derived before finalize from the checkout and compared with the proven head/merge. The
70
+ reason is sanitized and receives a digest for audit, without storing private paths, tokens, or
71
+ stderr. An absent or invalid checkpoint is WENDKEEP_RECEIPT_LEDGER_TRUNCATED. V1 remains
72
+ legacy-unbound and never authorizes cleanup.
73
+
74
+ Text and --json always expose operation, state, blocker, recovery, and the stable codes
75
+ WENDKEEP_WORKTREE_CLEANUP_BUSY, WENDKEEP_RECEIPT_LEDGER_CORRUPT, and
76
+ WENDKEEP_RECEIPT_LEDGER_TRUNCATED; recovery resumes the reservation or names the objective repair.
77
+
78
+ The common cleanup gate classifies the operation and blocks before mutation, including finish,
79
+ remove, and cleanup --apply. After append, the receipt is classified by the same gate before
80
+ finalize; a provenance failure neither finalizes nor reports success. A cleaned state without a v2
81
+ receipt is blocked as unproven; a v1 receipt never authorizes and remains legacy-unbound.
82
+
83
+ Text and --json blockers keep the same sanitized diagnostic: code, operation, state, blocker,
84
+ expected, observed, recovery, reason_codes, diagnostics, and repair.
85
+
61
86
  ## Cleanup, remove, and prune
62
87
 
63
88
  `cleanup --merged` and `prune` are dry-run by default. `--dry-run` makes that intent explicit; only
@@ -70,10 +95,20 @@ keeps every preflight and preserves both local and remote branches.
70
95
 
71
96
  The registry lives in the Git common-dir at `wendkeep/worktrees-v1.json`, protected by a
72
97
  multi-process lock. It stores repository/worktree identity, canonical binding, PR, and transient
73
- cleanup state; `.wendkeep.json` stays unchanged. Receipts live at
74
- `wendkeep/worktree-cleanup-receipts-v1.jsonl`. `.worktrees/` is added to both the versioned ignore
75
- and the repository-private exclude. JSON `list`/`status` output exposes neither Vault paths nor
76
- contents.
98
+ cleanup state; `.wendkeep.json` stays unchanged. New receipts live at
99
+ `wendkeep/worktree-cleanup-receipts-v2.jsonl`: every line carries `previous_hash` and
100
+ `receipt_hash`, while a separate checkpoint fixes the last validated sequence/hash/byte length.
101
+ V1 remains readable as `legacy-unbound`, with no silent append or rewrite.
102
+ `WENDKEEP_RECEIPT_LEDGER_CORRUPT` reports tampering/partial JSON and
103
+ `WENDKEEP_RECEIPT_LEDGER_TRUNCATED` reports a removed tail. Both block before removal and require
104
+ diagnosing the store, never inventing a receipt. `.worktrees/` is added to the versioned ignore and
105
+ repository-private exclude; JSON `list`/`status` exposes neither Vault paths nor contents.
106
+ Cleanup uses the `verified`, `reported`, `legacy-unbound`, `stale`, `conflict`, and `unproven` states;
107
+ `WENDKEEP_PROVENANCE_GATE_BLOCKED` and `WENDKEEP_RECEIPT_LEDGER_BUSY`,
108
+ `WENDKEEP_RECEIPT_LEDGER_CONFLICT`, `WENDKEEP_RECEIPT_LEDGER_CORRUPT`, and
109
+ `WENDKEEP_RECEIPT_LEDGER_TRUNCATED` fail closed. Objective recovery reads sanitized
110
+ `worktree status <slug> --json`, executes `repair.command` when present, and recaptures proof; never
111
+ edit the ledger/checkpoint or expose stderr, tokens, private URLs, or Vault paths.
77
112
 
78
113
  `create` is idempotent when slug, path, and branch already match. Collisions fail closed. Failures
79
114
  after reservation remain `failed`; run `worktree status <slug>` and follow `recovery`. `doctor`