mandrel 2.0.0 → 2.1.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 (311) hide show
  1. package/.agents/README.md +59 -28
  2. package/.agents/agents/acceptance-critic.md +9 -7
  3. package/.agents/agents/story-worker.md +41 -46
  4. package/.agents/audit-checklists/performance.md +1 -1
  5. package/.agents/docs/SDLC.md +51 -44
  6. package/.agents/docs/agentrc-reference.json +8 -13
  7. package/.agents/docs/configuration.md +32 -56
  8. package/.agents/docs/execution-reference.md +39 -10
  9. package/.agents/docs/quality-gates.md +14 -16
  10. package/.agents/docs/workflows.md +6 -6
  11. package/.agents/instructions.md +64 -79
  12. package/.agents/rules/ci-remediation.md +3 -3
  13. package/.agents/rules/git-conventions-reference.md +42 -51
  14. package/.agents/schemas/agentrc.schema.json +34 -45
  15. package/.agents/schemas/audit-rules.json +59 -1
  16. package/.agents/schemas/audit-rules.schema.json +33 -1
  17. package/.agents/schemas/lifecycle/README.md +1 -2
  18. package/.agents/schemas/lifecycle/ledger-record.schema.json +1 -1
  19. package/.agents/schemas/lifecycle/merge.flip-failed.schema.json +33 -0
  20. package/.agents/schemas/lifecycle/merge.unlanded.schema.json +1 -0
  21. package/.agents/schemas/lifecycle/story.merged.schema.json +1 -1
  22. package/.agents/schemas/signal-event.schema.json +3 -3
  23. package/.agents/schemas/story-deliver-terminal.schema.json +152 -0
  24. package/.agents/schemas/validation-evidence.schema.json +1 -1
  25. package/.agents/scripts/acceptance-eval.js +22 -66
  26. package/.agents/scripts/agents-bootstrap-github.js +1 -1
  27. package/.agents/scripts/bootstrap.js +3 -3
  28. package/.agents/scripts/check-dead-exports.js +43 -104
  29. package/.agents/scripts/check-doc-links.js +2 -2
  30. package/.agents/scripts/check-lifecycle-lint.js +1 -1
  31. package/.agents/scripts/check-workflow-cli-lint.js +91 -0
  32. package/.agents/scripts/deliver-recover.js +122 -0
  33. package/.agents/scripts/drain-pending-cleanup.js +1 -1
  34. package/.agents/scripts/evidence-gate.js +20 -50
  35. package/.agents/scripts/generate-skills-index.js +17 -1
  36. package/.agents/scripts/generate-workflows-doc.js +4 -4
  37. package/.agents/scripts/lib/ITicketingProvider.js +1 -19
  38. package/.agents/scripts/lib/audit-suite/selector.js +323 -23
  39. package/.agents/scripts/lib/baselines/kinds/maintainability.js +0 -11
  40. package/.agents/scripts/lib/bootstrap/ci-workflow-template.js +28 -33
  41. package/.agents/scripts/lib/bootstrap/manifest.js +8 -11
  42. package/.agents/scripts/lib/bootstrap/project-bootstrap.js +30 -53
  43. package/.agents/scripts/lib/bootstrap/quality-bootstrap.js +0 -2
  44. package/.agents/scripts/lib/checks/core-bare-clean.js +4 -1
  45. package/.agents/scripts/lib/checks/index.js +1 -1
  46. package/.agents/scripts/lib/checks/loop-health.js +12 -11
  47. package/.agents/scripts/lib/checks/state.js +17 -248
  48. package/.agents/scripts/lib/checks/story-init-not-backgrounded.js +3 -3
  49. package/.agents/scripts/lib/checks/subagent-agent-tool-required.js +3 -4
  50. package/.agents/scripts/lib/checks/worktree-bootstrap-env.js +2 -2
  51. package/.agents/scripts/lib/checks/worktree-residue-biome.js +3 -3
  52. package/.agents/scripts/lib/cli-args.js +23 -2
  53. package/.agents/scripts/lib/close-validation/gates.js +13 -13
  54. package/.agents/scripts/lib/close-validation/projections/inputs.js +7 -7
  55. package/.agents/scripts/lib/close-validation/projections/maintainability.js +12 -12
  56. package/.agents/scripts/lib/close-validation/runner.js +13 -21
  57. package/.agents/scripts/lib/close-validation/telemetry.js +17 -8
  58. package/.agents/scripts/lib/config/delivery-routing.js +7 -6
  59. package/.agents/scripts/lib/config/explain.js +10 -16
  60. package/.agents/scripts/lib/config/github.js +7 -5
  61. package/.agents/scripts/lib/config/limits.js +15 -25
  62. package/.agents/scripts/lib/config/quality.js +11 -14
  63. package/.agents/scripts/lib/config/runners.js +8 -21
  64. package/.agents/scripts/lib/config/temp-paths.js +18 -56
  65. package/.agents/scripts/lib/config-settings-schema-delivery.js +31 -13
  66. package/.agents/scripts/lib/config-settings-schema-quality.js +9 -2
  67. package/.agents/scripts/lib/config-settings-schema.js +48 -22
  68. package/.agents/scripts/lib/dead-exports-knip.js +105 -0
  69. package/.agents/scripts/lib/dead-exports-mode.js +51 -0
  70. package/.agents/scripts/lib/duplicate-search.js +38 -7
  71. package/.agents/scripts/lib/findings/promote-finding.js +23 -14
  72. package/.agents/scripts/lib/format-generated-json.js +97 -0
  73. package/.agents/scripts/lib/framework-version.js +19 -189
  74. package/.agents/scripts/lib/gh-exec.js +8 -0
  75. package/.agents/scripts/lib/git-branch-lifecycle.js +0 -158
  76. package/.agents/scripts/lib/git-utils.js +0 -14
  77. package/.agents/scripts/lib/json-utils.js +1 -2
  78. package/.agents/scripts/lib/label-constants.js +0 -15
  79. package/.agents/scripts/lib/label-taxonomy.js +1 -12
  80. package/.agents/scripts/lib/observability/active-story-env.js +42 -163
  81. package/.agents/scripts/lib/observability/runtime-friction.js +243 -0
  82. package/.agents/scripts/lib/observability/signal-validator.js +4 -4
  83. package/.agents/scripts/lib/observability/signals-writer.js +6 -82
  84. package/.agents/scripts/lib/observability/source-classifier.js +2 -2
  85. package/.agents/scripts/lib/observability/tool-trace-hook.js +2 -12
  86. package/.agents/scripts/lib/orchestration/acceptance-clusters.js +1 -1
  87. package/.agents/scripts/lib/orchestration/acceptance-eval-decision.js +2 -2
  88. package/.agents/scripts/lib/orchestration/ceremony-routing.js +43 -45
  89. package/.agents/scripts/lib/orchestration/code-review.js +58 -168
  90. package/.agents/scripts/lib/orchestration/consolidation-precondition.js +3 -3
  91. package/.agents/scripts/lib/orchestration/deliver-recover.js +328 -0
  92. package/.agents/scripts/lib/orchestration/detectors-phase.js +12 -6
  93. package/.agents/scripts/lib/orchestration/git-cleanup/phases/fast-forward.js +34 -0
  94. package/.agents/scripts/lib/orchestration/lease-guard-shared.js +3 -2
  95. package/.agents/scripts/lib/orchestration/lifecycle/emit-ledger-event.js +142 -0
  96. package/.agents/scripts/lib/orchestration/lifecycle/emit-loop-tick.js +9 -11
  97. package/.agents/scripts/lib/orchestration/lifecycle/emit-merge-flip-failed.js +86 -0
  98. package/.agents/scripts/lib/orchestration/lifecycle/emit-merge-unlanded.js +37 -103
  99. package/.agents/scripts/lib/orchestration/lifecycle/listeners/README.md +7 -3
  100. package/.agents/scripts/lib/orchestration/lifecycle/listeners/watcher.js +50 -85
  101. package/.agents/scripts/lib/orchestration/lifecycle/trace-logger.js +3 -14
  102. package/.agents/scripts/lib/orchestration/merge-block-class.js +76 -20
  103. package/.agents/scripts/lib/orchestration/merge-poll.js +104 -0
  104. package/.agents/scripts/lib/orchestration/plan-context.js +114 -24
  105. package/.agents/scripts/lib/orchestration/plan-critic-conditions.js +11 -22
  106. package/.agents/scripts/lib/orchestration/plan-critics-evaluate.js +3 -7
  107. package/.agents/scripts/lib/orchestration/plan-metrics.js +38 -6
  108. package/.agents/scripts/lib/orchestration/plan-persist/fan-out-gate.js +16 -6
  109. package/.agents/scripts/lib/orchestration/plan-persist/persist-helpers.js +173 -25
  110. package/.agents/scripts/lib/orchestration/plan-persist/plan-context-source.js +116 -0
  111. package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +280 -75
  112. package/.agents/scripts/lib/orchestration/plan-persist/story-ops.js +472 -55
  113. package/.agents/scripts/lib/orchestration/plan-persist/summary.js +21 -16
  114. package/.agents/scripts/lib/orchestration/plan-persist/supersede-ops.js +509 -0
  115. package/.agents/scripts/lib/orchestration/planning/authoring-context.js +41 -40
  116. package/.agents/scripts/lib/orchestration/planning/spec-authoring-grounding.js +1 -1
  117. package/.agents/scripts/lib/orchestration/resolve-stories.js +344 -0
  118. package/.agents/scripts/lib/orchestration/retro-proposals.js +7 -7
  119. package/.agents/scripts/lib/orchestration/review-depth.js +105 -40
  120. package/.agents/scripts/lib/orchestration/review-providers/findings-renderer.js +3 -13
  121. package/.agents/scripts/lib/orchestration/review-providers/native.js +1 -154
  122. package/.agents/scripts/lib/orchestration/review-providers/review-depth.js +3 -2
  123. package/.agents/scripts/lib/orchestration/review-providers/security-review.js +1 -1
  124. package/.agents/scripts/lib/orchestration/review-providers/types.js +5 -4
  125. package/.agents/scripts/lib/orchestration/review-providers/ultrareview.js +1 -1
  126. package/.agents/scripts/lib/orchestration/run-epilogue.js +374 -16
  127. package/.agents/scripts/lib/orchestration/single-story-close/phases/auto-merge.js +24 -0
  128. package/.agents/scripts/lib/orchestration/single-story-close/phases/base-sync.js +11 -9
  129. package/.agents/scripts/lib/orchestration/single-story-close/phases/close-validation.js +4 -4
  130. package/.agents/scripts/lib/orchestration/single-story-close/phases/code-review.js +3 -12
  131. package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +608 -152
  132. package/.agents/scripts/lib/orchestration/single-story-close/phases/options.js +72 -30
  133. package/.agents/scripts/lib/orchestration/single-story-close/phases/post-land.js +305 -0
  134. package/.agents/scripts/lib/orchestration/single-story-close/phases/pull-request.js +1 -1
  135. package/.agents/scripts/lib/orchestration/single-story-close/phases/review-block.js +12 -8
  136. package/.agents/scripts/lib/orchestration/single-story-close/phases/worktree-reap.js +37 -4
  137. package/.agents/scripts/lib/orchestration/single-story-close/phases/wrong-tree-guard.js +2 -2
  138. package/.agents/scripts/lib/orchestration/single-story-close/runner.js +264 -43
  139. package/.agents/scripts/lib/orchestration/single-story-lease-guard.js +1 -1
  140. package/.agents/scripts/lib/orchestration/story-close/format-autofix.js +10 -10
  141. package/.agents/scripts/lib/orchestration/story-close/phases/code-review.js +15 -32
  142. package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +360 -0
  143. package/.agents/scripts/lib/orchestration/story-follow-ups.js +75 -14
  144. package/.agents/scripts/lib/orchestration/story-init-remote.js +12 -8
  145. package/.agents/scripts/lib/orchestration/story-plan-state.js +14 -29
  146. package/.agents/scripts/lib/orchestration/task-body-validator.js +52 -7
  147. package/.agents/scripts/lib/orchestration/ticket-lease.js +27 -74
  148. package/.agents/scripts/lib/orchestration/ticket-validator-conflicts.js +119 -14
  149. package/.agents/scripts/lib/orchestration/ticket-validator-sizing.js +3 -4
  150. package/.agents/scripts/lib/orchestration/ticket-validator.js +121 -18
  151. package/.agents/scripts/lib/orchestration/ticketing/bulk.js +14 -47
  152. package/.agents/scripts/lib/orchestration/ticketing/reads.js +19 -32
  153. package/.agents/scripts/lib/orchestration/ticketing/transition.js +61 -1
  154. package/.agents/scripts/lib/orchestration/ticketing.js +0 -1
  155. package/.agents/scripts/lib/plan-phase-cleanup.js +12 -14
  156. package/.agents/scripts/lib/planning-corpus.js +12 -286
  157. package/.agents/scripts/lib/preflight-runner.js +2 -2
  158. package/.agents/scripts/lib/qa/qa-context-hydrator.js +5 -5
  159. package/.agents/scripts/lib/signals/index.js +4 -17
  160. package/.agents/scripts/lib/signals/read.js +35 -35
  161. package/.agents/scripts/lib/signals/schema.js +8 -11
  162. package/.agents/scripts/lib/signals/span-tree.js +7 -7
  163. package/.agents/scripts/lib/signals/write.js +0 -1
  164. package/.agents/scripts/lib/single-story/story-merged-notify.js +13 -2
  165. package/.agents/scripts/lib/skills/parse-skill.js +16 -3
  166. package/.agents/scripts/lib/story-adjacency.js +8 -7
  167. package/.agents/scripts/lib/story-body/story-body.js +6 -5
  168. package/.agents/scripts/lib/templates/decomposer-prompts.js +7 -3
  169. package/.agents/scripts/lib/test-env.js +14 -1
  170. package/.agents/scripts/lib/test-tiers.js +0 -3
  171. package/.agents/scripts/lib/ticket-body-sections.js +0 -14
  172. package/.agents/scripts/lib/validation-evidence.js +31 -59
  173. package/.agents/scripts/lib/wave-runner/ready-set.js +32 -6
  174. package/.agents/scripts/lib/worktree/lifecycle/pending-cleanup.js +1 -1
  175. package/.agents/scripts/lib/worktree/lifecycle/reap.js +68 -19
  176. package/.agents/scripts/lib/worktree/lifecycle-manager.js +1 -2
  177. package/.agents/scripts/plan-context.js +38 -6
  178. package/.agents/scripts/plan-persist.js +145 -35
  179. package/.agents/scripts/plan-run-epilogue.js +83 -38
  180. package/.agents/scripts/post-structured-comment.js +0 -38
  181. package/.agents/scripts/pr-watch-with-update.js +43 -22
  182. package/.agents/scripts/providers/github/compose.js +0 -1
  183. package/.agents/scripts/providers/github/errors.js +0 -19
  184. package/.agents/scripts/providers/github/issues.js +1 -11
  185. package/.agents/scripts/providers/github/mappers.js +5 -0
  186. package/.agents/scripts/providers/github/sub-issues.js +0 -47
  187. package/.agents/scripts/providers/github/tickets.js +33 -153
  188. package/.agents/scripts/providers/github.js +17 -6
  189. package/.agents/scripts/resolve-stories.js +236 -0
  190. package/.agents/scripts/run-coverage.js +4 -1
  191. package/.agents/scripts/run-lint.js +2 -2
  192. package/.agents/scripts/run-verify.js +31 -2
  193. package/.agents/scripts/signals-view.js +9 -10
  194. package/.agents/scripts/single-story-close.js +173 -18
  195. package/.agents/scripts/single-story-confirm-merge.js +288 -15
  196. package/.agents/scripts/single-story-init.js +6 -10
  197. package/.agents/scripts/stories-wave-tick.js +79 -4
  198. package/.agents/scripts/story-plan.js +3 -3
  199. package/.agents/scripts/update-ticket-state.js +8 -50
  200. package/.agents/skills/core/code-review-and-quality/SKILL.md +28 -450
  201. package/.agents/skills/core/code-review-and-quality/reference.md +458 -0
  202. package/.agents/skills/core/debugging-and-error-recovery/SKILL.md +22 -315
  203. package/.agents/skills/core/debugging-and-error-recovery/reference.md +323 -0
  204. package/.agents/skills/core/diagnose-friction/SKILL.md +14 -18
  205. package/.agents/skills/core/documentation-and-adrs/SKILL.md +25 -397
  206. package/.agents/skills/core/documentation-and-adrs/reference.md +403 -0
  207. package/.agents/skills/core/gates-and-baselines/SKILL.md +12 -12
  208. package/.agents/skills/core/idea-refinement/SKILL.md +3 -3
  209. package/.agents/skills/core/scope-triage/SKILL.md +3 -0
  210. package/.agents/skills/core/security-and-hardening/SKILL.md +22 -367
  211. package/.agents/skills/core/security-and-hardening/reference.md +375 -0
  212. package/.agents/skills/skills.index.json +2 -12
  213. package/.agents/skills/stack/qa/playwright-bdd/SKILL.md +2 -4
  214. package/.agents/skills/stack/qa/qa-explore-driving/SKILL.md +1 -1
  215. package/.agents/skills/stack/qa/qa-harness/SKILL.md +1 -3
  216. package/.agents/workflows/audit-architecture.md +3 -4
  217. package/.agents/workflows/audit-clean-code.md +4 -4
  218. package/.agents/workflows/audit-documentation.md +4 -5
  219. package/.agents/workflows/audit-lighthouse.md +8 -0
  220. package/.agents/workflows/audit-navigability.md +10 -0
  221. package/.agents/workflows/audit-performance.md +2 -3
  222. package/.agents/workflows/audit-quality.md +8 -9
  223. package/.agents/workflows/audit-security.md +1 -2
  224. package/.agents/workflows/audit-seo.md +10 -0
  225. package/.agents/workflows/audit-ux-ui.md +7 -0
  226. package/.agents/workflows/deliver.md +98 -45
  227. package/.agents/workflows/git-cleanup.md +2 -2
  228. package/.agents/workflows/git-deliver.md +1 -1
  229. package/.agents/workflows/helpers/acceptance-self-eval.md +21 -13
  230. package/.agents/workflows/helpers/code-quality-guardrails.md +7 -7
  231. package/.agents/workflows/helpers/code-review.md +12 -10
  232. package/.agents/workflows/helpers/deliver-story-reference.md +73 -32
  233. package/.agents/workflows/helpers/deliver-story.md +193 -118
  234. package/.agents/workflows/helpers/parallel-tooling.md +2 -2
  235. package/.agents/workflows/helpers/worktree-lifecycle.md +28 -32
  236. package/.agents/workflows/plan.md +184 -19
  237. package/.agents/workflows/qa-assist.md +6 -6
  238. package/.agents/workflows/qa-explore.md +3 -3
  239. package/.agents/workflows/qa-run.md +1 -5
  240. package/bin/mandrel.js +12 -1
  241. package/docs/CHANGELOG.md +40 -0
  242. package/lib/cli/registry.js +262 -19
  243. package/lib/cli/sync-agents.js +157 -0
  244. package/lib/cli/sync-commands.js +115 -6
  245. package/lib/cli/sync.js +168 -6
  246. package/lib/cli/update.js +105 -8
  247. package/lib/cli/version-helpers.js +131 -0
  248. package/lib/migrations/README.md +7 -5
  249. package/lib/migrations/index.js +12 -9
  250. package/lib/migrations/steps/2.1.0-retire-mi-drop-knobs.js +100 -0
  251. package/lib/migrations/steps/2.1.0-retire-verify-concurrency-cap.js +101 -0
  252. package/package.json +1 -1
  253. package/.agents/schemas/epic-perf-report.schema.json +0 -89
  254. package/.agents/schemas/lifecycle/acceptance.reconcile.failed.schema.json +0 -13
  255. package/.agents/schemas/lifecycle/acceptance.reconcile.ok.schema.json +0 -13
  256. package/.agents/schemas/lifecycle/acceptance.reconcile.skipped.schema.json +0 -13
  257. package/.agents/schemas/lifecycle/acceptance.reconcile.start.schema.json +0 -12
  258. package/.agents/schemas/lifecycle/acceptance.reconcile.waived.schema.json +0 -13
  259. package/.agents/schemas/lifecycle/epic.automerge.end.schema.json +0 -15
  260. package/.agents/schemas/lifecycle/epic.automerge.start.schema.json +0 -13
  261. package/.agents/schemas/lifecycle/epic.blocked.schema.json +0 -13
  262. package/.agents/schemas/lifecycle/epic.cleanup.end.schema.json +0 -12
  263. package/.agents/schemas/lifecycle/epic.cleanup.start.schema.json +0 -12
  264. package/.agents/schemas/lifecycle/epic.close.end.schema.json +0 -12
  265. package/.agents/schemas/lifecycle/epic.complete.schema.json +0 -13
  266. package/.agents/schemas/lifecycle/epic.finalize.end.schema.json +0 -13
  267. package/.agents/schemas/lifecycle/epic.finalize.start.schema.json +0 -12
  268. package/.agents/schemas/lifecycle/epic.merge.armed.schema.json +0 -13
  269. package/.agents/schemas/lifecycle/epic.merge.blocked.schema.json +0 -14
  270. package/.agents/schemas/lifecycle/epic.merge.confirmed.schema.json +0 -17
  271. package/.agents/schemas/lifecycle/epic.merge.ready.schema.json +0 -15
  272. package/.agents/schemas/lifecycle/epic.plan.end.schema.json +0 -18
  273. package/.agents/schemas/lifecycle/epic.plan.start.schema.json +0 -12
  274. package/.agents/schemas/lifecycle/epic.snapshot.end.schema.json +0 -16
  275. package/.agents/schemas/lifecycle/epic.snapshot.start.schema.json +0 -12
  276. package/.agents/schemas/lifecycle/epic.watch.end.schema.json +0 -29
  277. package/.agents/schemas/lifecycle/epic.watch.start.schema.json +0 -16
  278. package/.agents/schemas/lifecycle/story.heartbeat.schema.json +0 -20
  279. package/.agents/schemas/risk-verdict.schema.json +0 -53
  280. package/.agents/schemas/story-perf-summary.schema.json +0 -73
  281. package/.agents/scripts/analyze-execution.js +0 -444
  282. package/.agents/scripts/check-prepush-recovery.js +0 -90
  283. package/.agents/scripts/lib/git-merge-orchestrator.js +0 -261
  284. package/.agents/scripts/lib/observability/baseline-refresh-rate.js +0 -221
  285. package/.agents/scripts/lib/observability/hook-heartbeat.js +0 -187
  286. package/.agents/scripts/lib/observability/perf-aggregator.js +0 -813
  287. package/.agents/scripts/lib/observability/perf-report-readers.js +0 -328
  288. package/.agents/scripts/lib/observability/perf-report-render.js +0 -182
  289. package/.agents/scripts/lib/orchestration/audit-lens-routing.js +0 -128
  290. package/.agents/scripts/lib/orchestration/bookkeeping-outbox.js +0 -273
  291. package/.agents/scripts/lib/orchestration/error-journal.js +0 -139
  292. package/.agents/scripts/lib/orchestration/lifecycle/emit-story-heartbeat.js +0 -155
  293. package/.agents/scripts/lib/orchestration/lifecycle/ledger-diff.js +0 -140
  294. package/.agents/scripts/lib/orchestration/lifecycle/listeners/merge-watcher.js +0 -665
  295. package/.agents/scripts/lib/orchestration/plan-review-routing.js +0 -63
  296. package/.agents/scripts/lib/orchestration/planning/risk-verdict.js +0 -104
  297. package/.agents/scripts/lib/orchestration/planning-context-budget.js +0 -213
  298. package/.agents/scripts/lib/orchestration/planning-risk.js +0 -194
  299. package/.agents/scripts/lib/orchestration/post-merge/phases/branch-cleanup.js +0 -56
  300. package/.agents/scripts/lib/orchestration/post-merge/phases/dashboard-refresh.js +0 -21
  301. package/.agents/scripts/lib/orchestration/post-merge/phases/notification.js +0 -78
  302. package/.agents/scripts/lib/orchestration/post-merge/phases/temp-cleanup.js +0 -68
  303. package/.agents/scripts/lib/orchestration/post-merge/phases/ticket-closure.js +0 -118
  304. package/.agents/scripts/lib/orchestration/post-merge/phases/worktree-reap.js +0 -397
  305. package/.agents/scripts/lib/orchestration/preflight-cache.js +0 -187
  306. package/.agents/scripts/lib/orchestration/resolve-plan-run.js +0 -155
  307. package/.agents/scripts/lib/orchestration/retro-perf-heuristics.js +0 -275
  308. package/.agents/scripts/lib/orchestration/story-progress/story-run-progress-writer.js +0 -400
  309. package/.agents/scripts/lib/single-story/confirm-merge-follow-ups.js +0 -36
  310. package/.agents/scripts/resolve-plan-run.js +0 -117
  311. package/.agents/skills/core/analyze-execution/SKILL.md +0 -101
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  description:
3
3
  Execute one Story end-to-end. Creates story-<id> from main, implements in a
4
- worktree (optional ## Slicing checkpoints), runs risk-routed ceremony, opens
5
- a PR against main, and lands.
4
+ worktree (optional ## Slicing checkpoints), runs derived-level ceremony,
5
+ opens a PR against main, and lands.
6
6
  ---
7
7
 
8
8
  # /deliver-story #[Story ID]
@@ -18,10 +18,10 @@ description:
18
18
  large — uses the same machinery:
19
19
 
20
20
  ```text
21
- /deliver <storyId> (or /deliver --run <planRunId> one Story at a time)
21
+ /deliver <storyId> [<storyId> ...] (each Story runs through this engine)
22
22
  → single-story-init.js (branch from main, worktree, agent::executing)
23
23
  → agent implements + commits (optional ## Slicing intra-session checkpoints)
24
- risk-routed ceremony (acceptance critics · review · audit lenses)
24
+ derived-level ceremony (acceptance critics · review depth)
25
25
  → single-story-close.js (gates, push, gh pr create → main, agent::closing)
26
26
  → CI watch + fix loop (until required checks pass + PR merged)
27
27
  → single-story-confirm-merge.js (PR merged → agent::done + follow-ups)
@@ -34,7 +34,7 @@ large — uses the same machinery:
34
34
  | Merge target | `main` via PR (squash + required checks) |
35
35
  | Epic integration branch | **None** — no `epic/<id>`, no `--no-ff` wave merge |
36
36
  | Spec / slices | Folded `## Spec` + optional `## Slicing` checkpoints in-session |
37
- | Ceremony | Per-Story risk-routed via `ceremony-routing.js` |
37
+ | Ceremony | Per-Story, routed off the derived change level via `ceremony-routing.js` |
38
38
 
39
39
  If the Story still carries an `Epic: #N` reference, **stop** — that is a v1
40
40
  Epic-attached ticket; re-plan as a v2 Story or finish it on a pre-v2 checkout.
@@ -200,27 +200,32 @@ Story-path specifics:
200
200
 
201
201
  ---
202
202
 
203
- ## Step 2 — Ceremony (profile + risk)
203
+ ## Step 2 — Ceremony (profile + derived level)
204
204
 
205
205
  Per-Story ceremony is selected by `delivery.routing.ceremonyProfile`
206
206
  (`minimal` | `standard` | `strict`, default `standard`) and the Story's
207
- own risk envelope (folded plan `planningRisk` / `risk-verdict` on the
208
- Story or its plan-run context — never an Epic parent). Resolve
209
- fresh-vs-inline acceptance critics per AC-cluster with
207
+ **derived change level** not a planner-authored verdict (Story #4542 retired
208
+ that). Derive the level with
209
+ [`deriveChangeLevel`](../../scripts/lib/orchestration/review-depth.js) over the
210
+ Story's changed files (`git diff --name-only main...story-<id>`): a diff
211
+ touching a sensitive path registered in `.agents/schemas/audit-rules.json`
212
+ derives `high`, one touching none derives `low`, and an unenumerable diff
213
+ derives `null`.
214
+
215
+ Resolve fresh-vs-inline acceptance critics per AC-cluster with
210
216
  [`resolveCeremonyForRisk`](../../scripts/lib/orchestration/ceremony-routing.js)
211
217
  (`minimal` → always inline; `strict` → always fresh; `standard` →
212
- `high`/`medium`/`missing` → `fresh`, `low` → `inline` unless the
213
- `freshCriticSampleRate` floor forces `fresh`). Review depth and audit lenses
214
- follow the same envelope via `review-depth.js` /
215
- `audit-lens-routing.js#resolveAuditLenses` inside close.
218
+ `high`/`null` → `fresh`, `low` → `inline` unless the `freshCriticSampleRate`
219
+ floor forces `fresh`). Review depth reads the same derived level via
220
+ `review-depth.js` inside close, so the two decisions cannot disagree.
216
221
 
217
222
  Hard gates (lint / test / format / coverage / CRAP / maintainability) always
218
- run in Step 3 — risk never disables them. Do **not** pre-run the full
219
- close-validation chain here unless interactively iterating on a fix.
223
+ run in Step 3 — the derived level never disables them. Do **not** pre-run the
224
+ full close-validation chain here unless interactively iterating on a fix.
220
225
 
221
226
  ---
222
227
 
223
- ## Step 3 — Close (`single-story-close.js`)
228
+ ## Step 3 — Close and land (`single-story-close.js`)
224
229
 
225
230
  Invoke from the main checkout (or pass `--cwd <main-repo>` from inside
226
231
  the worktree):
@@ -229,14 +234,56 @@ the worktree):
229
234
  node <main-repo>/.agents/scripts/single-story-close.js --story <storyId> --cwd <main-repo>
230
235
  ```
231
236
 
237
+ **This step is the whole delivery tail.** Close owns the gates, the PR, the
238
+ merge wait, the `agent::done` flip, and the post-land tail (follow-up
239
+ capture, status-column resync, local ref cleanup, base fast-forward) in one
240
+ process. Your job is to run it and **branch on the terminal envelope's
241
+ `status`** — nothing more (Story #4543).
242
+
243
+ ### Branch on the terminal envelope
244
+
245
+ Every invocation emits exactly one schema-validated envelope
246
+ ([`story-deliver-terminal.schema.json`](../../schemas/story-deliver-terminal.schema.json))
247
+ between `--- STORY DELIVER TERMINAL ---` markers, and the exit code mirrors
248
+ its `status`:
249
+
250
+ | `status` | Exit | What it means | What you do |
251
+ | --- | --- | --- | --- |
252
+ | `landed` | 0 | PR merged, Story `agent::done`, tail ran. `tail.*` booleans expose any partial degradation — a `false` there does **not** demote the land. | Go to Step 7 and relay the envelope. Nothing else. |
253
+ | `pending` | 3 | **Resumable, not a failure.** The per-invocation merge wait expired with the PR healthy and in flight, or the operator owns the merge. No label was mutated; no `merge.unlanded` was emitted. | Run the envelope's `nextCommand`. Repeat until it resolves. Relay `pending` only once you have exhausted your own budget. |
254
+ | `blocked` | 1 | A classified hard block. Story carries `agent::blocked`; `blocked.blockClass` names the class and `blocked.frictionCommentId` points at the remediation. | `checks-failed` → fix the red check and push (Step 4). Otherwise go to Step 7 and relay the envelope. |
255
+ | `failed` | 1 | A phase crashed; `phase` names which. | Diagnose, fix, re-run close. |
256
+
257
+ Do **not** re-sequence the post-close steps by hand. Steps 4–6 below are
258
+ **recovery-only** — reached from a `blocked`/`pending` envelope, never as
259
+ routine choreography.
260
+
261
+ ### What close does internally
262
+
232
263
  The script runs the close-validation gates against `baseBranch`, syncs the
233
264
  Story branch from `origin/<baseBranch>` (Story #2580 — the parallel-race
234
265
  defence), pushes `story-<id>`, opens (or reuses) a PR against `baseBranch`
235
266
  with a `Closes #<storyId>` footer, enables GitHub native auto-merge
236
267
  (`--auto --squash --delete-branch`) **when `delivery.ci.autoMerge` is
237
- `"trust-ci"` (the default)**, flips the Story to **`agent::closing`**
238
- (NOT `agent::done` the issue stays OPEN until Step 5 confirms the merge,
239
- Story #3385), reaps the worktree, and releases the Story lease.
268
+ `"trust-ci"` (the default)**, flips the Story to `agent::closing`, reaps the
269
+ worktree, releases the lease, then **waits for the merge** and on a
270
+ confirmed merge flips `agent::done` and runs the post-land tail.
271
+
272
+ ### The merge wait is bounded and resumable
273
+
274
+ Two budgets, deliberately separate (`delivery.mergeWatch.*`):
275
+
276
+ - **`maxWaitSeconds`** (default 300) bounds **one invocation**, sized to fit
277
+ inside a single host tool invocation (~10 min ceiling) alongside the gates
278
+ that precede it. Expiry → `pending`. Pass `--max-wait-seconds <n>` to raise
279
+ it when your host has no such ceiling and you want to land in one block.
280
+ - **`maxBudgetSeconds`** (default 3600) bounds the **cumulative** wait across
281
+ resumes, anchored at the PR's `createdAt` so resuming does not restart the
282
+ clock. Exhausting *this* is the genuine give-up → `blocked`.
283
+
284
+ The wait probes the checks every poll: a red required check fails fast as
285
+ `checks-failed` instead of burning the budget, and a PR that falls behind its
286
+ base is brought up to date within `updateAttempts` tries.
240
287
 
241
288
  > **`delivery.ci.autoMerge` policy.** Under the default `"trust-ci"`, GitHub
242
289
  > native auto-merge is armed and the PR squash-merges once its **required**
@@ -254,20 +301,19 @@ Flags:
254
301
  behaviour and warrants a pre-merge eyeball; the operator then merges via
255
302
  the GitHub UI.
256
303
  - `--wait-merge` — **close-and-land** (Story #4428). Forces close to poll
257
- the armed PR to merge confirmation on the `delivery.mergeWatch.*`
258
- cadence (reusing the same `confirmStoryMerged` flip logic) and flip
259
- `agent::done` itself. If the arm fails, the PR closes without merging,
260
- or the poll budget is exhausted first, close classifies the block
261
- (`checks-pending-timeout` \| `branch-protection-human-required` \|
262
- `arm-failure` \| `api-race-other`), emits a `merge.unlanded` lifecycle
263
- event, posts a `friction` comment, transitions the Story to
264
- `agent::blocked`, and exits non-zero — never a silent `agent::closing`
265
- rest. When neither land flag is passed, close defaults from
266
- `delivery.routing.closeAndLand` (**true**): attended and headless
267
- delivers share the land-in-one-close happy path.
304
+ the armed PR to merge confirmation and flip `agent::done` itself. When
305
+ neither land flag is passed, close defaults from
306
+ `delivery.routing.closeAndLand` (**true**): attended and headless delivers
307
+ share the land-in-one-close happy path.
268
308
  - `--no-wait-merge` — explicit opt-out that always wins. Use when the
269
309
  operator wants the PR left at `agent::closing` for a human land (or a
270
- wrapper that will invoke `single-story-confirm-merge.js` itself).
310
+ wrapper that will invoke `single-story-confirm-merge.js` itself). Reports
311
+ `pending` — the work is not done, nothing is broken, and one named command
312
+ finishes it.
313
+ - `--max-wait-seconds <n>` — raise the merge wait's per-invocation bound for
314
+ this run (Story #4543). Use from a headless caller with no host
315
+ tool-invocation ceiling to keep single-block semantics without editing the
316
+ consumer's config.
271
317
 
272
318
  > **Full close pipeline (base-sync outcomes, `agent::closing` rationale,
273
319
  > lease release).** For the numbered close pipeline, the base-sync outcome
@@ -277,43 +323,48 @@ Flags:
277
323
 
278
324
  ---
279
325
 
280
- ## Step 4 — CI watch + fix loop (**required, not optional**)
281
-
282
- > **Close-and-land runs skip Steps 4 and 5.** When Step 3 lands through
283
- > merge (`--wait-merge` or the `closeAndLand` default),
284
- > `single-story-close.js` already polled the PR to a confirmed merge
285
- > (flipping `agent::done` itself) or exited non-zero after transitioning
286
- > the Story to `agent::blocked` with a `merge.unlanded` event there is
287
- > no separate CI-watch turn or manual confirm step to run. Proceed
288
- > straight to Step 5.5. Only `--no-wait-merge` runs still own Steps 4
289
- > and 5 as documented below.
290
-
291
- The Story is **not done** when `single-story-close.js` returns. Auto-merge
292
- only fires when every required CI check turns green. Local close-validation
293
- gates pass on the dev host's environment; CI runs on a different OS and
294
- concurrency, and coverage rounding, platform-conditional branches, and
295
- timing-sensitive tests routinely drift between the two. The agent owns the
296
- green-CI outcome, not just the push.
297
-
298
- > **The auto-merge wait is an internally-blocking step, not a reason to end
299
- > your turn.** `pr-watch-with-update.js` blocks the current turn until CI
300
- > resolves — that IS how you wait. Keep the turn alive: watch → (fix +
301
- > push + re-watch on red) → confirm the merge (Step 5) → flip
302
- > `agent::done` post-merge steps return the terminal JSON contract.
303
- > Ending the turn with prose and an unconfirmed merge is a contract
304
- > violation (the Story #1553 / PR #1554 failure mode). See
326
+ ## Step 4 — CI fix loop (**recovery-only**)
327
+
328
+ > **Steps 4, 5, 5.5, and 6 are recovery paths, not routine choreography
329
+ > (Story #4543).** On the default path Step 3 already polled the PR to a
330
+ > confirmed merge, flipped `agent::done`, and ran the whole post-land tail
331
+ > follow-up capture, status resync, ref cleanup, base fast-forward in one
332
+ > process. A `landed` envelope means all of it ran; go straight to Step 7.
333
+ >
334
+ > Enter this step **only** when Step 3 returned `blocked` with
335
+ > `blockClass: "checks-failed"` (a required check went red), or when a
336
+ > `--no-wait-merge` run left the PR for you to shepherd.
337
+
338
+ When a required check is red, the agent owns the green-CI outcome, not just
339
+ the push. Local close-validation gates pass on the dev host's environment;
340
+ CI runs on a different OS and concurrency, and coverage rounding,
341
+ platform-conditional branches, and timing-sensitive tests routinely drift
342
+ between the two.
343
+
344
+ Fix the failure and push a new commit on `story-<storyId>` auto-merge stays
345
+ armed across retries, so you do not re-arm then resume the land with the
346
+ envelope's `nextCommand`.
347
+
348
+ > **A watch is an internally-blocking step, not a reason to end your turn.**
349
+ > `pr-watch-with-update.js` blocks the current turn until CI resolves that
350
+ > IS how you wait. Ending the turn with prose and an unconfirmed merge is a
351
+ > contract violation (the Story #1553 / PR #1554 failure mode). See
305
352
  > [`deliver-story-reference.md` § The auto-merge wait is an internally-blocking step](deliver-story-reference.md#the-auto-merge-wait-is-an-internally-blocking-step).
306
353
 
307
- After `single-story-close.js` succeeds, enter the watch + fix loop. Drive
308
- `pr-watch-with-update.js` — the **single CI-watch mechanism** shared with
309
- the Epic Phase 8 path (Story #4358). It polls the required checks to a
354
+ To watch the checks on the red path, drive
355
+ `pr-watch-with-update.js` — the **single CI-watch mechanism**
356
+ (Story #4358). It polls the required checks to a
310
357
  terminal state and auto-recovers from `mergeStateStatus: BEHIND`; do
311
358
  **not** fall back to a bare `gh pr checks` watch invocation:
312
359
 
313
360
  ```bash
314
- node <agentRoot>/scripts/pr-watch-with-update.js --pr <prNumber>
361
+ node <agentRoot>/scripts/pr-watch-with-update.js --pr <prNumber> --story <storyId>
315
362
  ```
316
363
 
364
+ `--story` is what keys the red-path CI digest
365
+ (`temp/story-<id>-ci-digest.{json,md}` — failing check name, run id, and a
366
+ `gh run view --log-failed` tail). Omit it and a red check writes no digest.
367
+
317
368
  Poll cadence and caps come from `delivery.ci.watch.*`
318
369
  (`pollIntervalMs`, `maxPolls`, `maxResumes`); pass `--poll-interval-ms`,
319
370
  `--max-polls`, or `--max-resumes` to override for one run.
@@ -354,30 +405,22 @@ When the watch exits, branch on the exit code:
354
405
 
355
406
  ---
356
407
 
357
- ## Step 5 — Merge confirmation + `agent::done` flip (**required, not optional**)
358
-
359
- With auto-merge enabled (default), GitHub squash-merges the PR when
360
- every required check turns green and the `Closes #<id>` footer
361
- auto-closes the Story issue.
362
-
363
- Confirm the merge landed:
364
-
365
- ```bash
366
- gh pr view <prNumber> --json state,mergedAt,mergeCommit
367
- ```
368
-
369
- Expect `state: "MERGED"`. With `--no-auto-merge`, the PR is the merge
370
- gate — the operator reviews and merges via the GitHub UI; the same
371
- `Closes #<id>` auto-close fires when the merge lands on `main`.
408
+ ## Step 5 — Merge confirmation + land tail (**recovery-only**)
372
409
 
373
- **Then flip the Story to `agent::done`.** Step 3 deferred this flip
374
- (Story #3385); now that the merge is confirmed, drive the
375
- `agent::closing agent::done` transition (which closes the issue) via:
410
+ > On the default path Step 3 already did this. Run it only to resume a
411
+ > `pending` envelope, to finish a `--no-wait-merge` run, or to rescue a
412
+ > merged-but-mislabelled Story.
376
413
 
377
414
  ```bash
378
415
  node .agents/scripts/single-story-confirm-merge.js --story <storyId> --cwd <main-repo>
379
416
  ```
380
417
 
418
+ This is the **same** shared land path Step 3 reaches: it flips
419
+ `agent::closing → agent::done` on a confirmed merge (closing the issue) and
420
+ runs the **same** post-land tail — so the two surfaces cannot diverge. It is
421
+ idempotent, emits the same terminal envelope, and is safe to re-run while
422
+ the PR is still open (returns `pending`).
423
+
381
424
  > **Confirmation outcomes.** `single-story-confirm-merge.js` re-reads the
382
425
  > live PR state and flips to `agent::done` only on a confirmed `MERGED` PR;
383
426
  > it is idempotent and safe to re-run while the PR is still open (returns
@@ -386,12 +429,16 @@ node .agents/scripts/single-story-confirm-merge.js --story <storyId> --cwd <main
386
429
 
387
430
  ---
388
431
 
389
- ## Step 5.5 — Re-assert Status column (**required, not optional**)
432
+ ## Step 5.5 — Re-assert Status column (**recovery-only**)
433
+
434
+ > **The land tail already ran this** (Story #4543) — it is `tail.statusResync`
435
+ > in the terminal envelope. Run it by hand only when that step reported
436
+ > `false`, or after a manual merge on a `--no-wait-merge` run.
390
437
 
391
438
  GitHub Projects v2 built-in workflows fire minutes *after* auto-merge lands
392
439
  and clobber the `Done` Status the confirm step set, stranding closed
393
440
  Stories at `In Progress` on the board (reproduced on Story #2813).
394
- Re-assert authority once the merge confirms:
441
+ Re-assert authority:
395
442
 
396
443
  ```bash
397
444
  node .agents/scripts/resync-status-column.js --story <storyId>
@@ -399,9 +446,7 @@ node .agents/scripts/resync-status-column.js --story <storyId>
399
446
 
400
447
  The helper re-fires the `ColumnSync` mutation and **polls for ~15 s** to win
401
448
  the race against the bot's late write (Story #2876). It is idempotent and
402
- no-op-safe (`no-project` / `not-on-project` exit 0). Skip Step 5.5 only when
403
- the operator opted out of auto-merge AND has not yet merged the PR — run it
404
- after the manual merge instead.
449
+ no-op-safe (`no-project` / `not-on-project` exit 0).
405
450
 
406
451
  > **Status-column detail + tuning flags + operator fix.** For the poll-loop
407
452
  > flags (`--poll-attempts`, `--poll-delay-ms`), the `attempts` / `drifted`
@@ -411,12 +456,18 @@ after the manual merge instead.
411
456
 
412
457
  ---
413
458
 
414
- ## Step 6 — Local branch cleanup (**required, not optional**)
459
+ ## Step 6 — Local branch cleanup (**recovery-only**)
460
+
461
+ > **The land tail already ran this** (Story #4543) — it is `tail.refCleanup`
462
+ > and `tail.baseFastForward` in the terminal envelope, done in-process
463
+ > against the same planners this command drives. Run it by hand only when
464
+ > either step reported `false` (a dirty shared checkout is the common,
465
+ > benign cause), or after a manual merge on a `--no-wait-merge` run.
415
466
 
416
467
  GitHub deletes the **remote** branch on auto-merge, but the **local**
417
468
  `story-<storyId>` ref lingers in the main checkout until something prunes
418
- it. After Step 5 confirms `state: "MERGED"`, prune the story ref **and**
419
- fast-forward local `main` (or `project.baseBranch`):
469
+ it. To prune the story ref **and** fast-forward local `main` (or
470
+ `project.baseBranch`):
420
471
 
421
472
  ```bash
422
473
  node .agents/scripts/git-cleanup.js \
@@ -444,37 +495,62 @@ run the cleanup after the manual merge lands.
444
495
 
445
496
  ## Step 7 — Return contract (**required when dispatched as a sub-agent**) {#return-contract}
446
497
 
498
+ The return contract is the shipped schema
499
+ [`story-deliver-terminal.schema.json`](../../schemas/story-deliver-terminal.schema.json)
500
+ — **the single source of truth for every field, and the only place they are
501
+ defined** (Story #4543). Do not restate its fields here or anywhere else:
502
+ this section and
503
+ [`agents/story-worker.md`](../../agents/story-worker.md) each used to define
504
+ their own divergent shape, neither validated by anything, which is exactly
505
+ how they drifted apart.
506
+
447
507
  When this workflow runs as a per-Story sub-agent (dispatched by
448
- [`/deliver`](../deliver.md)), the **only** acceptable way to end your turn
449
- is to **return a single terminal JSON status object** — never free-form
450
- prose:
451
-
452
- ```json
453
- {
454
- "storyId": <number>,
455
- "status": "done" | "blocked" | "failed",
456
- "phase": "init|implementing|closing|blocked|done",
457
- "branchDeleted": <boolean>,
458
- "blockerCommentId": <string|null>,
459
- "detail": "<one-liner: what changed + what was verified, e.g. PR #N merged>",
460
- "renderedBody": "<terminal Story body>"
461
- }
462
- ```
508
+ [`/deliver`](../deliver.md)), the **only** acceptable way to end your turn is
509
+ to return a single terminal JSON object conforming to that schema — never
510
+ free-form prose. `single-story-close.js` already emits a validated one
511
+ between its `--- STORY DELIVER TERMINAL ---` markers; **relay that envelope**
512
+ rather than composing a new object by hand.
513
+
514
+ Its `status` is one of exactly four values, and the no-park rule follows
515
+ directly from them:
516
+
517
+ - `landed` — the PR merged, the Story is `agent::done`, and the tail was
518
+ attempted. Terminal; you are done.
519
+ - `pending` **resumable**, and the only sanctioned way to end a turn
520
+ without a merge. It carries the `nextCommand` that resumes it. Return this
521
+ only when you have exhausted your own budget, not as a way to avoid
522
+ waiting: the wait is internally blocking (Step 4).
523
+ - `blocked` — the Story carries `agent::blocked` and `blocked.blockClass`
524
+ names the class.
525
+ - `failed` — a phase crashed; `phase` names it.
526
+
527
+ Ending the turn with prose and an unconfirmed merge is a contract violation
528
+ (the Story #1553 / PR #1554 failure mode).
529
+
530
+ > **No-park rule + handoff discipline.** For why a prose hand-off with an
531
+ > unconfirmed merge is the very bug this workflow prevents, and the
532
+ > report-state-not-process handoff discipline, see
533
+ > [`deliver-story-reference.md` § Step 7 — Return-contract detail](deliver-story-reference.md#step-7--return-contract-detail).
463
534
 
464
- This section is the single-homed return contract for the Story worker so it
465
- is self-contained when this workflow is the entry point.
535
+ ---
466
536
 
467
- There is **no fourth "pending" status** — the CI/auto-merge wait is handled
468
- internally by blocking on `pr-watch-with-update.js` (Step 4) and confirming
469
- the merge (Step 5). Return **only** on a confirmed `MERGED` PR (`status: "done"`),
470
- an `agent::blocked` transition (`status: "blocked"`), or an unrecoverable
471
- failure (`status: "failed"`).
537
+ ## Recovering a stranded Story {#recover}
472
538
 
473
- > **No-park rule + per-status contract + handoff discipline.** For the full
474
- > terminal-status contract (what each status requires), why a prose hand-off
475
- > with an unconfirmed merge is the very bug this workflow prevents, and the
476
- > report-state-not-process handoff discipline, see
477
- > [`deliver-story-reference.md` § Step 7 — Return-contract detail](deliver-story-reference.md#step-7--return-contract-detail).
539
+ When a Story is in an unclear state a killed run, a `pending` envelope you
540
+ no longer have, a Story a `/deliver` re-run refuses do not guess and do not
541
+ re-run the pipeline hoping it converges. Probe it:
542
+
543
+ ```bash
544
+ node .agents/scripts/deliver-recover.js --story <storyId>
545
+ ```
546
+
547
+ It is **read-only**: it probes the labels, lease, branch, worktree, and PR
548
+ (state + checks), then prints the **one** next command with the evidence it
549
+ was derived from — never a menu.
550
+
551
+ It is the only automated way out of the **merged-but-label-stale** strand: a
552
+ `/deliver` re-run refuses that Story outright, because `single-story-init.js`
553
+ hard-errors on an already-closed one.
478
554
 
479
555
  ---
480
556
 
@@ -510,9 +586,8 @@ safe.
510
586
  your caller (the `/deliver` aggregator or the interactive operator),
511
587
  report essential terminal state only: the Story branch, the closing commit
512
588
  SHA, what changed, and what was verified. Mirror the fields the close
513
- pipeline already emits (`single-story-close.js` / `story-phase.js`
514
- envelopes, the `story-run-progress` snapshot) rather than inventing a new
515
- contract. Do not narrate the steps you took, and do not prescribe how the
589
+ pipeline already emits (the `single-story-close.js` terminal envelope)
590
+ rather than inventing a new contract. Do not narrate the steps you took, and do not prescribe how the
516
591
  next stage should do its work. Prose process commentary only bloats the
517
592
  hydrated prompt.
518
593
  - **Label transitions**: drive every `agent::*` state change through
@@ -525,7 +600,7 @@ safe.
525
600
 
526
601
  ## See also
527
602
 
528
- - [`/deliver`](../deliver.md) — unified entry point (`<storyId...>` or
529
- `--run <planRunId>`; sequences via `depends_on`).
603
+ - [`/deliver`](../deliver.md) — unified entry point (`<storyId...>`;
604
+ sequences via `depends_on`, resolved from live state).
530
605
  - [`deliver-story-reference.md`](deliver-story-reference.md) —
531
606
  lease, sweep, CI-recovery, and Status-column reference detail.
@@ -20,8 +20,8 @@ them in one assistant turn rather than serially. The host runtime executes
20
20
  the batch in parallel; serial calls cost N round-trips for no gain.
21
21
 
22
22
  - **Tool primitives:** `Read`, `Grep`, `Glob`, MCP `list_*` / `get_*` calls.
23
- - **When:** reading the Epic body (with its folded Tech Spec sections)
24
- and Story body up front; grepping
23
+ - **When:** reading the Story body (with its inline `## Spec`)
24
+ up front; grepping
25
25
  for multiple unrelated patterns; globbing several directory trees;
26
26
  fetching independent GitHub tickets.
27
27
  - **Anti-pattern:** sequential `Read` → wait → `Read` → wait → `Grep` chains
@@ -19,32 +19,29 @@ for the broader execution flow.
19
19
 
20
20
  ## Configuration
21
21
 
22
- All knobs live under `delivery.worktreeIsolation` in `.agentrc.json`:
23
-
24
- ```jsonc
25
- {
26
- "delivery": {
27
- "worktreeIsolation": {
28
- "enabled": true, // master switch; false = single-tree (v5.5.1)
29
- "root": ".worktrees", // relative to repo root; must stay inside it
30
- "nodeModulesStrategy": "clone", // clone | per-worktree | symlink | pnpm-store
31
- "primeFromPath": null, // required when strategy = "symlink"
32
- "allowSymlinkOnWindows": false, // explicit opt-in for symlink on win32
33
- "reapOnSuccess": true, // remove worktree after successful story merge
34
- "bootstrapFiles": [
35
- ".env",
36
- ".mcp.json",
37
- ".agentrc.local.json",
38
- ".agents/instructions.local.md"
39
- ]
40
- }
41
- }
42
- }
43
- ```
44
-
45
- The schema is validated by `config-resolver.js`. Unknown strategies, `root`
46
- values that escape the repo root, and shell-metacharacter injection in `root`
47
- are all rejected at config-load time.
22
+ All knobs live under `delivery.worktreeIsolation` in `.agentrc.json`. The
23
+ **key list, types, and accepted enum values are not restated here** — the
24
+ runtime schema in `config-resolver.js` validates them and
25
+ [`.agents/docs/configuration.md`](../../docs/configuration.md) is generated
26
+ from it, so a copy in this file could only drift out of agreement with the
27
+ thing that actually enforces it. Read the generated table for the shape.
28
+
29
+ What that table cannot tell you is which knob to reach for, so this document
30
+ covers the judgement instead, each in its own section below:
31
+
32
+ - `enabled` the master switch; see [Fallback: single-tree mode](#fallback-single-tree-mode).
33
+ - `nodeModulesStrategy`, `primeFromPath`, `allowSymlinkOnWindows` see
34
+ [node_modules strategies](#node_modules-strategies).
35
+ - `root` — where worktrees materialize; see [Windows notes](#windows-notes)
36
+ for the long-path constraint on it.
37
+ - `reapOnSuccess` — drives the **Reap** phase in the lifecycle table below.
38
+ - `bootstrapFiles` — untracked, per-developer files (local env, MCP, and
39
+ `.agentrc.local.json` / `instructions.local.md` overrides) copied into each
40
+ new worktree, because a worktree checkout carries only tracked content and
41
+ would otherwise boot without the operator's local configuration.
42
+
43
+ Config-load rejects unknown strategies, `root` values that escape the repo
44
+ root, and shell-metacharacter injection in `root`.
48
45
 
49
46
  ## Lifecycle
50
47
 
@@ -119,7 +116,7 @@ PowerShell `Get-CimInstance Win32_Process`, terminating them with
119
116
 
120
117
  ### When to run it manually
121
118
 
122
- - The end-of-epic banner reports `pending-cleanup persistent-lock: story-N, ...`.
119
+ - The close output reports `pending-cleanup persistent-lock: story-N, ...`.
123
120
  - `git worktree list` shows `.worktrees/story-N/` for a closed Story.
124
121
  - `npm run lint` fails because of a nested `biome.json` in a half-reaped
125
122
  worktree. The `worktree-residue-biome` self-healing check detects this
@@ -237,7 +234,7 @@ Symlink strategy:
237
234
  the pre-flight warning below catches those cases before a build breaks.
238
235
  - **Long-path warning**: when `worktreePath.length + 80` exceeds
239
236
  `windowsPathLengthWarnThreshold` (default 240), `WorktreeManager` emits a
240
- warning locally and the dispatcher posts an `⚠️` comment on the Epic issue.
237
+ warning locally.
241
238
  Relocate `delivery.worktreeIsolation.root` to a shorter prefix (e.g.
242
239
  `C:\w`) if you see this.
243
240
  - **`packed-refs` contention**: two worktrees fetching concurrently can collide
@@ -335,12 +332,11 @@ Pick single-tree mode when:
335
332
 
336
333
  Human reviewers should **keep using the main checkout** — not a worktree:
337
334
 
338
- - The Epic branch accumulates the cumulative diff for code review; that lives on
339
- the main checkout, not in any per-story worktree.
335
+ - Each Story's diff is reviewed on its PR on GitHub (`story-<id>` `main`);
336
+ no local branch accumulates a cumulative diff for review.
340
337
  - Opening a worktree in an IDE can mislead: the working directory looks like the
341
338
  main repo but carries a different HEAD. The main checkout is the canonical
342
- place to read Epic planning bodies and run the `helpers/code-review.md`
343
- procedure.
339
+ place to run the `helpers/code-review.md` procedure.
344
340
  - `git worktree list --porcelain` on the main checkout enumerates any still
345
341
  in-flight story worktrees if you need to inspect one — prefer read-only
346
342
  operations (`git log`, `git show`) when you do.