@ultimat3/cli 31.26.0 → 31.28.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.
- package/CLAUDE.md +47 -37
- package/README.md +19 -8
- package/package.json +29 -29
- package/src/app-manifest.ts +6 -1
- package/src/app-mcp.ts +17 -3
- package/src/cmd-cache-spec.ts +5 -2
- package/src/cmd-db-spec.ts +2 -3
- package/src/cmd-db.ts +0 -2
- package/src/cmd-deploy-verify-sample.ts +93 -0
- package/src/cmd-deploy-verify.ts +2 -41
- package/src/cmd-dev-spec.ts +15 -1
- package/src/cmd-dev.ts +31 -4
- package/src/cmd-doctor.ts +15 -4
- package/src/cmd-exercise-spec.ts +7 -1
- package/src/cmd-exercise.ts +22 -10
- package/src/cmd-generate.ts +2 -0
- package/src/cmd-jobs-spec.ts +3 -6
- package/src/cmd-jobs.ts +1 -7
- package/src/cmd-logs-spec.ts +2 -1
- package/src/cmd-logs.ts +9 -28
- package/src/cmd-planned.ts +11 -45
- package/src/cmd-profile-frames.ts +99 -0
- package/src/cmd-profile-spec.ts +24 -0
- package/src/cmd-profile.ts +164 -0
- package/src/cmd-repro-spec.ts +13 -1
- package/src/cmd-repro.ts +37 -5
- package/src/cmd-status-sample.ts +57 -0
- package/src/cmd-status-spec.ts +30 -0
- package/src/cmd-status.ts +108 -0
- package/src/cmd-token-spec.ts +5 -2
- package/src/cmd-token.ts +7 -3
- package/src/cmd-upgrade-codemods.ts +71 -0
- package/src/cmd-upgrade-spec.ts +19 -5
- package/src/cmd-upgrade.ts +91 -34
- package/src/codemods/agents-dev-mcp.ts +50 -0
- package/src/codemods/authenticator-session-refusal.ts +214 -0
- package/src/codemods/biome-no-default-export.ts +58 -0
- package/src/codemods/bunfig-island-coverage.ts +33 -0
- package/src/codemods/chart-dashboard.ts +73 -0
- package/src/codemods/ci-e2e-browser-stock.ts +75 -0
- package/src/codemods/ci-e2e-browser.ts +63 -0
- package/src/codemods/codemod.ts +58 -0
- package/src/codemods/define-error-leaf.ts +73 -0
- package/src/codemods/docs-ci-parts.ts +65 -0
- package/src/codemods/docs-gate-prose.ts +53 -0
- package/src/codemods/docs-island-rows.ts +31 -0
- package/src/codemods/docs-shipped-guards.ts +100 -0
- package/src/codemods/docs-test-services.ts +62 -0
- package/src/codemods/engine-diff.ts +104 -0
- package/src/codemods/engine-edits.ts +111 -0
- package/src/codemods/engine-fs.ts +95 -0
- package/src/codemods/engine.ts +191 -0
- package/src/codemods/format-edited-hook-3122.ts +28 -0
- package/src/codemods/format-edited-hook.ts +152 -0
- package/src/codemods/helm-alerts-objective.ts +105 -0
- package/src/codemods/helm-alerts-stock.ts +108 -0
- package/src/codemods/index.ts +56 -0
- package/src/codemods/metrics-probe-healthz.ts +47 -0
- package/src/codemods/pending.ts +36 -0
- package/src/codemods/repro-gitignore.ts +40 -0
- package/src/codemods/runtime-pin-lines.ts +109 -0
- package/src/codemods/runtime-pin.ts +116 -0
- package/src/codemods/solid-floor.ts +63 -0
- package/src/codemods/test-ports.ts +86 -0
- package/src/codemods/test-suites.ts +37 -0
- package/src/codemods/theme-toggle-mount-over.ts +70 -0
- package/src/codemods/vendored-guards.ts +186 -0
- package/src/codemods/verify-floor-skips.ts +88 -0
- package/src/codemods/verify-floor-steps.ts +90 -0
- package/src/coverage-island.ts +121 -0
- package/src/coverage-lcov.ts +49 -5
- package/src/coverage-remap.ts +146 -0
- package/src/db-replay-engine-prepared.ts +66 -0
- package/src/db-replay-engine-template.ts +156 -0
- package/src/db-replay-engine.ts +4 -0
- package/src/db-replay-scratch-reap.ts +54 -0
- package/src/deploy-verify-flags.ts +9 -2
- package/src/deploy-verify-grade.ts +10 -3
- package/src/dev-boot.ts +14 -1
- package/src/dev-dashboard-guard.ts +57 -10
- package/src/dev-host.ts +46 -0
- package/src/dev-tls-cache.ts +103 -0
- package/src/dev-tls-der.ts +69 -0
- package/src/dev-tls.ts +120 -0
- package/src/doctor-advisory-floors.ts +113 -0
- package/src/doctor-browser.ts +60 -0
- package/src/doctor-guards.ts +39 -86
- package/src/doctor-superseded.ts +67 -0
- package/src/error-codes-doctor.ts +12 -4
- package/src/error-codes-verify.ts +47 -0
- package/src/error-codes.ts +20 -23
- package/src/exercise-database.ts +47 -9
- package/src/exercise-push-device.ts +51 -0
- package/src/exercise-route-api.ts +74 -0
- package/src/exercise-routes.ts +14 -5
- package/src/exercise-services.ts +3 -1
- package/src/exercise-shard-flag.ts +47 -0
- package/src/fix-command.ts +2 -2
- package/src/generate-factories.ts +5 -11
- package/src/generate-feature-required.ts +9 -4
- package/src/generate-files.ts +26 -7
- package/src/generate-kinds.ts +5 -1
- package/src/guards-built-in-codes.ts +36 -0
- package/src/guards-built-in-refusal.ts +25 -0
- package/src/guards-built-in.ts +134 -0
- package/src/guards-materialize.ts +42 -0
- package/src/guards-paths.ts +37 -0
- package/src/guards-shipped-names.ts +38 -0
- package/src/guards-vendored.ts +73 -0
- package/src/guards.ts +105 -34
- package/src/index.ts +10 -0
- package/src/island-bundle-options.ts +48 -0
- package/src/island-bundle.ts +18 -46
- package/src/island-link.ts +5 -0
- package/src/island-outputs.ts +5 -0
- package/src/lint-findings.ts +3 -3
- package/src/mcp-errors-verify.ts +35 -0
- package/src/mcp-errors.ts +21 -20
- package/src/mcp-host-logs.ts +121 -0
- package/src/mcp-host.ts +12 -73
- package/src/measure-scope.ts +23 -3
- package/src/messages-floor.ts +19 -0
- package/src/messages-repro.ts +16 -2
- package/src/messages-status.ts +10 -0
- package/src/messages-upgrade.ts +15 -0
- package/src/messages.ts +22 -1
- package/src/registry.ts +4 -0
- package/src/repro-archive-collect.ts +161 -0
- package/src/repro-archive-write.ts +96 -0
- package/src/repro-archive.ts +161 -0
- package/src/repro-bundle.ts +8 -16
- package/src/repro-errors.ts +14 -2
- package/src/repro-framework.ts +53 -0
- package/src/repro-parse.ts +87 -0
- package/src/repro-redact.ts +218 -0
- package/src/repro-scrub.ts +257 -0
- package/src/role-start-types.ts +7 -0
- package/src/role-start.ts +4 -0
- package/src/serve-boot.ts +7 -1
- package/src/serve-env-tls.ts +57 -0
- package/src/solid-loader.ts +27 -10
- package/src/superseded-match.ts +87 -0
- package/src/superseded.ts +84 -0
- package/src/templates/bun-image.ts +48 -0
- package/src/templates/generate-export-rows.ts +136 -0
- package/src/templates/generate-import-rows.ts +186 -0
- package/src/templates/generate-rows-slice.ts +95 -0
- package/src/templates/github/ci.yml.ts +5 -1
- package/src/templates/guard-released-forms.ts +112 -0
- package/src/templates/guard-runtime-pin-test.ts +54 -0
- package/src/templates/guard-runtime-pin.ts +189 -0
- package/src/templates/scaffold-claude-agents.ts +6 -6
- package/src/templates/scaffold-claude-commands.ts +1 -1
- package/src/templates/scaffold-claude-hook.ts +18 -8
- package/src/templates/scaffold-claude.ts +2 -2
- package/src/templates/scaffold-db-package.ts +3 -0
- package/src/templates/scaffold-docs.ts +34 -30
- package/src/templates/scaffold-guards.ts +73 -39
- package/src/templates/scaffold-repo.ts +4 -8
- package/src/templates/scaffold-site.ts +4 -1
- package/src/templates/scaffold-suites.ts +72 -0
- package/src/templates/scaffold-test-services.ts +35 -10
- package/src/templates/scaffold-verify-floor.ts +53 -31
- package/src/templates/shapes/api.ts +4 -0
- package/src/templates/slice-foundation.ts +3 -3
- package/src/unthrown-codes.ts +3 -1
- package/src/upgrade-bun-floor.ts +4 -0
- package/src/upgrade-clean-tree.ts +54 -0
- package/src/upgrade-gate-codemods-install.ts +40 -0
- package/src/upgrade-gate-codemods.ts +151 -0
- package/src/upgrade-gate.ts +44 -7
- package/src/upgrade-guards-baseline.ts +43 -0
- package/src/upgrade-guards.ts +37 -2
- package/src/upgrade-lock.ts +118 -0
- package/src/upgrade-plan.ts +2 -1
- package/src/upgrade-report-codemods.ts +54 -0
- package/src/upgrade-report.ts +55 -27
- package/src/upgrade-signals.ts +91 -0
- package/src/upgrade-unfinished.ts +61 -0
- package/src/verify-coverage-run.ts +42 -11
- package/src/verify-e2e.ts +115 -4
- package/src/verify-floor.ts +27 -0
- package/src/verify-guard-baseline.ts +109 -0
- package/src/verify-live.ts +72 -0
- package/src/verify-merge-skips.ts +51 -0
- package/src/verify-merge.ts +36 -2
- package/src/verify-run.ts +48 -7
- package/src/verify-services.ts +287 -0
- package/src/verify-skip-reason.ts +53 -0
- package/src/verify-strict.ts +108 -0
- package/src/verify-test-command.ts +129 -0
- package/src/verify-tests.ts +39 -126
- package/types/babel-modules.d.ts +2 -0
- package/wiki/CLI-Reference.md +200 -27
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Entities-And-Migrations.md +1 -1
- package/wiki/Interface-Rules.md +17 -8
- package/wiki/Jobs-And-Workflows.md +3 -3
- package/wiki/Known-Gaps.md +5 -1
- package/wiki/MCP-And-AI.md +1 -1
- package/wiki/Observability.md +1 -0
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Project-Layout.md +4 -4
- package/wiki/Troubleshooting.md +3 -3
- package/wiki/Tutorial-05-Deploy-Free.md +2 -2
- package/wiki/Upgrading.md +8 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// What a caller may ask of `buildIslands`: one island, the split, the cache, the realtime answer,
|
|
2
|
+
// Solid as a vendor, and a coverage build. Split from `island-bundle.ts`, which builds.
|
|
3
|
+
|
|
4
|
+
export interface BuildIslandsOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Build ONE island, named app-root-relative — the whole option surface. A test that mounts a
|
|
7
|
+
* single island otherwise pays every OTHER island's Babel pass and `Bun.build` on every file,
|
|
8
|
+
* and the reference app is the one that feels it.
|
|
9
|
+
*
|
|
10
|
+
* Optional, and it must stay optional: `buildIslands` is on `@ultimat3/cli`'s public surface and
|
|
11
|
+
* `@ultimat3/testing`'s `IslandBuilder` satisfies it STRUCTURALLY as `(root: string) => …`, which
|
|
12
|
+
* is what keeps the `cli -> testing` edge pointing the one legal way.
|
|
13
|
+
*/
|
|
14
|
+
readonly only?: string;
|
|
15
|
+
/**
|
|
16
|
+
* One split build over every island (`app.config.ts`'s `islands.sharedChunks`, off by default),
|
|
17
|
+
* or one build per route group (`island-groups.ts`). Passed, it overrides the app's config — the
|
|
18
|
+
* seam a test asks both questions of one fixture through.
|
|
19
|
+
*/
|
|
20
|
+
readonly sharedChunks?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Reuse a group's output from `.x/cache/islands/` while every file it read is unchanged
|
|
23
|
+
* (`island-group-cache.ts`) — on by default. `false` is the seam a determinism test builds
|
|
24
|
+
* through: a reused byte string proves nothing about the bundler that emitted it.
|
|
25
|
+
*/
|
|
26
|
+
readonly reuse?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the app persists records (`appPersistsRecords`), asked only by a group one of whose
|
|
29
|
+
* islands reaches realtime, and once per call. `x dev` builds islands BESIDE the app load
|
|
30
|
+
* (`buildGeneration`), so it passes the answer the registry gives once the load settles; read
|
|
31
|
+
* any earlier it is the empty registry's `undefined`, and every reader islands is held. Absent,
|
|
32
|
+
* the registry is read as it stands: the caller loaded the app first.
|
|
33
|
+
*/
|
|
34
|
+
readonly persists?: () => Promise<boolean | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Solid as ONE shared output every island imports (`island-vendor.ts`), off by default. Measured
|
|
37
|
+
* As of 2026-11-12 (Bun 1.4.4, solid-js 1.9.17): each island inlines a tree-shaken ~14 kB of
|
|
38
|
+
* Solid, the whole vendor is 48,083 B, so every Solid route of the three tracked apps grew
|
|
39
|
+
* +33,572…+38,769 B with it on; it pays only where a page renders four or more Solid islands
|
|
40
|
+
* that are built apart.
|
|
41
|
+
*/
|
|
42
|
+
readonly vendorSolid?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* A build for `mountIsland` under a coverage run: whitespace kept, Babel's lines kept, the map on
|
|
45
|
+
* every chunk — so the chunk's lines count for the island's source. Never cached, never shipped.
|
|
46
|
+
*/
|
|
47
|
+
readonly coverage?: boolean;
|
|
48
|
+
}
|
package/src/island-bundle.ts
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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(),
|
package/src/island-link.ts
CHANGED
|
@@ -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);
|
package/src/island-outputs.ts
CHANGED
|
@@ -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));
|
package/src/lint-findings.ts
CHANGED
|
@@ -64,7 +64,7 @@ const editFinding = (diagnostic: Diagnostic): Finding => {
|
|
|
64
64
|
return {
|
|
65
65
|
code: 'X_LINT_FAILED',
|
|
66
66
|
cause: `${place} ${category}: ${message}`,
|
|
67
|
-
fix: `bunx biome check ${quoteArg(path)} # ${category}: edit ${commentSafe(place)}, ${commentSafe(message)}`,
|
|
67
|
+
fix: `bunx @biomejs/biome check ${quoteArg(path)} # ${category}: edit ${commentSafe(place)}, ${commentSafe(message)}`,
|
|
68
68
|
docs: ERROR_DOCS_URL,
|
|
69
69
|
at: path,
|
|
70
70
|
};
|
|
@@ -78,7 +78,7 @@ const writeFinding = (diagnostics: readonly Diagnostic[]): Finding => {
|
|
|
78
78
|
code: 'X_LINT_FAILED',
|
|
79
79
|
cause: places.join('; '),
|
|
80
80
|
// Each path through `quoteArg`, joined after: one command, every file one argument.
|
|
81
|
-
fix: ['bunx biome check --write', ...paths.map(quoteArg)].join(' '),
|
|
81
|
+
fix: ['bunx @biomejs/biome check --write', ...paths.map(quoteArg)].join(' '),
|
|
82
82
|
docs: ERROR_DOCS_URL,
|
|
83
83
|
...(paths.length === 1 ? { at: paths[0] } : {}),
|
|
84
84
|
};
|
|
@@ -119,7 +119,7 @@ export function lintOutcome(result: ExecResult): StepOutcome {
|
|
|
119
119
|
{
|
|
120
120
|
code: 'X_LINT_FAILED',
|
|
121
121
|
cause: 'biome exited red and reported no diagnostic to read',
|
|
122
|
-
fix: 'bunx biome check .',
|
|
122
|
+
fix: 'bunx @biomejs/biome check .',
|
|
123
123
|
docs: ERROR_DOCS_URL,
|
|
124
124
|
},
|
|
125
125
|
],
|
|
@@ -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',
|
|
@@ -88,13 +79,8 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
88
79
|
X_CLI_UNEXPECTED: 'x doctor --json',
|
|
89
80
|
// `-p .`: an app root has no `references`, so the gate's own step runs this form (#450).
|
|
90
81
|
X_TYPECHECK_FAILED: 'bunx tsc -p . --pretty false',
|
|
91
|
-
X_LINT_FAILED: 'bunx biome check .',
|
|
82
|
+
X_LINT_FAILED: 'bunx @biomejs/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,23 @@ 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',
|
|
396
|
+
X_SUPERSEDED_WORKAROUND:
|
|
397
|
+
'x doctor --json # each finding names the file, the release that retired the workaround and its replacement',
|
|
398
|
+
X_GUARD_VENDORED: 'x upgrade --json',
|
|
399
|
+
X_GUARD_BUILT_IN:
|
|
400
|
+
'x verify --only boundaries --json # set its severity in guards/shipped.json, or generate an app guard under another name',
|
|
401
|
+
X_REPRO_BUNDLE_INVALID:
|
|
402
|
+
'x repro --json # lists the failing jobs and error groups; then run it again with one id and --bundle, and attach the file it writes',
|
|
403
|
+
X_ADVISORY_FLOOR_UNMET: 'bun update source-map-js immutable',
|
|
404
|
+
X_UPGRADE_CODEMODS_PENDING: 'x upgrade --json',
|
|
405
|
+
X_UPGRADE_LOCKED: 'cat .x/upgrade.lock',
|
|
405
406
|
};
|
|
406
407
|
|
|
407
408
|
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
|
-
|
|
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
|
|
128
|
-
fix: 'x mcp serve --transport stdio #
|
|
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
|
-
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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));
|