@capybara-hq/plugin-sdk 0.1.0-rc.3 → 0.1.0-rc.31
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/agent-docs/agent-templates.md +15 -3
- package/agent-docs/concepts.md +5 -0
- package/agent-docs/connector-templates.md +2 -1
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/config-source.md +1 -1
- package/agent-docs/extension-points/connector.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/counter.md +1 -1
- package/agent-docs/extension-points/directory.md +1 -1
- package/agent-docs/extension-points/file-preview.md +1 -1
- package/agent-docs/extension-points/identity-source.md +1 -1
- package/agent-docs/extension-points/model-provider.md +4 -2
- package/agent-docs/extension-points/object-store.md +3 -1
- package/agent-docs/extension-points/sandbox.md +3 -3
- package/agent-docs/extension-points/secret-store.md +1 -1
- package/agent-docs/extension-points/web-fetch.md +1 -1
- package/agent-docs/extension-points/web-search.md +1 -1
- package/agent-docs/extensions.md +29 -4
- package/agent-docs/plugin-format.md +43 -3
- package/agent-docs/setup.md +46 -0
- package/agent-docs/skills.md +1 -1
- package/agent-docs/tool-naming.md +1 -1
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/bootstrap.d.ts +15 -1
- package/dist/bootstrap.js +17 -1
- package/dist/cards.d.ts +56 -13
- package/dist/cards.js +90 -20
- package/dist/channel.d.ts +111 -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 +135 -26
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +11 -4
- package/dist/device-protocol-v3.d.ts +117 -0
- package/dist/device-protocol-v3.js +409 -0
- package/dist/device-protocol.d.ts +330 -0
- package/dist/device-protocol.js +567 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +5 -2
- package/dist/file-preview.d.ts +1 -1
- package/dist/git-hosts.d.ts +44 -0
- package/dist/git-hosts.js +81 -0
- package/dist/hooks.d.ts +111 -21
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +52 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +22 -9
- package/dist/index.d.ts +23 -1
- package/dist/index.js +24 -1
- 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 +180 -71
- package/dist/model.js +71 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/permissions.d.ts +42 -20
- package/dist/permissions.js +97 -40
- 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/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +1886 -0
- package/dist/sandbox-native-runtime-source.d.ts +8 -0
- package/dist/sandbox-native-runtime-source.js +325 -0
- package/dist/sandbox-operation.d.ts +248 -0
- package/dist/sandbox-operation.js +245 -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 +60 -0
- package/dist/sandbox-write-denies.js +630 -0
- package/dist/sandbox.d.ts +201 -16
- package/dist/sandbox.js +89 -14
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +115 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +350 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +94 -0
- package/dist/setup-guide.js +336 -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 +48 -31
- package/dist/storage.d.ts +52 -25
- package/dist/theme-assets.d.ts +39 -0
- package/dist/theme-assets.js +449 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +279 -0
- package/dist/theme-tokens.generated.js +174 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -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 +337 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +53 -0
- package/dist/ui-slots.js +238 -0
- package/dist/ui.d.ts +191 -79
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +7 -1
- 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 +115 -3
- package/schemas/theme.v1.schema.json +225 -0
package/dist/sandbox.d.ts
CHANGED
|
@@ -4,29 +4,60 @@
|
|
|
4
4
|
* primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
|
|
5
5
|
* `writeFile`.
|
|
6
6
|
*
|
|
7
|
-
* `@2` separates
|
|
8
|
-
* (`createFileSystem`) lives until the
|
|
7
|
+
* `@2` separates a device's **file system** from its **instance**: the file system
|
|
8
|
+
* (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
|
|
9
9
|
* (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
|
|
10
10
|
*/
|
|
11
|
+
import type { SandboxBackground, SandboxBrowse, SandboxBrowseScope, SandboxOperation, SandboxOperationRef, SandboxOperationScope, SandboxPermissionSupport, SandboxPreparation, SandboxPreparationScope } from "./sandbox-operation.js";
|
|
11
12
|
/** Sandbox extension point ref. */
|
|
12
13
|
export declare const SANDBOX_EXTENSION_POINT = "sandbox@2";
|
|
13
14
|
/** The roots inside the sandbox the model may access. */
|
|
14
15
|
export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
|
|
15
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Sandbox resource and network limits. A provider that ignores `mode` and `network` still runs:
|
|
18
|
+
* it then behaves as an allowlisted sandbox (the safe direction).
|
|
19
|
+
*/
|
|
16
20
|
export interface SandboxLimits {
|
|
17
21
|
cpu: number;
|
|
18
22
|
memoryMb: number;
|
|
19
23
|
diskMb: number;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
/**
|
|
25
|
+
* `auto`: no OS sandbox (local: the owner; cloud: the container is the boundary);
|
|
26
|
+
* `sandbox`: the OS sandbox with the network limited by {@link SandboxLimits.network}.
|
|
27
|
+
* For operation-capable providers this encodes the independent device ceiling: auto allows
|
|
28
|
+
* Full access when separately authorized, sandbox permits restricted operations only.
|
|
29
|
+
* It never selects a conversation profile or changes per operation. Legacy consumers retain
|
|
30
|
+
* the current mode behavior until coordinated protocol activation.
|
|
31
|
+
*/
|
|
32
|
+
mode: "auto" | "sandbox";
|
|
33
|
+
/**
|
|
34
|
+
* The network the instance (cloud) must enforce, or the allowlist a local device's sandbox mode
|
|
35
|
+
* intersects with its own list (`open-public` is for cloud instances only). Each entry of
|
|
36
|
+
* `hosts` passes {@link validateAllowHost}.
|
|
37
|
+
*/
|
|
38
|
+
network: {
|
|
39
|
+
kind: "open-public" | "allowlist";
|
|
40
|
+
hosts: string[];
|
|
41
|
+
};
|
|
23
42
|
}
|
|
43
|
+
/** The absolute roots inside one instance (a device may place them anywhere on its host). */
|
|
44
|
+
export interface SandboxRoots {
|
|
45
|
+
workspace: string;
|
|
46
|
+
skills: string;
|
|
47
|
+
tmp: string;
|
|
48
|
+
}
|
|
49
|
+
/** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
|
|
50
|
+
export declare const DEFAULT_SANDBOX_ROOTS: Readonly<SandboxRoots>;
|
|
24
51
|
/** The provider's instance handle. */
|
|
25
52
|
export interface SandboxHandle {
|
|
26
53
|
/** The provider's instance id. */
|
|
27
54
|
id: string;
|
|
55
|
+
/** The instance's roots; absent means {@link DEFAULT_SANDBOX_ROOTS}. */
|
|
56
|
+
roots?: SandboxRoots;
|
|
28
57
|
}
|
|
29
|
-
/** The
|
|
58
|
+
/** The roots of an instance, falling back to {@link DEFAULT_SANDBOX_ROOTS}. */
|
|
59
|
+
export declare function rootsOf(h: SandboxHandle): SandboxRoots;
|
|
60
|
+
/** The provider's file system handle (a device's files, independent of any instance). */
|
|
30
61
|
export interface FileSystemHandle {
|
|
31
62
|
/** The provider's file system id. */
|
|
32
63
|
id: string;
|
|
@@ -35,6 +66,24 @@ export interface FileSystemHandle {
|
|
|
35
66
|
export interface SandboxActor {
|
|
36
67
|
accountId: string;
|
|
37
68
|
conversationId: string;
|
|
69
|
+
/**
|
|
70
|
+
* The run the command serves. The kernel uses it to route run grants (network hosts allowed
|
|
71
|
+
* for the rest of a run) to a connected device; informational for other providers.
|
|
72
|
+
*/
|
|
73
|
+
runId?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The layer that refused a network host: `device` (the org allows it, the device's local policy
|
|
77
|
+
* does not), `org` (not in the org's effective egress), `address` (an IP literal or a name that
|
|
78
|
+
* points to a private or local address; never grantable), `unknown`.
|
|
79
|
+
*/
|
|
80
|
+
export type NetworkBlockLayer = "device" | "org" | "address" | "unknown";
|
|
81
|
+
/** A host a command was refused, as the provider reports it. */
|
|
82
|
+
export interface NetworkBlockedHost {
|
|
83
|
+
/** The host as the proxy saw it (IPv6 literals bracketed). */
|
|
84
|
+
host: string;
|
|
85
|
+
port: number;
|
|
86
|
+
layer: NetworkBlockLayer;
|
|
38
87
|
}
|
|
39
88
|
/** Result of a command. */
|
|
40
89
|
export interface ExecResult {
|
|
@@ -44,6 +93,14 @@ export interface ExecResult {
|
|
|
44
93
|
stderr: string;
|
|
45
94
|
truncated: boolean;
|
|
46
95
|
timedOut: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Network refusals during the command (optional for every provider): at most
|
|
98
|
+
* `MAX_NETWORK_BLOCKED_HOSTS` hosts, deduped by host. The kernel recomputes the `org` layer
|
|
99
|
+
* itself and never trusts a provider's word that the org allows a host.
|
|
100
|
+
*/
|
|
101
|
+
network?: {
|
|
102
|
+
blocked: NetworkBlockedHost[];
|
|
103
|
+
};
|
|
47
104
|
}
|
|
48
105
|
/**
|
|
49
106
|
* The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
|
|
@@ -62,7 +119,7 @@ export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
|
|
|
62
119
|
/**
|
|
63
120
|
* The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
|
|
64
121
|
* `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
|
|
65
|
-
* reports the
|
|
122
|
+
* reports the device's files as lost rather than handing out a silently empty workspace.
|
|
66
123
|
*/
|
|
67
124
|
export declare class FileSystemGoneError extends Error {
|
|
68
125
|
readonly fileSystemGone: true;
|
|
@@ -81,8 +138,8 @@ export declare const SANDBOX_TAG_RE: RegExp;
|
|
|
81
138
|
/**
|
|
82
139
|
* The `sandbox@2` implementation (provided by a sandbox plugin such as Docker or E2B).
|
|
83
140
|
*
|
|
84
|
-
* **File systems and instances.** `createFileSystem` makes
|
|
85
|
-
* `destroyFileSystem` (the
|
|
141
|
+
* **File systems and instances.** `createFileSystem` makes a device's files; they live until
|
|
142
|
+
* `destroyFileSystem` (the device is deleted). `create` makes an instance attached to an
|
|
86
143
|
* existing file system; `destroy` / `destroyByName` drop the instance only and keep the files, and
|
|
87
144
|
* `suspend` keeps them too. When the file system is gone, `create` must throw
|
|
88
145
|
* {@link FileSystemGoneError} and never create an empty one in its place (a Docker provider checks
|
|
@@ -114,21 +171,51 @@ export declare const SANDBOX_TAG_RE: RegExp;
|
|
|
114
171
|
* `exitCode: null`, `timedOut: false` (and the output collected so far), it does not reject. An
|
|
115
172
|
* `exec` called with an already aborted signal rejects at once.
|
|
116
173
|
*
|
|
117
|
-
* **Concurrent use** (required in `@2`): the sessions of one
|
|
174
|
+
* **Concurrent use** (required in `@2`): the sessions of one device share its instance, so the
|
|
118
175
|
* kernel calls `exec`, `readFile`, `writeFile` and `stat` concurrently on one instance. Those four
|
|
119
176
|
* methods must be safe to call concurrently. Each `exec` labels its command with its `tag`, and an
|
|
120
177
|
* aborted `exec` kills only its own command.
|
|
121
178
|
*/
|
|
122
179
|
export interface SandboxProvider {
|
|
180
|
+
/** Runtime permission support for this instance; does not grant consent or provision an instance. */
|
|
181
|
+
permissionSupport?(h: SandboxHandle, signal: AbortSignal): Promise<SandboxPermissionSupport>;
|
|
182
|
+
/**
|
|
183
|
+
* Fresh immutable grant for one actual method invocation. Lightweight until a method is called;
|
|
184
|
+
* never cache grants on the handle or fall back to raw methods when unsupported.
|
|
185
|
+
*/
|
|
186
|
+
operation?(h: SandboxHandle, scope: SandboxOperationScope, signal: AbortSignal): Promise<SandboxOperation>;
|
|
187
|
+
/** Trusted skill/attachment staging only; never exposed to user operations. */
|
|
188
|
+
prepare?(h: SandboxHandle, scope: SandboxPreparationScope, signal: AbortSignal): Promise<SandboxPreparation>;
|
|
189
|
+
/** Owner-authenticated metadata browsing without conversation/profile consent. */
|
|
190
|
+
browse?(h: SandboxHandle, scope: SandboxBrowseScope, signal: AbortSignal): Promise<SandboxBrowse>;
|
|
191
|
+
/**
|
|
192
|
+
* Required for permission support: idempotently persist an operation-ID tombstone before
|
|
193
|
+
* cancelling exact owned work. A delayed launch checks it before effects; retain it through
|
|
194
|
+
* admitBeforeMs and any owned execution's lifetime, including across kernel restarts.
|
|
195
|
+
*/
|
|
196
|
+
revokeOperation?(h: SandboxHandle, ref: SandboxOperationRef, signal: AbortSignal): Promise<void>;
|
|
197
|
+
/** Exact registered background ownership; missing support must not fall back to shell launch. */
|
|
198
|
+
background?: SandboxBackground;
|
|
123
199
|
/** `exec` / `readFile` / `writeFile` / `stat` may run concurrently on one instance (required). */
|
|
124
200
|
readonly concurrentExec: true;
|
|
125
201
|
/**
|
|
126
|
-
* Whether the provider isolates the sessions of one
|
|
202
|
+
* Whether the provider isolates the sessions of one device from each other inside the
|
|
127
203
|
* instance (a declared capability; absent means false).
|
|
128
204
|
*/
|
|
129
205
|
readonly sessionIsolation?: boolean;
|
|
130
206
|
/**
|
|
131
|
-
*
|
|
207
|
+
* Where `create`-time limits are fixed: `instance` (absent; Docker: a new instance applies new
|
|
208
|
+
* limits) or `fileSystem` (E2B: the instance is the file system, so only a file reset applies
|
|
209
|
+
* them without {@link SandboxProvider.update}).
|
|
210
|
+
*/
|
|
211
|
+
readonly limitsApplyAt?: "instance" | "fileSystem";
|
|
212
|
+
/**
|
|
213
|
+
* Applies new limits to a running instance without recreating it (optional). `recreate` asks
|
|
214
|
+
* the kernel to destroy the instance and create one on the same files instead.
|
|
215
|
+
*/
|
|
216
|
+
update?(h: SandboxHandle, limits: SandboxLimits, signal: AbortSignal): Promise<"updated" | "recreate">;
|
|
217
|
+
/**
|
|
218
|
+
* Creates a device's file system. `name` looks like `cap-device-<deviceId>`. If a file
|
|
132
219
|
* system with this name already exists, return it.
|
|
133
220
|
*/
|
|
134
221
|
createFileSystem(args: {
|
|
@@ -225,8 +312,106 @@ export interface SandboxProvider {
|
|
|
225
312
|
size: number;
|
|
226
313
|
isDir: boolean;
|
|
227
314
|
} | null>;
|
|
315
|
+
/**
|
|
316
|
+
* Lists one directory's entries — each entry's `name` and whether it `isDir` — sorted by code
|
|
317
|
+
* unit (locale-independent), at most `limit` of them; `truncated` is true when the directory has
|
|
318
|
+
* more. Entries only: never file contents, never a recursive walk. A `name` is never `.` or `..`;
|
|
319
|
+
* `isDir` follows symbolic links (stat semantics: a link to a directory is `true`, a dangling link
|
|
320
|
+
* `false`, and so is a link whose target the request's mode cannot reach). `limits` is the kernel's current ceiling: read in the mode it gives, never in one an
|
|
321
|
+
* earlier command saw. Returns null only when the path does not exist and that mode could reach
|
|
322
|
+
* it; a path the mode cannot reach throws (a policy refusal), as does a path that is a file or a
|
|
323
|
+
* directory that cannot be read.
|
|
324
|
+
*
|
|
325
|
+
* Optional: a provider without it (or without {@link SandboxProvider.scan}) offers no projects,
|
|
326
|
+
* and its conversations stay in free mode.
|
|
327
|
+
*/
|
|
328
|
+
list?(h: SandboxHandle, path: string, opts: {
|
|
329
|
+
limit: number;
|
|
330
|
+
limits: Pick<SandboxLimits, "mode">;
|
|
331
|
+
signal: AbortSignal;
|
|
332
|
+
}): Promise<{
|
|
333
|
+
entries: {
|
|
334
|
+
name: string;
|
|
335
|
+
isDir: boolean;
|
|
336
|
+
}[];
|
|
337
|
+
truncated: boolean;
|
|
338
|
+
} | null>;
|
|
339
|
+
/**
|
|
340
|
+
* Looks for project-like directories, read in the mode `limits` gives (as for
|
|
341
|
+
* {@link SandboxProvider.list}). Every provider traverses the same way:
|
|
342
|
+
*
|
|
343
|
+
* - Candidates are `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH}
|
|
344
|
+
* levels below it that hold a `.git` entry (directory or file) or an `AGENTS.md` file.
|
|
345
|
+
* - The walk does not follow symbolic links and does not enter hidden directories (names
|
|
346
|
+
* starting with `.`); a candidate does not stop the descent (a monorepo's sub-projects are
|
|
347
|
+
* candidates too). It never enters a directory named in {@link DEVICE_SCAN_SKIPPED_DIRS}, at
|
|
348
|
+
* any depth, nor one named in {@link DEVICE_SCAN_SKIPPED_BASE_DIRS} directly under `base`;
|
|
349
|
+
* every provider skips exactly these. Paths under `base` the mode cannot reach are skipped,
|
|
350
|
+
* never an error.
|
|
351
|
+
* - A directory whose basename does not satisfy {@link isDeviceProjectName} is not returned as
|
|
352
|
+
* a candidate (never with a changed name), but it is still traversed.
|
|
353
|
+
* - Directories are visited breadth-first, each level in code-unit order of `path`, `base`
|
|
354
|
+
* counting as the first visit (visiting a directory reads its entries; one that cannot be read
|
|
355
|
+
* still counts as a visit); the walk stops after {@link MAX_DEVICE_SCAN_DIRS} visits, so a
|
|
356
|
+
* huge tree answers what was found by then.
|
|
357
|
+
* - Each candidate is its absolute `path` and its basename as `suggestedName`; the candidates
|
|
358
|
+
* found are sorted by `path` in code-unit order and cut to the first
|
|
359
|
+
* {@link MAX_DEVICE_SCAN_RESULTS}.
|
|
360
|
+
*
|
|
361
|
+
* Directory entries only, never file contents. A `base` that does not exist answers `[]`; a
|
|
362
|
+
* `base` that is a file, cannot be read, or lies outside the mode throws. Optional, like `list`.
|
|
363
|
+
*/
|
|
364
|
+
scan?(h: SandboxHandle, base: string, opts: {
|
|
365
|
+
limits: Pick<SandboxLimits, "mode">;
|
|
366
|
+
signal: AbortSignal;
|
|
367
|
+
}): Promise<{
|
|
368
|
+
path: string;
|
|
369
|
+
suggestedName: string;
|
|
370
|
+
}[]>;
|
|
228
371
|
}
|
|
229
|
-
/**
|
|
230
|
-
export declare
|
|
231
|
-
/**
|
|
372
|
+
/** The longest project name, in UTF-16 code units. */
|
|
373
|
+
export declare const MAX_DEVICE_PROJECT_NAME_LENGTH = 64;
|
|
374
|
+
/** The most candidates a `scan` answers ({@link SandboxProvider.scan}). */
|
|
375
|
+
export declare const MAX_DEVICE_SCAN_RESULTS = 50;
|
|
376
|
+
/**
|
|
377
|
+
* Directory names a `scan` never enters, at any depth ({@link SandboxProvider.scan}): dependency
|
|
378
|
+
* trees, not projects. Every provider skips exactly these.
|
|
379
|
+
*/
|
|
380
|
+
export declare const DEVICE_SCAN_SKIPPED_DIRS: readonly string[];
|
|
381
|
+
/**
|
|
382
|
+
* Directory names a `scan` does not enter directly under its `base` ({@link SandboxProvider.scan}):
|
|
383
|
+
* the owner's macOS `Library` (app data, huge, partly privacy-protected) is not where projects
|
|
384
|
+
* live. Every provider skips exactly these.
|
|
385
|
+
*/
|
|
386
|
+
export declare const DEVICE_SCAN_SKIPPED_BASE_DIRS: readonly string[];
|
|
387
|
+
/** How far below its base a `scan` looks: the base's children and their children. */
|
|
388
|
+
export declare const MAX_DEVICE_SCAN_DEPTH = 2;
|
|
389
|
+
/**
|
|
390
|
+
* The most directories one `scan` visits (reads the entries of), its `base` included
|
|
391
|
+
* ({@link SandboxProvider.scan}): breadth-first, each level in code-unit order of path.
|
|
392
|
+
*/
|
|
393
|
+
export declare const MAX_DEVICE_SCAN_DIRS = 500;
|
|
394
|
+
/**
|
|
395
|
+
* Whether `v` is a valid project name (a project's identity on its device, and a `scan`
|
|
396
|
+
* candidate's `suggestedName`): non-empty, at most {@link MAX_DEVICE_PROJECT_NAME_LENGTH} UTF-16
|
|
397
|
+
* code units, not `.` or `..`, no `/`, no control characters, and no leading or trailing
|
|
398
|
+
* whitespace.
|
|
399
|
+
*/
|
|
400
|
+
export declare function isDeviceProjectName(v: unknown): v is string;
|
|
401
|
+
/**
|
|
402
|
+
* The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
|
|
403
|
+
* control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
|
|
404
|
+
* empty when valid. {@link validateSandboxPath} adds root membership.
|
|
405
|
+
*/
|
|
406
|
+
export declare function validateSandboxPathShape(p: string): string[];
|
|
407
|
+
/**
|
|
408
|
+
* Checks a path inside an instance; returns the errors, empty when valid: the
|
|
409
|
+
* {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
|
|
410
|
+
* ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
|
|
411
|
+
*/
|
|
412
|
+
export declare function validateSandboxPath(p: string, roots?: SandboxRoots): string[];
|
|
413
|
+
/**
|
|
414
|
+
* Validates an outbound allowlist host name: lowercase, no protocol or port, optional leading `*.`,
|
|
415
|
+
* IDN accepted only as punycode.
|
|
416
|
+
*/
|
|
232
417
|
export declare function validateAllowHost(h: string): string[];
|
package/dist/sandbox.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
|
|
5
5
|
* `writeFile`.
|
|
6
6
|
*
|
|
7
|
-
* `@2` separates
|
|
8
|
-
* (`createFileSystem`) lives until the
|
|
7
|
+
* `@2` separates a device's **file system** from its **instance**: the file system
|
|
8
|
+
* (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
|
|
9
9
|
* (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
|
|
10
10
|
*/
|
|
11
11
|
/** Sandbox extension point ref. */
|
|
@@ -13,6 +13,16 @@ export const SANDBOX_EXTENSION_POINT = "sandbox@2";
|
|
|
13
13
|
/** The roots inside the sandbox the model may access. */
|
|
14
14
|
export const SANDBOX_ROOTS = ["/workspace", "/skills", "/tmp"];
|
|
15
15
|
const MAX_PATH_LENGTH = 4096;
|
|
16
|
+
/** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
|
|
17
|
+
export const DEFAULT_SANDBOX_ROOTS = Object.freeze({
|
|
18
|
+
workspace: "/workspace",
|
|
19
|
+
skills: "/skills",
|
|
20
|
+
tmp: "/tmp",
|
|
21
|
+
});
|
|
22
|
+
/** The roots of an instance, falling back to {@link DEFAULT_SANDBOX_ROOTS}. */
|
|
23
|
+
export function rootsOf(h) {
|
|
24
|
+
return h.roots ?? DEFAULT_SANDBOX_ROOTS;
|
|
25
|
+
}
|
|
16
26
|
/**
|
|
17
27
|
* The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
|
|
18
28
|
* `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
|
|
@@ -35,7 +45,7 @@ export function isSandboxGoneError(e) {
|
|
|
35
45
|
/**
|
|
36
46
|
* The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
|
|
37
47
|
* `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
|
|
38
|
-
* reports the
|
|
48
|
+
* reports the device's files as lost rather than handing out a silently empty workspace.
|
|
39
49
|
*/
|
|
40
50
|
export class FileSystemGoneError extends Error {
|
|
41
51
|
fileSystemGone = true;
|
|
@@ -56,10 +66,52 @@ export function isFileSystemGoneError(e) {
|
|
|
56
66
|
* kill pattern.
|
|
57
67
|
*/
|
|
58
68
|
export const SANDBOX_TAG_RE = /^[a-z0-9-]{1,64}$/;
|
|
59
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex:
|
|
69
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are exactly what must be blocked
|
|
60
70
|
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
61
|
-
/**
|
|
62
|
-
export
|
|
71
|
+
/** The longest project name, in UTF-16 code units. */
|
|
72
|
+
export const MAX_DEVICE_PROJECT_NAME_LENGTH = 64;
|
|
73
|
+
/** The most candidates a `scan` answers ({@link SandboxProvider.scan}). */
|
|
74
|
+
export const MAX_DEVICE_SCAN_RESULTS = 50;
|
|
75
|
+
/**
|
|
76
|
+
* Directory names a `scan` never enters, at any depth ({@link SandboxProvider.scan}): dependency
|
|
77
|
+
* trees, not projects. Every provider skips exactly these.
|
|
78
|
+
*/
|
|
79
|
+
export const DEVICE_SCAN_SKIPPED_DIRS = Object.freeze(["node_modules"]);
|
|
80
|
+
/**
|
|
81
|
+
* Directory names a `scan` does not enter directly under its `base` ({@link SandboxProvider.scan}):
|
|
82
|
+
* the owner's macOS `Library` (app data, huge, partly privacy-protected) is not where projects
|
|
83
|
+
* live. Every provider skips exactly these.
|
|
84
|
+
*/
|
|
85
|
+
export const DEVICE_SCAN_SKIPPED_BASE_DIRS = Object.freeze(["Library"]);
|
|
86
|
+
/** How far below its base a `scan` looks: the base's children and their children. */
|
|
87
|
+
export const MAX_DEVICE_SCAN_DEPTH = 2;
|
|
88
|
+
/**
|
|
89
|
+
* The most directories one `scan` visits (reads the entries of), its `base` included
|
|
90
|
+
* ({@link SandboxProvider.scan}): breadth-first, each level in code-unit order of path.
|
|
91
|
+
*/
|
|
92
|
+
export const MAX_DEVICE_SCAN_DIRS = 500;
|
|
93
|
+
/**
|
|
94
|
+
* Whether `v` is a valid project name (a project's identity on its device, and a `scan`
|
|
95
|
+
* candidate's `suggestedName`): non-empty, at most {@link MAX_DEVICE_PROJECT_NAME_LENGTH} UTF-16
|
|
96
|
+
* code units, not `.` or `..`, no `/`, no control characters, and no leading or trailing
|
|
97
|
+
* whitespace.
|
|
98
|
+
*/
|
|
99
|
+
export function isDeviceProjectName(v) {
|
|
100
|
+
return (typeof v === "string" &&
|
|
101
|
+
v !== "" &&
|
|
102
|
+
v !== "." &&
|
|
103
|
+
v !== ".." &&
|
|
104
|
+
v.length <= MAX_DEVICE_PROJECT_NAME_LENGTH &&
|
|
105
|
+
!CONTROL.test(v) &&
|
|
106
|
+
!v.includes("/") &&
|
|
107
|
+
!/^\s|\s$/.test(v));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
|
|
111
|
+
* control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
|
|
112
|
+
* empty when valid. {@link validateSandboxPath} adds root membership.
|
|
113
|
+
*/
|
|
114
|
+
export function validateSandboxPathShape(p) {
|
|
63
115
|
if (typeof p !== "string" || p.length === 0)
|
|
64
116
|
return ["path must be a non-empty string"];
|
|
65
117
|
if (p.length > MAX_PATH_LENGTH)
|
|
@@ -72,27 +124,49 @@ export function validateSandboxPath(p) {
|
|
|
72
124
|
return ["path must be absolute"];
|
|
73
125
|
if (p.includes("//"))
|
|
74
126
|
return ["path must not contain empty segments"];
|
|
75
|
-
const errors = [];
|
|
76
127
|
for (const seg of p.split("/")) {
|
|
77
128
|
let decoded = seg;
|
|
78
129
|
try {
|
|
79
130
|
decoded = decodeURIComponent(seg);
|
|
80
131
|
}
|
|
81
132
|
catch {
|
|
82
|
-
//
|
|
133
|
+
// invalid percent-encoding is taken literally
|
|
83
134
|
}
|
|
84
135
|
if (seg === ".." || decoded === ".." || decoded.includes("/") || decoded.includes("\\")) {
|
|
85
|
-
|
|
86
|
-
break;
|
|
136
|
+
return ["path must not contain '..' segments"];
|
|
87
137
|
}
|
|
88
138
|
}
|
|
89
|
-
|
|
90
|
-
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
/** A structural error after which {@link validateSandboxPath} stops (before the root check). */
|
|
142
|
+
const STOPS = new Set([
|
|
143
|
+
"path must be a non-empty string",
|
|
144
|
+
`path must be at most ${MAX_PATH_LENGTH} characters`,
|
|
145
|
+
"path must not contain control characters",
|
|
146
|
+
"path must not contain backslashes",
|
|
147
|
+
"path must be absolute",
|
|
148
|
+
"path must not contain empty segments",
|
|
149
|
+
]);
|
|
150
|
+
/**
|
|
151
|
+
* Checks a path inside an instance; returns the errors, empty when valid: the
|
|
152
|
+
* {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
|
|
153
|
+
* ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
|
|
154
|
+
*/
|
|
155
|
+
export function validateSandboxPath(p, roots) {
|
|
156
|
+
const errors = validateSandboxPathShape(p);
|
|
157
|
+
if (errors.some((e) => STOPS.has(e)))
|
|
158
|
+
return errors;
|
|
159
|
+
const allowed = roots === undefined ? SANDBOX_ROOTS : [roots.workspace, roots.skills, roots.tmp];
|
|
160
|
+
if (!allowed.some((r) => p === r || p.startsWith(`${r}/`))) {
|
|
161
|
+
errors.push(`path must be under ${allowed.join(", ")}`);
|
|
91
162
|
}
|
|
92
163
|
return errors;
|
|
93
164
|
}
|
|
94
165
|
const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
95
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* Validates an outbound allowlist host name: lowercase, no protocol or port, optional leading `*.`,
|
|
168
|
+
* IDN accepted only as punycode.
|
|
169
|
+
*/
|
|
96
170
|
export function validateAllowHost(h) {
|
|
97
171
|
if (typeof h !== "string" || h.length === 0)
|
|
98
172
|
return ["host must be a non-empty string"];
|
|
@@ -106,7 +180,8 @@ export function validateAllowHost(h) {
|
|
|
106
180
|
const tld = labels[labels.length - 1];
|
|
107
181
|
if (labels.length < 2)
|
|
108
182
|
return ["host must have at least two labels (no single-label names)"];
|
|
109
|
-
//
|
|
183
|
+
// The last label must start with a letter: this blocks the decimal / octal / hexadecimal
|
|
184
|
+
// spellings of IPv4
|
|
110
185
|
if (!/^[a-z]/.test(tld))
|
|
111
186
|
return ["host must not be an IP address literal"];
|
|
112
187
|
if (["local", "internal", "localhost"].includes(tld)) {
|
package/dist/secret.d.ts
CHANGED
|
@@ -4,5 +4,8 @@ import type { z } from "zod";
|
|
|
4
4
|
* (`ui` hints, `hot`), so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
|
|
5
5
|
*/
|
|
6
6
|
export declare function secret<T extends z.ZodTypeAny>(schema: T): T;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Reads the schema's meta to tell whether it is sensitive; the kernel's `meta({secret:true})` is
|
|
9
|
+
* recognized the same way.
|
|
10
|
+
*/
|
|
8
11
|
export declare function isSecret(schema: z.ZodTypeAny): boolean;
|
package/dist/secret.js
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
export function secret(schema) {
|
|
6
6
|
return schema.meta({ ...(schema.meta() ?? {}), secret: true });
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Reads the schema's meta to tell whether it is sensitive; the kernel's `meta({secret:true})` is
|
|
10
|
+
* recognized the same way.
|
|
11
|
+
*/
|
|
9
12
|
export function isSecret(schema) {
|
|
10
13
|
return schema.meta()?.secret === true;
|
|
11
14
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Setup checks (spec `2026-11-09-setup-guides-v2-design.md` §10): a check answers one question
|
|
3
|
+
* about one target ("does this bot token work?") for a `::check` line of a setup guide. An
|
|
4
|
+
* extension registers its checks in `setup` with `ctx.setup.check(id, def)`; each id must be
|
|
5
|
+
* listed in `permissions.setupChecks`. The kernel runs a check only when a person or an agent asks
|
|
6
|
+
* (never in the background), caches, single-flights and rate-limits it, and redacts the result.
|
|
7
|
+
*
|
|
8
|
+
* Contract rules (backed by review and kernel redaction, not by isolation: extensions are fully
|
|
9
|
+
* trusted):
|
|
10
|
+
* - A check never writes, at the third party or in Capybara, and stays cheap (one or two reads).
|
|
11
|
+
* - Pass `signal` to every request; the kernel aborts it at {@link SETUP_CHECK_LIMITS}.timeoutMs.
|
|
12
|
+
* - No retries inside the check: the person retries, retry policy is the kernel's.
|
|
13
|
+
* - Never put a secret in `reason` or `fix`. The kernel replaces known secret values with
|
|
14
|
+
* `[REDACTED]` before caching or returning, but it can only redact what it knows.
|
|
15
|
+
*
|
|
16
|
+
* What a check receives is what the extension already receives for the same target, nothing more:
|
|
17
|
+
* a channel connection's config (as `channel@1` `verify` and `connect` get it), or a connector's
|
|
18
|
+
* ids and OAuth client id. A check never gets the OAuth client secret or a member's token; those
|
|
19
|
+
* stay with the kernel and the connector extension's `auth()` (decided 2026-11-09).
|
|
20
|
+
*/
|
|
21
|
+
import type { SetupGuidePlace } from "./setup-guide.js";
|
|
22
|
+
/**
|
|
23
|
+
* `ok`: verified now. `failing`: verified wrong (needs a reason; should have a fix). `unknown`:
|
|
24
|
+
* could not tell (third party down, rate limited, the check does not apply yet); never a failure
|
|
25
|
+
* the person must act on.
|
|
26
|
+
*/
|
|
27
|
+
export type SetupCheckStatus = "ok" | "failing" | "unknown";
|
|
28
|
+
/** Plain text in English (required) and optionally Chinese; rendered as text, never Markdown. */
|
|
29
|
+
export interface SetupCheckText {
|
|
30
|
+
readonly en: string;
|
|
31
|
+
readonly zh?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The answer of a check. There is deliberately no structured details field: a result has nowhere
|
|
35
|
+
* for a token to hide. {@link validateSetupCheckResult} refuses any other key.
|
|
36
|
+
*/
|
|
37
|
+
export interface SetupCheckResult {
|
|
38
|
+
readonly status: SetupCheckStatus;
|
|
39
|
+
/** Why, in a sentence. At most `reasonChars` per language. Required when `failing`. */
|
|
40
|
+
readonly reason?: SetupCheckText;
|
|
41
|
+
/** What to do when failing. At most `fixChars` per language. */
|
|
42
|
+
readonly fix?: SetupCheckText;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What a check is about. The kernel builds it field by field; it only ever names targets of the
|
|
46
|
+
* check's own plugin (a channel connection on the plugin, a connector made from one of its
|
|
47
|
+
* templates).
|
|
48
|
+
*/
|
|
49
|
+
export type SetupCheckTarget = {
|
|
50
|
+
readonly kind: "channel-connection";
|
|
51
|
+
readonly connectionId: string;
|
|
52
|
+
/** The connection config as `channel@1` `verify` and `connect` receive it, secrets included. */
|
|
53
|
+
readonly config: unknown;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: "connector";
|
|
56
|
+
readonly connectorId: string;
|
|
57
|
+
readonly templateId: string;
|
|
58
|
+
/** The OAuth client id when the template uses a manual client; never the client secret. */
|
|
59
|
+
readonly clientId: string | null;
|
|
60
|
+
/** The viewing member's account, for member-audience checks; never their token. */
|
|
61
|
+
readonly accountId: string | null;
|
|
62
|
+
};
|
|
63
|
+
/** What `run` receives. */
|
|
64
|
+
export interface SetupCheckArgs {
|
|
65
|
+
readonly orgId: string;
|
|
66
|
+
/** The extension's effective config for the org (platform config plus the org's copy). */
|
|
67
|
+
readonly config: unknown;
|
|
68
|
+
readonly locale: "en" | "zh";
|
|
69
|
+
/** The guide's mode (`long_connection`, `webhook`), or null when the place has none. */
|
|
70
|
+
readonly mode: string | null;
|
|
71
|
+
readonly target: SetupCheckTarget;
|
|
72
|
+
/** Aborted at the kernel's timeout or when the extension is disposed. Pass it to every request. */
|
|
73
|
+
readonly signal: AbortSignal;
|
|
74
|
+
}
|
|
75
|
+
/** A check registered with `ctx.setup.check`. */
|
|
76
|
+
export interface SetupCheckDefinition {
|
|
77
|
+
/** The place whose guides may use the check; the kernel runs it only for targets of that place. */
|
|
78
|
+
place: SetupGuidePlace;
|
|
79
|
+
/** Never writes, passes `signal` on, does not retry, never puts a secret in the result. */
|
|
80
|
+
run(args: SetupCheckArgs): Promise<SetupCheckResult>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A check id an extension declares and registers. Ids with `:` belong to the kernel
|
|
84
|
+
* (`capybara:*`), so an extension cannot shadow a kernel check.
|
|
85
|
+
*/
|
|
86
|
+
export declare const SETUP_CHECK_ID_RE: RegExp;
|
|
87
|
+
/** Limits of setup checks (spec §10.5). Characters are UTF-16 code units. */
|
|
88
|
+
export declare const SETUP_CHECK_LIMITS: Readonly<{
|
|
89
|
+
/** Per run; the kernel aborts `signal` and records `unknown`. */
|
|
90
|
+
readonly timeoutMs: 10000;
|
|
91
|
+
/** Characters of `reason`, per language. */
|
|
92
|
+
readonly reasonChars: 300;
|
|
93
|
+
/** Characters of `fix`, per language. */
|
|
94
|
+
readonly fixChars: 500;
|
|
95
|
+
/** A cached result stays fresh this long (and for the same input fingerprint). */
|
|
96
|
+
readonly freshMs: 300000;
|
|
97
|
+
/** A forced rerun of one check and target at most this often. */
|
|
98
|
+
readonly cooldownMs: 10000;
|
|
99
|
+
/** Concurrent runs per org across all replicas. */
|
|
100
|
+
readonly orgConcurrency: 8;
|
|
101
|
+
/** Run requests per account per minute. */
|
|
102
|
+
readonly perAccountPerMinute: 30;
|
|
103
|
+
/** Ids in `permissions.setupChecks`. */
|
|
104
|
+
readonly idsPerExtension: 32;
|
|
105
|
+
}>;
|
|
106
|
+
type Problem = {
|
|
107
|
+
problem: string;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* The result as a fresh plain object holding only `status`, `reason` and `fix`, or why it is
|
|
111
|
+
* invalid (English). The kernel treats an invalid result as `unknown` and logs the problem. Run
|
|
112
|
+
* kernel redaction on the returned copy, then validate again (redaction can change the length).
|
|
113
|
+
*/
|
|
114
|
+
export declare function validateSetupCheckResult(x: unknown): SetupCheckResult | Problem;
|
|
115
|
+
export {};
|