@capybara-hq/plugin-sdk 0.1.0-rc.3 → 0.1.0-rc.30
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.d.ts +319 -0
- package/dist/device-protocol.js +559 -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 +21 -1
- package/dist/index.js +21 -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 +15 -0
- package/dist/sandbox-linux-runtime-source.js +1421 -0
- package/dist/sandbox-native-runtime-source.d.ts +8 -0
- package/dist/sandbox-native-runtime-source.js +307 -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.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
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { SANDBOX_TAG_RE, validateAllowHost, validateSandboxPathShape, } from "./sandbox.js";
|
|
2
|
+
/** Accepts only the supported permission profile names. */
|
|
3
|
+
export function isPermissionProfile(value) {
|
|
4
|
+
return value === "request-approval" || value === "approve-for-me" || value === "full-access";
|
|
5
|
+
}
|
|
6
|
+
/** The provider cannot enforce the requested permission profile. */
|
|
7
|
+
export class SandboxPermissionUnsupportedError extends Error {
|
|
8
|
+
sandboxPermissionUnsupported = true;
|
|
9
|
+
constructor(message, opts) {
|
|
10
|
+
super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
11
|
+
this.name = "SandboxPermissionUnsupportedError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Recognizes the name and tag across SDK copies without requiring this class's identity. */
|
|
15
|
+
export function isSandboxPermissionUnsupportedError(e) {
|
|
16
|
+
return (e instanceof Error &&
|
|
17
|
+
e.name === "SandboxPermissionUnsupportedError" &&
|
|
18
|
+
e.sandboxPermissionUnsupported === true);
|
|
19
|
+
}
|
|
20
|
+
/** The requested operation is outside the permitted scope. */
|
|
21
|
+
export class SandboxScopeDeniedError extends Error {
|
|
22
|
+
sandboxScopeDenied = true;
|
|
23
|
+
constructor(message, opts) {
|
|
24
|
+
super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
25
|
+
this.name = "SandboxScopeDeniedError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Recognizes the name and tag across SDK copies without requiring this class's identity. */
|
|
29
|
+
export function isSandboxScopeDeniedError(e) {
|
|
30
|
+
return (e instanceof Error &&
|
|
31
|
+
e.name === "SandboxScopeDeniedError" &&
|
|
32
|
+
e.sandboxScopeDenied === true);
|
|
33
|
+
}
|
|
34
|
+
/** A scope or execution reference is malformed; validate it before performing any effects. */
|
|
35
|
+
export class SandboxScopeValidationError extends Error {
|
|
36
|
+
sandboxScopeValidation = true;
|
|
37
|
+
constructor(message, opts) {
|
|
38
|
+
super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
39
|
+
this.name = "SandboxScopeValidationError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Recognizes validation errors across SDK copies. */
|
|
43
|
+
export function isSandboxScopeValidationError(e) {
|
|
44
|
+
return (e instanceof Error &&
|
|
45
|
+
e.name === "SandboxScopeValidationError" &&
|
|
46
|
+
e.sandboxScopeValidation === true);
|
|
47
|
+
}
|
|
48
|
+
/** An operation was consumed but its outcome is unknown. Never automatically retry with a new ID. */
|
|
49
|
+
export class SandboxOperationOutcomeUnknownError extends Error {
|
|
50
|
+
sandboxOperationOutcomeUnknown = true;
|
|
51
|
+
constructor(message, opts) {
|
|
52
|
+
super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
|
|
53
|
+
this.name = "SandboxOperationOutcomeUnknownError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Recognizes unknown outcomes across SDK copies; an unknown outcome is not a gone instance. */
|
|
57
|
+
export function isSandboxOperationOutcomeUnknownError(e) {
|
|
58
|
+
return (e instanceof Error &&
|
|
59
|
+
e.name === "SandboxOperationOutcomeUnknownError" &&
|
|
60
|
+
e.sandboxOperationOutcomeUnknown === true);
|
|
61
|
+
}
|
|
62
|
+
function invalid(field, requirement) {
|
|
63
|
+
throw new SandboxScopeValidationError(`Invalid ${field}: ${requirement}. Supply a valid scope or reference before retrying.`);
|
|
64
|
+
}
|
|
65
|
+
function record(value, keys, field) {
|
|
66
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
67
|
+
return invalid(field, "expected an object");
|
|
68
|
+
}
|
|
69
|
+
const prototype = Object.getPrototypeOf(value);
|
|
70
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
71
|
+
return invalid(field, "expected a plain object");
|
|
72
|
+
const result = Object.create(null);
|
|
73
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
74
|
+
if (typeof key !== "string" || !keys.includes(key))
|
|
75
|
+
return invalid(field, "unknown fields are not allowed");
|
|
76
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
77
|
+
if (!descriptor || !("value" in descriptor))
|
|
78
|
+
return invalid(field, "accessor fields are not allowed");
|
|
79
|
+
result[key] = descriptor.value;
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
function id(value, field) {
|
|
84
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 128) {
|
|
85
|
+
return invalid(field, "expected a nonempty string of at most 128 characters");
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
function integer(value, minimum, field) {
|
|
90
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < minimum) {
|
|
91
|
+
return invalid(field, `expected a safe integer greater than or equal to ${minimum}`);
|
|
92
|
+
}
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
function tag(value) {
|
|
96
|
+
if (typeof value !== "string" || !SANDBOX_TAG_RE.test(value))
|
|
97
|
+
return invalid("tag", "expected 1–64 lowercase letters, digits or hyphens");
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
function strings(value, maximum, check, field) {
|
|
101
|
+
if (!Array.isArray(value) || value.length > maximum)
|
|
102
|
+
return invalid(field, `expected an array of at most ${maximum} entries`);
|
|
103
|
+
if (Reflect.ownKeys(value).length !== value.length + 1)
|
|
104
|
+
return invalid(field, "sparse arrays and extra fields are not allowed");
|
|
105
|
+
const result = [];
|
|
106
|
+
for (let i = 0; i < value.length; i++) {
|
|
107
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, i);
|
|
108
|
+
if (!descriptor || !("value" in descriptor))
|
|
109
|
+
return invalid(field, "expected array data entries");
|
|
110
|
+
const item = descriptor.value;
|
|
111
|
+
if (typeof item !== "string")
|
|
112
|
+
return invalid(field, "expected string entries");
|
|
113
|
+
const errors = check(item);
|
|
114
|
+
if (errors.length > 0)
|
|
115
|
+
return invalid(field, errors.join("; "));
|
|
116
|
+
result.push(item);
|
|
117
|
+
}
|
|
118
|
+
return Object.freeze(result);
|
|
119
|
+
}
|
|
120
|
+
function roots(value, field) {
|
|
121
|
+
return strings(value, 64, validateSandboxPathShape, field);
|
|
122
|
+
}
|
|
123
|
+
function fileScope(value) {
|
|
124
|
+
const v = record(value, ["kind", "readRoots", "writeRoots"], "filesystem");
|
|
125
|
+
if (v.kind === "device") {
|
|
126
|
+
record(value, ["kind"], "filesystem");
|
|
127
|
+
return Object.freeze({ kind: "device" });
|
|
128
|
+
}
|
|
129
|
+
if (v.kind !== "scoped")
|
|
130
|
+
return invalid("filesystem.kind", "expected scoped or device");
|
|
131
|
+
return Object.freeze({
|
|
132
|
+
kind: "scoped",
|
|
133
|
+
readRoots: roots(v.readRoots, "filesystem.readRoots"),
|
|
134
|
+
writeRoots: roots(v.writeRoots, "filesystem.writeRoots"),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function networkScope(value) {
|
|
138
|
+
const v = record(value, ["kind", "hosts"], "network");
|
|
139
|
+
if (v.kind === "none" || v.kind === "environment") {
|
|
140
|
+
record(value, ["kind"], "network");
|
|
141
|
+
return Object.freeze({ kind: v.kind });
|
|
142
|
+
}
|
|
143
|
+
if (v.kind !== "allowlist")
|
|
144
|
+
return invalid("network.kind", "expected none, allowlist or environment");
|
|
145
|
+
return Object.freeze({
|
|
146
|
+
kind: "allowlist",
|
|
147
|
+
hosts: strings(v.hosts, 100, validateAllowHost, "network.hosts"),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function actor(value) {
|
|
151
|
+
const v = record(value, ["accountId", "conversationId", "runId"], "actor");
|
|
152
|
+
return Object.freeze({
|
|
153
|
+
accountId: id(v.accountId, "actor.accountId"),
|
|
154
|
+
conversationId: id(v.conversationId, "actor.conversationId"),
|
|
155
|
+
...(Object.hasOwn(v, "runId") ? { runId: id(v.runId, "actor.runId") } : {}),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function operationRef(v) {
|
|
159
|
+
return {
|
|
160
|
+
operationId: id(v.operationId, "operationId"),
|
|
161
|
+
admitBeforeMs: integer(v.admitBeforeMs, 1, "admitBeforeMs"),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/** Pure structural validation and a frozen copy; no clock lookup or authority resolution. */
|
|
165
|
+
export function parseSandboxOperationRef(value) {
|
|
166
|
+
return Object.freeze(operationRef(record(value, ["operationId", "admitBeforeMs"], "operation reference")));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Validates a scope and returns a deeply frozen copy, throwing SandboxScopeValidationError.
|
|
170
|
+
* IDs and ceiling revisions are bounded to 128 characters; roots to 64 paths of at most 4096 characters;
|
|
171
|
+
* hosts to 100 entries passing validateAllowHost. Empty grants stay empty, including deny-all.
|
|
172
|
+
* Performs no I/O, authority lookup or deadline refresh. Unknown fields are rejected at every level.
|
|
173
|
+
*/
|
|
174
|
+
export function parseSandboxOperationScope(value) {
|
|
175
|
+
const v = record(value, [
|
|
176
|
+
"operationId",
|
|
177
|
+
"admitBeforeMs",
|
|
178
|
+
"deviceId",
|
|
179
|
+
"rootConversationId",
|
|
180
|
+
"profileRevision",
|
|
181
|
+
"ceilingRevision",
|
|
182
|
+
"profile",
|
|
183
|
+
"actor",
|
|
184
|
+
"tag",
|
|
185
|
+
"filesystem",
|
|
186
|
+
"network",
|
|
187
|
+
], "operation scope");
|
|
188
|
+
if (!isPermissionProfile(v.profile))
|
|
189
|
+
return invalid("profile", "expected request-approval, approve-for-me or full-access");
|
|
190
|
+
return Object.freeze({
|
|
191
|
+
...operationRef(v),
|
|
192
|
+
deviceId: id(v.deviceId, "deviceId"),
|
|
193
|
+
rootConversationId: id(v.rootConversationId, "rootConversationId"),
|
|
194
|
+
profileRevision: integer(v.profileRevision, 0, "profileRevision"),
|
|
195
|
+
ceilingRevision: id(v.ceilingRevision, "ceilingRevision"),
|
|
196
|
+
profile: v.profile,
|
|
197
|
+
actor: actor(v.actor),
|
|
198
|
+
tag: tag(v.tag),
|
|
199
|
+
filesystem: fileScope(v.filesystem),
|
|
200
|
+
network: networkScope(v.network),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/** Validates an owner browsing grant and returns a deeply frozen copy; no conversation is required. */
|
|
204
|
+
export function parseSandboxBrowseScope(value) {
|
|
205
|
+
const v = record(value, [
|
|
206
|
+
"operationId",
|
|
207
|
+
"admitBeforeMs",
|
|
208
|
+
"deviceId",
|
|
209
|
+
"accountId",
|
|
210
|
+
"ceilingRevision",
|
|
211
|
+
"readRoots",
|
|
212
|
+
"tag",
|
|
213
|
+
], "browse scope");
|
|
214
|
+
return Object.freeze({
|
|
215
|
+
...operationRef(v),
|
|
216
|
+
deviceId: id(v.deviceId, "deviceId"),
|
|
217
|
+
accountId: id(v.accountId, "accountId"),
|
|
218
|
+
ceilingRevision: id(v.ceilingRevision, "ceilingRevision"),
|
|
219
|
+
readRoots: roots(v.readRoots, "readRoots"),
|
|
220
|
+
tag: tag(v.tag),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/** Validates trusted staging structure and returns a deeply frozen copy; does not authorize its roots. */
|
|
224
|
+
export function parseSandboxPreparationScope(value) {
|
|
225
|
+
const v = record(value, ["operationId", "deviceId", "purpose", "writeRoots", "tag"], "preparation scope");
|
|
226
|
+
if (v.purpose !== "skills" && v.purpose !== "attachments")
|
|
227
|
+
return invalid("purpose", "expected skills or attachments");
|
|
228
|
+
return Object.freeze({
|
|
229
|
+
operationId: id(v.operationId, "operationId"),
|
|
230
|
+
deviceId: id(v.deviceId, "deviceId"),
|
|
231
|
+
purpose: v.purpose,
|
|
232
|
+
writeRoots: roots(v.writeRoots, "writeRoots"),
|
|
233
|
+
tag: tag(v.tag),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/** Validates all four bounded locator fields and returns a frozen copy; does not authenticate the caller. */
|
|
237
|
+
export function parseSandboxExecutionRef(value) {
|
|
238
|
+
const v = record(value, ["executionId", "operationId", "instanceId", "instanceGeneration"], "execution reference");
|
|
239
|
+
return Object.freeze({
|
|
240
|
+
executionId: id(v.executionId, "executionId"),
|
|
241
|
+
operationId: id(v.operationId, "operationId"),
|
|
242
|
+
instanceId: id(v.instanceId, "instanceId"),
|
|
243
|
+
instanceGeneration: id(v.instanceGeneration, "instanceGeneration"),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Immutable runtime bytes for trusted consumer staging (requires Python 3). Consumers verify every
|
|
3
|
+
* hash before use, stage the files together in a directory the operation user cannot write, and
|
|
4
|
+
* supply pinned, already-authorized root descriptors.
|
|
5
|
+
*
|
|
6
|
+
* - `native-files.py`: the portable native helper (descriptor-relative file access).
|
|
7
|
+
* - `linux-sandbox.py`: the restricted Linux launcher and syscall broker (Landlock plus a seccomp
|
|
8
|
+
* notification broker). It decides nothing about authority; its `probe` reports whether the
|
|
9
|
+
* running kernel, architecture and container policy support restricted execution, and every
|
|
10
|
+
* unsupported case reports unavailable. Shipping these bytes is not a provider support claim.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SANDBOX_RUNTIME_SOURCE: {
|
|
13
|
+
readonly version: number;
|
|
14
|
+
readonly files: readonly {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly source: string;
|
|
17
|
+
readonly sha256: string;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LINUX_SANDBOX_SOURCE } from "./sandbox-linux-runtime-source.js";
|
|
2
|
+
import { NATIVE_FILES_SOURCE } from "./sandbox-native-runtime-source.js";
|
|
3
|
+
/**
|
|
4
|
+
* Immutable runtime bytes for trusted consumer staging (requires Python 3). Consumers verify every
|
|
5
|
+
* hash before use, stage the files together in a directory the operation user cannot write, and
|
|
6
|
+
* supply pinned, already-authorized root descriptors.
|
|
7
|
+
*
|
|
8
|
+
* - `native-files.py`: the portable native helper (descriptor-relative file access).
|
|
9
|
+
* - `linux-sandbox.py`: the restricted Linux launcher and syscall broker (Landlock plus a seccomp
|
|
10
|
+
* notification broker). It decides nothing about authority; its `probe` reports whether the
|
|
11
|
+
* running kernel, architecture and container policy support restricted execution, and every
|
|
12
|
+
* unsupported case reports unavailable. Shipping these bytes is not a provider support claim.
|
|
13
|
+
*/
|
|
14
|
+
export const SANDBOX_RUNTIME_SOURCE = Object.freeze({
|
|
15
|
+
version: 2,
|
|
16
|
+
files: Object.freeze([
|
|
17
|
+
Object.freeze({
|
|
18
|
+
name: "native-files.py",
|
|
19
|
+
source: NATIVE_FILES_SOURCE,
|
|
20
|
+
sha256: "601f51c1c46bedac5ab56f7ca38d7c15fdea8481efc6476d5a5b3243318ef79b",
|
|
21
|
+
}),
|
|
22
|
+
Object.freeze({
|
|
23
|
+
name: "linux-sandbox.py",
|
|
24
|
+
source: LINUX_SANDBOX_SOURCE,
|
|
25
|
+
sha256: "f27ab699dbb5f7fc0ea9eb02cfa2257a405e5ccf3b8c3e011df29ab54bc3d599",
|
|
26
|
+
}),
|
|
27
|
+
]),
|
|
28
|
+
});
|
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[];
|