@amalgm/shell 0.1.164-preview.35157059187 → 0.1.164-preview.35188094873
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 +2 -2
- package/README.md +7 -0
- package/dist/automations-host.d.ts +2 -0
- package/dist/automations-host.js.map +1 -1
- package/dist/boot.js +15 -20
- package/dist/boot.js.map +1 -1
- package/dist/bundle-automations.d.ts +2 -20
- package/dist/bundle-automations.js +17 -62
- package/dist/bundle-automations.js.map +1 -1
- package/dist/bundle-port.d.ts +2 -6
- package/dist/bundle-port.js +13 -15
- package/dist/bundle-port.js.map +1 -1
- package/dist/cli.js +51 -22
- package/dist/cli.js.map +1 -1
- package/dist/construct-apply-host.d.ts +61 -0
- package/dist/construct-apply-host.js +103 -0
- package/dist/construct-apply-host.js.map +1 -0
- package/dist/construct-door.d.ts +37 -0
- package/dist/construct-door.js +51 -0
- package/dist/construct-door.js.map +1 -0
- package/dist/construct-ledger.d.ts +26 -0
- package/dist/construct-ledger.js +86 -0
- package/dist/construct-ledger.js.map +1 -0
- package/dist/construct-products.d.ts +22 -0
- package/dist/construct-products.js +30 -0
- package/dist/construct-products.js.map +1 -0
- package/dist/entity-access-wire.d.ts +32 -0
- package/dist/entity-access-wire.js +153 -0
- package/dist/entity-access-wire.js.map +1 -0
- package/dist/entity-apply-host.d.ts +9 -1
- package/dist/entity-apply-host.js +20 -2
- package/dist/entity-apply-host.js.map +1 -1
- package/dist/entity-channel-holdings.d.ts +26 -0
- package/dist/entity-channel-holdings.js +52 -0
- package/dist/entity-channel-holdings.js.map +1 -0
- package/dist/entity-record-observability.js +21 -0
- package/dist/entity-record-observability.js.map +1 -1
- package/dist/entity-record-store.d.ts +8 -3
- package/dist/entity-record-store.js +28 -1
- package/dist/entity-record-store.js.map +1 -1
- package/dist/installation/environment.d.ts +0 -2
- package/dist/installation/environment.js +0 -4
- package/dist/installation/environment.js.map +1 -1
- package/dist/machine-host.d.ts +4 -5
- package/dist/machine-host.js +63 -81
- package/dist/machine-host.js.map +1 -1
- package/dist/runtime-command-host.d.ts +3 -1
- package/dist/runtime-command-host.js +2 -1
- package/dist/runtime-command-host.js.map +1 -1
- package/dist/sharing-host.d.ts +19 -0
- package/dist/sharing-host.js +19 -0
- package/dist/sharing-host.js.map +1 -0
- package/dist/sharing-mcp-host.d.ts +23 -0
- package/dist/{descriptor-mcp-host.js → sharing-mcp-host.js} +23 -9
- package/dist/sharing-mcp-host.js.map +1 -0
- package/dist/user-ground-host.d.ts +29 -3
- package/dist/user-ground-host.js +90 -5
- package/dist/user-ground-host.js.map +1 -1
- package/dist/wire-client.d.ts +0 -9
- package/dist/wire-client.js +0 -13
- package/dist/wire-client.js.map +1 -1
- package/examinations/fixtures/machine-control-plane.js +0 -13
- package/examinations/fixtures/private-wire-authority.js +170 -9
- package/npm-shrinkwrap.json +14 -14
- package/package.json +7 -7
- package/dist/descriptor-mcp-host.d.ts +0 -26
- package/dist/descriptor-mcp-host.js.map +0 -1
- package/dist/installed-automations.d.ts +0 -70
- package/dist/installed-automations.js +0 -135
- package/dist/installed-automations.js.map +0 -1
- package/dist/runtime-mcp-cli-host.d.ts +0 -29
- package/dist/runtime-mcp-cli-host.js +0 -84
- package/dist/runtime-mcp-cli-host.js.map +0 -1
- package/dist/share-host.d.ts +0 -24
- package/dist/share-host.js +0 -34
- package/dist/share-host.js.map +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which construct channels this computer follows: the UUIDs this user
|
|
3
|
+
* created and the UUIDs granted to them. Grants move while the runtime is
|
|
4
|
+
* up, so the user-level grant signal moves the held set; a signal naming no
|
|
5
|
+
* entity means the signal channel resumed after a gap and the whole set must
|
|
6
|
+
* be read again.
|
|
7
|
+
*/
|
|
8
|
+
/** Every construct UUID this user may read from this computer, owned first. */
|
|
9
|
+
export async function readGrantedChannels(access, userId) {
|
|
10
|
+
const [owned, granted] = await Promise.all([
|
|
11
|
+
access.owned(),
|
|
12
|
+
access.records.listGrantsTo(userId),
|
|
13
|
+
]);
|
|
14
|
+
return [...new Set([...owned, ...granted.map((grant) => grant.entityId)])];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Follow the grant signal for the life of the connection. `held` is the set
|
|
18
|
+
* the rail already started with, so a signal for an entity this computer
|
|
19
|
+
* already follows costs nothing.
|
|
20
|
+
*/
|
|
21
|
+
export async function followGrantedChannels(input) {
|
|
22
|
+
const held = new Set(input.held);
|
|
23
|
+
const reconcile = async () => {
|
|
24
|
+
const current = new Set(await readGrantedChannels(input.access, input.userId));
|
|
25
|
+
for (const entityId of current) {
|
|
26
|
+
if (!held.has(entityId))
|
|
27
|
+
input.rail.hold(entityId);
|
|
28
|
+
}
|
|
29
|
+
for (const entityId of held) {
|
|
30
|
+
if (!current.has(entityId))
|
|
31
|
+
input.rail.release(entityId);
|
|
32
|
+
}
|
|
33
|
+
held.clear();
|
|
34
|
+
for (const entityId of current)
|
|
35
|
+
held.add(entityId);
|
|
36
|
+
};
|
|
37
|
+
const apply = (signal) => {
|
|
38
|
+
if (signal.entityId === null) {
|
|
39
|
+
reconcile().catch((error) => input.onError?.(error));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (signal.revoked) {
|
|
43
|
+
input.rail.release(signal.entityId);
|
|
44
|
+
held.delete(signal.entityId);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
input.rail.hold(signal.entityId);
|
|
48
|
+
held.add(signal.entityId);
|
|
49
|
+
};
|
|
50
|
+
return input.access.watchGrants(apply);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=entity-channel-holdings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-channel-holdings.js","sourceRoot":"","sources":["../src/entity-channel-holdings.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAwB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;QAC1C,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC7B,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;YACrD,OAAO;QACT,CAAC;QACD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACpC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7B,OAAO;QACT,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC,CAAC;IACF,OAAO,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -19,6 +19,7 @@ export function observeEntityRecordPorts(input) {
|
|
|
19
19
|
});
|
|
20
20
|
},
|
|
21
21
|
readDeliveryCursor: (authorityId) => input.store.readDeliveryCursor(authorityId),
|
|
22
|
+
readEntityCursor: (entityId) => input.store.readEntityCursor(entityId),
|
|
22
23
|
receive: async (request) => {
|
|
23
24
|
const started = performance.now();
|
|
24
25
|
const result = await input.store.receive(request);
|
|
@@ -133,6 +134,26 @@ export function observeEntityRecordPorts(input) {
|
|
|
133
134
|
}
|
|
134
135
|
return deliveries;
|
|
135
136
|
},
|
|
137
|
+
subscribeEntity: async (request) => {
|
|
138
|
+
const started = performance.now();
|
|
139
|
+
emit({
|
|
140
|
+
primitive: "receive",
|
|
141
|
+
stage: "entity-channel-tail",
|
|
142
|
+
status: "started",
|
|
143
|
+
entityId: request.entityId,
|
|
144
|
+
measurements: { afterGlobalSequence: request.afterGlobalSequence },
|
|
145
|
+
});
|
|
146
|
+
const deliveries = await input.authority.subscribeEntity(request);
|
|
147
|
+
emit({
|
|
148
|
+
primitive: "receive",
|
|
149
|
+
stage: "entity-channel-tail",
|
|
150
|
+
status: "completed",
|
|
151
|
+
entityId: request.entityId,
|
|
152
|
+
durationMs: performance.now() - started,
|
|
153
|
+
measurements: { deliveries: deliveries.length },
|
|
154
|
+
});
|
|
155
|
+
return deliveries;
|
|
156
|
+
},
|
|
136
157
|
backfill: (request) => input.authority.backfill(request),
|
|
137
158
|
onAvailable: (listener) => input.authority.onAvailable((signal) => {
|
|
138
159
|
emit({ primitive: "receive", stage: "realtime-doorbell", status: "observed" });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-record-observability.js","sourceRoot":"","sources":["../src/entity-record-observability.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAQpE,OAAO,EAAE,cAAc,EAA2B,MAAM,0BAA0B,CAAC;AAEnF,MAAM,UAAU,wBAAwB,CAAC,KAKxC;IAKC,MAAM,IAAI,GAAG,CAAC,QAA8C,EAAE,EAAE,CAC9D,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC1C,OAAO;QACL,KAAK,EAAE;YACL,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC;YACtD,aAAa,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE;gBACrC,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;gBAClC,MAAM,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;gBAC/C,IAAI,CAAC;oBACH,SAAS,EAAE,MAAM;oBACjB,KAAK,EAAE,qBAAqB;oBAC5B,MAAM,EAAE,WAAW;oBACnB,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ;oBAC7B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU;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edEntityRecord, type DeliveredEntityRecord, type EntityRecordStorePort, type PendingEntityRecord, type ReceiveEntityDeliveriesResult } from "@amalgm/live";
|
|
2
|
+
import { type AcceptedEntityRecord, type DeliveredEntityRecord, type EntityRecordStorePort, type IntentionalRecordStorePort, type LocalEntityRecord, type PendingEntityRecord, type ReceiveEntityDeliveriesResult, type SealedPayload } from "@amalgm/live";
|
|
3
3
|
import Database from "better-sqlite3";
|
|
4
|
-
export declare class EntityRecordSqliteStore implements EntityRecordStorePort {
|
|
4
|
+
export declare class EntityRecordSqliteStore implements EntityRecordStorePort, IntentionalRecordStorePort {
|
|
5
5
|
#private;
|
|
6
|
-
constructor(database: Database.Database, now?: () => number);
|
|
6
|
+
constructor(database: Database.Database, cacheDir: string, now?: () => number);
|
|
7
7
|
readPending(limit: number): readonly PendingEntityRecord[];
|
|
8
8
|
/** Exact cache heads still required to retry unresolved Send records. */
|
|
9
9
|
pendingContentHashes(): ReadonlySet<string>;
|
|
10
10
|
stampAccepted(row: PendingEntityRecord, accepted: AcceptedEntityRecord): void;
|
|
11
11
|
readDeliveryCursor(authorityId: string): number;
|
|
12
|
+
readEntityCursor(entityId: string): number;
|
|
12
13
|
readEntityCursors(authorityId: string): ReadonlyMap<string, number>;
|
|
14
|
+
/** The intentional door's one durable effect. The payload is sealed before
|
|
15
|
+
* the row exists, so Send can always find the cargo a pending row names;
|
|
16
|
+
* unreferenced cache content is reclaimed by the machine's cache prune. */
|
|
17
|
+
append(record: LocalEntityRecord, payload: SealedPayload | null): void;
|
|
13
18
|
receive(input: {
|
|
14
19
|
readonly authorityId: string;
|
|
15
20
|
readonly deliveries: readonly DeliveredEntityRecord[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Persistent SQLite effects for Live's entity Record rail. No delivery policy lives here. */
|
|
2
2
|
import { acceptOutboxRow, decodeAcceptedEntityRecord, decodeLocalEntityRecord, encodeEntityRecord, receiveEntityRecord, } from "@amalgm/live";
|
|
3
|
+
import { sealCapturedArtifact } from "./content-cache-host.js";
|
|
3
4
|
import { ensureSnapshotDeliveryBaselineTable } from "./snapshot-delivery-baseline.js";
|
|
4
5
|
class ReceiveGap extends Error {
|
|
5
6
|
result;
|
|
@@ -10,8 +11,10 @@ class ReceiveGap extends Error {
|
|
|
10
11
|
}
|
|
11
12
|
export class EntityRecordSqliteStore {
|
|
12
13
|
#database;
|
|
14
|
+
#cacheDir;
|
|
13
15
|
#now;
|
|
14
16
|
#pending;
|
|
17
|
+
#append;
|
|
15
18
|
#stamp;
|
|
16
19
|
#outboxReceipt;
|
|
17
20
|
#deliveryCursor;
|
|
@@ -22,8 +25,9 @@ export class EntityRecordSqliteStore {
|
|
|
22
25
|
#advanceEntityCursor;
|
|
23
26
|
#advanceDeliveryCursor;
|
|
24
27
|
#snapshotBaseline;
|
|
25
|
-
constructor(database, now = Date.now) {
|
|
28
|
+
constructor(database, cacheDir, now = Date.now) {
|
|
26
29
|
this.#database = database;
|
|
30
|
+
this.#cacheDir = cacheDir;
|
|
27
31
|
this.#now = now;
|
|
28
32
|
ensureSnapshotDeliveryBaselineTable(database);
|
|
29
33
|
this.#pending = database.prepare(`
|
|
@@ -39,6 +43,12 @@ export class EntityRecordSqliteStore {
|
|
|
39
43
|
)
|
|
40
44
|
ORDER BY candidate.local_sequence
|
|
41
45
|
LIMIT ?
|
|
46
|
+
`);
|
|
47
|
+
this.#append = database.prepare(`
|
|
48
|
+
INSERT INTO record_outbox(
|
|
49
|
+
mutation_id, authority_id, entity_id, record_json, status,
|
|
50
|
+
global_sequence, created_at, accepted_at
|
|
51
|
+
) VALUES (?, ?, ?, ?, 'pending', NULL, ?, NULL)
|
|
42
52
|
`);
|
|
43
53
|
this.#stamp = database.prepare(`
|
|
44
54
|
UPDATE record_outbox
|
|
@@ -130,9 +140,26 @@ export class EntityRecordSqliteStore {
|
|
|
130
140
|
const row = this.#deliveryCursor.get(authorityId);
|
|
131
141
|
return row?.receivedThrough ?? 0;
|
|
132
142
|
}
|
|
143
|
+
readEntityCursor(entityId) {
|
|
144
|
+
const row = this.#entityCursor.get(entityId);
|
|
145
|
+
return row?.receivedThrough ?? 0;
|
|
146
|
+
}
|
|
133
147
|
readEntityCursors(authorityId) {
|
|
134
148
|
return new Map(this.#entityCursors.all(authorityId).map((row) => [row.entityId, row.receivedThrough]));
|
|
135
149
|
}
|
|
150
|
+
/** The intentional door's one durable effect. The payload is sealed before
|
|
151
|
+
* the row exists, so Send can always find the cargo a pending row names;
|
|
152
|
+
* unreferenced cache content is reclaimed by the machine's cache prune. */
|
|
153
|
+
append(record, payload) {
|
|
154
|
+
if (payload !== null) {
|
|
155
|
+
const artifact = record.change.cargo.find((candidate) => candidate.contentHash === payload.manifest.contentHash);
|
|
156
|
+
if (!artifact) {
|
|
157
|
+
throw new Error(`record ${record.mutationId} carries no cargo for its sealed payload`);
|
|
158
|
+
}
|
|
159
|
+
sealCapturedArtifact(this.#cacheDir, artifact, payload.bytes);
|
|
160
|
+
}
|
|
161
|
+
this.#append.run(record.mutationId, record.authorityId, record.entityId, encodeEntityRecord(record), record.createdAt);
|
|
162
|
+
}
|
|
136
163
|
receive(input) {
|
|
137
164
|
try {
|
|
138
165
|
return this.#database.transaction(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-record-store.js","sourceRoot":"","sources":["../src/entity-record-store.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,OAAO,EACL,eAAe,EACf,0BAA0B,EAC1B,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"entity-record-store.js","sourceRoot":"","sources":["../src/entity-record-store.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,OAAO,EACL,eAAe,EACf,0BAA0B,EAC1B,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,GASpB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,mCAAmC,EAAE,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
|
24
24
|
export declare function runtimeAppOrigin(binding: RuntimeBinding, explicit?: string): string;
|
|
25
|
-
/** Hosted apps live one label under the lane's app host: apps.amalgm.ai, apps.preview.amalgm.ai. */
|
|
26
|
-
export declare function runtimeAppsDomain(binding: RuntimeBinding, appUrl: string): string;
|
|
27
25
|
export declare function runtimeProxyOrigin(binding: RuntimeBinding, appUrl: string, explicit?: string): string | undefined;
|
|
28
26
|
export declare function runtimeWireUrl(binding: RuntimeBinding, appUrl: string, value: string, declared?: string): string;
|
|
29
27
|
export declare function runtimeHostedEndpoints(binding: RuntimeBinding, appUrl: string, env: NodeJS.ProcessEnv): {
|
|
@@ -3,10 +3,6 @@ export const managedEnvironments = managedRuntimeEndpoints;
|
|
|
3
3
|
export function runtimeAppOrigin(binding, explicit) {
|
|
4
4
|
return resolveRuntimeEndpoint(binding, 'app', explicit, explicit);
|
|
5
5
|
}
|
|
6
|
-
/** Hosted apps live one label under the lane's app host: apps.amalgm.ai, apps.preview.amalgm.ai. */
|
|
7
|
-
export function runtimeAppsDomain(binding, appUrl) {
|
|
8
|
-
return `apps.${new URL(runtimeAppOrigin(binding, appUrl)).host}`;
|
|
9
|
-
}
|
|
10
6
|
export function runtimeProxyOrigin(binding, appUrl, explicit) {
|
|
11
7
|
if (!explicit && (binding.runtimeLabel === 'local' || isLoopbackEndpoint(appUrl)))
|
|
12
8
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/installation/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,sBAAsB,EAAuB,MAAM,uBAAuB,CAAC;AAE3J,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAE3D,MAAM,UAAU,gBAAgB,CAAC,OAAuB,EAAE,QAAiB;IACzE,OAAO,sBAAsB,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,C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AAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACpG,MAAM,QAAQ,GAAG,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACzE,MAAM,WAAW,GAAG,GAAG,CAAC,sBAAsB,IAAI,QAAQ,EAAE,WAAW,CAAC;IACxE,MAAM,QAAQ,GAAG,GAAG,CAAC,mBAAmB,IAAI,QAAQ,EAAE,QAAQ,CAAC;IAC/D,OAAO;QACL,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,sBAAsB,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnH,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,sBAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxG,CAAC;AACJ,CAAC"}
|
package/dist/machine-host.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { EntityApplyStageEvidence } from "./entity-apply-host.js";
|
|
|
7
7
|
import { type DeviceKeyStore } from "./authorization/index.js";
|
|
8
8
|
import { type AuthorizationKeyRecoveryResult } from "./authorization/recovery-host.js";
|
|
9
9
|
import type { PlatformProductHostOptions } from "./platform-product-host.js";
|
|
10
|
-
import { type RuntimeCommandConnection } from "./runtime-command-host.js";
|
|
10
|
+
import { type RuntimeCommandPath, type RuntimeCommandConnection } from "./runtime-command-host.js";
|
|
11
11
|
import type { UserGroundHost, DetectScanEvidence, UserGroundCloseOptions, WorkspaceAddStage } from "./user-ground-host.js";
|
|
12
12
|
import type { OpenNativeWatch, WatchCoverageEvidence, WatchHealth } from "./watching/index.js";
|
|
13
13
|
export interface MachineHostOptions {
|
|
@@ -107,6 +107,8 @@ export declare class MachineHost {
|
|
|
107
107
|
private readonly ownership;
|
|
108
108
|
private selectedUserEmail;
|
|
109
109
|
private groundHost;
|
|
110
|
+
/** Apps while a runtime holds it: the product that answers for `app`. */
|
|
111
|
+
private appsProduct;
|
|
110
112
|
private running;
|
|
111
113
|
private readonly stages;
|
|
112
114
|
constructor(options: MachineHostOptions);
|
|
@@ -124,9 +126,6 @@ export declare class MachineHost {
|
|
|
124
126
|
* running Shell, resume a durable registration, or begin installation. */
|
|
125
127
|
status(): Promise<MachineStatus>;
|
|
126
128
|
filesCommandPorts(): ReturnType<UserGroundHost["filesCommandPorts"]>;
|
|
127
|
-
/** Runs one startup stage without holding readiness, reporting it through the diagnostic. */
|
|
128
|
-
private backgroundStage;
|
|
129
|
-
private requireGroundHost;
|
|
130
129
|
/** Materialize through Live and prove the same runtime owns ongoing Watch. */
|
|
131
130
|
addWorkspace(workspaceId: string, destinationParent: string): Promise<FilesAddResult & {
|
|
132
131
|
readonly watch: WatchCoverageEvidence;
|
|
@@ -140,7 +139,7 @@ export declare class MachineHost {
|
|
|
140
139
|
* is the only way a typed command can report what its journey spent. */
|
|
141
140
|
private journey;
|
|
142
141
|
watchEvidence(): WatchCoverageEvidence;
|
|
143
|
-
callFilesRuntime(path:
|
|
142
|
+
callFilesRuntime(path: RuntimeCommandPath, body: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
144
143
|
automationRuntimeConnection(): Promise<RuntimeCommandConnection>;
|
|
145
144
|
/** The global Channels CLI enters through the running Shell's private
|
|
146
145
|
* loopback MCP route. Shell alone reads the local admission capability. */
|
package/dist/machine-host.js
CHANGED
|
@@ -16,12 +16,12 @@ import { recoverMachineAuthorization, } from "./authorization/recovery-host.js";
|
|
|
16
16
|
import { postRegistration } from "./authorization/registration-http.js";
|
|
17
17
|
import { postSetupJson, setupOrigin } from "./authorization/setup-http.js";
|
|
18
18
|
import { installBuiltinAgents } from "./builtin-agents.js";
|
|
19
|
-
import { InstalledAutomations } from "./installed-automations.js";
|
|
20
19
|
import { InstallationOwnership } from "./installation/ownership.js";
|
|
21
20
|
import { assertSupportedInstallationLayout } from "./installation/layout.js";
|
|
22
|
-
import { runtimeAppOrigin,
|
|
21
|
+
import { runtimeAppOrigin, runtimeProxyOrigin, runtimeWireUrl } from "./installation/environment.js";
|
|
23
22
|
import { forwardMount } from "./forward.js";
|
|
24
23
|
import { filesBrowserMount } from "./files-browser-host.js";
|
|
24
|
+
import { createConstructPort } from "./construct-products.js";
|
|
25
25
|
import { createGateway } from "./gateway.js";
|
|
26
26
|
import { localMount } from "./local-host.js";
|
|
27
27
|
import { stateMount } from "./state-host.js";
|
|
@@ -45,6 +45,8 @@ export class MachineHost {
|
|
|
45
45
|
ownership;
|
|
46
46
|
selectedUserEmail;
|
|
47
47
|
groundHost = null;
|
|
48
|
+
/** Apps while a runtime holds it: the product that answers for `app`. */
|
|
49
|
+
appsProduct = null;
|
|
48
50
|
running = new Set();
|
|
49
51
|
stages;
|
|
50
52
|
constructor(options) {
|
|
@@ -178,6 +180,9 @@ export class MachineHost {
|
|
|
178
180
|
onWorkspaceAddStage: this.options.onWorkspaceAddStage,
|
|
179
181
|
onFilesStage: this.stages.observe,
|
|
180
182
|
filesTraceActive: () => this.stages.listening,
|
|
183
|
+
// The products are selected when the runtime starts, after this
|
|
184
|
+
// rail exists, so the owner of a construct type is asked per act.
|
|
185
|
+
constructProduct: (type) => (type === "app" ? this.appsProduct : null),
|
|
181
186
|
});
|
|
182
187
|
return this.groundHost.port.converge(identity);
|
|
183
188
|
},
|
|
@@ -370,21 +375,9 @@ export class MachineHost {
|
|
|
370
375
|
};
|
|
371
376
|
}
|
|
372
377
|
filesCommandPorts() {
|
|
373
|
-
return this.requireGroundHost().filesCommandPorts();
|
|
374
|
-
}
|
|
375
|
-
/** Runs one startup stage without holding readiness, reporting it through the diagnostic. */
|
|
376
|
-
backgroundStage(stage, work) {
|
|
377
|
-
this.options.diagnostic?.({ stage, status: "started" });
|
|
378
|
-
void work().then(() => this.options.diagnostic?.({ stage, status: "completed" }), (error) => this.options.diagnostic?.({
|
|
379
|
-
stage,
|
|
380
|
-
status: "failed",
|
|
381
|
-
code: error instanceof Error ? error.message : String(error),
|
|
382
|
-
}));
|
|
383
|
-
}
|
|
384
|
-
requireGroundHost() {
|
|
385
378
|
if (!this.groundHost)
|
|
386
|
-
throw new Error("
|
|
387
|
-
return this.groundHost;
|
|
379
|
+
throw new Error("Files commands require a resumed authenticated machine");
|
|
380
|
+
return this.groundHost.filesCommandPorts();
|
|
388
381
|
}
|
|
389
382
|
/** Materialize through Live and prove the same runtime owns ongoing Watch. */
|
|
390
383
|
async addWorkspace(workspaceId, destinationParent) {
|
|
@@ -745,22 +738,24 @@ export class MachineHost {
|
|
|
745
738
|
? new agentsSdk.Agents({ stateDir: join(serviceStateRoot, "agents") })
|
|
746
739
|
: null;
|
|
747
740
|
const agentsMcp = agentsService ? agentsMcpSdk.createMcpServer({ agents: agentsService }) : null;
|
|
748
|
-
|
|
749
|
-
// installs into; the REST server only needs it once a request arrives.
|
|
750
|
-
let bundlePort = null;
|
|
751
|
-
const agentsRest = agentsService ? agentsHttpSdk.createRestServer({
|
|
752
|
-
agents: agentsService,
|
|
753
|
-
bundlePort: {
|
|
754
|
-
exportResources: (input) => selectedBundlePort().exportResources(input),
|
|
755
|
-
installResources: (bundle) => selectedBundlePort().installResources(bundle),
|
|
756
|
-
},
|
|
757
|
-
}) : null;
|
|
758
|
-
const selectedBundlePort = () => {
|
|
759
|
-
if (!bundlePort)
|
|
760
|
-
throw new Error("Bundles need the Tools service in this installation.");
|
|
761
|
-
return bundlePort;
|
|
762
|
-
};
|
|
741
|
+
const agentsRest = agentsService ? agentsHttpSdk.createRestServer({ agents: agentsService }) : null;
|
|
763
742
|
const agentsAddress = agentsRest ? await agentsRest.listen(0, "127.0.0.1") : null;
|
|
743
|
+
// Apps owns the `app` construct type. The product is held for the whole
|
|
744
|
+
// runtime, not made on first use: the rails may deliver an app at any
|
|
745
|
+
// moment, and every deliberate act here reaches them through one door.
|
|
746
|
+
const appsService = appsSdk
|
|
747
|
+
? new appsSdk.Apps({
|
|
748
|
+
stateDir: join(serviceStateRoot, "apps"),
|
|
749
|
+
recordConstruct: (change) => {
|
|
750
|
+
const ground = this.groundHost;
|
|
751
|
+
if (!ground)
|
|
752
|
+
throw new Error("Recording an app requires a converged runtime");
|
|
753
|
+
return ground.recordConstruct({ entityType: "app", ...change });
|
|
754
|
+
},
|
|
755
|
+
})
|
|
756
|
+
: null;
|
|
757
|
+
const appsMcp = appsService ? appsSdk.createMcpServer({ apps: appsService }) : null;
|
|
758
|
+
this.appsProduct = appsService ? appsSdk.appConstructSurface(appsService) : null;
|
|
764
759
|
const platformTools = services.has("tools")
|
|
765
760
|
? await (await import("./platform-tools.js")).platformToolDefinitions({
|
|
766
761
|
...(agentsMcp ? { agents: agentsMcp } : {}),
|
|
@@ -776,27 +771,12 @@ export class MachineHost {
|
|
|
776
771
|
if (agentsService)
|
|
777
772
|
installBuiltinAgents(agentsService, platformTools.map((tool) => tool.id));
|
|
778
773
|
const credentialVault = createCredentialVault(join(this.paths(userEmail).machineDir, "credentials"));
|
|
779
|
-
let appsMcp = null;
|
|
780
|
-
const selectedAppsMcp = () => {
|
|
781
|
-
if (!appsSdk)
|
|
782
|
-
throw new Error("Apps is not selected in this installation.");
|
|
783
|
-
appsMcp ??= appsSdk.createMcpServer({
|
|
784
|
-
stateDir: join(serviceStateRoot, "apps"),
|
|
785
|
-
domain: runtimeAppsDomain(this.binding, this.options.appUrl),
|
|
786
|
-
publishRoutes: (routes) => this.requireGroundHost().advertiseAppRoutes(routes),
|
|
787
|
-
});
|
|
788
|
-
return appsMcp;
|
|
789
|
-
};
|
|
790
|
-
// A tool linked to an app runs with that app's address in its environment.
|
|
791
774
|
const toolsMcp = services.has("tools")
|
|
792
775
|
? await createShellToolsMcp({
|
|
793
776
|
credentials: { get: (ref) => credentialVault.getSecret(ref), set: (ref, value) => credentialVault.putSecret(ref, value), delete: (ref) => credentialVault.deleteSecret(ref) },
|
|
794
777
|
databaseFile: join(serviceStateRoot, "tools", "tools.db"),
|
|
795
778
|
deploymentDir: join(userRoot, "toolbox"),
|
|
796
779
|
systemTools: [...platformTools],
|
|
797
|
-
environment: (tool) => tool.appId && appsSdk
|
|
798
|
-
? appsSdk.linkedToolEnvironment(selectedAppsMcp().apps.get(tool.appId))
|
|
799
|
-
: {},
|
|
800
780
|
}, {
|
|
801
781
|
localBaseUrl: () => `http://127.0.0.1:${gatewayPort()}`, runtimeToken: () => runtimeToken,
|
|
802
782
|
})
|
|
@@ -823,6 +803,28 @@ export class MachineHost {
|
|
|
823
803
|
? { platform: this.options.authorizationPlatform }
|
|
824
804
|
: {}),
|
|
825
805
|
});
|
|
806
|
+
// The Sharing doors. Constructs are entity types on the rails, so the
|
|
807
|
+
// surface is mounted for every installation: which products answer for a
|
|
808
|
+
// construct kind is an installation fact, reported in that kind's own
|
|
809
|
+
// lane. The ports are read per call because the rail stops and starts
|
|
810
|
+
// under a long-lived mount.
|
|
811
|
+
const sharing = (await import("./sharing-host.js")).createSharingSurface({
|
|
812
|
+
ports: () => {
|
|
813
|
+
if (!this.groundHost)
|
|
814
|
+
throw new Error("Sharing requires a running authenticated runtime");
|
|
815
|
+
return this.groundHost.sharingPorts({
|
|
816
|
+
constructs: createConstructPort({
|
|
817
|
+
// Apps records its constructs through the intentional door, so
|
|
818
|
+
// it answers for `app`. A kind no product owns here resolves to
|
|
819
|
+
// "not selected in this installation"; no other kind is hurt.
|
|
820
|
+
products: this.appsProduct ? { app: this.appsProduct } : {},
|
|
821
|
+
kindOf: async (uuid) => this.groundHost?.constructKind(uuid) ?? null,
|
|
822
|
+
}),
|
|
823
|
+
link: (id) => `${this.options.appUrl.replace(/\/+$/, "")}/c/${id}`,
|
|
824
|
+
});
|
|
825
|
+
},
|
|
826
|
+
actor: () => ({ userId, email: userEmail }),
|
|
827
|
+
});
|
|
826
828
|
let gateway = null;
|
|
827
829
|
const gatewayPort = () => {
|
|
828
830
|
const address = gateway?.address();
|
|
@@ -880,24 +882,6 @@ export class MachineHost {
|
|
|
880
882
|
? await (await import("./official-mcp-host.js")).connectOfficialMcpServer((await import("@amalgm/channels/mcp")).createChannelsMcpServer(products.channels), { name: 'amalgm-channels', version: '0.1.0' })
|
|
881
883
|
: null;
|
|
882
884
|
const chatMcp = chat ? (await import("@amalgm/chat/mcp")).createChatMcpServer(chat.chat, { agentRunner: chat.agentRunner }) : null;
|
|
883
|
-
const shareMcp = (await import("./share-host.js")).createShareMcpHost({
|
|
884
|
-
appUrl: this.options.appUrl,
|
|
885
|
-
computerAuthToken,
|
|
886
|
-
computerId,
|
|
887
|
-
});
|
|
888
|
-
// An accepted automation lives and runs on the machine that accepted it:
|
|
889
|
-
// registered with the hosted service against this computer, projected
|
|
890
|
-
// to disk here, and reconciled against the service each runtime start.
|
|
891
|
-
const installedAutomations = products?.automations
|
|
892
|
-
? new InstalledAutomations(join(serviceStateRoot, "automations"))
|
|
893
|
-
: null;
|
|
894
|
-
bundlePort = toolsMcp ? (await import("./bundle-port.js")).createShellBundlePort({
|
|
895
|
-
apps: () => selectedAppsMcp().apps,
|
|
896
|
-
toolbox: toolsMcp.toolbox,
|
|
897
|
-
...(products?.automations && installedAutomations ? {
|
|
898
|
-
automations: { crud: products.automations, targetId: computerId, installed: installedAutomations },
|
|
899
|
-
} : {}),
|
|
900
|
-
}) : null;
|
|
901
885
|
let browserMcp = null;
|
|
902
886
|
let browserService = null;
|
|
903
887
|
const selectedBrowserMcp = () => {
|
|
@@ -908,9 +892,9 @@ export class MachineHost {
|
|
|
908
892
|
return browserMcp;
|
|
909
893
|
};
|
|
910
894
|
const closeSelectedProducts = async () => {
|
|
911
|
-
const selectedApps = appsMcp;
|
|
912
895
|
const selectedBrowser = browserService;
|
|
913
|
-
|
|
896
|
+
this.appsProduct = null;
|
|
897
|
+
await appsService?.close();
|
|
914
898
|
if (selectedBrowser) {
|
|
915
899
|
await Promise.all(selectedBrowser.listSessions().map((session) => selectedBrowser.closeSession(session.id)));
|
|
916
900
|
}
|
|
@@ -928,6 +912,17 @@ export class MachineHost {
|
|
|
928
912
|
prefix: "/entities/add",
|
|
929
913
|
handle: (body) => this.journey(body, () => this.addWorkspace(bodyText(body, "uuid"), bodyText(body, "path"))),
|
|
930
914
|
},
|
|
915
|
+
{
|
|
916
|
+
prefix: "/sharing/cli",
|
|
917
|
+
handle: async (body) => sharing.cli(body?.argv instanceof Array
|
|
918
|
+
? (body.argv).map((value) => String(value))
|
|
919
|
+
: []),
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
prefix: "/mcp/share",
|
|
923
|
+
protocol: "mcp-json-rpc",
|
|
924
|
+
handle: (body) => sharing.mcp.handle(body),
|
|
925
|
+
},
|
|
931
926
|
...(agentsMcp ? [{
|
|
932
927
|
prefix: "/mcp/agents",
|
|
933
928
|
protocol: "mcp-json-rpc",
|
|
@@ -938,10 +933,10 @@ export class MachineHost {
|
|
|
938
933
|
protocol: "mcp-json-rpc",
|
|
939
934
|
handle: (body) => toolsMcp.handle(body),
|
|
940
935
|
}] : []),
|
|
941
|
-
...(
|
|
936
|
+
...(appsMcp ? [{
|
|
942
937
|
prefix: "/mcp/apps",
|
|
943
938
|
protocol: "mcp-json-rpc",
|
|
944
|
-
handle: (body) =>
|
|
939
|
+
handle: (body) => appsMcp.handle(body),
|
|
945
940
|
}] : []),
|
|
946
941
|
...(browserSdk ? [{
|
|
947
942
|
prefix: "/mcp/browser",
|
|
@@ -958,11 +953,6 @@ export class MachineHost {
|
|
|
958
953
|
protocol: "mcp-json-rpc",
|
|
959
954
|
handle: (body) => toolsManagement.handle(body),
|
|
960
955
|
}] : []),
|
|
961
|
-
{
|
|
962
|
-
prefix: "/mcp/share",
|
|
963
|
-
protocol: "mcp-json-rpc",
|
|
964
|
-
handle: (body) => shareMcp.handle(body),
|
|
965
|
-
},
|
|
966
956
|
...(channelsMcp ? [{
|
|
967
957
|
prefix: "/mcp/channels",
|
|
968
958
|
protocol: "mcp-json-rpc",
|
|
@@ -1008,14 +998,6 @@ export class MachineHost {
|
|
|
1008
998
|
throw new Error("runtime gateway did not bind a TCP port");
|
|
1009
999
|
await this.groundHost?.activateRuntimeTunnel(address.port, runtimeToken);
|
|
1010
1000
|
products?.runner.start();
|
|
1011
|
-
const automations = products?.automations;
|
|
1012
|
-
if (automations && installedAutomations) {
|
|
1013
|
-
this.backgroundStage("installed-automations", () => installedAutomations.reconcile(automations, computerId));
|
|
1014
|
-
}
|
|
1015
|
-
// Apps the machine keeps running come back with the runtime: boot adopts
|
|
1016
|
-
// live processes, relaunches the rest, and advertises their routes.
|
|
1017
|
-
if (appsSdk)
|
|
1018
|
-
this.backgroundStage("apps", () => selectedAppsMcp().apps.boot());
|
|
1019
1001
|
commandPublication = {
|
|
1020
1002
|
instanceId: runtimeIdentity.instanceId,
|
|
1021
1003
|
userRoot: this.paths(userEmail).userRoot,
|