@ultimat3/cli 31.14.0 → 31.16.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 (69) hide show
  1. package/CLAUDE.md +1 -1
  2. package/README.md +3 -2
  3. package/package.json +29 -29
  4. package/src/budgets-requests.ts +37 -0
  5. package/src/budgets.ts +20 -1
  6. package/src/cmd-doctor.ts +47 -37
  7. package/src/cmd-exercise.ts +14 -1
  8. package/src/cmd-upgrade.ts +19 -2
  9. package/src/coverage-floor.ts +2 -2
  10. package/src/dev-boot.ts +2 -2
  11. package/src/dev-route-table.ts +5 -9
  12. package/src/doctor-env-reserved.ts +111 -0
  13. package/src/doctor-floor.ts +62 -0
  14. package/src/doctor-pins.ts +101 -0
  15. package/src/doctor-probe.ts +21 -1
  16. package/src/doctor-row-security.ts +119 -4
  17. package/src/doctor-warnings.ts +55 -0
  18. package/src/document-options.ts +0 -7
  19. package/src/error-codes-doctor.ts +24 -0
  20. package/src/error-codes.ts +5 -0
  21. package/src/exercise-floor-report.ts +138 -0
  22. package/src/exercise-floor-verdict.ts +98 -0
  23. package/src/exercise-floor.ts +158 -0
  24. package/src/island-bundle.ts +52 -12
  25. package/src/island-disposer.ts +1 -1
  26. package/src/island-group-cache.ts +4 -0
  27. package/src/island-link-check.ts +73 -0
  28. package/src/island-vendor.ts +183 -0
  29. package/src/mcp-errors.ts +11 -1
  30. package/src/messages-upgrade.ts +13 -0
  31. package/src/messages.ts +3 -0
  32. package/src/prerender.ts +7 -7
  33. package/src/route-islands-preload.ts +54 -11
  34. package/src/runtime-admin.ts +2 -4
  35. package/src/runtime-render-document.ts +34 -13
  36. package/src/runtime-render.ts +58 -30
  37. package/src/serve-web.ts +8 -11
  38. package/src/static-images.ts +25 -4
  39. package/src/static-precompress.ts +57 -0
  40. package/src/style-bundle.ts +28 -6
  41. package/src/templates/guard-island-mount-clears.ts +151 -0
  42. package/src/templates/island.ts +8 -7
  43. package/src/templates/resource-form-island.ts +12 -9
  44. package/src/templates/scaffold-docs.ts +1 -0
  45. package/src/templates/scaffold-guards.ts +4 -1
  46. package/src/templates/scaffold-shell.ts +12 -9
  47. package/src/templates/scaffold-verify-floor.ts +4 -0
  48. package/src/test-dotenv.ts +15 -2
  49. package/src/theme-brand.ts +18 -20
  50. package/src/upgrade-coverage.ts +109 -0
  51. package/src/upgrade-document.ts +18 -0
  52. package/src/upgrade-exercise-floor.ts +53 -0
  53. package/src/upgrade-gate.ts +68 -25
  54. package/src/upgrade-guards.ts +159 -0
  55. package/src/upgrade-report.ts +29 -1
  56. package/src/verify-checks.ts +3 -1
  57. package/src/verify-floor.ts +13 -0
  58. package/wiki/CLI-Reference.md +26 -3
  59. package/wiki/Client-Data.md +52 -0
  60. package/wiki/Configuration.md +17 -0
  61. package/wiki/MCP-And-AI.md +42 -1
  62. package/wiki/Notify.md +6 -0
  63. package/wiki/PWA-And-Offline.md +11 -0
  64. package/wiki/Realtime.md +4 -3
  65. package/wiki/SEO.md +1 -1
  66. package/wiki/Static-Assets.md +30 -3
  67. package/wiki/Testing.md +64 -2
  68. package/wiki/Theming.md +6 -6
  69. package/wiki/Upgrading.md +11 -0
@@ -0,0 +1,158 @@
1
+ // The `exercise` key of `x.verify.json`: how many reached primitives the pass may leave `unproven`,
2
+ // as a ratio of the reached, and the verdict on a report against it. Absent is a WARNING naming the
3
+ // figure to write (an app that never opted in stays green on `main`); present, above it is red.
4
+ // The ratchet only falls: a figure under the floor is a warning naming the lower number.
5
+
6
+ import { ERROR_DOCS_URL, renderCauseValue } from '@ultimat3/core';
7
+ import type { ExerciseRecord } from '@ultimat3/testing';
8
+ import type { Finding } from './output';
9
+
10
+ /** The floor's exercise key. Named once: the problem quotes it and the fix repairs it. */
11
+ export const EXERCISE_FIELD = 'exercise';
12
+
13
+ export interface ExerciseFloor {
14
+ /** Unproven ÷ reached the pass may report, `0` to `1`. `x new` writes `0`; `x upgrade` the measured figure. */
15
+ readonly unprovenMax?: number;
16
+ /** Statements one primitive call may issue before the pass reports it (`@ultimat3/testing`'s X4). */
17
+ readonly statementsMax?: number;
18
+ }
19
+
20
+ const KEYS = ['unprovenMax', 'statementsMax'] as const;
21
+
22
+ /** `{ "unprovenMax": 0.05, "statementsMax": 100 }`, or the problems — a typo covers nothing. */
23
+ export function readExerciseFloor(payload: Record<string, unknown> | undefined): {
24
+ floor?: ExerciseFloor;
25
+ problems: readonly string[];
26
+ } {
27
+ const raw = payload?.[EXERCISE_FIELD];
28
+ if (raw === undefined) return { problems: [] };
29
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
30
+ return { problems: [`"${EXERCISE_FIELD}" is not an object of { "unprovenMax": ratio }`] };
31
+ }
32
+ const problems: string[] = [];
33
+ const floor: { unprovenMax?: number; statementsMax?: number } = {};
34
+ for (const [key, value] of Object.entries(raw)) {
35
+ if (key === 'unprovenMax') {
36
+ if (typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1) {
37
+ floor.unprovenMax = value;
38
+ } else {
39
+ problems.push(
40
+ `"${EXERCISE_FIELD}.unprovenMax" is ${JSON.stringify(value)}, which is not a ratio from 0 to 1`,
41
+ );
42
+ }
43
+ } else if (key === 'statementsMax') {
44
+ if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 1) {
45
+ floor.statementsMax = value;
46
+ } else {
47
+ problems.push(
48
+ `"${EXERCISE_FIELD}.statementsMax" is ${JSON.stringify(value)}, which is not a whole number of statements`,
49
+ );
50
+ }
51
+ } else {
52
+ problems.push(`"${EXERCISE_FIELD}" names ${key}, which is not one of ${KEYS.join(', ')}`);
53
+ }
54
+ }
55
+ return { ...(Object.keys(floor).length === 0 ? {} : { floor }), problems };
56
+ }
57
+
58
+ type Proven = Pick<ExerciseRecord, 'kind' | 'name' | 'outcome' | 'tenant' | 'crash' | 'scale'>;
59
+
60
+ /** The first proof that could not ask, with the reason it gave. */
61
+ const unprovenReason = (record: Proven): string | undefined => {
62
+ for (const [proof, verdict] of [
63
+ ['tenant', record.tenant],
64
+ ['crash', record.crash],
65
+ ['scale', record.scale],
66
+ ] as const) {
67
+ if (verdict?.verdict === 'unproven') return `${proof}: ${verdict.reason}`;
68
+ }
69
+ return undefined;
70
+ };
71
+
72
+ export interface UnprovenTally {
73
+ readonly reached: number;
74
+ readonly unproven: readonly { readonly name: string; readonly reason: string }[];
75
+ /** Unproven ÷ reached, rounded UP to 4 places so a written figure always holds its own run. */
76
+ readonly figure: number;
77
+ }
78
+
79
+ export function unprovenTally(records: readonly Proven[]): UnprovenTally {
80
+ const reached = records.filter((one) => one.outcome === 'reached');
81
+ const unproven = reached.flatMap((one) => {
82
+ const reason = unprovenReason(one);
83
+ return reason === undefined ? [] : [{ name: `${one.kind} ${one.name}`, reason }];
84
+ });
85
+ // Integers first: `7 / 100 * 10_000` is 700.0000000000001 and ceil'd to 0.0701, over its own run.
86
+ const units = reached.length === 0 ? 0 : Math.ceil((unproven.length * 10_000) / reached.length);
87
+ return { reached: reached.length, unproven, figure: units / 10_000 };
88
+ }
89
+
90
+ /** `value` as `digits ÷ 10^scale`, read off its shortest decimal spelling (`0.07`, `1e-7`): exact. */
91
+ const decimal = (value: number): { readonly digits: bigint; readonly scale: bigint } => {
92
+ const [mantissa = '0', exponent = '0'] = String(value).toLowerCase().split('e');
93
+ const [whole = '0', fraction = ''] = mantissa.split('.');
94
+ const scale = fraction.length - Number(exponent);
95
+ const digits = BigInt(`${whole}${fraction}`);
96
+ return scale < 0
97
+ ? { digits: digits * 10n ** BigInt(-scale), scale: 0n }
98
+ : { digits, scale: BigInt(scale) };
99
+ };
100
+
101
+ /**
102
+ * `unproven ÷ reached > max`, in integers: `0.29 * 100` is 28.999999999999996 in floats, and a pass
103
+ * exactly at the floor it wrote read red. Not money — a ratio — so a bigint holds the cross product.
104
+ */
105
+ const aboveFloor = (unproven: number, reached: number, max: number): boolean => {
106
+ const { digits, scale } = decimal(max);
107
+ return BigInt(unproven) * 10n ** scale > digits * BigInt(reached);
108
+ };
109
+
110
+ /** How many unproven records a finding names: the head is where to start. */
111
+ const NAMED = 3;
112
+
113
+ /** The verdict: red above a declared floor, a warning without one, a warning when it can fall. */
114
+ export function judgeUnproven(
115
+ records: readonly Proven[],
116
+ floor: ExerciseFloor | undefined,
117
+ ): { readonly findings: readonly Finding[]; readonly warnings: readonly string[] } {
118
+ const tally = unprovenTally(records);
119
+ const count = `${String(tally.unproven.length)} of ${String(tally.reached)} reached primitive(s)`;
120
+ const max = floor?.unprovenMax;
121
+ const hold = `"${EXERCISE_FIELD}": { "unprovenMax": ${String(tally.figure)} }`;
122
+ if (max === undefined) {
123
+ return tally.unproven.length === 0
124
+ ? { findings: [], warnings: [] }
125
+ : {
126
+ findings: [],
127
+ warnings: [
128
+ `exercise left ${count} unproven (${String(tally.figure)}): hold it with ${hold} in x.verify.json, 0 to require every proof`,
129
+ ],
130
+ };
131
+ }
132
+ if (aboveFloor(tally.unproven.length, tally.reached, max)) {
133
+ const named = tally.unproven
134
+ .slice(0, NAMED)
135
+ .map((one) => `${one.name} (${renderCauseValue(one.reason)})`)
136
+ .join(', ');
137
+ return {
138
+ findings: [
139
+ {
140
+ code: 'X_EXERCISE_UNPROVEN_ABOVE_FLOOR',
141
+ cause: `exercise left ${count} unproven, ${String(tally.figure)} of the reached; x.verify.json "${EXERCISE_FIELD}.unprovenMax" allows ${String(max)}: ${named}`,
142
+ fix: 'x exercise --json # each unproven record in .x/exercise.json names the proof and its reason: fix the seed or the override it names; the floor only falls',
143
+ docs: ERROR_DOCS_URL,
144
+ at: 'x.verify.json',
145
+ },
146
+ ],
147
+ warnings: [],
148
+ };
149
+ }
150
+ return tally.figure < max
151
+ ? {
152
+ findings: [],
153
+ warnings: [
154
+ `exercise left ${count} unproven (${String(tally.figure)}), under "${EXERCISE_FIELD}.unprovenMax" ${String(max)}: lower it to ${hold} in x.verify.json`,
155
+ ],
156
+ }
157
+ : { findings: [], warnings: [] };
158
+ }
@@ -20,6 +20,7 @@
20
20
  // Bun ships no path API. `posix` does the specifier arithmetic (an app-relative route file is
21
21
  // POSIX by construction), `join`/`basename` the filesystem side.
22
22
  import { join, posix, relative, sep } from 'node:path';
23
+ import type { IslandsConfig } from '@ultimat3/core';
23
24
  import { logger, renderThrowable } from '@ultimat3/core';
24
25
  import { ISLAND_EXTENSION } from '@ultimat3/render';
25
26
  import { loadAppConfig } from './app-config-load';
@@ -41,6 +42,7 @@ import { groupKey, readGroup, sweepOnce, writeGroup } from './island-group-cache
41
42
  import { islandGroups } from './island-groups';
42
43
  import { describeBuildError } from './island-identity';
43
44
  import { linkOutputs } from './island-link';
45
+ import { refuseUnboundImports } from './island-link-check';
44
46
  import { builtOutputs, entryChunks, ISLAND_BASE_PATH, sharedChunks } from './island-outputs';
45
47
  import { frameworkDedupePlugins } from './island-package-dedupe';
46
48
  import {
@@ -56,6 +58,8 @@ import { solidDedupePlugin } from './island-solid-dedupe';
56
58
  import type { SourcePaths } from './island-sources';
57
59
  import type { IslandStyles } from './island-styles';
58
60
  import { islandStylesPlugin, stylesheetsOf } from './island-styles';
61
+ import type { Vendors } from './island-vendor';
62
+ import { loadingVendor, vendorBuilder, vendorExternalPlugin, vendorShared } from './island-vendor';
59
63
  import { hasPathSegment } from './path-segments';
60
64
  import { solidJsxPlugin } from './solid-loader';
61
65
 
@@ -169,6 +173,7 @@ async function buildAll(
169
173
  const follows = new Set(files.filter((_, index) => realtime[index] === 'follows'));
170
174
  const kinds = new Map(files.map((file, index) => [file, realtime[index]]));
171
175
  const runtime = live[0] === undefined ? undefined : await runtimes(live[0]);
176
+ const vendor = context.vendors === undefined ? undefined : await context.vendors();
172
177
  const entrypoints = files.map((file, index) =>
173
178
  realtime[index] !== undefined ? realtimeIslandEntry(file) : join(root, file),
174
179
  );
@@ -200,6 +205,8 @@ async function buildAll(
200
205
  // gets the same rule (`island-package-dedupe.ts`): a nested copy is a second module where no
201
206
  // symlink folds it, which is every `file:` install on Windows.
202
207
  plugins: [
208
+ // Ahead of everything: Solid itself is never read into an island (`island-vendor.ts`).
209
+ ...(vendor === undefined ? [] : [vendorExternalPlugin(vendor)]),
203
210
  ...(runtime === undefined
204
211
  ? []
205
212
  : [islandRealtimePlugin(root, runtime, follows, live.length === files.length)]),
@@ -250,22 +257,28 @@ async function buildAll(
250
257
  await refuseDuplicatedModules(files.join(', '), built.metafile, context.io);
251
258
  const sources = new Map<string, SourcePaths>();
252
259
  const linked = linkOutputs(await builtOutputs(root, files, built.outputs, sources));
253
- const chunks = loadingRuntime(entryChunks(files, linked, sources), live, runtime).map(
260
+ const entries = loadingRuntime(entryChunks(files, linked, sources), live, runtime).map(
254
261
  (chunk): IslandChunk => {
255
262
  const kind = kinds.get(chunk.file);
256
263
  return kind === undefined ? chunk : { ...chunk, realtime: kind };
257
264
  },
258
265
  );
259
- const shared = sharedChunks(chunks, linked, sources);
266
+ const shared = sharedChunks(entries, linked, sources);
267
+ const chunks = loadingVendor(entries, shared, vendor);
260
268
  const read = Object.keys(built.metafile.inputs);
261
269
  const stylesheets = stylesheetsOf(read);
262
- // The bundler's inputs, the runtime's, and every Sass partial a sheet `@use`s: a partial moves
263
- // the sheet's class hashes and is read by the Sass compiler, never by the bundler.
270
+ // The bundler's inputs, the runtime's, the vendor's, and every Sass partial a sheet `@use`s: a
271
+ // partial moves the sheet's class hashes and is read by the Sass compiler, never by the bundler.
264
272
  const partials = context.styles.dependenciesOf(stylesheets);
265
- const readFiles = [...(await inputFiles(read)), ...(runtime?.inputs ?? []), ...partials];
273
+ const readFiles = [
274
+ ...(await inputFiles(read)),
275
+ ...(runtime?.inputs ?? []),
276
+ ...(vendor?.inputs ?? []),
277
+ ...partials,
278
+ ];
266
279
  return {
267
280
  chunks,
268
- shared: [...shared, ...runtimeShared(runtime, live)],
281
+ shared: [...shared, ...runtimeShared(runtime, live), ...vendorShared(vendor, chunks)],
269
282
  inputs: [...new Set(readFiles)].sort(),
270
283
  stylesheets,
271
284
  };
@@ -303,6 +316,8 @@ interface BuildContext {
303
316
  readonly styles: IslandStyles;
304
317
  /** One realpath per file per call, however many groups' metafiles name it. */
305
318
  readonly io: ModuleIdentityIo;
319
+ /** Solid as one shared output (`island-vendor.ts`); `undefined` bundles it into each build. */
320
+ readonly vendors: Vendors | undefined;
306
321
  }
307
322
 
308
323
  export interface BuildIslandsOptions {
@@ -336,11 +351,19 @@ export interface BuildIslandsOptions {
336
351
  * the registry is read as it stands: the caller loaded the app first.
337
352
  */
338
353
  readonly persists?: () => Promise<boolean | undefined>;
354
+ /**
355
+ * Solid as ONE shared output every island imports (`island-vendor.ts`), off by default. Measured
356
+ * As of 2026-11-12 (Bun 1.4.4, solid-js 1.9.17): each island inlines a tree-shaken ~14 kB of
357
+ * Solid, the whole vendor is 48,083 B, so every Solid route of the three tracked apps grew
358
+ * +33,572…+38,769 B with it on; it pays only where a page renders four or more Solid islands
359
+ * that are built apart.
360
+ */
361
+ readonly vendorSolid?: boolean;
339
362
  }
340
363
 
341
- /** `islands.sharedChunks` off the one loader (`app-config-load.ts`) — `false` with no config file. */
342
- export async function loadSharedChunks(root: string): Promise<boolean> {
343
- return (await loadAppConfig(root))?.islands.sharedChunks ?? false;
364
+ /** The `islands` block off the one loader (`app-config-load.ts`) — both off with no config file. */
365
+ async function loadIslandsConfig(root: string): Promise<IslandsConfig> {
366
+ return (await loadAppConfig(root))?.islands ?? { sharedChunks: false, vendorSolid: false };
344
367
  }
345
368
 
346
369
  /** Build every island in the app. An app with none returns an empty bundle and costs one glob. */
@@ -355,10 +378,16 @@ export async function buildIslands(
355
378
  // an empty bundle here would surface two steps later, as a chunk table with no entry for a file
356
379
  // the caller can see on disk.
357
380
  if (only !== undefined && files.length === 0) throw onlyMissing(only, discovered);
381
+ // Read only where an option leaves a question open: an app with no islands costs one glob.
382
+ const asks =
383
+ files.length > 0 && (options.sharedChunks === undefined || options.vendorSolid === undefined);
384
+ const configured = asks ? await loadIslandsConfig(root) : undefined;
385
+ const vendorSolid = files.length > 0 && (options.vendorSolid ?? configured?.vendorSolid ?? false);
358
386
  const context: BuildContext = {
359
387
  runtimes: runtimeBuilder(root, ISLAND_BASE_PATH),
360
388
  styles: islandStylesPlugin(),
361
389
  io: memoizedIo(hostIo()),
390
+ vendors: vendorSolid ? vendorBuilder(root, ISLAND_BASE_PATH) : undefined,
362
391
  };
363
392
  let asked: Promise<boolean | undefined> | undefined;
364
393
  const persistsOnce = (): Promise<boolean | undefined> => {
@@ -369,7 +398,8 @@ export async function buildIslands(
369
398
  // build; every other island is alone, splitting off, self-contained but for the page runtime —
370
399
  // the ONE file every realtime island loads, counted once however many load it.
371
400
  // `islands.sharedChunks` is the one group of every island, split as it always was.
372
- const everyIsland = files.length > 0 && (options.sharedChunks ?? (await loadSharedChunks(root)));
401
+ const everyIsland =
402
+ files.length > 0 && (options.sharedChunks ?? configured?.sharedChunks ?? false);
373
403
  const groups = everyIsland ? [files] : files.length === 0 ? [] : await islandGroups(root, files);
374
404
  const reuse = options.reuse ?? true;
375
405
  const cache = {
@@ -390,7 +420,13 @@ export async function buildIslands(
390
420
  );
391
421
  const persists = reaches.includes(true) ? await persistsOnce() : undefined;
392
422
  if (!reuse) return buildAll(root, group, splitting, context, persists);
393
- const key = groupKey({ group, splitting, environment: cache.environment, persists });
423
+ const key = groupKey({
424
+ group,
425
+ splitting,
426
+ environment: cache.environment,
427
+ persists,
428
+ vendor: vendorSolid,
429
+ });
394
430
  const hit = await readGroup(root, key, cache.digestOf, cache.listingOf);
395
431
  if (hit !== undefined) return hit;
396
432
  // The wall clock as the filesystem stamps an mtime — never `Date.now()`, which a test may freeze.
@@ -408,7 +444,11 @@ export async function buildIslands(
408
444
  };
409
445
  if (reuse) await sweepOnce(root);
410
446
  const width = navigator.hardwareConcurrency;
411
- return islandBundle(...mergeBuilds(await boundedMap(groups, width, build)));
447
+ const [chunks, shared] = mergeBuilds(await boundedMap(groups, width, build));
448
+ // Over the MERGED bundle: groups come from a cache or a fresh build, the runtime and the vendor
449
+ // from builds of their own, so this is the one place every link of the page's files is in view.
450
+ refuseUnboundImports([...chunks, ...shared.map((one) => ({ ...one, file: one.importers[0] }))]);
451
+ return islandBundle(chunks, shared);
412
452
  }
413
453
 
414
454
  type GroupBuild = Pick<GroupOutput, 'chunks' | 'shared'>;
@@ -107,7 +107,7 @@ export function islandDisposerFindings(files: readonly SourceFile[]): readonly F
107
107
  {
108
108
  code: 'X_ISLAND_DISPOSER_MISSING',
109
109
  cause: `${path}'s mount() ${why}, so the client router has nothing to call when it navigates away and the island's listeners, hotkeys and live reads stay registered`,
110
- fix: `x verify --only boundaries --json # in ${commentSafe(path)}, end mount() with return render(() => <Island {...props} />, el) — Solid's disposer, which the router calls`,
110
+ fix: `x verify --only boundaries --json # in ${commentSafe(path)}, end mount() with return mountOver(el, (root) => render(() => <Island {...props} />, root)) — Solid's disposer, which the router calls (mountOver from @ultimat3/render/client)`,
111
111
  docs: ERROR_DOCS_URL,
112
112
  at: path,
113
113
  },
@@ -77,6 +77,8 @@ export function groupKey(parts: {
77
77
  readonly splitting: boolean;
78
78
  readonly environment: string;
79
79
  readonly persists: boolean | undefined;
80
+ /** Solid as one shared output (`island-vendor.ts`): other bytes, so another entry. */
81
+ readonly vendor?: boolean;
80
82
  }): string {
81
83
  return contentHash(
82
84
  JSON.stringify([
@@ -87,6 +89,8 @@ export function groupKey(parts: {
87
89
  parts.group,
88
90
  parts.splitting,
89
91
  parts.persists ?? null,
92
+ // Appended only when on, so every entry written before the vendor existed keeps its key.
93
+ ...(parts.vendor === true ? ['vendor-solid'] : []),
90
94
  ]),
91
95
  );
92
96
  }
@@ -0,0 +1,73 @@
1
+ // The post-build smoke #1075 asked for: every name an island output imports from another output
2
+ // of the bundle is a name that output exports. Groups come out of a cache, a store or a fresh
3
+ // build, and the vendor and page runtime are built apart — a binding that names nothing would
4
+ // fail in the browser as a `SyntaxError` on a blank island; here it fails the build, by file.
5
+
6
+ // why: Bun ships no path API; `basename` of a relative specifier.
7
+ import { posix } from 'node:path';
8
+ import { IslandBuildFailedError } from './errors';
9
+
10
+ /** One output as the check reads it: where it is served and what it is. */
11
+ export interface LinkedAsset {
12
+ readonly url: string;
13
+ readonly code: string;
14
+ /** The island source a refusal names — the entry's own, or a shared chunk's first importer. */
15
+ readonly file?: string | undefined;
16
+ }
17
+
18
+ /** A static `import{a as b,c}from"./x.js"` as Bun's minifier writes one. */
19
+ const NAMED_IMPORT = /import\s*\{([^}]*)\}\s*from\s*"(\.\/[^"]+)"/g;
20
+
21
+ /** `a as b` → `a`; `default as b` → `default`; a quoted name keeps its spelling. */
22
+ const importedName = (binding: string): string => {
23
+ const [name = ''] = binding.trim().split(/\s+as\s+/);
24
+ return name.startsWith('"') ? (JSON.parse(name) as string) : name;
25
+ };
26
+
27
+ export interface UnboundImport {
28
+ readonly importer: string;
29
+ readonly file: string | undefined;
30
+ readonly target: string;
31
+ readonly name: string;
32
+ }
33
+
34
+ /** Every imported name no sibling output exports, in the order found; empty when all bind. */
35
+ export function unboundImports(assets: readonly LinkedAsset[]): readonly UnboundImport[] {
36
+ const byName = new Map(assets.map((one) => [posix.basename(one.url), one]));
37
+ const exportsOf = new Map<string, ReadonlySet<string>>();
38
+ const transpiler = new Bun.Transpiler({ loader: 'js' });
39
+ const exported = (asset: LinkedAsset): ReadonlySet<string> => {
40
+ let known = exportsOf.get(asset.url);
41
+ if (known === undefined) {
42
+ known = new Set(transpiler.scan(asset.code).exports);
43
+ exportsOf.set(asset.url, known);
44
+ }
45
+ return known;
46
+ };
47
+ const unbound: UnboundImport[] = [];
48
+ for (const asset of assets) {
49
+ for (const match of asset.code.matchAll(NAMED_IMPORT)) {
50
+ const target = byName.get(posix.basename(match[2] ?? ''));
51
+ // A specifier naming no output of the bundle is not this check's: nothing it links to.
52
+ if (target === undefined) continue;
53
+ const names = exported(target);
54
+ for (const binding of (match[1] ?? '').split(',')) {
55
+ const name = importedName(binding);
56
+ if (name !== '' && !names.has(name)) {
57
+ unbound.push({ importer: asset.url, file: asset.file, target: target.url, name });
58
+ }
59
+ }
60
+ }
61
+ }
62
+ return unbound;
63
+ }
64
+
65
+ /** Refuses a bundle whose outputs do not link, naming the first import that binds nothing. */
66
+ export function refuseUnboundImports(assets: readonly LinkedAsset[]): void {
67
+ const [first] = unboundImports(assets);
68
+ if (first === undefined) return;
69
+ throw new IslandBuildFailedError({
70
+ file: first.file ?? first.importer,
71
+ logs: `${first.importer} imports ${first.name} from ${first.target}, which exports no such name, so the island would fail to link in the browser — clear the island cache with rm -rf .x/cache/islands and build again`,
72
+ });
73
+ }
@@ -0,0 +1,183 @@
1
+ // Solid as ONE output beside the islands: `vendor-solid.<contentHash>.js`, re-exporting `solid-js`,
2
+ // `solid-js/web` and `solid-js/store` whole, once per `buildIslands` call. Every island resolves
3
+ // them to it as an external, so three islands built apart download one Solid. Its bytes move with
4
+ // a Solid install, never an island edit, so no island's change re-names the file the rest import.
5
+
6
+ // why: Bun ships no path API; the vendor's URL is basePath joined to its file name.
7
+ import { posix } from 'node:path';
8
+ import { contentHash } from '@ultimat3/render/server';
9
+ import type { BunPlugin } from 'bun';
10
+ import { IslandBuildFailedError } from './errors';
11
+ import type { IslandChunk, SharedChunk } from './island-bundle';
12
+ import { inputFiles } from './island-cache-inputs';
13
+ import { describeBuildError, stableChunk, stripDebugId } from './island-identity';
14
+ import { frameworkDedupePlugins } from './island-package-dedupe';
15
+ import { solidDedupePlugin } from './island-solid-dedupe';
16
+
17
+ /**
18
+ * The specifiers the vendor answers. `solid-js/h`, `/html` and `/universal` stay bundled into the
19
+ * island that asks: rare, and each imports `solid-js/web`, which then resolves here.
20
+ */
21
+ export const VENDOR_SPECIFIER = /^solid-js(?:\/web|\/store)?$/;
22
+
23
+ /**
24
+ * The vendor entry. `DEV` is exported by both `solid-js` and `solid-js/store`, and two star
25
+ * exports of one name export NEITHER (measured on 1.9.17: 121 names, `DEV` missing) — an island
26
+ * importing it would fail to link in the browser. The explicit export wins over both stars; under
27
+ * the production condition both are `undefined`.
28
+ */
29
+ const VENDOR_SOURCE = [
30
+ `export * from 'solid-js';`,
31
+ `export * from 'solid-js/web';`,
32
+ `export * from 'solid-js/store';`,
33
+ `export { DEV } from 'solid-js';`,
34
+ '',
35
+ ].join('\n');
36
+
37
+ const ENTRY = 'ultimate:vendor-solid';
38
+ const NAMESPACE = 'ultimate-vendor-solid';
39
+
40
+ /**
41
+ * `vendor-solid.<identity>.js` — the dot, as `page-runtime.<identity>.js` has it: a module id is
42
+ * `[a-z0-9-]` only, so no island entry (`<moduleId>-<identity>.js`) can be served at this name.
43
+ */
44
+ const VENDOR_FILE = /^vendor-solid\.[0-9a-z]+\.js$/;
45
+
46
+ /** Whether `url` (any base path) is the Solid vendor chunk — the one predicate, never a prefix. */
47
+ export function isVendorChunk(url: string): boolean {
48
+ return VENDOR_FILE.test(posix.basename(url));
49
+ }
50
+
51
+ export interface VendorChunk {
52
+ readonly url: string;
53
+ /** `./vendor-solid.<identity>.js`: what an island's code imports, resolved beside it. */
54
+ readonly specifier: string;
55
+ readonly code: string;
56
+ readonly bytes: number;
57
+ /** Every file the vendor's build read, absolute (`inputFiles`): what a cached group rehashes. */
58
+ readonly inputs: readonly string[];
59
+ }
60
+
61
+ /** The vendor a build's islands import — built at most once per `buildIslands` call. */
62
+ export type Vendors = () => Promise<VendorChunk>;
63
+
64
+ export function vendorBuilder(root: string, basePath: string): Vendors {
65
+ let built: Promise<VendorChunk> | undefined;
66
+ return () => {
67
+ built ??= buildVendor(root, basePath);
68
+ return built;
69
+ };
70
+ }
71
+
72
+ async function buildVendor(root: string, basePath: string): Promise<VendorChunk> {
73
+ let built: Awaited<ReturnType<typeof Bun.build>>;
74
+ try {
75
+ built = await Bun.build({
76
+ entrypoints: [ENTRY],
77
+ root,
78
+ target: 'browser',
79
+ format: 'esm',
80
+ minify: true,
81
+ // The app's one Solid copy (`island-solid-dedupe.ts`) — the copy every island was built
82
+ // against before this file existed — under `island-bundle.ts`'s production `define`.
83
+ plugins: [vendorEntryPlugin(), solidDedupePlugin(root), ...frameworkDedupePlugins(root)],
84
+ define: { 'process.env.NODE_ENV': '"production"' },
85
+ metafile: true,
86
+ });
87
+ } catch (error) {
88
+ throw new IslandBuildFailedError({ file: 'solid-js', logs: describeBuildError(error) });
89
+ }
90
+ const output = built.outputs.find((artifact) => artifact.kind === 'entry-point');
91
+ if (!built.success || output === undefined) {
92
+ throw new IslandBuildFailedError({
93
+ file: 'solid-js',
94
+ logs: built.logs.map((log) => String(log)).join('; '),
95
+ });
96
+ }
97
+ // Named by its bytes (#1075), as every island output is: `immutable` is a promise about them.
98
+ const code = stripDebugId(await output.text());
99
+ const identity = contentHash(code);
100
+ const name = `vendor-solid.${identity}.js`;
101
+ const url = `${basePath}/${name}`;
102
+ return {
103
+ url,
104
+ specifier: `./${name}`,
105
+ ...stableChunk(url, identity, code),
106
+ inputs: await inputFiles(Object.keys(built.metafile?.inputs ?? {})),
107
+ };
108
+ }
109
+
110
+ function vendorEntryPlugin(): BunPlugin {
111
+ return {
112
+ name: 'ultimate-vendor-solid-entry',
113
+ setup(build) {
114
+ build.onResolve({ filter: /^ultimate:vendor-solid$/ }, () => ({
115
+ path: 'entry',
116
+ namespace: NAMESPACE,
117
+ }));
118
+ build.onLoad({ filter: /.*/, namespace: NAMESPACE }, () => ({
119
+ contents: VENDOR_SOURCE,
120
+ loader: 'js',
121
+ }));
122
+ },
123
+ };
124
+ }
125
+
126
+ /**
127
+ * The island-side half: every vendored specifier, from any file of the island's graph, is the
128
+ * vendor's relative URL, left external. Installed FIRST, ahead of the Solid dedupe, so no Solid
129
+ * file is ever read into an island chunk.
130
+ */
131
+ export function vendorExternalPlugin(vendor: VendorChunk): BunPlugin {
132
+ return {
133
+ name: 'ultimate-vendor-solid-external',
134
+ setup(build) {
135
+ build.onResolve({ filter: VENDOR_SPECIFIER }, () => ({
136
+ path: vendor.specifier,
137
+ external: true,
138
+ }));
139
+ },
140
+ };
141
+ }
142
+
143
+ /** Whether `code` imports the vendor — statically or by `import()`. */
144
+ function importsVendor(code: string, vendor: VendorChunk): boolean {
145
+ return new Bun.Transpiler({ loader: 'js' })
146
+ .scan(code)
147
+ .imports.some((one) => one.path === vendor.specifier);
148
+ }
149
+
150
+ /**
151
+ * Every entry whose own code or a shared chunk it loads imports the vendor names it among its
152
+ * `imports`, so a precache, a preload and a budget count it — once, by URL.
153
+ */
154
+ export function loadingVendor(
155
+ chunks: readonly IslandChunk[],
156
+ shared: readonly SharedChunk[],
157
+ vendor: VendorChunk | undefined,
158
+ ): readonly IslandChunk[] {
159
+ if (vendor === undefined) return chunks;
160
+ const sharedLoads = new Set(
161
+ shared.filter((one) => importsVendor(one.code, vendor)).map((one) => one.url),
162
+ );
163
+ return chunks.map((chunk) =>
164
+ importsVendor(chunk.code, vendor) || chunk.imports.some((url) => sharedLoads.has(url))
165
+ ? { ...chunk, imports: [...new Set([...chunk.imports, vendor.url])].sort() }
166
+ : chunk,
167
+ );
168
+ }
169
+
170
+ /** The vendor as the bundle's shared asset, with the islands that load it; none, no asset. */
171
+ export function vendorShared(
172
+ vendor: VendorChunk | undefined,
173
+ chunks: readonly IslandChunk[],
174
+ ): readonly SharedChunk[] {
175
+ if (vendor === undefined) return [];
176
+ const importers = chunks
177
+ .filter((chunk) => chunk.imports.includes(vendor.url))
178
+ .map((chunk) => chunk.file)
179
+ .sort();
180
+ if (importers.length === 0) return [];
181
+ const { url, code, bytes } = vendor;
182
+ return [{ url, code, bytes, importers, sources: [] }];
183
+ }
package/src/mcp-errors.ts CHANGED
@@ -357,7 +357,7 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
357
357
  X_NEW_SHAPE_GENERATE_FAILED:
358
358
  'bunx x g sign-in --password --json # in the app x new wrote, reproduces it; then bun test ./packages/cli/src/templates/shapes',
359
359
  X_ISLAND_DISPOSER_MISSING:
360
- 'x verify --only boundaries --json # names the file; end its mount() with return render(() => <Island {...props} />, el)',
360
+ 'x verify --only boundaries --json # names the file; end its mount() with return mountOver(el, (root) => render(() => <Island {...props} />, root))',
361
361
  X_SOCKET_HAND_ROLLED:
362
362
  'x verify --only boundaries --json — names the file and line; delete the upgrade and declare the socket with deviceSocket({ path, resolveToken, onFrame }) from @ultimat3/realtime/server',
363
363
  X_EXERCISE_FILE_UNEDITABLE:
@@ -384,6 +384,16 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
384
384
  "native: { success: (output) => '/where-it-lands' } in the action's declaration, then x verify --only manifest",
385
385
  X_ASSET_RETAIN_UNDECLARED:
386
386
  "edit app.config.ts: add assets: { retain: { disk: 'assets', builds: 3 } }, naming a disk your defineStorage({ disks }) declares that every web pod reads",
387
+ X_EXERCISE_UNPROVEN_ABOVE_FLOOR:
388
+ 'x exercise --json # each unproven record in .x/exercise.json names the proof and its reason: fix the seed or the override it names; the floor only falls',
389
+ X_ENV_NAME_RESERVED:
390
+ 'edit app.config.ts: add an APP_ prefix to the envSchema name the finding cites (or delete it where the value is meant for the framework); then: x env example --json && x doctor --json',
391
+ X_FRAMEWORK_PIN_RANGE:
392
+ 'x doctor --json # each X_FRAMEWORK_PIN_RANGE names a package.json line and the exact version: write it there, then: bun install',
393
+ X_VERIFY_STEP_UNFLOORED:
394
+ 'x doctor --json # its X_VERIFY_STEP_UNFLOORED fix names the steps: run that x verify --only, then add each step that passed, not skipped, to "steps" in x.verify.json',
395
+ X_DB_ROW_SECURITY_OFF:
396
+ 'database: { rowSecurity: true } # in defineConfig, app.config.ts; then: x db gen "row security" --json && x db migrate --json && x doctor --json',
387
397
  };
388
398
 
389
399
  const isCliCode = (code: string): code is CliErrorCode =>
@@ -31,6 +31,19 @@ export const UPGRADE_MESSAGES = {
31
31
  'cli.upgrade.done': '{from} -> {to}: the gate is green',
32
32
  'cli.upgrade.dryRun': '{from} -> {to}: nothing written, no gate run',
33
33
  'cli.upgrade.guard': 'guard, yours to take or leave: {fix}',
34
+ 'cli.upgrade.guardInstalled':
35
+ 'guard installed: guards/{name}.ts, from this release (delete the file to drop the rule)',
36
+ 'cli.upgrade.guardWithheld':
37
+ 'guard not installed, the tree breaks it in {count} place(s) — yours to take: {fix}',
38
+ 'cli.upgrade.guardUnmeasured':
39
+ 'guard not installed, its findings could not be counted — yours to take: {fix}',
40
+ 'cli.upgrade.coverage':
41
+ 'coverage floor: {file} {fromLines} / {fromFuncs} -> {toLines} / {toFuncs}, measured {lines}% / {funcs}% after the Bun floor moved — review the why',
42
+ 'cli.upgrade.exerciseFloor':
43
+ 'exercise floor: {file} "exercise" {figures}, measured by this hop\'s x exercise — it may only fall',
44
+ 'cli.upgrade.coverage.unpinned': 'no engines.bun',
45
+ 'cli.upgrade.coverage.why':
46
+ 'Rebaselined {date} by x upgrade to {release}: Bun {bunFrom} -> {bunTo}, with no test or source changed, measured {lines}% of lines and {funcs}% of functions, so the floor moves from {fromLines} / {fromFuncs} to {toLines} / {toFuncs}.',
34
47
  'cli.upgrade.read': 'read: {title} — {url}',
35
48
  'cli.upgrade.red': '{from} -> {to}: not done, the gate says: {summary}',
36
49
  'cli.upgrade.stillRunning': 'x upgrade: still in {stage} ({elapsed})',
package/src/messages.ts CHANGED
@@ -104,6 +104,9 @@ const CATALOG = {
104
104
  // `x doctor`'s reminder: the rolling rail is off until this key is set (`doctor-rolling.ts`).
105
105
  'cli.doctor.rollingSince':
106
106
  'the rolling-deploy rail is off: set "rollingSince": "{newest}" in x.verify.json to judge every migration after your newest',
107
+ // `x doctor`'s warnings: beside the verdict on `main`, red on `next` (`doctor-warnings.ts`).
108
+ 'cli.doctor.warnings': '{count} warning(s) — not in the verdict until the next major:',
109
+ 'cli.doctor.warning': ' {code}: {cause} — fix: {fix}',
107
110
  'cli.docs.code': '{code} is an error code — x errors explain answers it',
108
111
  'cli.docs.exports': 'exports: {list}',
109
112
  'cli.docs.installed': 'installed: {list}',