@deep-podder/dsh-remote-mobile 0.0.6 → 0.0.7

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 (45) hide show
  1. package/PROTOCOL.md +97 -9
  2. package/README.md +44 -9
  3. package/SECURITY.md +8 -0
  4. package/auth.js +16 -0
  5. package/bridge.js +336 -9
  6. package/docs/api-notes.md +12 -4
  7. package/docs/engineering-audit.md +252 -0
  8. package/docs/reference-chat-demo.md +41 -0
  9. package/docs/screenshots/chat-light.png +0 -0
  10. package/docs/screenshots/commands-dark.png +0 -0
  11. package/docs/screenshots/pairing-light.png +0 -0
  12. package/docs/screenshots/sessions-light.png +0 -0
  13. package/docs/verification.md +40 -4
  14. package/index.js +1 -1
  15. package/mobile/README.md +81 -35
  16. package/mobile/app.js +4268 -906
  17. package/mobile/index.html +28 -17
  18. package/mobile/lib/away.js +45 -0
  19. package/mobile/lib/constants.js +5 -0
  20. package/mobile/lib/errors.js +42 -0
  21. package/mobile/lib/format.js +94 -0
  22. package/mobile/lib/lock.js +21 -0
  23. package/mobile/manifest.webmanifest +24 -0
  24. package/mobile/mock-server.js +442 -17
  25. package/mobile/model/history.js +119 -0
  26. package/mobile/model/question.js +318 -0
  27. package/mobile/model/turns.js +57 -0
  28. package/mobile/styles/base.css +143 -0
  29. package/mobile/{styles.css → styles/components.css} +1170 -826
  30. package/mobile/styles/overrides.css +269 -0
  31. package/mobile/styles/tokens.css +169 -0
  32. package/mobile/sw.js +28 -4
  33. package/package.json +34 -20
  34. package/protocol.js +87 -0
  35. package/push-policy.js +58 -0
  36. package/server/frames/activity.js +110 -0
  37. package/server/frames/connection.js +21 -0
  38. package/server/frames/history.js +23 -0
  39. package/server/frames/interactions.js +77 -0
  40. package/server/frames/prompts.js +29 -0
  41. package/server/frames/queue.js +58 -0
  42. package/server/frames/sessions.js +201 -0
  43. package/server/frames/settings.js +38 -0
  44. package/server/frames/subagents.js +50 -0
  45. package/server.js +341 -423
package/PROTOCOL.md CHANGED
@@ -229,10 +229,12 @@ carries `type`; data frames additionally carry `sessionId`.
229
229
  ```jsonc
230
230
  { "type": "sessions.list" }
231
231
  { "type": "sessions.open", "sessionId": "..." }
232
- { "type": "sessions.create", "preset": "standard", "cwd": "/path/to/dir" } // both optional
232
+ { "type": "sessions.create", "workspaceId": "ws-id", "preset": "standard",
233
+ "cwd": "/path/to/dir", "requestId": "..." } // all optional; project xor directory
233
234
  { "type": "sessions.search", "query": "literal message text" } // cold-safe, max 20 sessions
234
235
  { "type": "session.rename", "sessionId": "...", "title": "New title" }
235
236
  { "type": "session.fork", "sessionId": "...", "atSeq": 123 } // atSeq optional
237
+ { "type": "session.attach", "sessionId": "...", "workspaceId": "ws-id" }
236
238
  { "type": "session.pin", "sessionId": "..." }
237
239
  { "type": "session.unpin", "sessionId": "..." }
238
240
  { "type": "session.archive", "sessionId": "...", "stopActivity": false } // stopActivity optional
@@ -240,14 +242,17 @@ carries `type`; data frames additionally carry `sessionId`.
240
242
  { "type": "queue.list", "sessionId": "..." } // live sessions only
241
243
  { "type": "queue.update", "sessionId": "...", "itemId": "...",
242
244
  "action": "edit" | "remove" | "steer", "text": "edited text" } // text only for edit
243
- { "type": "history.load", "sessionId": "...", "limit": 50 } // limit 1..200, default 50
245
+ { "type": "history.load", "sessionId": "...", "limit": 50 } // limit 1..500, default 50
244
246
  { "type": "prompt", "sessionId": "...", "text": "...", "requestId": "uuid",
245
247
  "mode": "queue" | "steer", // default "queue"
246
248
  "attachments": [{ "path": "...", "name": "photo.jpg", "mediaType": "image/jpeg", "size": 1234 }] }
247
249
  { "type": "stop", "sessionId": "..." }
250
+ { "type": "subagents.list", "sessionId": "..." } // read-only child catalog
251
+ { "type": "subagents.history", "sessionId": "...", "subagentId": "...", "limit": 100 } // 1..200
248
252
  { "type": "approval.answer", "requestId": "...", "decision": "allow" | "reject" }
249
253
  { "type": "question.answer", "sessionId": "...", "requestId": "...", "callId": "...",
250
- "answers": [{ "id": "color", "selected": ["Blue"], "custom": null }] }
254
+ "answers": [{ "id": "color", "selected": ["Blue"], "custom": "custom text" }] }
255
+ { "type": "question.cancel", "sessionId": "...", "requestId": "...", "callId": "..." }
251
256
  { "type": "model.list" }
252
257
  { "type": "model.select", "sessionId": "...", "provider": "...", "model": "...", "reasoningEffort": null }
253
258
  { "type": "preset.list" }
@@ -259,6 +264,7 @@ carries `type`; data frames additionally carry `sessionId`.
259
264
  { "type": "commands.list", "sessionId": "..." } // every Host command (export/permission hidden)
260
265
  { "type": "commands.execute", "sessionId": "...", "line": "goal ship it" } // "/" optional; args kept
261
266
  { "type": "client.visibility", "visible": true } // page foreground state (Web Push gating)
267
+ { "type": "pending.list" } // authoritative unresolved ids
262
268
  { "type": "ping", "t": 0 }
263
269
  ```
264
270
 
@@ -331,6 +337,18 @@ session belongs to no registered workspace (for example one created with a plain
331
337
  `workspaceId` and shows ungrouped sessions separately. Names, ids and project root paths only —
332
338
  never session content.
333
339
 
340
+ **Project membership.** The Host files a session under a project only when creation names the
341
+ Workspace: `sessionController.create` takes `workspaceId` **xor** `cwd`, and a cwd-only session
342
+ is never attached, so it shows up as ungrouped on the desktop sidebar. `sessions.create`
343
+ therefore takes `workspaceId` as the primary choice; when only `cwd` is sent and that directory
344
+ is exactly a registered project root, the bridge sends that project's `workspaceId` instead
345
+ (case- and separator-insensitive on Windows). Any other `cwd` stays an ungrouped session.
346
+ `session.attach` moves an existing session into a project — the repair path for sessions
347
+ created before the phone named a project: it answers `session.attached`, is followed by a
348
+ `sessions` refresh, and changes grouping only (the Host validates that the session's own
349
+ working directory resolves to the project root, so a session started in another folder is
350
+ refused with `code: "bad-request"`).
351
+
334
352
  `context.get` returns the context-window meter for one session. It is cold-safe (read from
335
353
  the Host's `contextPressure` / `tokenUsage` projections): `usedTokens` prefers
336
354
  `projectedTokens` (the size the next request would send) and falls back to
@@ -350,6 +368,12 @@ relativised to the session directory or reduced to a short tail — the phone ne
350
368
  `cwd`, drive letters or home paths. Diff data is live-process only: unknown coordinates answer
351
369
  `code: "unavailable"`.
352
370
 
371
+ Creating a session also opens it: the server answers `sessions` with `activeSessionId` and a
372
+ `session.opened` payload (created row plus empty history/queue if the follow-up open fails). A
373
+ failure echoes the optional `requestId` so the phone can leave its progress sheet immediately
374
+ instead of waiting for the local timeout. When the request names a project the created row
375
+ carries that `workspaceId`; when `workspaceId` and `cwd` are both sent the project wins.
376
+
353
377
  Commands: `commands.list` requires a live Agent, so a cold session answers
354
378
  `available: false` (the phone never activates a session just to list commands). For a live
355
379
  Agent the bridge returns every descriptor from the Agent's Host command registry — including
@@ -361,10 +385,30 @@ against that same live registry (never a static list), runs the full trimmed lin
361
385
  `command/done` events, so the phone should reload history afterwards to show the command node.
362
386
  A cold session answers `code: "not-live"`, an unknown or hidden command `code: "forbidden"`.
363
387
 
388
+ Reconnect reconciliation: every welcome replays every pending approval/question, then sends a
389
+ `pending` snapshot containing their ids. The phone removes unresolved local cards that are absent
390
+ from that snapshot (resolved while offline) and keeps the rest. The SPA also re-lists sessions and
391
+ queue/subagents after a socket open and every 30 s while visible, so a missed status frame heals
392
+ without a page reload.
393
+
394
+ Subagents: `subagents.list` returns the child tree under a parent session using the Host's
395
+ cold-safe `subagents.listDescendants` catalog, falling back to persisted summaries whose
396
+ `origin` is `"subagent"`. Rows are read-only and carry `id`, `parentId`, `depth`, `label`,
397
+ `mode` (`one-shot|external|continuable|unknown`), `title`, `running`, `status`
398
+ (`running|idle|unknown`), `createdAt`, `updatedAt` and `model`. `subagents.history` reads a
399
+ bounded page (default 100, max 200) through `sessionQuery.observeSession` (generic session
400
+ routing rejects subagent identities), verifies the child's parent when the header exposes it, and
401
+ skips inherited seed events so a fork does not replay the parent transcript. External tasks have
402
+ no local child transcript and are read-only rows; one-shot or still-running children may return
403
+ an empty page until durable events arrive. The phone never prompts,
404
+ steers, stops or approves inside a subagent; those writes stay on the parent/desktop. A live
405
+ `agent/status` change for a subagent is broadcast to every phone as `subagents.changed` with the
406
+ parent `sessionId`; the SPA refreshes the catalog/transcript instead of streaming child steps.
407
+
364
408
  ### Server → Client
365
409
 
366
410
  ```jsonc
367
- { "type": "ready", "version": "0.0.6", "server": { "name", "port" },
411
+ { "type": "ready", "version": "0.0.7", "server": { "name", "port" },
368
412
  "device": { "id", "name", "canApprove": true }, "sessions": [], "workspaces": [],
369
413
  "activeSessionId": null, "queue": [],
370
414
  "limits": { "image": { "maxBytes", "maxDimension", "maxImages",
@@ -397,8 +441,25 @@ A cold session answers `code: "not-live"`, an unknown or hidden command `code: "
397
441
  "results": [{ "id", "title", "snippet", "updatedAt", "running", "pinned", "archived",
398
442
  "agentAvailable", "workspaceId" }] }
399
443
 
444
+ { "type": "pending", "approvals": [{ "requestId", "sessionId" }],
445
+ "questions": [{ "requestId", "callId", "sessionId" }] } // after welcome replay
446
+
447
+ { "type": "subagents", "sessionId": "...", "items": [
448
+ { "id", "parentId", "depth": 1, "label": "research",
449
+ "mode": "one-shot|external|continuable|unknown", "title": "Research the API",
450
+ "running": true, "status": "running|idle|unknown",
451
+ "createdAt": 0, "updatedAt": 0,
452
+ "model": { "provider", "model" } | null, "preset": "standard|null" }
453
+ ] }
454
+
455
+ { "type": "subagents.changed", "sessionId": "parent-id", "subagentId": "child-id", "running": true }
456
+
457
+ { "type": "subagent.history", "sessionId": "parent-id", "subagentId": "child-id",
458
+ "items": [HistoryItem] }
459
+
400
460
  { "type": "session.pinned", "sessionId": "...", "pinned": true, "archived": false }
401
461
  { "type": "session.archived", "sessionId": "...", "archived": true, "pinned": false }
462
+ { "type": "session.attached", "sessionId": "...", "workspaceId": "ws-id" }
402
463
 
403
464
  { "type": "queue", "sessionId": "...",
404
465
  "items": [{ "id", "placement": "queued|steering|context", "rpcId": "..."?, "text": "..." }],
@@ -407,6 +468,9 @@ A cold session answers `code: "not-live"`, an unknown or hidden command `code: "
407
468
  "items": [{ "id", "placement", "rpcId": "...", "text": "..." }] }
408
469
 
409
470
  { "type": "history", "sessionId": "...", "items": [HistoryItem], "hasMore": false }
471
+ // `history.load` returns the newest `limit` events (there is no cursor). `hasMore` is
472
+ // best-effort: a full page means older events may exist, and the SPA's "Load earlier
473
+ // messages" asks again with a larger limit (up to 500).
410
474
 
411
475
  { "type": "context", "sessionId": "...",
412
476
  "usedTokens": 0, "pressureTokens": 0, "projectedTokens": 0, "contextWindow": 0,
@@ -459,12 +523,16 @@ A cold session answers `code: "not-live"`, an unknown or hidden command `code: "
459
523
  { "type": "question.request", "sessionId": "...", "requestId": "...", "callId": "..." | null,
460
524
  "questions": [
461
525
  { "id": "color", "question": "Which colour?", "header": "Colour",
462
- "detail": null, "multiSelect": false,
463
- "options": [{ "label": "Red", "description": "Warm" }, { "label": "Blue" }] }
526
+ "detail": "markdown" | undefined, "multiSelect": false,
527
+ "options": [{ "label": "Red", "description": "Warm" }, { "label": "Blue" }],
528
+ // Present only on presentation intents the asker declared; a client that
529
+ // does not know the kind renders the generic option list.
530
+ "intent": { "kind": "plan-review" | "approval", "approve": "...",
531
+ "reject": "...", "always": "..." } | undefined }
464
532
  ] }
465
533
  { "type": "question.resolved", "sessionId": "...", "requestId": "..." | null, "callId": "..." | null,
466
- "answers": [{ "id": "color", "selected": ["Blue"], "custom": null }] | null,
467
- "outcome": "answered" | "declined" | "unavailable",
534
+ "answers": [{ "id": "color", "selected": ["Blue"], "custom": "text" }] | null,
535
+ "outcome": "answered" | "declined" | "unavailable" | "continued",
468
536
  "by": "phone" | "desktop" | null }
469
537
 
470
538
  { "type": "session.status", "sessionId": "...", "running": true }
@@ -477,10 +545,30 @@ A cold session answers `code: "not-live"`, an unknown or hidden command `code: "
477
545
  { "type": "presets", "presets": [{ "id", "title", "description" }], "current": "standard" | null }
478
546
 
479
547
  { "type": "visibility", "visible": true } // ack for client.visibility; not required for Web Push
480
- { "type": "error", "code": "bad-request|not-found|internal|not-live|unavailable|forbidden", "message": "..." }
548
+ { "type": "error", "code": "bad-request|not-found|internal|not-live|unavailable|forbidden", "message": "...",
549
+ "requestId": "uuid" | undefined } // echoed when the failing frame carried one (e.g. prompt)
481
550
  { "type": "pong", "t": 0 }
482
551
  ```
483
552
 
553
+ ### Question answers
554
+
555
+ `question.answer` carries one item per question id. For a single-select question
556
+ `custom` **overrides** the selected label and `selected` is empty; for a
557
+ multi-select question `custom` supplements `selected`. A skipped question uses
558
+ the documented blank item `{ "id": "...", "selected": [] }`. The SPA sends every
559
+ question of the batch; the bridge fills any omitted id with that blank item and
560
+ re-applies the single-select rule, so an older cached client cannot send a
561
+ single-select answer carrying both a label and custom text.
562
+
563
+ `question.cancel` dismisses the whole request, matching the desktop card's close
564
+ control: the waterfall settles without an answer batch and the phone receives
565
+ `outcome: "declined"`. It never substitutes a blank answer batch.
566
+
567
+ A timed question whose foreground window closes is not declined: the bridge
568
+ reports `outcome: "continued"` with `answers: null`, the card stays answerable,
569
+ and a later `question.answer` is routed to the continued call by `callId`
570
+ (the Host still accepts it). An untimed request that is aborted is declined.
571
+
484
572
  ### Welcome replay
485
573
 
486
574
  After `ready`, the server immediately replays every open interaction as its original frame —
package/README.md CHANGED
@@ -30,12 +30,20 @@ the desktop-style project grouping, the chat surface and the Host command palett
30
30
 
31
31
  ## What you get
32
32
 
33
- - **Real-time chat** — token streaming, markdown, syntax-highlighted code, stop and steer.
34
- - **Sessions** — list, open, create (with an agent preset, a project shortcut and an optional
35
- working directory), rename, fork, pin/unpin and archive/unarchive. The list is grouped by
33
+ - **Real-time chat** — token streaming, markdown, syntax-highlighted code, stop and steer,
34
+ slash-command autocomplete, camera/file attachments, and edit-in-composer. A turn's tool
35
+ work folds into one thinking-first line (`Thought 12s` with `Used 21 Shell, Edit` beneath)
36
+ that expands to the reasoning and the per-tool cards, settled questions/approvals collapse
37
+ to a summary line, and the header is a single row with an Activity toggle.
38
+ - **Sessions** — list, open, create (with an agent preset, a project and an optional working
39
+ directory), rename, fork, pin/unpin and archive/unarchive. The New session sheet is explicit:
40
+ project chips, an optional directory and a preset list whose rows only select, with a footer
41
+ **Start session** button as the single create action. The list is grouped by
36
42
  registered project workspace exactly like the desktop sidebar (collapsible project sections,
37
43
  an **Ungrouped** section, pinned rows first) and archived sessions are hidden behind an
38
- explicit **Show archived** control. Content search when the deployment enables the Host's
44
+ explicit **Show archived** control. A chat started from the phone joins the chosen project, so
45
+ it lands under that project on the desktop too; **Project** in the session menu moves an
46
+ already-ungrouped chat into a project. Content search when the deployment enables the Host's
39
47
  session-query index.
40
48
  - **Model and preset selection** — switch the session's provider/model/reasoning effort and
41
49
  the DSH agent preset from the phone.
@@ -47,14 +55,37 @@ the desktop-style project grouping, the chat surface and the Host command palett
47
55
  small input sheet; unknown commands are refused.
48
56
  - **Queue and steer** — watch queued messages, edit or remove them, steer one into the
49
57
  running turn, and choose Queue vs Steer for the next send.
58
+ - **Conversation controls** — a separate draft per session (switching sessions never carries
59
+ text over), a failed or rejected message kept in place with **Retry**, **Load earlier
60
+ messages** for long sessions, file paste/drop, and **Branch from here** on any durable message
61
+ (forks the session at that event and opens the copy).
50
62
  - **Approvals and questions** — approvals surface as cards with a bounded, secret-scrubbed
51
63
  preview of the command or file write/edit when the bridge saw the tool call; per-device
52
64
  "can approve" control lives in the desktop pairing panel. `ask_user_question` renders as a
53
- native question card and answers the waiting tool.
65
+ question card that follows the desktop composer's flow: one question per card with a pager,
66
+ numbered or checkbox options, a "Recommended" badge and preselection, a free-text answer,
67
+ per-question Skip, and inline completion feedback. Plan-review requests render as an
68
+ Approve / Request changes decision.
69
+ - **PWA polish** — manifest shortcuts (New session, Needs you), install prompt, app badge and a
70
+ Get started checklist.
71
+ - **Devices and handoff** — see paired phones and rename this one; share/copy a transcript or a
72
+ session deep link for another paired device.
73
+ - **Notification intelligence** — per-device mute, decisions-only and quiet hours enforced by the
74
+ Host (test pushes always arrive), with a test-notification control.
75
+ - **Away recap** — returning after 15+ s with activity shows what was approved, asked, finished
76
+ or failed while you were gone.
77
+ - **Needs-you inbox** — unresolved approvals and questions across every session, with a session
78
+ badge, All/Needs you/Running filters, a title count and a PWA app badge.
79
+ - **Decision lock** — when app lock is on, approving or answering requires a biometric check within
80
+ the last two minutes; reading stays free. Devices can be view-only.
81
+ - **Subagents** — Activity shows the child-session tree with running/idle state and a read-only
82
+ transcript per child; monitoring without exposing child prompts.
54
83
  - **Activity** — live tool cards, and the session's changed files with unified diffs for text
55
84
  files (live sessions only).
56
- - **Context meter** — used/window tokens with an estimated badge when the Host has no usage
57
- sample.
85
+ - **Context ring** — used/window tokens draw a small progress ring around the header menu button
86
+ (full sentence in its tooltip/description); tap it for context details, **Compact now**,
87
+ **Fork from here**, or a copyable usage report. Estimated samples are dimmed and 85% warns once.
88
+ No composer-footer meter anymore.
58
89
  - **Attachments** — camera/library/file uploads, inline images delivered to the model as real
59
90
  image content parts, and Android share-sheet text/links into a session.
60
91
  - **Background notifications (Web Push)** — approvals, questions and finished replies reach
@@ -250,10 +281,11 @@ node dev/static-check.mjs # served SPA files, headers/CSP, PWA surface, s
250
281
  node dev/client-check.mjs # executes the browser half against a fake loader/React shim
251
282
  node dev/desk-auth-check.mjs # desktop endpoint loopback/key policy and same-origin route
252
283
  node dev/toggle-check.mjs # on/off switch closes and reopens the listener
253
- node dev/changes-bridge-check.mjs# context meter, changed files/diffs, command palette, project mapping
284
+ node dev/changes-bridge-check.mjs# context meter, changed files/diffs, command palette, project mapping + attach
254
285
  node dev/spa-check.mjs # SPA helper/id/version consistency (reads mobile/)
255
286
  node dev/release-check.mjs # package files completeness + public-release invariants
256
287
  node dev/ui-check.mjs # live: project grouping, archived filter, command palette (headless Chrome)
288
+ node dev/project-live.mjs # live: project create/attach validation (non-destructive)
257
289
  node dev/capture-screenshots.mjs # regenerates docs/screenshots from the mock server (headless Chrome)
258
290
  ```
259
291
 
@@ -292,13 +324,16 @@ The package publishes publicly to npm as
292
324
  no dependencies, so the published files are the tracked source.
293
325
 
294
326
  Version bumps touch `package.json`, `index.js`, `server.js`, `mobile/app.js`
295
- (`FALLBACK_VERSION`) and the PROTOCOL example; `release-check` enforces that they agree.
327
+ (`FALLBACK_VERSION`), `mobile/mock-server.js` and the PROTOCOL example; `release-check` enforces
328
+ that they agree.
296
329
 
297
330
  ## Documentation
298
331
 
299
332
  - [npm package](https://www.npmjs.com/package/@deep-podder/dsh-remote-mobile) ·
300
333
  [source on GitHub](https://github.com/unknown-spec10/dsg-remote-mobile) ·
301
334
  [issues](https://github.com/unknown-spec10/dsg-remote-mobile/issues)
335
+ - [AGENT.md](AGENT.md) and [.agent/](.agent/README.md) — onboarding, architecture, deployment,
336
+ checks, troubleshooting and design decisions for anyone (agent or human) working in this repo.
302
337
  - [PROTOCOL.md](PROTOCOL.md) — authoritative HTTP/WebSocket wire contract.
303
338
  - [SECURITY.md](SECURITY.md) — threat model and revocation/rotation procedures; report
304
339
  vulnerabilities through the repository's private advisory form.
package/SECURITY.md CHANGED
@@ -47,6 +47,10 @@ internet.
47
47
  outcomes), pairing device names, approval/push event identifiers and the bounded
48
48
  `POST /api/push/report` diagnostics line. Client-supplied diagnostic fields are collapsed to
49
49
  a single bounded line; no transcript text, prompt, tool argument, cookie or key is logged.
50
+ - **Drafts and unsent prompts never leave page memory.** Per-session composer text, a failed
51
+ prompt bubble kept for retry, and the rendered transcript are not written to
52
+ `localStorage`/`IndexedDB`, so closing the tab drops them and the phone does not keep a second
53
+ copy of the conversation. Only the shell assets are cached by the service worker.
50
54
 
51
55
  ## Approvals
52
56
 
@@ -70,6 +74,10 @@ command. The rules are:
70
74
  - Approval cards show a bounded, secret-scrubbed preview of the tool call when the bridge saw
71
75
  it. Values whose argument key looks like a password/secret/token/key/credential are never
72
76
  cached or displayed.
77
+ - Questions use the same exclusive routing, and dismissing one (`question.cancel`) carries the
78
+ same authority as answering it: a paired phone may settle the request without submitting a
79
+ batch. Cancelling is not gated by `canApprove`; it is equivalent to the desktop card's close
80
+ control and never widens permissions.
73
81
  - Only `allowed-once`, `rejected`, `cancelled` and `unavailable` exist; there is no
74
82
  always-allow grant. The Host's `ask | never` policy decides whether a request is raised at
75
83
  all.
package/auth.js CHANGED
@@ -224,6 +224,21 @@ export function createAuth(options = {}) {
224
224
  return publicDevice(device)
225
225
  }
226
226
 
227
+ /**
228
+ * Rename one paired device (the phone may only rename itself).
229
+ * @param {string} deviceId paired-device id
230
+ * @param {string} name display name, trimmed to 1..40 characters
231
+ * @returns the public device, or null when the id is unknown
232
+ */
233
+ function renameDevice(deviceId, name) {
234
+ const device = devices.get(deviceId)
235
+ if (device === undefined) return null
236
+ const clean = String(name ?? '').replace(/\s+/g, ' ').trim().slice(0, 40)
237
+ if (clean.length === 0) return null
238
+ device.name = clean
239
+ return publicDevice(device)
240
+ }
241
+
227
242
  function revokeAll() {
228
243
  const count = devices.size
229
244
  devices.clear()
@@ -281,6 +296,7 @@ export function createAuth(options = {}) {
281
296
  cookieMaxAgeSeconds,
282
297
  revoke,
283
298
  revokeAll,
299
+ renameDevice,
284
300
  setCanApprove,
285
301
  status,
286
302
  exportState,