@aiwayds/dsh-opentui 0.23.0 → 0.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,55 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.23.2] - 2026-11-20
9
+
10
+ ### Changed
11
+
12
+ - **Transcript block types now carry distinct theme hues.** Fenced code
13
+ blocks in assistant messages paint their streaming left rule and final
14
+ frame in the theme's code hue (`markdown.code` walked two ramp steps
15
+ deeper via `increase` — green.400 on the default theme), the user `❯`
16
+ box paints its border in the theme's interactive hue at the 400 step,
17
+ and the think block's left accent bars paint in the accent hue two ramp
18
+ steps deeper — the same family the widgets dock's think lines already
19
+ use. All three stay border-tier, low-saturation accents on dark themes;
20
+ body text colors are unchanged.
21
+ - **The last-request echo line reads as user content.** The composer
22
+ footer's last submitted prompt now prefixes with the `👤` user icon
23
+ (footer-emoji family, a deliberate departure from tui-pi's `●`) and
24
+ paints at `text.base` instead of `text.muted`. The `👤` glyph is
25
+ double-width; the line's clip budget already measures it through the
26
+ grapheme-aware `stringWidth`, so no layout math changed.
27
+
28
+ ## [0.23.1] - 2026-11-20
29
+
30
+ ### Changed
31
+
32
+ - **"Stop everything" now really interrupts in-bridge subagents.** Pressing Esc
33
+ twice and confirming "Stop everything?" makes the host interrupt its child
34
+ subagents at once, without waiting for the parent turn to reach a boundary;
35
+ their rows flip to the ⊘ aborted state within ~2s. Answering "no" at the
36
+ confirm leaves every child running untouched. The interrupt also reaches
37
+ children the client roster never showed (live-spawned / hidden subagents),
38
+ and is scoped by session ownership: a TUI can only stop the subagents of its
39
+ own session, never another session's. The model-side `rounds` / `model`
40
+ information on those rows is preserved.
41
+
42
+ ### Fixed
43
+
44
+ - **Running subagents are visible the moment they spawn.** In 0.23.0 a live
45
+ child was absent from the ctrl+g panel (and shift+k reported "no running
46
+ subagents") until the next turn boundary drained the journal. Live spawn now
47
+ enters the catalog immediately. Root cause: catalog-family spawn frames were
48
+ being silently dropped by the anti-collision guard.
49
+
50
+ ### Internal
51
+
52
+ - Bridge: added a `subagent-index` (session → sub-agents mapping) and
53
+ `subagents.interrupt` / `subagents.stopChildren` methods gated on session
54
+ ownership at both entrances; converged the stop path into a shell
55
+ confirm-then-emit flow; added the ⊘ state and i18n strings to tui-base.
56
+
8
57
  ## [0.23.0] - 2026-11-19
9
58
 
10
59
  ### 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;