@ultimat3/cli 31.47.1 → 31.49.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 (276) hide show
  1. package/CLAUDE.md +30 -23
  2. package/README.md +96 -4
  3. package/package.json +29 -29
  4. package/src/api-registration.ts +28 -14
  5. package/src/app-load.ts +6 -1
  6. package/src/app-root.ts +7 -1
  7. package/src/clean-services.ts +142 -0
  8. package/src/cmd-auth.ts +3 -0
  9. package/src/cmd-clean-spec.ts +10 -3
  10. package/src/cmd-clean.ts +23 -9
  11. package/src/cmd-db-backfill.ts +6 -0
  12. package/src/cmd-db-branch.ts +10 -4
  13. package/src/cmd-db-recount.ts +5 -12
  14. package/src/cmd-db-rollback.ts +77 -0
  15. package/src/cmd-db-spec.ts +18 -2
  16. package/src/cmd-db-status.ts +5 -10
  17. package/src/cmd-db.ts +105 -33
  18. package/src/cmd-deploy-verify.ts +14 -6
  19. package/src/cmd-docs-topic.ts +94 -0
  20. package/src/cmd-docs.ts +15 -1
  21. package/src/cmd-doctor.ts +109 -41
  22. package/src/cmd-drill.ts +100 -19
  23. package/src/cmd-env.ts +30 -8
  24. package/src/cmd-errors-app.ts +63 -0
  25. package/src/cmd-errors.ts +50 -14
  26. package/src/cmd-generate.ts +17 -4
  27. package/src/cmd-heavy-spec.ts +36 -0
  28. package/src/cmd-heavy.ts +244 -0
  29. package/src/cmd-jobs.ts +27 -1
  30. package/src/cmd-merge-driver-spec.ts +12 -0
  31. package/src/cmd-merge-driver.ts +95 -0
  32. package/src/cmd-new.ts +23 -3
  33. package/src/cmd-policy-spec.ts +9 -1
  34. package/src/cmd-policy.ts +72 -17
  35. package/src/cmd-stop.ts +18 -4
  36. package/src/cmd-tasks-run.ts +87 -0
  37. package/src/cmd-tasks-spec.ts +10 -3
  38. package/src/cmd-tasks.ts +8 -5
  39. package/src/cmd-test.ts +15 -4
  40. package/src/cmd-upgrade-spec.ts +8 -1
  41. package/src/cmd-upgrade.ts +32 -5
  42. package/src/cmd-verify.ts +9 -41
  43. package/src/codemods/agents-doc-row.ts +73 -0
  44. package/src/codemods/define-error-leaf.ts +37 -12
  45. package/src/codemods/docs-many-agents.ts +26 -0
  46. package/src/codemods/docs-worker-commands.ts +26 -0
  47. package/src/codemods/index.ts +6 -0
  48. package/src/codemods/merge-drivers.ts +66 -0
  49. package/src/command.ts +3 -0
  50. package/src/db-applied-edits.ts +117 -0
  51. package/src/db-dev-wire.ts +18 -0
  52. package/src/db-diagnostics.ts +5 -10
  53. package/src/db-generate.ts +82 -7
  54. package/src/db-migrate-pass.ts +51 -0
  55. package/src/db-migrate-through-dev.ts +209 -0
  56. package/src/db-rollback-consent.ts +128 -0
  57. package/src/db-rollback-pass.ts +76 -0
  58. package/src/db-seed-generate.ts +5 -1
  59. package/src/db-seed.ts +7 -1
  60. package/src/deploy-verify-findings.ts +3 -0
  61. package/src/deploy-verify-grade.ts +3 -0
  62. package/src/deploy-verify-processes.ts +32 -0
  63. package/src/dev-boot.ts +3 -0
  64. package/src/dev-db-migrate.ts +155 -0
  65. package/src/dev-db-rollback.ts +33 -0
  66. package/src/dev-db-settled.ts +22 -0
  67. package/src/dev-lock-errors.ts +78 -0
  68. package/src/dev-lock-holder-dir.ts +64 -0
  69. package/src/dev-lock-live.ts +44 -0
  70. package/src/dev-lock.ts +59 -84
  71. package/src/dev-policy.ts +11 -8
  72. package/src/dev-rebuild-schema.ts +116 -13
  73. package/src/dev-rebuild.ts +13 -4
  74. package/src/dev-route-table.ts +7 -0
  75. package/src/dispatch.ts +21 -1
  76. package/src/doctor-advisory-floors.ts +30 -8
  77. package/src/doctor-api-listing.ts +114 -0
  78. package/src/doctor-guarded.ts +41 -0
  79. package/src/doctor-port.ts +90 -17
  80. package/src/doctor-probe.ts +36 -5
  81. package/src/doctor-processes-probe.ts +127 -0
  82. package/src/doctor-processes.ts +136 -0
  83. package/src/doctor-warnings.ts +17 -0
  84. package/src/error-codes-agents.ts +35 -0
  85. package/src/error-codes-processes.ts +30 -0
  86. package/src/error-codes-tooling.ts +11 -3
  87. package/src/error-codes.ts +12 -13
  88. package/src/errors-suite.ts +27 -0
  89. package/src/errors.ts +18 -22
  90. package/src/exec.ts +11 -3
  91. package/src/exercise-registration.ts +4 -3
  92. package/src/framework-env.ts +7 -3
  93. package/src/generate-files.ts +1 -0
  94. package/src/generate-grant-findings.ts +7 -5
  95. package/src/generate-grants.ts +9 -8
  96. package/src/generate-kinds.ts +30 -6
  97. package/src/generate-roles-file.ts +30 -0
  98. package/src/generate-slice-policy.ts +3 -3
  99. package/src/guards.ts +2 -2
  100. package/src/heavy-cores.ts +51 -0
  101. package/src/heavy-env.ts +21 -0
  102. package/src/heavy-errors.ts +54 -0
  103. package/src/heavy-flock.ts +73 -0
  104. package/src/heavy-holders.ts +78 -0
  105. package/src/heavy-ledger.ts +400 -0
  106. package/src/heavy-memory.ts +67 -0
  107. package/src/heavy-pressure.ts +104 -0
  108. package/src/heavy-weights.ts +47 -0
  109. package/src/heavy.ts +308 -0
  110. package/src/i18n-registration.ts +22 -2
  111. package/src/island-harness.ts +2 -2
  112. package/src/job-budget.ts +4 -2
  113. package/src/job-registration.ts +64 -8
  114. package/src/jobs-queue-known.ts +43 -0
  115. package/src/local-cli.ts +6 -5
  116. package/src/mcp-errors-agents.ts +20 -0
  117. package/src/mcp-errors-doctor.ts +27 -0
  118. package/src/mcp-errors-processes.ts +23 -0
  119. package/src/mcp-errors.ts +18 -29
  120. package/src/mcp-host.ts +2 -2
  121. package/src/merge-driver-catalog.ts +58 -0
  122. package/src/merge-driver-config.ts +43 -0
  123. package/src/merge-driver-lines.ts +140 -0
  124. package/src/merge-state.ts +105 -0
  125. package/src/messages-db.ts +22 -1
  126. package/src/messages-processes.ts +13 -0
  127. package/src/messages-upgrade.ts +6 -0
  128. package/src/messages.ts +62 -1
  129. package/src/output-findings.ts +48 -21
  130. package/src/parse.ts +37 -6
  131. package/src/policy-facts.ts +38 -21
  132. package/src/policy-row.ts +99 -0
  133. package/src/port-pair-free.ts +28 -0
  134. package/src/registry-lines.ts +110 -0
  135. package/src/registry.ts +4 -0
  136. package/src/retain-sweep.ts +1 -1
  137. package/src/role-replicator.ts +9 -4
  138. package/src/role-select.ts +86 -0
  139. package/src/role-start.ts +13 -55
  140. package/src/role-sync.ts +10 -5
  141. package/src/runtime-cache-frame.ts +46 -0
  142. package/src/runtime-cache-ttl.ts +23 -0
  143. package/src/runtime-cache.ts +56 -18
  144. package/src/runtime-database-ssl.ts +84 -0
  145. package/src/runtime-idempotency-scope.ts +16 -2
  146. package/src/runtime-jobs-share.ts +52 -0
  147. package/src/runtime-jobs.ts +43 -12
  148. package/src/runtime-overrides.ts +4 -2
  149. package/src/runtime-queue.ts +18 -3
  150. package/src/runtime-services.ts +8 -1
  151. package/src/schema-drift.ts +19 -2
  152. package/src/schema-dump-drift.ts +4 -1
  153. package/src/serve-boot-probe.ts +30 -2
  154. package/src/serve-boot.ts +11 -1
  155. package/src/serve-env.ts +39 -3
  156. package/src/serve.ts +61 -10
  157. package/src/stop-run-start.ts +12 -0
  158. package/src/supervise-boot.ts +61 -0
  159. package/src/supervise-cgroup.ts +84 -0
  160. package/src/supervise-child.ts +206 -0
  161. package/src/supervise-count.ts +244 -0
  162. package/src/supervise-errors.ts +83 -0
  163. package/src/supervise-facts.ts +40 -0
  164. package/src/supervise-messages.ts +84 -0
  165. package/src/supervise-policy.ts +46 -0
  166. package/src/supervise-pool.ts +10 -0
  167. package/src/supervise-probe.ts +158 -0
  168. package/src/supervise-run.ts +54 -0
  169. package/src/supervise.ts +383 -0
  170. package/src/templates/generate-purge.ts +6 -6
  171. package/src/templates/guard-animated-layout-property.ts +2 -2
  172. package/src/templates/guard-bare-error.ts +1 -1
  173. package/src/templates/guard-error-declared.ts +2 -2
  174. package/src/templates/guard-focus-visible.ts +1 -1
  175. package/src/templates/guard-image-dimensions.ts +2 -2
  176. package/src/templates/guard-island-mount-clears.ts +1 -1
  177. package/src/templates/guard-native-confirm.ts +1 -1
  178. package/src/templates/guard-raw-breakpoint.ts +2 -2
  179. package/src/templates/guard-raw-colour.ts +2 -2
  180. package/src/templates/guard-raw-fetch.ts +1 -1
  181. package/src/templates/guard-raw-interval.ts +1 -1
  182. package/src/templates/guard-raw-length.ts +3 -3
  183. package/src/templates/guard-raw-motion.ts +1 -1
  184. package/src/templates/guard-raw-shadow.ts +1 -1
  185. package/src/templates/guard-raw-z-index.ts +1 -1
  186. package/src/templates/guard-released-forms.ts +59 -13
  187. package/src/templates/guard-repo-await-in-loop.ts +1 -1
  188. package/src/templates/guard-repo-raw-sql.ts +4 -4
  189. package/src/templates/guard-repo-unbounded.ts +1 -1
  190. package/src/templates/guard-runtime-pin.ts +1 -1
  191. package/src/templates/guard-semantic-interactive.ts +2 -2
  192. package/src/templates/guard-unbounded-fanout.ts +1 -1
  193. package/src/templates/guard-undeclared-custom-property.ts +3 -3
  194. package/src/templates/guard-undefined-style-class.ts +3 -3
  195. package/src/templates/guard-unzoned-date.ts +3 -3
  196. package/src/templates/query-slice.ts +82 -0
  197. package/src/templates/query.ts +76 -30
  198. package/src/templates/resource-page.ts +3 -2
  199. package/src/templates/scaffold-bin.ts +2 -0
  200. package/src/templates/scaffold-claude-agents.ts +9 -6
  201. package/src/templates/scaffold-claude-commands.ts +7 -1
  202. package/src/templates/scaffold-claude.ts +4 -4
  203. package/src/templates/scaffold-container-compose.ts +47 -7
  204. package/src/templates/scaffold-docs.ts +11 -6
  205. package/src/templates/scaffold-gitattributes.ts +18 -1
  206. package/src/templates/scaffold-helm-templates.ts +9 -0
  207. package/src/templates/scaffold-repo.ts +4 -1
  208. package/src/templates/scaffold-test-services.ts +33 -11
  209. package/src/templates/shapes/offline.ts +0 -7
  210. package/src/templates/shapes/realtime.ts +2 -6
  211. package/src/templates/sign-in-action-tests.ts +6 -4
  212. package/src/templates/sign-in-challenge.ts +62 -0
  213. package/src/templates/sign-in-oidc-mfa.ts +31 -0
  214. package/src/templates/sign-in-oidc.ts +11 -3
  215. package/src/templates/sign-in-password.ts +18 -56
  216. package/src/test-batches.ts +9 -3
  217. package/src/test-shards.ts +117 -37
  218. package/src/test-slots.ts +35 -161
  219. package/src/test-verdict.ts +79 -0
  220. package/src/test-workers.ts +15 -0
  221. package/src/upgrade-gate-codemods.ts +5 -3
  222. package/src/upgrade-gate.ts +19 -1
  223. package/src/upgrade-merge-drivers.ts +25 -0
  224. package/src/upgrade-report.ts +18 -4
  225. package/src/upgrade-scope.ts +62 -0
  226. package/src/verify-checks.ts +6 -11
  227. package/src/verify-coverage-run.ts +9 -5
  228. package/src/verify-deadline.ts +18 -2
  229. package/src/verify-heavy-steps.ts +26 -0
  230. package/src/verify-live.ts +38 -14
  231. package/src/verify-only.ts +67 -0
  232. package/src/verify-progress.ts +7 -3
  233. package/src/verify-run.ts +20 -2
  234. package/src/verify-services-stack.ts +165 -0
  235. package/src/verify-services.ts +84 -2
  236. package/src/verify-test-run.ts +9 -9
  237. package/src/verify-tests.ts +35 -22
  238. package/src/verify-typecheck.ts +25 -2
  239. package/wiki/Actions.md +2 -1
  240. package/wiki/Admin-Dashboard.md +2 -2
  241. package/wiki/Agents.md +5 -5
  242. package/wiki/Auth.md +15 -5
  243. package/wiki/Bare-VM.md +1 -1
  244. package/wiki/Building-Your-Own-Base.md +15 -2
  245. package/wiki/CI-Parallel-Gate.md +4 -4
  246. package/wiki/CLI-Reference.md +127 -48
  247. package/wiki/Caching-And-Invalidation.md +2 -2
  248. package/wiki/Client-Navigation.md +1 -1
  249. package/wiki/Configuration.md +32 -13
  250. package/wiki/Deployment.md +44 -4
  251. package/wiki/Entities-And-Migrations.md +5 -1
  252. package/wiki/FAQ.md +1 -1
  253. package/wiki/Getting-Started.md +2 -2
  254. package/wiki/Home.md +2 -1
  255. package/wiki/I18n.md +5 -3
  256. package/wiki/Installation.md +12 -11
  257. package/wiki/Interface-Rules.md +1 -1
  258. package/wiki/Jobs-And-Workflows.md +24 -4
  259. package/wiki/Known-Gaps.md +2 -2
  260. package/wiki/MCP-And-AI.md +8 -5
  261. package/wiki/Mail.md +1 -1
  262. package/wiki/Many-Agents.md +127 -0
  263. package/wiki/Migrations-And-Backfills.md +18 -0
  264. package/wiki/Notify.md +1 -1
  265. package/wiki/Observability.md +13 -0
  266. package/wiki/Queries-And-Live-Queries.md +2 -2
  267. package/wiki/Realtime.md +10 -1
  268. package/wiki/Routes-And-Render-Modes.md +1 -1
  269. package/wiki/Scheduled-Tasks.md +4 -1
  270. package/wiki/Testing.md +12 -9
  271. package/wiki/Timezones-And-Dates.md +5 -1
  272. package/wiki/Troubleshooting.md +1 -0
  273. package/wiki/Tutorial-01-First-App.md +5 -5
  274. package/wiki/Tutorial-02-First-Feature.md +1 -1
  275. package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
  276. package/wiki/Upgrading.md +37 -0
@@ -2,11 +2,16 @@
2
2
  // generated declaration always carries `orderBy` + `limit` and the generated test pins them:
3
3
  // an unbounded live query is a memory leak that only shows up under load.
4
4
 
5
- import { UltimateError } from '@ultimat3/core';
6
5
  import type { FeatureTarget } from './entity';
7
6
  import { sortedImports } from './imports';
8
7
  import type { GeneratedFile, NameSet } from './naming';
9
8
  import { names } from './naming';
9
+ import {
10
+ assertSliceExports,
11
+ QuerySliceEntityError,
12
+ readsThroughView,
13
+ withoutOwnedTests,
14
+ } from './query-slice';
10
15
  import { PLACEHOLDER_DB_MODULE } from './scaffold-db-client';
11
16
  import { foreignSliceEntity, sliceFoundation, sliceTakesScaffoldRow } from './slice-foundation';
12
17
  import { wrapImport } from './wrap';
@@ -15,22 +20,50 @@ import { wrapImport } from './wrap';
15
20
  const cacheLine = (feature: NameSet, live: boolean): string =>
16
21
  live ? '' : `\n cache: { tags: [${feature.camel}Tag], ttlMs: 30_000 },`;
17
22
 
23
+ /**
24
+ * The projection a read answers through: the slice's `<Feature>View`, the shape its actions
25
+ * already answer — so a column added to the entity reaches the wire only by an edit to the view,
26
+ * and the tenant column never does. Live too: `@ultimat3/realtime` narrows every patch to the
27
+ * columns the snapshot's rows carry (`narrowRow`).
28
+ */
29
+ const viewProjection = (feature: NameSet): string => `
30
+ /**
31
+ * What this read answers: the slice's \`${feature.pascal}View\`, the shape its actions answer —
32
+ * never the whole row. A column added to the entity reaches the wire only once the view lists it,
33
+ * and the tenant column never does.
34
+ */
35
+ const viewOf = (row: ${feature.pascal}): ${feature.pascal}View => {
36
+ const keys = ${feature.pascal}View.$keys;
37
+ return Object.fromEntries(keys.map((key) => [key, row[key]])) as ${feature.pascal}View;
38
+ };
39
+ `;
40
+
41
+ /** The `sql:` thunk: the repo's page, through the view when the slice declares one. */
42
+ const readThunk = (feature: NameSet, view: boolean): string =>
43
+ view
44
+ ? `from<${feature.pascal}View>('${feature.table}', async () => {
45
+ const rows = await repo.list(limit, sort, dir);
46
+ return rows.map(viewOf);
47
+ })`
48
+ : `from<${feature.pascal}>('${feature.table}', () => repo.list(limit, sort, dir))`;
49
+
18
50
  const querySource = (
19
51
  name: NameSet,
20
52
  feature: NameSet,
21
53
  live: boolean,
54
+ view: boolean,
22
55
  ): string => `// ${name.camel}: a ${live ? 'live (subscribable)' : 'one-shot'} read over ${feature.pluralKebab}.
23
56
  // Bounded and ordered — required for${live ? ' live queries' : ' predictable pagination'}.
24
57
  // \`t\` comes from @ultimat3/query, not @ultimat3/schema: a query file imports one package.
25
58
 
26
59
  import { from, query, t } from '@ultimat3/query';
27
- import type { ${feature.pascal} } from '../entity';
60
+ ${view ? wrapImport([`type ${feature.pascal}`, `${feature.pascal}View`], '../entity') : `import type { ${feature.pascal} } from '../entity';`}
28
61
  ${wrapImport(
29
62
  live ? [`can${feature.pascal}Read`] : [`can${feature.pascal}Read`, `${feature.camel}Tag`],
30
63
  '../policy',
31
64
  )}
32
65
  import * as repo from '../repo';
33
-
66
+ ${view ? viewProjection(feature) : ''}
34
67
  /** The columns this read sorts by: \`repo.ListSort\`, and what a page's \`listUrl\` offers. */
35
68
  export const ${name.camel}Sorts = ['createdAt', 'title'] as const;
36
69
 
@@ -56,7 +89,7 @@ export const ${name.camel} = query({
56
89
  sql: ({ limit, sort, dir }) =>
57
90
  // \`feature.table\`, not the kebab plural: \`from()\` quotes the identifier into the SQL text,
58
91
  // and the entity created the table as snake_case.
59
- from<${feature.pascal}>('${feature.table}', () => repo.list(limit, sort, dir))
92
+ ${readThunk(feature, view)}
60
93
  // \`repo.list\`'s own order. These lines are ONE read spelled twice: the thunk is what the
61
94
  // in-memory driver answers and this chain is the SQL Postgres runs, so a sort or a direction
62
95
  // that differs here is a bounded page holding different rows on each.
@@ -87,7 +120,7 @@ const queryTest = (name: NameSet, feature: NameSet, shape: ReadShape): string =>
87
120
  ? [`import { expect, ${wrapper} } from '@ultimat3/testing';`]
88
121
  : readImports(shape, ['expect', wrapper]);
89
122
  const repo = shape.storesRow
90
- ? `${subscribes ? `\nimport type { ${feature.pascal} } from '../entity';` : ''}\nimport * as repo from '../repo';`
123
+ ? `${subscribes ? `\nimport type { ${rowType(feature, shape)} } from '../entity';` : ''}${!live && shape.view ? `\nimport { ${feature.pascal}View } from '../entity';` : ''}\nimport * as repo from '../repo';`
91
124
  : '';
92
125
  return `// ${name.camel}: the shape it reads, the policy it asserts, and the actor it refuses. The read is
93
126
  // declarative, so what a test can get wrong is the authz, and that is what this pins.
@@ -165,7 +198,7 @@ ${wrapper}('the read is offered to no agent until its tool is described', () =>
165
198
  expect(target.kind).toBe('query');
166
199
  expect(target.mcp).toBeUndefined();
167
200
  });
168
- ${subscribes ? subscribeTest(name, feature) : ''}`;
201
+ ${subscribes ? subscribeTest(name, feature, shape) : ''}`;
169
202
  };
170
203
 
171
204
  /**
@@ -175,13 +208,13 @@ ${subscribes ? subscribeTest(name, feature) : ''}`;
175
208
  * `repo.list` — read fine there while every real subscriber was answered `X_TENANCY_UNSCOPED`.
176
209
  * Two orgs, a snapshot and a write: the window a subscriber is served from is its own org's.
177
210
  */
178
- const subscribeTest = (name: NameSet, feature: NameSet): string => `
211
+ const subscribeTest = (name: NameSet, feature: NameSet, shape: ReadShape): string => `
179
212
  // The module's own export under its own name, through \`defineApi\` as the boot hands it over, so
180
213
  // a subscribe frame naming it reaches this declaration.
181
214
  const api = defineApi({ queries: { ${name.camel} } });
182
215
  const live = api.queries.${name.camel};
183
216
 
184
- type Row = ${feature.pascal};
217
+ type Row = ${rowType(feature, shape)};
185
218
 
186
219
  const otherOrg = '${OTHER_ORG}';
187
220
 
@@ -223,10 +256,29 @@ liveTest('two orgs subscribe: each is sent its own rows and writes', async ({ su
223
256
  await theirs.settled();
224
257
  expect(ours.rows().map((row) => row.title)).toEqual(['ours too', 'ours']);
225
258
  expect(theirs.rows().map((row) => row.title)).toEqual(['theirs']);
226
- expect(theirs.patches()).toEqual([]);
259
+ expect(theirs.patches()).toEqual([]);${shape.view ? NARROWED_PATCH : ''}
227
260
  });
228
261
  `;
229
262
 
263
+ /** A patch is narrowed to the snapshot's columns (`narrowRow`): the view's, never the org's. */
264
+ const NARROWED_PATCH = `
265
+ // The patched row is narrowed to the columns the snapshot carried — the view's — so the tenant
266
+ // column a change event holds never reaches a subscriber.
267
+ for (const row of ours.rows()) expect(row).not.toHaveProperty('orgId');`;
268
+
269
+ /** The row type a read answers: the slice's view, or the row when the slice declares none. */
270
+ const rowType = (feature: NameSet, shape: ReadShape): string =>
271
+ shape.view ? `${feature.pascal}View` : feature.pascal;
272
+
273
+ /** What the stored-rows case pins about the wire: the view's keys, and never the tenant column. */
274
+ const wireShape = (feature: NameSet): string => `
275
+ // What leaves the server is the slice's view: its keys exactly, and never the tenant column — a
276
+ // column added to the entity reaches the wire only once the view lists it.
277
+ for (const row of page) {
278
+ expect(Object.keys(row).sort()).toEqual([...${feature.pascal}View.$keys].sort());
279
+ expect(row).not.toHaveProperty('orgId');
280
+ }`;
281
+
230
282
  const ORG = '00000000-0000-4000-8000-000000000002';
231
283
 
232
284
  /** The org the reader and its rows belong to — an actor's, never the read's input. */
@@ -241,6 +293,8 @@ interface ReadShape {
241
293
  readonly live: boolean;
242
294
  /** The slice still takes the row `x g entity` scaffolds, so the test may store some. */
243
295
  readonly storesRow: boolean;
296
+ /** The read answers through the slice's `<Feature>View` (`readsThroughView`). */
297
+ readonly view: boolean;
244
298
  readonly dbModule: string;
245
299
  }
246
300
 
@@ -249,7 +303,7 @@ interface ReadShape {
249
303
  * it. Three rows a second apart, a page of two — so an order that is not newest-first, a missing
250
304
  * bound and another org's row each fail it on their own.
251
305
  */
252
- const storedRowsTest = (): string => `
306
+ const storedRowsTest = (feature: NameSet, shape: ReadShape): string => `
253
307
  const otherOrg = '${OTHER_ORG}';
254
308
 
255
309
  // The request clock, so \`createdAt\` is an instant this file chose and "newest" is decidable.
@@ -275,7 +329,7 @@ unitTest('stored rows read back newest first, bounded, and never another org', a
275
329
  // The declaration's order over the repo's rows: what the SQL names on Postgres, read here
276
330
  // from the in-memory driver. A page of two is the two NEWEST, on both.
277
331
  const page = await target.as(member, { limit: 2 });
278
- expect(page.map((row) => row.title)).toEqual(['third', 'second']);
332
+ expect(page.map((row) => row.title)).toEqual(['third', 'second']);${shape.view ? wireShape(feature) : ''}
279
333
  // The same input, an actor in the other org: its own row, and nothing of this org's.
280
334
  const outsider = testActor('outsider', { orgId: otherOrg, permissions: [read] }).actor;
281
335
  const theirs = await target.as(outsider, { limit: 50 });
@@ -324,7 +378,7 @@ unitTest('the read runs as its caller: an org with no rows reads empty', async (
324
378
  // in-memory driver.
325
379
  expect(await target.as(member, { limit: 50 })).toEqual([]);
326
380
  });
327
- ${shape.storesRow ? storedRowsTest() : ''}`;
381
+ ${shape.storesRow ? storedRowsTest(feature, shape) : ''}`;
328
382
 
329
383
  /** The imports the read cases need, over whatever the file they land in already imports. */
330
384
  const readImports = (shape: ReadShape, testing: readonly string[]): readonly string[] => [
@@ -342,7 +396,7 @@ const liveReadTest = (
342
396
  shape: ReadShape,
343
397
  ): string => `// ${name.camel}, READ: what a caller gets back, through the repo and the in-memory driver. The
344
398
  // subscription — the snapshot and the patches a write produces — is the live suite's, next door.
345
- ${sortedImports([...readImports(shape, ['expect', 'unitTest']), "import { testActor } from '@ultimat3/policy';"])}${shape.storesRow ? "\nimport * as repo from '../repo';" : ''}
399
+ ${sortedImports([...readImports(shape, ['expect', 'unitTest']), "import { testActor } from '@ultimat3/policy';"])}${shape.storesRow ? `${shape.view ? `\nimport { ${feature.pascal}View } from '../entity';` : ''}\nimport * as repo from '../repo';` : ''}
346
400
  import { ${name.camel} } from './${name.kebab}';
347
401
 
348
402
  const orgId = '${ORG}';
@@ -364,21 +418,11 @@ export interface QueryOptions extends FeatureTarget {
364
418
  readonly sliceEntity?: string;
365
419
  /** The slice's `repo.ts` as it stands on disk, or absent alongside `sliceEntity`. */
366
420
  readonly sliceRepo?: string;
367
- }
368
-
369
- /**
370
- * Declared beside its one thrower, as `backfill.ts`'s twin is: the read imports the slice's own row
371
- * type and repo, and a slice declaring another table under its name has neither.
372
- */
373
- export class QuerySliceEntityError extends UltimateError {
374
- constructor(input: { readonly path: string; readonly binding: string; readonly table: string }) {
375
- super({
376
- code: 'X_QUERY_SLICE_ENTITY',
377
- cause: `x g query reads the slice's own scaffolded table, and its entity.ts declares ${input.binding} (${input.table}) instead — the generated read would import a row type and a repo that do not exist`,
378
- fix: `x queries list --json # then declare query({ sql: … from('${input.table}', …) }) by hand in ${input.path}, over ../entity's ${input.binding}`,
379
- meta: { binding: input.binding, table: input.table },
380
- });
381
- }
421
+ /**
422
+ * The slice's `policy.ts` as it stands on disk, absent when the slice has none yet (and then the
423
+ * scaffolded one is written). The read IMPORTS `can<Feature>Read` from it — `action.ts`'s reason.
424
+ */
425
+ readonly slicePolicy?: string;
382
426
  }
383
427
 
384
428
  export function queryFiles(rawName: string, target: QueryOptions): readonly GeneratedFile[] {
@@ -390,17 +434,19 @@ export function queryFiles(rawName: string, target: QueryOptions): readonly Gene
390
434
  if (foreign !== undefined) {
391
435
  throw new QuerySliceEntityError({ path: `${dir}/${name.kebab}.ts`, ...foreign });
392
436
  }
437
+ assertSliceExports(target, feature, live);
393
438
  const shape: ReadShape = {
394
439
  live,
395
440
  storesRow: sliceTakesScaffoldRow(target, target.sliceEntity, target.sliceRepo),
441
+ view: readsThroughView(feature, target.sliceEntity),
396
442
  dbModule: target.dbModule ?? PLACEHOLDER_DB_MODULE,
397
443
  };
398
444
  return [
399
445
  // A read declares the row type it returns (`../entity`), the rule that admits it (`../policy`)
400
446
  // and the one module allowed to query the table (`../repo`) — all three are the slice's, and
401
447
  // `--live` changes only which directory this file lands in.
402
- ...sliceFoundation(target, ['entity', 'policy'], target.locales),
403
- { path: `${dir}/${name.kebab}.ts`, contents: querySource(name, feature, live) },
448
+ ...withoutOwnedTests(sliceFoundation(target, ['entity', 'policy'], target.locales), target),
449
+ { path: `${dir}/${name.kebab}.ts`, contents: querySource(name, feature, live, shape.view) },
404
450
  // The suffix follows the WRAPPER, which follows `--live`: a `liveTest` in a plain
405
451
  // `<name>.test.ts` runs under `unit`, so `x test live` had no files in an app full of them.
406
452
  {
@@ -98,7 +98,7 @@ ${sortedImports([
98
98
  "import { defineRoute, Hole, island } from '@ultimat3/render';",
99
99
  "import {\n DataTable,\n type ListUrl,\n listUrl,\n Money,\n PageHeader,\n Section,\n Skeleton,\n} from '@ultimat3/ui';",
100
100
  ])}
101
- ${options.shell ? "import { Shell } from '../../shared/shell';\n" : ''}import type { ${feature.pascal} } from '../${feature.kebab}/entity';
101
+ ${options.shell ? "import { Shell } from '../../shared/shell';\n" : ''}import type { ${feature.pascal}View } from '../${feature.kebab}/entity';
102
102
  ${wrapImport([list, `${list}Sorts`], `../${feature.kebab}/live/${feature.kebab}-list`)}
103
103
  import styles from './page.module.scss';
104
104
 
@@ -108,7 +108,8 @@ const PAGE_ROWS = 50;
108
108
  /** The currency a price is typed in; the form sends integer minor units of it. */
109
109
  const CURRENCY = 'USD';
110
110
 
111
- type Row = ${feature.pascal};
111
+ /** What the slice's list query answers: its view, never the whole row (no tenant column). */
112
+ type Row = ${feature.pascal}View;
112
113
 
113
114
  /** The read's outcome as DATA, so the table renders each of its states. */
114
115
  export type PageData = AsyncState<RowPage<Row>>;
@@ -55,6 +55,8 @@ const hasMigration = (): boolean => {
55
55
  };
56
56
 
57
57
  await bun('install');
58
+ // Merge drivers live in .git/config, which no clone inherits. Outside a git checkout this is a no-op.
59
+ await x('merge-driver', 'install');
58
60
  ensureFile('.env.development.local', PER_BOX);
59
61
  if (!hasMigration()) await x('db', 'gen', 'initial');
60
62
  await x('db', 'migrate', ...process.argv.slice(2));
@@ -81,8 +81,9 @@ feature slice. Nothing else. A change outside that set is a collision — report
81
81
 
82
82
  Inspect before you change: \`bunx x entities list\`, \`bunx x entities show <name>\`, both with \`--json\`.
83
83
 
84
- Checks: \`bun test <path>/entity.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and \`bun run typecheck\`
85
- once when you are otherwise done. Never \`bunx x verify\` — that belongs to whoever coordinates you.
84
+ Checks: \`bun test <path>/entity.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and
85
+ \`bunx x verify --only typecheck\` once when you are otherwise done: it queues for the machine's memory.
86
+ Never the whole \`bunx x verify\` — that belongs to whoever coordinates you.
86
87
  `;
87
88
 
88
89
  const server = (app: NameSet): string => `---
@@ -108,8 +109,9 @@ renders. A change outside that set is a collision — report it, do not make it.
108
109
  Inspect before you change: \`bunx x actions show <name>\`, \`bunx x queries show <name>\`, \`bunx x jobs list\`,
109
110
  \`bunx x tasks list\`, \`bunx x policy explain <subject>\` — every one takes \`--json\`.
110
111
 
111
- Checks: \`bun test <path>/<file>.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and \`bun run typecheck\`
112
- once when you are otherwise done. Never \`bunx x verify\` — that belongs to whoever coordinates you.
112
+ Checks: \`bun test <path>/<file>.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and
113
+ \`bunx x verify --only typecheck\` once when you are otherwise done: it queues for the machine's memory.
114
+ Never the whole \`bunx x verify\` — that belongs to whoever coordinates you.
113
115
  `;
114
116
 
115
117
  const web = (app: NameSet): string => `---
@@ -143,8 +145,9 @@ Every one of the last five is a build error, not a preference — a guard the fr
143
145
  Inspect before you change: \`bunx x routes --json\`, \`bunx x i18n check\` for catalog gaps, and
144
146
  \`bunx x shot <route> --json\` when you need to see what you built.
145
147
 
146
- Checks: \`bun test <path>/page.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and \`bun run typecheck\`
147
- once when you are otherwise done. Never \`bunx x verify\` — that belongs to whoever coordinates you.
148
+ Checks: \`bun test <path>/page.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and
149
+ \`bunx x verify --only typecheck\` once when you are otherwise done: it queues for the machine's memory.
150
+ Never the whole \`bunx x verify\` — that belongs to whoever coordinates you.
148
151
  `;
149
152
 
150
153
  /** One agent per boundary, plus the read-only one that runs before there is a boundary to hold. */
@@ -19,6 +19,9 @@ anything — it is the short form of every rule below, and it wins where the two
19
19
  **Done means \`bun run verify\` green.** A passing unit test is not done. A working \`bunx x dev\` is not done.
20
20
  Report what you actually ran, never what you assume passed.
21
21
 
22
+ **Given a file set, you are a worker:** skip the gate, the coordinator runs it once. Run
23
+ \`bun test ./<file>\`, \`bunx x test --filter <path>\`, and \`bunx x verify --only typecheck\` once at the end.
24
+
22
25
  ## Request
23
26
  $ARGUMENTS
24
27
 
@@ -101,7 +104,7 @@ While you iterate, narrow the *feedback*, not the gate:
101
104
  | a whole type | \`bunx x test unit\` · \`bunx x test contract\` · \`bunx x test e2e\` |
102
105
  | one gate step | \`bunx x verify --only <step> --json\` — \`NOT A GATE RUN\` |
103
106
  | lint the files you touched | \`bunx @biomejs/biome check --write <paths>\` |
104
- | types, once, when otherwise done | \`bun run typecheck\` |
107
+ | types, once, when otherwise done | \`bunx x verify --only typecheck\` — queues for the machine's memory |
105
108
  | a broken environment | \`bunx x doctor\` |
106
109
 
107
110
  ## 5. Hard rules
@@ -206,6 +209,9 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash
206
209
 
207
210
  Run \`bun run verify\`.
208
211
 
212
+ **Given a file set, do not:** the coordinator runs the gate once. Run your own files
213
+ (\`bun test ./<file>\`, \`bunx x test --filter <path>\`) and report.
214
+
209
215
  It is \`bunx x verify\`, and it is THE gate — the one CI runs (\`.github/workflows/ci.yml\`) and the
210
216
  one \`README.md\` names. Its \`budgets\` step builds what it weighs, so nothing runs before it.
211
217
 
@@ -26,12 +26,12 @@ const settings = (): string => `{
26
26
  "allow": [
27
27
  "Bash(bun install)",
28
28
  "Bash(bun test:*)",
29
- "Bash(bun run typecheck)",
30
- "Bash(bun run lint)",
31
29
  "Bash(bun run verify:*)",
32
30
  "Bash(bunx @biomejs/biome check:*)",
33
31
  "Bash(bunx x verify:*)",
34
32
  "Bash(bunx x test:*)",
33
+ "Bash(bunx x heavy:*)",
34
+ "Bash(bunx x stop:*)",
35
35
  "Bash(bunx x doctor:*)",
36
36
  "Bash(bunx x g:*)",
37
37
  "Bash(bunx x routes:*)",
@@ -133,8 +133,8 @@ with the command that re-checks the file, instead of surfacing later as a red \`
133
133
 
134
134
  It is not a typecheck, because a *scoped* one does not exist: \`tsc\` needs the project, and even
135
135
  \`bunx x verify --only typecheck\` checks the whole tree — and says \`NOT A GATE RUN\`, because green
136
- means the run with no flag. There is no \`--skip\`. If you want types on every edit, \`bun run typecheck\`
137
- is the whole project and you are choosing to pay for it.
136
+ means the run with no flag. There is no \`--skip\`. Run it once, when the work is otherwise done: it
137
+ queues for the machine's memory, which \`bun run typecheck\` does not.
138
138
 
139
139
  ## Where the rules live
140
140
 
@@ -5,6 +5,10 @@
5
5
  import type { NameSet } from './naming';
6
6
  import { RUNTIME_UID } from './scaffold-helm';
7
7
 
8
+ /** The compose database: the tag and its multi-arch index digest, as `docker/*.yml` pin theirs. */
9
+ export const POSTGRES_IMAGE =
10
+ 'postgres:18-alpine@sha256:ff64c9e3bdf8e2120107d3559de8db314e8305f7e38c5105903c6295876738ff';
11
+
8
12
  /**
9
13
  * The production env file, relative to the app root. Named once because two readers must agree:
10
14
  * the compose file's \`env_file:\` (what the containers see) and \`x deploy\`'s \`--env-file\` (what
@@ -12,6 +16,13 @@ import { RUNTIME_UID } from './scaffold-helm';
12
16
  */
13
17
  export const PROD_ENV_FILE = '.env.production';
14
18
 
19
+ /**
20
+ * A compose interpolation, `${expr}` in the written file: one `$`, which compose reads (its `$$` is
21
+ * a literal `$`). Never `\${` in the template below: CodeQL reads that escape as a regex one
22
+ * (js/useless-regexp-character-escape), and the bytes are the same.
23
+ */
24
+ const composeVar = (expr: string): string => `${'$'}{${expr}}`;
25
+
15
26
  /** The production topology `x new` writes at `docker/docker-compose.prod.yml`. */
16
27
  export const composeProdFile = (
17
28
  app: NameSet,
@@ -22,7 +33,7 @@ export const composeProdFile = (
22
33
  #
23
34
  # ${PROD_ENV_FILE} first: \`x env init --production\` writes every value below with fresh secrets.
24
35
  #
25
- # By hand, always with \`--env-file ${PROD_ENV_FILE}\`: Compose fills \`\${VAR:?…}\` below from the shell
36
+ # By hand, always with \`--env-file ${PROD_ENV_FILE}\`: Compose fills \`${composeVar('VAR:?…')}\` below from the shell
26
37
  # and \`--env-file\` only, NEVER from \`env_file:\`, so without it a value set only in that file is
27
38
  # "missing" and the parse fails. \`x deploy\` passes it on every step.
28
39
  #
@@ -38,6 +49,14 @@ export const composeProdFile = (
38
49
  # file, is the chart \`x deploy --method helm\` installs. To scale them on one box anyway, drop
39
50
  # \`ports:\` and put your own proxy on this network — the service name resolves to every replica
40
51
  # over the compose DNS round robin.
52
+ #
53
+ # \`cpus:\` is the knob \`ULTIMATE_PROCESSES=auto\` (the default) reads: K whole cores run K processes
54
+ # of the role on one port; no \`cpus:\` runs one. Most of a request's wall time is I/O wait, so the
55
+ # budgets are modest: raise a role's \`cpus\` when its process sits above ~70% of one core. Memory
56
+ # is 256 MiB per process plus headroom; jobs.concurrency, jobs.maxInFlight and DATABASE_POOL_MAX
57
+ # are per CONTAINER, split across its processes. \`net.ipv4.tcp_migrate_req\` is a commented opt-in
58
+ # on web and sync, never active: a kernel older than Linux 5.14 has no such knob, and Docker then
59
+ # refuses to create the container at all.
41
60
  name: ${app.kebab}
42
61
 
43
62
  # Every service's logs, rotated. Docker's default json-file driver never rotates, so a chatty role
@@ -47,10 +66,13 @@ x-logging: &logging
47
66
  options: { max-size: 10m, max-file: '3' }
48
67
 
49
68
  x-image: &image
50
- image: \${IMAGE:-${app.kebab}:dev}
69
+ image: ${composeVar(`IMAGE:-${app.kebab}:dev`)}
51
70
  env_file: [../${PROD_ENV_FILE}]
52
71
  restart: unless-stopped
53
72
  logging: *logging
73
+ # An init as PID 1: Bun as PID 1 never reaps an orphaned grandchild, and ignores SIGTERM until a
74
+ # handler is installed, so \`docker stop\` waited out the grace and SIGKILLed.
75
+ init: true
54
76
  # SIGTERM → /readyz answers 503 for the readiness grace (5s outside local environments), then the
55
77
  # drain of in-flight requests, jobs and sockets (25s). 40s leaves 10s before Docker SIGKILLs.
56
78
  stop_grace_period: 40s
@@ -88,10 +110,12 @@ x-run-once-probe: &run-once-probe
88
110
  services:
89
111
  db:
90
112
  # Postgres 18 images keep the cluster under /var/lib/postgresql/18/docker, so the volume is the
91
- # parent — mounted at .../data, as for 17, the image refuses to start.
92
- image: postgres:18-alpine
113
+ # parent — mounted at .../data, as for 17, the image refuses to start. Pinned by digest: a tag
114
+ # is whatever the registry serves on the day this box pulls. To move it, read the new one with
115
+ # \`docker buildx imagetools inspect postgres:18-alpine\` and take a backup first.
116
+ image: ${POSTGRES_IMAGE}
93
117
  environment:
94
- POSTGRES_PASSWORD: \${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
118
+ POSTGRES_PASSWORD: ${composeVar('POSTGRES_PASSWORD:?set POSTGRES_PASSWORD')}
95
119
  POSTGRES_DB: ${app.kebab}
96
120
  volumes: ['pgdata:/var/lib/postgresql']
97
121
  healthcheck:
@@ -99,6 +123,7 @@ services:
99
123
  interval: 5s
100
124
  restart: unless-stopped
101
125
  logging: *logging
126
+ init: true
102
127
 
103
128
  # The release phase. Applies pending migrations under an advisory lock and exits; every serving
104
129
  # role waits for it to complete, so no replica ever serves against a schema it does not ship.
@@ -133,12 +158,19 @@ services:
133
158
  <<: *image
134
159
  # The page dials SYNC_URL; unset, it dials /_x/sync on :3000, which web does not serve here.
135
160
  # Set it in ${PROD_ENV_FILE}: \`--env-file\` (header) is what lets this line read it there.
136
- environment: [ROLE=web, 'SYNC_URL=\${SYNC_URL:?set SYNC_URL=ws://<host>:3001/_x/sync, see wiki/Deployment.md}']
161
+ environment: [ROLE=web, 'SYNC_URL=${composeVar('SYNC_URL:?set SYNC_URL=ws://<host>:3001/_x/sync, see wiki/Deployment.md')}']
137
162
  depends_on:
138
163
  db: { condition: service_healthy }
139
164
  migrate: { condition: service_completed_successfully }
140
165
  deploy: { replicas: 1 } # stateless, scales on RPS — pinned by the published port
141
166
  ports: ['3000:3000']
167
+ # Two processes on one port; 2 x 256 MiB plus headroom fits in the anchor's 1g.
168
+ cpus: '2'
169
+ # Opt-in, Linux >= 5.14 only (Docker refuses to create the container on an older kernel —
170
+ # RHEL 8, Ubuntu 20.04, Amazon Linux 2). With more than one process here, a stopping process's
171
+ # queued connections move to a sibling instead of being reset: 93-109 of 200 reset without it,
172
+ # 0 with it. \`x doctor\` warns when the knob exists, reads 0 and N > 1.
173
+ # sysctls: { net.ipv4.tcp_migrate_req: 1 }
142
174
 
143
175
  sync:
144
176
  <<: *image
@@ -146,7 +178,7 @@ services:
146
178
  # APP_URL's origin and no other once declared (scheme, host and port, exactly); undeclared, from
147
179
  # the origin it was reached on. Unset, every websocket is 403 X_SOCKET_ORIGIN_REFUSED, so it is
148
180
  # required: the same value web builds its links from.
149
- environment: [ROLE=sync, 'APP_URL=\${APP_URL:?set APP_URL=http://<host>:3000 — the origin the pages are served on, see wiki/Deployment.md}']
181
+ environment: [ROLE=sync, 'APP_URL=${composeVar('APP_URL:?set APP_URL=http://<host>:3000 — the origin the pages are served on, see wiki/Deployment.md')}']
150
182
  depends_on:
151
183
  db: { condition: service_healthy }
152
184
  migrate: { condition: service_completed_successfully }
@@ -159,6 +191,10 @@ services:
159
191
  deploy: { replicas: 0 } # when on: scales on concurrent websockets — pinned to 1 by the port
160
192
  # The sync role binds PORT + 1. PORT is unset here, so it is 3000 and this listens on 3001.
161
193
  ports: ['3001:3001']
194
+ # One process; a second needs NATS_URL. With a second, the opt-in below (Linux >= 5.14 only, as
195
+ # on web) keeps a stopping process's queued sockets instead of resetting them.
196
+ cpus: '1'
197
+ # sysctls: { net.ipv4.tcp_migrate_req: 1 }
162
198
  # ...which is why the image's own HEALTHCHECK cannot be inherited here. It fetches $PORT —
163
199
  # 3000 — and this role never binds it, so the container reports \`unhealthy\` from
164
200
  # \`start_period\` onward and never recovers, and anything gated on \`sync: service_healthy\`
@@ -180,6 +216,9 @@ services:
180
216
  migrate: { condition: service_completed_successfully }
181
217
  healthcheck: *metrics-probe
182
218
  deploy: { replicas: 1 } # scales on queue depth
219
+ # One process per replica. CPU-heavy queues raise it: a synchronous handler blocks every job in
220
+ # its process and their lease renewals.
221
+ cpus: '1'
183
222
 
184
223
  scheduler:
185
224
  <<: *image
@@ -193,6 +232,7 @@ services:
193
232
  # holds one. A second instance is harmless but idle.
194
233
  healthcheck: *metrics-probe
195
234
  deploy: { replicas: 1 }
235
+ cpus: '0.5' # always one process: a small budget
196
236
 
197
237
  volumes:
198
238
  pgdata:
@@ -23,7 +23,7 @@ import { testServicesFiles } from './scaffold-test-services';
23
23
  */
24
24
  const conventions = (app: NameSet): string => `# ${app.pascal}
25
25
 
26
- Human-authored, short, stable — one file under two names, \`AGENTS.md\` being a symlink to it.
26
+ One file, two names: \`AGENTS.md\` is a symlink to it.
27
27
  Facts live in \`x.manifest.json\`; this file holds only what an agent cannot infer from the code.
28
28
 
29
29
  Every row below names what refuses it. A rule with nothing in the last column does not exist.
@@ -40,6 +40,7 @@ queries, jobs, MCP tools, published operations and tests it touches, each with p
40
40
  |---|---|---|
41
41
  | One gate | \`bun run verify\` — \`bunx x verify\`, which builds what its \`budgets\` step weighs. Green means shippable; never merge red. CI runs the same gate, cut into parts: \`bun run verify plan --json\` names them, each runner runs \`bun run setup && bun run verify --only <steps>\`, and \`bun run verify merge\` is the verdict | the gate itself, and \`.github/workflows/ci.yml\` on every push and pull request; \`.github/workflows/image.yml\` publishes only a commit it passed |
42
42
  | Coverage | the unit suite covers 95% of the lines and functions of this app's own source — every file under \`apps/\` and \`packages/\`, one no test loads counted at 0%. A floor, not the goal: a test added to raise it is proven by mutation — break the source, watch it go red, restore | \`X_COVERAGE_BELOW_FLOOR\` on the \`unit\` step; \`coverage\` in \`x.verify.json\` states the floor, and it only rises |
43
+ | Many agents | a worker: \`bun test ./<file>\`, \`bunx x test --filter <path>\`; the coordinator: the gate, once | review |
43
44
  | One way | generators, not hand-rolled files: \`bunx x g resource\`, \`bunx x g action\`, \`bunx x g route\` | review |
44
45
  | Surfaces | \`site/\` is 0kb JS and may not import \`app/\`; \`shared/\` is a leaf | \`X_BOUNDARY_SITE_TO_APP\` |
45
46
  | Data | routes call actions and queries; only \`repo.ts\` touches the database | \`X_BOUNDARY_ROUTE_TO_DB\` |
@@ -134,11 +135,11 @@ Commands: \`bun run setup\`, \`bun run dev\`, \`bun run verify\`, \`bunx x g <pr
134
135
  | Tool | What it answers | How to reach it |
135
136
  |---|---|---|
136
137
  | \`x.manifest.json\` | every route, action, query, job and policy, generated — read it before searching the tree | \`bunx x manifest\` rewrites it |
137
- | \`bunx x impact <file|primitive> --json\` · \`bunx x graph --json\` | what an edit reaches, and the app as one graph (declared, import and observed edges) | rebuilt from the loaded app on every call |
138
+ | \`bunx x impact <file|primitive> --json\` · \`bunx x graph --json\` | what an edit reaches, and the app as one graph (declared, import and observed edges) | rebuilt on every call |
138
139
  | \`.mcp.json\` | the dev tools over MCP: routes, schema, policies, the database, tests, the gate — \`bunx x mcp tools\` lists them | a client that reads \`.mcp.json\` starts it; from any other, run \`bunx @ultimat3/cli mcp serve --transport stdio\` here |
139
140
  | \`POST /mcp\` | this app's own tools — every action declaring \`mcp: { expose: true }\` — for a remote agent | \`apps/web/mcp.ts\`; under \`bun run dev\`, \`Authorization: Bearer dev-agent.admin\`, else an API key |
140
- | \`.claude/commands/feature.md\` | build or fix one thing end to end, done when \`bun run verify\` is green | plain markdown: any agent can read one and follow it |
141
- | \`.claude/commands/planx.md\` | write a plan to \`docs/plans/\` for another agent to execute | the same |
141
+ | \`.claude/commands/feature.md\` | build or fix one thing end to end, done when \`bun run verify\` is green | plain markdown any agent can follow |
142
+ | \`.claude/commands/planx.md\` | write a plan to \`docs/plans/\` | the same |
142
143
  | \`.claude/commands/verify.md\` | run the gate and fix what it reports | the same |
143
144
 
144
145
  Project notes for ${app.kebab}: replace this line with the conventions a newcomer could not guess.
@@ -169,6 +170,10 @@ bun run verify
169
170
  \`x db gen "initial"\` for you on a fresh clone. Until it has, \`x verify\`'s \`drift\` step is red
170
171
  with \`X_DB_DRIFT\`, and that is the fix it names.
171
172
 
173
+ **Merging two features:** two branches' \`x g\` output merges with no hand edit once \`bun run setup\`
174
+ has run (\`x merge-driver install\`). After the merge run \`bunx x manifest\`. A conflict that remains
175
+ (\`git diff --name-only --diff-filter=U\`) is a real one: both branches changed the same existing line.
176
+
172
177
  ## 🗺 Layout
173
178
 
174
179
  | Path | Holds |
@@ -238,7 +243,7 @@ volumes:
238
243
  `;
239
244
 
240
245
  /** Docs, shims and container files for a new app, in the order a reader meets them. */
241
- export function docsFiles(app: NameSet): readonly GeneratedFile[] {
246
+ export function docsFiles(app: NameSet, root?: string): readonly GeneratedFile[] {
242
247
  return [
243
248
  { path: 'README.md', contents: readme(app) },
244
249
  { path: 'CLAUDE.md', contents: conventions(app) },
@@ -251,7 +256,7 @@ export function docsFiles(app: NameSet): readonly GeneratedFile[] {
251
256
  ...binFiles(),
252
257
  { path: 'docker/docker-compose.dev.yml', contents: composeDev(app) },
253
258
  // What the suites run against — in RAM, silent; ci.yml starts it before the gate.
254
- ...testServicesFiles(app),
259
+ ...testServicesFiles(app, root),
255
260
  // The harness half of the same job AGENTS.md does. It lands in the app's own repo rather than
256
261
  // in a global config, so it is visible in the scaffold's diff and deletable in one line.
257
262
  ...claudeFiles(app),
@@ -46,8 +46,25 @@ export const LINE_ENDING_ATTRIBUTES = `# Every text file is LF, in the index and
46
46
  ${BINARY_EXTENSIONS.map((extension) => `*.${extension} binary`).join('\n')}
47
47
  `;
48
48
 
49
- /** The app's root file: the shared block, then the app's one generated file git should collapse. */
49
+ /**
50
+ * How two branches' features merge. `bunx x merge-driver install` (a step of `bun run setup`) defines
51
+ * the drivers in `.git/config`; a clone without them gets git's ordinary text merge, so nothing here
52
+ * can lose work. Also carried into existing apps by the `merge-drivers` codemod.
53
+ */
54
+ export const MERGE_ATTRIBUTES = `# Merging two features. x-registry keeps what both branches added and leaves a real conflict alone;
55
+ # x-generated keeps our copy of a projection, which \`bunx x manifest\` then rebuilds.
56
+ apps/web/api/index.ts merge=x-registry
57
+ apps/web/exercise.ts merge=x-registry
58
+ apps/web/shared/roles.ts merge=x-registry
59
+ packages/db/src/client.ts merge=x-registry
60
+ packages/i18n/catalogs/*.json merge=x-registry
61
+ x.manifest.json merge=x-generated
62
+ openapi.json merge=x-generated
63
+ `;
64
+
65
+ /** The app's root file: the shared block, the merge rules, the generated file git should collapse. */
50
66
  export const rootGitattributes = (): string => `${LINE_ENDING_ATTRIBUTES}
67
+ ${MERGE_ATTRIBUTES}
51
68
  # Bun's lockfile. Regenerated by \`bun install\`, never edited by hand.
52
69
  bun.lock -diff linguist-generated=true
53
70
  `;
@@ -86,6 +86,15 @@ nobody bound. Derived here rather than stated twice in values.yaml, where the tw
86
86
  value: {{ $root.Values.metricsPort | quote }}
87
87
  {{- end }}
88
88
  {{- /*
89
+ One process per pod: per-pod parallelism is the HPA's. This chart sets CPU requests only, so
90
+ auto already resolves to 1; the pin makes the count explicit, and a CPU limit added later
91
+ cannot change it. env.ULTIMATE_PROCESSES wins when set.
92
+ */}}
93
+ {{- if not (hasKey $root.Values.env "ULTIMATE_PROCESSES") }}
94
+ - name: ULTIMATE_PROCESSES
95
+ value: "1"
96
+ {{- end }}
97
+ {{- /*
89
98
  The sync node's page origin, from the one place this chart already knows it. Undeclared, a node
90
99
  reached over plain http behind this Ingress admits BOTH spellings of its host — the plain-http
91
100
  page included. env.APP_URL wins when set; an APP_URL kept in the Secret is shadowed for this
@@ -107,6 +107,7 @@ const rootPackage = (app: NameSet, version: string): string => `{
107
107
  "@ultimat3/policy": "${version}",
108
108
  "@ultimat3/pwa": "${version}",
109
109
  "@ultimat3/query": "${version}",
110
+ "@ultimat3/realtime": "${version}",
110
111
  "@ultimat3/render": "${version}",
111
112
  "@ultimat3/schema": "${version}",
112
113
  "@ultimat3/seo": "${version}",
@@ -384,9 +385,11 @@ export function repoFiles(
384
385
  app: NameSet,
385
386
  version: string,
386
387
  example: boolean,
388
+ /** The app's directory, when known: the test stack's name and ports (`scaffold-test-services`). */
389
+ root?: string,
387
390
  ): readonly GeneratedFile[] {
388
391
  return [
389
- ...docsFiles(app),
392
+ ...docsFiles(app, root),
390
393
  { path: 'package.json', contents: rootPackage(app, version) },
391
394
  { path: 'tsconfig.json', contents: rootTsconfig(app) },
392
395
  { path: 'biome.json', contents: biome() },