dsh-hello 0.0.0-stage → 0.1.0

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 (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +508 -2
  3. package/cordis.patch.yml +3 -0
  4. package/lib/catalogs.d.ts +100 -0
  5. package/lib/catalogs.d.ts.map +1 -0
  6. package/lib/catalogs.js +205 -0
  7. package/lib/catalogs.js.map +1 -0
  8. package/lib/client.js +544 -0
  9. package/lib/config.d.ts +96 -0
  10. package/lib/config.d.ts.map +1 -0
  11. package/lib/config.js +110 -0
  12. package/lib/config.js.map +1 -0
  13. package/lib/devices.d.ts +71 -0
  14. package/lib/devices.d.ts.map +1 -0
  15. package/lib/devices.js +219 -0
  16. package/lib/devices.js.map +1 -0
  17. package/lib/files.d.ts +43 -0
  18. package/lib/files.d.ts.map +1 -0
  19. package/lib/files.js +187 -0
  20. package/lib/files.js.map +1 -0
  21. package/lib/host.d.ts +324 -0
  22. package/lib/host.d.ts.map +1 -0
  23. package/lib/host.js +10 -0
  24. package/lib/host.js.map +1 -0
  25. package/lib/http.d.ts +77 -0
  26. package/lib/http.d.ts.map +1 -0
  27. package/lib/http.js +340 -0
  28. package/lib/http.js.map +1 -0
  29. package/lib/index.d.ts +20 -0
  30. package/lib/index.d.ts.map +1 -0
  31. package/lib/index.js +8227 -0
  32. package/lib/index.js.map +7 -0
  33. package/lib/interactions.d.ts +99 -0
  34. package/lib/interactions.d.ts.map +1 -0
  35. package/lib/interactions.js +568 -0
  36. package/lib/interactions.js.map +1 -0
  37. package/lib/pairing.d.ts +56 -0
  38. package/lib/pairing.d.ts.map +1 -0
  39. package/lib/pairing.js +128 -0
  40. package/lib/pairing.js.map +1 -0
  41. package/lib/protocol.d.ts +336 -0
  42. package/lib/protocol.d.ts.map +1 -0
  43. package/lib/protocol.js +7 -0
  44. package/lib/protocol.js.map +1 -0
  45. package/lib/push.d.ts +47 -0
  46. package/lib/push.d.ts.map +1 -0
  47. package/lib/push.js +339 -0
  48. package/lib/push.js.map +1 -0
  49. package/lib/read-state.d.ts +32 -0
  50. package/lib/read-state.d.ts.map +1 -0
  51. package/lib/read-state.js +39 -0
  52. package/lib/read-state.js.map +1 -0
  53. package/lib/routes.d.ts +33 -0
  54. package/lib/routes.d.ts.map +1 -0
  55. package/lib/routes.js +1293 -0
  56. package/lib/routes.js.map +1 -0
  57. package/lib/schedules.d.ts +31 -0
  58. package/lib/schedules.d.ts.map +1 -0
  59. package/lib/schedules.js +122 -0
  60. package/lib/schedules.js.map +1 -0
  61. package/lib/sessions.d.ts +60 -0
  62. package/lib/sessions.d.ts.map +1 -0
  63. package/lib/sessions.js +287 -0
  64. package/lib/sessions.js.map +1 -0
  65. package/lib/speech.d.ts +20 -0
  66. package/lib/speech.d.ts.map +1 -0
  67. package/lib/speech.js +47 -0
  68. package/lib/speech.js.map +1 -0
  69. package/lib/streams.d.ts +30 -0
  70. package/lib/streams.d.ts.map +1 -0
  71. package/lib/streams.js +106 -0
  72. package/lib/streams.js.map +1 -0
  73. package/lib/terminal.d.ts +55 -0
  74. package/lib/terminal.d.ts.map +1 -0
  75. package/lib/terminal.js +231 -0
  76. package/lib/terminal.js.map +1 -0
  77. package/lib/util.d.ts +18 -0
  78. package/lib/util.d.ts.map +1 -0
  79. package/lib/util.js +52 -0
  80. package/lib/util.js.map +1 -0
  81. package/lib/version.d.ts +15 -0
  82. package/lib/version.d.ts.map +1 -0
  83. package/lib/version.js +98 -0
  84. package/lib/version.js.map +1 -0
  85. package/package.json +80 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xdnote
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,509 @@
1
- # Temporary Holding Version
1
+ # DSH Door
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/dsh-door?color=3d7bfd)](https://www.npmjs.com/package/dsh-door)
4
+ [![license](https://img.shields.io/npm/l/dsh-door?color=3d7bfd)](https://github.com/ada87/dsh-door/blob/main/LICENSE)
5
+ [![dsh](https://img.shields.io/badge/dsh-0.2.x-3d7bfd)](https://github.com/ada87/dsh-door/blob/main/docs/COMPATIBILITY.md)
6
+
7
+ Non-official mobile BFF for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (`dsh`).
8
+ It is a normal dsh plugin: it runs inside the Host process, calls the Host's own
9
+ Cordis services, and speaks a small JSON + SSE protocol to the React Native app.
10
+
11
+ It does **not** use Typert Remote, does **not** fork dsh, and does **not** put a
12
+ relay server between the user's phone and the user's Host.
13
+
14
+ ## Features
15
+
16
+ - **The session list, everywhere.** Open the drawer to read every session with tags, unread weight and live status.
17
+ - **Reply without opening a laptop.** Send a prompt, queue it behind the current turn, or steer mid-turn.
18
+ - **Approve tool calls from the phone.** Allow, always-allow or deny; answer the agent's structured questions.
19
+ - **Terminal and files.** Open a real PTY for the session, leave it running in the background, and browse the workspace.
20
+ - **Push when you leave.** Optional FCM/APNs notifications for turn end, approvals and questions.
21
+ - **One token per device.** Pair once; revoke any device from Settings at any time.
22
+
23
+ | Phone | Tablet |
24
+ |---|---|
25
+ | ![Session drawer on a phone](https://raw.githubusercontent.com/ada87/dsh-door/main/docs/images/phone-drawer.png) | ![Session list and chat side by side on a tablet](https://raw.githubusercontent.com/ada87/dsh-door/main/docs/images/tablet-split.png) |
26
+
27
+ ## Install
28
+
29
+ ```sh
30
+ dsh plugin --profile web add dsh-door
31
+ ```
32
+ From a checkout or a packed tarball:
33
+
34
+ ```sh
35
+ dsh plugin --profile web add /path/to/dsh-door
36
+ # or
37
+ pnpm pack
38
+ dsh plugin --profile web add ./dsh-door-<version>.tgz
39
+ ```
40
+
41
+ Restart `dsh web`. The terminal prints:
42
+
43
+ ```text
44
+ [dsh-door] dsh 0.2.2-rc.3 satisfies >=0.2.1-rc.4 <0.3.0
45
+ [dsh-door] routes mounted at /dsh-door (protocol 1, push none)
46
+ [dsh-door] pairing code 1234 — open the app, enter the server URL, then this code.
47
+ ```
48
+
49
+ The code has a five-minute TTL by default. After a successful pairing it rotates;
50
+ the terminal prints the next one.
51
+
52
+ ### Pairing and compatibility
53
+
54
+ The generated pairing code is **four digits** (`1234`). It is one-time, expires
55
+ after `pairingTtlMs`, and each client address gets `pairingMaxAttempts` (8)
56
+ tries per TTL. Four digits are convenient but low entropy: keep dsh on a trusted
57
+ LAN/Tailscale, or raise `pairingCodeLength` / lower `pairingMaxAttempts` before
58
+ exposing it to the internet.
59
+
60
+ The Host's compatibility gate enforces the `engines.dsh` range at install and
61
+ profile startup. If a linked or exempted install runs outside the tested range,
62
+ the plugin logs a warning and reports `dshCompatible: false` in `/health`
63
+ instead of failing to load.
64
+
65
+ Supported window: the latest three **minor** lines, starting with 0.2.2.
66
+ Prerelease suffixes (`alpha`, `rc`) do not create a new line; `0.2.2-rc.1` and
67
+ `0.2.2-rc.3` are one line. The current matrix and test record live in
68
+ [`docs/COMPATIBILITY.md`](docs/COMPATIBILITY.md) and `compat/versions.json`.
69
+
70
+ `engines.dsh` still reads `>=0.2.1-rc.4 <0.3.0` during the transition. 0.2.1 is
71
+ outside the support window and marked `@deprecated 0.2.2`: it lacks
72
+ `sessionController.state()` and the page cursor, so the facade synthesizes state
73
+ from projections + list and always supplies the projection watermark as the cut,
74
+ then fills the missing cursor with that cut. See `tests/compat.test.ts`. The
75
+ floor will move to `>=0.2.2-0` when the 0.2.1 shims are removed.
76
+
77
+ ## Usage
78
+
79
+ - Open `dsh web` → **Settings → DSH Door** to read the pairing code and manage paired devices.
80
+ - In the app, enter the Host URL and the four-digit code; the device stores its own bearer token.
81
+ - The drawer lists sessions: open one to read, reply, approve tool calls, or open its terminal and files.
82
+ - Push is optional; register an FCM/APNs token under Settings when a relay is configured.
83
+
84
+ ## Why a plugin
85
+
86
+ The official browser client uses generated Typert codecs and `/api/remote.mux`.
87
+ Those artifacts are browser bundles, and dsh's `/api` route sits behind a
88
+ Host/Origin fence and browser cookies. A native app cannot consume either
89
+ cleanly. This plugin registers its own routes on the same `webServer`, authenticates
90
+ devices with its own bearer token, and uses the Host's own
91
+ `sessionController` / `approval` / `userQuestions` services.
92
+
93
+ ## Upgrade
94
+
95
+ Install from the npm registry (the default `dsh plugin add dsh-door`) so dsh can
96
+ track releases. The **dsh-door** page under **Plugins** then shows **Update
97
+ available** and a **Versions** section; **Update** removes the old version,
98
+ installs the selected one, keeps the bundle enabled, and recomposes with HMR or
99
+ asks for a restart. A failed update restores the previous version when possible.
100
+
101
+ The **Update / Versions** section is a dsh 0.2.2 feature. On 0.2.1 (outside the
102
+ supported window) the page has no update action, so update from the CLI instead:
103
+
104
+ ```sh
105
+ dsh plugin --profile web remove dsh-door
106
+ dsh plugin --profile web add dsh-door@latest
107
+ # restart dsh
108
+ ```
109
+
110
+ The Web UI is preferred on 0.2.2+ because it checks `engines.dsh` before
111
+ touching the profile and rolls back a failed install. From the CLI:
112
+
113
+ ```sh
114
+ dsh plugin --profile web add dsh-door@latest
115
+ # restart dsh if the result asks for it
116
+ ```
117
+
118
+ If you installed from a tarball or a `link:` path, that entry is not updatable;
119
+ switch it once:
120
+
121
+ ```sh
122
+ dsh plugin --profile web remove dsh-door
123
+ dsh plugin --profile web add dsh-door@latest
124
+ ```
125
+
126
+ ### dsh upgrades
127
+
128
+ The plugin is a profile dependency, so upgrading dsh keeps it installed. dsh
129
+ 0.2.x releases stay inside the supported range. A dsh 0.3.x Host refuses this
130
+ version at startup and marks it incompatible: update dsh-door to a release with
131
+ a matching range instead of reinstalling. Pairings and device tokens live in the
132
+ credential store under `dsh-door/*` and survive plugin updates.
133
+
134
+ ### Coming from `@xdnote/dsh-mobile`
135
+
136
+ Remove the old package once; it owns the old `/dsh-mobile` routes and the old
137
+ credential keys:
138
+
139
+ ```sh
140
+ dsh plugin --profile web remove @xdnote/dsh-mobile
141
+ dsh plugin --profile web add dsh-door
142
+ ```
143
+
144
+ Device records now live under `dsh-door/*`, so pairings are not migrated: pair
145
+ the phone again. The app's storage keys are also `@dsh-door/*` now, so install
146
+ the new app build rather than upgrading the old one in place.
147
+
148
+ ## Pairing code in the browser
149
+
150
+ Open dsh Web UI and go to **Settings → dsh-door**, the section placed directly
151
+ after **General** (slot `settings.section`, order `5`). It uses dsh's React
152
+ runtime and locale dictionaries, so it follows the Web UI theme and language.
153
+
154
+ The page shows:
155
+
156
+ - the current numeric code and expiry;
157
+ - a QR payload (`{"v":1,"url":…,"code":…}`);
158
+ - the paired-device table;
159
+ - buttons to generate a new one-time code, set a **fixed code**, or restore
160
+ one-time rotation.
161
+
162
+ There is no standalone HTML page. The panel is contributed by `client/client.js`
163
+ through the `settings.section` and `settings.section.icon` slots and reads two
164
+ cookie-authenticated endpoints:
165
+
166
+ - `GET /admin/data` — current code, QR payload and device list;
167
+ - `POST /admin/pair-code` — rotate, set or clear a fixed code.
168
+
169
+ Both are protected by the dsh browser session: the plugin calls
170
+ `ctx.connection.admit()` on the request headers, with loopback accepted as a
171
+ local fallback. Without a valid dsh login the endpoints return 401.
172
+
173
+ The browser half is part of the page's boot manifest, so after installing or
174
+ updating the plugin, restart `dsh web` and reload the Web UI (a hard refresh,
175
+ not just the settings tab). An already-open tab keeps the old module graph and
176
+ will not show the section.
177
+
178
+ ### Local development without publishing
179
+
180
+ Install the checkout once as a link; every rebuild is served from the same path:
181
+
182
+ ```sh
183
+ dsh plugin --profile web add link:/absolute/path/to/dsh-door
184
+ ```
185
+
186
+ Then:
187
+
188
+ - **Host + client half**: `pnpm dev:host` (TypeScript types, esbuild bundle, and
189
+ the `client/client.js` copy); restart `dsh web`.
190
+ - **Before publishing**: `pnpm build` (types + bundle) and `pnpm test`.
191
+
192
+ Use a separate home if you do not want to touch your real profile:
193
+
194
+ ```sh
195
+ DSH_HOME=$HOME/.dsh-dev dsh plugin --profile web add link:/absolute/path/to/dsh-door
196
+ DSH_HOME=$HOME/.dsh-dev dsh web --port 4001
197
+ ```
198
+
199
+ On Windows PowerShell:
200
+
201
+ ```powershell
202
+ $env:DSH_HOME="$HOME\.dsh-dev"
203
+ dsh plugin --profile web add link:D:/all-in-mobile/apps/dsh-door
204
+ dsh web --port 4001
205
+ ```
206
+
207
+ Fixed codes are normalized (letters/digits, 4–32 chars, dashes ignored) and
208
+ persisted in the dsh credential store under `dsh-door/pairing`. They remain
209
+ valid until changed; use them only on a trusted network. One-time codes rotate
210
+ after a successful pairing and expire after `pairingTtlMs`.
211
+
212
+ ## Pairing
213
+
214
+ - The plugin generates a one-time code, prints it, and optionally prints a QR
215
+ payload (`{"v":1,"url":"http://host:port/dsh-door","code":"..."}`).
216
+ - The app sends the code plus a stable public-key fingerprint
217
+ (`devicePublicKey`). The server stores a hash of the bearer token and pins the
218
+ fingerprint as the device id.
219
+ - Tokens are not bound to `host:port`, so changing IP, port, or tunnel does not
220
+ require re-pairing.
221
+ - Device records live in the dsh credential store under the owner-scoped key
222
+ `dsh-door/devices` (grant payload). No token is stored in `cordis.yml`.
223
+ - `GET /dsh-door/pair/code` is loopback-only and only exists to make local
224
+ setup/curl tests convenient. Remote users read the code from the terminal.
225
+
226
+ ## Configuration
227
+
228
+ `basePath` defaults to `/dsh-door`. The app's v1 discovery probes that exact
229
+ path, so a deployment that changes it also needs an app-side setting (planned).
230
+
231
+ The wire prefix and the persisted credential keys use the same `dsh-door` name:
232
+ the app probes `/dsh-door/health`, and pairings live under `dsh-door/*`.
233
+
234
+ ```yaml
235
+ - id: dsh-door
236
+ name: 'dsh-door'
237
+ config:
238
+ basePath: /dsh-door
239
+ allowedHosts: ['dsh.example.com'] # extra Host-header authorities
240
+ requireSecure: false # true when the Host itself serves TLS
241
+ strictHostCheck: false # true binds requests to a known authority
242
+ pairingTtlMs: 300000
243
+ pairingCodeLength: 4
244
+ pairingMaxAttempts: 8
245
+ approvalWaitTimeoutMs: 120000
246
+ questionWaitTimeoutMs: 120000
247
+ allowSessionWideGrants: true
248
+ enableDebugRoutes: false # true exposes authenticated /debug/* test routes
249
+ maxBodyBytes: 65536
250
+ rateLimitWindowMs: 60000
251
+ rateLimitMax: 240
252
+ dshVersionRange: '>=0.2.1-rc.4 <0.3.0'
253
+ push:
254
+ provider: none # none | fcm | apns | relay
255
+ # provider: relay
256
+ # relayUrl: https://push.example.com
257
+ # relayHostToken: dshr_...
258
+ notifyTurnEnd: true
259
+ notifyApproval: true
260
+ notifyQuestion: true
261
+ ```
262
+
263
+ `relay` mode sends only the notification payload and host token to your relay;
264
+ the relay holds the FCM/APNs credentials. Device tokens are registered with the
265
+ relay automatically when the app calls `POST /push/register`.
266
+
267
+ The `notify*` config values are host-wide defaults. Each device can then set its own `approval`, `question` and `turnEnd` subscriptions with `PUT /push/subscriptions`; both direct sending and relay mode filter unsubscribed devices. Turn-end pushes are sent only when no app has a live global SSE connection. A connected app handles the event locally instead.
268
+
269
+ Push credentials are BYO. Put secrets in the dsh credential store under the
270
+ owner-scoped record `dsh-door/push` when possible; the plugin reads that record
271
+ first and falls back to configuration:
272
+
273
+ ```json
274
+ {
275
+ "provider": "fcm",
276
+ "fcmServiceAccountJson": "{\"type\":\"service_account\",...}",
277
+ "fcmProjectId": "my-project"
278
+ }
279
+ ```
280
+
281
+ The equivalent configuration fallback (useful for tests) is:
282
+
283
+ ```yaml
284
+ push:
285
+ provider: fcm
286
+ fcmServiceAccountJson: '{"type":"service_account",...}'
287
+ fcmProjectId: my-project
288
+ ```
289
+
290
+ or APNs:
291
+
292
+ ```yaml
293
+ push:
294
+ provider: apns
295
+ apnsKey: |
296
+ -----BEGIN PRIVATE KEY-----
297
+ ...
298
+ apnsKeyId: ABC123DEFG
299
+ apnsTeamId: TEAM123456
300
+ apnsTopic: com.example.dshapp
301
+ apnsEnvironment: production
302
+ ```
303
+
304
+ The plugin talks directly to Google/Apple; there is no author-operated relay.
305
+
306
+ ## HTTP API
307
+
308
+ All routes are under `basePath` (default `/dsh-door`). Except for `/health`
309
+ and `/pair`, every route requires `Authorization: Bearer <device token>`.
310
+
311
+ | Method | Path | Purpose |
312
+ |---|---|---|
313
+ | GET | `/health` | Public capability and version facts |
314
+ | GET | `/pair` | Public pairing availability (no code) |
315
+ | GET/POST | `/pair/code` | Loopback-only current/rotated code + QR |
316
+ | POST | `/pair` | One-time code → device token |
317
+ | GET | `/devices` | Paired devices |
318
+ | DELETE | `/devices/:id` | Revoke a device |
319
+ | POST | `/push/register` | Register an FCM/APNs token |
320
+ | PUT | `/push/subscriptions` | Set this device's `approval` / `question` / `turnEnd` subscriptions |
321
+ | DELETE | `/push` | Remove this device's push token |
322
+ | POST | `/presence` | Tell the plugin this device is foreground (`{ foreground: boolean }`) |
323
+ | GET | `/speech` | Host speech Provider readiness; requires the experimental speech API bundle |
324
+ | POST | `/speech/transcribe` | Transcribe one canonical base64 WAV without submitting a Session prompt |
325
+ | GET | `/schedules` | Automation catalog; `available: false` when the profile has no schedule service |
326
+ | GET | `/schedule-marks` | Active scheduled-task counts per Session, for the drawer clock mark |
327
+ | GET | `/schedules/:id` | One task with target, last delivery and execution flags |
328
+ | GET | `/schedules/:id/history?limit=20&before=` | Delivery history, newest first |
329
+ | POST | `/schedules/:id/run` | Deliver one occurrence now without moving the schedule |
330
+ | PUT | `/schedules/:id` | Pause/resume (`{ "active": boolean, "expectedUpdatedAt"?: string }`) |
331
+ | DELETE | `/schedules/:id` | Delete the task and its saved deliveries |
332
+ | GET | `/sessions` | Session list with title projections and optional `vitals` (context %, tokens, turns, todos, goal, plan, model) |
333
+ | POST | `/sessions` | Create/reuse a blank Session |
334
+ | GET | `/sessions/:id/transcript` | Message-aligned history page |
335
+ | GET | `/sessions/:id/files?path=` | Read-only directory listing, confined to the Session cwd (300 entries max) |
336
+ | GET | `/sessions/:id/file?path=` | UTF-8 text preview, confined to the Session cwd (256 KiB max) |
337
+ | GET | `/sessions/:id/state` | Running/queue state + projections |
338
+ | GET | `/sessions/:id/terminals` | List retained phone terminals |
339
+ | POST | `/sessions/:id/terminals` | Open a PTY in the Session working directory |
340
+ | GET | `/sessions/:id/terminals/:tid/events` | SSE replay + live terminal output |
341
+ | POST | `/sessions/:id/terminals/:tid/input` | Write terminal input |
342
+ | POST | `/sessions/:id/terminals/:tid/resize` | Resize the PTY |
343
+ | DELETE | `/sessions/:id/terminals/:tid` | Terminate the terminal |
344
+ | GET | `/sessions/:id/events` | SSE follow stream (snapshot + events) |
345
+ | POST | `/sessions/:id/prompt` | Send text (`queue` or `steer`) |
346
+ | POST | `/sessions/:id/rename` | Rename |
347
+ | POST | `/sessions/:id/fork` | Create a child Session at an optional inclusive `atSeq` prefix |
348
+ | GET | `/workspaces` | Workspace registry (id, path, title) |
349
+ | POST | `/workspaces` | Adopt an existing directory (`{ "path", "title"? }`) |
350
+ | PUT | `/workspaces/:id` | Rename a workspace (`{ "title": string }`); duplicate titles are allowed, like dsh Web |
351
+ | POST | `/sessions/:id/cancel` | Stop the current turn |
352
+ | GET | `/sessions/:id/open` | Escape-hatch browser URL |
353
+ | GET | `/read-state` | Shared read watermarks; proxied to dsh-tag |
354
+ | POST | `/read-state` | Merge this device's watermarks (`{ "sessions": { id: { readAt, unread, at } } }`) and return the merged map |
355
+ | GET | `/events` | Global SSE: approvals, questions, sessions, turn end |
356
+ | GET | `/approvals` | Pending approvals (optional `preview`: command/diff/URL/path) |
357
+ | POST | `/approvals/:id` | `allow` / `always` / `deny` |
358
+ | GET | `/questions` | Pending questions |
359
+ | POST | `/questions/:id/answer` | Structured answer batch |
360
+ | POST | `/sessions/:id/questions/:callId/answer` | Answer a continued question |
361
+ | POST | `/debug/approval` | Debug-only synthetic approval (enableDebugRoutes) |
362
+ | POST | `/debug/question` | Debug-only synthetic question (enableDebugRoutes) |
363
+
364
+ A schedule delivery receipt acknowledges that the target Session persisted the
365
+ message, not that the Agent finished or succeeded. Open the target Session for
366
+ the actual result. `GET /health` advertises `schedules`, `scheduleActions` and
367
+ `scheduleHistory` so older plugins can stay read-only; `workspaceRename` gates
368
+ the phone's workspace rename entry, and `readState` tells the app that read
369
+ watermarks are shared across paired devices.
370
+
371
+ ### Approval policy
372
+
373
+ The plugin follows the required policy exactly:
374
+
375
+ 1. If a paired app is in the foreground with a live global SSE connection, claim
376
+ the request even when a browser is connected. The app heartbeats
377
+ `POST /presence` every 20 seconds; a claim expires after 45 seconds without a
378
+ heartbeat, and backgrounding the app releases it immediately.
379
+ 2. Otherwise, if `ctx.typertGateway.hasLiveClient()` is true, call `next()` — the
380
+ browser wins. The waterfall is first-answerer-wins, so claiming would hide the
381
+ prompt from the official UI.
382
+ 3. With neither, claim the request, broadcast it over SSE, push it if configured,
383
+ and wait for the app or the timeout.
384
+ 4. Timeout, abort, an answer of "no", or the foreground app leaving falls back to
385
+ `next()`, so dsh's own fail-closed `unavailable` path still applies.
386
+
387
+ `always` is a process-local session grant for one `session + tool` pair. dsh only
388
+ defines one-shot `allowed-once`; the plugin does not invent durable grants.
389
+
390
+ Approval events try to include a presentation-only `preview` by reading the
391
+ matching `tool/call` event (`bash` command, `edit` diff, `web_fetch` URL, etc.).
392
+ The lookup is best-effort and bounded so it never blocks the approval. Push data
393
+ also carries `hostId` (when the Host origin is known) and the approval's
394
+ `sessionId`, so a multi-host app can switch to the right Host before opening the
395
+ session.
396
+
397
+ ### Questions
398
+
399
+ Questions use the same policy: a foreground app with a live SSE connection claims
400
+ the question before a connected browser. If the app leaves the foreground, the
401
+ claim is released and dsh shows the question in the browser. If the foreground
402
+ wait is already gone, the app can still answer the projection's `continued`
403
+ questions through the `callId` route, which calls
404
+ `ctx.userQuestions.answer(agent, callId, ...)`.
405
+
406
+ ### SSE frames
407
+
408
+ `GET /sessions/:id/events`:
409
+
410
+ ```text
411
+ event: ready
412
+ data: {"sessionId":"..."}
413
+
414
+ event: frame
415
+ data: {"type":"snapshot","header":{...},"records":[...],"projections":{...}}
416
+
417
+ event: frame
418
+ data: {"type":"event","event":{"type":"assistant/message",...}}
419
+ ```
420
+
421
+ `GET /events`:
422
+
423
+ ```text
424
+ event: hello
425
+ data: {"server":{...},"features":{...},"pendingApprovals":[],"pendingQuestions":[]}
426
+
427
+ event: approval
428
+ data: {"id":"...","sessionId":"...","toolName":"bash","displayReason":{"en":"..."}}
429
+
430
+ event: session
431
+ data: {"action":"status","sessionId":"...","running":true}
432
+ ```
433
+
434
+ ### Debug interaction routes
435
+
436
+ `enableDebugRoutes: true` adds authenticated `POST /debug/approval` and
437
+ `POST /debug/question` routes. They create the same pending items the real
438
+ interaction seams create, so a phone can exercise the approval/question UI
439
+ without a model key or a tool call. They are off by default and are not a
440
+ replacement for the real waterfall; turn them off after testing.
441
+
442
+ ## Security model
443
+
444
+ - Route registration is outside dsh's `/api` cookie fence, so the plugin owns
445
+ its own fence:
446
+ - A `Host` header is required. Unauthenticated routes accept loopback, the
447
+ listener's bind address, a configured `allowedHosts` entry, or an authority
448
+ recorded at pairing.
449
+ - An authenticated device request is accepted across address/tunnel changes:
450
+ the bearer token is the boundary, so changing IP, port, or tunnel does not
451
+ require re-pairing. Set `strictHostCheck: true` to bind requests to the
452
+ authority allowlist instead.
453
+ - An attached `Origin` must match the request authority; cross-site browser
454
+ requests are refused (`403`).
455
+ - Native clients do not need CORS, so no CORS headers are ever sent.
456
+ - The pairing admin page uses dsh's own browser authentication
457
+ (`ctx.connection.admit`) and only falls back to loopback; it is not an
458
+ unauthenticated code-dump route.
459
+ - Bearer tokens are compared in constant time after hashing.
460
+ - The phone terminal runs the Host's default shell through
461
+ `ctx.subprocess.spawnTerminal`, so it runs as the dsh OS user outside the
462
+ agent sandbox — the same permission model as dsh's Web sidebar terminal. It
463
+ is reachable only with a device token, input is capped at 64 KiB per request,
464
+ at most four terminals are kept per Session, and unattached terminals are
465
+ reclaimed after 30 idle minutes. Output is bounded to 200k characters.
466
+ - Revoking a device deletes its token and immediately ends every SSE stream
467
+ opened with it (global events and per-Session follows), so a lost phone stops
468
+ receiving events at revoke time rather than on its next reconnect.
469
+ - JSON bodies are bounded (`maxBodyBytes`) and rate-limited per client address.
470
+ - Pairing has a TTL, a one-time code, and a per-address failure cap.
471
+ - Plain HTTP on a public address is the user's choice and is surfaced by the
472
+ app as a strong warning; the app refuses to pair publicly over HTTP until the
473
+ user explicitly confirms. Prefer Tailscale, a private address, or TLS.
474
+
475
+ ## Verification
476
+
477
+ The plugin ships an integration suite that mounts the real router on a local
478
+ HTTP server with a fake Host context:
479
+
480
+ ```sh
481
+ node --import tsx --test tests/*.test.ts
482
+ # or, when deps are installed:
483
+ pnpm test
484
+ ```
485
+
486
+ It covers health, pairing and one-time-code consumption, token auth, session
487
+ projection, Host/Origin fences, approval claim/answer, browser-first delegation,
488
+ session-wide grants, question answers, terminal create/input/resize/close,
489
+ revoke stream teardown, body limits, and JSON-safe device persistence.
490
+
491
+ The app repository also contains a recorded M1 curl walkthrough in
492
+ `docs/M1-ACCEPTANCE.md` (https://cnb.cool/ada87/app-dsh-door).
493
+
494
+ ## Known limitations
495
+
496
+ - dsh is developer preview; the plugin is pinned to `0.2.x`.
497
+ - Session title/list reads call the projection service per row (fine for a
498
+ personal Host; not optimized for thousands of sessions).
499
+ - `always` is process-local and disappears on restart.
500
+ - Push is implemented for FCM v1 and APNs token auth, but this repository cannot
501
+ exercise Apple/Google credentials.
502
+ - The app reads committed `assistant/message` events; assistant token deltas
503
+ (`assistant-stream` frames) are not rendered yet.
504
+ - The browser escape hatch opens the Web root; dsh does not expose the launch
505
+ token to plugins, so an already-authenticated browser session is required.
506
+
507
+ ## License
508
+
509
+ MIT
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: dsh-door
3
+ name: dsh-door
@@ -0,0 +1,100 @@
1
+ import type { HostContext } from './host.js';
2
+ /**
3
+ * Read-only catalogs for the phone's new-session and model pickers. Every
4
+ * service is optional: a Host profile without workspaces, agent presets, or
5
+ * an LLM runtime simply reports the catalog as unavailable and the phone
6
+ * hides the corresponding selector.
7
+ */
8
+ export interface WorkspaceItem {
9
+ id: string;
10
+ path: string;
11
+ title: string;
12
+ }
13
+ export interface WorkspaceCreateValue {
14
+ workspace: WorkspaceItem;
15
+ }
16
+ export interface AgentPresetItem {
17
+ id: string;
18
+ name?: string;
19
+ description?: string;
20
+ broken?: string;
21
+ }
22
+ export interface AgentPresetList {
23
+ defaultId: string | null;
24
+ items: AgentPresetItem[];
25
+ }
26
+ export interface ModelSelection {
27
+ provider: string;
28
+ model: string;
29
+ reasoningEffort?: string;
30
+ }
31
+ export interface ModelCatalogModel {
32
+ id: string;
33
+ name: string;
34
+ reasoningEfforts: string[];
35
+ defaultEffort?: string;
36
+ }
37
+ export interface ModelCatalogProvider {
38
+ id: string;
39
+ name: string;
40
+ models: ModelCatalogModel[];
41
+ }
42
+ export interface ModelCatalog {
43
+ default: ModelSelection | null;
44
+ providers: ModelCatalogProvider[];
45
+ }
46
+ interface ModelCarrier {
47
+ current(): ModelSelection | undefined;
48
+ select(selection: ModelSelection): void;
49
+ }
50
+ interface AgentWithModel {
51
+ model?: ModelCarrier;
52
+ }
53
+ export declare function workspacesAvailable(ctx: HostContext): boolean;
54
+ export declare function agentPresetsAvailable(ctx: HostContext): boolean;
55
+ export declare function modelsAvailable(ctx: HostContext): boolean;
56
+ export declare function listWorkspaces(ctx: HostContext): WorkspaceItem[];
57
+ /** Adopt an existing Host directory as a workspace (the dsh Web folder-plus action). */
58
+ export declare function createWorkspace(ctx: HostContext, path: string, title?: string): Promise<WorkspaceItem>;
59
+ export declare function workspaceRenameAvailable(ctx: HostContext): boolean;
60
+ /** Rename a workspace without touching its directory or sessions. */
61
+ export declare function renameWorkspace(ctx: HostContext, id: string, title: string): Promise<{
62
+ workspace: WorkspaceItem;
63
+ } | {
64
+ code: 'workspace-not-found';
65
+ }>;
66
+ /** Pin/unpin a Session on every dsh Web grouping surface. */
67
+ export declare function setSessionPinned(ctx: HostContext, sessionId: string, pinned: boolean): Promise<void>;
68
+ /**
69
+ * Archive/unarchive a Session. Archiving a running Session fails unless
70
+ * `stopActivity` is explicitly true; the phone asks the user to stop first
71
+ * rather than silently cancelling work.
72
+ */
73
+ export declare function setSessionArchived(ctx: HostContext, sessionId: string, archived: boolean, stopActivity?: boolean): Promise<void>;
74
+ export declare function listAgentPresets(ctx: HostContext): Promise<AgentPresetList>;
75
+ export interface UploadReceipt {
76
+ receiptId: string;
77
+ kind: 'file' | 'image';
78
+ name?: string;
79
+ bytes?: number;
80
+ mediaType?: string;
81
+ width?: number;
82
+ height?: number;
83
+ }
84
+ export declare function uploadsAvailable(ctx: HostContext): boolean;
85
+ export declare function uploadAttachment(ctx: HostContext, sessionId: string, input: {
86
+ kind: 'file' | 'image';
87
+ name?: string;
88
+ mediaType?: string;
89
+ bytes: Buffer;
90
+ }): Promise<UploadReceipt>;
91
+ export declare function modelCatalog(ctx: HostContext): Promise<ModelCatalog>;
92
+ export declare function invalidateModelCatalog(): void;
93
+ export declare function currentSessionModel(agent: AgentWithModel | undefined, fallback: ModelSelection | null): ModelSelection | null;
94
+ /**
95
+ * Switch the session's model. Mirrors the Host's own validation order: the
96
+ * route must resolve before the durable model/selection event is appended.
97
+ */
98
+ export declare function selectSessionModel(ctx: HostContext, agent: AgentWithModel | undefined, selection: ModelSelection): Promise<void>;
99
+ export {};
100
+ //# sourceMappingURL=catalogs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalogs.d.ts","sourceRoot":"","sources":["../src/catalogs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAE5C;;;;;GAKG;AAEH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,aAAa,CAAA;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,KAAK,EAAE,eAAe,EAAE,CAAA;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,iBAAiB,EAAE,CAAA;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,GAAG,IAAI,CAAA;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