@intentius/chant 0.124.54 → 0.124.55

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 (894) 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 +833 -0
  71. package/dist/ci-control.d.ts +42 -0
  72. package/dist/ci-control.d.ts.map +1 -0
  73. package/dist/ci-control.js +42 -0
  74. package/dist/ci-estate/delivery.d.ts +137 -0
  75. package/dist/ci-estate/delivery.d.ts.map +1 -0
  76. package/dist/ci-estate/delivery.js +311 -0
  77. package/dist/ci-estate/overdue.d.ts +34 -0
  78. package/dist/ci-estate/overdue.d.ts.map +1 -0
  79. package/dist/ci-estate/overdue.js +58 -0
  80. package/dist/ci-estate/page.d.ts +134 -0
  81. package/dist/ci-estate/page.d.ts.map +1 -0
  82. package/dist/ci-estate/page.js +233 -0
  83. package/dist/ci-estate/rows.d.ts +118 -0
  84. package/dist/ci-estate/rows.d.ts.map +1 -0
  85. package/dist/ci-estate/rows.js +126 -0
  86. package/dist/ci-estate.d.ts +68 -0
  87. package/dist/ci-estate.d.ts.map +1 -0
  88. package/dist/ci-estate.js +83 -0
  89. package/dist/ci-handover.d.ts +29 -5
  90. package/dist/ci-handover.d.ts.map +1 -1
  91. package/dist/ci-handover.js +50 -16
  92. package/dist/ci-identity.d.ts +82 -7
  93. package/dist/ci-identity.d.ts.map +1 -1
  94. package/dist/ci-identity.js +87 -15
  95. package/dist/ci-product-words.d.ts +290 -0
  96. package/dist/ci-product-words.d.ts.map +1 -0
  97. package/dist/ci-product-words.js +373 -0
  98. package/dist/ci-product.d.ts +82 -0
  99. package/dist/ci-product.d.ts.map +1 -0
  100. package/dist/ci-product.js +78 -0
  101. package/dist/cli/commands/audit.d.ts +2 -2
  102. package/dist/cli/commands/audit.d.ts.map +1 -1
  103. package/dist/cli/commands/audit.js +3 -2
  104. package/dist/cli/commands/carve.js +2 -2
  105. package/dist/cli/commands/init.d.ts +2 -0
  106. package/dist/cli/commands/init.d.ts.map +1 -1
  107. package/dist/cli/commands/init.js +1 -1
  108. package/dist/cli/handlers/agent.d.ts +17 -0
  109. package/dist/cli/handlers/agent.d.ts.map +1 -0
  110. package/dist/cli/handlers/agent.js +114 -0
  111. package/dist/cli/handlers/approve-confirm.d.ts +84 -0
  112. package/dist/cli/handlers/approve-confirm.d.ts.map +1 -0
  113. package/dist/cli/handlers/approve-confirm.js +142 -0
  114. package/dist/cli/handlers/approve.d.ts.map +1 -1
  115. package/dist/cli/handlers/approve.js +19 -1
  116. package/dist/cli/handlers/build.d.ts.map +1 -1
  117. package/dist/cli/handlers/build.js +43 -1
  118. package/dist/cli/handlers/ci-check.d.ts +3 -0
  119. package/dist/cli/handlers/ci-check.d.ts.map +1 -0
  120. package/dist/cli/handlers/ci-check.js +34 -0
  121. package/dist/cli/handlers/ci-forge-check.d.ts +3 -0
  122. package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -0
  123. package/dist/cli/handlers/ci-forge-check.js +89 -0
  124. package/dist/cli/handlers/fan-out.js +4 -0
  125. package/dist/cli/handlers/gate-pending.d.ts +11 -0
  126. package/dist/cli/handlers/gate-pending.d.ts.map +1 -0
  127. package/dist/cli/handlers/gate-pending.js +44 -0
  128. package/dist/cli/handlers/init.d.ts.map +1 -1
  129. package/dist/cli/handlers/init.js +1 -0
  130. package/dist/cli/handlers/ledger.js +1 -1
  131. package/dist/cli/handlers/lifecycle-drift.d.ts +6 -2
  132. package/dist/cli/handlers/lifecycle-drift.d.ts.map +1 -1
  133. package/dist/cli/handlers/lifecycle-drift.js +7 -2
  134. package/dist/cli/handlers/lock.d.ts.map +1 -1
  135. package/dist/cli/handlers/lock.js +64 -5
  136. package/dist/cli/handlers/notify-relay.d.ts +15 -0
  137. package/dist/cli/handlers/notify-relay.d.ts.map +1 -0
  138. package/dist/cli/handlers/notify-relay.js +130 -0
  139. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  140. package/dist/cli/handlers/pr-env.js +42 -11
  141. package/dist/cli/handlers/pr.d.ts +38 -3
  142. package/dist/cli/handlers/pr.d.ts.map +1 -1
  143. package/dist/cli/handlers/pr.js +653 -205
  144. package/dist/cli/handlers/promote.d.ts.map +1 -1
  145. package/dist/cli/handlers/promote.js +21 -2
  146. package/dist/cli/handlers/release.d.ts.map +1 -1
  147. package/dist/cli/handlers/release.js +3 -0
  148. package/dist/cli/handlers/run-wave.d.ts +8 -0
  149. package/dist/cli/handlers/run-wave.d.ts.map +1 -1
  150. package/dist/cli/handlers/run-wave.js +71 -1
  151. package/dist/cli/handlers/run.d.ts +6 -1
  152. package/dist/cli/handlers/run.d.ts.map +1 -1
  153. package/dist/cli/handlers/run.js +86 -1
  154. package/dist/cli/handlers/serve.d.ts.map +1 -1
  155. package/dist/cli/handlers/serve.js +10 -1
  156. package/dist/cli/main.d.ts +11 -1
  157. package/dist/cli/main.d.ts.map +1 -1
  158. package/dist/cli/main.js +124 -13
  159. package/dist/cli/mcp/ledger-tools.d.ts +36 -0
  160. package/dist/cli/mcp/ledger-tools.d.ts.map +1 -0
  161. package/dist/cli/mcp/ledger-tools.js +122 -0
  162. package/dist/cli/mcp/product-tools.d.ts +78 -0
  163. package/dist/cli/mcp/product-tools.d.ts.map +1 -0
  164. package/dist/cli/mcp/product-tools.js +93 -0
  165. package/dist/cli/mcp/read-only.d.ts +34 -0
  166. package/dist/cli/mcp/read-only.d.ts.map +1 -0
  167. package/dist/cli/mcp/read-only.js +61 -0
  168. package/dist/cli/mcp/report-tools.d.ts +48 -0
  169. package/dist/cli/mcp/report-tools.d.ts.map +1 -0
  170. package/dist/cli/mcp/report-tools.js +128 -0
  171. package/dist/cli/mcp/server.d.ts +28 -1
  172. package/dist/cli/mcp/server.d.ts.map +1 -1
  173. package/dist/cli/mcp/server.js +86 -15
  174. package/dist/cli/mcp-config.d.ts +9 -2
  175. package/dist/cli/mcp-config.d.ts.map +1 -1
  176. package/dist/cli/mcp-config.js +8 -3
  177. package/dist/cli/parse-args.d.ts.map +1 -1
  178. package/dist/cli/parse-args.js +57 -3
  179. package/dist/cli/registry.d.ts +35 -0
  180. package/dist/cli/registry.d.ts.map +1 -1
  181. package/dist/cloud-lister/sigv4.d.ts +42 -7
  182. package/dist/cloud-lister/sigv4.d.ts.map +1 -1
  183. package/dist/cloud-lister/sigv4.js +72 -22
  184. package/dist/components/adoption.d.ts +69 -0
  185. package/dist/components/adoption.d.ts.map +1 -0
  186. package/dist/components/adoption.js +93 -0
  187. package/dist/components/apply-lease.d.ts +19 -0
  188. package/dist/components/apply-lease.d.ts.map +1 -0
  189. package/dist/components/apply-lease.js +41 -0
  190. package/dist/components/capability.d.ts +122 -5
  191. package/dist/components/capability.d.ts.map +1 -1
  192. package/dist/components/capability.js +14 -6
  193. package/dist/components/check-hooks.d.ts +113 -0
  194. package/dist/components/check-hooks.d.ts.map +1 -0
  195. package/dist/components/check-hooks.js +192 -0
  196. package/dist/components/ci-services.d.ts +57 -0
  197. package/dist/components/ci-services.d.ts.map +1 -0
  198. package/dist/components/ci-services.js +61 -0
  199. package/dist/components/cli-support.d.ts +13 -0
  200. package/dist/components/cli-support.d.ts.map +1 -1
  201. package/dist/components/cli-support.js +10 -2
  202. package/dist/components/driver.d.ts +20 -3
  203. package/dist/components/driver.d.ts.map +1 -1
  204. package/dist/components/driver.js +24 -4
  205. package/dist/components/fan-out-run.d.ts +12 -0
  206. package/dist/components/fan-out-run.d.ts.map +1 -1
  207. package/dist/components/fan-out-run.js +56 -16
  208. package/dist/components/groups.d.ts.map +1 -1
  209. package/dist/components/groups.js +19 -2
  210. package/dist/components/pr-env-ledger.d.ts +32 -0
  211. package/dist/components/pr-env-ledger.d.ts.map +1 -0
  212. package/dist/components/pr-env-ledger.js +39 -0
  213. package/dist/components/pr-env-ports.d.ts +12 -0
  214. package/dist/components/pr-env-ports.d.ts.map +1 -1
  215. package/dist/components/pr-env-ports.js +13 -3
  216. package/dist/components/pr-env-run.d.ts +6 -0
  217. package/dist/components/pr-env-run.d.ts.map +1 -1
  218. package/dist/components/pr-env-run.js +3 -2
  219. package/dist/components/pr-environment.d.ts +31 -3
  220. package/dist/components/pr-environment.d.ts.map +1 -1
  221. package/dist/components/pr-environment.js +25 -7
  222. package/dist/components/pr-pipeline.d.ts +169 -3
  223. package/dist/components/pr-pipeline.d.ts.map +1 -1
  224. package/dist/components/pr-pipeline.js +184 -9
  225. package/dist/components/pr-policy.d.ts +26 -2
  226. package/dist/components/pr-policy.d.ts.map +1 -1
  227. package/dist/components/pr-policy.js +41 -7
  228. package/dist/components/pr-run.d.ts +63 -0
  229. package/dist/components/pr-run.d.ts.map +1 -1
  230. package/dist/components/pr-run.js +82 -3
  231. package/dist/components/pr-targets.d.ts +24 -0
  232. package/dist/components/pr-targets.d.ts.map +1 -0
  233. package/dist/components/pr-targets.js +48 -0
  234. package/dist/components/product-pipeline.d.ts +217 -0
  235. package/dist/components/product-pipeline.d.ts.map +1 -0
  236. package/dist/components/product-pipeline.js +193 -0
  237. package/dist/components/promote.d.ts +6 -0
  238. package/dist/components/promote.d.ts.map +1 -1
  239. package/dist/components/promote.js +4 -1
  240. package/dist/components/release-compile.d.ts +22 -1
  241. package/dist/components/release-compile.d.ts.map +1 -1
  242. package/dist/components/release-compile.js +85 -0
  243. package/dist/components/release-promote.d.ts +15 -1
  244. package/dist/components/release-promote.d.ts.map +1 -1
  245. package/dist/components/release-promote.js +67 -2
  246. package/dist/components/repo-lock.d.ts +27 -0
  247. package/dist/components/repo-lock.d.ts.map +1 -0
  248. package/dist/components/repo-lock.js +49 -0
  249. package/dist/components/row-lease.d.ts +84 -0
  250. package/dist/components/row-lease.d.ts.map +1 -0
  251. package/dist/components/row-lease.js +110 -0
  252. package/dist/components/wave-plan.d.ts +34 -0
  253. package/dist/components/wave-plan.d.ts.map +1 -1
  254. package/dist/components/wave-plan.js +54 -2
  255. package/dist/control/applied.d.ts +89 -0
  256. package/dist/control/applied.d.ts.map +1 -0
  257. package/dist/control/applied.js +175 -0
  258. package/dist/control/consumers.d.ts +78 -0
  259. package/dist/control/consumers.d.ts.map +1 -0
  260. package/dist/control/consumers.js +172 -0
  261. package/dist/control/dispatch.d.ts +334 -0
  262. package/dist/control/dispatch.d.ts.map +1 -0
  263. package/dist/control/dispatch.js +519 -0
  264. package/dist/control/edges.d.ts +75 -0
  265. package/dist/control/edges.d.ts.map +1 -0
  266. package/dist/control/edges.js +133 -0
  267. package/dist/control/reconcile.d.ts +120 -0
  268. package/dist/control/reconcile.d.ts.map +1 -0
  269. package/dist/control/reconcile.js +178 -0
  270. package/dist/control/records.d.ts +187 -0
  271. package/dist/control/records.d.ts.map +1 -0
  272. package/dist/control/records.js +307 -0
  273. package/dist/discovery/sandbox/bundle.d.ts.map +1 -1
  274. package/dist/discovery/sandbox/bundle.js +25 -1
  275. package/dist/engine-facts.d.ts.map +1 -1
  276. package/dist/engine-facts.js +1 -2
  277. package/dist/exit-codes.d.ts +48 -0
  278. package/dist/exit-codes.d.ts.map +1 -0
  279. package/dist/exit-codes.js +49 -0
  280. package/dist/forge-check/check.d.ts +63 -0
  281. package/dist/forge-check/check.d.ts.map +1 -0
  282. package/dist/forge-check/check.js +139 -0
  283. package/dist/forge-check/contract.d.ts +152 -0
  284. package/dist/forge-check/contract.d.ts.map +1 -0
  285. package/dist/forge-check/contract.js +118 -0
  286. package/dist/forge-check/forge.d.ts +42 -0
  287. package/dist/forge-check/forge.d.ts.map +1 -0
  288. package/dist/forge-check/forge.js +338 -0
  289. package/dist/forge-check/index.d.ts +24 -0
  290. package/dist/forge-check/index.d.ts.map +1 -0
  291. package/dist/forge-check/index.js +23 -0
  292. package/dist/forge-check/pulumi.d.ts +44 -0
  293. package/dist/forge-check/pulumi.d.ts.map +1 -0
  294. package/dist/forge-check/pulumi.js +184 -0
  295. package/dist/forge-check/read-only.d.ts +26 -0
  296. package/dist/forge-check/read-only.d.ts.map +1 -0
  297. package/dist/forge-check/read-only.js +53 -0
  298. package/dist/forge-check/trust.d.ts +94 -0
  299. package/dist/forge-check/trust.d.ts.map +1 -0
  300. package/dist/forge-check/trust.js +532 -0
  301. package/dist/forge-check/types.d.ts +80 -0
  302. package/dist/forge-check/types.d.ts.map +1 -0
  303. package/dist/forge-check/types.js +18 -0
  304. package/dist/forge-check.d.ts +6 -0
  305. package/dist/forge-check.d.ts.map +1 -0
  306. package/dist/forge-check.js +5 -0
  307. package/dist/gate-decision.d.ts +1 -0
  308. package/dist/gate-decision.d.ts.map +1 -1
  309. package/dist/gate-decision.js +2 -0
  310. package/dist/gate-policy.d.ts +47 -1
  311. package/dist/gate-policy.d.ts.map +1 -1
  312. package/dist/gate-policy.js +50 -2
  313. package/dist/index.d.ts +1 -0
  314. package/dist/index.d.ts.map +1 -1
  315. package/dist/index.js +2 -0
  316. package/dist/lexicon.d.ts +106 -6
  317. package/dist/lexicon.d.ts.map +1 -1
  318. package/dist/lifecycle/adoption-file.d.ts +24 -0
  319. package/dist/lifecycle/adoption-file.d.ts.map +1 -1
  320. package/dist/lifecycle/adoption-file.js +1 -2
  321. package/dist/lifecycle/cloud-index.d.ts.map +1 -1
  322. package/dist/lifecycle/cloud-index.js +1 -2
  323. package/dist/lifecycle/gate-applied.d.ts +6 -0
  324. package/dist/lifecycle/gate-applied.d.ts.map +1 -1
  325. package/dist/lifecycle/gate-ledger.d.ts +29 -0
  326. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  327. package/dist/lifecycle/gate-ledger.js +11 -1
  328. package/dist/lifecycle/gate-pending-by-plan.d.ts +75 -0
  329. package/dist/lifecycle/gate-pending-by-plan.d.ts.map +1 -0
  330. package/dist/lifecycle/gate-pending-by-plan.js +96 -0
  331. package/dist/lifecycle/gated-request-digest.d.ts +28 -0
  332. package/dist/lifecycle/gated-request-digest.d.ts.map +1 -0
  333. package/dist/lifecycle/gated-request-digest.js +35 -0
  334. package/dist/lifecycle/gated-request.d.ts +126 -0
  335. package/dist/lifecycle/gated-request.d.ts.map +1 -0
  336. package/dist/lifecycle/gated-request.js +205 -0
  337. package/dist/lifecycle/identity-match.d.ts +15 -0
  338. package/dist/lifecycle/identity-match.d.ts.map +1 -1
  339. package/dist/lifecycle/identity-match.js +11 -6
  340. package/dist/lifecycle/index-diff.d.ts +40 -0
  341. package/dist/lifecycle/index-diff.d.ts.map +1 -1
  342. package/dist/lifecycle/index-diff.js +1 -2
  343. package/dist/lifecycle/index-document.d.ts.map +1 -1
  344. package/dist/lifecycle/index-document.js +1 -2
  345. package/dist/lifecycle/index-import.d.ts +4 -1
  346. package/dist/lifecycle/index-import.d.ts.map +1 -1
  347. package/dist/lifecycle/index-import.js +29 -32
  348. package/dist/lifecycle/ledger-read.d.ts.map +1 -1
  349. package/dist/lifecycle/ledger-read.js +7 -3
  350. package/dist/lifecycle/lock-rows.d.ts +76 -0
  351. package/dist/lifecycle/lock-rows.d.ts.map +1 -0
  352. package/dist/lifecycle/lock-rows.js +140 -0
  353. package/dist/lifecycle/query.d.ts +50 -3
  354. package/dist/lifecycle/query.d.ts.map +1 -1
  355. package/dist/lifecycle/query.js +97 -6
  356. package/dist/lifecycle/release-catalog-site.d.ts +66 -0
  357. package/dist/lifecycle/release-catalog-site.d.ts.map +1 -0
  358. package/dist/lifecycle/release-catalog-site.js +232 -0
  359. package/dist/lifecycle/release-catalog.d.ts +201 -0
  360. package/dist/lifecycle/release-catalog.d.ts.map +1 -0
  361. package/dist/lifecycle/release-catalog.js +198 -0
  362. package/dist/lifecycle/release-changelog.d.ts +41 -0
  363. package/dist/lifecycle/release-changelog.d.ts.map +1 -0
  364. package/dist/lifecycle/release-changelog.js +38 -0
  365. package/dist/lifecycle/release-cut.d.ts +1 -0
  366. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  367. package/dist/lifecycle/release-cut.js +1 -1
  368. package/dist/lifecycle/release-ledger.d.ts +16 -0
  369. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  370. package/dist/lifecycle/release-ledger.js +10 -0
  371. package/dist/lifecycle/release-publish.d.ts +43 -22
  372. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  373. package/dist/lifecycle/release-read.d.ts.map +1 -1
  374. package/dist/lifecycle/release-read.js +3 -0
  375. package/dist/lifecycle/release-status.d.ts +86 -0
  376. package/dist/lifecycle/release-status.d.ts.map +1 -0
  377. package/dist/lifecycle/release-status.js +136 -0
  378. package/dist/lifecycle/resource-lock.d.ts +120 -0
  379. package/dist/lifecycle/resource-lock.d.ts.map +1 -0
  380. package/dist/lifecycle/resource-lock.js +317 -0
  381. package/dist/lifecycle/retention.d.ts.map +1 -1
  382. package/dist/lifecycle/retention.js +3 -0
  383. package/dist/lifecycle/run-ledger.d.ts.map +1 -1
  384. package/dist/lifecycle/run-ledger.js +9 -1
  385. package/dist/lifecycle/snapshot-store-s3.d.ts +36 -3
  386. package/dist/lifecycle/snapshot-store-s3.d.ts.map +1 -1
  387. package/dist/lifecycle/snapshot-store-s3.js +9 -44
  388. package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
  389. package/dist/lifecycle/snapshot-store.js +1 -2
  390. package/dist/lifecycle/target-lock.d.ts +15 -0
  391. package/dist/lifecycle/target-lock.d.ts.map +1 -1
  392. package/dist/lifecycle/target-lock.js +25 -10
  393. package/dist/mcp/types.d.ts +7 -0
  394. package/dist/mcp/types.d.ts.map +1 -1
  395. package/dist/notify-product.d.ts +43 -0
  396. package/dist/notify-product.d.ts.map +1 -0
  397. package/dist/notify-product.js +58 -0
  398. package/dist/notify-relay.d.ts +197 -0
  399. package/dist/notify-relay.d.ts.map +1 -0
  400. package/dist/notify-relay.js +321 -0
  401. package/dist/notify.d.ts +44 -4
  402. package/dist/notify.d.ts.map +1 -1
  403. package/dist/notify.js +77 -14
  404. package/dist/object-store/azure-blob.d.ts +129 -0
  405. package/dist/object-store/azure-blob.d.ts.map +1 -0
  406. package/dist/object-store/azure-blob.js +341 -0
  407. package/dist/object-store/common.d.ts +108 -0
  408. package/dist/object-store/common.d.ts.map +1 -0
  409. package/dist/object-store/common.js +80 -0
  410. package/dist/object-store/errors.d.ts +28 -0
  411. package/dist/object-store/errors.d.ts.map +1 -0
  412. package/dist/object-store/errors.js +21 -0
  413. package/dist/object-store/from-env.d.ts +18 -0
  414. package/dist/object-store/from-env.d.ts.map +1 -0
  415. package/dist/object-store/from-env.js +22 -0
  416. package/dist/object-store/gcs.d.ts +106 -0
  417. package/dist/object-store/gcs.d.ts.map +1 -0
  418. package/dist/object-store/gcs.js +393 -0
  419. package/dist/object-store/index.d.ts +9 -0
  420. package/dist/object-store/index.d.ts.map +1 -0
  421. package/dist/object-store/index.js +8 -0
  422. package/dist/object-store/s3.d.ts +146 -0
  423. package/dist/object-store/s3.d.ts.map +1 -0
  424. package/dist/object-store/s3.js +306 -0
  425. package/dist/op/activities/converge.d.ts.map +1 -1
  426. package/dist/op/activities/converge.js +2 -1
  427. package/dist/op/activities/index.d.ts +1 -1
  428. package/dist/op/activities/index.d.ts.map +1 -1
  429. package/dist/op/activities/index.js +1 -1
  430. package/dist/op/activities/review-agent.d.ts +55 -2
  431. package/dist/op/activities/review-agent.d.ts.map +1 -1
  432. package/dist/op/activities/review-agent.js +65 -5
  433. package/dist/op/gate.d.ts +29 -1
  434. package/dist/op/gate.d.ts.map +1 -1
  435. package/dist/op/gate.js +59 -23
  436. package/dist/op/generate-pipeline.d.ts.map +1 -1
  437. package/dist/op/generate-pipeline.js +7 -1
  438. package/dist/op/index.d.ts +12 -1
  439. package/dist/op/index.d.ts.map +1 -1
  440. package/dist/op/index.js +7 -1
  441. package/dist/op/op-waves-after-plan.d.ts +137 -0
  442. package/dist/op/op-waves-after-plan.d.ts.map +1 -0
  443. package/dist/op/op-waves-after-plan.js +163 -0
  444. package/dist/op/op-waves-capability-spec.d.ts +55 -0
  445. package/dist/op/op-waves-capability-spec.d.ts.map +1 -0
  446. package/dist/op/op-waves-capability-spec.js +94 -0
  447. package/dist/op/op-waves-capability.d.ts +197 -0
  448. package/dist/op/op-waves-capability.d.ts.map +1 -0
  449. package/dist/op/op-waves-capability.js +311 -0
  450. package/dist/op/op-waves-events.d.ts +54 -0
  451. package/dist/op/op-waves-events.d.ts.map +1 -0
  452. package/dist/op/op-waves-events.js +122 -0
  453. package/dist/op/op-waves-notify.d.ts +7 -1
  454. package/dist/op/op-waves-notify.d.ts.map +1 -1
  455. package/dist/op/op-waves-notify.js +35 -16
  456. package/dist/op/op-waves-release-port.d.ts +18 -0
  457. package/dist/op/op-waves-release-port.d.ts.map +1 -0
  458. package/dist/op/op-waves-release-port.js +61 -0
  459. package/dist/op/op-waves-release.d.ts +92 -0
  460. package/dist/op/op-waves-release.d.ts.map +1 -0
  461. package/dist/op/op-waves-release.js +97 -0
  462. package/dist/op/op-waves-run.d.ts +175 -4
  463. package/dist/op/op-waves-run.d.ts.map +1 -1
  464. package/dist/op/op-waves-run.js +981 -41
  465. package/dist/op/op-waves-stand-down.d.ts +60 -0
  466. package/dist/op/op-waves-stand-down.d.ts.map +1 -0
  467. package/dist/op/op-waves-stand-down.js +97 -0
  468. package/dist/op/op-waves.d.ts +152 -8
  469. package/dist/op/op-waves.d.ts.map +1 -1
  470. package/dist/op/op-waves.js +161 -17
  471. package/dist/op/runtime.d.ts +91 -0
  472. package/dist/op/runtime.d.ts.map +1 -1
  473. package/dist/op/runtime.js +19 -0
  474. package/dist/op/stage-hooks.d.ts +45 -7
  475. package/dist/op/stage-hooks.d.ts.map +1 -1
  476. package/dist/op/stage-hooks.js +61 -3
  477. package/dist/op/steward-beside.d.ts.map +1 -1
  478. package/dist/op/steward-beside.js +2 -1
  479. package/dist/op/types.d.ts +2 -2
  480. package/dist/op/types.d.ts.map +1 -1
  481. package/dist/op/types.js +3 -2
  482. package/dist/otlp-metrics.d.ts +38 -0
  483. package/dist/otlp-metrics.d.ts.map +1 -0
  484. package/dist/otlp-metrics.js +82 -0
  485. package/dist/otlp.d.ts +249 -0
  486. package/dist/otlp.d.ts.map +1 -0
  487. package/dist/otlp.js +426 -0
  488. package/dist/override-gate.d.ts.map +1 -1
  489. package/dist/override-gate.js +5 -0
  490. package/dist/policy-packs.d.ts +69 -0
  491. package/dist/policy-packs.d.ts.map +1 -0
  492. package/dist/policy-packs.js +205 -0
  493. package/dist/policy-source.d.ts +51 -0
  494. package/dist/policy-source.d.ts.map +1 -0
  495. package/dist/policy-source.js +103 -0
  496. package/dist/pr-forge.d.ts +40 -0
  497. package/dist/pr-forge.d.ts.map +1 -1
  498. package/dist/pr-forge.js +92 -0
  499. package/dist/pr-loop.d.ts +149 -11
  500. package/dist/pr-loop.d.ts.map +1 -1
  501. package/dist/pr-loop.js +283 -44
  502. package/dist/pr-post.d.ts +16 -0
  503. package/dist/pr-post.d.ts.map +1 -1
  504. package/dist/pr-post.js +26 -1
  505. package/dist/pr-report-url.d.ts +32 -4
  506. package/dist/pr-report-url.d.ts.map +1 -1
  507. package/dist/pr-report-url.js +46 -5
  508. package/dist/pr-requires.d.ts +13 -2
  509. package/dist/pr-requires.d.ts.map +1 -1
  510. package/dist/pr-requires.js +14 -0
  511. package/dist/release-floors.d.ts +1 -1
  512. package/dist/release-floors.js +1 -1
  513. package/dist/run-event.d.ts +26 -1
  514. package/dist/run-event.d.ts.map +1 -1
  515. package/dist/run-event.js +4 -1
  516. package/dist/sorted-json.d.ts +10 -0
  517. package/dist/sorted-json.d.ts.map +1 -0
  518. package/dist/sorted-json.js +14 -0
  519. package/dist/terraform/credentials.d.ts +59 -0
  520. package/dist/terraform/credentials.d.ts.map +1 -0
  521. package/dist/terraform/credentials.js +149 -0
  522. package/dist/utils.d.ts +1 -4
  523. package/dist/utils.d.ts.map +1 -1
  524. package/dist/utils.js +1 -9
  525. package/dist/wave-runtime.d.ts +1 -1
  526. package/dist/wave-runtime.js +2 -2
  527. package/dist/wave-runtime.mjs +390 -285
  528. package/dist/workspace/chant-migrations/chud-lexicon-exit.d.ts.map +1 -1
  529. package/dist/workspace/chant-migrations/chud-lexicon-exit.js +4 -1
  530. package/dist/workspace/ci-lock-grain.d.ts +12 -0
  531. package/dist/workspace/ci-lock-grain.d.ts.map +1 -0
  532. package/dist/workspace/ci-lock-grain.js +27 -0
  533. package/dist/workspace/ci-run.d.ts +2 -1
  534. package/dist/workspace/ci-run.d.ts.map +1 -1
  535. package/dist/workspace/ci-run.js +6 -3
  536. package/dist/workspace/declaration.d.ts +16 -4
  537. package/dist/workspace/declaration.d.ts.map +1 -1
  538. package/dist/workspace/declaration.js +5 -2
  539. package/dist/workspace/declaration.schema.json +27 -3
  540. package/dist/workspace/drift-cli.d.ts.map +1 -1
  541. package/dist/workspace/drift-cli.js +8 -3
  542. package/dist/workspace/exit-cli.d.ts +1 -1
  543. package/dist/workspace/exit-cli.d.ts.map +1 -1
  544. package/dist/workspace/exit-cli.js +2 -1
  545. package/dist/workspace/import-fetch.d.ts +4 -2
  546. package/dist/workspace/import-fetch.d.ts.map +1 -1
  547. package/dist/workspace/import-fetch.js +4 -2
  548. package/dist/workspace/import-init.d.ts.map +1 -1
  549. package/dist/workspace/import-init.js +4 -2
  550. package/dist/workspace/ledger.schema.json +7 -3
  551. package/dist/workspace/lineage-upgrade-cli.d.ts +1 -1
  552. package/dist/workspace/lineage-upgrade-cli.d.ts.map +1 -1
  553. package/dist/workspace/lineage-upgrade-cli.js +2 -1
  554. package/dist/workspace/pr-report.schema.json +74 -3
  555. package/dist/workspace/promote.d.ts +1 -1
  556. package/dist/workspace/promote.d.ts.map +1 -1
  557. package/dist/workspace/promote.js +2 -1
  558. package/dist/workspace/records-cli.d.ts +2 -2
  559. package/dist/workspace/records-cli.d.ts.map +1 -1
  560. package/dist/workspace/records-cli.js +3 -2
  561. package/dist/workspace/release-catalog.schema.json +277 -0
  562. package/dist/workspace/run-event.schema.json +18 -1
  563. package/dist/workspace/work-cli.d.ts +3 -1
  564. package/dist/workspace/work-cli.d.ts.map +1 -1
  565. package/dist/workspace/work-cli.js +7 -2
  566. package/dist/workspace/workspace-run.d.ts.map +1 -1
  567. package/dist/workspace/workspace-run.js +2 -1
  568. package/package.json +21 -1
  569. package/src/__fixtures__/estate-ledger.ts +101 -0
  570. package/src/__fixtures__/oidc-emulator.ts +31 -2
  571. package/src/__fixtures__/product-words.ts +44 -0
  572. package/src/__golden__/wave-loop/op-by-apply-after-fails.json +10 -2
  573. package/src/__golden__/wave-loop/op-by-apply-hold.json +20 -4
  574. package/src/__golden__/wave-loop/op-by-apply-ignored.json +10 -2
  575. package/src/__golden__/wave-loop/op-by-apply-pass.json +10 -2
  576. package/src/__golden__/wave-loop/op-by-apply-skip.json +10 -2
  577. package/src/__golden__/wave-loop/op-discover-rest-stops.json +22 -6
  578. package/src/__golden__/wave-loop/op-discover-rest.json +44 -12
  579. package/src/__golden__/wave-loop/op-discover-wide.json +12 -3
  580. package/src/__golden__/wave-loop/op-held-on.json +28 -7
  581. package/src/__golden__/wave-loop/op-hooks-apply-fails.json +22 -6
  582. package/src/__golden__/wave-loop/op-hooks-fail-after-apply.json +22 -6
  583. package/src/__golden__/wave-loop/op-hooks-fail-before-apply.json +4 -2
  584. package/src/__golden__/wave-loop/op-hooks-held.json +26 -8
  585. package/src/__golden__/wave-loop/op-hooks-hold-before-apply.json +18 -4
  586. package/src/__golden__/wave-loop/op-hooks-pass.json +22 -6
  587. package/src/__golden__/wave-loop/op-hooks-share.json +20 -7
  588. package/src/__golden__/wave-loop/op-outcome-held.json +12 -3
  589. package/src/__golden__/wave-loop/op-outcome-replan-approved.json +16 -5
  590. package/src/__golden__/wave-loop/op-outcome-replan-forever.json +48 -21
  591. package/src/__golden__/wave-loop/op-outcome-replan.json +16 -5
  592. package/src/__golden__/wave-loop/op-outcome-stood-down.json +12 -3
  593. package/src/__golden__/wave-loop/op-outcome-unreadable.json +12 -3
  594. package/src/__golden__/wave-loop/op-overridden.json +28 -7
  595. package/src/__golden__/wave-loop/op-per-run.json +20 -4
  596. package/src/__golden__/wave-loop/op-point.json +18 -4
  597. package/src/__golden__/wave-loop/op-pr-review.json +10 -2
  598. package/src/__golden__/wave-loop/op-spend-change-only.json +10 -2
  599. package/src/__golden__/wave-loop/op-spend.json +10 -2
  600. package/src/__golden__/wave-loop/op-wave-commands.json +56 -13
  601. package/src/__golden__/wave-loop/op-wide.json +20 -4
  602. package/src/bucket-check/azure.ts +307 -0
  603. package/src/bucket-check/bucket-check.test.ts +210 -0
  604. package/src/bucket-check/fixtures/azure.json +153 -0
  605. package/src/bucket-check/fixtures/gcs.json +148 -0
  606. package/src/bucket-check/fixtures/s3.json +277 -0
  607. package/src/bucket-check/gcs.ts +257 -0
  608. package/src/bucket-check/index.ts +61 -0
  609. package/src/bucket-check/s3.ts +433 -0
  610. package/src/bucket-check/types.ts +75 -0
  611. package/src/bucket-check/wire.ts +50 -0
  612. package/src/bucket-check.ts +5 -0
  613. package/src/capabilities/templates.test.ts +2 -3
  614. package/src/capabilities/templates.ts +1 -2
  615. package/src/cdk/advise.test.ts +1 -1
  616. package/src/change-set-bundle.test.ts +0 -1
  617. package/src/change-set.ts +2 -3
  618. package/src/ci-agent.test.ts +348 -0
  619. package/src/ci-agent.ts +1026 -0
  620. package/src/ci-control.ts +174 -0
  621. package/src/ci-estate/delivery.ts +433 -0
  622. package/src/ci-estate/overdue.ts +81 -0
  623. package/src/ci-estate/page.ts +343 -0
  624. package/src/ci-estate/rows.ts +251 -0
  625. package/src/ci-estate.test.ts +281 -0
  626. package/src/ci-estate.ts +176 -0
  627. package/src/ci-handover.ts +67 -16
  628. package/src/ci-identity-database.test.ts +55 -0
  629. package/src/ci-identity-pulumi.test.ts +163 -0
  630. package/src/ci-identity-targets.test.ts +6 -2
  631. package/src/ci-identity.ts +124 -22
  632. package/src/ci-product-words.test.ts +101 -0
  633. package/src/ci-product-words.ts +536 -0
  634. package/src/ci-product.ts +174 -0
  635. package/src/ci-shared-reads.test.ts +145 -0
  636. package/src/cli/commands/audit.test.ts +1 -1
  637. package/src/cli/commands/audit.ts +3 -2
  638. package/src/cli/commands/carve.test.ts +1 -1
  639. package/src/cli/commands/carve.ts +2 -2
  640. package/src/cli/commands/init.ts +3 -1
  641. package/src/cli/component-wave-args.test.ts +16 -0
  642. package/src/cli/handlers/agent.ts +126 -0
  643. package/src/cli/handlers/approve-confirm.test.ts +276 -0
  644. package/src/cli/handlers/approve-confirm.ts +200 -0
  645. package/src/cli/handlers/approve.ts +18 -1
  646. package/src/cli/handlers/build.test.ts +7 -0
  647. package/src/cli/handlers/build.ts +44 -1
  648. package/src/cli/handlers/ci-check.ts +33 -0
  649. package/src/cli/handlers/ci-forge-check.ts +91 -0
  650. package/src/cli/handlers/fan-out.test.ts +10 -10
  651. package/src/cli/handlers/fan-out.ts +5 -0
  652. package/src/cli/handlers/gate-pending.ts +46 -0
  653. package/src/cli/handlers/init.ts +1 -0
  654. package/src/cli/handlers/ledger.ts +1 -1
  655. package/src/cli/handlers/lifecycle-drift.ts +7 -2
  656. package/src/cli/handlers/lock.test.ts +29 -2
  657. package/src/cli/handlers/lock.ts +66 -6
  658. package/src/cli/handlers/notify-relay.ts +130 -0
  659. package/src/cli/handlers/pr-before-merge.test.ts +2 -1
  660. package/src/cli/handlers/pr-deploy-inputs.test.ts +7 -7
  661. package/src/cli/handlers/pr-env.ts +48 -11
  662. package/src/cli/handlers/pr-plan-targets.test.ts +155 -0
  663. package/src/cli/handlers/pr-waves-blocked.test.ts +5 -0
  664. package/src/cli/handlers/pr-waves.test.ts +8 -2
  665. package/src/cli/handlers/pr.test.ts +8 -8
  666. package/src/cli/handlers/pr.ts +655 -205
  667. package/src/cli/handlers/promote.test.ts +5 -5
  668. package/src/cli/handlers/promote.ts +22 -2
  669. package/src/cli/handlers/release.ts +2 -0
  670. package/src/cli/handlers/run-components-exit.test.ts +7 -7
  671. package/src/cli/handlers/run-wave.ts +65 -1
  672. package/src/cli/handlers/run.test.ts +6 -4
  673. package/src/cli/handlers/run.ts +86 -1
  674. package/src/cli/handlers/serve.ts +10 -1
  675. package/src/cli/main.ts +126 -13
  676. package/src/cli/mcp/ledger-tools.ts +126 -0
  677. package/src/cli/mcp/product-tools.test.ts +123 -0
  678. package/src/cli/mcp/product-tools.ts +129 -0
  679. package/src/cli/mcp/read-only.test.ts +134 -0
  680. package/src/cli/mcp/read-only.ts +68 -0
  681. package/src/cli/mcp/report-tools.ts +135 -0
  682. package/src/cli/mcp/server.test.ts +5 -4
  683. package/src/cli/mcp/server.ts +90 -16
  684. package/src/cli/mcp-config.ts +8 -3
  685. package/src/cli/parse-args.ts +42 -2
  686. package/src/cli/registry.ts +35 -0
  687. package/src/cloud-lister/sigv4.ts +80 -23
  688. package/src/components/adoption.test.ts +140 -0
  689. package/src/components/adoption.ts +141 -0
  690. package/src/components/apply-lease.ts +49 -0
  691. package/src/components/capability.ts +130 -6
  692. package/src/components/check-hooks.test.ts +66 -0
  693. package/src/components/check-hooks.ts +252 -0
  694. package/src/components/ci-services.test.ts +51 -0
  695. package/src/components/ci-services.ts +83 -0
  696. package/src/components/cli-support.ts +23 -2
  697. package/src/components/driver.test.ts +3 -3
  698. package/src/components/driver.ts +38 -5
  699. package/src/components/fan-out-run.ts +68 -18
  700. package/src/components/groups.ts +17 -2
  701. package/src/components/pr-comment-preview.test.ts +54 -0
  702. package/src/components/pr-env-ledger.test.ts +9 -0
  703. package/src/components/pr-env-ledger.ts +43 -0
  704. package/src/components/pr-env-ports.ts +29 -4
  705. package/src/components/pr-env-run-bundle.test.ts +8 -0
  706. package/src/components/pr-env-run.test.ts +19 -0
  707. package/src/components/pr-env-run.ts +12 -2
  708. package/src/components/pr-environment.test.ts +29 -0
  709. package/src/components/pr-environment.ts +39 -7
  710. package/src/components/pr-pipeline.test.ts +15 -0
  711. package/src/components/pr-pipeline.ts +274 -9
  712. package/src/components/pr-policy.ts +45 -7
  713. package/src/components/pr-run.test.ts +1 -1
  714. package/src/components/pr-run.ts +121 -5
  715. package/src/components/pr-targets.test.ts +35 -0
  716. package/src/components/pr-targets.ts +45 -0
  717. package/src/components/product-pipeline.test.ts +200 -0
  718. package/src/components/product-pipeline.ts +341 -0
  719. package/src/components/promote.ts +10 -1
  720. package/src/components/release-compile.ts +87 -1
  721. package/src/components/release-promote.ts +65 -1
  722. package/src/components/repo-lock.ts +52 -0
  723. package/src/components/row-lease.test.ts +490 -0
  724. package/src/components/row-lease.ts +167 -0
  725. package/src/components/wave-plan-policy.test.ts +19 -0
  726. package/src/components/wave-plan.ts +78 -4
  727. package/src/control/__fixtures__/consumers/apps/consumers.json +15 -0
  728. package/src/control/__fixtures__/consumers/infra/consumers.json +23 -0
  729. package/src/control/applied.test.ts +148 -0
  730. package/src/control/applied.ts +191 -0
  731. package/src/control/consumers.test.ts +129 -0
  732. package/src/control/consumers.ts +192 -0
  733. package/src/control/control.test.ts +302 -0
  734. package/src/control/dispatch.ts +699 -0
  735. package/src/control/edges.test.ts +112 -0
  736. package/src/control/edges.ts +164 -0
  737. package/src/control/note-checkout.test.ts +91 -0
  738. package/src/control/reconcile.ts +250 -0
  739. package/src/control/records.ts +395 -0
  740. package/src/discovery/sandbox/bundle.ts +25 -1
  741. package/src/engine-facts.test.ts +2 -3
  742. package/src/engine-facts.ts +1 -2
  743. package/src/exit-codes.test.ts +31 -0
  744. package/src/exit-codes.ts +55 -0
  745. package/src/forge-check/check.ts +155 -0
  746. package/src/forge-check/contract.ts +215 -0
  747. package/src/forge-check/forge-check.test.ts +427 -0
  748. package/src/forge-check/forge.ts +318 -0
  749. package/src/forge-check/index.ts +43 -0
  750. package/src/forge-check/pulumi.ts +192 -0
  751. package/src/forge-check/read-only.ts +56 -0
  752. package/src/forge-check/trust.ts +527 -0
  753. package/src/forge-check/types.ts +78 -0
  754. package/src/forge-check.ts +5 -0
  755. package/src/gate-decision-bundle.test.ts +13 -0
  756. package/src/gate-decision.ts +3 -0
  757. package/src/gate-policy.ts +92 -3
  758. package/src/gated-waves-bundle.test.ts +0 -1
  759. package/src/index.ts +2 -0
  760. package/src/lexicon.ts +95 -6
  761. package/src/lifecycle/adoption-file.ts +1 -2
  762. package/src/lifecycle/cloud-index.test.ts +2 -3
  763. package/src/lifecycle/cloud-index.ts +1 -2
  764. package/src/lifecycle/control-entries-ledger.test.ts +70 -0
  765. package/src/lifecycle/gate-applied.ts +6 -0
  766. package/src/lifecycle/gate-ledger.ts +36 -1
  767. package/src/lifecycle/gate-pending-by-plan.test.ts +69 -0
  768. package/src/lifecycle/gate-pending-by-plan.ts +133 -0
  769. package/src/lifecycle/gated-request-digest.ts +49 -0
  770. package/src/lifecycle/gated-request-ledger.test.ts +53 -0
  771. package/src/lifecycle/gated-request.ts +280 -0
  772. package/src/lifecycle/identity-match.ts +25 -6
  773. package/src/lifecycle/index-diff.ts +1 -2
  774. package/src/lifecycle/index-document.ts +1 -2
  775. package/src/lifecycle/index-import.test.ts +14 -0
  776. package/src/lifecycle/index-import.ts +54 -34
  777. package/src/lifecycle/ledger-read.ts +7 -3
  778. package/src/lifecycle/lock-rows.test.ts +109 -0
  779. package/src/lifecycle/lock-rows.ts +167 -0
  780. package/src/lifecycle/publish-target-context.test.ts +108 -0
  781. package/src/lifecycle/query.test.ts +2 -3
  782. package/src/lifecycle/query.ts +109 -7
  783. package/src/lifecycle/release-catalog-site.test.ts +142 -0
  784. package/src/lifecycle/release-catalog-site.ts +291 -0
  785. package/src/lifecycle/release-catalog.test.ts +193 -0
  786. package/src/lifecycle/release-catalog.ts +353 -0
  787. package/src/lifecycle/release-changelog.test.ts +70 -0
  788. package/src/lifecycle/release-changelog.ts +71 -0
  789. package/src/lifecycle/release-cut.ts +2 -2
  790. package/src/lifecycle/release-ledger.ts +20 -0
  791. package/src/lifecycle/release-publish.ts +45 -22
  792. package/src/lifecycle/release-read.ts +2 -0
  793. package/src/lifecycle/release-status.test.ts +186 -0
  794. package/src/lifecycle/release-status.ts +176 -0
  795. package/src/lifecycle/resource-lock.test.ts +175 -0
  796. package/src/lifecycle/resource-lock.ts +354 -0
  797. package/src/lifecycle/retention.ts +2 -0
  798. package/src/lifecycle/run-ledger.ts +7 -1
  799. package/src/lifecycle/snapshot-store-s3.ts +9 -45
  800. package/src/lifecycle/snapshot-store.ts +1 -2
  801. package/src/lifecycle/target-lock.ts +24 -9
  802. package/src/mcp/types.ts +7 -0
  803. package/src/notify-product.ts +76 -0
  804. package/src/notify-relay.test.ts +213 -0
  805. package/src/notify-relay.ts +407 -0
  806. package/src/notify.ts +95 -14
  807. package/src/object-store/azure-blob.ts +374 -0
  808. package/src/object-store/common.ts +133 -0
  809. package/src/object-store/errors.ts +26 -0
  810. package/src/object-store/from-env.ts +36 -0
  811. package/src/object-store/gcs.ts +436 -0
  812. package/src/object-store/index.ts +8 -0
  813. package/src/object-store/object-store.test.ts +130 -0
  814. package/src/object-store/s3.ts +350 -0
  815. package/src/op/activities/converge.ts +2 -1
  816. package/src/op/activities/index.ts +1 -1
  817. package/src/op/activities/review-agent.open.test.ts +78 -0
  818. package/src/op/activities/review-agent.test.ts +13 -0
  819. package/src/op/activities/review-agent.ts +89 -5
  820. package/src/op/gate.ts +81 -22
  821. package/src/op/generate-pipeline.ts +7 -1
  822. package/src/op/index.ts +21 -0
  823. package/src/op/op-waves-after-plan.test.ts +276 -0
  824. package/src/op/op-waves-after-plan.ts +238 -0
  825. package/src/op/op-waves-capability-spec.ts +113 -0
  826. package/src/op/op-waves-capability.test.ts +217 -0
  827. package/src/op/op-waves-capability.ts +370 -0
  828. package/src/op/op-waves-events.ts +135 -0
  829. package/src/op/op-waves-notify-words.test.ts +149 -0
  830. package/src/op/op-waves-notify.ts +41 -16
  831. package/src/op/op-waves-pull-request.test.ts +142 -0
  832. package/src/op/op-waves-release-port.ts +64 -0
  833. package/src/op/op-waves-release.test.ts +209 -0
  834. package/src/op/op-waves-release.ts +133 -0
  835. package/src/op/op-waves-run-record.test.ts +32 -0
  836. package/src/op/op-waves-run.ts +1142 -49
  837. package/src/op/op-waves-stand-down.test.ts +240 -0
  838. package/src/op/op-waves-stand-down.ts +108 -0
  839. package/src/op/op-waves-trace.test.ts +205 -0
  840. package/src/op/op-waves.test.ts +112 -0
  841. package/src/op/op-waves.ts +261 -20
  842. package/src/op/runtime.ts +104 -0
  843. package/src/op/stage-hooks-hold-record.test.ts +41 -0
  844. package/src/op/stage-hooks.ts +91 -12
  845. package/src/op/steward-beside.ts +2 -1
  846. package/src/op/types.ts +3 -2
  847. package/src/otlp-metrics.ts +96 -0
  848. package/src/otlp.test.ts +243 -0
  849. package/src/otlp.ts +544 -0
  850. package/src/override-gate-bundle.test.ts +2 -0
  851. package/src/override-gate.ts +4 -0
  852. package/src/policy-packs.ts +230 -0
  853. package/src/policy-source.test.ts +256 -0
  854. package/src/policy-source.ts +112 -0
  855. package/src/pr-forge.ts +123 -0
  856. package/src/pr-loop-bundle.test.ts +6 -2
  857. package/src/pr-loop-words.test.ts +155 -0
  858. package/src/pr-loop.ts +371 -52
  859. package/src/pr-post.ts +32 -1
  860. package/src/pr-report-url.ts +62 -6
  861. package/src/pr-requires.test.ts +37 -1
  862. package/src/pr-requires.ts +16 -2
  863. package/src/product-subpaths-plain-node.e2e.test.ts +211 -0
  864. package/src/release-floors.ts +1 -1
  865. package/src/run-event.ts +29 -1
  866. package/src/sorted-json.ts +17 -0
  867. package/src/stage-hooks-bundle.test.ts +8 -0
  868. package/src/terraform/credentials.test.ts +77 -0
  869. package/src/terraform/credentials.ts +162 -0
  870. package/src/utils.ts +2 -11
  871. package/src/wave-loop-golden.test.ts +2 -1
  872. package/src/wave-runtime.ts +2 -2
  873. package/src/workspace/chant-migrations/chud-lexicon-exit.ts +4 -1
  874. package/src/workspace/ci-lock-grain.test.ts +31 -0
  875. package/src/workspace/ci-lock-grain.ts +30 -0
  876. package/src/workspace/ci-report-url.test.ts +1 -1
  877. package/src/workspace/ci-run.test.ts +1 -1
  878. package/src/workspace/ci-run.ts +6 -3
  879. package/src/workspace/declaration.schema.json +27 -3
  880. package/src/workspace/declaration.test.ts +1 -1
  881. package/src/workspace/declaration.ts +26 -10
  882. package/src/workspace/drift-cli.ts +8 -3
  883. package/src/workspace/exit-cli.ts +2 -1
  884. package/src/workspace/import-fetch.ts +4 -2
  885. package/src/workspace/import-init.ts +4 -2
  886. package/src/workspace/ledger.schema.json +7 -3
  887. package/src/workspace/lineage-upgrade-cli.ts +2 -1
  888. package/src/workspace/pr-report.schema.json +74 -3
  889. package/src/workspace/promote.ts +2 -1
  890. package/src/workspace/records-cli.ts +3 -2
  891. package/src/workspace/release-catalog.schema.json +277 -0
  892. package/src/workspace/run-event.schema.json +18 -1
  893. package/src/workspace/work-cli.ts +8 -2
  894. package/src/workspace/workspace-run.ts +2 -1
@@ -65,8 +65,10 @@
65
65
  */
66
66
 
67
67
  import { spawnSync } from "node:child_process";
68
- import { mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
69
- import { join, relative, resolve, sep } from "node:path";
68
+ import { CHANT_EXIT } from "../../exit-codes";
69
+ import { anyResourceGrain, leaseRowsOf as leaseRowsOfLocks, lockTargetsOf, type LockGrain } from "../../lifecycle/lock-rows";
70
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
71
+ import { dirname, join, relative, resolve, sep } from "node:path";
70
72
  import { loadChantConfig, resolveAutoReleaseDisabled, type ChantConfig } from "../../config";
71
73
  import { resolveCommit, resolveMergeBase } from "../../components/changed-files";
72
74
  import { deriveFanOut, fanOutRegistry } from "../../components/fan-out-support";
@@ -82,15 +84,14 @@ import {
82
84
  readOnlyLedger,
83
85
  prWavePlan,
84
86
  resumePrSet,
85
- waveNotCovered,
86
87
  type PrPlanSet,
87
88
  } from "../../components/pr-run";
88
89
  import { composeChangeSet, verifyChangeSetDigest } from "../../change-set";
89
- import { waveGateName } from "../../gated-waves";
90
90
  import { blockedMembers, blockedWords, settleEarlierWaves, type WaveMemberOutcome } from "../../wave-blocked";
91
91
  import { readFanOutAttempt, writeFanOutAttempt, type FanOutAttempt, type PrApplyRecord } from "../../components/fan-out-record";
92
92
  import { componentInputDigests, progressThatCarries } from "../../components/fan-out-inputs";
93
- import { samePlanDigest } from "../../lifecycle/plan-digest";
93
+ import { computePlanDigest, samePlanDigest } from "../../lifecycle/plan-digest";
94
+ import type { GateResolutionRecord } from "../../lifecycle/gate-ledger";
94
95
  import { evaluateGate, gateIsSealed, gitGateLedgerPort, type GateCheck, type GateLedgerPort } from "../../op/gate";
95
96
  import type { OtherGateHold } from "../../op/stage-hooks";
96
97
  import { emitGateStep, gateEventsOf, GATE_PHASE, type RunEventSink, type RunEventStream } from "../../run-event-stream";
@@ -101,6 +102,7 @@ import {
101
102
  describePlanChanged,
102
103
  PR_APPLY_GATE,
103
104
  prApproveCommand,
105
+ prApproveCommands,
104
106
  prNoteMarker,
105
107
  prOp,
106
108
  prStatusDescription,
@@ -110,6 +112,7 @@ import {
110
112
  type PrApproval,
111
113
  type PrBeforeMerge,
112
114
  type PrMember,
115
+ type PrMemberDetail,
113
116
  type PrPolicyReport,
114
117
  type PrReport,
115
118
  type PrWave,
@@ -118,6 +121,8 @@ import {
118
121
  } from "../../pr-loop";
119
122
  import { FORGE_KINDS, forgeFromEnv, forgePrincipalOf, type ForgeKind, type PrForge } from "../../pr-forge";
120
123
  import { GITHUB_COMMENT_LIMIT, GITLAB_NOTE_LIMIT } from "../../plan-summary";
124
+ import { upsertPlanNote } from "../../pr-post";
125
+ import { activeProductWords, productContext } from "../../ci-product-words";
121
126
  import { resolveCliBuildParams, parseParamFlags } from "../build-params-cli";
122
127
  import { formatError, formatInfo, formatSuccess, formatWarning } from "../format";
123
128
  import { reportUninstalledDependencies } from "../dependencies";
@@ -127,10 +132,12 @@ import { coverByMerges, greenOp, type GreenTarget } from "../../components/green
127
132
  import { GATED_EXIT_CODE, autoReleaseRun, recordAutoReleasesForRun } from "./run";
128
133
  import { appliedDigestOf } from "../../components/auto-release";
129
134
  import type { CommandContext } from "../registry";
135
+ import { parseArgs } from "../parse-args";
130
136
  import { withComponentEndpoint } from "../component-endpoint";
131
137
  import type { ComponentChangeSignal, FanOutPlan } from "../../components/fan-out";
132
- import { failedRunExitCode, type DriverComponent } from "../../components/driver";
133
- import type { CapabilityRegistry } from "../../components/capability";
138
+ import { assertTargetsAccepted, failedRunExitCode, type DriverComponent } from "../../components/driver";
139
+ import { TargetsRefusedError, type CapabilityRegistry } from "../../components/capability";
140
+ import { prPlanTargets } from "../../components/pr-targets";
134
141
  import type { ComponentEnvironmentDeclaration } from "../../components/component";
135
142
  import { prLoopHooksAt, runPrHooks, type PrHoldSettled, type PrHookPlace, type PrLoopHooks } from "../../components/pr-hooks";
136
143
  import { decidePrPolicyOverride, policyReviewOf, prLoopPolicyAt, prPolicyReport, runPrPolicy, spendPrPolicyOverride, type PrLoopPolicy } from "../../components/pr-policy";
@@ -172,6 +179,8 @@ export interface Prepared {
172
179
  hookFailed?: string;
173
180
  /** Where the stage's hooks run, once its op is known. */
174
181
  hookPlace?: PrHookPlace;
182
+ /** `pr-plan --target` (#4620): the addresses each planned member's capability plan narrows to. */
183
+ targets?: Record<string, string[]>;
175
184
  /**
176
185
  * Set when `ci.branches` or `ci.labels` (#4292) leave the member out of this
177
186
  * stage: why. The plan is then empty, so the stage reports `nothing`.
@@ -211,6 +220,10 @@ export async function prepare(ctx: CommandContext, stage: "plan" | "apply" | "re
211
220
  );
212
221
  }
213
222
  if (args.fromAffected) return fail(`pr-${stage} derives the change itself; drop --from-affected`);
223
+ // #4620: a target narrows the preview; an apply or a record covers what the approved plan covers.
224
+ if (stage !== "plan" && args.targets && args.targets.length > 0) {
225
+ return fail(`pr-${stage} applies or records what the pull request's approved plan covers, so it takes no --target`, "Narrow the plan with pr-plan --target, and approve that plan.");
226
+ }
214
227
  let member: string | undefined;
215
228
  if (args.members?.length) {
216
229
  const checked = await checkMember(projectPath, args.members);
@@ -476,17 +489,94 @@ export function planAll(p: Prepared, onRunEvent?: RunEventSink): Promise<PrPlanS
476
489
  return hookedPlan(p, p.plan.order, () => planBare(p, onRunEvent));
477
490
  }
478
491
 
479
- export function planBare(p: Prepared, onRunEvent?: RunEventSink): Promise<PrPlanSet> {
492
+ export async function planBare(p: Prepared, onRunEvent?: RunEventSink): Promise<PrPlanSet> {
493
+ const lockGrain = await declaredLockGrainOf(p);
480
494
  return planPrSet({
481
495
  components: p.components,
482
496
  plan: p.plan,
483
497
  registry: p.registry,
484
498
  env: p.env,
485
499
  seededOutputs: p.seededOutputs,
500
+ ...(lockGrain ? { lockGrain } : {}),
501
+ // #4613: a step's own policy engine (CrossGuard) reads its packs at the base, as ci.policy is.
502
+ policyBase: p.base,
486
503
  ...(onRunEvent ? { onRunEvent } : {}),
504
+ ...(p.targets ? { targets: p.targets } : {}),
487
505
  });
488
506
  }
489
507
 
508
+ /**
509
+ * `pr-plan --target` (#4620): the addresses by member, set on `p`, or the
510
+ * exit code when a value is refused or a targeted member has a capability
511
+ * that cannot narrow, which is named before anything plans.
512
+ */
513
+ function narrowToTargets(p: Prepared, values: readonly string[] | undefined): number | undefined {
514
+ if (!values || values.length === 0) return undefined;
515
+ const resolved = prPlanTargets(values, p.plan.order, new Set(p.components.map((c) => c.name)));
516
+ if ("error" in resolved) return fail(resolved.error, "--target <address> narrows every member the pull request plans; --target <member>:<address> narrows one.");
517
+ const { targets } = resolved;
518
+ const byName = new Map(p.components.map((c) => [c.name, c]));
519
+ for (const [name, addresses] of Object.entries(targets)) {
520
+ try {
521
+ assertTargetsAccepted(byName.get(name)!, p.registry, { targets: addresses });
522
+ } catch (err) {
523
+ if (err instanceof TargetsRefusedError) return fail(`${err.message}, so nothing was planned`, "Drop --target, or name a member whose steps can narrow: --target <member>:<address>.");
524
+ throw err;
525
+ }
526
+ }
527
+ p.targets = targets;
528
+ console.error(formatInfo(`narrowed to ${Object.entries(targets).map(([name, a]) => `${name}: ${a.join(", ")}`).join("; ") || "nothing planned"}`));
529
+ return undefined;
530
+ }
531
+
532
+ /**
533
+ * `ci.lockGrain` of the stage's member (#4552), read from the declaration at
534
+ * base like `ci.locks`, so a change cannot pick its own grain. Undefined when
535
+ * none is declared: each member then takes its lexicon's default.
536
+ */
537
+ async function declaredLockGrainOf(p: Pick<Prepared, "base" | "member">): Promise<LockGrain | undefined> {
538
+ const { ciLockGrainAt } = await import("../../workspace/ci-lock-grain");
539
+ return ciLockGrainAt(process.cwd(), p.base, p.member) ?? undefined;
540
+ }
541
+
542
+ /**
543
+ * Lease the rows a set's members on the resource grain change (#4552),
544
+ * before anything applies: the refusal naming the run that holds one, the
545
+ * exit code when the rows file could not be written, or the lease to let go
546
+ * of once the apply ends (one that holds nothing when no member is on the
547
+ * resource grain).
548
+ */
549
+ async function leaseSetRows(p: Prepared, set: Pick<PrPlanSet, "locks">): Promise<{ release(): Promise<boolean> } | { held: string } | number> {
550
+ const leased = await leaseRowsOf(p, set);
551
+ return "failed" in leased ? fail(leased.failed) : leased;
552
+ }
553
+
554
+ /**
555
+ * {@link leaseSetRows} without printing a failure (#4594), for a later round
556
+ * of `applyPrSet` (`leaseRound`), which records it on the round, and for a
557
+ * pull request environment's apply, which reports it.
558
+ */
559
+ export async function leaseRowsOf(p: Pick<Prepared, "gate">, set: Pick<PrPlanSet, "locks">, label = "this apply"): Promise<{ release(): Promise<boolean> } | { held: string } | { failed: string }> {
560
+ const rows = leaseRowsOfLocks(set.locks);
561
+ if (rows.length === 0) return { release: () => Promise.resolve(true) };
562
+ const { leaseLockRows } = await import("../../lifecycle/resource-lock");
563
+ let leased;
564
+ try {
565
+ leased = await leaseLockRows(p.gate, rows);
566
+ } catch (err) {
567
+ return { failed: `could not hold the rows ${label} changes in ${p.gate}, so nothing of it was applied: ${err instanceof Error ? err.message : String(err)}` };
568
+ }
569
+ if (!leased.ok) return { held: `${leased.message}, so nothing of ${label} was applied. Apply again once that run ends; a run that is gone, or whose lease is older than CHANT_LOCK_STALE seconds, is taken over.` };
570
+ for (const h of leased.tookOver) console.error(formatInfo(`took over the rows of run ${h.run}, which is gone`));
571
+ console.error(formatInfo(`${label} holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${p.gate} while it applies`));
572
+ return leased.lease;
573
+ }
574
+
575
+ /** `applyPrSet`'s `leaseRound` (#4594): a round after the first leases the rows its own plan locks. */
576
+ export function leaseRoundRows(p: Pick<Prepared, "gate">): NonNullable<Parameters<typeof applyPrSet>[0]["leaseRound"]> {
577
+ return ({ round, set }) => leaseRowsOf(p, set, `round ${round}`);
578
+ }
579
+
490
580
  /**
491
581
  * How a stage's report settles its run's events (#4041): a refusal waits on
492
582
  * a person, as a gate does, and exits the same way.
@@ -540,7 +630,7 @@ async function publish(forge: PrForge | undefined, report: PrReport, note: strin
540
630
  // member would put a line on every pull request for each member it skips.
541
631
  if (report.member && report.status === "nothing" && !report.overdue?.length && !report.migrations?.length) return;
542
632
  try {
543
- await forge.upsertNote(report.pr, prNoteMarker(report.env, report.member), note);
633
+ await upsertPlanNote(forge, report.pr, prNoteMarker(report.env, report.member), note);
544
634
  } catch (err) {
545
635
  console.error(formatWarning({ message: `could not post the note on #${report.pr}: ${err instanceof Error ? err.message : String(err)}` }));
546
636
  }
@@ -567,6 +657,14 @@ async function finish(ctx: CommandContext, p: Prepared, report: PrReport, upload
567
657
  if (p.routedAway && report.status === "nothing" && !report.message) report = { ...report, message: p.routedAway };
568
658
  if (p.policyReport) report = { ...report, policy: p.policyReport };
569
659
  if (p.beforeMerge) report = { ...report, beforeMerge: p.beforeMerge };
660
+ // #4617: with a checkout of the control repo named, its entries and apply records mark the cross-stack edges.
661
+ if (report.crossStackEdges?.length && process.env.CHANT_CONTROL_DIR) {
662
+ const { controlEdgeFactsFromEnv, remarkCrossStackEdges } = await import("../../control/edges");
663
+ report = remarkCrossStackEdges(report, await controlEdgeFactsFromEnv());
664
+ }
665
+ // #4573: each member's section its lexicon renders from its own part of the change set.
666
+ const details = await memberDetails(p, report);
667
+ if (details.length > 0) report = { ...report, details };
570
668
  const note = noteFor(report, p.forge);
571
669
  writeOutputs(ctx, report, note, upload);
572
670
  if (!ctx.args.noStatus) await publish(p.forge, report, note);
@@ -668,9 +766,9 @@ async function judgePolicy(p: Prepared, at: { stage: "plan" | "apply"; op: strin
668
766
  const why = err instanceof Error ? err.message : String(err);
669
767
  if (at.stage === "plan") {
670
768
  console.error(formatWarning({ message: `could not read the override ledger, so no override reads as standing: ${why}` }));
671
- return { held, stop: { refusal: "policy-denied", code: 1, message: `The policy denied this plan: ${denied}.` } };
769
+ return { held, stop: { refusal: "policy-denied", code: CHANT_EXIT.denied, message: `The policy denied this plan: ${denied}.` } };
672
770
  }
673
- return { held, stop: { refusal: "policy-denied", code: GATED_EXIT_CODE, message: `The policy denied this plan (${denied}), and the override ledger could not be read or written: ${why}. Nothing was applied.` } };
771
+ return { held, stop: { refusal: "policy-denied", code: CHANT_EXIT.denied, message: `The policy denied this plan (${denied}), and the override ledger could not be read or written: ${why}. Nothing was applied.` } };
674
772
  }
675
773
  if (decided.status === "overridden") {
676
774
  report.override = decided.override;
@@ -685,7 +783,7 @@ async function judgePolicy(p: Prepared, at: { stage: "plan" | "apply"; op: strin
685
783
  held,
686
784
  stop: {
687
785
  refusal: "policy-denied",
688
- code: at.stage === "plan" ? 1 : GATED_EXIT_CODE,
786
+ code: CHANT_EXIT.denied,
689
787
  message: `The policy denied this plan: ${denied}.${moved} Nothing was applied. ${who} override it: ${decided.command}`,
690
788
  },
691
789
  };
@@ -715,6 +813,8 @@ async function prPlan(ctx: CommandContext, stage: StageEvents): Promise<number>
715
813
  }
716
814
  const p = await prepare(ctx, "plan");
717
815
  if (typeof p === "number") return p;
816
+ const narrowed = narrowToTargets(p, ctx.args.targets);
817
+ if (narrowed !== undefined) return narrowed;
718
818
  const op = prOp(ctx.args.pr, p.member);
719
819
  placeHooks(ctx, p, "plan", op);
720
820
  const upload = openUpload(stage, "plan", ctx.args.pr, p);
@@ -766,10 +866,41 @@ async function prPlan(ctx: CommandContext, stage: StageEvents): Promise<number>
766
866
  printMembers(report);
767
867
  if (status === "planned") {
768
868
  console.error(formatInfo(`plan : ${report.digest}`));
769
- console.error(formatInfo(approval.status === "approved" ? `approved by ${(approval.approvedBy ?? []).join(", ")}` : `approve : ${prApproveCommand(report)}`));
869
+ console.error(formatInfo(approval.status === "approved" ? `approved by ${(approval.approvedBy ?? []).join(", ")}` : `approve : ${prApproveCommands(report).join("; ")}`));
770
870
  }
771
871
  if (judged.stop) console.error(formatWarning({ message: judged.stop.message }));
772
- return status === "plan-failed" || judged.stop ? 1 : 0;
872
+ // #4550: a capability's policy denial (pulumi-up's CrossGuard) exits as a denial, 7, not as a failed plan.
873
+ if (status === "plan-failed" && set.policyDenied) return CHANT_EXIT.denied;
874
+ return status === "plan-failed" ? CHANT_EXIT.failed : judged.stop ? judged.stop.code : CHANT_EXIT.done;
875
+ }
876
+
877
+ /**
878
+ * The member detail sections (#4573): each lexicon the project lists that
879
+ * renders one (`prNoteDetail`) gets each member's part of the change set. A
880
+ * lexicon that cannot load, or throws, leaves the note as it was.
881
+ */
882
+ async function memberDetails(p: Prepared, report: PrReport): Promise<PrMemberDetail[]> {
883
+ if (report.changeSet.members.length === 0) return [];
884
+ const { loadPlugin } = await import("../plugins");
885
+ const out: PrMemberDetail[] = [];
886
+ for (const name of lexiconNames(p.config.lexicons ?? [])) {
887
+ let plugin: Awaited<ReturnType<typeof loadPlugin>>;
888
+ try {
889
+ plugin = await loadPlugin(name);
890
+ } catch {
891
+ continue;
892
+ }
893
+ if (!plugin.prNoteDetail) continue;
894
+ for (const member of report.changeSet.members) {
895
+ try {
896
+ const detail = await plugin.prNoteDetail({ member: member.member, changeSet: report.changeSet, stage: report.stage });
897
+ if (detail && detail.lines.length > 0) out.push({ member: member.member, ...(detail.title ? { title: detail.title } : {}), lines: detail.lines });
898
+ } catch (err) {
899
+ console.error(formatWarning({ message: `the ${name} lexicon could not render ${member.member}'s detail: ${err instanceof Error ? err.message : String(err)}` }));
900
+ }
901
+ }
902
+ }
903
+ return out;
773
904
  }
774
905
 
775
906
  /**
@@ -817,12 +948,13 @@ async function overdueOps(forge: PrForge | undefined, member: string | undefined
817
948
  return overdueOpsAt({ forge, cwd: resolve("."), ...(member ? { member } : {}), log: (line) => console.error(formatWarning({ message: line })) });
818
949
  }
819
950
 
820
- /** chant components pr-apply --base <ref> [--pr <n>] [--env <env>] [--gate <name>] [--forge <kind>] [--require-review] [--output <dir>] [--json] [--events-json] [--report-url <url>] */
951
+ /** chant components pr-apply --base <ref> [--pr <n>] [--env <env>] [--gate <name>] [--forge <kind>] [--require-review] [--before-merge [--requires <list>]] [--output <dir>] [--json] [--events-json] [--report-url <url>] */
821
952
  export function runComponentsPrApply(ctx: CommandContext): Promise<number> {
822
953
  if (refusesEventsWithJson(ctx.args, "the stage's report")) return Promise.resolve(1);
823
954
  return withStageEvents("pr-apply", ctx, async (events) => {
824
955
  // #4301: an apply before merge asks the forge its requires checks before any of the head's code loads, the config included.
825
956
  let beforeMerge: PrBeforeMerge | undefined;
957
+ if (ctx.args.requires && !ctx.args.beforeMerge) return fail("--requires names the checks of an apply before merge, so it needs --before-merge --pr <n>");
826
958
  if (ctx.args.beforeMerge) {
827
959
  const checked = await beforeMergeChecks(ctx);
828
960
  if (typeof checked === "number") return checked;
@@ -881,7 +1013,7 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
881
1013
  const set: PrPlanSet = { doc: composeChangeSet([]), members: [], plans: {}, outputs: {}, failed: false };
882
1014
  return stopper(ctx, p, events, upload)(
883
1015
  prReport({ stage: "apply", pr, env: p.env, ...(p.member ? { member: p.member } : {}), base: p.base, head: p.head, op, gate: p.gate, plan: p.plan, signal: p.signal, set, approval: { status: "pending" }, status: "refused", refusal: "locked", message: held }),
884
- GATED_EXIT_CODE,
1016
+ CHANT_EXIT.held,
885
1017
  );
886
1018
  }
887
1019
  }
@@ -941,12 +1073,22 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
941
1073
  ...base,
942
1074
  approval: { status: "pending" },
943
1075
  status: "plan-failed",
944
- message: "A member failed to plan, so there is no plan to compare with the approved one. Nothing was applied.",
1076
+ message: set.policyDenied
1077
+ ? "The policy denied a member's plan, so nothing was applied."
1078
+ : "A member failed to plan, so there is no plan to compare with the approved one. Nothing was applied.",
945
1079
  }),
946
- 1,
1080
+ set.policyDenied ? CHANT_EXIT.denied : 1,
947
1081
  );
948
1082
  }
949
1083
 
1084
+ // #4552, ruling D: on the resource grain a pull request's locks name row keys, which only the plan knows.
1085
+ const lockTargets = lockTargetsOf(p.plan.order, set.locks);
1086
+ if (locks && anyResourceGrain(set.locks)) {
1087
+ const held = await heldLocksOf(p, pr, lockTargets);
1088
+ if (typeof held === "number") return held;
1089
+ if (held) return stop(prReport({ ...base, approval: { status: "pending" }, status: "refused", refusal: "locked", message: held }), CHANT_EXIT.held);
1090
+ }
1091
+
950
1092
  // #4022: keep the change set the gate binds on chant/lifecycle under its
951
1093
  // digest before deciding the gate, so the plan an approval bound, or the
952
1094
  // one a pending fact waits on, can be read once this job is gone.
@@ -966,7 +1108,7 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
966
1108
  // #4323: the after-gate hooks hear the decision, a refusal too; only a failure that would have applied changes the outcome.
967
1109
  const afterGate = await runGateHook(p, { op, digest: set.doc.digest, satisfied: decided.satisfied }, p.plan.order);
968
1110
  if (afterGate && decided.satisfied) return stop(prReport({ ...base, approval, status: "failed", message: afterGate }), 1);
969
- if (!decided.satisfied) return stop(prReport({ ...base, approval, status: "refused", refusal: decided.refusal, message: decided.message }), GATED_EXIT_CODE);
1111
+ if (!decided.satisfied) return stop(prReport({ ...base, approval, status: "refused", refusal: decided.refusal, message: decided.message }), decided.refusal === "plan-changed" ? CHANT_EXIT.moved : CHANT_EXIT.waiting);
970
1112
  via = decided.via;
971
1113
  }
972
1114
 
@@ -981,10 +1123,14 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
981
1123
  if (unspent) return stop(prReport({ ...base, approval, status: "refused", refusal: "policy-denied", message: unspent }), 1);
982
1124
  // #4293, #4301: under ci.locks an apply before merge holds its targets until the pull request merges or closes.
983
1125
  if (locks && beforeMerge && pr !== null) {
984
- const taken = await takeApplyLocks(p, pr);
1126
+ const taken = await takeApplyLocks(p, pr, lockTargets);
985
1127
  if (typeof taken === "number") return taken;
986
- if (taken) return stop(prReport({ ...base, approval, status: "refused", refusal: "locked", message: taken }), GATED_EXIT_CODE);
1128
+ if (taken) return stop(prReport({ ...base, approval, status: "refused", refusal: "locked", message: taken }), CHANT_EXIT.held);
987
1129
  }
1130
+ // #4552: on the resource grain the apply leases the rows it changes, whatever ci.locks says, and lets go when it ends.
1131
+ const lease = await leaseSetRows(p, set);
1132
+ if (typeof lease === "number") return lease;
1133
+ if ("held" in lease) return stop(prReport({ ...base, approval, status: "refused", refusal: "locked", message: lease.held }), CHANT_EXIT.held);
988
1134
 
989
1135
  // The record is written before the first component runs and again as each
990
1136
  // one settles, so a run killed partway still knows what applied.
@@ -1021,7 +1167,10 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1021
1167
  // #4288: the before-apply hooks, once the gate and the review let the apply through.
1022
1168
  const toApply = (resumed?.plan ?? p.plan).order.filter((name) => !completedSoFar.has(name));
1023
1169
  const beforeFailed = await runStageHook(p, "before-apply", toApply);
1024
- if (beforeFailed) return stop(prReport({ ...base, approval, status: "failed", message: beforeFailed }), 1);
1170
+ if (beforeFailed) {
1171
+ await lease.release();
1172
+ return stop(prReport({ ...base, approval, status: "failed", message: beforeFailed }), 1);
1173
+ }
1025
1174
 
1026
1175
  // #3999: a round planned after an upstream applied waits on a gate of its
1027
1176
  // own, under the same identity.gates rule and the same review checks.
@@ -1047,37 +1196,47 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1047
1196
  return { satisfied: true, approval: roundApproval };
1048
1197
  };
1049
1198
 
1050
- const applied = await applyPrSet({
1051
- components: p.components,
1052
- plan: resumed?.plan ?? p.plan,
1053
- registry: p.registry,
1054
- env: p.env,
1055
- set,
1056
- gate: p.gate,
1057
- approval,
1058
- decideRound,
1059
- ...(resumed ? { resumed: prior } : {}),
1060
- // The apply is this run's waves, so the fan-out's own run framing is
1061
- // dropped. The log's lines go to stderr with or without --events-json.
1062
- onRunEvent: (body: RunEventBody) => {
1063
- events?.nested(body);
1064
- log(body);
1065
- },
1066
- ...(resumePath
1067
- ? {
1068
- onComponentSettled: (settled, outputs) => {
1069
- if (settled.status === "ok") {
1070
- completedSoFar.add(settled.component);
1071
- if (inputsNow[settled.component] !== undefined) inputsSoFar[settled.component] = inputsNow[settled.component]!;
1072
- if (outputs) outputsSoFar[settled.component] = outputs;
1073
- } else if (settled.status === "fail") {
1074
- failedSoFar.push(settled.component);
1075
- }
1076
- recordAttempt();
1077
- },
1078
- }
1079
- : {}),
1080
- });
1199
+ const lockGrain = await declaredLockGrainOf(p);
1200
+ let applied: Awaited<ReturnType<typeof applyPrSet>>;
1201
+ try {
1202
+ applied = await applyPrSet({
1203
+ components: p.components,
1204
+ plan: resumed?.plan ?? p.plan,
1205
+ registry: p.registry,
1206
+ env: p.env,
1207
+ set,
1208
+ ...(lockGrain ? { lockGrain } : {}),
1209
+ policyBase: p.base,
1210
+ gate: p.gate,
1211
+ approval,
1212
+ decideRound,
1213
+ // #4594: a later round's plan may change rows the first did not, so it leases its own.
1214
+ leaseRound: leaseRoundRows(p),
1215
+ ...(resumed ? { resumed: prior } : {}),
1216
+ // The apply is this run's waves, so the fan-out's own run framing is
1217
+ // dropped. The log's lines go to stderr with or without --events-json.
1218
+ onRunEvent: (body: RunEventBody) => {
1219
+ events?.nested(body);
1220
+ log(body);
1221
+ },
1222
+ ...(resumePath
1223
+ ? {
1224
+ onComponentSettled: (settled, outputs) => {
1225
+ if (settled.status === "ok") {
1226
+ completedSoFar.add(settled.component);
1227
+ if (inputsNow[settled.component] !== undefined) inputsSoFar[settled.component] = inputsNow[settled.component]!;
1228
+ if (outputs) outputsSoFar[settled.component] = outputs;
1229
+ } else if (settled.status === "fail") {
1230
+ failedSoFar.push(settled.component);
1231
+ }
1232
+ recordAttempt();
1233
+ },
1234
+ }
1235
+ : {}),
1236
+ });
1237
+ } finally {
1238
+ await lease.release();
1239
+ }
1081
1240
  recordAttempt();
1082
1241
  // #4288: the after-apply hooks, for the components that applied.
1083
1242
  const afterFailed = await runStageHook(p, "after-apply", toApply.filter((name) => applied.run.completed.includes(name)), undefined, "the apply counts as failed though its components applied");
@@ -1089,12 +1248,23 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1089
1248
  members: applied.members,
1090
1249
  ...(resumed ? { resumed: resumed.completed } : {}),
1091
1250
  ...(applied.rounds ? { rounds: applied.rounds } : {}),
1092
- ...(applied.status === "waiting" ? { message: waitingMessage(op, applied.rounds) } : {}),
1251
+ ...(applied.held ? { message: applied.held } : applied.leaseFailed ? { message: applied.leaseFailed } : applied.status === "waiting" ? { message: waitingMessage(op, applied.rounds) } : {}),
1093
1252
  });
1094
1253
  // A component that stopped at a gate of its own leaves the apply waiting on
1095
1254
  // a person. A step that refused its plan because the target moved since
1096
- // the approval exits 3, as a moved digest does before anything applies (#3997).
1097
- const exit = afterFailed ? 1 : applied.status === "applied" ? 0 : applied.status === "waiting" ? GATED_EXIT_CODE : failedRunExitCode(applied.run.results);
1255
+ // the approval exits 4 (moved), as a moved digest does before anything applies (#3997, #4553).
1256
+ // A later round whose rows another run holds exits 5 (held, #4594).
1257
+ const exit = afterFailed
1258
+ ? 1
1259
+ : applied.held
1260
+ ? CHANT_EXIT.held
1261
+ : applied.status === "applied"
1262
+ ? 0
1263
+ : applied.status === "waiting"
1264
+ ? GATED_EXIT_CODE
1265
+ : applied.leaseFailed
1266
+ ? 1
1267
+ : failedRunExitCode(applied.run.results);
1098
1268
  if (green && applied.status === "applied") await recordGreenApplied(p, green, set.doc.digest, approval, via);
1099
1269
  const code = await stop(report, exit, applied.run.status === "gated" ? "gated" : undefined);
1100
1270
  if (applied.status === "applied" && !afterFailed) console.error(formatSuccess(`applied the plan ${report.digest} approved by ${(approval.approvedBy ?? []).join(", ")}`));
@@ -1109,12 +1279,12 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1109
1279
  * `--forge` every lock counts. A lock file that cannot be read stops the
1110
1280
  * apply, since nothing then says the targets are free.
1111
1281
  */
1112
- async function heldLocksOf(p: Prepared, pr: number | null): Promise<string | null | number> {
1282
+ async function heldLocksOf(p: Prepared, pr: number | null, targets: readonly string[] = p.plan.order): Promise<string | null | number> {
1113
1283
  const { heldTargetLocks, describeHeldTargetLocks } = await import("../../lifecycle/target-lock");
1114
1284
  const isOpen = p.forge?.pullRequestOpen?.bind(p.forge);
1115
1285
  let held;
1116
1286
  try {
1117
- held = await heldTargetLocks(p.gate, p.plan.order, pr, { ...(isOpen ? { isOpen } : {}) });
1287
+ held = await heldTargetLocks(p.gate, targets, pr, { ...(isOpen ? { isOpen } : {}) });
1118
1288
  } catch (err) {
1119
1289
  return fail(`could not read the target locks of ${p.gate}, so nothing was applied: ${err instanceof Error ? err.message : String(err)}`);
1120
1290
  }
@@ -1138,6 +1308,10 @@ async function beforeMergeChecks(ctx: CommandContext): Promise<PrBeforeMerge | n
1138
1308
  if (args.pr === undefined) return fail("--before-merge applies an open pull request, so it needs --pr <n>");
1139
1309
  if (!args.forge || !(FORGE_KINDS as readonly string[]).includes(args.forge)) return fail("--before-merge asks the forge whether the pull request is ready, so it needs --forge github|gitlab|forgejo");
1140
1310
  if (!args.base) return fail("pr-apply needs the commit the change is measured from: --base <ref>", "Before merge, the target branch's commit.");
1311
+ const { checkPrRequires, unmetRequires, parseRequiresList } = await import("../../pr-requires");
1312
+ // #4607: a product's `apply.requires` names the checks to ask; absent, all four.
1313
+ const only = args.requires ? parseRequiresList(args.requires) : undefined;
1314
+ if (only && "error" in only) return fail(only.error);
1141
1315
  const cwd = resolve(".");
1142
1316
  let forge: PrForge;
1143
1317
  let head: string;
@@ -1153,7 +1327,6 @@ async function beforeMergeChecks(ctx: CommandContext): Promise<PrBeforeMerge | n
1153
1327
  const gate = args.gate ?? PR_APPLY_GATE;
1154
1328
  const { ciWorkflowAt } = await import("../../workspace/ci-workflow-at");
1155
1329
  const { appliesBeforeMerge } = await import("../../workspace/ci-workflow");
1156
- const { checkPrRequires, unmetRequires } = await import("../../pr-requires");
1157
1330
  const workflow = ciWorkflowAt(cwd, args.base, member);
1158
1331
  const early = earlyStop(ctx, forge, { pr: args.pr, base, head, gate, ...(member ? { member } : {}) });
1159
1332
  if (!appliesBeforeMerge(workflow)) {
@@ -1165,9 +1338,10 @@ async function beforeMergeChecks(ctx: CommandContext): Promise<PrBeforeMerge | n
1165
1338
  );
1166
1339
  }
1167
1340
  // The apply's own statuses never hold it back: chant ci run's, and the report's.
1168
- const ignore = [`chant/${gate}`, `chant/${PR_APPLY_GATE}`, prStatusContext("apply", member)];
1169
- // No `only`: ws-106 gives the declaration no way to leave a check out, so all four are asked (#4336).
1170
- const requires = await checkPrRequires(forge, args.pr, head, { ignore });
1341
+ // #4550: under a product's words its own prefix too.
1342
+ const ignore = [...new Set([productContext(activeProductWords(), gate), productContext(activeProductWords(), PR_APPLY_GATE), `chant/${gate}`, `chant/${PR_APPLY_GATE}`, prStatusContext("apply", member)])];
1343
+ // ws-106 gives the declaration no way to leave a check out, so with no --requires all four are asked (#4336, #4607).
1344
+ const requires = await checkPrRequires(forge, args.pr, head, { ignore, ...(only ? { only: only.checks } : {}) });
1171
1345
  for (const r of requires) console.error(formatInfo(`${r.name}: ${r.passed ? "passed" : r.pending ? "pending" : "unmet"}, ${r.reason}`));
1172
1346
  const unmet = unmetRequires(requires);
1173
1347
  if (unmet) {
@@ -1194,13 +1368,13 @@ function earlyStop(ctx: CommandContext, forge: PrForge, at: { pr: number; base:
1194
1368
  * refusal when another open pull request holds one, null once taken, or the
1195
1369
  * exit code when the locks could not be written.
1196
1370
  */
1197
- async function takeApplyLocks(p: Prepared, pr: number): Promise<string | null | number> {
1371
+ async function takeApplyLocks(p: Prepared, pr: number, targets: readonly string[] = p.plan.order): Promise<string | null | number> {
1198
1372
  const { takeTargetLocks, describeHeldTargetLocks } = await import("../../lifecycle/target-lock");
1199
1373
  const isOpen = p.forge?.pullRequestOpen?.bind(p.forge);
1200
1374
  const by = process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_LOGIN ?? process.env.USER ?? "unknown";
1201
1375
  let result;
1202
1376
  try {
1203
- result = await takeTargetLocks(p.gate, p.plan.order, { pr, by, at: new Date().toISOString(), stage: "apply", head: p.head }, { ...(isOpen ? { isOpen } : {}) });
1377
+ result = await takeTargetLocks(p.gate, targets, { pr, by, at: new Date().toISOString(), stage: "apply", head: p.head }, { ...(isOpen ? { isOpen } : {}) });
1204
1378
  } catch (err) {
1205
1379
  return fail(`could not take the target locks of ${p.gate}, so nothing was applied: ${err instanceof Error ? err.message : String(err)}`);
1206
1380
  }
@@ -1552,6 +1726,11 @@ function settleWords(body: RunEventComponentSettle): string {
1552
1726
  * pr-apply's job log (#4007): a line on stderr as each wave starts and as
1553
1727
  * each component settles, so the log shows the waves in order while they run.
1554
1728
  */
1729
+ /** One wave's fan-out numbers its wave 1; the events and the log carry the derivation's number (#4003). */
1730
+ function inWave(body: RunEventBody, wave: number): RunEventBody {
1731
+ return "wave" in body && typeof (body as { wave?: unknown }).wave === "number" ? ({ ...body, wave } as RunEventBody) : body;
1732
+ }
1733
+
1555
1734
  function applyLog(): (body: RunEventBody) => void {
1556
1735
  let waves = 0;
1557
1736
  return (body) => {
@@ -1657,6 +1836,7 @@ async function tryResume(p: Prepared, attempt: FanOutAttempt, file: string, op:
1657
1836
  registry: p.registry,
1658
1837
  env: p.env,
1659
1838
  seededOutputs: p.seededOutputs,
1839
+ policyBase: p.base,
1660
1840
  record,
1661
1841
  completed,
1662
1842
  applied: outputs,
@@ -1714,22 +1894,20 @@ async function carryWaves(p: Prepared, attempt: FanOutAttempt, file: string, op:
1714
1894
  return { record, check, approval: approvalOf(check), completed, outputs };
1715
1895
  }
1716
1896
 
1717
- /** A run event with its wave renumbered to `wave`: the fan-out that applies one wave numbers it 1. */
1718
- function inWave(body: RunEventBody, wave: number): RunEventBody {
1719
- return "wave" in body && typeof (body as { wave?: unknown }).wave === "number" ? ({ ...body, wave } as RunEventBody) : body;
1720
- }
1721
-
1722
1897
  /**
1723
1898
  * `pr-apply --wave-gate <gate>` (#4003): apply the pull request's approved
1724
1899
  * set a wave at a time, each wave planned after the one before it applied.
1725
1900
  *
1726
1901
  * The first job plans every member, as pr-apply does, and decides the pull
1727
- * request's gate against that digest. Approved, wave 1 applies with those
1728
- * plans. Each later wave is planned again against the outputs the waves
1729
- * before it left. When the approved change set covers its plan
1730
- * (`planCoveredBy`, as on a resume) it applies under the pull request's
1731
- * approval; when it does not, it waits at `<gate>-wave-<k>` under the pull
1732
- * request's op for an approval of its new plan, and exits 3.
1902
+ * request's gate against that digest. The waves then run on op waves
1903
+ * (#4588): the component waves spec (`componentWavesSpec`), each run a
1904
+ * component, planned and applied through the component plan-wave and
1905
+ * apply-wave steps (`chant components plan-wave|apply-wave`). Each wave is
1906
+ * planned against the outputs the waves before it left. When the approved
1907
+ * change set covers its plan (`planCoveredBy`, the op waves' `pull-request`
1908
+ * approval) it applies under the pull request's approval; when it does not,
1909
+ * it waits at `<gate>-wave-<k>` under the pull request's op for an approval
1910
+ * of its new plan, and exits 3.
1733
1911
  *
1734
1912
  * With `--wave <k>` the job runs wave k and no other, reading the approved
1735
1913
  * set and the progress from the `--resume` record the job before it left.
@@ -1850,7 +2028,6 @@ async function prApplyWaves(
1850
2028
  );
1851
2029
  }
1852
2030
 
1853
- let planned: PrPlanSet | undefined;
1854
2031
  let judged: PolicyJudged = { held: false };
1855
2032
  if (carry) {
1856
2033
  // What the earlier waves applied settles first (#4007), each in its own wave, as a resumed apply's does.
@@ -1866,6 +2043,7 @@ async function prApplyWaves(
1866
2043
  const set = await planAll(p, events?.emit);
1867
2044
  approved = set;
1868
2045
  if (set.failed) {
2046
+ if (set.policyDenied) return stop(report({ status: "plan-failed", message: "The policy denied a member's plan, so nothing was applied." }), CHANT_EXIT.denied);
1869
2047
  return stop(report({ status: "plan-failed", message: "A member failed to plan, so there is no plan to compare with the approved one. Nothing was applied." }), 1);
1870
2048
  }
1871
2049
  await storeChangeSetForGate(ctx, p, set.doc);
@@ -1877,9 +2055,8 @@ async function prApplyWaves(
1877
2055
  // #4323: the after-gate hooks hear the decision, a refusal too.
1878
2056
  const afterGate = await runGateHook(p, { op, digest: set.doc.digest, satisfied: decided.satisfied }, p.plan.order);
1879
2057
  if (afterGate && decided.satisfied) return stop(report({ status: "failed", message: afterGate }), 1);
1880
- if (!decided.satisfied) return stop(report({ status: "refused", refusal: decided.refusal, message: decided.message }), GATED_EXIT_CODE);
2058
+ if (!decided.satisfied) return stop(report({ status: "refused", refusal: decided.refusal, message: decided.message }), decided.refusal === "plan-changed" ? CHANT_EXIT.moved : CHANT_EXIT.waiting);
1881
2059
  via = decided.via;
1882
- planned = set;
1883
2060
  }
1884
2061
  const approvedSet = approved!;
1885
2062
 
@@ -1923,8 +2100,11 @@ async function prApplyWaves(
1923
2100
  const from = only ?? (left || total + 1);
1924
2101
  const to = only ?? total;
1925
2102
  /** The last apply in this job that failed (#4291): its results give the exit code once every wave ran. */
1926
- let lastFailure: { results: Parameters<typeof failedRunExitCode>[0]; gated: boolean } | undefined;
2103
+ let lastFailure: { exitCode: number } | undefined;
1927
2104
  let planFailedIn: number | undefined;
2105
+ // #4588: the outputs file the waves' plan-wave and apply-wave steps hand outputs on in.
2106
+ const { componentWaveOutputsFile } = await import("../../components/product-pipeline");
2107
+ const outputsFile = componentWaveOutputsFile(op);
1928
2108
  for (let k = from; k <= to; k++) {
1929
2109
  // #4291: a component of this wave whose upstream failed, or was blocked by a failure, is blocked; the rest of the wave runs.
1930
2110
  const before = new Set(p.plan.waves.slice(0, k - 1).flat());
@@ -1943,138 +2123,59 @@ async function prApplyWaves(
1943
2123
  if (blockedNow.size > 0) recordAttempt();
1944
2124
  continue;
1945
2125
  }
1946
- const inThisWave = new Set(wavePlan.order);
1947
-
1948
- // Wave 1 of the apply that just planned every member applies those plans:
1949
- // they are the approved set's. Every other wave is planned again, against
1950
- // the outputs the waves before it left.
1951
- let set: PrPlanSet;
1952
- let entry: PrWave;
1953
- if (planned && k === 1) {
1954
- set = {
1955
- ...planned,
1956
- members: planned.members.filter((m) => inThisWave.has(m.component)),
1957
- plans: Object.fromEntries(Object.entries(planned.plans).filter(([name]) => inThisWave.has(name))),
1958
- };
1959
- entry = { wave: k, components: wavePlan.order, status: "applied", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest, ...(approval.approvedBy ? { approvedBy: approval.approvedBy } : {}) };
1960
- } else {
1961
- const notApplied = Object.fromEntries(Object.entries(approvedSet.outputs).filter(([name]) => !completed.has(name)));
1962
- const fresh = await hookedPlan(p, wavePlan.order, () =>
1963
- planPrSet({
1964
- components: p.components,
1965
- plan: wavePlan,
1966
- registry: p.registry,
1967
- env: p.env,
1968
- seededOutputs: { ...p.seededOutputs, ...notApplied, ...outputsSoFar },
1969
- ...(events ? { onRunEvent: (body: RunEventBody) => events.emit(body) } : {}),
1970
- }),
1971
- );
1972
- if (fresh.failed) {
1973
- for (const m of fresh.members) {
1974
- after.set(m.member, m);
1975
- if (m.status === "plan-failed") failedSoFar.add(m.component);
1976
- }
1977
- setWave({ wave: k, components: wavePlan.order, status: "plan-failed", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest });
1978
- // #4291: the later waves still run what does not depend on this wave.
1979
- console.error(formatWarning({ message: `A member of wave ${k} failed to plan, so nothing in wave ${k} was applied.`, hint: "The waves after it apply what does not depend on wave " + k + "." }));
1980
- planFailedIn ??= k;
1981
- continue;
1982
- }
1983
- const moved = waveNotCovered(approvedSet.doc, fresh.doc, approvedSet.members, { approved: approvedSet.shapes, fresh: fresh.shapes });
1984
- set = fresh;
1985
- if (moved.length === 0) {
1986
- console.error(formatInfo(`wave ${k}: the approved plan covers what it plans now, so it applies under the pull request's approval`));
1987
- entry = { wave: k, components: wavePlan.order, status: "applied", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest, ...(approval.approvedBy ? { approvedBy: approval.approvedBy } : {}) };
1988
- } else {
1989
- const gate = waveGateName(waveGate, k);
1990
- const digest = fresh.doc.digest;
1991
- console.error(formatInfo(`wave ${k}: its plan moved since the pull request's (${moved.join("; ")}), so it needs an approval of ${gate}`));
1992
- await storeChangeSetForGate(ctx, p, fresh.doc);
1993
- writeWaveChangeSet(ctx, k, fresh.doc, upload);
1994
- const approveLine = prApproveCommand({ op, gate, digest });
1995
- const check = await emitGateStep(
1996
- events?.emit,
1997
- { op, gate },
1998
- () => decidePrGate(gitGateLedgerPort(), { op, gate, digest, description: `${changeLabel(pr, green)}, wave ${k} of ${total}: ${wavePlan.order.join(", ")}` }),
1999
- (unapproved) =>
2000
- unapproved.mismatch
2001
- ? `wave ${k}'s plan changed after its approval. Approve the plan now: ${approveLine}`
2002
- : `wave ${k}'s plan is not the one the pull request approved. Approve it: ${approveLine}`,
2003
- );
2004
- const waveApproval = approvalOf(check);
2005
- const waiting: PrWave = {
2006
- wave: k,
2007
- components: wavePlan.order,
2008
- status: "waiting",
2009
- approval: "wave",
2010
- gate,
2011
- digest,
2012
- moved,
2013
- ...(waveApproval.approved ? { approved: waveApproval.approved } : {}),
2014
- };
2015
- if (!check.satisfied) {
2016
- setWave(waiting);
2017
- const message =
2018
- waveApproval.status === "changed"
2019
- ? `Wave ${k}'s plan changed after its approval, so nothing in it was applied. approved: ${waveApproval.approved ?? "(none)"}; planned now: ${digest}. ` +
2020
- `Read the new plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`
2021
- : `Wave ${k} was planned after the waves before it applied, and the pull request's approved plan does not cover it: ${moved.join("; ")}. ` +
2022
- `Nothing in wave ${k} was applied. Read its plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`;
2023
- return stop(report({ status: "refused", refusal: waveApproval.status === "changed" ? "wave-plan-changed" : "wave-not-approved", message }), GATED_EXIT_CODE);
2024
- }
2025
- const waveReview = await review(waveApproval.approvedBy ?? [], `Wave ${k}'s plan`);
2026
- if (waveReview && "error" in waveReview) return fail(waveReview.error);
2027
- if (waveReview) {
2028
- setWave(waiting);
2029
- emitReviewStop(events, waveReview.message);
2030
- return stop(report({ status: "refused", refusal: waveReview.refusal, message: waveReview.message }), GATED_EXIT_CODE);
2031
- }
2032
- entry = { wave: k, components: wavePlan.order, status: "applied", approval: "wave", gate, digest, moved, ...(waveApproval.approvedBy ? { approvedBy: waveApproval.approvedBy } : {}) };
2033
- }
2034
- }
2035
-
2126
+ // #4588: the wave plans, waits or passes its gate, and applies on op waves: the component waves spec,
2127
+ // each run a component, through the component plan-wave and apply-wave steps.
2128
+ const pending: PrWave = { wave: k, components: wavePlan.order, status: "applied", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest };
2036
2129
  // #4288: the wave's apply-side hooks, around its apply.
2037
2130
  const waveBefore = await runStageHook(p, "before-apply", wavePlan.order, undefined, `nothing in wave ${k} was applied`);
2038
2131
  if (waveBefore) {
2039
- setWave({ ...entry, status: "failed" });
2132
+ setWave({ ...pending, status: "failed" });
2040
2133
  return stop(report({ status: "failed", message: waveBefore }), 1);
2041
2134
  }
2042
- const applied = await applyPrSet({
2043
- components: p.components,
2044
- plan: wavePlan,
2045
- registry: p.registry,
2046
- env: p.env,
2047
- set,
2048
- // One wave's fan-out numbers its wave 1; the events and the log carry the derivation's number.
2049
- onRunEvent: (body: RunEventBody) => {
2050
- const numbered = inWave(body, k);
2051
- events?.nested(numbered);
2052
- if (numbered.type !== "run-start") log(numbered);
2053
- },
2054
- onComponentSettled: (settled, outputs) => {
2055
- if (settled.status === "ok") {
2056
- completed.add(settled.component);
2057
- failedSoFar.delete(settled.component);
2058
- if (inputsNow[settled.component] !== undefined) inputsSoFar[settled.component] = inputsNow[settled.component]!;
2059
- if (outputs) outputsSoFar[settled.component] = outputs;
2060
- } else if (settled.status === "fail") {
2061
- failedSoFar.add(settled.component);
2062
- }
2063
- recordAttempt();
2064
- },
2065
- });
2066
- for (const m of applied.members) after.set(m.member, m);
2067
- for (const name of applied.run.completed) {
2135
+ // The outputs the waves before this one left, and the approved set's for what has not applied yet, seed its plans.
2136
+ const notApplied = Object.fromEntries(Object.entries(approvedSet.outputs).filter(([name]) => !completed.has(name)));
2137
+ mkdirSync(dirname(resolve(outputsFile)), { recursive: true });
2138
+ writeFileSync(resolve(outputsFile), JSON.stringify({ ...p.seededOutputs, ...notApplied, ...outputsSoFar }, null, 2) + "\n");
2139
+ const ran = await runComponentWave(p, { op, waveGate, k, runs: wavePlan.order, approved: approvedSet.doc, approvedBy: approval.approvedBy ?? [], outputsFile, ...(args.noReleaseRecord ? { noReleaseRecord: true } : {}), review, ...(events ? { events } : {}), log });
2140
+ const entry = ran.entry;
2141
+ if (ran.review && "error" in ran.review) return fail(ran.review.error);
2142
+ if (ran.review && ran.exitCode === CHANT_EXIT.waiting) {
2143
+ setWave(entry);
2144
+ emitReviewStop(events, ran.review.message);
2145
+ return stop(report({ status: "refused", refusal: ran.review.refusal, message: ran.review.message }), GATED_EXIT_CODE);
2146
+ }
2147
+ for (const name of ran.applied) {
2068
2148
  completed.add(name);
2069
- const outputs = applied.run.componentOutputs[name];
2070
- if (outputs) outputsSoFar[name] = outputs;
2149
+ failedSoFar.delete(name);
2150
+ if (inputsNow[name] !== undefined) inputsSoFar[name] = inputsNow[name]!;
2151
+ if (ran.outputs[name]) outputsSoFar[name] = ran.outputs[name]!;
2152
+ }
2153
+ for (const name of ran.failed) failedSoFar.add(name);
2154
+ if (ran.exitCode === CHANT_EXIT.waiting || ran.exitCode === CHANT_EXIT.moved) {
2155
+ setWave(entry);
2156
+ // #4003: the wave's new plan beside the report, for whoever approves its gate.
2157
+ if (ran.changeSet) writeWaveChangeSet(ctx, k, ran.changeSet, upload);
2158
+ const approveLine = prApproveCommand({ op, gate: entry.gate, digest: entry.digest });
2159
+ const message =
2160
+ ran.exitCode === CHANT_EXIT.moved
2161
+ ? `Wave ${k}'s plan changed after its approval, so nothing in it was applied.${entry.approved ? ` approved: ${entry.approved}; planned now: ${entry.digest}.` : ""} Read the new plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`
2162
+ : `Wave ${k} was planned after the waves before it applied, and the pull request's approved plan does not cover it${entry.moved?.length ? `: ${entry.moved.join("; ")}` : ""}. ` +
2163
+ `Nothing in wave ${k} was applied. Read its plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`;
2164
+ return stop(report({ status: "refused", refusal: ran.exitCode === CHANT_EXIT.moved ? "wave-plan-changed" : "wave-not-approved", message }), ran.exitCode);
2165
+ }
2166
+ if (ran.exitCode === CHANT_EXIT.held) {
2167
+ setWave({ ...entry, status: "waiting" });
2168
+ return stop(report({ status: "refused", refusal: "locked", message: `Wave ${k}: another run holds what it changes, so nothing in it was applied.` }), CHANT_EXIT.held);
2169
+ }
2170
+ if (ran.exitCode === CHANT_EXIT.denied || ran.exitCode === CHANT_EXIT.declined || ran.exitCode === CHANT_EXIT.superseded) {
2171
+ setWave({ ...entry, status: "failed" });
2172
+ return stop(report({ status: "failed", message: `Wave ${k} stopped on op waves with exit ${ran.exitCode}; nothing more was applied.` }), ran.exitCode);
2071
2173
  }
2072
- const waveAfter = await runStageHook(p, "after-apply", wavePlan.order.filter((name) => applied.run.completed.includes(name)), undefined, `wave ${k} counts as failed though its components applied`);
2073
- setWave({ ...entry, status: applied.status === "applied" && !waveAfter ? "applied" : "failed" });
2074
- await recordAutoReleasesForRun(applied.run.results, p.env, at.release.runId, resolveAutoReleaseDisabled(p.config, args.noReleaseRecord), at.release.runOrigin, undefined, undefined, prAppliedDigests(p, applied.members));
2075
- if (applied.status !== "applied") {
2174
+ const waveAfter = await runStageHook(p, "after-apply", wavePlan.order.filter((name) => ran.applied.includes(name)), undefined, `wave ${k} counts as failed though its components applied`);
2175
+ setWave({ ...entry, status: ran.exitCode === CHANT_EXIT.done && !waveAfter ? "applied" : "failed" });
2176
+ if (ran.exitCode !== CHANT_EXIT.done) {
2076
2177
  // #4291: a failed member blocks only its dependents, so the later waves still run.
2077
- lastFailure = { results: applied.run.results, gated: applied.run.status === "gated" };
2178
+ lastFailure = { exitCode: ran.exitCode };
2078
2179
  recordAttempt();
2079
2180
  continue;
2080
2181
  }
@@ -2091,8 +2192,7 @@ async function prApplyWaves(
2091
2192
  : blockedLine ? blockedLine.trim() : undefined;
2092
2193
  return stop(
2093
2194
  report({ status: "failed", ...(message ? { message } : {}) }),
2094
- lastFailure ? failedRunExitCode(lastFailure.results) : 1,
2095
- lastFailure?.gated ? "gated" : undefined,
2195
+ lastFailure ? lastFailure.exitCode : 1,
2096
2196
  );
2097
2197
  }
2098
2198
 
@@ -2101,6 +2201,356 @@ async function prApplyWaves(
2101
2201
  return stop(report({ status: done ? "applied" : "wave-applied" }), 0);
2102
2202
  }
2103
2203
 
2204
+ // ── The component plan-wave and apply-wave steps (#4588) ─────────────────────
2205
+
2206
+ /** The outputs earlier waves' components left, from `--wave-outputs`; empty when the file is not there yet. */
2207
+ function readWaveOutputs(file: string | undefined): { outputs: Record<string, Record<string, unknown>> } | { error: string } {
2208
+ if (!file || !existsSync(resolve(file))) return { outputs: {} };
2209
+ try {
2210
+ const parsed = JSON.parse(readFileSync(resolve(file), "utf8")) as unknown;
2211
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { error: `--wave-outputs ${file} must hold { "<component>": { ...outputs } }` };
2212
+ return { outputs: parsed as Record<string, Record<string, unknown>> };
2213
+ } catch (err) {
2214
+ return { error: `--wave-outputs: could not read "${file}": ${err instanceof Error ? err.message : String(err)}` };
2215
+ }
2216
+ }
2217
+
2218
+ /** The runs `chant run wave` wrote to `{runs}`: their targets, each a component, and on apply-wave the digest each was approved at. */
2219
+ function readWaveRuns(file: string | undefined): Array<{ target: string; planDigest?: string }> | { error: string } {
2220
+ if (!file) return { error: "the step needs --runs <file>, which chant run wave fills in as {runs}" };
2221
+ try {
2222
+ const parsed = JSON.parse(readFileSync(resolve(file), "utf8")) as { runs?: unknown };
2223
+ if (!Array.isArray(parsed?.runs)) return { error: `--runs ${file} has no runs` };
2224
+ return (parsed.runs as Array<{ target?: unknown; planDigest?: unknown }>).flatMap((r) =>
2225
+ typeof r?.target === "string" ? [{ target: r.target, ...(typeof r.planDigest === "string" ? { planDigest: r.planDigest } : {}) }] : [],
2226
+ );
2227
+ } catch (err) {
2228
+ return { error: `--runs: could not read "${file}": ${err instanceof Error ? err.message : String(err)}` };
2229
+ }
2230
+ }
2231
+
2232
+ /** The fan-out plan of `names`, one wave of the derivation, with the rest of that wave counted as done. */
2233
+ function namedWavePlan(p: Prepared, names: readonly string[]): FanOutPlan | { error: string } {
2234
+ const unknown = names.filter((n) => !p.plan.order.includes(n));
2235
+ if (unknown.length > 0) return { error: `${unknown.join(", ")} ${unknown.length === 1 ? "is" : "are"} not in the change between ${p.base.slice(0, 12)} and ${p.head.slice(0, 12)}, so the wave cannot plan ${unknown.length === 1 ? "it" : "them"}` };
2236
+ const k = p.plan.waves.findIndex((w) => w.includes(names[0]!)) + 1;
2237
+ const wave = p.plan.waves[k - 1] ?? [];
2238
+ const across = names.filter((n) => !wave.includes(n));
2239
+ if (across.length > 0) return { error: `${names[0]} and ${across.join(", ")} are in different waves of the derivation, so one wave step cannot plan them together` };
2240
+ return prWavePlan(p.plan, p.components, k, wave.filter((n) => !names.includes(n)));
2241
+ }
2242
+
2243
+ /** One component's entry in the op-waves plans file: the digest over its members' plans, and whether it changes or destroys anything. */
2244
+ function componentPlanEntry(set: PrPlanSet, component: string): { target: string; planDigest: string; empty?: true; destructive?: true } {
2245
+ const members = set.members.filter((m) => m.component === component).sort((a, b) => a.member.localeCompare(b.member));
2246
+ const names = new Set(members.map((m) => m.member));
2247
+ const entries = set.doc.entries.filter((e) => names.has(e.member));
2248
+ const changes = entries.filter((e) => e.action !== "no-op" && e.action !== "read");
2249
+ const destructive = changes.some((e) => e.action === "delete" || e.action === "replace");
2250
+ return {
2251
+ target: component,
2252
+ planDigest: computePlanDigest("component-wave", members.map((m) => ({ member: m.member, planDigest: m.planDigest }))),
2253
+ ...(changes.length === 0 ? { empty: true as const } : {}),
2254
+ ...(destructive ? { destructive: true as const } : {}),
2255
+ };
2256
+ }
2257
+
2258
+ /** The files a component wave step names: `{runs}`, `{plans}` and the outputs file. */
2259
+ interface WaveStepFiles {
2260
+ runs: Array<{ target: string; planDigest?: string }>;
2261
+ plansFile: string;
2262
+ outputsFile?: string;
2263
+ outputs: Record<string, Record<string, unknown>>;
2264
+ }
2265
+
2266
+ /** Read the step's runs and outputs files from its flags. */
2267
+ function waveStepFiles(args: Pick<CommandContext["args"], "runsFile" | "plansFile" | "waveOutputs">): WaveStepFiles | { error: string } {
2268
+ const runs = readWaveRuns(args.runsFile);
2269
+ if ("error" in runs) return runs;
2270
+ if (!args.plansFile) return { error: "the step needs --plans <file>, which chant run wave fills in as {plans}" };
2271
+ const read = readWaveOutputs(args.waveOutputs);
2272
+ if ("error" in read) return read;
2273
+ return { runs, plansFile: args.plansFile, ...(args.waveOutputs ? { outputsFile: args.waveOutputs } : {}), outputs: read.outputs };
2274
+ }
2275
+
2276
+ /** Plan the step's runs, each a component, against the outputs the earlier waves left. */
2277
+ async function planComponentRuns(p: Prepared, files: WaveStepFiles): Promise<{ set: PrPlanSet; plan: FanOutPlan } | { error: string }> {
2278
+ const names = files.runs.map((r) => r.target);
2279
+ const plan = names.length > 0 ? namedWavePlan(p, names) : { ...p.plan, order: [], waves: [] };
2280
+ if ("error" in plan) return plan;
2281
+ const lockGrain = await declaredLockGrainOf(p);
2282
+ const set = await planPrSet({ components: p.components, plan, registry: p.registry, env: p.env, seededOutputs: { ...p.seededOutputs, ...files.outputs }, ...(lockGrain ? { lockGrain } : {}), policyBase: p.base });
2283
+ return { set, plan };
2284
+ }
2285
+
2286
+ /** The plan step over `p`: write `{plans}`, one digest per component and the wave's change set. */
2287
+ async function planComponentWave(p: Prepared, files: WaveStepFiles): Promise<number> {
2288
+ const planned = await planComponentRuns(p, files);
2289
+ if ("error" in planned) return fail(planned.error);
2290
+ const { set } = planned;
2291
+ if (set.failed) {
2292
+ for (const m of set.members.filter((x) => x.status === "plan-failed")) console.error(formatError({ message: `${m.member} (${m.component}) failed to plan${m.error ? `: ${m.error}` : ""}` }));
2293
+ return set.policyDenied ? CHANT_EXIT.denied : 1;
2294
+ }
2295
+ const file = { runs: files.runs.map((r) => componentPlanEntry(set, r.target)), changeSet: set.doc };
2296
+ mkdirSync(dirname(resolve(files.plansFile)), { recursive: true });
2297
+ writeFileSync(resolve(files.plansFile), JSON.stringify(file, null, 2) + "\n");
2298
+ console.error(formatInfo(`planned ${files.runs.length} component${files.runs.length === 1 ? "" : "s"}: ${files.runs.map((r) => r.target).join(", ") || "(none)"}; change set ${set.doc.digest}`));
2299
+ return 0;
2300
+ }
2301
+
2302
+ /** The apply step over `p`: plan the approved runs again, refuse a moved one with 4, else lease, apply, record, and hand the outputs on. */
2303
+ async function applyComponentWave(p: Prepared, files: WaveStepFiles, opts: { noReleaseRecord?: boolean; onRunEvent?: RunEventSink; runsResult?: string } = {}): Promise<number> {
2304
+ if (files.runs.length === 0) return 0;
2305
+ const planned = await planComponentRuns(p, files);
2306
+ if ("error" in planned) return fail(planned.error);
2307
+ const { set, plan } = planned;
2308
+ if (set.failed) return fail("A component of the wave failed to plan again, so nothing in it was applied.");
2309
+ const moved = files.runs.filter((r) => r.planDigest !== undefined && !samePlanDigest(componentPlanEntry(set, r.target).planDigest, r.planDigest));
2310
+ if (moved.length > 0) {
2311
+ console.error(formatError({ message: `${moved.map((r) => r.target).join(", ")} now plan${moved.length === 1 ? "s" : ""} something other than the approved plan, so nothing in the wave was applied.`, hint: "Run the wave's job again to plan it afresh and decide its gate." }));
2312
+ return CHANT_EXIT.moved;
2313
+ }
2314
+ const lease = await leaseSetRows(p, set);
2315
+ if (typeof lease === "number") return lease;
2316
+ if ("held" in lease) {
2317
+ console.error(formatError({ message: lease.held }));
2318
+ return CHANT_EXIT.held;
2319
+ }
2320
+ const lockGrain = await declaredLockGrainOf(p);
2321
+ const release = autoReleaseRun(`wave-${Date.now()}`);
2322
+ let applied: Awaited<ReturnType<typeof applyPrSet>>;
2323
+ try {
2324
+ applied = await applyPrSet({ components: p.components, plan, registry: p.registry, env: p.env, set, gate: p.gate, ...(lockGrain ? { lockGrain } : {}), policyBase: p.base, ...(opts.onRunEvent ? { onRunEvent: opts.onRunEvent } : {}) });
2325
+ } finally {
2326
+ await lease.release();
2327
+ }
2328
+ await recordAutoReleasesForRun(applied.run.results, p.env, release.runId, resolveAutoReleaseDisabled(p.config, opts.noReleaseRecord), release.runOrigin, undefined, undefined, prAppliedDigests(p, applied.members));
2329
+ if (files.outputsFile) {
2330
+ const next = { ...files.outputs };
2331
+ for (const name of applied.run.completed) next[name] = applied.run.componentOutputs[name] ?? {};
2332
+ mkdirSync(dirname(resolve(files.outputsFile)), { recursive: true });
2333
+ writeFileSync(resolve(files.outputsFile), JSON.stringify(next, null, 2) + "\n");
2334
+ }
2335
+ for (const m of applied.members) console.error(m.status === "applied" ? formatSuccess(`applied ${m.member} (${m.component})`) : formatWarning({ message: `${m.member} (${m.component}): ${m.status}${m.error ? `, ${m.error}` : ""}` }));
2336
+ // #4291: the components that applied, so op waves fails only the others and blocks only what depends on them.
2337
+ const runsResult = opts.runsResult ?? (process.env.CHANT_APPLY_RUNS_RESULT ? resolve(process.env.CHANT_APPLY_RUNS_RESULT) : undefined);
2338
+ if (runsResult && applied.status !== "applied") {
2339
+ mkdirSync(dirname(runsResult), { recursive: true });
2340
+ writeFileSync(runsResult, JSON.stringify({ applied: [...applied.run.completed].sort() }, null, 2) + "\n");
2341
+ }
2342
+ return applied.status === "applied" ? 0 : applied.status === "waiting" ? CHANT_EXIT.waiting : 1;
2343
+ }
2344
+
2345
+ /**
2346
+ * `chant components plan-wave --runs <file> --plans <file> --base <ref>
2347
+ * --env <env> [--member <m>] [--wave-outputs <file>]` (#4588): the
2348
+ * component plan step of a component waves spec. Plans each run, a
2349
+ * component, through the project's capabilities against the outputs the
2350
+ * waves before it left, and writes `{plans}`: one digest per component over
2351
+ * its members' plans, and the wave's change set, which a `pull-request`
2352
+ * wave checks the pull request's approval against.
2353
+ */
2354
+ export async function runComponentsPlanWave(ctx: CommandContext): Promise<number> {
2355
+ const files = waveStepFiles(ctx.args);
2356
+ if ("error" in files) return fail(files.error);
2357
+ const p = await prepare(ctx, "apply");
2358
+ if (typeof p === "number") return p;
2359
+ return planComponentWave(p, files);
2360
+ }
2361
+
2362
+ /**
2363
+ * `chant components apply-wave --runs <file> --plans <file> --base <ref>
2364
+ * --env <env> [--member <m>] [--wave-outputs <file>]` (#4588): the
2365
+ * component apply step. Plans the approved runs again and exits 4 when a
2366
+ * component's plan is not the one approved; else leases its rows on the
2367
+ * resource grain, applies, records the releases, and adds each applied
2368
+ * component's outputs to `--wave-outputs` for the next wave.
2369
+ */
2370
+ export async function runComponentsApplyWave(ctx: CommandContext): Promise<number> {
2371
+ const files = waveStepFiles(ctx.args);
2372
+ if ("error" in files) return fail(files.error);
2373
+ const p = await prepare(ctx, "apply");
2374
+ if (typeof p === "number") return p;
2375
+ return applyComponentWave(p, files, { noReleaseRecord: ctx.args.noReleaseRecord });
2376
+ }
2377
+
2378
+ /**
2379
+ * The component steps in this process (#4588): `pr-apply --wave-gate`
2380
+ * already holds the prepared project, so the plan-wave and apply-wave lines
2381
+ * of its spec run here against it, rather than in a process that would
2382
+ * derive the change again.
2383
+ */
2384
+ function componentWaveExec(p: Prepared, noReleaseRecord?: boolean, onRunEvent?: RunEventSink): (argv: string[], cwd: string, env?: Record<string, string>) => Promise<number> {
2385
+ return async (argv, cwd, env) => {
2386
+ const at = argv.findIndex((a, i) => a === "components" && (argv[i + 1] === "plan-wave" || argv[i + 1] === "apply-wave"));
2387
+ if (at < 0) return fail(`not a component wave step: ${argv.join(" ")}`);
2388
+ let args: CommandContext["args"];
2389
+ try {
2390
+ args = parseArgs(argv.slice(at));
2391
+ } catch (err) {
2392
+ return fail(err instanceof Error ? err.message : String(err));
2393
+ }
2394
+ const files = waveStepFiles(args);
2395
+ if ("error" in files) return fail(files.error);
2396
+ const runsResult = env?.CHANT_APPLY_RUNS_RESULT ? resolve(cwd, env.CHANT_APPLY_RUNS_RESULT) : undefined;
2397
+ return argv[at + 1] === "plan-wave" ? planComponentWave(p, files) : applyComponentWave(p, files, { noReleaseRecord, ...(onRunEvent ? { onRunEvent } : {}), ...(runsResult ? { runsResult } : {}) });
2398
+ };
2399
+ }
2400
+
2401
+ /**
2402
+ * A gate ledger that holds the approval `pr-apply` already decided (#4588):
2403
+ * an approval of the pull request's gate under its op, for the approved
2404
+ * change set, so an op wave of the component waves spec finds the approval
2405
+ * a pull request (or a green commit's merges) gave and checks its own plan
2406
+ * against it. Everything else is the real ledger's.
2407
+ */
2408
+ function withDecidedApproval(port: GateLedgerPort, at: { op: string; gate: string; digest: string; approvedBy: string[]; timestamp: string }): GateLedgerPort {
2409
+ return {
2410
+ ...port,
2411
+ appendPending: (input) => port.appendPending(input),
2412
+ async read(op) {
2413
+ const got = await port.read(op);
2414
+ if (op !== at.op) return got;
2415
+ const decided: GateResolutionRecord = { version: 1, kind: "resolution", op: at.op, gate: at.gate, resolvedBy: at.approvedBy.join(", ") || "pr-apply", timestamp: at.timestamp, planDigest: at.digest, changeSet: at.digest };
2416
+ return { ...got, resolutions: [...got.resolutions, decided] };
2417
+ },
2418
+ };
2419
+ }
2420
+
2421
+ /**
2422
+ * The review rule on a wave's own gate (#4000, #4588): `--require-review`
2423
+ * judges an approval of the wave's gate as it judges the pull request's, so
2424
+ * an approval it refuses never reaches the op wave, which then waits. The
2425
+ * refusal is kept in `refused` for pr-apply's report. The pull request's gate
2426
+ * was judged before the waves ran, so its approvals pass as they are.
2427
+ */
2428
+ function withWaveReview(port: GateLedgerPort, at: { prGate: string; what: string; review: (approvedBy: readonly string[], what: string) => Promise<ReviewStop>; refused: { stop?: ReviewStop } }): GateLedgerPort {
2429
+ return {
2430
+ ...port,
2431
+ async read(op) {
2432
+ const got = await port.read(op);
2433
+ const resolutions: GateResolutionRecord[] = [];
2434
+ for (const r of got.resolutions) {
2435
+ const stop = r.gate === at.prGate ? undefined : await at.review([r.resolvedBy], at.what);
2436
+ if (stop) at.refused.stop ??= stop;
2437
+ else resolutions.push(r);
2438
+ }
2439
+ return { ...got, resolutions };
2440
+ },
2441
+ };
2442
+ }
2443
+
2444
+ /** What one wave of `pr-apply --wave-gate` on op waves came to (#4588). */
2445
+ interface ComponentWaveOutcome {
2446
+ exitCode: number;
2447
+ applied: string[];
2448
+ failed: string[];
2449
+ entry: PrWave;
2450
+ /** The wave's outputs file after it ran. */
2451
+ outputs: Record<string, Record<string, unknown>>;
2452
+ /** The wave's new plan, when it planned: what an approval of its own gate is asked for. */
2453
+ changeSet?: PrPlanSet["doc"];
2454
+ /** Why `--require-review` refused an approval of the wave's own gate (#4000). */
2455
+ review?: ReviewStop;
2456
+ }
2457
+
2458
+ /**
2459
+ * Run wave `k` of `pr-apply --wave-gate` on op waves (#4588): the component
2460
+ * waves spec with the wave's runs left to apply, read at base as chant
2461
+ * wrote it (the spec is chant's, never the change's), decided under the
2462
+ * approval pr-apply holds, planned and applied through the component
2463
+ * plan-wave and apply-wave steps.
2464
+ */
2465
+ async function runComponentWave(
2466
+ p: Prepared,
2467
+ at: {
2468
+ op: string;
2469
+ waveGate: string;
2470
+ k: number;
2471
+ runs: string[];
2472
+ approved: PrPlanSet["doc"];
2473
+ approvedBy: string[];
2474
+ outputsFile: string;
2475
+ noReleaseRecord?: boolean;
2476
+ review: (approvedBy: readonly string[], what: string) => Promise<ReviewStop>;
2477
+ events?: RunEventStream;
2478
+ log: (body: RunEventBody) => void;
2479
+ },
2480
+ ): Promise<ComponentWaveOutcome> {
2481
+ const { componentWavesSpec, componentWaveSteps, PRODUCT_WAVES_SPEC_DIR: PRODUCT_WAVES_DIR } = await import("../../components/product-pipeline");
2482
+ const { runOpWave, opWavePlansPath } = await import("../../op/op-waves-run");
2483
+ const words = activeProductWords();
2484
+ const cwd = resolve(".");
2485
+ const steps = componentWaveSteps({ ...(words.bin ? { bin: words.bin } : {}), env: p.env, base: p.base, head: p.head, ...(p.member ? { member: p.member } : {}), op: at.op, gate: p.gate, outputs: at.outputsFile });
2486
+ const waves = p.plan.waves.map((w, i) => (i === at.k - 1 ? at.runs : w));
2487
+ const spec = componentWavesSpec(p.components, words, steps, { op: at.op, gate: at.waveGate, prGate: p.gate, waves });
2488
+ const specFile = `${PRODUCT_WAVES_DIR}/${at.op}.spec.json`;
2489
+ const refused: { stop?: ReviewStop } = {};
2490
+ const result = await runOpWave({
2491
+ spec,
2492
+ specFile,
2493
+ wave: at.k,
2494
+ base: p.base,
2495
+ head: p.head,
2496
+ cwd,
2497
+ show: () => ({ sha: p.base, text: JSON.stringify(spec) }),
2498
+ gates: withWaveReview(withDecidedApproval(gitGateLedgerPort(), { op: at.op, gate: p.gate, digest: at.approved.digest, approvedBy: at.approvedBy, timestamp: new Date().toISOString() }), {
2499
+ prGate: p.gate,
2500
+ what: `Wave ${at.k}'s plan`,
2501
+ review: at.review,
2502
+ refused,
2503
+ }),
2504
+ // pr-apply's report and the `chant ci run` record stand for the job, so the wave writes no op-wave run record beside them.
2505
+ runs: { append: async () => {} },
2506
+ changeSets: async (digest) => {
2507
+ if (samePlanDigest(digest, at.approved.digest)) return at.approved;
2508
+ const { readStoredChangeSet } = await import("../../lifecycle/change-set-store");
2509
+ const got = await readStoredChangeSet(digest, { cwd });
2510
+ return got.status === "found" ? got.document : undefined;
2511
+ },
2512
+ lockGate: p.gate,
2513
+ // The apply's run events nest in pr-apply's stream with the derivation's wave number, as its log does.
2514
+ waveExec: componentWaveExec(p, at.noReleaseRecord, (body) => {
2515
+ const numbered = inWave(body, at.k);
2516
+ at.events?.nested(numbered);
2517
+ if (numbered.type !== "run-start") at.log(numbered);
2518
+ }),
2519
+ // The outcome files of this commit's waves alone, so a run of another commit on the same checkout blocks nothing here.
2520
+ outcomeDir: `${PRODUCT_WAVES_DIR}/${at.op}/outcomes-${p.head.slice(0, 12)}`,
2521
+ });
2522
+ const d = result.decision;
2523
+ const byPullRequest = d?.via === "pull-request";
2524
+ // #4553: an approval of the wave's own gate stands, but for another plan: the plan moved after its approval.
2525
+ const exitCode = result.exitCode === CHANT_EXIT.waiting && !byPullRequest && d?.mismatch && !refused.stop ? CHANT_EXIT.moved : result.exitCode;
2526
+ const entry: PrWave = {
2527
+ wave: at.k,
2528
+ components: at.runs,
2529
+ status: exitCode === CHANT_EXIT.done ? "applied" : exitCode === CHANT_EXIT.waiting || exitCode === CHANT_EXIT.moved ? "waiting" : "failed",
2530
+ approval: byPullRequest || !d ? "pull-request" : "wave",
2531
+ gate: byPullRequest || !d ? p.gate : d.gate,
2532
+ digest: byPullRequest || !d ? at.approved.digest : d.digest,
2533
+ ...(byPullRequest ? (at.approvedBy.length > 0 ? { approvedBy: at.approvedBy } : {}) : d?.approvedBy ? { approvedBy: [d.approvedBy] } : {}),
2534
+ ...(!byPullRequest && d?.coveredBy?.reason ? { moved: [d.coveredBy.reason] } : {}),
2535
+ ...(!byPullRequest && d?.mismatch?.approved ? { approved: d.mismatch.approved } : {}),
2536
+ };
2537
+ // A wave that waits at its own gate is the stream's gate step there, as before op waves (#4003).
2538
+ if (d && !byPullRequest && (exitCode === CHANT_EXIT.waiting || exitCode === CHANT_EXIT.moved)) {
2539
+ const waiting = { satisfied: false, pending: { op: at.op }, ...(d.mismatch ? { mismatch: d.mismatch } : {}) } as unknown as GateCheck;
2540
+ await emitGateStep(at.events?.emit, { op: at.op, gate: d.gate }, async () => waiting, () =>
2541
+ d.mismatch ? `wave ${at.k}'s plan changed after its approval. Approve the plan now: ${prApproveCommand({ op: at.op, gate: d.gate, digest: d.digest })}` : `wave ${at.k}'s plan is not the one the pull request approved. Approve it: ${prApproveCommand({ op: at.op, gate: d.gate, digest: d.digest })}`,
2542
+ );
2543
+ }
2544
+ const read = readWaveOutputs(at.outputsFile);
2545
+ let changeSet: PrPlanSet["doc"] | undefined;
2546
+ try {
2547
+ changeSet = (JSON.parse(readFileSync(join(cwd, opWavePlansPath(spec, at.k)), "utf8")) as { changeSet?: PrPlanSet["doc"] }).changeSet;
2548
+ } catch {
2549
+ // The wave stopped before it planned.
2550
+ }
2551
+ return { exitCode, applied: result.applied, failed: result.failed, entry, outputs: "error" in read ? {} : read.outputs, ...(changeSet ? { changeSet } : {}), ...(refused.stop ? { review: refused.stop } : {}) };
2552
+ }
2553
+
2104
2554
  /** A wave's new plan (#4003), beside the report as `change-set-wave-<k>.json`, for whoever approves its gate. */
2105
2555
  function writeWaveChangeSet(ctx: CommandContext, wave: number, doc: PrPlanSet["doc"], upload?: PrReportUpload): void {
2106
2556
  const dir = resolve(ctx.args.output ?? PR_REPORT_DIR);