@linxin666/dsh-remote-bridge 0.4.8 → 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 (55) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +50 -17
  3. package/README.zh.md +50 -17
  4. package/lib/client.js +274 -253
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +6690 -2277
  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/icons.d.ts +5 -13
  10. package/lib/types/client/locales.d.ts +10 -14
  11. package/lib/types/client/semantic.d.ts +9 -5
  12. package/lib/types/core/commands.d.ts +59 -0
  13. package/lib/types/core/connection.d.ts +68 -0
  14. package/lib/types/core/devices.d.ts +98 -2
  15. package/lib/types/core/hub.d.ts +65 -15
  16. package/lib/types/core/liveactivity.d.ts +324 -0
  17. package/lib/types/core/protocol.d.ts +260 -1
  18. package/lib/types/core/push.d.ts +178 -0
  19. package/lib/types/core/questions.d.ts +61 -9
  20. package/lib/types/core/session-meta.d.ts +55 -1
  21. package/lib/types/core/squads.d.ts +130 -0
  22. package/lib/types/core/usage-stats.d.ts +160 -0
  23. package/lib/types/core/usage.d.ts +294 -0
  24. package/lib/types/host/apns.d.ts +151 -0
  25. package/lib/types/host/squads-ledger.d.ts +39 -0
  26. package/lib/types/host/squads.d.ts +77 -0
  27. package/lib/types/host/usage-stats.d.ts +75 -0
  28. package/lib/types/host/watchers.d.ts +88 -0
  29. package/lib/types/index.d.ts +18 -2
  30. package/package.json +13 -13
  31. package/src/client/PairEntry.tsx +58 -31
  32. package/src/client/PairPanel.tsx +181 -97
  33. package/src/client/icons.tsx +17 -60
  34. package/src/client/locales.ts +15 -23
  35. package/src/client/panel.module.css +239 -186
  36. package/src/client/semantic.ts +10 -6
  37. package/src/core/commands.ts +95 -0
  38. package/src/core/connection.ts +646 -10
  39. package/src/core/devices.ts +221 -3
  40. package/src/core/hub.ts +362 -42
  41. package/src/core/liveactivity.ts +833 -0
  42. package/src/core/protocol.ts +294 -1
  43. package/src/core/push.ts +354 -0
  44. package/src/core/questions.ts +81 -10
  45. package/src/core/session-meta.ts +73 -1
  46. package/src/core/squads.ts +345 -0
  47. package/src/core/usage-stats.ts +424 -0
  48. package/src/core/usage.ts +937 -0
  49. package/src/core/wire.ts +8 -0
  50. package/src/host/apns.ts +320 -0
  51. package/src/host/squads-ledger.ts +105 -0
  52. package/src/host/squads.ts +206 -0
  53. package/src/host/usage-stats.ts +155 -0
  54. package/src/host/watchers.ts +272 -0
  55. package/src/index.ts +257 -8
@@ -0,0 +1,324 @@
1
+ /**
2
+ * The Live Activity half of the push channel (protocol §29).
3
+ *
4
+ * The alert channel in `core/push.ts` tells a phone something happened; a Live
5
+ * Activity is the lock-screen card that keeps being right while the app is
6
+ * suspended, which is why it is a second payload with its own rules rather than
7
+ * a field on the first one:
8
+ *
9
+ * - the request is a `liveactivity` push to a per-card APNs token, under the app
10
+ * bundle's `.push-type.liveactivity` topic, with `apns-expiration: 0` — a card
11
+ * update that arrives late is a lie about the present, so it is never resent;
12
+ * - `content-state` is the App's own `SessionActivityState`, decoded with
13
+ * ActivityKit's default Codable strategy. Timestamps in it are seconds since
14
+ * Apple's reference date (2001-01-01T00:00:00Z), never Unix seconds: a Unix
15
+ * number decodes as a date decades away and the whole card fails to decode;
16
+ * - one card shows one session. A registered card names its session, a card
17
+ * without one is never pushed to, and a state is delivered to the cards whose
18
+ * session it is about — never to "all cards", because that is how one session's
19
+ * question ends up on another session's lock screen (§29.9). `runningCount` is
20
+ * the one bridge-wide number on a card, and it stays the total on purpose;
21
+ * - one card lays out at most three rows (§30). The address is still one session
22
+ * per card — rows say what that card has to tell, not who it is sent to — and
23
+ * every card is given them the same way: the sessions waiting on the user
24
+ * first, in the order their questions arrived, then the sessions running now,
25
+ * most recently updated first. A row's name is the host's own title with its
26
+ * trailing path group taken off, because §29.5 keeps paths off a lock screen;
27
+ * - a card that would say what the card before it already said is not sent, one
28
+ * activity takes at most one update per `LIVE_ACTIVITY_INTERVAL_MS`, and
29
+ * the whole bridge at most `LIVE_ACTIVITY_PER_MINUTE` a minute. What does
30
+ * not fit is dropped, never queued: a card is a snapshot of now, and a backlog
31
+ * of stale snapshots is exactly what this channel must not deliver.
32
+ *
33
+ * Nothing here is awaited by a frame path. Every entry point returns before a
34
+ * delivery starts, and a failure — connection, 401, 410, 5xx, timeout — is one
35
+ * log line and a dropped card, never a delayed or broken follow stream (§28.5).
36
+ * @module dsh-remote-bridge/core/liveactivity
37
+ */
38
+ import type { PushSendResult } from './push.ts';
39
+ /** The phases a lock-screen card can report. */
40
+ export type SessionActivityPhase = 'running' | 'waitingForAnswer' | 'failed' | 'ended';
41
+ /** The two events one Live Activity push carries. */
42
+ export type LiveActivityEvent = 'update' | 'end';
43
+ /**
44
+ * Seconds from 1970-01-01T00:00:00Z to Apple's reference date, 2001-01-01T00:00:00Z.
45
+ *
46
+ * ActivityKit encodes a `Date` as a double relative to that reference date, so a
47
+ * value meant to decode as "now" is Unix seconds minus this offset.
48
+ */
49
+ export declare const APPLE_REFERENCE_OFFSET_SECONDS = 978307200;
50
+ /** How long after delivery iOS may still treat a card as current. */
51
+ export declare const LIVE_ACTIVITY_STALE_SECONDS = 90;
52
+ /** Shortest gap between two updates of the same activity. */
53
+ export declare const LIVE_ACTIVITY_INTERVAL_MS = 5000;
54
+ /** Most Live Activity pushes this bridge sends in any rolling minute. */
55
+ export declare const LIVE_ACTIVITY_PER_MINUTE = 30;
56
+ /** Longest option list a card carries; the App shows them as the answer choices. */
57
+ export declare const LIVE_ACTIVITY_OPTION_LIMIT = 2;
58
+ /** Most rows one card lays out; a fourth is dropped, never wrapped or paged (§30.2). */
59
+ export declare const LIVE_ACTIVITY_ROW_LIMIT = 3;
60
+ /**
61
+ * Longest row name a card carries, in characters.
62
+ *
63
+ * A row is one line under a status phrase, so a name longer than this is cut
64
+ * rather than allowed to push the rest of the card off the glass.
65
+ */
66
+ export declare const LIVE_ACTIVITY_ROW_NAME_MAX = 48;
67
+ /** Activity ids whose last content is remembered before the oldest is forgotten. */
68
+ export declare const LIVE_ACTIVITY_TRACKED = 64;
69
+ /**
70
+ * The one line a card shows per phase, in the App's own words.
71
+ *
72
+ * Fixed English strings, one per phase, and the same table the App renders
73
+ * (§29.7, §30.2): the words on the glass are the client's, so a bridge that sent
74
+ * its own would put a second language on the same card. Fixed for the second
75
+ * reason the alert channel's bodies are fixed too — a line built out of host text
76
+ * is session content on a lock screen. `core/push.ts` keeps its own localized
77
+ * bodies: a notification is read in the user's language, a card is the App's, and
78
+ * both are the same event said for two different surfaces.
79
+ */
80
+ export declare const ACTIVITY_STATUS_LINE: {
81
+ readonly running: "Running";
82
+ readonly waitingForAnswer: "Waiting for your answer";
83
+ readonly failed: "Stopped";
84
+ readonly ended: "Turn finished";
85
+ };
86
+ /**
87
+ * The fixed line one phase shows.
88
+ *
89
+ * The one accessor the single-session field and a row both go through, so a
90
+ * phase cannot be named two ways on one card.
91
+ * @param phase - the phase whose line is wanted.
92
+ * @returns the App's own English phrase for it.
93
+ */
94
+ export declare function statusLineOf(phase: SessionActivityPhase): string;
95
+ /**
96
+ * One row of the multi-session card (§30.2).
97
+ *
98
+ * Exactly three keys, all non-empty: the host's own name for the session, the
99
+ * same status phrase that session's own card would carry, and its phase. There
100
+ * is no id, no url and no count — a row is a line on a card, not a record.
101
+ *
102
+ * A row only ever carries one of the two live phases: a failed or ended turn is
103
+ * the card's own `phase`, and repeating it as a row would say one thing twice
104
+ * on a card that is already on its way out.
105
+ */
106
+ export interface ActivityRow {
107
+ readonly name: string;
108
+ readonly status: string;
109
+ readonly phase: SessionActivityPhase;
110
+ }
111
+ /**
112
+ * One card's state, as the App's own `SessionActivityState` decodes it.
113
+ *
114
+ * The key set is frozen (§29): no field may be added or renamed, because the
115
+ * App's Codable type is the other half of this contract and a key it does not
116
+ * declare fails the whole decode.
117
+ */
118
+ export interface SessionActivityState {
119
+ readonly phase: SessionActivityPhase;
120
+ readonly statusLine: string;
121
+ readonly questionHeader?: string;
122
+ readonly optionLabels?: readonly string[];
123
+ /** Apple-reference-date seconds of the moment this bridge delivered the card. */
124
+ readonly asOf: number;
125
+ /** Sessions running right now across the whole bridge, never below 1. */
126
+ readonly runningCount: number;
127
+ /**
128
+ * The sessions this card lays out, most urgent first, at most
129
+ * {@link LIVE_ACTIVITY_ROW_LIMIT} of them (§30). Absent and empty mean the
130
+ * same thing to the App: it lays out one row out of the single-session keys.
131
+ */
132
+ readonly rows?: readonly ActivityRow[];
133
+ }
134
+ /** The request body one Live Activity delivery carries (protocol §29). */
135
+ export interface LiveActivityNotification {
136
+ readonly aps: {
137
+ /** Unix epoch seconds of the delivery. */
138
+ readonly timestamp: number;
139
+ readonly event: LiveActivityEvent;
140
+ readonly 'content-state': SessionActivityState;
141
+ /** Unix epoch seconds after which the card is stale: the delivery plus 90. */
142
+ readonly 'stale-date': number;
143
+ readonly 'relevance-score': number;
144
+ /** Only an `end` for a card whose session left the roster dismisses at once. */
145
+ readonly 'dismissal-date'?: number;
146
+ };
147
+ }
148
+ /** What the projection of one delivery says, before it is dated. */
149
+ export interface LiveActivityStateInput {
150
+ readonly event: LiveActivityEvent;
151
+ readonly phase: SessionActivityPhase;
152
+ readonly statusLine: string;
153
+ readonly questionHeader?: string;
154
+ readonly optionLabels?: readonly string[];
155
+ readonly runningCount: number;
156
+ /** The rows this card lays out, already chosen, ordered and capped by the notifier. */
157
+ readonly rows?: readonly ActivityRow[];
158
+ /** Delivery moment, in milliseconds since the Unix epoch. */
159
+ readonly now: number;
160
+ /** Dismiss the card the moment it is delivered, instead of letting it expire. */
161
+ readonly dismiss?: boolean;
162
+ }
163
+ /** @returns the score iOS ranks one card of this phase by. */
164
+ export declare function relevanceScoreOf(phase: SessionActivityPhase): number;
165
+ /**
166
+ * The push one card gets.
167
+ *
168
+ * Pure, and exported so the shape can be asserted without a sender: the headers
169
+ * and this key set are the contract, and every value derived from the delivery
170
+ * moment is derived here, once.
171
+ * @param input - the projection and the delivery moment.
172
+ * @returns the exact body an APNs Live Activity delivery carries.
173
+ */
174
+ export declare function buildLiveActivityNotification(input: LiveActivityStateInput): LiveActivityNotification;
175
+ /** One card this bridge may push to. */
176
+ export interface LiveActivityAddress {
177
+ /** The activity the App created; stable for the life of one card. */
178
+ readonly activityId: string;
179
+ /** The per-card APNs token, which is not the device's token. */
180
+ readonly token: string;
181
+ /**
182
+ * The session this card shows. Absent is a card this bridge never pushes to:
183
+ * it has no state to put on it, and borrowing another session's state is
184
+ * exactly what §29.9 forbids.
185
+ */
186
+ readonly sessionId?: string;
187
+ readonly environment: 'sandbox' | 'production';
188
+ /** The app bundle id; the topic is this bundle plus the Live Activity suffix. */
189
+ readonly bundle: string;
190
+ }
191
+ /** Whatever actually reaches a card; the APNs client implements this. */
192
+ export interface LiveActivitySender {
193
+ sendLiveActivity(target: LiveActivityAddress, notification: LiveActivityNotification): Promise<PushSendResult>;
194
+ }
195
+ /** One row of a roster this bridge just served, as the projection reads it. */
196
+ export interface ActivityRosterRow {
197
+ readonly id: string;
198
+ readonly agentRunning?: boolean;
199
+ /** The host's own title for that session, the name a row carries (§26, §30.2). */
200
+ readonly title?: string;
201
+ /** When the host last updated the session, in milliseconds; 0 when it names none. */
202
+ readonly updatedAt?: number;
203
+ }
204
+ export interface LiveActivityNotifierOptions {
205
+ /** The cards that are alive right now, read per delivery. */
206
+ readonly targets: () => readonly LiveActivityAddress[];
207
+ /** The sender; absent is a bridge with no signing key, and then nothing happens. */
208
+ readonly sender?: LiveActivitySender;
209
+ readonly now?: () => number;
210
+ readonly log?: (message: string) => void;
211
+ /**
212
+ * Forget a token APNs reported dead. The roster owner removes it from the
213
+ * device row and persists, so a token that can never work again is not retried
214
+ * on every later card (§29 token lifecycle).
215
+ */
216
+ readonly retire?: (activityId: string, token: string) => Promise<boolean> | boolean | void;
217
+ readonly intervalMs?: number;
218
+ readonly perMinute?: number;
219
+ }
220
+ /**
221
+ * The bridge's Live Activity path.
222
+ *
223
+ * Deliberately inert when no sender is configured: `enabled` is false, no
224
+ * card is ever read and no clock is consulted, so a bridge without an Apple key
225
+ * behaves — byte for byte, frame for frame — exactly as it did before this
226
+ * channel existed, and `push.register` still answers the same acknowledgement
227
+ * (§28.3: registering is one thing, sending is another).
228
+ */
229
+ export declare class LiveActivityNotifier {
230
+ #private;
231
+ constructor(options: LiveActivityNotifierOptions);
232
+ /** @returns whether this bridge will actually deliver anything. */
233
+ get enabled(): boolean;
234
+ /**
235
+ * Take the roster this bridge just served as the current picture of what runs.
236
+ *
237
+ * A listing is the only place this bridge learns which sessions are live, so it
238
+ * is where each running session's own card is refreshed: that session's card is
239
+ * told it is running, and the number beside it is how many sessions are running
240
+ * in total. A card waiting on the user keeps that state — listing sessions is
241
+ * not an answer, and downgrading the card would hide the question still owed.
242
+ * @param rows - the roster rows, as this connection built them.
243
+ */
244
+ noteRoster(rows: readonly ActivityRosterRow[]): void;
245
+ /**
246
+ * Report one turn that ended.
247
+ *
248
+ * Only that session's own card is affected: the session stops running, its
249
+ * pending question is gone with the turn, and its card is ended — not updated —
250
+ * because the turn it was about is over. A session that was listed before and
251
+ * is not in the roster any more has left it, so its card is dismissed on
252
+ * delivery instead of being left on a lock screen to describe a session that no
253
+ * longer exists.
254
+ * @param sessionId - the session whose turn ended.
255
+ * @param reason - the host's own reason, read exactly as the alert channel reads it.
256
+ */
257
+ noteTurnEnd(sessionId: string, reason: string): void;
258
+ /**
259
+ * Report a question that reached a phone and is now waiting for an answer.
260
+ *
261
+ * Only the header and at most two option labels cross: they are the choices the
262
+ * App can offer. The question itself and its detail stay behind the wire, the
263
+ * same rule the alert channel follows (§28.4), and only this session's card is
264
+ * told — another session's card has no business showing this question (§29.9).
265
+ * @param sessionId - the session that asked.
266
+ * @param question - the first question of the claimed batch.
267
+ */
268
+ noteQuestion(sessionId: string, question: {
269
+ readonly header?: string;
270
+ readonly optionLabels?: readonly string[];
271
+ }): void;
272
+ /**
273
+ * Report an approval that reached a phone and is blocking the agent.
274
+ *
275
+ * The card says what state that session is in and nothing more: an approval's
276
+ * own summary is a tool's reason text, which is exactly the session content a
277
+ * lock screen must not carry, so it gets the fixed line and no details.
278
+ * @param sessionId - the session whose tool is blocked.
279
+ */
280
+ noteApproval(sessionId: string): void;
281
+ /**
282
+ * Report that the question one card was waiting on is gone — answered here, on
283
+ * the desktop, or expired.
284
+ *
285
+ * A card left saying "waiting for an answer" after the answer landed is the one
286
+ * lie a lock screen cannot afford, so that session's card goes back to whatever
287
+ * is true now. Nothing is sent when that session is not known to run: there is
288
+ * no fact to show, and the ended card already covers that case.
289
+ * @param sessionId - the session whose claim settled.
290
+ */
291
+ noteSettled(sessionId: string): void;
292
+ }
293
+ /**
294
+ * What identifies a content state for the dedupe.
295
+ *
296
+ * `asOf` is left out on purpose: it is the delivery moment, so it differs on
297
+ * every build, and including it would make "the same content was sent" impossible
298
+ * to observe — a card is a duplicate exactly when everything a user can read on
299
+ * it is unchanged. The rows are part of what a user reads (§30), so a card whose
300
+ * list of sessions reordered, was renamed or lost a row says something new.
301
+ * @param state - the content state of one delivery.
302
+ * @returns a stable key for the readable part of it.
303
+ */
304
+ export declare function contentKeyOf(state: SessionActivityState): string;
305
+ /**
306
+ * The host's own title, as one row may carry it (§30.2).
307
+ *
308
+ * The same rule the App applies to a card's own name
309
+ * (`SessionActivityDisplayName`), so one card cannot show two versions of one
310
+ * name. A roster title is usually the session's first message, and those end on
311
+ * the absolute path the session ran in — `你是本仓 (/Users/zcl/code/x)` — while
312
+ * §29.5 keeps paths off a lock screen. A trailing group whose body is a path or
313
+ * nothing therefore comes off, brackets included, and whatever it exposed is
314
+ * cleaned up after it (the separator in front of it, the bracket of the group
315
+ * before it). A group that is part of the name, `Ship (main)`, stays. What is
316
+ * left is whitespace-collapsed, trimmed of the separators and dangling brackets
317
+ * its tail may hang on, and cut to {@link LIVE_ACTIVITY_ROW_NAME_MAX}.
318
+ *
319
+ * The rule lives here and nowhere else in this bridge, so there is one answer to
320
+ * "which words of a host title may reach a lock screen".
321
+ * @param title - the title the roster carried for that session, possibly empty.
322
+ * @returns a name a row can carry, and an empty string when the title held nothing else.
323
+ */
324
+ export declare function normalizeActivityRowName(title: string): string;
@@ -19,12 +19,30 @@ 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";
28
46
  /** Server-pushed topics of protocol v1. */
29
47
  export declare const TOPIC_SESSION_DELTA = "session.delta";
30
48
  export declare const TOPIC_APPROVAL_REQUEST = "approval.request";
@@ -76,6 +94,22 @@ export declare const CAP_SESSION_SNAPSHOT_SINCE = "session.snapshot.since.v1";
76
94
  * exactly as that frame was refused before.
77
95
  */
78
96
  export declare const CAP_QUESTIONS = "questions.v1";
97
+ /**
98
+ * Capability a client declares in `hello`'s `cap` array to learn that this
99
+ * bridge can list the user questions it is still holding.
100
+ *
101
+ * An announcement rather than a switch, the same shape as
102
+ * {@link CAP_SESSION_DEEP_HISTORY}: `question.list` is reachable from every
103
+ * client that declared {@link CAP_QUESTIONS}, exactly as `question.answer` is,
104
+ * so a client written before this name existed loses nothing by declaring it
105
+ * and nothing by never calling the method. What the name buys is a way to tell
106
+ * a bridge that serves the method from one that does not: a host built before
107
+ * it answers `unknown-method`, so a client that does not find this name in
108
+ * `hello`'s `capabilities` keeps the retirement rule it had — a card is over
109
+ * when `question.request` says `settled` — instead of reaping cards on an
110
+ * answer it cannot trust.
111
+ */
112
+ export declare const CAP_QUESTION_LIST = "questions.list.v1";
79
113
  /**
80
114
  * Capability a client declares in `hello`'s `cap` array to be handed the
81
115
  * approval questions this bridge is already holding for it.
@@ -134,6 +168,71 @@ export declare const CAP_JOBS = "jobs.v1";
134
168
  * host no request.
135
169
  */
136
170
  export declare const CAP_AGENTS = "agents.v1";
171
+ /**
172
+ * Capability a client declares in `hello`'s `cap` array to read the host's
173
+ * agent squads and to drive them.
174
+ *
175
+ * Declaring it is what makes `squads.state`, `squads.list`, `squads.runs`,
176
+ * `squads.runMember` and `squads.runSquad` part of that client's protocol at
177
+ * all: a client that does not declare it — including every client written before
178
+ * this channel existed — is refused each as an unknown method, exactly as those
179
+ * frames were refused before. No command is called on a connection's behalf
180
+ * either, so a client that never asks sends the host no request.
181
+ *
182
+ * The channel is additive beside {@link CAP_AGENTS} rather than a replacement:
183
+ * a phone that predates the squad model keeps the preset roster and session
184
+ * creation it was written against, and a phone that reads this name reads the
185
+ * squad domain instead of deriving agents from anything else.
186
+ */
187
+ export declare const CAP_SQUADS = "squads.v1";
188
+ /**
189
+ * Capability a client declares in `hello`'s `cap` array to register the APNs
190
+ * token this device wants to be notified on.
191
+ *
192
+ * Declaring it is what makes `push.register` part of that client's protocol at
193
+ * all: a client that does not declare it — including every client written before
194
+ * this channel existed — is refused that frame as an unknown method, and no
195
+ * device row is written on its behalf.
196
+ *
197
+ * The name announces that this bridge can REMEMBER a token, not that it will
198
+ * send anything. Whether a notification ever leaves the process is a deployment
199
+ * fact (is an APNs signing key configured?) that the wire deliberately cannot
200
+ * express: a bridge with no key answers `ok:true` exactly like one with a key,
201
+ * because a client has no second code path to keep for the difference. Every
202
+ * notification this channel produces is an outbound APNs request and nothing
203
+ * else — no topic, no frame and no state is added to `/ios/v1` (see the
204
+ * protocol's §28).
205
+ */
206
+ export declare const CAP_PUSH = "push.v1";
207
+ /**
208
+ * 客户端在 `hello` 的 `cap` 数组里宣告它要读本桥自己的用量读数。
209
+ *
210
+ * 宣告它是 `usage.session` 与 `usage.balance` 进入这个客户端协议的唯一前提:
211
+ * 不宣告的客户端——包括这个通道出现之前写下的每一个客户端——收到的是与从前
212
+ * 逐字一样的 `unknown-method`,本桥也不会替它读一条会话、更不会替它打一次
213
+ * 上游余额端点。
214
+ *
215
+ * 一个能力名带两个方法,因为它们读的是同一件事的两面:一条会话下一次请求由
216
+ * 什么组成(上下文窗口取宿主自己广播的值,组成由本桥按文本长度估算并恒标
217
+ * `estimated: true`),以及某条 provider 路由背后账户的余额(DeepSeek 官方
218
+ * 口径,只在路由确实指向 `api.deepseek.com` 且凭据拿得到时才查官方端点,宿主
219
+ * 侧同一 provider + 凭据 60 秒最多一次上游请求)。
220
+ */
221
+ export declare const CAP_USAGE = "usage.v1";
222
+ /**
223
+ * 客户端在 `hello` 的 `cap` 数组里宣告它要读宿主自己的用量台账聚合。
224
+ *
225
+ * 与 {@link CAP_USAGE} 平级、独立声明:宣告它是 `usage.stats` 进入这个客户端
226
+ * 协议的唯一前提,不宣告的客户端——包括 `usage.v1` 出现之后、这个能力出现之前
227
+ * 写下的每一个客户端——收到的仍是 `unknown-method`,本桥也不会替它去读宿主
228
+ * 上 `dsh-usage` 插件的任何一条路由。
229
+ *
230
+ * 拆成独立能力而不是塞进 `usage.v1`,是因为它读的是另一件事:那两半读的是本
231
+ * 进程自己的事实(一个会话、一条路由的账户),这一半读的是另一个插件挂在这个
232
+ * 宿主上的 HTTP 路由,而那个插件可能根本没装。老客户端忽略这个未知名字即可,
233
+ * 它看到的能力表里多一项、别的什么都没有变。
234
+ */
235
+ export declare const CAP_USAGE_STATS = "usage.stats.v1";
137
236
  /**
138
237
  * Capability a client declares in `hello`'s `cap` array to be answered with
139
238
  * byte-level increments instead of the whole roster or the whole board.
@@ -202,6 +301,63 @@ export declare const CAP_SESSION_DEEP_HISTORY = "session.deep-history.v1";
202
301
  * re-derived here.
203
302
  */
204
303
  export declare const CAP_SESSION_FORK = "session.fork.v1";
304
+ /**
305
+ * Capability a client declares in `hello`'s `cap` array to list a session's
306
+ * slash commands and skills and to run one of them.
307
+ *
308
+ * Declaring it is what makes `session.commands` and `session.command` part of
309
+ * that client's protocol at all: a client that does not declare it — including
310
+ * every client written before this channel existed — is refused both as unknown
311
+ * methods, exactly as those frames were refused before. Neither method is called
312
+ * on a connection's behalf either, so a client that never asks costs the host no
313
+ * registry read and no skill catalog read.
314
+ *
315
+ * The channel holds no events and no cache: a directory is read live on every
316
+ * call, so a command a plugin registered a moment ago and a skill withdrawn from
317
+ * one Agent preset are both reflected in the answer that follows.
318
+ */
319
+ export declare const CAP_COMMANDS = "commands.v1";
320
+ /**
321
+ * Capability a client declares in `hello`'s `cap` array to read the host's
322
+ * workspaces and its two registry-global session sets.
323
+ *
324
+ * Declaring it is what makes `workspace.list` part of that client's protocol at
325
+ * all: a client that does not declare it — including every client written before
326
+ * this channel existed — is refused that frame as an unknown method, and no
327
+ * registry is read on its behalf. Behind the name the answer is the host's own
328
+ * synchronous projection: one row per registered workspace in registry order,
329
+ * plus the complete archive and pin sets.
330
+ *
331
+ * The method is a read and nothing is cached, so a pin or an archive followed by
332
+ * another list reads the set the write left behind. That pair of calls is the
333
+ * whole refresh story of the session-admin channel: see {@link CAP_SESSION_ADMIN}.
334
+ */
335
+ export declare const CAP_WORKSPACE = "workspace.v1";
336
+ /**
337
+ * Capability a client declares in `hello`'s `cap` array to rename, pin,
338
+ * unpin, archive and unarchive a session.
339
+ *
340
+ * Declaring it is what makes those five methods part of that client's protocol
341
+ * at all: a client that does not declare it — including every client written
342
+ * before this channel existed — is refused each as an unknown method, and no
343
+ * write is asked of the host on its behalf.
344
+ *
345
+ * Every one of the five is forwarded one-to-one to the endpoint that already
346
+ * owns the semantics, so nothing about a title, a pin or an archive is modelled
347
+ * or re-derived here: a rename reaches `session/rename` — the endpoint that
348
+ * restores a cold session before it writes, which is why a client needs no
349
+ * resume path of its own — and the four set mutations reach
350
+ * `workspace/pinSession`, `workspace/unpinSession`, `workspace/archiveSession`
351
+ * and `workspace/unarchiveSession`. A host refusal crosses with its own code
352
+ * and text, `workspace/session-active` included.
353
+ *
354
+ * The channel publishes no event, because the host announces none of these
355
+ * writes as a cordis event a connection could fold into a delta: a rename
356
+ * appends one `session/title` log record and nothing else. A client re-reads
357
+ * after a write instead — the pin set through {@link CAP_WORKSPACE}, the roster
358
+ * through `session.list` — which is why one branch serves both capabilities.
359
+ */
360
+ export declare const CAP_SESSION_ADMIN = "session.admin.v1";
205
361
  /**
206
362
  * Capability a client declares in `hello`'s `cap` array to be sent frames
207
363
  * compressed instead of as plain text.
@@ -229,6 +385,14 @@ export declare const KNOWN_METHODS: ReadonlySet<string>;
229
385
  export declare const CODE_UNPAIRED = "unpaired";
230
386
  export declare const CODE_UNKNOWN_METHOD = "unknown-method";
231
387
  export declare const CODE_INVALID_ARGS = "invalid-args";
388
+ /**
389
+ * `usage.session` 点名的会话在这个宿主上不存在:宿主自己的会话名册里没有它,
390
+ * 活会话存储里没有它,本进程也从未观察过它的任何事件。它与「会话存在但两项
391
+ * 读数都取不到」是两个答案,后者回的是空对象——一条刚刚开始、还什么都没广播
392
+ * 的会话,以及一条在桥重载前就存在的会话,都在那个状态里:存在而没读数,不是
393
+ * 不存在。
394
+ */
395
+ export declare const CODE_UNKNOWN_SESSION = "unknown-session";
232
396
  export declare const CODE_PROTO_UNSUPPORTED = "proto-unsupported";
233
397
  export declare const CODE_TOKEN_INVALID = "token-invalid";
234
398
  export declare const CODE_NONCE_INVALID = "nonce-invalid";
@@ -240,6 +404,13 @@ export declare const CODE_APPROVAL_UNKNOWN = "approval-unknown";
240
404
  * failures crossing this method keep their own codes instead.
241
405
  */
242
406
  export declare const CODE_QUESTION_UNKNOWN = "question-unknown";
407
+ /**
408
+ * The bridge could not read the questions it is holding, so it cannot say which
409
+ * ones are still live. The answer is deliberately not an empty list: a client
410
+ * retires every card a COMPLETE list does not carry, and a read that failed is
411
+ * not a complete one — it is a bridge that cannot answer this question today.
412
+ */
413
+ export declare const CODE_QUESTION_LIST_UNAVAILABLE = "question-list-unavailable";
243
414
  /**
244
415
  * The named session is a delegated child whose durable parent is not a session
245
416
  * this connection may read. The bridge follows an addressable child and refuses
@@ -253,6 +424,32 @@ export declare const CODE_SNAPSHOT_UNAVAILABLE = "snapshot-unavailable";
253
424
  * what a particular host mounts — and only a call that needs the registry fails.
254
425
  */
255
426
  export declare const CODE_JOBS_UNAVAILABLE = "jobs-unavailable";
427
+ /**
428
+ * This host serves no endpoint behind the command channel: no `commands/list`,
429
+ * no `commands/execute` or no `skills/list`, which the gateway itself reports
430
+ * as an endpoint nothing exports. The capability stays advertised — it is a fact
431
+ * about this bridge, not about what a particular host mounts — and only a call
432
+ * that needs those endpoints fails.
433
+ */
434
+ export declare const CODE_COMMANDS_UNAVAILABLE = "commands-unavailable";
435
+ /**
436
+ * This host serves no squad domain this bridge can reach: no answer to the
437
+ * plugin's state route over loopback, no readable ledger beside it, or a body
438
+ * this build cannot read as one squad domain. The capability stays advertised —
439
+ * it is a fact about this bridge, not about what a particular host mounts — and
440
+ * only a call that needs the domain fails. A refusal the `dsh-agents` plugin
441
+ * itself raised crosses with the plugin's own code instead (`team-not-found`,
442
+ * `member-not-found`, `preset-unknown`, `workspace-required` and their
443
+ * neighbours).
444
+ */
445
+ export declare const CODE_SQUADS_UNAVAILABLE = "squads-unavailable";
446
+ /**
447
+ * The definitions are readable but the two run commands cannot be served: this
448
+ * host answered no run route over loopback, and the read-only ledger fallback
449
+ * cannot launch anything. Failing closed is the point — a client is told the
450
+ * capability is not served here rather than shown a run that never started.
451
+ */
452
+ export declare const CODE_SQUADS_RUN_UNAVAILABLE = "squads-run-unavailable";
256
453
  export declare const CODE_SNAPSHOT_TOO_LARGE = "snapshot-too-large";
257
454
  export declare const CODE_INTERNAL = "internal";
258
455
  /** Protocol version this package speaks. */
@@ -260,6 +457,68 @@ export declare const PROTO = 1;
260
457
  /**
261
458
  * Minor version this package speaks.
262
459
  *
460
+ * 20 when the usage stats channel shipped: behind {@link CAP_USAGE_STATS} a
461
+ * client may call {@link METHOD_USAGE_STATS} and read the host's own usage
462
+ * ledger — today, this month and one row per local day — and behind the same
463
+ * {@link CAP_USAGE} this bridge now also answers `usage.session` with a
464
+ * `modelContextWindow` when the model catalog of the session's route declares
465
+ * one, so a client reads one new reply body and one new optional key off the
466
+ * wire and has to read the name before it asks. The stats half is independent
467
+ * of {@link CAP_USAGE} on purpose: it reads another plugin's HTTP routes, which
468
+ * a host may not mount at all, so a client written before this name existed
469
+ * keeps the two readings it had and the bridge reads no route on its behalf.
470
+ * No frame, no topic, no existing method and no existing key changes shape.
471
+ * 19 when the usage channel shipped: behind {@link CAP_USAGE} a client may call
472
+ * {@link METHOD_USAGE_SESSION} and read one session's context window and its
473
+ * request's estimated composition, and {@link METHOD_USAGE_BALANCE} and read the
474
+ * account behind one provider route, so it reads two new reply bodies off the
475
+ * wire and has to read the name before it asks — a bridge below this one answers
476
+ * `unknown-method` for both. No frame, no topic and no existing method changes
477
+ * shape.
478
+ * 18 when one card learned to lay out several sessions (§30 of
479
+ * `docs/protocol-v1.md` in the iphone_remote_use_dsh repository): `content-state`
480
+ * gains the optional `rows` key, so a phone reads up to three sessions off one
481
+ * lock-screen card instead of having to hold one card per session. It is a pure
482
+ * addition — no new method, no new capability name, no existing key or topic
483
+ * changes shape — so the minor counts the key alone, and a client that reads 18
484
+ * knows the order of the rows it is handed is the bridge's rather than one it
485
+ * has to derive.
486
+ * 17 when the live-activity channel shipped (§29.2): this bridge now sends the
487
+ * lock-screen card a suspended app cannot update itself, addressed to the
488
+ * per-card APNs tokens {@link METHOD_PUSH_REGISTER} already carries and projected
489
+ * per session rather than per bridge. It is a pure addition — no new method, no
490
+ * new capability name, and no existing frame, field or topic changes shape — so
491
+ * the minor counts it alone: a client that wants a card has to read 17 before it
492
+ * registers one, because a bridge below this one has no sending path at all and
493
+ * would answer `ok:true` to a registration it can never use.
494
+ * 16 when the push channel shipped: behind {@link CAP_PUSH} a client may call
495
+ * {@link METHOD_PUSH_REGISTER} and have the device table remember an APNs token,
496
+ * so a phone learns a turn ended — or that a question is waiting — while its
497
+ * socket is not open. No frame, no topic and no existing method changes shape;
498
+ * the minor is raised because a new reply body and a new announcement appear on
499
+ * the wire, and because a client has to read the name before it registers.
500
+ * 15 when the squads channel shipped: behind {@link CAP_SQUADS} a client may
501
+ * call {@link METHOD_SQUADS_STATE}, {@link METHOD_SQUADS_LIST},
502
+ * {@link METHOD_SQUADS_RUNS}, {@link METHOD_SQUADS_RUN_MEMBER} and
503
+ * {@link METHOD_SQUADS_RUN_SQUAD}, so it reads five new reply bodies off the wire
504
+ * and drives the squad domain instead of deriving its agents from anything else.
505
+ * 14 when the session-admin channel shipped: behind {@link CAP_WORKSPACE} a
506
+ * client may call {@link METHOD_WORKSPACE_LIST} and read the host's workspaces
507
+ * with both registry-global session sets, and behind {@link CAP_SESSION_ADMIN}
508
+ * it may call {@link METHOD_SESSION_RENAME}, {@link METHOD_SESSION_PIN},
509
+ * {@link METHOD_SESSION_UNPIN}, {@link METHOD_SESSION_ARCHIVE} and
510
+ * {@link METHOD_SESSION_UNARCHIVE}, so a phone long-presses a roster row for the
511
+ * same five actions the desktop offers it.
512
+ * 13 when the question list shipped: behind {@link CAP_QUESTION_LIST} a client
513
+ * may call {@link METHOD_QUESTION_LIST} and be answered the questions this
514
+ * bridge is still holding, so it reads a new reply body off the wire and the
515
+ * number rises with it. It is what lets a phone stop trusting a card it holds:
516
+ * the one retirement signal before it was `question.request` with
517
+ * `state: "settled"`, which a phone that was disconnected when the last client
518
+ * left never receives.
519
+ * 12 when the command channel shipped: behind {@link CAP_COMMANDS} a client may
520
+ * call {@link METHOD_SESSION_COMMANDS} and {@link METHOD_SESSION_COMMAND}, so it
521
+ * reads a new reply body off the wire and the number rises with it.
263
522
  * 11 when the fork channel shipped: behind {@link CAP_SESSION_FORK} a client may
264
523
  * call {@link METHOD_SESSION_FORK} and receive the host's own fork answer, so a
265
524
  * phone branches a session that inherits the context of the one it forked. This
@@ -302,7 +561,7 @@ export declare const PROTO = 1;
302
561
  * declares the capability that plugin requires. No addition changed the major
303
562
  * version, a frozen field, or an existing method or topic name.
304
563
  */
305
- export declare const MINOR = 11;
564
+ export declare const MINOR = 20;
306
565
  /**
307
566
  * The capabilities this bridge itself serves, as `hello` advertises them.
308
567
  *