@moxuli/moremote 0.1.2 → 0.1.5
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/README.md +69 -50
- package/bin/moremote-cli.js +11 -4
- package/dist/cli.js +33 -7
- package/dist/cloud-client.d.ts +2 -9
- package/dist/cloud-client.js +3 -8
- package/dist/config.d.ts +7 -0
- package/dist/config.js +23 -4
- package/dist/enrollment-files.d.ts +37 -0
- package/dist/enrollment-files.js +225 -0
- package/dist/enrollment-protocol.d.ts +50 -0
- package/dist/enrollment-protocol.js +44 -0
- package/dist/local-enrollment.d.ts +25 -0
- package/dist/local-enrollment.js +160 -0
- package/dist/notification-state.d.ts +10 -0
- package/dist/notification-state.js +36 -0
- package/dist/official-client.d.ts +25 -65
- package/dist/official-client.js +83 -35
- package/dist/operations.d.ts +1 -0
- package/dist/operations.js +24 -4
- package/dist/projection.d.ts +3 -15
- package/dist/projection.js +11 -21
- package/dist/resources.d.ts +2 -1
- package/dist/resources.js +67 -31
- package/dist/runtime.d.ts +10 -1
- package/dist/runtime.js +81 -59
- package/dist/setup-upgrade.d.ts +2 -0
- package/dist/setup-upgrade.js +65 -0
- package/dist/setup.d.ts +12 -0
- package/dist/setup.js +38 -0
- package/docs/STATE.md +197 -13
- package/docs/configuration.md +70 -49
- package/docs/native-enrollment-acceptance.md +21 -0
- package/docs/specs/01-architecture.md +14 -1
- package/docs/specs/02-encrypted-delivery.md +4 -4
- package/docs/specs/03-api-contract.md +18 -123
- package/docs/specs/04-control-and-receipt-lifecycle.md +12 -0
- package/docs/specs/05-endpoint-and-lifecycle.md +126 -2
- package/docs/specs/06-managed-updates.md +25 -0
- package/package.json +29 -6
- package/dist/activity.d.ts +0 -77
- package/dist/activity.js +0 -193
package/dist/runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
4
4
|
import { loadConfig, saveConfig, privateDirectory, pruneRetiredPairs } from './config.js';
|
|
@@ -13,7 +13,9 @@ import { occurrenceBinding } from './bindings.js';
|
|
|
13
13
|
import { projectSnapshot } from './projection.js';
|
|
14
14
|
import { ownRuntime } from './control.js';
|
|
15
15
|
import { LIMITS, object } from './limits.js';
|
|
16
|
-
import {
|
|
16
|
+
import { NotificationStatePublisher } from './notification-state.js';
|
|
17
|
+
import { LocalEnrollment } from './local-enrollment.js';
|
|
18
|
+
import { inspectResource } from './resources.js';
|
|
17
19
|
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); }
|
|
18
20
|
export async function queueAttention(journal, pair, event, now = Date.now()) {
|
|
19
21
|
if (event.timestamp + LIMITS.snapshotMs <= now || event.timestamp > now + LIMITS.futureMs)
|
|
@@ -29,10 +31,19 @@ export async function queueAttention(journal, pair, event, now = Date.now()) {
|
|
|
29
31
|
return;
|
|
30
32
|
journal.queueAttention(pair.pairId, id, envelope.expiresAt, { id, kind: event.kind, topic, envelope }, payload);
|
|
31
33
|
}
|
|
32
|
-
async function boundAttention(journal, pair, event, official) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
export async function boundAttention(journal, pair, event, official) {
|
|
35
|
+
if (!event.requestId)
|
|
36
|
+
return event;
|
|
37
|
+
// Bind the occurrence captured when this event was observed. Looking up a
|
|
38
|
+
// replacement here could give its identity an older cached event's clock.
|
|
39
|
+
const occurrence = event.occurrence;
|
|
40
|
+
if (!occurrence || occurrence.serverId !== official.requestContext().serverId || occurrence.agentId !== event.agentId || occurrence.requestId !== event.requestId || occurrence.generation !== official.generation || occurrence.createdAt !== event.timestamp || !journal.isCurrent(occurrence))
|
|
41
|
+
return null;
|
|
42
|
+
const requestBinding = await occurrenceBinding(pair, occurrence);
|
|
43
|
+
if (!journal.isCurrent(occurrence))
|
|
44
|
+
return null;
|
|
45
|
+
return { ...event, occurrence, sourceFingerprint: occurrence.fingerprint, requestBinding };
|
|
46
|
+
}
|
|
36
47
|
async function publishResolutions(journal, pair, cloud) { for (const event of journal.attentionResolutions(pair.pairId)) {
|
|
37
48
|
try {
|
|
38
49
|
await cloud.resolveAttention(event.id, event.resolvedAt);
|
|
@@ -85,9 +96,10 @@ export async function runRuntime(dir, version) {
|
|
|
85
96
|
const parentGone = () => { draining = true; drainWake.abort(); };
|
|
86
97
|
let detach, closeJournal;
|
|
87
98
|
const release = await ownRuntime(dir, () => ({ stage, lastError, activePairs, version: version ?? null }), stop);
|
|
88
|
-
const
|
|
89
|
-
let activityFailure = null, activityPairCursor = 0;
|
|
99
|
+
const enrollment = new LocalEnrollment(dir);
|
|
90
100
|
try {
|
|
101
|
+
if (!inspectResource(join(dir, 'config.json'), 'file', true))
|
|
102
|
+
await saveConfig(dir, await loadConfig(dir));
|
|
91
103
|
const journal = new OperationJournal(join(dir, 'journal.sqlite'));
|
|
92
104
|
closeJournal = () => journal.close();
|
|
93
105
|
if (process.send) {
|
|
@@ -102,8 +114,7 @@ export async function runRuntime(dir, version) {
|
|
|
102
114
|
let backoff = LIMITS.pollMs;
|
|
103
115
|
let measuredAt = 0;
|
|
104
116
|
let snapshot;
|
|
105
|
-
const
|
|
106
|
-
const activityPublisher = new ActivityPublisher();
|
|
117
|
+
const statePublisher = new NotificationStatePublisher();
|
|
107
118
|
const retryStates = new Map();
|
|
108
119
|
const pollOrigins = new Set();
|
|
109
120
|
process.once('SIGINT', stop);
|
|
@@ -114,8 +125,7 @@ export async function runRuntime(dir, version) {
|
|
|
114
125
|
journal.cleanup(now);
|
|
115
126
|
const config = await loadConfig(dir);
|
|
116
127
|
pollOrigins.clear();
|
|
117
|
-
let failure
|
|
118
|
-
activityFailure = null;
|
|
128
|
+
let failure;
|
|
119
129
|
let acquisitionFailed = false;
|
|
120
130
|
const clouds = new Map();
|
|
121
131
|
const cycleFences = new Map();
|
|
@@ -129,14 +139,17 @@ export async function runRuntime(dir, version) {
|
|
|
129
139
|
if (pair.relayRetiredAt !== undefined)
|
|
130
140
|
pair.active = false;
|
|
131
141
|
}
|
|
142
|
+
try {
|
|
143
|
+
await enrollment.cleanup(config);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
failure = error;
|
|
147
|
+
}
|
|
132
148
|
// Prune before any request: a retained 404 must not extend automatic recovery.
|
|
133
149
|
if (pruneRetiredPairs(config, now, journal))
|
|
134
150
|
await saveConfig(dir, config);
|
|
135
151
|
journal.cleanupRevocations(config.pairs.map(p => p.pairId), now);
|
|
136
|
-
|
|
137
|
-
if (!config.pairs.some(pair => pair.pairId === pairId))
|
|
138
|
-
statePublications.delete(pairId);
|
|
139
|
-
activityPublisher.retain(config.cloudEnabled ? config.pairs.filter(pair => pair.active && pair.relayRetiredAt === undefined && !journal.pairRevoked(pair.pairId)).map(pair => pair.pairId) : []);
|
|
152
|
+
statePublisher.retain(config.cloudEnabled ? config.pairs.filter(pair => pair.active && pair.relayRetiredAt === undefined && !journal.pairRevoked(pair.pairId)).map(pair => pair.pairId) : []);
|
|
140
153
|
for (const origin of retryStates.keys())
|
|
141
154
|
if (!config.pairs.some(pair => (pair.apiOrigin || config.apiOrigin) === origin))
|
|
142
155
|
retryStates.delete(origin);
|
|
@@ -148,6 +161,8 @@ export async function runRuntime(dir, version) {
|
|
|
148
161
|
const origin = pair.apiOrigin || config.apiOrigin;
|
|
149
162
|
if (!origin || (!pair.active && pair.revokedAt === undefined && pair.relayRetiredAt === undefined && pair.expiresAt !== undefined && pair.expiresAt <= Date.now()))
|
|
150
163
|
continue;
|
|
164
|
+
if (config.enrollmentRequests?.some(record => record.pairId === pair.pairId && !record.created))
|
|
165
|
+
continue;
|
|
151
166
|
pollOrigins.add(origin);
|
|
152
167
|
let retryState = retryStates.get(origin);
|
|
153
168
|
if (!retryState) {
|
|
@@ -161,6 +176,12 @@ export async function runRuntime(dir, version) {
|
|
|
161
176
|
}
|
|
162
177
|
const cloud = new CloudClient(origin, pair.pairId, pair.hostToken, config.allowLoopbackHttp, fetch, controller.signal, retryState, cycleFence);
|
|
163
178
|
let controlsVerified = true;
|
|
179
|
+
// Pending endpoints cannot use active-only control routes. Admit activation
|
|
180
|
+
// after official identity verification, without granting an execution lane.
|
|
181
|
+
if (!pair.active && pair.revokedAt === undefined && pair.relayRetiredAt === undefined && !journal.pairRevoked(pair.pairId)) {
|
|
182
|
+
clouds.set(pair.pairId, cloud);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
164
185
|
try {
|
|
165
186
|
for (const envelope of await cloud.controls()) {
|
|
166
187
|
try {
|
|
@@ -231,6 +252,26 @@ export async function runRuntime(dir, version) {
|
|
|
231
252
|
lastError = 'ATTENTION_QUEUE_LIMIT'; });
|
|
232
253
|
measuredAt = 0;
|
|
233
254
|
}
|
|
255
|
+
try {
|
|
256
|
+
await enrollment.cycle(config, official.info().serverId, pair => {
|
|
257
|
+
const origin = pair.apiOrigin || config.apiOrigin;
|
|
258
|
+
pollOrigins.add(origin);
|
|
259
|
+
let retry = retryStates.get(origin);
|
|
260
|
+
if (!retry) {
|
|
261
|
+
retry = {};
|
|
262
|
+
retryStates.set(origin, retry);
|
|
263
|
+
}
|
|
264
|
+
let fence = cycleFences.get(origin);
|
|
265
|
+
if (!fence) {
|
|
266
|
+
fence = {};
|
|
267
|
+
cycleFences.set(origin, fence);
|
|
268
|
+
}
|
|
269
|
+
return new CloudClient(origin, pair.pairId, pair.hostToken, config.allowLoopbackHttp, fetch, controller.signal, retry, fence);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
failure = error;
|
|
274
|
+
}
|
|
234
275
|
if (snapshot === undefined || Date.now() - measuredAt >= 30000) {
|
|
235
276
|
snapshot = await official.snapshot();
|
|
236
277
|
measuredAt = snapshot.measuredAt;
|
|
@@ -246,33 +287,6 @@ export async function runRuntime(dir, version) {
|
|
|
246
287
|
if (bound)
|
|
247
288
|
await queueAttention(journal, pair, bound);
|
|
248
289
|
}
|
|
249
|
-
if (!stopped && !draining) {
|
|
250
|
-
const candidates = config.pairs.filter(pair => pair.active && pair.relayRetiredAt === undefined && !journal.pairRevoked(pair.pairId) && clouds.has(pair.pairId));
|
|
251
|
-
const ordered = [...candidates.slice(activityPairCursor), ...candidates.slice(0, activityPairCursor)], activitySnapshot = snapshot, activityOfficial = official;
|
|
252
|
-
// Schedule cached terminal recovery before any optional normal discovery.
|
|
253
|
-
// The owned lane never delays command acquisition and is aborted/joined on drain.
|
|
254
|
-
if (activityLane.start(async (signal) => {
|
|
255
|
-
let optionalFailure;
|
|
256
|
-
for (const terminalOnly of [true, false])
|
|
257
|
-
for (const pair of ordered) {
|
|
258
|
-
signal.throwIfAborted();
|
|
259
|
-
if (!pair.active || journal.pairRevoked(pair.pairId))
|
|
260
|
-
continue;
|
|
261
|
-
const cloud = clouds.get(pair.pairId);
|
|
262
|
-
try {
|
|
263
|
-
await activityPublisher.publish(pair, cloud, activitySnapshot, Date.now(), (agentId, readSignal) => activityOfficial.activityTask(agentId, readSignal), { signal, terminalOnly });
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
if (signal.aborted)
|
|
267
|
-
throw error;
|
|
268
|
-
optionalFailure ??= error;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
if (optionalFailure)
|
|
272
|
-
throw optionalFailure;
|
|
273
|
-
}, error => { activityFailure = error; }, AbortSignal.any([controller.signal, drainWake.signal])))
|
|
274
|
-
activityPairCursor = (activityPairCursor + 1) % Math.max(1, candidates.length);
|
|
275
|
-
}
|
|
276
290
|
for (const pair of config.pairs) {
|
|
277
291
|
if (stopped)
|
|
278
292
|
break;
|
|
@@ -285,6 +299,12 @@ export async function runRuntime(dir, version) {
|
|
|
285
299
|
continue;
|
|
286
300
|
throw Error('PAIR_DAEMON_MISMATCH');
|
|
287
301
|
}
|
|
302
|
+
// A new activation gets no commands/state in this cycle. The next cycle must
|
|
303
|
+
// acquire and validate controls before it can execute any phone operation.
|
|
304
|
+
if (!pair.active && pair.revokedAt === undefined && pair.relayRetiredAt === undefined && !journal.pairRevoked(pair.pairId)) {
|
|
305
|
+
await activatePending(config, dir, pair, cloud, official.info().serverId, snapshot.hostName);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
288
308
|
// Read-only reconciliation remains available after revoke and original message expiry.
|
|
289
309
|
if (await reconcileJournal({ pair, journal, official, cloud, clock: Date.now }))
|
|
290
310
|
failure = Error('RECEIPT_RECONCILIATION_FAILED');
|
|
@@ -293,20 +313,10 @@ export async function runRuntime(dir, version) {
|
|
|
293
313
|
const active = await activatePending(config, dir, pair, cloud, official.info().serverId, snapshot.hostName);
|
|
294
314
|
if (!active)
|
|
295
315
|
continue;
|
|
316
|
+
let detailsCurrent = false;
|
|
296
317
|
try {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
// newer measurement. Expired display-only state can yield to a fresh sample.
|
|
300
|
-
if (!publication || publication.envelope.expiresAt <= Date.now() || (publication.acknowledged && publication.envelope.issuedAt !== snapshot.measuredAt)) {
|
|
301
|
-
const payload = await projectSnapshot(snapshot, pair, journal, official.generation);
|
|
302
|
-
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);
|
|
303
|
-
publication = { envelope, widgetFingerprint: await widgetFingerprint(pair, payload), acknowledged: false };
|
|
304
|
-
statePublications.set(pair.pairId, publication);
|
|
305
|
-
}
|
|
306
|
-
if (!publication.acknowledged) {
|
|
307
|
-
await cloud.state(publication.envelope, publication.widgetFingerprint);
|
|
308
|
-
publication.acknowledged = true;
|
|
309
|
-
}
|
|
318
|
+
const payload = await projectSnapshot({ ...official.notificationSnapshot(), hostName: snapshot.hostName, measuredAt: snapshot.measuredAt }, pair, journal, official.generation);
|
|
319
|
+
detailsCurrent = await statePublisher.publish(pair, cloud, payload);
|
|
310
320
|
}
|
|
311
321
|
catch (error) {
|
|
312
322
|
failure = error;
|
|
@@ -320,6 +330,8 @@ export async function runRuntime(dir, version) {
|
|
|
320
330
|
failure = error;
|
|
321
331
|
}
|
|
322
332
|
for (const item of journal.attention(pair.pairId, Date.now())) {
|
|
333
|
+
if (!detailsCurrent && ['question', 'permission'].includes(item.body.kind))
|
|
334
|
+
continue;
|
|
323
335
|
try {
|
|
324
336
|
await cloud.attention(item.body);
|
|
325
337
|
journal.attentionSent(pair.pairId, item.id);
|
|
@@ -354,6 +366,12 @@ export async function runRuntime(dir, version) {
|
|
|
354
366
|
acquisitionFailed = true;
|
|
355
367
|
}
|
|
356
368
|
}
|
|
369
|
+
try {
|
|
370
|
+
await enrollment.cleanup(config);
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
failure = error;
|
|
374
|
+
}
|
|
357
375
|
if (failure) {
|
|
358
376
|
lastError = failure instanceof CloudError ? failure.code : 'CLI_CYCLE_FAILED';
|
|
359
377
|
stage = 'degraded';
|
|
@@ -395,16 +413,20 @@ export async function runRuntime(dir, version) {
|
|
|
395
413
|
process.removeListener('message', parentMessage);
|
|
396
414
|
process.removeListener('disconnect', parentGone);
|
|
397
415
|
try {
|
|
398
|
-
await activityLane.close();
|
|
399
416
|
detach?.();
|
|
400
417
|
await official?.close().catch(() => { });
|
|
401
418
|
}
|
|
402
419
|
finally {
|
|
403
420
|
try {
|
|
404
|
-
|
|
421
|
+
enrollment.close();
|
|
405
422
|
}
|
|
406
423
|
finally {
|
|
407
|
-
|
|
424
|
+
try {
|
|
425
|
+
closeJournal?.();
|
|
426
|
+
}
|
|
427
|
+
finally {
|
|
428
|
+
await release();
|
|
429
|
+
}
|
|
408
430
|
}
|
|
409
431
|
}
|
|
410
432
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { privateDirectory, privateManagedDirectory } from './config.js';
|
|
4
|
+
import { CONFIG_BYTES } from './resources.js';
|
|
5
|
+
import { runtimeHasLiveOwner } from './control.js';
|
|
6
|
+
import { managedEntry, stagePackage } from './service.js';
|
|
7
|
+
import { packageManaged, packageVersion, compatibleEntry, serviceEntry } from './updater.js';
|
|
8
|
+
import { readUpdateState, writeUpdateState, initialUpdateState, updateLock, supervisorRunning, autoUpdateDisabled } from './update-state.js';
|
|
9
|
+
import { object } from './limits.js';
|
|
10
|
+
export async function supportsLocalEnrollment(entry) {
|
|
11
|
+
const manifest = object(JSON.parse(await readFile(join(dirname(dirname(entry)), 'package.json'), 'utf8')));
|
|
12
|
+
const capability = manifest.moremote ? object(manifest.moremote) : {};
|
|
13
|
+
return capability.localEnrollment === 1 && typeof capability.configBytes === 'number' && capability.configBytes >= CONFIG_BYTES && await compatibleEntry(entry);
|
|
14
|
+
}
|
|
15
|
+
// Explicit setup may upgrade only this owned CLI, even when automatic updates
|
|
16
|
+
// are opted out. Never select an older public package as a feature fallback.
|
|
17
|
+
export async function setupServiceEntry(directory, currentEntry) {
|
|
18
|
+
const selected = readUpdateState(directory);
|
|
19
|
+
if (!selected && !await packageManaged())
|
|
20
|
+
return currentEntry;
|
|
21
|
+
await privateDirectory(directory);
|
|
22
|
+
await privateManagedDirectory(join(directory, 'managed'));
|
|
23
|
+
await privateManagedDirectory(join(directory, 'managed', 'versions'));
|
|
24
|
+
await updateLock(directory, async () => {
|
|
25
|
+
if (supervisorRunning(directory) || runtimeHasLiveOwner(directory))
|
|
26
|
+
throw Error('STOP_CLI_BEFORE_SETUP');
|
|
27
|
+
let state = readUpdateState(directory);
|
|
28
|
+
let entry = state ? await managedEntry(directory, state.active) : undefined;
|
|
29
|
+
const capable = entry ? await supportsLocalEnrollment(entry) : false;
|
|
30
|
+
if (state && capable && state.bootstrap === state.active)
|
|
31
|
+
return;
|
|
32
|
+
if (!entry || !capable) {
|
|
33
|
+
const version = await packageVersion();
|
|
34
|
+
try {
|
|
35
|
+
entry = await stagePackage(directory, version);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error instanceof Error && error.message.startsWith('FOREIGN_'))
|
|
39
|
+
throw error;
|
|
40
|
+
throw Error('SETUP_CURRENT_PACKAGE_UNAVAILABLE');
|
|
41
|
+
}
|
|
42
|
+
if (!await supportsLocalEnrollment(entry))
|
|
43
|
+
throw Error('SETUP_CAPABILITY_REQUIRED');
|
|
44
|
+
if (state) {
|
|
45
|
+
state.previous = state.active;
|
|
46
|
+
state.active = version;
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
state = initialUpdateState(version);
|
|
50
|
+
delete state.pending;
|
|
51
|
+
delete state.pendingManual;
|
|
52
|
+
delete state.activating;
|
|
53
|
+
delete state.manualRequired;
|
|
54
|
+
}
|
|
55
|
+
if (!state)
|
|
56
|
+
throw Error('SETUP_CAPABILITY_REQUIRED');
|
|
57
|
+
// The old bootstrap's compatibility reader cannot promise the enlarged
|
|
58
|
+
// config bound. Retain its immutable package/previous identity, not its loop.
|
|
59
|
+
state.bootstrap = state.active;
|
|
60
|
+
if (autoUpdateDisabled(directory))
|
|
61
|
+
state.enabled = false;
|
|
62
|
+
writeUpdateState(directory, state);
|
|
63
|
+
});
|
|
64
|
+
return serviceEntry(directory);
|
|
65
|
+
}
|
package/dist/setup.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Config } from './config.js';
|
|
2
|
+
export interface SetupDependencies {
|
|
3
|
+
yes: boolean;
|
|
4
|
+
home?: string;
|
|
5
|
+
stopOwned: () => Promise<void>;
|
|
6
|
+
authenticate: (config: Config) => Promise<{
|
|
7
|
+
serverId: string;
|
|
8
|
+
}>;
|
|
9
|
+
prepare?: () => Promise<void>;
|
|
10
|
+
install: () => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function setupEnrollment(directory: string, dependencies: SetupDependencies): Promise<Config>;
|
package/dist/setup.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { loadConfig, saveConfig, privateDirectory, validateOrigin } from './config.js';
|
|
4
|
+
import { DEFAULT_API_ORIGIN } from './local-enrollment.js';
|
|
5
|
+
import { ownRuntime } from './control.js';
|
|
6
|
+
// Lifecycle and identity I/O are injectable: consumer tests never register a
|
|
7
|
+
// service or touch the real home. Callers must use the owned lifecycle adapters.
|
|
8
|
+
export async function setupEnrollment(directory, dependencies) {
|
|
9
|
+
if (!dependencies.yes)
|
|
10
|
+
throw Error('EXPLICIT_YES_REQUIRED');
|
|
11
|
+
await dependencies.stopOwned();
|
|
12
|
+
// Preparation can stage an owned managed version, but never reads or writes
|
|
13
|
+
// enrollment configuration. A concurrent run wins safely before we claim it.
|
|
14
|
+
await dependencies.prepare?.();
|
|
15
|
+
await privateDirectory(directory);
|
|
16
|
+
let cancelled = false;
|
|
17
|
+
const release = await ownRuntime(directory, () => ({ stage: 'setup' }), () => { cancelled = true; });
|
|
18
|
+
let config;
|
|
19
|
+
try {
|
|
20
|
+
config = await loadConfig(directory);
|
|
21
|
+
const origin = validateOrigin(config.apiOrigin ?? DEFAULT_API_ORIGIN, false);
|
|
22
|
+
const identity = await dependencies.authenticate(config);
|
|
23
|
+
if (cancelled)
|
|
24
|
+
throw Error('SETUP_CANCELLED');
|
|
25
|
+
if (!identity.serverId || Buffer.byteLength(identity.serverId) > 512 || config.daemonServerId && config.daemonServerId !== identity.serverId || config.pairs.some(pair => pair.revokedAt === undefined && pair.relayRetiredAt === undefined && pair.daemonServerId && pair.daemonServerId !== identity.serverId))
|
|
26
|
+
throw Error('DAEMON_IDENTITY_CHANGED');
|
|
27
|
+
config.apiOrigin = origin;
|
|
28
|
+
config.cloudEnabled = true;
|
|
29
|
+
config.daemonServerId = identity.serverId;
|
|
30
|
+
config.localEnrollment = { home: resolve(dependencies.home ?? homedir()) };
|
|
31
|
+
await saveConfig(directory, config);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
await release();
|
|
35
|
+
}
|
|
36
|
+
await dependencies.install();
|
|
37
|
+
return config;
|
|
38
|
+
}
|
package/docs/STATE.md
CHANGED
|
@@ -1,8 +1,175 @@
|
|
|
1
|
-
# Current state — 2026-11-
|
|
1
|
+
# Current state — 2026-11-14
|
|
2
|
+
|
|
3
|
+
## Unreleased notification-only source — 2026-11-14
|
|
4
|
+
|
|
5
|
+
Cloudflare retains only notifications and explicit notification replies/approvals.
|
|
6
|
+
Deleted activity interests, optional surface lane, widget fingerprints and quota
|
|
7
|
+
reads. `/state` contains verified daemon identity and exact current bound requests
|
|
8
|
+
only. Accepted source reads retain pending requests outside bounded discovery;
|
|
9
|
+
resolution/replacement/reconnect fences prevent stale resurrection. Publish only
|
|
10
|
+
semantic changes, one final clear, and near-expiry pending hydration. Unknown
|
|
11
|
+
ACK retries keep original bytes and cannot replay user actions.
|
|
12
|
+
|
|
13
|
+
Fresh full `npm run check` passes237 behavioral tests, types and compilation.
|
|
14
|
+
Real SDK and real runtime subprocess consumers verify preserved notification
|
|
15
|
+
question/approval encoding,3s control cadence, normal/outage pause fences,
|
|
16
|
+
immutable lost acknowledgements, drain/receipt ownership and zero idle surface or
|
|
17
|
+
directory calls. Projection tests first exposed leaked title/host/usage fields
|
|
18
|
+
and silently dropped oversized requests; all now pass. Read-only independent
|
|
19
|
+
review found no remaining authority/replay blocker. No service registration,
|
|
20
|
+
installed runtime, npm publication or production host session was changed.
|
|
21
|
+
Published0.1.4 below remains the released artifact, not this new source.
|
|
22
|
+
|
|
23
|
+
## Released0.1.4 — 2026-11-13
|
|
24
|
+
|
|
25
|
+
- Owner-authorizedv0.1.4 targets tested sourcea5615b6. Final local251/251,
|
|
26
|
+
typecheck/build and independent source reviews pass. HostedCI43389151913 passes
|
|
27
|
+
complete checks/identity/real upgrade and rollback on Linux, macOS and Windows.
|
|
28
|
+
- Release43390548675 succeeds through existing-secret npm/provenance and GitHub
|
|
29
|
+
publication. Independent public reads confirm version/latest0.1.4; downloaded
|
|
30
|
+
npm/GitHub bytes match SHA1/SHA512, GitHubSHA256SUMS and the exact local artifact.
|
|
31
|
+
SHA256: `c0e56b6ce596216fea6b2e546fc153c3833bafebc4c5ecf271d18b6a2d4e5151`.
|
|
32
|
+
- No everyday service, ordinary official conversation or production cloud change.
|
|
33
|
+
Earlier unreleased/acceptance entries below are historical checkpoints; these
|
|
34
|
+
verified publication facts supersede their former release status.
|
|
35
|
+
|
|
36
|
+
- Pending questions/approvals now use a stable current-occurrence clock, not an
|
|
37
|
+
older task-completion clock. Actual SDK delayed-current/snapshot regressions
|
|
38
|
+
first reproduce resolution/replacement resurrection, then the observation fence
|
|
39
|
+
prevents journal, binding and notification renewal. Actual same-batch SDK reply
|
|
40
|
+
consumers also reproduce caller-continuation resurrection before repair: adapter
|
|
41
|
+
journal ownership removes duplicate synchronization, source fingerprints prevent
|
|
42
|
+
old request text acquiring a replacement binding, and crypto rechecks currentness.
|
|
43
|
+
Cached question/approval consumers fail before exact occurrence capture/drain
|
|
44
|
+
binding, then notifications10/10 pass without old clocks consuming new IDs.
|
|
45
|
+
Final unchanged-input full check passes251/251,typecheck and build. Independent
|
|
46
|
+
Stage A closes both lifecycle blockers; final quality re-review and hosted
|
|
47
|
+
three-platform verification remain pending before immutable publication.
|
|
48
|
+
- Quality review catches observed in-place mutation followed by valid rename;
|
|
49
|
+
both real regressions fail before the pre-retry guard, then resource24/24 pass.
|
|
50
|
+
Hosted40e1b73 passes Linux/macOS but Windows rejects test-injected replacement
|
|
51
|
+
with a live handle. Tests now verify real refusal, complete original contents
|
|
52
|
+
and identity, then actual post-close replacement and strict unsafe-file refusal;
|
|
53
|
+
no production error guard or platform coverage is removed. Narrow review passes.
|
|
54
|
+
|
|
55
|
+
- Ordinary config rename is now distinguished from an unsafe resource: at most
|
|
56
|
+
three reopen attempts, independent descriptor/path validation, retired handles
|
|
57
|
+
discarded, strict no-follow/user/private-mode/link/byte/encoding checks retained.
|
|
58
|
+
Same-inode content changes remain rejected. Real rename regressions reproduce
|
|
59
|
+
the failure before repair, then22resource consumers and the original2runtime
|
|
60
|
+
cases pass. Final unchanged-input full check passes235/235,typecheck and build.
|
|
61
|
+
Stage A narrow review passes; independent quality/security review and fresh
|
|
62
|
+
hosted three-platform verification remain in progress before publication.
|
|
63
|
+
|
|
64
|
+
- Hosted1df64e0 exercises all new behaviors successfully on Windows, but its
|
|
65
|
+
new cache fixture removes the directory before closing SQLite. Combine cleanup
|
|
66
|
+
into one ordered close-then-remove hook; preserve all behavior assertions and
|
|
67
|
+
rerun the full matrix on the corrected test source. Production code is unchanged.
|
|
68
|
+
|
|
69
|
+
- Corrected8e4e065 Windows cleanup passes; macOS then rejects signaling an
|
|
70
|
+
already stopped wrapper's old process group. Preserve independent lock/control/
|
|
71
|
+
supervisor/exit assertions and skip redundant group signaling only after those
|
|
72
|
+
shutdown proofs. All4actual local lifecycle consumers pass; narrow review agrees.
|
|
73
|
+
|
|
74
|
+
- Exact tagv0.1.3 and its successful three-platform CI43380589650 are retained.
|
|
75
|
+
Release43381419784 fails its full check before packaging/publication: concurrent
|
|
76
|
+
normal runtime config replacement triggers FOREIGN_RESOURCE_LIMIT in a read.
|
|
77
|
+
Publish and GitHub Release steps are skipped; no0.1.3 package is submitted.
|
|
78
|
+
Preserve that immutable failed tag and prepare0.1.4 after a deterministic repair.
|
|
79
|
+
|
|
80
|
+
- First hosted run43378427840 correctly rejects three cross-environment fixture
|
|
81
|
+
defects: inherited config/service paths, unsupported Windows POSIX-mode equality,
|
|
82
|
+
and an unbound synthetic Paseo home whose local mismatch check had accidentally
|
|
83
|
+
contacted the ordinary daemon read-only. Bind the exact fixture home and require
|
|
84
|
+
its real handshake, no cloud calls, unchanged config and private-output absence.
|
|
85
|
+
- Stricter pending-endpoint controls return409 before activation. Runtime now
|
|
86
|
+
activates only after official identity and original expiry/revocation checks;
|
|
87
|
+
no command/state lane exists in that cycle, and the next cycle validates controls.
|
|
88
|
+
Shared origin quota fences and fixed activation proof remain intact. Independent
|
|
89
|
+
narrow review finds no blocker. Final unchanged-input full check passes221/221
|
|
90
|
+
and build; hosted portability/packaged smoke are being rerun on this exact delta.
|
|
91
|
+
|
|
92
|
+
- Integrated51942a0 and reviewed the final enrollment/setup and packaging delta.
|
|
93
|
+
Exact public0.1.2 archive bytes now live in the test fixtures with verified npm
|
|
94
|
+
SHA1/SHA512 and matching recorded GitHub SHA256, independent of workstation caches.
|
|
95
|
+
- Final full check passes typecheck,221/221 tests and build. Three actual retained
|
|
96
|
+
public0.1.2 migration consumers pass. Real packaged activation/failed-start
|
|
97
|
+
rollback/retained frontend and clean shutdown pass; no everyday service is installed.
|
|
98
|
+
- Release validation accepts additive capability metadata while retaining the
|
|
99
|
+
strict1/1/1 protocol tuple and exact source/package capability equality.
|
|
100
|
+
Constructor-scoped fixture isolation removes inherited operator credentials;
|
|
101
|
+
the smoke retries only read-only unproven-stage probes under its live owned supervisor.
|
|
102
|
+
- Independent Stage A and Stage B reviews find no remaining scoped blocker.
|
|
103
|
+
Main integration, hosted checks, immutable npm/GitHub publication and independent
|
|
104
|
+
registry receipt remain pending. The production cloud remains unchanged.
|
|
2
105
|
|
|
3
106
|
## Scope
|
|
4
107
|
|
|
5
|
-
Owner-approved notification/scoped delivery
|
|
108
|
+
Owner-approved notification/scoped delivery; local native surfaces are app-owned; Apache-2.0. Standalone Node24 companion targeting inspected official SDK/protocol0.15.3. Existing iOS protocol-vector floor is independent and unchanged. OpenUI and broader system extensions remain outside this scope.
|
|
109
|
+
|
|
110
|
+
## Unreleased single-pairing enrollment — source0.1.3, locally accepted
|
|
111
|
+
|
|
112
|
+
- Official Paseo pairing is the only normal user pairing. Explicit
|
|
113
|
+
`setup --yes` prepares the optional owned CLI service; a connected native
|
|
114
|
+
client exchanges the existing per-phone offer through official authenticated
|
|
115
|
+
file APIs. No second QR, pasted invitation, terminal command or new relay
|
|
116
|
+
configuration is required in the app.
|
|
117
|
+
- Discovery is private and bounded; original request identity/expiry, canonical
|
|
118
|
+
offer and cloud-create bytes are durable before network I/O. Activation and
|
|
119
|
+
expiry remove the private handoff. Revocation, retained active phones, custom
|
|
120
|
+
origin, daemon pinning and managed-update opt-out remain authoritative.
|
|
121
|
+
- Confirmed review findings are fixed: duplicate runtime startup never rewrites
|
|
122
|
+
configuration; setup prepares packages before acquiring shared runtime
|
|
123
|
+
ownership, then holds it across load/authenticate/save. A concurrent runtime
|
|
124
|
+
either wins before config loading or is refused. Config readers/writers share
|
|
125
|
+
the524288-byte encoded bound; old managed0.1.2 setup selects a verified
|
|
126
|
+
enrollment-capable current package instead of silently enabling old code.
|
|
127
|
+
- Optional admission performs at most one cloud-create attempt per cycle with
|
|
128
|
+
its own3-second deadline. Unknown results retain exact retry bytes. No cloud
|
|
129
|
+
endpoint, recursive dispatch, polling budget or production deployment changes.
|
|
130
|
+
- Node24.13.0 typecheck passes. The final six-file selection passes37/38;
|
|
131
|
+
its remaining source-setup assertion incorrectly demanded absence of an
|
|
132
|
+
internal managed directory. That implementation-detail assertion is removed,
|
|
133
|
+
while actual package-manager refusal and service-entry checks remain. The
|
|
134
|
+
corrected consumer passes independently and the compiled build passes.
|
|
135
|
+
Both new setup/runtime interleavings failed before the ownership correction.
|
|
136
|
+
- Actual unmodified official Paseo0.15.4 and the native transport exchange the
|
|
137
|
+
canonical offer, verify the real native claim and unchanged activation proof,
|
|
138
|
+
and remove exact private request/response files. One cloud-create body and
|
|
139
|
+
zero official agents are observed. The cloud is a local in-process test
|
|
140
|
+
double; this is not production, physical-device or APNs acceptance.
|
|
141
|
+
- Independent-context source re-review closes the scoped native/CLI findings.
|
|
142
|
+
The weaker same-provider route is explicit; unavailable external native
|
|
143
|
+
reviews are not approvals. Temporary probe code/state are removed, with
|
|
144
|
+
redacted receipts retained outside the repository.
|
|
145
|
+
- Source0.1.3 remains unpublished. Public0.1.2, shared production and existing
|
|
146
|
+
official data are unchanged. No npm tag, TestFlight upload or phone install
|
|
147
|
+
is implied.
|
|
148
|
+
|
|
149
|
+
## Unreleased Share-first onboarding delta — locally verified
|
|
150
|
+
|
|
151
|
+
- Approved cross-repository plan: MoRemote
|
|
152
|
+
`docs/plans/2026-11-13-share-first-onboarding.md`; CLI ownership is source,
|
|
153
|
+
focused consumers and public docs only. No publication or deployment.
|
|
154
|
+
- Explicit `pair` opts in to cloud, uses the production endpoint only when no
|
|
155
|
+
origin exists, and reuses existing official listen/credential discovery.
|
|
156
|
+
Origin validation, daemon pinning, custom targets/origins and retained
|
|
157
|
+
pair authority remain intact. Plain load/check/status remain passive.
|
|
158
|
+
- Task snapshots carry genuine provider and ISO-8601 creation time alongside
|
|
159
|
+
last-user time, through existing bounded projection and authenticated state.
|
|
160
|
+
Widget equality includes the new meaningful metadata. No assistant-update
|
|
161
|
+
substitution for user recency.
|
|
162
|
+
- Added actual CLI enrollment consumers with a synthetic official WebSocket
|
|
163
|
+
and isolated relay, passive diagnostics/custom authority/invalid-origin and
|
|
164
|
+
daemon-pin cases; added real-SDK encrypted task metadata consumers.
|
|
165
|
+
- Node24.13.0 typecheck, 22 focused pair-onboarding/task-projection/activity/CLI
|
|
166
|
+
consumers, and compiled build pass. The actual SDK/HTTP boundary exercises
|
|
167
|
+
passive diagnostics, authenticated enrollment, custom authority and encrypted
|
|
168
|
+
metadata without production enrollment or official-file changes.
|
|
169
|
+
- Independent read-only review `run-20261113030053-9f69faa3` approves the scoped
|
|
170
|
+
implementation. The same-provider fallback is explicit; this is not physical
|
|
171
|
+
acceptance or a new package release. Public0.1.2 and its cached receiver remain
|
|
172
|
+
unchanged.
|
|
6
173
|
|
|
7
174
|
## Native service acceptance — 2026-11-12
|
|
8
175
|
|
|
@@ -34,10 +201,10 @@ Owner-approved notification/scoped delivery and local activity/widget integratio
|
|
|
34
201
|
later decision; these isolated native tests neither use nor disable it. Older
|
|
35
202
|
temporary-window shutdown receipts below are historical, not current policy.
|
|
36
203
|
|
|
37
|
-
##
|
|
204
|
+
## Released0.1.2 — 2026-11-12
|
|
38
205
|
|
|
39
|
-
- Package and lock root identities
|
|
40
|
-
tuple changes.
|
|
206
|
+
- Package and lock root identities select0.1.2; no dependency or compatibility
|
|
207
|
+
tuple changes. Owner-approved tagv0.1.2 targets739c76008ea583fa86bfb023dafaa17a3ea9adf4.
|
|
41
208
|
- The combined check passes typecheck and180/181 tests. Its remaining legacy-wire
|
|
42
209
|
case incorrectly requires an extra read for an old event that may be coalesced.
|
|
43
210
|
The test now drains the actual wire and retains the phone-visible no-new-notice
|
|
@@ -46,15 +213,32 @@ Owner-approved notification/scoped delivery and local activity/widget integratio
|
|
|
46
213
|
failed-start rollback/aliased frontend/clean stop, release identity validation
|
|
47
214
|
and deterministic0.1.2 packaging pass. These overlapping runs are not a new
|
|
48
215
|
single green full-suite result.
|
|
49
|
-
- Hosted
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
216
|
+
- Hosted CI43227228037 passes full check/build, release validation and real
|
|
217
|
+
packaged upgrade on Ubuntu24.04, macOS15 and Windows2025.
|
|
218
|
+
Automatic Release43232455123 passes check/build, upgrade smoke, deterministic
|
|
219
|
+
packaging, existing-secret npm publication/provenance and GitHub Release.
|
|
220
|
+
- Anonymous registry reads independently confirm version/latest0.1.2 after
|
|
221
|
+
asynchronous processing; publication is never repeated. Downloaded GitHub
|
|
222
|
+
bytes match SHA256SUMS and npm SHA1/SHA512 integrity. Archive SHA256:
|
|
223
|
+
`845fd98470964303a6a86dc696e64c47ac1e7b1ce90b59cd730cdec56d64f9bb`.
|
|
224
|
+
- Actual public0.1.1 installation/retained supervisor discovers and downloads
|
|
225
|
+
public0.1.2 through its unchanged normal background scheduler, not a custom
|
|
226
|
+
fetcher, direct queue, altered package or fake clock. Exact authenticated
|
|
227
|
+
status becomes0.1.2; bootstrap/previous remain0.1.1; retained frontend returns
|
|
228
|
+
0.1.2; normal stop exits0 and all owned processes/files are removed, in80.12s.
|
|
229
|
+
No login service, real official connection or cloud operation occurs.
|
|
230
|
+
An initial fixture prepopulates an unowned state directory and is correctly
|
|
231
|
+
rejected before any process starts; initialization is corrected outside the
|
|
232
|
+
managed state, preserving strict ownership. Its exact failed fixture is removed.
|
|
233
|
+
- Production device reply/approval and remote activity/widget delivery still
|
|
234
|
+
require their separate acceptance; the release does not claim those gates.
|
|
235
|
+
- Release: https://github.com/moxuli/moremote-cli/releases/tag/v0.1.2
|
|
236
|
+
|
|
237
|
+
## Released activity/widget integration — production acceptance open
|
|
238
|
+
|
|
239
|
+
- Published install identity is **`@moxuli/moremote`0.1.2**; command/runtime
|
|
56
240
|
remains `moremote-cli`, with existing per-platform service identities.
|
|
57
|
-
|
|
241
|
+
Activity/widget changes are included; physical production acceptance remains open.
|
|
58
242
|
- Implemented locally: authenticated encrypted per-task interests and activity
|
|
59
243
|
state, an owned optional2s host lane with250ms exact fallback reads, meaningful
|
|
60
244
|
keyed widget fingerprints on existing snapshot publication, and normal-only
|