@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
@@ -0,0 +1,110 @@
1
+ // The four registries every generated feature adds to, held one entry per line. Two branches that
2
+ // each add a feature then touch different lines, so `x merge-driver` can keep both; a list on one
3
+ // line is the same line changed twice, which no merge can tell from a real disagreement. `x new`
4
+ // writes this shape and the `registry-lines` codemod carries an existing app to it.
5
+
6
+ import { stripComments } from '@ultimat3/core';
7
+ import { apiListsOf, insertApiList } from './api-registration';
8
+ import { API_INDEX } from './app-root';
9
+ import { declarationLists } from './generate-grants';
10
+ import { ROLES_FILE } from './permission-grants';
11
+ import { maskOf, readList, readProperties } from './source-list-edit';
12
+ import { HANDLE_FILE } from './templates/scaffold-db-client';
13
+
14
+ const EXERCISE_FILE = 'apps/web/exercise.ts';
15
+
16
+ /** Inside the bracket, it is also what keeps Biome from joining the list back onto one line. */
17
+ export const REGISTRY_LINE_COMMENT =
18
+ '// One entry per line: branches that each add one merge cleanly (x merge-driver).';
19
+
20
+ /** Every file `withRegistryLines` holds to the shape. */
21
+ export const REGISTRY_FILES: readonly string[] = [
22
+ API_INDEX,
23
+ ROLES_FILE,
24
+ EXERCISE_FILE,
25
+ HANDLE_FILE,
26
+ ];
27
+
28
+ const API_LISTS = ['actions', 'queries', 'jobs', 'tasks'] as const;
29
+
30
+ const indentAt = (source: string, at: number): string =>
31
+ /^[ \t]*/.exec(source.slice(source.lastIndexOf('\n', at) + 1))?.[0] ?? '';
32
+
33
+ const startsItsLine = (source: string, at: number): boolean =>
34
+ source.slice(source.lastIndexOf('\n', at - 1) + 1, at).trim() === '';
35
+
36
+ /**
37
+ * The list opening at `open`, a row per entry under the comment. A list this cannot restate
38
+ * without moving the author's text — a comment beside entries on one line, two entries sharing a
39
+ * row — is left as it is: it still works, it just merges by hand.
40
+ */
41
+ export function listWithLines(source: string, open: number): string {
42
+ const list = readList(source, maskOf(source), open);
43
+ if (list === undefined) return source;
44
+ const span = source.slice(list.open, list.close + 1);
45
+ if (span.includes(REGISTRY_LINE_COMMENT)) return source;
46
+ const indent = indentAt(source, open);
47
+ const comment = `${indent} ${REGISTRY_LINE_COMMENT}`;
48
+ if (span.includes('\n')) {
49
+ const lineEnd = source.indexOf('\n', open);
50
+ const opensAlone = source.slice(open + 1, lineEnd).trim() === '';
51
+ if (!opensAlone || list.entries.some((entry) => !startsItsLine(source, entry.start))) {
52
+ return source;
53
+ }
54
+ return `${source.slice(0, lineEnd + 1)}${comment}\n${source.slice(lineEnd + 1)}`;
55
+ }
56
+ if (stripComments(source).slice(list.open, list.close + 1) !== span) return source;
57
+ const rows = list.entries.map((entry) => `${indent} ${entry.text},\n`).join('');
58
+ const bracket = source[list.close] as string;
59
+ const body = `${source[open] as string}\n${comment}\n${rows}${indent}${bracket}`;
60
+ return `${source.slice(0, open)}${body}${source.slice(list.close + 1)}`;
61
+ }
62
+
63
+ function apiWithLines(source: string): string {
64
+ let next = source;
65
+ for (const key of API_LISTS) {
66
+ // A list every branch can add to exists before either does: two branches each creating
67
+ // `tasks:` is one key written twice, the one shape no line merge can keep.
68
+ next = apiListsOf(next)?.(key) === undefined ? (insertApiList(next, key, '[]') ?? next) : next;
69
+ const list = apiListsOf(next)?.(key);
70
+ if (list !== undefined) next = listWithLines(next, list.open);
71
+ }
72
+ return next;
73
+ }
74
+
75
+ /** Applied from the last list back, so an edit never moves an offset still to be used. */
76
+ const eachFromLast = (source: string, opens: readonly number[]): string =>
77
+ [...opens].sort((a, b) => b - a).reduce(listWithLines, source);
78
+
79
+ function grantLists(source: string): readonly number[] {
80
+ const masked = maskOf(source);
81
+ const call = /\bdefineRoles\(\s*\{/.exec(masked);
82
+ if (call === null) return [];
83
+ return readProperties(source, masked, call.index + call[0].length - 1).flatMap((role) => {
84
+ if (masked[role.value] !== '{') return [];
85
+ const grants = readProperties(source, masked, role.value).find((p) => p.key === 'grants');
86
+ return grants !== undefined && masked[grants.value] === '[' ? [grants.value] : [];
87
+ });
88
+ }
89
+
90
+ const rolesWithLines = (source: string): string =>
91
+ eachFromLast(source, [...declarationLists(maskOf(source)), ...grantLists(source)]);
92
+
93
+ /** An EMPTY object only: a filled one is already a row per entry, which Biome keeps. */
94
+ function emptyObjectWithLines(source: string, opening: RegExp): string {
95
+ const masked = maskOf(source);
96
+ const found = opening.exec(masked);
97
+ if (found === null) return source;
98
+ const open = found.index + found[0].length - 1;
99
+ const list = readList(source, masked, open);
100
+ return list?.entries.length === 0 ? listWithLines(source, open) : source;
101
+ }
102
+
103
+ /** `source`, the registry at `path`, in the one-entry-per-line shape. Any other path: unchanged. */
104
+ export function withRegistryLines(path: string, source: string): string {
105
+ if (path === API_INDEX) return apiWithLines(source);
106
+ if (path === ROLES_FILE) return rolesWithLines(source);
107
+ if (path === EXERCISE_FILE) return emptyObjectWithLines(source, /\bdefineExercise\(\s*\{/);
108
+ if (path === HANDLE_FILE) return emptyObjectWithLines(source, /\bconst entities\s*=\s*\{/);
109
+ return source;
110
+ }
package/src/registry.ts CHANGED
@@ -27,6 +27,7 @@ import { explainSpec } from './cmd-explain-spec';
27
27
  import { fixSpec } from './cmd-fix-spec';
28
28
  import { generateSpec } from './cmd-generate-spec';
29
29
  import { graphSpec } from './cmd-graph-spec';
30
+ import { heavySpec } from './cmd-heavy-spec';
30
31
  import { profileSpec } from './cmd-profile-spec';
31
32
  // Registered here, not by whichever command body happens to load: `dispatch` renders a CLI code's
32
33
  // title for a refusal raised before any body is imported.
@@ -39,6 +40,7 @@ import { logsSpec } from './cmd-logs-spec';
39
40
  import { mailSpec } from './cmd-mail-spec';
40
41
  import { manifestSpec } from './cmd-manifest-spec';
41
42
  import { mcpSpec } from './cmd-mcp-spec';
43
+ import { mergeDriverSpec } from './cmd-merge-driver-spec';
42
44
  import { newSpec } from './cmd-new-spec';
43
45
  import { policySpec } from './cmd-policy-spec';
44
46
  import { prSpec } from './cmd-pr-spec';
@@ -132,12 +134,14 @@ export const LAZY_COMMANDS: readonly LazyCommand[] = [
132
134
  lazy(graphSpec, async () => (await import('./cmd-graph')).graphCommand),
133
135
  lazy(impactSpec, async () => (await import('./cmd-impact')).impactCommand),
134
136
  lazy(tokenSpec, async () => (await import('./cmd-token')).tokenCommand),
137
+ lazy(mergeDriverSpec, async () => (await import('./cmd-merge-driver')).mergeDriverCommand),
135
138
  lazy(configSpec, async () => (await import('./cmd-config')).configCommand),
136
139
  lazy(logsSpec, async () => (await import('./cmd-logs')).logsCommand),
137
140
  lazy(cacheSpec, async () => (await import('./cmd-cache')).cacheCommand),
138
141
  lazy(explainSpec, async () => (await import('./cmd-explain')).explainCommand),
139
142
  lazy(profileSpec, async () => (await import('./cmd-profile')).profileCommand),
140
143
  lazy(statusSpec, async () => (await import('./cmd-status')).statusCommand),
144
+ lazy(heavySpec, async () => (await import('./cmd-heavy')).heavyCommand),
141
145
  ];
142
146
 
143
147
  export const COMMANDS: readonly CliCommand[] = [
@@ -11,7 +11,7 @@ export function retainUnsweptFinding(entity: string): Finding {
11
11
  return {
12
12
  code: 'X_ENTITY_RETAIN_UNSWEPT',
13
13
  cause: `entity "${entity}" declares retain, and no purge() registered in this app sweeps it — rows past its window are kept forever`,
14
- fix: "export const retention = purge({ entities: 'declared' }) — in a jobs module named in jobs: [...] in apps/web/api/index.ts, then x verify",
14
+ fix: "export const retention = purge({ entities: 'declared' }) — in a jobs module named in jobs: [...] in apps/web/api/index.ts, then x manifest",
15
15
  at: 'apps/web/api/index.ts',
16
16
  };
17
17
  }
@@ -20,6 +20,7 @@ import {
20
20
  } from '@ultimat3/realtime/server';
21
21
  import { BadFlagError } from './errors';
22
22
  import type { DevServices, Env } from './runtime-bindings';
23
+ import { envWithAppTls } from './runtime-database-ssl';
23
24
 
24
25
  export interface StartReplicatorOptions {
25
26
  readonly services: DevServices;
@@ -69,7 +70,8 @@ const embeddedRefusal = (dev: boolean): BadFlagError | ConfigInvalidError =>
69
70
  });
70
71
 
71
72
  /**
72
- * The relations the feed decodes: every registered entity's PHYSICAL TABLE, never its name.
73
+ * The relations the feed decodes: every registered entity's PHYSICAL TABLE, never its name, and
74
+ * never a view's — a view writes no WAL of its own, and Postgres refuses one in a publication.
73
75
  *
74
76
  * Both readers of this list are catalog readers. `PgReplicationStream` keeps a change only when
75
77
  * `#entities.has(relation.name)`, and a pgoutput Relation message names the table; `warnPartialIdentity`
@@ -83,7 +85,8 @@ const embeddedRefusal = (dev: boolean): BadFlagError | ConfigInvalidError =>
83
85
  * feed the same list whatever order it was registered in.
84
86
  */
85
87
  export function replicatedRelations(): readonly string[] {
86
- return [...new Set(describeEntities().map((entity) => entity.table))].sort();
88
+ const tables = describeEntities().filter((entity) => entity.view === undefined);
89
+ return [...new Set(tables.map((entity) => entity.table))].sort();
87
90
  }
88
91
 
89
92
  /**
@@ -92,7 +95,7 @@ export function replicatedRelations(): readonly string[] {
92
95
  * list came from the app's own registry, so it can name the command that adds to it.
93
96
  */
94
97
  const NO_ENTITIES =
95
- 'no entities are registered, so the replicator would decode changes nothing matches';
98
+ 'no entity on a table is registered, so the replicator would decode changes nothing matches';
96
99
 
97
100
  const noEntitiesRefusal = (dev: boolean): BadFlagError | ConfigInvalidError =>
98
101
  dev
@@ -179,7 +182,9 @@ export async function startReplicator(options: StartReplicatorOptions): Promise<
179
182
  const entities = replicatedRelations();
180
183
  if (entities.length === 0) throw noEntitiesRefusal(options.dev);
181
184
 
182
- const selection = selectChangeFeed(options.env, { entities });
185
+ // `database.ssl` reaches this session too: it dials from the env, never through `startDb`.
186
+ const env = await envWithAppTls(options.services.root, options.env);
187
+ const selection = selectChangeFeed(env, { entities });
183
188
  const slot = selection.slot ?? '';
184
189
  const key = replicatorLockKey(slot);
185
190
  const heartbeat = loopHeartbeat('realtime.replicator', {
@@ -0,0 +1,86 @@
1
+ // `x dev --role`: which roles one dev process runs. Every value that is not a runnable selection
2
+ // is a flag error carrying the working invocation, never a silently narrowed or empty set.
3
+
4
+ import type { AppConfig, Role } from '@ultimat3/core';
5
+ import { ConfigInvalidError, isRole, logger, ROLES } from '@ultimat3/core';
6
+ import { BadFlagError } from './errors';
7
+ import { DEV_ROLES } from './role-start-types';
8
+ import { roleDeclared } from './serve-env';
9
+ import { quoteArg } from './shell-quote';
10
+
11
+ /**
12
+ * What `--role` accepts. The replicator is here but not in `DEV_ROLES`: opt-in, because it takes
13
+ * the one replication slot a database has, and a default that did that would mean two developers
14
+ * pointed at one staging database silently fighting over it.
15
+ */
16
+ export const SELECTABLE_ROLES: readonly Role[] = [...DEV_ROLES, 'replicator'];
17
+
18
+ /**
19
+ * `--role web,worker` picks a subset. An unknown or out-of-scope role is a flag error with the
20
+ * working invocation in the fix line, never a silently ignored value — which is what it was.
21
+ */
22
+ export function selectRoles(flag: string | undefined): readonly Role[] {
23
+ if (flag === undefined || flag.trim().length === 0) return DEV_ROLES;
24
+ const wanted = flag
25
+ .split(',')
26
+ .map((part) => part.trim())
27
+ .filter((part) => part.length > 0);
28
+ // `--role ,` names nothing: read as "no roles" it booted an `x dev` that served nothing.
29
+ if (wanted.length === 0) {
30
+ throw new BadFlagError({
31
+ flag: 'role',
32
+ command: 'dev',
33
+ reason: `it names no role (one or more of: ${SELECTABLE_ROLES.join(', ')})`,
34
+ fix: `x dev --role ${quoteArg(DEV_ROLES.join(','))}`,
35
+ });
36
+ }
37
+ const selected: Role[] = [];
38
+ for (const name of wanted) {
39
+ if (!isRole(name)) {
40
+ throw new BadFlagError({
41
+ flag: 'role',
42
+ command: 'dev',
43
+ reason: `"${name}" is not a role (known: ${ROLES.join(', ')})`,
44
+ fix: `x dev --role ${quoteArg(DEV_ROLES.join(','))}`,
45
+ });
46
+ }
47
+ if (!SELECTABLE_ROLES.includes(name)) {
48
+ throw new BadFlagError({
49
+ flag: 'role',
50
+ command: 'dev',
51
+ reason: `"${name}" does not run under x dev (it runs once, as \`x db migrate\`)`,
52
+ fix: `x dev --role ${quoteArg(DEV_ROLES.join(','))}`,
53
+ });
54
+ }
55
+ if (!selected.includes(name)) selected.push(name);
56
+ }
57
+ return SELECTABLE_ROLES.filter((role) => selected.includes(role));
58
+ }
59
+
60
+ /**
61
+ * The selection narrowed to the roles `app.config.ts` declares — the rule the container's `ROLE` is
62
+ * refused by (`roleDeclared`, `serve-env.ts`), so dev never fires a cron task, or binds a sync
63
+ * node, that the deploy will not run. What it drops is named in one line; a selection of nothing
64
+ * BUT undeclared roles is refused, as `rolesUnderRealtime` refuses one that would serve nothing.
65
+ */
66
+ export function rolesDeclaredForDev(
67
+ selected: readonly Role[],
68
+ config: AppConfig | undefined,
69
+ ): readonly Role[] {
70
+ const kept = selected.filter((role) => roleDeclared(role, config));
71
+ if (kept.length === selected.length || config === undefined) return selected;
72
+ const dropped = selected.filter((role) => !kept.includes(role));
73
+ if (kept.length === 0) {
74
+ throw new ConfigInvalidError({
75
+ cause: `role ${dropped.join(',')} was asked for and roles in app.config.ts lists ${config.roles.join(', ')}, so this process would serve nothing`,
76
+ fix: `x dev --role ${quoteArg(config.roles.filter((role) => role !== 'migrate').join(','))}`,
77
+ meta: { key: 'roles', roles: dropped, declared: [...config.roles] },
78
+ });
79
+ }
80
+ // info: once per boot — what this process does NOT run, which nothing else would say.
81
+ logger.info(`roles in app.config.ts does not list ${dropped.join(', ')}: not starting them`, {
82
+ dropped,
83
+ declared: [...config.roles],
84
+ });
85
+ return kept;
86
+ }
package/src/role-start.ts CHANGED
@@ -6,8 +6,7 @@
6
6
  // selectable but not default — it takes a replication slot on a shared database, which is not
7
7
  // something every `x dev` in a team should do to the same server by simply starting.
8
8
 
9
- import type { Role } from '@ultimat3/core';
10
- import { ctxOf, isRole, logger, markReady, ROLES } from '@ultimat3/core';
9
+ import { ctxOf, logger, markReady } from '@ultimat3/core';
11
10
  import { dbExecutor } from '@ultimat3/db';
12
11
  import type { RateLimitStore, Route, ServerHandle, WebSocketMount } from '@ultimat3/http';
13
12
  import {
@@ -31,7 +30,7 @@ import {
31
30
  import type { SyncWs } from '@ultimat3/realtime/server';
32
31
  import { loadAppConfig } from './app-config-load';
33
32
  import { errorPageHook } from './error-pages';
34
- import { BadFlagError, RuntimeDriverSplitError } from './errors';
33
+ import { RuntimeDriverSplitError } from './errors';
35
34
  import {
36
35
  DEFAULT_METRICS_PORT,
37
36
  rolePorts,
@@ -41,9 +40,9 @@ import {
41
40
  import { startRolePgStats } from './role-pg-stats';
42
41
  import { rolesUnderRealtime } from './role-realtime';
43
42
  import { startReplicator } from './role-replicator';
43
+ import { rolesDeclaredForDev } from './role-select';
44
44
  import { type DeviceMount, hostDeviceSockets } from './role-start-devices';
45
45
  import type { RunningRoles, StartRolesOptions } from './role-start-types';
46
- import { DEV_ROLES } from './role-start-types';
47
46
  import { prepareSync, type RunningSync, syncReadsChanges } from './role-sync';
48
47
  import { startWorkerWake } from './role-wake';
49
48
  import { installRoleBootWarnings } from './runtime-boot-warnings';
@@ -54,62 +53,22 @@ import { startLiveFeed } from './runtime-live-feed';
54
53
  import { type RunningServices, releaseOrThrow } from './runtime-services';
55
54
  import { inlineScriptSources } from './script-csp';
56
55
  import { bootWarningConcernsAny } from './serve-boot-warnings';
57
- import { quoteArg } from './shell-quote';
58
56
  import { inlineStyleSources } from './style-csp';
59
57
  import { syncConnectSources } from './sync-url';
60
58
  import { trustedHopsFromEnv } from './trusted-hops';
61
59
  import { DEV_BINDING } from './web-binding';
62
60
 
63
- // Declared beside the option types so `x dev`'s spec reads it without loading this module.
64
- export { DEV_ROLES } from './role-start-types';
65
-
66
- /**
67
- * What `--role` accepts. The replicator is here but not in `DEV_ROLES`: opt-in, because it takes
68
- * the one replication slot a database has, and a default that did that would mean two developers
69
- * pointed at one staging database silently fighting over it.
70
- */
71
- export const SELECTABLE_ROLES: readonly Role[] = [...DEV_ROLES, 'replicator'];
72
-
61
+ // `--role`'s reading, in a file of its own at the line ceiling.
62
+ export { rolesDeclaredForDev, SELECTABLE_ROLES, selectRoles } from './role-select';
73
63
  // The two shapes this module takes and answers, in a file of their own at the line ceiling.
74
64
  export type { RunningRoles, StartRolesOptions } from './role-start-types';
65
+ // Declared beside the option types so `x dev`'s spec reads it without loading this module.
66
+ export { DEV_ROLES } from './role-start-types';
75
67
 
76
68
  // Re-exported, not re-declared: `web-binding.ts` is a leaf so `role-sync` can read the default
77
69
  // without importing this module, which imports it.
78
70
  export { DEV_BINDING, type WebBinding } from './web-binding';
79
71
 
80
- /**
81
- * `--role web,worker` picks a subset. An unknown or out-of-scope role is a flag error with the
82
- * working invocation in the fix line, never a silently ignored value — which is what it was.
83
- */
84
- export function selectRoles(flag: string | undefined): readonly Role[] {
85
- if (flag === undefined || flag.trim().length === 0) return DEV_ROLES;
86
- const wanted = flag
87
- .split(',')
88
- .map((part) => part.trim())
89
- .filter((part) => part.length > 0);
90
- const selected: Role[] = [];
91
- for (const name of wanted) {
92
- if (!isRole(name)) {
93
- throw new BadFlagError({
94
- flag: 'role',
95
- command: 'dev',
96
- reason: `"${name}" is not a role (known: ${ROLES.join(', ')})`,
97
- fix: `x dev --role ${quoteArg(DEV_ROLES.join(','))}`,
98
- });
99
- }
100
- if (!SELECTABLE_ROLES.includes(name)) {
101
- throw new BadFlagError({
102
- flag: 'role',
103
- command: 'dev',
104
- reason: `"${name}" does not run under x dev (it runs once, as \`x db migrate\`)`,
105
- fix: `x dev --role ${quoteArg(DEV_ROLES.join(','))}`,
106
- });
107
- }
108
- if (!selected.includes(name)) selected.push(name);
109
- }
110
- return SELECTABLE_ROLES.filter((role) => selected.includes(role));
111
- }
112
-
113
72
  /**
114
73
  * A server whose route table demands an identity it has no way to resolve.
115
74
  *
@@ -268,12 +227,12 @@ function assertOneJobDriver(runtime: RunningServices): void {
268
227
  }
269
228
 
270
229
  export async function startRoles(options: StartRolesOptions): Promise<RunningRoles> {
271
- // `realtime.enabled` read here, before anything binds: a refusal leaves nothing to unwind.
272
- const selected = rolesUnderRealtime(
273
- options.roles,
274
- options.runtime.realtime,
275
- (options.http ?? DEV_BINDING).dev,
276
- );
230
+ const dev = (options.http ?? DEV_BINDING).dev;
231
+ const config = options.root === undefined ? undefined : await loadAppConfig(options.root);
232
+ // `realtime.enabled` and `roles` read here, before anything binds: a refusal leaves nothing to
233
+ // unwind. `roles` for `x dev` only — a container's `ROLE` was refused against it at boot.
234
+ const realtime = rolesUnderRealtime(options.roles, options.runtime.realtime, dev);
235
+ const selected = dev ? rolesDeclaredForDev(realtime, config) : realtime;
277
236
  assertOneJobDriver(options.runtime);
278
237
  // Once per process, and only where a role in it can act on the line (`serve-boot-warnings.ts`):
279
238
  // `rateLimitStoreFor` is asked twice in a web boot, and a scheduler spends no limit at all.
@@ -297,7 +256,6 @@ export async function startRoles(options: StartRolesOptions): Promise<RunningRol
297
256
  // these roles takes back exactly this install, whatever else stacked over or under it.
298
257
  // Once, before any role serves: which roles core's `bootWarning` concerns, and its per-build
299
258
  // marker store (`runtime-boot-warnings.ts`). Released by the stop, like every frame here.
300
- const config = options.root === undefined ? undefined : await loadAppConfig(options.root);
301
259
  const releaseWarnings = installRoleBootWarnings({
302
260
  roles: selected,
303
261
  config,
package/src/role-sync.ts CHANGED
@@ -23,7 +23,8 @@ import {
23
23
  SocketRegistry,
24
24
  syncNode,
25
25
  } from '@ultimat3/realtime/server';
26
- import { portPairAfter, syncPortFor } from './flag-number';
26
+ import { syncPortFor } from './flag-number';
27
+ import { freeDevPortPair } from './port-pair-free';
27
28
  import { portFree } from './port-probe';
28
29
  import type { StartRolesOptions } from './role-start';
29
30
  import { startOrWaitForBus } from './role-sync-bus-wait';
@@ -48,15 +49,15 @@ import { DEV_BINDING } from './web-binding';
48
49
  * "no findings — environment is shippable" when run (#F5).
49
50
  */
50
51
  class SyncPortInUseError extends UltimateError {
51
- constructor(input: { port: number; webPort: number }) {
52
+ constructor(input: { port: number; webPort: number; suggested: number }) {
52
53
  super({
53
54
  code: 'X_PORT_IN_USE',
54
55
  cause: `the sync role binds PORT + 1, so \`x dev --port ${input.webPort}\` needs port ${input.port} and something is already listening on it`,
55
- // `portPairAfter`, never `neighbouringPort`: `x dev` binds a PAIR, so the neighbour of the
56
+ // `freeDevPortPair`, never `neighbouringPort`: `x dev` binds a PAIR, so the neighbour of the
56
57
  // web port IS the sync port this refusal is about — the fix said `x dev --port 4000` for a
57
58
  // run that had just died on 4000, and a test named "its fix is a command that ends the
58
59
  // failure" pinned it.
59
- fix: `x dev --port ${quoteArg(String(portPairAfter(input.webPort)))} # or free port ${input.port}: lsof -nP -iTCP:${input.port} -sTCP:LISTEN`,
60
+ fix: `x dev --port ${quoteArg(String(input.suggested))} # or free port ${input.port}: lsof -nP -iTCP:${input.port} -sTCP:LISTEN`,
60
61
  meta: { port: input.port, webPort: input.webPort },
61
62
  });
62
63
  }
@@ -77,7 +78,11 @@ export async function syncBindRefusal(
77
78
  probe: (value: number) => Promise<boolean> = portFree,
78
79
  ): Promise<UltimateError | undefined> {
79
80
  if (await probe(port)) return undefined;
80
- return new SyncPortInUseError({ port, webPort });
81
+ return new SyncPortInUseError({
82
+ port,
83
+ webPort,
84
+ suggested: await freeDevPortPair(webPort, probe),
85
+ });
81
86
  }
82
87
 
83
88
  // Its rule lives in `flag-number.ts`, where the scrape port's reservation reads it too (`rolePorts`).
@@ -0,0 +1,46 @@
1
+ // The bust frame on `x.cache.invalidate`: the wire tags, then — when the sender's bust cleared a
2
+ // shared tier — one `{ scopes }` object naming what it cleared. Every receiver since v30 keeps the
3
+ // array's strings only, so an older pod reads the tags and busts every tier, as it always did.
4
+
5
+ import type { SharedTierScopes } from '@ultimat3/cache';
6
+
7
+ /** What a receiver reads off one frame: the tags, and the sender's scopes when it named any. */
8
+ export interface BustFrame {
9
+ readonly wire: readonly string[];
10
+ readonly sender?: SharedTierScopes;
11
+ }
12
+
13
+ /** `CACHE_FLUSH_ALL`, parsed: a peer had more refused busts than it could keep. */
14
+ export const isFlushAll = (parsed: unknown): boolean =>
15
+ typeof parsed === 'object' &&
16
+ parsed !== null &&
17
+ !Array.isArray(parsed) &&
18
+ Reflect.get(parsed, 'flush') === 'all';
19
+
20
+ /** The payload a bust publishes. No shared tier cleared, it is the bare tag array of old. */
21
+ export function encodeBustFrame(wire: readonly string[], sender?: SharedTierScopes): string {
22
+ if (sender === undefined || Object.keys(sender).length === 0) return JSON.stringify(wire);
23
+ return JSON.stringify([...wire, { scopes: sender }]);
24
+ }
25
+
26
+ /**
27
+ * A parsed frame array, read. A scopes object that is malformed in any part is read as NO scopes —
28
+ * every tier is busted — because a skipped bust is a stale row for the whole TTL.
29
+ */
30
+ export function decodeBustFrame(parsed: readonly unknown[]): BustFrame {
31
+ const wire = parsed.filter((value): value is string => typeof value === 'string');
32
+ const sender = parsed.map(scopesOf).find((scopes) => scopes !== undefined);
33
+ return sender === undefined ? { wire } : { wire, sender };
34
+ }
35
+
36
+ function scopesOf(value: unknown): SharedTierScopes | undefined {
37
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined;
38
+ const scopes: unknown = Reflect.get(value, 'scopes');
39
+ if (typeof scopes !== 'object' || scopes === null || Array.isArray(scopes)) return undefined;
40
+ const read: Record<string, string> = {};
41
+ for (const [name, scope] of Object.entries(scopes)) {
42
+ if (typeof scope !== 'string') return undefined;
43
+ read[name] = scope;
44
+ }
45
+ return read;
46
+ }
@@ -0,0 +1,23 @@
1
+ // `cache.defaultTtlMs` as the boot hands it to the rungs it builds — refused here under the key
2
+ // the app wrote, never by a rung under the name of an option the app never set.
3
+
4
+ import { ConfigInvalidError } from '@ultimat3/core';
5
+
6
+ /** `describeValue` answers "a number" for 0 and 2.5 alike; a number is printed as itself. */
7
+ const shown = (value: number): string => `${value}`;
8
+
9
+ /**
10
+ * The lease option for a built rung, or nothing so the rung keeps its own default. A value that is
11
+ * not a whole number of milliseconds above zero is `X_CONFIG_INVALID` naming `cache.defaultTtlMs`:
12
+ * `lruTier` refuses the same value as `X_CACHE_LIMIT_INVALID` about "lru.defaultTtlMs", with a
13
+ * fix that points at `runtime.ts` — the wrong file for a key written in `app.config.ts`.
14
+ */
15
+ export function defaultTtlOf(value: number | undefined): { defaultTtlMs?: number } {
16
+ if (value === undefined) return {};
17
+ if (Number.isSafeInteger(value) && value > 0) return { defaultTtlMs: value };
18
+ throw new ConfigInvalidError({
19
+ cause: `cache.defaultTtlMs must be a whole number of milliseconds of at least 1, not ${shown(value)}`,
20
+ fix: 'defineConfig({ cache: { defaultTtlMs: 60_000 } }) // in app.config.ts: the lease of a cached value set with no ttlMs',
21
+ meta: { key: 'cache.defaultTtlMs', value: shown(value) },
22
+ });
23
+ }