@moxuli/moremote 0.1.2 → 0.1.4
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 +53 -22
- package/bin/moremote-cli.js +11 -4
- package/dist/activity.d.ts +2 -0
- package/dist/activity.js +1 -1
- package/dist/cli.js +33 -7
- package/dist/cloud-client.d.ts +1 -1
- package/dist/cloud-client.js +1 -1
- 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/official-client.d.ts +15 -1
- package/dist/official-client.js +73 -32
- package/dist/operations.d.ts +1 -0
- package/dist/operations.js +24 -4
- package/dist/projection.d.ts +2 -0
- package/dist/resources.d.ts +2 -1
- package/dist/resources.js +67 -31
- package/dist/runtime.d.ts +10 -1
- package/dist/runtime.js +71 -6
- 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 +165 -12
- package/docs/configuration.md +60 -0
- 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 +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Optional, independent Apache-2.0 computer companion for MoRemote and an **unmodified Paseo 0.15.3** daemon. Existing official-only clients keep working without this project or its cloud.
|
|
4
4
|
|
|
5
5
|
Canonical repository/command: `moremote-cli`; public npm package:
|
|
6
|
-
**`@moxuli/moremote`** (published **0.1.
|
|
6
|
+
**`@moxuli/moremote`** (published **0.1.2**); source entry: `bin/moremote-cli.js`.
|
|
7
7
|
There is no unscoped npm alias or automatic adoption of foreign/old state.
|
|
8
8
|
|
|
9
9
|
## Install the published package
|
|
@@ -21,7 +21,7 @@ alone stays manual. No command starts/upgrades the official daemon.
|
|
|
21
21
|
|
|
22
22
|
## Build and foreground use
|
|
23
23
|
|
|
24
|
-
Requires Node **24.13.0 or later on Node 24** and npm.
|
|
24
|
+
Requires Node **24.13.0 or later on Node 24** and npm. Dependency installation and builds do not register a service; only explicit lifecycle commands do.
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
27
|
npm ci --ignore-scripts
|
|
@@ -34,35 +34,65 @@ node bin/moremote-cli.js run
|
|
|
34
34
|
|
|
35
35
|
The example endpoint is synthetic. Omit `--target` to use the official `paseo.pid` listen address under `PASEO_HOME` (otherwise the platform home’s `.paseo`). Auth follows the official CLI: target password, then `PASEO_PASSWORD`, otherwise a rotating local credential only when the selected target exactly matches the pid listen address after official normalization. Credentials are never printed or uploaded. No automatic daemon start or upgrade.
|
|
36
36
|
|
|
37
|
-
## Connect
|
|
37
|
+
## Connect once through official Paseo
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
Single-pairing setup requires **MoRemote CLI0.1.4 or later**. Update an older
|
|
40
|
+
CLI before using this command. Publication and platform acceptance receipts are
|
|
41
|
+
recorded in `docs/STATE.md`.
|
|
42
|
+
|
|
43
|
+
With the official Paseo daemon already running:
|
|
41
44
|
|
|
42
45
|
```sh
|
|
43
|
-
moremote-cli
|
|
44
|
-
moremote-cli check --connect
|
|
45
|
-
moremote-cli pair
|
|
46
|
-
moremote-cli run
|
|
46
|
+
moremote-cli setup --yes
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
This explicit command authenticates the existing official daemon, enables cloud
|
|
50
|
+
and automatic local enrollment, and installs/starts only the CLI's owned per-user
|
|
51
|
+
background service. It preserves configured targets/custom HTTPS origins, active
|
|
52
|
+
and revoked phones, and existing update preferences. With no origin configured,
|
|
53
|
+
it selects `https://moremote-cloud-ingress.pages.dev`. It never starts, modifies
|
|
54
|
+
or upgrades Paseo or global tools. Source-checkout setup without managed state
|
|
55
|
+
binds the current source frontend and retains manual updates. Installed packages
|
|
56
|
+
or retained managed state require an enrollment-capable runtime: explicit setup
|
|
57
|
+
can install the exact current CLI version into owned private state, preserving
|
|
58
|
+
the automatic-update opt-out. A missing current package/capability fails clearly
|
|
59
|
+
before enabling enrollment, never by substituting old public code. The immutable
|
|
60
|
+
old package stays retained; its selected runtime/bootstrap move to capable code.
|
|
61
|
+
|
|
62
|
+
Pair the computer **only in official Paseo**. A compatible MoRemote app uses
|
|
63
|
+
that already authenticated connection's ordinary file channel to discover the
|
|
64
|
+
optional CLI and enroll its own phone automatically, even before a workspace
|
|
65
|
+
exists. There is no second QR, paste field, terminal, hidden workspace or relay.
|
|
66
|
+
Missing installation appears only in the enhancement surface. A previously
|
|
67
|
+
disabled/revoked phone is not silently re-enabled.
|
|
68
|
+
|
|
69
|
+
Discovery is private local state under
|
|
70
|
+
`<home>/.moremote-cli-connect/<sha256(daemonServerId)>/`. Descriptor origins are
|
|
71
|
+
pinned through that authenticated file channel; each bounded immutable request
|
|
72
|
+
gets its original per-phone offer and unchanged endpoint proof handshake. Secret
|
|
73
|
+
responses are never printed and are removed on activation/expiry. See the
|
|
74
|
+
[complete version-1 contract](docs/specs/05-endpoint-and-lifecycle.md#single-pairing-local-enrollment-v1-unreleased).
|
|
75
|
+
|
|
76
|
+
For an advanced custom authority, configure it before explicit setup:
|
|
58
77
|
|
|
59
78
|
```sh
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
node bin/moremote-cli.js run
|
|
79
|
+
moremote-cli configure --api-origin https://relay.example.test
|
|
80
|
+
moremote-cli setup --yes
|
|
63
81
|
```
|
|
64
82
|
|
|
65
|
-
|
|
83
|
+
Plain config loads, `check` and `status` stay passive; only `check --connect`
|
|
84
|
+
makes a read-only official connection. They do not enable cloud, enroll a phone,
|
|
85
|
+
create discovery or install a service.
|
|
86
|
+
|
|
87
|
+
### Expert-only manual enrollment
|
|
88
|
+
|
|
89
|
+
`moremote-cli pair` remains an explicit expert tool, not the normal app flow.
|
|
90
|
+
It prints a **secret**, ten-minute, one-phone QR/link (`--json` prints canonical
|
|
91
|
+
offer JSON), enables cloud on the configured/default origin and waits for the
|
|
92
|
+
original encrypted claim/activation proof. Never share screenshots or log its
|
|
93
|
+
output. It installs no service. Existing custom origins and per-phone authority
|
|
94
|
+
remain unchanged. Published 0.1.2 requires explicit origin/cloud configuration
|
|
95
|
+
before using that legacy manual path.
|
|
66
96
|
|
|
67
97
|
## Optional activities and widget reloads — unreleased source
|
|
68
98
|
|
|
@@ -101,6 +131,7 @@ Endpoint cancellation/revocation uses authenticated encrypted controls and durab
|
|
|
101
131
|
## Lifecycle and ownership
|
|
102
132
|
|
|
103
133
|
- `status` and `check` are redacted. Only explicit `check --connect` contacts the selected official daemon (read-only).
|
|
134
|
+
- `setup --yes`: explicit automatic-enrollment/cloud opt-in plus only the owned per-user background service; no second user pairing or official changes. Existing custom authorities, phone records and update opt-out survive.
|
|
104
135
|
- `service-install --yes`: explicit per-user LaunchAgent on macOS, systemd user unit on Linux, or least-privilege interactive-user **logon task** on Windows (not an administrator Windows Service). Foreground `run` needs none of these. No sudo/admin installation.
|
|
105
136
|
- `stop`: stop only the owned companion registration/runtime; never signal an official process. Linux/Windows registration remains available for a future login; macOS bootout leaves its owned plist available for explicit reinstallation.
|
|
106
137
|
- `unpair --pair-id <exact-id>`: revoke one phone, leaving other phones unchanged. Stop the runtime first.
|
package/bin/moremote-cli.js
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {resolve} from 'node:path';
|
|
2
|
+
import {resolve,join,dirname} from 'node:path';
|
|
3
3
|
import {fileURLToPath} from 'node:url';
|
|
4
4
|
import {spawn} from 'node:child_process';
|
|
5
|
-
import {realpath} from 'node:fs/promises';
|
|
5
|
+
import {realpath,readFile} from 'node:fs/promises';
|
|
6
6
|
async function main(){
|
|
7
7
|
const {dataDirectory}=await import('../dist/config.js');
|
|
8
8
|
const {readUpdateState}=await import('../dist/update-state.js');
|
|
9
9
|
const {managedEntry}=await import('../dist/service.js');
|
|
10
10
|
// Dispatch before parsing: an old global frontend must accept a newer
|
|
11
11
|
// selected CLI's flags, including --version. Never overwrite that frontend.
|
|
12
|
-
let dir=dataDirectory();const args=process.argv.slice(2);
|
|
12
|
+
let dir=dataDirectory(),action;const args=process.argv.slice(2);
|
|
13
13
|
for(let i=0;i<args.length&&args[i]!=='--';i++){
|
|
14
14
|
if(args[i]==='--data-dir'&&args[i+1])dir=args[++i];
|
|
15
15
|
else if(args[i].startsWith('--data-dir='))dir=args[i].slice(11);
|
|
16
|
+
else if(!args[i].startsWith('-')&&action===undefined)action=args[i];
|
|
16
17
|
}
|
|
17
18
|
const state=readUpdateState(resolve(dir));
|
|
19
|
+
const currentPackage=JSON.parse(await readFile(new URL('../package.json',import.meta.url),'utf8'));
|
|
20
|
+
// A retained selected runtime can predate setup. The current capability-owning
|
|
21
|
+
// package must handle that explicit migration instead of forwarding to old code.
|
|
22
|
+
const currentSetup=action==='setup'&¤tPackage.moremote?.localEnrollment===1;
|
|
18
23
|
if(state&&!process.env.MOREMOTE_MANAGED_CHILD){
|
|
19
24
|
const entry=await managedEntry(resolve(dir),state.active);
|
|
20
|
-
|
|
25
|
+
const selectedPackage=currentSetup?JSON.parse(await readFile(join(dirname(dirname(entry)),'package.json'),'utf8')):undefined;
|
|
26
|
+
const selectedSetup=selectedPackage?.moremote?.localEnrollment===1&&selectedPackage.moremote.configBytes>=currentPackage.moremote.configBytes;
|
|
27
|
+
if((!currentSetup||selectedSetup)&&await realpath(entry)!==await realpath(fileURLToPath(import.meta.url))){
|
|
21
28
|
const child=spawn(process.execPath,[entry,...args],{stdio:['inherit','inherit','inherit','ipc'],shell:false,windowsHide:true});
|
|
22
29
|
const result=Promise.withResolvers();child.once('error',result.reject);child.once('exit',code=>result.resolve(code??1));
|
|
23
30
|
const ready=message=>{if(message&&typeof message==='object'&&message.kind==='moremote-ready'&&typeof message.version==='string'&&process.send&&process.connected)process.send({kind:'moremote-ready',version:message.version},undefined,undefined,()=>{})};
|
package/dist/activity.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface ActivityTask {
|
|
|
8
8
|
updatedAt: string;
|
|
9
9
|
requiresAttention: boolean;
|
|
10
10
|
attentionReason: string | null;
|
|
11
|
+
provider?: string;
|
|
12
|
+
createdAt?: string | null;
|
|
11
13
|
lastUserMessageAt?: string | null;
|
|
12
14
|
activeTurnStartedAt?: string | null;
|
|
13
15
|
cwd?: string | null;
|
package/dist/activity.js
CHANGED
|
@@ -34,7 +34,7 @@ function usageValues(value) {
|
|
|
34
34
|
}
|
|
35
35
|
/** Keyed opaque equality token; no raw task, usage, or title enters cloud metadata. */
|
|
36
36
|
export async function widgetFingerprint(pair, snapshot) {
|
|
37
|
-
const tasks = snapshot.tasks.map(task => ({ agentId: task.agentId, title: task.title, status: task.status,
|
|
37
|
+
const tasks = snapshot.tasks.map(task => ({ agentId: task.agentId, provider: task.provider ?? null, createdAt: task.createdAt ?? null, title: task.title, status: task.status,
|
|
38
38
|
requiresAttention: task.requiresAttention, attentionReason: task.attentionReason,
|
|
39
39
|
lastUserMessageAt: task.lastUserMessageAt ?? null, activeTurnStartedAt: task.activeTurnStartedAt ?? null,
|
|
40
40
|
cwd: task.cwd ?? null, pendingRequestIds: task.pendingRequests?.map(p => p.requestId).sort() ?? [] })).sort((a, b) => a.agentId.localeCompare(b.agentId));
|
package/dist/cli.js
CHANGED
|
@@ -9,18 +9,21 @@ import { OfficialClient } from './official-client.js';
|
|
|
9
9
|
import { CloudClient } from './cloud-client.js';
|
|
10
10
|
import { makeOffer, tokenHash, activatePending } from './pairing.js';
|
|
11
11
|
import { runRuntime } from './runtime.js';
|
|
12
|
-
import { requestControl } from './control.js';
|
|
12
|
+
import { requestControl, runtimeHasLiveOwner } from './control.js';
|
|
13
13
|
import { currentDefinition, installService, removeService, stopService, serviceStatus } from './service.js';
|
|
14
14
|
import { ensureManaged, packageManaged, packageVersion, queueUpdate, setAutoUpdate, readUpdateState, serviceEntry } from './updater.js';
|
|
15
15
|
import { runSupervisor, stopManagedRuntime } from './supervisor.js';
|
|
16
16
|
import { OperationJournal } from './journal.js';
|
|
17
17
|
const VERSION = await packageVersion();
|
|
18
|
+
import { setupEnrollment } from './setup.js';
|
|
19
|
+
import { setupServiceEntry } from './setup-upgrade.js';
|
|
18
20
|
const HELP = `MoRemote CLI ${VERSION} — optional Paseo 0.15.3 enhancement
|
|
19
21
|
Usage: moremote-cli <command> [options]
|
|
22
|
+
setup --yes Enable automatic enrollment and own background service
|
|
20
23
|
configure --target <official-target> --api-origin <https-origin> [--cloud-on]
|
|
21
24
|
[--paseo-home <directory>] [--allow-loopback-http]
|
|
22
25
|
check [--connect] Redacted local checks; --connect is read-only
|
|
23
|
-
pair [--json]
|
|
26
|
+
pair [--json] Expert-only private one-phone offer and activation
|
|
24
27
|
run Foreground observer and scoped command consumer
|
|
25
28
|
status Redacted runtime/config/owned-service/update state
|
|
26
29
|
service-install --yes Explicit per-user managed CLI login registration
|
|
@@ -91,7 +94,8 @@ async function main() {
|
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
96
|
if (action === 'run') {
|
|
94
|
-
|
|
97
|
+
if (runtimeHasLiveOwner(dir))
|
|
98
|
+
throw Error('CLI_ALREADY_RUNNING');
|
|
95
99
|
if (process.env.MOREMOTE_MANAGED_CHILD) {
|
|
96
100
|
try {
|
|
97
101
|
await runRuntime(dir, VERSION);
|
|
@@ -121,6 +125,27 @@ async function main() {
|
|
|
121
125
|
console.log('MoRemote CLI stopped; official Paseo unchanged.');
|
|
122
126
|
return;
|
|
123
127
|
}
|
|
128
|
+
if (action === 'setup') {
|
|
129
|
+
let preparedEntry;
|
|
130
|
+
await setupEnrollment(dir, { yes: !!args.yes, stopOwned: () => stopOwned(dir, definition), authenticate: async (current) => {
|
|
131
|
+
const official = new OfficialClient(current);
|
|
132
|
+
try {
|
|
133
|
+
await official.connect();
|
|
134
|
+
return { serverId: official.info().serverId };
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
await official.close();
|
|
138
|
+
}
|
|
139
|
+
}, prepare: async () => {
|
|
140
|
+
preparedEntry = await setupServiceEntry(dir, fileURLToPath(new URL('../bin/moremote-cli.js', import.meta.url)));
|
|
141
|
+
}, install: async () => {
|
|
142
|
+
if (!preparedEntry)
|
|
143
|
+
throw Error('SETUP_CAPABILITY_REQUIRED');
|
|
144
|
+
await installService(currentDefinition(preparedEntry, dir));
|
|
145
|
+
} });
|
|
146
|
+
console.log('MoRemote CLI automatic enrollment and owned per-user service enabled. Official Paseo unchanged.');
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
124
149
|
if (action === 'configure') {
|
|
125
150
|
await stopped(dir);
|
|
126
151
|
pruneRetiredPairs(config);
|
|
@@ -152,20 +177,21 @@ async function main() {
|
|
|
152
177
|
}
|
|
153
178
|
if (action === 'pair') {
|
|
154
179
|
await stopped(dir);
|
|
155
|
-
if (!config.apiOrigin || !config.cloudEnabled)
|
|
156
|
-
throw Error('CONFIGURE_AND_OPT_IN_CLOUD_FIRST');
|
|
157
180
|
if (config.pairs.length >= 16)
|
|
158
181
|
throw Error('PAIRING_LIMIT');
|
|
182
|
+
const origin = validateOrigin(config.apiOrigin ?? 'https://moremote-cloud-ingress.pages.dev', config.allowLoopbackHttp);
|
|
159
183
|
const official = new OfficialClient(config);
|
|
160
184
|
try {
|
|
161
185
|
await official.connect();
|
|
162
186
|
const info = official.info();
|
|
187
|
+
config.apiOrigin = origin;
|
|
188
|
+
config.cloudEnabled = true;
|
|
163
189
|
config.daemonServerId = info.serverId;
|
|
164
|
-
const { pair, offer } = makeOffer(
|
|
190
|
+
const { pair, offer } = makeOffer(origin);
|
|
165
191
|
pair.daemonServerId = info.serverId;
|
|
166
192
|
config.pairs.push(pair);
|
|
167
193
|
await saveConfig(dir, config);
|
|
168
|
-
const cloud = new CloudClient(
|
|
194
|
+
const cloud = new CloudClient(origin, pair.pairId, pair.hostToken, config.allowLoopbackHttp);
|
|
169
195
|
await cloud.create({ pairId: pair.pairId, hostTokenHash: tokenHash(pair.hostToken), enrollmentTokenHash: tokenHash(pair.enrollmentToken), expiresAt: pair.expiresAt });
|
|
170
196
|
const offerJSON = JSON.stringify(offer);
|
|
171
197
|
if (args.json)
|
package/dist/cloud-client.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare class CloudClient {
|
|
|
22
22
|
constructor(origin: string, pairId: string, token: string, allowLoopback?: boolean, fetcher?: typeof fetch, signal?: AbortSignal | undefined, retryState?: CloudRetryState, cycleFence?: CloudRetryState | undefined);
|
|
23
23
|
request(method: string, path: string, body?: unknown, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
24
24
|
private path;
|
|
25
|
-
create(body: unknown): Promise<Record<string, unknown>>;
|
|
25
|
+
create(body: unknown, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
26
26
|
pair(): Promise<Record<string, unknown>>;
|
|
27
27
|
activate(body: unknown): Promise<Record<string, unknown>>;
|
|
28
28
|
revoke(): Promise<Record<string, unknown>>;
|
package/dist/cloud-client.js
CHANGED
|
@@ -152,7 +152,7 @@ export class CloudClient {
|
|
|
152
152
|
return result;
|
|
153
153
|
}
|
|
154
154
|
path(suffix = '') { return '/pairs/' + this.pairId + suffix; }
|
|
155
|
-
create(body) { return this.request('POST', '/pairs', body); }
|
|
155
|
+
create(body, signal) { return this.request('POST', '/pairs', body, signal); }
|
|
156
156
|
pair() { return this.request('GET', this.path()); }
|
|
157
157
|
activate(body) { return this.request('POST', this.path('/activate'), body); }
|
|
158
158
|
revoke() { return this.request('DELETE', this.path()); }
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OperationJournal } from './journal.js';
|
|
2
|
+
import { type EnrollmentRecord } from './enrollment-protocol.js';
|
|
2
3
|
export interface Pair {
|
|
3
4
|
pairId: string;
|
|
4
5
|
rootKey: string;
|
|
@@ -13,6 +14,8 @@ export interface Pair {
|
|
|
13
14
|
daemonServerId?: string;
|
|
14
15
|
revokedAt?: number;
|
|
15
16
|
relayRetiredAt?: number;
|
|
17
|
+
automaticClientId?: string;
|
|
18
|
+
automaticRequestId?: string;
|
|
16
19
|
}
|
|
17
20
|
export interface Config {
|
|
18
21
|
version: 1;
|
|
@@ -24,6 +27,10 @@ export interface Config {
|
|
|
24
27
|
cloudEnabled: boolean;
|
|
25
28
|
daemonServerId?: string;
|
|
26
29
|
pairs: Pair[];
|
|
30
|
+
localEnrollment?: {
|
|
31
|
+
home: string;
|
|
32
|
+
};
|
|
33
|
+
enrollmentRequests?: EnrollmentRecord[];
|
|
27
34
|
}
|
|
28
35
|
export declare function dataDirectory(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, home?: string): string;
|
|
29
36
|
export declare function validateOrigin(value: string, allowLoopback: boolean): string;
|
package/dist/config.js
CHANGED
|
@@ -4,7 +4,8 @@ import { mkdir, readdir } from 'node:fs/promises';
|
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
5
5
|
import { decode } from './crypto.js';
|
|
6
6
|
import { UUID, LIMITS } from './limits.js';
|
|
7
|
-
import { assertStateRoot, assertStateResource, inspectResource, readPrivateText, createPrivateFile, writePrivateAtomic } from './resources.js';
|
|
7
|
+
import { CONFIG_BYTES, assertStateRoot, assertStateResource, inspectResource, readPrivateText, createPrivateFile, writePrivateAtomic } from './resources.js';
|
|
8
|
+
import { validateEnrollmentRecords, requestFingerprint } from './enrollment-protocol.js';
|
|
8
9
|
export function dataDirectory(env = process.env, platform = process.platform, home = homedir()) { return resolve(env.MOREMOTE_CLI_HOME || (platform === 'win32' ? join(env.LOCALAPPDATA || join(home, 'AppData', 'Local'), 'MoRemoteCLI') : platform === 'darwin' ? join(home, 'Library', 'Application Support', 'MoRemoteCLI') : join(env.XDG_STATE_HOME || join(home, '.local', 'state'), 'moremote-cli'))); }
|
|
9
10
|
export function validateOrigin(value, allowLoopback) { const u = new URL(value); if (u.username || u.password || u.search || u.hash || u.pathname !== '/')
|
|
10
11
|
throw Error('INVALID_API_ORIGIN'); if (u.protocol !== 'https:' && !(allowLoopback && u.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(u.hostname)))
|
|
@@ -37,20 +38,37 @@ export async function loadConfig(dir) {
|
|
|
37
38
|
let raw;
|
|
38
39
|
try {
|
|
39
40
|
assertStateRoot(dir);
|
|
40
|
-
raw = readPrivateText(join(dir, 'config.json'),
|
|
41
|
+
raw = readPrivateText(join(dir, 'config.json'), CONFIG_BYTES).text;
|
|
41
42
|
}
|
|
42
43
|
catch (e) {
|
|
43
44
|
if (e.code !== 'ENOENT')
|
|
44
45
|
throw e;
|
|
45
46
|
return { version: 1, clientId: 'moremote-cli-' + randomUUID(), paseoHome: process.env.PASEO_HOME || join(homedir(), '.paseo'), allowLoopbackHttp: false, cloudEnabled: false, pairs: [] };
|
|
46
47
|
}
|
|
47
|
-
if (Buffer.byteLength(raw) >
|
|
48
|
+
if (Buffer.byteLength(raw) > CONFIG_BYTES)
|
|
48
49
|
throw Error('CONFIG_LIMIT');
|
|
49
50
|
const c = JSON.parse(raw);
|
|
50
51
|
if (c.version !== 1 || typeof c.clientId !== 'string' || !c.clientId.startsWith('moremote-cli-') || c.clientId.length > 256 || typeof c.paseoHome !== 'string' || !c.paseoHome || c.paseoHome.length > 4096 || c.target !== undefined && (typeof c.target !== 'string' || !c.target || c.target.length > 16384) || !Array.isArray(c.pairs) || c.pairs.length > 16 || typeof c.cloudEnabled !== 'boolean' || typeof c.allowLoopbackHttp !== 'boolean')
|
|
51
52
|
throw Error('INVALID_CONFIG');
|
|
52
53
|
if (c.apiOrigin)
|
|
53
54
|
c.apiOrigin = validateOrigin(c.apiOrigin, c.allowLoopbackHttp);
|
|
55
|
+
if (c.localEnrollment && (typeof c.localEnrollment.home !== 'string' || !c.localEnrollment.home || c.localEnrollment.home.length > 4096 || resolve(c.localEnrollment.home) !== c.localEnrollment.home))
|
|
56
|
+
throw Error('INVALID_ENROLLMENT_HOME');
|
|
57
|
+
if (c.enrollmentRequests !== undefined) {
|
|
58
|
+
validateEnrollmentRecords(c.enrollmentRequests);
|
|
59
|
+
for (const record of c.enrollmentRequests) {
|
|
60
|
+
validateOrigin(record.offer.apiOrigin, false);
|
|
61
|
+
const pair = c.pairs.find(pair => pair.pairId === record.pairId);
|
|
62
|
+
if (!pair || pair.automaticClientId !== record.request.clientId || pair.automaticRequestId !== record.request.id || pair.daemonServerId !== record.request.daemonServerId || pair.rootKey !== record.offer.rootKey || pair.apiOrigin !== record.offer.apiOrigin || pair.expiresAt !== record.offer.expiresAt || JSON.parse(record.createBytes).hostTokenHash !== requestFingerprint(pair.hostToken) || pair.enrollmentToken !== undefined && pair.enrollmentToken !== record.offer.enrollmentToken)
|
|
63
|
+
throw Error('INVALID_ENROLLMENT_RECORD');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const pair of c.pairs)
|
|
67
|
+
if (pair.automaticClientId !== undefined && !UUID.test(pair.automaticClientId))
|
|
68
|
+
throw Error('INVALID_AUTOMATIC_CLIENT');
|
|
69
|
+
for (const pair of c.pairs)
|
|
70
|
+
if (pair.automaticRequestId !== undefined && !UUID.test(pair.automaticRequestId))
|
|
71
|
+
throw Error('INVALID_AUTOMATIC_REQUEST');
|
|
54
72
|
const identities = new Set();
|
|
55
73
|
for (const p of c.pairs) {
|
|
56
74
|
if (!UUID.test(p.pairId) || identities.has(p.pairId) || typeof p.active !== 'boolean' || p.expiresAt !== undefined && (!Number.isSafeInteger(p.expiresAt) || p.expiresAt < 0) || p.revokedAt !== undefined && (!Number.isSafeInteger(p.revokedAt) || p.revokedAt < 0) || p.relayRetiredAt !== undefined && (!Number.isSafeInteger(p.relayRetiredAt) || p.relayRetiredAt < 0))
|
|
@@ -65,4 +83,5 @@ export async function loadConfig(dir) {
|
|
|
65
83
|
}
|
|
66
84
|
export async function saveConfig(dir, config) { const a = resolve(dir), b = resolve(config.paseoHome); const left = process.platform === 'win32' ? a.toLowerCase() : a, right = process.platform === 'win32' ? b.toLowerCase() : b; if (left === right || left.startsWith(right + sep) || right.startsWith(left + sep))
|
|
67
85
|
throw Error('OFFICIAL_DATA_OVERLAP'); await privateDirectory(dir); await atomicJson(join(dir, 'config.json'), config); }
|
|
68
|
-
export function pruneRetiredPairs(config, now = Date.now(), journal) { const before = config.pairs.length; config.pairs = config.pairs.filter(p => {
|
|
86
|
+
export function pruneRetiredPairs(config, now = Date.now(), journal) { const before = config.pairs.length; config.pairs = config.pairs.filter(p => { if (config.enrollmentRequests?.some(record => record.pairId === p.pairId))
|
|
87
|
+
return true; const retiredAt = p.revokedAt === undefined ? p.relayRetiredAt : Math.max(p.revokedAt, p.relayRetiredAt ?? 0); return retiredAt === undefined ? !(p.active === false && p.expiresAt !== undefined && now >= p.expiresAt + LIMITS.retentionMs) : !journal || now < journal.retirementDeadline(p.pairId, retiredAt); }); return before !== config.pairs.length; }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ResourceIdentity } from './resources.js';
|
|
2
|
+
import { type EnrollmentRecord, type EnrollmentResponse } from './enrollment-protocol.js';
|
|
3
|
+
export declare function discoveryDirectory(home: string, daemonServerId: string): string;
|
|
4
|
+
export interface DiscoveryOptions {
|
|
5
|
+
home: string;
|
|
6
|
+
stateDirectory: string;
|
|
7
|
+
daemonServerId: string;
|
|
8
|
+
instanceId?: string;
|
|
9
|
+
isAlive?: (pid: number) => boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class EnrollmentFiles {
|
|
12
|
+
private options;
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly instanceId: string;
|
|
15
|
+
private lock;
|
|
16
|
+
private measuredAt;
|
|
17
|
+
private enabled;
|
|
18
|
+
private readonly hostMarker;
|
|
19
|
+
constructor(options: DiscoveryOptions);
|
|
20
|
+
open(records?: EnrollmentRecord[]): void;
|
|
21
|
+
private assertOwner;
|
|
22
|
+
publish(enabled: boolean, apiOrigin: string, now: number): void;
|
|
23
|
+
requestNames(): string[];
|
|
24
|
+
readRequest(name: string): {
|
|
25
|
+
text: string;
|
|
26
|
+
identity: {
|
|
27
|
+
dev: number;
|
|
28
|
+
ino: number;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
private responseIdentity;
|
|
32
|
+
assertResponseAvailable(id: string, record?: EnrollmentRecord): void;
|
|
33
|
+
writeResponse(record: EnrollmentRecord, response: EnrollmentResponse): void;
|
|
34
|
+
removeResponse(record: EnrollmentRecord): void;
|
|
35
|
+
removeRequest(name: string, identity: ResourceIdentity): void;
|
|
36
|
+
close(records?: EnrollmentRecord[]): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { mkdirSync, readdirSync, renameSync, openSync, closeSync, fsyncSync, constants } from 'node:fs';
|
|
2
|
+
import { join, resolve, dirname } from 'node:path';
|
|
3
|
+
import { randomUUID, createHash } from 'node:crypto';
|
|
4
|
+
import { createPrivateFile, hasCode, inspectResource, readPrivateText, removeOwnedResource, sameResource } from './resources.js';
|
|
5
|
+
import { object, exact, UUID } from './limits.js';
|
|
6
|
+
import { DISCOVERY_NAME, descriptorLifetime, descriptorRenewal } from './enrollment-protocol.js';
|
|
7
|
+
import { validateOrigin } from './config.js';
|
|
8
|
+
const marker = '.moremote-cli-owner';
|
|
9
|
+
const rootMarker = 'MoRemote CLI discovery v1\n';
|
|
10
|
+
function alive(pid) { try {
|
|
11
|
+
process.kill(pid, 0);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (hasCode(error, 'ESRCH'))
|
|
16
|
+
return false;
|
|
17
|
+
throw error;
|
|
18
|
+
} }
|
|
19
|
+
function assertDirectory(path, text) {
|
|
20
|
+
inspectResource(path, 'directory');
|
|
21
|
+
if (readPrivateText(join(path, marker), 2048).text !== text)
|
|
22
|
+
throw Error('FOREIGN_DISCOVERY_DIRECTORY');
|
|
23
|
+
}
|
|
24
|
+
function directory(path, text) {
|
|
25
|
+
try {
|
|
26
|
+
mkdirSync(path, { mode: 0o700 });
|
|
27
|
+
createPrivateFile(join(path, marker), text);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (!hasCode(error, 'EEXIST'))
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
assertDirectory(path, text);
|
|
34
|
+
}
|
|
35
|
+
function atomic(path, value, limit) {
|
|
36
|
+
const bytes = JSON.stringify(value);
|
|
37
|
+
if (Buffer.byteLength(bytes) > limit)
|
|
38
|
+
throw Error('ENROLLMENT_RESPONSE_LIMIT');
|
|
39
|
+
const before = inspectResource(path, 'file', true), temporary = path + '.' + randomUUID() + '.tmp';
|
|
40
|
+
const identity = createPrivateFile(temporary, bytes);
|
|
41
|
+
try {
|
|
42
|
+
const current = inspectResource(path, 'file', true);
|
|
43
|
+
if (before ? (!current || !sameResource(before, current)) : current !== null)
|
|
44
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
45
|
+
renameSync(temporary, path);
|
|
46
|
+
if (process.platform !== 'win32') {
|
|
47
|
+
const fd = openSync(dirname(path), constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
48
|
+
try {
|
|
49
|
+
fsyncSync(fd);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
closeSync(fd);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
removeOwnedResource(temporary, identity);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function validateDescriptor(path, daemon) {
|
|
61
|
+
const old = object(JSON.parse(readPrivateText(path, 4096).text));
|
|
62
|
+
exact(old, ['version', 'daemonServerId', 'instanceId', 'apiOrigin', 'enabled', 'measuredAt', 'expiresAt']);
|
|
63
|
+
if (old.version !== 1 || old.daemonServerId !== daemon || typeof old.instanceId !== 'string' || !UUID.test(old.instanceId) || typeof old.apiOrigin !== 'string' || typeof old.enabled !== 'boolean' || !Number.isSafeInteger(old.measuredAt) || Number(old.measuredAt) < 0 || Number(old.expiresAt) !== Number(old.measuredAt) + descriptorLifetime)
|
|
64
|
+
throw Error('FOREIGN_DISCOVERY_DESCRIPTOR');
|
|
65
|
+
if (validateOrigin(old.apiOrigin, false) !== old.apiOrigin)
|
|
66
|
+
throw Error('FOREIGN_DISCOVERY_DESCRIPTOR');
|
|
67
|
+
}
|
|
68
|
+
export function discoveryDirectory(home, daemonServerId) { return join(resolve(home), DISCOVERY_NAME, createHash('sha256').update(daemonServerId, 'utf8').digest('hex')); }
|
|
69
|
+
export class EnrollmentFiles {
|
|
70
|
+
options;
|
|
71
|
+
path;
|
|
72
|
+
instanceId;
|
|
73
|
+
lock;
|
|
74
|
+
measuredAt = -Infinity;
|
|
75
|
+
enabled;
|
|
76
|
+
hostMarker;
|
|
77
|
+
constructor(options) {
|
|
78
|
+
this.options = options;
|
|
79
|
+
this.instanceId = options.instanceId ?? randomUUID();
|
|
80
|
+
this.path = discoveryDirectory(options.home, options.daemonServerId);
|
|
81
|
+
this.hostMarker = JSON.stringify({ owner: 'MoRemote CLI discovery host', version: 1, daemonServerId: options.daemonServerId, stateDirectory: resolve(options.stateDirectory) }) + '\n';
|
|
82
|
+
}
|
|
83
|
+
open(records = []) {
|
|
84
|
+
if (this.lock) {
|
|
85
|
+
this.assertOwner();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const home = resolve(this.options.home), root = join(home, DISCOVERY_NAME), daemon = this.options.daemonServerId;
|
|
89
|
+
inspectResource(home, 'directory', false, false);
|
|
90
|
+
directory(root, rootMarker);
|
|
91
|
+
for (const name of readdirSync(root)) {
|
|
92
|
+
if (name === marker)
|
|
93
|
+
continue;
|
|
94
|
+
if (!/^[0-9a-f]{64}$/.test(name))
|
|
95
|
+
throw Error('FOREIGN_DISCOVERY_DIRECTORY');
|
|
96
|
+
inspectResource(join(root, name), 'directory');
|
|
97
|
+
}
|
|
98
|
+
directory(this.path, this.hostMarker);
|
|
99
|
+
const stages = [];
|
|
100
|
+
for (const name of readdirSync(this.path)) {
|
|
101
|
+
if ([marker, 'runtime.lock', 'descriptor.json', 'requests', 'responses'].includes(name))
|
|
102
|
+
continue;
|
|
103
|
+
if (/^descriptor\.json\.[0-9a-f-]{36}\.tmp$/.test(name) && UUID.test(name.slice(16, -4))) {
|
|
104
|
+
stages.push({ path: join(this.path, name) });
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
throw Error('FOREIGN_DISCOVERY_RESOURCE');
|
|
108
|
+
}
|
|
109
|
+
for (const child of ['requests', 'responses']) {
|
|
110
|
+
directory(join(this.path, child), 'MoRemote CLI discovery ' + child + ' v1\n');
|
|
111
|
+
for (const name of readdirSync(join(this.path, child))) {
|
|
112
|
+
if (name === marker)
|
|
113
|
+
continue;
|
|
114
|
+
if (child === 'responses' && /^[0-9a-f-]{36}\.json\.[0-9a-f-]{36}\.tmp$/.test(name) && UUID.test(name.slice(0, 36)) && UUID.test(name.slice(42, -4))) {
|
|
115
|
+
stages.push({ path: join(this.path, child, name), id: name.slice(0, 36) });
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (!/^[0-9a-f-]{36}\.json$/.test(name) || !UUID.test(name.slice(0, -5)))
|
|
119
|
+
throw Error('FOREIGN_DISCOVERY_RESOURCE');
|
|
120
|
+
inspectResource(join(this.path, child, name), 'file', false, child !== 'requests');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const lockPath = join(this.path, 'runtime.lock');
|
|
124
|
+
if (inspectResource(lockPath, 'file', true)) {
|
|
125
|
+
const previous = readPrivateText(lockPath, 2048), owner = object(JSON.parse(previous.text));
|
|
126
|
+
exact(owner, ['owner', 'version', 'instanceId', 'pid', 'stateDirectory']);
|
|
127
|
+
if (owner.owner !== 'MoRemote CLI discovery runtime' || owner.version !== 1 || typeof owner.instanceId !== 'string' || !UUID.test(owner.instanceId) || !Number.isSafeInteger(owner.pid) || Number(owner.pid) < 1 || Number(owner.pid) > 2147483647 || owner.stateDirectory !== resolve(this.options.stateDirectory))
|
|
128
|
+
throw Error('FOREIGN_DISCOVERY_LOCK');
|
|
129
|
+
if ((this.options.isAlive ?? alive)(Number(owner.pid)))
|
|
130
|
+
throw Error('DISCOVERY_ALREADY_RUNNING');
|
|
131
|
+
if (!removeOwnedResource(lockPath, previous.identity))
|
|
132
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
133
|
+
}
|
|
134
|
+
this.lock = createPrivateFile(lockPath, JSON.stringify({ owner: 'MoRemote CLI discovery runtime', version: 1, instanceId: this.instanceId, pid: process.pid, stateDirectory: resolve(this.options.stateDirectory) }));
|
|
135
|
+
try {
|
|
136
|
+
for (const stage of stages) {
|
|
137
|
+
if (stage.id)
|
|
138
|
+
this.responseIdentity(stage.id, records.find(record => record.request.id === stage.id), stage.path);
|
|
139
|
+
else
|
|
140
|
+
validateDescriptor(stage.path, daemon);
|
|
141
|
+
const file = readPrivateText(stage.path, 8192);
|
|
142
|
+
if (!removeOwnedResource(stage.path, file.identity))
|
|
143
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
removeOwnedResource(lockPath, this.lock);
|
|
148
|
+
this.lock = undefined;
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
assertOwner() {
|
|
153
|
+
if (!this.lock)
|
|
154
|
+
throw Error('DISCOVERY_NOT_OWNED');
|
|
155
|
+
assertDirectory(join(resolve(this.options.home), DISCOVERY_NAME), rootMarker);
|
|
156
|
+
assertDirectory(this.path, this.hostMarker);
|
|
157
|
+
for (const child of ['requests', 'responses'])
|
|
158
|
+
assertDirectory(join(this.path, child), 'MoRemote CLI discovery ' + child + ' v1\n');
|
|
159
|
+
const lock = readPrivateText(join(this.path, 'runtime.lock'), 2048);
|
|
160
|
+
if (!sameResource(lock.identity, this.lock) || object(JSON.parse(lock.text)).instanceId !== this.instanceId)
|
|
161
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
162
|
+
}
|
|
163
|
+
publish(enabled, apiOrigin, now) {
|
|
164
|
+
this.assertOwner();
|
|
165
|
+
if (now - this.measuredAt < descriptorRenewal && this.enabled === enabled)
|
|
166
|
+
return;
|
|
167
|
+
const path = join(this.path, 'descriptor.json');
|
|
168
|
+
if (inspectResource(path, 'file', true))
|
|
169
|
+
validateDescriptor(path, this.options.daemonServerId);
|
|
170
|
+
const descriptor = { version: 1, daemonServerId: this.options.daemonServerId, instanceId: this.instanceId, apiOrigin, enabled, measuredAt: now, expiresAt: now + descriptorLifetime };
|
|
171
|
+
atomic(path, descriptor, 4096);
|
|
172
|
+
this.measuredAt = now;
|
|
173
|
+
this.enabled = enabled;
|
|
174
|
+
}
|
|
175
|
+
requestNames() { this.assertOwner(); return readdirSync(join(this.path, 'requests')).filter(name => name !== marker).sort(); }
|
|
176
|
+
readRequest(name) {
|
|
177
|
+
this.assertOwner();
|
|
178
|
+
if (!/^[0-9a-f-]{36}\.json$/.test(name) || !UUID.test(name.slice(0, -5)))
|
|
179
|
+
throw Error('FOREIGN_DISCOVERY_RESOURCE');
|
|
180
|
+
// Official fs.entry.create may use 0644; the enclosing owned directories are 0700.
|
|
181
|
+
const path = join(this.path, 'requests', name), before = inspectResource(path, 'file', false, false);
|
|
182
|
+
const result = readPrivateText(path, 4096, 'utf8', false);
|
|
183
|
+
if (!sameResource(before, result.identity))
|
|
184
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
responseIdentity(id, record, path = join(this.path, 'responses', id + '.json')) {
|
|
188
|
+
if (!inspectResource(path, 'file', true))
|
|
189
|
+
return;
|
|
190
|
+
const file = readPrivateText(path, 8192), response = object(JSON.parse(file.text));
|
|
191
|
+
exact(response, ['version', 'id', 'clientId', 'daemonServerId', 'expiresAt', 'status', 'offer', 'code']);
|
|
192
|
+
if (!record || response.version !== 1 || response.id !== id || response.clientId !== record.request.clientId || response.daemonServerId !== record.request.daemonServerId || response.expiresAt !== record.offer.expiresAt || !['pending', 'offer', 'active', 'disabled', 'error'].includes(String(response.status)) || response.code !== undefined && (typeof response.code !== 'string' || !/^[A-Z0-9_]{1,64}$/.test(response.code)))
|
|
193
|
+
throw Error('FOREIGN_DISCOVERY_RESPONSE');
|
|
194
|
+
if (response.status === 'offer' ? JSON.stringify(response.offer) !== JSON.stringify(record.offer) : response.offer !== undefined)
|
|
195
|
+
throw Error('FOREIGN_DISCOVERY_RESPONSE');
|
|
196
|
+
return file.identity;
|
|
197
|
+
}
|
|
198
|
+
assertResponseAvailable(id, record) { this.assertOwner(); this.responseIdentity(id, record); }
|
|
199
|
+
writeResponse(record, response) { this.assertOwner(); this.responseIdentity(record.request.id, record); atomic(join(this.path, 'responses', record.request.id + '.json'), response, 8192); }
|
|
200
|
+
removeResponse(record) { this.assertOwner(); const identity = this.responseIdentity(record.request.id, record); if (identity && !removeOwnedResource(join(this.path, 'responses', record.request.id + '.json'), identity))
|
|
201
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED'); }
|
|
202
|
+
removeRequest(name, identity) { this.assertOwner(); if (!removeOwnedResource(join(this.path, 'requests', name), identity, 'file', false))
|
|
203
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED'); }
|
|
204
|
+
close(records = []) {
|
|
205
|
+
if (!this.lock)
|
|
206
|
+
return;
|
|
207
|
+
this.assertOwner();
|
|
208
|
+
try {
|
|
209
|
+
for (const record of records)
|
|
210
|
+
this.removeResponse(record);
|
|
211
|
+
const descriptor = join(this.path, 'descriptor.json');
|
|
212
|
+
if (inspectResource(descriptor, 'file', true)) {
|
|
213
|
+
validateDescriptor(descriptor, this.options.daemonServerId);
|
|
214
|
+
const file = readPrivateText(descriptor, 4096);
|
|
215
|
+
if (object(JSON.parse(file.text)).instanceId === this.instanceId)
|
|
216
|
+
removeOwnedResource(descriptor, file.identity);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
if (!removeOwnedResource(join(this.path, 'runtime.lock'), this.lock))
|
|
221
|
+
throw Error('DISCOVERY_RESOURCE_CHANGED');
|
|
222
|
+
this.lock = undefined;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|