@gate-forge/cli 0.7.0 → 0.8.0

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/README.md +511 -51
  2. package/dist/adapter-audit.d.ts +154 -0
  3. package/dist/adapter-audit.d.ts.map +1 -0
  4. package/dist/adapter-audit.js +531 -0
  5. package/dist/adapter-audit.js.map +1 -0
  6. package/dist/adapter-scaffold.d.ts +66 -0
  7. package/dist/adapter-scaffold.d.ts.map +1 -0
  8. package/dist/adapter-scaffold.js +353 -0
  9. package/dist/adapter-scaffold.js.map +1 -0
  10. package/dist/adopted-baseline.d.ts +10 -0
  11. package/dist/adopted-baseline.d.ts.map +1 -1
  12. package/dist/adopted-baseline.js +18 -1
  13. package/dist/adopted-baseline.js.map +1 -1
  14. package/dist/args.d.ts +15 -0
  15. package/dist/args.d.ts.map +1 -1
  16. package/dist/args.js +59 -2
  17. package/dist/args.js.map +1 -1
  18. package/dist/behavior-setup.d.ts +239 -0
  19. package/dist/behavior-setup.d.ts.map +1 -0
  20. package/dist/behavior-setup.js +738 -0
  21. package/dist/behavior-setup.js.map +1 -0
  22. package/dist/broker.d.ts.map +1 -1
  23. package/dist/broker.js +28 -2
  24. package/dist/broker.js.map +1 -1
  25. package/dist/cache-exclusions.d.ts +45 -0
  26. package/dist/cache-exclusions.d.ts.map +1 -0
  27. package/dist/cache-exclusions.js +205 -0
  28. package/dist/cache-exclusions.js.map +1 -0
  29. package/dist/candidate-tree.d.ts +86 -14
  30. package/dist/candidate-tree.d.ts.map +1 -1
  31. package/dist/candidate-tree.js +236 -62
  32. package/dist/candidate-tree.js.map +1 -1
  33. package/dist/ci-witnessed-template.d.ts +43 -0
  34. package/dist/ci-witnessed-template.d.ts.map +1 -0
  35. package/dist/ci-witnessed-template.js +283 -0
  36. package/dist/ci-witnessed-template.js.map +1 -0
  37. package/dist/cli.d.ts +1 -1
  38. package/dist/cli.d.ts.map +1 -1
  39. package/dist/cli.js +31 -4
  40. package/dist/cli.js.map +1 -1
  41. package/dist/commands/adapters.d.ts +15 -0
  42. package/dist/commands/adapters.d.ts.map +1 -0
  43. package/dist/commands/adapters.js +284 -0
  44. package/dist/commands/adapters.js.map +1 -0
  45. package/dist/commands/adopt.d.ts.map +1 -1
  46. package/dist/commands/adopt.js +9 -1
  47. package/dist/commands/adopt.js.map +1 -1
  48. package/dist/commands/baseline.d.ts.map +1 -1
  49. package/dist/commands/baseline.js +42 -1
  50. package/dist/commands/baseline.js.map +1 -1
  51. package/dist/commands/blocking.d.ts +81 -2
  52. package/dist/commands/blocking.d.ts.map +1 -1
  53. package/dist/commands/blocking.js +336 -53
  54. package/dist/commands/blocking.js.map +1 -1
  55. package/dist/commands/check.d.ts +36 -0
  56. package/dist/commands/check.d.ts.map +1 -1
  57. package/dist/commands/check.js +1008 -62
  58. package/dist/commands/check.js.map +1 -1
  59. package/dist/commands/classify.d.ts +2 -1
  60. package/dist/commands/classify.d.ts.map +1 -1
  61. package/dist/commands/classify.js +143 -5
  62. package/dist/commands/classify.js.map +1 -1
  63. package/dist/commands/enforce.d.ts +4 -4
  64. package/dist/commands/enforce.d.ts.map +1 -1
  65. package/dist/commands/enforce.js +41 -9
  66. package/dist/commands/enforce.js.map +1 -1
  67. package/dist/commands/enforcement.d.ts +13 -1
  68. package/dist/commands/enforcement.d.ts.map +1 -1
  69. package/dist/commands/enforcement.js +800 -30
  70. package/dist/commands/enforcement.js.map +1 -1
  71. package/dist/commands/history.d.ts +12 -0
  72. package/dist/commands/history.d.ts.map +1 -0
  73. package/dist/commands/history.js +45 -0
  74. package/dist/commands/history.js.map +1 -0
  75. package/dist/commands/init-presets.d.ts +148 -0
  76. package/dist/commands/init-presets.d.ts.map +1 -0
  77. package/dist/commands/init-presets.js +194 -0
  78. package/dist/commands/init-presets.js.map +1 -0
  79. package/dist/commands/init.d.ts +7 -12
  80. package/dist/commands/init.d.ts.map +1 -1
  81. package/dist/commands/init.js +610 -69
  82. package/dist/commands/init.js.map +1 -1
  83. package/dist/commands/keys.d.ts.map +1 -1
  84. package/dist/commands/keys.js +29 -13
  85. package/dist/commands/keys.js.map +1 -1
  86. package/dist/commands/next.d.ts.map +1 -1
  87. package/dist/commands/next.js +744 -15
  88. package/dist/commands/next.js.map +1 -1
  89. package/dist/commands/pre-commit.d.ts +25 -0
  90. package/dist/commands/pre-commit.d.ts.map +1 -1
  91. package/dist/commands/pre-commit.js +91 -6
  92. package/dist/commands/pre-commit.js.map +1 -1
  93. package/dist/commands/quarantine.d.ts +16 -0
  94. package/dist/commands/quarantine.d.ts.map +1 -0
  95. package/dist/commands/quarantine.js +213 -0
  96. package/dist/commands/quarantine.js.map +1 -0
  97. package/dist/commands/run.d.ts +39 -0
  98. package/dist/commands/run.d.ts.map +1 -0
  99. package/dist/commands/run.js +196 -0
  100. package/dist/commands/run.js.map +1 -0
  101. package/dist/commands/test-gates.d.ts +284 -2
  102. package/dist/commands/test-gates.d.ts.map +1 -1
  103. package/dist/commands/test-gates.js +3619 -186
  104. package/dist/commands/test-gates.js.map +1 -1
  105. package/dist/commands/tests.d.ts +1 -1
  106. package/dist/commands/tests.d.ts.map +1 -1
  107. package/dist/commands/tests.js +225 -22
  108. package/dist/commands/tests.js.map +1 -1
  109. package/dist/endpoint-compiler.d.ts.map +1 -1
  110. package/dist/endpoint-compiler.js +29 -8
  111. package/dist/endpoint-compiler.js.map +1 -1
  112. package/dist/engine-browser.d.ts +183 -0
  113. package/dist/engine-browser.d.ts.map +1 -0
  114. package/dist/engine-browser.js +381 -0
  115. package/dist/engine-browser.js.map +1 -0
  116. package/dist/engine-identity.d.ts +100 -0
  117. package/dist/engine-identity.d.ts.map +1 -0
  118. package/dist/engine-identity.js +182 -0
  119. package/dist/engine-identity.js.map +1 -0
  120. package/dist/evaluate.d.ts +89 -0
  121. package/dist/evaluate.d.ts.map +1 -1
  122. package/dist/evaluate.js +137 -16
  123. package/dist/evaluate.js.map +1 -1
  124. package/dist/execution.d.ts +253 -9
  125. package/dist/execution.d.ts.map +1 -1
  126. package/dist/execution.js +309 -12
  127. package/dist/execution.js.map +1 -1
  128. package/dist/git-hooks.d.ts +17 -0
  129. package/dist/git-hooks.d.ts.map +1 -1
  130. package/dist/git-hooks.js +119 -0
  131. package/dist/git-hooks.js.map +1 -1
  132. package/dist/git-objects.d.ts +60 -0
  133. package/dist/git-objects.d.ts.map +1 -0
  134. package/dist/git-objects.js +152 -0
  135. package/dist/git-objects.js.map +1 -0
  136. package/dist/history.d.ts +52 -0
  137. package/dist/history.d.ts.map +1 -0
  138. package/dist/history.js +116 -0
  139. package/dist/history.js.map +1 -0
  140. package/dist/host-load.d.ts +49 -0
  141. package/dist/host-load.d.ts.map +1 -0
  142. package/dist/host-load.js +78 -0
  143. package/dist/host-load.js.map +1 -0
  144. package/dist/input-snapshot.d.ts +63 -9
  145. package/dist/input-snapshot.d.ts.map +1 -1
  146. package/dist/input-snapshot.js +195 -17
  147. package/dist/input-snapshot.js.map +1 -1
  148. package/dist/io.d.ts +36 -0
  149. package/dist/io.d.ts.map +1 -1
  150. package/dist/io.js +21 -0
  151. package/dist/io.js.map +1 -1
  152. package/dist/mapping.d.ts +84 -1
  153. package/dist/mapping.d.ts.map +1 -1
  154. package/dist/mapping.js +276 -5
  155. package/dist/mapping.js.map +1 -1
  156. package/dist/native-freeze.d.ts +217 -0
  157. package/dist/native-freeze.d.ts.map +1 -0
  158. package/dist/native-freeze.js +332 -0
  159. package/dist/native-freeze.js.map +1 -0
  160. package/dist/pipeline.d.ts +52 -1
  161. package/dist/pipeline.d.ts.map +1 -1
  162. package/dist/pipeline.js +141 -3
  163. package/dist/pipeline.js.map +1 -1
  164. package/dist/playwright-browsers.d.ts +210 -0
  165. package/dist/playwright-browsers.d.ts.map +1 -0
  166. package/dist/playwright-browsers.js +364 -0
  167. package/dist/playwright-browsers.js.map +1 -0
  168. package/dist/plugins.d.ts +15 -5
  169. package/dist/plugins.d.ts.map +1 -1
  170. package/dist/plugins.js +59 -9
  171. package/dist/plugins.js.map +1 -1
  172. package/dist/progress.d.ts +148 -0
  173. package/dist/progress.d.ts.map +1 -0
  174. package/dist/progress.js +263 -0
  175. package/dist/progress.js.map +1 -0
  176. package/dist/providers.d.ts +26 -1
  177. package/dist/providers.d.ts.map +1 -1
  178. package/dist/providers.js +39 -0
  179. package/dist/providers.js.map +1 -1
  180. package/dist/receipts.d.ts +1 -0
  181. package/dist/receipts.d.ts.map +1 -1
  182. package/dist/receipts.js +35 -7
  183. package/dist/receipts.js.map +1 -1
  184. package/dist/repo-scan.d.ts +8 -1
  185. package/dist/repo-scan.d.ts.map +1 -1
  186. package/dist/repo-scan.js +221 -27
  187. package/dist/repo-scan.js.map +1 -1
  188. package/dist/reseal-chain.d.ts +184 -0
  189. package/dist/reseal-chain.d.ts.map +1 -0
  190. package/dist/reseal-chain.js +735 -0
  191. package/dist/reseal-chain.js.map +1 -0
  192. package/dist/reseal-evidence.d.ts +241 -0
  193. package/dist/reseal-evidence.d.ts.map +1 -0
  194. package/dist/reseal-evidence.js +319 -0
  195. package/dist/reseal-evidence.js.map +1 -0
  196. package/dist/reseal.d.ts +181 -0
  197. package/dist/reseal.d.ts.map +1 -0
  198. package/dist/reseal.js +1620 -0
  199. package/dist/reseal.js.map +1 -0
  200. package/dist/response-field-guidance.d.ts +82 -0
  201. package/dist/response-field-guidance.d.ts.map +1 -0
  202. package/dist/response-field-guidance.js +184 -0
  203. package/dist/response-field-guidance.js.map +1 -0
  204. package/dist/run-cache.d.ts +260 -0
  205. package/dist/run-cache.d.ts.map +1 -0
  206. package/dist/run-cache.js +771 -0
  207. package/dist/run-cache.js.map +1 -0
  208. package/dist/run-preflight.d.ts +77 -0
  209. package/dist/run-preflight.d.ts.map +1 -0
  210. package/dist/run-preflight.js +774 -0
  211. package/dist/run-preflight.js.map +1 -0
  212. package/dist/run-recipe.d.ts +107 -0
  213. package/dist/run-recipe.d.ts.map +1 -0
  214. package/dist/run-recipe.js +295 -0
  215. package/dist/run-recipe.js.map +1 -0
  216. package/dist/run-reliability.d.ts +126 -0
  217. package/dist/run-reliability.d.ts.map +1 -0
  218. package/dist/run-reliability.js +221 -0
  219. package/dist/run-reliability.js.map +1 -0
  220. package/dist/runtime.d.ts +15 -0
  221. package/dist/runtime.d.ts.map +1 -1
  222. package/dist/runtime.js +11 -1
  223. package/dist/runtime.js.map +1 -1
  224. package/dist/secret-guard.d.ts +36 -0
  225. package/dist/secret-guard.d.ts.map +1 -0
  226. package/dist/secret-guard.js +63 -0
  227. package/dist/secret-guard.js.map +1 -0
  228. package/dist/singleton-guidance.d.ts +73 -0
  229. package/dist/singleton-guidance.d.ts.map +1 -0
  230. package/dist/singleton-guidance.js +118 -0
  231. package/dist/singleton-guidance.js.map +1 -0
  232. package/dist/staged-candidate.d.ts +17 -0
  233. package/dist/staged-candidate.d.ts.map +1 -1
  234. package/dist/staged-candidate.js +50 -0
  235. package/dist/staged-candidate.js.map +1 -1
  236. package/dist/state-artifacts.d.ts +70 -0
  237. package/dist/state-artifacts.d.ts.map +1 -0
  238. package/dist/state-artifacts.js +215 -0
  239. package/dist/state-artifacts.js.map +1 -0
  240. package/dist/state.d.ts +170 -2
  241. package/dist/state.d.ts.map +1 -1
  242. package/dist/state.js +248 -8
  243. package/dist/state.js.map +1 -1
  244. package/dist/verifier-keys.d.ts +33 -2
  245. package/dist/verifier-keys.d.ts.map +1 -1
  246. package/dist/verifier-keys.js +95 -9
  247. package/dist/verifier-keys.js.map +1 -1
  248. package/guides/CONNECT-YOUR-PROJECT.md +367 -0
  249. package/guides/QUICKSTART.md +404 -0
  250. package/guides/RUNNER-NEUTRAL-EVIDENCE.md +199 -0
  251. package/guides/TEST-ENVIRONMENT.md +1226 -0
  252. package/guides/UPGRADE-0.6-to-0.7.md +65 -0
  253. package/guides/UPGRADE-0.7-to-0.8.md +114 -0
  254. package/package.json +12 -10
@@ -0,0 +1,774 @@
1
+ /**
2
+ * Managed-run preconditions (managed-run plan (2026-09-29), Part B, feedback E56).
3
+ *
4
+ * `gateforge doctor` gained a `run` section: every precondition a
5
+ * witnessed local run depends on, as ONE deterministic read-only line
6
+ * with the exact fix command. The section adds no authority — it runs
7
+ * no suite, starts no service and changes no file. Its default posture
8
+ * is report-only (the doctor's exit behavior is unchanged); with
9
+ * `--strict-preflight` the first FAIL ends the command with exit 1, so
10
+ * `gateforge run` never spends fifty minutes discovering a missing
11
+ * interpreter.
12
+ *
13
+ * Honesty rules (ADR 0005 D1, unchanged from the enforcement doctor):
14
+ * a precondition is `ok` only when it was actually observed; anything
15
+ * Gateforge cannot observe is `warn`, never `ok`; a broken boundary is
16
+ * `fail` with the command that repairs it. Checks are returned in
17
+ * DECLARED order — the order a run consumes them in — so "the first
18
+ * FAIL" is deterministic.
19
+ */
20
+ import { spawnSync } from 'node:child_process';
21
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
22
+ import { dirname, join, relative, resolve } from 'node:path';
23
+ import { policyWeakenedCandidate } from '@gate-forge/core';
24
+ import { findPlaywrightConfig } from '@gate-forge/pack-playwright';
25
+ import { loadConfigAt } from './commands/common.js';
26
+ import { trustedPolicyDigestForConfig } from './execution.js';
27
+ import { browserBuildSummary, browserLaunchSummary, inspectBrowserBuilds, unlaunchableBuilds } from './playwright-browsers.js';
28
+ import { resolveVerifierKeyring } from './verifier-keys.js';
29
+ import { engineBrowserRequirement, engineBrowserSummary, inspectEngineBrowserBuilds, resolveEngineBrowserInstall, } from './engine-browser.js';
30
+ import { describeApprovedPolicyResolution, resolveApprovedPolicyDigest } from './trusted-policy.js';
31
+ import { resolveStateDir } from './state.js';
32
+ import { sampleHostLoad } from './host-load.js';
33
+ import { loadRunRecipe, runRecipeStep } from './run-recipe.js';
34
+ /** Load average above this multiple of the CPU count is a warning. */
35
+ const LOAD_WARNING_FACTOR = 1.5;
36
+ /** Free disk below this percentage is a warning. */
37
+ const FREE_DISK_WARNING_PERCENT = 5;
38
+ /** Default milliseconds for a reachability probe. */
39
+ const DEFAULT_PROBE_TIMEOUT_MS = 3_000;
40
+ /** Milliseconds allowed for a runner/interpreter `--version` probe. */
41
+ const VERSION_PROBE_TIMEOUT_MS = 5_000;
42
+ /** Maximum bytecode cache directories named in one diagnostic. */
43
+ const MAX_NAMED_CACHES = 5;
44
+ /** Maximum directory depth of the bytecode-cache scan. */
45
+ const MAX_SCAN_DEPTH = 8;
46
+ /**
47
+ * Runs a process with a hard deadline and returns its trimmed output.
48
+ *
49
+ * Args:
50
+ * file: executable to run.
51
+ * args: arguments for the executable.
52
+ * cwd: working directory.
53
+ * env: environment for the child.
54
+ * timeoutMs: wall-clock budget in milliseconds.
55
+ *
56
+ * Returns:
57
+ * { code, output }: exit code (124 on timeout, 127 when it could not
58
+ * start) and the last 400 characters of combined output.
59
+ */
60
+ function probeProcess(file, args, cwd, env, timeoutMs) {
61
+ const result = spawnSync(file, [...args], {
62
+ cwd,
63
+ env,
64
+ encoding: 'utf8',
65
+ timeout: timeoutMs,
66
+ maxBuffer: 4 * 1024 * 1024,
67
+ });
68
+ if (result.error !== undefined)
69
+ return { code: 127, output: result.error.message };
70
+ const output = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim();
71
+ if (result.status === null)
72
+ return { code: 124, output: `did not finish within ${String(timeoutMs)}ms` };
73
+ return { code: result.status, output: output.slice(-400) };
74
+ }
75
+ /**
76
+ * Resolves an executable that may be a path or a bare name looked up on
77
+ * PATH (argv[0] of a configured suite is either).
78
+ *
79
+ * Args:
80
+ * name: executable as declared.
81
+ * cwd: repository root a relative path resolves against.
82
+ * env: environment whose PATH is searched.
83
+ *
84
+ * Returns:
85
+ * string | null: absolute path of the executable, or null.
86
+ */
87
+ function resolveExecutable(name, cwd, env) {
88
+ if (name.includes('/') || name.includes('\\')) {
89
+ const absolute = resolve(cwd, name);
90
+ try {
91
+ if (statSync(absolute).isFile())
92
+ return absolute;
93
+ }
94
+ catch {
95
+ return null;
96
+ }
97
+ return null;
98
+ }
99
+ for (const directory of (env['PATH'] ?? '').split(':')) {
100
+ if (directory.length === 0)
101
+ continue;
102
+ const candidate = join(directory, name);
103
+ try {
104
+ if (statSync(candidate).isFile())
105
+ return candidate;
106
+ }
107
+ catch {
108
+ // Unreadable PATH entries are skipped, exactly like execvp.
109
+ }
110
+ }
111
+ return null;
112
+ }
113
+ /**
114
+ * Reports the verifier key ring a witnessed run needs: an active key
115
+ * that resolves OUTSIDE the repository and the run-state directory.
116
+ *
117
+ * Args:
118
+ * cwd: repository root.
119
+ * env: operator environment (key source variables).
120
+ *
121
+ * Returns:
122
+ * RunCheck: the verifier-key precondition line.
123
+ */
124
+ function verifierKeyCheck(cwd, env) {
125
+ try {
126
+ const keyring = resolveVerifierKeyring(cwd, env, [resolveStateDir(cwd)]);
127
+ if (keyring === null) {
128
+ return {
129
+ id: 'verifier-key',
130
+ status: 'fail',
131
+ detail: 'no external verifier key is configured, so a witnessed run cannot seal a verifying receipt; ' +
132
+ 'fix: gateforge key create --confirm',
133
+ };
134
+ }
135
+ return {
136
+ id: 'verifier-key',
137
+ status: 'ok',
138
+ detail: `active verifier key '${keyring.active.keyId}' resolves outside the repository (key material is never printed)`,
139
+ };
140
+ }
141
+ catch (error) {
142
+ return {
143
+ id: 'verifier-key',
144
+ status: 'fail',
145
+ detail: `verifier key could not be resolved: ${error.message.split('\n')[0] ?? 'unknown'}; fix: gateforge key create --confirm`,
146
+ };
147
+ }
148
+ }
149
+ /**
150
+ * Reports whether an owner-approved policy revision is provisioned from
151
+ * a trusted channel and whether it matches this candidate.
152
+ *
153
+ * Args:
154
+ * cwd: repository root.
155
+ * config: loaded repository config (never an approval source).
156
+ * env: operator environment (protected pin variable).
157
+ *
158
+ * Returns:
159
+ * RunCheck: the approved-policy precondition line.
160
+ */
161
+ function approvedPolicyCheck(cwd, config, env) {
162
+ const resolution = resolveApprovedPolicyDigest({ env, candidateCwd: cwd, candidateConfig: config });
163
+ if (resolution.status !== 'ok') {
164
+ return {
165
+ id: 'approved-policy',
166
+ status: 'fail',
167
+ detail: `${describeApprovedPolicyResolution(resolution)}; fix: provision GATEFORGE_APPROVED_POLICY_DIGEST outside the candidate`,
168
+ };
169
+ }
170
+ if (resolution.digest === null) {
171
+ return {
172
+ id: 'approved-policy',
173
+ status: 'warn',
174
+ detail: `${describeApprovedPolicyResolution(resolution)}; a witnessed run still works, but nothing binds the ` +
175
+ 'policy revision — fix: export GATEFORGE_APPROVED_POLICY_DIGEST=<digest>',
176
+ };
177
+ }
178
+ try {
179
+ const candidateDigest = trustedPolicyDigestForConfig(cwd, config);
180
+ if (policyWeakenedCandidate(resolution.digest, candidateDigest).weakened) {
181
+ return {
182
+ id: 'approved-policy',
183
+ status: 'fail',
184
+ detail: `approved policy digest ${resolution.digest.slice(0, 12)}… does not match this candidate's policy ` +
185
+ `revision ${candidateDigest.slice(0, 12)}…; strict runs block with ENFORCEMENT_UNTRUSTED — ` +
186
+ 'fix: re-pin GATEFORGE_APPROVED_POLICY_DIGEST from the trusted revision',
187
+ };
188
+ }
189
+ return {
190
+ id: 'approved-policy',
191
+ status: 'ok',
192
+ detail: `${describeApprovedPolicyResolution(resolution)} — matches this candidate policy revision`,
193
+ };
194
+ }
195
+ catch (error) {
196
+ return {
197
+ id: 'approved-policy',
198
+ status: 'fail',
199
+ detail: `trusted policy digest could not be computed: ${error.message.split('\n')[0] ?? 'unknown'}`,
200
+ };
201
+ }
202
+ }
203
+ /**
204
+ * Finds the installed runner package where the supervised run resolves
205
+ * it: for Playwright, from the directory of the config enumeration runs
206
+ * (a sub-project like `e2e/` owns its own install), then from the
207
+ * repository root; each start walks up like Node resolution.
208
+ *
209
+ * Args:
210
+ * cwd: repository root.
211
+ * runner: the configured runner.
212
+ * packageNames: package names to accept, in preference order.
213
+ *
214
+ * Returns:
215
+ * string | null: the absolute path of the first `package.json` found.
216
+ */
217
+ export function findRunnerManifest(cwd, runner, packageNames) {
218
+ const starts = [];
219
+ if (runner === 'playwright') {
220
+ const playwrightConfig = findPlaywrightConfig(cwd);
221
+ if (playwrightConfig !== null)
222
+ starts.push(dirname(join(cwd, playwrightConfig)));
223
+ }
224
+ starts.push(resolve(cwd));
225
+ for (const start of starts) {
226
+ let cursor = start;
227
+ for (let depth = 0; depth < 6; depth += 1) {
228
+ for (const packageName of packageNames) {
229
+ const candidate = join(cursor, 'node_modules', packageName, 'package.json');
230
+ if (existsSync(candidate))
231
+ return candidate;
232
+ }
233
+ const parent = resolve(cursor, '..');
234
+ if (parent === cursor)
235
+ break;
236
+ cursor = parent;
237
+ }
238
+ }
239
+ return null;
240
+ }
241
+ /**
242
+ * Reports whether the configured runner's BINARY resolves and reports a
243
+ * version. The enforcement doctor's `runner` line answers a different
244
+ * question (is the runner configured and installed); this one answers
245
+ * "can this exact executable be launched, and which version is it".
246
+ *
247
+ * Args:
248
+ * cwd: repository root.
249
+ * config: loaded repository config.
250
+ * env: operator environment (PATH).
251
+ *
252
+ * Returns:
253
+ * RunCheck: the runner precondition line.
254
+ */
255
+ function runnerCheck(cwd, config, env) {
256
+ if (config.runner === 'pytest') {
257
+ const suites = config.diagnostics?.suites ?? [];
258
+ if (suites.length === 0) {
259
+ return {
260
+ id: 'runner',
261
+ status: 'warn',
262
+ detail: 'pytest is the configured runner but no diagnostics suite is configured; fix: declare diagnostics.suites in .gateforge.yml',
263
+ };
264
+ }
265
+ for (const suite of suites) {
266
+ const declared = suite.argv[0] ?? '';
267
+ const resolved = resolveExecutable(declared, cwd, env);
268
+ const probe = probeProcess(resolved ?? declared, ['--version'], cwd, env, VERSION_PROBE_TIMEOUT_MS);
269
+ if (resolved === null || probe.code !== 0) {
270
+ return {
271
+ id: 'runner',
272
+ status: 'fail',
273
+ detail: `pytest suite '${suite.name}' runs '${declared}', which does not run (${resolved === null ? 'not found' : `exit ${String(probe.code)}`}); ` +
274
+ `fix: point diagnostics.suites argv[0] at an installed interpreter or pytest (e.g. a venv's bin/pytest)`,
275
+ };
276
+ }
277
+ }
278
+ const versions = suites.map((suite) => {
279
+ const probe = probeProcess(resolveExecutable(suite.argv[0] ?? '', cwd, env) ?? '', ['--version'], cwd, env, VERSION_PROBE_TIMEOUT_MS);
280
+ return probe.output.split('\n')[0] ?? 'version unknown';
281
+ });
282
+ return {
283
+ id: 'runner',
284
+ status: 'ok',
285
+ detail: `pytest suite(s) ${suites.map((suite) => suite.name).join(', ')} resolve and run: ${versions.join('; ')}`,
286
+ };
287
+ }
288
+ const manifest = findRunnerManifest(cwd, config.runner, config.runner === 'playwright' ? ['@playwright/test', 'playwright'] : [config.runner]);
289
+ if (manifest === null) {
290
+ const packageName = config.runner;
291
+ return {
292
+ id: 'runner',
293
+ status: 'fail',
294
+ detail: `${config.runner} is the configured runner but ${packageName} is not installed; fix: npm install --save-dev ${packageName}`,
295
+ };
296
+ }
297
+ let version = 'unknown';
298
+ try {
299
+ const parsed = JSON.parse(readFileSync(manifest, 'utf8'));
300
+ if (typeof parsed.version === 'string')
301
+ version = parsed.version;
302
+ }
303
+ catch {
304
+ // A readable-but-unparsable manifest stays 'ok' with an unknown version.
305
+ }
306
+ // A resolvable binary is not a launchable browser: the resolved
307
+ // runner pins its own browser revisions, and a cache holding another
308
+ // release's builds fails every test with "Executable doesn't exist".
309
+ if (config.runner === 'playwright') {
310
+ const readiness = inspectBrowserBuilds(manifest, playwrightConfigText(cwd), env);
311
+ const configPath = findPlaywrightConfig(cwd);
312
+ const installCwd = configPath === null ? cwd : dirname(join(cwd, configPath));
313
+ if (readiness.missing.length > 0) {
314
+ return {
315
+ id: 'runner',
316
+ status: 'fail',
317
+ detail: `${config.runner} resolves at '${manifest}' (version ${version}), but ` +
318
+ browserBuildSummary(readiness, installCwd),
319
+ };
320
+ }
321
+ // Installed is not startable: the same loader failure the doctor
322
+ // reports stops the run here, BEFORE the suite spends its hours
323
+ // failing every test for a reason the operator was never told.
324
+ const launch = browserLaunchSummary(unlaunchableBuilds(readiness), installCwd);
325
+ if (launch !== '') {
326
+ return {
327
+ id: 'runner',
328
+ status: 'fail',
329
+ detail: `${config.runner} resolves at '${manifest}' (version ${version}), but ${launch}`,
330
+ };
331
+ }
332
+ }
333
+ return {
334
+ id: 'runner',
335
+ status: 'ok',
336
+ detail: `${config.runner} resolves at '${manifest}' (version ${version}); the supervised run can execute it`,
337
+ };
338
+ }
339
+ /**
340
+ * The engine-owned browser precondition, for repositories that declare
341
+ * engine-controlled browser evidence.
342
+ *
343
+ * It is a SEPARATE line from `runner` because the two answer different
344
+ * questions and routinely disagree: `runner` reports the browser the
345
+ * CONSUMER's tests launch, this one the browser the ENGINE drives
346
+ * through `EngineBrowserManager`. A consumer on `@playwright/test`
347
+ * 1.62.1 with Chromium 1234 installed makes `runner` say `ok` while the
348
+ * pack's own pinned 1.58.2 wants 1208 — and the run then dies inside the
349
+ * witness with `Executable doesn't exist`. This line refuses that run
350
+ * first and names the engine's OWN install command, because
351
+ * `npx playwright install` resolves the consumer's release and installs
352
+ * the revision the cache already holds.
353
+ *
354
+ * A Playwright runner conservatively requires the engine browser. Other
355
+ * runners require it only for an explicit `engine-browser` behavior case.
356
+ *
357
+ * Args:
358
+ * cwd: repository root.
359
+ * config: loaded repository config.
360
+ * env: operator environment (`PLAYWRIGHT_BROWSERS_PATH`).
361
+ *
362
+ * Returns:
363
+ * RunCheck: the engine-owned browser precondition line.
364
+ */
365
+ function engineBrowserCheck(cwd, config, env) {
366
+ const requirement = engineBrowserRequirement(cwd, config.runner, config.behaviorPolicy);
367
+ if (!requirement.required) {
368
+ return { id: 'engine-browser', status: 'ok', detail: `engine browser not required — ${requirement.reason}` };
369
+ }
370
+ const resolution = resolveEngineBrowserInstall(cwd);
371
+ if (resolution.kind === 'not-installed') {
372
+ return {
373
+ id: 'engine-browser',
374
+ status: 'warn',
375
+ detail: `${requirement.reason}, but @gate-forge/pack-playwright is not installed under this repository — ` +
376
+ 'the engine browser could not be inspected',
377
+ };
378
+ }
379
+ if (resolution.kind === 'no-pinned-playwright') {
380
+ return {
381
+ id: 'engine-browser',
382
+ status: 'warn',
383
+ detail: `${requirement.reason}, but the installed @gate-forge/pack-playwright resolves no readable pinned ` +
384
+ 'playwright release — the engine browser could not be inspected',
385
+ };
386
+ }
387
+ const readiness = inspectEngineBrowserBuilds(resolution.install, env);
388
+ const summary = engineBrowserSummary(readiness);
389
+ if (readiness.missing.length > 0 || readiness.unlaunchable.length > 0) {
390
+ return { id: 'engine-browser', status: 'fail', detail: summary };
391
+ }
392
+ return { id: 'engine-browser', status: 'ok', detail: summary };
393
+ }
394
+ /**
395
+ * The resolved Playwright config's source ('' when the repository has
396
+ * none): the config names the browsers its projects launch.
397
+ *
398
+ * Args:
399
+ * cwd: repository root.
400
+ *
401
+ * Returns:
402
+ * string: the config text, or '' when there is no readable config.
403
+ */
404
+ function playwrightConfigText(cwd) {
405
+ const config = findPlaywrightConfig(cwd);
406
+ if (config === null)
407
+ return '';
408
+ try {
409
+ return readFileSync(join(cwd, config), 'utf8');
410
+ }
411
+ catch {
412
+ return '';
413
+ }
414
+ }
415
+ /**
416
+ * Reports the configured interpreter paths of a python-backed run: the
417
+ * argv[0] of every configured suite must exist AND run. A wrong path is
418
+ * the single most expensive local mistake, so it is a hard FAIL.
419
+ *
420
+ * Args:
421
+ * cwd: repository root.
422
+ * config: loaded repository config.
423
+ * env: operator environment (PATH).
424
+ *
425
+ * Returns:
426
+ * RunCheck: the interpreter precondition line.
427
+ */
428
+ function interpreterCheck(cwd, config, env) {
429
+ if (config.runner !== 'pytest') {
430
+ return {
431
+ id: 'interpreter',
432
+ status: 'ok',
433
+ detail: `not applicable: the configured runner '${config.runner}' uses no python interpreter`,
434
+ };
435
+ }
436
+ const suites = config.diagnostics?.suites ?? [];
437
+ if (suites.length === 0) {
438
+ return { id: 'interpreter', status: 'warn', detail: 'no interpreter configured (no diagnostics.suites in .gateforge.yml)' };
439
+ }
440
+ const failures = [];
441
+ const resolved = [];
442
+ for (const suite of suites) {
443
+ const declared = suite.argv[0] ?? '';
444
+ const absolute = resolveExecutable(declared, cwd, env);
445
+ if (absolute === null) {
446
+ failures.push(`'${declared}' (suite '${suite.name}') does not exist`);
447
+ continue;
448
+ }
449
+ const probe = probeProcess(absolute, ['--version'], cwd, env, VERSION_PROBE_TIMEOUT_MS);
450
+ if (probe.code !== 0) {
451
+ failures.push(`'${absolute}' (suite '${suite.name}') does not run (exit ${String(probe.code)})`);
452
+ continue;
453
+ }
454
+ resolved.push(`${absolute} (${probe.output.split('\n')[0] ?? 'version unknown'})`);
455
+ }
456
+ if (failures.length > 0) {
457
+ return {
458
+ id: 'interpreter',
459
+ status: 'fail',
460
+ detail: `configured interpreter path(s) unusable: ${failures.join('; ')}; fix: correct diagnostics.suites argv[0] in .gateforge.yml (e.g. .venv/bin/python)`,
461
+ };
462
+ }
463
+ return { id: 'interpreter', status: 'ok', detail: `configured interpreter(s) run: ${resolved.join('; ')}` };
464
+ }
465
+ /**
466
+ * Lists bytecode cache directories in the candidate tree (bounded scan).
467
+ *
468
+ * Args:
469
+ * cwd: repository root.
470
+ *
471
+ * Returns:
472
+ * string[]: repository-relative paths of the `__pycache__` directories.
473
+ */
474
+ function findBytecodeCaches(cwd) {
475
+ const found = [];
476
+ const walk = (directory, depth) => {
477
+ if (found.length >= MAX_NAMED_CACHES || depth > MAX_SCAN_DEPTH)
478
+ return;
479
+ let entries;
480
+ try {
481
+ entries = readdirSync(directory, { withFileTypes: true });
482
+ }
483
+ catch {
484
+ return;
485
+ }
486
+ for (const entry of entries) {
487
+ if (found.length >= MAX_NAMED_CACHES)
488
+ return;
489
+ if (!entry.isDirectory() || entry.isSymbolicLink())
490
+ continue;
491
+ if (entry.name === 'node_modules' || entry.name === '.git')
492
+ continue;
493
+ const child = join(directory, entry.name);
494
+ if (entry.name === '__pycache__')
495
+ found.push(relative(cwd, child));
496
+ else
497
+ walk(child, depth + 1);
498
+ }
499
+ };
500
+ walk(cwd, 0);
501
+ return found.sort();
502
+ }
503
+ /**
504
+ * Reports whether the run can write bytecode into the candidate tree.
505
+ * Python bytecode caches are candidate bytes: a suite that rewrites
506
+ * `__pycache__` mid-run voids its own receipt, so the run is only
507
+ * bytecode-safe with the environment guard or a pre-compiled tree.
508
+ *
509
+ * Args:
510
+ * cwd: repository root.
511
+ * config: loaded repository config.
512
+ * env: operator environment.
513
+ *
514
+ * Returns:
515
+ * RunCheck: the bytecode-safety precondition line.
516
+ */
517
+ function bytecodeSafetyCheck(cwd, config, env) {
518
+ if (config.runner !== 'pytest') {
519
+ return {
520
+ id: 'bytecode-safety',
521
+ status: 'ok',
522
+ detail: `not applicable: the configured runner '${config.runner}' writes no python bytecode`,
523
+ };
524
+ }
525
+ const guard = env['PYTHONDONTWRITEBYTECODE'];
526
+ if (guard !== undefined && guard !== '' && guard !== '0') {
527
+ return {
528
+ id: 'bytecode-safety',
529
+ status: 'ok',
530
+ detail: `PYTHONDONTWRITEBYTECODE=${guard}: the run writes no bytecode into the candidate tree`,
531
+ };
532
+ }
533
+ const caches = findBytecodeCaches(cwd);
534
+ if (caches.length === 0) {
535
+ return {
536
+ id: 'bytecode-safety',
537
+ status: 'warn',
538
+ detail: 'PYTHONDONTWRITEBYTECODE is not set: a python import during the run would write __pycache__ bytes into the ' +
539
+ 'candidate tree and void the receipt; fix: PYTHONDONTWRITEBYTECODE=1 gateforge run (or pre-compile the tree)',
540
+ };
541
+ }
542
+ return {
543
+ id: 'bytecode-safety',
544
+ status: 'fail',
545
+ detail: `PYTHONDONTWRITEBYTECODE is not set and the candidate tree already holds bytecode caches (${caches.join(', ')}): ` +
546
+ 'a run can rewrite those bytes and void its own receipt; fix: PYTHONDONTWRITEBYTECODE=1 gateforge run, or ' +
547
+ 'remove the caches and pre-compile them outside the run',
548
+ };
549
+ }
550
+ /**
551
+ * Probes the attested target the run will exercise, but only when a
552
+ * base URL is configured: without one there is nothing to probe and
553
+ * Gateforge never invents a target.
554
+ *
555
+ * Args:
556
+ * url: base URL from the flag or the environment.
557
+ * timeoutMs: probe deadline.
558
+ *
559
+ * Returns:
560
+ * Promise<RunCheck>: the target precondition line.
561
+ */
562
+ async function targetCheck(url, timeoutMs) {
563
+ const started = Date.now();
564
+ // The probe runs in THIS process (no child, no shell): a reachability
565
+ // check must not depend on what a spawned process is allowed to do.
566
+ let reachable = false;
567
+ let note = '';
568
+ try {
569
+ const response = await fetch(url, { redirect: 'manual', signal: AbortSignal.timeout(timeoutMs) });
570
+ reachable = response.status < 500;
571
+ if (!reachable)
572
+ note = ` (HTTP ${String(response.status)})`;
573
+ }
574
+ catch (error) {
575
+ note = ` (${error.message.split('\n')[0] ?? 'unreachable'})`;
576
+ }
577
+ if (reachable) {
578
+ return { id: 'target', status: 'ok', detail: `target '${url}' is reachable (${String(Date.now() - started)}ms)` };
579
+ }
580
+ return {
581
+ id: 'target',
582
+ status: 'fail',
583
+ detail: `target '${url}' is not reachable${note}; the run would test nothing — ` +
584
+ 'fix: start the app (recipe services_up) and export GATEFORGE_TARGET_BASE_URL to its base URL',
585
+ };
586
+ }
587
+ /**
588
+ * Reports whether the recipe's own readiness probe passes, when a
589
+ * recipe exists. Without a recipe there is nothing Gateforge started,
590
+ * so the line is honest about managing nothing.
591
+ *
592
+ * Args:
593
+ * cwd: repository root.
594
+ * env: operator environment.
595
+ * recipe: loaded recipe, or null when the repository declares none.
596
+ * timeoutMs: probe deadline for the recipe's own budget.
597
+ *
598
+ * Returns:
599
+ * Promise<RunCheck>: the app-healthcheck precondition line.
600
+ */
601
+ async function appHealthcheckCheck(cwd, env, recipe, timeoutMs) {
602
+ if (recipe === null || recipe.healthcheck === null) {
603
+ return {
604
+ id: 'app-healthcheck',
605
+ status: 'ok',
606
+ detail: 'no recipe healthcheck declared (no .gateforge/runtime.yml lifecycle): gateforge run starts nothing',
607
+ };
608
+ }
609
+ const outcome = await runRecipeStep(recipe.healthcheck, cwd, env, { timeoutMs, log: () => undefined });
610
+ if (outcome.code === 0) {
611
+ return { id: 'app-healthcheck', status: 'ok', detail: 'recipe healthcheck passed' };
612
+ }
613
+ return {
614
+ id: 'app-healthcheck',
615
+ status: 'fail',
616
+ detail: `recipe healthcheck failed (exit ${String(outcome.code)}); fix: make the app healthy, or declare the healthcheck in .gateforge/runtime.yml`,
617
+ };
618
+ }
619
+ /**
620
+ * Reports machine load as an ADVISORY only: a busy host explains flaky
621
+ * failures, it never invalidates a proof.
622
+ *
623
+ * Args:
624
+ * cwd: repository root (selects the filesystem the run writes to).
625
+ *
626
+ * Returns:
627
+ * RunCheck: the host-load advisory line.
628
+ */
629
+ function hostLoadCheck(cwd) {
630
+ const sample = sampleHostLoad(cwd);
631
+ const load = sample.loadAverage[0] ?? 0;
632
+ const notes = [];
633
+ let status = 'ok';
634
+ if (load > sample.cpuCount * LOAD_WARNING_FACTOR) {
635
+ status = 'warn';
636
+ notes.push(`load ${load.toFixed(1)} on ${String(sample.cpuCount)} CPUs (advisory: slow or flaky-looking runs are likelier)`);
637
+ }
638
+ if (sample.freeDiskPercent < FREE_DISK_WARNING_PERCENT) {
639
+ status = 'warn';
640
+ notes.push(`free disk space is ${sample.freeDiskPercent.toFixed(1)}% (advisory)`);
641
+ }
642
+ return {
643
+ id: 'host-load',
644
+ status,
645
+ detail: notes.length === 0
646
+ ? `load ${load.toFixed(1)} on ${String(sample.cpuCount)} CPUs, ${sample.freeDiskPercent.toFixed(1)}% disk free (advisory only)`
647
+ : `${notes.join('; ')} — advisory only, it never fails a run`,
648
+ };
649
+ }
650
+ /**
651
+ * Reports whether the candidate tree can be hashed at all, and whether
652
+ * the working tree is clean enough for a run whose receipt binds those
653
+ * exact bytes.
654
+ *
655
+ * Args:
656
+ * cwd: repository root.
657
+ * env: Git environment.
658
+ *
659
+ * Returns:
660
+ * RunCheck: the candidate-tree precondition line.
661
+ */
662
+ function candidateTreeCheck(cwd, env) {
663
+ const inventory = spawnSync('git', ['ls-files', '--stage', '-z'], { cwd, env, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
664
+ if (inventory.error !== undefined || inventory.status !== 0) {
665
+ return {
666
+ id: 'candidate-tree',
667
+ status: 'fail',
668
+ detail: 'no usable Git inventory: the candidate tree cannot be hashed, so no receipt can be sealed; ' +
669
+ 'fix: run inside a Git repository with a valid index',
670
+ };
671
+ }
672
+ const status = spawnSync('git', ['status', '--porcelain'], { cwd, env, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
673
+ if (status.error !== undefined || status.status !== 0) {
674
+ return { id: 'candidate-tree', status: 'ok', detail: 'candidate tree is computable (git inventory available; working-tree state unknown)' };
675
+ }
676
+ const dirty = (status.stdout ?? '').split('\n').filter((line) => line.trim().length > 0);
677
+ if (dirty.length === 0) {
678
+ return { id: 'candidate-tree', status: 'ok', detail: 'candidate tree is computable and the working tree is clean' };
679
+ }
680
+ return {
681
+ id: 'candidate-tree',
682
+ status: 'warn',
683
+ detail: `candidate tree is computable but the working tree has ${String(dirty.length)} uncommitted change(s); the run seals ` +
684
+ 'a receipt for the bytes on disk — fix: commit or stash them (git status --short) before the run',
685
+ };
686
+ }
687
+ /**
688
+ * Builds the whole `run` preflight section, in the order a managed run
689
+ * consumes the preconditions. Every check is read-only.
690
+ *
691
+ * Args:
692
+ * io: process context (cwd + operator environment).
693
+ * options: optional base URL override and probe deadline.
694
+ *
695
+ * Returns:
696
+ * Promise<RunPreflightReport>: deterministic precondition section.
697
+ */
698
+ export async function buildRunPreflight(io, options = {}) {
699
+ const cwd = io.cwd;
700
+ const env = io.env;
701
+ const probeTimeoutMs = options.probeTimeoutMs ?? DEFAULT_PROBE_TIMEOUT_MS;
702
+ let config = null;
703
+ let recipe = null;
704
+ let loadError = null;
705
+ try {
706
+ config = loadConfigAt(cwd);
707
+ }
708
+ catch (error) {
709
+ loadError = error.message.split('\n')[0] ?? 'unknown';
710
+ }
711
+ if (config !== null) {
712
+ try {
713
+ recipe = loadRunRecipe(cwd, config);
714
+ }
715
+ catch (error) {
716
+ // A broken recipe is a precondition failure, never a crash: the
717
+ // healthcheck line names it and the rest of the section still runs.
718
+ loadError = error.message.split('\n')[0] ?? 'unknown';
719
+ recipe = null;
720
+ }
721
+ }
722
+ const skipped = (id, what) => ({
723
+ id,
724
+ status: 'fail',
725
+ detail: `${what} not checked: ${loadError ?? '.gateforge.yml could not be loaded'}`,
726
+ });
727
+ const checks = [];
728
+ if (config === null) {
729
+ checks.push({
730
+ id: 'config',
731
+ status: 'fail',
732
+ detail: `.gateforge.yml could not be loaded: ${loadError ?? 'unknown'}; fix: run gateforge init in this repository`,
733
+ });
734
+ }
735
+ checks.push(verifierKeyCheck(cwd, env));
736
+ checks.push(config === null ? skipped('approved-policy', 'approved policy digest') : approvedPolicyCheck(cwd, config, env));
737
+ checks.push(config === null ? skipped('runner', 'runner binary + version') : runnerCheck(cwd, config, env));
738
+ // The engine-owned browser is a SEPARATE precondition from `runner`:
739
+ // on a real install the consumer's Chromium and the engine's are
740
+ // different Playwright releases, so `runner: ok` beside a missing
741
+ // engine build is the exact false all-clear this line refuses.
742
+ checks.push(config === null ? skipped('engine-browser', 'engine-owned browser build') : engineBrowserCheck(cwd, config, env));
743
+ checks.push(config === null ? skipped('interpreter', 'configured interpreter paths') : interpreterCheck(cwd, config, env));
744
+ checks.push(config === null ? skipped('bytecode-safety', 'bytecode-safe settings') : bytecodeSafetyCheck(cwd, config, env));
745
+ const baseUrl = options.targetBaseUrl ?? env['GATEFORGE_TARGET_BASE_URL'] ?? env['GATEFORGE_APP_BASE_URL'] ?? '';
746
+ checks.push(options.externalWitness === true
747
+ ? {
748
+ id: 'target',
749
+ status: 'ok',
750
+ detail: 'not probed: the run uses an external witness (--witness-url), whose observation proxy fronts the target; ' +
751
+ 'a probe through it would count as an exchange before the run binds it, and the witness attests the target itself',
752
+ }
753
+ : baseUrl === ''
754
+ ? { id: 'target', status: 'ok', detail: 'no target base URL configured (GATEFORGE_TARGET_BASE_URL): nothing to probe; a supervised run starts its own app' }
755
+ : await targetCheck(baseUrl, probeTimeoutMs));
756
+ checks.push(await appHealthcheckCheck(cwd, env, recipe, probeTimeoutMs));
757
+ checks.push(hostLoadCheck(cwd));
758
+ checks.push(candidateTreeCheck(cwd, env));
759
+ return { checks, ready: checks.every((check) => check.status !== 'fail') };
760
+ }
761
+ /**
762
+ * Selects the first failing precondition — the one `--strict-preflight`
763
+ * exits on, and the one `gateforge run` reports before doing any work.
764
+ *
765
+ * Args:
766
+ * report: the built preflight section.
767
+ *
768
+ * Returns:
769
+ * RunCheck | null: the first failing line in declared order, or null.
770
+ */
771
+ export function firstFailingCheck(report) {
772
+ return report.checks.find((check) => check.status === 'fail') ?? null;
773
+ }
774
+ //# sourceMappingURL=run-preflight.js.map