@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.
@@ -91,7 +91,7 @@ export interface BridgeConnectionOptions {
91
91
  /** Pending user questions: the claims this bridge holds and the answer path back to the host. */
92
92
  readonly questions: QuestionClaims;
93
93
  /**
94
- * 整页卡(§35):`ui.present` 持有的每一张卡,`ui.event` 结算它们,`ui.list`
94
+ * 整页卡(§35):`ui_present` 持有的每一张卡,`ui.event` 结算它们,`ui.list`
95
95
  * 把它们念回去。与提问表平级、各自认领各自结算——两条通道互不改形状(§35.8)。
96
96
  */
97
97
  readonly ui: UiCards;
@@ -24,7 +24,7 @@
24
24
  * to answer with; and the claim outlives the last paired device by a grace
25
25
  * window, because a phone whose app the system suspended has refused nothing.
26
26
  *
27
- * A presented page (`ui.present`, protocol §35) is the second claim that takes a
27
+ * A presented page (`ui_present`, protocol §35) is the second claim that takes a
28
28
  * grace window, and it takes the same one: the tool call it blocks is the agent's
29
29
  * own wait, the card is the only place its answer can come from, and a phone that
30
30
  * was suspended has refused nothing either. It differs in one direction only —
@@ -103,7 +103,7 @@ export interface BridgeHubOptions extends BridgeConnectionOptions {
103
103
  readonly offlineClaimTtlMs?: number;
104
104
  }
105
105
  /**
106
- * What one `ui.present` call ended as, with the count of connections that took
106
+ * What one `ui_present` call ended as, with the count of connections that took
107
107
  * the first frame.
108
108
  *
109
109
  * The count is here rather than in the card registry because it is a fact about
@@ -221,7 +221,7 @@ export declare class BridgeHub {
221
221
  * Present one page to the clients that declared `ui.v1` and wait for the user's
222
222
  * first action (§35).
223
223
  *
224
- * The body of the `ui.present` tool call. Claimed only while a paired
224
+ * The body of the `ui_present` tool call. Claimed only while a paired
225
225
  * connection that declared the channel is on the wire: with none, a page would
226
226
  * reach nobody, so the call answers `unavailable` at once instead of holding the
227
227
  * agent on a wait no screen can end (§35.6 — the same judgement as §11.3's claim
@@ -245,7 +245,7 @@ export declare const CAP_USAGE_STATS = "usage.stats.v1";
245
245
  * §24.1 同一判据):宿主公告同名项、客户端声明,双向缺一即当作这个能力不存在,
246
246
  * 且不得把「宿主没这个能力」渲染成「这张卡不存在」或任何错误态。
247
247
  *
248
- * 宿主半区只有真实现了 `ui.present` 这一半的桥才把自己列进
248
+ * 宿主半区只有真实现了 `ui_present` 这一半的桥才把自己列进
249
249
  * {@link SERVED_CAPABILITIES},所以一个客户端读到这个名字,就能断定 `ui.request`
250
250
  * 会出现、`ui.event` 会被接受。
251
251
  */
@@ -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";
@@ -503,7 +503,7 @@ export declare const PROTO = 1;
503
503
  *
504
504
  * 21 当可交互回复(协议 §35)落地:新增 {@link CAP_UI} 与 {@link CAP_UI_LIST}
505
505
  * 两个能力名、{@link TOPIC_UI_REQUEST} 一个主题、{@link METHOD_UI_EVENT} 与
506
- * {@link METHOD_UI_LIST} 两个方法,宿主半区还多一个模型工具 `ui.present`。客户端
506
+ * {@link METHOD_UI_LIST} 两个方法,宿主半区还多一个模型工具 `ui_present`。客户端
507
507
  * 因此从线路上读到两项新能力名、一种新主题与两种新应答体,所以 minor 抬一格;
508
508
  * `proto` 仍为 1,没有任何既有帧、既有方法或既有键改形状。工具结果是**新增**的:
509
509
  * 老会话、老 prompt、老回合都不受影响,工具名进入宿主工具表之后只有新回合才可能
@@ -1,58 +1,107 @@
1
1
  /**
2
- * When a finished turn may be announced: after the session it belongs to falls
2
+ * When a finished turn may be announced: after the family it belongs to falls
3
3
  * quiet, not when the frame arrives.
4
4
  *
5
5
  * A `turn/end` increment is a fact about one turn and nothing more. The work the
6
- * user started with it may still be going: the child sessions it delegated to and
7
- * the background jobs the host still holds under those sessions outlive the turn
8
- * that started them. A phone told "turn finished" at the frame wakes on a session
9
- * the roster still badges as running, reads a card that says ended while the work
10
- * goes on, and is told again by a second turn end it never asked for. §28's
11
- * notification and §29's card answer the same question — "is this session working
12
- * right now" — and that question has one answer, the one the client already
13
- * computes in `SessionRun`: the host's own `agentRunning` for the session, any
14
- * descendant session still running, and any job the host attributes to either.
6
+ * user started with it may still be going: the subagent sessions the host spawned
7
+ * under it at any depth, and the background jobs the host still holds under any of
8
+ * them, outlive the turn that started them. A phone told "turn finished" at the
9
+ * frame wakes on a roster that still badges a session running, reads a card that
10
+ * says ended while the work goes on, and is told again by a second turn end it
11
+ * never asked for. §28's notification and §29's card answer the same question — "is
12
+ * this work still going" — and that question has one answer, the family's.
15
13
  *
16
- * So a turn end is registered here instead of sent, and sent once the host says
17
- * the session is quiet. Three rules hold that together:
14
+ * The family is the root a session's parent chain climbs to, plus every session
15
+ * under that root at any depth. A leaf session's own turn end therefore waits for
16
+ * the root and for the siblings and cousins it shares that root with, which is the
17
+ * work the user actually started. So a turn end is registered here instead of sent,
18
+ * and sent once the host says the family is quiet. Three rules hold that together:
18
19
  *
19
- * - the answer comes from the host and nowhere else: one `session/list` read for
20
- * the running flag and the parent chain, and the host's job registry for the
21
- * jobs it attributes to a session. This module invents no timer-based guess and
22
- * reads no client state, because a guess that says "quiet" is a lock screen
23
- * saying the work finished when it did not;
20
+ * - the answer comes from the host and nowhere else: one `session/list` read for the
21
+ * running flags, the parent chain and each session's origin, and the host's job
22
+ * registry for the jobs it attributes to a session. This module invents no
23
+ * timer-based guess and reads no client state, because a guess that says "quiet"
24
+ * is a lock screen saying the work finished when it did not;
24
25
  * - nothing on the frame path waits: a registration stores five fields and arms a
25
26
  * timer, so a follow stream still publishes its increment at the speed it did
26
27
  * before;
27
- * - the wait is bounded. At {@link TURN_END_QUIET_MAX_MS} the announcement goes
28
- * out anyway and the line it logs names what was still going, because a
29
- * notification that never arrives is the failure this channel exists to prevent.
28
+ * - the wait has no deadline. A family that stays busy is never announced, and a
29
+ * host that cannot answer is asked again rather than read as quiet: announcing
30
+ * work that is still running is the failure this channel exists to prevent, and a
31
+ * notification that never arrives is the lesser one. One question, though, is
32
+ * bounded ({@link TURN_END_QUIET_PROBE_TIMEOUT_MS}): a read the gateway never
33
+ * returns is abandoned as that question's own failure and the entry asks again, so
34
+ * a stuck call cannot leave the entry holding no question to ask and no way to
35
+ * speak. One line at {@link TURN_END_QUIET_REPORT_MS} says the bridge is still
36
+ * waiting, so an operator is not left guessing why a phone stayed silent.
37
+ *
38
+ * Not every turn end is the phone's to hear. A session the host spawned as a
39
+ * subagent (`origin: "subagent"`) ends turns nobody asked this bridge about, so its
40
+ * turn end is dropped on its first answer unless the phone itself prompted that
41
+ * session over the wire.
30
42
  * @module dsh-remote-bridge/core/turn-end-quiet
31
43
  */
32
44
  import type { JobRoster } from './jobs.ts';
33
45
  import type { LiveActivityNotifier } from './liveactivity.ts';
34
46
  import { type PushNotifier } from './push.ts';
35
47
  import { type BridgeGateway, type GatewayPeer } from './wire.ts';
36
- /** Longest a registered turn end waits for its session to fall quiet, in milliseconds. */
37
- export declare const TURN_END_QUIET_MAX_MS = 600000;
48
+ /**
49
+ * How long a held turn end waits before the bridge logs that it is still waiting,
50
+ * in milliseconds.
51
+ *
52
+ * A progress line and never a send: the wait itself has no cap, because announcing a
53
+ * turn while its family still works is exactly what this module exists to prevent.
54
+ */
55
+ export declare const TURN_END_QUIET_REPORT_MS = 600000;
38
56
  /**
39
57
  * How long a held turn end waits before asking the host again, in milliseconds.
40
58
  *
41
- * A turn end usually finds its session already quiet — the host clears the flag
42
- * as the turn finishes — so the first question is the one that matters, and five
59
+ * A turn end usually finds its family already quiet — the host clears the flag as
60
+ * the turn finishes — so the first question is the one that matters, and five
43
61
  * seconds is short enough that the notification a user waits for is not visibly
44
62
  * late. The interval is also what bounds how many questions one held turn end can
45
63
  * cost: at most one every five seconds, never more than one in flight.
46
64
  */
47
65
  export declare const TURN_END_QUIET_INTERVAL_MS = 5000;
48
- /** The host's answer about the work one session still holds. */
66
+ /**
67
+ * How long one question to the host may stay unanswered before the bridge abandons
68
+ * that question, in milliseconds.
69
+ *
70
+ * Three times {@link TURN_END_QUIET_INTERVAL_MS}. A `session/list` read the host is
71
+ * willing to make comes back well inside one interval, so a question that outlives
72
+ * three of them is a call that will not return — a stuck gateway request, not a slow
73
+ * host — and an entry that keeps waiting for it has no next question to ask, which is
74
+ * exactly how a phone goes permanently silent. The bound belongs to the question and
75
+ * never to the turn end: an abandoned question answers nothing, the entry stays held,
76
+ * and the next question leaves on the usual interval.
77
+ */
78
+ export declare const TURN_END_QUIET_PROBE_TIMEOUT_MS = 15000;
79
+ /**
80
+ * How many session ids the gate remembers the phone prompting, at most.
81
+ *
82
+ * The set exists to tell the phone's own subagent sessions from the ones it merely
83
+ * watches, and a bridge that runs for weeks must not grow it without end: the oldest
84
+ * id is dropped first, and a session dropped that way and prompted again enters as a
85
+ * new one.
86
+ */
87
+ export declare const TURN_END_PHONE_PROMPTED_MAX = 5000;
88
+ /** The host's answer about the work one session's family still holds. */
49
89
  export interface QuietAnswer {
50
- /** Whether nothing under this session is still going. */
90
+ /** Whether nothing in this session's family is still going. */
51
91
  readonly quiet: boolean;
52
92
  /** What was still going when it was not, in one token for the log line. */
53
93
  readonly busy?: string;
94
+ /**
95
+ * Present only when the host says another session spawned this one
96
+ * (`origin: "subagent"`).
97
+ *
98
+ * Absent is a host that said nothing about the session's origin, which is not the
99
+ * same as saying it has none: a turn end is announced for anything the host does
100
+ * not name as a subagent.
101
+ */
102
+ readonly subagent?: boolean;
54
103
  }
55
- /** Whether one session is quiet right now, as the host answers it. */
104
+ /** Whether one session's family is quiet right now, as the host answers it. */
56
105
  export type QuietProbe = (sessionId: string) => Promise<QuietAnswer>;
57
106
  export interface TurnEndQuietOptions {
58
107
  /** The notification path of §28; absent is a bridge that sends no notification. */
@@ -62,17 +111,22 @@ export interface TurnEndQuietOptions {
62
111
  /**
63
112
  * The host's own answer, asked off the frame path.
64
113
  *
65
- * Absent is a bridge assembled without one, which cannot tell a quiet session
66
- * from a busy one and therefore reports at the frame rather than holding
67
- * anything back.
114
+ * Absent is a bridge assembled without one, which cannot tell a quiet family from
115
+ * a busy one — nor a subagent session from the phone's own — and therefore reports
116
+ * at the frame rather than holding anything back.
68
117
  */
69
118
  readonly probe?: QuietProbe;
70
119
  readonly now?: () => number;
71
120
  readonly log?: (message: string) => void;
72
- /** The wait budget; the default is {@link TURN_END_QUIET_MAX_MS}, and a deployment moves it. */
73
- readonly maxWaitMs?: number;
121
+ /** When the still-waiting line is logged; the default is {@link TURN_END_QUIET_REPORT_MS}. */
122
+ readonly reportAfterMs?: number;
74
123
  /** The re-check interval; the default is {@link TURN_END_QUIET_INTERVAL_MS}. */
75
124
  readonly intervalMs?: number;
125
+ /**
126
+ * How many phone-prompted session ids to remember; the default and the ceiling are
127
+ * both {@link TURN_END_PHONE_PROMPTED_MAX}, and a deployment lowers it for a suite.
128
+ */
129
+ readonly phonePromptLimit?: number;
76
130
  }
77
131
  /**
78
132
  * The bridge's outbound turn-end path: registration now, announcement when quiet.
@@ -90,7 +144,7 @@ export declare class TurnEndQuietGate {
90
144
  /** @returns how many turn ends are held right now. */
91
145
  get held(): number;
92
146
  /**
93
- * Hold one finished turn until its session is quiet, then announce it.
147
+ * Hold one finished turn until its family is quiet, then announce it.
94
148
  *
95
149
  * Returns at once and never awaits a host read: the caller is a follow stream
96
150
  * that has already published its increment.
@@ -98,6 +152,16 @@ export declare class TurnEndQuietGate {
98
152
  * @param reason - the host's own reason for ending it.
99
153
  */
100
154
  noteTurnEnd(sessionId: string, reason: string): void;
155
+ /**
156
+ * Remember that the phone itself prompted one session.
157
+ *
158
+ * This is the one thing that makes a subagent session's turn end announceable: the
159
+ * host spawns those on its own, and a phone that never asked that session anything
160
+ * is not waiting to hear how its turn went. Bounded and first in, first out, so the
161
+ * memory is the recent work rather than everything since the bridge started.
162
+ * @param sessionId - the session a `session/prompt` frame carried.
163
+ */
164
+ notePhonePrompt(sessionId: string): void;
101
165
  /**
102
166
  * Drop a held turn end because another turn is on.
103
167
  *
@@ -121,14 +185,14 @@ export interface SessionQuietProbeOptions {
121
185
  readonly jobs: JobRoster;
122
186
  }
123
187
  /**
124
- * The host's answer to "is this session quiet", built from its own two facts.
188
+ * The host's answer to "is this session's family quiet", built from its own facts.
125
189
  *
126
- * The session list is where the running flag and the parent chain come from, and
127
- * the job registry is where a job's owner and status come from; neither is
128
- * captured once, because both move while a held turn end waits. A read that cannot
129
- * be made is thrown rather than answered as quiet: "the host did not answer" and
130
- * "nothing is running" are different facts, and the caller retries the one and
131
- * announces the other.
190
+ * The session list is where the running flags, the parent chain and each session's
191
+ * origin come from, and the job registry is where a job's owner and status come
192
+ * from; neither is captured once, because both move while a held turn end waits. A
193
+ * read that cannot be made is thrown rather than answered as quiet: "the host did
194
+ * not answer" and "nothing is running" are different facts, and the caller retries
195
+ * the one and announces the other.
132
196
  * @param options - the faces the answer is read through.
133
197
  * @returns the probe the gate asks.
134
198
  */
@@ -171,7 +171,7 @@ export interface OpenCardInput {
171
171
  */
172
172
  readonly onSettled?: (card: UiCardView) => void;
173
173
  }
174
- /** The presentation one `ui.present` call is waiting on, as the hub publishes it. */
174
+ /** The presentation one `ui_present` call is waiting on, as the hub publishes it. */
175
175
  export interface ClaimedCard extends UiCardView {
176
176
  /** The user's action, or the refusal that ended the card. Never rejects. */
177
177
  readonly outcome: Promise<UiPresentOutcome>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The `ui.present` model tool: the agent hands one self-contained page to the
2
+ * The `ui_present` model tool: the agent hands one self-contained page to the
3
3
  * clients paired with this host, and the user's first action comes back as that
4
4
  * same tool call's result (protocol §35).
5
5
  *
@@ -13,7 +13,7 @@
13
13
  * - `approval/request` is claimed in-process while a paired device is connected,
14
14
  * and delegated (`next()`) in every other case, which the Host normalizes to
15
15
  * the fail-closed `'unavailable'`.
16
- * - `ui.present` is this bridge's own model tool (protocol §35): one whole
16
+ * - `ui_present` is this bridge's own model tool (protocol §35): one whole
17
17
  * self-contained page is announced as `ui.request` to the paired clients that
18
18
  * declared `ui.v1`, and the user's first action inside it comes back as that
19
19
  * tool call's result. `ui.event` settles it, `ui.list` reads the cards still
@@ -42,7 +42,7 @@ export declare const name = "remote-bridge";
42
42
  * The Host services this plugin cannot run without.
43
43
  *
44
44
  * `tools` is what protocol §35 added: this bridge contributes one model tool of
45
- * its own (`ui.present`), so a host that composes no tool registry is a host where
45
+ * its own (`ui_present`), so a host that composes no tool registry is a host where
46
46
  * the card channel has no caller — the row simply does not mount here.
47
47
  */
48
48
  export declare const inject: string[];
@@ -61,20 +61,24 @@ export declare const OFFLINE_CLAIM_TTL_ENV = "DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TT
61
61
  * @returns the window in milliseconds.
62
62
  */
63
63
  export declare function offlineClaimTtl(env?: NodeJS.ProcessEnv): number;
64
- /** The environment variable that moves how long a finished turn waits for its session to go quiet (§28). */
64
+ /**
65
+ * The environment variable that moves when a still-waiting turn end is reported (§28).
66
+ *
67
+ * The name is the one deployments already set and is kept as it is; what it moves is
68
+ * the point at which the bridge says it is still waiting, because the wait itself has
69
+ * no cap.
70
+ */
65
71
  export declare const TURN_END_QUIET_MAX_ENV = "DSH_REMOTE_BRIDGE_TURN_END_QUIET_MAX_MS";
66
72
  /**
67
- * The quiet-wait budget this process runs with.
73
+ * The still-waiting report point this process runs with.
68
74
  *
69
- * The budget is the bridge's own constant and never a host fact, so a deployment
70
- * moves it here. A value that is missing, unreadable or not positive falls back to
71
- * the constant instead of closing the window: a zero budget would announce every
72
- * turn end at its frame, and an operator who wanted that would be turning push
73
- * off. The budget only bounds the wait — a session that does fall quiet inside it
74
- * is announced then, and one that does not is announced at the end with the
75
- * reason it was still busy.
75
+ * It is the bridge's own constant and never a host fact, so a deployment moves it
76
+ * here. A value that is missing, unreadable or not positive falls back to the
77
+ * constant: the point only decides when the log line saying the wait continues is
78
+ * written, and nothing about it can make the bridge announce work that is still
79
+ * running or withhold a turn end whose family is quiet.
76
80
  * @param env - the process environment, injectable for a suite.
77
- * @returns the budget in milliseconds.
81
+ * @returns the report point in milliseconds.
78
82
  */
79
83
  export declare function turnEndQuietMaxWait(env?: NodeJS.ProcessEnv): number;
80
84
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-remote-bridge",
3
3
  "description": "DSH remote bridge: the host half serves protocol v1 over one exact /ios/v1 WebSocket route — session roster, history baseline, prompting, live turn increments with tool activity, interrupt, and in-process agent approval — to a device paired by a one-shot bootstrap token and a P-256 challenge-response, with the token endpoint admitted only from this machine; the browser half adds one sidebar-foot panel that shows that same one-shot token as a QR symbol and draws an interactive card inside the tool row without answering it, and adds no wire surface",
4
- "version": "0.4.10",
4
+ "version": "0.4.12",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
7
7
  "engines": {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The transcript row of one `ui.present` call: the whole page an agent handed
2
+ * The transcript row of one `ui_present` call: the whole page an agent handed
3
3
  * into the session, drawn in a controlled frame (protocol §35.11).
4
4
  *
5
5
  * The row renders and does not answer. The frame carries `srcdoc` and the one
@@ -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 `ui.present` call's whole page in a controlled frame, while the
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
@@ -80,7 +80,7 @@ export function apply(ctx: ClientContext): void {
80
80
  })
81
81
 
82
82
  // The transcript card of an interactive presentation (§35.11): one keyed
83
- // registration under the wire Tool name draws the body of a `ui.present` call,
83
+ // registration under the wire Tool name draws the body of a `ui_present` call,
84
84
  // so the official Tool row keeps everything else — identity, timing and the
85
85
  // dispatch tree — and no Chat Node renderer is shadowed.
86
86
  registerPresentToolview(ctx, NS)
@@ -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
- * (`ui.present`), which is what makes one registration draw the card's body
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
@@ -35,7 +35,7 @@ import { UiPresentRow, type UiPresentRowProps } from './UiPresentRow.tsx'
35
35
  export const TOOLVIEW_SLOT = 'tool.call.toolview'
36
36
 
37
37
  /** The wire Tool name this package renders: the keyed cell it claims. */
38
- export const PRESENT_TOOL = 'ui.present'
38
+ export const PRESENT_TOOL = 'ui_present'
39
39
 
40
40
  /** The registration options this seam needs. */
41
41
  export interface ToolviewRegistration {
@@ -61,7 +61,7 @@ export interface ToolviewSlotHost {
61
61
  }
62
62
 
63
63
  /**
64
- * Contribute the `ui.present` card into the Tool row.
64
+ * Contribute the `ui_present` card into the Tool row.
65
65
  *
66
66
  * The contribution is declaration-aware: `inject` waits for the official slot
67
67
  * 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 `ui.present` call (protocol §35.10, §35.11):
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
@@ -191,7 +191,7 @@ export interface BridgeConnectionOptions {
191
191
  /** Pending user questions: the claims this bridge holds and the answer path back to the host. */
192
192
  readonly questions: QuestionClaims
193
193
  /**
194
- * 整页卡(§35):`ui.present` 持有的每一张卡,`ui.event` 结算它们,`ui.list`
194
+ * 整页卡(§35):`ui_present` 持有的每一张卡,`ui.event` 结算它们,`ui.list`
195
195
  * 把它们念回去。与提问表平级、各自认领各自结算——两条通道互不改形状(§35.8)。
196
196
  */
197
197
  readonly ui: UiCards
@@ -326,6 +326,13 @@ interface Subscription {
326
326
  */
327
327
  address: SessionAddress
328
328
  opened: Promise<Opening>
329
+ /**
330
+ * Whether this stream has delivered any frame after its opening one. The
331
+ * opening window is a moment, not a state: once the stream moves, that window
332
+ * is as old as the moment it was opened and can no longer answer for a session
333
+ * that has run a turn since.
334
+ */
335
+ advanced: boolean
329
336
  }
330
337
 
331
338
  /** The refusal half of every dispatch outcome. */
@@ -1356,7 +1363,7 @@ export class BridgeConnection {
1356
1363
  if (sessionId === undefined) return refusal(CODE_INVALID_ARGS, 'session.snapshot requires sessionId')
1357
1364
  const unfollowable = await this.#unfollowable(sessionId)
1358
1365
  if (unfollowable !== undefined) return refusal(CODE_SESSION_NOT_FOLLOWABLE, unfollowable)
1359
- const opening = await this.#awaitOpening(this.#ensureSubscription(sessionId))
1366
+ const opening = await this.#openingForBaseline(sessionId)
1360
1367
  if (!opening.ok) return refusal(opening.code, `session ${sessionId} produced no opening frame (${opening.msg})`)
1361
1368
  // A client that declared the trim capability chooses what it is sent, never
1362
1369
  // which turns it gets: the projection is trimmed inside each turn first, and
@@ -1479,7 +1486,7 @@ export class BridgeConnection {
1479
1486
  if (!budget.ok) return budget
1480
1487
  const unfollowable = await this.#unfollowable(sessionId)
1481
1488
  if (unfollowable !== undefined) return refusal(CODE_SESSION_NOT_FOLLOWABLE, unfollowable)
1482
- const opening = await this.#awaitOpening(this.#ensureSubscription(sessionId))
1489
+ const opening = await this.#openingForBaseline(sessionId)
1483
1490
  if (!opening.ok) return refusal(opening.code, `session ${sessionId} produced no opening frame (${opening.msg})`)
1484
1491
  const page = pageTurns(this.#projectionOf(opening.baseline.records), before, budget.maxBytes, (turns, nextBefore, hasMore) =>
1485
1492
  Buffer.byteLength(JSON.stringify(responseFrame(id, { turns, ...(nextBefore === undefined ? {} : { nextBefore }), hasMore })), 'utf8'))
@@ -1630,6 +1637,11 @@ export class BridgeConnection {
1630
1637
  if (!attachments.ok) return attachments
1631
1638
  const receipt = `${sessionId}\u0000${requestId}`
1632
1639
  if (this.#receipts.has(receipt)) return { ok: true, r: { accepted: true } }
1640
+ // A session the phone prompts is the phone's own work, which is the one thing that
1641
+ // makes its turn end announceable at all: the host's own subagent sessions are
1642
+ // dropped by the quiet gate unless they were prompted from here (§28/§29). The
1643
+ // fact is what the wire carried, not what the host accepted.
1644
+ this.#options.turnEndQuiet?.notePhonePrompt(sessionId)
1633
1645
  // A client may prompt without snapshotting first; the subscription is what
1634
1646
  // makes its own deltas reachable.
1635
1647
  this.#ensureSubscription(sessionId)
@@ -2429,6 +2441,7 @@ export class BridgeConnection {
2429
2441
  sessionId,
2430
2442
  controller: new AbortController(),
2431
2443
  address: this.#addressOf(sessionId),
2444
+ advanced: false,
2432
2445
  // Resolved without ever rejecting: a caller may subscribe without awaiting
2433
2446
  // the opening frame (`session.prompt` does exactly that), and an unobserved
2434
2447
  // rejection would take the whole host process down under node's default
@@ -2578,6 +2591,7 @@ export class BridgeConnection {
2578
2591
  for (;;) {
2579
2592
  const next = await iterator.next()
2580
2593
  if (next.done === true) return
2594
+ subscription.advanced = true
2581
2595
  const delta = deltaOfFollowFrame(next.value, this.#toolCalls, this.#messages, memory)
2582
2596
  if (delta === undefined) continue
2583
2597
  this.#emit(TOPIC_SESSION_DELTA, { sessionId: subscription.sessionId, ...delta })
@@ -2618,6 +2632,28 @@ export class BridgeConnection {
2618
2632
  this.#options.liveActivity?.noteTurnEnd(sessionId, reason)
2619
2633
  }
2620
2634
 
2635
+ /**
2636
+ * The opening frame a baseline read is answered from.
2637
+ *
2638
+ * A subscription that has delivered nothing since its opening frame still
2639
+ * holds the window that frame opened, so it is awaited and reused: a session
2640
+ * asked about while it stays silent costs one stream however often it is read.
2641
+ * One that HAS delivered a frame since has moved past that window, and reusing
2642
+ * it would answer a session that ran a turn on this very stream with the empty
2643
+ * baseline of the moment before that turn. Such a subscription is dropped —
2644
+ * its drain aborted and itself forgotten — and a fresh stream answers with the
2645
+ * window the harness opens now, which is the session as it is.
2646
+ * @param sessionId - the session whose baseline is wanted.
2647
+ * @returns that stream's opening frame, or why there is none.
2648
+ */
2649
+ async #openingForBaseline(sessionId: string): Promise<Opening> {
2650
+ const subscription = this.#ensureSubscription(sessionId)
2651
+ if (!subscription.advanced) return this.#awaitOpening(subscription)
2652
+ this.#forget(subscription)
2653
+ subscription.controller.abort()
2654
+ return this.#awaitOpening(this.#ensureSubscription(sessionId))
2655
+ }
2656
+
2621
2657
  /** Await a subscription's opening frame under a bounded wait. */
2622
2658
  async #awaitOpening(subscription: Subscription): Promise<Opening> {
2623
2659
  let timer: NodeJS.Timeout | undefined
package/src/core/hub.ts CHANGED
@@ -24,7 +24,7 @@
24
24
  * to answer with; and the claim outlives the last paired device by a grace
25
25
  * window, because a phone whose app the system suspended has refused nothing.
26
26
  *
27
- * A presented page (`ui.present`, protocol §35) is the second claim that takes a
27
+ * A presented page (`ui_present`, protocol §35) is the second claim that takes a
28
28
  * grace window, and it takes the same one: the tool call it blocks is the agent's
29
29
  * own wait, the card is the only place its answer can come from, and a phone that
30
30
  * was suspended has refused nothing either. It differs in one direction only —
@@ -143,7 +143,7 @@ export interface BridgeHubOptions extends BridgeConnectionOptions {
143
143
  }
144
144
 
145
145
  /**
146
- * What one `ui.present` call ended as, with the count of connections that took
146
+ * What one `ui_present` call ended as, with the count of connections that took
147
147
  * the first frame.
148
148
  *
149
149
  * The count is here rather than in the card registry because it is a fact about
@@ -475,7 +475,7 @@ export class BridgeHub {
475
475
  * Present one page to the clients that declared `ui.v1` and wait for the user's
476
476
  * first action (§35).
477
477
  *
478
- * The body of the `ui.present` tool call. Claimed only while a paired
478
+ * The body of the `ui_present` tool call. Claimed only while a paired
479
479
  * connection that declared the channel is on the wire: with none, a page would
480
480
  * reach nobody, so the call answers `unavailable` at once instead of holding the
481
481
  * agent on a wait no screen can end (§35.6 — the same judgement as §11.3's claim
@@ -745,7 +745,7 @@ export class BridgeHub {
745
745
  /**
746
746
  * @returns whether a reachable right now connection can be shown a page (§35.6).
747
747
  *
748
- * The one predicate `ui.present` reads before it claims anything, and the reason
748
+ * The one predicate `ui_present` reads before it claims anything, and the reason
749
749
  * a call with nobody on the wire answers `unavailable` without holding the agent:
750
750
  * announcing a capability is the whole of what makes a client able to receive one.
751
751
  */
@@ -263,7 +263,7 @@ export const CAP_USAGE_STATS = 'usage.stats.v1'
263
263
  * §24.1 同一判据):宿主公告同名项、客户端声明,双向缺一即当作这个能力不存在,
264
264
  * 且不得把「宿主没这个能力」渲染成「这张卡不存在」或任何错误态。
265
265
  *
266
- * 宿主半区只有真实现了 `ui.present` 这一半的桥才把自己列进
266
+ * 宿主半区只有真实现了 `ui_present` 这一半的桥才把自己列进
267
267
  * {@link SERVED_CAPABILITIES},所以一个客户端读到这个名字,就能断定 `ui.request`
268
268
  * 会出现、`ui.event` 会被接受。
269
269
  */
@@ -560,7 +560,7 @@ export const CODE_COMMANDS_UNAVAILABLE = 'commands-unavailable'
560
560
  * it is a fact about this bridge, not about what a particular host mounts — and
561
561
  * only a call that needs the domain fails. A refusal the `dsh-agents` plugin
562
562
  * itself raised crosses with the plugin's own code instead (`team-not-found`,
563
- * `member-not-found`, `preset-unknown`, `workspace-required` and their
563
+ * `member-not-found`, `preset-unknown`, `workspace-unavailable` and their
564
564
  * neighbours).
565
565
  */
566
566
  export const CODE_SQUADS_UNAVAILABLE = 'squads-unavailable'
@@ -581,7 +581,7 @@ export const PROTO = 1
581
581
  *
582
582
  * 21 当可交互回复(协议 §35)落地:新增 {@link CAP_UI} 与 {@link CAP_UI_LIST}
583
583
  * 两个能力名、{@link TOPIC_UI_REQUEST} 一个主题、{@link METHOD_UI_EVENT} 与
584
- * {@link METHOD_UI_LIST} 两个方法,宿主半区还多一个模型工具 `ui.present`。客户端
584
+ * {@link METHOD_UI_LIST} 两个方法,宿主半区还多一个模型工具 `ui_present`。客户端
585
585
  * 因此从线路上读到两项新能力名、一种新主题与两种新应答体,所以 minor 抬一格;
586
586
  * `proto` 仍为 1,没有任何既有帧、既有方法或既有键改形状。工具结果是**新增**的:
587
587
  * 老会话、老 prompt、老回合都不受影响,工具名进入宿主工具表之后只有新回合才可能