@intentius/chant 0.124.108 → 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 (342) 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/release.js +4 -2
  80. package/dist/cli/handlers/replan.d.ts +54 -0
  81. package/dist/cli/handlers/replan.js +177 -0
  82. package/dist/cli/handlers/run-generate.d.ts +5 -0
  83. package/dist/cli/handlers/run-generate.js +31 -4
  84. package/dist/cli/handlers/run-wave.js +15 -2
  85. package/dist/cli/handlers/run.js +4 -2
  86. package/dist/cli/handlers/stage.d.ts +35 -0
  87. package/dist/cli/handlers/stage.js +90 -0
  88. package/dist/cli/lsp/server.js +4 -0
  89. package/dist/cli/main.js +88 -8
  90. package/dist/cli/parse-args.js +35 -2
  91. package/dist/cli/registry.d.ts +12 -0
  92. package/dist/components/auto-release.d.ts +2 -0
  93. package/dist/components/auto-release.js +1 -0
  94. package/dist/components/capability.d.ts +40 -0
  95. package/dist/components/cli-support.d.ts +21 -1
  96. package/dist/components/cli-support.js +28 -6
  97. package/dist/components/component.d.ts +23 -4
  98. package/dist/components/component.schema.json +28 -0
  99. package/dist/components/declared-reads.d.ts +44 -4
  100. package/dist/components/declared-reads.js +80 -3
  101. package/dist/components/discover.d.ts +8 -0
  102. package/dist/components/discover.js +1 -1
  103. package/dist/components/driver.d.ts +13 -0
  104. package/dist/components/driver.js +23 -2
  105. package/dist/components/environment-sets.d.ts +229 -0
  106. package/dist/components/environment-sets.js +338 -0
  107. package/dist/components/fan-out-canary.d.ts +47 -0
  108. package/dist/components/fan-out-canary.js +58 -0
  109. package/dist/components/fan-out-run.d.ts +17 -0
  110. package/dist/components/fan-out-run.js +14 -1
  111. package/dist/components/fan-out-support.d.ts +7 -0
  112. package/dist/components/fan-out-support.js +1 -1
  113. package/dist/components/groups.d.ts +8 -1
  114. package/dist/components/groups.js +19 -1
  115. package/dist/components/index.d.ts +5 -2
  116. package/dist/components/index.js +4 -1
  117. package/dist/components/pr-cost.d.ts +28 -0
  118. package/dist/components/pr-cost.js +53 -0
  119. package/dist/components/pr-pipeline.d.ts +33 -0
  120. package/dist/components/pr-pipeline.js +32 -5
  121. package/dist/components/pr-policy.d.ts +33 -2
  122. package/dist/components/pr-policy.js +5 -2
  123. package/dist/components/pr-risk.d.ts +42 -0
  124. package/dist/components/pr-risk.js +74 -0
  125. package/dist/components/product-pipeline.d.ts +43 -0
  126. package/dist/components/product-pipeline.js +67 -1
  127. package/dist/components/promote.d.ts +6 -0
  128. package/dist/components/promote.js +13 -0
  129. package/dist/components/release-compile.js +3 -1
  130. package/dist/components/release-gate.d.ts +6 -1
  131. package/dist/components/release-gate.js +10 -2
  132. package/dist/components/step-environments.d.ts +236 -0
  133. package/dist/components/step-environments.js +392 -0
  134. package/dist/components/upstream-replan.d.ts +201 -0
  135. package/dist/components/upstream-replan.js +249 -0
  136. package/dist/components/verify-step.d.ts +30 -0
  137. package/dist/components/verify-step.js +27 -0
  138. package/dist/components/wave-plan.js +6 -2
  139. package/dist/config-environments.d.ts +4 -2
  140. package/dist/control/dispatch.d.ts +15 -0
  141. package/dist/control/dispatch.js +28 -4
  142. package/dist/cost-estimate.d.ts +188 -0
  143. package/dist/cost-estimate.js +363 -0
  144. package/dist/drift-record.d.ts +36 -0
  145. package/dist/drift-record.js +44 -0
  146. package/dist/engine-facts.d.ts +105 -0
  147. package/dist/engine-facts.js +111 -0
  148. package/dist/exit-codes.d.ts +4 -3
  149. package/dist/exit-codes.js +4 -3
  150. package/dist/flag-params.d.ts +2 -2
  151. package/dist/flag-params.js +9 -4
  152. package/dist/floor-table.data.js +53 -0
  153. package/dist/forge-token-vars.d.ts +12 -0
  154. package/dist/forge-token-vars.js +25 -0
  155. package/dist/gate-decision.d.ts +3 -1
  156. package/dist/gate-decision.js +3 -1
  157. package/dist/gated-waves.d.ts +2 -0
  158. package/dist/gated-waves.js +1 -0
  159. package/dist/graph-ir.d.ts +30 -0
  160. package/dist/graph-ir.js +33 -1
  161. package/dist/graph-refs.d.ts +26 -0
  162. package/dist/graph-refs.js +34 -3
  163. package/dist/graph-schema/graph.schema.json +136 -0
  164. package/dist/health.d.ts +65 -0
  165. package/dist/health.js +62 -0
  166. package/dist/lexicon.d.ts +188 -1
  167. package/dist/lifecycle/disruption.d.ts +14 -1
  168. package/dist/lifecycle/disruption.js +5 -1
  169. package/dist/lifecycle/gate-change-set.d.ts +8 -0
  170. package/dist/lifecycle/gate-change-set.js +2 -1
  171. package/dist/lifecycle/gate-ledger.d.ts +26 -0
  172. package/dist/lifecycle/gate-rejection.d.ts +82 -0
  173. package/dist/lifecycle/gate-rejection.js +93 -0
  174. package/dist/lifecycle/gate-seal.d.ts +3 -3
  175. package/dist/lifecycle/gate-seal.js +5 -5
  176. package/dist/lifecycle/observe.d.ts +17 -0
  177. package/dist/lifecycle/observe.js +10 -1
  178. package/dist/lifecycle/release-cut.js +4 -0
  179. package/dist/lifecycle/release-ledger.d.ts +8 -0
  180. package/dist/lifecycle/release-risk.d.ts +137 -0
  181. package/dist/lifecycle/release-risk.js +214 -0
  182. package/dist/lifecycle/release-store.d.ts +9 -0
  183. package/dist/lifecycle/release-store.js +4 -0
  184. package/dist/lifecycle/stage-log.d.ts +85 -0
  185. package/dist/lifecycle/stage-log.js +141 -0
  186. package/dist/lint/canary-checks.d.ts +31 -0
  187. package/dist/lint/canary-checks.js +45 -0
  188. package/dist/lint/rule.d.ts +1 -0
  189. package/dist/lint/rules/evl012-pipeline-fold.d.ts +14 -0
  190. package/dist/lint/rules/evl012-pipeline-fold.js +30 -0
  191. package/dist/lint/rules/index.d.ts +1 -0
  192. package/dist/lint/rules/index.js +3 -0
  193. package/dist/notify-relay-repo.d.ts +54 -0
  194. package/dist/notify-relay-repo.js +84 -0
  195. package/dist/notify-relay.d.ts +53 -3
  196. package/dist/notify-relay.js +96 -3
  197. package/dist/notify.d.ts +57 -1
  198. package/dist/notify.js +7 -1
  199. package/dist/notify.schema.json +61 -3
  200. package/dist/observation.d.ts +34 -0
  201. package/dist/observation.js +14 -1
  202. package/dist/op/activities/review-agent.d.ts +39 -2
  203. package/dist/op/activities/review-agent.js +88 -5
  204. package/dist/op/agent-permit.d.ts +88 -0
  205. package/dist/op/agent-permit.js +97 -0
  206. package/dist/op/gate-approval-base.d.ts +8 -0
  207. package/dist/op/gate-approval-base.js +9 -0
  208. package/dist/op/gate-approval.d.ts +30 -1
  209. package/dist/op/gate-approval.js +23 -2
  210. package/dist/op/gate-quorum.d.ts +114 -8
  211. package/dist/op/gate-quorum.js +198 -21
  212. package/dist/op/gate-reject.d.ts +79 -0
  213. package/dist/op/gate-reject.js +96 -0
  214. package/dist/op/gate-summary.js +1 -1
  215. package/dist/op/gate.d.ts +28 -3
  216. package/dist/op/gate.js +55 -13
  217. package/dist/op/generate-pipeline.d.ts +15 -1
  218. package/dist/op/generate-pipeline.js +32 -5
  219. package/dist/op/index.d.ts +11 -6
  220. package/dist/op/index.js +10 -5
  221. package/dist/op/local-executor.d.ts +2 -0
  222. package/dist/op/local-executor.js +23 -4
  223. package/dist/op/op-waves-after-plan.d.ts +23 -0
  224. package/dist/op/op-waves-after-plan.js +12 -1
  225. package/dist/op/op-waves-capability-spec.d.ts +14 -0
  226. package/dist/op/op-waves-capability-spec.js +46 -6
  227. package/dist/op/op-waves-capability.d.ts +21 -13
  228. package/dist/op/op-waves-capability.js +22 -59
  229. package/dist/op/op-waves-environment-sets.d.ts +41 -0
  230. package/dist/op/op-waves-environment-sets.js +82 -0
  231. package/dist/op/op-waves-quorum-warnings.d.ts +53 -0
  232. package/dist/op/op-waves-quorum-warnings.js +90 -0
  233. package/dist/op/op-waves-release-port.d.ts +7 -0
  234. package/dist/op/op-waves-release-port.js +15 -3
  235. package/dist/op/op-waves-release.d.ts +15 -0
  236. package/dist/op/op-waves-release.js +15 -0
  237. package/dist/op/op-waves-run.d.ts +37 -3
  238. package/dist/op/op-waves-run.js +141 -18
  239. package/dist/op/op-waves-soak.d.ts +57 -0
  240. package/dist/op/op-waves-soak.js +111 -0
  241. package/dist/op/op-waves-split.d.ts +4 -0
  242. package/dist/op/op-waves-split.js +4 -0
  243. package/dist/op/op-waves.d.ts +67 -4
  244. package/dist/op/op-waves.js +71 -3
  245. package/dist/pipeline/agent-ajv.d.ts +4 -0
  246. package/dist/pipeline/agent-ajv.js +14 -0
  247. package/dist/pipeline/agent-steps.d.ts +329 -0
  248. package/dist/pipeline/agent-steps.js +602 -0
  249. package/dist/pipeline/artifacts.d.ts +264 -0
  250. package/dist/pipeline/artifacts.js +425 -0
  251. package/dist/pipeline/diff.d.ts +45 -0
  252. package/dist/pipeline/diff.js +177 -0
  253. package/dist/pipeline/fold.d.ts +43 -0
  254. package/dist/pipeline/fold.js +140 -0
  255. package/dist/pipeline/generate.d.ts +52 -0
  256. package/dist/pipeline/generate.js +120 -0
  257. package/dist/pipeline/product.d.ts +225 -0
  258. package/dist/pipeline/product.js +257 -0
  259. package/dist/pipeline/promote.d.ts +404 -0
  260. package/dist/pipeline/promote.js +694 -0
  261. package/dist/pipeline/read.d.ts +37 -0
  262. package/dist/pipeline/read.js +58 -0
  263. package/dist/pipeline/rendered.d.ts +25 -0
  264. package/dist/pipeline/rendered.js +53 -0
  265. package/dist/pipeline/soak-checks.d.ts +80 -0
  266. package/dist/pipeline/soak-checks.js +254 -0
  267. package/dist/pipeline/soak-gate.d.ts +97 -0
  268. package/dist/pipeline/soak-gate.js +176 -0
  269. package/dist/pipeline/soak-sources.d.ts +17 -0
  270. package/dist/pipeline/soak-sources.js +42 -0
  271. package/dist/pipeline/soak.d.ts +260 -0
  272. package/dist/pipeline/soak.js +378 -0
  273. package/dist/pipeline/spec.d.ts +724 -0
  274. package/dist/pipeline/spec.js +567 -0
  275. package/dist/pipeline/stage-ledger.d.ts +187 -0
  276. package/dist/pipeline/stage-ledger.js +185 -0
  277. package/dist/pipeline/stage-waves.d.ts +114 -0
  278. package/dist/pipeline/stage-waves.js +161 -0
  279. package/dist/pipeline/stages.d.ts +64 -0
  280. package/dist/pipeline/stages.js +174 -0
  281. package/dist/pipeline/verify-rollback.d.ts +277 -0
  282. package/dist/pipeline/verify-rollback.js +393 -0
  283. package/dist/pipeline.d.ts +142 -0
  284. package/dist/pipeline.js +143 -0
  285. package/dist/pr-loop.d.ts +22 -0
  286. package/dist/pr-loop.js +8 -0
  287. package/dist/pr-plan-note.d.ts +15 -1
  288. package/dist/pr-plan-note.js +8 -0
  289. package/dist/pr-post.d.ts +31 -0
  290. package/dist/pr-post.js +89 -0
  291. package/dist/release-floors.d.ts +1 -1
  292. package/dist/release-floors.js +1 -1
  293. package/dist/report-store/audit.schema.json +50 -0
  294. package/dist/report-store/dora.schema.json +331 -0
  295. package/dist/report-store/estate.schema.json +96 -0
  296. package/dist/report-store/run.schema.json +14 -0
  297. package/dist/report-store.d.ts +151 -0
  298. package/dist/report-store.js +344 -0
  299. package/dist/run-event.d.ts +7 -2
  300. package/dist/wave-runtime.mjs +458 -404
  301. package/dist/workspace/catalog-edges.js +3 -3
  302. package/dist/workspace/change-set.schema.json +4 -0
  303. package/dist/workspace/ci-cloud-identity.d.ts +4 -0
  304. package/dist/workspace/ci-cloud-identity.js +30 -0
  305. package/dist/workspace/ci-run.js +17 -2
  306. package/dist/workspace/ci-secrets.d.ts +3 -1
  307. package/dist/workspace/ci-secrets.js +7 -1
  308. package/dist/workspace/compose-graph.d.ts +1 -1
  309. package/dist/workspace/compose-graph.js +3 -1
  310. package/dist/workspace/declaration.d.ts +27 -0
  311. package/dist/workspace/declaration.js +35 -0
  312. package/dist/workspace/declaration.schema.json +56 -0
  313. package/dist/workspace/graph-cli.js +26 -0
  314. package/dist/workspace/graph.schema.json +5 -1
  315. package/dist/workspace/identity-gate-rule.d.ts +4 -0
  316. package/dist/workspace/identity-gate-rule.js +2 -2
  317. package/dist/workspace/identity-reject-rule.d.ts +14 -0
  318. package/dist/workspace/identity-reject-rule.js +24 -0
  319. package/dist/workspace/identity.d.ts +3 -0
  320. package/dist/workspace/identity.js +2 -1
  321. package/dist/workspace/nested-graph.js +2 -0
  322. package/dist/workspace/pr-report.schema.json +65 -0
  323. package/dist/workspace/promotion-order.d.ts +19 -4
  324. package/dist/workspace/promotion-order.js +26 -4
  325. package/dist/workspace/release-train.d.ts +14 -0
  326. package/dist/workspace/release-train.js +32 -0
  327. package/dist/workspace/run-event.schema.json +2 -2
  328. package/dist/workspace/stack-read-edges.d.ts +19 -0
  329. package/dist/workspace/stack-read-edges.js +54 -0
  330. package/dist/workspace/status-gates.d.ts +51 -1
  331. package/dist/workspace/status-gates.js +60 -0
  332. package/dist/workspace/status-stages.d.ts +223 -0
  333. package/dist/workspace/status-stages.js +279 -0
  334. package/dist/workspace/status.d.ts +45 -1
  335. package/dist/workspace/status.js +109 -5
  336. package/dist/workspace/status.schema.json +283 -2
  337. package/dist/workspace/train-cut.js +5 -2
  338. package/dist/workspace/train-shell.d.ts +18 -0
  339. package/dist/workspace/train-shell.js +43 -0
  340. package/dist/workspace/trust/seal.d.ts +7 -0
  341. package/dist/workspace/trust/seal.js +9 -0
  342. package/package.json +5 -1
@@ -74,6 +74,11 @@ import { type DriverComponent } from "../../components/driver.js";
74
74
  import { type CapabilityRegistry } from "../../components/capability.js";
75
75
  import type { ComponentEnvironmentDeclaration } from "../../components/component.js";
76
76
  import { type PrHookPlace, type PrLoopHooks } from "../../components/pr-hooks.js";
77
+ import { type PrLoopCost } from "../../components/pr-cost.js";
78
+ import { type CostEstimate } from "../../cost-estimate.js";
79
+ import { type PrLoopRisk } from "../../components/pr-risk.js";
80
+ import type { ChangeRisk } from "../../change-risk.js";
81
+ import type { PolicyReview } from "../../components/pr-policy.js";
77
82
  import { type PrLoopPolicy } from "../../components/pr-policy.js";
78
83
  import type { OpWaveHookMoment } from "../../op/op-waves.js";
79
84
  import type { PrHookOutcome } from "../../pr-loop.js";
@@ -124,6 +129,21 @@ export interface Prepared {
124
129
  policy: PrLoopPolicy;
125
130
  /** What the policy said about the plan, for the report's `policy`. */
126
131
  policyReport?: PrPolicyReport;
132
+ /** `ci.cost` from the declaration at base (#5334). */
133
+ cost: PrLoopCost;
134
+ /** The plan's estimate under it, for the report's `cost` and the policy's `input.cost`. */
135
+ costEstimate?: CostEstimate;
136
+ /** `ci.risk` from the declaration at base (#5325). */
137
+ risk: PrLoopRisk;
138
+ /** The change risk under it, for the report's `risk`, the stored change set and the policy's `input.risk`, with the digest it scored. */
139
+ riskRecord?: {
140
+ digest: string;
141
+ risk: ChangeRisk;
142
+ };
143
+ /** The pull request's review, read once per job. */
144
+ review?: PolicyReview;
145
+ /** The `chant graph` flags the job's graph reads take: its `--param` and `--params-file`. */
146
+ graphArgs: string[];
127
147
  /** `pr-apply --before-merge` (#4301): the requires checks, for the report's `beforeMerge`. */
128
148
  beforeMerge?: PrBeforeMerge;
129
149
  }
@@ -105,6 +105,9 @@ import { PLAN_FLAG_ARGS, PlanFlagRefusedError, TargetsRefusedError } from "../..
105
105
  import { prPlanTargets } from "../../components/pr-targets.js";
106
106
  import { PREVIEW_COMMENT_ENV } from "../../components/pr-pipeline.js";
107
107
  import { prLoopHooksAt, runPrHooks } from "../../components/pr-hooks.js";
108
+ import { estimatePrSet, prLoopCostAt } from "../../components/pr-cost.js";
109
+ import { policyCost, signedAmount } from "../../cost-estimate.js";
110
+ import { prLoopRiskAt, prRiskDependents, scorePrSet } from "../../components/pr-risk.js";
108
111
  import { decidePrPolicyOverride, policyReviewOf, prLoopPolicyAt, preparePrPolicyEngine, prPolicyReport, runPrPolicy, spendPrPolicyOverride } from "../../components/pr-policy.js";
109
112
  import { lexiconNames } from "../../lexicon-module.js";
110
113
  import { actorFromEnv } from "../../actor.js";
@@ -183,6 +186,7 @@ export async function prepare(ctx, stage) {
183
186
  buildParams: paramsResolution.provenance,
184
187
  config,
185
188
  registry,
189
+ env: args.env ?? "local",
186
190
  });
187
191
  }
188
192
  catch (err) {
@@ -225,6 +229,26 @@ export async function prepare(ctx, stage) {
225
229
  }
226
230
  if (policy.note)
227
231
  console.error(formatInfo(policy.note));
232
+ // #5334: the cost estimate, read from the declaration at base like the policy.
233
+ let cost;
234
+ try {
235
+ cost = prLoopCostAt(projectPath, base);
236
+ }
237
+ catch (err) {
238
+ return fail(err instanceof Error ? err.message : String(err));
239
+ }
240
+ if (cost.note)
241
+ console.error(formatInfo(cost.note));
242
+ // #5325: the change risk, read from the declaration at base like the cost.
243
+ let risk;
244
+ try {
245
+ risk = prLoopRiskAt(projectPath, base);
246
+ }
247
+ catch (err) {
248
+ return fail(err instanceof Error ? err.message : String(err));
249
+ }
250
+ if (risk.note)
251
+ console.error(formatInfo(risk.note));
228
252
  const env = args.env ?? "local";
229
253
  const routedAway = member ? await routing(ctx, stage, projectPath, member, base, forge) : undefined;
230
254
  if (routedAway)
@@ -257,6 +281,9 @@ export async function prepare(ctx, stage) {
257
281
  hookOutcomes: [],
258
282
  ...(routedAway ? { routedAway } : {}),
259
283
  policy,
284
+ cost,
285
+ risk,
286
+ graphArgs: [...(args.param ?? []).flatMap((kv) => ["--param", kv]), ...(args.paramsFile ? ["--params-file", args.paramsFile] : [])],
260
287
  };
261
288
  }
262
289
  /** Set where `p`'s hooks run, once the stage knows its op (#4288). */
@@ -668,6 +695,10 @@ async function finish(ctx, p, report, upload) {
668
695
  report = { ...report, message: p.routedAway };
669
696
  if (p.policyReport)
670
697
  report = { ...report, policy: p.policyReport };
698
+ if (p.costEstimate)
699
+ report = { ...report, cost: p.costEstimate };
700
+ if (p.riskRecord && p.riskRecord.digest === report.digest)
701
+ report = { ...report, risk: p.riskRecord.risk };
671
702
  if (p.beforeMerge)
672
703
  report = { ...report, beforeMerge: p.beforeMerge };
673
704
  // #4617: with a checkout of the control repo named, its entries and apply records mark the cross-stack edges.
@@ -731,11 +762,69 @@ function openUpload(events, stage, pr, p) {
731
762
  * read only at the plan stage, and recorded for an override at the apply.
732
763
  */
733
764
  async function judgePolicy(p, at) {
765
+ // #5334: the cost estimate first, so the policy reads it as input.cost. It only ever adds a hold.
766
+ const costHeld = priceSet(p, at.set);
767
+ // #5325: then the change risk, so the policy reads it as input.risk. It only ever adds a hold.
768
+ const risk = await riskOfSet(p, at.set.doc, at.pr);
769
+ const riskHeld = risk?.over ? `the change risk (${risk.score.toFixed(2)}, ${risk.level}) is over ci.risk: ${risk.overBy.join("; ")}, so the plan needs an approval of its own digest` : undefined;
770
+ if (riskHeld)
771
+ console.error(formatInfo(riskHeld));
772
+ const judged = await judgePolicyOnly(p, at);
773
+ const added = [costHeld, riskHeld].filter((w) => w !== undefined);
774
+ if (added.length === 0)
775
+ return judged;
776
+ return { ...judged, held: true, heldBy: [...(judged.heldBy ?? []), ...added] };
777
+ }
778
+ /** The pull request's review, read once per job (#4326). */
779
+ async function reviewOnce(p, pr) {
780
+ p.review ?? (p.review = await policyReviewOf(p.forge, pr));
781
+ return p.review;
782
+ }
783
+ /**
784
+ * The change risk of a planned change set under `ci.risk` at base (#5325),
785
+ * scored once per digest and kept on `p`: the review's level and answers,
786
+ * the new migration files, and the dependents in the member's graph.
787
+ * Undefined when the base sets no `ci.risk`.
788
+ */
789
+ async function riskOfSet(p, doc, pr) {
790
+ if (!p.risk.settings)
791
+ return undefined;
792
+ if (p.riskRecord?.digest === doc.digest)
793
+ return p.riskRecord.risk;
794
+ const review = await reviewOnce(p, pr);
795
+ const migrations = await newMigrations(p);
796
+ const { gateGraphReader } = await import("../../lifecycle/gate-change-set.js");
797
+ const graph = await prRiskDependents(doc, resolve("."), gateGraphReader(p.graphArgs));
798
+ if ("error" in graph)
799
+ console.error(formatInfo(`risk: the graph could not be read, so no dependents count: ${graph.error}`));
800
+ const risk = scorePrSet(p.risk, { doc, env: p.env, review, migrations, ...("dependents" in graph ? { dependents: graph.dependents } : {}) });
801
+ if (!risk)
802
+ return undefined;
803
+ p.riskRecord = { digest: doc.digest, risk };
804
+ console.error(formatInfo(`risk: ${risk.score.toFixed(2)} (${risk.level})`));
805
+ return risk;
806
+ }
807
+ /** Price the planned set under `ci.cost` at base (#5334), keeping the estimate on `p`. The hold's reason when the plan is over `approveAbove`. */
808
+ function priceSet(p, set) {
809
+ const estimate = estimatePrSet(p.cost, set, resolve("."));
810
+ if (!estimate)
811
+ return undefined;
812
+ p.costEstimate = estimate;
813
+ const unpriced = estimate.unestimated.length > 0 ? `; not estimated: ${estimate.unestimated.join(", ")}` : "";
814
+ console.error(formatInfo(`cost (${estimate.estimator}): ${signedAmount(estimate.monthlyDelta, estimate.currency)} a month${unpriced}`));
815
+ if (!estimate.over)
816
+ return undefined;
817
+ const why = `the cost estimate (${signedAmount(estimate.monthlyDelta, estimate.currency)} a month${unpriced}) is over ci.cost.approveAbove (${estimate.approveAbove} ${estimate.currency}), so the plan needs an approval of its own digest`;
818
+ console.error(formatInfo(why));
819
+ return why;
820
+ }
821
+ async function judgePolicyOnly(p, at) {
734
822
  // The review is read only when a policy will run: a workspace with no policy makes no forge call for it.
735
- const review = p.policy.settings ? await policyReviewOf(p.forge, at.pr) : undefined;
823
+ const review = p.policy.settings ? await reviewOnce(p, at.pr) : undefined;
736
824
  // #4774: with ci.policy.install, the engine is fetched here, once, and only for a stage that runs the policy.
737
825
  p.policy = await preparePrPolicyEngine(p.policy);
738
- const verdict = runPrPolicy(p.policy, { version: 1, stage: at.stage, op: at.op, gate: p.gate, env: p.env, pr: at.pr, base: p.base, head: p.head, changeSet: at.set.doc, ...(review ? { review } : {}) });
826
+ const cost = p.costEstimate ? policyCost(p.costEstimate) : undefined;
827
+ const verdict = runPrPolicy(p.policy, { version: 1, stage: at.stage, op: at.op, gate: p.gate, env: p.env, pr: at.pr, base: p.base, head: p.head, changeSet: at.set.doc, ...(review ? { review } : {}), ...(cost ? { cost } : {}), ...(p.riskRecord?.digest === at.set.doc.digest ? { risk: p.riskRecord.risk } : {}) });
739
828
  if (!verdict)
740
829
  return { held: false };
741
830
  const report = prPolicyReport(verdict, p.policy.base);
@@ -749,7 +838,7 @@ async function judgePolicy(p, at) {
749
838
  for (const h of verdict.holds)
750
839
  console.error(formatInfo(`policy holds the plan for a person's approval (${h.rule}): ${h.message}`));
751
840
  if (verdict.result !== "denied")
752
- return { held };
841
+ return held ? { held, heldBy: ["the policy holds this plan for an approval of its own digest"] } : { held };
753
842
  const denied = verdict.denials.map((d) => `${d.rule}: ${d.message}`).join("; ");
754
843
  let decided;
755
844
  try {
@@ -1122,7 +1211,7 @@ async function prApply(ctx, stage, beforeMerge) {
1122
1211
  // #4022: keep the change set the gate binds on chant/lifecycle under its
1123
1212
  // digest before deciding the gate, so the plan an approval bound, or the
1124
1213
  // one a pending fact waits on, can be read once this job is gone.
1125
- await storeChangeSetForGate(ctx, p, set.doc);
1214
+ await storeChangeSetForGate(ctx, p, set.doc, pr);
1126
1215
  let approval;
1127
1216
  let via = "gate";
1128
1217
  // #4294: the policy at base, before the gate. A resume runs under the decision of the attempt it finishes.
@@ -1134,7 +1223,7 @@ async function prApply(ctx, stage, beforeMerge) {
1134
1223
  judged = await judgePolicy(p, { stage: "apply", op, pr, set });
1135
1224
  if (judged.stop)
1136
1225
  return stop(prReport({ ...base, approval: { status: "pending" }, status: "refused", refusal: judged.stop.refusal, message: judged.stop.message }), judged.stop.code);
1137
- const decided = await decideApplyGate(p, { op, pr, set, events, held: judged.held, ...(green ? { green } : {}) });
1226
+ const decided = await decideApplyGate(p, { op, pr, set, events, held: judged.held, ...(judged.heldBy ? { heldBy: judged.heldBy } : {}), ...(green ? { green } : {}) });
1138
1227
  approval = decided.approval;
1139
1228
  // #4323: the after-gate hooks hear the decision, a refusal too; only a failure that would have applied changes the outcome.
1140
1229
  const afterGate = await runGateHook(p, { op, digest: set.doc.digest, satisfied: decided.satisfied }, p.plan.order);
@@ -1712,8 +1801,10 @@ async function decideApplyGate(p, at) {
1712
1801
  let uncovered = [];
1713
1802
  // #4294: a plan the policy holds needs an approval of its own digest, so the merges' approvals do not cover it.
1714
1803
  if (green && at.held) {
1715
- console.error(formatInfo(`the policy holds the plan at ${green.commit.slice(0, 12)}, so it needs an approval of its own digest and does not apply under the merges' approvals`));
1716
- uncovered = ["the policy holds this plan for an approval of its own digest"];
1804
+ // #5334: the cost over ci.cost.approveAbove holds it the same way.
1805
+ const why = at.heldBy?.length ? [...at.heldBy] : ["the policy holds this plan for an approval of its own digest"];
1806
+ console.error(formatInfo(`${why.join("; ")}: the plan at ${green.commit.slice(0, 12)} needs an approval of its own digest and does not apply under the merges' approvals`));
1807
+ uncovered = why;
1717
1808
  }
1718
1809
  else if (green) {
1719
1810
  const cover = coverByMerges(set.doc, green.approved);
@@ -1824,8 +1915,17 @@ async function respondApply(ctx, p, report) {
1824
1915
  console.error(formatWarning({ message: `no response was posted: ${given.error}` }));
1825
1916
  return;
1826
1917
  }
1827
- const { respondPrApply } = await import("../../ci-respond-run.js");
1918
+ const { respondPrApply, triageOfPrReport } = await import("../../ci-respond-run.js");
1828
1919
  await respondPrApply(p.forge, report, given);
1920
+ // #5357: with CHANT_AGENT_FACTS=apply-failed, a failed apply records its facts for the failed-apply agent, beside its triage.
1921
+ const { agentFactsOn, recordApplyFailed } = await import("../../ci-agent-triggers.js");
1922
+ const failed = agentFactsOn(process.env, "apply-failed") ? triageOfPrReport(report) : undefined;
1923
+ if (failed) {
1924
+ const { activeProductWords } = await import("../../ci-product-words.js");
1925
+ const line = await recordApplyFailed(failed, { op: report.op, product: activeProductWords().product });
1926
+ if (line)
1927
+ console.error(line);
1928
+ }
1829
1929
  }
1830
1930
  catch (err) {
1831
1931
  console.error(formatWarning({ message: `the apply's responses were not posted: ${err instanceof Error ? err.message : String(err)}` }));
@@ -1955,7 +2055,10 @@ function emitReviewStop(events, message) {
1955
2055
  * way. A change set that never reaches the remote throws
1956
2056
  * `LifecyclePushLostError`, which stops the stage.
1957
2057
  */
1958
- async function storeChangeSetForGate(ctx, p, doc) {
2058
+ async function storeChangeSetForGate(ctx, p, planned, pr) {
2059
+ // #5325: with ci.risk at base, the change set is stored with its risk record (not part of its digest).
2060
+ const risk = pr !== undefined ? await riskOfSet(p, planned, pr) : undefined;
2061
+ const doc = risk ? { ...planned, risk } : planned;
1959
2062
  const { storeGateChangeSet, gateGraphReader } = await import("../../lifecycle/gate-change-set.js");
1960
2063
  const { pushLifecycleRebasing, LifecyclePushLostError } = await import("../../lifecycle/git.js");
1961
2064
  const graphArgs = [
@@ -2231,12 +2334,12 @@ async function prApplyWaves(ctx, p, at) {
2231
2334
  return stop(report({ status: "plan-failed", message: "The policy denied a member's plan, so nothing was applied." }), CHANT_EXIT.denied);
2232
2335
  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);
2233
2336
  }
2234
- await storeChangeSetForGate(ctx, p, set.doc);
2337
+ await storeChangeSetForGate(ctx, p, set.doc, pr);
2235
2338
  // #4294: the policy at base judges the whole change set, before the pull request's gate.
2236
2339
  judged = await judgePolicy(p, { stage: "apply", op, pr, set });
2237
2340
  if (judged.stop)
2238
2341
  return stop(report({ status: "refused", refusal: judged.stop.refusal, message: judged.stop.message }), judged.stop.code);
2239
- const decided = await decideApplyGate(p, { op, pr, set, events, held: judged.held, ...(green ? { green } : {}) });
2342
+ const decided = await decideApplyGate(p, { op, pr, set, events, held: judged.held, ...(judged.heldBy ? { heldBy: judged.heldBy } : {}), ...(green ? { green } : {}) });
2240
2343
  approval = decided.approval;
2241
2344
  // #4323: the after-gate hooks hear the decision, a refusal too.
2242
2345
  const afterGate = await runGateHook(p, { op, digest: set.doc.digest, satisfied: decided.satisfied }, p.plan.order);