@ultimat3/cli 31.46.0 → 31.47.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 (100) hide show
  1. package/CLAUDE.md +1 -1
  2. package/README.md +1 -1
  3. package/package.json +29 -29
  4. package/src/affected.ts +3 -2
  5. package/src/app-config-load.ts +8 -5
  6. package/src/app-mcp.ts +2 -5
  7. package/src/app-runtime.ts +4 -4
  8. package/src/cmd-cache.ts +8 -4
  9. package/src/cmd-deploy-compose.ts +11 -12
  10. package/src/cmd-deploy-helm.ts +5 -8
  11. package/src/cmd-exercise-spec.ts +2 -2
  12. package/src/cmd-exercise.ts +7 -19
  13. package/src/cmd-new.ts +4 -3
  14. package/src/cmd-planned.ts +11 -76
  15. package/src/cmd-shot-matrix.ts +3 -2
  16. package/src/cmd-token.ts +11 -3
  17. package/src/codemods/ci-weekly-schedule.ts +61 -0
  18. package/src/codemods/index.ts +2 -0
  19. package/src/codemods/vendored-guards.ts +3 -5
  20. package/src/codemods/verify-floor-skips.ts +4 -6
  21. package/src/codemods/verify-floor-steps.ts +4 -3
  22. package/src/db-seed.ts +3 -2
  23. package/src/dispatch.ts +2 -11
  24. package/src/duplicate-packages.ts +4 -4
  25. package/src/exercise-findings.ts +4 -3
  26. package/src/exercise-floor.ts +1 -1
  27. package/src/exercise-seed.ts +34 -0
  28. package/src/fix-command.ts +2 -3
  29. package/src/flag-reads.ts +6 -3
  30. package/src/generate-files.ts +10 -6
  31. package/src/gitignore.ts +4 -3
  32. package/src/guards-built-in.ts +3 -6
  33. package/src/guards.ts +5 -8
  34. package/src/island-bundle.ts +3 -2
  35. package/src/island-sources.ts +4 -3
  36. package/src/island-states-load.ts +4 -3
  37. package/src/island-store.ts +3 -2
  38. package/src/json-merge.ts +8 -6
  39. package/src/lint-findings.ts +4 -7
  40. package/src/mcp-errors.ts +1 -1
  41. package/src/messages.ts +1 -0
  42. package/src/prerender-out.ts +4 -3
  43. package/src/publish-closure.ts +4 -6
  44. package/src/pwa-manifest-locales.ts +5 -8
  45. package/src/registry.ts +0 -7
  46. package/src/root-env.ts +3 -2
  47. package/src/runtime-admin.ts +2 -4
  48. package/src/runtime-keys.ts +5 -2
  49. package/src/static-report.ts +5 -8
  50. package/src/templates/github/ci-schedule.ts +86 -0
  51. package/src/templates/github/ci.yml.ts +6 -8
  52. package/src/templates/github/dependabot.yml.ts +6 -1
  53. package/src/templates/scaffold-docs.ts +1 -0
  54. package/src/templates/shapes/overlay.ts +4 -7
  55. package/src/upgrade-guards-baseline.ts +3 -5
  56. package/src/verify-merge-skips.ts +2 -4
  57. package/src/verify-merge.ts +13 -8
  58. package/src/verify-part-step.ts +5 -7
  59. package/src/worker-bundle.ts +4 -2
  60. package/wiki/Actions.md +69 -5
  61. package/wiki/Agents.md +13 -0
  62. package/wiki/Auth.md +4 -0
  63. package/wiki/Batching-And-Preloading.md +77 -3
  64. package/wiki/CLI-Reference.md +18 -5
  65. package/wiki/Caching-And-Invalidation.md +76 -23
  66. package/wiki/Client-Navigation.md +2 -0
  67. package/wiki/Configuration.md +17 -4
  68. package/wiki/Entities-And-Migrations.md +168 -6
  69. package/wiki/FAQ.md +1 -1
  70. package/wiki/Feature-Flags.md +3 -0
  71. package/wiki/Getting-Started.md +27 -1
  72. package/wiki/Jobs-And-Workflows.md +70 -13
  73. package/wiki/Known-Gaps.md +58 -49
  74. package/wiki/MCP-And-AI.md +43 -3
  75. package/wiki/Mail.md +6 -0
  76. package/wiki/Migrations-And-Backfills.md +13 -0
  77. package/wiki/Money.md +20 -1
  78. package/wiki/N-Plus-One-Detection.md +31 -1
  79. package/wiki/Notify.md +13 -2
  80. package/wiki/PWA-And-Offline.md +34 -4
  81. package/wiki/Policies-And-Authz.md +27 -5
  82. package/wiki/Queries-And-Live-Queries.md +41 -4
  83. package/wiki/Realtime.md +22 -0
  84. package/wiki/Resource-Management.md +6 -1
  85. package/wiki/Routes-And-Render-Modes.md +54 -6
  86. package/wiki/SEO.md +24 -2
  87. package/wiki/Scheduled-Tasks.md +29 -11
  88. package/wiki/Scraping.md +33 -2
  89. package/wiki/Static-Assets.md +1 -0
  90. package/wiki/Storage-And-Uploads.md +8 -1
  91. package/wiki/Testing.md +120 -13
  92. package/wiki/The-Eight-Primitives.md +125 -6
  93. package/wiki/Timezones-And-Dates.md +13 -5
  94. package/wiki/Troubleshooting.md +1 -1
  95. package/wiki/Tutorial-02-First-Feature.md +6 -0
  96. package/wiki/Tutorial-03-Auth-And-Admin.md +8 -0
  97. package/wiki/Tutorial-04-Jobs-And-Realtime.md +40 -2
  98. package/wiki/Tutorial-06-Growing-Up.md +1 -2
  99. package/wiki/UI-Components.md +14 -5
  100. package/wiki/Upgrading.md +41 -4
@@ -172,6 +172,8 @@ Each worker then claims its list and nothing else. Every entry must be a queue t
172
172
 
173
173
  ```ts
174
174
  // app.config.ts
175
+ import { defineConfig } from '@ultimat3/core';
176
+
175
177
  export const config = defineConfig({ name: 'shop', realtime: { maxSubscriptionsPerActor: 200 } });
176
178
  ```
177
179
 
@@ -558,6 +560,8 @@ export const config = defineConfig({
558
560
  **Not an `app.config.ts` block.** There is no `storage` key on `AppConfigInput`. Storage is `defineStorage()`, called from `app.config.ts`, and it declares **named disks** (Laravel's model) rather than a driver and a bucket — so `disk('uploads').put(…)` never changes when `local` becomes `s3`:
559
561
 
560
562
  ```ts
563
+ import { defineStorage, localDriver } from '@ultimat3/storage';
564
+
561
565
  defineStorage({ disks: { uploads: localDriver({ root: '.storage/uploads' }) } });
562
566
  ```
563
567
 
@@ -663,6 +667,8 @@ How a SIGTERM'd process leaves: `DrainConfig` in [`packages/core/src/config-heal
663
667
  | `drain.workerRetireMs` | whole ms, `0`–`86400000` | `3600000` | how long a retiring worker may finish what it holds on a Kubernetes rollout or scale-down, aborting nothing; `0` turns it off. An idle worker exits at once. A job's `timeout` over it reds `x verify` (`X_JOB_OUTLASTS_DRAIN`) → [Deployment](Deployment#retiring-a-worker-before-sigterm) |
664
668
 
665
669
  ```ts
670
+ import { defineConfig } from '@ultimat3/core';
671
+
666
672
  export const config = defineConfig({
667
673
  name: 'postly',
668
674
  // A report job runs up to 8 minutes; a deploy lets it finish.
@@ -789,6 +795,8 @@ Four names, one env var, and a spelling the framework does not use is a refusal
789
795
  ```ts
790
796
  import { isLocal, isProduction, resolveEnvironment, tryResolveEnvironment } from '@ultimat3/core';
791
797
 
798
+ declare const someRecord: Readonly<Record<string, string | undefined>>;
799
+
792
800
  resolveEnvironment(); // 'development' | 'test' | 'staging' | 'production'
793
801
  resolveEnvironment({ fallback: 'production' });
794
802
  resolveEnvironment({ env: someRecord });
@@ -816,7 +824,9 @@ x env example # writes .env.example from the app's envSchema
816
824
  ```
817
825
 
818
826
  ```ts
819
- import { renderEnvExample, ENV_EXAMPLE_PATH } from '@ultimat3/core';
827
+ import { type EnvSchema, renderEnvExample, ENV_EXAMPLE_PATH } from '@ultimat3/core';
828
+
829
+ declare const schema: EnvSchema;
820
830
 
821
831
  await Bun.write(ENV_EXAMPLE_PATH, renderEnvExample(schema)); // '.env.example'
822
832
  ```
@@ -842,14 +852,17 @@ Which files are read at boot: `.env` and `.env.<mode>` always, plus `.env.local`
842
852
  A value that redacts **by value**, so it stays redacted under a key nobody thought to add to a deny-list.
843
853
 
844
854
  ```ts
845
- import { secret, revealSecret, isSecret } from '@ultimat3/core';
855
+ import { isSecret, logger, revealSecret, secret } from '@ultimat3/core';
856
+
857
+ declare const apiToken: string;
846
858
 
847
- const token = secret(process.env.API_TOKEN, 'API_TOKEN');
859
+ const token = secret(apiToken, 'API_TOKEN');
848
860
 
849
861
  `${token}`; // '[redacted]'
850
862
  JSON.stringify({ token }); // '{"token":"[redacted]"}'
851
863
  logger.info('boot', { token }); // token=[redacted]
852
864
  revealSecret(token); // the real string — the one call that unwraps
865
+ isSecret(token); // true
853
866
  ```
854
867
 
855
868
  | Surface | Redacted |
@@ -883,7 +896,7 @@ Not configuration of the app: what `x verify` holds it to, committed at the repo
883
896
  { "exercise": { "unprovenMax": 0, "statementsMax": 100 } }
884
897
  ```
885
898
 
886
- `x new` writes exactly that; `x upgrade` writes the figures the hop measured into a file that states none, so the floor only falls. A malformed value is a `manifest`-step problem naming the shape → [CLI reference](CLI-Reference#x-exercise).
899
+ `x new` writes exactly that; `x upgrade` writes the figures the hop measured into a file that states none, so the floor only falls; a figure the app already wrote is never changed, even when the pass's constant seed (31.47.0) lands above it → [Upgrading](Upgrading). A malformed value is a `manifest`-step problem naming the shape → [CLI reference](CLI-Reference#x-exercise).
887
900
 
888
901
  `x config show --json` prints the resolved config — defaults merged, credentials redacted; `--section database` for one key (since 31.17.0) → [CLI reference](CLI-Reference).
889
902
 
@@ -34,6 +34,13 @@ Rename a column and the entity type changes, the action's output stops matching,
34
34
  `As of 2026-08`:
35
35
 
36
36
  ```ts
37
+ import { entity, enumerated, integer, invariant, text, timestamp, uuid } from '@ultimat3/entity';
38
+
39
+ const POST_STATUSES = ['draft', 'published'] as const;
40
+ const TITLE_MAX = 120;
41
+
42
+ const orgs = entity('orgs', { columns: { id: uuid().primaryKey() } });
43
+
37
44
  export const posts = entity('posts', {
38
45
  columns: {
39
46
  id: uuid().primaryKey(),
@@ -393,6 +400,12 @@ export async function insert(row: Omit<Widget, 'id' | 'createdAt'>): Promise<Wid
393
400
 
394
401
  ```ts
395
402
  // packages/db/src/client.ts — the handle. `x g entity` adds the import and the line.
403
+ import { database, type Driver, entity, uuid } from '@ultimat3/entity';
404
+
405
+ declare const driver: Driver;
406
+ const post = entity('posts', { columns: { id: uuid().primaryKey() } });
407
+ const widget = entity('widgets', { columns: { id: uuid().primaryKey() } });
408
+
396
409
  const entities = {
397
410
  posts: post,
398
411
  widgets: widget,
@@ -478,8 +491,18 @@ A feature with more than one table: `x g entity <second> --feature <feature>` wr
478
491
  `findById` called several times in one microtask of one request is **one** statement, `As of 2026-08`:
479
492
 
480
493
  ```ts
494
+ import { entity, postgresRepo, uuid } from '@ultimat3/entity';
495
+
496
+ const users = entity('users', {
497
+ tenant: 'orgId',
498
+ columns: { id: uuid().primaryKey(), orgId: uuid() },
499
+ });
500
+ const repo = postgresRepo(users);
501
+ declare const posts: readonly { readonly authorId: string }[];
502
+ declare const orgId: string;
503
+
481
504
  // One `select … where "id" in ($1, $2, $3, …)`, not one statement per post.
482
- const authors = await Promise.all(posts.map((post) => users.findById(post.authorId, { orgId })));
505
+ const authors = await Promise.all(posts.map((post) => repo.findById(post.authorId, { orgId })));
483
506
  ```
484
507
 
485
508
  Nothing to opt into — no `dataloader()`, no `batch()`. `findById` keeps its signature and its meaning, which is the only way the fix reaches code that is already written.
@@ -499,11 +522,27 @@ A `for … of` loop awaits between iterations, so no two of its lookups share a
499
522
  they came from batches them instead, `As of 2026-08`:
500
523
 
501
524
  ```ts
502
- const page = await db.posts.findMany({ orgId });
525
+ import { entity, postgresRepo, uuid } from '@ultimat3/entity';
526
+
527
+ const members = entity('members', {
528
+ tenant: 'orgId',
529
+ columns: { id: uuid().primaryKey(), orgId: uuid() },
530
+ });
531
+ const posts = entity('posts', {
532
+ tenant: 'orgId',
533
+ columns: {
534
+ id: uuid().primaryKey(),
535
+ orgId: uuid(),
536
+ authorId: uuid().references(() => members.id),
537
+ },
538
+ });
539
+ declare const orgId: string;
540
+
541
+ const page = await postgresRepo(posts).findMany({ orgId });
503
542
  for (const post of page.rows) {
504
543
  // Two statements for the whole loop: the page, then one `where "id" in (…)` over every author
505
544
  // on it. Every lookup after the first is memory.
506
- const author = await db.users.findById(post.authorId, { orgId });
545
+ const author = await postgresRepo(members).findById(post.authorId, { orgId });
507
546
  }
508
547
  ```
509
548
 
@@ -526,11 +565,28 @@ The eager, declarative third of the family: the relation is named on the chain a
526
565
  before the caller sees a row, `As of 2026-08`:
527
566
 
528
567
  ```ts
568
+ import { database, entity, text, uuid } from '@ultimat3/entity';
569
+
570
+ const orgs = entity('orgs', { columns: { id: uuid().primaryKey(), name: text() } });
571
+ const members = entity('members', {
572
+ tenant: 'orgId',
573
+ columns: { id: uuid().primaryKey(), orgId: uuid(), name: text() },
574
+ });
575
+ const posts = entity('posts', {
576
+ tenant: 'orgId',
577
+ columns: {
578
+ id: uuid().primaryKey(),
579
+ orgId: uuid(),
580
+ authorId: uuid().references(() => members.id),
581
+ },
582
+ });
583
+ declare const orgId: string;
584
+
529
585
  export const db = database({ orgs, posts, members });
530
586
 
531
587
  // Two statements: the page, then one `select … where "id" in (…)` over its authors.
532
588
  const page = await db.posts.where({ orgId }).preload('author').page();
533
- page.rows[0].author; // the member row, or null — always present
589
+ page.rows[0]?.author; // the member row, or null — always present
534
590
  ```
535
591
 
536
592
  Nothing new to declare: `'author'` is the relation the `authorId` foreign key on `posts` already
@@ -605,6 +661,25 @@ for one page meant. Staging and production say nothing; refusing is a break, and
605
661
 
606
662
  ```ts
607
663
  // One statement per batch, one page of rows in memory at a time.
664
+ import { database, entity, uuid } from '@ultimat3/entity';
665
+
666
+ declare const search: { index(rows: readonly object[]): Promise<void> };
667
+
668
+ const members = entity('members', {
669
+ tenant: 'orgId',
670
+ columns: { id: uuid().primaryKey(), orgId: uuid() },
671
+ });
672
+ const posts = entity('posts', {
673
+ tenant: 'orgId',
674
+ columns: {
675
+ id: uuid().primaryKey(),
676
+ orgId: uuid(),
677
+ authorId: uuid().references(() => members.id),
678
+ },
679
+ });
680
+ const db = database({ members, posts });
681
+ declare const orgId: string;
682
+
608
683
  for await (const batch of db.posts.where({ orgId }).preload('author').inBatches(500)) {
609
684
  await search.index(batch);
610
685
  }
@@ -617,6 +692,25 @@ Stopping early keeps the position, which is what makes a long backfill a job tha
617
692
  time and pick up where it stopped:
618
693
 
619
694
  ```ts
695
+ import { database, entity, text, uuid } from '@ultimat3/entity';
696
+ import { type Ctx } from '@ultimat3/core';
697
+
698
+ declare const checkpoint: string | null;
699
+ declare const deadline: Date;
700
+ declare const search: { index(rows: readonly object[]): Promise<void> };
701
+
702
+ const posts = entity('posts', {
703
+ tenant: 'orgId',
704
+ columns: { id: uuid().primaryKey(), orgId: uuid() },
705
+ });
706
+ const checkpoints = entity('checkpoints', {
707
+ columns: { id: uuid().primaryKey(), cursor: text().nullable() },
708
+ });
709
+ const db = database({ checkpoints, posts });
710
+ declare const id: string;
711
+ declare const orgId: string;
712
+ declare const ctx: Ctx;
713
+
620
714
  await using batches = db.posts.where({ orgId }).after(checkpoint).inBatches(500);
621
715
  for await (const batch of batches) {
622
716
  await search.index(batch);
@@ -659,6 +753,20 @@ them, `As of 2026-08`:
659
753
 
660
754
  ```ts
661
755
  // One statement for all of `ids`, not one `select count(*)` per post.
756
+ import { database, entity, integer, uuid } from '@ultimat3/entity';
757
+
758
+ const posts = entity('posts', {
759
+ tenant: 'orgId',
760
+ columns: { id: uuid().primaryKey(), orgId: uuid(), likeCount: integer().default(0) },
761
+ });
762
+ const likes = entity('likes', {
763
+ tenant: 'orgId',
764
+ columns: { id: uuid().primaryKey(), orgId: uuid(), postId: uuid() },
765
+ });
766
+ const db = database({ likes, posts });
767
+ declare const orgId: string;
768
+ declare const ids: readonly string[];
769
+
662
770
  const counts = await db.likes.where({ orgId }).andWhere('postId', 'in', ids).countBy('postId');
663
771
  for (const id of ids) await db.posts.update(id, { likeCount: counts.get(id) ?? 0 });
664
772
  ```
@@ -761,14 +869,36 @@ the same defect on the write side, and `insertAll`/`upsertAll` are its answer, `
761
869
  call is all or nothing, `As of 2026-11-02`:
762
870
 
763
871
  ```ts
872
+ import { database, entity, text, uuid } from '@ultimat3/entity';
873
+
874
+ const likes = entity('likes', {
875
+ tenant: 'orgId',
876
+ columns: { id: uuid().primaryKey(), orgId: uuid(), postId: uuid(), memberId: uuid() },
877
+ indexes: [{ on: ['orgId', 'postId', 'memberId'], unique: true }],
878
+ });
879
+ const tags = entity('tags', {
880
+ tenant: 'orgId',
881
+ columns: { id: uuid().primaryKey(), orgId: uuid(), name: text() },
882
+ });
883
+ const counters = entity('counters', {
884
+ tenant: 'orgId',
885
+ columns: { id: uuid().primaryKey(), orgId: uuid(), day: text() },
886
+ indexes: [{ on: ['orgId', 'day'], unique: true }],
887
+ });
888
+ const db = database({ counters, likes, tags });
889
+ declare const orgId: string;
890
+ declare const names: readonly string[];
891
+ declare const likeRows: readonly { orgId: string; postId: string; memberId: string }[];
892
+ declare const counterRows: readonly { orgId: string; day: string }[];
893
+
764
894
  await db.tags.insertAll(names.map((name) => ({ orgId, name }))); // one statement, n rows
765
895
 
766
- await db.likes.upsertAll(rows, { // insert, or leave what is there
896
+ await db.likes.upsertAll(likeRows, { // insert, or leave what is there
767
897
  onConflict: ['orgId', 'postId', 'memberId'],
768
898
  onMatch: 'nothing',
769
899
  });
770
900
 
771
- await db.counters.upsertAll(rows, { onConflict: ['orgId', 'day'] }); // insert, or overwrite
901
+ await db.counters.upsertAll(counterRows, { onConflict: ['orgId', 'day'] }); // insert, or overwrite
772
902
  ```
773
903
 
774
904
  Rows are `Insertable` and go through `$parse` exactly as one row does, so declared defaults are
@@ -919,6 +1049,16 @@ in `packages/<pkg>/seeds/<name>.ts` or `packages/<pkg>/src/seed.ts` — the two
919
1049
  looks.
920
1050
 
921
1051
  ```ts
1052
+ import { defineSeed, entity, integer, text, uuid } from '@ultimat3/entity';
1053
+
1054
+ const plans = entity('plans', {
1055
+ columns: { id: uuid().primaryKey(), code: text(), currency: text(), monthly: integer() },
1056
+ });
1057
+ const orgs = entity('orgs', { columns: { id: uuid().primaryKey(), slug: text(), name: text() } });
1058
+ const reports = entity('reports', { columns: { id: uuid().primaryKey(), slug: text() } });
1059
+ declare const monthly: number;
1060
+ declare const generated: readonly { id: string; slug: string }[];
1061
+
922
1062
  export const dev = defineSeed('dev', async ({ insert, upsert, exists, id }) => {
923
1063
  // The table owns the id, so the NATURAL key is the only key: insert, or update what is there.
924
1064
  await upsert(plans, { by: ['code', 'currency'] }, { code: 'team', currency: 'EUR', monthly });
@@ -1039,6 +1179,8 @@ zone because it names no instant.
1039
1179
  A credential column is `text().sealed()`. The row reads `string`; the database holds ciphertext.
1040
1180
 
1041
1181
  ```ts
1182
+ import { database, entity, text, uuid } from '@ultimat3/entity';
1183
+
1042
1184
  export const connections = entity('connections', {
1043
1185
  columns: {
1044
1186
  id: uuid().primaryKey(),
@@ -1048,6 +1190,9 @@ export const connections = entity('connections', {
1048
1190
  },
1049
1191
  });
1050
1192
 
1193
+ const db = database({ connections });
1194
+ declare const email: string;
1195
+
1051
1196
  const row = await db.connections.where({ email }).one(); // found by the stored string
1052
1197
  row?.password; // the plaintext, on the server
1053
1198
  ```
@@ -1097,6 +1242,11 @@ password: true })` and `preload()` keep the property, still server-only.
1097
1242
  **Testing a sealed row.** `toEqual` walks enumerable properties. Write one of:
1098
1243
 
1099
1244
  ```ts
1245
+ import { expect } from '@ultimat3/testing';
1246
+
1247
+ declare const id: string;
1248
+ declare const row: { readonly id: string; readonly label: string; readonly password: string };
1249
+
1100
1250
  expect(row).toEqualRow({ id, label: 'primary', password: 'hunter2' }); // every own property
1101
1251
  expect(row.password).toBe('hunter2');
1102
1252
  expect(row).toMatchObject({ password: 'hunter2' });
@@ -1139,8 +1289,18 @@ A column with existing plaintext is migrated — expand, backfill, contract.
1139
1289
  ```ts
1140
1290
  // apps/web/app/connection/backfills/seal-connection-passwords.ts — a backfill IS a job: register
1141
1291
  // the module in defineApi({ jobs }) beside the slice's other jobs
1292
+ import { database, entity, text, uuid } from '@ultimat3/entity';
1142
1293
  import { backfill } from '@ultimat3/jobs';
1143
1294
 
1295
+ const connections = entity('connections', {
1296
+ columns: {
1297
+ id: uuid().primaryKey(),
1298
+ password: text().nullable(),
1299
+ passwordSealed: text().nullable().sealed(),
1300
+ },
1301
+ });
1302
+ const db = database({ connections });
1303
+
1144
1304
  export const sealConnectionPasswords = backfill({
1145
1305
  name: 'seal-connection-passwords',
1146
1306
  tenant: 'none', // every tenant; the pass opens the cross-tenant scope
@@ -1175,6 +1335,8 @@ Three overrides, `As of 2026-08`, and together they are what makes a schema Ulti
1175
1335
  generate declarable at all. An entity that uses none of them emits exactly what it always did.
1176
1336
 
1177
1337
  ```ts
1338
+ import { date, entity, money, text, uuid } from '@ultimat3/entity';
1339
+
1178
1340
  export const accounts = entity('account', {
1179
1341
  table: 'legacy_accounts',
1180
1342
  columns: {
package/wiki/FAQ.md CHANGED
@@ -29,7 +29,7 @@ What it does **not** claim:
29
29
  |---|---|
30
30
  | A multi-node realtime **rate** | correctness across nodes is proven over a real NATS bus (`multi-node.live.test.ts`, `As of 2026-11-14`): a publish on one node delivered by another in order, a page resuming on a survivor from its cursor with nothing lost or twice, a restarted node's snapshot, a missed-bus gap re-served at once ([Realtime](Realtime#across-nodes-over-a-real-bus)). The 50k forced-restart benchmark is still **one** `sync` node over `InProcessTransport`; fanout throughput and per-node socket capacity across nodes are unmeasured targets, not results |
31
31
  | A rolling restart on **Compose** | Compose is the single-node rung: one published port has one binder, so a restart there is a restart. The invisible-restart proof is Kubernetes only ([Deployment](Deployment)) |
32
- | Not shipped, `As of 2026-09-23` | the plugin API, multi-region replication, and the Redis **job** driver — all behind the interfaces that ship today (there is no NATS job driver since 25.0.0). The Redis driver throws `X_NOT_IMPLEMENTED` with a runnable `fix:` line rather than pretending to work |
32
+ | Not shipped, `As of 2026-11-18` | the plugin API and multi-region replication, both decided ([Known gaps](Known-Gaps#open-by-decision)). The Redis **job** driver does ship: `redisJobDriver()` from `@ultimat3/jobs/redis`, without `introspect`, `backfills` or `leases`. There is no NATS job driver since 25.0.0 |
33
33
 
34
34
  ### What is actually finished?
35
35
 
@@ -18,6 +18,9 @@ and no surface of its own ([The eight primitives](The-Eight-Primitives)).
18
18
 
19
19
  ```ts
20
20
  import { defineFlag, isEnabled } from '@ultimat3/flags';
21
+ import { type Actor } from '@ultimat3/core';
22
+
23
+ declare const actor: Actor;
21
24
 
22
25
  export const newTaxEngine = defineFlag({
23
26
  kind: 'temporary',
@@ -78,10 +78,36 @@ x g action publish-post --feature post
78
78
  ```
79
79
 
80
80
  ```ts
81
+ import { action, t } from '@ultimat3/action';
82
+ import { tag } from '@ultimat3/cache';
83
+ import type { Actor } from '@ultimat3/core';
84
+ import type { JobHandle } from '@ultimat3/jobs';
85
+ import { can } from '@ultimat3/policy';
86
+
87
+ declare module '@ultimat3/cache' {
88
+ interface CacheTagRegistry {
89
+ post: true;
90
+ feed: true;
91
+ }
92
+ }
93
+ declare module '@ultimat3/core' {
94
+ interface CtxServices {
95
+ readonly posts: {
96
+ publish(id: string): Promise<{ id: string; orgId: string; title: string }>;
97
+ like(id: string): Promise<{ likeCount: number; likedByMe: boolean }>;
98
+ body(id: string): Promise<string>;
99
+ };
100
+ }
101
+ }
102
+
103
+ declare const notifySubscribers: JobHandle<{ postId: string; orgId: string }>;
104
+ declare function ownsPost(actor: Actor | null, postId: string): boolean;
105
+ const PostView = t.object({ id: t.uuid, orgId: t.uuid, title: t.string });
106
+
81
107
  export const publishPost = action({
82
108
  input: t.object({ postId: t.uuid, notify: t.boolean.default(true) }),
83
109
  output: PostView,
84
- policy: can('post:publish', ({ input, actor }) => ownsPost(actor, input.postId)),
110
+ policy: can<{ postId: string }>('post:publish', ({ input, actor }) => ownsPost(actor, input.postId)),
85
111
  cache: { invalidates: [tag.post, tag.feed] },
86
112
  mcp: { expose: true, description: 'Publish a draft post' },
87
113
  async handle({ input, ctx }) {
@@ -10,6 +10,23 @@ Two factories return a `job` rather than a ninth primitive, so everything on thi
10
10
 
11
11
  ```ts
12
12
  // job
13
+ import { job } from '@ultimat3/jobs';
14
+ import { t } from '@ultimat3/action';
15
+ import { type AnyMailDefinition } from '@ultimat3/mail';
16
+
17
+ declare const welcomeEmail: AnyMailDefinition;
18
+ declare const nudgeEmail: AnyMailDefinition;
19
+
20
+ declare module '@ultimat3/core' {
21
+ interface CtxServices {
22
+ readonly orgs: {
23
+ provision(id: string): Promise<{ id: string; name: string }>;
24
+ byId(id: string): Promise<{ id: string; name: string }>;
25
+ };
26
+ readonly mail: { send(mail: unknown, to: unknown): Promise<void> };
27
+ }
28
+ }
29
+
13
30
  export const onboardOrg = job({
14
31
  input: t.object({ orgId: t.uuid }),
15
32
  tenant: ({ orgId }) => orgId, // the org this run acts as
@@ -219,6 +236,9 @@ export async function onDocSaved(docId: string, revision: number): Promise<void>
219
236
  Declared per job, held across the fleet.
220
237
 
221
238
  ```ts
239
+ import { job } from '@ultimat3/jobs';
240
+ import { t } from '@ultimat3/action';
241
+
222
242
  export const syncCrm = job({
223
243
  input: t.object({ orgId: t.uuid, accountId: t.uuid }),
224
244
  tenant: ({ orgId }) => orgId,
@@ -380,6 +400,14 @@ Every operator capability is a member of `JobIntrospection` (`driver.introspect`
380
400
  | how a run ended | `job({ onSettled })` — `completed` (with what `run` returned), `dead-lettered`, `dropped` or `refused`; after the row is settled, under the job's tenant, three tries of its own, on a live `ctx.signal` under `onSettledTimeout` (30 s by default): its `fetch` and its writes land | at least once across a crash (`redriven: true` on the re-drive), but at most once for a completion whose body returned a value; a hook that keeps failing is `X_JOB_ON_SETTLED_FAILED`, logged and reported, and the row is untouched. A cancel is not a settlement: whoever cancels is the observer |
381
401
 
382
402
  ```ts
403
+ import { t } from '@ultimat3/action';
404
+ import { job } from '@ultimat3/jobs';
405
+
406
+ declare function loadRows(id: string): Promise<readonly { readonly id: string }[]>;
407
+ declare function syncRow(row: { readonly id: string }): Promise<void>;
408
+ declare function markAccountSynced(id: string, rows: number): Promise<void>;
409
+ declare function markAccountBroken(id: string, code: string | undefined): Promise<void>;
410
+
383
411
  export const syncAccount = job({
384
412
  input: t.object({ accountId: t.uuid, orgId: t.uuid }),
385
413
  tenant: ({ orgId }) => orgId,
@@ -669,13 +697,21 @@ the event taxonomy, which endpoints exist, or what a payload means — the fan-o
669
697
  loop over its own subscription table. Do not hand-write a delivery job.
670
698
 
671
699
  ```ts
672
- import { memoryWebhookLedger, webhook } from '@ultimat3/jobs';
700
+ import { memoryWebhookLedger, webhook, type WebhookEndpoint } from '@ultimat3/jobs';
701
+
702
+ // The app's own tables: which endpoints exist and what an event says are never the framework's.
703
+ declare function endpointById(id: string): Promise<WebhookEndpoint | null>;
704
+ declare function eventById(id: string): Promise<{ topic: string; body: string } | null>;
705
+ declare function subscribersOf(
706
+ topic: string,
707
+ ): Promise<readonly { readonly id: string; readonly orgId: string }[]>;
708
+ declare const event: { readonly id: string };
673
709
 
674
710
  export const deliver = webhook({
675
711
  name: 'partner.webhooks', // required: a durable queue key
676
712
  tenant: ({ orgId }) => orgId, // the org that owns the endpoint — or 'none'
677
- endpoint: ({ endpointId }) => db.endpoints.byId(endpointId), // read per attempt, never checkpointed
678
- event: ({ eventId }) => db.events.byId(eventId), // { topic, body }
713
+ endpoint: ({ endpointId }) => endpointById(endpointId), // read per attempt, never checkpointed
714
+ event: ({ eventId }) => eventById(eventId), // { topic, body }
679
715
  ledger: memoryWebhookLedger(), // dev only — a WebhookLedger over your own table in production
680
716
  disableAfter: 10, // DEFAULT_WEBHOOK_DISABLE_AFTER
681
717
  });
@@ -814,6 +850,9 @@ export const paymentEvents = webhookReceiver({
814
850
  One interface. **Job code never changes.** Step persistence hangs off the same object (`steps`), so it is identical on every implementation. It is the `jobs` adapter port: the interface is on `@ultimat3/jobs/adapter`, `memoryJobDriver` is the driver to copy, `behavesLike(jobDriverConformance, () => yourDriver())` proves one, and `jobs:` in `apps/<app>/runtime.ts` wires it — [Adapters](Adapters#jobs). The bus `step.waitForEvent` resumes from (`eventBus`) and the store behind the outbox (`outboxStore`) are two more ports, swapped the same way and no other: [Adapters](Adapters#eventbus), [Adapters](Adapters#outboxstore).
815
851
 
816
852
  ```ts
853
+ import { type BackfillLedger, type ClaimedJob, type ClaimOptions, type EnqueueRequest, type EnqueueResult, type JobIntrospection, type LeaseStore, type NackOptions, type QueueStats, type StepStore } from '@ultimat3/jobs';
854
+ import { type HeartbeatOptions } from '@ultimat3/jobs/adapter';
855
+
817
856
  export interface JobDriver {
818
857
  readonly name: string;
819
858
  /** Step persistence lives with the queue: one store, one transaction boundary. */
@@ -838,20 +877,21 @@ Three of the four optional members degrade rather than refuse: no `introspect` i
838
877
 
839
878
  **`leases` is the one that refuses.** The in-process limiter is a fast path over one heap and is multiplied by the replica count, so a driver with no `LeaseStore` can only hold `concurrency.limit` per process. `jobWorker().start()` therefore **throws `X_JOB_CONCURRENCY_UNENFORCEABLE`**, naming every registered job that declared `concurrency`, rather than logging a cap it cannot keep. `postgres` ships one; a driver you write yourself needs one before any job in the tree may declare `concurrency`.
840
879
 
841
- Two implementations ship, `As of 25.0.0`: `postgresJobDriver()` and `memoryJobDriver()`. **Redis is not a jobs driver**, and neither is NATS: 25.0.0 deleted both all-throw stubs (`createNatsDriver` and the Redis one), whose every method raised `X_NOT_IMPLEMENTED` — an app could typecheck against a driver that could not enqueue a job. NATS stays the realtime fanout transport.
880
+ Three implementations ship, `As of 2026-11-18`: `postgresJobDriver()`, `redisJobDriver()` (from `@ultimat3/jobs/redis`, since 2026-10) and `memoryJobDriver()`. **NATS is not a jobs driver**; it stays the realtime fanout transport. 25.0.0 deleted the all-throw `createNatsDriver` and Redis stubs, whose every method raised `X_NOT_IMPLEMENTED` — an app could typecheck against a driver that could not enqueue a job. `redisJobDriver()` is a later, working implementation, not that stub.
842
881
 
843
- | Driver | Status `As of 25.0.0` | When | Trade-off |
882
+ | Driver | Status `As of 2026-11-18` | When | Trade-off |
844
883
  |---|---|---|---|
845
884
  | `postgres` (default) | **shipped** | always, up to ~thousands of jobs/sec. `x dev` runs it too, against the embedded PGlite | outbox is free (same DB, same tx); `SELECT ... FOR UPDATE SKIP LOCKED` claiming; zero extra infra |
885
+ | `redis` | **shipped** | a queue off the database, `jobs: redisJobDriver()` | one Lua script per operation; no `introspect`, `backfills` or `leases`, so a job declaring `concurrency` refuses `jobWorker().start()` (`X_JOB_CONCURRENCY_UNENFORCEABLE`); the outbox still stages in Postgres |
846
886
  | `memory` | **shipped**; there is no config value for any driver | tests and fixtures, through `memoryJobDriver()` | in-process; nothing survives a restart — which is why it was never a safe drain target |
847
887
 
848
888
  **There is no `jobs.driver`, and 5.0.0 is where it went.** It accepted `'postgres' | 'redis' | 'nats'` and had **no reader anywhere** — boot always built `postgresJobDriver`, stated in [`packages/jobs/src/driver.ts`](https://github.com/developerz-ai/ultimate/blob/main/packages/jobs/src/driver.ts)'s own header. So setting it to `redis` changed nothing at all and you silently got Postgres, which is the more dangerous behaviour because nothing reports it. From 5.0.0 to 24.x a stale key still rode through untyped; **25.0.0 refuses it** at `defineConfig`, naming the driver seam. Deleting it from `app.config.ts` is the whole of the upgrade.
849
889
 
850
890
  **The seam that does work is `jobs:` in `export const runtime = { … }`** (`apps/<app>/runtime.ts`; 31.0.0 deleted `setJobDriver`) — swap the driver, zero job-code change, which is what the interface buys; a test swaps one for itself with `await swapAdapter('jobs', driver)` from `@ultimat3/testing`. Every swappable backend works this way: [Adapters](Adapters). `redisJobDriver()` is the second durable driver (`As of 2026-10`, #710): `jobs: redisJobDriver()` on core's `redisClient()` — while Redis is down an `enqueue` is `X_DRIVER_UNAVAILABLE` at once, never a wait — imported from `@ultimat3/jobs/redis`, held to the same conformance suite as Postgres, without the operator surface (`x jobs show`, `retry`, `cancel`), backfill bookkeeping or fleet-wide `concurrency` — [`packages/jobs/README.md`](https://github.com/developerz-ai/ultimate/blob/main/packages/jobs/README.md#drivers) has the table. There is no NATS jobs driver.
851
891
 
852
- **`x jobs` has no `drain`, `As of 2026-11-15`.** It was planned from 25.0.0 and left the registry ([Known gaps](Known-Gaps#open-by-decision)): with Postgres the one durable driver, there is nowhere to drain to. To stop a queue for maintenance, `x jobs pause <queue>`, then `x jobs list --queue <queue> --state running --json` until it is empty. Its two former `--to` values, `redis` and `nats`, were all-throw stubs — until 2026-10 a drain leased the whole pending batch for five minutes, failed every enqueue and nacked it back, nothing moved, and no worker could claim those jobs meanwhile. 25.0.0 deleted the stubs and the unreachable drain body. A drain that returns with a real second driver is new code, and owes the lesson of `--to memory`, a target until 2026-09: `memoryJobDriver()` is a `Map` inside the command's own process, so the drain enqueued each job into it, acked the durable row off the source, printed `ok: true`, and lost every copy when the command exited.
892
+ **`x jobs` has no `drain`, `As of 2026-11-15`.** It was planned from 25.0.0 and left the registry ([Known gaps](Known-Gaps#open-by-decision)): moving in-flight rows between drivers is a migration no command owns. To stop a queue for maintenance, `x jobs pause <queue>`, then `x jobs list --queue <queue> --state running --json` until it is empty. Its two former `--to` values, `redis` and `nats`, were all-throw stubs — until 2026-10 a drain leased the whole pending batch for five minutes, failed every enqueue and nacked it back, nothing moved, and no worker could claim those jobs meanwhile. 25.0.0 deleted the stubs and the unreachable drain body. A drain that returns is new code, and owes the lesson of `--to memory`, a target until 2026-09: `memoryJobDriver()` is a `Map` inside the command's own process, so the drain enqueued each job into it, acked the durable row off the source, printed `ok: true`, and lost every copy when the command exited.
853
893
 
854
- So there is no cross-driver migration procedure — and none is needed while `postgres` is the only driver that runs.
894
+ So the framework ships no cross-driver migration procedure: moving queued jobs from one driver to another is the application's to do.
855
895
 
856
896
  ## Dead letter
857
897
 
@@ -908,14 +948,31 @@ Full index: [Error codes](Error-Codes). Verbatim error shapes live in each packa
908
948
 
909
949
  ```ts
910
950
  // job test — the step guarantee, not the happy path
911
- test('onboardOrg retries only the failed step', async ({ seed, clock, mail }) => {
912
- const { org } = await seed('fresh-org');
951
+ import type { JobHandle } from '@ultimat3/jobs';
952
+ import type { AnyMailDefinition } from '@ultimat3/mail';
953
+ import { expect, jobTest } from '@ultimat3/testing';
954
+
955
+ declare const nudgeEmail: AnyMailDefinition;
956
+ declare const onboardOrg: JobHandle<{ orgId: string }>;
957
+ declare const orgId: string;
958
+
959
+ jobTest('a resumed run replays its steps, and a mail blip retries the mail job', async ({
960
+ clock,
961
+ mail,
962
+ runJobs,
963
+ }) => {
913
964
  mail.failOnce(nudgeEmail);
914
- await runJobs(onboardOrg, { orgId: org.id });
965
+ await runJobs(onboardOrg, { orgId });
915
966
  clock.advance('3d');
916
- const trace = await runJobs.drain();
917
- expect(trace.steps.provision.executions).toBe(1); // replayed from storage
918
- expect(trace.steps['nudge'].executions).toBe(2); // only this one retried
967
+ const resumed = await runJobs.drain();
968
+ expect(resumed.steps['provision']?.executions).toBe(1); // replayed from storage
969
+ expect(resumed.steps['nudge']?.executions).toBe(1);
970
+ expect(mail.outbox()).toHaveLength(1); // the nudge's send was refused
971
+
972
+ clock.advance('1h');
973
+ const retried = await runJobs.drain();
974
+ expect(mail.outbox()).toHaveLength(2); // the mail job's retry lands
975
+ expect(retried.steps['nudge']?.executions).toBe(1); // and the step never ran again
919
976
  });
920
977
  ```
921
978