@intentius/chant 0.124.84 → 0.124.86

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 (254) hide show
  1. package/dist/bundle-check.d.ts +102 -0
  2. package/dist/bundle-check.d.ts.map +1 -0
  3. package/dist/bundle-check.js +310 -0
  4. package/dist/chant-install.d.ts +100 -0
  5. package/dist/chant-install.d.ts.map +1 -0
  6. package/dist/chant-install.js +158 -0
  7. package/dist/ci-commit.d.ts +19 -6
  8. package/dist/ci-commit.d.ts.map +1 -1
  9. package/dist/ci-commit.js +23 -4
  10. package/dist/ci-evidence-jobs.d.ts +54 -0
  11. package/dist/ci-evidence-jobs.d.ts.map +1 -0
  12. package/dist/ci-evidence-jobs.js +55 -0
  13. package/dist/ci-image.d.ts +274 -0
  14. package/dist/ci-image.d.ts.map +1 -0
  15. package/dist/ci-image.js +635 -0
  16. package/dist/ci-login.d.ts +150 -0
  17. package/dist/ci-login.d.ts.map +1 -0
  18. package/dist/ci-login.js +240 -0
  19. package/dist/ci-product.d.ts +16 -0
  20. package/dist/ci-product.d.ts.map +1 -1
  21. package/dist/ci-product.js +17 -0
  22. package/dist/cli/commands/import-index.js +2 -2
  23. package/dist/cli/handlers/build.d.ts +8 -0
  24. package/dist/cli/handlers/build.d.ts.map +1 -1
  25. package/dist/cli/handlers/build.js +22 -4
  26. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  27. package/dist/cli/handlers/ci-check.js +57 -2
  28. package/dist/cli/handlers/ci-evidence.d.ts +3 -0
  29. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
  30. package/dist/cli/handlers/ci-evidence.js +171 -0
  31. package/dist/cli/handlers/components.js +3 -3
  32. package/dist/cli/handlers/dead-guards.d.ts +3 -0
  33. package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
  34. package/dist/cli/handlers/dead-guards.js +35 -0
  35. package/dist/cli/handlers/graph.js +4 -4
  36. package/dist/cli/handlers/lifecycle.d.ts +2 -1
  37. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  38. package/dist/cli/handlers/lifecycle.js +5 -4
  39. package/dist/cli/handlers/local-chant.d.ts +16 -0
  40. package/dist/cli/handlers/local-chant.d.ts.map +1 -0
  41. package/dist/cli/handlers/local-chant.js +109 -0
  42. package/dist/cli/handlers/operator.js +2 -2
  43. package/dist/cli/handlers/search.js +5 -5
  44. package/dist/cli/main.d.ts.map +1 -1
  45. package/dist/cli/main.js +38 -0
  46. package/dist/cli/parse-args.d.ts.map +1 -1
  47. package/dist/cli/parse-args.js +28 -0
  48. package/dist/cli/registry.d.ts +16 -0
  49. package/dist/cli/registry.d.ts.map +1 -1
  50. package/dist/components/check-hooks.d.ts +49 -0
  51. package/dist/components/check-hooks.d.ts.map +1 -1
  52. package/dist/components/check-hooks.js +64 -4
  53. package/dist/components/check-steps.d.ts +17 -0
  54. package/dist/components/check-steps.d.ts.map +1 -1
  55. package/dist/components/check-steps.js +37 -5
  56. package/dist/components/product-pipeline.d.ts +23 -0
  57. package/dist/components/product-pipeline.d.ts.map +1 -1
  58. package/dist/components/product-pipeline.js +6 -2
  59. package/dist/components/product-plan.d.ts +137 -0
  60. package/dist/components/product-plan.d.ts.map +1 -0
  61. package/dist/components/product-plan.js +143 -0
  62. package/dist/components/release-compile.d.ts.map +1 -1
  63. package/dist/components/release-compile.js +2 -2
  64. package/dist/config.d.ts +39 -1
  65. package/dist/config.d.ts.map +1 -1
  66. package/dist/config.js +35 -3
  67. package/dist/dead-guards.d.ts +82 -0
  68. package/dist/dead-guards.d.ts.map +1 -0
  69. package/dist/dead-guards.js +436 -0
  70. package/dist/discovery/files.d.ts +3 -1
  71. package/dist/discovery/files.d.ts.map +1 -1
  72. package/dist/discovery/files.js +5 -3
  73. package/dist/drift-issue.d.ts +152 -0
  74. package/dist/drift-issue.d.ts.map +1 -0
  75. package/dist/drift-issue.js +167 -0
  76. package/dist/floor-table.d.ts +30 -0
  77. package/dist/floor-table.d.ts.map +1 -0
  78. package/dist/floor-table.data.d.ts +3 -0
  79. package/dist/floor-table.data.d.ts.map +1 -0
  80. package/dist/floor-table.data.js +178 -0
  81. package/dist/floor-table.js +56 -0
  82. package/dist/forge-flags.d.ts +90 -0
  83. package/dist/forge-flags.d.ts.map +1 -0
  84. package/dist/forge-flags.js +184 -0
  85. package/dist/lexicon.d.ts +69 -0
  86. package/dist/lexicon.d.ts.map +1 -1
  87. package/dist/lifecycle/gated-op.d.ts +7 -1
  88. package/dist/lifecycle/gated-op.d.ts.map +1 -1
  89. package/dist/lifecycle/gated-op.js +7 -4
  90. package/dist/local-chant.d.ts +98 -0
  91. package/dist/local-chant.d.ts.map +1 -0
  92. package/dist/local-chant.js +307 -0
  93. package/dist/op/activities/predict-behaviour.js +2 -2
  94. package/dist/op/op-waves-evidence-spec.d.ts +13 -0
  95. package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
  96. package/dist/op/op-waves-evidence-spec.js +21 -0
  97. package/dist/op/op-waves-evidence.d.ts +38 -0
  98. package/dist/op/op-waves-evidence.d.ts.map +1 -0
  99. package/dist/op/op-waves-evidence.js +57 -0
  100. package/dist/op/op-waves-run.d.ts +4 -0
  101. package/dist/op/op-waves-run.d.ts.map +1 -1
  102. package/dist/op/op-waves-run.js +24 -1
  103. package/dist/op/op-waves.d.ts +17 -1
  104. package/dist/op/op-waves.d.ts.map +1 -1
  105. package/dist/op/op-waves.js +23 -0
  106. package/dist/op/schedule-overdue.d.ts +41 -9
  107. package/dist/op/schedule-overdue.d.ts.map +1 -1
  108. package/dist/op/schedule-overdue.js +154 -25
  109. package/dist/plan-summary.d.ts +25 -0
  110. package/dist/plan-summary.d.ts.map +1 -1
  111. package/dist/plan-summary.js +31 -0
  112. package/dist/pr-plan-note.d.ts +35 -0
  113. package/dist/pr-plan-note.d.ts.map +1 -1
  114. package/dist/pr-plan-note.js +10 -0
  115. package/dist/pr-post.d.ts +23 -0
  116. package/dist/pr-post.d.ts.map +1 -1
  117. package/dist/pr-post.js +125 -3
  118. package/dist/release-floors.d.ts +31 -1
  119. package/dist/release-floors.d.ts.map +1 -1
  120. package/dist/release-floors.js +31 -1
  121. package/dist/state-migration.d.ts +24 -0
  122. package/dist/state-migration.d.ts.map +1 -1
  123. package/dist/state-migration.js +100 -5
  124. package/dist/wave-runtime.mjs +305 -298
  125. package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
  126. package/dist/workspace/lexicon-outputs.js +21 -7
  127. package/dist/workspace/reason-codes.d.ts +3 -0
  128. package/dist/workspace/reason-codes.d.ts.map +1 -1
  129. package/dist/workspace/reason-codes.js +4 -0
  130. package/dist/workspace/ref-gate.schema.json +85 -0
  131. package/dist/workspace/search-contract.d.ts +1 -1
  132. package/dist/workspace/search-contract.d.ts.map +1 -1
  133. package/dist/workspace/trust/check-evidence-report.d.ts +51 -0
  134. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
  135. package/dist/workspace/trust/check-evidence-report.js +102 -0
  136. package/dist/workspace/trust/check-evidence.d.ts +126 -0
  137. package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
  138. package/dist/workspace/trust/check-evidence.js +237 -0
  139. package/dist/workspace/trust/local-evidence.d.ts +120 -0
  140. package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
  141. package/dist/workspace/trust/local-evidence.js +259 -0
  142. package/dist/workspace/trust/policy.d.ts +84 -0
  143. package/dist/workspace/trust/policy.d.ts.map +1 -1
  144. package/dist/workspace/trust/policy.js +94 -1
  145. package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
  146. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
  147. package/dist/workspace/trust/ref-gate-cli.js +234 -0
  148. package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
  149. package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
  150. package/dist/workspace/trust/ref-gate-fixture.js +97 -0
  151. package/dist/workspace/trust/ref-gate.d.ts +187 -0
  152. package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
  153. package/dist/workspace/trust/ref-gate.js +430 -0
  154. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  155. package/dist/workspace/trust/trust-files.js +18 -1
  156. package/package.json +1 -1
  157. package/src/bundle-check.test.ts +140 -0
  158. package/src/bundle-check.ts +352 -0
  159. package/src/chant-install.test.ts +112 -0
  160. package/src/chant-install.ts +179 -0
  161. package/src/ci-commit.test.ts +45 -0
  162. package/src/ci-commit.ts +38 -4
  163. package/src/ci-evidence-jobs.ts +67 -0
  164. package/src/ci-image.test.ts +506 -0
  165. package/src/ci-image.ts +822 -0
  166. package/src/ci-login.test.ts +235 -0
  167. package/src/ci-login.ts +307 -0
  168. package/src/ci-product.ts +18 -0
  169. package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
  170. package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
  171. package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
  172. package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
  173. package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
  174. package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
  175. package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
  176. package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
  177. package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
  178. package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
  179. package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
  180. package/src/cli/commands/import-index.ts +2 -2
  181. package/src/cli/handlers/build-source-dir.test.ts +64 -0
  182. package/src/cli/handlers/build.ts +21 -4
  183. package/src/cli/handlers/ci-check.ts +56 -3
  184. package/src/cli/handlers/ci-evidence.ts +162 -0
  185. package/src/cli/handlers/components.ts +3 -3
  186. package/src/cli/handlers/dead-guards.ts +37 -0
  187. package/src/cli/handlers/graph.ts +4 -4
  188. package/src/cli/handlers/lifecycle.ts +5 -4
  189. package/src/cli/handlers/local-chant.ts +106 -0
  190. package/src/cli/handlers/operator.ts +2 -2
  191. package/src/cli/handlers/search.ts +5 -5
  192. package/src/cli/main.test.ts +7 -0
  193. package/src/cli/main.ts +38 -0
  194. package/src/cli/parse-args.ts +21 -0
  195. package/src/cli/registry.ts +16 -0
  196. package/src/components/check-evidence-stage.test.ts +80 -0
  197. package/src/components/check-hooks.ts +84 -4
  198. package/src/components/check-local-evidence-stage.test.ts +141 -0
  199. package/src/components/check-steps.ts +56 -6
  200. package/src/components/product-pipeline.ts +28 -3
  201. package/src/components/product-plan.test.ts +87 -0
  202. package/src/components/product-plan.ts +226 -0
  203. package/src/components/release-compile.ts +2 -2
  204. package/src/config.ts +44 -3
  205. package/src/dead-guards.test.ts +206 -0
  206. package/src/dead-guards.ts +446 -0
  207. package/src/discovery/files.ts +5 -3
  208. package/src/drift-issue-bundle.test.ts +31 -0
  209. package/src/drift-issue.test.ts +206 -0
  210. package/src/drift-issue.ts +274 -0
  211. package/src/fit-note.test.ts +44 -0
  212. package/src/floor-table.data.ts +180 -0
  213. package/src/floor-table.ts +77 -0
  214. package/src/forge-flags.test.ts +110 -0
  215. package/src/forge-flags.ts +208 -0
  216. package/src/gate-decision-bundle.test.ts +1 -0
  217. package/src/lexicon.ts +68 -0
  218. package/src/lifecycle/gated-op.ts +10 -5
  219. package/src/local-chant.e2e.test.ts +94 -0
  220. package/src/local-chant.test.ts +162 -0
  221. package/src/local-chant.ts +341 -0
  222. package/src/op/activities/predict-behaviour.ts +2 -2
  223. package/src/op/op-waves-evidence-spec.ts +24 -0
  224. package/src/op/op-waves-evidence.test.ts +130 -0
  225. package/src/op/op-waves-evidence.ts +57 -0
  226. package/src/op/op-waves-run.ts +25 -1
  227. package/src/op/op-waves.ts +31 -1
  228. package/src/op/schedule-overdue.test.ts +85 -0
  229. package/src/op/schedule-overdue.ts +162 -26
  230. package/src/plan-summary.ts +40 -0
  231. package/src/pr-plan-note.ts +34 -0
  232. package/src/pr-post-plan-note.test.ts +146 -0
  233. package/src/pr-post.ts +127 -3
  234. package/src/release-floors.ts +44 -1
  235. package/src/stage-hooks-bundle.test.ts +1 -0
  236. package/src/state-migration.test.ts +52 -1
  237. package/src/state-migration.ts +107 -5
  238. package/src/workspace/lexicon-outputs.ts +23 -6
  239. package/src/workspace/reason-codes.test.ts +3 -0
  240. package/src/workspace/reason-codes.ts +4 -0
  241. package/src/workspace/ref-gate.schema.json +85 -0
  242. package/src/workspace/trust/check-evidence-report.ts +106 -0
  243. package/src/workspace/trust/check-evidence.test.ts +133 -0
  244. package/src/workspace/trust/check-evidence.ts +257 -0
  245. package/src/workspace/trust/local-evidence.test.ts +127 -0
  246. package/src/workspace/trust/local-evidence.ts +266 -0
  247. package/src/workspace/trust/policy.ts +134 -1
  248. package/src/workspace/trust/ref-gate-cli.ts +244 -0
  249. package/src/workspace/trust/ref-gate-fixture.ts +125 -0
  250. package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
  251. package/src/workspace/trust/ref-gate.test.ts +247 -0
  252. package/src/workspace/trust/ref-gate.ts +538 -0
  253. package/src/workspace/trust/trust-files.test.ts +16 -0
  254. package/src/workspace/trust/trust-files.ts +41 -1
@@ -17,11 +17,14 @@
17
17
  * read at base so a change cannot drop a required check; a step is part of
18
18
  * the lexicon, so there is nothing for a change to remove.
19
19
  */
20
+ import { execFileSync } from "node:child_process";
20
21
  import { writeFileSync } from "node:fs";
21
22
  import { join, relative, resolve } from "node:path";
22
23
  import { readDeclaration } from "../workspace/declaration";
23
24
  import { locateWorkspace } from "../workspace/which-chant";
24
- import { CHECK_HOOKS_DIR, CHECK_HOOKS_REPORT_FILE, checkHookEnv, runCheckHooks, type CheckHooksReport, type RunCheckHooksOptions } from "./check-hooks";
25
+ import { recordChecks, signChecks, type EvidenceSigner } from "../workspace/trust/check-evidence";
26
+ import { recordLocalChecks, signLocalChecks, type LocalEvidenceSigner } from "../workspace/trust/local-evidence";
27
+ import { CHECK_HOOKS_DIR, CHECK_HOOKS_REPORT_FILE, checkHookEnv, passedCheckHooks, runCheckHooks, type CheckHooksReport, type RunCheckHooksOptions } from "./check-hooks";
25
28
 
26
29
  /** A workspace member a lexicon's check steps run for. */
27
30
  export interface CheckStageMember {
@@ -136,11 +139,13 @@ function failedLine(steps: CheckStepOutcome[]): string | undefined {
136
139
  * both under `dir` and returns it; `status` is `none` only when no hook is
137
140
  * declared and no step ran.
138
141
  */
139
- export async function runCheckStage(options: RunCheckHooksOptions & { adapters: readonly CheckStepsAdapter[]; members?: CheckStageMember[] }): Promise<CheckHooksReport> {
142
+ export async function runCheckStage(
143
+ options: RunCheckHooksOptions & { adapters: readonly CheckStepsAdapter[]; members?: CheckStageMember[]; evidence?: CheckStageEvidence },
144
+ ): Promise<CheckHooksReport> {
140
145
  const cwd = options.cwd ?? process.cwd();
141
146
  const log = options.log ?? ((line: string) => console.error(line));
142
147
  const hooks = runCheckHooks(options);
143
- if (hooks.status === "failed" || options.adapters.length === 0) return hooks;
148
+ if (hooks.status === "failed" || options.adapters.length === 0) return signHooks(options, cwd, log, hooks);
144
149
  const steps = await runCheckSteps({
145
150
  adapters: options.adapters,
146
151
  ...(options.members ? { members: options.members } : {}),
@@ -149,10 +154,55 @@ export async function runCheckStage(options: RunCheckHooksOptions & { adapters:
149
154
  env: { ...checkHookEnv(), ...options.env },
150
155
  log,
151
156
  });
152
- if (steps.length === 0) return hooks;
157
+ if (steps.length === 0) return signHooks(options, cwd, log, hooks);
153
158
  const failed = failedLine(steps);
154
159
  const report: CheckHooksReport = { ...hooks, status: failed ? "failed" : "passed", steps, ...(failed ? { failed } : {}) };
160
+ return signHooks(options, cwd, log, report);
161
+ }
162
+
163
+ /**
164
+ * Who signs the check stage's evidence (#4870), and where: the stage signs
165
+ * each hook that passed as a named check over `at` (default the checkout's
166
+ * `HEAD`) and attaches it under `refs/notes/chant/evidence`. Absent, nothing is signed and
167
+ * the report is as before. A {@link LocalEvidenceSigner} (#4868, a developer's or an agent's
168
+ * key) signs local evidence instead, under `refs/notes/chant/local-evidence`.
169
+ */
170
+ export interface CheckStageEvidence {
171
+ signer: EvidenceSigner | LocalEvidenceSigner;
172
+ /** The commit the checks ran at. Default `HEAD`. */
173
+ at?: string;
174
+ /** Push the ledger once signed. Default true. */
175
+ push?: boolean;
176
+ }
177
+
178
+ function isLocalSigner(signer: EvidenceSigner): signer is LocalEvidenceSigner {
179
+ return "class" in signer;
180
+ }
181
+
182
+ /**
183
+ * Sign each passed hook's evidence when the stage has a signer (#4870), and write the report.
184
+ * A local signer (#4868) signs local evidence, kept under `refs/notes/chant/local-evidence`.
185
+ */
186
+ async function signHooks(options: { dir?: string; evidence?: CheckStageEvidence }, cwd: string, log: (line: string) => void, report: CheckHooksReport): Promise<CheckHooksReport> {
155
187
  const dir = relative(cwd, resolve(cwd, options.dir ?? CHECK_HOOKS_DIR)) || ".";
156
- writeFileSync(join(cwd, dir, CHECK_HOOKS_REPORT_FILE), JSON.stringify(report, null, 2) + "\n");
157
- return report;
188
+ const passed = passedCheckHooks(report.hooks);
189
+ let out = report;
190
+ if (options.evidence && passed.length > 0) {
191
+ const repo = gitTopOf(cwd);
192
+ const signer = options.evidence.signer;
193
+ const at = options.evidence.at ?? "HEAD";
194
+ const wanted = passed.map((h) => ({ check: h.check, claim: JSON.stringify(h.runs) }));
195
+ const signed = isLocalSigner(signer) ? signLocalChecks(repo, at, wanted, signer) : signChecks(repo, at, wanted, signer);
196
+ const push = { push: options.evidence.push !== false };
197
+ const pushed = isLocalSigner(signer) ? await recordLocalChecks(repo, signed, push) : await recordChecks(repo, signed, push);
198
+ for (const s of signed) log(`ci check: signed ${isLocalSigner(signer) ? "local " : ""}evidence for ${s.check} at ${s.commit.slice(0, 12)} as ${s.runner}`);
199
+ if (options.evidence.push !== false && !pushed.pushed && pushed.pushWarning) log(`ci check: the evidence is attached here, and the push did not land: ${pushed.pushWarning}`);
200
+ out = { ...report, evidence: { signed: signed.map((s) => s.check), runner: signed[0]!.runner, commit: signed[0]!.commit, ...(pushed.pushWarning && options.evidence.push !== false ? { pushWarning: pushed.pushWarning } : {}) } };
201
+ }
202
+ writeFileSync(join(cwd, dir, CHECK_HOOKS_REPORT_FILE), JSON.stringify(out, null, 2) + "\n");
203
+ return out;
204
+ }
205
+
206
+ function gitTopOf(cwd: string): string {
207
+ return execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
158
208
  }
@@ -41,6 +41,8 @@ import type { CiRunner } from "../ci-jobs";
41
41
  import { resolveAgentSpec, type OpAgentSpec } from "../ci-agent";
42
42
  import { resolveCommitSpec, type OpCommitSpec } from "../ci-commit";
43
43
  import type { CiResponses } from "../ci-respond";
44
+ import { planEvidenceOf, productPlanJobs, type ProductPlanJob, type ProductPlanOptions } from "./product-plan";
45
+ import type { PipelineEvidence } from "../ci-evidence-jobs";
44
46
 
45
47
  /** Where the generator writes a product's waves spec, which chant reads at base (#4550). */
46
48
  export const PRODUCT_WAVES_SPEC_DIR = ".chant/op-waves";
@@ -112,6 +114,24 @@ export interface ProductPipelineOptions extends Omit<PrLoopPipelineOptions, "wor
112
114
  * pinned model. Needed with `respond.description: "check"`.
113
115
  */
114
116
  decide?: { backend: string; model: string };
117
+ /**
118
+ * The product's own plan verb in place of `chant components pr-plan`
119
+ * (#4799, the 2026-11-09 amendment of #4550 ruling A: "pr-plan or the
120
+ * product's plan verb"): one plan job per target, each with only that
121
+ * target's variables and secrets, and a plan-note job that posts the
122
+ * `PrReport` or plan note hand-off the verb wrote ({@link ProductPlanOptions}).
123
+ * The jobs come back as {@link ProductPipelineJobs.productPlan}, and the
124
+ * forge lexicons' `generateProductPlanPipeline` renders them. Absent: the
125
+ * plan job runs `pr-plan`, as before.
126
+ */
127
+ productPlan?: ProductPlanOptions;
128
+ /**
129
+ * The pipeline's runner identity (#4870): the secret holding the runner
130
+ * key `.chant/trust.json` lists. The product plan's jobs then sign the
131
+ * plan job's `plan` and `policy` checks ({@link ProductPlanJob.evidence}).
132
+ * Absent: nothing is signed, and the jobs are as before.
133
+ */
134
+ evidence?: PipelineEvidence;
115
135
  }
116
136
 
117
137
  /** The jobs of one product pipeline. */
@@ -127,7 +147,7 @@ export interface ProductPipelineJobs {
127
147
  * `chant/lifecycle` that sets `CHANT_CONTROL_DIR`, so the note marks the
128
148
  * cross-stack edges.
129
149
  */
130
- post: { command: string; env: Record<string, string>; control?: ControlNoteCheckout; runner?: CiRunner };
150
+ post: { command: string; env: Record<string, string>; control?: ControlNoteCheckout; runner?: CiRunner; evidence?: ProductPlanJob["evidence"] };
131
151
  /** The record job, when no waves apply on merge. */
132
152
  record?: PrLoopJob;
133
153
  /** The apply before merge, answering the apply comment, with `applyBeforeMerge`. */
@@ -179,6 +199,8 @@ export interface ProductPipelineJobs {
179
199
  * Forgejo lexicons render the same job.
180
200
  */
181
201
  action?: PrActionJob & { runner?: CiRunner };
202
+ /** The product plan's jobs (#4799), with `productPlan`: a plan job and a plan-note job per target. */
203
+ productPlan?: ProductPlanJob[];
182
204
  }
183
205
 
184
206
  /** An agent's settings as a product passes them (#4616): {@link OpAgentSpec} without the trigger, which the pipeline names. */
@@ -281,7 +303,7 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
281
303
  const built: CiProductApplyMode = options.waves || options.componentWaves ? "on-merge" : options.applyBeforeMerge ? "before-merge" : "release";
282
304
  const applyMode: CiProductApplyMode = options.words.applyMode === "before-merge" && options.applyBeforeMerge ? "before-merge" : built;
283
305
  const words = assertProductWords({ ...options.words, applyMode }, { jobs });
284
- const { waves: given, wavesSpecFile, member, agent: _agent, commits: _commits, actions: _actions, componentWaves, ...loop } = options;
306
+ const { waves: given, wavesSpecFile, member, agent: _agent, commits: _commits, actions: _actions, componentWaves, productPlan, evidence, ...loop } = options;
285
307
  const { respond } = options;
286
308
  // #4629: the pull request loop puts the responses on the apply and note jobs, as `chant build --pr-loop --respond` does.
287
309
  const prLoop: PrLoopPipelineOptions = { ...loop, words, gate: options.gate ?? words.prGate };
@@ -300,9 +322,12 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
300
322
  const out: ProductPipelineJobs = {
301
323
  words,
302
324
  plan: plan!,
303
- post: { ...post, ...(controlTarget ? { control: controlNoteCheckout(forge, controlTarget, words) } : {}), ...defaultRunner },
325
+ // #4870: the note job signs the plan job's plan and policy checks before it posts.
326
+ post: { ...post, ...(controlTarget ? { control: controlNoteCheckout(forge, controlTarget, words) } : {}), ...defaultRunner, ...(evidence ? { evidence: planEvidenceOf(forge, evidence, words, plan!.jobName) } : {}) },
304
327
  comments,
305
328
  ...(options.applyBeforeMerge ? { applyBeforeMerge: apply! } : {}),
329
+ // #4799: the product's plan verb, a plan job and a note job per target.
330
+ ...(productPlan ? { productPlan: productPlanJobs(forge, env, { ...prLoop, plan: productPlan }, words, evidence) } : {}),
306
331
  };
307
332
  const locks = prCommentLockJobs(forge, { locks: options.locks, words });
308
333
  if (locks.length > 0) out.locks = locks.map((job) => ({ ...job, ...defaultRunner }));
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The product plan (#4799): a product's plan verb in place of `pr-plan`,
3
+ * with a plan job and a note job per target, each holding only its target's
4
+ * values.
5
+ */
6
+ import { describe, expect, test } from "vitest";
7
+ import { productPipelineJobs } from "./product-pipeline";
8
+ import { PR_PLAN_NOTE_WORDS_ENV } from "./product-plan";
9
+ import { TERRAGUCCI, TERRAGUCCI_NOTE, YODEL } from "../__fixtures__/product-words";
10
+ import type { CiProductCommand } from "../ci-product-words";
11
+
12
+ const yodel = { ...YODEL, commands: {} as Record<string, CiProductCommand> };
13
+ const terragucci = { ...TERRAGUCCI, commands: { plan: "plan" as const }, aliases: [] };
14
+
15
+ const environments = {
16
+ command: "yodel plan {target} --pr-note {output}",
17
+ targets: [
18
+ { name: "staging", secrets: { PG_READER_URL: "STAGING_PG_READER_URL" }, writeProbe: "yodel config check staging --write-probe" },
19
+ { name: "prod", secrets: { PG_READER_URL: "PROD_PG_READER_URL" }, variables: { YODEL_REQUIRES: "staging" } },
20
+ ],
21
+ };
22
+
23
+ describe("the product plan (#4799)", () => {
24
+ test("without productPlan the jobs carry none, as before", () => {
25
+ expect(productPipelineJobs("github", "default", { words: terragucci })).not.toHaveProperty("productPlan");
26
+ });
27
+
28
+ test.each(["github", "forgejo", "gitlab"] as const)("on %s, one plan job and one note job per target, each with only its own target's values", (forge) => {
29
+ const [staging, prod] = productPipelineJobs(forge, "default", { words: yodel, productPlan: environments }).productPlan!;
30
+ const gitlab = forge === "gitlab";
31
+ expect(staging!.jobName).toBe(gitlab ? "staging-plan" : "plan-staging");
32
+ expect(staging!.noteJobName).toBe(gitlab ? "staging-plan-note" : "plan-note-staging");
33
+ expect(staging!.command).toBe("yodel plan staging --pr-note .chant/pr");
34
+ expect(staging!.writeProbe).toBe("yodel config check staging --write-probe");
35
+ expect(prod!.command).toBe("yodel plan prod --pr-note .chant/pr");
36
+ expect(Object.keys(staging!.env).sort()).toEqual(["BASE_SHA", "PG_READER_URL", "PR_NUMBER"]);
37
+ expect(Object.keys(prod!.env).sort()).toEqual(["BASE_SHA", "PG_READER_URL", "PR_NUMBER", "YODEL_REQUIRES"]);
38
+ expect(staging!.env.PG_READER_URL).toBe(gitlab ? "$STAGING_PG_READER_URL" : "${{ secrets.STAGING_PG_READER_URL }}");
39
+ expect(prod!.env.PG_READER_URL).toBe(gitlab ? "$PROD_PG_READER_URL" : "${{ secrets.PROD_PG_READER_URL }}");
40
+ // The note posts for the target, through the product's bin.
41
+ expect(staging!.post.command).toContain("yodel chant components pr-post");
42
+ expect(staging!.post.command).toContain("--member staging");
43
+ if (!gitlab) expect(staging!.post.env.PLAN_RESULT).toBe("${{ needs.plan-staging.result }}");
44
+ expect(staging!.artifact).toBe("chant-pr-plan-staging");
45
+ // No forge token in a plan step.
46
+ for (const p of [staging!, prod!]) expect(Object.keys(p.env).filter((k) => /TOKEN/.test(k))).toEqual([]);
47
+ });
48
+
49
+ test("without targets, one plan job named as the pull request loop's, and the note words reach the note job", () => {
50
+ const [plan] = productPipelineJobs("github", "default", { words: terragucci, productPlan: { command: "terragucci plan --pr-note {output}", noteWords: TERRAGUCCI_NOTE, artifact: "terragucci-report" } }).productPlan!;
51
+ expect(plan).toMatchObject({ jobName: "plan", noteJobName: "plan-note", command: "terragucci plan --pr-note .chant/pr", artifact: "terragucci-report" });
52
+ expect(plan!.post.command).not.toContain("--member");
53
+ expect(JSON.parse(plan!.post.env[PR_PLAN_NOTE_WORDS_ENV]!)).toEqual(TERRAGUCCI_NOTE);
54
+ });
55
+
56
+ test("the pipeline's passed values reach every target, and a name both give is refused", () => {
57
+ const [staging] = productPipelineJobs("github", "default", { words: yodel, variables: { YODEL_LOG: "info" }, productPlan: environments }).productPlan!;
58
+ expect(staging!.env.YODEL_LOG).toBe("info");
59
+ expect(() => productPipelineJobs("github", "default", { words: yodel, secrets: { PG_READER_URL: "X" }, productPlan: environments })).toThrow(/target staging's PG_READER_URL is the pipeline's too/);
60
+ });
61
+
62
+ test.each([
63
+ ["a target name that is not one", { targets: [{ name: "a b" }] }, /not a name/],
64
+ ["a target named twice", { targets: [{ name: "prod" }, { name: "prod" }] }, /names target prod twice/],
65
+ ["no targets", { targets: [] }, /targets are empty/],
66
+ ["a forge token on a target", { targets: [{ name: "prod", variables: { GITHUB_TOKEN: "x" } }] }, /GITHUB_TOKEN is one the jobs set or drop/],
67
+ ])("refuses %s", (_what, plan, error) => {
68
+ expect(() => productPipelineJobs("github", "default", { words: yodel, productPlan: { command: "yodel plan {target}", ...plan } })).toThrow(error);
69
+ });
70
+
71
+ test.each([
72
+ ["previewComment", { previewComment: true }],
73
+ ["staleNotes", { staleNotes: true }],
74
+ ["applyBeforeMerge", { applyBeforeMerge: true }],
75
+ ["build", { build: true }],
76
+ ])("refuses %s, which the product plan does not carry", (key, extra) => {
77
+ const words = key === "previewComment" ? { ...yodel, commands: { plan: "plan" as const } } : key === "applyBeforeMerge" ? { ...yodel, commands: { apply: "apply" as const } } : yodel;
78
+ expect(() => productPipelineJobs("github", "default", { words, ...extra, productPlan: { command: "yodel plan {target}" } })).toThrow(new RegExp(`takes no ${key}`));
79
+ });
80
+ });
81
+
82
+ test("PRODUCT_PLAN_FLOOR marks the product plan in the ci-product entry", async () => {
83
+ const { NEXT_RELEASE } = await import("../release-floors");
84
+ const ciProduct = (await import("../ci-product")) as Record<string, unknown>;
85
+ expect(ciProduct.PRODUCT_PLAN_FLOOR).toBe(NEXT_RELEASE);
86
+ expect(typeof ciProduct.planNoteHandoff).toBe("function");
87
+ });
@@ -0,0 +1,226 @@
1
+ /**
2
+ * The product plan (#4799): the pull request plan jobs of a product whose
3
+ * plan step runs its own plan verb, in place of `chant components pr-plan`.
4
+ *
5
+ * #4550 ruling A put the plan side of a product's pipeline on the pull
6
+ * request loop. The 2026-11-09 amendment (#4799) reads it as "pr-plan or the
7
+ * product's plan verb": sql-yodeler plans an environment with `yodel plan`
8
+ * and terragucci its roots with `terragucci plan`, and neither has a
9
+ * component graph for `pr-plan` to plan. Each keeps its plan verb, and chant
10
+ * writes the jobs around it, as it does for `pr-plan`:
11
+ *
12
+ * - the plan job checks the change out with the token given to its fetches
13
+ * alone, starts every later step without the forge tokens (#4295), and
14
+ * runs the plan verb last, which writes a `PrReport` (`pr-plan.json`) or
15
+ * a product's plan note hand-off (`pr-plan-note.json`, ../pr-plan-note.ts)
16
+ * into {@link PR_LOOP_REPORT_DIR}. The job hands the directory on.
17
+ * - the plan-note job checks out the target branch's commit, takes the
18
+ * directory back, keeps it as the run's artifact, and posts the note and
19
+ * the plan status with `chant components pr-post` (../pr-post.ts), which
20
+ * renders either file. On GitLab it is the target-branch job `pr-post
21
+ * --open`, as for `pr-plan` (#4328).
22
+ *
23
+ * With `targets`, one plan job and one plan-note job per target (an
24
+ * environment, for sql-yodeler) in the one workflow, each with only that
25
+ * target's own variables and secrets, and an optional write probe before the
26
+ * plan. A target is the note's and the status's member: `pr-post --member
27
+ * <target>`, so each target has its note and its `<product>/plan/<target>`.
28
+ *
29
+ * The forge lexicons render these descriptors
30
+ * (`generateProductPlanPipeline` in each): the products call them in
31
+ * process, with no component graph.
32
+ */
33
+
34
+ import type { ForgeKind } from "../pr-forge";
35
+ import type { CiRunner } from "../ci-jobs";
36
+ import type { CiProductWords } from "../ci-product-words";
37
+ import type { PrPlanNoteWords } from "../pr-plan-note";
38
+ import { assertPipelineEvidence, evidenceKeyEnv, 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";
40
+
41
+ /** The variable the plan-note job reads the product's note words from (#4799), as JSON. Set from the pipeline, never from the report. */
42
+ export const PR_PLAN_NOTE_WORDS_ENV = "CHANT_PLAN_NOTE_WORDS";
43
+
44
+ /** One target the product plans in a job of its own (#4799): an environment, for sql-yodeler. */
45
+ export interface ProductPlanTarget {
46
+ /** The target's name: `{target}` in the command, the job names, and the note's member. Letters, digits, `-` and `_`. */
47
+ name: string;
48
+ /** Variables for this target's plan job alone, as the forge reads them. A forge token's name is refused. */
49
+ variables?: Record<string, string>;
50
+ /** Secrets for this target's plan job alone, as `{ <variable>: <secret> }`, mapped as the pull request loop's `secrets` are. */
51
+ secrets?: Record<string, string>;
52
+ /**
53
+ * A shell line run before the plan that fails the job when the target's
54
+ * credentials can write, such as sql-yodeler's `yodel config check <env>
55
+ * --write-probe`. It runs with the target's variables, after the forge
56
+ * tokens are dropped.
57
+ */
58
+ writeProbe?: string;
59
+ }
60
+
61
+ /** The product plan (#4799): {@link ProductPipelineOptions.plan}. */
62
+ export interface ProductPlanOptions {
63
+ /**
64
+ * The product's plan verb, as one shell line: `{target}` is the target's
65
+ * name and `{output}` the directory the plan-note job takes back
66
+ * ({@link PR_LOOP_REPORT_DIR}). It reads `$BASE_SHA` and `$PR_NUMBER`, and
67
+ * writes `pr-plan.json` or `pr-plan-note.json` there. It runs as given,
68
+ * not through the words' `bin`: it is the product's command, not chant's.
69
+ */
70
+ command: string;
71
+ /** One plan job per target. Absent: one plan job, named as the pull request loop's. */
72
+ targets?: ProductPlanTarget[];
73
+ /**
74
+ * `skip`: a pull request from a fork runs no plan and no note job (on
75
+ * GitHub and Forgejo it carries no token and no OIDC; on GitLab, a fork's
76
+ * merge request pipeline runs in the fork). The product's check job,
77
+ * which holds no credentials, still runs for it. Default: every pull
78
+ * request plans.
79
+ */
80
+ forks?: "skip";
81
+ /** The artifact the plan-note job keeps the directory as. Default `chant-pr-plan`, or `chant-pr-plan-<target>`. */
82
+ artifact?: string;
83
+ /** The words a plan note hand-off renders with (`renderPlanNote`'s `note`), passed to the note job as {@link PR_PLAN_NOTE_WORDS_ENV}. */
84
+ noteWords?: PrPlanNoteWords;
85
+ /** The workflow's name (GitHub and Forgejo) or the pipeline's (GitLab). Default `chant-pr-<env>`. */
86
+ workflow?: string;
87
+ }
88
+
89
+ /** One plan job and its note job, for one target or for the whole pipeline (#4799). */
90
+ export interface ProductPlanJob {
91
+ /** The target, when the plan has targets. Also the note's and the status's member. */
92
+ target?: string;
93
+ /** The plan job: `plan` or `plan-<target>` on GitHub and Forgejo, `plan` or `<target>-plan` on GitLab, where `pr-post --open` finds it by that name. */
94
+ jobName: string;
95
+ /** The note job: `plan-note` or `plan-note-<target>`, `<target>-plan-note` on GitLab. */
96
+ noteJobName: string;
97
+ /** The plan verb's line, `{target}` and `{output}` filled. */
98
+ command: string;
99
+ /** The plan step's variables: `BASE_SHA`, `PR_NUMBER`, the pipeline's passed variables and secrets, then the target's. No forge token. */
100
+ env: Record<string, string>;
101
+ /** The target's write probe. */
102
+ writeProbe?: string;
103
+ /** The note job's command and variables. */
104
+ post: { command: string; env: Record<string, string> };
105
+ /** The artifact the note job (GitHub, Forgejo) or the plan job (GitLab) keeps the directory as. */
106
+ artifact: string;
107
+ /** Where the plan job runs: the loop's `plan` runner. */
108
+ runner?: CiRunner;
109
+ /** Where the note job runs: the loop's `default` runner. */
110
+ noteRunner?: CiRunner;
111
+ /**
112
+ * With the pipeline's `evidence` (#4870): the lines that sign the plan
113
+ * job's `plan` and `policy` checks from its report, and their variables
114
+ * (the runner key from its secret). GitHub and Forgejo run them in the
115
+ * note job before `pr-post`; GitLab in a job of their own after the plan
116
+ * job, `evidenceJobName`.
117
+ */
118
+ evidence?: { lines: string[]; env: Record<string, string>; jobName?: string };
119
+ }
120
+
121
+ const TARGET_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
122
+
123
+ /** The pull request loop's options the product plan's jobs do not carry, and what each needs. Each is refused with `plan` (#4799). */
124
+ const NOT_WITH_PLAN: ReadonlyArray<[keyof PrLoopPipelineOptions, string]> = [
125
+ ["applyBeforeMerge", "the apply before merge runs pr-apply on pr-plan's report"],
126
+ ["applyOnMerge", "the apply on merge runs on op waves, from the waves spec"],
127
+ ["waveGate", "the apply on merge runs on op waves, from the waves spec"],
128
+ ["locks", "the lock job reads pr-plan's report"],
129
+ ["previewComment", "the comment preview re-runs pr-plan"],
130
+ ["staleNotes", "the stale marking names one note per pipeline"],
131
+ ["identity", "a target's cloud login is the product's, through its variables"],
132
+ ["build", "the plan verb builds what it plans"],
133
+ ["buildCommand", "the plan verb builds what it plans"],
134
+ ["refresh", "--refresh is a pr-plan flag"],
135
+ ["parallelism", "--parallelism is a pr-plan flag"],
136
+ ["commentTargets", "--comment-targets is a pr-plan flag"],
137
+ ["events", "--events-json is a pr-plan flag"],
138
+ ["reportUrl", "--report-url is a pr-plan flag"],
139
+ ["prEnvironment", "the pull request environment jobs run pr-env"],
140
+ ["noteCommands", "the note-commands job starts pr-plan's comment jobs"],
141
+ ["actionJob", "the action job is in chant build --pr-loop's workflow"],
142
+ ["control", "the control read is the pr-plan report's cross-stack edges"],
143
+ ["decide", "the description check reads pr-plan's report"],
144
+ ];
145
+
146
+ /**
147
+ * The product plan's jobs for `forge` (#4799). `words` are the pipeline's,
148
+ * already checked. Throws on a target name that is not one, a name given
149
+ * twice, a target variable that is a forge token, and a pull request loop
150
+ * option the product plan does not carry.
151
+ */
152
+ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipelineOptions & { plan: ProductPlanOptions }, words: CiProductWords, evidence?: PipelineEvidence): ProductPlanJob[] {
153
+ const plan = loop.plan;
154
+ for (const [key, why] of NOT_WITH_PLAN) {
155
+ const value = loop[key];
156
+ if (value !== undefined && value !== false) throw new Error(`the product plan (plan) takes no ${key}: ${why}`);
157
+ }
158
+ if (!plan.command.trim()) throw new Error("the product plan's command is empty; give the product's plan verb");
159
+ const targets = plan.targets;
160
+ if (targets !== undefined && targets.length === 0) throw new Error("the product plan's targets are empty; leave targets out for one plan job");
161
+ const seen = new Set<string>();
162
+ for (const t of targets ?? []) {
163
+ if (!TARGET_NAME.test(t.name)) throw new Error(`the product plan's target ${JSON.stringify(t.name)} is not a name of letters, digits, - and _`);
164
+ if (seen.has(t.name)) throw new Error(`the product plan names target ${t.name} twice`);
165
+ seen.add(t.name);
166
+ }
167
+ const github = forge !== "gitlab";
168
+ const shared = prLoopPassedEnv(forge, loop);
169
+ const planRunner = prLoopRunner(loop, "plan");
170
+ const noteRunner = prLoopRunner(loop, "default");
171
+ const base = github
172
+ ? { BASE_SHA: "${{ github.event.pull_request.base.sha }}", PR_NUMBER: "${{ github.event.pull_request.number }}" }
173
+ : { BASE_SHA: "$CI_MERGE_REQUEST_DIFF_BASE_SHA", PR_NUMBER: "$CI_MERGE_REQUEST_IID" };
174
+ const noteWords: Record<string, string> = plan.noteWords ? { [PR_PLAN_NOTE_WORDS_ENV]: JSON.stringify(plan.noteWords) } : {};
175
+ const one = (target?: ProductPlanTarget): ProductPlanJob => {
176
+ const name = target?.name;
177
+ const jobName = github ? (name ? `plan-${name}` : "plan") : gitlabPlanJobName(name);
178
+ const noteJobName = github ? (name ? `${PR_PLAN_NOTE_JOB}-${name}` : PR_PLAN_NOTE_JOB) : name ? `${name}-${PR_PLAN_NOTE_JOB}` : PR_PLAN_NOTE_JOB;
179
+ const own = target ? prLoopPassedEnv(forge, { ...(target.variables ? { variables: target.variables } : {}), ...(target.secrets ? { secrets: target.secrets } : {}) }) : {};
180
+ for (const key of Object.keys(own)) {
181
+ 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`);
182
+ }
183
+ const post = prLoopPostJob(forge, env, name, words);
184
+ // The note job reads its own plan job's result, by that job's name.
185
+ const postEnv: Record<string, string> = github ? { ...post.env, PLAN_RESULT: `\${{ needs.${jobName}.result }}`, ...noteWords } : { ...post.env, ...noteWords };
186
+ return {
187
+ ...(name ? { target: name } : {}),
188
+ jobName,
189
+ noteJobName,
190
+ command: plan.command.replaceAll("{target}", name ?? env).replaceAll("{output}", PR_LOOP_REPORT_DIR),
191
+ env: { ...base, ...shared, ...own },
192
+ ...(target?.writeProbe ? { writeProbe: target.writeProbe } : {}),
193
+ post: { command: post.command, env: postEnv },
194
+ artifact: plan.artifact ? (name ? `${plan.artifact}-${name}` : plan.artifact) : name ? `chant-pr-plan-${name}` : "chant-pr-plan",
195
+ ...(planRunner !== undefined ? { runner: planRunner } : {}),
196
+ ...(noteRunner !== undefined ? { noteRunner } : {}),
197
+ ...(evidence ? { evidence: planEvidenceOf(forge, evidence, words, jobName) } : {}),
198
+ };
199
+ };
200
+ return targets ? targets.map(one) : [one()];
201
+ }
202
+
203
+ /** The evidence step of one plan job (#4870), as {@link ProductPlanJob.evidence}. */
204
+ export function planEvidenceOf(forge: ForgeKind, evidence: PipelineEvidence, words: CiProductWords, planJob: string): NonNullable<ProductPlanJob["evidence"]> {
205
+ assertPipelineEvidence(evidence);
206
+ const key = evidenceKeyEnv(forge, evidence);
207
+ const bin = words.bin;
208
+ if (forge === "gitlab") {
209
+ // The job runs only once the plan job succeeded, on the merge request's commit.
210
+ return {
211
+ jobName: `${planJob}-evidence`,
212
+ lines: planEvidenceLines({ dir: PR_LOOP_REPORT_DIR, at: '"$CI_COMMIT_SHA"', base: '"$CI_MERGE_REQUEST_DIFF_BASE_SHA"', result: "success", ...(bin ? { bin } : {}) }),
213
+ env: key,
214
+ };
215
+ }
216
+ return {
217
+ lines: planEvidenceLines({ dir: PR_LOOP_REPORT_DIR, at: '"$HEAD_SHA"', base: '"$BASE_SHA"', result: '"$PLAN_RESULT"', ...(bin ? { bin } : {}) }),
218
+ env: { HEAD_SHA: "${{ github.sha }}", BASE_SHA: "${{ github.event.pull_request.base.sha }}", PLAN_RESULT: `\${{ needs.${planJob}.result }}`, ...key },
219
+ };
220
+ }
221
+
222
+ /** The GitHub and Forgejo condition that a pull request is from this repository, not a fork (#4799). */
223
+ export const SAME_REPOSITORY_IF = "github.event.pull_request.head.repo.full_name == github.repository";
224
+
225
+ /** The GitLab rule condition that a merge request's source project is the project itself (#4799). */
226
+ export const GITLAB_SAME_PROJECT_IF = "$CI_MERGE_REQUEST_SOURCE_PROJECT_ID == $CI_MERGE_REQUEST_PROJECT_ID";
@@ -44,7 +44,7 @@ import { isUtf8 } from "node:buffer";
44
44
  import { existsSync, mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
45
45
  import { tmpdir } from "node:os";
46
46
  import { isAbsolute, join, relative, resolve } from "node:path";
47
- import { loadChantConfig, type ChantConfig } from "../config";
47
+ import { loadChantConfig, resolveSourceDir, type ChantConfig } from "../config";
48
48
  import { resolveFlaggedBuildParams } from "../flag-params";
49
49
  import { discoverComponents } from "./discover";
50
50
  import { withoutDisabled } from "./cli-support";
@@ -465,7 +465,7 @@ export async function compileBuildOutput(inputs: CompileInputs, env: string, con
465
465
  );
466
466
  }
467
467
  const projectDir = resolve(inputs.projectDir);
468
- const root = resolve(projectDir, inputs.src ?? config.sourceDir ?? ".");
468
+ const root = resolveSourceDir(projectDir, config, inputs.src);
469
469
  const output = resolve(projectDir, inputs.output ?? DEFAULT_BUILD_OUTPUT);
470
470
  const rel = relative(projectDir, output);
471
471
  if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) {
package/src/config.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readFileSync } from "fs";
2
- import { dirname, join } from "path";
2
+ import { dirname, join, resolve } from "path";
3
3
  import { z } from "zod";
4
4
  import type { LintConfig } from "./lint/config";
5
5
  import type { OwnershipMarker } from "./ownership";
@@ -264,6 +264,12 @@ export interface ChantConfig {
264
264
  * of the project root, so a mixed-layout project — chant `src/` alongside app
265
265
  * code that has import side effects — can scope the build to just the infra.
266
266
  * Defaults to "." (the project root). The `--src` flag overrides it.
267
+ *
268
+ * #4794: every command that picks a source directory (`chant build`, the
269
+ * release compile, `chant lifecycle`, `graph`, `search`, `components`, the
270
+ * lexicon commands) reads it through {@link resolveSourceDir}. A root build,
271
+ * one with no `sourceDir`, leaves a top-level `scripts/` directory out
272
+ * ({@link ROOT_SOURCE_EXCLUDES}) unless `include` brings it back.
267
273
  */
268
274
  sourceDir?: string;
269
275
 
@@ -727,6 +733,39 @@ export function findProjectConfigPastFragments(startDir: string): { dir: string;
727
733
  return { dir, configPath };
728
734
  }
729
735
 
736
+ /**
737
+ * The source directory a project's config names, relative to the project
738
+ * root: `sourceDir`, else "." (#4794). The relative half of
739
+ * {@link resolveSourceDir}, for a caller that names a path inside the
740
+ * project (a rollback's `git checkout -- <dir>`).
741
+ */
742
+ export function configuredSourceDir(config: { sourceDir?: unknown } | undefined): string {
743
+ return typeof config?.sourceDir === "string" && config.sourceDir !== "" ? config.sourceDir : ".";
744
+ }
745
+
746
+ /**
747
+ * The one source-dir rule (#4794): the directory a command builds a
748
+ * project's declarations from, absolute. `explicit` (a `--src` flag or a path
749
+ * argument) wins, resolved against `projectDir`; else the config's
750
+ * `sourceDir`; else the project root. There is no `src` fallback: a project
751
+ * whose declarations live in `src/` beside other code says so with
752
+ * `sourceDir: "src"`. A root build leaves out {@link ROOT_SOURCE_EXCLUDES}.
753
+ */
754
+ export function resolveSourceDir(projectDir: string, config: { sourceDir?: unknown } | undefined, explicit?: string): string {
755
+ return resolve(projectDir, explicit ?? configuredSourceDir(config));
756
+ }
757
+
758
+ /**
759
+ * The top-level directories a root build leaves out (#4794): a project with
760
+ * no `sourceDir`, built from its own root, does not load `scripts/`, where a
761
+ * script that runs on load (prints and exits) would take the build's place.
762
+ * Matched against the path relative to the project root, so only the
763
+ * project's own top-level `scripts/` is skipped. The config's `include`
764
+ * brings it back. Test and spec files are left out of every build already
765
+ * (`isSourceFileName`).
766
+ */
767
+ export const ROOT_SOURCE_EXCLUDES: readonly string[] = ["scripts"];
768
+
730
769
  /** A project's discovery globs (#2519) and the directory they are relative to. */
731
770
  export interface DiscoveryGlobs {
732
771
  /** The directory holding the config that declared the globs. */
@@ -747,7 +786,7 @@ export interface DiscoveryGlobs {
747
786
  * is in `exclude` or `include` themselves: ignoring those would discover the
748
787
  * very files the project asked to skip.
749
788
  */
750
- export async function resolveDiscoveryGlobs(startDir: string): Promise<DiscoveryGlobs | undefined> {
789
+ export async function resolveDiscoveryGlobs(startDir: string, options: { sourceWalk?: boolean } = {}): Promise<DiscoveryGlobs | undefined> {
751
790
  const { dir, configPath } = findProjectConfigPastFragments(startDir);
752
791
  if (!configPath) return undefined;
753
792
  let config: ChantConfig;
@@ -757,7 +796,9 @@ export async function resolveDiscoveryGlobs(startDir: string): Promise<Discovery
757
796
  if (err instanceof InvalidChantConfigError && (err.key === "exclude" || err.key === "include")) throw err;
758
797
  return undefined;
759
798
  }
760
- const exclude = config.exclude ?? [];
799
+ // #4794: a source walk from the root of a project with no sourceDir (a root build) leaves out ROOT_SOURCE_EXCLUDES.
800
+ const rootBuild = options.sourceWalk === true && config.sourceDir === undefined && resolve(startDir) === resolve(dir);
801
+ const exclude = [...(config.exclude ?? []), ...(rootBuild ? ROOT_SOURCE_EXCLUDES : [])];
761
802
  const include = config.include ?? [];
762
803
  if (exclude.length === 0 && include.length === 0) return undefined;
763
804
  return { root: dir, exclude, include };