@ultimat3/cli 31.39.0 → 31.40.1

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 (52) hide show
  1. package/README.md +1 -1
  2. package/package.json +29 -29
  3. package/src/cmd-errors-guards.ts +69 -0
  4. package/src/cmd-errors.ts +11 -4
  5. package/src/cmd-exercise.ts +3 -2
  6. package/src/cmd-new-spec.ts +8 -1
  7. package/src/cmd-new-target.ts +115 -0
  8. package/src/cmd-new.ts +13 -19
  9. package/src/cmd-repro.ts +2 -1
  10. package/src/codemods/ci-e2e-browser.ts +7 -1
  11. package/src/codemods/ci-services-env.ts +25 -0
  12. package/src/codemods/docs-env-guard.ts +31 -0
  13. package/src/codemods/index.ts +4 -0
  14. package/src/dev-boot.ts +3 -0
  15. package/src/dev-rebuild-isr.ts +17 -0
  16. package/src/dev-rebuild.ts +14 -5
  17. package/src/error-contract.ts +11 -4
  18. package/src/exercise-findings-unreached.ts +94 -0
  19. package/src/exercise-findings.ts +9 -57
  20. package/src/exercise-route-api.ts +3 -4
  21. package/src/fix-sequence.ts +28 -3
  22. package/src/framework-schema-wait.ts +41 -2
  23. package/src/generate-feature-required.ts +40 -3
  24. package/src/generate-kinds.ts +23 -2
  25. package/src/guards-shipped-names.ts +1 -0
  26. package/src/messages.ts +8 -0
  27. package/src/serve-boot.ts +4 -0
  28. package/src/templates/action.ts +7 -2
  29. package/src/templates/github/ci.yml.ts +3 -2
  30. package/src/templates/guard-raw-colour.ts +88 -13
  31. package/src/templates/guard-released-forms.ts +9 -3
  32. package/src/templates/guard-undeclared-env.ts +192 -0
  33. package/src/templates/guard-untranslated-string.ts +29 -1
  34. package/src/templates/policy.ts +7 -1
  35. package/src/templates/query.ts +8 -6
  36. package/src/templates/scaffold-docs.ts +1 -0
  37. package/src/templates/scaffold-guards.ts +4 -1
  38. package/src/templates/scaffold-i18n.ts +1 -1
  39. package/src/templates/scaffold-repo.ts +26 -24
  40. package/src/templates/shapes/agent.ts +2 -2
  41. package/src/templates/shapes/offline.ts +1 -1
  42. package/src/templates/shapes/realtime.ts +2 -2
  43. package/src/templates/shapes/saas.ts +5 -4
  44. package/src/templates/slice-foundation.ts +29 -9
  45. package/wiki/Actions.md +1 -1
  46. package/wiki/CLI-Reference.md +2 -2
  47. package/wiki/Getting-Started.md +1 -1
  48. package/wiki/Installation.md +2 -2
  49. package/wiki/Queries-And-Live-Queries.md +4 -4
  50. package/wiki/Realtime.md +12 -2
  51. package/wiki/Tutorial-04-Jobs-And-Realtime.md +3 -2
  52. package/wiki/Upgrading.md +2 -1
package/README.md CHANGED
@@ -184,7 +184,7 @@ failure — so a rule ships to every app before the apps are clean of it; a find
184
184
  contract fails either way. `repo-await-in-loop` ships that way. `x g guard <name>` scaffolds the
185
185
  app's own with its test.
186
186
 
187
- The twenty-six shipped guards (`SHIPPED_GUARD_NAMES`) run **built in**, from the installed CLI,
187
+ The twenty-seven shipped guards (`SHIPPED_GUARD_NAMES`) run **built in**, from the installed CLI,
188
188
  never from a copy (`guards-built-in.ts`, `As of 2026-11`): `x new` writes only
189
189
  `guards/shipped.json`, `{ "severity": { "<guard>": "error" | "warning" | "off" } }`, and its
190
190
  presence is the opt-in. Absent (a legacy app), a shipped guard the app holds a copy of runs that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/cli",
3
- "version": "31.39.0",
3
+ "version": "31.40.1",
4
4
  "description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -53,34 +53,34 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@babel/core": "^8.0.10",
56
- "@ultimat3/action": "31.39.0",
57
- "@ultimat3/admin": "31.39.0",
58
- "@ultimat3/ai": "31.39.0",
59
- "@ultimat3/auth": "31.39.0",
60
- "@ultimat3/cache": "31.39.0",
61
- "@ultimat3/core": "31.39.0",
62
- "@ultimat3/db": "31.39.0",
63
- "@ultimat3/entity": "31.39.0",
64
- "@ultimat3/flags": "31.39.0",
65
- "@ultimat3/http": "31.39.0",
66
- "@ultimat3/i18n": "31.39.0",
67
- "@ultimat3/jobs": "31.39.0",
68
- "@ultimat3/mail": "31.39.0",
69
- "@ultimat3/manifest": "31.39.0",
70
- "@ultimat3/mcp": "31.39.0",
71
- "@ultimat3/money": "31.39.0",
72
- "@ultimat3/notify": "31.39.0",
73
- "@ultimat3/policy": "31.39.0",
74
- "@ultimat3/pwa": "31.39.0",
75
- "@ultimat3/query": "31.39.0",
76
- "@ultimat3/realtime": "31.39.0",
77
- "@ultimat3/render": "31.39.0",
78
- "@ultimat3/schema": "31.39.0",
79
- "@ultimat3/scraping": "31.39.0",
80
- "@ultimat3/seo": "31.39.0",
81
- "@ultimat3/storage": "31.39.0",
82
- "@ultimat3/testing": "31.39.0",
83
- "@ultimat3/time": "31.39.0",
56
+ "@ultimat3/action": "31.40.1",
57
+ "@ultimat3/admin": "31.40.1",
58
+ "@ultimat3/ai": "31.40.1",
59
+ "@ultimat3/auth": "31.40.1",
60
+ "@ultimat3/cache": "31.40.1",
61
+ "@ultimat3/core": "31.40.1",
62
+ "@ultimat3/db": "31.40.1",
63
+ "@ultimat3/entity": "31.40.1",
64
+ "@ultimat3/flags": "31.40.1",
65
+ "@ultimat3/http": "31.40.1",
66
+ "@ultimat3/i18n": "31.40.1",
67
+ "@ultimat3/jobs": "31.40.1",
68
+ "@ultimat3/mail": "31.40.1",
69
+ "@ultimat3/manifest": "31.40.1",
70
+ "@ultimat3/mcp": "31.40.1",
71
+ "@ultimat3/money": "31.40.1",
72
+ "@ultimat3/notify": "31.40.1",
73
+ "@ultimat3/policy": "31.40.1",
74
+ "@ultimat3/pwa": "31.40.1",
75
+ "@ultimat3/query": "31.40.1",
76
+ "@ultimat3/realtime": "31.40.1",
77
+ "@ultimat3/render": "31.40.1",
78
+ "@ultimat3/schema": "31.40.1",
79
+ "@ultimat3/scraping": "31.40.1",
80
+ "@ultimat3/seo": "31.40.1",
81
+ "@ultimat3/storage": "31.40.1",
82
+ "@ultimat3/testing": "31.40.1",
83
+ "@ultimat3/time": "31.40.1",
84
84
  "babel-preset-solid": "^1.9.16"
85
85
  }
86
86
  }
@@ -0,0 +1,69 @@
1
+ // `x errors explain` for a code a guard raises: the shipped guards' (`X_RAW_COLOUR`, derived from the
2
+ // guard's name) and the app's own `guards/*.ts`. Neither is in an error registry — the app owns
3
+ // the codes its conventions raise — so each is answered from the guard's own declaration: its
4
+ // `summary`, read off the source text, never by importing and running the rule.
5
+
6
+ // why: Bun ships no path joiner; `guards/` sits under the app root.
7
+ import { join } from 'node:path';
8
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
9
+ import type { ErrorExplanation } from '@ultimat3/mcp';
10
+ import { findAppRoot } from './app-root';
11
+ import { SHIPPED_GUARD_CONFIG, SHIPPED_SEVERITY_FIELD } from './guards-built-in';
12
+ import { SHIPPED_GUARD_NAMES, shippedGuardCode } from './guards-shipped-names';
13
+
14
+ /** `summary: '…'` in a guard's `export const guard = { … }`, the line broken after the colon or not. */
15
+ const SUMMARY = /\bsummary:\s*'((?:[^'\\]|\\.)*)'/;
16
+
17
+ const summaryOf = (source: string): string | undefined => SUMMARY.exec(source)?.[1];
18
+
19
+ const RUN = 'x verify --only boundaries --json';
20
+
21
+ /** A shipped guard: its template's text, loaded only when a guard code was asked about. */
22
+ async function explainShipped(code: string): Promise<ErrorExplanation | undefined> {
23
+ const name = SHIPPED_GUARD_NAMES.find((one) => shippedGuardCode(one) === code);
24
+ if (name === undefined) return undefined;
25
+ const { shippedGuardSource } = await import('./templates/scaffold-guards');
26
+ const summary = summaryOf(shippedGuardSource(name) ?? '') ?? name;
27
+ return {
28
+ code,
29
+ cause: `the shipped ${name} guard refuses it: ${summary} (run by the boundaries step of x verify)`,
30
+ fix: `${RUN} # each ${code} finding names its file:line and the edit that clears it; to stop running the guard, set "${name}": "off" under "${SHIPPED_SEVERITY_FIELD}" in ${SHIPPED_GUARD_CONFIG}`,
31
+ docs: ERROR_DOCS_URL,
32
+ };
33
+ }
34
+
35
+ /** An app guard: the `guards/*.ts` file whose text names the code as a literal. */
36
+ async function explainAppGuard(code: string, cwd: string): Promise<ErrorExplanation | undefined> {
37
+ const literal = new RegExp(`['"\`]${code}['"\`]`);
38
+ // The app's root from anywhere inside it; outside an app, `--cwd` as given.
39
+ const dir = join(findAppRoot(cwd)?.dir ?? cwd, 'guards');
40
+ let files: string[];
41
+ try {
42
+ files = await Array.fromAsync(new Bun.Glob('*.{ts,tsx}').scan({ cwd: dir }));
43
+ } catch {
44
+ // No `guards/` here: not an app, or an app with none — nothing to explain from.
45
+ return undefined;
46
+ }
47
+ for (const file of files.sort()) {
48
+ if (/\.test\.tsx?$/.test(file)) continue;
49
+ const source = await Bun.file(join(dir, file)).text();
50
+ if (!literal.test(source)) continue;
51
+ const at = `guards/${file}`;
52
+ return {
53
+ code,
54
+ cause: `this app's guard ${at} refuses it: ${summaryOf(source) ?? 'its summary is not a plain string'} (run by the boundaries step of x verify)`,
55
+ fix: `${RUN} # each ${code} finding names its file:line and the edit that clears it; the rule is ${at} — delete that file to drop it`,
56
+ docs: ERROR_DOCS_URL,
57
+ };
58
+ }
59
+ return undefined;
60
+ }
61
+
62
+ /** The guard behind `code` — the app's own first, since its file is what this app runs. */
63
+ export async function explainGuardCode(
64
+ code: string,
65
+ cwd: string,
66
+ ): Promise<ErrorExplanation | undefined> {
67
+ if (!/^X(?:_[A-Z0-9]+)+$/.test(code)) return undefined;
68
+ return (await explainAppGuard(code, cwd)) ?? (await explainShipped(code));
69
+ }
package/src/cmd-errors.ts CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  import { nearestName, singleLine } from '@ultimat3/core';
6
6
  import type { ErrorExplanation } from '@ultimat3/mcp';
7
+ import { explainGuardCode } from './cmd-errors-guards';
7
8
  import { withRecent } from './cmd-errors-recent';
8
9
  import { errorsSpec } from './cmd-errors-spec';
9
10
  import type { CliCommand, CommandContext } from './command';
@@ -42,8 +43,12 @@ const detailLines = (explanation: ErrorExplanation): readonly string[] => [
42
43
  ` docs: ${singleLine(explanation.docs)}`,
43
44
  ];
44
45
 
45
- function explainOne(code: string): CommandResult {
46
- const explanation = explainErrorCode(code);
46
+ /**
47
+ * A registered code, else a guard's — a shipped guard's or this app's own (`cmd-errors-guards.ts`):
48
+ * the gate prints both, and the app's `CLAUDE.md` sends every printed code here.
49
+ */
50
+ async function explainOne(code: string, cwd: string): Promise<CommandResult> {
51
+ const explanation = explainErrorCode(code) ?? (await explainGuardCode(code, cwd));
47
52
  if (explanation === undefined) {
48
53
  const suggestion = nearestName(
49
54
  code,
@@ -108,7 +113,9 @@ export const errorsCommand: CliCommand = {
108
113
  });
109
114
  }
110
115
  // `--recent`: what THIS app has seen of the code — groups and the bundles `x repro` replays.
111
- if (flagBool(ctx.args, 'recent')) return withRecent(ctx, code, explainOne(code));
112
- return explainOne(code);
116
+ if (flagBool(ctx.args, 'recent')) {
117
+ return withRecent(ctx, code, await explainOne(code, ctx.cwd));
118
+ }
119
+ return explainOne(code, ctx.cwd);
113
120
  },
114
121
  };
@@ -175,8 +175,9 @@ async function exercisePass(
175
175
  ...(whole ? entityTenantFindings(describeEntities()) : []),
176
176
  ...subjectStatic,
177
177
  ...subjectProofs,
178
- // The fix pastes into the file the app has, or hands it the file it lacks.
179
- ...exerciseFindings(records, overrides === undefined ? 'absent' : 'present'),
178
+ // The fix pastes into the file the app has, hands it the file it lacks, or — for an entry the
179
+ // file already holds — edits that entry: a second key is TS1117.
180
+ ...exerciseFindings(records, overrides),
180
181
  ...floor.findings,
181
182
  ];
182
183
  return {
@@ -35,6 +35,13 @@ export const newSpec: CommandSpec = {
35
35
  default: true,
36
36
  },
37
37
  { name: 'dry-run', type: 'boolean', summary: 'print the file list, write nothing' },
38
- { name: 'force', type: 'boolean', summary: 'write into a directory that already exists' },
38
+ {
39
+ name: 'force',
40
+ type: 'boolean',
41
+ // Never over an app, never over a file: `cmd-new-target.ts` refuses a directory holding
42
+ // `app.config.ts` (D1) or any path the scaffold writes (round 3).
43
+ summary:
44
+ 'write into an existing directory that holds no app.config.ts and none of the files x new writes',
45
+ },
39
46
  ],
40
47
  };
@@ -0,0 +1,115 @@
1
+ // `x new`'s refusal of a target directory that already exists. Its fix names a FREE directory —
2
+ // never `--force`: a fix is pasted with no diff in front of it, and `--force` over an existing app
3
+ // reset its `api/index.ts` and `roles.ts` to the template (D1, 2026-11-16). `--force` writes only
4
+ // into free paths: one planned path already on disk refuses the run (round 3, 2026-11-16).
5
+
6
+ // why: the target is a DIRECTORY, which `Bun.file().exists()` answers false for; `lstatSync`
7
+ // also sees a dangling symlink, which `Bun.write` would write through.
8
+ import { existsSync, lstatSync } from 'node:fs';
9
+ // why: Bun ships no path API; `dirname`/`join` place the sibling the fix names.
10
+ import { dirname, join } from 'node:path';
11
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
12
+ import { appNameIssue } from './app-name';
13
+ import { msg } from './messages';
14
+ import type { CommandResult } from './output';
15
+ import { quoteArg } from './shell-quote';
16
+
17
+ /** How far `-2`, `-3`, … is walked before the fix falls back to a placeholder. */
18
+ const SUFFIX_LIMIT = 100;
19
+
20
+ /**
21
+ * The first `<slug>-<n>` beside `target` that is not on disk and that core's `defineConfig`
22
+ * accepts — a free name, so the fix cannot land on a second existing directory.
23
+ */
24
+ export function freeSibling(target: string, slug: string): string | undefined {
25
+ for (let n = 2; n <= SUFFIX_LIMIT; n += 1) {
26
+ const suffix = `-${n}`;
27
+ const candidate = `${slug.slice(0, 64 - suffix.length)}${suffix}`;
28
+ if (appNameIssue(candidate) !== undefined) continue;
29
+ if (!existsSync(join(dirname(target), candidate))) return candidate;
30
+ }
31
+ return undefined;
32
+ }
33
+
34
+ export interface NewTarget {
35
+ readonly target: string;
36
+ readonly slug: string;
37
+ readonly force: boolean;
38
+ /** `invocationOf(ctx, 'new')`: `x new` or `bunx create-ultimate`. */
39
+ readonly invocation: string;
40
+ /** The caller's flags as `reproducedFlags` spells them; `--force` is dropped here. */
41
+ readonly flags: readonly string[];
42
+ /** `planNewApp`'s paths, relative to `target`: what `--force` would write. */
43
+ readonly planned: readonly string[];
44
+ }
45
+
46
+ /** How many colliding paths the cause spells out before it counts the rest. */
47
+ const LISTED_COLLISIONS = 5;
48
+
49
+ /**
50
+ * The planned paths `--force` would overwrite: the path itself on disk (file, directory or link),
51
+ * or one of its parent segments on disk as something other than a directory.
52
+ */
53
+ export function collisions(target: string, planned: readonly string[]): readonly string[] {
54
+ const hit = new Set<string>();
55
+ for (const path of planned) {
56
+ const segments = path.split('/');
57
+ for (let i = 1; i <= segments.length; i += 1) {
58
+ const prefix = segments.slice(0, i).join('/');
59
+ const stat = lstatSync(join(target, prefix), { throwIfNoEntry: false });
60
+ if (stat === undefined) break;
61
+ if (i === segments.length || !stat.isDirectory()) {
62
+ hit.add(prefix);
63
+ break;
64
+ }
65
+ }
66
+ }
67
+ return [...hit].sort();
68
+ }
69
+
70
+ const listed = (paths: readonly string[]): string => {
71
+ const head = paths.slice(0, LISTED_COLLISIONS).join(', ');
72
+ const rest = paths.length - LISTED_COLLISIONS;
73
+ return rest > 0 ? `${head} and ${rest} more` : head;
74
+ };
75
+
76
+ /**
77
+ * The refusal of an existing target, before a byte is written — `undefined` when the run may go on.
78
+ * `--force` lifts it only for a directory that holds no `app.config.ts` and none of the planned
79
+ * paths — a fresh clone the platform scaffolds into (`.git`, a `LICENSE`). Over an app it would
80
+ * reset every file the template also writes; over a monorepo root, its `package.json` and
81
+ * `README.md`. A result, not a throw, so the summary says which it was.
82
+ */
83
+ export function targetConflict(input: NewTarget): CommandResult | undefined {
84
+ const { target, slug, force, invocation, flags } = input;
85
+ if (!existsSync(target)) return undefined;
86
+ const holdsApp = existsSync(join(target, 'app.config.ts'));
87
+ const taken = force && !holdsApp ? collisions(target, input.planned) : [];
88
+ if (force && !holdsApp && taken.length === 0) return undefined;
89
+ return {
90
+ ok: false,
91
+ command: 'new',
92
+ summary: holdsApp
93
+ ? msg('cli.new.existsApp', { dir: target })
94
+ : taken.length > 0
95
+ ? msg('cli.new.existsFiles', { dir: target, count: taken.length })
96
+ : msg('cli.new.exists', { dir: target }),
97
+ findings: [
98
+ {
99
+ code: 'X_GENERATE_CONFLICT',
100
+ cause: holdsApp
101
+ ? `${target} already exists and holds an app (app.config.ts): scaffolding into it, --force included, would reset its registrations and grants to the template, so x new refuses it`
102
+ : taken.length > 0
103
+ ? `${target} already holds ${taken.length} path(s) x new would write: ${listed(taken)}. --force writes only into free paths, so nothing was written — move each aside (mv -n ${quoteArg(taken[0] ?? '')} ${quoteArg(`${taken[0] ?? ''}.orig`)}, …) and run with --force again to scaffold here, or take a free name for a fresh app`
104
+ : `${target} already exists and holds no app.config.ts — --force writes the scaffold into it only when none of its paths are taken, a free name writes a fresh app`,
105
+ fix: [
106
+ invocation,
107
+ quoteArg(freeSibling(target, slug) ?? '<another-name>'),
108
+ ...flags.filter((flag) => flag !== '--force'),
109
+ ].join(' '),
110
+ docs: ERROR_DOCS_URL,
111
+ at: target,
112
+ },
113
+ ],
114
+ };
115
+ }
package/src/cmd-new.ts CHANGED
@@ -6,10 +6,11 @@
6
6
  // path API, and `isAbsolute`/`join`/`relative`/`resolve` place the new app.
7
7
  import { existsSync } from 'node:fs';
8
8
  import { isAbsolute, join, relative, resolve } from 'node:path';
9
- import { ERROR_DOCS_URL, renderThrowable } from '@ultimat3/core';
9
+ import { renderThrowable } from '@ultimat3/core';
10
10
  import { AppNameInvalidError, appNameIssue } from './app-name';
11
11
  import { dedupe } from './cmd-generate';
12
12
  import { newSpec } from './cmd-new-spec';
13
+ import { targetConflict } from './cmd-new-target';
13
14
  import type { CliCommand, CommandContext } from './command';
14
15
  import { invocationOf } from './command';
15
16
  import { AppNameEmptyError, AppNameIsPathError, MissingPositionalError } from './errors';
@@ -306,24 +307,17 @@ export const newCommand: CliCommand = {
306
307
  ),
307
308
  };
308
309
  }
309
- if (existsSync(target) && !flagBool(ctx.args, 'force')) {
310
- return {
311
- ok: false,
312
- command: 'new',
313
- summary: msg('cli.usage'),
314
- findings: [
315
- {
316
- code: 'X_GENERATE_CONFLICT',
317
- cause: `${target} already exists`,
318
- // The invocation the caller ran, with every flag it set: dropping `--dir` wrote a
319
- // second app into the cwd, and the literal `x` is not installed under create-ultimate.
320
- fix: `${[invocationOf(ctx, 'new'), quoteArg(app.kebab), ...callerFlags(ctx), '--force'].join(' ')} # or choose another name`,
321
- docs: ERROR_DOCS_URL,
322
- at: target,
323
- },
324
- ],
325
- };
326
- }
310
+ // The invocation the caller ran, with every flag it set: dropping `--dir` wrote a second app
311
+ // into the cwd, and the literal `x` is not installed under create-ultimate.
312
+ const conflict = targetConflict({
313
+ target,
314
+ slug: app.kebab,
315
+ force: flagBool(ctx.args, 'force'),
316
+ invocation: invocationOf(ctx, 'new'),
317
+ flags: callerFlags(ctx),
318
+ planned: planNewApp(options).map((file) => file.path),
319
+ });
320
+ if (conflict !== undefined) return conflict;
327
321
  // Read BEFORE writing: `--force` into a directory that already held files must never
328
322
  // `git add -A && git commit` them — they are the user's, and `x new` did not write them.
329
323
  const existed = existsSync(target);
package/src/cmd-repro.ts CHANGED
@@ -89,7 +89,8 @@ async function answer(
89
89
  return { ok: true, command: 'repro', summary: summaryOf(subject), data: base };
90
90
  }
91
91
  const file = reproFile(subject);
92
- const runningBuild = ctx.env['BUILD_ID'] ?? null;
92
+ // An empty `BUILD_ID` is an unstamped image, never a build named `""`.
93
+ const runningBuild = ctx.env['BUILD_ID'] || null;
93
94
  await writeRepro(root, file, await reproSource(root, subject, id, runningBuild), ctx.runner);
94
95
  const lines = [msg('cli.repro.written', { file })];
95
96
  if (!verify) {
@@ -19,6 +19,9 @@ const START = lines(
19
19
  ' docker compose -f docker/docker-compose.test.yml up -d --wait',
20
20
  ' cat docker/test-services.env >> "$GITHUB_ENV"',
21
21
  );
22
+ /** The line the inserted step writes: present, the edit is carried whatever surrounds it. */
23
+ const E2E_REQUIRED = 'E2E_BROWSER_REQUIRED=1';
24
+
22
25
  const NEXT =
23
26
  ' # Under $RUNNER_TEMP, never in the checkout, where `lint` would walk the open file.';
24
27
 
@@ -30,7 +33,7 @@ export const CI_E2E_EDITS: readonly SnippetEdit[] = [
30
33
  ' # ubuntu-latest ships Chrome, and the `e2e` step finds it. Required here, so a runner that',
31
34
  ' # has none (a `CI_RUNNER` label) is red with the command that locates one — never a skip.',
32
35
  " - if: contains(matrix.only, 'e2e')",
33
- ' run: echo "E2E_BROWSER_REQUIRED=1" >> "$GITHUB_ENV"',
36
+ ` run: echo "${E2E_REQUIRED}" >> "$GITHUB_ENV"`,
34
37
  NEXT,
35
38
  ),
36
39
  },
@@ -58,6 +61,9 @@ export const codemod: Codemod = {
58
61
  async run(app) {
59
62
  const held = await readText(app, CI);
60
63
  if (held === undefined) return { changed: [], skipped: [] };
64
+ // Carried already: its anchor's `cat` line is `ci-services-env`'s (31.40) to change, so a newer
65
+ // workflow no longer holds the text this edit is spelled against — the step it adds says enough.
66
+ if (held.text.includes(E2E_REQUIRED)) return { changed: [], skipped: [] };
61
67
  return (await wholeFile(app, held)) ?? editSnippets(app, CI, CI_E2E_EDITS);
62
68
  },
63
69
  };
@@ -0,0 +1,25 @@
1
+ // 31.40.0: the services part appends only the env file's `TEST_` assignments to $GITHUB_ENV.
2
+ // `cat docker/test-services.env` handed GitHub the file's `#` header, and GitHub refuses the whole
3
+ // file ("Invalid format"), so every services part went red. One line swapped; an app that appends
4
+ // its own way is reported with the diff.
5
+
6
+ import { CI_WORKFLOW_PATH } from '../templates/github/ci.yml';
7
+ import type { Codemod } from './codemod';
8
+ import type { SnippetEdit } from './engine-edits';
9
+ import { editSnippets } from './engine-edits';
10
+
11
+ const CI = CI_WORKFLOW_PATH;
12
+
13
+ export const CI_SERVICES_ENV_EDITS: readonly SnippetEdit[] = [
14
+ {
15
+ from: ' cat docker/test-services.env >> "$GITHUB_ENV"',
16
+ to: ` grep -E '^TEST_[A-Z0-9_]+=' docker/test-services.env >> "$GITHUB_ENV"`,
17
+ },
18
+ ];
19
+
20
+ export const codemod: Codemod = {
21
+ id: 'ci-services-env',
22
+ since: '31.40.0',
23
+ summary: `${CI}: the services part appends only TEST_ lines to $GITHUB_ENV, never the env file's # header GitHub refuses`,
24
+ run: (app) => editSnippets(app, CI, CI_SERVICES_ENV_EDITS),
25
+ };
@@ -0,0 +1,31 @@
1
+ // 31.40.0: the `undeclared-env` guard ships, so CLAUDE.md's table names it on an Env row,
2
+ // under the Runtime row. Prose: it lands where that row stands as `x new` wrote it, and is skipped
3
+ // silently where the app reworded it or already wrote one.
4
+
5
+ import type { Codemod } from './codemod';
6
+ import type { SnippetEdit } from './engine-edits';
7
+ import { editSnippets } from './engine-edits';
8
+
9
+ const CLAUDE = 'CLAUDE.md';
10
+
11
+ const RUNTIME =
12
+ "| Runtime | every Bun pin — `packageManager`, `.bun-version`, CI's `bun-version:`, the image's `FROM oven/bun:` — names the version `engines.bun` declares, and an image builds on a digest | `runtime-pin` |";
13
+
14
+ /** Terse on purpose: a shaped app's CLAUDE.md sits within bytes of `AGENTS_MD_MAX_BYTES`. */
15
+ export const ENVIRONMENT_ROW = '| Env | declared in `envSchema` | `undeclared-env` |';
16
+
17
+ export const DOCS_ENV_GUARD_EDITS: readonly SnippetEdit[] = [
18
+ { from: RUNTIME, to: `${RUNTIME}\n${ENVIRONMENT_ROW}`, optional: true },
19
+ ];
20
+
21
+ export const codemod: Codemod = {
22
+ id: 'docs-env-guard',
23
+ since: '31.40.0',
24
+ summary: "CLAUDE.md's table names the undeclared-env guard on an Env row",
25
+ async run(app) {
26
+ if (((await app.read(CLAUDE)) ?? '').includes('`undeclared-env`')) {
27
+ return { changed: [], skipped: [] };
28
+ }
29
+ return editSnippets(app, CLAUDE, DOCS_ENV_GUARD_EDITS);
30
+ },
31
+ };
@@ -8,9 +8,11 @@ import { codemod as biomeNoDefaultExport } from './biome-no-default-export';
8
8
  import { codemod as bunfigIslandCoverage } from './bunfig-island-coverage';
9
9
  import { codemod as chartDashboard } from './chart-dashboard';
10
10
  import { codemod as ciE2eBrowser } from './ci-e2e-browser';
11
+ import { codemod as ciServicesEnv } from './ci-services-env';
11
12
  import type { Codemod } from './codemod';
12
13
  import { codemod as defineErrorLeaf } from './define-error-leaf';
13
14
  import { codemod as docsCiParts } from './docs-ci-parts';
15
+ import { codemod as docsEnvGuard } from './docs-env-guard';
14
16
  import { codemod as docsGateProse } from './docs-gate-prose';
15
17
  import { codemod as docsIslandRows } from './docs-island-rows';
16
18
  import { codemod as docsShippedGuards } from './docs-shipped-guards';
@@ -57,4 +59,6 @@ export const CODEMODS: readonly Codemod[] = [
57
59
  verifyFloorSteps,
58
60
  helmAlertsDeploy,
59
61
  migrateJobOrdered,
62
+ ciServicesEnv,
63
+ docsEnvGuard,
60
64
  ];
package/src/dev-boot.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  import { devShellStyle } from '@ultimat3/admin/dev';
7
7
  import type { Role } from '@ultimat3/core';
8
8
  import { subscribe, subscribeSemconvMetrics, systemClock } from '@ultimat3/core';
9
+ import { installBuildId } from '@ultimat3/core/adapter';
9
10
  import type { OverlayNotice, RequestContext } from '@ultimat3/http';
10
11
  import { asCtx, subscribeRequestTimings } from '@ultimat3/http';
11
12
  import { loadSignInPath } from './app-auth';
@@ -240,6 +241,8 @@ async function bootDev(
240
241
  const rawStamp = options.env['BUILD_ID'];
241
242
  const stamped = rawStamp !== undefined && rawStamp !== '' ? rawStamp : undefined;
242
243
  const buildId = stamped ?? state.manifest.buildId;
244
+ // The pinned id is core's too, so `ctx.buildId` and `/healthz` name what the header names.
245
+ acquired.push(installBuildId(buildId));
243
246
 
244
247
  let server: DevServer;
245
248
  // Read at request time, never captured at boot: `/_x/services` must report the reload counter
@@ -0,0 +1,17 @@
1
+ // What `x dev`'s rebuild does to the ISR store on a save: every stored page goes, so the next
2
+ // request renders with the new module.
3
+
4
+ import { markAllInvalidated } from '@ultimat3/cache';
5
+ import type { IsrStore } from '@ultimat3/render/server';
6
+
7
+ /**
8
+ * Empty the store a save made stale — after voiding every fill in flight. A render that began with
9
+ * the OLD module before the save samples its fence first; deleted paths alone left that fence
10
+ * valid, so the pre-save HTML landed after the clear as a fresh page (audit round 2). Never
11
+ * `flushProcessTiers`: that also purges a CDN tier, the real CDN when its keys are in `.env`.
12
+ */
13
+ export async function clearIsrForRebuild(store: IsrStore): Promise<void> {
14
+ markAllInvalidated();
15
+ // Awaited one by one: a shared store answers over the network, and a dev save is rare.
16
+ for (const path of await store.paths()) await store.delete(path);
17
+ }
@@ -12,6 +12,7 @@ import type { AppManifest } from './app-manifest';
12
12
  import { appManifest } from './app-manifest';
13
13
  import type { StalePin } from './app-reload-graph';
14
14
  import { takeStalePins } from './app-reload-graph';
15
+ import { clearIsrForRebuild } from './dev-rebuild-isr';
15
16
  import { remountFinding, remountLine, remountReason } from './dev-rebuild-remount';
16
17
  import { schemaAheadFindings } from './dev-rebuild-schema';
17
18
  import type { ReloadTrigger } from './dev-reload';
@@ -122,6 +123,7 @@ export function devRebuilder(
122
123
  state: DevState,
123
124
  isr: IsrController,
124
125
  refreshDevices: () => Promise<readonly string[]>,
126
+ build: GenerationBuilders = BUILDERS,
125
127
  ): ReloadTrigger {
126
128
  // What the route table was built from: the boot's generation, for the life of this process. Each
127
129
  // save is compared with IT, not with the save before — a route added two saves ago is still a 404.
@@ -131,25 +133,29 @@ export function devRebuilder(
131
133
  // (the watcher's second event for one write, a no-op save) is still a restart: it reported
132
134
  // "reloaded" over the old read, and an unsupervised `/_x` lost its X_DEV_RESTART_REQUIRED.
133
135
  let held: readonly StalePin[] = [];
136
+ /** This rebuild's pins, taken and added to `held`; a pin already held is not added twice. */
137
+ const takeHeld = (): readonly StalePin[] => {
138
+ const reached = takeStalePins();
139
+ held = [...held, ...reached.filter((pin) => !held.some((was) => was.pinned === pin.pinned))];
140
+ return reached;
141
+ };
134
142
  // One rebuild at a time, and the last save wins: a tick arriving mid-build coalesces into ONE
135
143
  // trailing rebuild instead of racing the one in flight for `state.manifest` and `state.islands`.
136
144
  return coalesceReloads(
137
145
  async (file) => {
138
146
  const started = performance.now();
139
147
  beginDeviceSocketGeneration();
140
- const { manifest, findings, islands } = await buildGeneration(options.root);
148
+ const { manifest, findings, islands } = await buildGeneration(options.root, build);
141
149
  const remount = remountReason(mounted, { manifest, findings });
142
150
  state.manifest = manifest;
143
151
  state.appFindings = findings;
144
152
  state.islands = islands;
145
153
  const unserved = await refreshDevices();
146
- // Awaited one by one: a shared store answers over the network, and a dev save is rare.
147
- for (const path of await isr.store().paths()) await isr.store().delete(path);
154
+ await clearIsrForRebuild(isr.store());
148
155
  state.reloads += 1;
149
156
  // Read on EVERY rebuild, so a pin one save reached is never reported against the next save:
150
157
  // this save's own pins name it, and only a save that reached none inherits the held ones.
151
- const reached = takeStalePins();
152
- held = [...held, ...reached.filter((pin) => !held.some((was) => was.pinned === pin.pinned))];
158
+ const reached = takeHeld();
153
159
  const stale = reached.length > 0 ? reached : held;
154
160
  // A generation this process cannot mount is a restart named after the saved file — never
155
161
  // "reloaded" over a route table built for the generation before it.
@@ -177,6 +183,9 @@ export function devRebuilder(
177
183
  // Same rule as a module that will not import: a save the manifest cannot be rebuilt from is
178
184
  // a finding on `/_x`, never an unhandled rejection that takes the dev server down.
179
185
  (error: unknown, file: string) => {
186
+ // Its pins are taken all the same — the rescan ran before the throw, and the process holds
187
+ // what it pinned. Left in the graph they were read as the NEXT save's own (audit round 2).
188
+ takeHeld();
180
189
  state.reloadFinding = { ...findingFrom(error), at: file };
181
190
  },
182
191
  );
@@ -152,9 +152,12 @@ export async function checkErrorFixReport(root: string): Promise<ErrorFixReport>
152
152
  // At its point of use, like the catalog: `app-load.ts` imports this module for
153
153
  // `collectDeclaredCodes`, and a gate-only rule must not ride into every serving role's graph
154
154
  // (`serve-graph.test.ts`'s `SERVING_ROLE_CEILING`).
155
- const { FIX_SEQUENCE_BASELINE, fixSequenceProblem, generatorForceProblem } = await import(
156
- './fix-sequence'
157
- );
155
+ const {
156
+ FIX_SEQUENCE_BASELINE,
157
+ fixSequenceProblem,
158
+ generatorForceProblem,
159
+ interpolatedForceProblem,
160
+ } = await import('./fix-sequence');
158
161
  const imports = createHelperResolver(root);
159
162
  let checked = 0;
160
163
  let unreadable = 0;
@@ -172,8 +175,12 @@ export async function checkErrorFixReport(root: string): Promise<ErrorFixReport>
172
175
  // The interpolation-blanked form for both rules: `x ${name}` names no command this can
173
176
  // resolve, and reading `<value>` as one would be a finding nobody can act on.
174
177
  const fix = staticFix(site.fix);
178
+ // The --force rule twice: on the blanked text, and inside the interpolations it blanks.
175
179
  const problem =
176
- fixProblem(site.fix) ?? generatorForceProblem(fix) ?? citedCommandProblem(fix, catalog);
180
+ fixProblem(site.fix) ??
181
+ generatorForceProblem(fix) ??
182
+ interpolatedForceProblem(site.fix) ??
183
+ citedCommandProblem(fix, catalog);
177
184
  if (problem !== undefined) {
178
185
  findings.push(fixFinding(site, problem));
179
186
  continue;