@ultimat3/cli 31.48.0 → 31.50.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 (287) hide show
  1. package/CLAUDE.md +30 -23
  2. package/README.md +96 -4
  3. package/package.json +30 -30
  4. package/src/api-registration.ts +45 -14
  5. package/src/api-routes.ts +1 -0
  6. package/src/app-load.ts +7 -3
  7. package/src/app-openapi.ts +7 -1
  8. package/src/app-root.ts +7 -1
  9. package/src/budgets.ts +2 -1
  10. package/src/clean-services.ts +142 -0
  11. package/src/cmd-auth.ts +3 -0
  12. package/src/cmd-clean-spec.ts +10 -3
  13. package/src/cmd-clean.ts +23 -9
  14. package/src/cmd-db-backfill.ts +6 -0
  15. package/src/cmd-db-branch.ts +10 -4
  16. package/src/cmd-db-recount.ts +5 -12
  17. package/src/cmd-db-rollback.ts +77 -0
  18. package/src/cmd-db-spec.ts +18 -2
  19. package/src/cmd-db-status.ts +5 -10
  20. package/src/cmd-db.ts +105 -33
  21. package/src/cmd-deploy-verify.ts +14 -6
  22. package/src/cmd-docs-topic.ts +94 -0
  23. package/src/cmd-docs.ts +15 -1
  24. package/src/cmd-doctor.ts +109 -41
  25. package/src/cmd-drill.ts +80 -18
  26. package/src/cmd-env.ts +30 -8
  27. package/src/cmd-errors-app.ts +63 -0
  28. package/src/cmd-errors.ts +50 -14
  29. package/src/cmd-generate.ts +17 -4
  30. package/src/cmd-heavy-spec.ts +9 -1
  31. package/src/cmd-heavy.ts +111 -27
  32. package/src/cmd-i18n.ts +33 -1
  33. package/src/cmd-jobs.ts +27 -1
  34. package/src/cmd-merge-driver-spec.ts +12 -0
  35. package/src/cmd-merge-driver.ts +95 -0
  36. package/src/cmd-new.ts +23 -3
  37. package/src/cmd-policy-spec.ts +9 -1
  38. package/src/cmd-policy.ts +72 -17
  39. package/src/cmd-stop.ts +18 -4
  40. package/src/cmd-tasks-run.ts +87 -0
  41. package/src/cmd-tasks-spec.ts +10 -3
  42. package/src/cmd-tasks.ts +8 -5
  43. package/src/cmd-test.ts +2 -1
  44. package/src/cmd-upgrade-spec.ts +8 -1
  45. package/src/cmd-upgrade.ts +15 -1
  46. package/src/cmd-verify.ts +9 -41
  47. package/src/codemods/agents-doc-row.ts +73 -0
  48. package/src/codemods/define-error-leaf.ts +37 -12
  49. package/src/codemods/docs-many-agents.ts +11 -15
  50. package/src/codemods/docs-worker-commands.ts +26 -0
  51. package/src/codemods/engine-fs.ts +9 -2
  52. package/src/codemods/index.ts +4 -0
  53. package/src/codemods/merge-drivers.ts +147 -0
  54. package/src/command.ts +3 -0
  55. package/src/db-applied-edits.ts +117 -0
  56. package/src/db-dev-wire.ts +18 -0
  57. package/src/db-diagnostics.ts +5 -10
  58. package/src/db-generate.ts +82 -7
  59. package/src/db-migrate-pass.ts +51 -0
  60. package/src/db-migrate-through-dev.ts +209 -0
  61. package/src/db-rollback-consent.ts +128 -0
  62. package/src/db-rollback-pass.ts +76 -0
  63. package/src/db-seed-generate.ts +5 -1
  64. package/src/db-seed.ts +7 -1
  65. package/src/deploy-verify-findings.ts +3 -0
  66. package/src/deploy-verify-grade.ts +3 -0
  67. package/src/deploy-verify-processes.ts +32 -0
  68. package/src/dev-boot.ts +3 -0
  69. package/src/dev-db-migrate.ts +155 -0
  70. package/src/dev-db-rollback.ts +33 -0
  71. package/src/dev-db-settled.ts +22 -0
  72. package/src/dev-lock-errors.ts +78 -0
  73. package/src/dev-lock-holder-dir.ts +64 -0
  74. package/src/dev-lock-live.ts +44 -0
  75. package/src/dev-lock.ts +59 -84
  76. package/src/dev-policy.ts +11 -8
  77. package/src/dev-rebuild-schema.ts +116 -13
  78. package/src/dev-rebuild.ts +13 -4
  79. package/src/dev-route-table.ts +7 -0
  80. package/src/dispatch.ts +21 -1
  81. package/src/doctor-api-listing.ts +114 -0
  82. package/src/doctor-guarded.ts +41 -0
  83. package/src/doctor-port.ts +90 -17
  84. package/src/doctor-probe.ts +36 -5
  85. package/src/doctor-processes-probe.ts +127 -0
  86. package/src/doctor-processes.ts +136 -0
  87. package/src/doctor-warnings.ts +17 -0
  88. package/src/error-codes-agents.ts +35 -0
  89. package/src/error-codes-processes.ts +30 -0
  90. package/src/error-codes-tooling.ts +2 -0
  91. package/src/error-codes.ts +12 -13
  92. package/src/errors-suite.ts +27 -0
  93. package/src/errors.ts +18 -22
  94. package/src/exercise-registration.ts +4 -3
  95. package/src/exercise-services.ts +13 -3
  96. package/src/framework-env.ts +7 -3
  97. package/src/framework-schema.ts +15 -5
  98. package/src/generate-files.ts +1 -0
  99. package/src/generate-grant-findings.ts +7 -5
  100. package/src/generate-grants.ts +9 -8
  101. package/src/generate-kinds.ts +30 -6
  102. package/src/generate-roles-file.ts +30 -0
  103. package/src/generate-slice-policy.ts +3 -3
  104. package/src/guard-sources.ts +1 -2
  105. package/src/guards.ts +2 -2
  106. package/src/heavy-env.ts +2 -0
  107. package/src/heavy-errors.ts +18 -0
  108. package/src/heavy-holders.ts +78 -0
  109. package/src/heavy-ledger.ts +56 -14
  110. package/src/heavy-pressure.ts +104 -0
  111. package/src/heavy.ts +31 -13
  112. package/src/i18n-registration.ts +22 -2
  113. package/src/island-harness.ts +2 -2
  114. package/src/job-budget.ts +4 -2
  115. package/src/job-registration.ts +64 -8
  116. package/src/jobs-queue-known.ts +43 -0
  117. package/src/mcp-errors-agents.ts +20 -0
  118. package/src/mcp-errors-doctor.ts +27 -0
  119. package/src/mcp-errors-processes.ts +23 -0
  120. package/src/mcp-errors.ts +15 -29
  121. package/src/mcp-host.ts +2 -2
  122. package/src/merge-driver-catalog.ts +58 -0
  123. package/src/merge-driver-config.ts +43 -0
  124. package/src/merge-driver-lines.ts +140 -0
  125. package/src/merge-state.ts +105 -0
  126. package/src/messages-db.ts +22 -1
  127. package/src/messages-processes.ts +13 -0
  128. package/src/messages-upgrade.ts +10 -0
  129. package/src/messages.ts +54 -4
  130. package/src/output-findings.ts +48 -21
  131. package/src/page-navigation.ts +5 -2
  132. package/src/parse.ts +37 -6
  133. package/src/policy-facts.ts +38 -21
  134. package/src/policy-row.ts +99 -0
  135. package/src/port-pair-free.ts +28 -0
  136. package/src/pwa-artifacts.ts +1 -1
  137. package/src/registry-lines.ts +110 -0
  138. package/src/registry.ts +2 -0
  139. package/src/retain-sweep.ts +1 -1
  140. package/src/retained-assets-boot.ts +1 -1
  141. package/src/role-replicator.ts +4 -1
  142. package/src/role-select.ts +86 -0
  143. package/src/role-start.ts +13 -55
  144. package/src/role-sync.ts +10 -5
  145. package/src/runtime-assets-site.ts +2 -2
  146. package/src/runtime-assets.ts +1 -1
  147. package/src/runtime-cache-frame.ts +46 -0
  148. package/src/runtime-cache-ttl.ts +23 -0
  149. package/src/runtime-cache.ts +33 -16
  150. package/src/runtime-database-ssl.ts +84 -0
  151. package/src/runtime-idempotency-scope.ts +16 -2
  152. package/src/runtime-jobs-share.ts +52 -0
  153. package/src/runtime-jobs.ts +43 -12
  154. package/src/runtime-queue.ts +18 -3
  155. package/src/runtime-render-document.ts +1 -2
  156. package/src/runtime-services.ts +8 -1
  157. package/src/schema-drift.ts +19 -2
  158. package/src/schema-dump-drift.ts +4 -1
  159. package/src/serve-boot-probe.ts +30 -2
  160. package/src/serve-boot.ts +11 -1
  161. package/src/serve-env.ts +39 -3
  162. package/src/serve.ts +61 -10
  163. package/src/site-asset-routes.ts +2 -2
  164. package/src/site-assets.ts +5 -158
  165. package/src/stop-run-start.ts +12 -0
  166. package/src/supervise-boot.ts +61 -0
  167. package/src/supervise-cgroup.ts +84 -0
  168. package/src/supervise-child.ts +206 -0
  169. package/src/supervise-count.ts +244 -0
  170. package/src/supervise-errors.ts +83 -0
  171. package/src/supervise-facts.ts +40 -0
  172. package/src/supervise-messages.ts +84 -0
  173. package/src/supervise-policy.ts +46 -0
  174. package/src/supervise-pool.ts +10 -0
  175. package/src/supervise-probe.ts +158 -0
  176. package/src/supervise-run.ts +54 -0
  177. package/src/supervise.ts +383 -0
  178. package/src/sw-precache-plan.ts +1 -1
  179. package/src/templates/generate-purge.ts +6 -6
  180. package/src/templates/guard-animated-layout-property.ts +2 -2
  181. package/src/templates/guard-bare-error.ts +1 -1
  182. package/src/templates/guard-error-declared.ts +2 -2
  183. package/src/templates/guard-focus-visible.ts +1 -1
  184. package/src/templates/guard-image-dimensions.ts +2 -2
  185. package/src/templates/guard-island-mount-clears.ts +1 -1
  186. package/src/templates/guard-native-confirm.ts +1 -1
  187. package/src/templates/guard-raw-breakpoint.ts +2 -2
  188. package/src/templates/guard-raw-colour.ts +2 -2
  189. package/src/templates/guard-raw-fetch.ts +1 -1
  190. package/src/templates/guard-raw-interval.ts +1 -1
  191. package/src/templates/guard-raw-length.ts +3 -3
  192. package/src/templates/guard-raw-motion.ts +97 -1
  193. package/src/templates/guard-raw-shadow.ts +1 -1
  194. package/src/templates/guard-raw-z-index.ts +1 -1
  195. package/src/templates/guard-released-forms.ts +58 -9
  196. package/src/templates/guard-repo-await-in-loop.ts +1 -1
  197. package/src/templates/guard-repo-raw-sql.ts +4 -4
  198. package/src/templates/guard-repo-unbounded.ts +1 -1
  199. package/src/templates/guard-runtime-pin.ts +1 -1
  200. package/src/templates/guard-semantic-interactive.ts +2 -2
  201. package/src/templates/guard-unbounded-fanout.ts +1 -1
  202. package/src/templates/guard-undeclared-custom-property.ts +3 -3
  203. package/src/templates/guard-undefined-style-class.ts +3 -3
  204. package/src/templates/guard-unzoned-date.ts +3 -3
  205. package/src/templates/query-slice.ts +82 -0
  206. package/src/templates/query.ts +76 -30
  207. package/src/templates/resource-page.ts +3 -2
  208. package/src/templates/scaffold-bin.ts +2 -0
  209. package/src/templates/scaffold-claude-commands.ts +6 -0
  210. package/src/templates/scaffold-claude.ts +4 -4
  211. package/src/templates/scaffold-container-compose.ts +47 -7
  212. package/src/templates/scaffold-docs.ts +7 -3
  213. package/src/templates/scaffold-gitattributes.ts +18 -1
  214. package/src/templates/scaffold-helm-templates.ts +9 -0
  215. package/src/templates/scaffold-repo.ts +5 -2
  216. package/src/templates/scaffold-test-services.ts +33 -11
  217. package/src/templates/shapes/offline.ts +0 -7
  218. package/src/templates/shapes/realtime.ts +2 -6
  219. package/src/templates/sign-in-action-tests.ts +6 -4
  220. package/src/templates/sign-in-challenge.ts +62 -0
  221. package/src/templates/sign-in-oidc-mfa.ts +31 -0
  222. package/src/templates/sign-in-oidc.ts +11 -3
  223. package/src/templates/sign-in-password.ts +18 -56
  224. package/src/test-only-shipped.ts +29 -2
  225. package/src/test-shards.ts +134 -42
  226. package/src/test-verdict.ts +79 -0
  227. package/src/test-workers.ts +15 -0
  228. package/src/upgrade-coverage-ratchet.ts +95 -0
  229. package/src/upgrade-gate-codemods.ts +5 -3
  230. package/src/upgrade-gate.ts +42 -4
  231. package/src/upgrade-merge-drivers.ts +25 -0
  232. package/src/upgrade-report.ts +32 -4
  233. package/src/upgrade-scope.ts +62 -0
  234. package/src/verify-checks.ts +2 -8
  235. package/src/verify-coverage-run.ts +4 -1
  236. package/src/verify-e2e.ts +21 -3
  237. package/src/verify-live.ts +38 -14
  238. package/src/verify-only.ts +67 -0
  239. package/src/verify-progress.ts +7 -3
  240. package/src/verify-run.ts +20 -2
  241. package/src/verify-services-stack.ts +165 -0
  242. package/src/verify-services.ts +84 -2
  243. package/src/verify-test-run.ts +6 -7
  244. package/src/verify-tests.ts +8 -2
  245. package/src/verify-typecheck.ts +25 -2
  246. package/src/workspace-checks.ts +4 -1
  247. package/wiki/Actions.md +66 -3
  248. package/wiki/Admin-Dashboard.md +2 -2
  249. package/wiki/Agents.md +5 -5
  250. package/wiki/Auth.md +20 -6
  251. package/wiki/Bare-VM.md +1 -1
  252. package/wiki/CI-Parallel-Gate.md +2 -1
  253. package/wiki/CLI-Reference.md +115 -42
  254. package/wiki/Caching-And-Invalidation.md +1 -1
  255. package/wiki/Client-Navigation.md +35 -5
  256. package/wiki/Configuration.md +12 -10
  257. package/wiki/Deployment.md +44 -4
  258. package/wiki/Entities-And-Migrations.md +17 -3
  259. package/wiki/FAQ.md +1 -1
  260. package/wiki/Getting-Started.md +2 -2
  261. package/wiki/Home.md +3 -3
  262. package/wiki/I18n.md +6 -4
  263. package/wiki/Installation.md +12 -11
  264. package/wiki/Interface-Rules.md +3 -1
  265. package/wiki/Jobs-And-Workflows.md +24 -4
  266. package/wiki/Known-Gaps.md +2 -2
  267. package/wiki/MCP-And-AI.md +48 -13
  268. package/wiki/Many-Agents.md +69 -2
  269. package/wiki/Migrations-And-Backfills.md +18 -0
  270. package/wiki/Notify.md +5 -3
  271. package/wiki/Observability.md +13 -0
  272. package/wiki/Outbound-HTTP.md +53 -2
  273. package/wiki/Policies-And-Authz.md +1 -1
  274. package/wiki/Queries-And-Live-Queries.md +2 -2
  275. package/wiki/Realtime.md +24 -7
  276. package/wiki/Routes-And-Render-Modes.md +2 -2
  277. package/wiki/Scheduled-Tasks.md +4 -1
  278. package/wiki/Static-Assets.md +5 -3
  279. package/wiki/Testing.md +64 -7
  280. package/wiki/Theming.md +6 -3
  281. package/wiki/Timezones-And-Dates.md +5 -1
  282. package/wiki/Troubleshooting.md +1 -0
  283. package/wiki/Tutorial-01-First-App.md +3 -3
  284. package/wiki/Tutorial-02-First-Feature.md +1 -1
  285. package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
  286. package/wiki/UI-Components.md +1 -0
  287. package/wiki/Upgrading.md +38 -0
package/src/cmd-doctor.ts CHANGED
@@ -15,12 +15,16 @@ import { browserProbe, browserWarnings, withBrowserReport } from './doctor-brows
15
15
  import { chartAlertsProbe, NOTHING_MISSING, withChartAlertsListing } from './doctor-chart-alerts';
16
16
  import { coverageExcludesProbe, withCoverageExcludes } from './doctor-coverage';
17
17
  import { embeddedDatabaseFinding } from './doctor-database';
18
+ import { guardedCheck, guardedListing } from './doctor-guarded';
18
19
  import { shippedGuardsProbe, vendoredGuardWarnings, withGuardListing } from './doctor-guards';
19
20
  import { offlineFallbackFinding } from './doctor-offline';
20
21
  import { NO_POOLER_FACT, poolerFindings, withPoolerReport } from './doctor-pooler';
21
- import { doctorPort, portFindings } from './doctor-port';
22
+ import { doctorPort, ownerAskedOnce, portFindings } from './doctor-port';
22
23
  import type { DoctorProbe } from './doctor-probe';
23
24
  import { probeFor } from './doctor-probe';
25
+ import type { ProcessesFact } from './doctor-processes';
26
+ import { processesWarnings, withProcessesReport } from './doctor-processes';
27
+ import { hostProcessesSources, processesFact } from './doctor-processes-probe';
24
28
  import { redundantIndexesProbe, withRedundantIndexes } from './doctor-redundant-indexes';
25
29
  import { rollingSinceProbe, withRollingReminder } from './doctor-rolling';
26
30
  import { sealedKeyFindings } from './doctor-sealed';
@@ -31,6 +35,7 @@ import { ICON_SOURCE } from './icon-assets';
31
35
  import { msg } from './messages';
32
36
  import type { CommandResult, Finding } from './output';
33
37
  import { cliVersion } from './registry';
38
+ import { withAppTls } from './runtime-database-ssl';
34
39
  import { quoteArg } from './shell-quote';
35
40
 
36
41
  // `src/index.ts` publishes the seam from here; its declaration lives in `doctor-probe.ts`.
@@ -70,9 +75,18 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
70
75
  );
71
76
  return findings;
72
77
  }
78
+ // Every check below through `check`: one that throws is that check's finding, not the report's end.
79
+ const check = (name: string, run: () => Promise<void>): Promise<void> =>
80
+ guardedCheck(name, findings, run);
81
+ // First of the app's checks: an unfinished merge explains most of what any later one reports.
82
+ await check('merge state', async () => {
83
+ findings.push(...((await probe.mergeState?.()) ?? []));
84
+ });
73
85
  // Right after the runtime and for its reason: a compiler a major behind reds typecheck and build
74
86
  // on the framework's own files, and every finding below is read through a gate that cannot pass.
75
- findings.push(...typescriptFindings(await probe.typescript()));
87
+ await check('typescript', async () => {
88
+ findings.push(...typescriptFindings(await probe.typescript()));
89
+ });
76
90
  if (!probe.exists(ENV_DEVELOPMENT)) {
77
91
  findings.push(
78
92
  finding(
@@ -93,7 +107,9 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
93
107
  // Silent in development and on a shell naming no environment; reported where this machine names
94
108
  // a deploy. One list, one wording (`framework-env.ts`, #679).
95
109
  findings.push(...probe.frameworkFindings);
96
- findings.push(...(await portFindings(probe)));
110
+ await check('port', async () => {
111
+ findings.push(...(await portFindings(probe)));
112
+ });
97
113
  findings.push(...appUrlFindings(probe.appUrl, probe.port));
98
114
  // `@ultimat3/pwa`'s own codes, not CLI twins of them. `X_PWA_NO_ICON_SOURCE` and
99
115
  // `X_PWA_NO_FALLBACK` used to be declared here for the same two conditions the package already
@@ -116,29 +132,41 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
116
132
  // `apps/web/app/offline.tsx`, which is not a route file at all (`assertRouteFilename` refuses
117
133
  // it), so no app could clear the finding and its own `fix:` did not either. `doctor-offline.ts`
118
134
  // holds the rule and the reasons.
119
- const offline = offlineFallbackFinding(await probe.offlineFallback());
120
- if (offline !== undefined) findings.push(offline);
121
- const pooler = await probe.pooler();
122
- findings.push(...poolerFindings(pooler));
123
- // A pooler's refusal is every other database probe's answer too, and its fix is the true one: this
124
- // one's says "set DATABASE_URL" to an operator whose URL is right.
125
- const database = pooler.refused === undefined ? await probe.database() : null;
126
- if (database !== null) findings.push(database);
127
- // The other half of the same question, and the half a bare VM lands on: `database()` is silent
128
- // where there is no `DATABASE_URL`, and that silence IS the bare-VM configuration.
129
- const embedded = embeddedDatabaseFinding(await probe.embeddedDatabase());
130
- if (embedded !== undefined) findings.push(embedded);
131
- // Asked only of a database that answered: an unreachable one is already the finding above.
132
- const reachable = pooler.refused === undefined && database === null;
133
- if (reachable) findings.push(...((await probe.rowSecurity?.()) ?? []));
134
- findings.push(...(await probe.drift()));
135
+ await check('offline fallback', async () => {
136
+ const offline = offlineFallbackFinding(await probe.offlineFallback());
137
+ if (offline !== undefined) findings.push(offline);
138
+ });
139
+ await check('database', async () => {
140
+ const pooler = await probe.pooler();
141
+ findings.push(...poolerFindings(pooler));
142
+ // A pooler's refusal is every other database probe's answer too, and its fix is the true one:
143
+ // this one's says "set DATABASE_URL" to an operator whose URL is right.
144
+ const database = pooler.refused === undefined ? await probe.database() : null;
145
+ if (database !== null) findings.push(database);
146
+ // The other half of the same question, and the half a bare VM lands on: `database()` is silent
147
+ // where there is no `DATABASE_URL`, and that silence IS the bare-VM configuration.
148
+ const embedded = embeddedDatabaseFinding(await probe.embeddedDatabase());
149
+ if (embedded !== undefined) findings.push(embedded);
150
+ // Asked only of a database that answered: an unreachable one is already the finding above.
151
+ const reachable = pooler.refused === undefined && database === null;
152
+ if (reachable) findings.push(...((await probe.rowSecurity?.()) ?? []));
153
+ });
154
+ await check('migration drift', async () => {
155
+ findings.push(...(await probe.drift()));
156
+ });
135
157
  // Last, and it is why `X_CLI_UNEXPECTED`'s `fix: x doctor --json` is not a dead end on the path an
136
158
  // author reaches it from: `x db gen` throwing `X_MIGRATION_SNAPSHOT_MISSING` used to be a
137
159
  // condition this diagnostic could not see at all, so the fix line ran clean over a broken app.
138
- findings.push(...(await probe.snapshots()));
160
+ await check('migration snapshots', async () => {
161
+ findings.push(...(await probe.snapshots()));
162
+ });
139
163
  // Sealed columns against the key ring: no key at all, or a rotation whose re-seal is pending.
140
- findings.push(...sealedKeyFindings(await probe.sealedKeys()));
141
- findings.push(...authStorageFindings(await probe.authStorage()));
164
+ await check('sealed keys', async () => {
165
+ findings.push(...sealedKeyFindings(await probe.sealedKeys()));
166
+ });
167
+ await check('auth storage', async () => {
168
+ findings.push(...authStorageFindings(await probe.authStorage()));
169
+ });
142
170
  // `X_FRAMEWORK_PIN_RANGE`, `X_ENV_NAME_RESERVED`, `X_DB_ROW_SECURITY_OFF` and
143
171
  // `X_VERIFY_STEP_UNFLOORED` are not here: on `main` they warn beside the verdict
144
172
  // (`doctor-warnings.ts`), so an upgrade with no change keeps this green.
@@ -152,14 +180,31 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
152
180
  export interface DoctorReportProbe extends DoctorProbe {
153
181
  /** Which Chrome the e2e driver would launch, and whether one is required (`doctor-browser.ts`). */
154
182
  browser(): Promise<BrowserFact | undefined>;
183
+ /** Processes per container and the connections they hold (`doctor-processes.ts`); unset: unasked. */
184
+ processes?(): Promise<ProcessesFact>;
185
+ /**
186
+ * The release codemods still owed are measured up to: the CLI's own, `cliVersion()`. A fact like
187
+ * the rest, never read inside the report: from the stamp, a release bump moved every report test.
188
+ */
189
+ readonly release: string;
155
190
  }
156
191
 
157
192
  /** The whole report over one probe: the verdict, then the listings and warnings beside it. */
158
193
  export async function reportDoctor(probe: DoctorReportProbe): Promise<CommandResult> {
159
- // Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers.
160
- const pooler = probe.root === undefined ? NO_POOLER_FACT : await probe.pooler();
161
- const findings = await runDoctor({ ...probe, pooler: async () => pooler });
162
- const guardEntries = probe.root === undefined ? [] : await shippedGuardsProbe(probe.root);
194
+ // A listing that throws costs that listing, reported beside the rest (`doctor-guarded.ts`).
195
+ const failed: Finding[] = [];
196
+ const inApp = <T>(name: string, read: (root: string) => Promise<T>, none: T): Promise<T> => {
197
+ const { root } = probe;
198
+ return root === undefined
199
+ ? Promise.resolve(none)
200
+ : guardedListing(name, failed, () => read(root), none);
201
+ };
202
+ // Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers. The port's
203
+ // owner too: the verdict and the warnings partition one answer (`ownerAskedOnce`).
204
+ const pooler = await inApp('pooler', () => probe.pooler(), NO_POOLER_FACT);
205
+ const asked = { ...probe, pooler: async () => pooler, portOwner: ownerAskedOnce(probe) };
206
+ const findings = await runDoctor(asked);
207
+ const guardEntries = await inApp('shipped guards', shippedGuardsProbe, []);
163
208
  const listed = withGuardListing(
164
209
  {
165
210
  ok: findings.length === 0,
@@ -177,37 +222,50 @@ export async function reportDoctor(probe: DoctorReportProbe): Promise<CommandRes
177
222
  // The second listing: what the coverage floor does not see (`doctor-coverage.ts`).
178
223
  const covered = withCoverageExcludes(
179
224
  listed,
180
- probe.root === undefined ? [] : await coverageExcludesProbe(probe.root),
225
+ await inApp('coverage excludes', coverageExcludesProbe, []),
181
226
  );
182
227
  // The third: the monitoring templates and dashboard the chart predates (`doctor-chart-alerts.ts`).
183
228
  const charted = withChartAlertsListing(
184
229
  covered,
185
- probe.root === undefined ? NOTHING_MISSING : chartAlertsProbe(probe.root),
230
+ await inApp('chart alerts', async (root) => chartAlertsProbe(root), NOTHING_MISSING),
186
231
  );
187
232
  // The fourth: implicit indexes another already serves (`doctor-redundant-indexes.ts`).
188
233
  const indexed = withRedundantIndexes(
189
234
  charted,
190
- probe.root === undefined ? undefined : await redundantIndexesProbe(probe.root),
235
+ await inApp('redundant indexes', redundantIndexesProbe, undefined),
191
236
  );
192
237
  // A reminder, not a finding: the rolling rail is off until this is set (`doctor-rolling.ts`).
193
238
  const reminded = withPoolerReport(
194
- withRollingReminder(
195
- indexed,
196
- probe.root === undefined ? undefined : await rollingSinceProbe(probe.root),
197
- ),
239
+ withRollingReminder(indexed, await inApp('rolling deploys', rollingSinceProbe, undefined)),
198
240
  pooler,
199
241
  );
200
242
  // Last, and beside the verdict on `main`: the 31.16.0 checks (`doctor-warnings.ts`).
201
243
  // A copy of a shipped guard among them (`X_GUARD_VENDORED`): a warning, so exit stays.
202
- const browser = await probe.browser();
203
- return withDoctorWarnings(withBrowserReport(reminded, browser), [
204
- ...(await doctorWarnings(probe)),
244
+ const browser = await guardedListing('browser', failed, () => probe.browser(), undefined);
245
+ const { processes } = probe;
246
+ const counted =
247
+ processes === undefined
248
+ ? undefined
249
+ : await inApp<ProcessesFact | undefined>('processes', processes, undefined);
250
+ const warnings = await guardedListing('warnings', failed, () => doctorWarnings(asked), []);
251
+ const superseded = await inApp('superseded workarounds', supersededFindings, []);
252
+ const floors = await inApp('advisory floors', advisoryFloorFindings, []);
253
+ // An `x upgrade` driven by a CLI older than the codemod engine left files it owed.
254
+ const codemods = await inApp(
255
+ 'pending codemods',
256
+ (root) => pendingCodemodFindings(root, probe.release),
257
+ [],
258
+ );
259
+ const reported = counted === undefined ? reminded : withProcessesReport(reminded, counted);
260
+ return withDoctorWarnings(withBrowserReport(reported, browser), [
261
+ ...warnings,
262
+ ...(counted === undefined ? [] : processesWarnings(counted)),
205
263
  ...vendoredGuardWarnings(guardEntries),
206
264
  ...browserWarnings(browser),
207
- ...(probe.root === undefined ? [] : await supersededFindings(probe.root)),
208
- ...(probe.root === undefined ? [] : await advisoryFloorFindings(probe.root)),
209
- // An `x upgrade` driven by a CLI older than the codemod engine left files it owed.
210
- ...(probe.root === undefined ? [] : await pendingCodemodFindings(probe.root, cliVersion())),
265
+ ...superseded,
266
+ ...floors,
267
+ ...codemods,
268
+ ...failed,
211
269
  ]);
212
270
  }
213
271
 
@@ -216,6 +274,16 @@ export const doctorCommand: CliCommand = {
216
274
  run(ctx: CommandContext): Promise<CommandResult> {
217
275
  const port = doctorPort(ctx.args, ctx.env);
218
276
  const probe = probeFor(ctx.cwd, ctx.bunVersion, port, ctx.env);
219
- return reportDoctor({ ...probe, browser: () => browserProbe(probe.root, ctx.env) });
277
+ const { root } = probe;
278
+ const databaseUrl = () => withAppTls(root, ctx.env['DATABASE_URL'], ctx.env);
279
+ return reportDoctor({
280
+ ...probe,
281
+ browser: () => browserProbe(root, ctx.env),
282
+ release: cliVersion(),
283
+ // Outside an app there is no container to count, and `reportDoctor` asks no in-app listing.
284
+ ...(root === undefined
285
+ ? {}
286
+ : { processes: () => processesFact(hostProcessesSources(root, ctx.env, databaseUrl)) }),
287
+ });
220
288
  },
221
289
  };
package/src/cmd-drill.ts CHANGED
@@ -4,7 +4,12 @@
4
4
  // and the verdict are testing's. Not a gate step: it needs Postgres, and `x verify` needs nothing.
5
5
 
6
6
  import type { AppConfig } from '@ultimat3/core';
7
- import { DRAIN_DEADLINE_DEFAULT_MS, frameworkVersion, MAX_TIMER_MS } from '@ultimat3/core';
7
+ import {
8
+ DRAIN_DEADLINE_DEFAULT_MS,
9
+ frameworkVersion,
10
+ isUltimateError,
11
+ MAX_TIMER_MS,
12
+ } from '@ultimat3/core';
8
13
  import type {
9
14
  Drill,
10
15
  DrillConfig,
@@ -39,6 +44,7 @@ import { UnknownCommandError } from './errors';
39
44
  import { readIntFlag } from './flag-number';
40
45
  import { msg } from './messages';
41
46
  import type { CommandResult, Finding, JsonValue } from './output';
47
+ import { findingFrom } from './output';
42
48
  import { flagBool } from './parse';
43
49
  import { replicatedRelations } from './role-replicator';
44
50
 
@@ -98,7 +104,10 @@ const reportJson = (report: DrillReport): JsonValue =>
98
104
  ),
99
105
  ) as JsonValue;
100
106
 
101
- const findingsOf = (report: DrillReport): readonly Finding[] =>
107
+ /** A report's failures, each as `X_DRILL_FAILED`: the name and the verdict are all it reads. */
108
+ type JudgedDrill = Pick<DrillReport, 'name' | 'verdict'>;
109
+
110
+ const findingsOf = (report: JudgedDrill): readonly Finding[] =>
102
111
  report.verdict.failures.map((failure) => {
103
112
  const error = new DrillFailedError({ drill: report.name, failure });
104
113
  return { code: error.code, cause: error.cause, fix: error.fix };
@@ -107,28 +116,79 @@ const findingsOf = (report: DrillReport): readonly Finding[] =>
107
116
  /** The evidence connection: `bunDrillSql`'s shape, a seam so a test can make it throw. */
108
117
  type DrillSqlConnection = ReturnType<typeof bunDrillSql>;
109
118
 
119
+ /**
120
+ * The body's value — or what it threw — and the teardown's refusal (a scratch database left
121
+ * behind) as a finding. Both halves on both paths: a throw must not take the leak's finding with it.
122
+ */
123
+ export type DrillFleetRun<T> = ({ readonly value: T } | { readonly thrown: unknown }) & {
124
+ readonly teardown: readonly Finding[];
125
+ };
126
+
127
+ /** Stop the fleet; a coded refusal is answered as a finding, so it cannot replace a verdict. */
128
+ async function stopFleet(fleet: Pick<DrillFleet, 'stop'>): Promise<readonly Finding[]> {
129
+ try {
130
+ await fleet.stop();
131
+ return [];
132
+ } catch (error) {
133
+ if (!isUltimateError(error)) throw error;
134
+ return [{ code: error.code, cause: error.cause, fix: error.fix }];
135
+ }
136
+ }
137
+
110
138
  /**
111
139
  * One drill's body over a started fleet, which is ALWAYS stopped. The fleet is spawned role
112
140
  * processes: the connection was opened before the `try`, so a constructor that threw (a malformed
113
141
  * URL is a synchronous `Invalid URL`) left every role running, and a `close()` that threw skipped
114
- * `stop()` the same way.
142
+ * `stop()` the same way. A body that threw keeps its throw, answered as `thrown`: the teardown's
143
+ * failure — a later, smaller fact — rides beside it and never replaces the one that ended the run.
115
144
  */
116
145
  export async function withDrillFleet<T>(
117
146
  fleet: Pick<DrillFleet, 'databaseUrl' | 'stop'>,
118
147
  open: (url: string) => DrillSqlConnection,
119
148
  body: (sql: DrillSqlConnection) => Promise<T>,
120
- ): Promise<T> {
149
+ ): Promise<DrillFleetRun<T>> {
121
150
  let sql: DrillSqlConnection | undefined;
151
+ let closed = false;
152
+ let value: T;
122
153
  try {
123
154
  sql = open(fleet.databaseUrl);
124
- return await body(sql);
125
- } finally {
126
- try {
127
- await sql?.close();
128
- } finally {
129
- await fleet.stop();
130
- }
155
+ value = await body(sql);
156
+ closed = true;
157
+ await sql.close();
158
+ } catch (error) {
159
+ const [, stopped] = await Promise.allSettled([
160
+ closed ? undefined : sql?.close(),
161
+ stopFleet(fleet),
162
+ ]);
163
+ // `stopFleet` answers a coded refusal as a finding; only an uncoded throw rejects it.
164
+ const teardown = stopped.status === 'fulfilled' ? stopped.value : [findingFrom(stopped.reason)];
165
+ return { thrown: error, teardown };
131
166
  }
167
+ return { value, teardown: await stopFleet(fleet) };
168
+ }
169
+
170
+ /**
171
+ * A drill that threw ends the run, as it always has — red, exit 1 — with its throw first, then
172
+ * every finished drill's failures and every teardown finding so far: none of them is dropped.
173
+ */
174
+ export function thrownRun(input: {
175
+ readonly thrown: unknown;
176
+ readonly reports: readonly JudgedDrill[];
177
+ readonly teardowns: readonly Finding[];
178
+ readonly notRun: readonly string[];
179
+ }): CommandResult {
180
+ const { reports } = input;
181
+ return {
182
+ ok: false,
183
+ command: 'drill',
184
+ summary: msg('cli.drill.summary', {
185
+ held: reports.filter((report) => report.verdict.ok).length,
186
+ ran: reports.length + 1,
187
+ notRun: input.notRun.length,
188
+ }),
189
+ findings: [findingFrom(input.thrown), ...reports.flatMap(findingsOf), ...input.teardowns],
190
+ exitCode: 1,
191
+ };
132
192
  }
133
193
 
134
194
  export const drillCommand: CliCommand = {
@@ -183,6 +243,7 @@ export const drillCommand: CliCommand = {
183
243
  // After `drillTargets`: loading the app is what fills the entity registry read here.
184
244
  const publishable = replicatedRelations().length > 0;
185
245
  const reports: DrillReport[] = [];
246
+ const teardowns: Finding[] = [];
186
247
  const rolesNotPlayed: (DrillRoleNotPlayed & { readonly drill: string })[] = [];
187
248
  for (const { drill, services } of planned) {
188
249
  const { fault } = drill;
@@ -206,16 +267,17 @@ export const drillCommand: CliCommand = {
206
267
  readyTimeoutMs: READY_TIMEOUT_MS,
207
268
  beforeMigrate: order,
208
269
  });
209
- reports.push(
210
- await withDrillFleet(fleet, bunDrillSql, (sql) =>
211
- order === undefined
212
- ? runDrill({ drill, fleet, budgets, targets, sql, sync: drillSyncLane(fleet) })
213
- : runRollout({ drill, fleet, budgets, readyTimeoutMs: READY_TIMEOUT_MS }),
214
- ),
270
+ const run = await withDrillFleet(fleet, bunDrillSql, (sql) =>
271
+ order === undefined
272
+ ? runDrill({ drill, fleet, budgets, targets, sql, sync: drillSyncLane(fleet) })
273
+ : runRollout({ drill, fleet, budgets, readyTimeoutMs: READY_TIMEOUT_MS }),
215
274
  );
275
+ teardowns.push(...run.teardown);
276
+ if ('thrown' in run) return thrownRun({ thrown: run.thrown, reports, teardowns, notRun });
277
+ reports.push(run.value);
216
278
  }
217
279
  const held = reports.filter((report) => report.verdict.ok).length;
218
- const findings = reports.flatMap(findingsOf);
280
+ const findings = [...reports.flatMap(findingsOf), ...teardowns];
219
281
  return {
220
282
  ok: findings.length === 0 && held === reports.length,
221
283
  command: 'drill',
package/src/cmd-env.ts CHANGED
@@ -7,15 +7,19 @@ import { join } from 'node:path';
7
7
  import {
8
8
  checkEnv,
9
9
  ENV_EXAMPLE_PATH,
10
+ ENVIRONMENT_KEY,
10
11
  ERROR_DOCS_URL,
11
12
  maskedEnvValues,
13
+ tryResolveEnvironment,
12
14
  UltimateError,
13
15
  } from '@ultimat3/core';
14
16
  import { appSecretFacts, envExampleFor, loadEnvSchema } from './app-env';
15
17
  import { requireAppRoot } from './app-root';
16
18
  import { envSpec } from './cmd-env-spec';
17
19
  import type { CliCommand, CommandContext } from './command';
20
+ import { needsDevEnvironmentDeclaration } from './dev-environment';
18
21
  import { frameworkSecretFindings, namesNoEnvironment } from './framework-env';
22
+ import { isCi } from './heavy-env';
19
23
  import { msg } from './messages';
20
24
  import type { CommandResult, Finding, JsonValue } from './output';
21
25
 
@@ -67,6 +71,15 @@ async function writeExample(ctx: CommandContext): Promise<CommandResult> {
67
71
  };
68
72
  }
69
73
 
74
+ /**
75
+ * Does this table get `x dev`'s answer? Only where `x dev` itself would declare `development` —
76
+ * neither `ULTIMATE_ENV` nor `NODE_ENV` set (`needsDevEnvironmentDeclaration`, its one rule) — and
77
+ * not under `CI`, where an unnamed table is a deploy's and stays fail-closed. It was production
78
+ * everywhere, so `x env check` exited 1 on a pristine scaffold whose `x dev` ran clean.
79
+ */
80
+ const checkedAsDev = (env: CommandContext['env']): boolean =>
81
+ needsDevEnvironmentDeclaration(env) && !isCi(env);
82
+
70
83
  /**
71
84
  * The values are read from the environment the command was handed (`ctx.env`, the process's own
72
85
  * in `bin.ts`) — one table for the app's keys and the framework's — and only ever printed through
@@ -74,18 +87,23 @@ async function writeExample(ctx: CommandContext): Promise<CommandResult> {
74
87
  * return them, and a `--json` report is the last place a DSN should appear in full.
75
88
  *
76
89
  * The framework's deploy-required secrets (`framework-env.ts`) are asked exactly where the boot
77
- * refuses them — outside development/test, and where no environment is named at all — so `ULTIMATE_ENV=production x env check` answers what
90
+ * refuses them — outside development/test — so `ULTIMATE_ENV=production x env check` answers what
78
91
  * the first deployed boot would, instead of each role crash-looping on one key at a time (#679).
92
+ *
93
+ * WHICH environment, when the table names none (`checkedAsDev`): `x dev`'s own rule on a developer's
94
+ * shell, the boot's fail-closed one under `CI`. A named environment is always checked as named.
79
95
  */
80
96
  async function checkProcessEnv(ctx: CommandContext): Promise<CommandResult> {
81
97
  const { root, schema } = await requireSchema(ctx.cwd, 'check');
82
- const report = checkEnv(schema, { env: ctx.env });
98
+ const asDev = checkedAsDev(ctx.env);
99
+ const env = asDev ? { ...ctx.env, [ENVIRONMENT_KEY]: 'development' } : ctx.env;
100
+ const report = checkEnv(schema, { env });
83
101
  const total = Object.keys(schema).length;
84
102
  // A key the app's own declaration already reported is one finding, not two.
85
103
  const reported = new Set(report.issues.map((issue) => issue.key));
86
- // Gated by `deployed()` inside — the boot's own rule, so a table naming no environment is
87
- // checked as the production process it boots as.
88
- const framework = frameworkSecretFindings(ctx.env, reported, await appSecretFacts(root));
104
+ // Gated by `deployed()` inside — the boot's own rule, so under CI a table naming no environment
105
+ // is checked as the production process it boots as.
106
+ const framework = frameworkSecretFindings(env, reported, await appSecretFacts(root));
89
107
  const findings: readonly Finding[] = [
90
108
  ...report.issues.map((issue) => ({
91
109
  code: 'X_ENV_MISSING',
@@ -112,12 +130,16 @@ async function checkProcessEnv(ctx: CommandContext): Promise<CommandResult> {
112
130
  command: 'env',
113
131
  // `x doctor` asks about this machine and stays quiet on the same shell, so an exit 1 here over
114
132
  // a table that named nothing reads as a contradiction until this line says which question ran.
115
- summary: namesNoEnvironment(ctx.env)
116
- ? `${verdict} — ${msg('cli.env.checkedAsProduction')}`
117
- : verdict,
133
+ summary: asDev
134
+ ? `${verdict} — ${msg('cli.env.checkedAsDevelopment')}`
135
+ : namesNoEnvironment(env)
136
+ ? `${verdict} — ${msg('cli.env.checkedAsProduction')}`
137
+ : verdict,
118
138
  findings,
119
139
  data: {
120
140
  variables: total,
141
+ // The environment the answer is for; an unnamed table under CI is the boot's: production.
142
+ environment: tryResolveEnvironment({ env, fallback: 'production' }) ?? null,
121
143
  values: maskedEnvValues(schema, report.values) as JsonValue,
122
144
  },
123
145
  exitCode: ok ? 0 : 1,
@@ -0,0 +1,63 @@
1
+ // `x errors explain` for a code the APP declares with `defineError()` (`x g resource` writes one per
2
+ // slice). Loading the app registers it, and the answer is the registry's alone: title and status.
3
+ // A cause and a fix are functions of params only a throw has, so the declaring line is named instead.
4
+
5
+ import { describeErrorCode, ERROR_DOCS_URL, hasErrorCode, UltimateError } from '@ultimat3/core';
6
+ import { definedErrorStatus } from '@ultimat3/core/internal/error-status';
7
+ import { loadApp } from './app-load';
8
+ import { findAppRoot } from './app-root';
9
+ import { collectDeclaredCodes } from './error-contract';
10
+ import { quoteArg } from './shell-quote';
11
+
12
+ /** What an app code answers: what the registry holds for it, and the line that declares it. */
13
+ export interface AppCodeExplanation {
14
+ readonly code: string;
15
+ readonly title: string;
16
+ readonly docs: string;
17
+ /** `null` for an `offSocket` declaration. */
18
+ readonly status: number | null;
19
+ readonly site: { readonly at: string; readonly line: number } | null;
20
+ }
21
+
22
+ /**
23
+ * The app's declaration of `code`, or `undefined`: not inside an app, the load failed, or the app
24
+ * declares no such code. The caller then refuses with `AppCodeUnknownError`. The site is the
25
+ * `errors` step's own answer to "where is this code declared" (`collectDeclaredCodes`), never a
26
+ * second reading of the declaration.
27
+ */
28
+ export async function explainAppCode(
29
+ code: string,
30
+ cwd: string,
31
+ ): Promise<AppCodeExplanation | undefined> {
32
+ const root = findAppRoot(cwd)?.dir;
33
+ if (root === undefined) return undefined;
34
+ await loadApp(root);
35
+ if (!hasErrorCode(code)) return undefined;
36
+ const described = describeErrorCode(code);
37
+ const declared = (await collectDeclaredCodes(root)).find((site) => site.code === code);
38
+ return {
39
+ code,
40
+ title: described.title,
41
+ docs: described.docs ?? ERROR_DOCS_URL,
42
+ status: definedErrorStatus(code)?.status ?? null,
43
+ site: declared === undefined ? null : { at: declared.at, line: declared.line },
44
+ };
45
+ }
46
+
47
+ /**
48
+ * The framework does not know the code and no app answered for it. Same code as the CLI's own
49
+ * `ErrorCodeUnknownError`; the fix says where an app's codes come from, which that one cannot.
50
+ */
51
+ export class AppCodeUnknownError extends UltimateError {
52
+ constructor(input: { readonly code: string; readonly inApp: boolean }) {
53
+ super({
54
+ code: 'X_ERROR_CODE_UNKNOWN',
55
+ cause: input.inApp
56
+ ? `"${input.code}" is neither a framework code nor one this app declares with defineError()`
57
+ : `"${input.code}" is not a framework code, and an app's own defineError() codes resolve only inside that app`,
58
+ fix: input.inApp
59
+ ? `grep -rn ${quoteArg(input.code)} apps packages # an app code is a defineError({ code }) in a slice's errors.ts; x errors list --json lists the framework's`
60
+ : "x errors list --json # the framework's codes; an app's own defineError() codes answer when this runs inside the app (or with --cwd set to its directory)",
61
+ });
62
+ }
63
+ }