@ultimat3/cli 30.9.0 → 31.1.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 (215) hide show
  1. package/CLAUDE.md +80 -64
  2. package/README.md +4 -1
  3. package/package.json +30 -29
  4. package/src/admin-registration.ts +1 -1
  5. package/src/affected-base.ts +51 -0
  6. package/src/affected.ts +34 -11
  7. package/src/app-boundaries.ts +88 -9
  8. package/src/app-load-async.ts +133 -0
  9. package/src/app-load-batch.ts +203 -0
  10. package/src/app-load-prebuilt.ts +147 -0
  11. package/src/app-load-register.ts +175 -0
  12. package/src/app-load.ts +143 -175
  13. package/src/app-loader-imports.ts +31 -0
  14. package/src/app-root.ts +13 -0
  15. package/src/app-runtime.ts +5 -1
  16. package/src/boundary-findings.ts +12 -0
  17. package/src/browser-launcher-port.ts +3 -7
  18. package/src/browser-launcher.ts +1 -1
  19. package/src/budgets-scan.ts +8 -0
  20. package/src/budgets.ts +10 -1
  21. package/src/build-registry-background.ts +59 -0
  22. package/src/build-registry.ts +207 -0
  23. package/src/cdp-shot-clock.ts +3 -11
  24. package/src/cdp-shot-driver.ts +3 -2
  25. package/src/cdp-shot-element.ts +3 -2
  26. package/src/cdp-shot-page.ts +2 -2
  27. package/src/cdp-shot-watch.ts +4 -3
  28. package/src/ci-log.ts +76 -13
  29. package/src/cmd-affected-spec.ts +7 -3
  30. package/src/cmd-affected.ts +91 -77
  31. package/src/cmd-auth.ts +3 -3
  32. package/src/cmd-ci.ts +6 -3
  33. package/src/cmd-db-recount.ts +15 -0
  34. package/src/cmd-drill.ts +10 -6
  35. package/src/cmd-exercise.ts +2 -1
  36. package/src/cmd-generate-spec.ts +6 -0
  37. package/src/cmd-generate.ts +22 -4
  38. package/src/cmd-mail.ts +1 -1
  39. package/src/cmd-pr-spec.ts +1 -1
  40. package/src/cmd-pr.ts +72 -1
  41. package/src/cmd-routes.ts +2 -2
  42. package/src/cmd-secrets-spec.ts +4 -1
  43. package/src/cmd-shot.ts +14 -262
  44. package/src/cmd-test-spec.ts +2 -2
  45. package/src/cmd-verify-spec.ts +21 -1
  46. package/src/cmd-verify.ts +16 -4
  47. package/src/coverage-source.ts +4 -1
  48. package/src/db-diagnostics.ts +8 -1
  49. package/src/dev-boot.ts +29 -15
  50. package/src/dev-dashboard-invalidations.ts +43 -0
  51. package/src/dev-dashboard.ts +13 -16
  52. package/src/dev-n-plus-one.ts +7 -3
  53. package/src/dev-rebuild.ts +2 -1
  54. package/src/dev-route-table.ts +1 -1
  55. package/src/dev-traces.ts +16 -15
  56. package/src/document-options.ts +12 -1
  57. package/src/drift-store.ts +55 -0
  58. package/src/error-catalog.ts +8 -3
  59. package/src/error-codes-boundary.ts +32 -0
  60. package/src/error-codes-package.ts +38 -0
  61. package/src/error-codes.ts +28 -40
  62. package/src/errors.ts +17 -7
  63. package/src/exercise-database.ts +13 -1
  64. package/src/exercise-findings.ts +36 -18
  65. package/src/exercise-services.ts +84 -0
  66. package/src/exercise-subject.ts +38 -13
  67. package/src/failure-capture-boot.ts +9 -5
  68. package/src/framework-schema.ts +5 -5
  69. package/src/generate-exercise.ts +1 -1
  70. package/src/generate-files.ts +27 -7
  71. package/src/generate-kinds.ts +5 -0
  72. package/src/generate-refresh.ts +53 -0
  73. package/src/generate-workspace.ts +169 -0
  74. package/src/generate-write.ts +8 -2
  75. package/src/hold.ts +19 -8
  76. package/src/image-prepare.ts +6 -2
  77. package/src/index.ts +5 -20
  78. package/src/island-bundle.ts +7 -3
  79. package/src/island-capture.ts +2 -2
  80. package/src/island-harness.ts +1 -1
  81. package/src/job-registration.ts +43 -6
  82. package/src/jobs-driver.ts +4 -5
  83. package/src/mcp-errors.ts +20 -4
  84. package/src/mcp-host.ts +5 -1
  85. package/src/mcp-ui-interact.ts +3 -0
  86. package/src/messages-gate.ts +10 -0
  87. package/src/new-shapes-generate.ts +1 -1
  88. package/src/otlp-export.ts +94 -29
  89. package/src/output.ts +24 -10
  90. package/src/page-sync.ts +3 -1
  91. package/src/pr-activity.ts +150 -0
  92. package/src/pr-bots.ts +109 -0
  93. package/src/pr-threads.ts +7 -2
  94. package/src/role-load.ts +17 -11
  95. package/src/role-start.ts +5 -4
  96. package/src/role-sync.ts +7 -8
  97. package/src/route-islands-preload.ts +46 -0
  98. package/src/route-islands.ts +6 -2
  99. package/src/runtime-admin.ts +5 -1
  100. package/src/runtime-bindings.ts +25 -19
  101. package/src/runtime-boot-ports.ts +66 -0
  102. package/src/runtime-bus.ts +29 -5
  103. package/src/runtime-cache-bus.ts +53 -0
  104. package/src/runtime-cache.ts +43 -13
  105. package/src/runtime-isr-outcome.ts +5 -4
  106. package/src/runtime-jobs.ts +2 -2
  107. package/src/runtime-keys.ts +37 -0
  108. package/src/runtime-overrides.ts +148 -42
  109. package/src/runtime-port-bindings-queue.ts +36 -0
  110. package/src/runtime-port-bindings.ts +117 -0
  111. package/src/runtime-ports.ts +164 -0
  112. package/src/runtime-purge.ts +41 -28
  113. package/src/runtime-push.ts +7 -3
  114. package/src/runtime-queue.ts +70 -55
  115. package/src/runtime-realtime.ts +5 -5
  116. package/src/runtime-render-document.ts +4 -1
  117. package/src/runtime-services.ts +110 -158
  118. package/src/runtime-storage-boot.ts +111 -0
  119. package/src/runtime-storage-upload.ts +9 -7
  120. package/src/runtime-storage.ts +7 -1
  121. package/src/serve-boot.ts +8 -4
  122. package/src/serve-entry.ts +3 -0
  123. package/src/serve-env.ts +47 -14
  124. package/src/serve-prebuilt-paths.ts +3 -0
  125. package/src/serve-prebuilt.ts +15 -4
  126. package/src/serve.ts +2 -2
  127. package/src/shot-gpu.ts +61 -0
  128. package/src/shot-route.ts +95 -0
  129. package/src/shot-run.ts +189 -0
  130. package/src/shot-verdict.ts +5 -0
  131. package/src/static-cards.ts +3 -2
  132. package/src/static-report.ts +2 -2
  133. package/src/style-bundle.ts +1 -1
  134. package/src/sync-authenticator.ts +17 -18
  135. package/src/templates/action-tests.ts +4 -4
  136. package/src/templates/backfill.ts +5 -8
  137. package/src/templates/entity.ts +3 -0
  138. package/src/templates/github/ci.yml.ts +3 -1
  139. package/src/templates/github/dependabot.yml.ts +73 -0
  140. package/src/templates/job.ts +13 -22
  141. package/src/templates/naming.ts +20 -1
  142. package/src/templates/pinned/docker-compose.yml +1 -1
  143. package/src/templates/query.ts +7 -8
  144. package/src/templates/route.ts +5 -3
  145. package/src/templates/scaffold-api.ts +1 -1
  146. package/src/templates/scaffold-auth.ts +5 -3
  147. package/src/templates/scaffold-claude-commands.ts +6 -3
  148. package/src/templates/scaffold-claude.ts +4 -4
  149. package/src/templates/scaffold-container-compose.ts +2 -4
  150. package/src/templates/scaffold-domain-package.ts +1 -1
  151. package/src/templates/scaffold-entries.ts +6 -1
  152. package/src/templates/scaffold-helm-fences.ts +3 -2
  153. package/src/templates/scaffold-helm.ts +35 -6
  154. package/src/templates/scaffold-repo.ts +47 -135
  155. package/src/templates/scaffold-runtime-ports.ts +62 -0
  156. package/src/templates/scaffold-verify-floor.ts +97 -0
  157. package/src/templates/shapes/overlay.ts +1 -1
  158. package/src/templates/sign-in-oidc.ts +5 -3
  159. package/src/templates/sign-in-shared.ts +28 -10
  160. package/src/templates/workspace.ts +75 -0
  161. package/src/test-ignores.ts +5 -2
  162. package/src/test-select.ts +4 -1
  163. package/src/tsconfig-aliases.ts +85 -0
  164. package/src/upgrade-gate.ts +30 -5
  165. package/src/upgrade-report.ts +7 -1
  166. package/src/verify-changed-facts.ts +53 -0
  167. package/src/verify-changed-scope.ts +162 -0
  168. package/src/verify-changed.ts +174 -0
  169. package/src/verify-checks.ts +33 -19
  170. package/src/verify-drift-owner.ts +30 -0
  171. package/src/verify-e2e.ts +2 -1
  172. package/src/verify-factories.ts +86 -0
  173. package/src/verify-run.ts +13 -11
  174. package/src/verify-step.ts +13 -0
  175. package/src/verify-tests.ts +58 -6
  176. package/src/workspace-external-deps.ts +164 -0
  177. package/src/write-line.ts +21 -6
  178. package/wiki/Actions.md +2 -2
  179. package/wiki/Adapters.md +400 -0
  180. package/wiki/Admin-Dashboard.md +1 -1
  181. package/wiki/Agents.md +9 -9
  182. package/wiki/Auth.md +78 -2
  183. package/wiki/Building-Your-Own-Base.md +1 -1
  184. package/wiki/CLI-Reference.md +45 -14
  185. package/wiki/Caching-And-Invalidation.md +17 -5
  186. package/wiki/Compared.md +8 -2
  187. package/wiki/Configuration.md +14 -14
  188. package/wiki/Deployment.md +28 -1
  189. package/wiki/Entities-And-Migrations.md +47 -1
  190. package/wiki/FAQ.md +8 -2
  191. package/wiki/Feature-Flags.md +1 -1
  192. package/wiki/Home.md +3 -2
  193. package/wiki/Jobs-And-Workflows.md +107 -6
  194. package/wiki/Known-Gaps.md +4 -3
  195. package/wiki/MCP-And-AI.md +18 -4
  196. package/wiki/Mail.md +14 -5
  197. package/wiki/Migrations-And-Backfills.md +29 -4
  198. package/wiki/Money.md +2 -0
  199. package/wiki/N-Plus-One-Detection.md +24 -22
  200. package/wiki/Notify.md +28 -4
  201. package/wiki/Observability.md +121 -15
  202. package/wiki/Queries-And-Live-Queries.md +2 -2
  203. package/wiki/Realtime.md +9 -4
  204. package/wiki/Routes-And-Render-Modes.md +5 -0
  205. package/wiki/Scraping.md +57 -11
  206. package/wiki/Shapes.md +2 -2
  207. package/wiki/Stability.md +7 -5
  208. package/wiki/Storage-And-Uploads.md +56 -4
  209. package/wiki/Testing.md +65 -52
  210. package/wiki/Troubleshooting.md +1 -1
  211. package/wiki/Tutorial-01-First-App.md +1 -1
  212. package/wiki/Tutorial-04-Jobs-And-Realtime.md +1 -1
  213. package/wiki/Tutorial-05-Deploy-Free.md +1 -1
  214. package/wiki/Tutorial-06-Growing-Up.md +8 -8
  215. package/wiki/Upgrading.md +136 -5
@@ -2,7 +2,7 @@
2
2
  // nowhere else. `cdp-shot-driver.ts` implements it over raw CDP; a test hands in a fake. Every
3
3
  // member is one a shot or a `ui.*` call reads. A member nothing reads is one the raw driver would
4
4
  // have to build and nothing would test, and that is how a port rots.
5
- import type { Clock } from '@ultimat3/core';
5
+ import type { SleepClock } from '@ultimat3/core';
6
6
 
7
7
  /** What the browser is told the OS prefers. `'no-preference'` CLEARS the override. */
8
8
  export type ShotColorScheme = 'light' | 'dark' | 'no-preference';
@@ -103,11 +103,6 @@ export interface AccessibilityOptions {
103
103
  readonly max?: number | undefined;
104
104
  }
105
105
 
106
- /** Every wait goes through this, so a test of a 30-second deadline finishes in microseconds. */
107
- export interface ShotClock extends Clock {
108
- sleep(ms: number, signal?: AbortSignal): Promise<void>;
109
- }
110
-
111
106
  export interface ShotPage {
112
107
  url(): string;
113
108
  /** Refused before a byte leaves when the host is outside the session's `allowHosts`. */
@@ -142,7 +137,8 @@ export interface ShotSessionInit {
142
137
  readonly name: string;
143
138
  /** Never `*` from a shot: a headless browser inside your network is an SSRF surface. */
144
139
  readonly rules: { readonly allowHosts: readonly string[] };
145
- readonly clock: ShotClock;
140
+ /** Every wait goes through it, so a test of a 30-second deadline finishes in microseconds. */
141
+ readonly clock: SleepClock;
146
142
  /** Per-operation default, in ms. */
147
143
  readonly timeoutMs: number;
148
144
  /** CSS pixels the page is laid out in. Absent: the driver's own default. */
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { existsSync } from 'node:fs';
8
8
  import { UltimateError } from '@ultimat3/core';
9
- import { CHROME_CANDIDATES } from '@ultimat3/testing';
9
+ import { CHROME_CANDIDATES } from '@ultimat3/scraping/cdp';
10
10
  import type { ShotDriver } from './browser-launcher-port';
11
11
  import { cdpShotDriver } from './cdp-shot-driver';
12
12
 
@@ -34,6 +34,14 @@ export const carriesJson = (attrs: string): boolean => {
34
34
  */
35
35
  export const ENTRY_ATTR = /\sdata-x-entry="(?<url>[^"]*)"/g;
36
36
 
37
+ /**
38
+ * `<link rel="modulepreload" href>` — what `route-islands-preload.ts` emits. A preload is a fetch
39
+ * the browser makes whether or not an island imports the file, so it is weighed like a `src`.
40
+ * Only `modulepreload`: a stylesheet or a plain `preload` link names no module to execute.
41
+ */
42
+ export const MODULEPRELOAD_TAG = /<link\s[^>]*\brel="modulepreload"[^>]*>/g;
43
+ export const HREF_ATTR = /\shref="(?<href>[^"]*)"/;
44
+
37
45
  /**
38
46
  * Static imports and `import()` both. A chunk reached by `import()` was INLINED into its island
39
47
  * before islands were split, so charging it keeps a route's number what it was; and it is fetched
package/src/budgets.ts CHANGED
@@ -17,7 +17,9 @@ import {
17
17
  artifactPath,
18
18
  carriesJson,
19
19
  ENTRY_ATTR,
20
+ HREF_ATTR,
20
21
  loadedBy,
22
+ MODULEPRELOAD_TAG,
21
23
  SCRIPT_TAG,
22
24
  SRC_ATTR,
23
25
  } from './budgets-scan';
@@ -79,8 +81,9 @@ export interface BuildStats {
79
81
  * `5`: a URL is weighed at the path a browser resolves it to (`\` is `/`, `//host` is another
80
82
  * origin), so two spellings of one fetch are charged once; and an app/ page is weighed as SERVED
81
83
  * — its page boot charged, the runtime chunk that boot makes unfetched not (plan 101 sweep 9).
84
+ * `6`: a `<link rel="modulepreload">` is a fetch and is charged, deduped with every other (B4).
82
85
  */
83
- export const BUILD_STATS_RULES = 5;
86
+ export const BUILD_STATS_RULES = 6;
84
87
 
85
88
  const chainOf = (stats: RouteStats): string =>
86
89
  stats.heaviestChain === undefined ? 'unknown import chain' : stats.heaviestChain.join(' -> ');
@@ -413,6 +416,12 @@ export async function measureDocumentJs(
413
416
  if (url === undefined) continue;
414
417
  await weigh(url);
415
418
  }
419
+ // Charged even when the boot supplies it: the boot rule says an island never FETCHES the runtime
420
+ // chunk, and a preload of it is a fetch. What the preloaded file loads follows the rule in `weigh`.
421
+ for (const match of html.matchAll(MODULEPRELOAD_TAG)) {
422
+ const href = HREF_ATTR.exec(match[0])?.groups?.['href'];
423
+ if (href !== undefined) await weigh(href);
424
+ }
416
425
  return { jsBytes, frameworkBytes, inlineBytes, entries };
417
426
  }
418
427
 
@@ -0,0 +1,59 @@
1
+ // Which of the app's modules a background role (`worker`, `scheduler`) imports, decided at image
2
+ // build time for the prebuilt registry: the same rule `scanBackground` applies module by module at
3
+ // boot (`role-load.ts`), with what the process has "already loaded" simulated from the static
4
+ // import graph instead of read from Bun's module cache — so the boot imports a list, not a walk.
5
+
6
+ // why: Bun ships no path API; the API index is named app-root-relative and compared absolute.
7
+ import { resolve } from 'node:path';
8
+ import { API_INDEX } from './app-root';
9
+ import { createDocumentGraph } from './document-graph';
10
+ import { resolvedImports } from './module-imports';
11
+ import { hasPathSegment } from './path-segments';
12
+
13
+ /** An installed framework package — walked, as the document graph walks it. */
14
+ const FRAMEWORK_SCOPE = '/node_modules/@ultimat3/';
15
+
16
+ /** The files evaluating `path` evaluates, by the document graph's own rule for what it follows. */
17
+ async function evaluatedImports(path: string): Promise<readonly string[]> {
18
+ const source = await Bun.file(path)
19
+ .text()
20
+ .catch(() => '');
21
+ return resolvedImports(path, source, 'evaluated').filter(
22
+ (target) => !hasPathSegment(target, 'node_modules') || target.includes(FRAMEWORK_SCOPE),
23
+ );
24
+ }
25
+
26
+ /**
27
+ * The subset of `modules` (absolute, scan order) a background role imports, in the same order:
28
+ * the API index, every module an earlier imported one already evaluated, and every module that
29
+ * reaches no document. "Already evaluated" is the static closure of what was imported before it —
30
+ * the runtime answer differs only by a top-level `await import()`, which makes the runtime import
31
+ * MORE; a job that leaves out is answered at boot by the manifest check (`X_ROLE_LOAD_INCOMPLETE`).
32
+ */
33
+ export async function backgroundModules(
34
+ root: string,
35
+ modules: readonly string[],
36
+ ): Promise<readonly string[]> {
37
+ const index = resolve(root, API_INDEX);
38
+ const evaluated = new Set<string>();
39
+ const graph = createDocumentGraph((absolute) => evaluated.has(absolute));
40
+ const evaluate = async (start: string): Promise<void> => {
41
+ const stack = [start];
42
+ while (stack.length > 0) {
43
+ const path = stack.pop();
44
+ if (path === undefined || evaluated.has(path)) continue;
45
+ evaluated.add(path);
46
+ stack.push(...(await evaluatedImports(path)));
47
+ }
48
+ };
49
+ const included: string[] = [];
50
+ for (const absolute of modules) {
51
+ // `evaluated.has` first only skips a walk: the graph's own oracle answers it the same way.
52
+ const take =
53
+ absolute === index || evaluated.has(absolute) || !(await graph.reachesDocument(absolute));
54
+ if (!take) continue;
55
+ included.push(absolute);
56
+ await evaluate(absolute);
57
+ }
58
+ return included;
59
+ }
@@ -0,0 +1,207 @@
1
+ // The app's prebuilt module registry: every module the scan imports, in scan order, written by
2
+ // `x build --target prebuilt` as the scan's own batches (`batchSources`), and read by a serving
3
+ // role's boot instead of a scan (`app-load-prebuilt.ts`). A leaf of the boot graph: it writes and
4
+ // reads files and imports none of the app.
5
+
6
+ // why: Bun ships no recursive remove; a previous registry must not survive beside the new one.
7
+ import { rm } from 'node:fs/promises';
8
+ // why: Bun ships no path API; a chunk names each module relative to itself.
9
+ import { join, relative } from 'node:path';
10
+ import { isJsonObject } from '@ultimat3/core';
11
+ import type { AppScan } from './app-load';
12
+ import { scannedModulePaths } from './app-load';
13
+ import { asyncModules } from './app-load-async';
14
+ import { batchSources, planBatches, uniqueBatchName } from './app-load-batch';
15
+ import { backgroundModules } from './build-registry-background';
16
+ import { toPosix } from './posix-path';
17
+ import { PREBUILT_REGISTRY_DIR } from './serve-prebuilt-paths';
18
+
19
+ /**
20
+ * Bumped whenever the shape below changes: a registry of another format is not read. 2: a chunk
21
+ * imports a hook module per app module, which registers it before the next one evaluates. 3: a
22
+ * second chunk set, the background roles' (`background`), and the stamp it is trusted under.
23
+ */
24
+ export const REGISTRY_FORMAT = 3;
25
+
26
+ const INDEX_FILE = 'registry.json';
27
+
28
+ /** The background chunks' directory, beside the full set's: their hook files share names. */
29
+ const BACKGROUND_DIR = 'background';
30
+
31
+ /** One ordered module list and the chunks that import it. */
32
+ export interface RegistryChunks {
33
+ /** App-root-relative POSIX paths, in scan order — the order the chunks import them in. */
34
+ readonly files: readonly string[];
35
+ /**
36
+ * Registry-dir-relative chunk files, in order, holding `files` in order between them: up to
37
+ * `BATCH_SIZE` each, and a module whose evaluation can suspend in a chunk of its own. Each
38
+ * imports the hook modules (`hookFile`) beside it, one per app module.
39
+ */
40
+ readonly chunks: readonly string[];
41
+ }
42
+
43
+ /** `registry.json`: what the chunks import, and what wrote them. */
44
+ export interface PrebuiltRegistry extends RegistryChunks {
45
+ readonly format: typeof REGISTRY_FORMAT;
46
+ /** The Bun that wrote it: a chunk is evaluated by the runtime that resolved its specifiers. */
47
+ readonly bun: string;
48
+ /**
49
+ * What `worker` and `scheduler` import (`build-registry-background.ts`), a subsequence of
50
+ * `files`. `stamp` is `moduleStamp` (the bytes) of every module at write time: which modules
51
+ * reach a document is a fact about their content, so a module edited since is answered by the
52
+ * scan.
53
+ */
54
+ readonly background: RegistryChunks & { readonly stamp: string };
55
+ }
56
+
57
+ /** The registry's directory under `root`. */
58
+ export const registryDir = (root: string): string => join(root, PREBUILT_REGISTRY_DIR);
59
+
60
+ /**
61
+ * A chunk's specifier for one module: relative to the chunk, so a registry written at one
62
+ * `WORKDIR` resolves at another — the image is the same tree wherever it is mounted.
63
+ */
64
+ function specifierFor(dir: string, absolute: string): string {
65
+ const path = toPosix(relative(dir, absolute));
66
+ return path.startsWith('.') ? path : `./${path}`;
67
+ }
68
+
69
+ /** Reads at most this many modules at once: a 12k-module app opened 12k descriptors otherwise. */
70
+ const STAMP_BATCH = 64;
71
+
72
+ /** One module's bytes, hashed — or `absent` for a file that cannot be read. */
73
+ const contentHash = (path: string): Promise<string> =>
74
+ Bun.file(path)
75
+ .bytes()
76
+ .then(
77
+ (bytes) => Bun.hash(bytes).toString(16),
78
+ () => 'absent',
79
+ );
80
+
81
+ /**
82
+ * The bytes of every module of `files` (app-root-relative), hashed, path by path. Never a
83
+ * modification time: an image build that rewrites timestamps (BuildKit `rewrite-timestamp`, a
84
+ * stage that copies the app again) moves every one and changes no module, and a stamp built on
85
+ * them sent every worker boot to the scan. Measured on 5,101 modules (2026-11-10): 30–73 ms,
86
+ * median 51, against a 1.5 s boot.
87
+ */
88
+ export async function moduleStamp(root: string, files: readonly string[]): Promise<string> {
89
+ const facts: string[] = [];
90
+ for (let start = 0; start < files.length; start += STAMP_BATCH) {
91
+ const batch = files.slice(start, start + STAMP_BATCH);
92
+ const hashes = await Promise.all(batch.map((file) => contentHash(join(root, file))));
93
+ for (const [index, file] of batch.entries()) facts.push(`${file}\0${hashes[index] ?? ''}`);
94
+ }
95
+ return Bun.hash(facts.join('\n')).toString(16);
96
+ }
97
+
98
+ /** Writes the chunks importing `modules` (absolute, scan order) under `registryDir/<prefix>`. */
99
+ async function writeChunks(
100
+ root: string,
101
+ prefix: string,
102
+ modules: readonly string[],
103
+ alone: ReadonlySet<string>,
104
+ ): Promise<RegistryChunks> {
105
+ const dir = join(registryDir(root), prefix);
106
+ const chunks: string[] = [];
107
+ // Cut as the scan cuts: a module that awaits at its top level, or reaches one, is alone.
108
+ let first = 0;
109
+ for (const batch of planBatches(modules, alone)) {
110
+ const name = `chunk-${String(chunks.length)}.ts`;
111
+ const { entry, hooks } = batchSources(
112
+ batch.map((path) => specifierFor(dir, path)),
113
+ first,
114
+ );
115
+ await Promise.all(hooks.map(([hook, source]) => Bun.write(join(dir, hook), source)));
116
+ await Bun.write(join(dir, name), entry);
117
+ chunks.push(`${prefix}/${name}`);
118
+ first += batch.length;
119
+ }
120
+ return { files: modules.map((path) => toPosix(relative(root, path))), chunks };
121
+ }
122
+
123
+ /**
124
+ * Writes the registry for `modules` (absolute paths, scan order) and answers it. Every earlier
125
+ * registry is removed first: a chunk left from a larger app would import a module that is gone.
126
+ */
127
+ export async function writePrebuiltRegistry(
128
+ root: string,
129
+ modules: readonly string[],
130
+ ): Promise<PrebuiltRegistry> {
131
+ await rm(registryDir(root), { recursive: true, force: true });
132
+ // Under a directory of this write's own: a process that writes a registry twice and boots from
133
+ // it (a test, `x build` beside `x serve`) would otherwise import the first write's cached hooks.
134
+ const own = uniqueBatchName();
135
+ const alone = await asyncModules(root, modules);
136
+ const everything = await writeChunks(root, own, modules, alone);
137
+ const background = await writeChunks(
138
+ root,
139
+ `${own}/${BACKGROUND_DIR}`,
140
+ await backgroundModules(root, modules),
141
+ alone,
142
+ );
143
+ const registry: PrebuiltRegistry = {
144
+ format: REGISTRY_FORMAT,
145
+ bun: Bun.version,
146
+ ...everything,
147
+ background: { ...background, stamp: await moduleStamp(root, everything.files) },
148
+ };
149
+ await Bun.write(join(registryDir(root), INDEX_FILE), `${JSON.stringify(registry, null, 2)}\n`);
150
+ return registry;
151
+ }
152
+
153
+ const strings = (value: unknown): readonly string[] | undefined =>
154
+ Array.isArray(value) && value.every((one) => typeof one === 'string')
155
+ ? (value as string[])
156
+ : undefined;
157
+
158
+ /** One chunk set as read, or `undefined` when it cannot hold its files in order. */
159
+ function chunksOf(value: unknown): RegistryChunks | undefined {
160
+ if (!isJsonObject(value)) return undefined;
161
+ const files = strings(value['files']);
162
+ const chunks = strings(value['chunks']);
163
+ if (files === undefined || chunks === undefined) return undefined;
164
+ // Every chunk holds one module at least; the boot checks the modules they hold add up to `files`.
165
+ if (chunks.length > files.length || (files.length > 0 && chunks.length === 0)) return undefined;
166
+ return { files, chunks };
167
+ }
168
+
169
+ /**
170
+ * The registry under `root`, or `undefined` when there is none this process can use: absent,
171
+ * unreadable, of another format, or written by another Bun.
172
+ */
173
+ export async function readPrebuiltRegistry(root: string): Promise<PrebuiltRegistry | undefined> {
174
+ const parsed: unknown = await Bun.file(join(registryDir(root), INDEX_FILE))
175
+ .json()
176
+ .catch(() => undefined);
177
+ if (!isJsonObject(parsed)) return undefined;
178
+ if (parsed['format'] !== REGISTRY_FORMAT || parsed['bun'] !== Bun.version) return undefined;
179
+ const everything = chunksOf(parsed);
180
+ const background = chunksOf(parsed['background']);
181
+ const stamp = isJsonObject(parsed['background']) ? parsed['background']['stamp'] : undefined;
182
+ if (everything === undefined || background === undefined || typeof stamp !== 'string') {
183
+ return undefined;
184
+ }
185
+ return {
186
+ format: REGISTRY_FORMAT,
187
+ bun: Bun.version,
188
+ ...everything,
189
+ background: { ...background, stamp },
190
+ };
191
+ }
192
+
193
+ /**
194
+ * The image build's half: after its own scan of the app, the registry of what that scan imported —
195
+ * or none, removing any earlier one, when a module would not import. A registry missing that
196
+ * module would boot without its routes and actions; with none, the boot scans and refuses to serve
197
+ * a half-loaded app (`X_APP_MODULE_LOAD_FAILED`), with the module's own cause.
198
+ */
199
+ export async function prebuildRegistry(
200
+ root: string,
201
+ scan: AppScan,
202
+ ): Promise<PrebuiltRegistry | undefined> {
203
+ if (scan.findings.length === 0)
204
+ return writePrebuiltRegistry(root, await scannedModulePaths(root));
205
+ await rm(registryDir(root), { recursive: true, force: true });
206
+ return undefined;
207
+ }
@@ -1,14 +1,6 @@
1
- // The clock a shot session runs on, and the page deadline a run uses when it names none. The
2
- // system clock and `Bun.sleep`: a test hands `open()` its own `ShotClock`, where sleeping IS
3
- // advancing, so a 30-second deadline under test finishes in microseconds.
4
- import { systemClock } from '@ultimat3/core';
5
- import type { ShotClock } from './browser-launcher-port';
1
+ // The page deadline a shot run uses when it names none. The clock a session runs on is core's
2
+ // `SleepClock` — `systemClock` in a run, a `frozenClock` under test, where sleeping IS advancing,
3
+ // so a 30-second deadline finishes in microseconds (v31: `ShotClock` was that interface renamed).
6
4
 
7
5
  /** A navigation or a wait with no `timeout` of its own gets this. */
8
6
  export const DEFAULT_PAGE_TIMEOUT_MS = 30_000;
9
-
10
- export const systemShotClock: ShotClock = Object.freeze({
11
- now: () => systemClock.now(),
12
- monotonic: () => systemClock.monotonic(),
13
- sleep: (ms: number) => Bun.sleep(ms),
14
- });
@@ -2,14 +2,15 @@
2
2
  // (`@ultimat3/testing`'s launcher, the one the e2e step already runs on) or ATTACH to one somebody
3
3
  // else runs over `--cdp-url`. One `open()` is one browser and one page, so a picture's console and
4
4
  // network are its own. The page is `cdp-shot-page.ts`; this file is the session around it.
5
- import type { CdpConnection, LaunchedBrowser } from '@ultimat3/testing';
5
+
6
+ import type { CdpConnection, LaunchedBrowser } from '@ultimat3/scraping/cdp';
6
7
  import {
7
8
  CdpBrowserMissingError,
8
9
  CdpCallFailedError,
9
10
  CHROME_CANDIDATES,
10
11
  cdpConnect,
11
12
  launchChrome,
12
- } from '@ultimat3/testing';
13
+ } from '@ultimat3/scraping/cdp';
13
14
  import type { ShotDriver, ShotSession, ShotSessionInit } from './browser-launcher-port';
14
15
  import { cdpShotPage } from './cdp-shot-page';
15
16
  import { watchPage } from './cdp-shot-watch';
@@ -2,7 +2,8 @@
2
2
  // (layout box and hit-test included, which no DOM-only check can see), and the poll that waits for
3
3
  // the first match to reach a state. Two refusals, because they are two questions: the page does
4
4
  // not have the element, or it does and something keeps it from being acted on.
5
- import type { ActionabilityState, ElementSnapshot, ShotClock } from './browser-launcher-port';
5
+ import type { SleepClock } from '@ultimat3/core';
6
+ import type { ActionabilityState, ElementSnapshot } from './browser-launcher-port';
6
7
  import { ShotElementMissingError, ShotElementUnreadyError } from './cdp-shot-errors';
7
8
 
8
9
  /** JSON text, so the answer has one deserialiser: `parseSnapshots` below. */
@@ -108,7 +109,7 @@ export interface ReadyWait {
108
109
  readonly selector: string;
109
110
  readonly state: ActionabilityState;
110
111
  readonly timeoutMs: number;
111
- readonly clock: ShotClock;
112
+ readonly clock: SleepClock;
112
113
  /** Re-read on every poll: never a handle captured before the loop. */
113
114
  readonly snapshot: () => Promise<ElementSnapshot | undefined>;
114
115
  readonly url: () => string;
@@ -4,8 +4,8 @@
4
4
  // mouse press at the element's centre, a keystroke is a key event — because an in-page `.click()`
5
5
  // skips `pointerdown`, which is what a dialog's backdrop listens to.
6
6
  import { assert, finiteCount, hostDecision } from '@ultimat3/core';
7
- import type { CdpConnection } from '@ultimat3/testing';
8
- import { CdpCallFailedError, CdpTimeoutError } from '@ultimat3/testing';
7
+ import type { CdpConnection } from '@ultimat3/scraping/cdp';
8
+ import { CdpCallFailedError, CdpTimeoutError } from '@ultimat3/scraping/cdp';
9
9
  import type {
10
10
  ElementSnapshot,
11
11
  ShotCapture,
@@ -3,13 +3,14 @@
3
3
  // every request is paused (`Fetch.requestPaused`) and refused unless its host is allowed, so an
4
4
  // injected `<img src="http://169.254.169.254/…">` never leaves — it is recorded as `refused`.
5
5
  // Paused at the BROWSER too, so a popup the page opens is decided by the same `hostDecision`.
6
+
7
+ import type { SleepClock } from '@ultimat3/core';
6
8
  import { hostDecision } from '@ultimat3/core';
7
- import type { CdpConnection } from '@ultimat3/testing';
9
+ import type { CdpConnection } from '@ultimat3/scraping/cdp';
8
10
  import type {
9
11
  ConsoleLine,
10
12
  NetworkEntry,
11
13
  PageError,
12
- ShotClock,
13
14
  ShotResourceType,
14
15
  } from './browser-launcher-port';
15
16
 
@@ -136,7 +137,7 @@ export function watchPage(input: {
136
137
  readonly connection: CdpConnection;
137
138
  readonly sessionId: string;
138
139
  readonly browserSessionId?: string | undefined;
139
- readonly clock: ShotClock;
140
+ readonly clock: SleepClock;
140
141
  readonly allowHosts: readonly string[];
141
142
  }): PageWatch {
142
143
  const { connection, sessionId, browserSessionId } = input;
package/src/ci-log.ts CHANGED
@@ -46,17 +46,40 @@ export function parseLogLines(log: string): readonly CiLogLine[] {
46
46
  const columns = line.split('\t');
47
47
  const tabbed = columns.length >= 3;
48
48
  const rest = tabbed ? columns.slice(2).join('\t') : line;
49
- const text = rest.replace(STAMP, '').replace(/^##\[group\]/, '');
49
+ const text = rest.replace(STAMP, '').replace(MARKER, '');
50
50
  if (text.startsWith('##[endgroup]')) continue;
51
- out.push({
52
- job: tabbed ? (columns[0] ?? '') : '',
53
- step: tabbed ? (columns[1] ?? '') : '',
54
- text,
55
- });
51
+ const job = tabbed ? (columns[0] ?? '') : '';
52
+ const step = tabbed ? (columns[1] ?? '') : '';
53
+ for (const part of unannotated(text)) out.push({ job, step, text: part });
56
54
  }
57
55
  return out;
58
56
  }
59
57
 
58
+ /**
59
+ * The runner's own line markers: `##[group]` opens a fold, and an annotation is printed with its
60
+ * level as a prefix (`##[error]X_LINT_FAILED`). Neither is the text the step wrote.
61
+ */
62
+ const MARKER = /^##\[(?:group|error|warning|notice|debug)\]/;
63
+ /** A workflow command a step echoed whole: `::error file=a.ts,title=t::message`. */
64
+ const ANNOTATION = /^::(?:error|warning|notice|debug)(?:\s[^:]*)?::(.*)$/;
65
+
66
+ /**
67
+ * An annotation's message, decoded: GitHub's encoding writes a newline as `%0A` (and `%` as
68
+ * `%25`), so a three-line finding inside one `::error` is one line of the log until this splits it
69
+ * back into the lines `renderFinding` wrote. MESSAGE data escapes only `%`, CR and LF — `%3A` and
70
+ * `%2C` are property escapes, and decoding them here would corrupt a URL in a fix. `%25` goes
71
+ * last, so an escaped `%250A` comes back as the text `%0A` rather than a line break.
72
+ */
73
+ function unannotated(text: string): readonly string[] {
74
+ const message = ANNOTATION.exec(text)?.[1];
75
+ if (message === undefined) return [text];
76
+ return message
77
+ .replaceAll('%0D', '')
78
+ .split('%0A')
79
+ .map((part) => part.replaceAll('%25', '%'))
80
+ .filter((part) => part.trim() !== '');
81
+ }
82
+
60
83
  /** Every job the log carries a line for, in the order they first appear. */
61
84
  export function jobsInLog(lines: readonly CiLogLine[]): readonly string[] {
62
85
  const seen: string[] = [];
@@ -75,16 +98,54 @@ const CODE = /^(X_[A-Z][A-Z0-9_]*)/;
75
98
  // `CODE (path) [step=unit]` — an end-anchor matches only what follows the brackets, the match
76
99
  // fails, and the path is dropped. With no step the optional group is absent and the
77
100
  // parenthesised group is still the last thing on the line.
78
- const LOCATOR = /\(([^()]+)\)(?=\s*(?:\[step=[^[\]]+\]\s*)?$)/;
101
+ // A `[from=ci-log …]` marker (`output.ts`'s `fromLabel`) may close the head after both: an `x ci`
102
+ // render read back by another `x ci` must still yield its locators.
103
+ const LOCATOR = /\(([^()]+)\)(?=\s*(?:\[step=[^[\]]+\]\s*)?(?:\[from=[^[\]]*\]\s*)?$)/;
79
104
  // The second, non-path locator the renderer prints on the head — `meta.step` in the same
80
105
  // brackets-keyed form (`[step=lint]`) `renderFinding` writes — so a merge gap's gate step name
81
106
  // or any future non-path identifier survives the round-trip too. Its own brackets are what
82
107
  // `LOCATOR`'s lookahead stands aside for, so the two cannot collide in one head.
83
- const STEP_LOCATOR = /\[step=([^[\]]+)\]\s*$/;
108
+ const STEP_LOCATOR = /\[step=([^[\]]+)\]\s*(?:\[from=[^[\]]*\]\s*)?$/;
84
109
 
85
110
  const after = (text: string, label: string): string | undefined =>
86
111
  text.trim().startsWith(label) ? text.trim().slice(label.length).trim() : undefined;
87
112
 
113
+ // `commentBlock`'s fence (`foreign-text.ts`), as it reaches a log: `x ci` run INSIDE a job prints a
114
+ // fenced value through `singleLine`, so its newlines arrive as the two characters `\n`. The
115
+ // fence is transport around the value, never the value — the reader is owed the command.
116
+ const FENCE_OPEN = /^<comment id="[^"]*">$/;
117
+ const FENCE_ONE_LINE = /^<comment id="[^"]*">(?:\\n)?([\s\S]*?)(?:\\n)?<\/comment>$/;
118
+ const FENCE_CLOSE = '</comment>';
119
+
120
+ /** One labelled field of a finding block, and the index of the line after it. */
121
+ interface Field {
122
+ readonly value: string;
123
+ readonly next: number;
124
+ }
125
+
126
+ /**
127
+ * The value of `label:` on line `index`, with a fence around it taken off — whether the fence was
128
+ * flattened onto one line or spread over the lines that follow until `</comment>`.
129
+ */
130
+ function fieldAt(texts: readonly string[], index: number, label: string): Field | undefined {
131
+ const value = after(texts[index] ?? '', label);
132
+ if (value === undefined) return undefined;
133
+ const flat = FENCE_ONE_LINE.exec(value);
134
+ if (flat !== null) {
135
+ return { value: (flat[1] ?? '').split(String.raw`\n`).join(' ').trim(), next: index + 1 };
136
+ }
137
+ if (!FENCE_OPEN.test(value)) return { value, next: index + 1 };
138
+ const close = texts.indexOf(FENCE_CLOSE, index + 1);
139
+ if (close === -1) return { value, next: index + 1 };
140
+ return {
141
+ value: texts
142
+ .slice(index + 1, close)
143
+ .join(' ')
144
+ .trim(),
145
+ next: close + 1,
146
+ };
147
+ }
148
+
88
149
  // The `meta.step` locator the renderer prints in the head (`output.ts:185-189`): a gate step name
89
150
  // the finding carries on `meta`, never on `at`. Total on every shape `Finding.meta` may take —
90
151
  // the field is optional, and a malformed `meta` (a non-object value, an array) is read as "no
@@ -129,13 +190,15 @@ export function findingsFrom(lines: readonly CiLogLine[]): readonly Finding[] {
129
190
  for (let index = 0; index < texts.length; index += 1) {
130
191
  const head = CODE.exec(texts[index] ?? '');
131
192
  if (head === null) continue;
132
- const cause = after(texts[index + 1] ?? '', 'cause:');
133
- const fix = after(texts[index + 2] ?? '', 'fix:');
134
- if (cause === undefined || fix === undefined) continue;
193
+ const causeField = fieldAt(texts, index + 1, 'cause:');
194
+ const fixField = causeField === undefined ? undefined : fieldAt(texts, causeField.next, 'fix:');
195
+ if (causeField === undefined || fixField === undefined) continue;
196
+ const cause = causeField.value;
197
+ const fix = fixField.value;
135
198
  const code = head[1] ?? '';
136
199
  const at = LOCATOR.exec(texts[index] ?? '')?.[1];
137
200
  const step = STEP_LOCATOR.exec(texts[index] ?? '')?.[1];
138
- const docs = after(texts[index + 3] ?? '', 'docs:');
201
+ const docs = after(texts[fixField.next] ?? '', 'docs:');
139
202
  // Step name and any other reconstructed structured fact ride on `meta`, so the
140
203
  // reconstructed finding has a place to put a non-path locator `at` cannot carry.
141
204
  const meta = step === undefined ? undefined : { step };
@@ -155,7 +218,7 @@ export function findingsFrom(lines: readonly CiLogLine[]): readonly Finding[] {
155
218
  seen.add(findingKey(finding));
156
219
  out.push(finding);
157
220
  }
158
- index += 2;
221
+ index = fixField.next - 1;
159
222
  }
160
223
  return out;
161
224
  }
@@ -1,7 +1,7 @@
1
1
  // `x affected`'s declaration, apart from its body: the parser, `x help` and the `errors` step
2
2
  // read it without loading `cmd-affected.ts`, which `registry.ts` imports only when the command runs.
3
3
 
4
- import { DEFAULT_BASE } from './affected';
4
+ import { DEFAULT_BASE_HELP } from './affected-base';
5
5
  import type { CommandSpec } from './parse';
6
6
 
7
7
  export const affectedSpec: CommandSpec = {
@@ -12,13 +12,17 @@ export const affectedSpec: CommandSpec = {
12
12
  {
13
13
  name: 'base',
14
14
  type: 'string',
15
- summary: `git ref to diff against, merge-base style (default: ${DEFAULT_BASE})`,
15
+ summary: `git ref to diff against, merge-base style (default: ${DEFAULT_BASE_HELP})`,
16
16
  },
17
17
  {
18
18
  name: 'dirty',
19
19
  type: 'boolean',
20
20
  summary: 'also count uncommitted work — every agent sharing this checkout, not only yours',
21
21
  },
22
- { name: 'paths', type: 'boolean', summary: 'print bare directories instead of a table' },
22
+ {
23
+ name: 'paths',
24
+ type: 'boolean',
25
+ summary: 'stdout is the directories alone, one per line; notes and the summary go to stderr',
26
+ },
23
27
  ],
24
28
  };