@ultimat3/cli 31.26.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 (206) hide show
  1. package/CLAUDE.md +47 -37
  2. package/README.md +19 -8
  3. package/package.json +29 -29
  4. package/src/app-manifest.ts +6 -1
  5. package/src/app-mcp.ts +17 -3
  6. package/src/cmd-cache-spec.ts +5 -2
  7. package/src/cmd-db-spec.ts +2 -3
  8. package/src/cmd-db.ts +0 -2
  9. package/src/cmd-deploy-verify-sample.ts +93 -0
  10. package/src/cmd-deploy-verify.ts +2 -41
  11. package/src/cmd-dev-spec.ts +15 -1
  12. package/src/cmd-dev.ts +31 -4
  13. package/src/cmd-doctor.ts +15 -4
  14. package/src/cmd-exercise-spec.ts +7 -1
  15. package/src/cmd-exercise.ts +22 -10
  16. package/src/cmd-generate.ts +2 -0
  17. package/src/cmd-jobs-spec.ts +3 -6
  18. package/src/cmd-jobs.ts +1 -7
  19. package/src/cmd-logs-spec.ts +2 -1
  20. package/src/cmd-logs.ts +9 -28
  21. package/src/cmd-planned.ts +11 -45
  22. package/src/cmd-profile-frames.ts +99 -0
  23. package/src/cmd-profile-spec.ts +24 -0
  24. package/src/cmd-profile.ts +164 -0
  25. package/src/cmd-repro-spec.ts +13 -1
  26. package/src/cmd-repro.ts +37 -5
  27. package/src/cmd-status-sample.ts +57 -0
  28. package/src/cmd-status-spec.ts +30 -0
  29. package/src/cmd-status.ts +108 -0
  30. package/src/cmd-token-spec.ts +5 -2
  31. package/src/cmd-token.ts +7 -3
  32. package/src/cmd-upgrade-codemods.ts +71 -0
  33. package/src/cmd-upgrade-spec.ts +19 -5
  34. package/src/cmd-upgrade.ts +91 -34
  35. package/src/codemods/agents-dev-mcp.ts +50 -0
  36. package/src/codemods/authenticator-session-refusal.ts +214 -0
  37. package/src/codemods/biome-no-default-export.ts +58 -0
  38. package/src/codemods/bunfig-island-coverage.ts +33 -0
  39. package/src/codemods/chart-dashboard.ts +73 -0
  40. package/src/codemods/ci-e2e-browser-stock.ts +75 -0
  41. package/src/codemods/ci-e2e-browser.ts +63 -0
  42. package/src/codemods/codemod.ts +58 -0
  43. package/src/codemods/define-error-leaf.ts +73 -0
  44. package/src/codemods/docs-ci-parts.ts +65 -0
  45. package/src/codemods/docs-gate-prose.ts +53 -0
  46. package/src/codemods/docs-island-rows.ts +31 -0
  47. package/src/codemods/docs-shipped-guards.ts +100 -0
  48. package/src/codemods/docs-test-services.ts +62 -0
  49. package/src/codemods/engine-diff.ts +104 -0
  50. package/src/codemods/engine-edits.ts +111 -0
  51. package/src/codemods/engine-fs.ts +95 -0
  52. package/src/codemods/engine.ts +191 -0
  53. package/src/codemods/format-edited-hook-3122.ts +28 -0
  54. package/src/codemods/format-edited-hook.ts +152 -0
  55. package/src/codemods/helm-alerts-objective.ts +105 -0
  56. package/src/codemods/helm-alerts-stock.ts +108 -0
  57. package/src/codemods/index.ts +56 -0
  58. package/src/codemods/metrics-probe-healthz.ts +47 -0
  59. package/src/codemods/pending.ts +36 -0
  60. package/src/codemods/repro-gitignore.ts +40 -0
  61. package/src/codemods/runtime-pin-lines.ts +109 -0
  62. package/src/codemods/runtime-pin.ts +116 -0
  63. package/src/codemods/solid-floor.ts +63 -0
  64. package/src/codemods/test-ports.ts +86 -0
  65. package/src/codemods/test-suites.ts +37 -0
  66. package/src/codemods/theme-toggle-mount-over.ts +70 -0
  67. package/src/codemods/vendored-guards.ts +186 -0
  68. package/src/codemods/verify-floor-skips.ts +88 -0
  69. package/src/codemods/verify-floor-steps.ts +90 -0
  70. package/src/coverage-island.ts +121 -0
  71. package/src/coverage-lcov.ts +49 -5
  72. package/src/coverage-remap.ts +146 -0
  73. package/src/db-replay-engine-prepared.ts +66 -0
  74. package/src/db-replay-engine-template.ts +156 -0
  75. package/src/db-replay-engine.ts +4 -0
  76. package/src/db-replay-scratch-reap.ts +54 -0
  77. package/src/deploy-verify-flags.ts +9 -2
  78. package/src/deploy-verify-grade.ts +10 -3
  79. package/src/dev-boot.ts +14 -1
  80. package/src/dev-dashboard-guard.ts +57 -10
  81. package/src/dev-host.ts +46 -0
  82. package/src/dev-tls-cache.ts +103 -0
  83. package/src/dev-tls-der.ts +69 -0
  84. package/src/dev-tls.ts +120 -0
  85. package/src/doctor-advisory-floors.ts +113 -0
  86. package/src/doctor-browser.ts +60 -0
  87. package/src/doctor-guards.ts +39 -86
  88. package/src/doctor-superseded.ts +67 -0
  89. package/src/error-codes-doctor.ts +12 -4
  90. package/src/error-codes-verify.ts +47 -0
  91. package/src/error-codes.ts +20 -23
  92. package/src/exercise-database.ts +47 -9
  93. package/src/exercise-push-device.ts +51 -0
  94. package/src/exercise-route-api.ts +74 -0
  95. package/src/exercise-routes.ts +14 -5
  96. package/src/exercise-services.ts +3 -1
  97. package/src/exercise-shard-flag.ts +47 -0
  98. package/src/fix-command.ts +2 -2
  99. package/src/generate-factories.ts +5 -11
  100. package/src/generate-feature-required.ts +9 -4
  101. package/src/generate-files.ts +26 -7
  102. package/src/generate-kinds.ts +5 -1
  103. package/src/guards-built-in-codes.ts +36 -0
  104. package/src/guards-built-in-refusal.ts +25 -0
  105. package/src/guards-built-in.ts +134 -0
  106. package/src/guards-materialize.ts +42 -0
  107. package/src/guards-paths.ts +37 -0
  108. package/src/guards-shipped-names.ts +38 -0
  109. package/src/guards-vendored.ts +73 -0
  110. package/src/guards.ts +105 -34
  111. package/src/index.ts +10 -0
  112. package/src/island-bundle-options.ts +48 -0
  113. package/src/island-bundle.ts +18 -46
  114. package/src/island-link.ts +5 -0
  115. package/src/island-outputs.ts +5 -0
  116. package/src/lint-findings.ts +3 -3
  117. package/src/mcp-errors-verify.ts +35 -0
  118. package/src/mcp-errors.ts +21 -20
  119. package/src/mcp-host-logs.ts +121 -0
  120. package/src/mcp-host.ts +12 -73
  121. package/src/measure-scope.ts +23 -3
  122. package/src/messages-floor.ts +19 -0
  123. package/src/messages-repro.ts +16 -2
  124. package/src/messages-status.ts +10 -0
  125. package/src/messages-upgrade.ts +15 -0
  126. package/src/messages.ts +22 -1
  127. package/src/registry.ts +4 -0
  128. package/src/repro-archive-collect.ts +161 -0
  129. package/src/repro-archive-write.ts +96 -0
  130. package/src/repro-archive.ts +161 -0
  131. package/src/repro-bundle.ts +8 -16
  132. package/src/repro-errors.ts +14 -2
  133. package/src/repro-framework.ts +53 -0
  134. package/src/repro-parse.ts +87 -0
  135. package/src/repro-redact.ts +218 -0
  136. package/src/repro-scrub.ts +257 -0
  137. package/src/role-start-types.ts +7 -0
  138. package/src/role-start.ts +4 -0
  139. package/src/serve-boot.ts +7 -1
  140. package/src/serve-env-tls.ts +57 -0
  141. package/src/solid-loader.ts +27 -10
  142. package/src/superseded-match.ts +87 -0
  143. package/src/superseded.ts +84 -0
  144. package/src/templates/bun-image.ts +48 -0
  145. package/src/templates/generate-export-rows.ts +136 -0
  146. package/src/templates/generate-import-rows.ts +186 -0
  147. package/src/templates/generate-rows-slice.ts +95 -0
  148. package/src/templates/github/ci.yml.ts +5 -1
  149. package/src/templates/guard-released-forms.ts +112 -0
  150. package/src/templates/guard-runtime-pin-test.ts +54 -0
  151. package/src/templates/guard-runtime-pin.ts +189 -0
  152. package/src/templates/scaffold-claude-agents.ts +6 -6
  153. package/src/templates/scaffold-claude-commands.ts +1 -1
  154. package/src/templates/scaffold-claude-hook.ts +18 -8
  155. package/src/templates/scaffold-claude.ts +2 -2
  156. package/src/templates/scaffold-db-package.ts +3 -0
  157. package/src/templates/scaffold-docs.ts +34 -30
  158. package/src/templates/scaffold-guards.ts +73 -39
  159. package/src/templates/scaffold-repo.ts +4 -8
  160. package/src/templates/scaffold-site.ts +4 -1
  161. package/src/templates/scaffold-suites.ts +72 -0
  162. package/src/templates/scaffold-test-services.ts +35 -10
  163. package/src/templates/scaffold-verify-floor.ts +53 -31
  164. package/src/templates/shapes/api.ts +4 -0
  165. package/src/templates/slice-foundation.ts +3 -3
  166. package/src/unthrown-codes.ts +3 -1
  167. package/src/upgrade-bun-floor.ts +4 -0
  168. package/src/upgrade-clean-tree.ts +54 -0
  169. package/src/upgrade-gate-codemods-install.ts +40 -0
  170. package/src/upgrade-gate-codemods.ts +151 -0
  171. package/src/upgrade-gate.ts +44 -7
  172. package/src/upgrade-guards-baseline.ts +43 -0
  173. package/src/upgrade-guards.ts +37 -2
  174. package/src/upgrade-lock.ts +118 -0
  175. package/src/upgrade-plan.ts +2 -1
  176. package/src/upgrade-report-codemods.ts +54 -0
  177. package/src/upgrade-report.ts +55 -27
  178. package/src/upgrade-signals.ts +91 -0
  179. package/src/upgrade-unfinished.ts +61 -0
  180. package/src/verify-coverage-run.ts +42 -11
  181. package/src/verify-e2e.ts +115 -4
  182. package/src/verify-floor.ts +27 -0
  183. package/src/verify-guard-baseline.ts +109 -0
  184. package/src/verify-live.ts +72 -0
  185. package/src/verify-merge-skips.ts +51 -0
  186. package/src/verify-merge.ts +36 -2
  187. package/src/verify-run.ts +48 -7
  188. package/src/verify-services.ts +287 -0
  189. package/src/verify-skip-reason.ts +53 -0
  190. package/src/verify-strict.ts +108 -0
  191. package/src/verify-test-command.ts +129 -0
  192. package/src/verify-tests.ts +39 -126
  193. package/types/babel-modules.d.ts +2 -0
  194. package/wiki/CLI-Reference.md +200 -27
  195. package/wiki/Caching-And-Invalidation.md +1 -1
  196. package/wiki/Entities-And-Migrations.md +1 -1
  197. package/wiki/Interface-Rules.md +17 -8
  198. package/wiki/Jobs-And-Workflows.md +3 -3
  199. package/wiki/Known-Gaps.md +5 -1
  200. package/wiki/MCP-And-AI.md +1 -1
  201. package/wiki/Observability.md +1 -0
  202. package/wiki/PWA-And-Offline.md +1 -1
  203. package/wiki/Project-Layout.md +4 -4
  204. package/wiki/Troubleshooting.md +3 -3
  205. package/wiki/Tutorial-05-Deploy-Free.md +2 -2
  206. package/wiki/Upgrading.md +8 -0
@@ -0,0 +1,257 @@
1
+ // Single responsibility: what a repro bundle may say about the MACHINE and the people on it. The app
2
+ // root, home, secret-named / URL / dotenv env values (and a URL's credentials in every encoding),
3
+ // config hostnames, any URL's userinfo and query values, emails and IPs become tokens; a frame's
4
+ // absolute path is made relative. A value it was never told about is NOT found: say so to the user.
5
+
6
+ import { isRedactedKey } from '@ultimat3/core';
7
+
8
+ export interface ScrubEnv {
9
+ readonly name: string;
10
+ readonly value: string | undefined;
11
+ /** `process`: hidden only when secret-named or a URL. `dotenv`: an app file's, always hidden. */
12
+ readonly from: 'process' | 'dotenv';
13
+ }
14
+
15
+ export interface ScrubSources {
16
+ /** The app root, absolute. Becomes `.`. */
17
+ readonly root: string;
18
+ /** Every spelling of the home directory known here. Each becomes `~`. */
19
+ readonly homes: readonly string[];
20
+ readonly env: readonly ScrubEnv[];
21
+ /** Hostnames named by the config (and the machine's own); each becomes `[host]`. */
22
+ readonly hosts: readonly string[];
23
+ }
24
+
25
+ export interface ScrubReport {
26
+ /** Names (never values) of the env vars whose value was found and replaced, sorted. */
27
+ readonly env: readonly string[];
28
+ /** How many distinct hostnames were found and replaced. */
29
+ readonly hosts: number;
30
+ }
31
+
32
+ export interface Scrubber {
33
+ /** Every string leaf and key of a JSON-safe value, scrubbed. */
34
+ value(value: unknown): unknown;
35
+ /** A cause or a stack frame: scrubbed, then any absolute path left made relative. */
36
+ location(text: string): string;
37
+ report(): ScrubReport;
38
+ }
39
+
40
+ interface Needle {
41
+ readonly find: string;
42
+ readonly replace: string;
43
+ readonly env?: string;
44
+ readonly host?: true;
45
+ /** Matched as a whole token only: a URL's user `app` must not eat the `app` in `apps/`. */
46
+ readonly word?: true;
47
+ }
48
+
49
+ /** Shorter than this, a dotenv value is a flag (`true`, `3000`) that would match everywhere. */
50
+ const MIN_ENV_VALUE = 6;
51
+ /** A secret-NAMED var, or a URL's credential, hides from this length: a PIN is still a credential. */
52
+ const MIN_SECRET_VALUE = 3;
53
+ const LOOPBACK = new Set(['localhost', '127.0.0.1', '0.0.0.0', '::1', '[::1]']);
54
+
55
+ const parseUrl = (text: string): URL | undefined => {
56
+ if (!text.includes('://')) return undefined;
57
+ try {
58
+ return new URL(text.trim());
59
+ } catch {
60
+ return undefined;
61
+ }
62
+ };
63
+
64
+ /** The hostname inside an env value or config string that is a URL or a DSN, else `undefined`. */
65
+ export function hostOf(text: string): string | undefined {
66
+ const host = parseUrl(text)?.hostname.toLowerCase();
67
+ return host === undefined || host === '' || LOOPBACK.has(host) ? undefined : host;
68
+ }
69
+
70
+ const decoded = (text: string): string => {
71
+ try {
72
+ return decodeURIComponent(text);
73
+ } catch {
74
+ return text;
75
+ }
76
+ };
77
+
78
+ /** Every spelling a credential travels in: as written, URL-decoded, and base64 (a Basic header). */
79
+ function credentialSpellings(value: string): string[] {
80
+ const url = parseUrl(value);
81
+ if (url === undefined || (url.username === '' && url.password === '')) {
82
+ return base64Of([value]);
83
+ }
84
+ const user = decoded(url.username);
85
+ const pass = decoded(url.password);
86
+ return [
87
+ url.username,
88
+ url.password,
89
+ user,
90
+ pass,
91
+ ...base64Of([`${user}:${pass}`, `${url.username}:${url.password}`]),
92
+ ];
93
+ }
94
+
95
+ /**
96
+ * Base64 of each text's UTF-8 bytes — what a Basic header holds; `btoa` alone throws past Latin-1
97
+ * (`pässwörd€`) and took `x repro --bundle` down with it. A spelling that cannot be built is
98
+ * skipped, never the scrub.
99
+ */
100
+ function base64Of(texts: readonly string[]): string[] {
101
+ const out: string[] = [];
102
+ for (const text of texts) {
103
+ try {
104
+ out.push(btoa(String.fromCharCode(...new TextEncoder().encode(text))));
105
+ } catch {
106
+ // One spelling fewer: the raw and decoded values are still needles.
107
+ }
108
+ }
109
+ return out;
110
+ }
111
+
112
+ /** Both separators of a path, so a Windows root pasted either way is found. */
113
+ const spellings = (path: string): string[] =>
114
+ [...new Set([path, path.replaceAll('\\', '/'), path.replaceAll('/', '\\')])].filter(
115
+ (spelling) => spelling.length > 1,
116
+ );
117
+
118
+ function needlesOf(sources: ScrubSources): { paths: Needle[]; values: Needle[] } {
119
+ const paths = [
120
+ ...spellings(sources.root).map((find) => ({ find, replace: '.' })),
121
+ ...sources.homes.flatMap(spellings).map((find) => ({ find, replace: '~' })),
122
+ ];
123
+ const values: Needle[] = [];
124
+ const hosts = new Set(sources.hosts.map((host) => host.toLowerCase()));
125
+ for (const { name, value: raw, from } of sources.env) {
126
+ // Trimmed first: a dotenv `TOKEN="abc\n"` is held by the app, and reaches a log, as `abc`.
127
+ const value = raw?.trim();
128
+ if (value === undefined || value === '') continue;
129
+ const host = hostOf(value);
130
+ if (host !== undefined) hosts.add(host);
131
+ const secret = isRedactedKey(name);
132
+ const hidden = secret || host !== undefined || from === 'dotenv';
133
+ if (!hidden) continue;
134
+ const min = secret ? MIN_SECRET_VALUE : MIN_ENV_VALUE;
135
+ if (value.length >= min) values.push({ find: value, replace: `[env:${name}]`, env: name });
136
+ if (!secret && host === undefined) continue;
137
+ for (const find of credentialSpellings(value)) {
138
+ if (find.length >= MIN_SECRET_VALUE) {
139
+ values.push({ find, replace: `[env:${name}]`, env: name, word: true });
140
+ }
141
+ }
142
+ }
143
+ for (const host of hosts) {
144
+ if (host.length > 2 && !LOOPBACK.has(host))
145
+ values.push({ find: host, replace: '[host]', host: true });
146
+ }
147
+ // Longest first: a URL value is replaced whole before the host inside it is looked for.
148
+ const longest = (a: Needle, b: Needle): number => b.find.length - a.find.length;
149
+ return { paths: paths.sort(longest), values: values.sort(longest) };
150
+ }
151
+
152
+ const literal = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
153
+
154
+ /** A URL in prose: its scheme, then everything up to a space, a quote or a bracket. */
155
+ const URL_TEXT = /\b[a-z][a-z0-9+.-]*:\/\/[^\s'"`<>()]+/gi;
156
+ /** Any URL's userinfo and query VALUES: credentials and tokens ride in both. */
157
+ function withoutUrlSecrets(text: string): string {
158
+ return text.replace(URL_TEXT, (url) =>
159
+ url
160
+ .replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@]*@/i, '$1[cred]@')
161
+ .replace(/\?[^#]*/, (query) => query.replace(/=[^&]*/g, '=[redacted]')),
162
+ );
163
+ }
164
+
165
+ const EMAIL = /(?<![\w.%+-])[\w.%+-]+@[a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z]{2,}(?![\w-])/gi;
166
+ const OCTET = '(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)';
167
+ const IPV4 = new RegExp(`(?<![\\w.])(?:${OCTET}\\.){3}${OCTET}(?![\\w.])`, 'g');
168
+ const H = '[0-9a-f]{1,4}';
169
+ /** Eight groups, or a `::` with a group on at least one side: never a clock time or `A::b` in a word. */
170
+ const IPV6 = new RegExp(
171
+ `(?<![\\w:.])(?:(?:${H}:){7}${H}|(?:${H}:){1,7}:(?:${H}(?::${H}){0,5})?|::${H}(?::${H}){0,6})(?![\\w:])`,
172
+ 'gi',
173
+ );
174
+
175
+ /** The first segment of a path that is the machine's, whatever its extension. */
176
+ const SYSTEM_ROOT =
177
+ /^\/(?:home|Users|root|tmp|private|var|opt|usr|etc|srv|mnt|nix|snap|proc|run)\//;
178
+ /** An absolute POSIX path not glued to a word, a URL's `//`, or a token this file wrote. */
179
+ const POSIX_PATH = /(?<![\w.~\]:/>@-])\/(?:[^\s/():'"`,]+\/)*[^\s/():'"`,]+/g;
180
+ const WINDOWS_PATH = /\b[A-Za-z]:\\(?:[^\s\\():'"`,]+\\)*[^\s\\():'"`,]+/g;
181
+
182
+ /** A path that is the machine's: a known system root, or a file (its last segment has an extension). */
183
+ function relativePath(path: string, separator: '/' | '\\'): string {
184
+ const segments = path.split(separator);
185
+ const modules = segments.lastIndexOf('node_modules');
186
+ if (modules >= 0) return segments.slice(modules).join('/');
187
+ const last = segments.at(-1) ?? '';
188
+ const isFile = /\.[A-Za-z0-9]+$/.test(last.replace(/(?::\d+)+$/, ''));
189
+ if (separator === '/' && !isFile && !SYSTEM_ROOT.test(`${path}/`)) return path;
190
+ return `<abs>/${last}`;
191
+ }
192
+
193
+ /**
194
+ * A host is a whole name, and only where a host stands: `checkbox` keeps its `box`, and a host
195
+ * after one `/` (a path segment, a package scope's tail) or after a bare `@` is not one. After a
196
+ * URL's `//` or this file's own `[cred]@` it is.
197
+ */
198
+ const hostPattern = (host: string): RegExp =>
199
+ new RegExp(`(?<![\\w.-])(?<!(?:^|[^/])/)(?<!(?:^|[^\\]])@)${literal(host)}(?![\\w-])`, 'gi');
200
+
201
+ export function scrubberFor(sources: ScrubSources): Scrubber {
202
+ const { paths, values } = needlesOf(sources);
203
+ const hitEnv = new Set<string>();
204
+ const hitHosts = new Set<string>();
205
+ const replaceAll = (out: string, needles: readonly Needle[]): string => {
206
+ let next = out;
207
+ for (const needle of needles) {
208
+ const pattern =
209
+ needle.host === true
210
+ ? hostPattern(needle.find)
211
+ : needle.word === true
212
+ ? new RegExp(`(?<![\\w%+-])${literal(needle.find)}(?![\\w%+-])`, 'g')
213
+ : new RegExp(literal(needle.find), 'g');
214
+ if (!pattern.test(next)) continue;
215
+ next = next.replace(pattern, needle.replace);
216
+ if (needle.env !== undefined) hitEnv.add(needle.env);
217
+ if (needle.host === true) hitHosts.add(needle.find);
218
+ }
219
+ return next;
220
+ };
221
+ const envNeedles = values.filter((needle) => needle.host !== true);
222
+ const hostNeedles = values.filter((needle) => needle.host === true);
223
+ const text = (input: string): string => {
224
+ let out = input;
225
+ for (const needle of paths) out = out.replaceAll(needle.find, needle.replace);
226
+ out = withoutUrlSecrets(replaceAll(out, envNeedles));
227
+ return replaceAll(out, hostNeedles)
228
+ .replace(EMAIL, '[email]')
229
+ .replace(IPV4, '[ip]')
230
+ .replace(IPV6, '[ip]');
231
+ };
232
+ const value = (input: unknown, depth = 0): unknown => {
233
+ if (typeof input === 'string') return text(input);
234
+ if (input === null || typeof input !== 'object') return input;
235
+ if (depth > 32) return '[depth-limit]';
236
+ if (Array.isArray(input)) return input.map((entry) => value(entry, depth + 1));
237
+ const out: Record<string, unknown> = {};
238
+ for (const [key, entry] of Object.entries(input)) {
239
+ // `defineProperty`: a key named `__proto__` in captured input must stay a key.
240
+ Object.defineProperty(out, text(key), {
241
+ value: value(entry, depth + 1),
242
+ enumerable: true,
243
+ writable: true,
244
+ configurable: true,
245
+ });
246
+ }
247
+ return out;
248
+ };
249
+ return {
250
+ value: (input) => value(input),
251
+ location: (input) =>
252
+ text(input.replaceAll('file://', ''))
253
+ .replace(POSIX_PATH, (path) => relativePath(path, '/'))
254
+ .replace(WINDOWS_PATH, (path) => relativePath(path, '\\')),
255
+ report: () => ({ env: [...hitEnv].sort(), hosts: hitHosts.size }),
256
+ };
257
+ }
@@ -11,6 +11,7 @@ import type { Env } from './runtime-bindings';
11
11
  import type { LiveFeed } from './runtime-live-feed';
12
12
  import type { RuntimeOverrides } from './runtime-overrides';
13
13
  import type { RunningServices } from './runtime-services';
14
+ import type { ListenerTls } from './serve-env-tls';
14
15
  import type { WebBinding } from './web-binding';
15
16
 
16
17
  /** The roles `x dev` starts when `--role` names none, in boot order. */
@@ -33,6 +34,12 @@ export interface StartRolesOptions {
33
34
  * probe, which is the same failure in four costumes.
34
35
  */
35
36
  readonly http?: WebBinding;
37
+ /**
38
+ * The web role's certificate and key, PEM: its listener serves TLS. Absent is plaintext, the
39
+ * default — `x dev --tls` and `TLS_CERT`/`TLS_KEY` are the two callers. Never the `sync` node or
40
+ * the metrics endpoint: the sync socket is served on the web port too (`role-sync`).
41
+ */
42
+ readonly tls?: ListenerTls;
36
43
  /**
37
44
  * The app's `auth.signInPath`. Threaded rather than read from the config here because
38
45
  * `startRoles` takes plain values — a test starts a web role with no `app.config.ts` at all.
package/src/role-start.ts CHANGED
@@ -207,6 +207,7 @@ function startWeb(
207
207
  dev: binding.dev,
208
208
  buildId: options.buildId,
209
209
  hostname: binding.hostname,
210
+ ...(options.tls === undefined ? {} : { tls: options.tls }),
210
211
  signInPath: options.signInPath ?? null,
211
212
  // One declaration, never half of one: `defineHttpConfig` refuses `trustProxy` without hops.
212
213
  ...(hops === null ? {} : { trustProxy: true, trustedProxyHops: hops }),
@@ -223,6 +224,9 @@ function startWeb(
223
224
  // document that carries an island, so `script-src 'self'` meant no island booted anywhere
224
225
  // the policy is enforced — every container, and never `x dev`, where it is report-only.
225
226
  security: {
227
+ // A dev listener on TLS sends no HSTS: browsers pin it per HOST, so a two-year policy
228
+ // from `https://localhost:3000` would force every other localhost port onto https.
229
+ ...(binding.dev && options.tls !== undefined ? { hsts: null } : {}),
226
230
  csp: {
227
231
  extend: {
228
232
  'style-src': inlineStyleSources(options.inlineStyles ?? []),
package/src/serve-boot.ts CHANGED
@@ -27,6 +27,7 @@ import { bootTimeline } from './serve-boot-phases';
27
27
  import { bootWarningConcerns, warnAtBoot } from './serve-boot-warnings';
28
28
  import { loadDrainConfig, loadHealthConfig } from './serve-drain';
29
29
  import { configureReporting, containerBinding, metricsPortFor, portFromEnv } from './serve-env';
30
+ import { type ListenerTls, tlsFromEnv } from './serve-env-tls';
30
31
  import { adoptPrebuiltStyles, reportBootBuilds, watchBootBuilds } from './serve-prebuilt';
31
32
  import type { ServedApp, ServeOptions } from './serve-types';
32
33
 
@@ -92,6 +93,8 @@ export async function bootServing(boot: {
92
93
  readonly metrics: MetricsEndpoint;
93
94
  }): Promise<ServedApp> {
94
95
  const { options } = boot;
96
+ // Before any service starts: a half-declared pair is refused while there is nothing to unwind.
97
+ const tls = boot.role === 'web' ? await tlsFromEnv(options.env) : undefined;
95
98
  // One `boot.phase` line as each step ends, so a slow boot names its slow step (U12).
96
99
  const timeline = bootTimeline(boot.role, options.runtime?.clock);
97
100
  const services = resolveServices(options.root, options.env);
@@ -103,7 +106,7 @@ export async function bootServing(boot: {
103
106
  const runtime = await startServices(services, options.env, options.runtime, schema, [boot.role]);
104
107
  boot.acquired.push(() => runtime.stop());
105
108
  timeline.phase('services');
106
- return bootRoles({ ...boot, runtime, timeline });
109
+ return bootRoles({ ...boot, runtime, timeline, ...(tls === undefined ? {} : { tls }) });
107
110
  }
108
111
 
109
112
  /**
@@ -138,6 +141,8 @@ async function bootRoles(boot: {
138
141
  /** The scrape listener `serveApp` opened before any of this work; `startRoles` adopts it. */
139
142
  readonly metrics: MetricsEndpoint;
140
143
  readonly timeline: BootTimeline;
144
+ /** `TLS_CERT`/`TLS_KEY`, read by `bootServing`; the web role's listener serves TLS with it. */
145
+ readonly tls?: ListenerTls;
141
146
  }): Promise<ServedApp> {
142
147
  const { options, role, runtime, acquired, metrics, timeline } = boot;
143
148
  // Before the app's modules, because importing one may register a `close` hook, and that phase
@@ -239,6 +244,7 @@ async function bootRoles(boot: {
239
244
  // process and `x dev` cannot answer a browser differently.
240
245
  root: options.root,
241
246
  http: containerBinding(options.env, options.hostname),
247
+ ...(boot.tls === undefined ? {} : { tls: boot.tls }),
242
248
  // `app.config.ts`'s drain section: the readiness grace the chart's grace period is sized for.
243
249
  ...(drain === undefined ? {} : { drain }),
244
250
  // The read-replica scope rides in FRONT of whatever the host supplied, or the host's own value
@@ -0,0 +1,57 @@
1
+ // `TLS_CERT` / `TLS_KEY`: the paths of the PEM pair a container's `web` role serves TLS with, read
2
+ // once at boot. Both or neither — a listener that silently stayed plaintext because one variable
3
+ // was mistyped is the failure this refuses. Absent, nothing changes: the ingress terminates TLS.
4
+
5
+ import { renderFixShellArg, UltimateError } from '@ultimat3/core';
6
+ import type { HttpConfigInput } from '@ultimat3/http';
7
+ import type { Env } from './runtime-bindings';
8
+
9
+ export type ListenerTls = NonNullable<HttpConfigInput['tls']>;
10
+
11
+ export const TLS_CERT_ENV = 'TLS_CERT';
12
+ export const TLS_KEY_ENV = 'TLS_KEY';
13
+
14
+ /** `X_CONFIG_INVALID`, http's own code for a listener it cannot build. Never the file's bytes. */
15
+ export class ListenerTlsInvalidError extends UltimateError {
16
+ constructor(input: { name: string; reason: string }) {
17
+ super({
18
+ code: 'X_CONFIG_INVALID',
19
+ cause: `${input.name} ${input.reason}; the web role serves TLS with ${TLS_CERT_ENV} and ${TLS_KEY_ENV} together — two PEM file paths — or with neither`,
20
+ fix: `docker run -e TLS_CERT=/run/secrets/tls.crt -e TLS_KEY=/run/secrets/tls.key <image> # or unset both and terminate TLS at the ingress`,
21
+ meta: { key: input.name },
22
+ });
23
+ }
24
+ }
25
+
26
+ const setValue = (env: Env, name: string): string | undefined => {
27
+ const raw = env[name]?.trim();
28
+ return raw === undefined || raw.length === 0 ? undefined : raw;
29
+ };
30
+
31
+ async function readPem(name: string, path: string): Promise<string> {
32
+ const file = Bun.file(path);
33
+ const text = (await file.exists()) ? await file.text().catch(() => '') : '';
34
+ if (text.length === 0) {
35
+ throw new ListenerTlsInvalidError({
36
+ name,
37
+ reason: `names ${renderFixShellArg(path, '<path>')}, which is missing, empty or unreadable`,
38
+ });
39
+ }
40
+ return text;
41
+ }
42
+
43
+ /** The pair, read; `undefined` when neither is set. `defineHttpConfig` judges the PEM itself. */
44
+ export async function tlsFromEnv(env: Env): Promise<ListenerTls | undefined> {
45
+ const certPath = setValue(env, TLS_CERT_ENV);
46
+ const keyPath = setValue(env, TLS_KEY_ENV);
47
+ if (certPath === undefined && keyPath === undefined) return undefined;
48
+ if (certPath === undefined || keyPath === undefined) {
49
+ const [missing, present] =
50
+ certPath === undefined ? [TLS_CERT_ENV, TLS_KEY_ENV] : [TLS_KEY_ENV, TLS_CERT_ENV];
51
+ throw new ListenerTlsInvalidError({
52
+ name: missing,
53
+ reason: `is unset while ${present} is set`,
54
+ });
55
+ }
56
+ return { cert: await readPem(TLS_CERT_ENV, certPath), key: await readPem(TLS_KEY_ENV, keyPath) };
57
+ }
@@ -56,8 +56,9 @@ const babel = () => {
56
56
  };
57
57
 
58
58
  interface CacheEntry {
59
- /** `contentHash` of the source the code was compiled from. */
59
+ /** `contentHash` of the source the code was compiled from, and the flag it was compiled under. */
60
60
  readonly hash: string;
61
+ readonly retainLines: boolean;
61
62
  readonly code: string;
62
63
  }
63
64
 
@@ -88,11 +89,20 @@ export function clearIslandTransformCache(): void {
88
89
  *
89
90
  * The output is still TypeScript — Babel PARSES the annotations here and does not strip them,
90
91
  * which is why the plugin declares `loader: 'ts'` and lets Bun remove them.
92
+ *
93
+ * `retainLines` is a coverage build's alone (`solidJsxPluginFor`): Babel then keeps each source
94
+ * line at its own line number, so the island chunk's map names lines the file really holds there
95
+ * (`coverage-remap.ts`). Never on a shipped build — it is a layout, and a layout is bytes.
91
96
  */
92
- export async function transformIslandTsx(source: string, path: string): Promise<string> {
97
+ export async function transformIslandTsx(
98
+ source: string,
99
+ path: string,
100
+ options: { readonly retainLines?: boolean } = {},
101
+ ): Promise<string> {
102
+ const retainLines = options.retainLines === true;
93
103
  const hash = contentHash(source);
94
104
  const hit = cache.get(path);
95
- if (hit !== undefined && hit.hash === hash) return hit.code;
105
+ if (hit !== undefined && hit.hash === hash && hit.retainLines === retainLines) return hit.code;
96
106
 
97
107
  // Babel installs its own `prepareStackTrace` on the first TRANSFORM — not on import, which is
98
108
  // where this guard was first put — and leaving it installed makes `Error.captureStackTrace`
@@ -114,6 +124,7 @@ export async function transformIslandTsx(source: string, path: string): Promise<
114
124
  // have one must not change what its islands compile to.
115
125
  babelrc: false,
116
126
  configFile: false,
127
+ retainLines,
117
128
  parserOpts: { plugins: [...PARSER_PLUGINS] },
118
129
  presets: [[solidPreset, PRESET_OPTIONS]],
119
130
  });
@@ -131,14 +142,14 @@ export async function transformIslandTsx(source: string, path: string): Promise<
131
142
  logs: 'the Solid JSX transform emitted no code',
132
143
  });
133
144
  }
134
- cache.set(path, { hash, code });
145
+ cache.set(path, { hash, retainLines, code });
135
146
  return code;
136
147
  }
137
148
 
138
149
  /**
139
- * The plugin `island-bundle.ts` hands `Bun.build`. It carries no state of its own, so one frozen
140
- * descriptor serves every concurrent island build — `Bun.build` calls `setup` once per build with
141
- * that build's own builder.
150
+ * The plugin `island-bundle.ts` hands `Bun.build`. It carries no state of its own, so one
151
+ * descriptor per `retainLines` serves every concurrent island build — `Bun.build` calls `setup`
152
+ * once per build with that build's own builder.
142
153
  *
143
154
  * `.tsx`, NOT `.island.tsx`. The narrow filter looks like axiom 6 and is the opposite of it: an
144
155
  * island that imports a plain `.tsx` component — the most ordinary thing an author does, and what
@@ -149,12 +160,18 @@ export async function transformIslandTsx(source: string, path: string): Promise<
149
160
  * names its island by SPECIFIER and never imports one. So `.tsx` here already means exactly the
150
161
  * set that ships to a browser — the filter never had to do that work.
151
162
  */
152
- export const solidJsxPlugin: BunPlugin = {
163
+ export const solidJsxPluginFor = (retainLines: boolean): BunPlugin => ({
153
164
  name: 'ultimate-island-solid',
154
165
  setup(build): void {
155
166
  build.onLoad({ filter: /\.tsx$/ }, async ({ path }) => ({
156
- contents: await transformIslandTsx(await Bun.file(path).text(), path),
167
+ contents: await transformIslandTsx(await Bun.file(path).text(), path, { retainLines }),
157
168
  loader: 'ts',
158
169
  }));
159
170
  },
160
- };
171
+ });
172
+
173
+ /** The shipped build's transform. */
174
+ export const solidJsxPlugin: BunPlugin = solidJsxPluginFor(false);
175
+
176
+ /** A coverage build's (`buildIslands({ coverage: true })`): the same compile, lines kept. */
177
+ export const solidJsxCoveragePlugin: BunPlugin = solidJsxPluginFor(true);
@@ -0,0 +1,87 @@
1
+ // The superseded-workaround matcher, pure over one file's text: its comment blocks, and which
2
+ // table rows one of them names (`superseded.ts`). No I/O — `doctor-superseded.ts` walks the app.
3
+
4
+ import type { SupersededWorkaround } from './superseded';
5
+ import { NEAR_LINES } from './superseded';
6
+
7
+ /** Consecutive comment lines, joined: a note wrapped over three lines is one sentence. */
8
+ export interface CommentBlock {
9
+ /** 1-based, inclusive. */
10
+ readonly start: number;
11
+ readonly end: number;
12
+ readonly text: string;
13
+ }
14
+
15
+ export interface SupersededHit {
16
+ readonly id: string;
17
+ /** `path:line` of the note's first line. */
18
+ readonly at: string;
19
+ }
20
+
21
+ const WHOLE = /^(?:\/\/+|\/\*+|\*+\/?|\{\/\*+)\s?(.*)$/;
22
+ const TAIL = /\s\/\/\s(.*)$/;
23
+
24
+ /** A whole-line comment's text, or the tail after a trailing ` // `; `undefined` for code. */
25
+ function commentText(line: string): string | undefined {
26
+ const whole = WHOLE.exec(line.trim());
27
+ if (whole !== null) return whole[1] ?? '';
28
+ return TAIL.exec(line)?.[1];
29
+ }
30
+
31
+ /** The code on a line: nothing for a whole-line comment, the head before a trailing ` // `. */
32
+ function codePart(line: string): string {
33
+ if (WHOLE.test(line.trim())) return '';
34
+ const tail = TAIL.exec(line);
35
+ return tail === null ? line : line.slice(0, tail.index);
36
+ }
37
+
38
+ /** Markdown is prose throughout: each paragraph is a block. Code reads its comments only. */
39
+ export function commentBlocks(path: string, text: string): readonly CommentBlock[] {
40
+ const prose = path.endsWith('.md');
41
+ const lines = text.split(/\r?\n/);
42
+ const blocks: CommentBlock[] = [];
43
+ let open: { start: number; parts: string[] } | undefined;
44
+ const close = (end: number): void => {
45
+ if (open !== undefined) blocks.push({ start: open.start, end, text: open.parts.join(' ') });
46
+ open = undefined;
47
+ };
48
+ lines.forEach((line, index) => {
49
+ const part = prose ? (line.trim() === '' ? undefined : line.trim()) : commentText(line);
50
+ if (part === undefined) {
51
+ close(index);
52
+ return;
53
+ }
54
+ if (open === undefined) open = { start: index + 1, parts: [] };
55
+ open.parts.push(part);
56
+ });
57
+ close(lines.length);
58
+ return blocks;
59
+ }
60
+
61
+ /** Every row a block of `text` names, once per block, in file order. */
62
+ export function matchSuperseded(
63
+ path: string,
64
+ text: string,
65
+ rows: readonly SupersededWorkaround[],
66
+ ): readonly SupersededHit[] {
67
+ const prose = path.endsWith('.md');
68
+ const blocks = commentBlocks(path, text);
69
+ const lines = text.split(/\r?\n/);
70
+ const hits: SupersededHit[] = [];
71
+ for (const block of blocks) {
72
+ for (const row of rows) {
73
+ if (!row.pattern.comment.every((pattern) => pattern.test(block.text))) continue;
74
+ const near = row.pattern.near;
75
+ if (near !== undefined) {
76
+ // Prose has no code to stand beside: a page quoting the workaround is not holding it.
77
+ if (prose) continue;
78
+ const from = Math.max(0, block.start - 1 - NEAR_LINES);
79
+ const window = lines.slice(from, block.end + NEAR_LINES);
80
+ // Code only: a note quoting `render: 'ssr'` is not the page declaring it.
81
+ if (!window.some((line) => near.test(codePart(line)))) continue;
82
+ }
83
+ hits.push({ id: row.id, at: `${path}:${block.start}` });
84
+ }
85
+ }
86
+ return hits;
87
+ }
@@ -0,0 +1,84 @@
1
+ // The superseded-workaround table: what an app wrote while the framework lacked something, the
2
+ // version that shipped the real thing, and the edit that retires the workaround. `x doctor` and
3
+ // `x upgrade` report each hit (`doctor-superseded.ts`); `scripts/changelog-check.ts` refuses a
4
+ // release note that retires a workaround this table does not hold.
5
+
6
+ /**
7
+ * What to find. `comment` is matched on comment text only — a `//`, `/*` or `*` line of code, any
8
+ * line of markdown — and EVERY pattern must match one comment block: a workaround is recognised by
9
+ * the note that names it, never by ordinary code. `near`, when set, must also stand in the code
10
+ * within `NEAR_LINES` of that block: the note alone is stale prose, the note beside it is the
11
+ * workaround still in force.
12
+ */
13
+ export interface WorkaroundPattern {
14
+ readonly comment: readonly RegExp[];
15
+ readonly near?: RegExp;
16
+ }
17
+
18
+ export interface SupersededWorkaround {
19
+ /** Stable, kebab-case: a CHANGELOG line names it (`retires the workaround \`<id>\``). */
20
+ readonly id: string;
21
+ readonly pattern: WorkaroundPattern;
22
+ /** The framework version that shipped the replacement. */
23
+ readonly shippedIn: string;
24
+ /** What replaced it, as an author would search for it. */
25
+ readonly replacement: string;
26
+ /** Opens with the code or command to paste (the fix-prose rule). */
27
+ readonly fix: string;
28
+ }
29
+
30
+ /** How far from its note the workaround's code may stand, in lines either way. */
31
+ export const NEAR_LINES = 8;
32
+
33
+ export const SUPERSEDED_WORKAROUNDS: readonly SupersededWorkaround[] = [
34
+ {
35
+ // The scaffold itself wrote this until 30.0.0: "'ssr', not 'stream' … the framework has no hole
36
+ // marker yet". Apps kept the comment and the mode after the marker shipped.
37
+ id: 'ssr-until-hole',
38
+ pattern: { comment: [/\bhole\s+marker\b/i], near: /\brender\s*:\s*['"]ssr['"]/ },
39
+ shippedIn: '30.0.0',
40
+ replacement: "<Hole> from '@ultimat3/render' on a render: 'stream' page",
41
+ fix: "render: 'stream', with the slow read moved into <Hole fallback={<Skeleton />}>{() => read()}</Hole> (import { Hole } from '@ultimat3/render'); then delete the comment that waits for a hole marker",
42
+ },
43
+ {
44
+ // `x token` exited `X_NOT_IMPLEMENTED` until 31.17.0; a key-minting script said so in its header.
45
+ id: 'token-unimplemented',
46
+ pattern: {
47
+ comment: [
48
+ // Present tense only, and never `x token grant`, which is still planned: a changelog line
49
+ // saying the command "exited X_NOT_IMPLEMENTED" is history, not a workaround.
50
+ /\bx token`?(?! grant)\s+(?:\w+\s+){0,3}?(?:is|isn't|still|remains)\s+(?:not (?:yet )?(?:implemented|shipped|available)|unimplemented|planned|a stub)\b|\bx token`?(?! grant)[^.]*\bexits\s+`?X_NOT_IMPLEMENTED/i,
51
+ ],
52
+ },
53
+ shippedIn: '31.17.0',
54
+ replacement: 'x token create | list | revoke',
55
+ fix: 'x token create --scopes posts:read --json — mints the key with exact scopes; delete the note, and the script it stood in for',
56
+ },
57
+ {
58
+ // A gaps note saying the gate cannot run one step: `--only` shipped with the gate in 22.0.0.
59
+ id: 'verify-no-only',
60
+ pattern: {
61
+ comment: [
62
+ // The claim about the gate, never a fixture or a step that merely runs without the flag.
63
+ /\b(?:verify|gate)`?\s+(?:has|have|takes|offers|supports)\s+no\s+`?--only\b|`--only`\s+(?:flag\s+)?(?:does not exist|doesn't exist|is missing|is not supported|isn't supported)/i,
64
+ ],
65
+ },
66
+ shippedIn: '22.0.0',
67
+ replacement: 'x verify --only <step>',
68
+ fix: 'x verify --only lint --json — runs one step; delete the note that says the gate cannot',
69
+ },
70
+ {
71
+ // A hand-written TLS terminator or relay in front of `x dev` for a LAN or a secure origin.
72
+ id: 'dev-no-tls',
73
+ pattern: {
74
+ comment: [
75
+ // One sentence, a few words apart: `x dev`, then a whole-word negation, then what it lacks.
76
+ // "Start it with `x dev`. In production nothing terminates TLS" is two sentences.
77
+ /\bx dev`?\s+(?:[^\s.]+\s+){0,3}?\b(?:no|lacks|does not|doesn't|cannot|can't|won't)\s+(?:[^\s.]+\s+){0,3}?`?(?:tls|https|--tls|--host|ipv6)\b/i,
78
+ ],
79
+ },
80
+ shippedIn: '31.27.0',
81
+ replacement: 'x dev --host <address> --tls',
82
+ fix: 'x dev --host 0.0.0.0 --tls — serves https on the LAN with a cached local certificate; delete the terminator or relay the note describes',
83
+ },
84
+ ];