@aiwayds/dsh-opentui 0.17.3 → 0.18.1
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/CHANGELOG.md +29 -0
- package/README.md +61 -0
- package/bin/dsh-opentui.mjs +43 -2
- package/bin/lib/launcher.mjs +129 -1
- package/dist/client/index.js +1 -1
- package/package.json +1 -1
- package/scripts/lib/provision-plan.mjs +150 -7
- package/scripts/lib/provision-state.mjs +294 -0
- package/scripts/lib/upgrade-plan.mjs +406 -0
- package/scripts/provision-opentui-profile.mjs +239 -20
- package/scripts/upgrade.mjs +947 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.18.1] - 2026-11-16
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **Provisioning stops re-installing a pin that cannot be reached.** Consecutive install failures are recorded per pin in `<profile>/.provision-state.json`; a failing pin backs off for 10 minutes and is skipped after 3 attempts, and the record resets after 24 hours. A missing or unreadable state file is read as "no memory", so the old behavior is the fallback.
|
|
13
|
+
- **`dsh plugin add` is verified by readback, not by its exit code.** After the install, provisioning reads the version that actually landed in `node_modules` and compares it with the effective pin (including a newer version raised by an `upgrade` override); a batch that exits 0 while leaving a package at another version no longer counts as installed.
|
|
14
|
+
- **Skipped and degraded plugins are named.** Each one gets a one-line notice with the state file path and a `dsh-opentui upgrade` suggestion; provisioning still exits 0 and the launcher still starts, so a degraded profile does not block boot.
|
|
15
|
+
- **A successful upgrade leaves no empty `.upgrade-backup` directory.** The stamp directory is removed and then its parent only when empty.
|
|
16
|
+
|
|
17
|
+
### Internal
|
|
18
|
+
|
|
19
|
+
- **stub-`dsh` integration tests for the provisioning script** (`test/provision-script.test.ts`), running the real script end to end against a stub host CLI offline.
|
|
20
|
+
|
|
21
|
+
## [0.18.0] - 2026-11-16
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- **`upgrade` subcommand.** `dsh-opentui upgrade` moves the launcher and the opentui profile's plugins to the latest npm version, with `--dry-run`, a confirmation prompt, backup/rollback on a failed install, and an `upgrade-overrides.json` that stops provisioning from restoring the shipped pins.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- **A profile upgrade survives the next start.** Provisioning now reads `upgrade-overrides.json` from the profile and treats the versions recorded there as the effective pins, so a plugin installed past its built-in pin is no longer replaced by it on the following boot. A missing file keeps the old behavior, and an unreadable one degrades to the shipped pins with a warning.
|
|
30
|
+
- **An undeterminable target version fails the run.** When the registry query cannot resolve a package, `upgrade` exits non-zero and writes nothing — no `node_modules` change, no lockfile, no override file, `--dry-run` included — instead of reporting success.
|
|
31
|
+
- **A dead registry is answered in one request.** The version query runs with `--fetch-retries 0 --fetch-timeout 20000`, so an unreachable host reports `query-failed` without npm's retry ladder.
|
|
32
|
+
|
|
33
|
+
### Internal
|
|
34
|
+
|
|
35
|
+
- **`11-upgrade` e2e scenario** against a local registry fixture (`e2e/fixtures/upgrade-registry`), covering the profile upgrade path from query through `upgrade-overrides.json` to the next provision.
|
|
36
|
+
|
|
8
37
|
## [0.17.3] - 2026-11-16
|
|
9
38
|
|
|
10
39
|
### Added
|
package/README.md
CHANGED
|
@@ -33,6 +33,67 @@ npm i -g @aiwayds/dsh-opentui
|
|
|
33
33
|
dsh-opentui
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
## Upgrading
|
|
37
|
+
|
|
38
|
+
`dsh-opentui upgrade` moves the installed launcher itself to the newest npm
|
|
39
|
+
release (or another dist-tag via `--tag`) and upgrades the registry plugins
|
|
40
|
+
already installed in the `opentui` profile to their latest versions. It does
|
|
41
|
+
**not** upgrade the dsh host: the host is a separate global install.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
dsh-opentui upgrade --dry-run # print the plan table, write nothing
|
|
45
|
+
dsh-opentui upgrade # confirm, then apply
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
| Flag | Effect |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `--dry-run` | Print the plan table and exit; nothing is installed or written. |
|
|
51
|
+
| `-y`, `--yes` | Skip the confirmation prompt. Required when stdin is not a TTY. |
|
|
52
|
+
| `--tag <name>` | Resolve a dist-tag other than `latest` (`next`, for example). |
|
|
53
|
+
| `--no-self` | Skip the launcher; upgrade profile plugins only. |
|
|
54
|
+
| `--no-plugins` | Skip profile plugins; upgrade the launcher only. |
|
|
55
|
+
| `--reset-overrides` | Delete `upgrade-overrides.json` and exit (terminal; cannot be combined with `--no-self` / `--no-plugins`). |
|
|
56
|
+
| `-h`, `--help` | Print usage and exit. |
|
|
57
|
+
|
|
58
|
+
| Exit code | Meaning |
|
|
59
|
+
|---|---|
|
|
60
|
+
| `0` | Completed, nothing to upgrade, or `--dry-run` / `--help`. |
|
|
61
|
+
| `1` | Hard failure, already rolled back; a target version that cannot be resolved writes nothing. |
|
|
62
|
+
| `2` | Usage error. |
|
|
63
|
+
| `3` | Partial: some packages did not reach the target version, or overrides could not be recorded. |
|
|
64
|
+
|
|
65
|
+
### Why upgrades stick (upgrade-overrides)
|
|
66
|
+
|
|
67
|
+
Provisioning runs on every launch and converges the profile to the shipped
|
|
68
|
+
pins, so a plain upgrade would be undone on the next start. After a successful
|
|
69
|
+
upgrade the command records the new versions in
|
|
70
|
+
`$DSH_HOME/profiles/opentui/upgrade-overrides.json`, and provisioning honors
|
|
71
|
+
each entry instead of the pin. An entry applies only while it is **strictly
|
|
72
|
+
newer** than the built-in pin, so a later release that raises the pin past it
|
|
73
|
+
invalidates the entry by itself.
|
|
74
|
+
|
|
75
|
+
`--reset-overrides` deletes that file and exits. The next launch provisions
|
|
76
|
+
from the shipped pins again, which can **downgrade** a package the override
|
|
77
|
+
was holding above them.
|
|
78
|
+
|
|
79
|
+
### Mirrors
|
|
80
|
+
|
|
81
|
+
Queries go to `DSH_UPGRADE_REGISTRY` when set, otherwise the profile
|
|
82
|
+
`.npmrc`, `~/.npmrc`, or the public npm registry, always with
|
|
83
|
+
`--prefer-online`. A mirror's `latest` can lag behind npmjs; the command
|
|
84
|
+
prints a note when it resolves through one.
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
DSH_UPGRADE_REGISTRY=https://registry.npmmirror.com dsh-opentui upgrade --dry-run
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### After upgrading
|
|
91
|
+
|
|
92
|
+
Quit the TUI and run `dsh-opentui` again. The host is a long-running process
|
|
93
|
+
and keeps the plugin set it booted with, so a plugin upgrade never applies to
|
|
94
|
+
the current one. CI and scripted runs must pass `--yes` — without a TTY the
|
|
95
|
+
confirmation prompt is refused.
|
|
96
|
+
|
|
36
97
|
## Client mode
|
|
37
98
|
|
|
38
99
|
`dsh-opentui` starts a thin client TUI (`dist/client/index.js` under Bun) that
|
package/bin/dsh-opentui.mjs
CHANGED
|
@@ -51,8 +51,8 @@ import { spawnSync } from 'node:child_process'
|
|
|
51
51
|
import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
52
52
|
import { homedir } from 'node:os'
|
|
53
53
|
import { dirname, join } from 'node:path'
|
|
54
|
-
import { fileURLToPath } from 'node:url'
|
|
55
|
-
import { ancestorPids, killStaleProcesses, parseLauncherArgs, parseProcessHomes, parseProcessRows, readLauncherVersion, selectStaleProcesses } from './lib/launcher.mjs'
|
|
54
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
55
|
+
import { ancestorPids, formatUpgradeUsage, killStaleProcesses, parseLauncherArgs, parseProcessHomes, parseProcessRows, parseUpgradeArgs, readLauncherVersion, selectStaleProcesses } from './lib/launcher.mjs'
|
|
56
56
|
|
|
57
57
|
const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)))
|
|
58
58
|
const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
@@ -82,6 +82,47 @@ if (versionFlag) {
|
|
|
82
82
|
process.exit(0)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// --- 0.5 upgrade subcommand -------------------------------------------------
|
|
86
|
+
// `upgrade` is a positional subcommand: only the first remaining argument may
|
|
87
|
+
// select it, and here is its ONLY consumer. It must never reach the provision
|
|
88
|
+
// forwarder (step 3) or the client (step 6) — the client would take the bare
|
|
89
|
+
// `upgrade` for a session name. Placed after `--version` (whose absolute
|
|
90
|
+
// short-circuit is unchanged) and BEFORE the bun/dsh checks: upgrading needs
|
|
91
|
+
// `npm` and `dsh`, not bun, and must not provision or link anything.
|
|
92
|
+
const upgradeResult = parseUpgradeArgs(userArgs)
|
|
93
|
+
if (upgradeResult.isUpgrade) {
|
|
94
|
+
if (forceFlag) {
|
|
95
|
+
console.error('dsh-opentui: --force is not supported with upgrade.')
|
|
96
|
+
console.error(formatUpgradeUsage())
|
|
97
|
+
process.exit(2)
|
|
98
|
+
}
|
|
99
|
+
if (upgradeResult.error === 'unknown-flag') {
|
|
100
|
+
console.error(`dsh-opentui: unknown flag(s): ${upgradeResult.unknownFlags.join(', ')}`)
|
|
101
|
+
console.error(formatUpgradeUsage())
|
|
102
|
+
process.exit(2)
|
|
103
|
+
}
|
|
104
|
+
if (upgradeResult.error === 'missing-tag-value') {
|
|
105
|
+
console.error('dsh-opentui: --tag requires a non-empty value.')
|
|
106
|
+
console.error(formatUpgradeUsage())
|
|
107
|
+
process.exit(2)
|
|
108
|
+
}
|
|
109
|
+
if (upgradeResult.error === 'invalid-tag') {
|
|
110
|
+
console.error(
|
|
111
|
+
`dsh-opentui: invalid --tag value: ${upgradeResult.invalidTag} (allowed: A-Z a-z 0-9 . _ -)`,
|
|
112
|
+
)
|
|
113
|
+
console.error(formatUpgradeUsage())
|
|
114
|
+
process.exit(2)
|
|
115
|
+
}
|
|
116
|
+
if (upgradeResult.error === 'reset-overrides-conflict') {
|
|
117
|
+
console.error('dsh-opentui: --reset-overrides cannot be combined with --no-self or --no-plugins.')
|
|
118
|
+
console.error(formatUpgradeUsage())
|
|
119
|
+
process.exit(2)
|
|
120
|
+
}
|
|
121
|
+
// Loaded lazily so a normal launch never evaluates the upgrade body.
|
|
122
|
+
const { runUpgrade } = await import(pathToFileURL(join(pkgRoot, 'scripts', 'upgrade.mjs')).href)
|
|
123
|
+
process.exit(runUpgrade(upgradeResult.opts, { pkgRoot }))
|
|
124
|
+
}
|
|
125
|
+
|
|
85
126
|
// --- 1. bun: hard runtime dependency of the client chain -------------------
|
|
86
127
|
if (!spawnSync('which', ['bun'], { encoding: 'utf8' }).stdout.trim()) {
|
|
87
128
|
exitWithGuidance('bun', 'npm i -g bun')
|
package/bin/lib/launcher.mjs
CHANGED
|
@@ -7,11 +7,15 @@
|
|
|
7
7
|
* plain data so the flags can be unit-tested without a dsh, a profile or a
|
|
8
8
|
* running client. The bin stays the only thing that touches the process.
|
|
9
9
|
*
|
|
10
|
-
* The
|
|
10
|
+
* The capabilities:
|
|
11
11
|
* 1. `--version` — print `dsh-opentui <version>` and exit 0, BEFORE any
|
|
12
12
|
* provision/profile work (see the bin's step 0).
|
|
13
13
|
* 2. `--force` — kill this profile's stale instances (the resident `dsh
|
|
14
14
|
* host and the bun client) before starting.
|
|
15
|
+
* 3. `upgrade` — the positional upgrade subcommand: its argv is parsed
|
|
16
|
+
* here (pure) and dispatched by the bin to scripts/upgrade.mjs. The
|
|
17
|
+
* subcommand and its flags are consumed by the bin and NEVER forwarded
|
|
18
|
+
* to the client (which would take them for a session name).
|
|
15
19
|
*
|
|
16
20
|
* SCOPE (requirement: never touch another profile's instances):
|
|
17
21
|
* a candidate is "ours" only when BOTH hold:
|
|
@@ -281,3 +285,127 @@ export async function killStaleProcesses(targets, options = {}) {
|
|
|
281
285
|
survivors: survivors.filter((pid) => isAlive(pid)),
|
|
282
286
|
}
|
|
283
287
|
}
|
|
288
|
+
|
|
289
|
+
/** The dist-tag `upgrade` resolves against when none is given. */
|
|
290
|
+
export const UPGRADE_DEFAULT_TAG = 'latest'
|
|
291
|
+
// The tag becomes an argv value for `npm view` and must never be able to look
|
|
292
|
+
// like a flag or carry shell/URL syntax: npm dist-tags are [A-Za-z0-9._-].
|
|
293
|
+
const TAG_PATTERN = /^[A-Za-z0-9._-]+$/
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Parse the argv of the `upgrade` subcommand.
|
|
297
|
+
*
|
|
298
|
+
* The subcommand is POSITIONAL and must be the first argument the launcher
|
|
299
|
+
* sees after `parseLauncherArgs` consumed `--version`/`--force`. A `upgrade`
|
|
300
|
+
* anywhere else (`foo upgrade`, `--model upgrade`) is NOT the subcommand: the
|
|
301
|
+
* argument vector is forwarded to the client exactly as before (requirement:
|
|
302
|
+
* an old release silently ignores a stray positional, and this release must
|
|
303
|
+
* not turn that into an error).
|
|
304
|
+
*
|
|
305
|
+
* `--force` is deliberately absent here — `parseLauncherArgs` consumes it
|
|
306
|
+
* before this function runs, so it can never reach an upgrade flag parse. The
|
|
307
|
+
* bin rejects the `--force upgrade` combination itself (a usage error).
|
|
308
|
+
*
|
|
309
|
+
* Unknown flags are reported once as `error: 'unknown-flag'` with the offending
|
|
310
|
+
* tokens in `unknownFlags`; the caller prints the usage and exits 2 without
|
|
311
|
+
* doing anything. `--reset-overrides` is a terminal action and is incompatible
|
|
312
|
+
* with every flag that shapes an upgrade (`--no-self`/`--no-plugins`/`--yes`
|
|
313
|
+
* and a non-default `--tag`): combining them would silently ignore one intent.
|
|
314
|
+
*
|
|
315
|
+
* @param {string[]} argv arguments after the bin-level flags
|
|
316
|
+
* @returns {{ isUpgrade: boolean, opts: {
|
|
317
|
+
* dryRun: boolean, yes: boolean, tag: string, noSelf: boolean,
|
|
318
|
+
* noPlugins: boolean, resetOverrides: boolean, help: boolean,
|
|
319
|
+
* }, error: null | 'unknown-flag' | 'missing-tag-value' | 'invalid-tag' |
|
|
320
|
+
* 'reset-overrides-conflict', unknownFlags?: string[], invalidTag?: string }}
|
|
321
|
+
*/
|
|
322
|
+
export function parseUpgradeArgs(argv) {
|
|
323
|
+
const args = Array.isArray(argv) ? argv : []
|
|
324
|
+
const opts = {
|
|
325
|
+
dryRun: false,
|
|
326
|
+
yes: false,
|
|
327
|
+
tag: UPGRADE_DEFAULT_TAG,
|
|
328
|
+
noSelf: false,
|
|
329
|
+
noPlugins: false,
|
|
330
|
+
resetOverrides: false,
|
|
331
|
+
help: false,
|
|
332
|
+
}
|
|
333
|
+
// Positional contract: only argv[0] selects the subcommand.
|
|
334
|
+
if (args[0] !== 'upgrade') return { isUpgrade: false, opts, error: null }
|
|
335
|
+
|
|
336
|
+
const unknownFlags = []
|
|
337
|
+
// Presence, not value: `--reset-overrides --tag latest` is still two
|
|
338
|
+
// intents, and the conflict report must not depend on the tag's spelling.
|
|
339
|
+
let tagGiven = false
|
|
340
|
+
for (let i = 1; i < args.length; i++) {
|
|
341
|
+
const arg = args[i]
|
|
342
|
+
if (arg === '--dry-run') {
|
|
343
|
+
opts.dryRun = true
|
|
344
|
+
} else if (arg === '-y' || arg === '--yes') {
|
|
345
|
+
opts.yes = true
|
|
346
|
+
} else if (arg === '--no-self') {
|
|
347
|
+
opts.noSelf = true
|
|
348
|
+
} else if (arg === '--no-plugins') {
|
|
349
|
+
opts.noPlugins = true
|
|
350
|
+
} else if (arg === '--reset-overrides') {
|
|
351
|
+
opts.resetOverrides = true
|
|
352
|
+
} else if (arg === '-h' || arg === '--help') {
|
|
353
|
+
opts.help = true
|
|
354
|
+
} else if (arg === '--tag') {
|
|
355
|
+
const value = args[i + 1]
|
|
356
|
+
if (value === undefined || value.startsWith('-')) {
|
|
357
|
+
return { isUpgrade: true, opts, error: 'missing-tag-value' }
|
|
358
|
+
}
|
|
359
|
+
if (!TAG_PATTERN.test(value)) {
|
|
360
|
+
return { isUpgrade: true, opts, error: 'invalid-tag', invalidTag: value }
|
|
361
|
+
}
|
|
362
|
+
opts.tag = value
|
|
363
|
+
tagGiven = true
|
|
364
|
+
i++
|
|
365
|
+
} else if (arg.startsWith('--tag=')) {
|
|
366
|
+
const value = arg.slice('--tag='.length)
|
|
367
|
+
if (value === '') return { isUpgrade: true, opts, error: 'missing-tag-value' }
|
|
368
|
+
if (!TAG_PATTERN.test(value)) {
|
|
369
|
+
return { isUpgrade: true, opts, error: 'invalid-tag', invalidTag: value }
|
|
370
|
+
}
|
|
371
|
+
opts.tag = value
|
|
372
|
+
tagGiven = true
|
|
373
|
+
} else {
|
|
374
|
+
unknownFlags.push(arg)
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (unknownFlags.length > 0) {
|
|
379
|
+
return { isUpgrade: true, opts, error: 'unknown-flag', unknownFlags }
|
|
380
|
+
}
|
|
381
|
+
if (opts.resetOverrides && (opts.noSelf || opts.noPlugins || opts.yes || tagGiven)) {
|
|
382
|
+
return { isUpgrade: true, opts, error: 'reset-overrides-conflict' }
|
|
383
|
+
}
|
|
384
|
+
return { isUpgrade: true, opts, error: null }
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Usage text for `dsh-opentui upgrade` (also the `--help` body). Plain text,
|
|
388
|
+
* one flag per line; the exit-code block is part of the contract. */
|
|
389
|
+
export function formatUpgradeUsage() {
|
|
390
|
+
return [
|
|
391
|
+
'dsh-opentui upgrade — upgrade the launcher and the opentui profile plugins',
|
|
392
|
+
'',
|
|
393
|
+
'Usage: dsh-opentui upgrade [options]',
|
|
394
|
+
'',
|
|
395
|
+
'Options:',
|
|
396
|
+
' --dry-run print the plan and exit; write nothing',
|
|
397
|
+
' -y, --yes do not ask for confirmation',
|
|
398
|
+
' --tag <name> dist-tag to resolve (default: latest)',
|
|
399
|
+
' --no-self skip the dsh-opentui launcher itself',
|
|
400
|
+
' --no-plugins skip the opentui profile plugins',
|
|
401
|
+
' --reset-overrides delete upgrade-overrides.json and exit (terminal;',
|
|
402
|
+
' conflicts with --no-self/--no-plugins/--yes/--tag)',
|
|
403
|
+
' -h, --help print this help and exit',
|
|
404
|
+
'',
|
|
405
|
+
'Exit codes:',
|
|
406
|
+
' 0 already up to date, nothing to do, --dry-run, or --help',
|
|
407
|
+
' 1 hard failure (e.g. self-upgrade did not verify); profile untouched/rolled back',
|
|
408
|
+
' 2 usage error',
|
|
409
|
+
' 3 partial: a package did not reach the target version, or overrides could not be recorded',
|
|
410
|
+
].join('\n')
|
|
411
|
+
}
|
package/dist/client/index.js
CHANGED
|
@@ -59745,7 +59745,7 @@ var init_subagents_viewer = __esm(() => {
|
|
|
59745
59745
|
import { TextAttributes as TextAttributes12 } from "@opentui/core";
|
|
59746
59746
|
function resolveVersion() {
|
|
59747
59747
|
try {
|
|
59748
|
-
return "0.
|
|
59748
|
+
return "0.18.1";
|
|
59749
59749
|
} catch {
|
|
59750
59750
|
return "dev";
|
|
59751
59751
|
}
|
package/package.json
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
// fixtures. That split is what makes the idempotency rules (dep present,
|
|
6
6
|
// node_modules version satisfies, bundle entry present) testable without a
|
|
7
7
|
// network or a real dsh profile.
|
|
8
|
+
//
|
|
9
|
+
// The failure-memory policy lives in ./provision-state.mjs (also pure); this
|
|
10
|
+
// module only applies it to a plan, so "which specs does this launch actually
|
|
11
|
+
// run" is testable end to end without a profile.
|
|
12
|
+
|
|
13
|
+
import { shouldSkipRetry } from './provision-state.mjs'
|
|
8
14
|
|
|
9
15
|
export const PROFILE = 'opentui'
|
|
10
16
|
export const PREFIX = 'provision-opentui-profile: '
|
|
@@ -29,7 +35,7 @@ export const PLUGIN_SET = [
|
|
|
29
35
|
},
|
|
30
36
|
{
|
|
31
37
|
name: '@aiwayds/dsh-subagent-registry',
|
|
32
|
-
version: '0.20.
|
|
38
|
+
version: '0.20.1',
|
|
33
39
|
tier: 'core',
|
|
34
40
|
reason: 'subagent discovery and registration for the shell',
|
|
35
41
|
},
|
|
@@ -89,7 +95,7 @@ export const PLUGIN_SET = [
|
|
|
89
95
|
},
|
|
90
96
|
{
|
|
91
97
|
name: '@aiwayds/dsh-vault',
|
|
92
|
-
version: '0.8.
|
|
98
|
+
version: '0.8.2',
|
|
93
99
|
tier: 'recommended',
|
|
94
100
|
reason: 'secret storage used by the companion plugins',
|
|
95
101
|
},
|
|
@@ -343,6 +349,59 @@ export function isLocalSpec(spec) {
|
|
|
343
349
|
return typeof spec === 'string' && /^(?:link|file|workspace|portal):/.test(spec)
|
|
344
350
|
}
|
|
345
351
|
|
|
352
|
+
// ---------------------------------------------------------------------------
|
|
353
|
+
// upgrade-overrides: the profile's "do not downgrade me" list
|
|
354
|
+
//
|
|
355
|
+
// `dsh-opentui upgrade` installs versions newer than the shipped pins and
|
|
356
|
+
// records them in `$DSH_HOME/profiles/opentui/upgrade-overrides.json`, because
|
|
357
|
+
// provisioning runs on EVERY start and would otherwise pull the profile back
|
|
358
|
+
// to the pins. The file is a side manifest, not a relaxation of the pins:
|
|
359
|
+
//
|
|
360
|
+
// {
|
|
361
|
+
// "version": 1,
|
|
362
|
+
// "updatedAt": "<iso>",
|
|
363
|
+
// "packages": {
|
|
364
|
+
// "@aiwayds/dsh-cron": { "version": "0.7.2", "shippedPin": "0.7.0", "updatedAt": "<iso>" }
|
|
365
|
+
// }
|
|
366
|
+
// }
|
|
367
|
+
//
|
|
368
|
+
// An override raises the effective pin ONLY when it is strictly newer than the
|
|
369
|
+
// shipped pin: once a release raises the pin past the override, the override
|
|
370
|
+
// stops applying by itself and the shipped pin wins again — a stale override
|
|
371
|
+
// can never downgrade a profile.
|
|
372
|
+
// ---------------------------------------------------------------------------
|
|
373
|
+
|
|
374
|
+
/** The versions a shipped pin may be raised to by an override. Lookup is by
|
|
375
|
+
* package name, so an entry for a package this launcher does not manage can
|
|
376
|
+
* never take effect (PLUGIN_SET is the allowlist). */
|
|
377
|
+
const OVERRIDEABLE_PLUGINS = new Set(PLUGIN_SET.map((plugin) => plugin.name))
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* The version a managed plugin must be installed at: the shipped pin, or the
|
|
381
|
+
* override version when the profile carries a VALID override that is strictly
|
|
382
|
+
* newer than the pin.
|
|
383
|
+
*
|
|
384
|
+
* An override is ignored (the shipped pin is returned) when any of these holds:
|
|
385
|
+
* - `name` is not in PLUGIN_SET (unknown keys are silently ignored)
|
|
386
|
+
* - the entry is not an object, or its `version` is not a semver string
|
|
387
|
+
* - the override version equals or precedes the shipped pin
|
|
388
|
+
*
|
|
389
|
+
* @param {{name: string, shippedPin: string, overrides?: Record<string, {version?: string}>}} input
|
|
390
|
+
* @returns {string} the effective pin
|
|
391
|
+
*/
|
|
392
|
+
export function resolveEffectivePin({ name, shippedPin, overrides = {} }) {
|
|
393
|
+
if (!OVERRIDEABLE_PLUGINS.has(name)) return shippedPin
|
|
394
|
+
if (typeof overrides !== 'object' || overrides === null || Array.isArray(overrides)) return shippedPin
|
|
395
|
+
const entry = overrides[name]
|
|
396
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) return shippedPin
|
|
397
|
+
const parsed = typeof entry.version === 'string' ? parseVersion(entry.version) : null
|
|
398
|
+
if (parsed === null) return shippedPin
|
|
399
|
+
// Canonical form so an install spec never carries a `v` prefix or build
|
|
400
|
+
// metadata (`pkg@v1.2.3` is not a version pnpm resolves reliably).
|
|
401
|
+
const candidate = `${parsed.major}.${parsed.minor}.${parsed.patch}${parsed.pre.length ? `-${parsed.pre.join('.')}` : ''}`
|
|
402
|
+
return compareVersions(candidate, shippedPin) > 0 ? candidate : shippedPin
|
|
403
|
+
}
|
|
404
|
+
|
|
346
405
|
// ---------------------------------------------------------------------------
|
|
347
406
|
// Plan
|
|
348
407
|
// ---------------------------------------------------------------------------
|
|
@@ -354,11 +413,14 @@ export function isLocalSpec(spec) {
|
|
|
354
413
|
* Idempotency rule (all three must hold for a plugin to count as satisfied):
|
|
355
414
|
* 1. the package is a `dependencies` entry in the profile manifest
|
|
356
415
|
* 2. `node_modules/<pkg>/package.json` exists (its version is passed in)
|
|
357
|
-
* 3. that version satisfies the
|
|
416
|
+
* 3. that version satisfies the effective pin (see resolveEffectivePin)
|
|
358
417
|
* A dep pinned with a local spec (link/file/workspace) skips 2/3: the local
|
|
359
418
|
* pin wins and is never replaced.
|
|
360
419
|
*
|
|
361
|
-
*
|
|
420
|
+
* `overrides` is optional and empty by default, so a profile without the
|
|
421
|
+
* upgrade-overrides manifest plans exactly as it did before overrides existed.
|
|
422
|
+
*
|
|
423
|
+
* @param {{tier: string, dependencies?: Record<string,string>, bundles?: string[], installedVersions?: Record<string,string>, overrides?: Record<string,{version?: string}>}} input
|
|
362
424
|
* @returns {{
|
|
363
425
|
* total: number,
|
|
364
426
|
* satisfied: number,
|
|
@@ -367,18 +429,22 @@ export function isLocalSpec(spec) {
|
|
|
367
429
|
* managedOrder: string[],
|
|
368
430
|
* }}
|
|
369
431
|
*/
|
|
370
|
-
export function planPluginInstall({ tier, dependencies = {}, bundles = [], installedVersions = {} }) {
|
|
432
|
+
export function planPluginInstall({ tier, dependencies = {}, bundles = [], installedVersions = {}, overrides = {} }) {
|
|
371
433
|
const plugins = selectPlugins(tier)
|
|
372
434
|
const install = []
|
|
373
435
|
const missingBundles = []
|
|
374
436
|
const managedOrder = plugins.map((plugin) => plugin.name)
|
|
375
437
|
|
|
376
438
|
for (const plugin of plugins) {
|
|
439
|
+
const effectivePin = resolveEffectivePin({ name: plugin.name, shippedPin: plugin.version, overrides })
|
|
377
440
|
const depSpec = dependencies[plugin.name]
|
|
378
441
|
const installed = installedVersions[plugin.name]
|
|
379
|
-
const depOk = depSpec !== undefined && (isLocalSpec(depSpec) || satisfiesVersion(installed,
|
|
442
|
+
const depOk = depSpec !== undefined && (isLocalSpec(depSpec) || satisfiesVersion(installed, effectivePin))
|
|
380
443
|
if (!depOk) {
|
|
381
|
-
|
|
444
|
+
// `pin` is the EFFECTIVE pin (shipped pin or a newer override), so the
|
|
445
|
+
// caller can compare the installed version and the failure state against
|
|
446
|
+
// exactly the version this install asked for.
|
|
447
|
+
install.push({ name: plugin.name, pin: effectivePin, spec: `${plugin.name}@${effectivePin}`, reason: plugin.reason })
|
|
382
448
|
continue
|
|
383
449
|
}
|
|
384
450
|
if (!bundles.includes(plugin.name)) missingBundles.push(plugin.name)
|
|
@@ -394,6 +460,83 @@ export function planPluginInstall({ tier, dependencies = {}, bundles = [], insta
|
|
|
394
460
|
}
|
|
395
461
|
}
|
|
396
462
|
|
|
463
|
+
/**
|
|
464
|
+
* Split a plan's install rows into the specs this launch runs and the pins it
|
|
465
|
+
* skips after repeated failures (see provision-state.mjs for the policy:
|
|
466
|
+
* backoff, attempt cap, 24-hour reset).
|
|
467
|
+
*
|
|
468
|
+
* The pin compared is `row.pin` — the EFFECTIVE pin computed by
|
|
469
|
+
* planPluginInstall. Using the shipped pin here would make an override-raised
|
|
470
|
+
* package look permanently failed: its install spec says 0.7.2 while the
|
|
471
|
+
* recorded failure (from an older launch) says 0.7.0.
|
|
472
|
+
*
|
|
473
|
+
* Pure: `state` is the parsed state document, `now` a Date / ISO string /
|
|
474
|
+
* epoch ms. Returns the surviving rows and one summary row per skipped pin.
|
|
475
|
+
*
|
|
476
|
+
* @param {{
|
|
477
|
+
* install?: Array<{name: string, pin: string, spec: string}>,
|
|
478
|
+
* state?: object|null,
|
|
479
|
+
* now?: Date|string|number,
|
|
480
|
+
* backoffMs?: number,
|
|
481
|
+
* maxAttempts?: number,
|
|
482
|
+
* }} input
|
|
483
|
+
* @returns {{
|
|
484
|
+
* install: Array<{name: string, pin: string, spec: string}>,
|
|
485
|
+
* skips: Array<{name: string, pin: string, reason: string, attempts: number, lastFailedAt: string}>,
|
|
486
|
+
* }}
|
|
487
|
+
*/
|
|
488
|
+
export function partitionInstallByRetryState({ install = [], state, now, backoffMs, maxAttempts } = {}) {
|
|
489
|
+
const pending = []
|
|
490
|
+
const skips = []
|
|
491
|
+
for (const row of Array.isArray(install) ? install : []) {
|
|
492
|
+
if (!row || typeof row.name !== 'string' || row.name === '') {
|
|
493
|
+
pending.push(row)
|
|
494
|
+
continue
|
|
495
|
+
}
|
|
496
|
+
const pin = typeof row.pin === 'string' && row.pin !== '' ? row.pin : specPin(row.spec)
|
|
497
|
+
const verdict = shouldSkipRetry({ state, name: row.name, pin, now, backoffMs, maxAttempts })
|
|
498
|
+
if (!verdict.skip) {
|
|
499
|
+
pending.push(pin === row.pin ? row : { ...row, pin })
|
|
500
|
+
continue
|
|
501
|
+
}
|
|
502
|
+
skips.push({
|
|
503
|
+
name: row.name,
|
|
504
|
+
pin: verdict.entry.pin,
|
|
505
|
+
reason: verdict.reason,
|
|
506
|
+
attempts: verdict.entry.attempts,
|
|
507
|
+
lastFailedAt: verdict.entry.lastFailedAt,
|
|
508
|
+
})
|
|
509
|
+
}
|
|
510
|
+
return { install: pending, skips }
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/** `@scope/pkg@1.2.3` -> `1.2.3`. Only a fallback for rows without `pin`. */
|
|
514
|
+
function specPin(spec) {
|
|
515
|
+
if (typeof spec !== 'string') return ''
|
|
516
|
+
const at = spec.lastIndexOf('@')
|
|
517
|
+
return at > 0 ? spec.slice(at + 1) : ''
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Compare the versions that actually landed against the plan's effective pins.
|
|
522
|
+
* Exact match only: `dsh plugin add` was asked for an exact version, so a
|
|
523
|
+
* newer or older version is a degraded install, not a satisfied one.
|
|
524
|
+
*
|
|
525
|
+
* @param {{
|
|
526
|
+
* install?: Array<{name: string, pin: string}>,
|
|
527
|
+
* installedVersions?: Record<string, string|undefined>,
|
|
528
|
+
* }} input
|
|
529
|
+
* @returns {Array<{name: string, pin: string, installed: string|null, ok: boolean}>}
|
|
530
|
+
*/
|
|
531
|
+
export function verifyInstalledPins({ install = [], installedVersions = {} } = {}) {
|
|
532
|
+
const versions = installedVersions && typeof installedVersions === 'object' ? installedVersions : {}
|
|
533
|
+
return (Array.isArray(install) ? install : []).map((row) => {
|
|
534
|
+
const actual = row && typeof row.name === 'string' ? versions[row.name] : undefined
|
|
535
|
+
const installed = typeof actual === 'string' && actual !== '' ? actual : null
|
|
536
|
+
return { name: row?.name, pin: row?.pin, installed, ok: installed !== null && installed === row?.pin }
|
|
537
|
+
})
|
|
538
|
+
}
|
|
539
|
+
|
|
397
540
|
/**
|
|
398
541
|
* Merge bundle selection: drop retired entries, append missing managed
|
|
399
542
|
* entries, and keep the managed subset in `managedOrder` (the ask-router-first
|