@ultimat3/cli 31.25.0 → 31.27.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 (123) hide show
  1. package/CLAUDE.md +44 -36
  2. package/README.md +5 -4
  3. package/package.json +29 -29
  4. package/src/app-mcp.ts +17 -3
  5. package/src/cmd-cache-spec.ts +5 -2
  6. package/src/cmd-db-recount.ts +7 -0
  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 +4 -1
  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-status-sample.ts +57 -0
  26. package/src/cmd-status-spec.ts +30 -0
  27. package/src/cmd-status.ts +108 -0
  28. package/src/cmd-token-spec.ts +5 -2
  29. package/src/cmd-token.ts +7 -3
  30. package/src/coverage-island.ts +121 -0
  31. package/src/coverage-lcov.ts +49 -5
  32. package/src/coverage-remap.ts +146 -0
  33. package/src/db-replay-engine-prepared.ts +66 -0
  34. package/src/db-replay-engine-template.ts +156 -0
  35. package/src/db-replay-engine.ts +4 -0
  36. package/src/db-replay-scratch-reap.ts +54 -0
  37. package/src/deploy-verify-flags.ts +9 -2
  38. package/src/deploy-verify-grade.ts +10 -3
  39. package/src/dev-boot.ts +14 -1
  40. package/src/dev-dashboard-guard.ts +57 -10
  41. package/src/dev-host.ts +46 -0
  42. package/src/dev-tls-cache.ts +103 -0
  43. package/src/dev-tls-der.ts +69 -0
  44. package/src/dev-tls.ts +120 -0
  45. package/src/dispatch.ts +6 -1
  46. package/src/doctor-browser.ts +60 -0
  47. package/src/error-codes-verify.ts +47 -0
  48. package/src/error-codes.ts +14 -23
  49. package/src/exercise-database.ts +40 -7
  50. package/src/exercise-push-device.ts +51 -0
  51. package/src/exercise-route-api.ts +74 -0
  52. package/src/exercise-routes.ts +14 -5
  53. package/src/exercise-services.ts +3 -1
  54. package/src/exercise-shard-flag.ts +47 -0
  55. package/src/fix-command.ts +2 -2
  56. package/src/generate-factories.ts +9 -11
  57. package/src/generate-feature-required.ts +9 -4
  58. package/src/generate-files.ts +20 -2
  59. package/src/generate-kinds.ts +5 -1
  60. package/src/guards.ts +21 -6
  61. package/src/island-bundle-options.ts +48 -0
  62. package/src/island-bundle.ts +18 -46
  63. package/src/island-link.ts +5 -0
  64. package/src/island-outputs.ts +5 -0
  65. package/src/mcp-errors-verify.ts +35 -0
  66. package/src/mcp-errors.ts +10 -19
  67. package/src/mcp-host-logs.ts +121 -0
  68. package/src/mcp-host.ts +12 -73
  69. package/src/messages-floor.ts +19 -0
  70. package/src/messages-status.ts +10 -0
  71. package/src/messages.ts +21 -0
  72. package/src/registry.ts +4 -0
  73. package/src/role-start-types.ts +7 -0
  74. package/src/role-start.ts +4 -0
  75. package/src/serve-boot.ts +7 -1
  76. package/src/serve-env-tls.ts +57 -0
  77. package/src/solid-loader.ts +27 -10
  78. package/src/templates/generate-export-rows.ts +136 -0
  79. package/src/templates/generate-import-rows.ts +186 -0
  80. package/src/templates/generate-rows-slice.ts +95 -0
  81. package/src/templates/github/ci.yml.ts +4 -0
  82. package/src/templates/scaffold-db-package.ts +3 -0
  83. package/src/templates/scaffold-docs.ts +8 -6
  84. package/src/templates/scaffold-repo.ts +2 -7
  85. package/src/templates/scaffold-site.ts +4 -1
  86. package/src/templates/scaffold-suites.ts +72 -0
  87. package/src/templates/scaffold-test-services.ts +35 -10
  88. package/src/templates/scaffold-verify-floor.ts +53 -31
  89. package/src/templates/shapes/api.ts +4 -0
  90. package/src/templates/slice-foundation.ts +3 -3
  91. package/src/unthrown-codes.ts +1 -1
  92. package/src/upgrade-gate.ts +6 -1
  93. package/src/upgrade-guards-baseline.ts +43 -0
  94. package/src/upgrade-guards.ts +37 -2
  95. package/src/upgrade-report.ts +3 -0
  96. package/src/verify-coverage-run.ts +42 -11
  97. package/src/verify-e2e.ts +115 -4
  98. package/src/verify-floor.ts +27 -0
  99. package/src/verify-guard-baseline.ts +109 -0
  100. package/src/verify-live.ts +72 -0
  101. package/src/verify-merge-skips.ts +51 -0
  102. package/src/verify-merge.ts +36 -2
  103. package/src/verify-run.ts +48 -7
  104. package/src/verify-services.ts +287 -0
  105. package/src/verify-skip-reason.ts +53 -0
  106. package/src/verify-strict.ts +108 -0
  107. package/src/verify-test-command.ts +129 -0
  108. package/src/verify-tests.ts +39 -126
  109. package/types/babel-modules.d.ts +2 -0
  110. package/wiki/Agents.md +2 -5
  111. package/wiki/CLI-Reference.md +142 -23
  112. package/wiki/Caching-And-Invalidation.md +1 -1
  113. package/wiki/Entities-And-Migrations.md +1 -1
  114. package/wiki/Interface-Rules.md +5 -0
  115. package/wiki/Jobs-And-Workflows.md +3 -3
  116. package/wiki/Known-Gaps.md +5 -1
  117. package/wiki/MCP-And-AI.md +103 -2
  118. package/wiki/Mail.md +52 -0
  119. package/wiki/PWA-And-Offline.md +1 -1
  120. package/wiki/Scraping.md +19 -4
  121. package/wiki/Troubleshooting.md +3 -3
  122. package/wiki/Tutorial-05-Deploy-Free.md +2 -2
  123. package/wiki/Upgrading.md +3 -0
@@ -5,7 +5,7 @@
5
5
 
6
6
  import type { Environment } from '@ultimat3/core';
7
7
  import { ENVIRONMENT_KEY, resolveEnvironment, UltimateError } from '@ultimat3/core';
8
- import type { DbClient } from '@ultimat3/db';
8
+ import type { DbClient, Migration } from '@ultimat3/db';
9
9
  import { dbExecutor, migrate, raw, setDbClient } from '@ultimat3/db';
10
10
  import {
11
11
  captureDeterminism,
@@ -14,9 +14,10 @@ import {
14
14
  testSealKeyEnv,
15
15
  } from '@ultimat3/testing';
16
16
  import { loadAppConfig } from './app-config-load';
17
- import { chooseReplayEngine, withScratchDatabase } from './db-replay-engine';
17
+ import { chooseReplayEngine } from './db-replay-engine';
18
+ import { withPreparedScratch } from './db-replay-engine-prepared';
18
19
  import { installExerciseServices } from './exercise-services';
19
- import { applyFrameworkSchema } from './framework-schema';
20
+ import { applyFrameworkSchema, FRAMEWORK_SCHEMA, schemaStatements } from './framework-schema';
20
21
  import { readMigrations } from './migrations';
21
22
  import { resolveServices } from './runtime-bindings';
22
23
 
@@ -89,10 +90,36 @@ export async function withExerciseProcess<T>(
89
90
  }
90
91
  }
91
92
 
93
+ /**
94
+ * What decides a prepared scratch database: every framework statement, every migration's id and
95
+ * text, and the extensions they link — hashed, so a new migration (or a framework release that
96
+ * changes a table) is a new key and a miss. PGlite's own version is `@ultimat3/db`'s to add.
97
+ */
98
+ export function exerciseSchemaKey(
99
+ migrations: readonly Migration[],
100
+ extensions: readonly string[],
101
+ ): string {
102
+ const hasher = new Bun.CryptoHasher('sha256');
103
+ const part = (text: string): void => {
104
+ hasher.update(`${String(text.length)}:${text}\u0000`);
105
+ };
106
+ for (const entry of FRAMEWORK_SCHEMA)
107
+ for (const statement of schemaStatements(entry.ddl)) part(statement);
108
+ part('--migrations--');
109
+ for (const migration of migrations) {
110
+ part(migration.id);
111
+ part(migration.up);
112
+ }
113
+ part('--extensions--');
114
+ for (const name of extensions) part(name);
115
+ return hasher.digest('hex');
116
+ }
117
+
92
118
  /**
93
119
  * Framework tables, then every migration — the order every real boot runs them in — then `work`
94
120
  * with the client installed. Released either way: a command that exits holding an installed
95
- * client would hand the next caller in this process a closed pool.
121
+ * client would hand the next caller in this process a closed pool. The migrated state is kept
122
+ * under the app's state dir (`db-replay-engine-prepared.ts`), so a second run restores it.
96
123
  */
97
124
  export async function withExerciseDatabase<T>(
98
125
  root: string,
@@ -102,9 +129,15 @@ export async function withExerciseDatabase<T>(
102
129
  const migrations = await readMigrations(root);
103
130
  const engine = await chooseReplayEngine(migrations, env);
104
131
  const { stateDir } = resolveServices(root, env);
105
- return withScratchDatabase(engine, stateDir, async (client) => {
106
- await applyFrameworkSchema((statement) => client.execute(raw(statement)));
107
- await migrate({ migrations, client });
132
+ const extensions = engine.kind === 'embedded' ? engine.extensions : engine.requires;
133
+ const preparation = {
134
+ key: exerciseSchemaKey(migrations, extensions),
135
+ prepare: async (client: DbClient) => {
136
+ await applyFrameworkSchema((statement) => client.execute(raw(statement)));
137
+ await migrate({ migrations, client });
138
+ },
139
+ };
140
+ return withPreparedScratch(engine, stateDir, preparation, async (client) => {
108
141
  setDbClient(client);
109
142
  // What a server's boot installs beside its database, over this one: a primitive that reads a
110
143
  // disk, a shared rate limit or the push runtime runs, rather than needing `{ off }`.
@@ -0,0 +1,51 @@
1
+ // The device every actor holds in `x exercise`: the pass's push store answers each actor's stored
2
+ // subscriptions, else one stand-in on a listed push service with real P-256 keys, so a notifier's
3
+ // push is encrypted, signed and sent to the captured service — and recorded as a `push` effect by
4
+ // the room. As the memory mail driver accepts every address: a pusher that sends nothing shows.
5
+
6
+ import type { PushSubscriptionRecord, PushSubscriptionStore } from '@ultimat3/pwa';
7
+
8
+ /** A host `pushHostAllowed` lists, under a path no real browser hands out. */
9
+ const STAND_IN_ENDPOINT = 'https://fcm.googleapis.com/fcm/send/x-exercise-';
10
+
11
+ const base64Url = (bytes: Uint8Array): string => bytes.toBase64({ alphabet: 'base64url' });
12
+
13
+ /** One receiver key pair for the whole pass: the private half is never read, only the public. */
14
+ async function standInKeys(): Promise<PushSubscriptionRecord['keys']> {
15
+ const pair = await crypto.subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, [
16
+ 'deriveBits',
17
+ ]);
18
+ const point = new Uint8Array(await crypto.subtle.exportKey('raw', pair.publicKey));
19
+ return { p256dh: base64Url(point), auth: base64Url(crypto.getRandomValues(new Uint8Array(16))) };
20
+ }
21
+
22
+ /**
23
+ * `store`, with one stand-in device for an actor it holds none for. Never written: a subscribe the
24
+ * pass runs stores its row in `store`, and a stand-in's removal (a 404 the captured service never
25
+ * answers) removes nothing.
26
+ */
27
+ export function withStandInDevice(store: PushSubscriptionStore): PushSubscriptionStore {
28
+ let keys: Promise<PushSubscriptionRecord['keys']> | undefined;
29
+ return {
30
+ save: (record) => store.save(record),
31
+ async listFor(actorId) {
32
+ const held = await store.listFor(actorId);
33
+ if (held.length > 0) return held;
34
+ keys ??= standInKeys();
35
+ const device: PushSubscriptionRecord = {
36
+ endpoint: `${STAND_IN_ENDPOINT}${encodeURIComponent(actorId)}`,
37
+ keys: await keys,
38
+ locale: 'en',
39
+ timeZone: 'UTC',
40
+ actorId,
41
+ createdAt: 0,
42
+ expirationTime: null,
43
+ };
44
+ return [device];
45
+ },
46
+ remove: (endpoint, actorId) =>
47
+ endpoint.startsWith(STAND_IN_ENDPOINT)
48
+ ? Promise.resolve(false)
49
+ : store.remove(endpoint, actorId),
50
+ };
51
+ }
@@ -0,0 +1,74 @@
1
+ // A route `load` that reads through the app's own typed client (`queries.orgPosts(…)` over
2
+ // `APP_URL`) answered IN PROCESS during `x exercise`, as the build's measurement render is
3
+ // (`measure-scope.ts`): core's `withInProcessFetch` hands each call to the app's own API pipeline,
4
+ // authenticated as the actor the load runs as — so its statements are the load's, counted and swept.
5
+
6
+ import type { Actor } from '@ultimat3/core';
7
+ import { asyncContext, isAnonymous, tryUseContext, withInProcessFetch } from '@ultimat3/core';
8
+ import { defineHttpConfig, httpPipeline, httpRouter } from '@ultimat3/http';
9
+ import type { RouteLoadSubject } from '@ultimat3/testing';
10
+ import { apiRoutes } from './api-routes';
11
+
12
+ /** The origin the typed client is told when the app's env names none: never dialled. */
13
+ export const EXERCISE_APP_URL = 'http://localhost:3000';
14
+
15
+ /** Who the in-process request authenticates as: the load's own actor, read at the call. */
16
+ const caller = asyncContext<Actor | null>('the exercise in-process caller');
17
+
18
+ /** One dispatcher over the app's API table, built on first use: the registries are full by then. */
19
+ function dispatcher(): (url: string, init: RequestInit) => Promise<Response> {
20
+ // No rate limit: every request is the pass's own, as a build's are (`measure-scope.ts`).
21
+ const config = defineHttpConfig({
22
+ buildId: process.env['BUILD_ID'] ?? 'dev',
23
+ rateLimit: { enabled: false },
24
+ });
25
+ const pipeline = httpPipeline({
26
+ table: httpRouter(apiRoutes()),
27
+ config,
28
+ hooks: { authenticate: () => caller.get() ?? null },
29
+ });
30
+ return (url, init) => {
31
+ // A `prerender()` runs in no request: nobody, as a published read is (`publicScope`).
32
+ const actor = tryUseContext()?.actor;
33
+ // The page's own server calling its own API: same-origin by construction, so it says so —
34
+ // a write with neither `origin` nor `sec-fetch-site` is `X_CSRF_BLOCKED`, as it should be.
35
+ const headers = new Headers(init.headers);
36
+ if (!headers.has('origin')) headers.set('origin', new URL(url).origin);
37
+ return caller.run(actor === undefined || isAnonymous(actor) ? null : actor, () =>
38
+ pipeline.handle(new Request(url, { ...init, headers }), { role: 'web' }),
39
+ );
40
+ };
41
+ }
42
+
43
+ /**
44
+ * The app's own origin — `APP_URL` as the typed client reads it, at the call: only its urls are
45
+ * the app's to answer. Any other host is a call out, left to the pass's sealed network, which
46
+ * refuses and records it as one (`exercise-report.ts`).
47
+ */
48
+ const ownOrigin = (url: string): boolean => {
49
+ const base = process.env['APP_URL'] || EXERCISE_APP_URL;
50
+ try {
51
+ return new URL(url).origin === new URL(base).origin;
52
+ } catch {
53
+ return false;
54
+ }
55
+ };
56
+
57
+ /** `routes`, each load's (and `prerender()`'s) typed-client calls answered by the app's API here. */
58
+ export function servedInProcess(routes: readonly RouteLoadSubject[]): readonly RouteLoadSubject[] {
59
+ let dispatch: ReturnType<typeof dispatcher> | undefined;
60
+ const served = (url: string, init: RequestInit): Promise<Response> => {
61
+ dispatch ??= dispatcher();
62
+ return dispatch(url, init);
63
+ };
64
+ return routes.map((route) => {
65
+ const { samples } = route;
66
+ return {
67
+ ...route,
68
+ load: (ctx) => withInProcessFetch(served, () => route.load(ctx), ownOrigin),
69
+ ...(samples === undefined
70
+ ? {}
71
+ : { samples: () => withInProcessFetch(served, () => samples.call(route), ownOrigin) }),
72
+ };
73
+ });
74
+ }
@@ -3,6 +3,7 @@
3
3
  // each naming the route file or the primitive. Warnings on `main` — a page read was never judged
4
4
  // before, and an app that has not opted in stays green (X_BREAKING_ON_MAIN); red needs a floor key.
5
5
 
6
+ import { renderFixLiteral } from '@ultimat3/core';
6
7
  import type { ExerciseRecord, RouteLoadRecord } from '@ultimat3/testing';
7
8
 
8
9
  const where = (record: RouteLoadRecord): string => `route ${record.name} (${record.file})`;
@@ -10,10 +11,13 @@ const where = (record: RouteLoadRecord): string => `route ${record.name} (${reco
10
11
  /** Each route's load as warning lines: a loop, a call over the ceiling, a seq scan, or unrun. */
11
12
  export function routeLoadWarnings(records: readonly RouteLoadRecord[]): readonly string[] {
12
13
  return records.flatMap((record): readonly string[] => {
14
+ // `off` is declared, with its reason, in the report: nothing left to say.
15
+ if (record.outcome === 'off') return [];
13
16
  if (record.outcome !== 'reached') {
14
17
  return [`${where(record)} · load not exercised: ${record.reason ?? record.outcome}`];
15
18
  }
16
19
  const lines: string[] = [];
20
+ if (vacuous(record) && record.empty === undefined) lines.push(emptyRouteLine(record));
17
21
  if (record.scale?.verdict === 'grows') {
18
22
  for (const shape of record.scale.shapes) {
19
23
  lines.push(
@@ -35,6 +39,14 @@ export function routeLoadWarnings(records: readonly RouteLoadRecord[]): readonly
35
39
  });
36
40
  }
37
41
 
42
+ /** Reached with no statement and no effect: every proof on it is vacuous. */
43
+ const vacuous = (record: ExerciseRecord | RouteLoadRecord): boolean =>
44
+ record.outcome === 'reached' && record.statements === 0 && record.effects.length === 0;
45
+
46
+ /** The route's own line: its entry is keyed by pattern, so the paste names it. */
47
+ const emptyRouteLine = (record: RouteLoadRecord): string =>
48
+ `${where(record)} · ${EMPTY_REACH} its load sent no statement and had no effect, so its proofs prove nothing — fix: edit exercise.ts: defineExercise({…}, { routes: { ${renderFixLiteral(record.name, '<pattern>')}: { empty: '<why it reads nothing>' } } }), or give it the params that reach its read`;
49
+
38
50
  /** How many names an empty-reach line lists before it says how many more. */
39
51
  const NAMED = 5;
40
52
 
@@ -46,14 +58,11 @@ const EMPTY_REACH = 'X_EXERCISE_EMPTY_REACH';
46
58
  * is "flat", a tenant proof over nothing is "proven". Said once, with the first few named.
47
59
  */
48
60
  export function emptyReachWarnings(records: readonly ExerciseRecord[]): readonly string[] {
49
- const empty = records.filter(
50
- (record) =>
51
- record.outcome === 'reached' && record.statements === 0 && record.effects.length === 0,
52
- );
61
+ const empty = records.filter((record) => vacuous(record) && record.empty === undefined);
53
62
  if (empty.length === 0) return [];
54
63
  const named = empty.slice(0, NAMED).map((record) => `${record.kind} ${record.name}`);
55
64
  const more = empty.length > NAMED ? `, and ${String(empty.length - NAMED)} more` : '';
56
65
  return [
57
- `${EMPTY_REACH} ${String(empty.length)} reached primitive(s) sent no statement and had no effect, so their proofs prove nothing: ${named.join(', ')}${more} — fix: edit exercise.ts: give each an input that reaches its work, or { off: '<why>' }`,
66
+ `${EMPTY_REACH} ${String(empty.length)} reached primitive(s) sent no statement and had no effect, so their proofs prove nothing: ${named.join(', ')}${more} — fix: edit exercise.ts: give each an input that reaches its work, { empty: '<why it touches nothing>' }, or { off: '<why>' }`,
58
67
  ];
59
68
  }
@@ -13,6 +13,7 @@ import {
13
13
  memoryStorageDriver,
14
14
  resetStorage,
15
15
  } from '@ultimat3/storage';
16
+ import { withStandInDevice } from './exercise-push-device';
16
17
  import type { Env } from './runtime-bindings';
17
18
  import { selectWebPush } from './runtime-push';
18
19
 
@@ -55,7 +56,8 @@ async function installPush(inputs: ExerciseServiceInputs): Promise<() => void> {
55
56
  if (selection === undefined) return () => undefined;
56
57
  const { installWebPush, postgresPushSubscriptionStore } = await import('@ultimat3/pwa');
57
58
  return installWebPush({
58
- store: postgresPushSubscriptionStore({ executor: inputs.executor }),
59
+ // Every actor holds a device (`exercise-push-device.ts`): a sent push is an effect the room sees.
60
+ store: withStandInDevice(postgresPushSubscriptionStore({ executor: inputs.executor })),
59
61
  keys: selection.resolved.keys,
60
62
  subject: selection.subject,
61
63
  pushHosts: selection.pushHosts,
@@ -0,0 +1,47 @@
1
+ // `x exercise --shard i/n`: one of n processes' slice of the pass (`@ultimat3/testing`'s
2
+ // `exercise-shard.ts`), each on its own scratch database. A slice writes its own report beside the
3
+ // whole pass's, and judges no whole-pass floor: a ratio over a third of the pass is not the pass's.
4
+
5
+ // why: Bun ships no path joiner.
6
+ import { join } from 'node:path';
7
+ import { EXERCISE_REPORT_FILE } from './exercise-findings';
8
+ import type { ParsedArgs } from './parse';
9
+ import { flagString } from './parse';
10
+ import type { ShardSpec } from './verify-shard';
11
+ import { parseShard, VerifyShardInvalidError } from './verify-shard';
12
+
13
+ const COMMAND = 'x exercise';
14
+
15
+ /** `--shard`, read: absent, the whole pass. Refused beside a `<name>`, which is a slice already. */
16
+ export function readExerciseShard(
17
+ args: ParsedArgs,
18
+ only: string | undefined,
19
+ ): ShardSpec | undefined {
20
+ const raw = flagString(args, 'shard');
21
+ if (raw === undefined) return undefined;
22
+ let spec: ShardSpec;
23
+ try {
24
+ spec = parseShard(raw, COMMAND);
25
+ } catch {
26
+ // The verify step's fix names `--only`, which this command has not: the reason, with ours.
27
+ throw new VerifyShardInvalidError({
28
+ reason: 'expects i/n with 1 <= i <= n (e.g. 2/4)',
29
+ fix: `${COMMAND} --shard 1/2 --json`,
30
+ command: COMMAND,
31
+ });
32
+ }
33
+ if (only !== undefined) {
34
+ throw new VerifyShardInvalidError({
35
+ reason: 'a shard is a slice of the whole pass, and a <name> already runs one primitive',
36
+ fix: `${COMMAND} --shard ${String(spec.index)}/${String(spec.total)} --json`,
37
+ command: COMMAND,
38
+ });
39
+ }
40
+ return spec;
41
+ }
42
+
43
+ /** Where a slice's report goes: `.x/exercise.2-of-4.json`, never over the whole pass's file. */
44
+ export const shardReportFile = (shard: ShardSpec | undefined): string =>
45
+ shard === undefined
46
+ ? EXERCISE_REPORT_FILE
47
+ : join('.x', `exercise.${String(shard.index)}-of-${String(shard.total)}.json`);
@@ -147,8 +147,8 @@ export interface CommandCatalog {
147
147
  * one is a defect; a doc page may legitimately *say* a command is planned, and a rule that refused
148
148
  * that would delete `wiki/CLI-Reference.md`'s planned table one true row at a time.
149
149
  *
150
- * `allowPlanned` covers `PLANNED_SUBCOMMANDS` as well as `PLANNED_COMMANDS` — `x db studio` is the
151
- * single entry in the first table, and four pages name it as planned.
150
+ * `allowPlanned` covers `PLANNED_SUBCOMMANDS` as well as `PLANNED_COMMANDS`. The subcommand table is
151
+ * empty `As of 2026-11-15`; the rule stays so the next planned subcommand needs no second one.
152
152
  */
153
153
  export interface CitationRules {
154
154
  readonly allowPlanned?: boolean;
@@ -27,7 +27,7 @@ export const FACTORY_GENERATORS: readonly FactoryGenerator[] = [
27
27
  { factory: 'agent', none: MODEL },
28
28
  {
29
29
  factory: 'agentJob',
30
- none: 'wraps an action the app already declares, and which one is a choice x g cannot read off the disk; deferred (plan 101 U6) until x g takes the action to wrap',
30
+ none: "a worker runs a job as its tenant alone, with no grant, so an agentJob over any action x g action writes (policy: can('<feature>:write')) is X_FORBIDDEN on every attempt unless its actor() re-reads the member who asked — and how a member is found (its id on the input, the app's own member table and roles) is the app's convention; paste agentJob(<action>, { name, tenant, retry, actor }) beside the action, as examples/dummy/apps/web/app/posts/jobs/review-draft-later.ts does",
31
31
  },
32
32
  { factory: 'backfill', generator: 'backfill' },
33
33
  {
@@ -39,15 +39,9 @@ export const FACTORY_GENERATORS: readonly FactoryGenerator[] = [
39
39
  factory: 'deviceSocket',
40
40
  none: 'a websocket mount speaking the app’s own device protocol; the protocol is the whole of the declaration, and only the app knows it',
41
41
  },
42
- {
43
- factory: 'exportRows',
44
- none: 'reads one table through the app’s typed handle into a storage disk; deferred (plan 101 U6) until x g can refuse a slice whose table is not the scaffolded one under its own code',
45
- },
42
+ { factory: 'exportRows', generator: 'export-rows' },
46
43
  { factory: 'hive', none: MODEL },
47
- {
48
- factory: 'importRows',
49
- none: 'writes an uploaded file into one table through the app’s typed handle; deferred (plan 101 U6) on the same refusal exportRows waits for',
50
- },
44
+ { factory: 'importRows', generator: 'import-rows' },
51
45
  {
52
46
  factory: 'ledger',
53
47
  none: 'the attempt table a webhook() delivery writes, declared once beside that webhook — it has no meaning without one, so it ships with it',
@@ -96,7 +90,7 @@ export const FACTORY_GENERATORS: readonly FactoryGenerator[] = [
96
90
  },
97
91
  {
98
92
  factory: 'rollup',
99
- none: 'counts a source table into a destination entity by bucket; deferred (plan 101 U6) until x g plants the destination entity and its migration beside it',
93
+ none: 'counts a source table into a DESTINATION entity by bucket, with that entity’s key columns as the upsert key — two tables, one of them new, so the declaration is an entity, a migration (x db gen) and the call, never one call; x g entity <name>-daily writes the destination, then the rollup is pasted beside it',
100
94
  },
101
95
  {
102
96
  factory: 'scrape',
@@ -120,9 +114,13 @@ export const FACTORY_GENERATORS: readonly FactoryGenerator[] = [
120
114
  },
121
115
  {
122
116
  factory: 'webhook',
123
- none: 'one signed delivery to an endpoint the app stores, with its ledger; deferred (plan 101 U6) until x g plants the endpoint table and the ledger it needs',
117
+ none: 'one signed delivery to an endpoint the app stores, read per attempt with its secret, plus the ledger() table every attempt is written to — the endpoint and event tables are the app’s own schema and the ledger is a migration, so the declaration is two tables and the call, never one call',
124
118
  },
125
119
  { factory: 'webhookReceiver', generator: 'webhook-receiver' },
120
+ {
121
+ factory: 'inboundMail',
122
+ none: 'a receiver over a provider the app has an account with — which provider, its secret and where a message goes are choices x g cannot read off the disk; the wiki Mail page has the one call to paste',
123
+ },
126
124
  ];
127
125
 
128
126
  /** `x g llm` or `x g agent-job`: the factory a word names, when it is one no generator writes. */
@@ -1,6 +1,6 @@
1
- // `x g query` and `x g backfill` read a table, so a slice with no `entity.ts` is refused rather than
2
- // handed one. `x g query order` wrote 14 files and `next: x db gen "create orders"`: a read asked
3
- // for and a table delivered. Only `x g entity` and `x g resource` create a feature's data.
1
+ // `x g query`, `backfill`, `export-rows` and `import-rows` read a table, so a slice with no
2
+ // `entity.ts` is refused rather than handed one: `x g query order` wrote 14 files and `next: x db
3
+ // gen "create orders"`. Only `x g entity` and `x g resource` create a feature's data.
4
4
 
5
5
  import { existsSync } from 'node:fs'; // why: a synchronous file probe, as the slice's own guard.
6
6
  import { UltimateError } from '@ultimat3/core';
@@ -11,7 +11,12 @@ import { containedPath } from './generate-write';
11
11
  import { quoteArg } from './shell-quote';
12
12
 
13
13
  /** The generators whose whole body reads a table the slice declares. */
14
- const READS_A_TABLE: ReadonlySet<Generator> = new Set<Generator>(['query', 'backfill']);
14
+ export const READS_A_TABLE: ReadonlySet<Generator> = new Set<Generator>([
15
+ 'query',
16
+ 'backfill',
17
+ 'export-rows',
18
+ 'import-rows',
19
+ ]);
15
20
 
16
21
  /** Declared beside its one thrower: `errors.ts` sits at its 500-line ceiling. */
17
22
  export class FeatureRequiredError extends UltimateError {
@@ -30,6 +30,8 @@ import {
30
30
  import { adminCatalogFiles } from './templates/admin-catalog';
31
31
  import { helmDashboardFiles } from './templates/chart-dashboard';
32
32
  import { cronJobFiles } from './templates/generate-cron-job';
33
+ import { exportRowsFiles } from './templates/generate-export-rows';
34
+ import { importRowsFiles } from './templates/generate-import-rows';
33
35
  import { purgeFiles } from './templates/generate-purge';
34
36
  import { webhookReceiverFiles } from './templates/generate-webhook-receiver';
35
37
  import { inviteFiles } from './templates/invite';
@@ -200,14 +202,30 @@ export function generate(options: GenerateOptions): readonly GeneratedFile[] {
200
202
  ...(options.sliceRepo === undefined ? {} : { sliceRepo: options.sliceRepo }),
201
203
  }),
202
204
  );
203
- // A primitive factory's one call, in the feature's slice. None reads the slice: each declares
204
- // no table of its own, so it compiles in a feature that has no entity yet.
205
+ // A primitive factory's one call, in the feature's slice. These three read no slice: each
206
+ // declares no table of its own, so it compiles in a feature that has no entity yet.
205
207
  case 'cron-job':
206
208
  return dedupe(cronJobFiles(options.name, target));
207
209
  case 'purge':
208
210
  return dedupe(purgeFiles(options.name, target));
209
211
  case 'webhook-receiver':
210
212
  return dedupe(webhookReceiverFiles(options.name, target));
213
+ // These two DO read the slice: each moves its own scaffolded table through storage, so a slice
214
+ // shaped otherwise is refused, and one with no entity has it planted — `backfill`'s rule.
215
+ case 'export-rows':
216
+ case 'import-rows': {
217
+ const rows = {
218
+ ...target,
219
+ ...(options.locales === undefined ? {} : { locales: options.locales }),
220
+ ...(options.sliceEntity === undefined ? {} : { sliceEntity: options.sliceEntity }),
221
+ ...(options.sliceRepo === undefined ? {} : { sliceRepo: options.sliceRepo }),
222
+ };
223
+ return dedupe(
224
+ options.kind === 'export-rows'
225
+ ? exportRowsFiles(options.name, rows)
226
+ : importRowsFiles(options.name, rows),
227
+ );
228
+ }
211
229
  case 'entity':
212
230
  // With the labels the admin reads for it: the entity is an admin screen once it is in the
213
231
  // handle, whether or not a resource was generated around it.
@@ -19,11 +19,13 @@ export const GENERATORS = [
19
19
  'action',
20
20
  'mutator',
21
21
  'backfill',
22
- // Three primitive factories, each its one call in the feature's `jobs/`. Which factories have a
22
+ // Five primitive factories, each its one call in the feature's `jobs/`. Which factories have a
23
23
  // generator, and why the rest have none, is `FACTORY_GENERATORS` (`generate-factories.ts`).
24
24
  'cron-job',
25
25
  'purge',
26
26
  'webhook-receiver',
27
+ 'export-rows',
28
+ 'import-rows',
27
29
  'job',
28
30
  'route',
29
31
  'policy',
@@ -291,6 +293,8 @@ const EXAMPLE_NAME: Readonly<Record<Generator, string>> = {
291
293
  'cron-job': 'nightly-report',
292
294
  purge: 'purge-retained',
293
295
  'webhook-receiver': 'billing-events',
296
+ 'export-rows': 'export-posts --feature post',
297
+ 'import-rows': 'import-posts --feature post',
294
298
  job: 'send-digest',
295
299
  route: 'posts',
296
300
  policy: 'post',
package/src/guards.ts CHANGED
@@ -13,6 +13,9 @@ import { ERROR_DOCS_URL, renderCauseValue, renderThrowable } from '@ultimat3/cor
13
13
  import { fixProblem } from './error-contract';
14
14
  import { type GuardSources, guardSources } from './guard-sources';
15
15
  import type { Finding } from './output';
16
+ import { readVerifyFloor } from './verify-floor';
17
+ import type { GuardBaseline } from './verify-guard-baseline';
18
+ import { judgeGuardBaseline, orphanedBaselineFindings } from './verify-guard-baseline';
16
19
 
17
20
  /** The directory IS the registration. An app-side list is a list an app can forget to add to. */
18
21
  export const GUARD_DIR = 'guards';
@@ -167,7 +170,12 @@ export interface GuardReport {
167
170
  const refused = (finding: Finding): GuardReport => ({ findings: [finding], warnings: [] });
168
171
 
169
172
  /** One guard: import it, run it, and hold what it returns to the contract. Never throws. */
170
- async function runGuard(root: string, path: string, sources: GuardSources): Promise<GuardReport> {
173
+ async function runGuard(
174
+ root: string,
175
+ path: string,
176
+ sources: GuardSources,
177
+ baseline: GuardBaseline | undefined,
178
+ ): Promise<GuardReport> {
171
179
  let loaded: unknown;
172
180
  try {
173
181
  loaded = await import(pathToFileURL(join(root, path)).href);
@@ -201,9 +209,11 @@ async function runGuard(root: string, path: string, sources: GuardSources): Prom
201
209
  broken.push(findingInvalid(path, `it could not be read: ${messageOf(error)}`));
202
210
  }
203
211
  }
204
- return exported.severity === 'warning'
205
- ? { findings: broken, warnings: held }
206
- : { findings: [...broken, ...held], warnings: [] };
212
+ if (exported.severity === 'warning') return { findings: broken, warnings: held };
213
+ // A gating guard under its `guardBaseline` (`verify-guard-baseline.ts`): a broken finding is
214
+ // never counted against it — the contract fails either way.
215
+ const judged = judgeGuardBaseline(path, held, baseline);
216
+ return { findings: [...broken, ...judged.findings], warnings: judged.notices };
207
217
  }
208
218
 
209
219
  /**
@@ -221,11 +231,16 @@ export const guardReport = async (
221
231
  const findings: Finding[] = [];
222
232
  const warnings: Finding[] = [];
223
233
  const sources = guardSources(root, seed);
224
- for (const path of await guardPaths(root)) {
225
- const report = await runGuard(root, path, sources);
234
+ // Read here, not passed in: every caller of this seam — the step, `x upgrade`'s measuring run —
235
+ // judges the same committed counts, and a floor problem is the `manifest` step's to report.
236
+ const baseline = (await readVerifyFloor(root))?.guardBaseline;
237
+ const paths = await guardPaths(root);
238
+ for (const path of paths) {
239
+ const report = await runGuard(root, path, sources, baseline);
226
240
  findings.push(...report.findings);
227
241
  warnings.push(...report.warnings);
228
242
  }
243
+ findings.push(...orphanedBaselineFindings(paths, baseline));
229
244
  return { findings, warnings };
230
245
  };
231
246
 
@@ -0,0 +1,48 @@
1
+ // What a caller may ask of `buildIslands`: one island, the split, the cache, the realtime answer,
2
+ // Solid as a vendor, and a coverage build. Split from `island-bundle.ts`, which builds.
3
+
4
+ export interface BuildIslandsOptions {
5
+ /**
6
+ * Build ONE island, named app-root-relative — the whole option surface. A test that mounts a
7
+ * single island otherwise pays every OTHER island's Babel pass and `Bun.build` on every file,
8
+ * and the reference app is the one that feels it.
9
+ *
10
+ * Optional, and it must stay optional: `buildIslands` is on `@ultimat3/cli`'s public surface and
11
+ * `@ultimat3/testing`'s `IslandBuilder` satisfies it STRUCTURALLY as `(root: string) => …`, which
12
+ * is what keeps the `cli -> testing` edge pointing the one legal way.
13
+ */
14
+ readonly only?: string;
15
+ /**
16
+ * One split build over every island (`app.config.ts`'s `islands.sharedChunks`, off by default),
17
+ * or one build per route group (`island-groups.ts`). Passed, it overrides the app's config — the
18
+ * seam a test asks both questions of one fixture through.
19
+ */
20
+ readonly sharedChunks?: boolean;
21
+ /**
22
+ * Reuse a group's output from `.x/cache/islands/` while every file it read is unchanged
23
+ * (`island-group-cache.ts`) — on by default. `false` is the seam a determinism test builds
24
+ * through: a reused byte string proves nothing about the bundler that emitted it.
25
+ */
26
+ readonly reuse?: boolean;
27
+ /**
28
+ * Whether the app persists records (`appPersistsRecords`), asked only by a group one of whose
29
+ * islands reaches realtime, and once per call. `x dev` builds islands BESIDE the app load
30
+ * (`buildGeneration`), so it passes the answer the registry gives once the load settles; read
31
+ * any earlier it is the empty registry's `undefined`, and every reader islands is held. Absent,
32
+ * the registry is read as it stands: the caller loaded the app first.
33
+ */
34
+ readonly persists?: () => Promise<boolean | undefined>;
35
+ /**
36
+ * Solid as ONE shared output every island imports (`island-vendor.ts`), off by default. Measured
37
+ * As of 2026-11-12 (Bun 1.4.4, solid-js 1.9.17): each island inlines a tree-shaken ~14 kB of
38
+ * Solid, the whole vendor is 48,083 B, so every Solid route of the three tracked apps grew
39
+ * +33,572…+38,769 B with it on; it pays only where a page renders four or more Solid islands
40
+ * that are built apart.
41
+ */
42
+ readonly vendorSolid?: boolean;
43
+ /**
44
+ * A build for `mountIsland` under a coverage run: whitespace kept, Babel's lines kept, the map on
45
+ * every chunk — so the chunk's lines count for the island's source. Never cached, never shipped.
46
+ */
47
+ readonly coverage?: boolean;
48
+ }