@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
@@ -24,8 +24,10 @@ import {
24
24
  } from 'node:fs';
25
25
  // why: Bun ships no path-join primitive.
26
26
  import { join } from 'node:path';
27
- import { HeavyLedgerUnavailableError } from './heavy-errors';
27
+ import { HeavyLedgerUnavailableError, HeavyWaitExpiredError } from './heavy-errors';
28
28
  import type { TryLock } from './heavy-flock';
29
+ import type { CpuReading } from './heavy-pressure';
30
+ import { cpuAdmission } from './heavy-pressure';
29
31
 
30
32
  export const LEDGER_POLL_MS = 100;
31
33
  /** A temp file this old lost its creator: creating one takes microseconds. */
@@ -39,8 +41,13 @@ export interface LedgerEntry {
39
41
  readonly at: number;
40
42
  }
41
43
 
44
+ /** An admitted reservation, and the file whose lock it is. */
45
+ export interface LedgerHold extends LedgerEntry {
46
+ readonly file: string;
47
+ }
48
+
42
49
  export interface LedgerView {
43
- readonly holds: readonly LedgerEntry[];
50
+ readonly holds: readonly LedgerHold[];
44
51
  /** Oldest first: index 0 is the next admission. */
45
52
  readonly queue: readonly LedgerEntry[];
46
53
  }
@@ -72,6 +79,10 @@ export interface ReserveInput {
72
79
  readonly cwd: string;
73
80
  readonly tryLock: TryLock;
74
81
  readonly pollMs?: number;
82
+ /** Give up after this long in the queue. `0` is one attempt; unset waits for as long as it takes. */
83
+ readonly maxWaitMs?: number;
84
+ /** The CPU reading the head is judged by (`heavy-pressure.ts`); absent, CPU never holds it. */
85
+ readonly cpu?: () => CpuReading;
75
86
  readonly onWait?: (wait: LedgerWait) => void;
76
87
  }
77
88
 
@@ -82,6 +93,8 @@ export interface LedgerWait {
82
93
  readonly position: number;
83
94
  readonly queued: number;
84
95
  readonly holds: readonly LedgerEntry[];
96
+ /** Set when memory fits and the CPU is what holds the head back. */
97
+ readonly cpu?: CpuReading;
85
98
  }
86
99
 
87
100
  const codeOf = (error: unknown): unknown =>
@@ -164,7 +177,10 @@ function liveEntries(dir: string, tryLock: TryLock, sweep: boolean): Live[] {
164
177
  }
165
178
 
166
179
  export const readLedger = (dir: string, tryLock: TryLock): LedgerView => ({
167
- holds: liveEntries(join(dir, 'holds'), tryLock, false).map((one) => one.entry),
180
+ holds: liveEntries(join(dir, 'holds'), tryLock, false).map((one) => ({
181
+ ...one.entry,
182
+ file: join(dir, 'holds', one.name),
183
+ })),
168
184
  queue: liveEntries(join(dir, 'queue'), tryLock, false).map((one) => one.entry),
169
185
  });
170
186
 
@@ -298,8 +314,11 @@ export async function reserve(input: ReserveInput): Promise<Reservation> {
298
314
  if (ticket === undefined) throw new HeavyLedgerUnavailableError('a new queue file was locked');
299
315
  const minUnits = input.minUnits ?? 1;
300
316
  let said = '';
317
+ /** When the head started waiting on CPU alone: `CPU_WAIT_LIMIT_MS` is counted from here. */
318
+ let cpuBlockedAt: number | undefined;
301
319
  try {
302
320
  for (;;) {
321
+ let cpu: CpuReading | undefined;
303
322
  const queue = liveEntries(join(dir, 'queue'), tryLock, true);
304
323
  const position = queue.findIndex((one) => one.name === name);
305
324
  if (position === -1) throw new HeavyLedgerUnavailableError(`${dir} was removed mid-wait`);
@@ -313,7 +332,18 @@ export async function reserve(input: ReserveInput): Promise<Reservation> {
313
332
  holds = liveEntries(join(dir, 'holds'), tryLock, true);
314
333
  const usedMb = holds.reduce((sum, one) => sum + one.entry.mb, 0);
315
334
  const granted = unitsThatFit({ capacityMb, usedMb, unitMb, units, minUnits, baseMb });
316
- if (granted > 0) {
335
+ const reading = granted > 0 ? input.cpu?.() : undefined;
336
+ const now = performance.now();
337
+ const verdict = cpuAdmission({
338
+ reading,
339
+ running: holds.length,
340
+ blockedMs: cpuBlockedAt === undefined ? 0 : now - cpuBlockedAt,
341
+ });
342
+ if (granted > 0 && verdict === 'wait') {
343
+ cpuBlockedAt ??= now;
344
+ cpu = reading;
345
+ } else cpuBlockedAt = undefined;
346
+ if (granted > 0 && verdict === 'admit') {
317
347
  const mb = baseMb + granted * unitMb;
318
348
  const hold = createEntry(
319
349
  dir,
@@ -338,19 +368,31 @@ export async function reserve(input: ReserveInput): Promise<Reservation> {
338
368
  }
339
369
  }
340
370
  const usedMb = holds.reduce((sum, one) => sum + one.entry.mb, 0);
341
- const key = `${String(position)}|${holds.map((one) => one.name).join(',')}`;
371
+ // Behind the head, the queue is held by whatever holds the head: say CPU when that is it.
372
+ if (cpu === undefined && position > 0 && holds.length > 0) {
373
+ const reading = input.cpu?.();
374
+ if (reading?.busy === true) cpu = reading;
375
+ }
376
+ const wait: LedgerWait = {
377
+ needMb: Math.min(baseMb + units * unitMb, capacityMb),
378
+ usedMb,
379
+ capacityMb,
380
+ position: position + 1,
381
+ queued: queue.length,
382
+ holds: holds.map((one) => one.entry),
383
+ ...(cpu === undefined ? {} : { cpu }),
384
+ };
385
+ const key = `${String(position)}|${cpu === undefined ? '' : 'cpu'}|${holds.map((one) => one.name).join(',')}`;
342
386
  if (key !== said) {
343
387
  said = key;
344
- input.onWait?.({
345
- needMb: Math.min(baseMb + units * unitMb, capacityMb),
346
- usedMb,
347
- capacityMb,
348
- position: position + 1,
349
- queued: queue.length,
350
- holds: holds.map((one) => one.entry),
351
- });
388
+ input.onWait?.(wait);
389
+ }
390
+ const { maxWaitMs } = input;
391
+ const left = (maxWaitMs ?? Number.POSITIVE_INFINITY) - (performance.now() - started);
392
+ if (maxWaitMs !== undefined && left <= 0) {
393
+ throw new HeavyWaitExpiredError({ label: input.label, maxWaitMs, wait });
352
394
  }
353
- await Bun.sleep(pollMs);
395
+ await Bun.sleep(Math.min(pollMs, left));
354
396
  }
355
397
  } finally {
356
398
  ticket.release();
@@ -0,0 +1,104 @@
1
+ // The CPU half of admission: a run that fits in memory still waits while the machine's CPU is
2
+ // saturated and another heavy run is going. The thresholds, their measurement and the decision live
3
+ // here; `heavy-ledger.ts` asks it only for the queue's head, so first-come order is kept.
4
+
5
+ // why: Bun ships no synchronous file read, and `/proc/pressure/cpu` is read on every poll.
6
+ import { readFileSync } from 'node:fs';
7
+ // why: Bun exposes no available-parallelism primitive.
8
+ import { availableParallelism } from 'node:os';
9
+ import { runnableTasks } from './heavy-cores';
10
+ import type { HeavyEnv } from './heavy-env';
11
+ import { HEAVY_CPU_ENV, isCi } from './heavy-env';
12
+ import { msg } from './messages';
13
+
14
+ /**
15
+ * Measured on the 8-core shared box, 2026-11-18, `As of` Linux 7.0: four admitted runs held 14.3 of
16
+ * 15.9 GB while load was 74-94 with 69-84 runnable tasks, and `cpu some avg10` read 95.8. Memory was
17
+ * not the bound; CPU was, and every run on it slowed. `some` is the share of time at least one task
18
+ * waited for a CPU: an 8-core box running one 4-core typecheck stays far below 80, and at 80 most of
19
+ * every second already has a queue. avg10 is the shortest window the kernel keeps. ONE reading; a
20
+ * re-measure that moves it changes only these numbers.
21
+ */
22
+ export const CPU_SOME_BUSY_PERCENT = 80;
23
+ /** No PSI (macOS, older kernels): 69 runnable on 8 cores was 8.6 a core; 2 a core is a run queue. */
24
+ export const RUNNABLE_PER_CORE_BUSY = 2;
25
+ /**
26
+ * How long the queue's head waits on CPU alone before it goes anyway. A holder can run for hours
27
+ * while outside work keeps the CPU busy; this bounds the wait to one admission per window.
28
+ */
29
+ export const CPU_WAIT_LIMIT_MS = 5 * 60_000;
30
+
31
+ export interface CpuReading {
32
+ readonly source: 'psi' | 'runnable';
33
+ /** `cpu some avg10` in percent, or runnable tasks per core. */
34
+ readonly value: number;
35
+ readonly limit: number;
36
+ readonly busy: boolean;
37
+ }
38
+
39
+ /** `some avg10=95.83 …` → 95.83. */
40
+ export function parseCpuSome(text: string): number | undefined {
41
+ const match = /^some avg10=(\d+(?:\.\d+)?)/m.exec(text);
42
+ return match === null ? undefined : Number(match[1]);
43
+ }
44
+
45
+ const readPsi = (): string => readFileSync('/proc/pressure/cpu', 'utf8');
46
+
47
+ /** PSI where the kernel has it, else runnable tasks per core. Never throws. */
48
+ export function readCpuPressure(
49
+ input: { readonly read?: () => string; readonly cores?: number; readonly runnable?: number } = {},
50
+ ): CpuReading {
51
+ let some: number | undefined;
52
+ try {
53
+ some = parseCpuSome((input.read ?? readPsi)());
54
+ } catch {
55
+ some = undefined; // No PSI here.
56
+ }
57
+ if (some !== undefined) {
58
+ return {
59
+ source: 'psi',
60
+ value: some,
61
+ limit: CPU_SOME_BUSY_PERCENT,
62
+ busy: some >= CPU_SOME_BUSY_PERCENT,
63
+ };
64
+ }
65
+ const cores = Math.max(1, input.cores ?? availableParallelism());
66
+ const perCore = Math.round(((input.runnable ?? runnableTasks()) / cores) * 10) / 10;
67
+ return {
68
+ source: 'runnable',
69
+ value: perCore,
70
+ limit: RUNNABLE_PER_CORE_BUSY,
71
+ busy: perCore >= RUNNABLE_PER_CORE_BUSY,
72
+ };
73
+ }
74
+
75
+ /**
76
+ * Whether the head may start on CPU grounds. Never `wait` with nothing admitted: pressure from work
77
+ * outside the ledger must not stop the only run, and a ledger with no holder cannot deadlock.
78
+ */
79
+ export function cpuAdmission(input: {
80
+ readonly reading: CpuReading | undefined;
81
+ /** Reservations admitted now. */
82
+ readonly running: number;
83
+ /** How long the head has waited on CPU alone. */
84
+ readonly blockedMs: number;
85
+ }): 'admit' | 'wait' {
86
+ if (input.reading?.busy !== true || input.running === 0) return 'admit';
87
+ return input.blockedMs >= CPU_WAIT_LIMIT_MS ? 'admit' : 'wait';
88
+ }
89
+
90
+ /**
91
+ * Off in CI (single-tenant), off inside a test run (a fixture must not wait on the machine it runs
92
+ * on; `ambient` is this process's own env), and off with `ULTIMATE_HEAVY_CPU=0`.
93
+ */
94
+ export function cpuGateOn(env: HeavyEnv, ambient: HeavyEnv = Bun.env): boolean {
95
+ if (isCi(env) || env[HEAVY_CPU_ENV] === '0') return false;
96
+ return env['NODE_ENV'] !== 'test' && ambient['NODE_ENV'] !== 'test';
97
+ }
98
+
99
+ /** `CPU pressure 96% (new runs wait at 80%)`. */
100
+ export const cpuText = (reading: CpuReading): string =>
101
+ msg(reading.source === 'psi' ? 'cli.heavy.cpu.psi' : 'cli.heavy.cpu.runnable', {
102
+ value: reading.source === 'psi' ? Math.round(reading.value) : reading.value,
103
+ limit: reading.limit,
104
+ });
package/src/heavy.ts CHANGED
@@ -10,12 +10,13 @@ import { isUltimateError } from '@ultimat3/core';
10
10
  import { coreCap, nativeToolEnv } from './heavy-cores';
11
11
  import type { HeavyEnv } from './heavy-env';
12
12
  import { HEAVY_DIR_ENV, HEAVY_HOLD_ENV, isCi } from './heavy-env';
13
- import { HeavyLedgerUnavailableError } from './heavy-errors';
13
+ import { HeavyLedgerUnavailableError, HeavyWaitExpiredError } from './heavy-errors';
14
14
  import type { TryLock } from './heavy-flock';
15
15
  import { flockBinding } from './heavy-flock';
16
16
  import type { Held, LedgerEntry, LedgerWait, Reservation } from './heavy-ledger';
17
17
  import { isHeld, lockPath, prepareLedger, reserve } from './heavy-ledger';
18
18
  import { ledgerCapacityMb } from './heavy-memory';
19
+ import { cpuGateOn, cpuText, readCpuPressure } from './heavy-pressure';
19
20
  import { msg } from './messages';
20
21
  import { writeErrorLine } from './write-line';
21
22
 
@@ -61,9 +62,11 @@ export async function heavyState(env: HeavyEnv): Promise<HeavyState> {
61
62
  if (isCi(env)) return { on: false, off: 'ci' };
62
63
  const explicitDir = env[HEAVY_DIR_ENV];
63
64
  // A fixture's `x test` runs inside `bun test`, whose NODE_ENV every child inherits: queueing it
64
- // behind real work would turn a test's timeout into a machine-load verdict.
65
- if (env['NODE_ENV'] === 'test' && explicitDir === undefined)
66
- return { on: false, off: 'test-run' };
65
+ // behind real work would turn a test's timeout into a machine-load verdict. `Bun.env` as well: a
66
+ // fixture calling in-process with its own small env is just as much inside the test run, and a
67
+ // timed-out one left its ticket at the head of the machine's queue until the worker exited.
68
+ const inTestRun = env['NODE_ENV'] === 'test' || Bun.env['NODE_ENV'] === 'test';
69
+ if (inTestRun && explicitDir === undefined) return { on: false, off: 'test-run' };
67
70
  const capacityMb = ledgerCapacityMb(env);
68
71
  if (capacityMb === 0) return { on: false, off: 'disabled' };
69
72
  const binding = await flockBinding();
@@ -105,15 +108,24 @@ export const describeEntry = (entry: LedgerEntry, now: number): string =>
105
108
 
106
109
  /** The waiter's one line. Stderr always: stdout may be a `--json` document. */
107
110
  export const waitLine = (label: string, wait: LedgerWait, now: number = Date.now()): string =>
108
- msg('cli.heavy.waiting', {
109
- label: printable(label),
110
- need: wait.needMb,
111
- position: wait.position,
112
- queued: wait.queued,
113
- used: wait.usedMb,
114
- capacity: wait.capacityMb,
115
- holders: wait.holds.map((entry) => describeEntry(entry, now)).join('; ') || '-',
116
- });
111
+ // No holder to name is the instant between two admissions, not a mystery owner.
112
+ msg(
113
+ wait.cpu !== undefined
114
+ ? 'cli.heavy.waitingCpu'
115
+ : wait.holds.length === 0
116
+ ? 'cli.heavy.waitingAdmission'
117
+ : 'cli.heavy.waiting',
118
+ {
119
+ label: printable(label),
120
+ need: wait.needMb,
121
+ position: wait.position,
122
+ queued: wait.queued,
123
+ used: wait.usedMb,
124
+ capacity: wait.capacityMb,
125
+ holders: wait.holds.map((entry) => describeEntry(entry, now)).join('; '),
126
+ cpu: wait.cpu === undefined ? '' : cpuText(wait.cpu),
127
+ },
128
+ );
117
129
 
118
130
  // Time this process has spent queued, so a gate step's deadline can stop counting it.
119
131
  let finishedWaitMs = 0;
@@ -145,6 +157,8 @@ export interface HeavyRequest {
145
157
  readonly baseMb?: number;
146
158
  readonly units?: number;
147
159
  readonly minUnits?: number;
160
+ /** Give up after this long in the queue (`x heavy run --max-wait`). */
161
+ readonly maxWaitMs?: number;
148
162
  }
149
163
 
150
164
  /** A reservation, or nothing when admission does not apply or could not work. */
@@ -160,12 +174,16 @@ async function enter(request: HeavyRequest, state: HeavyState): Promise<Reservat
160
174
  ...(request.baseMb === undefined ? {} : { baseMb: request.baseMb }),
161
175
  units: request.units ?? 1,
162
176
  minUnits: request.minUnits ?? request.units ?? 1,
177
+ ...(request.maxWaitMs === undefined ? {} : { maxWaitMs: request.maxWaitMs }),
178
+ ...(cpuGateOn(request.env) ? { cpu: () => readCpuPressure() } : {}),
163
179
  label: request.label,
164
180
  cwd: request.cwd,
165
181
  onWait: (wait) => writeErrorLine(waitLine(request.label, wait)),
166
182
  }),
167
183
  );
168
184
  } catch (error) {
185
+ // The caller set this bound: running anyway, unadmitted, is what it asked not to happen.
186
+ if (error instanceof HeavyWaitExpiredError) throw error;
169
187
  warnOnce(describe(error));
170
188
  return undefined;
171
189
  }
@@ -166,6 +166,26 @@ export async function checkRegistration(input: RegistrationInput): Promise<Regis
166
166
  export const unanswered = (catalog: Catalog, keys: readonly string[]): readonly string[] =>
167
167
  keys.filter((key) => !Object.hasOwn(catalog, key) || isLoudMiss(catalog[key]));
168
168
 
169
+ /**
170
+ * What `x i18n sync <locale>` writes for a key source names, per locale (`cmd-i18n.ts`'s
171
+ * `runSync`). The code's own comment said "as ⟦key⟧" of every locale and every key: a non-default
172
+ * locale gets the default's string marked, and an admin key in the default locale gets a real
173
+ * label — a reader who went looking for the ⟦ it promised found none.
174
+ */
175
+ const SOURCE_KEYS_WRITTEN =
176
+ 'writes each key above as a placeholder to replace with the real string: ⟦key⟧ in the default locale, ⟦the default locale’s string⟧ in any other';
177
+
178
+ /** The same, for a key a mounted admin derives (`adminCatalog`, `adminKeyLabel`). */
179
+ const ADMIN_KEYS_WRITTEN =
180
+ 'writes each key above: in the default locale the label x g resource --admin generates, a real string to keep or reword; in any other locale that label inside ⟦…⟧, to translate';
181
+
182
+ /** The finding with the code's own COMMAND and a comment that is true of what it writes. */
183
+ function missingKeysFinding(locale: Locale, missing: readonly string[], written: string): Finding {
184
+ const finding = findingFrom(catalogMissingKeys(locale, missing));
185
+ const [command = finding.fix] = finding.fix.split(' #');
186
+ return { ...finding, fix: `${command} # ${written}` };
187
+ }
188
+
169
189
  /**
170
190
  * `X_CATALOG_MISSING_KEYS` — the same fact, a catalog without keys it is asked for — with the
171
191
  * cause naming who asks. The fix stays the code's own, `x i18n sync <locale>`: it writes these keys
@@ -177,7 +197,7 @@ function adminKeysFinding(locale: Locale, missing: readonly string[]): Finding {
177
197
  const shown = missing.slice(0, 12).map((key) => `"${key}"`);
178
198
  const more = missing.length > shown.length ? `, +${missing.length - shown.length} more` : '';
179
199
  return {
180
- ...findingFrom(catalogMissingKeys(locale, missing)),
200
+ ...missingKeysFinding(locale, missing, ADMIN_KEYS_WRITTEN),
181
201
  cause: `${path} is missing ${missing.length} key(s) the mounted admin renders (defineAdmin derives them, so no source file names one): ${shown.join(', ')}${more}`,
182
202
  at: path,
183
203
  };
@@ -289,7 +309,7 @@ export function missingKeyFindings(report: ExtractReport): readonly Finding[] {
289
309
  const missing = report.locales
290
310
  .filter((audit) => audit.missing.length > 0)
291
311
  .map((audit) => ({
292
- ...findingFrom(catalogMissingKeys(audit.locale, audit.missing)),
312
+ ...missingKeysFinding(audit.locale, audit.missing, SOURCE_KEYS_WRITTEN),
293
313
  at: catalogPath(audit.locale),
294
314
  }));
295
315
  // A select or ordinal family with no `_other` renders `⟦key⟧` for every value it does not name:
@@ -97,8 +97,8 @@ export function harnessPage(input: HarnessPageInput): string {
97
97
  timeZone: input.target.timeZone,
98
98
  })}</script>`,
99
99
  '</head><body>',
100
- `<div id="x-shot-frame"><div ${emitIslandAttributes(directive)}></div></div>`,
101
- emitIslandProps(directive),
100
+ // The props script INSIDE the island's element, as the render walk writes it for a page.
101
+ `<div id="x-shot-frame"><div ${emitIslandAttributes(directive)}>${emitIslandProps(directive)}</div></div>`,
102
102
  hydrateRuntime([directive]),
103
103
  '</body></html>',
104
104
  ].join('');
package/src/job-budget.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  DRAIN_DEADLINE_DEFAULT_MS,
9
9
  finiteCount,
10
10
  isUltimateError,
11
+ laterHooksReserveMs,
11
12
  WORKER_DRAIN_DEADLINE_MAX_MS,
12
13
  WORKER_RETIRE_DEFAULT_MS,
13
14
  } from '@ultimat3/core';
@@ -27,7 +28,8 @@ type WorkerDrain = Pick<Partial<DrainConfig>, 'deadlineMs' | 'workerDeadlineMs'
27
28
 
28
29
  /**
29
30
  * The retire when on, for it aborts nothing; else when a SIGTERM drain CANCELS a held job, which is
30
- * the cut-off's `cancelAt` (`worker-drain-cutoff.ts`), a margin before the deadline itself.
31
+ * the cut-off's `cancelAt` (`worker-drain-cutoff.ts`): a margin before core's in-flight wait ends,
32
+ * which is itself the later hooks' reserve before the deadline (`ShutdownReason.inflightUntil`).
31
33
  */
32
34
  export function workerBudgetMs(drain: WorkerDrain | undefined): number {
33
35
  // Screened here, not trusted: `defineConfig` screens an app's config, but this is exported, and a
@@ -44,7 +46,7 @@ export function workerBudgetMs(drain: WorkerDrain | undefined): number {
44
46
  drain?.workerDeadlineMs ?? drain?.deadlineMs ?? DRAIN_DEADLINE_DEFAULT_MS,
45
47
  1,
46
48
  );
47
- return cutoffTimes(deadline, 0).cancelAt;
49
+ return cutoffTimes(deadline, 0, deadline - laterHooksReserveMs(deadline)).cancelAt;
48
50
  }
49
51
 
50
52
  function outlastsFinding(job: BudgetedJob, limitMs: number, budgetMs: number): Finding {
@@ -3,17 +3,27 @@
3
3
  // and every dead-letter trace — moves with the import order (`X_JOB_UNREGISTERED`). And an entity
4
4
  // declaring `partitionBy` with no `partitions()` job registered (`X_PARTITIONS_UNMAINTAINED`).
5
5
 
6
+ // why: Bun ships no path API; `posix` because the fix prints an import specifier on every OS.
7
+ import { join, posix } from 'node:path';
6
8
  import { ERROR_DOCS_URL } from '@ultimat3/core';
7
9
  import {
10
+ isJobHandle,
8
11
  isPartitionsJob,
12
+ isTaskHandle,
9
13
  partitionedEntities,
10
14
  registeredJobs,
11
15
  registeredTasks,
12
16
  } from '@ultimat3/jobs';
13
17
  import { loadApp } from './app-load';
14
18
  import type { AppLoader } from './app-permissions';
19
+ import { API_INDEX } from './app-root';
15
20
  import type { Finding } from './output';
16
21
 
22
+ /** The load, plus the modules it imported: where a positional job's file is looked up. */
23
+ type JobAppLoader = (
24
+ root: string,
25
+ ) => Promise<Awaited<ReturnType<AppLoader>> & { readonly files?: readonly string[] }>;
26
+
17
27
  /** What `job()` and `task()` name a declaration nobody named (`packages/jobs/src/job.ts`). */
18
28
  const POSITIONAL = /^anonymous-(job|task)-\d+$/;
19
29
 
@@ -24,16 +34,59 @@ export function positionalNames(
24
34
  return names.filter((name) => POSITIONAL.test(name)).sort();
25
35
  }
26
36
 
27
- export function unregisteredJobFinding(name: string): Finding {
28
- const kind = name.startsWith('anonymous-task-') ? 'tasks' : 'jobs';
37
+ /** `nudge-post` → `nudgePost`: the name the import line binds, a valid identifier either way. */
38
+ const moduleAlias = (file: string): string => {
39
+ const base = posix.basename(file).replace(/\.tsx?$/, '');
40
+ const [head = '', ...rest] = base.split(/[^A-Za-z0-9]+/).filter((word) => word !== '');
41
+ const alias = [head, ...rest.map((word) => word.charAt(0).toUpperCase() + word.slice(1))].join(
42
+ '',
43
+ );
44
+ return /^[A-Za-z_]/.test(alias) ? alias : `module${alias}`;
45
+ };
46
+
47
+ /** The import the API index needs, relative to it and without the extension. */
48
+ const importLine = (file: string, alias: string): string => {
49
+ const path = posix.relative(posix.dirname(API_INDEX), file).replace(/\.tsx?$/, '');
50
+ return `import * as ${alias} from '${path.startsWith('.') ? path : `./${path}`}';`;
51
+ };
52
+
53
+ /**
54
+ * `file` is the module exporting the job, when one does: the positional name moves between runs, so
55
+ * the path is the only thing that tells several agents in one checkout whose job this is.
56
+ */
57
+ export function unregisteredJobFinding(name: string, file?: string): Finding {
58
+ const task = name.startsWith('anonymous-task-');
59
+ const alias = file === undefined ? '<module>' : moduleAlias(file);
60
+ const line =
61
+ file === undefined ? `import * as ${alias} from '<its file>';` : importLine(file, alias);
62
+ const where = file === undefined ? '' : ` declared in ${file}`;
29
63
  return {
30
64
  code: 'X_JOB_UNREGISTERED',
31
- cause: `${name} is a ${kind === 'tasks' ? 'task' : 'job'} no defineApi() call names, so it carries the positional name ${kind === 'tasks' ? 'task()' : 'job()'} minted — on the queue row, in the manifest and in every dead-letter trace, and it moves when the import order does`,
32
- fix: `import * as <module> from '<its file>'; // in apps/web/api/index.ts, and <module> added to ${kind}: [...] there — then x manifest`,
33
- at: 'apps/web/api/index.ts',
65
+ cause: `${name}${where} is a ${task ? 'task' : 'job'} no defineApi() call names, so it carries the positional name ${task ? 'task()' : 'job()'} minted — on the queue row, in the manifest and in every dead-letter trace, and it moves when the import order does`,
66
+ fix: `${line} // in ${API_INDEX}, and ${alias} added to ${task ? 'tasks' : 'jobs'}: [...] there — then x manifest`,
67
+ at: file ?? API_INDEX,
34
68
  };
35
69
  }
36
70
 
71
+ /**
72
+ * Which loaded module exports each positional handle. The imports answer from the module cache: the
73
+ * load just evaluated these files. A handle no module exports has no file to name.
74
+ */
75
+ async function declaringFiles(
76
+ root: string,
77
+ files: readonly string[],
78
+ ): Promise<ReadonlyMap<string, string>> {
79
+ const found = new Map<string, string>();
80
+ for (const file of files) {
81
+ const module = (await import(join(root, file))) as Record<string, unknown>;
82
+ for (const value of Object.values(module)) {
83
+ if (!isJobHandle(value) && !isTaskHandle(value)) continue;
84
+ if (POSITIONAL.test(value.name) && !found.has(value.name)) found.set(value.name, file);
85
+ }
86
+ }
87
+ return found;
88
+ }
89
+
37
90
  /**
38
91
  * The step's answer. Loads the app the way every other gate step does — the registries are only
39
92
  * whole after the scan — and says nothing when the load failed: a short registry is the load's
@@ -41,11 +94,14 @@ export function unregisteredJobFinding(name: string): Finding {
41
94
  */
42
95
  export async function unregisteredJobFindings(
43
96
  root: string,
44
- load: AppLoader = loadApp,
97
+ load: JobAppLoader = loadApp,
45
98
  ): Promise<readonly Finding[]> {
46
- if ((await load(root)).findings.length > 0) return [];
99
+ const app = await load(root);
100
+ if (app.findings.length > 0) return [];
101
+ const names = positionalNames();
102
+ const files = names.length === 0 ? new Map() : await declaringFiles(root, app.files ?? []);
47
103
  return [
48
- ...positionalNames().map(unregisteredJobFinding),
104
+ ...names.map((name) => unregisteredJobFinding(name, files.get(name))),
49
105
  ...unmaintainedPartitionFindings(
50
106
  partitionedEntities().map((described) => described.table),
51
107
  registeredJobs(),
@@ -0,0 +1,43 @@
1
+ // `x jobs pause|resume <queue>` names a queue this app serves. A typo paused nothing and reported
2
+ // success, and the runbook's next step (poll the queue until it is empty) then passed at once
3
+ // while the real queue kept claiming. The set is `x deploy verify`'s: config plus registered jobs.
4
+
5
+ import { nearestName, renderCauseValue, UltimateError } from '@ultimat3/core';
6
+ import { expectedQueues } from './deploy-verify-queues';
7
+ import { quoteArg } from './shell-quote';
8
+
9
+ /** The queue positional names nothing this app's workers claim from. */
10
+ export class JobsQueueUnknownError extends UltimateError {
11
+ constructor(input: { sub: 'pause' | 'resume'; queue: string; known: readonly string[] }) {
12
+ const nearest = nearestName(input.queue, input.known);
13
+ super({
14
+ code: 'X_CLI_BAD_FLAG',
15
+ cause: `"x jobs ${input.sub}" was given queue ${renderCauseValue(input.queue)}, which is not a queue of this app (${input.known.map((queue) => renderCauseValue(queue)).join(', ')}) — no worker claims from it, so the ${input.sub} would change nothing`,
16
+ fix:
17
+ nearest === undefined
18
+ ? 'x jobs list --json # data.depth.queues names what each queue holds'
19
+ : ['x', 'jobs', input.sub, quoteArg(nearest), '--json'].join(' '),
20
+ meta: { queue: input.queue, known: [...input.known] },
21
+ });
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Refuses before the pause row is written. An app that will not load is "cannot tell" — its jobs'
27
+ * queues are the half of the set a broken module hides — and is never refused on a guess. `resume`
28
+ * of a queue that IS paused always passes: that row is what the command exists to clear.
29
+ */
30
+ export async function assertQueueServed(
31
+ root: string,
32
+ sub: 'pause' | 'resume',
33
+ queue: string,
34
+ paused: readonly string[],
35
+ ): Promise<void> {
36
+ if (sub === 'resume' && paused.includes(queue)) return;
37
+ const expected = await expectedQueues(root);
38
+ // An app with no module at all hides nothing: its set is the configured queues, whole.
39
+ if (expected.findings.some((finding) => finding.code !== 'X_APP_EMPTY')) return;
40
+ // Nothing configured and nothing registered is the worker's own `default`.
41
+ const known = expected.queues.length === 0 ? ['default'] : expected.queues;
42
+ if (!known.includes(queue)) throw new JobsQueueUnknownError({ sub, queue, known });
43
+ }
@@ -0,0 +1,20 @@
1
+ // `errors.explain`'s rows for the codes of agents sharing a machine and a repository (`error-codes-
2
+ // agents.ts`), split out of `mcp-errors.ts` under the 500-line ceiling. Spread into `CLI_FIXES`
3
+ // there, whose `Record<CliErrorCode, string>` is still what makes a code without a row a build error.
4
+
5
+ import type { CliErrorCode } from './error-codes';
6
+
7
+ export const AGENTS_FIXES = {
8
+ X_PORT_IN_USE: 'x dev --port 3001 --json',
9
+ X_DEV_ALREADY_RUNNING:
10
+ 'x dev --json # after stopping the x dev that already owns this checkout',
11
+ // The path, not `x dev`: the boot has already refused and rerunning it refuses again. The
12
+ // error's own `fix:` carries the resolved `.x/dev.lock`; this table cannot know the state dir.
13
+ X_DEV_LOCK_UNREADABLE: 'rm .x/dev.lock # then: x dev --json',
14
+ X_UPGRADE_LOCKED: 'cat .x/upgrade.lock',
15
+ X_HEAVY_WAIT_EXPIRED: 'x heavy status --json',
16
+ X_MERGE_UNRESOLVED: 'git diff --name-only --diff-filter=U',
17
+ X_MERGE_DRIVER_UNSET: 'bunx x merge-driver install',
18
+ X_CATALOG_UNPARSEABLE: 'bunx biome check packages/i18n/catalogs',
19
+ X_DOCTOR_PROBE_FAILED: 'bunx x manifest --json',
20
+ } as const satisfies Partial<Record<CliErrorCode, string>>;
@@ -0,0 +1,27 @@
1
+ // `errors.explain`'s rows for the codes `error-codes-doctor.ts` owns: `x doctor`'s warnings and
2
+ // the upgrade's, split out of `mcp-errors.ts` under the 500-line ceiling. Spread into `CLI_FIXES`
3
+ // there, whose `Record<CliErrorCode, string>` makes a code without a row a build error.
4
+
5
+ import type { CliErrorCode } from './error-codes';
6
+
7
+ export const DOCTOR_FIXES = {
8
+ X_EXERCISE_UNPROVEN_ABOVE_FLOOR:
9
+ 'x exercise --json # re-measures at the constant seed the gate runs (a floor from before 31.47.0 was measured under random seeds); each unproven record in .x/exercise.json names the proof and its reason: fix the seed helper or override it names, assuming no order between sized calls; the floor only falls',
10
+ X_ENV_NAME_RESERVED:
11
+ 'edit app.config.ts: add an APP_ prefix to the envSchema name the finding cites (or delete it where the value is meant for the framework); then: x env example --json && x doctor --json',
12
+ X_FRAMEWORK_PIN_RANGE:
13
+ 'x doctor --json # each X_FRAMEWORK_PIN_RANGE names a package.json line and the exact version: write it there, then: bun install',
14
+ X_VERIFY_STEP_UNFLOORED:
15
+ 'x doctor --json # its X_VERIFY_STEP_UNFLOORED fix names the steps: run that x verify --only, then add each step that passed, not skipped, to "steps" in x.verify.json',
16
+ X_DB_ROW_SECURITY_OFF:
17
+ 'database: { rowSecurity: true } # in defineConfig, app.config.ts; then: x db gen "row security" --json && x db migrate --json && x doctor --json',
18
+ X_DB_INDEX_UNDECLARED:
19
+ 'x verify --only drift --json # each X_DB_INDEX_UNDECLARED warning names the index: its DROP INDEX CONCURRENTLY IF EXISTS "<name>"; goes in a new hand-written migration (-- transaction: false), or declare it in the entity\'s indexes: [...] and x db gen "<change>"',
20
+ X_SHIPPED_GUARD_MISSING:
21
+ "x doctor --json # each X_SHIPPED_GUARD_MISSING warning's fix is the command that writes its guard, then x verify --only boundaries --json",
22
+ X_SUPERSEDED_WORKAROUND:
23
+ 'x doctor --json # each finding names the file, the release that retired the workaround and its replacement',
24
+ X_GUARD_VENDORED: 'x upgrade --json',
25
+ X_ADVISORY_FLOOR_UNMET: 'bun update source-map-js immutable',
26
+ X_UPGRADE_CODEMODS_PENDING: 'x upgrade codemods --from 0.0.0 --json',
27
+ } as const satisfies Partial<Record<CliErrorCode, string>>;
@@ -0,0 +1,23 @@
1
+ // `errors.explain`'s rows for processes per container (`ULTIMATE_PROCESSES`) — the supervisor's
2
+ // family, split out of `mcp-errors.ts` under the 500-line ceiling. Spread into `CLI_FIXES` there,
3
+ // whose `Record<CliErrorCode, string>` is still what makes a code without a row a build error.
4
+
5
+ import type { CliErrorCode } from './error-codes';
6
+
7
+ export const PROCESSES_FIXES = {
8
+ X_PROCESSES_INVALID:
9
+ 'export ULTIMATE_PROCESSES=auto # in the deploy environment of this service, or a positive whole number such as 2',
10
+ X_PROCESSES_ROLE_SINGLETON:
11
+ 'export ULTIMATE_PROCESSES=1 # in the environment of the scheduler, replicator and migrate services',
12
+ X_PROCESSES_UNSHARED_STATE:
13
+ "export ULTIMATE_PROCESSES=1 # or share the state: set NATS_URL (REDIS_URL or VALKEY_URL for the cache) and drop the per-process store from the app's runtime.ts; the error lists each",
14
+ X_PROCESSES_OVER_POOL:
15
+ 'export ULTIMATE_PROCESSES=1 # or raise DATABASE_POOL_MAX to at least the count; the error names both numbers',
16
+ X_PROCESSES_UNBALANCED: 'export ULTIMATE_PROCESSES=1 # or run the image in a Linux container',
17
+ X_PROCESS_CRASH_LOOP:
18
+ 'docker compose logs --tail 200 # the last error line with the crashing child index names the boot error to fix',
19
+ X_PROCESSES_CPU_UNDECLARED:
20
+ "cpus: '2' # on the role's service in docker/docker-compose.prod.yml",
21
+ X_PROCESSES_MIGRATE_REQ_OFF:
22
+ 'sysctls: { net.ipv4.tcp_migrate_req: 1 } # uncomment it on web and sync in docker/docker-compose.prod.yml; Linux >= 5.14 only, an older kernel refuses to create the container',
23
+ } as const satisfies Partial<Record<CliErrorCode, string>>;