@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
@@ -38,14 +38,35 @@ export const DB_MESSAGES = {
38
38
  // The fourth: no DDL and no sidecar moved, but `packages/db/schema/` did — a hand edit repaired,
39
39
  // or a framework table that changed under an upgrade. `unchanged` would deny a write the lines
40
40
  // below it list, and this command is `X_SCHEMA_DUMP_DRIFT`'s whole `fix:`.
41
- 'cli.db.gen.dumped': 'no migration needed — schema dump rewritten ({count} file(s))',
41
+ // Names the migration, because in a shared checkout another agent's concurrent `x db gen` may be
42
+ // what recorded this run's table: the entities are one registry, so its migration carries them.
43
+ 'cli.db.gen.dumped':
44
+ 'no migration needed — {newest} already records every entity (a concurrent x db gen may have written it); schema dump rewritten ({count} file(s))',
45
+ // A sidecar moved and no migration exists: `written` would name one nobody can apply.
46
+ 'cli.db.gen.forkMerged':
47
+ 'forked migrations merged — {count} object(s) corrected in {id}.snapshot.json; no SQL changed, no migration deleted',
48
+ 'cli.db.gen.newest': ' newest migration: {id}',
42
49
  'cli.db.gen.written': 'migration {id} generated',
50
+ 'cli.db.gen.writtenTables': 'migration {id} generated — tables: {tables}',
51
+ // A diff that needs a step outside the transaction writes TWO: a line naming one hid the other.
52
+ 'cli.db.gen.writtenPair': 'migrations {id} and {followUp} generated',
53
+ 'cli.db.gen.writtenPairTables': 'migrations {id} and {followUp} generated — tables: {tables}',
54
+ 'cli.db.gen.editsUnchecked':
55
+ ' applied migrations were not compared with the ledger ({reason}) — x db status --json reports an edited one',
43
56
  // Exit 1 and a migration on disk at once: the summary carries the half the exit code hides.
44
57
  'cli.db.gen.writtenDumpFailed':
45
58
  'migration {id} generated and written — the schema dump was not; do not generate it again',
46
59
  'cli.db.migrate.applied': 'migrations applied',
47
60
  'cli.db.migrate.failed': 'migration failed',
48
61
  'cli.db.reset.done': 'database reset and migrated',
62
+ 'cli.db.rollback.done': 'rolled back {count} migration(s): {ids}',
63
+ 'cli.db.rollback.none': 'no applied migration to roll back',
64
+ 'cli.db.rollback.failed': 'rollback failed — nothing past the failing migration was reversed',
65
+ 'cli.db.rollback.deferredHalf':
66
+ ' {id} is the step x db gen writes beside {base} to run outside its transaction — {base} is still applied: x db rollback reverses it next',
67
+ // The file outlives its ledger row, so the migration is pending again: both next moves, named.
68
+ 'cli.db.rollback.kept':
69
+ ' each file is still on disk and pending — x db migrate re-applies it; to drop the change, delete the .sql with its .snapshot.json and .hash, then x db gen',
49
70
  // Every seed counted per outcome, exactly as the backfill summary is: a replayed seed writes
50
71
  // nothing and skips everything, and a total that hid that would make the second run look idle.
51
72
  'cli.db.seed.done':
@@ -0,0 +1,13 @@
1
+ // The `x doctor` processes rows of the CLI catalog (`messages.ts` composes them): how many processes
2
+ // a production container of each role runs here, and the connections one container holds. Data only.
3
+
4
+ export const PROCESSES_MESSAGES = {
5
+ 'cli.doctor.processes':
6
+ 'processes per container, as a production container here would run them — {cores} core(s) seen, CPU budget {budget}:',
7
+ 'cli.doctor.processesUndeclared': 'undeclared — auto runs 1 process',
8
+ 'cli.doctor.processesRole':
9
+ ' {role}: {count} process(es), bound by {binding} · pool {pool} + {listen} LISTEN = {connections} connection(s) per container',
10
+ 'cli.doctor.processesRefused': ' {role}: ULTIMATE_PROCESSES refused — {code}',
11
+ 'cli.doctor.processesConnections':
12
+ ' one container of each role holds {total} connection(s); the server allows max_connections {max} — multiply by your replicas',
13
+ } as const;
@@ -29,6 +29,12 @@ export const UPGRADE_MESSAGES = {
29
29
  'cli.upgrade.typescript':
30
30
  'typescript, by hand: {file} declares {from}, below the {to} the framework is checked with — run: {fix}',
31
31
  'cli.upgrade.done': '{from} -> {to}: the gate is green',
32
+ 'cli.upgrade.doneScoped':
33
+ '{from} -> {to}: green on {only} only — NOT THE FULL GATE; not run: {notRun}',
34
+ 'cli.upgrade.notRun':
35
+ 'not run by this hop, so not proven yet — CI, or this machine, owes: x verify --only {steps} --json',
36
+ 'cli.upgrade.then.scoped':
37
+ 'review the diff and commit this hop to {to}; it is done only once x verify --only {steps} --json (or a bare x verify) is green on it, in CI or here, then re-run x upgrade --json for the next one',
32
38
  'cli.upgrade.dryRun': '{from} -> {to}: nothing written, no gate run',
33
39
  'cli.upgrade.guard': 'guard, yours to take or leave: {fix}',
34
40
  'cli.upgrade.doctorWarning': 'doctor warning: {code}, red on the next major — fix: {fix}',
package/src/messages.ts CHANGED
@@ -8,6 +8,7 @@ import { DB_MESSAGES } from './messages-db';
8
8
  import { FLOOR_MESSAGES } from './messages-floor';
9
9
  import { GATE_MESSAGES } from './messages-gate';
10
10
  import { OPS_MESSAGES } from './messages-ops';
11
+ import { PROCESSES_MESSAGES } from './messages-processes';
11
12
  import { REPRO_MESSAGES } from './messages-repro';
12
13
  import { SHOT_MESSAGES } from './messages-shot';
13
14
  import { STATUS_MESSAGES } from './messages-status';
@@ -127,6 +128,7 @@ const CATALOG = {
127
128
  'cli.docs.installed': 'installed: {list}',
128
129
  'cli.docs.tryErrors': 'every X_* code, with its fix',
129
130
  'cli.docs.tryActions': "this app's own primitives, not the framework's",
131
+ 'cli.docs.tryTopic': 'any topic id above prints that section whole',
130
132
  'cli.docs.found': '{count} doc(s) for "{query}"',
131
133
  'cli.docs.none': 'no framework doc matches "{query}"',
132
134
  'cli.docs.unresolved': 'the installed framework packages could not be located',
@@ -241,12 +243,18 @@ const CATALOG = {
241
243
  'cli.policy.explained': '{subject} — allowed for {allowed} of {evaluations} actor evaluation(s)',
242
244
  'cli.policy.allow': 'allow',
243
245
  'cli.policy.deny': 'deny',
246
+ 'cli.policy.needsInput': 'needs input',
247
+ 'cli.policy.explainedPending':
248
+ '{subject} — allowed for {allowed} of {evaluations} actor evaluation(s); {pending} not denied, decided by a predicate that reads the request input — {command}',
249
+ 'cli.policy.withInput':
250
+ 'evaluated on --input, with no row — a row-level rule decides again on the real request',
251
+ 'cli.policy.undecidableInput':
252
+ 'not decidable on this --input — the policy threw reading it: a field the JSON does not carry, or a row rule',
244
253
  'cli.policy.declaration': '{kind} {name} — policy {label}',
245
254
  /** The empty cell in a `x policy list` column — a value, not a column key. */
246
255
  'cli.policy.none': '-',
247
256
  'cli.policy.noInput':
248
257
  'evaluated with no request input and no row — a rule reading either decides again on the real request',
249
- 'cli.policy.undecidable': 'not decidable outside a request — this policy reads request input',
250
258
  'cli.policy.unenforced': '{count} permission(s) no action or query enforces:',
251
259
  'cli.registry.count': '{count} {kind}',
252
260
  'cli.registry.described': '{kind} {name}',
@@ -256,6 +264,7 @@ const CATALOG = {
256
264
  'sealed {sealed} second-factor secret(s); {already} already sealed, {skipped} changed mid-run and left alone',
257
265
  'cli.tasks.count': '{count} task(s)',
258
266
  'cli.tasks.shown': '{name} — {cron} ({tz}), next {next}',
267
+ 'cli.tasks.ran': '{name} fired now — {count} job(s) enqueued; a worker (x dev) runs them',
259
268
  'cli.test.fail': '{failed} of {workers} shard(s) failed',
260
269
  'cli.test.affected.none': 'nothing is affected by {base}...HEAD — 0 test file(s) ran',
261
270
  'cli.test.empty': 'no test file matches {selection} — 0 test file(s) ran (--allow-empty)',
@@ -265,6 +274,8 @@ const CATALOG = {
265
274
  'cli.test.sampled': 'sampled {kept} of {total} {type} file(s)',
266
275
  'cli.test.type.fail': '{type} — {failed} of {workers} shard(s) failed',
267
276
  'cli.test.type.pass': '{type} — {files} test file(s) on {workers} worker(s) passed in {ms}ms',
277
+ 'cli.test.allSkipped':
278
+ '{label} — 0 test(s) ran: all {skipped} skipped themselves, so nothing was checked',
268
279
  'cli.clean.nothing': 'nothing to clean: no test leftovers under this app',
269
280
  'cli.clean.removed': 'removed {paths} path(s) and {databases} probe database(s)',
270
281
  'cli.clean.would':
@@ -272,6 +283,8 @@ const CATALOG = {
272
283
  'cli.env.checked': '{count} declared variable(s), all present and valid',
273
284
  'cli.env.invalid': '{count} of {total} declared variable(s) missing or malformed',
274
285
  'cli.env.checkedAsProduction': 'checked as production: no ULTIMATE_ENV named',
286
+ 'cli.env.checkedAsDevelopment':
287
+ 'checked as development, as x dev runs here: no ULTIMATE_ENV named — a deploy: ULTIMATE_ENV=production x env check',
275
288
  'cli.env.wrote': 'wrote {path} — {count} declared variable(s)',
276
289
  'cli.env.fresh': '{path} already matches the declaration',
277
290
  'cli.env.initialised': 'wrote {path} — {count} value(s), secrets generated and never printed',
@@ -315,8 +328,56 @@ const CATALOG = {
315
328
  ...UPGRADE_MESSAGES,
316
329
  ...GATE_MESSAGES,
317
330
  ...OPS_MESSAGES,
331
+ ...PROCESSES_MESSAGES,
318
332
  ...FLOOR_MESSAGES,
319
333
  ...STATUS_MESSAGES,
334
+ 'cli.heavy.waiting':
335
+ 'heavy: {label} waits for {need} MB, position {position} of {queued}; {used} of {capacity} MB held by {holders} — leave it running; it starts by itself (bunx x heavy status)',
336
+ 'cli.heavy.waitingAdmission':
337
+ 'heavy: {label} waits for {need} MB, position {position} of {queued}; admission in progress — leave it running; it starts by itself (bunx x heavy status)',
338
+ 'cli.heavy.waitingCpu':
339
+ 'heavy: {label} waits for CPU, position {position} of {queued}: {cpu}; running: {holders} — leave it running; it starts by itself (bunx x heavy status)',
340
+ 'cli.heavy.cpu.psi': 'CPU pressure {value}% (new runs wait at {limit}%)',
341
+ 'cli.heavy.cpu.runnable': '{value} runnable tasks per core (new runs wait at {limit})',
342
+ 'cli.heavy.status.cpu': 'cpu: {cpu} — a new heavy run waits while another is running',
343
+ 'cli.heavy.status.cpuOff': 'cpu: {cpu} — not gating here ({reason})',
344
+ 'cli.heavy.lockWait':
345
+ 'heavy: waiting for this checkout’s {name} lock, held by {holder} — leave it running; it starts by itself',
346
+ 'cli.heavy.status.summary':
347
+ '{used} of {capacity} MB reserved, {holds} running, {queued} queued; {cores} core(s) per run',
348
+ 'cli.heavy.status.off': 'admission is off here ({reason}); {cores} core(s) per run',
349
+ 'cli.heavy.status.machine':
350
+ 'machine: load {load} on {cpus} cores, {runnable} runnable, {free} GB of {total} GB available',
351
+ 'cli.heavy.status.hold': 'running: {entry}; {pids}',
352
+ 'cli.heavy.status.wrapper': 'wrapper pid {pid}',
353
+ 'cli.heavy.status.wrapperGone': 'wrapper pid {pid} exited',
354
+ 'cli.heavy.status.command': 'command pid {pids}',
355
+ 'cli.heavy.status.queued': 'queued {position}: {entry}',
356
+ 'cli.heavy.run.done': '{command} exited {code} after {ran}, {waited} in the queue',
357
+ // `test-workers.ts`: a step line for a run the machine held below its plan.
358
+ 'cli.test.narrowed': 'ran {peak} at once (peak), planned {planned}',
359
+ 'cli.test.narrowedWhy':
360
+ 'ran {peak} at once (peak), planned {planned} — the machine allowed no more (bunx x heavy status); plan: {reason}',
361
+ // `verify-live.ts`: which test stack the suites got, one line on stderr.
362
+ 'cli.verify.services.line.started':
363
+ 'services: started {project} ({services}) — bunx x clean --services stops it',
364
+ 'cli.verify.services.line.reused':
365
+ 'services: reused {project} — bunx x clean --services stops it',
366
+ 'cli.verify.services.line.shared':
367
+ 'services: shared {project} with {other} ({why}) — it stays up for that checkout too',
368
+ 'cli.verify.services.why.same-app': 'another checkout of this app',
369
+ 'cli.verify.services.why.declared': 'ULTIMATE_TEST_SERVICES_SHARED=1',
370
+ // `clean-services.ts`: what `x clean --services` did to the stack, and the ones it left alone.
371
+ 'cli.clean.services.stopped': 'stopped test stack {project} ({services})',
372
+ 'cli.clean.services.would-stop':
373
+ 'would stop test stack {project} ({services}) — --dry-run stopped nothing',
374
+ 'cli.clean.services.kept':
375
+ 'kept test stack {project}: {owner} started it and may be using it — stop it from there, or: docker compose -p {project} down --volumes',
376
+ 'cli.clean.services.none': 'no test stack is running for this app',
377
+ 'cli.clean.services.other':
378
+ 'other test stack {project} ({status}) from {root} — left alone; stop it with: docker compose -p {project} down --volumes',
379
+ 'cli.clean.services.otherGone':
380
+ 'other test stack {project} ({status}) from {root}, a checkout that no longer exists — left alone; stop it with: docker compose -p {project} down --volumes',
320
381
  } as const;
321
382
 
322
383
  export type MessageKey = keyof typeof CATALOG;
@@ -21,14 +21,32 @@ const commandWordAt = (fix: string, from: number): number => {
21
21
  const isBareX = (fix: string, at: number): boolean =>
22
22
  fix[at] === 'x' && (at + 1 === fix.length || fix[at + 1] === ' ');
23
23
 
24
+ /** What may stand before a quote that opens one: after a letter or a `"` it is an apostrophe. */
25
+ const BEFORE_QUOTE = /[\s([{=,:]/;
26
+ /** What may stand before a cited `x`: `apps/web/x.ts` and `max y` cite nothing. */
27
+ const BEFORE_CITATION = /[\s(`]/;
28
+ /** A runner already in front of this `x`. `then run x verify` has none: `run` alone is prose. */
29
+ const RUNNER_BEFORE = /(?:^|\s)(?:bunx|npx|bun|bun run|--bun)\s+$/;
30
+
31
+ const opensQuote = (fix: string, at: number): boolean =>
32
+ (fix[at] === "'" || fix[at] === '"') && (at === 0 || BEFORE_QUOTE.test(fix[at - 1] ?? ''));
33
+
34
+ /** `x <command>` anywhere in the line: a `then: x verify` tail is followed as literally as a head. */
35
+ const citesX = (fix: string, at: number): boolean =>
36
+ fix[at] === 'x' &&
37
+ fix[at + 1] === ' ' &&
38
+ /[a-z<]/.test(fix[at + 2] ?? '') &&
39
+ (at === 0 || BEFORE_CITATION.test(fix[at - 1] ?? '')) &&
40
+ !RUNNER_BEFORE.test(fix.slice(0, at));
41
+
24
42
  /**
25
- * A leading `x ` becomes `bunx x `, and after `&&`, `||` and `;`. Quoted text is an argument and a
26
- * `#` tail is never run, so both are copied as they are. `bunx x` itself does not match, so a report
27
- * read back by `x verify merge` and rendered again does not grow.
43
+ * Every `x` the line tells its reader to run becomes `bunx x`: the head of each `&&`, `||` and `;`
44
+ * segment, and a citation anywhere after it, a `#` or `//` tail included, because a reader follows
45
+ * `# then: x verify` too. A quoted span is an argument and is copied. `bunx x` itself does not
46
+ * match, so a report read back by `x verify merge` and rendered again does not grow.
28
47
  */
29
48
  export function runnableFix(fix: string): string {
30
49
  let out = '';
31
- let quote: string | undefined;
32
50
  let at = 0;
33
51
  let segmentStart = true;
34
52
  while (at < fix.length) {
@@ -36,27 +54,32 @@ export function runnableFix(fix: string): string {
36
54
  const word = commandWordAt(fix, at);
37
55
  out += fix.slice(at, word);
38
56
  at = word;
39
- if (isBareX(fix, at)) out += 'bunx ';
40
57
  segmentStart = false;
58
+ if (isBareX(fix, at)) {
59
+ out += 'bunx x';
60
+ at += 1;
61
+ }
41
62
  continue;
42
63
  }
43
- const char = fix[at] ?? '';
44
- if (quote !== undefined) {
45
- if (char === quote) quote = undefined;
46
- } else if (char === "'" || char === '"') {
47
- quote = char;
48
- } else if (char === '#' && (at === 0 || fix[at - 1] === ' ')) {
49
- return out + fix.slice(at);
50
- } else {
51
- const end = SEGMENT_END.exec(fix.slice(at));
52
- if (end !== null) {
53
- out += end[0];
54
- at += end[0].length;
55
- segmentStart = true;
56
- continue;
57
- }
64
+ const close = opensQuote(fix, at) ? fix.indexOf(fix[at] ?? '', at + 1) : -1;
65
+ if (close !== -1) {
66
+ out += fix.slice(at, close + 1);
67
+ at = close + 1;
68
+ continue;
58
69
  }
59
- out += char;
70
+ const end = SEGMENT_END.exec(fix.slice(at));
71
+ if (end !== null) {
72
+ out += end[0];
73
+ at += end[0].length;
74
+ segmentStart = true;
75
+ continue;
76
+ }
77
+ if (citesX(fix, at)) {
78
+ out += 'bunx x';
79
+ at += 1;
80
+ continue;
81
+ }
82
+ out += fix[at] ?? '';
60
83
  at += 1;
61
84
  }
62
85
  return out;
@@ -106,6 +129,10 @@ export interface ReaderOptions {
106
129
  readonly bunxRunner?: boolean;
107
130
  }
108
131
 
132
+ /** One fix line outside a finding: a pointer on stderr, or `x errors explain`'s answer. */
133
+ export const fixForReader = (fix: string, reader: ReaderOptions = {}): string =>
134
+ reader.bunxRunner === true ? runnableFix(fix) : fix;
135
+
109
136
  /** A finding read out of a CI log is fenced text and is never turned into an instruction. */
110
137
  const withRunnableFix = (finding: Finding): Finding => {
111
138
  if (finding.source === 'ci-log') return finding;
package/src/parse.ts CHANGED
@@ -122,11 +122,40 @@ export const wantsJson = (argv: readonly string[]): boolean =>
122
122
  const HELP_ALIASES = new Set(['--help', '-h', 'help']);
123
123
  const VERSION_ALIASES = new Set(['--version', '-v', '-V']);
124
124
 
125
+ // What an unknown top-level word most likely MEANT, ahead of what it merely resembles. Edit
126
+ // distance answered `x migrate` with `x upgrade` and `x start` with `x stop`: a `fix:` is pasted
127
+ // and run, so a guess that changes state is worse than no guess.
128
+ /**
129
+ * A word other toolchains use, as the `x` argv that does it. Each is held to the shipped parser by
130
+ * `parse.test.ts`, so an entry cannot outlive the command it names.
131
+ */
132
+ export const COMMAND_INTENTS: Readonly<Record<string, readonly string[]>> = Object.freeze({
133
+ migrate: ['db', 'migrate'],
134
+ seed: ['db', 'seed'],
135
+ start: ['dev'],
136
+ serve: ['dev'],
137
+ server: ['dev'],
138
+ lint: ['verify', '--only', 'lint'],
139
+ typecheck: ['verify', '--only', 'typecheck'],
140
+ tsc: ['verify', '--only', 'typecheck'],
141
+ check: ['verify'],
142
+ });
143
+
144
+ /** The suggestion for `word` (`'db migrate'`), when `commands` has the command it starts with. */
145
+ export function intentFor(word: string, commands: readonly string[]): string | undefined {
146
+ const argv = Object.hasOwn(COMMAND_INTENTS, word) ? COMMAND_INTENTS[word] : undefined;
147
+ const [command] = argv ?? [];
148
+ return argv !== undefined && command !== undefined && commands.includes(command)
149
+ ? argv.join(' ')
150
+ : undefined;
151
+ }
152
+
125
153
  function resolveCommand(token: string, specs: readonly CommandSpec[]): CommandSpec {
126
154
  const found = specs.find((spec) => spec.name === token || (spec.aliases ?? []).includes(token));
127
155
  if (found !== undefined) return found;
128
156
  const names = specs.map((spec) => spec.name);
129
- const suggestion = nearestName(token, names);
157
+ // What the word means before what it resembles: `migrate` is two edits from `upgrade`.
158
+ const suggestion = intentFor(token, names) ?? nearestName(token, names);
130
159
  throw new UnknownCommandError(
131
160
  suggestion === undefined
132
161
  ? { path: token, known: names }
@@ -351,11 +380,13 @@ function readSubcommand(spec: CommandSpec, positionals: readonly string[]): Reso
351
380
  if (spec.defaultSubcommandTakesPositional === true && suggestion === undefined) {
352
381
  return { name: spec.defaultSubcommand, consumed: false };
353
382
  }
354
- throw new UnknownCommandError(
355
- suggestion === undefined
356
- ? { path: `${spec.name} ${token}`, known: allowed }
357
- : { path: `${spec.name} ${token}`, known: allowed, suggestion: `${spec.name} ${suggestion}` },
358
- );
383
+ // Near nothing: the command's own page, which lists the subcommands it REGISTERS — the command
384
+ // was right, so the top-level `x help` sent the reader back through every other one.
385
+ throw new UnknownCommandError({
386
+ path: `${spec.name} ${token}`,
387
+ known: allowed,
388
+ suggestion: suggestion === undefined ? `help ${spec.name}` : `${spec.name} ${suggestion}`,
389
+ });
359
390
  }
360
391
 
361
392
  function blank(command: string, specs: readonly CommandSpec[], json: boolean): ParsedArgs {
@@ -4,11 +4,12 @@
4
4
 
5
5
  import type { AnyAction } from '@ultimat3/action';
6
6
  import { describeActions, getAction } from '@ultimat3/action';
7
- import type { MatrixRow, Policy } from '@ultimat3/policy';
7
+ import type { Policy } from '@ultimat3/policy';
8
8
  import { knownPermissions, policyMatrix, roleDefinitions, rolesGranting } from '@ultimat3/policy';
9
9
  import type { AnyQuery } from '@ultimat3/query';
10
10
  import { describeQueries, getQuery } from '@ultimat3/query';
11
11
  import { devActors } from './dev-policy';
12
+ import { decided, type ExplainRow, rowWithoutInput } from './policy-row';
12
13
 
13
14
  const isDefined = <T>(value: T | undefined): value is T => value !== undefined;
14
15
 
@@ -81,6 +82,12 @@ export function listPolicy(): PolicyListFacts {
81
82
  export type DeclarationKind = 'action' | 'query';
82
83
  export type SubjectKind = 'permission' | DeclarationKind;
83
84
 
85
+ /** What `x policy explain --input '<json>'` supplies: the request's input, parsed. */
86
+ export interface ExplainOptions {
87
+ /** Absent: no input was given, and a rule that reads one is `needs-input`. */
88
+ readonly input?: { readonly value: unknown } | undefined;
89
+ }
90
+
84
91
  export interface DeclarationExplanation {
85
92
  readonly name: string;
86
93
  readonly kind: DeclarationKind;
@@ -94,12 +101,13 @@ export interface DeclarationExplanation {
94
101
  readonly permissions: readonly string[];
95
102
  readonly label: string;
96
103
  /**
97
- * Whether this policy can be decided at all outside a request. `false` when evaluating it
98
- * with no request input threw — a predicate dereferencing `input.post.id` has nothing to
99
- * dereference here — and `rows` is then empty, because a partial matrix reads as a verdict.
104
+ * Whether this policy could be evaluated at all. `false` only when it threw on the input
105
+ * `--input` supplied — a row rule dereferencing a row there is none of, a field the JSON did not
106
+ * carry — and `rows` is then empty, because a partial matrix reads as a verdict. With no input
107
+ * given a throwing predicate is a `needs-input` row instead: the missing input is why it threw.
100
108
  */
101
109
  readonly decidable: boolean;
102
- readonly rows: readonly MatrixRow[];
110
+ readonly rows: readonly ExplainRow[];
103
111
  }
104
112
 
105
113
  export interface SubjectExplanation {
@@ -118,17 +126,21 @@ type DeclarationMatrix = Pick<DeclarationExplanation, 'decidable' | 'rows'>;
118
126
  * "every role plus anonymous" builder here is the duplicate axiom 1 bans, and it would drift
119
127
  * from the panel's own set the first time a role is renamed.
120
128
  *
121
- * Actor by actor inside a `try`, because there is no request input outside a request and
122
- * `policyMatrix` does not catch: a predicate reading `input.post.id` threw a bare `TypeError`
123
- * straight out of `x policy explain`. One throw makes the whole declaration undecidable rather
124
- * than half-reported — the rows a synthetic `{}` did produce are not the request's verdicts.
125
- * `policyMatrix` stays the only decider; nothing here re-derives one.
129
+ * With `--input` the policy is evaluated on it, actor by actor inside a `try`: `policyMatrix` does
130
+ * not catch, and a row rule dereferencing the row this command has none of threw a bare
131
+ * `TypeError` straight out of `x policy explain`. One throw makes the whole declaration
132
+ * undecidable rather than half-reported.
126
133
  */
127
- const matrixFor = (policy: Policy): DeclarationMatrix => {
128
- const rows: MatrixRow[] = [];
134
+ const matrixFor = (policy: Policy, options: ExplainOptions): DeclarationMatrix => {
135
+ const { input } = options;
136
+ if (input === undefined) {
137
+ return { decidable: true, rows: devActors().map((actor) => rowWithoutInput(policy, actor)) };
138
+ }
139
+ const rows: ExplainRow[] = [];
129
140
  for (const actor of devActors()) {
130
141
  try {
131
- rows.push(...policyMatrix(policy, { actors: [actor], input: {} }).rows);
142
+ const matrix = policyMatrix(policy, { actors: [actor], input: input.value });
143
+ rows.push(...matrix.rows.map(decided));
132
144
  } catch {
133
145
  return { decidable: false, rows: [] };
134
146
  }
@@ -136,7 +148,7 @@ const matrixFor = (policy: Policy): DeclarationMatrix => {
136
148
  return { decidable: true, rows };
137
149
  };
138
150
 
139
- const explainAction = (action: AnyAction): DeclarationExplanation => {
151
+ const explainAction = (action: AnyAction, options: ExplainOptions): DeclarationExplanation => {
140
152
  const descriptor = action.describe();
141
153
  return {
142
154
  name: descriptor.name,
@@ -144,11 +156,11 @@ const explainAction = (action: AnyAction): DeclarationExplanation => {
144
156
  capability: descriptor.capability,
145
157
  permissions: descriptor.permissions,
146
158
  label: action.policy.label,
147
- ...matrixFor(action.policy),
159
+ ...matrixFor(action.policy, options),
148
160
  };
149
161
  };
150
162
 
151
- const explainQuery = (query: AnyQuery): DeclarationExplanation => {
163
+ const explainQuery = (query: AnyQuery, options: ExplainOptions): DeclarationExplanation => {
152
164
  const descriptor = query.describe();
153
165
  return {
154
166
  name: descriptor.name,
@@ -156,7 +168,7 @@ const explainQuery = (query: AnyQuery): DeclarationExplanation => {
156
168
  capability: descriptor.capability,
157
169
  permissions: descriptor.permissions,
158
170
  label: query.policy.label,
159
- ...matrixFor(query.policy),
171
+ ...matrixFor(query.policy, options),
160
172
  };
161
173
  };
162
174
 
@@ -188,7 +200,10 @@ export function knownPolicySubjects(): readonly string[] {
188
200
  ];
189
201
  }
190
202
 
191
- export function explainPolicy(name: string): SubjectExplanation | undefined {
203
+ export function explainPolicy(
204
+ name: string,
205
+ options: ExplainOptions = {},
206
+ ): SubjectExplanation | undefined {
192
207
  const resolved = resolveSubject(name);
193
208
  if (resolved === undefined) return undefined;
194
209
  if (resolved.kind === 'permission') {
@@ -198,12 +213,12 @@ export function explainPolicy(name: string): SubjectExplanation | undefined {
198
213
  .filter((descriptor) => enforces(descriptor, permission))
199
214
  .map((descriptor) => getAction(descriptor.name))
200
215
  .filter(isDefined)
201
- .map(explainAction),
216
+ .map((action) => explainAction(action, options)),
202
217
  ...describeQueries()
203
218
  .filter((descriptor) => enforces(descriptor, permission))
204
219
  .map((descriptor) => getQuery(descriptor.name))
205
220
  .filter(isDefined)
206
- .map(explainQuery),
221
+ .map((query) => explainQuery(query, options)),
207
222
  ];
208
223
  return {
209
224
  subject: name,
@@ -213,7 +228,9 @@ export function explainPolicy(name: string): SubjectExplanation | undefined {
213
228
  };
214
229
  }
215
230
  const declaration =
216
- resolved.kind === 'action' ? explainAction(resolved.action) : explainQuery(resolved.query);
231
+ resolved.kind === 'action'
232
+ ? explainAction(resolved.action, options)
233
+ : explainQuery(resolved.query, options);
217
234
  return {
218
235
  subject: name,
219
236
  kind: resolved.kind,
@@ -0,0 +1,99 @@
1
+ // One actor's verdict on a policy, with or without the request's input: the row both `x policy
2
+ // explain` and the `/_x` policy panel draw. Without input, a predicate that READS input is
3
+ // `needs-input` — never the deny a stand-in `{}` produced. `policyMatrix` stays the only decider.
4
+
5
+ import type { MatrixRow, NamedActor, Policy } from '@ultimat3/policy';
6
+ import { decideBeforeInput, policyMatrix, reasonOf } from '@ultimat3/policy';
7
+
8
+ /**
9
+ * `needs-input` is NOT a denial: the actor passes every clause that reads only the actor, and a
10
+ * predicate then read the request's input — which this command was not given. Reported as a deny
11
+ * it sent the reader to edit a correct policy: every input-scoped rule (all that `x g resource`
12
+ * writes) read "predicate returned false" about the admin who had just succeeded over HTTP.
13
+ */
14
+ export type ExplainVerdict = 'allow' | 'deny' | 'needs-input';
15
+
16
+ /** A `MatrixRow` that can also say "not decided". `allowed` is `null` exactly when it was not. */
17
+ export interface ExplainRow extends Omit<MatrixRow, 'allowed'> {
18
+ readonly verdict: ExplainVerdict;
19
+ readonly allowed: boolean | null;
20
+ }
21
+
22
+ export const decided = (row: MatrixRow): ExplainRow => ({
23
+ ...row,
24
+ verdict: row.allowed ? 'allow' : 'deny',
25
+ });
26
+
27
+ /**
28
+ * A stand-in for the input nobody supplied, which records being READ. Every trap a predicate can
29
+ * reach it through answers "nothing there" — what `{}` answered — and sets the flag, so a verdict
30
+ * that came out of reading it is known to be a verdict about no request at all. `[]` as the
31
+ * target is the array-shaped one: `Array.isArray` sees through a proxy to its target.
32
+ */
33
+ function absentInput(target: object = {}): { readonly value: object; read(): boolean } {
34
+ let touched = false;
35
+ const touch = <T>(answer: T): T => {
36
+ touched = true;
37
+ return answer;
38
+ };
39
+ const value = new Proxy(target, {
40
+ get: () => touch(undefined),
41
+ has: () => touch(false),
42
+ ownKeys: () => touch([]),
43
+ getOwnPropertyDescriptor: () => touch(undefined),
44
+ });
45
+ return { value, read: () => touched };
46
+ }
47
+
48
+ /** The row over one stand-in, or `undefined` when a predicate threw on it. */
49
+ function rowOver(policy: Policy, entry: NamedActor, input: unknown): MatrixRow | undefined {
50
+ try {
51
+ return policyMatrix(policy, { actors: [entry], input }).rows[0];
52
+ } catch {
53
+ return undefined;
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Did the verdict depend on the input? Read through a trap, or — for a whole-value check
59
+ * (`Array.isArray(input)`, `input === null`, `typeof input`) that reaches no trap — moved when the
60
+ * stand-in's shape did. A predicate over the actor alone answers the same for every one of them.
61
+ */
62
+ function inputDecided(policy: Policy, entry: NamedActor, row: MatrixRow | undefined): boolean {
63
+ const array = absentInput([]);
64
+ const others = [array.value, null, ''].map((input) => rowOver(policy, entry, input));
65
+ return (
66
+ array.read() ||
67
+ // A throw is `undefined`, so throwing on one stand-in and not another is a move too.
68
+ others.some((other) => other?.allowed !== row?.allowed)
69
+ );
70
+ }
71
+
72
+ /**
73
+ * One actor with no input to hand the policy. The before-input gate (`decideBeforeInput`, the one
74
+ * the HTTP surface runs before it parses a body) says whether a predicate has to run for this
75
+ * actor at all; when one does, the full evaluation runs over `absentInput()`, and a predicate
76
+ * that read it, threw reading it, or answered otherwise for another stand-in is `needs-input`,
77
+ * never a deny. A predicate that reads only the actor decides as it would on a request.
78
+ * `policyMatrix` stays the only decider.
79
+ */
80
+ export function rowWithoutInput(policy: Policy, entry: NamedActor): ExplainRow {
81
+ const input = absentInput();
82
+ const row = rowOver(policy, entry, input.value);
83
+ const before = decideBeforeInput(policy, { actor: entry.actor });
84
+ const dependent = before === undefined && (input.read() || inputDecided(policy, entry, row));
85
+ if (row !== undefined && !dependent) return decided(row);
86
+ // Decided whatever the input is, and a predicate past the deciding clause threw on the stand-in.
87
+ if (before !== undefined) {
88
+ const { allowed } = before;
89
+ return decided({ actor: entry.name, allowed, reason: reasonOf(before), deciding: null });
90
+ }
91
+ const clause = row?.deciding ?? policy.label;
92
+ return {
93
+ actor: entry.name,
94
+ verdict: 'needs-input',
95
+ allowed: null,
96
+ deciding: row?.deciding ?? null,
97
+ reason: `not denied — every actor-only clause passes, and ${clause} has a predicate that reads the request input`,
98
+ };
99
+ }
@@ -0,0 +1,28 @@
1
+ // The port a "port in use" fix names. On a machine running several dev servers the next pair is
2
+ // often taken as well, and a fix that fails the same way is not a fix. Not `@ultimat3/testing`'s
3
+ // `freePortPair`, which binds; this one only asks.
4
+
5
+ import { PORT_RANGE, portPairAfter } from './flag-number';
6
+
7
+ /** How far to look: past this the machine is unusual and the plain suggestion is as good. */
8
+ const PAIRS_TRIED = 64;
9
+
10
+ /**
11
+ * The first pair after `port` with both ports free, walking the way `portPairAfter` points (down at
12
+ * the top of the range). `x dev --port N` binds N and N + 1, so both are asked. The answer is true
13
+ * when asked: another process can still take it.
14
+ */
15
+ export async function freeDevPortPair(
16
+ port: number,
17
+ isFree: (port: number) => boolean | Promise<boolean>,
18
+ ): Promise<number> {
19
+ const first = portPairAfter(port);
20
+ const step = first > port ? 2 : -2;
21
+ let candidate = first;
22
+ for (let tried = 0; tried < PAIRS_TRIED; tried += 1) {
23
+ if (candidate < 1 || candidate + 1 >= PORT_RANGE.max) break;
24
+ if ((await isFree(candidate)) && (await isFree(candidate + 1))) return candidate;
25
+ candidate += step;
26
+ }
27
+ return first;
28
+ }