@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.
Files changed (92) hide show
  1. package/dist/agents/skills/orkestrel-dispatch/scripts/bench.js +61 -96
  2. package/dist/agents/skills/orkestrel-dispatch/scripts/brief.js +48 -76
  3. package/dist/agents/skills/orkestrel-dispatch/scripts/chain.js +27 -66
  4. package/dist/agents/skills/orkestrel-dispatch/scripts/cite.js +31 -64
  5. package/dist/agents/skills/orkestrel-dispatch/scripts/launch.js +43 -57
  6. package/dist/agents/skills/orkestrel-dispatch/scripts/login.js +43 -86
  7. package/dist/agents/skills/orkestrel-dispatch/scripts/patch.js +68 -104
  8. package/dist/agents/skills/orkestrel-dispatch/scripts/result.js +35 -69
  9. package/dist/agents/skills/orkestrel-dispatch/scripts/sweep.js +47 -84
  10. package/dist/agents/skills/orkestrel-falsify/scripts/mutate.js +134 -116
  11. package/dist/agents/skills/orkestrel-harden/scripts/discovery.js +38 -90
  12. package/dist/agents/skills/orkestrel-harden/scripts/interleave.js +39 -103
  13. package/dist/agents/skills/orkestrel-harden/scripts/measure.js +40 -89
  14. package/dist/agents/skills/orkestrel-harden/scripts/titles.js +41 -87
  15. package/dist/agents/skills/orkestrel-parallel/scripts/cases.js +43 -88
  16. package/dist/agents/skills/orkestrel-parallel/scripts/lane.js +1568 -213
  17. package/dist/agents/skills/orkestrel-publish/scripts/compare.js +40 -60
  18. package/dist/agents/skills/orkestrel-publish/scripts/pins.js +47 -81
  19. package/dist/agents/skills/orkestrel-publish/scripts/steps.js +66 -104
  20. package/dist/agents/skills/orkestrel-publish/scripts/swap.js +74 -88
  21. package/dist/agents/skills/orkestrel-publish/scripts/wave.js +387 -109
  22. package/dist/agents/skills/orkestrel-publish/scripts/window.js +55 -96
  23. package/dist/agents/skills/orkestrel-scout/scripts/map.js +54 -101
  24. package/dist/bin/main.js +275 -33
  25. package/dist/bin/main.js.map +1 -1
  26. package/dist/host/AGENTS.md +1 -1
  27. package/dist/host/agents/skills/orkestrel-dispatch/scripts/bench.ts +81 -97
  28. package/dist/host/agents/skills/orkestrel-dispatch/scripts/brief.ts +64 -72
  29. package/dist/host/agents/skills/orkestrel-dispatch/scripts/chain.ts +41 -63
  30. package/dist/host/agents/skills/orkestrel-dispatch/scripts/cite.ts +56 -79
  31. package/dist/host/agents/skills/orkestrel-dispatch/scripts/launch.ts +61 -74
  32. package/dist/host/agents/skills/orkestrel-dispatch/scripts/login.ts +59 -89
  33. package/dist/host/agents/skills/orkestrel-dispatch/scripts/patch.ts +87 -106
  34. package/dist/host/agents/skills/orkestrel-dispatch/scripts/result.ts +57 -76
  35. package/dist/host/agents/skills/orkestrel-dispatch/scripts/sweep.ts +73 -88
  36. package/dist/host/agents/skills/orkestrel-falsify/SKILL.md +2 -2
  37. package/dist/host/agents/skills/orkestrel-falsify/scripts/mutate.ts +167 -119
  38. package/dist/host/agents/skills/orkestrel-harden/references/methods.md +1 -1
  39. package/dist/host/agents/skills/orkestrel-harden/scripts/discovery.ts +58 -75
  40. package/dist/host/agents/skills/orkestrel-harden/scripts/interleave.ts +55 -99
  41. package/dist/host/agents/skills/orkestrel-harden/scripts/measure.ts +59 -90
  42. package/dist/host/agents/skills/orkestrel-harden/scripts/titles.ts +60 -80
  43. package/dist/host/agents/skills/orkestrel-parallel/SKILL.md +4 -4
  44. package/dist/host/agents/skills/orkestrel-parallel/scripts/cases.ts +71 -108
  45. package/dist/host/agents/skills/orkestrel-parallel/scripts/lane.ts +1990 -274
  46. package/dist/host/agents/skills/orkestrel-publish/references/release.md +1 -0
  47. package/dist/host/agents/skills/orkestrel-publish/references/wave.md +28 -7
  48. package/dist/host/agents/skills/orkestrel-publish/scripts/compare.ts +58 -79
  49. package/dist/host/agents/skills/orkestrel-publish/scripts/pins.ts +66 -87
  50. package/dist/host/agents/skills/orkestrel-publish/scripts/steps.ts +84 -102
  51. package/dist/host/agents/skills/orkestrel-publish/scripts/swap.ts +92 -99
  52. package/dist/host/agents/skills/orkestrel-publish/scripts/wave.ts +483 -127
  53. package/dist/host/agents/skills/orkestrel-publish/scripts/window.ts +82 -120
  54. package/dist/host/agents/skills/orkestrel-scout/SKILL.md +3 -3
  55. package/dist/host/agents/skills/orkestrel-scout/scripts/map.ts +85 -112
  56. package/dist/host/claude/agents/orkestrel.md +16 -16
  57. package/dist/host/claude/rules/architecture.md +1 -1
  58. package/dist/host/claude/rules/documentation.md +1 -1
  59. package/dist/host/claude/rules/patterns.md +7 -4
  60. package/dist/host/claude/rules/styles.md +1 -1
  61. package/dist/host/claude/rules/tests.md +3 -3
  62. package/dist/host/claude/rules/workspace.md +50 -37
  63. package/dist/host/configs/helpers.ts +117 -71
  64. package/dist/host/dotfiles/oxlintrc.json +6 -0
  65. package/dist/host/guides/agent.md +989 -395
  66. package/dist/host/guides/database.md +357 -342
  67. package/dist/host/guides/form.md +79 -4
  68. package/dist/host/guides/middleware.md +5 -5
  69. package/dist/host/guides/ollama.md +41 -42
  70. package/dist/host/guides/scaffold.md +170 -70
  71. package/dist/host/guides/study.md +12 -12
  72. package/dist/host/guides/table.md +20 -6
  73. package/dist/host/guides/test.md +166 -52
  74. package/dist/host/guides/toolbox.md +127 -81
  75. package/dist/host/guides/workspace.md +21 -14
  76. package/dist/host/manifest.json +54 -54
  77. package/dist/host/tests/config.test.ts +251 -7
  78. package/dist/host/tests/policy.test.ts +14 -21
  79. package/dist/host/tests/setupPolicy.ts +43 -36
  80. package/dist/src/core/index.cjs +533 -139
  81. package/dist/src/core/index.cjs.map +1 -1
  82. package/dist/src/core/index.d.cts +223 -16
  83. package/dist/src/core/index.d.ts +223 -16
  84. package/dist/src/core/index.js +524 -139
  85. package/dist/src/core/index.js.map +1 -1
  86. package/dist/src/server/index.cjs +23 -14
  87. package/dist/src/server/index.cjs.map +1 -1
  88. package/dist/src/server/index.d.cts +3 -2
  89. package/dist/src/server/index.d.ts +3 -2
  90. package/dist/src/server/index.js +24 -15
  91. package/dist/src/server/index.js.map +1 -1
  92. package/package.json +2 -2
@@ -3,7 +3,14 @@
3
3
  // node .agents/skills/orkestrel-publish/scripts/wave.ts --plan [--catalog PATH] [--json]
4
4
  // --visit runs the visit `wave.md` § Visit a repository fixes, in order, stopping at the first step
5
5
  // that fails: pin (read `scaffold audit --json`, whose drift exit is the reading the pin closes, then
6
- // re-pin every range the audit release readings name to the registry caret and install), commit (`git commit --only` of
6
+ // re-pin every `dependencies` and `devDependencies` range the audit release readings name to the registry caret,
7
+ // look up each peer-only dependency with `npm view` as the audit bounds a dependency, stopping when a lookup
8
+ // exits non-zero, raise a `peerDependencies` range from its reading, never a dependency range from a peer-only
9
+ // reading, to the caret of its served version only when the declared exact, caret, tilde, or `||` range excludes
10
+ // that version, moving the one arm in the release's major, keep every other peer as declared, including one with
11
+ // several arms in that major, no eligible release, or no reading offline, and one spanning several majors whose
12
+ // lookup bound is its own range and never rises, name each peer raised or kept in the rewrite row, and install),
13
+ // commit (`git commit --only` of
7
14
  // the manifest and lockfile as the preparation commit), overwrite (`scaffold overwrite --json`, then
8
15
  // `scaffold audit` exiting 0; offline, an exit of 1 whose note names the skipped catalog step is
9
16
  // accepted; on @orkestrel/scaffold itself both are skipped with a note, because the vendored host
@@ -22,8 +29,9 @@
22
29
  // ruling is unanswered. --plan reads the marker-bounded catalog table in
23
30
  // `.claude/agents/orkestrel.md` and prints the packages by layer. The pins and compare steps run
24
31
  // `pins.ts` and `compare.ts` as child commands. Exit 0 when every step passed, 1 when a step
25
- // failed, 2 when a reading failed, 64 on usage, including --plan --regenerate, a flag the script
26
- // does not read, and the `--flag=value` form.
32
+ // failed, 2 when a reading failed, 64 on usage, including --plan --regenerate. The script reads its
33
+ // flags with `parseArgs` in strict mode.
34
+ import type { ParseArgsOptionsConfig } from 'node:util'
27
35
  import type { SpawnSyncReturns } from 'node:child_process'
28
36
  import { spawnSync } from 'node:child_process'
29
37
  import { createHash } from 'node:crypto'
@@ -41,6 +49,7 @@ import {
41
49
  } from 'node:fs'
42
50
  import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
43
51
  import { fileURLToPath } from 'node:url'
52
+ import { parseArgs } from 'node:util'
44
53
 
45
54
  /** Lists the steps of a visit in the order they run. */
46
55
  export const STEPS: readonly string[] = [
@@ -119,26 +128,59 @@ export const PINS = fileURLToPath(new URL(`./pins${EXTENSION}`, import.meta.url)
119
128
  export const DIRTY_ENTRY =
120
129
  /(?=[RC][^\0]|[^\0][RC])[^\0]{2} ([^\0]*)\0([^\0]*)(?:\0|$)|[^\0]{2} ([^\0]*)(?:\0|$)/gu
121
130
 
122
- /** Lists every flag the script reads, value flags and switches alike. */
123
- export const FLAGS: readonly string[] = [
124
- '--visit',
125
- '--plan',
126
- '--target',
127
- '--offline',
128
- '--regenerate',
129
- '--from',
130
- '--to',
131
- '--prior',
132
- '--dry-run',
133
- '--json',
134
- '--out',
135
- '--catalog',
136
- ]
137
-
138
131
  /** Holds the usage line the script prints when no mode was given. */
139
132
  export const USAGE =
140
133
  'usage: wave.ts --visit [--target DIR] [--offline] [--regenerate] [--from STEP] [--to STEP] [--prior VERSION] [--dry-run] [--json] [--out FILE] | --plan [--catalog PATH] [--json]'
141
134
 
135
+ /** Declares every flag the script reads, for `parseArgs`. */
136
+ export const OPTIONS: ParseArgsOptionsConfig = Object.freeze({
137
+ visit: Object.freeze({ type: 'boolean' }),
138
+ plan: Object.freeze({ type: 'boolean' }),
139
+ target: Object.freeze({ type: 'string' }),
140
+ offline: Object.freeze({ type: 'boolean' }),
141
+ regenerate: Object.freeze({ type: 'boolean' }),
142
+ from: Object.freeze({ type: 'string' }),
143
+ to: Object.freeze({ type: 'string' }),
144
+ prior: Object.freeze({ type: 'string' }),
145
+ 'dry-run': Object.freeze({ type: 'boolean' }),
146
+ json: Object.freeze({ type: 'boolean' }),
147
+ out: Object.freeze({ type: 'string' }),
148
+ catalog: Object.freeze({ type: 'string' }),
149
+ })
150
+
151
+ /** Describes the arguments `parseArgs` read: each flag's value by name, and the positionals. */
152
+ export interface Arguments {
153
+ readonly values: Readonly<
154
+ Record<string, string | boolean | ReadonlyArray<string | boolean> | undefined>
155
+ >
156
+ readonly positionals: readonly string[]
157
+ }
158
+
159
+ /** Describes how `parseArgs` read the arguments: the arguments, or the message it refused them with. */
160
+ export type ArgumentsResult =
161
+ | { readonly success: true; readonly value: Arguments }
162
+ | { readonly success: false; readonly error: string }
163
+
164
+ /**
165
+ * Parses the arguments in strict mode against `OPTIONS`.
166
+ *
167
+ * @param argv - The arguments after the script path.
168
+ * @returns The values and positionals, or the message `parseArgs` refused the arguments with.
169
+ */
170
+ export function parseArguments(argv: readonly string[]): ArgumentsResult {
171
+ try {
172
+ const { values, positionals } = parseArgs({
173
+ args: [...argv],
174
+ options: OPTIONS,
175
+ strict: true,
176
+ allowPositionals: false,
177
+ })
178
+ return { success: true, value: { values, positionals } }
179
+ } catch (error) {
180
+ return { success: false, error: error instanceof Error ? error.message : String(error) }
181
+ }
182
+ }
183
+
142
184
  /** Names the manifest fields that hold specs, including nested overrides. */
143
185
  export const SPEC_FIELDS: readonly string[] = Object.freeze([
144
186
  'dependencies',
@@ -188,6 +230,38 @@ export interface RangeMove {
188
230
  readonly moved: readonly string[]
189
231
  }
190
232
 
233
+ /** Describes a manifest re-pin: the ranges it moved, raised peers included, and the peers it kept. */
234
+ export interface Rewrite {
235
+ readonly moved: readonly string[]
236
+ readonly kept: readonly string[]
237
+ }
238
+
239
+ /** Describes one manifest field after a re-pin: its moves and the peer messages it kept. */
240
+ export interface FieldMove {
241
+ readonly field: string
242
+ readonly moves: RangeMove
243
+ readonly kept: readonly string[]
244
+ }
245
+
246
+ /** Describes the versions one `||` arm of a range admits, from `floor` up to but excluding `ceiling`. */
247
+ export interface RangeArm {
248
+ readonly floor: readonly [number, number, number]
249
+ readonly ceiling: readonly [number, number, number]
250
+ }
251
+
252
+ /** Describes the decision on one peer range: the range after it, its rewrite message, and whether it rose. */
253
+ export interface PeerMove {
254
+ readonly range: string
255
+ readonly message: string
256
+ readonly raised: boolean
257
+ }
258
+
259
+ /** Describes the registry lookup a peer-only dependency needs: its name and the lookup bound. */
260
+ export interface PeerLookup {
261
+ readonly name: string
262
+ readonly bound: string
263
+ }
264
+
191
265
  /** Describes the bump ruling a visit reaches. */
192
266
  export interface Ruling {
193
267
  readonly distMoved: boolean | undefined
@@ -325,60 +399,7 @@ export function removeTree(path: string): void {
325
399
  * @returns The same path with every backslash replaced by a slash.
326
400
  */
327
401
  export function normalizeSlashes(path: string): string {
328
- return path.split('\\').join('/')
329
- }
330
-
331
- /**
332
- * Reads the value that follows a flag.
333
- *
334
- * @remarks
335
- * Reads `--flag value` pairs: the first occurrence of a flag wins, a following value that opens
336
- * with `--` is a missing value, and the `--flag=value` form is not read.
337
- *
338
- * @param argv - The arguments after the script path.
339
- * @param name - The flag, such as `--target`.
340
- * @returns The value after the flag, or undefined when the flag is absent, last, or followed by
341
- * another flag.
342
- */
343
- export function readOption(argv: readonly string[], name: string): string | undefined {
344
- const index = argv.indexOf(name)
345
- const value = index === -1 ? undefined : argv[index + 1]
346
- return value === undefined || value.startsWith('--') ? undefined : value
347
- }
348
-
349
- /**
350
- * Names the value flags a caller gave with no value.
351
- *
352
- * @param argv - The arguments after the script path.
353
- * @param names - The flags that take a value.
354
- * @returns Each named flag that appears last or is followed by another flag, in argument order.
355
- */
356
- export function readMissingFlags(
357
- argv: readonly string[],
358
- names: readonly string[],
359
- ): readonly string[] {
360
- return names.filter((name) => argv.includes(name) && readOption(argv, name) === undefined)
361
- }
362
-
363
- /**
364
- * Names the flags a caller gave that the script does not read.
365
- *
366
- * @remarks
367
- * Reads the arguments before a bare `--`, which opens a command a script passes on. A `--flag=value`
368
- * argument is unknown, because the script reads no such form.
369
- *
370
- * @param argv - The arguments after the script path.
371
- * @param flags - Every flag the script reads, value flags and switches alike.
372
- * @returns Each argument that opens with `--` and is not a read flag, in argument order.
373
- */
374
- export function readUnknownFlags(
375
- argv: readonly string[],
376
- flags: readonly string[],
377
- ): readonly string[] {
378
- const end = argv.indexOf('--')
379
- return (end === -1 ? argv : argv.slice(0, end)).filter(
380
- (argument) => argument.startsWith('--') && !flags.includes(argument),
381
- )
402
+ return path.replaceAll('\\', '/')
382
403
  }
383
404
 
384
405
  /**
@@ -1544,6 +1565,246 @@ export function runFormat(runner: Runner): FormatReceipt | undefined {
1544
1565
  }
1545
1566
  }
1546
1567
 
1568
+ /**
1569
+ * Parses a whole text as one JSON object or a list of JSON objects.
1570
+ *
1571
+ * @param text - A JSON document, such as `npm view NAME@RANGE FIELD --json` output, which prints one
1572
+ * record for one match and a list for several.
1573
+ * @returns Each object the document carries, or none when the text is not JSON.
1574
+ */
1575
+ export function parseJsonRecords(text: string): ReadonlyArray<Record<string, unknown>> {
1576
+ try {
1577
+ const parsed: unknown = JSON.parse(text)
1578
+ return (Array.isArray(parsed) ? parsed : [parsed])
1579
+ .filter(isRecord)
1580
+ .map((entry) => Object.fromEntries(Object.entries(entry)))
1581
+ } catch {
1582
+ return []
1583
+ }
1584
+ }
1585
+
1586
+ /**
1587
+ * Parses the major, minor, and patch numbers of a plain `major.minor.patch` version.
1588
+ *
1589
+ * @param text - The version text.
1590
+ * @returns The three numbers, or undefined when the text carries a prefix, a prerelease, or any
1591
+ * other form.
1592
+ * @example
1593
+ * ```ts
1594
+ * parseVersion('8.3.8') // [8, 3, 8]
1595
+ * parseVersion('8.3.8-beta.1') // undefined
1596
+ * ```
1597
+ */
1598
+ export function parseVersion(text: string): readonly [number, number, number] | undefined {
1599
+ const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u.exec(text)
1600
+ if (match === null) return undefined
1601
+ return [Number(match[1]), Number(match[2]), Number(match[3])]
1602
+ }
1603
+
1604
+ /**
1605
+ * Compares two plain versions by their major, minor, and patch numbers.
1606
+ *
1607
+ * @param left - The version ordered first when it compares lower.
1608
+ * @param right - The version it is compared with.
1609
+ * @returns A negative number when `left` is lower, zero when equal, and a positive number when higher.
1610
+ * @example
1611
+ * ```ts
1612
+ * compareVersions([0, 0, 23], [0, 0, 24]) // -1
1613
+ * ```
1614
+ */
1615
+ export function compareVersions(
1616
+ left: readonly [number, number, number],
1617
+ right: readonly [number, number, number],
1618
+ ): number {
1619
+ return left[0] - right[0] || left[1] - right[1] || left[2] - right[2]
1620
+ }
1621
+
1622
+ /**
1623
+ * Parses a declared range as the half-open version intervals its `||` arms admit.
1624
+ *
1625
+ * @remarks
1626
+ * An arm is an exact `major.minor.patch` version, a caret, or a tilde over one. A caret admits up to
1627
+ * the next major, the next minor under major 0, and the next patch under `0.0`; a tilde admits up to
1628
+ * the next minor. Any other form, an empty arm included, makes the whole range unreadable.
1629
+ *
1630
+ * @param range - The declared range.
1631
+ * @returns One interval per arm, with an inclusive `floor` and an exclusive `ceiling`, or undefined
1632
+ * when an arm is outside those forms.
1633
+ * @example
1634
+ * ```ts
1635
+ * parseRange('^0.0.23') // [{ floor: [0, 0, 23], ceiling: [0, 0, 24] }]
1636
+ * parseRange('>=8') // undefined
1637
+ * ```
1638
+ */
1639
+ export function parseRange(range: string): readonly RangeArm[] | undefined {
1640
+ const arms = range.trim().split(/\s*\|\|\s*/u)
1641
+ const parsed = arms.flatMap((arm): readonly RangeArm[] => {
1642
+ const match = /^([\^~]?)(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u.exec(arm)
1643
+ if (match === null) return []
1644
+ const major = Number(match[2])
1645
+ const minor = Number(match[3])
1646
+ const patch = Number(match[4])
1647
+ const ceiling: readonly [number, number, number] =
1648
+ match[1] === '~'
1649
+ ? [major, minor + 1, 0]
1650
+ : match[1] === ''
1651
+ ? [major, minor, patch + 1]
1652
+ : major > 0
1653
+ ? [major + 1, 0, 0]
1654
+ : minor > 0
1655
+ ? [0, minor + 1, 0]
1656
+ : [0, 0, patch + 1]
1657
+ return [{ floor: [major, minor, patch], ceiling }]
1658
+ })
1659
+ return parsed.length === arms.length ? parsed : undefined
1660
+ }
1661
+
1662
+ /**
1663
+ * Computes whether a declared range admits a plain version.
1664
+ *
1665
+ * @param range - The declared range, in a form {@link parseRange} reads.
1666
+ * @param version - The plain version.
1667
+ * @returns True if an arm admits the version, false if none does, and undefined when the range or
1668
+ * the version is unreadable.
1669
+ * @example
1670
+ * ```ts
1671
+ * computeSatisfaction('^8.3.7', '8.3.8') // true
1672
+ * computeSatisfaction('^0.0.23', '0.0.24') // false
1673
+ * computeSatisfaction('*', '1.0.0') // undefined
1674
+ * ```
1675
+ */
1676
+ export function computeSatisfaction(range: string, version: string): boolean | undefined {
1677
+ const arms = parseRange(range)
1678
+ const parsed = parseVersion(version)
1679
+ if (arms === undefined || parsed === undefined) return undefined
1680
+ return arms.some(
1681
+ (arm) => compareVersions(arm.floor, parsed) <= 0 && compareVersions(parsed, arm.ceiling) < 0,
1682
+ )
1683
+ }
1684
+
1685
+ /**
1686
+ * Raises one declared peer range whose floor fails the served release, and words the decision.
1687
+ *
1688
+ * @remarks
1689
+ * A range the served version satisfies stays as declared. A failing range moves per
1690
+ * {@link moveRange}: the one arm in the release's major becomes the caret of the release. A range
1691
+ * that is unreadable, carries no arm or several arms in that major, or whose arm in that major opens
1692
+ * above the release stays as declared, and the message names why. A reading that names the peer and
1693
+ * carries no release keeps it as `no eligible release`; no reading keeps it as `no release reading`.
1694
+ *
1695
+ * @param name - The peer's package name.
1696
+ * @param range - The declared peer range.
1697
+ * @param reading - The release reading that names the peer, or undefined when none does.
1698
+ * @returns The range after the decision and the rewrite row message: `peer NAME OLD -> NEW` when it
1699
+ * rose, `peer NAME OLD kept, REASON` otherwise.
1700
+ * @example
1701
+ * ```ts
1702
+ * raisePeer('@orkestrel/database', '^0.0.23', { name: '@orkestrel/database', range: '*', latest: '0.0.24' })
1703
+ * // { range: '^0.0.24', message: 'peer @orkestrel/database ^0.0.23 -> ^0.0.24', raised: true }
1704
+ * ```
1705
+ */
1706
+ export function raisePeer(name: string, range: string, reading: Release | undefined): PeerMove {
1707
+ const arms = parseRange(range)
1708
+ const latest = reading?.latest
1709
+ const version = latest === undefined ? undefined : parseVersion(latest)
1710
+ const matched =
1711
+ version === undefined ? [] : (arms ?? []).filter((entry) => entry.floor[0] === version[0])
1712
+ const reason =
1713
+ arms === undefined
1714
+ ? 'unreadable range'
1715
+ : reading === undefined
1716
+ ? 'no release reading'
1717
+ : latest === undefined
1718
+ ? 'no eligible release'
1719
+ : version === undefined
1720
+ ? `unreadable release ${latest}`
1721
+ : computeSatisfaction(range, latest) === true
1722
+ ? `admits ${latest}`
1723
+ : matched.length === 0
1724
+ ? `no arm in the major of ${latest}`
1725
+ : matched.length > 1
1726
+ ? `several arms in the major of ${latest}`
1727
+ : matched.some((arm) => compareVersions(arm.floor, version) > 0)
1728
+ ? `its floor is above ${latest}`
1729
+ : undefined
1730
+ if (reason !== undefined || latest === undefined)
1731
+ return { range, message: `peer ${name} ${range} kept, ${String(reason)}`, raised: false }
1732
+ const next = String(moveRange(range, latest))
1733
+ return { range: next, message: `peer ${name} ${range} -> ${next}`, raised: true }
1734
+ }
1735
+
1736
+ /**
1737
+ * Collects the registry lookup each peer-only dependency needs for its release reading.
1738
+ *
1739
+ * @remarks
1740
+ * A peer a release reading already names, such as one also declared under `devDependencies`, takes
1741
+ * that reading. A peer whose range {@link parseRange} cannot read needs no reading. A fleet package
1742
+ * is looked up with `*`, and a foreign tool with a caret over its declared major, or with the
1743
+ * declared range when its arms span several majors, as the audit bounds a dependency. A range bound
1744
+ * by itself admits every release its lookup serves, so such a peer never rises.
1745
+ *
1746
+ * @param manifest - The manifest record.
1747
+ * @param releases - The audit's release readings.
1748
+ * @returns One lookup per peer-only dependency, in declaration order.
1749
+ * @example
1750
+ * ```ts
1751
+ * collectPeerLookups({ peerDependencies: { vite: '^8.3.7' } }, [])
1752
+ * // [{ name: 'vite', bound: '^8' }]
1753
+ * ```
1754
+ */
1755
+ export function collectPeerLookups(
1756
+ manifest: Record<string, unknown>,
1757
+ releases: readonly Release[],
1758
+ ): readonly PeerLookup[] {
1759
+ const named = new Set(releases.map((release) => release.name))
1760
+ const block = manifest.peerDependencies
1761
+ if (typeof block !== 'object' || block === null) return []
1762
+ return Object.entries(block).flatMap(([name, range]): readonly PeerLookup[] => {
1763
+ if (typeof range !== 'string' || named.has(name)) return []
1764
+ const majors = [...new Set(parseRange(range)?.map((arm) => arm.floor[0]))]
1765
+ if (majors.length === 0) return []
1766
+ const bound = name.startsWith('@orkestrel/')
1767
+ ? '*'
1768
+ : majors.length === 1
1769
+ ? `^${String(majors[0])}`
1770
+ : range
1771
+ return [{ name, bound }]
1772
+ })
1773
+ }
1774
+
1775
+ /**
1776
+ * Reads the release a registry lookup serves out of the output of
1777
+ * `npm view NAME@BOUND version deprecated dist-tags.latest --json`.
1778
+ *
1779
+ * @remarks
1780
+ * The reading skips a deprecated version, a version outside the plain `major.minor.patch` form, and
1781
+ * a version above `latest` when the bound is `*` or the caret of `latest`'s major, then takes the
1782
+ * highest, as the audit's lookup does.
1783
+ *
1784
+ * @param text - The command's standard output.
1785
+ * @param bound - The lookup bound.
1786
+ * @returns The served version, or undefined when no version is eligible or the output is unreadable.
1787
+ * @example
1788
+ * ```ts
1789
+ * readServedVersion('{"version":"0.0.24","dist-tags.latest":"0.0.24"}', '*') // '0.0.24'
1790
+ * ```
1791
+ */
1792
+ export function readServedVersion(text: string, bound: string): string | undefined {
1793
+ const eligible = parseJsonRecords(text).flatMap((entry) => {
1794
+ const version = readString(entry, 'version') ?? ''
1795
+ const plain = parseVersion(version)
1796
+ const deprecated = readString(entry, 'deprecated') ?? ''
1797
+ const latest = parseVersion(readString(entry, 'dist-tags.latest') ?? '')
1798
+ if (plain === undefined || deprecated.length > 0) return []
1799
+ const capped =
1800
+ latest !== undefined && (bound === '*' || bound === `^${String(latest[0])}`)
1801
+ ? compareVersions(plain, latest) <= 0
1802
+ : true
1803
+ return capped ? [{ version, plain }] : []
1804
+ })
1805
+ return eligible.toSorted((left, right) => compareVersions(right.plain, left.plain))[0]?.version
1806
+ }
1807
+
1547
1808
  /**
1548
1809
  * Moves one declared range to the registry caret of a release, keeping every other major a
1549
1810
  * disjunctive range admits.
@@ -1606,34 +1867,107 @@ export function computeRanges(
1606
1867
  }
1607
1868
 
1608
1869
  /**
1609
- * Writes the re-pinned ranges into the target's manifest.
1870
+ * Writes the re-pinned ranges into the target's manifest, raising each peer range whose floor fails
1871
+ * its release.
1872
+ *
1873
+ * @remarks
1874
+ * A `dependencies` or `devDependencies` range moves per {@link computeRanges} over the audit's
1875
+ * readings alone. A `peerDependencies` range takes the last audit reading that names it with a
1876
+ * release, else its peer-only reading, and moves per {@link raisePeer}: it rises to the caret of the
1877
+ * served version only when the declared range excludes that version, and otherwise stays as
1878
+ * declared. Every raised peer joins the moved list and every other peer is reported as kept.
1610
1879
  *
1611
1880
  * @param target - The target directory.
1612
1881
  * @param releases - The audit's release readings.
1613
- * @returns One message per range moved; the manifest is rewritten only when a range moved.
1882
+ * @param peers - The peer-only readings, which move `peerDependencies` ranges alone. Default: none.
1883
+ * @returns One message per range moved and one per peer range kept; the manifest is rewritten only
1884
+ * when a range moved.
1885
+ * @example
1886
+ * ```ts
1887
+ * writeRanges('.', [{ name: 'vite', range: '^8', latest: '8.3.8' }])
1888
+ * // { moved: ['vite ^8.3.7 -> ^8.3.8'], kept: ['peer vite ^8.3.7 kept, admits 8.3.8'] }
1889
+ * ```
1614
1890
  */
1615
- export function writeRanges(target: string, releases: readonly Release[]): readonly string[] {
1891
+ export function writeRanges(
1892
+ target: string,
1893
+ releases: readonly Release[],
1894
+ peers: readonly Release[] = [],
1895
+ ): Rewrite {
1616
1896
  const manifest = readManifest(target)
1617
- if (manifest === undefined) return []
1618
- const fields = RANGE_FIELDS.flatMap((field) => {
1897
+ if (manifest === undefined) return { moved: [], kept: [] }
1898
+ const fields = RANGE_FIELDS.flatMap((field): readonly FieldMove[] => {
1619
1899
  const block = manifest[field]
1620
1900
  if (typeof block !== 'object' || block === null) return []
1621
- return [{ field, ...computeRanges(Object.fromEntries(Object.entries(block)), releases) }]
1901
+ const ranges = Object.fromEntries(Object.entries(block))
1902
+ if (field !== 'peerDependencies')
1903
+ return [{ field, moves: computeRanges(ranges, releases), kept: [] }]
1904
+ const decisions = Object.entries(ranges).flatMap(([name, range]) =>
1905
+ typeof range === 'string'
1906
+ ? [
1907
+ [
1908
+ name,
1909
+ raisePeer(
1910
+ name,
1911
+ range,
1912
+ releases.findLast(
1913
+ (release) => release.name === name && release.latest !== undefined,
1914
+ ) ?? peers.findLast((release) => release.name === name),
1915
+ ),
1916
+ ] as const,
1917
+ ]
1918
+ : [],
1919
+ )
1920
+ return [
1921
+ {
1922
+ field,
1923
+ moves: {
1924
+ ranges: {
1925
+ ...ranges,
1926
+ ...Object.fromEntries(decisions.map(([name, peer]) => [name, peer.range])),
1927
+ },
1928
+ moved: decisions.flatMap(([, peer]) => (peer.raised ? [peer.message] : [])),
1929
+ },
1930
+ kept: decisions.flatMap(([, peer]) => (peer.raised ? [] : [peer.message])),
1931
+ },
1932
+ ]
1622
1933
  })
1623
- const moved = fields.flatMap((entry) => entry.moved)
1934
+ const moved = fields.flatMap((entry) => entry.moves.moved)
1624
1935
  if (moved.length > 0) {
1625
1936
  const written = {
1626
1937
  ...manifest,
1627
- ...Object.fromEntries(fields.map((entry) => [entry.field, entry.ranges])),
1938
+ ...Object.fromEntries(fields.map((entry) => [entry.field, entry.moves.ranges])),
1628
1939
  }
1629
1940
  writeFileSync(join(target, 'package.json'), `${JSON.stringify(written, null, '\t')}\n`)
1630
1941
  }
1631
- return moved
1942
+ return { moved, kept: fields.flatMap((entry) => entry.kept) }
1943
+ }
1944
+
1945
+ /**
1946
+ * Judges one peer-only release lookup.
1947
+ *
1948
+ * @param result - The `npm view NAME@BOUND version deprecated dist-tags.latest --json` command.
1949
+ * @param bound - The lookup bound.
1950
+ * @returns Exit 0 naming the served version, or naming that no release within the bound is
1951
+ * eligible, when the lookup exited 0; else the lookup's failing exit and its reason.
1952
+ */
1953
+ export function judgeLookup(result: SpawnSyncReturns<string>, bound: string): Verdict {
1954
+ if (result.status !== 0) return readVerdict(result)
1955
+ const served = readServedVersion(result.stdout, bound)
1956
+ return {
1957
+ exit: 0,
1958
+ note: served === undefined ? `no eligible release within ${bound}` : `serves ${served}`,
1959
+ }
1632
1960
  }
1633
1961
 
1634
1962
  /**
1635
1963
  * Runs the pin step.
1636
1964
  *
1965
+ * @remarks
1966
+ * A peer-only dependency produces no audit release reading, so the step looks each one up with
1967
+ * `npm view`, per {@link collectPeerLookups}, before the rewrite, and stops before the rewrite and
1968
+ * the install when a lookup exits non-zero. A lookup that exits 0 with no eligible release keeps
1969
+ * its peer. Offline, it looks up none and the rewrite keeps those peers as declared.
1970
+ *
1637
1971
  * @param runner - The visit's state.
1638
1972
  * @param scaffoldFile - The scaffold executable.
1639
1973
  * @param scaffoldPrefix - The arguments that precede scaffold's own.
@@ -1657,12 +1991,43 @@ export function runPin(
1657
1991
  if (audit !== undefined) {
1658
1992
  const releases = readReleases(audit.stdout)
1659
1993
  if (releases === undefined || (audit.status !== 0 && audit.status !== 1)) return
1660
- const moved = writeRanges(runner.target, releases)
1994
+ const lookups = collectPeerLookups(readManifest(runner.target) ?? {}, releases)
1995
+ if (runner.offline && lookups.length > 0)
1996
+ appendStep(
1997
+ runner,
1998
+ 'pin',
1999
+ 'npm view',
2000
+ `offline: no peer-only lookup for ${lookups.map((lookup) => lookup.name).join(', ')}`,
2001
+ )
2002
+ const readings = (runner.offline ? [] : lookups).map((lookup): Release | undefined => {
2003
+ const view = runNpmStep(
2004
+ runner,
2005
+ 'pin',
2006
+ [
2007
+ 'view',
2008
+ `${lookup.name}@${lookup.bound}`,
2009
+ 'version',
2010
+ 'deprecated',
2011
+ 'dist-tags.latest',
2012
+ '--json',
2013
+ ],
2014
+ (result) => judgeLookup(result, lookup.bound),
2015
+ )
2016
+ if (view?.status !== 0) return undefined
2017
+ const latest = readServedVersion(view.stdout, lookup.bound)
2018
+ return { name: lookup.name, range: lookup.bound, latest }
2019
+ })
2020
+ if (readings.includes(undefined)) return
2021
+ const { moved, kept } = writeRanges(
2022
+ runner.target,
2023
+ releases,
2024
+ readings.filter((reading) => reading !== undefined),
2025
+ )
1661
2026
  appendStep(
1662
2027
  runner,
1663
2028
  'pin',
1664
2029
  'rewrite audit release ranges to the registry caret',
1665
- moved.length === 0 ? 'no range moved' : moved.join(', '),
2030
+ [moved.length === 0 ? 'no range moved' : moved.join(', '), ...kept].join('; '),
1666
2031
  )
1667
2032
  } else {
1668
2033
  appendStep(runner, 'pin', 'rewrite audit release ranges to the registry caret', 'dry run')
@@ -1975,12 +2340,12 @@ export function describeChange(
1975
2340
  /**
1976
2341
  * Runs one repository's visit.
1977
2342
  *
1978
- * @param argv - The arguments after the script path.
2343
+ * @param values - The flag values `parseArgs` read.
1979
2344
  * @returns The finished visit, or undefined when the target carries no readable manifest or no
1980
2345
  * scaffold executable.
1981
2346
  */
1982
- export function runVisit(argv: readonly string[]): Visit | undefined {
1983
- const target = readOption(argv, '--target') ?? process.cwd()
2347
+ export function runVisit(values: Arguments['values']): Visit | undefined {
2348
+ const target = typeof values.target === 'string' ? values.target : process.cwd()
1984
2349
  if (!existsSync(join(target, 'package.json'))) {
1985
2350
  console.error(`wave: ${target} carries no package.json`)
1986
2351
  return undefined
@@ -1999,8 +2364,8 @@ export function runVisit(argv: readonly string[]): Visit | undefined {
1999
2364
  }
2000
2365
  const [scaffoldFile, ...scaffoldPrefix] = scaffold
2001
2366
  if (scaffoldFile === undefined) return undefined
2002
- const from = STEPS.indexOf(readOption(argv, '--from') ?? 'pin')
2003
- const to = STEPS.indexOf(readOption(argv, '--to') ?? 'compare')
2367
+ const from = STEPS.indexOf(typeof values.from === 'string' ? values.from : 'pin')
2368
+ const to = STEPS.indexOf(typeof values.to === 'string' ? values.to : 'compare')
2004
2369
  const selected = new Set(STEPS.slice(from, to + 1))
2005
2370
  const manifest = readManifest(target)
2006
2371
  if (manifest === undefined) {
@@ -2011,11 +2376,11 @@ export function runVisit(argv: readonly string[]): Visit | undefined {
2011
2376
  const version = readString(manifest, 'version')
2012
2377
  const runner: Runner = {
2013
2378
  target: resolve(target),
2014
- dry: argv.includes('--dry-run'),
2015
- offline: argv.includes('--offline'),
2016
- regenerate: argv.includes('--regenerate'),
2379
+ dry: values['dry-run'] === true,
2380
+ offline: values.offline === true,
2381
+ regenerate: values.regenerate === true,
2017
2382
  directory:
2018
- argv.includes('--dry-run') ||
2383
+ values['dry-run'] === true ||
2019
2384
  (name === SCAFFOLD && from === STEPS.indexOf('record') && to === from)
2020
2385
  ? undefined
2021
2386
  : readJournalDirectory(resolve(target)),
@@ -2049,7 +2414,7 @@ export function runVisit(argv: readonly string[]): Visit | undefined {
2049
2414
  if (selected.has('install') && !failed(runner.steps)) runInstall(runner, 'install')
2050
2415
  const hits =
2051
2416
  selected.has('pins') && !failed(runner.steps)
2052
- ? runPins(runner, before, readOption(argv, '--prior') ?? version)
2417
+ ? runPins(runner, before, typeof values.prior === 'string' ? values.prior : version)
2053
2418
  : undefined
2054
2419
  const format = selected.has('format') && !failed(runner.steps) ? runFormat(runner) : undefined
2055
2420
  if (selected.has('record') && !failed(runner.steps)) runRecord(runner, name, format)
@@ -2165,64 +2530,55 @@ export function renderVisit(visit: Visit): string {
2165
2530
  * on usage.
2166
2531
  */
2167
2532
  export function main(argv: readonly string[]): number {
2168
- const unknown = readUnknownFlags(argv, FLAGS)
2169
- if (unknown.length > 0) {
2170
- console.error(
2171
- `wave: unknown flag ${unknown.join(', ')}; give each flag and its value as separate arguments\n${USAGE}`,
2172
- )
2173
- return 64
2174
- }
2175
- const missing = readMissingFlags(argv, [
2176
- '--target',
2177
- '--from',
2178
- '--to',
2179
- '--prior',
2180
- '--catalog',
2181
- '--out',
2182
- ])
2183
- if (missing.length > 0) {
2184
- console.error(`wave: ${missing.join(', ')} given with no value`)
2533
+ const parsed = parseArguments(argv)
2534
+ if (!parsed.success) {
2535
+ console.error(`wave: ${parsed.error}; ${USAGE}`)
2185
2536
  return 64
2186
2537
  }
2187
- if (argv.includes('--plan') && argv.includes('--visit')) {
2188
- console.error('wave: --plan and --visit are two modes; name one')
2538
+ const { values } = parsed.value
2539
+ if (values.plan === true && values.visit === true) {
2540
+ console.error(`wave: --plan and --visit are two modes; name one; ${USAGE}`)
2189
2541
  return 64
2190
2542
  }
2191
- if (argv.includes('--plan')) {
2192
- if (argv.includes('--regenerate')) {
2193
- console.error('wave: --regenerate requires --visit, not --plan')
2543
+ if (values.plan === true) {
2544
+ if (values.regenerate === true) {
2545
+ console.error(`wave: --regenerate requires --visit, not --plan; ${USAGE}`)
2194
2546
  return 64
2195
2547
  }
2196
- const layers = readLayers(readOption(argv, '--catalog') ?? CATALOG)
2548
+ const layers = readLayers(typeof values.catalog === 'string' ? values.catalog : CATALOG)
2197
2549
  if (layers === undefined) {
2198
2550
  console.error('wave: no marker-bounded catalog table; run scaffold catalog first')
2199
2551
  return 2
2200
2552
  }
2201
- if (argv.includes('--json')) console.log(JSON.stringify(Object.fromEntries(layers)))
2553
+ if (values.json === true) console.log(JSON.stringify(Object.fromEntries(layers)))
2202
2554
  else for (const [layer, members] of layers) console.log(`${layer}\t${members.join(', ')}`)
2203
2555
  return 0
2204
2556
  }
2205
- if (!argv.includes('--visit')) {
2557
+ if (values.visit !== true) {
2206
2558
  console.error(USAGE)
2207
2559
  return 64
2208
2560
  }
2209
- const from = STEPS.indexOf(readOption(argv, '--from') ?? 'pin')
2210
- const to = STEPS.indexOf(readOption(argv, '--to') ?? 'compare')
2561
+ const first = typeof values.from === 'string' ? values.from : 'pin'
2562
+ const last = typeof values.to === 'string' ? values.to : 'compare'
2563
+ const from = STEPS.indexOf(first)
2564
+ const to = STEPS.indexOf(last)
2211
2565
  if (from === -1 || to === -1 || to < from) {
2212
- console.error(`wave: --from and --to name steps in order from: ${STEPS.join(', ')}`)
2566
+ console.error(
2567
+ `wave: --from and --to take steps in order from: ${STEPS.join(', ')}, not ${JSON.stringify(first)} and ${JSON.stringify(last)}; ${USAGE}`,
2568
+ )
2213
2569
  return 64
2214
2570
  }
2215
- const prior = readOption(argv, '--prior')
2571
+ const prior = typeof values.prior === 'string' ? values.prior : undefined
2216
2572
  if (prior !== undefined && !VERSION.test(prior)) {
2217
2573
  console.error(
2218
- 'wave: --prior takes the version the package carried before its bump, MAJOR.MINOR.PATCH',
2574
+ `wave: --prior takes the version the package carried before its bump, MAJOR.MINOR.PATCH, not ${JSON.stringify(prior)}; ${USAGE}`,
2219
2575
  )
2220
2576
  return 64
2221
2577
  }
2222
- const visit = runVisit(argv)
2578
+ const visit = runVisit(values)
2223
2579
  if (visit === undefined) return 2
2224
- const output = argv.includes('--json') ? `${JSON.stringify(visit)}\n` : renderVisit(visit)
2225
- const out = readOption(argv, '--out')
2580
+ const output = values.json === true ? `${JSON.stringify(visit)}\n` : renderVisit(visit)
2581
+ const out = typeof values.out === 'string' ? values.out : undefined
2226
2582
  if (out === undefined) process.stdout.write(output)
2227
2583
  else {
2228
2584
  mkdirSync(dirname(out), { recursive: true })