@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.48.0",
|
|
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.
|
|
57
|
-
"@ultimat3/admin": "31.
|
|
58
|
-
"@ultimat3/ai": "31.
|
|
59
|
-
"@ultimat3/auth": "31.
|
|
60
|
-
"@ultimat3/cache": "31.
|
|
61
|
-
"@ultimat3/core": "31.
|
|
62
|
-
"@ultimat3/db": "31.
|
|
63
|
-
"@ultimat3/entity": "31.
|
|
64
|
-
"@ultimat3/flags": "31.
|
|
65
|
-
"@ultimat3/http": "31.
|
|
66
|
-
"@ultimat3/i18n": "31.
|
|
67
|
-
"@ultimat3/jobs": "31.
|
|
68
|
-
"@ultimat3/mail": "31.
|
|
69
|
-
"@ultimat3/manifest": "31.
|
|
70
|
-
"@ultimat3/mcp": "31.
|
|
71
|
-
"@ultimat3/money": "31.
|
|
72
|
-
"@ultimat3/notify": "31.
|
|
73
|
-
"@ultimat3/policy": "31.
|
|
74
|
-
"@ultimat3/pwa": "31.
|
|
75
|
-
"@ultimat3/query": "31.
|
|
76
|
-
"@ultimat3/realtime": "31.
|
|
77
|
-
"@ultimat3/render": "31.
|
|
78
|
-
"@ultimat3/schema": "31.
|
|
79
|
-
"@ultimat3/scraping": "31.
|
|
80
|
-
"@ultimat3/seo": "31.
|
|
81
|
-
"@ultimat3/storage": "31.
|
|
82
|
-
"@ultimat3/testing": "31.
|
|
83
|
-
"@ultimat3/time": "31.
|
|
56
|
+
"@ultimat3/action": "31.48.0",
|
|
57
|
+
"@ultimat3/admin": "31.48.0",
|
|
58
|
+
"@ultimat3/ai": "31.48.0",
|
|
59
|
+
"@ultimat3/auth": "31.48.0",
|
|
60
|
+
"@ultimat3/cache": "31.48.0",
|
|
61
|
+
"@ultimat3/core": "31.48.0",
|
|
62
|
+
"@ultimat3/db": "31.48.0",
|
|
63
|
+
"@ultimat3/entity": "31.48.0",
|
|
64
|
+
"@ultimat3/flags": "31.48.0",
|
|
65
|
+
"@ultimat3/http": "31.48.0",
|
|
66
|
+
"@ultimat3/i18n": "31.48.0",
|
|
67
|
+
"@ultimat3/jobs": "31.48.0",
|
|
68
|
+
"@ultimat3/mail": "31.48.0",
|
|
69
|
+
"@ultimat3/manifest": "31.48.0",
|
|
70
|
+
"@ultimat3/mcp": "31.48.0",
|
|
71
|
+
"@ultimat3/money": "31.48.0",
|
|
72
|
+
"@ultimat3/notify": "31.48.0",
|
|
73
|
+
"@ultimat3/policy": "31.48.0",
|
|
74
|
+
"@ultimat3/pwa": "31.48.0",
|
|
75
|
+
"@ultimat3/query": "31.48.0",
|
|
76
|
+
"@ultimat3/realtime": "31.48.0",
|
|
77
|
+
"@ultimat3/render": "31.48.0",
|
|
78
|
+
"@ultimat3/schema": "31.48.0",
|
|
79
|
+
"@ultimat3/scraping": "31.48.0",
|
|
80
|
+
"@ultimat3/seo": "31.48.0",
|
|
81
|
+
"@ultimat3/storage": "31.48.0",
|
|
82
|
+
"@ultimat3/testing": "31.48.0",
|
|
83
|
+
"@ultimat3/time": "31.48.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/cmd-drill.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
DrillDeclarations,
|
|
12
12
|
DrillFleet,
|
|
13
13
|
DrillReport,
|
|
14
|
+
DrillRoleNotPlayed,
|
|
14
15
|
} from '@ultimat3/testing';
|
|
15
16
|
import {
|
|
16
17
|
bunDrillSql,
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
drillBudgets,
|
|
22
23
|
drillNamed,
|
|
23
24
|
drillRoles,
|
|
25
|
+
drillRolesNotPlayed,
|
|
24
26
|
drillServices,
|
|
25
27
|
runDrill,
|
|
26
28
|
runRollout,
|
|
@@ -38,6 +40,7 @@ import { readIntFlag } from './flag-number';
|
|
|
38
40
|
import { msg } from './messages';
|
|
39
41
|
import type { CommandResult, Finding, JsonValue } from './output';
|
|
40
42
|
import { flagBool } from './parse';
|
|
43
|
+
import { replicatedRelations } from './role-replicator';
|
|
41
44
|
|
|
42
45
|
/** Read through `readIntFlag`, which refuses `5s`, `NaN` and a fraction with the flag's name. */
|
|
43
46
|
const BUDGET_FLAG = 'budget-ms';
|
|
@@ -177,9 +180,20 @@ export const drillCommand: CliCommand = {
|
|
|
177
180
|
}
|
|
178
181
|
const budgets = drillBudgets(drillConfigOf(config), override);
|
|
179
182
|
const { targets, skipped } = await drillTargets(root);
|
|
183
|
+
// After `drillTargets`: loading the app is what fills the entity registry read here.
|
|
184
|
+
const publishable = replicatedRelations().length > 0;
|
|
180
185
|
const reports: DrillReport[] = [];
|
|
186
|
+
const rolesNotPlayed: (DrillRoleNotPlayed & { readonly drill: string })[] = [];
|
|
181
187
|
for (const { drill, services } of planned) {
|
|
182
188
|
const { fault } = drill;
|
|
189
|
+
const found = {
|
|
190
|
+
bus: services.nats !== undefined,
|
|
191
|
+
logicalPostgres: services.logicalPostgres === true,
|
|
192
|
+
publishable,
|
|
193
|
+
};
|
|
194
|
+
for (const gap of drillRolesNotPlayed(drill, found)) {
|
|
195
|
+
rolesNotPlayed.push({ drill: drill.name, ...gap });
|
|
196
|
+
}
|
|
183
197
|
// The rollout order: the stamp is this package's to write, so the rewind is handed in.
|
|
184
198
|
const order =
|
|
185
199
|
fault.kind === 'order'
|
|
@@ -188,7 +202,7 @@ export const drillCommand: CliCommand = {
|
|
|
188
202
|
const fleet = await startDrillFleet({
|
|
189
203
|
root,
|
|
190
204
|
services,
|
|
191
|
-
roles: drillRoles(drill),
|
|
205
|
+
roles: drillRoles(drill, found),
|
|
192
206
|
readyTimeoutMs: READY_TIMEOUT_MS,
|
|
193
207
|
beforeMigrate: order,
|
|
194
208
|
});
|
|
@@ -209,6 +223,9 @@ export const drillCommand: CliCommand = {
|
|
|
209
223
|
lines: [
|
|
210
224
|
...reports.map((report) => ` ${report.verdict.ok ? 'held' : 'FAILED'} ${report.name}`),
|
|
211
225
|
...notRun.map((drill) => ` not run ${drill}`),
|
|
226
|
+
...rolesNotPlayed.map(
|
|
227
|
+
(gap) => ` not played ${gap.drill}: ${gap.role}, needs ${gap.needs}`,
|
|
228
|
+
),
|
|
212
229
|
],
|
|
213
230
|
findings,
|
|
214
231
|
data: {
|
|
@@ -218,6 +235,8 @@ export const drillCommand: CliCommand = {
|
|
|
218
235
|
skippedWrites: skipped.map((entry) => ({ ...entry })),
|
|
219
236
|
drills: reports.map(reportJson),
|
|
220
237
|
notRun,
|
|
238
|
+
// A role the rollout order left out, with what it needs: CI refuses a non-empty list.
|
|
239
|
+
rolesNotPlayed: rolesNotPlayed.map((gap) => ({ ...gap })),
|
|
221
240
|
},
|
|
222
241
|
};
|
|
223
242
|
},
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// `x heavy`'s declaration, apart from its body: the parser, `x help` and the `errors` step read it
|
|
2
|
+
// without loading `cmd-heavy.ts`, which `registry.ts` imports only when the command runs.
|
|
3
|
+
|
|
4
|
+
import type { CommandSpec } from './parse';
|
|
5
|
+
|
|
6
|
+
export const heavySpec: CommandSpec = {
|
|
7
|
+
name: 'heavy',
|
|
8
|
+
summary:
|
|
9
|
+
"the machine's shared memory ledger: who is running, who is queued, and any command run inside it",
|
|
10
|
+
usage: 'x heavy [status] [--json] · x heavy run [--label s] [--mb n] [--json] -- <command…>',
|
|
11
|
+
subcommands: ['status', 'run'],
|
|
12
|
+
defaultSubcommand: 'status',
|
|
13
|
+
passthrough: true,
|
|
14
|
+
flags: [
|
|
15
|
+
{
|
|
16
|
+
name: 'label',
|
|
17
|
+
type: 'string',
|
|
18
|
+
summary: 'what other waiters see this run called (default: the command)',
|
|
19
|
+
subcommands: ['run'],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'mb',
|
|
23
|
+
type: 'string',
|
|
24
|
+
summary: 'the memory to reserve, its measured peak (default: a whole-repo typecheck)',
|
|
25
|
+
subcommands: ['run'],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
package/src/cmd-heavy.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// `x heavy`: the machine ledger as a command. `status` is a read that changes nothing; `run` puts any
|
|
2
|
+
// command inside one reservation, passes its exit code through and forwards stop signals, which is
|
|
3
|
+
// how a repository with no Ultimate in it shares the same queue.
|
|
4
|
+
|
|
5
|
+
// why: Bun exposes no load average, core count or total-memory primitive.
|
|
6
|
+
import { availableParallelism, loadavg, totalmem } from 'node:os';
|
|
7
|
+
import { heavySpec } from './cmd-heavy-spec';
|
|
8
|
+
import type { CliCommand, CommandContext } from './command';
|
|
9
|
+
import { MissingPositionalError } from './errors';
|
|
10
|
+
import { readIntFlag } from './flag-number';
|
|
11
|
+
import { describeEntry, heavyState, withHeavy } from './heavy';
|
|
12
|
+
import { coreCap, runnableTasks } from './heavy-cores';
|
|
13
|
+
import { HeavyCommandNotFoundError } from './heavy-errors';
|
|
14
|
+
import { readLedger } from './heavy-ledger';
|
|
15
|
+
import { availableMemoryBytes, usableMemoryBytes } from './heavy-memory';
|
|
16
|
+
import { DEFAULT_RUN_MB } from './heavy-weights';
|
|
17
|
+
import type { HandOffChild } from './local-cli-handoff';
|
|
18
|
+
import { handOff } from './local-cli-handoff';
|
|
19
|
+
import { msg } from './messages';
|
|
20
|
+
import type { CommandResult, JsonValue } from './output';
|
|
21
|
+
import { findingFrom } from './output';
|
|
22
|
+
import { flagString } from './parse';
|
|
23
|
+
|
|
24
|
+
const gb = (bytes: number): string => (bytes / 2 ** 30).toFixed(1);
|
|
25
|
+
const MAX_RUN_MB = 1024 * 1024;
|
|
26
|
+
|
|
27
|
+
async function status(ctx: CommandContext): Promise<CommandResult> {
|
|
28
|
+
const state = await heavyState({ ...ctx.env, ULTIMATE_HEAVY_HOLD: undefined });
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
const view = state.on ? readLedger(state.dir, state.tryLock) : { holds: [], queue: [] };
|
|
31
|
+
const cores = coreCap(ctx.env);
|
|
32
|
+
const coreText = cores === undefined ? String(availableParallelism()) : String(cores);
|
|
33
|
+
const usedMb = view.holds.reduce((sum, entry) => sum + entry.mb, 0);
|
|
34
|
+
const [one = 0, five = 0, fifteen = 0] = loadavg();
|
|
35
|
+
const machine = {
|
|
36
|
+
cores: availableParallelism(),
|
|
37
|
+
runnable: runnableTasks(),
|
|
38
|
+
load: { one, five, fifteen },
|
|
39
|
+
totalBytes: usableMemoryBytes(totalmem()),
|
|
40
|
+
availableBytes: availableMemoryBytes(),
|
|
41
|
+
};
|
|
42
|
+
const entryJson = (entry: (typeof view.holds)[number]): JsonValue => ({
|
|
43
|
+
pid: entry.pid,
|
|
44
|
+
mb: entry.mb,
|
|
45
|
+
label: entry.label,
|
|
46
|
+
cwd: entry.cwd,
|
|
47
|
+
ageMs: Math.max(0, now - entry.at),
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
ok: true,
|
|
51
|
+
command: 'heavy',
|
|
52
|
+
summary: state.on
|
|
53
|
+
? msg('cli.heavy.status.summary', {
|
|
54
|
+
used: usedMb,
|
|
55
|
+
capacity: state.capacityMb,
|
|
56
|
+
holds: view.holds.length,
|
|
57
|
+
queued: view.queue.length,
|
|
58
|
+
cores: coreText,
|
|
59
|
+
})
|
|
60
|
+
: msg('cli.heavy.status.off', { reason: state.detail ?? state.off, cores: coreText }),
|
|
61
|
+
lines: [
|
|
62
|
+
msg('cli.heavy.status.machine', {
|
|
63
|
+
load: one.toFixed(1),
|
|
64
|
+
cpus: machine.cores,
|
|
65
|
+
runnable: machine.runnable,
|
|
66
|
+
free: gb(machine.availableBytes),
|
|
67
|
+
total: gb(machine.totalBytes),
|
|
68
|
+
}),
|
|
69
|
+
...view.holds.map((entry) =>
|
|
70
|
+
msg('cli.heavy.status.hold', { entry: describeEntry(entry, now) }),
|
|
71
|
+
),
|
|
72
|
+
...view.queue.map((entry, at) =>
|
|
73
|
+
msg('cli.heavy.status.queued', { position: at + 1, entry: describeEntry(entry, now) }),
|
|
74
|
+
),
|
|
75
|
+
],
|
|
76
|
+
data: {
|
|
77
|
+
enabled: state.on,
|
|
78
|
+
...(state.on
|
|
79
|
+
? { dir: state.dir, capacityMb: state.capacityMb, usedMb }
|
|
80
|
+
: { off: state.off, ...(state.detail === undefined ? {} : { detail: state.detail }) }),
|
|
81
|
+
coreCap: cores ?? null,
|
|
82
|
+
machine,
|
|
83
|
+
holds: view.holds.map(entryJson),
|
|
84
|
+
queue: view.queue.map(entryJson),
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const seconds = (ms: number): string => `${(ms / 1000).toFixed(1)}s`;
|
|
90
|
+
|
|
91
|
+
async function run(ctx: CommandContext): Promise<CommandResult> {
|
|
92
|
+
const command = ctx.args.passthrough;
|
|
93
|
+
const first = command[0];
|
|
94
|
+
if (first === undefined || ctx.args.positionals.length > 0) {
|
|
95
|
+
throw new MissingPositionalError({
|
|
96
|
+
command: 'heavy run',
|
|
97
|
+
positional: '-- command',
|
|
98
|
+
example: 'x heavy run --label tests -- bun test',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// Under `--json` fd 1 is this command's one document, so the child's stdout moves to fd 2.
|
|
102
|
+
const stream = ctx.args.json ? undefined : ('stderr' as const);
|
|
103
|
+
const envelope = { command: 'heavy', ...(stream === undefined ? {} : { stream }) };
|
|
104
|
+
const path = ctx.env['PATH'];
|
|
105
|
+
if (Bun.which(first, { cwd: ctx.cwd, ...(path === undefined ? {} : { PATH: path }) }) === null) {
|
|
106
|
+
const finding = findingFrom(new HeavyCommandNotFoundError(first));
|
|
107
|
+
return { ...envelope, ok: false, summary: finding.cause, findings: [finding], exitCode: 127 };
|
|
108
|
+
}
|
|
109
|
+
const mb = readIntFlag(ctx.args, {
|
|
110
|
+
name: 'mb',
|
|
111
|
+
command: 'heavy',
|
|
112
|
+
min: 1,
|
|
113
|
+
max: MAX_RUN_MB,
|
|
114
|
+
example: 'x heavy run --mb 4096 -- bun test',
|
|
115
|
+
});
|
|
116
|
+
const label = flagString(ctx.args, 'label') ?? command.slice(0, 3).join(' ');
|
|
117
|
+
const queued = performance.now();
|
|
118
|
+
let startedAt = queued;
|
|
119
|
+
const code = await withHeavy(
|
|
120
|
+
{ label, cwd: ctx.cwd, env: ctx.env, unitMb: mb ?? DEFAULT_RUN_MB },
|
|
121
|
+
(child) => {
|
|
122
|
+
startedAt = performance.now();
|
|
123
|
+
return handOff(
|
|
124
|
+
command,
|
|
125
|
+
{ ...ctx.env, ...child.env },
|
|
126
|
+
{
|
|
127
|
+
spawn: (argv, env): HandOffChild =>
|
|
128
|
+
// Untimed: the child is the command the caller asked to run, and its stop signals are
|
|
129
|
+
// forwarded by `handOff`. Counted under `cli`'s spawn-timeout pin with that hand-off.
|
|
130
|
+
Bun.spawn([...argv], {
|
|
131
|
+
cwd: ctx.cwd,
|
|
132
|
+
env,
|
|
133
|
+
// The reservation's lock goes with it: killing this wrapper frees nothing the
|
|
134
|
+
// command is still using.
|
|
135
|
+
stdio: ['inherit', ctx.args.json ? 2 : 'inherit', 'inherit', ...child.fds],
|
|
136
|
+
}),
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
);
|
|
141
|
+
const ranMs = performance.now() - startedAt;
|
|
142
|
+
const waitedMs = startedAt - queued;
|
|
143
|
+
return {
|
|
144
|
+
...envelope,
|
|
145
|
+
ok: code === 0,
|
|
146
|
+
summary: msg('cli.heavy.run.done', {
|
|
147
|
+
command: label,
|
|
148
|
+
code,
|
|
149
|
+
ran: seconds(ranMs),
|
|
150
|
+
waited: seconds(waitedMs),
|
|
151
|
+
}),
|
|
152
|
+
exitCode: code,
|
|
153
|
+
data: { exitCode: code, ranMs: Math.round(ranMs), waitedMs: Math.round(waitedMs) },
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export const heavyCommand: CliCommand = {
|
|
158
|
+
spec: heavySpec,
|
|
159
|
+
run: (ctx) => (ctx.args.subcommand === 'run' ? run(ctx) : status(ctx)),
|
|
160
|
+
};
|
package/src/cmd-test.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { ok } from './command';
|
|
|
19
19
|
import { BadFlagError, NoTestFilesError } from './errors';
|
|
20
20
|
import type { Runner } from './exec';
|
|
21
21
|
import { readIntFlag } from './flag-number';
|
|
22
|
+
import { FREE_RUN_FILES } from './heavy-weights';
|
|
22
23
|
import { msg } from './messages';
|
|
23
24
|
import type { CommandResult, JsonValue } from './output';
|
|
24
25
|
import type { ParsedArgs } from './parse';
|
|
@@ -245,9 +246,18 @@ export const testCommand: CliCommand = {
|
|
|
245
246
|
workers,
|
|
246
247
|
...(isolate ? { isolate } : {}),
|
|
247
248
|
...(seed === undefined ? {} : { seed }),
|
|
248
|
-
//
|
|
249
|
-
// gate on the same box
|
|
250
|
-
...(
|
|
249
|
+
// Every run but a worker's own few files enters the machine ledger, so a second `x test` or
|
|
250
|
+
// gate on the same box narrows or queues instead of doubling its memory.
|
|
251
|
+
...(files.length <= FREE_RUN_FILES
|
|
252
|
+
? {}
|
|
253
|
+
: withLease(
|
|
254
|
+
machineLease(ctx.env, {
|
|
255
|
+
cwd: ctx.cwd,
|
|
256
|
+
label: type === undefined ? 'x test' : `x test ${type}`,
|
|
257
|
+
...(type === undefined ? {} : { type }),
|
|
258
|
+
...(plan === undefined ? { exact: true } : {}),
|
|
259
|
+
}),
|
|
260
|
+
)),
|
|
251
261
|
...(filter === undefined ? {} : { filter }),
|
|
252
262
|
...(type === undefined ? {} : { type }),
|
|
253
263
|
// `kept` is the corpus the run saw. `selected`, not `discovered`: with `--affected` the sample was taken from the narrowed
|
package/src/cmd-upgrade.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { runUpgradeCodemods } from './cmd-upgrade-codemods';
|
|
|
11
11
|
import { upgradeSpec } from './cmd-upgrade-spec';
|
|
12
12
|
import type { CliCommand, CommandContext } from './command';
|
|
13
13
|
import { failed, ok } from './command';
|
|
14
|
+
import { staleTransitiveFloors } from './doctor-advisory-floors';
|
|
14
15
|
import { supersededFindings } from './doctor-superseded';
|
|
15
16
|
import { BadFlagError, BunVersionError } from './errors';
|
|
16
17
|
import type { Runner } from './exec';
|
|
@@ -86,17 +87,29 @@ async function planWrites(input: {
|
|
|
86
87
|
return { files, edited, manual };
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
/** `bun install
|
|
90
|
-
async function
|
|
91
|
-
|
|
90
|
+
/** One `bun` step of the install, or the refusal carrying the command that undoes the pins. */
|
|
91
|
+
async function installStep(
|
|
92
|
+
runner: Runner,
|
|
93
|
+
root: string,
|
|
94
|
+
to: string,
|
|
95
|
+
args: readonly string[],
|
|
96
|
+
): Promise<void> {
|
|
97
|
+
const result = await runner([process.execPath, ...args], { cwd: root });
|
|
92
98
|
if (result.ok) return;
|
|
93
99
|
throw new UltimateError({
|
|
94
100
|
code: 'X_UPGRADE_INSTALL_FAILED',
|
|
95
|
-
cause: `bun
|
|
101
|
+
cause: `bun ${args.join(' ')} exited ${String(result.code)} after pinning ${to}: ${execOutput(result).slice(-800) || 'no output'}`,
|
|
96
102
|
fix: 'git restore . # undoes the pins, since the tree was clean; then fix what the cause names and re-run: x upgrade --json',
|
|
97
103
|
});
|
|
98
104
|
}
|
|
99
105
|
|
|
106
|
+
/** `bun install` keeps what the lockfile resolves, so a patched transitive release is asked for. */
|
|
107
|
+
async function install(runner: Runner, root: string, to: string): Promise<void> {
|
|
108
|
+
await installStep(runner, root, to, ['install']);
|
|
109
|
+
const stale = await staleTransitiveFloors(root);
|
|
110
|
+
if (stale.length > 0) await installStep(runner, root, to, ['update', ...stale]);
|
|
111
|
+
}
|
|
112
|
+
|
|
100
113
|
const stageLine = (stage: string): string => JSON.stringify({ upgrade: stage });
|
|
101
114
|
|
|
102
115
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// 31.48.0: CLAUDE.md states who runs what when several agents share a machine, the rule the machine
|
|
2
|
+
// ledger exists to back. Prose: it lands where the table stands as `x new` wrote it, and is skipped
|
|
3
|
+
// silently where the app reworded that row or already says it.
|
|
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
|
+
const NEXT_ROW = '| One way | generators, not hand-rolled files:';
|
|
11
|
+
|
|
12
|
+
/** Terse on purpose: a shaped app's CLAUDE.md sits within bytes of `AGENTS_MD_MAX_BYTES`. */
|
|
13
|
+
export const MANY_AGENTS_ROW =
|
|
14
|
+
'| Many agents | a worker runs its own files; the coordinator runs the gate once | `bunx x heavy status` |';
|
|
15
|
+
|
|
16
|
+
export const DOCS_MANY_AGENTS_EDITS: readonly SnippetEdit[] = [
|
|
17
|
+
{ from: NEXT_ROW, to: `${MANY_AGENTS_ROW}\n${NEXT_ROW}`, optional: true },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const codemod: Codemod = {
|
|
21
|
+
id: 'docs-many-agents',
|
|
22
|
+
since: '31.48.0',
|
|
23
|
+
summary: "CLAUDE.md's table says a worker runs its own files and the coordinator runs the gate",
|
|
24
|
+
async run(app) {
|
|
25
|
+
if (((await app.read(CLAUDE)) ?? '').includes('x heavy status')) {
|
|
26
|
+
return { changed: [], skipped: [] };
|
|
27
|
+
}
|
|
28
|
+
return editSnippets(app, CLAUDE, DOCS_MANY_AGENTS_EDITS);
|
|
29
|
+
},
|
|
30
|
+
};
|
package/src/codemods/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { codemod as docsCiParts } from './docs-ci-parts';
|
|
|
18
18
|
import { codemod as docsEnvGuard } from './docs-env-guard';
|
|
19
19
|
import { codemod as docsGateProse } from './docs-gate-prose';
|
|
20
20
|
import { codemod as docsIslandRows } from './docs-island-rows';
|
|
21
|
+
import { codemod as docsManyAgents } from './docs-many-agents';
|
|
21
22
|
import { codemod as docsShippedGuards } from './docs-shipped-guards';
|
|
22
23
|
import { codemod as docsTestServices } from './docs-test-services';
|
|
23
24
|
import { codemod as e2eSuiteFloor } from './e2e-suite-floor';
|
|
@@ -71,4 +72,5 @@ export const CODEMODS: readonly Codemod[] = [
|
|
|
71
72
|
ciArtifactRetention,
|
|
72
73
|
ciWeeklySchedule,
|
|
73
74
|
e2eSuiteFloor,
|
|
75
|
+
docsManyAgents,
|
|
74
76
|
];
|
|
@@ -79,6 +79,35 @@ async function lockPackages(root: string): Promise<Readonly<Record<string, unkno
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/** What `bun.lock` resolves for this row below its floor, lowest first. */
|
|
83
|
+
function versionsBelow(
|
|
84
|
+
packages: Readonly<Record<string, unknown>>,
|
|
85
|
+
row: AdvisoryFloor,
|
|
86
|
+
): readonly string[] {
|
|
87
|
+
// A git, tarball or `file:` head is no release on npm's line, so no advisory range reads it:
|
|
88
|
+
// skipped rather than ordered, because `Bun.semver.order` throws on it and would take every
|
|
89
|
+
// other `x doctor` check down with this warning.
|
|
90
|
+
return resolvedVersions(packages, row.name)
|
|
91
|
+
.filter((version) => RELEASE.test(version))
|
|
92
|
+
.filter((version) => Bun.semver.order(version, row.floor) < 0)
|
|
93
|
+
.sort((a, b) => Bun.semver.order(a, b));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The transitive packages `bun.lock` holds under a floor: `bun install` honours the lockfile, so
|
|
98
|
+
* `x upgrade` names these to `bun update`, and an upgraded app is not left to `x doctor`'s warning.
|
|
99
|
+
*/
|
|
100
|
+
export async function staleTransitiveFloors(
|
|
101
|
+
root: string,
|
|
102
|
+
floors: readonly AdvisoryFloor[] = ADVISORY_FLOORS,
|
|
103
|
+
): Promise<readonly string[]> {
|
|
104
|
+
const packages = await lockPackages(root);
|
|
105
|
+
if (packages === undefined) return [];
|
|
106
|
+
return floors
|
|
107
|
+
.filter((row) => row.via === 'transitive' && versionsBelow(packages, row).length > 0)
|
|
108
|
+
.map((row) => row.name);
|
|
109
|
+
}
|
|
110
|
+
|
|
82
111
|
/** One warning per floor the lockfile resolves under, lowest resolved version named. */
|
|
83
112
|
export async function advisoryFloorFindings(
|
|
84
113
|
root: string,
|
|
@@ -88,14 +117,7 @@ export async function advisoryFloorFindings(
|
|
|
88
117
|
if (packages === undefined) return [];
|
|
89
118
|
const transitive = floors.filter((f) => f.via === 'transitive').map((f) => quoteArg(f.name));
|
|
90
119
|
return floors.flatMap((row) => {
|
|
91
|
-
|
|
92
|
-
// skipped rather than ordered, because `Bun.semver.order` throws on it and would take every
|
|
93
|
-
// other `x doctor` check down with this warning.
|
|
94
|
-
const below = resolvedVersions(packages, row.name)
|
|
95
|
-
.filter((version) => RELEASE.test(version))
|
|
96
|
-
.filter((version) => Bun.semver.order(version, row.floor) < 0)
|
|
97
|
-
.sort((a, b) => Bun.semver.order(a, b));
|
|
98
|
-
const lowest = below[0];
|
|
120
|
+
const lowest = versionsBelow(packages, row)[0];
|
|
99
121
|
if (lowest === undefined) return [];
|
|
100
122
|
return [
|
|
101
123
|
{
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// The X_* codes of the
|
|
2
|
-
// `x
|
|
1
|
+
// The X_* codes of the tooling commands — `x client`, `x graph` / `x impact`, `x repro`, `x explain`
|
|
2
|
+
// and `x heavy` — split out of `error-codes.ts` at its 500-line ceiling, as `error-codes-shot.ts`
|
|
3
3
|
// was. That file folds these into the CLI's one owned union and registers them in its one call.
|
|
4
4
|
|
|
5
|
-
/** Codes `x client`, `x graph`, `x impact`, `x repro` and `x
|
|
5
|
+
/** Codes `x client`, `x graph`, `x impact`, `x repro`, `x explain` and `x heavy` own. */
|
|
6
6
|
export const CLI_TOOLING_ERROR_CODES = [
|
|
7
7
|
'X_CLIENT_SPEC_UNSUPPORTED',
|
|
8
8
|
'X_CLIENT_STALE',
|
|
@@ -13,6 +13,9 @@ export const CLI_TOOLING_ERROR_CODES = [
|
|
|
13
13
|
'X_REPRO_NOT_REPRODUCED',
|
|
14
14
|
'X_REPRO_CAPTURE_OFF',
|
|
15
15
|
'X_EXPLAIN_PRODUCTION_DATABASE',
|
|
16
|
+
'X_HEAVY_LEDGER_UNAVAILABLE',
|
|
17
|
+
'X_HEAVY_MEMORY_INVALID',
|
|
18
|
+
'X_HEAVY_COMMAND_NOT_FOUND',
|
|
16
19
|
] as const;
|
|
17
20
|
|
|
18
21
|
export type CliToolingErrorCode = (typeof CLI_TOOLING_ERROR_CODES)[number];
|
|
@@ -28,4 +31,7 @@ export const CLI_TOOLING_ERROR_TITLES: Readonly<Record<CliToolingErrorCode, stri
|
|
|
28
31
|
X_REPRO_NOT_REPRODUCED: 'a written repro test did not fail the way the original did',
|
|
29
32
|
X_REPRO_CAPTURE_OFF: 'x repro was given a request id while failure capture is off',
|
|
30
33
|
X_EXPLAIN_PRODUCTION_DATABASE: 'x explain refused to run on a production database',
|
|
34
|
+
X_HEAVY_LEDGER_UNAVAILABLE: 'the machine memory ledger cannot be used here',
|
|
35
|
+
X_HEAVY_MEMORY_INVALID: 'ULTIMATE_HEAVY_MEMORY is not a size',
|
|
36
|
+
X_HEAVY_COMMAND_NOT_FOUND: 'x heavy run was given a command that is not on PATH',
|
|
31
37
|
};
|
package/src/exec.ts
CHANGED
|
@@ -32,6 +32,11 @@ export interface ExecOptions {
|
|
|
32
32
|
*/
|
|
33
33
|
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
34
34
|
readonly stdin?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Descriptors the child inherits, from fd 3 up: the machine ledger's locks (`heavy-ledger.ts`),
|
|
37
|
+
* which must outlive this process when it is killed and the child is not.
|
|
38
|
+
*/
|
|
39
|
+
readonly inheritFds?: readonly number[];
|
|
35
40
|
/**
|
|
36
41
|
* Told the child's pid the moment it exists. A gate step's deadline records it here
|
|
37
42
|
* (`verify-deadline.ts`): on Windows no process's environment is readable, so the tag sweep
|
|
@@ -91,9 +96,12 @@ function spawnOrRefuse(command: readonly string[], options: ExecOptions) {
|
|
|
91
96
|
return Bun.spawn([head, ...rest], {
|
|
92
97
|
cwd: options.cwd,
|
|
93
98
|
env: options.env === undefined ? Bun.env : mergedEnv(options.env),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
stdio: [
|
|
100
|
+
options.stdin === undefined ? 'ignore' : new TextEncoder().encode(options.stdin),
|
|
101
|
+
'pipe',
|
|
102
|
+
'pipe',
|
|
103
|
+
...(options.inheritFds ?? []),
|
|
104
|
+
],
|
|
97
105
|
});
|
|
98
106
|
} catch (error) {
|
|
99
107
|
throw new UltimateError({
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// How many cores a local run may take: every one in CI, at most `LOCAL_CORE_CAP` on a shared box, and
|
|
2
|
+
// fewer while other sessions' runnable tasks already fill the machine. Oversubscribed cores do not
|
|
3
|
+
// finish work sooner; they turn timing-sensitive tests red.
|
|
4
|
+
|
|
5
|
+
// why: Bun ships no synchronous file read for `/proc/loadavg`.
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
// why: Bun exposes no available-parallelism primitive.
|
|
8
|
+
import { availableParallelism } from 'node:os';
|
|
9
|
+
import type { HeavyEnv } from './heavy-env';
|
|
10
|
+
import { HEAVY_CORES_ENV, isCi } from './heavy-env';
|
|
11
|
+
|
|
12
|
+
export const LOCAL_CORE_CAP = 4;
|
|
13
|
+
/** A busy machine still gets this much, or one run behind a burst never makes progress. */
|
|
14
|
+
export const BUSY_CORE_FLOOR = 2;
|
|
15
|
+
|
|
16
|
+
/** The instantaneous runnable count: `/proc/loadavg`'s `running/total`. The load average lags. */
|
|
17
|
+
export function parseRunnable(loadavg: string): number | undefined {
|
|
18
|
+
const match = /^\S+\s+\S+\s+\S+\s+(\d+)\/\d+\s/.exec(loadavg);
|
|
19
|
+
return match === null ? undefined : Number(match[1]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Runnable tasks now, this reader excluded; 0 where the kernel does not report them. */
|
|
23
|
+
export function runnableTasks(read: () => string = () => readFileSync('/proc/loadavg', 'utf8')) {
|
|
24
|
+
try {
|
|
25
|
+
return Math.max(0, (parseRunnable(read()) ?? 1) - 1);
|
|
26
|
+
} catch {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `undefined` means no ceiling: a CI runner, whose every core is this run's. */
|
|
32
|
+
export function coreCap(
|
|
33
|
+
env: HeavyEnv,
|
|
34
|
+
cores: number = availableParallelism(),
|
|
35
|
+
runnable: number = runnableTasks(),
|
|
36
|
+
): number | undefined {
|
|
37
|
+
const raw = Number(env[HEAVY_CORES_ENV]);
|
|
38
|
+
if (Number.isInteger(raw) && raw > 0) return raw;
|
|
39
|
+
if (isCi(env)) return undefined;
|
|
40
|
+
const ceiling = Math.min(LOCAL_CORE_CAP, Math.max(1, cores));
|
|
41
|
+
return Math.min(ceiling, Math.max(BUSY_CORE_FLOOR, cores - runnable));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Thread caps for the native tools: tsc is Go, biome is rayon. An exported value wins. */
|
|
45
|
+
export function nativeToolEnv(env: HeavyEnv, cap: number | undefined): Record<string, string> {
|
|
46
|
+
if (cap === undefined) return {};
|
|
47
|
+
return {
|
|
48
|
+
...(env['GOMAXPROCS'] === undefined ? { GOMAXPROCS: String(cap) } : {}),
|
|
49
|
+
...(env['RAYON_NUM_THREADS'] === undefined ? { RAYON_NUM_THREADS: String(cap) } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
package/src/heavy-env.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Every environment variable the machine ledger reads or sets, and the one reading of `CI`. A leaf:
|
|
2
|
+
// the worker planner and the error classes need these names without loading the ledger.
|
|
3
|
+
|
|
4
|
+
export type HeavyEnv = Readonly<Record<string, string | undefined>>;
|
|
5
|
+
|
|
6
|
+
/** The ledger's directory. Set by a test or an unusual machine; also opts a test run back in. */
|
|
7
|
+
export const HEAVY_DIR_ENV = 'ULTIMATE_HEAVY_DIR';
|
|
8
|
+
/** What the ledger admits in total (`8g`), replacing half of RAM. `0` turns it off. */
|
|
9
|
+
export const HEAVY_MEMORY_ENV = 'ULTIMATE_HEAVY_MEMORY';
|
|
10
|
+
/** The local core ceiling, replacing `LOCAL_CORE_CAP`. */
|
|
11
|
+
export const HEAVY_CORES_ENV = 'ULTIMATE_HEAVY_CORES';
|
|
12
|
+
/** Set on a holder's children: the reservation file they run inside. A protocol, not a knob. */
|
|
13
|
+
export const HEAVY_HOLD_ENV = 'ULTIMATE_HEAVY_HOLD';
|
|
14
|
+
|
|
15
|
+
/** A CI runner is single-tenant: nothing to queue behind, and every core is the run's. */
|
|
16
|
+
export const isCi = (env: HeavyEnv): boolean => {
|
|
17
|
+
const value = env['CI'];
|
|
18
|
+
return value !== undefined && value !== '' && value !== '0' && value !== 'false';
|
|
19
|
+
};
|