@parcha/agentrun-computer 0.1.0-beta.34 → 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 (99) hide show
  1. package/README.md +144 -26
  2. package/dist/browser.d.ts +12 -13
  3. package/dist/browser.js +16 -14
  4. package/dist/browserbase.d.ts +3 -5
  5. package/dist/browserbase.js +16 -13
  6. package/dist/chrome.js +1 -1
  7. package/dist/computerd-linux-amd64 +0 -0
  8. package/dist/computerd-linux-arm64 +0 -0
  9. package/dist/conformance/browserbase.js +1 -1
  10. package/dist/conformance/cases/provider.js +78 -3
  11. package/dist/conformance/daytona.js +2 -1
  12. package/dist/conformance/e2b.js +2 -1
  13. package/dist/conformance/fixture.js +24 -2
  14. package/dist/conformance/kernel.js +1 -1
  15. package/dist/conformance/kind.js +2 -1
  16. package/dist/conformance/{local.d.ts → local-chrome.d.ts} +7 -7
  17. package/dist/conformance/{local.js → local-chrome.js} +11 -11
  18. package/dist/conformance/orgo.d.ts +11 -5
  19. package/dist/conformance/orgo.js +37 -8
  20. package/dist/conformance/phone-harness.js +2 -1
  21. package/dist/conformance/report.js +3 -2
  22. package/dist/conformance/runner.js +25 -7
  23. package/dist/conformance/types.d.ts +21 -8
  24. package/dist/conformance/types.js +10 -0
  25. package/dist/conformance/windows-fixture.d.ts +1 -0
  26. package/dist/conformance/windows-fixture.js +37 -0
  27. package/dist/daytona.d.ts +3 -34
  28. package/dist/daytona.js +34 -61
  29. package/dist/descriptor.d.ts +94 -0
  30. package/dist/descriptor.js +81 -0
  31. package/dist/descriptors/browserbase.d.ts +24 -0
  32. package/dist/descriptors/browserbase.js +18 -0
  33. package/dist/descriptors/daytona.d.ts +62 -0
  34. package/dist/descriptors/daytona.js +49 -0
  35. package/dist/descriptors/docker.d.ts +12 -0
  36. package/dist/descriptors/docker.js +17 -0
  37. package/dist/descriptors/e2b.d.ts +22 -0
  38. package/dist/descriptors/e2b.js +19 -0
  39. package/dist/descriptors/index.d.ts +229 -0
  40. package/dist/descriptors/index.js +19 -0
  41. package/dist/descriptors/kernel.d.ts +20 -0
  42. package/dist/descriptors/kernel.js +15 -0
  43. package/dist/descriptors/local-chrome.d.ts +17 -0
  44. package/dist/descriptors/local-chrome.js +21 -0
  45. package/dist/descriptors/modal.d.ts +50 -0
  46. package/dist/descriptors/modal.js +38 -0
  47. package/dist/descriptors/orgo.d.ts +88 -0
  48. package/dist/descriptors/orgo.js +44 -0
  49. package/dist/descriptors/phone-harness.d.ts +28 -0
  50. package/dist/descriptors/phone-harness.js +20 -0
  51. package/dist/descriptors/shared.d.ts +7 -0
  52. package/dist/descriptors/shared.js +6 -0
  53. package/dist/desktop.d.ts +4 -4
  54. package/dist/desktop.js +4 -4
  55. package/dist/docker/egress.d.ts +1 -1
  56. package/dist/docker/image.js +17 -15
  57. package/dist/docker/inspect.d.ts +147 -0
  58. package/dist/docker/inspect.js +335 -0
  59. package/dist/docker.d.ts +6 -6
  60. package/dist/docker.js +46 -42
  61. package/dist/drift.d.ts +3 -145
  62. package/dist/drift.js +5 -334
  63. package/dist/e2b.d.ts +2 -8
  64. package/dist/e2b.js +16 -22
  65. package/dist/index.d.ts +8 -11
  66. package/dist/index.js +13 -11
  67. package/dist/isolation.js +2 -2
  68. package/dist/janitor.d.ts +18 -1
  69. package/dist/janitor.js +67 -19
  70. package/dist/kernel.d.ts +3 -5
  71. package/dist/kernel.js +19 -16
  72. package/dist/kinds.d.ts +54 -34
  73. package/dist/kinds.js +19 -117
  74. package/dist/labels.d.ts +12 -0
  75. package/dist/labels.js +39 -1
  76. package/dist/{local.d.ts → local-chrome.d.ts} +5 -8
  77. package/dist/{local.js → local-chrome.js} +19 -16
  78. package/dist/local-supervisor.d.ts +3 -3
  79. package/dist/local-supervisor.js +3 -3
  80. package/dist/modal.d.ts +3 -22
  81. package/dist/modal.js +15 -31
  82. package/dist/mount-archil.js +4 -4
  83. package/dist/orgo-channel.js +16 -13
  84. package/dist/orgo-desktop.d.ts +153 -0
  85. package/dist/orgo-desktop.js +1614 -0
  86. package/dist/orgo-names.d.ts +52 -0
  87. package/dist/orgo-names.js +84 -0
  88. package/dist/orgo.d.ts +18 -15
  89. package/dist/orgo.js +46 -107
  90. package/dist/phone-harness.d.ts +4 -10
  91. package/dist/phone-harness.js +45 -46
  92. package/dist/provider.d.ts +91 -10
  93. package/dist/provider.js +42 -0
  94. package/dist/providers.d.ts +23 -24
  95. package/dist/providers.js +14 -17
  96. package/dist/result.d.ts +11 -1
  97. package/dist/result.js +11 -0
  98. package/dist/test-connection.js +2 -2
  99. 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,14 +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 NetworkForm, 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
- /** The network an Orgo desktop's programs get: none, a network of their own. */
10
- export declare const NETWORK: readonly NetworkForm[];
11
- /** 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
+ */
12
14
  export declare const CAPABILITIES: readonly KindCapabilities[];
13
15
  /** The conformance CLI's module for Orgo: its live switch, the run's 1 h cap and the drifted twin. */
14
16
  export declare const conformance: () => Promise<typeof import("./conformance/orgo.js")>;
@@ -60,8 +62,6 @@ export interface OrgoProviderOptions {
60
62
  /** The addresses the probe tries, host:port over TCP or host:port/udp, to show none of them answers. */
61
63
  probeTargets?: string[];
62
64
  }
63
- /** Orgo's base desktop, no template: the image a spec names for a plain Linux desktop, and the default for kind desktop. */
64
- export declare const ORGO_BASE_IMAGE = "linux";
65
65
  /** The labels file: every label, the deadline and its most, the image and sizes, root's, readable by all. */
66
66
  export declare const LABELS_FILE = "/opt/agentrun/labels.json";
67
67
  /**
@@ -74,13 +74,6 @@ export declare const LABELS_FILE = "/opt/agentrun/labels.json";
74
74
  * nothing of its own loses a socket.
75
75
  */
76
76
  export declare const LOCKDOWN_SCRIPT: string;
77
- /**
78
- * The name of a computer with these labels: computer-<hex>, then -r<the run label's hash> and -e<the epoch label> when
79
- * the labels carry a run and an epoch that is one, then -d<the deadline> when given: whole seconds since the epoch,
80
- * 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
81
- * value. Everything but the deadline is the name's stable part, which a rename on extend keeps.
82
- */
83
- export declare function orgoName(labels: Record<string, string>, hex: string, deadline?: Date): string;
84
77
  /**
85
78
  * Orgo desktops: see the module's header. A spec's image is "linux" (Orgo's base desktop) or an Orgo template
86
79
  * (namespace/name@version); cpus and memoryMb are Orgo's sizes; the network is none.
@@ -121,7 +114,7 @@ export declare class OrgoProvider implements ComputerProvider {
121
114
  }>>;
122
115
  network(ref: ComputerRef, policy?: NetworkSpec, { signal }?: CallContext): Promise<Result<NetworkPolicy>>;
123
116
  /** delete: idempotent, a computer Orgo no longer has is done; it waits until Orgo no longer has it. No stop. */
124
- release(ref: ComputerRef, how: "stop" | "delete", { signal }?: CallContext): Promise<Result<void>>;
117
+ release(ref: ComputerRef, how: ReleaseHow, { signal }?: CallContext): Promise<Result<void>>;
125
118
  /**
126
119
  * Moves the deadline to now + ttlMs, never earlier and never past the most the labels file holds (create's time plus
127
120
  * the cap): Orgo's end first, in whole hours with an Idempotency-Key, so it never ends the computer before init does;
@@ -137,5 +130,15 @@ export declare class OrgoProvider implements ComputerProvider {
137
130
  * An OrgoProvider from its options alone, its key included: it reads no environment. Serve passes apiKey from its
138
131
  * ORGO_API_KEY setting and its workspace; the conformance module reads COMPUTER_ORGO_* (settingsFromEnv).
139
132
  */
140
- 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;
141
144
  export type { OrgoChannel, OrgoStart, OrgoStream, OrgoWebSocketFactory } from "./orgo-channel.js";
package/dist/orgo.js CHANGED
@@ -16,23 +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 { DAEMON_IN_COMPUTER, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, SOCKET_DIR, WORK } from "./drift.js";
21
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 { checkGpu, 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 = [];
30
- /** The network an Orgo desktop's programs get: none, a network of their own. */
31
- export const NETWORK = ["none"];
34
+ export const MOUNT = ORGO.mounts;
32
35
  /** The groups every Orgo computer offers: a Linux shell, files and processes, and the desktop's screen and input. */
33
36
  const GROUPS = ["exec", "files", "processes", ...DESKTOP_GROUPS];
34
- /** What a built provider declares, known without building one: one configuration, a Linux desktop (the registry's entry). */
35
- 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;
36
42
  /** The conformance CLI's module for Orgo: its live switch, the run's 1 h cap and the drifted twin. */
37
43
  export const conformance = () => import("./conformance/orgo.js");
38
44
  const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
@@ -44,15 +50,10 @@ const RAM_GB = [4, 8, 16, 32];
44
50
  const CPU_FOR_RAM = { 4: 1, 8: 2, 16: 4, 32: 6 };
45
51
  /** The vCPUs a computer may ask for on its own (8 needs Orgo to set the account up). */
46
52
  const CPUS = [0.5, 1, 2, 4, 6];
47
- const NAME_MAX = 80;
48
- /** A name of this provider's making: computer-<12 hex>, the run label's hash, the epoch label, the deadline (base 36 s). */
49
- 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}))?$/;
50
53
  /** An Orgo template: namespace/name@version. */
51
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}$/;
52
- /** Orgo's base desktop, no template: the image a spec names for a plain Linux desktop, and the default for kind desktop. */
53
- 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. */
54
56
  const BASE = ORGO_BASE_IMAGE;
55
- const COMPUTER_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
56
57
  const WORKSPACE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
57
58
  const USER = /^(\d+):(\d+)$/;
58
59
  const DISPLAY = /^:(\d{1,5})(?:\.\d{1,5})?$/;
@@ -69,7 +70,7 @@ const DELETE_TRIES = 5;
69
70
  const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb", "labels", "gpu"]);
70
71
  /** The states in which a computer runs, or is on its way to. */
71
72
  const RUNNING = new Set(["running", "creating", "restarting", "updating", "resuming"]);
72
- /** Why a network other than "none" is refused (NETWORK is the forms it makes). */
73
+ /** Why a network other than "none" is refused: this configuration makes none alone. */
73
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';
74
75
  /** The scripts the provider runs as root, each marked on its first line, its arguments after it. */
75
76
  const X11_SCRIPT = ["# agentrun-computer: orgo-x11", "s=$1", '[ -S "$s" ] || { echo "no X socket at $s"; exit 1; }'].join("\n");
@@ -127,7 +128,6 @@ export const LOCKDOWN_SCRIPT = [
127
128
  "EOF",
128
129
  "exit $failed",
129
130
  ].join("\n");
130
- const show = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
131
131
  const seconds = (ms) => `${ms / 1000} s`;
132
132
  const pause = (ms, signal) => new Promise((done) => {
133
133
  const timer = setTimeout(finish, ms);
@@ -141,77 +141,6 @@ const pause = (ms, signal) => new Promise((done) => {
141
141
  else
142
142
  signal?.addEventListener("abort", finish, { once: true });
143
143
  });
144
- /**
145
- * The name of a computer with these labels: computer-<hex>, then -r<the run label's hash> and -e<the epoch label> when
146
- * the labels carry a run and an epoch that is one, then -d<the deadline> when given: whole seconds since the epoch,
147
- * 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
148
- * value. Everything but the deadline is the name's stable part, which a rename on extend keeps.
149
- */
150
- export function orgoName(labels, hex, deadline) {
151
- const run = labels[RUN_LABEL];
152
- const epoch = labels[EPOCH_LABEL];
153
- 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}` : ""}`;
154
- return deadline === undefined ? stable : withDeadline(stable, deadline);
155
- }
156
- /** A name's stable part with this deadline. */
157
- function withDeadline(stable, deadline) {
158
- return `${stable}-d${Math.ceil(deadline.getTime() / 1000).toString(36)}`;
159
- }
160
- /** What a name of this provider's making says, or undefined for any other name: its stable part, and its deadline. */
161
- function nameParts(name) {
162
- const match = typeof name === "string" ? NAME.exec(name) : null;
163
- if (match === null)
164
- return undefined;
165
- const seconds = match[4] === undefined ? Number.NaN : Number.parseInt(match[4], 36);
166
- return {
167
- hex: match[1],
168
- ...(match[2] ? { run: match[2] } : {}),
169
- ...(match[3] !== undefined ? { epoch: match[3] } : {}),
170
- stable: name.replace(/-d[0-9a-z]+$/, ""),
171
- ...(Number.isSafeInteger(seconds) ? { deadline: new Date(seconds * 1000) } : {}),
172
- };
173
- }
174
- /** Whether two names are one computer's: their stable parts are the same (the deadline moves with extend). */
175
- const sameComputer = (a, b) => nameParts(a)?.stable !== undefined && nameParts(a)?.stable === nameParts(b)?.stable;
176
- function labelProblem(key, value) {
177
- if (typeof value !== "string")
178
- return `the label ${key} must be a string`;
179
- if (key === "" || key.includes("\0") || value.includes("\0"))
180
- return `the label ${JSON.stringify(key)} must be a non-empty name, and neither holds a NUL byte`;
181
- if (key === COMPUTER_LABEL || key.startsWith(`${COMPUTER_LABEL}.`))
182
- return `the label ${key} is in the provider's own namespace (${COMPUTER_LABEL})`;
183
- return undefined;
184
- }
185
- function filterProblem(labels) {
186
- if (typeof labels !== "object" || labels === null || Array.isArray(labels))
187
- return "labels must map names to strings";
188
- for (const [key, value] of Object.entries(labels)) {
189
- if (typeof value !== "string" || key === "" || key.includes("\0") || value.includes("\0"))
190
- return `the label ${JSON.stringify(key)} must be a non-empty name and a string, with no NUL byte`;
191
- }
192
- return undefined;
193
- }
194
- /** Why ref is not an Orgo computer's ref, or undefined. */
195
- function refProblem(ref) {
196
- if (typeof ref?.name !== "string" || nameParts(ref.name) === undefined)
197
- return `${String(ref?.name)} is not the name of an Orgo computer of this provider (computer-<12 hex digits>...)`;
198
- if (typeof ref.id !== "string" || !COMPUTER_ID.test(ref.id))
199
- return `${String(ref.id)} is not an Orgo computer id`;
200
- return undefined;
201
- }
202
- /** The labels file as written, or why it is not. */
203
- function labelsOf(text) {
204
- try {
205
- const value = JSON.parse(text);
206
- if (typeof value?.name === "string" && typeof value.labels === "object" && value.labels !== null && typeof value.deadline === "string" && typeof value.maxDeadline === "string" && typeof value.image === "string") {
207
- return value;
208
- }
209
- }
210
- catch {
211
- // Said below.
212
- }
213
- return `the labels file ${LABELS_FILE} is not the one create writes`;
214
- }
215
144
  /**
216
145
  * Orgo desktops: see the module's header. A spec's image is "linux" (Orgo's base desktop) or an Orgo template
217
146
  * (namespace/name@version); cpus and memoryMb are Orgo's sizes; the network is none.
@@ -287,7 +216,8 @@ export class OrgoProvider {
287
216
  return {
288
217
  kind: "desktop",
289
218
  lifetime: "janitor",
290
- network: [...NETWORK],
219
+ // This configuration's form, one of Orgo's descriptor's: none (the Windows desktop's is open).
220
+ network: ["none"],
291
221
  networkReadBack: false,
292
222
  isolation: "vm",
293
223
  os: "linux",
@@ -307,7 +237,7 @@ export class OrgoProvider {
307
237
  const { image, lifetimeMs, network, cpus, memoryMb, labels, mount } = given;
308
238
  if (image !== BASE && !(typeof image === "string" && TEMPLATE.test(image)))
309
239
  refuse("image", `an image is "${BASE}" (Orgo's base desktop) or an Orgo template, namespace/name@version`);
310
- refusals.push(...checkLifetime(lifetimeMs, this.capabilities()));
240
+ refusals.push(...checkTenure(given, this.capabilities(), "Orgo"));
311
241
  if (network !== "none")
312
242
  refuse("network", NETWORK_REFUSAL);
313
243
  if (memoryMb !== undefined && !RAM_GB.some((gb) => gb * 1024 === memoryMb))
@@ -351,7 +281,7 @@ export class OrgoProvider {
351
281
  return fail("aborted", "create was aborted before Orgo was called");
352
282
  const labels = { ...spec.labels };
353
283
  const now = Date.now();
354
- const deadline = new Date(now + spec.lifetimeMs).toISOString();
284
+ const deadline = new Date(now + runLifetimeMs(spec)).toISOString();
355
285
  const maxDeadline = new Date(now + this.#maxLifetimeMs).toISOString();
356
286
  // The janitor's deadline is in the name, so list() and the sweep read it with nothing run inside.
357
287
  const name = orgoName(labels, randomBytes(6).toString("hex"), new Date(deadline));
@@ -366,7 +296,7 @@ export class OrgoProvider {
366
296
  ram,
367
297
  cpu,
368
298
  // Orgo's end, the vendor's backstop: whole hours, deleting the computer and its disk. init ends it on time.
369
- ends_in_hours: Math.max(1, Math.ceil(spec.lifetimeMs / HOUR)),
299
+ ends_in_hours: Math.max(1, Math.ceil(runLifetimeMs(spec) / HOUR)),
370
300
  ...(spec.image === BASE ? {} : { template_ref: spec.image }),
371
301
  };
372
302
  const made = await this.#rest.request("POST", "/computers", { body, timeoutMs: this.#timeouts.createMs, ...(signal ? { signal } : {}) });
@@ -378,7 +308,7 @@ export class OrgoProvider {
378
308
  }
379
309
  const id = made.value?.id;
380
310
  if (typeof id !== "string" || !COMPUTER_ID.test(id))
381
- 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)}`);
382
312
  const ref = { id, name };
383
313
  const file = { name, labels, deadline, maxDeadline, image: spec.image, cpus: cpu, memoryMb: ram * 1024 };
384
314
  const prepared = await this.#prepare(ref, made.value.status, file, daemon, signal);
@@ -500,7 +430,7 @@ export class OrgoProvider {
500
430
  if (last === "running")
501
431
  return ok(undefined);
502
432
  if (!RUNNING.has(last))
503
- return fail("orgo", `Orgo read ${ref.name} ${last}, not running`);
433
+ return vendorFail("orgo", `Orgo read ${ref.name} ${last}, not running`);
504
434
  if (Date.now() >= until)
505
435
  return fail("timeout", `Orgo did not read ${ref.name} running within ${seconds(this.#timeouts.createMs)}; it last read ${last}`);
506
436
  await pause(this.#timeouts.pollMs, signal);
@@ -522,7 +452,7 @@ export class OrgoProvider {
522
452
  return read;
523
453
  if (read.value.exitCode !== 0)
524
454
  return fail("refused", `${ref.name} has no labels file ${LABELS_FILE} to read (exit ${read.value.exitCode})`);
525
- const file = labelsOf(read.value.output);
455
+ const file = labelsOf(read.value.output, LABELS_FILE);
526
456
  return typeof file === "string" ? fail("refused", `${ref.name}: ${file}`) : ok(file);
527
457
  }
528
458
  /**
@@ -585,7 +515,7 @@ export class OrgoProvider {
585
515
  return fail("timeout", `the daemon in ${ref.name} did not answer hello within ${seconds(helloMs)}`);
586
516
  if (hello.error.code !== "gone")
587
517
  return hello;
588
- 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 };
589
519
  }
590
520
  return ok({ client, hello: hello.value, close });
591
521
  }
@@ -605,13 +535,18 @@ export class OrgoProvider {
605
535
  if (!read.ok)
606
536
  return read;
607
537
  if (typeof read.value?.name !== "string" || typeof read.value.status !== "string")
608
- 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`);
609
539
  return ok(read.value);
610
540
  }
611
541
  /** Whether Orgo's record is a computer of this provider: its name's shape, in this workspace. */
612
542
  #ours(record, name) {
613
543
  // A ref's name matches by its stable part: extend renames the computer with its new deadline.
614
- 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"));
615
550
  }
616
551
  /** This provider's computer for ref, as Orgo reads it, or why not. */
617
552
  async #own(ref, signal) {
@@ -679,7 +614,7 @@ export class OrgoProvider {
679
614
  return read;
680
615
  const desktops = read.value?.desktops;
681
616
  if (!Array.isArray(desktops))
682
- 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`);
683
618
  return ok(desktops.filter((one) => typeof one?.id === "string" && typeof one.name === "string").map((one) => ({ ...one, workspace_id: this.#workspaceId })));
684
619
  }
685
620
  /** The live view: screen.watch on a connection of the watch's own (daemonWatch), never Orgo's VNC (proxy only). */
@@ -819,7 +754,9 @@ export class OrgoProvider {
819
754
  const infos = [];
820
755
  for (const record of listed.value) {
821
756
  const parts = nameParts(record.name);
822
- 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"))
823
760
  continue;
824
761
  if (labels[RUN_LABEL] !== undefined && parts.run !== runHash(labels[RUN_LABEL]))
825
762
  continue;
@@ -833,8 +770,9 @@ export class OrgoProvider {
833
770
  ...(labels[RUN_LABEL] !== undefined ? { [RUN_LABEL]: labels[RUN_LABEL] } : parts.run !== undefined ? { [RUN_HASH_LABEL]: parts.run } : {}),
834
771
  ...(parts.epoch !== undefined ? { [EPOCH_LABEL]: parts.epoch } : {}),
835
772
  };
836
- // The janitor's deadline is the name's; a name of an older make has none, and Orgo's end stands for it.
837
- 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;
838
776
  if (others.length > 0) {
839
777
  if (record.status !== "running")
840
778
  continue;
@@ -844,7 +782,6 @@ export class OrgoProvider {
844
782
  if (!others.every((key) => file.value.labels[key] === labels[key]))
845
783
  continue;
846
784
  read = { ...file.value.labels };
847
- deadline = parts.deadline ?? new Date(file.value.deadline);
848
785
  }
849
786
  infos.push({ ref, labels: read, deadline, state: running ? "running" : "stopped", network: "none" });
850
787
  }
@@ -984,10 +921,12 @@ export class OrgoProvider {
984
921
  return ok({ deadline: took });
985
922
  }
986
923
  }
987
- /**
988
- * An OrgoProvider from its options alone, its key included: it reads no environment. Serve passes apiKey from its
989
- * ORGO_API_KEY setting and its workspace; the conformance module reads COMPUTER_ORGO_* (settingsFromEnv).
990
- */
991
924
  export function create(options) {
992
- 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);
993
932
  }
@@ -1,21 +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 NetworkForm, 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 network a cloud phone runs on: the vendor's own, open; it cannot be closed or narrowed. */
14
- export declare const NETWORK: readonly NetworkForm[];
15
- /** 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. */
16
12
  export declare const CAPABILITIES: readonly KindCapabilities[];
17
- /** The image a phone is read back by: a cloud Android has none to choose, so a setting that names none takes this. */
18
- export declare const PHONE_IMAGE = "android";
19
13
  /** The longest lifetime by default: a rented phone bills by the minute. */
20
14
  export declare const DEFAULT_MAX_LIFETIME_MS: number;
21
15
  /** How long create waits for a phone to be ready by default: the service's own CLI waits 240 s. */
@@ -155,7 +149,7 @@ export declare class PhoneHarnessProvider implements ComputerProvider {
155
149
  }, context?: CallContext): Promise<Result<AttachedComputer>>;
156
150
  list(labels: Record<string, string>, context?: CallContext): Promise<Result<ComputerInfo[]>>;
157
151
  network(ref: ComputerRef, policy?: NetworkSpec): Promise<Result<NetworkPolicy>>;
158
- release(ref: ComputerRef, how: "stop" | "delete"): Promise<Result<void>>;
152
+ release(ref: ComputerRef, how: ReleaseHow): Promise<Result<void>>;
159
153
  connect(ref: ComputerRef): Promise<Result<ComputerConnection>>;
160
154
  /**
161
155
  * The live view: the phone client's screen.watch on a connection of the watch's own (daemonWatch), PNG frames from