@orkestrel/scaffold 0.0.133 → 0.0.135
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/dist/agents/skills/orkestrel-dispatch/scripts/bench.js +61 -96
- package/dist/agents/skills/orkestrel-dispatch/scripts/brief.js +48 -76
- package/dist/agents/skills/orkestrel-dispatch/scripts/chain.js +27 -66
- package/dist/agents/skills/orkestrel-dispatch/scripts/cite.js +31 -64
- package/dist/agents/skills/orkestrel-dispatch/scripts/launch.js +43 -57
- package/dist/agents/skills/orkestrel-dispatch/scripts/login.js +43 -86
- package/dist/agents/skills/orkestrel-dispatch/scripts/patch.js +68 -104
- package/dist/agents/skills/orkestrel-dispatch/scripts/result.js +35 -69
- package/dist/agents/skills/orkestrel-dispatch/scripts/sweep.js +47 -84
- package/dist/agents/skills/orkestrel-falsify/scripts/mutate.js +134 -116
- package/dist/agents/skills/orkestrel-harden/scripts/discovery.js +38 -90
- package/dist/agents/skills/orkestrel-harden/scripts/interleave.js +39 -103
- package/dist/agents/skills/orkestrel-harden/scripts/measure.js +40 -89
- package/dist/agents/skills/orkestrel-harden/scripts/titles.js +41 -87
- package/dist/agents/skills/orkestrel-parallel/scripts/cases.js +43 -88
- package/dist/agents/skills/orkestrel-parallel/scripts/lane.js +1568 -213
- package/dist/agents/skills/orkestrel-publish/scripts/compare.js +40 -60
- package/dist/agents/skills/orkestrel-publish/scripts/pins.js +47 -81
- package/dist/agents/skills/orkestrel-publish/scripts/steps.js +66 -104
- package/dist/agents/skills/orkestrel-publish/scripts/swap.js +74 -88
- package/dist/agents/skills/orkestrel-publish/scripts/wave.js +387 -109
- package/dist/agents/skills/orkestrel-publish/scripts/window.js +55 -96
- package/dist/agents/skills/orkestrel-scout/scripts/map.js +54 -101
- package/dist/bin/main.js +275 -33
- package/dist/bin/main.js.map +1 -1
- package/dist/host/AGENTS.md +1 -1
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/bench.ts +81 -97
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/brief.ts +64 -72
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/chain.ts +41 -63
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/cite.ts +56 -79
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/launch.ts +61 -74
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/login.ts +59 -89
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/patch.ts +87 -106
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/result.ts +57 -76
- package/dist/host/agents/skills/orkestrel-dispatch/scripts/sweep.ts +73 -88
- package/dist/host/agents/skills/orkestrel-falsify/SKILL.md +2 -2
- package/dist/host/agents/skills/orkestrel-falsify/scripts/mutate.ts +167 -119
- package/dist/host/agents/skills/orkestrel-harden/references/methods.md +1 -1
- package/dist/host/agents/skills/orkestrel-harden/scripts/discovery.ts +58 -75
- package/dist/host/agents/skills/orkestrel-harden/scripts/interleave.ts +55 -99
- package/dist/host/agents/skills/orkestrel-harden/scripts/measure.ts +59 -90
- package/dist/host/agents/skills/orkestrel-harden/scripts/titles.ts +60 -80
- package/dist/host/agents/skills/orkestrel-parallel/SKILL.md +4 -4
- package/dist/host/agents/skills/orkestrel-parallel/scripts/cases.ts +71 -108
- package/dist/host/agents/skills/orkestrel-parallel/scripts/lane.ts +1990 -274
- package/dist/host/agents/skills/orkestrel-publish/references/release.md +1 -0
- package/dist/host/agents/skills/orkestrel-publish/references/wave.md +28 -7
- package/dist/host/agents/skills/orkestrel-publish/scripts/compare.ts +58 -79
- package/dist/host/agents/skills/orkestrel-publish/scripts/pins.ts +66 -87
- package/dist/host/agents/skills/orkestrel-publish/scripts/steps.ts +84 -102
- package/dist/host/agents/skills/orkestrel-publish/scripts/swap.ts +92 -99
- package/dist/host/agents/skills/orkestrel-publish/scripts/wave.ts +483 -127
- package/dist/host/agents/skills/orkestrel-publish/scripts/window.ts +82 -120
- package/dist/host/agents/skills/orkestrel-scout/SKILL.md +3 -3
- package/dist/host/agents/skills/orkestrel-scout/scripts/map.ts +85 -112
- package/dist/host/claude/agents/orkestrel.md +16 -16
- package/dist/host/claude/rules/architecture.md +1 -1
- package/dist/host/claude/rules/documentation.md +1 -1
- package/dist/host/claude/rules/patterns.md +7 -4
- package/dist/host/claude/rules/styles.md +1 -1
- package/dist/host/claude/rules/tests.md +3 -3
- package/dist/host/claude/rules/workspace.md +50 -37
- package/dist/host/configs/helpers.ts +117 -71
- package/dist/host/dotfiles/oxlintrc.json +6 -0
- package/dist/host/guides/agent.md +989 -395
- package/dist/host/guides/database.md +357 -342
- package/dist/host/guides/form.md +79 -4
- package/dist/host/guides/middleware.md +5 -5
- package/dist/host/guides/ollama.md +41 -42
- package/dist/host/guides/scaffold.md +170 -70
- package/dist/host/guides/study.md +12 -12
- package/dist/host/guides/table.md +20 -6
- package/dist/host/guides/test.md +166 -52
- package/dist/host/guides/toolbox.md +127 -81
- package/dist/host/guides/workspace.md +21 -14
- package/dist/host/manifest.json +54 -54
- package/dist/host/tests/config.test.ts +251 -7
- package/dist/host/tests/policy.test.ts +14 -21
- package/dist/host/tests/setupPolicy.ts +43 -36
- package/dist/src/core/index.cjs +533 -139
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +223 -16
- package/dist/src/core/index.d.ts +223 -16
- package/dist/src/core/index.js +524 -139
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +23 -14
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +3 -2
- package/dist/src/server/index.d.ts +3 -2
- package/dist/src/server/index.js +24 -15
- package/dist/src/server/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -3,6 +3,7 @@ import { createHash } from 'node:crypto';
|
|
|
3
3
|
import { copyFileSync, existsSync, lstatSync, readFileSync, mkdirSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
4
4
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
6
7
|
/** Lists the steps of a visit in the order they run. */
|
|
7
8
|
export const STEPS = [
|
|
8
9
|
'pin',
|
|
@@ -66,23 +67,43 @@ export const PINS = fileURLToPath(new URL(`./pins${EXTENSION}`, import.meta.url)
|
|
|
66
67
|
* group holds a rename's new path, the second its original, and the third any other entry's path.
|
|
67
68
|
*/
|
|
68
69
|
export const DIRTY_ENTRY = /(?=[RC][^\0]|[^\0][RC])[^\0]{2} ([^\0]*)\0([^\0]*)(?:\0|$)|[^\0]{2} ([^\0]*)(?:\0|$)/gu;
|
|
69
|
-
/** Lists every flag the script reads, value flags and switches alike. */
|
|
70
|
-
export const FLAGS = [
|
|
71
|
-
'--visit',
|
|
72
|
-
'--plan',
|
|
73
|
-
'--target',
|
|
74
|
-
'--offline',
|
|
75
|
-
'--regenerate',
|
|
76
|
-
'--from',
|
|
77
|
-
'--to',
|
|
78
|
-
'--prior',
|
|
79
|
-
'--dry-run',
|
|
80
|
-
'--json',
|
|
81
|
-
'--out',
|
|
82
|
-
'--catalog',
|
|
83
|
-
];
|
|
84
70
|
/** Holds the usage line the script prints when no mode was given. */
|
|
85
71
|
export const USAGE = 'usage: wave.ts --visit [--target DIR] [--offline] [--regenerate] [--from STEP] [--to STEP] [--prior VERSION] [--dry-run] [--json] [--out FILE] | --plan [--catalog PATH] [--json]';
|
|
72
|
+
/** Declares every flag the script reads, for `parseArgs`. */
|
|
73
|
+
export const OPTIONS = Object.freeze({
|
|
74
|
+
visit: Object.freeze({ type: 'boolean' }),
|
|
75
|
+
plan: Object.freeze({ type: 'boolean' }),
|
|
76
|
+
target: Object.freeze({ type: 'string' }),
|
|
77
|
+
offline: Object.freeze({ type: 'boolean' }),
|
|
78
|
+
regenerate: Object.freeze({ type: 'boolean' }),
|
|
79
|
+
from: Object.freeze({ type: 'string' }),
|
|
80
|
+
to: Object.freeze({ type: 'string' }),
|
|
81
|
+
prior: Object.freeze({ type: 'string' }),
|
|
82
|
+
'dry-run': Object.freeze({ type: 'boolean' }),
|
|
83
|
+
json: Object.freeze({ type: 'boolean' }),
|
|
84
|
+
out: Object.freeze({ type: 'string' }),
|
|
85
|
+
catalog: Object.freeze({ type: 'string' }),
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Parses the arguments in strict mode against `OPTIONS`.
|
|
89
|
+
*
|
|
90
|
+
* @param argv - The arguments after the script path.
|
|
91
|
+
* @returns The values and positionals, or the message `parseArgs` refused the arguments with.
|
|
92
|
+
*/
|
|
93
|
+
export function parseArguments(argv) {
|
|
94
|
+
try {
|
|
95
|
+
const { values, positionals } = parseArgs({
|
|
96
|
+
args: [...argv],
|
|
97
|
+
options: OPTIONS,
|
|
98
|
+
strict: true,
|
|
99
|
+
allowPositionals: false,
|
|
100
|
+
});
|
|
101
|
+
return { success: true, value: { values, positionals } };
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
86
107
|
/** Names the manifest fields that hold specs, including nested overrides. */
|
|
87
108
|
export const SPEC_FIELDS = Object.freeze([
|
|
88
109
|
'dependencies',
|
|
@@ -157,49 +178,7 @@ export function removeTree(path) {
|
|
|
157
178
|
* @returns The same path with every backslash replaced by a slash.
|
|
158
179
|
*/
|
|
159
180
|
export function normalizeSlashes(path) {
|
|
160
|
-
return path.
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Reads the value that follows a flag.
|
|
164
|
-
*
|
|
165
|
-
* @remarks
|
|
166
|
-
* Reads `--flag value` pairs: the first occurrence of a flag wins, a following value that opens
|
|
167
|
-
* with `--` is a missing value, and the `--flag=value` form is not read.
|
|
168
|
-
*
|
|
169
|
-
* @param argv - The arguments after the script path.
|
|
170
|
-
* @param name - The flag, such as `--target`.
|
|
171
|
-
* @returns The value after the flag, or undefined when the flag is absent, last, or followed by
|
|
172
|
-
* another flag.
|
|
173
|
-
*/
|
|
174
|
-
export function readOption(argv, name) {
|
|
175
|
-
const index = argv.indexOf(name);
|
|
176
|
-
const value = index === -1 ? undefined : argv[index + 1];
|
|
177
|
-
return value === undefined || value.startsWith('--') ? undefined : value;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Names the value flags a caller gave with no value.
|
|
181
|
-
*
|
|
182
|
-
* @param argv - The arguments after the script path.
|
|
183
|
-
* @param names - The flags that take a value.
|
|
184
|
-
* @returns Each named flag that appears last or is followed by another flag, in argument order.
|
|
185
|
-
*/
|
|
186
|
-
export function readMissingFlags(argv, names) {
|
|
187
|
-
return names.filter((name) => argv.includes(name) && readOption(argv, name) === undefined);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Names the flags a caller gave that the script does not read.
|
|
191
|
-
*
|
|
192
|
-
* @remarks
|
|
193
|
-
* Reads the arguments before a bare `--`, which opens a command a script passes on. A `--flag=value`
|
|
194
|
-
* argument is unknown, because the script reads no such form.
|
|
195
|
-
*
|
|
196
|
-
* @param argv - The arguments after the script path.
|
|
197
|
-
* @param flags - Every flag the script reads, value flags and switches alike.
|
|
198
|
-
* @returns Each argument that opens with `--` and is not a read flag, in argument order.
|
|
199
|
-
*/
|
|
200
|
-
export function readUnknownFlags(argv, flags) {
|
|
201
|
-
const end = argv.indexOf('--');
|
|
202
|
-
return (end === -1 ? argv : argv.slice(0, end)).filter((argument) => argument.startsWith('--') && !flags.includes(argument));
|
|
181
|
+
return path.replaceAll('\\', '/');
|
|
203
182
|
}
|
|
204
183
|
/**
|
|
205
184
|
* Reads the last non-empty line of a text as a JSON object.
|
|
@@ -1129,6 +1108,234 @@ export function runFormat(runner) {
|
|
|
1129
1108
|
version,
|
|
1130
1109
|
};
|
|
1131
1110
|
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Parses a whole text as one JSON object or a list of JSON objects.
|
|
1113
|
+
*
|
|
1114
|
+
* @param text - A JSON document, such as `npm view NAME@RANGE FIELD --json` output, which prints one
|
|
1115
|
+
* record for one match and a list for several.
|
|
1116
|
+
* @returns Each object the document carries, or none when the text is not JSON.
|
|
1117
|
+
*/
|
|
1118
|
+
export function parseJsonRecords(text) {
|
|
1119
|
+
try {
|
|
1120
|
+
const parsed = JSON.parse(text);
|
|
1121
|
+
return (Array.isArray(parsed) ? parsed : [parsed])
|
|
1122
|
+
.filter(isRecord)
|
|
1123
|
+
.map((entry) => Object.fromEntries(Object.entries(entry)));
|
|
1124
|
+
}
|
|
1125
|
+
catch {
|
|
1126
|
+
return [];
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Parses the major, minor, and patch numbers of a plain `major.minor.patch` version.
|
|
1131
|
+
*
|
|
1132
|
+
* @param text - The version text.
|
|
1133
|
+
* @returns The three numbers, or undefined when the text carries a prefix, a prerelease, or any
|
|
1134
|
+
* other form.
|
|
1135
|
+
* @example
|
|
1136
|
+
* ```ts
|
|
1137
|
+
* parseVersion('8.3.8') // [8, 3, 8]
|
|
1138
|
+
* parseVersion('8.3.8-beta.1') // undefined
|
|
1139
|
+
* ```
|
|
1140
|
+
*/
|
|
1141
|
+
export function parseVersion(text) {
|
|
1142
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u.exec(text);
|
|
1143
|
+
if (match === null)
|
|
1144
|
+
return undefined;
|
|
1145
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Compares two plain versions by their major, minor, and patch numbers.
|
|
1149
|
+
*
|
|
1150
|
+
* @param left - The version ordered first when it compares lower.
|
|
1151
|
+
* @param right - The version it is compared with.
|
|
1152
|
+
* @returns A negative number when `left` is lower, zero when equal, and a positive number when higher.
|
|
1153
|
+
* @example
|
|
1154
|
+
* ```ts
|
|
1155
|
+
* compareVersions([0, 0, 23], [0, 0, 24]) // -1
|
|
1156
|
+
* ```
|
|
1157
|
+
*/
|
|
1158
|
+
export function compareVersions(left, right) {
|
|
1159
|
+
return left[0] - right[0] || left[1] - right[1] || left[2] - right[2];
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Parses a declared range as the half-open version intervals its `||` arms admit.
|
|
1163
|
+
*
|
|
1164
|
+
* @remarks
|
|
1165
|
+
* An arm is an exact `major.minor.patch` version, a caret, or a tilde over one. A caret admits up to
|
|
1166
|
+
* the next major, the next minor under major 0, and the next patch under `0.0`; a tilde admits up to
|
|
1167
|
+
* the next minor. Any other form, an empty arm included, makes the whole range unreadable.
|
|
1168
|
+
*
|
|
1169
|
+
* @param range - The declared range.
|
|
1170
|
+
* @returns One interval per arm, with an inclusive `floor` and an exclusive `ceiling`, or undefined
|
|
1171
|
+
* when an arm is outside those forms.
|
|
1172
|
+
* @example
|
|
1173
|
+
* ```ts
|
|
1174
|
+
* parseRange('^0.0.23') // [{ floor: [0, 0, 23], ceiling: [0, 0, 24] }]
|
|
1175
|
+
* parseRange('>=8') // undefined
|
|
1176
|
+
* ```
|
|
1177
|
+
*/
|
|
1178
|
+
export function parseRange(range) {
|
|
1179
|
+
const arms = range.trim().split(/\s*\|\|\s*/u);
|
|
1180
|
+
const parsed = arms.flatMap((arm) => {
|
|
1181
|
+
const match = /^([\^~]?)(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u.exec(arm);
|
|
1182
|
+
if (match === null)
|
|
1183
|
+
return [];
|
|
1184
|
+
const major = Number(match[2]);
|
|
1185
|
+
const minor = Number(match[3]);
|
|
1186
|
+
const patch = Number(match[4]);
|
|
1187
|
+
const ceiling = match[1] === '~'
|
|
1188
|
+
? [major, minor + 1, 0]
|
|
1189
|
+
: match[1] === ''
|
|
1190
|
+
? [major, minor, patch + 1]
|
|
1191
|
+
: major > 0
|
|
1192
|
+
? [major + 1, 0, 0]
|
|
1193
|
+
: minor > 0
|
|
1194
|
+
? [0, minor + 1, 0]
|
|
1195
|
+
: [0, 0, patch + 1];
|
|
1196
|
+
return [{ floor: [major, minor, patch], ceiling }];
|
|
1197
|
+
});
|
|
1198
|
+
return parsed.length === arms.length ? parsed : undefined;
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Computes whether a declared range admits a plain version.
|
|
1202
|
+
*
|
|
1203
|
+
* @param range - The declared range, in a form {@link parseRange} reads.
|
|
1204
|
+
* @param version - The plain version.
|
|
1205
|
+
* @returns True if an arm admits the version, false if none does, and undefined when the range or
|
|
1206
|
+
* the version is unreadable.
|
|
1207
|
+
* @example
|
|
1208
|
+
* ```ts
|
|
1209
|
+
* computeSatisfaction('^8.3.7', '8.3.8') // true
|
|
1210
|
+
* computeSatisfaction('^0.0.23', '0.0.24') // false
|
|
1211
|
+
* computeSatisfaction('*', '1.0.0') // undefined
|
|
1212
|
+
* ```
|
|
1213
|
+
*/
|
|
1214
|
+
export function computeSatisfaction(range, version) {
|
|
1215
|
+
const arms = parseRange(range);
|
|
1216
|
+
const parsed = parseVersion(version);
|
|
1217
|
+
if (arms === undefined || parsed === undefined)
|
|
1218
|
+
return undefined;
|
|
1219
|
+
return arms.some((arm) => compareVersions(arm.floor, parsed) <= 0 && compareVersions(parsed, arm.ceiling) < 0);
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Raises one declared peer range whose floor fails the served release, and words the decision.
|
|
1223
|
+
*
|
|
1224
|
+
* @remarks
|
|
1225
|
+
* A range the served version satisfies stays as declared. A failing range moves per
|
|
1226
|
+
* {@link moveRange}: the one arm in the release's major becomes the caret of the release. A range
|
|
1227
|
+
* that is unreadable, carries no arm or several arms in that major, or whose arm in that major opens
|
|
1228
|
+
* above the release stays as declared, and the message names why. A reading that names the peer and
|
|
1229
|
+
* carries no release keeps it as `no eligible release`; no reading keeps it as `no release reading`.
|
|
1230
|
+
*
|
|
1231
|
+
* @param name - The peer's package name.
|
|
1232
|
+
* @param range - The declared peer range.
|
|
1233
|
+
* @param reading - The release reading that names the peer, or undefined when none does.
|
|
1234
|
+
* @returns The range after the decision and the rewrite row message: `peer NAME OLD -> NEW` when it
|
|
1235
|
+
* rose, `peer NAME OLD kept, REASON` otherwise.
|
|
1236
|
+
* @example
|
|
1237
|
+
* ```ts
|
|
1238
|
+
* raisePeer('@orkestrel/database', '^0.0.23', { name: '@orkestrel/database', range: '*', latest: '0.0.24' })
|
|
1239
|
+
* // { range: '^0.0.24', message: 'peer @orkestrel/database ^0.0.23 -> ^0.0.24', raised: true }
|
|
1240
|
+
* ```
|
|
1241
|
+
*/
|
|
1242
|
+
export function raisePeer(name, range, reading) {
|
|
1243
|
+
const arms = parseRange(range);
|
|
1244
|
+
const latest = reading?.latest;
|
|
1245
|
+
const version = latest === undefined ? undefined : parseVersion(latest);
|
|
1246
|
+
const matched = version === undefined ? [] : (arms ?? []).filter((entry) => entry.floor[0] === version[0]);
|
|
1247
|
+
const reason = arms === undefined
|
|
1248
|
+
? 'unreadable range'
|
|
1249
|
+
: reading === undefined
|
|
1250
|
+
? 'no release reading'
|
|
1251
|
+
: latest === undefined
|
|
1252
|
+
? 'no eligible release'
|
|
1253
|
+
: version === undefined
|
|
1254
|
+
? `unreadable release ${latest}`
|
|
1255
|
+
: computeSatisfaction(range, latest) === true
|
|
1256
|
+
? `admits ${latest}`
|
|
1257
|
+
: matched.length === 0
|
|
1258
|
+
? `no arm in the major of ${latest}`
|
|
1259
|
+
: matched.length > 1
|
|
1260
|
+
? `several arms in the major of ${latest}`
|
|
1261
|
+
: matched.some((arm) => compareVersions(arm.floor, version) > 0)
|
|
1262
|
+
? `its floor is above ${latest}`
|
|
1263
|
+
: undefined;
|
|
1264
|
+
if (reason !== undefined || latest === undefined)
|
|
1265
|
+
return { range, message: `peer ${name} ${range} kept, ${String(reason)}`, raised: false };
|
|
1266
|
+
const next = String(moveRange(range, latest));
|
|
1267
|
+
return { range: next, message: `peer ${name} ${range} -> ${next}`, raised: true };
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Collects the registry lookup each peer-only dependency needs for its release reading.
|
|
1271
|
+
*
|
|
1272
|
+
* @remarks
|
|
1273
|
+
* A peer a release reading already names, such as one also declared under `devDependencies`, takes
|
|
1274
|
+
* that reading. A peer whose range {@link parseRange} cannot read needs no reading. A fleet package
|
|
1275
|
+
* is looked up with `*`, and a foreign tool with a caret over its declared major, or with the
|
|
1276
|
+
* declared range when its arms span several majors, as the audit bounds a dependency. A range bound
|
|
1277
|
+
* by itself admits every release its lookup serves, so such a peer never rises.
|
|
1278
|
+
*
|
|
1279
|
+
* @param manifest - The manifest record.
|
|
1280
|
+
* @param releases - The audit's release readings.
|
|
1281
|
+
* @returns One lookup per peer-only dependency, in declaration order.
|
|
1282
|
+
* @example
|
|
1283
|
+
* ```ts
|
|
1284
|
+
* collectPeerLookups({ peerDependencies: { vite: '^8.3.7' } }, [])
|
|
1285
|
+
* // [{ name: 'vite', bound: '^8' }]
|
|
1286
|
+
* ```
|
|
1287
|
+
*/
|
|
1288
|
+
export function collectPeerLookups(manifest, releases) {
|
|
1289
|
+
const named = new Set(releases.map((release) => release.name));
|
|
1290
|
+
const block = manifest.peerDependencies;
|
|
1291
|
+
if (typeof block !== 'object' || block === null)
|
|
1292
|
+
return [];
|
|
1293
|
+
return Object.entries(block).flatMap(([name, range]) => {
|
|
1294
|
+
if (typeof range !== 'string' || named.has(name))
|
|
1295
|
+
return [];
|
|
1296
|
+
const majors = [...new Set(parseRange(range)?.map((arm) => arm.floor[0]))];
|
|
1297
|
+
if (majors.length === 0)
|
|
1298
|
+
return [];
|
|
1299
|
+
const bound = name.startsWith('@orkestrel/')
|
|
1300
|
+
? '*'
|
|
1301
|
+
: majors.length === 1
|
|
1302
|
+
? `^${String(majors[0])}`
|
|
1303
|
+
: range;
|
|
1304
|
+
return [{ name, bound }];
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Reads the release a registry lookup serves out of the output of
|
|
1309
|
+
* `npm view NAME@BOUND version deprecated dist-tags.latest --json`.
|
|
1310
|
+
*
|
|
1311
|
+
* @remarks
|
|
1312
|
+
* The reading skips a deprecated version, a version outside the plain `major.minor.patch` form, and
|
|
1313
|
+
* a version above `latest` when the bound is `*` or the caret of `latest`'s major, then takes the
|
|
1314
|
+
* highest, as the audit's lookup does.
|
|
1315
|
+
*
|
|
1316
|
+
* @param text - The command's standard output.
|
|
1317
|
+
* @param bound - The lookup bound.
|
|
1318
|
+
* @returns The served version, or undefined when no version is eligible or the output is unreadable.
|
|
1319
|
+
* @example
|
|
1320
|
+
* ```ts
|
|
1321
|
+
* readServedVersion('{"version":"0.0.24","dist-tags.latest":"0.0.24"}', '*') // '0.0.24'
|
|
1322
|
+
* ```
|
|
1323
|
+
*/
|
|
1324
|
+
export function readServedVersion(text, bound) {
|
|
1325
|
+
const eligible = parseJsonRecords(text).flatMap((entry) => {
|
|
1326
|
+
const version = readString(entry, 'version') ?? '';
|
|
1327
|
+
const plain = parseVersion(version);
|
|
1328
|
+
const deprecated = readString(entry, 'deprecated') ?? '';
|
|
1329
|
+
const latest = parseVersion(readString(entry, 'dist-tags.latest') ?? '');
|
|
1330
|
+
if (plain === undefined || deprecated.length > 0)
|
|
1331
|
+
return [];
|
|
1332
|
+
const capped = latest !== undefined && (bound === '*' || bound === `^${String(latest[0])}`)
|
|
1333
|
+
? compareVersions(plain, latest) <= 0
|
|
1334
|
+
: true;
|
|
1335
|
+
return capped ? [{ version, plain }] : [];
|
|
1336
|
+
});
|
|
1337
|
+
return eligible.toSorted((left, right) => compareVersions(right.plain, left.plain))[0]?.version;
|
|
1338
|
+
}
|
|
1132
1339
|
/**
|
|
1133
1340
|
* Moves one declared range to the registry caret of a release, keeping every other major a
|
|
1134
1341
|
* disjunctive range admits.
|
|
@@ -1185,35 +1392,96 @@ export function computeRanges(ranges, releases) {
|
|
|
1185
1392
|
}, { ranges, moved: [] });
|
|
1186
1393
|
}
|
|
1187
1394
|
/**
|
|
1188
|
-
* Writes the re-pinned ranges into the target's manifest
|
|
1395
|
+
* Writes the re-pinned ranges into the target's manifest, raising each peer range whose floor fails
|
|
1396
|
+
* its release.
|
|
1397
|
+
*
|
|
1398
|
+
* @remarks
|
|
1399
|
+
* A `dependencies` or `devDependencies` range moves per {@link computeRanges} over the audit's
|
|
1400
|
+
* readings alone. A `peerDependencies` range takes the last audit reading that names it with a
|
|
1401
|
+
* release, else its peer-only reading, and moves per {@link raisePeer}: it rises to the caret of the
|
|
1402
|
+
* served version only when the declared range excludes that version, and otherwise stays as
|
|
1403
|
+
* declared. Every raised peer joins the moved list and every other peer is reported as kept.
|
|
1189
1404
|
*
|
|
1190
1405
|
* @param target - The target directory.
|
|
1191
1406
|
* @param releases - The audit's release readings.
|
|
1192
|
-
* @
|
|
1407
|
+
* @param peers - The peer-only readings, which move `peerDependencies` ranges alone. Default: none.
|
|
1408
|
+
* @returns One message per range moved and one per peer range kept; the manifest is rewritten only
|
|
1409
|
+
* when a range moved.
|
|
1410
|
+
* @example
|
|
1411
|
+
* ```ts
|
|
1412
|
+
* writeRanges('.', [{ name: 'vite', range: '^8', latest: '8.3.8' }])
|
|
1413
|
+
* // { moved: ['vite ^8.3.7 -> ^8.3.8'], kept: ['peer vite ^8.3.7 kept, admits 8.3.8'] }
|
|
1414
|
+
* ```
|
|
1193
1415
|
*/
|
|
1194
|
-
export function writeRanges(target, releases) {
|
|
1416
|
+
export function writeRanges(target, releases, peers = []) {
|
|
1195
1417
|
const manifest = readManifest(target);
|
|
1196
1418
|
if (manifest === undefined)
|
|
1197
|
-
return [];
|
|
1419
|
+
return { moved: [], kept: [] };
|
|
1198
1420
|
const fields = RANGE_FIELDS.flatMap((field) => {
|
|
1199
1421
|
const block = manifest[field];
|
|
1200
1422
|
if (typeof block !== 'object' || block === null)
|
|
1201
1423
|
return [];
|
|
1202
|
-
|
|
1424
|
+
const ranges = Object.fromEntries(Object.entries(block));
|
|
1425
|
+
if (field !== 'peerDependencies')
|
|
1426
|
+
return [{ field, moves: computeRanges(ranges, releases), kept: [] }];
|
|
1427
|
+
const decisions = Object.entries(ranges).flatMap(([name, range]) => typeof range === 'string'
|
|
1428
|
+
? [
|
|
1429
|
+
[
|
|
1430
|
+
name,
|
|
1431
|
+
raisePeer(name, range, releases.findLast((release) => release.name === name && release.latest !== undefined) ?? peers.findLast((release) => release.name === name)),
|
|
1432
|
+
],
|
|
1433
|
+
]
|
|
1434
|
+
: []);
|
|
1435
|
+
return [
|
|
1436
|
+
{
|
|
1437
|
+
field,
|
|
1438
|
+
moves: {
|
|
1439
|
+
ranges: {
|
|
1440
|
+
...ranges,
|
|
1441
|
+
...Object.fromEntries(decisions.map(([name, peer]) => [name, peer.range])),
|
|
1442
|
+
},
|
|
1443
|
+
moved: decisions.flatMap(([, peer]) => (peer.raised ? [peer.message] : [])),
|
|
1444
|
+
},
|
|
1445
|
+
kept: decisions.flatMap(([, peer]) => (peer.raised ? [] : [peer.message])),
|
|
1446
|
+
},
|
|
1447
|
+
];
|
|
1203
1448
|
});
|
|
1204
|
-
const moved = fields.flatMap((entry) => entry.moved);
|
|
1449
|
+
const moved = fields.flatMap((entry) => entry.moves.moved);
|
|
1205
1450
|
if (moved.length > 0) {
|
|
1206
1451
|
const written = {
|
|
1207
1452
|
...manifest,
|
|
1208
|
-
...Object.fromEntries(fields.map((entry) => [entry.field, entry.ranges])),
|
|
1453
|
+
...Object.fromEntries(fields.map((entry) => [entry.field, entry.moves.ranges])),
|
|
1209
1454
|
};
|
|
1210
1455
|
writeFileSync(join(target, 'package.json'), `${JSON.stringify(written, null, '\t')}\n`);
|
|
1211
1456
|
}
|
|
1212
|
-
return moved;
|
|
1457
|
+
return { moved, kept: fields.flatMap((entry) => entry.kept) };
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Judges one peer-only release lookup.
|
|
1461
|
+
*
|
|
1462
|
+
* @param result - The `npm view NAME@BOUND version deprecated dist-tags.latest --json` command.
|
|
1463
|
+
* @param bound - The lookup bound.
|
|
1464
|
+
* @returns Exit 0 naming the served version, or naming that no release within the bound is
|
|
1465
|
+
* eligible, when the lookup exited 0; else the lookup's failing exit and its reason.
|
|
1466
|
+
*/
|
|
1467
|
+
export function judgeLookup(result, bound) {
|
|
1468
|
+
if (result.status !== 0)
|
|
1469
|
+
return readVerdict(result);
|
|
1470
|
+
const served = readServedVersion(result.stdout, bound);
|
|
1471
|
+
return {
|
|
1472
|
+
exit: 0,
|
|
1473
|
+
note: served === undefined ? `no eligible release within ${bound}` : `serves ${served}`,
|
|
1474
|
+
};
|
|
1213
1475
|
}
|
|
1214
1476
|
/**
|
|
1215
1477
|
* Runs the pin step.
|
|
1216
1478
|
*
|
|
1479
|
+
* @remarks
|
|
1480
|
+
* A peer-only dependency produces no audit release reading, so the step looks each one up with
|
|
1481
|
+
* `npm view`, per {@link collectPeerLookups}, before the rewrite, and stops before the rewrite and
|
|
1482
|
+
* the install when a lookup exits non-zero. A lookup that exits 0 with no eligible release keeps
|
|
1483
|
+
* its peer. Offline, it looks up none and the rewrite keeps those peers as declared.
|
|
1484
|
+
*
|
|
1217
1485
|
* @param runner - The visit's state.
|
|
1218
1486
|
* @param scaffoldFile - The scaffold executable.
|
|
1219
1487
|
* @param scaffoldPrefix - The arguments that precede scaffold's own.
|
|
@@ -1226,8 +1494,27 @@ export function runPin(runner, scaffoldFile, scaffoldPrefix, offline) {
|
|
|
1226
1494
|
const releases = readReleases(audit.stdout);
|
|
1227
1495
|
if (releases === undefined || (audit.status !== 0 && audit.status !== 1))
|
|
1228
1496
|
return;
|
|
1229
|
-
const
|
|
1230
|
-
|
|
1497
|
+
const lookups = collectPeerLookups(readManifest(runner.target) ?? {}, releases);
|
|
1498
|
+
if (runner.offline && lookups.length > 0)
|
|
1499
|
+
appendStep(runner, 'pin', 'npm view', `offline: no peer-only lookup for ${lookups.map((lookup) => lookup.name).join(', ')}`);
|
|
1500
|
+
const readings = (runner.offline ? [] : lookups).map((lookup) => {
|
|
1501
|
+
const view = runNpmStep(runner, 'pin', [
|
|
1502
|
+
'view',
|
|
1503
|
+
`${lookup.name}@${lookup.bound}`,
|
|
1504
|
+
'version',
|
|
1505
|
+
'deprecated',
|
|
1506
|
+
'dist-tags.latest',
|
|
1507
|
+
'--json',
|
|
1508
|
+
], (result) => judgeLookup(result, lookup.bound));
|
|
1509
|
+
if (view?.status !== 0)
|
|
1510
|
+
return undefined;
|
|
1511
|
+
const latest = readServedVersion(view.stdout, lookup.bound);
|
|
1512
|
+
return { name: lookup.name, range: lookup.bound, latest };
|
|
1513
|
+
});
|
|
1514
|
+
if (readings.includes(undefined))
|
|
1515
|
+
return;
|
|
1516
|
+
const { moved, kept } = writeRanges(runner.target, releases, readings.filter((reading) => reading !== undefined));
|
|
1517
|
+
appendStep(runner, 'pin', 'rewrite audit release ranges to the registry caret', [moved.length === 0 ? 'no range moved' : moved.join(', '), ...kept].join('; '));
|
|
1231
1518
|
}
|
|
1232
1519
|
else {
|
|
1233
1520
|
appendStep(runner, 'pin', 'rewrite audit release ranges to the registry caret', 'dry run');
|
|
@@ -1447,12 +1734,12 @@ export function describeChange(moved, movedWord, sameWord) {
|
|
|
1447
1734
|
/**
|
|
1448
1735
|
* Runs one repository's visit.
|
|
1449
1736
|
*
|
|
1450
|
-
* @param
|
|
1737
|
+
* @param values - The flag values `parseArgs` read.
|
|
1451
1738
|
* @returns The finished visit, or undefined when the target carries no readable manifest or no
|
|
1452
1739
|
* scaffold executable.
|
|
1453
1740
|
*/
|
|
1454
|
-
export function runVisit(
|
|
1455
|
-
const target =
|
|
1741
|
+
export function runVisit(values) {
|
|
1742
|
+
const target = typeof values.target === 'string' ? values.target : process.cwd();
|
|
1456
1743
|
if (!existsSync(join(target, 'package.json'))) {
|
|
1457
1744
|
console.error(`wave: ${target} carries no package.json`);
|
|
1458
1745
|
return undefined;
|
|
@@ -1468,8 +1755,8 @@ export function runVisit(argv) {
|
|
|
1468
1755
|
const [scaffoldFile, ...scaffoldPrefix] = scaffold;
|
|
1469
1756
|
if (scaffoldFile === undefined)
|
|
1470
1757
|
return undefined;
|
|
1471
|
-
const from = STEPS.indexOf(
|
|
1472
|
-
const to = STEPS.indexOf(
|
|
1758
|
+
const from = STEPS.indexOf(typeof values.from === 'string' ? values.from : 'pin');
|
|
1759
|
+
const to = STEPS.indexOf(typeof values.to === 'string' ? values.to : 'compare');
|
|
1473
1760
|
const selected = new Set(STEPS.slice(from, to + 1));
|
|
1474
1761
|
const manifest = readManifest(target);
|
|
1475
1762
|
if (manifest === undefined) {
|
|
@@ -1480,10 +1767,10 @@ export function runVisit(argv) {
|
|
|
1480
1767
|
const version = readString(manifest, 'version');
|
|
1481
1768
|
const runner = {
|
|
1482
1769
|
target: resolve(target),
|
|
1483
|
-
dry:
|
|
1484
|
-
offline:
|
|
1485
|
-
regenerate:
|
|
1486
|
-
directory:
|
|
1770
|
+
dry: values['dry-run'] === true,
|
|
1771
|
+
offline: values.offline === true,
|
|
1772
|
+
regenerate: values.regenerate === true,
|
|
1773
|
+
directory: values['dry-run'] === true ||
|
|
1487
1774
|
(name === SCAFFOLD && from === STEPS.indexOf('record') && to === from)
|
|
1488
1775
|
? undefined
|
|
1489
1776
|
: readJournalDirectory(resolve(target)),
|
|
@@ -1516,7 +1803,7 @@ export function runVisit(argv) {
|
|
|
1516
1803
|
if (selected.has('install') && !failed(runner.steps))
|
|
1517
1804
|
runInstall(runner, 'install');
|
|
1518
1805
|
const hits = selected.has('pins') && !failed(runner.steps)
|
|
1519
|
-
? runPins(runner, before,
|
|
1806
|
+
? runPins(runner, before, typeof values.prior === 'string' ? values.prior : version)
|
|
1520
1807
|
: undefined;
|
|
1521
1808
|
const format = selected.has('format') && !failed(runner.steps) ? runFormat(runner) : undefined;
|
|
1522
1809
|
if (selected.has('record') && !failed(runner.steps))
|
|
@@ -1622,64 +1909,55 @@ export function renderVisit(visit) {
|
|
|
1622
1909
|
* on usage.
|
|
1623
1910
|
*/
|
|
1624
1911
|
export function main(argv) {
|
|
1625
|
-
const
|
|
1626
|
-
if (
|
|
1627
|
-
console.error(`wave:
|
|
1628
|
-
return 64;
|
|
1629
|
-
}
|
|
1630
|
-
const missing = readMissingFlags(argv, [
|
|
1631
|
-
'--target',
|
|
1632
|
-
'--from',
|
|
1633
|
-
'--to',
|
|
1634
|
-
'--prior',
|
|
1635
|
-
'--catalog',
|
|
1636
|
-
'--out',
|
|
1637
|
-
]);
|
|
1638
|
-
if (missing.length > 0) {
|
|
1639
|
-
console.error(`wave: ${missing.join(', ')} given with no value`);
|
|
1912
|
+
const parsed = parseArguments(argv);
|
|
1913
|
+
if (!parsed.success) {
|
|
1914
|
+
console.error(`wave: ${parsed.error}; ${USAGE}`);
|
|
1640
1915
|
return 64;
|
|
1641
1916
|
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1917
|
+
const { values } = parsed.value;
|
|
1918
|
+
if (values.plan === true && values.visit === true) {
|
|
1919
|
+
console.error(`wave: --plan and --visit are two modes; name one; ${USAGE}`);
|
|
1644
1920
|
return 64;
|
|
1645
1921
|
}
|
|
1646
|
-
if (
|
|
1647
|
-
if (
|
|
1648
|
-
console.error(
|
|
1922
|
+
if (values.plan === true) {
|
|
1923
|
+
if (values.regenerate === true) {
|
|
1924
|
+
console.error(`wave: --regenerate requires --visit, not --plan; ${USAGE}`);
|
|
1649
1925
|
return 64;
|
|
1650
1926
|
}
|
|
1651
|
-
const layers = readLayers(
|
|
1927
|
+
const layers = readLayers(typeof values.catalog === 'string' ? values.catalog : CATALOG);
|
|
1652
1928
|
if (layers === undefined) {
|
|
1653
1929
|
console.error('wave: no marker-bounded catalog table; run scaffold catalog first');
|
|
1654
1930
|
return 2;
|
|
1655
1931
|
}
|
|
1656
|
-
if (
|
|
1932
|
+
if (values.json === true)
|
|
1657
1933
|
console.log(JSON.stringify(Object.fromEntries(layers)));
|
|
1658
1934
|
else
|
|
1659
1935
|
for (const [layer, members] of layers)
|
|
1660
1936
|
console.log(`${layer}\t${members.join(', ')}`);
|
|
1661
1937
|
return 0;
|
|
1662
1938
|
}
|
|
1663
|
-
if (
|
|
1939
|
+
if (values.visit !== true) {
|
|
1664
1940
|
console.error(USAGE);
|
|
1665
1941
|
return 64;
|
|
1666
1942
|
}
|
|
1667
|
-
const
|
|
1668
|
-
const
|
|
1943
|
+
const first = typeof values.from === 'string' ? values.from : 'pin';
|
|
1944
|
+
const last = typeof values.to === 'string' ? values.to : 'compare';
|
|
1945
|
+
const from = STEPS.indexOf(first);
|
|
1946
|
+
const to = STEPS.indexOf(last);
|
|
1669
1947
|
if (from === -1 || to === -1 || to < from) {
|
|
1670
|
-
console.error(`wave: --from and --to
|
|
1948
|
+
console.error(`wave: --from and --to take steps in order from: ${STEPS.join(', ')}, not ${JSON.stringify(first)} and ${JSON.stringify(last)}; ${USAGE}`);
|
|
1671
1949
|
return 64;
|
|
1672
1950
|
}
|
|
1673
|
-
const prior =
|
|
1951
|
+
const prior = typeof values.prior === 'string' ? values.prior : undefined;
|
|
1674
1952
|
if (prior !== undefined && !VERSION.test(prior)) {
|
|
1675
|
-
console.error(
|
|
1953
|
+
console.error(`wave: --prior takes the version the package carried before its bump, MAJOR.MINOR.PATCH, not ${JSON.stringify(prior)}; ${USAGE}`);
|
|
1676
1954
|
return 64;
|
|
1677
1955
|
}
|
|
1678
|
-
const visit = runVisit(
|
|
1956
|
+
const visit = runVisit(values);
|
|
1679
1957
|
if (visit === undefined)
|
|
1680
1958
|
return 2;
|
|
1681
|
-
const output =
|
|
1682
|
-
const out =
|
|
1959
|
+
const output = values.json === true ? `${JSON.stringify(visit)}\n` : renderVisit(visit);
|
|
1960
|
+
const out = typeof values.out === 'string' ? values.out : undefined;
|
|
1683
1961
|
if (out === undefined)
|
|
1684
1962
|
process.stdout.write(output);
|
|
1685
1963
|
else {
|