@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.
Files changed (206) hide show
  1. package/CLAUDE.md +47 -37
  2. package/README.md +19 -8
  3. package/package.json +29 -29
  4. package/src/app-manifest.ts +6 -1
  5. package/src/app-mcp.ts +17 -3
  6. package/src/cmd-cache-spec.ts +5 -2
  7. package/src/cmd-db-spec.ts +2 -3
  8. package/src/cmd-db.ts +0 -2
  9. package/src/cmd-deploy-verify-sample.ts +93 -0
  10. package/src/cmd-deploy-verify.ts +2 -41
  11. package/src/cmd-dev-spec.ts +15 -1
  12. package/src/cmd-dev.ts +31 -4
  13. package/src/cmd-doctor.ts +15 -4
  14. package/src/cmd-exercise-spec.ts +7 -1
  15. package/src/cmd-exercise.ts +22 -10
  16. package/src/cmd-generate.ts +2 -0
  17. package/src/cmd-jobs-spec.ts +3 -6
  18. package/src/cmd-jobs.ts +1 -7
  19. package/src/cmd-logs-spec.ts +2 -1
  20. package/src/cmd-logs.ts +9 -28
  21. package/src/cmd-planned.ts +11 -45
  22. package/src/cmd-profile-frames.ts +99 -0
  23. package/src/cmd-profile-spec.ts +24 -0
  24. package/src/cmd-profile.ts +164 -0
  25. package/src/cmd-repro-spec.ts +13 -1
  26. package/src/cmd-repro.ts +37 -5
  27. package/src/cmd-status-sample.ts +57 -0
  28. package/src/cmd-status-spec.ts +30 -0
  29. package/src/cmd-status.ts +108 -0
  30. package/src/cmd-token-spec.ts +5 -2
  31. package/src/cmd-token.ts +7 -3
  32. package/src/cmd-upgrade-codemods.ts +71 -0
  33. package/src/cmd-upgrade-spec.ts +19 -5
  34. package/src/cmd-upgrade.ts +91 -34
  35. package/src/codemods/agents-dev-mcp.ts +50 -0
  36. package/src/codemods/authenticator-session-refusal.ts +214 -0
  37. package/src/codemods/biome-no-default-export.ts +58 -0
  38. package/src/codemods/bunfig-island-coverage.ts +33 -0
  39. package/src/codemods/chart-dashboard.ts +73 -0
  40. package/src/codemods/ci-e2e-browser-stock.ts +75 -0
  41. package/src/codemods/ci-e2e-browser.ts +63 -0
  42. package/src/codemods/codemod.ts +58 -0
  43. package/src/codemods/define-error-leaf.ts +73 -0
  44. package/src/codemods/docs-ci-parts.ts +65 -0
  45. package/src/codemods/docs-gate-prose.ts +53 -0
  46. package/src/codemods/docs-island-rows.ts +31 -0
  47. package/src/codemods/docs-shipped-guards.ts +100 -0
  48. package/src/codemods/docs-test-services.ts +62 -0
  49. package/src/codemods/engine-diff.ts +104 -0
  50. package/src/codemods/engine-edits.ts +111 -0
  51. package/src/codemods/engine-fs.ts +95 -0
  52. package/src/codemods/engine.ts +191 -0
  53. package/src/codemods/format-edited-hook-3122.ts +28 -0
  54. package/src/codemods/format-edited-hook.ts +152 -0
  55. package/src/codemods/helm-alerts-objective.ts +105 -0
  56. package/src/codemods/helm-alerts-stock.ts +108 -0
  57. package/src/codemods/index.ts +56 -0
  58. package/src/codemods/metrics-probe-healthz.ts +47 -0
  59. package/src/codemods/pending.ts +36 -0
  60. package/src/codemods/repro-gitignore.ts +40 -0
  61. package/src/codemods/runtime-pin-lines.ts +109 -0
  62. package/src/codemods/runtime-pin.ts +116 -0
  63. package/src/codemods/solid-floor.ts +63 -0
  64. package/src/codemods/test-ports.ts +86 -0
  65. package/src/codemods/test-suites.ts +37 -0
  66. package/src/codemods/theme-toggle-mount-over.ts +70 -0
  67. package/src/codemods/vendored-guards.ts +186 -0
  68. package/src/codemods/verify-floor-skips.ts +88 -0
  69. package/src/codemods/verify-floor-steps.ts +90 -0
  70. package/src/coverage-island.ts +121 -0
  71. package/src/coverage-lcov.ts +49 -5
  72. package/src/coverage-remap.ts +146 -0
  73. package/src/db-replay-engine-prepared.ts +66 -0
  74. package/src/db-replay-engine-template.ts +156 -0
  75. package/src/db-replay-engine.ts +4 -0
  76. package/src/db-replay-scratch-reap.ts +54 -0
  77. package/src/deploy-verify-flags.ts +9 -2
  78. package/src/deploy-verify-grade.ts +10 -3
  79. package/src/dev-boot.ts +14 -1
  80. package/src/dev-dashboard-guard.ts +57 -10
  81. package/src/dev-host.ts +46 -0
  82. package/src/dev-tls-cache.ts +103 -0
  83. package/src/dev-tls-der.ts +69 -0
  84. package/src/dev-tls.ts +120 -0
  85. package/src/doctor-advisory-floors.ts +113 -0
  86. package/src/doctor-browser.ts +60 -0
  87. package/src/doctor-guards.ts +39 -86
  88. package/src/doctor-superseded.ts +67 -0
  89. package/src/error-codes-doctor.ts +12 -4
  90. package/src/error-codes-verify.ts +47 -0
  91. package/src/error-codes.ts +20 -23
  92. package/src/exercise-database.ts +47 -9
  93. package/src/exercise-push-device.ts +51 -0
  94. package/src/exercise-route-api.ts +74 -0
  95. package/src/exercise-routes.ts +14 -5
  96. package/src/exercise-services.ts +3 -1
  97. package/src/exercise-shard-flag.ts +47 -0
  98. package/src/fix-command.ts +2 -2
  99. package/src/generate-factories.ts +5 -11
  100. package/src/generate-feature-required.ts +9 -4
  101. package/src/generate-files.ts +26 -7
  102. package/src/generate-kinds.ts +5 -1
  103. package/src/guards-built-in-codes.ts +36 -0
  104. package/src/guards-built-in-refusal.ts +25 -0
  105. package/src/guards-built-in.ts +134 -0
  106. package/src/guards-materialize.ts +42 -0
  107. package/src/guards-paths.ts +37 -0
  108. package/src/guards-shipped-names.ts +38 -0
  109. package/src/guards-vendored.ts +73 -0
  110. package/src/guards.ts +105 -34
  111. package/src/index.ts +10 -0
  112. package/src/island-bundle-options.ts +48 -0
  113. package/src/island-bundle.ts +18 -46
  114. package/src/island-link.ts +5 -0
  115. package/src/island-outputs.ts +5 -0
  116. package/src/lint-findings.ts +3 -3
  117. package/src/mcp-errors-verify.ts +35 -0
  118. package/src/mcp-errors.ts +21 -20
  119. package/src/mcp-host-logs.ts +121 -0
  120. package/src/mcp-host.ts +12 -73
  121. package/src/measure-scope.ts +23 -3
  122. package/src/messages-floor.ts +19 -0
  123. package/src/messages-repro.ts +16 -2
  124. package/src/messages-status.ts +10 -0
  125. package/src/messages-upgrade.ts +15 -0
  126. package/src/messages.ts +22 -1
  127. package/src/registry.ts +4 -0
  128. package/src/repro-archive-collect.ts +161 -0
  129. package/src/repro-archive-write.ts +96 -0
  130. package/src/repro-archive.ts +161 -0
  131. package/src/repro-bundle.ts +8 -16
  132. package/src/repro-errors.ts +14 -2
  133. package/src/repro-framework.ts +53 -0
  134. package/src/repro-parse.ts +87 -0
  135. package/src/repro-redact.ts +218 -0
  136. package/src/repro-scrub.ts +257 -0
  137. package/src/role-start-types.ts +7 -0
  138. package/src/role-start.ts +4 -0
  139. package/src/serve-boot.ts +7 -1
  140. package/src/serve-env-tls.ts +57 -0
  141. package/src/solid-loader.ts +27 -10
  142. package/src/superseded-match.ts +87 -0
  143. package/src/superseded.ts +84 -0
  144. package/src/templates/bun-image.ts +48 -0
  145. package/src/templates/generate-export-rows.ts +136 -0
  146. package/src/templates/generate-import-rows.ts +186 -0
  147. package/src/templates/generate-rows-slice.ts +95 -0
  148. package/src/templates/github/ci.yml.ts +5 -1
  149. package/src/templates/guard-released-forms.ts +112 -0
  150. package/src/templates/guard-runtime-pin-test.ts +54 -0
  151. package/src/templates/guard-runtime-pin.ts +189 -0
  152. package/src/templates/scaffold-claude-agents.ts +6 -6
  153. package/src/templates/scaffold-claude-commands.ts +1 -1
  154. package/src/templates/scaffold-claude-hook.ts +18 -8
  155. package/src/templates/scaffold-claude.ts +2 -2
  156. package/src/templates/scaffold-db-package.ts +3 -0
  157. package/src/templates/scaffold-docs.ts +34 -30
  158. package/src/templates/scaffold-guards.ts +73 -39
  159. package/src/templates/scaffold-repo.ts +4 -8
  160. package/src/templates/scaffold-site.ts +4 -1
  161. package/src/templates/scaffold-suites.ts +72 -0
  162. package/src/templates/scaffold-test-services.ts +35 -10
  163. package/src/templates/scaffold-verify-floor.ts +53 -31
  164. package/src/templates/shapes/api.ts +4 -0
  165. package/src/templates/slice-foundation.ts +3 -3
  166. package/src/unthrown-codes.ts +3 -1
  167. package/src/upgrade-bun-floor.ts +4 -0
  168. package/src/upgrade-clean-tree.ts +54 -0
  169. package/src/upgrade-gate-codemods-install.ts +40 -0
  170. package/src/upgrade-gate-codemods.ts +151 -0
  171. package/src/upgrade-gate.ts +44 -7
  172. package/src/upgrade-guards-baseline.ts +43 -0
  173. package/src/upgrade-guards.ts +37 -2
  174. package/src/upgrade-lock.ts +118 -0
  175. package/src/upgrade-plan.ts +2 -1
  176. package/src/upgrade-report-codemods.ts +54 -0
  177. package/src/upgrade-report.ts +55 -27
  178. package/src/upgrade-signals.ts +91 -0
  179. package/src/upgrade-unfinished.ts +61 -0
  180. package/src/verify-coverage-run.ts +42 -11
  181. package/src/verify-e2e.ts +115 -4
  182. package/src/verify-floor.ts +27 -0
  183. package/src/verify-guard-baseline.ts +109 -0
  184. package/src/verify-live.ts +72 -0
  185. package/src/verify-merge-skips.ts +51 -0
  186. package/src/verify-merge.ts +36 -2
  187. package/src/verify-run.ts +48 -7
  188. package/src/verify-services.ts +287 -0
  189. package/src/verify-skip-reason.ts +53 -0
  190. package/src/verify-strict.ts +108 -0
  191. package/src/verify-test-command.ts +129 -0
  192. package/src/verify-tests.ts +39 -126
  193. package/types/babel-modules.d.ts +2 -0
  194. package/wiki/CLI-Reference.md +200 -27
  195. package/wiki/Caching-And-Invalidation.md +1 -1
  196. package/wiki/Entities-And-Migrations.md +1 -1
  197. package/wiki/Interface-Rules.md +17 -8
  198. package/wiki/Jobs-And-Workflows.md +3 -3
  199. package/wiki/Known-Gaps.md +5 -1
  200. package/wiki/MCP-And-AI.md +1 -1
  201. package/wiki/Observability.md +1 -0
  202. package/wiki/PWA-And-Offline.md +1 -1
  203. package/wiki/Project-Layout.md +4 -4
  204. package/wiki/Troubleshooting.md +3 -3
  205. package/wiki/Tutorial-05-Deploy-Free.md +2 -2
  206. package/wiki/Upgrading.md +8 -0
package/src/dev-tls.ts ADDED
@@ -0,0 +1,120 @@
1
+ // `x dev --tls`'s certificate: a self-signed ECDSA P-256 X.509 built from WebCrypto alone, and
2
+ // the names a bind needs it to carry. Cached on disk by `dev-tls-cache.ts`.
3
+
4
+ import { classifyAddress } from '@ultimat3/core';
5
+ import {
6
+ bitString,
7
+ bool,
8
+ ecdsaSignature,
9
+ explicit,
10
+ integer,
11
+ octets,
12
+ oid,
13
+ pem,
14
+ sequence,
15
+ set,
16
+ time,
17
+ tlv,
18
+ utf8,
19
+ } from './dev-tls-der';
20
+
21
+ export const DAY_MS = 86_400_000;
22
+ /** Short on purpose: a local certificate is regenerated for free, and browsers cap leaf lifetimes. */
23
+ export const DEV_CERT_DAYS = 90;
24
+
25
+ const ECDSA_SHA256 = sequence(oid('1.2.840.10045.4.3.2'));
26
+ const SUBJECT = sequence(set(sequence(oid('2.5.4.3'), utf8('x dev local certificate'))));
27
+
28
+ export interface CertificatePair {
29
+ readonly cert: string;
30
+ readonly key: string;
31
+ }
32
+
33
+ /** Sixteen hex groups → bytes; `URL` first, so every spelling (`::ffff:1.2.3.4` too) is canonical. */
34
+ function v6Bytes(address: string): Uint8Array {
35
+ const canonical = (URL.parse(`http://[${address.split('%')[0]}]`)?.hostname ?? '[::]').slice(
36
+ 1,
37
+ -1,
38
+ );
39
+ const [head = '', tail] = canonical.split('::');
40
+ const left = head === '' ? [] : head.split(':');
41
+ const right = tail === undefined || tail === '' ? [] : tail.split(':');
42
+ const groups = [...left, ...Array<string>(8 - left.length - right.length).fill('0'), ...right];
43
+ const bytes = new Uint8Array(16);
44
+ groups.forEach((group, index) => {
45
+ const value = Number.parseInt(group, 16);
46
+ bytes[index * 2] = value >> 8;
47
+ bytes[index * 2 + 1] = value & 0xff;
48
+ });
49
+ return bytes;
50
+ }
51
+
52
+ /** `iPAddress [7]` for a literal, `dNSName [2]` for anything else — both IMPLICIT, primitive. */
53
+ function generalName(name: string): Uint8Array {
54
+ if (classifyAddress(name) === undefined) return tlv(0x82, new TextEncoder().encode(name));
55
+ const bytes = name.includes(':') ? v6Bytes(name) : Uint8Array.from(name.split('.').map(Number));
56
+ return tlv(0x87, bytes);
57
+ }
58
+
59
+ const extension = (id: string, critical: boolean, value: Uint8Array): Uint8Array =>
60
+ sequence(oid(id), ...(critical ? [bool(true)] : []), octets(value));
61
+
62
+ function serialNumber(): Uint8Array {
63
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
64
+ bytes[0] = ((bytes[0] ?? 0) & 0x7f) | 0x01; // positive and never a leading zero (RFC 5280 §4.1.2.2)
65
+ return bytes;
66
+ }
67
+
68
+ /** A fresh pair carrying `names` in its subjectAltName — the only field a client matches on. */
69
+ export async function selfSignedCertificate(input: {
70
+ readonly names: readonly string[];
71
+ readonly now: Date;
72
+ }): Promise<CertificatePair> {
73
+ const keys = await crypto.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, [
74
+ 'sign',
75
+ 'verify',
76
+ ]);
77
+ const spki = new Uint8Array(await crypto.subtle.exportKey('spki', keys.publicKey));
78
+ const tbs = sequence(
79
+ explicit(0, integer(Uint8Array.of(2))), // v3
80
+ integer(serialNumber()),
81
+ ECDSA_SHA256,
82
+ SUBJECT,
83
+ sequence(
84
+ time(new Date(input.now.getTime() - 3_600_000)),
85
+ time(new Date(input.now.getTime() + DEV_CERT_DAYS * DAY_MS)),
86
+ ),
87
+ SUBJECT,
88
+ spki,
89
+ explicit(
90
+ 3,
91
+ sequence(
92
+ extension('2.5.29.19', true, sequence()), // basicConstraints: not a CA
93
+ extension('2.5.29.37', false, sequence(oid('1.3.6.1.5.5.7.3.1'))), // serverAuth
94
+ extension('2.5.29.17', false, sequence(...input.names.map(generalName))),
95
+ ),
96
+ ),
97
+ );
98
+ const raw = new Uint8Array(
99
+ await crypto.subtle.sign(
100
+ { name: 'ECDSA', hash: 'SHA-256' },
101
+ keys.privateKey,
102
+ new Uint8Array(tbs),
103
+ ),
104
+ );
105
+ const der = sequence(tbs, ECDSA_SHA256, bitString(ecdsaSignature(raw)));
106
+ const pkcs8 = new Uint8Array(await crypto.subtle.exportKey('pkcs8', keys.privateKey));
107
+ return { cert: pem('CERTIFICATE', der), key: pem('PRIVATE KEY', pkcs8) };
108
+ }
109
+
110
+ /**
111
+ * The names a certificate for a bind on `hostname` carries: loopback in every spelling, plus the
112
+ * address itself when it is a specific one a client on another machine would dial.
113
+ */
114
+ export function certificateNames(hostname: string): readonly string[] {
115
+ const base = ['localhost', '127.0.0.1', '::1'];
116
+ // A wildcard is dialled as loopback; any other literal — `127.0.0.2` included — is the url printed.
117
+ const kind = classifyAddress(hostname);
118
+ const dialled = kind !== undefined && kind !== 'unspecified' && !base.includes(hostname);
119
+ return dialled ? [...base, hostname] : base;
120
+ }
@@ -0,0 +1,113 @@
1
+ // `x doctor`'s advisory floors: a version the app's `bun.lock` resolves below the first release an
2
+ // npm advisory left behind, for the dependencies the framework brings and cannot floor itself.
3
+ // A warning and never the verdict (`X_BREAKING_ON_MAIN`); `scripts/advisory-floors.ts` is the
4
+ // framework-side half that raises the ranges it can.
5
+
6
+ // why: Bun exposes no path-join primitive; Bun.file takes one already joined.
7
+ import { join } from 'node:path';
8
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
9
+ import type { Finding } from './output';
10
+ import { quoteArg } from './shell-quote';
11
+
12
+ export const ADVISORY_FLOOR_UNMET = 'X_ADVISORY_FLOOR_UNMET';
13
+
14
+ export interface AdvisoryFloor {
15
+ readonly name: string;
16
+ /** The lowest version every listed advisory left behind. */
17
+ readonly floor: string;
18
+ readonly advisories: readonly string[];
19
+ /** How it reaches an app: a range the app declares itself, or one a framework dependency does. */
20
+ readonly via: 'app' | 'transitive';
21
+ }
22
+
23
+ /**
24
+ * As of 2026-11-15. `solid-js` is the app's own pin (`@ultimat3/ui` peers `^1.9.18`: the first
25
+ * release asking for seroval `~1.6.11`); the other two arrive through `sass`, whose ranges admit
26
+ * the patched versions, so a lockfile refresh is the whole fix and no `overrides` is needed.
27
+ */
28
+ export const ADVISORY_FLOORS: readonly AdvisoryFloor[] = [
29
+ {
30
+ name: 'solid-js',
31
+ floor: '1.9.18',
32
+ advisories: ['GHSA-3qxh-p7jc-5xh6', 'GHSA-f86p-h4j2-7qgj', 'GHSA-9wx9-5pv9-3349'],
33
+ via: 'app',
34
+ },
35
+ {
36
+ name: 'source-map-js',
37
+ floor: '1.2.2',
38
+ advisories: ['GHSA-68fv-2mgg-jv7q'],
39
+ via: 'transitive',
40
+ },
41
+ {
42
+ name: 'immutable',
43
+ floor: '5.1.8',
44
+ advisories: ['GHSA-xvcm-6775-5m9r', 'GHSA-v56q-mh7h-f735'],
45
+ via: 'transitive',
46
+ },
47
+ ];
48
+
49
+ /** The floor the codemod raises an app's `solid-js` to. */
50
+ export const SOLID_FLOOR = ADVISORY_FLOORS[0]?.floor ?? '1.9.18';
51
+
52
+ /** A registry release: what `Bun.semver.order` can compare. */
53
+ const RELEASE = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]*)?$/;
54
+
55
+ /** Every version `bun.lock` resolves for `name`, nested `parent/name` entries included. */
56
+ function resolvedVersions(packages: Readonly<Record<string, unknown>>, name: string): string[] {
57
+ return Object.entries(packages).flatMap(([key, entry]) => {
58
+ if (key !== name && !key.endsWith(`/${name}`)) return [];
59
+ const head = Array.isArray(entry) ? entry[0] : undefined;
60
+ return typeof head === 'string' && head.startsWith(`${name}@`)
61
+ ? [head.slice(name.length + 1)]
62
+ : [];
63
+ });
64
+ }
65
+
66
+ async function lockPackages(root: string): Promise<Readonly<Record<string, unknown>> | undefined> {
67
+ const file = Bun.file(join(root, 'bun.lock'));
68
+ if (!(await file.exists())) return undefined;
69
+ try {
70
+ const parsed: unknown = Bun.JSONC.parse(await file.text());
71
+ const packages =
72
+ typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'packages') : undefined;
73
+ return typeof packages === 'object' && packages !== null
74
+ ? (packages as Record<string, unknown>)
75
+ : undefined;
76
+ } catch {
77
+ // Not swallowed: an unparsable lockfile is `bun install`'s to refuse, loudly, on the next run.
78
+ return undefined;
79
+ }
80
+ }
81
+
82
+ /** One warning per floor the lockfile resolves under, lowest resolved version named. */
83
+ export async function advisoryFloorFindings(
84
+ root: string,
85
+ floors: readonly AdvisoryFloor[] = ADVISORY_FLOORS,
86
+ ): Promise<readonly Finding[]> {
87
+ const packages = await lockPackages(root);
88
+ if (packages === undefined) return [];
89
+ const transitive = floors.filter((f) => f.via === 'transitive').map((f) => quoteArg(f.name));
90
+ return floors.flatMap((row) => {
91
+ // A git, tarball or `file:` head is no release on npm's line, so no advisory range reads it:
92
+ // skipped rather than ordered, because `Bun.semver.order` throws on it and would take every
93
+ // other `x doctor` check down with this warning.
94
+ const below = resolvedVersions(packages, row.name)
95
+ .filter((version) => RELEASE.test(version))
96
+ .filter((version) => Bun.semver.order(version, row.floor) < 0)
97
+ .sort((a, b) => Bun.semver.order(a, b));
98
+ const lowest = below[0];
99
+ if (lowest === undefined) return [];
100
+ return [
101
+ {
102
+ code: ADVISORY_FLOOR_UNMET,
103
+ cause: `bun.lock resolves ${row.name} ${lowest}, below ${row.floor}, the first release past ${row.advisories.join(', ')}`,
104
+ fix:
105
+ row.via === 'app'
106
+ ? ['bun', 'add', '--exact', `${quoteArg(row.name)}@${row.floor}`].join(' ')
107
+ : ['bun', 'update', ...transitive].join(' '),
108
+ docs: ERROR_DOCS_URL,
109
+ at: 'bun.lock',
110
+ },
111
+ ];
112
+ });
113
+ }
@@ -0,0 +1,60 @@
1
+ // `x doctor`'s browser report: which Chrome the e2e driver would launch on this machine, or that
2
+ // there is none and the command that installs one. A WARNING only where `x.verify.json` requires
3
+ // `e2e` — the case `x verify` reds (`judgeE2eBrowser`) — so an app that upgrades keeps its verdict.
4
+
5
+ import { findChrome } from '@ultimat3/scraping/cdp';
6
+ import { msg } from './messages';
7
+ import type { CommandResult, Finding, JsonValue } from './output';
8
+ import { browserInstallCommand, e2eBrowserMissingFinding } from './verify-e2e';
9
+ import { floorRequires, readVerifyFloor } from './verify-floor';
10
+
11
+ type Env = Readonly<Record<string, string | undefined>>;
12
+
13
+ export interface BrowserFact {
14
+ /** The binary `findChrome` answered, or `undefined` when this machine has none it can start. */
15
+ readonly path: string | undefined;
16
+ /** Whether `x.verify.json` names `e2e`, which turns an absent browser into a red gate. */
17
+ readonly required: boolean;
18
+ /** The finding an absent browser is, pre-rendered for this platform and environment. */
19
+ readonly missing: Finding;
20
+ /** The install command for this platform, for the report line. */
21
+ readonly install: string;
22
+ }
23
+
24
+ /** The I/O half. `undefined` outside an app: there is no floor and no e2e suite to report on. */
25
+ export async function browserProbe(
26
+ root: string | undefined,
27
+ env: Env = Bun.env,
28
+ platform: string = process.platform,
29
+ ): Promise<BrowserFact | undefined> {
30
+ if (root === undefined) return undefined;
31
+ return {
32
+ path: await findChrome(env, platform),
33
+ required: floorRequires(await readVerifyFloor(root), 'e2e'),
34
+ missing: e2eBrowserMissingFinding(env, platform),
35
+ install: browserInstallCommand(platform),
36
+ };
37
+ }
38
+
39
+ /** The warning `x doctor` lists beside its verdict: only a REQUIRED step with no browser. */
40
+ export const browserWarnings = (fact: BrowserFact | undefined): readonly Finding[] =>
41
+ fact !== undefined && fact.path === undefined && fact.required ? [fact.missing] : [];
42
+
43
+ /** `data.browser` and one line, on a result `x doctor` already decided: `ok` and findings stay. */
44
+ export function withBrowserReport(
45
+ result: CommandResult,
46
+ fact: BrowserFact | undefined,
47
+ ): CommandResult {
48
+ if (fact === undefined) return result;
49
+ const data = typeof result.data === 'object' && result.data !== null ? result.data : {};
50
+ const browser: JsonValue = { path: fact.path ?? null, e2eRequired: fact.required };
51
+ const line =
52
+ fact.path === undefined
53
+ ? msg('cli.doctor.browserMissing', { install: fact.install })
54
+ : msg('cli.doctor.browserFound', { path: fact.path });
55
+ return {
56
+ ...result,
57
+ data: { ...(data as Record<string, JsonValue>), browser },
58
+ lines: [...(result.lines ?? []), line],
59
+ };
60
+ }
@@ -1,58 +1,16 @@
1
- // `x doctor`'s guard listing: the shipped guards this app's `guards/` does not hold, and the ones
2
- // it holds in a form that is not the current template — each with the command that writes it.
3
- // Never in the VERDICT: every shipped guard is the app's copy ("delete this file to drop the
4
- // rule"), so a missing one is a warning beside it (`data.warnings`) and an edited one a listing.
1
+ // `x doctor`'s guard listing: the copies of shipped guards this app's `guards/` still holds. Every
2
+ // shipped guard runs from the installed framework (`guards-built-in.ts`), so none is ever missing;
3
+ // a copy runs in its place and never receives a fix, so each is listed with its diff and the edit
4
+ // that resolves it (`guards-vendored.ts`). Never in the VERDICT: a warning beside it.
5
5
 
6
6
  // why: Bun exposes no path-join primitive; Bun.file takes one already joined.
7
7
  import { join } from 'node:path';
8
- import { ERROR_DOCS_URL } from '@ultimat3/core';
9
- import { GUARD_DIR, guardPaths } from './guards';
8
+ import { guardPaths } from './guards';
9
+ import { vendoredPath } from './guards-built-in';
10
+ import { resolvingEdit, type VendoredCopy, vendoredCopy, vendoredFinding } from './guards-vendored';
10
11
  import { msg } from './messages';
11
12
  import type { CommandResult, Finding, JsonValue } from './output';
12
- import { SHIPPED_GUARD_NAMES, shippedGuardSources } from './templates/scaffold-guards';
13
-
14
- export interface MissingGuard {
15
- readonly name: string;
16
- /** The command that writes it, with its test. Then `x verify` says what it finds. */
17
- readonly add: string;
18
- }
19
-
20
- /** The rule, pure: which shipped names have no file among the guards an app holds. */
21
- export function missingShippedGuards(present: readonly string[]): readonly MissingGuard[] {
22
- const held = new Set(present.map((path) => path.replace(/\.tsx?$/, '')));
23
- return SHIPPED_GUARD_NAMES.filter((name) => !held.has(`${GUARD_DIR}/${name}`)).map((name) => ({
24
- name,
25
- add: `x g guard ${name}`,
26
- }));
27
- }
28
-
29
- export const MISSING_GUARD = 'X_SHIPPED_GUARD_MISSING';
30
-
31
- /**
32
- * A missing shipped guard as a WARNING, one per guard: the gate does not hold this app to that
33
- * rule, and "no findings — environment is shippable" alone said nothing of it. A warning and not a
34
- * finding, so on `main` an adopter's doctor keeps its exit status (`doctor-warnings.ts`).
35
- */
36
- export function missingGuardWarnings(entries: readonly GuardListingEntry[]): readonly Finding[] {
37
- return entries
38
- .filter((entry): entry is MissingGuard => 'add' in entry)
39
- .map(({ name, add }) => ({
40
- code: MISSING_GUARD,
41
- cause: `${GUARD_DIR}/${name}.ts is not in this app, so x verify does not hold it to the shipped ${name} rule`,
42
- fix: `${add} && x verify --only boundaries --json`,
43
- docs: ERROR_DOCS_URL,
44
- at: `${GUARD_DIR}/${name}.ts`,
45
- }));
46
- }
47
-
48
- export interface DifferingGuard {
49
- readonly name: string;
50
- /** Rewrites the guard and its test from the current template. Review the diff, then keep it. */
51
- readonly refresh: string;
52
- }
53
-
54
- /** One line of the listing: a shipped guard the app lacks, or holds in another form. */
55
- export type GuardListingEntry = MissingGuard | DifferingGuard;
13
+ import { SHIPPED_GUARD_NAMES } from './templates/scaffold-guards';
56
14
 
57
15
  /** A guard file as the app holds it, path relative to the app root. */
58
16
  export interface HeldGuard {
@@ -60,63 +18,58 @@ export interface HeldGuard {
60
18
  readonly source: string;
61
19
  }
62
20
 
63
- /** A checkout on Windows may write CRLF; the rule is the same text either way. */
64
- const sameText = (a: string, b: string): boolean =>
65
- a.replaceAll('\r\n', '\n') === b.replaceAll('\r\n', '\n');
66
-
67
21
  /**
68
- * The rule, pure: which held guards carry a shipped name and are not that guard's current
69
- * template. A guard with a name the framework never shipped is the app's own, and has no template.
22
+ * The rule, pure: which held guards carry a shipped name, each judged against the shipped guard. A
23
+ * guard with a name the framework never shipped is the app's own — `app-<name>` after the migration.
70
24
  */
71
- export function differingShippedGuards(held: readonly HeldGuard[]): readonly DifferingGuard[] {
72
- const differing: DifferingGuard[] = [];
73
- for (const { path, source } of held) {
74
- const name = path.slice(`${GUARD_DIR}/`.length).replace(/\.tsx?$/, '');
75
- // An earlier form a shipped guard still accepts (`shippedGuardSources`) is current too.
76
- const templates = shippedGuardSources(name);
77
- if (templates.length === 0 || templates.some((template) => sameText(source, template)))
78
- continue;
79
- differing.push({ name, refresh: `x g guard ${name} --force` });
25
+ export function vendoredShippedGuards(held: readonly HeldGuard[]): readonly VendoredCopy[] {
26
+ const paths = held.map(({ path }) => path);
27
+ const copies: VendoredCopy[] = [];
28
+ for (const name of SHIPPED_GUARD_NAMES) {
29
+ const path = vendoredPath(paths, name);
30
+ const source = held.find((guard) => guard.path === path)?.source;
31
+ if (path !== undefined && source !== undefined) copies.push(vendoredCopy(name, path, source));
80
32
  }
81
- return differing;
33
+ return copies;
82
34
  }
83
35
 
84
36
  /** The I/O half: the same enumeration the `boundaries` step runs, so the two cannot disagree. */
85
- export async function shippedGuardsProbe(root: string): Promise<readonly GuardListingEntry[]> {
37
+ export async function shippedGuardsProbe(root: string): Promise<readonly VendoredCopy[]> {
86
38
  const paths = await guardPaths(root);
87
39
  const held = await Promise.all(
88
40
  paths.map(async (path) => ({ path, source: await Bun.file(join(root, path)).text() })),
89
41
  );
90
- const entries: GuardListingEntry[] = [
91
- ...missingShippedGuards(paths),
92
- ...differingShippedGuards(held),
93
- ];
94
- return entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
42
+ return vendoredShippedGuards(held);
95
43
  }
96
44
 
45
+ /** One warning per copy — the code the `boundaries` step lists too — so the exit status stays. */
46
+ export const vendoredGuardWarnings = (copies: readonly VendoredCopy[]): readonly Finding[] =>
47
+ copies.map(vendoredFinding);
48
+
97
49
  /**
98
- * The listing, on a result `x doctor` already decided: `data.guards` for a machine; for a person,
99
- * a line per differing guard — a missing one's command is its warning's line, never printed twice.
100
- * `ok`, the summary and the findings are returned as they came.
50
+ * The listing, on a result `x doctor` already decided: `data.guards` for a machine — `missing`
51
+ * always empty now, `differs` each edited copy with the edit that resolves it and its diff,
52
+ * `vendored` every copy — and for a person, one line and an edit per copy. `ok`, the summary and
53
+ * the findings are returned as they came.
101
54
  */
102
55
  export function withGuardListing(
103
56
  result: CommandResult,
104
- entries: readonly GuardListingEntry[],
57
+ copies: readonly VendoredCopy[],
105
58
  ): CommandResult {
106
59
  const data = typeof result.data === 'object' && result.data !== null ? result.data : {};
107
- const missing = entries.filter((entry): entry is MissingGuard => 'add' in entry);
108
- const differs = entries.filter((entry): entry is DifferingGuard => 'refresh' in entry);
109
- const lines = [
110
- ...(differs.length === 0
60
+ const lines =
61
+ copies.length === 0
111
62
  ? []
112
63
  : [
113
- msg('cli.doctor.guardsDiffer', { count: differs.length }),
114
- ...differs.map(({ refresh }) => ` ${refresh}`),
115
- ]),
116
- ];
64
+ msg('cli.doctor.guardsDiffer', { count: copies.length }),
65
+ ...copies.map((copy) => ` ${resolvingEdit(copy)}`),
66
+ ];
117
67
  const guards: JsonValue = {
118
- missing: missing.map(({ name, add }) => ({ name, add })),
119
- differs: differs.map(({ name, refresh }) => ({ name, refresh })),
68
+ missing: [],
69
+ differs: copies
70
+ .filter(({ identical }) => !identical)
71
+ .map((copy) => ({ name: copy.name, refresh: resolvingEdit(copy), diff: copy.diff ?? '' })),
72
+ vendored: copies.map(({ name }) => name),
120
73
  };
121
74
  return {
122
75
  ...result,
@@ -0,0 +1,67 @@
1
+ // `x doctor`'s and `x upgrade`'s superseded workarounds: every note in an app's source or docs
2
+ // that names a workaround the framework has since retired (`superseded.ts`), as a warning with the
3
+ // edit that retires it. A warning and never the verdict: an app that upgrades with no change keeps
4
+ // a green doctor on `main` (`X_BREAKING_ON_MAIN`).
5
+
6
+ // why: Bun exposes no path-join primitive; Bun.file takes one already joined.
7
+ import { join } from 'node:path';
8
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
9
+ import type { Finding } from './output';
10
+ import { eachSourceFile, isVendored, sortedPosix } from './source-files';
11
+ import type { SupersededWorkaround } from './superseded';
12
+ import { SUPERSEDED_WORKAROUNDS } from './superseded';
13
+ import type { SupersededHit } from './superseded-match';
14
+ import { matchSuperseded } from './superseded-match';
15
+
16
+ export const SUPERSEDED_WORKAROUND = 'X_SUPERSEDED_WORKAROUND';
17
+
18
+ /**
19
+ * Beyond the gate's source set: an app's gaps list is markdown, and a hand-written terminator or
20
+ * relay lives in `bin/`, which no gate step reads.
21
+ */
22
+ const EXTRA_GLOBS = ['bin/**/*.{ts,tsx}', '*.md', 'docs/**/*.md'] as const;
23
+
24
+ /** Every file the scan reads: the gate's own source set, then `EXTRA_GLOBS`. */
25
+ export async function supersededPaths(root: string): Promise<readonly string[]> {
26
+ const paths: string[] = [];
27
+ for await (const path of eachSourceFile(root)) paths.push(path);
28
+ for (const pattern of EXTRA_GLOBS) {
29
+ const found: string[] = [];
30
+ for await (const path of new Bun.Glob(pattern).scan({ cwd: root, absolute: false })) {
31
+ if (!isVendored(path)) found.push(path);
32
+ }
33
+ paths.push(...sortedPosix(found));
34
+ }
35
+ return paths;
36
+ }
37
+
38
+ /** One hit as a warning: the cause names the replacement and the version that shipped it. */
39
+ export function supersededFinding(hit: SupersededHit, row: SupersededWorkaround): Finding {
40
+ return {
41
+ code: SUPERSEDED_WORKAROUND,
42
+ cause: `${hit.at} keeps the '${row.id}' workaround; ${row.replacement} shipped in ${row.shippedIn}`,
43
+ fix: row.fix,
44
+ docs: ERROR_DOCS_URL,
45
+ at: hit.at.replace(/:\d+$/, ''),
46
+ };
47
+ }
48
+
49
+ /**
50
+ * The seam `x upgrade` calls too: every superseded workaround under `root`, as warnings, in file
51
+ * order. `rows` defaults to the table; a test passes its own.
52
+ */
53
+ export async function supersededFindings(
54
+ root: string,
55
+ rows: readonly SupersededWorkaround[] = SUPERSEDED_WORKAROUNDS,
56
+ ): Promise<readonly Finding[]> {
57
+ const byId = new Map(rows.map((row) => [row.id, row]));
58
+ const findings: Finding[] = [];
59
+ for (const path of await supersededPaths(root)) {
60
+ const text = await Bun.file(join(root, path)).text();
61
+ for (const hit of matchSuperseded(path, text, rows)) {
62
+ const row = byId.get(hit.id);
63
+ if (row !== undefined) findings.push(supersededFinding(hit, row));
64
+ }
65
+ }
66
+ return findings;
67
+ }
@@ -1,7 +1,7 @@
1
- // The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env-name, row-security and
2
- // shipped-guard checks, the `exercise` floor and the `drift` step's undeclared index — split out of
3
- // `error-codes.ts` at its 500-line ceiling. `error-codes.ts` folds these into the CLI's one owned
4
- // union and registers them in its one call; nothing else imports this file.
1
+ // The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env, row-security, guard,
2
+ // superseded-workaround, advisory-floor and owed-codemod checks, the `exercise` floor and `drift`'s
3
+ // undeclared index. Split from `error-codes.ts` at its ceiling; it folds these into the CLI's one
4
+ // owned union and registers them in its one call; nothing else imports this file.
5
5
 
6
6
  /** Codes `x doctor`, the `exercise` floor and the `drift` step's index advice declare and own. */
7
7
  export const CLI_DOCTOR_ERROR_CODES = [
@@ -12,6 +12,10 @@ export const CLI_DOCTOR_ERROR_CODES = [
12
12
  'X_DB_ROW_SECURITY_OFF',
13
13
  'X_DB_INDEX_UNDECLARED',
14
14
  'X_SHIPPED_GUARD_MISSING',
15
+ 'X_SUPERSEDED_WORKAROUND',
16
+ 'X_GUARD_VENDORED',
17
+ 'X_ADVISORY_FLOOR_UNMET',
18
+ 'X_UPGRADE_CODEMODS_PENDING',
15
19
  ] as const;
16
20
 
17
21
  export type CliDoctorErrorCode = (typeof CLI_DOCTOR_ERROR_CODES)[number];
@@ -25,4 +29,8 @@ export const CLI_DOCTOR_ERROR_TITLES: Readonly<Record<CliDoctorErrorCode, string
25
29
  X_DB_ROW_SECURITY_OFF: 'Raw sql reaches tenant tables while database.rowSecurity is off',
26
30
  X_DB_INDEX_UNDECLARED: 'Schema dump holds an index nothing declares',
27
31
  X_SHIPPED_GUARD_MISSING: "A guard x new ships is not in this app's guards/",
32
+ X_SUPERSEDED_WORKAROUND: 'a workaround the framework has since retired is still in the app',
33
+ X_GUARD_VENDORED: 'a guards/ copy of a shipped guard',
34
+ X_ADVISORY_FLOOR_UNMET: 'a resolved dependency is below its advisory floor',
35
+ X_UPGRADE_CODEMODS_PENDING: 'files an older x upgrade left for codemods',
28
36
  };
@@ -0,0 +1,47 @@
1
+ // The X_* codes of the gate's own floor and run — `x.verify.json`'s ratchets (`steps`, `strict`,
2
+ // `skipCeiling`, `coverage`, `guardBaseline`), a step's deadline, the shard/merge split and the
3
+ // services a suite needs — split out of `error-codes.ts` at its 500-line ceiling, as
4
+ // `error-codes-package.ts` was. That file folds these into the CLI's union and registers them.
5
+
6
+ /** Codes the gate's floor, its run and its split declare and own. */
7
+ export const CLI_VERIFY_ERROR_CODES = [
8
+ // The ratchet's own code. A skipped step is not a failure — unless `x.verify.json` says this
9
+ // repo already ran it, in which case the suite was deleted and the gate would otherwise print
10
+ // one more green line for it.
11
+ 'X_VERIFY_SUITE_VANISHED',
12
+ 'X_VERIFY_SHARD_INVALID',
13
+ 'X_VERIFY_MERGE_INCOMPLETE',
14
+ 'X_VERIFY_MERGE_INPUT',
15
+ 'X_VERIFY_STEP_TIMEOUT',
16
+ 'X_COVERAGE_BELOW_FLOOR',
17
+ 'X_COVERAGE_FLOOR_UNSTATED',
18
+ 'X_COVERAGE_FLOOR_STALE',
19
+ 'X_VERIFY_SKIPS_OVER_CEILING',
20
+ 'X_TEST_SERVICES_UNAVAILABLE',
21
+ 'X_VERIFY_E2E_BROWSER_MISSING',
22
+ 'X_VERIFY_STRICT_UNRUN',
23
+ 'X_GUARD_OVER_BASELINE',
24
+ 'X_GUARD_BASELINE_STALE',
25
+ ] as const;
26
+
27
+ export type CliVerifyErrorCode = (typeof CLI_VERIFY_ERROR_CODES)[number];
28
+
29
+ /** Their titles, typed over the list above so a code without one is a build error. */
30
+ export const CLI_VERIFY_ERROR_TITLES: Readonly<Record<CliVerifyErrorCode, string>> = {
31
+ X_VERIFY_SUITE_VANISHED: 'a step the committed floor requires had nothing left to check',
32
+ X_VERIFY_SHARD_INVALID: 'x verify --shard was given a spec or a step list it cannot split',
33
+ X_VERIFY_MERGE_INCOMPLETE: 'x verify merge was handed parts that do not add up to the whole gate',
34
+ X_VERIFY_MERGE_INPUT: 'a part handed to x verify merge is not an x verify --json document',
35
+ X_VERIFY_STEP_TIMEOUT: 'a gate step ran past its deadline and was stopped',
36
+ X_COVERAGE_BELOW_FLOOR: 'the unit suite covers less of the app than x.verify.json states',
37
+ X_COVERAGE_FLOOR_UNSTATED:
38
+ 'x.verify.json states no coverage floor, or one under 95 with no reason',
39
+ X_COVERAGE_FLOOR_STALE: 'the app now covers more than the floor in x.verify.json states',
40
+ X_VERIFY_SKIPS_OVER_CEILING: 'a step skipped more tests than its skipCeiling allows',
41
+ X_TEST_SERVICES_UNAVAILABLE:
42
+ "the live step's test database is not reachable and could not be started",
43
+ X_VERIFY_E2E_BROWSER_MISSING: 'a floored e2e step found no browser to drive',
44
+ X_VERIFY_STRICT_UNRUN: 'x.verify.json is strict and a step ran no check with no written why',
45
+ X_GUARD_OVER_BASELINE: 'a guard reports more findings than its x.verify.json baseline allows',
46
+ X_GUARD_BASELINE_STALE: 'a guard baseline is above what the tree reports',
47
+ };