@linxin666/dsh-remote-bridge 0.4.7 → 0.4.9

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 (78) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +93 -26
  3. package/README.zh.md +91 -26
  4. package/icon.svg +3 -0
  5. package/lib/client.js +274 -253
  6. package/lib/client.js.map +1 -1
  7. package/lib/index.js +8891 -2433
  8. package/lib/types/client/PairEntry.d.ts +2 -2
  9. package/lib/types/client/PairPanel.d.ts +10 -2
  10. package/lib/types/client/icons.d.ts +5 -13
  11. package/lib/types/client/locales.d.ts +10 -14
  12. package/lib/types/client/semantic.d.ts +9 -5
  13. package/lib/types/core/approvals.d.ts +24 -0
  14. package/lib/types/core/commands.d.ts +59 -0
  15. package/lib/types/core/connection.d.ts +124 -5
  16. package/lib/types/core/delta.d.ts +101 -0
  17. package/lib/types/core/devices.d.ts +98 -2
  18. package/lib/types/core/dsh-frames.d.ts +155 -4
  19. package/lib/types/core/envelope.d.ts +34 -0
  20. package/lib/types/core/extension.d.ts +144 -0
  21. package/lib/types/core/hub.d.ts +96 -20
  22. package/lib/types/core/jobs.d.ts +204 -0
  23. package/lib/types/core/liveactivity.d.ts +324 -0
  24. package/lib/types/core/protocol.d.ts +491 -2
  25. package/lib/types/core/push.d.ts +178 -0
  26. package/lib/types/core/questions.d.ts +109 -9
  27. package/lib/types/core/session-meta.d.ts +55 -1
  28. package/lib/types/core/squads.d.ts +130 -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/core/wire.d.ts +1 -1
  32. package/lib/types/core/ws-frames.d.ts +11 -0
  33. package/lib/types/host/apns.d.ts +151 -0
  34. package/lib/types/host/squads-ledger.d.ts +39 -0
  35. package/lib/types/host/squads.d.ts +77 -0
  36. package/lib/types/host/usage-stats.d.ts +75 -0
  37. package/lib/types/host/watchers.d.ts +88 -0
  38. package/lib/types/host/websocket.d.ts +8 -1
  39. package/lib/types/index.d.ts +34 -3
  40. package/lib/types/mount-once.d.ts +55 -0
  41. package/locale/en.json +6 -0
  42. package/locale/ru.json +6 -0
  43. package/locale/zh.json +6 -0
  44. package/package.json +20 -14
  45. package/src/client/PairEntry.tsx +58 -31
  46. package/src/client/PairPanel.tsx +181 -97
  47. package/src/client/icons.tsx +17 -60
  48. package/src/client/locales.ts +15 -23
  49. package/src/client/panel.module.css +239 -186
  50. package/src/client/semantic.ts +10 -6
  51. package/src/core/approvals.ts +32 -1
  52. package/src/core/commands.ts +95 -0
  53. package/src/core/connection.ts +1483 -31
  54. package/src/core/delta.ts +204 -0
  55. package/src/core/devices.ts +221 -3
  56. package/src/core/dsh-frames.ts +365 -8
  57. package/src/core/envelope.ts +46 -0
  58. package/src/core/extension.ts +197 -0
  59. package/src/core/hub.ts +441 -49
  60. package/src/core/jobs.ts +372 -0
  61. package/src/core/liveactivity.ts +833 -0
  62. package/src/core/protocol.ts +556 -2
  63. package/src/core/push.ts +354 -0
  64. package/src/core/questions.ts +264 -17
  65. package/src/core/session-meta.ts +73 -1
  66. package/src/core/squads.ts +345 -0
  67. package/src/core/usage-stats.ts +424 -0
  68. package/src/core/usage.ts +937 -0
  69. package/src/core/wire.ts +13 -1
  70. package/src/core/ws-frames.ts +14 -0
  71. package/src/host/apns.ts +320 -0
  72. package/src/host/squads-ledger.ts +105 -0
  73. package/src/host/squads.ts +206 -0
  74. package/src/host/usage-stats.ts +155 -0
  75. package/src/host/watchers.ts +272 -0
  76. package/src/host/websocket.ts +37 -3
  77. package/src/index.ts +310 -9
  78. package/src/mount-once.ts +142 -0
@@ -10,6 +10,7 @@ export const METHOD_SESSION_LIST = 'session.list'
10
10
  export const METHOD_SESSION_TITLES = 'session.titles'
11
11
  export const METHOD_SESSION_SNAPSHOT = 'session.snapshot'
12
12
  export const METHOD_SESSION_HISTORY = 'session.history'
13
+ export const METHOD_SESSION_HISTORY_DEEP = 'session.history.deep'
13
14
  export const METHOD_SESSION_PROMPT = 'session.prompt'
14
15
  export const METHOD_SESSION_INTERRUPT = 'session.interrupt'
15
16
  export const METHOD_SESSION_ATTACHMENT = 'session.attachment'
@@ -17,15 +18,38 @@ export const METHOD_SESSION_PERMISSIONS = 'session.permissions'
17
18
  export const METHOD_SESSION_SET_PERMISSION = 'session.setPermission'
18
19
  export const METHOD_SESSION_MODELS = 'session.models'
19
20
  export const METHOD_SESSION_SET_MODEL = 'session.setModel'
21
+ export const METHOD_SESSION_CREATE = 'session.create'
22
+ export const METHOD_SESSION_FORK = 'session.fork'
23
+ export const METHOD_SESSION_COMMANDS = 'session.commands'
24
+ export const METHOD_SESSION_COMMAND = 'session.command'
25
+ export const METHOD_SESSION_RENAME = 'session.rename'
26
+ export const METHOD_SESSION_PIN = 'session.pin'
27
+ export const METHOD_SESSION_UNPIN = 'session.unpin'
28
+ export const METHOD_SESSION_ARCHIVE = 'session.archive'
29
+ export const METHOD_SESSION_UNARCHIVE = 'session.unarchive'
30
+ export const METHOD_WORKSPACE_LIST = 'workspace.list'
31
+ export const METHOD_PRESETS_LIST = 'presets.list'
20
32
  export const METHOD_PAIR_BEGIN = 'pair.begin'
21
33
  export const METHOD_PAIR_FINISH = 'pair.finish'
22
34
  export const METHOD_APPROVAL_RESOLVE = 'approval.resolve'
23
35
  export const METHOD_QUESTION_ANSWER = 'question.answer'
36
+ export const METHOD_QUESTION_LIST = 'question.list'
37
+ export const METHOD_JOBS_LIST = 'jobs.list'
38
+ export const METHOD_SQUADS_STATE = 'squads.state'
39
+ export const METHOD_SQUADS_LIST = 'squads.list'
40
+ export const METHOD_SQUADS_RUNS = 'squads.runs'
41
+ export const METHOD_SQUADS_RUN_MEMBER = 'squads.runMember'
42
+ export const METHOD_SQUADS_RUN_SQUAD = 'squads.runSquad'
43
+ export const METHOD_PUSH_REGISTER = 'push.register'
44
+ export const METHOD_USAGE_SESSION = 'usage.session'
45
+ export const METHOD_USAGE_BALANCE = 'usage.balance'
46
+ export const METHOD_USAGE_STATS = 'usage.stats'
24
47
 
25
48
  /** Server-pushed topics of protocol v1. */
26
49
  export const TOPIC_SESSION_DELTA = 'session.delta'
27
50
  export const TOPIC_APPROVAL_REQUEST = 'approval.request'
28
51
  export const TOPIC_QUESTION_REQUEST = 'question.request'
52
+ export const TOPIC_JOBS_CHANGED = 'jobs.changed'
29
53
 
30
54
  /**
31
55
  * Capability a client declares in `hello`'s `cap` array to ask for a trimmed
@@ -45,6 +69,26 @@ export const CAP_SESSION_SNAPSHOT_TRIM = 'session.snapshot.trim.v1'
45
69
  */
46
70
  export const CAP_SESSION_SNAPSHOT_PAGE = 'session.snapshot.page.v1'
47
71
 
72
+ /**
73
+ * Capability a client declares in `hello`'s `cap` array to have
74
+ * `session.snapshot` answer a reconnect with only what it missed.
75
+ *
76
+ * The declaration and the request's `sinceSeq` are what it takes together: a
77
+ * snapshot that carries no `sinceSeq` is answered, byte for byte, the body
78
+ * protocol v1 always served, whether or not the client declared this. Behind
79
+ * both, the client names the durable `lastSeq` of a snapshot it already holds
80
+ * and the answer is either that same reply in an incremental form —
81
+ * `{turns, lastSeq, mode:"since", reset:false}` carrying only the entries above
82
+ * that watermark — or a full baseline with `mode:"full"` and `reset:true`,
83
+ * which is the one answer that tells a client to throw its copy away. The
84
+ * estimate is only served when the bridge can PROVE nothing was lost: the
85
+ * current follow window's oldest entry must sit at or below `sinceSeq + 1`, so a
86
+ * window that has already scrolled past the watermark answers the baseline
87
+ * instead of a delta with a hole in it. It exists because a reconnect on the
88
+ * phone re-paid 0.86-1.06 s of baseline five times in one measured run.
89
+ */
90
+ export const CAP_SESSION_SNAPSHOT_SINCE = 'session.snapshot.since.v1'
91
+
48
92
  /**
49
93
  * Capability a client declares in `hello`'s `cap` array to be shown the
50
94
  * host's pending user questions and to answer them with `question.answer`.
@@ -57,6 +101,303 @@ export const CAP_SESSION_SNAPSHOT_PAGE = 'session.snapshot.page.v1'
57
101
  */
58
102
  export const CAP_QUESTIONS = 'questions.v1'
59
103
 
104
+ /**
105
+ * Capability a client declares in `hello`'s `cap` array to learn that this
106
+ * bridge can list the user questions it is still holding.
107
+ *
108
+ * An announcement rather than a switch, the same shape as
109
+ * {@link CAP_SESSION_DEEP_HISTORY}: `question.list` is reachable from every
110
+ * client that declared {@link CAP_QUESTIONS}, exactly as `question.answer` is,
111
+ * so a client written before this name existed loses nothing by declaring it
112
+ * and nothing by never calling the method. What the name buys is a way to tell
113
+ * a bridge that serves the method from one that does not: a host built before
114
+ * it answers `unknown-method`, so a client that does not find this name in
115
+ * `hello`'s `capabilities` keeps the retirement rule it had — a card is over
116
+ * when `question.request` says `settled` — instead of reaping cards on an
117
+ * answer it cannot trust.
118
+ */
119
+ export const CAP_QUESTION_LIST = 'questions.list.v1'
120
+
121
+ /**
122
+ * Capability a client declares in `hello`'s `cap` array to be handed the
123
+ * approval questions this bridge is already holding for it.
124
+ *
125
+ * Unlike every channel capability beside it, this one gates a second delivery
126
+ * rather than the channel: `approval.request` still reaches every paired
127
+ * connection the moment a tool asks, exactly as it did before this name
128
+ * existed, because gating the first broadcast would take approvals away from
129
+ * every client written before the capability. What the declaration buys is the
130
+ * replay — after a reconnect, or on a session screen opened late, the client is
131
+ * handed the questions that are still waiting instead of a card it never saw.
132
+ * Only a live claim is replayed: a question that was answered, that the bridge
133
+ * timed out, or that was withdrawn with the last phone is gone from the claim
134
+ * registry before the replay reads it.
135
+ *
136
+ * It is deliberately absent from {@link SERVED_CAPABILITIES}: that list is what
137
+ * `hello` advertises as served, advertising a capability is a minor-version
138
+ * addition (see {@link MINOR}), and this channel changes nothing a client can
139
+ * observe in the handshake — no answer, no field and no method behind it. The
140
+ * declaration is the whole switch, and the name reaches a client through this
141
+ * bridge's own protocol documentation.
142
+ */
143
+ export const CAP_APPROVALS = 'approvals.v1'
144
+
145
+ /**
146
+ * Capability a client declares in `hello`'s `cap` array to be told where a
147
+ * message came from and that an agent spawned a child session.
148
+ *
149
+ * Declaring it is what makes the `subagent` delta part of that client's
150
+ * protocol: a client that does not declare it — including every client written
151
+ * before this channel existed — receives no such event, exactly as that frame
152
+ * was dropped before. The `actor` of a `user-message` is not gated: it is an
153
+ * additive field a client that does not read it ignores.
154
+ */
155
+ export const CAP_SUBAGENT_THREAD = 'subagent.thread.v1'
156
+
157
+ /**
158
+ * Capability a client declares in `hello`'s `cap` array to see the host's
159
+ * background jobs and to be told when the set changes.
160
+ *
161
+ * Declaring it is what makes `jobs.list` reachable, and `jobs.list` is the only
162
+ * thing that opens a roster: a connection that declares this capability but
163
+ * never asks for a scope receives no `jobs.changed` at all. A client that does
164
+ * not declare it — including every client written before this channel existed —
165
+ * receives no such event, and its `jobs.list` is refused as an unknown method,
166
+ * exactly as that frame was refused before.
167
+ */
168
+ export const CAP_JOBS = 'jobs.v1'
169
+
170
+ /**
171
+ * Capability a client declares in `hello`'s `cap` array to read the host's
172
+ * Agent presets and to instantiate one as a session.
173
+ *
174
+ * Declaring it is what makes `presets.list` and `session.create` part of that
175
+ * client's protocol at all: a client that does not declare it — including every
176
+ * client written before this channel existed — is refused both as unknown
177
+ * methods, exactly as those frames were refused before. Neither method is
178
+ * called on a connection's behalf either, so a client that never asks sends the
179
+ * host no request.
180
+ */
181
+ export const CAP_AGENTS = 'agents.v1'
182
+
183
+ /**
184
+ * Capability a client declares in `hello`'s `cap` array to read the host's
185
+ * agent squads and to drive them.
186
+ *
187
+ * Declaring it is what makes `squads.state`, `squads.list`, `squads.runs`,
188
+ * `squads.runMember` and `squads.runSquad` part of that client's protocol at
189
+ * all: a client that does not declare it — including every client written before
190
+ * this channel existed — is refused each as an unknown method, exactly as those
191
+ * frames were refused before. No command is called on a connection's behalf
192
+ * either, so a client that never asks sends the host no request.
193
+ *
194
+ * The channel is additive beside {@link CAP_AGENTS} rather than a replacement:
195
+ * a phone that predates the squad model keeps the preset roster and session
196
+ * creation it was written against, and a phone that reads this name reads the
197
+ * squad domain instead of deriving agents from anything else.
198
+ */
199
+ export const CAP_SQUADS = 'squads.v1'
200
+
201
+ /**
202
+ * Capability a client declares in `hello`'s `cap` array to register the APNs
203
+ * token this device wants to be notified on.
204
+ *
205
+ * Declaring it is what makes `push.register` part of that client's protocol at
206
+ * all: a client that does not declare it — including every client written before
207
+ * this channel existed — is refused that frame as an unknown method, and no
208
+ * device row is written on its behalf.
209
+ *
210
+ * The name announces that this bridge can REMEMBER a token, not that it will
211
+ * send anything. Whether a notification ever leaves the process is a deployment
212
+ * fact (is an APNs signing key configured?) that the wire deliberately cannot
213
+ * express: a bridge with no key answers `ok:true` exactly like one with a key,
214
+ * because a client has no second code path to keep for the difference. Every
215
+ * notification this channel produces is an outbound APNs request and nothing
216
+ * else — no topic, no frame and no state is added to `/ios/v1` (see the
217
+ * protocol's §28).
218
+ */
219
+ export const CAP_PUSH = 'push.v1'
220
+
221
+ /**
222
+ * 客户端在 `hello` 的 `cap` 数组里宣告它要读本桥自己的用量读数。
223
+ *
224
+ * 宣告它是 `usage.session` 与 `usage.balance` 进入这个客户端协议的唯一前提:
225
+ * 不宣告的客户端——包括这个通道出现之前写下的每一个客户端——收到的是与从前
226
+ * 逐字一样的 `unknown-method`,本桥也不会替它读一条会话、更不会替它打一次
227
+ * 上游余额端点。
228
+ *
229
+ * 一个能力名带两个方法,因为它们读的是同一件事的两面:一条会话下一次请求由
230
+ * 什么组成(上下文窗口取宿主自己广播的值,组成由本桥按文本长度估算并恒标
231
+ * `estimated: true`),以及某条 provider 路由背后账户的余额(DeepSeek 官方
232
+ * 口径,只在路由确实指向 `api.deepseek.com` 且凭据拿得到时才查官方端点,宿主
233
+ * 侧同一 provider + 凭据 60 秒最多一次上游请求)。
234
+ */
235
+ export const CAP_USAGE = 'usage.v1'
236
+
237
+ /**
238
+ * 客户端在 `hello` 的 `cap` 数组里宣告它要读宿主自己的用量台账聚合。
239
+ *
240
+ * 与 {@link CAP_USAGE} 平级、独立声明:宣告它是 `usage.stats` 进入这个客户端
241
+ * 协议的唯一前提,不宣告的客户端——包括 `usage.v1` 出现之后、这个能力出现之前
242
+ * 写下的每一个客户端——收到的仍是 `unknown-method`,本桥也不会替它去读宿主
243
+ * 上 `dsh-usage` 插件的任何一条路由。
244
+ *
245
+ * 拆成独立能力而不是塞进 `usage.v1`,是因为它读的是另一件事:那两半读的是本
246
+ * 进程自己的事实(一个会话、一条路由的账户),这一半读的是另一个插件挂在这个
247
+ * 宿主上的 HTTP 路由,而那个插件可能根本没装。老客户端忽略这个未知名字即可,
248
+ * 它看到的能力表里多一项、别的什么都没有变。
249
+ */
250
+ export const CAP_USAGE_STATS = 'usage.stats.v1'
251
+
252
+ /**
253
+ * Capability a client declares in `hello`'s `cap` array to be answered with
254
+ * byte-level increments instead of the whole roster or the whole board.
255
+ *
256
+ * Behind it, `session.list` and `board.snapshot` (the latter through the board
257
+ * plugin, §15) accept an opaque `since` token and answer either the whole set
258
+ * (`mode:"reset"`) or only what changed since the set that token names. A
259
+ * client that does not declare it — including every client written before this
260
+ * channel existed — is answered today's body plus the ignorable `mode` and
261
+ * `token` keys, with `mode` always `"reset"`.
262
+ */
263
+ export const CAP_DELTA = 'delta.v1'
264
+
265
+ /**
266
+ * Capability a client declares in `hello`'s `cap` array to be told that an
267
+ * archived session is not in the roster at all.
268
+ *
269
+ * Unlike every capability beside it this one negotiates nothing: the bridge
270
+ * never transfers an archived session, whether or not a client declares it, so
271
+ * an older client simply receives the shorter roster it would have hidden
272
+ * anyway. The name is an announcement of that fact, so a client can stop
273
+ * filtering for itself: behind it, no `session.list` row is a session the
274
+ * host's archive set names, a row that does survive still carries
275
+ * `archived: false` under the same schema, and a live child of an archived
276
+ * parent still crosses with its `parentSessionId` — the parent id, not the
277
+ * parent row.
278
+ */
279
+ export const CAP_ROSTER_OMITS_ARCHIVED = 'session.list.omit-archived.v1'
280
+
281
+ /**
282
+ * Capability a client declares in `hello`'s `cap` array to be answered a
283
+ * compact roster it can page.
284
+ *
285
+ * The declaration alone changes nothing: a listing that carries none of the
286
+ * compact parameters (`cwd`, `maxRows`, `after`) is answered exactly the body
287
+ * protocol v1 always served, so a client can opt into the name before it
288
+ * relies on any of it. Behind the parameters, a row drops its absolute `cwd`
289
+ * unless the request asks for it, drops its `updatedAt` when this connection
290
+ * already sent that id the same value, and a `maxRows`/`after` pair cuts the
291
+ * roster into pages ordered most recent first. The roster is the most repeated
292
+ * large reply on the link, so this is what lets a reconnect pay for the newest
293
+ * screenful plus a cursor instead of the whole list again.
294
+ */
295
+ export const CAP_ROSTER_COMPACT = 'session.list.compact.v1'
296
+
297
+ /**
298
+ * Capability a client declares in `hello`'s `cap` array to be told that this
299
+ * bridge can page a session's durable history down to its oldest entry.
300
+ *
301
+ * The capability is an announcement and nothing more. `session.history.deep` is
302
+ * open to every paired connection, exactly as `session.history` is, because it
303
+ * is a pure read of the session store that costs no other client anything;
304
+ * declaring the capability is how a client learns the method exists, and a
305
+ * client that does not declare it loses only that knowledge.
306
+ */
307
+ export const CAP_SESSION_DEEP_HISTORY = 'session.deep-history.v1'
308
+
309
+ /**
310
+ * Capability a client declares in `hello`'s `cap` array to fork a session.
311
+ *
312
+ * Declaring it is what makes `session.fork` part of that client's protocol at
313
+ * all: a client that does not declare it — including every client written
314
+ * before this channel existed — is refused `unknown-method`, and no fork is
315
+ * asked of the host on its behalf. Behind the name the bridge forwards one
316
+ * `SessionForkRequest` to the host's `session/fork` and hands back the host's
317
+ * own `SessionForkValue`, so what a fork point means stays the host's: an
318
+ * `atSeq` is the source event seq the fork includes, an omitted one is the
319
+ * newest finished turn, and a cut the host opens itself is closed by the host's
320
+ * own synthetic finishing event. Nothing about a fork is modelled or
321
+ * re-derived here.
322
+ */
323
+ export const CAP_SESSION_FORK = 'session.fork.v1'
324
+
325
+ /**
326
+ * Capability a client declares in `hello`'s `cap` array to list a session's
327
+ * slash commands and skills and to run one of them.
328
+ *
329
+ * Declaring it is what makes `session.commands` and `session.command` part of
330
+ * that client's protocol at all: a client that does not declare it — including
331
+ * every client written before this channel existed — is refused both as unknown
332
+ * methods, exactly as those frames were refused before. Neither method is called
333
+ * on a connection's behalf either, so a client that never asks costs the host no
334
+ * registry read and no skill catalog read.
335
+ *
336
+ * The channel holds no events and no cache: a directory is read live on every
337
+ * call, so a command a plugin registered a moment ago and a skill withdrawn from
338
+ * one Agent preset are both reflected in the answer that follows.
339
+ */
340
+ export const CAP_COMMANDS = 'commands.v1'
341
+
342
+ /**
343
+ * Capability a client declares in `hello`'s `cap` array to read the host's
344
+ * workspaces and its two registry-global session sets.
345
+ *
346
+ * Declaring it is what makes `workspace.list` part of that client's protocol at
347
+ * all: a client that does not declare it — including every client written before
348
+ * this channel existed — is refused that frame as an unknown method, and no
349
+ * registry is read on its behalf. Behind the name the answer is the host's own
350
+ * synchronous projection: one row per registered workspace in registry order,
351
+ * plus the complete archive and pin sets.
352
+ *
353
+ * The method is a read and nothing is cached, so a pin or an archive followed by
354
+ * another list reads the set the write left behind. That pair of calls is the
355
+ * whole refresh story of the session-admin channel: see {@link CAP_SESSION_ADMIN}.
356
+ */
357
+ export const CAP_WORKSPACE = 'workspace.v1'
358
+
359
+ /**
360
+ * Capability a client declares in `hello`'s `cap` array to rename, pin,
361
+ * unpin, archive and unarchive a session.
362
+ *
363
+ * Declaring it is what makes those five methods part of that client's protocol
364
+ * at all: a client that does not declare it — including every client written
365
+ * before this channel existed — is refused each as an unknown method, and no
366
+ * write is asked of the host on its behalf.
367
+ *
368
+ * Every one of the five is forwarded one-to-one to the endpoint that already
369
+ * owns the semantics, so nothing about a title, a pin or an archive is modelled
370
+ * or re-derived here: a rename reaches `session/rename` — the endpoint that
371
+ * restores a cold session before it writes, which is why a client needs no
372
+ * resume path of its own — and the four set mutations reach
373
+ * `workspace/pinSession`, `workspace/unpinSession`, `workspace/archiveSession`
374
+ * and `workspace/unarchiveSession`. A host refusal crosses with its own code
375
+ * and text, `workspace/session-active` included.
376
+ *
377
+ * The channel publishes no event, because the host announces none of these
378
+ * writes as a cordis event a connection could fold into a delta: a rename
379
+ * appends one `session/title` log record and nothing else. A client re-reads
380
+ * after a write instead — the pin set through {@link CAP_WORKSPACE}, the roster
381
+ * through `session.list` — which is why one branch serves both capabilities.
382
+ */
383
+ export const CAP_SESSION_ADMIN = 'session.admin.v1'
384
+
385
+ /**
386
+ * Capability a client declares in `hello`'s `cap` array to be sent frames
387
+ * compressed instead of as plain text.
388
+ *
389
+ * Declaring it is what allows the host to compress at all: a frame whose JSON
390
+ * text is at least 1024 UTF-8 bytes crosses as one WebSocket binary frame
391
+ * carrying raw DEFLATE (RFC 1951) of exactly that text, and a frame that does
392
+ * not get smaller still crosses as the text frame it always was. A client that
393
+ * does not declare it — including every client written before this capability
394
+ * existed — receives byte for byte the text frames protocol v1 always wrote.
395
+ *
396
+ * The direction is one way: a client still sends text frames only, and the
397
+ * 10 MiB frame cap stays measured on the text, before inflation.
398
+ */
399
+ export const CAP_FRAME_DEFLATE = 'frame.deflate.v1'
400
+
60
401
  /**
61
402
  * Methods an unpaired connection may still call: the handshake itself and the
62
403
  * two pairing steps. Everything else answers `unpaired` — a caller can pair
@@ -75,6 +416,7 @@ export const KNOWN_METHODS: ReadonlySet<string> = new Set([
75
416
  METHOD_SESSION_TITLES,
76
417
  METHOD_SESSION_SNAPSHOT,
77
418
  METHOD_SESSION_HISTORY,
419
+ METHOD_SESSION_HISTORY_DEEP,
78
420
  METHOD_SESSION_PROMPT,
79
421
  METHOD_SESSION_INTERRUPT,
80
422
  METHOD_SESSION_ATTACHMENT,
@@ -86,12 +428,42 @@ export const KNOWN_METHODS: ReadonlySet<string> = new Set([
86
428
  METHOD_PAIR_FINISH,
87
429
  METHOD_APPROVAL_RESOLVE,
88
430
  METHOD_QUESTION_ANSWER,
431
+ METHOD_QUESTION_LIST,
432
+ METHOD_JOBS_LIST,
433
+ METHOD_PRESETS_LIST,
434
+ METHOD_SESSION_CREATE,
435
+ METHOD_SESSION_FORK,
436
+ METHOD_SESSION_COMMANDS,
437
+ METHOD_SESSION_COMMAND,
438
+ METHOD_SESSION_RENAME,
439
+ METHOD_SESSION_PIN,
440
+ METHOD_SESSION_UNPIN,
441
+ METHOD_SESSION_ARCHIVE,
442
+ METHOD_SESSION_UNARCHIVE,
443
+ METHOD_WORKSPACE_LIST,
444
+ METHOD_SQUADS_STATE,
445
+ METHOD_SQUADS_LIST,
446
+ METHOD_SQUADS_RUNS,
447
+ METHOD_SQUADS_RUN_MEMBER,
448
+ METHOD_SQUADS_RUN_SQUAD,
449
+ METHOD_PUSH_REGISTER,
450
+ METHOD_USAGE_SESSION,
451
+ METHOD_USAGE_BALANCE,
452
+ METHOD_USAGE_STATS,
89
453
  ])
90
454
 
91
455
  /** Refusal codes the bridge itself raises (DSH failures cross as their own code). */
92
456
  export const CODE_UNPAIRED = 'unpaired'
93
457
  export const CODE_UNKNOWN_METHOD = 'unknown-method'
94
458
  export const CODE_INVALID_ARGS = 'invalid-args'
459
+ /**
460
+ * `usage.session` 点名的会话在这个宿主上不存在:宿主自己的会话名册里没有它,
461
+ * 活会话存储里没有它,本进程也从未观察过它的任何事件。它与「会话存在但两项
462
+ * 读数都取不到」是两个答案,后者回的是空对象——一条刚刚开始、还什么都没广播
463
+ * 的会话,以及一条在桥重载前就存在的会话,都在那个状态里:存在而没读数,不是
464
+ * 不存在。
465
+ */
466
+ export const CODE_UNKNOWN_SESSION = 'unknown-session'
95
467
  export const CODE_PROTO_UNSUPPORTED = 'proto-unsupported'
96
468
  export const CODE_TOKEN_INVALID = 'token-invalid'
97
469
  export const CODE_NONCE_INVALID = 'nonce-invalid'
@@ -103,14 +475,196 @@ export const CODE_APPROVAL_UNKNOWN = 'approval-unknown'
103
475
  * failures crossing this method keep their own codes instead.
104
476
  */
105
477
  export const CODE_QUESTION_UNKNOWN = 'question-unknown'
478
+ /**
479
+ * The bridge could not read the questions it is holding, so it cannot say which
480
+ * ones are still live. The answer is deliberately not an empty list: a client
481
+ * retires every card a COMPLETE list does not carry, and a read that failed is
482
+ * not a complete one — it is a bridge that cannot answer this question today.
483
+ */
484
+ export const CODE_QUESTION_LIST_UNAVAILABLE = 'question-list-unavailable'
485
+ /**
486
+ * The named session is a delegated child whose durable parent is not a session
487
+ * this connection may read. The bridge follows an addressable child and refuses
488
+ * an unaddressable one, rather than reading it blind.
489
+ */
490
+ export const CODE_SESSION_NOT_FOLLOWABLE = 'session-not-followable'
106
491
  export const CODE_SNAPSHOT_UNAVAILABLE = 'snapshot-unavailable'
492
+ /**
493
+ * This host composes no job registry, so it has no background jobs to publish.
494
+ * The capability stays advertised — it is a fact about this bridge, not about
495
+ * what a particular host mounts — and only a call that needs the registry fails.
496
+ */
497
+ export const CODE_JOBS_UNAVAILABLE = 'jobs-unavailable'
498
+ /**
499
+ * This host serves no endpoint behind the command channel: no `commands/list`,
500
+ * no `commands/execute` or no `skills/list`, which the gateway itself reports
501
+ * as an endpoint nothing exports. The capability stays advertised — it is a fact
502
+ * about this bridge, not about what a particular host mounts — and only a call
503
+ * that needs those endpoints fails.
504
+ */
505
+ export const CODE_COMMANDS_UNAVAILABLE = 'commands-unavailable'
506
+ /**
507
+ * This host serves no squad domain this bridge can reach: no answer to the
508
+ * plugin's state route over loopback, no readable ledger beside it, or a body
509
+ * this build cannot read as one squad domain. The capability stays advertised —
510
+ * it is a fact about this bridge, not about what a particular host mounts — and
511
+ * only a call that needs the domain fails. A refusal the `dsh-agents` plugin
512
+ * itself raised crosses with the plugin's own code instead (`team-not-found`,
513
+ * `member-not-found`, `preset-unknown`, `workspace-required` and their
514
+ * neighbours).
515
+ */
516
+ export const CODE_SQUADS_UNAVAILABLE = 'squads-unavailable'
517
+ /**
518
+ * The definitions are readable but the two run commands cannot be served: this
519
+ * host answered no run route over loopback, and the read-only ledger fallback
520
+ * cannot launch anything. Failing closed is the point — a client is told the
521
+ * capability is not served here rather than shown a run that never started.
522
+ */
523
+ export const CODE_SQUADS_RUN_UNAVAILABLE = 'squads-run-unavailable'
107
524
  export const CODE_SNAPSHOT_TOO_LARGE = 'snapshot-too-large'
108
525
  export const CODE_INTERNAL = 'internal'
109
526
 
110
527
  /** Protocol version this package speaks. */
111
528
  export const PROTO = 1
112
- /** Minor version this package speaks. */
113
- export const MINOR = 0
529
+ /**
530
+ * Minor version this package speaks.
531
+ *
532
+ * 20 when the usage stats channel shipped: behind {@link CAP_USAGE_STATS} a
533
+ * client may call {@link METHOD_USAGE_STATS} and read the host's own usage
534
+ * ledger — today, this month and one row per local day — and behind the same
535
+ * {@link CAP_USAGE} this bridge now also answers `usage.session` with a
536
+ * `modelContextWindow` when the model catalog of the session's route declares
537
+ * one, so a client reads one new reply body and one new optional key off the
538
+ * wire and has to read the name before it asks. The stats half is independent
539
+ * of {@link CAP_USAGE} on purpose: it reads another plugin's HTTP routes, which
540
+ * a host may not mount at all, so a client written before this name existed
541
+ * keeps the two readings it had and the bridge reads no route on its behalf.
542
+ * No frame, no topic, no existing method and no existing key changes shape.
543
+ * 19 when the usage channel shipped: behind {@link CAP_USAGE} a client may call
544
+ * {@link METHOD_USAGE_SESSION} and read one session's context window and its
545
+ * request's estimated composition, and {@link METHOD_USAGE_BALANCE} and read the
546
+ * account behind one provider route, so it reads two new reply bodies off the
547
+ * wire and has to read the name before it asks — a bridge below this one answers
548
+ * `unknown-method` for both. No frame, no topic and no existing method changes
549
+ * shape.
550
+ * 18 when one card learned to lay out several sessions (§30 of
551
+ * `docs/protocol-v1.md` in the iphone_remote_use_dsh repository): `content-state`
552
+ * gains the optional `rows` key, so a phone reads up to three sessions off one
553
+ * lock-screen card instead of having to hold one card per session. It is a pure
554
+ * addition — no new method, no new capability name, no existing key or topic
555
+ * changes shape — so the minor counts the key alone, and a client that reads 18
556
+ * knows the order of the rows it is handed is the bridge's rather than one it
557
+ * has to derive.
558
+ * 17 when the live-activity channel shipped (§29.2): this bridge now sends the
559
+ * lock-screen card a suspended app cannot update itself, addressed to the
560
+ * per-card APNs tokens {@link METHOD_PUSH_REGISTER} already carries and projected
561
+ * per session rather than per bridge. It is a pure addition — no new method, no
562
+ * new capability name, and no existing frame, field or topic changes shape — so
563
+ * the minor counts it alone: a client that wants a card has to read 17 before it
564
+ * registers one, because a bridge below this one has no sending path at all and
565
+ * would answer `ok:true` to a registration it can never use.
566
+ * 16 when the push channel shipped: behind {@link CAP_PUSH} a client may call
567
+ * {@link METHOD_PUSH_REGISTER} and have the device table remember an APNs token,
568
+ * so a phone learns a turn ended — or that a question is waiting — while its
569
+ * socket is not open. No frame, no topic and no existing method changes shape;
570
+ * the minor is raised because a new reply body and a new announcement appear on
571
+ * the wire, and because a client has to read the name before it registers.
572
+ * 15 when the squads channel shipped: behind {@link CAP_SQUADS} a client may
573
+ * call {@link METHOD_SQUADS_STATE}, {@link METHOD_SQUADS_LIST},
574
+ * {@link METHOD_SQUADS_RUNS}, {@link METHOD_SQUADS_RUN_MEMBER} and
575
+ * {@link METHOD_SQUADS_RUN_SQUAD}, so it reads five new reply bodies off the wire
576
+ * and drives the squad domain instead of deriving its agents from anything else.
577
+ * 14 when the session-admin channel shipped: behind {@link CAP_WORKSPACE} a
578
+ * client may call {@link METHOD_WORKSPACE_LIST} and read the host's workspaces
579
+ * with both registry-global session sets, and behind {@link CAP_SESSION_ADMIN}
580
+ * it may call {@link METHOD_SESSION_RENAME}, {@link METHOD_SESSION_PIN},
581
+ * {@link METHOD_SESSION_UNPIN}, {@link METHOD_SESSION_ARCHIVE} and
582
+ * {@link METHOD_SESSION_UNARCHIVE}, so a phone long-presses a roster row for the
583
+ * same five actions the desktop offers it.
584
+ * 13 when the question list shipped: behind {@link CAP_QUESTION_LIST} a client
585
+ * may call {@link METHOD_QUESTION_LIST} and be answered the questions this
586
+ * bridge is still holding, so it reads a new reply body off the wire and the
587
+ * number rises with it. It is what lets a phone stop trusting a card it holds:
588
+ * the one retirement signal before it was `question.request` with
589
+ * `state: "settled"`, which a phone that was disconnected when the last client
590
+ * left never receives.
591
+ * 12 when the command channel shipped: behind {@link CAP_COMMANDS} a client may
592
+ * call {@link METHOD_SESSION_COMMANDS} and {@link METHOD_SESSION_COMMAND}, so it
593
+ * reads a new reply body off the wire and the number rises with it.
594
+ * 11 when the fork channel shipped: behind {@link CAP_SESSION_FORK} a client may
595
+ * call {@link METHOD_SESSION_FORK} and receive the host's own fork answer, so a
596
+ * phone branches a session that inherits the context of the one it forked. This
597
+ * is the second of two appends cut from 9 — the snapshot-`since` channel took
598
+ * 10 on the integration branch first — so the number steps over the one already
599
+ * on `dev`: the minor counts additions to this protocol, and a later landing
600
+ * steps over the earlier one instead of reusing its number.
601
+ * 10 when the snapshot became incremental on request: behind
602
+ * {@link CAP_SESSION_SNAPSHOT_SINCE} a `session.snapshot` that names `sinceSeq`
603
+ * is answered either the entries above that watermark or a full baseline
604
+ * carrying `mode` and `reset`, so a client reads a new reply shape off the
605
+ * wire and the number rises with it.
606
+ * 9 when the compact roster shipped: behind {@link CAP_ROSTER_COMPACT} a
607
+ * `session.list` that names one of the compact parameters is answered a
608
+ * shorter row and may be cut into pages, so a client reads a new row schema
609
+ * off the wire and the number rises with it.
610
+ * 8 when the outbound frame form became a capability: behind
611
+ * {@link CAP_FRAME_DEFLATE} a declaring client may be answered in binary
612
+ * frames carrying raw DEFLATE of the text, so the minor is raised for a change
613
+ * a client reads off the wire rather than for a name alone.
614
+ * 7 when the two channels met: the agent channel and the durable history
615
+ * channel each raised 5 to 6 on its own branch, so the protocol that carries
616
+ * both is 7. 6 when the agent channel shipped: behind {@link CAP_AGENTS}
617
+ * `presets.list` forwards the host's Agent-preset roster and `session.create`
618
+ * hands the host one creation request, both verbatim. 6 was also the durable
619
+ * history channel on its own: behind {@link CAP_SESSION_DEEP_HISTORY} a client
620
+ * may call {@link METHOD_SESSION_HISTORY_DEEP} and walk a session's store back
621
+ * to its oldest entry, below the follow window `session.history` slices. 5 when
622
+ * the roster stopped carrying archived sessions: behind
623
+ * {@link CAP_ROSTER_OMITS_ARCHIVED} `session.list` names no session the host's
624
+ * archive set holds, so a session archived between two listings arrives as a
625
+ * removal and one restored as a change. 4 when byte-level increments shipped:
626
+ * behind {@link CAP_DELTA} `session.list` and `board.snapshot` answer a reset
627
+ * or a delta against a `since` token. 3 was
628
+ * the background-job channel — behind {@link CAP_JOBS} a client may call
629
+ * `jobs.list` and receive `jobs.changed`. 2 was the subagent thread —
630
+ * a `user-message` delta may carry an `actor` and a `subagent` delta exists
631
+ * behind {@link CAP_SUBAGENT_THREAD}. 1 was the extension seam — a mounted
632
+ * plugin may answer methods outside {@link KNOWN_METHODS} once the client
633
+ * declares the capability that plugin requires. No addition changed the major
634
+ * version, a frozen field, or an existing method or topic name.
635
+ */
636
+ export const MINOR = 20
637
+
638
+ /**
639
+ * The capabilities this bridge itself serves, as `hello` advertises them.
640
+ *
641
+ * A capability a mounted plugin adds is not listed here: the bridge cannot know
642
+ * what it is not the author of. A client learns such a capability from the
643
+ * plugin's own documentation, exactly as it did before this list existed.
644
+ */
645
+ export const SERVED_CAPABILITIES: readonly string[] = [
646
+ CAP_SESSION_SNAPSHOT_TRIM,
647
+ CAP_SESSION_SNAPSHOT_PAGE,
648
+ CAP_QUESTIONS,
649
+ CAP_QUESTION_LIST,
650
+ CAP_SUBAGENT_THREAD,
651
+ CAP_JOBS,
652
+ CAP_AGENTS,
653
+ CAP_DELTA,
654
+ CAP_ROSTER_OMITS_ARCHIVED,
655
+ CAP_SESSION_DEEP_HISTORY,
656
+ CAP_FRAME_DEFLATE,
657
+ CAP_ROSTER_COMPACT,
658
+ CAP_SESSION_SNAPSHOT_SINCE,
659
+ CAP_SESSION_FORK,
660
+ CAP_COMMANDS,
661
+ CAP_WORKSPACE,
662
+ CAP_SESSION_ADMIN,
663
+ CAP_SQUADS,
664
+ CAP_PUSH,
665
+ CAP_USAGE,
666
+ CAP_USAGE_STATS,
667
+ ]
114
668
  /** `server` field of the hello response. */
115
669
  export const SERVER_ID = 'dsh-remote-bridge'
116
670