@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,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
+ };
@@ -0,0 +1,109 @@
1
+ // One line of a Dockerfile or a workflow, read as a Bun pin and judged against the pin `x new`
2
+ // writes now: already there, carried there (a shape an older scaffold wrote), or the app's own
3
+ // choice — which is never edited, only reported with the line the scaffold would have written.
4
+
5
+ import { REQUIRED_BUN } from '../app-root';
6
+ import { type BunImage, scaffoldDigestPatch } from '../templates/bun-image';
7
+ import { SETUP_BUN } from '../templates/github/ci.yml';
8
+
9
+ export type LineVerdict =
10
+ | { readonly kind: 'keep' }
11
+ | { readonly kind: 'carry'; readonly to: string }
12
+ /** `to` is the scaffold's line, for the diff; the file is not written. */
13
+ | { readonly kind: 'foreign'; readonly to: string; readonly why: string };
14
+
15
+ const KEEP: LineVerdict = { kind: 'keep' };
16
+
17
+ const FROM = /^(\s*FROM\s+(?:--\S+\s+)*)(oven\/bun:([^\s@]+)(?:@(sha256:[0-9a-f]{64}))?)/i;
18
+ const TAG = /^(\d+\.\d+(?:\.\d+)?)(-[\w.-]+)?$/;
19
+ const RECORDED = /(digest is \\?`?oven\/bun:)(\d+\.\d+\.\d+)(-alpine)/;
20
+ const SETUP = /^(\s*(?:-\s*)?uses:\s*)oven-sh\/setup-bun@([^\s#]+)(.*)$/;
21
+ const COMMIT = /^[0-9a-f]{40}$/;
22
+ const BUN_VERSION = /^(\s*(?:-\s*)?bun-version:\s*)(['"]?)([^'"\s#]+)\2(\s*(?:#.*)?)$/;
23
+ const EXACT = /^\d+\.\d+\.\d+$/;
24
+ const SERIES = /^(\d+\.\d+)(?:\.x)?$/;
25
+
26
+ /** `version` against `patch`, read at the version's own precision: `1.4` is not below `1.4.4`. */
27
+ export function compareAt(version: string, patch: string): number {
28
+ const held = version.split('.').map(Number);
29
+ const wanted = patch.split('.').map(Number);
30
+ for (let at = 0; at < held.length; at += 1) {
31
+ const difference = (held[at] ?? 0) - (wanted[at] ?? 0);
32
+ if (difference !== 0) return Math.sign(difference);
33
+ }
34
+ return 0;
35
+ }
36
+
37
+ const isComment = (line: string): boolean => line.trimStart().startsWith('#');
38
+
39
+ /** A `FROM oven/bun:` line against the scaffold's image. */
40
+ export function dockerfileLine(line: string, image: BunImage): LineVerdict {
41
+ if (isComment(line)) return KEEP;
42
+ const from = FROM.exec(line);
43
+ if (from === null) return KEEP;
44
+ const [whole, head = '', , tag = '', digest] = from;
45
+ const to = `${head}${image.ref}${line.slice(whole.length)}`;
46
+ const foreign = (why: string): LineVerdict => ({ kind: 'foreign', to, why });
47
+ if (tag.includes('$'))
48
+ return foreign(`the tag is a build arg: set it to ${image.ref} where it is defined`);
49
+ const parts = TAG.exec(tag);
50
+ if (parts === null) return foreign(`oven/bun:${tag} names no version`);
51
+ const order = compareAt(parts[1] ?? '', image.patch);
52
+ if (parts[2] !== `-${image.variant}`) {
53
+ return digest === undefined
54
+ ? foreign(`oven/bun:${tag} is a variant x new does not write, by no digest`)
55
+ : KEEP;
56
+ }
57
+ if (digest === image.digest) return KEEP;
58
+ // A digest no scaffold wrote was chosen or moved since — Dependabot's docker ecosystem does.
59
+ if (digest !== undefined && scaffoldDigestPatch(digest) === undefined) {
60
+ return order < 0
61
+ ? foreign(`oven/bun:${tag} is pinned by a digest x new never wrote, below Bun ${image.patch}`)
62
+ : KEEP;
63
+ }
64
+ if (order > 0) {
65
+ const inspect = `docker buildx imagetools inspect oven/bun:${tag}`;
66
+ return {
67
+ kind: 'foreign',
68
+ to: line,
69
+ why: `oven/bun:${tag} is ahead of x new's pin and has no digest: ${inspect}`,
70
+ };
71
+ }
72
+ return { kind: 'carry', to };
73
+ }
74
+
75
+ /** The "digest is `oven/bun:<patch>`" note, moved with the FROM lines it describes. */
76
+ export const recordedLine = (line: string, image: BunImage): string =>
77
+ isComment(line)
78
+ ? line.replace(
79
+ RECORDED,
80
+ (_whole, head: string, _patch: string, variant: string) =>
81
+ `${head}${image.patch}${variant}`,
82
+ )
83
+ : line;
84
+
85
+ /** A workflow's `uses: oven-sh/setup-bun@…` or `bun-version:` line against the scaffold's. */
86
+ export function workflowLine(line: string): LineVerdict {
87
+ if (isComment(line)) return KEEP;
88
+ const setup = SETUP.exec(line);
89
+ if (setup !== null) {
90
+ // A commit pin is a pin, whichever one Dependabot last moved it to.
91
+ return COMMIT.test(setup[2] ?? '')
92
+ ? KEEP
93
+ : { kind: 'carry', to: `${setup[1] ?? ''}${SETUP_BUN}` };
94
+ }
95
+ const key = BUN_VERSION.exec(line);
96
+ if (key === null) return KEEP;
97
+ const [, head = '', quote = '', value = '', tail = ''] = key;
98
+ if (value.includes('$')) return KEEP;
99
+ const to = `${head}${quote}${REQUIRED_BUN}${quote}${tail}`;
100
+ if (EXACT.test(value)) return compareAt(value, REQUIRED_BUN) < 0 ? { kind: 'carry', to } : KEEP;
101
+ const series = SERIES.exec(value)?.[1];
102
+ const scaffold = `${head}'${REQUIRED_BUN}'${tail}`;
103
+ if (series !== undefined && compareAt(series, REQUIRED_BUN) >= 0) return KEEP;
104
+ return {
105
+ kind: 'foreign',
106
+ to: scaffold,
107
+ why: `bun-version ${value} is a pin x new does not write`,
108
+ };
109
+ }
@@ -0,0 +1,116 @@
1
+ // Carries an older app's Bun pins to the ones `x new` writes now: every Dockerfile's `FROM oven/bun:`
2
+ // onto the scaffold's digest, every workflow's `setup-bun` onto its commit pin and `bun-version:`
3
+ // onto the CLI's floor, and `engines.bun` / `.bun-version` / `packageManager` up to that floor.
4
+ // A file holding a pin the app chose itself is left whole, reported with the diff it would take.
5
+
6
+ import { REQUIRED_BUN } from '../app-root';
7
+ import { SCAFFOLD_BUN_IMAGE } from '../templates/bun-image';
8
+ import { editBunSites } from '../upgrade-bun-floor';
9
+ import type { Codemod, CodemodApp, CodemodResult } from './codemod';
10
+ import { unifiedDiff } from './engine-diff';
11
+ import { mergeResults, readText } from './engine-edits';
12
+ import { dockerfileLine, type LineVerdict, recordedLine, workflowLine } from './runtime-pin-lines';
13
+
14
+ const NOTHING: CodemodResult = { changed: [], skipped: [] };
15
+
16
+ const DOCKERFILES = [
17
+ 'Dockerfile*',
18
+ '*.Dockerfile',
19
+ 'docker/**/Dockerfile*',
20
+ 'docker/**/*.Dockerfile',
21
+ ];
22
+ const WORKFLOWS = [
23
+ '.github/workflows/*.yml',
24
+ '.github/workflows/*.yaml',
25
+ '.github/actions/**/action.yml',
26
+ '.github/actions/**/action.yaml',
27
+ ];
28
+ const MANIFESTS = ['package.json', '.bun-version'];
29
+
30
+ /** Every path the patterns match, once, in order: two globs can name one file. */
31
+ async function pathsOf(app: CodemodApp, patterns: readonly string[]): Promise<readonly string[]> {
32
+ const found = await Promise.all(patterns.map((pattern) => app.glob(pattern)));
33
+ return [...new Set(found.flat())].filter((path) => !path.endsWith('.dockerignore')).sort();
34
+ }
35
+
36
+ /** One file, line by line: written when every pin in it is the scaffold's to move, else reported. */
37
+ async function migrateLines(
38
+ app: CodemodApp,
39
+ path: string,
40
+ judge: (line: string) => LineVerdict,
41
+ carried: (lines: readonly string[]) => readonly string[] = (lines) => lines,
42
+ ): Promise<CodemodResult> {
43
+ // LF lines with no BOM: a CRLF line's `\r` would defeat each `$`-anchored pin pattern.
44
+ const file = await readText(app, path);
45
+ if (file === undefined) return NOTHING;
46
+ const source = file.text;
47
+ const lines = source.split('\n');
48
+ const verdicts = lines.map(judge);
49
+ const foreign: string[] = [];
50
+ const next = verdicts.map((verdict, index) => {
51
+ if (verdict.kind === 'keep') return lines[index] ?? '';
52
+ if (verdict.kind === 'foreign') foreign.push(`${path}:${String(index + 1)}: ${verdict.why}`);
53
+ return verdict.to;
54
+ });
55
+ const moved = verdicts.some((verdict) => verdict.kind !== 'keep');
56
+ const text = (moved ? carried(next) : next).join('\n');
57
+ if (foreign.length > 0) {
58
+ const diff = unifiedDiff(path, source, text);
59
+ const reason = `a Bun pin here is the app's own, so the file is left as it is — ${foreign.join('; ')}`;
60
+ return { changed: [], skipped: [{ path, reason, ...(diff === '' ? {} : { diff }) }] };
61
+ }
62
+ if (text === source) return NOTHING;
63
+ await app.write(path, file.restore(text));
64
+ return { changed: [path], skipped: [] };
65
+ }
66
+
67
+ /** `engines.bun`, `packageManager` and `.bun-version`, raised by the one floor editor `x upgrade` has. */
68
+ async function migrateManifest(app: CodemodApp, path: string): Promise<CodemodResult> {
69
+ const source = await app.read(path);
70
+ if (source === undefined) return NOTHING;
71
+ const { text, manual } = editBunSites(path, source, REQUIRED_BUN);
72
+ if (manual.length > 0) {
73
+ const why = manual.map((site) => `${site.path}:${String(site.line)}: ${site.why}`).join('; ');
74
+ const diff = unifiedDiff(path, source, text);
75
+ return {
76
+ changed: [],
77
+ skipped: [
78
+ {
79
+ path,
80
+ reason: `a Bun pin here is the app's own — ${why}`,
81
+ ...(diff === '' ? {} : { diff }),
82
+ },
83
+ ],
84
+ };
85
+ }
86
+ if (text === source) return NOTHING;
87
+ await app.write(path, text);
88
+ return { changed: [path], skipped: [] };
89
+ }
90
+
91
+ export const codemod: Codemod = {
92
+ id: 'runtime-pin',
93
+ // The release that ships this codemod. Its rewrite targets the pin 29.0.0's scaffold first wrote,
94
+ // but a codemod runs only for a hop whose span holds `since` (or a rerun at the target), so a
95
+ // `since` of 29.0.0 would never reach an app already past it — every app this codemod is for.
96
+ since: '31.28.0',
97
+ summary: `every Bun pin onto the one x new writes: ${SCAFFOLD_BUN_IMAGE.ref}, bun-version ${REQUIRED_BUN}`,
98
+ async run(app) {
99
+ const results: CodemodResult[] = [];
100
+ for (const path of await pathsOf(app, DOCKERFILES)) {
101
+ results.push(
102
+ await migrateLines(
103
+ app,
104
+ path,
105
+ (line) => dockerfileLine(line, SCAFFOLD_BUN_IMAGE),
106
+ (lines) => lines.map((line) => recordedLine(line, SCAFFOLD_BUN_IMAGE)),
107
+ ),
108
+ );
109
+ }
110
+ for (const path of await pathsOf(app, WORKFLOWS))
111
+ results.push(await migrateLines(app, path, workflowLine));
112
+ for (const path of await pathsOf(app, MANIFESTS))
113
+ results.push(await migrateManifest(app, path));
114
+ return mergeResults(results);
115
+ },
116
+ };