@ultimat3/cli 31.47.1 → 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.
- package/package.json +29 -29
- package/src/cmd-drill.ts +20 -1
- package/src/cmd-heavy-spec.ts +28 -0
- package/src/cmd-heavy.ts +160 -0
- package/src/cmd-test.ts +13 -3
- package/src/cmd-upgrade.ts +17 -4
- package/src/codemods/docs-many-agents.ts +30 -0
- package/src/codemods/index.ts +2 -0
- package/src/doctor-advisory-floors.ts +30 -8
- package/src/error-codes-tooling.ts +9 -3
- package/src/exec.ts +11 -3
- package/src/heavy-cores.ts +51 -0
- package/src/heavy-env.ts +19 -0
- package/src/heavy-errors.ts +36 -0
- package/src/heavy-flock.ts +73 -0
- package/src/heavy-ledger.ts +358 -0
- package/src/heavy-memory.ts +67 -0
- package/src/heavy-weights.ts +47 -0
- package/src/heavy.ts +290 -0
- package/src/local-cli.ts +6 -5
- package/src/mcp-errors.ts +3 -0
- package/src/messages.ts +11 -0
- package/src/registry.ts +2 -0
- package/src/role-replicator.ts +5 -3
- package/src/runtime-cache.ts +24 -3
- package/src/runtime-overrides.ts +4 -2
- package/src/templates/guard-released-forms.ts +5 -5
- package/src/templates/scaffold-claude-agents.ts +9 -6
- package/src/templates/scaffold-claude-commands.ts +1 -1
- package/src/templates/scaffold-docs.ts +5 -4
- package/src/test-batches.ts +9 -3
- package/src/test-shards.ts +3 -3
- package/src/test-slots.ts +35 -161
- package/src/verify-checks.ts +4 -3
- package/src/verify-coverage-run.ts +5 -4
- package/src/verify-deadline.ts +18 -2
- package/src/verify-heavy-steps.ts +26 -0
- package/src/verify-test-run.ts +3 -2
- package/src/verify-tests.ts +27 -20
- package/wiki/Building-Your-Own-Base.md +15 -2
- package/wiki/CI-Parallel-Gate.md +2 -3
- package/wiki/CLI-Reference.md +24 -12
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Configuration.md +22 -4
- package/wiki/Home.md +1 -0
- package/wiki/Interface-Rules.md +1 -1
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/Mail.md +1 -1
- package/wiki/Many-Agents.md +60 -0
- package/wiki/Testing.md +5 -5
- package/wiki/Tutorial-01-First-App.md +2 -2
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
|
|
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
|
|
51
|
-
*
|
|
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
|
|
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
|
@@ -404,6 +404,9 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
404
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[] = [
|
package/src/role-replicator.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
package/src/runtime-cache.ts
CHANGED
|
@@ -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
|
|
78
|
-
*
|
|
79
|
-
*
|
|
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({
|
package/src/runtime-overrides.ts
CHANGED
|
@@ -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 `
|
|
58
|
-
*
|
|
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`. */
|
|
@@ -88,11 +88,11 @@ export const RELEASED_GUARD_FORMS: Readonly<
|
|
|
88
88
|
['3b0u9i8hze00x', 'error'],
|
|
89
89
|
],
|
|
90
90
|
'undeclared-env': [
|
|
91
|
-
['
|
|
92
|
-
['
|
|
93
|
-
['
|
|
94
|
-
['
|
|
95
|
-
['
|
|
91
|
+
['16pof11n1trhg', 'error'],
|
|
92
|
+
['1f8kizielequo', 'error'],
|
|
93
|
+
['2jb32jms80mge', 'error'],
|
|
94
|
+
['2t3qtexnpfnyq', 'error'],
|
|
95
|
+
['3gsoj050vbe69', 'error'],
|
|
96
96
|
],
|
|
97
97
|
'undefined-style-class': [
|
|
98
98
|
['3food9t4vrzv8', 'error'],
|
|
@@ -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
|
|
85
|
-
once when you are otherwise done
|
|
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
|
|
112
|
-
once when you are otherwise done
|
|
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
|
|
147
|
-
once when you are otherwise done
|
|
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 | \`
|
|
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
|
|
@@ -23,7 +23,7 @@ import { testServicesFiles } from './scaffold-test-services';
|
|
|
23
23
|
*/
|
|
24
24
|
const conventions = (app: NameSet): string => `# ${app.pascal}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
One file, two names: \`AGENTS.md\` is a symlink to it.
|
|
27
27
|
Facts live in \`x.manifest.json\`; this file holds only what an agent cannot infer from the code.
|
|
28
28
|
|
|
29
29
|
Every row below names what refuses it. A rule with nothing in the last column does not exist.
|
|
@@ -40,6 +40,7 @@ queries, jobs, MCP tools, published operations and tests it touches, each with p
|
|
|
40
40
|
|---|---|---|
|
|
41
41
|
| One gate | \`bun run verify\` — \`bunx x verify\`, which builds what its \`budgets\` step weighs. Green means shippable; never merge red. CI runs the same gate, cut into parts: \`bun run verify plan --json\` names them, each runner runs \`bun run setup && bun run verify --only <steps>\`, and \`bun run verify merge\` is the verdict | the gate itself, and \`.github/workflows/ci.yml\` on every push and pull request; \`.github/workflows/image.yml\` publishes only a commit it passed |
|
|
42
42
|
| Coverage | the unit suite covers 95% of the lines and functions of this app's own source — every file under \`apps/\` and \`packages/\`, one no test loads counted at 0%. A floor, not the goal: a test added to raise it is proven by mutation — break the source, watch it go red, restore | \`X_COVERAGE_BELOW_FLOOR\` on the \`unit\` step; \`coverage\` in \`x.verify.json\` states the floor, and it only rises |
|
|
43
|
+
| Many agents | a worker runs its own files; the coordinator runs the gate once | \`bunx x heavy status\` |
|
|
43
44
|
| One way | generators, not hand-rolled files: \`bunx x g resource\`, \`bunx x g action\`, \`bunx x g route\` | review |
|
|
44
45
|
| Surfaces | \`site/\` is 0kb JS and may not import \`app/\`; \`shared/\` is a leaf | \`X_BOUNDARY_SITE_TO_APP\` |
|
|
45
46
|
| Data | routes call actions and queries; only \`repo.ts\` touches the database | \`X_BOUNDARY_ROUTE_TO_DB\` |
|
|
@@ -134,11 +135,11 @@ Commands: \`bun run setup\`, \`bun run dev\`, \`bun run verify\`, \`bunx x g <pr
|
|
|
134
135
|
| Tool | What it answers | How to reach it |
|
|
135
136
|
|---|---|---|
|
|
136
137
|
| \`x.manifest.json\` | every route, action, query, job and policy, generated — read it before searching the tree | \`bunx x manifest\` rewrites it |
|
|
137
|
-
| \`bunx x impact <file|primitive> --json\` · \`bunx x graph --json\` | what an edit reaches, and the app as one graph (declared, import and observed edges) | rebuilt
|
|
138
|
+
| \`bunx x impact <file|primitive> --json\` · \`bunx x graph --json\` | what an edit reaches, and the app as one graph (declared, import and observed edges) | rebuilt on every call |
|
|
138
139
|
| \`.mcp.json\` | the dev tools over MCP: routes, schema, policies, the database, tests, the gate — \`bunx x mcp tools\` lists them | a client that reads \`.mcp.json\` starts it; from any other, run \`bunx @ultimat3/cli mcp serve --transport stdio\` here |
|
|
139
140
|
| \`POST /mcp\` | this app's own tools — every action declaring \`mcp: { expose: true }\` — for a remote agent | \`apps/web/mcp.ts\`; under \`bun run dev\`, \`Authorization: Bearer dev-agent.admin\`, else an API key |
|
|
140
|
-
| \`.claude/commands/feature.md\` | build or fix one thing end to end, done when \`bun run verify\` is green | plain markdown
|
|
141
|
-
| \`.claude/commands/planx.md\` | write a plan to \`docs/plans/\`
|
|
141
|
+
| \`.claude/commands/feature.md\` | build or fix one thing end to end, done when \`bun run verify\` is green | plain markdown any agent can follow |
|
|
142
|
+
| \`.claude/commands/planx.md\` | write a plan to \`docs/plans/\` | the same |
|
|
142
143
|
| \`.claude/commands/verify.md\` | run the gate and fix what it reports | the same |
|
|
143
144
|
|
|
144
145
|
Project notes for ${app.kebab}: replace this line with the conventions a newcomer could not guess.
|
package/src/test-batches.ts
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
import type { ExecResult, Runner } from './exec';
|
|
32
32
|
import { execOutput } from './exec';
|
|
33
33
|
import { msg } from './messages';
|
|
34
|
-
import {
|
|
34
|
+
import type { MachineLease } from './test-slots';
|
|
35
35
|
import { BATCH_FILES_PER_WORKER } from './test-workers';
|
|
36
36
|
|
|
37
37
|
/**
|
|
@@ -89,7 +89,7 @@ export async function runBatches(input: {
|
|
|
89
89
|
* Lease the batch's workers from the machine pool (`test-slots.ts`) before it starts, and give
|
|
90
90
|
* them back when it exits — so two runs on one box share its budget batch by batch.
|
|
91
91
|
*/
|
|
92
|
-
readonly lease?:
|
|
92
|
+
readonly lease?: MachineLease;
|
|
93
93
|
readonly options: Parameters<Runner>[1];
|
|
94
94
|
/**
|
|
95
95
|
* Launch no further batch once one is red. Set for a caller-forwarded `--bail`: Bun stops a
|
|
@@ -109,7 +109,13 @@ export async function runBatches(input: {
|
|
|
109
109
|
input.argsFor(files, width),
|
|
110
110
|
lease === undefined
|
|
111
111
|
? input.options
|
|
112
|
-
: {
|
|
112
|
+
: {
|
|
113
|
+
...input.options,
|
|
114
|
+
env: { ...input.options.env, ...lease.env },
|
|
115
|
+
...(lease.fds === undefined || lease.fds.length === 0
|
|
116
|
+
? {}
|
|
117
|
+
: { inheritFds: lease.fds }),
|
|
118
|
+
},
|
|
113
119
|
);
|
|
114
120
|
} finally {
|
|
115
121
|
lease?.release();
|
package/src/test-shards.ts
CHANGED
|
@@ -51,6 +51,7 @@ import { msg } from './messages';
|
|
|
51
51
|
import type { CommandResult, Finding, JsonValue, StepResult } from './output';
|
|
52
52
|
import { quoteArg } from './shell-quote';
|
|
53
53
|
import { testEnvOverrides } from './test-dotenv';
|
|
54
|
+
import type { MachineLease } from './test-slots';
|
|
54
55
|
|
|
55
56
|
/** Bun's per-file durations, cached under the run's root and refreshed by every parallel run. */
|
|
56
57
|
export const TEST_TIMINGS_FILE = '.x/test-timings.json';
|
|
@@ -201,7 +202,7 @@ export interface RunShardsOptions {
|
|
|
201
202
|
/** `--seed`: handed to the children by the caller's runner, printed back in the reproduce. */
|
|
202
203
|
readonly seed?: number;
|
|
203
204
|
/** The machine-pool lease (`test-slots.ts`), for a default-width run. */
|
|
204
|
-
readonly lease?:
|
|
205
|
+
readonly lease?: MachineLease;
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
const isolatedRun = (options: RunShardsOptions): boolean => {
|
|
@@ -297,8 +298,7 @@ export async function runShards(options: RunShardsOptions): Promise<CommandResul
|
|
|
297
298
|
batches,
|
|
298
299
|
stopOnFailure: bailing,
|
|
299
300
|
workers: pass.workers,
|
|
300
|
-
|
|
301
|
-
...(pass.workers > 1 && options.lease !== undefined ? { lease: options.lease } : {}),
|
|
301
|
+
...(options.lease === undefined ? {} : { lease: options.lease }),
|
|
302
302
|
argsFor: (batch, width) =>
|
|
303
303
|
testArgs({
|
|
304
304
|
files: batch,
|