@intentius/chant 0.124.54 → 0.124.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1077) hide show
  1. package/dist/__fixtures__/estate-ledger.d.ts +13 -0
  2. package/dist/__fixtures__/estate-ledger.d.ts.map +1 -0
  3. package/dist/__fixtures__/estate-ledger.js +67 -0
  4. package/dist/__fixtures__/oidc-emulator.d.ts +11 -1
  5. package/dist/__fixtures__/oidc-emulator.d.ts.map +1 -1
  6. package/dist/__fixtures__/oidc-emulator.js +26 -2
  7. package/dist/__fixtures__/product-words.d.ts +78 -0
  8. package/dist/__fixtures__/product-words.d.ts.map +1 -0
  9. package/dist/__fixtures__/product-words.js +43 -0
  10. package/dist/__golden__/wave-loop/op-by-apply-after-fails.json +10 -2
  11. package/dist/__golden__/wave-loop/op-by-apply-hold.json +20 -4
  12. package/dist/__golden__/wave-loop/op-by-apply-ignored.json +10 -2
  13. package/dist/__golden__/wave-loop/op-by-apply-pass.json +10 -2
  14. package/dist/__golden__/wave-loop/op-by-apply-skip.json +10 -2
  15. package/dist/__golden__/wave-loop/op-discover-rest-stops.json +22 -6
  16. package/dist/__golden__/wave-loop/op-discover-rest.json +44 -12
  17. package/dist/__golden__/wave-loop/op-discover-wide.json +12 -3
  18. package/dist/__golden__/wave-loop/op-held-on.json +28 -7
  19. package/dist/__golden__/wave-loop/op-hooks-apply-fails.json +22 -6
  20. package/dist/__golden__/wave-loop/op-hooks-fail-after-apply.json +22 -6
  21. package/dist/__golden__/wave-loop/op-hooks-fail-before-apply.json +4 -2
  22. package/dist/__golden__/wave-loop/op-hooks-held.json +26 -8
  23. package/dist/__golden__/wave-loop/op-hooks-hold-before-apply.json +18 -4
  24. package/dist/__golden__/wave-loop/op-hooks-pass.json +22 -6
  25. package/dist/__golden__/wave-loop/op-hooks-share.json +20 -7
  26. package/dist/__golden__/wave-loop/op-outcome-held.json +12 -3
  27. package/dist/__golden__/wave-loop/op-outcome-replan-approved.json +16 -5
  28. package/dist/__golden__/wave-loop/op-outcome-replan-forever.json +48 -21
  29. package/dist/__golden__/wave-loop/op-outcome-replan.json +16 -5
  30. package/dist/__golden__/wave-loop/op-outcome-stood-down.json +12 -3
  31. package/dist/__golden__/wave-loop/op-outcome-unreadable.json +12 -3
  32. package/dist/__golden__/wave-loop/op-overridden.json +28 -7
  33. package/dist/__golden__/wave-loop/op-per-run.json +20 -4
  34. package/dist/__golden__/wave-loop/op-point.json +18 -4
  35. package/dist/__golden__/wave-loop/op-pr-review.json +10 -2
  36. package/dist/__golden__/wave-loop/op-spend-change-only.json +10 -2
  37. package/dist/__golden__/wave-loop/op-spend.json +10 -2
  38. package/dist/__golden__/wave-loop/op-wave-commands.json +56 -13
  39. package/dist/__golden__/wave-loop/op-wide.json +20 -4
  40. package/dist/bucket-check/azure.d.ts +108 -0
  41. package/dist/bucket-check/azure.d.ts.map +1 -0
  42. package/dist/bucket-check/azure.js +258 -0
  43. package/dist/bucket-check/fixtures/azure.json +153 -0
  44. package/dist/bucket-check/fixtures/gcs.json +148 -0
  45. package/dist/bucket-check/fixtures/s3.json +277 -0
  46. package/dist/bucket-check/gcs.d.ts +77 -0
  47. package/dist/bucket-check/gcs.d.ts.map +1 -0
  48. package/dist/bucket-check/gcs.js +202 -0
  49. package/dist/bucket-check/index.d.ts +48 -0
  50. package/dist/bucket-check/index.d.ts.map +1 -0
  51. package/dist/bucket-check/index.js +44 -0
  52. package/dist/bucket-check/s3.d.ts +116 -0
  53. package/dist/bucket-check/s3.d.ts.map +1 -0
  54. package/dist/bucket-check/s3.js +362 -0
  55. package/dist/bucket-check/types.d.ts +66 -0
  56. package/dist/bucket-check/types.d.ts.map +1 -0
  57. package/dist/bucket-check/types.js +31 -0
  58. package/dist/bucket-check/wire.d.ts +27 -0
  59. package/dist/bucket-check/wire.d.ts.map +1 -0
  60. package/dist/bucket-check/wire.js +32 -0
  61. package/dist/bucket-check.d.ts +6 -0
  62. package/dist/bucket-check.d.ts.map +1 -0
  63. package/dist/bucket-check.js +5 -0
  64. package/dist/capabilities/templates.d.ts.map +1 -1
  65. package/dist/capabilities/templates.js +1 -2
  66. package/dist/change-set.d.ts.map +1 -1
  67. package/dist/change-set.js +2 -3
  68. package/dist/ci-agent.d.ts +381 -0
  69. package/dist/ci-agent.d.ts.map +1 -0
  70. package/dist/ci-agent.js +832 -0
  71. package/dist/ci-audit/attribution.d.ts +111 -0
  72. package/dist/ci-audit/attribution.d.ts.map +1 -0
  73. package/dist/ci-audit/attribution.js +194 -0
  74. package/dist/ci-audit/audit-log.d.ts +144 -0
  75. package/dist/ci-audit/audit-log.d.ts.map +1 -0
  76. package/dist/ci-audit/audit-log.js +149 -0
  77. package/dist/ci-audit/index.d.ts +12 -0
  78. package/dist/ci-audit/index.d.ts.map +1 -0
  79. package/dist/ci-audit/index.js +12 -0
  80. package/dist/ci-audit/unrecorded.d.ts +74 -0
  81. package/dist/ci-audit/unrecorded.d.ts.map +1 -0
  82. package/dist/ci-audit/unrecorded.js +95 -0
  83. package/dist/ci-audit.d.ts +3 -0
  84. package/dist/ci-audit.d.ts.map +1 -0
  85. package/dist/ci-audit.js +2 -0
  86. package/dist/ci-control.d.ts +42 -0
  87. package/dist/ci-control.d.ts.map +1 -0
  88. package/dist/ci-control.js +41 -0
  89. package/dist/ci-estate/delivery.d.ts +137 -0
  90. package/dist/ci-estate/delivery.d.ts.map +1 -0
  91. package/dist/ci-estate/delivery.js +311 -0
  92. package/dist/ci-estate/overdue.d.ts +34 -0
  93. package/dist/ci-estate/overdue.d.ts.map +1 -0
  94. package/dist/ci-estate/overdue.js +58 -0
  95. package/dist/ci-estate/page.d.ts +134 -0
  96. package/dist/ci-estate/page.d.ts.map +1 -0
  97. package/dist/ci-estate/page.js +233 -0
  98. package/dist/ci-estate/rows.d.ts +118 -0
  99. package/dist/ci-estate/rows.d.ts.map +1 -0
  100. package/dist/ci-estate/rows.js +126 -0
  101. package/dist/ci-estate.d.ts +92 -0
  102. package/dist/ci-estate.d.ts.map +1 -0
  103. package/dist/ci-estate.js +82 -0
  104. package/dist/ci-handover.d.ts +29 -5
  105. package/dist/ci-handover.d.ts.map +1 -1
  106. package/dist/ci-handover.js +50 -16
  107. package/dist/ci-identity.d.ts +82 -7
  108. package/dist/ci-identity.d.ts.map +1 -1
  109. package/dist/ci-identity.js +86 -15
  110. package/dist/ci-job-guard.d.ts +139 -0
  111. package/dist/ci-job-guard.d.ts.map +1 -0
  112. package/dist/ci-job-guard.js +287 -0
  113. package/dist/ci-jobs.d.ts +7 -0
  114. package/dist/ci-jobs.d.ts.map +1 -1
  115. package/dist/ci-jobs.js +7 -0
  116. package/dist/ci-product-words.d.ts +296 -0
  117. package/dist/ci-product-words.d.ts.map +1 -0
  118. package/dist/ci-product-words.js +407 -0
  119. package/dist/ci-product.d.ts +117 -0
  120. package/dist/ci-product.d.ts.map +1 -0
  121. package/dist/ci-product.js +113 -0
  122. package/dist/ci-respond-run.d.ts +73 -0
  123. package/dist/ci-respond-run.d.ts.map +1 -0
  124. package/dist/ci-respond-run.js +247 -0
  125. package/dist/ci-respond.d.ts +189 -0
  126. package/dist/ci-respond.d.ts.map +1 -0
  127. package/dist/ci-respond.js +285 -0
  128. package/dist/cli/commands/audit.d.ts +2 -2
  129. package/dist/cli/commands/audit.d.ts.map +1 -1
  130. package/dist/cli/commands/audit.js +3 -2
  131. package/dist/cli/commands/carve.js +2 -2
  132. package/dist/cli/commands/init.d.ts +2 -0
  133. package/dist/cli/commands/init.d.ts.map +1 -1
  134. package/dist/cli/commands/init.js +1 -1
  135. package/dist/cli/handlers/agent.d.ts +17 -0
  136. package/dist/cli/handlers/agent.d.ts.map +1 -0
  137. package/dist/cli/handlers/agent.js +114 -0
  138. package/dist/cli/handlers/approve-confirm.d.ts +84 -0
  139. package/dist/cli/handlers/approve-confirm.d.ts.map +1 -0
  140. package/dist/cli/handlers/approve-confirm.js +142 -0
  141. package/dist/cli/handlers/approve.d.ts.map +1 -1
  142. package/dist/cli/handlers/approve.js +19 -1
  143. package/dist/cli/handlers/audit-log.d.ts +12 -0
  144. package/dist/cli/handlers/audit-log.d.ts.map +1 -0
  145. package/dist/cli/handlers/audit-log.js +81 -0
  146. package/dist/cli/handlers/build.d.ts +7 -0
  147. package/dist/cli/handlers/build.d.ts.map +1 -1
  148. package/dist/cli/handlers/build.js +124 -1
  149. package/dist/cli/handlers/ci-check-job.d.ts +11 -0
  150. package/dist/cli/handlers/ci-check-job.d.ts.map +1 -0
  151. package/dist/cli/handlers/ci-check-job.js +27 -0
  152. package/dist/cli/handlers/ci-check.d.ts +3 -0
  153. package/dist/cli/handlers/ci-check.d.ts.map +1 -0
  154. package/dist/cli/handlers/ci-check.js +63 -0
  155. package/dist/cli/handlers/ci-forge-check.d.ts +3 -0
  156. package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -0
  157. package/dist/cli/handlers/ci-forge-check.js +89 -0
  158. package/dist/cli/handlers/e2e-safe-run.d.ts +12 -0
  159. package/dist/cli/handlers/e2e-safe-run.d.ts.map +1 -0
  160. package/dist/cli/handlers/e2e-safe-run.js +23 -0
  161. package/dist/cli/handlers/fan-out.js +4 -0
  162. package/dist/cli/handlers/gate-pending.d.ts +11 -0
  163. package/dist/cli/handlers/gate-pending.d.ts.map +1 -0
  164. package/dist/cli/handlers/gate-pending.js +44 -0
  165. package/dist/cli/handlers/init.d.ts.map +1 -1
  166. package/dist/cli/handlers/init.js +1 -0
  167. package/dist/cli/handlers/ledger.js +1 -1
  168. package/dist/cli/handlers/lifecycle-drift.d.ts +6 -2
  169. package/dist/cli/handlers/lifecycle-drift.d.ts.map +1 -1
  170. package/dist/cli/handlers/lifecycle-drift.js +7 -2
  171. package/dist/cli/handlers/lock.d.ts.map +1 -1
  172. package/dist/cli/handlers/lock.js +64 -5
  173. package/dist/cli/handlers/notify-relay.d.ts +15 -0
  174. package/dist/cli/handlers/notify-relay.d.ts.map +1 -0
  175. package/dist/cli/handlers/notify-relay.js +130 -0
  176. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  177. package/dist/cli/handlers/pr-env.js +42 -11
  178. package/dist/cli/handlers/pr.d.ts +43 -3
  179. package/dist/cli/handlers/pr.d.ts.map +1 -1
  180. package/dist/cli/handlers/pr.js +908 -205
  181. package/dist/cli/handlers/promote.d.ts.map +1 -1
  182. package/dist/cli/handlers/promote.js +21 -2
  183. package/dist/cli/handlers/release.d.ts.map +1 -1
  184. package/dist/cli/handlers/release.js +3 -0
  185. package/dist/cli/handlers/run-wave.d.ts +8 -0
  186. package/dist/cli/handlers/run-wave.d.ts.map +1 -1
  187. package/dist/cli/handlers/run-wave.js +160 -2
  188. package/dist/cli/handlers/run.d.ts +6 -1
  189. package/dist/cli/handlers/run.d.ts.map +1 -1
  190. package/dist/cli/handlers/run.js +86 -1
  191. package/dist/cli/handlers/serve.d.ts.map +1 -1
  192. package/dist/cli/handlers/serve.js +10 -1
  193. package/dist/cli/main.d.ts +11 -1
  194. package/dist/cli/main.d.ts.map +1 -1
  195. package/dist/cli/main.js +178 -13
  196. package/dist/cli/mcp/ledger-tools.d.ts +36 -0
  197. package/dist/cli/mcp/ledger-tools.d.ts.map +1 -0
  198. package/dist/cli/mcp/ledger-tools.js +122 -0
  199. package/dist/cli/mcp/product-tools.d.ts +78 -0
  200. package/dist/cli/mcp/product-tools.d.ts.map +1 -0
  201. package/dist/cli/mcp/product-tools.js +93 -0
  202. package/dist/cli/mcp/read-only.d.ts +34 -0
  203. package/dist/cli/mcp/read-only.d.ts.map +1 -0
  204. package/dist/cli/mcp/read-only.js +61 -0
  205. package/dist/cli/mcp/report-tools.d.ts +48 -0
  206. package/dist/cli/mcp/report-tools.d.ts.map +1 -0
  207. package/dist/cli/mcp/report-tools.js +128 -0
  208. package/dist/cli/mcp/server.d.ts +28 -1
  209. package/dist/cli/mcp/server.d.ts.map +1 -1
  210. package/dist/cli/mcp/server.js +86 -15
  211. package/dist/cli/mcp-config.d.ts +9 -2
  212. package/dist/cli/mcp-config.d.ts.map +1 -1
  213. package/dist/cli/mcp-config.js +8 -3
  214. package/dist/cli/parse-args.d.ts.map +1 -1
  215. package/dist/cli/parse-args.js +164 -3
  216. package/dist/cli/registry.d.ts +73 -0
  217. package/dist/cli/registry.d.ts.map +1 -1
  218. package/dist/cloud-lister/sigv4.d.ts +42 -7
  219. package/dist/cloud-lister/sigv4.d.ts.map +1 -1
  220. package/dist/cloud-lister/sigv4.js +72 -22
  221. package/dist/components/adoption.d.ts +69 -0
  222. package/dist/components/adoption.d.ts.map +1 -0
  223. package/dist/components/adoption.js +92 -0
  224. package/dist/components/apply-lease.d.ts +19 -0
  225. package/dist/components/apply-lease.d.ts.map +1 -0
  226. package/dist/components/apply-lease.js +41 -0
  227. package/dist/components/capability.d.ts +159 -5
  228. package/dist/components/capability.d.ts.map +1 -1
  229. package/dist/components/capability.js +39 -6
  230. package/dist/components/check-hooks.d.ts +116 -0
  231. package/dist/components/check-hooks.d.ts.map +1 -0
  232. package/dist/components/check-hooks.js +192 -0
  233. package/dist/components/check-steps.d.ts +74 -0
  234. package/dist/components/check-steps.d.ts.map +1 -0
  235. package/dist/components/check-steps.js +102 -0
  236. package/dist/components/ci-services.d.ts +57 -0
  237. package/dist/components/ci-services.d.ts.map +1 -0
  238. package/dist/components/ci-services.js +60 -0
  239. package/dist/components/cli-support.d.ts +13 -0
  240. package/dist/components/cli-support.d.ts.map +1 -1
  241. package/dist/components/cli-support.js +10 -2
  242. package/dist/components/driver.d.ts +32 -3
  243. package/dist/components/driver.d.ts.map +1 -1
  244. package/dist/components/driver.js +59 -5
  245. package/dist/components/fan-out-run.d.ts +12 -0
  246. package/dist/components/fan-out-run.d.ts.map +1 -1
  247. package/dist/components/fan-out-run.js +56 -16
  248. package/dist/components/groups.d.ts.map +1 -1
  249. package/dist/components/groups.js +23 -5
  250. package/dist/components/pr-env-ledger.d.ts +32 -0
  251. package/dist/components/pr-env-ledger.d.ts.map +1 -0
  252. package/dist/components/pr-env-ledger.js +38 -0
  253. package/dist/components/pr-env-ports.d.ts +12 -0
  254. package/dist/components/pr-env-ports.d.ts.map +1 -1
  255. package/dist/components/pr-env-ports.js +13 -3
  256. package/dist/components/pr-env-run.d.ts +6 -0
  257. package/dist/components/pr-env-run.d.ts.map +1 -1
  258. package/dist/components/pr-env-run.js +3 -2
  259. package/dist/components/pr-environment.d.ts +32 -4
  260. package/dist/components/pr-environment.d.ts.map +1 -1
  261. package/dist/components/pr-environment.js +26 -8
  262. package/dist/components/pr-pipeline.d.ts +297 -5
  263. package/dist/components/pr-pipeline.d.ts.map +1 -1
  264. package/dist/components/pr-pipeline.js +329 -18
  265. package/dist/components/pr-policy.d.ts +26 -2
  266. package/dist/components/pr-policy.d.ts.map +1 -1
  267. package/dist/components/pr-policy.js +41 -7
  268. package/dist/components/pr-run.d.ts +71 -0
  269. package/dist/components/pr-run.d.ts.map +1 -1
  270. package/dist/components/pr-run.js +91 -7
  271. package/dist/components/pr-targets.d.ts +24 -0
  272. package/dist/components/pr-targets.d.ts.map +1 -0
  273. package/dist/components/pr-targets.js +48 -0
  274. package/dist/components/product-pipeline.d.ts +250 -0
  275. package/dist/components/product-pipeline.d.ts.map +1 -0
  276. package/dist/components/product-pipeline.js +212 -0
  277. package/dist/components/promote.d.ts +6 -0
  278. package/dist/components/promote.d.ts.map +1 -1
  279. package/dist/components/promote.js +4 -1
  280. package/dist/components/release-compile.d.ts +22 -1
  281. package/dist/components/release-compile.d.ts.map +1 -1
  282. package/dist/components/release-compile.js +85 -0
  283. package/dist/components/release-promote.d.ts +15 -1
  284. package/dist/components/release-promote.d.ts.map +1 -1
  285. package/dist/components/release-promote.js +67 -2
  286. package/dist/components/repo-lock.d.ts +27 -0
  287. package/dist/components/repo-lock.d.ts.map +1 -0
  288. package/dist/components/repo-lock.js +49 -0
  289. package/dist/components/row-lease.d.ts +84 -0
  290. package/dist/components/row-lease.d.ts.map +1 -0
  291. package/dist/components/row-lease.js +110 -0
  292. package/dist/components/wave-plan.d.ts +42 -0
  293. package/dist/components/wave-plan.d.ts.map +1 -1
  294. package/dist/components/wave-plan.js +72 -4
  295. package/dist/control/applied.d.ts +89 -0
  296. package/dist/control/applied.d.ts.map +1 -0
  297. package/dist/control/applied.js +175 -0
  298. package/dist/control/consumers.d.ts +78 -0
  299. package/dist/control/consumers.d.ts.map +1 -0
  300. package/dist/control/consumers.js +172 -0
  301. package/dist/control/dispatch.d.ts +334 -0
  302. package/dist/control/dispatch.d.ts.map +1 -0
  303. package/dist/control/dispatch.js +519 -0
  304. package/dist/control/edges.d.ts +75 -0
  305. package/dist/control/edges.d.ts.map +1 -0
  306. package/dist/control/edges.js +133 -0
  307. package/dist/control/reconcile.d.ts +120 -0
  308. package/dist/control/reconcile.d.ts.map +1 -0
  309. package/dist/control/reconcile.js +178 -0
  310. package/dist/control/records.d.ts +187 -0
  311. package/dist/control/records.d.ts.map +1 -0
  312. package/dist/control/records.js +307 -0
  313. package/dist/discovery/sandbox/bundle.d.ts.map +1 -1
  314. package/dist/discovery/sandbox/bundle.js +25 -1
  315. package/dist/e2e-harness/bucket.d.ts +21 -0
  316. package/dist/e2e-harness/bucket.d.ts.map +1 -0
  317. package/dist/e2e-harness/bucket.js +61 -0
  318. package/dist/e2e-harness/claim.d.ts +70 -0
  319. package/dist/e2e-harness/claim.d.ts.map +1 -0
  320. package/dist/e2e-harness/claim.js +98 -0
  321. package/dist/e2e-harness/driver.d.ts +64 -0
  322. package/dist/e2e-harness/driver.d.ts.map +1 -0
  323. package/dist/e2e-harness/driver.js +243 -0
  324. package/dist/e2e-harness/forgejo.d.ts +77 -0
  325. package/dist/e2e-harness/forgejo.d.ts.map +1 -0
  326. package/dist/e2e-harness/forgejo.js +205 -0
  327. package/dist/e2e-harness/git.d.ts +32 -0
  328. package/dist/e2e-harness/git.d.ts.map +1 -0
  329. package/dist/e2e-harness/git.js +67 -0
  330. package/dist/e2e-harness/index.d.ts +22 -0
  331. package/dist/e2e-harness/index.d.ts.map +1 -0
  332. package/dist/e2e-harness/index.js +48 -0
  333. package/dist/e2e-harness/jobs.d.ts +8 -0
  334. package/dist/e2e-harness/jobs.d.ts.map +1 -0
  335. package/dist/e2e-harness/jobs.js +34 -0
  336. package/dist/e2e-harness/pins.d.ts +45 -0
  337. package/dist/e2e-harness/pins.d.ts.map +1 -0
  338. package/dist/e2e-harness/pins.js +44 -0
  339. package/dist/e2e-harness/ports.d.ts +113 -0
  340. package/dist/e2e-harness/ports.d.ts.map +1 -0
  341. package/dist/e2e-harness/ports.js +4 -0
  342. package/dist/e2e-harness/reports.d.ts +45 -0
  343. package/dist/e2e-harness/reports.d.ts.map +1 -0
  344. package/dist/e2e-harness/reports.js +57 -0
  345. package/dist/e2e-harness/safe-run-cli.d.ts +17 -0
  346. package/dist/e2e-harness/safe-run-cli.d.ts.map +1 -0
  347. package/dist/e2e-harness/safe-run-cli.js +43 -0
  348. package/dist/e2e-harness/safe-run.d.ts +61 -0
  349. package/dist/e2e-harness/safe-run.d.ts.map +1 -0
  350. package/dist/e2e-harness/safe-run.js +172 -0
  351. package/dist/e2e-harness/scenario.d.ts +11 -0
  352. package/dist/e2e-harness/scenario.d.ts.map +1 -0
  353. package/dist/e2e-harness/scenario.js +89 -0
  354. package/dist/e2e-harness/schemas/demo-cycle.schema.json +282 -0
  355. package/dist/e2e-harness/schemas/demo-step.schema.json +245 -0
  356. package/dist/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
  357. package/dist/e2e-harness/schemas/e2e-claims.schema.json +18 -0
  358. package/dist/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
  359. package/dist/e2e-harness/schemas/index.d.ts +191 -0
  360. package/dist/e2e-harness/schemas/index.d.ts.map +1 -0
  361. package/dist/e2e-harness/schemas/index.js +62 -0
  362. package/dist/e2e-harness/stack.d.ts +124 -0
  363. package/dist/e2e-harness/stack.d.ts.map +1 -0
  364. package/dist/e2e-harness/stack.js +207 -0
  365. package/dist/e2e-harness/steps.d.ts +11 -0
  366. package/dist/e2e-harness/steps.d.ts.map +1 -0
  367. package/dist/e2e-harness/steps.js +22 -0
  368. package/dist/e2e-harness.d.ts +3 -0
  369. package/dist/e2e-harness.d.ts.map +1 -0
  370. package/dist/e2e-harness.js +2 -0
  371. package/dist/engine-facts.d.ts.map +1 -1
  372. package/dist/engine-facts.js +1 -2
  373. package/dist/exit-codes.d.ts +54 -0
  374. package/dist/exit-codes.d.ts.map +1 -0
  375. package/dist/exit-codes.js +55 -0
  376. package/dist/forge-check/check.d.ts +63 -0
  377. package/dist/forge-check/check.d.ts.map +1 -0
  378. package/dist/forge-check/check.js +139 -0
  379. package/dist/forge-check/contract.d.ts +152 -0
  380. package/dist/forge-check/contract.d.ts.map +1 -0
  381. package/dist/forge-check/contract.js +118 -0
  382. package/dist/forge-check/forge.d.ts +42 -0
  383. package/dist/forge-check/forge.d.ts.map +1 -0
  384. package/dist/forge-check/forge.js +338 -0
  385. package/dist/forge-check/index.d.ts +24 -0
  386. package/dist/forge-check/index.d.ts.map +1 -0
  387. package/dist/forge-check/index.js +23 -0
  388. package/dist/forge-check/pulumi.d.ts +44 -0
  389. package/dist/forge-check/pulumi.d.ts.map +1 -0
  390. package/dist/forge-check/pulumi.js +184 -0
  391. package/dist/forge-check/read-only.d.ts +26 -0
  392. package/dist/forge-check/read-only.d.ts.map +1 -0
  393. package/dist/forge-check/read-only.js +53 -0
  394. package/dist/forge-check/trust.d.ts +94 -0
  395. package/dist/forge-check/trust.d.ts.map +1 -0
  396. package/dist/forge-check/trust.js +532 -0
  397. package/dist/forge-check/types.d.ts +80 -0
  398. package/dist/forge-check/types.d.ts.map +1 -0
  399. package/dist/forge-check/types.js +18 -0
  400. package/dist/forge-check.d.ts +6 -0
  401. package/dist/forge-check.d.ts.map +1 -0
  402. package/dist/forge-check.js +5 -0
  403. package/dist/gate-decision.d.ts +1 -0
  404. package/dist/gate-decision.d.ts.map +1 -1
  405. package/dist/gate-decision.js +2 -0
  406. package/dist/gate-policy.d.ts +47 -1
  407. package/dist/gate-policy.d.ts.map +1 -1
  408. package/dist/gate-policy.js +50 -2
  409. package/dist/index.d.ts +1 -0
  410. package/dist/index.d.ts.map +1 -1
  411. package/dist/index.js +2 -0
  412. package/dist/lexicon.d.ts +152 -6
  413. package/dist/lexicon.d.ts.map +1 -1
  414. package/dist/lifecycle/adoption-file.d.ts +24 -0
  415. package/dist/lifecycle/adoption-file.d.ts.map +1 -1
  416. package/dist/lifecycle/adoption-file.js +1 -2
  417. package/dist/lifecycle/cloud-index.d.ts.map +1 -1
  418. package/dist/lifecycle/cloud-index.js +1 -2
  419. package/dist/lifecycle/gate-applied.d.ts +6 -0
  420. package/dist/lifecycle/gate-applied.d.ts.map +1 -1
  421. package/dist/lifecycle/gate-ledger.d.ts +29 -0
  422. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  423. package/dist/lifecycle/gate-ledger.js +10 -1
  424. package/dist/lifecycle/gate-pending-by-plan.d.ts +75 -0
  425. package/dist/lifecycle/gate-pending-by-plan.d.ts.map +1 -0
  426. package/dist/lifecycle/gate-pending-by-plan.js +96 -0
  427. package/dist/lifecycle/gated-request-digest.d.ts +28 -0
  428. package/dist/lifecycle/gated-request-digest.d.ts.map +1 -0
  429. package/dist/lifecycle/gated-request-digest.js +35 -0
  430. package/dist/lifecycle/gated-request.d.ts +126 -0
  431. package/dist/lifecycle/gated-request.d.ts.map +1 -0
  432. package/dist/lifecycle/gated-request.js +204 -0
  433. package/dist/lifecycle/identity-match.d.ts +15 -0
  434. package/dist/lifecycle/identity-match.d.ts.map +1 -1
  435. package/dist/lifecycle/identity-match.js +11 -6
  436. package/dist/lifecycle/index-diff.d.ts +40 -0
  437. package/dist/lifecycle/index-diff.d.ts.map +1 -1
  438. package/dist/lifecycle/index-diff.js +1 -2
  439. package/dist/lifecycle/index-document.d.ts.map +1 -1
  440. package/dist/lifecycle/index-document.js +1 -2
  441. package/dist/lifecycle/index-import.d.ts +4 -1
  442. package/dist/lifecycle/index-import.d.ts.map +1 -1
  443. package/dist/lifecycle/index-import.js +29 -32
  444. package/dist/lifecycle/ledger-read.d.ts.map +1 -1
  445. package/dist/lifecycle/ledger-read.js +7 -3
  446. package/dist/lifecycle/lock-rows.d.ts +76 -0
  447. package/dist/lifecycle/lock-rows.d.ts.map +1 -0
  448. package/dist/lifecycle/lock-rows.js +140 -0
  449. package/dist/lifecycle/query.d.ts +50 -3
  450. package/dist/lifecycle/query.d.ts.map +1 -1
  451. package/dist/lifecycle/query.js +97 -7
  452. package/dist/lifecycle/release-catalog-site.d.ts +66 -0
  453. package/dist/lifecycle/release-catalog-site.d.ts.map +1 -0
  454. package/dist/lifecycle/release-catalog-site.js +232 -0
  455. package/dist/lifecycle/release-catalog.d.ts +201 -0
  456. package/dist/lifecycle/release-catalog.d.ts.map +1 -0
  457. package/dist/lifecycle/release-catalog.js +198 -0
  458. package/dist/lifecycle/release-changelog.d.ts +41 -0
  459. package/dist/lifecycle/release-changelog.d.ts.map +1 -0
  460. package/dist/lifecycle/release-changelog.js +38 -0
  461. package/dist/lifecycle/release-cut.d.ts +1 -0
  462. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  463. package/dist/lifecycle/release-cut.js +1 -1
  464. package/dist/lifecycle/release-ledger.d.ts +16 -0
  465. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  466. package/dist/lifecycle/release-ledger.js +9 -0
  467. package/dist/lifecycle/release-publish.d.ts +43 -22
  468. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  469. package/dist/lifecycle/release-read.d.ts.map +1 -1
  470. package/dist/lifecycle/release-read.js +3 -0
  471. package/dist/lifecycle/release-status.d.ts +106 -0
  472. package/dist/lifecycle/release-status.d.ts.map +1 -0
  473. package/dist/lifecycle/release-status.js +115 -0
  474. package/dist/lifecycle/resource-lock.d.ts +120 -0
  475. package/dist/lifecycle/resource-lock.d.ts.map +1 -0
  476. package/dist/lifecycle/resource-lock.js +317 -0
  477. package/dist/lifecycle/retention.d.ts.map +1 -1
  478. package/dist/lifecycle/retention.js +3 -0
  479. package/dist/lifecycle/run-ledger.d.ts.map +1 -1
  480. package/dist/lifecycle/run-ledger.js +9 -1
  481. package/dist/lifecycle/snapshot-store-s3.d.ts +36 -3
  482. package/dist/lifecycle/snapshot-store-s3.d.ts.map +1 -1
  483. package/dist/lifecycle/snapshot-store-s3.js +9 -44
  484. package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
  485. package/dist/lifecycle/snapshot-store.js +1 -2
  486. package/dist/lifecycle/target-lock.d.ts +15 -0
  487. package/dist/lifecycle/target-lock.d.ts.map +1 -1
  488. package/dist/lifecycle/target-lock.js +25 -10
  489. package/dist/lifecycle/wave-plans.d.ts +23 -7
  490. package/dist/lifecycle/wave-plans.d.ts.map +1 -1
  491. package/dist/lifecycle/wave-plans.js +9 -2
  492. package/dist/mcp/types.d.ts +7 -0
  493. package/dist/mcp/types.d.ts.map +1 -1
  494. package/dist/notify-product.d.ts +43 -0
  495. package/dist/notify-product.d.ts.map +1 -0
  496. package/dist/notify-product.js +58 -0
  497. package/dist/notify-relay.d.ts +197 -0
  498. package/dist/notify-relay.d.ts.map +1 -0
  499. package/dist/notify-relay.js +321 -0
  500. package/dist/notify.d.ts +44 -4
  501. package/dist/notify.d.ts.map +1 -1
  502. package/dist/notify.js +77 -14
  503. package/dist/object-store/azure-blob.d.ts +129 -0
  504. package/dist/object-store/azure-blob.d.ts.map +1 -0
  505. package/dist/object-store/azure-blob.js +341 -0
  506. package/dist/object-store/common.d.ts +108 -0
  507. package/dist/object-store/common.d.ts.map +1 -0
  508. package/dist/object-store/common.js +80 -0
  509. package/dist/object-store/errors.d.ts +28 -0
  510. package/dist/object-store/errors.d.ts.map +1 -0
  511. package/dist/object-store/errors.js +21 -0
  512. package/dist/object-store/from-env.d.ts +18 -0
  513. package/dist/object-store/from-env.d.ts.map +1 -0
  514. package/dist/object-store/from-env.js +22 -0
  515. package/dist/object-store/gcs.d.ts +106 -0
  516. package/dist/object-store/gcs.d.ts.map +1 -0
  517. package/dist/object-store/gcs.js +393 -0
  518. package/dist/object-store/index.d.ts +9 -0
  519. package/dist/object-store/index.d.ts.map +1 -0
  520. package/dist/object-store/index.js +8 -0
  521. package/dist/object-store/s3.d.ts +146 -0
  522. package/dist/object-store/s3.d.ts.map +1 -0
  523. package/dist/object-store/s3.js +306 -0
  524. package/dist/op/activities/converge.d.ts.map +1 -1
  525. package/dist/op/activities/converge.js +2 -1
  526. package/dist/op/activities/index.d.ts +1 -1
  527. package/dist/op/activities/index.d.ts.map +1 -1
  528. package/dist/op/activities/index.js +1 -1
  529. package/dist/op/activities/review-agent.d.ts +55 -2
  530. package/dist/op/activities/review-agent.d.ts.map +1 -1
  531. package/dist/op/activities/review-agent.js +65 -5
  532. package/dist/op/approval-status.d.ts +103 -0
  533. package/dist/op/approval-status.d.ts.map +1 -0
  534. package/dist/op/approval-status.js +197 -0
  535. package/dist/op/gate.d.ts +29 -1
  536. package/dist/op/gate.d.ts.map +1 -1
  537. package/dist/op/gate.js +59 -23
  538. package/dist/op/generate-pipeline.d.ts.map +1 -1
  539. package/dist/op/generate-pipeline.js +7 -1
  540. package/dist/op/index.d.ts +12 -1
  541. package/dist/op/index.d.ts.map +1 -1
  542. package/dist/op/index.js +7 -1
  543. package/dist/op/op-waves-after-plan.d.ts +137 -0
  544. package/dist/op/op-waves-after-plan.d.ts.map +1 -0
  545. package/dist/op/op-waves-after-plan.js +163 -0
  546. package/dist/op/op-waves-capability-spec.d.ts +63 -0
  547. package/dist/op/op-waves-capability-spec.d.ts.map +1 -0
  548. package/dist/op/op-waves-capability-spec.js +115 -0
  549. package/dist/op/op-waves-capability.d.ts +197 -0
  550. package/dist/op/op-waves-capability.d.ts.map +1 -0
  551. package/dist/op/op-waves-capability.js +311 -0
  552. package/dist/op/op-waves-events.d.ts +54 -0
  553. package/dist/op/op-waves-events.d.ts.map +1 -0
  554. package/dist/op/op-waves-events.js +122 -0
  555. package/dist/op/op-waves-notify.d.ts +7 -1
  556. package/dist/op/op-waves-notify.d.ts.map +1 -1
  557. package/dist/op/op-waves-notify.js +35 -16
  558. package/dist/op/op-waves-release-port.d.ts +18 -0
  559. package/dist/op/op-waves-release-port.d.ts.map +1 -0
  560. package/dist/op/op-waves-release-port.js +61 -0
  561. package/dist/op/op-waves-release.d.ts +92 -0
  562. package/dist/op/op-waves-release.d.ts.map +1 -0
  563. package/dist/op/op-waves-release.js +96 -0
  564. package/dist/op/op-waves-run.d.ts +182 -6
  565. package/dist/op/op-waves-run.d.ts.map +1 -1
  566. package/dist/op/op-waves-run.js +1076 -44
  567. package/dist/op/op-waves-stand-down.d.ts +60 -0
  568. package/dist/op/op-waves-stand-down.d.ts.map +1 -0
  569. package/dist/op/op-waves-stand-down.js +96 -0
  570. package/dist/op/op-waves.d.ts +187 -8
  571. package/dist/op/op-waves.d.ts.map +1 -1
  572. package/dist/op/op-waves.js +203 -19
  573. package/dist/op/runtime.d.ts +95 -0
  574. package/dist/op/runtime.d.ts.map +1 -1
  575. package/dist/op/runtime.js +18 -0
  576. package/dist/op/stage-hooks.d.ts +45 -7
  577. package/dist/op/stage-hooks.d.ts.map +1 -1
  578. package/dist/op/stage-hooks.js +61 -3
  579. package/dist/op/steward-beside.d.ts.map +1 -1
  580. package/dist/op/steward-beside.js +2 -1
  581. package/dist/op/types.d.ts +2 -2
  582. package/dist/op/types.d.ts.map +1 -1
  583. package/dist/op/types.js +3 -2
  584. package/dist/otlp-metrics.d.ts +38 -0
  585. package/dist/otlp-metrics.d.ts.map +1 -0
  586. package/dist/otlp-metrics.js +82 -0
  587. package/dist/otlp.d.ts +249 -0
  588. package/dist/otlp.d.ts.map +1 -0
  589. package/dist/otlp.js +425 -0
  590. package/dist/override-gate.d.ts.map +1 -1
  591. package/dist/override-gate.js +5 -0
  592. package/dist/parallelism.d.ts +17 -0
  593. package/dist/parallelism.d.ts.map +1 -0
  594. package/dist/parallelism.js +33 -0
  595. package/dist/policy-packs.d.ts +69 -0
  596. package/dist/policy-packs.d.ts.map +1 -0
  597. package/dist/policy-packs.js +205 -0
  598. package/dist/policy-source.d.ts +51 -0
  599. package/dist/policy-source.d.ts.map +1 -0
  600. package/dist/policy-source.js +102 -0
  601. package/dist/pr-forge.d.ts +40 -0
  602. package/dist/pr-forge.d.ts.map +1 -1
  603. package/dist/pr-forge.js +146 -37
  604. package/dist/pr-loop.d.ts +158 -11
  605. package/dist/pr-loop.d.ts.map +1 -1
  606. package/dist/pr-loop.js +302 -44
  607. package/dist/pr-merge.d.ts +64 -0
  608. package/dist/pr-merge.d.ts.map +1 -0
  609. package/dist/pr-merge.js +78 -0
  610. package/dist/pr-post.d.ts +86 -1
  611. package/dist/pr-post.d.ts.map +1 -1
  612. package/dist/pr-post.js +141 -5
  613. package/dist/pr-report-url.d.ts +32 -4
  614. package/dist/pr-report-url.d.ts.map +1 -1
  615. package/dist/pr-report-url.js +45 -5
  616. package/dist/pr-requires.d.ts +13 -2
  617. package/dist/pr-requires.d.ts.map +1 -1
  618. package/dist/pr-requires.js +14 -0
  619. package/dist/release-floors.d.ts +1 -1
  620. package/dist/release-floors.js +1 -1
  621. package/dist/run-event.d.ts +26 -1
  622. package/dist/run-event.d.ts.map +1 -1
  623. package/dist/run-event.js +3 -1
  624. package/dist/scheduled-op-cloud.d.ts +32 -0
  625. package/dist/scheduled-op-cloud.d.ts.map +1 -0
  626. package/dist/scheduled-op-cloud.js +69 -0
  627. package/dist/sorted-json.d.ts +10 -0
  628. package/dist/sorted-json.d.ts.map +1 -0
  629. package/dist/sorted-json.js +14 -0
  630. package/dist/terraform/credentials.d.ts +59 -0
  631. package/dist/terraform/credentials.d.ts.map +1 -0
  632. package/dist/terraform/credentials.js +149 -0
  633. package/dist/utils.d.ts +1 -4
  634. package/dist/utils.d.ts.map +1 -1
  635. package/dist/utils.js +1 -9
  636. package/dist/wave-runtime.d.ts +1 -1
  637. package/dist/wave-runtime.js +2 -2
  638. package/dist/wave-runtime.mjs +405 -287
  639. package/dist/workspace/chant-migrations/chud-lexicon-exit.d.ts.map +1 -1
  640. package/dist/workspace/chant-migrations/chud-lexicon-exit.js +4 -1
  641. package/dist/workspace/ci-lock-grain.d.ts +17 -0
  642. package/dist/workspace/ci-lock-grain.d.ts.map +1 -0
  643. package/dist/workspace/ci-lock-grain.js +21 -0
  644. package/dist/workspace/ci-run.d.ts +2 -1
  645. package/dist/workspace/ci-run.d.ts.map +1 -1
  646. package/dist/workspace/ci-run.js +10 -3
  647. package/dist/workspace/declaration.d.ts +16 -4
  648. package/dist/workspace/declaration.d.ts.map +1 -1
  649. package/dist/workspace/declaration.js +5 -2
  650. package/dist/workspace/declaration.schema.json +27 -3
  651. package/dist/workspace/drift-cli.d.ts.map +1 -1
  652. package/dist/workspace/drift-cli.js +8 -3
  653. package/dist/workspace/exit-cli.d.ts +1 -1
  654. package/dist/workspace/exit-cli.d.ts.map +1 -1
  655. package/dist/workspace/exit-cli.js +2 -1
  656. package/dist/workspace/import-fetch.d.ts +4 -2
  657. package/dist/workspace/import-fetch.d.ts.map +1 -1
  658. package/dist/workspace/import-fetch.js +4 -2
  659. package/dist/workspace/import-init.d.ts.map +1 -1
  660. package/dist/workspace/import-init.js +4 -2
  661. package/dist/workspace/ledger.schema.json +7 -3
  662. package/dist/workspace/lineage-upgrade-cli.d.ts +1 -1
  663. package/dist/workspace/lineage-upgrade-cli.d.ts.map +1 -1
  664. package/dist/workspace/lineage-upgrade-cli.js +2 -1
  665. package/dist/workspace/pr-report.schema.json +79 -3
  666. package/dist/workspace/promote.d.ts +1 -1
  667. package/dist/workspace/promote.d.ts.map +1 -1
  668. package/dist/workspace/promote.js +2 -1
  669. package/dist/workspace/records-cli.d.ts +2 -2
  670. package/dist/workspace/records-cli.d.ts.map +1 -1
  671. package/dist/workspace/records-cli.js +3 -2
  672. package/dist/workspace/release-catalog.schema.json +277 -0
  673. package/dist/workspace/run-event.schema.json +18 -1
  674. package/dist/workspace/work-cli.d.ts +3 -1
  675. package/dist/workspace/work-cli.d.ts.map +1 -1
  676. package/dist/workspace/work-cli.js +7 -2
  677. package/dist/workspace/workspace-run.d.ts.map +1 -1
  678. package/dist/workspace/workspace-run.js +2 -1
  679. package/package.json +21 -1
  680. package/src/__fixtures__/estate-ledger.ts +101 -0
  681. package/src/__fixtures__/oidc-emulator.ts +31 -2
  682. package/src/__fixtures__/product-words.ts +44 -0
  683. package/src/__golden__/wave-loop/op-by-apply-after-fails.json +10 -2
  684. package/src/__golden__/wave-loop/op-by-apply-hold.json +20 -4
  685. package/src/__golden__/wave-loop/op-by-apply-ignored.json +10 -2
  686. package/src/__golden__/wave-loop/op-by-apply-pass.json +10 -2
  687. package/src/__golden__/wave-loop/op-by-apply-skip.json +10 -2
  688. package/src/__golden__/wave-loop/op-discover-rest-stops.json +22 -6
  689. package/src/__golden__/wave-loop/op-discover-rest.json +44 -12
  690. package/src/__golden__/wave-loop/op-discover-wide.json +12 -3
  691. package/src/__golden__/wave-loop/op-held-on.json +28 -7
  692. package/src/__golden__/wave-loop/op-hooks-apply-fails.json +22 -6
  693. package/src/__golden__/wave-loop/op-hooks-fail-after-apply.json +22 -6
  694. package/src/__golden__/wave-loop/op-hooks-fail-before-apply.json +4 -2
  695. package/src/__golden__/wave-loop/op-hooks-held.json +26 -8
  696. package/src/__golden__/wave-loop/op-hooks-hold-before-apply.json +18 -4
  697. package/src/__golden__/wave-loop/op-hooks-pass.json +22 -6
  698. package/src/__golden__/wave-loop/op-hooks-share.json +20 -7
  699. package/src/__golden__/wave-loop/op-outcome-held.json +12 -3
  700. package/src/__golden__/wave-loop/op-outcome-replan-approved.json +16 -5
  701. package/src/__golden__/wave-loop/op-outcome-replan-forever.json +48 -21
  702. package/src/__golden__/wave-loop/op-outcome-replan.json +16 -5
  703. package/src/__golden__/wave-loop/op-outcome-stood-down.json +12 -3
  704. package/src/__golden__/wave-loop/op-outcome-unreadable.json +12 -3
  705. package/src/__golden__/wave-loop/op-overridden.json +28 -7
  706. package/src/__golden__/wave-loop/op-per-run.json +20 -4
  707. package/src/__golden__/wave-loop/op-point.json +18 -4
  708. package/src/__golden__/wave-loop/op-pr-review.json +10 -2
  709. package/src/__golden__/wave-loop/op-spend-change-only.json +10 -2
  710. package/src/__golden__/wave-loop/op-spend.json +10 -2
  711. package/src/__golden__/wave-loop/op-wave-commands.json +56 -13
  712. package/src/__golden__/wave-loop/op-wide.json +20 -4
  713. package/src/bucket-check/azure.ts +307 -0
  714. package/src/bucket-check/bucket-check.test.ts +210 -0
  715. package/src/bucket-check/fixtures/azure.json +153 -0
  716. package/src/bucket-check/fixtures/gcs.json +148 -0
  717. package/src/bucket-check/fixtures/s3.json +277 -0
  718. package/src/bucket-check/gcs.ts +257 -0
  719. package/src/bucket-check/index.ts +61 -0
  720. package/src/bucket-check/s3.ts +433 -0
  721. package/src/bucket-check/types.ts +75 -0
  722. package/src/bucket-check/wire.ts +50 -0
  723. package/src/bucket-check.ts +5 -0
  724. package/src/capabilities/templates.test.ts +2 -3
  725. package/src/capabilities/templates.ts +1 -2
  726. package/src/cdk/advise.test.ts +1 -1
  727. package/src/change-set-bundle.test.ts +0 -1
  728. package/src/change-set.ts +2 -3
  729. package/src/ci-agent.test.ts +348 -0
  730. package/src/ci-agent.ts +1025 -0
  731. package/src/ci-audit/__fixtures__/cloudtrail-lookup-bucket.json +37 -0
  732. package/src/ci-audit/__fixtures__/cloudtrail-writes-window.json +59 -0
  733. package/src/ci-audit/attribution.ts +260 -0
  734. package/src/ci-audit/audit-log.ts +220 -0
  735. package/src/ci-audit/ci-audit.test.ts +175 -0
  736. package/src/ci-audit/index.ts +15 -0
  737. package/src/ci-audit/unrecorded.ts +140 -0
  738. package/src/ci-audit.ts +2 -0
  739. package/src/ci-control.ts +173 -0
  740. package/src/ci-estate/delivery.ts +433 -0
  741. package/src/ci-estate/overdue.ts +81 -0
  742. package/src/ci-estate/page.ts +343 -0
  743. package/src/ci-estate/rows.ts +251 -0
  744. package/src/ci-estate.test.ts +281 -0
  745. package/src/ci-estate.ts +175 -0
  746. package/src/ci-handover.ts +67 -16
  747. package/src/ci-identity-database.test.ts +54 -0
  748. package/src/ci-identity-pulumi.test.ts +163 -0
  749. package/src/ci-identity-targets.test.ts +3 -1
  750. package/src/ci-identity.ts +123 -22
  751. package/src/ci-job-guard.test.ts +154 -0
  752. package/src/ci-job-guard.ts +319 -0
  753. package/src/ci-jobs.ts +8 -0
  754. package/src/ci-product-comment-targets.test.ts +45 -0
  755. package/src/ci-product-words.test.ts +101 -0
  756. package/src/ci-product-words.ts +565 -0
  757. package/src/ci-product.ts +226 -0
  758. package/src/ci-respond-run.ts +291 -0
  759. package/src/ci-respond.test.ts +264 -0
  760. package/src/ci-respond.ts +412 -0
  761. package/src/ci-shared-reads.test.ts +145 -0
  762. package/src/cli/commands/audit.test.ts +1 -1
  763. package/src/cli/commands/audit.ts +3 -2
  764. package/src/cli/commands/carve.test.ts +1 -1
  765. package/src/cli/commands/carve.ts +2 -2
  766. package/src/cli/commands/init.ts +3 -1
  767. package/src/cli/component-wave-args.test.ts +16 -0
  768. package/src/cli/handlers/agent.ts +126 -0
  769. package/src/cli/handlers/approve-confirm.test.ts +276 -0
  770. package/src/cli/handlers/approve-confirm.ts +200 -0
  771. package/src/cli/handlers/approve.ts +18 -1
  772. package/src/cli/handlers/audit-log.ts +74 -0
  773. package/src/cli/handlers/build-pr-loop-flags.test.ts +98 -0
  774. package/src/cli/handlers/build.test.ts +7 -0
  775. package/src/cli/handlers/build.ts +113 -1
  776. package/src/cli/handlers/ci-check-job.test.ts +114 -0
  777. package/src/cli/handlers/ci-check-job.ts +33 -0
  778. package/src/cli/handlers/ci-check.ts +63 -0
  779. package/src/cli/handlers/ci-forge-check.ts +91 -0
  780. package/src/cli/handlers/e2e-safe-run.ts +27 -0
  781. package/src/cli/handlers/fan-out.test.ts +10 -10
  782. package/src/cli/handlers/fan-out.ts +5 -0
  783. package/src/cli/handlers/gate-pending.ts +46 -0
  784. package/src/cli/handlers/init.ts +1 -0
  785. package/src/cli/handlers/ledger.ts +1 -1
  786. package/src/cli/handlers/lifecycle-drift.ts +7 -2
  787. package/src/cli/handlers/lock.test.ts +29 -2
  788. package/src/cli/handlers/lock.ts +66 -6
  789. package/src/cli/handlers/notify-relay.ts +130 -0
  790. package/src/cli/handlers/pr-before-merge.test.ts +2 -1
  791. package/src/cli/handlers/pr-deploy-inputs.test.ts +7 -7
  792. package/src/cli/handlers/pr-env.ts +48 -11
  793. package/src/cli/handlers/pr-plan-comment-targets.test.ts +166 -0
  794. package/src/cli/handlers/pr-plan-flags.test.ts +161 -0
  795. package/src/cli/handlers/pr-plan-targets.test.ts +155 -0
  796. package/src/cli/handlers/pr-waves-blocked.test.ts +5 -0
  797. package/src/cli/handlers/pr-waves.test.ts +8 -2
  798. package/src/cli/handlers/pr.test.ts +8 -8
  799. package/src/cli/handlers/pr.ts +879 -205
  800. package/src/cli/handlers/promote.test.ts +5 -5
  801. package/src/cli/handlers/promote.ts +22 -2
  802. package/src/cli/handlers/release.ts +2 -0
  803. package/src/cli/handlers/run-components-exit.test.ts +7 -7
  804. package/src/cli/handlers/run-wave.ts +144 -2
  805. package/src/cli/handlers/run.test.ts +6 -4
  806. package/src/cli/handlers/run.ts +86 -1
  807. package/src/cli/handlers/serve.ts +10 -1
  808. package/src/cli/main.test.ts +1 -1
  809. package/src/cli/main.ts +180 -13
  810. package/src/cli/mcp/ledger-tools.ts +126 -0
  811. package/src/cli/mcp/product-tools.test.ts +123 -0
  812. package/src/cli/mcp/product-tools.ts +129 -0
  813. package/src/cli/mcp/read-only.test.ts +134 -0
  814. package/src/cli/mcp/read-only.ts +68 -0
  815. package/src/cli/mcp/report-tools.ts +135 -0
  816. package/src/cli/mcp/server.test.ts +5 -4
  817. package/src/cli/mcp/server.ts +90 -16
  818. package/src/cli/mcp-config.ts +8 -3
  819. package/src/cli/parse-args.ts +119 -2
  820. package/src/cli/registry.ts +73 -0
  821. package/src/cloud-lister/sigv4.ts +80 -23
  822. package/src/components/adoption.test.ts +140 -0
  823. package/src/components/adoption.ts +140 -0
  824. package/src/components/apply-lease.ts +49 -0
  825. package/src/components/capability.ts +180 -6
  826. package/src/components/check-hooks.test.ts +66 -0
  827. package/src/components/check-hooks.ts +255 -0
  828. package/src/components/check-steps.test.ts +70 -0
  829. package/src/components/check-steps.ts +158 -0
  830. package/src/components/ci-services.test.ts +51 -0
  831. package/src/components/ci-services.ts +82 -0
  832. package/src/components/cli-support.ts +23 -2
  833. package/src/components/driver.test.ts +3 -3
  834. package/src/components/driver.ts +73 -6
  835. package/src/components/fan-out-run.ts +68 -18
  836. package/src/components/groups.ts +21 -4
  837. package/src/components/plan-flags.test.ts +46 -0
  838. package/src/components/pr-comment-preview-targets.test.ts +34 -0
  839. package/src/components/pr-comment-preview.test.ts +54 -0
  840. package/src/components/pr-env-ledger.test.ts +9 -0
  841. package/src/components/pr-env-ledger.ts +42 -0
  842. package/src/components/pr-env-ports.ts +29 -4
  843. package/src/components/pr-env-run-bundle.test.ts +2 -14
  844. package/src/components/pr-env-run.test.ts +19 -0
  845. package/src/components/pr-env-run.ts +12 -2
  846. package/src/components/pr-environment.test.ts +29 -0
  847. package/src/components/pr-environment.ts +40 -8
  848. package/src/components/pr-pipeline-runners.test.ts +80 -0
  849. package/src/components/pr-pipeline.test.ts +15 -0
  850. package/src/components/pr-pipeline.ts +498 -18
  851. package/src/components/pr-policy.ts +45 -7
  852. package/src/components/pr-run.test.ts +1 -1
  853. package/src/components/pr-run.ts +138 -11
  854. package/src/components/pr-stale-job.test.ts +34 -0
  855. package/src/components/pr-targets.test.ts +35 -0
  856. package/src/components/pr-targets.ts +45 -0
  857. package/src/components/product-pipeline.test.ts +200 -0
  858. package/src/components/product-pipeline.ts +383 -0
  859. package/src/components/promote.ts +10 -1
  860. package/src/components/release-compile.ts +87 -1
  861. package/src/components/release-promote.ts +65 -1
  862. package/src/components/repo-lock.ts +52 -0
  863. package/src/components/row-lease.test.ts +490 -0
  864. package/src/components/row-lease.ts +167 -0
  865. package/src/components/wave-plan-policy.test.ts +19 -0
  866. package/src/components/wave-plan.ts +96 -6
  867. package/src/control/__fixtures__/consumers/apps/consumers.json +15 -0
  868. package/src/control/__fixtures__/consumers/infra/consumers.json +23 -0
  869. package/src/control/applied.test.ts +148 -0
  870. package/src/control/applied.ts +191 -0
  871. package/src/control/consumers.test.ts +129 -0
  872. package/src/control/consumers.ts +192 -0
  873. package/src/control/control.test.ts +302 -0
  874. package/src/control/dispatch.ts +699 -0
  875. package/src/control/edges.test.ts +112 -0
  876. package/src/control/edges.ts +164 -0
  877. package/src/control/note-checkout.test.ts +91 -0
  878. package/src/control/reconcile.ts +250 -0
  879. package/src/control/records.ts +395 -0
  880. package/src/discovery/sandbox/bundle.ts +25 -1
  881. package/src/e2e-harness/__project__/chant.config.ts +4 -0
  882. package/src/e2e-harness/__project__/src/compose.ts +33 -0
  883. package/src/e2e-harness/bucket.ts +69 -0
  884. package/src/e2e-harness/claim.test.ts +150 -0
  885. package/src/e2e-harness/claim.ts +140 -0
  886. package/src/e2e-harness/driver.test.ts +304 -0
  887. package/src/e2e-harness/driver.ts +294 -0
  888. package/src/e2e-harness/forgejo.ts +267 -0
  889. package/src/e2e-harness/git.ts +96 -0
  890. package/src/e2e-harness/index.ts +50 -0
  891. package/src/e2e-harness/jobs.ts +35 -0
  892. package/src/e2e-harness/pins.ts +52 -0
  893. package/src/e2e-harness/ports.ts +130 -0
  894. package/src/e2e-harness/reports.ts +79 -0
  895. package/src/e2e-harness/safe-run-cli.test.ts +102 -0
  896. package/src/e2e-harness/safe-run-cli.ts +54 -0
  897. package/src/e2e-harness/safe-run.ts +198 -0
  898. package/src/e2e-harness/scenario.ts +89 -0
  899. package/src/e2e-harness/schemas/README.md +62 -0
  900. package/src/e2e-harness/schemas/demo-cycle.schema.json +282 -0
  901. package/src/e2e-harness/schemas/demo-step.schema.json +245 -0
  902. package/src/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
  903. package/src/e2e-harness/schemas/e2e-claims.schema.json +18 -0
  904. package/src/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
  905. package/src/e2e-harness/schemas/index.ts +220 -0
  906. package/src/e2e-harness/schemas.test.ts +145 -0
  907. package/src/e2e-harness/stack.test.ts +124 -0
  908. package/src/e2e-harness/stack.ts +306 -0
  909. package/src/e2e-harness/steps.ts +30 -0
  910. package/src/e2e-harness.ts +2 -0
  911. package/src/engine-facts.test.ts +2 -3
  912. package/src/engine-facts.ts +1 -2
  913. package/src/exit-codes.test.ts +32 -0
  914. package/src/exit-codes.ts +61 -0
  915. package/src/forge-check/check.ts +155 -0
  916. package/src/forge-check/contract.ts +215 -0
  917. package/src/forge-check/forge-check.test.ts +427 -0
  918. package/src/forge-check/forge.ts +318 -0
  919. package/src/forge-check/index.ts +43 -0
  920. package/src/forge-check/pulumi.ts +192 -0
  921. package/src/forge-check/read-only.ts +56 -0
  922. package/src/forge-check/trust.ts +527 -0
  923. package/src/forge-check/types.ts +78 -0
  924. package/src/forge-check.ts +5 -0
  925. package/src/gate-decision-bundle.test.ts +11 -0
  926. package/src/gate-decision.ts +3 -0
  927. package/src/gate-policy.ts +92 -3
  928. package/src/gated-waves-bundle.test.ts +0 -1
  929. package/src/index.ts +2 -0
  930. package/src/lexicon.ts +143 -6
  931. package/src/lifecycle/adoption-file.ts +1 -2
  932. package/src/lifecycle/cloud-index.test.ts +2 -3
  933. package/src/lifecycle/cloud-index.ts +1 -2
  934. package/src/lifecycle/control-entries-ledger.test.ts +69 -0
  935. package/src/lifecycle/gate-applied.ts +6 -0
  936. package/src/lifecycle/gate-ledger.ts +35 -1
  937. package/src/lifecycle/gate-pending-by-plan.test.ts +69 -0
  938. package/src/lifecycle/gate-pending-by-plan.ts +133 -0
  939. package/src/lifecycle/gated-request-digest.ts +49 -0
  940. package/src/lifecycle/gated-request-ledger.test.ts +53 -0
  941. package/src/lifecycle/gated-request.ts +279 -0
  942. package/src/lifecycle/identity-match.ts +25 -6
  943. package/src/lifecycle/index-diff.ts +1 -2
  944. package/src/lifecycle/index-document.ts +1 -2
  945. package/src/lifecycle/index-import.test.ts +14 -0
  946. package/src/lifecycle/index-import.ts +54 -34
  947. package/src/lifecycle/ledger-read.ts +7 -3
  948. package/src/lifecycle/lock-rows.test.ts +109 -0
  949. package/src/lifecycle/lock-rows.ts +167 -0
  950. package/src/lifecycle/publish-target-context.test.ts +108 -0
  951. package/src/lifecycle/query.test.ts +2 -3
  952. package/src/lifecycle/query.ts +109 -8
  953. package/src/lifecycle/release-catalog-site.test.ts +142 -0
  954. package/src/lifecycle/release-catalog-site.ts +291 -0
  955. package/src/lifecycle/release-catalog.test.ts +192 -0
  956. package/src/lifecycle/release-catalog.ts +353 -0
  957. package/src/lifecycle/release-changelog.test.ts +70 -0
  958. package/src/lifecycle/release-changelog.ts +71 -0
  959. package/src/lifecycle/release-cut.ts +2 -2
  960. package/src/lifecycle/release-ledger.ts +19 -0
  961. package/src/lifecycle/release-publish.ts +45 -22
  962. package/src/lifecycle/release-read.ts +2 -0
  963. package/src/lifecycle/release-status.test.ts +185 -0
  964. package/src/lifecycle/release-status.ts +175 -0
  965. package/src/lifecycle/resource-lock.test.ts +175 -0
  966. package/src/lifecycle/resource-lock.ts +354 -0
  967. package/src/lifecycle/retention.ts +2 -0
  968. package/src/lifecycle/run-ledger.ts +7 -1
  969. package/src/lifecycle/snapshot-store-s3.ts +9 -45
  970. package/src/lifecycle/snapshot-store.ts +1 -2
  971. package/src/lifecycle/target-lock.ts +24 -9
  972. package/src/lifecycle/wave-plans.ts +33 -5
  973. package/src/mcp/types.ts +7 -0
  974. package/src/notify-product.ts +76 -0
  975. package/src/notify-relay.test.ts +213 -0
  976. package/src/notify-relay.ts +407 -0
  977. package/src/notify.ts +95 -14
  978. package/src/object-store/azure-blob.ts +374 -0
  979. package/src/object-store/common.ts +133 -0
  980. package/src/object-store/errors.ts +26 -0
  981. package/src/object-store/from-env.ts +36 -0
  982. package/src/object-store/gcs.ts +436 -0
  983. package/src/object-store/index.ts +8 -0
  984. package/src/object-store/object-store.test.ts +130 -0
  985. package/src/object-store/s3.ts +350 -0
  986. package/src/op/activities/converge.ts +2 -1
  987. package/src/op/activities/index.ts +1 -1
  988. package/src/op/activities/review-agent.open.test.ts +78 -0
  989. package/src/op/activities/review-agent.test.ts +13 -0
  990. package/src/op/activities/review-agent.ts +89 -5
  991. package/src/op/approval-status.test.ts +134 -0
  992. package/src/op/approval-status.ts +235 -0
  993. package/src/op/gate-review.test.ts +2 -1
  994. package/src/op/gate.ts +81 -22
  995. package/src/op/generate-pipeline.ts +7 -1
  996. package/src/op/index.ts +23 -0
  997. package/src/op/op-waves-after-plan.test.ts +288 -0
  998. package/src/op/op-waves-after-plan.ts +238 -0
  999. package/src/op/op-waves-capability-spec.ts +133 -0
  1000. package/src/op/op-waves-capability.test.ts +217 -0
  1001. package/src/op/op-waves-capability.ts +370 -0
  1002. package/src/op/op-waves-events.ts +135 -0
  1003. package/src/op/op-waves-notify-words.test.ts +149 -0
  1004. package/src/op/op-waves-notify.ts +41 -16
  1005. package/src/op/op-waves-parallelism.test.ts +89 -0
  1006. package/src/op/op-waves-pull-request.test.ts +219 -0
  1007. package/src/op/op-waves-release-port.ts +64 -0
  1008. package/src/op/op-waves-release.test.ts +209 -0
  1009. package/src/op/op-waves-release.ts +132 -0
  1010. package/src/op/op-waves-run-record.test.ts +32 -0
  1011. package/src/op/op-waves-run.ts +1235 -52
  1012. package/src/op/op-waves-stand-down.test.ts +240 -0
  1013. package/src/op/op-waves-stand-down.ts +107 -0
  1014. package/src/op/op-waves-trace.test.ts +205 -0
  1015. package/src/op/op-waves.test.ts +112 -0
  1016. package/src/op/op-waves.ts +320 -22
  1017. package/src/op/runtime.ts +107 -0
  1018. package/src/op/stage-hooks-hold-record.test.ts +41 -0
  1019. package/src/op/stage-hooks.ts +91 -12
  1020. package/src/op/steward-beside.ts +2 -1
  1021. package/src/op/types.ts +3 -2
  1022. package/src/otlp-metrics.ts +96 -0
  1023. package/src/otlp.test.ts +243 -0
  1024. package/src/otlp.ts +543 -0
  1025. package/src/override-gate-bundle.test.ts +2 -0
  1026. package/src/override-gate.ts +4 -0
  1027. package/src/parallelism.test.ts +38 -0
  1028. package/src/parallelism.ts +33 -0
  1029. package/src/policy-packs.ts +230 -0
  1030. package/src/policy-source.test.ts +256 -0
  1031. package/src/policy-source.ts +111 -0
  1032. package/src/pr-forge-bundle.test.ts +1 -1
  1033. package/src/pr-forge.ts +175 -33
  1034. package/src/pr-loop-bundle.test.ts +7 -3
  1035. package/src/pr-loop-narrowed.test.ts +63 -0
  1036. package/src/pr-loop-words.test.ts +155 -0
  1037. package/src/pr-loop.ts +398 -52
  1038. package/src/pr-merge.test.ts +100 -0
  1039. package/src/pr-merge.ts +105 -0
  1040. package/src/pr-post-stale.test.ts +163 -0
  1041. package/src/pr-post.ts +190 -5
  1042. package/src/pr-report-url.ts +61 -6
  1043. package/src/pr-requires.test.ts +37 -1
  1044. package/src/pr-requires.ts +16 -2
  1045. package/src/product-subpaths-plain-node.e2e.test.ts +212 -0
  1046. package/src/release-floors.ts +1 -1
  1047. package/src/run-event.ts +28 -1
  1048. package/src/scheduled-op-cloud.ts +68 -0
  1049. package/src/sorted-json.ts +17 -0
  1050. package/src/stage-hooks-bundle.test.ts +6 -0
  1051. package/src/terraform/credentials.test.ts +77 -0
  1052. package/src/terraform/credentials.ts +162 -0
  1053. package/src/utils.ts +2 -11
  1054. package/src/wave-loop-golden.test.ts +2 -1
  1055. package/src/wave-runtime.ts +2 -2
  1056. package/src/workspace/chant-migrations/chud-lexicon-exit.ts +4 -1
  1057. package/src/workspace/ci-lock-grain.test.ts +31 -0
  1058. package/src/workspace/ci-lock-grain.ts +29 -0
  1059. package/src/workspace/ci-report-url.test.ts +1 -1
  1060. package/src/workspace/ci-run.test.ts +1 -1
  1061. package/src/workspace/ci-run.ts +10 -3
  1062. package/src/workspace/declaration.schema.json +27 -3
  1063. package/src/workspace/declaration.test.ts +1 -1
  1064. package/src/workspace/declaration.ts +26 -10
  1065. package/src/workspace/drift-cli.ts +8 -3
  1066. package/src/workspace/exit-cli.ts +2 -1
  1067. package/src/workspace/import-fetch.ts +4 -2
  1068. package/src/workspace/import-init.ts +4 -2
  1069. package/src/workspace/ledger.schema.json +7 -3
  1070. package/src/workspace/lineage-upgrade-cli.ts +2 -1
  1071. package/src/workspace/pr-report.schema.json +79 -3
  1072. package/src/workspace/promote.ts +2 -1
  1073. package/src/workspace/records-cli.ts +3 -2
  1074. package/src/workspace/release-catalog.schema.json +277 -0
  1075. package/src/workspace/run-event.schema.json +18 -1
  1076. package/src/workspace/work-cli.ts +8 -2
  1077. package/src/workspace/workspace-run.ts +2 -1
@@ -65,8 +65,10 @@
65
65
  */
66
66
 
67
67
  import { spawnSync } from "node:child_process";
68
- import { mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
69
- import { join, relative, resolve, sep } from "node:path";
68
+ import { CHANT_EXIT } from "../../exit-codes";
69
+ import { anyResourceGrain, leaseRowsOf as leaseRowsOfLocks, lockTargetsOf, type LockGrain } from "../../lifecycle/lock-rows";
70
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
71
+ import { dirname, join, relative, resolve, sep } from "node:path";
70
72
  import { loadChantConfig, resolveAutoReleaseDisabled, type ChantConfig } from "../../config";
71
73
  import { resolveCommit, resolveMergeBase } from "../../components/changed-files";
72
74
  import { deriveFanOut, fanOutRegistry } from "../../components/fan-out-support";
@@ -82,15 +84,14 @@ import {
82
84
  readOnlyLedger,
83
85
  prWavePlan,
84
86
  resumePrSet,
85
- waveNotCovered,
86
87
  type PrPlanSet,
87
88
  } from "../../components/pr-run";
88
89
  import { composeChangeSet, verifyChangeSetDigest } from "../../change-set";
89
- import { waveGateName } from "../../gated-waves";
90
90
  import { blockedMembers, blockedWords, settleEarlierWaves, type WaveMemberOutcome } from "../../wave-blocked";
91
91
  import { readFanOutAttempt, writeFanOutAttempt, type FanOutAttempt, type PrApplyRecord } from "../../components/fan-out-record";
92
92
  import { componentInputDigests, progressThatCarries } from "../../components/fan-out-inputs";
93
- import { samePlanDigest } from "../../lifecycle/plan-digest";
93
+ import { computePlanDigest, samePlanDigest } from "../../lifecycle/plan-digest";
94
+ import type { GateResolutionRecord } from "../../lifecycle/gate-ledger";
94
95
  import { evaluateGate, gateIsSealed, gitGateLedgerPort, type GateCheck, type GateLedgerPort } from "../../op/gate";
95
96
  import type { OtherGateHold } from "../../op/stage-hooks";
96
97
  import { emitGateStep, gateEventsOf, GATE_PHASE, type RunEventSink, type RunEventStream } from "../../run-event-stream";
@@ -101,6 +102,7 @@ import {
101
102
  describePlanChanged,
102
103
  PR_APPLY_GATE,
103
104
  prApproveCommand,
105
+ prApproveCommands,
104
106
  prNoteMarker,
105
107
  prOp,
106
108
  prStatusDescription,
@@ -110,6 +112,7 @@ import {
110
112
  type PrApproval,
111
113
  type PrBeforeMerge,
112
114
  type PrMember,
115
+ type PrMemberDetail,
113
116
  type PrPolicyReport,
114
117
  type PrReport,
115
118
  type PrWave,
@@ -118,6 +121,8 @@ import {
118
121
  } from "../../pr-loop";
119
122
  import { FORGE_KINDS, forgeFromEnv, forgePrincipalOf, type ForgeKind, type PrForge } from "../../pr-forge";
120
123
  import { GITHUB_COMMENT_LIMIT, GITLAB_NOTE_LIMIT } from "../../plan-summary";
124
+ import { upsertPlanNote } from "../../pr-post";
125
+ import { activeProductWords, commandWord, parseProductComment, productContext } from "../../ci-product-words";
121
126
  import { resolveCliBuildParams, parseParamFlags } from "../build-params-cli";
122
127
  import { formatError, formatInfo, formatSuccess, formatWarning } from "../format";
123
128
  import { reportUninstalledDependencies } from "../dependencies";
@@ -127,10 +132,13 @@ import { coverByMerges, greenOp, type GreenTarget } from "../../components/green
127
132
  import { GATED_EXIT_CODE, autoReleaseRun, recordAutoReleasesForRun } from "./run";
128
133
  import { appliedDigestOf } from "../../components/auto-release";
129
134
  import type { CommandContext } from "../registry";
135
+ import { parseArgs } from "../parse-args";
130
136
  import { withComponentEndpoint } from "../component-endpoint";
131
137
  import type { ComponentChangeSignal, FanOutPlan } from "../../components/fan-out";
132
- import { failedRunExitCode, type DriverComponent } from "../../components/driver";
133
- import type { CapabilityRegistry } from "../../components/capability";
138
+ import { assertPlanFlagsAccepted, assertTargetsAccepted, failedRunExitCode, type DriverComponent } from "../../components/driver";
139
+ import { PLAN_FLAG_ARGS, PlanFlagRefusedError, TargetsRefusedError, type CapabilityRegistry } from "../../components/capability";
140
+ import { prPlanTargets } from "../../components/pr-targets";
141
+ import { PREVIEW_COMMENT_ENV } from "../../components/pr-pipeline";
134
142
  import type { ComponentEnvironmentDeclaration } from "../../components/component";
135
143
  import { prLoopHooksAt, runPrHooks, type PrHoldSettled, type PrHookPlace, type PrLoopHooks } from "../../components/pr-hooks";
136
144
  import { decidePrPolicyOverride, policyReviewOf, prLoopPolicyAt, prPolicyReport, runPrPolicy, spendPrPolicyOverride, type PrLoopPolicy } from "../../components/pr-policy";
@@ -172,6 +180,13 @@ export interface Prepared {
172
180
  hookFailed?: string;
173
181
  /** Where the stage's hooks run, once its op is known. */
174
182
  hookPlace?: PrHookPlace;
183
+ /** `pr-plan --target` (#4620): the addresses each planned member's capability plan narrows to. */
184
+ targets?: Record<string, string[]>;
185
+ /** `pr-plan --parallelism <n>` (#4625): how many members of a wave plan at once. */
186
+ parallelism?: number;
187
+ /** `pr-plan --refresh` and `--target-dependents` (#4627). */
188
+ refresh?: boolean;
189
+ targetDependents?: boolean;
175
190
  /**
176
191
  * Set when `ci.branches` or `ci.labels` (#4292) leave the member out of this
177
192
  * stage: why. The plan is then empty, so the stage reports `nothing`.
@@ -211,6 +226,14 @@ export async function prepare(ctx: CommandContext, stage: "plan" | "apply" | "re
211
226
  );
212
227
  }
213
228
  if (args.fromAffected) return fail(`pr-${stage} derives the change itself; drop --from-affected`);
229
+ // #4620: a target narrows the preview; an apply or a record covers what the approved plan covers.
230
+ if (stage !== "plan" && args.targets && args.targets.length > 0) {
231
+ 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.");
232
+ }
233
+ // #4627: refresh and target dependents change what the preview plans, as a target does.
234
+ if (stage !== "plan" && (args.refresh || args.targetDependents)) {
235
+ return fail(`pr-${stage} applies or records what the pull request's approved plan covers, so it takes no ${args.refresh ? "--refresh" : "--target-dependents"}`, "Plan with pr-plan --refresh or --target-dependents, and approve that plan.");
236
+ }
214
237
  let member: string | undefined;
215
238
  if (args.members?.length) {
216
239
  const checked = await checkMember(projectPath, args.members);
@@ -476,17 +499,143 @@ export function planAll(p: Prepared, onRunEvent?: RunEventSink): Promise<PrPlanS
476
499
  return hookedPlan(p, p.plan.order, () => planBare(p, onRunEvent));
477
500
  }
478
501
 
479
- export function planBare(p: Prepared, onRunEvent?: RunEventSink): Promise<PrPlanSet> {
502
+ export async function planBare(p: Prepared, onRunEvent?: RunEventSink): Promise<PrPlanSet> {
503
+ const lockGrain = await declaredLockGrainOf(p);
480
504
  return planPrSet({
481
505
  components: p.components,
482
506
  plan: p.plan,
483
507
  registry: p.registry,
484
508
  env: p.env,
485
509
  seededOutputs: p.seededOutputs,
510
+ ...(lockGrain ? { lockGrain } : {}),
511
+ // #4613: a step's own policy engine (CrossGuard) reads its packs at the base, as ci.policy is.
512
+ policyBase: p.base,
486
513
  ...(onRunEvent ? { onRunEvent } : {}),
514
+ ...(p.targets ? { targets: p.targets } : {}),
515
+ ...(p.parallelism !== undefined ? { parallelism: p.parallelism } : {}),
516
+ ...(p.refresh ? { refresh: true } : {}),
517
+ ...(p.targetDependents ? { targetDependents: true } : {}),
487
518
  });
488
519
  }
489
520
 
521
+ /**
522
+ * `pr-plan --refresh` and `--target-dependents` (#4627), from the line or
523
+ * the preview comment: set on `p`, or the exit code when a planned member's
524
+ * capability cannot honour one, named before anything plans, as
525
+ * {@link narrowToTargets} does for targets. `--target-dependents` needs a
526
+ * target.
527
+ */
528
+ function planWithFlags(p: Prepared, flags: { refresh?: boolean; targetDependents?: boolean }): number | undefined {
529
+ if (!flags.refresh && !flags.targetDependents) return undefined;
530
+ if (flags.targetDependents && !p.targets) return fail("--target-dependents widens a --target to what depends on it, and nothing was narrowed", "Give --target <address> with it.");
531
+ const byName = new Map(p.components.map((c) => [c.name, c]));
532
+ for (const name of p.plan.order) {
533
+ const component = byName.get(name);
534
+ if (!component) continue;
535
+ try {
536
+ assertPlanFlagsAccepted(component, p.registry, { ...(flags.refresh ? { refresh: true } : {}), ...(flags.targetDependents && p.targets?.[name] ? { targetDependents: true } : {}) });
537
+ } catch (err) {
538
+ if (err instanceof PlanFlagRefusedError) return fail(`${err.message}, so nothing was planned`, `Drop ${PLAN_FLAG_ARGS[err.flag]}, or plan only members whose steps take it.`);
539
+ throw err;
540
+ }
541
+ }
542
+ if (flags.refresh) p.refresh = true;
543
+ if (flags.targetDependents) p.targetDependents = true;
544
+ console.error(formatInfo(`planning with ${[flags.refresh ? "--refresh" : "", flags.targetDependents ? "--target-dependents" : ""].filter(Boolean).join(" and ")}`));
545
+ return undefined;
546
+ }
547
+
548
+ /**
549
+ * `pr-plan --comment-targets` (#4626): the `--target` addresses of the
550
+ * preview comment in {@link PREVIEW_COMMENT_ENV}, read with the product's
551
+ * grammar, or the exit code when the comment is refused. No comment, or one
552
+ * with no target: none. The checks `--target` makes follow in
553
+ * {@link narrowToTargets}.
554
+ */
555
+ function commentTargets(env: NodeJS.ProcessEnv = process.env): { targets: string[]; refresh?: true; targetDependents?: true } | number {
556
+ const body = env[PREVIEW_COMMENT_ENV];
557
+ if (body === undefined || body.trim() === "") return { targets: [] };
558
+ const words = activeProductWords();
559
+ const parsed = parseProductComment(words, body, env);
560
+ if (parsed === undefined) return { targets: [] };
561
+ if (parsed.kind === "refused") return fail(`the preview comment is refused: ${parsed.reason}, so nothing was planned`, `/${words.product} ${commandWord(words, "plan") ?? "plan"} --target <address> narrows the preview to the address.`);
562
+ if (parsed.kind !== "plan") return { targets: [] };
563
+ // #4627: the comment's --refresh and --target-dependents too.
564
+ return { targets: parsed.targets ?? [], ...(parsed.refresh ? { refresh: true as const } : {}), ...(parsed.targetDependents ? { targetDependents: true as const } : {}) };
565
+ }
566
+
567
+ /**
568
+ * `pr-plan --target` (#4620): the addresses by member, set on `p`, or the
569
+ * exit code when a value is refused or a targeted member has a capability
570
+ * that cannot narrow, which is named before anything plans.
571
+ */
572
+ function narrowToTargets(p: Prepared, values: readonly string[] | undefined): number | undefined {
573
+ if (!values || values.length === 0) return undefined;
574
+ const resolved = prPlanTargets(values, p.plan.order, new Set(p.components.map((c) => c.name)));
575
+ if ("error" in resolved) return fail(resolved.error, "--target <address> narrows every member the pull request plans; --target <member>:<address> narrows one.");
576
+ const { targets } = resolved;
577
+ const byName = new Map(p.components.map((c) => [c.name, c]));
578
+ for (const [name, addresses] of Object.entries(targets)) {
579
+ try {
580
+ assertTargetsAccepted(byName.get(name)!, p.registry, { targets: addresses });
581
+ } catch (err) {
582
+ if (err instanceof TargetsRefusedError) return fail(`${err.message}, so nothing was planned`, "Drop --target, or name a member whose steps can narrow: --target <member>:<address>.");
583
+ throw err;
584
+ }
585
+ }
586
+ p.targets = targets;
587
+ console.error(formatInfo(`narrowed to ${Object.entries(targets).map(([name, a]) => `${name}: ${a.join(", ")}`).join("; ") || "nothing planned"}`));
588
+ return undefined;
589
+ }
590
+
591
+ /**
592
+ * `ci.lockGrain` of the stage's member (#4552), read from the declaration at
593
+ * base like `ci.locks`, so a change cannot pick its own grain. Undefined when
594
+ * none is declared: each member then takes its lexicon's default.
595
+ */
596
+ async function declaredLockGrainOf(p: Pick<Prepared, "base" | "member">): Promise<LockGrain | undefined> {
597
+ const { ciLockGrainAt } = await import("../../workspace/ci-lock-grain");
598
+ return ciLockGrainAt(process.cwd(), p.base, p.member) ?? undefined;
599
+ }
600
+
601
+ /**
602
+ * Lease the rows a set's members on the resource grain change (#4552),
603
+ * before anything applies: the refusal naming the run that holds one, the
604
+ * exit code when the rows file could not be written, or the lease to let go
605
+ * of once the apply ends (one that holds nothing when no member is on the
606
+ * resource grain).
607
+ */
608
+ async function leaseSetRows(p: Prepared, set: Pick<PrPlanSet, "locks">): Promise<{ release(): Promise<boolean> } | { held: string } | number> {
609
+ const leased = await leaseRowsOf(p, set);
610
+ return "failed" in leased ? fail(leased.failed) : leased;
611
+ }
612
+
613
+ /**
614
+ * {@link leaseSetRows} without printing a failure (#4594), for a later round
615
+ * of `applyPrSet` (`leaseRound`), which records it on the round, and for a
616
+ * pull request environment's apply, which reports it.
617
+ */
618
+ export async function leaseRowsOf(p: Pick<Prepared, "gate">, set: Pick<PrPlanSet, "locks">, label = "this apply"): Promise<{ release(): Promise<boolean> } | { held: string } | { failed: string }> {
619
+ const rows = leaseRowsOfLocks(set.locks);
620
+ if (rows.length === 0) return { release: () => Promise.resolve(true) };
621
+ const { leaseLockRows } = await import("../../lifecycle/resource-lock");
622
+ let leased;
623
+ try {
624
+ leased = await leaseLockRows(p.gate, rows);
625
+ } catch (err) {
626
+ 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)}` };
627
+ }
628
+ if (!leased.ok) return { held: `${leased.message}, so nothing of ${label} was applied. Apply again once that run ends; a run that is gone, or whose lease is older than CHANT_LOCK_STALE seconds, is taken over.` };
629
+ for (const h of leased.tookOver) console.error(formatInfo(`took over the rows of run ${h.run}, which is gone`));
630
+ console.error(formatInfo(`${label} holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${p.gate} while it applies`));
631
+ return leased.lease;
632
+ }
633
+
634
+ /** `applyPrSet`'s `leaseRound` (#4594): a round after the first leases the rows its own plan locks. */
635
+ export function leaseRoundRows(p: Pick<Prepared, "gate">): NonNullable<Parameters<typeof applyPrSet>[0]["leaseRound"]> {
636
+ return ({ round, set }) => leaseRowsOf(p, set, `round ${round}`);
637
+ }
638
+
490
639
  /**
491
640
  * How a stage's report settles its run's events (#4041): a refusal waits on
492
641
  * a person, as a gate does, and exits the same way.
@@ -540,7 +689,7 @@ async function publish(forge: PrForge | undefined, report: PrReport, note: strin
540
689
  // member would put a line on every pull request for each member it skips.
541
690
  if (report.member && report.status === "nothing" && !report.overdue?.length && !report.migrations?.length) return;
542
691
  try {
543
- await forge.upsertNote(report.pr, prNoteMarker(report.env, report.member), note);
692
+ await upsertPlanNote(forge, report.pr, prNoteMarker(report.env, report.member), note);
544
693
  } catch (err) {
545
694
  console.error(formatWarning({ message: `could not post the note on #${report.pr}: ${err instanceof Error ? err.message : String(err)}` }));
546
695
  }
@@ -567,6 +716,14 @@ async function finish(ctx: CommandContext, p: Prepared, report: PrReport, upload
567
716
  if (p.routedAway && report.status === "nothing" && !report.message) report = { ...report, message: p.routedAway };
568
717
  if (p.policyReport) report = { ...report, policy: p.policyReport };
569
718
  if (p.beforeMerge) report = { ...report, beforeMerge: p.beforeMerge };
719
+ // #4617: with a checkout of the control repo named, its entries and apply records mark the cross-stack edges.
720
+ if (report.crossStackEdges?.length && process.env.CHANT_CONTROL_DIR) {
721
+ const { controlEdgeFactsFromEnv, remarkCrossStackEdges } = await import("../../control/edges");
722
+ report = remarkCrossStackEdges(report, await controlEdgeFactsFromEnv());
723
+ }
724
+ // #4573: each member's section its lexicon renders from its own part of the change set.
725
+ const details = await memberDetails(p, report);
726
+ if (details.length > 0) report = { ...report, details };
570
727
  const note = noteFor(report, p.forge);
571
728
  writeOutputs(ctx, report, note, upload);
572
729
  if (!ctx.args.noStatus) await publish(p.forge, report, note);
@@ -668,9 +825,9 @@ async function judgePolicy(p: Prepared, at: { stage: "plan" | "apply"; op: strin
668
825
  const why = err instanceof Error ? err.message : String(err);
669
826
  if (at.stage === "plan") {
670
827
  console.error(formatWarning({ message: `could not read the override ledger, so no override reads as standing: ${why}` }));
671
- return { held, stop: { refusal: "policy-denied", code: 1, message: `The policy denied this plan: ${denied}.` } };
828
+ return { held, stop: { refusal: "policy-denied", code: CHANT_EXIT.denied, message: `The policy denied this plan: ${denied}.` } };
672
829
  }
673
- return { held, stop: { refusal: "policy-denied", code: GATED_EXIT_CODE, message: `The policy denied this plan (${denied}), and the override ledger could not be read or written: ${why}. Nothing was applied.` } };
830
+ return { held, stop: { refusal: "policy-denied", code: CHANT_EXIT.denied, message: `The policy denied this plan (${denied}), and the override ledger could not be read or written: ${why}. Nothing was applied.` } };
674
831
  }
675
832
  if (decided.status === "overridden") {
676
833
  report.override = decided.override;
@@ -685,7 +842,7 @@ async function judgePolicy(p: Prepared, at: { stage: "plan" | "apply"; op: strin
685
842
  held,
686
843
  stop: {
687
844
  refusal: "policy-denied",
688
- code: at.stage === "plan" ? 1 : GATED_EXIT_CODE,
845
+ code: CHANT_EXIT.denied,
689
846
  message: `The policy denied this plan: ${denied}.${moved} Nothing was applied. ${who} override it: ${decided.command}`,
690
847
  },
691
848
  };
@@ -715,6 +872,14 @@ async function prPlan(ctx: CommandContext, stage: StageEvents): Promise<number>
715
872
  }
716
873
  const p = await prepare(ctx, "plan");
717
874
  if (typeof p === "number") return p;
875
+ // #4626: the preview comment's --target addresses, read from the comment the job carries in a variable.
876
+ const fromComment = ctx.args.commentTargets ? commentTargets() : { targets: [] };
877
+ if (typeof fromComment === "number") return fromComment;
878
+ const narrowed = narrowToTargets(p, [...(ctx.args.targets ?? []), ...fromComment.targets]);
879
+ if (narrowed !== undefined) return narrowed;
880
+ const flagged = planWithFlags(p, { refresh: ctx.args.refresh === true || fromComment.refresh === true, targetDependents: ctx.args.targetDependents === true || fromComment.targetDependents === true });
881
+ if (flagged !== undefined) return flagged;
882
+ if (ctx.args.parallelism !== undefined) p.parallelism = ctx.args.parallelism;
718
883
  const op = prOp(ctx.args.pr, p.member);
719
884
  placeHooks(ctx, p, "plan", op);
720
885
  const upload = openUpload(stage, "plan", ctx.args.pr, p);
@@ -766,10 +931,41 @@ async function prPlan(ctx: CommandContext, stage: StageEvents): Promise<number>
766
931
  printMembers(report);
767
932
  if (status === "planned") {
768
933
  console.error(formatInfo(`plan : ${report.digest}`));
769
- console.error(formatInfo(approval.status === "approved" ? `approved by ${(approval.approvedBy ?? []).join(", ")}` : `approve : ${prApproveCommand(report)}`));
934
+ console.error(formatInfo(approval.status === "approved" ? `approved by ${(approval.approvedBy ?? []).join(", ")}` : `approve : ${prApproveCommands(report).join("; ")}`));
770
935
  }
771
936
  if (judged.stop) console.error(formatWarning({ message: judged.stop.message }));
772
- return status === "plan-failed" || judged.stop ? 1 : 0;
937
+ // #4550: a capability's policy denial (pulumi-up's CrossGuard) exits as a denial, 7, not as a failed plan.
938
+ if (status === "plan-failed" && set.policyDenied) return CHANT_EXIT.denied;
939
+ return status === "plan-failed" ? CHANT_EXIT.failed : judged.stop ? judged.stop.code : CHANT_EXIT.done;
940
+ }
941
+
942
+ /**
943
+ * The member detail sections (#4573): each lexicon the project lists that
944
+ * renders one (`prNoteDetail`) gets each member's part of the change set. A
945
+ * lexicon that cannot load, or throws, leaves the note as it was.
946
+ */
947
+ async function memberDetails(p: Prepared, report: PrReport): Promise<PrMemberDetail[]> {
948
+ if (report.changeSet.members.length === 0) return [];
949
+ const { loadPlugin } = await import("../plugins");
950
+ const out: PrMemberDetail[] = [];
951
+ for (const name of lexiconNames(p.config.lexicons ?? [])) {
952
+ let plugin: Awaited<ReturnType<typeof loadPlugin>>;
953
+ try {
954
+ plugin = await loadPlugin(name);
955
+ } catch {
956
+ continue;
957
+ }
958
+ if (!plugin.prNoteDetail) continue;
959
+ for (const member of report.changeSet.members) {
960
+ try {
961
+ const detail = await plugin.prNoteDetail({ member: member.member, changeSet: report.changeSet, stage: report.stage });
962
+ if (detail && detail.lines.length > 0) out.push({ member: member.member, ...(detail.title ? { title: detail.title } : {}), lines: detail.lines });
963
+ } catch (err) {
964
+ console.error(formatWarning({ message: `the ${name} lexicon could not render ${member.member}'s detail: ${err instanceof Error ? err.message : String(err)}` }));
965
+ }
966
+ }
967
+ }
968
+ return out;
773
969
  }
774
970
 
775
971
  /**
@@ -817,12 +1013,16 @@ async function overdueOps(forge: PrForge | undefined, member: string | undefined
817
1013
  return overdueOpsAt({ forge, cwd: resolve("."), ...(member ? { member } : {}), log: (line) => console.error(formatWarning({ message: line })) });
818
1014
  }
819
1015
 
820
- /** chant components pr-apply --base <ref> [--pr <n>] [--env <env>] [--gate <name>] [--forge <kind>] [--require-review] [--output <dir>] [--json] [--events-json] [--report-url <url>] */
1016
+ /** chant components pr-apply --base <ref> [--pr <n>] [--env <env>] [--gate <name>] [--forge <kind>] [--require-review] [--before-merge [--requires <list>]] [--output <dir>] [--json] [--events-json] [--report-url <url>] */
821
1017
  export function runComponentsPrApply(ctx: CommandContext): Promise<number> {
822
1018
  if (refusesEventsWithJson(ctx.args, "the stage's report")) return Promise.resolve(1);
823
1019
  return withStageEvents("pr-apply", ctx, async (events) => {
824
1020
  // #4301: an apply before merge asks the forge its requires checks before any of the head's code loads, the config included.
825
1021
  let beforeMerge: PrBeforeMerge | undefined;
1022
+ if (ctx.args.requires && !ctx.args.beforeMerge) return fail("--requires names the checks of an apply before merge, so it needs --before-merge --pr <n>");
1023
+ // #4636: the merge after the update, checked before anything applies.
1024
+ const mergeProblem = await mergeArgsProblem(ctx.args);
1025
+ if (mergeProblem) return fail(mergeProblem);
826
1026
  if (ctx.args.beforeMerge) {
827
1027
  const checked = await beforeMergeChecks(ctx);
828
1028
  if (typeof checked === "number") return checked;
@@ -881,7 +1081,7 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
881
1081
  const set: PrPlanSet = { doc: composeChangeSet([]), members: [], plans: {}, outputs: {}, failed: false };
882
1082
  return stopper(ctx, p, events, upload)(
883
1083
  prReport({ stage: "apply", pr, env: p.env, ...(p.member ? { member: p.member } : {}), base: p.base, head: p.head, op, gate: p.gate, plan: p.plan, signal: p.signal, set, approval: { status: "pending" }, status: "refused", refusal: "locked", message: held }),
884
- GATED_EXIT_CODE,
1084
+ CHANT_EXIT.held,
885
1085
  );
886
1086
  }
887
1087
  }
@@ -941,12 +1141,22 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
941
1141
  ...base,
942
1142
  approval: { status: "pending" },
943
1143
  status: "plan-failed",
944
- message: "A member failed to plan, so there is no plan to compare with the approved one. Nothing was applied.",
1144
+ message: set.policyDenied
1145
+ ? "The policy denied a member's plan, so nothing was applied."
1146
+ : "A member failed to plan, so there is no plan to compare with the approved one. Nothing was applied.",
945
1147
  }),
946
- 1,
1148
+ set.policyDenied ? CHANT_EXIT.denied : 1,
947
1149
  );
948
1150
  }
949
1151
 
1152
+ // #4552, ruling D: on the resource grain a pull request's locks name row keys, which only the plan knows.
1153
+ const lockTargets = lockTargetsOf(p.plan.order, set.locks);
1154
+ if (locks && anyResourceGrain(set.locks)) {
1155
+ const held = await heldLocksOf(p, pr, lockTargets);
1156
+ if (typeof held === "number") return held;
1157
+ if (held) return stop(prReport({ ...base, approval: { status: "pending" }, status: "refused", refusal: "locked", message: held }), CHANT_EXIT.held);
1158
+ }
1159
+
950
1160
  // #4022: keep the change set the gate binds on chant/lifecycle under its
951
1161
  // digest before deciding the gate, so the plan an approval bound, or the
952
1162
  // one a pending fact waits on, can be read once this job is gone.
@@ -966,7 +1176,7 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
966
1176
  // #4323: the after-gate hooks hear the decision, a refusal too; only a failure that would have applied changes the outcome.
967
1177
  const afterGate = await runGateHook(p, { op, digest: set.doc.digest, satisfied: decided.satisfied }, p.plan.order);
968
1178
  if (afterGate && decided.satisfied) return stop(prReport({ ...base, approval, status: "failed", message: afterGate }), 1);
969
- if (!decided.satisfied) return stop(prReport({ ...base, approval, status: "refused", refusal: decided.refusal, message: decided.message }), GATED_EXIT_CODE);
1179
+ if (!decided.satisfied) return stop(prReport({ ...base, approval, status: "refused", refusal: decided.refusal, message: decided.message }), decided.refusal === "plan-changed" ? CHANT_EXIT.moved : CHANT_EXIT.waiting);
970
1180
  via = decided.via;
971
1181
  }
972
1182
 
@@ -981,10 +1191,14 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
981
1191
  if (unspent) return stop(prReport({ ...base, approval, status: "refused", refusal: "policy-denied", message: unspent }), 1);
982
1192
  // #4293, #4301: under ci.locks an apply before merge holds its targets until the pull request merges or closes.
983
1193
  if (locks && beforeMerge && pr !== null) {
984
- const taken = await takeApplyLocks(p, pr);
1194
+ const taken = await takeApplyLocks(p, pr, lockTargets);
985
1195
  if (typeof taken === "number") return taken;
986
- if (taken) return stop(prReport({ ...base, approval, status: "refused", refusal: "locked", message: taken }), GATED_EXIT_CODE);
1196
+ if (taken) return stop(prReport({ ...base, approval, status: "refused", refusal: "locked", message: taken }), CHANT_EXIT.held);
987
1197
  }
1198
+ // #4552: on the resource grain the apply leases the rows it changes, whatever ci.locks says, and lets go when it ends.
1199
+ const lease = await leaseSetRows(p, set);
1200
+ if (typeof lease === "number") return lease;
1201
+ if ("held" in lease) return stop(prReport({ ...base, approval, status: "refused", refusal: "locked", message: lease.held }), CHANT_EXIT.held);
988
1202
 
989
1203
  // The record is written before the first component runs and again as each
990
1204
  // one settles, so a run killed partway still knows what applied.
@@ -1021,7 +1235,10 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1021
1235
  // #4288: the before-apply hooks, once the gate and the review let the apply through.
1022
1236
  const toApply = (resumed?.plan ?? p.plan).order.filter((name) => !completedSoFar.has(name));
1023
1237
  const beforeFailed = await runStageHook(p, "before-apply", toApply);
1024
- if (beforeFailed) return stop(prReport({ ...base, approval, status: "failed", message: beforeFailed }), 1);
1238
+ if (beforeFailed) {
1239
+ await lease.release();
1240
+ return stop(prReport({ ...base, approval, status: "failed", message: beforeFailed }), 1);
1241
+ }
1025
1242
 
1026
1243
  // #3999: a round planned after an upstream applied waits on a gate of its
1027
1244
  // own, under the same identity.gates rule and the same review checks.
@@ -1047,37 +1264,47 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1047
1264
  return { satisfied: true, approval: roundApproval };
1048
1265
  };
1049
1266
 
1050
- const applied = await applyPrSet({
1051
- components: p.components,
1052
- plan: resumed?.plan ?? p.plan,
1053
- registry: p.registry,
1054
- env: p.env,
1055
- set,
1056
- gate: p.gate,
1057
- approval,
1058
- decideRound,
1059
- ...(resumed ? { resumed: prior } : {}),
1060
- // The apply is this run's waves, so the fan-out's own run framing is
1061
- // dropped. The log's lines go to stderr with or without --events-json.
1062
- onRunEvent: (body: RunEventBody) => {
1063
- events?.nested(body);
1064
- log(body);
1065
- },
1066
- ...(resumePath
1067
- ? {
1068
- onComponentSettled: (settled, outputs) => {
1069
- if (settled.status === "ok") {
1070
- completedSoFar.add(settled.component);
1071
- if (inputsNow[settled.component] !== undefined) inputsSoFar[settled.component] = inputsNow[settled.component]!;
1072
- if (outputs) outputsSoFar[settled.component] = outputs;
1073
- } else if (settled.status === "fail") {
1074
- failedSoFar.push(settled.component);
1075
- }
1076
- recordAttempt();
1077
- },
1078
- }
1079
- : {}),
1080
- });
1267
+ const lockGrain = await declaredLockGrainOf(p);
1268
+ let applied: Awaited<ReturnType<typeof applyPrSet>>;
1269
+ try {
1270
+ applied = await applyPrSet({
1271
+ components: p.components,
1272
+ plan: resumed?.plan ?? p.plan,
1273
+ registry: p.registry,
1274
+ env: p.env,
1275
+ set,
1276
+ ...(lockGrain ? { lockGrain } : {}),
1277
+ policyBase: p.base,
1278
+ gate: p.gate,
1279
+ approval,
1280
+ decideRound,
1281
+ // #4594: a later round's plan may change rows the first did not, so it leases its own.
1282
+ leaseRound: leaseRoundRows(p),
1283
+ ...(resumed ? { resumed: prior } : {}),
1284
+ // The apply is this run's waves, so the fan-out's own run framing is
1285
+ // dropped. The log's lines go to stderr with or without --events-json.
1286
+ onRunEvent: (body: RunEventBody) => {
1287
+ events?.nested(body);
1288
+ log(body);
1289
+ },
1290
+ ...(resumePath
1291
+ ? {
1292
+ onComponentSettled: (settled, outputs) => {
1293
+ if (settled.status === "ok") {
1294
+ completedSoFar.add(settled.component);
1295
+ if (inputsNow[settled.component] !== undefined) inputsSoFar[settled.component] = inputsNow[settled.component]!;
1296
+ if (outputs) outputsSoFar[settled.component] = outputs;
1297
+ } else if (settled.status === "fail") {
1298
+ failedSoFar.push(settled.component);
1299
+ }
1300
+ recordAttempt();
1301
+ },
1302
+ }
1303
+ : {}),
1304
+ });
1305
+ } finally {
1306
+ await lease.release();
1307
+ }
1081
1308
  recordAttempt();
1082
1309
  // #4288: the after-apply hooks, for the components that applied.
1083
1310
  const afterFailed = await runStageHook(p, "after-apply", toApply.filter((name) => applied.run.completed.includes(name)), undefined, "the apply counts as failed though its components applied");
@@ -1089,18 +1316,85 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1089
1316
  members: applied.members,
1090
1317
  ...(resumed ? { resumed: resumed.completed } : {}),
1091
1318
  ...(applied.rounds ? { rounds: applied.rounds } : {}),
1092
- ...(applied.status === "waiting" ? { message: waitingMessage(op, applied.rounds) } : {}),
1319
+ ...(applied.held ? { message: applied.held } : applied.leaseFailed ? { message: applied.leaseFailed } : applied.status === "waiting" ? { message: waitingMessage(op, applied.rounds) } : {}),
1093
1320
  });
1094
1321
  // A component that stopped at a gate of its own leaves the apply waiting on
1095
1322
  // a person. A step that refused its plan because the target moved since
1096
- // the approval exits 3, as a moved digest does before anything applies (#3997).
1097
- const exit = afterFailed ? 1 : applied.status === "applied" ? 0 : applied.status === "waiting" ? GATED_EXIT_CODE : failedRunExitCode(applied.run.results);
1323
+ // the approval exits 4 (moved), as a moved digest does before anything applies (#3997, #4553).
1324
+ // A later round whose rows another run holds exits 5 (held, #4594).
1325
+ const exit = afterFailed
1326
+ ? 1
1327
+ : applied.held
1328
+ ? CHANT_EXIT.held
1329
+ : applied.status === "applied"
1330
+ ? 0
1331
+ : applied.status === "waiting"
1332
+ ? GATED_EXIT_CODE
1333
+ : applied.leaseFailed
1334
+ ? 1
1335
+ : failedRunExitCode(applied.run.results);
1098
1336
  if (green && applied.status === "applied") await recordGreenApplied(p, green, set.doc.digest, approval, via);
1099
1337
  const code = await stop(report, exit, applied.run.status === "gated" ? "gated" : undefined);
1100
1338
  if (applied.status === "applied" && !afterFailed) console.error(formatSuccess(`applied the plan ${report.digest} approved by ${(approval.approvedBy ?? []).join(", ")}`));
1339
+ // #4636: an update before merge that applied every member merges the pull request, never the other way round.
1340
+ if (code === 0 && beforeMerge && pr !== null && args.merge === "auto" && applied.status === "applied" && !afterFailed) return mergeAfterUpdate(ctx, p, pr);
1101
1341
  return code;
1102
1342
  }
1103
1343
 
1344
+ /** `--merge`, `--merge-token-env` and `--merge-method` as one problem, or undefined when they hold together. */
1345
+ async function mergeArgsProblem(args: CommandContext["args"]): Promise<string | undefined> {
1346
+ const { PR_APPLY_MERGES, PR_MERGE_METHODS } = await import("../../pr-merge");
1347
+ if (args.merge === undefined) {
1348
+ if (args.mergeTokenEnv || args.mergeMethod) return "--merge-token-env and --merge-method go with --merge auto";
1349
+ return undefined;
1350
+ }
1351
+ if (!(PR_APPLY_MERGES as readonly string[]).includes(args.merge)) return `--merge takes ${PR_APPLY_MERGES.join(" or ")}, not ${args.merge}`;
1352
+ if (args.merge === "manual") return args.mergeTokenEnv || args.mergeMethod ? "--merge manual leaves the merge to a person, so it takes no --merge-token-env or --merge-method" : undefined;
1353
+ if (!args.beforeMerge) return "--merge auto merges a pull request once its update before merge applied, so it needs --before-merge --pr <n>";
1354
+ if (!args.mergeTokenEnv) return "--merge auto merges with a token of its own, never the job's: --merge-token-env <VAR> (on GitLab a protected variable)";
1355
+ if (args.mergeMethod && !(PR_MERGE_METHODS as readonly string[]).includes(args.mergeMethod)) return `--merge-method takes ${PR_MERGE_METHODS.join(", ")}, not ${args.mergeMethod}`;
1356
+ return undefined;
1357
+ }
1358
+
1359
+ /**
1360
+ * The merge after an update before merge applied (#4636): the apply's
1361
+ * records pushed to the ledger, the head checked again, then the forge's
1362
+ * merge with the token `--merge-token-env` names alone. A refusal is posted
1363
+ * on the pull request and exits as waiting (3); the update stays applied.
1364
+ */
1365
+ async function mergeAfterUpdate(ctx: CommandContext, p: Prepared, pr: number): Promise<number> {
1366
+ const { mergeAfterApply, mergeTokenEnv } = await import("../../pr-merge");
1367
+ const { pushLifecycleReport } = await import("../../lifecycle/git");
1368
+ const kind = p.forge?.kind ?? (ctx.args.forge as ForgeKind | undefined);
1369
+ if (!kind) return fail("--merge auto needs --forge <kind> to merge on");
1370
+ const env = mergeTokenEnv(ctx.args.mergeTokenEnv!);
1371
+ if ("error" in env) {
1372
+ console.error(formatWarning({ message: `the pull request was not merged: ${env.error}` }));
1373
+ return CHANT_EXIT.waiting;
1374
+ }
1375
+ let forge: PrForge;
1376
+ try {
1377
+ forge = forgeFromEnv(kind, env);
1378
+ } catch (err) {
1379
+ console.error(formatWarning({ message: `the pull request was not merged: ${err instanceof Error ? err.message : String(err)}` }));
1380
+ return CHANT_EXIT.waiting;
1381
+ }
1382
+ const pushed = await pushLifecycleReport();
1383
+ const merged = await mergeAfterApply({
1384
+ forge,
1385
+ pr,
1386
+ head: p.head,
1387
+ ...(ctx.args.mergeMethod ? { method: ctx.args.mergeMethod as "merge" | "squash" | "rebase" } : {}),
1388
+ recorded: { pushed: pushed.pushed, ...(pushed.pushWarning ? { warning: pushed.pushWarning } : {}) },
1389
+ });
1390
+ if (merged.merged) {
1391
+ console.error(formatSuccess(`merged ${kind === "gitlab" ? `!${pr}` : `#${pr}`} at ${p.head.slice(0, 12)}${merged.sha ? ` as ${merged.sha.slice(0, 12)}` : ""}`));
1392
+ return 0;
1393
+ }
1394
+ console.error(formatWarning({ message: `the pull request was not merged: ${merged.reason}${merged.posted ? "; the reason is posted on it" : ""}` }));
1395
+ return CHANT_EXIT.waiting;
1396
+ }
1397
+
1104
1398
  /**
1105
1399
  * Under `ci.locks` (#4293): the refusal when another open pull request holds
1106
1400
  * a lock on a component this apply reaches, else null. The targets are the
@@ -1109,12 +1403,12 @@ async function prApply(ctx: CommandContext, stage: StageEvents, beforeMerge?: Pr
1109
1403
  * `--forge` every lock counts. A lock file that cannot be read stops the
1110
1404
  * apply, since nothing then says the targets are free.
1111
1405
  */
1112
- async function heldLocksOf(p: Prepared, pr: number | null): Promise<string | null | number> {
1406
+ async function heldLocksOf(p: Prepared, pr: number | null, targets: readonly string[] = p.plan.order): Promise<string | null | number> {
1113
1407
  const { heldTargetLocks, describeHeldTargetLocks } = await import("../../lifecycle/target-lock");
1114
1408
  const isOpen = p.forge?.pullRequestOpen?.bind(p.forge);
1115
1409
  let held;
1116
1410
  try {
1117
- held = await heldTargetLocks(p.gate, p.plan.order, pr, { ...(isOpen ? { isOpen } : {}) });
1411
+ held = await heldTargetLocks(p.gate, targets, pr, { ...(isOpen ? { isOpen } : {}) });
1118
1412
  } catch (err) {
1119
1413
  return fail(`could not read the target locks of ${p.gate}, so nothing was applied: ${err instanceof Error ? err.message : String(err)}`);
1120
1414
  }
@@ -1138,6 +1432,10 @@ async function beforeMergeChecks(ctx: CommandContext): Promise<PrBeforeMerge | n
1138
1432
  if (args.pr === undefined) return fail("--before-merge applies an open pull request, so it needs --pr <n>");
1139
1433
  if (!args.forge || !(FORGE_KINDS as readonly string[]).includes(args.forge)) return fail("--before-merge asks the forge whether the pull request is ready, so it needs --forge github|gitlab|forgejo");
1140
1434
  if (!args.base) return fail("pr-apply needs the commit the change is measured from: --base <ref>", "Before merge, the target branch's commit.");
1435
+ const { checkPrRequires, unmetRequires, parseRequiresList } = await import("../../pr-requires");
1436
+ // #4607: a product's `apply.requires` names the checks to ask; absent, all four.
1437
+ const only = args.requires ? parseRequiresList(args.requires) : undefined;
1438
+ if (only && "error" in only) return fail(only.error);
1141
1439
  const cwd = resolve(".");
1142
1440
  let forge: PrForge;
1143
1441
  let head: string;
@@ -1153,7 +1451,6 @@ async function beforeMergeChecks(ctx: CommandContext): Promise<PrBeforeMerge | n
1153
1451
  const gate = args.gate ?? PR_APPLY_GATE;
1154
1452
  const { ciWorkflowAt } = await import("../../workspace/ci-workflow-at");
1155
1453
  const { appliesBeforeMerge } = await import("../../workspace/ci-workflow");
1156
- const { checkPrRequires, unmetRequires } = await import("../../pr-requires");
1157
1454
  const workflow = ciWorkflowAt(cwd, args.base, member);
1158
1455
  const early = earlyStop(ctx, forge, { pr: args.pr, base, head, gate, ...(member ? { member } : {}) });
1159
1456
  if (!appliesBeforeMerge(workflow)) {
@@ -1165,9 +1462,10 @@ async function beforeMergeChecks(ctx: CommandContext): Promise<PrBeforeMerge | n
1165
1462
  );
1166
1463
  }
1167
1464
  // The apply's own statuses never hold it back: chant ci run's, and the report's.
1168
- const ignore = [`chant/${gate}`, `chant/${PR_APPLY_GATE}`, prStatusContext("apply", member)];
1169
- // No `only`: ws-106 gives the declaration no way to leave a check out, so all four are asked (#4336).
1170
- const requires = await checkPrRequires(forge, args.pr, head, { ignore });
1465
+ // #4550: under a product's words its own prefix too.
1466
+ const ignore = [...new Set([productContext(activeProductWords(), gate), productContext(activeProductWords(), PR_APPLY_GATE), `chant/${gate}`, `chant/${PR_APPLY_GATE}`, prStatusContext("apply", member)])];
1467
+ // ws-106 gives the declaration no way to leave a check out, so with no --requires all four are asked (#4336, #4607).
1468
+ const requires = await checkPrRequires(forge, args.pr, head, { ignore, ...(only ? { only: only.checks } : {}) });
1171
1469
  for (const r of requires) console.error(formatInfo(`${r.name}: ${r.passed ? "passed" : r.pending ? "pending" : "unmet"}, ${r.reason}`));
1172
1470
  const unmet = unmetRequires(requires);
1173
1471
  if (unmet) {
@@ -1194,13 +1492,13 @@ function earlyStop(ctx: CommandContext, forge: PrForge, at: { pr: number; base:
1194
1492
  * refusal when another open pull request holds one, null once taken, or the
1195
1493
  * exit code when the locks could not be written.
1196
1494
  */
1197
- async function takeApplyLocks(p: Prepared, pr: number): Promise<string | null | number> {
1495
+ async function takeApplyLocks(p: Prepared, pr: number, targets: readonly string[] = p.plan.order): Promise<string | null | number> {
1198
1496
  const { takeTargetLocks, describeHeldTargetLocks } = await import("../../lifecycle/target-lock");
1199
1497
  const isOpen = p.forge?.pullRequestOpen?.bind(p.forge);
1200
1498
  const by = process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_LOGIN ?? process.env.USER ?? "unknown";
1201
1499
  let result;
1202
1500
  try {
1203
- result = await takeTargetLocks(p.gate, p.plan.order, { pr, by, at: new Date().toISOString(), stage: "apply", head: p.head }, { ...(isOpen ? { isOpen } : {}) });
1501
+ result = await takeTargetLocks(p.gate, targets, { pr, by, at: new Date().toISOString(), stage: "apply", head: p.head }, { ...(isOpen ? { isOpen } : {}) });
1204
1502
  } catch (err) {
1205
1503
  return fail(`could not take the target locks of ${p.gate}, so nothing was applied: ${err instanceof Error ? err.message : String(err)}`);
1206
1504
  }
@@ -1461,6 +1759,8 @@ function stopper(ctx: CommandContext, p: Prepared, events: RunEventStream | unde
1461
1759
  return async (report: PrReport, code: number, settle?: RunEventSettleStatus): Promise<number> => {
1462
1760
  events?.settle(settle ?? settleOf(report.status), report.status === "plan-failed" || report.status === "failed" ? report.message ?? `pr-${report.stage} ${report.status}` : undefined);
1463
1761
  await finish(ctx, p, report, upload);
1762
+ // #4629: a failed apply's triage and a refused apply's diff, on the pull request.
1763
+ if (report.stage === "apply" && (report.status === "failed" || report.status === "refused") && !ctx.args.noStatus) await respondApply(ctx, p, report);
1464
1764
  console.error((code === 0 ? formatInfo : (m: string) => formatWarning({ message: m }))(`pr-${report.stage}: ${report.status}${report.refusal ? ` (${report.refusal})` : ""}`));
1465
1765
  if (report.message) console.error(report.message);
1466
1766
  printMembers(report);
@@ -1468,6 +1768,22 @@ function stopper(ctx: CommandContext, p: Prepared, events: RunEventStream | unde
1468
1768
  };
1469
1769
  }
1470
1770
 
1771
+ /** The responses an apply's report calls for (#4629), from `--respond` over `CHANT_RESPOND`. Never throws. */
1772
+ async function respondApply(ctx: CommandContext, p: Prepared, report: PrReport): Promise<void> {
1773
+ try {
1774
+ const { parseRespondList } = await import("../../ci-respond");
1775
+ const given = ctx.args.respond ? parseRespondList(ctx.args.respond) : {};
1776
+ if ("error" in given) {
1777
+ console.error(formatWarning({ message: `no response was posted: ${given.error}` }));
1778
+ return;
1779
+ }
1780
+ const { respondPrApply } = await import("../../ci-respond-run");
1781
+ await respondPrApply(p.forge, report, given);
1782
+ } catch (err) {
1783
+ console.error(formatWarning({ message: `the apply's responses were not posted: ${err instanceof Error ? err.message : String(err)}` }));
1784
+ }
1785
+ }
1786
+
1471
1787
  /** Why `--require-review` does not count an approval, or why the reviews could not be read. */
1472
1788
  type ReviewStop = { refusal: "author-approved" | "not-a-reviewer"; message: string } | { error: string } | undefined;
1473
1789
 
@@ -1552,6 +1868,11 @@ function settleWords(body: RunEventComponentSettle): string {
1552
1868
  * pr-apply's job log (#4007): a line on stderr as each wave starts and as
1553
1869
  * each component settles, so the log shows the waves in order while they run.
1554
1870
  */
1871
+ /** One wave's fan-out numbers its wave 1; the events and the log carry the derivation's number (#4003). */
1872
+ function inWave(body: RunEventBody, wave: number): RunEventBody {
1873
+ return "wave" in body && typeof (body as { wave?: unknown }).wave === "number" ? ({ ...body, wave } as RunEventBody) : body;
1874
+ }
1875
+
1555
1876
  function applyLog(): (body: RunEventBody) => void {
1556
1877
  let waves = 0;
1557
1878
  return (body) => {
@@ -1657,6 +1978,7 @@ async function tryResume(p: Prepared, attempt: FanOutAttempt, file: string, op:
1657
1978
  registry: p.registry,
1658
1979
  env: p.env,
1659
1980
  seededOutputs: p.seededOutputs,
1981
+ policyBase: p.base,
1660
1982
  record,
1661
1983
  completed,
1662
1984
  applied: outputs,
@@ -1714,22 +2036,20 @@ async function carryWaves(p: Prepared, attempt: FanOutAttempt, file: string, op:
1714
2036
  return { record, check, approval: approvalOf(check), completed, outputs };
1715
2037
  }
1716
2038
 
1717
- /** A run event with its wave renumbered to `wave`: the fan-out that applies one wave numbers it 1. */
1718
- function inWave(body: RunEventBody, wave: number): RunEventBody {
1719
- return "wave" in body && typeof (body as { wave?: unknown }).wave === "number" ? ({ ...body, wave } as RunEventBody) : body;
1720
- }
1721
-
1722
2039
  /**
1723
2040
  * `pr-apply --wave-gate <gate>` (#4003): apply the pull request's approved
1724
2041
  * set a wave at a time, each wave planned after the one before it applied.
1725
2042
  *
1726
2043
  * The first job plans every member, as pr-apply does, and decides the pull
1727
- * request's gate against that digest. Approved, wave 1 applies with those
1728
- * plans. Each later wave is planned again against the outputs the waves
1729
- * before it left. When the approved change set covers its plan
1730
- * (`planCoveredBy`, as on a resume) it applies under the pull request's
1731
- * approval; when it does not, it waits at `<gate>-wave-<k>` under the pull
1732
- * request's op for an approval of its new plan, and exits 3.
2044
+ * request's gate against that digest. The waves then run on op waves
2045
+ * (#4588): the component waves spec (`componentWavesSpec`), each run a
2046
+ * component, planned and applied through the component plan-wave and
2047
+ * apply-wave steps (`chant components plan-wave|apply-wave`). Each wave is
2048
+ * planned against the outputs the waves before it left. When the approved
2049
+ * change set covers its plan (`planCoveredBy`, the op waves' `pull-request`
2050
+ * approval) it applies under the pull request's approval; when it does not,
2051
+ * it waits at `<gate>-wave-<k>` under the pull request's op for an approval
2052
+ * of its new plan, and exits 3.
1733
2053
  *
1734
2054
  * With `--wave <k>` the job runs wave k and no other, reading the approved
1735
2055
  * set and the progress from the `--resume` record the job before it left.
@@ -1850,7 +2170,6 @@ async function prApplyWaves(
1850
2170
  );
1851
2171
  }
1852
2172
 
1853
- let planned: PrPlanSet | undefined;
1854
2173
  let judged: PolicyJudged = { held: false };
1855
2174
  if (carry) {
1856
2175
  // What the earlier waves applied settles first (#4007), each in its own wave, as a resumed apply's does.
@@ -1866,6 +2185,7 @@ async function prApplyWaves(
1866
2185
  const set = await planAll(p, events?.emit);
1867
2186
  approved = set;
1868
2187
  if (set.failed) {
2188
+ if (set.policyDenied) return stop(report({ status: "plan-failed", message: "The policy denied a member's plan, so nothing was applied." }), CHANT_EXIT.denied);
1869
2189
  return stop(report({ status: "plan-failed", message: "A member failed to plan, so there is no plan to compare with the approved one. Nothing was applied." }), 1);
1870
2190
  }
1871
2191
  await storeChangeSetForGate(ctx, p, set.doc);
@@ -1877,9 +2197,8 @@ async function prApplyWaves(
1877
2197
  // #4323: the after-gate hooks hear the decision, a refusal too.
1878
2198
  const afterGate = await runGateHook(p, { op, digest: set.doc.digest, satisfied: decided.satisfied }, p.plan.order);
1879
2199
  if (afterGate && decided.satisfied) return stop(report({ status: "failed", message: afterGate }), 1);
1880
- if (!decided.satisfied) return stop(report({ status: "refused", refusal: decided.refusal, message: decided.message }), GATED_EXIT_CODE);
2200
+ if (!decided.satisfied) return stop(report({ status: "refused", refusal: decided.refusal, message: decided.message }), decided.refusal === "plan-changed" ? CHANT_EXIT.moved : CHANT_EXIT.waiting);
1881
2201
  via = decided.via;
1882
- planned = set;
1883
2202
  }
1884
2203
  const approvedSet = approved!;
1885
2204
 
@@ -1923,8 +2242,11 @@ async function prApplyWaves(
1923
2242
  const from = only ?? (left || total + 1);
1924
2243
  const to = only ?? total;
1925
2244
  /** The last apply in this job that failed (#4291): its results give the exit code once every wave ran. */
1926
- let lastFailure: { results: Parameters<typeof failedRunExitCode>[0]; gated: boolean } | undefined;
2245
+ let lastFailure: { exitCode: number } | undefined;
1927
2246
  let planFailedIn: number | undefined;
2247
+ // #4588: the outputs file the waves' plan-wave and apply-wave steps hand outputs on in.
2248
+ const { componentWaveOutputsFile } = await import("../../components/product-pipeline");
2249
+ const outputsFile = componentWaveOutputsFile(op);
1928
2250
  for (let k = from; k <= to; k++) {
1929
2251
  // #4291: a component of this wave whose upstream failed, or was blocked by a failure, is blocked; the rest of the wave runs.
1930
2252
  const before = new Set(p.plan.waves.slice(0, k - 1).flat());
@@ -1943,138 +2265,59 @@ async function prApplyWaves(
1943
2265
  if (blockedNow.size > 0) recordAttempt();
1944
2266
  continue;
1945
2267
  }
1946
- const inThisWave = new Set(wavePlan.order);
1947
-
1948
- // Wave 1 of the apply that just planned every member applies those plans:
1949
- // they are the approved set's. Every other wave is planned again, against
1950
- // the outputs the waves before it left.
1951
- let set: PrPlanSet;
1952
- let entry: PrWave;
1953
- if (planned && k === 1) {
1954
- set = {
1955
- ...planned,
1956
- members: planned.members.filter((m) => inThisWave.has(m.component)),
1957
- plans: Object.fromEntries(Object.entries(planned.plans).filter(([name]) => inThisWave.has(name))),
1958
- };
1959
- entry = { wave: k, components: wavePlan.order, status: "applied", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest, ...(approval.approvedBy ? { approvedBy: approval.approvedBy } : {}) };
1960
- } else {
1961
- const notApplied = Object.fromEntries(Object.entries(approvedSet.outputs).filter(([name]) => !completed.has(name)));
1962
- const fresh = await hookedPlan(p, wavePlan.order, () =>
1963
- planPrSet({
1964
- components: p.components,
1965
- plan: wavePlan,
1966
- registry: p.registry,
1967
- env: p.env,
1968
- seededOutputs: { ...p.seededOutputs, ...notApplied, ...outputsSoFar },
1969
- ...(events ? { onRunEvent: (body: RunEventBody) => events.emit(body) } : {}),
1970
- }),
1971
- );
1972
- if (fresh.failed) {
1973
- for (const m of fresh.members) {
1974
- after.set(m.member, m);
1975
- if (m.status === "plan-failed") failedSoFar.add(m.component);
1976
- }
1977
- setWave({ wave: k, components: wavePlan.order, status: "plan-failed", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest });
1978
- // #4291: the later waves still run what does not depend on this wave.
1979
- console.error(formatWarning({ message: `A member of wave ${k} failed to plan, so nothing in wave ${k} was applied.`, hint: "The waves after it apply what does not depend on wave " + k + "." }));
1980
- planFailedIn ??= k;
1981
- continue;
1982
- }
1983
- const moved = waveNotCovered(approvedSet.doc, fresh.doc, approvedSet.members, { approved: approvedSet.shapes, fresh: fresh.shapes });
1984
- set = fresh;
1985
- if (moved.length === 0) {
1986
- console.error(formatInfo(`wave ${k}: the approved plan covers what it plans now, so it applies under the pull request's approval`));
1987
- entry = { wave: k, components: wavePlan.order, status: "applied", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest, ...(approval.approvedBy ? { approvedBy: approval.approvedBy } : {}) };
1988
- } else {
1989
- const gate = waveGateName(waveGate, k);
1990
- const digest = fresh.doc.digest;
1991
- console.error(formatInfo(`wave ${k}: its plan moved since the pull request's (${moved.join("; ")}), so it needs an approval of ${gate}`));
1992
- await storeChangeSetForGate(ctx, p, fresh.doc);
1993
- writeWaveChangeSet(ctx, k, fresh.doc, upload);
1994
- const approveLine = prApproveCommand({ op, gate, digest });
1995
- const check = await emitGateStep(
1996
- events?.emit,
1997
- { op, gate },
1998
- () => decidePrGate(gitGateLedgerPort(), { op, gate, digest, description: `${changeLabel(pr, green)}, wave ${k} of ${total}: ${wavePlan.order.join(", ")}` }),
1999
- (unapproved) =>
2000
- unapproved.mismatch
2001
- ? `wave ${k}'s plan changed after its approval. Approve the plan now: ${approveLine}`
2002
- : `wave ${k}'s plan is not the one the pull request approved. Approve it: ${approveLine}`,
2003
- );
2004
- const waveApproval = approvalOf(check);
2005
- const waiting: PrWave = {
2006
- wave: k,
2007
- components: wavePlan.order,
2008
- status: "waiting",
2009
- approval: "wave",
2010
- gate,
2011
- digest,
2012
- moved,
2013
- ...(waveApproval.approved ? { approved: waveApproval.approved } : {}),
2014
- };
2015
- if (!check.satisfied) {
2016
- setWave(waiting);
2017
- const message =
2018
- waveApproval.status === "changed"
2019
- ? `Wave ${k}'s plan changed after its approval, so nothing in it was applied. approved: ${waveApproval.approved ?? "(none)"}; planned now: ${digest}. ` +
2020
- `Read the new plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`
2021
- : `Wave ${k} was planned after the waves before it applied, and the pull request's approved plan does not cover it: ${moved.join("; ")}. ` +
2022
- `Nothing in wave ${k} was applied. Read its plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`;
2023
- return stop(report({ status: "refused", refusal: waveApproval.status === "changed" ? "wave-plan-changed" : "wave-not-approved", message }), GATED_EXIT_CODE);
2024
- }
2025
- const waveReview = await review(waveApproval.approvedBy ?? [], `Wave ${k}'s plan`);
2026
- if (waveReview && "error" in waveReview) return fail(waveReview.error);
2027
- if (waveReview) {
2028
- setWave(waiting);
2029
- emitReviewStop(events, waveReview.message);
2030
- return stop(report({ status: "refused", refusal: waveReview.refusal, message: waveReview.message }), GATED_EXIT_CODE);
2031
- }
2032
- entry = { wave: k, components: wavePlan.order, status: "applied", approval: "wave", gate, digest, moved, ...(waveApproval.approvedBy ? { approvedBy: waveApproval.approvedBy } : {}) };
2033
- }
2034
- }
2035
-
2268
+ // #4588: the wave plans, waits or passes its gate, and applies on op waves: the component waves spec,
2269
+ // each run a component, through the component plan-wave and apply-wave steps.
2270
+ const pending: PrWave = { wave: k, components: wavePlan.order, status: "applied", approval: "pull-request", gate: p.gate, digest: approvedSet.doc.digest };
2036
2271
  // #4288: the wave's apply-side hooks, around its apply.
2037
2272
  const waveBefore = await runStageHook(p, "before-apply", wavePlan.order, undefined, `nothing in wave ${k} was applied`);
2038
2273
  if (waveBefore) {
2039
- setWave({ ...entry, status: "failed" });
2274
+ setWave({ ...pending, status: "failed" });
2040
2275
  return stop(report({ status: "failed", message: waveBefore }), 1);
2041
2276
  }
2042
- const applied = await applyPrSet({
2043
- components: p.components,
2044
- plan: wavePlan,
2045
- registry: p.registry,
2046
- env: p.env,
2047
- set,
2048
- // One wave's fan-out numbers its wave 1; the events and the log carry the derivation's number.
2049
- onRunEvent: (body: RunEventBody) => {
2050
- const numbered = inWave(body, k);
2051
- events?.nested(numbered);
2052
- if (numbered.type !== "run-start") log(numbered);
2053
- },
2054
- onComponentSettled: (settled, outputs) => {
2055
- if (settled.status === "ok") {
2056
- completed.add(settled.component);
2057
- failedSoFar.delete(settled.component);
2058
- if (inputsNow[settled.component] !== undefined) inputsSoFar[settled.component] = inputsNow[settled.component]!;
2059
- if (outputs) outputsSoFar[settled.component] = outputs;
2060
- } else if (settled.status === "fail") {
2061
- failedSoFar.add(settled.component);
2062
- }
2063
- recordAttempt();
2064
- },
2065
- });
2066
- for (const m of applied.members) after.set(m.member, m);
2067
- for (const name of applied.run.completed) {
2277
+ // The outputs the waves before this one left, and the approved set's for what has not applied yet, seed its plans.
2278
+ const notApplied = Object.fromEntries(Object.entries(approvedSet.outputs).filter(([name]) => !completed.has(name)));
2279
+ mkdirSync(dirname(resolve(outputsFile)), { recursive: true });
2280
+ writeFileSync(resolve(outputsFile), JSON.stringify({ ...p.seededOutputs, ...notApplied, ...outputsSoFar }, null, 2) + "\n");
2281
+ 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 });
2282
+ const entry = ran.entry;
2283
+ if (ran.review && "error" in ran.review) return fail(ran.review.error);
2284
+ if (ran.review && ran.exitCode === CHANT_EXIT.waiting) {
2285
+ setWave(entry);
2286
+ emitReviewStop(events, ran.review.message);
2287
+ return stop(report({ status: "refused", refusal: ran.review.refusal, message: ran.review.message }), GATED_EXIT_CODE);
2288
+ }
2289
+ for (const name of ran.applied) {
2068
2290
  completed.add(name);
2069
- const outputs = applied.run.componentOutputs[name];
2070
- if (outputs) outputsSoFar[name] = outputs;
2291
+ failedSoFar.delete(name);
2292
+ if (inputsNow[name] !== undefined) inputsSoFar[name] = inputsNow[name]!;
2293
+ if (ran.outputs[name]) outputsSoFar[name] = ran.outputs[name]!;
2294
+ }
2295
+ for (const name of ran.failed) failedSoFar.add(name);
2296
+ if (ran.exitCode === CHANT_EXIT.waiting || ran.exitCode === CHANT_EXIT.moved) {
2297
+ setWave(entry);
2298
+ // #4003: the wave's new plan beside the report, for whoever approves its gate.
2299
+ if (ran.changeSet) writeWaveChangeSet(ctx, k, ran.changeSet, upload);
2300
+ const approveLine = prApproveCommand({ op, gate: entry.gate, digest: entry.digest });
2301
+ const message =
2302
+ ran.exitCode === CHANT_EXIT.moved
2303
+ ? `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.`
2304
+ : `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("; ")}` : ""}. ` +
2305
+ `Nothing in wave ${k} was applied. Read its plan, and if it is right, approve it: ${approveLine}; then run the wave's apply again.`;
2306
+ return stop(report({ status: "refused", refusal: ran.exitCode === CHANT_EXIT.moved ? "wave-plan-changed" : "wave-not-approved", message }), ran.exitCode);
2071
2307
  }
2072
- const waveAfter = await runStageHook(p, "after-apply", wavePlan.order.filter((name) => applied.run.completed.includes(name)), undefined, `wave ${k} counts as failed though its components applied`);
2073
- setWave({ ...entry, status: applied.status === "applied" && !waveAfter ? "applied" : "failed" });
2074
- await recordAutoReleasesForRun(applied.run.results, p.env, at.release.runId, resolveAutoReleaseDisabled(p.config, args.noReleaseRecord), at.release.runOrigin, undefined, undefined, prAppliedDigests(p, applied.members));
2075
- if (applied.status !== "applied") {
2308
+ if (ran.exitCode === CHANT_EXIT.held) {
2309
+ setWave({ ...entry, status: "waiting" });
2310
+ 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);
2311
+ }
2312
+ if (ran.exitCode === CHANT_EXIT.denied || ran.exitCode === CHANT_EXIT.declined || ran.exitCode === CHANT_EXIT.superseded) {
2313
+ setWave({ ...entry, status: "failed" });
2314
+ return stop(report({ status: "failed", message: `Wave ${k} stopped on op waves with exit ${ran.exitCode}; nothing more was applied.` }), ran.exitCode);
2315
+ }
2316
+ 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`);
2317
+ setWave({ ...entry, status: ran.exitCode === CHANT_EXIT.done && !waveAfter ? "applied" : "failed" });
2318
+ if (ran.exitCode !== CHANT_EXIT.done) {
2076
2319
  // #4291: a failed member blocks only its dependents, so the later waves still run.
2077
- lastFailure = { results: applied.run.results, gated: applied.run.status === "gated" };
2320
+ lastFailure = { exitCode: ran.exitCode };
2078
2321
  recordAttempt();
2079
2322
  continue;
2080
2323
  }
@@ -2091,8 +2334,7 @@ async function prApplyWaves(
2091
2334
  : blockedLine ? blockedLine.trim() : undefined;
2092
2335
  return stop(
2093
2336
  report({ status: "failed", ...(message ? { message } : {}) }),
2094
- lastFailure ? failedRunExitCode(lastFailure.results) : 1,
2095
- lastFailure?.gated ? "gated" : undefined,
2337
+ lastFailure ? lastFailure.exitCode : 1,
2096
2338
  );
2097
2339
  }
2098
2340
 
@@ -2101,6 +2343,356 @@ async function prApplyWaves(
2101
2343
  return stop(report({ status: done ? "applied" : "wave-applied" }), 0);
2102
2344
  }
2103
2345
 
2346
+ // ── The component plan-wave and apply-wave steps (#4588) ─────────────────────
2347
+
2348
+ /** The outputs earlier waves' components left, from `--wave-outputs`; empty when the file is not there yet. */
2349
+ function readWaveOutputs(file: string | undefined): { outputs: Record<string, Record<string, unknown>> } | { error: string } {
2350
+ if (!file || !existsSync(resolve(file))) return { outputs: {} };
2351
+ try {
2352
+ const parsed = JSON.parse(readFileSync(resolve(file), "utf8")) as unknown;
2353
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { error: `--wave-outputs ${file} must hold { "<component>": { ...outputs } }` };
2354
+ return { outputs: parsed as Record<string, Record<string, unknown>> };
2355
+ } catch (err) {
2356
+ return { error: `--wave-outputs: could not read "${file}": ${err instanceof Error ? err.message : String(err)}` };
2357
+ }
2358
+ }
2359
+
2360
+ /** The runs `chant run wave` wrote to `{runs}`: their targets, each a component, and on apply-wave the digest each was approved at. */
2361
+ function readWaveRuns(file: string | undefined): Array<{ target: string; planDigest?: string }> | { error: string } {
2362
+ if (!file) return { error: "the step needs --runs <file>, which chant run wave fills in as {runs}" };
2363
+ try {
2364
+ const parsed = JSON.parse(readFileSync(resolve(file), "utf8")) as { runs?: unknown };
2365
+ if (!Array.isArray(parsed?.runs)) return { error: `--runs ${file} has no runs` };
2366
+ return (parsed.runs as Array<{ target?: unknown; planDigest?: unknown }>).flatMap((r) =>
2367
+ typeof r?.target === "string" ? [{ target: r.target, ...(typeof r.planDigest === "string" ? { planDigest: r.planDigest } : {}) }] : [],
2368
+ );
2369
+ } catch (err) {
2370
+ return { error: `--runs: could not read "${file}": ${err instanceof Error ? err.message : String(err)}` };
2371
+ }
2372
+ }
2373
+
2374
+ /** The fan-out plan of `names`, one wave of the derivation, with the rest of that wave counted as done. */
2375
+ function namedWavePlan(p: Prepared, names: readonly string[]): FanOutPlan | { error: string } {
2376
+ const unknown = names.filter((n) => !p.plan.order.includes(n));
2377
+ if (unknown.length > 0) return { error: `${unknown.join(", ")} ${unknown.length === 1 ? "is" : "are"} not in the change between ${p.base.slice(0, 12)} and ${p.head.slice(0, 12)}, so the wave cannot plan ${unknown.length === 1 ? "it" : "them"}` };
2378
+ const k = p.plan.waves.findIndex((w) => w.includes(names[0]!)) + 1;
2379
+ const wave = p.plan.waves[k - 1] ?? [];
2380
+ const across = names.filter((n) => !wave.includes(n));
2381
+ if (across.length > 0) return { error: `${names[0]} and ${across.join(", ")} are in different waves of the derivation, so one wave step cannot plan them together` };
2382
+ return prWavePlan(p.plan, p.components, k, wave.filter((n) => !names.includes(n)));
2383
+ }
2384
+
2385
+ /** One component's entry in the op-waves plans file: the digest over its members' plans, and whether it changes or destroys anything. */
2386
+ function componentPlanEntry(set: PrPlanSet, component: string): { target: string; planDigest: string; empty?: true; destructive?: true } {
2387
+ const members = set.members.filter((m) => m.component === component).sort((a, b) => a.member.localeCompare(b.member));
2388
+ const names = new Set(members.map((m) => m.member));
2389
+ const entries = set.doc.entries.filter((e) => names.has(e.member));
2390
+ const changes = entries.filter((e) => e.action !== "no-op" && e.action !== "read");
2391
+ const destructive = changes.some((e) => e.action === "delete" || e.action === "replace");
2392
+ return {
2393
+ target: component,
2394
+ planDigest: computePlanDigest("component-wave", members.map((m) => ({ member: m.member, planDigest: m.planDigest }))),
2395
+ ...(changes.length === 0 ? { empty: true as const } : {}),
2396
+ ...(destructive ? { destructive: true as const } : {}),
2397
+ };
2398
+ }
2399
+
2400
+ /** The files a component wave step names: `{runs}`, `{plans}` and the outputs file. */
2401
+ interface WaveStepFiles {
2402
+ runs: Array<{ target: string; planDigest?: string }>;
2403
+ plansFile: string;
2404
+ outputsFile?: string;
2405
+ outputs: Record<string, Record<string, unknown>>;
2406
+ }
2407
+
2408
+ /** Read the step's runs and outputs files from its flags. */
2409
+ function waveStepFiles(args: Pick<CommandContext["args"], "runsFile" | "plansFile" | "waveOutputs">): WaveStepFiles | { error: string } {
2410
+ const runs = readWaveRuns(args.runsFile);
2411
+ if ("error" in runs) return runs;
2412
+ if (!args.plansFile) return { error: "the step needs --plans <file>, which chant run wave fills in as {plans}" };
2413
+ const read = readWaveOutputs(args.waveOutputs);
2414
+ if ("error" in read) return read;
2415
+ return { runs, plansFile: args.plansFile, ...(args.waveOutputs ? { outputsFile: args.waveOutputs } : {}), outputs: read.outputs };
2416
+ }
2417
+
2418
+ /** Plan the step's runs, each a component, against the outputs the earlier waves left. */
2419
+ async function planComponentRuns(p: Prepared, files: WaveStepFiles): Promise<{ set: PrPlanSet; plan: FanOutPlan } | { error: string }> {
2420
+ const names = files.runs.map((r) => r.target);
2421
+ const plan = names.length > 0 ? namedWavePlan(p, names) : { ...p.plan, order: [], waves: [] };
2422
+ if ("error" in plan) return plan;
2423
+ const lockGrain = await declaredLockGrainOf(p);
2424
+ const set = await planPrSet({ components: p.components, plan, registry: p.registry, env: p.env, seededOutputs: { ...p.seededOutputs, ...files.outputs }, ...(lockGrain ? { lockGrain } : {}), policyBase: p.base });
2425
+ return { set, plan };
2426
+ }
2427
+
2428
+ /** The plan step over `p`: write `{plans}`, one digest per component and the wave's change set. */
2429
+ async function planComponentWave(p: Prepared, files: WaveStepFiles): Promise<number> {
2430
+ const planned = await planComponentRuns(p, files);
2431
+ if ("error" in planned) return fail(planned.error);
2432
+ const { set } = planned;
2433
+ if (set.failed) {
2434
+ for (const m of set.members.filter((x) => x.status === "plan-failed")) console.error(formatError({ message: `${m.member} (${m.component}) failed to plan${m.error ? `: ${m.error}` : ""}` }));
2435
+ return set.policyDenied ? CHANT_EXIT.denied : 1;
2436
+ }
2437
+ const file = { runs: files.runs.map((r) => componentPlanEntry(set, r.target)), changeSet: set.doc };
2438
+ mkdirSync(dirname(resolve(files.plansFile)), { recursive: true });
2439
+ writeFileSync(resolve(files.plansFile), JSON.stringify(file, null, 2) + "\n");
2440
+ 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}`));
2441
+ return 0;
2442
+ }
2443
+
2444
+ /** 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. */
2445
+ async function applyComponentWave(p: Prepared, files: WaveStepFiles, opts: { noReleaseRecord?: boolean; onRunEvent?: RunEventSink; runsResult?: string } = {}): Promise<number> {
2446
+ if (files.runs.length === 0) return 0;
2447
+ const planned = await planComponentRuns(p, files);
2448
+ if ("error" in planned) return fail(planned.error);
2449
+ const { set, plan } = planned;
2450
+ if (set.failed) return fail("A component of the wave failed to plan again, so nothing in it was applied.");
2451
+ const moved = files.runs.filter((r) => r.planDigest !== undefined && !samePlanDigest(componentPlanEntry(set, r.target).planDigest, r.planDigest));
2452
+ if (moved.length > 0) {
2453
+ 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." }));
2454
+ return CHANT_EXIT.moved;
2455
+ }
2456
+ const lease = await leaseSetRows(p, set);
2457
+ if (typeof lease === "number") return lease;
2458
+ if ("held" in lease) {
2459
+ console.error(formatError({ message: lease.held }));
2460
+ return CHANT_EXIT.held;
2461
+ }
2462
+ const lockGrain = await declaredLockGrainOf(p);
2463
+ const release = autoReleaseRun(`wave-${Date.now()}`);
2464
+ let applied: Awaited<ReturnType<typeof applyPrSet>>;
2465
+ try {
2466
+ 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 } : {}) });
2467
+ } finally {
2468
+ await lease.release();
2469
+ }
2470
+ await recordAutoReleasesForRun(applied.run.results, p.env, release.runId, resolveAutoReleaseDisabled(p.config, opts.noReleaseRecord), release.runOrigin, undefined, undefined, prAppliedDigests(p, applied.members));
2471
+ if (files.outputsFile) {
2472
+ const next = { ...files.outputs };
2473
+ for (const name of applied.run.completed) next[name] = applied.run.componentOutputs[name] ?? {};
2474
+ mkdirSync(dirname(resolve(files.outputsFile)), { recursive: true });
2475
+ writeFileSync(resolve(files.outputsFile), JSON.stringify(next, null, 2) + "\n");
2476
+ }
2477
+ for (const m of applied.members) console.error(m.status === "applied" ? formatSuccess(`applied ${m.member} (${m.component})`) : formatWarning({ message: `${m.member} (${m.component}): ${m.status}${m.error ? `, ${m.error}` : ""}` }));
2478
+ // #4291: the components that applied, so op waves fails only the others and blocks only what depends on them.
2479
+ const runsResult = opts.runsResult ?? (process.env.CHANT_APPLY_RUNS_RESULT ? resolve(process.env.CHANT_APPLY_RUNS_RESULT) : undefined);
2480
+ if (runsResult && applied.status !== "applied") {
2481
+ mkdirSync(dirname(runsResult), { recursive: true });
2482
+ writeFileSync(runsResult, JSON.stringify({ applied: [...applied.run.completed].sort() }, null, 2) + "\n");
2483
+ }
2484
+ return applied.status === "applied" ? 0 : applied.status === "waiting" ? CHANT_EXIT.waiting : 1;
2485
+ }
2486
+
2487
+ /**
2488
+ * `chant components plan-wave --runs <file> --plans <file> --base <ref>
2489
+ * --env <env> [--member <m>] [--wave-outputs <file>]` (#4588): the
2490
+ * component plan step of a component waves spec. Plans each run, a
2491
+ * component, through the project's capabilities against the outputs the
2492
+ * waves before it left, and writes `{plans}`: one digest per component over
2493
+ * its members' plans, and the wave's change set, which a `pull-request`
2494
+ * wave checks the pull request's approval against.
2495
+ */
2496
+ export async function runComponentsPlanWave(ctx: CommandContext): Promise<number> {
2497
+ const files = waveStepFiles(ctx.args);
2498
+ if ("error" in files) return fail(files.error);
2499
+ const p = await prepare(ctx, "apply");
2500
+ if (typeof p === "number") return p;
2501
+ return planComponentWave(p, files);
2502
+ }
2503
+
2504
+ /**
2505
+ * `chant components apply-wave --runs <file> --plans <file> --base <ref>
2506
+ * --env <env> [--member <m>] [--wave-outputs <file>]` (#4588): the
2507
+ * component apply step. Plans the approved runs again and exits 4 when a
2508
+ * component's plan is not the one approved; else leases its rows on the
2509
+ * resource grain, applies, records the releases, and adds each applied
2510
+ * component's outputs to `--wave-outputs` for the next wave.
2511
+ */
2512
+ export async function runComponentsApplyWave(ctx: CommandContext): Promise<number> {
2513
+ const files = waveStepFiles(ctx.args);
2514
+ if ("error" in files) return fail(files.error);
2515
+ const p = await prepare(ctx, "apply");
2516
+ if (typeof p === "number") return p;
2517
+ return applyComponentWave(p, files, { noReleaseRecord: ctx.args.noReleaseRecord });
2518
+ }
2519
+
2520
+ /**
2521
+ * The component steps in this process (#4588): `pr-apply --wave-gate`
2522
+ * already holds the prepared project, so the plan-wave and apply-wave lines
2523
+ * of its spec run here against it, rather than in a process that would
2524
+ * derive the change again.
2525
+ */
2526
+ function componentWaveExec(p: Prepared, noReleaseRecord?: boolean, onRunEvent?: RunEventSink): (argv: string[], cwd: string, env?: Record<string, string>) => Promise<number> {
2527
+ return async (argv, cwd, env) => {
2528
+ const at = argv.findIndex((a, i) => a === "components" && (argv[i + 1] === "plan-wave" || argv[i + 1] === "apply-wave"));
2529
+ if (at < 0) return fail(`not a component wave step: ${argv.join(" ")}`);
2530
+ let args: CommandContext["args"];
2531
+ try {
2532
+ args = parseArgs(argv.slice(at));
2533
+ } catch (err) {
2534
+ return fail(err instanceof Error ? err.message : String(err));
2535
+ }
2536
+ const files = waveStepFiles(args);
2537
+ if ("error" in files) return fail(files.error);
2538
+ const runsResult = env?.CHANT_APPLY_RUNS_RESULT ? resolve(cwd, env.CHANT_APPLY_RUNS_RESULT) : undefined;
2539
+ return argv[at + 1] === "plan-wave" ? planComponentWave(p, files) : applyComponentWave(p, files, { noReleaseRecord, ...(onRunEvent ? { onRunEvent } : {}), ...(runsResult ? { runsResult } : {}) });
2540
+ };
2541
+ }
2542
+
2543
+ /**
2544
+ * A gate ledger that holds the approval `pr-apply` already decided (#4588):
2545
+ * an approval of the pull request's gate under its op, for the approved
2546
+ * change set, so an op wave of the component waves spec finds the approval
2547
+ * a pull request (or a green commit's merges) gave and checks its own plan
2548
+ * against it. Everything else is the real ledger's.
2549
+ */
2550
+ function withDecidedApproval(port: GateLedgerPort, at: { op: string; gate: string; digest: string; approvedBy: string[]; timestamp: string }): GateLedgerPort {
2551
+ return {
2552
+ ...port,
2553
+ appendPending: (input) => port.appendPending(input),
2554
+ async read(op) {
2555
+ const got = await port.read(op);
2556
+ if (op !== at.op) return got;
2557
+ const decided: GateResolutionRecord = { version: 1, kind: "resolution", op: at.op, gate: at.gate, resolvedBy: at.approvedBy.join(", ") || "pr-apply", timestamp: at.timestamp, planDigest: at.digest, changeSet: at.digest };
2558
+ return { ...got, resolutions: [...got.resolutions, decided] };
2559
+ },
2560
+ };
2561
+ }
2562
+
2563
+ /**
2564
+ * The review rule on a wave's own gate (#4000, #4588): `--require-review`
2565
+ * judges an approval of the wave's gate as it judges the pull request's, so
2566
+ * an approval it refuses never reaches the op wave, which then waits. The
2567
+ * refusal is kept in `refused` for pr-apply's report. The pull request's gate
2568
+ * was judged before the waves ran, so its approvals pass as they are.
2569
+ */
2570
+ function withWaveReview(port: GateLedgerPort, at: { prGate: string; what: string; review: (approvedBy: readonly string[], what: string) => Promise<ReviewStop>; refused: { stop?: ReviewStop } }): GateLedgerPort {
2571
+ return {
2572
+ ...port,
2573
+ async read(op) {
2574
+ const got = await port.read(op);
2575
+ const resolutions: GateResolutionRecord[] = [];
2576
+ for (const r of got.resolutions) {
2577
+ const stop = r.gate === at.prGate ? undefined : await at.review([r.resolvedBy], at.what);
2578
+ if (stop) at.refused.stop ??= stop;
2579
+ else resolutions.push(r);
2580
+ }
2581
+ return { ...got, resolutions };
2582
+ },
2583
+ };
2584
+ }
2585
+
2586
+ /** What one wave of `pr-apply --wave-gate` on op waves came to (#4588). */
2587
+ interface ComponentWaveOutcome {
2588
+ exitCode: number;
2589
+ applied: string[];
2590
+ failed: string[];
2591
+ entry: PrWave;
2592
+ /** The wave's outputs file after it ran. */
2593
+ outputs: Record<string, Record<string, unknown>>;
2594
+ /** The wave's new plan, when it planned: what an approval of its own gate is asked for. */
2595
+ changeSet?: PrPlanSet["doc"];
2596
+ /** Why `--require-review` refused an approval of the wave's own gate (#4000). */
2597
+ review?: ReviewStop;
2598
+ }
2599
+
2600
+ /**
2601
+ * Run wave `k` of `pr-apply --wave-gate` on op waves (#4588): the component
2602
+ * waves spec with the wave's runs left to apply, read at base as chant
2603
+ * wrote it (the spec is chant's, never the change's), decided under the
2604
+ * approval pr-apply holds, planned and applied through the component
2605
+ * plan-wave and apply-wave steps.
2606
+ */
2607
+ async function runComponentWave(
2608
+ p: Prepared,
2609
+ at: {
2610
+ op: string;
2611
+ waveGate: string;
2612
+ k: number;
2613
+ runs: string[];
2614
+ approved: PrPlanSet["doc"];
2615
+ approvedBy: string[];
2616
+ outputsFile: string;
2617
+ noReleaseRecord?: boolean;
2618
+ review: (approvedBy: readonly string[], what: string) => Promise<ReviewStop>;
2619
+ events?: RunEventStream;
2620
+ log: (body: RunEventBody) => void;
2621
+ },
2622
+ ): Promise<ComponentWaveOutcome> {
2623
+ const { componentWavesSpec, componentWaveSteps, PRODUCT_WAVES_SPEC_DIR: PRODUCT_WAVES_DIR } = await import("../../components/product-pipeline");
2624
+ const { runOpWave, opWavePlansPath } = await import("../../op/op-waves-run");
2625
+ const words = activeProductWords();
2626
+ const cwd = resolve(".");
2627
+ 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 });
2628
+ const waves = p.plan.waves.map((w, i) => (i === at.k - 1 ? at.runs : w));
2629
+ const spec = componentWavesSpec(p.components, words, steps, { op: at.op, gate: at.waveGate, prGate: p.gate, waves });
2630
+ const specFile = `${PRODUCT_WAVES_DIR}/${at.op}.spec.json`;
2631
+ const refused: { stop?: ReviewStop } = {};
2632
+ const result = await runOpWave({
2633
+ spec,
2634
+ specFile,
2635
+ wave: at.k,
2636
+ base: p.base,
2637
+ head: p.head,
2638
+ cwd,
2639
+ show: () => ({ sha: p.base, text: JSON.stringify(spec) }),
2640
+ gates: withWaveReview(withDecidedApproval(gitGateLedgerPort(), { op: at.op, gate: p.gate, digest: at.approved.digest, approvedBy: at.approvedBy, timestamp: new Date().toISOString() }), {
2641
+ prGate: p.gate,
2642
+ what: `Wave ${at.k}'s plan`,
2643
+ review: at.review,
2644
+ refused,
2645
+ }),
2646
+ // 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.
2647
+ runs: { append: async () => {} },
2648
+ changeSets: async (digest) => {
2649
+ if (samePlanDigest(digest, at.approved.digest)) return at.approved;
2650
+ const { readStoredChangeSet } = await import("../../lifecycle/change-set-store");
2651
+ const got = await readStoredChangeSet(digest, { cwd });
2652
+ return got.status === "found" ? got.document : undefined;
2653
+ },
2654
+ lockGate: p.gate,
2655
+ // The apply's run events nest in pr-apply's stream with the derivation's wave number, as its log does.
2656
+ waveExec: componentWaveExec(p, at.noReleaseRecord, (body) => {
2657
+ const numbered = inWave(body, at.k);
2658
+ at.events?.nested(numbered);
2659
+ if (numbered.type !== "run-start") at.log(numbered);
2660
+ }),
2661
+ // The outcome files of this commit's waves alone, so a run of another commit on the same checkout blocks nothing here.
2662
+ outcomeDir: `${PRODUCT_WAVES_DIR}/${at.op}/outcomes-${p.head.slice(0, 12)}`,
2663
+ });
2664
+ const d = result.decision;
2665
+ const byPullRequest = d?.via === "pull-request";
2666
+ // #4553: an approval of the wave's own gate stands, but for another plan: the plan moved after its approval.
2667
+ const exitCode = result.exitCode === CHANT_EXIT.waiting && !byPullRequest && d?.mismatch && !refused.stop ? CHANT_EXIT.moved : result.exitCode;
2668
+ const entry: PrWave = {
2669
+ wave: at.k,
2670
+ components: at.runs,
2671
+ status: exitCode === CHANT_EXIT.done ? "applied" : exitCode === CHANT_EXIT.waiting || exitCode === CHANT_EXIT.moved ? "waiting" : "failed",
2672
+ approval: byPullRequest || !d ? "pull-request" : "wave",
2673
+ gate: byPullRequest || !d ? p.gate : d.gate,
2674
+ digest: byPullRequest || !d ? at.approved.digest : d.digest,
2675
+ ...(byPullRequest ? (at.approvedBy.length > 0 ? { approvedBy: at.approvedBy } : {}) : d?.approvedBy ? { approvedBy: [d.approvedBy] } : {}),
2676
+ ...(!byPullRequest && d?.coveredBy?.reason ? { moved: [d.coveredBy.reason] } : {}),
2677
+ ...(!byPullRequest && d?.mismatch?.approved ? { approved: d.mismatch.approved } : {}),
2678
+ };
2679
+ // A wave that waits at its own gate is the stream's gate step there, as before op waves (#4003).
2680
+ if (d && !byPullRequest && (exitCode === CHANT_EXIT.waiting || exitCode === CHANT_EXIT.moved)) {
2681
+ const waiting = { satisfied: false, pending: { op: at.op }, ...(d.mismatch ? { mismatch: d.mismatch } : {}) } as unknown as GateCheck;
2682
+ await emitGateStep(at.events?.emit, { op: at.op, gate: d.gate }, async () => waiting, () =>
2683
+ 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 })}`,
2684
+ );
2685
+ }
2686
+ const read = readWaveOutputs(at.outputsFile);
2687
+ let changeSet: PrPlanSet["doc"] | undefined;
2688
+ try {
2689
+ changeSet = (JSON.parse(readFileSync(join(cwd, opWavePlansPath(spec, at.k)), "utf8")) as { changeSet?: PrPlanSet["doc"] }).changeSet;
2690
+ } catch {
2691
+ // The wave stopped before it planned.
2692
+ }
2693
+ return { exitCode, applied: result.applied, failed: result.failed, entry, outputs: "error" in read ? {} : read.outputs, ...(changeSet ? { changeSet } : {}), ...(refused.stop ? { review: refused.stop } : {}) };
2694
+ }
2695
+
2104
2696
  /** A wave's new plan (#4003), beside the report as `change-set-wave-<k>.json`, for whoever approves its gate. */
2105
2697
  function writeWaveChangeSet(ctx: CommandContext, wave: number, doc: PrPlanSet["doc"], upload?: PrReportUpload): void {
2106
2698
  const dir = resolve(ctx.args.output ?? PR_REPORT_DIR);
@@ -2124,6 +2716,7 @@ function writeWaveChangeSet(ctx: CommandContext, wave: number, doc: PrPlanSet["d
2124
2716
  */
2125
2717
  export async function runComponentsPrPost(ctx: CommandContext): Promise<number> {
2126
2718
  const { args } = ctx;
2719
+ if (args.stale) return runComponentsPrPostStale(ctx);
2127
2720
  if (args.open) return runComponentsPrPostOpen(ctx);
2128
2721
  if (args.pr === undefined) return fail("pr-post needs the pull or merge request: --pr <n>");
2129
2722
  if (!args.head || !/^[0-9a-f]{40}$/.test(args.head)) return fail("pr-post needs the full commit the plan job checked out: --head <sha>");
@@ -2138,6 +2731,8 @@ export async function runComponentsPrPost(ctx: CommandContext): Promise<number>
2138
2731
  }
2139
2732
  const { postPlanReport } = await import("../../pr-post");
2140
2733
  const member = args.members?.[0];
2734
+ const description = await descriptionCheckOf(ctx, forge);
2735
+ if (typeof description === "number") return description;
2141
2736
  const posted = await postPlanReport({
2142
2737
  forge,
2143
2738
  dir: resolve(args.output ?? PR_REPORT_DIR),
@@ -2148,6 +2743,10 @@ export async function runComponentsPrPost(ctx: CommandContext): Promise<number>
2148
2743
  ...(args.planResult ? { result: args.planResult } : {}),
2149
2744
  // #4289: the plan job could not ask the forge, so the note job does, from the Ops at the commit it checked out.
2150
2745
  overdue: () => overdueOps(forge, member),
2746
+ ...(description ? { description } : {}),
2747
+ // #4628: the target branch's commit for the note's tip line, and the job summary where the forge keeps one.
2748
+ ...(args.tip ? { baseTip: args.tip } : {}),
2749
+ ...(args.forge !== "gitlab" && process.env.GITHUB_STEP_SUMMARY ? { summaryFile: process.env.GITHUB_STEP_SUMMARY } : {}),
2151
2750
  });
2152
2751
  for (const message of posted.warnings) console.error(formatWarning({ message }));
2153
2752
  if (posted.refused) console.error(formatWarning({ message: `the plan report was not used: ${posted.refused}` }));
@@ -2155,6 +2754,76 @@ export async function runComponentsPrPost(ctx: CommandContext): Promise<number>
2155
2754
  return 0;
2156
2755
  }
2157
2756
 
2757
+ /**
2758
+ * The description check pr-post runs after the note (#4629), when the
2759
+ * responses turn it on (`--respond description=check`, or `CHANT_RESPOND`):
2760
+ * the `decide.backends` entry `--decide-backend` names, from chant.config
2761
+ * at the commit this job checked out (the target branch's, never the pull
2762
+ * request's), and the model `--decide-model` pins. On with no backend is
2763
+ * refused, so a pipeline that asks for the check learns it never ran.
2764
+ */
2765
+ async function descriptionCheckOf(ctx: CommandContext, forge: PrForge): Promise<((report: PrReport) => Promise<void>) | undefined | number> {
2766
+ const { parseRespondList, resolveResponses } = await import("../../ci-respond");
2767
+ const given = ctx.args.respond ? parseRespondList(ctx.args.respond) : {};
2768
+ if ("error" in given) return fail(given.error);
2769
+ if (resolveResponses(given, process.env, (m) => console.error(formatWarning({ message: m }))).description !== "check") return undefined;
2770
+ const name = ctx.args.decideBackend;
2771
+ if (!name || !ctx.args.decideModel) return fail("the description check asks a decide service, so it needs --decide-backend <name> and --decide-model <id>", "Name a decide.backends entry of chant.config, or turn the check off: --respond description=off");
2772
+ const { loadChantConfig } = await import("../../config");
2773
+ let backend;
2774
+ try {
2775
+ const loaded = await loadChantConfig(process.cwd());
2776
+ backend = loaded.config.decide?.backends?.[name];
2777
+ } catch (err) {
2778
+ return fail(`could not read decide.backends from chant.config: ${err instanceof Error ? err.message : String(err)}`);
2779
+ }
2780
+ if (!backend) return fail(`the description check names the backend ${name}, and chant.config has no decide.backends.${name}`);
2781
+ const { backendDescriptionAsk, respondDescription } = await import("../../ci-respond-run");
2782
+ const ask = backendDescriptionAsk(backend, { name, model: ctx.args.decideModel, cwd: process.cwd() });
2783
+ return async (report) => {
2784
+ await respondDescription(forge, report, { ask });
2785
+ };
2786
+ }
2787
+
2788
+ /**
2789
+ * `pr-post --stale --tip <sha> --env <env> --forge <kind> [--branch <branch>]
2790
+ * [--member <name>] [--preview-comment]` (#4628): after a push to the target
2791
+ * branch, mark each open pull request's note that was posted against
2792
+ * another commit stale, naming the comment that previews again with
2793
+ * `--preview-comment`, and set its plan status back to pending
2794
+ * (`markStaleNotes`, ../../pr-post.ts). The branch is `--branch`, else the
2795
+ * job's (`GITHUB_REF_NAME`, `CI_COMMIT_BRANCH`). It exits 0 once it has
2796
+ * marked, as `pr-post` does.
2797
+ */
2798
+ async function runComponentsPrPostStale(ctx: CommandContext): Promise<number> {
2799
+ const { args } = ctx;
2800
+ if (args.pr !== undefined || args.head) return fail("pr-post --stale finds each open pull request and its head itself, so it takes no --pr or --head");
2801
+ if (!args.tip) return fail("pr-post --stale needs the target branch's commit now: --tip <sha>");
2802
+ if (!args.env) return fail("pr-post needs the environment the plan was for: --env <env>");
2803
+ if (!args.forge || !(FORGE_KINDS as readonly string[]).includes(args.forge)) return fail(`pr-post posts to a forge: --forge ${FORGE_KINDS.join("|")}`);
2804
+ if (args.members && args.members.length > 1) return fail(`pr-post takes one --member, not ${args.members.join(", ")}`);
2805
+ const branch = args.branch ?? process.env.CI_COMMIT_BRANCH ?? process.env.GITHUB_REF_NAME;
2806
+ if (!branch) return fail("pr-post --stale marks the notes of the pull requests into a branch: run it in a job of a push, or pass --branch <branch>");
2807
+ let forge: PrForge;
2808
+ try {
2809
+ forge = forgeFromEnv(args.forge as ForgeKind);
2810
+ } catch (err) {
2811
+ return fail(err instanceof Error ? err.message : String(err));
2812
+ }
2813
+ const member = args.members?.[0];
2814
+ const { markStaleNotes } = await import("../../pr-post");
2815
+ let done: Awaited<ReturnType<typeof markStaleNotes>>;
2816
+ try {
2817
+ done = await markStaleNotes({ forge, branch, tip: args.tip, env: args.env, ...(member ? { member } : {}), ...(args.previewComment ? { previewComment: true } : {}) });
2818
+ } catch (err) {
2819
+ return fail(err instanceof Error ? err.message : String(err));
2820
+ }
2821
+ for (const message of done.warnings) console.error(formatWarning({ message }));
2822
+ const marked = done.marks.filter((m) => m.marked).map((m) => `#${m.pr}`);
2823
+ console.error(formatInfo(`pr-post --stale: ${marked.length > 0 ? `marked ${marked.join(", ")} stale` : "no note to mark"} after ${branch} moved to ${args.tip.slice(0, 12)}`));
2824
+ return 0;
2825
+ }
2826
+
2158
2827
  /**
2159
2828
  * `pr-post --open` (#4328): in a pipeline of the target branch on GitLab,
2160
2829
  * post the plan note and status of every open merge request into it whose
@@ -2182,6 +2851,8 @@ async function runComponentsPrPostOpen(ctx: CommandContext): Promise<number> {
2182
2851
  const top = spawnSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf-8" });
2183
2852
  if (top.status !== 0) return fail("pr-post --open reads the plan report's path from the repository root, and this directory is not in a git repository");
2184
2853
  const member = args.members?.[0];
2854
+ const description = await descriptionCheckOf(ctx, forge);
2855
+ if (typeof description === "number") return description;
2185
2856
  const artifactDir = relative(realpathSync(top.stdout.trim()), resolve(args.output ?? PR_REPORT_DIR)).split(sep).join("/");
2186
2857
  const { postOpenPlanReports } = await import("../../pr-post");
2187
2858
  const { gitlabPlanJobName } = await import("../../components/pr-pipeline");
@@ -2196,6 +2867,9 @@ async function runComponentsPrPostOpen(ctx: CommandContext): Promise<number> {
2196
2867
  ...(member ? { member } : {}),
2197
2868
  // #4289: the Ops at the commit this pipeline checked out, the target branch's.
2198
2869
  overdue: () => overdueOps(forge, member),
2870
+ ...(description ? { description } : {}),
2871
+ // #4628: the target branch's commit this pipeline runs at, which each note's tip line names.
2872
+ ...(args.tip ? { baseTip: args.tip } : {}),
2199
2873
  });
2200
2874
  } catch (err) {
2201
2875
  return fail(err instanceof Error ? err.message : String(err));