@linxin666/dsh-remote-bridge 0.4.11 → 0.4.12

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/lib/index.js CHANGED
@@ -1140,7 +1140,7 @@ const CODE_COMMANDS_UNAVAILABLE = "commands-unavailable";
1140
1140
  * it is a fact about this bridge, not about what a particular host mounts — and
1141
1141
  * only a call that needs the domain fails. A refusal the `dsh-agents` plugin
1142
1142
  * itself raised crosses with the plugin's own code instead (`team-not-found`,
1143
- * `member-not-found`, `preset-unknown`, `workspace-required` and their
1143
+ * `member-not-found`, `preset-unknown`, `workspace-unavailable` and their
1144
1144
  * neighbours).
1145
1145
  */
1146
1146
  const CODE_SQUADS_UNAVAILABLE = "squads-unavailable";
@@ -5820,7 +5820,7 @@ var BridgeConnection = class {
5820
5820
  if (sessionId === void 0) return refusal(CODE_INVALID_ARGS, "session.snapshot requires sessionId");
5821
5821
  const unfollowable = await this.#unfollowable(sessionId);
5822
5822
  if (unfollowable !== void 0) return refusal(CODE_SESSION_NOT_FOLLOWABLE, unfollowable);
5823
- const opening = await this.#awaitOpening(this.#ensureSubscription(sessionId));
5823
+ const opening = await this.#openingForBaseline(sessionId);
5824
5824
  if (!opening.ok) return refusal(opening.code, `session ${sessionId} produced no opening frame (${opening.msg})`);
5825
5825
  const window = turnsOfRecords(opening.baseline.records);
5826
5826
  const projection = this.#trimmedFor(window);
@@ -5945,7 +5945,7 @@ var BridgeConnection = class {
5945
5945
  if (!budget.ok) return budget;
5946
5946
  const unfollowable = await this.#unfollowable(sessionId);
5947
5947
  if (unfollowable !== void 0) return refusal(CODE_SESSION_NOT_FOLLOWABLE, unfollowable);
5948
- const opening = await this.#awaitOpening(this.#ensureSubscription(sessionId));
5948
+ const opening = await this.#openingForBaseline(sessionId);
5949
5949
  if (!opening.ok) return refusal(opening.code, `session ${sessionId} produced no opening frame (${opening.msg})`);
5950
5950
  const page = pageTurns(this.#projectionOf(opening.baseline.records), before, budget.maxBytes, (turns, nextBefore, hasMore) => Buffer.byteLength(JSON.stringify(responseFrame(id, {
5951
5951
  turns,
@@ -6094,6 +6094,7 @@ var BridgeConnection = class {
6094
6094
  ok: true,
6095
6095
  r: { accepted: true }
6096
6096
  };
6097
+ this.#options.turnEndQuiet?.notePhonePrompt(sessionId);
6097
6098
  this.#ensureSubscription(sessionId);
6098
6099
  const timeZone = this.#options.clientTimeZone();
6099
6100
  const call = await this.#unary("session", "prompt", {
@@ -6915,6 +6916,7 @@ var BridgeConnection = class {
6915
6916
  sessionId,
6916
6917
  controller: new AbortController(),
6917
6918
  address: this.#addressOf(sessionId),
6919
+ advanced: false,
6918
6920
  opened: Promise.resolve({
6919
6921
  ok: false,
6920
6922
  code: CODE_SNAPSHOT_UNAVAILABLE,
@@ -7062,6 +7064,7 @@ var BridgeConnection = class {
7062
7064
  for (;;) {
7063
7065
  const next = await iterator.next();
7064
7066
  if (next.done === true) return;
7067
+ subscription.advanced = true;
7065
7068
  const delta = deltaOfFollowFrame(next.value, this.#toolCalls, this.#messages, memory);
7066
7069
  if (delta === void 0) continue;
7067
7070
  this.#emit(TOPIC_SESSION_DELTA, {
@@ -7094,6 +7097,27 @@ var BridgeConnection = class {
7094
7097
  this.#options.push?.notify(pushEventOfTurnEnd(reason), sessionId);
7095
7098
  this.#options.liveActivity?.noteTurnEnd(sessionId, reason);
7096
7099
  }
7100
+ /**
7101
+ * The opening frame a baseline read is answered from.
7102
+ *
7103
+ * A subscription that has delivered nothing since its opening frame still
7104
+ * holds the window that frame opened, so it is awaited and reused: a session
7105
+ * asked about while it stays silent costs one stream however often it is read.
7106
+ * One that HAS delivered a frame since has moved past that window, and reusing
7107
+ * it would answer a session that ran a turn on this very stream with the empty
7108
+ * baseline of the moment before that turn. Such a subscription is dropped —
7109
+ * its drain aborted and itself forgotten — and a fresh stream answers with the
7110
+ * window the harness opens now, which is the session as it is.
7111
+ * @param sessionId - the session whose baseline is wanted.
7112
+ * @returns that stream's opening frame, or why there is none.
7113
+ */
7114
+ async #openingForBaseline(sessionId) {
7115
+ const subscription = this.#ensureSubscription(sessionId);
7116
+ if (!subscription.advanced) return this.#awaitOpening(subscription);
7117
+ this.#forget(subscription);
7118
+ subscription.controller.abort();
7119
+ return this.#awaitOpening(this.#ensureSubscription(sessionId));
7120
+ }
7097
7121
  /** Await a subscription's opening frame under a bounded wait. */
7098
7122
  async #awaitOpening(subscription) {
7099
7123
  let timer;
@@ -8923,38 +8947,78 @@ function normalizeActivityRowName(title) {
8923
8947
  //#endregion
8924
8948
  //#region src/core/turn-end-quiet.ts
8925
8949
  /**
8926
- * When a finished turn may be announced: after the session it belongs to falls
8950
+ * When a finished turn may be announced: after the family it belongs to falls
8927
8951
  * quiet, not when the frame arrives.
8928
8952
  *
8929
8953
  * A `turn/end` increment is a fact about one turn and nothing more. The work the
8930
- * user started with it may still be going: the child sessions it delegated to and
8931
- * the background jobs the host still holds under those sessions outlive the turn
8932
- * that started them. A phone told "turn finished" at the frame wakes on a session
8933
- * the roster still badges as running, reads a card that says ended while the work
8934
- * goes on, and is told again by a second turn end it never asked for. §28's
8935
- * notification and §29's card answer the same question — "is this session working
8936
- * right now" — and that question has one answer, the one the client already
8937
- * computes in `SessionRun`: the host's own `agentRunning` for the session, any
8938
- * descendant session still running, and any job the host attributes to either.
8954
+ * user started with it may still be going: the subagent sessions the host spawned
8955
+ * under it at any depth, and the background jobs the host still holds under any of
8956
+ * them, outlive the turn that started them. A phone told "turn finished" at the
8957
+ * frame wakes on a roster that still badges a session running, reads a card that
8958
+ * says ended while the work goes on, and is told again by a second turn end it
8959
+ * never asked for. §28's notification and §29's card answer the same question — "is
8960
+ * this work still going" — and that question has one answer, the family's.
8939
8961
  *
8940
- * So a turn end is registered here instead of sent, and sent once the host says
8941
- * the session is quiet. Three rules hold that together:
8962
+ * The family is the root a session's parent chain climbs to, plus every session
8963
+ * under that root at any depth. A leaf session's own turn end therefore waits for
8964
+ * the root and for the siblings and cousins it shares that root with, which is the
8965
+ * work the user actually started. So a turn end is registered here instead of sent,
8966
+ * and sent once the host says the family is quiet. Three rules hold that together:
8942
8967
  *
8943
- * - the answer comes from the host and nowhere else: one `session/list` read for
8944
- * the running flag and the parent chain, and the host's job registry for the
8945
- * jobs it attributes to a session. This module invents no timer-based guess and
8946
- * reads no client state, because a guess that says "quiet" is a lock screen
8947
- * saying the work finished when it did not;
8968
+ * - the answer comes from the host and nowhere else: one `session/list` read for the
8969
+ * running flags, the parent chain and each session's origin, and the host's job
8970
+ * registry for the jobs it attributes to a session. This module invents no
8971
+ * timer-based guess and reads no client state, because a guess that says "quiet"
8972
+ * is a lock screen saying the work finished when it did not;
8948
8973
  * - nothing on the frame path waits: a registration stores five fields and arms a
8949
8974
  * timer, so a follow stream still publishes its increment at the speed it did
8950
8975
  * before;
8951
- * - the wait is bounded. At {@link TURN_END_QUIET_MAX_MS} the announcement goes
8952
- * out anyway and the line it logs names what was still going, because a
8953
- * notification that never arrives is the failure this channel exists to prevent.
8976
+ * - the wait has no deadline. A family that stays busy is never announced, and a
8977
+ * host that cannot answer is asked again rather than read as quiet: announcing
8978
+ * work that is still running is the failure this channel exists to prevent, and a
8979
+ * notification that never arrives is the lesser one. One question, though, is
8980
+ * bounded ({@link TURN_END_QUIET_PROBE_TIMEOUT_MS}): a read the gateway never
8981
+ * returns is abandoned as that question's own failure and the entry asks again, so
8982
+ * a stuck call cannot leave the entry holding no question to ask and no way to
8983
+ * speak. One line at {@link TURN_END_QUIET_REPORT_MS} says the bridge is still
8984
+ * waiting, so an operator is not left guessing why a phone stayed silent.
8985
+ *
8986
+ * Not every turn end is the phone's to hear. A session the host spawned as a
8987
+ * subagent (`origin: "subagent"`) ends turns nobody asked this bridge about, so its
8988
+ * turn end is dropped on its first answer unless the phone itself prompted that
8989
+ * session over the wire.
8954
8990
  * @module dsh-remote-bridge/core/turn-end-quiet
8955
8991
  */
8956
- /** Longest a registered turn end waits for its session to fall quiet, in milliseconds. */
8957
- const TURN_END_QUIET_MAX_MS = 6e5;
8992
+ /**
8993
+ * How long a held turn end waits before the bridge logs that it is still waiting,
8994
+ * in milliseconds.
8995
+ *
8996
+ * A progress line and never a send: the wait itself has no cap, because announcing a
8997
+ * turn while its family still works is exactly what this module exists to prevent.
8998
+ */
8999
+ const TURN_END_QUIET_REPORT_MS = 6e5;
9000
+ /**
9001
+ * How long one question to the host may stay unanswered before the bridge abandons
9002
+ * that question, in milliseconds.
9003
+ *
9004
+ * Three times {@link TURN_END_QUIET_INTERVAL_MS}. A `session/list` read the host is
9005
+ * willing to make comes back well inside one interval, so a question that outlives
9006
+ * three of them is a call that will not return — a stuck gateway request, not a slow
9007
+ * host — and an entry that keeps waiting for it has no next question to ask, which is
9008
+ * exactly how a phone goes permanently silent. The bound belongs to the question and
9009
+ * never to the turn end: an abandoned question answers nothing, the entry stays held,
9010
+ * and the next question leaves on the usual interval.
9011
+ */
9012
+ const TURN_END_QUIET_PROBE_TIMEOUT_MS = 15e3;
9013
+ /**
9014
+ * How many session ids the gate remembers the phone prompting, at most.
9015
+ *
9016
+ * The set exists to tell the phone's own subagent sessions from the ones it merely
9017
+ * watches, and a bridge that runs for weeks must not grow it without end: the oldest
9018
+ * id is dropped first, and a session dropped that way and prompted again enters as a
9019
+ * new one.
9020
+ */
9021
+ const TURN_END_PHONE_PROMPTED_MAX = 5e3;
8958
9022
  /**
8959
9023
  * The bridge's outbound turn-end path: registration now, announcement when quiet.
8960
9024
  *
@@ -8969,11 +9033,17 @@ var TurnEndQuietGate = class {
8969
9033
  #log;
8970
9034
  /** Held turn ends by session id; one session has one thing to announce. */
8971
9035
  #waiting = /* @__PURE__ */ new Map();
9036
+ /** The sessions the phone itself prompted, oldest first. */
9037
+ #phonePrompted = /* @__PURE__ */ new Set();
9038
+ #phonePromptLimit;
9039
+ /** The last question generation handed out, so no question is ever minted twice. */
9040
+ #asked = 0;
8972
9041
  #disposed = false;
8973
9042
  constructor(options) {
8974
9043
  this.#options = options;
8975
9044
  this.#now = options.now ?? (() => Date.now());
8976
9045
  this.#log = options.log ?? (() => void 0);
9046
+ this.#phonePromptLimit = Math.max(1, Math.min(options.phonePromptLimit ?? 5e3, TURN_END_PHONE_PROMPTED_MAX));
8977
9047
  }
8978
9048
  /** @returns whether either channel can send, which is the only case a turn end is held at all. */
8979
9049
  get enabled() {
@@ -8985,7 +9055,7 @@ var TurnEndQuietGate = class {
8985
9055
  return this.#waiting.size;
8986
9056
  }
8987
9057
  /**
8988
- * Hold one finished turn until its session is quiet, then announce it.
9058
+ * Hold one finished turn until its family is quiet, then announce it.
8989
9059
  *
8990
9060
  * Returns at once and never awaits a host read: the caller is a follow stream
8991
9061
  * that has already published its increment.
@@ -9001,6 +9071,25 @@ var TurnEndQuietGate = class {
9001
9071
  }
9002
9072
  }
9003
9073
  /**
9074
+ * Remember that the phone itself prompted one session.
9075
+ *
9076
+ * This is the one thing that makes a subagent session's turn end announceable: the
9077
+ * host spawns those on its own, and a phone that never asked that session anything
9078
+ * is not waiting to hear how its turn went. Bounded and first in, first out, so the
9079
+ * memory is the recent work rather than everything since the bridge started.
9080
+ * @param sessionId - the session a `session/prompt` frame carried.
9081
+ */
9082
+ notePhonePrompt(sessionId) {
9083
+ if (sessionId === "") return;
9084
+ if (this.#phonePrompted.has(sessionId)) return;
9085
+ this.#phonePrompted.add(sessionId);
9086
+ while (this.#phonePrompted.size > this.#phonePromptLimit) {
9087
+ const oldest = this.#phonePrompted.values().next().value;
9088
+ if (oldest === void 0) break;
9089
+ this.#phonePrompted.delete(oldest);
9090
+ }
9091
+ }
9092
+ /**
9004
9093
  * Drop a held turn end because another turn is on.
9005
9094
  *
9006
9095
  * A caller reports this from the evidence it actually has — an increment for the
@@ -9022,6 +9111,7 @@ var TurnEndQuietGate = class {
9022
9111
  this.#disposed = true;
9023
9112
  for (const waiting of [...this.#waiting.values()]) this.#forget(waiting);
9024
9113
  this.#waiting.clear();
9114
+ this.#phonePrompted.clear();
9025
9115
  }
9026
9116
  /** Store one registration, or fold it into the one already held for that session. */
9027
9117
  #register(sessionId, reason) {
@@ -9038,11 +9128,11 @@ var TurnEndQuietGate = class {
9038
9128
  event: pushEventOfTurnEnd(reason),
9039
9129
  reason,
9040
9130
  registeredAt: now,
9041
- deadline: now + Math.max(0, this.#options.maxWaitMs ?? 6e5),
9042
9131
  check: void 0,
9043
- expiry: void 0,
9132
+ report: void 0,
9133
+ deadline: void 0,
9044
9134
  busy: void 0,
9045
- asking: false
9135
+ asking: 0
9046
9136
  };
9047
9137
  this.#waiting.set(sessionId, waiting);
9048
9138
  if (this.#options.probe === void 0) {
@@ -9050,36 +9140,65 @@ var TurnEndQuietGate = class {
9050
9140
  return;
9051
9141
  }
9052
9142
  this.#log(`turn-end registered session=${sessionId} event=${waiting.event}`);
9053
- const expiry = setTimeout(() => {
9054
- waiting.expiry = void 0;
9055
- this.#deliver(waiting, waiting.busy ?? "unanswered");
9056
- }, Math.max(0, waiting.deadline - now));
9057
- expiry.unref?.();
9058
- waiting.expiry = expiry;
9143
+ const report = setTimeout(() => {
9144
+ waiting.report = void 0;
9145
+ this.#stillWaiting(waiting);
9146
+ }, Math.max(0, this.#options.reportAfterMs ?? 6e5));
9147
+ report.unref?.();
9148
+ waiting.report = report;
9059
9149
  this.#arm(waiting);
9060
9150
  }
9061
- /** Arm the next question to the host, unless the budget runs out first. */
9151
+ /** Arm the next question to the host. */
9062
9152
  #arm(waiting) {
9063
9153
  if (this.#disposed || this.#waiting.get(waiting.sessionId) !== waiting) return;
9064
- const remaining = waiting.deadline - this.#now();
9065
- if (remaining <= 0) return;
9066
- const interval = this.#options.intervalMs ?? 5e3;
9154
+ const interval = Math.max(1, this.#options.intervalMs ?? 5e3);
9067
9155
  const timer = setTimeout(() => {
9068
9156
  waiting.check = void 0;
9069
9157
  this.#check(waiting);
9070
- }, Math.max(0, Math.min(interval, remaining)));
9158
+ }, interval);
9071
9159
  timer.unref?.();
9072
9160
  waiting.check = timer;
9073
9161
  }
9074
- /** Ask the host once whether a held entry's session is quiet. */
9162
+ /**
9163
+ * Ask the host once whether a held entry's family is quiet.
9164
+ *
9165
+ * One question is out at a time, and every question carries its own bound: a read
9166
+ * the gateway never returns would otherwise leave the entry holding a question that
9167
+ * has no answer coming, with no next question armed behind it — the channel silenced
9168
+ * for as long as the entry is held. The bound ends that one question only; the entry
9169
+ * keeps waiting and the next question leaves on the usual interval.
9170
+ */
9075
9171
  #check(waiting) {
9076
9172
  if (this.#disposed || this.#waiting.get(waiting.sessionId) !== waiting) return;
9077
9173
  const probe = this.#options.probe;
9078
- if (probe === void 0 || waiting.asking) return;
9079
- waiting.asking = true;
9080
- Promise.resolve().then(async () => await probe(waiting.sessionId)).then((answer) => {
9081
- waiting.asking = false;
9174
+ if (probe === void 0 || waiting.asking !== 0) return;
9175
+ const generation = ++this.#asked;
9176
+ waiting.asking = generation;
9177
+ Promise.resolve().then(async () => {
9178
+ if (this.#disposed || this.#waiting.get(waiting.sessionId) !== waiting) return void 0;
9179
+ if (waiting.asking !== generation) return void 0;
9180
+ const deadline = setTimeout(() => {
9181
+ waiting.deadline = void 0;
9182
+ if (this.#disposed || this.#waiting.get(waiting.sessionId) !== waiting) return;
9183
+ if (waiting.asking !== generation) return;
9184
+ waiting.asking = 0;
9185
+ waiting.busy = "unreadable";
9186
+ this.#log(`turn-end quiet check unreadable session=${waiting.sessionId} after=${TURN_END_QUIET_PROBE_TIMEOUT_MS}ms`);
9187
+ this.#arm(waiting);
9188
+ }, TURN_END_QUIET_PROBE_TIMEOUT_MS);
9189
+ deadline.unref?.();
9190
+ waiting.deadline = deadline;
9191
+ return await probe(waiting.sessionId);
9192
+ }).then((answer) => {
9193
+ if (answer === void 0 || waiting.asking !== generation) return;
9194
+ waiting.asking = 0;
9195
+ this.#dropDeadline(waiting);
9082
9196
  if (this.#disposed || this.#waiting.get(waiting.sessionId) !== waiting) return;
9197
+ if (answer.subagent === true && !this.#phonePrompted.has(waiting.sessionId)) {
9198
+ this.#forget(waiting);
9199
+ this.#log(`turn-end dropped session=${waiting.sessionId} reason=subagent-not-prompted`);
9200
+ return;
9201
+ }
9083
9202
  if (answer.quiet) {
9084
9203
  this.#deliver(waiting);
9085
9204
  return;
@@ -9087,26 +9206,41 @@ var TurnEndQuietGate = class {
9087
9206
  waiting.busy = answer.busy ?? "unstated";
9088
9207
  this.#arm(waiting);
9089
9208
  }).catch((error) => {
9090
- waiting.asking = false;
9209
+ if (waiting.asking !== generation) return;
9210
+ waiting.asking = 0;
9211
+ this.#dropDeadline(waiting);
9091
9212
  if (this.#disposed || this.#waiting.get(waiting.sessionId) !== waiting) return;
9092
9213
  waiting.busy = "unreadable";
9093
9214
  this.#log(`turn-end quiet check failed session=${waiting.sessionId}: ${failureText(error)}`);
9094
9215
  this.#arm(waiting);
9095
9216
  });
9096
9217
  }
9218
+ /** Cancel the bound on the question in flight, if it is still armed. */
9219
+ #dropDeadline(waiting) {
9220
+ if (waiting.deadline !== void 0) clearTimeout(waiting.deadline);
9221
+ waiting.deadline = void 0;
9222
+ }
9223
+ /**
9224
+ * Say once that a held turn end is still waiting, and keep holding it.
9225
+ * @param waiting - the entry that has been held this long.
9226
+ */
9227
+ #stillWaiting(waiting) {
9228
+ if (this.#disposed || this.#waiting.get(waiting.sessionId) !== waiting) return;
9229
+ const waited = this.#now() - waiting.registeredAt;
9230
+ this.#log(`turn-end still waiting session=${waiting.sessionId} waited=${waited}ms busy=${waiting.busy ?? "unanswered"}, nothing announced`);
9231
+ }
9097
9232
  /**
9098
9233
  * Announce one held turn end and forget it.
9099
9234
  *
9100
9235
  * The rate windows are booked inside the two calls below, at this instant: what
9101
9236
  * the channels admit is what they really send, never what was once registered.
9102
9237
  * @param waiting - the entry to announce.
9103
- * @param stillBusy - what kept it waiting, when the budget ran out first.
9104
9238
  */
9105
- #deliver(waiting, stillBusy) {
9239
+ #deliver(waiting) {
9106
9240
  this.#forget(waiting);
9107
9241
  const sessionId = waiting.sessionId;
9108
9242
  const waited = this.#now() - waiting.registeredAt;
9109
- this.#log(stillBusy === void 0 ? `turn-end quiet session=${sessionId} waited=${waited}ms event=${waiting.event}` : `turn-end session=${sessionId} still-busy(${stillBusy}) waited=${waited}ms, announcing anyway`);
9243
+ this.#log(`turn-end quiet session=${sessionId} waited=${waited}ms event=${waiting.event}`);
9110
9244
  try {
9111
9245
  this.#options.push?.notify(waiting.event, sessionId);
9112
9246
  } catch (error) {
@@ -9118,24 +9252,26 @@ var TurnEndQuietGate = class {
9118
9252
  this.#log(`turn-end card for ${sessionId} could not be ended: ${failureText(error)}`);
9119
9253
  }
9120
9254
  }
9121
- /** Drop one entry and both of its timers. */
9255
+ /** Drop one entry and every timer it holds. */
9122
9256
  #forget(waiting) {
9123
9257
  if (waiting.check !== void 0) clearTimeout(waiting.check);
9124
- if (waiting.expiry !== void 0) clearTimeout(waiting.expiry);
9258
+ if (waiting.report !== void 0) clearTimeout(waiting.report);
9259
+ this.#dropDeadline(waiting);
9125
9260
  waiting.check = void 0;
9126
- waiting.expiry = void 0;
9261
+ waiting.report = void 0;
9262
+ waiting.asking = 0;
9127
9263
  if (this.#waiting.get(waiting.sessionId) === waiting) this.#waiting.delete(waiting.sessionId);
9128
9264
  }
9129
9265
  };
9130
9266
  /**
9131
- * The host's answer to "is this session quiet", built from its own two facts.
9267
+ * The host's answer to "is this session's family quiet", built from its own facts.
9132
9268
  *
9133
- * The session list is where the running flag and the parent chain come from, and
9134
- * the job registry is where a job's owner and status come from; neither is
9135
- * captured once, because both move while a held turn end waits. A read that cannot
9136
- * be made is thrown rather than answered as quiet: "the host did not answer" and
9137
- * "nothing is running" are different facts, and the caller retries the one and
9138
- * announces the other.
9269
+ * The session list is where the running flags, the parent chain and each session's
9270
+ * origin come from, and the job registry is where a job's owner and status come
9271
+ * from; neither is captured once, because both move while a held turn end waits. A
9272
+ * read that cannot be made is thrown rather than answered as quiet: "the host did
9273
+ * not answer" and "nothing is running" are different facts, and the caller retries
9274
+ * the one and announces the other.
9139
9275
  * @param options - the faces the answer is read through.
9140
9276
  * @returns the probe the gate asks.
9141
9277
  */
@@ -9151,23 +9287,31 @@ function sessionQuietProbe(options) {
9151
9287
  if (!Array.isArray(items)) throw new Error("session/list returned no item table");
9152
9288
  const running = /* @__PURE__ */ new Set();
9153
9289
  const parents = /* @__PURE__ */ new Map();
9290
+ let subagent;
9154
9291
  for (const item of items) {
9155
9292
  if (typeof item !== "object" || item === null) continue;
9156
9293
  const row = item;
9157
9294
  if (typeof row.sessionId !== "string" || row.sessionId === "") continue;
9158
9295
  if (row.running === true) running.add(row.sessionId);
9159
9296
  if (typeof row.parentSessionId === "string" && row.parentSessionId !== "") parents.set(row.sessionId, row.parentSessionId);
9297
+ if (row.sessionId === sessionId && row.origin === "subagent") subagent = true;
9160
9298
  }
9299
+ const root = familyRootOf(sessionId, parents);
9300
+ const family = /* @__PURE__ */ new Set([root]);
9301
+ for (const id of parents.keys()) if (descendsFrom(id, root, parents)) family.add(id);
9161
9302
  if (running.has(sessionId)) return {
9162
9303
  quiet: false,
9163
- busy: "session-running"
9304
+ busy: "session-running",
9305
+ ...subagent === void 0 ? {} : { subagent }
9164
9306
  };
9165
- for (const id of running) if (descendsFrom(id, sessionId, parents)) return {
9166
- quiet: false,
9167
- busy: `descendant-running(${id})`
9168
- };
9169
- const family = /* @__PURE__ */ new Set([sessionId]);
9170
- for (const id of parents.keys()) if (descendsFrom(id, sessionId, parents)) family.add(id);
9307
+ for (const id of running) {
9308
+ if (id === sessionId || !family.has(id)) continue;
9309
+ return {
9310
+ quiet: false,
9311
+ busy: `${descendsFrom(id, sessionId, parents) ? "descendant" : "ancestor"}-running(${id})`,
9312
+ ...subagent === void 0 ? {} : { subagent }
9313
+ };
9314
+ }
9171
9315
  for (const id of family) {
9172
9316
  const roster = options.jobs.read(id);
9173
9317
  if (roster === void 0) continue;
@@ -9175,13 +9319,29 @@ function sessionQuietProbe(options) {
9175
9319
  if (job.ownerSessionId === void 0 || !family.has(job.ownerSessionId)) continue;
9176
9320
  if (job.finishedAt === void 0) return {
9177
9321
  quiet: false,
9178
- busy: `job-live(${job.id})`
9322
+ busy: `job-live(${job.id})`,
9323
+ ...subagent === void 0 ? {} : { subagent }
9179
9324
  };
9180
9325
  }
9181
9326
  }
9182
- return { quiet: true };
9327
+ return {
9328
+ quiet: true,
9329
+ ...subagent === void 0 ? {} : { subagent }
9330
+ };
9183
9331
  };
9184
9332
  }
9333
+ /** @returns the session a parent chain climbs to, stopping where the chain repeats. */
9334
+ function familyRootOf(sessionId, parents) {
9335
+ const walked = /* @__PURE__ */ new Set([sessionId]);
9336
+ let root = sessionId;
9337
+ let cursor = parents.get(sessionId);
9338
+ while (cursor !== void 0 && !walked.has(cursor)) {
9339
+ root = cursor;
9340
+ walked.add(cursor);
9341
+ cursor = parents.get(cursor);
9342
+ }
9343
+ return root;
9344
+ }
9185
9345
  /** @returns whether one session sits under another in the host's own parent chain. */
9186
9346
  function descendsFrom(sessionId, ancestorId, parents) {
9187
9347
  const walked = /* @__PURE__ */ new Set([sessionId]);
@@ -18309,24 +18469,28 @@ function offlineClaimTtl(env = process.env) {
18309
18469
  const configured = Number(env[OFFLINE_CLAIM_TTL_ENV]);
18310
18470
  return Number.isFinite(configured) && configured > 0 ? configured : OFFLINE_QUESTION_CLAIM_TTL_MS;
18311
18471
  }
18312
- /** The environment variable that moves how long a finished turn waits for its session to go quiet (§28). */
18472
+ /**
18473
+ * The environment variable that moves when a still-waiting turn end is reported (§28).
18474
+ *
18475
+ * The name is the one deployments already set and is kept as it is; what it moves is
18476
+ * the point at which the bridge says it is still waiting, because the wait itself has
18477
+ * no cap.
18478
+ */
18313
18479
  const TURN_END_QUIET_MAX_ENV = "DSH_REMOTE_BRIDGE_TURN_END_QUIET_MAX_MS";
18314
18480
  /**
18315
- * The quiet-wait budget this process runs with.
18481
+ * The still-waiting report point this process runs with.
18316
18482
  *
18317
- * The budget is the bridge's own constant and never a host fact, so a deployment
18318
- * moves it here. A value that is missing, unreadable or not positive falls back to
18319
- * the constant instead of closing the window: a zero budget would announce every
18320
- * turn end at its frame, and an operator who wanted that would be turning push
18321
- * off. The budget only bounds the wait — a session that does fall quiet inside it
18322
- * is announced then, and one that does not is announced at the end with the
18323
- * reason it was still busy.
18483
+ * It is the bridge's own constant and never a host fact, so a deployment moves it
18484
+ * here. A value that is missing, unreadable or not positive falls back to the
18485
+ * constant: the point only decides when the log line saying the wait continues is
18486
+ * written, and nothing about it can make the bridge announce work that is still
18487
+ * running or withhold a turn end whose family is quiet.
18324
18488
  * @param env - the process environment, injectable for a suite.
18325
- * @returns the budget in milliseconds.
18489
+ * @returns the report point in milliseconds.
18326
18490
  */
18327
18491
  function turnEndQuietMaxWait(env = process.env) {
18328
18492
  const configured = Number(env[TURN_END_QUIET_MAX_ENV]);
18329
- return Number.isFinite(configured) && configured > 0 ? configured : TURN_END_QUIET_MAX_MS;
18493
+ return Number.isFinite(configured) && configured > 0 ? configured : TURN_END_QUIET_REPORT_MS;
18330
18494
  }
18331
18495
  /** This machine's IANA time zone, or undefined when the platform has none. */
18332
18496
  function localTimeZone() {
@@ -18619,7 +18783,7 @@ function applyImpl(ctx) {
18619
18783
  peer: ownerPeer,
18620
18784
  jobs
18621
18785
  }),
18622
- maxWaitMs: turnEndQuietMaxWait(),
18786
+ reportAfterMs: turnEndQuietMaxWait(),
18623
18787
  log
18624
18788
  });
18625
18789
  const watchedSessions = () => {
@@ -483,7 +483,7 @@ export declare const CODE_COMMANDS_UNAVAILABLE = "commands-unavailable";
483
483
  * it is a fact about this bridge, not about what a particular host mounts — and
484
484
  * only a call that needs the domain fails. A refusal the `dsh-agents` plugin
485
485
  * itself raised crosses with the plugin's own code instead (`team-not-found`,
486
- * `member-not-found`, `preset-unknown`, `workspace-required` and their
486
+ * `member-not-found`, `preset-unknown`, `workspace-unavailable` and their
487
487
  * neighbours).
488
488
  */
489
489
  export declare const CODE_SQUADS_UNAVAILABLE = "squads-unavailable";