@aiwayds/dsh-opentui 0.23.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 CHANGED
@@ -5,6 +5,35 @@ 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
+
8
37
  ## [0.23.0] - 2026-11-19
9
38
 
10
39
  ### Changed
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@aiwayds/dsh-opentui-bridge",
3
3
  "version": "0.1.0",
4
- "sha256": "746fea7d4feac36427f0e42971c5417d5e7df59d95664d76f9713225dd8c6f03"
4
+ "sha256": "449350ad2f4be20203ca16195eeed30b1ff928f8a13d648fd6342be3623ac53e"
5
5
  }
@@ -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, { protocolVersion: PROTOCOL_VERSION, bridgeVersion, hostVersion });
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, { protocolVersion: PROTOCOL_VERSION, bridgeVersion, hostVersion });
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;
@@ -52223,6 +52223,17 @@ async function stopEverything(seam) {
52223
52223
  const parent = turn !== undefined && turn !== "idle";
52224
52224
  if (parent)
52225
52225
  seam.interrupt();
52226
+ if (seam.hasBridgeCapability?.("subagents.stopChildren") === true && seam.stopChildren) {
52227
+ let dispositions = [];
52228
+ try {
52229
+ dispositions = await seam.stopChildren();
52230
+ } catch {}
52231
+ return {
52232
+ parent,
52233
+ children: dispositions.filter((row) => row.disposition === "cancel-issued").length,
52234
+ dispositions
52235
+ };
52236
+ }
52226
52237
  let children = 0;
52227
52238
  for (const view of seam.subagentViews?.() ?? []) {
52228
52239
  if (view.status !== "running" || !seam.interruptChild)
@@ -63101,7 +63112,7 @@ function viewerRows(views) {
63101
63112
  return [...running, ...settled];
63102
63113
  }
63103
63114
  function viewerRowText(view, roundCap, elapsedText) {
63104
- const glyph = view.status === "running" ? "\u280B" : view.status === "completed" ? "\u2713" : view.status === "failed" ? "\u2717" : "\u2014";
63115
+ const glyph = view.status === "running" ? "\u280B" : view.status === "completed" ? "\u2713" : view.status === "failed" ? "\u2717" : view.status === "interrupted" ? "\u2298" : "\u2014";
63105
63116
  const stop = subagentHardStopGlyph(view);
63106
63117
  const label = `${stop ? `${stop} ` : ""}${titlecase(view.label)}`;
63107
63118
  const suffix = subagentMarkerSuffix(view);
@@ -63443,7 +63454,7 @@ function SubagentsViewer(props) {
63443
63454
  function headerText(view, now) {
63444
63455
  if (view === undefined)
63445
63456
  return t("panel.subagents.header.fallback");
63446
- const status = view.status === "running" ? t("panel.subagents.status.running") : view.status === "completed" ? t("panel.subagents.status.completed") : view.status === "failed" ? t("panel.subagents.status.failed") : t("panel.subagents.status.cancelled");
63457
+ const status = view.status === "running" ? t("panel.subagents.status.running") : view.status === "completed" ? t("panel.subagents.status.completed") : view.status === "failed" ? t("panel.subagents.status.failed") : view.status === "interrupted" ? t("panel.subagents.status.interrupted") : t("panel.subagents.status.cancelled");
63447
63458
  const elapsed = rowElapsedText(view, now);
63448
63459
  const rounds = t("panel.subagents.row.rounds", {
63449
63460
  count: String(view.rounds)
@@ -63654,7 +63665,7 @@ var init_subagents_viewer = __esm(() => {
63654
63665
  import { TextAttributes as TextAttributes12 } from "@opentui/core";
63655
63666
  function resolveVersion() {
63656
63667
  try {
63657
- return "0.23.0";
63668
+ return "0.23.1";
63658
63669
  } catch {
63659
63670
  return "dev";
63660
63671
  }
@@ -66169,7 +66180,11 @@ function bridgeAgentRunKey(runId, seq) {
66169
66180
  return `${runId}:${seq}`;
66170
66181
  }
66171
66182
  function bridgeSettledStatus(outcome) {
66172
- return outcome === "failed" || outcome === "cancelled" ? outcome : "completed";
66183
+ if (outcome === "failed" || outcome === "cancelled")
66184
+ return outcome;
66185
+ if (outcome === "aborted")
66186
+ return "interrupted";
66187
+ return "completed";
66173
66188
  }
66174
66189
  function bridgeSettleChild(existing, outcome, startedAt, now) {
66175
66190
  return {
@@ -66364,6 +66379,29 @@ function bridgeChildJournalMeta(rows) {
66364
66379
  ...model !== undefined ? { model } : {}
66365
66380
  };
66366
66381
  }
66382
+ function bridgeChildStopReason(rows) {
66383
+ for (let i = rows.length - 1;i >= 0; i -= 1) {
66384
+ const row = rows[i];
66385
+ if (row.type !== "user/message")
66386
+ continue;
66387
+ const source = asRecord5(asRecord5(row.payload).source);
66388
+ if (source.kind !== BRIDGE_SUBAGENT_SETTLED)
66389
+ continue;
66390
+ const reason = source.stopReason;
66391
+ if (typeof reason === "string" && reason !== "")
66392
+ return reason;
66393
+ }
66394
+ for (let i = rows.length - 1;i >= 0; i -= 1) {
66395
+ const row = rows[i];
66396
+ if (row.type !== "turn/end")
66397
+ continue;
66398
+ const reason = asRecord5(asRecord5(row.payload).reason);
66399
+ const kind = reason.kind;
66400
+ if (typeof kind === "string" && kind !== "")
66401
+ return kind;
66402
+ }
66403
+ return;
66404
+ }
66367
66405
  function bridgeChildJournalKey(view) {
66368
66406
  return `${view.id}@${view.startedAt ?? ""}`;
66369
66407
  }
@@ -66512,11 +66550,15 @@ class BridgeSessionSeam {
66512
66550
  #subagentJournalMeta = new Map;
66513
66551
  #sweepSettledRuns = new Map;
66514
66552
  #subagentSettleSnapshots = new Map;
66553
+ #interruptInFlight = new Map;
66554
+ #interruptGeneration = 0;
66555
+ #confirmClock;
66515
66556
  #connection = "disconnected";
66516
66557
  #turn = "idle";
66517
66558
  #bridgeLink = "ready";
66518
66559
  #sessionAttached = false;
66519
66560
  #currentSessionId;
66561
+ #bridgeCapabilities = new Set;
66520
66562
  #lastAppliedSeq;
66521
66563
  #lastAppliedSessionId;
66522
66564
  #appliedReplayKeys = new Set;
@@ -66550,17 +66592,37 @@ class BridgeSessionSeam {
66550
66592
  this.#ctx = options.ctx;
66551
66593
  this.#onDead = options.onDead;
66552
66594
  this.#onPermissionUnavailable = options.onPermissionUnavailable;
66595
+ this.#confirmClock = options.confirmClock ?? {
66596
+ sleep: (ms) => new Promise((resolve) => {
66597
+ const timer = setTimeout(resolve, ms);
66598
+ timer.unref?.();
66599
+ }),
66600
+ now: () => Date.now()
66601
+ };
66553
66602
  this.#unsubEvent = this.#transport.onEvent((frame) => this.#onBridgeEvent(frame));
66554
66603
  }
66555
66604
  async connect() {
66556
66605
  try {
66557
- await this.#transport.request("bridge.ping");
66606
+ const reply = asRecord5(await this.#transport.request("bridge.ping"));
66607
+ this.#recordBridgeCapabilities(reply.capabilities);
66558
66608
  this.#connection = "connected";
66559
66609
  } catch (err) {
66560
66610
  this.#connection = "disconnected";
66561
66611
  this.#ctx.logger.warn("[bridge-seam] bridge.ping failed, status connection=disconnected: %s", err);
66562
66612
  }
66563
66613
  }
66614
+ #recordBridgeCapabilities(value) {
66615
+ this.#bridgeCapabilities.clear();
66616
+ if (!Array.isArray(value))
66617
+ return;
66618
+ for (const entry of value) {
66619
+ if (typeof entry === "string" && entry !== "")
66620
+ this.#bridgeCapabilities.add(entry);
66621
+ }
66622
+ }
66623
+ hasBridgeCapability(name) {
66624
+ return this.#bridgeCapabilities.has(name);
66625
+ }
66564
66626
  status() {
66565
66627
  if (this.#connection === "disconnected") {
66566
66628
  this.#degradeOnce("status", "no handshake/status frame; returning disconnected/idle");
@@ -67027,6 +67089,108 @@ class BridgeSessionSeam {
67027
67089
  subagentViews() {
67028
67090
  return [...this.#subagentViews.values()].map((view) => ({ ...view }));
67029
67091
  }
67092
+ async interruptChild(childId) {
67093
+ const parentSessionId = this.#currentSessionId;
67094
+ if (parentSessionId === undefined || parentSessionId === "") {
67095
+ throw new BridgeProtocolError("NO_SESSION", "cannot interrupt a subagent: no session is bound to this bridge connection", { childId });
67096
+ }
67097
+ const generation = ++this.#interruptGeneration;
67098
+ const sessionAtStart = this.#subagentSessionId;
67099
+ this.#interruptInFlight.set(childId, generation);
67100
+ let value;
67101
+ try {
67102
+ value = asRecord5(await this.#transport.request("subagents.interrupt", { parentSessionId, childId }));
67103
+ } catch (err) {
67104
+ if (this.#interruptInFlight.get(childId) === generation)
67105
+ this.#interruptInFlight.delete(childId);
67106
+ throw err;
67107
+ }
67108
+ const disposition = value.disposition;
67109
+ if (disposition === "cancel-issued") {
67110
+ this.#confirmChildStop(childId, generation, sessionAtStart);
67111
+ return;
67112
+ }
67113
+ if (disposition === "already-settled") {
67114
+ if (this.#interruptInFlight.get(childId) === generation)
67115
+ this.#interruptInFlight.delete(childId);
67116
+ return;
67117
+ }
67118
+ if (this.#interruptInFlight.get(childId) === generation)
67119
+ this.#interruptInFlight.delete(childId);
67120
+ const detail = value.detail;
67121
+ throw new BridgeProtocolError("INTERRUPT_FAILED", `bridge failed to interrupt subagent ${childId}${typeof disposition === "string" ? ` (${disposition})` : ""}`, { childId, disposition, ...detail !== undefined ? { detail } : {} });
67122
+ }
67123
+ async stopChildren() {
67124
+ const parentSessionId = this.#currentSessionId;
67125
+ if (parentSessionId === undefined || parentSessionId === "") {
67126
+ throw new BridgeProtocolError("NO_SESSION", "cannot stop children: no session is bound to this bridge connection");
67127
+ }
67128
+ const value = asRecord5(await this.#transport.request("subagents.stopChildren", { parentSessionId }));
67129
+ const children = value.children;
67130
+ if (!Array.isArray(children))
67131
+ return [];
67132
+ const sessionAtStart = this.#subagentSessionId;
67133
+ const rows = children.map((row) => {
67134
+ const r = asRecord5(row);
67135
+ return {
67136
+ childId: typeof r.childId === "string" ? r.childId : "",
67137
+ disposition: typeof r.disposition === "string" ? r.disposition : "failed"
67138
+ };
67139
+ });
67140
+ for (const row of rows) {
67141
+ if (row.disposition !== "cancel-issued" || row.childId === "")
67142
+ continue;
67143
+ const generation = ++this.#interruptGeneration;
67144
+ this.#interruptInFlight.set(row.childId, generation);
67145
+ this.#confirmChildStop(row.childId, generation, sessionAtStart);
67146
+ }
67147
+ return rows;
67148
+ }
67149
+ async#confirmChildStop(childId, generation, sessionAtStart) {
67150
+ const clock = this.#confirmClock;
67151
+ const deadlineAt = clock.now() + CONFIRM_TIMEOUT_MS;
67152
+ let delayMs = CONFIRM_POLL_INITIAL_MS;
67153
+ try {
67154
+ for (;; ) {
67155
+ await clock.sleep(delayMs);
67156
+ if (this.#disposed || this.#subagentSessionId !== sessionAtStart || this.#interruptInFlight.get(childId) !== generation)
67157
+ return;
67158
+ let stopped = false;
67159
+ try {
67160
+ const items = asRecord5(await this.#transport.request("session.list", { _request: {} })).items;
67161
+ if (Array.isArray(items)) {
67162
+ stopped = items.some((row) => {
67163
+ const item = asRecord5(row);
67164
+ return item.sessionId === childId && item.running === false;
67165
+ });
67166
+ }
67167
+ } catch {}
67168
+ if (this.#disposed || this.#subagentSessionId !== sessionAtStart || this.#interruptInFlight.get(childId) !== generation)
67169
+ return;
67170
+ if (stopped) {
67171
+ let reason = "aborted";
67172
+ try {
67173
+ const rows = asRecord5(await this.#transport.request("journal.replay", { sessionId: childId })).rows;
67174
+ if (Array.isArray(rows)) {
67175
+ const clean = rows.filter((row) => row !== null && typeof row === "object" && !Array.isArray(row));
67176
+ reason = bridgeChildStopReason(clean) ?? "aborted";
67177
+ }
67178
+ } catch {}
67179
+ if (this.#disposed || this.#subagentSessionId !== sessionAtStart || this.#interruptInFlight.get(childId) !== generation)
67180
+ return;
67181
+ this.#settleChildFromHost(childId, reason, clock.now());
67182
+ return;
67183
+ }
67184
+ if (clock.now() >= deadlineAt) {
67185
+ if (this.#interruptInFlight.get(childId) === generation)
67186
+ this.#interruptInFlight.delete(childId);
67187
+ this.#ctx.logger.debug?.("[bridge-seam] subagent stop confirm timed out (child=%s, generation=%d, after=%dms); " + "clearing in-flight marker for turn sweep", childId, generation, CONFIRM_TIMEOUT_MS);
67188
+ return;
67189
+ }
67190
+ delayMs = Math.min(CONFIRM_POLL_MAX_MS, delayMs * 2);
67191
+ }
67192
+ } catch {}
67193
+ }
67030
67194
  #freezeSettles(before) {
67031
67195
  for (const [childId, startedAt] of before) {
67032
67196
  const view = this.#subagentViews.get(childId);
@@ -67079,19 +67243,30 @@ class BridgeSessionSeam {
67079
67243
  const now = Date.now();
67080
67244
  let changed = false;
67081
67245
  for (const childId of toSettle) {
67082
- const existing = this.#subagentViews.get(childId);
67083
- if (existing !== undefined)
67084
- this.#sweepSettledRuns.set(childId, bridgeChildJournalKey(existing));
67085
- if (this.#foldWithFrozenSettle("user/message", {
67086
- source: { kind: BRIDGE_SUBAGENT_SETTLED, stopReason: "completed", senderSessionId: childId }
67087
- }, now, false))
67246
+ if (this.#interruptInFlight.has(childId))
67247
+ continue;
67248
+ if (this.#settleChildFromHost(childId, "completed", now, false))
67088
67249
  changed = true;
67089
67250
  }
67090
67251
  if (changed) {
67091
- this.#syncSubagentMeta(false);
67092
67252
  this.#emitSubagentViews();
67093
67253
  }
67094
67254
  }
67255
+ #settleChildFromHost(childId, stopReason, now = Date.now(), emit = true) {
67256
+ const existing = this.#subagentViews.get(childId);
67257
+ if (existing !== undefined)
67258
+ this.#sweepSettledRuns.set(childId, bridgeChildJournalKey(existing));
67259
+ const changed = this.#foldWithFrozenSettle("user/message", {
67260
+ source: { kind: BRIDGE_SUBAGENT_SETTLED, stopReason, senderSessionId: childId }
67261
+ }, now, false);
67262
+ if (changed) {
67263
+ this.#syncSubagentMeta(false);
67264
+ if (emit)
67265
+ this.#emitSubagentViews();
67266
+ }
67267
+ this.#interruptInFlight.delete(childId);
67268
+ return changed;
67269
+ }
67095
67270
  async#ensureChildJournal(childId, startedAt) {
67096
67271
  const key = `${childId}@${startedAt ?? ""}`;
67097
67272
  if (this.#subagentJournalLoaded.has(key))
@@ -67212,7 +67387,9 @@ class BridgeSessionSeam {
67212
67387
  const now = Date.now();
67213
67388
  let changed = false;
67214
67389
  if (frame.type === "agent.spawn") {
67215
- changed = this.#foldWithFrozenSettle(BRIDGE_AGENT_START, payload, now, true);
67390
+ const runId = typeof payload.runId === "string" ? payload.runId : "";
67391
+ const childId = typeof payload.childId === "string" ? payload.childId : "";
67392
+ changed = runId === `${BRIDGE_CATALOG_RUN_PREFIX}${childId}` ? this.#foldWithFrozenSettle(BRIDGE_SUBAGENT_CATALOG, payload, now, true) : this.#foldWithFrozenSettle(BRIDGE_AGENT_START, payload, now, true);
67216
67393
  } else if (frame.type === "agent.settle") {
67217
67394
  changed = this.#foldWithFrozenSettle(BRIDGE_AGENT_END, payload, now, true);
67218
67395
  }
@@ -67231,6 +67408,8 @@ class BridgeSessionSeam {
67231
67408
  this.#subagentJournalMeta.clear();
67232
67409
  this.#sweepSettledRuns.clear();
67233
67410
  this.#subagentSettleSnapshots.clear();
67411
+ this.#interruptInFlight.clear();
67412
+ this.#interruptGeneration += 1;
67234
67413
  this.#subagentSessionId = sessionId;
67235
67414
  rosterReset = true;
67236
67415
  }
@@ -67378,6 +67557,9 @@ class BridgeSessionSeam {
67378
67557
  this.#subagentJournalMeta.clear();
67379
67558
  this.#sweepSettledRuns.clear();
67380
67559
  this.#subagentSettleSnapshots.clear();
67560
+ this.#interruptInFlight.clear();
67561
+ this.#interruptGeneration = 0;
67562
+ this.#bridgeCapabilities.clear();
67381
67563
  this.#activeCallbacks = undefined;
67382
67564
  this.#cancelAllAsks();
67383
67565
  this.#bufferedPendingSnapshot = undefined;
@@ -67712,7 +67894,7 @@ class BridgeSessionSeam {
67712
67894
  }
67713
67895
  }
67714
67896
  }
67715
- var BridgeProtocolError, BRIDGE_AGENT_START = "tool-workflow/agent-start", BRIDGE_AGENT_END = "tool-workflow/agent-end", BRIDGE_SUBAGENT_CATALOG = "subagent/catalog", BRIDGE_SUBAGENT_SETTLED = "subagent-settled", BRIDGE_CATALOG_RUN_PREFIX = "catalog:", fmtTokens = (n) => n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`;
67897
+ var BridgeProtocolError, BRIDGE_AGENT_START = "tool-workflow/agent-start", BRIDGE_AGENT_END = "tool-workflow/agent-end", BRIDGE_SUBAGENT_CATALOG = "subagent/catalog", BRIDGE_SUBAGENT_SETTLED = "subagent-settled", BRIDGE_CATALOG_RUN_PREFIX = "catalog:", CONFIRM_POLL_INITIAL_MS = 250, CONFIRM_POLL_MAX_MS = 1000, CONFIRM_TIMEOUT_MS = 45000, fmtTokens = (n) => n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`;
67716
67898
  var init_bridge_session_seam = __esm(() => {
67717
67899
  init_remote_session_ops();
67718
67900
  init_session_seam_adapter();
@@ -69471,5 +69653,5 @@ export {
69471
69653
  themeNameFromConfig
69472
69654
  };
69473
69655
 
69474
- //# debugId=CF96FD408007020364756E2164756E21
69656
+ //# debugId=E9FE1903EEBDE04F64756E2164756E21
69475
69657
  //# sourceMappingURL=index.js.map