@aiwayds/dsh-opentui 0.18.6 → 0.19.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 +47 -0
- package/bin/dsh-opentui.mjs +54 -24
- package/bin/lib/launcher.mjs +29 -2
- package/dist/client/index.js +2625 -1280
- package/dist/client/index.js.map +16 -10
- package/dist/host-launch.mjs +1276 -0
- package/dist/host-launch.mjs.map +19 -0
- package/dist/scripts/idle-reaper.mjs +9 -3
- package/dist/watchdog.mjs +467 -0
- package/dist/watchdog.mjs.map +16 -0
- package/package.json +5 -1
- package/scripts/idle-reaper.mjs +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,53 @@ 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.19.0] - 2026-11-17
|
|
9
|
+
|
|
10
|
+
0.18.7 carried the same code but shipped these lifecycle changes as a patch;
|
|
11
|
+
it is deprecated in favour of 0.19.0.
|
|
12
|
+
|
|
13
|
+
### BREAKING CHANGES
|
|
14
|
+
- The resident host no longer exits 5s after going idle. It now shuts down
|
|
15
|
+
once the last client exits (2s grace). `DSH_OPENTUI_HOST_IDLE_MS` keeps its
|
|
16
|
+
name but now means "last-one grace override" (default 2000); `0` means
|
|
17
|
+
resident. Scripts that relied on the 5s idle window must set it explicitly.
|
|
18
|
+
- The host registry moved to schema v2. v1 records are treated as legacy and
|
|
19
|
+
never overwritten or signalled; a live v1 host is left for stale cleanup
|
|
20
|
+
only. Tooling that parsed `opentui-host.<profile>.json` must accept
|
|
21
|
+
`version: 2`.
|
|
22
|
+
- `--force` without `--yes` now exits 2 and leaves the host untouched while
|
|
23
|
+
clients are still live. Automation calling `--force` must add `--yes`.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
- One host service per `(DSH_HOME, profile)`, on a port derived from the home
|
|
27
|
+
path. Later launches attach to the running host rather than spawning another;
|
|
28
|
+
warm attach measured at 407ms.
|
|
29
|
+
- Startup renders the boot phase and elapsed time before entering the client
|
|
30
|
+
interface, so a cold start shows progress instead of a blank screen.
|
|
31
|
+
- The host shuts down gracefully 2s after the last client exits, letting it
|
|
32
|
+
flush state. Set `DSH_OPENTUI_HOST_IDLE_MS=0` to keep it resident instead.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
- `--force` without `--yes` now exits 2 and leaves the host untouched while
|
|
36
|
+
clients are still live. A three-evidence gate keeps it from stopping a
|
|
37
|
+
process it cannot positively identify as this profile's server.
|
|
38
|
+
- The host registry is unified on v2, so v1 and v2 records no longer overwrite
|
|
39
|
+
each other.
|
|
40
|
+
- The row 39 git-branch probe in the shell tests now builds its own temporary
|
|
41
|
+
repository instead of assuming the checkout is on a named branch, so the
|
|
42
|
+
tests no longer fail under detached PR/tag checkouts.
|
|
43
|
+
- `--force --yes` now resets a host whose pid is an unreaped zombie: a zombie
|
|
44
|
+
still answers `kill(pid, 0)`, which used to look like "still running" and
|
|
45
|
+
abort the reset.
|
|
46
|
+
|
|
47
|
+
### Migration
|
|
48
|
+
- Replace 5s-idle assumptions: set `DSH_OPENTUI_HOST_IDLE_MS` explicitly to keep
|
|
49
|
+
the old grace, or `0` for a resident host; the new default is 2000ms.
|
|
50
|
+
- Update tooling reading `opentui-host.<profile>.json` to accept `version: 2`;
|
|
51
|
+
treat leftover v1 records as legacy and let stale cleanup remove them.
|
|
52
|
+
- Add `--yes` to every automation call that uses `--force`, or handle exit 2 and
|
|
53
|
+
leave the host untouched while clients are live.
|
|
54
|
+
|
|
8
55
|
## [0.18.6] - 2026-11-17
|
|
9
56
|
|
|
10
57
|
### Changed
|
package/bin/dsh-opentui.mjs
CHANGED
|
@@ -52,7 +52,7 @@ import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSyn
|
|
|
52
52
|
import { homedir } from 'node:os'
|
|
53
53
|
import { dirname, join } from 'node:path'
|
|
54
54
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
55
|
-
import {
|
|
55
|
+
import { formatUpgradeUsage, formatUsage, LAUNCHER_TIMEOUT_FLAGS, parseLauncherArgs, parseLauncherOptions, parseUpgradeArgs, prelaunchFailurePolicy, readLauncherVersion, validateLauncherArgs } 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')
|
|
@@ -63,14 +63,8 @@ function exitWithGuidance(what, installCmd) {
|
|
|
63
63
|
process.exit(1)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
/** Run a helper command and return its stdout ('' on failure). */
|
|
67
|
-
function capture(cmd, args) {
|
|
68
|
-
const r = spawnSync(cmd, args, { encoding: 'utf8' })
|
|
69
|
-
return r.stdout ?? ''
|
|
70
|
-
}
|
|
71
|
-
|
|
72
66
|
// --- 0. Bin-level flags: --version short-circuits, --force pre-clears -------
|
|
73
|
-
const { version: versionFlag, force: forceFlag, rest: userArgs, passthrough } = parseLauncherArgs(process.argv.slice(2))
|
|
67
|
+
const { version: versionFlag, force: forceFlag, yes: yesFlag, rest: userArgs, passthrough } = parseLauncherArgs(process.argv.slice(2))
|
|
74
68
|
|
|
75
69
|
if (versionFlag) {
|
|
76
70
|
const version = readLauncherVersion(pkgRoot)
|
|
@@ -82,6 +76,11 @@ if (versionFlag) {
|
|
|
82
76
|
process.exit(0)
|
|
83
77
|
}
|
|
84
78
|
|
|
79
|
+
if (yesFlag && !forceFlag) {
|
|
80
|
+
console.error('dsh-opentui: --yes is only meaningful together with --force.')
|
|
81
|
+
process.exit(2)
|
|
82
|
+
}
|
|
83
|
+
|
|
85
84
|
// --- 0.5 upgrade subcommand -------------------------------------------------
|
|
86
85
|
// `upgrade` is a positional subcommand: only the first remaining argument may
|
|
87
86
|
// select it, and here is its ONLY consumer. It must never reach the provision
|
|
@@ -202,22 +201,12 @@ if (!spawnSync('which', ['dsh'], { encoding: 'utf8' }).stdout.trim()) {
|
|
|
202
201
|
exitWithGuidance('the dsh CLI', 'npm i -g @deepseek-ai/dsh')
|
|
203
202
|
}
|
|
204
203
|
|
|
205
|
-
// --- 2.5 --force
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
const rows = parseProcessRows(capture('ps', ['-A', '-o', 'pid=,ppid=,command=']))
|
|
212
|
-
const homes = parseProcessHomes(capture('ps', ['eww', '-A', '-o', 'pid=,args=']))
|
|
213
|
-
const stale = selectStaleProcesses(rows, {
|
|
214
|
-
homes,
|
|
215
|
-
home: dshHome,
|
|
216
|
-
excludePids: ancestorPids(rows, process.pid),
|
|
217
|
-
})
|
|
218
|
-
const result = await killStaleProcesses(stale)
|
|
219
|
-
console.log(`--force: killed ${result.terminated} stale instance(s)`)
|
|
220
|
-
}
|
|
204
|
+
// --- 2.5 --force -----------------------------------------------------------
|
|
205
|
+
// NOTE (ADR-0009 decision 8): the old bare `--profile opentui` cmdline sweep
|
|
206
|
+
// lived here. It is deliberately removed — killing a process needs the THREE
|
|
207
|
+
// evidences (registry pid + `--profile opentui` cmdline + `DSH_OPENTUI_SERVER=1`
|
|
208
|
+
// env). `--force` is now handled at step 6a inside the host-launch bundle,
|
|
209
|
+
// which also enforces the `--yes` guard when live clients are connected.
|
|
221
210
|
|
|
222
211
|
// --- 3. Profile bootstrap (every start, best effort, idempotent) -----------
|
|
223
212
|
// provision-opentui-profile.mjs is idempotent and understands
|
|
@@ -422,6 +411,47 @@ if (!existsSync(clientEntry)) {
|
|
|
422
411
|
console.error('dsh-opentui: reinstall the package (npm i -g @aiwayds/dsh-opentui), or rebuild it with `bun scripts/build-client.mjs` from the repo.')
|
|
423
412
|
process.exit(1)
|
|
424
413
|
}
|
|
414
|
+
// --- 6a. Pre-launch the Host service (registry / port / health) ------------
|
|
415
|
+
// ADR-0009 §3: start/adopt the singleton host HERE, while the launcher still
|
|
416
|
+
// owns the terminal, so the `spawn → booting → ready + elapsed` progress is
|
|
417
|
+
// painted BEFORE the bun client enters its alternate screen. The client's own
|
|
418
|
+
// lifecycle.ensureHost then adopts the ready host (no double start). On the
|
|
419
|
+
// healthy-attach fast path nothing is printed. The orchestration bundle is a
|
|
420
|
+
// separate build artifact (packages/shell/dist/host-launch.mjs); a missing or
|
|
421
|
+
// failing pre-launch is best-effort — the client retries host boot itself —
|
|
422
|
+
// EXCEPT under `--force`, where a failed import/reset is fatal (P1-5).
|
|
423
|
+
// `--dry-run` is side-effect free and skips this step.
|
|
424
|
+
if (!clientArgs.includes('--dry-run')) {
|
|
425
|
+
try {
|
|
426
|
+
const hostLaunchPath = join(pkgRoot, 'dist', 'host-launch.mjs')
|
|
427
|
+
const { ensureHost: ensureLaunchHost, createLaunchProgress } = await import(pathToFileURL(hostLaunchPath).href)
|
|
428
|
+
await ensureLaunchHost({
|
|
429
|
+
home: dshHome,
|
|
430
|
+
profile: 'opentui',
|
|
431
|
+
cwd: process.cwd(),
|
|
432
|
+
...(forceFlag ? { force: true } : {}),
|
|
433
|
+
...(yesFlag ? { yes: true } : {}),
|
|
434
|
+
progress: createLaunchProgress({
|
|
435
|
+
isTty: Boolean(process.stderr.isTTY),
|
|
436
|
+
write: (text) => process.stderr.write(text),
|
|
437
|
+
}),
|
|
438
|
+
})
|
|
439
|
+
} catch (err) {
|
|
440
|
+
// P1-5: a force reset must NEVER silently degrade to a no-op. Only the
|
|
441
|
+
// non-force path is best-effort (the client retries host boot itself).
|
|
442
|
+
const policy = prelaunchFailurePolicy(err, forceFlag)
|
|
443
|
+
if (policy === 'usage-error') {
|
|
444
|
+
console.error(`dsh-opentui: ${err?.message ?? err}`)
|
|
445
|
+
process.exit(2)
|
|
446
|
+
}
|
|
447
|
+
if (policy === 'abort') {
|
|
448
|
+
console.error(`dsh-opentui: --force host pre-launch failed (${err?.message ?? err}); aborting without reset.`)
|
|
449
|
+
process.exit(1)
|
|
450
|
+
}
|
|
451
|
+
console.error(`dsh-opentui: host pre-launch failed (${err?.message ?? err}); the client will retry host boot.`)
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
425
455
|
const result = spawnSync('bun', [clientEntry, ...clientArgs], {
|
|
426
456
|
stdio: 'inherit',
|
|
427
457
|
env: clientEnv,
|
package/bin/lib/launcher.mjs
CHANGED
|
@@ -61,6 +61,7 @@ export function parseLauncherArgs(argv) {
|
|
|
61
61
|
const args = Array.isArray(argv) ? argv : []
|
|
62
62
|
let version = false
|
|
63
63
|
let force = false
|
|
64
|
+
let yes = false
|
|
64
65
|
const rest = []
|
|
65
66
|
const passthrough = []
|
|
66
67
|
let separatorSeen = false
|
|
@@ -81,9 +82,15 @@ export function parseLauncherArgs(argv) {
|
|
|
81
82
|
force = true
|
|
82
83
|
continue
|
|
83
84
|
}
|
|
85
|
+
// `--yes` confirms a --force reset when live clients exist (ADR-0009 §7).
|
|
86
|
+
// Consumed by the bin, never forwarded to dsh/the client.
|
|
87
|
+
if (arg === '--yes') {
|
|
88
|
+
yes = true
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
84
91
|
rest.push(arg)
|
|
85
92
|
}
|
|
86
|
-
return { version, force, rest, passthrough }
|
|
93
|
+
return { version, force, yes, rest, passthrough }
|
|
87
94
|
}
|
|
88
95
|
|
|
89
96
|
/**
|
|
@@ -280,7 +287,8 @@ export function formatUsage() {
|
|
|
280
287
|
'',
|
|
281
288
|
'Options:',
|
|
282
289
|
' -v, --version print the launcher version and exit',
|
|
283
|
-
' --force
|
|
290
|
+
' --force reset the singleton host before starting (needs --yes if clients are live)',
|
|
291
|
+
' --yes confirm a --force reset that would disconnect live clients',
|
|
284
292
|
' --boot-timeout <sec> seconds to wait for the host to cold-start (default: 30; /reload keeps its own 30s)',
|
|
285
293
|
' --mux-timeout <sec> seconds to wait for the host mux to serve (default: 20)',
|
|
286
294
|
' --connect-timeout <sec> seconds to wait for the first connection (default: 30)',
|
|
@@ -323,6 +331,25 @@ export function readLauncherVersion(pkgRoot) {
|
|
|
323
331
|
}
|
|
324
332
|
}
|
|
325
333
|
|
|
334
|
+
/**
|
|
335
|
+
* Decide how a failed host pre-launch (step 6a) must be handled (P1-5).
|
|
336
|
+
*
|
|
337
|
+
* - `force-needs-yes` is a usage error: exit 2 (the user must confirm).
|
|
338
|
+
* - with `--force`, ANY other failure is fatal: exit 1. A force reset that
|
|
339
|
+
* could not import/run the orchestration bundle did not happen, so quietly
|
|
340
|
+
* continuing would turn `--force` into a silent no-op (the bin-level force
|
|
341
|
+
* cleanup was removed in step 2.5). Never downgrade to a warning here.
|
|
342
|
+
* - without `--force`, pre-launch is best-effort: warn and let the client
|
|
343
|
+
* retry host boot itself.
|
|
344
|
+
*
|
|
345
|
+
* @returns 'usage-error' | 'abort' | 'warn'
|
|
346
|
+
*/
|
|
347
|
+
export function prelaunchFailurePolicy(err, force) {
|
|
348
|
+
if (err?.code === 'force-needs-yes') return 'usage-error'
|
|
349
|
+
if (force) return 'abort'
|
|
350
|
+
return 'warn'
|
|
351
|
+
}
|
|
352
|
+
|
|
326
353
|
/**
|
|
327
354
|
* Parse `ps -A -o pid=,ppid=,command=` output into process rows.
|
|
328
355
|
*
|