@linxin666/dsh-remote-bridge 0.4.10 → 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/README.i18n.yaml +2 -2
- package/README.md +6 -6
- package/README.zh.md +6 -6
- package/lib/client.js +4 -4
- package/lib/client.js.map +1 -1
- package/lib/index.js +254 -90
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/toolview-slot.d.ts +3 -3
- package/lib/types/client/ui-card.d.ts +1 -1
- package/lib/types/core/connection.d.ts +1 -1
- package/lib/types/core/hub.d.ts +3 -3
- package/lib/types/core/protocol.d.ts +3 -3
- package/lib/types/core/turn-end-quiet.d.ts +104 -40
- package/lib/types/core/ui.d.ts +1 -1
- package/lib/types/host/ui-tools.d.ts +1 -1
- package/lib/types/index.d.ts +16 -12
- package/package.json +1 -1
- package/src/client/UiPresentRow.tsx +1 -1
- package/src/client/index.ts +2 -2
- package/src/client/toolview-slot.ts +3 -3
- package/src/client/ui-card.ts +1 -1
- package/src/core/connection.ts +39 -3
- package/src/core/hub.ts +4 -4
- package/src/core/protocol.ts +3 -3
- package/src/core/turn-end-quiet.ts +281 -98
- package/src/core/ui.ts +1 -1
- package/src/host/ui-tools.ts +4 -4
- package/src/index.ts +28 -22
package/lib/index.js
CHANGED
|
@@ -857,7 +857,7 @@ const CAP_USAGE_STATS = "usage.stats.v1";
|
|
|
857
857
|
* §24.1 同一判据):宿主公告同名项、客户端声明,双向缺一即当作这个能力不存在,
|
|
858
858
|
* 且不得把「宿主没这个能力」渲染成「这张卡不存在」或任何错误态。
|
|
859
859
|
*
|
|
860
|
-
* 宿主半区只有真实现了 `
|
|
860
|
+
* 宿主半区只有真实现了 `ui_present` 这一半的桥才把自己列进
|
|
861
861
|
* {@link SERVED_CAPABILITIES},所以一个客户端读到这个名字,就能断定 `ui.request`
|
|
862
862
|
* 会出现、`ui.event` 会被接受。
|
|
863
863
|
*/
|
|
@@ -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-
|
|
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.#
|
|
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.#
|
|
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;
|
|
@@ -7924,7 +7948,7 @@ var BridgeHub = class {
|
|
|
7924
7948
|
* Present one page to the clients that declared `ui.v1` and wait for the user's
|
|
7925
7949
|
* first action (§35).
|
|
7926
7950
|
*
|
|
7927
|
-
* The body of the `
|
|
7951
|
+
* The body of the `ui_present` tool call. Claimed only while a paired
|
|
7928
7952
|
* connection that declared the channel is on the wire: with none, a page would
|
|
7929
7953
|
* reach nobody, so the call answers `unavailable` at once instead of holding the
|
|
7930
7954
|
* agent on a wait no screen can end (§35.6 — the same judgement as §11.3's claim
|
|
@@ -8167,7 +8191,7 @@ var BridgeHub = class {
|
|
|
8167
8191
|
/**
|
|
8168
8192
|
* @returns whether a reachable right now connection can be shown a page (§35.6).
|
|
8169
8193
|
*
|
|
8170
|
-
* The one predicate `
|
|
8194
|
+
* The one predicate `ui_present` reads before it claims anything, and the reason
|
|
8171
8195
|
* a call with nobody on the wire answers `unavailable` without holding the agent:
|
|
8172
8196
|
* announcing a capability is the whole of what makes a client able to receive one.
|
|
8173
8197
|
*/
|
|
@@ -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
|
|
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
|
|
8931
|
-
* the background jobs the host still holds under
|
|
8932
|
-
* that started them. A phone told "turn finished" at the
|
|
8933
|
-
*
|
|
8934
|
-
* goes on, and is told again by a second turn end it
|
|
8935
|
-
* notification and §29's card answer the same question — "is
|
|
8936
|
-
*
|
|
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
|
-
*
|
|
8941
|
-
*
|
|
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
|
|
8945
|
-
* jobs it attributes to a session. This module invents no
|
|
8946
|
-
* reads no client state, because a guess that says "quiet"
|
|
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
|
|
8952
|
-
*
|
|
8953
|
-
*
|
|
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
|
-
/**
|
|
8957
|
-
|
|
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
|
|
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
|
-
|
|
9132
|
+
report: void 0,
|
|
9133
|
+
deadline: void 0,
|
|
9044
9134
|
busy: void 0,
|
|
9045
|
-
asking:
|
|
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
|
|
9054
|
-
waiting.
|
|
9055
|
-
this.#
|
|
9056
|
-
}, Math.max(0,
|
|
9057
|
-
|
|
9058
|
-
waiting.
|
|
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
|
|
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
|
|
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
|
-
},
|
|
9158
|
+
}, interval);
|
|
9071
9159
|
timer.unref?.();
|
|
9072
9160
|
waiting.check = timer;
|
|
9073
9161
|
}
|
|
9074
|
-
/**
|
|
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
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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.
|
|
9258
|
+
if (waiting.report !== void 0) clearTimeout(waiting.report);
|
|
9259
|
+
this.#dropDeadline(waiting);
|
|
9125
9260
|
waiting.check = void 0;
|
|
9126
|
-
waiting.
|
|
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
|
|
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
|
|
9134
|
-
* the job registry is where a job's owner and status come
|
|
9135
|
-
* captured once, because both move while a held turn end waits. A
|
|
9136
|
-
* be made is thrown rather than answered as quiet: "the host did
|
|
9137
|
-
* "nothing is running" are different facts, and the caller retries
|
|
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)
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
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 {
|
|
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]);
|
|
@@ -17673,7 +17833,7 @@ function toolAbortedBeforeDispatchResult(prior) {
|
|
|
17673
17833
|
//#endregion
|
|
17674
17834
|
//#region src/host/ui-tools.ts
|
|
17675
17835
|
/**
|
|
17676
|
-
* The `
|
|
17836
|
+
* The `ui_present` model tool: the agent hands one self-contained page to the
|
|
17677
17837
|
* clients paired with this host, and the user's first action comes back as that
|
|
17678
17838
|
* same tool call's result (protocol §35).
|
|
17679
17839
|
*
|
|
@@ -17708,12 +17868,12 @@ const UI_PRESENT_DESCRIPTION = [
|
|
|
17708
17868
|
].join(" ");
|
|
17709
17869
|
/** The canonical result body: one sentence, never the page itself. */
|
|
17710
17870
|
function describe(value) {
|
|
17711
|
-
if (typeof value !== "object" || value === null) return "
|
|
17871
|
+
if (typeof value !== "object" || value === null) return "ui_present finished";
|
|
17712
17872
|
const record = value;
|
|
17713
17873
|
if (record.ok === true) return `presented to ${typeof record.delivered === "number" ? record.delivered : 0} paired client(s); settled by the operator with "${typeof record.type === "string" ? record.type : "an action"}"`;
|
|
17714
17874
|
const reason = typeof record.reason === "string" ? record.reason : "unknown";
|
|
17715
17875
|
if (reason === "timeout" || reason === "cancelled") return `presented to ${typeof record.delivered === "number" ? record.delivered : 0} paired client(s); the card was released without an action (${reason})`;
|
|
17716
|
-
return `
|
|
17876
|
+
return `ui_present was refused: ${reason}`;
|
|
17717
17877
|
}
|
|
17718
17878
|
/**
|
|
17719
17879
|
* The presentation payload a transcript-rendering client reads (§35.10).
|
|
@@ -17747,7 +17907,7 @@ function presentationOf(args, value) {
|
|
|
17747
17907
|
*/
|
|
17748
17908
|
function createUiPresentTool(host) {
|
|
17749
17909
|
return defineTool({
|
|
17750
|
-
name: "
|
|
17910
|
+
name: "ui_present",
|
|
17751
17911
|
description: UI_PRESENT_DESCRIPTION,
|
|
17752
17912
|
parameters: {
|
|
17753
17913
|
html: {
|
|
@@ -18283,7 +18443,7 @@ const name = "remote-bridge";
|
|
|
18283
18443
|
* The Host services this plugin cannot run without.
|
|
18284
18444
|
*
|
|
18285
18445
|
* `tools` is what protocol §35 added: this bridge contributes one model tool of
|
|
18286
|
-
* its own (`
|
|
18446
|
+
* its own (`ui_present`), so a host that composes no tool registry is a host where
|
|
18287
18447
|
* the card channel has no caller — the row simply does not mount here.
|
|
18288
18448
|
*/
|
|
18289
18449
|
const inject = [
|
|
@@ -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
|
-
/**
|
|
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
|
|
18481
|
+
* The still-waiting report point this process runs with.
|
|
18316
18482
|
*
|
|
18317
|
-
*
|
|
18318
|
-
*
|
|
18319
|
-
* the
|
|
18320
|
-
*
|
|
18321
|
-
*
|
|
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
|
|
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 :
|
|
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
|
-
|
|
18786
|
+
reportAfterMs: turnEndQuietMaxWait(),
|
|
18623
18787
|
log
|
|
18624
18788
|
});
|
|
18625
18789
|
const watchedSessions = () => {
|
|
@@ -18703,11 +18867,11 @@ function applyImpl(ctx) {
|
|
|
18703
18867
|
}, "remote-bridge: protocol v1 routes");
|
|
18704
18868
|
ctx.effect(() => {
|
|
18705
18869
|
const disposeTool = ctx.tools.register(createUiPresentTool({ present: async (card, signal) => await hub.present(card, signal) }));
|
|
18706
|
-
log("model tool
|
|
18870
|
+
log("model tool ui_present registered");
|
|
18707
18871
|
return () => {
|
|
18708
18872
|
disposeTool();
|
|
18709
18873
|
};
|
|
18710
|
-
}, "remote-bridge:
|
|
18874
|
+
}, "remote-bridge: ui_present tool");
|
|
18711
18875
|
ctx.on("session/event", (session, event) => {
|
|
18712
18876
|
usage.record(session.id, event);
|
|
18713
18877
|
});
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* service, its roster, or its browser cookie path.
|
|
13
13
|
*
|
|
14
14
|
* The half also draws the transcript side of §35.11: one keyed `tool.call.toolview`
|
|
15
|
-
* entry renders a `
|
|
15
|
+
* entry renders a `ui_present` call's whole page in a controlled frame, while the
|
|
16
16
|
* phone stays the only place an action can be answered.
|
|
17
17
|
*
|
|
18
18
|
* Export discipline (packages/AGENTS.md): the /client surface carries only what
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* shape locally:
|
|
12
12
|
*
|
|
13
13
|
* - the slot is keyed and session-scoped, and its key is the wire Tool name
|
|
14
|
-
* (`
|
|
14
|
+
* (`ui_present`), which is what makes one registration draw the card's body
|
|
15
15
|
* without shadowing the official `tool-call` renderer;
|
|
16
16
|
* - the owner publishes the call identity plus a stage union, mirrored here from
|
|
17
17
|
* the upstream `ToolCallPhaseProps`: `preparing`, `start` and `result`. The
|
|
@@ -32,7 +32,7 @@ import { type UiPresentRowProps } from './UiPresentRow.tsx';
|
|
|
32
32
|
/** The keyed Tool view slot the official row dispatches into. */
|
|
33
33
|
export declare const TOOLVIEW_SLOT = "tool.call.toolview";
|
|
34
34
|
/** The wire Tool name this package renders: the keyed cell it claims. */
|
|
35
|
-
export declare const PRESENT_TOOL = "
|
|
35
|
+
export declare const PRESENT_TOOL = "ui_present";
|
|
36
36
|
/** The registration options this seam needs. */
|
|
37
37
|
export interface ToolviewRegistration {
|
|
38
38
|
/** Exact SlotMap key. */
|
|
@@ -54,7 +54,7 @@ export interface ToolviewSlotHost {
|
|
|
54
54
|
readonly slots: unknown;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* Contribute the `
|
|
57
|
+
* Contribute the `ui_present` card into the Tool row.
|
|
58
58
|
*
|
|
59
59
|
* The contribution is declaration-aware: `inject` waits for the official slot
|
|
60
60
|
* declaration, so a GUI composed without a Tool layer has no keyed cell and thus
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The transcript reading of one `
|
|
2
|
+
* The transcript reading of one `ui_present` call (protocol §35.10, §35.11):
|
|
3
3
|
* what the desktop row draws, decided without touching the DOM.
|
|
4
4
|
*
|
|
5
5
|
* A card has two sources and neither may be dropped. While the call is still
|