@ultimat3/cli 31.34.0 → 31.36.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 (53) hide show
  1. package/package.json +29 -29
  2. package/src/affected.ts +3 -1
  3. package/src/async-pages.ts +1 -1
  4. package/src/cdp-shot-errors.ts +4 -4
  5. package/src/cmd-deploy-helm.ts +1 -1
  6. package/src/cmd-env.ts +1 -1
  7. package/src/cmd-mcp.ts +5 -3
  8. package/src/coverage-floor.ts +5 -4
  9. package/src/db-subscribes.ts +2 -3
  10. package/src/db-ungeneratable.ts +3 -3
  11. package/src/dev-lock.ts +1 -1
  12. package/src/dev-supervisor.ts +1 -1
  13. package/src/docs-section.ts +2 -2
  14. package/src/doctor-database.ts +5 -4
  15. package/src/doctor-offline.ts +5 -2
  16. package/src/document-styles.ts +1 -1
  17. package/src/error-contract.ts +160 -32
  18. package/src/error-unthrown.ts +44 -16
  19. package/src/exec.ts +3 -2
  20. package/src/fix-sequence.ts +1 -14
  21. package/src/flag-reads.ts +4 -1
  22. package/src/generate-grant-findings.ts +14 -4
  23. package/src/generate-write.ts +1 -1
  24. package/src/gh.ts +1 -1
  25. package/src/guards.ts +2 -2
  26. package/src/handle-registration.ts +4 -3
  27. package/src/hold.ts +1 -1
  28. package/src/i18n-index.ts +1 -1
  29. package/src/index.ts +5 -1
  30. package/src/island-capture.ts +1 -1
  31. package/src/island-harness-route.ts +1 -1
  32. package/src/island-routes.ts +1 -1
  33. package/src/island-shot-errors.ts +2 -2
  34. package/src/job-registration.ts +1 -1
  35. package/src/live-routes.ts +8 -7
  36. package/src/mcp-host-shell.ts +1 -1
  37. package/src/mcp-ui.ts +1 -1
  38. package/src/measure-paths.ts +1 -1
  39. package/src/permission-grants.ts +1 -1
  40. package/src/publish-closure.ts +2 -1
  41. package/src/role-load.ts +1 -1
  42. package/src/role-realtime.ts +1 -1
  43. package/src/runtime-cache.ts +2 -2
  44. package/src/runtime-storage-boot.ts +2 -2
  45. package/src/style-routes.ts +1 -1
  46. package/src/tsconfig-references.ts +1 -1
  47. package/src/verify-role-load.ts +1 -1
  48. package/src/worker-bundle.ts +1 -1
  49. package/src/workspace-checks.ts +11 -7
  50. package/src/workspace-graph.ts +2 -2
  51. package/wiki/CLI-Reference.md +3 -3
  52. package/wiki/N-Plus-One-Detection.md +1 -1
  53. package/wiki/Queries-And-Live-Queries.md +1 -1
@@ -14,6 +14,7 @@ import { createHelperResolver } from './fix-imports';
14
14
  import { citedPathProblem, FILE_TOKEN_PATTERN } from './fix-path';
15
15
  import { scanFixSites } from './fix-scan';
16
16
  import type { Finding } from './output';
17
+ import { quoteArg } from './shell-quote';
17
18
  import { eachSourceFile, isGenerated, isTest } from './source-files';
18
19
  import type { CodeSite, FixSite, UnresolvedCodeSite } from './ts-scan';
19
20
  import { isCodeRegistry, scanBorrowedCodes, scanCodeDeclarations, scanCodes } from './ts-scan';
@@ -72,7 +73,7 @@ export function fixProblem(raw: string): string | undefined {
72
73
  const fixFinding = (site: FixSite, problem: string): Finding => ({
73
74
  code: 'X_ERROR_FIX_INVALID',
74
75
  cause: problem,
75
- fix: `rewrite the fix at ${site.at}:${site.line} as a command to run, a call to paste, or an edit naming a file`,
76
+ fix: `edit ${site.at}:${site.line} — rewrite the fix as a command to run, a call to paste, or an edit naming a file`,
76
77
  docs: ERROR_DOCS_URL,
77
78
  at: `${site.at}:${site.line}`,
78
79
  });
@@ -85,7 +86,7 @@ const fixFinding = (site: FixSite, problem: string): Finding => ({
85
86
  const pathFinding = (site: FixSite, problem: string): Finding => ({
86
87
  code: 'X_ERROR_FIX_PATH_MISSING',
87
88
  cause: `the fix at ${site.at}:${site.line} ${problem}`,
88
- fix: `correct the path in the fix at ${site.at}:${site.line} to one this repo holds, or create the file it names`,
89
+ fix: `edit ${site.at}:${site.line} — correct the path in the fix to one this repo holds, or create the file it names`,
89
90
  docs: ERROR_DOCS_URL,
90
91
  at: `${site.at}:${site.line}`,
91
92
  });
@@ -178,17 +179,87 @@ export const checkErrorFixes = async (root: string): Promise<readonly Finding[]>
178
179
  (await checkErrorFixReport(root)).findings;
179
180
 
180
181
  /**
181
- * A code is documented when the reference page names it. Deliberately not "owns a table row": the
182
- * page legitimately groups near-identical codes onto one row, and a rule that forbade that would
183
- * be a rule about formatting rather than about coverage.
182
+ * One page of the error reference as the host read it, `path` relative to the repo root. The
183
+ * reference is a SET — an index (`wiki/Error-Codes.md`, which holds the reserved block) and one
184
+ * `Error-Codes-<owner>.md` per owner — and every rule here reads the whole set: a check handed one
185
+ * page would read every other owner's code as undocumented, or every ghost on them as absent.
184
186
  */
187
+ export interface ErrorCodePage {
188
+ readonly path: string;
189
+ readonly text: string;
190
+ }
191
+
192
+ /** Where the index lives when the host read no page at all: the framework's own reference. */
193
+ const DEFAULT_INDEX = 'wiki/Error-Codes.md';
194
+ const INDEX_NAME = 'Error-Codes.md';
195
+
196
+ /**
197
+ * The index of the set — the page the reserved block lives on. A set with no `Error-Codes.md` is
198
+ * one page a deprecated single-page caller named, and that page is its own index.
199
+ */
200
+ export const errorCodeIndex = (pages: readonly ErrorCodePage[]): string =>
201
+ pages.find((page) => page.path === INDEX_NAME || page.path.endsWith(`/${INDEX_NAME}`))?.path ??
202
+ pages[0]?.path ??
203
+ DEFAULT_INDEX;
204
+
205
+ /**
206
+ * Who owns a declaration, read off its path: a package by its directory name, anything else by its
207
+ * top directory (`scripts`). The same rule `scripts/manifest.ts`' `ownerOf` files a code under in
208
+ * `framework.manifest.json`, so the page this names is the page the manifest says it lives on.
209
+ */
210
+ function errorCodeOwner(at: string): string {
211
+ const segments = at.split('/');
212
+ return (segments[0] === 'packages' ? segments[1] : segments[0]) ?? '';
213
+ }
214
+
215
+ /** The owner page a code's row belongs on: `Error-Codes-<owner>.md`, beside the index. */
216
+ function errorCodeOwnerPage(pages: readonly ErrorCodePage[], at: string): string {
217
+ const index = errorCodeIndex(pages);
218
+ const dir = index.slice(0, index.lastIndexOf('/') + 1);
219
+ return `${dir}Error-Codes-${errorCodeOwner(at)}.md`;
220
+ }
221
+
222
+ const CODE_MENTION = /`(X_[A-Z0-9_]+)`/g;
223
+
224
+ /** Pages in path order, so "the first page naming a code" is the same answer on every machine. */
225
+ const byPath = (pages: readonly ErrorCodePage[]): readonly ErrorCodePage[] =>
226
+ [...pages].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
227
+
228
+ const mentionsOf = (
229
+ pages: readonly ErrorCodePage[],
230
+ textOf: (page: ErrorCodePage) => string,
231
+ ): ReadonlyMap<string, string> => {
232
+ const out = new Map<string, string>();
233
+ for (const page of byPath(pages)) {
234
+ for (const match of textOf(page).matchAll(CODE_MENTION)) {
235
+ const code = match[1] as string;
236
+ if (!out.has(code)) out.set(code, page.path);
237
+ }
238
+ }
239
+ return out;
240
+ };
241
+
242
+ /**
243
+ * A code is documented when a page of the set names it — code → the first page (by path) that
244
+ * does. Deliberately not "owns a table row": a page legitimately groups near-identical codes onto
245
+ * one row, and a rule that forbade that would be a rule about formatting rather than coverage. The
246
+ * index's generated "every code" table names each code plain, never in backticks, so it documents
247
+ * nothing on its own: the row on the owner page (or the reserved block) does.
248
+ */
249
+ export const documentedCodesIn = (pages: readonly ErrorCodePage[]): ReadonlyMap<string, string> =>
250
+ mentionsOf(pages, (page) => page.text);
251
+
252
+ /** The one-page set a deprecated single-page caller's markdown stands for. */
253
+ const legacyPage = (text: string): readonly ErrorCodePage[] => [{ path: DEFAULT_INDEX, text }];
254
+
255
+ /** @deprecated Use documentedCodesIn(pages) — the error reference is a page set since 31.35.0; removed at the next major. */
185
256
  export const documentedCodes = (markdown: string): ReadonlySet<string> =>
186
- new Set([...markdown.matchAll(/`(X_[A-Z0-9_]+)`/g)].map((match) => match[1] as string));
257
+ new Set(documentedCodesIn(legacyPage(markdown)).keys());
187
258
 
188
259
  const undocumentedFinding = (code: string, at: string, line: number, page: string): Finding => ({
189
260
  code: 'X_ERROR_CODE_UNDOCUMENTED',
190
- cause: `${code} is declared at ${at}:${line} and ${page} has no entry for it`,
191
- fix: `add a row for ${code} to ${page}, with its cause and the command that fixes it`,
261
+ cause: `${code} is declared at ${at}:${line} and no error reference page has an entry for it`,
262
+ fix: `x errors explain ${quoteArg(code)} --json # its title and fix: add a row for ${code} to ${page}, with its cause and the command that fixes it`,
192
263
  docs: ERROR_DOCS_URL,
193
264
  at: page,
194
265
  });
@@ -197,12 +268,12 @@ const undocumentedFinding = (code: string, at: string, line: number, page: strin
197
268
  * The heading below which the reference stops making live claims. What follows is a code that is
198
269
  * reserved (documented, nothing throws it yet) or a superseded name kept so an old log line still
199
270
  * resolves. Both earn their rows; neither is a code an agent can be handed today, which is the
200
- * only thing the registry rule below is about.
271
+ * only thing the registry rule below is about. It lives on the index; an owner page has none.
201
272
  */
202
273
  export const RESERVED_HEADING = '## Reserved codes';
203
274
 
204
275
  /**
205
- * The codes the reference presents as live: every one named above the reserved section.
276
+ * One page's live text: everything above its reserved heading, or all of it.
206
277
  *
207
278
  * The heading is matched as a whole line, never as a substring. The same text is quoted in prose,
208
279
  * in a fenced sample and in this file's own `unregisteredFinding` fix — and `indexOf` would cut the
@@ -210,16 +281,34 @@ export const RESERVED_HEADING = '## Reserved codes';
210
281
  * registry rule. A gate that stops reading halfway through the page reads green over the half it
211
282
  * never saw.
212
283
  */
213
- export function liveCodes(markdown: string): ReadonlySet<string> {
284
+ const liveText = (markdown: string): string => {
214
285
  const lines = markdown.split('\n');
215
286
  const cut = lines.findIndex((line) => line.trim() === RESERVED_HEADING);
216
- return documentedCodes(cut === -1 ? markdown : lines.slice(0, cut).join('\n'));
287
+ return cut === -1 ? markdown : lines.slice(0, cut).join('\n');
288
+ };
289
+
290
+ /** The codes the reference presents as live — code → the first page naming it above any cut. */
291
+ export const liveCodesIn = (pages: readonly ErrorCodePage[]): ReadonlyMap<string, string> =>
292
+ mentionsOf(pages, (page) => liveText(page.text));
293
+
294
+ /** @deprecated Use liveCodesIn(pages) — the error reference is a page set since 31.35.0; removed at the next major. */
295
+ export function liveCodes(markdown: string): ReadonlySet<string> {
296
+ return new Set(liveCodesIn(legacyPage(markdown)).keys());
217
297
  }
218
298
 
219
- const unregisteredFinding = (code: string, page: string): Finding => ({
299
+ /** A deprecated caller's one page, read off disk: `undefined` when it is not there. */
300
+ export async function readLegacyPage(
301
+ root: string,
302
+ page: string,
303
+ ): Promise<readonly ErrorCodePage[] | undefined> {
304
+ const file = Bun.file(join(root, page));
305
+ return (await file.exists()) ? [{ path: page, text: await file.text() }] : undefined;
306
+ }
307
+
308
+ const unregisteredFinding = (code: string, page: string, index: string): Finding => ({
220
309
  code: 'X_ERROR_CODE_UNREGISTERED',
221
310
  cause: `${page} documents ${code} as a live code and nothing registers it, so "x errors explain ${code}" refuses a code this page promises`,
222
- fix: `register ${code} through registerErrorCodes() in its package's src/errors.ts, or move its row under "${RESERVED_HEADING}" in ${page}`,
311
+ fix: `registerErrorCodes({ ${code}: { title: '<what it means>' } }) // in its package's src/errors.ts — or move its row under "${RESERVED_HEADING}" in ${index}`,
223
312
  docs: ERROR_DOCS_URL,
224
313
  at: page,
225
314
  });
@@ -232,19 +321,27 @@ const unregisteredFinding = (code: string, page: string): Finding => ({
232
321
  *
233
322
  * `known` is what the host can answer for: the process-wide registry, plus whatever codes the host
234
323
  * repo's own gate scripts declare (`X_ROADMAP_*` and friends never ship, so no package may own
235
- * them). A missing page is `checkErrorCodeDocs`'s finding to report, not a second copy here.
324
+ * them). An empty reference is `checkErrorCodeDocsIn`'s finding to report, not a second copy here.
236
325
  */
326
+ export function checkErrorCodeRegistryIn(
327
+ pages: readonly ErrorCodePage[],
328
+ known: ReadonlySet<string>,
329
+ ): readonly Finding[] {
330
+ const index = errorCodeIndex(pages);
331
+ return [...liveCodesIn(pages)]
332
+ .filter(([code]) => !known.has(code))
333
+ .sort(([a], [b]) => a.localeCompare(b))
334
+ .map(([code, page]) => unregisteredFinding(code, page, index));
335
+ }
336
+
337
+ /** @deprecated Use checkErrorCodeRegistryIn(pages, known) — the error reference is a page set since 31.35.0; removed at the next major. */
237
338
  export async function checkErrorCodeRegistry(
238
339
  root: string,
239
340
  page: string,
240
341
  known: ReadonlySet<string>,
241
342
  ): Promise<readonly Finding[]> {
242
- const reference = Bun.file(join(root, page));
243
- if (!(await reference.exists())) return [];
244
- return [...liveCodes(await reference.text())]
245
- .filter((code) => !known.has(code))
246
- .sort()
247
- .map((code) => unregisteredFinding(code, page));
343
+ const pages = await readLegacyPage(root, page);
344
+ return pages === undefined ? [] : checkErrorCodeRegistryIn(pages, known);
248
345
  }
249
346
 
250
347
  /**
@@ -304,7 +401,7 @@ export async function collectDeclaredCodes(root: string): Promise<readonly CodeS
304
401
  const unresolvedCodeFinding = (site: UnresolvedCodeSite): Finding => ({
305
402
  code: 'X_ERROR_CODE_UNRESOLVED',
306
403
  cause: `the code at ${site.at}:${site.line} is the name ${site.name}, and no module-scope const in that file gives it a value — so the manifest, the reference page and "x errors explain" are all blind to whatever code it holds`,
307
- fix: `write the X_* code as a string literal at ${site.at}:${site.line}, or declare it as a module-scope const in that same file`,
404
+ fix: `edit ${site.at}:${site.line} — write the X_* code as a string literal, or declare it as a module-scope const in that same file`,
308
405
  docs: ERROR_DOCS_URL,
309
406
  at: `${site.at}:${site.line}`,
310
407
  });
@@ -327,26 +424,57 @@ export async function checkErrorCodeResolution(root: string): Promise<readonly F
327
424
  return findings;
328
425
  }
329
426
 
427
+ /** A declared code no page names, reported where `rowPage` says its row belongs. */
428
+ async function undocumentedIn(
429
+ root: string,
430
+ pages: readonly ErrorCodePage[],
431
+ rowPage: (at: string) => string,
432
+ ): Promise<readonly Finding[]> {
433
+ const documented = documentedCodesIn(pages);
434
+ return (await collectDeclaredCodes(root))
435
+ .filter((site) => !documented.has(site.code))
436
+ .map((site) => undocumentedFinding(site.code, site.at, site.line, rowPage(site.at)));
437
+ }
438
+
330
439
  /**
331
- * Every `X_*` code shipped source declares must appear on the repo's error reference. The page is
332
- * the host repo's to name — a framework monorepo publishes one, a generated app does not — which
333
- * is why this arrives through the same host-check seam the tier table uses on `boundaries`.
440
+ * Every `X_*` code shipped source declares must appear on the repo's error reference — on some page
441
+ * of the set, and a missing one is owed on its owner's page. The set is the host repo's to name — a
442
+ * framework monorepo publishes one, a generated app does not — which is why this arrives through
443
+ * the same host-check seam the tier table uses on `boundaries`.
334
444
  */
445
+ export async function checkErrorCodeDocsIn(
446
+ root: string,
447
+ pages: readonly ErrorCodePage[],
448
+ ): Promise<readonly Finding[]> {
449
+ if (pages.length === 0) {
450
+ return [
451
+ {
452
+ code: 'X_ERROR_CODE_UNDOCUMENTED',
453
+ cause: 'the error reference has no page, so no code can be documented',
454
+ fix: `git restore --source=HEAD -- wiki/Error-Codes.md 'wiki/Error-Codes-*.md' # the pages were deleted; a new repo creates them with bun run new-error-code`,
455
+ docs: ERROR_DOCS_URL,
456
+ at: DEFAULT_INDEX,
457
+ },
458
+ ];
459
+ }
460
+ return undocumentedIn(root, pages, (at) => errorCodeOwnerPage(pages, at));
461
+ }
462
+
463
+ /** @deprecated Use checkErrorCodeDocsIn(root, pages) — the error reference is a page set since 31.35.0; removed at the next major. */
335
464
  export async function checkErrorCodeDocs(root: string, page: string): Promise<readonly Finding[]> {
336
- const reference = Bun.file(join(root, page));
337
- if (!(await reference.exists())) {
465
+ const pages = await readLegacyPage(root, page);
466
+ if (pages === undefined) {
338
467
  return [
339
468
  {
340
469
  code: 'X_ERROR_CODE_UNDOCUMENTED',
341
470
  cause: `the error reference ${page} does not exist, so no code can be documented`,
342
- fix: `create ${page} with a row per X_* code, or stop naming it as the error reference`,
471
+ // Line 1 is real: the page does not exist, so the edit starts it.
472
+ fix: `edit ${page}:1 — create it with a row per X_* code, or stop naming it as the error reference`,
343
473
  docs: ERROR_DOCS_URL,
344
474
  at: page,
345
475
  },
346
476
  ];
347
477
  }
348
- const documented = documentedCodes(await reference.text());
349
- return (await collectDeclaredCodes(root))
350
- .filter((site) => !documented.has(site.code))
351
- .map((site) => undocumentedFinding(site.code, site.at, site.line, page));
478
+ // The one page is where every row goes: a single-page reference has no owner pages.
479
+ return undocumentedIn(root, pages, () => page);
352
480
  }
@@ -8,7 +8,13 @@
8
8
  // why: Bun ships no path API; `join` builds the absolute path of each scanned file.
9
9
  import { join } from 'node:path';
10
10
  import { ERROR_DOCS_URL, maskLiterals, stripComments } from '@ultimat3/core';
11
- import { RESERVED_HEADING } from './error-contract';
11
+ import type { ErrorCodePage } from './error-contract';
12
+ import {
13
+ documentedCodesIn,
14
+ errorCodeIndex,
15
+ RESERVED_HEADING,
16
+ readLegacyPage,
17
+ } from './error-contract';
12
18
  import type { Finding } from './output';
13
19
  import { eachSourceFile, isGenerated, isTest } from './source-files';
14
20
  import { isCodeRegistry } from './ts-scan';
@@ -91,18 +97,28 @@ export async function collectCodeUse(root: string): Promise<CodeUse> {
91
97
  return { registered, used };
92
98
  }
93
99
 
94
- /** Codes that sit under the reserved heading — declared unthrown by WHERE they are, not by words. */
95
- export function declaredUnthrown(markdown: string): ReadonlySet<string> {
100
+ /**
101
+ * Codes that sit under a reserved heading — declared unthrown by WHERE they are, not by words. The
102
+ * heading lives on the index; each page is read on its own, so its cut never leaks onto the next.
103
+ */
104
+ export function declaredUnthrownIn(pages: readonly ErrorCodePage[]): ReadonlySet<string> {
96
105
  const out = new Set<string>();
97
- let reserved = false;
98
- for (const line of markdown.split('\n')) {
99
- if (line.trim() === RESERVED_HEADING) reserved = true;
100
- const row = /^\|\s*`(X_[A-Z0-9_]+)`\s*\|/.exec(line);
101
- if (row !== null && reserved) out.add(row[1] ?? '');
106
+ for (const page of pages) {
107
+ let reserved = false;
108
+ for (const line of page.text.split('\n')) {
109
+ if (line.trim() === RESERVED_HEADING) reserved = true;
110
+ const row = /^\|\s*`(X_[A-Z0-9_]+)`\s*\|/.exec(line);
111
+ if (row !== null && reserved) out.add(row[1] ?? '');
112
+ }
102
113
  }
103
114
  return out;
104
115
  }
105
116
 
117
+ /** @deprecated Use declaredUnthrownIn(pages) — the error reference is a page set since 31.35.0; removed at the next major. */
118
+ export function declaredUnthrown(markdown: string): ReadonlySet<string> {
119
+ return declaredUnthrownIn([{ path: 'wiki/Error-Codes.md', text: markdown }]);
120
+ }
121
+
106
122
  const unthrownFinding = (code: string, page: string): Finding => ({
107
123
  code: 'X_ERROR_CODE_UNTHROWN',
108
124
  cause: `${code} is registered and ${page} presents it as live, but no shipped source constructs it — a reader matching on it waits for an error that cannot arrive. Add it to UNTHROWN_CODES in ${UNTHROWN_CODES_FILE} and say so in its row, or throw it again where it belongs`,
@@ -123,22 +139,25 @@ const staleFinding = (code: string): Finding => ({
123
139
 
124
140
  /**
125
141
  * Registered, used by nothing, and not declared unthrown on the reference. A host check — the page
126
- * is the host repo's to name, and only a monorepo's walk sees every package's source; in a
127
- * generated app every framework code would read as unthrown.
142
+ * set is the host repo's to name, and only a monorepo's walk sees every package's source; in a
143
+ * generated app every framework code would read as unthrown. Reported at the page whose row
144
+ * presents the code as live, or the index when no page names it. An empty set reports nothing:
145
+ * `checkErrorCodeDocsIn` owns that finding.
128
146
  */
129
- export async function checkErrorCodesThrown(
147
+ export async function checkErrorCodesThrownIn(
130
148
  root: string,
131
- page: string,
149
+ pages: readonly ErrorCodePage[],
132
150
  listed: ReadonlySet<string> = UNTHROWN_CODES,
133
151
  ): Promise<readonly Finding[]> {
134
- const reference = Bun.file(join(root, page));
135
- if (!(await reference.exists())) return [];
136
- const reserved = declaredUnthrown(await reference.text());
152
+ if (pages.length === 0) return [];
153
+ const reserved = declaredUnthrownIn(pages);
154
+ const documented = documentedCodesIn(pages);
155
+ const index = errorCodeIndex(pages);
137
156
  const { registered, used } = await collectCodeUse(root);
138
157
  const unthrown = [...registered]
139
158
  .filter((code) => !used.has(code) && !listed.has(code) && !reserved.has(code))
140
159
  .sort()
141
- .map((code) => unthrownFinding(code, page));
160
+ .map((code) => unthrownFinding(code, documented.get(code) ?? index));
142
161
  // Only the THROWN-again direction: a listed name no registry holds waives nothing (the code it
143
162
  // was meant to name is still reported), and a host repo's fixture registering none of this
144
163
  // repo's codes would otherwise read every listing as stale.
@@ -148,3 +167,12 @@ export async function checkErrorCodesThrown(
148
167
  .map((code) => staleFinding(code));
149
168
  return [...unthrown, ...stale];
150
169
  }
170
+
171
+ /** @deprecated Use checkErrorCodesThrownIn(root, pages, listed) — the error reference is a page set since 31.35.0; removed at the next major. */
172
+ export async function checkErrorCodesThrown(
173
+ root: string,
174
+ page: string,
175
+ listed: ReadonlySet<string> = UNTHROWN_CODES,
176
+ ): Promise<readonly Finding[]> {
177
+ return checkErrorCodesThrownIn(root, (await readLegacyPage(root, page)) ?? [], listed);
178
+ }
package/src/exec.ts CHANGED
@@ -99,7 +99,8 @@ function spawnOrRefuse(command: readonly string[], options: ExecOptions) {
99
99
  throw new UltimateError({
100
100
  code: 'X_CLI_UNEXPECTED',
101
101
  cause: `the CLI could not run "${head}" from ${options.cwd}: ${renderThrowable(error)}`,
102
- fix: `install ${quoteArg(head)} and put it on PATH, then re-run — confirm with: command -v ${quoteArg(head)}`,
102
+ // `Bun.which`, not `command -v`: the one lookup this process ran, and a word every shell runs.
103
+ fix: `bun --print ${quoteArg(`Bun.which(${JSON.stringify(head)})`)} # null: install ${quoteArg(head)} and put it on PATH, then re-run`,
103
104
  });
104
105
  }
105
106
  }
@@ -114,7 +115,7 @@ export const exec: Runner = async (command, options) => {
114
115
  throw new UltimateError({
115
116
  code: 'X_CLI_UNEXPECTED',
116
117
  cause: 'exec() was called with an empty command, so there is no program to spawn',
117
- fix: 'pass the program as the first element: exec(["bun", "test"], { cwd })',
118
+ fix: 'exec(["bun", "test"], { cwd }) // the program as the first element',
118
119
  });
119
120
  }
120
121
  const proc = spawnOrRefuse([head, ...rest], options);
@@ -54,6 +54,7 @@ export function generatorForceProblem(fix: string): string | undefined {
54
54
  * `packages/docs-source/src/errors.ts` is the one app entry). A file at or under its count passes;
55
55
  * one past it, or any file not listed — every app's — is a finding at each of its refused lines.
56
56
  * Held EQUAL to the step's counts by `fix-sequence.test.ts`: rewrite a line, lower its entry.
57
+ * 2026-11-16 (sweep 8b-4): 30 lines in 23 files — `scripts/` rewritten edit-first, none left.
57
58
  */
58
59
  export const FIX_SEQUENCE_BASELINE: ReadonlyMap<string, number> = new Map([
59
60
  ['packages/cli/src/cmd-client-customer.ts', 1],
@@ -71,8 +72,6 @@ export const FIX_SEQUENCE_BASELINE: ReadonlyMap<string, number> = new Map([
71
72
  ['packages/db/src/lifecycle-errors.ts', 1],
72
73
  ['packages/db/src/primary-key.ts', 1],
73
74
  ['packages/docs-source/src/errors.ts', 4],
74
- ['packages/entity/src/partition.ts', 1],
75
- ['packages/entity/src/retain.ts', 1],
76
75
  ['packages/jobs/src/subject-errors.ts', 1],
77
76
  ['packages/mail/src/preview-check.ts', 1],
78
77
  ['packages/mcp/src/meta-errors.ts', 1],
@@ -81,16 +80,4 @@ export const FIX_SEQUENCE_BASELINE: ReadonlyMap<string, number> = new Map([
81
80
  ['packages/seo/src/errors.ts', 1],
82
81
  ['packages/testing/src/exercise-override-input.ts', 1],
83
82
  ['packages/testing/src/plan-sweep-report.ts', 4],
84
- ['scripts/adapter-ports.ts', 4],
85
- ['scripts/bench-claims.ts', 1],
86
- ['scripts/budget-raises.ts', 1],
87
- ['scripts/declaration-readers-callers.ts', 2],
88
- ['scripts/factory-names.ts', 2],
89
- ['scripts/instrument-slots.ts', 1],
90
- ['scripts/lib/export-all.ts', 1],
91
- ['scripts/new-error-code.ts', 1],
92
- ['scripts/plan-status.ts', 3],
93
- ['scripts/posix-relative.ts', 1],
94
- ['scripts/set-cookie-literals.ts', 2],
95
- ['scripts/sql-export-readers.ts', 1],
96
83
  ]);
package/src/flag-reads.ts CHANGED
@@ -62,7 +62,10 @@ const declaresFlag = (text: string, name: string): boolean =>
62
62
  const unreadFinding = (declared: DeclaredFlag, at: string): Finding => ({
63
63
  code: 'X_CLI_FLAG_UNREAD',
64
64
  cause: `x ${declared.command} declares --${declared.flag.name} ("${declared.flag.summary}") and no file in the CLI's source reads it, so the flag parses and changes nothing`,
65
- fix: `read it in ${at} with flag${declared.flag.type === 'boolean' ? 'Bool' : 'String'}(ctx.args, '${declared.flag.name}'), or delete it from the spec's flags`,
65
+ fix:
66
+ declared.flag.type === 'boolean'
67
+ ? `flagBool(ctx.args, '${declared.flag.name}') // read it in ${at} — or delete it from the spec's flags`
68
+ : `flagString(ctx.args, '${declared.flag.name}') // read it in ${at} — or delete it from the spec's flags`,
66
69
  docs: ERROR_DOCS_URL,
67
70
  at,
68
71
  });
@@ -16,15 +16,25 @@ import {
16
16
  import type { Finding } from './output';
17
17
  import { ROLES_FILE } from './permission-grants';
18
18
 
19
- /** `member: 'run:read'; admin: 'run:write', 'runs:read'` — each role, and what its `grants` owes. */
20
- const linesFor = (grants: readonly RoleGrant[]): string => {
19
+ /** Each role, and the quoted permissions its `grants` owes, in first-seen order. */
20
+ const byRoleOf = (grants: readonly RoleGrant[]): ReadonlyMap<string, readonly string[]> => {
21
21
  const byRole = new Map<string, string[]>();
22
22
  for (const grant of grants) {
23
23
  byRole.set(grant.role, [...(byRole.get(grant.role) ?? []), `'${grant.permission}'`]);
24
24
  }
25
- return [...byRole].map(([role, permissions]) => `${role}: ${permissions.join(', ')}`).join('; ');
25
+ return byRole;
26
26
  };
27
27
 
28
+ /** `member: 'run:read'; admin: 'run:write', 'runs:read'` — each role, and what its `grants` owes. */
29
+ const linesFor = (grants: readonly RoleGrant[]): string =>
30
+ [...byRoleOf(grants)].map(([role, owed]) => `${role}: ${owed.join(', ')}`).join('; ');
31
+
32
+ /** `member: { grants: [..., 'run:read'] }` — the same, as role-map entries to merge in. */
33
+ const roleEntries = (grants: readonly RoleGrant[]): string =>
34
+ [...byRoleOf(grants)]
35
+ .map(([role, owed]) => `${role}: { grants: [..., ${owed.join(', ')}] }`)
36
+ .join(', ');
37
+
28
38
  /** The grants the role map as it stands still lacks: no such role, no `grants`, or undeclared. */
29
39
  function stillMissing(source: string, grants: readonly RoleGrant[], admin: readonly RoleGrant[]) {
30
40
  const undeclared = insertPermissions(
@@ -71,7 +81,7 @@ export async function ungrantedByGenerator(
71
81
  {
72
82
  code: 'X_PERMISSION_UNGRANTED',
73
83
  cause: `${ROLES_FILE} has no role, no "grants: [...]" list or no definePermissions([...]) these could be safely added to, so nothing granted: ${linesFor(missing)}`,
74
- fix: `edit ${ROLES_FILE} — add to each role's grants (and declare any the map does not know in definePermissions([...])) — ${linesFor(missing)} — then x verify --only policy`,
84
+ fix: `{ ${roleEntries(missing)} } // merge into the role map in ${ROLES_FILE}, declaring any the map does not know in definePermissions([...]) — then x verify --only policy`,
75
85
  at: ROLES_FILE,
76
86
  },
77
87
  ];
@@ -137,7 +137,7 @@ async function planJsonMerge(
137
137
  finding: {
138
138
  code: 'X_GENERATE_CONFLICT',
139
139
  cause: `${file.path} exists but is not a JSON object, so its keys cannot be merged`,
140
- fix: `edit ${file.path} by hand until it parses as a JSON object, or delete it and re-run x g`,
140
+ fix: `bun --print ${quoteArg(`JSON.parse(await Bun.file(${JSON.stringify(file.path)}).text())`)} # its parse error, from the app root: edit it until it is a JSON object, or delete it and re-run x g`,
141
141
  docs: ERROR_DOCS_URL,
142
142
  at: file.path,
143
143
  },
package/src/gh.ts CHANGED
@@ -44,7 +44,7 @@ export class GhUnavailableError extends UltimateError {
44
44
  super({
45
45
  code: 'X_GH_UNAVAILABLE',
46
46
  cause: `the GitHub CLI could not be run from ${input.cwd}: ${input.detail}`,
47
- fix: 'install the GitHub CLI from https://cli.github.com, then run: gh auth login',
47
+ fix: 'bun --print \'Bun.which("gh")\' # null: install the GitHub CLI from https://cli.github.com, then: gh auth login',
48
48
  });
49
49
  }
50
50
  }
package/src/guards.ts CHANGED
@@ -119,7 +119,7 @@ function findingOf(value: Record<string, unknown>, at: string): Finding {
119
119
  const failed = (path: string, cause: string): Finding => ({
120
120
  code: 'X_GUARD_FAILED',
121
121
  cause,
122
- fix: `return a finding from ${path} instead of throwing, then: x verify`,
122
+ fix: `{ code: 'X_<YOURS>', cause: '<what is wrong>', fix: '<a command or a file>' } // what ${path} returns instead of throwing — then: x verify --only boundaries --json`,
123
123
  docs: ERROR_DOCS_URL,
124
124
  at: path,
125
125
  });
@@ -160,7 +160,7 @@ const notADirectory: Finding = {
160
160
  const findingInvalid = (path: string, cause: string): Finding => ({
161
161
  code: 'X_GUARD_FINDING_INVALID',
162
162
  cause: `${path} returned a finding that is not one: ${cause}`,
163
- fix: `rewrite what ${path} returns as a code, a cause and a fix naming a command or a file, then: x verify`,
163
+ fix: `{ code: 'X_<YOURS>', cause: '<what is wrong>', fix: '<a command or a file>' } // what ${path} returns, then: x verify`,
164
164
  docs: ERROR_DOCS_URL,
165
165
  at: path,
166
166
  });
@@ -42,7 +42,8 @@ export const resolveDbModule = async (root: string): Promise<string | undefined>
42
42
  export const handleUnregisteredFinding = (entry: HandleEntry, reason: string): Finding => ({
43
43
  code: 'X_DB_HANDLE_UNREGISTERED',
44
44
  cause: `${HANDLE_FILE} ${reason}, so db.${entry.key} does not exist and the generated repo.ts does not compile`,
45
- fix: `add ${handleImportLine(entry)} and the line "${handleEntryLine(entry).trim()}" to the entity set passed to database() in ${HANDLE_FILE}`,
45
+ // Opened with the import itself: `handleImportLine`'s own text, so the two can never disagree.
46
+ fix: `import ${handleImportLine(entry).slice('import '.length)} // in ${HANDLE_FILE}, with the line "${handleEntryLine(entry).trim()}" in the entity set passed to database()`,
46
47
  docs: ERROR_DOCS_URL,
47
48
  at: HANDLE_FILE,
48
49
  });
@@ -181,7 +182,7 @@ async function indexFindings(disk: GenerateDisk, dbModule: string): Promise<read
181
182
  {
182
183
  code: 'X_DB_HANDLE_UNREGISTERED',
183
184
  cause: `${INDEX_FILE} does not export the typed handle, so "import { db } from '${dbModule}'" in the generated repo.ts is not database()'s`,
184
- fix: `add export { db, driver, selectDriver } from './client'; to ${INDEX_FILE} and drop db from its '@ultimat3/db' re-export`,
185
+ fix: `export { db, driver, selectDriver } from './client'; // in ${INDEX_FILE} — and drop db from its '@ultimat3/db' re-export`,
185
186
  docs: ERROR_DOCS_URL,
186
187
  at: INDEX_FILE,
187
188
  },
@@ -241,7 +242,7 @@ export async function registerGeneratedEntities(
241
242
  findings.push({
242
243
  code: 'X_DB_HANDLE_UNREGISTERED',
243
244
  cause: `${DB_WORKSPACE}/package.json supplies no "name", so the generated repo.ts imports the placeholder ${PLACEHOLDER_DB_MODULE}`,
244
- fix: `add "name": "@<app>/db" to ${DB_WORKSPACE}/package.json, then re-run this command with --force`,
245
+ fix: `{ "name": "@<app>/db" } // in ${DB_WORKSPACE}/package.json, then re-run this command with --force`,
245
246
  docs: ERROR_DOCS_URL,
246
247
  at: `${DB_WORKSPACE}/package.json`,
247
248
  });
package/src/hold.ts CHANGED
@@ -229,7 +229,7 @@ async function releaseWithin(
229
229
  // Rounded: `deadlineAt - monotonic()` is a float, and `4923.185900000001ms` in a shutdown
230
230
  // log reads as a bug in the number rather than as the budget it is.
231
231
  cause: `the "${name}" release was still running ${Math.round(budgetMs)}ms after the drain finished and has been ABANDONED — the process exits without it, so anything it held may not be closed`,
232
- fix: 'raise the budget past the slowest teardown — configureLifecycle({ deadlineMs: 600_000 }) for a 10-minute one — and set terminationGracePeriodSeconds to at least as many seconds',
232
+ fix: 'configureLifecycle({ deadlineMs: 600_000 }) // a budget past the slowest teardown, 10 minutes here — and set terminationGracePeriodSeconds to at least as many seconds',
233
233
  });
234
234
  return false;
235
235
  } finally {
package/src/i18n-index.ts CHANGED
@@ -99,6 +99,6 @@ function withLocales(source: string, locales: readonly string[]): string | undef
99
99
  const refusal = (locales: readonly string[]): Finding => ({
100
100
  code: 'X_CATALOG_UNREGISTERED',
101
101
  cause: `${APP_CATALOGS_PATH} is hand-written in a shape this writer cannot add ${locales.join(', ')} to, so those catalogs are on disk and not selectable`,
102
- fix: `edit ${APP_CATALOGS_PATH} — add ${locales.map(localeImport).join(' ')} and ${locales.map(localeEntry).join(', ')} to the locales passed to defineCatalogs`,
102
+ fix: `defineCatalogs({ default, locales: { …, ${locales.map(localeEntry).join(', ')} } }) // in ${APP_CATALOGS_PATH}, below ${locales.map(localeImport).join(' ')}`,
103
103
  at: APP_CATALOGS_PATH,
104
104
  });
package/src/index.ts CHANGED
@@ -48,17 +48,21 @@ export { dispatch } from './dispatch';
48
48
  export { checkSourceDrift, reconcileSchemaHash, writeSchemaHash } from './drift';
49
49
  export { registeredErrorCodes } from './error-catalog';
50
50
  export type { CliErrorCode } from './error-codes';
51
+ export type { ErrorCodePage } from './error-contract';
51
52
  export {
52
53
  BANNED_PHRASES,
53
54
  COMMAND_TOKENS,
54
55
  checkErrorCodeDocs,
56
+ checkErrorCodeDocsIn,
55
57
  checkErrorCodeRegistry,
58
+ checkErrorCodeRegistryIn,
56
59
  checkErrorFixes,
57
60
  collectDeclaredCodes,
58
61
  documentedCodes,
62
+ documentedCodesIn,
59
63
  fixProblem,
60
64
  } from './error-contract';
61
- export { checkErrorCodesThrown } from './error-unthrown';
65
+ export { checkErrorCodesThrown, checkErrorCodesThrownIn } from './error-unthrown';
62
66
  export {
63
67
  BadFlagError,
64
68
  MissingPositionalError,
@@ -83,7 +83,7 @@ export function photographFault(
83
83
  return {
84
84
  reason:
85
85
  'was served a document that is not the shot harness — the dev server this run reused was booted against a different set of states files',
86
- fix: 'restart x dev, then run this command again',
86
+ fix: 'x stop --json && x dev # restart it against these states files, then run this command again',
87
87
  };
88
88
  }
89
89
  if (!seen.attached) {
@@ -72,7 +72,7 @@ export function islandHarnessRoutes(input: HarnessRouteInput): readonly Route[]
72
72
  if (manifest === undefined) {
73
73
  return refused(
74
74
  `this dev server declares no island states for ${address.island === '' ? '(no island named)' : address.island} — it knows ${islandStatesNames(all).join(', ') || 'none'}`,
75
- 'restart x dev, then: x shot --island <name> --json',
75
+ 'x stop --json && x dev # restart it, then: x shot --island <name> --json',
76
76
  );
77
77
  }
78
78
  // `wanted`, never a local called `state`: `bun run secret-compare` reads the NAME of a
@@ -43,7 +43,7 @@ export function islandRoutes(source: IslandSource): readonly Route[] {
43
43
  // were built at boot. `x build --target static` — which is what this said — writes
44
44
  // an export directory neither process serves from, so running it changed nothing
45
45
  // for the only two readers this line has ever had.
46
- fix: 'reload the page — this process serves only the chunks it built, and the document holding this URL came from an earlier build',
46
+ fix: 'location.reload() // in the browser — this process serves only the chunks it built, and the document holding this URL came from an earlier build',
47
47
  },
48
48
  },
49
49
  { status: 404 },