@ultimat3/cli 31.25.0 → 31.27.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 (123) hide show
  1. package/CLAUDE.md +44 -36
  2. package/README.md +5 -4
  3. package/package.json +29 -29
  4. package/src/app-mcp.ts +17 -3
  5. package/src/cmd-cache-spec.ts +5 -2
  6. package/src/cmd-db-recount.ts +7 -0
  7. package/src/cmd-db-spec.ts +2 -3
  8. package/src/cmd-db.ts +0 -2
  9. package/src/cmd-deploy-verify-sample.ts +93 -0
  10. package/src/cmd-deploy-verify.ts +2 -41
  11. package/src/cmd-dev-spec.ts +15 -1
  12. package/src/cmd-dev.ts +31 -4
  13. package/src/cmd-doctor.ts +4 -1
  14. package/src/cmd-exercise-spec.ts +7 -1
  15. package/src/cmd-exercise.ts +22 -10
  16. package/src/cmd-generate.ts +2 -0
  17. package/src/cmd-jobs-spec.ts +3 -6
  18. package/src/cmd-jobs.ts +1 -7
  19. package/src/cmd-logs-spec.ts +2 -1
  20. package/src/cmd-logs.ts +9 -28
  21. package/src/cmd-planned.ts +11 -45
  22. package/src/cmd-profile-frames.ts +99 -0
  23. package/src/cmd-profile-spec.ts +24 -0
  24. package/src/cmd-profile.ts +164 -0
  25. package/src/cmd-status-sample.ts +57 -0
  26. package/src/cmd-status-spec.ts +30 -0
  27. package/src/cmd-status.ts +108 -0
  28. package/src/cmd-token-spec.ts +5 -2
  29. package/src/cmd-token.ts +7 -3
  30. package/src/coverage-island.ts +121 -0
  31. package/src/coverage-lcov.ts +49 -5
  32. package/src/coverage-remap.ts +146 -0
  33. package/src/db-replay-engine-prepared.ts +66 -0
  34. package/src/db-replay-engine-template.ts +156 -0
  35. package/src/db-replay-engine.ts +4 -0
  36. package/src/db-replay-scratch-reap.ts +54 -0
  37. package/src/deploy-verify-flags.ts +9 -2
  38. package/src/deploy-verify-grade.ts +10 -3
  39. package/src/dev-boot.ts +14 -1
  40. package/src/dev-dashboard-guard.ts +57 -10
  41. package/src/dev-host.ts +46 -0
  42. package/src/dev-tls-cache.ts +103 -0
  43. package/src/dev-tls-der.ts +69 -0
  44. package/src/dev-tls.ts +120 -0
  45. package/src/dispatch.ts +6 -1
  46. package/src/doctor-browser.ts +60 -0
  47. package/src/error-codes-verify.ts +47 -0
  48. package/src/error-codes.ts +14 -23
  49. package/src/exercise-database.ts +40 -7
  50. package/src/exercise-push-device.ts +51 -0
  51. package/src/exercise-route-api.ts +74 -0
  52. package/src/exercise-routes.ts +14 -5
  53. package/src/exercise-services.ts +3 -1
  54. package/src/exercise-shard-flag.ts +47 -0
  55. package/src/fix-command.ts +2 -2
  56. package/src/generate-factories.ts +9 -11
  57. package/src/generate-feature-required.ts +9 -4
  58. package/src/generate-files.ts +20 -2
  59. package/src/generate-kinds.ts +5 -1
  60. package/src/guards.ts +21 -6
  61. package/src/island-bundle-options.ts +48 -0
  62. package/src/island-bundle.ts +18 -46
  63. package/src/island-link.ts +5 -0
  64. package/src/island-outputs.ts +5 -0
  65. package/src/mcp-errors-verify.ts +35 -0
  66. package/src/mcp-errors.ts +10 -19
  67. package/src/mcp-host-logs.ts +121 -0
  68. package/src/mcp-host.ts +12 -73
  69. package/src/messages-floor.ts +19 -0
  70. package/src/messages-status.ts +10 -0
  71. package/src/messages.ts +21 -0
  72. package/src/registry.ts +4 -0
  73. package/src/role-start-types.ts +7 -0
  74. package/src/role-start.ts +4 -0
  75. package/src/serve-boot.ts +7 -1
  76. package/src/serve-env-tls.ts +57 -0
  77. package/src/solid-loader.ts +27 -10
  78. package/src/templates/generate-export-rows.ts +136 -0
  79. package/src/templates/generate-import-rows.ts +186 -0
  80. package/src/templates/generate-rows-slice.ts +95 -0
  81. package/src/templates/github/ci.yml.ts +4 -0
  82. package/src/templates/scaffold-db-package.ts +3 -0
  83. package/src/templates/scaffold-docs.ts +8 -6
  84. package/src/templates/scaffold-repo.ts +2 -7
  85. package/src/templates/scaffold-site.ts +4 -1
  86. package/src/templates/scaffold-suites.ts +72 -0
  87. package/src/templates/scaffold-test-services.ts +35 -10
  88. package/src/templates/scaffold-verify-floor.ts +53 -31
  89. package/src/templates/shapes/api.ts +4 -0
  90. package/src/templates/slice-foundation.ts +3 -3
  91. package/src/unthrown-codes.ts +1 -1
  92. package/src/upgrade-gate.ts +6 -1
  93. package/src/upgrade-guards-baseline.ts +43 -0
  94. package/src/upgrade-guards.ts +37 -2
  95. package/src/upgrade-report.ts +3 -0
  96. package/src/verify-coverage-run.ts +42 -11
  97. package/src/verify-e2e.ts +115 -4
  98. package/src/verify-floor.ts +27 -0
  99. package/src/verify-guard-baseline.ts +109 -0
  100. package/src/verify-live.ts +72 -0
  101. package/src/verify-merge-skips.ts +51 -0
  102. package/src/verify-merge.ts +36 -2
  103. package/src/verify-run.ts +48 -7
  104. package/src/verify-services.ts +287 -0
  105. package/src/verify-skip-reason.ts +53 -0
  106. package/src/verify-strict.ts +108 -0
  107. package/src/verify-test-command.ts +129 -0
  108. package/src/verify-tests.ts +39 -126
  109. package/types/babel-modules.d.ts +2 -0
  110. package/wiki/Agents.md +2 -5
  111. package/wiki/CLI-Reference.md +142 -23
  112. package/wiki/Caching-And-Invalidation.md +1 -1
  113. package/wiki/Entities-And-Migrations.md +1 -1
  114. package/wiki/Interface-Rules.md +5 -0
  115. package/wiki/Jobs-And-Workflows.md +3 -3
  116. package/wiki/Known-Gaps.md +5 -1
  117. package/wiki/MCP-And-AI.md +103 -2
  118. package/wiki/Mail.md +52 -0
  119. package/wiki/PWA-And-Offline.md +1 -1
  120. package/wiki/Scraping.md +19 -4
  121. package/wiki/Troubleshooting.md +3 -3
  122. package/wiki/Tutorial-05-Deploy-Free.md +2 -2
  123. package/wiki/Upgrading.md +3 -0
@@ -27,6 +27,7 @@ import { loadAppConfig } from './app-config-load';
27
27
  import type { IslandResolve } from './document-options';
28
28
  import { IslandBuildFailedError } from './errors';
29
29
  import { boundedMap } from './island-build-pool';
30
+ import type { BuildIslandsOptions } from './island-bundle-options';
30
31
  import {
31
32
  environmentDigest,
32
33
  inputDigester,
@@ -61,8 +62,10 @@ import { islandStylesPlugin, stylesheetsOf } from './island-styles';
61
62
  import type { Vendors } from './island-vendor';
62
63
  import { loadingVendor, vendorBuilder, vendorExternalPlugin, vendorShared } from './island-vendor';
63
64
  import { hasPathSegment } from './path-segments';
64
- import { solidJsxPlugin } from './solid-loader';
65
+ import { solidJsxCoveragePlugin, solidJsxPlugin } from './solid-loader';
65
66
 
67
+ // `dev-rebuild.ts` names the options type here, where it lived before the split.
68
+ export type { BuildIslandsOptions } from './island-bundle-options';
66
69
  export { ISLAND_BASE_PATH } from './island-outputs';
67
70
 
68
71
  /**
@@ -92,6 +95,8 @@ export interface IslandChunk {
92
95
  readonly imports: readonly string[];
93
96
  /** The files on disk it was built from (`island-sources.ts`). Absent on a chunk not built here. */
94
97
  readonly sources?: SourcePaths;
98
+ /** The external source map — a coverage build's only (`BuildIslandsOptions.coverage`). */
99
+ readonly map?: string;
95
100
  /**
96
101
  * Absent unless the island's graph reaches `@ultimat3/realtime`: then whether it has page state
97
102
  * to restore or only follows the socket (`island-realtime-state.ts`). On the chunk, so the
@@ -109,6 +114,7 @@ export interface SharedChunk {
109
114
  /** The islands (app-root-relative) that load it — for a finding that names what an author edits. */
110
115
  readonly importers: readonly string[];
111
116
  readonly sources?: SourcePaths;
117
+ readonly map?: string;
112
118
  }
113
119
 
114
120
  export interface IslandBundle {
@@ -188,7 +194,9 @@ async function buildAll(
188
194
  // `[dir]` keeps two islands sharing a filename apart and maps an output back to its island;
189
195
  // a chunk's Bun hash is only a placeholder — `island-link.ts` renames every one by its bytes.
190
196
  naming: { entry: '[dir]/[name].[ext]', chunk: 'chunk-[hash].[ext]' },
191
- minify: true,
197
+ // A coverage build keeps the lines its map names, and only them: identifiers and syntax are
198
+ // minified as shipped, so the code a test mounts is the shipped code laid out on lines.
199
+ minify: context.coverage ? { whitespace: false, syntax: true, identifiers: true } : true,
192
200
  // A build with no `plugins` is a build with no JSX transform: `Bun.plugin` installs into the
193
201
  // RUNTIME's loader and `Bun.build` walks its own graph, so render's `.tsx` loader never sees
194
202
  // an island. The app's tsconfig says `jsx: "preserve"`, which makes the bundler fall back to
@@ -212,7 +220,7 @@ async function buildAll(
212
220
  : [islandRealtimePlugin(root, runtime, follows, live.length === files.length)]),
213
221
  solidDedupePlugin(root),
214
222
  ...frameworkDedupePlugins(root),
215
- solidJsxPlugin,
223
+ context.coverage ? solidJsxCoveragePlugin : solidJsxPlugin,
216
224
  context.styles,
217
225
  ],
218
226
  // The third one, and it is a `define` rather than the plugin this used to be: Bun selects
@@ -256,7 +264,9 @@ async function buildAll(
256
264
  }
257
265
  await refuseDuplicatedModules(files.join(', '), built.metafile, context.io);
258
266
  const sources = new Map<string, SourcePaths>();
259
- const linked = linkOutputs(await builtOutputs(root, files, built.outputs, sources));
267
+ const linked = linkOutputs(
268
+ await builtOutputs(root, files, built.outputs, sources, context.coverage),
269
+ );
260
270
  const entries = loadingRuntime(entryChunks(files, linked, sources), live, runtime).map(
261
271
  (chunk): IslandChunk => {
262
272
  const kind = kinds.get(chunk.file);
@@ -318,47 +328,8 @@ interface BuildContext {
318
328
  readonly io: ModuleIdentityIo;
319
329
  /** Solid as one shared output (`island-vendor.ts`); `undefined` bundles it into each build. */
320
330
  readonly vendors: Vendors | undefined;
321
- }
322
-
323
- export interface BuildIslandsOptions {
324
- /**
325
- * Build ONE island, named app-root-relative — the whole option surface. A test that mounts a
326
- * single island otherwise pays every OTHER island's Babel pass and `Bun.build` on every file,
327
- * and the reference app is the one that feels it.
328
- *
329
- * Optional, and it must stay optional: `buildIslands` is on `@ultimat3/cli`'s public surface and
330
- * `@ultimat3/testing`'s `IslandBuilder` satisfies it STRUCTURALLY as `(root: string) => …`, which
331
- * is what keeps the `cli -> testing` edge pointing the one legal way.
332
- */
333
- readonly only?: string;
334
- /**
335
- * One split build over every island (`app.config.ts`'s `islands.sharedChunks`, off by default),
336
- * or one build per route group (`island-groups.ts`). Passed, it overrides the app's config — the
337
- * seam a test asks both questions of one fixture through.
338
- */
339
- readonly sharedChunks?: boolean;
340
- /**
341
- * Reuse a group's output from `.x/cache/islands/` while every file it read is unchanged
342
- * (`island-group-cache.ts`) — on by default. `false` is the seam a determinism test builds
343
- * through: a reused byte string proves nothing about the bundler that emitted it.
344
- */
345
- readonly reuse?: boolean;
346
- /**
347
- * Whether the app persists records (`appPersistsRecords`), asked only by a group one of whose
348
- * islands reaches realtime, and once per call. `x dev` builds islands BESIDE the app load
349
- * (`buildGeneration`), so it passes the answer the registry gives once the load settles; read
350
- * any earlier it is the empty registry's `undefined`, and every reader islands is held. Absent,
351
- * the registry is read as it stands: the caller loaded the app first.
352
- */
353
- readonly persists?: () => Promise<boolean | undefined>;
354
- /**
355
- * Solid as ONE shared output every island imports (`island-vendor.ts`), off by default. Measured
356
- * As of 2026-11-12 (Bun 1.4.4, solid-js 1.9.17): each island inlines a tree-shaken ~14 kB of
357
- * Solid, the whole vendor is 48,083 B, so every Solid route of the three tracked apps grew
358
- * +33,572…+38,769 B with it on; it pays only where a page renders four or more Solid islands
359
- * that are built apart.
360
- */
361
- readonly vendorSolid?: boolean;
331
+ /** `BuildIslandsOptions.coverage`. */
332
+ readonly coverage: boolean;
362
333
  }
363
334
 
364
335
  /** The `islands` block off the one loader (`app-config-load.ts`) — both off with no config file. */
@@ -388,6 +359,7 @@ export async function buildIslands(
388
359
  styles: islandStylesPlugin(),
389
360
  io: memoizedIo(hostIo()),
390
361
  vendors: vendorSolid ? vendorBuilder(root, ISLAND_BASE_PATH) : undefined,
362
+ coverage: options.coverage === true,
391
363
  };
392
364
  let asked: Promise<boolean | undefined> | undefined;
393
365
  const persistsOnce = (): Promise<boolean | undefined> => {
@@ -401,7 +373,7 @@ export async function buildIslands(
401
373
  const everyIsland =
402
374
  files.length > 0 && (options.sharedChunks ?? configured?.sharedChunks ?? false);
403
375
  const groups = everyIsland ? [files] : files.length === 0 ? [] : await islandGroups(root, files);
404
- const reuse = options.reuse ?? true;
376
+ const reuse = (options.reuse ?? true) && options.coverage !== true;
405
377
  const cache = {
406
378
  environment: reuse ? await environmentDigest(root) : '',
407
379
  digestOf: inputDigester(),
@@ -21,6 +21,8 @@ export interface BuiltOutput {
21
21
  readonly file?: string;
22
22
  /** Emitted code, the debug-id comment already removed. */
23
23
  readonly code: string;
24
+ /** Its external source map, kept only by a coverage build (`mountIsland` records it). */
25
+ readonly map?: string;
24
26
  }
25
27
 
26
28
  export interface LinkedFile {
@@ -33,6 +35,8 @@ export interface LinkedFile {
33
35
  readonly code: string;
34
36
  /** Final basenames of the outputs this one imports, statically or by `import()`, direct only. */
35
37
  readonly imports: readonly string[];
38
+ /** The output's map, unchanged: a renamed specifier stays on its line, so the lines still hold. */
39
+ readonly map?: string;
36
40
  }
37
41
 
38
42
  /** The final basename a shared chunk is served under — beside every entry, under one base path. */
@@ -83,6 +87,7 @@ export function linkOutputs(outputs: readonly BuiltOutput[]): readonly LinkedFil
83
87
  identity: contentHash(code),
84
88
  code,
85
89
  imports: [...new Set(imports)].sort(),
90
+ ...(output.map === undefined ? {} : { map: output.map }),
86
91
  };
87
92
  visiting.delete(output.path);
88
93
  linked.set(output.path, done);
@@ -41,6 +41,7 @@ export async function builtOutputs(
41
41
  files: readonly string[],
42
42
  artifacts: readonly Bun.BuildArtifact[],
43
43
  sourcePaths: Map<string, SourcePaths>,
44
+ keepMaps = false,
44
45
  ): Promise<readonly BuiltOutput[]> {
45
46
  const byStem = new Map(files.map((file) => [withoutExtension(file), file]));
46
47
  const maps = new Map<string, string>();
@@ -66,6 +67,8 @@ export async function builtOutputs(
66
67
  path: key,
67
68
  ...(file === undefined ? {} : { file }),
68
69
  code: stripDebugId(await artifact.text()),
70
+ // A coverage build's only: `mountIsland` records it, and nothing ships or serves it.
71
+ ...(keepMaps && map !== undefined ? { map } : {}),
69
72
  });
70
73
  }
71
74
  return outputs;
@@ -120,6 +123,7 @@ export function entryChunks(
120
123
  ...stableChunk(file, entry.identity, entry.code),
121
124
  imports: closure(entry.imports),
122
125
  sources: withOwnFile(file, sources.get(entry.path) ?? []),
126
+ ...(entry.map === undefined ? {} : { map: entry.map }),
123
127
  });
124
128
  }
125
129
  return chunks;
@@ -143,6 +147,7 @@ export function sharedChunks(
143
147
  .map((chunk) => chunk.file)
144
148
  .sort(),
145
149
  sources: sources.get(one.path) ?? [],
150
+ ...(one.map === undefined ? {} : { map: one.map }),
146
151
  });
147
152
  }
148
153
  return out.sort((a, b) => (a.url < b.url ? -1 : a.url > b.url ? 1 : 0));
@@ -0,0 +1,35 @@
1
+ // `errors.explain`'s rows for the gate's own floor and run — `x.verify.json`'s ratchets, a step's
2
+ // deadline, the shard/merge split, the services a suite needs — split out of `mcp-errors.ts` under
3
+ // the 500-line ceiling. Spread into `CLI_FIXES` there, whose `Record<CliErrorCode, string>` is still
4
+ // what makes a code without a row a build error.
5
+
6
+ import type { CliErrorCode } from './error-codes';
7
+
8
+ export const VERIFY_FIXES = {
9
+ // The same two edits `vanishedSuiteFinding` names, verbatim, so both surfaces of this code hand
10
+ // an agent one instruction. Neither edit is scripted here on purpose: a command that rewrites
11
+ // x.verify.json is the gate editing its own ratchet, which is the false green the floor closes.
12
+ X_VERIFY_SUITE_VANISHED:
13
+ 'x verify --json # restore the suite, or drop its name from x.verify.json in the commit that says why',
14
+ X_VERIFY_SHARD_INVALID: 'x verify --only unit --shard 1/4 --json',
15
+ X_VERIFY_MERGE_INCOMPLETE:
16
+ 'x verify merge parts/*.json --json # after every CI job uploaded its part',
17
+ X_VERIFY_MERGE_INPUT: 'x verify --only unit --json > part.json # one document per part',
18
+ X_VERIFY_STEP_TIMEOUT:
19
+ 'x verify --only unit --json # reproduce the step alone; one that needs longer states it under "stepTimeoutMs" in x.verify.json',
20
+ X_COVERAGE_BELOW_FLOOR:
21
+ 'x verify --only unit --json # names the ten files losing the most lines; cover the worst with a test beside it',
22
+ X_COVERAGE_FLOOR_UNSTATED:
23
+ 'x verify --only unit --json # the finding carries the measured numbers and the "coverage" line to add to x.verify.json',
24
+ X_COVERAGE_FLOOR_STALE:
25
+ 'x verify --only unit --json # the finding carries the measured numbers; raise "coverage" in x.verify.json to them',
26
+ X_VERIFY_SKIPS_OVER_CEILING:
27
+ 'x test unit --json # then set what the skipped tests need, or raise skipCeiling in x.verify.json with the reason in the diff',
28
+ X_TEST_SERVICES_UNAVAILABLE: 'docker compose -f docker/docker-compose.test.yml up -d --wait',
29
+ X_VERIFY_E2E_BROWSER_MISSING:
30
+ 'curl -fsSLo /tmp/google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && sudo apt-get install -y /tmp/google-chrome.deb',
31
+ X_VERIFY_STRICT_UNRUN:
32
+ 'x verify --json # data.skipReasons names each step that ran no check: give it a suite, or write "skip": { "<step>": "<why>" } in x.verify.json',
33
+ X_GUARD_OVER_BASELINE: 'x verify --only boundaries --json',
34
+ X_GUARD_BASELINE_STALE: 'x verify --only boundaries --json',
35
+ } as const satisfies Partial<Record<CliErrorCode, string>>;
package/src/mcp-errors.ts CHANGED
@@ -8,6 +8,7 @@ import type { CliErrorCode } from './error-codes';
8
8
  import { CLI_ERROR_CODES } from './error-codes';
9
9
  import { codeFixes, codeFixScan } from './error-fixes';
10
10
  import { SHOT_FIXES } from './mcp-errors-shot';
11
+ import { VERIFY_FIXES } from './mcp-errors-verify';
11
12
 
12
13
  /**
13
14
  * One runnable command per CLI code. Typed over `CliErrorCode`, so a new code fails the build.
@@ -41,18 +42,6 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
41
42
  X_ENV_EXAMPLE_DRIFT: 'x env example --json',
42
43
  X_TEST_NO_FILES: 'x test --json # from the repo root, or pass --cwd to it',
43
44
  X_TEST_BUDGET_INVALID: 'ULTIMATE_TEST_MEMORY_BUDGET=3g x verify --json',
44
- X_VERIFY_SHARD_INVALID: 'x verify --only unit --shard 1/4 --json',
45
- X_VERIFY_MERGE_INCOMPLETE:
46
- 'x verify merge parts/*.json --json # after every CI job uploaded its part',
47
- X_VERIFY_MERGE_INPUT: 'x verify --only unit --json > part.json # one document per part',
48
- X_VERIFY_STEP_TIMEOUT:
49
- 'x verify --only unit --json # reproduce the step alone; one that needs longer states it under "stepTimeoutMs" in x.verify.json',
50
- X_COVERAGE_BELOW_FLOOR:
51
- 'x verify --only unit --json # names the ten files losing the most lines; cover the worst with a test beside it',
52
- X_COVERAGE_FLOOR_UNSTATED:
53
- 'x verify --only unit --json # the finding carries the measured numbers and the "coverage" line to add to x.verify.json',
54
- X_COVERAGE_FLOOR_STALE:
55
- 'x verify --only unit --json # the finding carries the measured numbers; raise "coverage" in x.verify.json to them',
56
45
  // Unthrown since `--worker` was deleted, and kept only because this record is typed over every
57
46
  // registered code: `--shard i/n` is the one way to rerun a slice.
58
47
  X_TEST_SHARD_FAILED: 'x verify --only unit --shard 1/2 --json',
@@ -73,6 +62,8 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
73
62
  'x i18n check --json # the finding names both copies and the package.json to pin',
74
63
  // `x shot` and the `ui.*` tools: their own family, in `mcp-errors-shot.ts`.
75
64
  ...SHOT_FIXES,
65
+ // The gate's floor, run and split: their own family, in `mcp-errors-verify.ts`.
66
+ ...VERIFY_FIXES,
76
67
  X_GH_UNAVAILABLE: 'gh auth login # install first from https://cli.github.com',
77
68
  X_GH_NOT_AUTHENTICATED: 'gh auth login',
78
69
  X_GH_COMMAND_FAILED: 'x ci --json # the finding carries the gh invocation that failed',
@@ -90,11 +81,6 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
90
81
  X_TYPECHECK_FAILED: 'bunx tsc -p . --pretty false',
91
82
  X_LINT_FAILED: 'bunx biome check .',
92
83
  X_TEST_FAILED: 'x test --json # the finding carries the exact bun test invocation that failed',
93
- // The same two edits `vanishedSuiteFinding` names, verbatim, so both surfaces of this code hand
94
- // an agent one instruction. Neither edit is scripted here on purpose: a command that rewrites
95
- // x.verify.json is the gate editing its own ratchet, which is the false green the floor closes.
96
- X_VERIFY_SUITE_VANISHED:
97
- 'x verify --json # restore the suite, or drop its name from x.verify.json in the commit that says why',
98
84
  X_FILE_TOO_LONG: 'x verify --json # the finding names the file to split',
99
85
  X_PACKAGE_SHAPE: 'bun run verify --json # every finding carries its own new-package.ts command',
100
86
  // NOT `bunx tsc -b`: an unreferenced package is one `tsc -b` skips by definition, so it exits 0
@@ -350,8 +336,6 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
350
336
  'export CHROME_PATH=/usr/bin/google-chrome # any Chrome, Chromium or Edge binary; or drop og.capture from the route; the gate build passes --no-capture and needs none',
351
337
  X_IMAGE_SOURCE_UNREADABLE:
352
338
  "x build --target static --json # lists the export; put the file under apps/web/site/assets/ and pass asset('assets/<file>') as src, or give an absolute https:// URL",
353
- X_VERIFY_SKIPS_OVER_CEILING:
354
- 'x test unit --json # then set what the skipped tests need, or raise skipCeiling in x.verify.json with the reason in the diff',
355
339
  X_ASSET_VARIANT_UNDECLARED:
356
340
  "responsiveImage({ src: asset('assets/hero.png'), width, height, alt }) # no widths/formats override for a site asset; an upload under /media answers any width",
357
341
  X_NEW_SHAPE_GENERATE_FAILED:
@@ -402,6 +386,13 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
402
386
  'x verify --only drift --json # each X_DB_INDEX_UNDECLARED warning names the index: its DROP INDEX CONCURRENTLY IF EXISTS "<name>"; goes in a new hand-written migration (-- transaction: false), or declare it in the entity\'s indexes: [...] and x db gen "<change>"',
403
387
  X_SHIPPED_GUARD_MISSING:
404
388
  "x doctor --json # each X_SHIPPED_GUARD_MISSING warning's fix is the command that writes its guard, then x verify --only boundaries --json",
389
+ X_DEV_LOG_ABSENT:
390
+ 'x dev --json # the dev server writes the dev log as it boots; then: x logs tail --json',
391
+ X_DEV_PEER_REFUSED:
392
+ 'x doctor --json # /_x answers a loopback peer only: open it on the machine the dev server runs on, or forward the port with ssh -L',
393
+ X_PROFILE_ROUTE_FAILED: 'x routes --json',
394
+ X_ROWS_SLICE_ENTITY:
395
+ 'x help g --json # then generate a job with the name and feature the finding names, and declare exportRows/importRows in it over the table that entity.ts declares',
405
396
  };
406
397
 
407
398
  const isCliCode = (code: string): code is CliErrorCode =>
@@ -0,0 +1,121 @@
1
+ // `logs.tail`'s reader, split from `mcp-host.ts` at its size ceiling: which file a tail reads, the
2
+ // end-first bounded read, and a role's tail out of the one dev log `x dev` writes for every role.
3
+ // `x logs tail` (`cmd-logs.ts`) reads through the same path rule and reader.
4
+
5
+ // why: Bun exposes no path API; the dev log and a per-role log are joined under the state dir.
6
+ import { join } from 'node:path';
7
+ import { isRole, ROLES, stringField, UltimateError } from '@ultimat3/core';
8
+ import { DEV_LOG_FILENAME } from './dev-log';
9
+ import { BadFlagError } from './errors';
10
+
11
+ /**
12
+ * The log `logs.tail` reads. `role` is joined into a path, so it must BE a role: `'../x'` named a
13
+ * file outside the state directory. The tool's schema lists the roles, but a schema is advice to a
14
+ * client and this is the line that opens the file.
15
+ */
16
+ export function logTailPath(dir: string, role: string | undefined): string {
17
+ if (role === undefined) return join(dir, DEV_LOG_FILENAME);
18
+ if (!isRole(role)) {
19
+ throw new BadFlagError({
20
+ flag: 'role',
21
+ command: 'mcp serve',
22
+ reason: `logs.tail's role "${role}" is not a runtime role`,
23
+ fix: `logs.tail({ role: 'web' }) # role is one of ${ROLES.join(', ')}; none reads dev.log`,
24
+ });
25
+ }
26
+ return join(dir, 'logs', `${role}.log`);
27
+ }
28
+
29
+ /** The first window read from a log's end; each further one is four times wider. */
30
+ const TAIL_WINDOW_BYTES = 64 * 1024;
31
+ /** The most a tail ever reads: past this, lines that long are cut rather than the log loaded. */
32
+ const TAIL_MAX_BYTES = 1024 * 1024;
33
+
34
+ /** What `tailLines` reads of a file: its size and a byte range — `Bun.file`'s own shape. */
35
+ export interface TailSource {
36
+ readonly size: number;
37
+ slice(start: number, end: number): { text(): Promise<string> };
38
+ }
39
+
40
+ /**
41
+ * The last `lines` lines that `keep` accepts, read from the END in widening windows. `file.text()`
42
+ * loaded the whole `dev.log` per call, and an agent calls this in a loop against a log `x dev`
43
+ * never rotates. A window that does not start at byte 0 drops its first line: it may be partial,
44
+ * and may begin mid-character. A filtered tail answers what the last 1 MiB holds.
45
+ */
46
+ export async function tailLines(
47
+ file: TailSource,
48
+ lines: number,
49
+ keep: (line: string) => boolean = () => true,
50
+ ): Promise<readonly string[]> {
51
+ let window = TAIL_WINDOW_BYTES;
52
+ for (;;) {
53
+ const start = Math.max(0, file.size - Math.min(window, TAIL_MAX_BYTES));
54
+ const all = (await file.slice(start, file.size).text()).trimEnd().split('\n');
55
+ const whole = (start === 0 ? all : all.slice(1)).filter(keep);
56
+ if (whole.length >= lines || start === 0) return whole.slice(-lines);
57
+ // At the cap with no newline inside it, the one line there is longer than the cap: answered
58
+ // cut, never as `[]` — an empty tail reads as an empty log.
59
+ if (window >= TAIL_MAX_BYTES) {
60
+ return (whole.length === 0 ? all.filter(keep) : whole).slice(-lines);
61
+ }
62
+ window *= 4;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * The runtime role a dev-log line names, when it names one. Core puts the context's `role` on
68
+ * every line written inside a request or a job (`context.ts`'s logger fields); a line written
69
+ * outside any context — the boot, a loop's own warning — names none and belongs to no role's tail.
70
+ */
71
+ export function lineRole(line: string): string | undefined {
72
+ let parsed: unknown;
73
+ try {
74
+ parsed = JSON.parse(line);
75
+ } catch {
76
+ return undefined;
77
+ }
78
+ // `stringField`, the total read: a parsed line is a stranger's object, never `in`-guarded then read.
79
+ const role = stringField(parsed, 'role');
80
+ return role !== undefined && isRole(role) ? role : undefined;
81
+ }
82
+
83
+ /** A log on disk: its size and byte ranges, or nothing. `Bun.file` unless a test hands one in. */
84
+ export type LogOpener = (path: string) => Promise<TailSource | undefined>;
85
+
86
+ export const openLog: LogOpener = async (path) => {
87
+ const file = Bun.file(path);
88
+ return (await file.exists()) ? file : undefined;
89
+ };
90
+
91
+ /** What a tail read: the file it came from, and its last lines. */
92
+ export interface LogTail {
93
+ readonly path: string;
94
+ readonly lines: readonly string[];
95
+ }
96
+
97
+ /**
98
+ * `logs.tail` and `x logs tail`, one answer: a role's own `logs/<role>.log` when one was written
99
+ * there (a role run with its output sent to it), else that role's lines of `dev.log` — `x dev` runs
100
+ * every role in one process and one log. With neither, `x dev` is the process that writes one.
101
+ */
102
+ export async function readLogTail(
103
+ dir: string,
104
+ lines: number,
105
+ role: string | undefined,
106
+ open: LogOpener = openLog,
107
+ ): Promise<LogTail> {
108
+ const ownPath = logTailPath(dir, role);
109
+ const own = await open(ownPath);
110
+ if (own !== undefined) return { path: ownPath, lines: await tailLines(own, lines) };
111
+ const devPath = join(dir, DEV_LOG_FILENAME);
112
+ const dev = role === undefined ? undefined : await open(devPath);
113
+ if (dev === undefined) {
114
+ throw new UltimateError({
115
+ code: 'X_DEV_LOG_ABSENT',
116
+ cause: `${devPath} does not exist yet: x dev writes it, every role's lines included${role === undefined ? '' : `, and no ${ownPath} was written either`}`,
117
+ fix: 'x dev',
118
+ });
119
+ }
120
+ return { path: devPath, lines: await tailLines(dev, lines, (line) => lineRole(line) === role) };
121
+ }
package/src/mcp-host.ts CHANGED
@@ -9,11 +9,7 @@
9
9
  import { join } from 'node:path';
10
10
  import {
11
11
  agentActor,
12
- isRole,
13
12
  isUltimateError,
14
- NotImplementedError,
15
- ROLES,
16
- renderFixShellArg,
17
13
  renderThrowable,
18
14
  retryMemo,
19
15
  UltimateError,
@@ -46,11 +42,11 @@ import { loadAppGraph, resolveNode } from './cmd-graph-load';
46
42
  import { declareDevEnvironment, needsDevEnvironmentDeclaration } from './dev-environment';
47
43
  import { liveDevLock } from './dev-lock';
48
44
  import { loadCodeFixes } from './error-fixes';
49
- import { BadFlagError } from './errors';
50
45
  import type { Runner } from './exec';
51
46
  import { assertExplainTarget, devNotRunning, narrowVerify, searchDocs } from './mcp-agent-host';
52
47
  import { databaseTarget } from './mcp-db-target';
53
48
  import { explainErrorCode } from './mcp-errors';
49
+ import { readLogTail } from './mcp-host-logs';
54
50
  import { type ShellRunInput, shellRunner, shellTests, shellVerify } from './mcp-host-shell';
55
51
  import { requestStatements } from './mcp-request-statements';
56
52
  import { type UiCapabilities, uiCapabilities } from './mcp-ui';
@@ -122,10 +118,13 @@ export function lazyServices(input: DevHostInput): LazyServices {
122
118
  // A boot started after close() would hold the PGlite data directory for the life of the
123
119
  // process with nobody left to stop it — the host is closed, so the call is the bug.
124
120
  if (closed) {
125
- throw new NotImplementedError({
121
+ // Core's code for work that arrives after shutdown: nothing is missing from this build.
122
+ throw new UltimateError({
123
+ code: 'X_DRAINING',
126
124
  cause:
127
- 'an MCP tool that needs the database after the host closed is not implemented in this build',
128
- fix: 'x mcp serve --transport stdio # keep the host open for the whole session',
125
+ 'an MCP tool needed the database after this host closed, and a closed host is not reopened',
126
+ fix: 'x mcp serve --transport stdio # a new session: a closed host is replaced, never reused',
127
+ retry: 'terminal',
129
128
  });
130
129
  }
131
130
  return boot.get();
@@ -212,54 +211,8 @@ export function migrateFailed(error: unknown): UltimateError {
212
211
  });
213
212
  }
214
213
 
215
- /**
216
- * The log `logs.tail` reads. `role` is joined into a path, so it must BE a role: `'../x'` named a
217
- * file outside the state directory. The tool's schema lists the roles, but a schema is advice to a
218
- * client and this is the line that opens the file.
219
- */
220
- export function logTailPath(dir: string, role: string | undefined): string {
221
- if (role === undefined) return join(dir, 'dev.log');
222
- if (!isRole(role)) {
223
- throw new BadFlagError({
224
- flag: 'role',
225
- command: 'mcp serve',
226
- reason: `logs.tail's role "${role}" is not a runtime role`,
227
- fix: `logs.tail({ role: 'web' }) # role is one of ${ROLES.join(', ')}; none reads dev.log`,
228
- });
229
- }
230
- return join(dir, 'logs', `${role}.log`);
231
- }
232
-
233
- /** The first window read from a log's end; each further one is four times wider. */
234
- const TAIL_WINDOW_BYTES = 64 * 1024;
235
- /** The most a tail ever reads: past this, lines that long are cut rather than the log loaded. */
236
- const TAIL_MAX_BYTES = 1024 * 1024;
237
-
238
- /** What `tailLines` reads of a file: its size and a byte range — `Bun.file`'s own shape. */
239
- export interface TailSource {
240
- readonly size: number;
241
- slice(start: number, end: number): { text(): Promise<string> };
242
- }
243
-
244
- /**
245
- * The last `lines` lines, read from the END in widening windows. `file.text()` loaded the whole
246
- * `dev.log` per call, and an agent calls this in a loop against a log `x dev` never rotates. A
247
- * window that does not start at byte 0 drops its first line: it may be partial, and may begin
248
- * mid-character.
249
- */
250
- export async function tailLines(file: TailSource, lines: number): Promise<readonly string[]> {
251
- let window = TAIL_WINDOW_BYTES;
252
- for (;;) {
253
- const start = Math.max(0, file.size - Math.min(window, TAIL_MAX_BYTES));
254
- const all = (await file.slice(start, file.size).text()).trimEnd().split('\n');
255
- const whole = start === 0 ? all : all.slice(1);
256
- if (whole.length >= lines || start === 0) return whole.slice(-lines);
257
- // At the cap with no newline inside it, the one line there is longer than the cap: answered
258
- // cut, never as `[]` — an empty tail reads as an empty log.
259
- if (window >= TAIL_MAX_BYTES) return (whole.length === 0 ? all : whole).slice(-lines);
260
- window *= 4;
261
- }
262
- }
214
+ // `logs.tail`'s reader lives in `mcp-host-logs.ts`; re-exported for `x logs tail` and the tests.
215
+ export { lineRole, logTailPath, type TailSource, tailLines } from './mcp-host-logs';
263
216
 
264
217
  function capabilities(
265
218
  input: DevHostInput,
@@ -343,23 +296,9 @@ function capabilities(
343
296
  // `x test` itself, never a second test path: the files, batches and env the shell gets.
344
297
  runTests: (filter: string | undefined) => shellTests(shell, filter),
345
298
 
346
- async tailLogs(lines: number, role: string | undefined) {
347
- const dir = lazy.services.stateDir;
348
- const path = logTailPath(dir, role);
349
- const file = Bun.file(path);
350
- if (!(await file.exists())) {
351
- // A log on disk is the only honest source: `x dev` tees every line of its own to
352
- // `dev.log` (`dev-log.ts`), so starting it is the fix. No role writes a log of its own.
353
- throw new NotImplementedError({
354
- cause: `logs.tail without ${path} is not implemented in this build`,
355
- fix:
356
- role === undefined
357
- ? 'x dev'
358
- : `mkdir -p ${renderFixShellArg(join(dir, 'logs'), '<the logs dir of the path the cause names>')} && x dev --role ${role} > ${path} 2>&1`,
359
- });
360
- }
361
- return tailLines(file, lines);
362
- },
299
+ // A role's own log when one was written, else its lines of the dev log (`mcp-host-logs.ts`).
300
+ tailLogs: async (lines: number, role: string | undefined) =>
301
+ (await readLogTail(lazy.services.stateDir, lines, role)).lines,
363
302
 
364
303
  async readManifest() {
365
304
  const file = Bun.file(join(root, MANIFEST_FILENAME));
@@ -0,0 +1,19 @@
1
+ // The suite floor's rows of the CLI catalog (`messages.ts` composes them): why a step ran no
2
+ // check, and the strict-floor notices. Data only — `msg()` is the one lookup.
3
+
4
+ export const FLOOR_MESSAGES = {
5
+ // One line per step that ran no check (`verify-skip-reason.ts`), under the step table.
6
+ 'cli.verify.skip.line': 'skipped: {step} — {reason}',
7
+ 'cli.verify.skip.noTypedFiles': 'no *.{type}.test.ts file in this tree',
8
+ 'cli.verify.skip.noEval': 'not an app root, and no *.eval.test.ts file',
9
+ 'cli.verify.skip.noApp': 'no {file} here, so there is no app to load',
10
+ 'cli.verify.skip.noPackages': 'no workspace package under packages/',
11
+ 'cli.verify.skip.noManifest': 'no {file} committed, so there is no contract to diff',
12
+ 'cli.verify.skip.noRoadmap': 'no {file} here',
13
+ 'cli.verify.skip.nothing': 'the step found nothing to check here',
14
+ // Without `strict`, a warning and never red: an existing app meets it on `main` (X_BREAKING_ON_MAIN).
15
+ 'cli.verify.unwaived':
16
+ 'not strict: {names} ran no check here — give each a suite, or a "skip" why in x.verify.json, then set "strict": true',
17
+ // A `skip` why over a step that ran: the reason is stale, and only a commit can drop it.
18
+ 'cli.verify.waiverStale': 'x.verify.json "skip" excuses {step}, which ran here — drop its entry',
19
+ } as const;
@@ -0,0 +1,10 @@
1
+ // The `x status` rows of the CLI catalog (`messages.ts` composes them): what the running
2
+ // deployment records about its builds, and which roles record nothing. Data only.
3
+
4
+ export const STATUS_MESSAGES = {
5
+ 'cli.status.summary': '{workers} live worker(s) read, {origins} origin(s) sampled',
6
+ 'cli.status.workers': 'workers: {count} live · builds {builds}',
7
+ 'cli.status.origin': '{origin}: {samples} sample(s) · builds {builds} · status {statuses}',
8
+ 'cli.status.unrecorded':
9
+ 'no fleet-wide record of {roles}: pass each one’s health origin to --url to read its build',
10
+ } as const;
package/src/messages.ts CHANGED
@@ -5,10 +5,12 @@
5
5
 
6
6
  import { CLIENT_MESSAGES } from './messages-client';
7
7
  import { DB_MESSAGES } from './messages-db';
8
+ import { FLOOR_MESSAGES } from './messages-floor';
8
9
  import { GATE_MESSAGES } from './messages-gate';
9
10
  import { OPS_MESSAGES } from './messages-ops';
10
11
  import { REPRO_MESSAGES } from './messages-repro';
11
12
  import { SHOT_MESSAGES } from './messages-shot';
13
+ import { STATUS_MESSAGES } from './messages-status';
12
14
  import { UPGRADE_MESSAGES } from './messages-upgrade';
13
15
 
14
16
  const CATALOG = {
@@ -73,6 +75,12 @@ const CATALOG = {
73
75
  'cli.dev.roles': ' roles {roles}',
74
76
  'cli.dev.panels': ' panels {panels}',
75
77
  'cli.dev.introspect': ' introspect {url}',
78
+ 'cli.dev.introspectUnreachable':
79
+ ' introspect none on {url} — /_x answers loopback only; x dev --host 0.0.0.0 keeps loopback bound beside it',
80
+ 'cli.dev.tls':
81
+ ' tls cert {path} — trust it once: curl --cacert {path}, or add it to the OS keychain',
82
+ 'cli.profile.done': 'profiled {route}: {runs} run(s), {samples} sample(s), status {status}',
83
+ 'cli.profile.frame': ' {percent}% {name} {at}',
76
84
  'cli.dev.manifest': ' manifest {path}',
77
85
  'cli.dev.mcp': ' mcp POST {path}',
78
86
  // `x stop` (`cmd-stop.ts`): the lock's holder, and only it.
@@ -110,6 +118,10 @@ const CATALOG = {
110
118
  // `x doctor`'s warnings: beside the verdict on `main`, red on `next` (`doctor-warnings.ts`).
111
119
  'cli.doctor.warnings': '{count} warning(s) — not in the verdict until the next major:',
112
120
  'cli.doctor.warning': ' {code}: {cause} — fix: {fix}',
121
+ // `x doctor`'s browser report (`doctor-browser.ts`): the e2e driver's Chrome, or how to get one.
122
+ 'cli.doctor.browserFound': 'e2e browser: {path}',
123
+ 'cli.doctor.browserMissing':
124
+ 'e2e browser: none found, so every e2eTest skips — install one: {install}',
113
125
  'cli.docs.code': '{code} is an error code — x errors explain answers it',
114
126
  'cli.docs.exports': 'exports: {list}',
115
127
  'cli.docs.installed': 'installed: {list}',
@@ -280,6 +292,13 @@ const CATALOG = {
280
292
  'cli.secrets.dropped':
281
293
  'dropped retired master key {kid} from {path} — {count} retired key(s) still declared',
282
294
  'cli.secrets.ring': 'retired master key(s) that still open sealed values: {kids}',
295
+ // `verify-live.ts`: the `live` step's warnings about the test stack it found, started or could not.
296
+ 'cli.verify.services.started':
297
+ 'this run started {services} ({command}) — left running for the next run; stop it with {stop}',
298
+ 'cli.verify.services.unavailable': '{code}: {cause} — fix: {fix}',
299
+ // `upgrade-report.ts`: a guard the tree breaks, kept at its measured count (`upgrade-guards.ts`).
300
+ 'cli.upgrade.guardBaselined':
301
+ 'guard installed at its baseline: guards/{name}.ts reports {count} finding(s), now "guardBaseline" in x.verify.json — fix them and lower it, it only falls',
283
302
  ...CLIENT_MESSAGES,
284
303
  ...REPRO_MESSAGES,
285
304
  ...DB_MESSAGES,
@@ -287,6 +306,8 @@ const CATALOG = {
287
306
  ...UPGRADE_MESSAGES,
288
307
  ...GATE_MESSAGES,
289
308
  ...OPS_MESSAGES,
309
+ ...FLOOR_MESSAGES,
310
+ ...STATUS_MESSAGES,
290
311
  } as const;
291
312
 
292
313
  export type MessageKey = keyof typeof CATALOG;