@wonderwhy-er/desktop-commander 0.2.51 → 0.3.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +14 -24
  2. package/dist/command-manager.d.ts +7 -2
  3. package/dist/command-manager.js +16 -11
  4. package/dist/config-manager.d.ts +49 -3
  5. package/dist/config-manager.js +329 -87
  6. package/dist/config-recovery.d.ts +28 -0
  7. package/dist/config-recovery.js +81 -0
  8. package/dist/config.d.ts +1 -0
  9. package/dist/config.js +9 -0
  10. package/dist/handlers/filesystem-handlers.d.ts +1 -1
  11. package/dist/handlers/filesystem-handlers.js +26 -16
  12. package/dist/handlers/search-answers.d.ts +58 -0
  13. package/dist/handlers/search-answers.js +172 -0
  14. package/dist/handlers/search-handlers.js +4 -92
  15. package/dist/index.js +14 -7
  16. package/dist/npm-scripts/remote.js +32 -4
  17. package/dist/remote-device/broadcast-analytics.d.ts +28 -0
  18. package/dist/remote-device/broadcast-analytics.js +41 -0
  19. package/dist/remote-device/desktop-commander-integration.d.ts +20 -0
  20. package/dist/remote-device/desktop-commander-integration.js +121 -40
  21. package/dist/remote-device/device-authenticator.d.ts +13 -1
  22. package/dist/remote-device/device-authenticator.js +87 -47
  23. package/dist/remote-device/device.d.ts +14 -0
  24. package/dist/remote-device/device.js +244 -51
  25. package/dist/remote-device/mqtt-enrollment.d.ts +16 -0
  26. package/dist/remote-device/mqtt-enrollment.js +162 -0
  27. package/dist/remote-device/mqtt-transport.d.ts +44 -0
  28. package/dist/remote-device/mqtt-transport.js +197 -0
  29. package/dist/remote-device/remote-channel.d.ts +64 -3
  30. package/dist/remote-device/remote-channel.js +317 -48
  31. package/dist/remote-device/scripts/blocking-offline-update.js +106 -69
  32. package/dist/remote-device/transport-analytics.d.ts +29 -0
  33. package/dist/remote-device/transport-analytics.js +44 -0
  34. package/dist/remote-device/transport-telemetry.d.ts +32 -0
  35. package/dist/remote-device/transport-telemetry.js +48 -0
  36. package/dist/search-manager.d.ts +239 -27
  37. package/dist/search-manager.js +746 -312
  38. package/dist/server.js +77 -92
  39. package/dist/terminal-manager.d.ts +138 -21
  40. package/dist/terminal-manager.js +300 -215
  41. package/dist/tools/config.d.ts +1 -1
  42. package/dist/tools/config.js +21 -70
  43. package/dist/tools/edit.js +12 -4
  44. package/dist/tools/filesystem.d.ts +30 -6
  45. package/dist/tools/filesystem.js +246 -140
  46. package/dist/tools/improved-process-tools.d.ts +9 -3
  47. package/dist/tools/improved-process-tools.js +171 -68
  48. package/dist/tools/pdf/extract-images.d.ts +2 -0
  49. package/dist/tools/pdf/extract-images.js +4 -1
  50. package/dist/tools/pdf/index.d.ts +5 -3
  51. package/dist/tools/pdf/index.js +4 -3
  52. package/dist/tools/pdf/lib/pdf2md.d.ts +8 -1
  53. package/dist/tools/pdf/lib/pdf2md.js +12 -5
  54. package/dist/tools/pdf/manipulations.d.ts +12 -1
  55. package/dist/tools/pdf/manipulations.js +17 -4
  56. package/dist/tools/pdf/markdown.d.ts +96 -0
  57. package/dist/tools/pdf/markdown.js +485 -20
  58. package/dist/tools/pdf/utils.d.ts +2 -2
  59. package/dist/tools/pdf/utils.js +4 -4
  60. package/dist/tools/process.js +8 -5
  61. package/dist/tools/schemas.d.ts +1 -1
  62. package/dist/tools/schemas.js +15 -6
  63. package/dist/tools/search.d.ts +32 -0
  64. package/dist/tools/search.js +202 -0
  65. package/dist/types.d.ts +1 -1
  66. package/dist/ui/config-editor/config-editor-runtime.js +6 -6
  67. package/dist/ui/config-editor/src/app.js +2 -15
  68. package/dist/utils/ab-test.js +27 -9
  69. package/dist/utils/atomic-write.d.ts +14 -0
  70. package/dist/utils/atomic-write.js +80 -0
  71. package/dist/utils/capture.d.ts +17 -1
  72. package/dist/utils/capture.js +177 -68
  73. package/dist/utils/exit-process.d.ts +24 -0
  74. package/dist/utils/exit-process.js +31 -0
  75. package/dist/utils/feature-flags.js +2 -1
  76. package/dist/utils/files/base.d.ts +3 -1
  77. package/dist/utils/files/docx.d.ts +3 -0
  78. package/dist/utils/files/docx.js +24 -9
  79. package/dist/utils/files/excel.d.ts +10 -0
  80. package/dist/utils/files/excel.js +93 -33
  81. package/dist/utils/files/factory.d.ts +22 -1
  82. package/dist/utils/files/factory.js +59 -4
  83. package/dist/utils/files/image.d.ts +12 -4
  84. package/dist/utils/files/image.js +19 -8
  85. package/dist/utils/files/index.d.ts +5 -3
  86. package/dist/utils/files/index.js +4 -3
  87. package/dist/utils/files/pdf.js +18 -36
  88. package/dist/utils/files/text.d.ts +21 -5
  89. package/dist/utils/files/text.js +90 -86
  90. package/dist/utils/internal-facts.d.ts +3 -0
  91. package/dist/utils/internal-facts.js +23 -0
  92. package/dist/utils/lazy-package.d.ts +23 -0
  93. package/dist/utils/lazy-package.js +42 -0
  94. package/dist/utils/open-browser.js +2 -1
  95. package/dist/utils/process-detection.d.ts +24 -5
  96. package/dist/utils/process-detection.js +199 -89
  97. package/dist/utils/process-tree.d.ts +14 -0
  98. package/dist/utils/process-tree.js +223 -0
  99. package/dist/utils/rename.d.ts +9 -0
  100. package/dist/utils/rename.js +74 -0
  101. package/dist/utils/ripgrep-resolver.js +9 -14
  102. package/dist/utils/shell.d.ts +42 -0
  103. package/dist/utils/shell.js +187 -0
  104. package/dist/utils/system-info.js +9 -7
  105. package/dist/utils/trackTools.js +2 -1
  106. package/dist/version.d.ts +1 -1
  107. package/dist/version.js +1 -1
  108. package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -0
  109. package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -0
  110. package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -0
  111. package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -0
  112. package/package.json +8 -2
  113. package/vendor/telemetry-contract/README.md +56 -0
  114. package/vendor/telemetry-contract/package.json +32 -0
  115. package/vendor/telemetry-contract/transport.d.ts +38 -0
  116. package/vendor/telemetry-contract/transport.js +164 -0
  117. package/vendor/telemetry-contract/transport.test.js +39 -0
@@ -0,0 +1,44 @@
1
+ import { type IClientOptions } from 'mqtt';
2
+ /** The server publishes identifiers only; RemoteChannel fetches the durable command row. */
3
+ export interface MqttDoorbell {
4
+ call_id: string;
5
+ user_id: string;
6
+ device_id: string;
7
+ expires_at: string;
8
+ }
9
+ export interface MqttConfig {
10
+ url: string;
11
+ options: IClientOptions;
12
+ }
13
+ /**
14
+ * Read opt-in connector settings for RemoteChannel registration/restoration.
15
+ * Return null for legacy installs; only explicit loopback development may bypass mutual TLS.
16
+ */
17
+ export declare function readMqttConfig(env?: NodeJS.ProcessEnv, credentials?: {
18
+ cert: string;
19
+ key: string;
20
+ }): MqttConfig | null;
21
+ /** Match the server publisher's exact device topic without granting wildcard subscriptions. */
22
+ export declare function mqttDoorbellTopic(userId: string, deviceId: string): string;
23
+ /** A per-device subscription; payload validation precedes all database access. */
24
+ export declare class MqttDoorbellReceiver {
25
+ private readonly config;
26
+ private readonly userId;
27
+ private readonly deviceId;
28
+ private readonly onDoorbell;
29
+ private readonly onReady;
30
+ private client;
31
+ private stopped;
32
+ private ready;
33
+ private cancelStart;
34
+ private readonly topic;
35
+ /** Bind verified registration identity and RemoteChannel's delivery/readiness callbacks once. */
36
+ constructor(config: MqttConfig, userId: string, deviceId: string, onDoorbell: (payload: MqttDoorbell) => Promise<void>, onReady: (ready: boolean) => Promise<void>);
37
+ /**
38
+ * Connect once and resolve after QoS 1 SUBACK plus the readiness callback.
39
+ * MQTT.js owns socket reconnects; this receiver owns resubscription and admission.
40
+ */
41
+ start(): Promise<void>;
42
+ /** Stop reconnects, reject pending startup and withdraw readiness on sign-out/shutdown. */
43
+ stop(): Promise<void>;
44
+ }
@@ -0,0 +1,197 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { connect } from 'mqtt';
3
+ // Ids become literal topic segments; reject separators and MQTT wildcards.
4
+ const ID = /^[A-Za-z0-9_-]{1,128}$/;
5
+ const CONNECT_TIMEOUT_MS = 10000;
6
+ /**
7
+ * Read opt-in connector settings for RemoteChannel registration/restoration.
8
+ * Return null for legacy installs; only explicit loopback development may bypass mutual TLS.
9
+ */
10
+ export function readMqttConfig(env = process.env, credentials) {
11
+ if (env.MQTT_TRANSPORT_ENABLED !== 'true')
12
+ return null;
13
+ let url;
14
+ try {
15
+ url = new URL(env.MQTT_BROKER_URL || '');
16
+ }
17
+ catch {
18
+ throw new Error('MQTT_BROKER_URL must be a valid MQTT URL');
19
+ }
20
+ if (url.username || url.password || url.search || url.hash || (url.pathname && url.pathname !== '/')) {
21
+ throw new Error('MQTT_BROKER_URL must not contain credentials, paths, or query parameters');
22
+ }
23
+ // MQTT 3.1.1 matches the local broker and AWS pilot. Clean sessions avoid broker
24
+ // backlog replay; each reconnect below must obtain a fresh SUBACK before admission.
25
+ const options = {
26
+ protocolVersion: 4,
27
+ clean: true,
28
+ keepalive: 30,
29
+ connectTimeout: CONNECT_TIMEOUT_MS,
30
+ // Spread reconnects between connector processes after a shared network outage.
31
+ reconnectPeriod: 1000 + Math.floor(Math.random() * 1500),
32
+ resubscribe: false,
33
+ queueQoSZero: false,
34
+ };
35
+ if (url.protocol === 'mqtt:') {
36
+ if (env.MQTT_ALLOW_INSECURE_LOCAL !== 'true' ||
37
+ !['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)) {
38
+ throw new Error('Plain MQTT requires MQTT_ALLOW_INSECURE_LOCAL=true and a loopback broker');
39
+ }
40
+ }
41
+ else if (url.protocol === 'mqtts:') {
42
+ if (!credentials && (!env.MQTT_CERT_FILE || !env.MQTT_KEY_FILE)) {
43
+ throw new Error('TLS MQTT requires MQTT_CERT_FILE and MQTT_KEY_FILE');
44
+ }
45
+ try {
46
+ // Enrollment supplies the locally held key directly; manual file configuration remains valid.
47
+ options.cert = credentials?.cert ?? readFileSync(env.MQTT_CERT_FILE);
48
+ options.key = credentials?.key ?? readFileSync(env.MQTT_KEY_FILE);
49
+ if (env.MQTT_CA_FILE)
50
+ options.ca = readFileSync(env.MQTT_CA_FILE);
51
+ }
52
+ catch {
53
+ throw new Error('Unable to read MQTT TLS files');
54
+ }
55
+ options.rejectUnauthorized = true;
56
+ }
57
+ else {
58
+ throw new Error('MQTT_BROKER_URL must use mqtts:// or explicit loopback mqtt://');
59
+ }
60
+ return { url: url.toString(), options };
61
+ }
62
+ /** Match the server publisher's exact device topic without granting wildcard subscriptions. */
63
+ export function mqttDoorbellTopic(userId, deviceId) {
64
+ if (!ID.test(userId) || !ID.test(deviceId))
65
+ throw new Error('Invalid MQTT device identity');
66
+ return `dc/mqtt/v1/users/${userId}/devices/${deviceId}/new_call`;
67
+ }
68
+ /** A per-device subscription; payload validation precedes all database access. */
69
+ export class MqttDoorbellReceiver {
70
+ /** Bind verified registration identity and RemoteChannel's delivery/readiness callbacks once. */
71
+ constructor(config, userId, deviceId, onDoorbell, onReady) {
72
+ this.config = config;
73
+ this.userId = userId;
74
+ this.deviceId = deviceId;
75
+ this.onDoorbell = onDoorbell;
76
+ this.onReady = onReady;
77
+ this.client = null;
78
+ this.stopped = false;
79
+ this.ready = false;
80
+ this.cancelStart = null;
81
+ this.topic = mqttDoorbellTopic(userId, deviceId);
82
+ }
83
+ /**
84
+ * Connect once and resolve after QoS 1 SUBACK plus the readiness callback.
85
+ * MQTT.js owns socket reconnects; this receiver owns resubscription and admission.
86
+ */
87
+ async start() {
88
+ if (this.client || this.stopped)
89
+ throw new Error('MQTT receiver already started or stopped');
90
+ // Log only the hostname: credentials and raw broker errors must stay out of logs.
91
+ console.log('[MQTT] Connecting to broker:', new URL(this.config.url).hostname);
92
+ const client = connect(this.config.url, {
93
+ ...this.config.options,
94
+ // Stable identity also lets an AWS policy restrict this certificate's Connect permission.
95
+ clientId: `dc-device-${this.deviceId}`,
96
+ });
97
+ this.client = client;
98
+ await new Promise((resolve, reject) => {
99
+ let settled = false;
100
+ // Startup has several competing exits; settle once and always cancel its timer.
101
+ const finish = (error) => {
102
+ if (settled)
103
+ return;
104
+ settled = true;
105
+ clearTimeout(timer);
106
+ this.cancelStart = null;
107
+ if (error)
108
+ reject(error);
109
+ else
110
+ resolve();
111
+ };
112
+ // A connected socket without a granted subscription must not hang device startup.
113
+ const timer = setTimeout(() => {
114
+ finish(new Error('MQTT connection/subscription timed out'));
115
+ void this.stop().catch(() => { });
116
+ }, this.config.options.connectTimeout ?? CONNECT_TIMEOUT_MS);
117
+ this.cancelStart = () => finish(new Error('MQTT receiver stopped'));
118
+ client.on('connect', () => {
119
+ if (this.stopped)
120
+ return;
121
+ // Run after every connection: a TCP connection alone cannot receive commands.
122
+ client.subscribe(this.topic, { qos: 1 }, (error, granted) => {
123
+ if (this.stopped || !client.connected)
124
+ return;
125
+ if (error || granted?.length !== 1 || granted[0].topic !== this.topic || granted[0].qos !== 1) {
126
+ finish(new Error('MQTT device subscription refused'));
127
+ void this.stop().catch(() => { });
128
+ return;
129
+ }
130
+ // Reject downgraded/foreign grants above, then let RemoteChannel persist capability.
131
+ // Recheck after that await so a stop/close cannot resolve stale startup as ready.
132
+ this.ready = true;
133
+ void this.onReady(true).then(() => {
134
+ if (!this.stopped && this.ready) {
135
+ // Report usable command delivery only after the broker grants the subscription.
136
+ console.log('[MQTT] Connected and subscribed; ready for tool calls');
137
+ finish();
138
+ }
139
+ }).catch(() => {
140
+ finish(new Error('MQTT readiness update failed'));
141
+ void this.stop().catch(() => { });
142
+ });
143
+ });
144
+ });
145
+ // Withdraw local admission immediately; RemoteChannel serializes the durable flag update.
146
+ client.on('close', () => {
147
+ if (this.ready && !this.stopped) {
148
+ console.warn('[MQTT] Disconnected; waiting for reconnection');
149
+ }
150
+ this.ready = false;
151
+ void this.onReady(false).catch(() => { });
152
+ });
153
+ // MQTT.js reconnects after network faults. Never print TLS/broker errors,
154
+ // which can include certificate paths or broker-provided sensitive text.
155
+ client.on('error', () => { });
156
+ // Treat broker input as untrusted before RemoteChannel performs any database read.
157
+ // Reject retained backlog and oversized data before parsing, then enforce exact identity.
158
+ client.on('message', (topic, bytes, packet) => {
159
+ if (this.stopped || !this.ready || topic !== this.topic || packet.retain || bytes.length > 1024)
160
+ return;
161
+ let payload;
162
+ try {
163
+ payload = JSON.parse(bytes.toString('utf8'));
164
+ }
165
+ catch {
166
+ return;
167
+ }
168
+ if (!payload || typeof payload !== 'object' || Object.keys(payload).length !== 4 ||
169
+ typeof payload.call_id !== 'string' || !ID.test(payload.call_id) ||
170
+ payload.user_id !== this.userId || payload.device_id !== this.deviceId ||
171
+ typeof payload.expires_at !== 'string')
172
+ return;
173
+ // Canonical UTC and a live deadline reject malformed/stale notifications; the row's
174
+ // independently stored deadline is checked again after RemoteChannel fetches it.
175
+ const expires = Date.parse(payload.expires_at);
176
+ if (!Number.isFinite(expires) || new Date(expires).toISOString() !== payload.expires_at ||
177
+ expires <= Date.now())
178
+ return;
179
+ // EventEmitter cannot await handlers. RemoteChannel owns bounded admission and
180
+ // observes execution; a rejected callback must not kill the MQTT event loop.
181
+ void this.onDoorbell(payload).catch(() => { });
182
+ });
183
+ });
184
+ }
185
+ /** Stop reconnects, reject pending startup and withdraw readiness on sign-out/shutdown. */
186
+ async stop() {
187
+ if (this.stopped)
188
+ return;
189
+ this.stopped = true;
190
+ this.ready = false;
191
+ this.cancelStart?.();
192
+ // Force socket closure: teardown must not wait for broker acknowledgements.
193
+ this.client?.end(true);
194
+ this.client = null;
195
+ await this.onReady(false);
196
+ }
197
+ }
@@ -10,6 +10,16 @@ export interface AuthSession {
10
10
  refresh_token: string | null;
11
11
  device_id?: string;
12
12
  }
13
+ /**
14
+ * The device registered, but its realtime channel is not usable — the join
15
+ * failed, or presence was never acknowledged. Distinct from every other
16
+ * registration failure on purpose: this one the socket watchdog can repair, so
17
+ * the caller keeps the process alive, while a failed lookup or a missing row
18
+ * happens before the recreation parameters are stored and nothing can repair it.
19
+ */
20
+ export declare class ChannelUnreachableError extends Error {
21
+ constructor(message: string);
22
+ }
13
23
  interface DeviceData {
14
24
  user_id: string;
15
25
  device_name: string;
@@ -17,6 +27,10 @@ interface DeviceData {
17
27
  status: string;
18
28
  last_seen: string;
19
29
  }
30
+ /** Jittered version of realtime-js's default 1s/2s/5s/10s stepped backoff. */
31
+ 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;
20
34
  export declare function observeServerDate(dateHeader: string | null): void;
21
35
  export declare class RemoteChannel {
22
36
  private client;
@@ -26,6 +40,12 @@ export declare class RemoteChannel {
26
40
  /** Device the heartbeat timer maintains; null = stopped, so re-arm is inert. */
27
41
  private heartbeatDeviceId;
28
42
  private statusWriteChain;
43
+ /**
44
+ * Answers whether the local execution child is alive. Default yes, so a
45
+ * RemoteChannel used without a device (tests, other callers) behaves as
46
+ * before; MCPDevice installs the real probe.
47
+ */
48
+ private localExecutorProbe;
29
49
  /** Tokens from the last setSession / TOKEN_REFRESHED, for setOffline(). */
30
50
  private lastKnownSession;
31
51
  /** Notified when auth-js rotates the session; the device persists it. */
@@ -45,6 +65,11 @@ export declare class RemoteChannel {
45
65
  private presenceTracked;
46
66
  /** Last capability value written (null = never), to avoid redundant writes. */
47
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;
48
73
  /** Re-entrancy guard: on a wedged socket each track() buffers for the full
49
74
  * 10s push timeout, so 10s health ticks would stack pushes. */
50
75
  private isTrackingPresence;
@@ -65,6 +90,12 @@ export declare class RemoteChannel {
65
90
  private _user;
66
91
  get user(): User | null;
67
92
  initialize(url: string, key: string): void;
93
+ /**
94
+ * Teach the channel how to ask whether the local executor is alive.
95
+ * `status` is a claim that this device will run a tool call right now, and
96
+ * a joined channel alone cannot support that claim - issue #4.
97
+ */
98
+ setLocalExecutorProbe(probe: () => boolean): void;
68
99
  /**
69
100
  * Register a callback fired when auth-js rotates the session. auth-js
70
101
  * rotates the refresh token on every refresh and the previous one is spent,
@@ -118,10 +149,28 @@ export declare class RemoteChannel {
118
149
  * Advertise (or withdraw) the broadcast capability. Only true while genuinely
119
150
  * reachable that way — the server fails dispatch fast without it and picks
120
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.
121
158
  */
122
159
  private setTransportCapable;
160
+ private writeTransportCapable;
161
+ /** Aborts one write to this device's row after DEVICE_ROW_WRITE_TIMEOUT_MS (a method, so tests can shorten it). */
162
+ private deviceRowWriteSignal;
123
163
  /** Create and subscribe the private channel (initial join and recreation). */
124
164
  private createChannel;
165
+ /**
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
168
+ * of truth. Only still-live pending rows for this device are considered.
169
+ *
170
+ * The follow-up onDoorbell() call performs the existing conditional claim,
171
+ * which makes this safe against a doorbell arriving at the same time.
172
+ */
173
+ private recoverPendingCalls;
125
174
  /** Hand a call to device.ts, observing the rejection — the handler is async
126
175
  * and an unhandled rejection terminates the process. */
127
176
  private dispatchToolCall;
@@ -169,15 +218,26 @@ export declare class RemoteChannel {
169
218
  */
170
219
  markCallExecuting(callId: string): Promise<boolean>;
171
220
  updateCallResult(callId: string, status: string, result?: any, errorMessage?: string | null): Promise<void>;
172
- /** Reachable means the private channel is joined. Gates the heartbeat and `status`. */
221
+ /**
222
+ * 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`.
227
+ */
173
228
  private isReachable;
174
229
  /**
175
230
  * Set `status` from actual reachability. `status` is transport-agnostic (the
176
231
  * server filters on it), so it must not follow one channel's health — the
177
232
  * private channel's error path re-fires on every rejoin and would oscillate
178
233
  * the row against the heartbeat. Same predicate as the heartbeat gate.
234
+ *
235
+ * Every transition belongs here rather than calling setOnlineStatus(), which
236
+ * is the write and not the decision. Public so the device can route its
237
+ * recovery transition through the predicate too.
179
238
  */
180
- private syncReachabilityStatus;
239
+ /** Resolves with whether the row actually took the write. */
240
+ syncReachabilityStatus(): Promise<boolean>;
181
241
  /**
182
242
  * Serialize the channel-callback status writes. They fire from un-awaited
183
243
  * callbacks, and inside recreateChannel() a teardown's 'offline' and the
@@ -202,7 +262,8 @@ export declare class RemoteChannel {
202
262
  /** Arm (or re-arm) the last_seen timer at the current tier's cadence. */
203
263
  private scheduleHeartbeat;
204
264
  stopHeartbeat(): void;
205
- setOnlineStatus(deviceId: string, status: 'online' | 'offline'): Promise<void>;
265
+ /** @returns whether the row actually took the write. */
266
+ setOnlineStatus(deviceId: string, status: 'online' | 'offline'): Promise<boolean>;
206
267
  setOffline(deviceId: string | undefined): Promise<void>;
207
268
  unsubscribe(): Promise<void>;
208
269
  }