@ultimat3/cli 31.48.0 → 31.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/CLAUDE.md +30 -23
  2. package/README.md +96 -4
  3. package/package.json +30 -30
  4. package/src/api-registration.ts +45 -14
  5. package/src/api-routes.ts +1 -0
  6. package/src/app-load.ts +7 -3
  7. package/src/app-openapi.ts +7 -1
  8. package/src/app-root.ts +7 -1
  9. package/src/budgets.ts +2 -1
  10. package/src/clean-services.ts +142 -0
  11. package/src/cmd-auth.ts +3 -0
  12. package/src/cmd-clean-spec.ts +10 -3
  13. package/src/cmd-clean.ts +23 -9
  14. package/src/cmd-db-backfill.ts +6 -0
  15. package/src/cmd-db-branch.ts +10 -4
  16. package/src/cmd-db-recount.ts +5 -12
  17. package/src/cmd-db-rollback.ts +77 -0
  18. package/src/cmd-db-spec.ts +18 -2
  19. package/src/cmd-db-status.ts +5 -10
  20. package/src/cmd-db.ts +105 -33
  21. package/src/cmd-deploy-verify.ts +14 -6
  22. package/src/cmd-docs-topic.ts +94 -0
  23. package/src/cmd-docs.ts +15 -1
  24. package/src/cmd-doctor.ts +109 -41
  25. package/src/cmd-drill.ts +80 -18
  26. package/src/cmd-env.ts +30 -8
  27. package/src/cmd-errors-app.ts +63 -0
  28. package/src/cmd-errors.ts +50 -14
  29. package/src/cmd-generate.ts +17 -4
  30. package/src/cmd-heavy-spec.ts +9 -1
  31. package/src/cmd-heavy.ts +111 -27
  32. package/src/cmd-i18n.ts +33 -1
  33. package/src/cmd-jobs.ts +27 -1
  34. package/src/cmd-merge-driver-spec.ts +12 -0
  35. package/src/cmd-merge-driver.ts +95 -0
  36. package/src/cmd-new.ts +23 -3
  37. package/src/cmd-policy-spec.ts +9 -1
  38. package/src/cmd-policy.ts +72 -17
  39. package/src/cmd-stop.ts +18 -4
  40. package/src/cmd-tasks-run.ts +87 -0
  41. package/src/cmd-tasks-spec.ts +10 -3
  42. package/src/cmd-tasks.ts +8 -5
  43. package/src/cmd-test.ts +2 -1
  44. package/src/cmd-upgrade-spec.ts +8 -1
  45. package/src/cmd-upgrade.ts +15 -1
  46. package/src/cmd-verify.ts +9 -41
  47. package/src/codemods/agents-doc-row.ts +73 -0
  48. package/src/codemods/define-error-leaf.ts +37 -12
  49. package/src/codemods/docs-many-agents.ts +11 -15
  50. package/src/codemods/docs-worker-commands.ts +26 -0
  51. package/src/codemods/engine-fs.ts +9 -2
  52. package/src/codemods/index.ts +4 -0
  53. package/src/codemods/merge-drivers.ts +147 -0
  54. package/src/command.ts +3 -0
  55. package/src/db-applied-edits.ts +117 -0
  56. package/src/db-dev-wire.ts +18 -0
  57. package/src/db-diagnostics.ts +5 -10
  58. package/src/db-generate.ts +82 -7
  59. package/src/db-migrate-pass.ts +51 -0
  60. package/src/db-migrate-through-dev.ts +209 -0
  61. package/src/db-rollback-consent.ts +128 -0
  62. package/src/db-rollback-pass.ts +76 -0
  63. package/src/db-seed-generate.ts +5 -1
  64. package/src/db-seed.ts +7 -1
  65. package/src/deploy-verify-findings.ts +3 -0
  66. package/src/deploy-verify-grade.ts +3 -0
  67. package/src/deploy-verify-processes.ts +32 -0
  68. package/src/dev-boot.ts +3 -0
  69. package/src/dev-db-migrate.ts +155 -0
  70. package/src/dev-db-rollback.ts +33 -0
  71. package/src/dev-db-settled.ts +22 -0
  72. package/src/dev-lock-errors.ts +78 -0
  73. package/src/dev-lock-holder-dir.ts +64 -0
  74. package/src/dev-lock-live.ts +44 -0
  75. package/src/dev-lock.ts +59 -84
  76. package/src/dev-policy.ts +11 -8
  77. package/src/dev-rebuild-schema.ts +116 -13
  78. package/src/dev-rebuild.ts +13 -4
  79. package/src/dev-route-table.ts +7 -0
  80. package/src/dispatch.ts +21 -1
  81. package/src/doctor-api-listing.ts +114 -0
  82. package/src/doctor-guarded.ts +41 -0
  83. package/src/doctor-port.ts +90 -17
  84. package/src/doctor-probe.ts +36 -5
  85. package/src/doctor-processes-probe.ts +127 -0
  86. package/src/doctor-processes.ts +136 -0
  87. package/src/doctor-warnings.ts +17 -0
  88. package/src/error-codes-agents.ts +35 -0
  89. package/src/error-codes-processes.ts +30 -0
  90. package/src/error-codes-tooling.ts +2 -0
  91. package/src/error-codes.ts +12 -13
  92. package/src/errors-suite.ts +27 -0
  93. package/src/errors.ts +18 -22
  94. package/src/exercise-registration.ts +4 -3
  95. package/src/exercise-services.ts +13 -3
  96. package/src/framework-env.ts +7 -3
  97. package/src/framework-schema.ts +15 -5
  98. package/src/generate-files.ts +1 -0
  99. package/src/generate-grant-findings.ts +7 -5
  100. package/src/generate-grants.ts +9 -8
  101. package/src/generate-kinds.ts +30 -6
  102. package/src/generate-roles-file.ts +30 -0
  103. package/src/generate-slice-policy.ts +3 -3
  104. package/src/guard-sources.ts +1 -2
  105. package/src/guards.ts +2 -2
  106. package/src/heavy-env.ts +2 -0
  107. package/src/heavy-errors.ts +18 -0
  108. package/src/heavy-holders.ts +78 -0
  109. package/src/heavy-ledger.ts +56 -14
  110. package/src/heavy-pressure.ts +104 -0
  111. package/src/heavy.ts +31 -13
  112. package/src/i18n-registration.ts +22 -2
  113. package/src/island-harness.ts +2 -2
  114. package/src/job-budget.ts +4 -2
  115. package/src/job-registration.ts +64 -8
  116. package/src/jobs-queue-known.ts +43 -0
  117. package/src/mcp-errors-agents.ts +20 -0
  118. package/src/mcp-errors-doctor.ts +27 -0
  119. package/src/mcp-errors-processes.ts +23 -0
  120. package/src/mcp-errors.ts +15 -29
  121. package/src/mcp-host.ts +2 -2
  122. package/src/merge-driver-catalog.ts +58 -0
  123. package/src/merge-driver-config.ts +43 -0
  124. package/src/merge-driver-lines.ts +140 -0
  125. package/src/merge-state.ts +105 -0
  126. package/src/messages-db.ts +22 -1
  127. package/src/messages-processes.ts +13 -0
  128. package/src/messages-upgrade.ts +10 -0
  129. package/src/messages.ts +54 -4
  130. package/src/output-findings.ts +48 -21
  131. package/src/page-navigation.ts +5 -2
  132. package/src/parse.ts +37 -6
  133. package/src/policy-facts.ts +38 -21
  134. package/src/policy-row.ts +99 -0
  135. package/src/port-pair-free.ts +28 -0
  136. package/src/pwa-artifacts.ts +1 -1
  137. package/src/registry-lines.ts +110 -0
  138. package/src/registry.ts +2 -0
  139. package/src/retain-sweep.ts +1 -1
  140. package/src/retained-assets-boot.ts +1 -1
  141. package/src/role-replicator.ts +4 -1
  142. package/src/role-select.ts +86 -0
  143. package/src/role-start.ts +13 -55
  144. package/src/role-sync.ts +10 -5
  145. package/src/runtime-assets-site.ts +2 -2
  146. package/src/runtime-assets.ts +1 -1
  147. package/src/runtime-cache-frame.ts +46 -0
  148. package/src/runtime-cache-ttl.ts +23 -0
  149. package/src/runtime-cache.ts +33 -16
  150. package/src/runtime-database-ssl.ts +84 -0
  151. package/src/runtime-idempotency-scope.ts +16 -2
  152. package/src/runtime-jobs-share.ts +52 -0
  153. package/src/runtime-jobs.ts +43 -12
  154. package/src/runtime-queue.ts +18 -3
  155. package/src/runtime-render-document.ts +1 -2
  156. package/src/runtime-services.ts +8 -1
  157. package/src/schema-drift.ts +19 -2
  158. package/src/schema-dump-drift.ts +4 -1
  159. package/src/serve-boot-probe.ts +30 -2
  160. package/src/serve-boot.ts +11 -1
  161. package/src/serve-env.ts +39 -3
  162. package/src/serve.ts +61 -10
  163. package/src/site-asset-routes.ts +2 -2
  164. package/src/site-assets.ts +5 -158
  165. package/src/stop-run-start.ts +12 -0
  166. package/src/supervise-boot.ts +61 -0
  167. package/src/supervise-cgroup.ts +84 -0
  168. package/src/supervise-child.ts +206 -0
  169. package/src/supervise-count.ts +244 -0
  170. package/src/supervise-errors.ts +83 -0
  171. package/src/supervise-facts.ts +40 -0
  172. package/src/supervise-messages.ts +84 -0
  173. package/src/supervise-policy.ts +46 -0
  174. package/src/supervise-pool.ts +10 -0
  175. package/src/supervise-probe.ts +158 -0
  176. package/src/supervise-run.ts +54 -0
  177. package/src/supervise.ts +383 -0
  178. package/src/sw-precache-plan.ts +1 -1
  179. package/src/templates/generate-purge.ts +6 -6
  180. package/src/templates/guard-animated-layout-property.ts +2 -2
  181. package/src/templates/guard-bare-error.ts +1 -1
  182. package/src/templates/guard-error-declared.ts +2 -2
  183. package/src/templates/guard-focus-visible.ts +1 -1
  184. package/src/templates/guard-image-dimensions.ts +2 -2
  185. package/src/templates/guard-island-mount-clears.ts +1 -1
  186. package/src/templates/guard-native-confirm.ts +1 -1
  187. package/src/templates/guard-raw-breakpoint.ts +2 -2
  188. package/src/templates/guard-raw-colour.ts +2 -2
  189. package/src/templates/guard-raw-fetch.ts +1 -1
  190. package/src/templates/guard-raw-interval.ts +1 -1
  191. package/src/templates/guard-raw-length.ts +3 -3
  192. package/src/templates/guard-raw-motion.ts +97 -1
  193. package/src/templates/guard-raw-shadow.ts +1 -1
  194. package/src/templates/guard-raw-z-index.ts +1 -1
  195. package/src/templates/guard-released-forms.ts +58 -9
  196. package/src/templates/guard-repo-await-in-loop.ts +1 -1
  197. package/src/templates/guard-repo-raw-sql.ts +4 -4
  198. package/src/templates/guard-repo-unbounded.ts +1 -1
  199. package/src/templates/guard-runtime-pin.ts +1 -1
  200. package/src/templates/guard-semantic-interactive.ts +2 -2
  201. package/src/templates/guard-unbounded-fanout.ts +1 -1
  202. package/src/templates/guard-undeclared-custom-property.ts +3 -3
  203. package/src/templates/guard-undefined-style-class.ts +3 -3
  204. package/src/templates/guard-unzoned-date.ts +3 -3
  205. package/src/templates/query-slice.ts +82 -0
  206. package/src/templates/query.ts +76 -30
  207. package/src/templates/resource-page.ts +3 -2
  208. package/src/templates/scaffold-bin.ts +2 -0
  209. package/src/templates/scaffold-claude-commands.ts +6 -0
  210. package/src/templates/scaffold-claude.ts +4 -4
  211. package/src/templates/scaffold-container-compose.ts +47 -7
  212. package/src/templates/scaffold-docs.ts +7 -3
  213. package/src/templates/scaffold-gitattributes.ts +18 -1
  214. package/src/templates/scaffold-helm-templates.ts +9 -0
  215. package/src/templates/scaffold-repo.ts +5 -2
  216. package/src/templates/scaffold-test-services.ts +33 -11
  217. package/src/templates/shapes/offline.ts +0 -7
  218. package/src/templates/shapes/realtime.ts +2 -6
  219. package/src/templates/sign-in-action-tests.ts +6 -4
  220. package/src/templates/sign-in-challenge.ts +62 -0
  221. package/src/templates/sign-in-oidc-mfa.ts +31 -0
  222. package/src/templates/sign-in-oidc.ts +11 -3
  223. package/src/templates/sign-in-password.ts +18 -56
  224. package/src/test-only-shipped.ts +29 -2
  225. package/src/test-shards.ts +134 -42
  226. package/src/test-verdict.ts +79 -0
  227. package/src/test-workers.ts +15 -0
  228. package/src/upgrade-coverage-ratchet.ts +95 -0
  229. package/src/upgrade-gate-codemods.ts +5 -3
  230. package/src/upgrade-gate.ts +42 -4
  231. package/src/upgrade-merge-drivers.ts +25 -0
  232. package/src/upgrade-report.ts +32 -4
  233. package/src/upgrade-scope.ts +62 -0
  234. package/src/verify-checks.ts +2 -8
  235. package/src/verify-coverage-run.ts +4 -1
  236. package/src/verify-e2e.ts +21 -3
  237. package/src/verify-live.ts +38 -14
  238. package/src/verify-only.ts +67 -0
  239. package/src/verify-progress.ts +7 -3
  240. package/src/verify-run.ts +20 -2
  241. package/src/verify-services-stack.ts +165 -0
  242. package/src/verify-services.ts +84 -2
  243. package/src/verify-test-run.ts +6 -7
  244. package/src/verify-tests.ts +8 -2
  245. package/src/verify-typecheck.ts +25 -2
  246. package/src/workspace-checks.ts +4 -1
  247. package/wiki/Actions.md +66 -3
  248. package/wiki/Admin-Dashboard.md +2 -2
  249. package/wiki/Agents.md +5 -5
  250. package/wiki/Auth.md +20 -6
  251. package/wiki/Bare-VM.md +1 -1
  252. package/wiki/CI-Parallel-Gate.md +2 -1
  253. package/wiki/CLI-Reference.md +115 -42
  254. package/wiki/Caching-And-Invalidation.md +1 -1
  255. package/wiki/Client-Navigation.md +35 -5
  256. package/wiki/Configuration.md +12 -10
  257. package/wiki/Deployment.md +44 -4
  258. package/wiki/Entities-And-Migrations.md +17 -3
  259. package/wiki/FAQ.md +1 -1
  260. package/wiki/Getting-Started.md +2 -2
  261. package/wiki/Home.md +3 -3
  262. package/wiki/I18n.md +6 -4
  263. package/wiki/Installation.md +12 -11
  264. package/wiki/Interface-Rules.md +3 -1
  265. package/wiki/Jobs-And-Workflows.md +24 -4
  266. package/wiki/Known-Gaps.md +2 -2
  267. package/wiki/MCP-And-AI.md +48 -13
  268. package/wiki/Many-Agents.md +69 -2
  269. package/wiki/Migrations-And-Backfills.md +18 -0
  270. package/wiki/Notify.md +5 -3
  271. package/wiki/Observability.md +13 -0
  272. package/wiki/Outbound-HTTP.md +53 -2
  273. package/wiki/Policies-And-Authz.md +1 -1
  274. package/wiki/Queries-And-Live-Queries.md +2 -2
  275. package/wiki/Realtime.md +24 -7
  276. package/wiki/Routes-And-Render-Modes.md +2 -2
  277. package/wiki/Scheduled-Tasks.md +4 -1
  278. package/wiki/Static-Assets.md +5 -3
  279. package/wiki/Testing.md +64 -7
  280. package/wiki/Theming.md +6 -3
  281. package/wiki/Timezones-And-Dates.md +5 -1
  282. package/wiki/Troubleshooting.md +1 -0
  283. package/wiki/Tutorial-01-First-App.md +3 -3
  284. package/wiki/Tutorial-02-First-Feature.md +1 -1
  285. package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
  286. package/wiki/UI-Components.md +1 -0
  287. package/wiki/Upgrading.md +38 -0
@@ -0,0 +1,73 @@
1
+ // One row of an app's agent brief, changed by a codemod: found in CLAUDE.md or AGENTS.md, held to
2
+ // the byte budget the manifest step enforces, and reported as a skip with the row itself whenever
3
+ // it cannot be placed. A silent `changed: []` left the row owed with nobody told.
4
+
5
+ import { AGENTS_MD_MAX_BYTES } from '@ultimat3/manifest';
6
+ import { parseVerifyFloor, VERIFY_FLOOR_FILE } from '../verify-floor';
7
+ import type { CodemodApp, CodemodResult } from './codemod';
8
+ import { readText } from './engine-edits';
9
+
10
+ /** Where an app keeps its brief: the scaffold writes CLAUDE.md, and some apps moved it. */
11
+ const BRIEFS = ['CLAUDE.md', 'AGENTS.md'] as const;
12
+
13
+ export interface AgentsDocRow {
14
+ /** The text the row is placed against, and what it becomes: an insert or a swap. */
15
+ readonly from: string;
16
+ readonly to: string;
17
+ /** The row a person adds when it cannot be placed. */
18
+ readonly row: string;
19
+ /** Already said, in the app's own words or the template's: nothing to do. */
20
+ readonly said: (text: string) => boolean;
21
+ /** Why `from` is missing, in the skip a person reads. */
22
+ readonly missing: string;
23
+ }
24
+
25
+ /** `x.verify.json`'s `agentsMdMaxBytes`, else the manifest's default: the one the gate holds. */
26
+ async function budgetOf(app: CodemodApp): Promise<number> {
27
+ const floor = await app.read(VERIFY_FLOOR_FILE);
28
+ if (floor === undefined) return AGENTS_MD_MAX_BYTES;
29
+ try {
30
+ return parseVerifyFloor(floor).agentsMdMaxBytes ?? AGENTS_MD_MAX_BYTES;
31
+ } catch {
32
+ // An unreadable floor is the gate's own finding (`floorProblemFindings`); the default stands.
33
+ return AGENTS_MD_MAX_BYTES;
34
+ }
35
+ }
36
+
37
+ const skip = (path: string, reason: string): CodemodResult => ({
38
+ changed: [],
39
+ skipped: [{ path, reason }],
40
+ });
41
+
42
+ export async function editAgentsDocRow(
43
+ app: CodemodApp,
44
+ edit: AgentsDocRow,
45
+ ): Promise<CodemodResult> {
46
+ const briefs: { path: string; text: string; restore: (text: string) => string }[] = [];
47
+ for (const path of BRIEFS) {
48
+ const file = await readText(app, path);
49
+ if (file !== undefined) briefs.push({ path, ...file });
50
+ }
51
+ if (briefs.length === 0 || briefs.some((brief) => edit.said(brief.text))) {
52
+ return { changed: [], skipped: [] };
53
+ }
54
+ const target = briefs.find((brief) => brief.text.split(edit.from).length === 2);
55
+ if (target === undefined) {
56
+ const path = briefs[0]?.path ?? BRIEFS[0];
57
+ return skip(
58
+ path,
59
+ `${edit.missing}; add this row to the conventions table by hand: ${edit.row}`,
60
+ );
61
+ }
62
+ const next = target.text.replace(edit.from, () => edit.to);
63
+ const bytes = Buffer.byteLength(target.restore(next), 'utf8');
64
+ const budget = await budgetOf(app);
65
+ if (bytes > budget) {
66
+ return skip(
67
+ target.path,
68
+ `the row would take ${target.path} to ${String(bytes)} bytes, over its ${String(budget)}-byte budget (${VERIFY_FLOOR_FILE} agentsMdMaxBytes); make room, then add this row by hand: ${edit.row}`,
69
+ );
70
+ }
71
+ await app.write(target.path, target.restore(next));
72
+ return { changed: [target.path], skipped: [] };
73
+ }
@@ -2,12 +2,18 @@
2
2
  // shipped `error-declared` guard refuses it from the `@ultimat3/core` barrel. A mechanical import
3
3
  // rewrite over every app source file (the rest of an import stays put), and the prose that names it.
4
4
 
5
- import type { Codemod, CodemodApp, CodemodResult } from './codemod';
5
+ import type { Codemod, CodemodApp, CodemodResult, CodemodSkip } from './codemod';
6
6
  import type { SnippetEdit } from './engine-edits';
7
7
  import { editSnippets, mergeResults } from './engine-edits';
8
8
 
9
- const IMPORT = /^import \{([^}]*)\} from '@ultimat3\/core';$/gm;
10
- const LEAF = "import { defineError } from '@ultimat3/core/page';";
9
+ // A trailing `// note` after the statement is kept where it was.
10
+ const IMPORT = /^import \{([^}]*)\} from '@ultimat3\/core';([ \t]*\/\/[^\n]*)?$/gm;
11
+ const leaf = (specifier: string): string => `import { ${specifier} } from '@ultimat3/core/page';`;
12
+ /** `defineError`, or `defineError as declare`: the one specifier that moves. */
13
+ const MOVES = /^defineError(?:\s+as\s+[A-Za-z_$][\w$]*)?$/;
14
+ /** What the rewrite left behind: a barrel import still naming it, in a shape this does not edit. */
15
+ const LEFT =
16
+ /\bimport\s*(?:type\s*)?\{[^}]*\bdefineError\b[^}]*\}\s*from\s*['"]@ultimat3\/core['"]/;
11
17
 
12
18
  /** The rows that name where `defineError` comes from, in CLAUDE.md, the server agent and /feature. */
13
19
  export const DEFINE_ERROR_PROSE: Readonly<Record<string, readonly SnippetEdit[]>> = {
@@ -34,29 +40,48 @@ export const DEFINE_ERROR_PROSE: Readonly<Record<string, readonly SnippetEdit[]>
34
40
  ],
35
41
  };
36
42
 
37
- /** The import with `defineError` taken out to the leaf; unchanged when it does not name it. */
38
- const rewrite = (whole: string, list: string): string => {
43
+ /**
44
+ * The import with `defineError` taken out to the leaf; unchanged when it does not name it, or when
45
+ * the braces hold a comment — a line this would have to drop or misplace, so it is reported.
46
+ */
47
+ const rewrite = (whole: string, list: string, trailing: string | undefined): string => {
48
+ if (list.includes('//') || list.includes('/*')) return whole;
39
49
  const names = list
40
50
  .split(',')
41
51
  .map((name) => name.trim())
42
52
  .filter((name) => name !== '');
43
- if (!names.includes('defineError')) return whole;
44
- const rest = names.filter((name) => name !== 'defineError');
45
- return rest.length === 0 ? LEAF : `import { ${rest.join(', ')} } from '@ultimat3/core';\n${LEAF}`;
53
+ const moved = names.find((name) => MOVES.test(name));
54
+ if (moved === undefined) return whole;
55
+ const rest = names.filter((name) => name !== moved);
56
+ const tail = trailing ?? '';
57
+ return rest.length === 0
58
+ ? `${leaf(moved)}${tail}`
59
+ : `import { ${rest.join(', ')} } from '@ultimat3/core';${tail}\n${leaf(moved)}`;
46
60
  };
47
61
 
48
62
  async function sources(app: CodemodApp): Promise<CodemodResult> {
49
63
  const changed: string[] = [];
64
+ const skipped: CodemodSkip[] = [];
50
65
  for (const path of await app.glob('{apps,packages}/**/*.{ts,tsx}')) {
51
66
  if (path.includes('node_modules/')) continue;
52
67
  const source = (await app.read(path)) ?? '';
53
68
  if (!source.includes('defineError')) continue;
54
69
  const next = source.replace(IMPORT, rewrite);
55
- if (next === source) continue;
56
- await app.write(path, next);
57
- changed.push(path);
70
+ if (next !== source) {
71
+ await app.write(path, next);
72
+ changed.push(path);
73
+ }
74
+ // Never silently kept: the shipped `error-declared` guard reds this file after the hop.
75
+ if (LEFT.test(next)) {
76
+ skipped.push({
77
+ path,
78
+ reason:
79
+ "imports defineError from '@ultimat3/core' in a shape this codemod does not rewrite (a comment inside the braces, a type-only import, or double quotes)",
80
+ diff: `- defineError (in the import from '@ultimat3/core')\n+ ${leaf('defineError')}`,
81
+ });
82
+ }
58
83
  }
59
- return { changed, skipped: [] };
84
+ return { changed, skipped };
60
85
  }
61
86
 
62
87
  export const codemod: Codemod = {
@@ -1,30 +1,26 @@
1
1
  // 31.48.0: CLAUDE.md states who runs what when several agents share a machine, the rule the machine
2
- // ledger exists to back. Prose: it lands where the table stands as `x new` wrote it, and is skipped
3
- // silently where the app reworded that row or already says it.
2
+ // ledger exists to back. Prose: it lands above the One way row, in CLAUDE.md or AGENTS.md, within
3
+ // the brief's byte budget; otherwise it is reported as skipped with the row to add by hand.
4
4
 
5
+ import { editAgentsDocRow } from './agents-doc-row';
5
6
  import type { Codemod } from './codemod';
6
- import type { SnippetEdit } from './engine-edits';
7
- import { editSnippets } from './engine-edits';
8
7
 
9
- const CLAUDE = 'CLAUDE.md';
10
8
  const NEXT_ROW = '| One way | generators, not hand-rolled files:';
11
9
 
12
10
  /** Terse on purpose: a shaped app's CLAUDE.md sits within bytes of `AGENTS_MD_MAX_BYTES`. */
13
11
  export const MANY_AGENTS_ROW =
14
12
  '| Many agents | a worker runs its own files; the coordinator runs the gate once | `bunx x heavy status` |';
15
13
 
16
- export const DOCS_MANY_AGENTS_EDITS: readonly SnippetEdit[] = [
17
- { from: NEXT_ROW, to: `${MANY_AGENTS_ROW}\n${NEXT_ROW}`, optional: true },
18
- ];
19
-
20
14
  export const codemod: Codemod = {
21
15
  id: 'docs-many-agents',
22
16
  since: '31.48.0',
23
17
  summary: "CLAUDE.md's table says a worker runs its own files and the coordinator runs the gate",
24
- async run(app) {
25
- if (((await app.read(CLAUDE)) ?? '').includes('x heavy status')) {
26
- return { changed: [], skipped: [] };
27
- }
28
- return editSnippets(app, CLAUDE, DOCS_MANY_AGENTS_EDITS);
29
- },
18
+ run: (app) =>
19
+ editAgentsDocRow(app, {
20
+ from: NEXT_ROW,
21
+ to: `${MANY_AGENTS_ROW}\n${NEXT_ROW}`,
22
+ row: MANY_AGENTS_ROW,
23
+ said: (text) => text.includes('| Many agents |'),
24
+ missing: `no "${NEXT_ROW}" row to place it above in CLAUDE.md or AGENTS.md`,
25
+ }),
30
26
  };
@@ -0,0 +1,26 @@
1
+ // 31.49.0: CLAUDE.md's many-agents row names the commands a worker runs. The row it replaces gave a
2
+ // worker none and listed `x heavy status` under "Refused by", which refuses nothing. Prose: it moves
3
+ // the row as written, within the brief's byte budget; a reworded or absent row is a reported skip.
4
+
5
+ import { editAgentsDocRow } from './agents-doc-row';
6
+ import type { Codemod } from './codemod';
7
+ import { MANY_AGENTS_ROW } from './docs-many-agents';
8
+
9
+ /** Terse on purpose: a shaped app's CLAUDE.md sits within bytes of `AGENTS_MD_MAX_BYTES`. */
10
+ export const WORKER_COMMANDS_ROW =
11
+ '| Many agents | a worker: `bun test ./<file>`, `bunx x test --filter <path>`; the coordinator: the gate, once | review |';
12
+
13
+ export const codemod: Codemod = {
14
+ id: 'docs-worker-commands',
15
+ since: '31.49.0',
16
+ summary: "CLAUDE.md's many-agents row names the commands a worker runs",
17
+ run: (app) =>
18
+ editAgentsDocRow(app, {
19
+ from: MANY_AGENTS_ROW,
20
+ to: WORKER_COMMANDS_ROW,
21
+ row: WORKER_COMMANDS_ROW,
22
+ said: (text) => text.includes(WORKER_COMMANDS_ROW),
23
+ missing:
24
+ 'the many-agents row is not the one x new or docs-many-agents wrote (reworded, or never added), so it is left as written',
25
+ }),
26
+ };
@@ -4,8 +4,8 @@
4
4
 
5
5
  // why: Bun has no file-removal, rename, lstat or realpath primitive; `rm` with `force` makes a
6
6
  // removal of nothing no error, `rename` lands a write whole, and only `realpath` answers where a
7
- // symlinked component really points.
8
- import { lstat, realpath, rename, rm } from 'node:fs/promises';
7
+ // symlinked component really points; `stat`/`chmod` carry a rewritten file's mode across the rename.
8
+ import { chmod, lstat, realpath, rename, rm, stat } from 'node:fs/promises';
9
9
  // why: Bun exposes no path-resolve primitive; containment is decided on the resolved path.
10
10
  import { dirname, resolve, sep } from 'node:path';
11
11
  import { ScaffoldPathEscapeError } from '../errors';
@@ -60,8 +60,15 @@ export async function landFile(
60
60
  move: (from: string, to: string) => Promise<void> = rename,
61
61
  ): Promise<void> {
62
62
  const temp = `${target}.x-codemod-${String(process.pid)}-${crypto.randomUUID()}.tmp`;
63
+ // The temp file is born 0644: without the target's mode carried over, the rename drops `+x` —
64
+ // 31.49.0's merge-drivers codemod turned an app's executable `bin/setup.ts` into a plain file.
65
+ const mode = await stat(target).then(
66
+ (found) => found.mode,
67
+ () => undefined,
68
+ );
63
69
  await Bun.write(temp, source);
64
70
  try {
71
+ if (mode !== undefined) await chmod(temp, mode);
65
72
  await move(temp, target);
66
73
  } catch (error) {
67
74
  await rm(temp, { force: true });
@@ -21,10 +21,12 @@ import { codemod as docsIslandRows } from './docs-island-rows';
21
21
  import { codemod as docsManyAgents } from './docs-many-agents';
22
22
  import { codemod as docsShippedGuards } from './docs-shipped-guards';
23
23
  import { codemod as docsTestServices } from './docs-test-services';
24
+ import { codemod as docsWorkerCommands } from './docs-worker-commands';
24
25
  import { codemod as e2eSuiteFloor } from './e2e-suite-floor';
25
26
  import { codemod as formatEditedHook } from './format-edited-hook';
26
27
  import { codemod as helmAlertsDeploy } from './helm-alerts-deploy';
27
28
  import { codemod as helmAlertsObjective } from './helm-alerts-objective';
29
+ import { codemod as mergeDrivers } from './merge-drivers';
28
30
  import { codemod as metricsProbeHealthz } from './metrics-probe-healthz';
29
31
  import { codemod as migrateJobOrdered } from './migrate-job-ordered';
30
32
  import { codemod as reproGitignore } from './repro-gitignore';
@@ -73,4 +75,6 @@ export const CODEMODS: readonly Codemod[] = [
73
75
  ciWeeklySchedule,
74
76
  e2eSuiteFloor,
75
77
  docsManyAgents,
78
+ docsWorkerCommands,
79
+ mergeDrivers,
76
80
  ];
@@ -0,0 +1,147 @@
1
+ // 31.49.0: two branches that each generate a feature merge without a hand edit. An existing app
2
+ // gains the `.gitattributes` rules, the `bun run setup` step that installs the drivers, and its
3
+ // registries one entry per line, the spread `api/index.ts` with a test that loads it. Additive: a
4
+ // list or a setup this cannot restate is left alone and reported; it only keeps merging by hand.
5
+
6
+ import { isJsonObject, stringField } from '@ultimat3/core';
7
+ import { API_INDEX } from '../app-root';
8
+ import { REGISTRY_FILES, withRegistryLines } from '../registry-lines';
9
+ import { BIN_SCRIPTS } from '../templates/scaffold-bin';
10
+ import { MERGE_ATTRIBUTES, ROOT_GITATTRIBUTES_PATH } from '../templates/scaffold-gitattributes';
11
+ import type { Codemod, CodemodApp, CodemodResult, CodemodSkip } from './codemod';
12
+
13
+ const INSTALL_ANCHOR = "await bun('install');\n";
14
+ export const INSTALL_STEP = "await x('merge-driver', 'install');\n";
15
+ /** The same step for a setup script that is not `bin/setup.ts`: a shell line, pasted by hand. */
16
+ export const SHELL_INSTALL_STEP = 'bunx x merge-driver install';
17
+
18
+ const withAttributes = (held: string | undefined): string | undefined => {
19
+ if (held?.includes('merge=x-registry') === true) return undefined;
20
+ if (held === undefined) return MERGE_ATTRIBUTES;
21
+ return `${held.endsWith('\n') ? held : `${held}\n`}\n${MERGE_ATTRIBUTES}`;
22
+ };
23
+
24
+ export const API_INDEX_TEST = API_INDEX.replace(/\.ts$/, '.test.ts');
25
+
26
+ /**
27
+ * The registration test, for an app `x new` wrote before it shipped `api/index.test.ts`. One row
28
+ * per entry is more lines, and an index no unit test loads weighs every one of them at 0% against
29
+ * the coverage floor — an upgrade that changed no behaviour went red. Generic on purpose: it reads
30
+ * the lists back, so it holds for any app's registrations.
31
+ */
32
+ export const apiIndexTest =
33
+ (): string => `// The registration, read back: importing the index runs \`defineApi\`, and every primitive it
34
+ // lists is registered under the export name it was handed over as.
35
+ import { expect, unitTest } from '@ultimat3/testing';
36
+ import { api } from './index';
37
+
38
+ unitTest('every listed primitive is registered under its export name', () => {
39
+ const lists: readonly object[] = [api.actions, api.queries, api.jobs, api.tasks];
40
+ for (const list of lists) {
41
+ for (const [name, primitive] of Object.entries(list)) {
42
+ expect(primitive).toHaveProperty('name', name);
43
+ }
44
+ }
45
+ });
46
+ `;
47
+
48
+ /** The index declares `api`, so the generic test has something to import; else it is reported. */
49
+ const EXPORTS_API = /^export const api = defineApi\(/m;
50
+
51
+ /** `scripts.setup` from the app's package.json, when it declares one. */
52
+ const setupCommand = (manifest: string | undefined): string | undefined => {
53
+ if (manifest === undefined) return undefined;
54
+ let parsed: unknown;
55
+ try {
56
+ parsed = JSON.parse(manifest);
57
+ } catch {
58
+ return undefined;
59
+ }
60
+ const scripts = isJsonObject(parsed) ? parsed['scripts'] : undefined;
61
+ return isJsonObject(scripts) ? stringField(scripts, 'setup') : undefined;
62
+ };
63
+
64
+ /**
65
+ * A setup that is not `bin/setup.ts` (a bash `bin/setup`, a Makefile) is never edited — a shell
66
+ * script has no anchor this can trust — but it is always reported, naming the file `bun run setup`
67
+ * runs when the app holds it, else `package.json`, unless that file already installs the drivers.
68
+ */
69
+ async function foreignSetup(app: CodemodApp): Promise<CodemodSkip | undefined> {
70
+ const command = setupCommand(await app.read('package.json'));
71
+ for (const token of command?.split(/\s+/) ?? []) {
72
+ const path = token.replace(/^\.\//, '');
73
+ const held = path === '' ? undefined : await app.read(path);
74
+ if (held === undefined) continue;
75
+ if (held.includes('merge-driver install')) return undefined;
76
+ return {
77
+ path,
78
+ reason: `bun run setup runs ${path}, not ${BIN_SCRIPTS.setup}; add the line ${SHELL_INSTALL_STEP} after its install step`,
79
+ };
80
+ }
81
+ return {
82
+ path: 'package.json',
83
+ reason: `no ${BIN_SCRIPTS.setup} and no setup script file in the app; add ${SHELL_INSTALL_STEP} to whatever bun run setup runs, after its install step`,
84
+ };
85
+ }
86
+
87
+ async function edit(
88
+ app: CodemodApp,
89
+ path: string,
90
+ change: (held: string) => string | undefined,
91
+ changed: string[],
92
+ ): Promise<void> {
93
+ const held = await app.read(path);
94
+ if (held === undefined) return;
95
+ const next = change(held);
96
+ if (next === undefined || next === held) return;
97
+ await app.write(path, next);
98
+ changed.push(path);
99
+ }
100
+
101
+ export const codemod: Codemod = {
102
+ id: 'merge-drivers',
103
+ since: '31.49.0',
104
+ summary: 'parallel branches merge generated features: drivers, setup step, one entry per line',
105
+ async run(app): Promise<CodemodResult> {
106
+ const changed: string[] = [];
107
+ const skipped: CodemodResult['skipped'] = [];
108
+ const attributes = withAttributes(await app.read(ROOT_GITATTRIBUTES_PATH));
109
+ if (attributes !== undefined) {
110
+ await app.write(ROOT_GITATTRIBUTES_PATH, attributes);
111
+ changed.push(ROOT_GITATTRIBUTES_PATH);
112
+ }
113
+ const setup = await app.read(BIN_SCRIPTS.setup);
114
+ if (setup === undefined) {
115
+ const skip = await foreignSetup(app);
116
+ if (skip !== undefined) skipped.push(skip);
117
+ } else if (!setup.includes(INSTALL_STEP)) {
118
+ if (setup.includes(INSTALL_ANCHOR)) {
119
+ await app.write(
120
+ BIN_SCRIPTS.setup,
121
+ setup.replace(INSTALL_ANCHOR, `${INSTALL_ANCHOR}${INSTALL_STEP}`),
122
+ );
123
+ changed.push(BIN_SCRIPTS.setup);
124
+ } else {
125
+ skipped.push({
126
+ path: BIN_SCRIPTS.setup,
127
+ reason: `no "${INSTALL_ANCHOR.trim()}" line to follow; add ${INSTALL_STEP.trim()} after your install step`,
128
+ });
129
+ }
130
+ }
131
+ for (const path of REGISTRY_FILES) {
132
+ await edit(app, path, (held) => withRegistryLines(path, held), changed);
133
+ }
134
+ if (changed.includes(API_INDEX) && !(await app.exists(API_INDEX_TEST))) {
135
+ if (EXPORTS_API.test((await app.read(API_INDEX)) ?? '')) {
136
+ await app.write(API_INDEX_TEST, apiIndexTest());
137
+ changed.push(API_INDEX_TEST);
138
+ } else {
139
+ skipped.push({
140
+ path: API_INDEX_TEST,
141
+ reason: `${API_INDEX} now lists one entry per line and no unit test loads it, so its lines count at 0% against the coverage floor; write a test that imports it`,
142
+ });
143
+ }
144
+ }
145
+ return { changed, skipped };
146
+ },
147
+ };
package/src/command.ts CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  import type { Runner } from './exec';
6
6
  import type { CommandResult } from './output';
7
+ import type { ReaderOptions } from './output-findings';
7
8
  import type { CommandSpec, ParsedArgs } from './parse';
8
9
 
9
10
  export interface CommandContext {
@@ -21,6 +22,8 @@ export interface CommandContext {
21
22
  * follow. Absent means the default below — a caller that builds a context by hand owes nothing.
22
23
  */
23
24
  readonly invocation?: string;
25
+ /** Who reads this run's fix lines, for one printed outside a finding. `dispatch` decides. */
26
+ readonly reader?: ReaderOptions;
24
27
  }
25
28
 
26
29
  /** What `ctx.invocation` means when nobody said: the binary, then the subcommand they typed. */
@@ -0,0 +1,117 @@
1
+ // An applied migration edited since, asked before `x db gen` writes anything: the command is
2
+ // `X_SCHEMA_DUMP_DRIFT`'s fix, and run over an edited migration it rewrote the dump to match the
3
+ // edit — blessing SQL no database holds. The embedded ledger is read where it can be, never dialled.
4
+
5
+ // why: Bun has no directory probe — `Bun.file().exists()` answers about a file.
6
+ import { existsSync } from 'node:fs';
7
+ import { renderThrowable } from '@ultimat3/core';
8
+ import type { Migration } from '@ultimat3/db';
9
+ import { auditLedger, isLedgerMissing, pgliteDataDir, readLedger } from '@ultimat3/db';
10
+ import { t } from '@ultimat3/schema';
11
+ import { withOpenedDb } from './db-client-displace';
12
+ import { DEV_LEDGER_PATH } from './db-dev-wire';
13
+ import { askDev, type PostJson, unreadable } from './db-migrate-through-dev';
14
+ import { liveDevLockChecked } from './dev-lock-live';
15
+ import { readMigrations } from './migrations';
16
+ import { resolveServices } from './runtime-bindings';
17
+ import { startDb } from './runtime-queue';
18
+
19
+ type Env = Readonly<Record<string, string | undefined>>;
20
+
21
+ /** One applied migration as the ledger records it: all the checksum rule reads. */
22
+ export interface AppliedRow {
23
+ readonly id: string;
24
+ readonly checksum: string;
25
+ }
26
+
27
+ const LEDGER = t.object({
28
+ ledger: t.array(t.object({ id: t.string, checksum: t.string })),
29
+ });
30
+
31
+ /**
32
+ * `auditLedger`'s checksum half over the rows this checkout still ships — a row it does not ship
33
+ * is another refusal (a rollback, a deleted file) and not this one's. Throws `X_MIGRATION_CONFLICT`
34
+ * with the migrator's own cause and fix, so the three places that ask cannot word it three ways.
35
+ */
36
+ export function refuseEdited(
37
+ applied: readonly AppliedRow[],
38
+ migrations: readonly Migration[],
39
+ ): void {
40
+ const shipped = new Set(migrations.map((migration) => migration.id));
41
+ auditLedger(
42
+ applied
43
+ .filter((row) => shipped.has(row.id))
44
+ // The fields the audit never reads on a known row, filled so the row types.
45
+ .map((row) => ({ ...row, name: row.id, applied_at: '', app_version: 'dev', duration_ms: 0 })),
46
+ migrations,
47
+ 'dev',
48
+ );
49
+ }
50
+
51
+ /** What the check found out: the rows, or why this run could not read them. */
52
+ export type AppliedRead =
53
+ | { readonly applied: readonly AppliedRow[] }
54
+ | { readonly skipped: string | undefined };
55
+
56
+ /**
57
+ * The embedded database's ledger, by whoever may read it: the live `x dev` that holds the
58
+ * directory, else this process on a read-only open (`x db status`'s). Never an external
59
+ * `DATABASE_URL` — `x db gen` is files in, files out, and must answer the same with no server up;
60
+ * there the migrator's own audit is the refusal. A read that fails is reported, never fatal: this
61
+ * command is the `fix:` of five errors and cannot start needing a healthy database to run.
62
+ */
63
+ export async function readApplied(root: string, env: Env, post?: PostJson): Promise<AppliedRead> {
64
+ const services = resolveServices(root, env);
65
+ if (services.db.mode !== 'embedded') return { skipped: undefined };
66
+ if (!existsSync(pgliteDataDir(services.db.url))) return { applied: [] };
67
+ try {
68
+ const holder = await liveDevLockChecked(services.stateDir);
69
+ if (holder !== undefined) {
70
+ const applied = await askDev(
71
+ holder,
72
+ services.stateDir,
73
+ {
74
+ path: DEV_LEDGER_PATH,
75
+ resume: ['db', 'gen'],
76
+ read: (data) => {
77
+ const parsed = LEDGER.safeParse(data);
78
+ return parsed.issues === undefined
79
+ ? { value: parsed.value.ledger }
80
+ : unreadable(parsed.issues);
81
+ },
82
+ },
83
+ post,
84
+ );
85
+ return { applied };
86
+ }
87
+ return {
88
+ applied: await withOpenedDb(
89
+ () => startDb(services, env, false),
90
+ async (client) => {
91
+ try {
92
+ return await readLedger(client);
93
+ } catch (error) {
94
+ if (!isLedgerMissing(error)) throw error;
95
+ return [];
96
+ }
97
+ },
98
+ ),
99
+ };
100
+ } catch (error) {
101
+ return { skipped: renderThrowable(error) };
102
+ }
103
+ }
104
+
105
+ /** Refuse (`X_MIGRATION_CONFLICT`) or answer why nothing was compared; `undefined` is "checked". */
106
+ export async function refuseAppliedEdits(
107
+ root: string,
108
+ env: Env,
109
+ post?: PostJson,
110
+ ): Promise<string | undefined> {
111
+ const migrations = await readMigrations(root);
112
+ if (migrations.length === 0) return undefined;
113
+ const read = await readApplied(root, env, post);
114
+ if ('skipped' in read) return read.skipped;
115
+ refuseEdited(read.applied, migrations);
116
+ return undefined;
117
+ }
@@ -0,0 +1,18 @@
1
+ // The `/_x/db` wire between `x db …` and a live `x dev` holding the embedded database: the three
2
+ // paths and the `--steps` rule, stated once. Import-free on purpose — the CLI clients read it
3
+ // without loading the route's graph, and the dev routes without loading a command's.
4
+
5
+ /** `x db migrate`, asked of the holder (`db-migrate-through-dev.ts` → `dev-db-migrate.ts`). */
6
+ export const DEV_MIGRATE_PATH = '/_x/db/migrate';
7
+
8
+ /** `x db rollback` (`db-rollback-pass.ts`) and `x db gen`'s ledger read (`db-applied-edits.ts`). */
9
+ export const DEV_ROLLBACK_PATH = '/_x/db/rollback';
10
+ export const DEV_LEDGER_PATH = '/_x/db/ledger';
11
+
12
+ /** `--steps` and the door's `?steps=`: one rule, so the holder refuses what the flag refuses. */
13
+ export const ROLLBACK_STEPS = {
14
+ name: 'steps',
15
+ command: 'db rollback',
16
+ min: 1,
17
+ example: 'x db rollback --steps 1',
18
+ } as const;
@@ -9,11 +9,12 @@ import {
9
9
  } from '@ultimat3/db/diagnostics';
10
10
  import type { CommandContext } from './command';
11
11
  import { withOpenedDb } from './db-client-displace';
12
- import { DevAlreadyRunningError, liveDevLock } from './dev-lock';
12
+ import { refuseBesideDev } from './dev-lock-live';
13
13
  import { readIntFlag } from './flag-number';
14
14
  import { msg } from './messages';
15
15
  import type { CommandResult, JsonValue } from './output';
16
16
  import { resolveServices } from './runtime-bindings';
17
+ import { databaseSslOf } from './runtime-database-ssl';
17
18
  import { startDb } from './runtime-queue';
18
19
  import { renderTable } from './table';
19
20
 
@@ -80,20 +81,14 @@ export async function runDiagnostics(ctx: CommandContext, root: string): Promise
80
81
  if (services.db.mode === 'embedded') {
81
82
  // Check-then-open, as `x db reset` does: an `x dev` starting between this read and `startDb`
82
83
  // below is not seen. Narrow, and the same window every embedded `x db` subcommand has.
83
- const holder = liveDevLock(services.stateDir);
84
- if (holder !== undefined) {
85
- throw new DevAlreadyRunningError({
86
- lock: holder,
87
- stateDir: services.stateDir,
88
- embeddedDb: true,
89
- });
90
- }
84
+ await refuseBesideDev(services.stateDir);
91
85
  }
86
+ const ssl = await databaseSslOf(services);
92
87
  // `startDb` installs its client as the process's `db()`; `withOpenedDb` puts back what was there
93
88
  // (closing a lazy default it dropped) and closes both pools, or every later `db()` in an
94
89
  // embedding process reaches a dead pool.
95
90
  return withOpenedDb(
96
- () => startDb(services, ctx.env),
91
+ () => startDb(services, ctx.env, ssl),
97
92
  async (client) => {
98
93
  // Embedded, the probe IS the boot — a WASM compile and an initdb, 12.6 s cold under coverage —
99
94
  // so the 3 s probe wait answered a healthy database X_DB_UNAVAILABLE. A server keeps the default.