@parcha/agentrun-computer 0.1.0-beta.37 → 0.1.0-beta.39

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 (124) hide show
  1. package/README.md +341 -260
  2. package/box/Dockerfile +18 -1
  3. package/box/README.md +14 -0
  4. package/box/build-daytona.py +2 -2
  5. package/box/build-e2b.mjs +41 -18
  6. package/box/recipe.d.mts +5 -0
  7. package/box/recipe.mjs +43 -0
  8. package/dist/agent37.d.ts +18 -66
  9. package/dist/agent37.js +187 -464
  10. package/dist/box-image.d.ts +14 -0
  11. package/dist/box-image.js +24 -0
  12. package/dist/browserbase.d.ts +0 -6
  13. package/dist/browserbase.js +1 -5
  14. package/dist/client.d.ts +12 -3
  15. package/dist/client.js +39 -4
  16. package/dist/computerd-linux-amd64 +0 -0
  17. package/dist/computerd-linux-arm64 +0 -0
  18. package/dist/computerd.json +4 -0
  19. package/dist/conformance/agent37.d.ts +9 -4
  20. package/dist/conformance/agent37.js +23 -11
  21. package/dist/conformance/browserbase.js +3 -3
  22. package/dist/conformance/cases/apps.d.ts +6 -0
  23. package/dist/conformance/cases/apps.js +18 -5
  24. package/dist/conformance/cases/isolation.d.ts +22 -5
  25. package/dist/conformance/cases/isolation.js +97 -16
  26. package/dist/conformance/cases/mount.js +5 -3
  27. package/dist/conformance/cases/provider.js +41 -0
  28. package/dist/conformance/cli.js +72 -11
  29. package/dist/conformance/daytona.d.ts +9 -20
  30. package/dist/conformance/daytona.js +12 -21
  31. package/dist/conformance/e2b.js +9 -4
  32. package/dist/conformance/exec-stream.d.ts +52 -0
  33. package/dist/conformance/exec-stream.js +493 -0
  34. package/dist/conformance/kernel.js +2 -2
  35. package/dist/conformance/modal.js +1 -1
  36. package/dist/conformance/orgo.js +2 -2
  37. package/dist/conformance/sweep.js +8 -8
  38. package/dist/conformance/types.d.ts +2 -2
  39. package/dist/create-requests.d.ts +1 -1
  40. package/dist/daytona.d.ts +17 -133
  41. package/dist/daytona.js +396 -1452
  42. package/dist/descriptor.d.ts +11 -4
  43. package/dist/descriptor.js +7 -0
  44. package/dist/descriptors/agent37.d.ts +3 -11
  45. package/dist/descriptors/agent37.js +9 -10
  46. package/dist/descriptors/daytona.d.ts +7 -6
  47. package/dist/descriptors/daytona.js +14 -7
  48. package/dist/descriptors/docker.d.ts +13 -1
  49. package/dist/descriptors/docker.js +3 -1
  50. package/dist/descriptors/e2b.d.ts +2 -9
  51. package/dist/descriptors/e2b.js +8 -8
  52. package/dist/descriptors/index.d.ts +25 -24
  53. package/dist/descriptors/index.js +1 -3
  54. package/dist/descriptors/modal.d.ts +2 -6
  55. package/dist/descriptors/modal.js +8 -6
  56. package/dist/descriptors/orgo.js +2 -1
  57. package/dist/descriptors/shared.d.ts +1 -1
  58. package/dist/descriptors/shared.js +2 -2
  59. package/dist/desktop.d.ts +18 -4
  60. package/dist/desktop.js +89 -9
  61. package/dist/docker/egress-main.js +23 -15
  62. package/dist/docker/egress.d.ts +6 -4
  63. package/dist/docker/egress.js +24 -16
  64. package/dist/docker/inspect.d.ts +2 -2
  65. package/dist/docker/inspect.js +5 -5
  66. package/dist/docker.d.ts +6 -11
  67. package/dist/docker.js +13 -16
  68. package/dist/drift.js +4 -4
  69. package/dist/e2b.d.ts +22 -130
  70. package/dist/e2b.js +163 -243
  71. package/dist/host.d.ts +136 -104
  72. package/dist/host.js +8 -1
  73. package/dist/hosted/network.d.ts +23 -0
  74. package/dist/hosted/network.js +77 -0
  75. package/dist/hosted/process.d.ts +24 -8
  76. package/dist/hosted/process.js +80 -44
  77. package/dist/hosted/provider.d.ts +38 -22
  78. package/dist/hosted/provider.js +500 -341
  79. package/dist/hosted/rest.d.ts +74 -0
  80. package/dist/hosted/rest.js +126 -0
  81. package/dist/hosted/scripts.d.ts +21 -3
  82. package/dist/hosted/scripts.js +76 -14
  83. package/dist/hosted/ssh-exec.d.ts +99 -0
  84. package/dist/hosted/ssh-exec.js +464 -0
  85. package/dist/hosted/values.d.ts +26 -0
  86. package/dist/hosted/values.js +63 -0
  87. package/dist/index.d.ts +2 -2
  88. package/dist/index.js +2 -2
  89. package/dist/isolation.d.ts +0 -2
  90. package/dist/isolation.js +3 -4
  91. package/dist/kernel.d.ts +0 -6
  92. package/dist/kernel.js +1 -5
  93. package/dist/kinds.d.ts +3 -1
  94. package/dist/local-chrome.d.ts +0 -6
  95. package/dist/local-chrome.js +1 -5
  96. package/dist/modal.d.ts +15 -86
  97. package/dist/modal.js +67 -185
  98. package/dist/mount-archil.d.ts +13 -8
  99. package/dist/mount-archil.js +27 -17
  100. package/dist/mount.d.ts +10 -4
  101. package/dist/mount.js +8 -4
  102. package/dist/orgo.d.ts +0 -9
  103. package/dist/orgo.js +8 -13
  104. package/dist/phone-harness.d.ts +0 -6
  105. package/dist/phone-harness.js +0 -4
  106. package/dist/protocol.d.ts +4 -1
  107. package/dist/protocol.js +1 -0
  108. package/dist/provider.d.ts +2 -2
  109. package/dist/providers.d.ts +15 -13
  110. package/dist/screen-watch.js +34 -6
  111. package/dist/surface/api.d.ts +14 -11
  112. package/dist/surface/core.d.ts +23 -5
  113. package/dist/surface/core.js +105 -15
  114. package/dist/surface/index.d.ts +1 -1
  115. package/dist/surface/index.js +1 -1
  116. package/dist/surface/outline.d.ts +2 -0
  117. package/dist/surface/outline.js +2 -1
  118. package/dist/surface/script.d.ts +4 -0
  119. package/dist/surface/script.js +11 -3
  120. package/dist/ui-engine.js +19 -3
  121. package/package.json +2 -3
  122. package/box/build-agent37.mjs +0 -177
  123. package/dist/conformance/daytona-sweep.d.ts +0 -18
  124. package/dist/conformance/daytona-sweep.js +0 -126
package/dist/host.d.ts CHANGED
@@ -1,76 +1,108 @@
1
- import type { MountKind } from "./mount.js";
2
- import type { ComputerCapabilities, ComputerSpec, GpuCapability, GpuSpec, NetworkForm, NetworkPolicy, Refusal } from "./provider.js";
3
- import type { ComputerErrorCode, Result } from "./result.js";
1
+ import type { ProviderDescriptor } from "./descriptor.js";
2
+ import type { ComputerCapabilities, ComputerSpec, GpuSpec, Refusal } from "./provider.js";
3
+ import type { ComputerErrorCode } from "./result.js";
4
4
  /**
5
- * One vendor's machines. Every call answers a Result: an expected failure (the vendor refused, the machine is not
6
- * there) is a result with a code from errorCode, never a throw. A call that throws is read through errorCode as well.
7
- * The adapter bounds each call by ctx.timeoutMs and ctx.signal; a host passes both on to its vendor call when it can.
5
+ * One vendor's machines. Every call answers its value or throws: a failure whose code the host knows throws a
6
+ * HostError with that code, and any other error is read through errorCode (default "vendor"); an AbortError or a
7
+ * TimeoutError the adapter reads itself. The adapter bounds each call by ctx.timeoutMs and ctx.signal; a host passes
8
+ * both on to its vendor call when it can.
8
9
  */
9
10
  export interface MachineHost {
10
- /** The provider's descriptor id ("e2b"): the vendor named by every error of code vendor. */
11
- readonly id: string;
11
+ /**
12
+ * The provider's descriptor (./descriptors): its id names the vendor of every error of code vendor, its label is the
13
+ * vendor in words, and capabilities() and check() read its network forms, mount kinds and unmounted kinds, and its
14
+ * configuration of the adapter's kind: the groups and GPUs.
15
+ */
16
+ readonly descriptor: HostDescriptor;
12
17
  readonly facts: HostFacts;
13
18
  /**
14
- * Makes one machine, by its options, and answers once the vendor has its id. It does not wait for the machine to run
15
- * (the adapter polls get while it is starting) or to be listed (the adapter waits for that too). The machine carries
16
- * req.name where the vendor can find it again by listing: the vendor's native name, or a label. An answer that never
17
- * comes is not a machine the adapter forgets: it lists by req.labels and deletes what it finds.
19
+ * Makes one machine, by its options, and answers its id once the vendor has one. It does not wait for the machine to
20
+ * run (the adapter polls get while it is starting) or to be listed (the adapter waits for that too), except where the
21
+ * vendor applies a machine's settings only once it is ready: there it may wait for ready within ctx.timeoutMs, set
22
+ * them, and answer then (PROVIDERS.md, create). The machine
23
+ * carries req.name where the vendor can find it again by listing: the vendor's native name, or a label. A native name
24
+ * the vendor already has throws exists (a REST host's named call: hosted/rest.ts), and the adapter adopts the machine
25
+ * the name lists, as a retry does. An answer that never comes is not a machine the adapter forgets: it lists by
26
+ * req.labels and deletes what it finds.
18
27
  */
19
- create(req: MachineRequest, ctx: HostCall): Promise<Result<{
28
+ create(req: MachineRequest, ctx: HostCall): Promise<{
20
29
  id: string;
21
- }>>;
22
- /** One machine as the vendor reads it now; undefined once the vendor no longer has it (not found is that, not an error). */
23
- get(id: string, ctx: HostCall): Promise<Result<Machine | undefined>>;
30
+ }>;
31
+ /** One machine as the vendor reads it now; undefined once the vendor no longer has it (not found is that, or a HostError not_found). */
32
+ get(id: string, ctx: HostCall): Promise<Machine | undefined>;
24
33
  /**
25
- * Every machine of the account that carries all of these labels, every page, each as get reads it (network included,
26
- * where the vendor reads one back), within ctx.timeoutMs in all. A machine the vendor is deleting may still be listed.
34
+ * The machines of the account the vendor's listing shows for these labels, every page, within ctx.timeoutMs in all.
35
+ * The listing finds; get answers: the adapter takes only the ids from it and reads each one it keeps by get, for its
36
+ * state, labels and end, so a listing may be stale (one still showing a deleted machine, or an end from before a
37
+ * timer moved: E2B's). It may answer more machines than carry all the labels (a vendor that filters by some, or
38
+ * none): the adapter keeps those whose get does. A listing may lag a create: two creates of one request on two
39
+ * provider instances can then both make a machine, and the adapter deletes every one but the oldest (createdAt), so
40
+ * a vendor may see a second create deleted.
27
41
  */
28
- list(labels: Record<string, string>, ctx: HostCall): Promise<Result<Machine[]>>;
29
- /** Deletes a machine; not found is ok. It answers once the vendor took the delete: the adapter waits for gone. */
30
- delete(id: string, ctx: HostCall): Promise<Result<void>>;
42
+ list(labels: Record<string, string>, ctx: HostCall): Promise<Machine[]>;
43
+ /**
44
+ * Deletes a machine; not found is ok. It answers once the vendor took the delete: the adapter then waits until get
45
+ * answers none, twice running (a machine get reads gone is still going, and holds the wait).
46
+ */
47
+ delete(id: string, ctx: HostCall): Promise<void>;
31
48
  /**
32
49
  * Starts argv in the machine as root (the vendor's own command user when it is root, else one with passwordless
33
- * sudo), the vendor's agent's own process, outside the computer's tools. With opts.stdin, the process reads what
34
- * write() gives until end(). No command timeout: the adapter kills it, or it ends. Answers once it has started.
50
+ * sudo), the vendor's agent's own process, outside the computer's tools, and answers once it has started.
51
+ *
52
+ * exec is the whole protocol: the adapter installs and starts its daemon through it, then talks to the daemon over
53
+ * one exec'd process's stdin and stdout for the computer's whole life (the stdio bridge, spec/computer/stdio.md). So:
54
+ * - Two-way and live. Each write() reaches the process's stdin as it is written, and stdout and stderr bytes come
55
+ * back as the process writes them, while it runs. Not request and response, never held until the process exits.
56
+ * - Byte-exact. Every byte value 0-255, both ways: no UTF-8 decode or encode, no newline translation, no terminal,
57
+ * nothing added or dropped. A client that hands output over as text breaks this (E2B's commands.run does).
58
+ * - No timeout. The process runs until it exits or kill() ends it: a vendor's command timeout, and any idle timeout
59
+ * on the stream, are off.
60
+ * - stdout and stderr stay apart. wait() answers the process's own exit code. kill() ends the process itself.
61
+ * The process reads what write() gives until end(); the adapter ends stdin at once where it gives none. The exec
62
+ * pre-check (conformance --exec-stream, src/conformance/exec-stream.ts) checks each of these on a machine made by
63
+ * hand, with exec alone.
35
64
  */
36
- exec(id: string, argv: readonly string[], opts: {
37
- stdin: boolean;
38
- }, ctx: HostCall): Promise<Result<MachineProcess>>;
65
+ exec(id: string, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
39
66
  /**
40
67
  * Puts bytes at path in the machine, as root. Optional: a vendor with no file API leaves it out, and the adapter
41
68
  * streams the file through exec's stdin.
42
69
  */
43
- upload?(id: string, path: string, bytes: Uint8Array, ctx: HostCall): Promise<Result<void>>;
44
- /** The code of an error the vendor's client threw: one of ComputerErrorCode, "vendor" for anything else. */
45
- errorCode(error: unknown): ComputerErrorCode;
46
- /** Vendor settings a machine takes once it runs and before the daemon goes in (egress rules, an idle timer). */
47
- prepare?(id: string, ctx: HostCall): Promise<Result<void>>;
48
- /** Stops a machine, keeping it; declared with facts.release "stop". It answers once the machine reads stopped (or gone with stopDeletes). */
49
- stop?(id: string, ctx: HostCall): Promise<Result<void>>;
70
+ upload?(id: string, path: string, bytes: Uint8Array, ctx: HostCall): Promise<void>;
50
71
  /**
51
- * Moves the vendor's own timer (facts.lifetime "vendor") so the machine ends at want.end, never past want.most, the
52
- * most it may live. A refusal (limit, in words) when no timer the vendor takes lands there without moving the end
53
- * earlier than it is or past want.most: nothing moves then. The adapter reads the end back with get.
72
+ * The code of an error the vendor's client threw: one of ComputerErrorCode. Optional: the adapter reads a HostError's
73
+ * own code, an AbortError as "aborted" and a TimeoutError as "timeout" itself, and anything else a host does not map
74
+ * is "vendor".
54
75
  */
55
- setTimer?(id: string, want: {
56
- end: Date;
57
- most: Date;
58
- }, ctx: HostCall): Promise<Result<void>>;
59
- /** Replaces some labels of a machine (the janitor's deadline label, at extend); facts.lifetime "janitor". */
60
- setLabels?(id: string, labels: Record<string, string>, ctx: HostCall): Promise<Result<void>>;
61
- /** The vendor's own rules of a spec, over the adapter's shared ones: an image name it takes, a GPU's image. No call. */
62
- check?(spec: ComputerSpec): Refusal[];
63
- /** Settings' test, where a list would make something (an app); default: one list by the adapter's label, counted. */
64
- testConnection?(ctx: HostCall): Promise<Result<{
65
- detail: string;
66
- }>>;
76
+ errorCode?(error: unknown): ComputerErrorCode;
77
+ /**
78
+ * Moves the machine's end to endsAt, never past its agentrun.computer.max-deadline label, the most it may live: the
79
+ * vendor's own timer (facts.lifetime "vendor"), or the janitor's deadline label (facts.lifetime "janitor"). A refusal
80
+ * (a HostError limit, in words) when no end the vendor takes lands there without moving it earlier than it is or past
81
+ * the most: nothing moves then. The adapter reads the end back with get (deadlineOf, the deadline label: a vendor that
82
+ * keeps no label change reads its moved timer as that label), and init's deadline follows it. Optional: a host without
83
+ * it has no extend.
84
+ */
85
+ extend?(id: string, endsAt: Date, ctx: HostCall): Promise<void>;
86
+ /**
87
+ * The vendor's own rules of a spec, over the adapter's shared ones: an image name it takes, a GPU's image. No call. The
88
+ * spec is an object, as the caller gave it: its fields are not checked yet (an image may be a number).
89
+ */
90
+ check?(spec: Partial<ComputerSpec>): Refusal[];
91
+ }
92
+ /** A host's failure whose code it knows: thrown by a host member, read by the adapter as that code, in these words. */
93
+ export declare class HostError extends Error {
94
+ readonly code: ComputerErrorCode;
95
+ constructor(code: ComputerErrorCode, message: string);
67
96
  }
68
97
  /** Every call's bound: the adapter's timeout for this kind of call, and the caller's signal when it has one. */
69
98
  export interface HostCall {
70
99
  signal?: AbortSignal;
71
100
  timeoutMs: number;
72
101
  }
73
- /** What create asks of the vendor: the adapter fills every field but the ones facts.specFields leaves out. */
102
+ /**
103
+ * What create asks of the vendor. A size (cpus, memoryMb) is passed whenever the spec gives one: a vendor whose size is
104
+ * its image's refuses it in its own check.
105
+ */
74
106
  export interface MachineRequest {
75
107
  /** computer-<12 hex digits>, from the create's request id: the vendor's native name, or a label it lists by. */
76
108
  name: string;
@@ -78,59 +110,44 @@ export interface MachineRequest {
78
110
  image: string;
79
111
  /** The caller's labels and the adapter's own (agentrun.computer*, the Archil mount's), every one to be read back. */
80
112
  labels: Record<string, string>;
81
- /** With facts.lifetime "vendor": the vendor's timer, the spec's lifetime. Absent for a janitor's machine. */
82
- lifetimeMs?: number;
113
+ /** The spec's lifetime: the vendor's timer (facts.lifetime "vendor"); a janitor's host may leave it. */
114
+ lifetimeMs: number;
83
115
  /**
84
- * The vendor's network for the machine: "open" only for an Archil computer's root, which reaches Archil; its tools'
85
- * network is init's own, none, read from inside.
116
+ * Whether the machine reaches out: true for an Archil computer's root, which reaches Archil, and for a network open
117
+ * or a list, whose egress proxy init starts outside its tools' network (./hosted/network.ts). Its tools' own network
118
+ * is init's, loopback alone, read from inside, either way.
86
119
  */
87
- network: "none" | "open";
120
+ egress: boolean;
88
121
  /** facts.daemon "pid1" alone: the machine's main process (the entrypoint that waits for the daemon, then becomes init). */
89
122
  command?: readonly string[];
123
+ /** A GPU computer's GPUs; the adapter records them in a label too, so no vendor reads them back. */
90
124
  gpu?: GpuSpec;
91
125
  cpus?: number;
92
126
  memoryMb?: number;
93
- workdir?: string;
127
+ /** With facts.user: the spec's user, uid:gid. */
94
128
  user?: string;
95
129
  }
96
- /** One machine as the vendor reads it back. */
130
+ /**
131
+ * One machine as the vendor reads it back. The adapter holds the rest itself: what create asked is in the labels, what
132
+ * runs is read from inside (the daemon's hello and sha256, the network probe).
133
+ */
97
134
  export interface Machine {
98
135
  id: string;
99
136
  /** Every label it carries, the adapter's own included. */
100
137
  labels: Record<string, string>;
101
- /** starting: not yet running; going: being deleted or ended; failed: the vendor gave up on it (why says how). */
102
- state: "starting" | "running" | "stopped" | "going" | "failed";
103
- /** The vendor's own read of its network; absent when the vendor reads none back (the probe stands for it then). */
104
- network?: NetworkPolicy;
105
- /** What the vendor resolved the image to, by its own name (a template's id, a snapshot). */
106
- image?: {
107
- resolved?: string;
108
- };
109
138
  /**
110
- * When the vendor made it, by its clock, where it says. Two creates of one request on two provider instances can each
111
- * make a machine before either is listed: the oldest is kept, by this, or by the lowest id where a machine has none.
139
+ * starting: not yet running; stopped: there, not running, and not being deleted (paused, asleep): listed, so the
140
+ * janitor still ends it; gone: being deleted, ended, or failed (why says how).
112
141
  */
113
- createdAt?: Date;
142
+ state: "starting" | "running" | "stopped" | "gone";
114
143
  /** With facts.lifetime "vendor": when the vendor's timer ends it. */
115
144
  endsAt?: Date;
116
145
  /**
117
- * With facts.lifetime "vendor": the vendor's timer was moved past where create set it (by an extend), so endsAt,
118
- * held to the most the machine may live, stands for its deadline: the vendor keeps no label change.
119
- */
120
- timerMoved?: boolean;
121
- /**
122
- * The vendor's own create options read back wrong, in words, one each ("lifecycle onTimeout: declared ..."). Held at
123
- * create and at attach alike, so only what holds for the machine's whole life: a timer an extend moved is timerMoved,
124
- * never drift (create refuses a machine whose timer reads moved before any extend).
146
+ * When the vendor made it, by its clock, where it says. Two creates of one request on two provider instances can each
147
+ * make a machine before either is listed: the oldest is kept, by this, or by the lowest id where a machine has none.
125
148
  */
126
- drift?: string[];
127
- /** The size the vendor reads back, in CPUs and MiB: attach reports it. */
128
- size?: {
129
- cpus?: number;
130
- memoryMb?: number;
131
- };
132
- gpu?: GpuSpec;
133
- /** The vendor's words for a failed state. */
149
+ createdAt?: Date;
150
+ /** The vendor's words for a machine that is gone because it failed: a create stops in them. */
134
151
  why?: string;
135
152
  }
136
153
  /** A process exec started: its output as it comes, its stdin, and its end. */
@@ -146,9 +163,21 @@ export interface MachineProcess {
146
163
  /** Ends it, best effort, and lets go of its streams; never throws. */
147
164
  kill(): Promise<void>;
148
165
  }
149
- /** What a vendor's machines are, static: with the adapter's options, capabilities() is built from these alone. */
166
+ /**
167
+ * What the host reads of its provider's descriptor: its id and label, its network forms and mounts, and its
168
+ * configurations, each kind's groups and GPUs.
169
+ */
170
+ export type HostDescriptor = Pick<ProviderDescriptor, "id" | "label" | "network" | "mounts" | "unmounted" | "capabilities">;
171
+ /**
172
+ * What a vendor's machines are, static: with its descriptor (network, mounts, each kind's groups and GPUs) and the
173
+ * adapter's options, capabilities() is built from these alone.
174
+ */
150
175
  export interface HostFacts {
151
- /** child: the vendor's agent is the machine's first process and starts init; pid1: init is the machine's main process. */
176
+ /**
177
+ * child: the vendor's agent is the machine's first process and starts init, after the adapter closes the session
178
+ * buses in /tmp (/tmp/dbus-*) to the computer's user, since a network namespace does not cut a path socket. pid1:
179
+ * init is the machine's main process (Modal's, whose sandbox ends when it does), started by request.command.
180
+ */
152
181
  daemon: "child" | "pid1";
153
182
  isolation: ComputerCapabilities["isolation"];
154
183
  /** Who ends a machine at its deadline: the vendor's timer, or the janitor by label. */
@@ -158,25 +187,28 @@ export interface HostFacts {
158
187
  arch: "amd64" | "arm64";
159
188
  /** The TCP ports the vendor's own agent listens on inside the machine (E2B's envd 49983). */
160
189
  vendorAgentPorts: number[];
161
- /** Whether get reads the network back from the vendor. */
162
- networkReadBack: boolean;
163
- /** The network forms its computers take: of its descriptor's. */
164
- network: NetworkForm[];
165
- /** The mount kinds it takes: of its descriptor's. */
166
- mounts?: MountKind[];
167
- /** How release may end one; "stop" needs host.stop. */
168
- release: Array<"stop" | "delete">;
169
- stopDeletes?: boolean;
170
- gpu?: GpuCapability;
171
- /** What spec.user may ask for, beside the daemon user. */
190
+ /** Whether its desktops run WINDOW_MANAGER (xfwm4, which its image has) once the display answers. Default none. */
191
+ windowManager?: boolean;
192
+ /** What spec.user may ask for, beside the daemon user: with it, the spec's user goes in MachineRequest.user. */
172
193
  user?: Array<"root" | "uid">;
173
- /** The spec's size and place fields the vendor takes, passed in MachineRequest; any other is refused. */
174
- specFields?: Array<"cpus" | "memoryMb" | "workdir" | "user">;
175
- /** The vendor's label rules: how many labels a machine takes, and the names it takes. */
176
- labelRules?: {
177
- max?: number;
178
- key?: RegExp;
194
+ /**
195
+ * The most a machine's labels may be, the adapter's own with the caller's: count, how many; bytes, every name and
196
+ * value together, the adapter's at their longest. Past either, check() refuses, and so create, before any host call.
197
+ * Absent: no bound. packed: the host stores the labels as packLabels packs them (./hosted/values.ts: one name to
198
+ * list by, the map in parts of at most valueBytes each) and get answers unpackLabels' map; count and bytes are then
199
+ * the packed labels'.
200
+ */
201
+ labels?: {
202
+ count?: number;
203
+ bytes?: number;
204
+ packed?: {
205
+ valueBytes?: number;
206
+ };
179
207
  };
180
- /** The runtime a machine of this request runs: "gvisor" only where the vendor runs one (a pid1 host's GPU). */
181
- runtime?(req: MachineRequest): "vm" | "gvisor";
208
+ /**
209
+ * Paths of the vendor's image that root runs or reads and whose permissions its template build sets wider than
210
+ * root's: create makes each root's alone (owned by root, writable by no group or other user), and everything under a
211
+ * directory, before the daemon's upload, so the computer's user can change nothing root runs. Default none.
212
+ */
213
+ rootOnly?: readonly string[];
182
214
  }
package/dist/host.js CHANGED
@@ -1 +1,8 @@
1
- export {};
1
+ /** A host's failure whose code it knows: thrown by a host member, read by the adapter as that code, in these words. */
2
+ export class HostError extends Error {
3
+ code;
4
+ constructor(code, message) {
5
+ super(message);
6
+ this.code = code;
7
+ }
8
+ }
@@ -0,0 +1,23 @@
1
+ import type { AllowCapability, NetworkForm, NetworkPolicy, NetworkSpec } from "../provider.js";
2
+ /** The label a computer whose network is open or a list carries: its form, as init was given it. None carries none. */
3
+ export declare const NETWORK_LABEL = "agentrun.computer.network";
4
+ /** Where init's proxy listens, and where it writes the form it serves (daemon/internal/egress/serve.go). */
5
+ export declare const EGRESS_PROXY_SOCKET: string;
6
+ export declare const EGRESS_POLICY: string;
7
+ /** The uid and gid init's proxy runs as, nobody (serve.go ProxyUser): no computer's user under open or a list may be it. */
8
+ export declare const EGRESS_PROXY_USER = 65534;
9
+ /** Init's relay on its programs' own loopback, which carries each connection to the proxy (daemon/internal/egress). */
10
+ export declare const EGRESS_RELAY = "127.0.0.1:3128";
11
+ /** What a hosted list may hold: Docker's bounds, ports 80 and 443, names and CIDRs together. */
12
+ export declare const HOSTED_ALLOW: AllowCapability;
13
+ /** A network spec as init's --network takes it: "" for none, "open", or "allow:" and the list, normalized. */
14
+ export declare function networkFormOf(network: NetworkSpec): string;
15
+ /** A form, as a label or the policy file holds it, as a network policy: none for no form; anything else in words. */
16
+ export declare function networkOfForm(form: string | undefined): NetworkPolicy;
17
+ /**
18
+ * Why a spec's network is refused by a provider (label) that declares forms, in plain words naming it and the choices;
19
+ * undefined when it is taken. A form the provider does not declare is refused, never widened or narrowed to another.
20
+ */
21
+ export declare function networkRefusal(label: string, forms: readonly NetworkForm[], network: unknown): string | undefined;
22
+ /** Whether a spec's network goes out through the proxy: open, or a list. */
23
+ export declare const throughProxy: (network: unknown) => boolean;
@@ -0,0 +1,77 @@
1
+ // A hosted computer's network, as the shared adapter (./provider.ts) makes, records and reads it back. Its programs run
2
+ // in a network of their own whose loopback alone is up (isolation.ts), so "none" holds by itself. "open" and a host list
3
+ // go through one egress proxy per computer that init, still root and in the machine's own network, starts before it
4
+ // leaves it (`computerd init --own-network --network <form>`, daemon/internal/egress): the proxy runs as nobody, listens
5
+ // on a Unix socket only root and the tool user's group reach, and goes to the public internet alone, so the vendor's
6
+ // agent, metadata, the machine's own addresses and every private range stay out of reach; with a list, to its hosts
7
+ // alone, refused before any lookup. Init relays the programs' loopback port 3128 to it and tells them it is their proxy.
8
+ // The machine itself gets the vendor's egress for it. The form is recorded in a label, written to the policy file init
9
+ // leaves beside the socket, and both are read back.
10
+ import { allowOf, MAX_ALLOW } from "../docker/egress.js";
11
+ import { LISTED_PORTS } from "../docker/egress-proxy.js";
12
+ import { COMPUTER_LABEL, DAEMON_IN_COMPUTER } from "../drift.js";
13
+ /** The label a computer whose network is open or a list carries: its form, as init was given it. None carries none. */
14
+ export const NETWORK_LABEL = `${COMPUTER_LABEL}.network`;
15
+ const EGRESS_DIR = `${DAEMON_IN_COMPUTER.slice(0, DAEMON_IN_COMPUTER.lastIndexOf("/"))}/egress`;
16
+ /** Where init's proxy listens, and where it writes the form it serves (daemon/internal/egress/serve.go). */
17
+ export const EGRESS_PROXY_SOCKET = `${EGRESS_DIR}/egress.sock`;
18
+ export const EGRESS_POLICY = `${EGRESS_DIR}/policy`;
19
+ /** The uid and gid init's proxy runs as, nobody (serve.go ProxyUser): no computer's user under open or a list may be it. */
20
+ export const EGRESS_PROXY_USER = 65534;
21
+ /** Init's relay on its programs' own loopback, which carries each connection to the proxy (daemon/internal/egress). */
22
+ export const EGRESS_RELAY = "127.0.0.1:3128"; // key-gate: loopback-rule the computer's own loopback, where init's egress relay listens
23
+ /** What a hosted list may hold: Docker's bounds, ports 80 and 443, names and CIDRs together. */
24
+ export const HOSTED_ALLOW = {
25
+ domains: { max: MAX_ALLOW, ports: [...LISTED_PORTS] },
26
+ cidrs: { max: MAX_ALLOW, ports: [...LISTED_PORTS] },
27
+ mixed: true,
28
+ };
29
+ /** A network spec as init's --network takes it: "" for none, "open", or "allow:" and the list, normalized. */
30
+ export function networkFormOf(network) {
31
+ if (network === "none")
32
+ return "";
33
+ if (network === "open")
34
+ return "open";
35
+ const allow = allowOf(network.allow);
36
+ if ("problem" in allow)
37
+ throw new Error(allow.problem);
38
+ return `allow:${allow.list.join(",")}`;
39
+ }
40
+ /** A form, as a label or the policy file holds it, as a network policy: none for no form; anything else in words. */
41
+ export function networkOfForm(form) {
42
+ if (form === undefined || form === "")
43
+ return "none";
44
+ if (form === "open")
45
+ return "open";
46
+ if (form.startsWith("allow:")) {
47
+ const allow = allowOf(form.slice("allow:".length).split(","));
48
+ if (!("problem" in allow) && `allow:${allow.list.join(",")}` === form)
49
+ return { allow: allow.list };
50
+ }
51
+ return { other: `the network ${JSON.stringify(form.slice(0, 200))}, which this provider never makes` };
52
+ }
53
+ const FORM_WORDS = { none: "none", open: "open", allow: "a list ({ allow: [names or CIDRs] })" };
54
+ /** The forms as a choice in words: "none", "none or open", "none, open or a list (...)". */
55
+ const choices = (forms) => {
56
+ const words = forms.map((form) => FORM_WORDS[form]);
57
+ return words.length <= 1 ? (words[0] ?? "none") : `${words.slice(0, -1).join(", ")} or ${words.at(-1)}`;
58
+ };
59
+ /**
60
+ * Why a spec's network is refused by a provider (label) that declares forms, in plain words naming it and the choices;
61
+ * undefined when it is taken. A form the provider does not declare is refused, never widened or narrowed to another.
62
+ */
63
+ export function networkRefusal(label, forms, network) {
64
+ if (network === "none")
65
+ return forms.includes("none") ? undefined : `${label} can't run with no network; choose ${choices(forms)}`;
66
+ if (network === "open")
67
+ return forms.includes("open") ? undefined : `${label} can't open the network; choose ${choices(forms)}`;
68
+ if (typeof network === "object" && network !== null && !Array.isArray(network) && "allow" in network) {
69
+ if (!forms.includes("allow"))
70
+ return `${label} can't limit the network to a list; choose ${choices(forms)}`;
71
+ const allow = allowOf(network.allow, `${label}'s allowlist`);
72
+ return "problem" in allow ? allow.problem : undefined;
73
+ }
74
+ return `network is required: ${choices(forms)}`;
75
+ }
76
+ /** Whether a spec's network goes out through the proxy: open, or a list. */
77
+ export const throughProxy = (network) => network === "open" || (typeof network === "object" && network !== null && "allow" in network);
@@ -1,4 +1,4 @@
1
- import type { HostCall, MachineHost } from "../host.js";
1
+ import { type HostCall, type MachineHost } from "../host.js";
2
2
  import type { ArchilRoot } from "../mount-archil.js";
3
3
  import type { ComputerConnection } from "../provider.js";
4
4
  import { type ComputerErrorCode, type Result } from "../result.js";
@@ -7,22 +7,38 @@ export declare const CALL_SLACK_MS = 5000;
7
7
  export declare const seconds: (ms: number) => string;
8
8
  /** An error in words, the vendor's name kept, cut to one line of 300 characters. */
9
9
  export declare const words: (error: unknown) => string;
10
+ /** text with every secret in it written [redacted], the longest first; an empty or missing secret is skipped. */
11
+ export declare const redact: (text: string, secrets: readonly (string | undefined)[]) => string;
10
12
  /** A pause that ends early when signal aborts; never rejects. */
11
13
  export declare const pause: (ms: number, signal?: AbortSignal) => Promise<void>;
12
14
  /** A signal that aborts with the caller's, or once ms pass. */
13
15
  export declare const bounded: (ms: number, signal?: AbortSignal) => AbortSignal;
14
- /** The failures of one host: an error of code vendor names it. */
15
- export declare const failOf: (host: Pick<MachineHost, "id">) => (code: ComputerErrorCode, message: string) => Result<never>;
16
16
  /**
17
- * Settles with the promise's result, or a timeout or abort in words once ms pass or signal aborts. A host call that
18
- * answers a Result is passed on as it answers; one that throws is read through the host's errorCode.
17
+ * A promise that rejects with an AbortError (the caller's signal aborted) or a TimeoutError (ms passed), and clear to
18
+ * stop listening when the work finished first.
19
19
  */
20
- export declare function race<T>(host: Pick<MachineHost, "id" | "errorCode">, promise: Promise<T>, what: string, ms: number, signal?: AbortSignal): Promise<Result<T>>;
20
+ export declare function boundOf(ms: number, signal: AbortSignal | undefined, what: string): {
21
+ promise: Promise<never>;
22
+ clear: () => void;
23
+ };
24
+ /**
25
+ * The code of an error a host threw: a HostError's own, AbortError and TimeoutError by name, else the host's errorCode,
26
+ * else "vendor".
27
+ */
28
+ export declare function codeOfError(host: Pick<MachineHost, "errorCode">, error: unknown): ComputerErrorCode;
29
+ /** A Result's value, or a HostError in its words: for a host whose own client answers Results (hosted/rest.ts). */
30
+ export declare function orThrow<T>(result: Result<T>): T;
31
+ /**
32
+ * Settles with the promise's value, or a timeout or abort in words once ms pass or signal aborts. A host call that
33
+ * throws is read through codeOfError.
34
+ */
35
+ export declare function race<T>(host: Pick<MachineHost, "descriptor" | "errorCode">, promise: Promise<T>, what: string, ms: number, signal?: AbortSignal): Promise<Result<T>>;
21
36
  /**
22
37
  * One host call, bounded: ctx.timeoutMs is the vendor's own bound, and the race gives it CALL_SLACK_MS more. A call
23
- * that throws at once is an error like one that rejects; a Result the host answers keeps its own words, prefixed.
38
+ * that throws at once is an error like one that rejects. A call given up on (timeout or abort), by the race or by the
39
+ * host's own client (a HostError timeout), hands onLate what it answers: its value, or its failure, once it settles.
24
40
  */
25
- export declare function hostCall<T>(host: Pick<MachineHost, "id" | "errorCode">, what: string, run: (ctx: HostCall) => Promise<Result<T>>, ms: number, signal?: AbortSignal): Promise<Result<T>>;
41
+ export declare function hostCall<T>(host: Pick<MachineHost, "descriptor" | "errorCode">, what: string, run: (ctx: HostCall) => Promise<T>, ms: number, signal?: AbortSignal, onLate?: (late: Result<T>) => unknown): Promise<Result<T>>;
26
42
  /** What one process run to its end printed: its exit code, and both streams (each cut to its last 64 KiB). */
27
43
  export interface RunResult {
28
44
  exitCode: number;