@wonderwhy-er/desktop-commander 0.3.1-alpha.2 → 0.3.2-alpha.1

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 (234) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +1154 -1152
  3. package/dist/bootstrap.js +0 -0
  4. package/dist/bootstrap.js.map +1 -0
  5. package/dist/command-manager.js +0 -0
  6. package/dist/command-manager.js.map +1 -0
  7. package/dist/config-field-definitions.js +0 -0
  8. package/dist/config-field-definitions.js.map +1 -0
  9. package/dist/config-manager.js +0 -0
  10. package/dist/config-manager.js.map +1 -0
  11. package/dist/config-recovery.js +0 -0
  12. package/dist/config-recovery.js.map +1 -0
  13. package/dist/config.js +0 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/custom-stdio.js +0 -0
  16. package/dist/custom-stdio.js.map +1 -0
  17. package/dist/data/onboarding-prompts.json +70 -70
  18. package/dist/error-handlers.js +0 -0
  19. package/dist/error-handlers.js.map +1 -0
  20. package/dist/handlers/edit-search-handlers.js.map +1 -0
  21. package/dist/handlers/filesystem-handlers.js +2 -2
  22. package/dist/handlers/filesystem-handlers.js.map +1 -0
  23. package/dist/handlers/history-handlers.js.map +1 -0
  24. package/dist/handlers/index.js.map +1 -0
  25. package/dist/handlers/process-handlers.js.map +1 -0
  26. package/dist/handlers/search-answers.js.map +1 -0
  27. package/dist/handlers/search-handlers.js.map +1 -0
  28. package/dist/handlers/terminal-handlers.js.map +1 -0
  29. package/dist/index.js +0 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/npm-scripts/remote.js +32 -28
  32. package/dist/npm-scripts/remote.js.map +1 -0
  33. package/dist/npm-scripts/setup.js.map +1 -0
  34. package/dist/npm-scripts/uninstall.js.map +1 -0
  35. package/dist/npm-scripts/verify-ripgrep.js.map +1 -0
  36. package/dist/remote-device/desktop-commander-integration.d.ts +1 -0
  37. package/dist/remote-device/desktop-commander-integration.js.map +1 -0
  38. package/dist/remote-device/device-authenticator.js.map +1 -0
  39. package/dist/remote-device/device.d.ts +4 -3
  40. package/dist/remote-device/device.js +134 -35
  41. package/dist/remote-device/device.js.map +1 -0
  42. package/dist/remote-device/diagnostics/device-log.js.map +1 -0
  43. package/dist/remote-device/diagnostics/redact.js.map +1 -0
  44. package/dist/remote-device/diagnostics/report.js +2 -1
  45. package/dist/remote-device/diagnostics/report.js.map +1 -0
  46. package/dist/remote-device/diagnostics/upload.d.ts +1 -1
  47. package/dist/remote-device/diagnostics/upload.js +3 -3
  48. package/dist/remote-device/diagnostics/upload.js.map +1 -0
  49. package/dist/remote-device/mqtt/config.d.ts +1 -0
  50. package/dist/remote-device/mqtt/config.js +3 -0
  51. package/dist/remote-device/mqtt/config.js.map +1 -0
  52. package/dist/remote-device/mqtt/mqtt-enrollment.d.ts +15 -0
  53. package/dist/remote-device/mqtt/mqtt-enrollment.js +293 -0
  54. package/dist/remote-device/mqtt/mqtt-enrollment.js.map +1 -0
  55. package/dist/remote-device/mqtt/mqtt-transport.d.ts +45 -0
  56. package/dist/remote-device/mqtt/mqtt-transport.js +276 -0
  57. package/dist/remote-device/mqtt/mqtt-transport.js.map +1 -0
  58. package/dist/remote-device/realtime-health-telemetry.d.ts +35 -0
  59. package/dist/remote-device/realtime-health-telemetry.js +110 -0
  60. package/dist/remote-device/realtime-health-telemetry.js.map +1 -0
  61. package/dist/remote-device/remote-channel.d.ts +87 -59
  62. package/dist/remote-device/remote-channel.js +509 -398
  63. package/dist/remote-device/remote-channel.js.map +1 -0
  64. package/dist/remote-device/remote-utils.d.ts +3 -0
  65. package/dist/remote-device/remote-utils.js +20 -0
  66. package/dist/remote-device/remote-utils.js.map +1 -0
  67. package/dist/remote-device/rollouts.d.ts +48 -0
  68. package/dist/remote-device/rollouts.js +105 -0
  69. package/dist/remote-device/rollouts.js.map +1 -0
  70. package/dist/remote-device/scripts/blocking-offline-update.js +135 -133
  71. package/dist/remote-device/transport-telemetry.d.ts +1 -1
  72. package/dist/remote-device/transport-telemetry.js +4 -2
  73. package/dist/remote-device/transport-telemetry.js.map +1 -0
  74. package/dist/search-manager.js +0 -0
  75. package/dist/search-manager.js.map +1 -0
  76. package/dist/server.js +581 -712
  77. package/dist/server.js.map +1 -0
  78. package/dist/setup-claude-server.js +942 -942
  79. package/dist/terminal-manager.js +2 -37
  80. package/dist/terminal-manager.js.map +1 -0
  81. package/dist/tools/config.js.map +1 -0
  82. package/dist/tools/edit.js +2 -2
  83. package/dist/tools/edit.js.map +1 -0
  84. package/dist/tools/feedback.js.map +1 -0
  85. package/dist/tools/filesystem.js.map +1 -0
  86. package/dist/tools/fuzzySearch.js +9 -9
  87. package/dist/tools/fuzzySearch.js.map +1 -0
  88. package/dist/tools/fuzzySearchCore.js.map +1 -0
  89. package/dist/tools/improved-process-tools.js +12 -11
  90. package/dist/tools/improved-process-tools.js.map +1 -0
  91. package/dist/tools/mime-types.js.map +1 -0
  92. package/dist/tools/pdf/extract-images.js +2 -6
  93. package/dist/tools/pdf/extract-images.js.map +1 -0
  94. package/dist/tools/pdf/index.js.map +1 -0
  95. package/dist/tools/pdf/lib/pdf2md.js +28 -33
  96. package/dist/tools/pdf/lib/pdf2md.js.map +1 -0
  97. package/dist/tools/pdf/manipulations.js.map +1 -0
  98. package/dist/tools/pdf/markdown.d.ts +10 -38
  99. package/dist/tools/pdf/markdown.js.map +1 -0
  100. package/dist/tools/pdf/utils.d.ts +10 -0
  101. package/dist/tools/pdf/utils.js +11 -0
  102. package/dist/tools/pdf/utils.js.map +1 -0
  103. package/dist/tools/process.js.map +1 -0
  104. package/dist/tools/prompts.js +1 -1
  105. package/dist/tools/prompts.js.map +1 -0
  106. package/dist/tools/schemas.d.ts +0 -10
  107. package/dist/tools/schemas.js +0 -8
  108. package/dist/tools/schemas.js.map +1 -0
  109. package/dist/tools/usage.js.map +1 -0
  110. package/dist/track-installation.js +387 -387
  111. package/dist/types.js +0 -0
  112. package/dist/types.js.map +1 -0
  113. package/dist/ui/config-editor/config-editor-runtime.js +61 -80
  114. package/dist/ui/config-editor/index.html +13 -13
  115. package/dist/ui/config-editor/src/app.js +30 -30
  116. package/dist/ui/config-editor/src/app.js.map +1 -0
  117. package/dist/ui/config-editor/src/array-modal.js +32 -32
  118. package/dist/ui/config-editor/src/array-modal.js.map +1 -0
  119. package/dist/ui/config-editor/src/main.js.map +1 -0
  120. package/dist/ui/config-editor/styles.css +586 -586
  121. package/dist/ui/contracts.d.ts +27 -0
  122. package/dist/ui/contracts.js +36 -0
  123. package/dist/ui/contracts.js.map +1 -0
  124. package/dist/ui/file-preview/index.html +16 -16
  125. package/dist/ui/file-preview/preview-runtime.js +221 -231
  126. package/dist/ui/file-preview/shared/preview-file-types.js.map +1 -0
  127. package/dist/ui/file-preview/src/app.js +8 -8
  128. package/dist/ui/file-preview/src/app.js.map +1 -0
  129. package/dist/ui/file-preview/src/components/code-viewer.js.map +1 -0
  130. package/dist/ui/file-preview/src/components/highlighting.js.map +1 -0
  131. package/dist/ui/file-preview/src/components/html-renderer.js +4 -2
  132. package/dist/ui/file-preview/src/components/html-renderer.js.map +1 -0
  133. package/dist/ui/file-preview/src/components/markdown-renderer.js.map +1 -0
  134. package/dist/ui/file-preview/src/directory-controller.js.map +1 -0
  135. package/dist/ui/file-preview/src/document-layout.js +31 -31
  136. package/dist/ui/file-preview/src/document-layout.js.map +1 -0
  137. package/dist/ui/file-preview/src/document-outline.js +8 -8
  138. package/dist/ui/file-preview/src/document-outline.js.map +1 -0
  139. package/dist/ui/file-preview/src/document-workspace.js.map +1 -0
  140. package/dist/ui/file-preview/src/file-type-handlers.js.map +1 -0
  141. package/dist/ui/file-preview/src/host/external-actions.js.map +1 -0
  142. package/dist/ui/file-preview/src/host/selection-context.js.map +1 -0
  143. package/dist/ui/file-preview/src/image-preview.js.map +1 -0
  144. package/dist/ui/file-preview/src/main.js.map +1 -0
  145. package/dist/ui/file-preview/src/markdown/conflict-dialog.js +33 -33
  146. package/dist/ui/file-preview/src/markdown/conflict-dialog.js.map +1 -0
  147. package/dist/ui/file-preview/src/markdown/controller.js +9 -9
  148. package/dist/ui/file-preview/src/markdown/controller.js.map +1 -0
  149. package/dist/ui/file-preview/src/markdown/editor.js +31 -31
  150. package/dist/ui/file-preview/src/markdown/editor.js.map +1 -0
  151. package/dist/ui/file-preview/src/markdown/linking.js.map +1 -0
  152. package/dist/ui/file-preview/src/markdown/outline.js.map +1 -0
  153. package/dist/ui/file-preview/src/markdown/parser.js.map +1 -0
  154. package/dist/ui/file-preview/src/markdown/preview.js.map +1 -0
  155. package/dist/ui/file-preview/src/markdown/slugify.js.map +1 -0
  156. package/dist/ui/file-preview/src/markdown/utils.js.map +1 -0
  157. package/dist/ui/file-preview/src/model.js.map +1 -0
  158. package/dist/ui/file-preview/src/panel-actions.js.map +1 -0
  159. package/dist/ui/file-preview/src/path-utils.js.map +1 -0
  160. package/dist/ui/file-preview/src/payload-utils.js.map +1 -0
  161. package/dist/ui/file-preview/src/types.js.map +1 -0
  162. package/dist/ui/file-preview/styles.css +1630 -1630
  163. package/dist/ui/resources.js +11 -4
  164. package/dist/ui/resources.js.map +1 -0
  165. package/dist/ui/shared/compact-row.js.map +1 -0
  166. package/dist/ui/shared/escape-html.js.map +1 -0
  167. package/dist/ui/shared/host-context.js.map +1 -0
  168. package/dist/ui/shared/tool-bridge.js.map +1 -0
  169. package/dist/ui/shared/tool-shell.js.map +1 -0
  170. package/dist/ui/shared/ui-event-tracker.js.map +1 -0
  171. package/dist/ui/shared/widget-state.js.map +1 -0
  172. package/dist/uninstall-claude-server.js +745 -745
  173. package/dist/utils/ab-test.js.map +1 -0
  174. package/dist/utils/atomic-write.js.map +1 -0
  175. package/dist/utils/capture.d.ts +1 -1
  176. package/dist/utils/capture.js +28 -6
  177. package/dist/utils/capture.js.map +1 -0
  178. package/dist/utils/dockerPrompt.js.map +1 -0
  179. package/dist/utils/exit-process.js.map +1 -0
  180. package/dist/utils/feature-flags.js.map +1 -0
  181. package/dist/utils/files/base.js.map +1 -0
  182. package/dist/utils/files/binary.js +4 -4
  183. package/dist/utils/files/binary.js.map +1 -0
  184. package/dist/utils/files/docx.js.map +1 -0
  185. package/dist/utils/files/excel.js +3 -3
  186. package/dist/utils/files/excel.js.map +1 -0
  187. package/dist/utils/files/factory.js.map +1 -0
  188. package/dist/utils/files/image.js.map +1 -0
  189. package/dist/utils/files/index.js.map +1 -0
  190. package/dist/utils/files/pdf.js.map +1 -0
  191. package/dist/utils/files/text.d.ts +7 -0
  192. package/dist/utils/files/text.js +40 -21
  193. package/dist/utils/files/text.js.map +1 -0
  194. package/dist/utils/fuzzySearchLogger.js.map +1 -0
  195. package/dist/utils/internal-facts.js.map +1 -0
  196. package/dist/utils/lazy-package.js.map +1 -0
  197. package/dist/utils/lineEndingHandler.js.map +1 -0
  198. package/dist/utils/logger.js.map +1 -0
  199. package/dist/utils/mcp-ui-ab-test.js.map +1 -0
  200. package/dist/utils/open-browser.js.map +1 -0
  201. package/dist/utils/process-detection.js.map +1 -0
  202. package/dist/utils/process-tree.js.map +1 -0
  203. package/dist/utils/rename.js.map +1 -0
  204. package/dist/utils/ripgrep-resolver.js.map +1 -0
  205. package/dist/utils/shell.d.ts +11 -0
  206. package/dist/utils/shell.js +50 -0
  207. package/dist/utils/shell.js.map +1 -0
  208. package/dist/utils/system-info.d.ts +1 -0
  209. package/dist/utils/system-info.js +110 -97
  210. package/dist/utils/system-info.js.map +1 -0
  211. package/dist/utils/terminal-timestamps.d.ts +2 -0
  212. package/dist/utils/terminal-timestamps.js +18 -0
  213. package/dist/utils/terminal-timestamps.js.map +1 -0
  214. package/dist/utils/toolHistory.js.map +1 -0
  215. package/dist/utils/trackTools.js.map +1 -0
  216. package/dist/utils/unsupportedParams.js.map +1 -0
  217. package/dist/utils/usageTracker.d.ts +0 -39
  218. package/dist/utils/usageTracker.js +16 -176
  219. package/dist/utils/usageTracker.js.map +1 -0
  220. package/dist/utils/welcome-onboarding.js.map +1 -0
  221. package/dist/utils/withTimeout.js.map +1 -0
  222. package/dist/version.d.ts +1 -1
  223. package/dist/version.js +1 -1
  224. package/dist/version.js.map +1 -0
  225. package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -56
  226. package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -32
  227. package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +39 -38
  228. package/node_modules/@desktop-commander/telemetry-contract/transport.js +167 -164
  229. package/package.json +11 -10
  230. package/vendor/telemetry-contract/README.md +56 -56
  231. package/vendor/telemetry-contract/package.json +32 -32
  232. package/vendor/telemetry-contract/transport.d.ts +38 -38
  233. package/vendor/telemetry-contract/transport.js +164 -164
  234. package/vendor/telemetry-contract/transport.test.js +39 -39
@@ -0,0 +1,35 @@
1
+ export type RealtimeCounter = 'explicit_subscribe_calls' | 'join_successes' | 'join_errors' | 'join_timeouts' | 'join_closures' | 'watchdog_recreates' | 'socket_disconnects' | 'presence_attempts' | 'presence_successes' | 'presence_failures' | 'readiness_write_failures';
2
+ export type RealtimeWindow = Record<RealtimeCounter, number> & {
3
+ event_version: number;
4
+ device_diag_id: string;
5
+ process_session_id: string;
6
+ channel_generation: number;
7
+ window_start: string;
8
+ window_seconds: number;
9
+ app_version: string;
10
+ platform: string;
11
+ };
12
+ export declare class RealtimeHealthTelemetry {
13
+ private readonly emit;
14
+ private readonly sample;
15
+ private readonly random;
16
+ readonly processSessionId: `${string}-${string}-${string}-${string}-${string}`;
17
+ private deviceDiagId;
18
+ private generation;
19
+ private counts;
20
+ private windowStart;
21
+ private windowStartMonotonic;
22
+ private socketState;
23
+ private timer;
24
+ constructor(emit: (window: RealtimeWindow) => void, sample?: (key: string) => number, random?: () => number);
25
+ private emptyCounts;
26
+ /** Stable for one registered device, unlinkable to its raw UUID without knowing the UUID. */
27
+ setDevice(deviceId: string): void;
28
+ newChannel(): void;
29
+ record(key: RealtimeCounter): void;
30
+ observeSocketState(state: string): void;
31
+ start(): void;
32
+ private schedule;
33
+ flush(now?: number, monotonicNow?: number): RealtimeWindow | null;
34
+ stop(): void;
35
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Low-volume Realtime lifecycle counters. No per-retry HTTP requests.
3
+ * Counts are local observations, NOT exact Phoenix phx_join wire frames.
4
+ */
5
+ import { createHash, randomUUID } from 'node:crypto';
6
+ import { VERSION } from '../version.js';
7
+ const COUNTERS = [
8
+ 'explicit_subscribe_calls', 'join_successes', 'join_errors',
9
+ 'join_timeouts', 'join_closures', 'watchdog_recreates',
10
+ 'socket_disconnects', 'presence_attempts', 'presence_successes',
11
+ 'presence_failures', 'readiness_write_failures',
12
+ ];
13
+ const DEGRADED = [
14
+ 'join_errors', 'join_timeouts', 'join_closures', 'watchdog_recreates',
15
+ 'socket_disconnects', 'presence_failures', 'readiness_write_failures',
16
+ ];
17
+ export class RealtimeHealthTelemetry {
18
+ constructor(emit, sample = (key) => parseInt(createHash('sha256').update(key).digest('hex').slice(0, 8), 16) / 0x100000000, random = Math.random) {
19
+ this.emit = emit;
20
+ this.sample = sample;
21
+ this.random = random;
22
+ this.processSessionId = randomUUID();
23
+ this.deviceDiagId = '';
24
+ this.generation = 0;
25
+ this.counts = this.emptyCounts();
26
+ this.windowStart = Date.now();
27
+ this.windowStartMonotonic = performance.now();
28
+ this.socketState = null;
29
+ this.timer = null;
30
+ }
31
+ emptyCounts() {
32
+ return Object.fromEntries(COUNTERS.map((key) => [key, 0]));
33
+ }
34
+ /** Stable for one registered device, unlinkable to its raw UUID without knowing the UUID. */
35
+ setDevice(deviceId) {
36
+ if (!deviceId)
37
+ return;
38
+ const id = createHash('sha256').update('dc-realtime-diagnostics-v1:').update(deviceId).digest('hex').slice(0, 32);
39
+ if (this.deviceDiagId === id)
40
+ return;
41
+ this.deviceDiagId = id;
42
+ this.windowStart = Date.now();
43
+ this.windowStartMonotonic = performance.now();
44
+ this.counts = this.emptyCounts();
45
+ }
46
+ newChannel() {
47
+ this.generation++;
48
+ this.record('explicit_subscribe_calls');
49
+ }
50
+ record(key) {
51
+ this.counts[key]++;
52
+ }
53
+ observeSocketState(state) {
54
+ if (this.socketState === 'open' && state !== 'open')
55
+ this.record('socket_disconnects');
56
+ this.socketState = state;
57
+ }
58
+ start() {
59
+ if (this.timer)
60
+ return;
61
+ this.schedule();
62
+ }
63
+ schedule() {
64
+ // Each device chooses a different reporting boundary; never a fleet-wide minute mark.
65
+ this.timer = setTimeout(() => {
66
+ this.timer = null;
67
+ this.flush();
68
+ this.schedule();
69
+ }, 60000 + Math.floor(this.random() * 30000));
70
+ this.timer.unref?.();
71
+ }
72
+ flush(now = Date.now(), monotonicNow = performance.now()) {
73
+ // Wall time may jump when observeServerDate() corrects clock skew.
74
+ // Use only monotonic time for durations; wall time still locates the window.
75
+ const elapsed = Math.max(1, Math.round((monotonicNow - this.windowStartMonotonic) / 1000));
76
+ const counts = this.counts;
77
+ const start = this.windowStart;
78
+ this.counts = this.emptyCounts();
79
+ this.windowStart = now;
80
+ this.windowStartMonotonic = monotonicNow;
81
+ if (!this.deviceDiagId)
82
+ return null;
83
+ const degraded = DEGRADED.some((key) => counts[key] > 0);
84
+ const sampleRate = degraded ? 0.05 : 0.01;
85
+ if (this.sample(this.deviceDiagId) >= sampleRate)
86
+ return null;
87
+ const window = {
88
+ ...counts,
89
+ event_version: 1,
90
+ device_diag_id: this.deviceDiagId,
91
+ process_session_id: this.processSessionId,
92
+ channel_generation: this.generation,
93
+ window_start: new Date(start).toISOString(),
94
+ window_seconds: elapsed,
95
+ app_version: VERSION,
96
+ platform: process.platform,
97
+ };
98
+ try {
99
+ this.emit(window);
100
+ }
101
+ catch { /* diagnostics must not affect transport */ }
102
+ return window;
103
+ }
104
+ stop() {
105
+ if (this.timer)
106
+ clearTimeout(this.timer);
107
+ this.timer = null;
108
+ this.flush();
109
+ }
110
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtime-health-telemetry.js","sourceRoot":"","sources":["../../src/remote-device/realtime-health-telemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,UAA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,IAAI,CAAC,YAAY;YACjC,kBAAkB,EAAE,IAAI,CAAC,gBAAgB;YACzC,kBAAkB,EAAE,IAAI,CAAC,UAAU;YACnC,YAAY,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE;YAC3C,cAAc,EAAE,OAAO;YACvB,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC7B,CAAC;QACF,IAAI,CAAC;YAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,2CAA2C,CAAC,CAAC;QAChF,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,IAAI;QACA,IAAI,IAAI,CAAC,KAAK;YAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;CACJ"}
@@ -12,7 +12,7 @@ export interface AuthSession {
12
12
  }
13
13
  /**
14
14
  * The device registered, but its realtime channel is not usable — the join
15
- * failed, or presence was never acknowledged. Distinct from every other
15
+ * failed, or the device row could not be marked ready. Distinct from every other
16
16
  * registration failure on purpose: this one the socket watchdog can repair, so
17
17
  * the caller keeps the process alive, while a failed lookup or a missing row
18
18
  * happens before the recreation parameters are stored and nothing can repair it.
@@ -27,18 +27,23 @@ interface DeviceData {
27
27
  status: string;
28
28
  last_seen: string;
29
29
  }
30
- /** Jittered version of realtime-js's default 1s/2s/5s/10s stepped backoff. */
30
+ export declare const HEARTBEAT_INTERVAL_MS: number;
31
+ /** Exponential-ish SDK backoff. Attempts 1-4 preserve short recovery latency. */
31
32
  export declare function realtimeReconnectDelayMs(tries: number, random?: () => number): number;
32
- /** Preserve Presence's existing 500ms-per-attempt retry shape, but desynchronize it. */
33
- export declare function presenceRetryDelayMs(failedAttempt: number, random?: () => number): number;
33
+ /** Watchdog must not defeat the SDK's slower persistent-failure backoff. */
34
+ export declare function watchdogRecreateDelayMs(tries: number, random?: () => number): number;
35
+ /**
36
+ * Wait before the next track() after failed ones, across SDK rejoins and
37
+ * recreates. Never shorter than the step; up to 50% extra spreads the fleet.
38
+ */
39
+ export declare function presenceRecoveryDelayMs(failures: number, random?: () => number): number;
34
40
  export declare function observeServerDate(dateHeader: string | null): void;
35
41
  export declare class RemoteChannel {
42
+ private readonly enrollment?;
36
43
  private client;
37
44
  private channel;
38
45
  private heartbeatInterval;
39
46
  private connectionCheckInterval;
40
- /** Device the heartbeat timer maintains; null = stopped, so re-arm is inert. */
41
- private heartbeatDeviceId;
42
47
  private statusWriteChain;
43
48
  /**
44
49
  * Answers whether the local execution child is alive. Default yes, so a
@@ -56,23 +61,35 @@ export declare class RemoteChannel {
56
61
  /** Auth session gone for good: stops rejoins and caps the notice at one line. */
57
62
  private sessionLost;
58
63
  private handlingSignedOut;
64
+ private mqttReceiver;
65
+ private mqttReady;
66
+ private mqttCapabilityWriteChain;
67
+ private authGeneration;
59
68
  private deviceId;
60
69
  private deviceName;
61
70
  private onToolCall;
62
71
  private authListenerRegistered;
63
- /** False when presence publishing failed on an otherwise healthy channel;
64
- * the health check retries, since SUBSCRIBED won't fire again. */
72
+ /** The current join's status write landed: dispatchable. Gates the
73
+ * heartbeat, so only that write first marks the row online. */
74
+ private channelReady;
75
+ /** Readiness write in flight. Cleared on every join, so each join writes its own. */
76
+ private readinessInFlight;
77
+ private consecutiveReadinessFailures;
78
+ private nextReadinessAttemptAt;
79
+ /** Presence published on the current join. Dashboard only; never gates dispatch. */
65
80
  private presenceTracked;
66
- /** Last capability value written (null = never), to avoid redundant writes. */
67
- private transportCapableWritten;
68
- /** Value of the last capability write still queued or in flight; null once the queue is idle. */
69
- private transportCapableQueued;
70
- private capabilityWriteChain;
71
- /** Monotonic start of a Presence-only degradation while broadcast remains joined. */
72
- private presenceFailureStartedAt;
73
81
  /** Re-entrancy guard: on a wedged socket each track() buffers for the full
74
82
  * 10s push timeout, so 10s health ticks would stack pushes. */
75
83
  private isTrackingPresence;
84
+ private consecutiveUnreadyJoins;
85
+ private consecutivePresenceFailures;
86
+ private nextPresenceAttemptAt;
87
+ /** performance.now() of the latest SUBSCRIBED; null while not joined. */
88
+ private joinedAt;
89
+ /** SDK channel and socket timers share reconnectAfterMs. The persistent
90
+ * unready-join budget prevents a series of partial successes restarting at 1s. */
91
+ private reconnectDelayMs;
92
+ private readonly realtimeHealth;
76
93
  private lastDeviceStatus;
77
94
  private lastChannelState;
78
95
  private reconnectAttempt;
@@ -89,6 +106,9 @@ export declare class RemoteChannel {
89
106
  private tokenRefreshInterval;
90
107
  private _user;
91
108
  get user(): User | null;
109
+ constructor(enrollment?: {
110
+ serverUrl: string;
111
+ } | undefined);
92
112
  initialize(url: string, key: string): void;
93
113
  /**
94
114
  * Teach the channel how to ask whether the local executor is alive.
@@ -120,51 +140,64 @@ export declare class RemoteChannel {
120
140
  };
121
141
  error: any;
122
142
  }>;
143
+ /**
144
+ * The session's current access token, for the realtime socket and the
145
+ * device's own requests. getSession() may refresh on-demand when the token
146
+ * reads expired — that check is clock-skew-safe now (see clockAwareFetch
147
+ * above). Without a session it falls back to the last token known, and
148
+ * without that it is null, never the anon key.
149
+ */
150
+ getAccessToken(): Promise<string | null>;
123
151
  findDevice(deviceId: string): Promise<{
124
152
  id: any;
125
153
  device_name: any;
126
154
  } | null>;
127
155
  updateDevice(deviceId: string, updates: any): Promise<{
128
156
  data: any[] | null;
129
- error: import("@supabase/postgrest-js").PostgrestError | null;
157
+ error: import("@supabase/supabase-js").PostgrestError | null;
130
158
  }>;
131
159
  createDevice(deviceData: DeviceData): Promise<{
132
160
  data: any;
133
161
  error: null;
134
162
  }>;
135
163
  registerDevice(capabilities: any, currentDeviceId: string | undefined, deviceName: string, onToolCall: (payload: any) => void): Promise<void>;
164
+ private startMqtt;
165
+ private prepareMqttConfig;
166
+ private startMqttTransport;
167
+ private stopMqttTransport;
168
+ private setMqttReady;
169
+ /** MQTT delivery hook; this branch records receipts without executing calls. */
170
+ private onMqttDoorbell;
171
+ private onBroadcastDoorbell;
136
172
  /**
137
- * Publish presence, retrying a non-'ok' result — track() resolves with a
138
- * status rather than rejecting, and absent presence reads as offline on the
139
- * dashboard. `presenceTracked` lets the health check retry later.
173
+ * Mark this join dispatchable by writing `status`. The write has to land —
174
+ * Supabase reports a refused write in the result rather than by throwing.
175
+ * The health check retries on its own cooldown.
140
176
  */
141
- private trackPresenceWithRetry;
142
- private trackPresenceInner;
177
+ private markChannelReady;
178
+ private markChannelReadyInner;
143
179
  /**
144
- * The complete `capabilities` JSONB value. One place only: every write
145
- * replaces the whole column, so a second literal would silently drop keys.
180
+ * Publish presence for the dashboard. Best effort: one track() per call,
181
+ * no effect on readiness, and a growing cooldown after each failure — a
182
+ * track() timeout on the server can end the whole channel, and every
183
+ * rejoin would otherwise publish again.
146
184
  */
147
- private capabilitiesPayload;
185
+ private trackPresence;
186
+ /** Presence is withheld by its cooldown right now. Monotonic, so a Date.now
187
+ * skew correction cannot shorten or extend it. */
188
+ private presenceInCooldown;
148
189
  /**
149
- * Advertise (or withdraw) the broadcast capability. Only true while genuinely
150
- * reachable that way — the server fails dispatch fast without it and picks
151
- * the offline-sweep tier from it, so every change must re-arm the heartbeat.
152
- *
153
- * Writes are queued, like the status writes. A withdrawal the recreate stops
154
- * waiting for still lands: compared with the last landed value, a re-publish
155
- * in the meantime looked redundant and was skipped, and the withdrawal then
156
- * left a device that claims to be online without the flag. Resolves with
157
- * whether the row holds `capable` once this write is done.
190
+ * The complete `capabilities` JSONB value. The write replaces the whole
191
+ * column, so a key left out here is dropped from the row.
158
192
  */
159
- private setTransportCapable;
160
- private writeTransportCapable;
193
+ private capabilitiesPayload;
161
194
  /** Aborts one write to this device's row after DEVICE_ROW_WRITE_TIMEOUT_MS (a method, so tests can shorten it). */
162
195
  private deviceRowWriteSignal;
163
196
  /** Create and subscribe the private channel (initial join and recreation). */
164
197
  private createChannel;
165
198
  /**
166
- * Recover calls whose Realtime doorbell was missed while this device was
167
- * disconnected. Broadcast provides the fast path; the DB row is the source
199
+ * Recover calls whose doorbell was missed while this device was
200
+ * disconnected. Notifications provide the fast path; the DB row is the source
168
201
  * of truth. Only still-live pending rows for this device are considered.
169
202
  *
170
203
  * The follow-up onDoorbell() call performs the existing conditional claim,
@@ -212,18 +245,21 @@ export declare class RemoteChannel {
212
245
  * Claim a call. True only when THIS update flipped the row pending ->
213
246
  * executing, which is what makes dual delivery safe across processes.
214
247
  * .eq('status','pending') makes it conditional; .select('id') makes the
215
- * result observable. On a transient DB error it returns true (execute
216
- * anyway), matching prior behaviour — so device.ts's in-memory guard is what
248
+ * result observable. Expiry is checked using Postgres time, not the
249
+ * device clock. On a transient DB error it returns true (execute anyway),
250
+ * matching prior behaviour — so device.ts's in-memory guard is what
217
251
  * actually guarantees exactly-once within a process.
218
252
  */
219
253
  markCallExecuting(callId: string): Promise<boolean>;
220
- updateCallResult(callId: string, status: string, result?: any, errorMessage?: string | null): Promise<void>;
254
+ updateCallResult(callId: string, status: string, result?: any, errorMessage?: string | null, originInstance?: string): Promise<void>;
255
+ private publishMqttResult;
221
256
  /**
222
257
  * Reachable means all of it is true at once: the private channel is
223
- * joined, this device has published its presence, and the local executor
224
- * answers. The server needs the first two before it will dispatch, and a
225
- * healthy channel on a device whose executor is dead is the false-online
226
- * state issue #4 was opened for. Gates the heartbeat and `status`.
258
+ * joined, the join's status write landed, and the local executor answers.
259
+ * The server needs the first two before it will dispatch, and a healthy
260
+ * channel on a device whose executor is dead is the false-online state
261
+ * issue #4 was opened for. Presence is not part of it. Gates the heartbeat
262
+ * and `status`.
227
263
  */
228
264
  private isReachable;
229
265
  /**
@@ -239,28 +275,20 @@ export declare class RemoteChannel {
239
275
  /** Resolves with whether the row actually took the write. */
240
276
  syncReachabilityStatus(): Promise<boolean>;
241
277
  /**
242
- * Serialize the channel-callback status writes. They fire from un-awaited
243
- * callbacks, and inside recreateChannel() a teardown's 'offline' and the
244
- * fresh join's 'online' land ~100-300ms apart — unordered, 'offline' can win
245
- * and leave a healthy device undispatchable until the next heartbeat.
278
+ * Serialize the status writes, the heartbeat's included. They fire from
279
+ * un-awaited callbacks, and inside recreateChannel() a teardown's 'offline'
280
+ * and the fresh join's 'online' land ~100-300ms apart — unordered, 'offline'
281
+ * can win and leave a healthy device undispatchable until the next heartbeat.
246
282
  *
247
- * Not the single writer: updateHeartbeat, registerDevice and setOffline's
248
- * subprocess write status directly, so this is not total ordering.
283
+ * Not the single writer: registerDevice and setOffline's subprocess write
284
+ * status directly, so this is not total ordering.
249
285
  */
250
286
  private queueStatusWrite;
251
- /**
252
- * Heartbeat cadence for the tier this device is CURRENTLY in. Follows the
253
- * capability flag (what the server actually tiers its sweep on), not the
254
- * build — see LEGACY_HEARTBEAT_INTERVAL.
255
- */
256
- private heartbeatIntervalMs;
257
- updateHeartbeat(deviceId: string): Promise<void>;
287
+ updateHeartbeat(): Promise<void>;
258
288
  startHeartbeat(deviceId: string): void;
259
289
  private refreshTokenNow;
260
290
  private startTokenRefresh;
261
291
  private stopTokenRefresh;
262
- /** Arm (or re-arm) the last_seen timer at the current tier's cadence. */
263
- private scheduleHeartbeat;
264
292
  stopHeartbeat(): void;
265
293
  /** @returns whether the row actually took the write. */
266
294
  setOnlineStatus(deviceId: string, status: 'online' | 'offline'): Promise<boolean>;