@parcha/agentrun-computer 0.1.0-beta.33 → 0.1.0-beta.35

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.
Files changed (112) hide show
  1. package/README.md +308 -36
  2. package/dist/browser.d.ts +13 -14
  3. package/dist/browser.js +22 -17
  4. package/dist/browserbase.d.ts +3 -3
  5. package/dist/browserbase.js +16 -11
  6. package/dist/child.d.ts +2 -0
  7. package/dist/child.js +13 -2
  8. package/dist/chrome.d.ts +73 -0
  9. package/dist/chrome.js +224 -0
  10. package/dist/computerd-linux-amd64 +0 -0
  11. package/dist/computerd-linux-arm64 +0 -0
  12. package/dist/conformance/browserbase.js +1 -1
  13. package/dist/conformance/cases/gpu.d.ts +2 -0
  14. package/dist/conformance/cases/gpu.js +108 -0
  15. package/dist/conformance/cases/health.js +83 -3
  16. package/dist/conformance/cases/index.js +2 -0
  17. package/dist/conformance/cases/mount.d.ts +8 -1
  18. package/dist/conformance/cases/mount.js +4 -3
  19. package/dist/conformance/cases/provider.js +92 -3
  20. package/dist/conformance/cli.js +46 -7
  21. package/dist/conformance/daytona.js +2 -1
  22. package/dist/conformance/e2b.js +2 -1
  23. package/dist/conformance/fixture.js +24 -2
  24. package/dist/conformance/kernel.js +1 -1
  25. package/dist/conformance/kind.js +2 -1
  26. package/dist/conformance/local-chrome.d.ts +30 -0
  27. package/dist/conformance/local-chrome.js +36 -0
  28. package/dist/conformance/orgo.d.ts +11 -5
  29. package/dist/conformance/orgo.js +37 -8
  30. package/dist/conformance/phone-harness.js +2 -1
  31. package/dist/conformance/report.js +13 -7
  32. package/dist/conformance/runner.js +68 -18
  33. package/dist/conformance/types.d.ts +78 -18
  34. package/dist/conformance/types.js +10 -0
  35. package/dist/conformance/windows-fixture.d.ts +1 -0
  36. package/dist/conformance/windows-fixture.js +37 -0
  37. package/dist/daytona.d.ts +4 -6
  38. package/dist/daytona.js +97 -52
  39. package/dist/descriptor.d.ts +94 -0
  40. package/dist/descriptor.js +81 -0
  41. package/dist/descriptors/browserbase.d.ts +24 -0
  42. package/dist/descriptors/browserbase.js +18 -0
  43. package/dist/descriptors/daytona.d.ts +62 -0
  44. package/dist/descriptors/daytona.js +49 -0
  45. package/dist/descriptors/docker.d.ts +12 -0
  46. package/dist/descriptors/docker.js +17 -0
  47. package/dist/descriptors/e2b.d.ts +22 -0
  48. package/dist/descriptors/e2b.js +19 -0
  49. package/dist/descriptors/index.d.ts +229 -0
  50. package/dist/descriptors/index.js +19 -0
  51. package/dist/descriptors/kernel.d.ts +20 -0
  52. package/dist/descriptors/kernel.js +15 -0
  53. package/dist/descriptors/local-chrome.d.ts +17 -0
  54. package/dist/descriptors/local-chrome.js +21 -0
  55. package/dist/descriptors/modal.d.ts +50 -0
  56. package/dist/descriptors/modal.js +38 -0
  57. package/dist/descriptors/orgo.d.ts +88 -0
  58. package/dist/descriptors/orgo.js +44 -0
  59. package/dist/descriptors/phone-harness.d.ts +28 -0
  60. package/dist/descriptors/phone-harness.js +20 -0
  61. package/dist/descriptors/shared.d.ts +7 -0
  62. package/dist/descriptors/shared.js +6 -0
  63. package/dist/desktop.d.ts +4 -4
  64. package/dist/desktop.js +4 -4
  65. package/dist/docker/egress.d.ts +1 -1
  66. package/dist/docker/image.js +17 -15
  67. package/dist/docker/inspect.d.ts +147 -0
  68. package/dist/docker/inspect.js +335 -0
  69. package/dist/docker.d.ts +6 -4
  70. package/dist/docker.js +53 -41
  71. package/dist/drift.d.ts +6 -146
  72. package/dist/drift.js +14 -334
  73. package/dist/e2b.d.ts +2 -6
  74. package/dist/e2b.js +19 -22
  75. package/dist/index.d.ts +9 -10
  76. package/dist/index.js +14 -10
  77. package/dist/isolation.d.ts +0 -2
  78. package/dist/isolation.js +2 -18
  79. package/dist/janitor.d.ts +18 -1
  80. package/dist/janitor.js +67 -19
  81. package/dist/kernel.d.ts +3 -3
  82. package/dist/kernel.js +19 -14
  83. package/dist/kinds.d.ts +56 -30
  84. package/dist/kinds.js +19 -97
  85. package/dist/labels.d.ts +18 -0
  86. package/dist/labels.js +65 -2
  87. package/dist/local-chrome.d.ts +86 -0
  88. package/dist/local-chrome.js +475 -0
  89. package/dist/local-supervisor.d.ts +51 -0
  90. package/dist/local-supervisor.js +221 -0
  91. package/dist/modal.d.ts +15 -7
  92. package/dist/modal.js +83 -39
  93. package/dist/mount-archil.js +4 -4
  94. package/dist/orgo-channel.js +16 -13
  95. package/dist/orgo-desktop.d.ts +153 -0
  96. package/dist/orgo-desktop.js +1614 -0
  97. package/dist/orgo-names.d.ts +52 -0
  98. package/dist/orgo-names.js +84 -0
  99. package/dist/orgo.d.ts +18 -13
  100. package/dist/orgo.js +54 -128
  101. package/dist/phone-harness.d.ts +4 -8
  102. package/dist/phone-harness.js +48 -46
  103. package/dist/protocol.d.ts +20 -0
  104. package/dist/protocol.js +9 -0
  105. package/dist/provider.d.ts +151 -10
  106. package/dist/provider.js +70 -0
  107. package/dist/providers.d.ts +22 -17
  108. package/dist/providers.js +14 -16
  109. package/dist/result.d.ts +11 -1
  110. package/dist/result.js +11 -0
  111. package/dist/test-connection.js +2 -2
  112. package/package.json +42 -2
@@ -0,0 +1,52 @@
1
+ import type { ComputerRef } from "./provider.js";
2
+ /** The longest name Orgo holds. */
3
+ export declare const NAME_MAX = 80;
4
+ /** An Orgo computer's id. */
5
+ export declare const COMPUTER_ID: RegExp;
6
+ /** What the labels file holds. */
7
+ export interface LabelsFile {
8
+ name: string;
9
+ labels: Record<string, string>;
10
+ deadline: string;
11
+ maxDeadline: string;
12
+ image: string;
13
+ cpus?: number;
14
+ memoryMb?: number;
15
+ }
16
+ /** What Orgo reports of a computer, as far as a provider reads it. */
17
+ export interface OrgoComputer {
18
+ id: string;
19
+ name: string;
20
+ status: string;
21
+ os?: string;
22
+ workspace_id?: string;
23
+ project_id?: string;
24
+ ends_at?: string | null;
25
+ created_at?: string;
26
+ }
27
+ export declare const show: (value: unknown) => string;
28
+ /**
29
+ * The name of a computer with these labels: computer-<hex>, then -r<the run label's hash> and -e<the epoch label> when
30
+ * the labels carry a run and an epoch that is one, then -d<the deadline> when given: whole seconds since the epoch,
31
+ * rounded up (never before init's own), in base 36, the janitor's deadline. Only those: a name is no place for a label's
32
+ * value. Everything but the deadline is the name's stable part, which a rename on extend keeps.
33
+ */
34
+ export declare function orgoName(labels: Record<string, string>, hex: string, deadline?: Date): string;
35
+ /** A name's stable part with this deadline. */
36
+ export declare function withDeadline(stable: string, deadline: Date): string;
37
+ /** What a name of this provider's making says, or undefined for any other name: its stable part, and its deadline. */
38
+ export declare function nameParts(name: unknown): {
39
+ hex: string;
40
+ run?: string;
41
+ epoch?: string;
42
+ stable: string;
43
+ deadline?: Date;
44
+ } | undefined;
45
+ /** Whether two names are one computer's: their stable parts are the same (the deadline moves with extend). */
46
+ export declare const sameComputer: (a: string, b: string) => boolean;
47
+ export declare function labelProblem(key: string, value: unknown): string | undefined;
48
+ export declare function filterProblem(labels: unknown): string | undefined;
49
+ /** Why ref is not an Orgo computer's ref, or undefined. */
50
+ export declare function refProblem(ref: ComputerRef): string | undefined;
51
+ /** The labels file at path as written, or why it is not. */
52
+ export declare function labelsOf(text: string, path: string): LabelsFile | string;
@@ -0,0 +1,84 @@
1
+ // What every Orgo provider (the Linux desktop with computerd, orgo.ts, and the Windows and macOS desktops Orgo's API
2
+ // answers, orgo-desktop.ts) shares about a computer with nothing run inside it: its name, which carries the run, the
3
+ // epoch and the janitor's deadline; the labels a spec may give; Orgo's record of a computer; and the labels file each
4
+ // keeps in the computer, the truth attach reads.
5
+ import { COMPUTER_LABEL } from "./drift.js";
6
+ import { EPOCH_LABEL, RUN_LABEL, runHash } from "./labels.js";
7
+ /** The longest name Orgo holds. */
8
+ export const NAME_MAX = 80;
9
+ /** A name of this provider's making: computer-<12 hex>, the run label's hash, the epoch label, the deadline (base 36 s). */
10
+ const NAME = /^computer-([0-9a-f]{12})(?:-r([a-z2-7]{16}))?(?:-e(0|[1-9][0-9]{0,15}))?(?:-d([0-9a-z]{1,11}))?$/;
11
+ /** An Orgo computer's id. */
12
+ export const COMPUTER_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
13
+ export const show = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
14
+ /**
15
+ * The name of a computer with these labels: computer-<hex>, then -r<the run label's hash> and -e<the epoch label> when
16
+ * the labels carry a run and an epoch that is one, then -d<the deadline> when given: whole seconds since the epoch,
17
+ * rounded up (never before init's own), in base 36, the janitor's deadline. Only those: a name is no place for a label's
18
+ * value. Everything but the deadline is the name's stable part, which a rename on extend keeps.
19
+ */
20
+ export function orgoName(labels, hex, deadline) {
21
+ const run = labels[RUN_LABEL];
22
+ const epoch = labels[EPOCH_LABEL];
23
+ const stable = `computer-${hex}${typeof run === "string" && run !== "" ? `-r${runHash(run)}` : ""}${typeof epoch === "string" && /^(?:0|[1-9][0-9]{0,15})$/.test(epoch) ? `-e${epoch}` : ""}`;
24
+ return deadline === undefined ? stable : withDeadline(stable, deadline);
25
+ }
26
+ /** A name's stable part with this deadline. */
27
+ export function withDeadline(stable, deadline) {
28
+ return `${stable}-d${Math.ceil(deadline.getTime() / 1000).toString(36)}`;
29
+ }
30
+ /** What a name of this provider's making says, or undefined for any other name: its stable part, and its deadline. */
31
+ export function nameParts(name) {
32
+ const match = typeof name === "string" ? NAME.exec(name) : null;
33
+ if (match === null)
34
+ return undefined;
35
+ const seconds = match[4] === undefined ? Number.NaN : Number.parseInt(match[4], 36);
36
+ return {
37
+ hex: match[1],
38
+ ...(match[2] ? { run: match[2] } : {}),
39
+ ...(match[3] !== undefined ? { epoch: match[3] } : {}),
40
+ stable: name.replace(/-d[0-9a-z]+$/, ""),
41
+ ...(Number.isSafeInteger(seconds) ? { deadline: new Date(seconds * 1000) } : {}),
42
+ };
43
+ }
44
+ /** Whether two names are one computer's: their stable parts are the same (the deadline moves with extend). */
45
+ export const sameComputer = (a, b) => nameParts(a)?.stable !== undefined && nameParts(a)?.stable === nameParts(b)?.stable;
46
+ export function labelProblem(key, value) {
47
+ if (typeof value !== "string")
48
+ return `the label ${key} must be a string`;
49
+ if (key === "" || key.includes("\0") || value.includes("\0"))
50
+ return `the label ${JSON.stringify(key)} must be a non-empty name, and neither holds a NUL byte`;
51
+ if (key === COMPUTER_LABEL || key.startsWith(`${COMPUTER_LABEL}.`))
52
+ return `the label ${key} is in the provider's own namespace (${COMPUTER_LABEL})`;
53
+ return undefined;
54
+ }
55
+ export function filterProblem(labels) {
56
+ if (typeof labels !== "object" || labels === null || Array.isArray(labels))
57
+ return "labels must map names to strings";
58
+ for (const [key, value] of Object.entries(labels)) {
59
+ if (typeof value !== "string" || key === "" || key.includes("\0") || value.includes("\0"))
60
+ return `the label ${JSON.stringify(key)} must be a non-empty name and a string, with no NUL byte`;
61
+ }
62
+ return undefined;
63
+ }
64
+ /** Why ref is not an Orgo computer's ref, or undefined. */
65
+ export function refProblem(ref) {
66
+ if (typeof ref?.name !== "string" || nameParts(ref.name) === undefined)
67
+ return `${String(ref?.name)} is not the name of an Orgo computer of this provider (computer-<12 hex digits>...)`;
68
+ if (typeof ref.id !== "string" || !COMPUTER_ID.test(ref.id))
69
+ return `${String(ref.id)} is not an Orgo computer id`;
70
+ return undefined;
71
+ }
72
+ /** The labels file at path as written, or why it is not. */
73
+ export function labelsOf(text, path) {
74
+ try {
75
+ const value = JSON.parse(text);
76
+ if (typeof value?.name === "string" && typeof value.labels === "object" && value.labels !== null && typeof value.deadline === "string" && typeof value.maxDeadline === "string" && typeof value.image === "string") {
77
+ return value;
78
+ }
79
+ }
80
+ catch {
81
+ // Said below.
82
+ }
83
+ return `the labels file ${path} is not the one create writes`;
84
+ }
package/dist/orgo.d.ts CHANGED
@@ -1,12 +1,16 @@
1
1
  import type { KindCapabilities } from "./kinds.js";
2
2
  import { type MountKind } from "./mount.js";
3
3
  import { type OrgoChannel, type OrgoStart, type OrgoWebSocketFactory } from "./orgo-channel.js";
4
- import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
4
+ import { OrgoDesktopProvider, type OrgoDesktopOptions } from "./orgo-desktop.js";
5
+ import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseHow } from "./provider.js";
5
6
  import { type Result } from "./result.js";
6
7
  import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
7
8
  /** The mount kinds an Orgo computer takes: none yet (an Archil mount needs an Orgo template that bakes the helper). */
8
9
  export declare const MOUNT: readonly MountKind[];
9
- /** What a built provider declares, known without building one: one configuration, a Linux desktop (the registry's entry). */
10
+ /**
11
+ * What a built provider declares, known without building one, per configuration (its descriptor's): the Linux desktop
12
+ * with computerd (the default), then the Windows and the macOS desktops Orgo's own API answers (options.os).
13
+ */
10
14
  export declare const CAPABILITIES: readonly KindCapabilities[];
11
15
  /** The conformance CLI's module for Orgo: its live switch, the run's 1 h cap and the drifted twin. */
12
16
  export declare const conformance: () => Promise<typeof import("./conformance/orgo.js")>;
@@ -58,8 +62,6 @@ export interface OrgoProviderOptions {
58
62
  /** The addresses the probe tries, host:port over TCP or host:port/udp, to show none of them answers. */
59
63
  probeTargets?: string[];
60
64
  }
61
- /** Orgo's base desktop, no template: the image a spec names for a plain Linux desktop, and the default for kind desktop. */
62
- export declare const ORGO_BASE_IMAGE = "linux";
63
65
  /** The labels file: every label, the deadline and its most, the image and sizes, root's, readable by all. */
64
66
  export declare const LABELS_FILE = "/opt/agentrun/labels.json";
65
67
  /**
@@ -72,13 +74,6 @@ export declare const LABELS_FILE = "/opt/agentrun/labels.json";
72
74
  * nothing of its own loses a socket.
73
75
  */
74
76
  export declare const LOCKDOWN_SCRIPT: string;
75
- /**
76
- * The name of a computer with these labels: computer-<hex>, then -r<the run label's hash> and -e<the epoch label> when
77
- * the labels carry a run and an epoch that is one, then -d<the deadline> when given: whole seconds since the epoch,
78
- * rounded up (never before init's own), in base 36, the janitor's deadline. Only those: a name is no place for a label's
79
- * value. Everything but the deadline is the name's stable part, which a rename on extend keeps.
80
- */
81
- export declare function orgoName(labels: Record<string, string>, hex: string, deadline?: Date): string;
82
77
  /**
83
78
  * Orgo desktops: see the module's header. A spec's image is "linux" (Orgo's base desktop) or an Orgo template
84
79
  * (namespace/name@version); cpus and memoryMb are Orgo's sizes; the network is none.
@@ -119,7 +114,7 @@ export declare class OrgoProvider implements ComputerProvider {
119
114
  }>>;
120
115
  network(ref: ComputerRef, policy?: NetworkSpec, { signal }?: CallContext): Promise<Result<NetworkPolicy>>;
121
116
  /** delete: idempotent, a computer Orgo no longer has is done; it waits until Orgo no longer has it. No stop. */
122
- release(ref: ComputerRef, how: "stop" | "delete", { signal }?: CallContext): Promise<Result<void>>;
117
+ release(ref: ComputerRef, how: ReleaseHow, { signal }?: CallContext): Promise<Result<void>>;
123
118
  /**
124
119
  * Moves the deadline to now + ttlMs, never earlier and never past the most the labels file holds (create's time plus
125
120
  * the cap): Orgo's end first, in whole hours with an Idempotency-Key, so it never ends the computer before init does;
@@ -135,5 +130,15 @@ export declare class OrgoProvider implements ComputerProvider {
135
130
  * An OrgoProvider from its options alone, its key included: it reads no environment. Serve passes apiKey from its
136
131
  * ORGO_API_KEY setting and its workspace; the conformance module reads COMPUTER_ORGO_* (settingsFromEnv).
137
132
  */
138
- export declare function create(options: OrgoProviderOptions): OrgoProvider;
133
+ export declare function create(options: OrgoProviderOptions & {
134
+ os?: "linux";
135
+ }): OrgoProvider;
136
+ export declare function create(options: OrgoDesktopOptions & {
137
+ os: "windows" | "macos";
138
+ }): OrgoDesktopProvider;
139
+ export declare function create(options: (OrgoProviderOptions & {
140
+ os?: "linux";
141
+ }) | (OrgoDesktopOptions & {
142
+ os: "windows" | "macos";
143
+ })): OrgoProvider | OrgoDesktopProvider;
139
144
  export type { OrgoChannel, OrgoStart, OrgoStream, OrgoWebSocketFactory } from "./orgo-channel.js";
package/dist/orgo.js CHANGED
@@ -16,21 +16,29 @@ import { readFileSync } from "node:fs";
16
16
  import { fileURLToPath } from "node:url";
17
17
  import { childCommands, daemonDrift } from "./child.js";
18
18
  import { DaemonClient } from "./client.js";
19
+ import { ORGO, ORGO_BASE_IMAGE } from "./descriptors/orgo.js";
19
20
  import { DESKTOP_GROUPS } from "./desktop.js";
20
- import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, SOCKET_DIR, WORK } from "./drift.js";
21
- import { EPOCH_LABEL, RUN_LABEL } from "./labels.js";
21
+ import { DAEMON_IN_COMPUTER, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, SOCKET_DIR, WORK } from "./drift.js";
22
+ import { EPOCH_LABEL, RUN_HASH_LABEL, RUN_LABEL, runHash } from "./labels.js";
22
23
  import { checkMount } from "./mount.js";
23
24
  import { ORGO_API_URL, orgoRest, orgoTerminalChannel, START_LOG } from "./orgo-channel.js";
24
- import { checkLifetime, } from "./provider.js";
25
- import { fail, ok } from "./result.js";
25
+ import { OrgoDesktopProvider } from "./orgo-desktop.js";
26
+ import { COMPUTER_ID, filterProblem, labelProblem, labelsOf, NAME_MAX, nameParts, orgoName, refProblem, sameComputer, show, withDeadline, } from "./orgo-names.js";
27
+ import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
28
+ import { failFor, ok, vendorFail } from "./result.js";
26
29
  import { daemonWatch } from "./screen-watch.js";
27
30
  import { listTested } from "./test-connection.js";
31
+ /** This module's failures: one with code vendor names Orgo. */
32
+ const fail = failFor("orgo");
28
33
  /** The mount kinds an Orgo computer takes: none yet (an Archil mount needs an Orgo template that bakes the helper). */
29
- export const MOUNT = [];
34
+ export const MOUNT = ORGO.mounts;
30
35
  /** The groups every Orgo computer offers: a Linux shell, files and processes, and the desktop's screen and input. */
31
36
  const GROUPS = ["exec", "files", "processes", ...DESKTOP_GROUPS];
32
- /** What a built provider declares, known without building one: one configuration, a Linux desktop (the registry's entry). */
33
- export const CAPABILITIES = [{ kind: "desktop", groups: [...GROUPS] }];
37
+ /**
38
+ * What a built provider declares, known without building one, per configuration (its descriptor's): the Linux desktop
39
+ * with computerd (the default), then the Windows and the macOS desktops Orgo's own API answers (options.os).
40
+ */
41
+ export const CAPABILITIES = ORGO.capabilities;
34
42
  /** The conformance CLI's module for Orgo: its live switch, the run's 1 h cap and the drifted twin. */
35
43
  export const conformance = () => import("./conformance/orgo.js");
36
44
  const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
@@ -42,15 +50,10 @@ const RAM_GB = [4, 8, 16, 32];
42
50
  const CPU_FOR_RAM = { 4: 1, 8: 2, 16: 4, 32: 6 };
43
51
  /** The vCPUs a computer may ask for on its own (8 needs Orgo to set the account up). */
44
52
  const CPUS = [0.5, 1, 2, 4, 6];
45
- const NAME_MAX = 80;
46
- /** A name of this provider's making: computer-<12 hex>, the run label's hash, the epoch label, the deadline (base 36 s). */
47
- const NAME = /^computer-([0-9a-f]{12})(?:-r([a-z2-7]{16}))?(?:-e(0|[1-9][0-9]{0,15}))?(?:-d([0-9a-z]{1,11}))?$/;
48
53
  /** An Orgo template: namespace/name@version. */
49
54
  const TEMPLATE = /^[a-z0-9][a-z0-9_.-]{0,63}\/[a-z0-9][a-z0-9_.-]{0,63}@[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$/;
50
- /** Orgo's base desktop, no template: the image a spec names for a plain Linux desktop, and the default for kind desktop. */
51
- export const ORGO_BASE_IMAGE = "linux";
55
+ /** Orgo's base desktop, no template: the image a spec names for a plain Linux desktop, and its descriptor's default. */
52
56
  const BASE = ORGO_BASE_IMAGE;
53
- const COMPUTER_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
54
57
  const WORKSPACE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
55
58
  const USER = /^(\d+):(\d+)$/;
56
59
  const DISPLAY = /^:(\d{1,5})(?:\.\d{1,5})?$/;
@@ -64,10 +67,11 @@ const STAGING = "/tmp/agentrun-computerd-";
64
67
  const LISTEN_RETRY_MS = 250;
65
68
  /** How often a delete that answers 409 (the computer waking) is tried again. */
66
69
  const DELETE_TRIES = 5;
67
- const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb", "labels"]);
70
+ const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb", "labels", "gpu"]);
68
71
  /** The states in which a computer runs, or is on its way to. */
69
72
  const RUNNING = new Set(["running", "creating", "restarting", "updating", "resuming"]);
70
- const NETWORK = 'an Orgo computer takes network "none" only: Orgo has no egress control, so its tools have no network of their own (init\'s namespace holds them to loopback), and open or an allowlist waits for the proxy-backed feature';
73
+ /** Why a network other than "none" is refused: this configuration makes none alone. */
74
+ const NETWORK_REFUSAL = 'an Orgo computer takes network "none" only: Orgo has no egress control, so its tools have no network of their own (init\'s namespace holds them to loopback), and open or an allowlist waits for the proxy-backed feature';
71
75
  /** The scripts the provider runs as root, each marked on its first line, its arguments after it. */
72
76
  const X11_SCRIPT = ["# agentrun-computer: orgo-x11", "s=$1", '[ -S "$s" ] || { echo "no X socket at $s"; exit 1; }'].join("\n");
73
77
  const LABELS_SCRIPT = ["# agentrun-computer: orgo-labels", 'p=$1; t=$2; d=${p%/*}', 'mkdir -p "$d" && printf \'%s\' "$t" > "$p.part" && chmod 0644 "$p.part" && mv -f "$p.part" "$p"'].join("\n");
@@ -124,7 +128,6 @@ export const LOCKDOWN_SCRIPT = [
124
128
  "EOF",
125
129
  "exit $failed",
126
130
  ].join("\n");
127
- const show = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
128
131
  const seconds = (ms) => `${ms / 1000} s`;
129
132
  const pause = (ms, signal) => new Promise((done) => {
130
133
  const timer = setTimeout(finish, ms);
@@ -138,96 +141,6 @@ const pause = (ms, signal) => new Promise((done) => {
138
141
  else
139
142
  signal?.addEventListener("abort", finish, { once: true });
140
143
  });
141
- /** The run label's hash, as a name carries it: base32 of its sha256, lower case, 16 letters. */
142
- function runHash(run) {
143
- const alphabet = "abcdefghijklmnopqrstuvwxyz234567";
144
- const bytes = createHash("sha256").update(run, "utf8").digest();
145
- let bits = 0;
146
- let value = 0;
147
- let out = "";
148
- for (const byte of bytes) {
149
- value = (value << 8) | byte;
150
- bits += 8;
151
- while (bits >= 5 && out.length < 16) {
152
- out += alphabet[(value >>> (bits - 5)) & 31];
153
- bits -= 5;
154
- }
155
- if (out.length >= 16)
156
- break;
157
- }
158
- return out;
159
- }
160
- /**
161
- * The name of a computer with these labels: computer-<hex>, then -r<the run label's hash> and -e<the epoch label> when
162
- * the labels carry a run and an epoch that is one, then -d<the deadline> when given: whole seconds since the epoch,
163
- * rounded up (never before init's own), in base 36, the janitor's deadline. Only those: a name is no place for a label's
164
- * value. Everything but the deadline is the name's stable part, which a rename on extend keeps.
165
- */
166
- export function orgoName(labels, hex, deadline) {
167
- const run = labels[RUN_LABEL];
168
- const epoch = labels[EPOCH_LABEL];
169
- const stable = `computer-${hex}${typeof run === "string" && run !== "" ? `-r${runHash(run)}` : ""}${typeof epoch === "string" && /^(?:0|[1-9][0-9]{0,15})$/.test(epoch) ? `-e${epoch}` : ""}`;
170
- return deadline === undefined ? stable : withDeadline(stable, deadline);
171
- }
172
- /** A name's stable part with this deadline. */
173
- function withDeadline(stable, deadline) {
174
- return `${stable}-d${Math.ceil(deadline.getTime() / 1000).toString(36)}`;
175
- }
176
- /** What a name of this provider's making says, or undefined for any other name: its stable part, and its deadline. */
177
- function nameParts(name) {
178
- const match = typeof name === "string" ? NAME.exec(name) : null;
179
- if (match === null)
180
- return undefined;
181
- const seconds = match[4] === undefined ? Number.NaN : Number.parseInt(match[4], 36);
182
- return {
183
- hex: match[1],
184
- ...(match[2] ? { run: match[2] } : {}),
185
- ...(match[3] !== undefined ? { epoch: match[3] } : {}),
186
- stable: name.replace(/-d[0-9a-z]+$/, ""),
187
- ...(Number.isSafeInteger(seconds) ? { deadline: new Date(seconds * 1000) } : {}),
188
- };
189
- }
190
- /** Whether two names are one computer's: their stable parts are the same (the deadline moves with extend). */
191
- const sameComputer = (a, b) => nameParts(a)?.stable !== undefined && nameParts(a)?.stable === nameParts(b)?.stable;
192
- function labelProblem(key, value) {
193
- if (typeof value !== "string")
194
- return `the label ${key} must be a string`;
195
- if (key === "" || key.includes("\0") || value.includes("\0"))
196
- return `the label ${JSON.stringify(key)} must be a non-empty name, and neither holds a NUL byte`;
197
- if (key === COMPUTER_LABEL || key.startsWith(`${COMPUTER_LABEL}.`))
198
- return `the label ${key} is in the provider's own namespace (${COMPUTER_LABEL})`;
199
- return undefined;
200
- }
201
- function filterProblem(labels) {
202
- if (typeof labels !== "object" || labels === null || Array.isArray(labels))
203
- return "labels must map names to strings";
204
- for (const [key, value] of Object.entries(labels)) {
205
- if (typeof value !== "string" || key === "" || key.includes("\0") || value.includes("\0"))
206
- return `the label ${JSON.stringify(key)} must be a non-empty name and a string, with no NUL byte`;
207
- }
208
- return undefined;
209
- }
210
- /** Why ref is not an Orgo computer's ref, or undefined. */
211
- function refProblem(ref) {
212
- if (typeof ref?.name !== "string" || nameParts(ref.name) === undefined)
213
- return `${String(ref?.name)} is not the name of an Orgo computer of this provider (computer-<12 hex digits>...)`;
214
- if (typeof ref.id !== "string" || !COMPUTER_ID.test(ref.id))
215
- return `${String(ref.id)} is not an Orgo computer id`;
216
- return undefined;
217
- }
218
- /** The labels file as written, or why it is not. */
219
- function labelsOf(text) {
220
- try {
221
- const value = JSON.parse(text);
222
- if (typeof value?.name === "string" && typeof value.labels === "object" && value.labels !== null && typeof value.deadline === "string" && typeof value.maxDeadline === "string" && typeof value.image === "string") {
223
- return value;
224
- }
225
- }
226
- catch {
227
- // Said below.
228
- }
229
- return `the labels file ${LABELS_FILE} is not the one create writes`;
230
- }
231
144
  /**
232
145
  * Orgo desktops: see the module's header. A spec's image is "linux" (Orgo's base desktop) or an Orgo template
233
146
  * (namespace/name@version); cpus and memoryMb are Orgo's sizes; the network is none.
@@ -303,6 +216,7 @@ export class OrgoProvider {
303
216
  return {
304
217
  kind: "desktop",
305
218
  lifetime: "janitor",
219
+ // This configuration's form, one of Orgo's descriptor's: none (the Windows desktop's is open).
306
220
  network: ["none"],
307
221
  networkReadBack: false,
308
222
  isolation: "vm",
@@ -323,9 +237,9 @@ export class OrgoProvider {
323
237
  const { image, lifetimeMs, network, cpus, memoryMb, labels, mount } = given;
324
238
  if (image !== BASE && !(typeof image === "string" && TEMPLATE.test(image)))
325
239
  refuse("image", `an image is "${BASE}" (Orgo's base desktop) or an Orgo template, namespace/name@version`);
326
- refusals.push(...checkLifetime(lifetimeMs, this.capabilities()));
240
+ refusals.push(...checkTenure(given, this.capabilities(), "Orgo"));
327
241
  if (network !== "none")
328
- refuse("network", NETWORK);
242
+ refuse("network", NETWORK_REFUSAL);
329
243
  if (memoryMb !== undefined && !RAM_GB.some((gb) => gb * 1024 === memoryMb))
330
244
  refuse("memoryMb", "memoryMb is one of Orgo's sizes: 4096, 8192, 16384 or 32768");
331
245
  if (cpus !== undefined && !CPUS.includes(cpus))
@@ -337,6 +251,7 @@ export class OrgoProvider {
337
251
  refuse("labels", bad);
338
252
  }
339
253
  refusals.push(...checkMount(mount, MOUNT));
254
+ refusals.push(...checkGpu(given.gpu, this.capabilities()));
340
255
  for (const [field, value] of Object.entries(given)) {
341
256
  if (SPEC_FIELDS.has(field) || field === "mount" || value === undefined)
342
257
  continue;
@@ -366,7 +281,7 @@ export class OrgoProvider {
366
281
  return fail("aborted", "create was aborted before Orgo was called");
367
282
  const labels = { ...spec.labels };
368
283
  const now = Date.now();
369
- const deadline = new Date(now + spec.lifetimeMs).toISOString();
284
+ const deadline = new Date(now + runLifetimeMs(spec)).toISOString();
370
285
  const maxDeadline = new Date(now + this.#maxLifetimeMs).toISOString();
371
286
  // The janitor's deadline is in the name, so list() and the sweep read it with nothing run inside.
372
287
  const name = orgoName(labels, randomBytes(6).toString("hex"), new Date(deadline));
@@ -381,7 +296,7 @@ export class OrgoProvider {
381
296
  ram,
382
297
  cpu,
383
298
  // Orgo's end, the vendor's backstop: whole hours, deleting the computer and its disk. init ends it on time.
384
- ends_in_hours: Math.max(1, Math.ceil(spec.lifetimeMs / HOUR)),
299
+ ends_in_hours: Math.max(1, Math.ceil(runLifetimeMs(spec) / HOUR)),
385
300
  ...(spec.image === BASE ? {} : { template_ref: spec.image }),
386
301
  };
387
302
  const made = await this.#rest.request("POST", "/computers", { body, timeoutMs: this.#timeouts.createMs, ...(signal ? { signal } : {}) });
@@ -393,7 +308,7 @@ export class OrgoProvider {
393
308
  }
394
309
  const id = made.value?.id;
395
310
  if (typeof id !== "string" || !COMPUTER_ID.test(id))
396
- return fail("orgo", `Orgo's create answered no computer id${await this.#deleteNamed(name)}`);
311
+ return vendorFail("orgo", `Orgo's create answered no computer id${await this.#deleteNamed(name)}`);
397
312
  const ref = { id, name };
398
313
  const file = { name, labels, deadline, maxDeadline, image: spec.image, cpus: cpu, memoryMb: ram * 1024 };
399
314
  const prepared = await this.#prepare(ref, made.value.status, file, daemon, signal);
@@ -515,7 +430,7 @@ export class OrgoProvider {
515
430
  if (last === "running")
516
431
  return ok(undefined);
517
432
  if (!RUNNING.has(last))
518
- return fail("orgo", `Orgo read ${ref.name} ${last}, not running`);
433
+ return vendorFail("orgo", `Orgo read ${ref.name} ${last}, not running`);
519
434
  if (Date.now() >= until)
520
435
  return fail("timeout", `Orgo did not read ${ref.name} running within ${seconds(this.#timeouts.createMs)}; it last read ${last}`);
521
436
  await pause(this.#timeouts.pollMs, signal);
@@ -537,7 +452,7 @@ export class OrgoProvider {
537
452
  return read;
538
453
  if (read.value.exitCode !== 0)
539
454
  return fail("refused", `${ref.name} has no labels file ${LABELS_FILE} to read (exit ${read.value.exitCode})`);
540
- const file = labelsOf(read.value.output);
455
+ const file = labelsOf(read.value.output, LABELS_FILE);
541
456
  return typeof file === "string" ? fail("refused", `${ref.name}: ${file}`) : ok(file);
542
457
  }
543
458
  /**
@@ -600,7 +515,7 @@ export class OrgoProvider {
600
515
  return fail("timeout", `the daemon in ${ref.name} did not answer hello within ${seconds(helloMs)}`);
601
516
  if (hello.error.code !== "gone")
602
517
  return hello;
603
- return { ...fail("orgo", `cannot reach the daemon in ${ref.name}: ${stream.said() || hello.error.message}`), notListening: true };
518
+ return { ...vendorFail("orgo", `cannot reach the daemon in ${ref.name}: ${stream.said() || hello.error.message}`), notListening: true };
604
519
  }
605
520
  return ok({ client, hello: hello.value, close });
606
521
  }
@@ -620,13 +535,18 @@ export class OrgoProvider {
620
535
  if (!read.ok)
621
536
  return read;
622
537
  if (typeof read.value?.name !== "string" || typeof read.value.status !== "string")
623
- return fail("orgo", `Orgo's record of ${id} has no name or status`);
538
+ return vendorFail("orgo", `Orgo's record of ${id} has no name or status`);
624
539
  return ok(read.value);
625
540
  }
626
541
  /** Whether Orgo's record is a computer of this provider: its name's shape, in this workspace. */
627
542
  #ours(record, name) {
628
543
  // A ref's name matches by its stable part: extend renames the computer with its new deadline.
629
- return nameParts(record.name) !== undefined && (record.workspace_id ?? record.project_id) === this.#workspaceId && (name === undefined || sameComputer(record.name, name)) && record.status !== "deleted";
544
+ // A Windows or macOS computer in the workspace is the desktop provider's (orgo-desktop.ts), where Orgo says its os.
545
+ return (nameParts(record.name) !== undefined &&
546
+ (record.workspace_id ?? record.project_id) === this.#workspaceId &&
547
+ (name === undefined || sameComputer(record.name, name)) &&
548
+ record.status !== "deleted" &&
549
+ (record.os === undefined || record.os === "linux"));
630
550
  }
631
551
  /** This provider's computer for ref, as Orgo reads it, or why not. */
632
552
  async #own(ref, signal) {
@@ -694,7 +614,7 @@ export class OrgoProvider {
694
614
  return read;
695
615
  const desktops = read.value?.desktops;
696
616
  if (!Array.isArray(desktops))
697
- return fail("orgo", `Orgo's workspace ${this.#workspaceId} lists no computers array`);
617
+ return vendorFail("orgo", `Orgo's workspace ${this.#workspaceId} lists no computers array`);
698
618
  return ok(desktops.filter((one) => typeof one?.id === "string" && typeof one.name === "string").map((one) => ({ ...one, workspace_id: this.#workspaceId })));
699
619
  }
700
620
  /** The live view: screen.watch on a connection of the watch's own (daemonWatch), never Orgo's VNC (proxy only). */
@@ -834,7 +754,9 @@ export class OrgoProvider {
834
754
  const infos = [];
835
755
  for (const record of listed.value) {
836
756
  const parts = nameParts(record.name);
837
- if (parts === undefined || record.status === "deleted")
757
+ // Orgo's workspace listing names each desktop's os: a Windows or macOS one is the desktop provider's
758
+ // (orgo-desktop.ts), never this one's to list or its janitor's to sweep.
759
+ if (parts === undefined || record.status === "deleted" || (record.os !== undefined && record.os !== "linux"))
838
760
  continue;
839
761
  if (labels[RUN_LABEL] !== undefined && parts.run !== runHash(labels[RUN_LABEL]))
840
762
  continue;
@@ -842,12 +764,15 @@ export class OrgoProvider {
842
764
  continue;
843
765
  const ref = { id: record.id, name: record.name };
844
766
  const running = RUNNING.has(record.status);
767
+ // The name keeps the run's hash, not the run: listed with no run to match, the hash is given, so a caller (serve's
768
+ // janitor) can still tell whose run a computer is.
845
769
  let read = {
846
- ...(labels[RUN_LABEL] !== undefined ? { [RUN_LABEL]: labels[RUN_LABEL] } : {}),
770
+ ...(labels[RUN_LABEL] !== undefined ? { [RUN_LABEL]: labels[RUN_LABEL] } : parts.run !== undefined ? { [RUN_HASH_LABEL]: parts.run } : {}),
847
771
  ...(parts.epoch !== undefined ? { [EPOCH_LABEL]: parts.epoch } : {}),
848
772
  };
849
- // The janitor's deadline is the name's; a name of an older make has none, and Orgo's end stands for it.
850
- let deadline = parts.deadline ?? (typeof record.ends_at === "string" ? new Date(record.ends_at) : undefined);
773
+ // The janitor's deadline is the name's, which every name this provider makes carries. One with none is listed
774
+ // with none, and the janitor ends it (a run's computer with no deadline it can read).
775
+ const deadline = parts.deadline;
851
776
  if (others.length > 0) {
852
777
  if (record.status !== "running")
853
778
  continue;
@@ -857,7 +782,6 @@ export class OrgoProvider {
857
782
  if (!others.every((key) => file.value.labels[key] === labels[key]))
858
783
  continue;
859
784
  read = { ...file.value.labels };
860
- deadline = parts.deadline ?? new Date(file.value.deadline);
861
785
  }
862
786
  infos.push({ ref, labels: read, deadline, state: running ? "running" : "stopped", network: "none" });
863
787
  }
@@ -873,7 +797,7 @@ export class OrgoProvider {
873
797
  if (problem)
874
798
  return fail("invalid", problem);
875
799
  if (policy !== undefined && policy !== "none")
876
- return fail("refused", NETWORK);
800
+ return fail("refused", NETWORK_REFUSAL);
877
801
  const found = await this.#own(ref, signal);
878
802
  if (!found.ok)
879
803
  return found;
@@ -997,10 +921,12 @@ export class OrgoProvider {
997
921
  return ok({ deadline: took });
998
922
  }
999
923
  }
1000
- /**
1001
- * An OrgoProvider from its options alone, its key included: it reads no environment. Serve passes apiKey from its
1002
- * ORGO_API_KEY setting and its workspace; the conformance module reads COMPUTER_ORGO_* (settingsFromEnv).
1003
- */
1004
924
  export function create(options) {
1005
- return new OrgoProvider(options);
925
+ const os = options?.os;
926
+ if (os === "windows" || os === "macos")
927
+ return new OrgoDesktopProvider(options);
928
+ if (os !== undefined && os !== "linux")
929
+ throw new Error(`os is "linux" (the default), "windows" or "macos", not ${JSON.stringify(os)}`);
930
+ const { os: _os, ...linux } = options;
931
+ return new OrgoProvider(linux);
1006
932
  }
@@ -1,19 +1,15 @@
1
1
  import type { KindCapabilities } from "./kinds.js";
2
2
  import type { MountKind } from "./mount.js";
3
- import { type Group, type Rect, type UiNode } from "./protocol.js";
4
- import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
3
+ import { type Rect, type UiNode } from "./protocol.js";
4
+ import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseHow } from "./provider.js";
5
5
  import { type Result } from "./result.js";
6
6
  import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
7
7
  /** The phone harness's API. */
8
8
  export declare const PHONE_HARNESS_URL = "https://api.phone-harness.com";
9
- /** What a cloud Android offers through this provider, as its capabilities and hello declare them. */
10
- export declare const PHONE_GROUPS: readonly Group[];
11
9
  /** A phone mounts no folder. */
12
10
  export declare const MOUNT: readonly MountKind[];
13
- /** The one configuration it offers, as its capabilities() declare it: the kind registry's entry holds the same. */
11
+ /** The one configuration it offers, as its capabilities() declare it: its descriptor's. */
14
12
  export declare const CAPABILITIES: readonly KindCapabilities[];
15
- /** The image a phone is read back by: a cloud Android has none to choose, so a setting that names none takes this. */
16
- export declare const PHONE_IMAGE = "android";
17
13
  /** The longest lifetime by default: a rented phone bills by the minute. */
18
14
  export declare const DEFAULT_MAX_LIFETIME_MS: number;
19
15
  /** How long create waits for a phone to be ready by default: the service's own CLI waits 240 s. */
@@ -153,7 +149,7 @@ export declare class PhoneHarnessProvider implements ComputerProvider {
153
149
  }, context?: CallContext): Promise<Result<AttachedComputer>>;
154
150
  list(labels: Record<string, string>, context?: CallContext): Promise<Result<ComputerInfo[]>>;
155
151
  network(ref: ComputerRef, policy?: NetworkSpec): Promise<Result<NetworkPolicy>>;
156
- release(ref: ComputerRef, how: "stop" | "delete"): Promise<Result<void>>;
152
+ release(ref: ComputerRef, how: ReleaseHow): Promise<Result<void>>;
157
153
  connect(ref: ComputerRef): Promise<Result<ComputerConnection>>;
158
154
  /**
159
155
  * The live view: the phone client's screen.watch on a connection of the watch's own (daemonWatch), PNG frames from