@ultimat3/cli 31.47.0 → 31.48.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 (62) hide show
  1. package/package.json +29 -29
  2. package/src/cmd-drill.ts +20 -1
  3. package/src/cmd-heavy-spec.ts +28 -0
  4. package/src/cmd-heavy.ts +160 -0
  5. package/src/cmd-test.ts +13 -3
  6. package/src/cmd-upgrade.ts +22 -11
  7. package/src/codemods/docs-many-agents.ts +30 -0
  8. package/src/codemods/e2e-suite-floor.ts +42 -0
  9. package/src/codemods/e2e-suite.ts +71 -0
  10. package/src/codemods/index.ts +4 -0
  11. package/src/codemods/pending.ts +2 -2
  12. package/src/codemods/test-ports.ts +40 -33
  13. package/src/codemods/test-suites.ts +11 -22
  14. package/src/codemods/verify-floor-skips.ts +18 -6
  15. package/src/doctor-advisory-floors.ts +30 -8
  16. package/src/error-codes-tooling.ts +9 -3
  17. package/src/exec.ts +11 -3
  18. package/src/heavy-cores.ts +51 -0
  19. package/src/heavy-env.ts +19 -0
  20. package/src/heavy-errors.ts +36 -0
  21. package/src/heavy-flock.ts +73 -0
  22. package/src/heavy-ledger.ts +358 -0
  23. package/src/heavy-memory.ts +67 -0
  24. package/src/heavy-weights.ts +47 -0
  25. package/src/heavy.ts +290 -0
  26. package/src/local-cli.ts +6 -5
  27. package/src/mcp-errors.ts +4 -1
  28. package/src/messages.ts +11 -0
  29. package/src/registry.ts +2 -0
  30. package/src/role-replicator.ts +5 -3
  31. package/src/runtime-cache.ts +24 -3
  32. package/src/runtime-overrides.ts +4 -2
  33. package/src/templates/guard-released-forms.ts +35 -13
  34. package/src/templates/scaffold-claude-agents.ts +9 -6
  35. package/src/templates/scaffold-claude-commands.ts +1 -1
  36. package/src/templates/scaffold-docs.ts +5 -4
  37. package/src/templates/scaffold-suites.ts +22 -0
  38. package/src/test-batches.ts +9 -3
  39. package/src/test-shards.ts +3 -3
  40. package/src/test-slots.ts +35 -161
  41. package/src/upgrade-gate-codemods.ts +1 -18
  42. package/src/verify-checks.ts +4 -3
  43. package/src/verify-coverage-run.ts +5 -4
  44. package/src/verify-deadline.ts +18 -2
  45. package/src/verify-heavy-steps.ts +26 -0
  46. package/src/verify-test-run.ts +3 -2
  47. package/src/verify-tests.ts +27 -20
  48. package/wiki/Building-Your-Own-Base.md +15 -2
  49. package/wiki/CI-Parallel-Gate.md +2 -3
  50. package/wiki/CLI-Reference.md +25 -13
  51. package/wiki/Caching-And-Invalidation.md +1 -1
  52. package/wiki/Compared.md +13 -11
  53. package/wiki/Configuration.md +22 -4
  54. package/wiki/Home.md +1 -0
  55. package/wiki/Interface-Rules.md +1 -1
  56. package/wiki/Known-Gaps.md +1 -1
  57. package/wiki/Mail.md +1 -1
  58. package/wiki/Many-Agents.md +60 -0
  59. package/wiki/Stability.md +1 -1
  60. package/wiki/Testing.md +5 -5
  61. package/wiki/Tutorial-01-First-App.md +2 -2
  62. package/wiki/Upgrading.md +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/cli",
3
- "version": "31.47.0",
3
+ "version": "31.48.0",
4
4
  "description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -53,34 +53,34 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@babel/core": "^8.0.10",
56
- "@ultimat3/action": "31.47.0",
57
- "@ultimat3/admin": "31.47.0",
58
- "@ultimat3/ai": "31.47.0",
59
- "@ultimat3/auth": "31.47.0",
60
- "@ultimat3/cache": "31.47.0",
61
- "@ultimat3/core": "31.47.0",
62
- "@ultimat3/db": "31.47.0",
63
- "@ultimat3/entity": "31.47.0",
64
- "@ultimat3/flags": "31.47.0",
65
- "@ultimat3/http": "31.47.0",
66
- "@ultimat3/i18n": "31.47.0",
67
- "@ultimat3/jobs": "31.47.0",
68
- "@ultimat3/mail": "31.47.0",
69
- "@ultimat3/manifest": "31.47.0",
70
- "@ultimat3/mcp": "31.47.0",
71
- "@ultimat3/money": "31.47.0",
72
- "@ultimat3/notify": "31.47.0",
73
- "@ultimat3/policy": "31.47.0",
74
- "@ultimat3/pwa": "31.47.0",
75
- "@ultimat3/query": "31.47.0",
76
- "@ultimat3/realtime": "31.47.0",
77
- "@ultimat3/render": "31.47.0",
78
- "@ultimat3/schema": "31.47.0",
79
- "@ultimat3/scraping": "31.47.0",
80
- "@ultimat3/seo": "31.47.0",
81
- "@ultimat3/storage": "31.47.0",
82
- "@ultimat3/testing": "31.47.0",
83
- "@ultimat3/time": "31.47.0",
56
+ "@ultimat3/action": "31.48.0",
57
+ "@ultimat3/admin": "31.48.0",
58
+ "@ultimat3/ai": "31.48.0",
59
+ "@ultimat3/auth": "31.48.0",
60
+ "@ultimat3/cache": "31.48.0",
61
+ "@ultimat3/core": "31.48.0",
62
+ "@ultimat3/db": "31.48.0",
63
+ "@ultimat3/entity": "31.48.0",
64
+ "@ultimat3/flags": "31.48.0",
65
+ "@ultimat3/http": "31.48.0",
66
+ "@ultimat3/i18n": "31.48.0",
67
+ "@ultimat3/jobs": "31.48.0",
68
+ "@ultimat3/mail": "31.48.0",
69
+ "@ultimat3/manifest": "31.48.0",
70
+ "@ultimat3/mcp": "31.48.0",
71
+ "@ultimat3/money": "31.48.0",
72
+ "@ultimat3/notify": "31.48.0",
73
+ "@ultimat3/policy": "31.48.0",
74
+ "@ultimat3/pwa": "31.48.0",
75
+ "@ultimat3/query": "31.48.0",
76
+ "@ultimat3/realtime": "31.48.0",
77
+ "@ultimat3/render": "31.48.0",
78
+ "@ultimat3/schema": "31.48.0",
79
+ "@ultimat3/scraping": "31.48.0",
80
+ "@ultimat3/seo": "31.48.0",
81
+ "@ultimat3/storage": "31.48.0",
82
+ "@ultimat3/testing": "31.48.0",
83
+ "@ultimat3/time": "31.48.0",
84
84
  "babel-preset-solid": "^1.9.16"
85
85
  }
86
86
  }
package/src/cmd-drill.ts CHANGED
@@ -11,6 +11,7 @@ import type {
11
11
  DrillDeclarations,
12
12
  DrillFleet,
13
13
  DrillReport,
14
+ DrillRoleNotPlayed,
14
15
  } from '@ultimat3/testing';
15
16
  import {
16
17
  bunDrillSql,
@@ -21,6 +22,7 @@ import {
21
22
  drillBudgets,
22
23
  drillNamed,
23
24
  drillRoles,
25
+ drillRolesNotPlayed,
24
26
  drillServices,
25
27
  runDrill,
26
28
  runRollout,
@@ -38,6 +40,7 @@ import { readIntFlag } from './flag-number';
38
40
  import { msg } from './messages';
39
41
  import type { CommandResult, Finding, JsonValue } from './output';
40
42
  import { flagBool } from './parse';
43
+ import { replicatedRelations } from './role-replicator';
41
44
 
42
45
  /** Read through `readIntFlag`, which refuses `5s`, `NaN` and a fraction with the flag's name. */
43
46
  const BUDGET_FLAG = 'budget-ms';
@@ -177,9 +180,20 @@ export const drillCommand: CliCommand = {
177
180
  }
178
181
  const budgets = drillBudgets(drillConfigOf(config), override);
179
182
  const { targets, skipped } = await drillTargets(root);
183
+ // After `drillTargets`: loading the app is what fills the entity registry read here.
184
+ const publishable = replicatedRelations().length > 0;
180
185
  const reports: DrillReport[] = [];
186
+ const rolesNotPlayed: (DrillRoleNotPlayed & { readonly drill: string })[] = [];
181
187
  for (const { drill, services } of planned) {
182
188
  const { fault } = drill;
189
+ const found = {
190
+ bus: services.nats !== undefined,
191
+ logicalPostgres: services.logicalPostgres === true,
192
+ publishable,
193
+ };
194
+ for (const gap of drillRolesNotPlayed(drill, found)) {
195
+ rolesNotPlayed.push({ drill: drill.name, ...gap });
196
+ }
183
197
  // The rollout order: the stamp is this package's to write, so the rewind is handed in.
184
198
  const order =
185
199
  fault.kind === 'order'
@@ -188,7 +202,7 @@ export const drillCommand: CliCommand = {
188
202
  const fleet = await startDrillFleet({
189
203
  root,
190
204
  services,
191
- roles: drillRoles(drill),
205
+ roles: drillRoles(drill, found),
192
206
  readyTimeoutMs: READY_TIMEOUT_MS,
193
207
  beforeMigrate: order,
194
208
  });
@@ -209,6 +223,9 @@ export const drillCommand: CliCommand = {
209
223
  lines: [
210
224
  ...reports.map((report) => ` ${report.verdict.ok ? 'held' : 'FAILED'} ${report.name}`),
211
225
  ...notRun.map((drill) => ` not run ${drill}`),
226
+ ...rolesNotPlayed.map(
227
+ (gap) => ` not played ${gap.drill}: ${gap.role}, needs ${gap.needs}`,
228
+ ),
212
229
  ],
213
230
  findings,
214
231
  data: {
@@ -218,6 +235,8 @@ export const drillCommand: CliCommand = {
218
235
  skippedWrites: skipped.map((entry) => ({ ...entry })),
219
236
  drills: reports.map(reportJson),
220
237
  notRun,
238
+ // A role the rollout order left out, with what it needs: CI refuses a non-empty list.
239
+ rolesNotPlayed: rolesNotPlayed.map((gap) => ({ ...gap })),
221
240
  },
222
241
  };
223
242
  },
@@ -0,0 +1,28 @@
1
+ // `x heavy`'s declaration, apart from its body: the parser, `x help` and the `errors` step read it
2
+ // without loading `cmd-heavy.ts`, which `registry.ts` imports only when the command runs.
3
+
4
+ import type { CommandSpec } from './parse';
5
+
6
+ export const heavySpec: CommandSpec = {
7
+ name: 'heavy',
8
+ summary:
9
+ "the machine's shared memory ledger: who is running, who is queued, and any command run inside it",
10
+ usage: 'x heavy [status] [--json] · x heavy run [--label s] [--mb n] [--json] -- <command…>',
11
+ subcommands: ['status', 'run'],
12
+ defaultSubcommand: 'status',
13
+ passthrough: true,
14
+ flags: [
15
+ {
16
+ name: 'label',
17
+ type: 'string',
18
+ summary: 'what other waiters see this run called (default: the command)',
19
+ subcommands: ['run'],
20
+ },
21
+ {
22
+ name: 'mb',
23
+ type: 'string',
24
+ summary: 'the memory to reserve, its measured peak (default: a whole-repo typecheck)',
25
+ subcommands: ['run'],
26
+ },
27
+ ],
28
+ };
@@ -0,0 +1,160 @@
1
+ // `x heavy`: the machine ledger as a command. `status` is a read that changes nothing; `run` puts any
2
+ // command inside one reservation, passes its exit code through and forwards stop signals, which is
3
+ // how a repository with no Ultimate in it shares the same queue.
4
+
5
+ // why: Bun exposes no load average, core count or total-memory primitive.
6
+ import { availableParallelism, loadavg, totalmem } from 'node:os';
7
+ import { heavySpec } from './cmd-heavy-spec';
8
+ import type { CliCommand, CommandContext } from './command';
9
+ import { MissingPositionalError } from './errors';
10
+ import { readIntFlag } from './flag-number';
11
+ import { describeEntry, heavyState, withHeavy } from './heavy';
12
+ import { coreCap, runnableTasks } from './heavy-cores';
13
+ import { HeavyCommandNotFoundError } from './heavy-errors';
14
+ import { readLedger } from './heavy-ledger';
15
+ import { availableMemoryBytes, usableMemoryBytes } from './heavy-memory';
16
+ import { DEFAULT_RUN_MB } from './heavy-weights';
17
+ import type { HandOffChild } from './local-cli-handoff';
18
+ import { handOff } from './local-cli-handoff';
19
+ import { msg } from './messages';
20
+ import type { CommandResult, JsonValue } from './output';
21
+ import { findingFrom } from './output';
22
+ import { flagString } from './parse';
23
+
24
+ const gb = (bytes: number): string => (bytes / 2 ** 30).toFixed(1);
25
+ const MAX_RUN_MB = 1024 * 1024;
26
+
27
+ async function status(ctx: CommandContext): Promise<CommandResult> {
28
+ const state = await heavyState({ ...ctx.env, ULTIMATE_HEAVY_HOLD: undefined });
29
+ const now = Date.now();
30
+ const view = state.on ? readLedger(state.dir, state.tryLock) : { holds: [], queue: [] };
31
+ const cores = coreCap(ctx.env);
32
+ const coreText = cores === undefined ? String(availableParallelism()) : String(cores);
33
+ const usedMb = view.holds.reduce((sum, entry) => sum + entry.mb, 0);
34
+ const [one = 0, five = 0, fifteen = 0] = loadavg();
35
+ const machine = {
36
+ cores: availableParallelism(),
37
+ runnable: runnableTasks(),
38
+ load: { one, five, fifteen },
39
+ totalBytes: usableMemoryBytes(totalmem()),
40
+ availableBytes: availableMemoryBytes(),
41
+ };
42
+ const entryJson = (entry: (typeof view.holds)[number]): JsonValue => ({
43
+ pid: entry.pid,
44
+ mb: entry.mb,
45
+ label: entry.label,
46
+ cwd: entry.cwd,
47
+ ageMs: Math.max(0, now - entry.at),
48
+ });
49
+ return {
50
+ ok: true,
51
+ command: 'heavy',
52
+ summary: state.on
53
+ ? msg('cli.heavy.status.summary', {
54
+ used: usedMb,
55
+ capacity: state.capacityMb,
56
+ holds: view.holds.length,
57
+ queued: view.queue.length,
58
+ cores: coreText,
59
+ })
60
+ : msg('cli.heavy.status.off', { reason: state.detail ?? state.off, cores: coreText }),
61
+ lines: [
62
+ msg('cli.heavy.status.machine', {
63
+ load: one.toFixed(1),
64
+ cpus: machine.cores,
65
+ runnable: machine.runnable,
66
+ free: gb(machine.availableBytes),
67
+ total: gb(machine.totalBytes),
68
+ }),
69
+ ...view.holds.map((entry) =>
70
+ msg('cli.heavy.status.hold', { entry: describeEntry(entry, now) }),
71
+ ),
72
+ ...view.queue.map((entry, at) =>
73
+ msg('cli.heavy.status.queued', { position: at + 1, entry: describeEntry(entry, now) }),
74
+ ),
75
+ ],
76
+ data: {
77
+ enabled: state.on,
78
+ ...(state.on
79
+ ? { dir: state.dir, capacityMb: state.capacityMb, usedMb }
80
+ : { off: state.off, ...(state.detail === undefined ? {} : { detail: state.detail }) }),
81
+ coreCap: cores ?? null,
82
+ machine,
83
+ holds: view.holds.map(entryJson),
84
+ queue: view.queue.map(entryJson),
85
+ },
86
+ };
87
+ }
88
+
89
+ const seconds = (ms: number): string => `${(ms / 1000).toFixed(1)}s`;
90
+
91
+ async function run(ctx: CommandContext): Promise<CommandResult> {
92
+ const command = ctx.args.passthrough;
93
+ const first = command[0];
94
+ if (first === undefined || ctx.args.positionals.length > 0) {
95
+ throw new MissingPositionalError({
96
+ command: 'heavy run',
97
+ positional: '-- command',
98
+ example: 'x heavy run --label tests -- bun test',
99
+ });
100
+ }
101
+ // Under `--json` fd 1 is this command's one document, so the child's stdout moves to fd 2.
102
+ const stream = ctx.args.json ? undefined : ('stderr' as const);
103
+ const envelope = { command: 'heavy', ...(stream === undefined ? {} : { stream }) };
104
+ const path = ctx.env['PATH'];
105
+ if (Bun.which(first, { cwd: ctx.cwd, ...(path === undefined ? {} : { PATH: path }) }) === null) {
106
+ const finding = findingFrom(new HeavyCommandNotFoundError(first));
107
+ return { ...envelope, ok: false, summary: finding.cause, findings: [finding], exitCode: 127 };
108
+ }
109
+ const mb = readIntFlag(ctx.args, {
110
+ name: 'mb',
111
+ command: 'heavy',
112
+ min: 1,
113
+ max: MAX_RUN_MB,
114
+ example: 'x heavy run --mb 4096 -- bun test',
115
+ });
116
+ const label = flagString(ctx.args, 'label') ?? command.slice(0, 3).join(' ');
117
+ const queued = performance.now();
118
+ let startedAt = queued;
119
+ const code = await withHeavy(
120
+ { label, cwd: ctx.cwd, env: ctx.env, unitMb: mb ?? DEFAULT_RUN_MB },
121
+ (child) => {
122
+ startedAt = performance.now();
123
+ return handOff(
124
+ command,
125
+ { ...ctx.env, ...child.env },
126
+ {
127
+ spawn: (argv, env): HandOffChild =>
128
+ // Untimed: the child is the command the caller asked to run, and its stop signals are
129
+ // forwarded by `handOff`. Counted under `cli`'s spawn-timeout pin with that hand-off.
130
+ Bun.spawn([...argv], {
131
+ cwd: ctx.cwd,
132
+ env,
133
+ // The reservation's lock goes with it: killing this wrapper frees nothing the
134
+ // command is still using.
135
+ stdio: ['inherit', ctx.args.json ? 2 : 'inherit', 'inherit', ...child.fds],
136
+ }),
137
+ },
138
+ );
139
+ },
140
+ );
141
+ const ranMs = performance.now() - startedAt;
142
+ const waitedMs = startedAt - queued;
143
+ return {
144
+ ...envelope,
145
+ ok: code === 0,
146
+ summary: msg('cli.heavy.run.done', {
147
+ command: label,
148
+ code,
149
+ ran: seconds(ranMs),
150
+ waited: seconds(waitedMs),
151
+ }),
152
+ exitCode: code,
153
+ data: { exitCode: code, ranMs: Math.round(ranMs), waitedMs: Math.round(waitedMs) },
154
+ };
155
+ }
156
+
157
+ export const heavyCommand: CliCommand = {
158
+ spec: heavySpec,
159
+ run: (ctx) => (ctx.args.subcommand === 'run' ? run(ctx) : status(ctx)),
160
+ };
package/src/cmd-test.ts CHANGED
@@ -19,6 +19,7 @@ import { ok } from './command';
19
19
  import { BadFlagError, NoTestFilesError } from './errors';
20
20
  import type { Runner } from './exec';
21
21
  import { readIntFlag } from './flag-number';
22
+ import { FREE_RUN_FILES } from './heavy-weights';
22
23
  import { msg } from './messages';
23
24
  import type { CommandResult, JsonValue } from './output';
24
25
  import type { ParsedArgs } from './parse';
@@ -245,9 +246,18 @@ export const testCommand: CliCommand = {
245
246
  workers,
246
247
  ...(isolate ? { isolate } : {}),
247
248
  ...(seed === undefined ? {} : { seed }),
248
- // A default-width run leases its workers from the machine pool, so a second `x test` or
249
- // gate on the same box runs narrower instead of doubling its memory.
250
- ...(plan === undefined ? {} : withLease(machineLease(plan.workers, ctx.env))),
249
+ // Every run but a worker's own few files enters the machine ledger, so a second `x test` or
250
+ // gate on the same box narrows or queues instead of doubling its memory.
251
+ ...(files.length <= FREE_RUN_FILES
252
+ ? {}
253
+ : withLease(
254
+ machineLease(ctx.env, {
255
+ cwd: ctx.cwd,
256
+ label: type === undefined ? 'x test' : `x test ${type}`,
257
+ ...(type === undefined ? {} : { type }),
258
+ ...(plan === undefined ? { exact: true } : {}),
259
+ }),
260
+ )),
251
261
  ...(filter === undefined ? {} : { filter }),
252
262
  ...(type === undefined ? {} : { type }),
253
263
  // `kept` is the corpus the run saw. `selected`, not `discovered`: with `--affected` the sample was taken from the narrowed
@@ -11,6 +11,8 @@ import { runUpgradeCodemods } from './cmd-upgrade-codemods';
11
11
  import { upgradeSpec } from './cmd-upgrade-spec';
12
12
  import type { CliCommand, CommandContext } from './command';
13
13
  import { failed, ok } from './command';
14
+ import { staleTransitiveFloors } from './doctor-advisory-floors';
15
+ import { supersededFindings } from './doctor-superseded';
14
16
  import { BadFlagError, BunVersionError } from './errors';
15
17
  import type { Runner } from './exec';
16
18
  import { execOutput } from './exec';
@@ -24,7 +26,7 @@ import type { BunEdit, BunManual } from './upgrade-bun-floor';
24
26
  import { editBunSites, floorOf, isBunSite } from './upgrade-bun-floor';
25
27
  import { requireCleanTree } from './upgrade-clean-tree';
26
28
  import { repoScripts, runHopGate, runRepoScripts } from './upgrade-gate';
27
- import { atTargetCodemods, EVERY_RELEASE, previewCodemods } from './upgrade-gate-codemods';
29
+ import { EVERY_RELEASE, previewCodemods } from './upgrade-gate-codemods';
28
30
  import { acquireUpgradeLock } from './upgrade-lock';
29
31
  import { readManifests, readPins, rewritePins } from './upgrade-pins';
30
32
  import type { UpgradeHop } from './upgrade-plan';
@@ -32,7 +34,6 @@ import { planHop, releaseOf } from './upgrade-plan';
32
34
  import { publishedVersions, releaseBunRange } from './upgrade-registry';
33
35
  import type { PlannedWrites } from './upgrade-report';
34
36
  import { humanLines, NO_WRITES, report, thenLine } from './upgrade-report';
35
- import { codemodLines } from './upgrade-report-codemods';
36
37
  import { findUpgradeRoot } from './upgrade-root';
37
38
  import { stopChildrenOnSignal, tagRunner, upgradeTag } from './upgrade-signals';
38
39
  import type { UnfinishedHop } from './upgrade-unfinished';
@@ -86,17 +87,29 @@ async function planWrites(input: {
86
87
  return { files, edited, manual };
87
88
  }
88
89
 
89
- /** `bun install`, or the refusal carrying the one command that undoes what was just written. */
90
- async function install(runner: Runner, root: string, to: string): Promise<void> {
91
- const result = await runner([process.execPath, 'install'], { cwd: root });
90
+ /** One `bun` step of the install, or the refusal carrying the command that undoes the pins. */
91
+ async function installStep(
92
+ runner: Runner,
93
+ root: string,
94
+ to: string,
95
+ args: readonly string[],
96
+ ): Promise<void> {
97
+ const result = await runner([process.execPath, ...args], { cwd: root });
92
98
  if (result.ok) return;
93
99
  throw new UltimateError({
94
100
  code: 'X_UPGRADE_INSTALL_FAILED',
95
- cause: `bun install exited ${String(result.code)} after pinning ${to}: ${execOutput(result).slice(-800) || 'no output'}`,
101
+ cause: `bun ${args.join(' ')} exited ${String(result.code)} after pinning ${to}: ${execOutput(result).slice(-800) || 'no output'}`,
96
102
  fix: 'git restore . # undoes the pins, since the tree was clean; then fix what the cause names and re-run: x upgrade --json',
97
103
  });
98
104
  }
99
105
 
106
+ /** `bun install` keeps what the lockfile resolves, so a patched transitive release is asked for. */
107
+ async function install(runner: Runner, root: string, to: string): Promise<void> {
108
+ await installStep(runner, root, to, ['install']);
109
+ const stale = await staleTransitiveFloors(root);
110
+ if (stale.length > 0) await installStep(runner, root, to, ['update', ...stale]);
111
+ }
112
+
100
113
  const stageLine = (stage: string): string => JSON.stringify({ upgrade: stage });
101
114
 
102
115
  /**
@@ -177,9 +190,8 @@ export const createUpgradeCommand = (
177
190
  // A record for some other target is a hop since undone (`git stash`): nothing left to finish.
178
191
  if (unfinished !== undefined && !dryRun) await clearUnfinished(root);
179
192
  const then = thenLine({ hop, dryRun, app, gate: undefined, scripts: [] });
180
- const carried = app
181
- ? await atTargetCodemods({ runner: ctx.runner, root, to: hop.to, dryRun })
182
- : undefined;
193
+ // No version moved, so no codemod is owed: a hand run is `x upgrade codemods --from <version>`.
194
+ const superseded = app ? await supersededFindings(root) : [];
183
195
  const summary =
184
196
  hop.next === null
185
197
  ? msg('cli.upgrade.atLatest', { version: hop.to })
@@ -198,11 +210,10 @@ export const createUpgradeCommand = (
198
210
  scripts: [],
199
211
  then,
200
212
  typescript,
201
- ...carried,
213
+ superseded,
202
214
  }),
203
215
  lines: [
204
216
  ...typescript.map((lag) => msg('cli.upgrade.typescript', { ...lag })),
205
- ...codemodLines(carried?.codemods ?? null),
206
217
  msg('cli.upgrade.then', { then }),
207
218
  ],
208
219
  });
@@ -0,0 +1,30 @@
1
+ // 31.48.0: CLAUDE.md states who runs what when several agents share a machine, the rule the machine
2
+ // ledger exists to back. Prose: it lands where the table stands as `x new` wrote it, and is skipped
3
+ // silently where the app reworded that row or already says it.
4
+
5
+ import type { Codemod } from './codemod';
6
+ import type { SnippetEdit } from './engine-edits';
7
+ import { editSnippets } from './engine-edits';
8
+
9
+ const CLAUDE = 'CLAUDE.md';
10
+ const NEXT_ROW = '| One way | generators, not hand-rolled files:';
11
+
12
+ /** Terse on purpose: a shaped app's CLAUDE.md sits within bytes of `AGENTS_MD_MAX_BYTES`. */
13
+ export const MANY_AGENTS_ROW =
14
+ '| Many agents | a worker runs its own files; the coordinator runs the gate once | `bunx x heavy status` |';
15
+
16
+ export const DOCS_MANY_AGENTS_EDITS: readonly SnippetEdit[] = [
17
+ { from: NEXT_ROW, to: `${MANY_AGENTS_ROW}\n${NEXT_ROW}`, optional: true },
18
+ ];
19
+
20
+ export const codemod: Codemod = {
21
+ id: 'docs-many-agents',
22
+ since: '31.48.0',
23
+ summary: "CLAUDE.md's table says a worker runs its own files and the coordinator runs the gate",
24
+ async run(app) {
25
+ if (((await app.read(CLAUDE)) ?? '').includes('x heavy status')) {
26
+ return { changed: [], skipped: [] };
27
+ }
28
+ return editSnippets(app, CLAUDE, DOCS_MANY_AGENTS_EDITS);
29
+ },
30
+ };
@@ -0,0 +1,42 @@
1
+ // 31.47.1: 31.28.0's floor required `e2e` of any app with a page, while only `apps/web/site/page.tsx`
2
+ // got a suite, so an app without that page answered `X_VERIFY_SUITE_VANISHED`. A floor in that state
3
+ // gains the suite, or, with no page a suite could visit, excuses the step and says why.
4
+
5
+ import { isJsonObject } from '@ultimat3/core';
6
+ import { VERIFY_FLOOR_FILE } from '../verify-floor';
7
+ import type { Codemod, CodemodResult } from './codemod';
8
+ import { e2eSuitePlan, writeE2eSuite } from './e2e-suite';
9
+ import { e2eExcuse, renderFloor, withSkip } from './verify-floor-skips';
10
+
11
+ const NOTHING: CodemodResult = { changed: [], skipped: [] };
12
+
13
+ function parsed(source: string): Record<string, unknown> | undefined {
14
+ try {
15
+ const floor: unknown = JSON.parse(source);
16
+ return isJsonObject(floor) ? floor : undefined;
17
+ } catch {
18
+ // `verify-floor-skips` reports a floor it cannot read.
19
+ return undefined;
20
+ }
21
+ }
22
+
23
+ export const codemod: Codemod = {
24
+ id: 'e2e-suite-floor',
25
+ since: '31.47.1',
26
+ summary: `an ${VERIFY_FLOOR_FILE} requiring e2e gains a suite for a page the app serves, or excuses the step where no page can be visited`,
27
+ async run(app) {
28
+ const source = await app.read(VERIFY_FLOOR_FILE);
29
+ const floor = source === undefined ? undefined : parsed(source);
30
+ const steps = floor?.['steps'];
31
+ if (floor === undefined || !Array.isArray(steps) || !steps.includes('e2e')) return NOTHING;
32
+ if (isJsonObject(floor['skip']) && 'e2e' in floor['skip']) return NOTHING;
33
+ const plan = await e2eSuitePlan(app);
34
+ if (plan.kind !== 'none') return writeE2eSuite(app, plan);
35
+ const next = withSkip(
36
+ { ...floor, steps: steps.filter((step) => step !== 'e2e') },
37
+ { e2e: e2eExcuse(plan) },
38
+ );
39
+ await app.write(VERIFY_FLOOR_FILE, renderFloor(next));
40
+ return { changed: [VERIFY_FLOOR_FILE], skipped: [] };
41
+ },
42
+ };
@@ -0,0 +1,71 @@
1
+ // Whether this app's `e2e` step has a suite to run, and if not which one a codemod can write: the
2
+ // one answer the suite codemods and the floor codemods share, so the floor never requires a suite
3
+ // nothing created (`X_VERIFY_SUITE_VANISHED`). Only `apps/web` is here: the page the step boots.
4
+
5
+ import { isJsonObject } from '@ultimat3/core';
6
+ import { routePathFromFile } from '@ultimat3/render';
7
+ import { E2E_SUITE_PATH, e2eSuiteFiles, pageE2eSuite } from '../templates/scaffold-suites';
8
+ import { VERIFY_FLOOR_FILE } from '../verify-floor';
9
+ import { ownerOf } from '../verify-test-command';
10
+ import type { CodemodApp, CodemodResult } from './codemod';
11
+ import { writeIfAbsent } from './engine-edits';
12
+
13
+ export type E2eSuitePlan =
14
+ /** The app already holds an e2e test: the step has something to run. */
15
+ | { readonly kind: 'held' }
16
+ | { readonly kind: 'write'; readonly path: string; readonly contents: string }
17
+ /** Nothing to run and nothing to write; `pages` says whether the app serves any page at all. */
18
+ | { readonly kind: 'none'; readonly pages: boolean };
19
+
20
+ const LANDING_PAGE = 'apps/web/site/page.tsx';
21
+
22
+ /** Why `e2e` is excused for an app whose every page needs a value in its URL. */
23
+ export const NO_STATIC_PAGE_WHY =
24
+ 'every page here needs a URL parameter, so no suite could be written for one: add a *.e2e.test.ts that visits a real URL, and then e2e moves from "skip" to "steps"';
25
+
26
+ /** A URL that names itself and is safe inside the suite's quotes: no `:param`, no `*rest`. */
27
+ const STATIC_URL = /^\/[\w./~-]*$/;
28
+
29
+ const holdsE2eTest = async (app: CodemodApp): Promise<boolean> =>
30
+ (await app.glob('{apps,packages,e2e}/**/*.test.{ts,tsx}')).some(
31
+ (path) => !path.includes('/node_modules/') && ownerOf(path) === 'e2e',
32
+ );
33
+
34
+ /** Whether the floor already excuses `e2e`: the app's decision, which no suite overrides. */
35
+ async function floorExcusesE2e(app: CodemodApp): Promise<boolean> {
36
+ try {
37
+ const floor: unknown = JSON.parse((await app.read(VERIFY_FLOOR_FILE)) ?? 'null');
38
+ return isJsonObject(floor) && isJsonObject(floor['skip']) && 'e2e' in floor['skip'];
39
+ } catch {
40
+ // Unreadable is `verify-floor-skips`' to report, and it excuses nothing.
41
+ return false;
42
+ }
43
+ }
44
+
45
+ /** The landing page's suite, else one for the shortest URL `apps/web` serves with no parameter. */
46
+ export async function e2eSuitePlan(app: CodemodApp): Promise<E2eSuitePlan> {
47
+ if (await app.exists(LANDING_PAGE)) {
48
+ const contents = e2eSuiteFiles()[0]?.contents;
49
+ if (typeof contents === 'string') return { kind: 'write', path: E2E_SUITE_PATH, contents };
50
+ }
51
+ if (await holdsE2eTest(app)) return { kind: 'held' };
52
+ const pages = await app.glob('apps/web/{site,app}/**/page.tsx');
53
+ const served = (await app.glob('apps/*/{site,app}/**/page.tsx')).length > 0;
54
+ if (await floorExcusesE2e(app)) return { kind: 'none', pages: served };
55
+ const [first] = pages
56
+ .map((file) => ({ file, url: routePathFromFile(file).path }))
57
+ .filter(({ url }) => STATIC_URL.test(url))
58
+ .sort((a, b) => a.url.length - b.url.length || (a.file < b.file ? -1 : 1));
59
+ if (first === undefined) return { kind: 'none', pages: served };
60
+ return {
61
+ kind: 'write',
62
+ path: first.file.replace(/page\.tsx$/, 'page.e2e.test.ts'),
63
+ contents: pageE2eSuite(first.url),
64
+ };
65
+ }
66
+
67
+ /** The plan's file, unless the app already holds that path. */
68
+ export const writeE2eSuite = async (app: CodemodApp, plan: E2eSuitePlan): Promise<CodemodResult> =>
69
+ plan.kind === 'write'
70
+ ? writeIfAbsent(app, plan.path, plan.contents)
71
+ : { changed: [], skipped: [] };
@@ -18,8 +18,10 @@ import { codemod as docsCiParts } from './docs-ci-parts';
18
18
  import { codemod as docsEnvGuard } from './docs-env-guard';
19
19
  import { codemod as docsGateProse } from './docs-gate-prose';
20
20
  import { codemod as docsIslandRows } from './docs-island-rows';
21
+ import { codemod as docsManyAgents } from './docs-many-agents';
21
22
  import { codemod as docsShippedGuards } from './docs-shipped-guards';
22
23
  import { codemod as docsTestServices } from './docs-test-services';
24
+ import { codemod as e2eSuiteFloor } from './e2e-suite-floor';
23
25
  import { codemod as formatEditedHook } from './format-edited-hook';
24
26
  import { codemod as helmAlertsDeploy } from './helm-alerts-deploy';
25
27
  import { codemod as helmAlertsObjective } from './helm-alerts-objective';
@@ -69,4 +71,6 @@ export const CODEMODS: readonly Codemod[] = [
69
71
  ciPinnedActions,
70
72
  ciArtifactRetention,
71
73
  ciWeeklySchedule,
74
+ e2eSuiteFloor,
75
+ docsManyAgents,
72
76
  ];
@@ -1,6 +1,6 @@
1
1
  // The codemods an app still owes, for `x doctor`: an `x upgrade` driven by a CLI older than the
2
2
  // engine applied none, and the installed CLI's gate cannot write. A dry run of every codemod up to
3
- // this CLI's release names them; `x upgrade --json` at the target then applies them (idempotent).
3
+ // this CLI's release names them; `x upgrade codemods --from 0.0.0` applies them (idempotent).
4
4
 
5
5
  import type { Finding } from '../output';
6
6
  import type { Codemod } from './codemod';
@@ -29,7 +29,7 @@ export async function pendingCodemodFindings(
29
29
  {
30
30
  code: CODEMODS_PENDING,
31
31
  cause: `${String(files.length)} file(s) still as an older scaffold wrote them, owed by ${owed.map((one) => `${one.id} (${one.since})`).join(', ')}: the x upgrade that installed ${to} ran under a CLI with no codemods — ${files.slice(0, 8).join(', ')}`,
32
- fix: 'x upgrade --json # on a clean tree; at the release it is on, it applies every codemod still owed',
32
+ fix: 'x upgrade codemods --from 0.0.0 --json # applies every codemod still owed, up to this release',
33
33
  at: files[0] ?? '.',
34
34
  },
35
35
  ];