@ultimat3/cli 31.47.0 → 31.48.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 (62) hide show
  1. package/package.json +29 -29
  2. package/src/cmd-drill.ts +20 -1
  3. package/src/cmd-heavy-spec.ts +28 -0
  4. package/src/cmd-heavy.ts +160 -0
  5. package/src/cmd-test.ts +13 -3
  6. package/src/cmd-upgrade.ts +22 -11
  7. package/src/codemods/docs-many-agents.ts +30 -0
  8. package/src/codemods/e2e-suite-floor.ts +42 -0
  9. package/src/codemods/e2e-suite.ts +71 -0
  10. package/src/codemods/index.ts +4 -0
  11. package/src/codemods/pending.ts +2 -2
  12. package/src/codemods/test-ports.ts +40 -33
  13. package/src/codemods/test-suites.ts +11 -22
  14. package/src/codemods/verify-floor-skips.ts +18 -6
  15. package/src/doctor-advisory-floors.ts +30 -8
  16. package/src/error-codes-tooling.ts +9 -3
  17. package/src/exec.ts +11 -3
  18. package/src/heavy-cores.ts +51 -0
  19. package/src/heavy-env.ts +19 -0
  20. package/src/heavy-errors.ts +36 -0
  21. package/src/heavy-flock.ts +73 -0
  22. package/src/heavy-ledger.ts +358 -0
  23. package/src/heavy-memory.ts +67 -0
  24. package/src/heavy-weights.ts +47 -0
  25. package/src/heavy.ts +290 -0
  26. package/src/local-cli.ts +6 -5
  27. package/src/mcp-errors.ts +4 -1
  28. package/src/messages.ts +11 -0
  29. package/src/registry.ts +2 -0
  30. package/src/role-replicator.ts +5 -3
  31. package/src/runtime-cache.ts +24 -3
  32. package/src/runtime-overrides.ts +4 -2
  33. package/src/templates/guard-released-forms.ts +35 -13
  34. package/src/templates/scaffold-claude-agents.ts +9 -6
  35. package/src/templates/scaffold-claude-commands.ts +1 -1
  36. package/src/templates/scaffold-docs.ts +5 -4
  37. package/src/templates/scaffold-suites.ts +22 -0
  38. package/src/test-batches.ts +9 -3
  39. package/src/test-shards.ts +3 -3
  40. package/src/test-slots.ts +35 -161
  41. package/src/upgrade-gate-codemods.ts +1 -18
  42. package/src/verify-checks.ts +4 -3
  43. package/src/verify-coverage-run.ts +5 -4
  44. package/src/verify-deadline.ts +18 -2
  45. package/src/verify-heavy-steps.ts +26 -0
  46. package/src/verify-test-run.ts +3 -2
  47. package/src/verify-tests.ts +27 -20
  48. package/wiki/Building-Your-Own-Base.md +15 -2
  49. package/wiki/CI-Parallel-Gate.md +2 -3
  50. package/wiki/CLI-Reference.md +25 -13
  51. package/wiki/Caching-And-Invalidation.md +1 -1
  52. package/wiki/Compared.md +13 -11
  53. package/wiki/Configuration.md +22 -4
  54. package/wiki/Home.md +1 -0
  55. package/wiki/Interface-Rules.md +1 -1
  56. package/wiki/Known-Gaps.md +1 -1
  57. package/wiki/Mail.md +1 -1
  58. package/wiki/Many-Agents.md +60 -0
  59. package/wiki/Stability.md +1 -1
  60. package/wiki/Testing.md +5 -5
  61. package/wiki/Tutorial-01-First-App.md +2 -2
  62. package/wiki/Upgrading.md +2 -1
package/src/heavy.ts ADDED
@@ -0,0 +1,290 @@
1
+ // Admission to the machine, as the rest of the CLI sees it: whether the ledger applies to this
2
+ // process, and the three ways in. Never a reason for work to fail: a ledger that cannot run is said
3
+ // once on stderr and the command goes ahead.
4
+
5
+ // why: Bun ships no lstat with ownership, and the fixed path below needs one.
6
+ import { lstatSync, mkdirSync, realpathSync } from 'node:fs';
7
+ // why: Bun ships no path-join primitive.
8
+ import { join } from 'node:path';
9
+ import { isUltimateError } from '@ultimat3/core';
10
+ import { coreCap, nativeToolEnv } from './heavy-cores';
11
+ import type { HeavyEnv } from './heavy-env';
12
+ import { HEAVY_DIR_ENV, HEAVY_HOLD_ENV, isCi } from './heavy-env';
13
+ import { HeavyLedgerUnavailableError } from './heavy-errors';
14
+ import type { TryLock } from './heavy-flock';
15
+ import { flockBinding } from './heavy-flock';
16
+ import type { Held, LedgerEntry, LedgerWait, Reservation } from './heavy-ledger';
17
+ import { isHeld, lockPath, prepareLedger, reserve } from './heavy-ledger';
18
+ import { ledgerCapacityMb } from './heavy-memory';
19
+ import { msg } from './messages';
20
+ import { writeErrorLine } from './write-line';
21
+
22
+ export type HeavyOff = 'ci' | 'test-run' | 'disabled' | 'nested' | 'unsupported';
23
+
24
+ export type HeavyState =
25
+ | {
26
+ readonly on: true;
27
+ readonly dir: string;
28
+ readonly capacityMb: number;
29
+ readonly tryLock: TryLock;
30
+ }
31
+ | { readonly on: false; readonly off: HeavyOff; readonly detail?: string };
32
+
33
+ /** One per machine and uid. A FIXED path: `TMPDIR` differs per session, and two ledgers are no bound. */
34
+ export const defaultLedgerDir = (uid: number | undefined = process.getuid?.()): string =>
35
+ `/tmp/ultimate-heavy-${String(uid ?? 0)}`;
36
+
37
+ /** `/tmp` is world-writable: refuse a directory someone else planted at our fixed path. */
38
+ function requireOwnDir(dir: string): void {
39
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
40
+ const stat = lstatSync(dir);
41
+ if (!stat.isDirectory() || (process.getuid !== undefined && stat.uid !== process.getuid())) {
42
+ throw new HeavyLedgerUnavailableError(`${dir} is not a directory this user owns`);
43
+ }
44
+ prepareLedger(dir);
45
+ }
46
+
47
+ const said = new Set<string>();
48
+ const warnOnce = (line: string): void => {
49
+ if (said.has(line)) return;
50
+ said.add(line);
51
+ writeErrorLine(line);
52
+ };
53
+
54
+ const describe = (error: unknown): string =>
55
+ isUltimateError(error)
56
+ ? `${error.code}: ${error.cause}\n fix: ${error.fix}`
57
+ : new HeavyLedgerUnavailableError(error instanceof Error ? error.message : 'unknown').message;
58
+
59
+ /** Whether admission applies here. Throws only coded errors; `admission` turns them into a line. */
60
+ export async function heavyState(env: HeavyEnv): Promise<HeavyState> {
61
+ if (isCi(env)) return { on: false, off: 'ci' };
62
+ const explicitDir = env[HEAVY_DIR_ENV];
63
+ // A fixture's `x test` runs inside `bun test`, whose NODE_ENV every child inherits: queueing it
64
+ // behind real work would turn a test's timeout into a machine-load verdict.
65
+ if (env['NODE_ENV'] === 'test' && explicitDir === undefined)
66
+ return { on: false, off: 'test-run' };
67
+ const capacityMb = ledgerCapacityMb(env);
68
+ if (capacityMb === 0) return { on: false, off: 'disabled' };
69
+ const binding = await flockBinding();
70
+ if (!binding.ok) return { on: false, off: 'unsupported', detail: binding.reason };
71
+ const hold = env[HEAVY_HOLD_ENV];
72
+ if (hold !== undefined && hold !== '' && isHeld(hold, binding.tryLock)) {
73
+ return { on: false, off: 'nested' };
74
+ }
75
+ const dir = explicitDir ?? defaultLedgerDir();
76
+ requireOwnDir(dir);
77
+ return { on: true, dir, capacityMb, tryLock: binding.tryLock };
78
+ }
79
+
80
+ async function admission(env: HeavyEnv): Promise<HeavyState> {
81
+ try {
82
+ return await heavyState(env);
83
+ } catch (error) {
84
+ warnOnce(describe(error));
85
+ return { on: false, off: 'unsupported', detail: 'see the line above' };
86
+ }
87
+ }
88
+
89
+ const PATH_SHOWN = 48;
90
+ const printable = (text: string): string => text.replace(/\p{Cc}/gu, ' ').slice(0, 120);
91
+
92
+ export const ageOf = (ms: number): string => {
93
+ const seconds = Math.max(0, Math.round(ms / 1000));
94
+ return seconds < 60
95
+ ? `${String(seconds)}s`
96
+ : `${String(Math.floor(seconds / 60))}m${String(seconds % 60).padStart(2, '0')}s`;
97
+ };
98
+
99
+ /** A directory's END names the checkout; a long path keeps that and loses its start. */
100
+ const shortPath = (path: string): string =>
101
+ path.length <= PATH_SHOWN ? printable(path) : `…${printable(path.slice(-PATH_SHOWN))}`;
102
+
103
+ export const describeEntry = (entry: LedgerEntry, now: number): string =>
104
+ `${printable(entry.label)} (${shortPath(entry.cwd)}, ${String(entry.mb)} MB, ${ageOf(now - entry.at)})`;
105
+
106
+ /** The waiter's one line. Stderr always: stdout may be a `--json` document. */
107
+ export const waitLine = (label: string, wait: LedgerWait, now: number = Date.now()): string =>
108
+ msg('cli.heavy.waiting', {
109
+ label: printable(label),
110
+ need: wait.needMb,
111
+ position: wait.position,
112
+ queued: wait.queued,
113
+ used: wait.usedMb,
114
+ capacity: wait.capacityMb,
115
+ holders: wait.holds.map((entry) => describeEntry(entry, now)).join('; ') || '-',
116
+ });
117
+
118
+ // Time this process has spent queued, so a gate step's deadline can stop counting it.
119
+ let finishedWaitMs = 0;
120
+ const waitStarts = new Set<number>();
121
+
122
+ /** Monotonic milliseconds spent waiting for admission, ongoing waits included. */
123
+ export const heavyWaitClock = (now: number = performance.now()): number => {
124
+ let total = finishedWaitMs;
125
+ for (const start of waitStarts) total += now - start;
126
+ return total;
127
+ };
128
+
129
+ async function timedWait<T>(wait: () => Promise<T>): Promise<T> {
130
+ const start = performance.now();
131
+ waitStarts.add(start);
132
+ try {
133
+ return await wait();
134
+ } finally {
135
+ waitStarts.delete(start);
136
+ finishedWaitMs += performance.now() - start;
137
+ }
138
+ }
139
+
140
+ export interface HeavyRequest {
141
+ readonly label: string;
142
+ readonly cwd: string;
143
+ readonly env: HeavyEnv;
144
+ readonly unitMb: number;
145
+ readonly baseMb?: number;
146
+ readonly units?: number;
147
+ readonly minUnits?: number;
148
+ }
149
+
150
+ /** A reservation, or nothing when admission does not apply or could not work. */
151
+ async function enter(request: HeavyRequest, state: HeavyState): Promise<Reservation | undefined> {
152
+ if (!state.on) return undefined;
153
+ try {
154
+ return await timedWait(() =>
155
+ reserve({
156
+ dir: state.dir,
157
+ capacityMb: state.capacityMb,
158
+ tryLock: state.tryLock,
159
+ unitMb: request.unitMb,
160
+ ...(request.baseMb === undefined ? {} : { baseMb: request.baseMb }),
161
+ units: request.units ?? 1,
162
+ minUnits: request.minUnits ?? request.units ?? 1,
163
+ label: request.label,
164
+ cwd: request.cwd,
165
+ onWait: (wait) => writeErrorLine(waitLine(request.label, wait)),
166
+ }),
167
+ );
168
+ } catch (error) {
169
+ warnOnce(describe(error));
170
+ return undefined;
171
+ }
172
+ }
173
+
174
+ /** What a holder's child is spawned with: the hold's name, and the locks it must keep alive. */
175
+ export interface HeavyChild {
176
+ readonly env: Readonly<Record<string, string>>;
177
+ readonly fds: readonly number[];
178
+ }
179
+
180
+ const childOf = (env: HeavyEnv, state: HeavyState, held: Held | undefined): HeavyChild => ({
181
+ env: {
182
+ ...toolEnv(env, state),
183
+ ...(held === undefined ? {} : { [HEAVY_HOLD_ENV]: held.path }),
184
+ },
185
+ fds: held === undefined ? [] : [held.fd],
186
+ });
187
+
188
+ /** What a native tool's child is spawned with: the thread cap, unless this run has no ceiling. */
189
+ function toolEnv(env: HeavyEnv, state: HeavyState): Record<string, string> {
190
+ const capped = state.on || state.off === 'nested' || state.off === 'unsupported';
191
+ return capped ? nativeToolEnv(env, coreCap(env)) : {};
192
+ }
193
+
194
+ /** Runner options carrying `child`; untouched when it adds nothing, as under CI and in a test. */
195
+ export function withChild<T extends { readonly cwd: string }>(
196
+ options: T,
197
+ child: HeavyChild,
198
+ ):
199
+ | T
200
+ | (T & {
201
+ readonly env: Readonly<Record<string, string>>;
202
+ readonly inheritFds: readonly number[];
203
+ }) {
204
+ return Object.keys(child.env).length === 0 && child.fds.length === 0
205
+ ? options
206
+ : { ...options, env: child.env, inheritFds: child.fds };
207
+ }
208
+
209
+ /** Run `work` inside one reservation; everything it spawns gets `child`. */
210
+ export async function withHeavy<T>(
211
+ request: HeavyRequest,
212
+ work: (child: HeavyChild) => Promise<T>,
213
+ ): Promise<T> {
214
+ const state = await admission(request.env);
215
+ const held = await enter(request, state);
216
+ try {
217
+ return await work(childOf(request.env, state, held));
218
+ } finally {
219
+ held?.release();
220
+ }
221
+ }
222
+
223
+ /** `name` for one checkout, whichever path reached it, in the ledger's directory. */
224
+ const checkoutLockPath = (dir: string, name: string, root: string): string =>
225
+ join(dir, 'locks', `${name}-${Bun.hash(realpathSync(root)).toString(36)}.lock`);
226
+
227
+ /**
228
+ * One `name` at a time in this checkout (two `tsc -b` race one `dist/`). Taken AFTER the ledger, by
229
+ * every caller: a process holding this lock must never queue for memory, or a nested run holding
230
+ * memory and waiting for the lock would close a cycle.
231
+ */
232
+ export async function withCheckoutLock<T>(
233
+ input: { readonly name: string; readonly root: string; readonly env: HeavyEnv },
234
+ child: HeavyChild,
235
+ work: (child: HeavyChild) => Promise<T>,
236
+ ): Promise<T> {
237
+ // Nested runs still exclude each other here, so the state's `nested` is not an exemption.
238
+ const state = await admission({ ...input.env, [HEAVY_HOLD_ENV]: undefined });
239
+ if (!state.on) return work(child);
240
+ let held: Held | undefined;
241
+ try {
242
+ const path = checkoutLockPath(state.dir, input.name, input.root);
243
+ held = await timedWait(() =>
244
+ lockPath(path, `${input.name} in ${input.root}`, state.tryLock, (holder) =>
245
+ writeErrorLine(msg('cli.heavy.lockWait', { name: input.name, holder: printable(holder) })),
246
+ ),
247
+ );
248
+ } catch (error) {
249
+ warnOnce(describe(error));
250
+ }
251
+ try {
252
+ // The compiler keeps the lock too: a killed wrapper must not let a second one start beside it.
253
+ return await work(held === undefined ? child : { ...child, fds: [...child.fds, held.fd] });
254
+ } finally {
255
+ held?.release();
256
+ }
257
+ }
258
+
259
+ export interface WorkerLease {
260
+ readonly count: number;
261
+ readonly env?: Readonly<Record<string, string>>;
262
+ /** Locked descriptors each worker process must inherit. */
263
+ readonly fds?: readonly number[];
264
+ release(): void;
265
+ }
266
+
267
+ /**
268
+ * Up to `want` test workers, as many as the core cap and the ledger allow right now, at least one.
269
+ * `exact` is an explicit `--workers`: the caller's width, and it waits for all of it.
270
+ */
271
+ export async function leaseWorkers(
272
+ want: number,
273
+ request: Omit<HeavyRequest, 'units' | 'minUnits'> & { readonly exact?: boolean },
274
+ ): Promise<WorkerLease> {
275
+ const state = await admission(request.env);
276
+ const unbounded = !state.on && state.off !== 'nested' && state.off !== 'unsupported';
277
+ const cap = request.exact === true || unbounded ? undefined : coreCap(request.env);
278
+ const units = Math.max(1, cap === undefined ? want : Math.min(want, cap));
279
+ const held = await enter(
280
+ { ...request, units, minUnits: request.exact === true ? units : 1 },
281
+ state,
282
+ );
283
+ const child = childOf(request.env, state, held);
284
+ return {
285
+ count: held?.units ?? units,
286
+ env: child.env,
287
+ fds: child.fds,
288
+ release: () => held?.release(),
289
+ };
290
+ }
package/src/local-cli.ts CHANGED
@@ -45,12 +45,13 @@ const nodeIo: LocalCliIo = {
45
45
  };
46
46
 
47
47
  /**
48
- * The one command the app's own CLI must not answer when it is the older of the two: an app with no
48
+ * The commands the app's own CLI must not answer when it is the older of the two. An app with no
49
49
  * `x upgrade` yet is told `bunx @ultimat3/cli@latest upgrade`, and handing that to the app's CLI
50
- * answers `X_NOT_IMPLEMENTED` from the very version it exists to move off. It is safe because of what
51
- * it does not do: it loads no app, so there is no second registry — the gate is the installed CLI's.
50
+ * answers `X_NOT_IMPLEMENTED` from the very version it exists to move off; `x heavy` is run from any
51
+ * directory on the machine, an app pinned before it included. Safe because of what they do not do:
52
+ * neither loads an app, so there is no second registry.
52
53
  */
53
- const OUTLIVES_THE_APP_CLI = 'upgrade';
54
+ const OUTLIVES_THE_APP_CLI: readonly (string | undefined)[] = ['upgrade', 'heavy'];
54
55
 
55
56
  const versionOfBin = (bin: string, io: LocalCliIo): string | undefined => {
56
57
  const parsed: unknown = JSON.parse(io.read(join(dirname(dirname(bin)), 'package.json')));
@@ -93,7 +94,7 @@ export function resolveLocalCli(
93
94
  if (!io.exists(local)) return undefined;
94
95
  try {
95
96
  if (io.realpath(local) === io.realpath(input.selfPath)) return undefined;
96
- if (input.command === OUTLIVES_THE_APP_CLI && appCliIsOlder(local, input.selfPath, io)) {
97
+ if (OUTLIVES_THE_APP_CLI.includes(input.command) && appCliIsOlder(local, input.selfPath, io)) {
97
98
  return undefined;
98
99
  }
99
100
  return local;
package/src/mcp-errors.ts CHANGED
@@ -401,9 +401,12 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
401
401
  X_REPRO_BUNDLE_INVALID:
402
402
  'x repro --json # lists the failing jobs and error groups; then run it again with one id and --bundle, and attach the file it writes',
403
403
  X_ADVISORY_FLOOR_UNMET: 'bun update source-map-js immutable',
404
- X_UPGRADE_CODEMODS_PENDING: 'x upgrade --json',
404
+ X_UPGRADE_CODEMODS_PENDING: 'x upgrade codemods --from 0.0.0 --json',
405
405
  X_UPGRADE_LOCKED: 'cat .x/upgrade.lock',
406
406
  X_APP_MIGRATIONS_UNAPPLIED: 'x db migrate --json',
407
+ X_HEAVY_LEDGER_UNAVAILABLE: 'x heavy status --json',
408
+ X_HEAVY_MEMORY_INVALID: 'export ULTIMATE_HEAVY_MEMORY=8g',
409
+ X_HEAVY_COMMAND_NOT_FOUND: 'x heavy run --json -- bun test',
407
410
  };
408
411
 
409
412
  const isCliCode = (code: string): code is CliErrorCode =>
package/src/messages.ts CHANGED
@@ -317,6 +317,17 @@ const CATALOG = {
317
317
  ...OPS_MESSAGES,
318
318
  ...FLOOR_MESSAGES,
319
319
  ...STATUS_MESSAGES,
320
+ 'cli.heavy.waiting':
321
+ 'heavy: {label} waits for {need} MB, position {position} of {queued}; {used} of {capacity} MB held by {holders}',
322
+ 'cli.heavy.lockWait': 'heavy: waiting for this checkout’s {name} lock, held by {holder}',
323
+ 'cli.heavy.status.summary':
324
+ '{used} of {capacity} MB reserved, {holds} running, {queued} queued; {cores} core(s) per run',
325
+ 'cli.heavy.status.off': 'admission is off here ({reason}); {cores} core(s) per run',
326
+ 'cli.heavy.status.machine':
327
+ 'machine: load {load} on {cpus} cores, {runnable} runnable, {free} GB of {total} GB available',
328
+ 'cli.heavy.status.hold': 'running: {entry}',
329
+ 'cli.heavy.status.queued': 'queued {position}: {entry}',
330
+ 'cli.heavy.run.done': '{command} exited {code} after {ran}, {waited} in the queue',
320
331
  } as const;
321
332
 
322
333
  export type MessageKey = keyof typeof CATALOG;
package/src/registry.ts CHANGED
@@ -27,6 +27,7 @@ import { explainSpec } from './cmd-explain-spec';
27
27
  import { fixSpec } from './cmd-fix-spec';
28
28
  import { generateSpec } from './cmd-generate-spec';
29
29
  import { graphSpec } from './cmd-graph-spec';
30
+ import { heavySpec } from './cmd-heavy-spec';
30
31
  import { profileSpec } from './cmd-profile-spec';
31
32
  // Registered here, not by whichever command body happens to load: `dispatch` renders a CLI code's
32
33
  // title for a refusal raised before any body is imported.
@@ -138,6 +139,7 @@ export const LAZY_COMMANDS: readonly LazyCommand[] = [
138
139
  lazy(explainSpec, async () => (await import('./cmd-explain')).explainCommand),
139
140
  lazy(profileSpec, async () => (await import('./cmd-profile')).profileCommand),
140
141
  lazy(statusSpec, async () => (await import('./cmd-status')).statusCommand),
142
+ lazy(heavySpec, async () => (await import('./cmd-heavy')).heavyCommand),
141
143
  ];
142
144
 
143
145
  export const COMMANDS: readonly CliCommand[] = [
@@ -69,7 +69,8 @@ const embeddedRefusal = (dev: boolean): BadFlagError | ConfigInvalidError =>
69
69
  });
70
70
 
71
71
  /**
72
- * The relations the feed decodes: every registered entity's PHYSICAL TABLE, never its name.
72
+ * The relations the feed decodes: every registered entity's PHYSICAL TABLE, never its name, and
73
+ * never a view's — a view writes no WAL of its own, and Postgres refuses one in a publication.
73
74
  *
74
75
  * Both readers of this list are catalog readers. `PgReplicationStream` keeps a change only when
75
76
  * `#entities.has(relation.name)`, and a pgoutput Relation message names the table; `warnPartialIdentity`
@@ -83,7 +84,8 @@ const embeddedRefusal = (dev: boolean): BadFlagError | ConfigInvalidError =>
83
84
  * feed the same list whatever order it was registered in.
84
85
  */
85
86
  export function replicatedRelations(): readonly string[] {
86
- return [...new Set(describeEntities().map((entity) => entity.table))].sort();
87
+ const tables = describeEntities().filter((entity) => entity.view === undefined);
88
+ return [...new Set(tables.map((entity) => entity.table))].sort();
87
89
  }
88
90
 
89
91
  /**
@@ -92,7 +94,7 @@ export function replicatedRelations(): readonly string[] {
92
94
  * list came from the app's own registry, so it can name the command that adds to it.
93
95
  */
94
96
  const NO_ENTITIES =
95
- 'no entities are registered, so the replicator would decode changes nothing matches';
97
+ 'no entity on a table is registered, so the replicator would decode changes nothing matches';
96
98
 
97
99
  const noEntitiesRefusal = (dev: boolean): BadFlagError | ConfigInvalidError =>
98
100
  dev
@@ -26,6 +26,7 @@ import {
26
26
  registerInvalidationBroadcast,
27
27
  registerTier,
28
28
  resetTiers,
29
+ usesDefaultRedisClient,
29
30
  } from '@ultimat3/cache';
30
31
  import type { AppConfig, CacheTierName } from '@ultimat3/core';
31
32
  import {
@@ -74,9 +75,12 @@ export interface CacheTiersOptions {
74
75
  */
75
76
  readonly tiers: readonly CacheTierName[];
76
77
  /**
77
- * `runtime.ts`'s `cacheTiers`: each replaces the rung of its own `name` — built from nothing
78
- * here, so a supplied `redis` tier needs no `REDIS_URL`. A supplied tier `tiers` does not name is
79
- * logged (`cache.tier.unnamed`) and never registered: the declaration decides the ladder.
78
+ * `runtime.ts`'s `cacheTiers`: each replaces the rung of its own `name`, and it is the ONE way
79
+ * to set a rung's limits (`lruTier({ maxBytes })`, `redisTier({ maxValueBytes, jitterFraction })`):
80
+ * `buildTier` passes none, and a config key would be a second spelling of this replacement. A
81
+ * supplied `redis` tier holding its own `client` needs no `REDIS_URL`; one without is
82
+ * `warnDefaultRedis`'s. A supplied tier `tiers` does not name is logged (`cache.tier.unnamed`) and
83
+ * never registered: the declaration decides the ladder.
80
84
  */
81
85
  readonly supplied?: readonly CacheTier[] | undefined;
82
86
  /** The wait before re-subscribing after `attempt` failures (1-based). Injected by a test. */
@@ -208,6 +212,22 @@ function warnUnnamed(options: CacheTiersOptions): void {
208
212
  }
209
213
  }
210
214
 
215
+ /**
216
+ * A `redisTier({ maxValueBytes })` with no `client`, and no URL in the boot's env. `buildTier` refuses
217
+ * that state, but only for the rung it builds: this one is the app's, and its default client dials
218
+ * the local server, which may be what a single-box deployment means. So it boots, and says so —
219
+ * tuning a limit must not quietly cost the operator the signal that the URL is missing.
220
+ */
221
+ function warnDefaultRedis(built: readonly CacheTier[], env: Env): void {
222
+ const onDefault = built.some((tier) => usesDefaultRedisClient(tier));
223
+ if (!onDefault || redisUrlSource(env) !== undefined) return;
224
+ logger.warn('cache.tier.default-redis', {
225
+ tier: 'redis',
226
+ source: 'runtime.ts',
227
+ expected: 'REDIS_URL or VALKEY_URL',
228
+ });
229
+ }
230
+
211
231
  /**
212
232
  * Register the tiers the app declared, wire both halves of cross-instance invalidation, and return
213
233
  * the release.
@@ -238,6 +258,7 @@ export function startCacheTiers(options: CacheTiersOptions): () => Promise<void>
238
258
  const built = options.tiers.map((name) => supplied.get(name) ?? buildTier(name, options));
239
259
  for (const tier of built) registerTier(tier);
240
260
  warnUnnamed(options);
261
+ warnDefaultRedis(built, options.env);
241
262
  // NATS (or a supplied transport) when it crosses processes; Redis pub/sub when the transport is
242
263
  // the in-process bus and REDIS_URL is set; else in-process. One rule, one boot line.
243
264
  const selected = selectCacheBus({
@@ -54,8 +54,10 @@ export interface PortValues {
54
54
  readonly authServerStore: AuthServerStore;
55
55
  /**
56
56
  * Rung implementations. `cache.tiers` still NAMES the ladder: a tier here replaces the rung of
57
- * its own `name` (a `redis` tier needs no `REDIS_URL`), the boot builds every other named rung,
58
- * and a tier whose name `cache.tiers` does not list is logged (`cache.tier.unnamed`) and unused.
57
+ * its own `name` (a `redisTier` given its own `client` needs no `REDIS_URL`; one without dials
58
+ * core's default and, with no URL set, logs `cache.tier.default-redis`), the boot builds every
59
+ * other named rung, and a tier `cache.tiers` does not list is logged (`cache.tier.unnamed`) and
60
+ * unused.
59
61
  */
60
62
  readonly cacheTiers: readonly CacheTier[];
61
63
  /** The process's clock: every "now" and every wait not handed one. Default `systemClock`. */
@@ -5,23 +5,36 @@
5
5
  export const RELEASED_GUARD_FORMS: Readonly<
6
6
  Record<string, readonly (readonly [string, 'error' | 'warning'])[]>
7
7
  > = {
8
- 'animated-layout-property': [['2hqr04589t23q', 'error']],
8
+ 'animated-layout-property': [
9
+ ['2hqr04589t23q', 'error'],
10
+ ['2z9j3sd8e7lgl', 'error'],
11
+ ],
9
12
  'bare-error': [
10
13
  ['1m3eimglwzrdq', 'error'],
11
14
  ['1njzso3r6drnd', 'error'],
15
+ ['1ot9kwydyzd0j', 'error'],
16
+ ['2aaavkemg4qee', 'error'],
17
+ ['2s43pcjqyhmfi', 'error'],
12
18
  ],
13
19
  'error-declared': [
14
20
  ['1rlzex7nalpiw', 'error'],
15
21
  ['2tfw2hq80msju', 'error'],
16
22
  ['3kqd7d8pzpcnn', 'error'],
17
23
  ],
18
- 'focus-visible': [['4c2nf0mpzn0z', 'error']],
24
+ 'focus-visible': [
25
+ ['3i4t0gznxyytf', 'error'],
26
+ ['4c2nf0mpzn0z', 'error'],
27
+ ],
19
28
  'image-dimensions': [
20
29
  ['1cfzth883qzt5', 'error'],
30
+ ['1upoweaclyd8', 'error'],
21
31
  ['33uv2ua4a9zcf', 'error'],
22
32
  ],
23
33
  'island-mount-clears': [['1v09h5ptzqvs2', 'error']],
24
- 'island-without-states': [['2os1f5fb6aass', 'error']],
34
+ 'island-without-states': [
35
+ ['2os1f5fb6aass', 'error'],
36
+ ['31gjhz3nyf0gz', 'error'],
37
+ ],
25
38
  'native-confirm': [
26
39
  ['1f7eh34hj085a', 'error'],
27
40
  ['2b134wpkoaqso', 'error'],
@@ -29,8 +42,10 @@ export const RELEASED_GUARD_FORMS: Readonly<
29
42
  ],
30
43
  'raw-breakpoint': [['wdo3lsqmvsya', 'error']],
31
44
  'raw-colour': [
45
+ ['17jw6r17ah3dq', 'error'],
32
46
  ['1e2pkqnmrjt44', 'error'],
33
47
  ['3onnbx54g9zmd', 'error'],
48
+ ['mdo7f20dnyof', 'error'],
34
49
  ],
35
50
  'raw-fetch': [
36
51
  ['17xdeprvzx5v2', 'error'],
@@ -54,6 +69,7 @@ export const RELEASED_GUARD_FORMS: Readonly<
54
69
  'repo-raw-sql': [
55
70
  ['12qj02j416sib', 'error'],
56
71
  ['2kr7gbv7j2m0v', 'error'],
72
+ ['2m5sh5923zcdx', 'error'],
57
73
  ['3nmlelym16o78', 'error'],
58
74
  ],
59
75
  'repo-unbounded': [
@@ -63,6 +79,7 @@ export const RELEASED_GUARD_FORMS: Readonly<
63
79
  'runtime-pin': [['28ffbpwy4q2ji', 'error']],
64
80
  'semantic-interactive': [
65
81
  ['29pfa4ea628cv', 'error'],
82
+ ['2m280ivq01zs2', 'error'],
66
83
  ['d4ncwu39wtrk', 'error'],
67
84
  ],
68
85
  'unbounded-fanout': [['xk4dv9vsq8gg', 'error']],
@@ -71,23 +88,28 @@ export const RELEASED_GUARD_FORMS: Readonly<
71
88
  ['3b0u9i8hze00x', 'error'],
72
89
  ],
73
90
  'undeclared-env': [
74
- ['13k4amuxgsnla', 'error'],
75
- ['1xkusngzbabza', 'error'],
76
- ['2jbihvbp83mb4', 'error'],
77
- ['3gsy96z8bgrrl', 'error'],
78
- ['81vvl6xx5bb8', 'error'],
91
+ ['16pof11n1trhg', 'error'],
92
+ ['1f8kizielequo', 'error'],
93
+ ['2jb32jms80mge', 'error'],
94
+ ['2t3qtexnpfnyq', 'error'],
95
+ ['3gsoj050vbe69', 'error'],
79
96
  ],
80
97
  'undefined-style-class': [
81
98
  ['3food9t4vrzv8', 'error'],
82
99
  ['w7as1ib1ido8', 'error'],
83
100
  ],
84
101
  'untranslated-string': [
102
+ ['211cleyx8cmgn', 'error'],
103
+ ['2tmea7cmz7rvr', 'error'],
85
104
  ['2x85ib5eqdxzi', 'error'],
86
105
  ['3j5e8t1k120u3', 'error'],
87
106
  ['d6gyn0l6szj8', 'error'],
88
107
  ['h57qtdwn7inz', 'error'],
89
108
  ],
90
109
  'unzoned-date': [
110
+ ['14sc1shft1opi', 'error'],
111
+ ['38jqi2md5adsi', 'error'],
112
+ ['3caz4m0vn66dz', 'error'],
91
113
  ['8apjndc5ybvm', 'error'],
92
114
  ['haaxmgzsgjns', 'error'],
93
115
  ],
@@ -96,7 +118,7 @@ export const RELEASED_GUARD_FORMS: Readonly<
96
118
  /** Every hash each shipped guard's TEST file was released as: an unedited test goes without a note. */
97
119
  export const RELEASED_GUARD_TEST_FORMS: Readonly<Record<string, readonly string[]>> = {
98
120
  'animated-layout-property': ['191zjn08f13h4'],
99
- 'bare-error': ['1w7vwbtypxdwe'],
121
+ 'bare-error': ['17uv4zrzcuwbk', '1epwa72g9sk4u', '1w7vwbtypxdwe'],
100
122
  'error-declared': ['2hj2bs2czhxnw', 'qe8afpq7pzf1'],
101
123
  'focus-visible': ['12c0rk3ljkx6q'],
102
124
  'image-dimensions': ['3p4hkambgpb4j'],
@@ -104,7 +126,7 @@ export const RELEASED_GUARD_TEST_FORMS: Readonly<Record<string, readonly string[
104
126
  'island-without-states': ['vls0ujdd16gw'],
105
127
  'native-confirm': ['1c7vps5wn37uv', 'qwyn1mzn9ace'],
106
128
  'raw-breakpoint': ['w356i8dreh7j'],
107
- 'raw-colour': ['1tc7cambk8byr', '319l3wictp9lf'],
129
+ 'raw-colour': ['1nhoblzxa9kp1', '1tc7cambk8byr', '319l3wictp9lf'],
108
130
  'raw-fetch': ['2lips924uo00f'],
109
131
  'raw-interval': ['1z55givy4sst0'],
110
132
  'raw-length': ['1hpgz9jowk5qu'],
@@ -112,7 +134,7 @@ export const RELEASED_GUARD_TEST_FORMS: Readonly<Record<string, readonly string[
112
134
  'raw-shadow': ['3kg8ft6y3ia0y'],
113
135
  'raw-z-index': ['3fb40f6bwp8kq'],
114
136
  'repo-await-in-loop': ['2axgbb82wldt4'],
115
- 'repo-raw-sql': ['c5pfl8w3qj94', 'f19j7irkta44'],
137
+ 'repo-raw-sql': ['1wxenxatjt885', 'c5pfl8w3qj94', 'f19j7irkta44'],
116
138
  'repo-unbounded': ['98ncw525gpmo'],
117
139
  'runtime-pin': ['dy20fh65qziz'],
118
140
  'semantic-interactive': ['2uh0p6xoh996t', '393msxyy1bz36'],
@@ -120,6 +142,6 @@ export const RELEASED_GUARD_TEST_FORMS: Readonly<Record<string, readonly string[
120
142
  'undeclared-custom-property': ['30bi2v92swukf', 'svuf8sm14fm8'],
121
143
  'undeclared-env': ['38run3rew6y0c', '8xdp7gp7hol7'],
122
144
  'undefined-style-class': ['1uy88gpk5k8p8', '2sy8me3i3bmzw'],
123
- 'untranslated-string': ['30q3u45cey2eq', 'cgvfv231gnvg'],
124
- 'unzoned-date': ['1siep3fqscks4', '20x6l238r09jk'],
145
+ 'untranslated-string': ['30q3u45cey2eq', 'cgvfv231gnvg', 'kdo3fxwgix3j'],
146
+ 'unzoned-date': ['1m46q3h8t4v7v', '1siep3fqscks4', '20x6l238r09jk', '3jzdaqcytkgil'],
125
147
  };
@@ -81,8 +81,9 @@ feature slice. Nothing else. A change outside that set is a collision — report
81
81
 
82
82
  Inspect before you change: \`bunx x entities list\`, \`bunx x entities show <name>\`, both with \`--json\`.
83
83
 
84
- Checks: \`bun test <path>/entity.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and \`bun run typecheck\`
85
- once when you are otherwise done. Never \`bunx x verify\` — that belongs to whoever coordinates you.
84
+ Checks: \`bun test <path>/entity.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and
85
+ \`bunx x verify --only typecheck\` once when you are otherwise done: it queues for the machine's memory.
86
+ Never the whole \`bunx x verify\` — that belongs to whoever coordinates you.
86
87
  `;
87
88
 
88
89
  const server = (app: NameSet): string => `---
@@ -108,8 +109,9 @@ renders. A change outside that set is a collision — report it, do not make it.
108
109
  Inspect before you change: \`bunx x actions show <name>\`, \`bunx x queries show <name>\`, \`bunx x jobs list\`,
109
110
  \`bunx x tasks list\`, \`bunx x policy explain <subject>\` — every one takes \`--json\`.
110
111
 
111
- Checks: \`bun test <path>/<file>.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and \`bun run typecheck\`
112
- once when you are otherwise done. Never \`bunx x verify\` — that belongs to whoever coordinates you.
112
+ Checks: \`bun test <path>/<file>.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and
113
+ \`bunx x verify --only typecheck\` once when you are otherwise done: it queues for the machine's memory.
114
+ Never the whole \`bunx x verify\` — that belongs to whoever coordinates you.
113
115
  `;
114
116
 
115
117
  const web = (app: NameSet): string => `---
@@ -143,8 +145,9 @@ Every one of the last five is a build error, not a preference — a guard the fr
143
145
  Inspect before you change: \`bunx x routes --json\`, \`bunx x i18n check\` for catalog gaps, and
144
146
  \`bunx x shot <route> --json\` when you need to see what you built.
145
147
 
146
- Checks: \`bun test <path>/page.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and \`bun run typecheck\`
147
- once when you are otherwise done. Never \`bunx x verify\` — that belongs to whoever coordinates you.
148
+ Checks: \`bun test <path>/page.test.ts\`, \`bunx @biomejs/biome check --write <paths>\`, and
149
+ \`bunx x verify --only typecheck\` once when you are otherwise done: it queues for the machine's memory.
150
+ Never the whole \`bunx x verify\` — that belongs to whoever coordinates you.
148
151
  `;
149
152
 
150
153
  /** One agent per boundary, plus the read-only one that runs before there is a boundary to hold. */
@@ -101,7 +101,7 @@ While you iterate, narrow the *feedback*, not the gate:
101
101
  | a whole type | \`bunx x test unit\` · \`bunx x test contract\` · \`bunx x test e2e\` |
102
102
  | one gate step | \`bunx x verify --only <step> --json\` — \`NOT A GATE RUN\` |
103
103
  | lint the files you touched | \`bunx @biomejs/biome check --write <paths>\` |
104
- | types, once, when otherwise done | \`bun run typecheck\` |
104
+ | types, once, when otherwise done | \`bunx x verify --only typecheck\` — queues for the machine's memory |
105
105
  | a broken environment | \`bunx x doctor\` |
106
106
 
107
107
  ## 5. Hard rules