@aiwayds/dsh-opentui 0.18.3 → 0.18.5

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,55 @@ 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.5] - 2026-11-16
9
+
10
+ ### Added
11
+ - `/stop` command: stops the active turn and every running subagent, matching
12
+ the double-Esc confirmation. It is a no-op on an idle session — `interrupt()`
13
+ clears the session binding, so it is only issued while a turn is running.
14
+ - `ctrl+g` opens the subagent activity panel (`/subagents`); `session.first`
15
+ moves to `ctrl+home` (`home`/`alt+home` still work).
16
+
17
+ ### Fixed
18
+ - The todo panel's right border was drawn two columns short: already-sized
19
+ content rows were re-clipped by `clipToWidth`, whose whitespace pattern
20
+ lacked the `g` flag and collapsed only the first run of spaces. Rows now go
21
+ through `takeWidth`, which never rewrites interior whitespace.
22
+ - The footer `msgs` segment stayed hidden for the entire first turn of a fresh
23
+ session: remote info was only refreshed on mount and after the turn ended, so
24
+ the count was still unknown while the turn ran. The first streaming delta (and
25
+ the first tool run) now triggers a throttled re-read.
26
+ - The `/subagents` transcript layer ignored `x` (stop one child) and `Enter`
27
+ (steer): the panel handle was a plain variable read by a reactive `enabled`
28
+ gate, so the layer's keymap never subscribed.
29
+ - The hints bar truncated mid-segment on narrow terminals, hiding
30
+ `esc stop` and `ctrl+c ×2 quit`. Segments are now dropped whole by priority.
31
+
32
+ ## [0.18.4] - 2026-11-16
33
+
34
+ ### Added
35
+ - `--boot-timeout`, `--mux-timeout`, `--connect-timeout` (seconds) with
36
+ matching `DSH_OPENTUI_*_TIMEOUT_MS` env overrides; the three wait budgets
37
+ in the boot chain were previously hard-coded. `--boot-timeout` applies to
38
+ the initial host cold-start only: `/reload` keeps its own hardcoded 30s
39
+ restart budget and does not read this value.
40
+ - `-v` alias for `--version`.
41
+ - `--help` / `-h` usage output for the launcher.
42
+ - `--` separator: everything after it is passed to the client without validation.
43
+ - Client bundles ship sourcemaps (`.map`) so crash traces resolve to source.
44
+
45
+ ### Changed
46
+ - Unknown launcher options are now rejected with `exit 2` and a usage block
47
+ instead of silently booting the full client. A near-miss suggestion is printed
48
+ when the typo is at least 3 characters long and within edit distance 2 of a
49
+ known option (short flags such as `-x` get no misleading hint).
50
+
51
+ ### Fixed
52
+ - The host mux probe aborted a still-connecting socket after removing its
53
+ listeners, turning a normal "host not serving yet" timeout into an uncaught
54
+ `WebSocket was closed before the connection was established` crash. The probe
55
+ now keeps a no-op error listener, so the failure surfaces as `HostNotServingError`.
56
+
8
57
  ## [0.18.3] - 2026-11-16
9
58
 
10
59
  ### Added
package/README.md CHANGED
@@ -33,6 +33,8 @@ npm i -g @aiwayds/dsh-opentui
33
33
  dsh-opentui
34
34
  ```
35
35
 
36
+ Run `dsh-opentui --help` for the full list of launcher options.
37
+
36
38
  ## Upgrading
37
39
 
38
40
  `dsh-opentui upgrade` moves the installed launcher itself to the newest npm
@@ -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; forward those,
156
- // ignore the rest. With nothing to do this is a local, sub-second pass.
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, ...userArgs], {
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}`)
@@ -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
- * `--version` and `--force` are BIN-level flags: they are consumed here and
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 (arg === '--version') {
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
  /**