@ultimat3/cli 31.0.0 → 31.2.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 (49) hide show
  1. package/CLAUDE.md +6 -1
  2. package/package.json +29 -29
  3. package/src/affected-base.ts +51 -0
  4. package/src/affected.ts +29 -10
  5. package/src/binding-names.ts +124 -0
  6. package/src/browser-transport.ts +28 -0
  7. package/src/ci-log.ts +76 -13
  8. package/src/cmd-affected-spec.ts +7 -3
  9. package/src/cmd-affected.ts +91 -77
  10. package/src/cmd-ci.ts +6 -3
  11. package/src/cmd-doctor.ts +8 -0
  12. package/src/cmd-exercise.ts +13 -1
  13. package/src/cmd-pr-spec.ts +1 -1
  14. package/src/cmd-pr.ts +72 -1
  15. package/src/cmd-shot.ts +13 -271
  16. package/src/cmd-test-spec.ts +2 -2
  17. package/src/cmd-upgrade.ts +28 -4
  18. package/src/cmd-verify-spec.ts +2 -2
  19. package/src/doctor-typescript.ts +31 -0
  20. package/src/error-codes-package.ts +38 -0
  21. package/src/error-codes.ts +7 -21
  22. package/src/mcp-errors-shot.ts +49 -0
  23. package/src/mcp-errors.ts +7 -41
  24. package/src/measure-scope.ts +17 -4
  25. package/src/messages-gate.ts +6 -0
  26. package/src/messages-upgrade.ts +2 -0
  27. package/src/offline-ports.ts +106 -0
  28. package/src/output.ts +21 -3
  29. package/src/pr-activity.ts +150 -0
  30. package/src/pr-bots.ts +109 -0
  31. package/src/pr-threads.ts +7 -2
  32. package/src/prerender.ts +2 -2
  33. package/src/runtime-storage-boot.ts +41 -7
  34. package/src/shot-gpu.ts +61 -0
  35. package/src/shot-route.ts +95 -0
  36. package/src/shot-run.ts +189 -0
  37. package/src/shot-verdict.ts +5 -0
  38. package/src/templates/scaffold-repo.ts +2 -1
  39. package/src/templates/sign-in-oidc.ts +24 -9
  40. package/src/transport-calls.ts +7 -3
  41. package/src/transport-values.ts +59 -0
  42. package/src/tsconfig-aliases.ts +85 -0
  43. package/src/typescript-floor.ts +83 -0
  44. package/src/upgrade-report.ts +8 -1
  45. package/src/verify-changed-scope.ts +3 -2
  46. package/src/verify-checks.ts +2 -0
  47. package/src/workspace-external-deps.ts +164 -0
  48. package/wiki/CLI-Reference.md +12 -8
  49. package/wiki/Upgrading.md +24 -5
package/src/cmd-shot.ts CHANGED
@@ -5,15 +5,12 @@
5
5
  // Never a step of `x verify`: it needs a real browser, and a gate that goes red because a machine
6
6
  // has no Chrome is a gate that fails for reasons unrelated to the change.
7
7
 
8
- import { mkdirSync } from 'node:fs';
9
8
  import { join, resolve } from 'node:path';
10
9
  import { renderFixShellArg } from '@ultimat3/core';
11
- import { systemClock } from '@ultimat3/core/adapter';
12
10
  import { appLocaleSet } from '@ultimat3/i18n/app-catalogs';
13
11
  import { IDLE_HYDRATE_TIMEOUT_MS } from '@ultimat3/render';
14
12
  import { requireAppRoot } from './app-root';
15
13
  import { appBrowser } from './browser-launcher';
16
- import type { ShotColorScheme, ShotDriver, ShotPage, ShotSession } from './browser-launcher-port';
17
14
  import { DEFAULT_PAGE_TIMEOUT_MS } from './cdp-shot-clock';
18
15
  import {
19
16
  islandShot,
@@ -34,130 +31,34 @@ import {
34
31
  } from './cmd-shot-matrix';
35
32
  import { shotSpec } from './cmd-shot-spec';
36
33
  import type { CliCommand, CommandContext } from './command';
37
- import { BadFlagError, MissingPositionalError } from './errors';
34
+ import { BadFlagError } from './errors';
38
35
  import { intFlagOr, PORT_RANGE } from './flag-number';
39
36
  import type { CommandResult } from './output';
40
37
  import type { ParsedArgs } from './parse';
41
38
  import { flagBool, flagString } from './parse';
42
39
  import { shotBrowserChoice } from './shot-browser';
43
- import { readCookieFlag, type ShotCookiePair, shotCookies } from './shot-cookie';
44
- import { acceptLanguageHeaders, localizedShotPath, readLocaleFlag } from './shot-locale';
40
+ import { readCookieFlag } from './shot-cookie';
41
+ import { localizedShotPath, readLocaleFlag } from './shot-locale';
42
+ import { readRoute, shotSlug } from './shot-route';
43
+ import { runShot } from './shot-run';
45
44
  import type { BootDevServer, ShotServer } from './shot-server';
46
45
  import { allowHostsFrom, devServerFor, SHOT_DIR } from './shot-server';
47
- import { SETTLE_POLL_MS, settleIslands } from './shot-settle';
48
- import { readThemeFlag, themeChoiceExpression } from './shot-theme';
49
- import type { IslandCount, ShotArtifacts } from './shot-verdict';
50
- import {
51
- buildVerdict,
52
- documentStatus,
53
- ISLAND_PROBE,
54
- parseIslandProbe,
55
- shotLines,
56
- shotSummary,
57
- verdictJson,
58
- } from './shot-verdict';
46
+ import { readThemeFlag } from './shot-theme';
47
+ import type { ShotArtifacts } from './shot-verdict';
48
+ import { shotLines, shotSummary, verdictJson } from './shot-verdict';
59
49
  import { parseViewports, refuseViewportWithComponent, runShotViewports } from './shot-viewport';
60
50
 
61
51
  /** Kernel-picked by default: :3000 is usually another project's dev server, not a free port. */
62
52
  const DEFAULT_PORT = 0;
63
53
 
64
- // Re-exported, not re-declared: a second declaration of a path or a host rule is a second answer.
54
+ // Re-exported, not re-declared: a second declaration of a path, a host rule, the route rule or the
55
+ // capture is a second answer. The route rule is `shot-route.ts`'s, the capture `shot-run.ts`'s.
56
+ export { readRoute, shotSlug } from './shot-route';
57
+ export type { ShotRun } from './shot-run';
58
+ export { runShot, SHOT_IMAGE, SHOT_VERDICT } from './shot-run';
65
59
  export type { BootDevServer, ShotServer };
66
60
  export { allowHostsFrom, devServerFor, SHOT_DIR };
67
61
 
68
- export const SHOT_IMAGE = 'shot.png';
69
- export const SHOT_VERDICT = 'verdict.json';
70
-
71
- /** A directory name a route can never escape: everything that is not a letter or digit is a dash. */
72
- export function shotSlug(route: string): string {
73
- const slug = route.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-+|-+$/g, '');
74
- return slug === '' ? 'root' : slug.toLowerCase();
75
- }
76
-
77
- const pathOf = (url: string): string => {
78
- try {
79
- return new URL(url).pathname;
80
- } catch {
81
- return '/';
82
- }
83
- };
84
-
85
- /**
86
- * A reserved name (RFC 2606) that resolves nowhere, so the origin check below can never be
87
- * satisfied by an accident of what the app's own host happens to be.
88
- */
89
- const ROUTE_BASE = 'http://route.invalid';
90
-
91
- /**
92
- * Where a browser would actually go. The refusal above reads `scheme:` and nothing else, and this
93
- * is the question it was standing in for: a path is a path only if resolving it lands back on the
94
- * origin it was resolved against.
95
- */
96
- const resolvedOrigin = (path: string): string => {
97
- try {
98
- return new URL(path, ROUTE_BASE).origin;
99
- } catch {
100
- // A path `new URL` will not parse is one no browser will fetch either, and reporting it as the
101
- // origin it is not is the honest answer here.
102
- return '';
103
- }
104
- };
105
-
106
- const refuseRoute = (reason: string): never => {
107
- throw new BadFlagError({
108
- flag: 'route',
109
- command: 'shot',
110
- reason,
111
- // A placeholder, because there is nothing safe to substitute: unlike an absolute URL, an
112
- // origin-escaping route carries no path the caller can be assumed to have meant.
113
- fix: 'x shot /<path> --json',
114
- });
115
- };
116
-
117
- /**
118
- * A path on the app, never a URL. `x shot https://example.com` would photograph somebody else's
119
- * site through a headless browser inside your network, which is the SSRF shape `allowHosts` exists
120
- * to refuse — so it is refused here, at the argument, where the reader can still see why.
121
- *
122
- * `scheme:` was the ONLY spelling refused until 2026-08-22, and it is one of four: `//evil/x` is a
123
- * protocol-relative URL, `\evil\x` is the same thing to every URL parser (a backslash IS a slash
124
- * for a special scheme), and a TAB inside the path is deleted by the parser before the host is
125
- * read, so `/⇥/evil/x` becomes `//evil/x`. Each one reached `new URL(route, server.url)` and came
126
- * back pointed at another host. `allowHostsFrom` one layer down could not catch any of them: it
127
- * allows a HOSTNAME, and the hostname it is given is the one the page has already left — which is
128
- * how `x shot //localhost:9200/_cat/indices` photographed whatever else was on the dev box.
129
- */
130
- export function readRoute(raw: string | undefined): string {
131
- if (raw === undefined || raw.trim() === '') {
132
- throw new MissingPositionalError({ command: 'shot', positional: 'route', example: 'x shot /' });
133
- }
134
- const route = raw.trim();
135
- if (/^[a-z][a-z0-9+.-]*:/i.test(route)) {
136
- throw new BadFlagError({
137
- flag: 'route',
138
- command: 'shot',
139
- reason: `"${route}" is an absolute URL; x shot photographs a route of the app under test`,
140
- // The path out of the URL when it parses — the refusal's own fix line has to be runnable,
141
- // and `new URL('http://')` throws, so the fallback is the route every app has.
142
- fix: `x shot ${pathOf(route)} --json`,
143
- });
144
- }
145
- const path = route.startsWith('/') ? route : `/${route}`;
146
- // Its own refusal rather than folded into the origin check: `/a\b` stays on this origin and is
147
- // still not the route that was typed — the verdict would record `/a\b` beside a picture of
148
- // `/a/b`, which is the artifact lying about its own subject.
149
- if (path.includes('\\')) {
150
- return refuseRoute(`"${route}" contains a backslash, which a URL parser reads as "/"`);
151
- }
152
- const origin = resolvedOrigin(path);
153
- if (origin !== ROUTE_BASE) {
154
- return refuseRoute(
155
- `"${route}" is not a path on the app: a browser resolves it to ${origin === '' ? 'no URL at all' : origin}`,
156
- );
157
- }
158
- return path;
159
- }
160
-
161
62
  /**
162
63
  * The three integer flags, each read with its NAME as an argument. `intFlagOr` takes the name in a
163
64
  * `name:` field, which `flag-reads.ts` counts as a declaration rather than a read — so a command
@@ -183,165 +84,6 @@ const intFlag = (
183
84
  fallback,
184
85
  );
185
86
 
186
- export interface ShotRun {
187
- readonly route: string;
188
- readonly outDir: string;
189
- readonly driver: ShotDriver;
190
- readonly boot: () => Promise<ShotServer>;
191
- readonly settleMs: number;
192
- readonly timeoutMs: number;
193
- readonly fullPage: boolean;
194
- /**
195
- * `--allow-hosts`, verbatim. The app's own host is added once the server is up and never here:
196
- * with `--port 0` the port — and therefore the origin — does not exist until after the boot.
197
- */
198
- readonly extraHosts?: string | undefined;
199
- /**
200
- * The theme the picture is of. Two things happen BEFORE navigation, because the boot script runs
201
- * inline and nothing after `goto` can reach it: `prefers-color-scheme` is emulated so the boot's
202
- * "system" branch answers the same on every box, AND the scheme is stored as the visitor's
203
- * choice under `THEME_STORAGE_KEY` (`shot-theme.ts`), because an app with `theme.defaultMode`
204
- * set answers that before the OS and only a stored choice beats it (issue #489). Absent means
205
- * neither: the box's own preference and the app's own default — what `x shot` has always done,
206
- * and the point of `defaultMode` — and `ui.shot` names one explicitly for exactly that reason.
207
- */
208
- readonly colorScheme?: ShotColorScheme | undefined;
209
- /** CSS pixels the page is laid out in; absent is the driver's default. */
210
- readonly viewport?: { readonly width: number; readonly height: number } | undefined;
211
- /**
212
- * Sent as `Accept-Language` on every request. The command always sets it — `--locale`, or the
213
- * app's default locale — so a picture never depends on the language of the machine's Chrome.
214
- */
215
- readonly acceptLanguage?: string | undefined;
216
- /**
217
- * `--cookie`: set before the first navigation, each for the server's own URL once it is up —
218
- * so a consent banner (or any cookie-held choice) is decided in the picture.
219
- */
220
- readonly cookies?: readonly ShotCookiePair[] | undefined;
221
- readonly now?: (() => Date) | undefined;
222
- /**
223
- * `--expect-status`: the document status this shot is ok with — `404` to photograph the not-found
224
- * page on purpose. Absent means any 2xx, and anything else fails the verdict with the status.
225
- */
226
- readonly expectStatus?: number | undefined;
227
- /**
228
- * Something to do with the page AFTER the islands settled and BEFORE the picture — `ui.inspect`
229
- * reads the DOM here, on the one navigation the picture already paid for. `settle` re-runs the
230
- * island poll (an action that mounts something changes the count the verdict reports); the
231
- * caller who never calls it gets the count from the first settle.
232
- */
233
- readonly act?:
234
- | ((page: ShotPage, settle: () => Promise<IslandCount | null>) => Promise<void>)
235
- | undefined;
236
- /**
237
- * The clock the settle window runs on — the same seam `SettleOptions.sleep` and
238
- * `InteractDeps.sleep` take, and the reason they had none on this path: `settleMs` was a
239
- * `Bun.sleep` here, so a caller that injected a sleep everywhere else still paid the real
240
- * 2000 ms window in wall time once per `runShot`, and a test doing it twice raced its own
241
- * per-test timeout on a slower box. Absent is `Bun.sleep`: production waits for real.
242
- */
243
- readonly sleep?: ((ms: number) => Promise<void>) | undefined;
244
- }
245
-
246
- /** Nothing here may replace the failure that caused it, so a teardown throw is swallowed. */
247
- const quietly = async (stop: () => Promise<void>): Promise<void> => {
248
- await stop().catch(() => undefined);
249
- };
250
-
251
- /**
252
- * Boot (or find) the server, photograph one route, write both artifacts. The driver and the boot
253
- * are ARGUMENTS: `bun test` drives this with `fakeBrowser()` and a stub server, so the whole
254
- * command is proved on a machine with no Chrome — which this command is explicitly excluded from
255
- * the gate for needing.
256
- */
257
- export async function runShot(options: ShotRun): Promise<ShotArtifacts> {
258
- const server = await options.boot();
259
- const sleep = options.sleep ?? ((ms: number): Promise<void> => Bun.sleep(ms));
260
- let session: ShotSession | undefined;
261
- try {
262
- const requestedUrl = new URL(options.route, server.url).toString();
263
- session = await options.driver.open({
264
- name: 'x shot',
265
- // The host the picture is of, plus whatever the caller named. Never `*`: a headless browser
266
- // inside your network is the widest SSRF surface an app can own, and a screenshot command is
267
- // not the place to open it by default. Every refusal lands in the verdict's `refused` count.
268
- rules: { allowHosts: allowHostsFrom(server.url, options.extraHosts) },
269
- clock: systemClock,
270
- timeoutMs: options.timeoutMs,
271
- ...(options.viewport === undefined ? {} : { viewport: options.viewport }),
272
- ...(options.acceptLanguage === undefined
273
- ? {}
274
- : { headers: acceptLanguageHeaders(options.acceptLanguage) }),
275
- ...(options.cookies === undefined || options.cookies.length === 0
276
- ? {}
277
- : { cookies: shotCookies(options.cookies, new URL(server.url).toString()) }),
278
- });
279
- const page = session.page;
280
- if (options.colorScheme !== undefined) {
281
- await page.colorScheme(options.colorScheme);
282
- const choice = themeChoiceExpression(options.colorScheme);
283
- if (choice !== undefined) await page.prepare(choice);
284
- }
285
- await page.goto(requestedUrl, { timeout: options.timeoutMs });
286
- // Read NOW as well as at capture: the network ring is bounded, and a page that fires a few
287
- // hundred requests while it settles evicts the document entry the verdict needs.
288
- const landedStatus = documentStatus(page.network(), page.url());
289
- if (options.settleMs > 0) await sleep(options.settleMs);
290
- // The probe may legitimately answer nothing — a page that refuses evaluation, a driver with no
291
- // JS engine. `null` says so; a `0` would read as "the route renders no islands", which is a
292
- // different and much more alarming claim.
293
- const probe = (): Promise<IslandCount | null> =>
294
- page
295
- .evaluate(ISLAND_PROBE)
296
- .then(parseIslandProbe)
297
- .catch(() => null);
298
- // The same budget again, and deliberately no new flag: `settleMs` is the deadline at which the
299
- // runtime CALLS `import()`, so a mount gets exactly as long to settle as the runtime got to
300
- // start it — and `--settle 0`, which asks for no wait, still gets none.
301
- const settle = (): Promise<IslandCount | null> =>
302
- settleIslands(probe, { windowMs: options.settleMs, pollMs: SETTLE_POLL_MS, sleep });
303
- let islands = await settle();
304
- if (options.act !== undefined) {
305
- await options.act(page, async () => {
306
- islands = await settle();
307
- return islands;
308
- });
309
- }
310
- const bytes = await page.screenshot({ fullPage: options.fullPage });
311
- // Read AFTER the capture, so an error logged while the page settled is in the verdict that
312
- // ships with the picture it explains.
313
- const verdict = buildVerdict({
314
- route: options.route,
315
- requestedUrl,
316
- finalUrl: page.url(),
317
- server: server.origin,
318
- capturedAt: (options.now ?? (() => new Date()))().toISOString(),
319
- screenshot: SHOT_IMAGE,
320
- bytes,
321
- console: page.console(),
322
- pageErrors: page.pageErrors(),
323
- pageErrorsDropped: page.pageErrorsDropped(),
324
- network: page.network(),
325
- networkDropped: page.networkDropped(),
326
- islands,
327
- landedStatus,
328
- ...(options.expectStatus === undefined ? {} : { expectStatus: options.expectStatus }),
329
- });
330
- mkdirSync(options.outDir, { recursive: true });
331
- const image = join(options.outDir, SHOT_IMAGE);
332
- const verdictFile = join(options.outDir, SHOT_VERDICT);
333
- await Bun.write(image, bytes);
334
- await Bun.write(verdictFile, `${JSON.stringify(verdictJson(verdict), null, 2)}\n`);
335
- return { verdict, image, verdictFile };
336
- } finally {
337
- // Bound to a const: narrowing a `let` does not survive into the closure below, and the session
338
- // has to be closed from inside one so a teardown throw cannot replace the real failure.
339
- const open = session;
340
- if (open !== undefined) await quietly(() => open.close());
341
- await quietly(() => server.stop());
342
- }
343
- }
344
-
345
87
  /**
346
88
  * Where the artifacts land. A relative `--out` is a path the caller typed from where they stand,
347
89
  * so it resolves against the cwd — `x build --out`'s rule. Against the app root it landed
@@ -2,7 +2,7 @@
2
2
  // read it without loading `cmd-test.ts`, which `registry.ts` imports only when the command runs.
3
3
 
4
4
  import { TEST_TYPES } from '@ultimat3/testing/test-types';
5
- import { DEFAULT_BASE } from './affected';
5
+ import { DEFAULT_BASE_HELP } from './affected-base';
6
6
  import type { CommandSpec } from './parse';
7
7
  import {
8
8
  BUDGET_RULE,
@@ -60,7 +60,7 @@ export const testSpec: CommandSpec = {
60
60
  {
61
61
  name: 'base',
62
62
  type: 'string',
63
- summary: `--affected: git ref to diff against, merge-base style (default: ${DEFAULT_BASE})`,
63
+ summary: `--affected: git ref to diff against, merge-base style (default: ${DEFAULT_BASE_HELP})`,
64
64
  },
65
65
  {
66
66
  name: 'seed',
@@ -17,6 +17,7 @@ import { msg } from './messages';
17
17
  import type { CommandResult } from './output';
18
18
  import { flagBool, flagString } from './parse';
19
19
  import { posixRelative } from './posix-path';
20
+ import { typescriptLags } from './typescript-floor';
20
21
  import { applyAgentsLink, planAgentsLink } from './upgrade-agents-link';
21
22
  import type { BunEdit, BunManual } from './upgrade-bun-floor';
22
23
  import { editBunSites, floorOf, isBunSite } from './upgrade-bun-floor';
@@ -154,6 +155,8 @@ export const createUpgradeCommand = (write: (line: string) => void): CliCommand
154
155
  const top = await requireCleanTree(ctx.runner, root);
155
156
  const manifests = await readManifests(root);
156
157
  const pins = readPins(manifests);
158
+ // Reported, never written: a compiler is the app's to move, and the line names the command.
159
+ const typescript = typescriptLags(manifests);
157
160
  const versions = await publishedVersions(ctx.runner, root);
158
161
  const hop = planHop({ pins, versions, ...(to === undefined ? {} : { to }) });
159
162
 
@@ -176,8 +179,12 @@ export const createUpgradeCommand = (write: (line: string) => void): CliCommand
176
179
  gate: undefined,
177
180
  scripts: [],
178
181
  then,
182
+ typescript,
179
183
  }),
180
- lines: [msg('cli.upgrade.then', { then })],
184
+ lines: [
185
+ ...typescript.map((lag) => msg('cli.upgrade.typescript', { ...lag })),
186
+ msg('cli.upgrade.then', { then }),
187
+ ],
181
188
  });
182
189
  }
183
190
 
@@ -199,7 +206,16 @@ export const createUpgradeCommand = (write: (line: string) => void): CliCommand
199
206
  const held = manifests.find((manifest) => manifest.file === 'package.json')?.text ?? '';
200
207
  const bunFrom = /"engines"\s*:\s*\{[^}]*?"bun"\s*:\s*"([^"]*)"/.exec(held)?.[1] ?? null;
201
208
  const agentsMd = await planAgentsLink(root);
202
- const shared = { hop, pins, bunFrom, bunTo: bunRange ?? null, writes, app, agentsMd };
209
+ const shared = {
210
+ hop,
211
+ pins,
212
+ bunFrom,
213
+ bunTo: bunRange ?? null,
214
+ writes,
215
+ app,
216
+ agentsMd,
217
+ typescript,
218
+ };
203
219
  const scriptNames = app ? [] : repoScripts(held);
204
220
 
205
221
  if (dryRun) {
@@ -214,7 +230,15 @@ export const createUpgradeCommand = (write: (line: string) => void): CliCommand
214
230
  scripts: named,
215
231
  then,
216
232
  }),
217
- lines: humanLines({ hop, writes, gate: undefined, scripts: named, then, agentsMd }),
233
+ lines: humanLines({
234
+ hop,
235
+ writes,
236
+ gate: undefined,
237
+ scripts: named,
238
+ then,
239
+ agentsMd,
240
+ typescript,
241
+ }),
218
242
  });
219
243
  }
220
244
 
@@ -248,7 +272,7 @@ export const createUpgradeCommand = (write: (line: string) => void): CliCommand
248
272
  const then = thenLine({ hop, dryRun: false, app, gate, scripts });
249
273
  const extra = {
250
274
  data: report({ ...shared, done, dryRun: false, gate, scripts, then }),
251
- lines: humanLines({ hop, writes, gate, scripts, then, agentsMd }),
275
+ lines: humanLines({ hop, writes, gate, scripts, then, agentsMd, typescript }),
252
276
  };
253
277
  const span = { from: hop.from, to: hop.to };
254
278
  if (gate !== undefined) {
@@ -1,7 +1,7 @@
1
1
  // `x verify`'s declaration, apart from its body: the parser, `x help` and the `errors` step
2
2
  // read it without loading `cmd-verify.ts`, which `registry.ts` imports only when the command runs.
3
3
 
4
- import { DEFAULT_BASE } from './affected';
4
+ import { DEFAULT_BASE_HELP } from './affected-base';
5
5
  import type { CommandSpec } from './parse';
6
6
  import { BUDGET_RULE, WORKER_BYTES, WORKER_CEILING, WORKER_FLOOR } from './test-workers';
7
7
 
@@ -45,7 +45,7 @@ export const verifySpec: CommandSpec = {
45
45
  name: 'base',
46
46
  type: 'string',
47
47
  subcommands: ['run'],
48
- summary: `with --changed: git ref to diff against, merge-base style, as x affected reads it (default: ${DEFAULT_BASE})`,
48
+ summary: `with --changed: git ref to diff against, merge-base style, as x affected reads it (default: ${DEFAULT_BASE_HELP})`,
49
49
  },
50
50
  {
51
51
  name: 'dirty',
@@ -0,0 +1,31 @@
1
+ // `x doctor`'s TypeScript check: every manifest whose `typescript` range lags the one `x new`
2
+ // scaffolds is `X_TYPESCRIPT_VERSION`, its fix the `bun add` that moves exactly that manifest.
3
+ // The rule is `typescript-floor.ts`'s; this file reads the manifests and words the finding.
4
+
5
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
6
+ import type { Finding } from './output';
7
+ import type { TypescriptLag } from './typescript-floor';
8
+ import { typescriptLags } from './typescript-floor';
9
+ import { readManifests } from './upgrade-pins';
10
+
11
+ /**
12
+ * The I/O half: the root manifest and every workspace's, the set `x upgrade` moves pins in. An
13
+ * unreadable root manifest is not this check's to report — `bun install` names its line — so it
14
+ * reads as nothing to judge rather than a second finding about the same file.
15
+ */
16
+ export async function typescriptProbe(root: string): Promise<readonly TypescriptLag[]> {
17
+ try {
18
+ return typescriptLags(await readManifests(root));
19
+ } catch {
20
+ return [];
21
+ }
22
+ }
23
+
24
+ export const typescriptFindings = (lags: readonly TypescriptLag[]): readonly Finding[] =>
25
+ lags.map((lag) => ({
26
+ code: 'X_TYPESCRIPT_VERSION',
27
+ at: lag.file,
28
+ cause: `${lag.file} declares ${lag.field}.typescript ${JSON.stringify(lag.from)}, below the ${lag.to} \`x new\` scaffolds; @ultimat3/* ships source and .d.ts checked by that compiler, so typecheck and build go red on framework files this app never wrote`,
29
+ fix: lag.fix,
30
+ docs: ERROR_DOCS_URL,
31
+ }));
@@ -0,0 +1,38 @@
1
+ // The X_* codes of the `package-shape` and `filesize` steps — what a workspace owes the repo it lives
2
+ // in — split out of `error-codes.ts` at its 500-line ceiling, as `error-codes-shot.ts` was. That
3
+ // file folds these into the CLI's one owned union and registers them in its one call.
4
+
5
+ /** Codes the workspace-shape rules declare and own. */
6
+ export const CLI_PACKAGE_ERROR_CODES = [
7
+ 'X_FILE_TOO_LONG',
8
+ 'X_PACKAGE_SHAPE',
9
+ // The build graph's own membership rule. `tsc -b` compiles referenced projects and nothing
10
+ // else, so a workspace no root reference names is one the `typecheck` step passes over without
11
+ // reading — the hole that let `scripts/` hold seven type errors under a green gate.
12
+ 'X_PACKAGE_UNREFERENCED',
13
+ 'X_RELEASE_VERSION_SKEW',
14
+ 'X_WORKSPACE_DEP_UNDECLARED',
15
+ // Two module instances of a registry-holding package inside ONE app's `node_modules`. Its own
16
+ // code and not the registry's (`X_CATALOG_UNREGISTERED`, `X_PERMISSION_UNKNOWN`): those carry a
17
+ // source-level fix, and an agent following it here edits a file that is already right — the
18
+ // repair is an install, and only `duplicate-packages.ts` can see that.
19
+ 'X_PACKAGE_DUPLICATED',
20
+ 'X_PACKAGE_TEST_ONLY_SHIPPED',
21
+ // A registry import only a SIBLING declares: hoisting resolves it until a clean install does not.
22
+ 'X_WORKSPACE_EXTERNAL_DEP_UNDECLARED',
23
+ ] as const;
24
+
25
+ export type CliPackageErrorCode = (typeof CLI_PACKAGE_ERROR_CODES)[number];
26
+
27
+ /** Their titles, typed over the list above so a code without one is a build error. */
28
+ export const CLI_PACKAGE_ERROR_TITLES: Readonly<Record<CliPackageErrorCode, string>> = {
29
+ X_FILE_TOO_LONG: 'a source file is over 500 lines',
30
+ X_PACKAGE_SHAPE: 'a workspace package is missing a contract file',
31
+ X_PACKAGE_UNREFERENCED: 'a published workspace is not in the root tsconfig build graph',
32
+ X_RELEASE_VERSION_SKEW: 'a workspace is not at the lockstep version',
33
+ X_WORKSPACE_DEP_UNDECLARED: 'a workspace imports another workspace it does not declare',
34
+ X_PACKAGE_DUPLICATED: 'two copies of one registry-holding framework package are installed',
35
+ X_PACKAGE_TEST_ONLY_SHIPPED: 'a test-only module ships in the tarball',
36
+ X_WORKSPACE_EXTERNAL_DEP_UNDECLARED:
37
+ 'a workspace imports a registry package that neither it nor the app root declares',
38
+ };
@@ -5,6 +5,8 @@
5
5
  import { registerErrorCodes } from '@ultimat3/core';
6
6
  import type { CliBoundaryErrorCode } from './error-codes-boundary';
7
7
  import { CLI_BOUNDARY_ERROR_CODES, CLI_BOUNDARY_ERROR_TITLES } from './error-codes-boundary';
8
+ import type { CliPackageErrorCode } from './error-codes-package';
9
+ import { CLI_PACKAGE_ERROR_CODES, CLI_PACKAGE_ERROR_TITLES } from './error-codes-package';
8
10
  import type { CliShotErrorCode } from './error-codes-shot';
9
11
  import { CLI_SHOT_ERROR_CODES, CLI_SHOT_ERROR_TITLES } from './error-codes-shot';
10
12
  import type { CliToolingErrorCode } from './error-codes-tooling';
@@ -51,13 +53,6 @@ export const CLI_OWNED_ERROR_CODES = [
51
53
  // repo already ran it, in which case the suite was deleted and the gate would otherwise print
52
54
  // one more green line for it.
53
55
  'X_VERIFY_SUITE_VANISHED',
54
- 'X_FILE_TOO_LONG',
55
- 'X_PACKAGE_SHAPE',
56
- // The build graph's own membership rule. `tsc -b` compiles referenced projects and nothing
57
- // else, so a workspace no root reference names is one the `typecheck` step passes over without
58
- // reading — the hole that let `scripts/` hold seven type errors under a green gate.
59
- 'X_PACKAGE_UNREFERENCED',
60
- 'X_RELEASE_VERSION_SKEW',
61
56
  // The framework's own tables, refused by name rather than by the driver's rejection: a raw
62
57
  // `permission denied for schema public` says which statement failed and neither which framework
63
58
  // table it was creating nor which package wants it.
@@ -153,12 +148,6 @@ export const CLI_OWNED_ERROR_CODES = [
153
148
  // CLI's problem alone, and core would have no `fix:` to offer for one.
154
149
  'X_SECRETS_EDITOR_MISSING',
155
150
  'X_SECRETS_EDIT_FAILED',
156
- 'X_WORKSPACE_DEP_UNDECLARED',
157
- // Two module instances of a registry-holding package inside ONE app's `node_modules`. Its own
158
- // code and not the registry's (`X_CATALOG_UNREGISTERED`, `X_PERMISSION_UNKNOWN`): those carry a
159
- // source-level fix, and an agent following it here edits a file that is already right — the
160
- // repair is an install, and only `duplicate-packages.ts` can see that.
161
- 'X_PACKAGE_DUPLICATED',
162
151
  'X_GH_UNAVAILABLE',
163
152
  'X_GH_NOT_AUTHENTICATED',
164
153
  'X_GH_COMMAND_FAILED',
@@ -198,7 +187,6 @@ export const CLI_OWNED_ERROR_CODES = [
198
187
  'X_PERMISSION_BORROWED',
199
188
  'X_ERROR_CODE_UNTHROWN_STALE',
200
189
  'X_DEV_STATE_UNWRITABLE',
201
- 'X_PACKAGE_TEST_ONLY_SHIPPED',
202
190
  'X_ISLAND_MODULE_DUPLICATED',
203
191
  'X_BACKFILL_SLICE_ENTITY',
204
192
  'X_LAYOUT_SIBLING_MODULE',
@@ -248,6 +236,7 @@ export const CLI_OWNED_ERROR_CODES = [
248
236
  'X_APP_ROOT_NESTED',
249
237
  'X_WORKSPACE_NAME_TAKEN',
250
238
  'X_PARTITIONS_UNMAINTAINED',
239
+ 'X_TYPESCRIPT_VERSION',
251
240
  ] as const;
252
241
 
253
242
  /**
@@ -284,6 +273,7 @@ export const CLI_BORROWED_ERROR_CODES = [
284
273
  export const CLI_ERROR_CODES = [
285
274
  ...CLI_OWNED_ERROR_CODES,
286
275
  ...CLI_BOUNDARY_ERROR_CODES,
276
+ ...CLI_PACKAGE_ERROR_CODES,
287
277
  ...CLI_SHOT_ERROR_CODES,
288
278
  ...CLI_TOOLING_ERROR_CODES,
289
279
  ...CLI_BORROWED_ERROR_CODES,
@@ -294,6 +284,7 @@ type CliListedErrorCode = (typeof CLI_OWNED_ERROR_CODES)[number];
294
284
  export type CliOwnedErrorCode =
295
285
  | CliListedErrorCode
296
286
  | CliBoundaryErrorCode
287
+ | CliPackageErrorCode
297
288
  | CliShotErrorCode
298
289
  | CliToolingErrorCode;
299
290
  export type CliErrorCode = (typeof CLI_ERROR_CODES)[number];
@@ -333,10 +324,6 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
333
324
  X_LINT_FAILED: 'Biome failed',
334
325
  X_TEST_FAILED: 'a test type failed',
335
326
  X_VERIFY_SUITE_VANISHED: 'a step the committed floor requires had nothing left to check',
336
- X_FILE_TOO_LONG: 'a source file is over 500 lines',
337
- X_PACKAGE_SHAPE: 'a workspace package is missing a contract file',
338
- X_PACKAGE_UNREFERENCED: 'a published workspace is not in the root tsconfig build graph',
339
- X_RELEASE_VERSION_SKEW: 'a workspace is not at the lockstep version',
340
327
  X_MANIFEST_STALE: 'openapi.json is stale',
341
328
  X_MANIFEST_MISSING: 'the app ships no x.manifest.json',
342
329
  X_BUDGET_UNMEASURED: 'a route declares a budget the build never measured',
@@ -370,8 +357,6 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
370
357
  X_CLI_FLAG_UNREAD: 'a command declares a flag no code reads',
371
358
  X_SECRETS_EDITOR_MISSING: 'no $EDITOR to open the decrypted secrets in',
372
359
  X_SECRETS_EDIT_FAILED: 'the editor exited non-zero, so nothing was resealed',
373
- X_WORKSPACE_DEP_UNDECLARED: 'a workspace imports another workspace it does not declare',
374
- X_PACKAGE_DUPLICATED: 'two copies of one registry-holding framework package are installed',
375
360
  X_GH_UNAVAILABLE: 'the GitHub CLI is not runnable from here',
376
361
  X_GH_NOT_AUTHENTICATED: 'gh holds no credentials for this host',
377
362
  X_GH_COMMAND_FAILED: 'a gh invocation exited non-zero',
@@ -420,7 +405,6 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
420
405
  X_ERROR_CODE_UNTHROWN_STALE:
421
406
  'a code UNTHROWN_CODES lists as thrown by nothing is thrown again — delete it from UNTHROWN_CODES in packages/cli/src/unthrown-codes.ts',
422
407
  X_DEV_STATE_UNWRITABLE: 'x dev cannot claim its state directory',
423
- X_PACKAGE_TEST_ONLY_SHIPPED: 'a test-only module ships in the tarball',
424
408
  X_ISLAND_MODULE_DUPLICATED: 'An island chunk bundles one module more than once',
425
409
  X_BACKFILL_SLICE_ENTITY: 'the slice holds no entity a generated backfill can sweep',
426
410
  X_LAYOUT_SIBLING_MODULE: 'a primitive module beside its directory',
@@ -475,6 +459,7 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
475
459
  X_WORKSPACE_NAME_TAKEN:
476
460
  'x g app or x g package was given a name the other workspace kind already holds',
477
461
  X_PARTITIONS_UNMAINTAINED: 'a partitioned entity with no partitions() job',
462
+ X_TYPESCRIPT_VERSION: 'The app declares a TypeScript older than the one x new scaffolds',
478
463
  };
479
464
 
480
465
  // One unconditional call, so a second package claiming one of the CLI's codes throws
@@ -484,6 +469,7 @@ registerErrorCodes(
484
469
  Object.entries({
485
470
  ...CLI_ERROR_TITLES,
486
471
  ...CLI_BOUNDARY_ERROR_TITLES,
472
+ ...CLI_PACKAGE_ERROR_TITLES,
487
473
  ...CLI_SHOT_ERROR_TITLES,
488
474
  ...CLI_TOOLING_ERROR_TITLES,
489
475
  }).map(([code, title]) => [code, { title }]),
@@ -0,0 +1,49 @@
1
+ // `errors.explain`'s rows for `x shot` and the `ui.*` MCP tools — the capture family, split out of
2
+ // `mcp-errors.ts` under the 500-line ceiling. Spread into `CLI_FIXES` there, whose
3
+ // `Record<CliErrorCode, string>` is still what makes a code without a row a build error.
4
+
5
+ import type { CliErrorCode } from './error-codes';
6
+
7
+ export const SHOT_FIXES = {
8
+ X_SHOT_BROWSER_MISSING:
9
+ 'export CHROME_PATH=/usr/bin/google-chrome # macOS: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; Windows PowerShell: $env:CHROME_PATH = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"',
10
+ X_UI_SHOT_ROUTE_UNKNOWN:
11
+ 'x routes --json # then call the ui.* tool with one of its path values',
12
+ X_UI_SHOT_ROUTE_UNBUDGETED:
13
+ "x build --target static --json && x verify --only budgets --json # after declaring budget: { js: '<n>kb' } in the route file",
14
+ // The four `ui.interact` refusals. None can be repaired by a command — each is a change to the
15
+ // step list the agent sends — so each names the command that SHOWS what a valid resend needs.
16
+ X_UI_INTERACT_STEPS_INVALID:
17
+ 'x help shot --json # then resend ui.interact with at most 12 one-key steps, type.text under 500 chars and wait under 5000 ms',
18
+ X_UI_INTERACT_SECRET_FIELD:
19
+ 'x shot --all-islands --json # or --island <name>: a declared state renders the filled form without the secret ever being typed',
20
+ X_UI_INTERACT_LEFT_APP:
21
+ 'x routes --json # then resend ui.interact with steps that stay on one of its paths',
22
+ X_UI_INTERACT_STEP_FAILED:
23
+ 'x routes --json # then run ui.inspect on the route first and copy a selector it reports with count >= 1',
24
+ X_SHOT_HOST_REFUSED: 'x shot /route --allow-hosts cdn.example.com --json',
25
+ X_SHOT_ELEMENT_MISSING:
26
+ 'x routes --json # then run ui.inspect on the route first and copy a selector it reports with count >= 1',
27
+ X_SHOT_ELEMENT_UNREADY:
28
+ 'x routes --json # then run ui.inspect on the route first and copy a selector it reports with count >= 1',
29
+ X_SHOT_KEY_INVALID: 'x help shot --json # a chord is modifiers then one key: Meta+K',
30
+ // The three `ui.diff` codes. Every capture it can compare was written by `x shot` or a `ui.*`
31
+ // tool under `.x/shot/`, so the runnable half is the command that writes one there.
32
+ X_UI_DIFF_PATH_OUTSIDE:
33
+ 'x shot / --json # then pass the image path it answers, relative to the app root: ui.diff reads .x/shot/ and nothing else',
34
+ X_UI_DIFF_FILE_MISSING:
35
+ 'x shot / --json # then diff the image path it answers; a capture ui.shot wrote is listed in its own answer',
36
+ X_UI_DIFF_SIZE_MISMATCH:
37
+ 'x shot / --json # photograph both captures at one viewport with one fullPage setting, then diff those two',
38
+ // The four island-capture codes. Each one's real repair is an edit to the app's own states file
39
+ // or component, which no command can perform — so each names the command that REPRODUCES it with
40
+ // the file and the reason attached, which is the runnable half.
41
+ X_SHOT_ISLAND_STATES_EMPTY:
42
+ 'x help shot --json # then export the manifest from the states file the cause names',
43
+ X_SHOT_ISLAND_UNPHOTOGRAPHABLE:
44
+ 'x help shot --json # the cause names the assertion that did not hold; --settle buys the slow ones more time',
45
+ X_SHOT_ISLAND_UNSTUBBED_REQUEST:
46
+ 'x help shot --json # the cause lists every request the state must answer under routes',
47
+ X_SHOT_ISLAND_MISSING:
48
+ 'x help shot --json # every absent picture carries its own named refusal in the run above',
49
+ } as const satisfies Partial<Record<CliErrorCode, string>>;