@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
@@ -9,6 +9,9 @@ import { loadApp } from './app-load';
9
9
  import { IMPORT_UNRESOLVED } from './app-load-unresolved';
10
10
  import { findAppRoot } from './app-root';
11
11
  import { checkMigrationSnapshots } from './db-snapshot';
12
+ import type { PortOwner } from './dev-lock-holder-dir';
13
+ import { portOwner } from './dev-lock-holder-dir';
14
+ import { unlistedPrimitiveFindings } from './doctor-api-listing';
12
15
  import { type AuthStorageFact, authStorageProbe } from './doctor-auth';
13
16
  import type { EmbeddedDatabase } from './doctor-database';
14
17
  import { externalUrl, installedAbove, probeDatabase } from './doctor-database';
@@ -26,9 +29,13 @@ import { rowSecurityOffProbe, rowSecurityProbe } from './doctor-row-security';
26
29
  import type { SealedKeysFact } from './doctor-sealed';
27
30
  import { sealedKeysProbe } from './doctor-sealed';
28
31
  import { typescriptProbe } from './doctor-typescript';
32
+ import { exec } from './exec';
29
33
  import { machineSecretFindings } from './framework-env';
34
+ import { driverUnset } from './merge-driver-config';
35
+ import { catalogFileFindings, unmergedFindings } from './merge-state';
30
36
  import type { Finding } from './output';
31
37
  import { portFree } from './port-probe';
38
+ import { withAppTls } from './runtime-database-ssl';
32
39
  import { checkMigrationDrift } from './schema-drift';
33
40
  import type { TypescriptLag } from './typescript-floor';
34
41
  import type { VerifyStepName } from './verify-step';
@@ -49,12 +56,19 @@ export interface DoctorProbe {
49
56
  /**
50
57
  * The framework's own secrets this machine lacks — `framework-env.ts`'s
51
58
  * `machineSecretFindings`, gated by `namedDeployed`: only an environment NAMED staging or
52
- * production (an unnamed developer shell owes nothing; `x env check` is the fail-closed answer).
59
+ * production (an unnamed developer shell owes nothing; `x env check` is the fail-closed answer
60
+ * under `CI` only — elsewhere it checks an unnamed shell as development, as `x dev` runs).
53
61
  * The list's own `needed`/`unsafe` decide; doctor reports.
54
62
  */
55
63
  readonly frameworkFindings: readonly Finding[];
56
64
  exists(relativePath: string): boolean;
57
65
  portFree(port: number): Promise<boolean>;
66
+ /**
67
+ * Who holds a taken port: another checkout's server is a warning, this one's a finding. This and
68
+ * the two merge facts below are optional against the rule above: the type is exported, and the
69
+ * public-API lock reads a required member added on `main` as a break. Absent asks the OS.
70
+ */
71
+ readonly portOwner?: (port: number) => Promise<PortOwner>;
58
72
  /**
59
73
  * Is the configured database reachable, and what refused? `null` is "reachable, or there is
60
74
  * nothing external to reach" — an unset `DATABASE_URL` is embedded PGlite, which `x dev` owns
@@ -113,6 +127,12 @@ export interface DoctorProbe {
113
127
  pins(): Promise<PinFact>;
114
128
  /** The gate steps that apply here and `x.verify.json` does not floor (`doctor-floor.ts`). */
115
129
  unflooredSteps(): Promise<readonly VerifyStepName[]>;
130
+ /** What a merge left: unmerged paths, catalogs that do not parse (`merge-state.ts`). Absent: none. */
131
+ readonly mergeState?: () => Promise<readonly Finding[]>;
132
+ /** Whether `.gitattributes` names a merge driver this clone has not installed. Absent: no. */
133
+ readonly mergeDriverUnset?: () => Promise<boolean>;
134
+ /** Actions and queries no `defineApi()` lists (`doctor-api-listing.ts`). Absent: none. */
135
+ readonly unlistedPrimitives?: () => Promise<readonly Finding[]>;
116
136
  }
117
137
 
118
138
  export function probeFor(
@@ -123,6 +143,10 @@ export function probeFor(
123
143
  env: Readonly<Record<string, string | undefined>> = process.env,
124
144
  ): DoctorProbe {
125
145
  const root = findAppRoot(cwd)?.dir;
146
+ // As the boot dials it: `database.ssl` requires TLS where the URL and `PGSSLMODE` state no mode,
147
+ // so a probe never answers green over a connection the app itself would refuse to make.
148
+ const databaseUrl = (): Promise<string | undefined> =>
149
+ withAppTls(root, process.env['DATABASE_URL'], env);
126
150
  return {
127
151
  bunVersion,
128
152
  root,
@@ -131,7 +155,8 @@ export function probeFor(
131
155
  frameworkFindings: machineSecretFindings(env),
132
156
  exists: (relativePath) => (root === undefined ? false : existsSync(join(root, relativePath))),
133
157
  portFree,
134
- database: () => probeDatabase(process.env['DATABASE_URL'], env),
158
+ portOwner,
159
+ database: async () => probeDatabase(await databaseUrl(), env),
135
160
  // `root ?? cwd` because the walk needs a directory that exists; outside an app `runDoctor`
136
161
  // returns on `X_NOT_IN_APP` before this is ever asked, so the value only has to be honest.
137
162
  embeddedDatabase: async () => ({
@@ -150,16 +175,22 @@ export function probeFor(
150
175
  root === undefined ? { fallback: null, routes: undefined } : offlineFallbackProbe(root),
151
176
  sealedKeys: async () =>
152
177
  root === undefined ? { columns: undefined, keys: undefined } : sealedKeysProbe(root),
153
- authStorage: () => authStorageProbe(process.env['DATABASE_URL'], env),
154
- pooler: () => poolerProbe(process.env['DATABASE_URL'], env),
178
+ authStorage: async () => authStorageProbe(await databaseUrl(), env),
179
+ pooler: async () => poolerProbe(await databaseUrl(), env),
155
180
  typescript: async () => (root === undefined ? [] : typescriptProbe(root)),
156
181
  rowSecurity: async () =>
157
- root === undefined ? [] : rowSecurityProbe(root, process.env['DATABASE_URL'], env),
182
+ root === undefined ? [] : rowSecurityProbe(root, await databaseUrl(), env),
158
183
  rowSecurityOff: async () =>
159
184
  root === undefined ? { declared: false, touches: [] } : rowSecurityOffProbe(root),
160
185
  envNames: async () => (root === undefined ? NO_APP_ENV_NAMES : appEnvNamesProbe(root, env)),
161
186
  pins: async () => (root === undefined ? { pins: [], installed: new Map() } : pinProbe(root)),
162
187
  unflooredSteps: async () => (root === undefined ? [] : unflooredStepsProbe(root)),
188
+ mergeState: async () =>
189
+ root === undefined
190
+ ? []
191
+ : [...(await unmergedFindings(root)), ...(await catalogFileFindings(root))],
192
+ mergeDriverUnset: async () => (root === undefined ? false : driverUnset(root, exec)),
193
+ unlistedPrimitives: async () => (root === undefined ? [] : unlistedPrimitiveFindings(root)),
163
194
  };
164
195
  }
165
196
 
@@ -0,0 +1,127 @@
1
+ // `x doctor`'s processes fact, read: each role through the boot's own `resolveProcessCount` as a
2
+ // production container on this host would ask it (cgroup, cores, pool, shared state), the
3
+ // `tcp_migrate_req` sysctl, and the server's `max_connections`. `doctor-processes.ts` judges it.
4
+
5
+ import type { Role } from '@ultimat3/core';
6
+ import { ROLES, resolveEnvironment } from '@ultimat3/core';
7
+ import { POOL_PROFILES, poolMaxFromEnv, postgresClient, sql } from '@ultimat3/db';
8
+ import { loadAppRuntime } from './app-runtime';
9
+ import type { ProcessesFact, RoleProcesses } from './doctor-processes';
10
+ import { findingFrom } from './output';
11
+ import type { RuntimeOverrides } from './runtime-overrides';
12
+ import type { ReadText } from './supervise-cgroup';
13
+ import { readCgroup, readText } from './supervise-cgroup';
14
+ import { resolveProcessCount } from './supervise-count';
15
+ import { sharedStateFacts } from './supervise-facts';
16
+
17
+ type Env = Readonly<Record<string, string | undefined>>;
18
+
19
+ /** Every role a container runs as; `migrate` runs once and exits, so it holds nothing. */
20
+ const REPORTED: readonly Role[] = ROLES.filter((role) => role !== 'migrate');
21
+
22
+ export const MIGRATE_REQ_PATH = '/proc/sys/net/ipv4/tcp_migrate_req';
23
+
24
+ export interface ProcessesSources {
25
+ readonly root: string;
26
+ readonly env: Env;
27
+ /** `apps/<app>/runtime.ts`'s overrides: its stores and transport are shared state or not. */
28
+ readonly runtime: () => Promise<RuntimeOverrides | undefined>;
29
+ readonly platform: string;
30
+ readonly cores: number;
31
+ readonly read: ReadText;
32
+ readonly maxConnections: () => Promise<number | undefined>;
33
+ }
34
+
35
+ /**
36
+ * Asked as `production`: the fact answers what a deployed container here would run, which `x dev`
37
+ * (always one process) never does. The image is taken as prebuilt (the Dockerfile's `x build
38
+ * --target prebuilt`): the boot itself clamps on that, and its line names the clamp.
39
+ */
40
+ export async function processesFact(sources: ProcessesSources): Promise<ProcessesFact> {
41
+ const { env } = sources;
42
+ const runtime = await sources.runtime();
43
+ // The boot's own reader of shared state (`supervise-facts.ts`) over the same `runtime.ts`, so
44
+ // doctor and the boot cannot name different clamps.
45
+ const options = { root: sources.root, env, ...(runtime === undefined ? {} : { runtime }) };
46
+ const cgroup = await readCgroup(sources.read);
47
+ const poolOf = (role: Role): number => poolMaxFromEnv(env).max ?? POOL_PROFILES[role].max;
48
+ const roles = await Promise.all(
49
+ REPORTED.map(async (role): Promise<RoleProcesses> => {
50
+ const listen = role === 'worker' ? 1 : 0;
51
+ try {
52
+ const resolved = await resolveProcessCount({
53
+ env,
54
+ role,
55
+ platform: sources.platform,
56
+ environment: 'production',
57
+ cgroup: async () => cgroup,
58
+ parallelism: () => sources.cores,
59
+ pool: () => poolOf(role),
60
+ shared: () => sharedStateFacts(options, role),
61
+ prebuilt: async () => true,
62
+ });
63
+ return { role, resolved, pool: poolOf(role), listen };
64
+ } catch (error) {
65
+ return {
66
+ role,
67
+ resolved: { refused: findingFrom(error) },
68
+ pool: POOL_PROFILES[role].max,
69
+ listen,
70
+ };
71
+ }
72
+ }),
73
+ );
74
+ const requested = env['ULTIMATE_PROCESSES']?.trim() ?? '';
75
+ return {
76
+ environment: resolveEnvironment({ env }),
77
+ cores: sources.cores,
78
+ cpuBudget: cgroup.cpus,
79
+ explicit: requested !== '' && requested !== 'auto',
80
+ migrateReq: (await sources.read(MIGRATE_REQ_PATH))?.trim(),
81
+ roles,
82
+ maxConnections: await sources.maxConnections(),
83
+ };
84
+ }
85
+
86
+ /** `max_connections` over one connection (the pool fills to max on first use); none on any failure. */
87
+ export async function maxConnectionsOf(
88
+ url: string | undefined,
89
+ env: Env,
90
+ ): Promise<number | undefined> {
91
+ if (url === undefined || url.trim() === '') return undefined;
92
+ let client: ReturnType<typeof postgresClient> | undefined;
93
+ try {
94
+ client = postgresClient({
95
+ url,
96
+ role: 'web',
97
+ env,
98
+ applicationName: 'x-doctor',
99
+ profile: { max: 1 },
100
+ });
101
+ const rows = await client.query<{ readonly setting: string }>(
102
+ sql`select setting from pg_settings where name = 'max_connections'`,
103
+ );
104
+ const max = Number(rows[0]?.setting);
105
+ return Number.isSafeInteger(max) && max > 0 ? max : undefined;
106
+ } catch {
107
+ // Unreachable is `database()`'s finding to make; this fact only omits the comparison.
108
+ return undefined;
109
+ } finally {
110
+ await client?.close();
111
+ }
112
+ }
113
+
114
+ /** The real sources: this host's files, cores, app and database. */
115
+ export const hostProcessesSources = (
116
+ root: string,
117
+ env: Env,
118
+ databaseUrl: () => Promise<string | undefined>,
119
+ ): ProcessesSources => ({
120
+ root,
121
+ env,
122
+ runtime: () => loadAppRuntime(root),
123
+ platform: process.platform,
124
+ cores: navigator.hardwareConcurrency,
125
+ read: readText,
126
+ maxConnections: async () => maxConnectionsOf(await databaseUrl(), env),
127
+ });
@@ -0,0 +1,136 @@
1
+ // `x doctor`'s processes fact, pure: how many processes a production container of each role runs
2
+ // here (`resolveProcessCount`, and the clamp that bound it), the connections one container holds
3
+ // (Σ child pool shares + one LISTEN session per worker process), and the two warnings a production
4
+ // host owes: no CPU budget declared, and N > 1 with `net.ipv4.tcp_migrate_req` off.
5
+
6
+ import type { Environment, Role } from '@ultimat3/core';
7
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
8
+ import { msg } from './messages';
9
+ import type { CommandResult, Finding, JsonValue } from './output';
10
+ import type { ProcessCount } from './supervise-count';
11
+
12
+ /** One role, resolved: its count, or the refusal an explicit `ULTIMATE_PROCESSES` met. */
13
+ export interface RoleProcesses {
14
+ readonly role: Role;
15
+ readonly resolved: ProcessCount | { readonly refused: Finding };
16
+ /** The container's pool: `DATABASE_POOL_MAX`, else the role's profile. */
17
+ readonly pool: number;
18
+ /** LISTEN sessions per process: the worker's queue wake holds one outside the pool. */
19
+ readonly listen: 0 | 1;
20
+ }
21
+
22
+ export interface ProcessesFact {
23
+ readonly environment: Environment;
24
+ /** Cores this process sees (`navigator.hardwareConcurrency`): every host core without a quota. */
25
+ readonly cores: number;
26
+ /** Whole CPUs the cgroup declares; `undefined` when none is. */
27
+ readonly cpuBudget: number | undefined;
28
+ /** `ULTIMATE_PROCESSES` was set to a count, so the operator chose and the CPU warning is moot. */
29
+ readonly explicit: boolean;
30
+ /** `/proc/sys/net/ipv4/tcp_migrate_req`, trimmed; `undefined` off Linux or unreadable. */
31
+ readonly migrateReq: string | undefined;
32
+ readonly roles: readonly RoleProcesses[];
33
+ /** The server's `max_connections`; `undefined` when no external database answered. */
34
+ readonly maxConnections: number | undefined;
35
+ }
36
+
37
+ const PRODUCTION_LIKE: ReadonlySet<Environment> = new Set(['production', 'staging']);
38
+
39
+ const countOf = (entry: RoleProcesses): number | undefined =>
40
+ 'count' in entry.resolved ? entry.resolved.count : undefined;
41
+
42
+ /** Σ childShare(pool, i, N) is max(pool, N); each process adds its LISTEN session. */
43
+ export const connectionsOf = (entry: RoleProcesses): number | undefined => {
44
+ const count = countOf(entry);
45
+ return count === undefined ? undefined : Math.max(entry.pool, count) + count * entry.listen;
46
+ };
47
+
48
+ const COMPOSE = 'docker/docker-compose.prod.yml';
49
+
50
+ /** Warnings, on a production-like host only: a laptop declares no CPU budget and owes none. */
51
+ export function processesWarnings(fact: ProcessesFact): readonly Finding[] {
52
+ const refused = fact.roles.flatMap((entry) =>
53
+ 'refused' in entry.resolved ? [entry.resolved.refused] : [],
54
+ );
55
+ if (!PRODUCTION_LIKE.has(fact.environment)) return refused;
56
+ const warnings: Finding[] = [...refused];
57
+ if (fact.cpuBudget === undefined && fact.cores > 1 && !fact.explicit) {
58
+ warnings.push({
59
+ code: 'X_PROCESSES_CPU_UNDECLARED',
60
+ cause: `this container declares no CPU budget on a host with ${fact.cores} cores, so ULTIMATE_PROCESSES=auto runs 1 process per role`,
61
+ fix: `cpus: '2' # on the role's service in ${COMPOSE} (resources.limits.cpu in Kubernetes); or ULTIMATE_PROCESSES=1 to say one is meant`,
62
+ docs: ERROR_DOCS_URL,
63
+ });
64
+ }
65
+ // Only where the knob exists and reads 0: a kernel before 5.14 has none (`migrateReq` undefined),
66
+ // and the compose line would then stop the container from being created at all.
67
+ const shared = fact.roles.filter((entry) => (countOf(entry) ?? 1) > 1);
68
+ if (shared.length > 0 && fact.migrateReq === '0') {
69
+ const roles = shared.map((entry) => `${entry.role} (${countOf(entry)})`).join(', ');
70
+ warnings.push({
71
+ code: 'X_PROCESSES_MIGRATE_REQ_OFF',
72
+ cause: `this kernel has net.ipv4.tcp_migrate_req and it reads 0 while ${roles} share a port: a process that closes its listener resets every connection queued on it (measured 93–109 of 200; 0 with the sysctl)`,
73
+ fix: `sysctls: { net.ipv4.tcp_migrate_req: 1 } # uncomment it on web and sync in ${COMPOSE}; Linux >= 5.14 only — this host has the knob, an older kernel refuses to create the container`,
74
+ docs: ERROR_DOCS_URL,
75
+ });
76
+ }
77
+ return warnings;
78
+ }
79
+
80
+ const roleJson = (entry: RoleProcesses): JsonValue =>
81
+ 'refused' in entry.resolved
82
+ ? { role: entry.role, refused: entry.resolved.refused.code }
83
+ : {
84
+ role: entry.role,
85
+ count: entry.resolved.count,
86
+ binding: entry.resolved.binding,
87
+ pool: entry.pool,
88
+ listen: entry.listen * entry.resolved.count,
89
+ connections: connectionsOf(entry) ?? null,
90
+ };
91
+
92
+ /** The fact beside the verdict: `data.processes` for a machine, a line per role for a person. */
93
+ export function withProcessesReport(result: CommandResult, fact: ProcessesFact): CommandResult {
94
+ const data = typeof result.data === 'object' && result.data !== null ? result.data : {};
95
+ const perContainer = fact.roles.reduce((sum, entry) => sum + (connectionsOf(entry) ?? 0), 0);
96
+ const lines = [
97
+ msg('cli.doctor.processes', {
98
+ cores: fact.cores,
99
+ budget: fact.cpuBudget ?? msg('cli.doctor.processesUndeclared'),
100
+ }),
101
+ ...fact.roles.map((entry) =>
102
+ 'refused' in entry.resolved
103
+ ? msg('cli.doctor.processesRefused', {
104
+ role: entry.role,
105
+ code: entry.resolved.refused.code,
106
+ })
107
+ : msg('cli.doctor.processesRole', {
108
+ role: entry.role,
109
+ count: entry.resolved.count,
110
+ binding: entry.resolved.binding,
111
+ pool: entry.pool,
112
+ listen: entry.listen * entry.resolved.count,
113
+ connections: connectionsOf(entry) ?? 0,
114
+ }),
115
+ ),
116
+ ...(fact.maxConnections === undefined
117
+ ? []
118
+ : [
119
+ msg('cli.doctor.processesConnections', { total: perContainer, max: fact.maxConnections }),
120
+ ]),
121
+ ];
122
+ const processes: JsonValue = {
123
+ environment: fact.environment,
124
+ cores: fact.cores,
125
+ cpuBudget: fact.cpuBudget ?? null,
126
+ migrateReq: fact.migrateReq ?? null,
127
+ roles: fact.roles.map(roleJson),
128
+ connectionsOneOfEach: perContainer,
129
+ maxConnections: fact.maxConnections ?? null,
130
+ };
131
+ return {
132
+ ...result,
133
+ data: { ...(data as Record<string, JsonValue>), processes },
134
+ lines: [...(result.lines ?? []), ...lines],
135
+ };
136
+ }
@@ -2,14 +2,25 @@
2
2
  // never in it. On `main` an app that upgrades with no change keeps a green doctor
3
3
  // (`X_BREAKING_ON_MAIN`); on `next` these move into `runDoctor`'s findings and the verdict.
4
4
 
5
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
5
6
  import { reservedEnvFindings } from './doctor-env-reserved';
6
7
  import { unflooredStepFindings } from './doctor-floor';
7
8
  import { pinRangeFindings } from './doctor-pins';
9
+ import { portWarnings } from './doctor-port';
8
10
  import type { DoctorProbe } from './doctor-probe';
9
11
  import { rowSecurityOffFindings } from './doctor-row-security';
12
+ import { REGISTRY_DRIVER } from './merge-driver-config';
10
13
  import { msg } from './messages';
11
14
  import type { CommandResult, Finding, JsonValue } from './output';
12
15
 
16
+ const MERGE_DRIVER_UNSET: Finding = {
17
+ code: 'X_MERGE_DRIVER_UNSET',
18
+ cause: `.gitattributes names merge=${REGISTRY_DRIVER}, and this clone has no such driver, so two branches' generated features conflict`,
19
+ fix: 'bunx x merge-driver install',
20
+ docs: ERROR_DOCS_URL,
21
+ at: '.gitattributes',
22
+ };
23
+
13
24
  /** The probes that only warn on `main`. Asked inside an app only; outside one there is no app. */
14
25
  export async function doctorWarnings(probe: DoctorProbe): Promise<readonly Finding[]> {
15
26
  if (probe.root === undefined) return [];
@@ -22,6 +33,12 @@ export async function doctorWarnings(probe: DoctorProbe): Promise<readonly Findi
22
33
  ...rowSecurityOffFindings(await probe.rowSecurityOff()),
23
34
  // A floor gap is the gate's blind spot, never a reason anything else is red.
24
35
  ...unflooredStepFindings(await probe.unflooredSteps()),
36
+ // A clone that merges by hand what its drivers would have merged: slower, never wrong.
37
+ ...((await probe.mergeDriverUnset?.()) === true ? [MERGE_DRIVER_UNSET] : []),
38
+ // A port another checkout's dev server holds: nothing is wrong with this environment.
39
+ ...(await portWarnings(probe)),
40
+ // Served by the scan, so never refused: an action or query the typed client cannot see.
41
+ ...((await probe.unlistedPrimitives?.()) ?? []),
25
42
  ];
26
43
  }
27
44
 
@@ -0,0 +1,35 @@
1
+ // The X_* codes of agents sharing one machine and repository: a checkout, port or app another
2
+ // process holds, a ledger wait given up, a half-done merge, a catalog a merge broke, a doctor check
3
+ // that threw. Split from `error-codes.ts` at its ceiling, which folds these into the CLI's one owned
4
+ // union and registers them in its one call; nothing else imports this file.
5
+
6
+ /** Codes `x dev`, `x upgrade`, `x heavy`, `x merge-driver`, `x doctor` and the catalog loader own. */
7
+ export const CLI_AGENTS_ERROR_CODES = [
8
+ 'X_DEV_ALREADY_RUNNING',
9
+ // The OTHER thing the preflight can find, and it was reported as the one above: an unreadable
10
+ // lock this process could not remove made `DevAlreadyRunningError` name THIS pid as the holder,
11
+ // so the remedy printed was `kill <self>` — unrunnable, and a cause that was simply untrue.
12
+ 'X_DEV_LOCK_UNREADABLE',
13
+ 'X_PORT_IN_USE',
14
+ 'X_UPGRADE_LOCKED',
15
+ 'X_HEAVY_WAIT_EXPIRED',
16
+ 'X_MERGE_UNRESOLVED',
17
+ 'X_MERGE_DRIVER_UNSET',
18
+ 'X_CATALOG_UNPARSEABLE',
19
+ 'X_DOCTOR_PROBE_FAILED',
20
+ ] as const;
21
+
22
+ export type CliAgentsErrorCode = (typeof CLI_AGENTS_ERROR_CODES)[number];
23
+
24
+ /** Their titles, typed over the list above so a code without one is a build error. */
25
+ export const CLI_AGENTS_ERROR_TITLES: Readonly<Record<CliAgentsErrorCode, string>> = {
26
+ X_DEV_ALREADY_RUNNING: 'another x dev already owns this checkout',
27
+ X_DEV_LOCK_UNREADABLE: 'the dev lock file cannot be read or removed',
28
+ X_PORT_IN_USE: 'the dev port is taken',
29
+ X_UPGRADE_LOCKED: 'another x upgrade holds this app',
30
+ X_HEAVY_WAIT_EXPIRED: 'x heavy run stopped waiting for the machine ledger',
31
+ X_MERGE_UNRESOLVED: 'a merge left conflicts in the app',
32
+ X_MERGE_DRIVER_UNSET: 'the merge drivers .gitattributes names are not configured',
33
+ X_CATALOG_UNPARSEABLE: 'an i18n catalog is not valid JSON',
34
+ X_DOCTOR_PROBE_FAILED: 'one x doctor check could not run',
35
+ };
@@ -0,0 +1,30 @@
1
+ // The X_* codes of processes per container (`ULTIMATE_PROCESSES`): the count's refusals, the
2
+ // supervisor's crash loop and `x doctor`'s two warnings — split out of `error-codes.ts` at its
3
+ // 500-line ceiling. `error-codes.ts` folds these into the CLI's one owned union and registers them
4
+ // in its one call; nothing else imports this file.
5
+
6
+ /** Codes the supervisor (`supervise*.ts`) and `doctor-processes.ts` declare and own. */
7
+ export const CLI_PROCESSES_ERROR_CODES = [
8
+ 'X_PROCESSES_INVALID',
9
+ 'X_PROCESSES_ROLE_SINGLETON',
10
+ 'X_PROCESSES_UNSHARED_STATE',
11
+ 'X_PROCESSES_OVER_POOL',
12
+ 'X_PROCESSES_UNBALANCED',
13
+ 'X_PROCESS_CRASH_LOOP',
14
+ 'X_PROCESSES_CPU_UNDECLARED',
15
+ 'X_PROCESSES_MIGRATE_REQ_OFF',
16
+ ] as const;
17
+
18
+ export type CliProcessesErrorCode = (typeof CLI_PROCESSES_ERROR_CODES)[number];
19
+
20
+ /** Their titles, typed over the list above so a code without one is a build error. */
21
+ export const CLI_PROCESSES_ERROR_TITLES: Readonly<Record<CliProcessesErrorCode, string>> = {
22
+ X_PROCESSES_INVALID: 'ULTIMATE_PROCESSES is not auto or a count',
23
+ X_PROCESSES_ROLE_SINGLETON: 'this role runs as one process per container',
24
+ X_PROCESSES_UNSHARED_STATE: 'more than one process over per-process state',
25
+ X_PROCESSES_OVER_POOL: 'more processes than database pool connections',
26
+ X_PROCESSES_UNBALANCED: 'SO_REUSEPORT does not balance on this platform',
27
+ X_PROCESS_CRASH_LOOP: 'a child process kept crashing',
28
+ X_PROCESSES_CPU_UNDECLARED: 'no CPU budget declared on a multi-core host',
29
+ X_PROCESSES_MIGRATE_REQ_OFF: 'shared-port listeners reset queued connections',
30
+ };
@@ -12,6 +12,7 @@ export const CLI_TOOLING_ERROR_CODES = [
12
12
  'X_REPRO_UNKNOWN',
13
13
  'X_REPRO_NOT_REPRODUCED',
14
14
  'X_REPRO_CAPTURE_OFF',
15
+ 'X_REPRO_BUNDLE_INVALID',
15
16
  'X_EXPLAIN_PRODUCTION_DATABASE',
16
17
  'X_HEAVY_LEDGER_UNAVAILABLE',
17
18
  'X_HEAVY_MEMORY_INVALID',
@@ -30,6 +31,7 @@ export const CLI_TOOLING_ERROR_TITLES: Readonly<Record<CliToolingErrorCode, stri
30
31
  X_REPRO_UNKNOWN: 'x repro was given an id nothing holds',
31
32
  X_REPRO_NOT_REPRODUCED: 'a written repro test did not fail the way the original did',
32
33
  X_REPRO_CAPTURE_OFF: 'x repro was given a request id while failure capture is off',
34
+ X_REPRO_BUNDLE_INVALID: 'the file is not a repro bundle this version can open',
33
35
  X_EXPLAIN_PRODUCTION_DATABASE: 'x explain refused to run on a production database',
34
36
  X_HEAVY_LEDGER_UNAVAILABLE: 'the machine memory ledger cannot be used here',
35
37
  X_HEAVY_MEMORY_INVALID: 'ULTIMATE_HEAVY_MEMORY is not a size',
@@ -3,12 +3,16 @@
3
3
  // the CLI is the surface an agent reads first — a failure here has to be actionable without a doc
4
4
  // lookup or a second round-trip. The classes that throw these codes live in `./errors`.
5
5
  import { registerErrorCodes } from '@ultimat3/core';
6
+ import type { CliAgentsErrorCode } from './error-codes-agents';
7
+ import { CLI_AGENTS_ERROR_CODES, CLI_AGENTS_ERROR_TITLES } from './error-codes-agents';
6
8
  import type { CliBoundaryErrorCode } from './error-codes-boundary';
7
9
  import { CLI_BOUNDARY_ERROR_CODES, CLI_BOUNDARY_ERROR_TITLES } from './error-codes-boundary';
8
10
  import type { CliDoctorErrorCode } from './error-codes-doctor';
9
11
  import { CLI_DOCTOR_ERROR_CODES, CLI_DOCTOR_ERROR_TITLES } from './error-codes-doctor';
10
12
  import type { CliPackageErrorCode } from './error-codes-package';
11
13
  import { CLI_PACKAGE_ERROR_CODES, CLI_PACKAGE_ERROR_TITLES } from './error-codes-package';
14
+ import type { CliProcessesErrorCode } from './error-codes-processes';
15
+ import { CLI_PROCESSES_ERROR_CODES, CLI_PROCESSES_ERROR_TITLES } from './error-codes-processes';
12
16
  import type { CliShotErrorCode } from './error-codes-shot';
13
17
  import { CLI_SHOT_ERROR_CODES, CLI_SHOT_ERROR_TITLES } from './error-codes-shot';
14
18
  import type { CliToolingErrorCode } from './error-codes-tooling';
@@ -82,11 +86,6 @@ export const CLI_OWNED_ERROR_CODES = [
82
86
  // its health check with nothing in the log that names the cause.
83
87
  'X_ROLE_UNKNOWN',
84
88
  'X_PORT_INVALID',
85
- 'X_DEV_ALREADY_RUNNING',
86
- // The OTHER thing the preflight can find, and it was reported as the one above: an unreadable
87
- // lock this process could not remove made `DevAlreadyRunningError` name THIS pid as the holder,
88
- // so the remedy printed was `kill <self>` — unrunnable, and a cause that was simply untrue.
89
- 'X_DEV_LOCK_UNREADABLE',
90
89
  // The boot's own consistency check. `startServices` captures the drivers it built, and
91
90
  // `loadApp` runs AFTER it — so an app module calling `installJobDriver(theirs)` moved the ambient
92
91
  // slot and left the captured object alone: every `handle.enqueue()` went to their queue while
@@ -94,7 +93,6 @@ export const CLI_OWNED_ERROR_CODES = [
94
93
  // the enqueue side. Nothing failed. Refused here rather than documented, per axiom 3.
95
94
  'X_RUNTIME_DRIVER_SPLIT',
96
95
  'X_GENERATE_CONFLICT',
97
- 'X_PORT_IN_USE',
98
96
  'X_DB_GEN_FAILED',
99
97
  // The two directions of the drift a hash cannot see, and they are two repairs. The `drift` step
100
98
  // compared a schema-source HASH to a `.hash` sidecar and never read what the migration recorded,
@@ -238,9 +236,8 @@ export const CLI_OWNED_ERROR_CODES = [
238
236
  'X_PROFILE_ROUTE_FAILED',
239
237
  'X_ROWS_SLICE_ENTITY',
240
238
  'X_GUARD_BUILT_IN',
241
- 'X_REPRO_BUNDLE_INVALID',
242
- 'X_UPGRADE_LOCKED',
243
239
  'X_APP_MIGRATIONS_UNAPPLIED',
240
+ 'X_TASK_RUN_PRODUCTION',
244
241
  ] as const;
245
242
 
246
243
  /**
@@ -276,9 +273,11 @@ export const CLI_BORROWED_ERROR_CODES = [
276
273
  /** Every code the CLI can throw: the ones it owns plus the one it borrows. */
277
274
  export const CLI_ERROR_CODES = [
278
275
  ...CLI_OWNED_ERROR_CODES,
276
+ ...CLI_AGENTS_ERROR_CODES,
279
277
  ...CLI_BOUNDARY_ERROR_CODES,
280
278
  ...CLI_DOCTOR_ERROR_CODES,
281
279
  ...CLI_PACKAGE_ERROR_CODES,
280
+ ...CLI_PROCESSES_ERROR_CODES,
282
281
  ...CLI_SHOT_ERROR_CODES,
283
282
  ...CLI_TOOLING_ERROR_CODES,
284
283
  ...CLI_VERIFY_ERROR_CODES,
@@ -289,9 +288,11 @@ export const CLI_ERROR_CODES = [
289
288
  type CliListedErrorCode = (typeof CLI_OWNED_ERROR_CODES)[number];
290
289
  export type CliOwnedErrorCode =
291
290
  | CliListedErrorCode
291
+ | CliAgentsErrorCode
292
292
  | CliBoundaryErrorCode
293
293
  | CliDoctorErrorCode
294
294
  | CliPackageErrorCode
295
+ | CliProcessesErrorCode
295
296
  | CliShotErrorCode
296
297
  | CliToolingErrorCode
297
298
  | CliVerifyErrorCode;
@@ -340,11 +341,8 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
340
341
  X_DEPLOY_FAILED: 'a deploy step failed',
341
342
  X_ROLE_UNKNOWN: 'ROLE names something that is not a role',
342
343
  X_PORT_INVALID: 'PORT is not a TCP port number',
343
- X_DEV_ALREADY_RUNNING: 'another x dev already owns this checkout',
344
- X_DEV_LOCK_UNREADABLE: 'the dev lock file cannot be read or removed',
345
344
  X_RUNTIME_DRIVER_SPLIT: 'the ambient driver is not the one this process serves',
346
345
  X_GENERATE_CONFLICT: 'a generator would overwrite a file',
347
- X_PORT_IN_USE: 'the dev port is taken',
348
346
  X_DB_GEN_FAILED: 'x db gen failed',
349
347
  X_DB_SCHEMA_UNMIGRATED: 'an entity declaration no migration recorded',
350
348
  X_DB_SCHEMA_UNDECLARED: 'a migration records schema no entity declares',
@@ -467,10 +465,9 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
467
465
  X_PROFILE_ROUTE_FAILED: 'the profiled route answered an error',
468
466
  X_ROWS_SLICE_ENTITY: "the slice's entity is not the scaffolded table",
469
467
  X_GUARD_BUILT_IN: 'x g guard named a shipped guard',
470
- X_REPRO_BUNDLE_INVALID: 'the file is not a repro bundle this version can open',
471
- X_UPGRADE_LOCKED: 'another x upgrade holds this app',
472
468
  X_APP_MIGRATIONS_UNAPPLIED:
473
469
  'a serving role booted over a database missing migrations this build ships',
470
+ X_TASK_RUN_PRODUCTION: 'x tasks run refused to fire a task in production unasked',
474
471
  };
475
472
 
476
473
  // One unconditional call, so a second package claiming one of the CLI's codes throws
@@ -479,9 +476,11 @@ registerErrorCodes(
479
476
  Object.fromEntries(
480
477
  Object.entries({
481
478
  ...CLI_ERROR_TITLES,
479
+ ...CLI_AGENTS_ERROR_TITLES,
482
480
  ...CLI_BOUNDARY_ERROR_TITLES,
483
481
  ...CLI_DOCTOR_ERROR_TITLES,
484
482
  ...CLI_PACKAGE_ERROR_TITLES,
483
+ ...CLI_PROCESSES_ERROR_TITLES,
485
484
  ...CLI_SHOT_ERROR_TITLES,
486
485
  ...CLI_TOOLING_ERROR_TITLES,
487
486
  ...CLI_VERIFY_ERROR_TITLES,
@@ -0,0 +1,27 @@
1
+ // `x test` over a selection that matched nothing. Its fix never prints the bare command: pasted as
2
+ // printed, that starts every suite, which a worker on a file set must not (`wiki/Many-Agents.md`).
3
+
4
+ import { UltimateError } from '@ultimat3/core';
5
+
6
+ /**
7
+ * `x test` discovered nothing. A green run over zero files is the most expensive false pass, so
8
+ * the selection that found nothing is named in full — a caller that cannot see whether the type
9
+ * or the filter emptied the set has to guess which one to drop.
10
+ */
11
+ export class NoTestFilesError extends UltimateError {
12
+ constructor(input: { root: string; type?: string; filter?: string }) {
13
+ const parts = [
14
+ input.type === undefined ? undefined : `of type ${input.type}`,
15
+ input.filter === undefined ? undefined : `matching "${input.filter}"`,
16
+ ].filter((part): part is string => part !== undefined);
17
+ const where = parts.length === 0 ? '' : ` ${parts.join(' ')}`;
18
+ super({
19
+ code: 'X_TEST_NO_FILES',
20
+ cause: `no *.test.ts files${where} under ${input.root}`,
21
+ fix:
22
+ parts.length === 0
23
+ ? 'x test --json # run it from the repo root'
24
+ : 'x test --affected --dirty # the tests your edits reach; or a path that exists: x test --filter <path>',
25
+ });
26
+ }
27
+ }