@aiwayds/dsh-opentui 0.22.0 → 0.23.1
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 +57 -0
- package/README.md +15 -9
- package/bin/dsh-opentui.mjs +20 -30
- package/bin/lib/launcher.mjs +2 -36
- package/dist/bridge/bundle-fingerprint.json +1 -1
- package/dist/bridge/index.js +218 -2
- package/dist/client/index.js +476 -28
- package/dist/client/index.js.map +12 -12
- package/dist/locales/en.json +1 -0
- package/dist/locales/zh-CN.json +1 -0
- package/package.json +1 -1
- package/scripts/lib/bridge-failfast-text.d.mts +1 -0
- package/scripts/lib/bridge-failfast-text.mjs +7 -1
- package/scripts/provision-inproc-profile.mjs +27 -22
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,63 @@ 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.23.1] - 2026-11-20
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **"Stop everything" now really interrupts in-bridge subagents.** Pressing Esc
|
|
13
|
+
twice and confirming "Stop everything?" makes the host interrupt its child
|
|
14
|
+
subagents at once, without waiting for the parent turn to reach a boundary;
|
|
15
|
+
their rows flip to the ⊘ aborted state within ~2s. Answering "no" at the
|
|
16
|
+
confirm leaves every child running untouched. The interrupt also reaches
|
|
17
|
+
children the client roster never showed (live-spawned / hidden subagents),
|
|
18
|
+
and is scoped by session ownership: a TUI can only stop the subagents of its
|
|
19
|
+
own session, never another session's. The model-side `rounds` / `model`
|
|
20
|
+
information on those rows is preserved.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **Running subagents are visible the moment they spawn.** In 0.23.0 a live
|
|
25
|
+
child was absent from the ctrl+g panel (and shift+k reported "no running
|
|
26
|
+
subagents") until the next turn boundary drained the journal. Live spawn now
|
|
27
|
+
enters the catalog immediately. Root cause: catalog-family spawn frames were
|
|
28
|
+
being silently dropped by the anti-collision guard.
|
|
29
|
+
|
|
30
|
+
### Internal
|
|
31
|
+
|
|
32
|
+
- Bridge: added a `subagent-index` (session → sub-agents mapping) and
|
|
33
|
+
`subagents.interrupt` / `subagents.stopChildren` methods gated on session
|
|
34
|
+
ownership at both entrances; converged the stop path into a shell
|
|
35
|
+
confirm-then-emit flow; added the ⊘ state and i18n strings to tui-base.
|
|
36
|
+
|
|
37
|
+
## [0.23.0] - 2026-11-19
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- **The in-process bridge is now the default.** A plain `dsh-opentui` boot
|
|
42
|
+
provisions the `opentui-inproc` profile and drives the TUI through the bridge
|
|
43
|
+
seam — no flag or env var needed. `DSH_OPENTUI_INPROC=1` remains valid
|
|
44
|
+
(idempotent). Setting `DSH_OPENTUI_INPROC=0` is the escape hatch back to the
|
|
45
|
+
legacy remote thin-client seam. A failed bridge handshake / fingerprint check
|
|
46
|
+
still fails fast with a diagnosis, a repair command and a mode notice, and
|
|
47
|
+
never silently falls back.
|
|
48
|
+
- **`--remote` has been removed.** It is no longer accepted as a launch flag;
|
|
49
|
+
passing it exits with a usage error (exit 2). The legacy remote seam is now
|
|
50
|
+
reachable only through the `DSH_OPENTUI_INPROC=0` env escape hatch.
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
|
|
54
|
+
- **Ghost subagent rows are swept at turn boundaries.** When a parent turn is
|
|
55
|
+
aborted the host never journals the subagent's settle notice, so the child
|
|
56
|
+
stayed `running` forever. The bridge seam now reconciles its catalog against
|
|
57
|
+
the host session list at every turn terminal and after session recovery, and
|
|
58
|
+
settles any child the host no longer reports as running. Best-effort and
|
|
59
|
+
idempotent; still no wall-clock fallback.
|
|
60
|
+
- **ctrl+g subagent views show real progress.** `rounds`, `lastLine` and
|
|
61
|
+
`model` are now read from each subagent's own journal (lazily, cached, and
|
|
62
|
+
re-read once the child settles), so the viewer no longer shows 0 rounds, an
|
|
63
|
+
empty last line, and a missing model.
|
|
64
|
+
|
|
8
65
|
## [0.22.0] - 2026-11-19
|
|
9
66
|
|
|
10
67
|
### Changed
|
package/README.md
CHANGED
|
@@ -8,8 +8,9 @@ running on Bun.
|
|
|
8
8
|
The repo's product is the **architecture**; the shipped Shell is a working
|
|
9
9
|
chat agent TUI on top of it. By default it boots an in-process session bridge
|
|
10
10
|
inside the dsh host and drives the OpenTUI client over a stdio JSON-lines
|
|
11
|
-
channel; the legacy thin client over the host's remote API is retained
|
|
12
|
-
`--remote`
|
|
11
|
+
channel; the legacy thin client over the host's remote API is retained only as
|
|
12
|
+
an escape hatch (`DSH_OPENTUI_INPROC=0`). The `--remote` flag was removed in
|
|
13
|
+
0.23.0.
|
|
13
14
|
|
|
14
15
|
| Package | What it is |
|
|
15
16
|
|---|---|
|
|
@@ -38,7 +39,9 @@ dsh-opentui
|
|
|
38
39
|
|
|
39
40
|
The first launch automatically provisions the `opentui-inproc` profile (bridge
|
|
40
41
|
dependencies are symlinked from the dsh install, never copied). If that bridge
|
|
41
|
-
install is damaged, rerun with `dsh-opentui --repair-bridge`.
|
|
42
|
+
install is damaged, rerun with `dsh-opentui --repair-bridge`. To fall back to
|
|
43
|
+
the legacy remote thin client for a launch, set `DSH_OPENTUI_INPROC=0` — that
|
|
44
|
+
skips in-process provisioning and selects the remote seam.
|
|
42
45
|
|
|
43
46
|
Run `dsh-opentui --help` for the full list of launcher options.
|
|
44
47
|
|
|
@@ -105,13 +108,16 @@ confirmation prompt is refused.
|
|
|
105
108
|
|
|
106
109
|
## Client mode
|
|
107
110
|
|
|
108
|
-
>
|
|
111
|
+
> Since 0.23.0 the default TUI path is the in-process session bridge
|
|
109
112
|
> (`opentui-inproc` profile, see ADR-0009). The thin-client topology below is
|
|
110
|
-
> the
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
> the legacy path, reachable only through the `DSH_OPENTUI_INPROC=0` escape
|
|
114
|
+
> hatch. The old `--remote` flag was removed in 0.23.0; passing it is a usage
|
|
115
|
+
> error (exit 2).
|
|
116
|
+
|
|
117
|
+
With `DSH_OPENTUI_INPROC=0`, `dsh-opentui` starts a thin client TUI
|
|
118
|
+
(`dist/client/index.js` under Bun) that connects to a resident
|
|
119
|
+
`dsh --profile opentui` host process. The launcher handles everything on
|
|
120
|
+
startup:
|
|
115
121
|
|
|
116
122
|
- **Profile bootstrap** — `$DSH_HOME/profiles/opentui` is provisioned on
|
|
117
123
|
EVERY launch (idempotent; a no-op pass is sub-second). Pass `--provider` /
|
package/bin/dsh-opentui.mjs
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* clients are connected; ADR-0009). `--repair-bridge` is a terminal
|
|
11
11
|
* maintenance command: it clears this profile's stale instances (TERM
|
|
12
12
|
* then KILL), runs the in-process bridge self-heal (T7), and exits before
|
|
13
|
-
* any bun/dsh check, TUI launch, or default-seam change; it
|
|
14
|
-
*
|
|
13
|
+
* any bun/dsh check, TUI launch, or default-seam change; it always runs
|
|
14
|
+
* full in-process provisioning (bridge is the default since 0.23.0).
|
|
15
15
|
* All three are consumed by the bin and never forwarded to the client.
|
|
16
16
|
* 1. bun check — the client bundle runs under bun (FFI, import attributes,
|
|
17
17
|
* bun export conditions); no bun on PATH → install guidance, exit 1.
|
|
@@ -56,7 +56,7 @@ import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSyn
|
|
|
56
56
|
import { constants as osConstants, homedir } from 'node:os'
|
|
57
57
|
import { dirname, join } from 'node:path'
|
|
58
58
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
59
|
-
import { ancestorPids,
|
|
59
|
+
import { ancestorPids, formatUpgradeUsage, formatUsage, killStaleProcesses, launcherFlagConflict, LAUNCHER_TIMEOUT_FLAGS, parseLauncherArgs, parseLauncherOptions, parseProcessHomes, parseProcessRows, parseUpgradeArgs, prelaunchFailurePolicy, readLauncherVersion, selectStaleProcesses, validateLauncherArgs } from './lib/launcher.mjs'
|
|
60
60
|
|
|
61
61
|
const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)))
|
|
62
62
|
const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
@@ -89,11 +89,7 @@ if (versionFlag) {
|
|
|
89
89
|
// P3-3: make flag combinations that used to fall into dead corners explicit.
|
|
90
90
|
// Checked here (before the upgrade/help/repair branches) so the same conflict
|
|
91
91
|
// wins regardless of which branch a combination would otherwise reach.
|
|
92
|
-
const
|
|
93
|
-
const flagConflict = launcherFlagConflict(
|
|
94
|
-
{ force: forceFlag, repairBridge: repairBridgeFlag, yes: yesFlag },
|
|
95
|
-
remoteRequested,
|
|
96
|
-
)
|
|
92
|
+
const flagConflict = launcherFlagConflict({ force: forceFlag, repairBridge: repairBridgeFlag, yes: yesFlag })
|
|
97
93
|
if (flagConflict === 'yes-without-force') {
|
|
98
94
|
console.error('dsh-opentui: --yes is only meaningful together with --force.')
|
|
99
95
|
process.exit(2)
|
|
@@ -102,17 +98,6 @@ if (flagConflict === 'repair-force') {
|
|
|
102
98
|
console.error('dsh-opentui: --repair-bridge and --force are mutually exclusive; choose one.')
|
|
103
99
|
process.exit(2)
|
|
104
100
|
}
|
|
105
|
-
if (flagConflict === 'repair-remote') {
|
|
106
|
-
console.error('dsh-opentui: --repair-bridge cannot be combined with --remote (remote mode has no bridge to repair).')
|
|
107
|
-
process.exit(2)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// --- 0.4 --remote deprecation (T10): one clear notice per launch -------------
|
|
111
|
-
// Emitted after --version (whose short-circuit stays absolute) and before the
|
|
112
|
-
// upgrade/help paths, so `--remote --help` also carries it. `emitRemoteDeprecation`
|
|
113
|
-
// prints AT MOST ONCE even when the flag is repeated, and the notice names the
|
|
114
|
-
// removal line (0.23.0) plus the replacement entry (inproc default, no flag).
|
|
115
|
-
emitRemoteDeprecation([userArgs, passthrough])
|
|
116
101
|
|
|
117
102
|
// --- 0.5 upgrade subcommand -------------------------------------------------
|
|
118
103
|
// `upgrade` is a positional subcommand: only the first remaining argument may
|
|
@@ -204,6 +189,12 @@ const validation = validateLauncherArgs(userArgs, { skip: LAUNCHER_TIMEOUT_FLAGS
|
|
|
204
189
|
if (validation.unknown.length > 0) {
|
|
205
190
|
for (const flag of validation.unknown) {
|
|
206
191
|
console.error(`dsh-opentui: unknown option '${flag}'`)
|
|
192
|
+
// P2-4b: the removed --remote flag has a launch-level replacement — point
|
|
193
|
+
// users at it instead of leaving a dead end. Other unknown flags get only
|
|
194
|
+
// the generic did-you-mean rule (no misleading migration advice).
|
|
195
|
+
if (flag === '--remote') {
|
|
196
|
+
console.error('dsh-opentui: use DSH_OPENTUI_INPROC=0 for the legacy remote seam')
|
|
197
|
+
}
|
|
207
198
|
if (validation.suggestions[flag]) {
|
|
208
199
|
console.error(`dsh-opentui: did you mean '${validation.suggestions[flag]}'?`)
|
|
209
200
|
}
|
|
@@ -213,9 +204,8 @@ if (validation.unknown.length > 0) {
|
|
|
213
204
|
}
|
|
214
205
|
|
|
215
206
|
// --- 0.7 --repair-bridge: terminal in-process bridge self-heal (T7) ---------
|
|
216
|
-
// This is a maintenance command, not a launch. It
|
|
217
|
-
//
|
|
218
|
-
// the opt-in startup path uses, in its repair mode. It deliberately exits here
|
|
207
|
+
// This is a maintenance command, not a launch. It invokes the SAME provisioner
|
|
208
|
+
// the default startup path uses, in its repair mode. It deliberately exits here
|
|
219
209
|
// — before the bun/dsh checks, the default `opentui` profile bootstrap, the
|
|
220
210
|
// client-connection link, and the bun client launch — so it never starts a TUI
|
|
221
211
|
// and never changes the default seam (that is M2's job). The provisioner owns
|
|
@@ -315,14 +305,14 @@ const opentuiProfileDir = join(dshHome, 'profiles', 'opentui')
|
|
|
315
305
|
}
|
|
316
306
|
}
|
|
317
307
|
|
|
318
|
-
// --- 3b. In-process bridge profile provisioning (
|
|
319
|
-
//
|
|
320
|
-
//
|
|
321
|
-
//
|
|
322
|
-
//
|
|
323
|
-
// A non-zero exit is fatal
|
|
324
|
-
// unlike the best-effort
|
|
325
|
-
if (process.env.DSH_OPENTUI_INPROC
|
|
308
|
+
// --- 3b. In-process bridge profile provisioning (default since 0.23.0) -----
|
|
309
|
+
// The bridge is the default, so this runs on EVERY launch; only the explicit
|
|
310
|
+
// escape hatch DSH_OPENTUI_INPROC=0 skips it (legacy remote thin client). "1"
|
|
311
|
+
// is still accepted and is now a no-op-equivalent (idempotent). The script
|
|
312
|
+
// provisions ONLY the `opentui-inproc` profile: bundle manifest + absolute
|
|
313
|
+
// symlink to the embedded dist/bridge artifact. A non-zero exit is fatal here
|
|
314
|
+
// (the bridge cannot work without it), unlike the best-effort path above.
|
|
315
|
+
if (process.env.DSH_OPENTUI_INPROC !== '0') {
|
|
326
316
|
const r = spawnSync(process.execPath, [join(pkgRoot, 'scripts', 'provision-inproc-profile.mjs')], {
|
|
327
317
|
stdio: 'inherit',
|
|
328
318
|
})
|
package/bin/lib/launcher.mjs
CHANGED
|
@@ -123,9 +123,6 @@ export const KNOWN_CLIENT_ARGS = [
|
|
|
123
123
|
'--resume-last',
|
|
124
124
|
'--session',
|
|
125
125
|
'--session=',
|
|
126
|
-
// T10: retained but deprecated; removed in 0.23.0. Still accepted so the
|
|
127
|
-
// legacy thin-client seam remains selectable during phase one.
|
|
128
|
-
'--remote',
|
|
129
126
|
]
|
|
130
127
|
|
|
131
128
|
/**
|
|
@@ -290,50 +287,19 @@ export function validateLauncherArgs(rest, { skip = [] } = {}) {
|
|
|
290
287
|
}
|
|
291
288
|
}
|
|
292
289
|
|
|
293
|
-
/**
|
|
294
|
-
* T10 — the `--remote` deprecation notice. Names the removal line (0.23.0)
|
|
295
|
-
* and the inproc migration path (set DSH_OPENTUI_INPROC=1, then drop the flag;
|
|
296
|
-
* inproc becomes the default in 0.23.0). Kept here (pure)
|
|
297
|
-
* so the "printed exactly once" contract is unit-testable without a TUI.
|
|
298
|
-
*/
|
|
299
|
-
export const REMOTE_DEPRECATION_NOTICE =
|
|
300
|
-
'dsh-opentui: --remote is deprecated and will be removed in 0.23.0; ' +
|
|
301
|
-
'to move to the in-process bridge, set DSH_OPENTUI_INPROC=1 and drop the flag ' +
|
|
302
|
-
'(inproc becomes the default in 0.23.0; the /resume, --session, --resume-last entries also use it).'
|
|
303
|
-
|
|
304
|
-
/** True when `--remote` appears anywhere in the launch argv (before or after
|
|
305
|
-
* a `--` separator). */
|
|
306
|
-
export function isRemoteRequested(...argvLists) {
|
|
307
|
-
return argvLists.some((list) => Array.isArray(list) && list.includes('--remote'))
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Emit the deprecation notice AT MOST ONCE per launch, even if `--remote`
|
|
312
|
-
* appears multiple times. Returns the number of lines written (0 or 1) so
|
|
313
|
-
* callers/tests can assert the "exactly once" contract. `sink` is injectable.
|
|
314
|
-
*/
|
|
315
|
-
export function emitRemoteDeprecation(argvLists, sink = console.warn) {
|
|
316
|
-
if (!argvLists.some((list) => Array.isArray(list) && list.includes('--remote'))) return 0
|
|
317
|
-
sink(REMOTE_DEPRECATION_NOTICE)
|
|
318
|
-
return 1
|
|
319
|
-
}
|
|
320
|
-
|
|
321
290
|
/**
|
|
322
291
|
* P3-3 — explicit handling of launcher flag combinations that previously fell
|
|
323
292
|
* into dead corners (silently ignored one flag or ran the wrong branch). Pure
|
|
324
293
|
* so the bin's reject/notice decisions are unit-testable without spawning.
|
|
325
|
-
* `remote` is precomputed via `isRemoteRequested(userArgs, passthrough)`.
|
|
326
294
|
*
|
|
327
295
|
* Returns a conflict code, or null when the combination is fine:
|
|
328
296
|
* 'repair-force' --repair-bridge + --force → mutually exclusive
|
|
329
|
-
* 'repair-remote' --repair-bridge + --remote → no bridge in remote mode
|
|
330
297
|
* 'yes-without-force' --yes without --force/--repair-bridge (under
|
|
331
298
|
* --repair-bridge, --yes is tolerated — the repair branch
|
|
332
299
|
* never reads it — and is intentionally allowed through)
|
|
333
300
|
*/
|
|
334
|
-
export function launcherFlagConflict({ force, repairBridge, yes } = {}
|
|
301
|
+
export function launcherFlagConflict({ force, repairBridge, yes } = {}) {
|
|
335
302
|
if (repairBridge && force) return 'repair-force'
|
|
336
|
-
if (repairBridge && remote) return 'repair-remote'
|
|
337
303
|
if (yes && !force && !repairBridge) return 'yes-without-force'
|
|
338
304
|
return null
|
|
339
305
|
}
|
|
@@ -361,6 +327,7 @@ export function formatUsage() {
|
|
|
361
327
|
' -h, --help print this help and exit',
|
|
362
328
|
'',
|
|
363
329
|
'Environment:',
|
|
330
|
+
' DSH_OPENTUI_INPROC=0 use the legacy remote thin-client seam instead of the default in-process bridge (escape hatch); unset or 1 = bridge',
|
|
364
331
|
' DSH_OPENTUI_BOOT_TIMEOUT_MS host cold-start budget in ms (CLI flag wins)',
|
|
365
332
|
' DSH_OPENTUI_MUX_TIMEOUT_MS mux readiness budget in ms (CLI flag wins)',
|
|
366
333
|
' DSH_OPENTUI_CONNECT_TIMEOUT_MS first-connect budget in ms (CLI flag wins)',
|
|
@@ -368,7 +335,6 @@ export function formatUsage() {
|
|
|
368
335
|
'',
|
|
369
336
|
'Client options (passed through; put them after -- to skip validation):',
|
|
370
337
|
' --new, --resume-last, --session <id>',
|
|
371
|
-
' --remote (deprecated; removed in 0.23.0) force the legacy thin-client seam; default is the in-process bridge in inproc mode',
|
|
372
338
|
'',
|
|
373
339
|
'Exit codes:',
|
|
374
340
|
' 0 success, --version, or --help',
|
package/dist/bridge/index.js
CHANGED
|
@@ -881,6 +881,92 @@ function logLegacyAppendPreset(logger) {
|
|
|
881
881
|
logger.debug(`[append-system] header.agentPreset="${APPEND_SYSTEM_PRESET_ID}" 为旧版合成 preset id,在本 profile 中不生效(无 agentPresets 服务);append 内容由 bridge section 注入,行为与新建会话一致`);
|
|
882
882
|
}
|
|
883
883
|
|
|
884
|
+
// ../bridge/src/subagent-index.ts
|
|
885
|
+
class SubagentIndex {
|
|
886
|
+
rows = new Map;
|
|
887
|
+
built = false;
|
|
888
|
+
reset() {
|
|
889
|
+
this.rows.clear();
|
|
890
|
+
this.built = false;
|
|
891
|
+
}
|
|
892
|
+
syncFromList(items) {
|
|
893
|
+
const next = new Map;
|
|
894
|
+
let subagentCount = 0;
|
|
895
|
+
for (const row of items) {
|
|
896
|
+
if (row === null || typeof row !== "object")
|
|
897
|
+
continue;
|
|
898
|
+
if (row.origin !== "subagent")
|
|
899
|
+
continue;
|
|
900
|
+
if (typeof row.sessionId !== "string" || row.sessionId === "")
|
|
901
|
+
continue;
|
|
902
|
+
subagentCount += 1;
|
|
903
|
+
next.set(row.sessionId, {
|
|
904
|
+
parentSessionId: typeof row.parentSessionId === "string" ? row.parentSessionId : "",
|
|
905
|
+
startedAt: typeof row.updatedAt === "number" ? row.updatedAt : 0,
|
|
906
|
+
status: row.running === true ? "running" : "settled"
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
for (const [childId, cached] of this.rows) {
|
|
910
|
+
if (!next.has(childId))
|
|
911
|
+
next.set(childId, cached);
|
|
912
|
+
}
|
|
913
|
+
this.rows.clear();
|
|
914
|
+
for (const [childId, row] of next)
|
|
915
|
+
this.rows.set(childId, row);
|
|
916
|
+
this.built = true;
|
|
917
|
+
return subagentCount;
|
|
918
|
+
}
|
|
919
|
+
noteCatalog(childId, parentSessionId, startedAt) {
|
|
920
|
+
if (typeof childId !== "string" || childId === "")
|
|
921
|
+
return;
|
|
922
|
+
const existing = this.rows.get(childId);
|
|
923
|
+
if (existing !== undefined) {
|
|
924
|
+
if (!existing.startedAt && typeof startedAt === "number")
|
|
925
|
+
existing.startedAt = startedAt;
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
this.rows.set(childId, {
|
|
929
|
+
parentSessionId,
|
|
930
|
+
startedAt: typeof startedAt === "number" ? startedAt : 0,
|
|
931
|
+
status: "running"
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
noteSettled(childId, lastSeq) {
|
|
935
|
+
if (typeof childId !== "string" || childId === "")
|
|
936
|
+
return;
|
|
937
|
+
const row = this.rows.get(childId);
|
|
938
|
+
if (row === undefined)
|
|
939
|
+
return;
|
|
940
|
+
row.status = "settled";
|
|
941
|
+
if (typeof lastSeq === "number")
|
|
942
|
+
row.lastSeq = lastSeq;
|
|
943
|
+
}
|
|
944
|
+
has(childId) {
|
|
945
|
+
return this.rows.has(childId);
|
|
946
|
+
}
|
|
947
|
+
get(childId) {
|
|
948
|
+
return this.rows.get(childId);
|
|
949
|
+
}
|
|
950
|
+
runningChildrenOf(parentSessionId) {
|
|
951
|
+
const out = [];
|
|
952
|
+
for (const [childId, row] of this.rows) {
|
|
953
|
+
if (row.parentSessionId === parentSessionId && row.status === "running") {
|
|
954
|
+
out.push({ childId, row });
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return out;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
var indexes = new WeakMap;
|
|
961
|
+
function getSubagentIndex(ctx) {
|
|
962
|
+
let index = indexes.get(ctx);
|
|
963
|
+
if (index === undefined) {
|
|
964
|
+
index = new SubagentIndex;
|
|
965
|
+
indexes.set(ctx, index);
|
|
966
|
+
}
|
|
967
|
+
return index;
|
|
968
|
+
}
|
|
969
|
+
|
|
884
970
|
// ../bridge/src/index.ts
|
|
885
971
|
function createBridgeUserMessage(text) {
|
|
886
972
|
return Object.freeze({
|
|
@@ -925,6 +1011,7 @@ function getAskRegistry(ctx) {
|
|
|
925
1011
|
}
|
|
926
1012
|
var PROTOCOL_VERSION = 1;
|
|
927
1013
|
var STDIO_SWITCH = "DSH_OPENTUI_BRIDGE_STDIO";
|
|
1014
|
+
var BRIDGE_CAPABILITIES = ["subagents.interrupt", "subagents.stopChildren"];
|
|
928
1015
|
var TERMINAL_TURN_ID_LIMIT = 64;
|
|
929
1016
|
function findPackageVersion(entryFile, wantedName) {
|
|
930
1017
|
try {
|
|
@@ -1133,6 +1220,7 @@ function apply(ctx, config) {
|
|
|
1133
1220
|
const bridgeVersion = readBridgeVersion();
|
|
1134
1221
|
const hostVersion = readHostVersion();
|
|
1135
1222
|
logger.info(`[dsh-opentui-bridge] stdio protocol active (protocolVersion=${PROTOCOL_VERSION}, bridge=${bridgeVersion}, host=${hostVersion})`);
|
|
1223
|
+
getSubagentIndex(ctx).reset();
|
|
1136
1224
|
let buffer = "";
|
|
1137
1225
|
let closing = false;
|
|
1138
1226
|
let awaitingDrain = false;
|
|
@@ -1342,6 +1430,7 @@ function apply(ctx, config) {
|
|
|
1342
1430
|
const childId = typeof data.childId === "string" ? data.childId : "";
|
|
1343
1431
|
if (!childId)
|
|
1344
1432
|
return;
|
|
1433
|
+
getSubagentIndex(ctx).noteCatalog(childId, sessionId, typeof data.childCreatedAt === "number" ? data.childCreatedAt : undefined);
|
|
1345
1434
|
const turnId = state !== undefined && !state.ended ? state.turnId : inFlightTurnId ?? "";
|
|
1346
1435
|
const label = typeof data.label === "string" && data.label !== "" ? data.label : typeof data.name === "string" ? data.name : "";
|
|
1347
1436
|
emitEvent("agent.spawn", {
|
|
@@ -1383,6 +1472,12 @@ function apply(ctx, config) {
|
|
|
1383
1472
|
}
|
|
1384
1473
|
return;
|
|
1385
1474
|
}
|
|
1475
|
+
if (type === "turn/end") {
|
|
1476
|
+
const index = getSubagentIndex(ctx);
|
|
1477
|
+
if (index.has(sessionId)) {
|
|
1478
|
+
index.noteSettled(sessionId, typeof data.seq === "number" ? data.seq : undefined);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1386
1481
|
if (state === undefined || state.ended)
|
|
1387
1482
|
return;
|
|
1388
1483
|
if (sessionId !== state.sessionId)
|
|
@@ -1961,6 +2056,109 @@ function apply(ctx, config) {
|
|
|
1961
2056
|
replyError(req.id, mapped.code, mapped.message, mapped.detail);
|
|
1962
2057
|
}
|
|
1963
2058
|
}
|
|
2059
|
+
async function reconcileSubagentIndex() {
|
|
2060
|
+
const controller = resolveSessionController(ctx);
|
|
2061
|
+
if (controller === undefined) {
|
|
2062
|
+
logger.warn("[dsh-opentui-bridge] subagent index reconcile skipped: sessionController unavailable");
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2065
|
+
try {
|
|
2066
|
+
const raw = await controller.list({ _request: {} });
|
|
2067
|
+
if (raw !== null && typeof raw === "object" && !Array.isArray(raw) && Array.isArray(raw.items)) {
|
|
2068
|
+
const count = getSubagentIndex(ctx).syncFromList(raw.items);
|
|
2069
|
+
logger.info("[dsh-opentui-bridge] subagent index reconciled: subagents=%d rows=%d", count, getSubagentIndex(ctx).rows.size);
|
|
2070
|
+
} else {
|
|
2071
|
+
logger.warn("[dsh-opentui-bridge] subagent index reconcile skipped: malformed session.list reply");
|
|
2072
|
+
}
|
|
2073
|
+
} catch (err) {
|
|
2074
|
+
logger.warn("[dsh-opentui-bridge] subagent index reconcile failed: %s", err);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
function gateSubagentParent(parentSessionId) {
|
|
2078
|
+
if (binding === undefined) {
|
|
2079
|
+
return { code: "NO_SESSION", message: "no session is open; cannot authorize a subagent stop" };
|
|
2080
|
+
}
|
|
2081
|
+
if (typeof parentSessionId !== "string" || parentSessionId === "") {
|
|
2082
|
+
return { code: "BAD_PARAMS", message: "parentSessionId must be a non-empty string" };
|
|
2083
|
+
}
|
|
2084
|
+
if (parentSessionId !== binding.sessionId) {
|
|
2085
|
+
return {
|
|
2086
|
+
code: "OWNERSHIP_MISMATCH",
|
|
2087
|
+
message: "parentSessionId is not the bound session",
|
|
2088
|
+
detail: { parentSessionId, boundSessionId: binding.sessionId }
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
return;
|
|
2092
|
+
}
|
|
2093
|
+
function issueChildCancel(childId) {
|
|
2094
|
+
try {
|
|
2095
|
+
const agents = resolveAgents(ctx);
|
|
2096
|
+
const agent = agents?.get(childId);
|
|
2097
|
+
if (agent === undefined)
|
|
2098
|
+
return "agent not available in host registry";
|
|
2099
|
+
agent.cancel({ kind: "user" }, { keepInbox: true });
|
|
2100
|
+
return;
|
|
2101
|
+
} catch (err) {
|
|
2102
|
+
return err instanceof Error ? err.message : String(err);
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
async function handleInterruptSubagent(req) {
|
|
2106
|
+
const gate = gateSubagentParent(req.params.parentSessionId);
|
|
2107
|
+
if (gate !== undefined) {
|
|
2108
|
+
replyError(req.id, gate.code, gate.message, gate.detail);
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2111
|
+
const childId = req.params.childId;
|
|
2112
|
+
if (typeof childId !== "string" || childId === "") {
|
|
2113
|
+
replyError(req.id, "BAD_PARAMS", "childId must be a non-empty string");
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
const parentSessionId = req.params.parentSessionId;
|
|
2117
|
+
await reconcileSubagentIndex();
|
|
2118
|
+
const index = getSubagentIndex(ctx);
|
|
2119
|
+
const row = index.get(childId);
|
|
2120
|
+
if (row === undefined || row.parentSessionId !== parentSessionId) {
|
|
2121
|
+
replyError(req.id, "OWNERSHIP_MISMATCH", "child is not a subagent of the bound session", {
|
|
2122
|
+
childId,
|
|
2123
|
+
parentSessionId
|
|
2124
|
+
});
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
if (row.status !== "running") {
|
|
2128
|
+
replyOk(req.id, { childId, disposition: "already-settled" });
|
|
2129
|
+
return;
|
|
2130
|
+
}
|
|
2131
|
+
const detail = issueChildCancel(childId);
|
|
2132
|
+
replyOk(req.id, {
|
|
2133
|
+
childId,
|
|
2134
|
+
disposition: detail === undefined ? "cancel-issued" : "failed",
|
|
2135
|
+
...detail !== undefined ? { detail } : {}
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
2138
|
+
async function handleStopChildren(req) {
|
|
2139
|
+
const gate = gateSubagentParent(req.params.parentSessionId);
|
|
2140
|
+
if (gate !== undefined) {
|
|
2141
|
+
replyError(req.id, gate.code, gate.message, gate.detail);
|
|
2142
|
+
return;
|
|
2143
|
+
}
|
|
2144
|
+
const parentSessionId = req.params.parentSessionId;
|
|
2145
|
+
await reconcileSubagentIndex();
|
|
2146
|
+
const index = getSubagentIndex(ctx);
|
|
2147
|
+
const children = [];
|
|
2148
|
+
for (const [childId, row] of index.rows) {
|
|
2149
|
+
if (row.status !== "running")
|
|
2150
|
+
continue;
|
|
2151
|
+
if (row.parentSessionId !== parentSessionId)
|
|
2152
|
+
continue;
|
|
2153
|
+
const detail = issueChildCancel(childId);
|
|
2154
|
+
children.push({
|
|
2155
|
+
childId,
|
|
2156
|
+
disposition: detail === undefined ? "cancel-issued" : "failed",
|
|
2157
|
+
...detail !== undefined ? { detail } : {}
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
replyOk(req.id, { children });
|
|
2161
|
+
}
|
|
1964
2162
|
async function handleReplay(req) {
|
|
1965
2163
|
const persistence = resolvePersistence(ctx);
|
|
1966
2164
|
if (persistence === undefined) {
|
|
@@ -2029,7 +2227,12 @@ function apply(ctx, config) {
|
|
|
2029
2227
|
return;
|
|
2030
2228
|
}
|
|
2031
2229
|
if (req.method === "bridge.ping") {
|
|
2032
|
-
replyOk(req.id, {
|
|
2230
|
+
replyOk(req.id, {
|
|
2231
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
2232
|
+
bridgeVersion,
|
|
2233
|
+
hostVersion,
|
|
2234
|
+
capabilities: [...BRIDGE_CAPABILITIES]
|
|
2235
|
+
});
|
|
2033
2236
|
return;
|
|
2034
2237
|
}
|
|
2035
2238
|
if (req.method === "bridge.hello") {
|
|
@@ -2038,7 +2241,12 @@ function apply(ctx, config) {
|
|
|
2038
2241
|
replyError(req.id, "VERSION_INCOMPATIBLE", `protocolVersion incompatible: client=${String(clientVersion)}, bridge=${PROTOCOL_VERSION}, host=${hostVersion}`, { clientProtocolVersion: clientVersion, bridgeProtocolVersion: PROTOCOL_VERSION, hostVersion });
|
|
2039
2242
|
return;
|
|
2040
2243
|
}
|
|
2041
|
-
replyOk(req.id, {
|
|
2244
|
+
replyOk(req.id, {
|
|
2245
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
2246
|
+
bridgeVersion,
|
|
2247
|
+
hostVersion,
|
|
2248
|
+
capabilities: [...BRIDGE_CAPABILITIES]
|
|
2249
|
+
});
|
|
2042
2250
|
return;
|
|
2043
2251
|
}
|
|
2044
2252
|
if (req.method === "model.currentSelection") {
|
|
@@ -2058,6 +2266,14 @@ function apply(ctx, config) {
|
|
|
2058
2266
|
await handleListSessions(req);
|
|
2059
2267
|
return;
|
|
2060
2268
|
}
|
|
2269
|
+
if (req.method === "subagents.interrupt") {
|
|
2270
|
+
await handleInterruptSubagent(req);
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2273
|
+
if (req.method === "subagents.stopChildren") {
|
|
2274
|
+
await handleStopChildren(req);
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2061
2277
|
if (req.method === "session.open") {
|
|
2062
2278
|
await handleOpen(req);
|
|
2063
2279
|
return;
|