@ultimat3/cli 31.15.0 → 31.17.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 (86) hide show
  1. package/README.md +7 -1
  2. package/package.json +29 -29
  3. package/src/cache-graph.ts +67 -0
  4. package/src/cmd-cache-spec.ts +25 -0
  5. package/src/cmd-cache.ts +187 -0
  6. package/src/cmd-config-spec.ts +23 -0
  7. package/src/cmd-config.ts +61 -0
  8. package/src/cmd-doctor.ts +47 -37
  9. package/src/cmd-exercise.ts +42 -5
  10. package/src/cmd-explain-spec.ts +24 -0
  11. package/src/cmd-explain.ts +201 -0
  12. package/src/cmd-logs-spec.ts +34 -0
  13. package/src/cmd-logs.ts +80 -0
  14. package/src/cmd-planned.ts +15 -29
  15. package/src/cmd-token-spec.ts +54 -0
  16. package/src/cmd-token.ts +173 -0
  17. package/src/cmd-upgrade.ts +19 -2
  18. package/src/cmd-verify-spec.ts +13 -3
  19. package/src/cmd-verify.ts +2 -0
  20. package/src/config-redact.ts +39 -0
  21. package/src/coverage-floor.ts +2 -2
  22. package/src/dev-boot-data-dir.ts +69 -0
  23. package/src/dev-boot.ts +26 -13
  24. package/src/doctor-env-reserved.ts +111 -0
  25. package/src/doctor-floor.ts +62 -0
  26. package/src/doctor-pins.ts +101 -0
  27. package/src/doctor-probe.ts +21 -1
  28. package/src/doctor-row-security.ts +119 -4
  29. package/src/doctor-warnings.ts +55 -0
  30. package/src/error-codes-doctor.ts +24 -0
  31. package/src/error-codes-tooling.ts +6 -4
  32. package/src/error-codes.ts +7 -0
  33. package/src/errors.ts +8 -2
  34. package/src/exercise-entry-edit.ts +5 -1
  35. package/src/exercise-floor-report.ts +138 -0
  36. package/src/exercise-floor-verdict.ts +98 -0
  37. package/src/exercise-floor.ts +158 -0
  38. package/src/exercise-routes.ts +59 -0
  39. package/src/explain-capture.ts +38 -0
  40. package/src/generate-exercise.ts +2 -2
  41. package/src/generate-factories.ts +133 -0
  42. package/src/generate-files.ts +11 -0
  43. package/src/generate-kinds.ts +13 -0
  44. package/src/mcp-db-target.ts +4 -3
  45. package/src/mcp-errors.ts +14 -0
  46. package/src/messages-gate.ts +2 -0
  47. package/src/messages-ops.ts +32 -0
  48. package/src/messages-upgrade.ts +14 -0
  49. package/src/messages.ts +5 -0
  50. package/src/otlp-export.ts +16 -2
  51. package/src/registry.ts +10 -0
  52. package/src/role-start.ts +11 -5
  53. package/src/runtime-services.ts +35 -19
  54. package/src/serve-boot-phases.ts +30 -0
  55. package/src/serve-boot-warnings.ts +62 -0
  56. package/src/serve-boot.ts +30 -11
  57. package/src/templates/generate-cron-job.ts +90 -0
  58. package/src/templates/generate-purge.ts +93 -0
  59. package/src/templates/generate-webhook-receiver.ts +274 -0
  60. package/src/templates/github/ci.yml.ts +101 -36
  61. package/src/templates/guard-repo-raw-sql-test.ts +174 -0
  62. package/src/templates/guard-repo-raw-sql.ts +115 -145
  63. package/src/templates/guard-unbounded-fanout.ts +170 -0
  64. package/src/templates/scaffold-claude-commands.ts +3 -2
  65. package/src/templates/scaffold-docs.ts +3 -2
  66. package/src/templates/scaffold-guards.ts +3 -0
  67. package/src/templates/scaffold-verify-floor.ts +4 -0
  68. package/src/test-dotenv.ts +15 -2
  69. package/src/upgrade-coverage.ts +109 -0
  70. package/src/upgrade-document.ts +18 -0
  71. package/src/upgrade-exercise-floor.ts +53 -0
  72. package/src/upgrade-gate.ts +84 -29
  73. package/src/upgrade-guards.ts +159 -0
  74. package/src/upgrade-report.ts +33 -1
  75. package/src/verify-checks.ts +3 -1
  76. package/src/verify-floor.ts +13 -0
  77. package/src/verify-plan.ts +127 -0
  78. package/wiki/CI-Parallel-Gate.md +38 -1
  79. package/wiki/CLI-Reference.md +115 -14
  80. package/wiki/Caching-And-Invalidation.md +10 -10
  81. package/wiki/Configuration.md +20 -2
  82. package/wiki/Known-Gaps.md +1 -1
  83. package/wiki/MCP-And-AI.md +1 -1
  84. package/wiki/Testing.md +96 -2
  85. package/wiki/Troubleshooting.md +3 -2
  86. package/wiki/Upgrading.md +9 -0
@@ -1,16 +1,27 @@
1
- // A hop's gate, run by the CLI the hop just installed: `x manifest`, `x doctor --json`, `x exercise
2
- // --json`, `x verify --json`. Never in this process, because the installed CLI is the one that knows the installed
3
- // framework (`local-cli.ts`), and it may be many majors older than this one: each answer is read as
4
- // a foreign document, and one that will not parse is a finding, never a green.
1
+ // A hop's gate, run by the CLI the hop just installed: manifest, doctor, the missing guards and a
2
+ // Bun-floor hop's coverage (`upgrade-guards.ts`, `upgrade-coverage.ts`), exercise, verify. Never in
3
+ // this process: the installed CLI knows the installed framework (`local-cli.ts`) and may be majors
4
+ // older, so each answer is read as a foreign document, and one that will not parse is never green.
5
5
 
6
6
  // why: Bun exposes no path-join primitive; the installed bin is assembled from the app root.
7
7
  import { join } from 'node:path';
8
8
  import { t } from '@ultimat3/schema';
9
9
  import type { ExecResult, Runner } from './exec';
10
10
  import { execOutput } from './exec';
11
+ import { exerciseReportStamp } from './exercise-floor-report';
11
12
  import { LOCAL_CLI_BIN } from './local-cli';
13
+ import type { CoverageRebaseline, HopCoverage } from './upgrade-coverage';
14
+ import { rebaselineCoverage, statedCoverage } from './upgrade-coverage';
15
+ import { documentIn } from './upgrade-document';
16
+ import type { HopExerciseFloor } from './upgrade-exercise-floor';
17
+ import { ratchetExerciseFloor } from './upgrade-exercise-floor';
18
+ import type { WithheldGuard } from './upgrade-guards';
19
+ import { installMissingGuards } from './upgrade-guards';
12
20
  import { parseJson } from './upgrade-registry';
13
21
 
22
+ // Where it always was: `verify-exercise.ts` and `verify-budgets-build.ts` read it from here.
23
+ export { documentIn } from './upgrade-document';
24
+
14
25
  const FINDING = t.object({
15
26
  code: t.string,
16
27
  cause: t.string,
@@ -31,6 +42,7 @@ const GUARD_DIFFERS = t.object({ name: t.string, refresh: t.string });
31
42
  const DOCTOR = t.object({
32
43
  data: t.optional(
33
44
  t.object({
45
+ warnings: t.optional(t.array(FINDING)),
34
46
  guards: t.optional(
35
47
  t.object({
36
48
  missing: t.optional(t.array(GUARD_MISSING)),
@@ -70,6 +82,7 @@ interface VerifyDocument {
70
82
 
71
83
  interface DoctorDocument {
72
84
  readonly data?: {
85
+ readonly warnings?: readonly RawFinding[];
73
86
  readonly guards?: {
74
87
  readonly missing?: readonly { readonly name: string; readonly add: string }[];
75
88
  readonly differs?: readonly { readonly name: string; readonly refresh: string }[];
@@ -80,8 +93,14 @@ interface DoctorDocument {
80
93
  export interface HopGuards {
81
94
  /** False when the hop's `x doctor` predates the listing: unknown, which is not the same as none. */
82
95
  readonly reported: boolean;
96
+ /** Still missing after the hop: the ones it withheld, each with the command that adds it. */
83
97
  readonly missing: readonly { readonly name: string; readonly add: string }[];
98
+ /** Held in another form: the app's edit, listed and never touched. */
84
99
  readonly differs: readonly { readonly name: string; readonly refresh: string }[];
100
+ /** Written by this hop from the installed release's template; `boundaries` found nothing more. */
101
+ readonly installed: readonly string[];
102
+ /** Not written, with how many findings each would have added (`upgrade-guards.ts`). */
103
+ readonly withheld: readonly WithheldGuard[];
85
104
  }
86
105
 
87
106
  /**
@@ -97,8 +116,17 @@ export interface HopExercise {
97
116
 
98
117
  export interface HopGate {
99
118
  readonly manifest: { readonly ok: boolean; readonly findings: readonly GateFinding[] };
119
+ /**
120
+ * The installed `x doctor`'s `data.warnings[]`: never red on this major, the next one's red —
121
+ * said by the hop that installed the doctor saying them (`X_VERIFY_STEP_UNFLOORED` among them).
122
+ */
123
+ readonly doctorWarnings: readonly GateFinding[];
100
124
  readonly guards: HopGuards;
125
+ /** The coverage floor a Bun-floor hop moved to what it measured; null when none moved. */
126
+ readonly coverage: HopCoverage | null;
101
127
  readonly exercise: HopExercise;
128
+ /** The exercise figures the hop wrote into `x.verify.json` as its ratchet; null when none. */
129
+ readonly exerciseFloor: HopExerciseFloor | null;
102
130
  readonly verify: {
103
131
  readonly ok: boolean;
104
132
  readonly summary: string;
@@ -108,21 +136,6 @@ export interface HopGate {
108
136
  };
109
137
  }
110
138
 
111
- /**
112
- * The one JSON document on a child's stdout. Whole first; then its last line that parses, because
113
- * the CLI that keeps fd 1 to one document under `--json` is a recent one and a hop can install one
114
- * that still logs a boot line ahead of it.
115
- */
116
- export function documentIn(stdout: string): unknown {
117
- const whole = parseJson(stdout.trim());
118
- if (whole !== undefined) return whole;
119
- const lines = stdout.split('\n').filter((line) => line.trimStart().startsWith('{'));
120
- return lines
121
- .reverse()
122
- .map(parseJson)
123
- .find((parsed) => parsed !== undefined);
124
- }
125
-
126
139
  const flatten = (document: {
127
140
  readonly steps?: VerifyDocument['steps'];
128
141
  readonly findings?: readonly RawFinding[];
@@ -187,20 +200,39 @@ const readExercise = (result: ExecResult): HopExercise => {
187
200
  return { reported: true, ok: result.ok && document.ok, findings: flatten(document) };
188
201
  };
189
202
 
190
- /** A doctor that exits red is normal (a port, an env key); only its listing is read here. */
191
- const readGuards = (result: ExecResult): HopGuards => {
203
+ /** A doctor that exits red is normal (a port, an env key); its listing and warnings are read. */
204
+ const readDoctor = (result: ExecResult): DoctorDocument['data'] => {
192
205
  const parsed = DOCTOR.safeParse(documentIn(result.stdout));
193
- const guards =
194
- parsed.issues === undefined ? (parsed.value as DoctorDocument).data?.guards : undefined;
195
- if (guards === undefined) return { reported: false, missing: [], differs: [] };
196
- return { reported: true, missing: guards.missing ?? [], differs: guards.differs ?? [] };
206
+ return parsed.issues === undefined ? (parsed.value as DoctorDocument).data : undefined;
207
+ };
208
+
209
+ const readGuards = (doctor: DoctorDocument['data']): HopGuards => {
210
+ const guards = doctor?.guards;
211
+ if (guards === undefined) {
212
+ return { reported: false, missing: [], differs: [], installed: [], withheld: [] };
213
+ }
214
+ return {
215
+ reported: true,
216
+ missing: guards.missing ?? [],
217
+ differs: guards.differs ?? [],
218
+ installed: [],
219
+ withheld: [],
220
+ };
197
221
  };
198
222
 
199
- /** The four, in order, each told apart by `onStage` so a long gate is not a long silence. */
223
+ export type HopStage = 'manifest' | 'doctor' | 'guards' | 'coverage' | 'exercise' | 'verify';
224
+
225
+ /**
226
+ * The gate, in order, each stage told apart by `onStage` so a long gate is not a long silence.
227
+ * `guards` runs only when the doctor lists a missing one; `coverage` only on a hop that moved the
228
+ * Bun floor — both before `verify`, so the verdict is the one on the tree the hop leaves.
229
+ */
200
230
  export async function runHopGate(input: {
201
231
  readonly runner: Runner;
202
232
  readonly root: string;
203
- readonly onStage: (stage: 'manifest' | 'doctor' | 'exercise' | 'verify') => void;
233
+ readonly onStage: (stage: HopStage) => void;
234
+ /** Present when the hop moved the Bun floor: what the coverage rebaseline's `why` says. */
235
+ readonly bunMoved?: CoverageRebaseline;
204
236
  }): Promise<HopGate> {
205
237
  const { runner, root, onStage } = input;
206
238
  const installed = (args: readonly string[]): Promise<ExecResult> =>
@@ -208,12 +240,35 @@ export async function runHopGate(input: {
208
240
  onStage('manifest');
209
241
  const manifest = readManifest(await installed(['manifest', '--json']));
210
242
  onStage('doctor');
211
- const guards = readGuards(await installed(['doctor', '--json']));
243
+ const doctor = readDoctor(await installed(['doctor', '--json']));
244
+ const doctorWarnings = (doctor?.warnings ?? []).map(pick);
245
+ const listed = readGuards(doctor);
246
+ let guards = listed;
247
+ if (listed.missing.length > 0) {
248
+ onStage('guards');
249
+ const done = await installMissingGuards({ cli: installed, root, missing: listed.missing });
250
+ const still = new Set(done.withheld.map((guard) => guard.name));
251
+ guards = {
252
+ ...listed,
253
+ missing: listed.missing.filter((guard) => still.has(guard.name)),
254
+ ...done,
255
+ };
256
+ }
257
+ let coverage: HopCoverage | null = null;
258
+ const stated = input.bunMoved === undefined ? undefined : await statedCoverage(root);
259
+ if (input.bunMoved !== undefined && stated !== undefined) {
260
+ onStage('coverage');
261
+ coverage = await rebaselineCoverage({ cli: installed, root, stated, bun: input.bunMoved });
262
+ }
263
+ // The report's stamp first: only a report this exercise rewrote is ratcheted.
264
+ const stamp = await exerciseReportStamp(root);
212
265
  onStage('exercise');
213
266
  const exercise = readExercise(await installed(['exercise', '--json']));
267
+ // Before `verify`, from the report that exercise just wrote: the gate judges the figures it holds.
268
+ const exerciseFloor = await ratchetExerciseFloor(root, stamp);
214
269
  onStage('verify');
215
270
  const verify = readVerify(await installed(['verify', '--json']));
216
- return { manifest, guards, exercise, verify };
271
+ return { manifest, doctorWarnings, guards, coverage, exercise, exerciseFloor, verify };
217
272
  }
218
273
 
219
274
  /** What a repository with no app can still be asked, in the order an author would run them. */
@@ -0,0 +1,159 @@
1
+ // A hop's missing shipped guards, installed by the CLI the hop just installed (`x g guard <name>`,
2
+ // that release's own template) — each one only if the `boundaries` step finds nothing more with it
3
+ // on disk. One the tree breaks is taken back out — every file its run listed, the refreshed manifest
4
+ // too, put back as it was — and listed; an app-modified guard is never touched (`differs`).
5
+
6
+ // why: Bun exposes no path-join primitive; a written guard's path is relative to the app root.
7
+ import { join } from 'node:path';
8
+ import { MANIFEST_FILENAME } from '@ultimat3/manifest';
9
+ import { t } from '@ultimat3/schema';
10
+ import type { ExecResult } from './exec';
11
+ import { documentIn } from './upgrade-document';
12
+
13
+ const GENERATED = t.object({
14
+ data: t.optional(t.object({ files: t.optional(t.array(t.string)) })),
15
+ });
16
+ const STEP = t.object({
17
+ name: t.string,
18
+ findings: t.optional(t.array(t.object({ code: t.string }))),
19
+ });
20
+ const BOUNDARIES = t.object({ steps: t.array(STEP) });
21
+
22
+ /** A missing guard the hop did not install, with what stood in the way. */
23
+ export interface WithheldGuard {
24
+ readonly name: string;
25
+ /** The command that writes it anyway; `x verify` then names what it finds. */
26
+ readonly add: string;
27
+ /** How many findings it would add to `boundaries`; null when that could not be measured. */
28
+ readonly findings: number | null;
29
+ }
30
+
31
+ export interface GuardInstall {
32
+ readonly installed: readonly string[];
33
+ readonly withheld: readonly WithheldGuard[];
34
+ }
35
+
36
+ /** Runs the installed CLI with these arguments in the app root. */
37
+ export type InstalledCli = (args: readonly string[]) => Promise<ExecResult>;
38
+
39
+ const MEASURE = ['verify', '--only', 'boundaries', '--json'] as const;
40
+
41
+ /** `boundaries`' finding count, or undefined when this CLI answered no step by that name. */
42
+ const boundariesCount = async (cli: InstalledCli): Promise<number | undefined> => {
43
+ const parsed = BOUNDARIES.safeParse(documentIn((await cli(MEASURE)).stdout));
44
+ if (parsed.issues !== undefined) return undefined;
45
+ const steps = (
46
+ parsed.value as { readonly steps: readonly { name: string; findings?: unknown[] }[] }
47
+ ).steps;
48
+ const step = steps.find((candidate) => candidate.name === 'boundaries');
49
+ return step === undefined ? undefined : (step.findings ?? []).length;
50
+ };
51
+
52
+ /** A path's bytes before a run, or null when it did not exist: what a rollback puts back. */
53
+ type Prior = ReadonlyMap<string, Uint8Array | null>;
54
+
55
+ /** One generator run: the paths it listed, and how to put each back. */
56
+ interface Generated {
57
+ readonly files: readonly string[];
58
+ readonly prior: Prior;
59
+ }
60
+
61
+ /**
62
+ * Every path a guard run can write, read before it runs: the guard and its test, and the generated
63
+ * contracts `x g` refreshes and lists beside them (`x.manifest.json`, `openapi*.json`). A listed
64
+ * path outside this set has no known prior state and is never deleted.
65
+ */
66
+ const snapshot = async (root: string, name: string): Promise<Prior> => {
67
+ const paths = new Set([`guards/${name}.ts`, `guards/${name}.test.ts`, MANIFEST_FILENAME]);
68
+ paths.add('openapi.json');
69
+ for await (const path of new Bun.Glob('openapi*.json').scan({ cwd: root })) paths.add(path);
70
+ const prior = new Map<string, Uint8Array | null>();
71
+ for (const path of paths) {
72
+ const file = Bun.file(join(root, path));
73
+ prior.set(path, (await file.exists()) ? await file.bytes() : null);
74
+ }
75
+ return prior;
76
+ };
77
+
78
+ /** Writes one guard; what it listed with what stood there before, or undefined when refused. */
79
+ const generate = async (
80
+ cli: InstalledCli,
81
+ root: string,
82
+ name: string,
83
+ ): Promise<Generated | undefined> => {
84
+ const prior = await snapshot(root, name);
85
+ const result = await cli(['g', 'guard', name, '--json']);
86
+ if (!result.ok) return undefined;
87
+ const parsed = GENERATED.safeParse(documentIn(result.stdout));
88
+ const listed =
89
+ parsed.issues === undefined
90
+ ? (parsed.value as { readonly data?: { readonly files?: readonly string[] } }).data?.files
91
+ : undefined;
92
+ return { files: listed ?? [`guards/${name}.ts`, `guards/${name}.test.ts`], prior };
93
+ };
94
+
95
+ /** Puts each listed path back: rewritten when it existed before the run, deleted when it did not. */
96
+ const rollback = async (root: string, run: Generated | undefined): Promise<void> => {
97
+ for (const path of run?.files ?? []) {
98
+ const before = run?.prior.get(path);
99
+ // Unknown prior state: leaving a file is recoverable, deleting a committed one is not.
100
+ if (before === undefined) continue;
101
+ const file = Bun.file(join(root, path));
102
+ if (before !== null) await Bun.write(file, before);
103
+ else if (await file.exists()) await file.delete();
104
+ }
105
+ };
106
+
107
+ /**
108
+ * Every missing guard, installed or withheld. All at once first — two `boundaries` runs when the
109
+ * tree breaks none of them, the usual case — and one at a time only when the count rose, so the
110
+ * guard that found something is the one taken back out.
111
+ */
112
+ export async function installMissingGuards(input: {
113
+ readonly cli: InstalledCli;
114
+ readonly root: string;
115
+ readonly missing: readonly { readonly name: string; readonly add: string }[];
116
+ }): Promise<GuardInstall> {
117
+ const { cli, root, missing } = input;
118
+ if (missing.length === 0) return { installed: [], withheld: [] };
119
+ const unmeasured = (guard: { name: string; add: string }): WithheldGuard => ({
120
+ name: guard.name,
121
+ add: guard.add,
122
+ findings: null,
123
+ });
124
+ const base = await boundariesCount(cli);
125
+ if (base === undefined) return { installed: [], withheld: missing.map(unmeasured) };
126
+
127
+ const written = new Map<string, Generated>();
128
+ const withheld: WithheldGuard[] = [];
129
+ for (const guard of missing) {
130
+ const run = await generate(cli, root, guard.name);
131
+ if (run === undefined) withheld.push(unmeasured(guard));
132
+ else written.set(guard.name, run);
133
+ }
134
+ if (written.size === 0) return { installed: [], withheld };
135
+ const together = await boundariesCount(cli);
136
+ if (together !== undefined && together <= base) {
137
+ return { installed: [...written.keys()], withheld: sortByName(withheld) };
138
+ }
139
+
140
+ // Newest first, so each artifact ends at the bytes it held before the first run.
141
+ for (const run of [...written.values()].reverse()) await rollback(root, run);
142
+ const installed: string[] = [];
143
+ let held = base;
144
+ for (const guard of missing.filter(({ name }) => written.has(name))) {
145
+ const run = await generate(cli, root, guard.name);
146
+ const count = run === undefined ? undefined : await boundariesCount(cli);
147
+ if (run !== undefined && count !== undefined && count <= held) {
148
+ installed.push(guard.name);
149
+ held = count;
150
+ continue;
151
+ }
152
+ await rollback(root, run);
153
+ withheld.push({ ...guard, findings: count === undefined ? null : count - held });
154
+ }
155
+ return { installed, withheld: sortByName(withheld) };
156
+ }
157
+
158
+ const sortByName = (list: readonly WithheldGuard[]): readonly WithheldGuard[] =>
159
+ [...list].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
@@ -88,10 +88,39 @@ export const humanLines = (input: {
88
88
  ...(agentsMd === 'link' || agentsMd === 'differs'
89
89
  ? [msg(agentsMd === 'link' ? 'cli.upgrade.agentsMd.link' : 'cli.upgrade.agentsMd.differs')]
90
90
  : []),
91
- ...(gate?.guards.missing ?? []).map((guard) => msg('cli.upgrade.guard', { fix: guard.add })),
91
+ ...(gate?.guards.installed ?? []).map((name) => msg('cli.upgrade.guardInstalled', { name })),
92
+ ...(gate?.guards.withheld ?? []).map((guard) =>
93
+ guard.findings === null
94
+ ? msg('cli.upgrade.guardUnmeasured', { fix: guard.add })
95
+ : msg('cli.upgrade.guardWithheld', { fix: guard.add, count: guard.findings }),
96
+ ),
92
97
  ...(gate?.guards.differs ?? []).map((guard) =>
93
98
  msg('cli.upgrade.guard', { fix: guard.refresh }),
94
99
  ),
100
+ ...(gate === undefined || gate.coverage === null
101
+ ? []
102
+ : [
103
+ msg('cli.upgrade.coverage', {
104
+ file: gate.coverage.file,
105
+ fromLines: gate.coverage.from.lines,
106
+ fromFuncs: gate.coverage.from.funcs,
107
+ toLines: gate.coverage.to.lines,
108
+ toFuncs: gate.coverage.to.funcs,
109
+ lines: Math.floor(gate.coverage.measured.lines * 10) / 10,
110
+ funcs: Math.floor(gate.coverage.measured.funcs * 10) / 10,
111
+ }),
112
+ ]),
113
+ ...(gate === undefined || gate.exerciseFloor === null
114
+ ? []
115
+ : [
116
+ msg('cli.upgrade.exerciseFloor', {
117
+ file: gate.exerciseFloor.file,
118
+ figures: JSON.stringify(gate.exerciseFloor.written),
119
+ }),
120
+ ]),
121
+ ...(gate?.doctorWarnings ?? []).map((warning) =>
122
+ msg('cli.upgrade.doctorWarning', { code: warning.code, fix: warning.fix }),
123
+ ),
95
124
  // The exercise's own list first: every fix it has, before the gate's verdict on the same tree.
96
125
  ...findingLines([
97
126
  ...(gate?.exercise.findings ?? []),
@@ -144,8 +173,11 @@ export const report = (input: {
144
173
  typescript: input.typescript,
145
174
  agentsMd: input.agentsMd ?? null,
146
175
  guards: gate?.guards ?? null,
176
+ coverage: gate?.coverage ?? null,
147
177
  manifest: gate?.manifest ?? null,
178
+ doctorWarnings: gate?.doctorWarnings ?? [],
148
179
  exercise: gate?.exercise ?? null,
180
+ exerciseFloor: gate?.exerciseFloor ?? null,
149
181
  verify: gate?.verify ?? null,
150
182
  scripts,
151
183
  then,
@@ -24,6 +24,7 @@ import { checkUngeneratableMigrations } from './db-ungeneratable';
24
24
  import { checkDocumentStyles, documentSurfaces } from './document-styles';
25
25
  import { driftOutcome } from './drift-store';
26
26
  import { checkErrorCodeResolution, checkErrorFixReport } from './error-contract';
27
+ import { withUnprovenFloor } from './exercise-floor-report';
27
28
  import { guardFindings } from './guards';
28
29
  import { catalogFindings } from './i18n-registration';
29
30
  import { isrQueryAdvice } from './isr-query-advice';
@@ -195,7 +196,8 @@ export const VERIFY_STEPS: readonly VerifyStep[] = [
195
196
  ...TEST_STEPS.slice(0, AFTER_JOB),
196
197
  // Every step that loads the app stands down while the load is red: the cause is `manifest`'s,
197
198
  // and what a half-filled registry looks like is not a finding (`load-findings.ts`).
198
- blockedByLoad(exerciseStep),
199
+ // The floor's verdict on the report the child wrote rides on the step (`exercise-floor-report.ts`).
200
+ blockedByLoad(withUnprovenFloor(exerciseStep)),
199
201
  ...TEST_STEPS.slice(AFTER_JOB),
200
202
  blockedByLoad({
201
203
  name: 'drift',
@@ -11,6 +11,8 @@ import { ERROR_DOCS_URL, renderThrowable } from '@ultimat3/core';
11
11
  import { AGENTS_MD_MAX_BYTES } from '@ultimat3/manifest';
12
12
  import type { CoverageFloor } from './coverage-floor';
13
13
  import { COVERAGE_FIELD, readCoverageFloor } from './coverage-floor';
14
+ import type { ExerciseFloor } from './exercise-floor';
15
+ import { EXERCISE_FIELD, readExerciseFloor } from './exercise-floor';
14
16
  import type { Finding } from './output';
15
17
  import type { StepTimeouts } from './verify-deadline';
16
18
  import { readStepTimeouts, STEP_TIMEOUT_FIELD } from './verify-deadline';
@@ -75,6 +77,11 @@ export interface VerifyFloor {
75
77
  * whole `x verify` under `CI`. Absent is no ceiling, and a CI run names the number to write.
76
78
  */
77
79
  readonly skipCeiling?: SkipCeiling;
80
+ /**
81
+ * What the `exercise` step's pass may leave unproven (`exercise-floor.ts`). Absent is a warning
82
+ * naming the figure to write, never red: an app that has not opted in stays green on `main`.
83
+ */
84
+ readonly exercise?: ExerciseFloor;
78
85
  /** Why part of the file is not a floor. The `manifest` step reports these; nothing swallows them. */
79
86
  readonly problems: readonly string[];
80
87
  }
@@ -194,6 +201,7 @@ export function parseVerifyFloor(
194
201
  const coverage = readCoverageFloor(record);
195
202
  const rolling = readRollingSince(record);
196
203
  const skips = readSkipCeiling(record, declared);
204
+ const exercise = readExerciseFloor(record);
197
205
  const rest = {
198
206
  ...(budget.budget === undefined ? {} : { agentsMdMaxBytes: budget.budget }),
199
207
  ...(typecheckBin.bin === undefined ? {} : { typecheckBin: typecheckBin.bin }),
@@ -202,6 +210,7 @@ export function parseVerifyFloor(
202
210
  ...(coverage.coverage === undefined ? {} : { coverage: coverage.coverage }),
203
211
  ...(rolling.since === undefined ? {} : { rollingSince: rolling.since }),
204
212
  ...(skips.ceiling === undefined ? {} : { skipCeiling: skips.ceiling }),
213
+ ...(exercise.floor === undefined ? {} : { exercise: exercise.floor }),
205
214
  };
206
215
  const steps = record?.['steps'];
207
216
  if (!Array.isArray(steps)) {
@@ -217,6 +226,7 @@ export function parseVerifyFloor(
217
226
  ...coverage.problems,
218
227
  ...rolling.problems,
219
228
  ...skips.problems,
229
+ ...exercise.problems,
220
230
  ],
221
231
  };
222
232
  }
@@ -237,6 +247,7 @@ export function parseVerifyFloor(
237
247
  ...coverage.problems,
238
248
  ...rolling.problems,
239
249
  ...skips.problems,
250
+ ...exercise.problems,
240
251
  ],
241
252
  };
242
253
  }
@@ -330,5 +341,7 @@ const fixFor = (problem: string): string => {
330
341
  return `x doctor --json # it names your newest migration id: set "${ROLLING_SINCE_FIELD}" in ${VERIFY_FLOOR_FILE} to that, "0" to judge them all, or drop the key`;
331
342
  if (problem.includes(`"${SKIP_CEILING_FIELD}"`))
332
343
  return `x verify --json # then write "${SKIP_CEILING_FIELD}" in ${VERIFY_FLOOR_FILE} as { "contract": 9 } — a step it runs, a whole number of tests`;
344
+ if (problem.includes(`"${EXERCISE_FIELD}`))
345
+ return `x exercise --json # then write "${EXERCISE_FIELD}" in ${VERIFY_FLOOR_FILE} as { "unprovenMax": 0, "statementsMax": 100 } — a ratio from 0 to 1, a whole number of statements`;
333
346
  return `x verify --json # then write ${VERIFY_FLOOR_FILE} as {"steps":["unit","contract"]}, naming only steps it ran`;
334
347
  };
@@ -0,0 +1,127 @@
1
+ // `x verify plan --parts <n> --json`: the gate cut into CI parts, each `x verify --only <steps>
2
+ // [--shard i/n]` on a runner of its own, as one document a workflow's matrix reads by `fromJSON`.
3
+ // Derived from `VERIFY_STEP_NAMES` and `SHARDABLE_STEPS`, so a new step lands in a part without
4
+ // anyone editing a workflow — and `x verify merge` folds the parts back into the one verdict.
5
+
6
+ import { BadFlagError } from './errors';
7
+ import { readIntFlag } from './flag-number';
8
+ import { msg } from './messages';
9
+ import type { CommandResult, JsonValue } from './output';
10
+ import type { ParsedArgs } from './parse';
11
+ import type { VerifyStepName } from './verify-step';
12
+ import { VERIFY_STEP_NAMES } from './verify-step';
13
+
14
+ /**
15
+ * What a part's runner starts before the gate: nothing, the test Postgres alone, or every test
16
+ * service. A level rather than service names — the compose file is the app's, and the workflow that
17
+ * starts it is the one place its names are spelled.
18
+ */
19
+ export type PartNeeds = 'none' | 'database' | 'services';
20
+
21
+ export interface PlanPart {
22
+ /** The matrix row's name: the job's title and its artifact's, unique across the plan. */
23
+ readonly part: string;
24
+ /** In the gate's declared order, as `--only` runs them. */
25
+ readonly only: readonly VerifyStepName[];
26
+ /** `i/n` — absent on a part that runs its steps whole. */
27
+ readonly shard?: string;
28
+ readonly needs: PartNeeds;
29
+ }
30
+
31
+ /**
32
+ * The three groups that are not "everything else". The suites that read the test database split
33
+ * together; `live` alone, one process per runner (`SHARDABLE_STEPS`); `e2e` beside `typecheck`,
34
+ * the two slow unsharded steps, so the cheap static steps finish on a runner of their own.
35
+ */
36
+ const UNIT_STEPS: readonly VerifyStepName[] = ['unit', 'contract', 'job'];
37
+ const LIVE_STEPS: readonly VerifyStepName[] = ['live'];
38
+ const BROWSER_STEPS: readonly VerifyStepName[] = ['typecheck', 'e2e'];
39
+
40
+ /** What `x new` writes into the workflow: one static, one browser, one unit and one live runner. */
41
+ export const DEFAULT_PLAN_PARTS = 4;
42
+ /** Two unsharded parts and at least one shard of each split group: fewer is not this layout. */
43
+ export const MIN_SPLIT_PARTS = 4;
44
+ /** A bound on a typo, not on cost: GitHub caps one matrix at 256 jobs. */
45
+ export const MAX_PLAN_PARTS = 64;
46
+
47
+ const ordered = (steps: readonly VerifyStepName[]): readonly VerifyStepName[] =>
48
+ VERIFY_STEP_NAMES.filter((name) => steps.includes(name));
49
+
50
+ const shards = (
51
+ prefix: string,
52
+ steps: readonly VerifyStepName[],
53
+ total: number,
54
+ needs: PartNeeds,
55
+ ): readonly PlanPart[] =>
56
+ Array.from({ length: total }, (_, at) => ({
57
+ part: `${prefix}-${String(at + 1)}`,
58
+ only: ordered(steps),
59
+ shard: `${String(at + 1)}/${String(total)}`,
60
+ needs,
61
+ }));
62
+
63
+ /**
64
+ * `parts` runners' worth of the gate. One is the whole gate on one runner. From four, the
65
+ * runners past the two unsharded parts split the unit group and `live`, the unit group taking the
66
+ * odd one: it holds the most files. Every step lands in exactly one part or in every shard of one
67
+ * split — the rule `x verify merge` refuses a run by.
68
+ */
69
+ export function verifyPlan(parts: number): readonly PlanPart[] {
70
+ if (parts === 1) return [{ part: 'gate', only: VERIFY_STEP_NAMES, needs: 'services' }];
71
+ const split = parts - 2;
72
+ const grouped = new Set<VerifyStepName>([...UNIT_STEPS, ...LIVE_STEPS, ...BROWSER_STEPS]);
73
+ return [
74
+ ...shards('unit', UNIT_STEPS, Math.ceil(split / 2), 'database'),
75
+ ...shards('live', LIVE_STEPS, Math.floor(split / 2), 'services'),
76
+ { part: 'static', only: VERIFY_STEP_NAMES.filter((name) => !grouped.has(name)), needs: 'none' },
77
+ { part: 'e2e', only: ordered(BROWSER_STEPS), needs: 'database' },
78
+ ];
79
+ }
80
+
81
+ /** `strategy.matrix` as GitHub reads it: `only` comma-joined, `shard` only where there is one. */
82
+ export const planMatrix = (plan: readonly PlanPart[]): { readonly include: JsonValue[] } => ({
83
+ include: plan.map((part) => ({
84
+ part: part.part,
85
+ only: part.only.join(','),
86
+ ...(part.shard === undefined ? {} : { shard: part.shard }),
87
+ needs: part.needs,
88
+ })),
89
+ });
90
+
91
+ /** `--parts`, screened: an integer in range, and never the two counts this layout cannot make. */
92
+ export function readPlanParts(args: ParsedArgs): number {
93
+ const example = `x verify plan --parts ${String(DEFAULT_PLAN_PARTS)} --json`;
94
+ const parts =
95
+ readIntFlag(args, {
96
+ name: 'parts',
97
+ command: 'verify plan',
98
+ min: 1,
99
+ max: MAX_PLAN_PARTS,
100
+ example,
101
+ }) ?? DEFAULT_PLAN_PARTS;
102
+ if (parts > 1 && parts < MIN_SPLIT_PARTS) {
103
+ throw new BadFlagError({
104
+ flag: 'parts',
105
+ command: 'verify plan',
106
+ reason: `${String(parts)} runners cannot hold the static part, the browser part and a shard of each split group (1, or ${String(MIN_SPLIT_PARTS)} to ${String(MAX_PLAN_PARTS)})`,
107
+ fix: example,
108
+ });
109
+ }
110
+ return parts;
111
+ }
112
+
113
+ /** The subcommand's body: pure, so the workflow's matrix and this answer cannot disagree. */
114
+ export function verifyPlanCommand(args: ParsedArgs): CommandResult {
115
+ const parts = readPlanParts(args);
116
+ const plan = verifyPlan(parts);
117
+ return {
118
+ ok: true,
119
+ command: 'verify plan',
120
+ summary: msg('cli.verify.plan', { parts: plan.length, steps: VERIFY_STEP_NAMES.length }),
121
+ data: { parts: plan.length, matrix: planMatrix(plan) },
122
+ lines: plan.map(
123
+ (part) =>
124
+ `${part.part} x verify --only ${part.only.join(',')}${part.shard === undefined ? '' : ` --shard ${part.shard}`} (${part.needs})`,
125
+ ),
126
+ };
127
+ }
@@ -80,7 +80,44 @@ slowest part's, which is the wall time CI waited. A part that is not an `x verif
80
80
  document is `X_VERIFY_MERGE_INPUT` — and so is a step whose `durationMs` is not a number or whose
81
81
  `findings` are not each a `code`, `cause` and `fix`.
82
82
 
83
- ## A GitHub Actions workflow
83
+ ## `x verify plan` — the parts, as data
84
+
85
+ `As of 31.17.0`. `x verify plan [--parts n] --json` answers the split instead of a workflow spelling
86
+ it: `data.matrix` is a GitHub `strategy.matrix`, one row per part —
87
+ `{ part, only, shard?, needs }` — derived from `VERIFY_STEP_NAMES`, so a step the gate gains lands in
88
+ a part with no workflow edit. Pure: no file read, nothing started.
89
+
90
+ ```text
91
+ $ x verify plan --parts 4
92
+ unit-1 x verify --only unit,contract,job --shard 1/1 (database)
93
+ live-1 x verify --only live --shard 1/1 (services)
94
+ static x verify --only lint,boundaries,filesize,package-shape,errors,exercise,eval,drift,contract-diff,budgets,seo,i18n,policy,manifest,roadmap (none)
95
+ e2e x verify --only typecheck,e2e (database)
96
+ ```
97
+
98
+ | `--parts` | Layout |
99
+ |---|---|
100
+ | `1` | `gate`: every step on one runner, `needs: services` |
101
+ | `4`–`64` (default `4`) | `static` and `e2e` (`typecheck` + `e2e`, the two slow unsharded steps) whole; the rest of the runners split between shards of `unit,contract,job` and of `live`, the unit group taking the odd one |
102
+ | `2`, `3`, `0`, `65`+ | `X_CLI_BAD_FLAG` — two or three runners cannot hold this layout |
103
+
104
+ `needs` is a level, not service names: `none`, `database` (the test Postgres alone) or `services`
105
+ (every test service) — the compose file is the app's, and the workflow is the one place its names are
106
+ spelled. **`x new`'s `.github/workflows/ci.yml` reads it**: a `plan` job runs
107
+ `bun run verify plan --parts 4 --json` and hands `.data.matrix` to the `gate` job by `fromJSON`;
108
+ each part runs `bun run setup`, starts what its `needs` asks for, runs
109
+ `bun run verify --only "$ONLY" ${SHARD:+--shard "$SHARD"} --json` and uploads the document, red or
110
+ green; `verify` downloads every part and runs `bun run verify merge`. An app scaffolded before 31.17.0
111
+ keeps its one-job workflow, which still works; to adopt, copy a fresh scaffold's
112
+ `.github/workflows/ci.yml`.
113
+
114
+ This repository's own `ci.yml` stays hand-written — it carries services and URLs only the framework
115
+ has — and `verify-plan.test.ts` holds its `gate` matrix to `verifyPlan(7)`: a step added to the gate
116
+ or a part edited out of the matrix is red there before it is `X_VERIFY_MERGE_INCOMPLETE` after a push.
117
+
118
+ ## A GitHub Actions workflow, by hand
119
+
120
+ The same shape with a matrix you write yourself — for a split the plan does not make:
84
121
 
85
122
  ```yaml
86
123
  name: ci