@ultimat3/cli 31.27.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 (107) hide show
  1. package/CLAUDE.md +3 -1
  2. package/README.md +14 -4
  3. package/package.json +29 -29
  4. package/src/app-manifest.ts +6 -1
  5. package/src/cmd-doctor.ts +11 -3
  6. package/src/cmd-repro-spec.ts +13 -1
  7. package/src/cmd-repro.ts +37 -5
  8. package/src/cmd-upgrade-codemods.ts +71 -0
  9. package/src/cmd-upgrade-spec.ts +19 -5
  10. package/src/cmd-upgrade.ts +91 -34
  11. package/src/codemods/agents-dev-mcp.ts +50 -0
  12. package/src/codemods/authenticator-session-refusal.ts +214 -0
  13. package/src/codemods/biome-no-default-export.ts +58 -0
  14. package/src/codemods/bunfig-island-coverage.ts +33 -0
  15. package/src/codemods/chart-dashboard.ts +73 -0
  16. package/src/codemods/ci-e2e-browser-stock.ts +75 -0
  17. package/src/codemods/ci-e2e-browser.ts +63 -0
  18. package/src/codemods/codemod.ts +58 -0
  19. package/src/codemods/define-error-leaf.ts +73 -0
  20. package/src/codemods/docs-ci-parts.ts +65 -0
  21. package/src/codemods/docs-gate-prose.ts +53 -0
  22. package/src/codemods/docs-island-rows.ts +31 -0
  23. package/src/codemods/docs-shipped-guards.ts +100 -0
  24. package/src/codemods/docs-test-services.ts +62 -0
  25. package/src/codemods/engine-diff.ts +104 -0
  26. package/src/codemods/engine-edits.ts +111 -0
  27. package/src/codemods/engine-fs.ts +95 -0
  28. package/src/codemods/engine.ts +191 -0
  29. package/src/codemods/format-edited-hook-3122.ts +28 -0
  30. package/src/codemods/format-edited-hook.ts +152 -0
  31. package/src/codemods/helm-alerts-objective.ts +105 -0
  32. package/src/codemods/helm-alerts-stock.ts +108 -0
  33. package/src/codemods/index.ts +56 -0
  34. package/src/codemods/metrics-probe-healthz.ts +47 -0
  35. package/src/codemods/pending.ts +36 -0
  36. package/src/codemods/repro-gitignore.ts +40 -0
  37. package/src/codemods/runtime-pin-lines.ts +109 -0
  38. package/src/codemods/runtime-pin.ts +116 -0
  39. package/src/codemods/solid-floor.ts +63 -0
  40. package/src/codemods/test-ports.ts +86 -0
  41. package/src/codemods/test-suites.ts +37 -0
  42. package/src/codemods/theme-toggle-mount-over.ts +70 -0
  43. package/src/codemods/vendored-guards.ts +186 -0
  44. package/src/codemods/verify-floor-skips.ts +88 -0
  45. package/src/codemods/verify-floor-steps.ts +90 -0
  46. package/src/doctor-advisory-floors.ts +113 -0
  47. package/src/doctor-guards.ts +39 -86
  48. package/src/doctor-superseded.ts +67 -0
  49. package/src/error-codes-doctor.ts +12 -4
  50. package/src/error-codes.ts +6 -0
  51. package/src/exercise-database.ts +7 -2
  52. package/src/generate-files.ts +6 -5
  53. package/src/guards-built-in-codes.ts +36 -0
  54. package/src/guards-built-in-refusal.ts +25 -0
  55. package/src/guards-built-in.ts +134 -0
  56. package/src/guards-materialize.ts +42 -0
  57. package/src/guards-paths.ts +37 -0
  58. package/src/guards-shipped-names.ts +38 -0
  59. package/src/guards-vendored.ts +73 -0
  60. package/src/guards.ts +90 -34
  61. package/src/index.ts +10 -0
  62. package/src/lint-findings.ts +3 -3
  63. package/src/mcp-errors.ts +11 -1
  64. package/src/measure-scope.ts +23 -3
  65. package/src/messages-repro.ts +16 -2
  66. package/src/messages-upgrade.ts +15 -0
  67. package/src/messages.ts +1 -1
  68. package/src/repro-archive-collect.ts +161 -0
  69. package/src/repro-archive-write.ts +96 -0
  70. package/src/repro-archive.ts +161 -0
  71. package/src/repro-bundle.ts +8 -16
  72. package/src/repro-errors.ts +14 -2
  73. package/src/repro-framework.ts +53 -0
  74. package/src/repro-parse.ts +87 -0
  75. package/src/repro-redact.ts +218 -0
  76. package/src/repro-scrub.ts +257 -0
  77. package/src/superseded-match.ts +87 -0
  78. package/src/superseded.ts +84 -0
  79. package/src/templates/bun-image.ts +48 -0
  80. package/src/templates/github/ci.yml.ts +1 -1
  81. package/src/templates/guard-released-forms.ts +112 -0
  82. package/src/templates/guard-runtime-pin-test.ts +54 -0
  83. package/src/templates/guard-runtime-pin.ts +189 -0
  84. package/src/templates/scaffold-claude-agents.ts +6 -6
  85. package/src/templates/scaffold-claude-commands.ts +1 -1
  86. package/src/templates/scaffold-claude-hook.ts +18 -8
  87. package/src/templates/scaffold-claude.ts +2 -2
  88. package/src/templates/scaffold-docs.ts +26 -24
  89. package/src/templates/scaffold-guards.ts +73 -39
  90. package/src/templates/scaffold-repo.ts +2 -1
  91. package/src/unthrown-codes.ts +2 -0
  92. package/src/upgrade-bun-floor.ts +4 -0
  93. package/src/upgrade-clean-tree.ts +54 -0
  94. package/src/upgrade-gate-codemods-install.ts +40 -0
  95. package/src/upgrade-gate-codemods.ts +151 -0
  96. package/src/upgrade-gate.ts +38 -6
  97. package/src/upgrade-lock.ts +118 -0
  98. package/src/upgrade-plan.ts +2 -1
  99. package/src/upgrade-report-codemods.ts +54 -0
  100. package/src/upgrade-report.ts +52 -27
  101. package/src/upgrade-signals.ts +91 -0
  102. package/src/upgrade-unfinished.ts +61 -0
  103. package/wiki/CLI-Reference.md +58 -4
  104. package/wiki/Interface-Rules.md +17 -8
  105. package/wiki/Observability.md +1 -0
  106. package/wiki/Project-Layout.md +4 -4
  107. package/wiki/Upgrading.md +5 -0
@@ -0,0 +1,84 @@
1
+ // The superseded-workaround table: what an app wrote while the framework lacked something, the
2
+ // version that shipped the real thing, and the edit that retires the workaround. `x doctor` and
3
+ // `x upgrade` report each hit (`doctor-superseded.ts`); `scripts/changelog-check.ts` refuses a
4
+ // release note that retires a workaround this table does not hold.
5
+
6
+ /**
7
+ * What to find. `comment` is matched on comment text only — a `//`, `/*` or `*` line of code, any
8
+ * line of markdown — and EVERY pattern must match one comment block: a workaround is recognised by
9
+ * the note that names it, never by ordinary code. `near`, when set, must also stand in the code
10
+ * within `NEAR_LINES` of that block: the note alone is stale prose, the note beside it is the
11
+ * workaround still in force.
12
+ */
13
+ export interface WorkaroundPattern {
14
+ readonly comment: readonly RegExp[];
15
+ readonly near?: RegExp;
16
+ }
17
+
18
+ export interface SupersededWorkaround {
19
+ /** Stable, kebab-case: a CHANGELOG line names it (`retires the workaround \`<id>\``). */
20
+ readonly id: string;
21
+ readonly pattern: WorkaroundPattern;
22
+ /** The framework version that shipped the replacement. */
23
+ readonly shippedIn: string;
24
+ /** What replaced it, as an author would search for it. */
25
+ readonly replacement: string;
26
+ /** Opens with the code or command to paste (the fix-prose rule). */
27
+ readonly fix: string;
28
+ }
29
+
30
+ /** How far from its note the workaround's code may stand, in lines either way. */
31
+ export const NEAR_LINES = 8;
32
+
33
+ export const SUPERSEDED_WORKAROUNDS: readonly SupersededWorkaround[] = [
34
+ {
35
+ // The scaffold itself wrote this until 30.0.0: "'ssr', not 'stream' … the framework has no hole
36
+ // marker yet". Apps kept the comment and the mode after the marker shipped.
37
+ id: 'ssr-until-hole',
38
+ pattern: { comment: [/\bhole\s+marker\b/i], near: /\brender\s*:\s*['"]ssr['"]/ },
39
+ shippedIn: '30.0.0',
40
+ replacement: "<Hole> from '@ultimat3/render' on a render: 'stream' page",
41
+ fix: "render: 'stream', with the slow read moved into <Hole fallback={<Skeleton />}>{() => read()}</Hole> (import { Hole } from '@ultimat3/render'); then delete the comment that waits for a hole marker",
42
+ },
43
+ {
44
+ // `x token` exited `X_NOT_IMPLEMENTED` until 31.17.0; a key-minting script said so in its header.
45
+ id: 'token-unimplemented',
46
+ pattern: {
47
+ comment: [
48
+ // Present tense only, and never `x token grant`, which is still planned: a changelog line
49
+ // saying the command "exited X_NOT_IMPLEMENTED" is history, not a workaround.
50
+ /\bx token`?(?! grant)\s+(?:\w+\s+){0,3}?(?:is|isn't|still|remains)\s+(?:not (?:yet )?(?:implemented|shipped|available)|unimplemented|planned|a stub)\b|\bx token`?(?! grant)[^.]*\bexits\s+`?X_NOT_IMPLEMENTED/i,
51
+ ],
52
+ },
53
+ shippedIn: '31.17.0',
54
+ replacement: 'x token create | list | revoke',
55
+ fix: 'x token create --scopes posts:read --json — mints the key with exact scopes; delete the note, and the script it stood in for',
56
+ },
57
+ {
58
+ // A gaps note saying the gate cannot run one step: `--only` shipped with the gate in 22.0.0.
59
+ id: 'verify-no-only',
60
+ pattern: {
61
+ comment: [
62
+ // The claim about the gate, never a fixture or a step that merely runs without the flag.
63
+ /\b(?:verify|gate)`?\s+(?:has|have|takes|offers|supports)\s+no\s+`?--only\b|`--only`\s+(?:flag\s+)?(?:does not exist|doesn't exist|is missing|is not supported|isn't supported)/i,
64
+ ],
65
+ },
66
+ shippedIn: '22.0.0',
67
+ replacement: 'x verify --only <step>',
68
+ fix: 'x verify --only lint --json — runs one step; delete the note that says the gate cannot',
69
+ },
70
+ {
71
+ // A hand-written TLS terminator or relay in front of `x dev` for a LAN or a secure origin.
72
+ id: 'dev-no-tls',
73
+ pattern: {
74
+ comment: [
75
+ // One sentence, a few words apart: `x dev`, then a whole-word negation, then what it lacks.
76
+ // "Start it with `x dev`. In production nothing terminates TLS" is two sentences.
77
+ /\bx dev`?\s+(?:[^\s.]+\s+){0,3}?\b(?:no|lacks|does not|doesn't|cannot|can't|won't)\s+(?:[^\s.]+\s+){0,3}?`?(?:tls|https|--tls|--host|ipv6)\b/i,
78
+ ],
79
+ },
80
+ shippedIn: '31.27.0',
81
+ replacement: 'x dev --host <address> --tls',
82
+ fix: 'x dev --host 0.0.0.0 --tls — serves https on the LAN with a cached local certificate; delete the terminator or relay the note describes',
83
+ },
84
+ ];
@@ -0,0 +1,48 @@
1
+ // The Bun image `x new` builds on, as a value: what the `runtime-pin` guard names in a fix and what
2
+ // the `runtime-pin` codemod moves an older app to. The Dockerfile template states the same image as
3
+ // literal text (scripts/bun-pin.test.ts reads that source), and bun-image.test.ts holds the two equal.
4
+
5
+ import { REQUIRED_BUN } from '../app-root';
6
+
7
+ export interface BunImage {
8
+ /** The exact Bun the digest was read from — `engines.bun`'s floor, the patch CI runs. */
9
+ readonly patch: string;
10
+ /** What the `FROM` tag names: the series, so the reader sees which line it follows. */
11
+ readonly series: string;
12
+ readonly variant: string;
13
+ readonly digest: string;
14
+ /** `oven/bun:<series>-<variant>@<digest>`, the text after `FROM`. */
15
+ readonly ref: string;
16
+ }
17
+
18
+ const series = REQUIRED_BUN.split('.').slice(0, 2).join('.');
19
+ const variant = 'alpine';
20
+ // `docker buildx imagetools inspect oven/bun:1.4.4-alpine` — moved together with REQUIRED_BUN.
21
+ const digest = 'sha256:4cf82f5686b196504fe119db3fcd9185b191f82ece82c40680e597228ec6070a';
22
+
23
+ export const SCAFFOLD_BUN_IMAGE: BunImage = {
24
+ patch: REQUIRED_BUN,
25
+ series,
26
+ variant,
27
+ digest,
28
+ ref: `oven/bun:${series}-${variant}@${digest}`,
29
+ };
30
+
31
+ /**
32
+ * Every digest a released scaffold's Dockerfile built on, by the exact Bun it was read from. The
33
+ * `FROM` tag names only the series, so this is how the framework reads back the patch of an image
34
+ * it wrote itself; any other digest was chosen or moved by the app. A bump moves the current row
35
+ * here as an earlier one.
36
+ */
37
+ const DIGEST_PATCHES: Readonly<Record<string, string>> = {
38
+ // 27.10.3
39
+ 'sha256:d888c0ae6c86d7866ff10c5aafdd9077b36aee6455b33dd270fb93c0dd5cef6f': '1.4.2',
40
+ // 28.0.0
41
+ 'sha256:629e17411f1f129dbec3af78d5af9c9f2a937435c80349437206c6b0b7422373': '1.4.3',
42
+ // 29.0.0 onward
43
+ [digest]: REQUIRED_BUN,
44
+ };
45
+
46
+ /** The Bun patch a scaffold-written digest holds, or undefined for one no scaffold wrote. */
47
+ export const scaffoldDigestPatch = (sha: string): string | undefined =>
48
+ Object.hasOwn(DIGEST_PATCHES, sha) ? DIGEST_PATCHES[sha] : undefined;
@@ -23,7 +23,7 @@ const CI_WORKFLOW_NAME = 'ci';
23
23
  * instead: GitHub owns the runner and the tag together. Same rule the framework's own
24
24
  * `.github/actions/setup/action.yml` states, and the same SHA.
25
25
  */
26
- const SETUP_BUN = 'oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0';
26
+ export const SETUP_BUN = 'oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0';
27
27
 
28
28
  /** The plan job's one command: the app's `verify` script, so the CLI it asks is the one installed. */
29
29
  export const PLAN_COMMAND = `bun run verify plan --parts ${String(DEFAULT_PLAN_PARTS)} --json`;
@@ -0,0 +1,112 @@
1
+ // GENERATED by `bun run scripts/lib/guard-refresh-forms.ts --write` — never hand-edited. Every
2
+ // rule-file text each shipped guard was released as (`guardFormHash`), with how it reported, so the
3
+ // `vendored-guards` codemod deletes a stale but unedited copy instead of keeping it as an edit.
4
+
5
+ export const RELEASED_GUARD_FORMS: Readonly<
6
+ Record<string, readonly (readonly [string, 'error' | 'warning'])[]>
7
+ > = {
8
+ 'animated-layout-property': [['2hqr04589t23q', 'error']],
9
+ 'bare-error': [
10
+ ['1m3eimglwzrdq', 'error'],
11
+ ['1njzso3r6drnd', 'error'],
12
+ ],
13
+ 'error-declared': [
14
+ ['1rlzex7nalpiw', 'error'],
15
+ ['2tfw2hq80msju', 'error'],
16
+ ['3kqd7d8pzpcnn', 'error'],
17
+ ],
18
+ 'focus-visible': [['4c2nf0mpzn0z', 'error']],
19
+ 'image-dimensions': [
20
+ ['1cfzth883qzt5', 'error'],
21
+ ['33uv2ua4a9zcf', 'error'],
22
+ ],
23
+ 'island-mount-clears': [['1v09h5ptzqvs2', 'error']],
24
+ 'island-without-states': [['2os1f5fb6aass', 'error']],
25
+ 'native-confirm': [
26
+ ['1f7eh34hj085a', 'error'],
27
+ ['2b134wpkoaqso', 'error'],
28
+ ['2eb7ld3hg0tpb', 'error'],
29
+ ],
30
+ 'raw-breakpoint': [['wdo3lsqmvsya', 'error']],
31
+ 'raw-colour': [['3onnbx54g9zmd', 'error']],
32
+ 'raw-fetch': [
33
+ ['17xdeprvzx5v2', 'error'],
34
+ ['1hgdwthi7j353', 'error'],
35
+ ['mazudnz7t6iy', 'error'],
36
+ ],
37
+ 'raw-interval': [
38
+ ['1o6p0fmjhzdhw', 'error'],
39
+ ['2xrqszz066coc', 'error'],
40
+ ['3qipy7ijjnz7r', 'error'],
41
+ ['ll7h7zpr075u', 'error'],
42
+ ],
43
+ 'raw-length': [['2vfl0ssvkqvua', 'error']],
44
+ 'raw-motion': [
45
+ ['14c1bs20ysc1u', 'error'],
46
+ ['w8aw0q20tfsz', 'error'],
47
+ ],
48
+ 'raw-shadow': [['1vhy6xulc5cs5', 'error']],
49
+ 'raw-z-index': [['2nnuj62o3qvvr', 'error']],
50
+ 'repo-await-in-loop': [['3a3v6vvmbf8q2', 'warning']],
51
+ 'repo-raw-sql': [
52
+ ['12qj02j416sib', 'error'],
53
+ ['2kr7gbv7j2m0v', 'error'],
54
+ ['3nmlelym16o78', 'error'],
55
+ ],
56
+ 'repo-unbounded': [
57
+ ['2yjuyaj4n8dqq', 'error'],
58
+ ['ae4czielms3c', 'warning'],
59
+ ],
60
+ 'runtime-pin': [['28ffbpwy4q2ji', 'error']],
61
+ 'semantic-interactive': [
62
+ ['29pfa4ea628cv', 'error'],
63
+ ['d4ncwu39wtrk', 'error'],
64
+ ],
65
+ 'unbounded-fanout': [['xk4dv9vsq8gg', 'error']],
66
+ 'undeclared-custom-property': [
67
+ ['2xnl4zuy9xv6f', 'error'],
68
+ ['3b0u9i8hze00x', 'error'],
69
+ ],
70
+ 'undefined-style-class': [
71
+ ['3food9t4vrzv8', 'error'],
72
+ ['w7as1ib1ido8', 'error'],
73
+ ],
74
+ 'untranslated-string': [
75
+ ['2x85ib5eqdxzi', 'error'],
76
+ ['h57qtdwn7inz', 'error'],
77
+ ],
78
+ 'unzoned-date': [
79
+ ['8apjndc5ybvm', 'error'],
80
+ ['haaxmgzsgjns', 'error'],
81
+ ],
82
+ };
83
+
84
+ /** Every hash each shipped guard's TEST file was released as: an unedited test goes without a note. */
85
+ export const RELEASED_GUARD_TEST_FORMS: Readonly<Record<string, readonly string[]>> = {
86
+ 'animated-layout-property': ['191zjn08f13h4'],
87
+ 'bare-error': ['1w7vwbtypxdwe'],
88
+ 'error-declared': ['2hj2bs2czhxnw', 'qe8afpq7pzf1'],
89
+ 'focus-visible': ['12c0rk3ljkx6q'],
90
+ 'image-dimensions': ['3p4hkambgpb4j'],
91
+ 'island-mount-clears': ['2jkeu60fnvtdg'],
92
+ 'island-without-states': ['vls0ujdd16gw'],
93
+ 'native-confirm': ['1c7vps5wn37uv', 'qwyn1mzn9ace'],
94
+ 'raw-breakpoint': ['w356i8dreh7j'],
95
+ 'raw-colour': ['1tc7cambk8byr'],
96
+ 'raw-fetch': ['2lips924uo00f'],
97
+ 'raw-interval': ['1z55givy4sst0'],
98
+ 'raw-length': ['1hpgz9jowk5qu'],
99
+ 'raw-motion': ['6420344uhv97', 'g6cs0de9jmr7'],
100
+ 'raw-shadow': ['3kg8ft6y3ia0y'],
101
+ 'raw-z-index': ['3fb40f6bwp8kq'],
102
+ 'repo-await-in-loop': ['2axgbb82wldt4'],
103
+ 'repo-raw-sql': ['c5pfl8w3qj94', 'f19j7irkta44'],
104
+ 'repo-unbounded': ['98ncw525gpmo'],
105
+ 'runtime-pin': ['dy20fh65qziz'],
106
+ 'semantic-interactive': ['2uh0p6xoh996t', '393msxyy1bz36'],
107
+ 'unbounded-fanout': ['key86lol3wnh'],
108
+ 'undeclared-custom-property': ['30bi2v92swukf', 'svuf8sm14fm8'],
109
+ 'undefined-style-class': ['1uy88gpk5k8p8', '2sy8me3i3bmzw'],
110
+ 'untranslated-string': ['30q3u45cey2eq'],
111
+ 'unzoned-date': ['1siep3fqscks4', '20x6l238r09jk'],
112
+ };
@@ -0,0 +1,54 @@
1
+ // The test `x new` writes beside the `runtime-pin` guard: the rule's own cases, run in the app.
2
+ // Split from `guard-runtime-pin.ts` at the file target; the code and the image are handed in.
3
+
4
+ import { SCAFFOLD_BUN_IMAGE } from './bun-image';
5
+
6
+ export const runtimePinTest = (code: string): string => {
7
+ const { patch, ref, series, variant } = SCAFFOLD_BUN_IMAGE;
8
+ return `// The rule, driven directly. Failure case first: a guard whose rule silently stopped matching is
9
+ // a green gate over the convention it was written to enforce.
10
+
11
+ import { expect, unitTest } from '@ultimat3/testing';
12
+ import { runtimePins } from './runtime-pin';
13
+
14
+ /** The image \`x new\` wrote: the digest every FROM builds on. */
15
+ const IMAGE =
16
+ '${ref}';
17
+
18
+ const ENGINES = { path: 'package.json', source: '{ "engines": { "bun": ">=${patch}" } }' };
19
+ const workflow = (pin: string) => ({
20
+ path: '.github/workflows/ci.yml',
21
+ source: ['jobs:', ' a:', ' steps:', \` bun-version: \${pin}\`].join('\\n'),
22
+ });
23
+ const dockerfile = (from: string) => ({
24
+ path: 'docker/Dockerfile',
25
+ source: \`FROM \${from} AS deps\`,
26
+ });
27
+
28
+ unitTest('a CI pin off engines.bun is refused at its line, with the line to write', () => {
29
+ const findings = runtimePins([ENGINES, workflow("'1.0.0'")]);
30
+ expect(findings).toHaveLength(1);
31
+ expect(findings[0]?.code).toBe('${code}');
32
+ expect(findings[0]?.at).toBe('.github/workflows/ci.yml:4');
33
+ expect(findings[0]?.fix).toStartWith("edit .github/workflows/ci.yml:4 — bun-version: '${patch}'");
34
+ });
35
+
36
+ unitTest('an image tag with no digest is refused, and the fix pastes one', () => {
37
+ const findings = runtimePins([ENGINES, dockerfile('oven/bun:${series}-${variant}')]);
38
+ expect(findings.map((finding) => finding.at)).toEqual(['docker/Dockerfile:1']);
39
+ expect(findings[0]?.fix).toContain(\`FROM \${IMAGE} AS deps\`);
40
+ });
41
+
42
+ unitTest('no engines.bun is refused: nothing else can be checked against it', () => {
43
+ const findings = runtimePins([{ path: 'package.json', source: '{}' }]);
44
+ expect(findings.map((finding) => finding.at)).toEqual(['package.json:1']);
45
+ });
46
+
47
+ unitTest('the same patch, its series, an expression and a digest-pinned image are silent', () => {
48
+ expect(runtimePins([ENGINES, workflow("'${patch}'"), dockerfile(IMAGE)])).toEqual([]);
49
+ expect(runtimePins([ENGINES, workflow('${series}.x')])).toEqual([]);
50
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: a GitHub expression, written as text.
51
+ expect(runtimePins([ENGINES, workflow('\${{ matrix.bun }}')])).toEqual([]);
52
+ });
53
+ `;
54
+ };
@@ -0,0 +1,189 @@
1
+ // The `runtime-pin` guard `x new` ships: every Bun pin in the app — `packageManager`,
2
+ // `.bun-version`, a workflow's `bun-version:`, a Dockerfile's `FROM oven/bun:` and the patch its
3
+ // digest note records — names the one version `engines.bun` declares, and every image builds on a
4
+ // digest. Four apps each wrote this check for themselves before it shipped.
5
+
6
+ import { SCAFFOLD_BUN_IMAGE } from './bun-image';
7
+ import { guardCode } from './guard';
8
+ import { runtimePinTest } from './guard-runtime-pin-test';
9
+ import type { GeneratedFile } from './naming';
10
+
11
+ /** Derived from the guard's name, never a literal: an `X_*` literal here is a FRAMEWORK code. */
12
+ const NAME = 'runtime-pin';
13
+ const CODE = guardCode(NAME);
14
+
15
+ const source =
16
+ (): string => `// runtime-pin: every Bun pin in this app names the one version engines.bun declares.
17
+ // \`x verify\` runs it on the \`boundaries\` step; \`{ "severity": { "runtime-pin": "off" } }\` in
18
+ // \`guards/shipped.json\` turns it off, \`"warning"\` makes it report only.
19
+ //
20
+ // Why: the dev box, CI and the image each install their own Bun. When the pins disagree, a green
21
+ // gate is evidence about a runtime production never runs, and a lockfile one Bun wrote is installed
22
+ // \`--frozen-lockfile\` by another. A tag is a pointer its publisher can move: an image builds on a
23
+ // digest. Read: \`package.json\` (\`engines.bun\`, THE version, and \`packageManager\`), \`.bun-version\`,
24
+ // every \`bun-version:\` under \`.github/\`, every \`FROM oven/bun:\` in a Dockerfile and the "digest is
25
+ // \`oven/bun:<patch>\`" note above it. Not read: an expression, a build arg, any other comment.
26
+
27
+ import type { Finding, Guard } from '@ultimat3/cli';
28
+
29
+ /** The app owns the codes its own conventions raise — this one is named for the guard. */
30
+ const CODE = '${CODE}';
31
+
32
+ /** The image \`x new\` wrote, so a fix can paste it when \`engines.bun\` is the patch it was read from. */
33
+ const SCAFFOLD = {
34
+ patch: '${SCAFFOLD_BUN_IMAGE.patch}',
35
+ variant: '-${SCAFFOLD_BUN_IMAGE.variant}',
36
+ ref: '${SCAFFOLD_BUN_IMAGE.ref}',
37
+ };
38
+
39
+ export interface PinFile {
40
+ /** App-root-relative POSIX path, so the finding names the file an author opens. */
41
+ readonly path: string;
42
+ readonly source: string;
43
+ }
44
+
45
+ const EXACT = /^\\d+\\.\\d+\\.\\d+$/;
46
+ const SERIES = /^(\\d+\\.\\d+)(?:\\.x)?$/;
47
+ const ENGINES = /"engines"\\s*:\\s*\\{[^}]*?"bun"\\s*:\\s*"([^"]*)"/;
48
+ const PACKAGE_MANAGER = /"packageManager"\\s*:\\s*"bun@([^"]*)"/;
49
+ const BUN_VERSION = /^\\s*(?:-\\s*)?bun-version:\\s*['"]?([^'"#\\s]+)/;
50
+ const FROM = /^\\s*FROM\\s+(?:--\\S+\\s+)*oven\\/bun:([^\\s@]+)(@sha256:[0-9a-f]{64})?(.*)$/i;
51
+ const TAG = /^(\\d+\\.\\d+(?:\\.\\d+)?)(-[\\w.-]+)?$/;
52
+ const RECORDED = /digest is \`?oven\\/bun:(\\d+\\.\\d+\\.\\d+)(-[\\w.-]+)?/;
53
+
54
+ /** Whether a pin names the version: the same patch, or the version's own series. */
55
+ const agrees = (pin: string, version: string): boolean => {
56
+ if (EXACT.test(pin)) return pin === version;
57
+ const series = SERIES.exec(pin)?.[1];
58
+ return series !== undefined && version.startsWith(\`\${series}.\`);
59
+ };
60
+
61
+ const lineAt = (text: string, offset: number): number => text.slice(0, offset).split('\\n').length;
62
+
63
+ /** The FROM line naming the version by digest: the scaffold's own when it is that patch. */
64
+ const imageFor = (version: string, variant: string, rest: string): string =>
65
+ version === SCAFFOLD.patch && variant === SCAFFOLD.variant
66
+ ? \`FROM \${SCAFFOLD.ref}\${rest}\`
67
+ : \`FROM oven/bun:\${version.split('.').slice(0, 2).join('.')}\${variant}@<digest>\${rest}, the digest from: docker buildx imagetools inspect oven/bun:\${version}\${variant}\`;
68
+
69
+ const finding = (at: string, cause: string, write: string): Finding => ({
70
+ code: CODE,
71
+ cause,
72
+ fix: \`edit \${at} — \${write} — then: x verify\`,
73
+ at,
74
+ });
75
+
76
+ /** \`path:line\` ordering, so two machines list the same findings in the same order. */
77
+ const byPlace = (a: Finding, b: Finding): number => {
78
+ const [pathA = '', lineA = '0'] = (a.at ?? '').split(/:(?=\\d+$)/);
79
+ const [pathB = '', lineB = '0'] = (b.at ?? '').split(/:(?=\\d+$)/);
80
+ return pathA === pathB ? Number(lineA) - Number(lineB) : pathA < pathB ? -1 : 1;
81
+ };
82
+
83
+ /** One Dockerfile, workflow or action, line by line: what each pin there says against \`version\`. */
84
+ function linePins(file: PinFile, version: string, findings: Finding[]): void {
85
+ const disagrees = (at: string, pin: string, write: string): void => {
86
+ if (agrees(pin, version)) return;
87
+ const cause = \`\${at} pins Bun \${pin} and engines.bun in package.json declares \${version}: the dev box, CI and the image run different runtimes, so a green gate is evidence about none of them\`;
88
+ findings.push(finding(at, cause, write));
89
+ };
90
+ file.source.split('\\n').forEach((text, index) => {
91
+ const at = \`\${file.path}:\${index + 1}\`;
92
+ if (text.trimStart().startsWith('#')) {
93
+ const recorded = RECORDED.exec(text);
94
+ if (recorded === null) return;
95
+ const variant = recorded[2] ?? '';
96
+ const write = \`# The digest is \\\`oven/bun:\${version}\${variant}\\\`'s, with every FROM below it on that digest\`;
97
+ disagrees(at, recorded[1] ?? '', write);
98
+ return;
99
+ }
100
+ const key = BUN_VERSION.exec(text);
101
+ if (key !== null) {
102
+ const pin = key[1] ?? '';
103
+ if (!pin.includes('$')) disagrees(at, pin, \`bun-version: '\${version}'\`);
104
+ return;
105
+ }
106
+ const from = FROM.exec(text);
107
+ if (from === null) return;
108
+ const [, tag = '', digest, rest = ''] = from;
109
+ if (tag.includes('$')) return;
110
+ const parts = TAG.exec(tag);
111
+ const write = imageFor(version, parts?.[2] ?? '', rest.trimEnd());
112
+ if (parts === null || !agrees(parts[1] ?? '', version)) {
113
+ disagrees(at, \`oven/bun:\${tag}\`, write);
114
+ } else if (digest === undefined) {
115
+ const cause = \`\${at} builds on the tag oven/bun:\${tag} alone, a pointer its publisher can move: the same commit can build on two runtimes\`;
116
+ findings.push(finding(at, cause, write));
117
+ }
118
+ });
119
+ }
120
+
121
+ /** Pure — the caller does the I/O — so the rule is testable without a filesystem. */
122
+ export function runtimePins(files: readonly PinFile[]): readonly Finding[] {
123
+ const manifest = files.find((file) => file.path === 'package.json')?.source ?? '';
124
+ const declared = ENGINES.exec(manifest)?.[1]?.match(/\\d+\\.\\d+(?:\\.\\d+)?/)?.[0];
125
+ if (declared === undefined) {
126
+ const cause =
127
+ 'package.json declares no engines.bun, so no Bun pin in this app names a version anything can check';
128
+ return [finding('package.json:1', cause, \`"engines": { "bun": ">=\${SCAFFOLD.patch}" }\`)];
129
+ }
130
+ // \`>=1.4\` admits 1.4.0: a range's version is its lower bound.
131
+ const version = [...declared.split('.'), '0', '0'].slice(0, 3).join('.');
132
+ const findings: Finding[] = [];
133
+ for (const file of files) {
134
+ if (file.path === 'package.json') {
135
+ const manager = PACKAGE_MANAGER.exec(file.source);
136
+ const pin = manager?.[1];
137
+ if (manager !== null && pin !== undefined && !agrees(pin, version)) {
138
+ const at = \`package.json:\${lineAt(file.source, manager.index)}\`;
139
+ const cause = \`\${at} pins Bun \${pin} and engines.bun declares \${version}: the toolchain and the gate run different runtimes\`;
140
+ findings.push(finding(at, cause, \`"packageManager": "bun@\${version}"\`));
141
+ }
142
+ } else if (file.path === '.bun-version') {
143
+ const pin = file.source.trim();
144
+ if (!agrees(pin, version)) {
145
+ const cause = \`.bun-version pins Bun \${pin} and engines.bun in package.json declares \${version}: the dev box runs a Bun CI does not\`;
146
+ findings.push(finding('.bun-version:1', cause, version));
147
+ }
148
+ } else {
149
+ linePins(file, version, findings);
150
+ }
151
+ }
152
+ return findings.sort(byPlace);
153
+ }
154
+
155
+ /** Every file a Bun pin lives in, one glob each: a wildcard never matches a dot directory. */
156
+ const PIN_GLOBS = [
157
+ 'package.json',
158
+ '.bun-version',
159
+ '.github/workflows/*.yml',
160
+ '.github/workflows/*.yaml',
161
+ '.github/actions/**/action.yml',
162
+ '.github/actions/**/action.yaml',
163
+ 'Dockerfile*',
164
+ '*.Dockerfile',
165
+ 'docker/**/Dockerfile*',
166
+ 'docker/**/*.Dockerfile',
167
+ ];
168
+
169
+ export const guard: Guard = {
170
+ summary: 'every Bun pin names the one version engines.bun declares; every image is by digest',
171
+ async check(_root, sources) {
172
+ // Each glob is the run's ONE walk of it, shared with any other guard that asks.
173
+ const found = await Promise.all(PIN_GLOBS.map((glob) => sources.files(glob)));
174
+ const files = new Map<string, PinFile>();
175
+ for (const file of found.flat()) {
176
+ if (!file.path.endsWith('.dockerignore')) {
177
+ files.set(file.path, { path: file.path, source: file.text });
178
+ }
179
+ }
180
+ return runtimePins([...files.values()]);
181
+ },
182
+ };
183
+ `;
184
+
185
+ /** `guards/runtime-pin.ts` and its test. No index, no registry — the directory registers it. */
186
+ export const runtimePinGuardFiles = (): readonly GeneratedFile[] => [
187
+ { path: `guards/${NAME}.ts`, contents: source() },
188
+ { path: `guards/${NAME}.test.ts`, contents: runtimePinTest(CODE) },
189
+ ];
@@ -81,7 +81,7 @@ feature slice. Nothing else. A change outside that set is a collision — report
81
81
 
82
82
  Inspect before you change: \`bunx x entities list\`, \`bunx x entities show <name>\`, both with \`--json\`.
83
83
 
84
- Checks: \`bun test <path>/entity.test.ts\`, \`bunx biome check --write <paths>\`, and \`bun run typecheck\`
84
+ Checks: \`bun test <path>/entity.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and \`bun run typecheck\`
85
85
  once when you are otherwise done. Never \`bunx x verify\` — that belongs to whoever coordinates you.
86
86
  `;
87
87
 
@@ -100,7 +100,7 @@ renders. A change outside that set is a collision — report it, do not make it.
100
100
  | Generate, then edit | \`bunx x g <kind> <name> --feature <slice>\` for every one of them — a hand-written primitive is missing from every registry that projects it |
101
101
  | One authz object | the policy decides; a route or a UI that re-checks is a second answer that will drift |
102
102
  | Data through the repo | an action calls \`repo.ts\`, never the database |
103
- | Errors are instructions | never \`throw new Error\` — declare each code once with \`defineError({ code, title, status, cause, fix })\` from \`@ultimat3/core/page\`: a stable \`X_SCREAMING_SNAKE\` code, a cause and a \`fix:\` a caller can actually run. \`guards/error-declared.ts\` refuses a handwritten \`UltimateError\` subclass |
103
+ | Errors are instructions | never \`throw new Error\` — declare each code once with \`defineError({ code, title, status, cause, fix })\` from \`@ultimat3/core/page\`: a stable \`X_SCREAMING_SNAKE\` code, a cause and a \`fix:\` a caller can actually run. the \`error-declared\` guard refuses a handwritten \`UltimateError\` subclass |
104
104
  | Jobs run at least once | a handler must be idempotent — an upsert or a statement whose second run changes nothing, never \`count + 1\` |
105
105
  | Tasks name a time zone | a cron schedule with an ambient zone is a different time twice a year |
106
106
  | No \`any\` | \`unknown\` plus a schema parse |
@@ -108,7 +108,7 @@ renders. A change outside that set is a collision — report it, do not make it.
108
108
  Inspect before you change: \`bunx x actions show <name>\`, \`bunx x queries show <name>\`, \`bunx x jobs list\`,
109
109
  \`bunx x tasks list\`, \`bunx x policy explain <subject>\` — every one takes \`--json\`.
110
110
 
111
- Checks: \`bun test <path>/<file>.test.ts\`, \`bunx biome check --write <paths>\`, and \`bun run typecheck\`
111
+ Checks: \`bun test <path>/<file>.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and \`bun run typecheck\`
112
112
  once when you are otherwise done. Never \`bunx x verify\` — that belongs to whoever coordinates you.
113
113
  `;
114
114
 
@@ -137,13 +137,13 @@ calls. A change outside that set is a collision — report it, do not make it.
137
137
  | Animate transform and opacity | nothing else composites: a \`top\`, a \`width\` or a \`box-shadow\` costs a layout pass every frame, and \`transition: all\` animates properties nobody chose. \`tokens.duration()\` / \`tokens.easing()\` are the values |
138
138
  | An island declares its states | a sibling \`<name>.island.states.ts\`, so \`bunx x shot --island <name> --json\` can photograph the failures nobody can click to |
139
139
 
140
- Every one of the last five is a build error, not a preference — \`guards/\` holds them and \`bunx x verify\`'s
141
- \`boundaries\` step runs them. Read the guard rather than guessing at the rule.
140
+ Every one of the last five is a build error, not a preference — a guard the framework ships, run by
141
+ \`bunx x verify\`'s \`boundaries\` step. Read the guard's finding rather than guessing at the rule.
142
142
 
143
143
  Inspect before you change: \`bunx x routes --json\`, \`bunx x i18n check\` for catalog gaps, and
144
144
  \`bunx x shot <route> --json\` when you need to see what you built.
145
145
 
146
- Checks: \`bun test <path>/page.test.ts\`, \`bunx biome check --write <paths>\`, and \`bun run typecheck\`
146
+ Checks: \`bun test <path>/page.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and \`bun run typecheck\`
147
147
  once when you are otherwise done. Never \`bunx x verify\` — that belongs to whoever coordinates you.
148
148
  `;
149
149
 
@@ -100,7 +100,7 @@ While you iterate, narrow the *feedback*, not the gate:
100
100
  | one test by name | \`bun test -t '<name>'\` |
101
101
  | a whole type | \`bunx x test unit\` · \`bunx x test contract\` · \`bunx x test e2e\` |
102
102
  | one gate step | \`bunx x verify --only <step> --json\` — \`NOT A GATE RUN\` |
103
- | lint the files you touched | \`bunx biome check --write <paths>\` |
103
+ | lint the files you touched | \`bunx @biomejs/biome check --write <paths>\` |
104
104
  | types, once, when otherwise done | \`bun run typecheck\` |
105
105
  | a broken environment | \`bunx x doctor\` |
106
106
 
@@ -11,24 +11,34 @@ export const HOOK_PATH = '.claude/hooks/format-edited.ts';
11
11
  export const HOOK_COMMAND = `bun "$CLAUDE_PROJECT_DIR"/${HOOK_PATH}`;
12
12
 
13
13
  const script = `#!/usr/bin/env bun
14
- // PostToolUse(Edit|Write): \`biome check --write\` on the one file just edited — it formats in place
15
- // and reports what it cannot fix. The path arrives on stdin as \`tool_input.file_path\`. Exit 2
16
- // shows the agent the finding (the edit already landed); a file biome does not handle is a no-op.
14
+ // PostToolUse(Edit|Write): the app's own biome, \`check --write\` on the one file just edited — it
15
+ // formats in place and reports what it cannot fix. The path arrives on stdin as
16
+ // \`tool_input.file_path\`. Exit 2 shows the agent the finding (the edit already landed). Only the
17
+ // installed binary: \`bunx biome\` with no install fetches an unrelated npm package named \`biome\`.
17
18
 
19
+ const root = process.env['CLAUDE_PROJECT_DIR'] || process.cwd();
20
+ const biome = Bun.which('biome', { PATH: \`\${root}/node_modules/.bin\` });
18
21
  const input: unknown = JSON.parse((await Bun.stdin.text()) || '{}');
19
22
  const record = (typeof input === 'object' && input !== null ? input : {}) as {
20
23
  tool_input?: { file_path?: unknown };
21
24
  };
22
25
  const file = record.tool_input?.file_path;
23
26
  if (typeof file === 'string' && file !== '') {
24
- const proc = Bun.spawnSync(
25
- ['bunx', 'biome', 'check', '--write', '--no-errors-on-unmatched', file],
26
- { stdout: 'pipe', stderr: 'pipe', timeout: 15_000 },
27
- );
27
+ if (biome === null) {
28
+ process.stderr.write(
29
+ 'format-edited: no node_modules/.bin/biome in this app, nothing formatted — bun install\\n',
30
+ );
31
+ process.exit(0);
32
+ }
33
+ const proc = Bun.spawnSync([biome, 'check', '--write', '--no-errors-on-unmatched', file], {
34
+ stdout: 'pipe',
35
+ stderr: 'pipe',
36
+ timeout: 15_000,
37
+ });
28
38
  if (proc.exitCode !== 0) {
29
39
  const out = \`\${proc.stdout.toString()}\${proc.stderr.toString()}\`.trim();
30
40
  process.stderr.write(
31
- \`\${out.split('\\n').slice(-30).join('\\n')}\\nfix what it names, then: bunx biome check --write \${file}\\n\`,
41
+ \`\${out.split('\\n').slice(-30).join('\\n')}\\nfix what it names, then: bunx @biomejs/biome check --write \${file}\\n\`,
32
42
  );
33
43
  process.exit(2);
34
44
  }
@@ -29,7 +29,7 @@ const settings = (): string => `{
29
29
  "Bash(bun run typecheck)",
30
30
  "Bash(bun run lint)",
31
31
  "Bash(bun run verify:*)",
32
- "Bash(bunx biome check:*)",
32
+ "Bash(bunx @biomejs/biome check:*)",
33
33
  "Bash(bunx x verify:*)",
34
34
  "Bash(bunx x test:*)",
35
35
  "Bash(bunx x doctor:*)",
@@ -124,7 +124,7 @@ framework's.
124
124
 
125
125
  ## The hook
126
126
 
127
- One \`PostToolUse\` hook, \`${HOOK_PATH}\`: \`bunx biome check --write\` on the file that was just
127
+ One \`PostToolUse\` hook, \`${HOOK_PATH}\`: the installed \`biome check --write\` on the file that was just
128
128
  edited, named by the JSON the harness sends on stdin. **\`--write\` means it rewrites that file in
129
129
  place** — the same safe fixes \`biome check --write .\` would make repo-wide, but your working tree
130
130
  does change after every agent edit. Scoped to one file, so it costs milliseconds, and it settles