@ultimat3/cli 30.9.0 → 31.0.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 (197) hide show
  1. package/CLAUDE.md +75 -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.ts +5 -1
  6. package/src/app-boundaries.ts +88 -9
  7. package/src/app-load-async.ts +133 -0
  8. package/src/app-load-batch.ts +203 -0
  9. package/src/app-load-prebuilt.ts +147 -0
  10. package/src/app-load-register.ts +175 -0
  11. package/src/app-load.ts +143 -175
  12. package/src/app-loader-imports.ts +31 -0
  13. package/src/app-root.ts +13 -0
  14. package/src/app-runtime.ts +5 -1
  15. package/src/boundary-findings.ts +12 -0
  16. package/src/browser-launcher-port.ts +3 -7
  17. package/src/browser-launcher.ts +1 -1
  18. package/src/budgets-scan.ts +8 -0
  19. package/src/budgets.ts +10 -1
  20. package/src/build-registry-background.ts +59 -0
  21. package/src/build-registry.ts +207 -0
  22. package/src/cdp-shot-clock.ts +3 -11
  23. package/src/cdp-shot-driver.ts +3 -2
  24. package/src/cdp-shot-element.ts +3 -2
  25. package/src/cdp-shot-page.ts +2 -2
  26. package/src/cdp-shot-watch.ts +4 -3
  27. package/src/cmd-auth.ts +3 -3
  28. package/src/cmd-db-recount.ts +15 -0
  29. package/src/cmd-drill.ts +10 -6
  30. package/src/cmd-exercise.ts +2 -1
  31. package/src/cmd-generate-spec.ts +6 -0
  32. package/src/cmd-generate.ts +22 -4
  33. package/src/cmd-mail.ts +1 -1
  34. package/src/cmd-routes.ts +2 -2
  35. package/src/cmd-secrets-spec.ts +4 -1
  36. package/src/cmd-shot.ts +14 -4
  37. package/src/cmd-verify-spec.ts +21 -1
  38. package/src/cmd-verify.ts +16 -4
  39. package/src/coverage-source.ts +4 -1
  40. package/src/db-diagnostics.ts +8 -1
  41. package/src/dev-boot.ts +29 -15
  42. package/src/dev-dashboard-invalidations.ts +43 -0
  43. package/src/dev-dashboard.ts +13 -16
  44. package/src/dev-n-plus-one.ts +7 -3
  45. package/src/dev-rebuild.ts +2 -1
  46. package/src/dev-route-table.ts +1 -1
  47. package/src/dev-traces.ts +16 -15
  48. package/src/document-options.ts +12 -1
  49. package/src/drift-store.ts +55 -0
  50. package/src/error-catalog.ts +8 -3
  51. package/src/error-codes-boundary.ts +32 -0
  52. package/src/error-codes.ts +23 -19
  53. package/src/errors.ts +17 -7
  54. package/src/exercise-database.ts +13 -1
  55. package/src/exercise-findings.ts +36 -18
  56. package/src/exercise-services.ts +84 -0
  57. package/src/exercise-subject.ts +38 -13
  58. package/src/failure-capture-boot.ts +9 -5
  59. package/src/framework-schema.ts +5 -5
  60. package/src/generate-exercise.ts +1 -1
  61. package/src/generate-files.ts +27 -7
  62. package/src/generate-kinds.ts +5 -0
  63. package/src/generate-refresh.ts +53 -0
  64. package/src/generate-workspace.ts +169 -0
  65. package/src/generate-write.ts +8 -2
  66. package/src/hold.ts +19 -8
  67. package/src/image-prepare.ts +6 -2
  68. package/src/index.ts +5 -20
  69. package/src/island-bundle.ts +7 -3
  70. package/src/island-capture.ts +2 -2
  71. package/src/island-harness.ts +1 -1
  72. package/src/job-registration.ts +43 -6
  73. package/src/jobs-driver.ts +4 -5
  74. package/src/mcp-errors.ts +18 -4
  75. package/src/mcp-host.ts +5 -1
  76. package/src/mcp-ui-interact.ts +3 -0
  77. package/src/messages-gate.ts +4 -0
  78. package/src/new-shapes-generate.ts +1 -1
  79. package/src/otlp-export.ts +94 -29
  80. package/src/output.ts +3 -7
  81. package/src/page-sync.ts +3 -1
  82. package/src/role-load.ts +17 -11
  83. package/src/role-start.ts +5 -4
  84. package/src/role-sync.ts +7 -8
  85. package/src/route-islands-preload.ts +46 -0
  86. package/src/route-islands.ts +6 -2
  87. package/src/runtime-admin.ts +5 -1
  88. package/src/runtime-bindings.ts +25 -19
  89. package/src/runtime-boot-ports.ts +66 -0
  90. package/src/runtime-bus.ts +29 -5
  91. package/src/runtime-cache-bus.ts +53 -0
  92. package/src/runtime-cache.ts +43 -13
  93. package/src/runtime-isr-outcome.ts +5 -4
  94. package/src/runtime-jobs.ts +2 -2
  95. package/src/runtime-keys.ts +37 -0
  96. package/src/runtime-overrides.ts +148 -42
  97. package/src/runtime-port-bindings-queue.ts +36 -0
  98. package/src/runtime-port-bindings.ts +117 -0
  99. package/src/runtime-ports.ts +164 -0
  100. package/src/runtime-purge.ts +41 -28
  101. package/src/runtime-push.ts +7 -3
  102. package/src/runtime-queue.ts +70 -55
  103. package/src/runtime-realtime.ts +5 -5
  104. package/src/runtime-render-document.ts +4 -1
  105. package/src/runtime-services.ts +110 -158
  106. package/src/runtime-storage-boot.ts +111 -0
  107. package/src/runtime-storage-upload.ts +9 -7
  108. package/src/runtime-storage.ts +7 -1
  109. package/src/serve-boot.ts +8 -4
  110. package/src/serve-entry.ts +3 -0
  111. package/src/serve-env.ts +47 -14
  112. package/src/serve-prebuilt-paths.ts +3 -0
  113. package/src/serve-prebuilt.ts +15 -4
  114. package/src/serve.ts +2 -2
  115. package/src/static-cards.ts +3 -2
  116. package/src/static-report.ts +2 -2
  117. package/src/style-bundle.ts +1 -1
  118. package/src/sync-authenticator.ts +17 -18
  119. package/src/templates/action-tests.ts +4 -4
  120. package/src/templates/backfill.ts +5 -8
  121. package/src/templates/entity.ts +3 -0
  122. package/src/templates/github/ci.yml.ts +3 -1
  123. package/src/templates/github/dependabot.yml.ts +73 -0
  124. package/src/templates/job.ts +13 -22
  125. package/src/templates/naming.ts +20 -1
  126. package/src/templates/pinned/docker-compose.yml +1 -1
  127. package/src/templates/query.ts +7 -8
  128. package/src/templates/route.ts +5 -3
  129. package/src/templates/scaffold-api.ts +1 -1
  130. package/src/templates/scaffold-auth.ts +5 -3
  131. package/src/templates/scaffold-claude-commands.ts +6 -3
  132. package/src/templates/scaffold-claude.ts +4 -4
  133. package/src/templates/scaffold-container-compose.ts +2 -4
  134. package/src/templates/scaffold-domain-package.ts +1 -1
  135. package/src/templates/scaffold-entries.ts +6 -1
  136. package/src/templates/scaffold-helm-fences.ts +3 -2
  137. package/src/templates/scaffold-helm.ts +35 -6
  138. package/src/templates/scaffold-repo.ts +47 -135
  139. package/src/templates/scaffold-runtime-ports.ts +62 -0
  140. package/src/templates/scaffold-verify-floor.ts +97 -0
  141. package/src/templates/shapes/overlay.ts +1 -1
  142. package/src/templates/sign-in-oidc.ts +5 -3
  143. package/src/templates/sign-in-shared.ts +28 -10
  144. package/src/templates/workspace.ts +75 -0
  145. package/src/test-ignores.ts +5 -2
  146. package/src/test-select.ts +4 -1
  147. package/src/upgrade-gate.ts +30 -5
  148. package/src/upgrade-report.ts +7 -1
  149. package/src/verify-changed-facts.ts +53 -0
  150. package/src/verify-changed-scope.ts +161 -0
  151. package/src/verify-changed.ts +174 -0
  152. package/src/verify-checks.ts +31 -19
  153. package/src/verify-drift-owner.ts +30 -0
  154. package/src/verify-e2e.ts +2 -1
  155. package/src/verify-factories.ts +86 -0
  156. package/src/verify-run.ts +13 -11
  157. package/src/verify-step.ts +13 -0
  158. package/src/verify-tests.ts +58 -6
  159. package/src/write-line.ts +21 -6
  160. package/wiki/Actions.md +2 -2
  161. package/wiki/Adapters.md +400 -0
  162. package/wiki/Admin-Dashboard.md +1 -1
  163. package/wiki/Agents.md +9 -9
  164. package/wiki/Auth.md +78 -2
  165. package/wiki/Building-Your-Own-Base.md +1 -1
  166. package/wiki/CLI-Reference.md +34 -7
  167. package/wiki/Caching-And-Invalidation.md +17 -5
  168. package/wiki/Compared.md +8 -2
  169. package/wiki/Configuration.md +14 -14
  170. package/wiki/Deployment.md +28 -1
  171. package/wiki/Entities-And-Migrations.md +47 -1
  172. package/wiki/FAQ.md +8 -2
  173. package/wiki/Feature-Flags.md +1 -1
  174. package/wiki/Home.md +3 -2
  175. package/wiki/Jobs-And-Workflows.md +107 -6
  176. package/wiki/Known-Gaps.md +4 -3
  177. package/wiki/MCP-And-AI.md +18 -4
  178. package/wiki/Mail.md +14 -5
  179. package/wiki/Migrations-And-Backfills.md +29 -4
  180. package/wiki/Money.md +2 -0
  181. package/wiki/N-Plus-One-Detection.md +24 -22
  182. package/wiki/Notify.md +28 -4
  183. package/wiki/Observability.md +121 -15
  184. package/wiki/Queries-And-Live-Queries.md +2 -2
  185. package/wiki/Realtime.md +9 -4
  186. package/wiki/Routes-And-Render-Modes.md +5 -0
  187. package/wiki/Scraping.md +57 -11
  188. package/wiki/Shapes.md +2 -2
  189. package/wiki/Stability.md +7 -5
  190. package/wiki/Storage-And-Uploads.md +56 -4
  191. package/wiki/Testing.md +65 -52
  192. package/wiki/Troubleshooting.md +1 -1
  193. package/wiki/Tutorial-01-First-App.md +1 -1
  194. package/wiki/Tutorial-04-Jobs-And-Realtime.md +1 -1
  195. package/wiki/Tutorial-05-Deploy-Free.md +1 -1
  196. package/wiki/Tutorial-06-Growing-Up.md +8 -8
  197. package/wiki/Upgrading.md +129 -4
package/src/serve-env.ts CHANGED
@@ -7,10 +7,15 @@ import {
7
7
  configureErrorReporting,
8
8
  errorReportersOf,
9
9
  installedErrorReporter,
10
+ isLocalErrorSink,
10
11
  isRole,
12
+ isSentryErrorReporter,
13
+ logger,
11
14
  ROLES,
12
15
  sentryErrorReporter,
16
+ UltimateError,
13
17
  } from '@ultimat3/core';
18
+ import { installErrorReporter } from '@ultimat3/core/adapter';
14
19
  import { PortInvalidError, RoleUnknownError } from './errors';
15
20
  import { DEFAULT_METRICS_PORT } from './metrics-endpoint';
16
21
  import type { WebBinding } from './role-start';
@@ -111,27 +116,55 @@ export const metricsPortFor = (env: Env, port: number, override?: number): numbe
111
116
  */
112
117
  export const ERROR_DSN_KEY = 'SENTRY_DSN';
113
118
 
114
- /** The transport the LAST `configureReporting` installed, so a second boot swaps it, never adds. */
119
+ /** The transport the LAST `configureReporting` chained, so a second boot swaps it, never adds. */
115
120
  let vendor: ErrorReporter | undefined;
116
121
 
117
122
  /**
118
- * Switch reporting on for this process. Unset DSN leaves whatever the app installed (or core's
119
- * no-op) in place, so a laptop and a CI run pay nothing and page nobody — and the release every
123
+ * Logged, never thrown: `SENTRY_DSN` is set and the app installed reporters that are neither its
124
+ * marked Sentry transport nor local sinks — so the boot adds none, and says how to mark them.
125
+ */
126
+ export class ErrorReporterDsnUnclaimedError extends UltimateError {
127
+ constructor(reporters: number) {
128
+ super({
129
+ code: 'X_ERROR_REPORTER_DSN_UNCLAIMED',
130
+ cause: `${ERROR_DSN_KEY} is set and the app installed ${String(reporters)} error reporter(s) marked neither as its Sentry transport nor as a local sink — one may already send to a monitor, so the boot adds no second transport and nothing is sent to that DSN`,
131
+ fix: 'errorReporter: sentryTransport(yourWrapper) // in apps/web/runtime.ts, around the reporter that wraps sentryErrorReporter — or localErrorSink(yourSink) when it keeps reports on the box, and the boot adds the DSN transport beside it',
132
+ meta: { key: ERROR_DSN_KEY, reporters },
133
+ });
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Switch reporting on for this process, and answer the release of what it installed. Unset DSN
139
+ * leaves the app's reporter — `runtime.ts`'s `errorReporter`, installed before `loadApp` — (or
140
+ * core's no-op) in place, so a laptop and a CI run pay nothing and page nobody — and the release every
120
141
  * event carries is the build id this boot already computed, never a second identity for the deploy.
121
142
  *
122
- * The transport is CHAINED beside the app's reporter, never over it: the app's modules import —
123
- * and install an `errorGroupsSink`, say — before this line runs, and replacing it here would
124
- * leave `/admin/errors` empty in exactly the deploys that set `SENTRY_DSN`.
143
+ * The rule (v31): the boot adds its `SENTRY_DSN` transport beside the app's reporters when every
144
+ * one of them is a LOCAL sink (`localErrorSink`: `errorGroupsSink`, `memoryErrorReporter`) — or
145
+ * there are none. An app whose reporters include its own Sentry transport (`sentryErrorReporter`,
146
+ * or a wrapper marked `sentryTransport`) keeps it as the only one: a boot that chained a second
147
+ * beside it sent every error twice, once unscrubbed. Any other reporter is `{ report }` and might
148
+ * be a transport, so the boot adds nothing beside it and logs `X_ERROR_REPORTER_DSN_UNCLAIMED`.
125
149
  */
126
- export function configureReporting(env: Env, buildId: string): void {
150
+ export function configureReporting(env: Env, buildId: string): () => void {
127
151
  const dsn = env[ERROR_DSN_KEY]?.trim();
128
- // A malformed DSN throws here, at boot, rather than at the first outage: a monitor that was
129
- // never connected looks exactly like an app that never failed.
130
- const next = dsn === undefined || dsn.length === 0 ? undefined : sentryErrorReporter({ dsn });
131
152
  const app = errorReportersOf(installedErrorReporter()).filter((member) => member !== vendor);
153
+ // A malformed DSN throws here, at boot, rather than at the first outage: a monitor that was
154
+ // never connected looks exactly like an app that never failed — checked even when the app's
155
+ // reporters keep the boot from adding it, so a DSN that could never have connected is never silent.
156
+ const built = dsn === undefined || dsn.length === 0 ? undefined : sentryErrorReporter({ dsn });
157
+ const owned = app.some(isSentryErrorReporter);
158
+ const unmarked = app.filter(
159
+ (member) => !isSentryErrorReporter(member) && !isLocalErrorSink(member),
160
+ );
161
+ const next = owned || unmarked.length > 0 ? undefined : built;
162
+ if (built !== undefined && !owned && unmarked.length > 0) {
163
+ const unclaimed = new ErrorReporterDsnUnclaimedError(unmarked.length);
164
+ logger.warn(unclaimed.format(), { code: unclaimed.code, ...unclaimed.meta });
165
+ }
132
166
  vendor = next;
133
- configureErrorReporting({
134
- release: buildId,
135
- reporter: chainErrorReporters(...app, ...(next === undefined ? [] : [next])),
136
- });
167
+ configureErrorReporting({ release: buildId });
168
+ // A frame ABOVE the app's: its release restores exactly the app's reporter, whatever stopped first.
169
+ return installErrorReporter(chainErrorReporters(...app, ...(next === undefined ? [] : [next])));
137
170
  }
@@ -15,5 +15,8 @@ export const PREBUILT_ISLANDS_DIR = `${PREBUILT_DIR}/islands`;
15
15
 
16
16
  export const PREBUILT_SASS_DIR = `${PREBUILT_DIR}/sass`;
17
17
 
18
+ /** The app's module registry: what a serving role imports instead of scanning (`build-registry.ts`). */
19
+ export const PREBUILT_REGISTRY_DIR = `${PREBUILT_DIR}/registry`;
20
+
18
21
  /** The Dockerfile line that writes the store — one spelling, for the template and every `fix:`. */
19
22
  export const PREBUILT_COMMAND = 'bun node_modules/@ultimat3/cli/src/bin.ts build --target prebuilt';
@@ -9,8 +9,9 @@ import { existsSync } from 'node:fs';
9
9
  // why: Bun ships no path-join primitive.
10
10
  import { join } from 'node:path';
11
11
  import type { Role } from '@ultimat3/core';
12
- import { logger, UltimateError } from '@ultimat3/core';
12
+ import { logger, tryResolveEnvironment, UltimateError } from '@ultimat3/core';
13
13
  import { sassCompilations, setSassCacheDir } from '@ultimat3/render/server';
14
+ import type { Env } from './runtime-bindings';
14
15
  import { PREBUILT_COMMAND, PREBUILT_SASS_DIR } from './serve-prebuilt-paths';
15
16
 
16
17
  /**
@@ -75,10 +76,20 @@ export function watchBootBuilds(): (islands?: BootBuilds['islands']) => BootBuil
75
76
  });
76
77
  }
77
78
 
78
- /** One `error` line when the boot built anything, and nothing when it built nothing. */
79
- export function reportBootBuilds(role: Role, builds: BootBuilds): boolean {
79
+ /**
80
+ * One line when the boot built anything, and nothing when it built nothing. `warn` only where the
81
+ * environment is DECLARED local (`ULTIMATE_ENV` or `NODE_ENV` = `development`/`test`): no image
82
+ * exists to fix, and an `error` in every test boot buries the real ones. `error` everywhere else —
83
+ * `staging` fails the way production does, and a container that declares nothing, or names no
84
+ * environment, is read as production: the direction that still pages.
85
+ */
86
+ export function reportBootBuilds(role: Role, builds: BootBuilds, env: Env): boolean {
80
87
  if (builds.islands === undefined && builds.stylesheets === 0) return false;
81
88
  const error = new ImageNotPrebuiltError({ role, ...builds });
82
- logger.error(error.format(), { code: error.code, ...error.meta });
89
+ const environment = tryResolveEnvironment({ env, fallback: 'production' });
90
+ const local = environment === 'development' || environment === 'test';
91
+ const fields = { code: error.code, ...error.meta };
92
+ if (local) logger.warn(error.format(), fields);
93
+ else logger.error(error.format(), fields);
83
94
  return true;
84
95
  }
package/src/serve.ts CHANGED
@@ -12,7 +12,7 @@ import { type BootedHold, holdWhileBooting } from './hold';
12
12
  import { rolePorts, startMetricsEndpoint } from './metrics-endpoint';
13
13
  import { readMigrations } from './migrations';
14
14
  import { resolveServices } from './runtime-bindings';
15
- import { startQueue } from './runtime-queue';
15
+ import { startQueueWithBoot } from './runtime-boot-ports';
16
16
  import { containerBinding, metricsPortFor, portFromEnv, roleFromEnv } from './serve-env';
17
17
  import type { MigratedApp, ServedApp, ServeOptions, StartedApp } from './serve-types';
18
18
 
@@ -51,7 +51,7 @@ export async function runMigrations(options: ServeOptions): Promise<MigratedApp>
51
51
  // `'apply'`, never the stamp-first default: this IS the step that applies, and an operator
52
52
  // re-running it is how a dropped framework table comes back.
53
53
  const services = resolveServices(options.root, options.env);
54
- const queue = await startQueue(services, options.runtime, options.env, 'apply');
54
+ const queue = await startQueueWithBoot(services, options.runtime, options.env, 'apply');
55
55
  try {
56
56
  const migrations = await readMigrations(options.root);
57
57
  // PGlite with `database.rowSecurity`: the app's migrations run as `x_migrator` for their scope.
@@ -6,9 +6,10 @@
6
6
  // why: Bun exposes no path-join primitive, and every card path is relative to the export root.
7
7
  import { join } from 'node:path';
8
8
  import { probeImage, transformImageBytes } from '@ultimat3/core';
9
+ import { systemClock } from '@ultimat3/core/adapter';
9
10
  import type { OpenGraphImage } from '@ultimat3/seo';
10
11
  import type { ShotDriver } from './browser-launcher-port';
11
- import { DEFAULT_PAGE_TIMEOUT_MS, systemShotClock } from './cdp-shot-clock';
12
+ import { DEFAULT_PAGE_TIMEOUT_MS } from './cdp-shot-clock';
12
13
  import { CardBrowserMissingError, CardRouteUnknownError } from './static-capture-errors';
13
14
  import { serveExport } from './static-cards-serve';
14
15
 
@@ -72,7 +73,7 @@ export function staticCards(): StaticCards {
72
73
  const session = await driver.open({
73
74
  name: 'x build cards',
74
75
  rules: { allowHosts: ['127.0.0.1'] },
75
- clock: systemShotClock,
76
+ clock: systemClock,
76
77
  timeoutMs: DEFAULT_PAGE_TIMEOUT_MS,
77
78
  viewport: CARD_SIZE,
78
79
  });
@@ -9,9 +9,9 @@
9
9
  import { rm } from 'node:fs/promises';
10
10
  import { join } from 'node:path';
11
11
  import type { RenderMode } from '@ultimat3/core';
12
- import { RENDER_MODES } from '@ultimat3/core';
12
+ import { RENDER_MODES, SURFACES } from '@ultimat3/core';
13
13
  import type { Surface } from '@ultimat3/render';
14
- import { SURFACE_SPECS, SURFACES, surfaceAllows } from '@ultimat3/render';
14
+ import { SURFACE_SPECS, surfaceAllows } from '@ultimat3/render';
15
15
  import type { JsonValue } from './output';
16
16
  import { SERVICE_WORKER_PATH } from './sw-artifacts';
17
17
 
@@ -12,8 +12,8 @@
12
12
  // Bun ships no path API; `join` is the filesystem side of writing a chunk into a static export.
13
13
  // why: Bun exposes no path API — nothing native joins a directory to a URL-shaped path.
14
14
  import { join } from 'node:path';
15
+ import { SURFACES } from '@ultimat3/core';
15
16
  import type { Surface } from '@ultimat3/render';
16
- import { SURFACES } from '@ultimat3/render';
17
17
  import { contentHash, stylesFor, stylesheetsRevision } from '@ultimat3/render/server';
18
18
 
19
19
  /**
@@ -9,27 +9,19 @@ import { finiteCount, systemClock } from '@ultimat3/core';
9
9
  import type { HttpConfig } from '@ultimat3/http';
10
10
  import {
11
11
  configuredAuthenticator,
12
+ configuredCredentialTtlMs,
12
13
  defineHttpConfig,
14
+ MAX_CREDENTIAL_TTL_MS,
13
15
  requestContext,
14
16
  UltimateRequest,
15
17
  } from '@ultimat3/http';
16
18
  import type { SyncAuthenticator, SyncGrant } from '@ultimat3/realtime/server';
17
19
 
18
- /**
19
- * How long one grant stands before the node re-decides it.
20
- *
21
- * A grant with no expiry never appears in `GrantBook.expired()`, so `sweepGrants` — the only path
22
- * to `hub.onActorChange` and `registry.reauthorize` — never fired for a socket this adapter opened.
23
- * `logout`, `revokeSession`, `disableUser` and `updatePrivileges` closed the HTTP session and never
24
- * the websocket, and the client's 15s heartbeat beats the 120s idle sweep, so the socket stayed up
25
- * with the revoked actor's authority for as long as the tab was open.
26
- *
27
- * Five minutes, against `DEFAULT_REAUTH_INTERVAL_MS` (30s): the window a revoked actor keeps its
28
- * socket is this plus one sweep, and the cost is one resolver call per socket per window — 167/s
29
- * on the 50,000-socket node this repo has measured, against 1,667/s at a 30s TTL. A deployment
30
- * whose credential has a shorter real lifetime passes `runtime.syncAuthenticate` and states it.
31
- */
32
- export const SYNC_GRANT_TTL_MS = 5 * 60_000;
20
+ // How long one grant stands before the node re-decides it is `@ultimat3/http`'s
21
+ // `MAX_CREDENTIAL_TTL_MS` (five minutes) — one constant, the ceiling an app's `credentialTtlMs` is
22
+ // held to. A grant with no expiry never reaches `sweepGrants`, so `logout` closed the HTTP session
23
+ // and never the socket; five minutes is one resolver call per socket per window (167/s at 50,000
24
+ // sockets, against 1,667/s at 30 s).
33
25
 
34
26
  /**
35
27
  * The credential this adapter retains per socket, and nothing else.
@@ -41,7 +33,7 @@ export const SYNC_GRANT_TTL_MS = 5 * 60_000;
41
33
  * Dropping the rest can only make a refresh MORE restrictive, never more permissive: an app that
42
34
  * resolves identity from some other header sees its refresh answer `null`, which closes the socket
43
35
  * with `1008` and the client re-dials carrying that header again. One reconnect per window, not an
44
- * escalation — and `runtime.syncAuthenticate` is the declared seam for stating something else.
36
+ * escalation.
45
37
  */
46
38
  const CREDENTIAL_HEADERS = ['cookie', 'authorization'] as const;
47
39
 
@@ -77,7 +69,7 @@ function credentialOf(request: Request): Credential {
77
69
  export interface SyncAuthenticatorOptions {
78
70
  /** The clock a grant's window is measured on. Injected so a re-auth is provable without sleeping. */
79
71
  readonly clock?: Clock;
80
- /** Overrides `SYNC_GRANT_TTL_MS`. A test names its own window; nothing in the boot passes one. */
72
+ /** Overrides `MAX_CREDENTIAL_TTL_MS`. A test names its own window; nothing in the boot passes one. */
81
73
  readonly ttlMs?: number;
82
74
  }
83
75
 
@@ -108,7 +100,14 @@ export function syncAuthenticator(
108
100
  // long as the tab is open. That is the hole this whole file was written to close, and a `??`
109
101
  // does not close it: `NaN` is not nullish. At least 1ms — a window that has already shut when
110
102
  // the grant is minted is not a window.
111
- const ttlMs = finiteCount('syncAuthenticator', 'ttlMs', options.ttlMs ?? SYNC_GRANT_TTL_MS, 1);
103
+ const ttlMs = finiteCount(
104
+ 'syncAuthenticator',
105
+ 'ttlMs',
106
+ // The app's own credential lifetime, declared beside its resolver (`configureAuthenticator(fn,
107
+ // { credentialTtlMs })`) — what `runtime.syncAuthenticate` was the second way to state.
108
+ options.ttlMs ?? configuredCredentialTtlMs() ?? MAX_CREDENTIAL_TTL_MS,
109
+ 1,
110
+ );
112
111
 
113
112
  const resolve = async (credential: Credential): Promise<SyncGrant | null> => {
114
113
  const request = new Request(credential.url, {
@@ -60,8 +60,8 @@ const input = { id, orgId${isMutator ? ", title: 'a title'" : ''} };
60
60
  : ''
61
61
  }
62
62
  // Named here because every projection needs a stable name and this file does not boot the app.
63
- // At boot \`registerActions(await import('./actions'))\` stamps the same name onto the same
64
- // object, so each projection of it works there with nothing to remember.
63
+ // At boot \`defineApi\` stamps the same name onto the same object, so each projection of it
64
+ // works there with nothing to remember.
65
65
  const target = ${name.camel}.named('${name.camel}');
66
66
  ${
67
67
  outsider
@@ -205,8 +205,8 @@ const id = '${ID}';
205
205
  ${shape.org ? `const orgId = '${ORG}';\n` : ''}const input = { id${shape.org ? ', orgId' : ''}${shape.isMutator ? ", title: 'a title'" : ''} };
206
206
  ${shape.isMutator ? `\n// The client store's table: the entity's own, so the twin and the server row share one key.\nconst TABLE = '${feature.table}';\n` : ''}
207
207
  // Named here because every projection needs a stable name and this file does not boot the app.
208
- // At boot \`registerActions(await import('./actions'))\` stamps the same name onto the same
209
- // object, so each projection of it works there with nothing to remember.
208
+ // At boot \`defineApi\` stamps the same name onto the same object, so each projection of it
209
+ // works there with nothing to remember.
210
210
  const target = ${name.camel}.named('${name.camel}');
211
211
  ${
212
212
  known
@@ -108,16 +108,13 @@ const backfillTest = (
108
108
  ): string => `// ${name.camel}'s durable identity: one live run per name, retried under the same key. The work
109
109
  // itself — the pass over real rows and the projection it applies — is the unit suite's, next door.
110
110
 
111
- import { memoryJobDriver, resetJobDriver, setJobDriver } from '@ultimat3/jobs';
112
- import { afterAll, beforeAll, expect, jobTest } from '@ultimat3/testing';
111
+ import { memoryJobDriver } from '@ultimat3/jobs';
112
+ import { beforeAll, expect, jobTest, swapAdapter } from '@ultimat3/testing';
113
113
  import { ${name.camel} } from './${name.kebab}';
114
114
 
115
- // The driver is process-global, so it is installed and released around this file rather than
116
- // left behind for whichever test happens to run next.
117
- beforeAll(() => {
118
- setJobDriver(memoryJobDriver());
119
- });
120
- afterAll(resetJobDriver);
115
+ // The queue is a process-global adapter port, so it is swapped for this file and put back when the
116
+ // file ends, never left behind for whichever test happens to run next.
117
+ beforeAll(() => swapAdapter('jobs', memoryJobDriver()));
121
118
 
122
119
  // The durable name this sweep runs under, spelled once — so the assertion below carries the
123
120
  // backfill's own name and still fits the formatter width the app's \`lint\` step enforces.
@@ -66,6 +66,9 @@ export const ${name.camel} = entity('${table}', {
66
66
  invariant('${snake}_price_non_negative', c.price.minor.atLeast(0)),
67
67
  ],
68
68
  indexes: [{ on: ['orgId', 'createdAt'] }],
69
+ // PARTITIONED? \`partitionBy: { column: 'createdAt', interval: 'month' }\` needs its maintenance
70
+ // job too, or no partition is created ahead: export \`partitions()\` from '@ultimat3/jobs' in a
71
+ // module listed under \`jobs\` in apps/web/api/index.ts, and its \`.schedule\` under \`tasks\`.
69
72
  });
70
73
 
71
74
  export type ${name.pascal} = typeof ${name.camel}.$row;
@@ -12,6 +12,7 @@
12
12
  import { REQUIRED_BUN } from '../../app-root';
13
13
  import type { GeneratedFile, NameSet } from '../naming';
14
14
  import { TEST_COMPOSE_PATH, TEST_ENV_PATH } from '../scaffold-test-services';
15
+ import { DEPENDABOT_PATH, dependabot } from './dependabot.yml';
15
16
  import { IMAGE_WORKFLOW_PATH, imageWorkflow } from './image.yml';
16
17
  import { RUNS_ON } from './runner';
17
18
 
@@ -96,10 +97,11 @@ jobs:
96
97
  - run: bun run verify
97
98
  `;
98
99
 
99
- /** The CI a new app is born with, in the order a reader meets it: the gate, then the image. */
100
+ /** The CI a new app is born with, in reading order: the gate, the image, the dependency updates. */
100
101
  export function githubFiles(app: NameSet): readonly GeneratedFile[] {
101
102
  return [
102
103
  { path: CI_WORKFLOW_PATH, contents: ci(app) },
103
104
  { path: IMAGE_WORKFLOW_PATH, contents: imageWorkflow(CI_WORKFLOW_NAME) },
105
+ { path: DEPENDABOT_PATH, contents: dependabot() },
104
106
  ];
105
107
  }
@@ -0,0 +1,73 @@
1
+ // The Dependabot config `x new` writes. Every `@ultimat3/*` package is released in lockstep, so a
2
+ // PR that bumps one of them alone is an install no release ever shipped: they move as ONE group,
3
+ // majors included. The base images the scaffold pins under `docker/` are watched beside them.
4
+
5
+ /** Where GitHub reads it. */
6
+ export const DEPENDABOT_PATH = '.github/dependabot.yml';
7
+
8
+ /** The directory `x new` writes its Dockerfile and compose files into. */
9
+ const DOCKER_DIR = '/docker';
10
+
11
+ export const dependabot = (): string => `version: 2
12
+
13
+ # Weekly, grouped, and small — a dependency PR nobody can review in one sitting gets merged unread.
14
+ updates:
15
+ # \`bun\`, never \`npm\`: the tree is locked by \`bun.lock\` alone, which the npm ecosystem refuses.
16
+ - package-ecosystem: bun
17
+ directory: /
18
+ schedule:
19
+ interval: weekly
20
+ # A release sits 14 days before it is proposed: most yanked versions are yanked by then.
21
+ cooldown:
22
+ default-days: 14
23
+ open-pull-requests-limit: 5
24
+ labels: [dependencies]
25
+ groups:
26
+ # Released in lockstep, so upgraded in lockstep: one PR, every update type. A bump of one
27
+ # package alone is a combination no release shipped. A major is \`x upgrade\`'s job — the PR
28
+ # says it is due; run \`bunx x upgrade\` on its branch.
29
+ ultimate:
30
+ patterns: ['@ultimat3/*', 'create-ultimate']
31
+ dependencies:
32
+ patterns: ['*']
33
+ exclude-patterns: ['@ultimat3/*', 'create-ultimate']
34
+ update-types: [minor, patch]
35
+ ignore:
36
+ # Bun is pinned by \`engines\` and the workflow's \`bun-version\`, not by a package bump.
37
+ - dependency-name: bun
38
+
39
+ - package-ecosystem: github-actions
40
+ directory: /
41
+ schedule:
42
+ interval: weekly
43
+ cooldown:
44
+ default-days: 14
45
+ labels: [dependencies, ci]
46
+ groups:
47
+ actions:
48
+ patterns: ['*']
49
+
50
+ # The base images the Dockerfile and the compose files pin.
51
+ - package-ecosystem: docker
52
+ directories: ['${DOCKER_DIR}']
53
+ schedule:
54
+ interval: weekly
55
+ cooldown:
56
+ default-days: 14
57
+ labels: [dependencies, docker]
58
+ ignore:
59
+ # A Postgres MAJOR is a planned migration (a new data directory), never a weekly bump.
60
+ - dependency-name: postgres
61
+ update-types: ['version-update:semver-major']
62
+
63
+ - package-ecosystem: docker-compose
64
+ directories: ['${DOCKER_DIR}']
65
+ schedule:
66
+ interval: weekly
67
+ cooldown:
68
+ default-days: 14
69
+ labels: [dependencies, docker]
70
+ ignore:
71
+ - dependency-name: postgres
72
+ update-types: ['version-update:semver-major']
73
+ `;
@@ -129,8 +129,8 @@ const jobTest = (
129
129
  name: NameSet,
130
130
  ): string => `// ${name.camel} against a real driver: enqueue, drain, assert. Retries and the dead-letter path
131
131
  // are the framework's, so what this pins is that THIS job's steps run and are idempotent.
132
- import { memoryJobDriver, resetJobDriver, setJobDriver } from '@ultimat3/jobs';
133
- import { afterAll, beforeAll, expect, jobTest } from '@ultimat3/testing';
132
+ import { memoryJobDriver } from '@ultimat3/jobs';
133
+ import { beforeAll, expect, jobTest, swapAdapter } from '@ultimat3/testing';
134
134
  import { ${name.camel} } from './${name.kebab}';
135
135
 
136
136
  const id = '00000000-0000-4000-8000-000000000001';
@@ -140,12 +140,9 @@ const input = { id, orgId };
140
140
  // the job's own name and still fits the formatter width the app's \`lint\` step enforces.
141
141
  const expectedKey = \`${name.kebab}:\${id}\`;
142
142
 
143
- // The driver is process-global, so it is installed and released around this file rather than
144
- // left behind for whichever test happens to run next.
145
- beforeAll(() => {
146
- setJobDriver(memoryJobDriver());
147
- });
148
- afterAll(resetJobDriver);
143
+ // The queue is a process-global adapter port, so it is swapped for this file and put back when the
144
+ // file ends, never left behind for whichever test happens to run next.
145
+ beforeAll(() => swapAdapter('jobs', memoryJobDriver()));
149
146
 
150
147
  jobTest('${name.camel} declares a key and a retry policy', () => {
151
148
  expect(${name.camel}.kind).toBe('job');
@@ -186,8 +183,8 @@ const neutralJobTest = (
186
183
  name: NameSet,
187
184
  ): string => `// ${name.camel} against a real driver: enqueue, drain, assert. Retries and the dead-letter path
188
185
  // are the framework's, so what this pins is that THIS job's steps run and are idempotent.
189
- import { memoryJobDriver, resetJobDriver, setJobDriver } from '@ultimat3/jobs';
190
- import { afterAll, beforeAll, expect, jobTest } from '@ultimat3/testing';
186
+ import { memoryJobDriver } from '@ultimat3/jobs';
187
+ import { beforeAll, expect, jobTest, swapAdapter } from '@ultimat3/testing';
191
188
  import { ${name.camel} } from './${name.kebab}';
192
189
 
193
190
  const id = '00000000-0000-4000-8000-000000000001';
@@ -196,12 +193,9 @@ const input = { id };
196
193
  // the job's own name and still fits the formatter width the app's \`lint\` step enforces.
197
194
  const expectedKey = \`${name.kebab}:\${id}\`;
198
195
 
199
- // The driver is process-global, so it is installed and released around this file rather than
200
- // left behind for whichever test happens to run next.
201
- beforeAll(() => {
202
- setJobDriver(memoryJobDriver());
203
- });
204
- afterAll(resetJobDriver);
196
+ // The queue is a process-global adapter port, so it is swapped for this file and put back when the
197
+ // file ends, never left behind for whichever test happens to run next.
198
+ beforeAll(() => swapAdapter('jobs', memoryJobDriver()));
205
199
 
206
200
  jobTest('${name.camel} declares a key and a retry policy', () => {
207
201
  expect(${name.camel}.kind).toBe('job');
@@ -243,15 +237,12 @@ const taskTest = (
243
237
  jobName: NameSet,
244
238
  ): string => `// ${name.camel}: the schedule it declares, the timezone it declares it in, and the job it
245
239
  // enqueues. A cron with no explicit IANA zone fires at a different hour twice a year.
246
- import { memoryJobDriver, resetJobDriver, setJobDriver } from '@ultimat3/jobs';
247
- import { afterAll, beforeAll, expect, jobTest } from '@ultimat3/testing';
240
+ import { memoryJobDriver } from '@ultimat3/jobs';
241
+ import { beforeAll, expect, jobTest, swapAdapter } from '@ultimat3/testing';
248
242
  import { ${jobName.camel} } from '../jobs/${jobName.kebab}';
249
243
  import { ${name.camel} } from './${name.kebab}';
250
244
 
251
- beforeAll(() => {
252
- setJobDriver(memoryJobDriver());
253
- });
254
- afterAll(resetJobDriver);
245
+ beforeAll(() => swapAdapter('jobs', memoryJobDriver()));
255
246
 
256
247
  jobTest('${name.camel} declares a cron with an explicit time zone', () => {
257
248
  expect(${name.camel}.kind).toBe('task');
@@ -55,13 +55,32 @@ export interface GeneratedFoundationFile {
55
55
  readonly merge: 'if-absent';
56
56
  }
57
57
 
58
+ /**
59
+ * A file the base scaffold writes and a later generator owns a richer version of — `x g sign-in`'s
60
+ * `apps/web/runtime.ts`. Written when absent, REPLACED when the copy on disk is still byte-for-byte
61
+ * `pristine` (the scaffold's own, untouched), and a conflict once the author has edited it: their
62
+ * ports are theirs, and only `--force` overwrites them.
63
+ */
64
+ export interface GeneratedReplacingFile {
65
+ /** POSIX path relative to the app root. */
66
+ readonly path: string;
67
+ readonly contents: string;
68
+ readonly merge: 'replaces-pristine';
69
+ /** The exact bytes this file may replace without asking. */
70
+ readonly pristine: string;
71
+ }
72
+
58
73
  /**
59
74
  * Split on `merge` rather than widening one shape's `contents` in place, so the split is
60
75
  * load-bearing, not cosmetic: a `merge: 'json'` file's `contents` stays a plain `string` at the
61
76
  * type level, which is what stops a byte-carrying file from ever reaching
62
77
  * `cmd-generate.ts`'s JSON parser — the compiler refuses the call before the code can run.
63
78
  */
64
- export type GeneratedFile = GeneratedJsonFile | GeneratedSourceFile | GeneratedFoundationFile;
79
+ export type GeneratedFile =
80
+ | GeneratedJsonFile
81
+ | GeneratedSourceFile
82
+ | GeneratedFoundationFile
83
+ | GeneratedReplacingFile;
65
84
 
66
85
  const words = (input: string): readonly string[] =>
67
86
  input
@@ -3,4 +3,4 @@
3
3
  # It is grouped in .github/dependabot.yml with docker/, so one PR moves every copy together.
4
4
  services:
5
5
  s3:
6
- image: versity/versitygw:v1.9.0@sha256:eb7f786fcd91e72194e48fcf1ac16302d686bf8e3a71434bdbc067a6efd3fdc7
6
+ image: versity/versitygw:v1.10.0@sha256:89cad13cc981986ee284cbafea4613f9533ce6fd5f37a2c96c4c4fb8adb3a316
@@ -75,6 +75,7 @@ const queryTest = (name: NameSet, feature: NameSet, shape: ReadShape): string =>
75
75
  const subscribes = live && shape.storesRow;
76
76
  const imports = subscribes
77
77
  ? [
78
+ "import { defineApi } from '@ultimat3/action';",
78
79
  "import { ctxOf, frozenClock, runWithContext } from '@ultimat3/core';",
79
80
  `import { afterEach, expect, ${wrapper} } from '@ultimat3/testing';`,
80
81
  `import { driver } from '${shape.dbModule}';`,
@@ -90,15 +91,12 @@ const queryTest = (name: NameSet, feature: NameSet, shape: ReadShape): string =>
90
91
  ${sortedImports([
91
92
  ...imports,
92
93
  "import { testActor } from '@ultimat3/policy';",
93
- subscribes
94
- ? "import { registerQuery, sourceFor } from '@ultimat3/query';"
95
- : "import { sourceFor } from '@ultimat3/query';",
94
+ "import { sourceFor } from '@ultimat3/query';",
96
95
  ])}${repo}
97
96
  import { ${name.camel} } from './${name.kebab}';
98
97
  ${live && !shape.storesRow ? '' : ORG_LINE}
99
98
  // Named here because every projection needs a stable name and this file does not boot the app.
100
- // At boot \`registerQueries(await import('./${live ? 'live' : 'queries'}'))\` stamps the same name
101
- // onto the same object.
99
+ // At boot \`defineApi\` stamps the same name onto the same object.
102
100
  const target = ${name.camel}.named('${name.camel}');
103
101
 
104
102
  // Holds the grant and no org — so a denial here is the predicate deciding, not the grant.
@@ -174,9 +172,10 @@ ${subscribes ? subscribeTest(name, feature) : ''}`;
174
172
  * Two orgs, a snapshot and a write: the window a subscriber is served from is its own org's.
175
173
  */
176
174
  const subscribeTest = (name: NameSet, feature: NameSet): string => `
177
- // The module's own export under its own name — what \`defineApi\` does at boot — so a subscribe
178
- // frame naming it reaches this declaration.
179
- const live = registerQuery('${name.camel}', ${name.camel});
175
+ // The module's own export under its own name, through \`defineApi\` as the boot hands it over, so
176
+ // a subscribe frame naming it reaches this declaration.
177
+ const api = defineApi({ queries: { ${name.camel} } });
178
+ const live = api.queries.${name.camel};
180
179
 
181
180
  type Row = ${feature.pascal};
182
181
 
@@ -75,8 +75,8 @@ export const routeParams = (path: string): readonly string[] =>
75
75
  * only this function knows where `x g resource`'s page went — a second copy of the formula in the
76
76
  * resource generator is how the specifier it prints stops matching the file it writes.
77
77
  */
78
- export const routeDir = (surface: Surface, path: string): string =>
79
- `apps/web/${surface}/${segmentsOf(path).join('/')}`;
78
+ export const routeDir = (surface: Surface, path: string, app = 'web'): string =>
79
+ `apps/${app}/${surface}/${segmentsOf(path).join('/')}`;
80
80
 
81
81
  /**
82
82
  * How the generated page reaches a string, and it is the whole reason this generator takes an app
@@ -260,11 +260,13 @@ export interface RouteOptions {
260
260
  * generated page fall back to importing `t` from `@ultimat3/i18n`.
261
261
  */
262
262
  readonly catalogModule?: string;
263
+ /** The app workspace the page lands in, `apps/<app>/` — `x g route --app`. Default `web`. */
264
+ readonly app?: string;
263
265
  }
264
266
 
265
267
  export function routeFiles(rawPath: string, options: RouteOptions): readonly GeneratedFile[] {
266
268
  const path = rawPath.replace(/^\/+/, '');
267
- const dir = routeDir(options.surface, path);
269
+ const dir = routeDir(options.surface, path, options.app);
268
270
  const locales = resolveLocales(options.locales);
269
271
  return [
270
272
  { path: `${dir}/page.tsx`, contents: pageSource(options.surface, path, options.catalogModule) },
@@ -33,7 +33,7 @@ import { contractTest, expect } from '@ultimat3/testing';
33
33
  import { health } from './health';
34
34
 
35
35
  // Named here because every projection needs a stable name and this file does not boot the app.
36
- // At boot \`registerActions\` stamps the same name onto the same object.
36
+ // At boot \`defineApi\` stamps the same name onto the same object.
37
37
  const target = health.named('health');
38
38
 
39
39
  contractTest('health is an action exposed over MCP', () => {
@@ -209,7 +209,7 @@ const devActorTest =
209
209
  (): string => `// The development viewer is safe because of what it refuses: a role nobody declared is never the
210
210
  // default viewer, and the actor it mints holds what its role holds and nothing else. WHEN it is
211
211
  // asked is \`authenticator.ts\`'s, and \`authenticator.test.ts\` holds that half.
212
- import { setLogSink } from '@ultimat3/core';
212
+ import { installLogSink } from '@ultimat3/core';
213
213
  import { actorHas } from '@ultimat3/policy';
214
214
  import { expect, unitTest } from '@ultimat3/testing';
215
215
  import { roles } from '../../shared/roles';
@@ -267,12 +267,14 @@ unitTest('it answers a request from its cookie header, and no other', () => {
267
267
 
268
268
  unitTest('an undeclared role is answered as ANONYMOUS, and the log names what it read', () => {
269
269
  const lines: Record<string, unknown>[] = [];
270
- const previous = setLogSink((line) => lines.push(JSON.parse(line) as Record<string, unknown>));
270
+ const releaseLogSink = installLogSink((line) =>
271
+ lines.push(JSON.parse(line) as Record<string, unknown>),
272
+ );
271
273
  try {
272
274
  const cookie = \`\${DEV_ROLE_COOKIE}=auditor\`;
273
275
  expect(devAuthenticate({ header: () => cookie })).toBeNull();
274
276
  } finally {
275
- setLogSink(previous);
277
+ releaseLogSink();
276
278
  }
277
279
  expect(lines).toHaveLength(1);
278
280
  expect(lines[0]?.level).toBe('warn');