@linxin666/dsh-remote-bridge 0.4.8 → 0.4.10

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.
Files changed (72) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +75 -18
  3. package/README.zh.md +74 -18
  4. package/lib/client.js +783 -260
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +15849 -2913
  7. package/lib/types/client/PairEntry.d.ts +2 -2
  8. package/lib/types/client/PairPanel.d.ts +10 -2
  9. package/lib/types/client/UiPresentRow.d.ts +13 -0
  10. package/lib/types/client/icons.d.ts +5 -13
  11. package/lib/types/client/index.d.ts +4 -0
  12. package/lib/types/client/locales.d.ts +24 -15
  13. package/lib/types/client/semantic.d.ts +9 -5
  14. package/lib/types/client/toolview-slot.d.ts +68 -0
  15. package/lib/types/client/ui-card.d.ts +160 -0
  16. package/lib/types/core/commands.d.ts +59 -0
  17. package/lib/types/core/connection.d.ts +106 -0
  18. package/lib/types/core/devices.d.ts +102 -2
  19. package/lib/types/core/extension.d.ts +13 -0
  20. package/lib/types/core/hub.d.ts +129 -15
  21. package/lib/types/core/liveactivity.d.ts +324 -0
  22. package/lib/types/core/protocol.d.ts +328 -5
  23. package/lib/types/core/push.d.ts +186 -0
  24. package/lib/types/core/questions.d.ts +61 -9
  25. package/lib/types/core/session-meta.d.ts +55 -1
  26. package/lib/types/core/squads.d.ts +130 -0
  27. package/lib/types/core/turn-end-quiet.d.ts +135 -0
  28. package/lib/types/core/ui.d.ts +238 -0
  29. package/lib/types/core/usage-stats.d.ts +160 -0
  30. package/lib/types/core/usage.d.ts +294 -0
  31. package/lib/types/host/apns.d.ts +151 -0
  32. package/lib/types/host/squads-ledger.d.ts +39 -0
  33. package/lib/types/host/squads.d.ts +77 -0
  34. package/lib/types/host/ui-tools.d.ts +80 -0
  35. package/lib/types/host/usage-stats.d.ts +75 -0
  36. package/lib/types/host/watchers.d.ts +95 -0
  37. package/lib/types/index.d.ts +47 -3
  38. package/package.json +15 -14
  39. package/src/client/PairEntry.tsx +58 -31
  40. package/src/client/PairPanel.tsx +181 -97
  41. package/src/client/UiPresentRow.tsx +149 -0
  42. package/src/client/icons.tsx +17 -60
  43. package/src/client/index.ts +11 -0
  44. package/src/client/locales.ts +36 -24
  45. package/src/client/panel.module.css +239 -186
  46. package/src/client/semantic.ts +10 -6
  47. package/src/client/toolview-slot.ts +84 -0
  48. package/src/client/ui-card.ts +368 -0
  49. package/src/client/ui-present.module.css +87 -0
  50. package/src/core/commands.ts +95 -0
  51. package/src/core/connection.ts +811 -12
  52. package/src/core/devices.ts +337 -5
  53. package/src/core/extension.ts +20 -0
  54. package/src/core/hub.ts +518 -43
  55. package/src/core/liveactivity.ts +833 -0
  56. package/src/core/protocol.ts +370 -5
  57. package/src/core/push.ts +385 -0
  58. package/src/core/questions.ts +81 -10
  59. package/src/core/session-meta.ts +73 -1
  60. package/src/core/squads.ts +345 -0
  61. package/src/core/turn-end-quiet.ts +388 -0
  62. package/src/core/ui.ts +398 -0
  63. package/src/core/usage-stats.ts +424 -0
  64. package/src/core/usage.ts +937 -0
  65. package/src/core/wire.ts +8 -0
  66. package/src/host/apns.ts +320 -0
  67. package/src/host/squads-ledger.ts +105 -0
  68. package/src/host/squads.ts +206 -0
  69. package/src/host/ui-tools.ts +233 -0
  70. package/src/host/usage-stats.ts +155 -0
  71. package/src/host/watchers.ts +296 -0
  72. package/src/index.ts +327 -10
@@ -19,17 +19,38 @@ export declare const METHOD_SESSION_MODELS = "session.models";
19
19
  export declare const METHOD_SESSION_SET_MODEL = "session.setModel";
20
20
  export declare const METHOD_SESSION_CREATE = "session.create";
21
21
  export declare const METHOD_SESSION_FORK = "session.fork";
22
+ export declare const METHOD_SESSION_COMMANDS = "session.commands";
23
+ export declare const METHOD_SESSION_COMMAND = "session.command";
24
+ export declare const METHOD_SESSION_RENAME = "session.rename";
25
+ export declare const METHOD_SESSION_PIN = "session.pin";
26
+ export declare const METHOD_SESSION_UNPIN = "session.unpin";
27
+ export declare const METHOD_SESSION_ARCHIVE = "session.archive";
28
+ export declare const METHOD_SESSION_UNARCHIVE = "session.unarchive";
29
+ export declare const METHOD_WORKSPACE_LIST = "workspace.list";
22
30
  export declare const METHOD_PRESETS_LIST = "presets.list";
23
31
  export declare const METHOD_PAIR_BEGIN = "pair.begin";
24
32
  export declare const METHOD_PAIR_FINISH = "pair.finish";
25
33
  export declare const METHOD_APPROVAL_RESOLVE = "approval.resolve";
26
34
  export declare const METHOD_QUESTION_ANSWER = "question.answer";
35
+ export declare const METHOD_QUESTION_LIST = "question.list";
27
36
  export declare const METHOD_JOBS_LIST = "jobs.list";
37
+ export declare const METHOD_SQUADS_STATE = "squads.state";
38
+ export declare const METHOD_SQUADS_LIST = "squads.list";
39
+ export declare const METHOD_SQUADS_RUNS = "squads.runs";
40
+ export declare const METHOD_SQUADS_RUN_MEMBER = "squads.runMember";
41
+ export declare const METHOD_SQUADS_RUN_SQUAD = "squads.runSquad";
42
+ export declare const METHOD_PUSH_REGISTER = "push.register";
43
+ export declare const METHOD_USAGE_SESSION = "usage.session";
44
+ export declare const METHOD_USAGE_BALANCE = "usage.balance";
45
+ export declare const METHOD_USAGE_STATS = "usage.stats";
46
+ export declare const METHOD_UI_EVENT = "ui.event";
47
+ export declare const METHOD_UI_LIST = "ui.list";
28
48
  /** Server-pushed topics of protocol v1. */
29
49
  export declare const TOPIC_SESSION_DELTA = "session.delta";
30
50
  export declare const TOPIC_APPROVAL_REQUEST = "approval.request";
31
51
  export declare const TOPIC_QUESTION_REQUEST = "question.request";
32
52
  export declare const TOPIC_JOBS_CHANGED = "jobs.changed";
53
+ export declare const TOPIC_UI_REQUEST = "ui.request";
33
54
  /**
34
55
  * Capability a client declares in `hello`'s `cap` array to ask for a trimmed
35
56
  * `session.snapshot` baseline. A client that does not declare it — including
@@ -76,6 +97,22 @@ export declare const CAP_SESSION_SNAPSHOT_SINCE = "session.snapshot.since.v1";
76
97
  * exactly as that frame was refused before.
77
98
  */
78
99
  export declare const CAP_QUESTIONS = "questions.v1";
100
+ /**
101
+ * Capability a client declares in `hello`'s `cap` array to learn that this
102
+ * bridge can list the user questions it is still holding.
103
+ *
104
+ * An announcement rather than a switch, the same shape as
105
+ * {@link CAP_SESSION_DEEP_HISTORY}: `question.list` is reachable from every
106
+ * client that declared {@link CAP_QUESTIONS}, exactly as `question.answer` is,
107
+ * so a client written before this name existed loses nothing by declaring it
108
+ * and nothing by never calling the method. What the name buys is a way to tell
109
+ * a bridge that serves the method from one that does not: a host built before
110
+ * it answers `unknown-method`, so a client that does not find this name in
111
+ * `hello`'s `capabilities` keeps the retirement rule it had — a card is over
112
+ * when `question.request` says `settled` — instead of reaping cards on an
113
+ * answer it cannot trust.
114
+ */
115
+ export declare const CAP_QUESTION_LIST = "questions.list.v1";
79
116
  /**
80
117
  * Capability a client declares in `hello`'s `cap` array to be handed the
81
118
  * approval questions this bridge is already holding for it.
@@ -134,6 +171,95 @@ export declare const CAP_JOBS = "jobs.v1";
134
171
  * host no request.
135
172
  */
136
173
  export declare const CAP_AGENTS = "agents.v1";
174
+ /**
175
+ * Capability a client declares in `hello`'s `cap` array to read the host's
176
+ * agent squads and to drive them.
177
+ *
178
+ * Declaring it is what makes `squads.state`, `squads.list`, `squads.runs`,
179
+ * `squads.runMember` and `squads.runSquad` part of that client's protocol at
180
+ * all: a client that does not declare it — including every client written before
181
+ * this channel existed — is refused each as an unknown method, exactly as those
182
+ * frames were refused before. No command is called on a connection's behalf
183
+ * either, so a client that never asks sends the host no request.
184
+ *
185
+ * The channel is additive beside {@link CAP_AGENTS} rather than a replacement:
186
+ * a phone that predates the squad model keeps the preset roster and session
187
+ * creation it was written against, and a phone that reads this name reads the
188
+ * squad domain instead of deriving agents from anything else.
189
+ */
190
+ export declare const CAP_SQUADS = "squads.v1";
191
+ /**
192
+ * Capability a client declares in `hello`'s `cap` array to register the APNs
193
+ * token this device wants to be notified on.
194
+ *
195
+ * Declaring it is what makes `push.register` part of that client's protocol at
196
+ * all: a client that does not declare it — including every client written before
197
+ * this channel existed — is refused that frame as an unknown method, and no
198
+ * device row is written on its behalf.
199
+ *
200
+ * The name announces that this bridge can REMEMBER a token, not that it will
201
+ * send anything. Whether a notification ever leaves the process is a deployment
202
+ * fact (is an APNs signing key configured?) that the wire deliberately cannot
203
+ * express: a bridge with no key answers `ok:true` exactly like one with a key,
204
+ * because a client has no second code path to keep for the difference. Every
205
+ * notification this channel produces is an outbound APNs request and nothing
206
+ * else — no topic, no frame and no state is added to `/ios/v1` (see the
207
+ * protocol's §28).
208
+ */
209
+ export declare const CAP_PUSH = "push.v1";
210
+ /**
211
+ * 客户端在 `hello` 的 `cap` 数组里宣告它要读本桥自己的用量读数。
212
+ *
213
+ * 宣告它是 `usage.session` 与 `usage.balance` 进入这个客户端协议的唯一前提:
214
+ * 不宣告的客户端——包括这个通道出现之前写下的每一个客户端——收到的是与从前
215
+ * 逐字一样的 `unknown-method`,本桥也不会替它读一条会话、更不会替它打一次
216
+ * 上游余额端点。
217
+ *
218
+ * 一个能力名带两个方法,因为它们读的是同一件事的两面:一条会话下一次请求由
219
+ * 什么组成(上下文窗口取宿主自己广播的值,组成由本桥按文本长度估算并恒标
220
+ * `estimated: true`),以及某条 provider 路由背后账户的余额(DeepSeek 官方
221
+ * 口径,只在路由确实指向 `api.deepseek.com` 且凭据拿得到时才查官方端点,宿主
222
+ * 侧同一 provider + 凭据 60 秒最多一次上游请求)。
223
+ */
224
+ export declare const CAP_USAGE = "usage.v1";
225
+ /**
226
+ * 客户端在 `hello` 的 `cap` 数组里宣告它要读宿主自己的用量台账聚合。
227
+ *
228
+ * 与 {@link CAP_USAGE} 平级、独立声明:宣告它是 `usage.stats` 进入这个客户端
229
+ * 协议的唯一前提,不宣告的客户端——包括 `usage.v1` 出现之后、这个能力出现之前
230
+ * 写下的每一个客户端——收到的仍是 `unknown-method`,本桥也不会替它去读宿主
231
+ * 上 `dsh-usage` 插件的任何一条路由。
232
+ *
233
+ * 拆成独立能力而不是塞进 `usage.v1`,是因为它读的是另一件事:那两半读的是本
234
+ * 进程自己的事实(一个会话、一条路由的账户),这一半读的是另一个插件挂在这个
235
+ * 宿主上的 HTTP 路由,而那个插件可能根本没装。老客户端忽略这个未知名字即可,
236
+ * 它看到的能力表里多一项、别的什么都没有变。
237
+ */
238
+ export declare const CAP_USAGE_STATS = "usage.stats.v1";
239
+ /**
240
+ * 客户端在 `hello` 的 `cap` 数组里宣告它要渲染整页卡并回答它(协议 §35)。
241
+ *
242
+ * 宣告它是 `ui.request` 与 `ui.event` 进入这个客户端协议的唯一前提:不宣告的
243
+ * 客户端——包括这个通道出现之前写下的每一个客户端——收不到任何一帧整页卡,它的
244
+ * `ui.event` 回 `unknown-method`,其余逐字节不变。它是**公告不是协商**(§13.1、
245
+ * §24.1 同一判据):宿主公告同名项、客户端声明,双向缺一即当作这个能力不存在,
246
+ * 且不得把「宿主没这个能力」渲染成「这张卡不存在」或任何错误态。
247
+ *
248
+ * 宿主半区只有真实现了 `ui.present` 这一半的桥才把自己列进
249
+ * {@link SERVED_CAPABILITIES},所以一个客户端读到这个名字,就能断定 `ui.request`
250
+ * 会出现、`ui.event` 会被接受。
251
+ */
252
+ export declare const CAP_UI = "ui.v1";
253
+ /**
254
+ * 客户端在 `hello` 的 `cap` 数组里宣告它要按 §24.3 的四条件对账自己手上的整页卡
255
+ * (协议 §35.4)。
256
+ *
257
+ * 与 {@link CAP_QUESTION_LIST} 同一形状:`ui.list` 本身是只读的、对每条配对连接
258
+ * 都开放,这个名字买到的是「这条连接会不会被答」之外的另一种确定性——一条老桥
259
+ * 回 `unknown-method`,于是没有这个名字的客户端就保留它原有的退休规则(卡片只在
260
+ * `ui.request` 说 `settled` 时结束),而不是按一次它信不过的应答清卡。
261
+ */
262
+ export declare const CAP_UI_LIST = "ui.list.v1";
137
263
  /**
138
264
  * Capability a client declares in `hello`'s `cap` array to be answered with
139
265
  * byte-level increments instead of the whole roster or the whole board.
@@ -202,6 +328,63 @@ export declare const CAP_SESSION_DEEP_HISTORY = "session.deep-history.v1";
202
328
  * re-derived here.
203
329
  */
204
330
  export declare const CAP_SESSION_FORK = "session.fork.v1";
331
+ /**
332
+ * Capability a client declares in `hello`'s `cap` array to list a session's
333
+ * slash commands and skills and to run one of them.
334
+ *
335
+ * Declaring it is what makes `session.commands` and `session.command` part of
336
+ * that client's protocol at all: a client that does not declare it — including
337
+ * every client written before this channel existed — is refused both as unknown
338
+ * methods, exactly as those frames were refused before. Neither method is called
339
+ * on a connection's behalf either, so a client that never asks costs the host no
340
+ * registry read and no skill catalog read.
341
+ *
342
+ * The channel holds no events and no cache: a directory is read live on every
343
+ * call, so a command a plugin registered a moment ago and a skill withdrawn from
344
+ * one Agent preset are both reflected in the answer that follows.
345
+ */
346
+ export declare const CAP_COMMANDS = "commands.v1";
347
+ /**
348
+ * Capability a client declares in `hello`'s `cap` array to read the host's
349
+ * workspaces and its two registry-global session sets.
350
+ *
351
+ * Declaring it is what makes `workspace.list` part of that client's protocol at
352
+ * all: a client that does not declare it — including every client written before
353
+ * this channel existed — is refused that frame as an unknown method, and no
354
+ * registry is read on its behalf. Behind the name the answer is the host's own
355
+ * synchronous projection: one row per registered workspace in registry order,
356
+ * plus the complete archive and pin sets.
357
+ *
358
+ * The method is a read and nothing is cached, so a pin or an archive followed by
359
+ * another list reads the set the write left behind. That pair of calls is the
360
+ * whole refresh story of the session-admin channel: see {@link CAP_SESSION_ADMIN}.
361
+ */
362
+ export declare const CAP_WORKSPACE = "workspace.v1";
363
+ /**
364
+ * Capability a client declares in `hello`'s `cap` array to rename, pin,
365
+ * unpin, archive and unarchive a session.
366
+ *
367
+ * Declaring it is what makes those five methods part of that client's protocol
368
+ * at all: a client that does not declare it — including every client written
369
+ * before this channel existed — is refused each as an unknown method, and no
370
+ * write is asked of the host on its behalf.
371
+ *
372
+ * Every one of the five is forwarded one-to-one to the endpoint that already
373
+ * owns the semantics, so nothing about a title, a pin or an archive is modelled
374
+ * or re-derived here: a rename reaches `session/rename` — the endpoint that
375
+ * restores a cold session before it writes, which is why a client needs no
376
+ * resume path of its own — and the four set mutations reach
377
+ * `workspace/pinSession`, `workspace/unpinSession`, `workspace/archiveSession`
378
+ * and `workspace/unarchiveSession`. A host refusal crosses with its own code
379
+ * and text, `workspace/session-active` included.
380
+ *
381
+ * The channel publishes no event, because the host announces none of these
382
+ * writes as a cordis event a connection could fold into a delta: a rename
383
+ * appends one `session/title` log record and nothing else. A client re-reads
384
+ * after a write instead — the pin set through {@link CAP_WORKSPACE}, the roster
385
+ * through `session.list` — which is why one branch serves both capabilities.
386
+ */
387
+ export declare const CAP_SESSION_ADMIN = "session.admin.v1";
205
388
  /**
206
389
  * Capability a client declares in `hello`'s `cap` array to be sent frames
207
390
  * compressed instead of as plain text.
@@ -229,6 +412,14 @@ export declare const KNOWN_METHODS: ReadonlySet<string>;
229
412
  export declare const CODE_UNPAIRED = "unpaired";
230
413
  export declare const CODE_UNKNOWN_METHOD = "unknown-method";
231
414
  export declare const CODE_INVALID_ARGS = "invalid-args";
415
+ /**
416
+ * `usage.session` 点名的会话在这个宿主上不存在:宿主自己的会话名册里没有它,
417
+ * 活会话存储里没有它,本进程也从未观察过它的任何事件。它与「会话存在但两项
418
+ * 读数都取不到」是两个答案,后者回的是空对象——一条刚刚开始、还什么都没广播
419
+ * 的会话,以及一条在桥重载前就存在的会话,都在那个状态里:存在而没读数,不是
420
+ * 不存在。
421
+ */
422
+ export declare const CODE_UNKNOWN_SESSION = "unknown-session";
232
423
  export declare const CODE_PROTO_UNSUPPORTED = "proto-unsupported";
233
424
  export declare const CODE_TOKEN_INVALID = "token-invalid";
234
425
  export declare const CODE_NONCE_INVALID = "nonce-invalid";
@@ -240,6 +431,30 @@ export declare const CODE_APPROVAL_UNKNOWN = "approval-unknown";
240
431
  * failures crossing this method keep their own codes instead.
241
432
  */
242
433
  export declare const CODE_QUESTION_UNKNOWN = "question-unknown";
434
+ /**
435
+ * The bridge could not read the questions it is holding, so it cannot say which
436
+ * ones are still live. The answer is deliberately not an empty list: a client
437
+ * retires every card a COMPLETE list does not carry, and a read that failed is
438
+ * not a complete one — it is a bridge that cannot answer this question today.
439
+ */
440
+ export declare const CODE_QUESTION_LIST_UNAVAILABLE = "question-list-unavailable";
441
+ /**
442
+ * 本桥不认领这个 `callId`:它从没呈现过这张卡,或者这张卡已被别处结算(宽限窗口
443
+ * 到期、回合被取消、桥卸载)。客户端码表保持开放:除本码之外的未知码不得被读成
444
+ * 「卡已消失」(§11.3 同一句)。
445
+ */
446
+ export declare const CODE_UI_UNKNOWN = "ui-unknown";
447
+ /**
448
+ * 这张卡已经被用户自己的第一条动作结算过(§35.3)。它与 {@link CODE_UI_UNKNOWN}
449
+ * 是两个答案:重复的一次点击是「已经做完了」,不是「这张卡不存在」。
450
+ */
451
+ export declare const CODE_UI_SETTLED = "ui-settled";
452
+ /**
453
+ * 本桥读不出自己持有的卡,所以它说不了哪些还活着。答案故意不是一张空表:客户端
454
+ * 只会按 COMPLETE 的列表退休卡片,一次失败的读不是一张完整的空表,而是这台桥今天
455
+ * 答不了这一问(与 {@link CODE_QUESTION_LIST_UNAVAILABLE} 同一句)。
456
+ */
457
+ export declare const CODE_UI_LIST_UNAVAILABLE = "ui-list-unavailable";
243
458
  /**
244
459
  * The named session is a delegated child whose durable parent is not a session
245
460
  * this connection may read. The bridge follows an addressable child and refuses
@@ -253,6 +468,32 @@ export declare const CODE_SNAPSHOT_UNAVAILABLE = "snapshot-unavailable";
253
468
  * what a particular host mounts — and only a call that needs the registry fails.
254
469
  */
255
470
  export declare const CODE_JOBS_UNAVAILABLE = "jobs-unavailable";
471
+ /**
472
+ * This host serves no endpoint behind the command channel: no `commands/list`,
473
+ * no `commands/execute` or no `skills/list`, which the gateway itself reports
474
+ * as an endpoint nothing exports. The capability stays advertised — it is a fact
475
+ * about this bridge, not about what a particular host mounts — and only a call
476
+ * that needs those endpoints fails.
477
+ */
478
+ export declare const CODE_COMMANDS_UNAVAILABLE = "commands-unavailable";
479
+ /**
480
+ * This host serves no squad domain this bridge can reach: no answer to the
481
+ * plugin's state route over loopback, no readable ledger beside it, or a body
482
+ * this build cannot read as one squad domain. The capability stays advertised —
483
+ * it is a fact about this bridge, not about what a particular host mounts — and
484
+ * only a call that needs the domain fails. A refusal the `dsh-agents` plugin
485
+ * itself raised crosses with the plugin's own code instead (`team-not-found`,
486
+ * `member-not-found`, `preset-unknown`, `workspace-required` and their
487
+ * neighbours).
488
+ */
489
+ export declare const CODE_SQUADS_UNAVAILABLE = "squads-unavailable";
490
+ /**
491
+ * The definitions are readable but the two run commands cannot be served: this
492
+ * host answered no run route over loopback, and the read-only ledger fallback
493
+ * cannot launch anything. Failing closed is the point — a client is told the
494
+ * capability is not served here rather than shown a run that never started.
495
+ */
496
+ export declare const CODE_SQUADS_RUN_UNAVAILABLE = "squads-run-unavailable";
256
497
  export declare const CODE_SNAPSHOT_TOO_LARGE = "snapshot-too-large";
257
498
  export declare const CODE_INTERNAL = "internal";
258
499
  /** Protocol version this package speaks. */
@@ -260,6 +501,75 @@ export declare const PROTO = 1;
260
501
  /**
261
502
  * Minor version this package speaks.
262
503
  *
504
+ * 21 当可交互回复(协议 §35)落地:新增 {@link CAP_UI} 与 {@link CAP_UI_LIST}
505
+ * 两个能力名、{@link TOPIC_UI_REQUEST} 一个主题、{@link METHOD_UI_EVENT} 与
506
+ * {@link METHOD_UI_LIST} 两个方法,宿主半区还多一个模型工具 `ui.present`。客户端
507
+ * 因此从线路上读到两项新能力名、一种新主题与两种新应答体,所以 minor 抬一格;
508
+ * `proto` 仍为 1,没有任何既有帧、既有方法或既有键改形状。工具结果是**新增**的:
509
+ * 老会话、老 prompt、老回合都不受影响,工具名进入宿主工具表之后只有新回合才可能
510
+ * 被调用。
511
+ * 20 when the usage stats channel shipped: behind {@link CAP_USAGE_STATS} a
512
+ * client may call {@link METHOD_USAGE_STATS} and read the host's own usage
513
+ * ledger — today, this month and one row per local day — and behind the same
514
+ * {@link CAP_USAGE} this bridge now also answers `usage.session` with a
515
+ * `modelContextWindow` when the model catalog of the session's route declares
516
+ * one, so a client reads one new reply body and one new optional key off the
517
+ * wire and has to read the name before it asks. The stats half is independent
518
+ * of {@link CAP_USAGE} on purpose: it reads another plugin's HTTP routes, which
519
+ * a host may not mount at all, so a client written before this name existed
520
+ * keeps the two readings it had and the bridge reads no route on its behalf.
521
+ * No frame, no topic, no existing method and no existing key changes shape.
522
+ * 19 when the usage channel shipped: behind {@link CAP_USAGE} a client may call
523
+ * {@link METHOD_USAGE_SESSION} and read one session's context window and its
524
+ * request's estimated composition, and {@link METHOD_USAGE_BALANCE} and read the
525
+ * account behind one provider route, so it reads two new reply bodies off the
526
+ * wire and has to read the name before it asks — a bridge below this one answers
527
+ * `unknown-method` for both. No frame, no topic and no existing method changes
528
+ * shape.
529
+ * 18 when one card learned to lay out several sessions (§30 of
530
+ * `docs/protocol-v1.md` in the iphone_remote_use_dsh repository): `content-state`
531
+ * gains the optional `rows` key, so a phone reads up to three sessions off one
532
+ * lock-screen card instead of having to hold one card per session. It is a pure
533
+ * addition — no new method, no new capability name, no existing key or topic
534
+ * changes shape — so the minor counts the key alone, and a client that reads 18
535
+ * knows the order of the rows it is handed is the bridge's rather than one it
536
+ * has to derive.
537
+ * 17 when the live-activity channel shipped (§29.2): this bridge now sends the
538
+ * lock-screen card a suspended app cannot update itself, addressed to the
539
+ * per-card APNs tokens {@link METHOD_PUSH_REGISTER} already carries and projected
540
+ * per session rather than per bridge. It is a pure addition — no new method, no
541
+ * new capability name, and no existing frame, field or topic changes shape — so
542
+ * the minor counts it alone: a client that wants a card has to read 17 before it
543
+ * registers one, because a bridge below this one has no sending path at all and
544
+ * would answer `ok:true` to a registration it can never use.
545
+ * 16 when the push channel shipped: behind {@link CAP_PUSH} a client may call
546
+ * {@link METHOD_PUSH_REGISTER} and have the device table remember an APNs token,
547
+ * so a phone learns a turn ended — or that a question is waiting — while its
548
+ * socket is not open. No frame, no topic and no existing method changes shape;
549
+ * the minor is raised because a new reply body and a new announcement appear on
550
+ * the wire, and because a client has to read the name before it registers.
551
+ * 15 when the squads channel shipped: behind {@link CAP_SQUADS} a client may
552
+ * call {@link METHOD_SQUADS_STATE}, {@link METHOD_SQUADS_LIST},
553
+ * {@link METHOD_SQUADS_RUNS}, {@link METHOD_SQUADS_RUN_MEMBER} and
554
+ * {@link METHOD_SQUADS_RUN_SQUAD}, so it reads five new reply bodies off the wire
555
+ * and drives the squad domain instead of deriving its agents from anything else.
556
+ * 14 when the session-admin channel shipped: behind {@link CAP_WORKSPACE} a
557
+ * client may call {@link METHOD_WORKSPACE_LIST} and read the host's workspaces
558
+ * with both registry-global session sets, and behind {@link CAP_SESSION_ADMIN}
559
+ * it may call {@link METHOD_SESSION_RENAME}, {@link METHOD_SESSION_PIN},
560
+ * {@link METHOD_SESSION_UNPIN}, {@link METHOD_SESSION_ARCHIVE} and
561
+ * {@link METHOD_SESSION_UNARCHIVE}, so a phone long-presses a roster row for the
562
+ * same five actions the desktop offers it.
563
+ * 13 when the question list shipped: behind {@link CAP_QUESTION_LIST} a client
564
+ * may call {@link METHOD_QUESTION_LIST} and be answered the questions this
565
+ * bridge is still holding, so it reads a new reply body off the wire and the
566
+ * number rises with it. It is what lets a phone stop trusting a card it holds:
567
+ * the one retirement signal before it was `question.request` with
568
+ * `state: "settled"`, which a phone that was disconnected when the last client
569
+ * left never receives.
570
+ * 12 when the command channel shipped: behind {@link CAP_COMMANDS} a client may
571
+ * call {@link METHOD_SESSION_COMMANDS} and {@link METHOD_SESSION_COMMAND}, so it
572
+ * reads a new reply body off the wire and the number rises with it.
263
573
  * 11 when the fork channel shipped: behind {@link CAP_SESSION_FORK} a client may
264
574
  * call {@link METHOD_SESSION_FORK} and receive the host's own fork answer, so a
265
575
  * phone branches a session that inherits the context of the one it forked. This
@@ -302,13 +612,26 @@ export declare const PROTO = 1;
302
612
  * declares the capability that plugin requires. No addition changed the major
303
613
  * version, a frozen field, or an existing method or topic name.
304
614
  */
305
- export declare const MINOR = 11;
615
+ export declare const MINOR = 21;
306
616
  /**
307
- * The capabilities this bridge itself serves, as `hello` advertises them.
617
+ * The capabilities this bridge itself serves, and the opening half of what
618
+ * `hello` advertises.
619
+ *
620
+ * A capability a mounted plugin adds is not listed here — the bridge is not its
621
+ * author and names none of them — but `hello` advertises it all the same: the
622
+ * answer is this list plus every capability the extension registry currently
623
+ * requires a client to declare (`RemoteBridgeRegistry.capabilities`), computed
624
+ * on each greeting so a plugin mounted after this bridge was built is visible
625
+ * to the next phone. A name both halves carry is listed once, and this list
626
+ * keeps its order at the front, so a bridge with no extension mounted answers
627
+ * byte for byte the list it always did. Extension names never move
628
+ * {@link MINOR}: that number describes this protocol, and a plugin's own names
629
+ * are the plugin's.
308
630
  *
309
- * A capability a mounted plugin adds is not listed here: the bridge cannot know
310
- * what it is not the author of. A client learns such a capability from the
311
- * plugin's own documentation, exactly as it did before this list existed.
631
+ * A capability whose whole switch is a declaration — no method, no answer, no
632
+ * field behind it, such as {@link CAP_APPROVALS} — stays out of this list for
633
+ * the reason it always did: advertising it would claim a handshake change
634
+ * without one.
312
635
  */
313
636
  export declare const SERVED_CAPABILITIES: readonly string[];
314
637
  /** `server` field of the hello response. */
@@ -0,0 +1,186 @@
1
+ /**
2
+ * What this bridge tells a phone that is not listening.
3
+ *
4
+ * Every fact a phone needs already has a read on the wire — a roster, a
5
+ * baseline, a question list — and a notification is not one of them. It is the
6
+ * `turn ended` or `something is waiting` event, delivered by APNs to a device
7
+ * whose socket is closed, and nothing else: this module deliberately holds no
8
+ * session state, publishes no topic, and answers no method. A client that acts
9
+ * on a notification still has to read the fact behind it (protocol §28).
10
+ *
11
+ * Three rules live here, so the sender beside it cannot disagree about them:
12
+ *
13
+ * - the payload carries a session's NAME, its workspace's short name, the state
14
+ * and one deep link. Never a message, a tool output, a file name or a
15
+ * question's body — a notification crosses Apple's servers and sits on a lock
16
+ * screen, which is the last place session content should be;
17
+ * - the same `(sessionId, event)` inside {@link PUSH_DEDUPE_MS} is one
18
+ * notification, because two phones following one session both see the same
19
+ * turn end and the user has one lock screen, and one APNs token is one
20
+ * delivery, because a token belongs to the app install rather than to one
21
+ * pairing, so the rows that share it are still that one phone;
22
+ * - a failed delivery is logged and dropped. Nothing here is awaited by the
23
+ * delta path, so a broken APNs connection cannot delay, reorder or suppress a
24
+ * frame that a connected phone is waiting for.
25
+ * @module dsh-remote-bridge/core/push
26
+ */
27
+ /** One thing a notification can be about. */
28
+ export type PushEvent = 'turn-end' | 'turn-error' | 'question' | 'approval';
29
+ /** Window inside which the same `(sessionId, event)` is one notification. */
30
+ export declare const PUSH_DEDUPE_MS = 30000;
31
+ /** Shortest gap between two notifications about the same session. */
32
+ export declare const PUSH_SESSION_INTERVAL_MS = 10000;
33
+ /** Most notifications this bridge sends in any rolling minute. */
34
+ export declare const PUSH_GLOBAL_PER_MINUTE = 30;
35
+ /** Sessions whose workspace short name is remembered for the payload. */
36
+ export declare const PUSH_WORKSPACE_LIMIT = 512;
37
+ /** The only deep-link form this channel emits. */
38
+ export declare const PUSH_DEEP_LINK_PREFIX = "whale://session/";
39
+ /** One device a notification can be addressed to. */
40
+ export interface PushAddress {
41
+ readonly deviceToken: string;
42
+ readonly environment: 'sandbox' | 'production';
43
+ readonly bundle: string;
44
+ readonly locale?: string;
45
+ }
46
+ /** The request body one APNs delivery carries (protocol §28.4). */
47
+ export interface PushNotification {
48
+ readonly aps: {
49
+ readonly alert: {
50
+ readonly title: string;
51
+ readonly body: string;
52
+ };
53
+ readonly sound: 'default';
54
+ };
55
+ /** Workspace short name; absent when this bridge cannot resolve one. */
56
+ readonly w?: string;
57
+ readonly s: string;
58
+ readonly st: PushEvent;
59
+ readonly url: string;
60
+ }
61
+ /** What one delivery attempt reported. */
62
+ export interface PushSendResult {
63
+ readonly ok: boolean;
64
+ /** The status APNs answered, when it answered at all. */
65
+ readonly status?: number;
66
+ /** The reason APNs named, or this bridge's own note. */
67
+ readonly reason?: string;
68
+ }
69
+ /** One delivery a sender refused, in the words the bridge needs to read it. */
70
+ export interface PushDeliveryFailure {
71
+ /** The registration APNs refused: the roster row holding it is a device that no longer exists. */
72
+ readonly deviceToken: string;
73
+ /** The status APNs answered, when it answered at all. */
74
+ readonly status?: number;
75
+ /** The reason APNs named, or this bridge's own note. */
76
+ readonly reason?: string;
77
+ }
78
+ /** What one {@link PushNotifier.notify} ended up doing, once every attempt settled. */
79
+ export interface PushDeliveryReport {
80
+ /** How many devices took the notification. */
81
+ readonly delivered: number;
82
+ /** Every attempt that did not land, in target order. */
83
+ readonly failures: readonly PushDeliveryFailure[];
84
+ }
85
+ /**
86
+ * @param failure - one refused delivery.
87
+ * @returns whether the registration behind it is dead for good.
88
+ *
89
+ * APNs says a token will never work again in three ways: 410 with
90
+ * `Unregistered`, and 400 with `Unregistered` or `BadDeviceToken`. All three are
91
+ * final facts about the registration — the app was removed, or this token belongs
92
+ * to another environment or bundle — so it is cleaned up instead of retried, and
93
+ * a claim held for it is a claim held for a phone that cannot come back.
94
+ */
95
+ export declare function isDeadPushToken(failure: PushDeliveryFailure): boolean;
96
+ /** Whatever actually reaches a device; the APNs client implements this. */
97
+ export interface PushSender {
98
+ send(target: PushAddress, notification: PushNotification): Promise<PushSendResult>;
99
+ }
100
+ /** What the payload builder may say about one session. */
101
+ export interface PushLabels {
102
+ readonly title?: string;
103
+ readonly workspace?: string;
104
+ }
105
+ export interface PushNotifierOptions {
106
+ /**
107
+ * The devices that asked to be notified, read per event.
108
+ *
109
+ * The list may carry several rows holding the same `deviceToken`: a phone that
110
+ * pairs again owns more than one roster row, and a token outlives any one
111
+ * pairing. Converging them is this module's job, not the caller's.
112
+ */
113
+ readonly targets: () => readonly PushAddress[];
114
+ /** The sender; absent is a bridge with no signing key, and then nothing happens. */
115
+ readonly sender?: PushSender;
116
+ /** The session's own title (§26's source), read per event. */
117
+ readonly titles?: (sessionId: string) => string | undefined;
118
+ readonly now?: () => number;
119
+ readonly log?: (message: string) => void;
120
+ readonly dedupeMs?: number;
121
+ readonly sessionIntervalMs?: number;
122
+ readonly globalPerMinute?: number;
123
+ }
124
+ /**
125
+ * The notification the channel sends for one event (protocol §28.4).
126
+ *
127
+ * Pure, and exported so the shape can be asserted without a sender: the keys
128
+ * are the contract, and the absence of any body text is the property that
129
+ * matters most.
130
+ * @param event - what happened.
131
+ * @param sessionId - the session it happened to.
132
+ * @param labels - the name and workspace short name, when the bridge holds them.
133
+ * @returns the exact payload an APNs delivery carries.
134
+ */
135
+ export declare function buildPushNotification(event: PushEvent, sessionId: string, labels?: PushLabels): PushNotification;
136
+ /**
137
+ * Which event one `turn-end` delta is.
138
+ * @param reason - the host's own reason for ending the turn.
139
+ * @returns the normal end for `completed`, the abnormal one for every other
140
+ * value — including `unknown`, which is what an unreadable reason reports.
141
+ */
142
+ export declare function pushEventOfTurnEnd(reason: string): PushEvent;
143
+ /**
144
+ * The bridge's outbound notification path.
145
+ *
146
+ * Deliberately inert when no sender is configured: {@link enabled} is false, no
147
+ * target is ever read and no clock is ever consulted, so an unconfigured bridge
148
+ * behaves — byte for byte, frame for frame — exactly as it did before this
149
+ * channel existed.
150
+ */
151
+ export declare class PushNotifier {
152
+ #private;
153
+ constructor(options: PushNotifierOptions);
154
+ /** @returns whether this bridge will actually deliver anything. */
155
+ get enabled(): boolean;
156
+ /**
157
+ * Remember the workspace each session belongs to, from a roster this bridge
158
+ * just served.
159
+ *
160
+ * A notification's `w` is the only label the bridge cannot read from the
161
+ * title service, and asking the host for a roster on every turn end would put
162
+ * a gateway call on the notification path. The rows are already in hand when a
163
+ * phone lists them, so the short name is picked up there and kept bounded; a
164
+ * session never listed simply gets a payload without `w`.
165
+ * @param rows - the roster rows that were just built for a client.
166
+ */
167
+ noteSessions(rows: readonly {
168
+ readonly id: string;
169
+ readonly cwd?: string;
170
+ }[]): void;
171
+ /**
172
+ * Announce one event to every registered device.
173
+ *
174
+ * Returns before anything is sent: delivery starts on a fresh microtask, so a
175
+ * caller on the delta path never awaits an APNs round trip and a sender that
176
+ * throws cannot reach it.
177
+ * @param event - what happened.
178
+ * @param sessionId - the session it happened to.
179
+ * @param onReport - receives how the announcement ended, once every attempt has
180
+ * settled. A caller that held something for a phone — an offline claim (§32) —
181
+ * needs to know whether any phone was actually told, and may not block the
182
+ * caller's own path on an APNs round trip to find out. Not called when nothing
183
+ * was attempted: no sender, no target, or a rate limit that dropped this event.
184
+ */
185
+ notify(event: PushEvent, sessionId: string, onReport?: (report: PushDeliveryReport) => void): void;
186
+ }