@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.
@@ -45692,16 +45692,11 @@ var SESSIONS_MIN_BYTES = 1024, SESSIONS_DIR_CAP = 32;
45692
45692
  function parseLaunchArgs(argv) {
45693
45693
  let newRequested = false;
45694
45694
  let resumeLastRequested = false;
45695
- let remoteRequested = false;
45696
45695
  let sessionId;
45697
45696
  for (let index = 0;index < argv.length; index++) {
45698
45697
  const arg = argv[index];
45699
45698
  if (arg === undefined)
45700
45699
  continue;
45701
- if (arg === "--remote") {
45702
- remoteRequested = true;
45703
- continue;
45704
- }
45705
45700
  if (arg === "--new") {
45706
45701
  newRequested = true;
45707
45702
  continue;
@@ -45727,8 +45722,7 @@ function parseLaunchArgs(argv) {
45727
45722
  return {
45728
45723
  newRequested,
45729
45724
  resumeLastRequested,
45730
- ...sessionId !== undefined ? { sessionId } : {},
45731
- ...remoteRequested ? { remoteRequested: true } : {}
45725
+ ...sessionId !== undefined ? { sessionId } : {}
45732
45726
  };
45733
45727
  }
45734
45728
  function readAutoResumeMode(config) {
@@ -52229,6 +52223,17 @@ async function stopEverything(seam) {
52229
52223
  const parent = turn !== undefined && turn !== "idle";
52230
52224
  if (parent)
52231
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
+ }
52232
52237
  let children = 0;
52233
52238
  for (const view of seam.subagentViews?.() ?? []) {
52234
52239
  if (view.status !== "running" || !seam.interruptChild)
@@ -63107,7 +63112,7 @@ function viewerRows(views) {
63107
63112
  return [...running, ...settled];
63108
63113
  }
63109
63114
  function viewerRowText(view, roundCap, elapsedText) {
63110
- 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";
63111
63116
  const stop = subagentHardStopGlyph(view);
63112
63117
  const label = `${stop ? `${stop} ` : ""}${titlecase(view.label)}`;
63113
63118
  const suffix = subagentMarkerSuffix(view);
@@ -63449,7 +63454,7 @@ function SubagentsViewer(props) {
63449
63454
  function headerText(view, now) {
63450
63455
  if (view === undefined)
63451
63456
  return t("panel.subagents.header.fallback");
63452
- 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");
63453
63458
  const elapsed = rowElapsedText(view, now);
63454
63459
  const rounds = t("panel.subagents.row.rounds", {
63455
63460
  count: String(view.rounds)
@@ -63660,7 +63665,7 @@ var init_subagents_viewer = __esm(() => {
63660
63665
  import { TextAttributes as TextAttributes12 } from "@opentui/core";
63661
63666
  function resolveVersion() {
63662
63667
  try {
63663
- return "0.22.0";
63668
+ return "0.23.1";
63664
63669
  } catch {
63665
63670
  return "dev";
63666
63671
  }
@@ -66175,7 +66180,11 @@ function bridgeAgentRunKey(runId, seq) {
66175
66180
  return `${runId}:${seq}`;
66176
66181
  }
66177
66182
  function bridgeSettledStatus(outcome) {
66178
- 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";
66179
66188
  }
66180
66189
  function bridgeSettleChild(existing, outcome, startedAt, now) {
66181
66190
  return {
@@ -66284,6 +66293,122 @@ function bridgeFoldAgentRecord(children, runSeq, liveStarts, type, data, now, li
66284
66293
  }
66285
66294
  return false;
66286
66295
  }
66296
+ function bridgeSweepSettledChildIds(rows, parentId, locallyRunning) {
66297
+ if (parentId === undefined || parentId === "")
66298
+ return [];
66299
+ const settled = [];
66300
+ for (const raw of rows) {
66301
+ const row = asRecord5(raw);
66302
+ if (row.origin !== "subagent")
66303
+ continue;
66304
+ if (row.parentSessionId !== parentId)
66305
+ continue;
66306
+ const id = row.sessionId;
66307
+ if (typeof id !== "string" || id === "")
66308
+ continue;
66309
+ if (row.running !== false)
66310
+ continue;
66311
+ if (!locallyRunning.has(id) || settled.includes(id))
66312
+ continue;
66313
+ settled.push(id);
66314
+ }
66315
+ return settled;
66316
+ }
66317
+ function bridgeBlocksText(content) {
66318
+ if (typeof content === "string")
66319
+ return content.trim();
66320
+ if (!Array.isArray(content))
66321
+ return "";
66322
+ let text = "";
66323
+ for (const block of content) {
66324
+ const typed = block;
66325
+ if (typed?.type === "text" && typeof typed.text === "string") {
66326
+ text += (text === "" ? "" : `
66327
+ `) + typed.text;
66328
+ }
66329
+ }
66330
+ return text.trim();
66331
+ }
66332
+ function bridgeLastContentLine(text) {
66333
+ if (text === undefined)
66334
+ return;
66335
+ const lines = text.replace(/\r\n?/g, `
66336
+ `).split(`
66337
+ `);
66338
+ for (let i = lines.length - 1;i >= 0; i--) {
66339
+ const line = lines[i].trim();
66340
+ if (line !== "")
66341
+ return line.replace(/\s+/gu, " ").slice(0, 240);
66342
+ }
66343
+ return;
66344
+ }
66345
+ function bridgeChildJournalMeta(rows) {
66346
+ let rounds = 0;
66347
+ let lastLine;
66348
+ let contextModel;
66349
+ let descriptorModel;
66350
+ for (const row of rows) {
66351
+ const data = asRecord5(row.payload);
66352
+ if (row.type === "assistant/message") {
66353
+ rounds += 1;
66354
+ const message = asRecord5(data.message);
66355
+ const tail = bridgeLastContentLine(bridgeBlocksText(message.content ?? data.content));
66356
+ if (tail !== undefined)
66357
+ lastLine = tail;
66358
+ } else if (row.type === "tool/result") {
66359
+ if (data.isError !== true) {
66360
+ const message = asRecord5(data.message);
66361
+ const tail = bridgeLastContentLine(bridgeBlocksText(message.content ?? data.content));
66362
+ if (tail !== undefined)
66363
+ lastLine = tail;
66364
+ }
66365
+ } else if (row.type === "request/context") {
66366
+ if (contextModel === undefined && typeof data.model === "string" && data.model !== "") {
66367
+ contextModel = data.model;
66368
+ }
66369
+ } else if (row.type === "subagent/descriptor") {
66370
+ if (descriptorModel === undefined && typeof data.agentModel === "string" && data.agentModel !== "") {
66371
+ descriptorModel = data.agentModel;
66372
+ }
66373
+ }
66374
+ }
66375
+ const model = contextModel ?? descriptorModel;
66376
+ return {
66377
+ rounds,
66378
+ ...lastLine !== undefined ? { lastLine } : {},
66379
+ ...model !== undefined ? { model } : {}
66380
+ };
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
+ }
66405
+ function bridgeChildJournalKey(view) {
66406
+ return `${view.id}@${view.startedAt ?? ""}`;
66407
+ }
66408
+ function bridgeRestoreSettled(view, snap) {
66409
+ const { startedAt: _startedAt, ...rest } = view;
66410
+ return { ...rest, status: snap.status, elapsedSec: snap.elapsedSec, endedAt: snap.endedAt };
66411
+ }
66287
66412
  function lastJournalTurnTerminal(rows, startOutsideWindow = false) {
66288
66413
  if (startOutsideWindow) {
66289
66414
  let nextStart = Infinity;
@@ -66421,11 +66546,19 @@ class BridgeSessionSeam {
66421
66546
  #subagentLiveStarts = new Set;
66422
66547
  #subagentListeners = new Set;
66423
66548
  #subagentSessionId;
66549
+ #subagentJournalLoaded = new Set;
66550
+ #subagentJournalMeta = new Map;
66551
+ #sweepSettledRuns = new Map;
66552
+ #subagentSettleSnapshots = new Map;
66553
+ #interruptInFlight = new Map;
66554
+ #interruptGeneration = 0;
66555
+ #confirmClock;
66424
66556
  #connection = "disconnected";
66425
66557
  #turn = "idle";
66426
66558
  #bridgeLink = "ready";
66427
66559
  #sessionAttached = false;
66428
66560
  #currentSessionId;
66561
+ #bridgeCapabilities = new Set;
66429
66562
  #lastAppliedSeq;
66430
66563
  #lastAppliedSessionId;
66431
66564
  #appliedReplayKeys = new Set;
@@ -66459,17 +66592,37 @@ class BridgeSessionSeam {
66459
66592
  this.#ctx = options.ctx;
66460
66593
  this.#onDead = options.onDead;
66461
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
+ };
66462
66602
  this.#unsubEvent = this.#transport.onEvent((frame) => this.#onBridgeEvent(frame));
66463
66603
  }
66464
66604
  async connect() {
66465
66605
  try {
66466
- await this.#transport.request("bridge.ping");
66606
+ const reply = asRecord5(await this.#transport.request("bridge.ping"));
66607
+ this.#recordBridgeCapabilities(reply.capabilities);
66467
66608
  this.#connection = "connected";
66468
66609
  } catch (err) {
66469
66610
  this.#connection = "disconnected";
66470
66611
  this.#ctx.logger.warn("[bridge-seam] bridge.ping failed, status connection=disconnected: %s", err);
66471
66612
  }
66472
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
+ }
66473
66626
  status() {
66474
66627
  if (this.#connection === "disconnected") {
66475
66628
  this.#degradeOnce("status", "no handshake/status frame; returning disconnected/idle");
@@ -66595,6 +66748,7 @@ class BridgeSessionSeam {
66595
66748
  this.#ctx.logger.warn("[bridge-seam] recovery replay from=%d is ahead of journal max=%d; clamped to %d", from, Math.max(0, drained.cursor - 1), drained.cursor);
66596
66749
  }
66597
66750
  this.#foldAgentReplayRows(drained.rows, boundId);
66751
+ await this.#sweepSubagents(boundId);
66598
66752
  const rows = bridgeReplayRowsToSeamTranscript(drained.rows);
66599
66753
  if (drained.rows.length > 0) {
66600
66754
  const maxSeq = drained.rows.reduce((m, row) => Math.max(m, row.seq), -Infinity);
@@ -66935,6 +67089,279 @@ class BridgeSessionSeam {
66935
67089
  subagentViews() {
66936
67090
  return [...this.#subagentViews.values()].map((view) => ({ ...view }));
66937
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
+ }
67194
+ #freezeSettles(before) {
67195
+ for (const [childId, startedAt] of before) {
67196
+ const view = this.#subagentViews.get(childId);
67197
+ if (view === undefined || view.status === "running")
67198
+ continue;
67199
+ if (view.elapsedSec === undefined || view.endedAt === undefined)
67200
+ continue;
67201
+ const runKey = `${childId}@${startedAt ?? ""}`;
67202
+ const frozen = this.#subagentSettleSnapshots.get(runKey);
67203
+ if (frozen !== undefined) {
67204
+ this.#subagentViews.set(childId, bridgeRestoreSettled(view, frozen));
67205
+ } else {
67206
+ this.#subagentSettleSnapshots.set(runKey, {
67207
+ status: view.status,
67208
+ elapsedSec: view.elapsedSec,
67209
+ endedAt: view.endedAt
67210
+ });
67211
+ }
67212
+ }
67213
+ }
67214
+ #foldWithFrozenSettle(type, data, now, live) {
67215
+ const before = new Map;
67216
+ for (const [id, v] of this.#subagentViews) {
67217
+ if (v.status === "running")
67218
+ before.set(id, v.startedAt);
67219
+ }
67220
+ const changed = bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, type, data, now, live);
67221
+ if (changed)
67222
+ this.#freezeSettles(before);
67223
+ return changed;
67224
+ }
67225
+ async#sweepSubagents(parentId) {
67226
+ let value;
67227
+ try {
67228
+ value = await this.#transport.request("session.list", { _request: {} });
67229
+ } catch {
67230
+ return;
67231
+ }
67232
+ const items = asRecord5(value).items;
67233
+ if (!Array.isArray(items))
67234
+ return;
67235
+ const locallyRunning = new Set;
67236
+ for (const view of this.#subagentViews.values()) {
67237
+ if (view.status === "running")
67238
+ locallyRunning.add(view.id);
67239
+ }
67240
+ const toSettle = bridgeSweepSettledChildIds(items, parentId, locallyRunning);
67241
+ if (toSettle.length === 0)
67242
+ return;
67243
+ const now = Date.now();
67244
+ let changed = false;
67245
+ for (const childId of toSettle) {
67246
+ if (this.#interruptInFlight.has(childId))
67247
+ continue;
67248
+ if (this.#settleChildFromHost(childId, "completed", now, false))
67249
+ changed = true;
67250
+ }
67251
+ if (changed) {
67252
+ this.#emitSubagentViews();
67253
+ }
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
+ }
67270
+ async#ensureChildJournal(childId, startedAt) {
67271
+ const key = `${childId}@${startedAt ?? ""}`;
67272
+ if (this.#subagentJournalLoaded.has(key))
67273
+ return;
67274
+ this.#subagentJournalLoaded.add(key);
67275
+ const sessionAtStart = this.#subagentSessionId;
67276
+ try {
67277
+ const value = asRecord5(await this.#transport.request("journal.replay", { sessionId: childId }));
67278
+ const rows = value.rows;
67279
+ if (!Array.isArray(rows))
67280
+ return;
67281
+ const cleanRows = rows.filter((row) => row !== null && typeof row === "object" && !Array.isArray(row));
67282
+ const meta = bridgeChildJournalMeta(cleanRows);
67283
+ if (this.#subagentSessionId !== sessionAtStart || this.#disposed)
67284
+ return;
67285
+ this.#subagentJournalMeta.set(key, meta);
67286
+ const existing = this.#subagentViews.get(childId);
67287
+ if (existing === undefined || bridgeChildJournalKey(existing) !== key)
67288
+ return;
67289
+ this.#subagentViews.set(childId, {
67290
+ ...existing,
67291
+ rounds: meta.rounds,
67292
+ ...meta.lastLine !== undefined ? { lastLine: meta.lastLine } : {},
67293
+ ...meta.model !== undefined ? { model: meta.model } : {}
67294
+ });
67295
+ this.#emitSubagentViews();
67296
+ } catch {}
67297
+ }
67298
+ #syncSubagentMeta(emit = true) {
67299
+ let changed = false;
67300
+ if (this.#sweepSettledRuns.size > 0) {
67301
+ for (const view of [...this.#subagentViews.values()]) {
67302
+ if (view.status !== "running")
67303
+ continue;
67304
+ const recordedKey = this.#sweepSettledRuns.get(view.id);
67305
+ if (recordedKey === undefined)
67306
+ continue;
67307
+ const key = bridgeChildJournalKey(view);
67308
+ if (key !== recordedKey) {
67309
+ this.#degradeOnce("sweep-sticky-run-key-mismatch", `sweep settle run key ${recordedKey} != replay key ${key} for ${view.id}`);
67310
+ continue;
67311
+ }
67312
+ const frozen = this.#subagentSettleSnapshots.get(recordedKey);
67313
+ if (frozen !== undefined) {
67314
+ this.#subagentViews.set(view.id, bridgeRestoreSettled(view, frozen));
67315
+ changed = true;
67316
+ } else {
67317
+ if (this.#foldWithFrozenSettle("user/message", {
67318
+ source: { kind: BRIDGE_SUBAGENT_SETTLED, stopReason: "completed", senderSessionId: view.id }
67319
+ }, Date.now(), false))
67320
+ changed = true;
67321
+ }
67322
+ }
67323
+ }
67324
+ for (const view of [...this.#subagentViews.values()]) {
67325
+ const key = bridgeChildJournalKey(view);
67326
+ const exactMeta = this.#subagentJournalMeta.get(key);
67327
+ const meta = exactMeta ?? (key === `${view.id}@` ? this.#priorRunMeta(view.id) : undefined);
67328
+ if (meta !== undefined) {
67329
+ const restored = {
67330
+ ...view,
67331
+ rounds: meta.rounds,
67332
+ ...meta.lastLine !== undefined ? { lastLine: meta.lastLine } : {},
67333
+ ...meta.model !== undefined ? { model: meta.model } : {}
67334
+ };
67335
+ if (restored.rounds !== view.rounds || restored.lastLine !== view.lastLine || restored.model !== view.model) {
67336
+ this.#subagentViews.set(view.id, restored);
67337
+ changed = true;
67338
+ }
67339
+ }
67340
+ if (exactMeta === undefined && !this.#subagentJournalLoaded.has(key)) {
67341
+ this.#ensureChildJournal(view.id, view.startedAt);
67342
+ }
67343
+ }
67344
+ if (changed && emit)
67345
+ this.#emitSubagentViews();
67346
+ }
67347
+ #priorRunMeta(childId) {
67348
+ const prefix = `${childId}@`;
67349
+ let best;
67350
+ let bestStart = -Infinity;
67351
+ for (const [key, meta] of this.#subagentJournalMeta) {
67352
+ if (!key.startsWith(prefix))
67353
+ continue;
67354
+ const suffix = key.slice(prefix.length);
67355
+ if (suffix === "")
67356
+ continue;
67357
+ const start = Number(suffix);
67358
+ if (Number.isFinite(start) && start > bestStart) {
67359
+ bestStart = start;
67360
+ best = meta;
67361
+ }
67362
+ }
67363
+ return best;
67364
+ }
66938
67365
  onSubagentViews(listener) {
66939
67366
  this.#subagentListeners.add(listener);
66940
67367
  listener(this.subagentViews());
@@ -66960,12 +67387,16 @@ class BridgeSessionSeam {
66960
67387
  const now = Date.now();
66961
67388
  let changed = false;
66962
67389
  if (frame.type === "agent.spawn") {
66963
- changed = bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, 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);
66964
67393
  } else if (frame.type === "agent.settle") {
66965
- changed = bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, BRIDGE_AGENT_END, payload, now, true);
67394
+ changed = this.#foldWithFrozenSettle(BRIDGE_AGENT_END, payload, now, true);
66966
67395
  }
66967
- if (changed)
67396
+ if (changed) {
67397
+ this.#syncSubagentMeta(false);
66968
67398
  this.#emitSubagentViews();
67399
+ }
66969
67400
  }
66970
67401
  #foldAgentReplayRows(rows, sessionId) {
66971
67402
  let rosterReset = false;
@@ -66973,17 +67404,25 @@ class BridgeSessionSeam {
66973
67404
  this.#subagentViews.clear();
66974
67405
  this.#subagentRunSeq.clear();
66975
67406
  this.#subagentLiveStarts.clear();
67407
+ this.#subagentJournalLoaded.clear();
67408
+ this.#subagentJournalMeta.clear();
67409
+ this.#sweepSettledRuns.clear();
67410
+ this.#subagentSettleSnapshots.clear();
67411
+ this.#interruptInFlight.clear();
67412
+ this.#interruptGeneration += 1;
66976
67413
  this.#subagentSessionId = sessionId;
66977
67414
  rosterReset = true;
66978
67415
  }
66979
67416
  let changed = false;
66980
67417
  const now = Date.now();
66981
67418
  for (const row of rows) {
66982
- if (bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, row.type, asRecord5(row.payload), now, false))
67419
+ if (this.#foldWithFrozenSettle(row.type, asRecord5(row.payload), now, false))
66983
67420
  changed = true;
66984
67421
  }
66985
- if (rosterReset || changed)
67422
+ if (rosterReset || changed) {
67423
+ this.#syncSubagentMeta(false);
66986
67424
  this.#emitSubagentViews();
67425
+ }
66987
67426
  }
66988
67427
  configLoad() {
66989
67428
  this.#degradeOnce("configLoad", "no config frame on the in-process bridge; returning {} (no stored override)");
@@ -67017,6 +67456,7 @@ class BridgeSessionSeam {
67017
67456
  const value = await this.#transport.request("journal.replay", { sessionId: id });
67018
67457
  const rows = Array.isArray(asRecord5(value).rows) ? asRecord5(value).rows : [];
67019
67458
  this.#foldAgentReplayRows(rows, id);
67459
+ this.#sweepSubagents(id);
67020
67460
  return bridgeReplayRowsToSeamTranscript(rows, skip);
67021
67461
  }
67022
67462
  async currentModelSelection() {
@@ -67113,6 +67553,13 @@ class BridgeSessionSeam {
67113
67553
  this.#subagentViews.clear();
67114
67554
  this.#subagentRunSeq.clear();
67115
67555
  this.#subagentLiveStarts.clear();
67556
+ this.#subagentJournalLoaded.clear();
67557
+ this.#subagentJournalMeta.clear();
67558
+ this.#sweepSettledRuns.clear();
67559
+ this.#subagentSettleSnapshots.clear();
67560
+ this.#interruptInFlight.clear();
67561
+ this.#interruptGeneration = 0;
67562
+ this.#bridgeCapabilities.clear();
67116
67563
  this.#activeCallbacks = undefined;
67117
67564
  this.#cancelAllAsks();
67118
67565
  this.#bufferedPendingSnapshot = undefined;
@@ -67380,6 +67827,9 @@ class BridgeSessionSeam {
67380
67827
  if (endedTurnId !== undefined)
67381
67828
  this.#cancelAsksForTurn(endedTurnId);
67382
67829
  this.#turnDone?.();
67830
+ if (this.#currentSessionId !== undefined && this.#currentSessionId !== "") {
67831
+ this.#sweepSubagents(this.#currentSessionId);
67832
+ }
67383
67833
  }
67384
67834
  if (frame.type === "turn.end") {
67385
67835
  const usage = parseUsage(payload.usage);
@@ -67444,7 +67894,7 @@ class BridgeSessionSeam {
67444
67894
  }
67445
67895
  }
67446
67896
  }
67447
- 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}`;
67448
67898
  var init_bridge_session_seam = __esm(() => {
67449
67899
  init_remote_session_ops();
67450
67900
  init_session_seam_adapter();
@@ -67467,9 +67917,10 @@ function formatBridgeFailFastMessage(diagnosis, repairCommand = BRIDGE_REPAIR_CO
67467
67917
  return [diagnosis, `Fix: ${repairCommand}`, BRIDGE_APPEND_PRESET_NOTICE].join(`
67468
67918
  `);
67469
67919
  }
67470
- var BRIDGE_REPAIR_COMMAND = "dsh-opentui --repair-bridge", BRIDGE_APPEND_PRESET_NOTICE = "inproc bridge mode injects append-system via the bridge section; presets are standard only.", BRIDGE_REPAIR_HINT;
67920
+ var BRIDGE_REPAIR_COMMAND = "dsh-opentui --repair-bridge", BRIDGE_APPEND_PRESET_NOTICE = "inproc bridge mode injects append-system via the bridge section; presets are standard only.", BRIDGE_LEGACY_REMOTE_HINT = "To keep the legacy remote thin client for this launch: DSH_OPENTUI_INPROC=0", BRIDGE_REPAIR_HINT;
67471
67921
  var init_bridge_failfast_text = __esm(() => {
67472
- BRIDGE_REPAIR_HINT = `Run \`${BRIDGE_REPAIR_COMMAND}\` to rebuild the bridge symlink / manifest (it fixes links, not corrupted artifact contents).`;
67922
+ BRIDGE_REPAIR_HINT = `Run \`${BRIDGE_REPAIR_COMMAND}\` to rebuild the bridge symlink / manifest (it fixes links, not corrupted artifact contents).
67923
+ ${BRIDGE_LEGACY_REMOTE_HINT}`;
67473
67924
  });
67474
67925
 
67475
67926
  // scripts/lib/host-compat.mjs
@@ -67554,12 +68005,10 @@ __export(exports_seam_bootstrap, {
67554
68005
  verifyRecoveryHandshake: () => verifyRecoveryHandshake
67555
68006
  });
67556
68007
  function selectSeamKind(input) {
67557
- if (input.remote)
67558
- return "remote";
67559
68008
  return input.inproc ? "bridge" : "remote";
67560
68009
  }
67561
68010
  function isInprocMode(env = process.env) {
67562
- return env.DSH_OPENTUI_INPROC === "1";
68011
+ return env.DSH_OPENTUI_INPROC !== "0";
67563
68012
  }
67564
68013
  function formatBridgeBootstrapMessage(options) {
67565
68014
  return formatBridgeFailFastMessage(`dsh-opentui inproc bridge seam failed [${options.code}]: ${options.diagnosis}`, options.repairCommand ?? BRIDGE_REPAIR_COMMAND);
@@ -68469,8 +68918,7 @@ async function bootClientV2(options = {}) {
68469
68918
  }
68470
68919
  const launchArgs = parseLaunchArgs(options.argv ?? process.argv.slice(2));
68471
68920
  const seamKind = seamBootstrap.selectSeamKind({
68472
- inproc: seamBootstrap.isInprocMode(),
68473
- remote: launchArgs.remoteRequested === true
68921
+ inproc: seamBootstrap.isInprocMode()
68474
68922
  });
68475
68923
  const seam = await seamBootstrap.createSessionSeam({
68476
68924
  kind: seamKind,
@@ -68478,7 +68926,7 @@ async function bootClientV2(options = {}) {
68478
68926
  if (options.bridgeTransport === undefined) {
68479
68927
  throw new seamBootstrap.BridgeBootstrapError({
68480
68928
  code: "BRIDGE_TRANSPORT_MISSING",
68481
- diagnosis: "inproc mode is on (DSH_OPENTUI_INPROC=1) but no bridge transport was injected at the synthetic root"
68929
+ diagnosis: "bridge seam is selected (DSH_OPENTUI_INPROC is not 0) but no bridge transport was injected at the synthetic root"
68482
68930
  });
68483
68931
  }
68484
68932
  return seamBootstrap.createBridgeSessionSeam({
@@ -69176,7 +69624,7 @@ async function main() {
69176
69624
  const mod = await Promise.resolve().then(() => (init_v2_entry(), {}));
69177
69625
  const argv = process.argv.slice(2);
69178
69626
  let bootOptions = { argv };
69179
- if (process.env.DSH_OPENTUI_INPROC === "1" && !argv.includes("--remote")) {
69627
+ if (process.env.DSH_OPENTUI_INPROC !== "0") {
69180
69628
  const bridgeMod = await Promise.resolve().then(() => (init_bridge_transport(), {}));
69181
69629
  bootOptions = {
69182
69630
  ...bootOptions,
@@ -69205,5 +69653,5 @@ export {
69205
69653
  themeNameFromConfig
69206
69654
  };
69207
69655
 
69208
- //# debugId=A1DE0F5F067B3B7E64756E2164756E21
69656
+ //# debugId=E9FE1903EEBDE04F64756E2164756E21
69209
69657
  //# sourceMappingURL=index.js.map