@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
@@ -64,26 +64,29 @@
64
64
  * through `--forge`.
65
65
  */
66
66
  import { spawnSync } from "node:child_process";
67
- import { mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
68
- import { join, relative, resolve, sep } from "node:path";
67
+ import { CHANT_EXIT } from "../../exit-codes.js";
68
+ import { anyResourceGrain, leaseRowsOf as leaseRowsOfLocks, lockTargetsOf } from "../../lifecycle/lock-rows.js";
69
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
70
+ import { dirname, join, relative, resolve, sep } from "node:path";
69
71
  import { loadChantConfig, resolveAutoReleaseDisabled } from "../../config.js";
70
72
  import { resolveCommit, resolveMergeBase } from "../../components/changed-files.js";
71
73
  import { deriveFanOut, fanOutRegistry } from "../../components/fan-out-support.js";
72
74
  import { findComponentGroups, groupFanOut } from "../../components/groups.js";
73
- import { applyPrSet, approvalOf, approversWhoAuthored, approversWithoutReview, decidePrGate, planPrSet, prReport, readOnlyLedger, prWavePlan, resumePrSet, waveNotCovered, } from "../../components/pr-run.js";
75
+ import { applyPrSet, approvalOf, approversWhoAuthored, approversWithoutReview, decidePrGate, planPrSet, prReport, readOnlyLedger, prWavePlan, resumePrSet, } from "../../components/pr-run.js";
74
76
  import { composeChangeSet, verifyChangeSetDigest } from "../../change-set.js";
75
- import { waveGateName } from "../../gated-waves.js";
76
77
  import { blockedMembers, blockedWords, settleEarlierWaves } from "../../wave-blocked.js";
77
78
  import { readFanOutAttempt, writeFanOutAttempt } from "../../components/fan-out-record.js";
78
79
  import { componentInputDigests, progressThatCarries } from "../../components/fan-out-inputs.js";
79
- import { samePlanDigest } from "../../lifecycle/plan-digest.js";
80
+ import { computePlanDigest, samePlanDigest } from "../../lifecycle/plan-digest.js";
80
81
  import { evaluateGate, gateIsSealed, gitGateLedgerPort } from "../../op/gate.js";
81
82
  import { emitGateStep, gateEventsOf, GATE_PHASE } from "../../run-event-stream.js";
82
83
  import { openCliRunEvents, refusesEventsWithJson } from "../run-events.js";
83
84
  import { openPrReportUpload, parseReportUrl, reportKey } from "../../pr-report-url.js";
84
- import { describePlanChanged, PR_APPLY_GATE, prApproveCommand, prNoteMarker, prOp, prStatusDescription, prStatusContext, prStatusState, renderPrNote, } from "../../pr-loop.js";
85
+ import { describePlanChanged, PR_APPLY_GATE, prApproveCommand, prApproveCommands, prNoteMarker, prOp, prStatusDescription, prStatusContext, prStatusState, renderPrNote, } from "../../pr-loop.js";
85
86
  import { FORGE_KINDS, forgeFromEnv, forgePrincipalOf } from "../../pr-forge.js";
86
87
  import { GITHUB_COMMENT_LIMIT, GITLAB_NOTE_LIMIT } from "../../plan-summary.js";
88
+ import { upsertPlanNote } from "../../pr-post.js";
89
+ import { activeProductWords, productContext } from "../../ci-product-words.js";
87
90
  import { resolveCliBuildParams, parseParamFlags } from "../build-params-cli.js";
88
91
  import { formatError, formatInfo, formatSuccess, formatWarning } from "../format.js";
89
92
  import { reportUninstalledDependencies } from "../dependencies.js";
@@ -92,8 +95,11 @@ import { resolveChangedUnits } from "./fan-out.js";
92
95
  import { coverByMerges, greenOp } from "../../components/green-cover.js";
93
96
  import { GATED_EXIT_CODE, autoReleaseRun, recordAutoReleasesForRun } from "./run.js";
94
97
  import { appliedDigestOf } from "../../components/auto-release.js";
98
+ import { parseArgs } from "../parse-args.js";
95
99
  import { withComponentEndpoint } from "../component-endpoint.js";
96
- import { failedRunExitCode } from "../../components/driver.js";
100
+ import { assertTargetsAccepted, failedRunExitCode } from "../../components/driver.js";
101
+ import { TargetsRefusedError } from "../../components/capability.js";
102
+ import { prPlanTargets } from "../../components/pr-targets.js";
97
103
  import { prLoopHooksAt, runPrHooks } from "../../components/pr-hooks.js";
98
104
  import { decidePrPolicyOverride, policyReviewOf, prLoopPolicyAt, prPolicyReport, runPrPolicy, spendPrPolicyOverride } from "../../components/pr-policy.js";
99
105
  import { lexiconNames } from "../../lexicon-module.js";
@@ -123,6 +129,10 @@ export async function prepare(ctx, stage) {
123
129
  }
124
130
  if (args.fromAffected)
125
131
  return fail(`pr-${stage} derives the change itself; drop --from-affected`);
132
+ // #4620: a target narrows the preview; an apply or a record covers what the approved plan covers.
133
+ if (stage !== "plan" && args.targets && args.targets.length > 0) {
134
+ 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.");
135
+ }
126
136
  let member;
127
137
  if (args.members?.length) {
128
138
  const checked = await checkMember(projectPath, args.members);
@@ -396,16 +406,96 @@ async function checkMember(projectPath, names) {
396
406
  export function planAll(p, onRunEvent) {
397
407
  return hookedPlan(p, p.plan.order, () => planBare(p, onRunEvent));
398
408
  }
399
- export function planBare(p, onRunEvent) {
409
+ export async function planBare(p, onRunEvent) {
410
+ const lockGrain = await declaredLockGrainOf(p);
400
411
  return planPrSet({
401
412
  components: p.components,
402
413
  plan: p.plan,
403
414
  registry: p.registry,
404
415
  env: p.env,
405
416
  seededOutputs: p.seededOutputs,
417
+ ...(lockGrain ? { lockGrain } : {}),
418
+ // #4613: a step's own policy engine (CrossGuard) reads its packs at the base, as ci.policy is.
419
+ policyBase: p.base,
406
420
  ...(onRunEvent ? { onRunEvent } : {}),
421
+ ...(p.targets ? { targets: p.targets } : {}),
407
422
  });
408
423
  }
424
+ /**
425
+ * `pr-plan --target` (#4620): the addresses by member, set on `p`, or the
426
+ * exit code when a value is refused or a targeted member has a capability
427
+ * that cannot narrow, which is named before anything plans.
428
+ */
429
+ function narrowToTargets(p, values) {
430
+ if (!values || values.length === 0)
431
+ return undefined;
432
+ const resolved = prPlanTargets(values, p.plan.order, new Set(p.components.map((c) => c.name)));
433
+ if ("error" in resolved)
434
+ return fail(resolved.error, "--target <address> narrows every member the pull request plans; --target <member>:<address> narrows one.");
435
+ const { targets } = resolved;
436
+ const byName = new Map(p.components.map((c) => [c.name, c]));
437
+ for (const [name, addresses] of Object.entries(targets)) {
438
+ try {
439
+ assertTargetsAccepted(byName.get(name), p.registry, { targets: addresses });
440
+ }
441
+ catch (err) {
442
+ if (err instanceof TargetsRefusedError)
443
+ return fail(`${err.message}, so nothing was planned`, "Drop --target, or name a member whose steps can narrow: --target <member>:<address>.");
444
+ throw err;
445
+ }
446
+ }
447
+ p.targets = targets;
448
+ console.error(formatInfo(`narrowed to ${Object.entries(targets).map(([name, a]) => `${name}: ${a.join(", ")}`).join("; ") || "nothing planned"}`));
449
+ return undefined;
450
+ }
451
+ /**
452
+ * `ci.lockGrain` of the stage's member (#4552), read from the declaration at
453
+ * base like `ci.locks`, so a change cannot pick its own grain. Undefined when
454
+ * none is declared: each member then takes its lexicon's default.
455
+ */
456
+ async function declaredLockGrainOf(p) {
457
+ const { ciLockGrainAt } = await import("../../workspace/ci-lock-grain.js");
458
+ return ciLockGrainAt(process.cwd(), p.base, p.member) ?? undefined;
459
+ }
460
+ /**
461
+ * Lease the rows a set's members on the resource grain change (#4552),
462
+ * before anything applies: the refusal naming the run that holds one, the
463
+ * exit code when the rows file could not be written, or the lease to let go
464
+ * of once the apply ends (one that holds nothing when no member is on the
465
+ * resource grain).
466
+ */
467
+ async function leaseSetRows(p, set) {
468
+ const leased = await leaseRowsOf(p, set);
469
+ return "failed" in leased ? fail(leased.failed) : leased;
470
+ }
471
+ /**
472
+ * {@link leaseSetRows} without printing a failure (#4594), for a later round
473
+ * of `applyPrSet` (`leaseRound`), which records it on the round, and for a
474
+ * pull request environment's apply, which reports it.
475
+ */
476
+ export async function leaseRowsOf(p, set, label = "this apply") {
477
+ const rows = leaseRowsOfLocks(set.locks);
478
+ if (rows.length === 0)
479
+ return { release: () => Promise.resolve(true) };
480
+ const { leaseLockRows } = await import("../../lifecycle/resource-lock.js");
481
+ let leased;
482
+ try {
483
+ leased = await leaseLockRows(p.gate, rows);
484
+ }
485
+ catch (err) {
486
+ 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)}` };
487
+ }
488
+ if (!leased.ok)
489
+ 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.` };
490
+ for (const h of leased.tookOver)
491
+ console.error(formatInfo(`took over the rows of run ${h.run}, which is gone`));
492
+ console.error(formatInfo(`${label} holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${p.gate} while it applies`));
493
+ return leased.lease;
494
+ }
495
+ /** `applyPrSet`'s `leaseRound` (#4594): a round after the first leases the rows its own plan locks. */
496
+ export function leaseRoundRows(p) {
497
+ return ({ round, set }) => leaseRowsOf(p, set, `round ${round}`);
498
+ }
409
499
  /**
410
500
  * How a stage's report settles its run's events (#4041): a refusal waits on
411
501
  * a person, as a gate does, and exits the same way.
@@ -461,7 +551,7 @@ async function publish(forge, report, note) {
461
551
  if (report.member && report.status === "nothing" && !report.overdue?.length && !report.migrations?.length)
462
552
  return;
463
553
  try {
464
- await forge.upsertNote(report.pr, prNoteMarker(report.env, report.member), note);
554
+ await upsertPlanNote(forge, report.pr, prNoteMarker(report.env, report.member), note);
465
555
  }
466
556
  catch (err) {
467
557
  console.error(formatWarning({ message: `could not post the note on #${report.pr}: ${err instanceof Error ? err.message : String(err)}` }));
@@ -491,6 +581,15 @@ async function finish(ctx, p, report, upload) {
491
581
  report = { ...report, policy: p.policyReport };
492
582
  if (p.beforeMerge)
493
583
  report = { ...report, beforeMerge: p.beforeMerge };
584
+ // #4617: with a checkout of the control repo named, its entries and apply records mark the cross-stack edges.
585
+ if (report.crossStackEdges?.length && process.env.CHANT_CONTROL_DIR) {
586
+ const { controlEdgeFactsFromEnv, remarkCrossStackEdges } = await import("../../control/edges.js");
587
+ report = remarkCrossStackEdges(report, await controlEdgeFactsFromEnv());
588
+ }
589
+ // #4573: each member's section its lexicon renders from its own part of the change set.
590
+ const details = await memberDetails(p, report);
591
+ if (details.length > 0)
592
+ report = { ...report, details };
494
593
  const note = noteFor(report, p.forge);
495
594
  writeOutputs(ctx, report, note, upload);
496
595
  if (!ctx.args.noStatus)
@@ -582,9 +681,9 @@ async function judgePolicy(p, at) {
582
681
  const why = err instanceof Error ? err.message : String(err);
583
682
  if (at.stage === "plan") {
584
683
  console.error(formatWarning({ message: `could not read the override ledger, so no override reads as standing: ${why}` }));
585
- return { held, stop: { refusal: "policy-denied", code: 1, message: `The policy denied this plan: ${denied}.` } };
684
+ return { held, stop: { refusal: "policy-denied", code: CHANT_EXIT.denied, message: `The policy denied this plan: ${denied}.` } };
586
685
  }
587
- 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.` } };
686
+ 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.` } };
588
687
  }
589
688
  if (decided.status === "overridden") {
590
689
  report.override = decided.override;
@@ -600,7 +699,7 @@ async function judgePolicy(p, at) {
600
699
  held,
601
700
  stop: {
602
701
  refusal: "policy-denied",
603
- code: at.stage === "plan" ? 1 : GATED_EXIT_CODE,
702
+ code: CHANT_EXIT.denied,
604
703
  message: `The policy denied this plan: ${denied}.${moved} Nothing was applied. ${who} override it: ${decided.command}`,
605
704
  },
606
705
  };
@@ -631,6 +730,9 @@ async function prPlan(ctx, stage) {
631
730
  const p = await prepare(ctx, "plan");
632
731
  if (typeof p === "number")
633
732
  return p;
733
+ const narrowed = narrowToTargets(p, ctx.args.targets);
734
+ if (narrowed !== undefined)
735
+ return narrowed;
634
736
  const op = prOp(ctx.args.pr, p.member);
635
737
  placeHooks(ctx, p, "plan", op);
636
738
  const upload = openUpload(stage, "plan", ctx.args.pr, p);
@@ -679,11 +781,47 @@ async function prPlan(ctx, stage) {
679
781
  printMembers(report);
680
782
  if (status === "planned") {
681
783
  console.error(formatInfo(`plan : ${report.digest}`));
682
- console.error(formatInfo(approval.status === "approved" ? `approved by ${(approval.approvedBy ?? []).join(", ")}` : `approve : ${prApproveCommand(report)}`));
784
+ console.error(formatInfo(approval.status === "approved" ? `approved by ${(approval.approvedBy ?? []).join(", ")}` : `approve : ${prApproveCommands(report).join("; ")}`));
683
785
  }
684
786
  if (judged.stop)
685
787
  console.error(formatWarning({ message: judged.stop.message }));
686
- return status === "plan-failed" || judged.stop ? 1 : 0;
788
+ // #4550: a capability's policy denial (pulumi-up's CrossGuard) exits as a denial, 7, not as a failed plan.
789
+ if (status === "plan-failed" && set.policyDenied)
790
+ return CHANT_EXIT.denied;
791
+ return status === "plan-failed" ? CHANT_EXIT.failed : judged.stop ? judged.stop.code : CHANT_EXIT.done;
792
+ }
793
+ /**
794
+ * The member detail sections (#4573): each lexicon the project lists that
795
+ * renders one (`prNoteDetail`) gets each member's part of the change set. A
796
+ * lexicon that cannot load, or throws, leaves the note as it was.
797
+ */
798
+ async function memberDetails(p, report) {
799
+ if (report.changeSet.members.length === 0)
800
+ return [];
801
+ const { loadPlugin } = await import("../plugins.js");
802
+ const out = [];
803
+ for (const name of lexiconNames(p.config.lexicons ?? [])) {
804
+ let plugin;
805
+ try {
806
+ plugin = await loadPlugin(name);
807
+ }
808
+ catch {
809
+ continue;
810
+ }
811
+ if (!plugin.prNoteDetail)
812
+ continue;
813
+ for (const member of report.changeSet.members) {
814
+ try {
815
+ const detail = await plugin.prNoteDetail({ member: member.member, changeSet: report.changeSet, stage: report.stage });
816
+ if (detail && detail.lines.length > 0)
817
+ out.push({ member: member.member, ...(detail.title ? { title: detail.title } : {}), lines: detail.lines });
818
+ }
819
+ catch (err) {
820
+ console.error(formatWarning({ message: `the ${name} lexicon could not render ${member.member}'s detail: ${err instanceof Error ? err.message : String(err)}` }));
821
+ }
822
+ }
823
+ }
824
+ return out;
687
825
  }
688
826
  /**
689
827
  * The migration files the pull request adds in a migration-directory member
@@ -732,13 +870,15 @@ async function overdueOps(forge, member) {
732
870
  const { overdueOpsAt } = await import("../../op/schedule-overdue.js");
733
871
  return overdueOpsAt({ forge, cwd: resolve("."), ...(member ? { member } : {}), log: (line) => console.error(formatWarning({ message: line })) });
734
872
  }
735
- /** chant components pr-apply --base <ref> [--pr <n>] [--env <env>] [--gate <name>] [--forge <kind>] [--require-review] [--output <dir>] [--json] [--events-json] [--report-url <url>] */
873
+ /** 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>] */
736
874
  export function runComponentsPrApply(ctx) {
737
875
  if (refusesEventsWithJson(ctx.args, "the stage's report"))
738
876
  return Promise.resolve(1);
739
877
  return withStageEvents("pr-apply", ctx, async (events) => {
740
878
  // #4301: an apply before merge asks the forge its requires checks before any of the head's code loads, the config included.
741
879
  let beforeMerge;
880
+ if (ctx.args.requires && !ctx.args.beforeMerge)
881
+ return fail("--requires names the checks of an apply before merge, so it needs --before-merge --pr <n>");
742
882
  if (ctx.args.beforeMerge) {
743
883
  const checked = await beforeMergeChecks(ctx);
744
884
  if (typeof checked === "number")
@@ -804,7 +944,7 @@ async function prApply(ctx, stage, beforeMerge) {
804
944
  return held;
805
945
  if (held) {
806
946
  const set = { doc: composeChangeSet([]), members: [], plans: {}, outputs: {}, failed: false };
807
- return stopper(ctx, p, events, upload)(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 }), GATED_EXIT_CODE);
947
+ return stopper(ctx, p, events, upload)(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 }), CHANT_EXIT.held);
808
948
  }
809
949
  }
810
950
  if (args.waveGate)
@@ -857,8 +997,19 @@ async function prApply(ctx, stage, beforeMerge) {
857
997
  ...base,
858
998
  approval: { status: "pending" },
859
999
  status: "plan-failed",
860
- message: "A member failed to plan, so there is no plan to compare with the approved one. Nothing was applied.",
861
- }), 1);
1000
+ message: set.policyDenied
1001
+ ? "The policy denied a member's plan, so nothing was applied."
1002
+ : "A member failed to plan, so there is no plan to compare with the approved one. Nothing was applied.",
1003
+ }), set.policyDenied ? CHANT_EXIT.denied : 1);
1004
+ }
1005
+ // #4552, ruling D: on the resource grain a pull request's locks name row keys, which only the plan knows.
1006
+ const lockTargets = lockTargetsOf(p.plan.order, set.locks);
1007
+ if (locks && anyResourceGrain(set.locks)) {
1008
+ const held = await heldLocksOf(p, pr, lockTargets);
1009
+ if (typeof held === "number")
1010
+ return held;
1011
+ if (held)
1012
+ return stop(prReport({ ...base, approval: { status: "pending" }, status: "refused", refusal: "locked", message: held }), CHANT_EXIT.held);
862
1013
  }
863
1014
  // #4022: keep the change set the gate binds on chant/lifecycle under its
864
1015
  // digest before deciding the gate, so the plan an approval bound, or the
@@ -882,7 +1033,7 @@ async function prApply(ctx, stage, beforeMerge) {
882
1033
  if (afterGate && decided.satisfied)
883
1034
  return stop(prReport({ ...base, approval, status: "failed", message: afterGate }), 1);
884
1035
  if (!decided.satisfied)
885
- return stop(prReport({ ...base, approval, status: "refused", refusal: decided.refusal, message: decided.message }), GATED_EXIT_CODE);
1036
+ return stop(prReport({ ...base, approval, status: "refused", refusal: decided.refusal, message: decided.message }), decided.refusal === "plan-changed" ? CHANT_EXIT.moved : CHANT_EXIT.waiting);
886
1037
  via = decided.via;
887
1038
  }
888
1039
  const reviewOf = reviewFor(args, p, pr, green);
@@ -898,12 +1049,18 @@ async function prApply(ctx, stage, beforeMerge) {
898
1049
  return stop(prReport({ ...base, approval, status: "refused", refusal: "policy-denied", message: unspent }), 1);
899
1050
  // #4293, #4301: under ci.locks an apply before merge holds its targets until the pull request merges or closes.
900
1051
  if (locks && beforeMerge && pr !== null) {
901
- const taken = await takeApplyLocks(p, pr);
1052
+ const taken = await takeApplyLocks(p, pr, lockTargets);
902
1053
  if (typeof taken === "number")
903
1054
  return taken;
904
1055
  if (taken)
905
- return stop(prReport({ ...base, approval, status: "refused", refusal: "locked", message: taken }), GATED_EXIT_CODE);
906
- }
1056
+ return stop(prReport({ ...base, approval, status: "refused", refusal: "locked", message: taken }), CHANT_EXIT.held);
1057
+ }
1058
+ // #4552: on the resource grain the apply leases the rows it changes, whatever ci.locks says, and lets go when it ends.
1059
+ const lease = await leaseSetRows(p, set);
1060
+ if (typeof lease === "number")
1061
+ return lease;
1062
+ if ("held" in lease)
1063
+ return stop(prReport({ ...base, approval, status: "refused", refusal: "locked", message: lease.held }), CHANT_EXIT.held);
907
1064
  // The record is written before the first component runs and again as each
908
1065
  // one settles, so a run killed partway still knows what applied.
909
1066
  const prior = resumed ? { completed: resumed.completed, outputs: resumed.outputs } : { completed: [], outputs: {} };
@@ -937,8 +1094,10 @@ async function prApply(ctx, stage, beforeMerge) {
937
1094
  // #4288: the before-apply hooks, once the gate and the review let the apply through.
938
1095
  const toApply = (resumed?.plan ?? p.plan).order.filter((name) => !completedSoFar.has(name));
939
1096
  const beforeFailed = await runStageHook(p, "before-apply", toApply);
940
- if (beforeFailed)
1097
+ if (beforeFailed) {
1098
+ await lease.release();
941
1099
  return stop(prReport({ ...base, approval, status: "failed", message: beforeFailed }), 1);
1100
+ }
942
1101
  // #3999: a round planned after an upstream applied waits on a gate of its
943
1102
  // own, under the same identity.gates rule and the same review checks.
944
1103
  const roundLedger = gitGateLedgerPort();
@@ -961,40 +1120,51 @@ async function prApply(ctx, stage, beforeMerge) {
961
1120
  }
962
1121
  return { satisfied: true, approval: roundApproval };
963
1122
  };
964
- const applied = await applyPrSet({
965
- components: p.components,
966
- plan: resumed?.plan ?? p.plan,
967
- registry: p.registry,
968
- env: p.env,
969
- set,
970
- gate: p.gate,
971
- approval,
972
- decideRound,
973
- ...(resumed ? { resumed: prior } : {}),
974
- // The apply is this run's waves, so the fan-out's own run framing is
975
- // dropped. The log's lines go to stderr with or without --events-json.
976
- onRunEvent: (body) => {
977
- events?.nested(body);
978
- log(body);
979
- },
980
- ...(resumePath
981
- ? {
982
- onComponentSettled: (settled, outputs) => {
983
- if (settled.status === "ok") {
984
- completedSoFar.add(settled.component);
985
- if (inputsNow[settled.component] !== undefined)
986
- inputsSoFar[settled.component] = inputsNow[settled.component];
987
- if (outputs)
988
- outputsSoFar[settled.component] = outputs;
989
- }
990
- else if (settled.status === "fail") {
991
- failedSoFar.push(settled.component);
992
- }
993
- recordAttempt();
994
- },
995
- }
996
- : {}),
997
- });
1123
+ const lockGrain = await declaredLockGrainOf(p);
1124
+ let applied;
1125
+ try {
1126
+ applied = await applyPrSet({
1127
+ components: p.components,
1128
+ plan: resumed?.plan ?? p.plan,
1129
+ registry: p.registry,
1130
+ env: p.env,
1131
+ set,
1132
+ ...(lockGrain ? { lockGrain } : {}),
1133
+ policyBase: p.base,
1134
+ gate: p.gate,
1135
+ approval,
1136
+ decideRound,
1137
+ // #4594: a later round's plan may change rows the first did not, so it leases its own.
1138
+ leaseRound: leaseRoundRows(p),
1139
+ ...(resumed ? { resumed: prior } : {}),
1140
+ // The apply is this run's waves, so the fan-out's own run framing is
1141
+ // dropped. The log's lines go to stderr with or without --events-json.
1142
+ onRunEvent: (body) => {
1143
+ events?.nested(body);
1144
+ log(body);
1145
+ },
1146
+ ...(resumePath
1147
+ ? {
1148
+ onComponentSettled: (settled, outputs) => {
1149
+ if (settled.status === "ok") {
1150
+ completedSoFar.add(settled.component);
1151
+ if (inputsNow[settled.component] !== undefined)
1152
+ inputsSoFar[settled.component] = inputsNow[settled.component];
1153
+ if (outputs)
1154
+ outputsSoFar[settled.component] = outputs;
1155
+ }
1156
+ else if (settled.status === "fail") {
1157
+ failedSoFar.push(settled.component);
1158
+ }
1159
+ recordAttempt();
1160
+ },
1161
+ }
1162
+ : {}),
1163
+ });
1164
+ }
1165
+ finally {
1166
+ await lease.release();
1167
+ }
998
1168
  recordAttempt();
999
1169
  // #4288: the after-apply hooks, for the components that applied.
1000
1170
  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");
@@ -1006,12 +1176,23 @@ async function prApply(ctx, stage, beforeMerge) {
1006
1176
  members: applied.members,
1007
1177
  ...(resumed ? { resumed: resumed.completed } : {}),
1008
1178
  ...(applied.rounds ? { rounds: applied.rounds } : {}),
1009
- ...(applied.status === "waiting" ? { message: waitingMessage(op, applied.rounds) } : {}),
1179
+ ...(applied.held ? { message: applied.held } : applied.leaseFailed ? { message: applied.leaseFailed } : applied.status === "waiting" ? { message: waitingMessage(op, applied.rounds) } : {}),
1010
1180
  });
1011
1181
  // A component that stopped at a gate of its own leaves the apply waiting on
1012
1182
  // a person. A step that refused its plan because the target moved since
1013
- // the approval exits 3, as a moved digest does before anything applies (#3997).
1014
- const exit = afterFailed ? 1 : applied.status === "applied" ? 0 : applied.status === "waiting" ? GATED_EXIT_CODE : failedRunExitCode(applied.run.results);
1183
+ // the approval exits 4 (moved), as a moved digest does before anything applies (#3997, #4553).
1184
+ // A later round whose rows another run holds exits 5 (held, #4594).
1185
+ const exit = afterFailed
1186
+ ? 1
1187
+ : applied.held
1188
+ ? CHANT_EXIT.held
1189
+ : applied.status === "applied"
1190
+ ? 0
1191
+ : applied.status === "waiting"
1192
+ ? GATED_EXIT_CODE
1193
+ : applied.leaseFailed
1194
+ ? 1
1195
+ : failedRunExitCode(applied.run.results);
1015
1196
  if (green && applied.status === "applied")
1016
1197
  await recordGreenApplied(p, green, set.doc.digest, approval, via);
1017
1198
  const code = await stop(report, exit, applied.run.status === "gated" ? "gated" : undefined);
@@ -1027,12 +1208,12 @@ async function prApply(ctx, stage, beforeMerge) {
1027
1208
  * `--forge` every lock counts. A lock file that cannot be read stops the
1028
1209
  * apply, since nothing then says the targets are free.
1029
1210
  */
1030
- async function heldLocksOf(p, pr) {
1211
+ async function heldLocksOf(p, pr, targets = p.plan.order) {
1031
1212
  const { heldTargetLocks, describeHeldTargetLocks } = await import("../../lifecycle/target-lock.js");
1032
1213
  const isOpen = p.forge?.pullRequestOpen?.bind(p.forge);
1033
1214
  let held;
1034
1215
  try {
1035
- held = await heldTargetLocks(p.gate, p.plan.order, pr, { ...(isOpen ? { isOpen } : {}) });
1216
+ held = await heldTargetLocks(p.gate, targets, pr, { ...(isOpen ? { isOpen } : {}) });
1036
1217
  }
1037
1218
  catch (err) {
1038
1219
  return fail(`could not read the target locks of ${p.gate}, so nothing was applied: ${err instanceof Error ? err.message : String(err)}`);
@@ -1062,6 +1243,11 @@ async function beforeMergeChecks(ctx) {
1062
1243
  return fail("--before-merge asks the forge whether the pull request is ready, so it needs --forge github|gitlab|forgejo");
1063
1244
  if (!args.base)
1064
1245
  return fail("pr-apply needs the commit the change is measured from: --base <ref>", "Before merge, the target branch's commit.");
1246
+ const { checkPrRequires, unmetRequires, parseRequiresList } = await import("../../pr-requires.js");
1247
+ // #4607: a product's `apply.requires` names the checks to ask; absent, all four.
1248
+ const only = args.requires ? parseRequiresList(args.requires) : undefined;
1249
+ if (only && "error" in only)
1250
+ return fail(only.error);
1065
1251
  const cwd = resolve(".");
1066
1252
  let forge;
1067
1253
  let head;
@@ -1078,16 +1264,16 @@ async function beforeMergeChecks(ctx) {
1078
1264
  const gate = args.gate ?? PR_APPLY_GATE;
1079
1265
  const { ciWorkflowAt } = await import("../../workspace/ci-workflow-at.js");
1080
1266
  const { appliesBeforeMerge } = await import("../../workspace/ci-workflow.js");
1081
- const { checkPrRequires, unmetRequires } = await import("../../pr-requires.js");
1082
1267
  const workflow = ciWorkflowAt(cwd, args.base, member);
1083
1268
  const early = earlyStop(ctx, forge, { pr: args.pr, base, head, gate, ...(member ? { member } : {}) });
1084
1269
  if (!appliesBeforeMerge(workflow)) {
1085
1270
  return early({ requires: [] }, "before-merge-off", `The declaration at base sets ci.workflow to ${workflow ?? "nothing"}${member ? ` for ${member}` : ""}, and only apply-before-merge applies a pull request before it merges (ws-106). Nothing was applied.`, 1);
1086
1271
  }
1087
1272
  // The apply's own statuses never hold it back: chant ci run's, and the report's.
1088
- const ignore = [`chant/${gate}`, `chant/${PR_APPLY_GATE}`, prStatusContext("apply", member)];
1089
- // No `only`: ws-106 gives the declaration no way to leave a check out, so all four are asked (#4336).
1090
- const requires = await checkPrRequires(forge, args.pr, head, { ignore });
1273
+ // #4550: under a product's words its own prefix too.
1274
+ const ignore = [...new Set([productContext(activeProductWords(), gate), productContext(activeProductWords(), PR_APPLY_GATE), `chant/${gate}`, `chant/${PR_APPLY_GATE}`, prStatusContext("apply", member)])];
1275
+ // ws-106 gives the declaration no way to leave a check out, so with no --requires all four are asked (#4336, #4607).
1276
+ const requires = await checkPrRequires(forge, args.pr, head, { ignore, ...(only ? { only: only.checks } : {}) });
1091
1277
  for (const r of requires)
1092
1278
  console.error(formatInfo(`${r.name}: ${r.passed ? "passed" : r.pending ? "pending" : "unmet"}, ${r.reason}`));
1093
1279
  const unmet = unmetRequires(requires);
@@ -1113,13 +1299,13 @@ function earlyStop(ctx, forge, at) {
1113
1299
  * refusal when another open pull request holds one, null once taken, or the
1114
1300
  * exit code when the locks could not be written.
1115
1301
  */
1116
- async function takeApplyLocks(p, pr) {
1302
+ async function takeApplyLocks(p, pr, targets = p.plan.order) {
1117
1303
  const { takeTargetLocks, describeHeldTargetLocks } = await import("../../lifecycle/target-lock.js");
1118
1304
  const isOpen = p.forge?.pullRequestOpen?.bind(p.forge);
1119
1305
  const by = process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_LOGIN ?? process.env.USER ?? "unknown";
1120
1306
  let result;
1121
1307
  try {
1122
- result = await takeTargetLocks(p.gate, p.plan.order, { pr, by, at: new Date().toISOString(), stage: "apply", head: p.head }, { ...(isOpen ? { isOpen } : {}) });
1308
+ result = await takeTargetLocks(p.gate, targets, { pr, by, at: new Date().toISOString(), stage: "apply", head: p.head }, { ...(isOpen ? { isOpen } : {}) });
1123
1309
  }
1124
1310
  catch (err) {
1125
1311
  return fail(`could not take the target locks of ${p.gate}, so nothing was applied: ${err instanceof Error ? err.message : String(err)}`);
@@ -1457,6 +1643,10 @@ function settleWords(body) {
1457
1643
  * pr-apply's job log (#4007): a line on stderr as each wave starts and as
1458
1644
  * each component settles, so the log shows the waves in order while they run.
1459
1645
  */
1646
+ /** One wave's fan-out numbers its wave 1; the events and the log carry the derivation's number (#4003). */
1647
+ function inWave(body, wave) {
1648
+ return "wave" in body && typeof body.wave === "number" ? { ...body, wave } : body;
1649
+ }
1460
1650
  function applyLog() {
1461
1651
  let waves = 0;
1462
1652
  return (body) => {
@@ -1565,6 +1755,7 @@ async function tryResume(p, attempt, file, op, inputsNow) {
1565
1755
  registry: p.registry,
1566
1756
  env: p.env,
1567
1757
  seededOutputs: p.seededOutputs,
1758
+ policyBase: p.base,
1568
1759
  record,
1569
1760
  completed,
1570
1761
  applied: outputs,
@@ -1619,21 +1810,20 @@ async function carryWaves(p, attempt, file, op, inputsNow) {
1619
1810
  const outputs = Object.fromEntries(Object.entries(attempt.outputs).filter(([name]) => completed.includes(name)));
1620
1811
  return { record, check, approval: approvalOf(check), completed, outputs };
1621
1812
  }
1622
- /** A run event with its wave renumbered to `wave`: the fan-out that applies one wave numbers it 1. */
1623
- function inWave(body, wave) {
1624
- return "wave" in body && typeof body.wave === "number" ? { ...body, wave } : body;
1625
- }
1626
1813
  /**
1627
1814
  * `pr-apply --wave-gate <gate>` (#4003): apply the pull request's approved
1628
1815
  * set a wave at a time, each wave planned after the one before it applied.
1629
1816
  *
1630
1817
  * The first job plans every member, as pr-apply does, and decides the pull
1631
- * request's gate against that digest. Approved, wave 1 applies with those
1632
- * plans. Each later wave is planned again against the outputs the waves
1633
- * before it left. When the approved change set covers its plan
1634
- * (`planCoveredBy`, as on a resume) it applies under the pull request's
1635
- * approval; when it does not, it waits at `<gate>-wave-<k>` under the pull
1636
- * request's op for an approval of its new plan, and exits 3.
1818
+ * request's gate against that digest. The waves then run on op waves
1819
+ * (#4588): the component waves spec (`componentWavesSpec`), each run a
1820
+ * component, planned and applied through the component plan-wave and
1821
+ * apply-wave steps (`chant components plan-wave|apply-wave`). Each wave is
1822
+ * planned against the outputs the waves before it left. When the approved
1823
+ * change set covers its plan (`planCoveredBy`, the op waves' `pull-request`
1824
+ * approval) it applies under the pull request's approval; when it does not,
1825
+ * it waits at `<gate>-wave-<k>` under the pull request's op for an approval
1826
+ * of its new plan, and exits 3.
1637
1827
  *
1638
1828
  * With `--wave <k>` the job runs wave k and no other, reading the approved
1639
1829
  * set and the progress from the `--resume` record the job before it left.
@@ -1747,7 +1937,6 @@ async function prApplyWaves(ctx, p, at) {
1747
1937
  `Nothing was applied. Run wave ${left}'s job first, with the same --resume record.`,
1748
1938
  }), 1);
1749
1939
  }
1750
- let planned;
1751
1940
  let judged = { held: false };
1752
1941
  if (carry) {
1753
1942
  // What the earlier waves applied settles first (#4007), each in its own wave, as a resumed apply's does.
@@ -1764,6 +1953,8 @@ async function prApplyWaves(ctx, p, at) {
1764
1953
  const set = await planAll(p, events?.emit);
1765
1954
  approved = set;
1766
1955
  if (set.failed) {
1956
+ if (set.policyDenied)
1957
+ return stop(report({ status: "plan-failed", message: "The policy denied a member's plan, so nothing was applied." }), CHANT_EXIT.denied);
1767
1958
  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);
1768
1959
  }
1769
1960
  await storeChangeSetForGate(ctx, p, set.doc);
@@ -1778,9 +1969,8 @@ async function prApplyWaves(ctx, p, at) {
1778
1969
  if (afterGate && decided.satisfied)
1779
1970
  return stop(report({ status: "failed", message: afterGate }), 1);
1780
1971
  if (!decided.satisfied)
1781
- return stop(report({ status: "refused", refusal: decided.refusal, message: decided.message }), GATED_EXIT_CODE);
1972
+ return stop(report({ status: "refused", refusal: decided.refusal, message: decided.message }), decided.refusal === "plan-changed" ? CHANT_EXIT.moved : CHANT_EXIT.waiting);
1782
1973
  via = decided.via;
1783
- planned = set;
1784
1974
  }
1785
1975
  const approvedSet = approved;
1786
1976
  const review = reviewFor(args, p, pr, green);
@@ -1826,6 +2016,9 @@ async function prApplyWaves(ctx, p, at) {
1826
2016
  /** The last apply in this job that failed (#4291): its results give the exit code once every wave ran. */
1827
2017
  let lastFailure;
1828
2018
  let planFailedIn;
2019
+ // #4588: the outputs file the waves' plan-wave and apply-wave steps hand outputs on in.
2020
+ const { componentWaveOutputsFile } = await import("../../components/product-pipeline.js");
2021
+ const outputsFile = componentWaveOutputsFile(op);
1829
2022
  for (let k = from; k <= to; k++) {
1830
2023
  // #4291: a component of this wave whose upstream failed, or was blocked by a failure, is blocked; the rest of the wave runs.
1831
2024
  const before = new Set(p.plan.waves.slice(0, k - 1).flat());
@@ -1848,137 +2041,63 @@ async function prApplyWaves(ctx, p, at) {
1848
2041
  recordAttempt();
1849
2042
  continue;
1850
2043
  }
1851
- const inThisWave = new Set(wavePlan.order);
1852
- // Wave 1 of the apply that just planned every member applies those plans:
1853
- // they are the approved set's. Every other wave is planned again, against
1854
- // the outputs the waves before it left.
1855
- let set;
1856
- let entry;
1857
- if (planned && k === 1) {
1858
- set = {
1859
- ...planned,
1860
- members: planned.members.filter((m) => inThisWave.has(m.component)),
1861
- plans: Object.fromEntries(Object.entries(planned.plans).filter(([name]) => inThisWave.has(name))),
1862
- };
1863
- entry = { wave: k, components: wavePlan.order, status: "applied", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest, ...(approval.approvedBy ? { approvedBy: approval.approvedBy } : {}) };
1864
- }
1865
- else {
1866
- const notApplied = Object.fromEntries(Object.entries(approvedSet.outputs).filter(([name]) => !completed.has(name)));
1867
- const fresh = await hookedPlan(p, wavePlan.order, () => planPrSet({
1868
- components: p.components,
1869
- plan: wavePlan,
1870
- registry: p.registry,
1871
- env: p.env,
1872
- seededOutputs: { ...p.seededOutputs, ...notApplied, ...outputsSoFar },
1873
- ...(events ? { onRunEvent: (body) => events.emit(body) } : {}),
1874
- }));
1875
- if (fresh.failed) {
1876
- for (const m of fresh.members) {
1877
- after.set(m.member, m);
1878
- if (m.status === "plan-failed")
1879
- failedSoFar.add(m.component);
1880
- }
1881
- setWave({ wave: k, components: wavePlan.order, status: "plan-failed", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest });
1882
- // #4291: the later waves still run what does not depend on this wave.
1883
- 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 + "." }));
1884
- planFailedIn ?? (planFailedIn = k);
1885
- continue;
1886
- }
1887
- const moved = waveNotCovered(approvedSet.doc, fresh.doc, approvedSet.members, { approved: approvedSet.shapes, fresh: fresh.shapes });
1888
- set = fresh;
1889
- if (moved.length === 0) {
1890
- console.error(formatInfo(`wave ${k}: the approved plan covers what it plans now, so it applies under the pull request's approval`));
1891
- entry = { wave: k, components: wavePlan.order, status: "applied", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest, ...(approval.approvedBy ? { approvedBy: approval.approvedBy } : {}) };
1892
- }
1893
- else {
1894
- const gate = waveGateName(waveGate, k);
1895
- const digest = fresh.doc.digest;
1896
- console.error(formatInfo(`wave ${k}: its plan moved since the pull request's (${moved.join("; ")}), so it needs an approval of ${gate}`));
1897
- await storeChangeSetForGate(ctx, p, fresh.doc);
1898
- writeWaveChangeSet(ctx, k, fresh.doc, upload);
1899
- const approveLine = prApproveCommand({ op, gate, digest });
1900
- const check = await emitGateStep(events?.emit, { op, gate }, () => decidePrGate(gitGateLedgerPort(), { op, gate, digest, description: `${changeLabel(pr, green)}, wave ${k} of ${total}: ${wavePlan.order.join(", ")}` }), (unapproved) => unapproved.mismatch
1901
- ? `wave ${k}'s plan changed after its approval. Approve the plan now: ${approveLine}`
1902
- : `wave ${k}'s plan is not the one the pull request approved. Approve it: ${approveLine}`);
1903
- const waveApproval = approvalOf(check);
1904
- const waiting = {
1905
- wave: k,
1906
- components: wavePlan.order,
1907
- status: "waiting",
1908
- approval: "wave",
1909
- gate,
1910
- digest,
1911
- moved,
1912
- ...(waveApproval.approved ? { approved: waveApproval.approved } : {}),
1913
- };
1914
- if (!check.satisfied) {
1915
- setWave(waiting);
1916
- const message = waveApproval.status === "changed"
1917
- ? `Wave ${k}'s plan changed after its approval, so nothing in it was applied. approved: ${waveApproval.approved ?? "(none)"}; planned now: ${digest}. ` +
1918
- `Read the new plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`
1919
- : `Wave ${k} was planned after the waves before it applied, and the pull request's approved plan does not cover it: ${moved.join("; ")}. ` +
1920
- `Nothing in wave ${k} was applied. Read its plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`;
1921
- return stop(report({ status: "refused", refusal: waveApproval.status === "changed" ? "wave-plan-changed" : "wave-not-approved", message }), GATED_EXIT_CODE);
1922
- }
1923
- const waveReview = await review(waveApproval.approvedBy ?? [], `Wave ${k}'s plan`);
1924
- if (waveReview && "error" in waveReview)
1925
- return fail(waveReview.error);
1926
- if (waveReview) {
1927
- setWave(waiting);
1928
- emitReviewStop(events, waveReview.message);
1929
- return stop(report({ status: "refused", refusal: waveReview.refusal, message: waveReview.message }), GATED_EXIT_CODE);
1930
- }
1931
- entry = { wave: k, components: wavePlan.order, status: "applied", approval: "wave", gate, digest, moved, ...(waveApproval.approvedBy ? { approvedBy: waveApproval.approvedBy } : {}) };
1932
- }
1933
- }
2044
+ // #4588: the wave plans, waits or passes its gate, and applies on op waves: the component waves spec,
2045
+ // each run a component, through the component plan-wave and apply-wave steps.
2046
+ const pending = { wave: k, components: wavePlan.order, status: "applied", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest };
1934
2047
  // #4288: the wave's apply-side hooks, around its apply.
1935
2048
  const waveBefore = await runStageHook(p, "before-apply", wavePlan.order, undefined, `nothing in wave ${k} was applied`);
1936
2049
  if (waveBefore) {
1937
- setWave({ ...entry, status: "failed" });
2050
+ setWave({ ...pending, status: "failed" });
1938
2051
  return stop(report({ status: "failed", message: waveBefore }), 1);
1939
2052
  }
1940
- const applied = await applyPrSet({
1941
- components: p.components,
1942
- plan: wavePlan,
1943
- registry: p.registry,
1944
- env: p.env,
1945
- set,
1946
- // One wave's fan-out numbers its wave 1; the events and the log carry the derivation's number.
1947
- onRunEvent: (body) => {
1948
- const numbered = inWave(body, k);
1949
- events?.nested(numbered);
1950
- if (numbered.type !== "run-start")
1951
- log(numbered);
1952
- },
1953
- onComponentSettled: (settled, outputs) => {
1954
- if (settled.status === "ok") {
1955
- completed.add(settled.component);
1956
- failedSoFar.delete(settled.component);
1957
- if (inputsNow[settled.component] !== undefined)
1958
- inputsSoFar[settled.component] = inputsNow[settled.component];
1959
- if (outputs)
1960
- outputsSoFar[settled.component] = outputs;
1961
- }
1962
- else if (settled.status === "fail") {
1963
- failedSoFar.add(settled.component);
1964
- }
1965
- recordAttempt();
1966
- },
1967
- });
1968
- for (const m of applied.members)
1969
- after.set(m.member, m);
1970
- for (const name of applied.run.completed) {
2053
+ // The outputs the waves before this one left, and the approved set's for what has not applied yet, seed its plans.
2054
+ const notApplied = Object.fromEntries(Object.entries(approvedSet.outputs).filter(([name]) => !completed.has(name)));
2055
+ mkdirSync(dirname(resolve(outputsFile)), { recursive: true });
2056
+ writeFileSync(resolve(outputsFile), JSON.stringify({ ...p.seededOutputs, ...notApplied, ...outputsSoFar }, null, 2) + "\n");
2057
+ 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 });
2058
+ const entry = ran.entry;
2059
+ if (ran.review && "error" in ran.review)
2060
+ return fail(ran.review.error);
2061
+ if (ran.review && ran.exitCode === CHANT_EXIT.waiting) {
2062
+ setWave(entry);
2063
+ emitReviewStop(events, ran.review.message);
2064
+ return stop(report({ status: "refused", refusal: ran.review.refusal, message: ran.review.message }), GATED_EXIT_CODE);
2065
+ }
2066
+ for (const name of ran.applied) {
1971
2067
  completed.add(name);
1972
- const outputs = applied.run.componentOutputs[name];
1973
- if (outputs)
1974
- outputsSoFar[name] = outputs;
2068
+ failedSoFar.delete(name);
2069
+ if (inputsNow[name] !== undefined)
2070
+ inputsSoFar[name] = inputsNow[name];
2071
+ if (ran.outputs[name])
2072
+ outputsSoFar[name] = ran.outputs[name];
2073
+ }
2074
+ for (const name of ran.failed)
2075
+ failedSoFar.add(name);
2076
+ if (ran.exitCode === CHANT_EXIT.waiting || ran.exitCode === CHANT_EXIT.moved) {
2077
+ setWave(entry);
2078
+ // #4003: the wave's new plan beside the report, for whoever approves its gate.
2079
+ if (ran.changeSet)
2080
+ writeWaveChangeSet(ctx, k, ran.changeSet, upload);
2081
+ const approveLine = prApproveCommand({ op, gate: entry.gate, digest: entry.digest });
2082
+ const message = ran.exitCode === CHANT_EXIT.moved
2083
+ ? `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.`
2084
+ : `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("; ")}` : ""}. ` +
2085
+ `Nothing in wave ${k} was applied. Read its plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`;
2086
+ return stop(report({ status: "refused", refusal: ran.exitCode === CHANT_EXIT.moved ? "wave-plan-changed" : "wave-not-approved", message }), ran.exitCode);
2087
+ }
2088
+ if (ran.exitCode === CHANT_EXIT.held) {
2089
+ setWave({ ...entry, status: "waiting" });
2090
+ 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);
1975
2091
  }
1976
- 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`);
1977
- setWave({ ...entry, status: applied.status === "applied" && !waveAfter ? "applied" : "failed" });
1978
- await recordAutoReleasesForRun(applied.run.results, p.env, at.release.runId, resolveAutoReleaseDisabled(p.config, args.noReleaseRecord), at.release.runOrigin, undefined, undefined, prAppliedDigests(p, applied.members));
1979
- if (applied.status !== "applied") {
2092
+ if (ran.exitCode === CHANT_EXIT.denied || ran.exitCode === CHANT_EXIT.declined || ran.exitCode === CHANT_EXIT.superseded) {
2093
+ setWave({ ...entry, status: "failed" });
2094
+ return stop(report({ status: "failed", message: `Wave ${k} stopped on op waves with exit ${ran.exitCode}; nothing more was applied.` }), ran.exitCode);
2095
+ }
2096
+ 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`);
2097
+ setWave({ ...entry, status: ran.exitCode === CHANT_EXIT.done && !waveAfter ? "applied" : "failed" });
2098
+ if (ran.exitCode !== CHANT_EXIT.done) {
1980
2099
  // #4291: a failed member blocks only its dependents, so the later waves still run.
1981
- lastFailure = { results: applied.run.results, gated: applied.run.status === "gated" };
2100
+ lastFailure = { exitCode: ran.exitCode };
1982
2101
  recordAttempt();
1983
2102
  continue;
1984
2103
  }
@@ -1993,13 +2112,342 @@ async function prApplyWaves(ctx, p, at) {
1993
2112
  const message = planFailedIn !== undefined && !lastFailure
1994
2113
  ? `A member of wave ${planFailedIn} failed to plan, so nothing in wave ${planFailedIn} was applied.${blockedLine}`
1995
2114
  : blockedLine ? blockedLine.trim() : undefined;
1996
- return stop(report({ status: "failed", ...(message ? { message } : {}) }), lastFailure ? failedRunExitCode(lastFailure.results) : 1, lastFailure?.gated ? "gated" : undefined);
2115
+ return stop(report({ status: "failed", ...(message ? { message } : {}) }), lastFailure ? lastFailure.exitCode : 1);
1997
2116
  }
1998
2117
  const done = p.plan.order.every((name) => completed.has(name));
1999
2118
  if (green && done)
2000
2119
  await recordGreenApplied(p, green, approvedSet.doc.digest, approval, via);
2001
2120
  return stop(report({ status: done ? "applied" : "wave-applied" }), 0);
2002
2121
  }
2122
+ // ── The component plan-wave and apply-wave steps (#4588) ─────────────────────
2123
+ /** The outputs earlier waves' components left, from `--wave-outputs`; empty when the file is not there yet. */
2124
+ function readWaveOutputs(file) {
2125
+ if (!file || !existsSync(resolve(file)))
2126
+ return { outputs: {} };
2127
+ try {
2128
+ const parsed = JSON.parse(readFileSync(resolve(file), "utf8"));
2129
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
2130
+ return { error: `--wave-outputs ${file} must hold { "<component>": { ...outputs } }` };
2131
+ return { outputs: parsed };
2132
+ }
2133
+ catch (err) {
2134
+ return { error: `--wave-outputs: could not read "${file}": ${err instanceof Error ? err.message : String(err)}` };
2135
+ }
2136
+ }
2137
+ /** The runs `chant run wave` wrote to `{runs}`: their targets, each a component, and on apply-wave the digest each was approved at. */
2138
+ function readWaveRuns(file) {
2139
+ if (!file)
2140
+ return { error: "the step needs --runs <file>, which chant run wave fills in as {runs}" };
2141
+ try {
2142
+ const parsed = JSON.parse(readFileSync(resolve(file), "utf8"));
2143
+ if (!Array.isArray(parsed?.runs))
2144
+ return { error: `--runs ${file} has no runs` };
2145
+ return parsed.runs.flatMap((r) => typeof r?.target === "string" ? [{ target: r.target, ...(typeof r.planDigest === "string" ? { planDigest: r.planDigest } : {}) }] : []);
2146
+ }
2147
+ catch (err) {
2148
+ return { error: `--runs: could not read "${file}": ${err instanceof Error ? err.message : String(err)}` };
2149
+ }
2150
+ }
2151
+ /** The fan-out plan of `names`, one wave of the derivation, with the rest of that wave counted as done. */
2152
+ function namedWavePlan(p, names) {
2153
+ const unknown = names.filter((n) => !p.plan.order.includes(n));
2154
+ if (unknown.length > 0)
2155
+ 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"}` };
2156
+ const k = p.plan.waves.findIndex((w) => w.includes(names[0])) + 1;
2157
+ const wave = p.plan.waves[k - 1] ?? [];
2158
+ const across = names.filter((n) => !wave.includes(n));
2159
+ if (across.length > 0)
2160
+ return { error: `${names[0]} and ${across.join(", ")} are in different waves of the derivation, so one wave step cannot plan them together` };
2161
+ return prWavePlan(p.plan, p.components, k, wave.filter((n) => !names.includes(n)));
2162
+ }
2163
+ /** One component's entry in the op-waves plans file: the digest over its members' plans, and whether it changes or destroys anything. */
2164
+ function componentPlanEntry(set, component) {
2165
+ const members = set.members.filter((m) => m.component === component).sort((a, b) => a.member.localeCompare(b.member));
2166
+ const names = new Set(members.map((m) => m.member));
2167
+ const entries = set.doc.entries.filter((e) => names.has(e.member));
2168
+ const changes = entries.filter((e) => e.action !== "no-op" && e.action !== "read");
2169
+ const destructive = changes.some((e) => e.action === "delete" || e.action === "replace");
2170
+ return {
2171
+ target: component,
2172
+ planDigest: computePlanDigest("component-wave", members.map((m) => ({ member: m.member, planDigest: m.planDigest }))),
2173
+ ...(changes.length === 0 ? { empty: true } : {}),
2174
+ ...(destructive ? { destructive: true } : {}),
2175
+ };
2176
+ }
2177
+ /** Read the step's runs and outputs files from its flags. */
2178
+ function waveStepFiles(args) {
2179
+ const runs = readWaveRuns(args.runsFile);
2180
+ if ("error" in runs)
2181
+ return runs;
2182
+ if (!args.plansFile)
2183
+ return { error: "the step needs --plans <file>, which chant run wave fills in as {plans}" };
2184
+ const read = readWaveOutputs(args.waveOutputs);
2185
+ if ("error" in read)
2186
+ return read;
2187
+ return { runs, plansFile: args.plansFile, ...(args.waveOutputs ? { outputsFile: args.waveOutputs } : {}), outputs: read.outputs };
2188
+ }
2189
+ /** Plan the step's runs, each a component, against the outputs the earlier waves left. */
2190
+ async function planComponentRuns(p, files) {
2191
+ const names = files.runs.map((r) => r.target);
2192
+ const plan = names.length > 0 ? namedWavePlan(p, names) : { ...p.plan, order: [], waves: [] };
2193
+ if ("error" in plan)
2194
+ return plan;
2195
+ const lockGrain = await declaredLockGrainOf(p);
2196
+ const set = await planPrSet({ components: p.components, plan, registry: p.registry, env: p.env, seededOutputs: { ...p.seededOutputs, ...files.outputs }, ...(lockGrain ? { lockGrain } : {}), policyBase: p.base });
2197
+ return { set, plan };
2198
+ }
2199
+ /** The plan step over `p`: write `{plans}`, one digest per component and the wave's change set. */
2200
+ async function planComponentWave(p, files) {
2201
+ const planned = await planComponentRuns(p, files);
2202
+ if ("error" in planned)
2203
+ return fail(planned.error);
2204
+ const { set } = planned;
2205
+ if (set.failed) {
2206
+ for (const m of set.members.filter((x) => x.status === "plan-failed"))
2207
+ console.error(formatError({ message: `${m.member} (${m.component}) failed to plan${m.error ? `: ${m.error}` : ""}` }));
2208
+ return set.policyDenied ? CHANT_EXIT.denied : 1;
2209
+ }
2210
+ const file = { runs: files.runs.map((r) => componentPlanEntry(set, r.target)), changeSet: set.doc };
2211
+ mkdirSync(dirname(resolve(files.plansFile)), { recursive: true });
2212
+ writeFileSync(resolve(files.plansFile), JSON.stringify(file, null, 2) + "\n");
2213
+ 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}`));
2214
+ return 0;
2215
+ }
2216
+ /** 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. */
2217
+ async function applyComponentWave(p, files, opts = {}) {
2218
+ if (files.runs.length === 0)
2219
+ return 0;
2220
+ const planned = await planComponentRuns(p, files);
2221
+ if ("error" in planned)
2222
+ return fail(planned.error);
2223
+ const { set, plan } = planned;
2224
+ if (set.failed)
2225
+ return fail("A component of the wave failed to plan again, so nothing in it was applied.");
2226
+ const moved = files.runs.filter((r) => r.planDigest !== undefined && !samePlanDigest(componentPlanEntry(set, r.target).planDigest, r.planDigest));
2227
+ if (moved.length > 0) {
2228
+ 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." }));
2229
+ return CHANT_EXIT.moved;
2230
+ }
2231
+ const lease = await leaseSetRows(p, set);
2232
+ if (typeof lease === "number")
2233
+ return lease;
2234
+ if ("held" in lease) {
2235
+ console.error(formatError({ message: lease.held }));
2236
+ return CHANT_EXIT.held;
2237
+ }
2238
+ const lockGrain = await declaredLockGrainOf(p);
2239
+ const release = autoReleaseRun(`wave-${Date.now()}`);
2240
+ let applied;
2241
+ try {
2242
+ 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 } : {}) });
2243
+ }
2244
+ finally {
2245
+ await lease.release();
2246
+ }
2247
+ await recordAutoReleasesForRun(applied.run.results, p.env, release.runId, resolveAutoReleaseDisabled(p.config, opts.noReleaseRecord), release.runOrigin, undefined, undefined, prAppliedDigests(p, applied.members));
2248
+ if (files.outputsFile) {
2249
+ const next = { ...files.outputs };
2250
+ for (const name of applied.run.completed)
2251
+ next[name] = applied.run.componentOutputs[name] ?? {};
2252
+ mkdirSync(dirname(resolve(files.outputsFile)), { recursive: true });
2253
+ writeFileSync(resolve(files.outputsFile), JSON.stringify(next, null, 2) + "\n");
2254
+ }
2255
+ for (const m of applied.members)
2256
+ console.error(m.status === "applied" ? formatSuccess(`applied ${m.member} (${m.component})`) : formatWarning({ message: `${m.member} (${m.component}): ${m.status}${m.error ? `, ${m.error}` : ""}` }));
2257
+ // #4291: the components that applied, so op waves fails only the others and blocks only what depends on them.
2258
+ const runsResult = opts.runsResult ?? (process.env.CHANT_APPLY_RUNS_RESULT ? resolve(process.env.CHANT_APPLY_RUNS_RESULT) : undefined);
2259
+ if (runsResult && applied.status !== "applied") {
2260
+ mkdirSync(dirname(runsResult), { recursive: true });
2261
+ writeFileSync(runsResult, JSON.stringify({ applied: [...applied.run.completed].sort() }, null, 2) + "\n");
2262
+ }
2263
+ return applied.status === "applied" ? 0 : applied.status === "waiting" ? CHANT_EXIT.waiting : 1;
2264
+ }
2265
+ /**
2266
+ * `chant components plan-wave --runs <file> --plans <file> --base <ref>
2267
+ * --env <env> [--member <m>] [--wave-outputs <file>]` (#4588): the
2268
+ * component plan step of a component waves spec. Plans each run, a
2269
+ * component, through the project's capabilities against the outputs the
2270
+ * waves before it left, and writes `{plans}`: one digest per component over
2271
+ * its members' plans, and the wave's change set, which a `pull-request`
2272
+ * wave checks the pull request's approval against.
2273
+ */
2274
+ export async function runComponentsPlanWave(ctx) {
2275
+ const files = waveStepFiles(ctx.args);
2276
+ if ("error" in files)
2277
+ return fail(files.error);
2278
+ const p = await prepare(ctx, "apply");
2279
+ if (typeof p === "number")
2280
+ return p;
2281
+ return planComponentWave(p, files);
2282
+ }
2283
+ /**
2284
+ * `chant components apply-wave --runs <file> --plans <file> --base <ref>
2285
+ * --env <env> [--member <m>] [--wave-outputs <file>]` (#4588): the
2286
+ * component apply step. Plans the approved runs again and exits 4 when a
2287
+ * component's plan is not the one approved; else leases its rows on the
2288
+ * resource grain, applies, records the releases, and adds each applied
2289
+ * component's outputs to `--wave-outputs` for the next wave.
2290
+ */
2291
+ export async function runComponentsApplyWave(ctx) {
2292
+ const files = waveStepFiles(ctx.args);
2293
+ if ("error" in files)
2294
+ return fail(files.error);
2295
+ const p = await prepare(ctx, "apply");
2296
+ if (typeof p === "number")
2297
+ return p;
2298
+ return applyComponentWave(p, files, { noReleaseRecord: ctx.args.noReleaseRecord });
2299
+ }
2300
+ /**
2301
+ * The component steps in this process (#4588): `pr-apply --wave-gate`
2302
+ * already holds the prepared project, so the plan-wave and apply-wave lines
2303
+ * of its spec run here against it, rather than in a process that would
2304
+ * derive the change again.
2305
+ */
2306
+ function componentWaveExec(p, noReleaseRecord, onRunEvent) {
2307
+ return async (argv, cwd, env) => {
2308
+ const at = argv.findIndex((a, i) => a === "components" && (argv[i + 1] === "plan-wave" || argv[i + 1] === "apply-wave"));
2309
+ if (at < 0)
2310
+ return fail(`not a component wave step: ${argv.join(" ")}`);
2311
+ let args;
2312
+ try {
2313
+ args = parseArgs(argv.slice(at));
2314
+ }
2315
+ catch (err) {
2316
+ return fail(err instanceof Error ? err.message : String(err));
2317
+ }
2318
+ const files = waveStepFiles(args);
2319
+ if ("error" in files)
2320
+ return fail(files.error);
2321
+ const runsResult = env?.CHANT_APPLY_RUNS_RESULT ? resolve(cwd, env.CHANT_APPLY_RUNS_RESULT) : undefined;
2322
+ return argv[at + 1] === "plan-wave" ? planComponentWave(p, files) : applyComponentWave(p, files, { noReleaseRecord, ...(onRunEvent ? { onRunEvent } : {}), ...(runsResult ? { runsResult } : {}) });
2323
+ };
2324
+ }
2325
+ /**
2326
+ * A gate ledger that holds the approval `pr-apply` already decided (#4588):
2327
+ * an approval of the pull request's gate under its op, for the approved
2328
+ * change set, so an op wave of the component waves spec finds the approval
2329
+ * a pull request (or a green commit's merges) gave and checks its own plan
2330
+ * against it. Everything else is the real ledger's.
2331
+ */
2332
+ function withDecidedApproval(port, at) {
2333
+ return {
2334
+ ...port,
2335
+ appendPending: (input) => port.appendPending(input),
2336
+ async read(op) {
2337
+ const got = await port.read(op);
2338
+ if (op !== at.op)
2339
+ return got;
2340
+ const decided = { 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 };
2341
+ return { ...got, resolutions: [...got.resolutions, decided] };
2342
+ },
2343
+ };
2344
+ }
2345
+ /**
2346
+ * The review rule on a wave's own gate (#4000, #4588): `--require-review`
2347
+ * judges an approval of the wave's gate as it judges the pull request's, so
2348
+ * an approval it refuses never reaches the op wave, which then waits. The
2349
+ * refusal is kept in `refused` for pr-apply's report. The pull request's gate
2350
+ * was judged before the waves ran, so its approvals pass as they are.
2351
+ */
2352
+ function withWaveReview(port, at) {
2353
+ return {
2354
+ ...port,
2355
+ async read(op) {
2356
+ var _a;
2357
+ const got = await port.read(op);
2358
+ const resolutions = [];
2359
+ for (const r of got.resolutions) {
2360
+ const stop = r.gate === at.prGate ? undefined : await at.review([r.resolvedBy], at.what);
2361
+ if (stop)
2362
+ (_a = at.refused).stop ?? (_a.stop = stop);
2363
+ else
2364
+ resolutions.push(r);
2365
+ }
2366
+ return { ...got, resolutions };
2367
+ },
2368
+ };
2369
+ }
2370
+ /**
2371
+ * Run wave `k` of `pr-apply --wave-gate` on op waves (#4588): the component
2372
+ * waves spec with the wave's runs left to apply, read at base as chant
2373
+ * wrote it (the spec is chant's, never the change's), decided under the
2374
+ * approval pr-apply holds, planned and applied through the component
2375
+ * plan-wave and apply-wave steps.
2376
+ */
2377
+ async function runComponentWave(p, at) {
2378
+ const { componentWavesSpec, componentWaveSteps, PRODUCT_WAVES_SPEC_DIR: PRODUCT_WAVES_DIR } = await import("../../components/product-pipeline.js");
2379
+ const { runOpWave, opWavePlansPath } = await import("../../op/op-waves-run.js");
2380
+ const words = activeProductWords();
2381
+ const cwd = resolve(".");
2382
+ 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 });
2383
+ const waves = p.plan.waves.map((w, i) => (i === at.k - 1 ? at.runs : w));
2384
+ const spec = componentWavesSpec(p.components, words, steps, { op: at.op, gate: at.waveGate, prGate: p.gate, waves });
2385
+ const specFile = `${PRODUCT_WAVES_DIR}/${at.op}.spec.json`;
2386
+ const refused = {};
2387
+ const result = await runOpWave({
2388
+ spec,
2389
+ specFile,
2390
+ wave: at.k,
2391
+ base: p.base,
2392
+ head: p.head,
2393
+ cwd,
2394
+ show: () => ({ sha: p.base, text: JSON.stringify(spec) }),
2395
+ gates: withWaveReview(withDecidedApproval(gitGateLedgerPort(), { op: at.op, gate: p.gate, digest: at.approved.digest, approvedBy: at.approvedBy, timestamp: new Date().toISOString() }), {
2396
+ prGate: p.gate,
2397
+ what: `Wave ${at.k}'s plan`,
2398
+ review: at.review,
2399
+ refused,
2400
+ }),
2401
+ // 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.
2402
+ runs: { append: async () => { } },
2403
+ changeSets: async (digest) => {
2404
+ if (samePlanDigest(digest, at.approved.digest))
2405
+ return at.approved;
2406
+ const { readStoredChangeSet } = await import("../../lifecycle/change-set-store.js");
2407
+ const got = await readStoredChangeSet(digest, { cwd });
2408
+ return got.status === "found" ? got.document : undefined;
2409
+ },
2410
+ lockGate: p.gate,
2411
+ // The apply's run events nest in pr-apply's stream with the derivation's wave number, as its log does.
2412
+ waveExec: componentWaveExec(p, at.noReleaseRecord, (body) => {
2413
+ const numbered = inWave(body, at.k);
2414
+ at.events?.nested(numbered);
2415
+ if (numbered.type !== "run-start")
2416
+ at.log(numbered);
2417
+ }),
2418
+ // The outcome files of this commit's waves alone, so a run of another commit on the same checkout blocks nothing here.
2419
+ outcomeDir: `${PRODUCT_WAVES_DIR}/${at.op}/outcomes-${p.head.slice(0, 12)}`,
2420
+ });
2421
+ const d = result.decision;
2422
+ const byPullRequest = d?.via === "pull-request";
2423
+ // #4553: an approval of the wave's own gate stands, but for another plan: the plan moved after its approval.
2424
+ const exitCode = result.exitCode === CHANT_EXIT.waiting && !byPullRequest && d?.mismatch && !refused.stop ? CHANT_EXIT.moved : result.exitCode;
2425
+ const entry = {
2426
+ wave: at.k,
2427
+ components: at.runs,
2428
+ status: exitCode === CHANT_EXIT.done ? "applied" : exitCode === CHANT_EXIT.waiting || exitCode === CHANT_EXIT.moved ? "waiting" : "failed",
2429
+ approval: byPullRequest || !d ? "pull-request" : "wave",
2430
+ gate: byPullRequest || !d ? p.gate : d.gate,
2431
+ digest: byPullRequest || !d ? at.approved.digest : d.digest,
2432
+ ...(byPullRequest ? (at.approvedBy.length > 0 ? { approvedBy: at.approvedBy } : {}) : d?.approvedBy ? { approvedBy: [d.approvedBy] } : {}),
2433
+ ...(!byPullRequest && d?.coveredBy?.reason ? { moved: [d.coveredBy.reason] } : {}),
2434
+ ...(!byPullRequest && d?.mismatch?.approved ? { approved: d.mismatch.approved } : {}),
2435
+ };
2436
+ // A wave that waits at its own gate is the stream's gate step there, as before op waves (#4003).
2437
+ if (d && !byPullRequest && (exitCode === CHANT_EXIT.waiting || exitCode === CHANT_EXIT.moved)) {
2438
+ const waiting = { satisfied: false, pending: { op: at.op }, ...(d.mismatch ? { mismatch: d.mismatch } : {}) };
2439
+ await emitGateStep(at.events?.emit, { op: at.op, gate: d.gate }, async () => waiting, () => 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 })}`);
2440
+ }
2441
+ const read = readWaveOutputs(at.outputsFile);
2442
+ let changeSet;
2443
+ try {
2444
+ changeSet = JSON.parse(readFileSync(join(cwd, opWavePlansPath(spec, at.k)), "utf8")).changeSet;
2445
+ }
2446
+ catch {
2447
+ // The wave stopped before it planned.
2448
+ }
2449
+ return { exitCode, applied: result.applied, failed: result.failed, entry, outputs: "error" in read ? {} : read.outputs, ...(changeSet ? { changeSet } : {}), ...(refused.stop ? { review: refused.stop } : {}) };
2450
+ }
2003
2451
  /** A wave's new plan (#4003), beside the report as `change-set-wave-<k>.json`, for whoever approves its gate. */
2004
2452
  function writeWaveChangeSet(ctx, wave, doc, upload) {
2005
2453
  const dir = resolve(ctx.args.output ?? PR_REPORT_DIR);