@intentius/chant 0.124.88 → 0.124.90

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 (377) hide show
  1. package/dist/actor.d.ts +36 -1
  2. package/dist/actor.d.ts.map +1 -1
  3. package/dist/actor.js +39 -1
  4. package/dist/chant-install.d.ts.map +1 -1
  5. package/dist/chant-install.js +1 -2
  6. package/dist/ci-base.d.ts +30 -0
  7. package/dist/ci-base.d.ts.map +1 -0
  8. package/dist/ci-base.js +33 -0
  9. package/dist/ci-comment-commands.d.ts +193 -0
  10. package/dist/ci-comment-commands.d.ts.map +1 -0
  11. package/dist/ci-comment-commands.js +353 -0
  12. package/dist/ci-comment-replies.d.ts +40 -0
  13. package/dist/ci-comment-replies.d.ts.map +1 -0
  14. package/dist/ci-comment-replies.js +59 -0
  15. package/dist/ci-evidence-from-job.d.ts +25 -0
  16. package/dist/ci-evidence-from-job.d.ts.map +1 -1
  17. package/dist/ci-evidence-from-job.js +43 -2
  18. package/dist/ci-evidence-jobs.d.ts +30 -1
  19. package/dist/ci-evidence-jobs.d.ts.map +1 -1
  20. package/dist/ci-evidence-jobs.js +46 -3
  21. package/dist/ci-image.d.ts +21 -4
  22. package/dist/ci-image.d.ts.map +1 -1
  23. package/dist/ci-image.js +62 -10
  24. package/dist/ci-job-guard.d.ts +42 -45
  25. package/dist/ci-job-guard.d.ts.map +1 -1
  26. package/dist/ci-job-guard.js +206 -3
  27. package/dist/ci-note-commands.d.ts +104 -4
  28. package/dist/ci-note-commands.d.ts.map +1 -1
  29. package/dist/ci-note-commands.js +131 -38
  30. package/dist/ci-product-words.d.ts +42 -0
  31. package/dist/ci-product-words.d.ts.map +1 -1
  32. package/dist/ci-product-words.js +25 -0
  33. package/dist/ci-product.d.ts +72 -1
  34. package/dist/ci-product.d.ts.map +1 -1
  35. package/dist/ci-product.js +73 -6
  36. package/dist/cli/commands/build.d.ts.map +1 -1
  37. package/dist/cli/commands/build.js +29 -2
  38. package/dist/cli/handlers/approve.d.ts.map +1 -1
  39. package/dist/cli/handlers/approve.js +2 -1
  40. package/dist/cli/handlers/ci-check.d.ts +1 -1
  41. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  42. package/dist/cli/handlers/ci-check.js +17 -7
  43. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  44. package/dist/cli/handlers/ci-evidence.js +33 -7
  45. package/dist/cli/handlers/components.d.ts.map +1 -1
  46. package/dist/cli/handlers/components.js +3 -1
  47. package/dist/cli/handlers/generated-check.d.ts +8 -0
  48. package/dist/cli/handlers/generated-check.d.ts.map +1 -1
  49. package/dist/cli/handlers/generated-check.js +31 -1
  50. package/dist/cli/handlers/lock.d.ts.map +1 -1
  51. package/dist/cli/handlers/lock.js +121 -4
  52. package/dist/cli/handlers/pr-comment.d.ts +33 -0
  53. package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
  54. package/dist/cli/handlers/pr-comment.js +201 -0
  55. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  56. package/dist/cli/handlers/pr-env.js +6 -3
  57. package/dist/cli/handlers/pr-notes.d.ts.map +1 -1
  58. package/dist/cli/handlers/pr-notes.js +23 -1
  59. package/dist/cli/handlers/pr.d.ts +23 -1
  60. package/dist/cli/handlers/pr.d.ts.map +1 -1
  61. package/dist/cli/handlers/pr.js +71 -23
  62. package/dist/cli/handlers/promote.d.ts.map +1 -1
  63. package/dist/cli/handlers/promote.js +2 -1
  64. package/dist/cli/handlers/release.d.ts.map +1 -1
  65. package/dist/cli/handlers/release.js +11 -2
  66. package/dist/cli/handlers/run-wave.d.ts.map +1 -1
  67. package/dist/cli/handlers/run-wave.js +180 -4
  68. package/dist/cli/handlers/run.d.ts.map +1 -1
  69. package/dist/cli/handlers/run.js +2 -1
  70. package/dist/cli/main.d.ts.map +1 -1
  71. package/dist/cli/main.js +41 -2
  72. package/dist/cli/parse-args.d.ts.map +1 -1
  73. package/dist/cli/parse-args.js +31 -0
  74. package/dist/cli/registry.d.ts +19 -1
  75. package/dist/cli/registry.d.ts.map +1 -1
  76. package/dist/components/auto-release.d.ts.map +1 -1
  77. package/dist/components/auto-release.js +2 -1
  78. package/dist/components/pr-checks.d.ts +97 -6
  79. package/dist/components/pr-checks.d.ts.map +1 -1
  80. package/dist/components/pr-checks.js +107 -13
  81. package/dist/components/pr-pipeline.d.ts +19 -14
  82. package/dist/components/pr-pipeline.d.ts.map +1 -1
  83. package/dist/components/pr-pipeline.js +7 -13
  84. package/dist/components/product-pipeline.d.ts +96 -3
  85. package/dist/components/product-pipeline.d.ts.map +1 -1
  86. package/dist/components/product-pipeline.js +120 -14
  87. package/dist/components/product-plan.d.ts +203 -6
  88. package/dist/components/product-plan.d.ts.map +1 -1
  89. package/dist/components/product-plan.js +250 -43
  90. package/dist/drift-record.d.ts +7 -0
  91. package/dist/drift-record.d.ts.map +1 -1
  92. package/dist/drift-record.js +19 -0
  93. package/dist/floor-table.data.d.ts.map +1 -1
  94. package/dist/floor-table.data.js +63 -31
  95. package/dist/forge-check/contract.d.ts +11 -1
  96. package/dist/forge-check/contract.d.ts.map +1 -1
  97. package/dist/forge-check/contract.js +4 -1
  98. package/dist/forge-check/index.d.ts +2 -0
  99. package/dist/forge-check/index.d.ts.map +1 -1
  100. package/dist/forge-check/index.js +2 -0
  101. package/dist/gate-resume-run.d.ts +9 -1
  102. package/dist/gate-resume-run.d.ts.map +1 -1
  103. package/dist/gate-resume-run.js +26 -3
  104. package/dist/generated-check.d.ts +18 -4
  105. package/dist/generated-check.d.ts.map +1 -1
  106. package/dist/generated-check.js +37 -5
  107. package/dist/image-pins.d.ts +26 -0
  108. package/dist/image-pins.d.ts.map +1 -0
  109. package/dist/image-pins.js +19 -0
  110. package/dist/lexicon.d.ts +93 -4
  111. package/dist/lexicon.d.ts.map +1 -1
  112. package/dist/lifecycle/gate-applied.d.ts +9 -0
  113. package/dist/lifecycle/gate-applied.d.ts.map +1 -1
  114. package/dist/lifecycle/git.d.ts +11 -0
  115. package/dist/lifecycle/git.d.ts.map +1 -1
  116. package/dist/lifecycle/git.js +30 -3
  117. package/dist/lifecycle/publish-npm.d.ts +11 -0
  118. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  119. package/dist/lifecycle/publish-npm.js +27 -1
  120. package/dist/lifecycle/reach-locks.d.ts +131 -0
  121. package/dist/lifecycle/reach-locks.d.ts.map +1 -0
  122. package/dist/lifecycle/reach-locks.js +118 -0
  123. package/dist/lifecycle/release-cut.d.ts +3 -1
  124. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  125. package/dist/lifecycle/release-cut.js +15 -0
  126. package/dist/lifecycle/release-images.d.ts.map +1 -1
  127. package/dist/lifecycle/release-images.js +1 -2
  128. package/dist/notify-product.d.ts +12 -3
  129. package/dist/notify-product.d.ts.map +1 -1
  130. package/dist/notify-product.js +10 -6
  131. package/dist/op/activities/source-release.d.ts.map +1 -1
  132. package/dist/op/activities/source-release.js +2 -1
  133. package/dist/op/activities/source-rollback.d.ts.map +1 -1
  134. package/dist/op/activities/source-rollback.js +2 -1
  135. package/dist/op/apply-status.d.ts +84 -0
  136. package/dist/op/apply-status.d.ts.map +1 -0
  137. package/dist/op/apply-status.js +106 -0
  138. package/dist/op/before-merge-decide.d.ts +102 -0
  139. package/dist/op/before-merge-decide.d.ts.map +1 -0
  140. package/dist/op/before-merge-decide.js +142 -0
  141. package/dist/op/before-merge-done.d.ts +56 -0
  142. package/dist/op/before-merge-done.d.ts.map +1 -0
  143. package/dist/op/before-merge-done.js +69 -0
  144. package/dist/op/before-merge-store.d.ts +20 -0
  145. package/dist/op/before-merge-store.d.ts.map +1 -0
  146. package/dist/op/before-merge-store.js +48 -0
  147. package/dist/op/before-merge.d.ts +150 -0
  148. package/dist/op/before-merge.d.ts.map +1 -0
  149. package/dist/op/before-merge.js +207 -0
  150. package/dist/op/follow-on-run.d.ts +117 -0
  151. package/dist/op/follow-on-run.d.ts.map +1 -0
  152. package/dist/op/follow-on-run.js +154 -0
  153. package/dist/op/follow-on-store.d.ts +17 -0
  154. package/dist/op/follow-on-store.d.ts.map +1 -0
  155. package/dist/op/follow-on-store.js +54 -0
  156. package/dist/op/gate.d.ts +6 -0
  157. package/dist/op/gate.d.ts.map +1 -1
  158. package/dist/op/gate.js +10 -1
  159. package/dist/op/index.d.ts +5 -1
  160. package/dist/op/index.d.ts.map +1 -1
  161. package/dist/op/index.js +2 -0
  162. package/dist/op/op-waves-after-plan.d.ts +13 -0
  163. package/dist/op/op-waves-after-plan.d.ts.map +1 -1
  164. package/dist/op/op-waves-evidence-jobs.d.ts +10 -2
  165. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
  166. package/dist/op/op-waves-evidence-jobs.js +19 -5
  167. package/dist/op/op-waves-follow-on.d.ts +162 -0
  168. package/dist/op/op-waves-follow-on.d.ts.map +1 -0
  169. package/dist/op/op-waves-follow-on.js +355 -0
  170. package/dist/op/op-waves-render-spec.d.ts +100 -0
  171. package/dist/op/op-waves-render-spec.d.ts.map +1 -0
  172. package/dist/op/op-waves-render-spec.js +162 -0
  173. package/dist/op/op-waves-run.d.ts +148 -6
  174. package/dist/op/op-waves-run.d.ts.map +1 -1
  175. package/dist/op/op-waves-run.js +873 -100
  176. package/dist/op/op-waves-split.d.ts +122 -0
  177. package/dist/op/op-waves-split.d.ts.map +1 -0
  178. package/dist/op/op-waves-split.js +166 -0
  179. package/dist/op/op-waves.d.ts +24 -0
  180. package/dist/op/op-waves.d.ts.map +1 -1
  181. package/dist/op/op-waves.js +18 -1
  182. package/dist/op/schedule-overdue.d.ts +15 -1
  183. package/dist/op/schedule-overdue.d.ts.map +1 -1
  184. package/dist/op/schedule-overdue.js +77 -5
  185. package/dist/op/stage-hooks.d.ts +36 -1
  186. package/dist/op/stage-hooks.d.ts.map +1 -1
  187. package/dist/op/stage-hooks.js +17 -3
  188. package/dist/op/wave-stop.d.ts +67 -0
  189. package/dist/op/wave-stop.d.ts.map +1 -0
  190. package/dist/op/wave-stop.js +129 -0
  191. package/dist/planned-files.d.ts +76 -0
  192. package/dist/planned-files.d.ts.map +1 -0
  193. package/dist/planned-files.js +108 -0
  194. package/dist/pr-forge-job.d.ts +22 -0
  195. package/dist/pr-forge-job.d.ts.map +1 -0
  196. package/dist/pr-forge-job.js +46 -0
  197. package/dist/pr-loop.d.ts +3 -6
  198. package/dist/pr-loop.d.ts.map +1 -1
  199. package/dist/pr-loop.js +4 -81
  200. package/dist/pr-plan-note.d.ts +97 -0
  201. package/dist/pr-plan-note.d.ts.map +1 -1
  202. package/dist/pr-plan-note.js +94 -1
  203. package/dist/pr-post.d.ts +28 -3
  204. package/dist/pr-post.d.ts.map +1 -1
  205. package/dist/pr-post.js +146 -13
  206. package/dist/pr-status.d.ts +16 -0
  207. package/dist/pr-status.d.ts.map +1 -0
  208. package/dist/pr-status.js +90 -0
  209. package/dist/ref-gate-init.d.ts +16 -2
  210. package/dist/ref-gate-init.d.ts.map +1 -1
  211. package/dist/ref-gate-init.js +24 -13
  212. package/dist/release-floors.d.ts +39 -1
  213. package/dist/release-floors.d.ts.map +1 -1
  214. package/dist/release-floors.js +63 -25
  215. package/dist/render-module.d.ts +15 -0
  216. package/dist/render-module.d.ts.map +1 -0
  217. package/dist/render-module.js +73 -0
  218. package/dist/state-migration.d.ts.map +1 -1
  219. package/dist/state-migration.js +1 -2
  220. package/dist/wave-blocked.d.ts +7 -1
  221. package/dist/wave-blocked.d.ts.map +1 -1
  222. package/dist/wave-blocked.js +7 -2
  223. package/dist/wave-runtime.mjs +366 -350
  224. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  225. package/dist/workspace/ci-green-cli.js +3 -2
  226. package/dist/workspace/release-train.d.ts.map +1 -1
  227. package/dist/workspace/release-train.js +2 -1
  228. package/dist/workspace/release-workflow.d.ts +4 -3
  229. package/dist/workspace/release-workflow.d.ts.map +1 -1
  230. package/dist/workspace/release-workflow.js +10 -7
  231. package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
  232. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  233. package/dist/workspace/trust/check-evidence-report.js +15 -8
  234. package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
  235. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
  236. package/dist/workspace/trust/ref-gate-cli.js +30 -10
  237. package/dist/workspace/workspace-run.d.ts.map +1 -1
  238. package/dist/workspace/workspace-run.js +2 -1
  239. package/package.json +1 -1
  240. package/src/actor.test.ts +68 -2
  241. package/src/actor.ts +61 -1
  242. package/src/chant-install.test.ts +2 -3
  243. package/src/chant-install.ts +1 -2
  244. package/src/ci-base.test.ts +41 -0
  245. package/src/ci-base.ts +43 -0
  246. package/src/ci-comment-commands.test.ts +439 -0
  247. package/src/ci-comment-commands.ts +428 -0
  248. package/src/ci-comment-replies.ts +78 -0
  249. package/src/ci-commit.test.ts +2 -3
  250. package/src/ci-evidence-from-job.test.ts +18 -0
  251. package/src/ci-evidence-from-job.ts +58 -2
  252. package/src/ci-evidence-jobs.ts +50 -5
  253. package/src/ci-image.test.ts +130 -10
  254. package/src/ci-image.ts +85 -12
  255. package/src/ci-job-guard.before-merge.test.ts +148 -0
  256. package/src/ci-job-guard.follow-on-record.test.ts +137 -0
  257. package/src/ci-job-guard.follow-on.test.ts +144 -0
  258. package/src/ci-job-guard.ts +221 -3
  259. package/src/ci-note-commands.test.ts +76 -1
  260. package/src/ci-note-commands.ts +198 -46
  261. package/src/ci-product-words.ts +59 -0
  262. package/src/ci-product.ts +90 -6
  263. package/src/cli/commands/build.test.ts +41 -0
  264. package/src/cli/commands/build.ts +27 -2
  265. package/src/cli/handlers/approve.ts +2 -1
  266. package/src/cli/handlers/ci-check.ts +19 -7
  267. package/src/cli/handlers/ci-evidence.ts +29 -8
  268. package/src/cli/handlers/components.ts +3 -1
  269. package/src/cli/handlers/generated-check.ts +31 -1
  270. package/src/cli/handlers/lock-reach.test.ts +103 -0
  271. package/src/cli/handlers/lock.ts +100 -4
  272. package/src/cli/handlers/pr-comment.ts +187 -0
  273. package/src/cli/handlers/pr-env.ts +6 -3
  274. package/src/cli/handlers/pr-notes.ts +30 -6
  275. package/src/cli/handlers/pr-record.test.ts +1 -1
  276. package/src/cli/handlers/pr.ts +64 -21
  277. package/src/cli/handlers/promote.ts +2 -1
  278. package/src/cli/handlers/release.e2e.test.ts +35 -0
  279. package/src/cli/handlers/release.ts +14 -2
  280. package/src/cli/handlers/run-wave.ts +170 -4
  281. package/src/cli/handlers/run.ts +2 -1
  282. package/src/cli/main.ts +41 -2
  283. package/src/cli/parse-args.ts +23 -0
  284. package/src/cli/registry.ts +19 -1
  285. package/src/components/auto-release.ts +2 -1
  286. package/src/components/pr-checks.ts +165 -17
  287. package/src/components/pr-pipeline.ts +22 -18
  288. package/src/components/product-pipeline.apply-status.test.ts +50 -0
  289. package/src/components/product-pipeline.ts +204 -17
  290. package/src/components/product-plan.test.ts +60 -4
  291. package/src/components/product-plan.ts +367 -50
  292. package/src/drift-record.test.ts +20 -0
  293. package/src/drift-record.ts +16 -0
  294. package/src/floor-table.data.ts +63 -31
  295. package/src/forge-check/contract.ts +12 -1
  296. package/src/forge-check/forge-check.test.ts +17 -0
  297. package/src/forge-check/index.ts +2 -0
  298. package/src/gate-resume-run.ts +27 -3
  299. package/src/generated-check.e2e.test.ts +21 -1
  300. package/src/generated-check.test.ts +66 -0
  301. package/src/generated-check.ts +51 -10
  302. package/src/image-pins.ts +31 -0
  303. package/src/lexicon.ts +89 -1
  304. package/src/lifecycle/gate-applied.ts +7 -0
  305. package/src/lifecycle/git.test.ts +48 -0
  306. package/src/lifecycle/git.ts +27 -4
  307. package/src/lifecycle/publish-npm.ts +31 -1
  308. package/src/lifecycle/reach-locks.test.ts +87 -0
  309. package/src/lifecycle/reach-locks.ts +169 -0
  310. package/src/lifecycle/release-cut.ts +17 -1
  311. package/src/lifecycle/release-images.test.ts +56 -0
  312. package/src/lifecycle/release-images.ts +1 -2
  313. package/src/notify-product.ts +19 -8
  314. package/src/op/activities/source-release.ts +2 -1
  315. package/src/op/activities/source-rollback.ts +2 -1
  316. package/src/op/apply-status.test.ts +83 -0
  317. package/src/op/apply-status.ts +132 -0
  318. package/src/op/before-merge-decide.ts +190 -0
  319. package/src/op/before-merge-done.ts +99 -0
  320. package/src/op/before-merge-store.ts +44 -0
  321. package/src/op/before-merge.test.ts +201 -0
  322. package/src/op/before-merge.ts +266 -0
  323. package/src/op/follow-on-run.ts +206 -0
  324. package/src/op/follow-on-store.ts +54 -0
  325. package/src/op/gate-resume.test.ts +27 -0
  326. package/src/op/gate.ts +16 -1
  327. package/src/op/index.ts +15 -0
  328. package/src/op/op-waves-after-plan.ts +13 -0
  329. package/src/op/op-waves-evidence-jobs.ts +21 -7
  330. package/src/op/op-waves-follow-on-record.test.ts +152 -0
  331. package/src/op/op-waves-follow-on.test.ts +247 -0
  332. package/src/op/op-waves-follow-on.ts +385 -0
  333. package/src/op/op-waves-notify-words.test.ts +18 -0
  334. package/src/op/op-waves-render-spec.test.ts +159 -0
  335. package/src/op/op-waves-render-spec.ts +171 -0
  336. package/src/op/op-waves-run.ts +973 -94
  337. package/src/op/op-waves-split-product.test.ts +288 -0
  338. package/src/op/op-waves-split-step.test.ts +298 -0
  339. package/src/op/op-waves-split.test.ts +196 -0
  340. package/src/op/op-waves-split.ts +189 -0
  341. package/src/op/op-waves.ts +31 -3
  342. package/src/op/schedule-overdue.test.ts +72 -1
  343. package/src/op/schedule-overdue.ts +84 -6
  344. package/src/op/stage-hooks.ts +52 -4
  345. package/src/op/wave-stop.test.ts +72 -0
  346. package/src/op/wave-stop.ts +139 -0
  347. package/src/planned-files.test.ts +80 -0
  348. package/src/planned-files.ts +134 -0
  349. package/src/pr-forge-job.test.ts +53 -0
  350. package/src/pr-forge-job.ts +46 -0
  351. package/src/pr-loop-narrowed.test.ts +2 -1
  352. package/src/pr-loop-words.test.ts +2 -1
  353. package/src/pr-loop.test.ts +1 -2
  354. package/src/pr-loop.ts +4 -80
  355. package/src/pr-plan-note.ts +155 -3
  356. package/src/pr-post-replan.test.ts +144 -0
  357. package/src/pr-post-subject.test.ts +230 -0
  358. package/src/pr-post.test.ts +2 -1
  359. package/src/pr-post.ts +151 -15
  360. package/src/pr-status.ts +91 -0
  361. package/src/ref-gate-init.ts +30 -11
  362. package/src/release-floors.ts +81 -25
  363. package/src/render-module.ts +73 -0
  364. package/src/state-migration-record.test.ts +2 -3
  365. package/src/state-migration.ts +1 -2
  366. package/src/wave-blocked.ts +9 -4
  367. package/src/workspace/ci-green-cli.ts +3 -2
  368. package/src/workspace/ci-green-workflow.test.ts +32 -1
  369. package/src/workspace/release-train.ts +2 -1
  370. package/src/workspace/release-workflow.test.ts +36 -5
  371. package/src/workspace/release-workflow.ts +10 -7
  372. package/src/workspace/trust/check-evidence-report.ts +15 -8
  373. package/src/workspace/trust/check-evidence.test.ts +5 -0
  374. package/src/workspace/trust/ref-gate-cli.ts +30 -8
  375. package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
  376. package/src/workspace/trust/ref-gate.test.ts +10 -0
  377. package/src/workspace/workspace-run.ts +2 -1
@@ -25,6 +25,9 @@
25
25
  * target's own variables and secrets, and an optional write probe before the
26
26
  * plan. A target is the note's and the status's member: `pr-post --member
27
27
  * <target>`, so each target has its note and its `<product>/plan/<target>`.
28
+ * With `evidence`, a target's note job (GitLab: `<target>-plan-evidence`)
29
+ * signs `plan:<target>` and `policy:<target>` (#4978,
30
+ * `targetEvidenceCheck`): one target's plan says nothing of another's.
28
31
  *
29
32
  * The forge lexicons render these descriptors
30
33
  * (`generateProductPlanPipeline` in each): the products call them in
@@ -36,7 +39,8 @@ import type { CiRunner } from "../ci-jobs";
36
39
  import type { CiProductWords } from "../ci-product-words";
37
40
  import type { PrPlanNoteWords } from "../pr-plan-note";
38
41
  import { assertPipelineEvidence, evidenceIdTokens, evidenceKeyEnv, evidenceKeyless, gitlabOpenEvidenceDir, openEvidenceLines, planEvidenceLines, type PipelineEvidence } from "../ci-evidence-jobs";
39
- import { gitlabPlanJobName, PR_LOOP_REPORT_DIR, PR_PLAN_NOTE_JOB, prLoopPassedEnv, prLoopPostJob, prLoopRunner, type PrLoopPipelineOptions } from "./pr-pipeline";
42
+ import { gitlabPlanJobName, PR_LOCK_JOB, PR_LOOP_REPORT_DIR, PR_PLAN_NOTE_JOB, prLoopPassedEnv, prLoopPostJob, prLoopRunner, withProductBin, type PrLoopPipelineOptions } from "./pr-pipeline";
43
+ import { LOCK_REACH_ENV } from "../lifecycle/reach-locks";
40
44
  import { GITHUB_JOB_TOKEN } from "../ci-jobs";
41
45
  import { cloudLogin, type CloudLoginSpec } from "../ci-login";
42
46
  import type { OpWaveRunStep } from "../lexicon";
@@ -44,6 +48,9 @@ import { controlNoteCheckout, type ControlNoteCheckout, type ControlTarget } fro
44
48
  import { commentLine, productStatusContext } from "../ci-product-words";
45
49
  import { PLAN_WATCHES_ENV, scheduledWatchProblem, type ScheduledWatch } from "../op/schedule-overdue";
46
50
  import { PLAN_RUN_OP, PLAN_RUN_RECORD_FILE } from "../pr-plan-record";
51
+ import { idTokenVar, tradedClouds, type CloudTradeSpec } from "../ci-identity";
52
+ import { prNoteMarker } from "../pr-loop";
53
+ import { PRODUCT_MARKER_NAME } from "../pr-plan-note";
47
54
 
48
55
  /** The variable the plan-note job reads the product's note words from (#4799), as JSON. Set from the pipeline, never from the report. */
49
56
  export const PR_PLAN_NOTE_WORDS_ENV = "CHANT_PLAN_NOTE_WORDS";
@@ -71,6 +78,45 @@ export interface ProductPlanTarget {
71
78
  login?: CloudLoginSpec;
72
79
  /** OIDC tokens this target's plan job requests besides its login's, `{ <variable>: <audience> }`, in place of the plan's {@link ProductPlanOptions.idTokens}. */
73
80
  idTokens?: Record<string, string>;
81
+ /** This target's trade (#4963), in place of the plan's {@link ProductPlanOptions.trade}. A target gives one of `login` and `trade`. */
82
+ trade?: CloudTradeSpec;
83
+ }
84
+
85
+ /**
86
+ * What the comment re-plan does besides answering the plan command (#4963),
87
+ * `replan: { ... }` in place of `replan: true`.
88
+ */
89
+ export interface ProductPlanReplanOptions {
90
+ /**
91
+ * Re-plan from `workflow_dispatch` too, on GitHub and Forgejo: the inputs
92
+ * `pr` (the pull request) and `argument` (default `argument`; the target,
93
+ * or the one word {@link PLAN_ARGUMENT_ENV} reads, such as terragucci's
94
+ * `root`). Either forge lets only someone who can write to the repository
95
+ * dispatch, so the decision asks no permission for it. On GitLab a web
96
+ * pipeline of the target branch with `CHANT_PREVIEW_PR` and
97
+ * `CHANT_PREVIEW_COMMENT` is the dispatch already, so it renders nothing
98
+ * more there.
99
+ */
100
+ dispatch?: boolean | { argument?: string };
101
+ /**
102
+ * Reply to a `/<product>` comment no other job takes (#4963), on GitHub
103
+ * and Forgejo: a word that is not the plan command, a target that is none
104
+ * of the plan's, and a pull request from a fork with `forks: "skip"`. The
105
+ * reply names the commands. `others` are the comments the product's own
106
+ * jobs answer, such as `/terragucci apply`: the re-plan leaves them alone.
107
+ * With targets, the first target's re-plan job replies. GitLab's
108
+ * note-commands job answers every comment already.
109
+ */
110
+ reply?: boolean | { others?: string[] };
111
+ /**
112
+ * Reply "not affected" for a re-plan narrowed to one argument the change
113
+ * does not reach (#4963): when the hand-off's note says `nothing` (or a
114
+ * `PrReport` says `nothing`), the re-plan's note job comments
115
+ * `<product>: <argument> is not affected by this pull request, so
116
+ * nothing was planned.` and leaves the note and the status as they were
117
+ * (`pr-post --not-affected <argument>`).
118
+ */
119
+ notAffected?: boolean;
74
120
  }
75
121
 
76
122
  /**
@@ -109,6 +155,28 @@ export interface ProductPlanReplanJob {
109
155
  post: { command: string; env: Record<string, string>; setup?: string[] };
110
156
  /** The artifact the note job (GitHub, Forgejo) or the re-plan job (GitLab) keeps the directory as. */
111
157
  artifact: string;
158
+ /** With `dispatch` (#4963), GitHub and Forgejo: the `workflow_dispatch` input that names the argument. */
159
+ dispatch?: { argument: string };
160
+ /** With `reply` (#4963), GitHub and Forgejo, on one re-plan job: the product's prefix and the comments other jobs answer. */
161
+ reply?: { prefix: string; others: string[] };
162
+ /** With `notAffected` (#4963): the note job's command carries `--not-affected`, and reads the argument as {@link PLAN_ARGUMENT_ENV}. */
163
+ notAffected?: true;
164
+ }
165
+
166
+ /**
167
+ * The one word a comment re-plan takes after the command (#4899): letters,
168
+ * digits and `_./@+=,:-`, and (#4984) never starting with `-`, so a flag
169
+ * such as `--target=x` is refused rather than read as a root. The source
170
+ * of a regular expression, without anchors.
171
+ */
172
+ export const REPLAN_WORD_SOURCE = "[A-Za-z0-9_.\\/@+=,:][A-Za-z0-9_.\\/@+=,:-]*";
173
+
174
+ /** {@link REPLAN_WORD_SOURCE} anchored, as the re-plan's `node -e` program writes it between slashes. */
175
+ const REPLAN_WORD_JS = `^${REPLAN_WORD_SOURCE}$`;
176
+
177
+ /** Whether `word` is one a re-plan takes (#4984). */
178
+ export function isReplanWord(word: string): boolean {
179
+ return new RegExp(`^${REPLAN_WORD_SOURCE}$`).test(word);
112
180
  }
113
181
 
114
182
  /** The variable a comment re-plan's one argument reaches the plan verb in (#4899). Empty on a pull request's own plan. */
@@ -206,7 +274,37 @@ export interface ProductPlanOptions {
206
274
  * pipeline of the target branch for the comment, which runs the re-plan
207
275
  * jobs whose target the comment names.
208
276
  */
209
- replan?: boolean;
277
+ replan?: boolean | ProductPlanReplanOptions;
278
+ /**
279
+ * The plan job's trade (#4963): chant's trade of the job's OIDC token for
280
+ * the plan identities' own credentials (`@intentius/chant/ci-identity`,
281
+ * #4296), before the change is checked out, as terragucci's re-plan
282
+ * trades. The plan job and the re-plan job trade in a step of their own
283
+ * (GitHub, Forgejo: after the pending status and the re-plan's decision,
284
+ * before the checkout; GitLab: the script's first lines, before the
285
+ * re-plan checks out the head), and every later step starts without the
286
+ * variables a token is requested with, so the change's code holds the
287
+ * traded credentials and no OIDC token. Give one of `login` and `trade`.
288
+ */
289
+ trade?: CloudTradeSpec;
290
+ /**
291
+ * The previous note's product marker for the plan verb (#4963), on GitHub
292
+ * and Forgejo: a step before the checkout, which alone holds the job's
293
+ * token, finds the pull request's note by chant's marker and sets
294
+ * `CHANT_PLAN_PREVIOUS_MARKER` to the body of its second line, the
295
+ * product's own (`noteWords.productMarker`, a hand-off's `marker`), so a
296
+ * plan verb such as `yodel plan` reads the digest subject it left there
297
+ * and says what moved. Empty when there is no note yet. The body was
298
+ * checked against the marker's pattern before chant posted it, and is
299
+ * checked again. Needs `noteWords.productMarker`. GitLab's plan job holds
300
+ * no token to read a note with, so it takes none.
301
+ *
302
+ * @deprecated #4972: hand the plan's `subject` in the plan note hand-off
303
+ * instead. The note job compares it with the previous note's on every
304
+ * forge and says what changed, so the plan job reads no note. This option
305
+ * still works on GitHub and Forgejo.
306
+ */
307
+ previousMarker?: boolean;
210
308
  /**
211
309
  * Lines the note job runs (#4931), on GitHub and Forgejo, in the job that
212
310
  * holds the token and none of the change's code: `before` after the report
@@ -216,8 +314,13 @@ export interface ProductPlanOptions {
216
314
  * note's counts, such as terragucci's notice naming whose review does not
217
315
  * count. They reach the job's token as `GITHUB_TOKEN`. GitLab's note job
218
316
  * posts every open merge request's note in one run, so it takes none.
317
+ *
318
+ * With `pullRequest` (#4963) the lines also read the pull request and the
319
+ * commit planned as `PR_NUMBER` and `HEAD_SHA`, the note's own, which in
320
+ * a re-plan's note job come from the re-plan job, such as terragucci's
321
+ * notice and approval status, which ask the forge about the head.
219
322
  */
220
- noteSteps?: { before?: string[]; after?: string[] };
323
+ noteSteps?: { before?: string[]; after?: string[]; pullRequest?: boolean };
221
324
  /**
222
325
  * The product's own scheduled jobs the note job checks for having stopped
223
326
  * (#4888), such as terragucci's drift job: each a `ScheduledWatch` with
@@ -226,7 +329,10 @@ export interface ProductPlanOptions {
226
329
  * so `pr-post` asks the forge when each last ran, in its checkout of the
227
330
  * target branch's commit, and adds the line for one that is overdue under
228
331
  * the note's counts. They reach it as `CHANT_PLAN_WATCHES`, from the
229
- * pipeline, never from the plan job's report.
332
+ * pipeline, never from the plan job's report. #4988: a watch's `targets`
333
+ * scope it to those targets' notes, such as an environment's drift
334
+ * watch to that environment's note; left out, every target's note checks
335
+ * it.
230
336
  */
231
337
  watches?: ScheduledWatch[];
232
338
  /**
@@ -243,6 +349,64 @@ export interface ProductPlanOptions {
243
349
  * Unsigned, as `pr-plan`'s is (#4328). Default off.
244
350
  */
245
351
  record?: boolean;
352
+ /**
353
+ * What the lock job locks under `locks: "plan"` (#4979): the targets the
354
+ * change reaches, by the product's reach line, in place of what a
355
+ * `PrReport` selected. `command` is one shell line that prints the target
356
+ * names the change from `$BASE_SHA` to `$HEAD_SHA` reaches, one a line,
357
+ * reading the change's files as data from git (`git diff`, `git show`),
358
+ * such as terragucci's roots, Terragrunt units or Atmos instances. It
359
+ * runs at the target branch's commit, after chant fetched the pull
360
+ * request's head and checked it is the head the job was started for
361
+ * (`chant lock --reach`, ../lifecycle/reach-locks.ts), so none of the
362
+ * change's code runs in the job that holds the write token. `gate` names
363
+ * the lock file, `_locks/<gate>.json` (default the pull request loop's).
364
+ *
365
+ * GitHub and Forgejo run one `lock` job on each push of a pull request
366
+ * from this repository, beside the plan, and the `unlock` job on close.
367
+ * On GitLab, where a merge request's pipeline is built from its own files,
368
+ * the `lock` job runs in the target branch's plan notes pipeline and locks
369
+ * every open merge request (`--open`), releasing the locks of one that is
370
+ * no longer open; with `noteCommands` the comment lock and unlock jobs
371
+ * answer `/<product> lock` and `/<product> unlock` there too.
372
+ */
373
+ reach?: { command: string; gate?: string };
374
+ }
375
+
376
+ /** The lock job a product plan with {@link ProductPlanOptions.reach} writes (#4979): its command and the values the command reads. */
377
+ export interface ProductPlanReachLock {
378
+ jobName: typeof PR_LOCK_JOB;
379
+ command: string;
380
+ env: Record<string, string>;
381
+ runner?: CiRunner;
382
+ }
383
+
384
+ /**
385
+ * The reach lock job (#4979), under `locks: "plan"` with `reach`: `chant lock
386
+ * --reach` through the words' bin, with the reach line as
387
+ * {@link LOCK_REACH_ENV}. On GitHub and Forgejo it locks the pull request of
388
+ * the event; on GitLab every open merge request into the branch.
389
+ */
390
+ export function productPlanReachLock(forge: ForgeKind, loop: Pick<PrLoopPipelineOptions, "locks" | "runners"> & { plan: Pick<ProductPlanOptions, "reach"> }, words: CiProductWords): ProductPlanReachLock | undefined {
391
+ const reach = loop.plan.reach;
392
+ if (!reach) return undefined;
393
+ if (loop.locks !== "plan") throw new Error("the product plan's reach says what the lock job locks, and there is none without locks: \"plan\"; set locks: \"plan\", or drop reach");
394
+ if (!reach.command.trim()) throw new Error("the product plan's reach.command is empty; give the line that prints the targets a change reaches");
395
+ if (/[\r\n]/.test(reach.command)) throw new Error("the product plan's reach.command is one shell line");
396
+ if (reach.gate !== undefined) {
397
+ // The lock file's name, as ../lifecycle/target-lock.ts takes it.
398
+ if (!/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(reach.gate)) throw new Error(`the product plan's reach.gate ${JSON.stringify(reach.gate)} is not a lock file name: letters, digits, '.', '_' and '-', starting with a letter or digit`);
399
+ }
400
+ const gate = reach.gate !== undefined ? ["--gate", reach.gate] : [];
401
+ const github = forge !== "gitlab";
402
+ const line = github
403
+ ? ["chant", "lock", "--reach", "--pr", '"$PR_NUMBER"', "--head", '"$HEAD_SHA"', "--base", '"$BASE_SHA"', "--stage", "plan", ...gate, "--forge", forge]
404
+ : ["chant", "lock", "--reach", "--open", "--base", '"$CI_COMMIT_SHA"', "--stage", "plan", ...gate, "--forge", "gitlab"];
405
+ const env: Record<string, string> = github
406
+ ? { PR_NUMBER: "${{ github.event.pull_request.number }}", HEAD_SHA: "${{ github.event.pull_request.head.sha }}", BASE_SHA: "${{ github.event.pull_request.base.sha }}", GITHUB_TOKEN: GITHUB_JOB_TOKEN, [LOCK_REACH_ENV]: reach.command }
407
+ : { [LOCK_REACH_ENV]: reach.command };
408
+ const runner = prLoopRunner(loop, "default");
409
+ return { jobName: PR_LOCK_JOB, command: withProductBin(line.join(" "), words.bin), env, ...(runner !== undefined ? { runner } : {}) };
246
410
  }
247
411
 
248
412
  /** The file a product plan job writes its run record to under the hand-off directory, and the Op it is recorded under: `pr-plan`'s (#4899, ../pr-plan-record.ts). */
@@ -275,7 +439,8 @@ export interface ProductPlanJob {
275
439
  noteRunner?: CiRunner;
276
440
  /**
277
441
  * With the pipeline's `evidence` (#4870): the lines that sign the plan
278
- * job's `plan` and `policy` checks from its report, and their variables
442
+ * job's `plan` and `policy` checks from its report (with a target,
443
+ * `plan:<target>` and `policy:<target>`, #4978), and their variables
279
444
  * (the runner key from its secret). GitHub and Forgejo run them in the
280
445
  * note job before `pr-post`; GitLab in a job of their own, `jobName`, in
281
446
  * the target branch's plan notes pipeline before the note job (#4914),
@@ -302,8 +467,12 @@ export interface ProductPlanJob {
302
467
  report?: string;
303
468
  /** The comment re-plan's jobs for this target (#4899). */
304
469
  replan?: ProductPlanReplanJob;
305
- /** The note job's own lines (#4931). */
306
- noteSteps?: { before: string[]; after: string[] };
470
+ /** The note job's own lines (#4931); with `pullRequest` (#4963) they read `PR_NUMBER` and `HEAD_SHA`. */
471
+ noteSteps?: { before: string[]; after: string[]; pullRequest?: true };
472
+ /** The trade before the checkout (#4963), and on GitLab the `id_tokens` it reads (in `idTokens` too). */
473
+ trade?: CloudTradeSpec;
474
+ /** With `previousMarker` (#4963): the note's marker and the product marker's name the read step looks for. */
475
+ previous?: { marker: string; name: string };
307
476
  /** With `record` (#4899): the plan step writes the run record, `env` its op, environment and labels as {@link PLAN_RUN_RECORD_ENV}; the note job's command records it. */
308
477
  record?: { env: Record<string, string> };
309
478
  }
@@ -312,13 +481,11 @@ const TARGET_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
312
481
 
313
482
  /** The pull request loop's options the product plan's jobs do not carry, and what each needs. Each is refused with `plan` (#4799). */
314
483
  const NOT_WITH_PLAN: ReadonlyArray<[keyof PrLoopPipelineOptions, string]> = [
315
- ["applyBeforeMerge", "the apply before merge runs pr-apply on pr-plan's report"],
484
+ ["applyBeforeMerge", "the apply before merge runs pr-apply on pr-plan's report; give wavesBeforeMerge to run the waves on an open pull request's head (#4984)"],
316
485
  ["applyOnMerge", "the apply on merge runs on op waves, from the waves spec"],
317
486
  ["waveGate", "the apply on merge runs on op waves, from the waves spec"],
318
- ["locks", "the lock job reads pr-plan's report"],
319
487
  ["previewComment", "the comment preview re-runs pr-plan"],
320
- ["staleNotes", "the stale marking names one note per pipeline"],
321
- ["identity", "the identity trade runs before pr-plan's checkout; give the product plan's login (or a target's) instead"],
488
+ ["identity", "the identity trade runs before pr-plan's checkout; give the product plan's trade or login (or a target's) instead"],
322
489
  ["build", "the plan verb builds what it plans"],
323
490
  ["buildCommand", "the plan verb builds what it plans"],
324
491
  ["refresh", "--refresh is a pr-plan flag"],
@@ -344,6 +511,9 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
344
511
  const value = loop[key];
345
512
  if (value !== undefined && value !== false) throw new Error(`the product plan (plan) takes no ${key}: ${why}`);
346
513
  }
514
+ // #4946: GitHub's and Forgejo's product plan writes the lock jobs around the plan verb's PrReport.
515
+ // #4979: GitLab's locks what each open merge request reaches, from the plan notes pipeline, so it needs the reach line.
516
+ if (loop.locks && forge === "gitlab" && !plan.reach) throw new Error("the product plan (plan) takes locks on GitLab only with reach: a merge request's pipeline is built from its own files, so the lock job runs in the target branch's plan notes pipeline and locks what reach prints for each open merge request");
347
517
  // #4899: GitLab's comment commands start the re-plan, so the note-commands job comes with it.
348
518
  if (loop.noteCommands && !plan.replan) throw new Error("the product plan (plan) takes no noteCommands without replan: the note-commands job starts its comment re-plan");
349
519
  if (!plan.command.trim()) throw new Error("the product plan's command is empty; give the product's plan verb");
@@ -367,6 +537,18 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
367
537
  }
368
538
  if (plan.concurrency?.group !== undefined && !/^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(plan.concurrency.group)) throw new Error(`the product plan's concurrency group ${JSON.stringify(plan.concurrency.group)} is not a name of letters, digits, ., - and _`);
369
539
  const replanComments = plan.replan ? replanCommentsOf(words) : undefined;
540
+ // #4963: what the re-plan does besides the plan command.
541
+ const replanOpts: ProductPlanReplanOptions = typeof plan.replan === "object" ? plan.replan : {};
542
+ const dispatchArg = replanOpts.dispatch ? (typeof replanOpts.dispatch === "object" && replanOpts.dispatch.argument !== undefined ? replanOpts.dispatch.argument : "argument") : undefined;
543
+ if (dispatchArg !== undefined && (dispatchArg === "pr" || !/^[a-z][a-z0-9_-]*$/.test(dispatchArg))) throw new Error(`the product plan's replan.dispatch.argument ${JSON.stringify(dispatchArg)} is not an input name of lowercase letters, digits, - and _ other than pr`);
544
+ const others = typeof replanOpts.reply === "object" ? (replanOpts.reply.others ?? []) : [];
545
+ for (const o of others) {
546
+ if (!o.startsWith(`/${words.product} `) && !o.startsWith(`/${words.product}\t`) && o !== `/${words.product}`) throw new Error(`the product plan's replan.reply.others ${JSON.stringify(o)} is not a /${words.product} comment`);
547
+ if (/['\r\n]/.test(o)) throw new Error(`the product plan's replan.reply.others ${JSON.stringify(o)} holds a quote or a line break`);
548
+ }
549
+ if (plan.previousMarker && !github) throw new Error("the product plan's previousMarker reads the pull request's note before the checkout, with the job's token, and GitLab's plan job holds no token to read a merge request's notes with; leave previousMarker out on GitLab");
550
+ const productMarker = plan.noteWords?.productMarker;
551
+ if (plan.previousMarker && (productMarker === undefined || !PRODUCT_MARKER_NAME.test(productMarker))) throw new Error("the product plan's previousMarker reads the note's product marker, and the note words name none; give noteWords.productMarker");
370
552
  if (plan.noteSteps && !github && ((plan.noteSteps.before?.length ?? 0) > 0 || (plan.noteSteps.after?.length ?? 0) > 0)) {
371
553
  throw new Error("the product plan's noteSteps run in the note job of one pull request, and GitLab's note job posts every open merge request's note in one run (pr-post --open); leave noteSteps out on GitLab");
372
554
  }
@@ -378,6 +560,10 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
378
560
  for (const w of plan.watches ?? []) {
379
561
  const problem = scheduledWatchProblem(w);
380
562
  if (problem) throw new Error(`the product plan's watches: ${problem}`);
563
+ // #4988: a watch scoped to targets names the plan's own.
564
+ for (const t of w.targets ?? []) {
565
+ if (!seen.has(t)) throw new Error(`the product plan's watch ${w.op} names target ${t}, which the plan ${targets?.length ? "does not have" : "cannot scope to: it has no targets"}`);
566
+ }
381
567
  }
382
568
  if (new Set((plan.watches ?? []).map((w) => w.op)).size !== (plan.watches ?? []).length) throw new Error("the product plan's watches name an Op twice");
383
569
  // The note job's variables from the pipeline: the note words, and the product's watches (#4888).
@@ -396,7 +582,8 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
396
582
  if (key in shared) throw new Error(`target ${name}'s ${key} is the pipeline's too; give it on the target or on the pipeline`);
397
583
  if (key in jobEnv) throw new Error(`target ${name}'s ${key} is the product plan's env too; give it once`);
398
584
  }
399
- const post0 = prLoopPostJob(forge, env, name, words);
585
+ // #4987: with staleNotes each target's note carries the target branch's commit, so the waves' push can mark it stale.
586
+ const post0 = prLoopPostJob(forge, env, name, words, loop.staleNotes ? { staleNotes: true } : {});
400
587
  // #4899: the note job records the plan job's run, named by that job.
401
588
  const post1 = plan.record ? { ...post0, command: `${post0.command} --record-run ${jobName}` } : post0;
402
589
  // #4914: on GitLab the signing job of the same pipeline keeps each merge request's evidence, which the note's checks line reads.
@@ -404,17 +591,34 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
404
591
  // The note job reads its own plan job's result, by that job's name.
405
592
  const postEnv: Record<string, string> = github ? { ...post.env, PLAN_RESULT: `\${{ needs.${jobName}.result }}`, ...noteWords } : { ...post.env, ...noteWords };
406
593
  // #4931: the target's login, else the plan's, from the OIDC token file (ci-login, #4788).
407
- const loginSpec = target?.login ?? plan.login;
594
+ // #4963: a target's own login or trade stands in for both of the plan's.
595
+ const own2 = target?.login !== undefined || target?.trade !== undefined;
596
+ const loginSpec = own2 ? target?.login : plan.login;
597
+ const tradeSpec = own2 ? target?.trade : plan.trade;
598
+ if (loginSpec && tradeSpec) throw new Error(`the product plan${name ? `'s target ${name}` : ""} gives both login and trade; the trade leaves no token for a login to read, so give one`);
599
+ if (tradeSpec && tradedClouds(tradeSpec).length === 0) throw new Error(`the product plan${name ? `'s target ${name}` : ""} trades for no identity; give the trade a cloud`);
408
600
  const login = loginSpec ? cloudLogin(forge, loginSpec) : undefined;
601
+ const tradeTokens: Record<string, string> = tradeSpec ? Object.fromEntries(tradedClouds(tradeSpec).map((c) => [idTokenVar(c), tradeSpec[c]!.audience])) : {};
409
602
  const ownTokens = target?.idTokens ?? plan.idTokens;
410
603
  for (const [v, aud] of Object.entries(ownTokens ?? {})) {
411
604
  if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(v)) throw new Error(`the product plan's id token ${JSON.stringify(v)} is not a variable name`);
412
605
  if (!aud.trim() || /\s/.test(aud)) throw new Error(`the product plan's id token ${v} names no audience`);
413
606
  if (login && v in login.idTokens && login.idTokens[v] !== aud) throw new Error(`the product plan's id token ${v} is the login's, with another audience`);
607
+ if (v in tradeTokens && tradeTokens[v] !== aud) throw new Error(`the product plan's id token ${v} is the trade's, with another audience`);
414
608
  }
415
- const idTokens = { ...(login?.idTokens ?? {}), ...(ownTokens ?? {}) };
609
+ const idTokens = { ...(login?.idTokens ?? {}), ...tradeTokens, ...(ownTokens ?? {}) };
416
610
  const artifact = plan.artifact ? (name ? `${plan.artifact}-${name}` : plan.artifact) : name ? `chant-pr-plan-${name}` : "chant-pr-plan";
417
- const replan0 = replanComments ? { ...replanJobOf(forge, env, words, name, artifact, noteWords), ...replanComments } : undefined;
611
+ // #4963: on GitHub and Forgejo the first re-plan job replies to the comments no other job takes.
612
+ const replies = github && Boolean(replanOpts.reply) && (targets === undefined || target === targets[0]);
613
+ const replan0 = replanComments
614
+ ? {
615
+ ...replanJobOf(forge, env, words, name, artifact, noteWords, { notAffected: replanOpts.notAffected === true, ...(loop.staleNotes ? { staleNotes: true } : {}) }),
616
+ ...replanComments,
617
+ ...(github && dispatchArg !== undefined ? { dispatch: { argument: dispatchArg } } : {}),
618
+ ...(replies ? { reply: { prefix: `/${words.product}`, others } } : {}),
619
+ ...(replanOpts.notAffected ? { notAffected: true as const } : {}),
620
+ }
621
+ : undefined;
418
622
  const replan = replan0 && plan.record ? { ...replan0, post: { ...replan0.post, command: `${replan0.post.command} --record-run ${replan0.jobName}` } } : replan0;
419
623
  const record = plan.record ? { env: { [PLAN_RUN_RECORD_ENV]: JSON.stringify({ op: PLAN_RUN_OP, env, labels: { Env: env, Pipeline: "pr", Job: "plan", ...(name ? { Target: name } : {}) } }) } } : undefined;
420
624
  const noteBefore = plan.noteSteps?.before ?? [];
@@ -430,7 +634,8 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
430
634
  artifact,
431
635
  ...(planRunner !== undefined ? { runner: planRunner } : {}),
432
636
  ...(noteRunner !== undefined ? { noteRunner } : {}),
433
- ...(evidence ? { evidence: planEvidenceOf(forge, evidence, words, jobName, plan.forks === "skip" ? { noForks: true } : {}) } : {}),
637
+ // #4978: a target's plan job plans that target alone, so its checks are `plan:<target>` and `policy:<target>`.
638
+ ...(evidence ? { evidence: planEvidenceOf(forge, evidence, words, jobName, { ...(plan.forks === "skip" ? { noForks: true } : {}), ...(name ? { member: { name, reportPath: PR_LOOP_REPORT_DIR } } : {}) }) } : {}),
434
639
  ...(Object.keys(jobEnv).length > 0 ? { jobEnv } : {}),
435
640
  ...(login && login.steps.length > 0 ? { login: login.steps } : {}),
436
641
  ...(Object.keys(idTokens).length > 0 ? { idTokens } : {}),
@@ -439,8 +644,10 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
439
644
  ...(plan.setup?.length ? { setup: plan.setup } : {}),
440
645
  ...(plan.report ? { report: fill(plan.report, name) } : {}),
441
646
  ...(replan ? { replan } : {}),
442
- ...(noteBefore.length > 0 || noteAfter.length > 0 ? { noteSteps: { before: noteBefore, after: noteAfter } } : {}),
647
+ ...(noteBefore.length > 0 || noteAfter.length > 0 ? { noteSteps: { before: noteBefore, after: noteAfter, ...(plan.noteSteps?.pullRequest ? { pullRequest: true as const } : {}) } } : {}),
443
648
  ...(record ? { record } : {}),
649
+ ...(tradeSpec ? { trade: tradeSpec } : {}),
650
+ ...(plan.previousMarker && productMarker ? { previous: { marker: prNoteMarker(env, name), name: productMarker } } : {}),
444
651
  };
445
652
  };
446
653
  return targets ? targets.map(one) : [one()];
@@ -455,12 +662,18 @@ function replanCommentsOf(words: CiProductWords): { comments: string[]; gated: A
455
662
  }
456
663
 
457
664
  /** The re-plan's jobs for one target (#4899), its comments filled in by the caller. */
458
- function replanJobOf(forge: ForgeKind, env: string, words: CiProductWords, name: string | undefined, artifact: string, noteWords: Record<string, string>): Omit<ProductPlanReplanJob, "comments" | "gated"> {
665
+ function replanJobOf(forge: ForgeKind, env: string, words: CiProductWords, name: string | undefined, artifact: string, noteWords0: Record<string, string>, opts: { notAffected?: boolean; staleNotes?: boolean } = {}): Omit<ProductPlanReplanJob, "comments" | "gated"> {
459
666
  const github = forge !== "gitlab";
460
667
  const jobName = github ? (name ? `${REPLAN_JOB}-${name}` : REPLAN_JOB) : name ? `${name}-${REPLAN_JOB}` : REPLAN_JOB;
461
668
  const noteJobName = github ? (name ? `${REPLAN_NOTE_JOB}-${name}` : REPLAN_NOTE_JOB) : name ? `${name}-${REPLAN_NOTE_JOB}` : REPLAN_NOTE_JOB;
462
669
  // pr-post reads the pull request and the head from the re-plan job, never the comment. GitLab's is GitHub's line with its own --forge.
463
- const command = github ? prLoopPostJob(forge, env, name, words).command : prLoopPostJob("github", env, name, words).command.replace(" --forge github ", " --forge gitlab ");
670
+ // #4987: with staleNotes the note's tip line is the target branch's commit the re-plan ran at, as the comment preview's is.
671
+ const stale = opts.staleNotes ? { staleNotes: true } : {};
672
+ const command0 = github ? prLoopPostJob(forge, env, name, words, stale).command : prLoopPostJob("github", env, name, words, stale).command.replace(" --forge github ", " --forge gitlab ");
673
+ // #4963: the argument the re-plan was narrowed to, which pr-post answers "not affected" for when the change does not reach it.
674
+ const command = opts.notAffected ? `${command0} --not-affected "$${PLAN_ARGUMENT_ENV}"` : command0;
675
+ const noteWords1 = opts.notAffected && github ? { ...noteWords0, [PLAN_ARGUMENT_ENV]: `\${{ needs.${jobName}.outputs.argument }}` } : noteWords0;
676
+ const noteWords = opts.staleNotes ? { ...noteWords1, TIP_SHA: github ? "${{ github.sha }}" : "$CI_COMMIT_SHA" } : noteWords1;
464
677
  const post = github
465
678
  ? {
466
679
  command,
@@ -504,7 +717,8 @@ function literal(text: string): string {
504
717
  * a target, the command with at most one word after it.
505
718
  */
506
719
  export function gitlabReplanCommentIf(replan: Pick<ProductPlanReplanJob, "comments" | "gated">, target?: string): string {
507
- const arg = target ? `( +${literal(target)})?` : "( +[A-Za-z0-9_.\\/@+=,:-]+)?";
720
+ // #4984: the one word never starts with `-`, so a flag such as `--target=x` starts no re-plan.
721
+ const arg = target ? `( +${literal(target)})?` : `( +${REPLAN_WORD_SOURCE})?`;
508
722
  const one = (c: string): string => `$${GITLAB_REPLAN_COMMENT_VAR} =~ /^${literal(c)}${arg} *$/`;
509
723
  return [...replan.comments.map(one), ...replan.gated.map((g) => `($${g.when} && ${one(g.comment)})`)].join(" || ");
510
724
  }
@@ -519,36 +733,131 @@ export function gitlabReplanCommentIf(replan: Pick<ProductPlanReplanJob, "commen
519
733
  * commenter), whether the commenter can write. It writes `go=1`, `pr`,
520
734
  * `head`, `base` and `argument` to the step's outputs.
521
735
  */
522
- export const REPLAN_DECIDE_JS = [
736
+ export const REPLAN_DECIDE_JS = replanDecideJs();
737
+
738
+ /**
739
+ * The re-plan's decision script (#4899) with what `replan`'s options add
740
+ * (#4963). With neither it is {@link REPLAN_DECIDE_JS}, as before.
741
+ *
742
+ * - `dispatch`: on `workflow_dispatch` the pull request is the `pr` input
743
+ * and the argument the input `CHANT_REPLAN_DISPATCH_ARGUMENT` names;
744
+ * a `pr` that is not a number, or an argument that is not one plain
745
+ * word, fails the job. No permission is asked: only a writer dispatches.
746
+ * - `reply`: a comment that starts with `CHANT_REPLAN_PRODUCT` and is not
747
+ * the plan command, nor one of `CHANT_REPLAN_OTHERS`, a target that is
748
+ * none of the plan's, and a fork's pull request with `forks: "skip"`
749
+ * get a reply comment with the reason, once the commenter's permission
750
+ * is known (Forgejo). A dispatch's reason goes to the log alone.
751
+ */
752
+ export function replanDecideJs(opts: { dispatch?: boolean; reply?: boolean } = {}): string {
753
+ const { dispatch = false, reply = false } = opts;
754
+ const replyLine = reply
755
+ ? [
756
+ // The reply, as the product: on a dispatch the log alone.
757
+ `const post=async(t)=>{say(t);${dispatch ? "if(dispatch)return;" : ""}const r=await fetch(api+"/repos/"+repo+"/issues/"+n+"/comments",{method:"POST",headers:{authorization:"token "+process.env.CHANT_REPLAN_TOKEN,accept:"application/json","content-type":"application/json"},body:JSON.stringify({body:product.slice(1)+": "+t})});if(!r.ok)console.error("chant: the reply was not posted: the forge answered "+r.status)};`,
758
+ ]
759
+ : [];
760
+ return [
761
+ 'const fs=require("fs");',
762
+ 'const say=(m)=>console.log("chant: "+m);',
763
+ 'const out=(k,v)=>fs.appendFileSync(process.env.GITHUB_OUTPUT,k+"="+v+"\\n");',
764
+ "let e;try{e=JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH,\"utf8\"))}catch{say(\"the event file does not read, so nothing is planned again\");process.exit(0)}",
765
+ ...(dispatch ? ['const dispatch=process.env.GITHUB_EVENT_NAME==="workflow_dispatch",inputs=e.inputs&&typeof e.inputs==="object"?e.inputs:{};'] : []),
766
+ 'const body=String((e.comment&&e.comment.body)||"").trim();',
767
+ 'const cmds=JSON.parse(process.env.CHANT_REPLAN_COMMANDS||"[]");',
768
+ 'for(const g of JSON.parse(process.env.CHANT_REPLAN_GATED||"[]")){const v=process.env[g.when]||"";if(v&&v!=="0"&&v!=="false")cmds.push(g.comment)}',
769
+ "let arg,flag;",
770
+ ...(reply ? ['let refusal;const product=process.env.CHANT_REPLAN_PRODUCT||"",others=JSON.parse(process.env.CHANT_REPLAN_OTHERS||"[]");const says=(c)=>body===c||body.startsWith(c+" ")||body.startsWith(c+"\\t");'] : []),
771
+ ...(dispatch
772
+ ? [
773
+ 'if(dispatch){const pv=String(inputs.pr==null?"":inputs.pr).trim();if(!pv){say("the dispatch names no pull request");process.exit(0)}if(!/^[1-9][0-9]{0,9}$/.test(pv)){console.error("chant: the dispatch\\u0027s pr input is a pull request number, like 42");process.exit(1)}',
774
+ `const k=process.env.CHANT_REPLAN_DISPATCH_ARGUMENT||"argument",a=String(inputs[k]==null?"":inputs[k]).trim();if(a&&!/${REPLAN_WORD_JS}/.test(a)){console.error("chant: the dispatch\\u0027s "+k+" input is one word of letters, digits and _./@+=,:-, not starting with -");process.exit(1)}arg=a}else `,
775
+ ]
776
+ : []),
777
+ // #4984: a word that starts with `-` is a flag (`--target=x`), which the re-plan does not take.
778
+ `for(const c of cmds){if(body===c){arg="";break}if(body.startsWith(c+" ")){const r=body.slice(c.length).trim();if(r.startsWith("-")){flag=r.split(/\\s/)[0];break}if(/${REPLAN_WORD_JS}/.test(r)){arg=r;break}}}`,
779
+ reply
780
+ ? 'if(flag!==undefined){refusal="the re-plan takes no flags, and "+flag+" is one: write the command alone, or with one word that does not start with -";arg=""}'
781
+ : 'if(flag!==undefined){say("the re-plan takes no flags, and "+flag+" is one, so nothing is planned again");process.exit(0)}',
782
+ reply
783
+ ? 'if(arg===undefined){if(product&&says(product)&&!others.some(says)){refusal="the commands are "+cmds.concat(others).map((c)=>"`"+c+"`").join(", ")}else{say("the comment asks for no plan");process.exit(0)}}'
784
+ : 'if(arg===undefined){say("the comment asks for no plan");process.exit(0)}',
785
+ 'const target=process.env.CHANT_REPLAN_TARGET||"",targets=JSON.parse(process.env.CHANT_REPLAN_TARGETS||"[]");',
786
+ reply
787
+ ? 'if(targets.length&&arg&&!targets.includes(arg)){refusal=arg+" is none of "+targets.join(", ")+", so nothing is planned again";arg=""}'
788
+ : 'if(targets.length&&arg&&!targets.includes(arg)){say(arg+" is none of "+targets.join(", ")+", so nothing is planned again");process.exit(0)}',
789
+ 'if(targets.length&&arg&&arg!==target){say("the comment plans "+arg+" again, not "+target);process.exit(0)}',
790
+ dispatch
791
+ ? 'const n=dispatch?Number(String(inputs.pr).trim()):e.issue&&e.issue.number;if(!dispatch&&(!Number.isInteger(n)||!(e.issue.pull_request||e.is_pull))){say("the comment is not on a pull request");process.exit(0)}'
792
+ : 'const n=e.issue&&e.issue.number;if(!Number.isInteger(n)||!(e.issue.pull_request||e.is_pull)){say("the comment is not on a pull request");process.exit(0)}',
793
+ 'const api=String(process.env.GITHUB_API_URL||"").replace(/\\/+$/,""),repo=process.env.GITHUB_REPOSITORY;',
794
+ 'const get=async(p)=>{const r=await fetch(api+"/repos/"+repo+p,{headers:{authorization:"token "+process.env.CHANT_REPLAN_TOKEN,accept:"application/json"}});if(!r.ok)throw new Error(p+" answered "+r.status);return r.json()};',
795
+ ...replyLine,
796
+ "(async()=>{",
797
+ ...(reply
798
+ ? [
799
+ // Who asked comes first: a commenter who cannot write gets no reply.
800
+ `if(process.env.CHANT_REPLAN_PERMISSION${dispatch ? "&&!dispatch" : ""}){const who=e.comment&&e.comment.user&&e.comment.user.login;const p=who?await get("/collaborators/"+encodeURIComponent(who)+"/permission"):{};`,
801
+ 'if(!["owner","admin","maintain","write"].includes(p.permission)){say((who||"the commenter")+" cannot write to "+repo+", so nothing is planned again");return}}',
802
+ "if(refusal){await post(refusal);return}",
803
+ 'const pr=await get("/pulls/"+n);',
804
+ 'if(pr.state!=="open"){say("pull request "+n+" is not open, so it is not planned again");return}',
805
+ 'const same=Boolean(pr.head&&pr.head.repo&&pr.head.repo.full_name===repo);',
806
+ 'if(!same&&process.env.CHANT_REPLAN_FORKS==="skip"){await post("pull request "+n+" is from a fork, and its code never runs with this repository\\u0027s credentials, so it is not planned again");return}',
807
+ ]
808
+ : [
809
+ 'const pr=await get("/pulls/"+n);',
810
+ 'if(pr.state!=="open"){say("pull request "+n+" is not open, so it is not planned again");return}',
811
+ 'const same=Boolean(pr.head&&pr.head.repo&&pr.head.repo.full_name===repo);',
812
+ 'if(!same&&process.env.CHANT_REPLAN_FORKS==="skip"){say("pull request "+n+" is from a fork, and its code never runs with this repository\\u0027s credentials");return}',
813
+ `if(process.env.CHANT_REPLAN_PERMISSION${dispatch ? "&&!dispatch" : ""}){const who=e.comment&&e.comment.user&&e.comment.user.login;const p=who?await get("/collaborators/"+encodeURIComponent(who)+"/permission"):{};`,
814
+ 'if(!["owner","admin","maintain","write"].includes(p.permission)){say((who||"the commenter")+" cannot write to "+repo+", so nothing is planned again");return}}',
815
+ ]),
816
+ 'const sha=/^[0-9a-f]{40}$/;if(!sha.test(String(pr.head&&pr.head.sha))||!sha.test(String(pr.base&&pr.base.sha)))throw new Error("the pull request names no head or base commit");',
817
+ 'out("go","1");out("pr",String(n));out("head",pr.head.sha);out("base",pr.base.sha);out("argument",arg);',
818
+ 'say("planning pull request "+n+" again at "+pr.head.sha.slice(0,12)+(arg?" for "+arg:""))',
819
+ '})().catch((err)=>{console.error("chant: the re-plan could not decide: "+(err&&err.message?err.message:String(err)));process.exit(1)});',
820
+ ].join("");
821
+ }
822
+
823
+ /**
824
+ * The previous note's read step on GitHub and Forgejo (#4963): `node -e`,
825
+ * from `/`, with the job's token in `CHANT_PREVIOUS_TOKEN` alone. It pages
826
+ * through pull request `CHANT_PREVIOUS_PR`'s comments for the one whose
827
+ * first line is `CHANT_PREVIOUS_NOTE` (chant's marker), takes its second
828
+ * line's body when it is `<!-- <CHANT_PREVIOUS_NAME> <body> -->` and the
829
+ * body is plain words, and appends `CHANT_PLAN_PREVIOUS_MARKER=<body>` to
830
+ * `$GITHUB_ENV`, empty when there is none. A forge that refuses is a
831
+ * warning: the plan verb plans without it.
832
+ */
833
+ export const PREVIOUS_MARKER_JS = [
523
834
  'const fs=require("fs");',
524
- 'const say=(m)=>console.log("chant: "+m);',
525
- 'const out=(k,v)=>fs.appendFileSync(process.env.GITHUB_OUTPUT,k+"="+v+"\\n");',
526
- "let e;try{e=JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH,\"utf8\"))}catch{say(\"the event file does not read, so nothing is planned again\");process.exit(0)}",
527
- 'const body=String((e.comment&&e.comment.body)||"").trim();',
528
- 'const cmds=JSON.parse(process.env.CHANT_REPLAN_COMMANDS||"[]");',
529
- 'for(const g of JSON.parse(process.env.CHANT_REPLAN_GATED||"[]")){const v=process.env[g.when]||"";if(v&&v!=="0"&&v!=="false")cmds.push(g.comment)}',
530
- "let arg;",
531
- 'for(const c of cmds){if(body===c){arg="";break}if(body.startsWith(c+" ")){const r=body.slice(c.length).trim();if(/^[A-Za-z0-9_.\\/@+=,:-]+$/.test(r)){arg=r;break}}}',
532
- 'if(arg===undefined){say("the comment asks for no plan");process.exit(0)}',
533
- 'const target=process.env.CHANT_REPLAN_TARGET||"",targets=JSON.parse(process.env.CHANT_REPLAN_TARGETS||"[]");',
534
- 'if(targets.length&&arg&&!targets.includes(arg)){say(arg+" is none of "+targets.join(", ")+", so nothing is planned again");process.exit(0)}',
535
- 'if(targets.length&&arg&&arg!==target){say("the comment plans "+arg+" again, not "+target);process.exit(0)}',
536
- 'const n=e.issue&&e.issue.number;if(!Number.isInteger(n)||!(e.issue.pull_request||e.is_pull)){say("the comment is not on a pull request");process.exit(0)}',
537
- 'const api=String(process.env.GITHUB_API_URL||"").replace(/\\/+$/,""),repo=process.env.GITHUB_REPOSITORY;',
538
- 'const get=async(p)=>{const r=await fetch(api+"/repos/"+repo+p,{headers:{authorization:"token "+process.env.CHANT_REPLAN_TOKEN,accept:"application/json"}});if(!r.ok)throw new Error(p+" answered "+r.status);return r.json()};',
835
+ 'const api=String(process.env.GITHUB_API_URL||"").replace(/\\/+$/,""),repo=process.env.GITHUB_REPOSITORY,n=process.env.CHANT_PREVIOUS_PR||"";',
836
+ 'const note=process.env.CHANT_PREVIOUS_NOTE||"",name=process.env.CHANT_PREVIOUS_NAME||"";',
837
+ 'const put=(v)=>fs.appendFileSync(process.env.GITHUB_ENV,"CHANT_PLAN_PREVIOUS_MARKER="+v+"\\n");',
838
+ 'const esc=(s)=>s.replace(/[.*+?^${}()|[\\]\\\\]/g,"\\\\$&");',
839
+ 'const own=new RegExp("^<!-- "+esc(name)+"(?: ([A-Za-z0-9_.,\\\\/@+=:-]+(?: [A-Za-z0-9_.,\\\\/@+=:-]+)*))? -->$");',
840
+ 'if(!/^[0-9]+$/.test(n)){console.log("chant: no pull request to read the previous note of");put("");process.exit(0)}',
539
841
  "(async()=>{",
540
- 'const pr=await get("/pulls/"+n);',
541
- 'if(pr.state!=="open"){say("pull request "+n+" is not open, so it is not planned again");return}',
542
- 'const same=Boolean(pr.head&&pr.head.repo&&pr.head.repo.full_name===repo);',
543
- 'if(!same&&process.env.CHANT_REPLAN_FORKS==="skip"){say("pull request "+n+" is from a fork, and its code never runs with this repository\\u0027s credentials");return}',
544
- 'if(process.env.CHANT_REPLAN_PERMISSION){const who=e.comment&&e.comment.user&&e.comment.user.login;const p=who?await get("/collaborators/"+encodeURIComponent(who)+"/permission"):{};',
545
- 'if(!["owner","admin","maintain","write"].includes(p.permission)){say((who||"the commenter")+" cannot write to "+repo+", so nothing is planned again");return}}',
546
- 'const sha=/^[0-9a-f]{40}$/;if(!sha.test(String(pr.head&&pr.head.sha))||!sha.test(String(pr.base&&pr.base.sha)))throw new Error("the pull request names no head or base commit");',
547
- 'out("go","1");out("pr",String(n));out("head",pr.head.sha);out("base",pr.base.sha);out("argument",arg);',
548
- 'say("planning pull request "+n+" again at "+pr.head.sha.slice(0,12)+(arg?" for "+arg:""))',
549
- '})().catch((err)=>{console.error("chant: the re-plan could not decide: "+(err&&err.message?err.message:String(err)));process.exit(1)});',
842
+ "for(let page=1;page<=50;page++){",
843
+ 'const r=await fetch(api+"/repos/"+repo+"/issues/"+n+"/comments?per_page=100&limit=50&page="+page,{headers:{authorization:"token "+process.env.CHANT_PREVIOUS_TOKEN,accept:"application/json"}});',
844
+ 'if(!r.ok)throw new Error("the forge answered "+r.status);',
845
+ "const list=await r.json();if(!Array.isArray(list)||list.length===0)break;",
846
+ 'for(const c of list){const lines=String(c&&c.body||"").replace(/\\r\\n/g,"\\n").split("\\n");if(lines[0]!==note)continue;const m=own.exec(lines[1]||"");const v=m&&m[1]&&m[1].length<=4096?m[1]:"";put(v);console.log("chant: the previous note"+(v?" carries "+name:" carries no "+name));return}',
847
+ "}",
848
+ 'put("");console.log("chant: the pull request has no note yet")',
849
+ '})().catch((err)=>{put("");console.log("chant: the previous note was not read: "+(err&&err.message?err.message:String(err)))});',
550
850
  ].join("");
551
851
 
852
+ /** The GitLab re-plan's lines that set {@link PLAN_ARGUMENT_ENV} from the comment's one word after the command (#4899), which the rule already held to plain characters. */
853
+ export function gitlabReplanArgumentLines(replan: Pick<ProductPlanReplanJob, "comments" | "gated">): string[] {
854
+ const byLength = [...replan.comments, ...replan.gated.map((g) => g.comment)].sort((a, b) => b.length - a.length);
855
+ return [
856
+ `case "$${GITLAB_REPLAN_COMMENT_VAR}" in ${byLength.map((c) => `"${c}"*) chant_rest="\${${GITLAB_REPLAN_COMMENT_VAR}#"${c}"}" ;;`).join(" ")} *) chant_rest="" ;; esac`,
857
+ `${PLAN_ARGUMENT_ENV}="$(printf '%s' "$chant_rest" | tr -d ' ')" && export ${PLAN_ARGUMENT_ENV}`,
858
+ ];
859
+ }
860
+
552
861
  /**
553
862
  * The pending step's script on GitHub and Forgejo (#4899): `node -e`, from
554
863
  * `/`, posting the plan status pending at `CHANT_PENDING_SHA` with the token
@@ -600,25 +909,33 @@ export const PLAN_RECORD_JS = [
600
909
  `fs.mkdirSync(dir,{recursive:true});fs.writeFileSync(path.join(dir,"${PLAN_RUN_RECORD_FILE}"),JSON.stringify(rec)+"\\n");`,
601
910
  ].join("");
602
911
 
603
- /** The evidence step of one plan job (#4870), as {@link ProductPlanJob.evidence}. */
604
- export function planEvidenceOf(forge: ForgeKind, evidence: PipelineEvidence, words: CiProductWords, planJob: string, opts: { noForks?: boolean } = {}): NonNullable<ProductPlanJob["evidence"]> {
912
+ /**
913
+ * The evidence step of one plan job (#4870), as {@link ProductPlanJob.evidence}.
914
+ * #4964: for a workspace member's pipeline (`member`) the checks are signed
915
+ * as `plan:<member>` and `policy:<member>` (`--member`), and on GitLab the
916
+ * report is read from the plan job's artifact at the member's `reportPath`.
917
+ * #4978: a product plan target's plan job is signed the same way, under the
918
+ * target's name.
919
+ */
920
+ export function planEvidenceOf(forge: ForgeKind, evidence: PipelineEvidence, words: CiProductWords, planJob: string, opts: { noForks?: boolean; member?: { name: string; reportPath: string } } = {}): NonNullable<ProductPlanJob["evidence"]> {
605
921
  assertPipelineEvidence(evidence);
606
922
  const key = evidenceKeyEnv(forge, evidence);
607
923
  const bin = words.bin;
924
+ const member = opts.member ? { member: opts.member.name } : {};
608
925
  if (forge === "gitlab") {
609
926
  // #4914: the job runs in the target branch's plan notes pipeline, before the note job, and signs every open
610
927
  // merge request's settled plan job from its artifact; no job of a merge request pipeline holds the key.
611
928
  const dir = gitlabOpenEvidenceDir(planJob);
612
929
  return {
613
930
  jobName: `${planJob}-evidence`,
614
- lines: openEvidenceLines({ job: planJob, dir: PR_LOOP_REPORT_DIR, out: dir, ...(bin ? { bin } : {}), ...(opts.noForks ? { noForks: true } : {}) }),
931
+ lines: openEvidenceLines({ job: planJob, dir: opts.member?.reportPath ?? PR_LOOP_REPORT_DIR, out: dir, ...(bin ? { bin } : {}), ...(opts.noForks ? { noForks: true } : {}), ...member }),
615
932
  env: key,
616
933
  dir,
617
934
  ...(evidenceKeyless(evidence) ? { idTokens: evidenceIdTokens(evidence) } : {}),
618
935
  };
619
936
  }
620
937
  return {
621
- lines: planEvidenceLines({ dir: PR_LOOP_REPORT_DIR, at: '"$HEAD_SHA"', base: '"$BASE_SHA"', result: '"$PLAN_RESULT"', ...(bin ? { bin } : {}) }),
938
+ lines: planEvidenceLines({ dir: PR_LOOP_REPORT_DIR, at: '"$HEAD_SHA"', base: '"$BASE_SHA"', result: '"$PLAN_RESULT"', ...(bin ? { bin } : {}), ...member }),
622
939
  env: { HEAD_SHA: "${{ github.sha }}", BASE_SHA: "${{ github.event.pull_request.base.sha }}", PLAN_RESULT: `\${{ needs.${planJob}.result }}`, ...key },
623
940
  ...(evidenceKeyless(evidence) ? { idToken: true as const } : {}),
624
941
  };