@aiwayds/dsh-opentui 0.17.3 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,22 @@ 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.0] - 2026-11-16
9
+
10
+ ### Added
11
+
12
+ - **`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.
13
+
14
+ ### Fixed
15
+
16
+ - **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.
17
+ - **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.
18
+ - **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.
19
+
20
+ ### Internal
21
+
22
+ - **`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.
23
+
8
24
  ## [0.17.3] - 2026-11-16
9
25
 
10
26
  ### 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
@@ -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')
@@ -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 two capabilities:
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
+ }
@@ -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.17.3";
59748
+ return "0.18.0";
59749
59749
  } catch {
59750
59750
  return "dev";
59751
59751
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiwayds/dsh-opentui",
3
- "version": "0.17.3",
3
+ "version": "0.18.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "bin": {
@@ -29,7 +29,7 @@ export const PLUGIN_SET = [
29
29
  },
30
30
  {
31
31
  name: '@aiwayds/dsh-subagent-registry',
32
- version: '0.20.0',
32
+ version: '0.20.1',
33
33
  tier: 'core',
34
34
  reason: 'subagent discovery and registration for the shell',
35
35
  },
@@ -89,7 +89,7 @@ export const PLUGIN_SET = [
89
89
  },
90
90
  {
91
91
  name: '@aiwayds/dsh-vault',
92
- version: '0.8.0',
92
+ version: '0.8.2',
93
93
  tier: 'recommended',
94
94
  reason: 'secret storage used by the companion plugins',
95
95
  },
@@ -343,6 +343,59 @@ export function isLocalSpec(spec) {
343
343
  return typeof spec === 'string' && /^(?:link|file|workspace|portal):/.test(spec)
344
344
  }
345
345
 
346
+ // ---------------------------------------------------------------------------
347
+ // upgrade-overrides: the profile's "do not downgrade me" list
348
+ //
349
+ // `dsh-opentui upgrade` installs versions newer than the shipped pins and
350
+ // records them in `$DSH_HOME/profiles/opentui/upgrade-overrides.json`, because
351
+ // provisioning runs on EVERY start and would otherwise pull the profile back
352
+ // to the pins. The file is a side manifest, not a relaxation of the pins:
353
+ //
354
+ // {
355
+ // "version": 1,
356
+ // "updatedAt": "<iso>",
357
+ // "packages": {
358
+ // "@aiwayds/dsh-cron": { "version": "0.7.2", "shippedPin": "0.7.0", "updatedAt": "<iso>" }
359
+ // }
360
+ // }
361
+ //
362
+ // An override raises the effective pin ONLY when it is strictly newer than the
363
+ // shipped pin: once a release raises the pin past the override, the override
364
+ // stops applying by itself and the shipped pin wins again — a stale override
365
+ // can never downgrade a profile.
366
+ // ---------------------------------------------------------------------------
367
+
368
+ /** The versions a shipped pin may be raised to by an override. Lookup is by
369
+ * package name, so an entry for a package this launcher does not manage can
370
+ * never take effect (PLUGIN_SET is the allowlist). */
371
+ const OVERRIDEABLE_PLUGINS = new Set(PLUGIN_SET.map((plugin) => plugin.name))
372
+
373
+ /**
374
+ * The version a managed plugin must be installed at: the shipped pin, or the
375
+ * override version when the profile carries a VALID override that is strictly
376
+ * newer than the pin.
377
+ *
378
+ * An override is ignored (the shipped pin is returned) when any of these holds:
379
+ * - `name` is not in PLUGIN_SET (unknown keys are silently ignored)
380
+ * - the entry is not an object, or its `version` is not a semver string
381
+ * - the override version equals or precedes the shipped pin
382
+ *
383
+ * @param {{name: string, shippedPin: string, overrides?: Record<string, {version?: string}>}} input
384
+ * @returns {string} the effective pin
385
+ */
386
+ export function resolveEffectivePin({ name, shippedPin, overrides = {} }) {
387
+ if (!OVERRIDEABLE_PLUGINS.has(name)) return shippedPin
388
+ if (typeof overrides !== 'object' || overrides === null || Array.isArray(overrides)) return shippedPin
389
+ const entry = overrides[name]
390
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) return shippedPin
391
+ const parsed = typeof entry.version === 'string' ? parseVersion(entry.version) : null
392
+ if (parsed === null) return shippedPin
393
+ // Canonical form so an install spec never carries a `v` prefix or build
394
+ // metadata (`pkg@v1.2.3` is not a version pnpm resolves reliably).
395
+ const candidate = `${parsed.major}.${parsed.minor}.${parsed.patch}${parsed.pre.length ? `-${parsed.pre.join('.')}` : ''}`
396
+ return compareVersions(candidate, shippedPin) > 0 ? candidate : shippedPin
397
+ }
398
+
346
399
  // ---------------------------------------------------------------------------
347
400
  // Plan
348
401
  // ---------------------------------------------------------------------------
@@ -354,11 +407,14 @@ export function isLocalSpec(spec) {
354
407
  * Idempotency rule (all three must hold for a plugin to count as satisfied):
355
408
  * 1. the package is a `dependencies` entry in the profile manifest
356
409
  * 2. `node_modules/<pkg>/package.json` exists (its version is passed in)
357
- * 3. that version satisfies the pinned version
410
+ * 3. that version satisfies the effective pin (see resolveEffectivePin)
358
411
  * A dep pinned with a local spec (link/file/workspace) skips 2/3: the local
359
412
  * pin wins and is never replaced.
360
413
  *
361
- * @param {{tier: string, dependencies?: Record<string,string>, bundles?: string[], installedVersions?: Record<string,string>}} input
414
+ * `overrides` is optional and empty by default, so a profile without the
415
+ * upgrade-overrides manifest plans exactly as it did before overrides existed.
416
+ *
417
+ * @param {{tier: string, dependencies?: Record<string,string>, bundles?: string[], installedVersions?: Record<string,string>, overrides?: Record<string,{version?: string}>}} input
362
418
  * @returns {{
363
419
  * total: number,
364
420
  * satisfied: number,
@@ -367,18 +423,19 @@ export function isLocalSpec(spec) {
367
423
  * managedOrder: string[],
368
424
  * }}
369
425
  */
370
- export function planPluginInstall({ tier, dependencies = {}, bundles = [], installedVersions = {} }) {
426
+ export function planPluginInstall({ tier, dependencies = {}, bundles = [], installedVersions = {}, overrides = {} }) {
371
427
  const plugins = selectPlugins(tier)
372
428
  const install = []
373
429
  const missingBundles = []
374
430
  const managedOrder = plugins.map((plugin) => plugin.name)
375
431
 
376
432
  for (const plugin of plugins) {
433
+ const effectivePin = resolveEffectivePin({ name: plugin.name, shippedPin: plugin.version, overrides })
377
434
  const depSpec = dependencies[plugin.name]
378
435
  const installed = installedVersions[plugin.name]
379
- const depOk = depSpec !== undefined && (isLocalSpec(depSpec) || satisfiesVersion(installed, plugin.version))
436
+ const depOk = depSpec !== undefined && (isLocalSpec(depSpec) || satisfiesVersion(installed, effectivePin))
380
437
  if (!depOk) {
381
- install.push({ name: plugin.name, spec: `${plugin.name}@${plugin.version}`, reason: plugin.reason })
438
+ install.push({ name: plugin.name, spec: `${plugin.name}@${effectivePin}`, reason: plugin.reason })
382
439
  continue
383
440
  }
384
441
  if (!bundles.includes(plugin.name)) missingBundles.push(plugin.name)