@amalgm/shell 0.1.164-preview.37557324064 → 0.1.164-preview.41762776698
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/PURPOSE.md +16 -19
- package/README.md +24 -5
- package/dist/agent-execution.d.ts +1 -3
- package/dist/agent-execution.js +2 -2
- package/dist/agent-execution.js.map +1 -1
- package/dist/apply-recovery.js +2 -1
- package/dist/apply-recovery.js.map +1 -1
- package/dist/authorization/index.d.ts +7 -7
- package/dist/authorization/index.js +3 -3
- package/dist/authorization/index.js.map +1 -1
- package/dist/authorization/recovery-host.d.ts +2 -1
- package/dist/authorization/recovery-host.js +1 -1
- package/dist/authorization/recovery-host.js.map +1 -1
- package/dist/browser-host.d.ts +1 -1
- package/dist/chat-composition.d.ts +8 -3
- package/dist/chat-composition.js +8 -5
- package/dist/chat-composition.js.map +1 -1
- package/dist/chat-host.d.ts +3 -0
- package/dist/chat-host.js +3 -0
- package/dist/chat-host.js.map +1 -1
- package/dist/cli.js +26 -14
- package/dist/cli.js.map +1 -1
- package/dist/content-clock.js +2 -1
- package/dist/content-clock.js.map +1 -1
- package/dist/credentials-host.d.ts +0 -1
- package/dist/credentials-host.js +0 -3
- package/dist/credentials-host.js.map +1 -1
- package/dist/detection/identity-discovery.js +3 -3
- package/dist/detection/identity-discovery.js.map +1 -1
- package/dist/detection/repository-routes.js +2 -1
- package/dist/detection/repository-routes.js.map +1 -1
- package/dist/detection/runtime.js +4 -3
- package/dist/detection/runtime.js.map +1 -1
- package/dist/detection/sharing-policy.js +3 -2
- package/dist/detection/sharing-policy.js.map +1 -1
- package/dist/detection/walk-law.d.ts +5 -4
- package/dist/detection/walk-law.js +8 -6
- package/dist/detection/walk-law.js.map +1 -1
- package/dist/entity-apply-host.js +3 -2
- package/dist/entity-apply-host.js.map +1 -1
- package/dist/files-browser-host.js +5 -0
- package/dist/files-browser-host.js.map +1 -1
- package/dist/files-register-host.d.ts +2 -2
- package/dist/files-register-host.js +3 -6
- package/dist/files-register-host.js.map +1 -1
- package/dist/git-capture.d.ts +0 -4
- package/dist/git-capture.js +7 -2
- package/dist/git-capture.js.map +1 -1
- package/dist/git-checkpoint-construction.d.ts +0 -3
- package/dist/git-checkpoint-construction.js +3 -2
- package/dist/git-checkpoint-construction.js.map +1 -1
- package/dist/git-checkpoint-preparation.js +5 -4
- package/dist/git-checkpoint-preparation.js.map +1 -1
- package/dist/git-index-entries.d.ts +0 -1
- package/dist/git-index-entries.js +0 -1
- package/dist/git-index-entries.js.map +1 -1
- package/dist/git-literal-replay.js +5 -4
- package/dist/git-literal-replay.js.map +1 -1
- package/dist/git-registration-host.js +3 -3
- package/dist/git-registration-host.js.map +1 -1
- package/dist/git-repository-host.js +2 -1
- package/dist/git-repository-host.js.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/installation/ownership.d.ts +8 -6
- package/dist/installation/ownership.js +23 -15
- package/dist/installation/ownership.js.map +1 -1
- package/dist/local-host.d.ts +7 -1
- package/dist/local-host.js +29 -30
- package/dist/local-host.js.map +1 -1
- package/dist/machine-host.d.ts +11 -18
- package/dist/machine-host.js +105 -142
- package/dist/machine-host.js.map +1 -1
- package/dist/product-cli.d.ts +26 -0
- package/dist/product-cli.js +233 -0
- package/dist/product-cli.js.map +1 -0
- package/dist/pty-host.js +1 -1
- package/dist/pty-host.js.map +1 -1
- package/dist/runtime-command-host.d.ts +0 -4
- package/dist/runtime-command-host.js +5 -23
- package/dist/runtime-command-host.js.map +1 -1
- package/dist/service/cli.js +5 -10
- package/dist/service/cli.js.map +1 -1
- package/dist/service/control.js +1 -1
- package/dist/service/control.js.map +1 -1
- package/dist/service/keepalive.js +0 -2
- package/dist/service/keepalive.js.map +1 -1
- package/dist/service/registration.d.ts +8 -6
- package/dist/service/registration.js +10 -5
- package/dist/service/registration.js.map +1 -1
- package/dist/toolbox-host.js +3 -2
- package/dist/toolbox-host.js.map +1 -1
- package/dist/updates/artifacts.d.ts +0 -3
- package/dist/updates/artifacts.js +7 -15
- package/dist/updates/artifacts.js.map +1 -1
- package/dist/updates/controller.d.ts +2 -2
- package/dist/updates/controller.js +6 -9
- package/dist/updates/controller.js.map +1 -1
- package/dist/user-ground-host.d.ts +10 -6
- package/dist/user-ground-host.js +123 -142
- package/dist/user-ground-host.js.map +1 -1
- package/dist/watching/host.js +7 -1
- package/dist/watching/host.js.map +1 -1
- package/dist/wire-client.d.ts +3 -0
- package/dist/wire-client.js +3 -2
- package/dist/wire-client.js.map +1 -1
- package/dist/workspace-host.d.ts +0 -5
- package/dist/workspace-host.js +3 -3
- package/dist/workspace-host.js.map +1 -1
- package/examinations/native-service.mjs +4 -5
- package/examinations/runtime-upgrade.native-test.mjs +70 -38
- package/npm-shrinkwrap.json +97 -96
- package/package.json +13 -14
- package/skills/shell/SKILL.md +38 -12
- package/dist/automations-host.d.ts +0 -19
- package/dist/automations-host.js +0 -41
- package/dist/automations-host.js.map +0 -1
- package/dist/boot.d.ts +0 -49
- package/dist/boot.js +0 -292
- package/dist/boot.js.map +0 -1
- package/dist/bundle-apps.d.ts +0 -12
- package/dist/bundle-apps.js +0 -71
- package/dist/bundle-apps.js.map +0 -1
- package/dist/bundle-automations.d.ts +0 -8
- package/dist/bundle-automations.js +0 -115
- package/dist/bundle-automations.js.map +0 -1
- package/dist/bundle-bindings.d.ts +0 -8
- package/dist/bundle-bindings.js +0 -101
- package/dist/bundle-bindings.js.map +0 -1
- package/dist/bundle-port.d.ts +0 -14
- package/dist/bundle-port.js +0 -166
- package/dist/bundle-port.js.map +0 -1
- package/dist/compose.d.ts +0 -32
- package/dist/compose.js +0 -41
- package/dist/compose.js.map +0 -1
- package/dist/diagnostics-host.d.ts +0 -3
- package/dist/diagnostics-host.js +0 -92
- package/dist/diagnostics-host.js.map +0 -1
- package/dist/event-triggers-host.d.ts +0 -4
- package/dist/event-triggers-host.js +0 -48
- package/dist/event-triggers-host.js.map +0 -1
- package/dist/external-proxy-host.d.ts +0 -15
- package/dist/external-proxy-host.js +0 -167
- package/dist/external-proxy-host.js.map +0 -1
- package/dist/installation/layout.d.ts +0 -5
- package/dist/installation/layout.js +0 -18
- package/dist/installation/layout.js.map +0 -1
- package/dist/parity.d.ts +0 -36
- package/dist/parity.js +0 -71
- package/dist/parity.js.map +0 -1
- package/dist/ports-host.d.ts +0 -8
- package/dist/ports-host.js +0 -26
- package/dist/ports-host.js.map +0 -1
package/dist/machine-host.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createCredentialVault, credentialVaultMounts } from "./credentials-host.js";
|
|
2
2
|
import { createShellToolsMcp } from "./toolbox-host.js";
|
|
3
3
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
4
|
-
import { existsSync, readdirSync
|
|
4
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
5
5
|
import { homedir as osHomedir, hostname, platform, release } from "node:os";
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
7
|
import { admitRuntimeFormat } from './updates/store.js';
|
|
8
8
|
import { serviceIdentity } from './service/registration.js';
|
|
9
9
|
import { RuntimeWireHost } from './runtime-wire-host.js';
|
|
10
10
|
import { readSyncMode, writeSyncMode, syncPausedError, syncBlocked } from './sync-setting.js';
|
|
11
|
-
import { buildRootManifest, approveMachineSetup, adoptMachineSetup, joinApprovedMachine, mergeRecordAuth, resumeMachine, resolveRuntimeBinding, runtimeBindingsMatch, runtimeBindingFromRecord, RUNTIME_IDENTITY_PATH, createRuntimeIdentity,
|
|
11
|
+
import { buildRootManifest, requireCurrentLayout, approveMachineSetup, adoptMachineSetup, joinApprovedMachine, mergeRecordAuth, resumeMachine, resolveRuntimeBinding, runtimeBindingsMatch, runtimeBindingFromRecord, RUNTIME_IDENTITY_PATH, createRuntimeIdentity, laneLayout, laneRoot, resolveRuntimeEndpoint, userLayout, } from "@amalgm/core/identity";
|
|
12
12
|
import { StateRail } from "@amalgm/core/state";
|
|
13
13
|
import { atomicJson, atomicJsonSet, ensurePrivateDir, readJson, } from "./filesystem.js";
|
|
14
14
|
import { emitFilesStage, } from "./files-observability.js";
|
|
@@ -19,7 +19,6 @@ import { postRegistration } from "./authorization/registration-http.js";
|
|
|
19
19
|
import { postSetupJson, setupOrigin } from "./authorization/setup-http.js";
|
|
20
20
|
import { installBuiltinAgents } from "./builtin-agents.js";
|
|
21
21
|
import { InstallationOwnership } from "./installation/ownership.js";
|
|
22
|
-
import { assertSupportedInstallationLayout } from "./installation/layout.js";
|
|
23
22
|
import { runtimeAppOrigin, runtimeProxyOrigin, runtimeWireUrl } from "./installation/environment.js";
|
|
24
23
|
import { forwardMount } from "./forward.js";
|
|
25
24
|
import { filesBrowserMount } from "./files-browser-host.js";
|
|
@@ -30,15 +29,15 @@ import { stateMount } from "./state-host.js";
|
|
|
30
29
|
import { FileStateEventStore } from "./state-store.js";
|
|
31
30
|
import { createWorkspaceHost } from "./workspace-host.js";
|
|
32
31
|
import { createPtyHost } from "./pty-host.js";
|
|
33
|
-
import { callRuntimeCommand,
|
|
32
|
+
import { callRuntimeCommand, inspectRuntimeCommands, publishRuntimeCommands, runtimeCommandConnection, unpublishRuntimeCommands, } from "./runtime-command-host.js";
|
|
34
33
|
import { shellReleaseCatalog, shellReleaseVerifier } from "./release-catalog.js";
|
|
35
34
|
/** The production effects around Core's machine-setup operation. It does not
|
|
36
35
|
* decide ordering, readiness, or installation selection; those remain Core. */
|
|
37
36
|
export class MachineHost {
|
|
38
37
|
options;
|
|
39
38
|
homedir;
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
/** This binding's lane: `~/amalgm`, `~/amalgm-preview` or `~/amalgm-dev/<session>`. */
|
|
40
|
+
lane;
|
|
42
41
|
ports;
|
|
43
42
|
binding;
|
|
44
43
|
/** A local runtime with no declared Wire composes no Files cloud rail:
|
|
@@ -75,15 +74,9 @@ export class MachineHost {
|
|
|
75
74
|
this.options = { ...options, ...this.binding };
|
|
76
75
|
this.wireComposed = this.binding.runtimeLabel !== 'local' || Boolean(options.wireUrl);
|
|
77
76
|
this.stages = new FilesStageRecorder(options.onFilesStage);
|
|
78
|
-
this.homedir = options.homedir ?? osHomedir();
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
this.ownership = new InstallationOwnership({
|
|
82
|
-
home: this.homedir,
|
|
83
|
-
installationRoot: this.amalgmRoot,
|
|
84
|
-
binding: this.binding,
|
|
85
|
-
});
|
|
86
|
-
this.deviceFile = join(this.amalgmRoot, ".amalgm", "device.json");
|
|
77
|
+
this.homedir = resolve(options.homedir ?? osHomedir());
|
|
78
|
+
this.lane = laneLayout(laneRoot(this.homedir, this.binding));
|
|
79
|
+
this.ownership = new InstallationOwnership({ home: this.homedir, binding: this.binding });
|
|
87
80
|
this.selectedUserEmail = normalizeEmail(options.userEmail);
|
|
88
81
|
try {
|
|
89
82
|
this.ownership.initialize(() => this.ensureInstallationRoot());
|
|
@@ -93,15 +86,14 @@ export class MachineHost {
|
|
|
93
86
|
throw error;
|
|
94
87
|
}
|
|
95
88
|
const deviceStore = {
|
|
96
|
-
load: async () => readJson(this.
|
|
97
|
-
save: async (device) => atomicJson(this.
|
|
89
|
+
load: async () => readJson(this.lane.device),
|
|
90
|
+
save: async (device) => atomicJson(this.lane.device, device),
|
|
98
91
|
};
|
|
99
92
|
const machineStore = {
|
|
100
93
|
load: async () => this.loadMachine(),
|
|
101
94
|
save: async (machine) => this.saveMachine(machine),
|
|
102
95
|
markReady: async () => {
|
|
103
|
-
|
|
104
|
-
atomicJson(paths.status, { ready: true, updatedAt: new Date().toISOString() });
|
|
96
|
+
atomicJson(this.user().computer.status, { ready: true, updatedAt: new Date().toISOString() });
|
|
105
97
|
},
|
|
106
98
|
};
|
|
107
99
|
const withRegistrationKey = async (body) => {
|
|
@@ -124,7 +116,7 @@ export class MachineHost {
|
|
|
124
116
|
code: "device_missing",
|
|
125
117
|
});
|
|
126
118
|
const signer = await loadInstallationDeviceKey({
|
|
127
|
-
|
|
119
|
+
dir: this.lane.authorization,
|
|
128
120
|
deviceId,
|
|
129
121
|
...(this.options.authorizationKeyStore
|
|
130
122
|
? { keyStore: this.options.authorizationKeyStore }
|
|
@@ -146,21 +138,11 @@ export class MachineHost {
|
|
|
146
138
|
return response;
|
|
147
139
|
},
|
|
148
140
|
};
|
|
141
|
+
// The release is already unpacked in the lane's `rt/`, and the plan is
|
|
142
|
+
// saved with the machine (installation.json), so installing writes nothing.
|
|
149
143
|
const installer = {
|
|
150
|
-
install: async (plan) => {
|
|
151
|
-
|
|
152
|
-
ensurePrivateDir(releaseDir);
|
|
153
|
-
atomicJson(join(releaseDir, "services.json"), {
|
|
154
|
-
releaseId: plan.releaseId,
|
|
155
|
-
services: plan.services,
|
|
156
|
-
runtimeVersion: this.options.runtimeVersion,
|
|
157
|
-
});
|
|
158
|
-
return { id: plan.releaseId };
|
|
159
|
-
},
|
|
160
|
-
rollback: async (installed) => {
|
|
161
|
-
const target = join(this.amalgmRoot, ".amalgm", "managed", "releases", installed.id);
|
|
162
|
-
rmSync(target, { recursive: true, force: true });
|
|
163
|
-
},
|
|
144
|
+
install: async (plan) => ({ id: plan.releaseId }),
|
|
145
|
+
rollback: async () => undefined,
|
|
164
146
|
};
|
|
165
147
|
const userGround = !this.wireComposed ? null : {
|
|
166
148
|
converge: async (identity) => {
|
|
@@ -187,10 +169,11 @@ export class MachineHost {
|
|
|
187
169
|
this.syncIdentity = identity;
|
|
188
170
|
this.createGround = async () => {
|
|
189
171
|
const { UserGroundHost } = await import("./user-ground-host.js");
|
|
172
|
+
const user = this.user(identity.userEmail);
|
|
190
173
|
return new UserGroundHost({
|
|
191
174
|
wire: this.runtimeWire.client,
|
|
192
|
-
|
|
193
|
-
|
|
175
|
+
userRoot: user.root,
|
|
176
|
+
dir: user.computer.live,
|
|
194
177
|
tunnelUrl,
|
|
195
178
|
tunnelToken,
|
|
196
179
|
runtimeVersion: this.options.runtimeVersion,
|
|
@@ -211,7 +194,7 @@ export class MachineHost {
|
|
|
211
194
|
if (this.activeSyncMode === 'paused') {
|
|
212
195
|
this.syncPhase = 'paused';
|
|
213
196
|
return {
|
|
214
|
-
...identity, localRoot: this.
|
|
197
|
+
...identity, localRoot: this.user().root, mode: 'paused',
|
|
215
198
|
cloudHead: null, entityCount: null, watcherRoots: 0, watching: false,
|
|
216
199
|
};
|
|
217
200
|
}
|
|
@@ -267,7 +250,6 @@ export class MachineHost {
|
|
|
267
250
|
try {
|
|
268
251
|
const approved = await this.approveSetup(input);
|
|
269
252
|
this.acquireRuntimeOwnership();
|
|
270
|
-
this.assertRuntimeCanStart();
|
|
271
253
|
return await joinApprovedMachine(approved, this.ports);
|
|
272
254
|
}
|
|
273
255
|
finally {
|
|
@@ -288,7 +270,6 @@ export class MachineHost {
|
|
|
288
270
|
deviceId: approved.device.device_id };
|
|
289
271
|
}
|
|
290
272
|
this.acquireRuntimeOwnership();
|
|
291
|
-
this.assertRuntimeCanStart();
|
|
292
273
|
enrolling = true;
|
|
293
274
|
const ready = await joinApprovedMachine(approved, this.ports);
|
|
294
275
|
return { disposition: 'enrolled', userEmail: this.requireSelectedUser(),
|
|
@@ -309,16 +290,8 @@ export class MachineHost {
|
|
|
309
290
|
resume() {
|
|
310
291
|
this.resolveUserForResume();
|
|
311
292
|
this.acquireRuntimeOwnership();
|
|
312
|
-
this.assertRuntimeCanStart();
|
|
313
293
|
return resumeMachine(this.ports, { services: this.options.services });
|
|
314
294
|
}
|
|
315
|
-
assertRuntimeCanStart() {
|
|
316
|
-
const deviceId = text(readJson(this.deviceFile)?.device_id);
|
|
317
|
-
if (!deviceId)
|
|
318
|
-
return;
|
|
319
|
-
assertRuntimeCanStart({ userRoot: this.paths().userRoot, deviceId,
|
|
320
|
-
...this.binding, userScope: this.requireSelectedUser() });
|
|
321
|
-
}
|
|
322
295
|
async recoverAuthorizationKey(input = {}) {
|
|
323
296
|
this.resolveUserForResume();
|
|
324
297
|
const machine = await this.loadMachine();
|
|
@@ -340,15 +313,16 @@ export class MachineHost {
|
|
|
340
313
|
save: (next) => this.saveMachine(next),
|
|
341
314
|
});
|
|
342
315
|
}
|
|
316
|
+
/** The selected user's home and computer-only files. */
|
|
343
317
|
selectedPaths() {
|
|
344
|
-
return this.
|
|
318
|
+
return this.user();
|
|
345
319
|
}
|
|
346
320
|
/** One read-only answer for platform adapters deciding whether to adopt a
|
|
347
321
|
* running Shell, resume a durable registration, or begin installation. */
|
|
348
322
|
async status() {
|
|
349
323
|
const user = this.requireSelectedUser();
|
|
350
|
-
const
|
|
351
|
-
const device = readJson(this.
|
|
324
|
+
const paths = this.user(user);
|
|
325
|
+
const device = readJson(this.lane.device);
|
|
352
326
|
const deviceId = text(device?.device_id) || null;
|
|
353
327
|
if (!deviceId) {
|
|
354
328
|
return {
|
|
@@ -361,14 +335,11 @@ export class MachineHost {
|
|
|
361
335
|
running: false,
|
|
362
336
|
runtimePid: null,
|
|
363
337
|
runtimePort: null,
|
|
364
|
-
deviceFile: this.
|
|
365
|
-
userRoot,
|
|
366
|
-
machineDir: null,
|
|
367
|
-
database: null,
|
|
338
|
+
deviceFile: this.lane.device,
|
|
339
|
+
userRoot: paths.root,
|
|
368
340
|
};
|
|
369
341
|
}
|
|
370
|
-
const
|
|
371
|
-
const publicRecord = readJson(paths.publicRecord);
|
|
342
|
+
const publicRecord = readJson(paths.computer.record);
|
|
372
343
|
let recordMatches = true;
|
|
373
344
|
if (publicRecord) {
|
|
374
345
|
try {
|
|
@@ -380,16 +351,16 @@ export class MachineHost {
|
|
|
380
351
|
recordMatches = false;
|
|
381
352
|
}
|
|
382
353
|
}
|
|
383
|
-
const secretAuth = readJson(paths.
|
|
384
|
-
const installation = readJson(paths.installation);
|
|
385
|
-
const storedStatus = readJson(paths.status);
|
|
354
|
+
const secretAuth = readJson(paths.computer.auth);
|
|
355
|
+
const installation = readJson(paths.computer.installation);
|
|
356
|
+
const storedStatus = readJson(paths.computer.status);
|
|
386
357
|
const complete = Boolean(publicRecord && secretAuth && installation && storedStatus);
|
|
387
358
|
const registration = !recordMatches ? "incomplete" : !complete
|
|
388
359
|
? (publicRecord || secretAuth || installation || storedStatus ? "incomplete" : "absent")
|
|
389
360
|
: storedStatus?.ready === true ? "ready" : "incomplete";
|
|
390
361
|
const runtime = registration === "ready" && deviceId
|
|
391
362
|
? await inspectRuntimeCommands({
|
|
392
|
-
userRoot: paths.
|
|
363
|
+
userRoot: paths.root,
|
|
393
364
|
deviceId,
|
|
394
365
|
...this.binding,
|
|
395
366
|
userScope: user,
|
|
@@ -405,10 +376,8 @@ export class MachineHost {
|
|
|
405
376
|
running: runtime.running,
|
|
406
377
|
runtimePid: runtime.pid,
|
|
407
378
|
runtimePort: runtime.port,
|
|
408
|
-
deviceFile: this.
|
|
409
|
-
userRoot: paths.
|
|
410
|
-
machineDir: paths.machineDir,
|
|
411
|
-
database: join(paths.machineDir, "live", "identity.db"),
|
|
379
|
+
deviceFile: this.lane.device,
|
|
380
|
+
userRoot: paths.root,
|
|
412
381
|
};
|
|
413
382
|
}
|
|
414
383
|
filesCommandPorts() {
|
|
@@ -521,7 +490,8 @@ export class MachineHost {
|
|
|
521
490
|
async callFilesRuntime(path, body) {
|
|
522
491
|
return callRuntimeCommand(await this.runtimeCommandAddress(), path, body);
|
|
523
492
|
}
|
|
524
|
-
|
|
493
|
+
/** The running runtime's loopback address and admission token, for product commands. */
|
|
494
|
+
async runtimeConnection() {
|
|
525
495
|
return runtimeCommandConnection(await this.runtimeCommandAddress());
|
|
526
496
|
}
|
|
527
497
|
/** The global Channels CLI enters through the running Shell's private
|
|
@@ -570,7 +540,7 @@ export class MachineHost {
|
|
|
570
540
|
this.syncPhase = 'stopped';
|
|
571
541
|
}
|
|
572
542
|
}
|
|
573
|
-
syncSettingFile() { return
|
|
543
|
+
syncSettingFile() { return this.user().computer.sync; }
|
|
574
544
|
syncMode() { return readSyncMode(this.syncSettingFile()); }
|
|
575
545
|
syncStatus() {
|
|
576
546
|
return { configured: this.syncMode(),
|
|
@@ -645,24 +615,24 @@ export class MachineHost {
|
|
|
645
615
|
if (this.syncPhase !== 'enabled')
|
|
646
616
|
throw new Error(`Sync is ${this.syncPhase}${this.syncError ? `: ${this.syncError}` : '.'}`);
|
|
647
617
|
}
|
|
618
|
+
/** Mints the lane manifest on first start (the installer may already have
|
|
619
|
+
* put a runtime in the lane), and refuses a manifest made by an older
|
|
620
|
+
* Amalgm or for another binding. There is no migration. */
|
|
648
621
|
ensureInstallationRoot() {
|
|
649
|
-
ensurePrivateDir(this.
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
622
|
+
ensurePrivateDir(this.lane.root);
|
|
623
|
+
if (existsSync(this.lane.manifest)) {
|
|
624
|
+
const existing = readJson(this.lane.manifest);
|
|
625
|
+
requireCurrentLayout(existing);
|
|
626
|
+
if (!existing?.runtimeBinding || !runtimeBindingsMatch(existing.runtimeBinding, this.binding)) {
|
|
627
|
+
throw new Error('This Amalgm folder belongs to another runtime binding.');
|
|
628
|
+
}
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const manifest = buildRootManifest(null, {
|
|
653
632
|
nowIso: () => new Date().toISOString(),
|
|
654
633
|
randomHex: (bytes) => randomBytes(bytes).toString("hex"),
|
|
655
634
|
});
|
|
656
|
-
|
|
657
|
-
if (previousBinding && !runtimeBindingsMatch(previousBinding, this.binding)) {
|
|
658
|
-
throw new Error('This installation root belongs to another runtime binding.');
|
|
659
|
-
}
|
|
660
|
-
if (existing?.installationId && !previousBinding && this.binding.runtimeLabel !== 'main') {
|
|
661
|
-
throw new Error('An unbound existing installation must be adopted explicitly; use a fresh root for preview/local.');
|
|
662
|
-
}
|
|
663
|
-
if (!existing?.installationId || !previousBinding) {
|
|
664
|
-
atomicJson(manifestFile, { ...manifest, runtimeBinding: this.binding });
|
|
665
|
-
}
|
|
635
|
+
atomicJson(this.lane.manifest, { ...manifest, runtimeBinding: this.binding });
|
|
666
636
|
}
|
|
667
637
|
async openChannelsCommands() {
|
|
668
638
|
const access = runtimeCommandConnection(await this.runtimeCommandAddress());
|
|
@@ -681,7 +651,7 @@ export class MachineHost {
|
|
|
681
651
|
throw new Error("stored machine identity does not match this user and physical device");
|
|
682
652
|
}
|
|
683
653
|
return {
|
|
684
|
-
userRoot: this.
|
|
654
|
+
userRoot: this.user().root,
|
|
685
655
|
deviceId,
|
|
686
656
|
...this.binding,
|
|
687
657
|
userScope: userEmail,
|
|
@@ -695,7 +665,7 @@ export class MachineHost {
|
|
|
695
665
|
}
|
|
696
666
|
authorizationStorageOptions() {
|
|
697
667
|
return {
|
|
698
|
-
|
|
668
|
+
dir: this.lane.authorization,
|
|
699
669
|
...(this.options.authorizationKeyStore
|
|
700
670
|
? { keyStore: this.options.authorizationKeyStore }
|
|
701
671
|
: {}),
|
|
@@ -707,21 +677,8 @@ export class MachineHost {
|
|
|
707
677
|
: {}),
|
|
708
678
|
};
|
|
709
679
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
const device = readJson(this.deviceFile);
|
|
713
|
-
const deviceId = text(device?.device_id);
|
|
714
|
-
if (!deviceId)
|
|
715
|
-
throw Object.assign(new Error("physical device identity is missing"), { code: "device_missing" });
|
|
716
|
-
const machineDir = resolve(userMachineDir(userRoot, deviceId));
|
|
717
|
-
return {
|
|
718
|
-
userRoot,
|
|
719
|
-
machineDir,
|
|
720
|
-
publicRecord: join(machineDir, "computer.json"),
|
|
721
|
-
secretAuth: join(machineDir, "auth.json"),
|
|
722
|
-
installation: join(machineDir, "installation.json"),
|
|
723
|
-
status: join(machineDir, "status.json"),
|
|
724
|
-
};
|
|
680
|
+
user(email = this.requireSelectedUser()) {
|
|
681
|
+
return userLayout(this.lane.user(email));
|
|
725
682
|
}
|
|
726
683
|
requireSelectedUser() {
|
|
727
684
|
if (!this.selectedUserEmail) {
|
|
@@ -734,19 +691,16 @@ export class MachineHost {
|
|
|
734
691
|
resolveUserForResume() {
|
|
735
692
|
if (this.selectedUserEmail)
|
|
736
693
|
return;
|
|
737
|
-
|
|
738
|
-
const device = readJson(this.deviceFile);
|
|
739
|
-
const deviceId = text(device?.device_id);
|
|
740
|
-
if (!deviceId || !existsSync(usersRoot))
|
|
694
|
+
if (!existsSync(this.lane.users))
|
|
741
695
|
return;
|
|
742
696
|
const candidates = [];
|
|
743
|
-
for (const entry of readdirSync(
|
|
697
|
+
for (const entry of readdirSync(this.lane.users, { withFileTypes: true })) {
|
|
744
698
|
if (!entry.isDirectory())
|
|
745
699
|
continue;
|
|
746
|
-
const
|
|
747
|
-
const manifest = readJson(
|
|
700
|
+
const user = userLayout(join(this.lane.users, entry.name));
|
|
701
|
+
const manifest = readJson(user.manifest);
|
|
748
702
|
const email = normalizeEmail(manifest?.canonicalEmail || entry.name);
|
|
749
|
-
const status = readJson(
|
|
703
|
+
const status = readJson(user.computer.status);
|
|
750
704
|
if (email && status?.ready === true)
|
|
751
705
|
candidates.push(email);
|
|
752
706
|
}
|
|
@@ -780,11 +734,11 @@ export class MachineHost {
|
|
|
780
734
|
this.resolveUserForResume();
|
|
781
735
|
if (!this.selectedUserEmail)
|
|
782
736
|
return null;
|
|
783
|
-
const
|
|
784
|
-
const publicRecord = readJson(
|
|
785
|
-
const secretAuth = readJson(
|
|
786
|
-
const installation = readJson(
|
|
787
|
-
const status = readJson(
|
|
737
|
+
const { computer } = this.user();
|
|
738
|
+
const publicRecord = readJson(computer.record);
|
|
739
|
+
const secretAuth = readJson(computer.auth);
|
|
740
|
+
const installation = readJson(computer.installation);
|
|
741
|
+
const status = readJson(computer.status);
|
|
788
742
|
if (!publicRecord || !secretAuth || !installation || !status)
|
|
789
743
|
return null;
|
|
790
744
|
this.assertRecordBinding(publicRecord);
|
|
@@ -808,18 +762,18 @@ export class MachineHost {
|
|
|
808
762
|
if (recordEmail)
|
|
809
763
|
this.selectedUserEmail = recordEmail;
|
|
810
764
|
this.acquireRuntimeOwnership();
|
|
811
|
-
const
|
|
765
|
+
const { computer } = this.user();
|
|
812
766
|
atomicJsonSet([
|
|
813
|
-
[
|
|
814
|
-
[
|
|
815
|
-
[
|
|
816
|
-
[
|
|
767
|
+
[computer.record, machine.publicRecord],
|
|
768
|
+
[computer.auth, machine.secretAuth],
|
|
769
|
+
[computer.installation, machine.installation],
|
|
770
|
+
[computer.status, { ready: machine.ready, updatedAt: new Date().toISOString() }],
|
|
817
771
|
]);
|
|
818
772
|
}
|
|
819
773
|
acquireRuntimeOwnership() {
|
|
820
774
|
const user = this.requireSelectedUser();
|
|
821
775
|
this.ownership.acquireRuntime(user);
|
|
822
|
-
admitRuntimeFormat(serviceIdentity({ ...this.binding, user, home: this.homedir
|
|
776
|
+
admitRuntimeFormat(serviceIdentity({ ...this.binding, user, home: this.homedir }).serviceDir);
|
|
823
777
|
}
|
|
824
778
|
async startRuntime(machine) {
|
|
825
779
|
const record = mergeRecordAuth(machine.publicRecord, machine.secretAuth) ?? {};
|
|
@@ -831,15 +785,13 @@ export class MachineHost {
|
|
|
831
785
|
if (!userId || !userEmail || !computerId || !deviceId || !computerAuthToken) {
|
|
832
786
|
throw Object.assign(new Error("runtime identity or credentials are incomplete"), { code: "runtime_identity_incomplete" });
|
|
833
787
|
}
|
|
834
|
-
const
|
|
835
|
-
const workspaceRoot = join(userRoot, "workspaces");
|
|
788
|
+
const user = this.user(userEmail);
|
|
836
789
|
const runtimeToken = randomBytes(32).toString("base64url");
|
|
837
790
|
const runtimeIdentity = createRuntimeIdentity({
|
|
838
791
|
binding: this.binding, userScope: userEmail, deviceId, instanceId: randomUUID(),
|
|
839
792
|
});
|
|
840
793
|
const env = {
|
|
841
794
|
...process.env,
|
|
842
|
-
AMALGM_ROOT: this.amalgmRoot,
|
|
843
795
|
AMALGM_USER_EMAIL: userEmail,
|
|
844
796
|
AMALGM_USER_ID: userId,
|
|
845
797
|
AMALGM_DEVICE_ID: deviceId,
|
|
@@ -849,21 +801,19 @@ export class MachineHost {
|
|
|
849
801
|
AMALGM_RUNTIME_TOKEN: runtimeToken,
|
|
850
802
|
AMALGM_LOCAL_SESSION: this.binding.localSession,
|
|
851
803
|
AMALGM_PROXY_URL: runtimeProxyOrigin(this.binding, this.options.appUrl, this.options.proxyUrl),
|
|
852
|
-
AMALGM_WORKSPACES_DIR: workspaceRoot,
|
|
853
804
|
};
|
|
854
805
|
const pty = createPtyHost({
|
|
855
806
|
env,
|
|
856
|
-
defaultCwd:
|
|
807
|
+
defaultCwd: user.workspaces,
|
|
857
808
|
});
|
|
858
809
|
const services = new Set(machine.installation.services);
|
|
859
|
-
const serviceStateRoot = join(this.paths(userEmail).machineDir, "services");
|
|
860
810
|
const state = new StateRail({
|
|
861
|
-
store: new FileStateEventStore(
|
|
811
|
+
store: new FileStateEventStore(user.computer.stateEvents),
|
|
862
812
|
});
|
|
863
813
|
const workspaceHost = createWorkspaceHost({
|
|
864
|
-
file:
|
|
814
|
+
file: user.computer.workspaces,
|
|
865
815
|
computerId,
|
|
866
|
-
workspaceRoot,
|
|
816
|
+
workspaceRoot: user.workspaces,
|
|
867
817
|
state,
|
|
868
818
|
});
|
|
869
819
|
const chatHostSdk = services.has("chat") ? await import("@amalgm/chat/host") : null;
|
|
@@ -879,12 +829,19 @@ export class MachineHost {
|
|
|
879
829
|
const appsSdk = toolsSdk && includeApps ? await import("@amalgm/apps") : null;
|
|
880
830
|
const browserHost = toolsSdk && includeBrowser
|
|
881
831
|
? (await import("./browser-host.js")).createBrowserHost({
|
|
882
|
-
root:
|
|
832
|
+
root: user.computer.browser,
|
|
883
833
|
account: { id: userId, name: userEmail },
|
|
884
834
|
})
|
|
885
835
|
: null;
|
|
836
|
+
// Agents renames an idle agent's folder; no agent is busy until Chat is up.
|
|
837
|
+
let agentBusy = (_agentId) => false;
|
|
886
838
|
const agentsService = agentsSdk
|
|
887
|
-
? new agentsSdk.Agents({
|
|
839
|
+
? new agentsSdk.Agents({
|
|
840
|
+
root: user.agents,
|
|
841
|
+
parked: user.computer.parked,
|
|
842
|
+
osHome: this.homedir,
|
|
843
|
+
isBusy: (agentId) => agentBusy(agentId),
|
|
844
|
+
})
|
|
888
845
|
: null;
|
|
889
846
|
const agentsMcp = agentsService ? agentsMcpSdk.createMcpServer({ agents: agentsService }) : null;
|
|
890
847
|
const agentsRest = agentsService ? agentsHttpSdk.createRestServer({ agents: agentsService }) : null;
|
|
@@ -894,7 +851,9 @@ export class MachineHost {
|
|
|
894
851
|
// moment, and every deliberate act here reaches them through one door.
|
|
895
852
|
const appsService = appsSdk
|
|
896
853
|
? new appsSdk.Apps({
|
|
897
|
-
|
|
854
|
+
root: user.apps,
|
|
855
|
+
dir: user.computer.apps,
|
|
856
|
+
parked: user.computer.parked,
|
|
898
857
|
recordConstruct: (change) => {
|
|
899
858
|
this.assertSyncEnabled();
|
|
900
859
|
const ground = this.groundHost;
|
|
@@ -920,12 +879,13 @@ export class MachineHost {
|
|
|
920
879
|
: [];
|
|
921
880
|
if (agentsService)
|
|
922
881
|
installBuiltinAgents(agentsService, platformTools.map((tool) => tool.id));
|
|
923
|
-
const credentialVault = createCredentialVault(
|
|
882
|
+
const credentialVault = createCredentialVault(user.computer.credentials);
|
|
924
883
|
const toolsMcp = services.has("tools")
|
|
925
884
|
? await createShellToolsMcp({
|
|
885
|
+
root: user.toolbox,
|
|
886
|
+
dir: user.computer.tools,
|
|
887
|
+
parked: user.computer.parked,
|
|
926
888
|
credentials: { get: (ref) => credentialVault.getSecret(ref), set: (ref, value) => credentialVault.putSecret(ref, value), delete: (ref) => credentialVault.deleteSecret(ref) },
|
|
927
|
-
databaseFile: join(serviceStateRoot, "tools", "tools.db"),
|
|
928
|
-
deploymentDir: join(userRoot, "toolbox"),
|
|
929
889
|
systemTools: [...platformTools],
|
|
930
890
|
}, {
|
|
931
891
|
localBaseUrl: () => `http://127.0.0.1:${gatewayPort()}`, runtimeToken: () => runtimeToken,
|
|
@@ -941,7 +901,7 @@ export class MachineHost {
|
|
|
941
901
|
throw new Error("The Chat release requires Agents and Tools");
|
|
942
902
|
}
|
|
943
903
|
const authorization = await createShellAuthorization({
|
|
944
|
-
|
|
904
|
+
dir: this.lane.authorization,
|
|
945
905
|
appUrl: this.options.appUrl,
|
|
946
906
|
computerAuthToken,
|
|
947
907
|
computerId,
|
|
@@ -987,18 +947,21 @@ export class MachineHost {
|
|
|
987
947
|
? await (await import("./chat-composition.js")).createShellChatComposition({
|
|
988
948
|
ownerUserId: userId,
|
|
989
949
|
computerId,
|
|
990
|
-
|
|
950
|
+
user,
|
|
951
|
+
osHome: this.homedir,
|
|
991
952
|
agents: agentsService,
|
|
992
953
|
toolbox: toolsMcp.toolbox,
|
|
954
|
+
resolveCredential: (input) => credentialVault.resolve(input),
|
|
993
955
|
...(this.options.chatRuntime ? { runtime: this.options.chatRuntime } : {}),
|
|
994
956
|
localBaseUrl: () => `http://127.0.0.1:${gatewayPort()}`,
|
|
995
957
|
runtimeToken,
|
|
996
958
|
credentialBroker: authorization,
|
|
997
959
|
proxyBaseUrl: env.AMALGM_PROXY_URL,
|
|
998
|
-
amalgmDir: this.paths(userEmail).userRoot,
|
|
999
960
|
workspaces: workspaceHost.scope,
|
|
1000
961
|
})
|
|
1001
962
|
: null;
|
|
963
|
+
if (chat)
|
|
964
|
+
agentBusy = chat.isAgentBusy;
|
|
1002
965
|
const products = this.options.platformProducts
|
|
1003
966
|
? await (await import("./platform-product-host.js")).createPlatformProductHost({
|
|
1004
967
|
...this.options.platformProducts,
|
|
@@ -1007,7 +970,7 @@ export class MachineHost {
|
|
|
1007
970
|
sourceHomeDirectory: this.homedir,
|
|
1008
971
|
...(this.options.platformProducts.automationsBaseUrl ? {
|
|
1009
972
|
processes: (await import("@amalgm/automations")).createNodeAutomationProcessHost({
|
|
1010
|
-
defaultCwd:
|
|
973
|
+
defaultCwd: user.workspaces,
|
|
1011
974
|
environment: { ...process.env, HOME: this.homedir },
|
|
1012
975
|
}),
|
|
1013
976
|
} : {}),
|
|
@@ -1119,13 +1082,15 @@ export class MachineHost {
|
|
|
1119
1082
|
...(chat?.mounts() ?? []),
|
|
1120
1083
|
stateMount(state),
|
|
1121
1084
|
workspaceHost.mount,
|
|
1122
|
-
filesBrowserMount({ userEmail, computerId, userRoot }),
|
|
1085
|
+
filesBrowserMount({ userEmail, computerId, userRoot: user.root }),
|
|
1123
1086
|
...(services.has("core") ? [localMount({
|
|
1124
1087
|
home: this.homedir,
|
|
1125
1088
|
env,
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1089
|
+
workspaceRoot: user.workspaces,
|
|
1090
|
+
...(chatHostSdk ? {
|
|
1091
|
+
providerLogin: chatHostSdk.providerLoginConfigured,
|
|
1092
|
+
harnessAvailability: () => chatHostSdk.harnessAvailability({ home: this.homedir }),
|
|
1093
|
+
} : {}),
|
|
1129
1094
|
})] : []),
|
|
1130
1095
|
pty.mount,
|
|
1131
1096
|
],
|
|
@@ -1146,7 +1111,7 @@ export class MachineHost {
|
|
|
1146
1111
|
products?.runner.start();
|
|
1147
1112
|
commandPublication = {
|
|
1148
1113
|
instanceId: runtimeIdentity.instanceId,
|
|
1149
|
-
userRoot:
|
|
1114
|
+
userRoot: user.root,
|
|
1150
1115
|
deviceId,
|
|
1151
1116
|
...this.binding,
|
|
1152
1117
|
userScope: userEmail,
|
|
@@ -1181,7 +1146,6 @@ export class MachineHost {
|
|
|
1181
1146
|
await agentsRest?.close();
|
|
1182
1147
|
await toolsHttp?.close();
|
|
1183
1148
|
await closeSelectedProducts();
|
|
1184
|
-
agentsService?.close();
|
|
1185
1149
|
toolsMcp?.toolbox.close();
|
|
1186
1150
|
}
|
|
1187
1151
|
finally {
|
|
@@ -1216,7 +1180,6 @@ export class MachineHost {
|
|
|
1216
1180
|
() => agentsRest?.close(),
|
|
1217
1181
|
() => toolsHttp?.close(),
|
|
1218
1182
|
closeSelectedProducts,
|
|
1219
|
-
() => agentsService?.close(),
|
|
1220
1183
|
() => toolsMcp?.toolbox.close(),
|
|
1221
1184
|
]) {
|
|
1222
1185
|
try {
|