@intentius/chant 0.124.109 → 0.124.110

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 (338) hide show
  1. package/dist/__golden__/wave-loop/fan-out-applied.json +12 -6
  2. package/dist/__golden__/wave-loop/fan-out-apply-fails.json +8 -4
  3. package/dist/__golden__/wave-loop/fan-out-gated.json +4 -2
  4. package/dist/__golden__/wave-loop/fan-out-no-members.json +16 -8
  5. package/dist/__golden__/wave-loop/fan-out-plan-fails.json +8 -4
  6. package/dist/__golden__/wave-loop/fan-out-same-root.json +4 -2
  7. package/dist/agent-facts.d.ts +130 -0
  8. package/dist/agent-facts.js +196 -0
  9. package/dist/change-risk.d.ts +216 -0
  10. package/dist/change-risk.js +304 -0
  11. package/dist/change-set.d.ts +8 -0
  12. package/dist/ci-agent-alert.d.ts +139 -0
  13. package/dist/ci-agent-alert.js +342 -0
  14. package/dist/ci-agent-triggers.d.ts +152 -0
  15. package/dist/ci-agent-triggers.js +232 -0
  16. package/dist/ci-agent-verify-failed.d.ts +149 -0
  17. package/dist/ci-agent-verify-failed.js +191 -0
  18. package/dist/ci-agent.d.ts +136 -8
  19. package/dist/ci-agent.js +353 -26
  20. package/dist/ci-comment-commands.d.ts +8 -0
  21. package/dist/ci-comment-commands.js +17 -1
  22. package/dist/ci-comment-reject.d.ts +70 -0
  23. package/dist/ci-comment-reject.js +135 -0
  24. package/dist/ci-comment-replies.d.ts +3 -1
  25. package/dist/ci-comment-replies.js +6 -0
  26. package/dist/ci-estate/delivery.d.ts +25 -3
  27. package/dist/ci-estate/delivery.js +28 -9
  28. package/dist/ci-estate/page.d.ts +7 -3
  29. package/dist/ci-estate/page.js +19 -4
  30. package/dist/ci-estate/rows.d.ts +14 -2
  31. package/dist/ci-estate/rows.js +9 -1
  32. package/dist/ci-estate.d.ts +5 -2
  33. package/dist/ci-estate.js +3 -2
  34. package/dist/ci-handover.d.ts +2 -7
  35. package/dist/ci-handover.js +3 -20
  36. package/dist/ci-jobs.d.ts +6 -0
  37. package/dist/ci-jobs.js +17 -0
  38. package/dist/ci-note-commands.d.ts +2 -0
  39. package/dist/ci-note-commands.js +12 -1
  40. package/dist/ci-product-words.d.ts +151 -1
  41. package/dist/ci-product-words.js +1390 -3
  42. package/dist/ci-product.d.ts +100 -4
  43. package/dist/ci-product.js +99 -3
  44. package/dist/ci-respond-run.d.ts +9 -0
  45. package/dist/ci-respond-run.js +35 -4
  46. package/dist/ci-respond-summary-env.d.ts +56 -0
  47. package/dist/ci-respond-summary-env.js +81 -0
  48. package/dist/ci-respond-summary.d.ts +103 -0
  49. package/dist/ci-respond-summary.js +243 -0
  50. package/dist/ci-respond.d.ts +4 -2
  51. package/dist/ci-respond.js +4 -2
  52. package/dist/cli/command-group.js +1 -1
  53. package/dist/cli/commands/lint.js +21 -3
  54. package/dist/cli/handlers/agent.js +49 -4
  55. package/dist/cli/handlers/approve.js +3 -1
  56. package/dist/cli/handlers/build.d.ts +97 -1
  57. package/dist/cli/handlers/build.js +251 -3
  58. package/dist/cli/handlers/fan-out.js +55 -0
  59. package/dist/cli/handlers/graph.d.ts +14 -0
  60. package/dist/cli/handlers/graph.js +58 -3
  61. package/dist/cli/handlers/lifecycle-health.d.ts +7 -0
  62. package/dist/cli/handlers/lifecycle-health.js +47 -9
  63. package/dist/cli/handlers/lifecycle.js +4 -1
  64. package/dist/cli/handlers/notify-relay.d.ts +2 -2
  65. package/dist/cli/handlers/notify-relay.js +67 -7
  66. package/dist/cli/handlers/pipeline-agent.d.ts +30 -0
  67. package/dist/cli/handlers/pipeline-agent.js +255 -0
  68. package/dist/cli/handlers/pipeline-artifacts.d.ts +39 -0
  69. package/dist/cli/handlers/pipeline-artifacts.js +203 -0
  70. package/dist/cli/handlers/pipeline.d.ts +16 -0
  71. package/dist/cli/handlers/pipeline.js +112 -0
  72. package/dist/cli/handlers/pr-comment.js +4 -0
  73. package/dist/cli/handlers/pr-notes.js +4 -1
  74. package/dist/cli/handlers/pr.d.ts +20 -0
  75. package/dist/cli/handlers/pr.js +114 -11
  76. package/dist/cli/handlers/promote.js +792 -47
  77. package/dist/cli/handlers/reject.d.ts +84 -0
  78. package/dist/cli/handlers/reject.js +216 -0
  79. package/dist/cli/handlers/replan.d.ts +54 -0
  80. package/dist/cli/handlers/replan.js +177 -0
  81. package/dist/cli/handlers/run-generate.d.ts +5 -0
  82. package/dist/cli/handlers/run-generate.js +31 -4
  83. package/dist/cli/handlers/run-wave.js +15 -2
  84. package/dist/cli/handlers/run.js +4 -2
  85. package/dist/cli/handlers/stage.d.ts +35 -0
  86. package/dist/cli/handlers/stage.js +90 -0
  87. package/dist/cli/lsp/server.js +4 -0
  88. package/dist/cli/main.js +88 -8
  89. package/dist/cli/parse-args.js +35 -2
  90. package/dist/cli/registry.d.ts +12 -0
  91. package/dist/components/auto-release.d.ts +2 -0
  92. package/dist/components/auto-release.js +1 -0
  93. package/dist/components/capability.d.ts +40 -0
  94. package/dist/components/cli-support.d.ts +21 -1
  95. package/dist/components/cli-support.js +28 -6
  96. package/dist/components/component.d.ts +23 -4
  97. package/dist/components/component.schema.json +28 -0
  98. package/dist/components/declared-reads.d.ts +44 -4
  99. package/dist/components/declared-reads.js +80 -3
  100. package/dist/components/discover.d.ts +8 -0
  101. package/dist/components/discover.js +1 -1
  102. package/dist/components/driver.d.ts +13 -0
  103. package/dist/components/driver.js +23 -2
  104. package/dist/components/environment-sets.d.ts +229 -0
  105. package/dist/components/environment-sets.js +338 -0
  106. package/dist/components/fan-out-canary.d.ts +47 -0
  107. package/dist/components/fan-out-canary.js +58 -0
  108. package/dist/components/fan-out-run.d.ts +17 -0
  109. package/dist/components/fan-out-run.js +14 -1
  110. package/dist/components/fan-out-support.d.ts +7 -0
  111. package/dist/components/fan-out-support.js +1 -1
  112. package/dist/components/groups.d.ts +8 -1
  113. package/dist/components/groups.js +19 -1
  114. package/dist/components/index.d.ts +5 -2
  115. package/dist/components/index.js +4 -1
  116. package/dist/components/pr-cost.d.ts +28 -0
  117. package/dist/components/pr-cost.js +53 -0
  118. package/dist/components/pr-pipeline.d.ts +33 -0
  119. package/dist/components/pr-pipeline.js +32 -5
  120. package/dist/components/pr-policy.d.ts +33 -2
  121. package/dist/components/pr-policy.js +5 -2
  122. package/dist/components/pr-risk.d.ts +42 -0
  123. package/dist/components/pr-risk.js +74 -0
  124. package/dist/components/product-pipeline.d.ts +43 -0
  125. package/dist/components/product-pipeline.js +67 -1
  126. package/dist/components/promote.d.ts +6 -0
  127. package/dist/components/promote.js +13 -0
  128. package/dist/components/release-compile.js +3 -1
  129. package/dist/components/release-gate.d.ts +6 -1
  130. package/dist/components/release-gate.js +10 -2
  131. package/dist/components/step-environments.d.ts +236 -0
  132. package/dist/components/step-environments.js +392 -0
  133. package/dist/components/upstream-replan.d.ts +201 -0
  134. package/dist/components/upstream-replan.js +249 -0
  135. package/dist/components/verify-step.d.ts +30 -0
  136. package/dist/components/verify-step.js +27 -0
  137. package/dist/components/wave-plan.js +6 -2
  138. package/dist/config-environments.d.ts +4 -2
  139. package/dist/control/dispatch.d.ts +15 -0
  140. package/dist/control/dispatch.js +28 -4
  141. package/dist/cost-estimate.d.ts +188 -0
  142. package/dist/cost-estimate.js +363 -0
  143. package/dist/drift-record.d.ts +36 -0
  144. package/dist/drift-record.js +44 -0
  145. package/dist/engine-facts.d.ts +105 -0
  146. package/dist/engine-facts.js +111 -0
  147. package/dist/exit-codes.d.ts +4 -3
  148. package/dist/exit-codes.js +4 -3
  149. package/dist/flag-params.d.ts +2 -2
  150. package/dist/flag-params.js +9 -4
  151. package/dist/floor-table.data.js +53 -0
  152. package/dist/forge-token-vars.d.ts +12 -0
  153. package/dist/forge-token-vars.js +25 -0
  154. package/dist/gate-decision.d.ts +3 -1
  155. package/dist/gate-decision.js +3 -1
  156. package/dist/gated-waves.d.ts +2 -0
  157. package/dist/gated-waves.js +1 -0
  158. package/dist/graph-ir.d.ts +30 -0
  159. package/dist/graph-ir.js +33 -1
  160. package/dist/graph-refs.d.ts +26 -0
  161. package/dist/graph-refs.js +34 -3
  162. package/dist/graph-schema/graph.schema.json +136 -0
  163. package/dist/health.d.ts +65 -0
  164. package/dist/health.js +62 -0
  165. package/dist/lexicon.d.ts +188 -1
  166. package/dist/lifecycle/disruption.d.ts +14 -1
  167. package/dist/lifecycle/disruption.js +5 -1
  168. package/dist/lifecycle/gate-change-set.d.ts +8 -0
  169. package/dist/lifecycle/gate-change-set.js +2 -1
  170. package/dist/lifecycle/gate-ledger.d.ts +26 -0
  171. package/dist/lifecycle/gate-rejection.d.ts +82 -0
  172. package/dist/lifecycle/gate-rejection.js +93 -0
  173. package/dist/lifecycle/gate-seal.d.ts +3 -3
  174. package/dist/lifecycle/gate-seal.js +5 -5
  175. package/dist/lifecycle/observe.d.ts +17 -0
  176. package/dist/lifecycle/observe.js +10 -1
  177. package/dist/lifecycle/release-cut.js +4 -0
  178. package/dist/lifecycle/release-ledger.d.ts +8 -0
  179. package/dist/lifecycle/release-risk.d.ts +137 -0
  180. package/dist/lifecycle/release-risk.js +214 -0
  181. package/dist/lifecycle/release-store.d.ts +9 -0
  182. package/dist/lifecycle/release-store.js +4 -0
  183. package/dist/lifecycle/stage-log.d.ts +85 -0
  184. package/dist/lifecycle/stage-log.js +141 -0
  185. package/dist/lint/canary-checks.d.ts +31 -0
  186. package/dist/lint/canary-checks.js +45 -0
  187. package/dist/lint/rule.d.ts +1 -0
  188. package/dist/lint/rules/evl012-pipeline-fold.d.ts +14 -0
  189. package/dist/lint/rules/evl012-pipeline-fold.js +30 -0
  190. package/dist/lint/rules/index.d.ts +1 -0
  191. package/dist/lint/rules/index.js +3 -0
  192. package/dist/notify-relay-repo.d.ts +54 -0
  193. package/dist/notify-relay-repo.js +84 -0
  194. package/dist/notify-relay.d.ts +53 -3
  195. package/dist/notify-relay.js +96 -3
  196. package/dist/notify.d.ts +57 -1
  197. package/dist/notify.js +7 -1
  198. package/dist/notify.schema.json +61 -3
  199. package/dist/observation.d.ts +34 -0
  200. package/dist/observation.js +14 -1
  201. package/dist/op/activities/review-agent.d.ts +39 -2
  202. package/dist/op/activities/review-agent.js +88 -5
  203. package/dist/op/agent-permit.d.ts +88 -0
  204. package/dist/op/agent-permit.js +97 -0
  205. package/dist/op/gate-approval-base.d.ts +8 -0
  206. package/dist/op/gate-approval-base.js +9 -0
  207. package/dist/op/gate-approval.d.ts +30 -1
  208. package/dist/op/gate-approval.js +23 -2
  209. package/dist/op/gate-quorum.d.ts +114 -8
  210. package/dist/op/gate-quorum.js +198 -21
  211. package/dist/op/gate-reject.d.ts +79 -0
  212. package/dist/op/gate-reject.js +96 -0
  213. package/dist/op/gate-summary.js +1 -1
  214. package/dist/op/gate.d.ts +28 -3
  215. package/dist/op/gate.js +55 -13
  216. package/dist/op/generate-pipeline.d.ts +15 -1
  217. package/dist/op/generate-pipeline.js +32 -5
  218. package/dist/op/index.d.ts +11 -6
  219. package/dist/op/index.js +10 -5
  220. package/dist/op/local-executor.d.ts +2 -0
  221. package/dist/op/local-executor.js +23 -4
  222. package/dist/op/op-waves-after-plan.d.ts +23 -0
  223. package/dist/op/op-waves-after-plan.js +12 -1
  224. package/dist/op/op-waves-capability-spec.d.ts +14 -0
  225. package/dist/op/op-waves-capability-spec.js +46 -6
  226. package/dist/op/op-waves-capability.d.ts +21 -13
  227. package/dist/op/op-waves-capability.js +22 -59
  228. package/dist/op/op-waves-environment-sets.d.ts +41 -0
  229. package/dist/op/op-waves-environment-sets.js +82 -0
  230. package/dist/op/op-waves-quorum-warnings.d.ts +53 -0
  231. package/dist/op/op-waves-quorum-warnings.js +90 -0
  232. package/dist/op/op-waves-release-port.d.ts +7 -0
  233. package/dist/op/op-waves-release-port.js +15 -3
  234. package/dist/op/op-waves-release.d.ts +15 -0
  235. package/dist/op/op-waves-release.js +15 -0
  236. package/dist/op/op-waves-run.d.ts +37 -3
  237. package/dist/op/op-waves-run.js +141 -18
  238. package/dist/op/op-waves-soak.d.ts +57 -0
  239. package/dist/op/op-waves-soak.js +111 -0
  240. package/dist/op/op-waves-split.d.ts +4 -0
  241. package/dist/op/op-waves-split.js +4 -0
  242. package/dist/op/op-waves.d.ts +67 -4
  243. package/dist/op/op-waves.js +71 -3
  244. package/dist/pipeline/agent-ajv.d.ts +4 -0
  245. package/dist/pipeline/agent-ajv.js +14 -0
  246. package/dist/pipeline/agent-steps.d.ts +329 -0
  247. package/dist/pipeline/agent-steps.js +602 -0
  248. package/dist/pipeline/artifacts.d.ts +264 -0
  249. package/dist/pipeline/artifacts.js +425 -0
  250. package/dist/pipeline/diff.d.ts +45 -0
  251. package/dist/pipeline/diff.js +177 -0
  252. package/dist/pipeline/fold.d.ts +43 -0
  253. package/dist/pipeline/fold.js +140 -0
  254. package/dist/pipeline/generate.d.ts +52 -0
  255. package/dist/pipeline/generate.js +120 -0
  256. package/dist/pipeline/product.d.ts +225 -0
  257. package/dist/pipeline/product.js +257 -0
  258. package/dist/pipeline/promote.d.ts +404 -0
  259. package/dist/pipeline/promote.js +694 -0
  260. package/dist/pipeline/read.d.ts +37 -0
  261. package/dist/pipeline/read.js +58 -0
  262. package/dist/pipeline/rendered.d.ts +25 -0
  263. package/dist/pipeline/rendered.js +53 -0
  264. package/dist/pipeline/soak-checks.d.ts +80 -0
  265. package/dist/pipeline/soak-checks.js +254 -0
  266. package/dist/pipeline/soak-gate.d.ts +97 -0
  267. package/dist/pipeline/soak-gate.js +176 -0
  268. package/dist/pipeline/soak-sources.d.ts +17 -0
  269. package/dist/pipeline/soak-sources.js +42 -0
  270. package/dist/pipeline/soak.d.ts +260 -0
  271. package/dist/pipeline/soak.js +378 -0
  272. package/dist/pipeline/spec.d.ts +724 -0
  273. package/dist/pipeline/spec.js +567 -0
  274. package/dist/pipeline/stage-ledger.d.ts +187 -0
  275. package/dist/pipeline/stage-ledger.js +185 -0
  276. package/dist/pipeline/stage-waves.d.ts +114 -0
  277. package/dist/pipeline/stage-waves.js +161 -0
  278. package/dist/pipeline/stages.d.ts +64 -0
  279. package/dist/pipeline/stages.js +174 -0
  280. package/dist/pipeline/verify-rollback.d.ts +277 -0
  281. package/dist/pipeline/verify-rollback.js +393 -0
  282. package/dist/pipeline.d.ts +142 -0
  283. package/dist/pipeline.js +143 -0
  284. package/dist/pr-loop.d.ts +22 -0
  285. package/dist/pr-loop.js +8 -0
  286. package/dist/pr-plan-note.d.ts +15 -1
  287. package/dist/pr-plan-note.js +8 -0
  288. package/dist/pr-post.d.ts +31 -0
  289. package/dist/pr-post.js +89 -0
  290. package/dist/release-floors.d.ts +1 -1
  291. package/dist/release-floors.js +1 -1
  292. package/dist/report-store/audit.schema.json +50 -0
  293. package/dist/report-store/dora.schema.json +331 -0
  294. package/dist/report-store/estate.schema.json +96 -0
  295. package/dist/report-store/run.schema.json +14 -0
  296. package/dist/report-store.d.ts +151 -0
  297. package/dist/report-store.js +344 -0
  298. package/dist/run-event.d.ts +7 -2
  299. package/dist/wave-runtime.mjs +458 -404
  300. package/dist/workspace/catalog-edges.js +3 -3
  301. package/dist/workspace/change-set.schema.json +4 -0
  302. package/dist/workspace/ci-cloud-identity.d.ts +4 -0
  303. package/dist/workspace/ci-cloud-identity.js +30 -0
  304. package/dist/workspace/ci-run.js +17 -2
  305. package/dist/workspace/ci-secrets.d.ts +3 -1
  306. package/dist/workspace/ci-secrets.js +7 -1
  307. package/dist/workspace/compose-graph.d.ts +1 -1
  308. package/dist/workspace/compose-graph.js +3 -1
  309. package/dist/workspace/declaration.d.ts +27 -0
  310. package/dist/workspace/declaration.js +35 -0
  311. package/dist/workspace/declaration.schema.json +56 -0
  312. package/dist/workspace/graph-cli.js +26 -0
  313. package/dist/workspace/graph.schema.json +5 -1
  314. package/dist/workspace/identity-gate-rule.d.ts +4 -0
  315. package/dist/workspace/identity-gate-rule.js +2 -2
  316. package/dist/workspace/identity-reject-rule.d.ts +14 -0
  317. package/dist/workspace/identity-reject-rule.js +24 -0
  318. package/dist/workspace/identity.d.ts +3 -0
  319. package/dist/workspace/identity.js +2 -1
  320. package/dist/workspace/nested-graph.js +2 -0
  321. package/dist/workspace/pr-report.schema.json +65 -0
  322. package/dist/workspace/promotion-order.d.ts +19 -4
  323. package/dist/workspace/promotion-order.js +26 -4
  324. package/dist/workspace/release-train.d.ts +14 -0
  325. package/dist/workspace/release-train.js +32 -0
  326. package/dist/workspace/run-event.schema.json +2 -2
  327. package/dist/workspace/stack-read-edges.d.ts +19 -0
  328. package/dist/workspace/stack-read-edges.js +54 -0
  329. package/dist/workspace/status-gates.d.ts +51 -1
  330. package/dist/workspace/status-gates.js +60 -0
  331. package/dist/workspace/status-stages.d.ts +223 -0
  332. package/dist/workspace/status-stages.js +279 -0
  333. package/dist/workspace/status.d.ts +45 -1
  334. package/dist/workspace/status.js +109 -5
  335. package/dist/workspace/status.schema.json +283 -2
  336. package/dist/workspace/trust/seal.d.ts +7 -0
  337. package/dist/workspace/trust/seal.js +9 -0
  338. package/package.json +5 -1
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The canary's soak in a gated-wave fan-out (#5327).
3
+ *
4
+ * `chant components fan-out --canary <component> --wave-gate <gate>` puts
5
+ * the canary components the change selects in wave 1. The soak that holds
6
+ * the waves after it is the soak of the pipeline stage the fan-out runs in
7
+ * (`--env`), read from `.chant/pipeline.ts` at the default branch's tip: the
8
+ * same soak, so no key of its own. Before each wave after the canary
9
+ * plans, the run reads it through gate `<gate>-wave-1-soak` under the
10
+ * `fan-out` op (`waveSoakGate`), with its clock at the end of the canary
11
+ * wave's applies (`WaveRecord.settledAt`). While it holds, the run stops
12
+ * with exit 3, as at a gate nobody approved; running the same command
13
+ * again reads it again, and approving that gate ends it early.
14
+ *
15
+ * A canary wave that applied nothing, or whose record is not at hand,
16
+ * gives the soak no clock, so it holds: a canary that did not land never
17
+ * lets the waves after it through on time alone.
18
+ */
19
+ import { createHash } from "node:crypto";
20
+ import { waveGateName } from "../gated-waves.js";
21
+ import { soakAtGate, waveSoakGate } from "../pipeline/soak-gate.js";
22
+ /** The soak of stage `env` in `pipeline`, the one a fan-out's canary takes; undefined when the stage or its soak is absent. */
23
+ export function fanOutCanarySoakOf(pipeline, env) {
24
+ return pipeline?.stages.find((s) => s.name === env)?.soak;
25
+ }
26
+ /** Whether the plan's first wave is the canary: it holds a component `--canary` named. */
27
+ export function fanOutHasCanaryWave(waves, canary) {
28
+ return (waves[0] ?? []).some((name) => canary.includes(name));
29
+ }
30
+ /** The `waveGate.soak` hook: the canary's soak in front of wave `k`. */
31
+ export function fanOutCanarySoak(input) {
32
+ return async (k) => {
33
+ const record = input.canaryWave();
34
+ const failed = new Set((record?.failed ?? []).map((f) => f.component));
35
+ const applied = record && record.status !== "gated" ? record.components.filter((c) => !failed.has(c)) : [];
36
+ const digest = record?.digest || `sha256:${createHash("sha256").update(JSON.stringify([input.op, input.gate, 1, "no-run"])).digest("hex")}`;
37
+ const outcome = await soakAtGate({
38
+ op: input.op,
39
+ gate: waveSoakGate(waveGateName(input.gate, 1)),
40
+ soak: input.soak,
41
+ stage: input.env,
42
+ holds: `wave ${k}`,
43
+ wave: 1,
44
+ digest,
45
+ subjects: applied.map((c) => ({ member: c, targets: [c], ...(record?.settledAt ? { appliedAt: record.settledAt } : {}) })),
46
+ port: input.port,
47
+ read: input.read,
48
+ now: input.now?.() ?? new Date(),
49
+ ...(input.notify ? { notify: input.notify } : {}),
50
+ });
51
+ if (outcome.passed) {
52
+ for (const line of outcome.lines)
53
+ input.log?.(`wave ${k}: ${line}`);
54
+ return undefined;
55
+ }
56
+ return { message: outcome.message, hint: outcome.hint, ...(outcome.recorded ? { pending: outcome.recorded } : {}) };
57
+ };
58
+ }
@@ -91,6 +91,21 @@ export interface FanOutWaveGate {
91
91
  gate: string;
92
92
  components: readonly string[];
93
93
  }>;
94
+ /**
95
+ * The canary's soak (#5327, `--canary`): read before each wave after the
96
+ * canary wave plans, given that wave's number. The caller reads the
97
+ * canary wave's record (this attempt's, else the one `--resume` carried)
98
+ * through `onWaveSettled`. Held, the run
99
+ * stops there with nothing in that wave or after it applied, as at a gate
100
+ * nobody approved. Absent: no soak.
101
+ */
102
+ soak?: (wave: number) => Promise<FanOutSoakHold | undefined>;
103
+ }
104
+ /** A canary soak that holds a wave (#5327): what the run says, and the soak gate's pending fact when this run recorded it. */
105
+ export interface FanOutSoakHold {
106
+ message: string;
107
+ hint: string;
108
+ pending?: PendingGateRecord;
94
109
  }
95
110
  /** Thrown when `FanOutWaveGate.only` names a wave whose predecessors have not all applied. */
96
111
  export declare class EarlierWaveNotAppliedError extends Error {
@@ -229,6 +244,8 @@ export interface FanOutRunResult {
229
244
  gate?: PendingGateRecord;
230
245
  /** With `waveGate`: each wave this attempt planned, in order, the one it stopped at included. */
231
246
  waves?: WaveRecord[];
247
+ /** With `waveGate.soak` (#5327): the canary soak that stopped the run; `status` is then `gated`. */
248
+ soak?: FanOutSoakHold;
232
249
  /** What {@link FanOutRunOptions.hold} held back, in plan order. Absent when nothing was. */
233
250
  held?: FanOutHeld[];
234
251
  /**
@@ -400,6 +400,7 @@ async function runGatedWaves(plan, active, components, registry, options, waveGa
400
400
  const blockedBy = new Map();
401
401
  const waves = [];
402
402
  let gatedFact;
403
+ let soakHeld;
403
404
  const markBlocked = (root) => {
404
405
  for (const [component, by] of downstreamWithin(components, left, [root])) {
405
406
  if (blockedBy.has(component) || failed.includes(component))
@@ -436,6 +437,15 @@ async function runGatedWaves(plan, active, components, registry, options, waveGa
436
437
  return { end: "stop" };
437
438
  if (runnable.length === 0)
438
439
  return { end: "next" };
440
+ // #5327: the canary's soak holds every wave after the canary, before anything of it plans.
441
+ if (waveGate.soak && waveNum > 1) {
442
+ const held = await waveGate.soak(waveNum);
443
+ if (held) {
444
+ soakHeld = held;
445
+ gatedFact ?? (gatedFact = held.pending);
446
+ return { end: "stop" };
447
+ }
448
+ }
439
449
  const gateName = waveGateName(waveGate.gate, waveNum);
440
450
  const contexts = new Map(runnable.map((name) => [name, fanOutContext(options, name)]));
441
451
  const planned = await Promise.all(runnable.map((name) => planComponent(byName.get(name), contexts.get(name), componentOutputs)));
@@ -583,6 +593,8 @@ async function runGatedWaves(plan, active, components, registry, options, waveGa
583
593
  status: waveFailures.length > 0 ? "failed" : "applied",
584
594
  approvedBy: check.resolution.resolvedBy,
585
595
  ...(waveFailures.length > 0 ? { failed: waveFailures } : {}),
596
+ // #5327: when the wave's applies ended, the clock a canary's soak counts from.
597
+ settledAt: options.now ?? new Date().toISOString(),
586
598
  };
587
599
  waves.push(settled);
588
600
  options.onWaveSettled?.(settled);
@@ -600,7 +612,7 @@ async function runGatedWaves(plan, active, components, registry, options, waveGa
600
612
  .map(([component, by]) => ({ component, reason: "blocked", blockedBy: by }));
601
613
  // #4291: a member of this job's wave that an earlier job's failure blocked fails the job, though the rest of the wave applied.
602
614
  const blockedHere = waveGate.only !== undefined && (plan.waves[waveGate.only - 1] ?? []).some((name) => blockedBy.has(name));
603
- const status = failed.length > 0 || blockedHere ? "fail" : gatedFact ? "gated" : "ok";
615
+ const status = failed.length > 0 || blockedHere ? "fail" : gatedFact || soakHeld ? "gated" : "ok";
604
616
  emit?.({ type: "run-settle", status: status === "fail" ? "failed" : status, durationMs: null });
605
617
  return {
606
618
  // The derivation's waves, not the narrowed re-layering: their numbers name the gates.
@@ -613,5 +625,6 @@ async function runGatedWaves(plan, active, components, registry, options, waveGa
613
625
  componentOutputs,
614
626
  ...(gatedFact ? { gate: gatedFact } : {}),
615
627
  waves,
628
+ ...(soakHeld ? { soak: soakHeld } : {}),
616
629
  };
617
630
  }
@@ -36,6 +36,13 @@ export interface DeriveFanOutOptions {
36
36
  * (`fanOutRegistry`) is built for it.
37
37
  */
38
38
  registry?: CapabilityRegistry;
39
+ /**
40
+ * The environment the fan-out plans or runs in (#5360). Each step's
41
+ * `environments` is resolved for it before the reads and the plan read the
42
+ * steps, a pull request's `pr-<n>` through its template. Absent: the steps
43
+ * are read as declared.
44
+ */
45
+ env?: string;
39
46
  }
40
47
  export interface DerivedFanOut {
41
48
  success: boolean;
@@ -42,7 +42,7 @@ export async function deriveFanOut(options) {
42
42
  const { config } = options.config ? { config: options.config } : await loadChantConfig(options.path);
43
43
  const defaulted = resolved.targets.map((component) => applyConfigDefaults(component, config));
44
44
  // #4466: the reads a capability finds in its steps' files, such as a template's Fn::ImportValue, order and hold like declared ones.
45
- const components = await withDeclaredReads(defaulted, options.registry ?? (await fanOutRegistry(options.path, config)), options.path);
45
+ const components = await withDeclaredReads(defaulted, options.registry ?? (await fanOutRegistry(options.path, config)), options.path, options.env !== undefined ? { env: options.env } : undefined);
46
46
  const signal = componentsForUnits(components, options.units);
47
47
  const plan = planFanOut({
48
48
  components,
@@ -28,7 +28,7 @@
28
28
  import { groupDigest } from "./group-digest.js";
29
29
  export { groupDigest };
30
30
  import { type DriverComponent, type DriverComponentResult } from "./driver.js";
31
- import { type CapabilityPlan, type CapabilityRegistry, type DeployContext, type GroupMemberStatus, type GroupRun } from "./capability.js";
31
+ import { type CapabilityPlan, type CapabilityRegistry, type DeployContext, type GroupMemberStatus, type GroupRun, type ReportedGroupRead } from "./capability.js";
32
32
  import type { FanOutGroup, FanOutGroupFallback, FanOutPlan } from "./fan-out.js";
33
33
  import { type WaveComponentPlan } from "./wave-plan.js";
34
34
  export interface FindComponentGroupsOptions {
@@ -53,6 +53,13 @@ export interface FoundComponentGroups {
53
53
  /** Sorted by component. */
54
54
  fallbacks: FanOutGroupFallback[];
55
55
  }
56
+ /**
57
+ * The reads each capability with `groupReads` reports among every one of
58
+ * `components` whose step it takes (#5345), as {@link reportedReads} asks
59
+ * for a change's: reads that sit in a member's files rather than its step.
60
+ * The steps are read for `env`. A capability that throws reports none.
61
+ */
62
+ export declare function capabilityGroupReads(components: readonly DriverComponent[], registry: CapabilityRegistry, env: string, ctxOf: (component: string) => DeployContext, vars?: Record<string, unknown>): Promise<ReportedGroupRead[]>;
56
63
  /**
57
64
  * The groups among the components of the change (ws-107):
58
65
  *
@@ -25,6 +25,7 @@
25
25
  * {@link planAndRunComponentGroup}: the same groups where a promote under a
26
26
  * release, `components fan-out` and `run --components` run (#4465).
27
27
  */
28
+ import { stepInputForEnvironment } from "./step-environments.js";
28
29
  import { computePlanDigest } from "../lifecycle/plan-digest.js";
29
30
  import { groupDigest } from "./group-digest.js";
30
31
  export { groupDigest };
@@ -214,8 +215,10 @@ function groupMembers(group, byName, registry, ctxOf, outputs) {
214
215
  const at = component ? groupStepOf(component, registry) : undefined;
215
216
  if (!component || !at)
216
217
  throw new Error(`${name} has no ${group.capability} step to plan in its group`);
217
- const { kind: _kind, ...step } = at.step;
218
+ const { kind: _kind, ...declared } = at.step;
218
219
  const base = ctxOf(name);
220
+ // #5360: the step's inputs for this environment.
221
+ const step = stepInputForEnvironment(declared, base.env, { component: name, phase: "deploy", kind: at.step.kind });
219
222
  assertTargetsAccepted(component, registry, base);
220
223
  assertPlanFlagsAccepted(component, registry, base);
221
224
  const reads = groupReadsOf(step, inGroup, name);
@@ -268,6 +271,21 @@ async function reportedReads(order, kindOf, byName, options, ctxOf) {
268
271
  }
269
272
  return out.sort((a, b) => a.reader.localeCompare(b.reader) || a.ref.localeCompare(b.ref) || a.upstream.localeCompare(b.upstream));
270
273
  }
274
+ /**
275
+ * The reads each capability with `groupReads` reports among every one of
276
+ * `components` whose step it takes (#5345), as {@link reportedReads} asks
277
+ * for a change's: reads that sit in a member's files rather than its step.
278
+ * The steps are read for `env`. A capability that throws reports none.
279
+ */
280
+ export async function capabilityGroupReads(components, registry, env, ctxOf, vars) {
281
+ const byName = new Map(components.map((c) => [c.name, c]));
282
+ const kindOf = (name) => {
283
+ const component = byName.get(name);
284
+ return component ? groupStepOf(component, registry)?.kind : undefined;
285
+ };
286
+ const plan = { order: [], waves: [], skipped: [], seeds: [], indeterminate: [], digest: "" };
287
+ return reportedReads(components.map((c) => c.name), kindOf, byName, { components: [...components], plan, registry, env, ...(vars ? { vars } : {}) }, ctxOf);
288
+ }
271
289
  /** `set` with each member after every member of it that it reads or depends on, else in the order of `set`. */
272
290
  function upstreamsFirst(set, upstreams) {
273
291
  const out = [];
@@ -8,7 +8,7 @@ export { type Archetype, type Wiring, type StackOutputReference, type BuildSpec,
8
8
  export { type DiscoveredComponent, type ComponentDiscoveryResult, discoverComponents, } from "./discover.js";
9
9
  export { type ListedComponent, type ListComponentsResult, type DescribedComponent, type DescribeComponentResult, type ComponentGraphResult, type GenerateLexicon, type GenerateComponentsResult, type RunComponentsOptions, type RunComponentsResult, type ResolvedComponentTargets, listComponents, describeComponent, computeComponentGraph, generateComponentsPipeline, runComponents, findComponentGate, resolveComponentTargets, } from "./cli-support.js";
10
10
  export { renderDriverHuman, renderDriverJson } from "./driver-output.js";
11
- export { type Capability, type CapabilityInput, type CapabilityOutput, type DeployContext, type CapabilityGroupOutcome, type CapabilityGroupPlan, type GroupContext, type GroupDrop, type GroupFallback, type GroupMember, type GroupMemberOutcome, type GroupMemberStatus, type GroupRead, type GroupRun, type ReportedGroupRead, type DeclaredRead, type DeclaredReadMember, type DeclaredReadsContext, type DiscoveredRuns, type RunDiscoveryContext, CapabilityRegistry, CapabilityNotImplementedError, } from "./capability.js";
11
+ export { type Capability, type CapabilityInput, type CapabilityOutput, type DeployContext, type CapabilityGroupOutcome, type CapabilityGroupPlan, type GroupContext, type GroupDrop, type GroupFallback, type GroupMember, type GroupMemberOutcome, type GroupMemberStatus, type GroupRead, type GroupRun, type ReportedGroupRead, type DeclaredRead, type MarkedOutputs, type GraphRead, type DeclaredReadMember, type DeclaredReadsContext, type DiscoveredRuns, type RunDiscoveryContext, CapabilityRegistry, CapabilityNotImplementedError, } from "./capability.js";
12
12
  export { coveredRound, normalizePlanShape, PlanShapeMovedError, planShapeCovers, planShapeDifferences, planShapeDigest, shapeFromChangeSet, type CoveredRoundInput, type CoverageSide, type PlanShape, type PlanShapeArtifact, type PlanShapeEntry, type RoundCover, type RoundCoverage, type ShapeReplacement, } from "./covered-round.js";
13
13
  export { checkPlanShapeConformance, planShapeProblems, type PlanShapeConformanceConfig, } from "./plan-shape-conformance.js";
14
14
  export { createCapabilityRegistry, STARTER_VERB_FAMILIES } from "./registry.js";
@@ -19,11 +19,14 @@ export { starterCapabilityPlugin } from "./starter-plugin.js";
19
19
  export * from "./verbs/index.js";
20
20
  export * from "./builders.js";
21
21
  export { type DriverStep, type DriverGate, type DriverPhase, type DriverComponent, type DriverStepRecord, type DriverComponentResult, type DriverRunResult, type ComponentGraph, type InterpretRunOptions, type WiringValue, resolveComponentGraph, resolveWiring, resolveStepInput, collectComponentOutputs, accumulateComponentOutputs, runComponentDeploy, runInterpretDriver, type GateContext, DependencyCycleError, UnknownDependencyError, DriverRunFailure, } from "./driver.js";
22
+ export { STEP_ENVIRONMENTS_KEY, STEP_ENVIRONMENTS_FLOOR, type StepEnvironments, type StepEnvironmentOptions, type StepEnvironmentRefusal, StepEnvironmentRefusedError, hasStepEnvironments, stepEnvironmentNames, stepForEnvironment, environmentEntryName, stepInputForEnvironment, componentForEnvironment, componentsForEnvironment, GATE_ENVIRONMENTS_FLOOR, GATE_ENVIRONMENT_KEYS, type SkippedGate, type SkippedGateAt, type UnknownGateEnvironment, gateEnvironmentNames, gateForEnvironment, skippedGatesOf, unknownGateEnvironments, } from "./step-environments.js";
23
+ export { ENVIRONMENT_SETS_FLOOR, ENV_SET_ENV, ENV_SET_FETCH_ENV, ENV_SET_SCHEMA, type EnvironmentSecretRef, type EnvironmentSet, type EnvironmentSets, type EnvironmentSecretSource, type EnvironmentSetOrigin, type EnvironmentConfigValue, type EnvironmentSecretValue, type ResolvedEnvironmentSet, type EnvironmentSetRecord, type EnvironmentSetForge, type EnvironmentSetJobInputs, EnvironmentSetError, environmentSetsProblems, environmentSecretSource, resolveEnvironmentSet, environmentSetRecord, environmentSetSecretNames, environmentSetFetchLines, environmentSetJobInputs, } from "./environment-sets.js";
22
24
  export { type FanOutRequest, type FanOutPlan, type FanOutGroup, type FanOutGroupFallback, type FanOutSkip, type FanOutSkipReason, type ChangedUnits, type ComponentChangeSignal, type FanOutProgress, planFanOut, componentsForUnits, remainingFanOut, downstreamWithin, UnknownComponentError, } from "./fan-out.js";
23
25
  export { type FindComponentGroupsOptions, type FoundComponentGroups, type ComponentGroupPlan, type ComponentGroupRunResult, findComponentGroups, groupFanOut, narrowGroups, regroupRemaining, groupDigest, bindGroup, planComponentGroup, runComponentGroup, type FormRunGroupsOptions, formRunGroups, componentSetFanOut, planAndRunComponentGroup, WAVE_GATE_FALLBACK, } from "./groups.js";
24
26
  export { type RunGroupReport, type RunGroupsReport, runGroupsReport, renderRunGroups } from "./run-groups.js";
25
27
  export { type FanOutGate, type FanOutRunOptions, type FanOutRunResult, runFanOut, } from "./fan-out-run.js";
26
28
  export { type FanOutGateRef, type FanOutRenderOptions, renderFanOutPlan, renderFanOutHuman, renderFanOutJson, } from "./fan-out-output.js";
27
29
  export { type DeriveFanOutOptions, type DerivedFanOut, deriveFanOut, fanOutRegistry, } from "./fan-out-support.js";
28
- export { applyDeclaredReads, declaredReadsOf, withDeclaredReads, type PlacedRead } from "./declared-reads.js";
30
+ export { applyDeclaredReads, declaredReadsOf, graphReadsOf, withDeclaredReads, GRAPH_READS_FLOOR, type PlacedRead, type PlacedGraphRead } from "./declared-reads.js";
31
+ export { changedOutputs, dependentsOfChange, gitOutputRecordPort, outputDigests, OUTPUT_RECORDS_FILE, parseOutputRecords, readMarkedOutputs, replanAfterApply, replanDescription, replanGate, replanNames, replanNote, upstreamReadsOf, UPSTREAM_REPLAN_FLOOR, type ChangedDependent, type OutputRecord, type OutputRecordPort, type ReplanOptions, type ReplanPlanned, type ReplanPlanner, type ReplanResult, type UpstreamChange, type UpstreamRead, } from "./upstream-replan.js";
29
32
  export { EcsFargateComponent, type EcsFargateComponentConfig, LambdaComponent, type LambdaComponentConfig, SingleHostComposeComponent, type SingleHostComposeComponentConfig, } from "./presets/index.js";
@@ -19,11 +19,14 @@ export { starterCapabilityPlugin } from "./starter-plugin.js";
19
19
  export * from "./verbs/index.js";
20
20
  export * from "./builders.js";
21
21
  export { resolveComponentGraph, resolveWiring, resolveStepInput, collectComponentOutputs, accumulateComponentOutputs, runComponentDeploy, runInterpretDriver, DependencyCycleError, UnknownDependencyError, DriverRunFailure, } from "./driver.js";
22
+ export { STEP_ENVIRONMENTS_KEY, STEP_ENVIRONMENTS_FLOOR, StepEnvironmentRefusedError, hasStepEnvironments, stepEnvironmentNames, stepForEnvironment, environmentEntryName, stepInputForEnvironment, componentForEnvironment, componentsForEnvironment, GATE_ENVIRONMENTS_FLOOR, GATE_ENVIRONMENT_KEYS, gateEnvironmentNames, gateForEnvironment, skippedGatesOf, unknownGateEnvironments, } from "./step-environments.js";
23
+ export { ENVIRONMENT_SETS_FLOOR, ENV_SET_ENV, ENV_SET_FETCH_ENV, ENV_SET_SCHEMA, EnvironmentSetError, environmentSetsProblems, environmentSecretSource, resolveEnvironmentSet, environmentSetRecord, environmentSetSecretNames, environmentSetFetchLines, environmentSetJobInputs, } from "./environment-sets.js";
22
24
  export { planFanOut, componentsForUnits, remainingFanOut, downstreamWithin, UnknownComponentError, } from "./fan-out.js";
23
25
  export { findComponentGroups, groupFanOut, narrowGroups, regroupRemaining, groupDigest, bindGroup, planComponentGroup, runComponentGroup, formRunGroups, componentSetFanOut, planAndRunComponentGroup, WAVE_GATE_FALLBACK, } from "./groups.js";
24
26
  export { runGroupsReport, renderRunGroups } from "./run-groups.js";
25
27
  export { runFanOut, } from "./fan-out-run.js";
26
28
  export { renderFanOutPlan, renderFanOutHuman, renderFanOutJson, } from "./fan-out-output.js";
27
29
  export { deriveFanOut, fanOutRegistry, } from "./fan-out-support.js";
28
- export { applyDeclaredReads, declaredReadsOf, withDeclaredReads } from "./declared-reads.js";
30
+ export { applyDeclaredReads, declaredReadsOf, graphReadsOf, withDeclaredReads, GRAPH_READS_FLOOR } from "./declared-reads.js";
31
+ export { changedOutputs, dependentsOfChange, gitOutputRecordPort, outputDigests, OUTPUT_RECORDS_FILE, parseOutputRecords, readMarkedOutputs, replanAfterApply, replanDescription, replanGate, replanNames, replanNote, upstreamReadsOf, UPSTREAM_REPLAN_FLOOR, } from "./upstream-replan.js";
29
32
  export { EcsFargateComponent, LambdaComponent, SingleHostComposeComponent, } from "./presets/index.js";
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The cost estimate on the pull-request path (#5334): `ci.cost` in the
3
+ * workspace declaration, read at the base the job measures the change from,
4
+ * run by `chant components pr-plan` and `pr-apply` over each planned
5
+ * member's plan document (`artifact.planJson` of `terraform-apply` and
6
+ * `pulumi-up`). The record is `../cost-estimate.ts`'s: the report and the
7
+ * note carry it as `cost`, and the policy reads it as `input.cost`.
8
+ *
9
+ * Reading it at base means a change cannot raise its own `approveAbove` or
10
+ * drop the estimate that would ask for an approval. Like the policy, a base
11
+ * that cannot be read while the checkout names `ci.cost` stops the job.
12
+ */
13
+ import { type CostEstimate, type CostEstimateExec, type CostEstimateSettings, type CostRun } from "../cost-estimate.js";
14
+ import type { PrPlanSet } from "./pr-run.js";
15
+ /** `ci.cost` as read at base. */
16
+ export interface PrLoopCost {
17
+ /** Absent when the declaration at base sets none. */
18
+ settings?: CostEstimateSettings;
19
+ base: string;
20
+ /** A line for the log when no estimate runs because the base has no declaration. */
21
+ note?: string;
22
+ }
23
+ /** The estimate a pull-request job in `cwd` runs, from the declaration at `base`. Throws when the base cannot be read and the checkout names one. */
24
+ export declare function prLoopCostAt(cwd: string, base: string): PrLoopCost;
25
+ /** The members of a planned set as the estimator takes them: each planned member with its capability's artifact, empty when its plan changes nothing. */
26
+ export declare function prCostRuns(set: Pick<PrPlanSet, "doc" | "members" | "plans">): CostRun[];
27
+ /** Price a planned set under `ci.cost` at base. Undefined when the base sets none. */
28
+ export declare function estimatePrSet(read: PrLoopCost, set: Pick<PrPlanSet, "doc" | "members" | "plans">, cwd: string, exec?: CostEstimateExec): CostEstimate | undefined;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The cost estimate on the pull-request path (#5334): `ci.cost` in the
3
+ * workspace declaration, read at the base the job measures the change from,
4
+ * run by `chant components pr-plan` and `pr-apply` over each planned
5
+ * member's plan document (`artifact.planJson` of `terraform-apply` and
6
+ * `pulumi-up`). The record is `../cost-estimate.ts`'s: the report and the
7
+ * note carry it as `cost`, and the policy reads it as `input.cost`.
8
+ *
9
+ * Reading it at base means a change cannot raise its own `approveAbove` or
10
+ * drop the estimate that would ask for an approval. Like the policy, a base
11
+ * that cannot be read while the checkout names `ci.cost` stops the job.
12
+ */
13
+ import { readDeclaration, WorkspaceReadError } from "../workspace/declaration.js";
14
+ import { locateWorkspace } from "../workspace/which-chant.js";
15
+ import { estimateCosts } from "../cost-estimate.js";
16
+ function checkoutNamesCost(cwd) {
17
+ try {
18
+ return readDeclaration(locateWorkspace(cwd).tree).ci?.cost !== undefined;
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ /** The estimate a pull-request job in `cwd` runs, from the declaration at `base`. Throws when the base cannot be read and the checkout names one. */
25
+ export function prLoopCostAt(cwd, base) {
26
+ try {
27
+ const settings = readDeclaration(locateWorkspace(cwd, base).tree).ci?.cost;
28
+ return settings ? { base, settings } : { base };
29
+ }
30
+ catch (err) {
31
+ const missing = err instanceof WorkspaceReadError && (err.code === "declaration-missing" || err.code === "not-a-git-repository");
32
+ const why = err instanceof Error ? err.message : String(err);
33
+ if (checkoutNamesCost(cwd)) {
34
+ if (missing)
35
+ return { base, note: `ci.cost: the base ${base.slice(0, 12)} has no workspace declaration, so the estimate this change declares runs once it merges` };
36
+ throw new Error(`ci.cost is read from the workspace declaration at ${base.slice(0, 12)}, and it could not be read (${why}), so the plan cannot be priced`);
37
+ }
38
+ return { base };
39
+ }
40
+ }
41
+ /** The members of a planned set as the estimator takes them: each planned member with its capability's artifact, empty when its plan changes nothing. */
42
+ export function prCostRuns(set) {
43
+ const changes = new Set(set.doc.entries.map((e) => e.member));
44
+ return set.members
45
+ .filter((m) => m.status === "planned" || m.status === "applied")
46
+ .map((m) => ({ member: m.member, artifact: set.plans[m.component]?.[m.member], empty: !changes.has(m.member) }));
47
+ }
48
+ /** Price a planned set under `ci.cost` at base. Undefined when the base sets none. */
49
+ export function estimatePrSet(read, set, cwd, exec) {
50
+ if (!read.settings)
51
+ return undefined;
52
+ return estimateCosts(read.settings, prCostRuns(set), cwd, exec);
53
+ }
@@ -92,8 +92,11 @@ import type { CloudTradeSpec, PipelineCloudIdentity } from "../ci-identity.js";
92
92
  import { type CiProductWords, type CiProductWordsInput } from "../ci-product-words.js";
93
93
  import type { ControlTarget } from "../control/dispatch.js";
94
94
  import { type CiResponses } from "../ci-respond.js";
95
+ import { type AgentFactsOption } from "../ci-agent-triggers.js";
96
+ import { type WaveSummarySpec } from "../ci-respond-summary-env.js";
95
97
  import type { PipelineEvidence } from "../ci-evidence-jobs.js";
96
98
  import type { PrCheckJobOptions } from "./pr-checks.js";
99
+ import { type EnvironmentSets } from "./environment-sets.js";
97
100
  /** Where both jobs write their reports, kept as a CI artifact. */
98
101
  export declare const PR_LOOP_REPORT_DIR = ".chant/pr";
99
102
  /**
@@ -323,6 +326,18 @@ export interface PrLoopPipelineOptions {
323
326
  * of a forge token is refused.
324
327
  */
325
328
  secrets?: Record<string, string>;
329
+ /**
330
+ * The config and secret sets per environment (#5348,
331
+ * ./environment-sets.ts), resolved for the pipeline's environment. The
332
+ * plan job gets the set's config and its record, and no secret, since it
333
+ * runs the pull request's code. The apply and record jobs get the config,
334
+ * the forge secrets as passed secrets, and the store secrets read after
335
+ * the job's login, with the identity `identity` gives this environment.
336
+ * A set's value replaces a `variables` or `secrets` entry of the same
337
+ * name. An environment the sets do not name is refused. Absent: the jobs
338
+ * get no set.
339
+ */
340
+ environmentSets?: EnvironmentSets;
326
341
  /**
327
342
  * How many members of a wave the plan job plans at once (#4625): `pr-plan
328
343
  * --parallelism <n>`, on the plan and the comment preview. Absent: all of
@@ -367,6 +382,20 @@ export interface PrLoopPipelineOptions {
367
382
  * at its default: neither job sets it.
368
383
  */
369
384
  respond?: CiResponses;
385
+ /**
386
+ * The model run of `wave-refused: summary` (#5335): with that response the
387
+ * apply job carries these settings as `CHANT_WAVE_SUMMARY_*` and the
388
+ * model's key (on GitHub and Forgejo from the secret of its name). Read
389
+ * only with `respond["wave-refused"]: "summary"`.
390
+ */
391
+ waveSummary?: WaveSummarySpec;
392
+ /**
393
+ * The facts the apply job records for an agent (#5357): with this set a
394
+ * failed apply carries `CHANT_AGENT_FACTS` and the relay key (on GitHub
395
+ * and Forgejo from the secret of its name), as a wave job does with the
396
+ * same option. Absent: the job carries neither.
397
+ */
398
+ agentFacts?: AgentFactsOption;
370
399
  /**
371
400
  * The decide service the description check asks (#4629), from
372
401
  * `--decide-backend` and `--decide-model`: the plan-note job passes both
@@ -415,6 +444,10 @@ export interface PrLoopPipelineOptions {
415
444
  export declare function checkJobOptions(checkJob: boolean | PrCheckJobOptions | undefined): PrCheckJobOptions | undefined;
416
445
  /** The `CHANT_RESPOND` value of `respond` (#4629), or undefined when every event is at its default. Throws on a description check with no decide service. */
417
446
  export declare function prLoopRespondEnv(options: Pick<PrLoopPipelineOptions, "respond" | "decide">): Record<string, string>;
447
+ /**
448
+ * The first chant whose pull request loop takes `waveSummary` and `agentFacts` from `chant build --pr-loop` (#5399): `--wave-summary`, `--agent-facts` and `--agent-facts-key-env` put the refused-wave summary's settings and the failed-apply facts' relay key on the apply job, as a wave job carries them.
449
+ */
450
+ export declare const PR_LOOP_AGENT_SETTINGS_FLOOR = "0.124.110";
418
451
  /** The variable the comment preview's plan reads the comment from (#4626); never a shell argument. */
419
452
  export declare const PREVIEW_COMMENT_ENV = "CHANT_PREVIEW_COMMENT";
420
453
  /** Where the pull request loop's jobs run, by stage (#4625). */
@@ -95,6 +95,9 @@ import { layerWaves } from "../gated-waves.js";
95
95
  import { commandWord, commentLine, PRODUCT_ACTION_ENV, PRODUCT_ACTION_EVENT_FLAG, resolveProductWords } from "../ci-product-words.js";
96
96
  import { CHANT_EXIT } from "../exit-codes.js";
97
97
  import { CI_RESPOND_ENV, respondList } from "../ci-respond.js";
98
+ import { opWavesAgentFactsEnv } from "../ci-agent-triggers.js";
99
+ import { waveSummaryJobEnv } from "../ci-respond-summary-env.js";
100
+ import { environmentSetJobInputs, resolveEnvironmentSet } from "./environment-sets.js";
98
101
  /** The variable `chant ci run` reads its runner key from (`RUNNER_KEY_ENV` in ../workspace/ci-green.ts). */
99
102
  const RUNNER_KEY_ENV = "CHANT_RUNNER_KEY";
100
103
  /** Where both jobs write their reports, kept as a CI artifact. */
@@ -153,6 +156,10 @@ export function prLoopRespondEnv(options) {
153
156
  const list = options.respond ? respondList(options.respond) : "";
154
157
  return list ? { [CI_RESPOND_ENV]: list } : {};
155
158
  }
159
+ /**
160
+ * The first chant whose pull request loop takes `waveSummary` and `agentFacts` from `chant build --pr-loop` (#5399): `--wave-summary`, `--agent-facts` and `--agent-facts-key-env` put the refused-wave summary's settings and the failed-apply facts' relay key on the apply job, as a wave job carries them.
161
+ */
162
+ export const PR_LOOP_AGENT_SETTINGS_FLOOR = "0.124.110";
156
163
  /** The variable the comment preview's plan reads the comment from (#4626); never a shell argument. */
157
164
  export const PREVIEW_COMMENT_ENV = "CHANT_PREVIEW_COMMENT";
158
165
  /** The runner of `stage` (#4625): the stage's own, else `default`, else undefined for the forge's default. */
@@ -472,9 +479,22 @@ export function prLoopJobs(forge, env, options = {}, member) {
472
479
  const github = forge !== "gitlab";
473
480
  const buildLines = prLoopBuildLines(env, options);
474
481
  const build = buildLines.length > 0 ? { build: buildLines } : {};
482
+ // #5348: the environment's config and secret set; the plan job gets its config and record alone.
483
+ const set = options.environmentSets ? resolveEnvironmentSet(options.environmentSets, env) : undefined;
484
+ const setInputs = set ? environmentSetJobInputs(set, forge) : undefined;
485
+ // A name the set gives, a secret included, replaces the pipeline's entry in every job, the plan's too.
486
+ const mine = new Set(set ? [...set.config, ...set.secrets].map((v) => v.name) : []);
487
+ const passed = (inputs) => {
488
+ if (!inputs)
489
+ return prLoopPassedEnv(forge, options);
490
+ const keep = (map) => Object.fromEntries(Object.entries(map ?? {}).filter(([k]) => !mine.has(k)));
491
+ return prLoopPassedEnv(forge, { variables: { ...keep(options.variables), ...inputs.variables }, secrets: { ...keep(options.secrets), ...inputs.secrets } });
492
+ };
493
+ const setFetch = setInputs && setInputs.setup.length > 0 ? setInputs.setup : [];
494
+ const withFetch = (setup) => (setup || setFetch.length > 0 ? { setup: [...(setup ?? []), ...setFetch] } : {});
475
495
  // #4625: the caller's variables and passed secrets, in every job that plans or applies.
476
496
  const jobEnv = {
477
- ...prLoopPassedEnv(forge, options),
497
+ ...passed(setInputs),
478
498
  ...(github ? { GITHUB_TOKEN: GITHUB_JOB_TOKEN } : {}),
479
499
  ...(options.events ? { CHANT_RUN_EVENTS_DIR: PR_LOOP_EVENTS_DIR } : {}),
480
500
  };
@@ -505,9 +525,13 @@ export function prLoopJobs(forge, env, options = {}, member) {
505
525
  const runEnv = (env) => (github ? { ...env, [RUNNER_KEY_ENV]: `\${{ secrets.${RUNNER_KEY_ENV} }}` } : env);
506
526
  // #4295: the plan runs the pull request's code, so it gets no forge token. It writes the note and the
507
527
  // status into its report (--no-status), and the plan-note job posts them (prLoopPostJob).
528
+ // #5348: the plan's variables carry the set's config and record, never its secrets.
529
+ const planJobEnv = set
530
+ ? { ...passed(environmentSetJobInputs(set, forge, { secrets: false })), ...(github ? { GITHUB_TOKEN: GITHUB_JOB_TOKEN } : {}), ...(options.events ? { CHANT_RUN_EVENTS_DIR: PR_LOOP_EVENTS_DIR } : {}) }
531
+ : jobEnv;
508
532
  const planEnv = github
509
- ? { BASE_SHA: "${{ github.event.pull_request.base.sha }}", PR_NUMBER: "${{ github.event.pull_request.number }}", ...withoutForgeTokens(jobEnv) }
510
- : { BASE_SHA: "$CI_MERGE_REQUEST_DIFF_BASE_SHA", PR_NUMBER: "$CI_MERGE_REQUEST_IID", ...withoutForgeTokens(jobEnv) };
533
+ ? { BASE_SHA: "${{ github.event.pull_request.base.sha }}", PR_NUMBER: "${{ github.event.pull_request.number }}", ...withoutForgeTokens(planJobEnv) }
534
+ : { BASE_SHA: "$CI_MERGE_REQUEST_DIFF_BASE_SHA", PR_NUMBER: "$CI_MERGE_REQUEST_IID", ...withoutForgeTokens(planJobEnv) };
511
535
  const greenBranch = github ? JSON.stringify(options.branch ?? "main") : options.branch ? JSON.stringify(options.branch) : "$CI_DEFAULT_BRANCH";
512
536
  const applyEnv = github ? { BASE_SHA: "${{ github.event.before }}", ...jobEnv } : { BASE_SHA: "$CI_COMMIT_BEFORE_SHA", ...jobEnv };
513
537
  // #4301: the apply before merge runs in a job of the target branch, whose commit is the base, at the pull request's head.
@@ -527,6 +551,7 @@ export function prLoopJobs(forge, env, options = {}, member) {
527
551
  env: jobEnv,
528
552
  checkout: [greenCheckout(greenBranch)],
529
553
  greenBranch,
554
+ ...withFetch(undefined),
530
555
  ...(applyRunner !== undefined ? { runner: applyRunner } : {}),
531
556
  ...build,
532
557
  run: { command: ciRun("apply").join(" "), env: runEnv(jobEnv) },
@@ -541,12 +566,14 @@ export function prLoopJobs(forge, env, options = {}, member) {
541
566
  ].join(" "),
542
567
  env: earlyEnv,
543
568
  checkout: [pullRequestCheckout(forge)],
569
+ ...withFetch(undefined),
544
570
  ...(applyRunner !== undefined ? { runner: applyRunner } : {}),
545
571
  run: { command: ciRun("apply").join(" "), env: runEnv(earlyEnv) },
546
572
  };
547
573
  const bin = options.words?.bin;
548
574
  // #4629: the apply posts a failed apply's triage and a refused one's diff as CHANT_RESPOND says.
549
- const respondEnv = prLoopRespondEnv(options);
575
+ // #5335: with wave-refused: summary, the model's settings and key too. #5399: with agentFacts, the facts a failed apply records and the relay key.
576
+ const respondEnv = { ...prLoopRespondEnv(options), ...waveSummaryJobEnv(forge, options.respond?.["wave-refused"], options.waveSummary), ...(opWavesAgentFactsEnv(forge, options.agentFacts) ?? {}) };
550
577
  const withRespond = (job) => (Object.keys(respondEnv).length > 0 ? { ...job, env: { ...job.env, ...respondEnv }, run: { ...job.run, env: { ...job.run.env, ...respondEnv } } } : job);
551
578
  return [
552
579
  {
@@ -564,7 +591,7 @@ export function prLoopJobs(forge, env, options = {}, member) {
564
591
  jobName: "record",
565
592
  command: ["chant", "components", "pr-record", "--base", '"$BASE_SHA"', ...common].join(" "),
566
593
  env: applyEnv,
567
- setup: [github ? githubBaseFallback(options.branch) : gitlabBaseFallback(options.branch)],
594
+ ...withFetch([github ? githubBaseFallback(options.branch) : gitlabBaseFallback(options.branch)]),
568
595
  ...build,
569
596
  // The record runs on merge, where the apply would.
570
597
  ...(applyRunner !== undefined ? { runner: applyRunner } : {}),
@@ -22,7 +22,10 @@
22
22
  * applies nothing.
23
23
  *
24
24
  * A policy also reads `input.review` (#4326): the risk the pull request's
25
- * review note names, when the review agent posted one ({@link policyReviewOf}).
25
+ * review note names, when the review agent posted one ({@link policyReviewOf}),
26
+ * `input.cost` (#5334): the plan's cost estimate with `ci.cost` at base
27
+ * (`./pr-cost.ts`), and `input.risk` (#5325): the change risk with `ci.risk`
28
+ * at base (`./pr-risk.ts`).
26
29
  *
27
30
  * `ci.policy.source` (#4613) names a shared repository and ref instead of
28
31
  * the workspace's own directory. The source is named at base, fetched once
@@ -40,10 +43,13 @@ import { type ResolvedGatePolicySource } from "../policy-source.js";
40
43
  import { type GatePolicyExec, type GatePolicySettings, type GatePolicyVerdict } from "../gate-policy.js";
41
44
  import { type PolicyEngineBinaryOptions } from "../policy-engine.js";
42
45
  import type { ChangeSetDocument } from "../change-set.js";
46
+ import type { PolicyCost } from "../cost-estimate.js";
47
+ import type { PolicyAgentAnswer } from "../pipeline/agent-steps.js";
43
48
  import type { GateLedgerPort } from "../op/gate.js";
44
49
  import type { PrPolicyReport } from "../pr-loop.js";
45
50
  import type { PrForge } from "../pr-forge.js";
46
- import { type ReviewRisk } from "../op/activities/review-agent.js";
51
+ import { type ReviewAnswers, type ReviewRisk } from "../op/activities/review-agent.js";
52
+ import type { ChangeRisk } from "../change-risk.js";
47
53
  /** `ci.policy` as read at base. */
48
54
  export interface PrLoopPolicy {
49
55
  /** Absent when the declaration at base sets none. */
@@ -93,6 +99,29 @@ export interface PrPolicyInput {
93
99
  changeSet: ChangeSetDocument;
94
100
  /** What the pull request's review note says (#4326). Absent only when the caller did not look. */
95
101
  review?: PolicyReview;
102
+ /**
103
+ * The plan's cost estimate (#5334), with `ci.cost` at base on the
104
+ * pull-request path, or a wave's `holds.cost`: each member's monthly
105
+ * change, the sum, `approveAbove` and whether the sum is over it. A wave's
106
+ * policy runs once per run and gets that run's figures as `member`.
107
+ * Absent when no estimate is set.
108
+ */
109
+ cost?: PolicyCost;
110
+ /**
111
+ * The change risk (#5325), with `ci.risk` at base on the pull-request path,
112
+ * or a wave's `holds.risk`: the score from 0 to 1, its level, each reason
113
+ * with its weight, and whether a threshold is crossed. Absent when no risk
114
+ * is set. A policy may add holds on it; nothing in it passes a gate.
115
+ */
116
+ risk?: ChangeRisk;
117
+ /**
118
+ * The answers of a stage's agent steps (#5358), by step name, when a
119
+ * promote runs the stage gate's policy: each step's JSON answer with its
120
+ * release, prompt digest, schema digest and cost
121
+ * (`../pipeline/agent-steps.ts`). A model's reading, one fact among the
122
+ * others; a policy can deny or hold on it and never pass a gate with it.
123
+ */
124
+ agent?: Record<string, PolicyAgentAnswer>;
96
125
  }
97
126
  /**
98
127
  * The review agent's finding as a policy reads it, `input.review`. The risk is
@@ -109,6 +138,8 @@ export interface PolicyReview {
109
138
  head: string | null;
110
139
  /** Why nothing was found, for the log. Absent when a review was. */
111
140
  reason?: string;
141
+ /** The review's answers to `ci.risk.questions` (#5325), by id. Absent when none were asked. */
142
+ answers?: ReviewAnswers;
112
143
  }
113
144
  /**
114
145
  * The users the run's own token acts as on GitHub and Forgejo. Only a note one
@@ -22,7 +22,10 @@
22
22
  * applies nothing.
23
23
  *
24
24
  * A policy also reads `input.review` (#4326): the risk the pull request's
25
- * review note names, when the review agent posted one ({@link policyReviewOf}).
25
+ * review note names, when the review agent posted one ({@link policyReviewOf}),
26
+ * `input.cost` (#5334): the plan's cost estimate with `ci.cost` at base
27
+ * (`./pr-cost.ts`), and `input.risk` (#5325): the change risk with `ci.risk`
28
+ * at base (`./pr-risk.ts`).
26
29
  *
27
30
  * `ci.policy.source` (#4613) names a shared repository and ref instead of
28
31
  * the workspace's own directory. The source is named at base, fetched once
@@ -126,7 +129,7 @@ export async function policyReviewOf(forge, pr) {
126
129
  const result = parseReviewResult(note.body);
127
130
  if (!result)
128
131
  return none(`the review note on #${pr} names no head and risk`);
129
- return { found: true, risk: result.risk, head: result.head };
132
+ return { found: true, risk: result.risk, head: result.head, ...(result.answers ? { answers: result.answers } : {}) };
130
133
  }
131
134
  /** The Rego directory a read names: the source's `path`, else `ci.policy.path`, else the default, and whether one was named. */
132
135
  export function prPolicyPath(read) {