@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
@@ -42,33 +42,35 @@ queries, jobs, MCP tools, published operations and tests it touches, each with p
42
42
  | One way | generators, not hand-rolled files: \`bunx x g resource\`, \`bunx x g action\`, \`bunx x g route\` | review |
43
43
  | Surfaces | \`site/\` is 0kb JS and may not import \`app/\`; \`shared/\` is a leaf | \`X_BOUNDARY_SITE_TO_APP\` |
44
44
  | Data | routes call actions and queries; only \`repo.ts\` touches the database | \`X_BOUNDARY_ROUTE_TO_DB\` |
45
- | Repos | a \`repo.ts\` reads through the typed handle, never a \`sql\` literal it can express; reported, not refused: an \`await\` per loop turn outside \`expectedQueryLoop('<why>', fn)\`, a bare \`.all()\` (it stops at 50 rows: say \`.limit(n)\`) | \`guards/repo-raw-sql.ts\`, \`guards/repo-await-in-loop.ts\`, \`guards/repo-unbounded.ts\` |
46
- | Fan-out | a database call per element of a list runs through \`mapBounded(rows, fn, { width })\` from \`@ultimat3/core\` — never \`Promise.all(rows.map(async …))\`, one statement per row at once; a \`// why:\` on the line admits a list bounded where it is built | \`guards/unbounded-fanout.ts\` |
47
- | Vendors | a server \`fetch(\` carries a \`signal\` in its own options — better, it is \`outbound()\` from \`@ultimat3/core/outbound\`: a deadline, the caller's signal, safe-only retry | \`guards/raw-fetch.ts\` |
48
- | Polling | an island re-reads a query on a timer with \`useQuery(ref, input, { poll: pollEvery(ms) })\` (\`@ultimat3/realtime\`), anything else with \`visibleInterval(run, ms)\` from \`@ultimat3/core/page\` — no call while the tab is hidden, none after a lost session — never a bare \`setInterval(\`; a \`// why:\` on the line admits a tick that is not a read | \`guards/raw-interval.ts\` |
49
- | Confirmation | a destructive act asks through \`ConfirmDialog\` from \`@ultimat3/ui\` — Cancel focused, a native post, stays open on a refusal — never \`confirm(\`; a \`// why:\` on the line admits a call that is not that question | \`guards/native-confirm.ts\` |
50
- | Errors | never \`throw new Error\` — declare each code once, \`defineError({ code, title, status, cause, fix })\` from \`@ultimat3/core/page\`, and throw its class; never a handwritten \`UltimateError\` subclass | \`guards/bare-error.ts\`, \`guards/error-declared.ts\` |
45
+ | Repos | a \`repo.ts\` reads through the typed handle, never a \`sql\` literal it can express; reported, not refused: an \`await\` per loop turn outside \`expectedQueryLoop('<why>', fn)\`, a bare \`.all()\` (it stops at 50 rows: say \`.limit(n)\`) | \`repo-raw-sql\`, \`repo-await-in-loop\`, \`repo-unbounded\` |
46
+ | Fan-out | a database call per element of a list runs through \`mapBounded(rows, fn, { width })\` from \`@ultimat3/core\` — never \`Promise.all(rows.map(async …))\`, one statement per row at once; a \`// why:\` on the line admits a list bounded where it is built | \`unbounded-fanout\` |
47
+ | Vendors | a server \`fetch(\` carries a \`signal\` in its own options — better, it is \`outbound()\` from \`@ultimat3/core/outbound\`: a deadline, the caller's signal, safe-only retry | \`raw-fetch\` |
48
+ | Runtime | every Bun pin — \`packageManager\`, \`.bun-version\`, CI's \`bun-version:\`, the image's \`FROM oven/bun:\` — names the version \`engines.bun\` declares, and an image builds on a digest | \`runtime-pin\` |
49
+ | Polling | an island re-reads a query on a timer with \`useQuery(ref, input, { poll: pollEvery(ms) })\` (\`@ultimat3/realtime\`), anything else with \`visibleInterval(run, ms)\` from \`@ultimat3/core/page\` — no call while the tab is hidden, none after a lost session — never a bare \`setInterval(\`; a \`// why:\` on the line admits a tick that is not a read | \`raw-interval\` |
50
+ | Confirmation | a destructive act asks through \`ConfirmDialog\` from \`@ultimat3/ui\` — Cancel focused, a native post, stays open on a refusal — never \`confirm(\`; a \`// why:\` on the line admits a call that is not that question | \`native-confirm\` |
51
+ | Errors | never \`throw new Error\` — declare each code once, \`defineError({ code, title, status, cause, fix })\` from \`@ultimat3/core/page\`, and throw its class; never a handwritten \`UltimateError\` subclass | \`bare-error\`, \`error-declared\` |
51
52
  | Money | \`{ minor, currency }\`, never a float — \`money()\` on the column | the type: \`price: 19.99\` is TS2322, \`number\` is not \`MoneyInput\` |
52
- | Time | store UTC, format with an explicit IANA time zone | \`guards/unzoned-date.ts\` |
53
- | Strings | every user-facing string goes through \`t()\` | \`guards/untranslated-string.ts\` |
54
- | Colour | semantic tokens only, never a raw hex | \`guards/raw-colour.ts\` |
55
- | Lengths | a length is a token or \`rem()\`, never a raw \`px\` | \`guards/raw-length.ts\` |
56
- | Breakpoints | a viewport query names a breakpoint rung (\`respond-up\`, \`respond-down\`, \`respond-between\`), never a width | \`guards/raw-breakpoint.ts\` |
57
- | Layers | a \`z-index\` is a named layer, never a number | \`guards/raw-z-index.ts\` |
58
- | Shadows | a shadow comes off the shadow scale, never a hand-written offset and blur | \`guards/raw-shadow.ts\` |
59
- | Timing | a duration and an easing curve come off the motion scale, never a literal | \`guards/raw-motion.ts\` |
60
- | Classes | a class a component reads off its stylesheet is one that sheet compiles | \`guards/undefined-style-class.ts\` |
61
- | Properties | a custom property a stylesheet reads is one the app declares | \`guards/undeclared-custom-property.ts\` |
62
- | Interaction | a click is answered by a control — never a \`<div onClick>\`, and never a \`role=\` where the native tag exists | \`guards/semantic-interactive.ts\` |
63
- | Focus | \`outline: none\` replaces the ring in the same rule or the one beside it, or it does not remove it | \`guards/focus-visible.ts\` |
64
- | Images | every image carries width + height or an aspect-ratio, and the priority one is never \`loading="lazy"\` | \`guards/image-dimensions.ts\` |
65
- | Motion | animate \`transform\` and \`opacity\` — never a layout property, never \`transition: all\` | \`guards/animated-layout-property.ts\` |
66
- | Islands | every \`*.island.tsx\` has a sibling \`*.island.states.ts\`, so \`bunx x shot --island\` can photograph its failures | \`guards/island-without-states.ts\` |
67
- | Island mounts | a \`mount\` replaces its server markup through \`mountOver\`, so a render that throws shows the server's HTML, not a blank box | \`guards/island-mount-clears.ts\` |
53
+ | Time | store UTC, format with an explicit IANA time zone | \`unzoned-date\` |
54
+ | Strings | every user-facing string goes through \`t()\` | \`untranslated-string\` |
55
+ | Colour | semantic tokens only, never a raw hex | \`raw-colour\` |
56
+ | Lengths | a length is a token or \`rem()\`, never a raw \`px\` | \`raw-length\` |
57
+ | Breakpoints | a viewport query names a breakpoint rung (\`respond-up\`, \`respond-down\`, \`respond-between\`), never a width | \`raw-breakpoint\` |
58
+ | Layers | a \`z-index\` is a named layer, never a number | \`raw-z-index\` |
59
+ | Shadows | a shadow comes off the shadow scale, never a hand-written offset and blur | \`raw-shadow\` |
60
+ | Timing | a duration and an easing curve come off the motion scale, never a literal | \`raw-motion\` |
61
+ | Classes | a class a component reads off its stylesheet is one that sheet compiles | \`undefined-style-class\` |
62
+ | Properties | a custom property a stylesheet reads is one the app declares | \`undeclared-custom-property\` |
63
+ | Interaction | a click is answered by a control — never a \`<div onClick>\`, and never a \`role=\` where the native tag exists | \`semantic-interactive\` |
64
+ | Focus | \`outline: none\` replaces the ring in the same rule or the one beside it, or it does not remove it | \`focus-visible\` |
65
+ | Images | every image carries width + height or an aspect-ratio, and the priority one is never \`loading="lazy"\` | \`image-dimensions\` |
66
+ | Motion | animate \`transform\` and \`opacity\` — never a layout property, never \`transition: all\` | \`animated-layout-property\` |
67
+ | Islands | every \`*.island.tsx\` has a sibling \`*.island.states.ts\`, so \`bunx x shot --island\` can photograph its failures | \`island-without-states\` |
68
+ | Island mounts | a \`mount\` replaces its server markup through \`mountOver\`, so a render that throws shows the server's HTML, not a blank box | \`island-mount-clears\` |
68
69
  | Size | one file, one job — ${LINE_CEILING} lines of reviewable logic, and split past it | \`X_FILE_TOO_LONG\` |
69
70
 
70
- \`guards/\` is yours: each file is one rule, discovered by \`bunx x verify\` and run inside its
71
- \`boundaries\` step. Delete one to drop the rule, and \`bunx x g guard <name>\` writes the next.
71
+ Each lowercase name is a guard the framework ships, run on \`bunx x verify\`'s \`boundaries\` step
72
+ from the installed version. \`guards/shipped.json\` sets one's severity (\`"warning"\`, \`"off"\`);
73
+ \`bunx x g guard <name>\` writes this app's own into \`guards/\`.
72
74
 
73
75
  The last five rows are about what this app is like to USE, and each is decidable from the file
74
76
  alone — which is why they are those five and not the many that are not. A role is a promise:
@@ -1,4 +1,4 @@
1
- // The `guards/` directory `x new` writes, and the one list that names every guard in it.
1
+ // The one list that names every guard the framework ships, and what `x new` writes into `guards/`.
2
2
  //
3
3
  // `x new` shipped ZERO guards while the `AGENTS.md` it writes stated nine non-negotiables — five of
4
4
  // which nothing enforced, each measured green on `x verify` in a scaffolded app. The mechanism was
@@ -29,6 +29,7 @@
29
29
  // until the apps are clean of it, and a `.all()` that says no bound — failing the gate in an app
30
30
  // scaffolded from 31.23 on, while an older app keeps the report-only copy it was given.
31
31
 
32
+ import { SHIPPED_GUARD_NAMES as NAMES, type ShippedGuardName } from '../guards-shipped-names';
32
33
  import { animatedLayoutPropertyGuardFiles } from './guard-animated-layout-property';
33
34
  import { bareErrorGuardFiles } from './guard-bare-error';
34
35
  import { errorDeclaredGuardFiles } from './guard-error-declared';
@@ -48,6 +49,7 @@ import { rawZIndexGuardFiles } from './guard-raw-z-index';
48
49
  import { repoAwaitInLoopGuardFiles } from './guard-repo-await-in-loop';
49
50
  import { repoRawSqlGuardFiles } from './guard-repo-raw-sql';
50
51
  import { repoUnboundedGuardFiles } from './guard-repo-unbounded';
52
+ import { runtimePinGuardFiles } from './guard-runtime-pin';
51
53
  import { semanticInteractiveGuardFiles } from './guard-semantic-interactive';
52
54
  import { unboundedFanoutGuardFiles } from './guard-unbounded-fanout';
53
55
  import { undeclaredCustomPropertyGuardFiles } from './guard-undeclared-custom-property';
@@ -57,48 +59,49 @@ import { unzonedDateGuardFiles } from './guard-unzoned-date';
57
59
  import type { GeneratedFile } from './naming';
58
60
 
59
61
  /**
60
- * Every guard the framework ships, by the name its file carries — the ONE list. `x new` writes all
61
- * of them (`scaffoldGuardFiles`), `x g guard <name>` writes the one it is asked for by name
62
- * (`shippedGuardFiles`), and `x doctor` names the ones an app does not have. Sorted, so the three
63
- * agree on an order. A new shipped guard is one module beside these and one row here.
62
+ * Every guard the framework ships, keyed by the ONE list of names (`guards-shipped-names.ts`, a
63
+ * leaf the serving graph may read): a `Record`, so tsc refuses a name without its module and a
64
+ * module without its name. The `boundaries` step runs each from the installed framework; a new
65
+ * shipped guard is one module beside these, one name there and one row here.
64
66
  */
65
- const SHIPPED: readonly (readonly [string, () => readonly GeneratedFile[]])[] = [
66
- ['animated-layout-property', animatedLayoutPropertyGuardFiles],
67
- ['bare-error', bareErrorGuardFiles],
68
- ['error-declared', errorDeclaredGuardFiles],
69
- ['focus-visible', focusVisibleGuardFiles],
70
- ['image-dimensions', imageDimensionsGuardFiles],
71
- ['island-mount-clears', islandMountClearsGuardFiles],
72
- ['island-without-states', islandWithoutStatesGuardFiles],
73
- ['native-confirm', nativeConfirmGuardFiles],
74
- ['raw-breakpoint', rawBreakpointGuardFiles],
75
- ['raw-colour', rawColourGuardFiles],
76
- ['raw-fetch', rawFetchGuardFiles],
77
- ['raw-interval', rawIntervalGuardFiles],
78
- ['raw-length', rawLengthGuardFiles],
79
- ['raw-motion', rawMotionGuardFiles],
80
- ['raw-shadow', rawShadowGuardFiles],
81
- ['raw-z-index', rawZIndexGuardFiles],
82
- ['repo-await-in-loop', repoAwaitInLoopGuardFiles],
83
- ['repo-raw-sql', repoRawSqlGuardFiles],
84
- ['repo-unbounded', () => repoUnboundedGuardFiles('error')],
85
- ['semantic-interactive', semanticInteractiveGuardFiles],
86
- ['unbounded-fanout', unboundedFanoutGuardFiles],
87
- ['undeclared-custom-property', undeclaredCustomPropertyGuardFiles],
88
- ['undefined-style-class', undefinedStyleClassGuardFiles],
89
- ['untranslated-string', untranslatedStringGuardFiles],
90
- ['unzoned-date', unzonedDateGuardFiles],
91
- ];
67
+ const SHIPPED: Readonly<Record<ShippedGuardName, () => readonly GeneratedFile[]>> = {
68
+ 'animated-layout-property': animatedLayoutPropertyGuardFiles,
69
+ 'bare-error': bareErrorGuardFiles,
70
+ 'error-declared': errorDeclaredGuardFiles,
71
+ 'focus-visible': focusVisibleGuardFiles,
72
+ 'image-dimensions': imageDimensionsGuardFiles,
73
+ 'island-mount-clears': islandMountClearsGuardFiles,
74
+ 'island-without-states': islandWithoutStatesGuardFiles,
75
+ 'native-confirm': nativeConfirmGuardFiles,
76
+ 'raw-breakpoint': rawBreakpointGuardFiles,
77
+ 'raw-colour': rawColourGuardFiles,
78
+ 'raw-fetch': rawFetchGuardFiles,
79
+ 'raw-interval': rawIntervalGuardFiles,
80
+ 'raw-length': rawLengthGuardFiles,
81
+ 'raw-motion': rawMotionGuardFiles,
82
+ 'raw-shadow': rawShadowGuardFiles,
83
+ 'raw-z-index': rawZIndexGuardFiles,
84
+ 'repo-await-in-loop': repoAwaitInLoopGuardFiles,
85
+ 'repo-raw-sql': repoRawSqlGuardFiles,
86
+ 'repo-unbounded': () => repoUnboundedGuardFiles('error'),
87
+ 'runtime-pin': runtimePinGuardFiles,
88
+ 'semantic-interactive': semanticInteractiveGuardFiles,
89
+ 'unbounded-fanout': unboundedFanoutGuardFiles,
90
+ 'undeclared-custom-property': undeclaredCustomPropertyGuardFiles,
91
+ 'undefined-style-class': undefinedStyleClassGuardFiles,
92
+ 'untranslated-string': untranslatedStringGuardFiles,
93
+ 'unzoned-date': unzonedDateGuardFiles,
94
+ };
92
95
 
93
96
  /** The names, in the order every list of them is shown. */
94
- export const SHIPPED_GUARD_NAMES: readonly string[] = SHIPPED.map(([name]) => name);
97
+ export const SHIPPED_GUARD_NAMES: readonly string[] = NAMES;
95
98
 
96
99
  /**
97
100
  * The shipped guard of that name with its test, or `undefined` when the name is not one — which
98
101
  * is an app's own convention, and `x g guard` then writes the blank template instead.
99
102
  */
100
103
  export const shippedGuardFiles = (name: string): readonly GeneratedFile[] | undefined =>
101
- SHIPPED.find(([shipped]) => shipped === name)?.[1]();
104
+ (Object.hasOwn(SHIPPED, name) ? SHIPPED[name as ShippedGuardName] : undefined)?.();
102
105
 
103
106
  /**
104
107
  * The current text of a shipped guard's rule file (`guards/<name>.ts`), or `undefined` when the
@@ -134,10 +137,41 @@ export const shippedGuardSources = (name: string): readonly string[] => {
134
137
  return typeof earlier?.contents === 'string' ? [current, earlier.contents] : [current];
135
138
  };
136
139
 
140
+ /** A rule-file text a shipped guard has been emitted as, and how that form reports. */
141
+ export interface ShippedGuardForm {
142
+ readonly source: string;
143
+ readonly severity: 'error' | 'warning';
144
+ }
145
+
146
+ /** `severity: 'warning',` on a line of its own: the one spelling a shipped template emits. */
147
+ const REPORT_ONLY = /^\s*severity:\s*'warning',\s*$/m;
148
+
149
+ /** Whether a guard's rule-file text reports only. */
150
+ export const reportOnlyForm = (source: string): boolean => REPORT_ONLY.test(source);
151
+
152
+ /**
153
+ * Every current form of a shipped guard with its severity, the template first — what the
154
+ * `vendored-guards` codemod matches an app's copy against. Empty when the name was never shipped.
155
+ */
156
+ export const shippedGuardForms = (name: string): readonly ShippedGuardForm[] =>
157
+ shippedGuardSources(name).map((source) => ({
158
+ source,
159
+ severity: reportOnlyForm(source) ? 'warning' : 'error',
160
+ }));
161
+
162
+ /** The current text of a shipped guard's test (`guards/<name>.test.ts`), or `undefined`. */
163
+ export const shippedGuardTest = (name: string): string | undefined => {
164
+ const contents = shippedGuardFiles(name)?.find(
165
+ (file) => file.path === `guards/${name}.test.ts`,
166
+ )?.contents;
167
+ return typeof contents === 'string' ? contents : undefined;
168
+ };
169
+
137
170
  /**
138
- * Every guard `x new` ships, each with its test. One module per guard, because an app deletes a
139
- * rule it does not want by deleting one file — and a guard the app then writes for itself is
140
- * `x g guard <name>`, the same shape.
171
+ * What `x new` writes into `guards/`: no guard at all — every shipped one runs from the installed
172
+ * framework (`guards-built-in.ts`) — only `guards/shipped.json`, whose presence opts the app into
173
+ * that and whose rows are its severities. The app's own guards join it from `x g guard <name>`.
141
174
  */
142
- export const scaffoldGuardFiles = (): readonly GeneratedFile[] =>
143
- SHIPPED.flatMap(([, files]) => files());
175
+ export const scaffoldGuardFiles = (): readonly GeneratedFile[] => [
176
+ { path: 'guards/shipped.json', contents: '{\n "severity": {}\n}\n' },
177
+ ];
@@ -48,7 +48,7 @@ export const TYPESCRIPT_VERSION = '^7.0.2';
48
48
  * that installed an older runtime than the compiler targets drifted as a buried literal (1.9.14
49
49
  * beside the repository's 1.9.15). `scaffold-repo.test.ts` holds it equal to the root manifest's.
50
50
  */
51
- const SOLID_VERSION = '1.9.17';
51
+ const SOLID_VERSION = '1.9.18';
52
52
 
53
53
  // `engines.bun` is `REQUIRED_BUN`, the floor the SHIPPED `x` enforces
54
54
  // (`packages/cli/src/app-root.ts`), and not a second literal. It was one: `>=1.3.0`, a whole minor
@@ -356,6 +356,7 @@ packages/*/dist/
356
356
  /coverage/
357
357
  playwright-report/
358
358
  test-results/
359
+ repro/bundle-*.json
359
360
  `;
360
361
 
361
362
  // Values, not declarations — the declaration is `envSchema` and `.env.example` is its projection.
@@ -23,4 +23,6 @@ export const UNTHROWN_CODES: ReadonlySet<string> = new Set([
23
23
  'X_PWA_SYNC_INCOMPLETE',
24
24
  // 24.0.0: `x test --worker` was deleted; `x verify --only unit --shard i/n` is the one split.
25
25
  'X_TEST_SHARD_FAILED',
26
+ // 31.28.0: shipped guards run built in, so none is ever missing (X_GUARD_VENDORED names copies).
27
+ 'X_SHIPPED_GUARD_MISSING',
26
28
  ]);
@@ -4,6 +4,7 @@
4
4
 
5
5
  // why: Bun exposes no basename primitive.
6
6
  import { basename } from 'node:path';
7
+ import { scaffoldDigestPatch } from './templates/bun-image';
7
8
 
8
9
  export interface BunEdit {
9
10
  readonly path: string;
@@ -181,6 +182,9 @@ function editLine(input: {
181
182
  const parts = TAG.exec(tag);
182
183
  const version = parts?.[1];
183
184
  if (digest !== undefined) {
185
+ // A digest `x new` wrote holds a patch the framework knows, so the line says enough after all.
186
+ const known = scaffoldDigestPatch(digest.slice(1));
187
+ if (known !== undefined && !isBelow(known, floor)) return line;
184
188
  const inspect = `by hand (docker buildx imagetools inspect oven/bun:${floor}-alpine)`;
185
189
  if (version === undefined || isBelow(version, floor)) {
186
190
  return listed(
@@ -0,0 +1,54 @@
1
+ // `x upgrade`'s first refusal: a hop is one reviewable commit, so the tree must be clean — its own
2
+ // lock and record aside. When a stopped hop's record is there, the dirty tree IS that hop, and the
3
+ // fix is to stash it: committing half a hop is how a broken tree gets reviewed as a finished one.
4
+
5
+ // why: Bun exposes no path-join primitive; the state files are joined onto the app root.
6
+ import { join } from 'node:path';
7
+ import { UltimateError } from '@ultimat3/core';
8
+ import type { Runner } from './exec';
9
+ import { posixRelative } from './posix-path';
10
+ import { UPGRADE_LOCK_FILE } from './upgrade-lock';
11
+ import type { UnfinishedHop } from './upgrade-unfinished';
12
+ import { UNFINISHED_FILE } from './upgrade-unfinished';
13
+
14
+ /** The repository's root, or the refusal: git is the only record of where the walk stands. */
15
+ export async function requireCleanTree(
16
+ runner: Runner,
17
+ root: string,
18
+ unfinished: UnfinishedHop | undefined,
19
+ ): Promise<string> {
20
+ const top = await runner(['git', 'rev-parse', '--show-toplevel'], { cwd: root });
21
+ if (!top.ok) {
22
+ throw new UltimateError({
23
+ code: 'X_UPGRADE_DIRTY_TREE',
24
+ cause: `${root} is not a git repository, and a hop has to be one commit you can review or undo`,
25
+ fix: 'git init && git add -A && git commit -m "before x upgrade" # then: x upgrade --json',
26
+ });
27
+ }
28
+ const repo = top.stdout.trim();
29
+ // Every untracked file by name, so this run's own lock and record — in an `.x/` a repository
30
+ // with no app may not ignore — are told apart from an author's change.
31
+ const own = new Set(
32
+ [UPGRADE_LOCK_FILE, UNFINISHED_FILE].map((file) => posixRelative(repo, join(root, file))),
33
+ );
34
+ const status = await runner(['git', 'status', '--porcelain', '--untracked-files=all'], {
35
+ cwd: root,
36
+ });
37
+ const changes = status.stdout
38
+ .split('\n')
39
+ .filter((line) => line.trim().length > 0 && !own.has(line.slice(3)));
40
+ if (status.ok && changes.length === 0) return repo;
41
+ const listed = changes.slice(0, 5).join('; ');
42
+ if (unfinished !== undefined) {
43
+ throw new UltimateError({
44
+ code: 'X_UPGRADE_DIRTY_TREE',
45
+ cause: `an x upgrade from ${unfinished.from} to ${unfinished.to} stopped after writing its pins (${UNFINISHED_FILE}, started ${unfinished.startedAt || 'at an unknown time'}), and its ${String(changes.length)} uncommitted change(s) are that half-finished hop: ${listed}`,
46
+ fix: 'git stash push --include-untracked # sets the half hop aside; then: x upgrade --json',
47
+ });
48
+ }
49
+ throw new UltimateError({
50
+ code: 'X_UPGRADE_DIRTY_TREE',
51
+ cause: `${String(changes.length)} uncommitted change(s), and a hop has to be one reviewable commit: ${listed}`,
52
+ fix: 'git status --short # then commit or stash, and re-run: x upgrade --json',
53
+ });
54
+ }
@@ -0,0 +1,40 @@
1
+ // After codemods, the install they may owe: every `package.json` of the app read before and after,
2
+ // byte for byte — never a codemod's own report, which an installed CLI may under-state — and one
3
+ // `bun install` when any moved, so bun.lock and node_modules follow before anything reads them.
4
+
5
+ import { UltimateError } from '@ultimat3/core';
6
+ import type { Runner } from './exec';
7
+ import { execOutput } from './exec';
8
+
9
+ const MANIFESTS = new Bun.Glob('**/package.json');
10
+
11
+ /** Every `package.json` under the app root (none under `node_modules`), path to bytes. */
12
+ export async function manifestSnapshot(root: string): Promise<ReadonlyMap<string, string>> {
13
+ const out = new Map<string, string>();
14
+ for await (const path of MANIFESTS.scan({ cwd: root, dot: false })) {
15
+ const posix = path.replaceAll('\\', '/');
16
+ if (posix.split('/').includes('node_modules')) continue;
17
+ out.set(posix, await Bun.file(`${root}/${posix}`).text());
18
+ }
19
+ return out;
20
+ }
21
+
22
+ const moved = (before: ReadonlyMap<string, string>, after: ReadonlyMap<string, string>): boolean =>
23
+ before.size !== after.size || [...after].some(([path, text]) => before.get(path) !== text);
24
+
25
+ /** `bun install` when a manifest moved since `before`; true when it ran. */
26
+ export async function reinstallIfMoved(input: {
27
+ readonly runner: Runner;
28
+ readonly root: string;
29
+ readonly to: string;
30
+ readonly before: ReadonlyMap<string, string>;
31
+ }): Promise<boolean> {
32
+ if (!moved(input.before, await manifestSnapshot(input.root))) return false;
33
+ const result = await input.runner([process.execPath, 'install'], { cwd: input.root });
34
+ if (result.ok) return true;
35
+ throw new UltimateError({
36
+ code: 'X_UPGRADE_INSTALL_FAILED',
37
+ cause: `bun install exited ${String(result.code)} after the ${input.to} codemods moved a package.json: ${execOutput(result).slice(-800) || 'no output'}`,
38
+ fix: 'git diff -- "*package.json" # the codemods\' edits; fix what the cause names, then: bun install && x upgrade --json',
39
+ });
40
+ }
@@ -0,0 +1,151 @@
1
+ // A hop's codemods, applied by the CLI the hop just installed (`x upgrade codemods`): that CLI holds
2
+ // the target release's list, which this one may predate. An installed CLI with no such subcommand
3
+ // (one older than the engine) answers no document; this CLI applies its own list instead.
4
+
5
+ // why: Bun exposes no path-join primitive; the installed bin is assembled from the app root.
6
+ import { join } from 'node:path';
7
+ import { t } from '@ultimat3/schema';
8
+ import { CODEMODS } from './codemods';
9
+ import type { CodemodsReport } from './codemods/engine';
10
+ import { runCodemods } from './codemods/engine';
11
+ import { fsCodemodApp } from './codemods/engine-fs';
12
+ import { supersededFindings } from './doctor-superseded';
13
+ import type { ExecResult, Runner } from './exec';
14
+ import { LOCAL_CLI_BIN } from './local-cli';
15
+ import type { Finding } from './output';
16
+ import { documentIn } from './upgrade-document';
17
+ import { manifestSnapshot, reinstallIfMoved } from './upgrade-gate-codemods-install';
18
+ import type { HopCodemods } from './upgrade-report-codemods';
19
+
20
+ const SKIP = t.object({ path: t.string, reason: t.string, diff: t.optional(t.string) });
21
+ const OUTCOME = t.object({
22
+ id: t.string,
23
+ since: t.string,
24
+ summary: t.string,
25
+ changed: t.array(t.string),
26
+ skipped: t.array(SKIP),
27
+ });
28
+ const DOCUMENT = t.object({
29
+ data: t.object({
30
+ codemods: t.object({
31
+ from: t.string,
32
+ to: t.string,
33
+ dryRun: t.boolean,
34
+ applied: t.array(OUTCOME),
35
+ }),
36
+ }),
37
+ });
38
+
39
+ /** The installed CLI's report, or undefined when it answered none this one can read. */
40
+ export function readCodemods(result: ExecResult): CodemodsReport | undefined {
41
+ const parsed = DOCUMENT.safeParse(documentIn(result.stdout));
42
+ if (!result.ok || parsed.issues !== undefined) return undefined;
43
+ return (parsed.value as { readonly data: { readonly codemods: CodemodsReport } }).data.codemods;
44
+ }
45
+
46
+ /**
47
+ * The codes an installed CLI with no `x upgrade codemods` answers: an unknown flag or subcommand,
48
+ * an unknown command. Only those leave the span to this CLI; any other failure is the hop's.
49
+ */
50
+ const NO_SUBCOMMAND = new Set(['X_CLI_BAD_FLAG', 'X_CLI_UNKNOWN_COMMAND', 'X_NOT_IMPLEMENTED']);
51
+
52
+ const FAILURE = t.object({
53
+ findings: t.array(t.object({ code: t.string, cause: t.string, fix: t.string })),
54
+ });
55
+
56
+ /** The installed CLI's own failure, when it is one: undefined when it simply lacks the subcommand. */
57
+ function failureOf(result: ExecResult): HopCodemods['failure'] {
58
+ const parsed = FAILURE.safeParse(documentIn(result.stdout));
59
+ if (parsed.issues !== undefined) return undefined;
60
+ const [first] = (parsed.value as { readonly findings: NonNullable<HopCodemods['failure']>[] })
61
+ .findings;
62
+ return first === undefined || NO_SUBCOMMAND.has(first.code) ? undefined : first;
63
+ }
64
+
65
+ /**
66
+ * The span's codemods, by the installed CLI (or this one, only when that one lacks the
67
+ * subcommand), then a second `bun install` when any `package.json` moved — `reinstalled: true`.
68
+ */
69
+ export async function applyHopCodemods(input: {
70
+ readonly runner: Runner;
71
+ readonly root: string;
72
+ readonly from: string;
73
+ readonly to: string;
74
+ }): Promise<HopCodemods> {
75
+ const { runner, root, from, to } = input;
76
+ const before = await manifestSnapshot(root);
77
+ const result = await runner(
78
+ [
79
+ process.execPath,
80
+ join(root, LOCAL_CLI_BIN),
81
+ 'upgrade',
82
+ 'codemods',
83
+ '--from',
84
+ from,
85
+ '--to',
86
+ to,
87
+ '--json',
88
+ ],
89
+ { cwd: root },
90
+ );
91
+ const answered = readCodemods(result);
92
+ const failure = answered === undefined ? failureOf(result) : undefined;
93
+ if (failure !== undefined) {
94
+ return { from, to, dryRun: false, applied: [], source: 'installed', failure };
95
+ }
96
+ const report: HopCodemods =
97
+ answered !== undefined
98
+ ? { ...answered, source: 'installed' }
99
+ : {
100
+ ...(await runCodemods({
101
+ app: fsCodemodApp(root),
102
+ codemods: CODEMODS,
103
+ from,
104
+ to,
105
+ dryRun: false,
106
+ })),
107
+ source: 'driver',
108
+ };
109
+ return (await reinstallIfMoved({ runner, root, to, before }))
110
+ ? { ...report, reinstalled: true }
111
+ : report;
112
+ }
113
+
114
+ /**
115
+ * `x upgrade --dry-run`'s view: this CLI's codemods over the span, written nowhere, and the
116
+ * superseded workarounds the tree holds now. The hop itself applies the installed release's list.
117
+ */
118
+ export async function previewCodemods(
119
+ root: string,
120
+ from: string,
121
+ to: string,
122
+ ): Promise<{ readonly codemods: HopCodemods; readonly superseded: readonly Finding[] }> {
123
+ const own = await runCodemods({
124
+ app: fsCodemodApp(root),
125
+ codemods: CODEMODS,
126
+ from,
127
+ to,
128
+ dryRun: true,
129
+ });
130
+ return { codemods: { ...own, source: 'driver' }, superseded: await supersededFindings(root) };
131
+ }
132
+
133
+ /** Below every release: an app already at its target reruns every codemod, which are idempotent. */
134
+ export const EVERY_RELEASE = '0.0.0';
135
+
136
+ /**
137
+ * No version moves, and still no copy of an old template stays: every codemod up to the release
138
+ * the app is on, through the installed CLI as a hop would (a dry run previews this CLI's list).
139
+ * Each is idempotent, so one already applied is a run that changes nothing.
140
+ */
141
+ export async function atTargetCodemods(input: {
142
+ readonly runner: Runner;
143
+ readonly root: string;
144
+ readonly to: string;
145
+ readonly dryRun: boolean;
146
+ }): Promise<{ readonly codemods: HopCodemods; readonly superseded: readonly Finding[] }> {
147
+ const { runner, root, to } = input;
148
+ if (input.dryRun) return previewCodemods(root, EVERY_RELEASE, to);
149
+ const codemods = await applyHopCodemods({ runner, root, from: EVERY_RELEASE, to });
150
+ return { codemods, superseded: await supersededFindings(root) };
151
+ }
@@ -1,11 +1,12 @@
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.
1
+ // A hop's gate, run by the CLI the hop just installed: codemods, manifest, doctor, missing guards,
2
+ // a Bun-floor hop's coverage, exercise, verify (`upgrade-gate-codemods.ts`, `upgrade-guards.ts`).
3
+ // Never in this process: the installed CLI may be majors older, so each answer is read as a
4
+ // foreign document (`local-cli.ts`), 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
+ import { supersededFindings } from './doctor-superseded';
9
10
  import type { ExecResult, Runner } from './exec';
10
11
  import { execOutput } from './exec';
11
12
  import { exerciseReportStamp } from './exercise-floor-report';
@@ -15,9 +16,11 @@ import { rebaselineCoverage, statedCoverage } from './upgrade-coverage';
15
16
  import { documentIn } from './upgrade-document';
16
17
  import type { HopExerciseFloor } from './upgrade-exercise-floor';
17
18
  import { ratchetExerciseFloor } from './upgrade-exercise-floor';
19
+ import { applyHopCodemods } from './upgrade-gate-codemods';
18
20
  import type { BaselinedGuard, WithheldGuard } from './upgrade-guards';
19
21
  import { installMissingGuards } from './upgrade-guards';
20
22
  import { parseJson } from './upgrade-registry';
23
+ import type { HopCodemods } from './upgrade-report-codemods';
21
24
 
22
25
  // Where it always was: `verify-exercise.ts` and `verify-budgets-build.ts` read it from here.
23
26
  export { documentIn } from './upgrade-document';
@@ -120,6 +123,10 @@ export interface HopExercise {
120
123
  }
121
124
 
122
125
  export interface HopGate {
126
+ /** The codemods the hop applied before anything below judged the tree; null when none were asked. */
127
+ readonly codemods?: HopCodemods | null;
128
+ /** Workarounds the hop's framework made unnecessary, read after the codemods: warnings, never red. */
129
+ readonly superseded?: readonly GateFinding[];
123
130
  readonly manifest: { readonly ok: boolean; readonly findings: readonly GateFinding[] };
124
131
  /**
125
132
  * The installed `x doctor`'s `data.warnings[]`: never red on this major, the next one's red —
@@ -225,7 +232,14 @@ const readGuards = (doctor: DoctorDocument['data']): HopGuards => {
225
232
  };
226
233
  };
227
234
 
228
- export type HopStage = 'manifest' | 'doctor' | 'guards' | 'coverage' | 'exercise' | 'verify';
235
+ export type HopStage =
236
+ | 'codemods'
237
+ | 'manifest'
238
+ | 'doctor'
239
+ | 'guards'
240
+ | 'coverage'
241
+ | 'exercise'
242
+ | 'verify';
229
243
 
230
244
  /**
231
245
  * The gate, in order, each stage told apart by `onStage` so a long gate is not a long silence.
@@ -238,10 +252,18 @@ export async function runHopGate(input: {
238
252
  readonly onStage: (stage: HopStage) => void;
239
253
  /** Present when the hop moved the Bun floor: what the coverage rebaseline's `why` says. */
240
254
  readonly bunMoved?: CoverageRebaseline;
255
+ /** The span whose codemods run first, so every later stage judges the carried-across tree. */
256
+ readonly codemods?: { readonly from: string; readonly to: string };
241
257
  }): Promise<HopGate> {
242
258
  const { runner, root, onStage } = input;
243
259
  const installed = (args: readonly string[]): Promise<ExecResult> =>
244
260
  runner([process.execPath, join(root, LOCAL_CLI_BIN), ...args], { cwd: root });
261
+ let codemods: HopCodemods | null = null;
262
+ if (input.codemods !== undefined) {
263
+ onStage('codemods');
264
+ codemods = await applyHopCodemods({ runner, root, ...input.codemods });
265
+ }
266
+ const superseded = (await supersededFindings(root)).map(pick);
245
267
  onStage('manifest');
246
268
  const manifest = readManifest(await installed(['manifest', '--json']));
247
269
  onStage('doctor');
@@ -273,7 +295,17 @@ export async function runHopGate(input: {
273
295
  const exerciseFloor = await ratchetExerciseFloor(root, stamp);
274
296
  onStage('verify');
275
297
  const verify = readVerify(await installed(['verify', '--json']));
276
- return { manifest, doctorWarnings, guards, coverage, exercise, exerciseFloor, verify };
298
+ return {
299
+ codemods,
300
+ superseded,
301
+ manifest,
302
+ doctorWarnings,
303
+ guards,
304
+ coverage,
305
+ exercise,
306
+ exerciseFloor,
307
+ verify,
308
+ };
277
309
  }
278
310
 
279
311
  /** What a repository with no app can still be asked, in the order an author would run them. */