@ultimat3/cli 31.48.0 → 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 (260) 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 +80 -18
  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 +9 -1
  28. package/src/cmd-heavy.ts +111 -27
  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 +2 -1
  40. package/src/cmd-upgrade-spec.ts +8 -1
  41. package/src/cmd-upgrade.ts +15 -1
  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 +11 -15
  46. package/src/codemods/docs-worker-commands.ts +26 -0
  47. package/src/codemods/index.ts +4 -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-api-listing.ts +114 -0
  77. package/src/doctor-guarded.ts +41 -0
  78. package/src/doctor-port.ts +90 -17
  79. package/src/doctor-probe.ts +36 -5
  80. package/src/doctor-processes-probe.ts +127 -0
  81. package/src/doctor-processes.ts +136 -0
  82. package/src/doctor-warnings.ts +17 -0
  83. package/src/error-codes-agents.ts +35 -0
  84. package/src/error-codes-processes.ts +30 -0
  85. package/src/error-codes-tooling.ts +2 -0
  86. package/src/error-codes.ts +12 -13
  87. package/src/errors-suite.ts +27 -0
  88. package/src/errors.ts +18 -22
  89. package/src/exercise-registration.ts +4 -3
  90. package/src/framework-env.ts +7 -3
  91. package/src/generate-files.ts +1 -0
  92. package/src/generate-grant-findings.ts +7 -5
  93. package/src/generate-grants.ts +9 -8
  94. package/src/generate-kinds.ts +30 -6
  95. package/src/generate-roles-file.ts +30 -0
  96. package/src/generate-slice-policy.ts +3 -3
  97. package/src/guards.ts +2 -2
  98. package/src/heavy-env.ts +2 -0
  99. package/src/heavy-errors.ts +18 -0
  100. package/src/heavy-holders.ts +78 -0
  101. package/src/heavy-ledger.ts +56 -14
  102. package/src/heavy-pressure.ts +104 -0
  103. package/src/heavy.ts +31 -13
  104. package/src/i18n-registration.ts +22 -2
  105. package/src/island-harness.ts +2 -2
  106. package/src/job-budget.ts +4 -2
  107. package/src/job-registration.ts +64 -8
  108. package/src/jobs-queue-known.ts +43 -0
  109. package/src/mcp-errors-agents.ts +20 -0
  110. package/src/mcp-errors-doctor.ts +27 -0
  111. package/src/mcp-errors-processes.ts +23 -0
  112. package/src/mcp-errors.ts +15 -29
  113. package/src/mcp-host.ts +2 -2
  114. package/src/merge-driver-catalog.ts +58 -0
  115. package/src/merge-driver-config.ts +43 -0
  116. package/src/merge-driver-lines.ts +140 -0
  117. package/src/merge-state.ts +105 -0
  118. package/src/messages-db.ts +22 -1
  119. package/src/messages-processes.ts +13 -0
  120. package/src/messages-upgrade.ts +6 -0
  121. package/src/messages.ts +54 -4
  122. package/src/output-findings.ts +48 -21
  123. package/src/parse.ts +37 -6
  124. package/src/policy-facts.ts +38 -21
  125. package/src/policy-row.ts +99 -0
  126. package/src/port-pair-free.ts +28 -0
  127. package/src/registry-lines.ts +110 -0
  128. package/src/registry.ts +2 -0
  129. package/src/retain-sweep.ts +1 -1
  130. package/src/role-replicator.ts +4 -1
  131. package/src/role-select.ts +86 -0
  132. package/src/role-start.ts +13 -55
  133. package/src/role-sync.ts +10 -5
  134. package/src/runtime-cache-frame.ts +46 -0
  135. package/src/runtime-cache-ttl.ts +23 -0
  136. package/src/runtime-cache.ts +33 -16
  137. package/src/runtime-database-ssl.ts +84 -0
  138. package/src/runtime-idempotency-scope.ts +16 -2
  139. package/src/runtime-jobs-share.ts +52 -0
  140. package/src/runtime-jobs.ts +43 -12
  141. package/src/runtime-queue.ts +18 -3
  142. package/src/runtime-services.ts +8 -1
  143. package/src/schema-drift.ts +19 -2
  144. package/src/schema-dump-drift.ts +4 -1
  145. package/src/serve-boot-probe.ts +30 -2
  146. package/src/serve-boot.ts +11 -1
  147. package/src/serve-env.ts +39 -3
  148. package/src/serve.ts +61 -10
  149. package/src/stop-run-start.ts +12 -0
  150. package/src/supervise-boot.ts +61 -0
  151. package/src/supervise-cgroup.ts +84 -0
  152. package/src/supervise-child.ts +206 -0
  153. package/src/supervise-count.ts +244 -0
  154. package/src/supervise-errors.ts +83 -0
  155. package/src/supervise-facts.ts +40 -0
  156. package/src/supervise-messages.ts +84 -0
  157. package/src/supervise-policy.ts +46 -0
  158. package/src/supervise-pool.ts +10 -0
  159. package/src/supervise-probe.ts +158 -0
  160. package/src/supervise-run.ts +54 -0
  161. package/src/supervise.ts +383 -0
  162. package/src/templates/generate-purge.ts +6 -6
  163. package/src/templates/guard-animated-layout-property.ts +2 -2
  164. package/src/templates/guard-bare-error.ts +1 -1
  165. package/src/templates/guard-error-declared.ts +2 -2
  166. package/src/templates/guard-focus-visible.ts +1 -1
  167. package/src/templates/guard-image-dimensions.ts +2 -2
  168. package/src/templates/guard-island-mount-clears.ts +1 -1
  169. package/src/templates/guard-native-confirm.ts +1 -1
  170. package/src/templates/guard-raw-breakpoint.ts +2 -2
  171. package/src/templates/guard-raw-colour.ts +2 -2
  172. package/src/templates/guard-raw-fetch.ts +1 -1
  173. package/src/templates/guard-raw-interval.ts +1 -1
  174. package/src/templates/guard-raw-length.ts +3 -3
  175. package/src/templates/guard-raw-motion.ts +1 -1
  176. package/src/templates/guard-raw-shadow.ts +1 -1
  177. package/src/templates/guard-raw-z-index.ts +1 -1
  178. package/src/templates/guard-released-forms.ts +54 -8
  179. package/src/templates/guard-repo-await-in-loop.ts +1 -1
  180. package/src/templates/guard-repo-raw-sql.ts +4 -4
  181. package/src/templates/guard-repo-unbounded.ts +1 -1
  182. package/src/templates/guard-runtime-pin.ts +1 -1
  183. package/src/templates/guard-semantic-interactive.ts +2 -2
  184. package/src/templates/guard-unbounded-fanout.ts +1 -1
  185. package/src/templates/guard-undeclared-custom-property.ts +3 -3
  186. package/src/templates/guard-undefined-style-class.ts +3 -3
  187. package/src/templates/guard-unzoned-date.ts +3 -3
  188. package/src/templates/query-slice.ts +82 -0
  189. package/src/templates/query.ts +76 -30
  190. package/src/templates/resource-page.ts +3 -2
  191. package/src/templates/scaffold-bin.ts +2 -0
  192. package/src/templates/scaffold-claude-commands.ts +6 -0
  193. package/src/templates/scaffold-claude.ts +4 -4
  194. package/src/templates/scaffold-container-compose.ts +47 -7
  195. package/src/templates/scaffold-docs.ts +7 -3
  196. package/src/templates/scaffold-gitattributes.ts +18 -1
  197. package/src/templates/scaffold-helm-templates.ts +9 -0
  198. package/src/templates/scaffold-repo.ts +4 -1
  199. package/src/templates/scaffold-test-services.ts +33 -11
  200. package/src/templates/shapes/offline.ts +0 -7
  201. package/src/templates/shapes/realtime.ts +2 -6
  202. package/src/templates/sign-in-action-tests.ts +6 -4
  203. package/src/templates/sign-in-challenge.ts +62 -0
  204. package/src/templates/sign-in-oidc-mfa.ts +31 -0
  205. package/src/templates/sign-in-oidc.ts +11 -3
  206. package/src/templates/sign-in-password.ts +18 -56
  207. package/src/test-shards.ts +114 -34
  208. package/src/test-verdict.ts +79 -0
  209. package/src/test-workers.ts +15 -0
  210. package/src/upgrade-gate-codemods.ts +5 -3
  211. package/src/upgrade-gate.ts +19 -1
  212. package/src/upgrade-merge-drivers.ts +25 -0
  213. package/src/upgrade-report.ts +18 -4
  214. package/src/upgrade-scope.ts +62 -0
  215. package/src/verify-checks.ts +2 -8
  216. package/src/verify-coverage-run.ts +4 -1
  217. package/src/verify-live.ts +38 -14
  218. package/src/verify-only.ts +67 -0
  219. package/src/verify-progress.ts +7 -3
  220. package/src/verify-run.ts +20 -2
  221. package/src/verify-services-stack.ts +165 -0
  222. package/src/verify-services.ts +84 -2
  223. package/src/verify-test-run.ts +6 -7
  224. package/src/verify-tests.ts +8 -2
  225. package/src/verify-typecheck.ts +25 -2
  226. package/wiki/Actions.md +2 -1
  227. package/wiki/Admin-Dashboard.md +2 -2
  228. package/wiki/Agents.md +5 -5
  229. package/wiki/Auth.md +15 -5
  230. package/wiki/Bare-VM.md +1 -1
  231. package/wiki/CI-Parallel-Gate.md +2 -1
  232. package/wiki/CLI-Reference.md +107 -40
  233. package/wiki/Caching-And-Invalidation.md +1 -1
  234. package/wiki/Client-Navigation.md +1 -1
  235. package/wiki/Configuration.md +10 -9
  236. package/wiki/Deployment.md +44 -4
  237. package/wiki/Entities-And-Migrations.md +5 -1
  238. package/wiki/FAQ.md +1 -1
  239. package/wiki/Getting-Started.md +2 -2
  240. package/wiki/Home.md +1 -1
  241. package/wiki/I18n.md +5 -3
  242. package/wiki/Installation.md +12 -11
  243. package/wiki/Jobs-And-Workflows.md +24 -4
  244. package/wiki/Known-Gaps.md +1 -1
  245. package/wiki/MCP-And-AI.md +8 -5
  246. package/wiki/Many-Agents.md +69 -2
  247. package/wiki/Migrations-And-Backfills.md +18 -0
  248. package/wiki/Notify.md +1 -1
  249. package/wiki/Observability.md +13 -0
  250. package/wiki/Queries-And-Live-Queries.md +2 -2
  251. package/wiki/Realtime.md +10 -1
  252. package/wiki/Routes-And-Render-Modes.md +1 -1
  253. package/wiki/Scheduled-Tasks.md +4 -1
  254. package/wiki/Testing.md +7 -4
  255. package/wiki/Timezones-And-Dates.md +5 -1
  256. package/wiki/Troubleshooting.md +1 -0
  257. package/wiki/Tutorial-01-First-App.md +3 -3
  258. package/wiki/Tutorial-02-First-Feature.md +1 -1
  259. package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
  260. package/wiki/Upgrading.md +37 -0
@@ -2,12 +2,18 @@
2
2
  // shipped `error-declared` guard refuses it from the `@ultimat3/core` barrel. A mechanical import
3
3
  // rewrite over every app source file (the rest of an import stays put), and the prose that names it.
4
4
 
5
- import type { Codemod, CodemodApp, CodemodResult } from './codemod';
5
+ import type { Codemod, CodemodApp, CodemodResult, CodemodSkip } from './codemod';
6
6
  import type { SnippetEdit } from './engine-edits';
7
7
  import { editSnippets, mergeResults } from './engine-edits';
8
8
 
9
- const IMPORT = /^import \{([^}]*)\} from '@ultimat3\/core';$/gm;
10
- const LEAF = "import { defineError } from '@ultimat3/core/page';";
9
+ // A trailing `// note` after the statement is kept where it was.
10
+ const IMPORT = /^import \{([^}]*)\} from '@ultimat3\/core';([ \t]*\/\/[^\n]*)?$/gm;
11
+ const leaf = (specifier: string): string => `import { ${specifier} } from '@ultimat3/core/page';`;
12
+ /** `defineError`, or `defineError as declare`: the one specifier that moves. */
13
+ const MOVES = /^defineError(?:\s+as\s+[A-Za-z_$][\w$]*)?$/;
14
+ /** What the rewrite left behind: a barrel import still naming it, in a shape this does not edit. */
15
+ const LEFT =
16
+ /\bimport\s*(?:type\s*)?\{[^}]*\bdefineError\b[^}]*\}\s*from\s*['"]@ultimat3\/core['"]/;
11
17
 
12
18
  /** The rows that name where `defineError` comes from, in CLAUDE.md, the server agent and /feature. */
13
19
  export const DEFINE_ERROR_PROSE: Readonly<Record<string, readonly SnippetEdit[]>> = {
@@ -34,29 +40,48 @@ export const DEFINE_ERROR_PROSE: Readonly<Record<string, readonly SnippetEdit[]>
34
40
  ],
35
41
  };
36
42
 
37
- /** The import with `defineError` taken out to the leaf; unchanged when it does not name it. */
38
- const rewrite = (whole: string, list: string): string => {
43
+ /**
44
+ * The import with `defineError` taken out to the leaf; unchanged when it does not name it, or when
45
+ * the braces hold a comment — a line this would have to drop or misplace, so it is reported.
46
+ */
47
+ const rewrite = (whole: string, list: string, trailing: string | undefined): string => {
48
+ if (list.includes('//') || list.includes('/*')) return whole;
39
49
  const names = list
40
50
  .split(',')
41
51
  .map((name) => name.trim())
42
52
  .filter((name) => name !== '');
43
- if (!names.includes('defineError')) return whole;
44
- const rest = names.filter((name) => name !== 'defineError');
45
- return rest.length === 0 ? LEAF : `import { ${rest.join(', ')} } from '@ultimat3/core';\n${LEAF}`;
53
+ const moved = names.find((name) => MOVES.test(name));
54
+ if (moved === undefined) return whole;
55
+ const rest = names.filter((name) => name !== moved);
56
+ const tail = trailing ?? '';
57
+ return rest.length === 0
58
+ ? `${leaf(moved)}${tail}`
59
+ : `import { ${rest.join(', ')} } from '@ultimat3/core';${tail}\n${leaf(moved)}`;
46
60
  };
47
61
 
48
62
  async function sources(app: CodemodApp): Promise<CodemodResult> {
49
63
  const changed: string[] = [];
64
+ const skipped: CodemodSkip[] = [];
50
65
  for (const path of await app.glob('{apps,packages}/**/*.{ts,tsx}')) {
51
66
  if (path.includes('node_modules/')) continue;
52
67
  const source = (await app.read(path)) ?? '';
53
68
  if (!source.includes('defineError')) continue;
54
69
  const next = source.replace(IMPORT, rewrite);
55
- if (next === source) continue;
56
- await app.write(path, next);
57
- changed.push(path);
70
+ if (next !== source) {
71
+ await app.write(path, next);
72
+ changed.push(path);
73
+ }
74
+ // Never silently kept: the shipped `error-declared` guard reds this file after the hop.
75
+ if (LEFT.test(next)) {
76
+ skipped.push({
77
+ path,
78
+ reason:
79
+ "imports defineError from '@ultimat3/core' in a shape this codemod does not rewrite (a comment inside the braces, a type-only import, or double quotes)",
80
+ diff: `- defineError (in the import from '@ultimat3/core')\n+ ${leaf('defineError')}`,
81
+ });
82
+ }
58
83
  }
59
- return { changed, skipped: [] };
84
+ return { changed, skipped };
60
85
  }
61
86
 
62
87
  export const codemod: Codemod = {
@@ -1,30 +1,26 @@
1
1
  // 31.48.0: CLAUDE.md states who runs what when several agents share a machine, the rule the machine
2
- // ledger exists to back. Prose: it lands where the table stands as `x new` wrote it, and is skipped
3
- // silently where the app reworded that row or already says it.
2
+ // ledger exists to back. Prose: it lands above the One way row, in CLAUDE.md or AGENTS.md, within
3
+ // the brief's byte budget; otherwise it is reported as skipped with the row to add by hand.
4
4
 
5
+ import { editAgentsDocRow } from './agents-doc-row';
5
6
  import type { Codemod } from './codemod';
6
- import type { SnippetEdit } from './engine-edits';
7
- import { editSnippets } from './engine-edits';
8
7
 
9
- const CLAUDE = 'CLAUDE.md';
10
8
  const NEXT_ROW = '| One way | generators, not hand-rolled files:';
11
9
 
12
10
  /** Terse on purpose: a shaped app's CLAUDE.md sits within bytes of `AGENTS_MD_MAX_BYTES`. */
13
11
  export const MANY_AGENTS_ROW =
14
12
  '| Many agents | a worker runs its own files; the coordinator runs the gate once | `bunx x heavy status` |';
15
13
 
16
- export const DOCS_MANY_AGENTS_EDITS: readonly SnippetEdit[] = [
17
- { from: NEXT_ROW, to: `${MANY_AGENTS_ROW}\n${NEXT_ROW}`, optional: true },
18
- ];
19
-
20
14
  export const codemod: Codemod = {
21
15
  id: 'docs-many-agents',
22
16
  since: '31.48.0',
23
17
  summary: "CLAUDE.md's table says a worker runs its own files and the coordinator runs the gate",
24
- async run(app) {
25
- if (((await app.read(CLAUDE)) ?? '').includes('x heavy status')) {
26
- return { changed: [], skipped: [] };
27
- }
28
- return editSnippets(app, CLAUDE, DOCS_MANY_AGENTS_EDITS);
29
- },
18
+ run: (app) =>
19
+ editAgentsDocRow(app, {
20
+ from: NEXT_ROW,
21
+ to: `${MANY_AGENTS_ROW}\n${NEXT_ROW}`,
22
+ row: MANY_AGENTS_ROW,
23
+ said: (text) => text.includes('| Many agents |'),
24
+ missing: `no "${NEXT_ROW}" row to place it above in CLAUDE.md or AGENTS.md`,
25
+ }),
30
26
  };
@@ -0,0 +1,26 @@
1
+ // 31.49.0: CLAUDE.md's many-agents row names the commands a worker runs. The row it replaces gave a
2
+ // worker none and listed `x heavy status` under "Refused by", which refuses nothing. Prose: it moves
3
+ // the row as written, within the brief's byte budget; a reworded or absent row is a reported skip.
4
+
5
+ import { editAgentsDocRow } from './agents-doc-row';
6
+ import type { Codemod } from './codemod';
7
+ import { MANY_AGENTS_ROW } from './docs-many-agents';
8
+
9
+ /** Terse on purpose: a shaped app's CLAUDE.md sits within bytes of `AGENTS_MD_MAX_BYTES`. */
10
+ export const WORKER_COMMANDS_ROW =
11
+ '| Many agents | a worker: `bun test ./<file>`, `bunx x test --filter <path>`; the coordinator: the gate, once | review |';
12
+
13
+ export const codemod: Codemod = {
14
+ id: 'docs-worker-commands',
15
+ since: '31.49.0',
16
+ summary: "CLAUDE.md's many-agents row names the commands a worker runs",
17
+ run: (app) =>
18
+ editAgentsDocRow(app, {
19
+ from: MANY_AGENTS_ROW,
20
+ to: WORKER_COMMANDS_ROW,
21
+ row: WORKER_COMMANDS_ROW,
22
+ said: (text) => text.includes(WORKER_COMMANDS_ROW),
23
+ missing:
24
+ 'the many-agents row is not the one x new or docs-many-agents wrote (reworded, or never added), so it is left as written',
25
+ }),
26
+ };
@@ -21,10 +21,12 @@ import { codemod as docsIslandRows } from './docs-island-rows';
21
21
  import { codemod as docsManyAgents } from './docs-many-agents';
22
22
  import { codemod as docsShippedGuards } from './docs-shipped-guards';
23
23
  import { codemod as docsTestServices } from './docs-test-services';
24
+ import { codemod as docsWorkerCommands } from './docs-worker-commands';
24
25
  import { codemod as e2eSuiteFloor } from './e2e-suite-floor';
25
26
  import { codemod as formatEditedHook } from './format-edited-hook';
26
27
  import { codemod as helmAlertsDeploy } from './helm-alerts-deploy';
27
28
  import { codemod as helmAlertsObjective } from './helm-alerts-objective';
29
+ import { codemod as mergeDrivers } from './merge-drivers';
28
30
  import { codemod as metricsProbeHealthz } from './metrics-probe-healthz';
29
31
  import { codemod as migrateJobOrdered } from './migrate-job-ordered';
30
32
  import { codemod as reproGitignore } from './repro-gitignore';
@@ -73,4 +75,6 @@ export const CODEMODS: readonly Codemod[] = [
73
75
  ciWeeklySchedule,
74
76
  e2eSuiteFloor,
75
77
  docsManyAgents,
78
+ docsWorkerCommands,
79
+ mergeDrivers,
76
80
  ];
@@ -0,0 +1,66 @@
1
+ // 31.49.0: two branches that each generate a feature merge without a hand edit. An existing app
2
+ // gains the `.gitattributes` rules, the `bun run setup` step that installs the drivers, and its
3
+ // registries one entry per line. Every step is additive: a list this cannot restate is left alone,
4
+ // and it still works; it only keeps merging by hand.
5
+
6
+ import { REGISTRY_FILES, withRegistryLines } from '../registry-lines';
7
+ import { BIN_SCRIPTS } from '../templates/scaffold-bin';
8
+ import { MERGE_ATTRIBUTES, ROOT_GITATTRIBUTES_PATH } from '../templates/scaffold-gitattributes';
9
+ import type { Codemod, CodemodApp, CodemodResult } from './codemod';
10
+
11
+ const INSTALL_ANCHOR = "await bun('install');\n";
12
+ export const INSTALL_STEP = "await x('merge-driver', 'install');\n";
13
+
14
+ const withAttributes = (held: string | undefined): string | undefined => {
15
+ if (held?.includes('merge=x-registry') === true) return undefined;
16
+ if (held === undefined) return MERGE_ATTRIBUTES;
17
+ return `${held.endsWith('\n') ? held : `${held}\n`}\n${MERGE_ATTRIBUTES}`;
18
+ };
19
+
20
+ async function edit(
21
+ app: CodemodApp,
22
+ path: string,
23
+ change: (held: string) => string | undefined,
24
+ changed: string[],
25
+ ): Promise<void> {
26
+ const held = await app.read(path);
27
+ if (held === undefined) return;
28
+ const next = change(held);
29
+ if (next === undefined || next === held) return;
30
+ await app.write(path, next);
31
+ changed.push(path);
32
+ }
33
+
34
+ export const codemod: Codemod = {
35
+ id: 'merge-drivers',
36
+ since: '31.49.0',
37
+ summary: 'parallel branches merge generated features: drivers, setup step, one entry per line',
38
+ async run(app): Promise<CodemodResult> {
39
+ const changed: string[] = [];
40
+ const skipped: CodemodResult['skipped'] = [];
41
+ const attributes = withAttributes(await app.read(ROOT_GITATTRIBUTES_PATH));
42
+ if (attributes !== undefined) {
43
+ await app.write(ROOT_GITATTRIBUTES_PATH, attributes);
44
+ changed.push(ROOT_GITATTRIBUTES_PATH);
45
+ }
46
+ const setup = await app.read(BIN_SCRIPTS.setup);
47
+ if (setup !== undefined && !setup.includes(INSTALL_STEP)) {
48
+ if (setup.includes(INSTALL_ANCHOR)) {
49
+ await app.write(
50
+ BIN_SCRIPTS.setup,
51
+ setup.replace(INSTALL_ANCHOR, `${INSTALL_ANCHOR}${INSTALL_STEP}`),
52
+ );
53
+ changed.push(BIN_SCRIPTS.setup);
54
+ } else {
55
+ skipped.push({
56
+ path: BIN_SCRIPTS.setup,
57
+ reason: `no "${INSTALL_ANCHOR.trim()}" line to follow; add ${INSTALL_STEP.trim()} after your install step`,
58
+ });
59
+ }
60
+ }
61
+ for (const path of REGISTRY_FILES) {
62
+ await edit(app, path, (held) => withRegistryLines(path, held), changed);
63
+ }
64
+ return { changed, skipped };
65
+ },
66
+ };
package/src/command.ts CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  import type { Runner } from './exec';
6
6
  import type { CommandResult } from './output';
7
+ import type { ReaderOptions } from './output-findings';
7
8
  import type { CommandSpec, ParsedArgs } from './parse';
8
9
 
9
10
  export interface CommandContext {
@@ -21,6 +22,8 @@ export interface CommandContext {
21
22
  * follow. Absent means the default below — a caller that builds a context by hand owes nothing.
22
23
  */
23
24
  readonly invocation?: string;
25
+ /** Who reads this run's fix lines, for one printed outside a finding. `dispatch` decides. */
26
+ readonly reader?: ReaderOptions;
24
27
  }
25
28
 
26
29
  /** What `ctx.invocation` means when nobody said: the binary, then the subcommand they typed. */
@@ -0,0 +1,117 @@
1
+ // An applied migration edited since, asked before `x db gen` writes anything: the command is
2
+ // `X_SCHEMA_DUMP_DRIFT`'s fix, and run over an edited migration it rewrote the dump to match the
3
+ // edit — blessing SQL no database holds. The embedded ledger is read where it can be, never dialled.
4
+
5
+ // why: Bun has no directory probe — `Bun.file().exists()` answers about a file.
6
+ import { existsSync } from 'node:fs';
7
+ import { renderThrowable } from '@ultimat3/core';
8
+ import type { Migration } from '@ultimat3/db';
9
+ import { auditLedger, isLedgerMissing, pgliteDataDir, readLedger } from '@ultimat3/db';
10
+ import { t } from '@ultimat3/schema';
11
+ import { withOpenedDb } from './db-client-displace';
12
+ import { DEV_LEDGER_PATH } from './db-dev-wire';
13
+ import { askDev, type PostJson, unreadable } from './db-migrate-through-dev';
14
+ import { liveDevLockChecked } from './dev-lock-live';
15
+ import { readMigrations } from './migrations';
16
+ import { resolveServices } from './runtime-bindings';
17
+ import { startDb } from './runtime-queue';
18
+
19
+ type Env = Readonly<Record<string, string | undefined>>;
20
+
21
+ /** One applied migration as the ledger records it: all the checksum rule reads. */
22
+ export interface AppliedRow {
23
+ readonly id: string;
24
+ readonly checksum: string;
25
+ }
26
+
27
+ const LEDGER = t.object({
28
+ ledger: t.array(t.object({ id: t.string, checksum: t.string })),
29
+ });
30
+
31
+ /**
32
+ * `auditLedger`'s checksum half over the rows this checkout still ships — a row it does not ship
33
+ * is another refusal (a rollback, a deleted file) and not this one's. Throws `X_MIGRATION_CONFLICT`
34
+ * with the migrator's own cause and fix, so the three places that ask cannot word it three ways.
35
+ */
36
+ export function refuseEdited(
37
+ applied: readonly AppliedRow[],
38
+ migrations: readonly Migration[],
39
+ ): void {
40
+ const shipped = new Set(migrations.map((migration) => migration.id));
41
+ auditLedger(
42
+ applied
43
+ .filter((row) => shipped.has(row.id))
44
+ // The fields the audit never reads on a known row, filled so the row types.
45
+ .map((row) => ({ ...row, name: row.id, applied_at: '', app_version: 'dev', duration_ms: 0 })),
46
+ migrations,
47
+ 'dev',
48
+ );
49
+ }
50
+
51
+ /** What the check found out: the rows, or why this run could not read them. */
52
+ export type AppliedRead =
53
+ | { readonly applied: readonly AppliedRow[] }
54
+ | { readonly skipped: string | undefined };
55
+
56
+ /**
57
+ * The embedded database's ledger, by whoever may read it: the live `x dev` that holds the
58
+ * directory, else this process on a read-only open (`x db status`'s). Never an external
59
+ * `DATABASE_URL` — `x db gen` is files in, files out, and must answer the same with no server up;
60
+ * there the migrator's own audit is the refusal. A read that fails is reported, never fatal: this
61
+ * command is the `fix:` of five errors and cannot start needing a healthy database to run.
62
+ */
63
+ export async function readApplied(root: string, env: Env, post?: PostJson): Promise<AppliedRead> {
64
+ const services = resolveServices(root, env);
65
+ if (services.db.mode !== 'embedded') return { skipped: undefined };
66
+ if (!existsSync(pgliteDataDir(services.db.url))) return { applied: [] };
67
+ try {
68
+ const holder = await liveDevLockChecked(services.stateDir);
69
+ if (holder !== undefined) {
70
+ const applied = await askDev(
71
+ holder,
72
+ services.stateDir,
73
+ {
74
+ path: DEV_LEDGER_PATH,
75
+ resume: ['db', 'gen'],
76
+ read: (data) => {
77
+ const parsed = LEDGER.safeParse(data);
78
+ return parsed.issues === undefined
79
+ ? { value: parsed.value.ledger }
80
+ : unreadable(parsed.issues);
81
+ },
82
+ },
83
+ post,
84
+ );
85
+ return { applied };
86
+ }
87
+ return {
88
+ applied: await withOpenedDb(
89
+ () => startDb(services, env, false),
90
+ async (client) => {
91
+ try {
92
+ return await readLedger(client);
93
+ } catch (error) {
94
+ if (!isLedgerMissing(error)) throw error;
95
+ return [];
96
+ }
97
+ },
98
+ ),
99
+ };
100
+ } catch (error) {
101
+ return { skipped: renderThrowable(error) };
102
+ }
103
+ }
104
+
105
+ /** Refuse (`X_MIGRATION_CONFLICT`) or answer why nothing was compared; `undefined` is "checked". */
106
+ export async function refuseAppliedEdits(
107
+ root: string,
108
+ env: Env,
109
+ post?: PostJson,
110
+ ): Promise<string | undefined> {
111
+ const migrations = await readMigrations(root);
112
+ if (migrations.length === 0) return undefined;
113
+ const read = await readApplied(root, env, post);
114
+ if ('skipped' in read) return read.skipped;
115
+ refuseEdited(read.applied, migrations);
116
+ return undefined;
117
+ }
@@ -0,0 +1,18 @@
1
+ // The `/_x/db` wire between `x db …` and a live `x dev` holding the embedded database: the three
2
+ // paths and the `--steps` rule, stated once. Import-free on purpose — the CLI clients read it
3
+ // without loading the route's graph, and the dev routes without loading a command's.
4
+
5
+ /** `x db migrate`, asked of the holder (`db-migrate-through-dev.ts` → `dev-db-migrate.ts`). */
6
+ export const DEV_MIGRATE_PATH = '/_x/db/migrate';
7
+
8
+ /** `x db rollback` (`db-rollback-pass.ts`) and `x db gen`'s ledger read (`db-applied-edits.ts`). */
9
+ export const DEV_ROLLBACK_PATH = '/_x/db/rollback';
10
+ export const DEV_LEDGER_PATH = '/_x/db/ledger';
11
+
12
+ /** `--steps` and the door's `?steps=`: one rule, so the holder refuses what the flag refuses. */
13
+ export const ROLLBACK_STEPS = {
14
+ name: 'steps',
15
+ command: 'db rollback',
16
+ min: 1,
17
+ example: 'x db rollback --steps 1',
18
+ } as const;
@@ -9,11 +9,12 @@ import {
9
9
  } from '@ultimat3/db/diagnostics';
10
10
  import type { CommandContext } from './command';
11
11
  import { withOpenedDb } from './db-client-displace';
12
- import { DevAlreadyRunningError, liveDevLock } from './dev-lock';
12
+ import { refuseBesideDev } from './dev-lock-live';
13
13
  import { readIntFlag } from './flag-number';
14
14
  import { msg } from './messages';
15
15
  import type { CommandResult, JsonValue } from './output';
16
16
  import { resolveServices } from './runtime-bindings';
17
+ import { databaseSslOf } from './runtime-database-ssl';
17
18
  import { startDb } from './runtime-queue';
18
19
  import { renderTable } from './table';
19
20
 
@@ -80,20 +81,14 @@ export async function runDiagnostics(ctx: CommandContext, root: string): Promise
80
81
  if (services.db.mode === 'embedded') {
81
82
  // Check-then-open, as `x db reset` does: an `x dev` starting between this read and `startDb`
82
83
  // below is not seen. Narrow, and the same window every embedded `x db` subcommand has.
83
- const holder = liveDevLock(services.stateDir);
84
- if (holder !== undefined) {
85
- throw new DevAlreadyRunningError({
86
- lock: holder,
87
- stateDir: services.stateDir,
88
- embeddedDb: true,
89
- });
90
- }
84
+ await refuseBesideDev(services.stateDir);
91
85
  }
86
+ const ssl = await databaseSslOf(services);
92
87
  // `startDb` installs its client as the process's `db()`; `withOpenedDb` puts back what was there
93
88
  // (closing a lazy default it dropped) and closes both pools, or every later `db()` in an
94
89
  // embedding process reaches a dead pool.
95
90
  return withOpenedDb(
96
- () => startDb(services, ctx.env),
91
+ () => startDb(services, ctx.env, ssl),
97
92
  async (client) => {
98
93
  // Embedded, the probe IS the boot — a WASM compile and an initdb, 12.6 s cold under coverage —
99
94
  // so the 3 s probe wait answered a healthy database X_DB_UNAVAILABLE. A server keeps the default.
@@ -4,15 +4,22 @@
4
4
 
5
5
  // why: `node:path` — Bun ships no path joiner of its own, and these paths are built, not opened.
6
6
  import { join } from 'node:path';
7
- import type { GeneratedMigration, UnrenderedDeclaration } from '@ultimat3/db';
7
+ import type {
8
+ GeneratedMigration,
9
+ Migration,
10
+ SchemaDescription,
11
+ UnrenderedDeclaration,
12
+ } from '@ultimat3/db';
8
13
  import {
9
14
  DESTRUCTIVE_MARKER,
10
15
  declaredSchema,
11
16
  generateMigration,
17
+ migrationForked,
12
18
  migrationSnapshotMissing,
13
19
  ROLLING_UNSAFE_MARKER,
14
20
  snapshotJson,
15
21
  } from '@ultimat3/db';
22
+ import { migrationFork } from '@ultimat3/db/schema-dump';
16
23
  import { registeredEntities } from '@ultimat3/entity';
17
24
  import { describeQueries } from '@ultimat3/query';
18
25
  import { loadApp } from './app-load';
@@ -35,16 +42,27 @@ export interface GenerateMigrationOptions {
35
42
  * concurrently. Never a default; once dropped, a plain run does not rebuild it.
36
43
  */
37
44
  readonly dropRedundant?: boolean | undefined;
45
+ /**
46
+ * `x db gen --merge-fork`, the fix `X_MIGRATION_FORKED` prints. Rewrites the newest sidecar to what
47
+ * the merged chain builds, and goes on as any run does from there. No `.sql` is touched.
48
+ */
49
+ readonly mergeFork?: boolean | undefined;
38
50
  /** `database.rowSecurity` and the tenant columns. The app's own unless a test injects one. */
39
51
  readonly rowSecurity?: RowSecurityWanted | undefined;
40
52
  }
41
53
 
42
54
  /**
43
- * What this run actually did — four different things, and `--json` has to tell them apart. A
55
+ * What this run actually did — five different things, and `--json` has to tell them apart. A
44
56
  * `hash-recorded` run wrote a file and generated no migration; reporting it as `generated` would
45
57
  * claim a migration nobody can apply, and reporting it as `unchanged` would hide the one write.
58
+ * `fork-merged` is the same honesty for `--merge-fork`: a sidecar moved and no migration exists.
46
59
  */
47
- export type GenerateOutcome = 'generated' | 'hash-recorded' | 'unchanged' | 'blocked';
60
+ export type GenerateOutcome =
61
+ | 'generated'
62
+ | 'hash-recorded'
63
+ | 'fork-merged'
64
+ | 'unchanged'
65
+ | 'blocked';
48
66
 
49
67
  export interface GeneratedFiles {
50
68
  readonly outcome: GenerateOutcome;
@@ -52,6 +70,12 @@ export interface GeneratedFiles {
52
70
  readonly migration?: GeneratedMigration | undefined;
53
71
  /** App-root-relative paths written, in write order. Empty when there was nothing to write. */
54
72
  readonly files: readonly string[];
73
+ /** The tables `migration` creates, changes or drops, so a shared checkout can see whose they are. */
74
+ readonly tables?: readonly string[] | undefined;
75
+ /** The newest migration on disk once this run ended: what an empty diff was measured against. */
76
+ readonly newest?: string | undefined;
77
+ /** How many objects `--merge-fork` put right in the newest sidecar. Absent when it merged none. */
78
+ readonly forkRepairs?: number | undefined;
55
79
  /** What the source hashes to, whenever this run was in a position to record it. */
56
80
  readonly schemaHash?: string | undefined;
57
81
  /**
@@ -91,6 +115,47 @@ export function migrationSql(migration: GeneratedMigration): string {
91
115
  ].join('\n');
92
116
  }
93
117
 
118
+ /** Every table whose recorded shape differs between two snapshots, in name order. */
119
+ function tablesBetween(before: SchemaDescription, after: SchemaDescription): readonly string[] {
120
+ const shape = (schema: SchemaDescription): Map<string, string> =>
121
+ new Map(schema.tables.map((table) => [table.name, JSON.stringify(table)]));
122
+ const was = shape(before);
123
+ const now = shape(after);
124
+ return [...new Set([...was.keys(), ...now.keys()])]
125
+ .filter((name) => was.get(name) !== now.get(name))
126
+ .sort();
127
+ }
128
+
129
+ interface SettledChain {
130
+ readonly migrations: readonly Migration[];
131
+ readonly files: readonly string[];
132
+ readonly repairs: number;
133
+ }
134
+
135
+ /**
136
+ * Before any diff: against a forked chain the diff is wrong in both directions, asking for a second
137
+ * `create table` the replay refuses. Merging only rewrites a sidecar, which no checksum covers; a
138
+ * collision has no such repair, so it is refused even under `--merge-fork`.
139
+ */
140
+ async function settleFork(
141
+ root: string,
142
+ migrations: readonly Migration[],
143
+ mergeFork: boolean,
144
+ ): Promise<SettledChain> {
145
+ const fork = migrationFork(migrations);
146
+ if (fork === undefined) return { migrations, files: [], repairs: 0 };
147
+ if (!mergeFork || fork.collisions.length > 0) throw migrationForked(fork);
148
+ const file = `${MIGRATIONS_DIR}/${snapshotFileName(fork.newest)}`;
149
+ await Bun.write(join(root, file), snapshotJson(fork.merged));
150
+ return {
151
+ migrations: migrations.map((migration) =>
152
+ migration.id === fork.newest ? { ...migration, snapshot: fork.merged } : migration,
153
+ ),
154
+ files: [file],
155
+ repairs: fork.lost.length + fork.stale.length,
156
+ };
157
+ }
158
+
94
159
  /**
95
160
  * Generation reads source and writes files; it never opens a database. The previous migration's
96
161
  * snapshot is what it diffs against (`declaredSchema`), so `x db gen` answers the same in CI, on a
@@ -109,7 +174,10 @@ export async function generateAppMigration(
109
174
  return { outcome: 'blocked', files: [], findings: app.findings, unrendered: [] };
110
175
  }
111
176
 
112
- const migrations = await readMigrations(root);
177
+ const onDisk = await readMigrations(root);
178
+ const settled = await settleFork(root, onDisk, options.mergeFork === true);
179
+ const migrations = settled.migrations;
180
+ const forkFields = settled.repairs === 0 ? {} : { forkRepairs: settled.repairs };
113
181
  const current = declaredSchema(migrations);
114
182
  // Refused, never defaulted to the empty schema: with nothing to diff against, every table the
115
183
  // database already holds looks new and the generated `up` is `create table` for all of them.
@@ -166,10 +234,14 @@ export async function generateAppMigration(
166
234
  return { outcome: 'unchanged', files: [], findings: [], unrendered: migration.unrendered };
167
235
  }
168
236
  const reconciled = await reconcileSchemaHash(root, newest.id);
237
+ const hashFiles = reconciled.written ? [`${MIGRATIONS_DIR}/${hashFileName(newest.id)}`] : [];
238
+ const quietOutcome = reconciled.written ? 'hash-recorded' : 'unchanged';
169
239
  return {
170
- outcome: reconciled.written ? 'hash-recorded' : 'unchanged',
240
+ outcome: settled.repairs > 0 ? 'fork-merged' : quietOutcome,
171
241
  schemaHash: reconciled.hash,
172
- files: reconciled.written ? [`${MIGRATIONS_DIR}/${hashFileName(newest.id)}`] : [],
242
+ files: [...settled.files, ...hashFiles],
243
+ newest: newest.id,
244
+ ...forkFields,
173
245
  findings: [],
174
246
  unrendered: migration.unrendered,
175
247
  };
@@ -180,7 +252,7 @@ export async function generateAppMigration(
180
252
  // after this one. Each file is a ledger row of its own; see `@ultimat3/db`'s `generate-steps.ts`.
181
253
  const steps = [migration, ...(migration.followUp === undefined ? [] : [migration.followUp])];
182
254
  const dir = join(root, MIGRATIONS_DIR);
183
- const files: string[] = [];
255
+ const files: string[] = [...settled.files];
184
256
  let schemaHash = '';
185
257
  for (const step of steps) {
186
258
  const sql = `${step.id}.sql`;
@@ -200,6 +272,9 @@ export async function generateAppMigration(
200
272
  migration,
201
273
  schemaHash,
202
274
  files,
275
+ tables: tablesBetween(current, steps[steps.length - 1]?.snapshot ?? migration.snapshot),
276
+ newest: steps[steps.length - 1]?.id ?? migration.id,
277
+ ...forkFields,
203
278
  findings: [],
204
279
  unrendered: migration.unrendered,
205
280
  };
@@ -0,0 +1,51 @@
1
+ // One `x db migrate` pass and who applies it: this process through `serve.ts`'s `runMigrations`,
2
+ // or — beside a live `x dev` holding the embedded database — that process, asked over `/_x`.
3
+ // PGlite takes no lock of its own: a second opener's tables are gone at the holder's next write.
4
+
5
+ import type { DriftDifference, DriftReport } from '@ultimat3/db';
6
+ import type { CatalogDescription } from '@ultimat3/db/schema-dump';
7
+ import { unexpectedObjects } from '@ultimat3/db/schema-dump';
8
+ import { migrateThroughDev } from './db-migrate-through-dev';
9
+ import { liveObjectDrift } from './db-object-drift';
10
+ import { liveDevLockChecked } from './dev-lock-live';
11
+ import { resolveServices } from './runtime-bindings';
12
+ import { runMigrations } from './serve';
13
+
14
+ type Env = Readonly<Record<string, string | undefined>>;
15
+
16
+ export interface MigratePass {
17
+ readonly applied: readonly string[];
18
+ readonly skipped: number;
19
+ readonly appVersion: string;
20
+ readonly durationMs: number;
21
+ /** The live schema against the ledger, after the apply. */
22
+ readonly drift: DriftReport;
23
+ /** What the live database holds that `expected` (the replayed migrations) does not create. */
24
+ objects(expected: CatalogDescription): Promise<readonly DriftDifference[]>;
25
+ }
26
+
27
+ export async function migratePass(root: string, env: Env): Promise<MigratePass> {
28
+ const services = resolveServices(root, env);
29
+ const holder =
30
+ services.db.mode === 'embedded' ? await liveDevLockChecked(services.stateDir) : undefined;
31
+ if (holder !== undefined) {
32
+ const { drift, catalog, storage, ...report } = await migrateThroughDev(
33
+ holder,
34
+ services.stateDir,
35
+ );
36
+ return {
37
+ ...report,
38
+ drift: { ok: drift.length === 0, differences: drift },
39
+ objects: async (expected) => [...unexpectedObjects(catalog, expected), ...storage],
40
+ };
41
+ }
42
+ const { report, drift } = await runMigrations({ root, env });
43
+ return {
44
+ applied: report.applied.map((entry) => entry.id),
45
+ skipped: report.skipped.length,
46
+ appVersion: report.appVersion,
47
+ durationMs: report.durationMs,
48
+ drift,
49
+ objects: (expected) => liveObjectDrift(root, env, expected),
50
+ };
51
+ }