@parcha/agentrun-computer 0.1.0-beta.41 → 0.1.0-beta.42
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/NOTICE +2 -0
- package/README.md +254 -14
- package/box/README.md +2 -2
- package/box/build-e2b.mjs +1 -1
- package/dist/box-image.d.ts +1 -3
- package/dist/box-image.js +1 -11
- package/dist/boxd.d.ts +126 -0
- package/dist/boxd.js +418 -0
- package/dist/cloudflare.d.ts +32 -0
- package/dist/cloudflare.js +179 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/boxd.d.ts +77 -0
- package/dist/conformance/boxd.js +113 -0
- package/dist/conformance/cases/isolation.js +1 -17
- package/dist/conformance/cloudflare.d.ts +42 -0
- package/dist/conformance/cloudflare.js +54 -0
- package/dist/conformance/dial-only.d.ts +6 -0
- package/dist/conformance/dial-only.js +9 -0
- package/dist/conformance/e2b.d.ts +12 -3
- package/dist/conformance/e2b.js +21 -4
- package/dist/conformance/fly.d.ts +52 -0
- package/dist/conformance/fly.js +52 -0
- package/dist/conformance/modal.d.ts +15 -2
- package/dist/conformance/modal.js +36 -3
- package/dist/conformance/morph.d.ts +59 -0
- package/dist/conformance/morph.js +95 -0
- package/dist/conformance/phone-harness.js +2 -2
- package/dist/conformance/runner.js +3 -3
- package/dist/conformance/sweep.d.ts +1 -6
- package/dist/conformance/sweep.js +8 -18
- package/dist/descriptors/boxd.d.ts +52 -0
- package/dist/descriptors/boxd.js +29 -0
- package/dist/descriptors/cloudflare.d.ts +21 -0
- package/dist/descriptors/cloudflare.js +29 -0
- package/dist/descriptors/e2b.d.ts +4 -0
- package/dist/descriptors/e2b.js +3 -0
- package/dist/descriptors/fly.d.ts +19 -0
- package/dist/descriptors/fly.js +28 -0
- package/dist/descriptors/index.d.ts +113 -1
- package/dist/descriptors/index.js +7 -2
- package/dist/descriptors/modal.d.ts +3 -0
- package/dist/descriptors/modal.js +7 -2
- package/dist/descriptors/morph.d.ts +15 -0
- package/dist/descriptors/morph.js +21 -0
- package/dist/descriptors/phone-harness.d.ts +1 -0
- package/dist/descriptors/phone-harness.js +2 -0
- package/dist/e2b.d.ts +7 -1
- package/dist/e2b.js +87 -44
- package/dist/fly.d.ts +43 -0
- package/dist/fly.js +245 -0
- package/dist/host.d.ts +8 -28
- package/dist/hosted/process.d.ts +19 -0
- package/dist/hosted/process.js +28 -0
- package/dist/hosted/provider.d.ts +11 -22
- package/dist/hosted/provider.js +30 -201
- package/dist/hosted/scripts.d.ts +2 -8
- package/dist/hosted/scripts.js +2 -22
- package/dist/hosted/ssh-exec.d.ts +2 -1
- package/dist/hosted/ssh-exec.js +58 -2
- package/dist/hosted/values.d.ts +5 -0
- package/dist/hosted/values.js +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/modal.d.ts +6 -0
- package/dist/modal.js +20 -10
- package/dist/morph.d.ts +65 -0
- package/dist/morph.js +495 -0
- package/dist/phone-harness.d.ts +15 -5
- package/dist/phone-harness.js +50 -15
- package/dist/screen-watch.js +2 -2
- package/package.json +20 -2
package/dist/hosted/provider.js
CHANGED
|
@@ -12,7 +12,6 @@ import { resolve } from "node:path";
|
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
13
|
import { isDeepStrictEqual } from "node:util";
|
|
14
14
|
import { ATTACH_PATH, DAEMON_PATH } from "../attach.js";
|
|
15
|
-
import { isBoxImage } from "../box-image.js";
|
|
16
15
|
import { CreateRequests, endedWords, otherSpecWords, readBackDiffer } from "../create-requests.js";
|
|
17
16
|
import { desktopOf, startDisplay } from "../desktop.js";
|
|
18
17
|
import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, show, WORK } from "../drift.js";
|
|
@@ -27,10 +26,10 @@ import { failFor, ok } from "../result.js";
|
|
|
27
26
|
import { daemonWatch } from "../screen-watch.js";
|
|
28
27
|
import { countTested } from "../test-connection.js";
|
|
29
28
|
import { waitUntil } from "../wait.js";
|
|
30
|
-
import { bounded, CALL_SLACK_MS, hostCall,
|
|
29
|
+
import { bounded, CALL_SLACK_MS, hostCall, openBridge, pause, rootOf, runToExit, seconds, uploadThroughExec, words } from "./process.js";
|
|
31
30
|
import { isWhole, PACKED_NAME, packLabels, unpackLabels } from "./values.js";
|
|
32
31
|
import { EGRESS_POLICY, EGRESS_PROXY_USER, EGRESS_RELAY, HOSTED_ALLOW, NETWORK_LABEL, networkFormOf, networkOfForm, networkRefusal, throughProxy } from "./network.js";
|
|
33
|
-
import { ARCHIL_GATE, closedSocketsOf, daemonDrift, hostedCommands, initFlags, installerOf
|
|
32
|
+
import { ARCHIL_GATE, closedSocketsOf, daemonDrift, hostedCommands, initFlags, installerOf } from "./scripts.js";
|
|
34
33
|
const VERSION = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
|
|
35
34
|
export const NAME_LABEL = `${COMPUTER_LABEL}.name`;
|
|
36
35
|
/** The image create was asked for: a vendor may report another name for it (a template's id). */
|
|
@@ -68,12 +67,6 @@ const LISTED_POLL_MS = 150;
|
|
|
68
67
|
const LISTED_ROUNDS = 2;
|
|
69
68
|
const LISTEN_RETRY_MS = 250;
|
|
70
69
|
const START_POLL_MS = 500;
|
|
71
|
-
/**
|
|
72
|
-
* With labels kept in the machine: what a machine of a request's name with no label file must be older than, past the
|
|
73
|
-
* longest a create takes to write the file (#unfiledMs), before a sweep of the name takes it: another instance's longer
|
|
74
|
-
* timeouts, and the vendor's clock against this one's.
|
|
75
|
-
*/
|
|
76
|
-
const UNFILED_MARGIN_MS = 300_000;
|
|
77
70
|
/**
|
|
78
71
|
* The computerd build a hosted machine of arch runs: HostedProvider's default daemonPath, and the file serve's daemon
|
|
79
72
|
* route serves, so the sha256 a dial machine checks (AGENTRUN_DAEMON_SHA256) is this file's.
|
|
@@ -108,7 +101,7 @@ const REFUSED_CREATE = new Set(["invalid", "denied", "limit", "not_found", "refu
|
|
|
108
101
|
* nothing: a machine under the name then is another's (exists: another instance's create of the request), never
|
|
109
102
|
* deleted. Any other failure (the vendor's, a timeout) may have made one, answered in time or after create gave up.
|
|
110
103
|
*/
|
|
111
|
-
const mayHaveMade = (code) => !REFUSED_CREATE.has(code);
|
|
104
|
+
export const mayHaveMade = (code) => !REFUSED_CREATE.has(code);
|
|
112
105
|
/** An ISO time a label holds, or undefined when it is missing or not the ISO time create writes. */
|
|
113
106
|
export function isoOf(written) {
|
|
114
107
|
const at = written === undefined ? Number.NaN : Date.parse(written);
|
|
@@ -175,8 +168,6 @@ export class HostedProvider {
|
|
|
175
168
|
#uid;
|
|
176
169
|
#gid;
|
|
177
170
|
#timeouts;
|
|
178
|
-
/** What foundBy reads with: the timeouts, onNote, which hears of a machine a listing leaves out, and the image option. */
|
|
179
|
-
#finding;
|
|
180
171
|
#probeTargets;
|
|
181
172
|
#onNote;
|
|
182
173
|
#archilEgress;
|
|
@@ -188,7 +179,7 @@ export class HostedProvider {
|
|
|
188
179
|
/** A dial host's server: what its machines reach, and what holds their tokens and sockets. */
|
|
189
180
|
#dial;
|
|
190
181
|
constructor(host, options) {
|
|
191
|
-
const { kind = "linux", desktop = {}, maxLifetimeMs = host.facts.maxLifetimeMs, daemonPath = hostedDaemonPath(host.facts.arch), daemonUser = TOOL_USER, timeouts = {}, probeTargets = DEFAULT_PROBE_TARGETS, onNote, archilEgress,
|
|
182
|
+
const { kind = "linux", desktop = {}, maxLifetimeMs = host.facts.maxLifetimeMs, daemonPath = hostedDaemonPath(host.facts.arch), daemonUser = TOOL_USER, timeouts = {}, probeTargets = DEFAULT_PROBE_TARGETS, onNote, archilEgress, } = options;
|
|
192
183
|
const { id, label, capabilities } = host.descriptor;
|
|
193
184
|
if (kind !== "desktop" && kind !== "linux")
|
|
194
185
|
throw new Error(`kind is desktop or linux, not ${String(kind)}`);
|
|
@@ -207,21 +198,11 @@ export class HostedProvider {
|
|
|
207
198
|
}
|
|
208
199
|
if (host.facts.connect === "dial") {
|
|
209
200
|
// Every connection goes over the socket the machine dials: nothing reaches into it from here.
|
|
210
|
-
if (host.facts.labels === "machine")
|
|
211
|
-
throw new Error(`${label}'s machines dial this server (facts.connect "dial") and keep no labels (facts.labels "machine"), which are read through exec: keep its labels in vendor tags or packed`);
|
|
212
201
|
if (host.exec || host.upload)
|
|
213
202
|
throw new Error(`${label}'s machines dial this server (facts.connect "dial"), so its host has no exec and no upload: leave them out`);
|
|
214
203
|
if (kind === "desktop")
|
|
215
204
|
throw new Error(`${label}'s machines dial this server (facts.connect "dial"), and agentrun-dial starts init with no display: make it kind linux`);
|
|
216
205
|
}
|
|
217
|
-
// A machine whose create was cut off before its labels were written carries none the janitor lists: only the vendor's
|
|
218
|
-
// timer ends it. And the most a computer may live, which bounds an extend, would be read from inside the machine.
|
|
219
|
-
if (host.facts.labels === "machine" && host.facts.lifetime !== "vendor") {
|
|
220
|
-
throw new Error(`${label} keeps no labels (facts.labels "machine"), so its vendor's timer must end its machines: a machine whose create stopped before its labels were written has none the janitor lists. Declare lifetime "vendor"`);
|
|
221
|
-
}
|
|
222
|
-
if (host.facts.labels === "machine" && host.extend) {
|
|
223
|
-
throw new Error(`${label} keeps no labels (facts.labels "machine") and has extend: the most a computer may live, which bounds an extend, would be read from a file inside the machine. Leave extend out: its computers end at the deadline create gave them`);
|
|
224
|
-
}
|
|
225
206
|
const user = USER.exec(daemonUser);
|
|
226
207
|
if (user === null || Number(user[1]) > MAX_ID || Number(user[2]) > MAX_ID)
|
|
227
208
|
throw new Error(`the daemon user ${daemonUser} must be uid:gid in numbers, such as 1000:1000`);
|
|
@@ -246,9 +227,6 @@ export class HostedProvider {
|
|
|
246
227
|
this.#maxLifetimeMs = maxLifetimeMs;
|
|
247
228
|
[this.#uid, this.#gid] = [String(Number(user[1])), String(Number(user[2]))];
|
|
248
229
|
this.#timeouts = merged;
|
|
249
|
-
if (image !== undefined && (typeof image !== "string" || image === ""))
|
|
250
|
-
throw new Error(`image names the image this provider's computers start from, not ${JSON.stringify(image)}`);
|
|
251
|
-
this.#finding = { ...merged, onNote, image };
|
|
252
230
|
this.#probeTargets = [...probeTargets];
|
|
253
231
|
this.#dial = host.facts.connect === "dial" ? options.dial : undefined;
|
|
254
232
|
// Extend only where the end can follow it: the host moves its timer or its deadline label.
|
|
@@ -312,10 +290,6 @@ export class HostedProvider {
|
|
|
312
290
|
}
|
|
313
291
|
if (typeof image !== "string" || image === "" || image.includes("\0"))
|
|
314
292
|
refuse("image", `an image is required: the name of ${a(label)} image`);
|
|
315
|
-
else if (this.#keeps && !ourImage({ image }, this.#finding.image)) {
|
|
316
|
-
// list reads labels only in a machine of our image, so a computer of another would never be found again.
|
|
317
|
-
refuse("image", `${a(label)} computer keeps its labels inside the machine, and list reads them only in one of this provider's image option or a box image, so ${image} is refused: ${this.#finding.image === undefined ? "ask for a box image" : `ask for ${this.#finding.image} or a box image`}`);
|
|
318
|
-
}
|
|
319
293
|
refusals.push(...checkTenure(given, capabilities, label));
|
|
320
294
|
// Only the forms the descriptor declares, each one this computer enforces; any other is refused, never widened.
|
|
321
295
|
const networkProblem = networkRefusal(label, capabilities.network, network);
|
|
@@ -400,44 +374,6 @@ export class HostedProvider {
|
|
|
400
374
|
dial.hub.revoke(name, `${name} was deleted`);
|
|
401
375
|
}
|
|
402
376
|
}
|
|
403
|
-
/** Whether the host keeps no labels (facts.labels "machine"): the adapter keeps them in the machine, at LABEL_FILE. */
|
|
404
|
-
get #keeps() {
|
|
405
|
-
return this.host.facts.labels === "machine";
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* The longest a create takes from the vendor's create to the label file: its own call and the wait for the machine to
|
|
409
|
-
* run (createMs each), the listing of the name between them (listMs, and a read), and the file's write (execMs), plus
|
|
410
|
-
* UNFILED_MARGIN_MS.
|
|
411
|
-
*/
|
|
412
|
-
get #unfiledMs() {
|
|
413
|
-
const { createMs, listMs, requestMs, execMs } = this.#timeouts;
|
|
414
|
-
return 2 * createMs + listMs + requestMs + execMs + UNFILED_MARGIN_MS;
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* With labels kept in the machine, a machine with no label file is the request's whose name it has (Machine.name, the
|
|
418
|
-
* request's own name, never a bare computer- prefix), and a sweep of the name takes it only once it is older than
|
|
419
|
-
* #unfiledMs: before that, another instance's create of the request may still be writing its file (provider.md,
|
|
420
|
-
* Idempotent create). A machine with no createdAt is never old enough: the vendor's timer ends it.
|
|
421
|
-
*/
|
|
422
|
-
#unfiled(machine, name) {
|
|
423
|
-
if (!this.#keeps || machine.labels[COMPUTER_LABEL] !== undefined || machine.name !== name)
|
|
424
|
-
return undefined;
|
|
425
|
-
const age = machine.createdAt instanceof Date ? Date.now() - machine.createdAt.getTime() : Number.NaN;
|
|
426
|
-
return age > this.#unfiledMs ? "old" : "young";
|
|
427
|
-
}
|
|
428
|
-
/** Writes labels to the machine's label file, root's alone, and answers them as the file reads back. */
|
|
429
|
-
async #keep(ref, labels, signal) {
|
|
430
|
-
const what = `writing ${ref.name}'s labels to ${LABEL_FILE}`;
|
|
431
|
-
const json = Buffer.from(JSON.stringify(labels));
|
|
432
|
-
const wrote = await runToExit(this.host, ref.id, labelsCommand(json.length), { stdin: [json], ms: this.#timeouts.execMs, ...(signal ? { signal } : {}), what });
|
|
433
|
-
if (!wrote.ok)
|
|
434
|
-
return wrote;
|
|
435
|
-
const read = wrote.value.exitCode === 0 ? labelMapOf(wrote.value.stdout) : undefined;
|
|
436
|
-
if (read === undefined)
|
|
437
|
-
return this.#fail("refused", `${what} failed (exit ${wrote.value.exitCode}): ${`${wrote.value.stdout} ${wrote.value.stderr}`.trim().slice(0, 300)}`);
|
|
438
|
-
filedOf(this.host).set(ref.id, read);
|
|
439
|
-
return ok(read);
|
|
440
|
-
}
|
|
441
377
|
/** Whether the host takes a spec's user (facts.user): then a computer's daemon runs as the one a spec names. */
|
|
442
378
|
get #takesUser() {
|
|
443
379
|
return this.host.facts.user !== undefined;
|
|
@@ -452,18 +388,12 @@ export class HostedProvider {
|
|
|
452
388
|
* they fit.
|
|
453
389
|
*/
|
|
454
390
|
#labelsOver(spec) {
|
|
455
|
-
const
|
|
391
|
+
const { count, bytes: max, packed } = this.host.facts.labels ?? {};
|
|
456
392
|
// Stand-ins as long as create's name and deadlines and as mixed, fixed so a spec's answer never changes (attach and a
|
|
457
393
|
// retry check the spec again): a packed map deflates them as it does create's, give or take a byte, and create packs
|
|
458
394
|
// its own before the host's call (#stored).
|
|
459
395
|
const name = "computer-5f3a9c1e7b2d";
|
|
460
396
|
const labels = this.#labelsOf(spec, name, "2026-11-16T04:15:29.481Z", "2026-11-17T04:05:29.481Z");
|
|
461
|
-
if (room === "machine") {
|
|
462
|
-
// The label file is read back whole only up to what a run keeps of its output.
|
|
463
|
-
const json = Buffer.byteLength(JSON.stringify(labels));
|
|
464
|
-
return json <= OUTPUT_MAX ? undefined : { bytes: true, why: `${a(this.#label)} computer keeps its labels in the machine, at most ${OUTPUT_MAX} bytes as JSON, and this computer's would come to ${json}: ${shorterWords(labels)}` };
|
|
465
|
-
}
|
|
466
|
-
const { count, bytes: max, packed } = room;
|
|
467
397
|
if (packed) {
|
|
468
398
|
const fit = this.#stored(labels, name);
|
|
469
399
|
return "problem" in fit ? { bytes: true, why: fit.problem } : undefined;
|
|
@@ -562,15 +492,10 @@ export class HostedProvider {
|
|
|
562
492
|
}
|
|
563
493
|
/** taken: the vendor refused this create's name as one a machine has (exists), so the name's machine is read once more. */
|
|
564
494
|
async #createOnce(spec, name, signal, taken) {
|
|
565
|
-
const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#
|
|
495
|
+
const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#timeouts, signal);
|
|
566
496
|
if (!listed.ok)
|
|
567
497
|
return listed;
|
|
568
|
-
|
|
569
|
-
// (#again waits for its labels); an old one never got them, and is deleted.
|
|
570
|
-
const found = listed.value.filter((machine) => ours(machine.labels, name) || this.#unfiled(machine, name) === "young");
|
|
571
|
-
if (found.length === 0 && listed.value.some((machine) => this.#unfiled(machine, name) === "old")) {
|
|
572
|
-
return this.#fail("exists", `${name} was made for this request and its labels were never written: create with a new request id${await this.#deleteNamed(name)}`);
|
|
573
|
-
}
|
|
498
|
+
const found = listed.value.filter((machine) => ours(machine.labels, name));
|
|
574
499
|
if (found.length > 1)
|
|
575
500
|
return this.#fail("exists", `${found.length} machines carry the name ${name} (${found.map((m) => m.id).join(", ")}): create with a new request id`);
|
|
576
501
|
if (found.length === 1)
|
|
@@ -616,7 +541,7 @@ export class HostedProvider {
|
|
|
616
541
|
* same listing. Its value is the machine kept, or undefined when mine holds the name alone (or nothing is listed yet).
|
|
617
542
|
*/
|
|
618
543
|
async #converge(name, mine, signal) {
|
|
619
|
-
const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#
|
|
544
|
+
const listed = await foundBy(this.host, "the listing by the request's name", byName(name), this.#timeouts, signal);
|
|
620
545
|
if (!listed.ok)
|
|
621
546
|
return listed;
|
|
622
547
|
const holders = listed.value.filter((machine) => ours(machine.labels, name) && alive(machine.state));
|
|
@@ -654,11 +579,7 @@ export class HostedProvider {
|
|
|
654
579
|
const deadline = deadlineOf(machine);
|
|
655
580
|
if (deadline !== undefined && deadline.getTime() <= Date.now())
|
|
656
581
|
return this.#fail("exists", endedWords(name));
|
|
657
|
-
|
|
658
|
-
const unwritten = machine.state === "running" && this.#unfiled(machine, name) !== undefined;
|
|
659
|
-
if (unwritten)
|
|
660
|
-
last = { code: "refused", message: "has no labels written" };
|
|
661
|
-
if (machine.state === "running" && !unwritten) {
|
|
582
|
+
if (machine.state === "running") {
|
|
662
583
|
const differ = this.#labelDiffer(spec, name, machine.labels, "read back");
|
|
663
584
|
if (differ.length > 0)
|
|
664
585
|
return this.#fail("exists", otherSpecWords(name, "was made", differ));
|
|
@@ -831,55 +752,44 @@ export class HostedProvider {
|
|
|
831
752
|
* Every machine carrying a name create gave, deleted and read back gone: for a create that may have made one whose
|
|
832
753
|
* id never came (mayHaveMade), never after a refusal, where a machine under the name is another's. The
|
|
833
754
|
* listing shows a new machine a moment after the vendor makes it, so it is read for the name until one shows or
|
|
834
|
-
* listedMs passes, as create's own wait reads it.
|
|
835
|
-
* only once it is old (#unfiled). Best effort, in words.
|
|
755
|
+
* listedMs passes, as create's own wait reads it. Best effort, in words.
|
|
836
756
|
*/
|
|
837
757
|
async #deleteNamed(name) {
|
|
838
758
|
const { listedMs, pollMs } = this.#timeouts;
|
|
839
759
|
const until = Date.now() + listedMs;
|
|
840
|
-
let
|
|
760
|
+
let found;
|
|
841
761
|
for (let delay = Math.min(LISTED_POLL_MS, pollMs);; delay = Math.min(delay * 2, pollMs)) {
|
|
842
|
-
const listed = await foundBy(this.host, "the listing by name", byName(name), this.#
|
|
762
|
+
const listed = await foundBy(this.host, "the listing by name", byName(name), this.#timeouts);
|
|
843
763
|
if (!listed.ok)
|
|
844
764
|
return `; a machine named ${name} may be left (${listed.error.message}), which ends at its deadline`;
|
|
845
|
-
|
|
846
|
-
if (
|
|
765
|
+
found = listed.value.filter((machine) => ours(machine.labels, name));
|
|
766
|
+
if (found.length > 0 || Date.now() >= until)
|
|
847
767
|
break;
|
|
848
768
|
await pause(Math.min(delay, until - Date.now()));
|
|
849
769
|
}
|
|
850
|
-
const found = named.filter((machine) => this.#unfiled(machine, name) !== "young");
|
|
851
|
-
const young = named.length - found.length;
|
|
852
|
-
const left = young === 0 ? "" : `; ${young} machine${young === 1 ? "" : "s"} named ${name} with no labels written yet, younger than ${seconds(this.#unfiledMs)}, left: another create of this request may still be making it`;
|
|
853
|
-
if (named.length === 0)
|
|
854
|
-
return `; no machine named ${name} was listed within ${seconds(listedMs)}, and any it made ends at its deadline`;
|
|
855
770
|
if (found.length === 0)
|
|
856
|
-
return
|
|
771
|
+
return `; no machine named ${name} was listed within ${seconds(listedMs)}, and any it made ends at its deadline`;
|
|
857
772
|
const said = [];
|
|
858
773
|
for (const machine of found) {
|
|
859
774
|
const { gone } = await this.#remove({ id: machine.id, name }, undefined);
|
|
860
775
|
said.push(gone.ok ? `${machine.id} was deleted and read back gone` : `${machine.id} may be left (${gone.error.message}), which ends at its deadline`);
|
|
861
776
|
}
|
|
862
|
-
return `; the machine named ${name} it made: ${said.join("; ")}
|
|
777
|
+
return `; the machine named ${name} it made: ${said.join("; ")}`;
|
|
863
778
|
}
|
|
864
779
|
/** The host's delete, never signalled: a delete that cleans up after an abort must outlive it. Not found is done. */
|
|
865
780
|
async #kill(id) {
|
|
866
781
|
const killed = await this.#call(`the delete of ${id}`, (ctx) => this.host.delete(id, ctx), this.#timeouts.requestMs);
|
|
867
782
|
if (!killed.ok && killed.error.code !== "not_found")
|
|
868
783
|
return killed;
|
|
869
|
-
filedOf(this.host).delete(id);
|
|
870
784
|
return ok(undefined);
|
|
871
785
|
}
|
|
872
786
|
/** The pause between two reads of a machine that is starting: the next read comes after it, within createMs. */
|
|
873
787
|
#startPollMs() {
|
|
874
788
|
return Math.min(START_POLL_MS, this.#timeouts.pollMs * 10);
|
|
875
789
|
}
|
|
876
|
-
/**
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
*/
|
|
880
|
-
async #get(id, signal) {
|
|
881
|
-
const read = await readMachine(this.host, id, this.#timeouts.requestMs, signal);
|
|
882
|
-
return read.ok ? labelled(this.host, read.value, this.#timeouts.requestMs, signal, false) : read;
|
|
790
|
+
/** The host's get, bounded by requestMs; a machine the vendor reports as not found is none. */
|
|
791
|
+
#get(id, signal) {
|
|
792
|
+
return readMachine(this.host, id, this.#timeouts.requestMs, signal);
|
|
883
793
|
}
|
|
884
794
|
/** The machine running, read while it starts (within createMs); gone or failed is refused in words. */
|
|
885
795
|
async #running(ref, signal) {
|
|
@@ -926,11 +836,7 @@ export class HostedProvider {
|
|
|
926
836
|
const running = await this.#running(ref, signal);
|
|
927
837
|
if (!running.ok)
|
|
928
838
|
return running;
|
|
929
|
-
|
|
930
|
-
const kept = this.#keeps ? await this.#keep(ref, labels, signal) : ok(running.value.labels);
|
|
931
|
-
if (!kept.ok)
|
|
932
|
-
return kept;
|
|
933
|
-
const drift = this.#machineDrift({ ...running.value, labels: kept.value }, labels);
|
|
839
|
+
const drift = this.#machineDrift(running.value, labels);
|
|
934
840
|
if (drift.length > 0)
|
|
935
841
|
return this.#fail("refused", `it did not match its spec: ${drift.join("; ")}`);
|
|
936
842
|
const gpu = spec.gpu !== undefined;
|
|
@@ -1389,9 +1295,7 @@ export class HostedProvider {
|
|
|
1389
1295
|
*/
|
|
1390
1296
|
async testConnection({ signal } = {}) {
|
|
1391
1297
|
const listed = await listedBy(this.host, "the listing", { [COMPUTER_LABEL]: "1" }, this.#timeouts.listMs, signal);
|
|
1392
|
-
|
|
1393
|
-
const keptOurs = (machine) => ourImage(machine, this.#finding.image) && (machine.name === undefined || NAME.test(machine.name));
|
|
1394
|
-
const counted = (machine) => (this.#keeps ? keptOurs(machine) : ours(machine.labels)) && alive(machine.state);
|
|
1298
|
+
const counted = (machine) => ours(machine.labels) && alive(machine.state);
|
|
1395
1299
|
return countTested(this.#label, listed.ok ? ok({ count: listed.value.filter(counted).length }) : listed);
|
|
1396
1300
|
}
|
|
1397
1301
|
/**
|
|
@@ -1404,7 +1308,7 @@ export class HostedProvider {
|
|
|
1404
1308
|
if (problem)
|
|
1405
1309
|
return this.#fail("invalid", problem);
|
|
1406
1310
|
const { listMs } = this.#timeouts;
|
|
1407
|
-
const listed = await foundBy(this.host, "the listing", { ...labels, [COMPUTER_LABEL]: "1" }, this.#
|
|
1311
|
+
const listed = await foundBy(this.host, "the listing", { ...labels, [COMPUTER_LABEL]: "1" }, this.#timeouts, signal);
|
|
1408
1312
|
if (!listed.ok)
|
|
1409
1313
|
return listed.error.code === "timeout" ? this.#fail("timeout", `list did not finish within ${seconds(listMs)}: ${listed.error.message}`) : listed;
|
|
1410
1314
|
const infos = [];
|
|
@@ -1613,113 +1517,38 @@ const byName = (name) => ({ [COMPUTER_LABEL]: "1", [NAME_LABEL]: name });
|
|
|
1613
1517
|
/** The room of a host that keeps its labels packed (facts.labels.packed), or undefined. */
|
|
1614
1518
|
function packedRoom(host) {
|
|
1615
1519
|
const room = host.facts.labels;
|
|
1616
|
-
return room
|
|
1520
|
+
return room?.packed ? room : undefined;
|
|
1617
1521
|
}
|
|
1618
1522
|
/** A machine as the host read it, with a packed host's labels unpacked: none where it holds no packed map (not the adapter's). */
|
|
1619
1523
|
const unpacked = (host, machine) => (packedRoom(host) === undefined ? machine : { ...machine, labels: unpackLabels(machine.labels) ?? {} });
|
|
1620
1524
|
/**
|
|
1621
1525
|
* The host's listing by labels, bounded by ms: only the machines that carry every one of them, since a vendor's listing
|
|
1622
1526
|
* may answer more (MachineHost.list). A packed host is asked for PACKED_NAME alone, the name's where one is asked, and
|
|
1623
|
-
* its machines' labels unpacked.
|
|
1624
|
-
* left out, and the rest kept for foundBy to read.
|
|
1527
|
+
* its machines' labels unpacked.
|
|
1625
1528
|
*/
|
|
1626
1529
|
export async function listedBy(host, what, labels, ms, signal) {
|
|
1627
1530
|
const name = labels[NAME_LABEL];
|
|
1628
1531
|
const asked = packedRoom(host) === undefined ? labels : name === undefined ? {} : { [PACKED_NAME]: name };
|
|
1629
1532
|
const listed = await hostCall(host, what, (ctx) => host.list(asked, ctx), ms, signal);
|
|
1630
|
-
|
|
1631
|
-
return listed.ok ? ok(listed.value.map((machine) => unpacked(host, machine)).filter(keeps)) : listed;
|
|
1632
|
-
}
|
|
1633
|
-
/** Whether a machine's image is ours: the provider's image option, or a box image by its name rule (isBoxImage). */
|
|
1634
|
-
const ourImage = (machine, image) => machine.image !== undefined && (machine.image === image || isBoxImage(machine.image));
|
|
1635
|
-
/** With labels kept in the machine: each machine's label map as its file was last read, by host and machine id. */
|
|
1636
|
-
const filed = new WeakMap();
|
|
1637
|
-
function filedOf(host) {
|
|
1638
|
-
let known = filed.get(host);
|
|
1639
|
-
if (known === undefined)
|
|
1640
|
-
filed.set(host, (known = new Map()));
|
|
1641
|
-
return known;
|
|
1642
|
-
}
|
|
1643
|
-
/** A label file's JSON as a label map, or undefined where it is not one. */
|
|
1644
|
-
function labelMapOf(text) {
|
|
1645
|
-
try {
|
|
1646
|
-
const map = JSON.parse(text);
|
|
1647
|
-
return typeof map === "object" && map !== null && !Array.isArray(map) && Object.values(map).every((value) => typeof value === "string") ? map : undefined;
|
|
1648
|
-
}
|
|
1649
|
-
catch {
|
|
1650
|
-
return undefined;
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
/**
|
|
1654
|
-
* A machine of a host that keeps labels in the machine, with the labels its file holds: read through exec while it runs
|
|
1655
|
-
* (fresh), within ms, else as last read, or none. No file (exit 3) is none; a read that fails otherwise, or does not end
|
|
1656
|
-
* within ms, is an error, never none (foundBy leaves the machine out of its listing, in words). Another host's machine is
|
|
1657
|
-
* as read.
|
|
1658
|
-
*/
|
|
1659
|
-
async function labelled(host, machine, ms, signal, fresh) {
|
|
1660
|
-
if (host.facts.labels !== "machine" || machine === undefined)
|
|
1661
|
-
return ok(machine);
|
|
1662
|
-
const known = filedOf(host);
|
|
1663
|
-
const held = known.get(machine.id);
|
|
1664
|
-
if (machine.state !== "running" || (held !== undefined && !fresh))
|
|
1665
|
-
return ok({ ...machine, labels: { ...held } });
|
|
1666
|
-
const what = `reading the labels in ${machine.id}`;
|
|
1667
|
-
const read = await runToExit(host, machine.id, labelsCommand(), { ms, ...(signal ? { signal } : {}), what });
|
|
1668
|
-
// Gone since the vendor's read: as a read that finds none.
|
|
1669
|
-
if (!read.ok)
|
|
1670
|
-
return read.error.code === "not_found" ? ok(undefined) : read;
|
|
1671
|
-
if (read.value.exitCode === 3)
|
|
1672
|
-
return ok({ ...machine, labels: {} });
|
|
1673
|
-
const labels = read.value.exitCode === 0 ? labelMapOf(read.value.stdout) : undefined;
|
|
1674
|
-
if (labels === undefined)
|
|
1675
|
-
return failFor(host.descriptor.id)("vendor", `${what} failed (exit ${read.value.exitCode}): ${`${read.value.stdout} ${read.value.stderr}`.trim().slice(0, 300)}`);
|
|
1676
|
-
known.set(machine.id, labels);
|
|
1677
|
-
return ok({ ...machine, labels: { ...labels } });
|
|
1533
|
+
return listed.ok ? ok(listed.value.map((machine) => unpacked(host, machine)).filter((machine) => carries(machine, labels))) : listed;
|
|
1678
1534
|
}
|
|
1679
1535
|
/** Whether a machine carries every one of these labels. */
|
|
1680
1536
|
const carries = (machine, labels) => Object.entries(labels).every(([key, value]) => machine.labels?.[key] === value);
|
|
1681
1537
|
/**
|
|
1682
1538
|
* The listing finds, get answers (MachineHost.list): the machines the host's listing by labels names, each read now by
|
|
1683
|
-
* readMachine, within requestMs
|
|
1684
|
-
*
|
|
1685
|
-
* labels are not written yet. A label file's read that fails or does not end within requestMs leaves its machine out of
|
|
1686
|
-
* this listing alone, told through onNote by its id: one wedged machine never holds up the rest. A listing by a
|
|
1687
|
-
* request's name is the exception: what is left of it may be the request's own, so such a read fails it, as a get that
|
|
1688
|
-
* fails fails the whole. The label file is read only in a machine whose listed image is ours (ourImage): another's is
|
|
1689
|
-
* left out unread, and one that shows no image is left out in words.
|
|
1539
|
+
* readMachine, within requestMs. One the vendor no longer has (not found) is dropped, and so is one whose get carries
|
|
1540
|
+
* not every label. A get that fails fails the whole listing.
|
|
1690
1541
|
*/
|
|
1691
|
-
export async function foundBy(host, what, labels, { listMs, requestMs
|
|
1542
|
+
export async function foundBy(host, what, labels, { listMs, requestMs }, signal) {
|
|
1692
1543
|
const listed = await listedBy(host, what, labels, listMs, signal);
|
|
1693
1544
|
if (!listed.ok)
|
|
1694
1545
|
return listed;
|
|
1695
|
-
const
|
|
1696
|
-
// With labels in the machine, the label read runs only in a machine of our image: never in another's.
|
|
1697
|
-
const readable = (machine) => {
|
|
1698
|
-
if (host.facts.labels !== "machine")
|
|
1699
|
-
return true;
|
|
1700
|
-
if (machine.image === undefined)
|
|
1701
|
-
onNote?.({ computer: machine.id, note: "its vendor record shows no image, so its labels are not read: this listing leaves it out" });
|
|
1702
|
-
return ourImage(machine, image);
|
|
1703
|
-
};
|
|
1704
|
-
const reads = await Promise.all(listed.value.filter(readable).map(async ({ id }) => {
|
|
1705
|
-
const read = await readMachine(host, id, requestMs, signal);
|
|
1706
|
-
if (!read.ok)
|
|
1707
|
-
return read;
|
|
1708
|
-
const inside = await labelled(host, read.value, requestMs, signal, true);
|
|
1709
|
-
// A listing by a request's name is left with machines of that name or of none (listedBy), and either may be the
|
|
1710
|
-
// request's own: one that can't be read fails the listing, so its create never makes a second.
|
|
1711
|
-
if (inside.ok || inside.error.code === "aborted" || name !== undefined)
|
|
1712
|
-
return inside;
|
|
1713
|
-
onNote?.({ computer: id, note: `${inside.error.message}; this listing leaves it out, and the next one reads it again` });
|
|
1714
|
-
return ok(undefined);
|
|
1715
|
-
}));
|
|
1716
|
-
// With labels in the machine, one of the name asked for with none written yet is kept too, for the caller to judge.
|
|
1717
|
-
const unfiled = (machine) => host.facts.labels === "machine" && name !== undefined && machine.name === name && machine.labels[COMPUTER_LABEL] === undefined;
|
|
1546
|
+
const reads = await Promise.all(listed.value.map(({ id }) => readMachine(host, id, requestMs, signal)));
|
|
1718
1547
|
const found = [];
|
|
1719
1548
|
for (const read of reads) {
|
|
1720
1549
|
if (!read.ok)
|
|
1721
1550
|
return read;
|
|
1722
|
-
if (read.value !== undefined &&
|
|
1551
|
+
if (read.value !== undefined && carries(read.value, labels))
|
|
1723
1552
|
found.push(read.value);
|
|
1724
1553
|
}
|
|
1725
1554
|
return ok(found);
|
package/dist/hosted/scripts.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export declare function installerOf(output: string): string | undefined;
|
|
|
7
7
|
export declare const shellCommand: (script: string, args: readonly string[]) => string;
|
|
8
8
|
/** One argv as one shell line, every word but a plain one ("sh", "-c") single-quoted: for a vendor whose exec takes a line. */
|
|
9
9
|
export declare const shellLine: (argv: readonly string[]) => string;
|
|
10
|
+
/** The box image's agentrun-dial (box/install.sh): what a dial machine runs first, from MachineRequest.boot.env. */
|
|
11
|
+
export declare const AGENTRUN_DIAL = "/usr/local/bin/agentrun-dial";
|
|
10
12
|
/** Where start leaves what init writes, root's alone: the words a create that never hears the daemon gives back. */
|
|
11
13
|
export declare const INIT_LOG = "/run/agentrun-init.log";
|
|
12
14
|
/**
|
|
@@ -17,14 +19,6 @@ export declare const INIT_LOG = "/run/agentrun-init.log";
|
|
|
17
19
|
export declare const SESSION_BUSES: readonly string[];
|
|
18
20
|
/** The sockets the sockets script closed, from its `closed <path>` lines. */
|
|
19
21
|
export declare function closedSocketsOf(output: string): string[];
|
|
20
|
-
/**
|
|
21
|
-
* Where a machine of a host that keeps no labels (HostFacts.labels "machine") holds its label map, as JSON. Under
|
|
22
|
-
* /var/lib, on the machine's disk, so it outlives a restart: /run is a tmpfs, and /run/agentrun is the daemon user's.
|
|
23
|
-
* In a directory root's alone (0700), so the computer's user can neither read nor change it.
|
|
24
|
-
*/
|
|
25
|
-
export declare const LABEL_FILE = "/var/lib/agentrun/labels.json";
|
|
26
|
-
/** The label file's read, or given the byte length of the JSON on stdin, its write and then its read. */
|
|
27
|
-
export declare const labelsCommand: (bytes?: number) => string[];
|
|
28
22
|
/**
|
|
29
23
|
* Where a pid1 Archil computer's entrypoint waits for root's word that the run's folder is mounted: beside the daemon,
|
|
30
24
|
* in the directory install makes root's alone before root makes the gate, so no other user can make it early. (A path
|
package/dist/hosted/scripts.js
CHANGED
|
@@ -84,6 +84,8 @@ export const shellCommand = (script, args) => ["sh", "-c", quote(script), "sh",
|
|
|
84
84
|
/** One argv as one shell line, every word but a plain one ("sh", "-c") single-quoted: for a vendor whose exec takes a line. */
|
|
85
85
|
export const shellLine = (argv) => argv.map((word) => (/^[A-Za-z0-9_./:=@%+-]+$/.test(word) ? word : quote(word))).join(" ");
|
|
86
86
|
const argvOf = (script, args) => ["sh", "-c", script, "sh", ...args];
|
|
87
|
+
/** The box image's agentrun-dial (box/install.sh): what a dial machine runs first, from MachineRequest.boot.env. */
|
|
88
|
+
export const AGENTRUN_DIAL = "/usr/local/bin/agentrun-dial";
|
|
87
89
|
/** Where start leaves what init writes, root's alone: the words a create that never hears the daemon gives back. */
|
|
88
90
|
export const INIT_LOG = `${SOCKET_DIR}-init.log`;
|
|
89
91
|
/**
|
|
@@ -143,28 +145,6 @@ export function closedSocketsOf(output) {
|
|
|
143
145
|
}
|
|
144
146
|
/** The last words init wrote to its log, as root; nothing when it wrote none. */
|
|
145
147
|
const LOG_SCRIPT = ["# agentrun-computer: log", "l=$1", ROOT, '$p tail -c 2000 "$l" 2>/dev/null || true'].join("\n");
|
|
146
|
-
/**
|
|
147
|
-
* Where a machine of a host that keeps no labels (HostFacts.labels "machine") holds its label map, as JSON. Under
|
|
148
|
-
* /var/lib, on the machine's disk, so it outlives a restart: /run is a tmpfs, and /run/agentrun is the daemon user's.
|
|
149
|
-
* In a directory root's alone (0700), so the computer's user can neither read nor change it.
|
|
150
|
-
*/
|
|
151
|
-
export const LABEL_FILE = "/var/lib/agentrun/labels.json";
|
|
152
|
-
/**
|
|
153
|
-
* The label file, as root. With write <bytes>, that many bytes of stdin replace it, read by length so no end of stdin
|
|
154
|
-
* is needed: written to a file of its own beside it (two writers never share one) and renamed in, 0600 in a 0700
|
|
155
|
-
* directory, both root's. Then it prints the file; exit 3 when there is none.
|
|
156
|
-
*/
|
|
157
|
-
const LABELS_SCRIPT = [
|
|
158
|
-
"# agentrun-computer: labels",
|
|
159
|
-
"f=$1",
|
|
160
|
-
ROOT,
|
|
161
|
-
'if [ "${2-}" = write ]; then',
|
|
162
|
-
`\t$p sh -c 'umask 077; d=\${0%/*}; mkdir -p "$d" && chown 0:0 "$d" && chmod 700 "$d" && t=$(mktemp "$0.XXXXXX") || exit 5; head -c "$1" >"$t" && [ "$(wc -c <"$t")" -eq "$1" ] && mv -f "$t" "$0" || { rm -f "$t"; exit 5; }' "$f" "$3" || exit 5`,
|
|
163
|
-
"fi",
|
|
164
|
-
`exec $p sh -c '[ -e "$0" ] || exit 3; exec cat "$0"' "$f"`,
|
|
165
|
-
].join("\n");
|
|
166
|
-
/** The label file's read, or given the byte length of the JSON on stdin, its write and then its read. */
|
|
167
|
-
export const labelsCommand = (bytes) => argvOf(LABELS_SCRIPT, [LABEL_FILE, ...(bytes === undefined ? [] : ["write", String(bytes)])]);
|
|
168
148
|
/**
|
|
169
149
|
* A pid1 machine's main process: waits, bounded, for the daemon this create installed to be moved into place executable
|
|
170
150
|
* (the marker beside it, `<daemon>.installed`, holds this create's nonce: a daemon the image had at the path, or one an
|
|
@@ -95,6 +95,7 @@ export declare class SshExec {
|
|
|
95
95
|
/**
|
|
96
96
|
* A private key in the PEM armor ssh2 reads (its parser wants the BEGIN and END lines on lines of their own), or
|
|
97
97
|
* undefined when text is not one. A key pasted into Settings → Computers comes back on one line, since a password
|
|
98
|
-
* field drops line breaks: its body is wrapped again at 70 characters, as ssh-keygen writes it.
|
|
98
|
+
* field drops line breaks: its body is wrapped again at 70 characters, as ssh-keygen writes it. A PKCS#8 key
|
|
99
|
+
* (the PEM label "PRIVATE KEY", Morph's GET /instance/{id}/ssh/key) is converted (fromPkcs8).
|
|
99
100
|
*/
|
|
100
101
|
export declare function pemOf(text: string): string | undefined;
|
package/dist/hosted/ssh-exec.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// the machine's sshd (Agent37's WebSocket tunnel) and as the login the host gives (Agent37's root and key). Every error it throws or
|
|
4
4
|
// rejects with is redacted of the login's secrets. The host's own ssh2 package does the protocol; this package names
|
|
5
5
|
// only the slice it uses (Ssh2Module) and imports nothing at load.
|
|
6
|
+
import { createPrivateKey, randomBytes } from "node:crypto";
|
|
6
7
|
import { PassThrough } from "node:stream";
|
|
7
8
|
import { boundOf, redact } from "./process.js";
|
|
8
9
|
import { PID_WRAPPER, pidKill, pidStderr, shellLine } from "./scripts.js";
|
|
@@ -429,7 +430,8 @@ export class SshExec {
|
|
|
429
430
|
/**
|
|
430
431
|
* A private key in the PEM armor ssh2 reads (its parser wants the BEGIN and END lines on lines of their own), or
|
|
431
432
|
* undefined when text is not one. A key pasted into Settings → Computers comes back on one line, since a password
|
|
432
|
-
* field drops line breaks: its body is wrapped again at 70 characters, as ssh-keygen writes it.
|
|
433
|
+
* field drops line breaks: its body is wrapped again at 70 characters, as ssh-keygen writes it. A PKCS#8 key
|
|
434
|
+
* (the PEM label "PRIVATE KEY", Morph's GET /instance/{id}/ssh/key) is converted (fromPkcs8).
|
|
433
435
|
*/
|
|
434
436
|
export function pemOf(text) {
|
|
435
437
|
const armor = /^-----BEGIN ([A-Z0-9 ]*PRIVATE KEY)-----([\s\S]*?)-----END \1-----$/.exec(text.replace(/\r/g, "").trim());
|
|
@@ -443,5 +445,59 @@ export function pemOf(text) {
|
|
|
443
445
|
const body = lines.join("").replace(/\s+/g, "");
|
|
444
446
|
if (body === "" || !/^[A-Za-z0-9+/=]+$/.test(body))
|
|
445
447
|
return undefined;
|
|
446
|
-
|
|
448
|
+
const pem = armored(label, Buffer.from(body, "base64"));
|
|
449
|
+
return label === "PRIVATE KEY" ? fromPkcs8(pem) : pem;
|
|
450
|
+
}
|
|
451
|
+
/** bytes as base64 between BEGIN and END lines of label, 70 characters a line. */
|
|
452
|
+
function armored(label, bytes) {
|
|
453
|
+
return `-----BEGIN ${label}-----\n${bytes.toString("base64").match(/.{1,70}/g)?.join("\n")}\n-----END ${label}-----\n`;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* A PKCS#8 key as the same key in a form ssh2 reads, or undefined for a body node:crypto can't read or a type SSH has
|
|
457
|
+
* no use for here. ssh2 reads OpenSSH's own form, PKCS#1 RSA, SEC1 EC, DSA and PuTTY's, never PKCS#8 (ssh2@1.17.0
|
|
458
|
+
* lib/protocol/keyParser.js parseKey: no parser matches, "Unsupported key format"). node:crypto writes RSA as PKCS#1 and
|
|
459
|
+
* EC as SEC1; Ed25519 it writes only as PKCS#8, and ssh2 reads Ed25519 only in OpenSSH's form, so openSshEd25519 writes it.
|
|
460
|
+
*/
|
|
461
|
+
function fromPkcs8(pem) {
|
|
462
|
+
let key;
|
|
463
|
+
try {
|
|
464
|
+
key = createPrivateKey(pem);
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
return undefined;
|
|
468
|
+
}
|
|
469
|
+
if (key.asymmetricKeyType === "rsa")
|
|
470
|
+
return key.export({ type: "pkcs1", format: "pem" });
|
|
471
|
+
if (key.asymmetricKeyType === "ec")
|
|
472
|
+
return key.export({ type: "sec1", format: "pem" });
|
|
473
|
+
if (key.asymmetricKeyType === "ed25519")
|
|
474
|
+
return openSshEd25519(key);
|
|
475
|
+
return undefined;
|
|
476
|
+
}
|
|
477
|
+
/** An SSH string (RFC 4251 §5): its uint32 length, then its bytes. */
|
|
478
|
+
const sshString = (bytes) => {
|
|
479
|
+
const body = Buffer.from(bytes);
|
|
480
|
+
const length = Buffer.alloc(4);
|
|
481
|
+
length.writeUInt32BE(body.length);
|
|
482
|
+
return Buffer.concat([length, body]);
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* An Ed25519 private key in OpenSSH's own format, unencrypted (openssh-portable PROTOCOL.key; sshkey.c writes it so):
|
|
486
|
+
* "openssh-key-v1\0", cipher "none", KDF "none", empty KDF options, the key count 1, the public key blob (RFC 8709 §4:
|
|
487
|
+
* "ssh-ed25519", the 32-byte public key), then the private section as one string: two equal random check words, the
|
|
488
|
+
* key type, the public key, the 64-byte private key (the 32-byte seed, then the public key), an empty comment, and
|
|
489
|
+
* the padding bytes 1, 2, 3, ... to a multiple of 8, the block size of cipher "none".
|
|
490
|
+
*/
|
|
491
|
+
function openSshEd25519(key) {
|
|
492
|
+
const { d, x } = key.export({ format: "jwk" });
|
|
493
|
+
const seed = Buffer.from(d ?? "", "base64url");
|
|
494
|
+
const publicKey = Buffer.from(x ?? "", "base64url");
|
|
495
|
+
const blob = Buffer.concat([sshString("ssh-ed25519"), sshString(publicKey)]);
|
|
496
|
+
const check = randomBytes(4);
|
|
497
|
+
const section = Buffer.concat([check, check, blob, sshString(Buffer.concat([seed, publicKey])), sshString("")]);
|
|
498
|
+
const padding = Buffer.from(Array.from({ length: (8 - (section.length % 8)) % 8 }, (_, index) => index + 1));
|
|
499
|
+
const count = Buffer.alloc(4);
|
|
500
|
+
count.writeUInt32BE(1);
|
|
501
|
+
const body = Buffer.concat([Buffer.from("openssh-key-v1\0", "latin1"), sshString("none"), sshString("none"), sshString(""), count, sshString(blob), sshString(Buffer.concat([section, padding]))]);
|
|
502
|
+
return armored("OPENSSH PRIVATE KEY", body);
|
|
447
503
|
}
|
package/dist/hosted/values.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ import type { ComputerSpec, Refusal } from "../provider.js";
|
|
|
3
3
|
/** A host name, as a vendor's domain option is one: DNS labels and a top-level name of letters. */
|
|
4
4
|
export declare const DOMAIN: RegExp;
|
|
5
5
|
export declare const isWhole: (value: unknown) => value is number;
|
|
6
|
+
/**
|
|
7
|
+
* How a provider that can do both reaches its machines (its descriptor's connect setting): exec (the default), a bridge
|
|
8
|
+
* through the vendor's exec for each connection; dial, the machine's computerd dials the server (HostFacts.connect).
|
|
9
|
+
*/
|
|
10
|
+
export declare function connectOf(value: unknown, label: string): "exec" | "dial";
|
|
6
11
|
/** A vendor whose computer has its image's size: a spec's cpus or memoryMb, refused in words (computer: "an E2B computer"). */
|
|
7
12
|
export declare function sizeRefusals(spec: Partial<ComputerSpec>, computer: string, image: string): Refusal[];
|
|
8
13
|
/** A time the vendor reports: a Date, an ISO string, or a whole number of ms (or seconds); undefined when it is none of them. */
|
package/dist/hosted/values.js
CHANGED
|
@@ -4,6 +4,15 @@ import { deflateRawSync, inflateRawSync } from "node:zlib";
|
|
|
4
4
|
/** A host name, as a vendor's domain option is one: DNS labels and a top-level name of letters. */
|
|
5
5
|
export const DOMAIN = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
|
6
6
|
export const isWhole = (value) => typeof value === "number" && Number.isSafeInteger(value);
|
|
7
|
+
/**
|
|
8
|
+
* How a provider that can do both reaches its machines (its descriptor's connect setting): exec (the default), a bridge
|
|
9
|
+
* through the vendor's exec for each connection; dial, the machine's computerd dials the server (HostFacts.connect).
|
|
10
|
+
*/
|
|
11
|
+
export function connectOf(value, label) {
|
|
12
|
+
if (value === undefined || value === "exec" || value === "dial")
|
|
13
|
+
return value ?? "exec";
|
|
14
|
+
throw new Error(`connect is how ${label} reaches its machines, "exec" (the default) or "dial", not ${JSON.stringify(value)}`);
|
|
15
|
+
}
|
|
7
16
|
/** A vendor whose computer has its image's size: a spec's cpus or memoryMb, refused in words (computer: "an E2B computer"). */
|
|
8
17
|
export function sizeRefusals(spec, computer, image) {
|
|
9
18
|
return ["cpus", "memoryMb"].filter((field) => spec[field] !== undefined).map((field) => ({ field, message: `${computer} has the size of its ${image}: name a ${image} of the size you need, not ${field}` }));
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export { EPOCH_LABEL, epochOf, epochProblem, IDLE_TTL_LABEL, OWNER_LABEL, OWNER_
|
|
|
24
24
|
export { waitUntil, type WaitOptions } from "./wait.js";
|
|
25
25
|
export { type BuiltinProviderId, type ConformanceModule, descriptorOf, isProviderId, type ProviderEnv, providerFor, type ProviderId, providerIds, type ProviderModule, providerModule, type ProviderOptions, providers, } from "./providers.js";
|
|
26
26
|
export { type DescriptorKey, type DescriptorSetting, defineProvider, descriptorProblems, type HostCommand, mountsOf, type ParkedConfiguration, type ProviderDescriptor } from "./descriptor.js";
|
|
27
|
-
export { AGENT37, AGENT37_BASE_TEMPLATE, BROWSER_IMAGE, BROWSERBASE, DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, type DaytonaGpuSnapshot, DESCRIPTORS, daytonaGpu, daytonaGpuSnapshot, DOCKER, E2B, KERNEL, LOCAL, MODAL, ORGO, ORGO_BASE_IMAGE, PHONE_GROUPS, PHONE_HARNESS, PHONE_IMAGE, } from "./descriptors/index.js";
|
|
27
|
+
export { AGENT37, AGENT37_BASE_TEMPLATE, BOXD, BOXD_DEFAULT_IMAGE, BROWSER_IMAGE, BROWSERBASE, DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, type DaytonaGpuSnapshot, DESCRIPTORS, daytonaGpu, daytonaGpuSnapshot, DOCKER, E2B, KERNEL, LOCAL, MODAL, MORPH, ORGO, ORGO_BASE_IMAGE, PHONE_GROUPS, PHONE_HARNESS, PHONE_IMAGE, } from "./descriptors/index.js";
|
|
28
28
|
export type { PhoneLedger, PhoneLedgerEntry } from "./phone-harness.js";
|
|
29
29
|
export { type ComputerSettingKind, configurationOf, entryOf, imagesOf, type KindCapabilities, kindOf, kindServed, type ProviderEntry, PROVIDERS, SETTING_KIND_NAMES, SETTING_KINDS, type SettingKindSpec, serves, servingRefusals, type TestConnection, type TestConnectionOptions, } from "./kinds.js";
|
|
30
30
|
export * from "./conformance/index.js";
|