@ultimat3/cli 31.48.0 → 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 (260) 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 +80 -18
  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 +9 -1
  28. package/src/cmd-heavy.ts +111 -27
  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 +2 -1
  40. package/src/cmd-upgrade-spec.ts +8 -1
  41. package/src/cmd-upgrade.ts +15 -1
  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 +11 -15
  46. package/src/codemods/docs-worker-commands.ts +26 -0
  47. package/src/codemods/index.ts +4 -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-api-listing.ts +114 -0
  77. package/src/doctor-guarded.ts +41 -0
  78. package/src/doctor-port.ts +90 -17
  79. package/src/doctor-probe.ts +36 -5
  80. package/src/doctor-processes-probe.ts +127 -0
  81. package/src/doctor-processes.ts +136 -0
  82. package/src/doctor-warnings.ts +17 -0
  83. package/src/error-codes-agents.ts +35 -0
  84. package/src/error-codes-processes.ts +30 -0
  85. package/src/error-codes-tooling.ts +2 -0
  86. package/src/error-codes.ts +12 -13
  87. package/src/errors-suite.ts +27 -0
  88. package/src/errors.ts +18 -22
  89. package/src/exercise-registration.ts +4 -3
  90. package/src/framework-env.ts +7 -3
  91. package/src/generate-files.ts +1 -0
  92. package/src/generate-grant-findings.ts +7 -5
  93. package/src/generate-grants.ts +9 -8
  94. package/src/generate-kinds.ts +30 -6
  95. package/src/generate-roles-file.ts +30 -0
  96. package/src/generate-slice-policy.ts +3 -3
  97. package/src/guards.ts +2 -2
  98. package/src/heavy-env.ts +2 -0
  99. package/src/heavy-errors.ts +18 -0
  100. package/src/heavy-holders.ts +78 -0
  101. package/src/heavy-ledger.ts +56 -14
  102. package/src/heavy-pressure.ts +104 -0
  103. package/src/heavy.ts +31 -13
  104. package/src/i18n-registration.ts +22 -2
  105. package/src/island-harness.ts +2 -2
  106. package/src/job-budget.ts +4 -2
  107. package/src/job-registration.ts +64 -8
  108. package/src/jobs-queue-known.ts +43 -0
  109. package/src/mcp-errors-agents.ts +20 -0
  110. package/src/mcp-errors-doctor.ts +27 -0
  111. package/src/mcp-errors-processes.ts +23 -0
  112. package/src/mcp-errors.ts +15 -29
  113. package/src/mcp-host.ts +2 -2
  114. package/src/merge-driver-catalog.ts +58 -0
  115. package/src/merge-driver-config.ts +43 -0
  116. package/src/merge-driver-lines.ts +140 -0
  117. package/src/merge-state.ts +105 -0
  118. package/src/messages-db.ts +22 -1
  119. package/src/messages-processes.ts +13 -0
  120. package/src/messages-upgrade.ts +6 -0
  121. package/src/messages.ts +54 -4
  122. package/src/output-findings.ts +48 -21
  123. package/src/parse.ts +37 -6
  124. package/src/policy-facts.ts +38 -21
  125. package/src/policy-row.ts +99 -0
  126. package/src/port-pair-free.ts +28 -0
  127. package/src/registry-lines.ts +110 -0
  128. package/src/registry.ts +2 -0
  129. package/src/retain-sweep.ts +1 -1
  130. package/src/role-replicator.ts +4 -1
  131. package/src/role-select.ts +86 -0
  132. package/src/role-start.ts +13 -55
  133. package/src/role-sync.ts +10 -5
  134. package/src/runtime-cache-frame.ts +46 -0
  135. package/src/runtime-cache-ttl.ts +23 -0
  136. package/src/runtime-cache.ts +33 -16
  137. package/src/runtime-database-ssl.ts +84 -0
  138. package/src/runtime-idempotency-scope.ts +16 -2
  139. package/src/runtime-jobs-share.ts +52 -0
  140. package/src/runtime-jobs.ts +43 -12
  141. package/src/runtime-queue.ts +18 -3
  142. package/src/runtime-services.ts +8 -1
  143. package/src/schema-drift.ts +19 -2
  144. package/src/schema-dump-drift.ts +4 -1
  145. package/src/serve-boot-probe.ts +30 -2
  146. package/src/serve-boot.ts +11 -1
  147. package/src/serve-env.ts +39 -3
  148. package/src/serve.ts +61 -10
  149. package/src/stop-run-start.ts +12 -0
  150. package/src/supervise-boot.ts +61 -0
  151. package/src/supervise-cgroup.ts +84 -0
  152. package/src/supervise-child.ts +206 -0
  153. package/src/supervise-count.ts +244 -0
  154. package/src/supervise-errors.ts +83 -0
  155. package/src/supervise-facts.ts +40 -0
  156. package/src/supervise-messages.ts +84 -0
  157. package/src/supervise-policy.ts +46 -0
  158. package/src/supervise-pool.ts +10 -0
  159. package/src/supervise-probe.ts +158 -0
  160. package/src/supervise-run.ts +54 -0
  161. package/src/supervise.ts +383 -0
  162. package/src/templates/generate-purge.ts +6 -6
  163. package/src/templates/guard-animated-layout-property.ts +2 -2
  164. package/src/templates/guard-bare-error.ts +1 -1
  165. package/src/templates/guard-error-declared.ts +2 -2
  166. package/src/templates/guard-focus-visible.ts +1 -1
  167. package/src/templates/guard-image-dimensions.ts +2 -2
  168. package/src/templates/guard-island-mount-clears.ts +1 -1
  169. package/src/templates/guard-native-confirm.ts +1 -1
  170. package/src/templates/guard-raw-breakpoint.ts +2 -2
  171. package/src/templates/guard-raw-colour.ts +2 -2
  172. package/src/templates/guard-raw-fetch.ts +1 -1
  173. package/src/templates/guard-raw-interval.ts +1 -1
  174. package/src/templates/guard-raw-length.ts +3 -3
  175. package/src/templates/guard-raw-motion.ts +1 -1
  176. package/src/templates/guard-raw-shadow.ts +1 -1
  177. package/src/templates/guard-raw-z-index.ts +1 -1
  178. package/src/templates/guard-released-forms.ts +54 -8
  179. package/src/templates/guard-repo-await-in-loop.ts +1 -1
  180. package/src/templates/guard-repo-raw-sql.ts +4 -4
  181. package/src/templates/guard-repo-unbounded.ts +1 -1
  182. package/src/templates/guard-runtime-pin.ts +1 -1
  183. package/src/templates/guard-semantic-interactive.ts +2 -2
  184. package/src/templates/guard-unbounded-fanout.ts +1 -1
  185. package/src/templates/guard-undeclared-custom-property.ts +3 -3
  186. package/src/templates/guard-undefined-style-class.ts +3 -3
  187. package/src/templates/guard-unzoned-date.ts +3 -3
  188. package/src/templates/query-slice.ts +82 -0
  189. package/src/templates/query.ts +76 -30
  190. package/src/templates/resource-page.ts +3 -2
  191. package/src/templates/scaffold-bin.ts +2 -0
  192. package/src/templates/scaffold-claude-commands.ts +6 -0
  193. package/src/templates/scaffold-claude.ts +4 -4
  194. package/src/templates/scaffold-container-compose.ts +47 -7
  195. package/src/templates/scaffold-docs.ts +7 -3
  196. package/src/templates/scaffold-gitattributes.ts +18 -1
  197. package/src/templates/scaffold-helm-templates.ts +9 -0
  198. package/src/templates/scaffold-repo.ts +4 -1
  199. package/src/templates/scaffold-test-services.ts +33 -11
  200. package/src/templates/shapes/offline.ts +0 -7
  201. package/src/templates/shapes/realtime.ts +2 -6
  202. package/src/templates/sign-in-action-tests.ts +6 -4
  203. package/src/templates/sign-in-challenge.ts +62 -0
  204. package/src/templates/sign-in-oidc-mfa.ts +31 -0
  205. package/src/templates/sign-in-oidc.ts +11 -3
  206. package/src/templates/sign-in-password.ts +18 -56
  207. package/src/test-shards.ts +114 -34
  208. package/src/test-verdict.ts +79 -0
  209. package/src/test-workers.ts +15 -0
  210. package/src/upgrade-gate-codemods.ts +5 -3
  211. package/src/upgrade-gate.ts +19 -1
  212. package/src/upgrade-merge-drivers.ts +25 -0
  213. package/src/upgrade-report.ts +18 -4
  214. package/src/upgrade-scope.ts +62 -0
  215. package/src/verify-checks.ts +2 -8
  216. package/src/verify-coverage-run.ts +4 -1
  217. package/src/verify-live.ts +38 -14
  218. package/src/verify-only.ts +67 -0
  219. package/src/verify-progress.ts +7 -3
  220. package/src/verify-run.ts +20 -2
  221. package/src/verify-services-stack.ts +165 -0
  222. package/src/verify-services.ts +84 -2
  223. package/src/verify-test-run.ts +6 -7
  224. package/src/verify-tests.ts +8 -2
  225. package/src/verify-typecheck.ts +25 -2
  226. package/wiki/Actions.md +2 -1
  227. package/wiki/Admin-Dashboard.md +2 -2
  228. package/wiki/Agents.md +5 -5
  229. package/wiki/Auth.md +15 -5
  230. package/wiki/Bare-VM.md +1 -1
  231. package/wiki/CI-Parallel-Gate.md +2 -1
  232. package/wiki/CLI-Reference.md +107 -40
  233. package/wiki/Caching-And-Invalidation.md +1 -1
  234. package/wiki/Client-Navigation.md +1 -1
  235. package/wiki/Configuration.md +10 -9
  236. package/wiki/Deployment.md +44 -4
  237. package/wiki/Entities-And-Migrations.md +5 -1
  238. package/wiki/FAQ.md +1 -1
  239. package/wiki/Getting-Started.md +2 -2
  240. package/wiki/Home.md +1 -1
  241. package/wiki/I18n.md +5 -3
  242. package/wiki/Installation.md +12 -11
  243. package/wiki/Jobs-And-Workflows.md +24 -4
  244. package/wiki/Known-Gaps.md +1 -1
  245. package/wiki/MCP-And-AI.md +8 -5
  246. package/wiki/Many-Agents.md +69 -2
  247. package/wiki/Migrations-And-Backfills.md +18 -0
  248. package/wiki/Notify.md +1 -1
  249. package/wiki/Observability.md +13 -0
  250. package/wiki/Queries-And-Live-Queries.md +2 -2
  251. package/wiki/Realtime.md +10 -1
  252. package/wiki/Routes-And-Render-Modes.md +1 -1
  253. package/wiki/Scheduled-Tasks.md +4 -1
  254. package/wiki/Testing.md +7 -4
  255. package/wiki/Timezones-And-Dates.md +5 -1
  256. package/wiki/Troubleshooting.md +1 -0
  257. package/wiki/Tutorial-01-First-App.md +3 -3
  258. package/wiki/Tutorial-02-First-Feature.md +1 -1
  259. package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
  260. package/wiki/Upgrading.md +37 -0
@@ -0,0 +1,58 @@
1
+ // The catalog half of `x merge-driver`: a three-way merge of the JSON, key by key. Lines cannot do
2
+ // it — the entry before an addition gains a comma on both sides. Two values for one key stay a
3
+ // conflict: which wording ships is a decision, and this file does not make decisions.
4
+
5
+ import { isJsonObject } from '@ultimat3/core';
6
+ import type { JsonObject } from './json-merge';
7
+ import { sortJsonDeep } from './json-merge';
8
+
9
+ const CONFLICT = Symbol('conflict');
10
+ const ABSENT = Symbol('absent');
11
+
12
+ const same = (a: unknown, b: unknown): boolean => Bun.deepEquals(a, b, true);
13
+
14
+ function mergeValue(base: unknown, ours: unknown, theirs: unknown): unknown {
15
+ if (same(ours, theirs) || same(theirs, base)) return ours;
16
+ if (same(ours, base)) return theirs;
17
+ if (!isJsonObject(ours) || !isJsonObject(theirs)) return CONFLICT;
18
+ return mergeObject(isJsonObject(base) ? base : {}, ours, theirs);
19
+ }
20
+
21
+ function mergeObject(base: JsonObject, ours: JsonObject, theirs: JsonObject): unknown {
22
+ const merged: [string, unknown][] = [];
23
+ for (const key of new Set([...Object.keys(ours), ...Object.keys(theirs)])) {
24
+ const read = (side: JsonObject): unknown => (Object.hasOwn(side, key) ? side[key] : ABSENT);
25
+ const value = mergeValue(read(base), read(ours), read(theirs));
26
+ if (value === CONFLICT) return CONFLICT;
27
+ if (value !== ABSENT) merged.push([key, value]);
28
+ }
29
+ return Object.fromEntries(merged);
30
+ }
31
+
32
+ const parsed = (text: string): JsonObject | undefined => {
33
+ try {
34
+ const value: unknown = JSON.parse(text.trim() === '' ? '{}' : text);
35
+ return isJsonObject(value) ? value : undefined;
36
+ } catch {
37
+ // Not JSON is an answer here: the caller falls back to a text merge, with markers.
38
+ return undefined;
39
+ }
40
+ };
41
+
42
+ const isSortedDeep = (value: unknown): boolean =>
43
+ JSON.stringify(value) === JSON.stringify(sortJsonDeep(value));
44
+
45
+ /**
46
+ * The merged catalog as `x g` prints one, or `undefined` when a side is not JSON or two sides
47
+ * disagree on a key. Sorted where both sides were, which is every catalog a generator wrote, so
48
+ * the merge order leaves no trace; a hand-grouped catalog keeps its order, the other side's new
49
+ * keys after it.
50
+ */
51
+ export function mergeCatalogText(base: string, ours: string, theirs: string): string | undefined {
52
+ const [b, o, t] = [parsed(base), parsed(ours), parsed(theirs)];
53
+ if (b === undefined || o === undefined || t === undefined) return undefined;
54
+ const merged = mergeObject(b, o, t);
55
+ if (merged === CONFLICT) return undefined;
56
+ const value = isSortedDeep(o) && isSortedDeep(t) ? sortJsonDeep(merged) : merged;
57
+ return `${JSON.stringify(value, null, 2)}\n`;
58
+ }
@@ -0,0 +1,43 @@
1
+ // The two git merge drivers `.gitattributes` names, and whether this clone has them. Git keeps a
2
+ // driver's command in `.git/config`, which no clone inherits, so `x merge-driver install` (a step
3
+ // of `bun run setup`) writes it; an attribute naming an unknown driver is an ordinary text merge.
4
+
5
+ import type { Runner } from './exec';
6
+ import { quoteArg } from './shell-quote';
7
+
8
+ export const GENERATED_DRIVER = 'x-generated';
9
+ export const REGISTRY_DRIVER = 'x-registry';
10
+
11
+ /**
12
+ * Through the installed binary, never `bunx x`: a clone with no install would fetch an unrelated
13
+ * npm package named `x` and run it on the merge. With none, this is git's own text merge.
14
+ */
15
+ export const registryDriverCommand = (prefix: string): string => {
16
+ const bin = quoteArg(`${prefix}node_modules/.bin/x`);
17
+ return `if [ -x ${bin} ]; then ${bin} merge-driver run %O %A %B %P; else git merge-file -L ours -L base -L theirs %A %O %B; fi`;
18
+ };
19
+
20
+ /** Every `git config` key and value, in the order they are written. */
21
+ export const driverConfig = (prefix: string): readonly (readonly [string, string])[] => [
22
+ [`merge.${GENERATED_DRIVER}.name`, 'keep ours: x manifest rebuilds this file'],
23
+ // `true` exits 0 and leaves our side in place: the file is a projection, rebuilt after the merge.
24
+ [`merge.${GENERATED_DRIVER}.driver`, 'true'],
25
+ [`merge.${REGISTRY_DRIVER}.name`, 'keep what both sides added to an x registry'],
26
+ [`merge.${REGISTRY_DRIVER}.driver`, registryDriverCommand(prefix)],
27
+ ];
28
+
29
+ /** `undefined` outside a git checkout. */
30
+ export async function gitPrefix(root: string, runner: Runner): Promise<string | undefined> {
31
+ const found = await runner(['git', 'rev-parse', '--show-prefix'], { cwd: root });
32
+ return found.ok ? found.stdout.trim() : undefined;
33
+ }
34
+
35
+ /** Whether `.gitattributes` names the driver and this clone does not define it. */
36
+ export async function driverUnset(root: string, runner: Runner): Promise<boolean> {
37
+ const attributes = Bun.file(`${root}/.gitattributes`);
38
+ if (!(await attributes.exists())) return false;
39
+ if (!(await attributes.text()).includes(`merge=${REGISTRY_DRIVER}`)) return false;
40
+ if ((await gitPrefix(root, runner)) === undefined) return false;
41
+ const key = `merge.${REGISTRY_DRIVER}.driver`;
42
+ return !(await runner(['git', 'config', '--get', key], { cwd: root })).ok;
43
+ }
@@ -0,0 +1,140 @@
1
+ // The registry half of `x merge-driver`: conflicts that are only "both sides ADDED here" keep both.
2
+ // Not `merge=union`, which also keeps a line one side deleted (a revoked grant in `roles.ts` comes
3
+ // back) and splices multi-line entries together. A conflict touching an existing line stays one.
4
+
5
+ import { maskOf } from './source-list-edit';
6
+
7
+ export const OURS_MARKER = '<<<<<<< ours';
8
+ const BASE_MARKER = '||||||| base';
9
+ const SPLIT_MARKER = '=======';
10
+ const THEIRS_MARKER = '>>>>>>> theirs';
11
+
12
+ export interface LineMerge {
13
+ readonly text: string;
14
+ /** The conflicts left in `text`, each still between its markers. */
15
+ readonly conflicts: number;
16
+ }
17
+
18
+ const indentOf = (line: string): number => /^[ \t]*/.exec(line)?.[0].length ?? 0;
19
+
20
+ const depthOf = (masked: string): number => {
21
+ let depth = 0;
22
+ for (const ch of masked) {
23
+ if ('([{'.includes(ch)) depth += 1;
24
+ else if (')]}'.includes(ch)) depth -= 1;
25
+ }
26
+ return depth;
27
+ };
28
+
29
+ /** Brackets balanced and the last code a `,` or `;`: nothing a neighbour could be spliced into. */
30
+ const isWhole = (lines: readonly string[]): boolean => {
31
+ const masked = maskOf(lines.join('\n')).trimEnd();
32
+ return depthOf(masked) === 0 && /[,;]$/.test(masked);
33
+ };
34
+
35
+ /**
36
+ * The added lines as whole entries — an entry starts at the block's own indent and runs until it
37
+ * is complete, so `foo: {`…`},` is one and a comment joins what it precedes. `undefined` when they
38
+ * do not divide that way: such a hunk is not a list of additions.
39
+ */
40
+ function entriesOf(lines: readonly string[]): readonly string[] | undefined {
41
+ if (lines.some((line) => line.trim() === '')) return undefined;
42
+ const indent = Math.min(...lines.map(indentOf));
43
+ const entries: string[][] = [];
44
+ for (const line of lines) {
45
+ const last = entries.at(-1);
46
+ if (last === undefined || (indentOf(line) === indent && isWhole(last))) entries.push([line]);
47
+ else last.push(line);
48
+ }
49
+ return entries.every(isWhole) ? entries.map((entry) => entry.join('\n')) : undefined;
50
+ }
51
+
52
+ const SPECIFIER = /\bfrom\s+'([^']+)';\s*$/;
53
+
54
+ /** What may appear once: an import's binding or module, an object entry's key. */
55
+ function identityOf(entry: string): string | undefined {
56
+ const code = entry.trimStart();
57
+ if (code.startsWith('import ')) {
58
+ const namespace = /^import \* as ([\w$]+)/.exec(code)?.[1];
59
+ return namespace === undefined ? `from:${SPECIFIER.exec(code)?.[1]}` : `as:${namespace}`;
60
+ }
61
+ const key = /^(?:([\w$]+)|'([^']+)'|"([^"]+)")\s*:/.exec(code);
62
+ return key === null ? undefined : `key:${key[1] ?? key[2] ?? key[3]}`;
63
+ }
64
+
65
+ const sortKeyOf = (entry: string): string => SPECIFIER.exec(entry)?.[1] ?? entry.trimStart();
66
+
67
+ /**
68
+ * Both sides' entries, each once, in one order. Sorted so that merging A into B and B into A write
69
+ * the same bytes, and so an import block stays in the order Biome requires. `undefined` when the
70
+ * two sides declare one name differently, which is a real conflict.
71
+ */
72
+ function bothSides(ours: readonly string[], theirs: readonly string[]): string[] | undefined {
73
+ const left = entriesOf(ours);
74
+ const right = entriesOf(theirs);
75
+ if (left === undefined || right === undefined) return undefined;
76
+ const entries = [...new Set([...left, ...right])];
77
+ const identities = entries.flatMap((entry) => identityOf(entry) ?? []);
78
+ if (new Set(identities).size !== identities.length) return undefined;
79
+ return entries
80
+ .sort((a, b) => {
81
+ const [x, y] = [sortKeyOf(a), sortKeyOf(b)];
82
+ return x < y ? -1 : x > y ? 1 : 0;
83
+ })
84
+ .flatMap((entry) => entry.split('\n'));
85
+ }
86
+
87
+ /**
88
+ * A marker line, with or without the `\r` git ends it with on a CRLF file. The `\r` stays on every
89
+ * line this module passes through or reorders, so the merged file keeps its own line ending.
90
+ */
91
+ const isMarker = (line: string | undefined, marker: string): boolean =>
92
+ line === marker || line === `${marker}\r`;
93
+
94
+ /** The first `marker` line at or after `from`; -1 when there is none, or no `from` to start at. */
95
+ export const markerAt = (lines: readonly string[], marker: string, from: number): number => {
96
+ if (from < 0) return -1;
97
+ for (let at = from; at < lines.length; at += 1) {
98
+ if (isMarker(lines[at], marker)) return at;
99
+ }
100
+ return -1;
101
+ };
102
+
103
+ /** `text` — `git merge-file --diff3 -L ours -L base -L theirs` output — with additions resolved. */
104
+ export function resolveAdditions(text: string): LineMerge {
105
+ const lines = text.split('\n');
106
+ const out: string[] = [];
107
+ let conflicts = 0;
108
+ for (let index = 0; index < lines.length; index += 1) {
109
+ const line = lines[index] as string;
110
+ if (!isMarker(line, OURS_MARKER)) {
111
+ out.push(line);
112
+ continue;
113
+ }
114
+ const baseAt = markerAt(lines, BASE_MARKER, index);
115
+ const splitAt = markerAt(lines, SPLIT_MARKER, baseAt);
116
+ const endAt = markerAt(lines, THEIRS_MARKER, splitAt);
117
+ if (baseAt === -1 || splitAt === -1 || endAt === -1) {
118
+ out.push(line);
119
+ continue;
120
+ }
121
+ const merged =
122
+ splitAt === baseAt + 1
123
+ ? bothSides(lines.slice(index + 1, baseAt), lines.slice(splitAt + 1, endAt))
124
+ : undefined;
125
+ if (merged === undefined) conflicts += 1;
126
+ out.push(...(merged ?? lines.slice(index, endAt + 1)));
127
+ index = endAt;
128
+ }
129
+ return { text: out.join('\n'), conflicts };
130
+ }
131
+
132
+ /**
133
+ * The count the driver exits on. `resolved` is `resolveAdditions`' own; the rest is a backstop for
134
+ * a marker it did not recognise: when git reported conflicts and a line of the result still opens
135
+ * one, the file is not merged whatever was counted, and git's number stands.
136
+ */
137
+ export function conflictsLeft(text: string, resolved: number, gitReported: number): number {
138
+ if (resolved > 0 || gitReported <= 0) return resolved;
139
+ return /^<{7} /m.test(text) ? gitReported : 0;
140
+ }
@@ -0,0 +1,105 @@
1
+ // What a merge left behind, as findings: paths git still holds unmerged, and i18n catalogs that do
2
+ // not parse. A catalog is imported by nearly every page, so one stray marker used to surface as a
3
+ // SyntaxError blamed on each importer, with the catalog itself named nowhere.
4
+
5
+ // why: `Bun.Glob.scan` throws on a missing directory, and an app need not have any catalog.
6
+ import { existsSync } from 'node:fs';
7
+ import { ERROR_DOCS_URL, renderThrowable } from '@ultimat3/core';
8
+ import type { Runner } from './exec';
9
+ import { exec } from './exec';
10
+ import type { Finding } from './output';
11
+ import { quoteArg } from './shell-quote';
12
+
13
+ /**
14
+ * `templates/locales.ts`'s `CATALOG_ROOT`, restated: `loadApp` reaches this module, and the serve
15
+ * graph carries no template (`serve-graph.test.ts`). `merge-state.test.ts` holds the two equal.
16
+ */
17
+ export const CATALOG_ROOT = 'packages/i18n/catalogs';
18
+
19
+ export const UNMERGED_FIX = 'git diff --name-only --diff-filter=U';
20
+
21
+ const MARKER = /^(?:<{7}|\|{7}|={7}|>{7})(?: |$)/m;
22
+
23
+ const finding = (code: string, cause: string, fix: string, at: string): Finding => ({
24
+ code,
25
+ cause,
26
+ fix,
27
+ docs: ERROR_DOCS_URL,
28
+ at,
29
+ });
30
+
31
+ /** Every path git holds unmerged, relative to `root`; none outside a checkout. */
32
+ export async function unmergedPaths(
33
+ root: string,
34
+ runner: Runner = exec,
35
+ ): Promise<readonly string[]> {
36
+ const argv = ['git', 'diff', '--name-only', '--relative', '--diff-filter=U'];
37
+ const found = await runner(argv, { cwd: root }).catch(() => undefined);
38
+ if (found?.ok !== true) return [];
39
+ return found.stdout.split('\n').filter((path) => path !== '');
40
+ }
41
+
42
+ export async function unmergedFindings(root: string, runner?: Runner): Promise<readonly Finding[]> {
43
+ return (await unmergedPaths(root, runner)).map((path) =>
44
+ finding(
45
+ 'X_MERGE_UNRESOLVED',
46
+ `${path} is still unmerged: git holds conflicting versions of it`,
47
+ UNMERGED_FIX,
48
+ path,
49
+ ),
50
+ );
51
+ }
52
+
53
+ /** One finding per catalog that will not load, naming the file every importer failed on. */
54
+ export async function catalogFileFindings(root: string): Promise<readonly Finding[]> {
55
+ const findings: Finding[] = [];
56
+ const directory = `${root}/${CATALOG_ROOT}`;
57
+ if (!existsSync(directory)) return findings;
58
+ for await (const name of new Bun.Glob('*.json').scan(directory)) {
59
+ const at = `${CATALOG_ROOT}/${name}`;
60
+ const text = await Bun.file(`${root}/${at}`).text();
61
+ if (MARKER.test(text)) {
62
+ findings.push(
63
+ finding(
64
+ 'X_MERGE_UNRESOLVED',
65
+ `${at} holds conflict markers, so it is not JSON and no page importing it loads`,
66
+ `grep -nE '^(<{7}|={7}|>{7})' ${quoteArg(at)} # keep the right side of each, delete the markers`,
67
+ at,
68
+ ),
69
+ );
70
+ continue;
71
+ }
72
+ try {
73
+ JSON.parse(text);
74
+ } catch (error) {
75
+ findings.push(
76
+ finding(
77
+ 'X_CATALOG_UNPARSEABLE',
78
+ `${at} is not valid JSON (${renderThrowable(error)}), so no page importing it loads`,
79
+ `bunx biome check ${quoteArg(at)} # names the line to correct`,
80
+ at,
81
+ ),
82
+ );
83
+ }
84
+ }
85
+ return findings;
86
+ }
87
+
88
+ const isCatalogSymptom = (one: Finding): boolean =>
89
+ one.code === 'X_CLI_UNEXPECTED' && one.cause.includes('JSON Parse error');
90
+
91
+ /**
92
+ * A failed app load, its causes first: an unparseable catalog replaces the parse errors it caused
93
+ * in every importer, and an unmerged path leads, because it explains whatever else failed. Asked
94
+ * only once the load has already failed, so a healthy app pays nothing.
95
+ */
96
+ export async function withMergeCauses(
97
+ root: string,
98
+ findings: readonly Finding[],
99
+ ): Promise<readonly Finding[]> {
100
+ const catalogs = await catalogFileFindings(root);
101
+ const held = new Set(catalogs.map((one) => one.at));
102
+ const unmerged = (await unmergedFindings(root)).filter((one) => !held.has(one.at));
103
+ const rest = catalogs.length > 0 ? findings.filter((one) => !isCatalogSymptom(one)) : findings;
104
+ return [...unmerged, ...catalogs, ...rest];
105
+ }
@@ -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,19 +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,
320
334
  'cli.heavy.waiting':
321
- 'heavy: {label} waits for {need} MB, position {position} of {queued}; {used} of {capacity} MB held by {holders}',
322
- 'cli.heavy.lockWait': 'heavy: waiting for this checkout’s {name} lock, held by {holder}',
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',
323
346
  'cli.heavy.status.summary':
324
347
  '{used} of {capacity} MB reserved, {holds} running, {queued} queued; {cores} core(s) per run',
325
348
  'cli.heavy.status.off': 'admission is off here ({reason}); {cores} core(s) per run',
326
349
  'cli.heavy.status.machine':
327
350
  'machine: load {load} on {cpus} cores, {runnable} runnable, {free} GB of {total} GB available',
328
- 'cli.heavy.status.hold': 'running: {entry}',
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}',
329
355
  'cli.heavy.status.queued': 'queued {position}: {entry}',
330
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',
331
381
  } as const;
332
382
 
333
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;