@ultimat3/cli 31.47.1 → 31.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/CLAUDE.md +30 -23
  2. package/README.md +96 -4
  3. package/package.json +29 -29
  4. package/src/api-registration.ts +28 -14
  5. package/src/app-load.ts +6 -1
  6. package/src/app-root.ts +7 -1
  7. package/src/clean-services.ts +142 -0
  8. package/src/cmd-auth.ts +3 -0
  9. package/src/cmd-clean-spec.ts +10 -3
  10. package/src/cmd-clean.ts +23 -9
  11. package/src/cmd-db-backfill.ts +6 -0
  12. package/src/cmd-db-branch.ts +10 -4
  13. package/src/cmd-db-recount.ts +5 -12
  14. package/src/cmd-db-rollback.ts +77 -0
  15. package/src/cmd-db-spec.ts +18 -2
  16. package/src/cmd-db-status.ts +5 -10
  17. package/src/cmd-db.ts +105 -33
  18. package/src/cmd-deploy-verify.ts +14 -6
  19. package/src/cmd-docs-topic.ts +94 -0
  20. package/src/cmd-docs.ts +15 -1
  21. package/src/cmd-doctor.ts +109 -41
  22. package/src/cmd-drill.ts +100 -19
  23. package/src/cmd-env.ts +30 -8
  24. package/src/cmd-errors-app.ts +63 -0
  25. package/src/cmd-errors.ts +50 -14
  26. package/src/cmd-generate.ts +17 -4
  27. package/src/cmd-heavy-spec.ts +36 -0
  28. package/src/cmd-heavy.ts +244 -0
  29. package/src/cmd-jobs.ts +27 -1
  30. package/src/cmd-merge-driver-spec.ts +12 -0
  31. package/src/cmd-merge-driver.ts +95 -0
  32. package/src/cmd-new.ts +23 -3
  33. package/src/cmd-policy-spec.ts +9 -1
  34. package/src/cmd-policy.ts +72 -17
  35. package/src/cmd-stop.ts +18 -4
  36. package/src/cmd-tasks-run.ts +87 -0
  37. package/src/cmd-tasks-spec.ts +10 -3
  38. package/src/cmd-tasks.ts +8 -5
  39. package/src/cmd-test.ts +15 -4
  40. package/src/cmd-upgrade-spec.ts +8 -1
  41. package/src/cmd-upgrade.ts +32 -5
  42. package/src/cmd-verify.ts +9 -41
  43. package/src/codemods/agents-doc-row.ts +73 -0
  44. package/src/codemods/define-error-leaf.ts +37 -12
  45. package/src/codemods/docs-many-agents.ts +26 -0
  46. package/src/codemods/docs-worker-commands.ts +26 -0
  47. package/src/codemods/index.ts +6 -0
  48. package/src/codemods/merge-drivers.ts +66 -0
  49. package/src/command.ts +3 -0
  50. package/src/db-applied-edits.ts +117 -0
  51. package/src/db-dev-wire.ts +18 -0
  52. package/src/db-diagnostics.ts +5 -10
  53. package/src/db-generate.ts +82 -7
  54. package/src/db-migrate-pass.ts +51 -0
  55. package/src/db-migrate-through-dev.ts +209 -0
  56. package/src/db-rollback-consent.ts +128 -0
  57. package/src/db-rollback-pass.ts +76 -0
  58. package/src/db-seed-generate.ts +5 -1
  59. package/src/db-seed.ts +7 -1
  60. package/src/deploy-verify-findings.ts +3 -0
  61. package/src/deploy-verify-grade.ts +3 -0
  62. package/src/deploy-verify-processes.ts +32 -0
  63. package/src/dev-boot.ts +3 -0
  64. package/src/dev-db-migrate.ts +155 -0
  65. package/src/dev-db-rollback.ts +33 -0
  66. package/src/dev-db-settled.ts +22 -0
  67. package/src/dev-lock-errors.ts +78 -0
  68. package/src/dev-lock-holder-dir.ts +64 -0
  69. package/src/dev-lock-live.ts +44 -0
  70. package/src/dev-lock.ts +59 -84
  71. package/src/dev-policy.ts +11 -8
  72. package/src/dev-rebuild-schema.ts +116 -13
  73. package/src/dev-rebuild.ts +13 -4
  74. package/src/dev-route-table.ts +7 -0
  75. package/src/dispatch.ts +21 -1
  76. package/src/doctor-advisory-floors.ts +30 -8
  77. package/src/doctor-api-listing.ts +114 -0
  78. package/src/doctor-guarded.ts +41 -0
  79. package/src/doctor-port.ts +90 -17
  80. package/src/doctor-probe.ts +36 -5
  81. package/src/doctor-processes-probe.ts +127 -0
  82. package/src/doctor-processes.ts +136 -0
  83. package/src/doctor-warnings.ts +17 -0
  84. package/src/error-codes-agents.ts +35 -0
  85. package/src/error-codes-processes.ts +30 -0
  86. package/src/error-codes-tooling.ts +11 -3
  87. package/src/error-codes.ts +12 -13
  88. package/src/errors-suite.ts +27 -0
  89. package/src/errors.ts +18 -22
  90. package/src/exec.ts +11 -3
  91. package/src/exercise-registration.ts +4 -3
  92. package/src/framework-env.ts +7 -3
  93. package/src/generate-files.ts +1 -0
  94. package/src/generate-grant-findings.ts +7 -5
  95. package/src/generate-grants.ts +9 -8
  96. package/src/generate-kinds.ts +30 -6
  97. package/src/generate-roles-file.ts +30 -0
  98. package/src/generate-slice-policy.ts +3 -3
  99. package/src/guards.ts +2 -2
  100. package/src/heavy-cores.ts +51 -0
  101. package/src/heavy-env.ts +21 -0
  102. package/src/heavy-errors.ts +54 -0
  103. package/src/heavy-flock.ts +73 -0
  104. package/src/heavy-holders.ts +78 -0
  105. package/src/heavy-ledger.ts +400 -0
  106. package/src/heavy-memory.ts +67 -0
  107. package/src/heavy-pressure.ts +104 -0
  108. package/src/heavy-weights.ts +47 -0
  109. package/src/heavy.ts +308 -0
  110. package/src/i18n-registration.ts +22 -2
  111. package/src/island-harness.ts +2 -2
  112. package/src/job-budget.ts +4 -2
  113. package/src/job-registration.ts +64 -8
  114. package/src/jobs-queue-known.ts +43 -0
  115. package/src/local-cli.ts +6 -5
  116. package/src/mcp-errors-agents.ts +20 -0
  117. package/src/mcp-errors-doctor.ts +27 -0
  118. package/src/mcp-errors-processes.ts +23 -0
  119. package/src/mcp-errors.ts +18 -29
  120. package/src/mcp-host.ts +2 -2
  121. package/src/merge-driver-catalog.ts +58 -0
  122. package/src/merge-driver-config.ts +43 -0
  123. package/src/merge-driver-lines.ts +140 -0
  124. package/src/merge-state.ts +105 -0
  125. package/src/messages-db.ts +22 -1
  126. package/src/messages-processes.ts +13 -0
  127. package/src/messages-upgrade.ts +6 -0
  128. package/src/messages.ts +62 -1
  129. package/src/output-findings.ts +48 -21
  130. package/src/parse.ts +37 -6
  131. package/src/policy-facts.ts +38 -21
  132. package/src/policy-row.ts +99 -0
  133. package/src/port-pair-free.ts +28 -0
  134. package/src/registry-lines.ts +110 -0
  135. package/src/registry.ts +4 -0
  136. package/src/retain-sweep.ts +1 -1
  137. package/src/role-replicator.ts +9 -4
  138. package/src/role-select.ts +86 -0
  139. package/src/role-start.ts +13 -55
  140. package/src/role-sync.ts +10 -5
  141. package/src/runtime-cache-frame.ts +46 -0
  142. package/src/runtime-cache-ttl.ts +23 -0
  143. package/src/runtime-cache.ts +56 -18
  144. package/src/runtime-database-ssl.ts +84 -0
  145. package/src/runtime-idempotency-scope.ts +16 -2
  146. package/src/runtime-jobs-share.ts +52 -0
  147. package/src/runtime-jobs.ts +43 -12
  148. package/src/runtime-overrides.ts +4 -2
  149. package/src/runtime-queue.ts +18 -3
  150. package/src/runtime-services.ts +8 -1
  151. package/src/schema-drift.ts +19 -2
  152. package/src/schema-dump-drift.ts +4 -1
  153. package/src/serve-boot-probe.ts +30 -2
  154. package/src/serve-boot.ts +11 -1
  155. package/src/serve-env.ts +39 -3
  156. package/src/serve.ts +61 -10
  157. package/src/stop-run-start.ts +12 -0
  158. package/src/supervise-boot.ts +61 -0
  159. package/src/supervise-cgroup.ts +84 -0
  160. package/src/supervise-child.ts +206 -0
  161. package/src/supervise-count.ts +244 -0
  162. package/src/supervise-errors.ts +83 -0
  163. package/src/supervise-facts.ts +40 -0
  164. package/src/supervise-messages.ts +84 -0
  165. package/src/supervise-policy.ts +46 -0
  166. package/src/supervise-pool.ts +10 -0
  167. package/src/supervise-probe.ts +158 -0
  168. package/src/supervise-run.ts +54 -0
  169. package/src/supervise.ts +383 -0
  170. package/src/templates/generate-purge.ts +6 -6
  171. package/src/templates/guard-animated-layout-property.ts +2 -2
  172. package/src/templates/guard-bare-error.ts +1 -1
  173. package/src/templates/guard-error-declared.ts +2 -2
  174. package/src/templates/guard-focus-visible.ts +1 -1
  175. package/src/templates/guard-image-dimensions.ts +2 -2
  176. package/src/templates/guard-island-mount-clears.ts +1 -1
  177. package/src/templates/guard-native-confirm.ts +1 -1
  178. package/src/templates/guard-raw-breakpoint.ts +2 -2
  179. package/src/templates/guard-raw-colour.ts +2 -2
  180. package/src/templates/guard-raw-fetch.ts +1 -1
  181. package/src/templates/guard-raw-interval.ts +1 -1
  182. package/src/templates/guard-raw-length.ts +3 -3
  183. package/src/templates/guard-raw-motion.ts +1 -1
  184. package/src/templates/guard-raw-shadow.ts +1 -1
  185. package/src/templates/guard-raw-z-index.ts +1 -1
  186. package/src/templates/guard-released-forms.ts +59 -13
  187. package/src/templates/guard-repo-await-in-loop.ts +1 -1
  188. package/src/templates/guard-repo-raw-sql.ts +4 -4
  189. package/src/templates/guard-repo-unbounded.ts +1 -1
  190. package/src/templates/guard-runtime-pin.ts +1 -1
  191. package/src/templates/guard-semantic-interactive.ts +2 -2
  192. package/src/templates/guard-unbounded-fanout.ts +1 -1
  193. package/src/templates/guard-undeclared-custom-property.ts +3 -3
  194. package/src/templates/guard-undefined-style-class.ts +3 -3
  195. package/src/templates/guard-unzoned-date.ts +3 -3
  196. package/src/templates/query-slice.ts +82 -0
  197. package/src/templates/query.ts +76 -30
  198. package/src/templates/resource-page.ts +3 -2
  199. package/src/templates/scaffold-bin.ts +2 -0
  200. package/src/templates/scaffold-claude-agents.ts +9 -6
  201. package/src/templates/scaffold-claude-commands.ts +7 -1
  202. package/src/templates/scaffold-claude.ts +4 -4
  203. package/src/templates/scaffold-container-compose.ts +47 -7
  204. package/src/templates/scaffold-docs.ts +11 -6
  205. package/src/templates/scaffold-gitattributes.ts +18 -1
  206. package/src/templates/scaffold-helm-templates.ts +9 -0
  207. package/src/templates/scaffold-repo.ts +4 -1
  208. package/src/templates/scaffold-test-services.ts +33 -11
  209. package/src/templates/shapes/offline.ts +0 -7
  210. package/src/templates/shapes/realtime.ts +2 -6
  211. package/src/templates/sign-in-action-tests.ts +6 -4
  212. package/src/templates/sign-in-challenge.ts +62 -0
  213. package/src/templates/sign-in-oidc-mfa.ts +31 -0
  214. package/src/templates/sign-in-oidc.ts +11 -3
  215. package/src/templates/sign-in-password.ts +18 -56
  216. package/src/test-batches.ts +9 -3
  217. package/src/test-shards.ts +117 -37
  218. package/src/test-slots.ts +35 -161
  219. package/src/test-verdict.ts +79 -0
  220. package/src/test-workers.ts +15 -0
  221. package/src/upgrade-gate-codemods.ts +5 -3
  222. package/src/upgrade-gate.ts +19 -1
  223. package/src/upgrade-merge-drivers.ts +25 -0
  224. package/src/upgrade-report.ts +18 -4
  225. package/src/upgrade-scope.ts +62 -0
  226. package/src/verify-checks.ts +6 -11
  227. package/src/verify-coverage-run.ts +9 -5
  228. package/src/verify-deadline.ts +18 -2
  229. package/src/verify-heavy-steps.ts +26 -0
  230. package/src/verify-live.ts +38 -14
  231. package/src/verify-only.ts +67 -0
  232. package/src/verify-progress.ts +7 -3
  233. package/src/verify-run.ts +20 -2
  234. package/src/verify-services-stack.ts +165 -0
  235. package/src/verify-services.ts +84 -2
  236. package/src/verify-test-run.ts +9 -9
  237. package/src/verify-tests.ts +35 -22
  238. package/src/verify-typecheck.ts +25 -2
  239. package/wiki/Actions.md +2 -1
  240. package/wiki/Admin-Dashboard.md +2 -2
  241. package/wiki/Agents.md +5 -5
  242. package/wiki/Auth.md +15 -5
  243. package/wiki/Bare-VM.md +1 -1
  244. package/wiki/Building-Your-Own-Base.md +15 -2
  245. package/wiki/CI-Parallel-Gate.md +4 -4
  246. package/wiki/CLI-Reference.md +127 -48
  247. package/wiki/Caching-And-Invalidation.md +2 -2
  248. package/wiki/Client-Navigation.md +1 -1
  249. package/wiki/Configuration.md +32 -13
  250. package/wiki/Deployment.md +44 -4
  251. package/wiki/Entities-And-Migrations.md +5 -1
  252. package/wiki/FAQ.md +1 -1
  253. package/wiki/Getting-Started.md +2 -2
  254. package/wiki/Home.md +2 -1
  255. package/wiki/I18n.md +5 -3
  256. package/wiki/Installation.md +12 -11
  257. package/wiki/Interface-Rules.md +1 -1
  258. package/wiki/Jobs-And-Workflows.md +24 -4
  259. package/wiki/Known-Gaps.md +2 -2
  260. package/wiki/MCP-And-AI.md +8 -5
  261. package/wiki/Mail.md +1 -1
  262. package/wiki/Many-Agents.md +127 -0
  263. package/wiki/Migrations-And-Backfills.md +18 -0
  264. package/wiki/Notify.md +1 -1
  265. package/wiki/Observability.md +13 -0
  266. package/wiki/Queries-And-Live-Queries.md +2 -2
  267. package/wiki/Realtime.md +10 -1
  268. package/wiki/Routes-And-Render-Modes.md +1 -1
  269. package/wiki/Scheduled-Tasks.md +4 -1
  270. package/wiki/Testing.md +12 -9
  271. package/wiki/Timezones-And-Dates.md +5 -1
  272. package/wiki/Troubleshooting.md +1 -0
  273. package/wiki/Tutorial-01-First-App.md +5 -5
  274. package/wiki/Tutorial-02-First-Feature.md +1 -1
  275. package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
  276. package/wiki/Upgrading.md +37 -0
package/src/cmd-verify.ts CHANGED
@@ -10,11 +10,10 @@
10
10
 
11
11
  // why: Bun ships no path-joining primitive: `join`/`isAbsolute` resolve a part path against the cwd.
12
12
  import { isAbsolute, join } from 'node:path';
13
- import { nearestName, renderFixShellArg } from '@ultimat3/core';
14
13
  import { requireAppRoot } from './app-root';
15
14
  import { verifySpec } from './cmd-verify-spec';
16
15
  import type { CliCommand, CommandContext } from './command';
17
- import { BadFlagError, MissingPositionalError } from './errors';
16
+ import { MissingPositionalError } from './errors';
18
17
  import { readIntFlag } from './flag-number';
19
18
  import type { CommandResult, JsonValue } from './output';
20
19
  import type { ParsedArgs } from './parse';
@@ -25,6 +24,7 @@ import { VERIFY_STEPS } from './verify-checks';
25
24
  import { readVerifyFloor } from './verify-floor';
26
25
  import type { VerifyPart } from './verify-merge';
27
26
  import { coverageRiders, mergeParts, parsePart, VerifyMergeInputError } from './verify-merge';
27
+ import { readStepList } from './verify-only';
28
28
  import { measurePace } from './verify-pace';
29
29
  import { verifyPlanCommand } from './verify-plan';
30
30
  import { withVerifyProgress } from './verify-progress';
@@ -82,7 +82,10 @@ export const verifyCommand: CliCommand = {
82
82
  ...progress,
83
83
  }),
84
84
  // A line per step a person reads, JSON only for the `--json` reader that parses stderr.
85
- { render: ctx.args.json ? 'json' : 'human' },
85
+ {
86
+ render: ctx.args.json ? 'json' : 'human',
87
+ ...(ctx.reader === undefined ? {} : { reader: ctx.reader }),
88
+ },
86
89
  );
87
90
  const sharded = shard === undefined ? result : withShardData(result, shard);
88
91
  return changed === undefined ? sharded : withChangedData(sharded, changed);
@@ -154,44 +157,9 @@ async function mergeCommand(
154
157
  });
155
158
  }
156
159
 
157
- /**
158
- * The steps `--only` names, or nothing: one step (`--only lint`) or a comma-separated list
159
- * (`--only typecheck,lint,boundaries`) run in ONE process, in the gate's declared order whatever
160
- * order they were typed in. Refused against `VERIFY_STEP_NAMES` — the same constant the runner's
161
- * list is built from — so a typo can never be read as "narrow to no steps at all", which is a run
162
- * that passes by checking nothing. An empty item (`lint,,drift`, a trailing comma) is refused for
163
- * the same reason.
164
- *
165
- * A near miss leads with the list as it would be with each typo corrected; an item near NOTHING
166
- * gets the gate itself rather than an invented lead, which is the rule `parse.ts` already follows
167
- * for a command that resembles none. Both arms are commands that run.
168
- */
169
- export const readOnlySteps = (args: ParsedArgs): readonly VerifyStepName[] | undefined => {
170
- const raw = flagString(args, 'only');
171
- if (raw === undefined) return undefined;
172
- const items = raw.split(',').map((item) => item.trim());
173
- const unknown = items.filter((item) => !isStepName(item));
174
- if (unknown.length === 0) {
175
- return VERIFY_STEP_NAMES.filter((name) => items.includes(name));
176
- }
177
- // An empty item corrects to nothing — never to whichever step is nearest to ''.
178
- const corrected = items.map((item) =>
179
- isStepName(item) ? item : item === '' ? undefined : nearestName(item, VERIFY_STEP_NAMES),
180
- );
181
- const fix = corrected.every((item) => item !== undefined)
182
- ? `x verify --only ${renderFixShellArg([...new Set(corrected)].join(','), '<step,step>')} --json`
183
- : 'x verify --json';
184
- const named = unknown.map((item) => (item === '' ? '(empty)' : `"${item}"`)).join(', ');
185
- throw new BadFlagError({
186
- flag: 'only',
187
- command: 'verify',
188
- reason: `${named} ${unknown.length === 1 ? 'is not a gate step' : 'are not gate steps'} (${VERIFY_STEP_NAMES.join(', ')})`,
189
- fix,
190
- });
191
- };
192
-
193
- const isStepName = (raw: string): raw is VerifyStepName =>
194
- (VERIFY_STEP_NAMES as readonly string[]).includes(raw);
160
+ /** `--only`'s list, read by `verify-only.ts` — the one reader `x upgrade --only` shares. */
161
+ export const readOnlySteps = (args: ParsedArgs): readonly VerifyStepName[] | undefined =>
162
+ readStepList(args, 'verify');
195
163
 
196
164
  /**
197
165
  * Both bounds are the constants the flag summary already names, so `x help verify` and the reader
@@ -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 = {
@@ -0,0 +1,26 @@
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 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
+
5
+ import { editAgentsDocRow } from './agents-doc-row';
6
+ import type { Codemod } from './codemod';
7
+
8
+ const NEXT_ROW = '| One way | generators, not hand-rolled files:';
9
+
10
+ /** Terse on purpose: a shaped app's CLAUDE.md sits within bytes of `AGENTS_MD_MAX_BYTES`. */
11
+ export const MANY_AGENTS_ROW =
12
+ '| Many agents | a worker runs its own files; the coordinator runs the gate once | `bunx x heavy status` |';
13
+
14
+ export const codemod: Codemod = {
15
+ id: 'docs-many-agents',
16
+ since: '31.48.0',
17
+ summary: "CLAUDE.md's table says a worker runs its own files and the coordinator runs the gate",
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
+ }),
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
+ };
@@ -18,12 +18,15 @@ import { codemod as docsCiParts } from './docs-ci-parts';
18
18
  import { codemod as docsEnvGuard } from './docs-env-guard';
19
19
  import { codemod as docsGateProse } from './docs-gate-prose';
20
20
  import { codemod as docsIslandRows } from './docs-island-rows';
21
+ import { codemod as docsManyAgents } from './docs-many-agents';
21
22
  import { codemod as docsShippedGuards } from './docs-shipped-guards';
22
23
  import { codemod as docsTestServices } from './docs-test-services';
24
+ import { codemod as docsWorkerCommands } from './docs-worker-commands';
23
25
  import { codemod as e2eSuiteFloor } from './e2e-suite-floor';
24
26
  import { codemod as formatEditedHook } from './format-edited-hook';
25
27
  import { codemod as helmAlertsDeploy } from './helm-alerts-deploy';
26
28
  import { codemod as helmAlertsObjective } from './helm-alerts-objective';
29
+ import { codemod as mergeDrivers } from './merge-drivers';
27
30
  import { codemod as metricsProbeHealthz } from './metrics-probe-healthz';
28
31
  import { codemod as migrateJobOrdered } from './migrate-job-ordered';
29
32
  import { codemod as reproGitignore } from './repro-gitignore';
@@ -71,4 +74,7 @@ export const CODEMODS: readonly Codemod[] = [
71
74
  ciArtifactRetention,
72
75
  ciWeeklySchedule,
73
76
  e2eSuiteFloor,
77
+ docsManyAgents,
78
+ docsWorkerCommands,
79
+ mergeDrivers,
74
80
  ];
@@ -0,0 +1,66 @@
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. Every step is additive: a list this cannot restate is left alone,
4
+ // and it still works; it only keeps merging by hand.
5
+
6
+ import { REGISTRY_FILES, withRegistryLines } from '../registry-lines';
7
+ import { BIN_SCRIPTS } from '../templates/scaffold-bin';
8
+ import { MERGE_ATTRIBUTES, ROOT_GITATTRIBUTES_PATH } from '../templates/scaffold-gitattributes';
9
+ import type { Codemod, CodemodApp, CodemodResult } from './codemod';
10
+
11
+ const INSTALL_ANCHOR = "await bun('install');\n";
12
+ export const INSTALL_STEP = "await x('merge-driver', 'install');\n";
13
+
14
+ const withAttributes = (held: string | undefined): string | undefined => {
15
+ if (held?.includes('merge=x-registry') === true) return undefined;
16
+ if (held === undefined) return MERGE_ATTRIBUTES;
17
+ return `${held.endsWith('\n') ? held : `${held}\n`}\n${MERGE_ATTRIBUTES}`;
18
+ };
19
+
20
+ async function edit(
21
+ app: CodemodApp,
22
+ path: string,
23
+ change: (held: string) => string | undefined,
24
+ changed: string[],
25
+ ): Promise<void> {
26
+ const held = await app.read(path);
27
+ if (held === undefined) return;
28
+ const next = change(held);
29
+ if (next === undefined || next === held) return;
30
+ await app.write(path, next);
31
+ changed.push(path);
32
+ }
33
+
34
+ export const codemod: Codemod = {
35
+ id: 'merge-drivers',
36
+ since: '31.49.0',
37
+ summary: 'parallel branches merge generated features: drivers, setup step, one entry per line',
38
+ async run(app): Promise<CodemodResult> {
39
+ const changed: string[] = [];
40
+ const skipped: CodemodResult['skipped'] = [];
41
+ const attributes = withAttributes(await app.read(ROOT_GITATTRIBUTES_PATH));
42
+ if (attributes !== undefined) {
43
+ await app.write(ROOT_GITATTRIBUTES_PATH, attributes);
44
+ changed.push(ROOT_GITATTRIBUTES_PATH);
45
+ }
46
+ const setup = await app.read(BIN_SCRIPTS.setup);
47
+ if (setup !== undefined && !setup.includes(INSTALL_STEP)) {
48
+ if (setup.includes(INSTALL_ANCHOR)) {
49
+ await app.write(
50
+ BIN_SCRIPTS.setup,
51
+ setup.replace(INSTALL_ANCHOR, `${INSTALL_ANCHOR}${INSTALL_STEP}`),
52
+ );
53
+ changed.push(BIN_SCRIPTS.setup);
54
+ } else {
55
+ skipped.push({
56
+ path: BIN_SCRIPTS.setup,
57
+ reason: `no "${INSTALL_ANCHOR.trim()}" line to follow; add ${INSTALL_STEP.trim()} after your install step`,
58
+ });
59
+ }
60
+ }
61
+ for (const path of REGISTRY_FILES) {
62
+ await edit(app, path, (held) => withRegistryLines(path, held), changed);
63
+ }
64
+ return { changed, skipped };
65
+ },
66
+ };
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.