dsh-hello 0.1.0 → 0.1.2

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.
package/README.md CHANGED
@@ -1,509 +1,529 @@
1
- # DSH Door
2
-
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
1
+ # DSH Hello
2
+
3
+ [![npm version](https://img.shields.io/npm/v/dsh-hello?color=3d7bfd)](https://www.npmjs.com/package/dsh-hello)
4
+ [![license](https://img.shields.io/npm/l/dsh-hello?color=3d7bfd)](https://github.com/ada87/dsh-hello/blob/main/LICENSE)
5
+ [![dsh](https://img.shields.io/badge/dsh-0.2.x-3d7bfd)](https://github.com/ada87/dsh-hello/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-hello/main/docs/images/phone-drawer.png) | ![Session list and chat side by side on a tablet](https://raw.githubusercontent.com/ada87/dsh-hello/main/docs/images/tablet-split.png) |
26
+
27
+ ## Install
28
+
29
+ ```sh
30
+ dsh plugin --profile web add dsh-hello
31
+ ```
32
+ From a checkout or a packed tarball:
33
+
34
+ ```sh
35
+ dsh plugin --profile web add /path/to/dsh-hello
36
+ # or
37
+ pnpm pack
38
+ dsh plugin --profile web add ./dsh-hello-<version>.tgz
39
+ ```
40
+
41
+ Restart `dsh web`. The terminal prints:
42
+
43
+ ```text
44
+ [dsh-hello] dsh 0.2.2-rc.3 satisfies >=0.2.1-rc.4 <0.3.0
45
+ [dsh-hello] routes mounted at /dsh-hello (protocol 1, push none)
46
+ [dsh-hello] 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 Hello** 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-hello`) so dsh can
96
+ track releases. The **dsh-hello** 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-hello
106
+ dsh plugin --profile web add dsh-hello@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-hello@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-hello
123
+ dsh plugin --profile web add dsh-hello@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-hello to a release with
131
+ a matching range instead of reinstalling. Pairings and device tokens live in the
132
+ credential store under `dsh-hello/*` 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-hello
142
+ ```
143
+
144
+ Device records now live under `dsh-hello/*`, so pairings are not migrated: pair
145
+ the phone again. The app's storage keys are also `@dsh-hello/*` 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-hello**, 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
+ - a **lock** switch: while locked, `POST /pair` answers `403 pair-locked` and no
157
+ new device can join, while devices that are already paired keep working;
158
+ - the current numeric code and expiry;
159
+ - a QR payload (`{"v":1,"url":…,"code":…}`);
160
+ - the paired-device table;
161
+ - buttons to generate a new one-time code, set a **fixed code**, or restore
162
+ one-time rotation.
163
+
164
+ The lock is persisted next to the fixed code in the credential store, so it
165
+ survives a Host restart. There is no standalone HTML page. The panel is
166
+ contributed by `client/client.js` through the `settings.section` and
167
+ `settings.section.icon` slots and reads three cookie-authenticated endpoints:
168
+
169
+ - `GET /admin/data` – current code, QR payload, lock state and device list;
170
+ - `POST /admin/pair-code` – rotate, set or clear a fixed code;
171
+ - `POST /admin/lock` – `{ "locked": true | false }`.
172
+
173
+ Both are protected by the dsh browser session: the plugin calls
174
+ `ctx.connection.admit()` on the request headers, with loopback accepted as a
175
+ local fallback. Without a valid dsh login the endpoints return 401.
176
+
177
+ The browser half is part of the page's boot manifest, so after installing or
178
+ updating the plugin, restart `dsh web` and reload the Web UI (a hard refresh,
179
+ not just the settings tab). An already-open tab keeps the old module graph and
180
+ will not show the section.
181
+
182
+ ### Local development without publishing
183
+
184
+ Install the checkout once as a link; every rebuild is served from the same path:
185
+
186
+ ```sh
187
+ dsh plugin --profile web add link:/absolute/path/to/dsh-hello
188
+ ```
189
+
190
+ Then:
191
+
192
+ - **Host + client half**: `pnpm dev:host` (TypeScript types, esbuild bundle, and
193
+ the `client/client.js` copy); restart `dsh web`.
194
+ - **Before publishing**: `pnpm build` (types + bundle) and `pnpm test`.
195
+
196
+ Use a separate home if you do not want to touch your real profile:
197
+
198
+ ```sh
199
+ DSH_HOME=$HOME/.dsh-dev dsh plugin --profile web add link:/absolute/path/to/dsh-hello
200
+ DSH_HOME=$HOME/.dsh-dev dsh web --port 4001
201
+ ```
202
+
203
+ On Windows PowerShell:
204
+
205
+ ```powershell
206
+ $env:DSH_HOME="$HOME\.dsh-dev"
207
+ dsh plugin --profile web add link:D:/all-in-dsh/apps/dsh-hello
208
+ dsh web --port 4001
209
+ ```
210
+
211
+ Fixed codes are normalized (letters/digits, 4–32 chars, dashes ignored) and
212
+ persisted in the dsh credential store under `dsh-hello/pairing`. They remain
213
+ valid until changed; use them only on a trusted network. One-time codes rotate
214
+ after a successful pairing and expire after `pairingTtlMs`.
215
+
216
+ ## Pairing
217
+
218
+ - The plugin generates a one-time code, prints it, and optionally prints a QR
219
+ payload (`{"v":1,"url":"http://host:port/dsh-hello","code":"..."}`). The
220
+ Settings-page QR uses the browser's base URL; the terminal QR uses the bind
221
+ origin.
222
+ - The app sends the code plus a stable public-key fingerprint
223
+ (`devicePublicKey`). The server stores a hash of the bearer token and pins the
224
+ fingerprint as the device id.
225
+ - Tokens are not bound to `host:port`, so changing IP, port, or tunnel does not
226
+ require re-pairing.
227
+ - Device records live in the dsh credential store under the owner-scoped key
228
+ `dsh-hello/devices` (grant payload). No token is stored in `cordis.yml`.
229
+ - `GET /dsh-hello/pair/code` is loopback-only and only exists to make local
230
+ setup/curl tests convenient. Remote users read the code from the terminal.
231
+
232
+ ## Configuration
233
+
234
+ `basePath` defaults to `/dsh-hello`. The app's v1 discovery probes that exact
235
+ path, so a deployment that changes it also needs an app-side setting (planned).
236
+
237
+ The wire prefix and the persisted credential keys use the same `dsh-hello` name:
238
+ the app probes `/dsh-hello/health`, and pairings live under `dsh-hello/*`.
239
+
240
+ ```yaml
241
+ - id: dsh-hello
242
+ name: 'dsh-hello'
243
+ config:
244
+ basePath: /dsh-hello
245
+ allowedHosts: ['dsh.example.com'] # extra Host-header authorities
246
+ requireSecure: false # true when the Host itself serves TLS
247
+ strictHostCheck: false # true binds requests to a known authority
248
+ pairingTtlMs: 300000
249
+ pairingCodeLength: 4
250
+ pairingMaxAttempts: 8
251
+ interactionTarget: browser-first # phone-first | browser-first | browser-only
252
+ approvalWaitTimeoutMs: 120000
253
+ questionWaitTimeoutMs: 120000
254
+ allowSessionWideGrants: true
255
+ enableDebugRoutes: false # true exposes authenticated /debug/* test routes
256
+ maxBodyBytes: 65536
257
+ rateLimitWindowMs: 60000
258
+ rateLimitMax: 240
259
+ dshVersionRange: '>=0.2.1-rc.4 <0.3.0'
260
+ push:
261
+ provider: none # none | fcm | apns | relay
262
+ # provider: relay
263
+ # relayUrl: https://push.example.com
264
+ # relayHostToken: dshr_...
265
+ notifyTurnEnd: true
266
+ notifyApproval: true
267
+ notifyQuestion: true
268
+ ```
269
+
270
+ `relay` mode sends only the notification payload and host token to your relay;
271
+ the relay holds the FCM/APNs credentials. Device tokens are registered with the
272
+ relay automatically when the app calls `POST /push/register`.
273
+
274
+ 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.
275
+
276
+ Push credentials are BYO. Put secrets in the dsh credential store under the
277
+ owner-scoped record `dsh-hello/push` when possible; the plugin reads that record
278
+ first and falls back to configuration:
279
+
280
+ ```json
281
+ {
282
+ "provider": "fcm",
283
+ "fcmServiceAccountJson": "{\"type\":\"service_account\",...}",
284
+ "fcmProjectId": "my-project"
285
+ }
286
+ ```
287
+
288
+ The equivalent configuration fallback (useful for tests) is:
289
+
290
+ ```yaml
291
+ push:
292
+ provider: fcm
293
+ fcmServiceAccountJson: '{"type":"service_account",...}'
294
+ fcmProjectId: my-project
295
+ ```
296
+
297
+ or APNs:
298
+
299
+ ```yaml
300
+ push:
301
+ provider: apns
302
+ apnsKey: |
303
+ -----BEGIN PRIVATE KEY-----
304
+ ...
305
+ apnsKeyId: ABC123DEFG
306
+ apnsTeamId: TEAM123456
307
+ apnsTopic: com.example.dshapp
308
+ apnsEnvironment: production
309
+ ```
310
+
311
+ The plugin talks directly to Google/Apple; there is no author-operated relay.
312
+
313
+ ## HTTP API
314
+
315
+ All routes are under `basePath` (default `/dsh-hello`). Except for `/health`
316
+ and `/pair`, every route requires `Authorization: Bearer <device token>`.
317
+
318
+ | Method | Path | Purpose |
319
+ |---|---|---|
320
+ | GET | `/health` | Public capability and version facts |
321
+ | GET | `/pair` | Public pairing availability (no code) |
322
+ | GET/POST | `/pair/code` | Loopback-only current/rotated code + QR |
323
+ | POST | `/pair` | One-time code → device token |
324
+ | GET | `/devices` | Paired devices |
325
+ | DELETE | `/devices/:id` | Revoke a device |
326
+ | POST | `/push/register` | Register an FCM/APNs token |
327
+ | PUT | `/push/subscriptions` | Set this device's `approval` / `question` / `turnEnd` subscriptions |
328
+ | DELETE | `/push` | Remove this device's push token |
329
+ | POST | `/presence` | Tell the plugin this device is foreground (`{ foreground: boolean }`) |
330
+ | GET | `/speech` | Host speech Provider readiness; requires the experimental speech API bundle |
331
+ | POST | `/speech/transcribe` | Transcribe one canonical base64 WAV without submitting a Session prompt |
332
+ | GET | `/schedules` | Automation catalog; `available: false` when the profile has no schedule service |
333
+ | GET | `/schedule-marks` | Active scheduled-task counts per Session, for the drawer clock mark |
334
+ | GET | `/schedules/:id` | One task with target, last delivery and execution flags |
335
+ | GET | `/schedules/:id/history?limit=20&before=` | Delivery history, newest first |
336
+ | POST | `/schedules/:id/run` | Deliver one occurrence now without moving the schedule |
337
+ | PUT | `/schedules/:id` | Pause/resume (`{ "active": boolean, "expectedUpdatedAt"?: string }`) |
338
+ | DELETE | `/schedules/:id` | Delete the task and its saved deliveries |
339
+ | GET | `/sessions` | Session list with title projections and optional `vitals` (context %, tokens, turns, todos, goal, plan, model) |
340
+ | POST | `/sessions` | Create/reuse a blank Session |
341
+ | GET | `/sessions/:id/transcript` | Message-aligned history page |
342
+ | GET | `/sessions/:id/files?path=` | Read-only directory listing, confined to the Session cwd (300 entries max) |
343
+ | GET | `/sessions/:id/file?path=` | UTF-8 text preview, confined to the Session cwd (256 KiB max) |
344
+ | GET | `/sessions/:id/state` | Running/queue state + projections |
345
+ | GET | `/sessions/:id/terminals` | List retained phone terminals |
346
+ | POST | `/sessions/:id/terminals` | Open a PTY in the Session working directory |
347
+ | GET | `/sessions/:id/terminals/:tid/events` | SSE replay + live terminal output |
348
+ | POST | `/sessions/:id/terminals/:tid/input` | Write terminal input |
349
+ | POST | `/sessions/:id/terminals/:tid/resize` | Resize the PTY |
350
+ | DELETE | `/sessions/:id/terminals/:tid` | Terminate the terminal |
351
+ | GET | `/sessions/:id/events` | SSE follow stream (snapshot + events) |
352
+ | POST | `/sessions/:id/prompt` | Send text (`queue` or `steer`) |
353
+ | POST | `/sessions/:id/rename` | Rename |
354
+ | POST | `/sessions/:id/fork` | Create a child Session at an optional inclusive `atSeq` prefix |
355
+ | GET | `/workspaces` | Workspace registry (id, path, title) |
356
+ | POST | `/workspaces` | Adopt an existing directory (`{ "path", "title"? }`) |
357
+ | PUT | `/workspaces/:id` | Rename a workspace (`{ "title": string }`); duplicate titles are allowed, like dsh Web |
358
+ | POST | `/sessions/:id/cancel` | Stop the current turn |
359
+ | GET | `/web-url` | This Host's Web UI, with the process launch token already attached |
360
+ | GET | `/read-state` | Shared read watermarks; proxied to dsh-tag |
361
+ | POST | `/read-state` | Merge this device's watermarks (`{ "sessions": { id: { readAt, unread, at } } }`) and return the merged map |
362
+ | GET | `/events` | Global SSE: approvals, questions, sessions, turn end |
363
+ | GET | `/approvals` | Pending approvals (optional `preview`: command/diff/URL/path) |
364
+ | POST | `/approvals/:id` | `allow` / `always` / `deny` |
365
+ | GET | `/questions` | Pending questions |
366
+ | POST | `/questions/:id/answer` | Structured answer batch |
367
+ | POST | `/sessions/:id/questions/:callId/answer` | Answer a continued question |
368
+ | POST | `/debug/approval` | Debug-only synthetic approval (enableDebugRoutes) |
369
+ | POST | `/debug/question` | Debug-only synthetic question (enableDebugRoutes) |
370
+
371
+ A schedule delivery receipt acknowledges that the target Session persisted the
372
+ message, not that the Agent finished or succeeded. Open the target Session for
373
+ the actual result. `GET /health` advertises `schedules`, `scheduleActions` and
374
+ `scheduleHistory` so older plugins can stay read-only; `workspaceRename` gates
375
+ the phone's workspace rename entry, and `readState` tells the app that read
376
+ watermarks are shared across paired devices.
377
+
378
+ ### Approval policy
379
+
380
+ dsh hands an approval or a question to **one** answerer: the first listener that
381
+ does not call `next()`. `interactionTarget` decides who that is.
382
+
383
+ | Value | Who answers |
384
+ |---|---|
385
+ | `browser-first` (default) | A live browser always answers. With no browser connected the app holds the request, even in the background. |
386
+ | `phone-first` | A foreground app answers, even when a browser is connected; otherwise dsh's own listeners do. |
387
+ | `browser-only` | Nobody here: the plugin registers no listener, so dsh behaves exactly as if it were not installed. The app shows a read-only prompt and hands the decision to the Web UI. |
388
+
389
+ The plugin registers unscoped (`global`) waterfall listeners ahead of the
390
+ browser's answerer, so the policy rather than listener order decides. dsh 0.2.2
391
+ dispatches both waterfalls with `scopeTarget(agent, agent)`; a listener bound to
392
+ the plugin's own scope never sees them.
393
+
394
+ With a request claimed, the app is asked over SSE (and push) and its answer
395
+ becomes the tool's outcome:
396
+
397
+ 1. A claim expires after 45 seconds without a `POST /presence` heartbeat, and
398
+ backgrounding the app releases it immediately, so a browser can take over.
399
+ 2. Timeout, abort, "no", or the app leaving falls back to `next()`, so dsh's own
400
+ fail-closed `unavailable` path still applies.
401
+
402
+ `always` is a process-local session grant for one `session + tool` pair. dsh only
403
+ defines one-shot `allowed-once`; the plugin does not invent durable grants.
404
+
405
+ Approval events try to include a presentation-only `preview` by reading the
406
+ matching `tool/call` event (`bash` command, `edit` diff, `web_fetch` URL, etc.).
407
+ The lookup is best-effort and bounded so it never blocks the approval. Push data
408
+ also carries `hostId` (when the Host origin is known) and the approval's
409
+ `sessionId`, so a multi-host app can switch to the right Host before opening the
410
+ session.
411
+
412
+ ### Questions
413
+
414
+ Questions use the same policy: a foreground app with a live SSE connection claims
415
+ the question before a connected browser. If the app leaves the foreground, the
416
+ claim is released and dsh shows the question in the browser. If the foreground
417
+ wait is already gone, the app can still answer the projection's `continued`
418
+ questions through the `callId` route, which calls
419
+ `ctx.userQuestions.answer(agent, callId, ...)`.
420
+
421
+ ### SSE frames
422
+
423
+ `GET /sessions/:id/events`:
424
+
425
+ ```text
426
+ event: ready
427
+ data: {"sessionId":"..."}
428
+
429
+ event: frame
430
+ data: {"type":"snapshot","header":{...},"records":[...],"projections":{...}}
431
+
432
+ event: frame
433
+ data: {"type":"event","event":{"type":"assistant/message",...}}
434
+ ```
435
+
436
+ `GET /events`:
437
+
438
+ ```text
439
+ event: hello
440
+ data: {"server":{...},"features":{...},"pendingApprovals":[],"pendingQuestions":[]}
441
+
442
+ event: approval
443
+ data: {"id":"...","sessionId":"...","toolName":"bash","displayReason":{"en":"..."}}
444
+
445
+ event: session
446
+ data: {"action":"status","sessionId":"...","running":true}
447
+ ```
448
+
449
+ ### Debug interaction routes
450
+
451
+ `enableDebugRoutes: true` adds authenticated `POST /debug/approval` and
452
+ `POST /debug/question` routes. They create the same pending items the real
453
+ interaction seams create, so a phone can exercise the approval/question UI
454
+ without a model key or a tool call. They are off by default and are not a
455
+ replacement for the real waterfall; turn them off after testing.
456
+
457
+ ## Security model
458
+
459
+ - Route registration is outside dsh's `/api` cookie fence, so the plugin owns
460
+ its own fence:
461
+ - A `Host` header is required. Unauthenticated routes accept loopback, the
462
+ listener's bind address, a configured `allowedHosts` entry, or an authority
463
+ recorded at pairing.
464
+ - An authenticated device request is accepted across address/tunnel changes:
465
+ the bearer token is the boundary, so changing IP, port, or tunnel does not
466
+ require re-pairing. Set `strictHostCheck: true` to bind requests to the
467
+ authority allowlist instead.
468
+ - An attached web `Origin` must match the request authority; cross-site web
469
+ requests are refused (`403`).
470
+ - Installed browser-extension origins (`chrome-extension://`,
471
+ `moz-extension://`, `safari-web-extension://`) are accepted as paired
472
+ clients and receive scoped CORS headers plus `OPTIONS` preflight. The
473
+ device token or pairing code remains the authentication boundary. Web pages
474
+ still receive no CORS headers.
475
+ - Native clients do not need CORS; their requests are unchanged.
476
+ - The pairing admin page uses dsh's own browser authentication
477
+ (`ctx.connection.admit`) and only falls back to loopback; it is not an
478
+ unauthenticated code-dump route.
479
+ - Bearer tokens are compared in constant time after hashing.
480
+ - The phone terminal runs the Host's default shell through
481
+ `ctx.subprocess.spawnTerminal`, so it runs as the dsh OS user outside the
482
+ agent sandbox — the same permission model as dsh's Web sidebar terminal. It
483
+ is reachable only with a device token, input is capped at 64 KiB per request,
484
+ at most four terminals are kept per Session, and unattached terminals are
485
+ reclaimed after 30 idle minutes. Output is bounded to 200k characters.
486
+ - Revoking a device deletes its token and immediately ends every SSE stream
487
+ opened with it (global events and per-Session follows), so a lost phone stops
488
+ receiving events at revoke time rather than on its next reconnect.
489
+ - JSON bodies are bounded (`maxBodyBytes`) and rate-limited per client address.
490
+ - Pairing has a TTL, a one-time code, and a per-address failure cap.
491
+ - Plain HTTP on a public address is the user's choice and is surfaced by the
492
+ app as a strong warning; the app refuses to pair publicly over HTTP until the
493
+ user explicitly confirms. Prefer Tailscale, a private address, or TLS.
494
+
495
+ ## Verification
496
+
497
+ The plugin ships an integration suite that mounts the real router on a local
498
+ HTTP server with a fake Host context:
499
+
500
+ ```sh
501
+ node --import tsx --test tests/*.test.ts
502
+ # or, when deps are installed:
503
+ pnpm test
504
+ ```
505
+
506
+ It covers health, pairing and one-time-code consumption, token auth, session
507
+ projection, Host/Origin fences, approval claim/answer, browser-first delegation,
508
+ session-wide grants, question answers, terminal create/input/resize/close,
509
+ revoke stream teardown, body limits, and JSON-safe device persistence.
510
+
511
+ The app repository also contains a recorded M1 curl walkthrough in
512
+ `docs/M1-ACCEPTANCE.md` (https://cnb.cool/ada87/app-dsh-hello).
513
+
514
+ ## Known limitations
515
+
516
+ - dsh is developer preview; the plugin is pinned to `0.2.x`.
517
+ - Session title/list reads call the projection service per row (fine for a
518
+ personal Host; not optimized for thousands of sessions).
519
+ - `always` is process-local and disappears on restart.
520
+ - Push is implemented for FCM v1 and APNs token auth, but this repository cannot
521
+ exercise Apple/Google credentials.
522
+ - The app reads committed `assistant/message` events; assistant token deltas
523
+ (`assistant-stream` frames) are not rendered yet.
524
+ - The browser escape hatch opens the Web root; dsh does not expose the launch
525
+ token to plugins, so an already-authenticated browser session is required.
526
+
527
+ ## License
528
+
529
+ MIT