@intentius/chant 0.124.88 → 0.124.89

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 (303) 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 +177 -0
  10. package/dist/ci-comment-commands.d.ts.map +1 -0
  11. package/dist/ci-comment-commands.js +325 -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-note-commands.d.ts +63 -3
  25. package/dist/ci-note-commands.d.ts.map +1 -1
  26. package/dist/ci-note-commands.js +69 -35
  27. package/dist/ci-product-words.d.ts +42 -0
  28. package/dist/ci-product-words.d.ts.map +1 -1
  29. package/dist/ci-product-words.js +25 -0
  30. package/dist/ci-product.d.ts +31 -0
  31. package/dist/ci-product.d.ts.map +1 -1
  32. package/dist/ci-product.js +34 -4
  33. package/dist/cli/commands/build.d.ts.map +1 -1
  34. package/dist/cli/commands/build.js +29 -2
  35. package/dist/cli/handlers/approve.d.ts.map +1 -1
  36. package/dist/cli/handlers/approve.js +2 -1
  37. package/dist/cli/handlers/ci-check.d.ts +1 -1
  38. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  39. package/dist/cli/handlers/ci-check.js +17 -7
  40. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  41. package/dist/cli/handlers/ci-evidence.js +33 -7
  42. package/dist/cli/handlers/components.d.ts.map +1 -1
  43. package/dist/cli/handlers/components.js +3 -1
  44. package/dist/cli/handlers/generated-check.d.ts +8 -0
  45. package/dist/cli/handlers/generated-check.d.ts.map +1 -1
  46. package/dist/cli/handlers/generated-check.js +31 -1
  47. package/dist/cli/handlers/lock.d.ts.map +1 -1
  48. package/dist/cli/handlers/lock.js +121 -4
  49. package/dist/cli/handlers/pr-comment.d.ts +21 -0
  50. package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
  51. package/dist/cli/handlers/pr-comment.js +112 -0
  52. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  53. package/dist/cli/handlers/pr-env.js +6 -3
  54. package/dist/cli/handlers/pr.d.ts +23 -1
  55. package/dist/cli/handlers/pr.d.ts.map +1 -1
  56. package/dist/cli/handlers/pr.js +55 -9
  57. package/dist/cli/handlers/promote.d.ts.map +1 -1
  58. package/dist/cli/handlers/promote.js +2 -1
  59. package/dist/cli/handlers/release.d.ts.map +1 -1
  60. package/dist/cli/handlers/release.js +11 -2
  61. package/dist/cli/handlers/run-wave.d.ts.map +1 -1
  62. package/dist/cli/handlers/run-wave.js +28 -2
  63. package/dist/cli/handlers/run.d.ts.map +1 -1
  64. package/dist/cli/handlers/run.js +2 -1
  65. package/dist/cli/main.d.ts.map +1 -1
  66. package/dist/cli/main.js +24 -2
  67. package/dist/cli/parse-args.d.ts.map +1 -1
  68. package/dist/cli/parse-args.js +16 -0
  69. package/dist/cli/registry.d.ts +11 -0
  70. package/dist/cli/registry.d.ts.map +1 -1
  71. package/dist/components/auto-release.d.ts.map +1 -1
  72. package/dist/components/auto-release.js +2 -1
  73. package/dist/components/pr-checks.d.ts +70 -6
  74. package/dist/components/pr-checks.d.ts.map +1 -1
  75. package/dist/components/pr-checks.js +74 -13
  76. package/dist/components/pr-pipeline.d.ts +16 -12
  77. package/dist/components/pr-pipeline.d.ts.map +1 -1
  78. package/dist/components/pr-pipeline.js +3 -11
  79. package/dist/components/product-pipeline.d.ts +42 -1
  80. package/dist/components/product-pipeline.d.ts.map +1 -1
  81. package/dist/components/product-pipeline.js +64 -12
  82. package/dist/components/product-plan.d.ts +190 -5
  83. package/dist/components/product-plan.d.ts.map +1 -1
  84. package/dist/components/product-plan.js +220 -39
  85. package/dist/drift-record.d.ts +7 -0
  86. package/dist/drift-record.d.ts.map +1 -1
  87. package/dist/drift-record.js +19 -0
  88. package/dist/floor-table.data.d.ts.map +1 -1
  89. package/dist/floor-table.data.js +54 -31
  90. package/dist/forge-check/contract.d.ts +11 -1
  91. package/dist/forge-check/contract.d.ts.map +1 -1
  92. package/dist/forge-check/contract.js +4 -1
  93. package/dist/forge-check/index.d.ts +2 -0
  94. package/dist/forge-check/index.d.ts.map +1 -1
  95. package/dist/forge-check/index.js +2 -0
  96. package/dist/gate-resume-run.d.ts +9 -1
  97. package/dist/gate-resume-run.d.ts.map +1 -1
  98. package/dist/gate-resume-run.js +26 -3
  99. package/dist/generated-check.d.ts +18 -4
  100. package/dist/generated-check.d.ts.map +1 -1
  101. package/dist/generated-check.js +37 -5
  102. package/dist/image-pins.d.ts +26 -0
  103. package/dist/image-pins.d.ts.map +1 -0
  104. package/dist/image-pins.js +19 -0
  105. package/dist/lexicon.d.ts +11 -0
  106. package/dist/lexicon.d.ts.map +1 -1
  107. package/dist/lifecycle/git.d.ts +11 -0
  108. package/dist/lifecycle/git.d.ts.map +1 -1
  109. package/dist/lifecycle/git.js +30 -3
  110. package/dist/lifecycle/publish-npm.d.ts +11 -0
  111. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  112. package/dist/lifecycle/publish-npm.js +27 -1
  113. package/dist/lifecycle/reach-locks.d.ts +131 -0
  114. package/dist/lifecycle/reach-locks.d.ts.map +1 -0
  115. package/dist/lifecycle/reach-locks.js +118 -0
  116. package/dist/lifecycle/release-cut.d.ts +3 -1
  117. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  118. package/dist/lifecycle/release-cut.js +15 -0
  119. package/dist/lifecycle/release-images.d.ts.map +1 -1
  120. package/dist/lifecycle/release-images.js +1 -2
  121. package/dist/notify-product.d.ts +12 -3
  122. package/dist/notify-product.d.ts.map +1 -1
  123. package/dist/notify-product.js +10 -6
  124. package/dist/op/activities/source-release.d.ts.map +1 -1
  125. package/dist/op/activities/source-release.js +2 -1
  126. package/dist/op/activities/source-rollback.d.ts.map +1 -1
  127. package/dist/op/activities/source-rollback.js +2 -1
  128. package/dist/op/index.d.ts +2 -0
  129. package/dist/op/index.d.ts.map +1 -1
  130. package/dist/op/index.js +1 -0
  131. package/dist/op/op-waves-evidence-jobs.d.ts +6 -1
  132. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
  133. package/dist/op/op-waves-evidence-jobs.js +9 -3
  134. package/dist/op/op-waves-render-spec.d.ts +100 -0
  135. package/dist/op/op-waves-render-spec.d.ts.map +1 -0
  136. package/dist/op/op-waves-render-spec.js +162 -0
  137. package/dist/op/op-waves-run.d.ts +2 -0
  138. package/dist/op/op-waves-run.d.ts.map +1 -1
  139. package/dist/op/op-waves-run.js +2 -1
  140. package/dist/op/op-waves.d.ts +4 -0
  141. package/dist/op/op-waves.d.ts.map +1 -1
  142. package/dist/op/op-waves.js +4 -1
  143. package/dist/op/schedule-overdue.d.ts.map +1 -1
  144. package/dist/op/schedule-overdue.js +59 -3
  145. package/dist/op/wave-stop.d.ts +64 -0
  146. package/dist/op/wave-stop.d.ts.map +1 -0
  147. package/dist/op/wave-stop.js +127 -0
  148. package/dist/planned-files.d.ts +76 -0
  149. package/dist/planned-files.d.ts.map +1 -0
  150. package/dist/planned-files.js +108 -0
  151. package/dist/pr-forge-job.d.ts +22 -0
  152. package/dist/pr-forge-job.d.ts.map +1 -0
  153. package/dist/pr-forge-job.js +46 -0
  154. package/dist/pr-loop.d.ts +3 -6
  155. package/dist/pr-loop.d.ts.map +1 -1
  156. package/dist/pr-loop.js +4 -81
  157. package/dist/pr-plan-note.d.ts +97 -0
  158. package/dist/pr-plan-note.d.ts.map +1 -1
  159. package/dist/pr-plan-note.js +94 -1
  160. package/dist/pr-post.d.ts +28 -3
  161. package/dist/pr-post.d.ts.map +1 -1
  162. package/dist/pr-post.js +145 -13
  163. package/dist/pr-status.d.ts +16 -0
  164. package/dist/pr-status.d.ts.map +1 -0
  165. package/dist/pr-status.js +90 -0
  166. package/dist/ref-gate-init.d.ts +16 -2
  167. package/dist/ref-gate-init.d.ts.map +1 -1
  168. package/dist/ref-gate-init.js +24 -13
  169. package/dist/release-floors.d.ts +37 -1
  170. package/dist/release-floors.d.ts.map +1 -1
  171. package/dist/release-floors.js +61 -25
  172. package/dist/render-module.d.ts +15 -0
  173. package/dist/render-module.d.ts.map +1 -0
  174. package/dist/render-module.js +73 -0
  175. package/dist/state-migration.d.ts.map +1 -1
  176. package/dist/state-migration.js +1 -2
  177. package/dist/wave-runtime.mjs +304 -301
  178. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  179. package/dist/workspace/ci-green-cli.js +3 -2
  180. package/dist/workspace/release-train.d.ts.map +1 -1
  181. package/dist/workspace/release-train.js +2 -1
  182. package/dist/workspace/release-workflow.d.ts +4 -3
  183. package/dist/workspace/release-workflow.d.ts.map +1 -1
  184. package/dist/workspace/release-workflow.js +10 -7
  185. package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
  186. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  187. package/dist/workspace/trust/check-evidence-report.js +15 -8
  188. package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
  189. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
  190. package/dist/workspace/trust/ref-gate-cli.js +30 -10
  191. package/dist/workspace/workspace-run.d.ts.map +1 -1
  192. package/dist/workspace/workspace-run.js +2 -1
  193. package/package.json +1 -1
  194. package/src/actor.test.ts +68 -2
  195. package/src/actor.ts +61 -1
  196. package/src/chant-install.test.ts +2 -3
  197. package/src/chant-install.ts +1 -2
  198. package/src/ci-base.test.ts +41 -0
  199. package/src/ci-base.ts +43 -0
  200. package/src/ci-comment-commands.test.ts +376 -0
  201. package/src/ci-comment-commands.ts +389 -0
  202. package/src/ci-comment-replies.ts +78 -0
  203. package/src/ci-commit.test.ts +2 -3
  204. package/src/ci-evidence-from-job.test.ts +18 -0
  205. package/src/ci-evidence-from-job.ts +58 -2
  206. package/src/ci-evidence-jobs.ts +50 -5
  207. package/src/ci-image.test.ts +130 -9
  208. package/src/ci-image.ts +85 -12
  209. package/src/ci-note-commands.ts +104 -41
  210. package/src/ci-product-words.ts +59 -0
  211. package/src/ci-product.ts +40 -4
  212. package/src/cli/commands/build.test.ts +41 -0
  213. package/src/cli/commands/build.ts +27 -2
  214. package/src/cli/handlers/approve.ts +2 -1
  215. package/src/cli/handlers/ci-check.ts +19 -7
  216. package/src/cli/handlers/ci-evidence.ts +29 -8
  217. package/src/cli/handlers/components.ts +3 -1
  218. package/src/cli/handlers/generated-check.ts +31 -1
  219. package/src/cli/handlers/lock-reach.test.ts +103 -0
  220. package/src/cli/handlers/lock.ts +100 -4
  221. package/src/cli/handlers/pr-comment.ts +104 -0
  222. package/src/cli/handlers/pr-env.ts +6 -3
  223. package/src/cli/handlers/pr-record.test.ts +1 -1
  224. package/src/cli/handlers/pr.ts +50 -10
  225. package/src/cli/handlers/promote.ts +2 -1
  226. package/src/cli/handlers/release.e2e.test.ts +35 -0
  227. package/src/cli/handlers/release.ts +14 -2
  228. package/src/cli/handlers/run-wave.ts +28 -2
  229. package/src/cli/handlers/run.ts +2 -1
  230. package/src/cli/main.ts +24 -2
  231. package/src/cli/parse-args.ts +12 -0
  232. package/src/cli/registry.ts +11 -0
  233. package/src/components/auto-release.ts +2 -1
  234. package/src/components/pr-checks.ts +112 -17
  235. package/src/components/pr-pipeline.ts +17 -15
  236. package/src/components/product-pipeline.ts +93 -11
  237. package/src/components/product-plan.test.ts +40 -2
  238. package/src/components/product-plan.ts +331 -45
  239. package/src/drift-record.test.ts +20 -0
  240. package/src/drift-record.ts +16 -0
  241. package/src/floor-table.data.ts +54 -31
  242. package/src/forge-check/contract.ts +12 -1
  243. package/src/forge-check/forge-check.test.ts +17 -0
  244. package/src/forge-check/index.ts +2 -0
  245. package/src/gate-resume-run.ts +27 -3
  246. package/src/generated-check.e2e.test.ts +21 -1
  247. package/src/generated-check.test.ts +66 -0
  248. package/src/generated-check.ts +51 -10
  249. package/src/image-pins.ts +31 -0
  250. package/src/lexicon.ts +11 -0
  251. package/src/lifecycle/git.test.ts +48 -0
  252. package/src/lifecycle/git.ts +27 -4
  253. package/src/lifecycle/publish-npm.ts +31 -1
  254. package/src/lifecycle/reach-locks.test.ts +87 -0
  255. package/src/lifecycle/reach-locks.ts +169 -0
  256. package/src/lifecycle/release-cut.ts +17 -1
  257. package/src/lifecycle/release-images.test.ts +56 -0
  258. package/src/lifecycle/release-images.ts +1 -2
  259. package/src/notify-product.ts +19 -8
  260. package/src/op/activities/source-release.ts +2 -1
  261. package/src/op/activities/source-rollback.ts +2 -1
  262. package/src/op/gate-resume.test.ts +27 -0
  263. package/src/op/index.ts +10 -0
  264. package/src/op/op-waves-evidence-jobs.ts +10 -4
  265. package/src/op/op-waves-notify-words.test.ts +18 -0
  266. package/src/op/op-waves-render-spec.test.ts +160 -0
  267. package/src/op/op-waves-render-spec.ts +171 -0
  268. package/src/op/op-waves-run.ts +2 -1
  269. package/src/op/op-waves.ts +5 -2
  270. package/src/op/schedule-overdue.test.ts +43 -0
  271. package/src/op/schedule-overdue.ts +57 -3
  272. package/src/op/wave-stop.test.ts +72 -0
  273. package/src/op/wave-stop.ts +137 -0
  274. package/src/planned-files.test.ts +80 -0
  275. package/src/planned-files.ts +134 -0
  276. package/src/pr-forge-job.test.ts +53 -0
  277. package/src/pr-forge-job.ts +46 -0
  278. package/src/pr-loop-narrowed.test.ts +2 -1
  279. package/src/pr-loop-words.test.ts +2 -1
  280. package/src/pr-loop.test.ts +1 -2
  281. package/src/pr-loop.ts +4 -80
  282. package/src/pr-plan-note.ts +155 -3
  283. package/src/pr-post-replan.test.ts +144 -0
  284. package/src/pr-post-subject.test.ts +230 -0
  285. package/src/pr-post.test.ts +2 -1
  286. package/src/pr-post.ts +150 -15
  287. package/src/pr-status.ts +91 -0
  288. package/src/ref-gate-init.ts +30 -11
  289. package/src/release-floors.ts +78 -25
  290. package/src/render-module.ts +73 -0
  291. package/src/state-migration-record.test.ts +2 -3
  292. package/src/state-migration.ts +1 -2
  293. package/src/workspace/ci-green-cli.ts +3 -2
  294. package/src/workspace/ci-green-workflow.test.ts +32 -1
  295. package/src/workspace/release-train.ts +2 -1
  296. package/src/workspace/release-workflow.test.ts +36 -5
  297. package/src/workspace/release-workflow.ts +10 -7
  298. package/src/workspace/trust/check-evidence-report.ts +15 -8
  299. package/src/workspace/trust/check-evidence.test.ts +5 -0
  300. package/src/workspace/trust/ref-gate-cli.ts +30 -8
  301. package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
  302. package/src/workspace/trust/ref-gate.test.ts +10 -0
  303. package/src/workspace/workspace-run.ts +2 -1
@@ -29,9 +29,10 @@
29
29
 
30
30
  import { GITLAB_AGENT_ASK_VAR, GITLAB_AGENT_PR_VAR } from "./ci-agent";
31
31
  import { GITLAB_COMMIT_ARG_VAR, GITLAB_COMMIT_PR_VAR, GITLAB_COMMIT_WORD_VAR } from "./ci-commit";
32
- import { parseProductComment, productStatusContext, type CiProductWords, type ParsedProductComment } from "./ci-product-words";
32
+ import { parseProductComment, productStatusContext, type CiProductCommand, type CiProductWords, type ParsedProductComment } from "./ci-product-words";
33
+ import { commandLine, commentTerms, forkReply, memberReply, notRunReply } from "./ci-comment-replies";
33
34
  import { GITLAB_APPLY_PR_VAR, GITLAB_LOCK_PR_VAR, GITLAB_PREVIEW_PR_VAR, GITLAB_UNLOCK_PR_VAR, PREVIEW_COMMENT_ENV } from "./components/pr-pipeline";
34
- import { ForgeApiError, type ForgeFetch, type GitlabForgeOptions, type PrForge } from "./pr-forge";
35
+ import { ForgeApiError, type ForgeFetch, type ForgeKind, type GitlabForgeOptions, type PrForge } from "./pr-forge";
35
36
  import type { ForgeReads, PullRequestDetail, PullRequestNote, RunJob, WorkflowRun } from "./pr-forge-reads";
36
37
 
37
38
  export { GITLAB_NOTE_COMMANDS_VAR } from "./components/pr-pipeline";
@@ -304,8 +305,11 @@ async function answer(o: NoteCommandsOptions, mr: PullRequestDetail, note: PullR
304
305
  }
305
306
  return reply(`started pipeline${link(started)} to ${run.doing} for ${note.author}`, true, started.url);
306
307
  }
307
- case "retry":
308
- return retry(o, mr, note.author, run, reply, broke);
308
+ case "retry": {
309
+ const done = await retryApply(o, "gitlab", mr, note.author, run, gitlabRetry(o.pipelines));
310
+ if (done.kind === "fail") return broke(done.reason);
311
+ return reply(done.text, done.kind === "ran", done.kind === "ran" ? done.url : undefined);
312
+ }
309
313
  }
310
314
  }
311
315
 
@@ -314,17 +318,53 @@ export const APPLY_JOBS = /^(?:[a-z0-9][a-z0-9-]*-)?apply(?:-wave-([1-9][0-9]*)(
314
318
 
315
319
  const NOT_DONE = new Set(["created", "pending", "running", "waiting_for_resource", "preparing", "scheduled"]);
316
320
 
317
- async function retry(
318
- o: NoteCommandsOptions,
319
- mr: PullRequestDetail,
320
- user: string,
321
- run: Extract<NoteRun, { kind: "retry" }>,
322
- reply: (text: string, ran?: boolean, url?: string) => Promise<NoteOutcome>,
323
- broke: (reason: string) => NoteOutcome,
324
- ): Promise<NoteOutcome> {
321
+ /** What starting a merge commit's apply again came to: a reply alone, a run started (`ran`), or a forge answer that broke it. */
322
+ export type ApplyRetried = { kind: "reply"; text: string } | { kind: "ran"; text: string; url?: string } | { kind: "fail"; reason: string };
323
+
324
+ /** What {@link ApplyRerun} is told: the merge commit, the pull request's name in a reply, who asked, and the default branch. */
325
+ export interface ApplyRerunContext {
326
+ sha: string;
327
+ /** `!12`, or `pull request 12`. */
328
+ at: string;
329
+ user: string;
330
+ base: string;
331
+ /** The pattern the apply jobs matched, whose groups are the wave and the share. */
332
+ pattern: RegExp;
333
+ }
334
+
335
+ /**
336
+ * How a forge starts a merge commit's apply again (#4946), once
337
+ * {@link retryApply} found the push run at the commit with apply jobs and no
338
+ * later apply. GitLab retries the first apply job that did not succeed
339
+ * ({@link gitlabRetry}); GitHub and Forgejo answer in ./ci-comment-commands.ts.
340
+ */
341
+ export type ApplyRerun = (run: WorkflowRun, jobs: RunJob[], c: ApplyRerunContext) => Promise<ApplyRetried>;
342
+
343
+ /** What {@link retryApply} reads with. */
344
+ export interface ApplyRetryReads {
345
+ reads: ForgeReads;
346
+ /** chant's client: it reads the later commits' statuses. */
347
+ forge: Pick<PrForge, "commitStatuses">;
348
+ words: CiProductWords;
349
+ /** The default branch. */
350
+ base: string;
351
+ }
352
+
353
+ /**
354
+ * Start a merged pull request's apply again (#4785; shared with GitHub and
355
+ * Forgejo in #4946): the newest push run at the merge commit that has an
356
+ * apply job, refused when a later commit of the default branch already
357
+ * carries the product's apply status, since going back to this one would
358
+ * undo it. `rerun` is the forge's own start.
359
+ */
360
+ export async function retryApply(o: ApplyRetryReads, forgeKind: ForgeKind, mr: PullRequestDetail, user: string, run: Extract<NoteRun, { kind: "retry" }>, rerun: ApplyRerun): Promise<ApplyRetried> {
325
361
  const { sha } = run;
326
362
  const pattern = run.jobs ?? APPLY_JOBS;
327
- const iid = mr.number;
363
+ const t = commentTerms(forgeKind);
364
+ const at = t.at(mr.number);
365
+ const gitlab = forgeKind === "gitlab";
366
+ const runWord = gitlab ? "pipeline" : "workflow run";
367
+ const reply = (text: string): ApplyRetried => ({ kind: "reply", text });
328
368
  // The newest push pipeline at the merge commit with an apply job: a branch pipeline, or a ci/green tag's.
329
369
  let pipeline: WorkflowRun | undefined;
330
370
  let jobs: RunJob[] = [];
@@ -338,10 +378,10 @@ async function retry(
338
378
  break;
339
379
  }
340
380
  }
341
- if (!pipeline) return reply(`no pipeline at the merge commit ${short(sha)} of !${iid} has an apply job, so there is nothing to retry; push to ${o.base} again`);
381
+ if (!pipeline) return reply(`no ${runWord} at the merge commit ${short(sha)} of ${at} has an apply job, so there is nothing to ${gitlab ? "retry" : "run again"}; push to ${o.base} again`);
342
382
  newer = await o.reads.branchRuns(o.base, { event: "push", limit: NOTE_COMMANDS_NEWER_PIPELINES });
343
383
  } catch (e) {
344
- return broke(`could not read the pipelines at ${short(sha)} (${message(e)})`);
384
+ return { kind: "fail", reason: `could not read the ${runWord}s at ${short(sha)} (${message(e)})` };
345
385
  }
346
386
  // A later commit whose apply started applied a newer tree: going back to this one would undo it.
347
387
  const applyContext = productStatusContext(o.words, "apply");
@@ -351,32 +391,40 @@ async function retry(
351
391
  try {
352
392
  applied = (await o.forge.commitStatuses?.(c))?.find((s) => s.context === applyContext);
353
393
  } catch (e) {
354
- return broke(`could not read the statuses of ${short(c)} (${message(e)})`);
394
+ return { kind: "fail", reason: `could not read the statuses of ${short(c)} (${message(e)})` };
355
395
  }
356
396
  if (applied) {
357
- const at = applied.targetUrl && /^https?:\/\//.test(applied.targetUrl) ? ` (${applied.targetUrl})` : "";
358
- return reply(`a later apply already ran on ${o.base} at ${short(c)}${at}, so the merge commit ${short(sha)} of !${iid} is not applied: comment on the merge request that commit came from, or push again`);
397
+ const link = applied.targetUrl && /^https?:\/\//.test(applied.targetUrl) ? ` (${applied.targetUrl})` : "";
398
+ return reply(`a later apply already ran on ${o.base} at ${short(c)}${link}, so the merge commit ${short(sha)} of ${at} is not applied: comment on the ${t.request} that commit came from, or push again`);
359
399
  }
360
400
  }
361
- const order = (j: RunJob): [number, number] => {
362
- const m = pattern.exec(j.name);
363
- return [m?.[1] ? Number(m[1]) : 0, m?.[2] ? Number(m[2]) : 0];
401
+ return rerun(pipeline, jobs, { sha, at, user, base: o.base, pattern });
402
+ }
403
+
404
+ /** GitLab's start: retry the first apply job, by wave and share, that did not succeed; the jobs after it follow by themselves. */
405
+ export function gitlabRetry(pipelines: Pick<GitlabPipelines, "retryJob">): ApplyRerun {
406
+ return async (pipeline, jobs, { sha, at, user, base, pattern }) => {
407
+ const reply = (text: string): ApplyRetried => ({ kind: "reply", text });
408
+ const order = (j: RunJob): [number, number] => {
409
+ const m = pattern.exec(j.name);
410
+ return [m?.[1] ? Number(m[1]) : 0, m?.[2] ? Number(m[2]) : 0];
411
+ };
412
+ const sorted = [...jobs].sort((a, b) => order(a)[0] - order(b)[0] || order(a)[1] - order(b)[1]);
413
+ const next = sorted.find((j) => j.status !== "success");
414
+ if (!next) return reply(`every apply job of ${at}'s merge commit ${short(sha)} already succeeded`);
415
+ if (NOT_DONE.has(next.status)) return reply(`${next.name} at ${short(sha)} is ${next.status} already, so it is not retried`);
416
+ if (next.status !== "failed" && next.status !== "canceled") {
417
+ return reply(`${next.name} at ${short(sha)} was ${next.status}, and GitLab retries only a failed or canceled job; push to ${base} again`);
418
+ }
419
+ let retried: StartedRun;
420
+ try {
421
+ retried = await pipelines.retryJob(next.id);
422
+ } catch (e) {
423
+ return { kind: "fail", reason: `could not retry ${next.name} of pipeline ${pipeline.id} (${message(e)})` };
424
+ }
425
+ const link = retried.url ? ` (${retried.url})` : "";
426
+ return { kind: "ran", text: `retried ${next.name} of ${at}'s merge commit ${short(sha)}${link} for ${user}; its gate decides again, and the jobs after it follow, each behind its own gate`, ...(retried.url ? { url: retried.url } : {}) };
364
427
  };
365
- const sorted = [...jobs].sort((a, b) => order(a)[0] - order(b)[0] || order(a)[1] - order(b)[1]);
366
- const next = sorted.find((j) => j.status !== "success");
367
- if (!next) return reply(`every apply job of !${iid}'s merge commit ${short(sha)} already succeeded`);
368
- if (NOT_DONE.has(next.status)) return reply(`${next.name} at ${short(sha)} is ${next.status} already, so it is not retried`);
369
- if (next.status !== "failed" && next.status !== "canceled") {
370
- return reply(`${next.name} at ${short(sha)} was ${next.status}, and GitLab retries only a failed or canceled job; push to ${o.base} again`);
371
- }
372
- let retried: StartedRun;
373
- try {
374
- retried = await o.pipelines.retryJob(next.id);
375
- } catch (e) {
376
- return broke(`could not retry ${next.name} of pipeline ${pipeline.id} (${message(e)})`);
377
- }
378
- const link = retried.url ? ` (${retried.url})` : "";
379
- return reply(`retried ${next.name} of !${iid}'s merge commit ${short(sha)}${link} for ${user}; its gate decides again, and the jobs after it follow, each behind its own gate`, true, retried.url);
380
428
  }
381
429
 
382
430
  /** The jobs chant's GitLab pipeline has, which {@link chantNoteRuns} starts. */
@@ -393,17 +441,32 @@ export interface ChantNoteJobs {
393
441
  agent?: boolean;
394
442
  /** The commit jobs, started with `CHANT_COMMIT_PR`, `CHANT_COMMIT` and `CHANT_COMMIT_ARG`. */
395
443
  commits?: boolean;
444
+ /**
445
+ * The members the pipeline was written with (#4946), such as terragucci's
446
+ * roots: a plan or an action naming any other gets the words' `member`
447
+ * reply, and nothing starts. Absent: any member a comment may name.
448
+ */
449
+ members?: readonly string[];
396
450
  }
397
451
 
398
- /** What a command runs in chant's own GitLab pipeline, for the jobs it has. */
452
+ /**
453
+ * What a command runs in chant's own GitLab pipeline, for the jobs it has.
454
+ * A command no job runs gets the words' reply for it (`words.replies`,
455
+ * #4946), else chant's.
456
+ */
399
457
  export function chantNoteRuns(jobs: ChantNoteJobs): NoteCommandRuns {
400
458
  return ({ mr, note, parsed, base, words }): NoteRun => {
401
459
  const iid = String(mr.number);
402
460
  const at = `!${mr.number}`;
403
- const line = (kind: string): string => `\`/${words.product} ${Object.entries(words.commands).find(([, c]) => c === kind)?.[0] ?? kind}\``;
404
- if (!mr.sameRepo) return { kind: "reply", text: `a merge request from a fork runs no command: its code never runs with this project's credentials` };
461
+ const line = (kind: CiProductCommand): string => commandLine(words, kind);
462
+ // #4946: a member outside the pipeline's is refused before anything starts, a fork's included.
463
+ const member = parsed.kind === "plan" || parsed.kind === "action" ? parsed.member : undefined;
464
+ if (member !== undefined && jobs.members && !jobs.members.includes(member)) return { kind: "reply", text: memberReply(words, member, jobs.members, "gitlab") };
465
+ if (!mr.sameRepo) return { kind: "reply", text: forkReply(words, "gitlab") };
405
466
  const open = mr.state === "open";
406
467
  const intoBase = mr.base === undefined || mr.base === base;
468
+ // #4946: the product's sentence for an apply no job answers, in place of chant's, which say what the merge does.
469
+ if (parsed.kind === "apply" && !jobs.applyBeforeMerge && !jobs.applyOnMerge && words.replies?.apply !== undefined) return { kind: "reply", text: words.replies.apply };
407
470
  switch (parsed.kind) {
408
471
  case "plan":
409
472
  if (!open) return { kind: "reply", text: `${at} is not open, so it is not ${words.verbs.plan[1]}` };
@@ -425,11 +488,11 @@ export function chantNoteRuns(jobs: ChantNoteJobs): NoteCommandRuns {
425
488
  return { kind: "retry", sha: mr.mergeCommit };
426
489
  case "lock":
427
490
  case "unlock":
428
- if (!jobs.locks) return { kind: "reply", text: `${line(parsed.kind)} does not run here: this project takes no locks` };
491
+ if (!jobs.locks) return { kind: "reply", text: notRunReply(words, parsed.kind, "gitlab") };
429
492
  if (parsed.kind === "lock" && !open) return { kind: "reply", text: `${at} is not open, so it takes no lock` };
430
493
  return { kind: "pipeline", ref: base, variables: { [parsed.kind === "lock" ? GITLAB_LOCK_PR_VAR : GITLAB_UNLOCK_PR_VAR]: iid }, doing: `${parsed.kind} the ${words.noun[1]} of ${at}` };
431
494
  case "agent":
432
- if (!jobs.agent) return { kind: "reply", text: `the agent command is off in this project` };
495
+ if (!jobs.agent) return { kind: "reply", text: notRunReply(words, "agent", "gitlab") };
433
496
  if (!open) return { kind: "reply", text: `${at} is not open, so the agent does not run` };
434
497
  if (mr.head === base) return { kind: "reply", text: `${at}'s source branch is the default branch, and an agent never pushes there` };
435
498
  return { kind: "pipeline", ref: base, variables: { [GITLAB_AGENT_PR_VAR]: iid, [GITLAB_AGENT_ASK_VAR]: parsed.ask }, doing: `run the agent on ${at}` };
@@ -68,8 +68,48 @@ export interface CiProductAlias {
68
68
  command: CiProductCommand;
69
69
  /** The variable that turns the alias on in a job (terragucci's `TG_ATLANTIS_COMMENTS`). Absent: always on. */
70
70
  when?: string;
71
+ /**
72
+ * Flags of the other tool that the product has no counterpart for, each
73
+ * with the reply that refuses it (#4946), such as terragucci's `{ "-p":
74
+ * "a root goes by its path, not a project name: ..." }` on `atlantis
75
+ * plan`. A flag here is refused before the alias reads `-d`, so a product
76
+ * can refuse `atlantis apply -d` too. `--` refuses everything after it.
77
+ */
78
+ refuse?: Record<string, string>;
71
79
  }
72
80
 
81
+ /**
82
+ * What a comment job replies to a command the pipeline runs no job for
83
+ * (#4946), in the product's own sentences. Each slot left out takes
84
+ * chant's. The comment job on GitHub and Forgejo and the note poll on
85
+ * GitLab both read these.
86
+ */
87
+ export interface CiProductCommentReplies {
88
+ /** A plan comment where no job plans on a comment (GitHub and Forgejo; GitLab starts a merge request pipeline). */
89
+ plan?: string;
90
+ /** An apply comment where no job applies on a comment: neither an apply before merge nor the re-run of a merged pull request's apply. */
91
+ apply?: string;
92
+ /** A lock comment where the pipeline takes no locks. */
93
+ lock?: string;
94
+ /** An unlock comment where the pipeline takes no locks. */
95
+ unlock?: string;
96
+ /** An action comment where no workflow runs actions (GitHub and Forgejo; GitLab names the checkout to run it from). */
97
+ action?: string;
98
+ /** An agent comment where the agent is off. */
99
+ agent?: string;
100
+ /** Any command on a pull request from a fork. */
101
+ fork?: string;
102
+ /**
103
+ * A comment that names a member the pipeline was not written with, over
104
+ * `{member}` (the one named) and `{members}` (the pipeline's, each in
105
+ * backticks, sorted, comma separated).
106
+ */
107
+ member?: string;
108
+ }
109
+
110
+ /** The reply slots, for checking a product's words. */
111
+ export const CI_PRODUCT_COMMENT_REPLIES: readonly (keyof CiProductCommentReplies)[] = ["plan", "apply", "lock", "unlock", "action", "agent", "fork", "member"];
112
+
73
113
  /** The words a product passes. Every slot is optional; a missing one takes chant's. */
74
114
  export interface CiProductWordsInput {
75
115
  /** The status prefix, the note heading and the comment prefix: `chant`, `terragucci`, `plywood`. */
@@ -124,6 +164,8 @@ export interface CiProductWordsInput {
124
164
  adoptMarkers?: string[];
125
165
  /** What chant's notify sends under these words (#4610). */
126
166
  notify?: CiProductNotifyWordsInput;
167
+ /** The replies to commands the pipeline runs no job for (#4946). Default: chant's. */
168
+ replies?: CiProductCommentReplies;
127
169
  }
128
170
 
129
171
  /** The notify slots a product passes (#4610). */
@@ -174,6 +216,8 @@ export interface CiProductWords {
174
216
  bin?: string;
175
217
  adoptMarkers: string[];
176
218
  notify: CiProductNotifyWords;
219
+ /** The product's replies to commands no job runs (#4946), when it gives any. */
220
+ replies?: CiProductCommentReplies;
177
221
  }
178
222
 
179
223
  /** chant's own approve line. */
@@ -227,6 +271,7 @@ export function resolveProductWords(input: CiProductWordsInput | CiProductWords
227
271
  headers: input.notify?.headers ?? `x-${product}`,
228
272
  ...(input.notify?.message ? { message: input.notify.message } : {}),
229
273
  },
274
+ ...(input.replies !== undefined ? { replies: input.replies } : {}),
230
275
  };
231
276
  }
232
277
 
@@ -278,6 +323,17 @@ export function productWordsProblems(words: CiProductWords, options: { jobs?: re
278
323
  for (const a of words.aliases) {
279
324
  if (!/^[a-z0-9][a-z0-9 -]*$/.test(a.from)) problems.push(`the alias ${JSON.stringify(a.from)} is lowercase words`);
280
325
  if (!Object.values(words.commands).includes(a.command)) problems.push(`the alias ${JSON.stringify(a.from)} stands for ${a.command}, which no command names`);
326
+ // #4946: a refused flag is one word starting with -, and its reply one line.
327
+ for (const [flag, reason] of Object.entries(a.refuse ?? {})) {
328
+ if (!/^--?[A-Za-z0-9-]*$/.test(flag)) problems.push(`the alias ${JSON.stringify(a.from)} refuses ${JSON.stringify(flag)}, and a flag is - or -- then letters, digits and -`);
329
+ if (typeof reason !== "string" || reason.trim() === "" || /[\r\n]/.test(reason)) problems.push(`the alias ${JSON.stringify(a.from)} refuses ${flag} with no one-line reply`);
330
+ }
331
+ }
332
+ // #4946: each reply is one line of text; the member reply's placeholders are {member} and {members}.
333
+ for (const [slot, text] of Object.entries(words.replies ?? {})) {
334
+ if (!CI_PRODUCT_COMMENT_REPLIES.includes(slot as keyof CiProductCommentReplies)) problems.push(`replies.${slot} is not one of ${CI_PRODUCT_COMMENT_REPLIES.join(", ")}`);
335
+ else if (typeof text !== "string" || text.trim() === "" || /[\r\n]/.test(text)) problems.push(`replies.${slot} is one line of text`);
336
+ else for (const m of text.matchAll(/\{([^}]*)\}/g)) if (slot !== "member" || (m[1] !== "member" && m[1] !== "members")) problems.push(`replies.${slot} names {${m[1]}}, which chant does not fill`);
281
337
  }
282
338
  for (const [where, template] of [["approve", words.approve], ["override", words.override]] as const) {
283
339
  for (const m of template.matchAll(/\{([^}]*)\}/g)) if (!PLACEHOLDERS.has(m[1]!)) problems.push(`${where} names {${m[1]}}, which chant does not fill`);
@@ -560,6 +616,9 @@ export function parseProductComment(
560
616
  const args: string[] = [];
561
617
  for (let i = 0; i < rest.length; i++) {
562
618
  const w = rest[i]!;
619
+ // #4946: a flag the product has no counterpart for gets the product's own reason.
620
+ const refused = a.refuse && Object.prototype.hasOwnProperty.call(a.refuse, w) ? a.refuse[w] : undefined;
621
+ if (refused !== undefined) return { kind: "refused", reason: refused };
563
622
  if (w === "-d" || w === "--dir") {
564
623
  const dir = rest[++i];
565
624
  if (dir === undefined) return { kind: "refused", reason: `\`${w}\` names the ${words.noun[0]}'s directory` };
package/src/ci-product.ts CHANGED
@@ -140,26 +140,62 @@ export { planNoteHandoff, PR_PLAN_NOTE_FILE, type PrPlanNoteHandoff } from "./pr
140
140
  /**
141
141
  * The first chant whose product plan carries the plan-job steps beside the plan verb and the note job's own lines (#4899, #4931): `productPlan.login` and a target's `login` (ci-login) with the job's OIDC token, `idTokens`, `pending`, `controlRead`, `setup` steps, job-level `env`, `report`, `concurrency`, the comment re-plan `replan`, and `noteSteps`; a hand-off's `marker` kept under the note words' `productMarker`; and the note job's notices and overdue Ops under a hand-off's counts.
142
142
  */
143
- export const PRODUCT_PLAN_STEPS_FLOOR = NEXT_RELEASE;
143
+ export const PRODUCT_PLAN_STEPS_FLOOR = "0.124.88";
144
144
  export { PLAN_ARGUMENT_ENV, PLAN_NOTE_NOTICES_ENV, type ProductPlanReplanJob, type ProductPlanSetupStep } from "./components/product-plan";
145
145
 
146
146
  /**
147
147
  * The first chant whose `parseProductComment` takes `leaveCommit` and that has `commitWordOf` (#4890): a comment job that is not the commit job leaves every comment for a commit word to it, a malformed one included, so the comment gets one reply.
148
148
  */
149
- export const COMMENT_LEAVES_COMMIT_FLOOR = NEXT_RELEASE;
149
+ export const COMMENT_LEAVES_COMMIT_FLOOR = "0.124.88";
150
+
151
+ /**
152
+ * The first chant with the comment job on GitHub and Forgejo and the replies to commands no job runs (#4946): `commentJob` in the product pipeline (`chant components pr-comment`, `answerProductComment` in `@intentius/chant/ci-comment-commands`), which replies to a refusal and to a command the pipeline runs no job for, and with waves on merge starts a merged pull request's apply again; the words' `replies` and an alias's `refuse`, which the GitLab note poll reads too, as `chantNoteRuns`' `members`; `retryApply`; and `locks: "plan"` in GitHub's and Forgejo's product plan, with the lock, unlock and comment lock jobs.
153
+ */
154
+ export const COMMENT_COMMANDS_FLOOR = NEXT_RELEASE;
155
+ export { answerProductComment, answeredElsewhere, COMMENT_JOBS_ENV, commentRuns, PR_COMMENT_JOB, RERUN_APPLY_JOBS, type CommentJobs, type CommentOutcome, type CommentRuns, type AnswerCommentOptions } from "./ci-comment-commands";
156
+ export { forkReply, memberReply, notRunReply } from "./ci-comment-replies";
157
+ export type { CiProductCommentReplies } from "./ci-product-words";
158
+ export { productCommentJob, type ProductCommentJob } from "./components/product-pipeline";
159
+
160
+ /**
161
+ * The first chant whose product plan locks what a change reaches (#4979): `productPlan.reach`, a reach line the lock job runs at the target branch's commit with `chant lock --reach` (`@intentius/chant/lifecycle/reach-locks`), on GitHub, Forgejo and GitLab, where the lock job runs in the plan notes pipeline with `--open` beside the comment lock and unlock jobs; and whose comment job answers a re-plan comment with flags the product plan's re-plan cannot take (`noPlanFlags`).
162
+ */
163
+ export const PRODUCT_PLAN_REACH_LOCKS_FLOOR = NEXT_RELEASE;
164
+ export { LOCK_REACH_ENV, reachedTargets, reachOpen, type Reached, type ReachInput } from "./lifecycle/reach-locks";
165
+ export { productPlanReachLock, type ProductPlanReachLock } from "./components/product-plan";
166
+ export { planFlagsReply } from "./ci-comment-commands";
167
+
168
+ /**
169
+ * The first chant whose comment job stops a merged pull request's re-run at a wave (#4979): `/<product> apply wave-<n>` writes a stop for the merge commit on `chant/lifecycle` (`_waves/<op>.stops.json`, `@intentius/chant/op/wave-stop`) before GitHub's re-run or Forgejo's dispatch, and `chant run wave` leaves each wave after n waiting (exit 3).
170
+ */
171
+ export const WAVE_STOP_FLOOR = NEXT_RELEASE;
172
+ export { setWaveStop, waveStopAt, waveStopLine, type WaveStop } from "./op/wave-stop";
150
173
 
151
174
  /**
152
175
  * The first chant whose product plan takes `watches`, the product's own scheduled jobs the note job's `pr-post` checks for having stopped with the job's token (#4888), and whose `checkOverdueOps` and `overdueOpsAt` take a product's `logPrefix` and `label`.
153
176
  */
154
- export const PRODUCT_PLAN_WATCHES_FLOOR = NEXT_RELEASE;
177
+ export const PRODUCT_PLAN_WATCHES_FLOOR = "0.124.88";
155
178
  export { PLAN_WATCHES_ENV } from "./op/schedule-overdue";
156
179
 
157
180
  /**
158
181
  * The first chant whose product plan takes `record` (#4899): the plan step writes the plan job's run record into the hand-off, and the note job keeps it as Op `pr-plan` on `chant/lifecycle` with `pr-post --record-run <plan job>` (`--open` on GitLab), as `chant ci run plan --in-place` records `pr-plan`'s.
159
182
  */
160
- export const PRODUCT_PLAN_RECORD_FLOOR = NEXT_RELEASE;
183
+ export const PRODUCT_PLAN_RECORD_FLOOR = "0.124.88";
161
184
  export { PLAN_RUN_OP, PLAN_RUN_RECORD_FILE, readPlanRunRecord } from "./pr-plan-record";
162
185
 
186
+ /**
187
+ * The first chant whose product plan carries what terragucci's and sql-yodeler's plan jobs did themselves (#4963, #4951): `trade` (a plan's or a target's) before the checkout, `replan: { dispatch, reply, notAffected }` (a re-plan from `workflow_dispatch`, a reply to a comment no other job takes, `pr-post --not-affected`), `previousMarker` (`CHANT_PLAN_PREVIOUS_MARKER`), `noteSteps.pullRequest`, a `PrReport`'s `marker`, and a hand-off of the product's own note text (`planBodyHandoff`).
188
+ */
189
+ export const PRODUCT_PLAN_REPLAN_FLOOR = NEXT_RELEASE;
190
+ export { gitlabReplanArgumentLines, PREVIOUS_MARKER_JS, replanDecideJs, type ProductPlanReplanOptions } from "./components/product-plan";
191
+ export { planBodyHandoff, PLAN_BODY_LIMIT, type PrPlanBodyHandoff } from "./pr-plan-note";
192
+
193
+ /**
194
+ * The first chant whose note job compares the plan's subject with the previous note's (#4972), on GitHub, Forgejo and GitLab: a plan note hand-off's `subject` (`PrPlanSubject`, an id and named parts) is kept in the note, and `pr-post` adds the note words' `sinceLast` line, naming the parts added, gone and changed (`subjectParts`), when the previous note kept another id. The plan job reads no note, and `previousMarker` is deprecated.
195
+ */
196
+ export const PRODUCT_PLAN_SUBJECT_FLOOR = NEXT_RELEASE;
197
+ export { PLAN_SUBJECT_LIMIT, planSubjectProblem, sinceLastLine, subjectChanges, type PrPlanSubject, type PrPlanSubjectPartWords } from "./pr-plan-note";
198
+
163
199
  /**
164
200
  * Day-2 actions in the product pipeline (#4654): the `action` comment
165
201
  * command counted as answered by the product's own workflow
@@ -770,6 +770,47 @@ export const testEntity = {
770
770
  expect(existsSync(join(testDir, "dist", "ops", "alb-deploy", "worker.ts"))).toBe(true);
771
771
  });
772
772
 
773
+ describe("--output naming a directory (#4950)", () => {
774
+ /** Stands in for the docker lexicon on a project of Dockerfiles alone: a blank compose file and one file per Dockerfile. */
775
+ const dockerfilesOnly = (primary = "\n"): Serializer => ({
776
+ name: "dock",
777
+ rulePrefix: "DOCK",
778
+ serialize: () => ({ primary, files: { "Dockerfile.tofu": "FROM tofu\n", "Dockerfile.node": "FROM node\n" } }),
779
+ });
780
+ const declare = () =>
781
+ writeFile(
782
+ join(testDir, "images.ts"),
783
+ `export const tofu = { [Symbol.for("chant.declarable")]: true, entityType: "Docker::Dockerfile", lexicon: "dock", kind: "resource", props: {}, attributes: {} };\n`,
784
+ );
785
+
786
+ test("writes the additional files into it and no primary file, when the primary output is blank", async () => {
787
+ await declare();
788
+ const dir = join(testDir, "out", "images");
789
+ const result = await buildCommand({ path: testDir, output: `${dir}/`, format: "yaml", serializers: [dockerfilesOnly()] });
790
+ expect(result.errors).toEqual([]);
791
+ expect(readFileSync(join(dir, "Dockerfile.tofu"), "utf8")).toBe("FROM tofu\n");
792
+ expect(readFileSync(join(dir, "Dockerfile.node"), "utf8")).toBe("FROM node\n");
793
+ expect(existsSync(join(testDir, "out", "images.yaml"))).toBe(false);
794
+ });
795
+
796
+ test("takes an existing directory without the trailing slash", async () => {
797
+ await declare();
798
+ const dir = join(testDir, "existing");
799
+ await mkdir(dir, { recursive: true });
800
+ const result = await buildCommand({ path: testDir, output: dir, format: "yaml", serializers: [dockerfilesOnly()] });
801
+ expect(result.errors).toEqual([]);
802
+ expect(readFileSync(join(dir, "Dockerfile.tofu"), "utf8")).toBe("FROM tofu\n");
803
+ });
804
+
805
+ test("refuses a build with a primary output, which needs a file", async () => {
806
+ await declare();
807
+ const result = await buildCommand({ path: testDir, output: `${join(testDir, "d")}/`, format: "yaml", serializers: [dockerfilesOnly("services:\n a: {}\n")] });
808
+ expect(result.success).toBe(false);
809
+ expect(result.errors.join("\n")).toContain("names a directory");
810
+ expect(existsSync(join(testDir, "d", "Dockerfile.tofu"))).toBe(false);
811
+ });
812
+ });
813
+
773
814
  describe("committed-encrypted secret sidecars", () => {
774
815
  const CIPHERTEXT = 'apiVersion: v1\nkind: Secret\nstringData:\n T: ENC[AES256_GCM,data:xx]\nsops:\n version: 3.9.4\n';
775
816
 
@@ -34,7 +34,7 @@ import { sortedJsonReplacer } from "../../utils";
34
34
  import { rankFoldBlockers, toCollapsedFormat, type FoldRankResult } from "../../discovery/fold-rank";
35
35
  import { foldExecutionCounts } from "../../discovery/fold-import";
36
36
  import { formatError, formatWarning, formatSuccess, formatBold, formatInfo } from "../format";
37
- import { writeFileSync, mkdirSync } from "fs";
37
+ import { existsSync, statSync, writeFileSync, mkdirSync } from "fs";
38
38
  import { resolve, dirname, join, relative } from "path";
39
39
  import { watchDirectory, formatTimestamp, formatChangedFiles } from "../watch";
40
40
 
@@ -924,7 +924,32 @@ export async function buildCommand(options: BuildOptions): Promise<BuildResult>
924
924
  console.error(formatInfo(`Wrote ${irWritten} op.json file(s) under ${join(options.path ?? ".", "dist", "ops")}/`));
925
925
  }
926
926
 
927
- if (options.output) {
927
+ // #4950: `--output <dir>/` (or an existing directory) writes the
928
+ // additional files into that directory and no primary file, so a docker
929
+ // project of Dockerfiles alone renders them where they are committed
930
+ // (`chant build images -o images/`) with no compose file to throw away.
931
+ // A build whose primary output holds anything needs a file to put it in.
932
+ const outputDir =
933
+ options.output !== undefined && (/[\\/]$/.test(options.output) || (existsSync(options.output) && statSync(options.output).isDirectory()))
934
+ ? resolve(options.output)
935
+ : undefined;
936
+ if (outputDir !== undefined) {
937
+ if (output.trim() !== "") {
938
+ errors.push(
939
+ formatError({
940
+ message: `--output ${options.output} names a directory, which takes a build's additional files (a docker project's Dockerfiles) but not its primary output; this build has one, so name a file for it`,
941
+ }),
942
+ );
943
+ } else if (additionalFiles.size === 0) {
944
+ errors.push(formatError({ message: `--output ${options.output} names a directory, but this build has no files to write into it` }));
945
+ } else {
946
+ try {
947
+ for (const [filename, entry] of additionalFiles) writeOutput(join(outputDir, filename), entry.content);
948
+ } catch (err) {
949
+ errors.push(formatError({ message: `Failed to write output file: ${err instanceof Error ? err.message : String(err)}` }));
950
+ }
951
+ }
952
+ } else if (options.output) {
928
953
  // Write to file — ensure parent directories exist for both the primary
929
954
  // output path and any nested additional-file paths (e.g. ops/<name>/...).
930
955
  try {
@@ -35,6 +35,7 @@ import { readFileSync } from "node:fs";
35
35
  import { resolve as resolvePath } from "node:path";
36
36
  import { formatError, formatWarning, formatSuccess, formatInfo } from "../format";
37
37
  import type { CommandContext } from "../registry";
38
+ import { actorFromEnv } from "../../actor";
38
39
 
39
40
  // ── chant approve <op> <gate> ───────────────────────────────────────────────
40
41
 
@@ -623,7 +624,7 @@ async function approveGate(
623
624
  // "unattested" reads as what it is; a name the model chose would read in
624
625
  // the ledger exactly like a name a person gave.
625
626
  ? UNATTESTED_APPROVER
626
- : process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_LOGIN ?? process.env.USER ?? "unknown");
627
+ : actorFromEnv());
627
628
 
628
629
  // #2508: who this is, as the gate's quorum and policy read it. A model on
629
630
  // MCP or ACP is an agent whatever it claims, the same reasoning that gives
@@ -24,8 +24,13 @@
24
24
  * #4914: `--summary <file>` appends the report's markdown section
25
25
  * (`checkReportSummary`) to the file, as a product's check report keeps it,
26
26
  * and a job with `GITHUB_STEP_SUMMARY` set gets it in its summary too.
27
+ *
28
+ * #4966: `--base` defaults to the job's base (`ciBaseRef`,
29
+ * `@intentius/chant/ci-base`), `--branch` naming the default branch on a
30
+ * forge whose job does not carry it.
27
31
  */
28
32
  import { resolve } from "node:path";
33
+ import { ciBaseRef } from "../../ci-base";
29
34
  import type { CheckStageEvidence, CheckStepsAdapter } from "../../components/check-steps";
30
35
  import { CHANT_EXIT } from "../../exit-codes";
31
36
  import { formatError } from "../format";
@@ -49,7 +54,7 @@ async function lexiconCheckSteps(ctx: CommandContext, cwd: string): Promise<Chec
49
54
  return plugins.map((p) => p.checkSteps?.()).filter((a): a is CheckStepsAdapter => a !== undefined);
50
55
  }
51
56
 
52
- const USAGE = "chant ci check --base <rev> [<target>...] [--output <dir>] [--summary <file>] [--no-push] [--json]";
57
+ const USAGE = "chant ci check [--base <rev>] [--branch <default branch>] [<target>...] [--output <dir>] [--summary <file>] [--no-push] [--json]";
53
58
 
54
59
  /**
55
60
  * The check stage's signer (#4870), when the job has a runner identity: a
@@ -91,10 +96,17 @@ async function localEvidenceAt(base: string): Promise<{ base: string } | undefin
91
96
  }
92
97
  }
93
98
 
94
- export async function runCiCheck(ctx: CommandContext): Promise<number> {
99
+ export async function runCiCheck(ctx: CommandContext, env: Record<string, string | undefined> = process.env): Promise<number> {
95
100
  const { args } = ctx;
96
- if (!args.base) {
97
- console.error(formatError({ message: "chant ci check needs --base <rev>, the commit the change is measured from", hint: `${USAGE}. The hooks are read at base, so a change cannot remove a required check.` }));
101
+ // #4966: with no --base, the job's own (`ciBaseRef`): a pull request's target branch, else the default branch (--branch) for a push to another branch.
102
+ const base = args.base ?? ciBaseRef(env, args.branch ? { defaultBranch: args.branch } : {});
103
+ if (!base) {
104
+ console.error(
105
+ formatError({
106
+ message: "chant ci check needs --base <rev>, the commit the change is measured from, and the job names no pull request target or default branch to take it from",
107
+ hint: `${USAGE}. The hooks are read at base, so a change cannot remove a required check.`,
108
+ }),
109
+ );
98
110
  return 1;
99
111
  }
100
112
  const targets = (args.positionals ?? []).slice(1);
@@ -102,10 +114,10 @@ export async function runCiCheck(ctx: CommandContext): Promise<number> {
102
114
  let report;
103
115
  try {
104
116
  const adapters = await lexiconCheckSteps(ctx, process.cwd());
105
- const evidence = await checkEvidenceSigner(args.base, args.noPush === true);
117
+ const evidence = await checkEvidenceSigner(base, args.noPush === true);
106
118
  // #4868: a job that signs local evidence runs every hook; any other may skip one on local evidence.
107
- const local = evidence && "class" in evidence.signer ? undefined : await localEvidenceAt(args.base);
108
- report = await runCheckStage({ base: args.base, targets, adapters, ...(args.output ? { dir: args.output } : {}), ...(evidence ? { evidence } : {}), ...(local ? { localEvidence: local } : {}) });
119
+ const local = evidence && "class" in evidence.signer ? undefined : await localEvidenceAt(base);
120
+ report = await runCheckStage({ base, targets, adapters, ...(args.output ? { dir: args.output } : {}), ...(evidence ? { evidence } : {}), ...(local ? { localEvidence: local } : {}) });
109
121
  } catch (err) {
110
122
  console.error(formatError({ message: err instanceof Error ? err.message : String(err), hint: USAGE }));
111
123
  return CHANT_EXIT.failed;