@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,151 @@
1
+ // The `island-mount-clears` guard `x new` ships: an island's `mount` never empties its wrapper
2
+ // outside `mountOver` (`@ultimat3/render/client`). An island that clears and then throws in render
3
+ // shows a blank box; `mountOver` puts the server's markup back. The guard is how an app scaffolded
4
+ // before it adopts the helper: `x g guard island-mount-clears`, then each finding's fix.
5
+
6
+ import { guardCode } from './guard';
7
+ import type { GeneratedFile } from './naming';
8
+
9
+ /** Derived from the guard's name, never a literal: an `X_*` literal here is a FRAMEWORK code. */
10
+ const NAME = 'island-mount-clears';
11
+ const CODE = guardCode(NAME);
12
+
13
+ const source =
14
+ (): string => `// island-mount-clears: an island never empties its server markup with no way back.
15
+ // \`x verify\` discovers every file in \`guards/\` and runs its \`guard\` inside the \`boundaries\`
16
+ // step — nothing registers this file, so nothing can forget to. Delete it to drop the rule.
17
+ //
18
+ // Why: a \`mount\` that empties its wrapper and then renders leaves a BLANK box when the render
19
+ // throws. \`mountOver\` from \`@ultimat3/render/client\` clears the same way, puts the server's markup
20
+ // back on a throw, and rethrows — the runtime still marks the root \`data-x-failed\` for the reporter.
21
+ // Read: \`.textContent = ''\`, \`.innerHTML = ''\` and \`.replaceChildren()\` on \`mount\`'s own wrapper (its
22
+ // first parameter) in a \`*.island.tsx\` that calls no \`mountOver(\`. Not read: a clear of an element
23
+ // inside the wrapper, a comment, a string, a test, a file that is not an island.
24
+
25
+ import type { Finding, Guard } from '@ultimat3/cli';
26
+
27
+ /** The app owns the codes its own conventions raise — this one is named for the guard. */
28
+ const CODE = '${CODE}';
29
+
30
+ export interface SourceFile {
31
+ /** App-root-relative POSIX path, so the finding names the file an author opens. */
32
+ readonly path: string;
33
+ readonly source: string;
34
+ }
35
+
36
+ /** Found on the BLANKED text, so a comment or a string never matches; the value is read below. */
37
+ const WRITE = /([\\w$]+)\\.(?:textContent|innerHTML)\\s*=(?!=)/g;
38
+ /** On the original text at a write's offset: an EMPTY literal is the clear; any other is content. */
39
+ const EMPTIES = /^[\\w$]+\\.(?:textContent|innerHTML)\\s*=\\s*(?:''|""|\`\`)/;
40
+ const REPLACE_ALL = /([\\w$]+)\\.replaceChildren\\s*\\(\\s*\\)/g;
41
+ /** \`function mount(el\` or \`mount = (el\`: the wrapper's name. None found reads \`el\`, the convention. */
42
+ const MOUNT_PARAM = /\\bmount\\s*(?:=\\s*(?:async\\s*)?)?\\(\\s*([\\w$]+)/;
43
+ const MOUNT_OVER = /(?<![\\w$.])mountOver\\s*\\(/;
44
+
45
+ /** Comments and string bodies blanked IN PLACE, so a line number still points at the source. */
46
+ const blank = (text: string): string =>
47
+ text
48
+ .replaceAll(/\\/\\*[\\s\\S]*?\\*\\//g, (match) => match.replaceAll(/[^\\n]/g, ' '))
49
+ .replaceAll(/(?<![:\\w])\\/\\/[^\\n]*/g, (match) => ' '.repeat(match.length))
50
+ .replaceAll(/'(?:[^'\\\\\\n]|\\\\.)*'|"(?:[^"\\\\\\n]|\\\\.)*"|\`(?:[^\`\\\\]|\\\\.)*\`/g, (match) =>
51
+ match.replaceAll(/[^\\n]/g, ' '),
52
+ );
53
+
54
+ /** Every offset in \`source\` that empties the WRAPPER: an empty-literal write or a bare replace. */
55
+ const clears = (source: string, text: string): readonly number[] => {
56
+ const wrapper = MOUNT_PARAM.exec(text)?.[1] ?? 'el';
57
+ return [
58
+ ...[...text.matchAll(WRITE)]
59
+ .filter((match) => match[1] === wrapper && EMPTIES.test(source.slice(match.index)))
60
+ .map((match) => match.index),
61
+ ...[...text.matchAll(REPLACE_ALL)]
62
+ .filter((match) => match[1] === wrapper)
63
+ .map((match) => match.index),
64
+ ];
65
+ };
66
+
67
+ /** Pure — the caller does the I/O — so the rule is testable without a filesystem. */
68
+ export function islandMountClears(files: readonly SourceFile[]): readonly Finding[] {
69
+ const findings: Finding[] = [];
70
+ for (const file of files) {
71
+ const text = blank(file.source);
72
+ if (MOUNT_OVER.test(text)) continue;
73
+ for (const index of [...clears(file.source, text)].sort((a, b) => a - b)) {
74
+ const at = \`\${file.path}:\${text.slice(0, index).split('\\n').length}\`;
75
+ findings.push({
76
+ code: CODE,
77
+ cause: \`\${at} empties the island's server markup outside mountOver, so a render that throws leaves a blank box where the server's HTML was, and the visitor sees nothing to retry\`,
78
+ fix: \`edit \${at} — delete the clear and end mount() with return mountOver(el, (root) => render(() => <Island {...props} />, root)), adding mountOver to the island's imports from '@ultimat3/render/client' — then: x verify\`,
79
+ at,
80
+ });
81
+ }
82
+ }
83
+ return findings;
84
+ }
85
+
86
+ /** The files the rule reads: islands, never a test. */
87
+ export const readsFile = (path: string): boolean =>
88
+ path.endsWith('.island.tsx') && !/\\.test\\.tsx?$/.test(path);
89
+
90
+ export const guard: Guard = {
91
+ summary: 'an island mounts over its server markup, never clears it with no way back',
92
+ async check(_root, sources) {
93
+ // The run's ONE read of the source: every guard asking for this glob shares the walk.
94
+ const code = await sources.files('{apps,packages}/**/*.{ts,tsx}');
95
+ return islandMountClears(
96
+ code
97
+ .filter((file) => readsFile(file.path))
98
+ .map((file) => ({ path: file.path, source: file.text })),
99
+ );
100
+ },
101
+ };
102
+ `;
103
+
104
+ const test =
105
+ (): string => `// The rule, driven directly. Failure case first: a guard whose rule silently stopped matching is
106
+ // a green gate over the convention it was written to enforce.
107
+
108
+ import { expect, unitTest } from '@ultimat3/testing';
109
+ import { islandMountClears, readsFile } from './island-mount-clears';
110
+
111
+ const file = (source: string) => [{ path: 'apps/web/app/posts/like.island.tsx', source }];
112
+
113
+ unitTest('a mount that clears its shell is refused, and the finding names the line', () => {
114
+ const findings = islandMountClears(
115
+ file("export function mount(el) {\\n el.textContent = '';\\n}"),
116
+ );
117
+ expect(findings).toHaveLength(1);
118
+ expect(findings[0]?.code).toBe('${CODE}');
119
+ expect(findings[0]?.at).toBe('apps/web/app/posts/like.island.tsx:2');
120
+ // Not an import line: an app's import audit would read a pasteable one as this file's own.
121
+ expect(findings[0]?.fix).toContain("imports from '@ultimat3/render/client'");
122
+ });
123
+
124
+ unitTest('innerHTML and a bare replaceChildren() are the same clear', () => {
125
+ expect(islandMountClears(file('el.innerHTML = "";'))).toHaveLength(1);
126
+ expect(islandMountClears(file('el.replaceChildren();'))).toHaveLength(1);
127
+ });
128
+
129
+ unitTest('mountOver, a comment, a string and a non-empty write are not refused', () => {
130
+ expect(
131
+ islandMountClears(file('return mountOver(el, (root) => render(() => <A />, root));')),
132
+ ).toEqual([]);
133
+ expect(islandMountClears(file("// el.textContent = '';"))).toEqual([]);
134
+ expect(islandMountClears(file('const s = "el.textContent = \\'\\'";'))).toEqual([]);
135
+ expect(islandMountClears(file("el.textContent = 'ready';"))).toEqual([]);
136
+ expect(islandMountClears(file('if (el.textContent === "") go();'))).toEqual([]);
137
+ });
138
+
139
+ unitTest('islands are read; their tests and other files are not', () => {
140
+ expect(readsFile('apps/web/app/posts/like.island.tsx')).toBe(true);
141
+ expect(readsFile('packages/ui/src/menu.island.tsx')).toBe(true);
142
+ expect(readsFile('apps/web/app/posts/like.island.test.tsx')).toBe(false);
143
+ expect(readsFile('apps/web/app/posts/page.tsx')).toBe(false);
144
+ });
145
+ `;
146
+
147
+ /** `guards/island-mount-clears.ts` and its test. No index, no registry — the directory registers it. */
148
+ export const islandMountClearsGuardFiles = (): readonly GeneratedFile[] => [
149
+ { path: `guards/${NAME}.ts`, contents: source() },
150
+ { path: `guards/${NAME}.test.ts`, contents: test() },
151
+ ];
@@ -34,6 +34,7 @@ const islandSource = (name: string): string => {
34
34
  // A string has no import edge, so nothing follows one into this file and the page's bundle graph
35
35
  // stays the page's (axiom 6). WHEN it wakes is the route's \`hydrate\`, never a declaration here.
36
36
 
37
+ import { mountOver } from '@ultimat3/render/client';
37
38
  import type { JSX } from 'solid-js';
38
39
  import { createSignal } from 'solid-js';
39
40
  import { render } from 'solid-js/web';
@@ -67,15 +68,15 @@ function ${Name}(props: ${Name}Props): JSX.Element {
67
68
  * The one export the hydration runtime calls — \`import(entry).then((m) => m.mount(el, props))\`.
68
69
  * \`el\` is the wrapper the page rendered, with the server's own markup already inside it.
69
70
  *
70
- * The shell is cleared first, and that line is load-bearing: Solid's \`render\` APPENDS when the
71
- * container already has children, so without it the server's markup stays on screen above a
72
- * second, live copy of the same thing.
71
+ * \`mountOver\` clears that markup for the live render (Solid's \`render\` APPENDS, so it would
72
+ * otherwise stay on screen above a second copy) and puts it BACK if the render throws: a broken
73
+ * island shows what the server sent, not a blank box, and the throw still reaches the runtime,
74
+ * which marks the root \`data-x-failed\` for the error reporter.
73
75
  */
74
76
  export function mount(el: HTMLElement, props: ${Name}Props): () => void {
75
- el.textContent = '';
76
- // Solid's \`render\` answers its disposer; returning it is what lets \`@ultimat3/testing\`
77
- // stop this island — its timers included — when a test is done with it.
78
- return render(() => <${Name} {...props} />, el);
77
+ // Solid's \`render\` answers its disposer; returning it is what lets the client router and
78
+ // \`@ultimat3/testing\` stop this island — its timers included — when they are done with it.
79
+ return mountOver(el, (root) => render(() => <${Name} {...props} />, root));
79
80
  }
80
81
  `;
81
82
  };
@@ -40,6 +40,7 @@ const formIslandSource = (
40
40
 
41
41
  import { clientTransport } from '@ultimat3/core';
42
42
  import { fromDecimal } from '@ultimat3/money';
43
+ import { mountOver } from '@ultimat3/render/client';
43
44
  import { Button, Form, Input, setSolidRuntime, UiProvider } from '@ultimat3/ui';
44
45
  import type { JSX } from 'solid-js';
45
46
  import {
@@ -151,8 +152,9 @@ function ${feature.pascal}FormBody(props: ${feature.pascal}FormProps): JSX.Eleme
151
152
  * keeps every export of solid-js alive, and the bundler cannot shake what it cannot see unused —
152
153
  * measured at 14.8 kB minified per island chunk (5.6 kB gzipped) for the namespace form.
153
154
  *
154
- * The shell is cleared first: Solid's \`render\` APPENDS when the container already has children,
155
- * so without it the server's markup stays on screen above a second, live copy of the same thing.
155
+ * \`mountOver\` clears the shell (Solid's \`render\` APPENDS, so the server's markup would stay above
156
+ * a second, live copy) and puts it back if the render throws — a broken form shows what the server
157
+ * sent, not a blank box, and the throw still reaches the runtime's \`data-x-failed\` marker.
156
158
  */
157
159
  export function mount(el: HTMLElement, props: ${feature.pascal}FormProps): () => void {
158
160
  setSolidRuntime({
@@ -164,16 +166,17 @@ export function mount(el: HTMLElement, props: ${feature.pascal}FormProps): () =>
164
166
  onCleanup,
165
167
  createRoot,
166
168
  });
167
- el.textContent = '';
168
169
  // Solid's disposer, returned: the client router calls it when it navigates away, and a mount
169
170
  // that returns nothing is X_ISLAND_DISPOSER_MISSING.
170
- return render(
171
- () => (
172
- <UiProvider locale={props.locale}>
173
- <${feature.pascal}FormBody {...props} />
174
- </UiProvider>
171
+ return mountOver(el, (root) =>
172
+ render(
173
+ () => (
174
+ <UiProvider locale={props.locale}>
175
+ <${feature.pascal}FormBody {...props} />
176
+ </UiProvider>
177
+ ),
178
+ root,
175
179
  ),
176
- el,
177
180
  );
178
181
  }
179
182
  `;
@@ -64,6 +64,7 @@ queries, jobs, MCP tools, published operations and tests it touches, each with p
64
64
  | Images | every image carries width + height or an aspect-ratio, and the priority one is never \`loading="lazy"\` | \`guards/image-dimensions.ts\` |
65
65
  | Motion | animate \`transform\` and \`opacity\` — never a layout property, never \`transition: all\` | \`guards/animated-layout-property.ts\` |
66
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\` |
67
68
  | Size | one file, one job — ${LINE_CEILING} lines of reviewable logic, and split past it | \`X_FILE_TOO_LONG\` |
68
69
 
69
70
  \`guards/\` is yours: each file is one rule, discovered by \`bunx x verify\` and run inside its
@@ -9,7 +9,8 @@
9
9
  //
10
10
  // The other five are about what the app is like to USE, which no row of `AGENTS.md` had ever been
11
11
  // about: a control a keyboard cannot reach, a focus ring taken away and not replaced, an image with
12
- // no box, an animation the compositor cannot run, and an island nobody has seen fail. Each is
12
+ // no box, an animation the compositor cannot run, an island nobody has seen fail, and one that
13
+ // fails BLANK — its server markup cleared outside `mountOver`. Each is
13
14
  // statically decidable from the file alone — the reason those five and not the many that are not.
14
15
  //
15
16
  // The seven after those are about the STYLESHEET, which Biome does not read at all: a length, a
@@ -29,6 +30,7 @@ import { bareErrorGuardFiles } from './guard-bare-error';
29
30
  import { errorDeclaredGuardFiles } from './guard-error-declared';
30
31
  import { focusVisibleGuardFiles } from './guard-focus-visible';
31
32
  import { imageDimensionsGuardFiles } from './guard-image-dimensions';
33
+ import { islandMountClearsGuardFiles } from './guard-island-mount-clears';
32
34
  import { islandWithoutStatesGuardFiles } from './guard-island-without-states';
33
35
  import { nativeConfirmGuardFiles } from './guard-native-confirm';
34
36
  import { rawBreakpointGuardFiles } from './guard-raw-breakpoint';
@@ -59,6 +61,7 @@ const SHIPPED: readonly (readonly [string, () => readonly GeneratedFile[]])[] =
59
61
  ['error-declared', errorDeclaredGuardFiles],
60
62
  ['focus-visible', focusVisibleGuardFiles],
61
63
  ['image-dimensions', imageDimensionsGuardFiles],
64
+ ['island-mount-clears', islandMountClearsGuardFiles],
62
65
  ['island-without-states', islandWithoutStatesGuardFiles],
63
66
  ['native-confirm', nativeConfirmGuardFiles],
64
67
  ['raw-breakpoint', rawBreakpointGuardFiles],
@@ -245,6 +245,7 @@ const toggleIsland =
245
245
  // reads the browser on its own: the theme the boot stamped on \`<html>\`, then \`theme.defaultMode\`
246
246
  // (stamped beside it), then the OS.
247
247
 
248
+ import { mountOver } from '@ultimat3/render/client';
248
249
  import { setSolidRuntime, ThemeToggle, UiProvider } from '@ultimat3/ui';
249
250
  import {
250
251
  createContext,
@@ -266,8 +267,9 @@ export interface ThemeToggleIslandProps {
266
267
  * The one export the hydration runtime calls. \`setSolidRuntime\` comes FIRST and is not optional:
267
268
  * \`@ultimat3/ui\` imports types from solid-js and never a runtime, so the reactive graph a
268
269
  * component reaches is the one an entry registers. Seven NAMED imports, never a namespace: a
269
- * namespace object keeps every export of solid-js alive in the chunk. The shell is cleared before
270
- * \`render\`, which APPENDS — the server's copy would otherwise stay on screen beside the live one.
270
+ * namespace object keeps every export of solid-js alive in the chunk. \`mountOver\` clears the shell
271
+ * before \`render\`, which APPENDS, and puts it back if the render throws: a broken toggle shows the
272
+ * server's copy, not a blank box, and the throw still reaches the runtime's \`data-x-failed\`.
271
273
  */
272
274
  export function mount(el: HTMLElement, props: ThemeToggleIslandProps): () => void {
273
275
  setSolidRuntime({
@@ -279,16 +281,17 @@ export function mount(el: HTMLElement, props: ThemeToggleIslandProps): () => voi
279
281
  onCleanup,
280
282
  createRoot,
281
283
  });
282
- el.textContent = '';
283
284
  // Solid's disposer, returned: the client router calls it when it navigates away, and a mount
284
285
  // that returns nothing is X_ISLAND_DISPOSER_MISSING.
285
- return render(
286
- () => (
287
- <UiProvider locale={props.locale}>
288
- <ThemeToggle mode="toggle" />
289
- </UiProvider>
286
+ return mountOver(el, (root) =>
287
+ render(
288
+ () => (
289
+ <UiProvider locale={props.locale}>
290
+ <ThemeToggle mode="toggle" />
291
+ </UiProvider>
292
+ ),
293
+ root,
290
294
  ),
291
- el,
292
295
  );
293
296
  }
294
297
  `;
@@ -1,6 +1,7 @@
1
1
  // `x new`'s `x.verify.json`: the suite floor and the coverage bar every scaffolded app starts on.
2
2
  // Split from `scaffold-repo.ts` (the repo's root files), which had reached the 500-line ceiling.
3
3
 
4
+ import { STATEMENTS_MAX } from '@ultimat3/testing';
4
5
  import type { CoverageExclude } from '../coverage-floor';
5
6
  import { COVERAGE_BAR } from '../coverage-floor';
6
7
  import type { VerifyStepName } from '../verify-step';
@@ -91,6 +92,9 @@ export const verifyFloor = (example: boolean): string =>
91
92
  },
92
93
  // The rolling rail judges from the first migration: a new app has nothing to grandfather.
93
94
  rollingSince: '0',
95
+ // Nor does the exercise pass: every proof must ask, and one call sends the default ceiling
96
+ // at most. An app scaffolded before this key reads warnings instead (`exercise-floor.ts`).
97
+ exercise: { unprovenMax: 0, statementsMax: STATEMENTS_MAX },
94
98
  },
95
99
  null,
96
100
  2,
@@ -27,6 +27,18 @@ import { readFileSync } from 'node:fs'; // why: Bun ships no synchronous file re
27
27
  // why: Bun exposes no path-join primitive.
28
28
  import { join } from 'node:path';
29
29
 
30
+ /**
31
+ * Keys that LOCATE something on this host and never change what the app does: a browser binary
32
+ * (`browser-launcher.ts`'s `BROWSER_PATH_VARS`, restated so this file does not load the CDP driver
33
+ * graph; `test-dotenv.test.ts` pins the two lists together) and the temp directory. Scrubbing one
34
+ * because `.env.development` happens to name it only breaks the child — e2e stops finding Chrome.
35
+ */
36
+ export const HOST_LOCATOR_KEYS: readonly string[] = [
37
+ 'PUPPETEER_EXECUTABLE_PATH',
38
+ 'CHROME_PATH',
39
+ 'TMPDIR',
40
+ ];
41
+
30
42
  /** Bun's own grammar, matched against `env-example.ts`'s `ENV_KEY_RE` (kept separate: see header). */
31
43
  const ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
32
44
 
@@ -72,14 +84,15 @@ export interface DevOnlyLeakInput {
72
84
 
73
85
  /**
74
86
  * The pure decision, no filesystem: every key `.env.development`/`.env.development.local` would
75
- * set, where `env`'s CURRENT value for that key is exactly what the file would have set. See this
76
- * file's header for why a legitimate test file declaring the same key does not exempt it.
87
+ * set, where `env`'s CURRENT value for that key is exactly what the file would have set — a
88
+ * `HOST_LOCATOR_KEYS` member excepted. See this file's header for why a legitimate test file declaring the same key does not exempt it.
77
89
  */
78
90
  export function devOnlyLeakedKeys(input: DevOnlyLeakInput): readonly string[] {
79
91
  const merged = new Map(parseDotenvValues(input.devText));
80
92
  for (const [key, value] of parseDotenvValues(input.devLocalText)) merged.set(key, value);
81
93
  const leaked: string[] = [];
82
94
  for (const [key, devValue] of merged) {
95
+ if (HOST_LOCATOR_KEYS.includes(key)) continue;
83
96
  // `Object.hasOwn` FIRST: `key` is data (a name out of a dotenv file), and `env['constructor']`
84
97
  // on a plain object answers `Object.prototype`'s member, not `undefined` — the rule
85
98
  // `scripts/proto-index.ts` ratchets, with its own sanctioned repair.
@@ -1,12 +1,12 @@
1
1
  // The app's brand, declared once as `export const brand = defineTheme(…)` in
2
- // `apps/web/shared/theme.ts`, read here and nowhere else: the `<style>` every document the boot
3
- // renders carries after its stylesheet, and the body `style-src` admits. No module, no brand: an
4
- // unthemed app emits no tag and extends no policy.
2
+ // `apps/web/shared/theme.ts`, read here and nowhere else: its CSS is appended to every surface
3
+ // stylesheet (`style-bundle.ts`), so it rides the hashed, immutable file — no inline `<style>`, no
4
+ // `style-src` hash. No module, no brand: an unthemed app's sheets are unchanged.
5
5
 
6
6
  // why: Bun exposes no path-join primitive, and the module path is app-root-relative.
7
7
  import { join } from 'node:path';
8
8
  import { ConfigInvalidError, describeValue } from '@ultimat3/core';
9
- import { renderHead } from '@ultimat3/render';
9
+ import { setBrandStyles } from './style-bundle';
10
10
 
11
11
  /** The conventional module, beside `shared/global.ts` — one fixed path, as `API_INDEX` is. */
12
12
  export const APP_THEME_MODULE = 'apps/web/shared/theme.ts';
@@ -14,36 +14,34 @@ export const APP_THEME_MODULE = 'apps/web/shared/theme.ts';
14
14
  export const APP_THEME_EXPORT = 'brand';
15
15
 
16
16
  export interface ThemeBrand {
17
- /** The rendered `<style>`, for `DocumentOptions.brandHead`. */
18
- readonly head: string;
19
- /** Exactly the text between the tags — the body a boot hands `inlineStyleSources`. */
20
- readonly style: string;
17
+ /** The brand's CSS, exactly as `defineTheme()` rendered it — now the tail of every sheet. */
18
+ readonly css: string;
21
19
  }
22
20
 
23
21
  /** Code to paste, as `loadAppConfig`'s is: the module path is already in the cause. */
24
22
  const FIX = `export const ${APP_THEME_EXPORT} = defineTheme({ preset: 'scifi' });`;
25
23
 
26
24
  /**
27
- * `undefined` when the app has no theme module or its brand renders no CSS. A module that will not
28
- * import throws as it did, so a palette `defineTheme()` refuses fails the boot with
29
- * `X_UI_CONTRAST_INSUFFICIENT` (or its token code) and not a rewording of it.
25
+ * `undefined` when the app has no theme module or its brand renders no CSS. Either way the answer
26
+ * is REGISTERED with the stylesheet table, so the next `styleBundle()` carries it (or drops a
27
+ * previous app's). A module that will not import throws as it did, so a palette `defineTheme()`
28
+ * refuses fails the boot with `X_UI_CONTRAST_INSUFFICIENT` (or its token code), not a rewording.
30
29
  */
31
30
  export async function loadThemeBrand(root: string): Promise<ThemeBrand | undefined> {
32
31
  const path = join(root, APP_THEME_MODULE);
33
- if (!(await Bun.file(path).exists())) return undefined;
34
- const module = (await import(path)) as Record<string, unknown>;
35
- const css = brandCss(path, module);
36
- if (css.length === 0) return undefined;
37
- // `renderHead` escapes `</` in a style body, which would make the tag's text differ from the
38
- // hashed one — so a body that needs escaping is refused above rather than escaped here.
39
- return { head: renderHead([{ kind: 'style', key: 'style:brand', content: css }]), style: css };
32
+ const css = (await Bun.file(path).exists())
33
+ ? brandCss(path, (await import(path)) as Record<string, unknown>)
34
+ : '';
35
+ setBrandStyles(css);
36
+ return css.length === 0 ? undefined : { css };
40
37
  }
41
38
 
42
39
  /**
43
40
  * The brand's stylesheet, read structurally: `@ultimat3/ui` is a tier below and this package does
44
41
  * not import it, so a `Brand` is `{ css: string }`. `defineTheme()` never emits `<` — its values
45
42
  * are validated against grammars that exclude it — so one here came from a hand-built object, and
46
- * it is the one character that could end the element and start markup.
43
+ * a sheet every document links is not where an unvalidated one goes. Kept from the inline era,
44
+ * when `<` could also close the element and start markup.
47
45
  */
48
46
  function brandCss(path: string, module: Record<string, unknown>): string {
49
47
  const brand = Object.hasOwn(module, APP_THEME_EXPORT) ? module[APP_THEME_EXPORT] : undefined;
@@ -57,7 +55,7 @@ function brandCss(path: string, module: Record<string, unknown>): string {
57
55
  }
58
56
  if (css.includes('<')) {
59
57
  throw new ConfigInvalidError({
60
- cause: `${path}'s ${APP_THEME_EXPORT}.css contains "<", which defineTheme() never emits and which could close the <style> element it is inlined in`,
58
+ cause: `${path}'s ${APP_THEME_EXPORT}.css contains "<", which defineTheme() never emits, so the brand was hand-built and is not appended to every stylesheet the documents link`,
61
59
  fix: FIX,
62
60
  meta: { key: APP_THEME_EXPORT },
63
61
  });
@@ -0,0 +1,109 @@
1
+ // A Bun-floor hop's coverage rebaseline: Bun 1.4.4 counted functions differently with no test or
2
+ // source changed, so a hop that moves the Bun floor measures the unit suite once (the installed
3
+ // CLI's `verify --only unit`) and, only when that lands under the stated floor, moves the floor to
4
+ // what it measured with a dated `why`. Written into the hop's diff and reported, never silently.
5
+
6
+ // why: Bun exposes no path-join primitive; `x.verify.json` sits at the app root.
7
+ import { join } from 'node:path';
8
+ import { t } from '@ultimat3/schema';
9
+ import type { CoverageFloor } from './coverage-floor';
10
+ import { COVERAGE_FIELD, floorFor, readCoverageFloor, shown } from './coverage-floor';
11
+ import { msg } from './messages';
12
+ import { documentIn } from './upgrade-document';
13
+ import type { InstalledCli } from './upgrade-guards';
14
+ import { parseJson } from './upgrade-registry';
15
+ import { VERIFY_FLOOR_FILE } from './verify-floor';
16
+
17
+ const NUMBERS = t.object({ lines: t.number, funcs: t.number });
18
+ const UNIT = t.object({
19
+ steps: t.array(
20
+ t.object({
21
+ name: t.string,
22
+ findings: t.optional(t.array(t.object({ code: t.string }))),
23
+ }),
24
+ ),
25
+ data: t.object({ coverage: t.object({ unit: NUMBERS }) }),
26
+ });
27
+
28
+ interface Numbers {
29
+ readonly lines: number;
30
+ readonly funcs: number;
31
+ }
32
+
33
+ /** What the `why` says about the hop that moved the floor. */
34
+ export interface CoverageRebaseline {
35
+ readonly release: string;
36
+ readonly bunFrom: string | null;
37
+ readonly bunTo: string;
38
+ /** `YYYY-MM-DD`, UTC: the day the measurement was taken. */
39
+ readonly today: string;
40
+ }
41
+
42
+ /** What the report carries: the floor before, the one written, and the measurement behind it. */
43
+ export interface HopCoverage {
44
+ readonly file: string;
45
+ readonly measured: Numbers;
46
+ readonly from: Numbers;
47
+ readonly to: Numbers;
48
+ readonly why: string;
49
+ }
50
+
51
+ /** The app's floor file, as an object, with the coverage floor in it — or undefined: nothing to move. */
52
+ export async function statedCoverage(
53
+ root: string,
54
+ ): Promise<
55
+ { readonly payload: Record<string, unknown>; readonly floor: CoverageFloor } | undefined
56
+ > {
57
+ const file = Bun.file(join(root, VERIFY_FLOOR_FILE));
58
+ if (!(await file.exists())) return undefined;
59
+ const payload = parseJson(await file.text());
60
+ if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) return undefined;
61
+ const record = payload as Record<string, unknown>;
62
+ const floor = readCoverageFloor(record).coverage;
63
+ return floor === undefined ? undefined : { payload: record, floor };
64
+ }
65
+
66
+ /** Measures once; moves only the number that fell under its floor, and only to what was measured. */
67
+ export async function rebaselineCoverage(input: {
68
+ readonly cli: InstalledCli;
69
+ readonly root: string;
70
+ readonly stated: NonNullable<Awaited<ReturnType<typeof statedCoverage>>>;
71
+ readonly bun: CoverageRebaseline;
72
+ }): Promise<HopCoverage | null> {
73
+ const { cli, root, stated, bun } = input;
74
+ const parsed = UNIT.safeParse(
75
+ documentIn((await cli(['verify', '--only', 'unit', '--json'])).stdout),
76
+ );
77
+ if (parsed.issues !== undefined) return null;
78
+ const document = parsed.value as {
79
+ readonly steps: readonly { name: string; findings?: readonly { code: string }[] }[];
80
+ readonly data: { readonly coverage: { readonly unit: Numbers } };
81
+ };
82
+ const below = document.steps
83
+ .find((step) => step.name === 'unit')
84
+ ?.findings?.some((finding) => finding.code === 'X_COVERAGE_BELOW_FLOOR');
85
+ if (below !== true) return null;
86
+ const measured = document.data.coverage.unit;
87
+ const from = { lines: stated.floor.lines, funcs: stated.floor.funcs };
88
+ const to = {
89
+ lines: measured.lines < from.lines ? floorFor(measured.lines) : from.lines,
90
+ funcs: measured.funcs < from.funcs ? floorFor(measured.funcs) : from.funcs,
91
+ };
92
+ const said = msg('cli.upgrade.coverage.why', {
93
+ date: bun.today,
94
+ release: bun.release,
95
+ bunFrom: bun.bunFrom ?? msg('cli.upgrade.coverage.unpinned'),
96
+ bunTo: bun.bunTo,
97
+ lines: shown(measured.lines),
98
+ funcs: shown(measured.funcs),
99
+ fromLines: String(from.lines),
100
+ fromFuncs: String(from.funcs),
101
+ toLines: String(to.lines),
102
+ toFuncs: String(to.funcs),
103
+ });
104
+ const why = stated.floor.why === undefined ? said : `${said} ${stated.floor.why}`;
105
+ const raw = stated.payload[COVERAGE_FIELD] as Record<string, unknown>;
106
+ const next = { ...stated.payload, [COVERAGE_FIELD]: { ...raw, ...to, why } };
107
+ await Bun.write(join(root, VERIFY_FLOOR_FILE), `${JSON.stringify(next, null, 2)}\n`);
108
+ return { file: VERIFY_FLOOR_FILE, measured, from, to, why };
109
+ }
@@ -0,0 +1,18 @@
1
+ // The one JSON document on a child CLI's stdout, read as a foreign document: a hop's gate, the
2
+ // guards it installs and every caller that spawns an installed CLI share this one reading of it.
3
+
4
+ import { parseJson } from './upgrade-registry';
5
+
6
+ /**
7
+ * Whole first; then its last line that parses, because the CLI that keeps fd 1 to one document
8
+ * under `--json` is a recent one and a hop can install one that still logs a boot line ahead of it.
9
+ */
10
+ export function documentIn(stdout: string): unknown {
11
+ const whole = parseJson(stdout.trim());
12
+ if (whole !== undefined) return whole;
13
+ const lines = stdout.split('\n').filter((line) => line.trimStart().startsWith('{'));
14
+ return lines
15
+ .reverse()
16
+ .map(parseJson)
17
+ .find((parsed) => parsed !== undefined);
18
+ }
@@ -0,0 +1,53 @@
1
+ // A hop's exercise ratchet: after the hop's `x exercise` wrote `.x/exercise.json`, an app whose
2
+ // `x.verify.json` states no `exercise.unprovenMax` / `statementsMax` gets the figures that pass
3
+ // measured, so the floor starts where the app is and only falls. A key the app already wrote is
4
+ // never touched. Written into the hop's diff and reported, never silently.
5
+
6
+ // why: Bun exposes no path-join primitive; `x.verify.json` sits at the app root.
7
+ import { join } from 'node:path';
8
+ import type { ExerciseFloor } from './exercise-floor';
9
+ import { readExerciseFloor } from './exercise-floor';
10
+ import {
11
+ exerciseReportStamp,
12
+ measuredExerciseFloor,
13
+ withExerciseFloor,
14
+ } from './exercise-floor-report';
15
+ import { parseJson } from './upgrade-registry';
16
+ import { VERIFY_FLOOR_FILE } from './verify-floor';
17
+
18
+ /** What the report carries: the figures written, each one the hop's own pass measured. */
19
+ export interface HopExerciseFloor {
20
+ readonly file: string;
21
+ readonly written: ExerciseFloor;
22
+ }
23
+
24
+ /**
25
+ * Writes the measured figure for each exercise key the floor file lacks; null when none. `before`
26
+ * is the report's stamp ahead of the hop's `x exercise`: a report that pass did not rewrite (it
27
+ * died, or is a CLI with no report) holds another pass's figures and is never ratcheted.
28
+ */
29
+ export async function ratchetExerciseFloor(
30
+ root: string,
31
+ before: number | undefined,
32
+ ): Promise<HopExerciseFloor | null> {
33
+ const after = await exerciseReportStamp(root);
34
+ if (after === undefined || after === before) return null;
35
+ const file = Bun.file(join(root, VERIFY_FLOOR_FILE));
36
+ if (!(await file.exists())) return null;
37
+ const text = await file.text();
38
+ const payload = parseJson(text);
39
+ if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) return null;
40
+ const stated = readExerciseFloor(payload as Record<string, unknown>);
41
+ // A malformed key is the `manifest` step's finding; writing beside it would hide it.
42
+ if (stated.problems.length > 0) return null;
43
+ const measured = await measuredExerciseFloor(root);
44
+ if (measured === undefined) return null;
45
+ const written: { unprovenMax?: number; statementsMax?: number } = {};
46
+ if (stated.floor?.unprovenMax === undefined) written.unprovenMax = measured.unprovenMax;
47
+ if (stated.floor?.statementsMax === undefined) written.statementsMax = measured.statementsMax;
48
+ if (Object.keys(written).length === 0) return null;
49
+ const next = withExerciseFloor(text, written);
50
+ if (next === text) return null;
51
+ await Bun.write(join(root, VERIFY_FLOOR_FILE), next);
52
+ return { file: VERIFY_FLOOR_FILE, written };
53
+ }