@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/mobile/index.html CHANGED
@@ -18,7 +18,10 @@
18
18
  <link rel="apple-touch-icon" href="/icons/apple-touch-icon.png">
19
19
  <!-- Theme resolution lives in app.js: the Host serves a strict
20
20
  script-src 'self' CSP, so this page intentionally carries no inline script. -->
21
- <link rel="stylesheet" href="/styles.css?v=20">
21
+ <link rel="stylesheet" href="/styles/tokens.css?v=1">
22
+ <link rel="stylesheet" href="/styles/base.css?v=1">
23
+ <link rel="stylesheet" href="/styles/components.css?v=1">
24
+ <link rel="stylesheet" href="/styles/overrides.css?v=1">
22
25
  </head>
23
26
  <body>
24
27
  <!-- Icon sprite: kept inline so the SPA stays a single network round-trip and
@@ -52,6 +55,9 @@
52
55
  <symbol id="i-chevron-right" viewBox="0 0 24 24">
53
56
  <path d="m9.4 6.2 5.8 5.8-5.8 5.8"></path>
54
57
  </symbol>
58
+ <symbol id="i-chevron-left" viewBox="0 0 24 24">
59
+ <path d="m14.6 6.2-5.8 5.8 5.8 5.8"></path>
60
+ </symbol>
55
61
  <symbol id="i-check" viewBox="0 0 24 24">
56
62
  <path d="m4.8 12.4 4.7 4.7L19.4 7"></path>
57
63
  </symbol>
@@ -140,6 +146,10 @@
140
146
  <path d="M6.4 16.8V11a5.6 5.6 0 0 1 11.2 0v5.8l1.7 2.2H4.7l1.7-2.2Z"></path>
141
147
  <path d="M10.1 19.6a1.9 1.9 0 0 0 3.8 0"></path>
142
148
  </symbol>
149
+ <symbol id="i-clock" viewBox="0 0 24 24">
150
+ <circle cx="12" cy="12" r="8.2"></circle>
151
+ <path d="M12 7.6V12l3 1.8"></path>
152
+ </symbol>
143
153
  <symbol id="i-camera" viewBox="0 0 24 24">
144
154
  <path d="M4.4 8.6h3.2l1.6-2.2h5.6l1.6 2.2h3.2v10.2H4.4V8.6Z"></path>
145
155
  <circle cx="12" cy="13.6" r="3.2"></circle>
@@ -235,7 +245,10 @@
235
245
  <button class="iconbtn" id="btn-sessions" type="button" aria-label="Sessions" aria-haspopup="dialog">
236
246
  <svg class="icon" aria-hidden="true"><use href="#i-drawer"></use></svg>
237
247
  </button>
238
- <span class="topbar-spacer" aria-hidden="true"></span>
248
+ <button class="iconbtn" id="btn-activity" type="button" aria-label="Show activity" aria-pressed="false" aria-controls="view-activity">
249
+ <svg class="icon" aria-hidden="true"><use href="#i-activity"></use></svg>
250
+ <span class="activity-badge" id="activity-badge" hidden></span>
251
+ </button>
239
252
  </div>
240
253
  <div class="titleblock">
241
254
  <h1 class="session-title" id="session-title">Sessions</h1>
@@ -246,16 +259,16 @@
246
259
  <svg class="icon" aria-hidden="true"><use href="#i-compose"></use></svg>
247
260
  </button>
248
261
  <button class="iconbtn" id="btn-menu" type="button" aria-label="More options" aria-haspopup="dialog">
262
+ <svg class="menu-ring" id="menu-ring" viewBox="0 0 44 44" aria-hidden="true" focusable="false">
263
+ <circle class="menu-ring-track" cx="22" cy="22" r="20" pathLength="1"></circle>
264
+ <circle class="menu-ring-fill" id="menu-ring-fill" cx="22" cy="22" r="20" pathLength="1"></circle>
265
+ </svg>
249
266
  <svg class="icon" aria-hidden="true"><use href="#i-more"></use></svg>
250
267
  </button>
268
+ <span class="visually-hidden" id="menu-context-label"></span>
251
269
  </div>
252
270
  </header>
253
271
 
254
- <div class="tabs" role="tablist" aria-label="Views">
255
- <button class="tab is-active" id="tab-chat" type="button" role="tab" aria-selected="true" aria-controls="view-chat">Chat</button>
256
- <button class="tab" id="tab-activity" type="button" role="tab" aria-selected="false" aria-controls="view-activity">Activity<span class="tab-badge" id="tab-badge" hidden></span></button>
257
- </div>
258
-
259
272
  <div class="banner" id="banner" role="status" hidden>
260
273
  <svg class="icon banner-icon" aria-hidden="true"><use href="#i-wifi-off"></use></svg>
261
274
  <span class="banner-text" id="banner-text">Reconnecting…</span>
@@ -263,7 +276,7 @@
263
276
  </div>
264
277
 
265
278
  <main class="main">
266
- <section class="view view-chat" id="view-chat" role="tabpanel" aria-labelledby="tab-chat">
279
+ <section class="view view-chat" id="view-chat" role="region" aria-label="Chat">
267
280
  <div class="chat-scroll" id="chat-scroll">
268
281
  <div class="messages" id="messages" role="log" aria-live="polite" aria-relevant="additions"></div>
269
282
  </div>
@@ -273,7 +286,7 @@
273
286
  </button>
274
287
  </section>
275
288
 
276
- <section class="view view-activity" id="view-activity" role="tabpanel" aria-labelledby="tab-activity" hidden>
289
+ <section class="view view-activity" id="view-activity" role="region" aria-label="Activity" hidden>
277
290
  <div class="activity-bar">
278
291
  <div class="segmented" id="activity-filter" role="group" aria-label="Filter activity">
279
292
  <button class="seg-btn is-active" type="button" data-filter="all" aria-pressed="true">All</button>
@@ -283,6 +296,7 @@
283
296
  <span class="activity-live" id="activity-live"><span class="live-dot" aria-hidden="true"></span>Live</span>
284
297
  </div>
285
298
  <div class="activity-scroll" id="activity-scroll">
299
+ <div class="subagents-panel" id="subagents-panel" hidden></div>
286
300
  <div class="changes-panel" id="changes-panel" hidden></div>
287
301
  <div class="activity-list" id="activity-list"></div>
288
302
  </div>
@@ -296,6 +310,7 @@
296
310
  <span class="archived-banner-text">Archived session — unarchive to continue</span>
297
311
  <button class="archived-banner-action" id="btn-unarchive" type="button">Unarchive</button>
298
312
  </div>
313
+ <div class="command-suggest" id="command-suggest" role="listbox" aria-label="Command suggestions" hidden></div>
299
314
  <div class="composer-box">
300
315
  <textarea class="composer-input" id="composer-input" rows="1" maxlength="8000" placeholder="Message…"
301
316
  aria-label="Message" enterkeyhint="send" autocapitalize="sentences" spellcheck="true"></textarea>
@@ -311,13 +326,8 @@
311
326
  </button>
312
327
  </div>
313
328
  </div>
314
- <div class="composer-meta">
329
+ <div class="composer-meta" id="composer-meta">
315
330
  <span class="composer-note" id="composer-note">Ready</span>
316
- <div class="context-meter" id="context-meter" role="group" aria-label="Context usage" hidden>
317
- <span class="context-label" id="context-label" aria-hidden="true"></span>
318
- <span class="context-track" aria-hidden="true"><span class="context-fill" id="context-fill"></span></span>
319
- <span class="context-est" id="context-est" aria-hidden="true" hidden>est.</span>
320
- </div>
321
331
  <div class="composer-right">
322
332
  <div class="prompt-mode" id="prompt-mode" role="group" aria-label="Send mode" hidden>
323
333
  <button class="prompt-mode-btn is-active" type="button" data-mode="queue" aria-pressed="true">Queue</button>
@@ -353,7 +363,7 @@
353
363
  <svg class="logo-glyph" aria-hidden="true"><use href="#i-mark"></use></svg>
354
364
  </div>
355
365
  <h2 class="app-lock-title" id="app-lock-title">DSH Remote is locked</h2>
356
- <p class="app-lock-text">Unlock with this phone's biometrics or screen lock to see the session.</p>
366
+ <p class="app-lock-text" id="app-lock-text">Unlock with this phone's biometrics or screen lock to see the session.</p>
357
367
  <button class="btn btn-primary btn-block" id="app-lock-unlock" type="button">Unlock</button>
358
368
  <p class="app-lock-error" id="app-lock-error" role="alert" hidden></p>
359
369
  <p class="app-lock-recovery">Can't unlock? Revoke this device from the desktop pairing panel and pair again.</p>
@@ -363,7 +373,8 @@
363
373
  <div class="toast" id="toast" role="status" aria-live="polite"></div>
364
374
 
365
375
  <noscript><p class="noscript">DSH Remote needs JavaScript enabled.</p></noscript>
366
- <script src="/app.js?v=20" defer></script>
376
+ <div id="sr-announcer" class="visually-hidden" aria-live="polite" aria-atomic="true"></div>
377
+ <script type="module" src="/app.js?v=1" defer></script>
367
378
  </body>
368
379
  </html>
369
380
 
@@ -0,0 +1,45 @@
1
+ // Pure away-summary formatting. The SPA tracks event counts while hidden;
2
+ // this module decides whether the return is worth a recap and how to phrase it.
3
+ export const AWAY_MIN_MS = 15 * 1000
4
+
5
+ export function summarizeAway(events, durationMs, now = Date.now()) {
6
+ const approvals = Number(events?.approvals) || 0
7
+ const questions = Number(events?.questions) || 0
8
+ const finished = Number(events?.finished) || 0
9
+ const errors = Number(events?.errors) || 0
10
+ const total = approvals + questions + finished + errors
11
+ if (!Number.isFinite(durationMs) || durationMs < AWAY_MIN_MS || total === 0) return null
12
+ return {
13
+ durationMs,
14
+ since: now - durationMs,
15
+ approvals,
16
+ questions,
17
+ finished,
18
+ errors,
19
+ total,
20
+ }
21
+ }
22
+
23
+ export function awayHeadline(summary) {
24
+ if (!summary) return ''
25
+ if (summary.approvals > 0 && summary.questions > 0) {
26
+ return (
27
+ summary.approvals +
28
+ ' approval' +
29
+ (summary.approvals === 1 ? '' : 's') +
30
+ ' and ' +
31
+ summary.questions +
32
+ ' question' +
33
+ (summary.questions === 1 ? '' : 's') +
34
+ ' need you'
35
+ )
36
+ }
37
+ if (summary.approvals > 0) {
38
+ return summary.approvals + ' approval' + (summary.approvals === 1 ? ' needs' : 's need') + ' you'
39
+ }
40
+ if (summary.questions > 0) {
41
+ return summary.questions + ' question' + (summary.questions === 1 ? ' needs' : 's need') + ' you'
42
+ }
43
+ if (summary.errors > 0) return summary.errors + ' run' + (summary.errors === 1 ? '' : 's') + ' hit an error'
44
+ return summary.finished + ' turn' + (summary.finished === 1 ? '' : 's') + ' finished'
45
+ }
@@ -0,0 +1,5 @@
1
+ // SPA-only tuning constants. Wire limits live in ../../protocol.js.
2
+
3
+ export const MAX_TOOL_OUTPUT = 120000;
4
+
5
+ export const HISTORY_PAGE = 100;
@@ -0,0 +1,42 @@
1
+ // Error taxonomy for the phone shell: protocol code -> message/action, plus an
2
+ // opt-in debug hook for swallowed failures (?debug=1). No DOM, no state.
3
+ const FALLBACK_MESSAGE = 'The Harness reported an error.'
4
+ const ACTIONS = {
5
+ 'not-live': 'Open the session on the desktop to make it live.',
6
+ forbidden: 'This device is not allowed to do that.',
7
+ unavailable: 'That feature is unavailable on this deployment.',
8
+ 'not-found': 'That item is no longer available.',
9
+ 'bad-request': 'The Host rejected the request.',
10
+ internal: 'The Host hit an internal error.',
11
+ }
12
+
13
+ let debugEnabled = false
14
+
15
+ export function setDebugLogging(enabled) {
16
+ debugEnabled = enabled === true
17
+ }
18
+
19
+ export function isDebugLogging() {
20
+ return debugEnabled
21
+ }
22
+
23
+ export function describeServerError(frame) {
24
+ const code = frame && typeof frame.code === 'string' && frame.code.length > 0 ? frame.code : 'internal'
25
+ const message = frame && typeof frame.message === 'string' && frame.message.length > 0
26
+ ? frame.message
27
+ : FALLBACK_MESSAGE
28
+ return { code, message, action: ACTIONS[code] ?? null }
29
+ }
30
+
31
+ /**
32
+ * Record a failure that the UI intentionally degrades over. Disabled unless the
33
+ * page was opened with ?debug=1 so normal use never logs conversation content.
34
+ */
35
+ export function debugError(scope, detail) {
36
+ if (!debugEnabled) return
37
+ try {
38
+ console.warn('[dsh-remote]', scope, detail)
39
+ } catch {
40
+ /* a console failure must never break the caller */
41
+ }
42
+ }
@@ -0,0 +1,94 @@
1
+ // Pure formatting helpers shared by the SPA renderers. No DOM, no state.
2
+
3
+ export function timeAgo(ts) {
4
+ var t = Number(ts) || 0;
5
+ if (!t) return 'just now';
6
+ var diff = Date.now() - t;
7
+ if (diff < 45000) return 'just now';
8
+ var min = Math.round(diff / 60000);
9
+ if (min < 60) return min + 'm ago';
10
+ var hr = Math.round(min / 60);
11
+ if (hr < 24) return hr + 'h ago';
12
+ var day = Math.round(hr / 24);
13
+ if (day < 7) return day + 'd ago';
14
+ try {
15
+ return new Date(t).toLocaleDateString(undefined, {
16
+ month: 'short',
17
+ day: 'numeric'
18
+ });
19
+ } catch (err) {
20
+ return '';
21
+ }
22
+ }
23
+
24
+ export function fmtClock(ts) {
25
+ var d = new Date(Number(ts) || Date.now());
26
+ try {
27
+ return d.toLocaleTimeString(undefined, {
28
+ hour: '2-digit',
29
+ minute: '2-digit',
30
+ second: '2-digit'
31
+ });
32
+ } catch (err) {
33
+ return '';
34
+ }
35
+ }
36
+
37
+ export function fmtMsgTime(ts) {
38
+ var t = Number(ts) || 0;
39
+ if (!t) return '';
40
+ try {
41
+ return new Date(t).toLocaleTimeString(undefined, {
42
+ hour: '2-digit',
43
+ minute: '2-digit'
44
+ });
45
+ } catch (err) {
46
+ return '';
47
+ }
48
+ }
49
+
50
+ export function isoTime(ts) {
51
+ var t = Number(ts) || 0;
52
+ if (!t) return '';
53
+ try {
54
+ return new Date(t).toISOString();
55
+ } catch (err) {
56
+ return '';
57
+ }
58
+ }
59
+
60
+ export function formatDuration(ms) {
61
+ if (typeof ms !== 'number' || !isFinite(ms)) return '';
62
+ if (ms < 1000) return Math.max(1, Math.round(ms)) + 'ms';
63
+ if (ms < 60000) return (ms / 1000).toFixed(ms < 10000 ? 1 : 0) + 's';
64
+ var mins = Math.floor(ms / 60000);
65
+ var secs = Math.round((ms % 60000) / 1000);
66
+ return mins + 'm ' + secs + 's';
67
+ }
68
+
69
+ export function formatElapsed(ms) {
70
+ if (!ms || ms < 1000) return '0s';
71
+ var secs = Math.floor(ms / 1000);
72
+ if (secs < 60) return secs + 's';
73
+ var mins = Math.floor(secs / 60);
74
+ if (mins < 60) return mins + 'm ' + (secs % 60) + 's';
75
+ var hrs = Math.floor(mins / 60);
76
+ return hrs + 'h ' + (mins % 60) + 'm';
77
+ }
78
+
79
+ export function formatCountdown(ms) {
80
+ var total = Math.max(0, Math.ceil(ms / 1000));
81
+ var mins = Math.floor(total / 60);
82
+ var secs = total % 60;
83
+ return mins + ':' + (secs < 10 ? '0' : '') + secs;
84
+ }
85
+
86
+ export function formatDetail(detail) {
87
+ if (detail === null || detail === undefined || detail === '') return '';
88
+ if (typeof detail === 'string') return detail;
89
+ try {
90
+ return JSON.stringify(detail, null, 2);
91
+ } catch (err) {
92
+ return String(detail);
93
+ }
94
+ }
@@ -0,0 +1,21 @@
1
+ // Decision-lock policy: even after the app is unlocked, an approval or answer
2
+ // requires a recent biometric verification. Pure and unit-testable.
3
+ export const DECISION_GRACE_MS = 2 * 60 * 1000
4
+
5
+ /**
6
+ * @param {object} state app-lock state
7
+ * @param {boolean} state.enabled lock configured for this device
8
+ * @param {boolean} state.supported WebAuthn + secure context available
9
+ * @param {string} state.credentialId stored credential
10
+ * @param {boolean} state.locked overlay currently shown
11
+ * @param {boolean} state.sessionVerified this page session was verified
12
+ * @param {number} state.unlockedAt last successful verification timestamp
13
+ * @param {number} [now] current clock
14
+ * @param {number} [graceMs] how long one verification covers decisions
15
+ */
16
+ export function decisionLockRequired(state, now = Date.now(), graceMs = DECISION_GRACE_MS) {
17
+ if (!state || state.enabled !== true || state.supported !== true) return false
18
+ if (!state.credentialId) return false
19
+ if (state.locked === true || state.sessionVerified !== true) return true
20
+ return now - (Number(state.unlockedAt) || 0) > graceMs
21
+ }
@@ -28,6 +28,30 @@
28
28
  "purpose": "maskable"
29
29
  }
30
30
  ],
31
+ "shortcuts": [
32
+ {
33
+ "name": "New session",
34
+ "short_name": "New",
35
+ "url": "/?shortcut=new",
36
+ "icons": [
37
+ {
38
+ "src": "/icons/icon-192.png",
39
+ "sizes": "192x192"
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ "name": "Needs you",
45
+ "short_name": "Needs you",
46
+ "url": "/?shortcut=needs",
47
+ "icons": [
48
+ {
49
+ "src": "/icons/icon-192.png",
50
+ "sizes": "192x192"
51
+ }
52
+ ]
53
+ }
54
+ ],
31
55
  "share_target": {
32
56
  "action": "/share-target",
33
57
  "method": "GET",