@ultimat3/cli 31.47.1 → 31.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/CLAUDE.md +30 -23
  2. package/README.md +96 -4
  3. package/package.json +29 -29
  4. package/src/api-registration.ts +28 -14
  5. package/src/app-load.ts +6 -1
  6. package/src/app-root.ts +7 -1
  7. package/src/clean-services.ts +142 -0
  8. package/src/cmd-auth.ts +3 -0
  9. package/src/cmd-clean-spec.ts +10 -3
  10. package/src/cmd-clean.ts +23 -9
  11. package/src/cmd-db-backfill.ts +6 -0
  12. package/src/cmd-db-branch.ts +10 -4
  13. package/src/cmd-db-recount.ts +5 -12
  14. package/src/cmd-db-rollback.ts +77 -0
  15. package/src/cmd-db-spec.ts +18 -2
  16. package/src/cmd-db-status.ts +5 -10
  17. package/src/cmd-db.ts +105 -33
  18. package/src/cmd-deploy-verify.ts +14 -6
  19. package/src/cmd-docs-topic.ts +94 -0
  20. package/src/cmd-docs.ts +15 -1
  21. package/src/cmd-doctor.ts +109 -41
  22. package/src/cmd-drill.ts +100 -19
  23. package/src/cmd-env.ts +30 -8
  24. package/src/cmd-errors-app.ts +63 -0
  25. package/src/cmd-errors.ts +50 -14
  26. package/src/cmd-generate.ts +17 -4
  27. package/src/cmd-heavy-spec.ts +36 -0
  28. package/src/cmd-heavy.ts +244 -0
  29. package/src/cmd-jobs.ts +27 -1
  30. package/src/cmd-merge-driver-spec.ts +12 -0
  31. package/src/cmd-merge-driver.ts +95 -0
  32. package/src/cmd-new.ts +23 -3
  33. package/src/cmd-policy-spec.ts +9 -1
  34. package/src/cmd-policy.ts +72 -17
  35. package/src/cmd-stop.ts +18 -4
  36. package/src/cmd-tasks-run.ts +87 -0
  37. package/src/cmd-tasks-spec.ts +10 -3
  38. package/src/cmd-tasks.ts +8 -5
  39. package/src/cmd-test.ts +15 -4
  40. package/src/cmd-upgrade-spec.ts +8 -1
  41. package/src/cmd-upgrade.ts +32 -5
  42. package/src/cmd-verify.ts +9 -41
  43. package/src/codemods/agents-doc-row.ts +73 -0
  44. package/src/codemods/define-error-leaf.ts +37 -12
  45. package/src/codemods/docs-many-agents.ts +26 -0
  46. package/src/codemods/docs-worker-commands.ts +26 -0
  47. package/src/codemods/index.ts +6 -0
  48. package/src/codemods/merge-drivers.ts +66 -0
  49. package/src/command.ts +3 -0
  50. package/src/db-applied-edits.ts +117 -0
  51. package/src/db-dev-wire.ts +18 -0
  52. package/src/db-diagnostics.ts +5 -10
  53. package/src/db-generate.ts +82 -7
  54. package/src/db-migrate-pass.ts +51 -0
  55. package/src/db-migrate-through-dev.ts +209 -0
  56. package/src/db-rollback-consent.ts +128 -0
  57. package/src/db-rollback-pass.ts +76 -0
  58. package/src/db-seed-generate.ts +5 -1
  59. package/src/db-seed.ts +7 -1
  60. package/src/deploy-verify-findings.ts +3 -0
  61. package/src/deploy-verify-grade.ts +3 -0
  62. package/src/deploy-verify-processes.ts +32 -0
  63. package/src/dev-boot.ts +3 -0
  64. package/src/dev-db-migrate.ts +155 -0
  65. package/src/dev-db-rollback.ts +33 -0
  66. package/src/dev-db-settled.ts +22 -0
  67. package/src/dev-lock-errors.ts +78 -0
  68. package/src/dev-lock-holder-dir.ts +64 -0
  69. package/src/dev-lock-live.ts +44 -0
  70. package/src/dev-lock.ts +59 -84
  71. package/src/dev-policy.ts +11 -8
  72. package/src/dev-rebuild-schema.ts +116 -13
  73. package/src/dev-rebuild.ts +13 -4
  74. package/src/dev-route-table.ts +7 -0
  75. package/src/dispatch.ts +21 -1
  76. package/src/doctor-advisory-floors.ts +30 -8
  77. package/src/doctor-api-listing.ts +114 -0
  78. package/src/doctor-guarded.ts +41 -0
  79. package/src/doctor-port.ts +90 -17
  80. package/src/doctor-probe.ts +36 -5
  81. package/src/doctor-processes-probe.ts +127 -0
  82. package/src/doctor-processes.ts +136 -0
  83. package/src/doctor-warnings.ts +17 -0
  84. package/src/error-codes-agents.ts +35 -0
  85. package/src/error-codes-processes.ts +30 -0
  86. package/src/error-codes-tooling.ts +11 -3
  87. package/src/error-codes.ts +12 -13
  88. package/src/errors-suite.ts +27 -0
  89. package/src/errors.ts +18 -22
  90. package/src/exec.ts +11 -3
  91. package/src/exercise-registration.ts +4 -3
  92. package/src/framework-env.ts +7 -3
  93. package/src/generate-files.ts +1 -0
  94. package/src/generate-grant-findings.ts +7 -5
  95. package/src/generate-grants.ts +9 -8
  96. package/src/generate-kinds.ts +30 -6
  97. package/src/generate-roles-file.ts +30 -0
  98. package/src/generate-slice-policy.ts +3 -3
  99. package/src/guards.ts +2 -2
  100. package/src/heavy-cores.ts +51 -0
  101. package/src/heavy-env.ts +21 -0
  102. package/src/heavy-errors.ts +54 -0
  103. package/src/heavy-flock.ts +73 -0
  104. package/src/heavy-holders.ts +78 -0
  105. package/src/heavy-ledger.ts +400 -0
  106. package/src/heavy-memory.ts +67 -0
  107. package/src/heavy-pressure.ts +104 -0
  108. package/src/heavy-weights.ts +47 -0
  109. package/src/heavy.ts +308 -0
  110. package/src/i18n-registration.ts +22 -2
  111. package/src/island-harness.ts +2 -2
  112. package/src/job-budget.ts +4 -2
  113. package/src/job-registration.ts +64 -8
  114. package/src/jobs-queue-known.ts +43 -0
  115. package/src/local-cli.ts +6 -5
  116. package/src/mcp-errors-agents.ts +20 -0
  117. package/src/mcp-errors-doctor.ts +27 -0
  118. package/src/mcp-errors-processes.ts +23 -0
  119. package/src/mcp-errors.ts +18 -29
  120. package/src/mcp-host.ts +2 -2
  121. package/src/merge-driver-catalog.ts +58 -0
  122. package/src/merge-driver-config.ts +43 -0
  123. package/src/merge-driver-lines.ts +140 -0
  124. package/src/merge-state.ts +105 -0
  125. package/src/messages-db.ts +22 -1
  126. package/src/messages-processes.ts +13 -0
  127. package/src/messages-upgrade.ts +6 -0
  128. package/src/messages.ts +62 -1
  129. package/src/output-findings.ts +48 -21
  130. package/src/parse.ts +37 -6
  131. package/src/policy-facts.ts +38 -21
  132. package/src/policy-row.ts +99 -0
  133. package/src/port-pair-free.ts +28 -0
  134. package/src/registry-lines.ts +110 -0
  135. package/src/registry.ts +4 -0
  136. package/src/retain-sweep.ts +1 -1
  137. package/src/role-replicator.ts +9 -4
  138. package/src/role-select.ts +86 -0
  139. package/src/role-start.ts +13 -55
  140. package/src/role-sync.ts +10 -5
  141. package/src/runtime-cache-frame.ts +46 -0
  142. package/src/runtime-cache-ttl.ts +23 -0
  143. package/src/runtime-cache.ts +56 -18
  144. package/src/runtime-database-ssl.ts +84 -0
  145. package/src/runtime-idempotency-scope.ts +16 -2
  146. package/src/runtime-jobs-share.ts +52 -0
  147. package/src/runtime-jobs.ts +43 -12
  148. package/src/runtime-overrides.ts +4 -2
  149. package/src/runtime-queue.ts +18 -3
  150. package/src/runtime-services.ts +8 -1
  151. package/src/schema-drift.ts +19 -2
  152. package/src/schema-dump-drift.ts +4 -1
  153. package/src/serve-boot-probe.ts +30 -2
  154. package/src/serve-boot.ts +11 -1
  155. package/src/serve-env.ts +39 -3
  156. package/src/serve.ts +61 -10
  157. package/src/stop-run-start.ts +12 -0
  158. package/src/supervise-boot.ts +61 -0
  159. package/src/supervise-cgroup.ts +84 -0
  160. package/src/supervise-child.ts +206 -0
  161. package/src/supervise-count.ts +244 -0
  162. package/src/supervise-errors.ts +83 -0
  163. package/src/supervise-facts.ts +40 -0
  164. package/src/supervise-messages.ts +84 -0
  165. package/src/supervise-policy.ts +46 -0
  166. package/src/supervise-pool.ts +10 -0
  167. package/src/supervise-probe.ts +158 -0
  168. package/src/supervise-run.ts +54 -0
  169. package/src/supervise.ts +383 -0
  170. package/src/templates/generate-purge.ts +6 -6
  171. package/src/templates/guard-animated-layout-property.ts +2 -2
  172. package/src/templates/guard-bare-error.ts +1 -1
  173. package/src/templates/guard-error-declared.ts +2 -2
  174. package/src/templates/guard-focus-visible.ts +1 -1
  175. package/src/templates/guard-image-dimensions.ts +2 -2
  176. package/src/templates/guard-island-mount-clears.ts +1 -1
  177. package/src/templates/guard-native-confirm.ts +1 -1
  178. package/src/templates/guard-raw-breakpoint.ts +2 -2
  179. package/src/templates/guard-raw-colour.ts +2 -2
  180. package/src/templates/guard-raw-fetch.ts +1 -1
  181. package/src/templates/guard-raw-interval.ts +1 -1
  182. package/src/templates/guard-raw-length.ts +3 -3
  183. package/src/templates/guard-raw-motion.ts +1 -1
  184. package/src/templates/guard-raw-shadow.ts +1 -1
  185. package/src/templates/guard-raw-z-index.ts +1 -1
  186. package/src/templates/guard-released-forms.ts +59 -13
  187. package/src/templates/guard-repo-await-in-loop.ts +1 -1
  188. package/src/templates/guard-repo-raw-sql.ts +4 -4
  189. package/src/templates/guard-repo-unbounded.ts +1 -1
  190. package/src/templates/guard-runtime-pin.ts +1 -1
  191. package/src/templates/guard-semantic-interactive.ts +2 -2
  192. package/src/templates/guard-unbounded-fanout.ts +1 -1
  193. package/src/templates/guard-undeclared-custom-property.ts +3 -3
  194. package/src/templates/guard-undefined-style-class.ts +3 -3
  195. package/src/templates/guard-unzoned-date.ts +3 -3
  196. package/src/templates/query-slice.ts +82 -0
  197. package/src/templates/query.ts +76 -30
  198. package/src/templates/resource-page.ts +3 -2
  199. package/src/templates/scaffold-bin.ts +2 -0
  200. package/src/templates/scaffold-claude-agents.ts +9 -6
  201. package/src/templates/scaffold-claude-commands.ts +7 -1
  202. package/src/templates/scaffold-claude.ts +4 -4
  203. package/src/templates/scaffold-container-compose.ts +47 -7
  204. package/src/templates/scaffold-docs.ts +11 -6
  205. package/src/templates/scaffold-gitattributes.ts +18 -1
  206. package/src/templates/scaffold-helm-templates.ts +9 -0
  207. package/src/templates/scaffold-repo.ts +4 -1
  208. package/src/templates/scaffold-test-services.ts +33 -11
  209. package/src/templates/shapes/offline.ts +0 -7
  210. package/src/templates/shapes/realtime.ts +2 -6
  211. package/src/templates/sign-in-action-tests.ts +6 -4
  212. package/src/templates/sign-in-challenge.ts +62 -0
  213. package/src/templates/sign-in-oidc-mfa.ts +31 -0
  214. package/src/templates/sign-in-oidc.ts +11 -3
  215. package/src/templates/sign-in-password.ts +18 -56
  216. package/src/test-batches.ts +9 -3
  217. package/src/test-shards.ts +117 -37
  218. package/src/test-slots.ts +35 -161
  219. package/src/test-verdict.ts +79 -0
  220. package/src/test-workers.ts +15 -0
  221. package/src/upgrade-gate-codemods.ts +5 -3
  222. package/src/upgrade-gate.ts +19 -1
  223. package/src/upgrade-merge-drivers.ts +25 -0
  224. package/src/upgrade-report.ts +18 -4
  225. package/src/upgrade-scope.ts +62 -0
  226. package/src/verify-checks.ts +6 -11
  227. package/src/verify-coverage-run.ts +9 -5
  228. package/src/verify-deadline.ts +18 -2
  229. package/src/verify-heavy-steps.ts +26 -0
  230. package/src/verify-live.ts +38 -14
  231. package/src/verify-only.ts +67 -0
  232. package/src/verify-progress.ts +7 -3
  233. package/src/verify-run.ts +20 -2
  234. package/src/verify-services-stack.ts +165 -0
  235. package/src/verify-services.ts +84 -2
  236. package/src/verify-test-run.ts +9 -9
  237. package/src/verify-tests.ts +35 -22
  238. package/src/verify-typecheck.ts +25 -2
  239. package/wiki/Actions.md +2 -1
  240. package/wiki/Admin-Dashboard.md +2 -2
  241. package/wiki/Agents.md +5 -5
  242. package/wiki/Auth.md +15 -5
  243. package/wiki/Bare-VM.md +1 -1
  244. package/wiki/Building-Your-Own-Base.md +15 -2
  245. package/wiki/CI-Parallel-Gate.md +4 -4
  246. package/wiki/CLI-Reference.md +127 -48
  247. package/wiki/Caching-And-Invalidation.md +2 -2
  248. package/wiki/Client-Navigation.md +1 -1
  249. package/wiki/Configuration.md +32 -13
  250. package/wiki/Deployment.md +44 -4
  251. package/wiki/Entities-And-Migrations.md +5 -1
  252. package/wiki/FAQ.md +1 -1
  253. package/wiki/Getting-Started.md +2 -2
  254. package/wiki/Home.md +2 -1
  255. package/wiki/I18n.md +5 -3
  256. package/wiki/Installation.md +12 -11
  257. package/wiki/Interface-Rules.md +1 -1
  258. package/wiki/Jobs-And-Workflows.md +24 -4
  259. package/wiki/Known-Gaps.md +2 -2
  260. package/wiki/MCP-And-AI.md +8 -5
  261. package/wiki/Mail.md +1 -1
  262. package/wiki/Many-Agents.md +127 -0
  263. package/wiki/Migrations-And-Backfills.md +18 -0
  264. package/wiki/Notify.md +1 -1
  265. package/wiki/Observability.md +13 -0
  266. package/wiki/Queries-And-Live-Queries.md +2 -2
  267. package/wiki/Realtime.md +10 -1
  268. package/wiki/Routes-And-Render-Modes.md +1 -1
  269. package/wiki/Scheduled-Tasks.md +4 -1
  270. package/wiki/Testing.md +12 -9
  271. package/wiki/Timezones-And-Dates.md +5 -1
  272. package/wiki/Troubleshooting.md +1 -0
  273. package/wiki/Tutorial-01-First-App.md +5 -5
  274. package/wiki/Tutorial-02-First-Feature.md +1 -1
  275. package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
  276. package/wiki/Upgrading.md +37 -0
package/src/cmd-new.ts CHANGED
@@ -23,6 +23,7 @@ import { runShapeGenerators } from './new-shapes-generate';
23
23
  import type { CommandResult } from './output';
24
24
  import { flagBool, flagString } from './parse';
25
25
  import { posixRelative } from './posix-path';
26
+ import { withRegistryLines } from './registry-lines';
26
27
  import { quoteArg } from './shell-quote';
27
28
  import type { GeneratedFile } from './templates';
28
29
  import { appFiles, names, repoFiles, resourceFiles } from './templates';
@@ -36,6 +37,12 @@ export interface NewAppOptions {
36
37
  readonly example: boolean;
37
38
  /** `--shape`: an overlay over the scaffold below (`templates/shapes/`); absent is the default. */
38
39
  readonly shape?: NewShape | undefined;
40
+ /**
41
+ * The directory the app lands in. Hashed into the test stack's compose project and ports, so two
42
+ * checkouts of one name never share a stack; absent (a pure plan, the codemods' render), the
43
+ * bytes are the ones every earlier scaffold wrote.
44
+ */
45
+ readonly root?: string | undefined;
39
46
  }
40
47
 
41
48
  /** `--no-git`'s `problem`, matched rather than re-spelled where the report decides on a line. */
@@ -141,17 +148,29 @@ const cdTarget = (cwd: string, target: string): string => quoteArg(displayPath(c
141
148
  const shapeGenerateLines = (shape: NewShape): readonly string[] =>
142
149
  (SHAPE_OVERLAYS[shape].generate ?? []).map((argv) => ['x', 'g', ...argv].join(' '));
143
150
 
144
- /** Pure: the complete file list for a new app, so `--dry-run` and the test see the same thing. */
151
+ /**
152
+ * Pure: the complete file list for a new app, so `--dry-run` and the test see the same thing. The
153
+ * registries take their one-entry-per-line shape last: a shape's overlay edits the lists as the
154
+ * templates print them.
155
+ */
145
156
  export function planNewApp(options: NewAppOptions): readonly GeneratedFile[] {
157
+ return planFiles(options).map((file) =>
158
+ typeof file.contents === 'string' && file.merge === undefined
159
+ ? { ...file, contents: withRegistryLines(file.path, file.contents) }
160
+ : file,
161
+ );
162
+ }
163
+
164
+ function planFiles(options: NewAppOptions): readonly GeneratedFile[] {
146
165
  if (options.shape !== undefined) {
147
166
  const overlay = SHAPE_OVERLAYS[options.shape];
148
- const base = planNewApp({ name: options.name, example: overlay.example });
167
+ const base = planFiles({ name: options.name, example: overlay.example, root: options.root });
149
168
  // Merge-aware, as below: a shape's catalog keys land in the one catalog the base wrote.
150
169
  return withDeclaredExercises(dedupe(applyOverlay(base, overlay, names(options.name))));
151
170
  }
152
171
  const app = names(options.name);
153
172
  const files: GeneratedFile[] = [
154
- ...repoFiles(app, loadVersion(), options.example),
173
+ ...repoFiles(app, loadVersion(), options.example, options.root),
155
174
  ...appFiles(app, options.example),
156
175
  ];
157
176
  if (options.example) {
@@ -282,6 +301,7 @@ export const newCommand: CliCommand = {
282
301
  name: raw,
283
302
  example: ctx.args.flags.get('example') !== false,
284
303
  shape,
304
+ root: target,
285
305
  };
286
306
 
287
307
  if (flagBool(ctx.args, 'dry-run')) {
@@ -6,8 +6,16 @@ import type { CommandSpec } from './parse';
6
6
  export const policySpec: CommandSpec = {
7
7
  name: 'policy',
8
8
  summary: 'which clause decided a permission, and why',
9
- usage: 'x policy [list|explain <subject>] [--json]',
9
+ usage: "x policy [list|explain <subject> [--input '<json>']] [--json]",
10
10
  requiresApp: true,
11
11
  subcommands: ['list', 'explain'],
12
12
  defaultSubcommand: 'list',
13
+ flags: [
14
+ {
15
+ name: 'input',
16
+ type: 'string',
17
+ summary: "the request's input as JSON — what a predicate that reads input is decided on",
18
+ subcommands: ['explain'],
19
+ },
20
+ ],
13
21
  };
package/src/cmd-policy.ts CHANGED
@@ -7,11 +7,13 @@ import { loadApp } from './app-load';
7
7
  import { requireAppRoot } from './app-root';
8
8
  import { policySpec } from './cmd-policy-spec';
9
9
  import type { CliCommand, CommandContext } from './command';
10
- import { DeclarationUnknownError, MissingPositionalError } from './errors';
10
+ import { BadFlagError, DeclarationUnknownError, MissingPositionalError } from './errors';
11
11
  import { msg } from './messages';
12
12
  import type { CommandResult, Finding, JsonValue } from './output';
13
- import type { DeclarationExplanation } from './policy-facts';
13
+ import type { DeclarationExplanation, ExplainOptions } from './policy-facts';
14
14
  import { explainPolicy, knownPolicySubjects, listPolicy } from './policy-facts';
15
+ import type { ExplainVerdict } from './policy-row';
16
+ import { quoteArg } from './shell-quote';
15
17
  import { renderTable } from './table';
16
18
 
17
19
  /** A descriptor is plain JSON by construction — same idiom as `cmd-registries.ts`'s `asJson`. */
@@ -49,27 +51,68 @@ function runList(findings: readonly Finding[]): CommandResult {
49
51
  };
50
52
  }
51
53
 
54
+ const VERDICT_KEYS = {
55
+ allow: 'cli.policy.allow',
56
+ deny: 'cli.policy.deny',
57
+ 'needs-input': 'cli.policy.needsInput',
58
+ } as const satisfies Record<ExplainVerdict, string>;
59
+
52
60
  /** A header naming the declaration and its policy label, then the actor/verdict/deciding table. */
53
- function declarationLines(declaration: DeclarationExplanation): readonly string[] {
61
+ function declarationLines(
62
+ declaration: DeclarationExplanation,
63
+ withInput: boolean,
64
+ ): readonly string[] {
54
65
  const header = ` ${msg('cli.policy.declaration', {
55
66
  kind: declaration.kind,
56
67
  name: declaration.name,
57
68
  label: declaration.label,
58
69
  })}`;
59
- // Both notes say the same thing `dev-policy.ts` writes into the `/_x` trace: this ran outside a
60
- // request. A policy that merely reads input gets its table plus the caveat; one that cannot be
61
- // evaluated at all gets the caveat instead of a table, never a synthetic deny dressed as one.
62
- if (!declaration.decidable) return [header, ` ${msg('cli.policy.undecidable')}`];
70
+ // Undecidable only on an input it was handed and threw on: the caveat instead of a table, never
71
+ // a synthetic deny dressed as one. With no input a predicate that reads one is a `needs input`
72
+ // row — "not decided", which a deny would misreport about an actor the request lets through.
73
+ if (!declaration.decidable) return [header, ` ${msg('cli.policy.undecidableInput')}`];
63
74
  const rows = declaration.rows.map((row) => [
64
75
  row.actor,
65
- msg(row.allowed ? 'cli.policy.allow' : 'cli.policy.deny'),
76
+ msg(VERDICT_KEYS[row.verdict]),
66
77
  row.deciding ?? msg('cli.policy.none'),
67
78
  row.reason ?? msg('cli.policy.none'),
68
79
  ]);
69
80
  const table = renderTable(['actor', 'verdict', 'deciding', 'reason'], rows).map(
70
81
  (line) => ` ${line}`,
71
82
  );
72
- return [header, ...table, ` ${msg('cli.policy.noInput')}`];
83
+ return [
84
+ header,
85
+ ...table,
86
+ ` ${msg(withInput ? 'cli.policy.withInput' : 'cli.policy.noInput')}`,
87
+ ];
88
+ }
89
+
90
+ /**
91
+ * `--input '<json>'`: the request's input, for a predicate that reads one. Any JSON value — the
92
+ * action's own schema is not applied, because the question is what the POLICY decides on it.
93
+ */
94
+ function readInput(ctx: CommandContext): ExplainOptions {
95
+ const raw = ctx.args.flags.get('input');
96
+ if (raw === undefined) return {};
97
+ if (typeof raw !== 'string') {
98
+ throw new BadFlagError({
99
+ flag: 'input',
100
+ command: 'policy explain',
101
+ reason: 'it takes the request input as one JSON argument',
102
+ fix: `x policy explain ${quoteArg(ctx.args.positionals)} --input '{}' --json`,
103
+ });
104
+ }
105
+ try {
106
+ return { input: { value: JSON.parse(raw) as unknown } };
107
+ } catch {
108
+ throw new BadFlagError({
109
+ flag: 'input',
110
+ command: 'policy explain',
111
+ // The length, never the text: a request body pasted here may carry a credential.
112
+ reason: `its value (${raw.length} characters) is not JSON`,
113
+ fix: `x policy explain ${quoteArg(ctx.args.positionals)} --input '{"id":"<the request field>"}' --json`,
114
+ });
115
+ }
73
116
  }
74
117
 
75
118
  function requireSubject(ctx: CommandContext): string {
@@ -89,7 +132,8 @@ function requireSubject(ctx: CommandContext): string {
89
132
 
90
133
  function runExplain(ctx: CommandContext, findings: readonly Finding[]): CommandResult {
91
134
  const name = requireSubject(ctx);
92
- const explanation = explainPolicy(name);
135
+ const options = readInput(ctx);
136
+ const explanation = explainPolicy(name, options);
93
137
  if (explanation === undefined) {
94
138
  const known = knownPolicySubjects();
95
139
  const suggestion = nearestName(name, known);
@@ -102,21 +146,32 @@ function runExplain(ctx: CommandContext, findings: readonly Finding[]): CommandR
102
146
  // One row per (declaration, actor) pair — a permission two declarations enforce evaluates every
103
147
  // actor twice, so this counts evaluations and never roles.
104
148
  const rows = explanation.declarations.flatMap((declaration) => declaration.rows);
105
- const allowed = rows.filter((row) => row.allowed).length;
149
+ const allowed = rows.filter((row) => row.verdict === 'allow').length;
150
+ const pending = rows.filter((row) => row.verdict === 'needs-input').length;
151
+ const counts = { subject: explanation.subject, allowed, evaluations: rows.length };
152
+ const withInput = options.input !== undefined;
106
153
  return {
107
154
  ok: findings.length === 0,
108
155
  command: 'policy',
109
- summary: msg('cli.policy.explained', {
110
- subject: explanation.subject,
111
- allowed,
112
- evaluations: rows.length,
113
- }),
114
- lines: explanation.declarations.flatMap(declarationLines),
156
+ // The command to run next is in the summary: a count of "not decided" with no way to decide
157
+ // it is the dead end the bare "allowed for 0 of 3" was.
158
+ summary:
159
+ pending === 0
160
+ ? msg('cli.policy.explained', counts)
161
+ : msg('cli.policy.explainedPending', {
162
+ ...counts,
163
+ pending,
164
+ command: `x policy explain ${quoteArg([name])} --input '<the request input as JSON>'`,
165
+ }),
166
+ lines: explanation.declarations.flatMap((declaration) =>
167
+ declarationLines(declaration, withInput),
168
+ ),
115
169
  findings,
116
170
  data: asJson({
117
171
  subject: explanation.subject,
118
172
  kind: explanation.kind,
119
173
  grantingRoles: explanation.grantingRoles,
174
+ pending,
120
175
  declarations: explanation.declarations.map((declaration) => asJson(declaration)),
121
176
  }),
122
177
  };
package/src/cmd-stop.ts CHANGED
@@ -7,7 +7,15 @@ import { parseDuration } from '@ultimat3/time';
7
7
  import { requireAppRoot } from './app-root';
8
8
  import { stopSpec } from './cmd-stop-spec';
9
9
  import type { CliCommand, CommandContext } from './command';
10
- import { clearLock, isProcessAlive, liveDevLock, lockPath, parseLock, reusedPid } from './dev-lock';
10
+ import {
11
+ clearLock,
12
+ clearStaleLock,
13
+ isProcessAlive,
14
+ liveDevLock,
15
+ lockPath,
16
+ parseLock,
17
+ reusedPid,
18
+ } from './dev-lock';
11
19
  import { BadFlagError } from './errors';
12
20
  import { MIN_RELEASE_MS } from './hold';
13
21
  import { msg } from './messages';
@@ -96,15 +104,21 @@ const lockNames = async (stateDir: string, pid: number): Promise<boolean> => {
96
104
  * Signal the lock's holder and wait for both facts the next boot reads: the pid gone and the lock
97
105
  * no longer naming it. A dead pid whose lock survived was terminated without a drain (Windows, or a
98
106
  * crash mid-drain), and its lock is cleared here so `x stop` returning means `x dev` boots.
99
- * No live holder is not a failure: a stale lock is left for `preflight`, which owns that clear.
107
+ * No live holder is not a failure: a lock naming a dead pid is left for `preflight`'s clear, and
108
+ * one naming a pid the kernel reused is cleared here, with nothing signalled.
100
109
  */
101
110
  export async function stopDev(input: StopInput): Promise<StopResult> {
102
111
  const alive = input.alive ?? isProcessAlive;
103
112
  const lock = liveDevLock(input.stateDir);
104
113
  if (lock === undefined || !alive(lock.pid)) return { stopped: false };
105
114
  // A pid alone is not the holder: a kill -9 leaves the lock and the kernel reuses the number.
106
- // Nothing is signalled and nothing cleared; the next `x dev`'s preflight clears it (`reusedPid`).
107
- if (await reusedPid(lock)) return { stopped: false, stale: true };
115
+ // Nothing is signalled. The lock is cleared, under `preflight`'s own guard and only while it
116
+ // still holds the bytes judged here (`stealStale`): `x stop` returning means nothing holds the
117
+ // directory, and a lock left behind kept answering "stale" until the next `x dev`.
118
+ if (await reusedPid(lock)) {
119
+ clearStaleLock(input.stateDir, lock);
120
+ return { stopped: false, stale: true };
121
+ }
108
122
  const windows = (input.platform ?? process.platform) === 'win32';
109
123
  const started = performance.now();
110
124
  signal(lock.pid, input.kill ?? ((pid: number) => process.kill(pid, 'SIGTERM')));
@@ -0,0 +1,87 @@
1
+ // `x tasks run <name>`: fire a scheduled task now — the jobs its occurrence enqueues, onto the
2
+ // app's queue — so a cron job is exercised in dev without waiting for its cron or editing it.
3
+ // Through the task's own manual-run path (`TaskHandle.enqueue`), the one the admin's run-now uses.
4
+
5
+ import { isProduction, UltimateError } from '@ultimat3/core';
6
+ import type { TaskHandle } from '@ultimat3/jobs';
7
+ import type { CommandContext } from './command';
8
+ import { refuseEmbeddedWriteBesideDev } from './dev-lock-live';
9
+ import { withJobDriver } from './jobs-driver';
10
+ import { msg } from './messages';
11
+ import type { CommandResult, Finding, JsonValue } from './output';
12
+ import { flagBool } from './parse';
13
+ import { quoteArg } from './shell-quote';
14
+
15
+ /** The container's half of the consent: the task this deploy fires, named, as a fixed argv can. */
16
+ export const TASK_RUN_ENV = 'ULTIMATE_TASK_RUN';
17
+
18
+ /**
19
+ * Does this environment fire only when asked by name? `x db seed`'s production gate, mirrored: the
20
+ * same predicate (`ULTIMATE_ENV` resolved `production`; staging runs unasked, as a `dev` seed does;
21
+ * an `ULTIMATE_ENV` that is no environment refuses with `X_ENVIRONMENT_INVALID`), and consent is
22
+ * named — `--production` on the command line, or `ULTIMATE_TASK_RUN=<name>` for a container whose
23
+ * command line is fixed, as `--tier` and `ULTIMATE_SEED_TIER` are. Pinned against `seedTiersFor`.
24
+ */
25
+ export const tasksRunNeedsFlag = (env: Readonly<Record<string, string | undefined>>): boolean =>
26
+ isProduction({ env });
27
+
28
+ /**
29
+ * `X_SEED_ENVIRONMENT`'s form: its own code, not `X_CLI_BAD_FLAG` — the argv was well formed and
30
+ * the answer is still no. The env var is in the cause, the one pasteable flag line is the fix.
31
+ */
32
+ export class TaskRunProductionError extends UltimateError {
33
+ constructor(name: string) {
34
+ super({
35
+ code: 'X_TASK_RUN_PRODUCTION',
36
+ cause: `ULTIMATE_ENV resolved production, where firing ${name} enqueues real work beside its next scheduled occurrence — x tasks run fires there only when asked by name; ${TASK_RUN_ENV}=${name} says this deploy takes it`,
37
+ fix: `x tasks run ${quoteArg(name)} --production --json`,
38
+ });
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Production fires only when asked. Not a scheduled occurrence: the scheduler's watermark is never
44
+ * moved, so the next real tick still fires — a manual run in production is real work twice.
45
+ */
46
+ function refuseUnaskedProduction(ctx: CommandContext, name: string): void {
47
+ if (flagBool(ctx.args, 'production') || ctx.env[TASK_RUN_ENV] === name) return;
48
+ if (!tasksRunNeedsFlag(ctx.env)) return;
49
+ throw new TaskRunProductionError(name);
50
+ }
51
+
52
+ /** One job a fire enqueued, as `TaskHandle.enqueue` answers it (`@ultimat3/jobs` exports no name). */
53
+ type Fired = Awaited<ReturnType<TaskHandle['enqueue']>>[number];
54
+
55
+ const asJson = (fired: Fired): JsonValue => ({
56
+ job: fired.job,
57
+ id: fired.result.id,
58
+ runId: fired.result.runId,
59
+ deduped: fired.result.deduped,
60
+ });
61
+
62
+ /**
63
+ * `handle` is already resolved (a typo is refused before any queue opens). Beside an `x dev`
64
+ * holding the embedded database this is a second writer, refused with the stop-run-restart fix.
65
+ */
66
+ export async function runTask(
67
+ root: string,
68
+ ctx: CommandContext,
69
+ handle: TaskHandle,
70
+ findings: readonly Finding[],
71
+ ): Promise<CommandResult> {
72
+ refuseUnaskedProduction(ctx, handle.name);
73
+ await refuseEmbeddedWriteBesideDev(root, ctx.env, ['tasks', 'run', handle.name]);
74
+ return withJobDriver(root, ctx, async () => {
75
+ const fired = await handle.enqueue();
76
+ return {
77
+ ok: findings.length === 0,
78
+ command: 'tasks',
79
+ summary: msg('cli.tasks.ran', { name: handle.name, count: fired.length }),
80
+ lines: fired.map(
81
+ (one) => ` ${one.job} ${one.result.id}${one.result.deduped ? ' (deduped)' : ''}`,
82
+ ),
83
+ findings,
84
+ data: { task: handle.name, jobs: fired.map(asJson) },
85
+ };
86
+ });
87
+ }
@@ -5,10 +5,10 @@ import type { CommandSpec } from './parse';
5
5
 
6
6
  export const tasksSpec: CommandSpec = {
7
7
  name: 'tasks',
8
- summary: 'cron tasks, their timezone and their next run',
9
- usage: 'x tasks [list|show <name>] [--count n] [--json]',
8
+ summary: 'cron tasks, their timezone and their next run; fire one now',
9
+ usage: 'x tasks [list|show <name>|run <name>] [--count n] [--production] [--json]',
10
10
  requiresApp: true,
11
- subcommands: ['list', 'show'],
11
+ subcommands: ['list', 'show', 'run'],
12
12
  defaultSubcommand: 'list',
13
13
  flags: [
14
14
  {
@@ -17,5 +17,12 @@ export const tasksSpec: CommandSpec = {
17
17
  summary: 'show: how many upcoming occurrences to list',
18
18
  subcommands: ['show'],
19
19
  },
20
+ {
21
+ name: 'production',
22
+ type: 'boolean',
23
+ summary:
24
+ 'run: fire it where ULTIMATE_ENV resolves production — real work, asked for by name; also ULTIMATE_TASK_RUN=<name>',
25
+ subcommands: ['run'],
26
+ },
20
27
  ],
21
28
  };
package/src/cmd-tasks.ts CHANGED
@@ -1,5 +1,6 @@
1
- // `x tasks [list|show <name>]` — introspect scheduled cron tasks: cadence, timezone, enqueued
2
- // jobs, last dispatch and real next occurrences. CLI wiring only (`tasks-facts.ts`).
1
+ // `x tasks [list|show <name>|run <name>]` — introspect scheduled cron tasks: cadence, timezone,
2
+ // enqueued jobs, last dispatch and real next occurrences; `run` fires one now (`cmd-tasks-run.ts`).
3
+ // CLI wiring only (`tasks-facts.ts`).
3
4
  //
4
5
  // The last dispatch is read off the queue's own record, and the next occurrences are real instants
5
6
  // from `@ultimat3/time`'s cron math instead of an agent reading `0 3 * * *` and guessing. The
@@ -12,6 +13,7 @@ import type { CronPhrases } from '@ultimat3/time';
12
13
  import { fromEpochMs, isoInZone } from '@ultimat3/time';
13
14
  import { loadApp } from './app-load';
14
15
  import { requireAppRoot } from './app-root';
16
+ import { runTask } from './cmd-tasks-run';
15
17
  import { tasksSpec } from './cmd-tasks-spec';
16
18
  import type { CliCommand, CommandContext } from './command';
17
19
  import { BadFlagError, DeclarationUnknownError } from './errors';
@@ -125,15 +127,15 @@ function runList(
125
127
  };
126
128
  }
127
129
 
128
- /** Resolves the `show <name>` positional to a handle, or throws — the two failure paths named
129
- * in the brief: no positional at all, and a positional that names no registered task. */
130
+ /** Resolves the `show|run <name>` positional to a handle, or throws — the two failure paths: no
131
+ * positional at all, and a positional that names no registered task. */
130
132
  function requireHandle(ctx: CommandContext): TaskHandle {
131
133
  const name = ctx.args.positionals[0];
132
134
  if (name === undefined) {
133
135
  throw new BadFlagError({
134
136
  flag: 'name',
135
137
  command: 'tasks',
136
- reason: 'x tasks show <name> needs a task name',
138
+ reason: `x tasks ${ctx.args.subcommand ?? 'show'} <name> needs a task name`,
137
139
  fix: 'x tasks list --json',
138
140
  });
139
141
  }
@@ -194,6 +196,7 @@ export const tasksCommand: CliCommand = {
194
196
  const root = requireAppRoot('tasks', ctx.cwd).dir;
195
197
  const { findings } = await loadApp(root);
196
198
  const nowMs = systemClock.now().getTime();
199
+ if (ctx.args.subcommand === 'run') return runTask(root, ctx, requireHandle(ctx), findings);
197
200
  // Everything argv can get wrong is refused BEFORE the queue is opened: a typo in a task name
198
201
  // must not cost a database boot to be told about.
199
202
  const shown =
package/src/cmd-test.ts CHANGED
@@ -16,9 +16,11 @@ import { appTestScope, narrowToApp } from './affected-tests';
16
16
  import { testSpec } from './cmd-test-spec';
17
17
  import type { CliCommand, CommandContext } from './command';
18
18
  import { ok } from './command';
19
- import { BadFlagError, NoTestFilesError } from './errors';
19
+ import { BadFlagError } from './errors';
20
+ import { NoTestFilesError } from './errors-suite';
20
21
  import type { Runner } from './exec';
21
22
  import { readIntFlag } from './flag-number';
23
+ import { FREE_RUN_FILES } from './heavy-weights';
22
24
  import { msg } from './messages';
23
25
  import type { CommandResult, JsonValue } from './output';
24
26
  import type { ParsedArgs } from './parse';
@@ -245,9 +247,18 @@ export const testCommand: CliCommand = {
245
247
  workers,
246
248
  ...(isolate ? { isolate } : {}),
247
249
  ...(seed === undefined ? {} : { seed }),
248
- // A default-width run leases its workers from the machine pool, so a second `x test` or
249
- // gate on the same box runs narrower instead of doubling its memory.
250
- ...(plan === undefined ? {} : withLease(machineLease(plan.workers, ctx.env))),
250
+ // Every run but a worker's own few files enters the machine ledger, so a second `x test` or
251
+ // gate on the same box narrows or queues instead of doubling its memory.
252
+ ...(files.length <= FREE_RUN_FILES
253
+ ? {}
254
+ : withLease(
255
+ machineLease(ctx.env, {
256
+ cwd: ctx.cwd,
257
+ label: type === undefined ? 'x test' : `x test ${type}`,
258
+ ...(type === undefined ? {} : { type }),
259
+ ...(plan === undefined ? { exact: true } : {}),
260
+ }),
261
+ )),
251
262
  ...(filter === undefined ? {} : { filter }),
252
263
  ...(type === undefined ? {} : { type }),
253
264
  // `kept` is the corpus the run saw. `selected`, not `discovered`: with `--affected` the sample was taken from the narrowed
@@ -11,7 +11,7 @@ export const upgradeSpec: CommandSpec = {
11
11
  summary:
12
12
  'move every @ultimat3/* one major in lockstep, raise the Bun floor, install, apply codemods, gate — and name the section to read',
13
13
  usage:
14
- 'x upgrade [--to <version>] [--dry-run] [--json] · x upgrade codemods --from <version> [--to <version>] [--dry-run] [--json]',
14
+ 'x upgrade [--to <version>] [--only <step>[,<step>…]] [--dry-run] [--json] · x upgrade codemods --from <version> [--to <version>] [--dry-run] [--json]',
15
15
  // The one command a repository with pins and no `app.config.ts` can still use: `upgrade-root.ts`
16
16
  // finds its root, and its report says which check it could run. `codemods` needs the app.
17
17
  subcommands: UPGRADE_SUBCOMMANDS,
@@ -30,6 +30,13 @@ export const upgradeSpec: CommandSpec = {
30
30
  summary:
31
31
  'the release the app came from: the codemods whose version lies after it, up to --to, run',
32
32
  },
33
+ {
34
+ name: 'only',
35
+ type: 'string',
36
+ subcommands: ['run'],
37
+ summary:
38
+ "the hop's x verify runs only the named step(s), comma-separated, as x verify --only does — NOT THE FULL GATE: data.verify.notRun names the rest, for CI to run (default: the full gate)",
39
+ },
33
40
  {
34
41
  name: 'dry-run',
35
42
  type: 'boolean',
@@ -11,6 +11,7 @@ import { runUpgradeCodemods } from './cmd-upgrade-codemods';
11
11
  import { upgradeSpec } from './cmd-upgrade-spec';
12
12
  import type { CliCommand, CommandContext } from './command';
13
13
  import { failed, ok } from './command';
14
+ import { staleTransitiveFloors } from './doctor-advisory-floors';
14
15
  import { supersededFindings } from './doctor-superseded';
15
16
  import { BadFlagError, BunVersionError } from './errors';
16
17
  import type { Runner } from './exec';
@@ -34,6 +35,8 @@ import { publishedVersions, releaseBunRange } from './upgrade-registry';
34
35
  import type { PlannedWrites } from './upgrade-report';
35
36
  import { humanLines, NO_WRITES, report, thenLine } from './upgrade-report';
36
37
  import { findUpgradeRoot } from './upgrade-root';
38
+ import type { GateScope } from './upgrade-scope';
39
+ import { readScope } from './upgrade-scope';
37
40
  import { stopChildrenOnSignal, tagRunner, upgradeTag } from './upgrade-signals';
38
41
  import type { UnfinishedHop } from './upgrade-unfinished';
39
42
  import { clearUnfinished, readUnfinished, writeUnfinished } from './upgrade-unfinished';
@@ -86,17 +89,29 @@ async function planWrites(input: {
86
89
  return { files, edited, manual };
87
90
  }
88
91
 
89
- /** `bun install`, or the refusal carrying the one command that undoes what was just written. */
90
- async function install(runner: Runner, root: string, to: string): Promise<void> {
91
- const result = await runner([process.execPath, 'install'], { cwd: root });
92
+ /** One `bun` step of the install, or the refusal carrying the command that undoes the pins. */
93
+ async function installStep(
94
+ runner: Runner,
95
+ root: string,
96
+ to: string,
97
+ args: readonly string[],
98
+ ): Promise<void> {
99
+ const result = await runner([process.execPath, ...args], { cwd: root });
92
100
  if (result.ok) return;
93
101
  throw new UltimateError({
94
102
  code: 'X_UPGRADE_INSTALL_FAILED',
95
- cause: `bun install exited ${String(result.code)} after pinning ${to}: ${execOutput(result).slice(-800) || 'no output'}`,
103
+ cause: `bun ${args.join(' ')} exited ${String(result.code)} after pinning ${to}: ${execOutput(result).slice(-800) || 'no output'}`,
96
104
  fix: 'git restore . # undoes the pins, since the tree was clean; then fix what the cause names and re-run: x upgrade --json',
97
105
  });
98
106
  }
99
107
 
108
+ /** `bun install` keeps what the lockfile resolves, so a patched transitive release is asked for. */
109
+ async function install(runner: Runner, root: string, to: string): Promise<void> {
110
+ await installStep(runner, root, to, ['install']);
111
+ const stale = await staleTransitiveFloors(root);
112
+ if (stale.length > 0) await installStep(runner, root, to, ['update', ...stale]);
113
+ }
114
+
100
115
  const stageLine = (stage: string): string => JSON.stringify({ upgrade: stage });
101
116
 
102
117
  /**
@@ -157,6 +172,7 @@ export const createUpgradeCommand = (
157
172
  root: string,
158
173
  app: boolean,
159
174
  to: string | undefined,
175
+ scope: GateScope | undefined,
160
176
  ): Promise<CommandResult> {
161
177
  const dryRun = flagBool(ctx.args, 'dry-run');
162
178
  const unfinished = await readUnfinished(root);
@@ -308,6 +324,7 @@ export const createUpgradeCommand = (
308
324
  onStage: stageReached,
309
325
  codemods: { from: resume === undefined ? hop.from : EVERY_RELEASE, to: hop.to },
310
326
  ...(bunMoved === undefined ? {} : { bunMoved }),
327
+ ...(scope === undefined ? {} : { only: scope }),
311
328
  });
312
329
  return { gate: hopGate, scripts: [] };
313
330
  });
@@ -326,6 +343,15 @@ export const createUpgradeCommand = (
326
343
  };
327
344
  const span = { from: hop.from, to: hop.to };
328
345
  if (gate !== undefined) {
346
+ const notRun = gate.verify.notRun ?? [];
347
+ if (done && notRun.length > 0) {
348
+ const scoped = {
349
+ ...span,
350
+ only: (gate.verify.only ?? []).join(','),
351
+ notRun: notRun.join(','),
352
+ };
353
+ return ok('upgrade', msg('cli.upgrade.doneScoped', scoped), extra);
354
+ }
329
355
  return done
330
356
  ? ok('upgrade', msg('cli.upgrade.done', span), extra)
331
357
  : failed(
@@ -350,6 +376,7 @@ export const createUpgradeCommand = (
350
376
  if (ctx.args.subcommand === 'codemods') return runUpgradeCodemods(ctx);
351
377
  const { dir: root, app } = await findUpgradeRoot(ctx.cwd);
352
378
  const to = readTarget(ctx);
379
+ const scope = readScope(ctx, app);
353
380
  // One hop per app at a time, and a stopped hop stops its children: every spawn below is
354
381
  // tagged, and SIGINT/SIGTERM kill that tree and release the lock before the signal lands.
355
382
  const release = await acquireUpgradeLock(root);
@@ -358,7 +385,7 @@ export const createUpgradeCommand = (
358
385
  const undoSignals = stopChildrenOnSignal({ tag, pids, cleanup: release });
359
386
  try {
360
387
  const runner = tagRunner(ctx.runner, tag, ctx.env, pids);
361
- return await runHop({ ...ctx, runner }, root, app, to);
388
+ return await runHop({ ...ctx, runner }, root, app, to, scope);
362
389
  } finally {
363
390
  undoSignals();
364
391
  release();