@parcha/agentrun-computer 0.1.0-beta.34 → 0.1.0-beta.36

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 (107) hide show
  1. package/README.md +251 -46
  2. package/box/Dockerfile +3 -1
  3. package/box/agentrun-archil +59 -7
  4. package/box/build-daytona.py +20 -4
  5. package/dist/browser.d.ts +73 -23
  6. package/dist/browser.js +141 -17
  7. package/dist/browserbase.d.ts +48 -25
  8. package/dist/browserbase.js +176 -29
  9. package/dist/chrome.d.ts +3 -4
  10. package/dist/chrome.js +6 -11
  11. package/dist/computerd-linux-amd64 +0 -0
  12. package/dist/computerd-linux-arm64 +0 -0
  13. package/dist/conformance/browserbase.js +1 -1
  14. package/dist/conformance/cases/provider.js +78 -3
  15. package/dist/conformance/daytona.d.ts +4 -0
  16. package/dist/conformance/daytona.js +7 -1
  17. package/dist/conformance/e2b.js +2 -1
  18. package/dist/conformance/fixture.js +24 -2
  19. package/dist/conformance/kernel.js +1 -1
  20. package/dist/conformance/kind.js +2 -1
  21. package/dist/conformance/{local.d.ts → local-chrome.d.ts} +7 -7
  22. package/dist/conformance/{local.js → local-chrome.js} +11 -11
  23. package/dist/conformance/orgo.d.ts +11 -5
  24. package/dist/conformance/orgo.js +37 -8
  25. package/dist/conformance/phone-harness.js +2 -1
  26. package/dist/conformance/report.js +3 -2
  27. package/dist/conformance/runner.js +25 -7
  28. package/dist/conformance/types.d.ts +21 -8
  29. package/dist/conformance/types.js +10 -0
  30. package/dist/conformance/windows-fixture.d.ts +1 -0
  31. package/dist/conformance/windows-fixture.js +37 -0
  32. package/dist/daytona.d.ts +16 -35
  33. package/dist/daytona.js +87 -95
  34. package/dist/descriptor.d.ts +116 -0
  35. package/dist/descriptor.js +92 -0
  36. package/dist/descriptors/browserbase.d.ts +25 -0
  37. package/dist/descriptors/browserbase.js +20 -0
  38. package/dist/descriptors/daytona.d.ts +83 -0
  39. package/dist/descriptors/daytona.js +81 -0
  40. package/dist/descriptors/docker.d.ts +12 -0
  41. package/dist/descriptors/docker.js +17 -0
  42. package/dist/descriptors/e2b.d.ts +22 -0
  43. package/dist/descriptors/e2b.js +19 -0
  44. package/dist/descriptors/index.d.ts +256 -0
  45. package/dist/descriptors/index.js +19 -0
  46. package/dist/descriptors/kernel.d.ts +21 -0
  47. package/dist/descriptors/kernel.js +17 -0
  48. package/dist/descriptors/local-chrome.d.ts +17 -0
  49. package/dist/descriptors/local-chrome.js +21 -0
  50. package/dist/descriptors/modal.d.ts +54 -0
  51. package/dist/descriptors/modal.js +48 -0
  52. package/dist/descriptors/orgo.d.ts +99 -0
  53. package/dist/descriptors/orgo.js +49 -0
  54. package/dist/descriptors/phone-harness.d.ts +33 -0
  55. package/dist/descriptors/phone-harness.js +23 -0
  56. package/dist/descriptors/shared.d.ts +7 -0
  57. package/dist/descriptors/shared.js +6 -0
  58. package/dist/desktop.d.ts +4 -4
  59. package/dist/desktop.js +4 -4
  60. package/dist/docker/egress.d.ts +5 -4
  61. package/dist/docker/egress.js +7 -6
  62. package/dist/docker/image.js +17 -15
  63. package/dist/docker/inspect.d.ts +147 -0
  64. package/dist/docker/inspect.js +335 -0
  65. package/dist/docker.d.ts +6 -6
  66. package/dist/docker.js +53 -47
  67. package/dist/drift.d.ts +3 -145
  68. package/dist/drift.js +5 -334
  69. package/dist/e2b.d.ts +2 -8
  70. package/dist/e2b.js +17 -23
  71. package/dist/index.d.ts +9 -12
  72. package/dist/index.js +14 -12
  73. package/dist/isolation.js +2 -2
  74. package/dist/janitor.d.ts +20 -2
  75. package/dist/janitor.js +67 -19
  76. package/dist/kernel.d.ts +19 -29
  77. package/dist/kernel.js +110 -32
  78. package/dist/kinds.d.ts +59 -34
  79. package/dist/kinds.js +19 -117
  80. package/dist/labels.d.ts +20 -0
  81. package/dist/labels.js +62 -1
  82. package/dist/{local.d.ts → local-chrome.d.ts} +8 -9
  83. package/dist/{local.js → local-chrome.js} +26 -19
  84. package/dist/local-supervisor.d.ts +3 -3
  85. package/dist/local-supervisor.js +3 -3
  86. package/dist/modal.d.ts +6 -25
  87. package/dist/modal.js +86 -88
  88. package/dist/mount-archil.d.ts +25 -3
  89. package/dist/mount-archil.js +43 -12
  90. package/dist/orgo-channel.js +16 -13
  91. package/dist/orgo-desktop.d.ts +162 -0
  92. package/dist/orgo-desktop.js +1856 -0
  93. package/dist/orgo-names.d.ts +178 -0
  94. package/dist/orgo-names.js +287 -0
  95. package/dist/orgo.d.ts +34 -20
  96. package/dist/orgo.js +424 -173
  97. package/dist/phone-harness.d.ts +7 -12
  98. package/dist/phone-harness.js +70 -54
  99. package/dist/protocol.d.ts +5 -0
  100. package/dist/provider.d.ts +153 -10
  101. package/dist/provider.js +48 -1
  102. package/dist/providers.d.ts +23 -24
  103. package/dist/providers.js +14 -17
  104. package/dist/result.d.ts +11 -1
  105. package/dist/result.js +11 -0
  106. package/dist/test-connection.js +2 -2
  107. package/package.json +42 -2
package/dist/kinds.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { DescriptorKey, DescriptorSetting, HostCommand, ParkedConfiguration, ProviderDescriptor } from "./descriptor.js";
1
2
  import type { MountKind } from "./mount.js";
2
3
  import type { ComputerKind, Group } from "./protocol.js";
3
4
  import type { ComputerCapabilities, NetworkForm } from "./provider.js";
@@ -20,54 +21,78 @@ export interface SettingKindSpec {
20
21
  export declare const SETTING_KINDS: Readonly<Record<ComputerSettingKind, SettingKindSpec>>;
21
22
  /** Every setting kind, in the table's order. */
22
23
  export declare const SETTING_KIND_NAMES: ComputerSettingKind[];
23
- /** The capabilities serves() and kindOf() read, and the GPUs a configuration offers (Settings' GPU choice). */
24
- export type KindCapabilities = Pick<ComputerCapabilities, "kind" | "groups" | "gpu">;
24
+ /**
25
+ * The capabilities serves() and kindOf() read: one configuration a provider offers, with the GPUs it offers (Settings'
26
+ * GPU choice), and whether it keeps a computer for an agent (`persistence`, as its built provider declares it: Settings'
27
+ * persistent choice). In a descriptor, `image` is the name an agent's setting selects it by (Orgo's `windows`), the image
28
+ * its computer starts from, and `options` are what create() takes to build it ({ os: "windows" }), beside the keys. A
29
+ * configuration with no image is the one a setting that names none gets, as is the one whose image is the kind's
30
+ * defaultImage.
31
+ */
32
+ export type KindCapabilities = Pick<ComputerCapabilities, "kind" | "groups" | "gpu" | "persistence"> & {
33
+ readonly image?: string;
34
+ readonly options?: Readonly<Record<string, unknown>>;
35
+ };
25
36
  /** Why capabilities do not serve a setting kind, in words; none when they do. */
26
37
  export declare function servingRefusals(capabilities: KindCapabilities, kind: ComputerSettingKind): string[];
27
38
  /** Whether a provider with these capabilities serves the kind: its machine kind is one of the kind's, and it declares every required group. */
28
39
  export declare function serves(capabilities: KindCapabilities, kind: ComputerSettingKind): boolean;
29
40
  /** The setting kind these capabilities serve, or undefined when they serve none. Machine kinds are apart, so at most one. */
30
41
  export declare function kindOf(capabilities: KindCapabilities): ComputerSettingKind | undefined;
31
- /** One key a provider takes in Settings: its serve-side name (Settings accepts only these), and whether it is needed. */
32
- export interface ProviderKey {
33
- name: string;
34
- required: boolean;
35
- }
36
- /** A provider as Settings shows it. */
42
+ /** The images a kind's configurations offer by name (`serving`: those that serve it), the kind's default first when it is one. */
43
+ export declare function imagesOf(serving: readonly Pick<KindCapabilities, "image">[], defaultImage: string | undefined): string[];
44
+ /**
45
+ * The configuration a setting selects among a kind's (`serving`): the one its image names; with none named, the one
46
+ * whose image is the kind's default, else one with no image, else the first. Undefined when the image names none.
47
+ */
48
+ export declare function configurationOf<Configuration extends Pick<KindCapabilities, "image">>(serving: readonly Configuration[], image: string | undefined, defaultImage: string | undefined): Configuration | undefined;
49
+ /** A provider as Settings shows it: its descriptor's data, and the setting kinds it serves. */
37
50
  export interface ProviderEntry {
38
- /** Its id: a line of the provider registry (providers.ts) once its file lands. */
39
- id: string;
40
- label: string;
51
+ /** Its id: a line of the provider registry (providers.ts). */
52
+ readonly id: string;
53
+ readonly label: string;
41
54
  /** Derived: the setting kinds its capabilities serve (serves), never written by hand. */
42
- kinds: readonly ComputerSettingKind[];
43
- /** The serve-side key names only; never a value. */
44
- keys: readonly ProviderKey[];
45
- /** The mount kinds its computers take; [] cannot mount the run's folder. Its module's MOUNT, once its file lands. */
46
- mounts: readonly MountKind[];
55
+ readonly kinds: readonly ComputerSettingKind[];
56
+ /** The serve-side key names and the options they fill; never a value. */
57
+ readonly keys: readonly DescriptorKey[];
58
+ /** Settings that are no key but go to its options. */
59
+ readonly settings?: readonly DescriptorSetting[];
60
+ /** The mount kinds its computers take; [] cannot mount the run's folder. */
61
+ readonly mounts: readonly MountKind[];
47
62
  /**
48
- * The network forms its computers make: its module's NETWORK, which its capabilities().network returns. ["none"]: a
49
- * remote computer whose programs run in a network of their own; ["open"]: the vendor's own network, which no
50
- * allowlist of this server reaches; Docker's makes all three.
63
+ * The network forms its computers make, its descriptor's: ["none"], a remote computer whose programs run in a network
64
+ * of their own; ["open"], the vendor's own network, which no allowlist of this server reaches; Docker's all three.
51
65
  */
52
- network: readonly NetworkForm[];
66
+ readonly network: readonly NetworkForm[];
53
67
  /** The vendor bills by time; prices are the vendor's page, not ours. */
54
- metered: boolean;
68
+ readonly metered: boolean;
69
+ /** Its static capabilities: the machine kind and groups of each configuration it offers. */
70
+ readonly capabilities: readonly KindCapabilities[];
55
71
  /**
56
- * Its static capabilities: the machine kind and groups of each configuration it offers. Its module's CAPABILITIES,
57
- * once its file lands, and each built configuration's capabilities().
72
+ * The image a computer of each setting kind starts from when its setting names none. A kind with no entry has no
73
+ * default, and the caller refuses the setting in words. Docker's sandbox has none: its image is made (prepareImage).
58
74
  */
59
- capabilities: readonly KindCapabilities[];
60
- /**
61
- * The image a computer of each setting kind starts from when its setting names none, each the constant its provider
62
- * module owns. A kind with no entry has no default, and the caller refuses the setting in words. Docker's sandbox has
63
- * none: serve builds its image itself (DOCKER_RECIPE).
64
- */
65
- defaultImage?: Partial<Record<ComputerSettingKind, string>>;
75
+ readonly defaultImage?: Partial<Record<ComputerSettingKind, string>>;
76
+ /** Its built providers make or pull their image before the first create (prepareImage()). */
77
+ readonly prepareImage?: boolean;
78
+ /** The server's environment variable whose value, when set, is the image of every computer of it (descriptor.ts). */
79
+ readonly imageEnv?: string;
80
+ /** Its computers run on this machine's container engine. */
81
+ readonly local?: boolean;
82
+ /** create() takes a ledger the server keeps for it, as this option. */
83
+ readonly ledger?: {
84
+ readonly option: string;
85
+ };
86
+ /** The server's environment variables its provider reads on this machine, passed as options.env (descriptor.ts). */
87
+ readonly hostEnv?: readonly string[];
88
+ /** A program its computers need on this machine's PATH, and the machines it is built for (descriptor.ts). */
89
+ readonly hostCommand?: HostCommand;
90
+ /** Configurations it builds but does not offer yet, each with why: a setting naming one's image is refused as parked. */
91
+ readonly parked?: readonly ParkedConfiguration[];
66
92
  }
67
- /**
68
- * Every provider Settings offers, each with its provider file in the registry;
69
- * a unit test then holds each to its module (CAPABILITIES, MOUNT, NETWORK). daytona, modal and e2b take archil mounts.
70
- */
93
+ /** A descriptor as Settings shows it: its data, and the setting kinds its capabilities serve, derived by serves(). */
94
+ export declare function entryOf(descriptor: ProviderDescriptor): ProviderEntry;
95
+ /** Every provider Settings offers: each built-in descriptor (descriptors/index.ts), as entryOf gives it. */
71
96
  export declare const PROVIDERS: readonly ProviderEntry[];
72
97
  /** What testConnection is given: the provider's keys by their serve-side names, and the caller's signal. */
73
98
  export interface TestConnectionOptions {
package/dist/kinds.js CHANGED
@@ -1,17 +1,4 @@
1
- // The kind registry: the computer an agent is given, its setting kind, and the providers Settings offers for it. Two
2
- // axes: the machine kind is the protocol's (capabilities().kind, KIND_SHAPES); the setting kind is what an agent is
3
- // given in Settings, `computer: { kind, provider? }`, as machine kinds and capability groups. Whether a provider serves
4
- // a setting kind is computed from its capabilities alone (serves), never kept beside them: a provider that drops a
5
- // group stops serving the kind. The model's tools are not here: they live in the kernel's tool registry, keyed by
6
- // these groups.
7
- // The default images are values: each from the provider module that owns it. Those modules import this one for types
8
- // alone, so this is no import cycle.
9
- import { BROWSER_IMAGE } from "./browser.js";
10
- import { DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU } from "./daytona.js";
11
- import { E2B_BASE_TEMPLATE, E2B_DESKTOP_TEMPLATE } from "./e2b.js";
12
- import { MODAL_DEFAULT_IMAGE, MODAL_GPU } from "./modal.js";
13
- import { ORGO_BASE_IMAGE } from "./orgo.js";
14
- import { PHONE_IMAGE } from "./phone-harness.js";
1
+ import { DESCRIPTORS } from "./descriptors/index.js";
15
2
  export const SETTING_KINDS = {
16
3
  none: { machineKinds: [], required: [], optional: [] },
17
4
  sandbox: { machineKinds: ["linux"], required: ["exec", "files", "processes"], optional: [] },
@@ -45,109 +32,24 @@ export function serves(capabilities, kind) {
45
32
  export function kindOf(capabilities) {
46
33
  return SETTING_KIND_NAMES.find((kind) => serves(capabilities, kind));
47
34
  }
48
- const SANDBOX = { kind: "linux", groups: ["exec", "files", "processes"] };
49
- const LINUX_DESKTOP = { kind: "desktop", groups: ["exec", "files", "processes", "screen", "input.pointer", "input.keys"] };
50
- /** A provider's GPU capability as its configuration carries it: a deep copy of the module's own. */
51
- const gpuOf = (gpu) => structuredClone(gpu);
52
- /** An entry with its kinds derived from its capabilities. */
53
- function entry(fields) {
54
- return { ...fields, kinds: SETTING_KIND_NAMES.filter((kind) => fields.capabilities.some((one) => serves(one, kind))) };
35
+ /** The images a kind's configurations offer by name (`serving`: those that serve it), the kind's default first when it is one. */
36
+ export function imagesOf(serving, defaultImage) {
37
+ const names = [...new Set(serving.flatMap((one) => (one.image === undefined ? [] : [one.image])))];
38
+ return defaultImage !== undefined && names.includes(defaultImage) ? [defaultImage, ...names.filter((name) => name !== defaultImage)] : names;
55
39
  }
56
40
  /**
57
- * Every provider Settings offers, each with its provider file in the registry;
58
- * a unit test then holds each to its module (CAPABILITIES, MOUNT, NETWORK). daytona, modal and e2b take archil mounts.
41
+ * The configuration a setting selects among a kind's (`serving`): the one its image names; with none named, the one
42
+ * whose image is the kind's default, else one with no image, else the first. Undefined when the image names none.
59
43
  */
60
- export const PROVIDERS = [
61
- entry({ id: "docker", label: "Docker", keys: [], mounts: ["bind"], network: ["none", "open", "allow"], metered: false, capabilities: [SANDBOX, LINUX_DESKTOP] }),
62
- entry({
63
- id: "daytona",
64
- label: "Daytona",
65
- keys: [
66
- { name: "DAYTONA_API_KEY", required: true },
67
- { name: "DAYTONA_API_URL", required: false },
68
- { name: "DAYTONA_TARGET", required: false },
69
- ],
70
- mounts: ["archil"],
71
- network: ["none"],
72
- metered: true,
73
- capabilities: [{ ...SANDBOX, gpu: gpuOf(DAYTONA_GPU) }],
74
- defaultImage: { sandbox: DAYTONA_DEFAULT_SNAPSHOT },
75
- }),
76
- entry({
77
- id: "modal",
78
- label: "Modal",
79
- keys: [
80
- { name: "MODAL_TOKEN_ID", required: true },
81
- { name: "MODAL_TOKEN_SECRET", required: true },
82
- ],
83
- mounts: ["archil"],
84
- network: ["none"],
85
- metered: true,
86
- capabilities: [{ ...SANDBOX, gpu: gpuOf(MODAL_GPU) }],
87
- defaultImage: { sandbox: MODAL_DEFAULT_IMAGE },
88
- }),
89
- entry({
90
- id: "e2b",
91
- label: "E2B",
92
- keys: [{ name: "E2B_API_KEY", required: true }],
93
- mounts: ["archil"],
94
- network: ["none"],
95
- metered: true,
96
- capabilities: [SANDBOX, LINUX_DESKTOP],
97
- defaultImage: { sandbox: E2B_BASE_TEMPLATE, desktop: E2B_DESKTOP_TEMPLATE },
98
- }),
99
- entry({
100
- id: "orgo",
101
- label: "Orgo",
102
- keys: [{ name: "ORGO_API_KEY", required: true }],
103
- mounts: [],
104
- network: ["none"],
105
- metered: true,
106
- capabilities: [LINUX_DESKTOP],
107
- defaultImage: { desktop: ORGO_BASE_IMAGE },
108
- }),
109
- entry({
110
- id: "phone-harness",
111
- label: "Phone harness",
112
- keys: [{ name: "PHONE_HARNESS_API_KEY", required: true }],
113
- mounts: [],
114
- network: ["open"],
115
- metered: true,
116
- capabilities: [{ kind: "android", groups: ["screen", "input.touch", "input.keys", "apps", "apps.ui_tree"] }],
117
- defaultImage: { phone: PHONE_IMAGE },
118
- }),
119
- entry({
120
- id: "browserbase",
121
- label: "Browserbase",
122
- keys: [
123
- { name: "BROWSERBASE_API_KEY", required: true },
124
- { name: "BROWSERBASE_PROJECT_ID", required: true },
125
- ],
126
- mounts: [],
127
- network: ["open"],
128
- metered: true,
129
- capabilities: [{ kind: "browser", groups: ["cdp", "stream"] }],
130
- defaultImage: { browser: BROWSER_IMAGE },
131
- }),
132
- entry({
133
- id: "kernel",
134
- label: "Kernel",
135
- keys: [{ name: "KERNEL_API_KEY", required: true }],
136
- mounts: [],
137
- network: ["open"],
138
- metered: true,
139
- capabilities: [{ kind: "browser", groups: ["cdp", "stream"] }],
140
- defaultImage: { browser: BROWSER_IMAGE },
141
- }),
142
- // This machine's Chrome: no key, nothing billed, no live view (a person watching runs it headed).
143
- entry({
144
- id: "local",
145
- label: "Local Chrome",
146
- keys: [],
147
- mounts: [],
148
- network: ["open", "allow"],
149
- metered: false,
150
- capabilities: [{ kind: "browser", groups: ["cdp"] }],
151
- defaultImage: { browser: BROWSER_IMAGE },
152
- }),
153
- ];
44
+ export function configurationOf(serving, image, defaultImage) {
45
+ if (image !== undefined)
46
+ return serving.find((one) => one.image === image);
47
+ return serving.find((one) => defaultImage !== undefined && one.image === defaultImage) ?? serving.find((one) => one.image === undefined) ?? serving[0];
48
+ }
49
+ /** A descriptor as Settings shows it: its data, and the setting kinds its capabilities serve, derived by serves(). */
50
+ export function entryOf(descriptor) {
51
+ const { load: _load, ...data } = descriptor;
52
+ return { ...data, kinds: SETTING_KIND_NAMES.filter((kind) => descriptor.capabilities.some((one) => serves(one, kind))) };
53
+ }
54
+ /** Every provider Settings offers: each built-in descriptor (descriptors/index.ts), as entryOf gives it. */
55
+ export const PROVIDERS = DESCRIPTORS.map(entryOf);
package/dist/labels.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { epochProblem } from "./mount.js";
2
+ import { type ComputerOwner } from "./provider.js";
2
3
  import { type Result } from "./result.js";
3
4
  export { epochProblem };
4
5
  /** The run a computer works for. */
@@ -11,6 +12,25 @@ export declare const RUN_HASH_LABEL = "agentrun.run.hash";
11
12
  /** The run label's hash, as a provider keeps it where the run itself doesn't fit (a computer's name): base32 of its
12
13
  * sha256, lower case, 16 letters. */
13
14
  export declare function runHash(run: string): string;
15
+ /** The agent a persistent computer belongs to, as agent:<id>. */
16
+ export declare const OWNER_LABEL = "agentrun.owner";
17
+ /** The server that agent is on, when the owner names one (owner.server). */
18
+ export declare const OWNER_SERVER_LABEL = "agentrun.owner-server";
19
+ /** The owner's idle TTL of a persistent computer, in milliseconds, in decimal: how long it may stay detached. */
20
+ export declare const IDLE_TTL_LABEL = "agentrun.idle-ttl-ms";
21
+ /**
22
+ * The labels of an agent's computer: its owner, its server when the owner names one, and its idle TTL when the owner
23
+ * set one. Throws, in words, on an owner that is not one.
24
+ */
25
+ export declare function ownerLabels(owner: ComputerOwner): Record<string, string>;
26
+ /** The labels an owner's listing filters by: its agent's, and its server's when it names one (no idle TTL). */
27
+ export declare function ownerFilter(owner: Pick<ComputerOwner, "agent" | "server">): Record<string, string>;
28
+ /**
29
+ * A computer's owner, read from its labels: undefined for a run's computer (no owner label). An owner label that is not
30
+ * agent:<id>, a server label that is not a server id, or an idle TTL that is not a decimal whole number above 0, is
31
+ * invalid, in words naming what it reads.
32
+ */
33
+ export declare function ownerOf(labels: Record<string, string> | undefined): Result<ComputerOwner | undefined>;
14
34
  /**
15
35
  * Why run is not a run id, in words, or undefined when it is one: a non-empty string with no NUL byte. That is the
16
36
  * strictest rule the providers share for a label's value (Docker, Daytona and Modal each refuse only a NUL), so every
package/dist/labels.js CHANGED
@@ -2,8 +2,13 @@
2
2
  // and computers: a new claim is epoch + 1, and it releases every computer of the run labelled with a lower epoch
3
3
  // (releaseOlder, in janitor.ts). Both names live here alone, with the run label's hash: a provider whose computers keep
4
4
  // only that (Orgo's names) lists it under RUN_HASH_LABEL, so a caller can still tell whose run a computer is.
5
+ //
6
+ // An agent's persistent computer carries its owner as more labels, set at create: agentrun.owner=agent:<id>, the
7
+ // agent's server when the owner names one, and the owner's idle TTL when it set one. The run and epoch labels then name
8
+ // the claim that holds it now.
5
9
  import { createHash } from "node:crypto";
6
10
  import { epochProblem } from "./mount.js";
11
+ import { ownerProblem } from "./provider.js";
7
12
  import { fail, ok } from "./result.js";
8
13
  export { epochProblem };
9
14
  /** The run a computer works for. */
@@ -33,8 +38,64 @@ export function runHash(run) {
33
38
  }
34
39
  return out;
35
40
  }
41
+ /** The agent a persistent computer belongs to, as agent:<id>. */
42
+ export const OWNER_LABEL = "agentrun.owner";
43
+ /** The server that agent is on, when the owner names one (owner.server). */
44
+ export const OWNER_SERVER_LABEL = "agentrun.owner-server";
45
+ /** The owner's idle TTL of a persistent computer, in milliseconds, in decimal: how long it may stay detached. */
46
+ export const IDLE_TTL_LABEL = "agentrun.idle-ttl-ms";
47
+ /** A whole number as a label holds it: decimal digits, no sign, no leading zero, no space. */
48
+ const DECIMAL = /^(?:0|[1-9][0-9]*)$/;
49
+ /**
50
+ * The labels of an agent's computer: its owner, its server when the owner names one, and its idle TTL when the owner
51
+ * set one. Throws, in words, on an owner that is not one.
52
+ */
53
+ export function ownerLabels(owner) {
54
+ const problem = ownerProblem(owner);
55
+ if (problem !== undefined)
56
+ throw new TypeError(problem);
57
+ return {
58
+ [OWNER_LABEL]: `agent:${owner.agent}`,
59
+ ...(owner.server === undefined ? {} : { [OWNER_SERVER_LABEL]: owner.server }),
60
+ ...(owner.idleTtlMs === undefined ? {} : { [IDLE_TTL_LABEL]: String(owner.idleTtlMs) }),
61
+ };
62
+ }
63
+ /** The labels an owner's listing filters by: its agent's, and its server's when it names one (no idle TTL). */
64
+ export function ownerFilter(owner) {
65
+ const { [IDLE_TTL_LABEL]: _, ...labels } = ownerLabels({ agent: owner.agent, ...(owner.server === undefined ? {} : { server: owner.server }) });
66
+ return labels;
67
+ }
68
+ /**
69
+ * A computer's owner, read from its labels: undefined for a run's computer (no owner label). An owner label that is not
70
+ * agent:<id>, a server label that is not a server id, or an idle TTL that is not a decimal whole number above 0, is
71
+ * invalid, in words naming what it reads.
72
+ */
73
+ export function ownerOf(labels) {
74
+ if (typeof labels !== "object" || labels === null || Array.isArray(labels))
75
+ return fail("invalid", "the computer's labels are not a map of names to strings");
76
+ if (!Object.hasOwn(labels, OWNER_LABEL))
77
+ return ok(undefined);
78
+ const text = labels[OWNER_LABEL];
79
+ const agent = typeof text === "string" && text.startsWith("agent:") ? text.slice("agent:".length) : undefined;
80
+ if (agent === undefined || ownerProblem({ agent }) !== undefined)
81
+ return fail("invalid", `the label ${OWNER_LABEL} reads ${JSON.stringify(text)}, not agent:<id>`);
82
+ let owner = { agent };
83
+ if (Object.hasOwn(labels, OWNER_SERVER_LABEL)) {
84
+ const server = labels[OWNER_SERVER_LABEL];
85
+ if (typeof server !== "string" || ownerProblem({ agent, server }) !== undefined)
86
+ return fail("invalid", `the label ${OWNER_SERVER_LABEL} reads ${JSON.stringify(server)}, not a server's id`);
87
+ owner = { agent, server };
88
+ }
89
+ if (!Object.hasOwn(labels, IDLE_TTL_LABEL))
90
+ return ok(owner);
91
+ const ttl = labels[IDLE_TTL_LABEL];
92
+ const idleTtlMs = typeof ttl === "string" && DECIMAL.test(ttl) ? Number(ttl) : Number.NaN;
93
+ if (!(Number.isSafeInteger(idleTtlMs) && idleTtlMs > 0))
94
+ return fail("invalid", `the label ${IDLE_TTL_LABEL} reads ${JSON.stringify(ttl)}, not a whole number of milliseconds above 0`);
95
+ return ok({ ...owner, idleTtlMs });
96
+ }
36
97
  /** An epoch as a label holds it: decimal digits, no sign, no leading zero, no space. */
37
- const EPOCH_TEXT = /^(?:0|[1-9][0-9]*)$/;
98
+ const EPOCH_TEXT = DECIMAL;
38
99
  /**
39
100
  * Why run is not a run id, in words, or undefined when it is one: a non-empty string with no NUL byte. That is the
40
101
  * strictest rule the providers share for a label's value (Docker, Daytona and Modal each refuse only a NUL), so every
@@ -1,21 +1,18 @@
1
1
  import type { KindCapabilities } from "./kinds.js";
2
2
  import type { MountKind } from "./mount.js";
3
- import type { AttachedComputer, CallContext, ComputerCapabilities, ComputerConnection, ComputerInfo, ComputerProvider, ComputerRef, ComputerSpec, CreatedComputer, NetworkForm, NetworkPolicy, NetworkSpec, Refusal } from "./provider.js";
3
+ import type { AttachedComputer, CallContext, ComputerCapabilities, ComputerConnection, ComputerInfo, ComputerProvider, ComputerRef, ComputerSpec, CreatedComputer, NetworkPolicy, NetworkSpec, Refusal } from "./provider.js";
4
4
  import { type Result } from "./result.js";
5
5
  /** The longest a local browser lives: a day, as pi-browser's local Chrome. */
6
6
  export declare const LOCAL_MAX_LIFETIME_MS: number;
7
- /** A browser takes no mount. */
7
+ /** A browser takes no mount: its descriptor's (descriptors/local-chrome.ts). */
8
8
  export declare const MOUNT: readonly MountKind[];
9
- /** The networks a local browser runs on, through its egress proxy: public addresses ("open"), or only the hosts of a list
10
- * ("allow"), public ones still. It cannot have none: a browser with no network has nothing to do. */
11
- export declare const NETWORK: readonly NetworkForm[];
12
9
  /** A spec's network as this browser's proxy takes it: open (no list), a list (parseAllow's), or why it can't. */
13
10
  export declare function browserNetworkOf(network: unknown): {
14
11
  allow?: string[];
15
12
  } | {
16
13
  problem: string;
17
14
  };
18
- /** The one configuration it offers: a browser with a CDP target. No live view: a person watching runs it headed. */
15
+ /** The one configuration it offers, its descriptor's: a browser with a CDP target. */
19
16
  export declare const CAPABILITIES: readonly KindCapabilities[];
20
17
  export interface LocalBrowserOptions {
21
18
  /** The Chrome or Chromium to run; default the one findChrome finds in `env`, then in the usual places. */
@@ -35,7 +32,7 @@ export interface LocalBrowserOptions {
35
32
  /** Computers that are this machine's Chrome. */
36
33
  export declare class LocalBrowserProvider implements ComputerProvider {
37
34
  #private;
38
- readonly id = "local";
35
+ readonly id = "local-chrome";
39
36
  readonly version: string;
40
37
  readonly root: string;
41
38
  constructor({ executablePath, env, headed, root, uid }?: LocalBrowserOptions);
@@ -43,7 +40,9 @@ export declare class LocalBrowserProvider implements ComputerProvider {
43
40
  * A browser: our supervisor ends it at its deadline, and list reads that deadline, so the janitor sweeps one whose
44
41
  * supervisor is gone (lifetime janitor); it reaches public addresses only, through its egress proxy (network open), or
45
42
  * only a list's hosts among them (network allow);
46
- * it runs on this host, as this user, isolated by Chrome's sandbox alone (isolation host).
43
+ * it runs on this host, as this user, isolated by Chrome's sandbox alone (isolation host). Its sessions (browser) end
44
+ * at their deadline, a wall clock, and take a viewport (spec.browser.viewport, its window); no profile, no stealth,
45
+ * and headless is the provider's option, not a session's.
47
46
  */
48
47
  capabilities(): ComputerCapabilities;
49
48
  /** The Chrome this provider runs: the option's, else one found; null when there is none. */
@@ -86,4 +85,4 @@ export declare class LocalBrowserProvider implements ComputerProvider {
86
85
  /** The provider, built from its options alone: no key, and no environment read but the `env` it is given. */
87
86
  export declare function create(options?: LocalBrowserOptions): LocalBrowserProvider;
88
87
  /** The conformance CLI's module for the local browser: its live switch, its image and its notes. */
89
- export declare const conformance: () => Promise<typeof import("./conformance/local.js")>;
88
+ export declare const conformance: () => Promise<typeof import("./conformance/local-chrome.js")>;
@@ -27,11 +27,13 @@ import { lstat, mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises
27
27
  import { tmpdir } from "node:os";
28
28
  import { join, resolve } from "node:path";
29
29
  import { fileURLToPath } from "node:url";
30
- import { BROWSER_IMAGE, browserClient, browserHello, carries, labelsProblem } from "./browser.js";
30
+ import { browserClient, browserHello, browserSpecRefusals, carries, labelsProblem } from "./browser.js";
31
31
  import { alive, answeringPath, CHROME_FLAGS, checkChrome, findChrome, killTree, NO_CHROME, AS_ROOT, runsWith, singletonDir } from "./chrome.js";
32
+ import { LOCAL } from "./descriptors/local-chrome.js";
33
+ import { BROWSER_IMAGE } from "./descriptors/shared.js";
32
34
  import { parseAllow } from "./docker/egress-proxy.js";
33
35
  import { BROWSER_FILE, CHROME_PID_FILE, EGRESS_SOCKET_FILE, PROFILE_DIR, READY_MS, STATE_FILE, SUPERVISOR_FILE } from "./local-supervisor.js";
34
- import { checkLifetime } from "./provider.js";
36
+ import { checkTenure, runLifetimeMs } from "./provider.js";
35
37
  import { fail, ok } from "./result.js";
36
38
  const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
37
39
  const SUPERVISOR = fileURLToPath(new URL("./local-supervisor.js", import.meta.url));
@@ -43,11 +45,11 @@ const WINDOW = "--window-size=1280,800";
43
45
  const SOCKET_PATH_MAX = 107;
44
46
  /** How long a release waits for the supervisor, then for Chrome, to end. */
45
47
  const END_MS = 10_000;
46
- /** A browser takes no mount. */
47
- export const MOUNT = [];
48
- /** The networks a local browser runs on, through its egress proxy: public addresses ("open"), or only the hosts of a list
49
- * ("allow"), public ones still. It cannot have none: a browser with no network has nothing to do. */
50
- export const NETWORK = ["open", "allow"];
48
+ /** A browser takes no mount: its descriptor's (descriptors/local-chrome.ts). */
49
+ export const MOUNT = LOCAL.mounts;
50
+ /** The networks a local browser runs on, its descriptor's: through its egress proxy, public addresses ("open"), or only
51
+ * the hosts of a list ("allow"), public ones still. */
52
+ const NETWORK = LOCAL.network;
51
53
  /** A spec's network as this browser's proxy takes it: open (no list), a list (parseAllow's), or why it can't. */
52
54
  export function browserNetworkOf(network) {
53
55
  if (network === "open")
@@ -73,12 +75,12 @@ const networkRecord = (network) => {
73
75
  };
74
76
  /** A browser's network as list, attach and network() read it back from browser.json. */
75
77
  const networkRead = (record) => (record.allow ? { allow: [...record.allow] } : "open");
76
- /** The one configuration it offers: a browser with a CDP target. No live view: a person watching runs it headed. */
77
- export const CAPABILITIES = [{ kind: "browser", groups: ["cdp"] }];
78
+ /** The one configuration it offers, its descriptor's: a browser with a CDP target. */
79
+ export const CAPABILITIES = LOCAL.capabilities;
78
80
  const ID = /^lb-[0-9a-f]{16}$/;
79
81
  const idProblem = (id) => (typeof id === "string" && ID.test(id) ? undefined : `${typeof id === "string" ? JSON.stringify(id) : String(id)} is not a local browser's id`);
80
82
  const refOf = (id) => ({ id, name: id });
81
- const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels"]);
83
+ const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "browser"]);
82
84
  const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
83
85
  const readJson = async (file) => {
84
86
  try {
@@ -90,7 +92,7 @@ const readJson = async (file) => {
90
92
  };
91
93
  /** Computers that are this machine's Chrome. */
92
94
  export class LocalBrowserProvider {
93
- id = "local";
95
+ id = "local-chrome";
94
96
  version = VERSION;
95
97
  #executablePath;
96
98
  #env;
@@ -110,7 +112,9 @@ export class LocalBrowserProvider {
110
112
  * A browser: our supervisor ends it at its deadline, and list reads that deadline, so the janitor sweeps one whose
111
113
  * supervisor is gone (lifetime janitor); it reaches public addresses only, through its egress proxy (network open), or
112
114
  * only a list's hosts among them (network allow);
113
- * it runs on this host, as this user, isolated by Chrome's sandbox alone (isolation host).
115
+ * it runs on this host, as this user, isolated by Chrome's sandbox alone (isolation host). Its sessions (browser) end
116
+ * at their deadline, a wall clock, and take a viewport (spec.browser.viewport, its window); no profile, no stealth,
117
+ * and headless is the provider's option, not a session's.
114
118
  */
115
119
  capabilities() {
116
120
  return {
@@ -123,6 +127,7 @@ export class LocalBrowserProvider {
123
127
  groups: [...CAPABILITIES[0].groups],
124
128
  maxLifetimeMs: LOCAL_MAX_LIFETIME_MS,
125
129
  release: ["delete"],
130
+ browser: { timeout: "wall-clock" },
126
131
  };
127
132
  }
128
133
  /** The Chrome this provider runs: the option's, else one found; null when there is none. */
@@ -143,13 +148,15 @@ export class LocalBrowserProvider {
143
148
  check(spec) {
144
149
  const refusals = [];
145
150
  const given = (typeof spec === "object" && spec !== null ? spec : {});
146
- const { image, lifetimeMs, network, labels } = given;
151
+ const { image, lifetimeMs, owner, network, labels } = given;
147
152
  if (image !== BROWSER_IMAGE)
148
153
  refusals.push({ field: "image", message: `a local browser is this machine's Chrome: image is "${BROWSER_IMAGE}", not ${JSON.stringify(image)}` });
149
- refusals.push(...checkLifetime(lifetimeMs, this.capabilities()));
154
+ // A run's browser: it declares no persistence, so an agent's (spec.owner) is refused in words.
155
+ refusals.push(...checkTenure({ lifetimeMs, owner }, this.capabilities(), LOCAL.label));
150
156
  const net = browserNetworkOf(network);
151
157
  if ("problem" in net)
152
158
  refusals.push({ field: "network", message: net.problem });
159
+ refusals.push(...browserSpecRefusals(given.browser, { timeout: "wall-clock" }, LOCAL.label));
153
160
  if (labels !== undefined) {
154
161
  const problem = labelsProblem(labels);
155
162
  if (problem)
@@ -196,13 +203,13 @@ export class LocalBrowserProvider {
196
203
  return fail("invalid", `the local browser's root ${this.root} is too long for a Unix socket under it: set the root option to a shorter directory`);
197
204
  const now = Date.now();
198
205
  const record = {
199
- provider: "local",
206
+ provider: LOCAL.id,
200
207
  id,
201
208
  labels: { ...spec.labels },
202
209
  created: new Date(now).toISOString(),
203
- deadline: new Date(now + spec.lifetimeMs).toISOString(),
210
+ deadline: new Date(now + runLifetimeMs(spec)).toISOString(),
204
211
  executablePath: this.executable(),
205
- args: [...CHROME_FLAGS, ...(this.#headed ? [] : ["--headless=new"]), WINDOW],
212
+ args: [...CHROME_FLAGS, ...(this.#headed ? [] : ["--headless=new"]), spec.browser?.viewport ? `--window-size=${spec.browser.viewport.width},${spec.browser.viewport.height}` : WINDOW],
206
213
  ...networkRecord(spec.network),
207
214
  };
208
215
  try {
@@ -296,7 +303,7 @@ export class LocalBrowserProvider {
296
303
  }
297
304
  async #record(id) {
298
305
  const record = await readJson(join(this.#dir(id), BROWSER_FILE));
299
- return record?.provider === "local" && record.id === id ? record : undefined;
306
+ return record?.provider === LOCAL.id && record.id === id ? record : undefined;
300
307
  }
301
308
  /** Chrome's state, when the Chrome it names still runs on this browser's profile. */
302
309
  async #live(id) {
@@ -469,4 +476,4 @@ export function create(options = {}) {
469
476
  return new LocalBrowserProvider(options ?? {});
470
477
  }
471
478
  /** The conformance CLI's module for the local browser: its live switch, its image and its notes. */
472
- export const conformance = () => import("./conformance/local.js");
479
+ export const conformance = () => import("./conformance/local-chrome.js");
@@ -1,4 +1,4 @@
1
- /** The browser's record, written by local.ts before the supervisor starts: the label a list finds it by. */
1
+ /** The browser's record, written by local-chrome.ts before the supervisor starts: the label a list finds it by. */
2
2
  export declare const BROWSER_FILE = "browser.json";
3
3
  /** What the supervisor writes once Chrome answers: the pids and ports a connect and a release read. */
4
4
  export declare const STATE_FILE = "state.json";
@@ -17,9 +17,9 @@ export declare const BROWSER_MAX_TUNNELS = 128;
17
17
  export declare const BROWSER_MAX_CONNECTIONS = 100000;
18
18
  /** How long Chrome has to answer on its debugging port. */
19
19
  export declare const READY_MS = 20000;
20
- /** What local.ts writes in browser.json. */
20
+ /** What local-chrome.ts writes in browser.json. */
21
21
  export interface BrowserRecord {
22
- provider: "local";
22
+ provider: "local-chrome";
23
23
  id: string;
24
24
  labels: Record<string, string>;
25
25
  /** ISO times. */
@@ -1,4 +1,4 @@
1
- // One local browser's supervisor: a detached Node process of its own per browser (local.ts starts it), so the browser
1
+ // One local browser's supervisor: a detached Node process of its own per browser (local-chrome.ts starts it), so the browser
2
2
  // outlives neither its deadline nor its release, whatever becomes of the process that made it. It reads the browser's
3
3
  // directory (browser.json), starts the browser's egress proxy (docker/egress-proxy.ts: with no list, every public host
4
4
  // and nothing else; with the record's list, only its hosts, public ones still) on a Unix socket in that directory, with
@@ -6,7 +6,7 @@
6
6
  // (Chrome takes a proxy over TCP alone; the relay passes each connection to the socket unread, the proxy decides), then
7
7
  // starts Chrome behind that fence (chrome.ts chromeFence) with a fresh profile in the directory and a debugging port
8
8
  // Chrome picks on 127.0.0.1. Once Chrome's DevTools socket answers it writes state.json and one line on stdout, which
9
- // local.ts waits for; a Chrome that never does is reported on that line in words and nothing is left.
9
+ // local-chrome.ts waits for; a Chrome that never does is reported on that line in words and nothing is left.
10
10
  //
11
11
  // It then ends the browser (Chrome's whole process group, the proxy, the relay, Chrome's singleton socket directory and
12
12
  // the browser's directory) at the first of: the deadline in browser.json, SIGTERM (a release), or Chrome's own exit. So a
@@ -21,7 +21,7 @@ import { join, resolve } from "node:path";
21
21
  import { alive, chromeFence, killTree, NO_SANDBOX, ownDebugger, answeringPath, singletonDir } from "./chrome.js";
22
22
  import { startEgressProxy } from "./docker/egress-proxy.js";
23
23
  import { isCommand } from "./entry.js";
24
- /** The browser's record, written by local.ts before the supervisor starts: the label a list finds it by. */
24
+ /** The browser's record, written by local-chrome.ts before the supervisor starts: the label a list finds it by. */
25
25
  export const BROWSER_FILE = "browser.json";
26
26
  /** What the supervisor writes once Chrome answers: the pids and ports a connect and a release read. */
27
27
  export const STATE_FILE = "state.json";