@ultimat3/cli 31.27.0 → 31.29.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 (134) hide show
  1. package/CLAUDE.md +4 -1
  2. package/README.md +14 -4
  3. package/package.json +29 -29
  4. package/src/app-manifest.ts +6 -1
  5. package/src/app-migrations-verdict.ts +84 -0
  6. package/src/cmd-doctor.ts +11 -3
  7. package/src/cmd-drill.ts +23 -9
  8. package/src/cmd-repro-spec.ts +13 -1
  9. package/src/cmd-repro.ts +37 -5
  10. package/src/cmd-upgrade-codemods.ts +71 -0
  11. package/src/cmd-upgrade-spec.ts +19 -5
  12. package/src/cmd-upgrade.ts +91 -34
  13. package/src/codemods/agents-dev-mcp.ts +50 -0
  14. package/src/codemods/authenticator-session-refusal.ts +214 -0
  15. package/src/codemods/biome-no-default-export.ts +58 -0
  16. package/src/codemods/bunfig-island-coverage.ts +33 -0
  17. package/src/codemods/chart-dashboard.ts +73 -0
  18. package/src/codemods/ci-e2e-browser-stock.ts +75 -0
  19. package/src/codemods/ci-e2e-browser.ts +63 -0
  20. package/src/codemods/codemod.ts +58 -0
  21. package/src/codemods/define-error-leaf.ts +73 -0
  22. package/src/codemods/docs-ci-parts.ts +65 -0
  23. package/src/codemods/docs-gate-prose.ts +53 -0
  24. package/src/codemods/docs-island-rows.ts +31 -0
  25. package/src/codemods/docs-shipped-guards.ts +100 -0
  26. package/src/codemods/docs-test-services.ts +62 -0
  27. package/src/codemods/engine-diff.ts +104 -0
  28. package/src/codemods/engine-edits.ts +111 -0
  29. package/src/codemods/engine-fs.ts +95 -0
  30. package/src/codemods/engine.ts +191 -0
  31. package/src/codemods/format-edited-hook-3122.ts +28 -0
  32. package/src/codemods/format-edited-hook.ts +152 -0
  33. package/src/codemods/helm-alerts-deploy.ts +85 -0
  34. package/src/codemods/helm-alerts-objective.ts +105 -0
  35. package/src/codemods/helm-alerts-stock.ts +108 -0
  36. package/src/codemods/index.ts +60 -0
  37. package/src/codemods/metrics-probe-healthz.ts +47 -0
  38. package/src/codemods/migrate-job-ordered.ts +81 -0
  39. package/src/codemods/migrate-job-stock.ts +41 -0
  40. package/src/codemods/pending.ts +36 -0
  41. package/src/codemods/repro-gitignore.ts +40 -0
  42. package/src/codemods/runtime-pin-lines.ts +109 -0
  43. package/src/codemods/runtime-pin.ts +116 -0
  44. package/src/codemods/solid-floor.ts +63 -0
  45. package/src/codemods/test-ports.ts +86 -0
  46. package/src/codemods/test-suites.ts +37 -0
  47. package/src/codemods/theme-toggle-mount-over.ts +70 -0
  48. package/src/codemods/vendored-guards.ts +186 -0
  49. package/src/codemods/verify-floor-skips.ts +88 -0
  50. package/src/codemods/verify-floor-steps.ts +90 -0
  51. package/src/doctor-advisory-floors.ts +113 -0
  52. package/src/doctor-guards.ts +39 -86
  53. package/src/doctor-superseded.ts +67 -0
  54. package/src/drill-schema-behind.ts +26 -0
  55. package/src/error-codes-doctor.ts +12 -4
  56. package/src/error-codes.ts +9 -0
  57. package/src/exercise-database.ts +7 -2
  58. package/src/framework-schema-apply.ts +7 -19
  59. package/src/framework-schema-stamp.ts +38 -3
  60. package/src/framework-schema-verify.ts +120 -0
  61. package/src/framework-schema-wait.ts +125 -0
  62. package/src/generate-files.ts +6 -5
  63. package/src/guards-built-in-codes.ts +36 -0
  64. package/src/guards-built-in-refusal.ts +25 -0
  65. package/src/guards-built-in.ts +134 -0
  66. package/src/guards-materialize.ts +42 -0
  67. package/src/guards-paths.ts +37 -0
  68. package/src/guards-shipped-names.ts +38 -0
  69. package/src/guards-vendored.ts +73 -0
  70. package/src/guards.ts +90 -34
  71. package/src/index.ts +10 -0
  72. package/src/lint-findings.ts +3 -3
  73. package/src/mcp-errors.ts +12 -1
  74. package/src/measure-scope.ts +23 -3
  75. package/src/messages-repro.ts +16 -2
  76. package/src/messages-upgrade.ts +15 -0
  77. package/src/messages.ts +1 -1
  78. package/src/repro-archive-collect.ts +161 -0
  79. package/src/repro-archive-write.ts +96 -0
  80. package/src/repro-archive.ts +161 -0
  81. package/src/repro-bundle.ts +8 -16
  82. package/src/repro-errors.ts +14 -2
  83. package/src/repro-framework.ts +53 -0
  84. package/src/repro-parse.ts +87 -0
  85. package/src/repro-redact.ts +218 -0
  86. package/src/repro-scrub.ts +257 -0
  87. package/src/role-pg-stats.ts +21 -0
  88. package/src/role-start.ts +4 -0
  89. package/src/runtime-queue.ts +27 -6
  90. package/src/serve-boot-probe.ts +97 -0
  91. package/src/serve-boot.ts +26 -1
  92. package/src/serve-retire.ts +16 -3
  93. package/src/superseded-match.ts +87 -0
  94. package/src/superseded.ts +84 -0
  95. package/src/templates/bun-image.ts +48 -0
  96. package/src/templates/chart-dashboard-panels.ts +178 -0
  97. package/src/templates/chart-dashboard.ts +9 -135
  98. package/src/templates/github/ci.yml.ts +1 -1
  99. package/src/templates/guard-released-forms.ts +112 -0
  100. package/src/templates/guard-runtime-pin-test.ts +54 -0
  101. package/src/templates/guard-runtime-pin.ts +189 -0
  102. package/src/templates/scaffold-claude-agents.ts +6 -6
  103. package/src/templates/scaffold-claude-commands.ts +1 -1
  104. package/src/templates/scaffold-claude-hook.ts +18 -8
  105. package/src/templates/scaffold-claude.ts +2 -2
  106. package/src/templates/scaffold-container.ts +2 -2
  107. package/src/templates/scaffold-docs.ts +26 -24
  108. package/src/templates/scaffold-guards.ts +73 -39
  109. package/src/templates/scaffold-helm-alert-deploy.ts +105 -0
  110. package/src/templates/scaffold-helm-alert-rules.ts +7 -1
  111. package/src/templates/scaffold-helm-alerts.ts +3 -0
  112. package/src/templates/scaffold-helm-migrate.ts +85 -0
  113. package/src/templates/scaffold-helm-templates.ts +2 -36
  114. package/src/templates/scaffold-helm.ts +1 -0
  115. package/src/templates/scaffold-repo.ts +2 -1
  116. package/src/unthrown-codes.ts +2 -0
  117. package/src/upgrade-bun-floor.ts +4 -0
  118. package/src/upgrade-clean-tree.ts +54 -0
  119. package/src/upgrade-gate-codemods-install.ts +40 -0
  120. package/src/upgrade-gate-codemods.ts +151 -0
  121. package/src/upgrade-gate.ts +38 -6
  122. package/src/upgrade-lock.ts +118 -0
  123. package/src/upgrade-plan.ts +2 -1
  124. package/src/upgrade-report-codemods.ts +54 -0
  125. package/src/upgrade-report.ts +52 -27
  126. package/src/upgrade-signals.ts +91 -0
  127. package/src/upgrade-unfinished.ts +61 -0
  128. package/wiki/CLI-Reference.md +70 -5
  129. package/wiki/Deployment.md +2 -1
  130. package/wiki/Interface-Rules.md +17 -8
  131. package/wiki/Known-Gaps.md +1 -1
  132. package/wiki/Observability.md +1 -0
  133. package/wiki/Project-Layout.md +4 -4
  134. package/wiki/Upgrading.md +6 -0
@@ -1,4 +1,4 @@
1
- // The `guards/` directory `x new` writes, and the one list that names every guard in it.
1
+ // The one list that names every guard the framework ships, and what `x new` writes into `guards/`.
2
2
  //
3
3
  // `x new` shipped ZERO guards while the `AGENTS.md` it writes stated nine non-negotiables — five of
4
4
  // which nothing enforced, each measured green on `x verify` in a scaffolded app. The mechanism was
@@ -29,6 +29,7 @@
29
29
  // until the apps are clean of it, and a `.all()` that says no bound — failing the gate in an app
30
30
  // scaffolded from 31.23 on, while an older app keeps the report-only copy it was given.
31
31
 
32
+ import { SHIPPED_GUARD_NAMES as NAMES, type ShippedGuardName } from '../guards-shipped-names';
32
33
  import { animatedLayoutPropertyGuardFiles } from './guard-animated-layout-property';
33
34
  import { bareErrorGuardFiles } from './guard-bare-error';
34
35
  import { errorDeclaredGuardFiles } from './guard-error-declared';
@@ -48,6 +49,7 @@ import { rawZIndexGuardFiles } from './guard-raw-z-index';
48
49
  import { repoAwaitInLoopGuardFiles } from './guard-repo-await-in-loop';
49
50
  import { repoRawSqlGuardFiles } from './guard-repo-raw-sql';
50
51
  import { repoUnboundedGuardFiles } from './guard-repo-unbounded';
52
+ import { runtimePinGuardFiles } from './guard-runtime-pin';
51
53
  import { semanticInteractiveGuardFiles } from './guard-semantic-interactive';
52
54
  import { unboundedFanoutGuardFiles } from './guard-unbounded-fanout';
53
55
  import { undeclaredCustomPropertyGuardFiles } from './guard-undeclared-custom-property';
@@ -57,48 +59,49 @@ import { unzonedDateGuardFiles } from './guard-unzoned-date';
57
59
  import type { GeneratedFile } from './naming';
58
60
 
59
61
  /**
60
- * Every guard the framework ships, by the name its file carries — the ONE list. `x new` writes all
61
- * of them (`scaffoldGuardFiles`), `x g guard <name>` writes the one it is asked for by name
62
- * (`shippedGuardFiles`), and `x doctor` names the ones an app does not have. Sorted, so the three
63
- * agree on an order. A new shipped guard is one module beside these and one row here.
62
+ * Every guard the framework ships, keyed by the ONE list of names (`guards-shipped-names.ts`, a
63
+ * leaf the serving graph may read): a `Record`, so tsc refuses a name without its module and a
64
+ * module without its name. The `boundaries` step runs each from the installed framework; a new
65
+ * shipped guard is one module beside these, one name there and one row here.
64
66
  */
65
- const SHIPPED: readonly (readonly [string, () => readonly GeneratedFile[]])[] = [
66
- ['animated-layout-property', animatedLayoutPropertyGuardFiles],
67
- ['bare-error', bareErrorGuardFiles],
68
- ['error-declared', errorDeclaredGuardFiles],
69
- ['focus-visible', focusVisibleGuardFiles],
70
- ['image-dimensions', imageDimensionsGuardFiles],
71
- ['island-mount-clears', islandMountClearsGuardFiles],
72
- ['island-without-states', islandWithoutStatesGuardFiles],
73
- ['native-confirm', nativeConfirmGuardFiles],
74
- ['raw-breakpoint', rawBreakpointGuardFiles],
75
- ['raw-colour', rawColourGuardFiles],
76
- ['raw-fetch', rawFetchGuardFiles],
77
- ['raw-interval', rawIntervalGuardFiles],
78
- ['raw-length', rawLengthGuardFiles],
79
- ['raw-motion', rawMotionGuardFiles],
80
- ['raw-shadow', rawShadowGuardFiles],
81
- ['raw-z-index', rawZIndexGuardFiles],
82
- ['repo-await-in-loop', repoAwaitInLoopGuardFiles],
83
- ['repo-raw-sql', repoRawSqlGuardFiles],
84
- ['repo-unbounded', () => repoUnboundedGuardFiles('error')],
85
- ['semantic-interactive', semanticInteractiveGuardFiles],
86
- ['unbounded-fanout', unboundedFanoutGuardFiles],
87
- ['undeclared-custom-property', undeclaredCustomPropertyGuardFiles],
88
- ['undefined-style-class', undefinedStyleClassGuardFiles],
89
- ['untranslated-string', untranslatedStringGuardFiles],
90
- ['unzoned-date', unzonedDateGuardFiles],
91
- ];
67
+ const SHIPPED: Readonly<Record<ShippedGuardName, () => readonly GeneratedFile[]>> = {
68
+ 'animated-layout-property': animatedLayoutPropertyGuardFiles,
69
+ 'bare-error': bareErrorGuardFiles,
70
+ 'error-declared': errorDeclaredGuardFiles,
71
+ 'focus-visible': focusVisibleGuardFiles,
72
+ 'image-dimensions': imageDimensionsGuardFiles,
73
+ 'island-mount-clears': islandMountClearsGuardFiles,
74
+ 'island-without-states': islandWithoutStatesGuardFiles,
75
+ 'native-confirm': nativeConfirmGuardFiles,
76
+ 'raw-breakpoint': rawBreakpointGuardFiles,
77
+ 'raw-colour': rawColourGuardFiles,
78
+ 'raw-fetch': rawFetchGuardFiles,
79
+ 'raw-interval': rawIntervalGuardFiles,
80
+ 'raw-length': rawLengthGuardFiles,
81
+ 'raw-motion': rawMotionGuardFiles,
82
+ 'raw-shadow': rawShadowGuardFiles,
83
+ 'raw-z-index': rawZIndexGuardFiles,
84
+ 'repo-await-in-loop': repoAwaitInLoopGuardFiles,
85
+ 'repo-raw-sql': repoRawSqlGuardFiles,
86
+ 'repo-unbounded': () => repoUnboundedGuardFiles('error'),
87
+ 'runtime-pin': runtimePinGuardFiles,
88
+ 'semantic-interactive': semanticInteractiveGuardFiles,
89
+ 'unbounded-fanout': unboundedFanoutGuardFiles,
90
+ 'undeclared-custom-property': undeclaredCustomPropertyGuardFiles,
91
+ 'undefined-style-class': undefinedStyleClassGuardFiles,
92
+ 'untranslated-string': untranslatedStringGuardFiles,
93
+ 'unzoned-date': unzonedDateGuardFiles,
94
+ };
92
95
 
93
96
  /** The names, in the order every list of them is shown. */
94
- export const SHIPPED_GUARD_NAMES: readonly string[] = SHIPPED.map(([name]) => name);
97
+ export const SHIPPED_GUARD_NAMES: readonly string[] = NAMES;
95
98
 
96
99
  /**
97
100
  * The shipped guard of that name with its test, or `undefined` when the name is not one — which
98
101
  * is an app's own convention, and `x g guard` then writes the blank template instead.
99
102
  */
100
103
  export const shippedGuardFiles = (name: string): readonly GeneratedFile[] | undefined =>
101
- SHIPPED.find(([shipped]) => shipped === name)?.[1]();
104
+ (Object.hasOwn(SHIPPED, name) ? SHIPPED[name as ShippedGuardName] : undefined)?.();
102
105
 
103
106
  /**
104
107
  * The current text of a shipped guard's rule file (`guards/<name>.ts`), or `undefined` when the
@@ -134,10 +137,41 @@ export const shippedGuardSources = (name: string): readonly string[] => {
134
137
  return typeof earlier?.contents === 'string' ? [current, earlier.contents] : [current];
135
138
  };
136
139
 
140
+ /** A rule-file text a shipped guard has been emitted as, and how that form reports. */
141
+ export interface ShippedGuardForm {
142
+ readonly source: string;
143
+ readonly severity: 'error' | 'warning';
144
+ }
145
+
146
+ /** `severity: 'warning',` on a line of its own: the one spelling a shipped template emits. */
147
+ const REPORT_ONLY = /^\s*severity:\s*'warning',\s*$/m;
148
+
149
+ /** Whether a guard's rule-file text reports only. */
150
+ export const reportOnlyForm = (source: string): boolean => REPORT_ONLY.test(source);
151
+
152
+ /**
153
+ * Every current form of a shipped guard with its severity, the template first — what the
154
+ * `vendored-guards` codemod matches an app's copy against. Empty when the name was never shipped.
155
+ */
156
+ export const shippedGuardForms = (name: string): readonly ShippedGuardForm[] =>
157
+ shippedGuardSources(name).map((source) => ({
158
+ source,
159
+ severity: reportOnlyForm(source) ? 'warning' : 'error',
160
+ }));
161
+
162
+ /** The current text of a shipped guard's test (`guards/<name>.test.ts`), or `undefined`. */
163
+ export const shippedGuardTest = (name: string): string | undefined => {
164
+ const contents = shippedGuardFiles(name)?.find(
165
+ (file) => file.path === `guards/${name}.test.ts`,
166
+ )?.contents;
167
+ return typeof contents === 'string' ? contents : undefined;
168
+ };
169
+
137
170
  /**
138
- * Every guard `x new` ships, each with its test. One module per guard, because an app deletes a
139
- * rule it does not want by deleting one file — and a guard the app then writes for itself is
140
- * `x g guard <name>`, the same shape.
171
+ * What `x new` writes into `guards/`: no guard at all — every shipped one runs from the installed
172
+ * framework (`guards-built-in.ts`) — only `guards/shipped.json`, whose presence opts the app into
173
+ * that and whose rows are its severities. The app's own guards join it from `x g guard <name>`.
141
174
  */
142
- export const scaffoldGuardFiles = (): readonly GeneratedFile[] =>
143
- SHIPPED.flatMap(([, files]) => files());
175
+ export const scaffoldGuardFiles = (): readonly GeneratedFile[] => [
176
+ { path: 'guards/shipped.json', contents: '{\n "severity": {}\n}\n' },
177
+ ];
@@ -0,0 +1,105 @@
1
+ // The chart's rules past the request path: latency, the Postgres server (connections, long
2
+ // transactions, autovacuum, replication-slot WAL), the framework schema a rollout must apply first,
3
+ // and the volumes a namespace's claims fill. Joined into `CHART_ALERTS`; type-only imports, so no cycle.
4
+
5
+ import type { AlertScope, ChartAlert } from './scaffold-helm-alert-rules';
6
+
7
+ type Rule = Omit<ChartAlert, 'anchor'>;
8
+
9
+ /** `docs/ops/06-runbooks.md`'s heading for the rule: its name, lower-cased. */
10
+ const rule = (alert: Rule): ChartAlert => ({ ...alert, anchor: alert.alert.toLowerCase() });
11
+
12
+ /** 1 GiB of WAL held for one slot: minutes of a busy primary, hours of a quiet one. */
13
+ const SLOT_RETAINED_BYTES = 1_073_741_824;
14
+
15
+ const max = (s: AlertScope, series: string, extra = ''): string =>
16
+ `max by (${s.by}${extra}) (${s.series(series)})`;
17
+
18
+ export const DEPLOY_ALERTS: readonly ChartAlert[] = [
19
+ rule({
20
+ alert: 'UltimateRequestLatency',
21
+ threshold: 1,
22
+ // Release-wide, never per route: a mechanism's floor, not the app's latency objective — an app
23
+ // with one sets its own threshold, or a per-route rule of its own.
24
+ expr: (s) =>
25
+ `histogram_quantile(0.95, sum by (${s.by}, le) ` +
26
+ `(rate(${s.series('http_request_duration_seconds_bucket')}[5m]))) > ${s.threshold(1)}`,
27
+ for: '10m',
28
+ severity: 'warning',
29
+ summary: 'The p95 of request duration is above the threshold, in seconds',
30
+ }),
31
+ rule({
32
+ alert: 'UltimateConnectionsNearMax',
33
+ threshold: 0.8,
34
+ expr: (s) =>
35
+ `max by (${s.by}) (${s.series('db_server_connections')} / ` +
36
+ `${s.series('db_server_max_connections')}) > ${s.threshold(0.8)}`,
37
+ for: '10m',
38
+ severity: 'warning',
39
+ summary: "The Postgres server's open connections are near its max_connections",
40
+ }),
41
+ rule({
42
+ alert: 'UltimateLongTransaction',
43
+ threshold: 300,
44
+ expr: (s) => `${max(s, 'db_longest_transaction_seconds')} > ${s.threshold(300)}`,
45
+ for: '5m',
46
+ severity: 'warning',
47
+ summary: 'A transaction has been open longer than the threshold, holding back vacuum and locks',
48
+ }),
49
+ rule({
50
+ alert: 'UltimateAutovacuumLag',
51
+ threshold: 2,
52
+ expr: (s) => `${max(s, 'db_autovacuum_backlog_ratio')} > ${s.threshold(2)}`,
53
+ for: '30m',
54
+ severity: 'warning',
55
+ summary:
56
+ 'A table holds more dead tuples than its autovacuum trigger, and is not being vacuumed',
57
+ }),
58
+ rule({
59
+ alert: 'UltimateReplicationSlotRetention',
60
+ threshold: SLOT_RETAINED_BYTES,
61
+ expr: (s) =>
62
+ `${max(s, 'db_replication_slot_retained_bytes', ', slot')} > ${s.threshold(SLOT_RETAINED_BYTES)}`,
63
+ for: '15m',
64
+ severity: 'warning',
65
+ summary: 'A replication slot holds more WAL on the primary than the threshold, in bytes',
66
+ }),
67
+ rule({
68
+ alert: 'UltimateDbStatsStale',
69
+ // The four rules above read gauges a failed round leaves at their last value: without this, a
70
+ // dead sampler keeps every one of them quiet.
71
+ expr: (s) => `count by (${s.by}) (${s.series('db_stats_sample_ok')} == 0) > 0`,
72
+ for: '15m',
73
+ severity: 'warning',
74
+ summary:
75
+ 'The Postgres stats sampler is failing: the connection, transaction, autovacuum and slot values are stale',
76
+ }),
77
+ rule({
78
+ alert: 'UltimateSchemaUnapplied',
79
+ expr: (s) =>
80
+ `count by (${s.by}, ${s.component}) (${s.series('framework_schema_applied')} == 0) > 0`,
81
+ for: '10m',
82
+ severity: 'critical',
83
+ summary:
84
+ "A role is waiting: its build's framework schema or app migrations are not applied (x db migrate)",
85
+ }),
86
+ rule({
87
+ alert: 'UltimateVersionSkew',
88
+ expr: (s) => `${max(s, 'framework_schema_major_skew')} > 0`,
89
+ for: '30m',
90
+ severity: 'warning',
91
+ summary: 'Roles run a different major than the newest applied framework schema',
92
+ }),
93
+ rule({
94
+ alert: 'UltimateVolumeNearFull',
95
+ threshold: 0.85,
96
+ // The kubelet's series, per claim in the release's namespace: the chart mounts no claim, so the
97
+ // volumes this reads are its neighbours' — the database's, most often.
98
+ expr: (s) =>
99
+ `max by (namespace, persistentvolumeclaim) (${s.namespaced('kubelet_volume_stats_used_bytes')} / ` +
100
+ `${s.namespaced('kubelet_volume_stats_capacity_bytes')}) > ${s.threshold(0.85)}`,
101
+ for: '15m',
102
+ severity: 'warning',
103
+ summary: "A persistent volume in the release's namespace is fuller than the threshold",
104
+ }),
105
+ ];
@@ -1,11 +1,16 @@
1
1
  // The rule table every Ultimate chart's alerts are written from, renderer-neutral. Only mechanism
2
2
  // ships (axiom 8): a stalled queue, a dead letter, a lost lease, a dropped frame, error-budget burn,
3
- // job failures, pool, loop and memory saturation, a dead target. A latency target is the app's.
3
+ // job failures, pool, loop and memory saturation, a dead target — and `DEPLOY_ALERTS`' rest. A
4
+ // latency OBJECTIVE is the app's: the shipped latency rule is a generous floor it overrides.
5
+
6
+ import { DEPLOY_ALERTS } from './scaffold-helm-alert-deploy';
4
7
 
5
8
  /** How an expression names a series and groups its result, per renderer. */
6
9
  export interface AlertScope {
7
10
  /** `name{matchers}` — the scope's own matchers, then `extra`. */
8
11
  readonly series: (name: string, extra?: string) => string;
12
+ /** `name{namespace}` — a series the release does not emit (the kubelet's), scoped to its namespace. */
13
+ readonly namespaced: (name: string) => string;
9
14
  /** The labels every rule groups by, so one release (or one job) fires one alert. */
10
15
  readonly by: string;
11
16
  /** The label naming a scrape target's role. */
@@ -157,4 +162,5 @@ export const CHART_ALERTS: readonly ChartAlert[] = [
157
162
  severity: 'critical',
158
163
  summary: 'A role has a scrape target that is down',
159
164
  }),
165
+ ...DEPLOY_ALERTS,
160
166
  ];
@@ -19,6 +19,7 @@ const matchers = (own: string, extra?: string): string =>
19
19
  export const K8S_SCOPE: AlertScope = {
20
20
  series: (name, extra) =>
21
21
  `${name}{${matchers('namespace="{{ $.Release.Namespace }}",app_kubernetes_io_instance="{{ $.Release.Name }}"', extra)}}`,
22
+ namespaced: (name) => `${name}{namespace="{{ $.Release.Namespace }}"}`,
22
23
  by: 'namespace, app_kubernetes_io_instance',
23
24
  component: 'app_kubernetes_io_component',
24
25
  // The operator's own target label: one pod, whichever role it runs.
@@ -32,6 +33,8 @@ const plainScope = (own: string, objective: number): AlertScope => ({
32
33
  const inner = matchers(own, extra);
33
34
  return inner === '' ? name : `${name}{${inner}}`;
34
35
  },
36
+ // Outside Kubernetes no kubelet is scraped: the bare name matches what the loader has, if anything.
37
+ namespaced: (name) => name,
35
38
  by: 'job',
36
39
  component: 'instance',
37
40
  target: 'instance',
@@ -0,0 +1,85 @@
1
+ // The scaffolded chart's release phase: the one migrate Job, ordered before every role under helm,
2
+ // under Argo CD, and as an ordinary object under an applier that ignores both. Split from
3
+ // scaffold-helm-templates.ts; `docker/helm/templates/migrate-job.yaml` is the framework's copy.
4
+
5
+ import type { GeneratedFile, NameSet } from './naming';
6
+
7
+ export const MIGRATE_JOB_PATH = 'docker/helm/templates/migrate-job.yaml';
8
+
9
+ const migrateJob = (app: NameSet): string => `{{/*
10
+ The release phase: ROLE=migrate applies every pending migration under an advisory lock and exits,
11
+ before any serving role starts. Same image, same entry point — there is no second migration engine
12
+ and no toolchain in the container. ONE Job, ordered by whichever applier renders it:
13
+
14
+ helm (and Flux's helm-controller) a pre-install / pre-upgrade / pre-rollback hook: no role is
15
+ touched until it has succeeded. On a rollback it is the OLDER
16
+ build's migrate, which refuses a ledger a newer build left
17
+ destructive rows in (X_MIGRATION_ROLLBACK_DESTRUCTIVE) before
18
+ any role is rolled back onto it
19
+ Argo CD a Sync hook in wave -1. Its own annotation wins over the Helm
20
+ one Argo would otherwise map to PreSync — the phase that runs
21
+ before EVERY wave, so a database the same sync creates was
22
+ waited on forever. Put that database and the Secret the Job
23
+ reads in wave -2 or lower; every role sits in wave 0
24
+ an applier that ignores both an ordinary object, applied beside the roles. Its name hashes
25
+ (kubectl apply, a rendered tree) the image, the migrate block and the chart version, so a new
26
+ image is a new Job rather than an immutable-field refusal of
27
+ the whole apply (an env change alone is still refused: change
28
+ migrate.*, or delete the Job); the roles wait for the stamp it
29
+ leaves, unready, and maxUnavailable: 0 keeps the old pods
30
+ serving meanwhile
31
+
32
+ No init container on any role: a per-pod migrate is a second mechanism, run once per pod, and it
33
+ only ever ordered the Deployment that carried it. Deleted once it succeeds (hook-succeeded, which
34
+ Argo CD honours too); a failed one stays for kubectl logs until migrate.ttlSecondsAfterFinished (a day)
35
+ collects it. A retry of the same image replaces it sooner; a new image's Job has another name and
36
+ never does.
37
+ */}}
38
+ {{- if .Values.migrate.enabled }}
39
+ apiVersion: batch/v1
40
+ kind: Job
41
+ metadata:
42
+ {{- /*
43
+ The name hashes what should make a new Job — the image, the migrate block and the chart version —
44
+ and NEVER the rendered pod: an inline env value would be guessable from 32 bits of its hash.
45
+ 46 + "-migrate-" + 8 = 63, the ceiling of the job-name label every pod of it carries.
46
+ */}}
47
+ {{- $inputs := printf "%s|%s|%s" (include "${app.kebab}.image" .) (toYaml .Values.migrate) .Chart.Version }}
48
+ name: {{ printf "%s-migrate-%s" (include "${app.kebab}.fullname" . | trunc 46 | trimSuffix "-") ($inputs | sha256sum | trunc 8) }}
49
+ labels:
50
+ {{- include "${app.kebab}.labels" . | nindent 4 }}
51
+ app.kubernetes.io/component: migrate
52
+ annotations:
53
+ helm.sh/hook: pre-install,pre-upgrade,pre-rollback
54
+ helm.sh/hook-weight: "-5"
55
+ helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
56
+ argocd.argoproj.io/hook: Sync
57
+ argocd.argoproj.io/sync-wave: "-1"
58
+ spec:
59
+ backoffLimit: {{ .Values.migrate.backoffLimit }}
60
+ {{- /*
61
+ Collected a day after it finishes unless migrate.ttlSecondsAfterFinished says otherwise: the one
62
+ cleanup an applier that ignores hooks gets. Such an applier that reconciles re-creates a collected
63
+ Job on its next pass, which re-runs a migrate with nothing to apply.
64
+ */}}
65
+ ttlSecondsAfterFinished: {{ ternary .Values.migrate.ttlSecondsAfterFinished 86400 (hasKey .Values.migrate "ttlSecondsAfterFinished") | int }}
66
+ template:
67
+ metadata:
68
+ labels:
69
+ {{- include "${app.kebab}.labels" . | nindent 8 }}
70
+ app.kubernetes.io/component: migrate
71
+ spec:
72
+ restartPolicy: Never
73
+ automountServiceAccountToken: false
74
+ securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }}
75
+ containers:
76
+ {{- include "${app.kebab}.container" (dict "role" "migrate" "cfg" .Values.migrate "root" .) | nindent 8 }}
77
+ volumes:
78
+ {{- include "${app.kebab}.tmpVolume" . | nindent 8 }}
79
+ {{- end }}
80
+ `;
81
+
82
+ /** The chart's migrate Job, as `x new` writes it. */
83
+ export function helmMigrateFile(app: NameSet): GeneratedFile {
84
+ return { path: MIGRATE_JOB_PATH, contents: migrateJob(app) };
85
+ }
@@ -6,6 +6,7 @@ import { helmDashboardFiles } from './chart-dashboard';
6
6
  import type { GeneratedFile, NameSet } from './naming';
7
7
  import { helmMonitoringFiles } from './scaffold-helm-alerts';
8
8
  import { helmFenceFiles } from './scaffold-helm-fences';
9
+ import { helmMigrateFile } from './scaffold-helm-migrate';
9
10
 
10
11
  const helpers = (
11
12
  app: NameSet,
@@ -325,41 +326,6 @@ spec:
325
326
  {{- end }}
326
327
  `;
327
328
 
328
- const migrateJob = (app: NameSet): string => `{{/*
329
- The release phase, as a pre-install / pre-upgrade hook: ROLE=migrate applies every pending
330
- migration under an advisory lock and exits, before any serving role starts. Same image, same entry
331
- point — there is no second migration engine and no toolchain in the container.
332
- */}}
333
- {{- if .Values.migrate.enabled }}
334
- apiVersion: batch/v1
335
- kind: Job
336
- metadata:
337
- name: {{ include "${app.kebab}.fullname" . }}-migrate
338
- labels:
339
- {{- include "${app.kebab}.labels" . | nindent 4 }}
340
- app.kubernetes.io/component: migrate
341
- annotations:
342
- helm.sh/hook: pre-install,pre-upgrade
343
- helm.sh/hook-weight: "-5"
344
- helm.sh/hook-delete-policy: before-hook-creation
345
- spec:
346
- backoffLimit: {{ .Values.migrate.backoffLimit }}
347
- template:
348
- metadata:
349
- labels:
350
- {{- include "${app.kebab}.labels" . | nindent 8 }}
351
- app.kubernetes.io/component: migrate
352
- spec:
353
- restartPolicy: Never
354
- automountServiceAccountToken: false
355
- securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }}
356
- containers:
357
- {{- include "${app.kebab}.container" (dict "role" "migrate" "cfg" .Values.migrate "root" .) | nindent 8 }}
358
- volumes:
359
- {{- include "${app.kebab}.tmpVolume" . | nindent 8 }}
360
- {{- end }}
361
- `;
362
-
363
329
  const ingress = (
364
330
  app: NameSet,
365
331
  ): string => `{{/* Standard ingress, no vendor edge primitives. Off by default: the host is yours to name. */}}
@@ -467,7 +433,7 @@ export function helmTemplateFiles(app: NameSet): readonly GeneratedFile[] {
467
433
  { path: 'docker/helm/templates/_helpers.tpl', contents: helpers(app) },
468
434
  { path: 'docker/helm/templates/deployments.yaml', contents: deployments(app) },
469
435
  { path: 'docker/helm/templates/service.yaml', contents: service(app) },
470
- { path: 'docker/helm/templates/migrate-job.yaml', contents: migrateJob(app) },
436
+ helmMigrateFile(app),
471
437
  { path: 'docker/helm/templates/ingress.yaml', contents: ingress(app) },
472
438
  { path: 'docker/helm/templates/hpa.yaml', contents: hpa(app) },
473
439
  ...helmFenceFiles(app),
@@ -191,6 +191,7 @@ minReadySeconds: 10
191
191
  migrate:
192
192
  enabled: true
193
193
  backoffLimit: 1
194
+ ttlSecondsAfterFinished: 86400 # a finished Job, and its logs, are collected after a day
194
195
  resources:
195
196
  requests: { cpu: 100m, memory: 128Mi }
196
197
  limits: { memory: 512Mi }
@@ -48,7 +48,7 @@ export const TYPESCRIPT_VERSION = '^7.0.2';
48
48
  * that installed an older runtime than the compiler targets drifted as a buried literal (1.9.14
49
49
  * beside the repository's 1.9.15). `scaffold-repo.test.ts` holds it equal to the root manifest's.
50
50
  */
51
- const SOLID_VERSION = '1.9.17';
51
+ const SOLID_VERSION = '1.9.18';
52
52
 
53
53
  // `engines.bun` is `REQUIRED_BUN`, the floor the SHIPPED `x` enforces
54
54
  // (`packages/cli/src/app-root.ts`), and not a second literal. It was one: `>=1.3.0`, a whole minor
@@ -356,6 +356,7 @@ packages/*/dist/
356
356
  /coverage/
357
357
  playwright-report/
358
358
  test-results/
359
+ repro/bundle-*.json
359
360
  `;
360
361
 
361
362
  // Values, not declarations — the declaration is `envSchema` and `.env.example` is its projection.
@@ -23,4 +23,6 @@ export const UNTHROWN_CODES: ReadonlySet<string> = new Set([
23
23
  'X_PWA_SYNC_INCOMPLETE',
24
24
  // 24.0.0: `x test --worker` was deleted; `x verify --only unit --shard i/n` is the one split.
25
25
  'X_TEST_SHARD_FAILED',
26
+ // 31.28.0: shipped guards run built in, so none is ever missing (X_GUARD_VENDORED names copies).
27
+ 'X_SHIPPED_GUARD_MISSING',
26
28
  ]);
@@ -4,6 +4,7 @@
4
4
 
5
5
  // why: Bun exposes no basename primitive.
6
6
  import { basename } from 'node:path';
7
+ import { scaffoldDigestPatch } from './templates/bun-image';
7
8
 
8
9
  export interface BunEdit {
9
10
  readonly path: string;
@@ -181,6 +182,9 @@ function editLine(input: {
181
182
  const parts = TAG.exec(tag);
182
183
  const version = parts?.[1];
183
184
  if (digest !== undefined) {
185
+ // A digest `x new` wrote holds a patch the framework knows, so the line says enough after all.
186
+ const known = scaffoldDigestPatch(digest.slice(1));
187
+ if (known !== undefined && !isBelow(known, floor)) return line;
184
188
  const inspect = `by hand (docker buildx imagetools inspect oven/bun:${floor}-alpine)`;
185
189
  if (version === undefined || isBelow(version, floor)) {
186
190
  return listed(
@@ -0,0 +1,54 @@
1
+ // `x upgrade`'s first refusal: a hop is one reviewable commit, so the tree must be clean — its own
2
+ // lock and record aside. When a stopped hop's record is there, the dirty tree IS that hop, and the
3
+ // fix is to stash it: committing half a hop is how a broken tree gets reviewed as a finished one.
4
+
5
+ // why: Bun exposes no path-join primitive; the state files are joined onto the app root.
6
+ import { join } from 'node:path';
7
+ import { UltimateError } from '@ultimat3/core';
8
+ import type { Runner } from './exec';
9
+ import { posixRelative } from './posix-path';
10
+ import { UPGRADE_LOCK_FILE } from './upgrade-lock';
11
+ import type { UnfinishedHop } from './upgrade-unfinished';
12
+ import { UNFINISHED_FILE } from './upgrade-unfinished';
13
+
14
+ /** The repository's root, or the refusal: git is the only record of where the walk stands. */
15
+ export async function requireCleanTree(
16
+ runner: Runner,
17
+ root: string,
18
+ unfinished: UnfinishedHop | undefined,
19
+ ): Promise<string> {
20
+ const top = await runner(['git', 'rev-parse', '--show-toplevel'], { cwd: root });
21
+ if (!top.ok) {
22
+ throw new UltimateError({
23
+ code: 'X_UPGRADE_DIRTY_TREE',
24
+ cause: `${root} is not a git repository, and a hop has to be one commit you can review or undo`,
25
+ fix: 'git init && git add -A && git commit -m "before x upgrade" # then: x upgrade --json',
26
+ });
27
+ }
28
+ const repo = top.stdout.trim();
29
+ // Every untracked file by name, so this run's own lock and record — in an `.x/` a repository
30
+ // with no app may not ignore — are told apart from an author's change.
31
+ const own = new Set(
32
+ [UPGRADE_LOCK_FILE, UNFINISHED_FILE].map((file) => posixRelative(repo, join(root, file))),
33
+ );
34
+ const status = await runner(['git', 'status', '--porcelain', '--untracked-files=all'], {
35
+ cwd: root,
36
+ });
37
+ const changes = status.stdout
38
+ .split('\n')
39
+ .filter((line) => line.trim().length > 0 && !own.has(line.slice(3)));
40
+ if (status.ok && changes.length === 0) return repo;
41
+ const listed = changes.slice(0, 5).join('; ');
42
+ if (unfinished !== undefined) {
43
+ throw new UltimateError({
44
+ code: 'X_UPGRADE_DIRTY_TREE',
45
+ cause: `an x upgrade from ${unfinished.from} to ${unfinished.to} stopped after writing its pins (${UNFINISHED_FILE}, started ${unfinished.startedAt || 'at an unknown time'}), and its ${String(changes.length)} uncommitted change(s) are that half-finished hop: ${listed}`,
46
+ fix: 'git stash push --include-untracked # sets the half hop aside; then: x upgrade --json',
47
+ });
48
+ }
49
+ throw new UltimateError({
50
+ code: 'X_UPGRADE_DIRTY_TREE',
51
+ cause: `${String(changes.length)} uncommitted change(s), and a hop has to be one reviewable commit: ${listed}`,
52
+ fix: 'git status --short # then commit or stash, and re-run: x upgrade --json',
53
+ });
54
+ }
@@ -0,0 +1,40 @@
1
+ // After codemods, the install they may owe: every `package.json` of the app read before and after,
2
+ // byte for byte — never a codemod's own report, which an installed CLI may under-state — and one
3
+ // `bun install` when any moved, so bun.lock and node_modules follow before anything reads them.
4
+
5
+ import { UltimateError } from '@ultimat3/core';
6
+ import type { Runner } from './exec';
7
+ import { execOutput } from './exec';
8
+
9
+ const MANIFESTS = new Bun.Glob('**/package.json');
10
+
11
+ /** Every `package.json` under the app root (none under `node_modules`), path to bytes. */
12
+ export async function manifestSnapshot(root: string): Promise<ReadonlyMap<string, string>> {
13
+ const out = new Map<string, string>();
14
+ for await (const path of MANIFESTS.scan({ cwd: root, dot: false })) {
15
+ const posix = path.replaceAll('\\', '/');
16
+ if (posix.split('/').includes('node_modules')) continue;
17
+ out.set(posix, await Bun.file(`${root}/${posix}`).text());
18
+ }
19
+ return out;
20
+ }
21
+
22
+ const moved = (before: ReadonlyMap<string, string>, after: ReadonlyMap<string, string>): boolean =>
23
+ before.size !== after.size || [...after].some(([path, text]) => before.get(path) !== text);
24
+
25
+ /** `bun install` when a manifest moved since `before`; true when it ran. */
26
+ export async function reinstallIfMoved(input: {
27
+ readonly runner: Runner;
28
+ readonly root: string;
29
+ readonly to: string;
30
+ readonly before: ReadonlyMap<string, string>;
31
+ }): Promise<boolean> {
32
+ if (!moved(input.before, await manifestSnapshot(input.root))) return false;
33
+ const result = await input.runner([process.execPath, 'install'], { cwd: input.root });
34
+ if (result.ok) return true;
35
+ throw new UltimateError({
36
+ code: 'X_UPGRADE_INSTALL_FAILED',
37
+ cause: `bun install exited ${String(result.code)} after the ${input.to} codemods moved a package.json: ${execOutput(result).slice(-800) || 'no output'}`,
38
+ fix: 'git diff -- "*package.json" # the codemods\' edits; fix what the cause names, then: bun install && x upgrade --json',
39
+ });
40
+ }