@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
@@ -0,0 +1,28 @@
1
+ // The format hook as `x new` wrote it from 31.22.0 to 31.27.0, byte for byte: the text the
2
+ // format-edited-hook codemod recognises as the stock script. It ran `bunx biome`, which on a checkout
3
+ // with no install fetches an unrelated npm package named `biome`; today's script never does.
4
+
5
+ export const HOOK_SCRIPT_3122 = `#!/usr/bin/env bun
6
+ // PostToolUse(Edit|Write): \`biome check --write\` on the one file just edited — it formats in place
7
+ // and reports what it cannot fix. The path arrives on stdin as \`tool_input.file_path\`. Exit 2
8
+ // shows the agent the finding (the edit already landed); a file biome does not handle is a no-op.
9
+
10
+ const input: unknown = JSON.parse((await Bun.stdin.text()) || '{}');
11
+ const record = (typeof input === 'object' && input !== null ? input : {}) as {
12
+ tool_input?: { file_path?: unknown };
13
+ };
14
+ const file = record.tool_input?.file_path;
15
+ if (typeof file === 'string' && file !== '') {
16
+ const proc = Bun.spawnSync(
17
+ ['bunx', 'biome', 'check', '--write', '--no-errors-on-unmatched', file],
18
+ { stdout: 'pipe', stderr: 'pipe', timeout: 15_000 },
19
+ );
20
+ if (proc.exitCode !== 0) {
21
+ const out = \`\${proc.stdout.toString()}\${proc.stderr.toString()}\`.trim();
22
+ process.stderr.write(
23
+ \`\${out.split('\\n').slice(-30).join('\\n')}\\nfix what it names, then: bunx biome check --write \${file}\\n\`,
24
+ );
25
+ process.exit(2);
26
+ }
27
+ }
28
+ `;
@@ -0,0 +1,152 @@
1
+ // The PostToolUse format hook, carried twice. 31.22.0: it read `$CLAUDE_FILE_PATHS`, which the
2
+ // harness never sets; now `.claude/hooks/format-edited.ts` reads the path from stdin. 31.28.0: that
3
+ // script ran `bunx biome`, which with no install fetches an unrelated npm package; now it runs the
4
+ // app's own `node_modules/.bin/biome` or nothing, and the docs name `@biomejs/biome`.
5
+
6
+ import { claudeHookFile, HOOK_PATH } from '../templates/scaffold-claude-hook';
7
+ import type { Codemod } from './codemod';
8
+ import type { SnippetEdit } from './engine-edits';
9
+ import { editSnippets, mergeResults, writeIfAbsent } from './engine-edits';
10
+ import { HOOK_SCRIPT_3122 } from './format-edited-hook-3122';
11
+
12
+ const SETTINGS = '.claude/settings.json';
13
+ const README = '.claude/README.md';
14
+
15
+ const lines = (...text: readonly string[]): string => text.join('\n');
16
+
17
+ /** The hook as `settings.json` held it before: the dead command, matched as the template wrote it. */
18
+ const HOOK: SnippetEdit = {
19
+ from: lines(
20
+ ' "matcher": "Edit|Write",',
21
+ ' "hooks": [',
22
+ ' {',
23
+ ' "type": "command",',
24
+ ' "command": "bunx biome check --no-errors-on-unmatched --write \\"$CLAUDE_FILE_PATHS\\" 2>/dev/null || true"',
25
+ ' }',
26
+ ),
27
+ to: lines(
28
+ ' "matcher": "Edit|Write|MultiEdit",',
29
+ ' "hooks": [',
30
+ ' {',
31
+ ' "type": "command",',
32
+ ` "command": "bun \\"$CLAUDE_PROJECT_DIR\\"/${HOOK_PATH}",`,
33
+ ' "timeout": 20',
34
+ ' }',
35
+ ),
36
+ };
37
+
38
+ /** The read-only commands added to the allowlist alongside: the app's own list wins if edited. */
39
+ const ALLOWED: SnippetEdit = {
40
+ from: lines(' "Bash(bunx x docs:*)",', ' "Bash(bunx x env check:*)",'),
41
+ to: lines(
42
+ ' "Bash(bunx x docs:*)",',
43
+ ...[
44
+ 'impact',
45
+ 'graph',
46
+ 'affected',
47
+ 'exercise',
48
+ 'i18n sync',
49
+ 'fix boundary',
50
+ 'mcp tools',
51
+ 'env check',
52
+ ].map((command) => ` "Bash(bunx x ${command}:*)",`),
53
+ ),
54
+ optional: true,
55
+ };
56
+
57
+ const README_EDITS: readonly SnippetEdit[] = [
58
+ {
59
+ from: lines(
60
+ '| `settings.json` | nothing in context | read once per session; the hook runs per edit |',
61
+ '| `commands/*.md` |',
62
+ ),
63
+ to: lines(
64
+ '| `settings.json` | nothing in context | read once per session; the hook runs per edit |',
65
+ `| \`${HOOK_PATH.slice('.claude/'.length)}\` | nothing in context | runs after each edit, on that one file |`,
66
+ '| `commands/*.md` |',
67
+ ),
68
+ optional: true,
69
+ },
70
+ {
71
+ from: lines(
72
+ 'One `PostToolUse` hook: `bunx biome check --write` on the file that was just edited. **`--write`',
73
+ 'means it rewrites that file in place** — the same safe fixes `biome check --write .` would make',
74
+ 'repo-wide, but your working tree does change after every agent edit. Scoped to one file, so it costs',
75
+ 'milliseconds, and it settles formatting arguments before they reach a diff.',
76
+ ),
77
+ to: lines(
78
+ `One \`PostToolUse\` hook, \`${HOOK_PATH}\`: \`bunx biome check --write\` on the file that was just`,
79
+ 'edited, named by the JSON the harness sends on stdin. **`--write` means it rewrites that file in',
80
+ 'place** — the same safe fixes `biome check --write .` would make repo-wide, but your working tree',
81
+ 'does change after every agent edit. Scoped to one file, so it costs milliseconds, and it settles',
82
+ 'formatting arguments before they reach a diff. What biome cannot fix is shown to the agent at once,',
83
+ 'with the command that re-checks the file, instead of surfacing later as a red `lint` step.',
84
+ ),
85
+ optional: true,
86
+ },
87
+ ];
88
+
89
+ /** The stock script `x new` wrote from 31.22.0, whole: an app that edited it keeps its own. */
90
+ const script = claudeHookFile().contents;
91
+ const HOOK_SCRIPT: SnippetEdit = {
92
+ from: HOOK_SCRIPT_3122,
93
+ to: typeof script === 'string' ? script : HOOK_SCRIPT_3122,
94
+ };
95
+
96
+ /** `bunx biome` names whatever npm calls `biome`; `@biomejs/biome` is the formatter. */
97
+ const BIOME_ALLOW: SnippetEdit = {
98
+ from: ' "Bash(bunx biome check:*)",',
99
+ to: ' "Bash(bunx @biomejs/biome check:*)",',
100
+ optional: true,
101
+ };
102
+ const README_BIOME: SnippetEdit = {
103
+ from: `One \`PostToolUse\` hook, \`${HOOK_PATH}\`: \`bunx biome check --write\` on the file that was just`,
104
+ to: `One \`PostToolUse\` hook, \`${HOOK_PATH}\`: the installed \`biome check --write\` on the file that was just`,
105
+ optional: true,
106
+ };
107
+ const LINT_LINE: SnippetEdit = {
108
+ from: '`bunx biome check --write <paths>`',
109
+ to: '`bunx @biomejs/biome check --write <paths>`',
110
+ optional: true,
111
+ };
112
+ const DOCS = [
113
+ '.claude/agents/data.md',
114
+ '.claude/agents/server.md',
115
+ '.claude/agents/web.md',
116
+ '.claude/commands/feature.md',
117
+ ] as const;
118
+
119
+ /** The 31.28.0 edits alone, per file, in run order: what a 31.22-to-31.27 app is carried by. */
120
+ export const BIOME_EDITS: Readonly<Record<string, readonly SnippetEdit[]>> = {
121
+ [SETTINGS]: [BIOME_ALLOW],
122
+ [HOOK_PATH]: [HOOK_SCRIPT],
123
+ [README]: [README_BIOME],
124
+ ...Object.fromEntries(DOCS.map((path) => [path, [LINT_LINE]])),
125
+ };
126
+
127
+ /** Each file's edits: what the codemod runs, and what its test runs backwards. */
128
+ export const FORMAT_HOOK_EDITS = {
129
+ [SETTINGS]: [ALLOWED, HOOK, BIOME_ALLOW],
130
+ [README]: [...README_EDITS, README_BIOME],
131
+ } as const;
132
+
133
+ export const codemod: Codemod = {
134
+ id: 'format-edited-hook',
135
+ since: '31.28.0',
136
+ summary: `.claude/settings.json runs ${HOOK_PATH}, which reads the edited file from stdin and runs the app's own biome, never bunx biome`,
137
+ async run(app) {
138
+ const settings = await editSnippets(app, SETTINGS, FORMAT_HOOK_EDITS[SETTINGS]);
139
+ // The script only where settings.json runs it: an app that dropped the hook keeps none.
140
+ const runsIt = ((await app.read(SETTINGS)) ?? '').includes(HOOK_PATH);
141
+ const results = [
142
+ settings,
143
+ runsIt && typeof script === 'string'
144
+ ? await writeIfAbsent(app, HOOK_PATH, script)
145
+ : { changed: [], skipped: [] },
146
+ await editSnippets(app, HOOK_PATH, [HOOK_SCRIPT]),
147
+ await editSnippets(app, README, FORMAT_HOOK_EDITS[README]),
148
+ ];
149
+ for (const path of DOCS) results.push(await editSnippets(app, path, [LINT_LINE]));
150
+ return mergeResults(results);
151
+ },
152
+ };
@@ -0,0 +1,105 @@
1
+ // 31.18.0: the chart's alerts gain burn-rate rules against `alerts.objective`, and each role's
2
+ // memory request is what it measured idle. The rules template, still exactly the old one, is
3
+ // replaced whole; each values.yaml line moves where it stands as `x new` wrote it.
4
+
5
+ import { CHART_FILE, VALUES_FILE } from '../generate-chart-alerts';
6
+ import { names } from '../templates/naming';
7
+ import { helmMonitoringFiles } from '../templates/scaffold-helm-alerts';
8
+ import { chartName } from './chart-dashboard';
9
+ import type { Codemod, CodemodApp, CodemodResult } from './codemod';
10
+ import { unifiedDiff } from './engine-diff';
11
+ import type { SnippetEdit } from './engine-edits';
12
+ import { editSnippets, mergeResults, readText } from './engine-edits';
13
+ import { ALERT_RULES_31_15_LINES } from './helm-alerts-stock';
14
+
15
+ const RULES = 'docker/helm/templates/alert-rules.yaml';
16
+
17
+ const lines = (...text: readonly string[]): string => text.join('\n');
18
+
19
+ export const HELM_VALUES_EDITS: readonly SnippetEdit[] = [
20
+ {
21
+ from: lines('alerts:', ' enabled: auto', ' runbookBase:'),
22
+ to: lines(
23
+ 'alerts:',
24
+ ' enabled: auto',
25
+ " objective: 99.9 # percent of requests answered without a 5xx; the burn-rate rules' budget",
26
+ ' runbookBase:',
27
+ ),
28
+ },
29
+ {
30
+ from: lines(' port: 3000', ' resources:', ' requests: { cpu: 200m, memory: 256Mi }'),
31
+ to: lines(
32
+ ' port: 3000',
33
+ ' # Requests are measured idle plus headroom, limits the ceiling: a web pod of the demo app idled',
34
+ ' # at 73 Mi (plan 101 O6, 2026-11-11), so 128Mi; the limit is what an OOMKill reads.',
35
+ ' resources:',
36
+ ' requests: { cpu: 200m, memory: 128Mi }',
37
+ ),
38
+ optional: true,
39
+ },
40
+ {
41
+ from: lines(
42
+ ' retireSeconds: 3600',
43
+ ' resources:',
44
+ ' requests: { cpu: 200m, memory: 256Mi }',
45
+ ),
46
+ to: lines(
47
+ ' retireSeconds: 3600',
48
+ ' # 160Mi: ROLE=worker of the reference app idled at 138 MiB (Bun 1.4.4, 45 s, 2026-11-13).',
49
+ ' resources:',
50
+ ' requests: { cpu: 200m, memory: 160Mi }',
51
+ ),
52
+ optional: true,
53
+ },
54
+ {
55
+ from: lines(' resources:', ' requests: { cpu: 50m, memory: 128Mi }'),
56
+ to: lines(
57
+ ' resources:',
58
+ ' # 160Mi: ROLE=scheduler of the reference app idled at 137 MiB (Bun 1.4.4, 45 s, 2026-11-13).',
59
+ ' requests: { cpu: 50m, memory: 160Mi }',
60
+ ),
61
+ optional: true,
62
+ },
63
+ ];
64
+
65
+ /**
66
+ * Today's rules template, when the app's is still the pre-31.18 one exactly; one of the app's own
67
+ * (neither that nor today's) is reported with the template's change as a diff.
68
+ */
69
+ async function rules(app: CodemodApp, chart: string): Promise<CodemodResult> {
70
+ const file = await readText(app, RULES);
71
+ const today = helmMonitoringFiles(names(chart)).find((one) => one.path === RULES)?.contents;
72
+ if (file === undefined || typeof today !== 'string' || file.text === today) {
73
+ return { changed: [], skipped: [] };
74
+ }
75
+ const stock = ALERT_RULES_31_15_LINES.map((line) => line.replaceAll('<APP>', chart)).join('\n');
76
+ if (file.text === stock) {
77
+ await app.write(RULES, file.restore(today));
78
+ return { changed: [RULES], skipped: [] };
79
+ }
80
+ return {
81
+ changed: [],
82
+ skipped: [
83
+ {
84
+ path: RULES,
85
+ reason:
86
+ "the chart holds alert rules of its own, so the burn-rate rules were not written: the diff is the template's change, to make by hand",
87
+ diff: unifiedDiff(RULES, stock, today),
88
+ },
89
+ ],
90
+ };
91
+ }
92
+
93
+ export const codemod: Codemod = {
94
+ id: 'helm-alerts-objective',
95
+ since: '31.18.0',
96
+ summary: `${RULES} gains the burn-rate rules, ${VALUES_FILE} alerts.objective and the measured memory requests`,
97
+ async run(app) {
98
+ const chart = chartName((await readText(app, CHART_FILE))?.text ?? '');
99
+ if (chart === undefined) return { changed: [], skipped: [] };
100
+ return mergeResults([
101
+ await rules(app, chart),
102
+ await editSnippets(app, VALUES_FILE, HELM_VALUES_EDITS),
103
+ ]);
104
+ },
105
+ };
@@ -0,0 +1,108 @@
1
+ // `docker/helm/templates/alert-rules.yaml` as `x new` wrote it from 31.4.0 through 31.17.x — before
2
+ // the burn-rate rules and `alerts.objective` — kept byte for byte (the chart's name as `<APP>`), so
3
+ // a template still exactly that is recognised and replaced whole by today's, and an edited one not.
4
+
5
+ // biome-ignore-all lint/suspicious/noTemplateCurlyInString: Helm's own {{ … }}, never a JS template
6
+
7
+ export const ALERT_RULES_31_15_LINES: readonly string[] = [
8
+ '{{/*',
9
+ "The alert rules for this release's own series, written from @ultimat3/cli's rule table. Each rule",
10
+ 'reads alerts.rules.<alert> for threshold, for, severity and enabled; its runbook_url is',
11
+ "alerts.runbookBase plus the rule's anchor. Rendered by capability, like servicemonitor.yaml.",
12
+ '*/}}',
13
+ '{{- $cfg := .Values.alerts | default dict }}',
14
+ '{{- $mode := toString (ternary $cfg.enabled "auto" (hasKey $cfg "enabled")) }}',
15
+ '{{- if not (has $mode (list "auto" "true" "false")) }}',
16
+ '{{- fail (printf "alerts.enabled is %q — set it to auto (render when the cluster serves monitoring.coreos.com/v1/PrometheusRule), true or false" $mode) }}',
17
+ '{{- end }}',
18
+ '{{- if or (eq $mode "true") (and (eq $mode "auto") (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1/PrometheusRule")) }}',
19
+ '{{- $rules := $cfg.rules | default dict }}',
20
+ '{{- $base := $cfg.runbookBase | default "https://github.com/developerz-ai/ultimate/blob/main/docs/ops/06-runbooks.md" }}',
21
+ 'apiVersion: monitoring.coreos.com/v1',
22
+ 'kind: PrometheusRule',
23
+ 'metadata:',
24
+ ' name: {{ include "<APP>.fullname" . }}',
25
+ ' labels:',
26
+ ' {{- include "<APP>.labels" . | nindent 4 }}',
27
+ ' {{- with $cfg.labels }}',
28
+ ' {{- toYaml . | nindent 4 }}',
29
+ ' {{- end }}',
30
+ 'spec:',
31
+ ' groups:',
32
+ ' - name: {{ include "<APP>.fullname" . }}.ultimate',
33
+ ' rules:',
34
+ ' {{- $r := index $rules "UltimateQueueStalled" | default dict }}',
35
+ ' {{- if ne (toString $r.enabled) "false" }}',
36
+ ' - alert: UltimateQueueStalled',
37
+ ' expr: >-',
38
+ ' max by (namespace, app_kubernetes_io_instance, queue) (queue_oldest_ready_seconds{namespace="{{ $.Release.Namespace }}",app_kubernetes_io_instance="{{ $.Release.Name }}"}) > {{ ternary $r.threshold 300 (hasKey $r "threshold") }}',
39
+ ' for: {{ $r.for | default "5m" }}',
40
+ ' labels:',
41
+ ' severity: {{ $r.severity | default "warning" }}',
42
+ ' annotations:',
43
+ ' summary: "A queue has a due job nothing has claimed for longer than the threshold"',
44
+ ' runbook_url: {{ printf "%s#ultimatequeuestalled" $base | quote }}',
45
+ ' {{- end }}',
46
+ ' {{- $r := index $rules "UltimateDeadLetters" | default dict }}',
47
+ ' {{- if ne (toString $r.enabled) "false" }}',
48
+ ' - alert: UltimateDeadLetters',
49
+ ' expr: >-',
50
+ ' max by (namespace, app_kubernetes_io_instance, queue) (queue_dead_jobs{namespace="{{ $.Release.Namespace }}",app_kubernetes_io_instance="{{ $.Release.Name }}"}) > 0',
51
+ ' for: {{ $r.for | default "5m" }}',
52
+ ' labels:',
53
+ ' severity: {{ $r.severity | default "warning" }}',
54
+ ' annotations:',
55
+ ' summary: "A queue holds dead-lettered jobs"',
56
+ ' runbook_url: {{ printf "%s#ultimatedeadletters" $base | quote }}',
57
+ ' {{- end }}',
58
+ ' {{- $r := index $rules "UltimateLeaseLost" | default dict }}',
59
+ ' {{- if ne (toString $r.enabled) "false" }}',
60
+ ' - alert: UltimateLeaseLost',
61
+ ' expr: >-',
62
+ ' sum by (namespace, app_kubernetes_io_instance, queue) (rate(job_leases_lost_total{namespace="{{ $.Release.Namespace }}",app_kubernetes_io_instance="{{ $.Release.Name }}"}[5m])) > 0',
63
+ ' for: {{ $r.for | default "5m" }}',
64
+ ' labels:',
65
+ ' severity: {{ $r.severity | default "warning" }}',
66
+ ' annotations:',
67
+ ' summary: "Job leases are lapsing while their jobs still run, so jobs run twice"',
68
+ ' runbook_url: {{ printf "%s#ultimateleaselost" $base | quote }}',
69
+ ' {{- end }}',
70
+ ' {{- $r := index $rules "UltimateFramesDropped" | default dict }}',
71
+ ' {{- if ne (toString $r.enabled) "false" }}',
72
+ ' - alert: UltimateFramesDropped',
73
+ ' expr: >-',
74
+ ' sum by (namespace, app_kubernetes_io_instance) (rate(channel_frames_dropped_total{namespace="{{ $.Release.Namespace }}",app_kubernetes_io_instance="{{ $.Release.Name }}"}[5m])) > 0',
75
+ ' for: {{ $r.for | default "5m" }}',
76
+ ' labels:',
77
+ ' severity: {{ $r.severity | default "warning" }}',
78
+ ' annotations:',
79
+ ' summary: "Sync nodes are dropping channel frames to socket backpressure"',
80
+ ' runbook_url: {{ printf "%s#ultimateframesdropped" $base | quote }}',
81
+ ' {{- end }}',
82
+ ' {{- $r := index $rules "UltimateServerErrors" | default dict }}',
83
+ ' {{- if ne (toString $r.enabled) "false" }}',
84
+ ' - alert: UltimateServerErrors',
85
+ ' expr: >-',
86
+ ' sum by (namespace, app_kubernetes_io_instance) (rate(http_requests_total{namespace="{{ $.Release.Namespace }}",app_kubernetes_io_instance="{{ $.Release.Name }}",status="5xx"}[5m])) / sum by (namespace, app_kubernetes_io_instance) (rate(http_requests_total{namespace="{{ $.Release.Namespace }}",app_kubernetes_io_instance="{{ $.Release.Name }}"}[5m])) > {{ ternary $r.threshold 0.05 (hasKey $r "threshold") }}',
87
+ ' for: {{ $r.for | default "10m" }}',
88
+ ' labels:',
89
+ ' severity: {{ $r.severity | default "critical" }}',
90
+ ' annotations:',
91
+ ' summary: "The share of requests answered 5xx is above the threshold"',
92
+ ' runbook_url: {{ printf "%s#ultimateservererrors" $base | quote }}',
93
+ ' {{- end }}',
94
+ ' {{- $r := index $rules "UltimateTargetDown" | default dict }}',
95
+ ' {{- if ne (toString $r.enabled) "false" }}',
96
+ ' - alert: UltimateTargetDown',
97
+ ' expr: >-',
98
+ ' count by (namespace, app_kubernetes_io_instance, app_kubernetes_io_component) (up{namespace="{{ $.Release.Namespace }}",app_kubernetes_io_instance="{{ $.Release.Name }}"} == 0) > 0',
99
+ ' for: {{ $r.for | default "5m" }}',
100
+ ' labels:',
101
+ ' severity: {{ $r.severity | default "critical" }}',
102
+ ' annotations:',
103
+ ' summary: "A role has a scrape target that is down"',
104
+ ' runbook_url: {{ printf "%s#ultimatetargetdown" $base | quote }}',
105
+ ' {{- end }}',
106
+ '{{- end }}',
107
+ '',
108
+ ];
@@ -0,0 +1,56 @@
1
+ // The one ordered list of codemods `x upgrade` runs, in run order (`since`, then `id`). A codemod
2
+ // module not listed here is refused by `index.test.ts`; `scripts/template-codemods.ts` refuses a
3
+ // scaffold-owned template change with no codemod (or no written reason) for the next release.
4
+
5
+ import { codemod as agentsDevMcp } from './agents-dev-mcp';
6
+ import { codemod as authenticatorSessionRefusal } from './authenticator-session-refusal';
7
+ import { codemod as biomeNoDefaultExport } from './biome-no-default-export';
8
+ import { codemod as bunfigIslandCoverage } from './bunfig-island-coverage';
9
+ import { codemod as chartDashboard } from './chart-dashboard';
10
+ import { codemod as ciE2eBrowser } from './ci-e2e-browser';
11
+ import type { Codemod } from './codemod';
12
+ import { codemod as defineErrorLeaf } from './define-error-leaf';
13
+ import { codemod as docsCiParts } from './docs-ci-parts';
14
+ import { codemod as docsGateProse } from './docs-gate-prose';
15
+ import { codemod as docsIslandRows } from './docs-island-rows';
16
+ import { codemod as docsShippedGuards } from './docs-shipped-guards';
17
+ import { codemod as docsTestServices } from './docs-test-services';
18
+ import { codemod as formatEditedHook } from './format-edited-hook';
19
+ import { codemod as helmAlertsObjective } from './helm-alerts-objective';
20
+ import { codemod as metricsProbeHealthz } from './metrics-probe-healthz';
21
+ import { codemod as reproGitignore } from './repro-gitignore';
22
+ import { codemod as runtimePin } from './runtime-pin';
23
+ import { codemod as solidFloor } from './solid-floor';
24
+ import { codemod as testPorts } from './test-ports';
25
+ import { codemod as testSuites } from './test-suites';
26
+ import { codemod as themeToggleMountOver } from './theme-toggle-mount-over';
27
+ import { codemod as vendoredGuards } from './vendored-guards';
28
+ import { codemod as verifyFloorSkips } from './verify-floor-skips';
29
+ import { codemod as verifyFloorSteps } from './verify-floor-steps';
30
+
31
+ export const CODEMODS: readonly Codemod[] = [
32
+ defineErrorLeaf,
33
+ biomeNoDefaultExport,
34
+ docsIslandRows,
35
+ themeToggleMountOver,
36
+ docsCiParts,
37
+ chartDashboard,
38
+ helmAlertsObjective,
39
+ authenticatorSessionRefusal,
40
+ agentsDevMcp,
41
+ docsGateProse,
42
+ metricsProbeHealthz,
43
+ bunfigIslandCoverage,
44
+ ciE2eBrowser,
45
+ docsTestServices,
46
+ testPorts,
47
+ testSuites,
48
+ verifyFloorSkips,
49
+ docsShippedGuards,
50
+ formatEditedHook,
51
+ reproGitignore,
52
+ runtimePin,
53
+ solidFloor,
54
+ vendoredGuards,
55
+ verifyFloorSteps,
56
+ ];
@@ -0,0 +1,47 @@
1
+ // 31.25.0: a role with no HTTP socket is probed on `/healthz` of its scrape listener — the one path
2
+ // that reads the loops' heartbeats — where it was `/metrics`, which answers while a loop is stuck.
3
+ // The compose anchor and the chart's liveness probe, each where it stands as `x new` wrote it.
4
+
5
+ import type { Codemod } from './codemod';
6
+ import type { SnippetEdit } from './engine-edits';
7
+ import { editSnippets, mergeResults } from './engine-edits';
8
+
9
+ const COMPOSE = 'docker/docker-compose.prod.yml';
10
+ const HELPERS = 'docker/helm/templates/_helpers.tpl';
11
+
12
+ const probe = (path: string): string =>
13
+ ` test: ['CMD', 'bun', '--eval', "fetch('http://127.0.0.1:'+(process.env.METRICS_PORT||9090)+'${path}').then(r=>process.exit(r.ok?0:1),()=>process.exit(1))"]`;
14
+
15
+ export const METRICS_PROBE_EDITS: Readonly<Record<string, readonly SnippetEdit[]>> = {
16
+ [COMPOSE]: [
17
+ {
18
+ from: '# gated on it never starts. Probes follow the role here, exactly as they do in `docker/helm`.',
19
+ to: [
20
+ '# gated on it never starts. Probes follow the role here, exactly as they do in `docker/helm`:',
21
+ "# `/healthz`, the one path on the scrape listener that reads the loops' heartbeats.",
22
+ ].join('\n'),
23
+ optional: true,
24
+ },
25
+ // The probe itself, apart from the prose above it: a reworded comment keeps no stale probe.
26
+ { from: probe('/metrics'), to: probe('/healthz') },
27
+ ],
28
+ [HELPERS]: [
29
+ {
30
+ from: ' livenessProbe:\n httpGet: { path: /metrics, port: metrics }\n periodSeconds: 15',
31
+ to: ' livenessProbe:\n httpGet: { path: /healthz, port: metrics }\n periodSeconds: 15',
32
+ },
33
+ ],
34
+ };
35
+
36
+ export const codemod: Codemod = {
37
+ id: 'metrics-probe-healthz',
38
+ since: '31.25.0',
39
+ summary: `${COMPOSE} and ${HELPERS} probe a socketless role on /healthz, which reads its loops' heartbeats`,
40
+ async run(app) {
41
+ const results = [];
42
+ for (const [path, edits] of Object.entries(METRICS_PROBE_EDITS)) {
43
+ results.push(await editSnippets(app, path, edits));
44
+ }
45
+ return mergeResults(results);
46
+ },
47
+ };
@@ -0,0 +1,36 @@
1
+ // The codemods an app still owes, for `x doctor`: an `x upgrade` driven by a CLI older than the
2
+ // engine applied none, and the installed CLI's gate cannot write. A dry run of every codemod up to
3
+ // this CLI's release names them; `x upgrade --json` at the target then applies them (idempotent).
4
+
5
+ import type { Finding } from '../output';
6
+ import type { Codemod } from './codemod';
7
+ import { runCodemods } from './engine';
8
+ import { fsCodemodApp } from './engine-fs';
9
+ import { CODEMODS } from './index';
10
+
11
+ export const CODEMODS_PENDING = 'X_UPGRADE_CODEMODS_PENDING';
12
+
13
+ export async function pendingCodemodFindings(
14
+ root: string,
15
+ to: string,
16
+ codemods: readonly Codemod[] = CODEMODS,
17
+ ): Promise<readonly Finding[]> {
18
+ const report = await runCodemods({
19
+ app: fsCodemodApp(root),
20
+ codemods,
21
+ from: '0.0.0',
22
+ to,
23
+ dryRun: true,
24
+ });
25
+ const owed = report.applied.filter((one) => one.changed.length > 0);
26
+ if (owed.length === 0) return [];
27
+ const files = [...new Set(owed.flatMap((one) => one.changed))].sort();
28
+ return [
29
+ {
30
+ code: CODEMODS_PENDING,
31
+ cause: `${String(files.length)} file(s) still as an older scaffold wrote them, owed by ${owed.map((one) => `${one.id} (${one.since})`).join(', ')}: the x upgrade that installed ${to} ran under a CLI with no codemods — ${files.slice(0, 8).join(', ')}`,
32
+ fix: 'x upgrade --json # on a clean tree; at the release it is on, it applies every codemod still owed',
33
+ at: files[0] ?? '.',
34
+ },
35
+ ];
36
+ }
@@ -0,0 +1,40 @@
1
+ // Carries an older app's `.gitignore` to the 31.28.0 scaffold's: the line that keeps an
2
+ // `x repro --bundle` file — redacted, but meant for an issue, never the repository — out of a
3
+ // commit. Idempotent; an app that already ignores `repro/` whole is left alone; no file, no file.
4
+
5
+ import type { Codemod } from './codemod';
6
+
7
+ /** The line, as `x new`'s `.gitignore` (`templates/scaffold-repo.ts`) writes it. */
8
+ export const REPRO_BUNDLE_IGNORE = 'repro/bundle-*.json';
9
+
10
+ const GITIGNORE = '.gitignore';
11
+
12
+ /** Lines that already keep a bundle out: this one, or the whole `repro/` directory. */
13
+ const COVERING = new Set([REPRO_BUNDLE_IGNORE, `/${REPRO_BUNDLE_IGNORE}`, 'repro/', '/repro/']);
14
+
15
+ export const codemod: Codemod = {
16
+ id: 'repro-gitignore',
17
+ since: '31.28.0',
18
+ summary: `.gitignore gains ${REPRO_BUNDLE_IGNORE}: an x repro --bundle file is for an issue, never a commit`,
19
+ async run(app) {
20
+ const source = await app.read(GITIGNORE);
21
+ if (source === undefined) {
22
+ return {
23
+ changed: [],
24
+ skipped: [
25
+ {
26
+ path: GITIGNORE,
27
+ reason: `the app has no .gitignore, so none was created; add ${REPRO_BUNDLE_IGNORE} to whatever keeps files out of its commits`,
28
+ diff: `+${REPRO_BUNDLE_IGNORE}`,
29
+ },
30
+ ],
31
+ };
32
+ }
33
+ const lines = source.split(/\r?\n/).map((line) => line.trim());
34
+ if (lines.some((line) => COVERING.has(line))) return { changed: [], skipped: [] };
35
+ const eol = source.includes('\r\n') ? '\r\n' : '\n';
36
+ const base = source === '' || source.endsWith('\n') ? source : `${source}${eol}`;
37
+ await app.write(GITIGNORE, `${base}${REPRO_BUNDLE_IGNORE}${eol}`);
38
+ return { changed: [GITIGNORE], skipped: [] };
39
+ },
40
+ };