@aiwayds/dsh-opentui 0.18.3 → 0.18.4
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 +25 -0
- package/README.md +2 -0
- package/bin/dsh-opentui.mjs +81 -5
- package/bin/lib/launcher.mjs +241 -4
- package/dist/client/index.js +51 -13
- package/dist/client/index.js.map +323 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,31 @@ 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.4] - 2026-11-16
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `--boot-timeout`, `--mux-timeout`, `--connect-timeout` (seconds) with
|
|
12
|
+
matching `DSH_OPENTUI_*_TIMEOUT_MS` env overrides; the three wait budgets
|
|
13
|
+
in the boot chain were previously hard-coded. `--boot-timeout` applies to
|
|
14
|
+
the initial host cold-start only: `/reload` keeps its own hardcoded 30s
|
|
15
|
+
restart budget and does not read this value.
|
|
16
|
+
- `-v` alias for `--version`.
|
|
17
|
+
- `--help` / `-h` usage output for the launcher.
|
|
18
|
+
- `--` separator: everything after it is passed to the client without validation.
|
|
19
|
+
- Client bundles ship sourcemaps (`.map`) so crash traces resolve to source.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Unknown launcher options are now rejected with `exit 2` and a usage block
|
|
23
|
+
instead of silently booting the full client. A near-miss suggestion is printed
|
|
24
|
+
when the typo is at least 3 characters long and within edit distance 2 of a
|
|
25
|
+
known option (short flags such as `-x` get no misleading hint).
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
- The host mux probe aborted a still-connecting socket after removing its
|
|
29
|
+
listeners, turning a normal "host not serving yet" timeout into an uncaught
|
|
30
|
+
`WebSocket was closed before the connection was established` crash. The probe
|
|
31
|
+
now keeps a no-op error listener, so the failure surfaces as `HostNotServingError`.
|
|
32
|
+
|
|
8
33
|
## [0.18.3] - 2026-11-16
|
|
9
34
|
|
|
10
35
|
### Added
|
package/README.md
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 { ancestorPids, formatUpgradeUsage, killStaleProcesses, parseLauncherArgs, parseProcessHomes, parseProcessRows, parseUpgradeArgs, readLauncherVersion, selectStaleProcesses } from './lib/launcher.mjs'
|
|
55
|
+
import { ancestorPids, formatUpgradeUsage, formatUsage, killStaleProcesses, LAUNCHER_TIMEOUT_FLAGS, parseLauncherArgs, parseLauncherOptions, parseProcessHomes, parseProcessRows, parseUpgradeArgs, readLauncherVersion, selectStaleProcesses, 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')
|
|
@@ -70,7 +70,7 @@ function capture(cmd, args) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
// --- 0. Bin-level flags: --version short-circuits, --force pre-clears -------
|
|
73
|
-
const { version: versionFlag, force: forceFlag, rest: userArgs } = parseLauncherArgs(process.argv.slice(2))
|
|
73
|
+
const { version: versionFlag, force: forceFlag, rest: userArgs, passthrough } = parseLauncherArgs(process.argv.slice(2))
|
|
74
74
|
|
|
75
75
|
if (versionFlag) {
|
|
76
76
|
const version = readLauncherVersion(pkgRoot)
|
|
@@ -123,6 +123,75 @@ if (upgradeResult.isUpgrade) {
|
|
|
123
123
|
process.exit(runUpgrade(upgradeResult.opts, { pkgRoot }))
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// --- 0.6 usage/help and argument validation --------------------------------
|
|
127
|
+
// Placed after --version (absolute short-circuit) and after `upgrade` (whose
|
|
128
|
+
// -h/--help belongs to parseUpgradeArgs), but BEFORE provisioning or any TUI
|
|
129
|
+
// work: a typo like `--verison` must fail here instead of running a full
|
|
130
|
+
// provision pass first.
|
|
131
|
+
function stripLauncherTimeoutFlags(args) {
|
|
132
|
+
const out = []
|
|
133
|
+
for (let i = 0; i < args.length; i++) {
|
|
134
|
+
const arg = args[i]
|
|
135
|
+
const flag = LAUNCHER_TIMEOUT_FLAGS.find((f) => arg === f || arg.startsWith(`${f}=`))
|
|
136
|
+
if (!flag) {
|
|
137
|
+
out.push(arg)
|
|
138
|
+
continue
|
|
139
|
+
}
|
|
140
|
+
// `--flag value`: parseLauncherOptions already verified the value does not
|
|
141
|
+
// start with '-', so it is safe to consume here.
|
|
142
|
+
if (arg === flag) i++
|
|
143
|
+
}
|
|
144
|
+
return out
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (userArgs.includes('-h') || userArgs.includes('--help')) {
|
|
148
|
+
console.log(formatUsage())
|
|
149
|
+
process.exit(0)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const options = parseLauncherOptions(userArgs)
|
|
153
|
+
if (options.error === 'missing-value') {
|
|
154
|
+
console.error(`dsh-opentui: option '${options.errorFlag}' requires a value`)
|
|
155
|
+
console.error(formatUsage())
|
|
156
|
+
process.exit(2)
|
|
157
|
+
}
|
|
158
|
+
if (options.error === 'invalid-value') {
|
|
159
|
+
console.error(
|
|
160
|
+
`dsh-opentui: invalid value '${options.errorValue}' for '${options.errorFlag}' (expected 1-3600 seconds)`,
|
|
161
|
+
)
|
|
162
|
+
console.error(formatUsage())
|
|
163
|
+
process.exit(2)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const validation = validateLauncherArgs(userArgs, { skip: LAUNCHER_TIMEOUT_FLAGS })
|
|
167
|
+
if (validation.unknown.length > 0) {
|
|
168
|
+
for (const flag of validation.unknown) {
|
|
169
|
+
console.error(`dsh-opentui: unknown option '${flag}'`)
|
|
170
|
+
if (validation.suggestions[flag]) {
|
|
171
|
+
console.error(`dsh-opentui: did you mean '${validation.suggestions[flag]}'?`)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
console.error(formatUsage())
|
|
175
|
+
process.exit(2)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Write a timeout to the client env only when the user supplied that flag:
|
|
179
|
+
// defaults must not clobber a value already set in the shell environment.
|
|
180
|
+
const clientEnv = { ...process.env }
|
|
181
|
+
const timeoutEnvNames = {
|
|
182
|
+
bootTimeoutSec: 'DSH_OPENTUI_BOOT_TIMEOUT_MS',
|
|
183
|
+
muxTimeoutSec: 'DSH_OPENTUI_MUX_TIMEOUT_MS',
|
|
184
|
+
connectTimeoutSec: 'DSH_OPENTUI_CONNECT_TIMEOUT_MS',
|
|
185
|
+
}
|
|
186
|
+
for (const [key, envName] of Object.entries(timeoutEnvNames)) {
|
|
187
|
+
if (options[key] !== undefined) clientEnv[envName] = String(options[key] * 1000)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// The client bundle does not understand the launcher's timeout flags; strip
|
|
191
|
+
// them and append anything after a `--` verbatim.
|
|
192
|
+
const clientArgs = stripLauncherTimeoutFlags(userArgs)
|
|
193
|
+
clientArgs.push(...(passthrough ?? []))
|
|
194
|
+
|
|
126
195
|
// --- 1. bun: hard runtime dependency of the client chain -------------------
|
|
127
196
|
if (!spawnSync('which', ['bun'], { encoding: 'utf8' }).stdout.trim()) {
|
|
128
197
|
exitWithGuidance('bun', 'npm i -g bun')
|
|
@@ -152,12 +221,18 @@ if (forceFlag) {
|
|
|
152
221
|
|
|
153
222
|
// --- 3. Profile bootstrap (every start, best effort, idempotent) -----------
|
|
154
223
|
// provision-opentui-profile.mjs is idempotent and understands
|
|
155
|
-
// --provider/--model/--reasoning-effort --plugins/--dry-run
|
|
156
|
-
// ignore the rest. With nothing to do this is a
|
|
224
|
+
// --provider/--model/--reasoning-effort --plugins/--dry-run (both space and
|
|
225
|
+
// `=` forms); forward those, ignore the rest. With nothing to do this is a
|
|
226
|
+
// local, sub-second pass.
|
|
157
227
|
const opentuiProfileDir = join(dshHome, 'profiles', 'opentui')
|
|
158
228
|
{
|
|
159
229
|
const provisionFlags = []
|
|
160
230
|
for (const name of ['provider', 'model', 'reasoning-effort']) {
|
|
231
|
+
const inline = userArgs.find((arg) => arg.startsWith(`--${name}=`))
|
|
232
|
+
if (inline) {
|
|
233
|
+
provisionFlags.push(inline)
|
|
234
|
+
continue
|
|
235
|
+
}
|
|
161
236
|
const i = userArgs.indexOf(`--${name}`)
|
|
162
237
|
if (i >= 0 && userArgs[i + 1]) provisionFlags.push(`--${name}`, userArgs[i + 1])
|
|
163
238
|
}
|
|
@@ -347,8 +422,9 @@ if (!existsSync(clientEntry)) {
|
|
|
347
422
|
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.')
|
|
348
423
|
process.exit(1)
|
|
349
424
|
}
|
|
350
|
-
const result = spawnSync('bun', [clientEntry, ...
|
|
425
|
+
const result = spawnSync('bun', [clientEntry, ...clientArgs], {
|
|
351
426
|
stdio: 'inherit',
|
|
427
|
+
env: clientEnv,
|
|
352
428
|
})
|
|
353
429
|
if (result.error) {
|
|
354
430
|
console.error(`dsh-opentui: failed to launch the client: ${result.error.message}`)
|
package/bin/lib/launcher.mjs
CHANGED
|
@@ -49,16 +49,31 @@ export function defaultDshHome() {
|
|
|
49
49
|
* Split the launcher's argv into the flags the bin consumes itself and the
|
|
50
50
|
* arguments forwarded to the client bundle.
|
|
51
51
|
*
|
|
52
|
-
*
|
|
53
|
-
* NOT forwarded (the client must never see `--force`).
|
|
52
|
+
* `-v`/`--version` and `--force` are BIN-level flags: they are consumed here
|
|
53
|
+
* and NOT forwarded (the client must never see `--force`).
|
|
54
|
+
*
|
|
55
|
+
* A standalone `--` ends launcher parsing: every token after it (even one that
|
|
56
|
+
* spells a launcher flag) goes to `passthrough` verbatim and is never
|
|
57
|
+
* interpreted by the bin. `passthrough` is always a string array; it is empty
|
|
58
|
+
* when no separator appears, so callers never have to handle a union type.
|
|
54
59
|
*/
|
|
55
60
|
export function parseLauncherArgs(argv) {
|
|
56
61
|
const args = Array.isArray(argv) ? argv : []
|
|
57
62
|
let version = false
|
|
58
63
|
let force = false
|
|
59
64
|
const rest = []
|
|
65
|
+
const passthrough = []
|
|
66
|
+
let separatorSeen = false
|
|
60
67
|
for (const arg of args) {
|
|
61
|
-
if (
|
|
68
|
+
if (separatorSeen) {
|
|
69
|
+
passthrough.push(arg)
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
if (arg === '--') {
|
|
73
|
+
separatorSeen = true
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
if (arg === '--version' || arg === '-v') {
|
|
62
77
|
version = true
|
|
63
78
|
continue
|
|
64
79
|
}
|
|
@@ -68,7 +83,229 @@ export function parseLauncherArgs(argv) {
|
|
|
68
83
|
}
|
|
69
84
|
rest.push(arg)
|
|
70
85
|
}
|
|
71
|
-
return { version, force, rest }
|
|
86
|
+
return { version, force, rest, passthrough }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Flags the launcher itself consumes before the client starts. Kept here so
|
|
91
|
+
* every flag is validated by exactly one owner: the bin rejects these before
|
|
92
|
+
* the client sees them, and `validateLauncherArgs` ignores them via `skip`.
|
|
93
|
+
*/
|
|
94
|
+
export const LAUNCHER_TIMEOUT_FLAGS = ['--boot-timeout', '--mux-timeout', '--connect-timeout']
|
|
95
|
+
|
|
96
|
+
/** Allowed argv tokens/patterns: profile provisioning forwards + client launch. */
|
|
97
|
+
export const KNOWN_CLIENT_ARGS = [
|
|
98
|
+
'--provider',
|
|
99
|
+
'--provider=',
|
|
100
|
+
'--model',
|
|
101
|
+
'--model=',
|
|
102
|
+
'--reasoning-effort',
|
|
103
|
+
'--reasoning-effort=',
|
|
104
|
+
'--plugins',
|
|
105
|
+
'--plugins=',
|
|
106
|
+
'--dry-run',
|
|
107
|
+
'--new',
|
|
108
|
+
'--resume-last',
|
|
109
|
+
'--session',
|
|
110
|
+
'--session=',
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Parse the launcher-only timeout flags out of `rest`.
|
|
115
|
+
*
|
|
116
|
+
* Both `--flag 45` and `--flag=45` are accepted for each flag; the last
|
|
117
|
+
* occurrence of a flag wins. No printing and no exit: errors come back as a
|
|
118
|
+
* marker (`missing-value` / `invalid-value`) plus the offending flag and value
|
|
119
|
+
* so the bin can render its message and usage.
|
|
120
|
+
*/
|
|
121
|
+
export function parseLauncherOptions(rest) {
|
|
122
|
+
const parsed = {
|
|
123
|
+
bootTimeoutSec: undefined,
|
|
124
|
+
muxTimeoutSec: undefined,
|
|
125
|
+
connectTimeoutSec: undefined,
|
|
126
|
+
error: null,
|
|
127
|
+
}
|
|
128
|
+
const specs = [
|
|
129
|
+
{ flag: '--boot-timeout', key: 'bootTimeoutSec' },
|
|
130
|
+
{ flag: '--mux-timeout', key: 'muxTimeoutSec' },
|
|
131
|
+
{ flag: '--connect-timeout', key: 'connectTimeoutSec' },
|
|
132
|
+
]
|
|
133
|
+
const args = Array.isArray(rest) ? rest : []
|
|
134
|
+
for (let i = 0; i < args.length; i++) {
|
|
135
|
+
const arg = args[i]
|
|
136
|
+
if (arg === '--') break
|
|
137
|
+
let spec
|
|
138
|
+
let value
|
|
139
|
+
for (const candidate of specs) {
|
|
140
|
+
if (arg === candidate.flag) {
|
|
141
|
+
spec = candidate
|
|
142
|
+
value = args[i + 1]
|
|
143
|
+
if (value === undefined) {
|
|
144
|
+
parsed.error = 'missing-value'
|
|
145
|
+
parsed.errorFlag = candidate.flag
|
|
146
|
+
return parsed
|
|
147
|
+
}
|
|
148
|
+
if (value.startsWith('-')) {
|
|
149
|
+
// A negative number IS a supplied value (the user gave one),
|
|
150
|
+
// just an invalid one — report it as such, not as a missing
|
|
151
|
+
// value. A flag-looking token is a genuinely missing value.
|
|
152
|
+
if (/^-\d+$/.test(value)) {
|
|
153
|
+
parsed.error = 'invalid-value'
|
|
154
|
+
parsed.errorFlag = candidate.flag
|
|
155
|
+
parsed.errorValue = value
|
|
156
|
+
} else {
|
|
157
|
+
parsed.error = 'missing-value'
|
|
158
|
+
parsed.errorFlag = candidate.flag
|
|
159
|
+
}
|
|
160
|
+
return parsed
|
|
161
|
+
}
|
|
162
|
+
i++
|
|
163
|
+
break
|
|
164
|
+
}
|
|
165
|
+
if (arg.startsWith(`${candidate.flag}=`)) {
|
|
166
|
+
spec = candidate
|
|
167
|
+
value = arg.slice(candidate.flag.length + 1)
|
|
168
|
+
break
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!spec) continue
|
|
172
|
+
if (value === '' || !/^\d+$/.test(value)) {
|
|
173
|
+
parsed.error = value === '' ? 'missing-value' : 'invalid-value'
|
|
174
|
+
parsed.errorFlag = spec.flag
|
|
175
|
+
if (value !== '') parsed.errorValue = value
|
|
176
|
+
return parsed
|
|
177
|
+
}
|
|
178
|
+
const seconds = Number(value)
|
|
179
|
+
if (seconds < 1 || seconds > 3600) {
|
|
180
|
+
parsed.error = 'invalid-value'
|
|
181
|
+
parsed.errorFlag = spec.flag
|
|
182
|
+
parsed.errorValue = value
|
|
183
|
+
return parsed
|
|
184
|
+
}
|
|
185
|
+
parsed[spec.key] = seconds
|
|
186
|
+
}
|
|
187
|
+
return parsed
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Levenshtein distance — small, dependency-free, only used for flag hints. */
|
|
191
|
+
function levenshtein(a, b) {
|
|
192
|
+
let prev = Array.from({ length: b.length + 1 }, (_, i) => i)
|
|
193
|
+
for (let i = 1; i <= a.length; i++) {
|
|
194
|
+
const curr = [i]
|
|
195
|
+
for (let j = 1; j <= b.length; j++) {
|
|
196
|
+
curr[j] = Math.min(
|
|
197
|
+
curr[j - 1] + 1,
|
|
198
|
+
prev[j] + 1,
|
|
199
|
+
prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1),
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
prev = curr
|
|
203
|
+
}
|
|
204
|
+
return prev[b.length]
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Reject unknown launcher-level flags before provisioning runs.
|
|
209
|
+
*
|
|
210
|
+
* Positional tokens and flag values (anything not starting with `-`) are left
|
|
211
|
+
* alone. Tokens after a standalone `--` are never validated. `skip` names
|
|
212
|
+
* launcher flags already consumed elsewhere (the timeout flags), so they are
|
|
213
|
+
* not mistaken for client options. A space-form value-taking flag consumes the
|
|
214
|
+
* token right after it — even one starting with `-` — unless that token is
|
|
215
|
+
* itself a known flag, so `--session -x` is not mistaken for an unknown flag
|
|
216
|
+
* while `--session --new` leaves `--new` to be validated on its own. Each
|
|
217
|
+
* unknown flag may carry a spelling hint when it is at least 3 characters long
|
|
218
|
+
* and within edit distance 2 of a known flag; one-character typos such as `-x`
|
|
219
|
+
* get no misleading hint.
|
|
220
|
+
*/
|
|
221
|
+
export function validateLauncherArgs(rest, { skip = [] } = {}) {
|
|
222
|
+
const skipped = Array.isArray(skip) ? skip : []
|
|
223
|
+
const knownFlags = [
|
|
224
|
+
'--version',
|
|
225
|
+
'-v',
|
|
226
|
+
'--force',
|
|
227
|
+
...LAUNCHER_TIMEOUT_FLAGS,
|
|
228
|
+
'-h',
|
|
229
|
+
'--help',
|
|
230
|
+
...KNOWN_CLIENT_ARGS.filter((known) => !known.endsWith('=')),
|
|
231
|
+
]
|
|
232
|
+
const isKnown = (token) =>
|
|
233
|
+
knownFlags.includes(token) ||
|
|
234
|
+
skipped.some((s) => token === s || token.startsWith(`${s}=`)) ||
|
|
235
|
+
KNOWN_CLIENT_ARGS.some((known) => known.endsWith('=') && token.startsWith(known))
|
|
236
|
+
// Space-form flags whose immediately following token is always their value.
|
|
237
|
+
const valueTaking = ['--provider', '--model', '--reasoning-effort', '--plugins', '--session']
|
|
238
|
+
const unknown = []
|
|
239
|
+
const args = Array.isArray(rest) ? rest : []
|
|
240
|
+
for (let i = 0; i < args.length; i++) {
|
|
241
|
+
const arg = args[i]
|
|
242
|
+
if (arg === '--') break
|
|
243
|
+
if (!arg.startsWith('-')) continue
|
|
244
|
+
if (valueTaking.includes(arg)) {
|
|
245
|
+
const next = args[i + 1]
|
|
246
|
+
if (next !== undefined && next !== '--' && !isKnown(next)) i++
|
|
247
|
+
continue
|
|
248
|
+
}
|
|
249
|
+
if (isKnown(arg)) continue
|
|
250
|
+
unknown.push(arg)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const suggestions = {}
|
|
254
|
+
for (const flag of unknown) {
|
|
255
|
+
if (flag.length < 3) continue
|
|
256
|
+
let best
|
|
257
|
+
let bestDistance = 3
|
|
258
|
+
for (const known of knownFlags) {
|
|
259
|
+
const distance = levenshtein(flag, known)
|
|
260
|
+
if (distance < bestDistance) {
|
|
261
|
+
bestDistance = distance
|
|
262
|
+
best = known
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (best) suggestions[flag] = best
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
unknown,
|
|
269
|
+
suggestions,
|
|
270
|
+
suggestion: unknown.length > 0 ? suggestions[unknown[0]] : undefined,
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Usage text for the normal launcher (not the `upgrade` subcommand). */
|
|
275
|
+
export function formatUsage() {
|
|
276
|
+
return [
|
|
277
|
+
'dsh-opentui — terminal client for the dsh harness',
|
|
278
|
+
'',
|
|
279
|
+
'Usage: dsh-opentui [options] [-- <client args>]',
|
|
280
|
+
'',
|
|
281
|
+
'Options:',
|
|
282
|
+
' -v, --version print the launcher version and exit',
|
|
283
|
+
' --force kill stale dsh processes before starting',
|
|
284
|
+
' --boot-timeout <sec> seconds to wait for the host to cold-start (default: 30; /reload keeps its own 30s)',
|
|
285
|
+
' --mux-timeout <sec> seconds to wait for the host mux to serve (default: 20)',
|
|
286
|
+
' --connect-timeout <sec> seconds to wait for the first connection (default: 30)',
|
|
287
|
+
' --provider <name> forwarded to profile provisioning',
|
|
288
|
+
' --model <name> forwarded to profile provisioning',
|
|
289
|
+
' --reasoning-effort <level> forwarded to profile provisioning',
|
|
290
|
+
' --plugins <tier> forwarded to profile provisioning',
|
|
291
|
+
' --dry-run forwarded to profile provisioning',
|
|
292
|
+
' -h, --help print this help and exit',
|
|
293
|
+
'',
|
|
294
|
+
'Environment:',
|
|
295
|
+
' DSH_OPENTUI_BOOT_TIMEOUT_MS host cold-start budget in ms (CLI flag wins)',
|
|
296
|
+
' DSH_OPENTUI_MUX_TIMEOUT_MS mux readiness budget in ms (CLI flag wins)',
|
|
297
|
+
' DSH_OPENTUI_CONNECT_TIMEOUT_MS first-connect budget in ms (CLI flag wins)',
|
|
298
|
+
' Precedence: CLI flag > environment variable > default.',
|
|
299
|
+
'',
|
|
300
|
+
'Client options (passed through; put them after -- to skip validation):',
|
|
301
|
+
' --new, --resume-last, --session <id>',
|
|
302
|
+
'',
|
|
303
|
+
'Exit codes:',
|
|
304
|
+
' 0 success, --version, or --help',
|
|
305
|
+
' 1 launcher startup failure',
|
|
306
|
+
' 2 usage error (unknown option, invalid timeout value)',
|
|
307
|
+
" other the client's own exit code is passed through (e.g. 130 on SIGINT)",
|
|
308
|
+
].join('\n')
|
|
72
309
|
}
|
|
73
310
|
|
|
74
311
|
/**
|
package/dist/client/index.js
CHANGED
|
@@ -931,6 +931,7 @@ async function probeHostMux(options) {
|
|
|
931
931
|
if (!validAuthority(options.authority))
|
|
932
932
|
return false;
|
|
933
933
|
const timeoutMs = options.timeoutMs ?? DEFAULT_HOST_PROBE_TIMEOUT_MS;
|
|
934
|
+
const makeSocket = options.socketFactory ?? (() => new WS(`ws://${options.authority}/api/remote.mux`, { headers: { cookie: options.cookieHeader } }));
|
|
934
935
|
return await new Promise((resolve) => {
|
|
935
936
|
let settled = false;
|
|
936
937
|
let socket;
|
|
@@ -942,14 +943,13 @@ async function probeHostMux(options) {
|
|
|
942
943
|
clearTimeout(timer);
|
|
943
944
|
try {
|
|
944
945
|
socket?.removeAllListeners();
|
|
946
|
+
socket?.on("error", () => {});
|
|
945
947
|
socket?.terminate();
|
|
946
948
|
} catch {}
|
|
947
949
|
resolve(ok);
|
|
948
950
|
}
|
|
949
951
|
try {
|
|
950
|
-
socket =
|
|
951
|
-
headers: { cookie: options.cookieHeader }
|
|
952
|
-
});
|
|
952
|
+
socket = makeSocket();
|
|
953
953
|
} catch {
|
|
954
954
|
done(false);
|
|
955
955
|
return;
|
|
@@ -1502,12 +1502,17 @@ var init_cookie_mint = __esm(() => {
|
|
|
1502
1502
|
// src/client/lifecycle.ts
|
|
1503
1503
|
var exports_lifecycle = {};
|
|
1504
1504
|
__export(exports_lifecycle, {
|
|
1505
|
+
DEFAULT_CONNECT_TIMEOUT_MS: () => DEFAULT_CONNECT_TIMEOUT_MS,
|
|
1505
1506
|
DEFAULT_IDLE_EXIT_MS: () => DEFAULT_IDLE_EXIT_MS,
|
|
1506
1507
|
DEFAULT_IDLE_EXIT_SEC: () => DEFAULT_IDLE_EXIT_SEC,
|
|
1507
1508
|
DEFAULT_PROFILE: () => DEFAULT_PROFILE,
|
|
1508
1509
|
DEFAULT_READINESS_TIMEOUT_MS: () => DEFAULT_READINESS_TIMEOUT_MS,
|
|
1510
|
+
DEFAULT_SERVE_PROBE_BUDGET_MS: () => DEFAULT_SERVE_PROBE_BUDGET_MS,
|
|
1509
1511
|
DEFAULT_STALE_PROBE_MS: () => DEFAULT_STALE_PROBE_MS,
|
|
1512
|
+
ENV_BOOT_TIMEOUT_MS: () => ENV_BOOT_TIMEOUT_MS,
|
|
1513
|
+
ENV_CONNECT_TIMEOUT_MS: () => ENV_CONNECT_TIMEOUT_MS,
|
|
1510
1514
|
ENV_IDLE_EXIT_MS: () => ENV_IDLE_EXIT_MS,
|
|
1515
|
+
ENV_MUX_TIMEOUT_MS: () => ENV_MUX_TIMEOUT_MS,
|
|
1511
1516
|
HostBootSupersededError: () => HostBootSupersededError,
|
|
1512
1517
|
HostBootTimeoutError: () => HostBootTimeoutError,
|
|
1513
1518
|
HostDiedError: () => HostDiedError,
|
|
@@ -1522,8 +1527,11 @@ __export(exports_lifecycle, {
|
|
|
1522
1527
|
ensureHost: () => ensureHost,
|
|
1523
1528
|
isListening: () => isListening,
|
|
1524
1529
|
pidAlive: () => pidAlive,
|
|
1530
|
+
resolveBootTimeoutMs: () => resolveBootTimeoutMs,
|
|
1531
|
+
resolveConnectTimeoutMs: () => resolveConnectTimeoutMs,
|
|
1525
1532
|
resolveIdleExitMs: () => resolveIdleExitMs,
|
|
1526
|
-
resolveIdleExitSec: () => resolveIdleExitSec
|
|
1533
|
+
resolveIdleExitSec: () => resolveIdleExitSec,
|
|
1534
|
+
resolveMuxTimeoutMs: () => resolveMuxTimeoutMs
|
|
1527
1535
|
});
|
|
1528
1536
|
import { spawn as spawn2 } from "child_process";
|
|
1529
1537
|
import { existsSync as existsSync3, linkSync, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync3, rmSync, writeFileSync as writeFileSync3 } from "fs";
|
|
@@ -1545,6 +1553,29 @@ function resolveIdleExitMs(explicitSec) {
|
|
|
1545
1553
|
function resolveIdleExitSec(explicitSec) {
|
|
1546
1554
|
return resolveIdleExitMs(explicitSec) / 1000;
|
|
1547
1555
|
}
|
|
1556
|
+
function validBudgetMs(value) {
|
|
1557
|
+
return Number.isFinite(value) && Number.isInteger(value) && value > 0;
|
|
1558
|
+
}
|
|
1559
|
+
function resolveBudgetMs(explicitMs, envName, defaultMs) {
|
|
1560
|
+
if (explicitMs !== undefined && validBudgetMs(explicitMs))
|
|
1561
|
+
return explicitMs;
|
|
1562
|
+
const raw = process.env[envName];
|
|
1563
|
+
if (raw !== undefined && /^\d+$/.test(raw)) {
|
|
1564
|
+
const parsed = Number(raw);
|
|
1565
|
+
if (validBudgetMs(parsed))
|
|
1566
|
+
return parsed;
|
|
1567
|
+
}
|
|
1568
|
+
return defaultMs;
|
|
1569
|
+
}
|
|
1570
|
+
function resolveBootTimeoutMs(explicitMs) {
|
|
1571
|
+
return resolveBudgetMs(explicitMs, ENV_BOOT_TIMEOUT_MS, DEFAULT_READINESS_TIMEOUT_MS);
|
|
1572
|
+
}
|
|
1573
|
+
function resolveMuxTimeoutMs(explicitMs) {
|
|
1574
|
+
return resolveBudgetMs(explicitMs, ENV_MUX_TIMEOUT_MS, DEFAULT_SERVE_PROBE_BUDGET_MS);
|
|
1575
|
+
}
|
|
1576
|
+
function resolveConnectTimeoutMs(explicitMs) {
|
|
1577
|
+
return resolveBudgetMs(explicitMs, ENV_CONNECT_TIMEOUT_MS, DEFAULT_CONNECT_TIMEOUT_MS);
|
|
1578
|
+
}
|
|
1548
1579
|
function errorTail(outputTail) {
|
|
1549
1580
|
const lines = outputTail.split(/\r?\n/).filter((line) => line.length > 0);
|
|
1550
1581
|
if (lines.length === 0)
|
|
@@ -1953,7 +1984,8 @@ function resolveOptions(opts) {
|
|
|
1953
1984
|
profile,
|
|
1954
1985
|
dshHome,
|
|
1955
1986
|
idleExitSec,
|
|
1956
|
-
readinessTimeoutMs: opts.readinessTimeoutMs
|
|
1987
|
+
readinessTimeoutMs: resolveBootTimeoutMs(opts.readinessTimeoutMs),
|
|
1988
|
+
serveProbeBudgetMs: resolveMuxTimeoutMs(opts.serveProbeBudgetMs),
|
|
1957
1989
|
...opts.bootJoinTimeoutMs !== undefined ? { bootJoinTimeoutMs: opts.bootJoinTimeoutMs } : {},
|
|
1958
1990
|
staleProbeMs: opts.staleProbeMs ?? DEFAULT_STALE_PROBE_MS,
|
|
1959
1991
|
...opts.maxAgeMs !== undefined ? { maxAgeMs: opts.maxAgeMs } : {},
|
|
@@ -2066,7 +2098,7 @@ async function bootHost(o) {
|
|
|
2066
2098
|
host.authority = ready.authority;
|
|
2067
2099
|
host.cookieHeader = await mintCookieWithRetry(host);
|
|
2068
2100
|
if (ready.via === "listener") {
|
|
2069
|
-
const deadline = Date.now() +
|
|
2101
|
+
const deadline = Date.now() + o.serveProbeBudgetMs;
|
|
2070
2102
|
let serving = false;
|
|
2071
2103
|
while (Date.now() < deadline) {
|
|
2072
2104
|
serving = await probeHostMux({
|
|
@@ -2081,7 +2113,7 @@ async function bootHost(o) {
|
|
|
2081
2113
|
await sleep(SERVE_PROBE_POLL_MS);
|
|
2082
2114
|
}
|
|
2083
2115
|
if (!serving)
|
|
2084
|
-
throw new HostNotServingError(host.outputTail);
|
|
2116
|
+
throw new HostNotServingError(host.outputTail, o.serveProbeBudgetMs);
|
|
2085
2117
|
}
|
|
2086
2118
|
if (!bootClaimIntact(o.dshHome, o.profile, claimStartedAt)) {
|
|
2087
2119
|
throw new HostBootSupersededError;
|
|
@@ -2196,7 +2228,7 @@ async function ensureHost(opts = {}) {
|
|
|
2196
2228
|
attachHost(host);
|
|
2197
2229
|
return makeHandle(host);
|
|
2198
2230
|
}
|
|
2199
|
-
var DEFAULT_PROFILE = "opentui", DEFAULT_IDLE_EXIT_MS = 5000, DEFAULT_IDLE_EXIT_SEC, ENV_IDLE_EXIT_MS = "DSH_OPENTUI_HOST_IDLE_MS", DEFAULT_READINESS_TIMEOUT_MS = 30000, DEFAULT_STALE_PROBE_MS = 8000, BOOT_JOIN_MARGIN_MS = 20000, BOOT_JOIN_POLL_MS = 200, RESPAWN_WINDOW_MS = 15000, MAX_RAPID_RESPAWNS = 3, LISTEN_PROBE_TIMEOUT_MS = 750, LISTEN_POLL_MS = 200, ADOPT_PROBE_TIMEOUT_MS = 2000, SERVE_PROBE_POLL_MS = 250,
|
|
2231
|
+
var DEFAULT_PROFILE = "opentui", DEFAULT_IDLE_EXIT_MS = 5000, DEFAULT_IDLE_EXIT_SEC, ENV_IDLE_EXIT_MS = "DSH_OPENTUI_HOST_IDLE_MS", DEFAULT_READINESS_TIMEOUT_MS = 30000, ENV_BOOT_TIMEOUT_MS = "DSH_OPENTUI_BOOT_TIMEOUT_MS", ENV_MUX_TIMEOUT_MS = "DSH_OPENTUI_MUX_TIMEOUT_MS", DEFAULT_SERVE_PROBE_BUDGET_MS = 20000, ENV_CONNECT_TIMEOUT_MS = "DSH_OPENTUI_CONNECT_TIMEOUT_MS", DEFAULT_CONNECT_TIMEOUT_MS = 30000, DEFAULT_STALE_PROBE_MS = 8000, BOOT_JOIN_MARGIN_MS = 20000, BOOT_JOIN_POLL_MS = 200, RESPAWN_WINDOW_MS = 15000, MAX_RAPID_RESPAWNS = 3, LISTEN_PROBE_TIMEOUT_MS = 750, LISTEN_POLL_MS = 200, ADOPT_PROBE_TIMEOUT_MS = 2000, SERVE_PROBE_POLL_MS = 250, ERROR_TAIL_LINES = 12, KILL_GRACE_MS = 5000, KILL_ESCALATE_MS = 2000, OUTPUT_TAIL_CAP = 8000, URL_LINE, HostLifecycleError, HostBootTimeoutError, HostDiedError, HostNotServingError, HostSpawnError, HostRespawnLoopError, HostBootSupersededError, ProfileMissingError, MintUnavailableError, registry, pendingBoots, respawnHistory, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), realMintPromise = null, RETRYABLE_MINT_ERRORS, MINT_RETRY_BUDGET_MS = 15000, MINT_RETRY_INTERVAL_MS = 250, FFI_FLAG = "--experimental-ffi", __internals;
|
|
2200
2232
|
var init_lifecycle = __esm(() => {
|
|
2201
2233
|
init_host_probe();
|
|
2202
2234
|
init_append_system();
|
|
@@ -2232,9 +2264,11 @@ var init_lifecycle = __esm(() => {
|
|
|
2232
2264
|
};
|
|
2233
2265
|
HostNotServingError = class HostNotServingError extends HostLifecycleError {
|
|
2234
2266
|
outputTail;
|
|
2235
|
-
|
|
2236
|
-
|
|
2267
|
+
budgetMs;
|
|
2268
|
+
constructor(outputTail, budgetMs = DEFAULT_SERVE_PROBE_BUDGET_MS) {
|
|
2269
|
+
super("host-not-serving", `dsh host is listening but never served the client mux (${budgetMs}ms budget)${errorTail(outputTail)}`);
|
|
2237
2270
|
this.outputTail = outputTail;
|
|
2271
|
+
this.budgetMs = budgetMs;
|
|
2238
2272
|
}
|
|
2239
2273
|
};
|
|
2240
2274
|
HostSpawnError = class HostSpawnError extends HostLifecycleError {
|
|
@@ -4332,7 +4366,7 @@ class ClientConnection {
|
|
|
4332
4366
|
};
|
|
4333
4367
|
this.#recovery = options.recovery;
|
|
4334
4368
|
this.#maxConnectAttempts = Math.max(0, options.maxConnectAttempts ?? DEFAULT_MAX_CONNECT_ATTEMPTS);
|
|
4335
|
-
this.#connectBudgetMs =
|
|
4369
|
+
this.#connectBudgetMs = resolveConnectTimeoutMs(options.connectBudgetMs);
|
|
4336
4370
|
this.#diagnostics = options.diagnostics;
|
|
4337
4371
|
this.#pumpCallbacks = {
|
|
4338
4372
|
onReady: (info) => {
|
|
@@ -4487,10 +4521,11 @@ class ClientConnection {
|
|
|
4487
4521
|
}
|
|
4488
4522
|
}
|
|
4489
4523
|
}
|
|
4490
|
-
var RemoteRpcError, RpcTransportError, ConnectionClosedError, ConnectionRetryExhaustedError, DEFAULT_MAX_CONNECT_ATTEMPTS = 3
|
|
4524
|
+
var RemoteRpcError, RpcTransportError, ConnectionClosedError, ConnectionRetryExhaustedError, DEFAULT_MAX_CONNECT_ATTEMPTS = 3;
|
|
4491
4525
|
var init_transport = __esm(() => {
|
|
4492
4526
|
init_lib2();
|
|
4493
4527
|
init_events_source();
|
|
4528
|
+
init_lifecycle();
|
|
4494
4529
|
RemoteRpcError = class RemoteRpcError extends Error {
|
|
4495
4530
|
code;
|
|
4496
4531
|
details;
|
|
@@ -60987,7 +61022,7 @@ var init_subagents_viewer = __esm(() => {
|
|
|
60987
61022
|
import { TextAttributes as TextAttributes12 } from "@opentui/core";
|
|
60988
61023
|
function resolveVersion() {
|
|
60989
61024
|
try {
|
|
60990
|
-
return "0.18.
|
|
61025
|
+
return "0.18.4";
|
|
60991
61026
|
} catch {
|
|
60992
61027
|
return "dev";
|
|
60993
61028
|
}
|
|
@@ -64492,3 +64527,6 @@ export {
|
|
|
64492
64527
|
spawnIdleReaper,
|
|
64493
64528
|
themeNameFromConfig
|
|
64494
64529
|
};
|
|
64530
|
+
|
|
64531
|
+
//# debugId=2E46D145BFA38F7364756E2164756E21
|
|
64532
|
+
//# sourceMappingURL=index.js.map
|