@intentius/chant 0.124.28 → 0.124.30

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 (449) hide show
  1. package/dist/build-params.d.ts +34 -1
  2. package/dist/build-params.d.ts.map +1 -1
  3. package/dist/build-params.js +31 -1
  4. package/dist/change-set-graph.d.ts +8 -1
  5. package/dist/change-set-graph.d.ts.map +1 -1
  6. package/dist/change-set-graph.js +4 -2
  7. package/dist/change-set.d.ts +10 -0
  8. package/dist/change-set.d.ts.map +1 -1
  9. package/dist/change-set.js +4 -3
  10. package/dist/cli/build-params-cli.d.ts +7 -1
  11. package/dist/cli/build-params-cli.d.ts.map +1 -1
  12. package/dist/cli/build-params-cli.js +17 -8
  13. package/dist/cli/commands/build.d.ts.map +1 -1
  14. package/dist/cli/commands/build.js +6 -3
  15. package/dist/cli/handlers/approve.d.ts.map +1 -1
  16. package/dist/cli/handlers/approve.js +45 -0
  17. package/dist/cli/handlers/build.d.ts.map +1 -1
  18. package/dist/cli/handlers/build.js +18 -4
  19. package/dist/cli/handlers/fan-out.d.ts +9 -0
  20. package/dist/cli/handlers/fan-out.d.ts.map +1 -1
  21. package/dist/cli/handlers/fan-out.js +67 -8
  22. package/dist/cli/handlers/lifecycle-gc.d.ts +19 -0
  23. package/dist/cli/handlers/lifecycle-gc.d.ts.map +1 -0
  24. package/dist/cli/handlers/lifecycle-gc.js +143 -0
  25. package/dist/cli/handlers/pr.d.ts +11 -3
  26. package/dist/cli/handlers/pr.d.ts.map +1 -1
  27. package/dist/cli/handlers/pr.js +134 -26
  28. package/dist/cli/handlers/promote.d.ts +7 -0
  29. package/dist/cli/handlers/promote.d.ts.map +1 -1
  30. package/dist/cli/handlers/promote.js +210 -33
  31. package/dist/cli/handlers/release.d.ts +62 -5
  32. package/dist/cli/handlers/release.d.ts.map +1 -1
  33. package/dist/cli/handlers/release.js +414 -28
  34. package/dist/cli/handlers/run.d.ts +11 -1
  35. package/dist/cli/handlers/run.d.ts.map +1 -1
  36. package/dist/cli/handlers/run.js +67 -6
  37. package/dist/cli/main.d.ts.map +1 -1
  38. package/dist/cli/main.js +91 -10
  39. package/dist/cli/parse-args.d.ts.map +1 -1
  40. package/dist/cli/parse-args.js +73 -2
  41. package/dist/cli/registry.d.ts +32 -4
  42. package/dist/cli/registry.d.ts.map +1 -1
  43. package/dist/cli/run-events.d.ts +3 -2
  44. package/dist/cli/run-events.d.ts.map +1 -1
  45. package/dist/cli/run-events.js +5 -3
  46. package/dist/components/auto-release.d.ts +2 -0
  47. package/dist/components/auto-release.d.ts.map +1 -1
  48. package/dist/components/auto-release.js +1 -0
  49. package/dist/components/capability.d.ts +9 -0
  50. package/dist/components/capability.d.ts.map +1 -1
  51. package/dist/components/driver.d.ts +8 -0
  52. package/dist/components/driver.d.ts.map +1 -1
  53. package/dist/components/driver.js +35 -0
  54. package/dist/components/fan-out-inputs.d.ts +69 -0
  55. package/dist/components/fan-out-inputs.d.ts.map +1 -0
  56. package/dist/components/fan-out-inputs.js +169 -0
  57. package/dist/components/fan-out-record.d.ts +13 -0
  58. package/dist/components/fan-out-record.d.ts.map +1 -1
  59. package/dist/components/fan-out-record.js +16 -0
  60. package/dist/components/fan-out-run.d.ts.map +1 -1
  61. package/dist/components/fan-out-run.js +50 -0
  62. package/dist/components/fan-out.d.ts +4 -0
  63. package/dist/components/fan-out.d.ts.map +1 -1
  64. package/dist/components/pr-pipeline.d.ts +49 -0
  65. package/dist/components/pr-pipeline.d.ts.map +1 -1
  66. package/dist/components/pr-pipeline.js +38 -4
  67. package/dist/components/pr-run.d.ts +20 -2
  68. package/dist/components/pr-run.d.ts.map +1 -1
  69. package/dist/components/pr-run.js +26 -13
  70. package/dist/components/promote.d.ts +23 -0
  71. package/dist/components/promote.d.ts.map +1 -1
  72. package/dist/components/promote.js +60 -2
  73. package/dist/components/release-compile.d.ts +9 -0
  74. package/dist/components/release-compile.d.ts.map +1 -1
  75. package/dist/components/release-compile.js +9 -3
  76. package/dist/components/release-gate.d.ts +11 -1
  77. package/dist/components/release-gate.d.ts.map +1 -1
  78. package/dist/components/release-gate.js +10 -4
  79. package/dist/components/wave-plan.d.ts +16 -0
  80. package/dist/components/wave-plan.d.ts.map +1 -1
  81. package/dist/components/wave-plan.js +36 -2
  82. package/dist/config.d.ts +38 -0
  83. package/dist/config.d.ts.map +1 -1
  84. package/dist/config.js +2 -0
  85. package/dist/flag-params.d.ts +54 -0
  86. package/dist/flag-params.d.ts.map +1 -0
  87. package/dist/flag-params.js +130 -0
  88. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +120 -0
  89. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -0
  90. package/dist/lifecycle/__fixtures__/publish-fakes.js +304 -0
  91. package/dist/lifecycle/change-set-store.d.ts +2 -1
  92. package/dist/lifecycle/change-set-store.d.ts.map +1 -1
  93. package/dist/lifecycle/change-set-store.js +2 -1
  94. package/dist/lifecycle/delivery-metrics.d.ts +139 -0
  95. package/dist/lifecycle/delivery-metrics.d.ts.map +1 -0
  96. package/dist/lifecycle/delivery-metrics.js +145 -0
  97. package/dist/lifecycle/deploy-outcome.d.ts +81 -0
  98. package/dist/lifecycle/deploy-outcome.d.ts.map +1 -0
  99. package/dist/lifecycle/deploy-outcome.js +101 -0
  100. package/dist/lifecycle/gate-change-set.d.ts +10 -1
  101. package/dist/lifecycle/gate-change-set.d.ts.map +1 -1
  102. package/dist/lifecycle/gate-change-set.js +35 -3
  103. package/dist/lifecycle/gate-ledger.d.ts +2 -3
  104. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  105. package/dist/lifecycle/git.d.ts +30 -1
  106. package/dist/lifecycle/git.d.ts.map +1 -1
  107. package/dist/lifecycle/git.js +31 -5
  108. package/dist/lifecycle/index.d.ts +4 -0
  109. package/dist/lifecycle/index.d.ts.map +1 -1
  110. package/dist/lifecycle/index.js +4 -0
  111. package/dist/lifecycle/mixed-environment.d.ts +95 -0
  112. package/dist/lifecycle/mixed-environment.d.ts.map +1 -0
  113. package/dist/lifecycle/mixed-environment.js +154 -0
  114. package/dist/lifecycle/publish-attachments.d.ts +79 -0
  115. package/dist/lifecycle/publish-attachments.d.ts.map +1 -0
  116. package/dist/lifecycle/publish-attachments.js +179 -0
  117. package/dist/lifecycle/publish-credentials.d.ts +37 -0
  118. package/dist/lifecycle/publish-credentials.d.ts.map +1 -0
  119. package/dist/lifecycle/publish-credentials.js +69 -0
  120. package/dist/lifecycle/publish-declaration.d.ts +97 -0
  121. package/dist/lifecycle/publish-declaration.d.ts.map +1 -0
  122. package/dist/lifecycle/publish-declaration.js +83 -0
  123. package/dist/lifecycle/publish-forge.d.ts +53 -0
  124. package/dist/lifecycle/publish-forge.d.ts.map +1 -0
  125. package/dist/lifecycle/publish-forge.js +298 -0
  126. package/dist/lifecycle/publish-npm.d.ts +61 -0
  127. package/dist/lifecycle/publish-npm.d.ts.map +1 -0
  128. package/dist/lifecycle/publish-npm.js +242 -0
  129. package/dist/lifecycle/publish-oci.d.ts +64 -0
  130. package/dist/lifecycle/publish-oci.d.ts.map +1 -0
  131. package/dist/lifecycle/publish-oci.js +383 -0
  132. package/dist/lifecycle/publish-record.d.ts +66 -0
  133. package/dist/lifecycle/publish-record.d.ts.map +1 -0
  134. package/dist/lifecycle/publish-record.js +84 -0
  135. package/dist/lifecycle/publish-targets.d.ts +45 -0
  136. package/dist/lifecycle/publish-targets.d.ts.map +1 -0
  137. package/dist/lifecycle/publish-targets.js +85 -0
  138. package/dist/lifecycle/release-cut.d.ts +48 -1
  139. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  140. package/dist/lifecycle/release-cut.js +116 -23
  141. package/dist/lifecycle/release-join.d.ts +95 -0
  142. package/dist/lifecycle/release-join.d.ts.map +1 -0
  143. package/dist/lifecycle/release-join.js +139 -0
  144. package/dist/lifecycle/release-ledger.d.ts +8 -3
  145. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  146. package/dist/lifecycle/release-ledger.js +2 -0
  147. package/dist/lifecycle/release-publish.d.ts +312 -0
  148. package/dist/lifecycle/release-publish.d.ts.map +1 -0
  149. package/dist/lifecycle/release-publish.js +335 -0
  150. package/dist/lifecycle/release-revocation.d.ts +80 -0
  151. package/dist/lifecycle/release-revocation.d.ts.map +1 -0
  152. package/dist/lifecycle/release-revocation.js +123 -0
  153. package/dist/lifecycle/release-store.d.ts +12 -2
  154. package/dist/lifecycle/release-store.d.ts.map +1 -1
  155. package/dist/lifecycle/release-store.js +4 -2
  156. package/dist/lifecycle/release-verify.d.ts +61 -0
  157. package/dist/lifecycle/release-verify.d.ts.map +1 -0
  158. package/dist/lifecycle/release-verify.js +92 -0
  159. package/dist/lifecycle/release-workstation.d.ts +91 -0
  160. package/dist/lifecycle/release-workstation.d.ts.map +1 -0
  161. package/dist/lifecycle/release-workstation.js +180 -0
  162. package/dist/lifecycle/retention-policy.d.ts +45 -0
  163. package/dist/lifecycle/retention-policy.d.ts.map +1 -0
  164. package/dist/lifecycle/retention-policy.js +43 -0
  165. package/dist/lifecycle/retention.d.ts +185 -0
  166. package/dist/lifecycle/retention.d.ts.map +1 -0
  167. package/dist/lifecycle/retention.js +400 -0
  168. package/dist/lifecycle/run-ledger.d.ts +1 -1
  169. package/dist/lifecycle/run-ledger.d.ts.map +1 -1
  170. package/dist/lifecycle/run-ledger.js +9 -0
  171. package/dist/op/activities/activity-contracts.d.ts +1 -0
  172. package/dist/op/activities/activity-contracts.d.ts.map +1 -1
  173. package/dist/op/activities/activity-contracts.js +1 -0
  174. package/dist/op/activities/shell.d.ts +6 -0
  175. package/dist/op/activities/shell.d.ts.map +1 -1
  176. package/dist/op/activities/shell.js +1 -1
  177. package/dist/op/local-executor.d.ts +23 -1
  178. package/dist/op/local-executor.d.ts.map +1 -1
  179. package/dist/op/local-executor.js +9 -3
  180. package/dist/op/runtime.d.ts +27 -0
  181. package/dist/op/runtime.d.ts.map +1 -1
  182. package/dist/op/runtime.js +20 -0
  183. package/dist/plan-summary.d.ts.map +1 -1
  184. package/dist/plan-summary.js +8 -2
  185. package/dist/pr-forge.d.ts +23 -0
  186. package/dist/pr-forge.d.ts.map +1 -1
  187. package/dist/pr-forge.js +44 -0
  188. package/dist/pr-loop.d.ts +17 -0
  189. package/dist/pr-loop.d.ts.map +1 -1
  190. package/dist/pr-loop.js +30 -4
  191. package/dist/pr-report-url.d.ts +82 -0
  192. package/dist/pr-report-url.d.ts.map +1 -0
  193. package/dist/pr-report-url.js +174 -0
  194. package/dist/provenance.d.ts +2 -2
  195. package/dist/provenance.d.ts.map +1 -1
  196. package/dist/run-event-store.d.ts +29 -2
  197. package/dist/run-event-store.d.ts.map +1 -1
  198. package/dist/run-event-store.js +50 -3
  199. package/dist/run-event-stream.d.ts +4 -3
  200. package/dist/run-event-stream.d.ts.map +1 -1
  201. package/dist/run-event-stream.js +7 -3
  202. package/dist/run-event.d.ts +34 -1
  203. package/dist/run-event.d.ts.map +1 -1
  204. package/dist/run-event.js +4 -0
  205. package/dist/wave-runtime.mjs +260 -229
  206. package/dist/workspace/__fixtures__/flag-workspace.d.ts +31 -0
  207. package/dist/workspace/__fixtures__/flag-workspace.d.ts.map +1 -0
  208. package/dist/workspace/__fixtures__/flag-workspace.js +114 -0
  209. package/dist/workspace/change-set.schema.json +5 -1
  210. package/dist/workspace/check.schema.json +4 -2
  211. package/dist/workspace/checks/records.d.ts +9 -1
  212. package/dist/workspace/checks/records.d.ts.map +1 -1
  213. package/dist/workspace/checks/records.js +35 -1
  214. package/dist/workspace/checks.d.ts +1 -0
  215. package/dist/workspace/checks.d.ts.map +1 -1
  216. package/dist/workspace/checks.js +2 -1
  217. package/dist/workspace/ci-green-forge.d.ts +2 -0
  218. package/dist/workspace/ci-green-forge.d.ts.map +1 -1
  219. package/dist/workspace/ci-green.d.ts +10 -0
  220. package/dist/workspace/ci-green.d.ts.map +1 -1
  221. package/dist/workspace/ci-green.js +14 -5
  222. package/dist/workspace/ci-run.d.ts +222 -0
  223. package/dist/workspace/ci-run.d.ts.map +1 -0
  224. package/dist/workspace/ci-run.js +464 -0
  225. package/dist/workspace/ci-serve.d.ts +214 -0
  226. package/dist/workspace/ci-serve.d.ts.map +1 -0
  227. package/dist/workspace/ci-serve.js +412 -0
  228. package/dist/workspace/declaration.d.ts +16 -0
  229. package/dist/workspace/declaration.d.ts.map +1 -1
  230. package/dist/workspace/declaration.js +26 -0
  231. package/dist/workspace/declaration.schema.json +64 -0
  232. package/dist/workspace/declared-kinds.d.ts +16 -0
  233. package/dist/workspace/declared-kinds.d.ts.map +1 -1
  234. package/dist/workspace/declared-kinds.js +25 -0
  235. package/dist/workspace/delivery-metrics.d.ts +91 -0
  236. package/dist/workspace/delivery-metrics.d.ts.map +1 -0
  237. package/dist/workspace/delivery-metrics.js +217 -0
  238. package/dist/workspace/delivery-metrics.schema.json +519 -0
  239. package/dist/workspace/flags-read.d.ts +37 -0
  240. package/dist/workspace/flags-read.d.ts.map +1 -0
  241. package/dist/workspace/flags-read.js +103 -0
  242. package/dist/workspace/flags.d.ts +100 -0
  243. package/dist/workspace/flags.d.ts.map +1 -0
  244. package/dist/workspace/flags.js +98 -0
  245. package/dist/workspace/graph-cli.js +1 -1
  246. package/dist/workspace/intent-cli.d.ts +11 -2
  247. package/dist/workspace/intent-cli.d.ts.map +1 -1
  248. package/dist/workspace/intent-cli.js +54 -5
  249. package/dist/workspace/intent-trace.d.ts +219 -0
  250. package/dist/workspace/intent-trace.d.ts.map +1 -0
  251. package/dist/workspace/intent-trace.js +314 -0
  252. package/dist/workspace/intent.d.ts +30 -6
  253. package/dist/workspace/intent.d.ts.map +1 -1
  254. package/dist/workspace/intent.js +141 -21
  255. package/dist/workspace/intent.schema.json +702 -6
  256. package/dist/workspace/overlap.d.ts +146 -0
  257. package/dist/workspace/overlap.d.ts.map +1 -0
  258. package/dist/workspace/overlap.js +276 -0
  259. package/dist/workspace/pr-report.schema.json +5 -0
  260. package/dist/workspace/reason-codes.d.ts +2 -0
  261. package/dist/workspace/reason-codes.d.ts.map +1 -1
  262. package/dist/workspace/reason-codes.js +3 -0
  263. package/dist/workspace/records.d.ts +15 -2
  264. package/dist/workspace/records.d.ts.map +1 -1
  265. package/dist/workspace/records.js +32 -0
  266. package/dist/workspace/records.schema.json +21 -2
  267. package/dist/workspace/reference-kinds/flag/flag.kind.mjs +32 -0
  268. package/dist/workspace/reference-kinds/flag/flag.schema.json +53 -0
  269. package/dist/workspace/releases.d.ts +9 -0
  270. package/dist/workspace/releases.d.ts.map +1 -1
  271. package/dist/workspace/releases.js +9 -0
  272. package/dist/workspace/releases.schema.json +123 -1
  273. package/dist/workspace/run-event.schema.json +24 -6
  274. package/dist/workspace/status-gates.d.ts +8 -0
  275. package/dist/workspace/status-gates.d.ts.map +1 -1
  276. package/dist/workspace/status-stewards.d.ts +2 -0
  277. package/dist/workspace/status-stewards.d.ts.map +1 -1
  278. package/dist/workspace/status-stewards.js +1 -0
  279. package/dist/workspace/status.d.ts +78 -0
  280. package/dist/workspace/status.d.ts.map +1 -1
  281. package/dist/workspace/status.js +170 -3
  282. package/dist/workspace/status.schema.json +210 -2
  283. package/dist/workspace/wip.d.ts.map +1 -1
  284. package/dist/workspace/wip.js +11 -3
  285. package/package.json +1 -1
  286. package/src/build-params.test.ts +46 -0
  287. package/src/build-params.ts +55 -1
  288. package/src/change-set-graph.ts +10 -2
  289. package/src/change-set.ts +14 -3
  290. package/src/cli/build-params-cli.ts +22 -9
  291. package/src/cli/commands/build.ts +6 -3
  292. package/src/cli/handlers/approve-release.test.ts +5 -1
  293. package/src/cli/handlers/approve-revoked.test.ts +155 -0
  294. package/src/cli/handlers/approve.ts +47 -0
  295. package/src/cli/handlers/build.test.ts +30 -0
  296. package/src/cli/handlers/build.ts +20 -4
  297. package/src/cli/handlers/fan-out.test.ts +262 -1
  298. package/src/cli/handlers/fan-out.ts +72 -8
  299. package/src/cli/handlers/intent-trace.e2e.test.ts +201 -0
  300. package/src/cli/handlers/lifecycle-gc.test.ts +126 -0
  301. package/src/cli/handlers/lifecycle-gc.ts +146 -0
  302. package/src/cli/handlers/pr.test.ts +148 -1
  303. package/src/cli/handlers/pr.ts +144 -28
  304. package/src/cli/handlers/promote.test.ts +280 -2
  305. package/src/cli/handlers/promote.ts +210 -34
  306. package/src/cli/handlers/release-implicit.e2e.test.ts +12 -4
  307. package/src/cli/handlers/release-join.e2e.test.ts +185 -0
  308. package/src/cli/handlers/release-publish-targets.e2e.test.ts +295 -0
  309. package/src/cli/handlers/release-verify.e2e.test.ts +117 -0
  310. package/src/cli/handlers/release-workstation-ci.e2e.test.ts +135 -0
  311. package/src/cli/handlers/release.e2e.test.ts +146 -32
  312. package/src/cli/handlers/release.ts +415 -28
  313. package/src/cli/handlers/run-auto-release.test.ts +9 -0
  314. package/src/cli/handlers/run-release.test.ts +55 -0
  315. package/src/cli/handlers/run.ts +69 -5
  316. package/src/cli/main.test.ts +1 -0
  317. package/src/cli/main.ts +91 -10
  318. package/src/cli/parse-args.ts +54 -2
  319. package/src/cli/registry.ts +32 -4
  320. package/src/cli/run-events.ts +5 -2
  321. package/src/components/auto-release.test.ts +9 -0
  322. package/src/components/auto-release.ts +3 -0
  323. package/src/components/capability.ts +9 -0
  324. package/src/components/driver.test.ts +24 -0
  325. package/src/components/driver.ts +36 -0
  326. package/src/components/fan-out-inputs.test.ts +85 -0
  327. package/src/components/fan-out-inputs.ts +192 -0
  328. package/src/components/fan-out-record.test.ts +10 -0
  329. package/src/components/fan-out-record.ts +19 -0
  330. package/src/components/fan-out-run.ts +48 -0
  331. package/src/components/fan-out.ts +4 -0
  332. package/src/components/pr-pipeline.ts +67 -4
  333. package/src/components/pr-run.test.ts +127 -0
  334. package/src/components/pr-run.ts +32 -12
  335. package/src/components/promote.ts +68 -2
  336. package/src/components/release-compile.ts +17 -3
  337. package/src/components/release-gate.ts +18 -4
  338. package/src/components/wave-plan.ts +45 -2
  339. package/src/config.ts +8 -0
  340. package/src/flag-params.test.ts +144 -0
  341. package/src/flag-params.ts +134 -0
  342. package/src/lifecycle/__fixtures__/publish-fakes.ts +351 -0
  343. package/src/lifecycle/change-set-store.ts +2 -1
  344. package/src/lifecycle/delivery-metrics.ts +263 -0
  345. package/src/lifecycle/deploy-outcome.ts +147 -0
  346. package/src/lifecycle/gate-change-set.ts +37 -6
  347. package/src/lifecycle/gate-ledger.ts +2 -2
  348. package/src/lifecycle/git.ts +61 -8
  349. package/src/lifecycle/index.ts +4 -0
  350. package/src/lifecycle/mixed-environment.test.ts +97 -0
  351. package/src/lifecycle/mixed-environment.ts +204 -0
  352. package/src/lifecycle/publish-attachments.ts +196 -0
  353. package/src/lifecycle/publish-credentials.ts +84 -0
  354. package/src/lifecycle/publish-declaration.ts +95 -0
  355. package/src/lifecycle/publish-forge.ts +325 -0
  356. package/src/lifecycle/publish-npm.ts +259 -0
  357. package/src/lifecycle/publish-oci.ts +396 -0
  358. package/src/lifecycle/publish-record.ts +113 -0
  359. package/src/lifecycle/publish-resume.test.ts +168 -0
  360. package/src/lifecycle/publish-targets.test.ts +494 -0
  361. package/src/lifecycle/publish-targets.ts +100 -0
  362. package/src/lifecycle/release-cut.test.ts +74 -2
  363. package/src/lifecycle/release-cut.ts +158 -22
  364. package/src/lifecycle/release-flag.test.ts +112 -0
  365. package/src/lifecycle/release-join.test.ts +68 -0
  366. package/src/lifecycle/release-join.ts +182 -0
  367. package/src/lifecycle/release-ledger.ts +9 -3
  368. package/src/lifecycle/release-publish.test.ts +225 -0
  369. package/src/lifecycle/release-publish.ts +568 -0
  370. package/src/lifecycle/release-revocation.ts +147 -0
  371. package/src/lifecycle/release-store.ts +15 -4
  372. package/src/lifecycle/release-verify.test.ts +110 -0
  373. package/src/lifecycle/release-verify.ts +120 -0
  374. package/src/lifecycle/release-workstation.test.ts +204 -0
  375. package/src/lifecycle/release-workstation.ts +216 -0
  376. package/src/lifecycle/retention-growth.e2e.test.ts +279 -0
  377. package/src/lifecycle/retention-policy.ts +63 -0
  378. package/src/lifecycle/retention.test.ts +363 -0
  379. package/src/lifecycle/retention.ts +508 -0
  380. package/src/lifecycle/run-ledger.ts +7 -1
  381. package/src/op/activities/activity-contracts.ts +1 -0
  382. package/src/op/activities/shell.ts +7 -1
  383. package/src/op/local-executor.ts +27 -4
  384. package/src/op/runtime.ts +42 -0
  385. package/src/plan-summary.test.ts +20 -0
  386. package/src/plan-summary.ts +8 -1
  387. package/src/pr-forge.test.ts +25 -0
  388. package/src/pr-forge.ts +62 -0
  389. package/src/pr-loop.test.ts +13 -1
  390. package/src/pr-loop.ts +41 -4
  391. package/src/pr-report-url.test.ts +131 -0
  392. package/src/pr-report-url.ts +209 -0
  393. package/src/provenance.ts +2 -2
  394. package/src/run-event-store.ts +63 -3
  395. package/src/run-event-stream.ts +8 -4
  396. package/src/run-event.ts +38 -1
  397. package/src/workspace/__fixtures__/flag-workspace.ts +132 -0
  398. package/src/workspace/__fixtures__/older-records/change-set-984534ea9.json +100 -0
  399. package/src/workspace/__fixtures__/older-records/older-records.json +326 -0
  400. package/src/workspace/change-set.schema.json +5 -1
  401. package/src/workspace/check.schema.json +4 -2
  402. package/src/workspace/checks/records.ts +35 -1
  403. package/src/workspace/checks.ts +2 -1
  404. package/src/workspace/ci-green-forge.ts +2 -0
  405. package/src/workspace/ci-green.ts +20 -5
  406. package/src/workspace/ci-run.test.ts +416 -0
  407. package/src/workspace/ci-run.ts +571 -0
  408. package/src/workspace/ci-serve.test.ts +268 -0
  409. package/src/workspace/ci-serve.ts +521 -0
  410. package/src/workspace/declaration.schema.json +64 -0
  411. package/src/workspace/declaration.test.ts +28 -0
  412. package/src/workspace/declaration.ts +38 -0
  413. package/src/workspace/declared-kinds.ts +40 -1
  414. package/src/workspace/delivery-metrics.schema.json +519 -0
  415. package/src/workspace/delivery-metrics.test.ts +236 -0
  416. package/src/workspace/delivery-metrics.ts +286 -0
  417. package/src/workspace/flags-read.ts +121 -0
  418. package/src/workspace/flags.test.ts +141 -0
  419. package/src/workspace/flags.ts +157 -0
  420. package/src/workspace/graph-cli.ts +1 -1
  421. package/src/workspace/intent-cli.ts +46 -5
  422. package/src/workspace/intent-trace.test.ts +173 -0
  423. package/src/workspace/intent-trace.ts +484 -0
  424. package/src/workspace/intent.schema.json +702 -6
  425. package/src/workspace/intent.ts +148 -25
  426. package/src/workspace/older-records.test.ts +412 -0
  427. package/src/workspace/overlap.test.ts +165 -0
  428. package/src/workspace/overlap.ts +340 -0
  429. package/src/workspace/pr-report.schema.json +5 -0
  430. package/src/workspace/read-contract.e2e.test.ts +2 -1
  431. package/src/workspace/reason-codes.test.ts +5 -0
  432. package/src/workspace/reason-codes.ts +3 -0
  433. package/src/workspace/record-assets.test.ts +2 -1
  434. package/src/workspace/records-contract.e2e.test.ts +2 -1
  435. package/src/workspace/records.schema.json +21 -2
  436. package/src/workspace/records.ts +36 -2
  437. package/src/workspace/reference-kinds/flag/flag.kind.mjs +32 -0
  438. package/src/workspace/reference-kinds/flag/flag.schema.json +53 -0
  439. package/src/workspace/releases.schema.json +123 -1
  440. package/src/workspace/releases.ts +11 -0
  441. package/src/workspace/run-event.schema.json +24 -6
  442. package/src/workspace/status-contract.test.ts +29 -0
  443. package/src/workspace/status-gates.ts +8 -0
  444. package/src/workspace/status-mixed.test.ts +152 -0
  445. package/src/workspace/status-revoked.test.ts +153 -0
  446. package/src/workspace/status-stewards.ts +3 -0
  447. package/src/workspace/status.schema.json +210 -2
  448. package/src/workspace/status.ts +254 -3
  449. package/src/workspace/wip.ts +11 -2
@@ -0,0 +1,263 @@
1
+ /**
2
+ * The four DORA metrics of one environment's deploy records (#4039): how
3
+ * often it deploys, the lead time from commit to running release, the change
4
+ * failure rate and the time to restore.
5
+ *
6
+ * Everything here is pure. The caller reads the ledgers, the release files
7
+ * and the ci tags, and hands this module one environment's records with
8
+ * lookups for the rest; `workspace/delivery-metrics.ts` does that for
9
+ * `chant workspace metrics`.
10
+ *
11
+ * A deploy is one record in `<env>/releases.jsonl`: one component deployed
12
+ * once. A redeploy, which puts the running release back, is counted apart and
13
+ * is not a deploy for the metrics. A deploy fails when, within the failure window after it, the commit
14
+ * it deployed is revoked (a counted `ci/revoked/<sha>` tag, #4033) or the
15
+ * environment is rolled back from it. Which records are rollbacks, and which
16
+ * put the current release back, is decided in {@link rollbackOf} and
17
+ * {@link isRedeploy} and nowhere else, so a new kind of rollback record
18
+ * (#4035) changes those two functions only.
19
+ */
20
+
21
+ import type { ReleaseRecord, ReleaseRef } from "./release-ledger";
22
+
23
+ /** The failure window when the declaration's `metrics.failureWindowDays` is not set. */
24
+ export const DEFAULT_FAILURE_WINDOW_DAYS = 7;
25
+
26
+ const DAY_MS = 86_400_000;
27
+
28
+ /**
29
+ * The earlier deploy a rollback record restores, or null when the record is
30
+ * not a rollback. Today a rollback is a record `chant components rollback`
31
+ * wrote, which names what it restores in `restores` (#2531). Every rule below
32
+ * that asks whether a record rolled an environment back asks this function.
33
+ */
34
+ export function rollbackOf(record: Pick<ReleaseRecord, "restores">): ReleaseRef | null {
35
+ return record.restores ?? null;
36
+ }
37
+
38
+ /**
39
+ * Whether the record put the current release back (`chant components
40
+ * redeploy`, #2604). A redeploy deploys the same release again, so it neither
41
+ * restores a failed deploy nor stands between a deploy and its rollback.
42
+ */
43
+ export function isRedeploy(record: Pick<ReleaseRecord, "redeploys">): boolean {
44
+ return record.redeploys !== undefined;
45
+ }
46
+
47
+ /** A counted revoked tag on a commit, with the time it was made, or null for a lightweight tag. */
48
+ export interface CommitRevocation {
49
+ tag: string;
50
+ tagged: string | null;
51
+ }
52
+
53
+ /** What the caller knows beyond the records, as lookups. */
54
+ export interface MetricsLookups {
55
+ /** The release a deploy record names: its `releaseDigest`, else the one its release-gate admission names. Undefined when it names none. */
56
+ releaseOf: (record: ReleaseRecord) => string | undefined;
57
+ /** The commit a release was cut from, or null when its file can't be read here. */
58
+ commitOfRelease: (releaseDigest: string) => string | null;
59
+ /** The release's label, or null. */
60
+ labelOf: (releaseDigest: string) => string | null;
61
+ /** The counted revoked tag on a commit, or null when the commit is not revoked. */
62
+ revocationOf: (commit: string) => CommitRevocation | null;
63
+ /** The commit's committer time in milliseconds, or null when the commit is not in this repository. */
64
+ commitTime: (commit: string) => number | null;
65
+ }
66
+
67
+ /** The span of time the metrics count deploys in. */
68
+ export interface MetricsWindow {
69
+ /** ISO-8601, inclusive. */
70
+ since: string;
71
+ /** ISO-8601, inclusive. */
72
+ until: string;
73
+ }
74
+
75
+ /** A record named the way `restores` names one. */
76
+ export interface DeployRef {
77
+ runId: string;
78
+ timestamp: string;
79
+ }
80
+
81
+ /** One failed deploy, and how it was restored. */
82
+ export interface DeployFailure {
83
+ component: string;
84
+ timestamp: string;
85
+ runId: string;
86
+ /** The release the deploy came from, or null for a deploy made from no release. */
87
+ releaseDigest: string | null;
88
+ label: string | null;
89
+ /** The commit it deployed: the release's commit, or the record's `gitSha` for a deploy made from no release. */
90
+ commit: string;
91
+ /** Why it counts as failed: `revoked`, `rolled-back`, or both. */
92
+ causes: Array<"revoked" | "rolled-back">;
93
+ /** The revoked tag on the commit, when that is a cause. */
94
+ revoked: CommitRevocation | null;
95
+ /** The rollback record that rolled the environment back from it, when that is a cause. */
96
+ rolledBackBy: DeployRef | null;
97
+ /** The next deploy of the component in the environment whose commit is not revoked, or null while there is none. */
98
+ restoredBy: DeployRef | null;
99
+ /** Seconds from the failed deploy to `restoredBy`, or null while it is not restored. */
100
+ restoreSeconds: number | null;
101
+ }
102
+
103
+ /** The four metrics of one environment. */
104
+ export interface EnvironmentMetrics {
105
+ env: string;
106
+ deployments: {
107
+ /** Deploy records in the window, one per component deployed, leaving out redeploys. Rollbacks count. */
108
+ count: number;
109
+ /** Redeploys in the window: records that put the running release back, counted apart from `count`. */
110
+ redeploys: number;
111
+ /** Distinct `runId` values among them, so a run that deploys several components counts once. */
112
+ runs: number;
113
+ /** Of `count`, the deploys made from a release. */
114
+ fromRelease: number;
115
+ /** `count` over the window in weeks, to two decimals. */
116
+ perWeek: number;
117
+ };
118
+ leadTime: {
119
+ /** Changes whose first deploy here falls in the window and whose commit time is known. */
120
+ changes: number;
121
+ /** Of `changes`, releases (the first deploy naming the release). */
122
+ fromRelease: number;
123
+ /** Of `changes`, commits deployed from no release (the first deploy with that `gitSha`). */
124
+ fromCommit: number;
125
+ /** Changes left out because their commit is not in this repository. */
126
+ unknown: number;
127
+ /** The median, in seconds, or null when `changes` is 0. */
128
+ medianSeconds: number | null;
129
+ };
130
+ changeFailure: {
131
+ deployments: number;
132
+ failed: number;
133
+ /** Failed deploys whose commit was revoked within the window after them. */
134
+ revoked: number;
135
+ /** Failed deploys the environment was rolled back from within the window after them. */
136
+ rolledBack: number;
137
+ /** `failed` over `deployments`, to four decimals, or null with no deployments. */
138
+ rate: number | null;
139
+ };
140
+ restore: {
141
+ restored: number;
142
+ open: number;
143
+ medianSeconds: number | null;
144
+ };
145
+ /** The failed deploys in the window, oldest first. */
146
+ failures: DeployFailure[];
147
+ }
148
+
149
+ function median(values: number[]): number | null {
150
+ if (values.length === 0) return null;
151
+ const s = [...values].sort((a, b) => a - b);
152
+ const mid = Math.floor(s.length / 2);
153
+ return Math.round(s.length % 2 === 1 ? s[mid] : (s[mid - 1] + s[mid]) / 2);
154
+ }
155
+
156
+ const at = (iso: string): number => Date.parse(iso);
157
+ const ref = (r: ReleaseRecord): DeployRef => ({ runId: r.runId, timestamp: r.timestamp });
158
+
159
+ /**
160
+ * The metrics of one environment's records. `records` is the whole ledger of
161
+ * the environment, every component, in ledger order: deploys before the
162
+ * window still decide lead times, and deploys after a failure decide its
163
+ * restore. Only deploys whose `timestamp` falls in `window` are counted.
164
+ */
165
+ export function environmentMetrics(
166
+ env: string,
167
+ records: readonly ReleaseRecord[],
168
+ lookups: MetricsLookups,
169
+ window: MetricsWindow,
170
+ failureWindowDays: number = DEFAULT_FAILURE_WINDOW_DAYS,
171
+ ): EnvironmentMetrics {
172
+ // Ledger order breaks timestamp ties, as `latestPerComponent` does.
173
+ const sorted = records.map((r, i) => ({ r, i })).sort((a, b) => at(a.r.timestamp) - at(b.r.timestamp) || a.i - b.i).map((x) => x.r);
174
+ const since = at(window.since);
175
+ const until = at(window.until);
176
+ const failureMs = failureWindowDays * DAY_MS;
177
+ const inWindow = (r: ReleaseRecord) => at(r.timestamp) >= since && at(r.timestamp) <= until;
178
+
179
+ const facts = sorted.map((r) => {
180
+ const releaseDigest = lookups.releaseOf(r) ?? null;
181
+ const commit = (releaseDigest !== null ? lookups.commitOfRelease(releaseDigest) : null) ?? r.gitSha;
182
+ return { r, releaseDigest, commit, revocation: lookups.revocationOf(commit) };
183
+ });
184
+
185
+ // A redeploy puts the running release back: it is counted apart, and
186
+ // neither fails nor restores on its own.
187
+ const deployments = facts.filter((f) => inWindow(f.r) && !isRedeploy(f.r));
188
+ const failures: DeployFailure[] = [];
189
+ for (const [i, f] of facts.entries()) {
190
+ if (!inWindow(f.r) || isRedeploy(f.r)) continue;
191
+ const t = at(f.r.timestamp);
192
+ const later = facts.slice(i + 1).filter((g) => g.r.component === f.r.component);
193
+
194
+ // Revoked within the window after the deploy. A tag with no time, or one
195
+ // made before the deploy, revokes what was deployed all the same.
196
+ const revoked = f.revocation !== null && (f.revocation.tagged === null || at(f.revocation.tagged) - t <= failureMs) ? f.revocation : null;
197
+
198
+ // Rolled back from it: the next deploy of the component that is not a
199
+ // redeploy is a rollback, within the window.
200
+ const next = later.find((g) => !isRedeploy(g.r));
201
+ const rolledBack = next !== undefined && rollbackOf(next.r) !== null && at(next.r.timestamp) - t <= failureMs ? next.r : null;
202
+
203
+ if (!revoked && !rolledBack) continue;
204
+ const restore = later.find((g) => !isRedeploy(g.r) && g.revocation === null);
205
+ failures.push({
206
+ component: f.r.component,
207
+ timestamp: f.r.timestamp,
208
+ runId: f.r.runId,
209
+ releaseDigest: f.releaseDigest,
210
+ label: f.releaseDigest !== null ? lookups.labelOf(f.releaseDigest) : null,
211
+ commit: f.commit,
212
+ causes: [...(revoked ? (["revoked"] as const) : []), ...(rolledBack ? (["rolled-back"] as const) : [])],
213
+ revoked,
214
+ rolledBackBy: rolledBack ? ref(rolledBack) : null,
215
+ restoredBy: restore ? ref(restore.r) : null,
216
+ restoreSeconds: restore ? Math.round((at(restore.r.timestamp) - t) / 1000) : null,
217
+ });
218
+ }
219
+
220
+ // Lead time: one change per release, or per commit deployed from no
221
+ // release, timed at its first deploy in this environment.
222
+ const firstDeploy = new Map<string, (typeof facts)[number]>();
223
+ for (const f of facts) {
224
+ const key = f.releaseDigest !== null ? `release:${f.releaseDigest}` : `commit:${f.r.gitSha}`;
225
+ if (!firstDeploy.has(key)) firstDeploy.set(key, f);
226
+ }
227
+ const leads: number[] = [];
228
+ let fromRelease = 0;
229
+ let unknown = 0;
230
+ for (const f of firstDeploy.values()) {
231
+ if (!inWindow(f.r)) continue;
232
+ const committed = lookups.commitTime(f.commit);
233
+ if (committed === null) {
234
+ unknown++;
235
+ continue;
236
+ }
237
+ leads.push(Math.max(0, (at(f.r.timestamp) - committed) / 1000));
238
+ if (f.releaseDigest !== null) fromRelease++;
239
+ }
240
+
241
+ const weeks = Math.max(until - since, DAY_MS) / (7 * DAY_MS);
242
+ const restored = failures.filter((x) => x.restoreSeconds !== null);
243
+ return {
244
+ env,
245
+ deployments: {
246
+ count: deployments.length,
247
+ redeploys: facts.filter((f) => inWindow(f.r) && isRedeploy(f.r)).length,
248
+ runs: new Set(deployments.map((f) => f.r.runId)).size,
249
+ fromRelease: deployments.filter((f) => f.releaseDigest !== null).length,
250
+ perWeek: Math.round((deployments.length / weeks) * 100) / 100,
251
+ },
252
+ leadTime: { changes: leads.length, fromRelease, fromCommit: leads.length - fromRelease, unknown, medianSeconds: median(leads) },
253
+ changeFailure: {
254
+ deployments: deployments.length,
255
+ failed: failures.length,
256
+ revoked: failures.filter((x) => x.revoked !== null).length,
257
+ rolledBack: failures.filter((x) => x.rolledBackBy !== null).length,
258
+ rate: deployments.length === 0 ? null : Math.round((failures.length / deployments.length) * 10_000) / 10_000,
259
+ },
260
+ restore: { restored: restored.length, open: failures.length - restored.length, medianSeconds: median(restored.map((x) => x.restoreSeconds!)) },
261
+ failures,
262
+ };
263
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * What a promote, rollback or redeploy left behind when it did not deploy
3
+ * every component it planned (#4035).
4
+ *
5
+ * The release ledger records a component only once its deploy succeeded, so
6
+ * after a run that applied partly it still names the earlier release for
7
+ * every component that failed, and nothing says that component may be
8
+ * running part of the new one. A deploy outcome is the record of that run:
9
+ * one line per run in `<env>/outcomes.jsonl` on `chant/lifecycle`, beside
10
+ * the environment's `releases.jsonl` and under the same member prefix,
11
+ * naming each planned component and what happened to it.
12
+ *
13
+ * It is written only when the run ended with some components deployed and
14
+ * others not, or with a component that failed. A run that stopped at a gate
15
+ * before deploying anything changed nothing in the environment; its pending
16
+ * gate is what `workspace status` shows for it.
17
+ *
18
+ * The file is append-only, like the release ledger. Whether the environment
19
+ * is still mixed is derived when it is read ({@link ./mixed-environment.ts}):
20
+ * a component the outcome names as failed or gated stays unsettled until the
21
+ * release ledger has a newer record of it, which a redeploy, a rollback or
22
+ * the same promote run again writes.
23
+ */
24
+
25
+ import { sortedJsonReplacer } from "../utils";
26
+ import type { PromotionPlan } from "../components/promote";
27
+ import type { DriverRunResult } from "../components/driver";
28
+
29
+ /** The file a deploy outcome is appended to, under the environment's directory. */
30
+ export const OUTCOMES_FILE = "outcomes.jsonl";
31
+
32
+ /** What a run did to one component it planned. */
33
+ export type DeployOutcomeState = "deployed" | "failed" | "gated" | "not-run";
34
+
35
+ export interface DeployOutcomeComponent {
36
+ component: string;
37
+ /** `deployed` (a release record was written), `failed`, `gated` (stopped at a gate after the steps before it ran), or `not-run`. */
38
+ outcome: DeployOutcomeState;
39
+ /** The artifact digest the run was deploying. */
40
+ digest: string;
41
+ /** The release the run was deploying for this component, or null when it named none. */
42
+ releaseDigest: string | null;
43
+ }
44
+
45
+ /** One line of `<env>/outcomes.jsonl`. */
46
+ export interface DeployOutcome {
47
+ version: 1;
48
+ env: string;
49
+ verb: "promote" | "rollback" | "redeploy";
50
+ /** The run id the run's release records carry. */
51
+ runId: string;
52
+ /** The timestamp the run's release records carry. */
53
+ timestamp: string;
54
+ actor: string;
55
+ /** The release the run deployed under (`--release`), or null. */
56
+ releaseDigest: string | null;
57
+ /** How the run ended. */
58
+ status: "fail" | "gated";
59
+ components: DeployOutcomeComponent[];
60
+ }
61
+
62
+ /**
63
+ * The outcome to record for a run, or null when there is nothing to record:
64
+ * every planned component deployed, or the run stopped at a gate with
65
+ * nothing deployed and nothing failed.
66
+ */
67
+ export function deployOutcomeOf(input: {
68
+ verb: DeployOutcome["verb"];
69
+ plan: PromotionPlan;
70
+ run: Pick<DriverRunResult, "status" | "results">;
71
+ /** The release the run deployed under, if any. */
72
+ releaseDigest: string | null;
73
+ runId: string;
74
+ timestamp: string;
75
+ actor: string;
76
+ }): DeployOutcome | null {
77
+ const { plan, run } = input;
78
+ if (run.status === "ok") return null;
79
+ const components: DeployOutcomeComponent[] = plan.items.map((item) => {
80
+ const result = run.results.find((r) => r.component === item.component);
81
+ const outcome: DeployOutcomeState = !result ? "not-run" : result.status === "ok" ? "deployed" : result.status === "gated" ? "gated" : "failed";
82
+ return {
83
+ component: item.component,
84
+ outcome,
85
+ digest: item.digest,
86
+ releaseDigest: input.releaseDigest ?? item.source.releaseDigest ?? null,
87
+ };
88
+ });
89
+ const deployed = components.some((c) => c.outcome === "deployed");
90
+ const failed = components.some((c) => c.outcome === "failed");
91
+ if (!deployed && !failed) return null;
92
+ return {
93
+ version: 1,
94
+ env: plan.to,
95
+ verb: input.verb,
96
+ runId: input.runId,
97
+ timestamp: input.timestamp,
98
+ actor: input.actor,
99
+ releaseDigest: input.releaseDigest,
100
+ status: run.status,
101
+ components,
102
+ };
103
+ }
104
+
105
+ const STATES: readonly string[] = ["deployed", "failed", "gated", "not-run"];
106
+
107
+ function isOutcome(v: unknown): v is DeployOutcome {
108
+ const o = v as Partial<DeployOutcome> | null;
109
+ return (
110
+ o !== null &&
111
+ typeof o === "object" &&
112
+ o.version === 1 &&
113
+ typeof o.env === "string" &&
114
+ typeof o.runId === "string" &&
115
+ typeof o.timestamp === "string" &&
116
+ Array.isArray(o.components) &&
117
+ o.components.every((c) => c && typeof c.component === "string" && STATES.includes(c.outcome) && typeof c.digest === "string")
118
+ );
119
+ }
120
+
121
+ /** Parse the lines of an `outcomes.jsonl`, oldest first. A line that is not an outcome is counted and skipped. */
122
+ export function parseDeployOutcomes(text: string | null): { outcomes: DeployOutcome[]; malformed: number } {
123
+ const outcomes: DeployOutcome[] = [];
124
+ let malformed = 0;
125
+ for (const line of (text ?? "").split("\n").map((l) => l.trim()).filter(Boolean)) {
126
+ try {
127
+ const parsed = JSON.parse(line) as unknown;
128
+ if (isOutcome(parsed)) outcomes.push(parsed);
129
+ else malformed++;
130
+ } catch {
131
+ malformed++;
132
+ }
133
+ }
134
+ return { outcomes, malformed };
135
+ }
136
+
137
+ /** Append one outcome to `<env>/outcomes.jsonl`. Does not push; the caller pushes with the release records. */
138
+ export async function appendDeployOutcome(outcome: DeployOutcome, opts?: { cwd?: string }): Promise<string> {
139
+ const { appendLedgerLine } = await import("./git");
140
+ return appendLedgerLine(outcome.env, OUTCOMES_FILE, JSON.stringify(outcome, sortedJsonReplacer), "Deploy outcome", opts);
141
+ }
142
+
143
+ /** Every outcome recorded for `env`, oldest first, read where `readReleaseLedger` reads; `[]` when none is. */
144
+ export async function readDeployOutcomes(env: string, opts?: import("./git").LedgerLocation): Promise<DeployOutcome[]> {
145
+ const { readBlobFromPath } = await import("./git");
146
+ return parseDeployOutcomes(await readBlobFromPath(env, OUTCOMES_FILE, opts)).outcomes;
147
+ }
@@ -10,19 +10,27 @@
10
10
  * (`../change-set-graph.ts`), and stores the document under its digest
11
11
  * (`./change-set-store.ts`).
12
12
  *
13
+ * Each entry mapped onto a node that has a source location also records that
14
+ * file from the repository root as `source` (#4025), which the overlap report
15
+ * in `workspace status` attributes the entry to work items by.
16
+ *
13
17
  * The graph is read only when the digest is not stored yet. A graph that
14
18
  * can't be read never stops the gate: the document is stored with `graph:
15
19
  * null` and every `node` null, and the caller gets a warning to print.
16
20
  */
17
21
 
18
- import { spawn } from "node:child_process";
22
+ import { execFileSync, spawn } from "node:child_process";
23
+ import { posix } from "node:path";
19
24
  import { mapChangeSetToGraph, type ChangeSetGraphNodes } from "../change-set-graph";
20
25
  import type { ChangeSetDocument, ChangeSetGraph } from "../change-set";
21
26
  import { persistChangeSet, readStoredChangeSet } from "./change-set-store";
22
27
  import { resolveMemberLedger } from "./member-ledger";
23
28
 
24
- /** Reads the node ids of the graph of the project at `projectDir`. */
25
- export type GraphIdReader = (projectDir: string) => Promise<{ ids: string[] } | { error: string }>;
29
+ /**
30
+ * Reads the node ids of the graph of the project at `projectDir`, with each
31
+ * node's source file (relative to `projectDir`) when the graph gives one.
32
+ */
33
+ export type GraphIdReader = (projectDir: string) => Promise<{ ids: string[]; sources?: Record<string, string> } | { error: string }>;
26
34
 
27
35
  const GRAPH_TIMEOUT_MS = 300_000;
28
36
 
@@ -32,7 +40,7 @@ const GRAPH_TIMEOUT_MS = 300_000;
32
40
  * one), as `chant workspace graph` runs each member. `args` are passed after
33
41
  * `graph --format ir`, such as the run's `--param` flags.
34
42
  */
35
- export async function readGraphIds(projectDir: string, args: readonly string[] = []): Promise<{ ids: string[] } | { error: string }> {
43
+ export async function readGraphIds(projectDir: string, args: readonly string[] = []): Promise<{ ids: string[]; sources: Record<string, string> } | { error: string }> {
36
44
  const { readerToolchain, resolveToolchain } = await import("../workspace/member-commands");
37
45
  const { readMemberIr } = await import("../workspace/compose-graph");
38
46
  const { findWorkspaceRoot } = await import("../project-root");
@@ -61,7 +69,9 @@ export async function readGraphIds(projectDir: string, args: readonly string[] =
61
69
  }
62
70
  const read = readMemberIr(out.stdout);
63
71
  if ("reason" in read) return { error: read.reason.message };
64
- return { ids: read.ir.nodes.map((n) => n.id) };
72
+ const sources: Record<string, string> = {};
73
+ for (const n of read.ir.nodes) if (n.sourceLoc?.file) sources[n.id] = n.sourceLoc.file;
74
+ return { ids: read.ir.nodes.map((n) => n.id), sources };
65
75
  }
66
76
 
67
77
  let graphReaderOverride: GraphIdReader | undefined;
@@ -102,6 +112,27 @@ export interface StoreGateChangeSetResult {
102
112
  warning?: string;
103
113
  }
104
114
 
115
+ /**
116
+ * Each node's source file as a path from the repository root (#4025): the
117
+ * graph gives it relative to the member's directory at `cwd`. Undefined when
118
+ * the graph gives none or `cwd` is in no git repository.
119
+ */
120
+ function repoSources(cwd: string, sources: Record<string, string> | undefined): Map<string, string> | undefined {
121
+ if (!sources || Object.keys(sources).length === 0) return undefined;
122
+ let prefix: string;
123
+ try {
124
+ prefix = execFileSync("git", ["rev-parse", "--show-prefix"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
125
+ } catch {
126
+ return undefined;
127
+ }
128
+ const out = new Map<string, string>();
129
+ for (const [id, file] of Object.entries(sources)) {
130
+ const path = posix.normalize(posix.join(prefix, file.split("\\").join("/")));
131
+ if (!path.startsWith("../") && path !== "..") out.set(id, path);
132
+ }
133
+ return out;
134
+ }
135
+
105
136
  /**
106
137
  * Store `doc` under its digest in the member's ledger at `cwd`, mapped onto
107
138
  * the member's graph, unless it is stored already. Does not push; the gate's
@@ -118,7 +149,7 @@ export async function storeGateChangeSet(input: StoreGateChangeSetInput): Promis
118
149
  try {
119
150
  const read = await (input.readGraph ?? gateGraphReader())(cwd);
120
151
  if ("error" in read) warning = read.error;
121
- else nodes = { member, at: input.at ?? null, ids: read.ids };
152
+ else nodes = { member, at: input.at ?? null, ids: read.ids, sources: repoSources(cwd, read.sources) };
122
153
  } catch (err) {
123
154
  warning = err instanceof Error ? err.message : String(err);
124
155
  }
@@ -47,7 +47,7 @@ import { currentGateOrigin, type GateOrigin } from "./gate-origin";
47
47
  import type { GateApprover, GatePolicyDecision, ResolvedGateApproval } from "../op/gate-approval";
48
48
  import type { GateApprovalSource } from "../op/op-waves";
49
49
  import type { GateRunLocator } from "../op/gate-run-locator";
50
- import { readBlobFromPath, readPathSha, readBlobBySha, writeBlobToPath, RefCASConflictError } from "./git";
50
+ import { readBlobFromPath, readPathSha, readBlobBySha, writeBlobToPath, RefCASConflictError, type LedgerLocation } from "./git";
51
51
 
52
52
  // The facts a pending record is written with live apart, so a bundle can import them without git (#3816).
53
53
  export { DEFAULT_GATE_EXPIRY, isApprovalUrl, resolveApprovalUrl } from "./gate-pending";
@@ -519,7 +519,7 @@ async function appendGateLine(
519
519
  */
520
520
  export async function readGateLedger(
521
521
  op: string,
522
- opts?: { cwd?: string },
522
+ opts?: LedgerLocation,
523
523
  ): Promise<{ resolutions: GateResolutionRecord[]; pending: PendingGateRecord[]; malformed: number }> {
524
524
  const content = await readBlobFromPath(DIR, filename(op), opts);
525
525
  if (!content) return { resolutions: [], pending: [], malformed: 0 };
@@ -171,6 +171,21 @@ export interface LedgerFileWrite {
171
171
  expectPriorSha?: string | null;
172
172
  }
173
173
 
174
+ /**
175
+ * One file for {@link writeLedgerFiles} to remove (#4036): retention's
176
+ * garbage collection takes a stored change set, release or template out of
177
+ * the tree in a new commit. The history keeps it.
178
+ */
179
+ export interface LedgerFileRemoval {
180
+ /** The file's full path on the branch. No prefix is added. */
181
+ path: string;
182
+ remove: true;
183
+ /** The blob sha the caller saw at the path; a different sha, or no file, is a conflict. */
184
+ expectPriorSha?: string | null;
185
+ }
186
+
187
+ const isRemoval = (f: LedgerFileWrite | LedgerFileRemoval): f is LedgerFileRemoval => (f as LedgerFileRemoval).remove === true;
188
+
174
189
  /**
175
190
  * Write several files to the branch in one commit (#2538). Paths are full
176
191
  * branch paths, so one commit can write the ledgers of several members, for
@@ -185,9 +200,18 @@ export interface LedgerFileWrite {
185
200
  * of an unchanged directory keeps its sha.
186
201
  */
187
202
  export async function writeLedgerFiles(
188
- files: LedgerFileWrite[],
203
+ files: Array<LedgerFileWrite | LedgerFileRemoval>,
189
204
  commitMessage: string,
190
- opts?: { cwd?: string },
205
+ opts?: {
206
+ cwd?: string;
207
+ /**
208
+ * The branch tip the caller read before deciding what to write (#4036).
209
+ * A different tip is a conflict, thrown at once and never retried here,
210
+ * so a caller whose choice depends on files it does not write (garbage
211
+ * collection reading the gate ledgers) reads again.
212
+ */
213
+ expectTip?: string;
214
+ },
191
215
  ): Promise<string> {
192
216
  const rt = getRuntime();
193
217
  const cwd = opts?.cwd;
@@ -208,8 +232,13 @@ export async function writeLedgerFiles(
208
232
  // kubectl.kubernetes.io/last-applied-configuration annotation) and no
209
233
  // shell-quoting dance around embedded single quotes. Content-addressed
210
234
  // and idempotent, so this stays outside the retry loop below.
211
- const blobs: { path: string; sha: string }[] = [];
235
+ // A removal has no blob: its sha is null, and step 3 deletes the entry.
236
+ const blobs: { path: string; sha: string | null }[] = [];
212
237
  for (const f of files) {
238
+ if (isRemoval(f)) {
239
+ blobs.push({ path: f.path, sha: null });
240
+ continue;
241
+ }
213
242
  const blobResult = await rt.spawn(["git", "hash-object", "-w", "--stdin"], { cwd, stdin: f.content });
214
243
  if (blobResult.exitCode !== 0) {
215
244
  throw ledgerWriteError("git hash-object", f.path, blobResult.stderr);
@@ -283,6 +312,9 @@ export async function writeLedgerFiles(
283
312
  // there instead can observe a newer tip than the listings reflect, which
284
313
  // makes the CAS succeed against a tree built from a stale read.
285
314
  const tip = await getStateBranchTip(cwd);
315
+ if (opts?.expectTip !== undefined && tip !== opts.expectTip) {
316
+ throw new RefCASConflictError(`refs/heads/${STATE_BRANCH}`, opts.expectTip, `the branch moved to ${tip ?? "(none)"} since it was read`);
317
+ }
286
318
  const trees = new Map<string, Map<string, TreeLine>>();
287
319
  const listing = async (dir: string): Promise<Map<string, TreeLine>> => {
288
320
  let entries = trees.get(dir);
@@ -312,16 +344,22 @@ export async function writeLedgerFiles(
312
344
  // rebuild below has each parent in hand.
313
345
  for (const b of blobs) {
314
346
  const { dir, name } = splitPath(b.path);
315
- (await listing(dir)).set(name, { mode: "100644", type: "blob", sha: b.sha });
347
+ if (b.sha === null) (await listing(dir)).delete(name);
348
+ else (await listing(dir)).set(name, { mode: "100644", type: "blob", sha: b.sha });
316
349
  for (let d = dir; d !== ""; d = parentDir(d)) await listing(parentDir(d));
317
350
  }
318
351
 
319
- // 4. Rebuild the touched trees, deepest first, then the root.
352
+ // 4. Rebuild the touched trees, deepest first, then the root. A directory
353
+ // a removal left empty is dropped from its parent, as git itself would.
320
354
  const touched = [...trees.keys()].sort((a, b) => depth(b) - depth(a) || (a < b ? -1 : 1));
321
355
  let rootTreeSha = "";
322
356
  for (const dir of touched) {
357
+ if (dir !== "" && trees.get(dir)!.size === 0) {
358
+ trees.get(parentDir(dir))!.delete(baseName(dir));
359
+ continue;
360
+ }
323
361
  const lines = [...trees.get(dir)!].map(([name, e]) => `${e.mode} ${e.type} ${e.sha}\t${name}`).join("\n");
324
- const result = await rt.spawn(["git", "mktree"], { cwd, stdin: `${lines}\n` });
362
+ const result = await rt.spawn(["git", "mktree"], { cwd, stdin: lines === "" ? "" : `${lines}\n` });
325
363
  if (result.exitCode !== 0) {
326
364
  throw ledgerWriteError(`git mktree (${dir === "" ? "root" : dir})`, path, result.stderr);
327
365
  }
@@ -517,15 +555,30 @@ export async function appendReleaseRecordLine(
517
555
  recordJson: string,
518
556
  opts?: { cwd?: string },
519
557
  ): Promise<string> {
520
- const filename = "releases.jsonl";
558
+ return appendLedgerLine(environment, "releases.jsonl", recordJson, "Release record", opts);
559
+ }
521
560
 
561
+ /**
562
+ * Append one line to `<environment>/<filename>` on the orphan branch, with
563
+ * the same read, append and compare-and-swap retry as
564
+ * {@link appendReleaseRecordLine}. The deploy outcomes of
565
+ * ../lifecycle/deploy-outcome.ts (#4035) are appended through here, beside
566
+ * the environment's `releases.jsonl`.
567
+ */
568
+ export async function appendLedgerLine(
569
+ environment: string,
570
+ filename: string,
571
+ recordJson: string,
572
+ commitMessage: string,
573
+ opts?: { cwd?: string },
574
+ ): Promise<string> {
522
575
  let lastErr: unknown;
523
576
  for (let attempt = 1; attempt <= WRITE_BLOB_RETRY_ATTEMPTS; attempt++) {
524
577
  try {
525
578
  const priorSha = await readPathSha(environment, filename, opts);
526
579
  const existing = priorSha ? await readBlobBySha(priorSha, opts) : null;
527
580
  const content = `${existing ? `${existing.replace(/\n$/, "")}\n` : ""}${recordJson}\n`;
528
- return await writeBlobToPath(environment, filename, content, "Release record", {
581
+ return await writeBlobToPath(environment, filename, content, commitMessage, {
529
582
  ...opts,
530
583
  expectPriorPathSha: priorSha,
531
584
  });
@@ -12,6 +12,10 @@ export * from "./unobserved-gate";
12
12
  export * from "./receipt-plan";
13
13
  export * from "./affected";
14
14
  export * from "./release-ledger";
15
+ export * from "./release-join";
16
+ export * from "./retention-policy";
17
+ export * from "./delivery-metrics";
18
+ export { planLifecycleGc, runLifecycleGc, type GcFile, type GcKept, type GcKeepCode, type GcKeepReason, type GcKind, type GcReport, type LifecycleGcPlan } from "./retention";
15
19
  export * from "./build-ledger";
16
20
  export * from "./build-ledger-store";
17
21
  export * from "./oras-referrer-lookup";