@capybara-hq/plugin-sdk 0.1.0-rc.5 → 0.1.0-rc.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +4 -1
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +2 -0
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +29 -3
- package/agent-docs/plugin-format.md +53 -2
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +86 -1
- package/dist/bootstrap.js +161 -2
- package/dist/cards.d.ts +67 -13
- package/dist/cards.js +91 -21
- package/dist/channel.d.ts +148 -48
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/connector-auth.d.ts +7 -2
- package/dist/connector-auth.js +29 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +120 -29
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +11 -4
- package/dist/device-denied-paths.d.ts +14 -0
- package/dist/device-denied-paths.js +41 -0
- package/dist/device-operation.d.ts +302 -0
- package/dist/device-operation.js +292 -0
- package/dist/device-protocol.d.ts +490 -0
- package/dist/device-protocol.js +1117 -0
- package/dist/device-provider.d.ts +472 -0
- package/dist/device-provider.js +283 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +6 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +62 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +38 -9
- package/dist/identity.js +21 -1
- package/dist/index.d.ts +29 -2
- package/dist/index.js +29 -2
- package/dist/marketplace.d.ts +26 -0
- package/dist/marketplace.js +43 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +206 -71
- package/dist/model.js +152 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +41 -21
- package/dist/permissions.js +101 -42
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +169 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2318 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +476 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +135 -0
- package/dist/setup-guide-parse.js +413 -0
- package/dist/setup-guide-render.d.ts +50 -0
- package/dist/setup-guide-render.js +367 -0
- package/dist/setup-guide.d.ts +109 -0
- package/dist/setup-guide.js +377 -0
- package/dist/shell-capabilities.d.ts +231 -0
- package/dist/shell-capabilities.js +37 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +22 -0
- package/dist/skill-invocation.d.ts +4 -3
- package/dist/skill-invocation.js +5 -4
- package/dist/skill.d.ts +34 -21
- package/dist/skill.js +49 -32
- package/dist/storage.d.ts +52 -25
- package/dist/theme-assets.d.ts +55 -0
- package/dist/theme-assets.js +507 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +299 -0
- package/dist/theme-tokens.generated.js +184 -0
- package/dist/theme.d.ts +190 -0
- package/dist/theme.js +471 -0
- package/dist/tool.d.ts +69 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +348 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +212 -76
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +8 -1
- package/schemas/bootstrap-extra.v1.schema.json +172 -0
- package/schemas/bootstrap.v1.schema.json +6 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +117 -3
- package/schemas/theme.v1.schema.json +302 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/sandbox.d.ts +0 -232
- package/dist/sandbox.js +0 -120
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device provider contract `device-provider@1`: a multi, brokered, org-scoped extension point
|
|
3
|
+
* (extensions may not `requires` it; the kernel's `SandboxService` consumes it). The provider implements only the
|
|
4
|
+
* primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
|
|
5
|
+
* `writeFile`.
|
|
6
|
+
*
|
|
7
|
+
* A device separates its **file system** from its **instance**: the file system
|
|
8
|
+
* (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
|
|
9
|
+
* (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
|
|
10
|
+
*/
|
|
11
|
+
import type { SandboxBackground, SandboxBrowse, SandboxBrowseScope, SandboxOperation, SandboxOperationRef, SandboxOperationScope, SandboxPermissionSupport, SandboxPreparation, SandboxPreparationScope } from "./device-operation.js";
|
|
12
|
+
/** Device provider extension point ref. */
|
|
13
|
+
export declare const DEVICE_PROVIDER_EXTENSION_POINT = "device-provider@1";
|
|
14
|
+
/** The roots inside the sandbox the model may access. */
|
|
15
|
+
export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
|
|
16
|
+
/**
|
|
17
|
+
* Sandbox resource and network limits: what lifecycle create and update carry (resources and the
|
|
18
|
+
* outer network only; each operation's scope says how it runs). A provider that ignores `network`
|
|
19
|
+
* still runs: it then behaves as an allowlisted sandbox (the safe direction).
|
|
20
|
+
*/
|
|
21
|
+
export interface SandboxLimits {
|
|
22
|
+
cpu: number;
|
|
23
|
+
memoryMb: number;
|
|
24
|
+
diskMb: number;
|
|
25
|
+
/**
|
|
26
|
+
* The network the instance (cloud) must enforce, or the allowlist a local device's sandbox
|
|
27
|
+
* intersects with its own list (`open-public` is for cloud instances only). Each entry of
|
|
28
|
+
* `hosts` passes {@link validateAllowHost}.
|
|
29
|
+
*/
|
|
30
|
+
network: {
|
|
31
|
+
kind: "open-public" | "allowlist";
|
|
32
|
+
hosts: string[];
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The absolute roots inside one instance (a device may place them anywhere on its host). */
|
|
36
|
+
export interface SandboxRoots {
|
|
37
|
+
workspace: string;
|
|
38
|
+
skills: string;
|
|
39
|
+
tmp: string;
|
|
40
|
+
}
|
|
41
|
+
/** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
|
|
42
|
+
export declare const DEFAULT_SANDBOX_ROOTS: Readonly<SandboxRoots>;
|
|
43
|
+
/** The provider's instance handle. */
|
|
44
|
+
export interface SandboxHandle {
|
|
45
|
+
/** The provider's instance id. */
|
|
46
|
+
id: string;
|
|
47
|
+
/** The instance's roots; absent means {@link DEFAULT_SANDBOX_ROOTS}. */
|
|
48
|
+
roots?: SandboxRoots;
|
|
49
|
+
}
|
|
50
|
+
/** The roots of an instance, falling back to {@link DEFAULT_SANDBOX_ROOTS}. */
|
|
51
|
+
export declare function rootsOf(h: SandboxHandle): SandboxRoots;
|
|
52
|
+
/** The provider's file system handle (a device's files, independent of any instance). */
|
|
53
|
+
export interface FileSystemHandle {
|
|
54
|
+
/** The provider's file system id. */
|
|
55
|
+
id: string;
|
|
56
|
+
}
|
|
57
|
+
/** Who runs an `exec` (informational in phase 1: audit and attribution). */
|
|
58
|
+
export interface SandboxActor {
|
|
59
|
+
accountId: string;
|
|
60
|
+
conversationId: string;
|
|
61
|
+
/**
|
|
62
|
+
* The run the command serves. The kernel uses it to route run grants (network hosts allowed
|
|
63
|
+
* for the rest of a run) to a connected device; informational for other providers.
|
|
64
|
+
*/
|
|
65
|
+
runId?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The layer that refused a network host: `device` (the org allows it, the device's local policy
|
|
69
|
+
* does not), `org` (not in the org's effective egress), `address` (an IP literal or a name that
|
|
70
|
+
* points to a private or local address; never grantable), `unknown`.
|
|
71
|
+
*/
|
|
72
|
+
export type NetworkBlockLayer = "device" | "org" | "address" | "unknown";
|
|
73
|
+
/** A host a command was refused, as the provider reports it. */
|
|
74
|
+
export interface NetworkBlockedHost {
|
|
75
|
+
/** The host as the proxy saw it (IPv6 literals bracketed). */
|
|
76
|
+
host: string;
|
|
77
|
+
port: number;
|
|
78
|
+
layer: NetworkBlockLayer;
|
|
79
|
+
}
|
|
80
|
+
/** Result of a command. */
|
|
81
|
+
export interface ExecResult {
|
|
82
|
+
/** null on timeout or when aborted while running (`timedOut` is then true / false). */
|
|
83
|
+
exitCode: number | null;
|
|
84
|
+
stdout: string;
|
|
85
|
+
stderr: string;
|
|
86
|
+
truncated: boolean;
|
|
87
|
+
timedOut: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Network refusals during the command (optional for every provider): at most
|
|
90
|
+
* `MAX_NETWORK_BLOCKED_HOSTS` hosts, deduped by host. The kernel recomputes the `org` layer
|
|
91
|
+
* itself and never trusts a provider's word that the org allows a host.
|
|
92
|
+
*/
|
|
93
|
+
network?: {
|
|
94
|
+
blocked: NetworkBlockedHost[];
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
|
|
99
|
+
* `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
|
|
100
|
+
* instance gone; the kernel then rebuilds the instance and retries once. A transient connection
|
|
101
|
+
* failure throws a plain error.
|
|
102
|
+
*/
|
|
103
|
+
export declare class SandboxGoneError extends Error {
|
|
104
|
+
readonly sandboxGone: true;
|
|
105
|
+
constructor(message: string, opts?: {
|
|
106
|
+
cause?: unknown;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
110
|
+
export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
|
|
111
|
+
/**
|
|
112
|
+
* The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
|
|
113
|
+
* `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
|
|
114
|
+
* reports the device's files as lost rather than handing out a silently empty workspace.
|
|
115
|
+
*/
|
|
116
|
+
export declare class FileSystemGoneError extends Error {
|
|
117
|
+
readonly fileSystemGone: true;
|
|
118
|
+
constructor(message: string, opts?: {
|
|
119
|
+
cause?: unknown;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
123
|
+
export declare function isFileSystemGoneError(e: unknown): e is FileSystemGoneError;
|
|
124
|
+
/**
|
|
125
|
+
* A holder tag (`exec` argument `tag`, {@link DeviceProvider.killTagged}): the kernel passes its
|
|
126
|
+
* lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
|
|
127
|
+
* kill pattern.
|
|
128
|
+
*/
|
|
129
|
+
export declare const SANDBOX_TAG_RE: RegExp;
|
|
130
|
+
/** Text in English with an optional Chinese translation (what a person reads). */
|
|
131
|
+
export interface DeviceText {
|
|
132
|
+
en: string;
|
|
133
|
+
zh?: string;
|
|
134
|
+
}
|
|
135
|
+
/** The device a provider answers about: the kernel's device id, its org and the instance, if any. */
|
|
136
|
+
export interface DeviceRef {
|
|
137
|
+
deviceId: string;
|
|
138
|
+
orgId: string;
|
|
139
|
+
/** The current instance, or null when the device has none. */
|
|
140
|
+
handle: SandboxHandle | null;
|
|
141
|
+
}
|
|
142
|
+
/** One limit line of a {@link DeviceReport} (shown as is; the provider enforces it). */
|
|
143
|
+
export interface DeviceReportLimit {
|
|
144
|
+
label: DeviceText;
|
|
145
|
+
value: string;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* What a provider tells about a device ({@link DeviceProvider.report}): shown to people, never
|
|
149
|
+
* used for enforcement. `revision` changes whenever the rest changes; `home` is the owner's home
|
|
150
|
+
* directory (absolute) or null; `reset` says whether the provider can reset the device's files.
|
|
151
|
+
*/
|
|
152
|
+
export interface DeviceReport {
|
|
153
|
+
revision: string;
|
|
154
|
+
description: DeviceText;
|
|
155
|
+
home: string | null;
|
|
156
|
+
limits: DeviceReportLimit[];
|
|
157
|
+
reset: boolean;
|
|
158
|
+
}
|
|
159
|
+
/** Size limits {@link parseDeviceReport} enforces. */
|
|
160
|
+
export declare const DEVICE_REPORT_LIMITS: Readonly<{
|
|
161
|
+
revisionChars: 128;
|
|
162
|
+
descriptionChars: 300;
|
|
163
|
+
limits: 8;
|
|
164
|
+
limitLabelChars: 60;
|
|
165
|
+
limitValueChars: 60;
|
|
166
|
+
homeChars: 4096;
|
|
167
|
+
}>;
|
|
168
|
+
/** Checks a provider's report; throws `TypeError` on any other shape, returns a clean copy. */
|
|
169
|
+
export declare function parseDeviceReport(value: unknown): DeviceReport;
|
|
170
|
+
/**
|
|
171
|
+
* The provider refuses a project directory (`projects` operations: it lies where the provider
|
|
172
|
+
* will not serve, for example another connection's directory). `reason` is shown to the person.
|
|
173
|
+
* The kernel answers it as `device.project_refused` (422).
|
|
174
|
+
*/
|
|
175
|
+
export declare class ProjectPathRefusedError extends Error {
|
|
176
|
+
readonly projectPathRefused: true;
|
|
177
|
+
readonly reason: DeviceText;
|
|
178
|
+
constructor(reason: DeviceText, opts?: {
|
|
179
|
+
cause?: unknown;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
|
|
183
|
+
export declare function isProjectPathRefusedError(e: unknown): e is ProjectPathRefusedError;
|
|
184
|
+
/**
|
|
185
|
+
* The `device-provider@1` implementation (provided by a sandbox plugin such as Docker or E2B).
|
|
186
|
+
*
|
|
187
|
+
* **File systems and instances.** `createFileSystem` makes a device's files; they live until
|
|
188
|
+
* `destroyFileSystem` (the device is deleted). `create` makes an instance attached to an
|
|
189
|
+
* existing file system; `destroy` / `destroyByName` drop the instance only and keep the files, and
|
|
190
|
+
* `suspend` keeps them too. When the file system is gone, `create` must throw
|
|
191
|
+
* {@link FileSystemGoneError} and never create an empty one in its place (a Docker provider checks
|
|
192
|
+
* its volumes exist before mounting them, because Docker would otherwise create empty volumes).
|
|
193
|
+
*
|
|
194
|
+
* **Gone instances.** When the instance is definitely gone: `resume` returns `gone`; `exec` /
|
|
195
|
+
* `readFile` / `writeFile` / `stat` / `killAll` / `killTagged` throw {@link SandboxGoneError};
|
|
196
|
+
* `suspend` / `destroy` succeed as usual.
|
|
197
|
+
*
|
|
198
|
+
* **Auto-start**: when the instance still exists but is stopped or paused (for a reason outside the
|
|
199
|
+
* kernel: host or daemon restart, a process in the sandbox stopping its init, an idle sweep that
|
|
200
|
+
* stopped the instance before recording `suspended`...), `exec` / `readFile` / `writeFile` /
|
|
201
|
+
* `stat` / `killAll` / `killTagged` must start it transparently first (like `resume`, files kept)
|
|
202
|
+
* and then run, never fail: the kernel trusts only the `running` it recorded itself. Auto-start
|
|
203
|
+
* must be idempotent under concurrent calls: two calls that both find the instance stopped both
|
|
204
|
+
* start it without failing.
|
|
205
|
+
*
|
|
206
|
+
* **Time limits apply inside the sandbox too**: besides stopping a command after `timeoutMs` on the
|
|
207
|
+
* provider's side, `exec` must make the command in the sandbox kill itself shortly (a few seconds)
|
|
208
|
+
* after `timeoutMs`. When a kernel replica crashes, the provider-side timer goes with it, and a
|
|
209
|
+
* dropped connection does not end the command; the in-sandbox limit keeps it from running
|
|
210
|
+
* indefinitely next to the next holder's commands.
|
|
211
|
+
*
|
|
212
|
+
* **Abort**: every method must respond to `signal` promptly (fail at once when already aborted, end
|
|
213
|
+
* with the abort reason as soon as possible when aborted mid-way): the kernel relies on it to stop
|
|
214
|
+
* on lock loss, run abort or timeout, and ignoring it may let two holders operate on one instance.
|
|
215
|
+
* An aborted `exec` must kill its running command (and the processes it spawned), not just stop
|
|
216
|
+
* waiting for its output; an `exec` aborted after its command started resolves normally with
|
|
217
|
+
* `exitCode: null`, `timedOut: false` (and the output collected so far), it does not reject. An
|
|
218
|
+
* `exec` called with an already aborted signal rejects at once.
|
|
219
|
+
*
|
|
220
|
+
* **Concurrent use** (required in `@2`): the sessions of one device share its instance, so the
|
|
221
|
+
* kernel calls `exec`, `readFile`, `writeFile` and `stat` concurrently on one instance. Those four
|
|
222
|
+
* methods must be safe to call concurrently. Each `exec` labels its command with its `tag`, and an
|
|
223
|
+
* aborted `exec` kills only its own command.
|
|
224
|
+
*/
|
|
225
|
+
export interface DeviceProvider {
|
|
226
|
+
/** Runtime permission support for this instance; does not grant consent or provision an instance. */
|
|
227
|
+
permissionSupport?(h: SandboxHandle, signal: AbortSignal): Promise<SandboxPermissionSupport>;
|
|
228
|
+
/**
|
|
229
|
+
* Fresh immutable grant for one actual method invocation. Lightweight until a method is called;
|
|
230
|
+
* never cache grants on the handle or fall back to raw methods when unsupported.
|
|
231
|
+
*/
|
|
232
|
+
operation?(h: SandboxHandle, scope: SandboxOperationScope, signal: AbortSignal): Promise<SandboxOperation>;
|
|
233
|
+
/** Trusted skill/attachment staging only; never exposed to user operations. */
|
|
234
|
+
prepare?(h: SandboxHandle, scope: SandboxPreparationScope, signal: AbortSignal): Promise<SandboxPreparation>;
|
|
235
|
+
/** Owner-authenticated metadata browsing without conversation/profile consent. */
|
|
236
|
+
browse?(h: SandboxHandle, scope: SandboxBrowseScope, signal: AbortSignal): Promise<SandboxBrowse>;
|
|
237
|
+
/**
|
|
238
|
+
* Required for permission support: idempotently persist an operation-ID tombstone before
|
|
239
|
+
* cancelling exact owned work. A delayed launch checks it before effects; retain it through
|
|
240
|
+
* admitBeforeMs and any owned execution's lifetime, including across kernel restarts.
|
|
241
|
+
*/
|
|
242
|
+
revokeOperation?(h: SandboxHandle, ref: SandboxOperationRef, signal: AbortSignal): Promise<void>;
|
|
243
|
+
/** Exact registered background ownership; missing support must not fall back to shell launch. */
|
|
244
|
+
background?: SandboxBackground;
|
|
245
|
+
/** `exec` / `readFile` / `writeFile` / `stat` may run concurrently on one instance (required). */
|
|
246
|
+
readonly concurrentExec: true;
|
|
247
|
+
/**
|
|
248
|
+
* Declares that the provider enforces `limits.network` allowlists (required, always `true`):
|
|
249
|
+
* a provider that cannot restrict outbound hosts does not implement `device-provider@1`.
|
|
250
|
+
*/
|
|
251
|
+
readonly networkAllowlist: true;
|
|
252
|
+
/**
|
|
253
|
+
* What the provider tells about the device: a description, the owner's home, limits and whether
|
|
254
|
+
* files can be reset ({@link DeviceReport}). Shown to people only; the answer passes
|
|
255
|
+
* {@link parseDeviceReport}. Must respond to `signal`.
|
|
256
|
+
*/
|
|
257
|
+
report(device: DeviceRef, signal: AbortSignal): Promise<DeviceReport>;
|
|
258
|
+
/**
|
|
259
|
+
* Whether the provider isolates the sessions of one device from each other inside the
|
|
260
|
+
* instance (a declared capability; absent means false).
|
|
261
|
+
*/
|
|
262
|
+
readonly sessionIsolation?: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Where `create`-time limits are fixed: `instance` (absent; Docker: a new instance applies new
|
|
265
|
+
* limits) or `fileSystem` (E2B: the instance is the file system, so only a file reset applies
|
|
266
|
+
* them without {@link DeviceProvider.update}).
|
|
267
|
+
*/
|
|
268
|
+
readonly limitsApplyAt?: "instance" | "fileSystem";
|
|
269
|
+
/**
|
|
270
|
+
* Applies new limits to a running instance without recreating it (optional). `recreate` asks
|
|
271
|
+
* the kernel to destroy the instance and create one on the same files instead.
|
|
272
|
+
*/
|
|
273
|
+
update?(h: SandboxHandle, limits: SandboxLimits, signal: AbortSignal): Promise<"updated" | "recreate">;
|
|
274
|
+
/**
|
|
275
|
+
* Creates a device's file system. `name` looks like `cap-device-<deviceId>`. If a file
|
|
276
|
+
* system with this name already exists, return it.
|
|
277
|
+
*/
|
|
278
|
+
createFileSystem(args: {
|
|
279
|
+
name: string;
|
|
280
|
+
limits: SandboxLimits;
|
|
281
|
+
signal: AbortSignal;
|
|
282
|
+
}): Promise<FileSystemHandle>;
|
|
283
|
+
/** Deletes the file system and its files. Succeeds when it does not exist. */
|
|
284
|
+
destroyFileSystem(fs: FileSystemHandle, signal: AbortSignal): Promise<void>;
|
|
285
|
+
/**
|
|
286
|
+
* Deletes the file system made under `name` by `createFileSystem`; succeeds when there is none.
|
|
287
|
+
* The kernel uses it when it has no handle (`createFileSystem` finished on the provider's side
|
|
288
|
+
* but the kernel stopped before recording the handle), and in its one-off cleanup of
|
|
289
|
+
* per-conversation sandboxes with `cap-<conversationId>` names that a `sandbox@1` provider's
|
|
290
|
+
* `create` made together with their files (Docker: the `cap-<conversationId>-workspace` and
|
|
291
|
+
* `-skills` volumes); a provider removes those under the same call.
|
|
292
|
+
*/
|
|
293
|
+
destroyFileSystemByName(name: string, signal: AbortSignal): Promise<void>;
|
|
294
|
+
/**
|
|
295
|
+
* Creates an instance attached to `fileSystem`. Without `image` the provider uses its own
|
|
296
|
+
* published image. Throws {@link FileSystemGoneError} when the file system is gone.
|
|
297
|
+
*/
|
|
298
|
+
create(args: {
|
|
299
|
+
name: string;
|
|
300
|
+
image?: string;
|
|
301
|
+
limits: SandboxLimits;
|
|
302
|
+
fileSystem: FileSystemHandle;
|
|
303
|
+
signal: AbortSignal;
|
|
304
|
+
}): Promise<SandboxHandle>;
|
|
305
|
+
/** `gone` means the provider no longer has this instance. */
|
|
306
|
+
resume(h: SandboxHandle, signal: AbortSignal): Promise<"resumed" | "gone">;
|
|
307
|
+
/** Files must be kept. Succeeds when the instance does not exist. */
|
|
308
|
+
suspend(h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
309
|
+
/** Drops the instance only; the file system and its files are kept. Succeeds when it does not exist. */
|
|
310
|
+
destroy(h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Drops the instance made under `name` by `create` (instance only, files kept); succeeds when
|
|
313
|
+
* there is none. The kernel uses it when it has no handle (`create` finished on the provider's
|
|
314
|
+
* side but the kernel stopped before recording the handle), and in its one-off cleanup of
|
|
315
|
+
* per-conversation sandboxes with `cap-<conversationId>` names made by a `sandbox@1` provider's
|
|
316
|
+
* `create`.
|
|
317
|
+
*/
|
|
318
|
+
destroyByName(name: string, signal: AbortSignal): Promise<void>;
|
|
319
|
+
/**
|
|
320
|
+
* Kills every running command started through `exec` in this instance (and the processes they
|
|
321
|
+
* spawned that did not start their own session). The kernel calls it only when no other holder
|
|
322
|
+
* can be running commands (an instance just resumed from `suspended`, or under the exclusive
|
|
323
|
+
* lease), never while another session may be; to clean up after one crashed holder it uses
|
|
324
|
+
* {@link DeviceProvider.killTagged}. Processes a command put in the background in their own
|
|
325
|
+
* session are not guaranteed to be killed.
|
|
326
|
+
*/
|
|
327
|
+
killAll(h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
328
|
+
/**
|
|
329
|
+
* Kills every running `exec` command labelled with one of `tags` (and its process tree), leaving
|
|
330
|
+
* other commands running. The kernel calls it for the tags of holders that crashed while live
|
|
331
|
+
* holders keep running commands. Tags match {@link SANDBOX_TAG_RE}. Match whole tags: one tag
|
|
332
|
+
* may be a prefix of another (`ab` of `ab-cd`), and killing `ab` must not touch `ab-cd`'s
|
|
333
|
+
* commands.
|
|
334
|
+
*/
|
|
335
|
+
killTagged(h: SandboxHandle, tags: string[], signal: AbortSignal): Promise<void>;
|
|
336
|
+
/**
|
|
337
|
+
* Runs a command. `maxOutputBytes` caps stdout and stderr **combined**; the rest is dropped and
|
|
338
|
+
* `truncated` is true.
|
|
339
|
+
*/
|
|
340
|
+
exec(h: SandboxHandle, args: {
|
|
341
|
+
command: string;
|
|
342
|
+
cwd?: string;
|
|
343
|
+
env?: Record<string, string>;
|
|
344
|
+
timeoutMs: number;
|
|
345
|
+
maxOutputBytes: number;
|
|
346
|
+
signal: AbortSignal;
|
|
347
|
+
/**
|
|
348
|
+
* The holder's tag ({@link SANDBOX_TAG_RE}); label the command with it so
|
|
349
|
+
* {@link DeviceProvider.killTagged} can find it.
|
|
350
|
+
*/
|
|
351
|
+
tag: string;
|
|
352
|
+
/** Who runs the command; informational in phase 1 (record it, do not act on it). */
|
|
353
|
+
actor: SandboxActor;
|
|
354
|
+
}): Promise<ExecResult>;
|
|
355
|
+
/**
|
|
356
|
+
* Reads a file (at most `maxBytes`; longer files are truncated and `truncated` is true). Returns
|
|
357
|
+
* null when it does not exist or is a directory.
|
|
358
|
+
*/
|
|
359
|
+
readFile(h: SandboxHandle, path: string, opts: {
|
|
360
|
+
maxBytes: number;
|
|
361
|
+
signal: AbortSignal;
|
|
362
|
+
}): Promise<{
|
|
363
|
+
data: Uint8Array;
|
|
364
|
+
truncated: boolean;
|
|
365
|
+
} | null>;
|
|
366
|
+
/** Parent directories are created. */
|
|
367
|
+
writeFile(h: SandboxHandle, path: string, data: Uint8Array, signal: AbortSignal): Promise<void>;
|
|
368
|
+
stat(h: SandboxHandle, path: string, signal: AbortSignal): Promise<{
|
|
369
|
+
size: number;
|
|
370
|
+
isDir: boolean;
|
|
371
|
+
} | null>;
|
|
372
|
+
/**
|
|
373
|
+
* Lists one directory's entries — each entry's `name` and whether it `isDir` — sorted by code
|
|
374
|
+
* unit (locale-independent), at most `limit` of them; `truncated` is true when the directory has
|
|
375
|
+
* more. Entries only: never file contents, never a recursive walk. A `name` is never `.` or `..`;
|
|
376
|
+
* `isDir` follows symbolic links (stat semantics: a link to a directory is `true`, a dangling link
|
|
377
|
+
* `false`, and so is a link whose target the device cannot reach). Returns null only when the
|
|
378
|
+
* path does not exist and the device could reach it; a path it cannot reach throws (a policy
|
|
379
|
+
* refusal), as does a path that is a file or a directory that cannot be read.
|
|
380
|
+
*
|
|
381
|
+
* Optional: a provider without it (or without {@link DeviceProvider.scan}) offers no projects,
|
|
382
|
+
* and its conversations stay in free mode.
|
|
383
|
+
*/
|
|
384
|
+
list?(h: SandboxHandle, path: string, opts: {
|
|
385
|
+
limit: number;
|
|
386
|
+
signal: AbortSignal;
|
|
387
|
+
}): Promise<{
|
|
388
|
+
entries: {
|
|
389
|
+
name: string;
|
|
390
|
+
isDir: boolean;
|
|
391
|
+
}[];
|
|
392
|
+
truncated: boolean;
|
|
393
|
+
} | null>;
|
|
394
|
+
/**
|
|
395
|
+
* Looks for project-like directories, read as for {@link DeviceProvider.list}. Every provider
|
|
396
|
+
* traverses the same way:
|
|
397
|
+
*
|
|
398
|
+
* - Candidates are `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH}
|
|
399
|
+
* levels below it that hold a `.git` entry (directory or file) or an `AGENTS.md` file.
|
|
400
|
+
* - The walk does not follow symbolic links and does not enter hidden directories (names
|
|
401
|
+
* starting with `.`); a candidate does not stop the descent (a monorepo's sub-projects are
|
|
402
|
+
* candidates too). It never enters a directory named in {@link DEVICE_SCAN_SKIPPED_DIRS}, at
|
|
403
|
+
* any depth, nor one named in {@link DEVICE_SCAN_SKIPPED_BASE_DIRS} directly under `base`;
|
|
404
|
+
* every provider skips exactly these. Paths under `base` the device cannot reach are skipped,
|
|
405
|
+
* never an error.
|
|
406
|
+
* - A directory whose basename does not satisfy {@link isDeviceProjectName} is not returned as
|
|
407
|
+
* a candidate (never with a changed name), but it is still traversed.
|
|
408
|
+
* - Directories are visited breadth-first, each level in code-unit order of `path`, `base`
|
|
409
|
+
* counting as the first visit (visiting a directory reads its entries; one that cannot be read
|
|
410
|
+
* still counts as a visit); the walk stops after {@link MAX_DEVICE_SCAN_DIRS} visits, so a
|
|
411
|
+
* huge tree answers what was found by then.
|
|
412
|
+
* - Each candidate is its absolute `path` and its basename as `suggestedName`; the candidates
|
|
413
|
+
* found are sorted by `path` in code-unit order and cut to the first
|
|
414
|
+
* {@link MAX_DEVICE_SCAN_RESULTS}.
|
|
415
|
+
*
|
|
416
|
+
* Directory entries only, never file contents. A `base` that does not exist answers `[]`; a
|
|
417
|
+
* `base` that is a file, cannot be read, or lies outside what the device reaches throws.
|
|
418
|
+
* Optional, like `list`.
|
|
419
|
+
*/
|
|
420
|
+
scan?(h: SandboxHandle, base: string, opts: {
|
|
421
|
+
signal: AbortSignal;
|
|
422
|
+
}): Promise<{
|
|
423
|
+
path: string;
|
|
424
|
+
suggestedName: string;
|
|
425
|
+
}[]>;
|
|
426
|
+
}
|
|
427
|
+
/** The longest project name, in UTF-16 code units. */
|
|
428
|
+
export declare const MAX_DEVICE_PROJECT_NAME_LENGTH = 64;
|
|
429
|
+
/** The most candidates a `scan` answers ({@link DeviceProvider.scan}). */
|
|
430
|
+
export declare const MAX_DEVICE_SCAN_RESULTS = 50;
|
|
431
|
+
/**
|
|
432
|
+
* Directory names a `scan` never enters, at any depth ({@link DeviceProvider.scan}): dependency
|
|
433
|
+
* trees, not projects. Every provider skips exactly these.
|
|
434
|
+
*/
|
|
435
|
+
export declare const DEVICE_SCAN_SKIPPED_DIRS: readonly string[];
|
|
436
|
+
/**
|
|
437
|
+
* Directory names a `scan` does not enter directly under its `base` ({@link DeviceProvider.scan}):
|
|
438
|
+
* the owner's macOS `Library` (app data, huge, partly privacy-protected) is not where projects
|
|
439
|
+
* live. Every provider skips exactly these.
|
|
440
|
+
*/
|
|
441
|
+
export declare const DEVICE_SCAN_SKIPPED_BASE_DIRS: readonly string[];
|
|
442
|
+
/** How far below its base a `scan` looks: the base's children and their children. */
|
|
443
|
+
export declare const MAX_DEVICE_SCAN_DEPTH = 2;
|
|
444
|
+
/**
|
|
445
|
+
* The most directories one `scan` visits (reads the entries of), its `base` included
|
|
446
|
+
* ({@link DeviceProvider.scan}): breadth-first, each level in code-unit order of path.
|
|
447
|
+
*/
|
|
448
|
+
export declare const MAX_DEVICE_SCAN_DIRS = 500;
|
|
449
|
+
/**
|
|
450
|
+
* Whether `v` is a valid project name (a project's identity on its device, and a `scan`
|
|
451
|
+
* candidate's `suggestedName`): non-empty, at most {@link MAX_DEVICE_PROJECT_NAME_LENGTH} UTF-16
|
|
452
|
+
* code units, not `.` or `..`, no `/`, no control characters, and no leading or trailing
|
|
453
|
+
* whitespace.
|
|
454
|
+
*/
|
|
455
|
+
export declare function isDeviceProjectName(v: unknown): v is string;
|
|
456
|
+
/**
|
|
457
|
+
* The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
|
|
458
|
+
* control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
|
|
459
|
+
* empty when valid. {@link validateSandboxPath} adds root membership.
|
|
460
|
+
*/
|
|
461
|
+
export declare function validateSandboxPathShape(p: string): string[];
|
|
462
|
+
/**
|
|
463
|
+
* Checks a path inside an instance; returns the errors, empty when valid: the
|
|
464
|
+
* {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
|
|
465
|
+
* ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
|
|
466
|
+
*/
|
|
467
|
+
export declare function validateSandboxPath(p: string, roots?: SandboxRoots): string[];
|
|
468
|
+
/**
|
|
469
|
+
* Validates an outbound allowlist host name: lowercase, no protocol or port, optional leading `*.`,
|
|
470
|
+
* IDN accepted only as punycode.
|
|
471
|
+
*/
|
|
472
|
+
export declare function validateAllowHost(h: string): string[];
|