@ultimat3/cli 31.27.0 → 31.28.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 (107) hide show
  1. package/CLAUDE.md +3 -1
  2. package/README.md +14 -4
  3. package/package.json +29 -29
  4. package/src/app-manifest.ts +6 -1
  5. package/src/cmd-doctor.ts +11 -3
  6. package/src/cmd-repro-spec.ts +13 -1
  7. package/src/cmd-repro.ts +37 -5
  8. package/src/cmd-upgrade-codemods.ts +71 -0
  9. package/src/cmd-upgrade-spec.ts +19 -5
  10. package/src/cmd-upgrade.ts +91 -34
  11. package/src/codemods/agents-dev-mcp.ts +50 -0
  12. package/src/codemods/authenticator-session-refusal.ts +214 -0
  13. package/src/codemods/biome-no-default-export.ts +58 -0
  14. package/src/codemods/bunfig-island-coverage.ts +33 -0
  15. package/src/codemods/chart-dashboard.ts +73 -0
  16. package/src/codemods/ci-e2e-browser-stock.ts +75 -0
  17. package/src/codemods/ci-e2e-browser.ts +63 -0
  18. package/src/codemods/codemod.ts +58 -0
  19. package/src/codemods/define-error-leaf.ts +73 -0
  20. package/src/codemods/docs-ci-parts.ts +65 -0
  21. package/src/codemods/docs-gate-prose.ts +53 -0
  22. package/src/codemods/docs-island-rows.ts +31 -0
  23. package/src/codemods/docs-shipped-guards.ts +100 -0
  24. package/src/codemods/docs-test-services.ts +62 -0
  25. package/src/codemods/engine-diff.ts +104 -0
  26. package/src/codemods/engine-edits.ts +111 -0
  27. package/src/codemods/engine-fs.ts +95 -0
  28. package/src/codemods/engine.ts +191 -0
  29. package/src/codemods/format-edited-hook-3122.ts +28 -0
  30. package/src/codemods/format-edited-hook.ts +152 -0
  31. package/src/codemods/helm-alerts-objective.ts +105 -0
  32. package/src/codemods/helm-alerts-stock.ts +108 -0
  33. package/src/codemods/index.ts +56 -0
  34. package/src/codemods/metrics-probe-healthz.ts +47 -0
  35. package/src/codemods/pending.ts +36 -0
  36. package/src/codemods/repro-gitignore.ts +40 -0
  37. package/src/codemods/runtime-pin-lines.ts +109 -0
  38. package/src/codemods/runtime-pin.ts +116 -0
  39. package/src/codemods/solid-floor.ts +63 -0
  40. package/src/codemods/test-ports.ts +86 -0
  41. package/src/codemods/test-suites.ts +37 -0
  42. package/src/codemods/theme-toggle-mount-over.ts +70 -0
  43. package/src/codemods/vendored-guards.ts +186 -0
  44. package/src/codemods/verify-floor-skips.ts +88 -0
  45. package/src/codemods/verify-floor-steps.ts +90 -0
  46. package/src/doctor-advisory-floors.ts +113 -0
  47. package/src/doctor-guards.ts +39 -86
  48. package/src/doctor-superseded.ts +67 -0
  49. package/src/error-codes-doctor.ts +12 -4
  50. package/src/error-codes.ts +6 -0
  51. package/src/exercise-database.ts +7 -2
  52. package/src/generate-files.ts +6 -5
  53. package/src/guards-built-in-codes.ts +36 -0
  54. package/src/guards-built-in-refusal.ts +25 -0
  55. package/src/guards-built-in.ts +134 -0
  56. package/src/guards-materialize.ts +42 -0
  57. package/src/guards-paths.ts +37 -0
  58. package/src/guards-shipped-names.ts +38 -0
  59. package/src/guards-vendored.ts +73 -0
  60. package/src/guards.ts +90 -34
  61. package/src/index.ts +10 -0
  62. package/src/lint-findings.ts +3 -3
  63. package/src/mcp-errors.ts +11 -1
  64. package/src/measure-scope.ts +23 -3
  65. package/src/messages-repro.ts +16 -2
  66. package/src/messages-upgrade.ts +15 -0
  67. package/src/messages.ts +1 -1
  68. package/src/repro-archive-collect.ts +161 -0
  69. package/src/repro-archive-write.ts +96 -0
  70. package/src/repro-archive.ts +161 -0
  71. package/src/repro-bundle.ts +8 -16
  72. package/src/repro-errors.ts +14 -2
  73. package/src/repro-framework.ts +53 -0
  74. package/src/repro-parse.ts +87 -0
  75. package/src/repro-redact.ts +218 -0
  76. package/src/repro-scrub.ts +257 -0
  77. package/src/superseded-match.ts +87 -0
  78. package/src/superseded.ts +84 -0
  79. package/src/templates/bun-image.ts +48 -0
  80. package/src/templates/github/ci.yml.ts +1 -1
  81. package/src/templates/guard-released-forms.ts +112 -0
  82. package/src/templates/guard-runtime-pin-test.ts +54 -0
  83. package/src/templates/guard-runtime-pin.ts +189 -0
  84. package/src/templates/scaffold-claude-agents.ts +6 -6
  85. package/src/templates/scaffold-claude-commands.ts +1 -1
  86. package/src/templates/scaffold-claude-hook.ts +18 -8
  87. package/src/templates/scaffold-claude.ts +2 -2
  88. package/src/templates/scaffold-docs.ts +26 -24
  89. package/src/templates/scaffold-guards.ts +73 -39
  90. package/src/templates/scaffold-repo.ts +2 -1
  91. package/src/unthrown-codes.ts +2 -0
  92. package/src/upgrade-bun-floor.ts +4 -0
  93. package/src/upgrade-clean-tree.ts +54 -0
  94. package/src/upgrade-gate-codemods-install.ts +40 -0
  95. package/src/upgrade-gate-codemods.ts +151 -0
  96. package/src/upgrade-gate.ts +38 -6
  97. package/src/upgrade-lock.ts +118 -0
  98. package/src/upgrade-plan.ts +2 -1
  99. package/src/upgrade-report-codemods.ts +54 -0
  100. package/src/upgrade-report.ts +52 -27
  101. package/src/upgrade-signals.ts +91 -0
  102. package/src/upgrade-unfinished.ts +61 -0
  103. package/wiki/CLI-Reference.md +58 -4
  104. package/wiki/Interface-Rules.md +17 -8
  105. package/wiki/Observability.md +1 -0
  106. package/wiki/Project-Layout.md +4 -4
  107. package/wiki/Upgrading.md +5 -0
@@ -0,0 +1,63 @@
1
+ // Carries an older app's `solid-js` pins up to the advisory floor `@ultimat3/ui` now peers: every
2
+ // manifest's exact, caret or tilde pin below it is raised in its own shape, so the app resolves a
3
+ // seroval past every advisory with no `overrides`. A range the app wrote itself is reported whole.
4
+
5
+ import { SOLID_FLOOR } from '../doctor-advisory-floors';
6
+ import type { Codemod, CodemodApp, CodemodResult } from './codemod';
7
+ import { mergeResults } from './engine-edits';
8
+
9
+ const NOTHING: CodemodResult = { changed: [], skipped: [] };
10
+ const MANIFESTS = ['package.json', 'apps/*/package.json', 'packages/*/package.json'];
11
+ const DECLARED = /("solid-js"\s*:\s*")([^"]*)"/g;
12
+ const PIN = /^([~^]?)(\d+)\.\d+\.\d+$/;
13
+
14
+ type Verdict = { readonly kind: 'keep' } | { readonly kind: 'raise'; readonly to: string };
15
+
16
+ /** One declared range: kept, raised, or `undefined` when it is a shape only the app can judge. */
17
+ function judge(range: string): Verdict | undefined {
18
+ const pin = PIN.exec(range);
19
+ if (pin === null) return undefined;
20
+ const [, operator = '', major = ''] = pin;
21
+ // A later major is past the floor already; an earlier one is a migration, not a security floor.
22
+ if (major !== '1') return Number(major) > 1 ? { kind: 'keep' } : undefined;
23
+ const version = range.slice(operator.length);
24
+ return Bun.semver.order(version, SOLID_FLOOR) >= 0
25
+ ? { kind: 'keep' }
26
+ : { kind: 'raise', to: `${operator}${SOLID_FLOOR}` };
27
+ }
28
+
29
+ async function migrate(app: CodemodApp, path: string): Promise<CodemodResult> {
30
+ const source = await app.read(path);
31
+ if (source === undefined) return NOTHING;
32
+ const foreign: string[] = [];
33
+ const next = source.replace(DECLARED, (whole, head: string, range: string) => {
34
+ const verdict = judge(range);
35
+ if (verdict === undefined) {
36
+ foreign.push(range);
37
+ return whole;
38
+ }
39
+ return verdict.kind === 'raise' ? `${head}${verdict.to}"` : whole;
40
+ });
41
+ if (foreign.length > 0) {
42
+ const ranges = foreign.map((range) => `solid-js ${range}`).join(', ');
43
+ const reason = `${ranges} is the app's own range, so the file is left as it is; it must resolve solid-js ${SOLID_FLOOR} or later`;
44
+ return { changed: [], skipped: [{ path, reason }] };
45
+ }
46
+ if (next === source) return NOTHING;
47
+ await app.write(path, next);
48
+ return { changed: [path], skipped: [] };
49
+ }
50
+
51
+ export const codemod: Codemod = {
52
+ id: 'solid-floor',
53
+ // The release whose `@ultimat3/ui` first peers `solid-js ^1.9.18`, and whose scaffold pins it.
54
+ since: '31.28.0',
55
+ summary: `every solid-js pin up to ${SOLID_FLOOR}, the first release past the seroval advisories`,
56
+ async run(app) {
57
+ const found = await Promise.all(MANIFESTS.map((pattern) => app.glob(pattern)));
58
+ const paths = [...new Set(found.flat())].sort();
59
+ const results: CodemodResult[] = [];
60
+ for (const path of paths) results.push(await migrate(app, path));
61
+ return mergeResults(results);
62
+ },
63
+ };
@@ -0,0 +1,86 @@
1
+ // 31.27.0: the test stack's host ports are the app's own (its name picks an offset into each band),
2
+ // so two apps on one machine stop dialling each other's Postgres. Only a compose file and env file
3
+ // still byte-for-byte the old scaffold's move; an edited one is reported with the diff.
4
+
5
+ import type { NameSet } from '../templates/naming';
6
+ import { names } from '../templates/naming';
7
+ import {
8
+ TEST_COMPOSE_PATH,
9
+ TEST_ENV_PATH,
10
+ TEST_PORTS,
11
+ testPorts,
12
+ testServicesFiles,
13
+ } from '../templates/scaffold-test-services';
14
+ import type { Codemod, CodemodApp, CodemodResult } from './codemod';
15
+ import { unifiedDiff } from './engine-diff';
16
+ import { mergeResults, readText } from './engine-edits';
17
+
18
+ const NOTHING: CodemodResult = { changed: [], skipped: [] };
19
+
20
+ /** The compose comment the old scaffold wrote, and today's. */
21
+ const OLD_NOTE =
22
+ "# and a suite that needs a real server skips. Ports are the dev stack's plus 50000, so both run.";
23
+ const NEW_NOTE = [
24
+ "# and a suite that needs a real server skips. Ports are this app's own (its name picks",
25
+ "# them), above the dev stack's, so both stacks — and two apps — run at once.",
26
+ ].join('\n');
27
+
28
+ /** The app's name, as the old env file spells it in its database URL. */
29
+ const appName = (env: string): string | undefined =>
30
+ /^TEST_DATABASE_URL=postgres:\/\/([a-z0-9-]+):\1-test@/m.exec(env)?.[1];
31
+
32
+ /** Today's file with the old fixed ports and comment: what the old scaffold wrote for this app. */
33
+ function before(today: string, app: NameSet): string {
34
+ const ports = testPorts(app);
35
+ let text = today.replace(NEW_NOTE, () => OLD_NOTE);
36
+ for (const key of Object.keys(TEST_PORTS) as (keyof typeof TEST_PORTS)[]) {
37
+ text = text.replaceAll(
38
+ `127.0.0.1:${String(ports[key])}`,
39
+ `127.0.0.1:${String(TEST_PORTS[key])}`,
40
+ );
41
+ }
42
+ return text;
43
+ }
44
+
45
+ async function move(
46
+ app: CodemodApp,
47
+ path: string,
48
+ today: string,
49
+ name: NameSet,
50
+ ): Promise<CodemodResult> {
51
+ const file = await readText(app, path);
52
+ if (file === undefined || file.text === today) return NOTHING;
53
+ const old = before(today, name);
54
+ if (file.text === old) {
55
+ await app.write(path, file.restore(today));
56
+ return { changed: [path], skipped: [] };
57
+ }
58
+ return {
59
+ changed: [],
60
+ skipped: [
61
+ {
62
+ path,
63
+ reason:
64
+ "it is no longer the old scaffold's file byte for byte, so its ports stay: the diff is the scaffold's change, to make by hand if two apps share this machine",
65
+ diff: unifiedDiff(path, old, today),
66
+ },
67
+ ],
68
+ };
69
+ }
70
+
71
+ export const codemod: Codemod = {
72
+ id: 'test-ports',
73
+ since: '31.27.0',
74
+ summary: `${TEST_COMPOSE_PATH} and ${TEST_ENV_PATH} publish this app's own test ports, so two apps on one machine run at once`,
75
+ async run(app) {
76
+ const kebab = appName((await readText(app, TEST_ENV_PATH))?.text ?? '');
77
+ if (kebab === undefined) return NOTHING;
78
+ const name = names(kebab);
79
+ const results: CodemodResult[] = [];
80
+ for (const file of testServicesFiles(name)) {
81
+ if (typeof file.contents === 'string')
82
+ results.push(await move(app, file.path, file.contents, name));
83
+ }
84
+ return mergeResults(results);
85
+ },
86
+ };
@@ -0,0 +1,37 @@
1
+ // 31.27.0: every scaffold ships a `live` suite (the production driver against a real Postgres) and,
2
+ // where it serves a page, an `e2e` suite (the landing page in a real browser). An app that predates
3
+ // them gains each, as `x new` writes it today; one it already holds is its own.
4
+
5
+ import {
6
+ E2E_SUITE_PATH,
7
+ e2eSuiteFiles,
8
+ LIVE_SUITE_PATH,
9
+ liveSuiteFiles,
10
+ } from '../templates/scaffold-suites';
11
+ import type { Codemod, CodemodApp, CodemodResult } from './codemod';
12
+ import { mergeResults, writeIfAbsent } from './engine-edits';
13
+
14
+ const NOTHING: CodemodResult = { changed: [], skipped: [] };
15
+
16
+ /** Each suite lands beside what it drives: no db package, no live suite; no landing page, no e2e. */
17
+ const HOSTS: readonly (readonly [string, string])[] = [
18
+ [LIVE_SUITE_PATH, 'packages/db/src/index.ts'],
19
+ [E2E_SUITE_PATH, 'apps/web/site/page.tsx'],
20
+ ];
21
+
22
+ async function suite(app: CodemodApp, path: string, host: string): Promise<CodemodResult> {
23
+ if (!(await app.exists(host))) return NOTHING;
24
+ const file = [...liveSuiteFiles(), ...e2eSuiteFiles()].find((one) => one.path === path);
25
+ return typeof file?.contents === 'string' ? writeIfAbsent(app, path, file.contents) : NOTHING;
26
+ }
27
+
28
+ export const codemod: Codemod = {
29
+ id: 'test-suites',
30
+ since: '31.27.0',
31
+ summary: `the live and e2e suites every scaffold ships: ${LIVE_SUITE_PATH} and ${E2E_SUITE_PATH}`,
32
+ async run(app) {
33
+ const results: CodemodResult[] = [];
34
+ for (const [path, host] of HOSTS) results.push(await suite(app, path, host));
35
+ return mergeResults(results);
36
+ },
37
+ };
@@ -0,0 +1,70 @@
1
+ // 31.15.0: an island's mount replaces its server markup through `mountOver`, which puts it back if
2
+ // the render throws — the shipped `island-mount-clears` guard refuses `el.textContent = ''`. The
3
+ // scaffold's own theme toggle, where it stands as `x new` wrote it; the example slice is the app's.
4
+
5
+ import type { Codemod } from './codemod';
6
+ import type { SnippetEdit } from './engine-edits';
7
+ import { editSnippets } from './engine-edits';
8
+
9
+ const TOGGLE = 'apps/web/shared/theme-toggle.island.tsx';
10
+
11
+ const lines = (...text: readonly string[]): string => text.join('\n');
12
+
13
+ const UI = "import { setSolidRuntime, ThemeToggle, UiProvider } from '@ultimat3/ui';";
14
+
15
+ export const THEME_TOGGLE_EDITS: readonly SnippetEdit[] = [
16
+ { from: UI, to: lines("import { mountOver } from '@ultimat3/render/client';", UI) },
17
+ {
18
+ from: lines(
19
+ ' * namespace object keeps every export of solid-js alive in the chunk. The shell is cleared before',
20
+ " * `render`, which APPENDS — the server's copy would otherwise stay on screen beside the live one.",
21
+ ),
22
+ to: lines(
23
+ ' * namespace object keeps every export of solid-js alive in the chunk. `mountOver` clears the shell',
24
+ ' * before `render`, which APPENDS, and puts it back if the render throws: a broken toggle shows the',
25
+ " * server's copy, not a blank box, and the throw still reaches the runtime's `data-x-failed`.",
26
+ ),
27
+ optional: true,
28
+ },
29
+ {
30
+ from: lines(
31
+ " el.textContent = '';",
32
+ " // Solid's disposer, returned: the client router calls it when it navigates away, and a mount",
33
+ ' // that returns nothing is X_ISLAND_DISPOSER_MISSING.',
34
+ ' return render(',
35
+ ' () => (',
36
+ ' <UiProvider locale={props.locale}>',
37
+ ' <ThemeToggle mode="toggle" />',
38
+ ' </UiProvider>',
39
+ ' ),',
40
+ ' el,',
41
+ ' );',
42
+ ),
43
+ to: lines(
44
+ " // Solid's disposer, returned: the client router calls it when it navigates away, and a mount",
45
+ ' // that returns nothing is X_ISLAND_DISPOSER_MISSING.',
46
+ ' return mountOver(el, (root) =>',
47
+ ' render(',
48
+ ' () => (',
49
+ ' <UiProvider locale={props.locale}>',
50
+ ' <ThemeToggle mode="toggle" />',
51
+ ' </UiProvider>',
52
+ ' ),',
53
+ ' root,',
54
+ ' ),',
55
+ ' );',
56
+ ),
57
+ },
58
+ ];
59
+
60
+ export const codemod: Codemod = {
61
+ id: 'theme-toggle-mount-over',
62
+ since: '31.15.0',
63
+ summary: `${TOGGLE} mounts through mountOver: a toggle whose render throws keeps the server's copy`,
64
+ async run(app) {
65
+ // The import alone would be added to a toggle whose mount the app rewrote: both, or neither.
66
+ const held = (await app.read(TOGGLE)) ?? '';
67
+ if (!held.includes(" el.textContent = '';")) return { changed: [], skipped: [] };
68
+ return editSnippets(app, TOGGLE, THEME_TOGGLE_EDITS);
69
+ },
70
+ };
@@ -0,0 +1,186 @@
1
+ // Carries an app off vendored copies of shipped guards, once: every shipped guard runs from the
2
+ // installed framework now. An unedited copy — any form a release shipped — is deleted; one that
3
+ // differs only in severity becomes a `guards/shipped.json` row; any other edit is kept as the app's
4
+ // own guard under a new name, the shipped one off, with the reason and the diff — never lost.
5
+
6
+ import {
7
+ parseShippedConfig,
8
+ SHIPPED_GUARD_CONFIG,
9
+ SHIPPED_SEVERITY_FIELD,
10
+ type ShippedSeverity,
11
+ vendoredPath,
12
+ } from '../guards-built-in';
13
+ import { guardFormHash, sameText, shippedFormSeverity } from '../guards-vendored';
14
+ import { RELEASED_GUARD_TEST_FORMS } from '../templates/guard-released-forms';
15
+ import {
16
+ SHIPPED_GUARD_NAMES,
17
+ shippedGuardForms,
18
+ shippedGuardTest,
19
+ } from '../templates/scaffold-guards';
20
+ import { VERIFY_FLOOR_FILE } from '../verify-floor';
21
+ import { GUARD_BASELINE_FIELD } from '../verify-guard-baseline';
22
+ import type { Codemod, CodemodApp, CodemodResult } from './codemod';
23
+ import { unifiedDiff } from './engine-diff';
24
+
25
+ /** The severity line a report-only guard carries; stripped, two copies differing only there match. */
26
+ const SEVERITY_LINE = /^\s*severity:\s*'warning',\s*\n/gm;
27
+ const REPORT_ONLY = /^\s*severity:\s*'warning',\s*$/m;
28
+ const withoutSeverity = (text: string): string =>
29
+ text.replaceAll('\r\n', '\n').replaceAll(SEVERITY_LINE, '');
30
+
31
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
32
+ typeof value === 'object' && value !== null && !Array.isArray(value);
33
+
34
+ /** What one copy becomes: deleted at a severity, or kept as the app's own guard. */
35
+ type Verdict =
36
+ | { readonly kind: 'delete'; readonly severity: 'error' | 'warning' }
37
+ | { readonly kind: 'keep' };
38
+
39
+ /** The copy against every current form of its guard: exact, then exact but for severity. */
40
+ /** Every rule-file text a release shipped, by guard: `RELEASED_GUARD_FORMS`' shape. */
41
+ type ReleasedForms = Parameters<typeof shippedFormSeverity>[2];
42
+
43
+ /** The tables a run judges against: the committed ones unless a test passes its own. */
44
+ export interface ReleasedTables {
45
+ readonly forms?: ReleasedForms;
46
+ readonly tests?: Readonly<Record<string, readonly string[]>>;
47
+ }
48
+
49
+ /** The copy against every form of its guard — current or released — then exact but for severity. */
50
+ const judge = (name: string, copy: string, released: ReleasedForms): Verdict => {
51
+ const shipped = shippedFormSeverity(name, copy, released);
52
+ if (shipped !== undefined) return { kind: 'delete', severity: shipped };
53
+ const bare = withoutSeverity(copy);
54
+ if (shippedGuardForms(name).some((form) => withoutSeverity(form.source) === bare)) {
55
+ return { kind: 'delete', severity: REPORT_ONLY.test(copy) ? 'warning' : 'error' };
56
+ }
57
+ return { kind: 'keep' };
58
+ };
59
+
60
+ /** `guards/app-<name>.ts`, or the first `app-<name>-<n>` the app does not already hold. */
61
+ const freeName = async (app: CodemodApp, name: string): Promise<string> => {
62
+ for (let n = 1; ; n += 1) {
63
+ const candidate = n === 1 ? `app-${name}` : `app-${name}-${String(n)}`;
64
+ if (!(await app.exists(`guards/${candidate}.ts`))) return candidate;
65
+ }
66
+ };
67
+
68
+ /** A baseline written for the shipped name follows its rule to the new one, or it goes stale. */
69
+ const moveBaselines = async (
70
+ app: CodemodApp,
71
+ renamed: ReadonlyMap<string, string>,
72
+ ): Promise<boolean> => {
73
+ const text = await app.read(VERIFY_FLOOR_FILE);
74
+ if (text === undefined || renamed.size === 0) return false;
75
+ let floor: unknown;
76
+ try {
77
+ floor = JSON.parse(text);
78
+ } catch {
79
+ return false;
80
+ }
81
+ const baseline = isRecord(floor) ? floor[GUARD_BASELINE_FIELD] : undefined;
82
+ if (!isRecord(floor) || !isRecord(baseline)) return false;
83
+ const moved = Object.fromEntries(
84
+ Object.entries(baseline).map(([key, value]) => [renamed.get(key) ?? key, value]),
85
+ );
86
+ if (Object.keys(baseline).every((key) => !renamed.has(key))) return false;
87
+ await app.write(
88
+ VERIFY_FLOOR_FILE,
89
+ `${JSON.stringify({ ...floor, [GUARD_BASELINE_FIELD]: moved }, null, 2)}\n`,
90
+ );
91
+ return true;
92
+ };
93
+
94
+ async function run(app: CodemodApp, tables: ReleasedTables): Promise<CodemodResult> {
95
+ const changed: string[] = [];
96
+ const skipped: CodemodResult['skipped'] = [];
97
+ const configText = await app.read(SHIPPED_GUARD_CONFIG);
98
+ const parsed = configText === undefined ? undefined : parseShippedConfig(configText);
99
+ if (parsed !== undefined && parsed.problems.length > 0) {
100
+ const reason = `${SHIPPED_GUARD_CONFIG} does not parse (${parsed.problems.join('; ')}): fix it, then x upgrade again`;
101
+ return { changed, skipped: [{ path: SHIPPED_GUARD_CONFIG, reason }] };
102
+ }
103
+ const rows: Record<string, ShippedSeverity> = { ...(parsed?.severity ?? {}) };
104
+ const held = (await app.glob('guards/*.{ts,tsx}')).filter(
105
+ (path) => !/\.(?:test|d)\.tsx?$/.test(path),
106
+ );
107
+ const renamed = new Map<string, string>();
108
+ for (const name of SHIPPED_GUARD_NAMES) {
109
+ const path = vendoredPath(held, name);
110
+ const own = shippedGuardForms(name)[0]?.severity ?? 'error';
111
+ if (path === undefined) {
112
+ // A legacy app never had this guard gate it: it keeps reporting only, until the author says.
113
+ if (configText === undefined && own === 'error' && !Object.hasOwn(rows, name)) {
114
+ rows[name] = 'warning';
115
+ }
116
+ continue;
117
+ }
118
+ const copy = (await app.read(path)) ?? '';
119
+ const testPath = `guards/${name}.test.ts`;
120
+ const test = await app.read(testPath);
121
+ const verdict = judge(name, copy, tables.forms);
122
+ if (verdict.kind === 'delete') {
123
+ await app.remove(path);
124
+ changed.push(path);
125
+ if (verdict.severity !== own && !Object.hasOwn(rows, name)) rows[name] = verdict.severity;
126
+ if (test !== undefined) {
127
+ await app.remove(testPath);
128
+ changed.push(testPath);
129
+ const shipped = shippedGuardTest(name) ?? '';
130
+ const releasedTests = tables.tests ?? RELEASED_GUARD_TEST_FORMS;
131
+ const known = Object.hasOwn(releasedTests, name) ? releasedTests[name] : undefined;
132
+ // A test some release wrote is unedited; only one no release shipped can hold a case.
133
+ if (!sameText(test, shipped) && !(known ?? []).includes(guardFormHash(test))) {
134
+ skipped.push({
135
+ path: testPath,
136
+ reason: `deleted with its rule, which is the shipped one and tested by the framework now; a case you added is in the diff — carry it to a test of your own`,
137
+ diff: unifiedDiff(testPath, shipped, test),
138
+ });
139
+ }
140
+ }
141
+ continue;
142
+ }
143
+ const next = await freeName(app, name);
144
+ const nextPath = `guards/${next}${path.endsWith('.tsx') ? '.tsx' : '.ts'}`;
145
+ await app.write(nextPath, copy);
146
+ await app.remove(path);
147
+ changed.push(path, nextPath);
148
+ if (test !== undefined) {
149
+ const nextTest = `guards/${next}.test.ts`;
150
+ await app.write(nextTest, test.replaceAll(`from './${name}'`, `from './${next}'`));
151
+ await app.remove(testPath);
152
+ changed.push(testPath, nextTest);
153
+ }
154
+ rows[name] = 'off';
155
+ renamed.set(name, next);
156
+ skipped.push({
157
+ path: nextPath,
158
+ reason: `${path} is not a form of the shipped ${name} guard and not one a ${SHIPPED_GUARD_CONFIG} row can say, so it is kept as your own guard ${nextPath} and the shipped one is "off" — delete ${nextPath} and that row to take the shipped rule`,
159
+ diff: unifiedDiff(path, shippedGuardForms(name)[0]?.source ?? '', copy),
160
+ });
161
+ }
162
+ if (await moveBaselines(app, renamed)) changed.push(VERIFY_FLOOR_FILE);
163
+ // Written when absent — its presence is the opt-in — or when a row moved; never reformatted.
164
+ const sorted = Object.entries(rows).sort(([a], [b]) => (a < b ? -1 : 1));
165
+ const before = Object.entries(parsed?.severity ?? {}).sort(([a], [b]) => (a < b ? -1 : 1));
166
+ if (configText === undefined || JSON.stringify(sorted) !== JSON.stringify(before)) {
167
+ const severity = Object.fromEntries(sorted);
168
+ await app.write(
169
+ SHIPPED_GUARD_CONFIG,
170
+ `${JSON.stringify({ [SHIPPED_SEVERITY_FIELD]: severity }, null, 2)}\n`,
171
+ );
172
+ changed.push(SHIPPED_GUARD_CONFIG);
173
+ }
174
+ return { changed, skipped };
175
+ }
176
+
177
+ /** The migration over a released-forms table: the committed one, or a test's own. */
178
+ export const vendoredGuardsCodemod = (tables: ReleasedTables = {}): Codemod => ({
179
+ id: 'vendored-guards',
180
+ since: '31.28.0',
181
+ summary:
182
+ 'shipped guards run from the installed framework: unedited copies in guards/ deleted, an edit kept as a guards/shipped.json row or an app guard',
183
+ run: (app) => run(app, tables),
184
+ });
185
+
186
+ export const codemod: Codemod = vendoredGuardsCodemod();
@@ -0,0 +1,88 @@
1
+ // 31.27.0: a scaffold's x.verify.json names every gate step — required in `steps`, or excused in
2
+ // `skip` with its why — and sets `strict`. An older app gains the `skip` rows that hold for it
3
+ // (roadmap; job with no job suite; e2e with no page). `strict` is 31.28.0's (`verify-floor-steps`).
4
+
5
+ import { floorSteps } from '../templates/scaffold-verify-floor';
6
+ import { VERIFY_FLOOR_FILE } from '../verify-floor';
7
+ import type { Codemod, CodemodApp } from './codemod';
8
+
9
+ export type Floor = Record<string, unknown>;
10
+
11
+ export const isObject = (value: unknown): value is Floor =>
12
+ typeof value === 'object' && value !== null && !Array.isArray(value);
13
+
14
+ const any = async (app: CodemodApp, pattern: string): Promise<boolean> =>
15
+ (await app.glob(pattern)).length > 0;
16
+
17
+ /** What the app ships suites for, as `floorSteps` asks it: a job suite, a page to load. */
18
+ export async function floorSuites(
19
+ app: CodemodApp,
20
+ ): Promise<{ readonly jobs: boolean; readonly pages: boolean }> {
21
+ return {
22
+ jobs: await any(app, '{apps,packages}/**/*.job.test.ts'),
23
+ pages: await any(app, 'apps/*/{site,app}/**/page.tsx'),
24
+ };
25
+ }
26
+
27
+ /** The steps that cannot run in this app, each with the scaffold's own why. */
28
+ async function excused(app: CodemodApp): Promise<Readonly<Record<string, string>>> {
29
+ const { jobs, pages } = await floorSuites(app);
30
+ const why = floorSteps({ jobs: false, pages: false }).skip;
31
+ const out: Record<string, string> = {};
32
+ if (!jobs && why.job !== undefined) out['job'] = why.job;
33
+ if (!pages && why.e2e !== undefined) out['e2e'] = why.e2e;
34
+ if (!(await app.exists('docs/idea/14-roadmap.md')) && why.roadmap !== undefined) {
35
+ out['roadmap'] = why.roadmap;
36
+ }
37
+ return out;
38
+ }
39
+
40
+ /** `floor` with `skip` merged in, placed right after `steps` as the scaffold writes it. */
41
+ function withSkip(floor: Floor, skip: Readonly<Record<string, string>>): Floor {
42
+ const merged = { ...(isObject(floor['skip']) ? floor['skip'] : {}), ...skip };
43
+ const out: Floor = {};
44
+ for (const [key, value] of Object.entries(floor)) {
45
+ if (key === 'skip') continue;
46
+ out[key] = value;
47
+ if (key === 'steps') out['skip'] = merged;
48
+ }
49
+ if (!('skip' in out)) out['skip'] = merged;
50
+ return out;
51
+ }
52
+
53
+ export const renderFloor = (floor: Floor): string => `${JSON.stringify(floor, null, 2)}\n`;
54
+
55
+ export const codemod: Codemod = {
56
+ id: 'verify-floor-skips',
57
+ since: '31.27.0',
58
+ summary: `${VERIFY_FLOOR_FILE} excuses the gate steps this app cannot run (roadmap; job, e2e where it has none), each with its why`,
59
+ async run(app) {
60
+ const source = await app.read(VERIFY_FLOOR_FILE);
61
+ if (source === undefined) return { changed: [], skipped: [] };
62
+ let floor: unknown;
63
+ try {
64
+ floor = JSON.parse(source);
65
+ } catch {
66
+ floor = undefined;
67
+ }
68
+ if (!isObject(floor)) {
69
+ return {
70
+ changed: [],
71
+ skipped: [
72
+ { path: VERIFY_FLOOR_FILE, reason: 'it is not a JSON object, so no row was added to it' },
73
+ ],
74
+ };
75
+ }
76
+ const steps = Array.isArray(floor['steps']) ? floor['steps'] : [];
77
+ const held = isObject(floor['skip']) ? floor['skip'] : {};
78
+ const add = Object.fromEntries(
79
+ Object.entries(await excused(app)).filter(
80
+ ([step]) => !steps.includes(step) && !(step in held),
81
+ ),
82
+ );
83
+ const next = Object.keys(add).length === 0 ? floor : withSkip(floor, add);
84
+ if (Object.keys(add).length === 0) return { changed: [], skipped: [] };
85
+ await app.write(VERIFY_FLOOR_FILE, renderFloor(next));
86
+ return { changed: [VERIFY_FLOOR_FILE], skipped: [] };
87
+ },
88
+ };
@@ -0,0 +1,90 @@
1
+ // 31.28.0: x.verify.json floors every step the scaffold floors for an app like this one (the list
2
+ // is `floorSteps`, never restated here), so none is `X_VERIFY_STEP_UNFLOORED`; and once the floor
3
+ // names every gate step — required or excused — `strict` goes on. Short of that, `strict: false`
4
+ // is written once with a note: a decision recorded, not a question asked on every upgrade.
5
+
6
+ import { floorSteps } from '../templates/scaffold-verify-floor';
7
+ import { VERIFY_FLOOR_FILE } from '../verify-floor';
8
+ import { VERIFY_STEP_NAMES } from '../verify-step';
9
+ import type { Codemod, CodemodResult } from './codemod';
10
+ import { unifiedDiff } from './engine-diff';
11
+ import type { Floor } from './verify-floor-skips';
12
+ import { floorSuites, isObject, renderFloor } from './verify-floor-skips';
13
+
14
+ const NOTHING: CodemodResult = { changed: [], skipped: [] };
15
+
16
+ /** The scaffold's order for every step it floors, then the app's own steps in theirs. */
17
+ const ordered = (
18
+ held: readonly unknown[],
19
+ wanted: readonly string[],
20
+ added: readonly string[],
21
+ ): readonly unknown[] => [
22
+ ...wanted.filter((step) => held.includes(step) || added.includes(step)),
23
+ ...held.filter((step) => typeof step !== 'string' || !wanted.includes(step)),
24
+ ];
25
+
26
+ /** `floor` with `strict` set, placed after `skip` (or `steps`) as the scaffold writes it. */
27
+ function withStrict(floor: Floor, strict: boolean): Floor {
28
+ const anchor = 'skip' in floor ? 'skip' : 'steps';
29
+ const out: Floor = {};
30
+ for (const [key, value] of Object.entries(floor)) {
31
+ if (key === 'strict') continue;
32
+ out[key] = value;
33
+ if (key === anchor) out['strict'] = strict;
34
+ }
35
+ if (!('strict' in out)) out['strict'] = strict;
36
+ return out;
37
+ }
38
+
39
+ export const codemod: Codemod = {
40
+ id: 'verify-floor-steps',
41
+ since: '31.28.0',
42
+ summary: `${VERIFY_FLOOR_FILE} floors every step the scaffold floors, and is strict once it names the whole gate`,
43
+ async run(app) {
44
+ const source = await app.read(VERIFY_FLOOR_FILE);
45
+ if (source === undefined) return NOTHING;
46
+ let floor: unknown;
47
+ try {
48
+ floor = JSON.parse(source);
49
+ } catch {
50
+ return NOTHING;
51
+ }
52
+ // `verify-floor-skips` already reports a floor that is not a JSON object.
53
+ if (!isObject(floor) || !Array.isArray(floor['steps'])) return NOTHING;
54
+ const held: unknown[] = floor['steps'];
55
+ const skip = isObject(floor['skip']) ? floor['skip'] : {};
56
+ const wanted = floorSteps(await floorSuites(app)).steps;
57
+ const added = wanted.filter((step) => !held.includes(step) && !(step in skip));
58
+ // `steps` replaced where it stands: the app's key order kept.
59
+ let next: Floor =
60
+ added.length === 0
61
+ ? floor
62
+ : Object.fromEntries(
63
+ Object.entries(floor).map(([key, value]) => [
64
+ key,
65
+ key === 'steps' ? ordered(held, wanted, added) : value,
66
+ ]),
67
+ );
68
+ const skipped: CodemodResult['skipped'][number][] = [];
69
+ if (next['strict'] === undefined) {
70
+ const named = new Set([...(next['steps'] as unknown[]), ...Object.keys(skip)]);
71
+ const unnamed = VERIFY_STEP_NAMES.filter((step) => !named.has(step));
72
+ next = withStrict(next, unnamed.length === 0);
73
+ if (unnamed.length > 0) {
74
+ skipped.push({
75
+ path: VERIFY_FLOOR_FILE,
76
+ reason: `"strict": false recorded, once: ${unnamed.join(', ')} is in neither "steps" nor "skip", so strict would be red where those run nothing. Run x verify --json, give each its place, then set "strict": true`,
77
+ diff: unifiedDiff(
78
+ VERIFY_FLOOR_FILE,
79
+ renderFloor(next),
80
+ renderFloor(withStrict(next, true)),
81
+ ),
82
+ });
83
+ }
84
+ }
85
+ const text = renderFloor(next);
86
+ if (text === source) return { changed: [], skipped };
87
+ await app.write(VERIFY_FLOOR_FILE, text);
88
+ return { changed: [VERIFY_FLOOR_FILE], skipped };
89
+ },
90
+ };