@aiwayds/dsh-opentui 0.27.2 → 0.28.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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Launcher support for bin/dsh-opentui.mjs — the pure parts behind the
3
- * `--version` / `--force` flags.
3
+ * `--version` / deprecated `--force` / `--yes` flags.
4
4
  *
5
5
  * WHY A SEPARATE MODULE: the bin is a top-level script (importing it would
6
6
  * RUN it — provision, spawn, exit). Everything here is a pure function over
@@ -10,20 +10,18 @@
10
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
- * 2. `--force` — reset the singleton host before starting (needs `--yes`
14
- * when live clients are connected; ADR-0009). Stale-instance cleanup is a
15
- * `--repair-bridge` maintenance action.
16
- * 3. `upgrade` — the positional upgrade subcommand: its argv is parsed
17
- * here (pure) and dispatched by the bin to scripts/upgrade.mjs. The
18
- * subcommand and its flags are consumed by the bin and NEVER forwarded
19
- * to the client (which would take them for a session name).
13
+ * 2. `--force` / `--yes` — deprecated no-ops in this in-process-only build.
14
+ * They remain parsed for compatibility but do not kill or reset anything;
15
+ * stale-instance cleanup belongs to `--repair-bridge`. Both flags will be
16
+ * removed in the next minor release.
20
17
  *
21
18
  * SCOPE (requirement: never touch another profile's instances):
22
19
  * a candidate is "ours" only when BOTH hold:
23
- * - the command line is the host/client shape of the `opentui` profile
24
- * (`node <...>/dsh --profile opentui ...` for the host; a bun process
25
- * running the client entry for the client). A `dsh plugin --profile
26
- * opentui add ...` provision child is NOT a host and never matches.
20
+ * - the command line is the host/client shape of the active in-process
21
+ * profile (`node <...>/dsh --profile opentui-monday ...` for the host; a
22
+ * bun process running the client entry for the client). A `dsh plugin
23
+ * --profile opentui-monday add ...` provision child is NOT a host and
24
+ * never matches.
27
25
  * - the process resolves to the SAME dsh home as this launcher (DSH_HOME
28
26
  * from the process environment, defaulting to ~/.dsh). The profile
29
27
  * instance is identified by (dsh home, profile) — the same key the
@@ -37,11 +35,12 @@
37
35
  import { readFileSync, realpathSync } from 'node:fs'
38
36
  import { homedir } from 'node:os'
39
37
  import { basename, join, resolve } from 'node:path'
38
+ import { DEFAULT_PROFILE } from '../../scripts/lib/profile-name.mjs'
40
39
 
41
- /** The one product profile (ADR-0005 decision 3). */
42
- export const PROFILE = 'opentui'
40
+ /** The one active in-process host profile (shared with the provisioner). */
41
+ export const PROFILE = DEFAULT_PROFILE
43
42
 
44
- /** The default dsh home when DSH_HOME is unset (mirrors lifecycle.ts). */
43
+ /** The default dsh home when DSH_HOME is unset. */
45
44
  export function defaultDshHome() {
46
45
  return join(homedir(), '.dsh')
47
46
  }
@@ -90,8 +89,8 @@ export function parseLauncherArgs(argv) {
90
89
  repairBridge = true
91
90
  continue
92
91
  }
93
- // `--yes` confirms a --force reset when live clients exist (ADR-0009 §7).
94
- // Consumed by the bin, never forwarded to dsh/the client.
92
+ // Deprecated alongside `--force`; no kill/reset side effect. Consumed by
93
+ // the bin, never forwarded to dsh/the client.
95
94
  if (arg === '--yes') {
96
95
  yes = true
97
96
  continue
@@ -108,17 +107,8 @@ export function parseLauncherArgs(argv) {
108
107
  */
109
108
  export const LAUNCHER_TIMEOUT_FLAGS = ['--boot-timeout', '--mux-timeout', '--connect-timeout']
110
109
 
111
- /** Allowed argv tokens/patterns: profile provisioning forwards + client launch. */
110
+ /** Allowed argv tokens/patterns: client launch. */
112
111
  export const KNOWN_CLIENT_ARGS = [
113
- '--provider',
114
- '--provider=',
115
- '--model',
116
- '--model=',
117
- '--reasoning-effort',
118
- '--reasoning-effort=',
119
- '--plugins',
120
- '--plugins=',
121
- '--dry-run',
122
112
  '--new',
123
113
  '--resume-last',
124
114
  '--session',
@@ -250,7 +240,7 @@ export function validateLauncherArgs(rest, { skip = [] } = {}) {
250
240
  skipped.some((s) => token === s || token.startsWith(`${s}=`)) ||
251
241
  KNOWN_CLIENT_ARGS.some((known) => known.endsWith('=') && token.startsWith(known))
252
242
  // Space-form flags whose immediately following token is always their value.
253
- const valueTaking = ['--provider', '--model', '--reasoning-effort', '--plugins', '--session']
243
+ const valueTaking = ['--session']
254
244
  const unknown = []
255
245
  const args = Array.isArray(rest) ? rest : []
256
246
  for (let i = 0; i < args.length; i++) {
@@ -294,9 +284,9 @@ export function validateLauncherArgs(rest, { skip = [] } = {}) {
294
284
  *
295
285
  * Returns a conflict code, or null when the combination is fine:
296
286
  * 'repair-force' --repair-bridge + --force → mutually exclusive
297
- * 'yes-without-force' --yes without --force/--repair-bridge (under
298
- * --repair-bridge, --yes is tolerated — the repair branch
299
- * never reads it — and is intentionally allowed through)
287
+ * 'yes-without-force' --yes without --force (under
288
+ * --repair-bridge, --yes is tolerated and ignored — the
289
+ * repair branch never reads it — and is allowed through)
300
290
  */
301
291
  export function launcherFlagConflict({ force, repairBridge, yes } = {}) {
302
292
  if (repairBridge && force) return 'repair-force'
@@ -304,7 +294,7 @@ export function launcherFlagConflict({ force, repairBridge, yes } = {}) {
304
294
  return null
305
295
  }
306
296
 
307
- /** Usage text for the normal launcher (not the `upgrade` subcommand). */
297
+ /** Usage text for the normal launcher. */
308
298
  export function formatUsage() {
309
299
  return [
310
300
  'dsh-opentui — terminal client for the dsh harness',
@@ -313,17 +303,12 @@ export function formatUsage() {
313
303
  '',
314
304
  'Options:',
315
305
  ' -v, --version print the launcher version and exit',
316
- ' --force reset the singleton host before starting (needs --yes if clients are live; no-op under --dry-run)',
317
- ' --yes confirm a --force reset that would disconnect live clients',
306
+ ' --force deprecated no-op; use --repair-bridge to clear stale instances; removed in the next minor release',
307
+ ' --yes deprecated no-op; only accepted with --force; use --repair-bridge to clear stale instances; removed in the next minor release',
318
308
  ' --repair-bridge kill stale instances, repair the in-process bridge symlink / manifest, re-verify its identity, then exit (no TUI)',
319
309
  ' --boot-timeout <sec> seconds to wait for the host to cold-start (default: 30; /reload keeps its own 30s)',
320
310
  ' --mux-timeout <sec> seconds to wait for the host mux to serve (default: 20)',
321
311
  ' --connect-timeout <sec> seconds to wait for the first connection (default: 30)',
322
- ' --provider <name> forwarded to profile provisioning',
323
- ' --model <name> forwarded to profile provisioning',
324
- ' --reasoning-effort <level> forwarded to profile provisioning',
325
- ' --plugins <tier> forwarded to profile provisioning',
326
- ' --dry-run forwarded to profile provisioning',
327
312
  ' -h, --help print this help and exit',
328
313
  '',
329
314
  'Environment:',
@@ -358,25 +343,6 @@ export function readLauncherVersion(pkgRoot) {
358
343
  }
359
344
  }
360
345
 
361
- /**
362
- * Decide how a failed host pre-launch (step 6a) must be handled (P1-5).
363
- *
364
- * - `force-needs-yes` is a usage error: exit 2 (the user must confirm).
365
- * - with `--force`, ANY other failure is fatal: exit 1. A force reset that
366
- * could not import/run the orchestration bundle did not happen, so quietly
367
- * continuing would turn `--force` into a silent no-op (the bin-level force
368
- * cleanup was removed in step 2.5). Never downgrade to a warning here.
369
- * - without `--force`, pre-launch is best-effort: warn and let the client
370
- * retry host boot itself.
371
- *
372
- * @returns 'usage-error' | 'abort' | 'warn'
373
- */
374
- export function prelaunchFailurePolicy(err, force) {
375
- if (err?.code === 'force-needs-yes') return 'usage-error'
376
- if (force) return 'abort'
377
- return 'warn'
378
- }
379
-
380
346
  /**
381
347
  * Parse `ps -A -o pid=,ppid=,command=` output into process rows.
382
348
  *
@@ -424,7 +390,7 @@ export function parseProcessHomes(psEwwOutput) {
424
390
  * Classify a process command line.
425
391
  *
426
392
  * @returns 'host' | 'client' | null
427
- * host — the resident dsh host of the opentui profile
393
+ * host — the resident dsh host of the active in-process profile
428
394
  * client — a dsh-opentui client process (source tree entry or the
429
395
  * published bundle)
430
396
  * null — anything else (the shell/tmux wrapper, a `dsh plugin ...`
@@ -438,20 +404,20 @@ export function classifyProcess(command) {
438
404
 
439
405
  const exe = basename(tokens[0])
440
406
  // Only a real runtime may be the process itself — a shell that merely
441
- // mentions these paths (`sh -c "dsh --profile opentui"`, a tmux command
407
+ // mentions these paths (`sh -c "dsh --profile opentui-monday"`, a tmux command
442
408
  // line) is NOT the host.
443
409
  if (exe !== 'node' && exe !== 'bun' && exe !== 'dsh') return null
444
410
 
445
411
  // The host: the dsh binary IS the process or sits right after the
446
- // runtime (node/bun + script), and is followed by `--profile opentui`.
412
+ // runtime (node/bun + script), and is followed by the active profile flag.
447
413
  // Only the first two tokens may be the dsh binary — a wrapper script
448
- // (`node wrapper.js dsh --profile opentui`) merely MENTIONS it.
414
+ // (`node wrapper.js dsh --profile opentui-monday`) merely MENTIONS it.
449
415
  for (let i = 0; i < Math.min(tokens.length, 2); i++) {
450
416
  if (basename(tokens[i]) !== 'dsh') continue
451
417
  const next = tokens[i + 1]
452
418
  if (next === '--profile' && tokens[i + 2] === PROFILE) return 'host'
453
419
  if (next === `--profile=${PROFILE}`) return 'host'
454
- // `dsh plugin --profile opentui add ...` (provision) and
420
+ // `dsh plugin --profile <active> add ...` (provision) and
455
421
  // `dsh opentui --dump-config` are not the host.
456
422
  return null
457
423
  }
@@ -576,127 +542,3 @@ export async function killStaleProcesses(targets, options = {}) {
576
542
  survivors: survivors.filter((pid) => isAlive(pid)),
577
543
  }
578
544
  }
579
-
580
- /** The dist-tag `upgrade` resolves against when none is given. */
581
- export const UPGRADE_DEFAULT_TAG = 'latest'
582
- // The tag becomes an argv value for `npm view` and must never be able to look
583
- // like a flag or carry shell/URL syntax: npm dist-tags are [A-Za-z0-9._-].
584
- const TAG_PATTERN = /^[A-Za-z0-9._-]+$/
585
-
586
- /**
587
- * Parse the argv of the `upgrade` subcommand.
588
- *
589
- * The subcommand is POSITIONAL and must be the first argument the launcher
590
- * sees after `parseLauncherArgs` consumed `--version`/`--force`. A `upgrade`
591
- * anywhere else (`foo upgrade`, `--model upgrade`) is NOT the subcommand: the
592
- * argument vector is forwarded to the client exactly as before (requirement:
593
- * an old release silently ignores a stray positional, and this release must
594
- * not turn that into an error).
595
- *
596
- * `--force` is deliberately absent here — `parseLauncherArgs` consumes it
597
- * before this function runs, so it can never reach an upgrade flag parse. The
598
- * bin rejects the `--force upgrade` combination itself (a usage error).
599
- *
600
- * Unknown flags are reported once as `error: 'unknown-flag'` with the offending
601
- * tokens in `unknownFlags`; the caller prints the usage and exits 2 without
602
- * doing anything. `--reset-overrides` is a terminal action and is incompatible
603
- * with every flag that shapes an upgrade (`--no-self`/`--no-plugins`/`--yes`
604
- * and a non-default `--tag`): combining them would silently ignore one intent.
605
- *
606
- * @param {string[]} argv arguments after the bin-level flags
607
- * @returns {{ isUpgrade: boolean, opts: {
608
- * dryRun: boolean, yes: boolean, tag: string, noSelf: boolean,
609
- * noPlugins: boolean, resetOverrides: boolean, help: boolean,
610
- * }, error: null | 'unknown-flag' | 'missing-tag-value' | 'invalid-tag' |
611
- * 'reset-overrides-conflict', unknownFlags?: string[], invalidTag?: string }}
612
- */
613
- export function parseUpgradeArgs(argv) {
614
- const args = Array.isArray(argv) ? argv : []
615
- const opts = {
616
- dryRun: false,
617
- yes: false,
618
- tag: UPGRADE_DEFAULT_TAG,
619
- noSelf: false,
620
- noPlugins: false,
621
- resetOverrides: false,
622
- help: false,
623
- }
624
- // Positional contract: only argv[0] selects the subcommand.
625
- if (args[0] !== 'upgrade') return { isUpgrade: false, opts, error: null }
626
-
627
- const unknownFlags = []
628
- // Presence, not value: `--reset-overrides --tag latest` is still two
629
- // intents, and the conflict report must not depend on the tag's spelling.
630
- let tagGiven = false
631
- for (let i = 1; i < args.length; i++) {
632
- const arg = args[i]
633
- if (arg === '--dry-run') {
634
- opts.dryRun = true
635
- } else if (arg === '-y' || arg === '--yes') {
636
- opts.yes = true
637
- } else if (arg === '--no-self') {
638
- opts.noSelf = true
639
- } else if (arg === '--no-plugins') {
640
- opts.noPlugins = true
641
- } else if (arg === '--reset-overrides') {
642
- opts.resetOverrides = true
643
- } else if (arg === '-h' || arg === '--help') {
644
- opts.help = true
645
- } else if (arg === '--tag') {
646
- const value = args[i + 1]
647
- if (value === undefined || value.startsWith('-')) {
648
- return { isUpgrade: true, opts, error: 'missing-tag-value' }
649
- }
650
- if (!TAG_PATTERN.test(value)) {
651
- return { isUpgrade: true, opts, error: 'invalid-tag', invalidTag: value }
652
- }
653
- opts.tag = value
654
- tagGiven = true
655
- i++
656
- } else if (arg.startsWith('--tag=')) {
657
- const value = arg.slice('--tag='.length)
658
- if (value === '') return { isUpgrade: true, opts, error: 'missing-tag-value' }
659
- if (!TAG_PATTERN.test(value)) {
660
- return { isUpgrade: true, opts, error: 'invalid-tag', invalidTag: value }
661
- }
662
- opts.tag = value
663
- tagGiven = true
664
- } else {
665
- unknownFlags.push(arg)
666
- }
667
- }
668
-
669
- if (unknownFlags.length > 0) {
670
- return { isUpgrade: true, opts, error: 'unknown-flag', unknownFlags }
671
- }
672
- if (opts.resetOverrides && (opts.noSelf || opts.noPlugins || opts.yes || tagGiven)) {
673
- return { isUpgrade: true, opts, error: 'reset-overrides-conflict' }
674
- }
675
- return { isUpgrade: true, opts, error: null }
676
- }
677
-
678
- /** Usage text for `dsh-opentui upgrade` (also the `--help` body). Plain text,
679
- * one flag per line; the exit-code block is part of the contract. */
680
- export function formatUpgradeUsage() {
681
- return [
682
- 'dsh-opentui upgrade — upgrade the launcher and the opentui profile plugins',
683
- '',
684
- 'Usage: dsh-opentui upgrade [options]',
685
- '',
686
- 'Options:',
687
- ' --dry-run print the plan and exit; write nothing',
688
- ' -y, --yes do not ask for confirmation',
689
- ' --tag <name> dist-tag to resolve (default: latest)',
690
- ' --no-self skip the dsh-opentui launcher itself',
691
- ' --no-plugins skip the opentui profile plugins',
692
- ' --reset-overrides delete upgrade-overrides.json and exit (terminal;',
693
- ' conflicts with --no-self/--no-plugins/--yes/--tag)',
694
- ' -h, --help print this help and exit',
695
- '',
696
- 'Exit codes:',
697
- ' 0 already up to date, nothing to do, --dry-run, or --help',
698
- ' 1 hard failure (e.g. self-upgrade did not verify); profile untouched/rolled back',
699
- ' 2 usage error, or another upgrade is already running (profile lock held)',
700
- ' 3 partial: a package did not reach the target version, or overrides could not be recorded',
701
- ].join('\n')
702
- }