@intentius/chant 0.124.54 → 0.124.56

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 (1077) hide show
  1. package/dist/__fixtures__/estate-ledger.d.ts +13 -0
  2. package/dist/__fixtures__/estate-ledger.d.ts.map +1 -0
  3. package/dist/__fixtures__/estate-ledger.js +67 -0
  4. package/dist/__fixtures__/oidc-emulator.d.ts +11 -1
  5. package/dist/__fixtures__/oidc-emulator.d.ts.map +1 -1
  6. package/dist/__fixtures__/oidc-emulator.js +26 -2
  7. package/dist/__fixtures__/product-words.d.ts +78 -0
  8. package/dist/__fixtures__/product-words.d.ts.map +1 -0
  9. package/dist/__fixtures__/product-words.js +43 -0
  10. package/dist/__golden__/wave-loop/op-by-apply-after-fails.json +10 -2
  11. package/dist/__golden__/wave-loop/op-by-apply-hold.json +20 -4
  12. package/dist/__golden__/wave-loop/op-by-apply-ignored.json +10 -2
  13. package/dist/__golden__/wave-loop/op-by-apply-pass.json +10 -2
  14. package/dist/__golden__/wave-loop/op-by-apply-skip.json +10 -2
  15. package/dist/__golden__/wave-loop/op-discover-rest-stops.json +22 -6
  16. package/dist/__golden__/wave-loop/op-discover-rest.json +44 -12
  17. package/dist/__golden__/wave-loop/op-discover-wide.json +12 -3
  18. package/dist/__golden__/wave-loop/op-held-on.json +28 -7
  19. package/dist/__golden__/wave-loop/op-hooks-apply-fails.json +22 -6
  20. package/dist/__golden__/wave-loop/op-hooks-fail-after-apply.json +22 -6
  21. package/dist/__golden__/wave-loop/op-hooks-fail-before-apply.json +4 -2
  22. package/dist/__golden__/wave-loop/op-hooks-held.json +26 -8
  23. package/dist/__golden__/wave-loop/op-hooks-hold-before-apply.json +18 -4
  24. package/dist/__golden__/wave-loop/op-hooks-pass.json +22 -6
  25. package/dist/__golden__/wave-loop/op-hooks-share.json +20 -7
  26. package/dist/__golden__/wave-loop/op-outcome-held.json +12 -3
  27. package/dist/__golden__/wave-loop/op-outcome-replan-approved.json +16 -5
  28. package/dist/__golden__/wave-loop/op-outcome-replan-forever.json +48 -21
  29. package/dist/__golden__/wave-loop/op-outcome-replan.json +16 -5
  30. package/dist/__golden__/wave-loop/op-outcome-stood-down.json +12 -3
  31. package/dist/__golden__/wave-loop/op-outcome-unreadable.json +12 -3
  32. package/dist/__golden__/wave-loop/op-overridden.json +28 -7
  33. package/dist/__golden__/wave-loop/op-per-run.json +20 -4
  34. package/dist/__golden__/wave-loop/op-point.json +18 -4
  35. package/dist/__golden__/wave-loop/op-pr-review.json +10 -2
  36. package/dist/__golden__/wave-loop/op-spend-change-only.json +10 -2
  37. package/dist/__golden__/wave-loop/op-spend.json +10 -2
  38. package/dist/__golden__/wave-loop/op-wave-commands.json +56 -13
  39. package/dist/__golden__/wave-loop/op-wide.json +20 -4
  40. package/dist/bucket-check/azure.d.ts +108 -0
  41. package/dist/bucket-check/azure.d.ts.map +1 -0
  42. package/dist/bucket-check/azure.js +258 -0
  43. package/dist/bucket-check/fixtures/azure.json +153 -0
  44. package/dist/bucket-check/fixtures/gcs.json +148 -0
  45. package/dist/bucket-check/fixtures/s3.json +277 -0
  46. package/dist/bucket-check/gcs.d.ts +77 -0
  47. package/dist/bucket-check/gcs.d.ts.map +1 -0
  48. package/dist/bucket-check/gcs.js +202 -0
  49. package/dist/bucket-check/index.d.ts +48 -0
  50. package/dist/bucket-check/index.d.ts.map +1 -0
  51. package/dist/bucket-check/index.js +44 -0
  52. package/dist/bucket-check/s3.d.ts +116 -0
  53. package/dist/bucket-check/s3.d.ts.map +1 -0
  54. package/dist/bucket-check/s3.js +362 -0
  55. package/dist/bucket-check/types.d.ts +66 -0
  56. package/dist/bucket-check/types.d.ts.map +1 -0
  57. package/dist/bucket-check/types.js +31 -0
  58. package/dist/bucket-check/wire.d.ts +27 -0
  59. package/dist/bucket-check/wire.d.ts.map +1 -0
  60. package/dist/bucket-check/wire.js +32 -0
  61. package/dist/bucket-check.d.ts +6 -0
  62. package/dist/bucket-check.d.ts.map +1 -0
  63. package/dist/bucket-check.js +5 -0
  64. package/dist/capabilities/templates.d.ts.map +1 -1
  65. package/dist/capabilities/templates.js +1 -2
  66. package/dist/change-set.d.ts.map +1 -1
  67. package/dist/change-set.js +2 -3
  68. package/dist/ci-agent.d.ts +381 -0
  69. package/dist/ci-agent.d.ts.map +1 -0
  70. package/dist/ci-agent.js +832 -0
  71. package/dist/ci-audit/attribution.d.ts +111 -0
  72. package/dist/ci-audit/attribution.d.ts.map +1 -0
  73. package/dist/ci-audit/attribution.js +194 -0
  74. package/dist/ci-audit/audit-log.d.ts +144 -0
  75. package/dist/ci-audit/audit-log.d.ts.map +1 -0
  76. package/dist/ci-audit/audit-log.js +149 -0
  77. package/dist/ci-audit/index.d.ts +12 -0
  78. package/dist/ci-audit/index.d.ts.map +1 -0
  79. package/dist/ci-audit/index.js +12 -0
  80. package/dist/ci-audit/unrecorded.d.ts +74 -0
  81. package/dist/ci-audit/unrecorded.d.ts.map +1 -0
  82. package/dist/ci-audit/unrecorded.js +95 -0
  83. package/dist/ci-audit.d.ts +3 -0
  84. package/dist/ci-audit.d.ts.map +1 -0
  85. package/dist/ci-audit.js +2 -0
  86. package/dist/ci-control.d.ts +42 -0
  87. package/dist/ci-control.d.ts.map +1 -0
  88. package/dist/ci-control.js +41 -0
  89. package/dist/ci-estate/delivery.d.ts +137 -0
  90. package/dist/ci-estate/delivery.d.ts.map +1 -0
  91. package/dist/ci-estate/delivery.js +311 -0
  92. package/dist/ci-estate/overdue.d.ts +34 -0
  93. package/dist/ci-estate/overdue.d.ts.map +1 -0
  94. package/dist/ci-estate/overdue.js +58 -0
  95. package/dist/ci-estate/page.d.ts +134 -0
  96. package/dist/ci-estate/page.d.ts.map +1 -0
  97. package/dist/ci-estate/page.js +233 -0
  98. package/dist/ci-estate/rows.d.ts +118 -0
  99. package/dist/ci-estate/rows.d.ts.map +1 -0
  100. package/dist/ci-estate/rows.js +126 -0
  101. package/dist/ci-estate.d.ts +92 -0
  102. package/dist/ci-estate.d.ts.map +1 -0
  103. package/dist/ci-estate.js +82 -0
  104. package/dist/ci-handover.d.ts +29 -5
  105. package/dist/ci-handover.d.ts.map +1 -1
  106. package/dist/ci-handover.js +50 -16
  107. package/dist/ci-identity.d.ts +82 -7
  108. package/dist/ci-identity.d.ts.map +1 -1
  109. package/dist/ci-identity.js +86 -15
  110. package/dist/ci-job-guard.d.ts +139 -0
  111. package/dist/ci-job-guard.d.ts.map +1 -0
  112. package/dist/ci-job-guard.js +287 -0
  113. package/dist/ci-jobs.d.ts +7 -0
  114. package/dist/ci-jobs.d.ts.map +1 -1
  115. package/dist/ci-jobs.js +7 -0
  116. package/dist/ci-product-words.d.ts +296 -0
  117. package/dist/ci-product-words.d.ts.map +1 -0
  118. package/dist/ci-product-words.js +407 -0
  119. package/dist/ci-product.d.ts +117 -0
  120. package/dist/ci-product.d.ts.map +1 -0
  121. package/dist/ci-product.js +113 -0
  122. package/dist/ci-respond-run.d.ts +73 -0
  123. package/dist/ci-respond-run.d.ts.map +1 -0
  124. package/dist/ci-respond-run.js +247 -0
  125. package/dist/ci-respond.d.ts +189 -0
  126. package/dist/ci-respond.d.ts.map +1 -0
  127. package/dist/ci-respond.js +285 -0
  128. package/dist/cli/commands/audit.d.ts +2 -2
  129. package/dist/cli/commands/audit.d.ts.map +1 -1
  130. package/dist/cli/commands/audit.js +3 -2
  131. package/dist/cli/commands/carve.js +2 -2
  132. package/dist/cli/commands/init.d.ts +2 -0
  133. package/dist/cli/commands/init.d.ts.map +1 -1
  134. package/dist/cli/commands/init.js +1 -1
  135. package/dist/cli/handlers/agent.d.ts +17 -0
  136. package/dist/cli/handlers/agent.d.ts.map +1 -0
  137. package/dist/cli/handlers/agent.js +114 -0
  138. package/dist/cli/handlers/approve-confirm.d.ts +84 -0
  139. package/dist/cli/handlers/approve-confirm.d.ts.map +1 -0
  140. package/dist/cli/handlers/approve-confirm.js +142 -0
  141. package/dist/cli/handlers/approve.d.ts.map +1 -1
  142. package/dist/cli/handlers/approve.js +19 -1
  143. package/dist/cli/handlers/audit-log.d.ts +12 -0
  144. package/dist/cli/handlers/audit-log.d.ts.map +1 -0
  145. package/dist/cli/handlers/audit-log.js +81 -0
  146. package/dist/cli/handlers/build.d.ts +7 -0
  147. package/dist/cli/handlers/build.d.ts.map +1 -1
  148. package/dist/cli/handlers/build.js +124 -1
  149. package/dist/cli/handlers/ci-check-job.d.ts +11 -0
  150. package/dist/cli/handlers/ci-check-job.d.ts.map +1 -0
  151. package/dist/cli/handlers/ci-check-job.js +27 -0
  152. package/dist/cli/handlers/ci-check.d.ts +3 -0
  153. package/dist/cli/handlers/ci-check.d.ts.map +1 -0
  154. package/dist/cli/handlers/ci-check.js +63 -0
  155. package/dist/cli/handlers/ci-forge-check.d.ts +3 -0
  156. package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -0
  157. package/dist/cli/handlers/ci-forge-check.js +89 -0
  158. package/dist/cli/handlers/e2e-safe-run.d.ts +12 -0
  159. package/dist/cli/handlers/e2e-safe-run.d.ts.map +1 -0
  160. package/dist/cli/handlers/e2e-safe-run.js +23 -0
  161. package/dist/cli/handlers/fan-out.js +4 -0
  162. package/dist/cli/handlers/gate-pending.d.ts +11 -0
  163. package/dist/cli/handlers/gate-pending.d.ts.map +1 -0
  164. package/dist/cli/handlers/gate-pending.js +44 -0
  165. package/dist/cli/handlers/init.d.ts.map +1 -1
  166. package/dist/cli/handlers/init.js +1 -0
  167. package/dist/cli/handlers/ledger.js +1 -1
  168. package/dist/cli/handlers/lifecycle-drift.d.ts +6 -2
  169. package/dist/cli/handlers/lifecycle-drift.d.ts.map +1 -1
  170. package/dist/cli/handlers/lifecycle-drift.js +7 -2
  171. package/dist/cli/handlers/lock.d.ts.map +1 -1
  172. package/dist/cli/handlers/lock.js +64 -5
  173. package/dist/cli/handlers/notify-relay.d.ts +15 -0
  174. package/dist/cli/handlers/notify-relay.d.ts.map +1 -0
  175. package/dist/cli/handlers/notify-relay.js +130 -0
  176. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  177. package/dist/cli/handlers/pr-env.js +42 -11
  178. package/dist/cli/handlers/pr.d.ts +43 -3
  179. package/dist/cli/handlers/pr.d.ts.map +1 -1
  180. package/dist/cli/handlers/pr.js +908 -205
  181. package/dist/cli/handlers/promote.d.ts.map +1 -1
  182. package/dist/cli/handlers/promote.js +21 -2
  183. package/dist/cli/handlers/release.d.ts.map +1 -1
  184. package/dist/cli/handlers/release.js +3 -0
  185. package/dist/cli/handlers/run-wave.d.ts +8 -0
  186. package/dist/cli/handlers/run-wave.d.ts.map +1 -1
  187. package/dist/cli/handlers/run-wave.js +160 -2
  188. package/dist/cli/handlers/run.d.ts +6 -1
  189. package/dist/cli/handlers/run.d.ts.map +1 -1
  190. package/dist/cli/handlers/run.js +86 -1
  191. package/dist/cli/handlers/serve.d.ts.map +1 -1
  192. package/dist/cli/handlers/serve.js +10 -1
  193. package/dist/cli/main.d.ts +11 -1
  194. package/dist/cli/main.d.ts.map +1 -1
  195. package/dist/cli/main.js +178 -13
  196. package/dist/cli/mcp/ledger-tools.d.ts +36 -0
  197. package/dist/cli/mcp/ledger-tools.d.ts.map +1 -0
  198. package/dist/cli/mcp/ledger-tools.js +122 -0
  199. package/dist/cli/mcp/product-tools.d.ts +78 -0
  200. package/dist/cli/mcp/product-tools.d.ts.map +1 -0
  201. package/dist/cli/mcp/product-tools.js +93 -0
  202. package/dist/cli/mcp/read-only.d.ts +34 -0
  203. package/dist/cli/mcp/read-only.d.ts.map +1 -0
  204. package/dist/cli/mcp/read-only.js +61 -0
  205. package/dist/cli/mcp/report-tools.d.ts +48 -0
  206. package/dist/cli/mcp/report-tools.d.ts.map +1 -0
  207. package/dist/cli/mcp/report-tools.js +128 -0
  208. package/dist/cli/mcp/server.d.ts +28 -1
  209. package/dist/cli/mcp/server.d.ts.map +1 -1
  210. package/dist/cli/mcp/server.js +86 -15
  211. package/dist/cli/mcp-config.d.ts +9 -2
  212. package/dist/cli/mcp-config.d.ts.map +1 -1
  213. package/dist/cli/mcp-config.js +8 -3
  214. package/dist/cli/parse-args.d.ts.map +1 -1
  215. package/dist/cli/parse-args.js +164 -3
  216. package/dist/cli/registry.d.ts +73 -0
  217. package/dist/cli/registry.d.ts.map +1 -1
  218. package/dist/cloud-lister/sigv4.d.ts +42 -7
  219. package/dist/cloud-lister/sigv4.d.ts.map +1 -1
  220. package/dist/cloud-lister/sigv4.js +72 -22
  221. package/dist/components/adoption.d.ts +69 -0
  222. package/dist/components/adoption.d.ts.map +1 -0
  223. package/dist/components/adoption.js +92 -0
  224. package/dist/components/apply-lease.d.ts +19 -0
  225. package/dist/components/apply-lease.d.ts.map +1 -0
  226. package/dist/components/apply-lease.js +41 -0
  227. package/dist/components/capability.d.ts +159 -5
  228. package/dist/components/capability.d.ts.map +1 -1
  229. package/dist/components/capability.js +39 -6
  230. package/dist/components/check-hooks.d.ts +116 -0
  231. package/dist/components/check-hooks.d.ts.map +1 -0
  232. package/dist/components/check-hooks.js +192 -0
  233. package/dist/components/check-steps.d.ts +74 -0
  234. package/dist/components/check-steps.d.ts.map +1 -0
  235. package/dist/components/check-steps.js +102 -0
  236. package/dist/components/ci-services.d.ts +57 -0
  237. package/dist/components/ci-services.d.ts.map +1 -0
  238. package/dist/components/ci-services.js +60 -0
  239. package/dist/components/cli-support.d.ts +13 -0
  240. package/dist/components/cli-support.d.ts.map +1 -1
  241. package/dist/components/cli-support.js +10 -2
  242. package/dist/components/driver.d.ts +32 -3
  243. package/dist/components/driver.d.ts.map +1 -1
  244. package/dist/components/driver.js +59 -5
  245. package/dist/components/fan-out-run.d.ts +12 -0
  246. package/dist/components/fan-out-run.d.ts.map +1 -1
  247. package/dist/components/fan-out-run.js +56 -16
  248. package/dist/components/groups.d.ts.map +1 -1
  249. package/dist/components/groups.js +23 -5
  250. package/dist/components/pr-env-ledger.d.ts +32 -0
  251. package/dist/components/pr-env-ledger.d.ts.map +1 -0
  252. package/dist/components/pr-env-ledger.js +38 -0
  253. package/dist/components/pr-env-ports.d.ts +12 -0
  254. package/dist/components/pr-env-ports.d.ts.map +1 -1
  255. package/dist/components/pr-env-ports.js +13 -3
  256. package/dist/components/pr-env-run.d.ts +6 -0
  257. package/dist/components/pr-env-run.d.ts.map +1 -1
  258. package/dist/components/pr-env-run.js +3 -2
  259. package/dist/components/pr-environment.d.ts +32 -4
  260. package/dist/components/pr-environment.d.ts.map +1 -1
  261. package/dist/components/pr-environment.js +26 -8
  262. package/dist/components/pr-pipeline.d.ts +297 -5
  263. package/dist/components/pr-pipeline.d.ts.map +1 -1
  264. package/dist/components/pr-pipeline.js +329 -18
  265. package/dist/components/pr-policy.d.ts +26 -2
  266. package/dist/components/pr-policy.d.ts.map +1 -1
  267. package/dist/components/pr-policy.js +41 -7
  268. package/dist/components/pr-run.d.ts +71 -0
  269. package/dist/components/pr-run.d.ts.map +1 -1
  270. package/dist/components/pr-run.js +91 -7
  271. package/dist/components/pr-targets.d.ts +24 -0
  272. package/dist/components/pr-targets.d.ts.map +1 -0
  273. package/dist/components/pr-targets.js +48 -0
  274. package/dist/components/product-pipeline.d.ts +250 -0
  275. package/dist/components/product-pipeline.d.ts.map +1 -0
  276. package/dist/components/product-pipeline.js +212 -0
  277. package/dist/components/promote.d.ts +6 -0
  278. package/dist/components/promote.d.ts.map +1 -1
  279. package/dist/components/promote.js +4 -1
  280. package/dist/components/release-compile.d.ts +22 -1
  281. package/dist/components/release-compile.d.ts.map +1 -1
  282. package/dist/components/release-compile.js +85 -0
  283. package/dist/components/release-promote.d.ts +15 -1
  284. package/dist/components/release-promote.d.ts.map +1 -1
  285. package/dist/components/release-promote.js +67 -2
  286. package/dist/components/repo-lock.d.ts +27 -0
  287. package/dist/components/repo-lock.d.ts.map +1 -0
  288. package/dist/components/repo-lock.js +49 -0
  289. package/dist/components/row-lease.d.ts +84 -0
  290. package/dist/components/row-lease.d.ts.map +1 -0
  291. package/dist/components/row-lease.js +110 -0
  292. package/dist/components/wave-plan.d.ts +42 -0
  293. package/dist/components/wave-plan.d.ts.map +1 -1
  294. package/dist/components/wave-plan.js +72 -4
  295. package/dist/control/applied.d.ts +89 -0
  296. package/dist/control/applied.d.ts.map +1 -0
  297. package/dist/control/applied.js +175 -0
  298. package/dist/control/consumers.d.ts +78 -0
  299. package/dist/control/consumers.d.ts.map +1 -0
  300. package/dist/control/consumers.js +172 -0
  301. package/dist/control/dispatch.d.ts +334 -0
  302. package/dist/control/dispatch.d.ts.map +1 -0
  303. package/dist/control/dispatch.js +519 -0
  304. package/dist/control/edges.d.ts +75 -0
  305. package/dist/control/edges.d.ts.map +1 -0
  306. package/dist/control/edges.js +133 -0
  307. package/dist/control/reconcile.d.ts +120 -0
  308. package/dist/control/reconcile.d.ts.map +1 -0
  309. package/dist/control/reconcile.js +178 -0
  310. package/dist/control/records.d.ts +187 -0
  311. package/dist/control/records.d.ts.map +1 -0
  312. package/dist/control/records.js +307 -0
  313. package/dist/discovery/sandbox/bundle.d.ts.map +1 -1
  314. package/dist/discovery/sandbox/bundle.js +25 -1
  315. package/dist/e2e-harness/bucket.d.ts +21 -0
  316. package/dist/e2e-harness/bucket.d.ts.map +1 -0
  317. package/dist/e2e-harness/bucket.js +61 -0
  318. package/dist/e2e-harness/claim.d.ts +70 -0
  319. package/dist/e2e-harness/claim.d.ts.map +1 -0
  320. package/dist/e2e-harness/claim.js +98 -0
  321. package/dist/e2e-harness/driver.d.ts +64 -0
  322. package/dist/e2e-harness/driver.d.ts.map +1 -0
  323. package/dist/e2e-harness/driver.js +243 -0
  324. package/dist/e2e-harness/forgejo.d.ts +77 -0
  325. package/dist/e2e-harness/forgejo.d.ts.map +1 -0
  326. package/dist/e2e-harness/forgejo.js +205 -0
  327. package/dist/e2e-harness/git.d.ts +32 -0
  328. package/dist/e2e-harness/git.d.ts.map +1 -0
  329. package/dist/e2e-harness/git.js +67 -0
  330. package/dist/e2e-harness/index.d.ts +22 -0
  331. package/dist/e2e-harness/index.d.ts.map +1 -0
  332. package/dist/e2e-harness/index.js +48 -0
  333. package/dist/e2e-harness/jobs.d.ts +8 -0
  334. package/dist/e2e-harness/jobs.d.ts.map +1 -0
  335. package/dist/e2e-harness/jobs.js +34 -0
  336. package/dist/e2e-harness/pins.d.ts +45 -0
  337. package/dist/e2e-harness/pins.d.ts.map +1 -0
  338. package/dist/e2e-harness/pins.js +44 -0
  339. package/dist/e2e-harness/ports.d.ts +113 -0
  340. package/dist/e2e-harness/ports.d.ts.map +1 -0
  341. package/dist/e2e-harness/ports.js +4 -0
  342. package/dist/e2e-harness/reports.d.ts +45 -0
  343. package/dist/e2e-harness/reports.d.ts.map +1 -0
  344. package/dist/e2e-harness/reports.js +57 -0
  345. package/dist/e2e-harness/safe-run-cli.d.ts +17 -0
  346. package/dist/e2e-harness/safe-run-cli.d.ts.map +1 -0
  347. package/dist/e2e-harness/safe-run-cli.js +43 -0
  348. package/dist/e2e-harness/safe-run.d.ts +61 -0
  349. package/dist/e2e-harness/safe-run.d.ts.map +1 -0
  350. package/dist/e2e-harness/safe-run.js +172 -0
  351. package/dist/e2e-harness/scenario.d.ts +11 -0
  352. package/dist/e2e-harness/scenario.d.ts.map +1 -0
  353. package/dist/e2e-harness/scenario.js +89 -0
  354. package/dist/e2e-harness/schemas/demo-cycle.schema.json +282 -0
  355. package/dist/e2e-harness/schemas/demo-step.schema.json +245 -0
  356. package/dist/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
  357. package/dist/e2e-harness/schemas/e2e-claims.schema.json +18 -0
  358. package/dist/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
  359. package/dist/e2e-harness/schemas/index.d.ts +191 -0
  360. package/dist/e2e-harness/schemas/index.d.ts.map +1 -0
  361. package/dist/e2e-harness/schemas/index.js +62 -0
  362. package/dist/e2e-harness/stack.d.ts +124 -0
  363. package/dist/e2e-harness/stack.d.ts.map +1 -0
  364. package/dist/e2e-harness/stack.js +207 -0
  365. package/dist/e2e-harness/steps.d.ts +11 -0
  366. package/dist/e2e-harness/steps.d.ts.map +1 -0
  367. package/dist/e2e-harness/steps.js +22 -0
  368. package/dist/e2e-harness.d.ts +3 -0
  369. package/dist/e2e-harness.d.ts.map +1 -0
  370. package/dist/e2e-harness.js +2 -0
  371. package/dist/engine-facts.d.ts.map +1 -1
  372. package/dist/engine-facts.js +1 -2
  373. package/dist/exit-codes.d.ts +54 -0
  374. package/dist/exit-codes.d.ts.map +1 -0
  375. package/dist/exit-codes.js +55 -0
  376. package/dist/forge-check/check.d.ts +63 -0
  377. package/dist/forge-check/check.d.ts.map +1 -0
  378. package/dist/forge-check/check.js +139 -0
  379. package/dist/forge-check/contract.d.ts +152 -0
  380. package/dist/forge-check/contract.d.ts.map +1 -0
  381. package/dist/forge-check/contract.js +118 -0
  382. package/dist/forge-check/forge.d.ts +42 -0
  383. package/dist/forge-check/forge.d.ts.map +1 -0
  384. package/dist/forge-check/forge.js +338 -0
  385. package/dist/forge-check/index.d.ts +24 -0
  386. package/dist/forge-check/index.d.ts.map +1 -0
  387. package/dist/forge-check/index.js +23 -0
  388. package/dist/forge-check/pulumi.d.ts +44 -0
  389. package/dist/forge-check/pulumi.d.ts.map +1 -0
  390. package/dist/forge-check/pulumi.js +184 -0
  391. package/dist/forge-check/read-only.d.ts +26 -0
  392. package/dist/forge-check/read-only.d.ts.map +1 -0
  393. package/dist/forge-check/read-only.js +53 -0
  394. package/dist/forge-check/trust.d.ts +94 -0
  395. package/dist/forge-check/trust.d.ts.map +1 -0
  396. package/dist/forge-check/trust.js +532 -0
  397. package/dist/forge-check/types.d.ts +80 -0
  398. package/dist/forge-check/types.d.ts.map +1 -0
  399. package/dist/forge-check/types.js +18 -0
  400. package/dist/forge-check.d.ts +6 -0
  401. package/dist/forge-check.d.ts.map +1 -0
  402. package/dist/forge-check.js +5 -0
  403. package/dist/gate-decision.d.ts +1 -0
  404. package/dist/gate-decision.d.ts.map +1 -1
  405. package/dist/gate-decision.js +2 -0
  406. package/dist/gate-policy.d.ts +47 -1
  407. package/dist/gate-policy.d.ts.map +1 -1
  408. package/dist/gate-policy.js +50 -2
  409. package/dist/index.d.ts +1 -0
  410. package/dist/index.d.ts.map +1 -1
  411. package/dist/index.js +2 -0
  412. package/dist/lexicon.d.ts +152 -6
  413. package/dist/lexicon.d.ts.map +1 -1
  414. package/dist/lifecycle/adoption-file.d.ts +24 -0
  415. package/dist/lifecycle/adoption-file.d.ts.map +1 -1
  416. package/dist/lifecycle/adoption-file.js +1 -2
  417. package/dist/lifecycle/cloud-index.d.ts.map +1 -1
  418. package/dist/lifecycle/cloud-index.js +1 -2
  419. package/dist/lifecycle/gate-applied.d.ts +6 -0
  420. package/dist/lifecycle/gate-applied.d.ts.map +1 -1
  421. package/dist/lifecycle/gate-ledger.d.ts +29 -0
  422. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  423. package/dist/lifecycle/gate-ledger.js +10 -1
  424. package/dist/lifecycle/gate-pending-by-plan.d.ts +75 -0
  425. package/dist/lifecycle/gate-pending-by-plan.d.ts.map +1 -0
  426. package/dist/lifecycle/gate-pending-by-plan.js +96 -0
  427. package/dist/lifecycle/gated-request-digest.d.ts +28 -0
  428. package/dist/lifecycle/gated-request-digest.d.ts.map +1 -0
  429. package/dist/lifecycle/gated-request-digest.js +35 -0
  430. package/dist/lifecycle/gated-request.d.ts +126 -0
  431. package/dist/lifecycle/gated-request.d.ts.map +1 -0
  432. package/dist/lifecycle/gated-request.js +204 -0
  433. package/dist/lifecycle/identity-match.d.ts +15 -0
  434. package/dist/lifecycle/identity-match.d.ts.map +1 -1
  435. package/dist/lifecycle/identity-match.js +11 -6
  436. package/dist/lifecycle/index-diff.d.ts +40 -0
  437. package/dist/lifecycle/index-diff.d.ts.map +1 -1
  438. package/dist/lifecycle/index-diff.js +1 -2
  439. package/dist/lifecycle/index-document.d.ts.map +1 -1
  440. package/dist/lifecycle/index-document.js +1 -2
  441. package/dist/lifecycle/index-import.d.ts +4 -1
  442. package/dist/lifecycle/index-import.d.ts.map +1 -1
  443. package/dist/lifecycle/index-import.js +29 -32
  444. package/dist/lifecycle/ledger-read.d.ts.map +1 -1
  445. package/dist/lifecycle/ledger-read.js +7 -3
  446. package/dist/lifecycle/lock-rows.d.ts +76 -0
  447. package/dist/lifecycle/lock-rows.d.ts.map +1 -0
  448. package/dist/lifecycle/lock-rows.js +140 -0
  449. package/dist/lifecycle/query.d.ts +50 -3
  450. package/dist/lifecycle/query.d.ts.map +1 -1
  451. package/dist/lifecycle/query.js +97 -7
  452. package/dist/lifecycle/release-catalog-site.d.ts +66 -0
  453. package/dist/lifecycle/release-catalog-site.d.ts.map +1 -0
  454. package/dist/lifecycle/release-catalog-site.js +232 -0
  455. package/dist/lifecycle/release-catalog.d.ts +201 -0
  456. package/dist/lifecycle/release-catalog.d.ts.map +1 -0
  457. package/dist/lifecycle/release-catalog.js +198 -0
  458. package/dist/lifecycle/release-changelog.d.ts +41 -0
  459. package/dist/lifecycle/release-changelog.d.ts.map +1 -0
  460. package/dist/lifecycle/release-changelog.js +38 -0
  461. package/dist/lifecycle/release-cut.d.ts +1 -0
  462. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  463. package/dist/lifecycle/release-cut.js +1 -1
  464. package/dist/lifecycle/release-ledger.d.ts +16 -0
  465. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  466. package/dist/lifecycle/release-ledger.js +9 -0
  467. package/dist/lifecycle/release-publish.d.ts +43 -22
  468. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  469. package/dist/lifecycle/release-read.d.ts.map +1 -1
  470. package/dist/lifecycle/release-read.js +3 -0
  471. package/dist/lifecycle/release-status.d.ts +106 -0
  472. package/dist/lifecycle/release-status.d.ts.map +1 -0
  473. package/dist/lifecycle/release-status.js +115 -0
  474. package/dist/lifecycle/resource-lock.d.ts +120 -0
  475. package/dist/lifecycle/resource-lock.d.ts.map +1 -0
  476. package/dist/lifecycle/resource-lock.js +317 -0
  477. package/dist/lifecycle/retention.d.ts.map +1 -1
  478. package/dist/lifecycle/retention.js +3 -0
  479. package/dist/lifecycle/run-ledger.d.ts.map +1 -1
  480. package/dist/lifecycle/run-ledger.js +9 -1
  481. package/dist/lifecycle/snapshot-store-s3.d.ts +36 -3
  482. package/dist/lifecycle/snapshot-store-s3.d.ts.map +1 -1
  483. package/dist/lifecycle/snapshot-store-s3.js +9 -44
  484. package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
  485. package/dist/lifecycle/snapshot-store.js +1 -2
  486. package/dist/lifecycle/target-lock.d.ts +15 -0
  487. package/dist/lifecycle/target-lock.d.ts.map +1 -1
  488. package/dist/lifecycle/target-lock.js +25 -10
  489. package/dist/lifecycle/wave-plans.d.ts +23 -7
  490. package/dist/lifecycle/wave-plans.d.ts.map +1 -1
  491. package/dist/lifecycle/wave-plans.js +9 -2
  492. package/dist/mcp/types.d.ts +7 -0
  493. package/dist/mcp/types.d.ts.map +1 -1
  494. package/dist/notify-product.d.ts +43 -0
  495. package/dist/notify-product.d.ts.map +1 -0
  496. package/dist/notify-product.js +58 -0
  497. package/dist/notify-relay.d.ts +197 -0
  498. package/dist/notify-relay.d.ts.map +1 -0
  499. package/dist/notify-relay.js +321 -0
  500. package/dist/notify.d.ts +44 -4
  501. package/dist/notify.d.ts.map +1 -1
  502. package/dist/notify.js +77 -14
  503. package/dist/object-store/azure-blob.d.ts +129 -0
  504. package/dist/object-store/azure-blob.d.ts.map +1 -0
  505. package/dist/object-store/azure-blob.js +341 -0
  506. package/dist/object-store/common.d.ts +108 -0
  507. package/dist/object-store/common.d.ts.map +1 -0
  508. package/dist/object-store/common.js +80 -0
  509. package/dist/object-store/errors.d.ts +28 -0
  510. package/dist/object-store/errors.d.ts.map +1 -0
  511. package/dist/object-store/errors.js +21 -0
  512. package/dist/object-store/from-env.d.ts +18 -0
  513. package/dist/object-store/from-env.d.ts.map +1 -0
  514. package/dist/object-store/from-env.js +22 -0
  515. package/dist/object-store/gcs.d.ts +106 -0
  516. package/dist/object-store/gcs.d.ts.map +1 -0
  517. package/dist/object-store/gcs.js +393 -0
  518. package/dist/object-store/index.d.ts +9 -0
  519. package/dist/object-store/index.d.ts.map +1 -0
  520. package/dist/object-store/index.js +8 -0
  521. package/dist/object-store/s3.d.ts +146 -0
  522. package/dist/object-store/s3.d.ts.map +1 -0
  523. package/dist/object-store/s3.js +306 -0
  524. package/dist/op/activities/converge.d.ts.map +1 -1
  525. package/dist/op/activities/converge.js +2 -1
  526. package/dist/op/activities/index.d.ts +1 -1
  527. package/dist/op/activities/index.d.ts.map +1 -1
  528. package/dist/op/activities/index.js +1 -1
  529. package/dist/op/activities/review-agent.d.ts +55 -2
  530. package/dist/op/activities/review-agent.d.ts.map +1 -1
  531. package/dist/op/activities/review-agent.js +65 -5
  532. package/dist/op/approval-status.d.ts +103 -0
  533. package/dist/op/approval-status.d.ts.map +1 -0
  534. package/dist/op/approval-status.js +197 -0
  535. package/dist/op/gate.d.ts +29 -1
  536. package/dist/op/gate.d.ts.map +1 -1
  537. package/dist/op/gate.js +59 -23
  538. package/dist/op/generate-pipeline.d.ts.map +1 -1
  539. package/dist/op/generate-pipeline.js +7 -1
  540. package/dist/op/index.d.ts +12 -1
  541. package/dist/op/index.d.ts.map +1 -1
  542. package/dist/op/index.js +7 -1
  543. package/dist/op/op-waves-after-plan.d.ts +137 -0
  544. package/dist/op/op-waves-after-plan.d.ts.map +1 -0
  545. package/dist/op/op-waves-after-plan.js +163 -0
  546. package/dist/op/op-waves-capability-spec.d.ts +63 -0
  547. package/dist/op/op-waves-capability-spec.d.ts.map +1 -0
  548. package/dist/op/op-waves-capability-spec.js +115 -0
  549. package/dist/op/op-waves-capability.d.ts +197 -0
  550. package/dist/op/op-waves-capability.d.ts.map +1 -0
  551. package/dist/op/op-waves-capability.js +311 -0
  552. package/dist/op/op-waves-events.d.ts +54 -0
  553. package/dist/op/op-waves-events.d.ts.map +1 -0
  554. package/dist/op/op-waves-events.js +122 -0
  555. package/dist/op/op-waves-notify.d.ts +7 -1
  556. package/dist/op/op-waves-notify.d.ts.map +1 -1
  557. package/dist/op/op-waves-notify.js +35 -16
  558. package/dist/op/op-waves-release-port.d.ts +18 -0
  559. package/dist/op/op-waves-release-port.d.ts.map +1 -0
  560. package/dist/op/op-waves-release-port.js +61 -0
  561. package/dist/op/op-waves-release.d.ts +92 -0
  562. package/dist/op/op-waves-release.d.ts.map +1 -0
  563. package/dist/op/op-waves-release.js +96 -0
  564. package/dist/op/op-waves-run.d.ts +182 -6
  565. package/dist/op/op-waves-run.d.ts.map +1 -1
  566. package/dist/op/op-waves-run.js +1076 -44
  567. package/dist/op/op-waves-stand-down.d.ts +60 -0
  568. package/dist/op/op-waves-stand-down.d.ts.map +1 -0
  569. package/dist/op/op-waves-stand-down.js +96 -0
  570. package/dist/op/op-waves.d.ts +187 -8
  571. package/dist/op/op-waves.d.ts.map +1 -1
  572. package/dist/op/op-waves.js +203 -19
  573. package/dist/op/runtime.d.ts +95 -0
  574. package/dist/op/runtime.d.ts.map +1 -1
  575. package/dist/op/runtime.js +18 -0
  576. package/dist/op/stage-hooks.d.ts +45 -7
  577. package/dist/op/stage-hooks.d.ts.map +1 -1
  578. package/dist/op/stage-hooks.js +61 -3
  579. package/dist/op/steward-beside.d.ts.map +1 -1
  580. package/dist/op/steward-beside.js +2 -1
  581. package/dist/op/types.d.ts +2 -2
  582. package/dist/op/types.d.ts.map +1 -1
  583. package/dist/op/types.js +3 -2
  584. package/dist/otlp-metrics.d.ts +38 -0
  585. package/dist/otlp-metrics.d.ts.map +1 -0
  586. package/dist/otlp-metrics.js +82 -0
  587. package/dist/otlp.d.ts +249 -0
  588. package/dist/otlp.d.ts.map +1 -0
  589. package/dist/otlp.js +425 -0
  590. package/dist/override-gate.d.ts.map +1 -1
  591. package/dist/override-gate.js +5 -0
  592. package/dist/parallelism.d.ts +17 -0
  593. package/dist/parallelism.d.ts.map +1 -0
  594. package/dist/parallelism.js +33 -0
  595. package/dist/policy-packs.d.ts +69 -0
  596. package/dist/policy-packs.d.ts.map +1 -0
  597. package/dist/policy-packs.js +205 -0
  598. package/dist/policy-source.d.ts +51 -0
  599. package/dist/policy-source.d.ts.map +1 -0
  600. package/dist/policy-source.js +102 -0
  601. package/dist/pr-forge.d.ts +40 -0
  602. package/dist/pr-forge.d.ts.map +1 -1
  603. package/dist/pr-forge.js +146 -37
  604. package/dist/pr-loop.d.ts +158 -11
  605. package/dist/pr-loop.d.ts.map +1 -1
  606. package/dist/pr-loop.js +302 -44
  607. package/dist/pr-merge.d.ts +64 -0
  608. package/dist/pr-merge.d.ts.map +1 -0
  609. package/dist/pr-merge.js +78 -0
  610. package/dist/pr-post.d.ts +86 -1
  611. package/dist/pr-post.d.ts.map +1 -1
  612. package/dist/pr-post.js +141 -5
  613. package/dist/pr-report-url.d.ts +32 -4
  614. package/dist/pr-report-url.d.ts.map +1 -1
  615. package/dist/pr-report-url.js +45 -5
  616. package/dist/pr-requires.d.ts +13 -2
  617. package/dist/pr-requires.d.ts.map +1 -1
  618. package/dist/pr-requires.js +14 -0
  619. package/dist/release-floors.d.ts +1 -1
  620. package/dist/release-floors.js +1 -1
  621. package/dist/run-event.d.ts +26 -1
  622. package/dist/run-event.d.ts.map +1 -1
  623. package/dist/run-event.js +3 -1
  624. package/dist/scheduled-op-cloud.d.ts +32 -0
  625. package/dist/scheduled-op-cloud.d.ts.map +1 -0
  626. package/dist/scheduled-op-cloud.js +69 -0
  627. package/dist/sorted-json.d.ts +10 -0
  628. package/dist/sorted-json.d.ts.map +1 -0
  629. package/dist/sorted-json.js +14 -0
  630. package/dist/terraform/credentials.d.ts +59 -0
  631. package/dist/terraform/credentials.d.ts.map +1 -0
  632. package/dist/terraform/credentials.js +149 -0
  633. package/dist/utils.d.ts +1 -4
  634. package/dist/utils.d.ts.map +1 -1
  635. package/dist/utils.js +1 -9
  636. package/dist/wave-runtime.d.ts +1 -1
  637. package/dist/wave-runtime.js +2 -2
  638. package/dist/wave-runtime.mjs +405 -287
  639. package/dist/workspace/chant-migrations/chud-lexicon-exit.d.ts.map +1 -1
  640. package/dist/workspace/chant-migrations/chud-lexicon-exit.js +4 -1
  641. package/dist/workspace/ci-lock-grain.d.ts +17 -0
  642. package/dist/workspace/ci-lock-grain.d.ts.map +1 -0
  643. package/dist/workspace/ci-lock-grain.js +21 -0
  644. package/dist/workspace/ci-run.d.ts +2 -1
  645. package/dist/workspace/ci-run.d.ts.map +1 -1
  646. package/dist/workspace/ci-run.js +10 -3
  647. package/dist/workspace/declaration.d.ts +16 -4
  648. package/dist/workspace/declaration.d.ts.map +1 -1
  649. package/dist/workspace/declaration.js +5 -2
  650. package/dist/workspace/declaration.schema.json +27 -3
  651. package/dist/workspace/drift-cli.d.ts.map +1 -1
  652. package/dist/workspace/drift-cli.js +8 -3
  653. package/dist/workspace/exit-cli.d.ts +1 -1
  654. package/dist/workspace/exit-cli.d.ts.map +1 -1
  655. package/dist/workspace/exit-cli.js +2 -1
  656. package/dist/workspace/import-fetch.d.ts +4 -2
  657. package/dist/workspace/import-fetch.d.ts.map +1 -1
  658. package/dist/workspace/import-fetch.js +4 -2
  659. package/dist/workspace/import-init.d.ts.map +1 -1
  660. package/dist/workspace/import-init.js +4 -2
  661. package/dist/workspace/ledger.schema.json +7 -3
  662. package/dist/workspace/lineage-upgrade-cli.d.ts +1 -1
  663. package/dist/workspace/lineage-upgrade-cli.d.ts.map +1 -1
  664. package/dist/workspace/lineage-upgrade-cli.js +2 -1
  665. package/dist/workspace/pr-report.schema.json +79 -3
  666. package/dist/workspace/promote.d.ts +1 -1
  667. package/dist/workspace/promote.d.ts.map +1 -1
  668. package/dist/workspace/promote.js +2 -1
  669. package/dist/workspace/records-cli.d.ts +2 -2
  670. package/dist/workspace/records-cli.d.ts.map +1 -1
  671. package/dist/workspace/records-cli.js +3 -2
  672. package/dist/workspace/release-catalog.schema.json +277 -0
  673. package/dist/workspace/run-event.schema.json +18 -1
  674. package/dist/workspace/work-cli.d.ts +3 -1
  675. package/dist/workspace/work-cli.d.ts.map +1 -1
  676. package/dist/workspace/work-cli.js +7 -2
  677. package/dist/workspace/workspace-run.d.ts.map +1 -1
  678. package/dist/workspace/workspace-run.js +2 -1
  679. package/package.json +21 -1
  680. package/src/__fixtures__/estate-ledger.ts +101 -0
  681. package/src/__fixtures__/oidc-emulator.ts +31 -2
  682. package/src/__fixtures__/product-words.ts +44 -0
  683. package/src/__golden__/wave-loop/op-by-apply-after-fails.json +10 -2
  684. package/src/__golden__/wave-loop/op-by-apply-hold.json +20 -4
  685. package/src/__golden__/wave-loop/op-by-apply-ignored.json +10 -2
  686. package/src/__golden__/wave-loop/op-by-apply-pass.json +10 -2
  687. package/src/__golden__/wave-loop/op-by-apply-skip.json +10 -2
  688. package/src/__golden__/wave-loop/op-discover-rest-stops.json +22 -6
  689. package/src/__golden__/wave-loop/op-discover-rest.json +44 -12
  690. package/src/__golden__/wave-loop/op-discover-wide.json +12 -3
  691. package/src/__golden__/wave-loop/op-held-on.json +28 -7
  692. package/src/__golden__/wave-loop/op-hooks-apply-fails.json +22 -6
  693. package/src/__golden__/wave-loop/op-hooks-fail-after-apply.json +22 -6
  694. package/src/__golden__/wave-loop/op-hooks-fail-before-apply.json +4 -2
  695. package/src/__golden__/wave-loop/op-hooks-held.json +26 -8
  696. package/src/__golden__/wave-loop/op-hooks-hold-before-apply.json +18 -4
  697. package/src/__golden__/wave-loop/op-hooks-pass.json +22 -6
  698. package/src/__golden__/wave-loop/op-hooks-share.json +20 -7
  699. package/src/__golden__/wave-loop/op-outcome-held.json +12 -3
  700. package/src/__golden__/wave-loop/op-outcome-replan-approved.json +16 -5
  701. package/src/__golden__/wave-loop/op-outcome-replan-forever.json +48 -21
  702. package/src/__golden__/wave-loop/op-outcome-replan.json +16 -5
  703. package/src/__golden__/wave-loop/op-outcome-stood-down.json +12 -3
  704. package/src/__golden__/wave-loop/op-outcome-unreadable.json +12 -3
  705. package/src/__golden__/wave-loop/op-overridden.json +28 -7
  706. package/src/__golden__/wave-loop/op-per-run.json +20 -4
  707. package/src/__golden__/wave-loop/op-point.json +18 -4
  708. package/src/__golden__/wave-loop/op-pr-review.json +10 -2
  709. package/src/__golden__/wave-loop/op-spend-change-only.json +10 -2
  710. package/src/__golden__/wave-loop/op-spend.json +10 -2
  711. package/src/__golden__/wave-loop/op-wave-commands.json +56 -13
  712. package/src/__golden__/wave-loop/op-wide.json +20 -4
  713. package/src/bucket-check/azure.ts +307 -0
  714. package/src/bucket-check/bucket-check.test.ts +210 -0
  715. package/src/bucket-check/fixtures/azure.json +153 -0
  716. package/src/bucket-check/fixtures/gcs.json +148 -0
  717. package/src/bucket-check/fixtures/s3.json +277 -0
  718. package/src/bucket-check/gcs.ts +257 -0
  719. package/src/bucket-check/index.ts +61 -0
  720. package/src/bucket-check/s3.ts +433 -0
  721. package/src/bucket-check/types.ts +75 -0
  722. package/src/bucket-check/wire.ts +50 -0
  723. package/src/bucket-check.ts +5 -0
  724. package/src/capabilities/templates.test.ts +2 -3
  725. package/src/capabilities/templates.ts +1 -2
  726. package/src/cdk/advise.test.ts +1 -1
  727. package/src/change-set-bundle.test.ts +0 -1
  728. package/src/change-set.ts +2 -3
  729. package/src/ci-agent.test.ts +348 -0
  730. package/src/ci-agent.ts +1025 -0
  731. package/src/ci-audit/__fixtures__/cloudtrail-lookup-bucket.json +37 -0
  732. package/src/ci-audit/__fixtures__/cloudtrail-writes-window.json +59 -0
  733. package/src/ci-audit/attribution.ts +260 -0
  734. package/src/ci-audit/audit-log.ts +220 -0
  735. package/src/ci-audit/ci-audit.test.ts +175 -0
  736. package/src/ci-audit/index.ts +15 -0
  737. package/src/ci-audit/unrecorded.ts +140 -0
  738. package/src/ci-audit.ts +2 -0
  739. package/src/ci-control.ts +173 -0
  740. package/src/ci-estate/delivery.ts +433 -0
  741. package/src/ci-estate/overdue.ts +81 -0
  742. package/src/ci-estate/page.ts +343 -0
  743. package/src/ci-estate/rows.ts +251 -0
  744. package/src/ci-estate.test.ts +281 -0
  745. package/src/ci-estate.ts +175 -0
  746. package/src/ci-handover.ts +67 -16
  747. package/src/ci-identity-database.test.ts +54 -0
  748. package/src/ci-identity-pulumi.test.ts +163 -0
  749. package/src/ci-identity-targets.test.ts +3 -1
  750. package/src/ci-identity.ts +123 -22
  751. package/src/ci-job-guard.test.ts +154 -0
  752. package/src/ci-job-guard.ts +319 -0
  753. package/src/ci-jobs.ts +8 -0
  754. package/src/ci-product-comment-targets.test.ts +45 -0
  755. package/src/ci-product-words.test.ts +101 -0
  756. package/src/ci-product-words.ts +565 -0
  757. package/src/ci-product.ts +226 -0
  758. package/src/ci-respond-run.ts +291 -0
  759. package/src/ci-respond.test.ts +264 -0
  760. package/src/ci-respond.ts +412 -0
  761. package/src/ci-shared-reads.test.ts +145 -0
  762. package/src/cli/commands/audit.test.ts +1 -1
  763. package/src/cli/commands/audit.ts +3 -2
  764. package/src/cli/commands/carve.test.ts +1 -1
  765. package/src/cli/commands/carve.ts +2 -2
  766. package/src/cli/commands/init.ts +3 -1
  767. package/src/cli/component-wave-args.test.ts +16 -0
  768. package/src/cli/handlers/agent.ts +126 -0
  769. package/src/cli/handlers/approve-confirm.test.ts +276 -0
  770. package/src/cli/handlers/approve-confirm.ts +200 -0
  771. package/src/cli/handlers/approve.ts +18 -1
  772. package/src/cli/handlers/audit-log.ts +74 -0
  773. package/src/cli/handlers/build-pr-loop-flags.test.ts +98 -0
  774. package/src/cli/handlers/build.test.ts +7 -0
  775. package/src/cli/handlers/build.ts +113 -1
  776. package/src/cli/handlers/ci-check-job.test.ts +114 -0
  777. package/src/cli/handlers/ci-check-job.ts +33 -0
  778. package/src/cli/handlers/ci-check.ts +63 -0
  779. package/src/cli/handlers/ci-forge-check.ts +91 -0
  780. package/src/cli/handlers/e2e-safe-run.ts +27 -0
  781. package/src/cli/handlers/fan-out.test.ts +10 -10
  782. package/src/cli/handlers/fan-out.ts +5 -0
  783. package/src/cli/handlers/gate-pending.ts +46 -0
  784. package/src/cli/handlers/init.ts +1 -0
  785. package/src/cli/handlers/ledger.ts +1 -1
  786. package/src/cli/handlers/lifecycle-drift.ts +7 -2
  787. package/src/cli/handlers/lock.test.ts +29 -2
  788. package/src/cli/handlers/lock.ts +66 -6
  789. package/src/cli/handlers/notify-relay.ts +130 -0
  790. package/src/cli/handlers/pr-before-merge.test.ts +2 -1
  791. package/src/cli/handlers/pr-deploy-inputs.test.ts +7 -7
  792. package/src/cli/handlers/pr-env.ts +48 -11
  793. package/src/cli/handlers/pr-plan-comment-targets.test.ts +166 -0
  794. package/src/cli/handlers/pr-plan-flags.test.ts +161 -0
  795. package/src/cli/handlers/pr-plan-targets.test.ts +155 -0
  796. package/src/cli/handlers/pr-waves-blocked.test.ts +5 -0
  797. package/src/cli/handlers/pr-waves.test.ts +8 -2
  798. package/src/cli/handlers/pr.test.ts +8 -8
  799. package/src/cli/handlers/pr.ts +879 -205
  800. package/src/cli/handlers/promote.test.ts +5 -5
  801. package/src/cli/handlers/promote.ts +22 -2
  802. package/src/cli/handlers/release.ts +2 -0
  803. package/src/cli/handlers/run-components-exit.test.ts +7 -7
  804. package/src/cli/handlers/run-wave.ts +144 -2
  805. package/src/cli/handlers/run.test.ts +6 -4
  806. package/src/cli/handlers/run.ts +86 -1
  807. package/src/cli/handlers/serve.ts +10 -1
  808. package/src/cli/main.test.ts +1 -1
  809. package/src/cli/main.ts +180 -13
  810. package/src/cli/mcp/ledger-tools.ts +126 -0
  811. package/src/cli/mcp/product-tools.test.ts +123 -0
  812. package/src/cli/mcp/product-tools.ts +129 -0
  813. package/src/cli/mcp/read-only.test.ts +134 -0
  814. package/src/cli/mcp/read-only.ts +68 -0
  815. package/src/cli/mcp/report-tools.ts +135 -0
  816. package/src/cli/mcp/server.test.ts +5 -4
  817. package/src/cli/mcp/server.ts +90 -16
  818. package/src/cli/mcp-config.ts +8 -3
  819. package/src/cli/parse-args.ts +119 -2
  820. package/src/cli/registry.ts +73 -0
  821. package/src/cloud-lister/sigv4.ts +80 -23
  822. package/src/components/adoption.test.ts +140 -0
  823. package/src/components/adoption.ts +140 -0
  824. package/src/components/apply-lease.ts +49 -0
  825. package/src/components/capability.ts +180 -6
  826. package/src/components/check-hooks.test.ts +66 -0
  827. package/src/components/check-hooks.ts +255 -0
  828. package/src/components/check-steps.test.ts +70 -0
  829. package/src/components/check-steps.ts +158 -0
  830. package/src/components/ci-services.test.ts +51 -0
  831. package/src/components/ci-services.ts +82 -0
  832. package/src/components/cli-support.ts +23 -2
  833. package/src/components/driver.test.ts +3 -3
  834. package/src/components/driver.ts +73 -6
  835. package/src/components/fan-out-run.ts +68 -18
  836. package/src/components/groups.ts +21 -4
  837. package/src/components/plan-flags.test.ts +46 -0
  838. package/src/components/pr-comment-preview-targets.test.ts +34 -0
  839. package/src/components/pr-comment-preview.test.ts +54 -0
  840. package/src/components/pr-env-ledger.test.ts +9 -0
  841. package/src/components/pr-env-ledger.ts +42 -0
  842. package/src/components/pr-env-ports.ts +29 -4
  843. package/src/components/pr-env-run-bundle.test.ts +2 -14
  844. package/src/components/pr-env-run.test.ts +19 -0
  845. package/src/components/pr-env-run.ts +12 -2
  846. package/src/components/pr-environment.test.ts +29 -0
  847. package/src/components/pr-environment.ts +40 -8
  848. package/src/components/pr-pipeline-runners.test.ts +80 -0
  849. package/src/components/pr-pipeline.test.ts +15 -0
  850. package/src/components/pr-pipeline.ts +498 -18
  851. package/src/components/pr-policy.ts +45 -7
  852. package/src/components/pr-run.test.ts +1 -1
  853. package/src/components/pr-run.ts +138 -11
  854. package/src/components/pr-stale-job.test.ts +34 -0
  855. package/src/components/pr-targets.test.ts +35 -0
  856. package/src/components/pr-targets.ts +45 -0
  857. package/src/components/product-pipeline.test.ts +200 -0
  858. package/src/components/product-pipeline.ts +383 -0
  859. package/src/components/promote.ts +10 -1
  860. package/src/components/release-compile.ts +87 -1
  861. package/src/components/release-promote.ts +65 -1
  862. package/src/components/repo-lock.ts +52 -0
  863. package/src/components/row-lease.test.ts +490 -0
  864. package/src/components/row-lease.ts +167 -0
  865. package/src/components/wave-plan-policy.test.ts +19 -0
  866. package/src/components/wave-plan.ts +96 -6
  867. package/src/control/__fixtures__/consumers/apps/consumers.json +15 -0
  868. package/src/control/__fixtures__/consumers/infra/consumers.json +23 -0
  869. package/src/control/applied.test.ts +148 -0
  870. package/src/control/applied.ts +191 -0
  871. package/src/control/consumers.test.ts +129 -0
  872. package/src/control/consumers.ts +192 -0
  873. package/src/control/control.test.ts +302 -0
  874. package/src/control/dispatch.ts +699 -0
  875. package/src/control/edges.test.ts +112 -0
  876. package/src/control/edges.ts +164 -0
  877. package/src/control/note-checkout.test.ts +91 -0
  878. package/src/control/reconcile.ts +250 -0
  879. package/src/control/records.ts +395 -0
  880. package/src/discovery/sandbox/bundle.ts +25 -1
  881. package/src/e2e-harness/__project__/chant.config.ts +4 -0
  882. package/src/e2e-harness/__project__/src/compose.ts +33 -0
  883. package/src/e2e-harness/bucket.ts +69 -0
  884. package/src/e2e-harness/claim.test.ts +150 -0
  885. package/src/e2e-harness/claim.ts +140 -0
  886. package/src/e2e-harness/driver.test.ts +304 -0
  887. package/src/e2e-harness/driver.ts +294 -0
  888. package/src/e2e-harness/forgejo.ts +267 -0
  889. package/src/e2e-harness/git.ts +96 -0
  890. package/src/e2e-harness/index.ts +50 -0
  891. package/src/e2e-harness/jobs.ts +35 -0
  892. package/src/e2e-harness/pins.ts +52 -0
  893. package/src/e2e-harness/ports.ts +130 -0
  894. package/src/e2e-harness/reports.ts +79 -0
  895. package/src/e2e-harness/safe-run-cli.test.ts +102 -0
  896. package/src/e2e-harness/safe-run-cli.ts +54 -0
  897. package/src/e2e-harness/safe-run.ts +198 -0
  898. package/src/e2e-harness/scenario.ts +89 -0
  899. package/src/e2e-harness/schemas/README.md +62 -0
  900. package/src/e2e-harness/schemas/demo-cycle.schema.json +282 -0
  901. package/src/e2e-harness/schemas/demo-step.schema.json +245 -0
  902. package/src/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
  903. package/src/e2e-harness/schemas/e2e-claims.schema.json +18 -0
  904. package/src/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
  905. package/src/e2e-harness/schemas/index.ts +220 -0
  906. package/src/e2e-harness/schemas.test.ts +145 -0
  907. package/src/e2e-harness/stack.test.ts +124 -0
  908. package/src/e2e-harness/stack.ts +306 -0
  909. package/src/e2e-harness/steps.ts +30 -0
  910. package/src/e2e-harness.ts +2 -0
  911. package/src/engine-facts.test.ts +2 -3
  912. package/src/engine-facts.ts +1 -2
  913. package/src/exit-codes.test.ts +32 -0
  914. package/src/exit-codes.ts +61 -0
  915. package/src/forge-check/check.ts +155 -0
  916. package/src/forge-check/contract.ts +215 -0
  917. package/src/forge-check/forge-check.test.ts +427 -0
  918. package/src/forge-check/forge.ts +318 -0
  919. package/src/forge-check/index.ts +43 -0
  920. package/src/forge-check/pulumi.ts +192 -0
  921. package/src/forge-check/read-only.ts +56 -0
  922. package/src/forge-check/trust.ts +527 -0
  923. package/src/forge-check/types.ts +78 -0
  924. package/src/forge-check.ts +5 -0
  925. package/src/gate-decision-bundle.test.ts +11 -0
  926. package/src/gate-decision.ts +3 -0
  927. package/src/gate-policy.ts +92 -3
  928. package/src/gated-waves-bundle.test.ts +0 -1
  929. package/src/index.ts +2 -0
  930. package/src/lexicon.ts +143 -6
  931. package/src/lifecycle/adoption-file.ts +1 -2
  932. package/src/lifecycle/cloud-index.test.ts +2 -3
  933. package/src/lifecycle/cloud-index.ts +1 -2
  934. package/src/lifecycle/control-entries-ledger.test.ts +69 -0
  935. package/src/lifecycle/gate-applied.ts +6 -0
  936. package/src/lifecycle/gate-ledger.ts +35 -1
  937. package/src/lifecycle/gate-pending-by-plan.test.ts +69 -0
  938. package/src/lifecycle/gate-pending-by-plan.ts +133 -0
  939. package/src/lifecycle/gated-request-digest.ts +49 -0
  940. package/src/lifecycle/gated-request-ledger.test.ts +53 -0
  941. package/src/lifecycle/gated-request.ts +279 -0
  942. package/src/lifecycle/identity-match.ts +25 -6
  943. package/src/lifecycle/index-diff.ts +1 -2
  944. package/src/lifecycle/index-document.ts +1 -2
  945. package/src/lifecycle/index-import.test.ts +14 -0
  946. package/src/lifecycle/index-import.ts +54 -34
  947. package/src/lifecycle/ledger-read.ts +7 -3
  948. package/src/lifecycle/lock-rows.test.ts +109 -0
  949. package/src/lifecycle/lock-rows.ts +167 -0
  950. package/src/lifecycle/publish-target-context.test.ts +108 -0
  951. package/src/lifecycle/query.test.ts +2 -3
  952. package/src/lifecycle/query.ts +109 -8
  953. package/src/lifecycle/release-catalog-site.test.ts +142 -0
  954. package/src/lifecycle/release-catalog-site.ts +291 -0
  955. package/src/lifecycle/release-catalog.test.ts +192 -0
  956. package/src/lifecycle/release-catalog.ts +353 -0
  957. package/src/lifecycle/release-changelog.test.ts +70 -0
  958. package/src/lifecycle/release-changelog.ts +71 -0
  959. package/src/lifecycle/release-cut.ts +2 -2
  960. package/src/lifecycle/release-ledger.ts +19 -0
  961. package/src/lifecycle/release-publish.ts +45 -22
  962. package/src/lifecycle/release-read.ts +2 -0
  963. package/src/lifecycle/release-status.test.ts +185 -0
  964. package/src/lifecycle/release-status.ts +175 -0
  965. package/src/lifecycle/resource-lock.test.ts +175 -0
  966. package/src/lifecycle/resource-lock.ts +354 -0
  967. package/src/lifecycle/retention.ts +2 -0
  968. package/src/lifecycle/run-ledger.ts +7 -1
  969. package/src/lifecycle/snapshot-store-s3.ts +9 -45
  970. package/src/lifecycle/snapshot-store.ts +1 -2
  971. package/src/lifecycle/target-lock.ts +24 -9
  972. package/src/lifecycle/wave-plans.ts +33 -5
  973. package/src/mcp/types.ts +7 -0
  974. package/src/notify-product.ts +76 -0
  975. package/src/notify-relay.test.ts +213 -0
  976. package/src/notify-relay.ts +407 -0
  977. package/src/notify.ts +95 -14
  978. package/src/object-store/azure-blob.ts +374 -0
  979. package/src/object-store/common.ts +133 -0
  980. package/src/object-store/errors.ts +26 -0
  981. package/src/object-store/from-env.ts +36 -0
  982. package/src/object-store/gcs.ts +436 -0
  983. package/src/object-store/index.ts +8 -0
  984. package/src/object-store/object-store.test.ts +130 -0
  985. package/src/object-store/s3.ts +350 -0
  986. package/src/op/activities/converge.ts +2 -1
  987. package/src/op/activities/index.ts +1 -1
  988. package/src/op/activities/review-agent.open.test.ts +78 -0
  989. package/src/op/activities/review-agent.test.ts +13 -0
  990. package/src/op/activities/review-agent.ts +89 -5
  991. package/src/op/approval-status.test.ts +134 -0
  992. package/src/op/approval-status.ts +235 -0
  993. package/src/op/gate-review.test.ts +2 -1
  994. package/src/op/gate.ts +81 -22
  995. package/src/op/generate-pipeline.ts +7 -1
  996. package/src/op/index.ts +23 -0
  997. package/src/op/op-waves-after-plan.test.ts +288 -0
  998. package/src/op/op-waves-after-plan.ts +238 -0
  999. package/src/op/op-waves-capability-spec.ts +133 -0
  1000. package/src/op/op-waves-capability.test.ts +217 -0
  1001. package/src/op/op-waves-capability.ts +370 -0
  1002. package/src/op/op-waves-events.ts +135 -0
  1003. package/src/op/op-waves-notify-words.test.ts +149 -0
  1004. package/src/op/op-waves-notify.ts +41 -16
  1005. package/src/op/op-waves-parallelism.test.ts +89 -0
  1006. package/src/op/op-waves-pull-request.test.ts +219 -0
  1007. package/src/op/op-waves-release-port.ts +64 -0
  1008. package/src/op/op-waves-release.test.ts +209 -0
  1009. package/src/op/op-waves-release.ts +132 -0
  1010. package/src/op/op-waves-run-record.test.ts +32 -0
  1011. package/src/op/op-waves-run.ts +1235 -52
  1012. package/src/op/op-waves-stand-down.test.ts +240 -0
  1013. package/src/op/op-waves-stand-down.ts +107 -0
  1014. package/src/op/op-waves-trace.test.ts +205 -0
  1015. package/src/op/op-waves.test.ts +112 -0
  1016. package/src/op/op-waves.ts +320 -22
  1017. package/src/op/runtime.ts +107 -0
  1018. package/src/op/stage-hooks-hold-record.test.ts +41 -0
  1019. package/src/op/stage-hooks.ts +91 -12
  1020. package/src/op/steward-beside.ts +2 -1
  1021. package/src/op/types.ts +3 -2
  1022. package/src/otlp-metrics.ts +96 -0
  1023. package/src/otlp.test.ts +243 -0
  1024. package/src/otlp.ts +543 -0
  1025. package/src/override-gate-bundle.test.ts +2 -0
  1026. package/src/override-gate.ts +4 -0
  1027. package/src/parallelism.test.ts +38 -0
  1028. package/src/parallelism.ts +33 -0
  1029. package/src/policy-packs.ts +230 -0
  1030. package/src/policy-source.test.ts +256 -0
  1031. package/src/policy-source.ts +111 -0
  1032. package/src/pr-forge-bundle.test.ts +1 -1
  1033. package/src/pr-forge.ts +175 -33
  1034. package/src/pr-loop-bundle.test.ts +7 -3
  1035. package/src/pr-loop-narrowed.test.ts +63 -0
  1036. package/src/pr-loop-words.test.ts +155 -0
  1037. package/src/pr-loop.ts +398 -52
  1038. package/src/pr-merge.test.ts +100 -0
  1039. package/src/pr-merge.ts +105 -0
  1040. package/src/pr-post-stale.test.ts +163 -0
  1041. package/src/pr-post.ts +190 -5
  1042. package/src/pr-report-url.ts +61 -6
  1043. package/src/pr-requires.test.ts +37 -1
  1044. package/src/pr-requires.ts +16 -2
  1045. package/src/product-subpaths-plain-node.e2e.test.ts +212 -0
  1046. package/src/release-floors.ts +1 -1
  1047. package/src/run-event.ts +28 -1
  1048. package/src/scheduled-op-cloud.ts +68 -0
  1049. package/src/sorted-json.ts +17 -0
  1050. package/src/stage-hooks-bundle.test.ts +6 -0
  1051. package/src/terraform/credentials.test.ts +77 -0
  1052. package/src/terraform/credentials.ts +162 -0
  1053. package/src/utils.ts +2 -11
  1054. package/src/wave-loop-golden.test.ts +2 -1
  1055. package/src/wave-runtime.ts +2 -2
  1056. package/src/workspace/chant-migrations/chud-lexicon-exit.ts +4 -1
  1057. package/src/workspace/ci-lock-grain.test.ts +31 -0
  1058. package/src/workspace/ci-lock-grain.ts +29 -0
  1059. package/src/workspace/ci-report-url.test.ts +1 -1
  1060. package/src/workspace/ci-run.test.ts +1 -1
  1061. package/src/workspace/ci-run.ts +10 -3
  1062. package/src/workspace/declaration.schema.json +27 -3
  1063. package/src/workspace/declaration.test.ts +1 -1
  1064. package/src/workspace/declaration.ts +26 -10
  1065. package/src/workspace/drift-cli.ts +8 -3
  1066. package/src/workspace/exit-cli.ts +2 -1
  1067. package/src/workspace/import-fetch.ts +4 -2
  1068. package/src/workspace/import-init.ts +4 -2
  1069. package/src/workspace/ledger.schema.json +7 -3
  1070. package/src/workspace/lineage-upgrade-cli.ts +2 -1
  1071. package/src/workspace/pr-report.schema.json +79 -3
  1072. package/src/workspace/promote.ts +2 -1
  1073. package/src/workspace/records-cli.ts +3 -2
  1074. package/src/workspace/release-catalog.schema.json +277 -0
  1075. package/src/workspace/run-event.schema.json +18 -1
  1076. package/src/workspace/work-cli.ts +8 -2
  1077. package/src/workspace/workspace-run.ts +2 -1
@@ -49,8 +49,10 @@
49
49
  * (`pointGateResumable`, #3835).
50
50
  */
51
51
  import { execFileSync } from "node:child_process";
52
+ import { createHash } from "node:crypto";
52
53
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
53
54
  import { dirname, isAbsolute, join, posix } from "node:path";
55
+ import { CHANT_EXIT } from "../exit-codes.js";
54
56
  import { decideWaveGate, runWaveLoop, waveDigestMembers, waveSetDigest, writeWaveRecordFile, } from "../wave-engine.js";
55
57
  import { blockedMembers, blockedWords, earlierWaveOutcomes, passesThrough, readWaveOutcomeFile, waveOutcomeFileName, writeWaveOutcomeFile, } from "../wave-blocked.js";
56
58
  import { approveCommand, evaluateGate, gitGateLedgerPort } from "./gate.js";
@@ -58,9 +60,22 @@ import { isApprovalSpent } from "../lifecycle/gate-applied.js";
58
60
  import { samePlanDigest } from "../lifecycle/plan-digest.js";
59
61
  import { isLifecycleLocalNote } from "../lifecycle/local-note.js";
60
62
  import { ciRunIdFromEnv } from "./gate-run-locator.js";
63
+ import { appendRunRecord, DEFAULT_RUN_ENV } from "../lifecycle/run-ledger.js";
64
+ import { pushLifecycleReport } from "../lifecycle/git.js";
65
+ import { resolveCiJob } from "../lifecycle/release-ledger.js";
66
+ import { foldPolicyRows, opWaveAfterPlanProblems, runOpWaveAfterPlanHooks } from "./op-waves-after-plan.js";
67
+ import { activeOtlp, RunEventTrace } from "../otlp.js";
68
+ import { joinRunEventSinks, resolveRunEventRun } from "../run-event-stream.js";
69
+ import { OpWaveRunEvents } from "./op-waves-events.js";
70
+ import { opWaveReleaseNames } from "./op-waves-release.js";
71
+ import { gitOpWaveReleasePort } from "./op-waves-release-port.js";
72
+ import { gitOpWaveNewerCommit, opWaveStandDownReason, tipAppliesTargets } from "./op-waves-stand-down.js";
73
+ import { mapLimited } from "../parallelism.js";
74
+ import { applyOpWaveStep, opWaveCosts, opWaveCostVerdict, opWaveHoldsAt, opWaveHoldsProblems, opWavePolicyVerdicts, opWaveRegistry, opWaveStepChangeSet, planJsonOf, planOpWaveStep, } from "./op-waves-capability.js";
75
+ import { NEXT_RELEASE } from "../release-floors.js";
61
76
  import { changeInvolvement, quorumProblems, quorumRuleLine, quorumRulesFor, quorumWaiting, recordedReviewApprovals, ruleNeedsProof, samePrincipal, trustQuorumJudge, } from "./gate-quorum.js";
62
77
  import { OP_WAVE_DEFAULT_APPLY, OP_WAVE_GATE_POLICIES, OP_WAVE_HOOK_MOMENTS, GATE_APPROVAL_SOURCES, assertOpWaveHooks, assertOpWavesSpec, opWaveApplyHooksRunBy, opWaveGateName, opWaveHooksAt, opWaveOutcomeDir, opWavePointAt, opWavePointProblems, opWaveRecordPath, opWaveGroupRuns, opWaveGroupsProblem, opWaveShare, OP_LEDGER_NAME, opWavesInvolvedProblems, } from "./op-waves.js";
63
- import { OP_WAVE_PENDING_RESERVED, opWaveArgv, pendingFields, readHoldRequest, runHookList, runStageHooks, runStageHooksAsync, spawnExec, spawnExecAsync, } from "./stage-hooks.js";
78
+ import { OP_WAVE_PENDING_RESERVED, opWaveArgv, pendingFields, holdFinishedPath, readHoldFinished, readHoldRequest, runHookList, runHookListAsync, runStageHooks, runStageHooksAsync, spawnExec, spawnExecAsync, } from "./stage-hooks.js";
64
79
  export { OP_WAVE_PENDING_RESERVED, opWaveArgv, runStageHooks, runStageHooksAsync, spawnExecAsync };
65
80
  export const OP_WAVE_APPLY_OUTCOMES = ["stood-down", "held", "replan"];
66
81
  const gitShowAtBase = (base, path, cwd) => {
@@ -120,7 +135,7 @@ export function readOpWavePolicy(specFile, name, base, cwd, show = gitShowAtBase
120
135
  const spend = spec.approvals?.spend === true;
121
136
  const neverOverMcp = spec.neverOverMcp === true;
122
137
  // #3836: the gate's decision point, the spec's for a wave the base does not have yet.
123
- const asks = { ...pointAtBase(spec, name, `${specFile} at ${sha.slice(0, 12)}`), ...quorumAtBase(spec, `${specFile} at ${sha.slice(0, 12)}`) };
138
+ const asks = { ...pointAtBase(spec, name, `${specFile} at ${sha.slice(0, 12)}`), ...quorumAtBase(spec, `${specFile} at ${sha.slice(0, 12)}`), ...holdsAtBase(spec, `${specFile} at ${sha.slice(0, 12)}`), ...pullRequestGateAtBase(spec) };
124
139
  const wave = spec.waves.find((w) => w.name === name);
125
140
  if (!wave)
126
141
  return { ...absent, spend, neverOverMcp, ...asks };
@@ -140,6 +155,11 @@ export function readOpWavePolicy(specFile, name, base, cwd, show = gitShowAtBase
140
155
  }
141
156
  return rules;
142
157
  }
158
+ /** `approvals.pullRequest.gate` at base (#4550), when it names a gate. */
159
+ function pullRequestGateAtBase(spec) {
160
+ const gate = spec.approvals?.pullRequest?.gate;
161
+ return typeof gate === "string" && OP_LEDGER_NAME.test(gate) ? { pullRequestGate: gate } : {};
162
+ }
143
163
  /** The approval rules at base (#4290), or why they cannot be read. A spec at base with none has none. */
144
164
  function quorumAtBase(spec, where) {
145
165
  const a = spec.approvals;
@@ -164,6 +184,16 @@ function quorumAtBase(spec, where) {
164
184
  return { quorumRefused: `the approval rules in ${where} cannot be read (${problems.join("; ")})` };
165
185
  return raw.length > 0 ? { quorum: raw, ...extra } : {};
166
186
  }
187
+ /** The holds at base (#4545), or why they cannot be read. */
188
+ function holdsAtBase(spec, where) {
189
+ const raw = spec.holds;
190
+ if (raw === undefined)
191
+ return {};
192
+ const problems = opWaveHoldsProblems(raw);
193
+ if (problems.length > 0)
194
+ return { holdsRefused: `the holds in ${where} cannot be read (${problems.join("; ")})` };
195
+ return { holds: structuredClone(raw) };
196
+ }
167
197
  /** The point wave `name` asks at base (#3836), or why it cannot be asked. */
168
198
  function pointAtBase(spec, name, where) {
169
199
  const raw = spec.waves.find((w) => w.name === name)?.point ?? spec.point;
@@ -174,7 +204,9 @@ function pointAtBase(spec, name, where) {
174
204
  return { pointRefused: `the decision point at base cannot be asked (${where}: ${problems.join("; ")})` };
175
205
  return { point: opWavePointAt(spec, name) };
176
206
  }
177
- /** Where a run's plan file goes. */
207
+ /** The first chant whose op entry exports {@link opWavePlanPath} (terragucci#1304). */
208
+ export const OP_WAVE_PLAN_PATH_FLOOR = NEXT_RELEASE;
209
+ /** Where a run's plan file goes: one target's plan, as opposed to {@link opWavePlansPath}, the wave's `plans.json`. */
178
210
  export function opWavePlanPath(spec, wave, target) {
179
211
  return `.chant/op-waves/${spec.name}/wave-${wave}/${target.replace(/[^A-Za-z0-9._-]/g, "_")}.plan.json`;
180
212
  }
@@ -186,6 +218,16 @@ export function opWaveRunsPath(spec, wave) {
186
218
  export function opWavePlansPath(spec, wave) {
187
219
  return `.chant/op-waves/${spec.name}/wave-${wave}/plans.json`;
188
220
  }
221
+ /** The run ledger on `chant/lifecycle` (#4551): `appendRunRecord`, then a push. Honours `--no-record` through the git layer. */
222
+ export function gitOpWaveRunPort(opts) {
223
+ return {
224
+ async append(record) {
225
+ await appendRunRecord(record, opts);
226
+ const { pushWarning } = await pushLifecycleReport(opts);
227
+ return pushWarning ? { pushWarning } : {};
228
+ },
229
+ };
230
+ }
189
231
  function planRun(opts, waveName, run) {
190
232
  const op = run.op ?? opts.spec.op;
191
233
  const plan = opWavePlanPath(opts.spec, opts.wave, run.target);
@@ -250,14 +292,22 @@ function writeRunsFile(at, runs, members, digest, path = opWaveRunsPath(at.spec,
250
292
  * for all of them (#3762). A wave plan is written out as each run's plan file
251
293
  * too, so a per-run `apply` or hook reads `{plan}` either way.
252
294
  */
253
- function planRuns(at, runs, discover = false) {
295
+ async function planRuns(at, runs, discover = false) {
254
296
  const { spec, k, wave, cwd, exec } = at;
255
- if (!spec.planWave)
256
- return { members: runs.map((run) => planRun({ spec, wave: k, cwd, exec }, wave.name, run)) };
297
+ if (!spec.planWave) {
298
+ const members = runs.map((run) => planRun({ spec, wave: k, cwd, exec }, wave.name, run));
299
+ // #4545: a plan file's `changeSet` part, which a policy hold reads.
300
+ const parts = new Map(runs.flatMap((run) => {
301
+ const part = partOf(readPlanFileField(join(cwd, opWavePlanPath(spec, k, run.target)), "changeSet"));
302
+ return part ? [[run.target, part]] : [];
303
+ }));
304
+ return { members, ...(parts.size > 0 ? { parts } : {}) };
305
+ }
257
306
  const runsPath = writeRunsFile(at, runs, undefined, undefined, undefined, discover);
258
307
  const plans = opWavePlansPath(spec, k);
259
308
  rmSync(join(cwd, plans), { force: true });
260
- const code = exec(opWaveArgv(spec.planWave, { op: spec.op, wave: wave.name, runs: runsPath, plans }), cwd);
309
+ const planArgv = opWaveArgv(spec.planWave, { op: spec.op, wave: wave.name, runs: runsPath, plans });
310
+ const code = at.waveExec ? await at.waveExec(planArgv, cwd) : exec(planArgv, cwd);
261
311
  if (code !== 0)
262
312
  throw new Error(`planning wave ${k} (${wave.name}) exited ${code}`);
263
313
  let parsed;
@@ -301,6 +351,14 @@ function planRuns(at, runs, discover = false) {
301
351
  if (count !== undefined && (!Number.isInteger(count) || count < 0))
302
352
  throw new Error(`the plans file of wave ${k} (${plans}): \`waves\` must be the number of waves found, a whole number`);
303
353
  const pending = Array.isArray(parsed) ? undefined : pendingFields(parsed.pending, `the plans file of wave ${k} (${plans})`);
354
+ const changeSetDoc = Array.isArray(parsed) ? undefined : parsed.changeSet;
355
+ if (changeSetDoc !== undefined && (changeSetDoc === null || typeof changeSetDoc !== "object" || Array.isArray(changeSetDoc))) {
356
+ throw new Error(`the plans file of wave ${k} (${plans}): \`changeSet\` must be a change-set document`);
357
+ }
358
+ const parts = new Map(runs.flatMap((run) => {
359
+ const part = partOf(byTarget.get(run.target)?.changeSet);
360
+ return part ? [[run.target, part]] : [];
361
+ }));
304
362
  const members = runs.map((run) => {
305
363
  const m = member(run.target, run.op ?? spec.op, byTarget.get(run.target));
306
364
  const path = join(cwd, opWavePlanPath(spec, k, run.target));
@@ -317,13 +375,241 @@ function planRuns(at, runs, discover = false) {
317
375
  }
318
376
  return {
319
377
  members,
378
+ ...(parts.size > 0 ? { parts } : {}),
320
379
  ...(pending ? { pending } : {}),
321
380
  ...(overriders ? { overriders: overriders } : {}),
322
381
  ...(overriders && overridersSource ? { overridersSource: overridersSource } : {}),
323
382
  ...(extras ? { extras } : {}),
324
383
  ...(count !== undefined ? { waves: count } : {}),
384
+ ...(changeSetDoc !== undefined ? { changeSet: changeSetDoc } : {}),
325
385
  };
326
386
  }
387
+ /**
388
+ * Plan `runs` of wave `k` (#4545): through the spec's `step` when it names
389
+ * one, each run's plan kept on `at.steps` for its apply, else with the
390
+ * commands ({@link planRuns}).
391
+ */
392
+ async function planWaveRuns(at, runs, discover = false) {
393
+ const { spec, k, wave, cwd } = at;
394
+ if (!spec.step)
395
+ return planRuns({ ...at, ...(at.options.waveExec ? { waveExec: at.options.waveExec } : {}) }, runs, discover);
396
+ const registry = await opWaveRegistry(at.options, cwd, at.options.capabilities);
397
+ const base = at.gateRule?.base ?? at.options.base;
398
+ const lockGrain = at.options.lockGrain ?? (await declaredLockGrain(cwd, base));
399
+ // #4613: a step's own policy engine (CrossGuard) reads its packs at the base the wave's rules were read at.
400
+ const policyBase = base && base !== "HEAD" ? base : undefined;
401
+ const plans = [];
402
+ for (const run of runs) {
403
+ const plan = await planOpWaveStep({ spec, wave, cwd, registry, planPath: opWavePlanPath(spec, k, run.target), lockGrain, ...(policyBase ? { policyBase } : {}) }, run);
404
+ at.steps?.set(run.target, plan);
405
+ plans.push(plan);
406
+ }
407
+ const members = plans.map((p) => ({
408
+ member: p.target,
409
+ planDigest: p.planDigest,
410
+ op: runs.find((r) => r.target === p.target)?.op ?? spec.op,
411
+ ...(p.destructive ? { destructive: true } : {}),
412
+ ...(p.empty ? { empty: true } : {}),
413
+ }));
414
+ const parts = new Map(plans.flatMap((p) => (p.part ? [[p.target, p.part]] : [])));
415
+ const changeSet = opWaveStepChangeSet(plans);
416
+ return { members, ...(parts.size > 0 ? { parts } : {}), ...(changeSet ? { changeSet } : {}) };
417
+ }
418
+ /**
419
+ * `ci.lockGrain` of the member holding `cwd` (#4552), read at `base`, behind
420
+ * a dynamic import so the wave-job runtime bundle leaves the declaration
421
+ * reader out. Null when none is declared or the declaration cannot be read
422
+ * there: each run then takes its lexicon's default.
423
+ */
424
+ async function declaredLockGrain(cwd, base) {
425
+ try {
426
+ const { ciLockGrainAt } = await import("../workspace/ci-lock-grain.js");
427
+ return ciLockGrainAt(cwd, base);
428
+ }
429
+ catch {
430
+ return null;
431
+ }
432
+ }
433
+ /**
434
+ * Lease the rows of a wave's runs on the resource grain (#4552), before
435
+ * anything of the wave applies, all in one take. A held row makes the wave
436
+ * apply nothing with the `held` outcome, exit 5, naming the run that holds it.
437
+ */
438
+ async function leaseWaveRows(options, ctx, runs) {
439
+ const rows = runs.flatMap((r) => {
440
+ const lock = ctx.steps?.get(r.target)?.lock;
441
+ return lock?.grain === "resource" ? lock.rows : [];
442
+ });
443
+ if (rows.length === 0)
444
+ return undefined;
445
+ const { leaseLockRows } = await import("../lifecycle/resource-lock.js");
446
+ const { PR_APPLY_GATE } = await import("../pr-loop.js");
447
+ const gate = options.lockGate ?? PR_APPLY_GATE;
448
+ let leased;
449
+ try {
450
+ leased = await leaseLockRows(gate, rows, { cwd: ctx.cwd, ...(options.lockLiveness ? { alive: options.lockLiveness } : {}) });
451
+ }
452
+ catch (err) {
453
+ return { failed: `wave ${ctx.k} (${ctx.wave.name}): could not hold the rows its runs change in ${gate}, so nothing was applied: ${err instanceof Error ? err.message : String(err)}` };
454
+ }
455
+ if (!leased.ok) {
456
+ const first = leased.held[0].holder;
457
+ return { outcome: "held", reason: leased.message, holder: { run: first.run, ...(first.url ? { url: first.url } : {}) } };
458
+ }
459
+ for (const h of leased.tookOver)
460
+ ctx.log(`wave ${ctx.k} (${ctx.wave.name}): took over the rows of run ${h.run}, which is gone`);
461
+ ctx.log(`wave ${ctx.k} (${ctx.wave.name}): holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${gate} while it applies`);
462
+ return leased.lease;
463
+ }
464
+ /** A wave's cost hold over its plans (#4545): each changing run priced, the sum against `approveAbove`. */
465
+ function costVerdictOf(hold, spec, k, members, steps, cwd, exec) {
466
+ const runs = members.map((m) => ({ target: m.member, plan: opWavePlanPath(spec, k, m.member), artifact: steps?.get(m.member)?.artifact, empty: m.empty === true }));
467
+ return opWaveCostVerdict(hold, opWaveCosts(hold, runs, cwd, exec));
468
+ }
469
+ /**
470
+ * Run a wave's holds over its plans (#4545): the policy marks each run it
471
+ * denies or holds (the gate then settles them as a product's plan file
472
+ * would), and the cost adds its digest member and, over its amount, a hold.
473
+ * `failed` when the policy cannot run, or a run gave it no change set.
474
+ */
475
+ async function runWaveHolds(ctx, holds, members, parts, base) {
476
+ const { spec, k, wave, cwd, log, options } = ctx;
477
+ // #4614: each run's ci.policy row, which the after-plan hooks and the run record read.
478
+ const out = { holds: [], extras: [], rows: new Map() };
479
+ if (!holds)
480
+ return out;
481
+ if (holds.policy) {
482
+ const missing = members.filter((m) => !parts?.has(m.member)).map((m) => m.member);
483
+ if (missing.length > 0)
484
+ return { failed: `wave ${k} (${wave.name}): holds.policy reads each run's change set, and the plans of ${missing.join(", ")} gave none, so nothing in it was applied` };
485
+ let head = options.head;
486
+ if (!head) {
487
+ try {
488
+ head = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
489
+ }
490
+ catch {
491
+ head = "";
492
+ }
493
+ }
494
+ let got;
495
+ try {
496
+ got = await opWavePolicyVerdicts({ spec, gate: opWaveGateName(spec, k), env: spec.labels?.Env ?? wave.name, base, head, cwd, ...(options.holdExec ? { exec: options.holdExec } : {}) }, parts);
497
+ }
498
+ catch (err) {
499
+ return { failed: `wave ${k} (${wave.name}): ${err instanceof Error ? err.message : String(err)}, so nothing in it was applied` };
500
+ }
501
+ if ("note" in got)
502
+ log(`wave ${k} (${wave.name}): ${got.note}`);
503
+ else {
504
+ if (got.source) {
505
+ out.policySource = got.source;
506
+ log(`wave ${k} (${wave.name}): ci.policy read from ${got.source.repo}@${got.source.ref} at commit ${got.source.commit}`);
507
+ }
508
+ for (const m of members) {
509
+ const v = got.verdicts.get(m.member);
510
+ if (v && v.result !== "error") {
511
+ const rules = v.result === "held" ? v.holds : v.result === "denied" ? v.rules : [];
512
+ out.rows.set(m.member, { source: "ci.policy", result: v.result, rules, ...(v.reason ? { reason: v.reason } : {}) });
513
+ }
514
+ if (!v || v.result === "passed")
515
+ continue;
516
+ if (v.result === "error")
517
+ return { failed: `wave ${k} (${wave.name}): the policy did not run on ${m.member} (${v.reason ?? "no answer"}), so nothing in it was applied` };
518
+ if (v.result === "denied")
519
+ m.denied = { rules: v.rules, ...(v.reason ? { reason: v.reason } : {}) };
520
+ else
521
+ m.held = { rules: v.holds, ...(v.reason ? { reason: v.reason } : {}) };
522
+ }
523
+ }
524
+ }
525
+ if (holds.cost) {
526
+ const verdict = costVerdictOf(holds.cost, spec, k, members, ctx.steps, cwd, options.holdExec);
527
+ out.extras.push(verdict.member);
528
+ log(`wave ${k} (${wave.name}): cost ${verdict.monthlyDelta >= 0 ? "+" : ""}${verdict.monthlyDelta.toFixed(2)} ${verdict.currency} a month${verdict.unestimated.length ? `, ${verdict.unestimated.length} run${verdict.unestimated.length === 1 ? "" : "s"} not priced` : ""}`);
529
+ if (verdict.hold)
530
+ out.holds.push(verdict.hold);
531
+ }
532
+ return out;
533
+ }
534
+ /** The job's after-plan hooks (#4614), as a list. */
535
+ function afterPlanHooks(options) {
536
+ const given = options.afterPlan;
537
+ if (given === undefined)
538
+ return [];
539
+ return Array.isArray(given) ? given : [given];
540
+ }
541
+ /**
542
+ * Run the after-plan hooks in the job's process over a wave's plans (#4614),
543
+ * fold their policy rows into each run's denial and hold, and put each run's
544
+ * rows and files on the result for the run record. With no hook, the rows
545
+ * chant's `holds.policy` gave still go on the result.
546
+ */
547
+ async function runAfterPlan(ctx, members, parts, policyRows) {
548
+ const { spec, k, wave, cwd, options, result } = ctx;
549
+ const hooks = afterPlanHooks(options);
550
+ const job = options.decide ? "decide" : options.group !== undefined ? "group" : options.share !== undefined ? "share" : "wave";
551
+ const runs = members.map((m) => {
552
+ const plan = opWavePlanPath(spec, k, m.member);
553
+ const step = ctx.steps?.get(m.member);
554
+ const planJson = runPlanJson(ctx, m.member, plan);
555
+ const part = parts?.get(m.member) ?? step?.part;
556
+ const row = policyRows.get(m.member);
557
+ return {
558
+ spec: spec.name,
559
+ op: spec.op,
560
+ wave: k,
561
+ waveName: wave.name,
562
+ job,
563
+ target: m.member,
564
+ runOp: m.op,
565
+ planDigest: m.planDigest,
566
+ plan,
567
+ ...(planJson ? { planJson } : {}),
568
+ ...(step?.artifact !== undefined ? { artifact: step.artifact } : {}),
569
+ ...(part ? { changeSet: part } : {}),
570
+ empty: m.empty === true,
571
+ destructive: m.destructive === true,
572
+ policy: row ? [row] : [],
573
+ cwd,
574
+ };
575
+ });
576
+ const out = hooks.length > 0 && runs.length > 0 ? await runOpWaveAfterPlanHooks(hooks, runs, ctx.log) : undefined;
577
+ if (out)
578
+ result.hooks.push(...out.outcomes);
579
+ const plans = { ...(result.plans ?? {}) };
580
+ for (const m of members) {
581
+ const mine = out?.runs.get(m.member);
582
+ const chant = policyRows.get(m.member);
583
+ const rows = [...(chant ? [chant] : []), ...(mine?.policy ?? [])];
584
+ if (mine?.policy.length) {
585
+ const folded = foldPolicyRows(mine.policy, { ...(m.denied ? { denied: m.denied } : {}), ...(m.held ? { held: m.held } : {}) });
586
+ if (folded.denied)
587
+ m.denied = folded.denied;
588
+ if (folded.held)
589
+ m.held = folded.held;
590
+ }
591
+ if (rows.length === 0 && !mine?.files.length)
592
+ continue;
593
+ plans[m.member] = { planDigest: m.planDigest, ...(rows.length ? { policy: rows } : {}), ...(mine?.files.length ? { files: [...mine.files] } : {}) };
594
+ }
595
+ if (Object.keys(plans).length > 0)
596
+ result.plans = plans;
597
+ return { ...(out?.failed ? { failed: out.failed } : {}), holds: out?.holds ?? [] };
598
+ }
599
+ /** One field of a plan file, or undefined when the file or the field is missing. */
600
+ function readPlanFileField(path, field) {
601
+ try {
602
+ return JSON.parse(readFileSync(path, "utf-8"))[field];
603
+ }
604
+ catch {
605
+ return undefined;
606
+ }
607
+ }
608
+ /** A plan file's change-set part (#4545), when it gives one of the right shape. */
609
+ function partOf(value) {
610
+ const p = value;
611
+ return p && typeof p === "object" && p.member && typeof p.member.member === "string" && Array.isArray(p.entries) ? p : undefined;
612
+ }
327
613
  /** A plans file's `members` (#3821): digest members that are no run, each named once and by no run's target. */
328
614
  function extraMembers(value, targets, where) {
329
615
  if (value === undefined)
@@ -354,7 +640,21 @@ export function opWaveSetDigest(spec, members, extras = []) {
354
640
  return waveSetDigest(waveDigestMembers(members, { ...(spec.digest?.over ? { over: spec.digest.over } : {}), extras }));
355
641
  }
356
642
  const placeOf = (ctx) => ({ name: ctx.spec.name, op: ctx.spec.op, waveName: ctx.wave.name, k: ctx.k, cwd: ctx.cwd, exec: ctx.exec, log: ctx.log });
357
- const hookRuns = (spec, k, runs, members) => runs.map((run) => ({ target: run.target, op: run.op ?? spec.op, ...(members?.has(run.target) ? { plan: opWavePlanPath(spec, k, run.target) } : {}) }));
643
+ const hookRuns = (ctx, runs, members) => runs.map((run) => {
644
+ const { spec, k } = ctx;
645
+ const m = members?.get(run.target);
646
+ if (!m)
647
+ return { target: run.target, op: run.op ?? spec.op };
648
+ const plan = opWavePlanPath(spec, k, run.target);
649
+ // #4614: the engine's plan document, from the step's artifact or the plan file's.
650
+ const planJson = runPlanJson(ctx, run.target, plan);
651
+ return { target: run.target, op: run.op ?? spec.op, plan, planDigest: m.planDigest, ...(planJson ? { planJson } : {}) };
652
+ });
653
+ /** The engine's plan document a run's plan names (#4614): the step's artifact, else the plan file's `artifact`. */
654
+ function runPlanJson(ctx, target, plan) {
655
+ const artifact = ctx.steps?.get(target)?.artifact ?? readPlanFileField(join(ctx.cwd, plan), "artifact");
656
+ return planJsonOf(artifact, ctx.cwd);
657
+ }
358
658
  /**
359
659
  * Run one moment's hooks in the wave job (#3762), recording each outcome on
360
660
  * the result. A hook that held the wave on another gate (#3821) has that
@@ -367,7 +667,10 @@ async function runHooks(ctx, moment, hooks, runs, members, digest, extraEnv = {}
367
667
  if (!hooks || hooks.length === 0)
368
668
  return { holds: [] };
369
669
  const runsPath = writeRunsFile(ctx, runs, members, digest);
370
- const out = runHookList(placeOf(ctx), moment, hooks, hookRuns(ctx.spec, ctx.k, runs, members), runsPath, extraEnv);
670
+ const hookExec = ctx.options.hookExec;
671
+ const out = hookExec
672
+ ? await runHookListAsync({ ...placeOf(ctx), exec: hookExec }, moment, hooks, hookRuns(ctx, runs, members), runsPath, extraEnv)
673
+ : runHookList(placeOf(ctx), moment, hooks, hookRuns(ctx, runs, members), runsPath, extraEnv);
371
674
  ctx.result.hooks.push(...out.outcomes);
372
675
  const back = { holds: out.holds, ...(out.failed ? { failed: out.failed } : {}) };
373
676
  if (out.failed)
@@ -386,6 +689,7 @@ async function runHooks(ctx, moment, hooks, runs, members, digest, extraEnv = {}
386
689
  }
387
690
  const now = { op: held.op, gate: held.gate, digest: held.digest, approvedBy: held.approvedBy, approvedAt: held.approvedAt };
388
691
  approved.push(now);
692
+ const target = hold.target ? { target: hold.target } : {};
389
693
  const approvedEnv = {
390
694
  ...hold.env,
391
695
  CHANT_HOLD_APPROVED: JSON.stringify(now),
@@ -394,15 +698,33 @@ async function runHooks(ctx, moment, hooks, runs, members, digest, extraEnv = {}
394
698
  };
395
699
  const holdPath = join(ctx.cwd, hold.env.CHANT_HOLD);
396
700
  rmSync(holdPath, { force: true });
701
+ // #4623: a hold that asks chant to record its gate is spent here, before the re-run acts under the approval.
702
+ let spent;
703
+ let finishedAt;
704
+ if (hold.request.record) {
705
+ const got = await spendHeldGate(ctx, hold, now);
706
+ if ("failed" in got) {
707
+ ctx.result.hooks.push({ moment, name: hold.name, ...target, exit: 1, outcome: "failed" });
708
+ back.failed = got.failed;
709
+ ctx.log(back.failed);
710
+ return back;
711
+ }
712
+ spent = got.record;
713
+ const finishedRel = holdFinishedPath(hold.env.CHANT_HOLD);
714
+ finishedAt = join(ctx.cwd, finishedRel);
715
+ rmSync(finishedAt, { force: true });
716
+ approvedEnv.CHANT_HOLD_FINISHED = finishedRel;
717
+ }
397
718
  let code;
398
719
  try {
399
- code = ctx.exec(hold.argv, ctx.cwd, approvedEnv);
720
+ code = hookExec ? await hookExec(hold.argv, ctx.cwd, approvedEnv) : ctx.exec(hold.argv, ctx.cwd, approvedEnv);
400
721
  }
401
722
  catch (err) {
402
723
  ctx.log(`${hold.label} did not run: ${err instanceof Error ? err.message : String(err)}`);
403
724
  code = 127;
404
725
  }
405
- const target = hold.target ? { target: hold.target } : {};
726
+ if (spent && finishedAt)
727
+ await finishHeldGate(ctx, hold, spent, readHoldFinished(finishedAt, ctx.log, hold.label), code);
406
728
  if (code === 0) {
407
729
  ctx.result.hooks.push({ moment, name: hold.name, ...target, exit: code, outcome: "passed" });
408
730
  ctx.log(`${hold.label}: ${held.approvedBy} approved ${held.op} / ${held.gate} at ${held.digest}, and the hook ran again and passed`);
@@ -474,6 +796,77 @@ function logRefused(log, label, check) {
474
796
  for (const { resolution: r, reason } of check.refused ?? [])
475
797
  log(`${label}: the approval by ${r.resolvedBy} at ${r.timestamp} does not count: ${reason}`);
476
798
  }
799
+ /**
800
+ * Spend a held gate's approval before the hook runs again under it (#4623),
801
+ * when the hold asked chant to `record` the gate: an applied line in
802
+ * `_gates/<op>/applied.jsonl`, as a gated request's (#4551). A digest that
803
+ * already applied under this gate does not apply again, and a line that did
804
+ * not reach the remote stops the re-run, so two jobs never act on one
805
+ * approval.
806
+ */
807
+ async function spendHeldGate(ctx, hold, approval) {
808
+ const { k, wave, cwd, options } = ctx;
809
+ const port = options.gates ?? gitGateLedgerPort({ cwd });
810
+ const label = `${approval.op} / ${approval.gate}`;
811
+ try {
812
+ if (!port.appendApplied)
813
+ throw new Error("this gate ledger cannot record an applied approval");
814
+ const prior = ((await port.readApplied?.(approval.op)) ?? []).filter((a) => a.gate === approval.gate && samePlanDigest(a.planDigest, approval.digest)).at(-1);
815
+ if (prior)
816
+ return { failed: `${hold.label}: ${label} at ${approval.digest} applied already under the approval by ${prior.approvedBy} (${prior.timestamp}); a held request applies once, so the hook did not run again` };
817
+ const commit = typeof hold.request.pending?.commit === "string" ? hold.request.pending.commit : undefined;
818
+ const runId = ciRunIdFromEnv();
819
+ const record = {
820
+ version: 1,
821
+ kind: "applied",
822
+ op: approval.op,
823
+ gate: approval.gate,
824
+ planDigest: approval.digest,
825
+ approvedAt: approval.approvedAt,
826
+ approvedBy: approval.approvedBy,
827
+ timestamp: options.now ?? new Date().toISOString(),
828
+ wave: { number: k, name: wave.name },
829
+ ...(runId ? { runId } : {}),
830
+ ...(commit ? { commit } : {}),
831
+ };
832
+ requireSpendPushed(await port.appendApplied(record));
833
+ ctx.log(`${hold.label}: ${label} applies under the approval by ${record.approvedBy} at ${record.approvedAt}, which is now spent`);
834
+ return { record };
835
+ }
836
+ catch (err) {
837
+ return { failed: `${hold.label}: could not record that ${label} applies under the approval by ${approval.approvedBy}, so the hook did not run again: ${err instanceof Error ? err.message : String(err)}` };
838
+ }
839
+ }
840
+ /**
841
+ * Write the finished line of a held gate the hook ran again under (#4623):
842
+ * how it ended, from the hook's `CHANT_HOLD_FINISHED` file, else from its
843
+ * exit code, with the file's detail. A line that is not written is logged;
844
+ * the work under the approval is done either way.
845
+ */
846
+ async function finishHeldGate(ctx, hold, spent, wrote, code) {
847
+ const port = ctx.options.gates ?? gitGateLedgerPort({ cwd: ctx.cwd });
848
+ const record = {
849
+ version: 1,
850
+ kind: "finished",
851
+ op: spent.op,
852
+ gate: spent.gate,
853
+ planDigest: spent.planDigest,
854
+ applied: spent.timestamp,
855
+ result: wrote?.result ?? (code === 0 ? "applied" : "failed"),
856
+ timestamp: ctx.options.now ?? new Date().toISOString(),
857
+ ...(wrote?.detail ? { detail: wrote.detail } : {}),
858
+ };
859
+ try {
860
+ if (!port.appendFinished)
861
+ throw new Error("this gate ledger keeps no finished lines");
862
+ const pushed = await port.appendFinished(record);
863
+ if (!pushed.pushed && pushed.pushWarning && !isLifecycleLocalNote(pushed.pushWarning))
864
+ ctx.log(`${hold.label}: the finished line of ${spent.op} / ${spent.gate} was written and not pushed: ${pushed.pushWarning}`);
865
+ }
866
+ catch (err) {
867
+ ctx.log(`${hold.label}: the finished line of ${spent.op} / ${spent.gate} was not written: ${err instanceof Error ? err.message : String(err)}`);
868
+ }
869
+ }
477
870
  /**
478
871
  * Settle a hold on another gate (#3821): an approval of that gate and digest
479
872
  * under the wave's approval mode (`pr-review` counts the ledger alone, since
@@ -487,6 +880,19 @@ async function settleOtherGate(ctx, hold) {
487
880
  const { port } = await gatePort(ctx.options, ctx.cwd, hold.request.gate, mode, rules.base);
488
881
  const neverOverMcp = rules.neverOverMcp;
489
882
  const now = ctx.options.now ?? new Date().toISOString();
883
+ // #4623: the file the request carries, stored once before the pending fact, which names its SHA-256.
884
+ const attachment = hold.request.attachment;
885
+ if (attachment !== undefined) {
886
+ try {
887
+ if (!port.storeRequestAttachment)
888
+ throw new Error("this gate ledger keeps no request files");
889
+ await port.storeRequestAttachment(op, hold.request.digest, attachment);
890
+ }
891
+ catch (err) {
892
+ log(`${op} / ${hold.request.gate}: the file ${hold.label} attached was not stored beside the pending fact: ${err instanceof Error ? err.message : String(err)}`);
893
+ }
894
+ }
895
+ const proof = attachment !== undefined ? { proof: `sha256:${createHash("sha256").update(attachment).digest("hex")}` } : {};
490
896
  const check = await evaluateGate(port, {
491
897
  op,
492
898
  gate: hold.request.gate,
@@ -494,7 +900,7 @@ async function settleOtherGate(ctx, hold) {
494
900
  description: hold.request.description ?? `wave ${k} (${wave.name}) of ${spec.name} is held on it by ${hold.label}`,
495
901
  now,
496
902
  // #3839: the wave a hold belongs to, as a field, whatever the hook's own description says.
497
- fields: { ...hold.request.pending, approvalMode: rules.approval, wave: { number: k, name: wave.name, op: spec.name }, heldBy: { hook: hold.name, moment: hold.moment, ...(hold.target ? { target: hold.target } : {}) } },
903
+ fields: { ...hold.request.pending, ...proof, approvalMode: rules.approval, wave: { number: k, name: wave.name, op: spec.name }, heldBy: { hook: hold.name, moment: hold.moment, ...(hold.target ? { target: hold.target } : {}) } },
498
904
  ...(neverOverMcp ? { neverOverMcp: true } : {}),
499
905
  });
500
906
  const base = { op, gate: hold.request.gate, digest: hold.request.digest, hook: hold.label };
@@ -654,8 +1060,231 @@ function noteHooksAtBase(ctx, rules) {
654
1060
  * its plan command found.
655
1061
  */
656
1062
  export async function runOpWave(options) {
1063
+ assertOpWavesSpec(options.spec);
1064
+ const afterPlanWrong = opWaveAfterPlanProblems(options.afterPlan);
1065
+ if (afterPlanWrong.length > 0)
1066
+ throw new Error(`Op waves "${options.spec.name}": ${afterPlanWrong.join("; ")}`);
1067
+ // #4551: one run record per job, on every way the job ends.
1068
+ const started = new Date().toISOString();
1069
+ // #4555: the job's run events and its trace, when a reader or an exporter wants them.
1070
+ const events = await openOpWaveEvents(options);
1071
+ if (events)
1072
+ jobEvents.set(options, events);
1073
+ events?.start();
1074
+ let result;
1075
+ try {
1076
+ result = await runOpWaveJob(options);
1077
+ }
1078
+ catch (err) {
1079
+ const record = await recordOpWaveRun(options, started, { error: err });
1080
+ await closeOpWaveEvents(options, events, record);
1081
+ throw err;
1082
+ }
1083
+ const record = await recordOpWaveRun(options, started, { result });
1084
+ await closeOpWaveEvents(options, events, record, result);
1085
+ return result;
1086
+ }
1087
+ /** Each running job's events (#4555), by its options, which every step of the job is handed. */
1088
+ const jobEvents = new WeakMap();
1089
+ /** The job's run events (#4555): to `options.events`, and to a trace when the exporter is on. Undefined when neither wants them. */
1090
+ async function openOpWaveEvents(options) {
1091
+ const log = options.log ?? ((line) => console.error(line));
1092
+ let exporter;
1093
+ try {
1094
+ exporter = options.otlp === false ? undefined : (options.otlp ?? activeOtlp());
1095
+ }
1096
+ catch (err) {
1097
+ log(`wave ${options.wave}: no trace is sent: ${err instanceof Error ? err.message : String(err)}`);
1098
+ }
1099
+ if (!options.events && !exporter)
1100
+ return undefined;
1101
+ let trace;
1102
+ if (exporter) {
1103
+ const run = await resolveRunEventRun({ kind: "op", name: options.spec.name, cwd: options.cwd ?? process.cwd() });
1104
+ trace = new RunEventTrace(run, { exporter });
1105
+ }
1106
+ return new OpWaveRunEvents(joinRunEventSinks(options.events, trace?.sink), trace);
1107
+ }
1108
+ /** Settle the job's events from its run record and send its trace (#4555). A trace that does not go out is a line in the log, never a change of exit code. */
1109
+ async function closeOpWaveEvents(options, events, record, result) {
1110
+ if (!events)
1111
+ return;
1112
+ jobEvents.delete(options);
1113
+ events.finish(record, { ...(result ? { moved: result.moved } : {}), ...(result?.blocked ? { blocked: result.blocked } : {}) });
1114
+ const problem = await events.trace?.flush();
1115
+ if (problem)
1116
+ (options.log ?? ((line) => console.error(line)))(`wave ${options.wave}: the trace was not sent: ${problem}`);
1117
+ }
1118
+ /** A target's apply began (#4555): its start time for the record, and its `step-start`. */
1119
+ function targetStarted(options, k, target) {
1120
+ jobEvents.get(options)?.stepStart(k, target);
1121
+ return Date.now();
1122
+ }
1123
+ /** A target's apply ended (#4555): its time and facts on the result, and its `step-settle`. */
1124
+ function targetSettled(options, result, k, target, startedMs, status, opts = {}) {
1125
+ const durationMs = Math.max(0, Date.now() - startedMs);
1126
+ result.targets = {
1127
+ ...result.targets,
1128
+ [target]: {
1129
+ startedAt: new Date(startedMs).toISOString(),
1130
+ durationMs,
1131
+ ...(opts.facts?.attributes ? { attributes: opts.facts.attributes } : {}),
1132
+ ...(opts.facts?.spans?.length ? { spans: opts.facts.spans } : {}),
1133
+ // #4629: what the failed-apply triage reads back from the run record.
1134
+ ...(status === "failed" && opts.error ? { error: opts.error } : {}),
1135
+ ...(status === "failed" && opts.facts?.resources?.some((r) => r.status === "failed")
1136
+ ? { failedResources: opts.facts.resources.filter((r) => r.status === "failed").map((r) => r.name ?? r.resource) }
1137
+ : {}),
1138
+ },
1139
+ };
1140
+ jobEvents.get(options)?.stepSettle(k, target, status, durationMs, opts);
1141
+ // #4615: one log line per resource the engine reported.
1142
+ if (opts.facts?.resources?.length) {
1143
+ const log = options.log ?? ((line) => console.error(line));
1144
+ for (const line of opWaveResourceLines(target, opts.facts.resources))
1145
+ log(line);
1146
+ }
1147
+ }
1148
+ /** The log lines for what a target's engine reported per resource (#4615): `<target>: <resource> (<type>) ok in 412 ms, 3 calls`. */
1149
+ export function opWaveResourceLines(target, resources) {
1150
+ return resources.map((r) => {
1151
+ const what = r.name ? `${r.name}${r.type ? ` (${r.type})` : ""}` : `${r.resource}${r.type ? ` (${r.type})` : ""}`;
1152
+ const took = r.durationMs === null ? "" : ` in ${Math.round(r.durationMs)} ms`;
1153
+ const calls = r.calls !== undefined ? `, ${r.calls} call${r.calls === 1 ? "" : "s"}` : "";
1154
+ return `${target}: ${what} ${r.status === "ok" ? "ok" : "failed"}${took}${calls}`;
1155
+ });
1156
+ }
1157
+ /** The run ledger's status and failure for a job's exit code (#4551), by chant's exit-code table. */
1158
+ function opWaveRunStatus(result) {
1159
+ const d = result.decision;
1160
+ switch (result.exitCode) {
1161
+ case CHANT_EXIT.done:
1162
+ case CHANT_EXIT.held:
1163
+ case CHANT_EXIT.superseded:
1164
+ return { status: "ok" };
1165
+ case CHANT_EXIT.waiting:
1166
+ return { status: d?.point?.question ? "waiting" : "gated" };
1167
+ case CHANT_EXIT.moved:
1168
+ return { status: "fail", failure: { code: "moved", reason: `plans moved since the decision: ${result.moved.join(", ") || "(none named)"}` } };
1169
+ case CHANT_EXIT.denied:
1170
+ return { status: "fail", failure: { code: "denied", reason: d?.refused?.message ?? `the policy denied ${d?.refused?.runs.join(", ") ?? "a run"}, and no override counts` } };
1171
+ case CHANT_EXIT.declined:
1172
+ return { status: "fail", failure: { code: "point-refused", reason: d?.refused?.message ?? "the gate's decision point was answered with an answer it does not pass on" } };
1173
+ default:
1174
+ return { status: "fail", failure: { code: "command-failed", reason: result.failed.length > 0 ? `failed: ${result.failed.join(", ")}` : "the wave job failed" } };
1175
+ }
1176
+ }
1177
+ /**
1178
+ * The run record of one `chant run wave` job (#4551): one phase per wave the
1179
+ * job walked, one step per run target. A run that applied is `ok`, one that
1180
+ * failed `fail`, and one that moved, was blocked or waited `skipped`.
1181
+ */
1182
+ export function opWaveRunRecord(options, times, outcome) {
1183
+ const { spec } = options;
1184
+ const result = "result" in outcome ? outcome.result : { exitCode: CHANT_EXIT.failed, applied: [], failed: [], moved: [], hooks: [] };
1185
+ const d = result.decision;
1186
+ const applied = new Set(result.applied);
1187
+ const failedRuns = new Set(result.failed);
1188
+ const walked = result.rest?.length ? result.rest.map((r) => r.wave) : [options.wave];
1189
+ const last = walked[walked.length - 1];
1190
+ const phases = walked.map((k) => {
1191
+ const targets = k === last && d ? d.members.map((m) => m.member) : (spec.waves[k - 1]?.runs ?? []).map((r) => r.target);
1192
+ const steps = targets.map((t) => ({
1193
+ fn: t,
1194
+ status: failedRuns.has(t) ? "fail" : applied.has(t) ? "ok" : "skipped",
1195
+ durationMs: result.targets?.[t]?.durationMs ?? 0,
1196
+ }));
1197
+ const status = steps.some((x) => x.status === "fail") ? "fail" : steps.length > 0 && steps.every((x) => x.status === "skipped") ? "skipped" : "ok";
1198
+ return { name: `wave-${k}`, status, steps };
1199
+ });
1200
+ const verdict = "error" in outcome
1201
+ ? { status: "fail", failure: { code: "command-failed", reason: outcome.error instanceof Error ? outcome.error.message : String(outcome.error) } }
1202
+ : opWaveRunStatus(result);
1203
+ const wave = {
1204
+ spec: spec.name,
1205
+ number: options.wave,
1206
+ name: spec.waves[options.wave - 1]?.name ?? `wave-${options.wave}`,
1207
+ job: options.decide ? "decide" : options.group !== undefined ? "group" : options.share !== undefined ? "share" : "wave",
1208
+ ...(options.share !== undefined ? { share: options.share } : {}),
1209
+ ...(options.group !== undefined ? { group: options.group } : {}),
1210
+ ...(d?.digest ? { digest: d.digest } : {}),
1211
+ exitCode: result.exitCode,
1212
+ ...(result.outcome && result.outcome.outcome !== "replan" ? { outcome: result.outcome.outcome } : {}),
1213
+ ...(result.supersededBy ? { supersededBy: { ...result.supersededBy } } : {}),
1214
+ applied: [...result.applied],
1215
+ failed: [...result.failed],
1216
+ moved: [...result.moved],
1217
+ ...(result.blocked && Object.keys(result.blocked).length > 0 ? { blocked: { ...result.blocked } } : {}),
1218
+ ...(result.targets && Object.keys(result.targets).length > 0 ? { targets: { ...result.targets } } : {}),
1219
+ ...(result.plans && Object.keys(result.plans).length > 0 ? { plans: { ...result.plans } } : {}),
1220
+ };
1221
+ const labels = { ...(spec.labels ?? {}) };
1222
+ return {
1223
+ op: spec.name,
1224
+ env: labels.Env ?? DEFAULT_RUN_ENV,
1225
+ started: times.started,
1226
+ ended: times.ended,
1227
+ status: verdict.status,
1228
+ labels,
1229
+ outcomes: {},
1230
+ phases,
1231
+ ...(verdict.status === "gated" && d ? { gate: { name: d.gate, since: d.waitingSince ?? times.ended, ...(d.op !== spec.name ? { op: d.op } : {}) } } : {}),
1232
+ ...(verdict.status === "waiting" && d?.point?.question ? { point: { ...d.point.question, since: d.waitingSince ?? times.ended } } : {}),
1233
+ ...(times.gitSha ? { gitSha: times.gitSha } : {}),
1234
+ ...(times.runOrigin ? { runOrigin: times.runOrigin } : {}),
1235
+ ...(verdict.failure ? { failure: { ...verdict.failure, exitCode: result.exitCode } } : {}),
1236
+ wave,
1237
+ };
1238
+ }
1239
+ /** Append the job's run record (#4551). A failed write warns and never changes the job's exit code. */
1240
+ async function recordOpWaveRun(options, started, outcome) {
1241
+ const cwd = options.cwd ?? process.cwd();
1242
+ const port = options.runs ?? (options.gates ? undefined : gitOpWaveRunPort({ cwd }));
1243
+ const log = options.log ?? ((line) => console.error(line));
1244
+ let gitSha = options.head;
1245
+ if (gitSha === undefined) {
1246
+ try {
1247
+ gitSha = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
1248
+ }
1249
+ catch {
1250
+ gitSha = undefined;
1251
+ }
1252
+ }
1253
+ const ci = resolveCiJob();
1254
+ const record = opWaveRunRecord(options, { started, ended: new Date().toISOString(), ...(gitSha ? { gitSha } : {}), ...(ci ? { runOrigin: ci.runOrigin } : {}) }, outcome);
1255
+ // The record is built either way: the job's run events settle from it (#4555).
1256
+ if (!port)
1257
+ return record;
1258
+ try {
1259
+ const wrote = await port.append(record);
1260
+ if (wrote && wrote.pushWarning)
1261
+ log(`wave ${options.wave}: the run record was written and not pushed: ${wrote.pushWarning}`);
1262
+ }
1263
+ catch (err) {
1264
+ log(`wave ${options.wave}: could not record the run on the run ledger: ${err instanceof Error ? err.message : String(err)}`);
1265
+ }
1266
+ return record;
1267
+ }
1268
+ /**
1269
+ * Store the change-set document a wave's plans file gave (#4551), so the
1270
+ * pending fact can cite it. A document that is not one, or does not hash to
1271
+ * its digest, is logged and left out; it never blocks the gate.
1272
+ */
1273
+ async function storeWaveChangeSet(options, ctx, decision, doc) {
1274
+ const ledger = options.gates ?? gitGateLedgerPort({ cwd: ctx.cwd });
1275
+ if (!ledger.storeChangeSet)
1276
+ return;
1277
+ try {
1278
+ await ledger.storeChangeSet(doc);
1279
+ decision.changeSet = doc.digest;
1280
+ }
1281
+ catch (err) {
1282
+ ctx.log(`wave ${ctx.k} (${ctx.wave.name}): the plans file's change set was not stored, so the pending fact cites none: ${err instanceof Error ? err.message : String(err)}`);
1283
+ }
1284
+ }
1285
+ /** One job's plan, decide and apply, which {@link runOpWave} records. */
1286
+ async function runOpWaveJob(options) {
657
1287
  const { spec } = options;
658
- assertOpWavesSpec(spec);
659
1288
  const log = options.log ?? ((line) => console.error(line));
660
1289
  const cwd = options.cwd ?? process.cwd();
661
1290
  const outcomeDir = options.outcomeDir ?? opWaveOutcomeDir(spec);
@@ -704,6 +1333,8 @@ async function runOpWaveLoop(options, log, applied, skip) {
704
1333
  const { spec } = options;
705
1334
  const last = spec.waves[spec.waves.length - 1];
706
1335
  const rest = [];
1336
+ // #4555: each wave a `rest` job walks keeps its targets' times.
1337
+ const targets = {};
707
1338
  const result = await runWaveLoop({
708
1339
  first: options.wave,
709
1340
  plan: (at) => planOpWave(options, at, at.k === options.wave ? skip : undefined),
@@ -723,6 +1354,7 @@ async function runOpWaveLoop(options, log, applied, skip) {
723
1354
  },
724
1355
  onward(k, outcome) {
725
1356
  applied.push(...outcome.applied);
1357
+ Object.assign(targets, outcome.targets ?? {});
726
1358
  // #3821: a `rest` wave goes on through the waves its plan command found.
727
1359
  const found = outcome.decision?.discovered?.waves;
728
1360
  const onward = k >= spec.waves.length && last.rest === true && options.share === undefined && options.group === undefined && !options.decide && outcome.exitCode === 0 && found !== undefined && k < found;
@@ -733,7 +1365,8 @@ async function runOpWaveLoop(options, log, applied, skip) {
733
1365
  return onward;
734
1366
  },
735
1367
  });
736
- return { ...result, applied, ...(rest.length > 0 ? { rest } : {}) };
1368
+ const timed = { ...targets, ...(result.targets ?? {}) };
1369
+ return { ...result, applied, ...(rest.length > 0 ? { rest } : {}), ...(Object.keys(timed).length > 0 ? { targets: timed } : {}) };
737
1370
  }
738
1371
  /**
739
1372
  * Read the outcome files under `dir` for wave `k`'s job (#4322). A wave or
@@ -784,7 +1417,7 @@ function opWaveBefore(options, dir) {
784
1417
  ? `Nothing in wave ${k} (${wave.name}) ran: ${shown} waits at its gate. Approve it and run that wave's job again, then this one.`
785
1418
  : `Nothing in wave ${k} (${wave.name}) ran: ${shown} did not apply, and only a failure lets the waves after it go on.`;
786
1419
  const status = waiting.length > 0 ? "waiting" : "not-applied";
787
- return { blocked: new Map(), stop: { exitCode: waiting.length > 0 ? 3 : 1, line, members: Object.fromEntries((wave.runs ?? []).map((r) => [r.target, { status }])) } };
1420
+ return { blocked: new Map(), stop: { exitCode: waiting.length > 0 ? CHANT_EXIT.waiting : CHANT_EXIT.failed, line, members: Object.fromEntries((wave.runs ?? []).map((r) => [r.target, { status }])) } };
788
1421
  }
789
1422
  const runs = wave.runs ?? [];
790
1423
  const index = new Map(runs.map((r, i) => [r.target, i]));
@@ -828,9 +1461,9 @@ function writeOpWaveOutcome(options, dir, result, members) {
828
1461
  const failed = new Set(result.failed);
829
1462
  const moved = new Set(result.moved);
830
1463
  const otherwise = result.exitCode === 0 ? (options.decide ? "decided" : "unchanged")
831
- : result.exitCode === 3 ? "waiting"
832
- : result.exitCode === 7 || result.exitCode === 8 ? "refused"
833
- : result.exitCode >= 4 && result.exitCode <= 6 ? "not-applied"
1464
+ : result.exitCode === CHANT_EXIT.waiting ? "waiting"
1465
+ : result.exitCode === CHANT_EXIT.denied || result.exitCode === CHANT_EXIT.declined ? "refused"
1466
+ : result.exitCode >= CHANT_EXIT.moved && result.exitCode <= CHANT_EXIT.superseded ? "not-applied"
834
1467
  : "failed";
835
1468
  for (const t of targets) {
836
1469
  const by = result.blocked?.[t];
@@ -902,7 +1535,7 @@ async function planOpWave(options, { k, pass }, skip) {
902
1535
  ctx.gateRule = { approval: decision.approval, base: decision.base, neverOverMcp: decision.neverOverMcp === true };
903
1536
  if (decision.status === "waiting" || decision.status === "refused") {
904
1537
  log(`wave ${k} (${wave.name}) is ${decision.status === "refused" ? "refused by its policy" : `waiting on ${decision.heldOn?.gate ?? decision.gate}`}; nothing applied. ${decision.approve ?? ""}`.trim());
905
- return { end: { ...result, exitCode: decision.status === "refused" ? refusedExit(decision) : 3 } };
1538
+ return { end: { ...result, exitCode: decision.status === "refused" ? refusedExit(decision) : CHANT_EXIT.waiting } };
906
1539
  }
907
1540
  // The share runs the hooks its deciding job read at base, around its own slice.
908
1541
  if (wave.discover) {
@@ -924,14 +1557,20 @@ async function planOpWave(options, { k, pass }, skip) {
924
1557
  return { end: failed(ctx, `a hook before the plan failed, so nothing in ${part} of wave ${k} was planned or applied`) };
925
1558
  if (before.waitingOn)
926
1559
  return { end: await waitOnOther(ctx, decision, before.waitingOn) };
927
- const { members } = planRuns(ctx, slice);
1560
+ if (spec.step)
1561
+ ctx.steps = new Map();
1562
+ const { members, parts: sliceParts } = await planWaveRuns(ctx, slice);
1563
+ // #4614: the after-plan hooks in the job's process, over the share's own plans.
1564
+ const inProcess = await runAfterPlan(ctx, members, sliceParts, new Map());
1565
+ if (inProcess.failed)
1566
+ return { end: failed(ctx, `${inProcess.failed}, so nothing in ${part} of wave ${k} was applied`) };
928
1567
  const planned = new Map(members.map((m) => [m.member, m]));
929
1568
  const after = await runHooks(ctx, "after-plan", decision.hooks?.["after-plan"], slice, planned);
930
1569
  if (after.failed)
931
1570
  return { end: failed(ctx, `a hook after the plan failed, so nothing in ${part} of wave ${k} was applied`) };
932
1571
  if (after.waitingOn)
933
1572
  return { end: await waitOnOther(ctx, decision, after.waitingOn) };
934
- return { go: { kind: "share", ctx, decision, slice, planned, holds: [...before.holds, ...after.holds] } };
1573
+ return { go: { kind: "share", ctx, decision, slice, planned, holds: [...before.holds, ...inProcess.holds, ...after.holds] } };
935
1574
  }
936
1575
  // The policy, the approval mode and the hooks, read at base before anything runs.
937
1576
  const rules = readOpWavePolicy(options.specFile, wave.name, options.base ?? spec.base ?? "HEAD^1", cwd, options.show);
@@ -990,7 +1629,33 @@ async function planOpWave(options, { k, pass }, skip) {
990
1629
  return { end: failed(ctx, `a hook before the plan failed, so nothing in wave ${k} was planned or applied`) };
991
1630
  if (before.waitingOn)
992
1631
  return { end: await decided(ctx, decision, recordPath, before.waitingOn) };
993
- const { members, pending, overriders, overridersSource, extras, waves: found } = planRuns(ctx, wave.runs, wave.discover === true);
1632
+ if (spec.step)
1633
+ ctx.steps = new Map();
1634
+ const { members, pending, overriders, overridersSource, extras: planExtras, waves: found, changeSet, parts } = await planWaveRuns(ctx, wave.runs, wave.discover === true);
1635
+ // #4545: the holds at base (else the change's), run over the plans before the gate decides.
1636
+ let extras = planExtras;
1637
+ let policyRows = new Map();
1638
+ if (rules.holdsRefused) {
1639
+ holds.push(rules.holdsRefused);
1640
+ log(`wave ${k} (${wave.name}): ${rules.holdsRefused}, so none runs and the wave waits for an approval`);
1641
+ }
1642
+ else {
1643
+ const held = await runWaveHolds(ctx, opWaveHoldsAt(rules.holds, spec.holds), members, parts, base);
1644
+ if ("failed" in held)
1645
+ return { end: failed(ctx, held.failed) };
1646
+ holds.push(...held.holds);
1647
+ if (held.extras.length > 0)
1648
+ extras = [...(extras ?? []), ...held.extras];
1649
+ policyRows = held.rows;
1650
+ // #4613: the decision names the shared policy commit its runs were judged by.
1651
+ if (held.policySource)
1652
+ decision.ciPolicySource = held.policySource;
1653
+ }
1654
+ // #4614: the after-plan hooks in the job's process, before the set digest and the gate.
1655
+ const inProcess = await runAfterPlan(ctx, members, parts, policyRows);
1656
+ if (inProcess.failed)
1657
+ return { end: failed(ctx, `${inProcess.failed}, so nothing in wave ${k} was approved or applied`) };
1658
+ holds.push(...inProcess.holds);
994
1659
  if (wave.discover) {
995
1660
  wave = { ...wave, runs: members.map((m) => ({ target: m.member, ...(m.op !== spec.op ? { op: m.op } : {}) })) };
996
1661
  ctx.wave = wave;
@@ -1017,6 +1682,7 @@ async function planOpWave(options, { k, pass }, skip) {
1017
1682
  ...(overriders ? { overriders } : {}),
1018
1683
  ...(overridersSource ? { overridersSource } : {}),
1019
1684
  ...(extras ? { extras } : {}),
1685
+ ...(changeSet ? { changeSet } : {}),
1020
1686
  },
1021
1687
  };
1022
1688
  }
@@ -1066,6 +1732,13 @@ async function decideOpWave(options, { prior }, planned, digest) {
1066
1732
  decision.extras = extras;
1067
1733
  if (pending)
1068
1734
  decision.pending = pending;
1735
+ if (planned.changeSet)
1736
+ await storeWaveChangeSet(options, ctx, decision, planned.changeSet);
1737
+ // #4550: a pull-request wave checks the pull request's approval against the plans file's change set.
1738
+ if (planned.changeSet)
1739
+ ctx.changeSetDoc = planned.changeSet;
1740
+ if (decision.approval === "pull-request" && planned.rules.pullRequestGate)
1741
+ decision.pullRequestGate = planned.rules.pullRequestGate;
1069
1742
  const after = await runHooks(ctx, "after-plan", planned.rules.hooks["after-plan"], wave.runs, planned.planned, digest);
1070
1743
  if (after.failed)
1071
1744
  return { end: failed(ctx, `a hook after the plan failed, so nothing in wave ${k} was applied`) };
@@ -1124,7 +1797,7 @@ async function applyOpWave(options, planned, decidedWave) {
1124
1797
  const { ctx, decision } = planned;
1125
1798
  await applyStage(options, ctx, decision, decidedWave.runs, planned.planned, decidedWave.earlierHolds, decidedWave.recordPath);
1126
1799
  if (planned.kind === "share" && ctx.result.exitCode === 0 && ctx.result.moved.length > 0)
1127
- ctx.result.exitCode = 4;
1800
+ ctx.result.exitCode = CHANT_EXIT.moved;
1128
1801
  return ctx.result;
1129
1802
  }
1130
1803
  /**
@@ -1148,15 +1821,15 @@ async function decided(ctx, decision, recordPath, heldOn) {
1148
1821
  const hook = await runGateHooks(ctx, decision, recordPath);
1149
1822
  if (decision.status === "waiting") {
1150
1823
  log(`Nothing in wave ${k} or after it ran. ${decision.heldOn ? `It waits on ${decision.heldOn.op} / ${decision.heldOn.gate}.` : "Read the plans, then"} approve: ${decision.approve} (with --resume, the approval also starts this job again)`);
1151
- return { ...result, exitCode: 3 };
1824
+ return { ...result, exitCode: CHANT_EXIT.waiting };
1152
1825
  }
1153
1826
  if (decision.status === "refused" && decision.refused?.reason === "point") {
1154
1827
  log(`Nothing in wave ${k} (${wave.name}) or after it ran: ${decision.refused.message}`);
1155
- return { ...result, exitCode: 8 };
1828
+ return { ...result, exitCode: CHANT_EXIT.declined };
1156
1829
  }
1157
1830
  if (decision.status === "refused") {
1158
1831
  log(`Nothing in wave ${k} (${wave.name}) or after it ran: the policy denied ${decision.refused?.runs.join(", ")}, and no override counts for ${decision.refused?.runs.length === 1 ? "it" : "them"}.`);
1159
- return { ...result, exitCode: 7 };
1832
+ return { ...result, exitCode: CHANT_EXIT.denied };
1160
1833
  }
1161
1834
  if (hook.failed)
1162
1835
  return failed(ctx, `wave ${k} (${wave.name}): ${hook.failed}, so nothing in it was applied`);
@@ -1176,7 +1849,7 @@ function markHeldOn(decision, heldOn) {
1176
1849
  async function waitOnOther(ctx, decision, heldOn) {
1177
1850
  markHeldOn(decision, heldOn);
1178
1851
  ctx.log(`${shareLabel(ctx.options)} of wave ${ctx.k} (${ctx.wave.name}) waits on ${heldOn.op} / ${heldOn.gate}; nothing in it applied. Approve: ${heldOn.approve}`);
1179
- return { ...ctx.result, decision, exitCode: 3 };
1852
+ return { ...ctx.result, decision, exitCode: CHANT_EXIT.waiting };
1180
1853
  }
1181
1854
  /**
1182
1855
  * Run the `after-gate` hooks (#3821) once the gate decided. Their
@@ -1328,7 +2001,7 @@ async function spendOverrides(ctx, decision) {
1328
2001
  }
1329
2002
  /** The exit code of a refused wave: 8 when its decision point refused it (#3836), 7 when the product's policy did (#3821). */
1330
2003
  function refusedExit(decision) {
1331
- return decision.refused?.reason === "point" ? 8 : 7;
2004
+ return decision.refused?.reason === "point" ? CHANT_EXIT.declined : CHANT_EXIT.denied;
1332
2005
  }
1333
2006
  function failed(ctx, line) {
1334
2007
  ctx.log(line);
@@ -1352,7 +2025,17 @@ async function settleGate(options, ctx, decision) {
1352
2025
  // #3784: under the spend rule at base, an approval a wave already applied under counts for nothing.
1353
2026
  const spent = decision.spend === "base" ? ((await ledger.readApplied?.(spec.name)) ?? []).filter((a) => a.gate === gate) : undefined;
1354
2027
  const held = decision.heldBy?.length ? `, held by ${decision.heldBy.join(", ")}` : "";
1355
- const check = await decideWaveGate(port, {
2028
+ // Under the pull request's approval the pending fact waits for the coverage check: a wave the
2029
+ // pull request's approval covers applies with no pending line at its own gate (#4588).
2030
+ let deferred;
2031
+ const deciding = approval !== "pull-request" ? port : {
2032
+ ...port,
2033
+ async appendPending(input) {
2034
+ deferred = input;
2035
+ return { record: { version: 1, kind: "pending", ...input }, pushed: false };
2036
+ },
2037
+ };
2038
+ const check = await decideWaveGate(deciding, {
1356
2039
  op: spec.name,
1357
2040
  gate,
1358
2041
  digest,
@@ -1360,7 +2043,7 @@ async function settleGate(options, ctx, decision) {
1360
2043
  now,
1361
2044
  ...(spent ? { spent } : {}),
1362
2045
  // #3861: the approval mode the wave asked under, for readers deciding which approvals count.
1363
- fields: { ...decision.pending, approvalMode: approval },
2046
+ fields: { ...decision.pending, ...(decision.changeSet ? { changeSet: decision.changeSet } : {}), approvalMode: approval },
1364
2047
  ...(decision.neverOverMcp ? { neverOverMcp: true } : {}),
1365
2048
  });
1366
2049
  if (check.satisfied) {
@@ -1381,6 +2064,29 @@ async function settleGate(options, ctx, decision) {
1381
2064
  if (used) {
1382
2065
  ctx.log(`wave ${k} (${wave.name}): the approval of ${digest} by ${used.approvedBy} at ${used.approvedAt} is spent: a wave applied under it at ${used.timestamp}. Applying it again needs a new approval`);
1383
2066
  }
2067
+ if (approval === "pull-request") {
2068
+ const covered = await approveByPullRequest(options, ctx, decision, ledger);
2069
+ decision.coveredBy = covered.digest ? { digest: covered.digest } : { reason: covered.reason };
2070
+ if (covered.digest) {
2071
+ for (const key of ["pendingFact", "recorded", "waitingSince", "mismatch"])
2072
+ delete decision[key];
2073
+ decision.status = "approved";
2074
+ decision.via = "pull-request";
2075
+ decision.approvedBy = covered.approvedBy;
2076
+ decision.approvedAt = covered.approvedAt;
2077
+ ctx.log(`wave ${k} (${wave.name}) applies under the pull request's approval of ${covered.digest} at ${decision.pullRequestGate}, which covers its plans`);
2078
+ return;
2079
+ }
2080
+ if (deferred) {
2081
+ const written = await port.appendPending(deferred);
2082
+ decision.pendingFact = written.record;
2083
+ decision.waitingSince = written.record.timestamp;
2084
+ }
2085
+ ctx.log(`wave ${k} (${wave.name}): the pull request's approval does not cover it (${covered.reason}), so it waits at its own gate ${gate}`);
2086
+ decision.status = "waiting";
2087
+ decision.approve = approveCommand(spec.name, gate, undefined, digest);
2088
+ return;
2089
+ }
1384
2090
  if (approval === "pr-review") {
1385
2091
  const byReview = await approveByReview(options, { op: spec.name, gate, k, digest, cwd, now, port: ledger, ...(spent ? { spent } : {}) });
1386
2092
  decision.review = byReview.review;
@@ -1400,6 +2106,51 @@ async function settleGate(options, ctx, decision) {
1400
2106
  decision.status = "waiting";
1401
2107
  decision.approve = approveCommand(spec.name, gate, undefined, digest, approval === "sealed");
1402
2108
  }
2109
+ /**
2110
+ * Under `approval: "pull-request"` (#4550, ruling B): find an approval of the
2111
+ * pull request's gate, under the spec's op, whose change set covers every
2112
+ * member of this wave's plans (`planCoveredBy`, as a resume checks a wave
2113
+ * against the pull request's approval). The newest such approval wins. A
2114
+ * spent one counts for nothing under the spend rule. Needs the plans file's
2115
+ * change set; without one the wave waits at its own gate.
2116
+ */
2117
+ async function approveByPullRequest(options, ctx, decision, ledger) {
2118
+ const prGate = decision.pullRequestGate;
2119
+ if (!prGate)
2120
+ return { reason: "the spec at base names no approvals.pullRequest.gate" };
2121
+ const fresh = ctx.changeSetDoc;
2122
+ if (!fresh)
2123
+ return { reason: "the plans file carries no change set to check the approval against" };
2124
+ const { planCoveredBy } = await import("../components/pr-run.js");
2125
+ const read = options.changeSets ?? (async (d) => {
2126
+ const { readStoredChangeSet } = await import("../lifecycle/change-set-store.js");
2127
+ const got = await readStoredChangeSet(d, { cwd: ctx.cwd });
2128
+ return got.status === "found" ? got.document : undefined;
2129
+ });
2130
+ const { resolutions } = await ledger.read(ctx.spec.name);
2131
+ const spent = decision.spend === "base" ? ((await ledger.readApplied?.(ctx.spec.name)) ?? []).filter((a) => a.gate === prGate) : [];
2132
+ const approvals = resolutions.filter((r) => r.gate === prGate && (r.changeSet ?? r.planDigest)).sort((a, b) => (a.timestamp < b.timestamp ? 1 : -1));
2133
+ if (approvals.length === 0)
2134
+ return { reason: `no approval stands at ${prGate}` };
2135
+ let reason = `no approval at ${prGate} covers it`;
2136
+ for (const r of approvals) {
2137
+ const digest = (r.changeSet ?? r.planDigest);
2138
+ if (spent.some((a) => a.planDigest === digest && a.approvedAt === r.timestamp)) {
2139
+ reason = `the approval of ${digest} at ${prGate} is spent`;
2140
+ continue;
2141
+ }
2142
+ const approved = await read(digest).catch(() => undefined);
2143
+ if (!approved) {
2144
+ reason = `the change set ${digest} the approval names is not stored`;
2145
+ continue;
2146
+ }
2147
+ const why = fresh.members.map((m) => planCoveredBy(approved, fresh, m.member)).find((w) => w !== undefined);
2148
+ if (why === undefined)
2149
+ return { digest, approvedBy: r.resolvedBy, approvedAt: r.timestamp, reason: "" };
2150
+ reason = why;
2151
+ }
2152
+ return { reason };
2153
+ }
1403
2154
  /** The commits after `base` up to `head`, merge commits left out, for the `Requested-by:` trailers on them (#4333). */
1404
2155
  const gitCommitsBetween = (cwd) => (base, head) => {
1405
2156
  try {
@@ -1538,7 +2289,7 @@ async function settleQuorumGate(options, ctx, decision, rules) {
1538
2289
  description: (typeof decision.pending?.description === "string" ? decision.pending.description : undefined) ?? `wave ${k} (${wave.name}): ${members.length} run${members.length === 1 ? "" : "s"}, gate ${policy}, approval ${approval}${held}`,
1539
2290
  now,
1540
2291
  ...(spent ? { spent } : {}),
1541
- fields: { ...decision.pending, approvalMode: approval },
2292
+ fields: { ...decision.pending, ...(decision.changeSet ? { changeSet: decision.changeSet } : {}), approvalMode: approval },
1542
2293
  ...(decision.neverOverMcp ? { neverOverMcp: true } : {}),
1543
2294
  approval: { quorum: rules, mode: "log-only" },
1544
2295
  judge,
@@ -1593,7 +2344,7 @@ async function settlePointGate(options, ctx, decision, point) {
1593
2344
  planDigest: digest,
1594
2345
  ...(options.now ? { now: options.now } : {}),
1595
2346
  // #3863: the plans file's pending fields and the spec's neverOverMcp, as settleGate passes them.
1596
- fields: { ...decision.pending, approvalMode: decision.approval },
2347
+ fields: { ...decision.pending, ...(decision.changeSet ? { changeSet: decision.changeSet } : {}), approvalMode: decision.approval },
1597
2348
  ...(decision.neverOverMcp ? { neverOverMcp: true } : {}),
1598
2349
  });
1599
2350
  if (check.satisfied) {
@@ -1649,12 +2400,31 @@ async function settleHolds(options, ctx, decision, holds, recordPath) {
1649
2400
  if (recordPath)
1650
2401
  await runGateHooks(ctx, decision, recordPath);
1651
2402
  log(`wave ${k} (${wave.name}) is held by ${holds.join(", ")}, and nobody approved ${decision.digest}; nothing applied. Approve: ${decision.approve}`);
1652
- result.exitCode = 3;
2403
+ result.exitCode = CHANT_EXIT.waiting;
1653
2404
  return false;
1654
2405
  }
1655
2406
  log(`wave ${k} (${wave.name}) is held by ${holds.join(", ")}, and ${decision.approvedBy} approved its digest`);
1656
2407
  return true;
1657
2408
  }
2409
+ /**
2410
+ * The runs a failed `applyWave` call says it applied (#4291 on op waves):
2411
+ * `{ "applied": [<target>...] }` at `CHANT_APPLY_RUNS_RESULT`. Absent or
2412
+ * unreadable, none did, as before.
2413
+ */
2414
+ function readAppliedRuns(path, label, log) {
2415
+ if (!existsSync(path))
2416
+ return undefined;
2417
+ try {
2418
+ const got = JSON.parse(readFileSync(path, "utf-8"));
2419
+ if (Array.isArray(got?.applied) && got.applied.every((t) => typeof t === "string"))
2420
+ return got.applied;
2421
+ }
2422
+ catch {
2423
+ // Read as absent below.
2424
+ }
2425
+ log(`${label}: CHANT_APPLY_RUNS_RESULT is not { "applied": [<target>...] }, so no run counts as applied`);
2426
+ return undefined;
2427
+ }
1658
2428
  /** Read what an apply wrote to `CHANT_APPLY_OUTCOME` (#3821), or undefined when it wrote nothing. A file that says something else is logged and ignored. */
1659
2429
  function readApplyOutcome(path, label, log) {
1660
2430
  if (!existsSync(path))
@@ -1687,6 +2457,7 @@ async function callApply(options, ctx, decision, runs, planned, argv, call, reco
1687
2457
  const filePath = `${dir}/${call.key}.json`;
1688
2458
  const resultPath = `${dir}/${call.key}-result.json`;
1689
2459
  const outcomePath = `${dir}/${call.key}-outcome.json`;
2460
+ const appliedRunsPath = `${dir}/${call.key}-runs-result.json`;
1690
2461
  const handed = {};
1691
2462
  if (byApply) {
1692
2463
  for (const m of ["before-apply", "after-apply"])
@@ -1706,7 +2477,7 @@ async function callApply(options, ctx, decision, runs, planned, argv, call, reco
1706
2477
  approved,
1707
2478
  ...(decision.heldBy?.length ? { heldBy: decision.heldBy } : {}),
1708
2479
  runBy: byApply ? "apply" : "chant",
1709
- runs: hookRuns(spec, k, runs, planned),
2480
+ runs: hookRuns(ctx, runs, planned),
1710
2481
  runsFile: call.runsPath,
1711
2482
  hooks: handed,
1712
2483
  outcomes: [...result.hooks],
@@ -1716,9 +2487,13 @@ async function callApply(options, ctx, decision, runs, planned, argv, call, reco
1716
2487
  writeFileSync(join(cwd, filePath), JSON.stringify(file, null, 2) + "\n");
1717
2488
  rmSync(join(cwd, resultPath), { force: true });
1718
2489
  rmSync(join(cwd, outcomePath), { force: true });
2490
+ if (call.wave)
2491
+ rmSync(join(cwd, appliedRunsPath), { force: true });
1719
2492
  let code;
1720
2493
  try {
1721
- code = exec(argv, cwd, { CHANT_HOOKS: filePath, CHANT_APPLY_OUTCOME: outcomePath, ...(byApply ? { CHANT_HOOKS_RESULT: resultPath } : {}) });
2494
+ const env = { CHANT_HOOKS: filePath, CHANT_APPLY_OUTCOME: outcomePath, ...(call.wave ? { CHANT_APPLY_RUNS_RESULT: appliedRunsPath } : {}), ...(byApply ? { CHANT_HOOKS_RESULT: resultPath } : {}) };
2495
+ // #4588: an applyWave its caller runs in process.
2496
+ code = call.wave && options.waveExec ? await options.waveExec(argv, cwd, env) : exec(argv, cwd, env);
1722
2497
  }
1723
2498
  catch (err) {
1724
2499
  log(`${call.label}: the apply did not run: ${err instanceof Error ? err.message : String(err)}`);
@@ -1740,8 +2515,13 @@ async function callApply(options, ctx, decision, runs, planned, argv, call, reco
1740
2515
  log(`${call.label}: the apply applied nothing: ${said.outcome}${said.reason ? ` (${said.reason})` : ""}${said.holder ? `, held by run ${said.holder.run}` : ""}`);
1741
2516
  return { outcome: "applied-nothing", said };
1742
2517
  }
2518
+ // #4291: a failed applyWave that says which runs applied fails only the others.
2519
+ const failedCall = () => {
2520
+ const applied = call.wave ? readAppliedRuns(join(cwd, appliedRunsPath), call.label, log) : undefined;
2521
+ return { outcome: "failed", ...(applied?.length ? { applied } : {}) };
2522
+ };
1743
2523
  if (!byApply)
1744
- return { outcome: code === 0 ? "applied" : "failed" };
2524
+ return code === 0 ? { outcome: "applied" } : failedCall();
1745
2525
  let back = null;
1746
2526
  try {
1747
2527
  back = JSON.parse(readFileSync(join(cwd, resultPath), "utf-8"));
@@ -1770,7 +2550,7 @@ async function callApply(options, ctx, decision, runs, planned, argv, call, reco
1770
2550
  if (afterFailed)
1771
2551
  return { outcome: "applied", problem: `${call.label} applied, and then the after-apply hook ${afterFailed.name} failed` };
1772
2552
  if (code !== 0)
1773
- return { outcome: "failed" };
2553
+ return failedCall();
1774
2554
  const skipped = ["before-apply", "after-apply"].filter((m) => handed[m] && !moments.includes(m));
1775
2555
  if (skipped.length > 0) {
1776
2556
  return { outcome: "applied", problem: `${call.label}: the apply exited 0 without running its ${skipped.join(" and ")} hooks (runOpWaveApplyHooks with CHANT_HOOKS), which the spec at base hands it` };
@@ -1806,13 +2586,78 @@ async function applyStage(options, ctx, decision, runs, planned, earlierHolds, r
1806
2586
  await runGateHooks(ctx, decision, recordPath);
1807
2587
  }
1808
2588
  result.decision = decision;
1809
- result.exitCode = 3;
2589
+ result.exitCode = CHANT_EXIT.waiting;
1810
2590
  return;
1811
2591
  }
1812
2592
  holds.push(...before.holds);
1813
2593
  }
1814
2594
  if (!(await settleHolds(options, ctx, decision, holds, recordPath)))
1815
2595
  return;
2596
+ // #4552: on the resource grain the wave holds the rows its runs change, before its approval is spent.
2597
+ const lease = spec.step ? await leaseWaveRows(options, ctx, runs) : undefined;
2598
+ if (lease && "failed" in lease) {
2599
+ failed(ctx, lease.failed);
2600
+ return;
2601
+ }
2602
+ if (lease && "outcome" in lease) {
2603
+ log(`wave ${k} (${wave.name}): applied nothing: ${lease.reason}`);
2604
+ result.outcome = lease;
2605
+ result.exitCode = CHANT_EXIT.held;
2606
+ if (recordPath)
2607
+ writeRecord(recordPath, decision, result);
2608
+ return;
2609
+ }
2610
+ try {
2611
+ // #4581: under the lease the grain took, a newer commit that applies the same targets makes this apply stand down.
2612
+ if (await standDownForNewer(options, ctx, decision, runs, recordPath))
2613
+ return;
2614
+ await applyLeased(options, ctx, decision, runs, planned, byApply, recordPath);
2615
+ }
2616
+ finally {
2617
+ if (lease && !(await lease.release()))
2618
+ log(`wave ${k} (${wave.name}): could not let go of the rows it held; the next apply takes them over once this run is gone`);
2619
+ }
2620
+ }
2621
+ /**
2622
+ * Stand down for a newer commit (#4581), when the spec's `standDown` (or
2623
+ * the job's option) asks: a newer commit on the branch whose spec at the
2624
+ * tip applies every one of `runs` in this wave makes the wave apply
2625
+ * nothing, with the `stood-down` outcome and exit 6. The approval is left
2626
+ * unspent. True when it stood down.
2627
+ */
2628
+ async function standDownForNewer(options, ctx, decision, runs, recordPath) {
2629
+ const { spec, k, wave, cwd, log, result } = ctx;
2630
+ if (!(options.standDown ?? spec.standDown === true))
2631
+ return false;
2632
+ const newer = await (options.newerCommit ?? gitOpWaveNewerCommit)(cwd, options.head);
2633
+ if (!newer)
2634
+ return false;
2635
+ const targets = runs.map((r) => r.target);
2636
+ let atTip;
2637
+ try {
2638
+ const { text } = (options.show ?? gitShowAtBase)(newer.tip, options.specFile.replace(/^\.\//, "").split("\\").join(posix.sep), cwd);
2639
+ atTip = text === null ? null : parseOpWavesSpec(text, `${options.specFile} at ${newer.tip.slice(0, 12)}`);
2640
+ }
2641
+ catch (err) {
2642
+ log(`wave ${k} (${wave.name}): ${newer.branch} has a newer commit ${newer.tip.slice(0, 12)}, and its spec cannot be read (${err instanceof Error ? err.message : String(err)}), so this job applies`);
2643
+ return false;
2644
+ }
2645
+ if (!tipAppliesTargets(atTip, newer.branch, wave.name, targets)) {
2646
+ log(`wave ${k} (${wave.name}): ${newer.branch} has a newer commit ${newer.tip.slice(0, 12)}, and its wave does not apply every target of this job, so this job applies`);
2647
+ return false;
2648
+ }
2649
+ const reason = opWaveStandDownReason(newer, targets);
2650
+ log(`wave ${k} (${wave.name}): standing down, nothing applied: ${reason}`);
2651
+ result.outcome = { outcome: "stood-down", reason };
2652
+ result.supersededBy = { branch: newer.branch, commit: newer.tip };
2653
+ result.exitCode = CHANT_EXIT.superseded;
2654
+ if (recordPath)
2655
+ writeRecord(recordPath, decision, result);
2656
+ return true;
2657
+ }
2658
+ /** {@link applyStage} once its holds are settled and, on the resource grain, its rows held. */
2659
+ async function applyLeased(options, ctx, decision, runs, planned, byApply, recordPath) {
2660
+ const { spec, k, wave, log, result } = ctx;
1816
2661
  if (!(await spendApproval(options, ctx, decision)))
1817
2662
  return;
1818
2663
  if (!(await spendOverrides(ctx, decision)))
@@ -1825,7 +2670,13 @@ async function applyStage(options, ctx, decision, runs, planned, earlierHolds, r
1825
2670
  if (spec.applyWave) {
1826
2671
  const runsPath = writeRunsFile(ctx, runs, planned, decision.digest);
1827
2672
  const argv = opWaveArgv(spec.applyWave, { op: spec.op, wave: wave.name, runs: runsPath, plans: opWavePlansPath(spec, k) });
1828
- const got = await callApply(options, ctx, decision, runs, planned, argv, { label: `wave ${k} (${wave.name})`, key: "hooks", runsPath }, recordPath);
2673
+ // #4555: one call applies every run, so each run's step spans that call.
2674
+ const startedMs = runs.map((r) => targetStarted(options, k, r.target))[0] ?? Date.now();
2675
+ const got = await callApply(options, ctx, decision, runs, planned, argv, { label: `wave ${k} (${wave.name})`, key: "hooks", runsPath, wave: true }, recordPath);
2676
+ const said = new Set(got.outcome === "failed" ? (got.applied ?? []) : []);
2677
+ const settle = (target) => (got.outcome === "applied" || said.has(target) ? "ok" : got.outcome === "failed" ? "failed" : "skipped");
2678
+ for (const r of runs)
2679
+ targetSettled(options, result, k, r.target, startedMs, settle(r.target));
1829
2680
  if (got.outcome === "applied-nothing")
1830
2681
  nothing = got.said;
1831
2682
  else if (got.outcome === "applied") {
@@ -1835,11 +2686,23 @@ async function applyStage(options, ctx, decision, runs, planned, earlierHolds, r
1835
2686
  }
1836
2687
  else if (got.outcome === "waiting")
1837
2688
  waiting = true;
2689
+ else if (said.size > 0) {
2690
+ // #4291: the apply said which runs applied, so a failure blocks only what depends on the others.
2691
+ const applied = runs.filter((r) => said.has(r.target)).map((r) => r.target);
2692
+ const failedRuns = runs.filter((r) => !said.has(r.target)).map((r) => r.target);
2693
+ log(`wave ${k} (${wave.name}): apply failed for ${failedRuns.join(", ")}; ${applied.join(", ")} applied`);
2694
+ result.applied.push(...applied);
2695
+ result.failed.push(...failedRuns);
2696
+ }
1838
2697
  else {
1839
2698
  log(`wave ${k} (${wave.name}): apply failed, so none of ${runs.map((r) => r.target).join(", ")} counts as applied`);
1840
2699
  result.failed.push(...runs.map((r) => r.target));
1841
2700
  }
1842
2701
  }
2702
+ else if (spec.step && (wave.parallelism ?? spec.parallelism ?? 1) > 1) {
2703
+ // #4625: the step's runs apply several at once.
2704
+ await applyStepRunsAtOnce(options, ctx, runs, wave.parallelism ?? spec.parallelism);
2705
+ }
1843
2706
  else {
1844
2707
  const order = new Map(runs.map((r, i) => [r.target, i]));
1845
2708
  for (const [i, run] of runs.entries()) {
@@ -1851,11 +2714,40 @@ async function applyStage(options, ctx, decision, runs, planned, earlierHolds, r
1851
2714
  log(`${run.target}: blocked by ${by}, so not applied`);
1852
2715
  continue;
1853
2716
  }
2717
+ if (spec.step) {
2718
+ // #4545: the run applies through its step, with the plan the gate decided.
2719
+ const plan = ctx.steps?.get(run.target);
2720
+ if (!plan) {
2721
+ log(`${run.target}: this job holds no plan of it to apply`);
2722
+ result.failed.push(run.target);
2723
+ continue;
2724
+ }
2725
+ const registry = await opWaveRegistry(options, ctx.cwd, options.capabilities);
2726
+ const startedMs = targetStarted(options, k, run.target);
2727
+ const got = await applyOpWaveStep({ spec, wave, registry }, run, plan);
2728
+ targetSettled(options, result, k, run.target, startedMs, got.outcome === "applied" ? "ok" : got.outcome === "moved" ? "skipped" : "failed", {
2729
+ ...(got.outcome !== "applied" ? { error: got.reason } : {}),
2730
+ ...(got.facts ? { facts: got.facts } : {}),
2731
+ });
2732
+ if (got.outcome === "applied")
2733
+ result.applied.push(run.target);
2734
+ else if (got.outcome === "moved") {
2735
+ log(`${run.target}: its plan moved since wave ${k} was decided, so it was not applied: ${got.reason}`);
2736
+ result.moved.push(run.target);
2737
+ }
2738
+ else {
2739
+ log(`${run.target}: apply failed: ${got.reason}`);
2740
+ result.failed.push(run.target);
2741
+ }
2742
+ continue;
2743
+ }
1854
2744
  const key = run.target.replace(/[^A-Za-z0-9._-]/g, "_");
1855
2745
  // Under runBy "apply" each run's apply runs its own apply-stage hooks, over a runs file of that run alone.
1856
2746
  const runsPath = byApply ? writeRunsFile(ctx, [run], planned, decision.digest, `.chant/op-waves/${spec.name}/wave-${k}/${key}.runs.json`) : opWaveRunsPath(spec, k);
1857
2747
  const argv = opWaveArgv(spec.apply ?? OP_WAVE_DEFAULT_APPLY, { op: run.op ?? spec.op, target: run.target, wave: wave.name, plan: opWavePlanPath(spec, k, run.target) });
2748
+ const startedMs = targetStarted(options, k, run.target);
1858
2749
  const got = await callApply(options, ctx, decision, [run], planned, argv, { label: run.target, key: `${key}.hooks`, runsPath }, recordPath);
2750
+ targetSettled(options, result, k, run.target, startedMs, got.outcome === "applied" ? "ok" : got.outcome === "failed" ? "failed" : "skipped");
1859
2751
  if (got.outcome === "applied-nothing") {
1860
2752
  nothing = got.said;
1861
2753
  break;
@@ -1875,6 +2767,8 @@ async function applyStage(options, ctx, decision, runs, planned, earlierHolds, r
1875
2767
  }
1876
2768
  }
1877
2769
  }
2770
+ if (spec.step)
2771
+ await recordStepReleases(options, ctx, decision, runs);
1878
2772
  if (recordPath && byApply)
1879
2773
  writeRecord(recordPath, decision, result);
1880
2774
  if (nothing) {
@@ -1884,19 +2778,24 @@ async function applyStage(options, ctx, decision, runs, planned, earlierHolds, r
1884
2778
  return;
1885
2779
  }
1886
2780
  result.outcome = nothing;
1887
- result.exitCode = nothing.outcome === "stood-down" ? 6 : 5;
2781
+ result.exitCode = nothing.outcome === "stood-down" ? CHANT_EXIT.superseded : CHANT_EXIT.held;
1888
2782
  if (recordPath)
1889
2783
  writeRecord(recordPath, decision, result);
1890
2784
  return;
1891
2785
  }
1892
2786
  if (waiting) {
1893
- result.exitCode = decision.status === "refused" ? refusedExit(decision) : 3;
2787
+ result.exitCode = decision.status === "refused" ? refusedExit(decision) : CHANT_EXIT.waiting;
1894
2788
  return;
1895
2789
  }
1896
2790
  if (result.failed.length > 0) {
1897
2791
  result.exitCode = 1;
1898
2792
  return;
1899
2793
  }
2794
+ // #4545: a run its step refused as moved applied nothing, so the wave exits moved and its after-apply hooks do not run.
2795
+ if (spec.step && result.moved.length > 0) {
2796
+ result.exitCode = CHANT_EXIT.moved;
2797
+ return;
2798
+ }
1900
2799
  if (problems.length > 0) {
1901
2800
  for (const p of problems)
1902
2801
  log(p);
@@ -1911,6 +2810,113 @@ async function applyStage(options, ctx, decision, runs, planned, earlierHolds, r
1911
2810
  if (recordPath && result.hooks.length > 0)
1912
2811
  writeRecord(recordPath, decision, result);
1913
2812
  }
2813
+ /**
2814
+ * A wave's step runs applied at most `limit` at once (#4625). A run waits
2815
+ * for each run the wave lists before it that it depends on, and is blocked,
2816
+ * as one at a time, when that one failed or was blocked. The outcomes land
2817
+ * in the result in the wave's order.
2818
+ */
2819
+ async function applyStepRunsAtOnce(options, ctx, runs, limit) {
2820
+ const { spec, k, wave, log, result } = ctx;
2821
+ const order = new Map(runs.map((r, i) => [r.target, i]));
2822
+ const registry = await opWaveRegistry(options, ctx.cwd, options.capabilities);
2823
+ const settled = new Map();
2824
+ const outcomes = await mapLimited(runs, limit, (run, i) => {
2825
+ const going = (async () => {
2826
+ const earlier = (run.dependsOn ?? []).filter((d) => (order.get(d) ?? Infinity) < i).sort();
2827
+ for (const dep of earlier) {
2828
+ const got = await settled.get(dep);
2829
+ if ("failed" in got || "blockedBy" in got) {
2830
+ const by = "blockedBy" in got ? got.blockedBy : dep;
2831
+ log(`${run.target}: blocked by ${by}, so not applied`);
2832
+ return { blockedBy: by };
2833
+ }
2834
+ }
2835
+ const plan = ctx.steps?.get(run.target);
2836
+ if (!plan) {
2837
+ log(`${run.target}: this job holds no plan of it to apply`);
2838
+ return { failed: true };
2839
+ }
2840
+ const startedMs = targetStarted(options, k, run.target);
2841
+ const got = await applyOpWaveStep({ spec, wave, registry }, run, plan);
2842
+ targetSettled(options, result, k, run.target, startedMs, got.outcome === "applied" ? "ok" : got.outcome === "moved" ? "skipped" : "failed", {
2843
+ ...(got.outcome !== "applied" ? { error: got.reason } : {}),
2844
+ ...(got.facts ? { facts: got.facts } : {}),
2845
+ });
2846
+ if (got.outcome === "applied")
2847
+ return { applied: true };
2848
+ if (got.outcome === "moved") {
2849
+ log(`${run.target}: its plan moved since wave ${k} was decided, so it was not applied: ${got.reason}`);
2850
+ return { moved: true };
2851
+ }
2852
+ log(`${run.target}: apply failed: ${got.reason}`);
2853
+ return { failed: true };
2854
+ })();
2855
+ settled.set(run.target, going);
2856
+ return going;
2857
+ });
2858
+ for (const [i, got] of outcomes.entries()) {
2859
+ const target = runs[i].target;
2860
+ if ("applied" in got)
2861
+ result.applied.push(target);
2862
+ else if ("moved" in got)
2863
+ result.moved.push(target);
2864
+ else if ("failed" in got)
2865
+ result.failed.push(target);
2866
+ else
2867
+ result.blocked = { ...result.blocked, [target]: got.blockedBy };
2868
+ }
2869
+ }
2870
+ /**
2871
+ * The release records of the runs this wave applied through its step
2872
+ * (#4615), one per run, on the environment ledger each names. A record that
2873
+ * is not written is a line in the log; the job's exit code stays.
2874
+ */
2875
+ async function recordStepReleases(options, ctx, decision, runs) {
2876
+ const { spec, k, wave, log, result } = ctx;
2877
+ if (options.releases === false)
2878
+ return;
2879
+ const port = options.releases ?? (options.gates ? undefined : gitOpWaveReleasePort({ cwd: ctx.cwd }));
2880
+ if (!port)
2881
+ return;
2882
+ const applied = new Set(result.applied);
2883
+ let gitSha = options.head;
2884
+ const requests = [];
2885
+ for (const run of runs) {
2886
+ if (!applied.has(run.target))
2887
+ continue;
2888
+ const names = opWaveReleaseNames(spec, wave, run);
2889
+ const plan = ctx.steps?.get(run.target);
2890
+ if (!names || !plan)
2891
+ continue;
2892
+ if (gitSha === undefined) {
2893
+ try {
2894
+ gitSha = execFileSync("git", ["rev-parse", "HEAD"], { cwd: ctx.cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
2895
+ }
2896
+ catch {
2897
+ gitSha = "";
2898
+ }
2899
+ }
2900
+ requests.push({ ...names, target: run.target, planDigest: plan.planDigest, ...(gitSha ? { gitSha } : {}), ...(decision.approvedBy ? { approver: decision.approvedBy } : {}) });
2901
+ }
2902
+ if (requests.length === 0)
2903
+ return;
2904
+ let outcomes;
2905
+ try {
2906
+ outcomes = await port.record(requests);
2907
+ }
2908
+ catch (err) {
2909
+ log(`wave ${k} (${wave.name}): applied, and no release record was written: ${err instanceof Error ? err.message : String(err)}`);
2910
+ return;
2911
+ }
2912
+ for (const [i, req] of requests.entries()) {
2913
+ const got = outcomes[i];
2914
+ if (got?.recorded)
2915
+ log(`${req.target}: recorded on the "${got.env}" release ledger as ${got.component} ${got.digest}${got.releaseDigest ? ` under release ${got.releaseDigest}` : ""}`);
2916
+ else
2917
+ log(`${req.target}: applied, and no release record was written for ${req.component} in "${req.env}": ${got?.reason ?? "the port gave no answer"}`);
2918
+ }
2919
+ }
1914
2920
  /**
1915
2921
  * Record that the wave applies under its approval (#3784), which spends it:
1916
2922
  * one line in `_gates/<name>/applied.jsonl`, before anything applies, as
@@ -2014,7 +3020,8 @@ async function readHeadPlans(name, head, cwd) {
2014
3020
  * pull request's head and record each wave's digest on `chant/lifecycle`,
2015
3021
  * `_wave-plans/<name>/<head>.json`. A `pr-review` wave reads it after the
2016
3022
  * merge: the review of that head approves the digests it planned, and only
2017
- * those.
3023
+ * those. A wave whose plans file gives a change set records its digest and
3024
+ * stores it (#4630), for the approval status of a `pull-request` wave.
2018
3025
  */
2019
3026
  export async function recordOpWaveHeadPlans(options) {
2020
3027
  const { spec } = options;
@@ -2030,18 +3037,43 @@ export async function recordOpWaveHeadPlans(options) {
2030
3037
  timestamp: options.now ?? new Date().toISOString(),
2031
3038
  waves: [],
2032
3039
  };
3040
+ const changeSets = [];
2033
3041
  // A `rest` wave (#3821) goes on through the waves the plan command found.
2034
3042
  const last = spec.waves[spec.waves.length - 1];
2035
3043
  for (let k = 1;; k++) {
2036
3044
  const wave = spec.waves[k - 1] ?? last;
2037
- const { members, extras, waves: found } = planRuns({ spec, k, wave, cwd, exec }, wave.runs, wave.discover === true);
2038
- plans.waves.push({ wave: k, name: wave.name, digest: opWaveSetDigest(spec, members, extras) });
3045
+ const steps = new Map();
3046
+ const { members, extras: planExtras, waves: found, changeSet } = await planWaveRuns({ spec, k, wave, cwd, exec, options, steps }, wave.runs, wave.discover === true);
3047
+ // #4545: a cost hold's member is in the digest the merged wave decides, so the head's digest carries it too.
3048
+ const cost = spec.holds?.cost ? costVerdictOf(spec.holds.cost, spec, k, members, steps, cwd, options.holdExec).member : undefined;
3049
+ const extras = cost ? [...(planExtras ?? []), cost] : planExtras;
3050
+ // #4630: the facts a gate policy reads, so the approval status before merge says which waves will wait.
3051
+ plans.waves.push({
3052
+ wave: k,
3053
+ name: wave.name,
3054
+ digest: opWaveSetDigest(spec, members, extras),
3055
+ changes: !members.every((m) => m.empty === true),
3056
+ destructive: members.some((m) => m.destructive === true),
3057
+ // #4630: a pull-request wave's change set, which the pull request's own approval must cover.
3058
+ ...(changeSet ? { changeSet: changeSet.digest } : {}),
3059
+ });
3060
+ if (changeSet)
3061
+ changeSets.push(changeSet);
2039
3062
  if (k >= spec.waves.length && !(last.rest && found !== undefined && k < found))
2040
3063
  break;
2041
3064
  }
3065
+ // The change sets go on the ledger first, so the record's push carries them.
3066
+ for (const doc of changeSets)
3067
+ await (options.storeChangeSet ?? ((d) => storeHeadChangeSet(d, cwd)))(doc);
2042
3068
  await (options.write ?? ((p) => writeHeadPlans(p, cwd)))(plans);
2043
3069
  return plans;
2044
3070
  }
3071
+ async function storeHeadChangeSet(doc, cwd) {
3072
+ const { requireLifecycleLedger } = await import("../lifecycle/git.js");
3073
+ const { persistChangeSet } = await import("../lifecycle/change-set-store.js");
3074
+ await requireLifecycleLedger({ cwd });
3075
+ await persistChangeSet(doc, { cwd });
3076
+ }
2045
3077
  async function writeHeadPlans(plans, cwd) {
2046
3078
  const { pushLifecycle, requireLifecycleLedger, writeBlobToPath } = await import("../lifecycle/git.js");
2047
3079
  const { headPlansPath } = await import("./gate-review.js");