@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
@@ -0,0 +1,178 @@
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;
20
+ * - a failed delivery is logged and dropped. Nothing here is awaited by the
21
+ * delta path, so a broken APNs connection cannot delay, reorder or suppress a
22
+ * frame that a connected phone is waiting for.
23
+ * @module dsh-remote-bridge/core/push
24
+ */
25
+ /** One thing a notification can be about. */
26
+ export type PushEvent = 'turn-end' | 'turn-error' | 'question' | 'approval';
27
+ /** Window inside which the same `(sessionId, event)` is one notification. */
28
+ export declare const PUSH_DEDUPE_MS = 30000;
29
+ /** Shortest gap between two notifications about the same session. */
30
+ export declare const PUSH_SESSION_INTERVAL_MS = 10000;
31
+ /** Most notifications this bridge sends in any rolling minute. */
32
+ export declare const PUSH_GLOBAL_PER_MINUTE = 30;
33
+ /** Sessions whose workspace short name is remembered for the payload. */
34
+ export declare const PUSH_WORKSPACE_LIMIT = 512;
35
+ /** The only deep-link form this channel emits. */
36
+ export declare const PUSH_DEEP_LINK_PREFIX = "whale://session/";
37
+ /** One device a notification can be addressed to. */
38
+ export interface PushAddress {
39
+ readonly deviceToken: string;
40
+ readonly environment: 'sandbox' | 'production';
41
+ readonly bundle: string;
42
+ readonly locale?: string;
43
+ }
44
+ /** The request body one APNs delivery carries (protocol §28.4). */
45
+ export interface PushNotification {
46
+ readonly aps: {
47
+ readonly alert: {
48
+ readonly title: string;
49
+ readonly body: string;
50
+ };
51
+ readonly sound: 'default';
52
+ };
53
+ /** Workspace short name; absent when this bridge cannot resolve one. */
54
+ readonly w?: string;
55
+ readonly s: string;
56
+ readonly st: PushEvent;
57
+ readonly url: string;
58
+ }
59
+ /** What one delivery attempt reported. */
60
+ export interface PushSendResult {
61
+ readonly ok: boolean;
62
+ /** The status APNs answered, when it answered at all. */
63
+ readonly status?: number;
64
+ /** The reason APNs named, or this bridge's own note. */
65
+ readonly reason?: string;
66
+ }
67
+ /** One delivery a sender refused, in the words the bridge needs to read it. */
68
+ export interface PushDeliveryFailure {
69
+ /** The registration APNs refused: the roster row holding it is a device that no longer exists. */
70
+ readonly deviceToken: string;
71
+ /** The status APNs answered, when it answered at all. */
72
+ readonly status?: number;
73
+ /** The reason APNs named, or this bridge's own note. */
74
+ readonly reason?: string;
75
+ }
76
+ /** What one {@link PushNotifier.notify} ended up doing, once every attempt settled. */
77
+ export interface PushDeliveryReport {
78
+ /** How many devices took the notification. */
79
+ readonly delivered: number;
80
+ /** Every attempt that did not land, in target order. */
81
+ readonly failures: readonly PushDeliveryFailure[];
82
+ }
83
+ /**
84
+ * @param failure - one refused delivery.
85
+ * @returns whether the registration behind it is dead for good.
86
+ *
87
+ * APNs says a token will never work again in three ways: 410 with
88
+ * `Unregistered`, and 400 with `Unregistered` or `BadDeviceToken`. All three are
89
+ * final facts about the registration — the app was removed, or this token belongs
90
+ * to another environment or bundle — so it is cleaned up instead of retried, and
91
+ * a claim held for it is a claim held for a phone that cannot come back.
92
+ */
93
+ export declare function isDeadPushToken(failure: PushDeliveryFailure): boolean;
94
+ /** Whatever actually reaches a device; the APNs client implements this. */
95
+ export interface PushSender {
96
+ send(target: PushAddress, notification: PushNotification): Promise<PushSendResult>;
97
+ }
98
+ /** What the payload builder may say about one session. */
99
+ export interface PushLabels {
100
+ readonly title?: string;
101
+ readonly workspace?: string;
102
+ }
103
+ export interface PushNotifierOptions {
104
+ /** The devices that asked to be notified, read per event. */
105
+ readonly targets: () => readonly PushAddress[];
106
+ /** The sender; absent is a bridge with no signing key, and then nothing happens. */
107
+ readonly sender?: PushSender;
108
+ /** The session's own title (§26's source), read per event. */
109
+ readonly titles?: (sessionId: string) => string | undefined;
110
+ readonly now?: () => number;
111
+ readonly log?: (message: string) => void;
112
+ readonly dedupeMs?: number;
113
+ readonly sessionIntervalMs?: number;
114
+ readonly globalPerMinute?: number;
115
+ }
116
+ /**
117
+ * The notification the channel sends for one event (protocol §28.4).
118
+ *
119
+ * Pure, and exported so the shape can be asserted without a sender: the keys
120
+ * are the contract, and the absence of any body text is the property that
121
+ * matters most.
122
+ * @param event - what happened.
123
+ * @param sessionId - the session it happened to.
124
+ * @param labels - the name and workspace short name, when the bridge holds them.
125
+ * @returns the exact payload an APNs delivery carries.
126
+ */
127
+ export declare function buildPushNotification(event: PushEvent, sessionId: string, labels?: PushLabels): PushNotification;
128
+ /**
129
+ * Which event one `turn-end` delta is.
130
+ * @param reason - the host's own reason for ending the turn.
131
+ * @returns the normal end for `completed`, the abnormal one for every other
132
+ * value — including `unknown`, which is what an unreadable reason reports.
133
+ */
134
+ export declare function pushEventOfTurnEnd(reason: string): PushEvent;
135
+ /**
136
+ * The bridge's outbound notification path.
137
+ *
138
+ * Deliberately inert when no sender is configured: {@link enabled} is false, no
139
+ * target is ever read and no clock is ever consulted, so an unconfigured bridge
140
+ * behaves — byte for byte, frame for frame — exactly as it did before this
141
+ * channel existed.
142
+ */
143
+ export declare class PushNotifier {
144
+ #private;
145
+ constructor(options: PushNotifierOptions);
146
+ /** @returns whether this bridge will actually deliver anything. */
147
+ get enabled(): boolean;
148
+ /**
149
+ * Remember the workspace each session belongs to, from a roster this bridge
150
+ * just served.
151
+ *
152
+ * A notification's `w` is the only label the bridge cannot read from the
153
+ * title service, and asking the host for a roster on every turn end would put
154
+ * a gateway call on the notification path. The rows are already in hand when a
155
+ * phone lists them, so the short name is picked up there and kept bounded; a
156
+ * session never listed simply gets a payload without `w`.
157
+ * @param rows - the roster rows that were just built for a client.
158
+ */
159
+ noteSessions(rows: readonly {
160
+ readonly id: string;
161
+ readonly cwd?: string;
162
+ }[]): void;
163
+ /**
164
+ * Announce one event to every registered device.
165
+ *
166
+ * Returns before anything is sent: delivery starts on a fresh microtask, so a
167
+ * caller on the delta path never awaits an APNs round trip and a sender that
168
+ * throws cannot reach it.
169
+ * @param event - what happened.
170
+ * @param sessionId - the session it happened to.
171
+ * @param onReport - receives how the announcement ended, once every attempt has
172
+ * settled. A caller that held something for a phone — an offline claim (§32) —
173
+ * needs to know whether any phone was actually told, and may not block the
174
+ * caller's own path on an APNs round trip to find out. Not called when nothing
175
+ * was attempted: no sender, no target, or a rate limit that dropped this event.
176
+ */
177
+ notify(event: PushEvent, sessionId: string, onReport?: (report: PushDeliveryReport) => void): void;
178
+ }
@@ -30,6 +30,13 @@
30
30
  * delegated to `next()`, never answered with a decision the operator did not
31
31
  * make.
32
32
  *
33
+ * A timed ask's deadline is read back from the host itself
34
+ * (`userQuestions/attachWait`) and published as `expiresAt`, so the phone can
35
+ * count down the wait the host is actually serving. Holding that subscription
36
+ * parks the host's own deadline timer, so this module also has to let go at the
37
+ * instant the deadline it learned has passed: only then does the host raise
38
+ * `ASK_TIMED_OUT` and hand the claim its `continued` state.
39
+ *
33
40
  * The types below mirror `@deepseek-ai/dsh-user-questions` field for field. The
34
41
  * package is not a dependency of this one (it is the host's, not the bridge's),
35
42
  * so the contract is declared locally instead of imported.
@@ -60,12 +67,59 @@ export interface QuestionAnswerItem {
60
67
  export interface QuestionAnswer {
61
68
  readonly answers: readonly QuestionAnswerItem[];
62
69
  }
70
+ /**
71
+ * The `question.request` payload for one claim, and the `payload` of every
72
+ * `question.list` entry.
73
+ *
74
+ * One function for both so the card a phone was handed and the card it reads back
75
+ * out of a list cannot drift apart: `expiresAt` appears only once the claim
76
+ * learned the host's own deadline, and a blocking ask publishes no such key at
77
+ * all rather than an empty or null one.
78
+ * @param state - whether the foreground ask still holds the question.
79
+ * @param question - the claim being published.
80
+ * @returns the frozen payload body.
81
+ */
82
+ export declare function questionPayload(state: QuestionState, question: ClaimedQuestionView): QuestionRequestPayload;
83
+ /**
84
+ * The identity a client knows one question card by.
85
+ *
86
+ * The same `sessionId/callId` pair the phone already derives for its own card,
87
+ * so a list entry and the card it describes are compared as one name instead of
88
+ * two fields that could be recombined differently on each side.
89
+ * @param sessionId - the session that asked.
90
+ * @param callId - the wire call id the client answers with.
91
+ * @returns the card key.
92
+ */
93
+ export declare function questionKey(sessionId: string, callId: string): string;
94
+ /** One question this bridge still holds, as `question.list` publishes it. */
95
+ export interface ListedQuestion {
96
+ /** {@link questionKey}: the card identity the client holds it under. */
97
+ readonly key: string;
98
+ readonly sessionId: string;
99
+ /** `open` or `continued`; a settled question is not held and never listed. */
100
+ readonly state: QuestionState;
101
+ /** The `question.request` payload, byte for byte the shape that channel froze. */
102
+ readonly payload: QuestionRequestPayload;
103
+ }
104
+ /**
105
+ * The body of one `question.list` answer.
106
+ *
107
+ * `complete` is what a client is allowed to act on: only a complete list may
108
+ * retire a card it does not carry, so a bridge that could answer only part of the
109
+ * set must say `false` rather than let the difference read as "the question is
110
+ * over".
111
+ */
112
+ export interface QuestionListPayload {
113
+ readonly questions: readonly ListedQuestion[];
114
+ readonly complete: boolean;
115
+ }
63
116
  /** Whether a question still holds the foreground ask, or only its late reply. */
64
117
  /**
65
118
  * `open` while the ask is still waiting, `continued` once the host's foreground
66
119
  * wait ended but a late answer can still be steered in, and `settled` as the
67
- * one-way notice that the phone's card is over — the host's own UI answered it or
68
- * the last paired client left. `settled` is published, never held.
120
+ * one-way notice that the phone's card is over — the host's own UI answered it, or
121
+ * none was left to answer it once the claim's grace window ended. `settled` is
122
+ * published, never held.
69
123
  */
70
124
  export type QuestionState = 'open' | 'continued' | 'settled';
71
125
  /** `question.request`'s payload, as frozen by the contract. */
@@ -103,11 +157,29 @@ export interface ClaimedQuestionView {
103
157
  readonly sessionId: string;
104
158
  readonly callId: string;
105
159
  readonly questions: readonly QuestionItem[];
160
+ /**
161
+ * Epoch milliseconds at which the host's own deadline falls — the absolute
162
+ * form of the remaining wait the host reported through `attachWait`.
163
+ *
164
+ * Absent when the host said nothing: a blocking ask has no deadline at all,
165
+ * and a timed one is only known once a wait frame arrived.
166
+ */
167
+ readonly expiresAt?: number;
106
168
  }
107
169
  /** One claim the hub holds while the host's ask is still open. */
108
170
  export interface ClaimedQuestion extends ClaimedQuestionView {
109
171
  /** The host's ask: the phone's answer, or whatever the next answerer says. */
110
172
  readonly answer: Promise<QuestionAnswer>;
173
+ /**
174
+ * Epoch milliseconds at which the host's own deadline falls, from the first
175
+ * wait frame of this claim.
176
+ *
177
+ * Resolves undefined when there is no deadline to publish — a blocking ask, a
178
+ * failed subscription, or a stream that ended before its first frame — and
179
+ * never rejects: a phone must be shown the question whether or not the host
180
+ * would say how long it has.
181
+ */
182
+ readonly deadline: Promise<number | undefined>;
111
183
  }
112
184
  /** What one `question.answer` produced: acknowledgement, or the refusal to send. */
113
185
  export type QuestionReply = {
@@ -130,6 +202,15 @@ export declare const QUESTION_TIMED_OUT_CODE = "ASK_TIMED_OUT";
130
202
  export declare const MINTED_CALL_ID_PREFIX = "bridge:";
131
203
  /** Entropy of one minted call id. */
132
204
  export declare const MINTED_CALL_ID_BYTES = 16;
205
+ /**
206
+ * How often at most a phone is told that the host's deadline moved, in
207
+ * milliseconds.
208
+ *
209
+ * The host re-reports its remaining wait on every touch of the wait, which can
210
+ * be far more often than a countdown needs; one update per second keeps the
211
+ * wire quiet without the phone ever showing a stale second.
212
+ */
213
+ export declare const QUESTION_WAIT_BROADCAST_MIN_INTERVAL_MS = 1000;
133
214
  export interface OpenQuestionInput {
134
215
  readonly sessionId: string;
135
216
  /** The id published on the wire: the host's own, or one this bridge minted. */
@@ -148,6 +229,15 @@ export interface OpenQuestionInput {
148
229
  readonly signal?: AbortSignal;
149
230
  /** Called once when the host's deadline released the model but the question stayed answerable. */
150
231
  readonly onContinued?: (question: ClaimedQuestionView) => void;
232
+ /**
233
+ * Called when a later wait frame moved the host's deadline, so a phone that
234
+ * already holds the card can update it in place.
235
+ *
236
+ * The first frame is not reported here: it is what {@link ClaimedQuestion.deadline}
237
+ * hands the hub for the question's own first broadcast, so reporting it would
238
+ * publish the same deadline twice.
239
+ */
240
+ readonly onDeadline?: (question: ClaimedQuestionView) => void;
151
241
  /**
152
242
  * Called when the claim leaves this bridge without the phone answering it — the
153
243
  * host's own UI answered first, or the last paired client went away. The phone
@@ -163,6 +253,11 @@ export interface QuestionClaimsOptions {
163
253
  readonly log: (message: string) => void;
164
254
  /** Id source, injectable so a test can answer the exact id it was given. */
165
255
  readonly random?: (byteLength: number) => string;
256
+ /**
257
+ * Clock the deadline bookkeeping reads, injectable so a suite can move the
258
+ * remaining wait instead of sleeping through it.
259
+ */
260
+ readonly now?: () => number;
166
261
  }
167
262
  /**
168
263
  * Project a host question into the contract's own fields.
@@ -212,13 +307,17 @@ export declare class QuestionClaims {
212
307
  */
213
308
  answer(sessionId: string, callId: string, answer: QuestionAnswer): Promise<QuestionReply>;
214
309
  /**
215
- * Every claim still waiting on an answer.
310
+ * Every question this bridge still holds, as `question.list` publishes it.
216
311
  *
217
- * A phone that connects after the question was raised never saw the original
218
- * broadcast, so it has to be handed the live claims again — otherwise the
219
- * question sits on the host with an answerable card nowhere.
312
+ * The claim registry IS the answer: a question leaves it the moment it is
313
+ * answered, settled by the host's own UI, withdrawn with the last paired phone
314
+ * or expired, so a card missing from this list is a card no one can answer any
315
+ * more. Both live states are listed — `continued` is still answerable through
316
+ * the host's late-answer path — and a settled question is never here, because
317
+ * it is never held.
318
+ * @returns one entry per held claim, in claim order.
220
319
  */
221
- openClaims(): readonly ClaimedQuestionView[];
320
+ listed(): readonly ListedQuestion[];
222
321
  /**
223
322
  * Withdraw the named questions, delegating each to the next answerer.
224
323
  * @returns how many were still open and therefore delegated.
@@ -226,8 +325,9 @@ export declare class QuestionClaims {
226
325
  withdraw(callIds: readonly string[]): number;
227
326
  /**
228
327
  * Withdraw every claim, delegating each open question to the next answerer.
229
- * Called when the last paired phone goes away and when the bridge unloads: a
230
- * question nobody can answer must not hold the agent until its own deadline.
328
+ * Called when the last paired phone has been gone long enough that no grace
329
+ * window is still running, and when the bridge unloads: a question nobody can
330
+ * answer must not hold the agent until its own deadline.
231
331
  * @returns how many questions were still open.
232
332
  */
233
333
  withdrawAll(): number;
@@ -32,18 +32,56 @@ export interface SessionTitleFace {
32
32
  export interface ArchiveSetFace {
33
33
  readonly archivedSessionIds: readonly string[];
34
34
  }
35
+ /**
36
+ * One workspace registration, as far as `workspace.list` publishes it.
37
+ *
38
+ * The host's entity carries more — its `sessionIds` account above all — and the
39
+ * face deliberately does not declare it: a row this bridge publishes must not be
40
+ * able to carry an array that grows with the session count.
41
+ */
42
+ export interface WorkspaceFace {
43
+ readonly id: string;
44
+ readonly path: string;
45
+ readonly title: string;
46
+ readonly createdAt?: string;
47
+ readonly updatedAt?: string;
48
+ }
49
+ /**
50
+ * The slice of `ctx.workspaceRegistry` `workspace.list` reads: the registry
51
+ * itself.
52
+ *
53
+ * Wider than {@link ArchiveSetFace} by the ordered projection and the pin set,
54
+ * because one method publishes all three: a client pins a session and reads
55
+ * both sets back in one frame. Every member is synchronous — `list()` answers a
56
+ * fresh array and both sets are getters over the durable registry — which is
57
+ * what lets the answer be built without awaiting anything.
58
+ */
59
+ export interface WorkspacesFace extends ArchiveSetFace {
60
+ list(): readonly WorkspaceFace[];
61
+ readonly pinnedSessionIds: readonly string[];
62
+ }
63
+ /** The body `workspace.list` answers. */
64
+ export interface WorkspaceListAnswer {
65
+ readonly workspaces: readonly WorkspaceFace[];
66
+ readonly archivedSessionIds: readonly string[];
67
+ readonly pinnedSessionIds: readonly string[];
68
+ }
35
69
  /**
36
70
  * The in-process services one metadata read may use.
37
71
  *
38
72
  * Every field is optional on purpose. The bridge does not require the title or
39
73
  * workspace plugins to be installed — the protocol's roster and title methods
40
74
  * stay answerable with them absent, and a field that is missing degrades one
41
- * key of one row instead of failing a method.
75
+ * key of one row instead of failing a method. `workspaces` is the member that
76
+ * breaks that rule on purpose: `workspace.list` exists only to publish the
77
+ * registry, so its absence is reported as a host without one rather than
78
+ * answered with an empty list.
42
79
  */
43
80
  export interface SessionMetaFaces {
44
81
  readonly sessions?: SessionStoreFace | undefined;
45
82
  readonly titles?: SessionTitleFace | undefined;
46
83
  readonly archive?: ArchiveSetFace | undefined;
84
+ readonly workspaces?: WorkspacesFace | undefined;
47
85
  }
48
86
  /** Largest id batch one `session.titles` call accepts. */
49
87
  export declare const TITLES_MAX_IDS = 100;
@@ -102,4 +140,20 @@ export declare class SessionMeta {
102
140
  * @returns the archived session ids, or undefined when the registry is unavailable.
103
141
  */
104
142
  archiveSet(): ReadonlySet<string> | undefined;
143
+ /**
144
+ * The host's workspaces and its two registry-global session sets.
145
+ *
146
+ * One synchronous projection and nothing more: `list()` already answers a
147
+ * fresh array in registry order, and both sets are getters over the durable
148
+ * registry, so this read awaits nothing, opens no follow stream and touches no
149
+ * persistence. Workspaces are neither sorted nor filtered — the registry's own
150
+ * order is the display order — and a row carries exactly the fields protocol
151
+ * v1 names, `sessionIds` never among them.
152
+ *
153
+ * An unmounted registry answers undefined instead of an empty list: "this host
154
+ * has no workspaces" and "this host has no registry to ask" are two different
155
+ * facts, and only the caller can say which one it must report.
156
+ * @returns the answer, or undefined when this host composes no workspace registry.
157
+ */
158
+ workspaceList(): WorkspaceListAnswer | undefined;
105
159
  }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The squads channel: the squad domain of the `dsh-agents` plugin — its
3
+ * definitions and the runs that launch sessions — as a phone reads and drives
4
+ * it.
5
+ *
6
+ * Nothing about a squad is modelled here. A squad is the plugin's own team row
7
+ * with the definition timestamps dropped, a run is the plugin's own run record
8
+ * with the goal it was given dropped, and a refusal the plugin raised crosses
9
+ * with the plugin's own code. What this module owns is the mapping onto the
10
+ * frozen `squads.v1` bodies plus the transport seam a Host half implements to
11
+ * reach the domain.
12
+ *
13
+ * The seam answers the plugin's rows unread (`unknown`), so one mapping serves
14
+ * both ways a Host can reach them: the plugin's HTTP routes over loopback, and
15
+ * the read-only ledger fallback. A row this build cannot read is refused rather
16
+ * than repaired, because a repaired squad is a squad the user never wrote.
17
+ * @module dsh-remote-bridge/core/squads
18
+ */
19
+ /**
20
+ * Every method the squads capability puts in a client's protocol. The gate in
21
+ * `connection.ts` reads this set once, so a method added beside these is gated
22
+ * by the same declaration rather than by a second list to keep in step.
23
+ */
24
+ export declare const SQUAD_METHODS: ReadonlySet<string>;
25
+ /** Sandbox modes a member may pin; the DSH permission presets, as the plugin spells them. */
26
+ export type SquadMemberPermission = 'read-only' | 'workspace-write' | 'danger-full-access';
27
+ /** One member of a squad: a display name and the pins its session is composed from. */
28
+ export interface SquadMember {
29
+ id: string;
30
+ name: string;
31
+ preset?: string;
32
+ permission?: SquadMemberPermission;
33
+ model?: string;
34
+ reasoningEffort?: string;
35
+ brief?: string;
36
+ }
37
+ /** One squad: an ordered set of member definitions sharing a workspace. */
38
+ export interface Squad {
39
+ id: string;
40
+ name: string;
41
+ description?: string;
42
+ workspaceId?: string;
43
+ leadPreset?: string;
44
+ order?: number;
45
+ members: SquadMember[];
46
+ }
47
+ /** One launched session: a member session, or the Lead session of a whole squad. */
48
+ export interface SquadRun {
49
+ id: string;
50
+ squadId: string;
51
+ kind: 'squad' | 'member';
52
+ memberId?: string;
53
+ sessionId: string;
54
+ createdAt: number;
55
+ status: 'running' | 'settled' | 'failed';
56
+ failure?: string;
57
+ }
58
+ /** The `squads.state` body: definitions, run history, the offered presets and the owning pid. */
59
+ export interface SquadsState {
60
+ squads: Squad[];
61
+ runs: SquadRun[];
62
+ presets?: string[];
63
+ host: {
64
+ ownerPid?: number;
65
+ };
66
+ }
67
+ /** What `squads.runMember` asks the domain to launch. */
68
+ export interface SquadMemberRunRequest {
69
+ squadId: string;
70
+ memberId: string;
71
+ firstMessage?: string;
72
+ }
73
+ /** What `squads.runSquad` asks the domain to launch. */
74
+ export interface SquadRunRequest {
75
+ squadId: string;
76
+ goal?: string;
77
+ }
78
+ /**
79
+ * A refusal this channel answers with. The transport raises it and the
80
+ * connection publishes its `code` and text unchanged, so a domain refusal
81
+ * (`team-not-found`, `preset-unknown`) and a capability refusal
82
+ * (`squads-unavailable`, `squads-run-unavailable`) reach the client the same way.
83
+ */
84
+ export declare class SquadRefusal extends Error {
85
+ /** Stable machine code the client switches on. */
86
+ readonly code: string;
87
+ constructor(code: string, message: string);
88
+ }
89
+ /** @returns whether a caught value is this channel's own refusal. */
90
+ export declare function isSquadRefusal(value: unknown): value is SquadRefusal;
91
+ /**
92
+ * How a Host reaches the squad domain. Every method answers the plugin's own
93
+ * body unread: `state` is one `{teams, runs, host, presets?}` document, and the
94
+ * two run methods answer one `{run}` document.
95
+ */
96
+ export interface SquadTransport {
97
+ /** Definitions, run history and the owning pid, as the domain publishes them. */
98
+ state(): Promise<unknown>;
99
+ /** Launch one member session. */
100
+ runMember(request: SquadMemberRunRequest): Promise<unknown>;
101
+ /** Launch the Lead session of one whole squad. */
102
+ runSquad(request: SquadRunRequest): Promise<unknown>;
103
+ }
104
+ /**
105
+ * Map one `squads.state` answer.
106
+ * @param source - the domain's `{teams, runs, host, presets?}` document, from
107
+ * either the plugin's route or its ledger.
108
+ * @returns the frozen state body.
109
+ */
110
+ export declare function squadsStateOf(source: unknown): SquadsState;
111
+ /**
112
+ * Map one run answer.
113
+ * @param source - the domain's `{run}` document.
114
+ * @returns the frozen run row.
115
+ */
116
+ export declare function squadRunOf(source: unknown): SquadRun;
117
+ /**
118
+ * Gate `squads.runMember`'s payload. Only the two names this command needs are
119
+ * required; the lengths the domain accepts are the domain's own, so an oversized
120
+ * message is forwarded and refused there instead of being cut here.
121
+ * @param payload - the request's `p`.
122
+ * @returns the request, or undefined when it does not name a squad and a member.
123
+ */
124
+ export declare function parseSquadMemberRun(payload: Readonly<Record<string, unknown>>): SquadMemberRunRequest | undefined;
125
+ /**
126
+ * Gate `squads.runSquad`'s payload.
127
+ * @param payload - the request's `p`.
128
+ * @returns the request, or undefined when it does not name a squad.
129
+ */
130
+ export declare function parseSquadRun(payload: Readonly<Record<string, unknown>>): SquadRunRequest | undefined;