@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
package/src/cmd-db.ts CHANGED
@@ -1,7 +1,7 @@
1
- // `x db gen|migrate|reset|seed|studio|branch|backfill|diagnostics|recount|status` — everything that touches the
1
+ // `x db gen|migrate|rollback|reset|seed|studio|branch|backfill|diagnostics|recount|status` — everything that touches the
2
2
  // database. One subcommand per line and no fall-through: a word this file does not know is refused,
3
3
  // never re-read as an argument to the last branch. `branch` is `cmd-db-branch.ts`, `diagnostics`
4
- // is `db-diagnostics.ts`, `status` is `cmd-db-status.ts`.
4
+ // is `db-diagnostics.ts`, `status` is `cmd-db-status.ts`, `rollback` is `cmd-db-rollback.ts`.
5
5
  //
6
6
  // Every subcommand here runs `@ultimat3/db`'s own engine, which is the engine `ROLE=migrate` runs
7
7
  // (`serve.ts`): one `x_migrations` ledger, one checksum rule, one advisory lock, from a laptop to
@@ -13,19 +13,22 @@
13
13
  import { rm } from 'node:fs/promises';
14
14
  import { join } from 'node:path';
15
15
  import { NotImplementedError, resolveEnvironment } from '@ultimat3/core';
16
- import { type DriftReport, driftError, withTransaction } from '@ultimat3/db';
16
+ import { type DriftReport, driftError, migrationForked, withTransaction } from '@ultimat3/db';
17
+ import { migrationFork } from '@ultimat3/db/schema-dump';
17
18
  import { postgresDriver } from '@ultimat3/entity';
18
19
  import { requireAppRoot } from './app-root';
19
20
  import { runBackfillCommand } from './cmd-db-backfill';
20
21
  import { runBranchCommand } from './cmd-db-branch';
21
22
  import { runRecountCommand } from './cmd-db-recount';
23
+ import { runRollbackCommand } from './cmd-db-rollback';
22
24
  import { DB_SUBCOMMANDS, dbSpec } from './cmd-db-spec';
23
25
  import { runDbStatus } from './cmd-db-status';
24
26
  import type { CliCommand, CommandContext } from './command';
27
+ import { refuseAppliedEdits } from './db-applied-edits';
25
28
  import { runDiagnostics } from './db-diagnostics';
26
29
  import { stepFinding } from './db-finding';
27
30
  import { generateAppMigration, unrenderedJson, unrenderedLines } from './db-generate';
28
- import { liveObjectDrift } from './db-object-drift';
31
+ import { migratePass } from './db-migrate-pass';
29
32
  import { layTemplate } from './db-reset-template';
30
33
  import { schemaDumpLines } from './db-schema-dump';
31
34
  import { afterWrittenMigration, refreshSchemaDump, schemaDumpJson } from './db-schema-refresh';
@@ -40,15 +43,16 @@ import {
40
43
  selectSeeds,
41
44
  } from './db-seed';
42
45
  import { runGeneratedSeed } from './db-seed-generate';
43
- import { DevAlreadyRunningError, liveDevLock } from './dev-lock';
46
+ import { refuseBesideDev, refuseEmbeddedWriteBesideDev } from './dev-lock-live';
44
47
  import { MissingSubcommandError, UnknownCommandError } from './errors';
48
+ import { type HeavyChild, withCheckoutLock } from './heavy';
45
49
  import { withJobDriver } from './jobs-driver';
46
50
  import { msg } from './messages';
51
+ import { readMigrations } from './migrations';
47
52
  import type { CommandResult, Finding } from './output';
48
53
  import { findingFrom } from './output';
49
54
  import { flagBool, flagString } from './parse';
50
55
  import { resolveServices } from './runtime-bindings';
51
- import { runMigrations } from './serve';
52
56
 
53
57
  export { DB_SUBCOMMANDS } from './cmd-db-spec';
54
58
 
@@ -66,6 +70,7 @@ export const dbCommand: CliCommand = {
66
70
 
67
71
  if (sub === 'gen') return runGen(ctx, root, argument ?? 'change');
68
72
  if (sub === 'migrate') return runMigrate(ctx, root, msg('cli.db.migrate.applied'));
73
+ if (sub === 'rollback') return runRollbackCommand(ctx, root);
69
74
  if (sub === 'reset') return runReset(ctx, root);
70
75
  if (sub === 'seed') return runSeed(ctx, root);
71
76
  if (sub === 'backfill') return runBackfillCommand(ctx, root);
@@ -99,13 +104,34 @@ export const dbCommand: CliCommand = {
99
104
  * exists when none does, or that nothing was written when the sidecar was.
100
105
  */
101
106
  async function runGen(ctx: CommandContext, root: string, name: string): Promise<CommandResult> {
107
+ // One at a time per checkout, from reading the newest sidecar to writing the dump. Two overlapping
108
+ // runs each diffed the same sidecar and each wrote `create table` for every new entity: a chain
109
+ // that cannot replay. The kernel drops the lock when its holder dies, so no stale file can wedge it.
110
+ return withCheckoutLock({ name: 'db-gen', root, env: ctx.env }, NO_CHILD, () =>
111
+ generateLocked(ctx, root, name),
112
+ );
113
+ }
114
+
115
+ /** `x db gen` starts no process under the lock, so there is nothing to hand one. */
116
+ const NO_CHILD: HeavyChild = { env: {}, fds: [] };
117
+
118
+ async function generateLocked(
119
+ ctx: CommandContext,
120
+ root: string,
121
+ name: string,
122
+ ): Promise<CommandResult> {
102
123
  let generated: Awaited<ReturnType<typeof generateAppMigration>>;
124
+ let unchecked: string | undefined;
103
125
  try {
126
+ // First, and before any file is written: over an applied migration edited since, this command
127
+ // rewrote the schema dump to match the edit and exited 0 (`db-applied-edits.ts`).
128
+ unchecked = await refuseAppliedEdits(root, ctx.env);
104
129
  generated = await generateAppMigration(root, {
105
130
  name,
106
131
  allowDestructive: flagBool(ctx.args, 'allow-destructive'),
107
132
  rollingUnsafe: flagBool(ctx.args, 'rolling-unsafe'),
108
133
  dropRedundant: flagBool(ctx.args, 'drop-redundant'),
134
+ mergeFork: flagBool(ctx.args, 'merge-fork'),
109
135
  });
110
136
  } catch (error) {
111
137
  return {
@@ -120,14 +146,22 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
120
146
  // this build cannot project would make every one of those instructions unfollowable — the
121
147
  // `x i18n add fr` failure, repeated. The count is the verdict; the gate's own `drift` step is
122
148
  // where a red belongs, and it reads the same list to decide that `x db gen` is not the fix.
123
- const lost = unrenderedLines(generated.unrendered);
149
+ const lost = [
150
+ ...unrenderedLines(generated.unrendered),
151
+ ...(unchecked === undefined ? [] : [msg('cli.db.gen.editsUnchecked', { reason: unchecked })]),
152
+ ];
124
153
  // After the migration, from the migrations alone: the dump is what replaying them produces, so
125
154
  // it is rewritten on all three outcomes — `unchanged` included, which is what makes this
126
155
  // command the `fix:` on `X_SCHEMA_DUMP_DRIFT` when a framework table or a hand edit moved it.
127
156
  const dump = await refreshSchemaDump(root, ctx.env);
128
157
  const dumpFindings = dump.finding === undefined ? [] : [dump.finding];
129
158
  const migration = generated.migration;
159
+ const newest = generated.newest;
130
160
  if (migration === undefined) {
161
+ const newestLine =
162
+ newest === undefined || generated.outcome === 'blocked'
163
+ ? []
164
+ : [msg('cli.db.gen.newest', { id: newest })];
131
165
  return {
132
166
  ok: generated.findings.length === 0 && dumpFindings.length === 0,
133
167
  command: 'db',
@@ -139,17 +173,32 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
139
173
  summary:
140
174
  generated.outcome === 'blocked'
141
175
  ? msg('cli.db.gen.blocked', { count: generated.findings.length })
142
- : generated.outcome === 'hash-recorded'
143
- ? msg('cli.db.gen.recorded', { file: generated.files[0] ?? '' })
144
- : dump.status === 'written'
145
- ? msg('cli.db.gen.dumped', { count: dump.written.length + dump.removed.length })
146
- : msg('cli.db.gen.unchanged'),
176
+ : generated.outcome === 'fork-merged'
177
+ ? msg('cli.db.gen.forkMerged', {
178
+ count: generated.forkRepairs ?? 0,
179
+ id: newest ?? '',
180
+ })
181
+ : generated.outcome === 'hash-recorded'
182
+ ? msg('cli.db.gen.recorded', { file: generated.files[0] ?? '' })
183
+ : dump.status === 'written'
184
+ ? msg('cli.db.gen.dumped', {
185
+ count: dump.written.length + dump.removed.length,
186
+ newest: newest ?? msg('cli.db.status.none'),
187
+ })
188
+ : msg('cli.db.gen.unchanged'),
147
189
  findings: [...generated.findings, ...dumpFindings],
148
190
  // `files` is what this command WROTE, so the empty array here was a false claim.
149
- lines: [...generated.files.map((file) => ` ${file}`), ...schemaDumpLines(dump), ...lost],
191
+ lines: [
192
+ ...generated.files.map((file) => ` ${file}`),
193
+ ...schemaDumpLines(dump),
194
+ ...newestLine,
195
+ ...lost,
196
+ ],
150
197
  data: {
151
198
  outcome: generated.outcome,
152
199
  migration: null,
200
+ newest: newest ?? null,
201
+ forkRepairs: generated.forkRepairs ?? 0,
153
202
  files: [...generated.files],
154
203
  schemaHash: generated.schemaHash ?? null,
155
204
  unrendered: unrenderedJson(generated.unrendered),
@@ -157,13 +206,30 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
157
206
  },
158
207
  };
159
208
  }
209
+ const tables = generated.tables ?? [];
210
+ // Every migration written, never the first alone: the follow-up is a file to apply too.
211
+ const followUp = migration.followUp?.id;
212
+ const written = (): string =>
213
+ followUp === undefined
214
+ ? tables.length === 0
215
+ ? msg('cli.db.gen.written', { id: migration.id })
216
+ : msg('cli.db.gen.writtenTables', { id: migration.id, tables: tables.join(', ') })
217
+ : tables.length === 0
218
+ ? msg('cli.db.gen.writtenPair', { id: migration.id, followUp })
219
+ : msg('cli.db.gen.writtenPairTables', {
220
+ id: migration.id,
221
+ followUp,
222
+ tables: tables.join(', '),
223
+ });
160
224
  return {
161
225
  ok: dumpFindings.length === 0,
162
226
  command: 'db',
163
227
  summary:
164
- dumpFindings.length === 0
165
- ? msg('cli.db.gen.written', { id: migration.id })
166
- : msg('cli.db.gen.writtenDumpFailed', { id: migration.id }),
228
+ dumpFindings.length > 0
229
+ ? msg('cli.db.gen.writtenDumpFailed', {
230
+ id: followUp === undefined ? migration.id : `${migration.id} and ${followUp}`,
231
+ })
232
+ : written(),
167
233
  // Exit 1 with a migration on disk: the finding has to say so, or the next move is a duplicate.
168
234
  findings: dumpFindings.map((finding) => afterWrittenMigration(finding, migration.id)),
169
235
  lines: [...generated.files.map((file) => ` ${file}`), ...schemaDumpLines(dump), ...lost],
@@ -173,6 +239,9 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
173
239
  // The `-- transaction: false` step written beside it, when the diff needed one.
174
240
  followUp: migration.followUp?.id ?? null,
175
241
  name: migration.name,
242
+ tables: [...tables],
243
+ newest: newest ?? migration.id,
244
+ forkRepairs: generated.forkRepairs ?? 0,
176
245
  files: [...generated.files],
177
246
  schemaHash: generated.schemaHash ?? null,
178
247
  unrendered: unrenderedJson(generated.unrendered),
@@ -206,17 +275,20 @@ async function runMigrate(
206
275
  summary: string,
207
276
  ): Promise<CommandResult> {
208
277
  try {
209
- const migrated = await runMigrations({ root, env: ctx.env });
210
- const report = migrated.report;
278
+ // Before anything is applied: a forked chain either stops halfway through a replay or finishes
279
+ // and reports its own table as drift, and neither result says what happened.
280
+ const fork = migrationFork(await readMigrations(root));
281
+ if (fork !== undefined) throw migrationForked(fork);
282
+ // Applied here, or by the `x dev` that holds the embedded database (`db-migrate-pass.ts`).
283
+ const pass = await migratePass(root, ctx.env);
211
284
  // A hand-written or pulled migration reaches the dump here, with no `x db gen` in between.
212
285
  const dump = await refreshSchemaDump(root, ctx.env);
213
286
  // The half a snapshot cannot hold: a trigger, function, view, type or sequence this database
214
287
  // carries and no migration creates. Asked only when the replay produced a catalog to ask
215
288
  // against — without one there is nothing that says what the migrations create.
216
- const objects =
217
- dump.catalog === undefined ? [] : await liveObjectDrift(root, ctx.env, dump.catalog);
289
+ const objects = dump.catalog === undefined ? [] : await pass.objects(dump.catalog);
218
290
  const findings = [
219
- ...driftFindings(migrated.drift),
291
+ ...driftFindings(pass.drift),
220
292
  ...objects.map((difference) => findingFrom(driftError(difference))),
221
293
  ...(dump.finding === undefined ? [] : [dump.finding]),
222
294
  ];
@@ -227,10 +299,10 @@ async function runMigrate(
227
299
  findings,
228
300
  lines: schemaDumpLines(dump),
229
301
  data: {
230
- applied: report.applied.map((entry) => entry.id),
231
- skipped: report.skipped.length,
232
- appVersion: report.appVersion,
233
- durationMs: report.durationMs,
302
+ applied: [...pass.applied],
303
+ skipped: pass.skipped,
304
+ appVersion: pass.appVersion,
305
+ durationMs: pass.durationMs,
234
306
  schemaDump: schemaDumpJson(dump),
235
307
  },
236
308
  };
@@ -263,14 +335,7 @@ async function runReset(ctx: CommandContext, root: string): Promise<CommandResul
263
335
  }
264
336
  // A running `x dev` has this directory open: deleting it under a live embedded Postgres is data
265
337
  // loss mid-write, not a reset. The dev lock is the one fact that says someone holds it.
266
- const holder = liveDevLock(services.stateDir);
267
- if (holder !== undefined) {
268
- throw new DevAlreadyRunningError({
269
- lock: holder,
270
- stateDir: services.stateDir,
271
- embeddedDb: true,
272
- });
273
- }
338
+ await refuseBesideDev(services.stateDir);
274
339
  const dataDir = join(services.stateDir, 'pgdata');
275
340
  await rm(dataDir, { recursive: true, force: true });
276
341
  // From the migrated template when it can be had (`db-reset-template.ts`); the migrate below runs
@@ -316,6 +381,13 @@ async function runSeed(ctx: CommandContext, root: string): Promise<CommandResult
316
381
  data: seedPassToJson([]),
317
382
  };
318
383
  }
384
+ // A seed writes through this command's own boot: beside an `x dev` holding the embedded
385
+ // database that is a second PGlite writer, whose rows the holder's next write replaces.
386
+ await refuseEmbeddedWriteBesideDev(root, ctx.env, [
387
+ 'db',
388
+ 'seed',
389
+ ...(name === undefined ? [] : [name]),
390
+ ]);
319
391
  return withJobDriver(root, ctx, async () => {
320
392
  const rows = await runSeeds({
321
393
  seeds: chosen,
@@ -28,9 +28,11 @@ import {
28
28
  UNGRADED,
29
29
  windowClosed,
30
30
  } from './deploy-verify-grade';
31
+ import { workerContainers } from './deploy-verify-processes';
31
32
  import { BadFlagError } from './errors';
32
33
  import { msg } from './messages';
33
34
  import type { CommandResult, Finding } from './output';
35
+ import { withAppTls } from './runtime-database-ssl';
34
36
 
35
37
  /** One sample's own limit: a pod that hangs is a bad sample, never the whole wait gone. */
36
38
  const SAMPLE_TIMEOUT_MS = 10_000;
@@ -160,11 +162,15 @@ async function readQueues(
160
162
  disarm.abort();
161
163
  }
162
164
  const [workers, demand] = rows;
163
- return gradeQueues({
164
- ...input,
165
- workers,
166
- depth: new Map(demand.map((queue) => [queue.queue, queue.demand])),
167
- });
165
+ return {
166
+ ...gradeQueues({
167
+ ...input,
168
+ workers,
169
+ depth: new Map(demand.map((queue) => [queue.queue, queue.demand])),
170
+ }),
171
+ // N rows under one host is a container running N processes (`ULTIMATE_PROCESSES`).
172
+ containers: workerContainers(workers, input.build),
173
+ };
168
174
  }
169
175
 
170
176
  /**
@@ -276,7 +282,9 @@ export async function runDeployVerify(
276
282
  // Read off the env directly: `resolveServices` falls back to the embedded database and would grade
277
283
  // an empty one, so a CI job with no credentials would "pass" having read nothing.
278
284
  const raw = ctx.env['DATABASE_URL'];
279
- const databaseUrl = raw === undefined || raw.trim() === '' ? undefined : raw;
285
+ // Under `database.ssl` as the roles dial it: the grade reads the database they serve from.
286
+ const databaseUrl =
287
+ raw === undefined || raw.trim() === '' ? undefined : await withAppTls(root, raw, ctx.env);
280
288
  const expected = databaseUrl === undefined ? undefined : await readExpected(root, options, deps);
281
289
  if (expected !== undefined && expected.findings.length > 0) {
282
290
  return failed(
@@ -0,0 +1,94 @@
1
+ // `x docs <topic-id>` — the id a search lists, handed back, answered with that topic's BODY. A
2
+ // terminal search prints titles; the body existed only under `--json`, cut at the index's excerpt
3
+ // length, so an agent opened `node_modules/@ultimat3/<pkg>/README.md` by hand to read one section.
4
+
5
+ // why: Bun ships no path module; a package's guide is joined onto the scope it was scanned from.
6
+ import { join } from 'node:path';
7
+ import type { DocEntry } from '@ultimat3/manifest';
8
+ import { wikiHeadings } from '@ultimat3/manifest';
9
+ import { msg } from './messages';
10
+ import type { CommandResult } from './output';
11
+
12
+ /** `@ultimat3/jobs` → `jobs`: a package's directory under a scope, installed or in this checkout. */
13
+ const directoryOf = (entry: DocEntry): string =>
14
+ entry.package.slice(entry.package.indexOf('/') + 1);
15
+
16
+ /**
17
+ * The whole section `entry` was cut from: its heading, its body and every subsection, to the next
18
+ * heading of the same or a higher level. `undefined` when the file or the heading is not found —
19
+ * the caller then prints the index's own excerpt, which is the same text, shorter.
20
+ */
21
+ async function guideSection(
22
+ entry: DocEntry,
23
+ scopes: readonly string[],
24
+ ): Promise<string | undefined> {
25
+ for (const scope of scopes) {
26
+ const file = Bun.file(join(scope, directoryOf(entry), entry.source));
27
+ if (!(await file.exists())) continue;
28
+ const markdown = await file.text();
29
+ const headings = wikiHeadings(markdown);
30
+ const index = headings.findIndex((heading) => heading.heading === entry.title);
31
+ const start = headings[index];
32
+ if (start === undefined) return undefined;
33
+ const end = headings.slice(index + 1).find((heading) => heading.level <= start.level);
34
+ const lines = markdown.split('\n');
35
+ return lines
36
+ .slice(start.line, end?.line ?? lines.length)
37
+ .join('\n')
38
+ .trimEnd();
39
+ }
40
+ return undefined;
41
+ }
42
+
43
+ /** A module's header comment and what it exports; a guide's section, whole. */
44
+ async function bodyOf(entry: DocEntry, scopes: readonly string[]): Promise<string> {
45
+ if (entry.kind === 'guide') return (await guideSection(entry, scopes)) ?? entry.text;
46
+ return entry.text;
47
+ }
48
+
49
+ /** The entry whose topic id IS the query — exact, so a question never lands here by accident. */
50
+ export const topicNamed = (entries: readonly DocEntry[], query: string): DocEntry | undefined =>
51
+ entries.find((entry) => entry.topic === query);
52
+
53
+ /** One topic, answered with its body in the terminal and in `--json` alike. */
54
+ export async function topicResult(
55
+ entry: DocEntry,
56
+ scopes: readonly string[],
57
+ query: string,
58
+ ): Promise<CommandResult> {
59
+ const text = await bodyOf(entry, scopes);
60
+ const exports =
61
+ entry.symbols.length === 0
62
+ ? []
63
+ : ['', ` ${msg('cli.docs.exports', { list: entry.symbols.join(', ') })}`];
64
+ return {
65
+ ok: true,
66
+ command: 'docs',
67
+ summary: msg('cli.docs.found', { count: 1, query }),
68
+ // The package's own prose, verbatim: quoted source, not this command's wording.
69
+ lines: [
70
+ ` ${entry.topic} ${entry.package}/${entry.source}`,
71
+ '',
72
+ ...text.split('\n').map((line) => ` ${line}`),
73
+ ...exports,
74
+ ],
75
+ data: {
76
+ matches: [
77
+ {
78
+ topic: entry.topic,
79
+ package: entry.package,
80
+ version: entry.version,
81
+ kind: entry.kind,
82
+ title: entry.title,
83
+ text,
84
+ symbols: [...entry.symbols],
85
+ source: entry.source,
86
+ matched: [],
87
+ score: 0,
88
+ },
89
+ ],
90
+ suggestions: [],
91
+ query,
92
+ },
93
+ };
94
+ }
package/src/cmd-docs.ts CHANGED
@@ -4,19 +4,23 @@
4
4
  // should not have to guess which of 29 packages holds the answer, and it must never be handed a
5
5
  // URL: `node_modules` already contains every doc, because the published artifact IS the source.
6
6
 
7
+ // why: Bun ships no path module; the CLI's own scope is its package directory's parent.
8
+ import { dirname } from 'node:path';
7
9
  import { ERROR_DOCS_URL } from '@ultimat3/core';
8
10
  import type { DocEntry, DocHit } from '@ultimat3/manifest';
9
11
  import { nearestTopics, searchDocs } from '@ultimat3/manifest';
10
12
  import { DEFAULT_LIMIT, docsSpec } from './cmd-docs-spec';
13
+ import { topicNamed, topicResult } from './cmd-docs-topic';
11
14
  import type { CliCommand, CommandContext } from './command';
12
15
  import { parseWikiTopic, sectionResult } from './docs-section';
13
- import { loadDocs, wikiSource } from './docs-sources';
16
+ import { cliPackageDir, loadDocs, wikiSource } from './docs-sources';
14
17
  import { MissingPositionalError } from './errors';
15
18
  import { frameworkScopeDir } from './framework-scope';
16
19
  import { parseLimitFlag } from './jobs-report';
17
20
  import { msg } from './messages';
18
21
  import type { CommandResult, Finding, JsonValue } from './output';
19
22
  import { flagString } from './parse';
23
+ import { quoteArg } from './shell-quote';
20
24
 
21
25
  /** An install where the CLI cannot see its own dependency is broken, not merely undocumented. */
22
26
  const unresolvedFinding = (): Finding => ({
@@ -69,6 +73,11 @@ function humanLines(hits: readonly DocHit[]): readonly string[] {
69
73
  );
70
74
  }
71
75
  }
76
+ // What to type next for the body: the id above, handed back. Inline, as every command here is.
77
+ const [first] = hits;
78
+ if (first !== undefined) {
79
+ lines.push(` x docs ${quoteArg(first.entry.topic)} # ${msg('cli.docs.tryTopic')}`);
80
+ }
72
81
  return lines;
73
82
  }
74
83
 
@@ -173,6 +182,11 @@ export const docsCommand: CliCommand = {
173
182
 
174
183
  const { entries, wiki } = await loadDocs(scope);
175
184
  const findings = wiki === undefined ? [noWikiFinding()] : [];
185
+ // A topic id — what every search line starts with — is answered with that topic's body.
186
+ const named = topicNamed(entries, query);
187
+ if (named !== undefined) {
188
+ return topicResult(named, [scope, dirname(cliPackageDir())], query);
189
+ }
176
190
  // `x jobs list --limit`'s reader, and its `command` parameter exists for exactly this second
177
191
  // caller. A local `Number.parseInt` accepted `--limit 1e9` as 1 and answered with one match,
178
192
  // and fell silently through to the default for `abc`, `0` and `-3` — a bound other than the one