@moxuli/moremote 0.0.0-stage → 0.1.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.
- package/LICENSE +202 -0
- package/NOTICE +31 -0
- package/README.md +73 -2
- package/bin/moremote-cli.js +34 -0
- package/bin/moremote-service.js +7 -0
- package/dist/bindings.d.ts +6 -0
- package/dist/bindings.js +4 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +308 -0
- package/dist/cloud-client.d.ts +43 -0
- package/dist/cloud-client.js +128 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.js +68 -0
- package/dist/control.d.ts +3 -0
- package/dist/control.js +226 -0
- package/dist/controls.d.ts +15 -0
- package/dist/controls.js +36 -0
- package/dist/crypto.d.ts +23 -0
- package/dist/crypto.js +68 -0
- package/dist/evidence.d.ts +19 -0
- package/dist/evidence.js +4 -0
- package/dist/journal.d.ts +104 -0
- package/dist/journal.js +132 -0
- package/dist/limits.d.ts +21 -0
- package/dist/limits.js +8 -0
- package/dist/official-client.d.ts +120 -0
- package/dist/official-client.js +162 -0
- package/dist/operations.d.ts +71 -0
- package/dist/operations.js +210 -0
- package/dist/pairing.d.ts +19 -0
- package/dist/pairing.js +68 -0
- package/dist/permission.d.ts +9 -0
- package/dist/permission.js +66 -0
- package/dist/projection.d.ts +24 -0
- package/dist/projection.js +35 -0
- package/dist/resources.d.ts +76 -0
- package/dist/resources.js +299 -0
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.js +375 -0
- package/dist/service.d.ts +21 -0
- package/dist/service.js +310 -0
- package/dist/supervisor.d.ts +15 -0
- package/dist/supervisor.js +175 -0
- package/dist/update-state.d.ts +30 -0
- package/dist/update-state.js +158 -0
- package/dist/updater.d.ts +9 -0
- package/dist/updater.js +152 -0
- package/docs/README.md +23 -0
- package/docs/STATE.md +132 -0
- package/docs/configuration.md +37 -0
- package/docs/conventions.md +9 -0
- package/docs/decisions/0001-managed-updates.md +19 -0
- package/docs/plans/2026-11-10-managed-updates.md +26 -0
- package/docs/plans/2026-11-10-notification-delivery.md +118 -0
- package/docs/releasing.md +38 -0
- package/docs/specs/01-architecture.md +102 -0
- package/docs/specs/02-encrypted-delivery.md +194 -0
- package/docs/specs/03-api-contract.md +397 -0
- package/docs/specs/04-control-and-receipt-lifecycle.md +175 -0
- package/docs/specs/05-endpoint-and-lifecycle.md +57 -0
- package/docs/specs/06-managed-updates.md +49 -0
- package/licenses/Paseo-0.15.3.txt +211 -0
- package/package.json +37 -4
- package/vectors/bearer-v1.json +6 -0
- package/vectors/envelope-v1.json +24 -0
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { randomUUID, createHash } from 'node:crypto';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
4
|
+
import { loadConfig, saveConfig, privateDirectory, pruneRetiredPairs } from './config.js';
|
|
5
|
+
import { OfficialClient } from './official-client.js';
|
|
6
|
+
import { CloudClient, CloudError } from './cloud-client.js';
|
|
7
|
+
import { sealEnvelope, decode, presenceTopic } from './crypto.js';
|
|
8
|
+
import { OperationJournal } from './journal.js';
|
|
9
|
+
import { executeOperation, reconcileJournal } from './operations.js';
|
|
10
|
+
import { activatePending } from './pairing.js';
|
|
11
|
+
import { processControl, retransmitControls } from './controls.js';
|
|
12
|
+
import { occurrenceBinding } from './bindings.js';
|
|
13
|
+
import { projectSnapshot } from './projection.js';
|
|
14
|
+
import { ownRuntime } from './control.js';
|
|
15
|
+
import { LIMITS, object } from './limits.js';
|
|
16
|
+
function stableId(value) { const h = createHash('sha256').update(JSON.stringify(value)).digest('hex').slice(0, 32); return h.slice(0, 8) + '-' + h.slice(8, 12) + '-' + h.slice(12, 16) + '-' + h.slice(16, 20) + '-' + h.slice(20); }
|
|
17
|
+
export async function queueAttention(journal, pair, event, now = Date.now()) {
|
|
18
|
+
if (event.timestamp + LIMITS.snapshotMs <= now || event.timestamp > now + LIMITS.futureMs)
|
|
19
|
+
return;
|
|
20
|
+
const payload = { agentId: event.agentId, kind: event.kind, timestamp: event.timestamp, ...(event.requestId ? { requestId: event.requestId } : {}), ...(event.requestBinding ? { requestBinding: event.requestBinding } : {}) };
|
|
21
|
+
const id = stableId([pair.pairId, event.agentId, event.kind, event.requestId || '', event.sourceFingerprint || '', event.requestId && !event.sourceFingerprint ? null : event.timestamp]);
|
|
22
|
+
const issuedAt = event.timestamp;
|
|
23
|
+
const envelope = await sealEnvelope(decode(pair.rootKey, 32), { version: 1, pairId: pair.pairId, id, channel: 'attention', issuedAt, expiresAt: issuedAt + LIMITS.snapshotMs }, payload);
|
|
24
|
+
const topic = await presenceTopic(decode(pair.rootKey, 32), pair.pairId, event.agentId);
|
|
25
|
+
if (event.occurrence && !journal.isCurrent(event.occurrence))
|
|
26
|
+
return;
|
|
27
|
+
journal.queueAttention(pair.pairId, id, envelope.expiresAt, { id, kind: event.kind, topic, envelope }, payload);
|
|
28
|
+
}
|
|
29
|
+
async function boundAttention(journal, pair, event, official) { if (!event.requestId)
|
|
30
|
+
return event; const occurrence = journal.currentOccurrence(official.requestContext().serverId, event.agentId, event.requestId); if (!occurrence || occurrence.generation !== official.generation)
|
|
31
|
+
return null; const requestBinding = await occurrenceBinding(pair, occurrence); if (!journal.isCurrent(occurrence))
|
|
32
|
+
return null; return { ...event, occurrence, sourceFingerprint: occurrence.fingerprint, requestBinding }; }
|
|
33
|
+
async function publishResolutions(journal, pair, cloud) { for (const event of journal.attentionResolutions(pair.pairId)) {
|
|
34
|
+
try {
|
|
35
|
+
await cloud.resolveAttention(event.id, event.resolvedAt);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (!(error instanceof CloudError && error.status === 404))
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
journal.attentionResolutionSent(pair.pairId, event.id);
|
|
42
|
+
} }
|
|
43
|
+
// Relay disappearance/retirement fences execution, but is not an authenticated
|
|
44
|
+
// endpoint revoke. Never manufacture a control receipt or reset its audit clock.
|
|
45
|
+
async function observeRelayRetirement(config, dir, pair, cloud, error) {
|
|
46
|
+
if (pair.relayRetiredAt !== undefined)
|
|
47
|
+
return true;
|
|
48
|
+
if (!(error instanceof CloudError) || ![404, 409].includes(error.status))
|
|
49
|
+
return false;
|
|
50
|
+
let retired = false;
|
|
51
|
+
try {
|
|
52
|
+
const state = object((await cloud.pair()).pair).state;
|
|
53
|
+
retired = state === 'revoked' || state === 'expired';
|
|
54
|
+
}
|
|
55
|
+
catch (probe) {
|
|
56
|
+
if (probe instanceof CloudError && probe.status === 404)
|
|
57
|
+
retired = true;
|
|
58
|
+
}
|
|
59
|
+
if (!retired)
|
|
60
|
+
return false;
|
|
61
|
+
pair.active = false;
|
|
62
|
+
pair.relayRetiredAt = Date.now();
|
|
63
|
+
await saveConfig(dir, config);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
// An elapsed deadline still fences the cycle that observed it.
|
|
67
|
+
function retryPaused(error) { return error instanceof CloudError && error.retryAt !== undefined; }
|
|
68
|
+
export async function runRuntime(dir, version) {
|
|
69
|
+
await privateDirectory(dir);
|
|
70
|
+
let stopped = false, draining = false;
|
|
71
|
+
let official;
|
|
72
|
+
let stage = 'starting';
|
|
73
|
+
let lastError = null;
|
|
74
|
+
let activePairs = 0;
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
const stop = () => { stopped = true; controller.abort(); void official?.sdk.close().catch(() => { }); };
|
|
77
|
+
const drainWake = new AbortController();
|
|
78
|
+
const parentMessage = (message) => { if (message && typeof message === 'object' && 'kind' in message && message.kind === 'moremote-drain') {
|
|
79
|
+
draining = true;
|
|
80
|
+
drainWake.abort();
|
|
81
|
+
} };
|
|
82
|
+
const parentGone = () => { draining = true; drainWake.abort(); };
|
|
83
|
+
let detach, closeJournal;
|
|
84
|
+
const release = await ownRuntime(dir, () => ({ stage, lastError, activePairs, version: version ?? null }), stop);
|
|
85
|
+
try {
|
|
86
|
+
const journal = new OperationJournal(join(dir, 'journal.sqlite'));
|
|
87
|
+
closeJournal = () => journal.close();
|
|
88
|
+
if (process.send) {
|
|
89
|
+
process.on('message', parentMessage);
|
|
90
|
+
process.on('disconnect', parentGone);
|
|
91
|
+
if (!process.connected)
|
|
92
|
+
parentGone();
|
|
93
|
+
else
|
|
94
|
+
process.send({ kind: 'moremote-ready' }, undefined, undefined, () => { });
|
|
95
|
+
}
|
|
96
|
+
const attentionQueue = [];
|
|
97
|
+
let backoff = LIMITS.pollMs;
|
|
98
|
+
let measuredAt = 0;
|
|
99
|
+
let snapshot;
|
|
100
|
+
const statePublications = new Map();
|
|
101
|
+
const retryStates = new Map();
|
|
102
|
+
const pollOrigins = new Set();
|
|
103
|
+
process.once('SIGINT', stop);
|
|
104
|
+
process.once('SIGTERM', stop);
|
|
105
|
+
while (!stopped && !draining) {
|
|
106
|
+
try {
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
journal.cleanup(now);
|
|
109
|
+
const config = await loadConfig(dir);
|
|
110
|
+
pollOrigins.clear();
|
|
111
|
+
let failure = null;
|
|
112
|
+
let acquisitionFailed = false;
|
|
113
|
+
const clouds = new Map();
|
|
114
|
+
const cycleFences = new Map();
|
|
115
|
+
for (const pair of config.pairs) {
|
|
116
|
+
const revokedAt = journal.revocationTime(pair.pairId);
|
|
117
|
+
if (revokedAt !== undefined && pair.revokedAt === undefined) {
|
|
118
|
+
pair.active = false;
|
|
119
|
+
pair.revokedAt = revokedAt;
|
|
120
|
+
await saveConfig(dir, config);
|
|
121
|
+
}
|
|
122
|
+
if (pair.relayRetiredAt !== undefined)
|
|
123
|
+
pair.active = false;
|
|
124
|
+
}
|
|
125
|
+
// Prune before any request: a retained 404 must not extend automatic recovery.
|
|
126
|
+
if (pruneRetiredPairs(config, now, journal))
|
|
127
|
+
await saveConfig(dir, config);
|
|
128
|
+
journal.cleanupRevocations(config.pairs.map(p => p.pairId), now);
|
|
129
|
+
for (const pairId of statePublications.keys())
|
|
130
|
+
if (!config.pairs.some(pair => pair.pairId === pairId))
|
|
131
|
+
statePublications.delete(pairId);
|
|
132
|
+
for (const origin of retryStates.keys())
|
|
133
|
+
if (!config.pairs.some(pair => (pair.apiOrigin || config.apiOrigin) === origin))
|
|
134
|
+
retryStates.delete(origin);
|
|
135
|
+
// Endpoint revocation must work even when the official daemon is offline.
|
|
136
|
+
if (config.cloudEnabled)
|
|
137
|
+
for (const pair of config.pairs) {
|
|
138
|
+
if (stopped)
|
|
139
|
+
break;
|
|
140
|
+
const origin = pair.apiOrigin || config.apiOrigin;
|
|
141
|
+
if (!origin || (!pair.active && pair.revokedAt === undefined && pair.relayRetiredAt === undefined && pair.expiresAt !== undefined && pair.expiresAt <= Date.now()))
|
|
142
|
+
continue;
|
|
143
|
+
pollOrigins.add(origin);
|
|
144
|
+
let retryState = retryStates.get(origin);
|
|
145
|
+
if (!retryState) {
|
|
146
|
+
retryState = {};
|
|
147
|
+
retryStates.set(origin, retryState);
|
|
148
|
+
}
|
|
149
|
+
let cycleFence = cycleFences.get(origin);
|
|
150
|
+
if (!cycleFence) {
|
|
151
|
+
cycleFence = {};
|
|
152
|
+
cycleFences.set(origin, cycleFence);
|
|
153
|
+
}
|
|
154
|
+
const cloud = new CloudClient(origin, pair.pairId, pair.hostToken, config.allowLoopbackHttp, fetch, controller.signal, retryState, cycleFence);
|
|
155
|
+
let controlsVerified = true;
|
|
156
|
+
try {
|
|
157
|
+
for (const envelope of await cloud.controls()) {
|
|
158
|
+
try {
|
|
159
|
+
const state = await processControl({ pair, journal, cloud }, envelope);
|
|
160
|
+
if (state === 'revoked') {
|
|
161
|
+
pair.active = false;
|
|
162
|
+
pair.revokedAt ??= journal.revocationTime(pair.pairId) ?? Date.now();
|
|
163
|
+
await saveConfig(dir, config);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
failure = error;
|
|
168
|
+
controlsVerified = false;
|
|
169
|
+
if (!retryPaused(error))
|
|
170
|
+
acquisitionFailed = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
failure = error;
|
|
176
|
+
if (!await observeRelayRetirement(config, dir, pair, cloud, error)) {
|
|
177
|
+
if (!retryPaused(error))
|
|
178
|
+
acquisitionFailed = true;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (controlsVerified || journal.pairRevoked(pair.pairId) || pair.relayRetiredAt !== undefined)
|
|
183
|
+
clouds.set(pair.pairId, cloud);
|
|
184
|
+
try {
|
|
185
|
+
await retransmitControls({ pair, journal, cloud });
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
failure = error;
|
|
189
|
+
}
|
|
190
|
+
for (const record of journal.receipts(pair.pairId, Date.now())) {
|
|
191
|
+
try {
|
|
192
|
+
await cloud.receipt(record.id, { state: record.state, revision: record.revision, envelope: record.receipt });
|
|
193
|
+
journal.receiptSent(pair.pairId, record.id, record.revision);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
failure = error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (pair.active && !journal.pairRevoked(pair.pairId))
|
|
200
|
+
try {
|
|
201
|
+
await publishResolutions(journal, pair, cloud);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
failure = error;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (stopped)
|
|
208
|
+
break;
|
|
209
|
+
if (!official || !official.sdk.isConnected) {
|
|
210
|
+
detach?.();
|
|
211
|
+
await official?.close().catch(() => { });
|
|
212
|
+
stage = 'connecting';
|
|
213
|
+
official = new OfficialClient(config, journal);
|
|
214
|
+
await official.connect();
|
|
215
|
+
const serverId = official.info().serverId;
|
|
216
|
+
if (!config.daemonServerId) {
|
|
217
|
+
config.daemonServerId = serverId;
|
|
218
|
+
await saveConfig(dir, config);
|
|
219
|
+
}
|
|
220
|
+
detach = official.onAttention(event => { if (attentionQueue.length < 500)
|
|
221
|
+
attentionQueue.push(event);
|
|
222
|
+
else
|
|
223
|
+
lastError = 'ATTENTION_QUEUE_LIMIT'; });
|
|
224
|
+
measuredAt = 0;
|
|
225
|
+
}
|
|
226
|
+
if (snapshot === undefined || Date.now() - measuredAt >= 30000) {
|
|
227
|
+
snapshot = await official.snapshot();
|
|
228
|
+
measuredAt = snapshot.measuredAt;
|
|
229
|
+
}
|
|
230
|
+
stage = config.cloudEnabled ? 'cloud-enabled' : 'local-only';
|
|
231
|
+
activePairs = config.pairs.filter(p => p.active && p.relayRetiredAt === undefined && !journal.pairRevoked(p.pairId)).length;
|
|
232
|
+
const events = attentionQueue.splice(0);
|
|
233
|
+
// Persist every active phone's events before the first network send.
|
|
234
|
+
if (config.cloudEnabled)
|
|
235
|
+
for (const pair of config.pairs.filter(p => p.active && p.relayRetiredAt === undefined && !journal.pairRevoked(p.pairId)))
|
|
236
|
+
for (const event of events) {
|
|
237
|
+
const bound = await boundAttention(journal, pair, event, official);
|
|
238
|
+
if (bound)
|
|
239
|
+
await queueAttention(journal, pair, bound);
|
|
240
|
+
}
|
|
241
|
+
for (const pair of config.pairs) {
|
|
242
|
+
if (stopped)
|
|
243
|
+
break;
|
|
244
|
+
const cloud = clouds.get(pair.pairId);
|
|
245
|
+
if (!cloud || cycleFences.get(cloud.origin)?.error)
|
|
246
|
+
continue;
|
|
247
|
+
try {
|
|
248
|
+
if (pair.daemonServerId && pair.daemonServerId !== official.info().serverId) {
|
|
249
|
+
if (journal.pairRevoked(pair.pairId) || pair.relayRetiredAt !== undefined)
|
|
250
|
+
continue;
|
|
251
|
+
throw Error('PAIR_DAEMON_MISMATCH');
|
|
252
|
+
}
|
|
253
|
+
// Read-only reconciliation remains available after revoke and original message expiry.
|
|
254
|
+
if (await reconcileJournal({ pair, journal, official, cloud, clock: Date.now }))
|
|
255
|
+
failure = Error('RECEIPT_RECONCILIATION_FAILED');
|
|
256
|
+
if (journal.pairRevoked(pair.pairId) || pair.relayRetiredAt !== undefined)
|
|
257
|
+
continue;
|
|
258
|
+
const active = await activatePending(config, dir, pair, cloud, official.info().serverId, snapshot.hostName);
|
|
259
|
+
if (!active)
|
|
260
|
+
continue;
|
|
261
|
+
try {
|
|
262
|
+
let publication = statePublications.get(pair.pairId);
|
|
263
|
+
// A lost acknowledgement keeps the exact immutable envelope even across a
|
|
264
|
+
// newer measurement. Expired display-only state can yield to a fresh sample.
|
|
265
|
+
if (!publication || publication.envelope.expiresAt <= Date.now() || (publication.acknowledged && publication.envelope.issuedAt !== snapshot.measuredAt)) {
|
|
266
|
+
const payload = await projectSnapshot(snapshot, pair, journal, official.generation);
|
|
267
|
+
const envelope = await sealEnvelope(decode(pair.rootKey, 32), { version: 1, pairId: pair.pairId, id: randomUUID(), channel: 'state', issuedAt: snapshot.measuredAt, expiresAt: snapshot.measuredAt + LIMITS.snapshotMs }, payload);
|
|
268
|
+
publication = { envelope, acknowledged: false };
|
|
269
|
+
statePublications.set(pair.pairId, publication);
|
|
270
|
+
}
|
|
271
|
+
if (!publication.acknowledged) {
|
|
272
|
+
await cloud.state(publication.envelope);
|
|
273
|
+
publication.acknowledged = true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
failure = error;
|
|
278
|
+
if (await observeRelayRetirement(config, dir, pair, cloud, error))
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
await publishResolutions(journal, pair, cloud);
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
failure = error;
|
|
286
|
+
}
|
|
287
|
+
for (const item of journal.attention(pair.pairId, Date.now())) {
|
|
288
|
+
try {
|
|
289
|
+
await cloud.attention(item.body);
|
|
290
|
+
journal.attentionSent(pair.pairId, item.id);
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
failure = error;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Publication failures are independent from acquisition. Preserve the normal
|
|
297
|
+
// three-second command/control cadence while still surfacing degraded status.
|
|
298
|
+
try {
|
|
299
|
+
for (const envelope of await cloud.commands()) {
|
|
300
|
+
if (stopped || cycleFences.get(cloud.origin)?.error)
|
|
301
|
+
break;
|
|
302
|
+
try {
|
|
303
|
+
await executeOperation({ pair, journal, official, cloud, clock: Date.now }, envelope);
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
failure = error;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
failure = error;
|
|
312
|
+
if (!await observeRelayRetirement(config, dir, pair, cloud, error) && !retryPaused(error))
|
|
313
|
+
acquisitionFailed = true;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
failure = error;
|
|
318
|
+
if (!await observeRelayRetirement(config, dir, pair, cloud, error) && !retryPaused(error))
|
|
319
|
+
acquisitionFailed = true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (failure) {
|
|
323
|
+
lastError = failure instanceof CloudError ? failure.code : 'CLI_CYCLE_FAILED';
|
|
324
|
+
stage = 'degraded';
|
|
325
|
+
backoff = acquisitionFailed ? Math.min(backoff * 2, LIMITS.maxBackoffMs) : LIMITS.pollMs;
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
lastError = null;
|
|
329
|
+
backoff = LIMITS.pollMs;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
lastError = error instanceof CloudError ? error.code : 'CLI_CYCLE_FAILED';
|
|
334
|
+
stage = 'degraded';
|
|
335
|
+
backoff = retryPaused(error) ? LIMITS.pollMs : Math.min(backoff * 2, LIMITS.maxBackoffMs);
|
|
336
|
+
}
|
|
337
|
+
// Pauses are shared only by relay origin, never reset by a cached rejection.
|
|
338
|
+
// Other relays retain ordinary control priority/cadence. If all are paused,
|
|
339
|
+
// sleep to the first original deadline; stop still interrupts this wait.
|
|
340
|
+
const wakeNow = Date.now();
|
|
341
|
+
let retryWake = Infinity;
|
|
342
|
+
for (const origin of pollOrigins) {
|
|
343
|
+
const retryAt = retryStates.get(origin)?.error?.retryAt;
|
|
344
|
+
if (retryAt === undefined || retryAt <= wakeNow) {
|
|
345
|
+
retryWake = wakeNow;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
retryWake = Math.min(retryWake, retryAt);
|
|
349
|
+
}
|
|
350
|
+
if (Number.isFinite(retryWake) && retryWake > wakeNow)
|
|
351
|
+
backoff = Math.max(backoff, retryWake - wakeNow);
|
|
352
|
+
if (draining)
|
|
353
|
+
break;
|
|
354
|
+
await sleep(backoff, undefined, { signal: AbortSignal.any([controller.signal, drainWake.signal]) }).catch(() => { });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
finally {
|
|
358
|
+
process.removeListener('SIGINT', stop);
|
|
359
|
+
process.removeListener('SIGTERM', stop);
|
|
360
|
+
process.removeListener('message', parentMessage);
|
|
361
|
+
process.removeListener('disconnect', parentGone);
|
|
362
|
+
try {
|
|
363
|
+
detach?.();
|
|
364
|
+
await official?.close().catch(() => { });
|
|
365
|
+
}
|
|
366
|
+
finally {
|
|
367
|
+
try {
|
|
368
|
+
closeJournal?.();
|
|
369
|
+
}
|
|
370
|
+
finally {
|
|
371
|
+
await release();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ServiceDefinition {
|
|
2
|
+
path: string;
|
|
3
|
+
content: string;
|
|
4
|
+
platform: string;
|
|
5
|
+
entry: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function serviceDefinition(platform: string, home: string, node: string, entry: string, data: string): ServiceDefinition;
|
|
8
|
+
export declare function command(program: string, args: string[], capture?: boolean, timeout?: number): Promise<string>;
|
|
9
|
+
export interface ServiceStatus {
|
|
10
|
+
owned: boolean;
|
|
11
|
+
registration: 'registered' | 'absent' | 'unknown';
|
|
12
|
+
error?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function serviceStatus(def: ServiceDefinition): Promise<ServiceStatus>;
|
|
15
|
+
export declare function installService(def: ServiceDefinition): Promise<void>;
|
|
16
|
+
export declare function stopService(def: ServiceDefinition): Promise<void>;
|
|
17
|
+
export declare function removeService(def: ServiceDefinition): Promise<void>;
|
|
18
|
+
export declare function managedEntry(dir: string, version: string): Promise<string>;
|
|
19
|
+
export declare function updatePackage(dir: string, version: string): Promise<string>;
|
|
20
|
+
export declare function stagePackage(dir: string, version: string): Promise<string>;
|
|
21
|
+
export declare function currentDefinition(entry: string, dir: string): ServiceDefinition;
|