@aiwayds/dsh-opentui 0.22.0 → 0.23.0

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) {
@@ -63660,7 +63654,7 @@ var init_subagents_viewer = __esm(() => {
63660
63654
  import { TextAttributes as TextAttributes12 } from "@opentui/core";
63661
63655
  function resolveVersion() {
63662
63656
  try {
63663
- return "0.22.0";
63657
+ return "0.23.0";
63664
63658
  } catch {
63665
63659
  return "dev";
63666
63660
  }
@@ -66284,6 +66278,99 @@ function bridgeFoldAgentRecord(children, runSeq, liveStarts, type, data, now, li
66284
66278
  }
66285
66279
  return false;
66286
66280
  }
66281
+ function bridgeSweepSettledChildIds(rows, parentId, locallyRunning) {
66282
+ if (parentId === undefined || parentId === "")
66283
+ return [];
66284
+ const settled = [];
66285
+ for (const raw of rows) {
66286
+ const row = asRecord5(raw);
66287
+ if (row.origin !== "subagent")
66288
+ continue;
66289
+ if (row.parentSessionId !== parentId)
66290
+ continue;
66291
+ const id = row.sessionId;
66292
+ if (typeof id !== "string" || id === "")
66293
+ continue;
66294
+ if (row.running !== false)
66295
+ continue;
66296
+ if (!locallyRunning.has(id) || settled.includes(id))
66297
+ continue;
66298
+ settled.push(id);
66299
+ }
66300
+ return settled;
66301
+ }
66302
+ function bridgeBlocksText(content) {
66303
+ if (typeof content === "string")
66304
+ return content.trim();
66305
+ if (!Array.isArray(content))
66306
+ return "";
66307
+ let text = "";
66308
+ for (const block of content) {
66309
+ const typed = block;
66310
+ if (typed?.type === "text" && typeof typed.text === "string") {
66311
+ text += (text === "" ? "" : `
66312
+ `) + typed.text;
66313
+ }
66314
+ }
66315
+ return text.trim();
66316
+ }
66317
+ function bridgeLastContentLine(text) {
66318
+ if (text === undefined)
66319
+ return;
66320
+ const lines = text.replace(/\r\n?/g, `
66321
+ `).split(`
66322
+ `);
66323
+ for (let i = lines.length - 1;i >= 0; i--) {
66324
+ const line = lines[i].trim();
66325
+ if (line !== "")
66326
+ return line.replace(/\s+/gu, " ").slice(0, 240);
66327
+ }
66328
+ return;
66329
+ }
66330
+ function bridgeChildJournalMeta(rows) {
66331
+ let rounds = 0;
66332
+ let lastLine;
66333
+ let contextModel;
66334
+ let descriptorModel;
66335
+ for (const row of rows) {
66336
+ const data = asRecord5(row.payload);
66337
+ if (row.type === "assistant/message") {
66338
+ rounds += 1;
66339
+ const message = asRecord5(data.message);
66340
+ const tail = bridgeLastContentLine(bridgeBlocksText(message.content ?? data.content));
66341
+ if (tail !== undefined)
66342
+ lastLine = tail;
66343
+ } else if (row.type === "tool/result") {
66344
+ if (data.isError !== true) {
66345
+ const message = asRecord5(data.message);
66346
+ const tail = bridgeLastContentLine(bridgeBlocksText(message.content ?? data.content));
66347
+ if (tail !== undefined)
66348
+ lastLine = tail;
66349
+ }
66350
+ } else if (row.type === "request/context") {
66351
+ if (contextModel === undefined && typeof data.model === "string" && data.model !== "") {
66352
+ contextModel = data.model;
66353
+ }
66354
+ } else if (row.type === "subagent/descriptor") {
66355
+ if (descriptorModel === undefined && typeof data.agentModel === "string" && data.agentModel !== "") {
66356
+ descriptorModel = data.agentModel;
66357
+ }
66358
+ }
66359
+ }
66360
+ const model = contextModel ?? descriptorModel;
66361
+ return {
66362
+ rounds,
66363
+ ...lastLine !== undefined ? { lastLine } : {},
66364
+ ...model !== undefined ? { model } : {}
66365
+ };
66366
+ }
66367
+ function bridgeChildJournalKey(view) {
66368
+ return `${view.id}@${view.startedAt ?? ""}`;
66369
+ }
66370
+ function bridgeRestoreSettled(view, snap) {
66371
+ const { startedAt: _startedAt, ...rest } = view;
66372
+ return { ...rest, status: snap.status, elapsedSec: snap.elapsedSec, endedAt: snap.endedAt };
66373
+ }
66287
66374
  function lastJournalTurnTerminal(rows, startOutsideWindow = false) {
66288
66375
  if (startOutsideWindow) {
66289
66376
  let nextStart = Infinity;
@@ -66421,6 +66508,10 @@ class BridgeSessionSeam {
66421
66508
  #subagentLiveStarts = new Set;
66422
66509
  #subagentListeners = new Set;
66423
66510
  #subagentSessionId;
66511
+ #subagentJournalLoaded = new Set;
66512
+ #subagentJournalMeta = new Map;
66513
+ #sweepSettledRuns = new Map;
66514
+ #subagentSettleSnapshots = new Map;
66424
66515
  #connection = "disconnected";
66425
66516
  #turn = "idle";
66426
66517
  #bridgeLink = "ready";
@@ -66595,6 +66686,7 @@ class BridgeSessionSeam {
66595
66686
  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
66687
  }
66597
66688
  this.#foldAgentReplayRows(drained.rows, boundId);
66689
+ await this.#sweepSubagents(boundId);
66598
66690
  const rows = bridgeReplayRowsToSeamTranscript(drained.rows);
66599
66691
  if (drained.rows.length > 0) {
66600
66692
  const maxSeq = drained.rows.reduce((m, row) => Math.max(m, row.seq), -Infinity);
@@ -66935,6 +67027,166 @@ class BridgeSessionSeam {
66935
67027
  subagentViews() {
66936
67028
  return [...this.#subagentViews.values()].map((view) => ({ ...view }));
66937
67029
  }
67030
+ #freezeSettles(before) {
67031
+ for (const [childId, startedAt] of before) {
67032
+ const view = this.#subagentViews.get(childId);
67033
+ if (view === undefined || view.status === "running")
67034
+ continue;
67035
+ if (view.elapsedSec === undefined || view.endedAt === undefined)
67036
+ continue;
67037
+ const runKey = `${childId}@${startedAt ?? ""}`;
67038
+ const frozen = this.#subagentSettleSnapshots.get(runKey);
67039
+ if (frozen !== undefined) {
67040
+ this.#subagentViews.set(childId, bridgeRestoreSettled(view, frozen));
67041
+ } else {
67042
+ this.#subagentSettleSnapshots.set(runKey, {
67043
+ status: view.status,
67044
+ elapsedSec: view.elapsedSec,
67045
+ endedAt: view.endedAt
67046
+ });
67047
+ }
67048
+ }
67049
+ }
67050
+ #foldWithFrozenSettle(type, data, now, live) {
67051
+ const before = new Map;
67052
+ for (const [id, v] of this.#subagentViews) {
67053
+ if (v.status === "running")
67054
+ before.set(id, v.startedAt);
67055
+ }
67056
+ const changed = bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, type, data, now, live);
67057
+ if (changed)
67058
+ this.#freezeSettles(before);
67059
+ return changed;
67060
+ }
67061
+ async#sweepSubagents(parentId) {
67062
+ let value;
67063
+ try {
67064
+ value = await this.#transport.request("session.list", { _request: {} });
67065
+ } catch {
67066
+ return;
67067
+ }
67068
+ const items = asRecord5(value).items;
67069
+ if (!Array.isArray(items))
67070
+ return;
67071
+ const locallyRunning = new Set;
67072
+ for (const view of this.#subagentViews.values()) {
67073
+ if (view.status === "running")
67074
+ locallyRunning.add(view.id);
67075
+ }
67076
+ const toSettle = bridgeSweepSettledChildIds(items, parentId, locallyRunning);
67077
+ if (toSettle.length === 0)
67078
+ return;
67079
+ const now = Date.now();
67080
+ let changed = false;
67081
+ 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))
67088
+ changed = true;
67089
+ }
67090
+ if (changed) {
67091
+ this.#syncSubagentMeta(false);
67092
+ this.#emitSubagentViews();
67093
+ }
67094
+ }
67095
+ async#ensureChildJournal(childId, startedAt) {
67096
+ const key = `${childId}@${startedAt ?? ""}`;
67097
+ if (this.#subagentJournalLoaded.has(key))
67098
+ return;
67099
+ this.#subagentJournalLoaded.add(key);
67100
+ const sessionAtStart = this.#subagentSessionId;
67101
+ try {
67102
+ const value = asRecord5(await this.#transport.request("journal.replay", { sessionId: childId }));
67103
+ const rows = value.rows;
67104
+ if (!Array.isArray(rows))
67105
+ return;
67106
+ const cleanRows = rows.filter((row) => row !== null && typeof row === "object" && !Array.isArray(row));
67107
+ const meta = bridgeChildJournalMeta(cleanRows);
67108
+ if (this.#subagentSessionId !== sessionAtStart || this.#disposed)
67109
+ return;
67110
+ this.#subagentJournalMeta.set(key, meta);
67111
+ const existing = this.#subagentViews.get(childId);
67112
+ if (existing === undefined || bridgeChildJournalKey(existing) !== key)
67113
+ return;
67114
+ this.#subagentViews.set(childId, {
67115
+ ...existing,
67116
+ rounds: meta.rounds,
67117
+ ...meta.lastLine !== undefined ? { lastLine: meta.lastLine } : {},
67118
+ ...meta.model !== undefined ? { model: meta.model } : {}
67119
+ });
67120
+ this.#emitSubagentViews();
67121
+ } catch {}
67122
+ }
67123
+ #syncSubagentMeta(emit = true) {
67124
+ let changed = false;
67125
+ if (this.#sweepSettledRuns.size > 0) {
67126
+ for (const view of [...this.#subagentViews.values()]) {
67127
+ if (view.status !== "running")
67128
+ continue;
67129
+ const recordedKey = this.#sweepSettledRuns.get(view.id);
67130
+ if (recordedKey === undefined)
67131
+ continue;
67132
+ const key = bridgeChildJournalKey(view);
67133
+ if (key !== recordedKey) {
67134
+ this.#degradeOnce("sweep-sticky-run-key-mismatch", `sweep settle run key ${recordedKey} != replay key ${key} for ${view.id}`);
67135
+ continue;
67136
+ }
67137
+ const frozen = this.#subagentSettleSnapshots.get(recordedKey);
67138
+ if (frozen !== undefined) {
67139
+ this.#subagentViews.set(view.id, bridgeRestoreSettled(view, frozen));
67140
+ changed = true;
67141
+ } else {
67142
+ if (this.#foldWithFrozenSettle("user/message", {
67143
+ source: { kind: BRIDGE_SUBAGENT_SETTLED, stopReason: "completed", senderSessionId: view.id }
67144
+ }, Date.now(), false))
67145
+ changed = true;
67146
+ }
67147
+ }
67148
+ }
67149
+ for (const view of [...this.#subagentViews.values()]) {
67150
+ const key = bridgeChildJournalKey(view);
67151
+ const exactMeta = this.#subagentJournalMeta.get(key);
67152
+ const meta = exactMeta ?? (key === `${view.id}@` ? this.#priorRunMeta(view.id) : undefined);
67153
+ if (meta !== undefined) {
67154
+ const restored = {
67155
+ ...view,
67156
+ rounds: meta.rounds,
67157
+ ...meta.lastLine !== undefined ? { lastLine: meta.lastLine } : {},
67158
+ ...meta.model !== undefined ? { model: meta.model } : {}
67159
+ };
67160
+ if (restored.rounds !== view.rounds || restored.lastLine !== view.lastLine || restored.model !== view.model) {
67161
+ this.#subagentViews.set(view.id, restored);
67162
+ changed = true;
67163
+ }
67164
+ }
67165
+ if (exactMeta === undefined && !this.#subagentJournalLoaded.has(key)) {
67166
+ this.#ensureChildJournal(view.id, view.startedAt);
67167
+ }
67168
+ }
67169
+ if (changed && emit)
67170
+ this.#emitSubagentViews();
67171
+ }
67172
+ #priorRunMeta(childId) {
67173
+ const prefix = `${childId}@`;
67174
+ let best;
67175
+ let bestStart = -Infinity;
67176
+ for (const [key, meta] of this.#subagentJournalMeta) {
67177
+ if (!key.startsWith(prefix))
67178
+ continue;
67179
+ const suffix = key.slice(prefix.length);
67180
+ if (suffix === "")
67181
+ continue;
67182
+ const start = Number(suffix);
67183
+ if (Number.isFinite(start) && start > bestStart) {
67184
+ bestStart = start;
67185
+ best = meta;
67186
+ }
67187
+ }
67188
+ return best;
67189
+ }
66938
67190
  onSubagentViews(listener) {
66939
67191
  this.#subagentListeners.add(listener);
66940
67192
  listener(this.subagentViews());
@@ -66960,12 +67212,14 @@ class BridgeSessionSeam {
66960
67212
  const now = Date.now();
66961
67213
  let changed = false;
66962
67214
  if (frame.type === "agent.spawn") {
66963
- changed = bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, BRIDGE_AGENT_START, payload, now, true);
67215
+ changed = this.#foldWithFrozenSettle(BRIDGE_AGENT_START, payload, now, true);
66964
67216
  } else if (frame.type === "agent.settle") {
66965
- changed = bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, BRIDGE_AGENT_END, payload, now, true);
67217
+ changed = this.#foldWithFrozenSettle(BRIDGE_AGENT_END, payload, now, true);
66966
67218
  }
66967
- if (changed)
67219
+ if (changed) {
67220
+ this.#syncSubagentMeta(false);
66968
67221
  this.#emitSubagentViews();
67222
+ }
66969
67223
  }
66970
67224
  #foldAgentReplayRows(rows, sessionId) {
66971
67225
  let rosterReset = false;
@@ -66973,17 +67227,23 @@ class BridgeSessionSeam {
66973
67227
  this.#subagentViews.clear();
66974
67228
  this.#subagentRunSeq.clear();
66975
67229
  this.#subagentLiveStarts.clear();
67230
+ this.#subagentJournalLoaded.clear();
67231
+ this.#subagentJournalMeta.clear();
67232
+ this.#sweepSettledRuns.clear();
67233
+ this.#subagentSettleSnapshots.clear();
66976
67234
  this.#subagentSessionId = sessionId;
66977
67235
  rosterReset = true;
66978
67236
  }
66979
67237
  let changed = false;
66980
67238
  const now = Date.now();
66981
67239
  for (const row of rows) {
66982
- if (bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, row.type, asRecord5(row.payload), now, false))
67240
+ if (this.#foldWithFrozenSettle(row.type, asRecord5(row.payload), now, false))
66983
67241
  changed = true;
66984
67242
  }
66985
- if (rosterReset || changed)
67243
+ if (rosterReset || changed) {
67244
+ this.#syncSubagentMeta(false);
66986
67245
  this.#emitSubagentViews();
67246
+ }
66987
67247
  }
66988
67248
  configLoad() {
66989
67249
  this.#degradeOnce("configLoad", "no config frame on the in-process bridge; returning {} (no stored override)");
@@ -67017,6 +67277,7 @@ class BridgeSessionSeam {
67017
67277
  const value = await this.#transport.request("journal.replay", { sessionId: id });
67018
67278
  const rows = Array.isArray(asRecord5(value).rows) ? asRecord5(value).rows : [];
67019
67279
  this.#foldAgentReplayRows(rows, id);
67280
+ this.#sweepSubagents(id);
67020
67281
  return bridgeReplayRowsToSeamTranscript(rows, skip);
67021
67282
  }
67022
67283
  async currentModelSelection() {
@@ -67113,6 +67374,10 @@ class BridgeSessionSeam {
67113
67374
  this.#subagentViews.clear();
67114
67375
  this.#subagentRunSeq.clear();
67115
67376
  this.#subagentLiveStarts.clear();
67377
+ this.#subagentJournalLoaded.clear();
67378
+ this.#subagentJournalMeta.clear();
67379
+ this.#sweepSettledRuns.clear();
67380
+ this.#subagentSettleSnapshots.clear();
67116
67381
  this.#activeCallbacks = undefined;
67117
67382
  this.#cancelAllAsks();
67118
67383
  this.#bufferedPendingSnapshot = undefined;
@@ -67380,6 +67645,9 @@ class BridgeSessionSeam {
67380
67645
  if (endedTurnId !== undefined)
67381
67646
  this.#cancelAsksForTurn(endedTurnId);
67382
67647
  this.#turnDone?.();
67648
+ if (this.#currentSessionId !== undefined && this.#currentSessionId !== "") {
67649
+ this.#sweepSubagents(this.#currentSessionId);
67650
+ }
67383
67651
  }
67384
67652
  if (frame.type === "turn.end") {
67385
67653
  const usage = parseUsage(payload.usage);
@@ -67467,9 +67735,10 @@ function formatBridgeFailFastMessage(diagnosis, repairCommand = BRIDGE_REPAIR_CO
67467
67735
  return [diagnosis, `Fix: ${repairCommand}`, BRIDGE_APPEND_PRESET_NOTICE].join(`
67468
67736
  `);
67469
67737
  }
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;
67738
+ 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
67739
  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).`;
67740
+ BRIDGE_REPAIR_HINT = `Run \`${BRIDGE_REPAIR_COMMAND}\` to rebuild the bridge symlink / manifest (it fixes links, not corrupted artifact contents).
67741
+ ${BRIDGE_LEGACY_REMOTE_HINT}`;
67473
67742
  });
67474
67743
 
67475
67744
  // scripts/lib/host-compat.mjs
@@ -67554,12 +67823,10 @@ __export(exports_seam_bootstrap, {
67554
67823
  verifyRecoveryHandshake: () => verifyRecoveryHandshake
67555
67824
  });
67556
67825
  function selectSeamKind(input) {
67557
- if (input.remote)
67558
- return "remote";
67559
67826
  return input.inproc ? "bridge" : "remote";
67560
67827
  }
67561
67828
  function isInprocMode(env = process.env) {
67562
- return env.DSH_OPENTUI_INPROC === "1";
67829
+ return env.DSH_OPENTUI_INPROC !== "0";
67563
67830
  }
67564
67831
  function formatBridgeBootstrapMessage(options) {
67565
67832
  return formatBridgeFailFastMessage(`dsh-opentui inproc bridge seam failed [${options.code}]: ${options.diagnosis}`, options.repairCommand ?? BRIDGE_REPAIR_COMMAND);
@@ -68469,8 +68736,7 @@ async function bootClientV2(options = {}) {
68469
68736
  }
68470
68737
  const launchArgs = parseLaunchArgs(options.argv ?? process.argv.slice(2));
68471
68738
  const seamKind = seamBootstrap.selectSeamKind({
68472
- inproc: seamBootstrap.isInprocMode(),
68473
- remote: launchArgs.remoteRequested === true
68739
+ inproc: seamBootstrap.isInprocMode()
68474
68740
  });
68475
68741
  const seam = await seamBootstrap.createSessionSeam({
68476
68742
  kind: seamKind,
@@ -68478,7 +68744,7 @@ async function bootClientV2(options = {}) {
68478
68744
  if (options.bridgeTransport === undefined) {
68479
68745
  throw new seamBootstrap.BridgeBootstrapError({
68480
68746
  code: "BRIDGE_TRANSPORT_MISSING",
68481
- diagnosis: "inproc mode is on (DSH_OPENTUI_INPROC=1) but no bridge transport was injected at the synthetic root"
68747
+ diagnosis: "bridge seam is selected (DSH_OPENTUI_INPROC is not 0) but no bridge transport was injected at the synthetic root"
68482
68748
  });
68483
68749
  }
68484
68750
  return seamBootstrap.createBridgeSessionSeam({
@@ -69176,7 +69442,7 @@ async function main() {
69176
69442
  const mod = await Promise.resolve().then(() => (init_v2_entry(), {}));
69177
69443
  const argv = process.argv.slice(2);
69178
69444
  let bootOptions = { argv };
69179
- if (process.env.DSH_OPENTUI_INPROC === "1" && !argv.includes("--remote")) {
69445
+ if (process.env.DSH_OPENTUI_INPROC !== "0") {
69180
69446
  const bridgeMod = await Promise.resolve().then(() => (init_bridge_transport(), {}));
69181
69447
  bootOptions = {
69182
69448
  ...bootOptions,
@@ -69205,5 +69471,5 @@ export {
69205
69471
  themeNameFromConfig
69206
69472
  };
69207
69473
 
69208
- //# debugId=A1DE0F5F067B3B7E64756E2164756E21
69474
+ //# debugId=CF96FD408007020364756E2164756E21
69209
69475
  //# sourceMappingURL=index.js.map