@capybara-hq/plugin-sdk 0.1.0-rc.24 → 0.1.0-rc.26
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/extension-points/model-provider.md +2 -0
- package/agent-docs/extension-points/object-store.md +2 -0
- package/dist/device-protocol.d.ts +6 -4
- package/dist/device-protocol.js +5 -3
- package/dist/hooks.d.ts +6 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/model.d.ts +25 -6
- package/dist/model.js +24 -5
- 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 +13 -0
- package/dist/sandbox-runtime-source.js +16 -0
- package/dist/sandbox.d.ts +24 -0
- package/dist/storage.d.ts +7 -0
- package/package.json +1 -1
|
@@ -12,4 +12,6 @@ Contract: ModelProvider (`model.ts`); refs `model-provider@1` and `@2`
|
|
|
12
12
|
|
|
13
13
|
Map the kernel's messages and tools to the vendor API and stream the result. Do not retry inside the extension; return a `ModelError` with the right kind and let the kernel degrade. History sent to the model is append-only. Declare parameters and media support.
|
|
14
14
|
|
|
15
|
+
Messages may carry an `image` or a `document` block, gated by `capabilities.vision` and `capabilities.documents`; the kernel replaces a block the model cannot take with an English placeholder and never sends the bytes. A `file` block is an attachment the model can only reference (an xlsx, say): the kernel resolves it to text before the request, so a provider never receives one. Resolve any block you do not recognize by skipping it. The `size` on an attachment block is display metadata (the UI chip, the reference line) and is never sent to a provider.
|
|
16
|
+
|
|
15
17
|
See `extensions` for the rules every extension follows.
|
|
@@ -12,4 +12,6 @@ Contract: ObjectStore (`storage.ts`)
|
|
|
12
12
|
|
|
13
13
|
Return `null` for a missing key, reject keys containing `${`, and enforce the size of presigned uploads in the store itself. The kernel adds key prefixes; extensions consume it as `ctx.storage`.
|
|
14
14
|
|
|
15
|
+
Optionally implement `uri(key)`: the store's canonical identifier for a key, such as `s3://bucket/key`. It is unsigned, stable and carries no credentials, and is never a presigned URL — the kernel may record it in an event log and show it to a model. A store with no notion of URIs simply leaves it out.
|
|
16
|
+
|
|
15
17
|
See `extensions` for the rules every extension follows.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Device protocol
|
|
2
|
+
* Device protocol v2: the WebSocket frames between the kernel and a `capybara-device` program
|
|
3
3
|
* (a connected machine that serves as a device). Pure types and hand-written guards.
|
|
4
4
|
*/
|
|
5
5
|
import { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots } from "./sandbox.js";
|
|
6
6
|
/** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
|
|
7
|
-
export declare const DEVICE_PROTOCOL_VERSION =
|
|
7
|
+
export declare const DEVICE_PROTOCOL_VERSION = 2;
|
|
8
8
|
/** The operations the kernel asks a device to run. */
|
|
9
9
|
export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop" | "policy" | "policyStatus" | "list" | "scan";
|
|
10
10
|
/**
|
|
@@ -38,7 +38,7 @@ export interface DeviceProjectCandidate {
|
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* The kernel's current ceiling on a request that reads the device's file system outside a command
|
|
41
|
-
* (`list`, `scan`): the device answers in the mode it would run this request in, the owner's
|
|
41
|
+
* (`readFile`, `stat`, `list`, `scan`): the device answers in the mode it would run this request in, the owner's
|
|
42
42
|
* choice cut to `mode`, never by a ceiling it saw on an earlier command.
|
|
43
43
|
*/
|
|
44
44
|
export type DeviceRequestCeiling = Pick<SandboxLimits, "mode">;
|
|
@@ -161,6 +161,7 @@ export interface DeviceExecGrants {
|
|
|
161
161
|
export type DeviceExecResult = ExecResult;
|
|
162
162
|
export interface DeviceReadFileArgs {
|
|
163
163
|
path: string;
|
|
164
|
+
limits: DeviceRequestCeiling;
|
|
164
165
|
maxBytes: number;
|
|
165
166
|
}
|
|
166
167
|
export type DeviceReadFileResult = {
|
|
@@ -174,6 +175,7 @@ export interface DeviceWriteFileArgs {
|
|
|
174
175
|
export type DeviceWriteFileResult = null;
|
|
175
176
|
export interface DeviceStatArgs {
|
|
176
177
|
path: string;
|
|
178
|
+
limits: DeviceRequestCeiling;
|
|
177
179
|
}
|
|
178
180
|
export type DeviceStatResult = {
|
|
179
181
|
size: number;
|
|
@@ -281,7 +283,7 @@ export interface DeviceScanArgs {
|
|
|
281
283
|
* first {@link MAX_DEVICE_SCAN_RESULTS}. Never file contents. See `SandboxProvider.scan`.
|
|
282
284
|
*/
|
|
283
285
|
export type DeviceScanResult = DeviceProjectCandidate[];
|
|
284
|
-
/** A frame that is not valid protocol
|
|
286
|
+
/** A frame that is not valid device protocol (or came from the wrong side). */
|
|
285
287
|
export declare class DeviceProtocolError extends Error {
|
|
286
288
|
constructor(message: string);
|
|
287
289
|
}
|
package/dist/device-protocol.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Device protocol
|
|
2
|
+
* Device protocol v2: the WebSocket frames between the kernel and a `capybara-device` program
|
|
3
3
|
* (a connected machine that serves as a device). Pure types and hand-written guards.
|
|
4
4
|
*/
|
|
5
5
|
import { isDeviceProjectName, MAX_DEVICE_PROJECT_NAME_LENGTH, MAX_DEVICE_SCAN_DEPTH, MAX_DEVICE_SCAN_RESULTS, validateAllowHost, validateSandboxPathShape, } from "./sandbox.js";
|
|
6
6
|
/** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
|
|
7
|
-
export const DEVICE_PROTOCOL_VERSION =
|
|
7
|
+
export const DEVICE_PROTOCOL_VERSION = 2;
|
|
8
8
|
const DEVICE_OPS = [
|
|
9
9
|
"create",
|
|
10
10
|
"exec",
|
|
@@ -46,7 +46,7 @@ const MAX_POLICY_HOSTS = 100;
|
|
|
46
46
|
export const MAX_POLICY_OP_ID_LENGTH = 128;
|
|
47
47
|
/** The most entries a hello's `recentOps` carries; the parser keeps the newest. */
|
|
48
48
|
export const MAX_RECENT_POLICY_OPS = 100;
|
|
49
|
-
/** A frame that is not valid protocol
|
|
49
|
+
/** A frame that is not valid device protocol (or came from the wrong side). */
|
|
50
50
|
export class DeviceProtocolError extends Error {
|
|
51
51
|
constructor(message) {
|
|
52
52
|
super(message);
|
|
@@ -397,6 +397,7 @@ function validateArgs(op, a) {
|
|
|
397
397
|
}
|
|
398
398
|
case "readFile": {
|
|
399
399
|
str(a, "path");
|
|
400
|
+
parseCeiling(a.limits);
|
|
400
401
|
const m = a.maxBytes;
|
|
401
402
|
if (typeof m !== "number" || !Number.isInteger(m) || m < 0) {
|
|
402
403
|
throw new DeviceProtocolError('field "maxBytes" must be a non-negative integer');
|
|
@@ -409,6 +410,7 @@ function validateArgs(op, a) {
|
|
|
409
410
|
return;
|
|
410
411
|
case "stat":
|
|
411
412
|
str(a, "path");
|
|
413
|
+
parseCeiling(a.limits);
|
|
412
414
|
return;
|
|
413
415
|
case "killTagged":
|
|
414
416
|
strArray(a, "tags");
|
package/dist/hooks.d.ts
CHANGED
|
@@ -49,21 +49,23 @@ export type ModelCallPurpose = "step" | "compaction" | "title" | "web_fetch" | "
|
|
|
49
49
|
*/
|
|
50
50
|
export type UsagePurpose = ModelCallPurpose | "embedding";
|
|
51
51
|
/**
|
|
52
|
-
* An image or
|
|
53
|
-
* attachment ids: each image
|
|
52
|
+
* An image, document or file of a `model.request` payload. Hook payloads never carry media bytes or
|
|
53
|
+
* attachment ids: each image / document / file block is replaced by this placeholder.
|
|
54
54
|
* `size` is the size of the bytes sent to the provider, in bytes (0 when unknown).
|
|
55
55
|
*/
|
|
56
56
|
export interface HookMediaPlaceholder {
|
|
57
57
|
type: "media_omitted";
|
|
58
|
-
kind: "image" | "document";
|
|
58
|
+
kind: "image" | "document" | "file";
|
|
59
59
|
mediaType: string;
|
|
60
60
|
size: number;
|
|
61
61
|
}
|
|
62
|
-
/** A content block of a `model.request` payload: image and
|
|
62
|
+
/** A content block of a `model.request` payload: image, document and file blocks become placeholders. */
|
|
63
63
|
export type HookContentBlock = Exclude<ContentBlock, {
|
|
64
64
|
type: "image";
|
|
65
65
|
} | {
|
|
66
66
|
type: "document";
|
|
67
|
+
} | {
|
|
68
|
+
type: "file";
|
|
67
69
|
}> | HookMediaPlaceholder;
|
|
68
70
|
/** A message of a `model.request` payload (see {@link HookContentBlock}). */
|
|
69
71
|
export type HookModelMessage = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.1.0-rc.
|
|
1
|
+
export declare const SDK_VERSION = "0.1.0-rc.26";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -27,6 +27,8 @@ export * from "./permissions.js";
|
|
|
27
27
|
export * from "./plugin-manifest.js";
|
|
28
28
|
export * from "./plugin-package.js";
|
|
29
29
|
export * from "./sandbox.js";
|
|
30
|
+
export * from "./sandbox-operation.js";
|
|
31
|
+
export { SANDBOX_RUNTIME_SOURCE } from "./sandbox-runtime-source.js";
|
|
30
32
|
export * from "./secret.js";
|
|
31
33
|
export * from "./setup-check.js";
|
|
32
34
|
export * from "./setup-guide.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.1.0-rc.
|
|
1
|
+
export const SDK_VERSION = "0.1.0-rc.26";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -27,6 +27,8 @@ export * from "./permissions.js";
|
|
|
27
27
|
export * from "./plugin-manifest.js";
|
|
28
28
|
export * from "./plugin-package.js";
|
|
29
29
|
export * from "./sandbox.js";
|
|
30
|
+
export * from "./sandbox-operation.js";
|
|
31
|
+
export { SANDBOX_RUNTIME_SOURCE } from "./sandbox-runtime-source.js";
|
|
30
32
|
export * from "./secret.js";
|
|
31
33
|
export * from "./setup-check.js";
|
|
32
34
|
export * from "./setup-guide.js";
|
package/dist/model.d.ts
CHANGED
|
@@ -112,21 +112,37 @@ export type ContentBlock =
|
|
|
112
112
|
isError: boolean;
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
115
|
+
* An image (only in user messages). When the model has no `vision` the kernel sends an English
|
|
116
|
+
* placeholder instead; a plugin need not check. An older plugin that does not know this block
|
|
117
|
+
* skips it. `size` is display metadata (the UI chip, the reference line) and is never sent.
|
|
117
118
|
*/
|
|
118
119
|
| {
|
|
119
120
|
type: "image";
|
|
120
121
|
mediaType: ImageMediaType;
|
|
121
122
|
source: MediaSource;
|
|
122
123
|
name?: string;
|
|
124
|
+
size?: number;
|
|
123
125
|
}
|
|
124
|
-
/**
|
|
126
|
+
/** A document (only in user messages), gated by `capabilities.documents`; same rules as image. */
|
|
125
127
|
| {
|
|
126
128
|
type: "document";
|
|
127
129
|
mediaType: DocumentMediaType;
|
|
128
130
|
source: MediaSource;
|
|
129
131
|
name?: string;
|
|
132
|
+
size?: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* An attachment whose content the model cannot read (an xlsx, say): the kernel replaces it with
|
|
136
|
+
* text carrying an unsigned object reference before the request, so a provider **never** receives
|
|
137
|
+
* this block. `mediaType` is any non-empty `type/subtype`; `size` is display metadata (the UI
|
|
138
|
+
* chip, the reference line) and is never sent.
|
|
139
|
+
*/
|
|
140
|
+
| {
|
|
141
|
+
type: "file";
|
|
142
|
+
mediaType: string;
|
|
143
|
+
source: MediaSource;
|
|
144
|
+
name?: string;
|
|
145
|
+
size?: number;
|
|
130
146
|
};
|
|
131
147
|
/** 媒体块 `name` 的最大长度(字符)。 */
|
|
132
148
|
export declare const MEDIA_NAME_MAX_CHARS = 255;
|
|
@@ -142,9 +158,12 @@ export declare function hasControlChars(s: string): boolean;
|
|
|
142
158
|
/** 附件 id 是否为 UUID(任意版本,大小写不限)。 */
|
|
143
159
|
export declare function isAttachmentId(s: unknown): s is string;
|
|
144
160
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
161
|
+
* Validates an image / document / file block, returning a list of errors (empty means valid): the
|
|
162
|
+
* media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
|
|
163
|
+
* standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
|
|
164
|
+
* `attachmentId` is a UUID; `name`, when present, is a string of at most
|
|
165
|
+
* {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
|
|
166
|
+
* non-negative integer (display metadata, never sent by a plugin).
|
|
148
167
|
*/
|
|
149
168
|
export declare function validateMediaBlock(b: unknown): string[];
|
|
150
169
|
export type ModelMessage = {
|
package/dist/model.js
CHANGED
|
@@ -42,14 +42,22 @@ export function hasControlChars(s) {
|
|
|
42
42
|
export function isAttachmentId(s) {
|
|
43
43
|
return typeof s === "string" && UUID_RE.test(s);
|
|
44
44
|
}
|
|
45
|
+
/** Any non-empty `type/subtype` (a `file` block's `mediaType`). */
|
|
46
|
+
const MEDIA_TYPE_RE = /^[^/\s]+\/[^/\s]+$/;
|
|
45
47
|
const MEDIA = {
|
|
46
48
|
image: { types: IMAGE_MEDIA_TYPES, limit: MEDIA_LIMITS.imageBytes },
|
|
47
49
|
document: { types: DOCUMENT_MEDIA_TYPES, limit: MEDIA_LIMITS.documentBytes },
|
|
50
|
+
// A file the model cannot read: the kernel resolves it to text before the request, so no media
|
|
51
|
+
// type list applies. The byte ceiling is the one attachments already have.
|
|
52
|
+
file: { types: [], limit: MEDIA_LIMITS.documentBytes, anyType: true },
|
|
48
53
|
};
|
|
49
54
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
55
|
+
* Validates an image / document / file block, returning a list of errors (empty means valid): the
|
|
56
|
+
* media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
|
|
57
|
+
* standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
|
|
58
|
+
* `attachmentId` is a UUID; `name`, when present, is a string of at most
|
|
59
|
+
* {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
|
|
60
|
+
* non-negative integer (display metadata, never sent by a plugin).
|
|
53
61
|
*/
|
|
54
62
|
export function validateMediaBlock(b) {
|
|
55
63
|
if (typeof b !== "object" || b === null || Array.isArray(b))
|
|
@@ -57,9 +65,16 @@ export function validateMediaBlock(b) {
|
|
|
57
65
|
const o = b;
|
|
58
66
|
const spec = typeof o.type === "string" && Object.hasOwn(MEDIA, o.type) ? MEDIA[o.type] : undefined;
|
|
59
67
|
if (!spec)
|
|
60
|
-
return ['block type must be "image" or "
|
|
68
|
+
return ['block type must be "image", "document" or "file"'];
|
|
61
69
|
const errs = [];
|
|
62
|
-
if (
|
|
70
|
+
if (spec.anyType) {
|
|
71
|
+
if (typeof o.mediaType !== "string" ||
|
|
72
|
+
!MEDIA_TYPE_RE.test(o.mediaType) ||
|
|
73
|
+
hasControlChars(o.mediaType)) {
|
|
74
|
+
errs.push(`${o.type} mediaType must be a non-empty type/subtype string`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (typeof o.mediaType !== "string" || !spec.types.includes(o.mediaType)) {
|
|
63
78
|
errs.push(`${o.type} mediaType must be one of ${spec.types.join(", ")}`);
|
|
64
79
|
}
|
|
65
80
|
if (o.name !== undefined) {
|
|
@@ -72,6 +87,10 @@ export function validateMediaBlock(b) {
|
|
|
72
87
|
errs.push(`${o.type} name must not contain control characters`);
|
|
73
88
|
}
|
|
74
89
|
}
|
|
90
|
+
if (o.size !== undefined &&
|
|
91
|
+
(typeof o.size !== "number" || !Number.isInteger(o.size) || o.size < 0)) {
|
|
92
|
+
errs.push(`${o.type} size must be a non-negative integer`);
|
|
93
|
+
}
|
|
75
94
|
const src = o.source;
|
|
76
95
|
if (typeof src !== "object" || src === null) {
|
|
77
96
|
errs.push(`${o.type} source must be an object`);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Private Python 3 transport: one JSON request on stdin, one result/error on stdout.
|
|
3
|
+
* The trusted caller supplies already-authorized canonical root paths and inherited directory
|
|
4
|
+
* descriptors in roots.read/roots.write ({path, fd}); this helper never selects a profile.
|
|
5
|
+
* Binary data uses dataB64. Callers own launch, signal handling, admission and error translation.
|
|
6
|
+
* Descriptor-relative native access alone does not establish an OS execution boundary.
|
|
7
|
+
*/
|
|
8
|
+
export declare const NATIVE_FILES_SOURCE: string;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { DEVICE_SCAN_SKIPPED_BASE_DIRS, DEVICE_SCAN_SKIPPED_DIRS, MAX_DEVICE_PROJECT_NAME_LENGTH, MAX_DEVICE_SCAN_DEPTH, MAX_DEVICE_SCAN_DIRS, MAX_DEVICE_SCAN_RESULTS, } from "./sandbox.js";
|
|
2
|
+
/**
|
|
3
|
+
* Private Python 3 transport: one JSON request on stdin, one result/error on stdout.
|
|
4
|
+
* The trusted caller supplies already-authorized canonical root paths and inherited directory
|
|
5
|
+
* descriptors in roots.read/roots.write ({path, fd}); this helper never selects a profile.
|
|
6
|
+
* Binary data uses dataB64. Callers own launch, signal handling, admission and error translation.
|
|
7
|
+
* Descriptor-relative native access alone does not establish an OS execution boundary.
|
|
8
|
+
*/
|
|
9
|
+
export const NATIVE_FILES_SOURCE = String.raw `import base64
|
|
10
|
+
import errno
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
import stat
|
|
15
|
+
import sys
|
|
16
|
+
import urllib.parse
|
|
17
|
+
|
|
18
|
+
MAX_DEPTH = ${MAX_DEVICE_SCAN_DEPTH}
|
|
19
|
+
MAX_VISITS = ${MAX_DEVICE_SCAN_DIRS}
|
|
20
|
+
MAX_RESULTS = ${MAX_DEVICE_SCAN_RESULTS}
|
|
21
|
+
MAX_NAME = ${MAX_DEVICE_PROJECT_NAME_LENGTH}
|
|
22
|
+
SKIP_ANY = ${JSON.stringify(DEVICE_SCAN_SKIPPED_DIRS)}
|
|
23
|
+
SKIP_BASE = ${JSON.stringify(DEVICE_SCAN_SKIPPED_BASE_DIRS)}
|
|
24
|
+
# ECMAScript whitespace (Python's str.strip also removes several extra control characters).
|
|
25
|
+
SPACE = "\u0009\u000a\u000b\u000c\u000d\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff"
|
|
26
|
+
|
|
27
|
+
class ScopeDenied(Exception):
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
def units(value):
|
|
31
|
+
return value.encode("utf-16-be", "surrogatepass")
|
|
32
|
+
|
|
33
|
+
def valid_path(path):
|
|
34
|
+
if not isinstance(path, str) or not path.startswith("/") or len(units(path)) > 8192:
|
|
35
|
+
return False
|
|
36
|
+
if "\\" in path or "//" in path or re.search(r"[\x00-\x1f\x7f]", path):
|
|
37
|
+
return False
|
|
38
|
+
for part in path.split("/"):
|
|
39
|
+
try:
|
|
40
|
+
# decodeURIComponent rejects the entire segment on malformed escapes or UTF-8.
|
|
41
|
+
if re.search(r"%(?![0-9a-fA-F]{2})", part):
|
|
42
|
+
raise ValueError("Malformed percent escape")
|
|
43
|
+
decoded = urllib.parse.unquote(part, errors="strict")
|
|
44
|
+
except (UnicodeError, ValueError):
|
|
45
|
+
decoded = part
|
|
46
|
+
if decoded == ".." or "/" in decoded or "\\" in decoded:
|
|
47
|
+
return False
|
|
48
|
+
return True
|
|
49
|
+
|
|
50
|
+
def within(root, path):
|
|
51
|
+
return root == "/" or path == root or path.startswith(root + "/")
|
|
52
|
+
|
|
53
|
+
def valid_name(name):
|
|
54
|
+
return (name not in ("", ".", "..") and len(units(name)) <= MAX_NAME * 2
|
|
55
|
+
and not re.search(r"[\x00-\x1f\x7f/]", name)
|
|
56
|
+
and name[0] not in SPACE and name[-1] not in SPACE)
|
|
57
|
+
|
|
58
|
+
class NativeFiles:
|
|
59
|
+
def __init__(self, roots):
|
|
60
|
+
self.roots = roots
|
|
61
|
+
# Descriptors are supplied by the trusted consumer, never reopened by root pathname.
|
|
62
|
+
for root in roots["read"] + roots["write"]:
|
|
63
|
+
if not valid_path(root["path"]) or os.path.normpath(root["path"]) != root["path"]:
|
|
64
|
+
raise ValueError("Supply canonical absolute root paths")
|
|
65
|
+
if not stat.S_ISDIR(os.fstat(root["fd"]).st_mode):
|
|
66
|
+
raise ValueError("Supply pinned directory descriptors")
|
|
67
|
+
|
|
68
|
+
def parent(self, path, write=False, create=False):
|
|
69
|
+
fd, name, _, _ = self.resolve(path, write, create, 0, False)
|
|
70
|
+
return fd, name
|
|
71
|
+
|
|
72
|
+
def resolve(self, path, write, create, links, must_exist):
|
|
73
|
+
if not valid_path(path):
|
|
74
|
+
raise ValueError("Supply a valid absolute native path")
|
|
75
|
+
path = os.path.normpath(path)
|
|
76
|
+
roots = self.roots["write"] if write else self.roots["read"] + self.roots["write"]
|
|
77
|
+
matches = [root for root in roots if within(root["path"], path)]
|
|
78
|
+
if not matches:
|
|
79
|
+
raise ScopeDenied("Native path is outside the supplied roots")
|
|
80
|
+
root = max(matches, key=lambda entry: len(entry["path"]))
|
|
81
|
+
fd = os.dup(root["fd"])
|
|
82
|
+
current = root["path"]
|
|
83
|
+
parts = os.path.relpath(path, current).split("/")
|
|
84
|
+
return self.walk(fd, current, parts, write, create, links, must_exist)
|
|
85
|
+
|
|
86
|
+
def walk(self, fd, current, parts, write, create, links, must_exist):
|
|
87
|
+
try:
|
|
88
|
+
for index, name in enumerate(parts):
|
|
89
|
+
final = index == len(parts) - 1
|
|
90
|
+
try:
|
|
91
|
+
info = os.stat(name, dir_fd=fd, follow_symlinks=False)
|
|
92
|
+
except FileNotFoundError:
|
|
93
|
+
if not final and create:
|
|
94
|
+
try:
|
|
95
|
+
os.mkdir(name, 0o755, dir_fd=fd)
|
|
96
|
+
except FileExistsError:
|
|
97
|
+
pass
|
|
98
|
+
info = os.stat(name, dir_fd=fd, follow_symlinks=False)
|
|
99
|
+
elif final and not must_exist:
|
|
100
|
+
return fd, name, os.path.normpath(os.path.join(current, name)), links
|
|
101
|
+
else:
|
|
102
|
+
raise
|
|
103
|
+
if stat.S_ISLNK(info.st_mode):
|
|
104
|
+
if links >= 40:
|
|
105
|
+
raise OSError(errno.ELOOP, "Too many symbolic links")
|
|
106
|
+
target = os.readlink(name, dir_fd=fd)
|
|
107
|
+
after = os.stat(name, dir_fd=fd, follow_symlinks=False)
|
|
108
|
+
if (info.st_dev, info.st_ino) != (after.st_dev, after.st_ino):
|
|
109
|
+
raise ScopeDenied("Native path changed during resolution")
|
|
110
|
+
target = os.path.normpath(os.path.join(current, target))
|
|
111
|
+
os.close(fd)
|
|
112
|
+
fd = None
|
|
113
|
+
# Resolve the target once. Writes require an existing target; the returned
|
|
114
|
+
# descriptor/name is reused, including when a directory has a suffix to walk.
|
|
115
|
+
fd, linked_name, resolved, links = self.resolve(
|
|
116
|
+
target, write, False, links + 1, must_exist or write)
|
|
117
|
+
if final:
|
|
118
|
+
return fd, linked_name, resolved, links
|
|
119
|
+
try:
|
|
120
|
+
child = os.open(linked_name, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW,
|
|
121
|
+
dir_fd=fd)
|
|
122
|
+
except NotADirectoryError:
|
|
123
|
+
if not write:
|
|
124
|
+
raise FileNotFoundError(errno.ENOENT, "Native target does not exist")
|
|
125
|
+
raise
|
|
126
|
+
os.close(fd)
|
|
127
|
+
fd = None
|
|
128
|
+
return self.walk(child, resolved, parts[index + 1:], write, create,
|
|
129
|
+
links, must_exist)
|
|
130
|
+
if final:
|
|
131
|
+
return fd, name, os.path.normpath(os.path.join(current, name)), links
|
|
132
|
+
if not write and not stat.S_ISDIR(info.st_mode):
|
|
133
|
+
# Existing readers treat ENOTDIR in an ancestor as a missing target.
|
|
134
|
+
raise FileNotFoundError(errno.ENOENT, "Native target does not exist")
|
|
135
|
+
child = os.open(name, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=fd)
|
|
136
|
+
os.close(fd)
|
|
137
|
+
fd = child
|
|
138
|
+
current = os.path.join(current, name)
|
|
139
|
+
except BaseException:
|
|
140
|
+
if fd is not None:
|
|
141
|
+
os.close(fd)
|
|
142
|
+
raise
|
|
143
|
+
|
|
144
|
+
def open(self, path, write=False, directory=False):
|
|
145
|
+
parent, name = self.parent(path, write, write)
|
|
146
|
+
try:
|
|
147
|
+
flags = os.O_NOFOLLOW | os.O_NONBLOCK
|
|
148
|
+
flags |= os.O_WRONLY | os.O_CREAT if write else os.O_RDONLY
|
|
149
|
+
if directory:
|
|
150
|
+
flags |= os.O_DIRECTORY
|
|
151
|
+
return os.open(name, flags, 0o600, dir_fd=parent)
|
|
152
|
+
finally:
|
|
153
|
+
os.close(parent)
|
|
154
|
+
|
|
155
|
+
def metadata(self, path):
|
|
156
|
+
parent, name = self.parent(path)
|
|
157
|
+
try:
|
|
158
|
+
value = os.stat(name, dir_fd=parent, follow_symlinks=False)
|
|
159
|
+
if stat.S_ISLNK(value.st_mode):
|
|
160
|
+
raise ScopeDenied("Native path changed during resolution")
|
|
161
|
+
return value
|
|
162
|
+
finally:
|
|
163
|
+
os.close(parent)
|
|
164
|
+
|
|
165
|
+
def entries(self, fd):
|
|
166
|
+
# Dirent type data works even when child metadata cannot be searched. If the
|
|
167
|
+
# filesystem needs a metadata fallback, propagate its errors instead of dropping names.
|
|
168
|
+
with os.scandir(fd) as entries:
|
|
169
|
+
result = [(entry.name, entry.is_dir(follow_symlinks=False), entry.is_symlink())
|
|
170
|
+
for entry in entries]
|
|
171
|
+
return sorted(result, key=lambda entry: units(entry[0]))
|
|
172
|
+
|
|
173
|
+
def listing(self, path, limit):
|
|
174
|
+
fd = self.open(path, directory=True)
|
|
175
|
+
try:
|
|
176
|
+
entries = self.entries(fd)
|
|
177
|
+
result = []
|
|
178
|
+
for name, is_dir, is_link in entries[:limit]:
|
|
179
|
+
if is_link:
|
|
180
|
+
try:
|
|
181
|
+
is_dir = stat.S_ISDIR(self.metadata(os.path.join(path, name)).st_mode)
|
|
182
|
+
except (OSError, ScopeDenied, ValueError):
|
|
183
|
+
is_dir = False
|
|
184
|
+
result.append({"name": name, "isDir": is_dir})
|
|
185
|
+
return {"entries": result, "truncated": len(entries) > limit}
|
|
186
|
+
finally:
|
|
187
|
+
os.close(fd)
|
|
188
|
+
|
|
189
|
+
def scan(self, base):
|
|
190
|
+
# Exactly the SDK traversal: sorted breadth-first levels, count all attempted reads,
|
|
191
|
+
# descend past hits/invalid candidate names, then sort/filter/truncate the final answer.
|
|
192
|
+
base = os.path.normpath(base)
|
|
193
|
+
level = [base]
|
|
194
|
+
found = []
|
|
195
|
+
visits = 0
|
|
196
|
+
depth = 0
|
|
197
|
+
while level and visits < MAX_VISITS:
|
|
198
|
+
next_level = []
|
|
199
|
+
for path in sorted(level, key=units):
|
|
200
|
+
if visits >= MAX_VISITS:
|
|
201
|
+
break
|
|
202
|
+
visits += 1
|
|
203
|
+
try:
|
|
204
|
+
fd = self.open(path, directory=True)
|
|
205
|
+
try:
|
|
206
|
+
entries = self.entries(fd)
|
|
207
|
+
finally:
|
|
208
|
+
os.close(fd)
|
|
209
|
+
except FileNotFoundError:
|
|
210
|
+
if depth == 0:
|
|
211
|
+
return []
|
|
212
|
+
continue
|
|
213
|
+
except (OSError, ScopeDenied, ValueError):
|
|
214
|
+
if depth == 0:
|
|
215
|
+
raise
|
|
216
|
+
continue
|
|
217
|
+
if any(name == ".git" or (name == "AGENTS.md" and not is_dir)
|
|
218
|
+
for name, is_dir, _ in entries):
|
|
219
|
+
found.append(path)
|
|
220
|
+
if depth < MAX_DEPTH:
|
|
221
|
+
for name, is_dir, is_link in entries:
|
|
222
|
+
if (is_dir and not is_link and not name.startswith(".")
|
|
223
|
+
and name not in SKIP_ANY and not (depth == 0 and name in SKIP_BASE)):
|
|
224
|
+
next_level.append(os.path.join(path, name))
|
|
225
|
+
level = next_level
|
|
226
|
+
depth += 1
|
|
227
|
+
return [{"path": path, "suggestedName": os.path.basename(path)}
|
|
228
|
+
for path in sorted(set(found), key=units)
|
|
229
|
+
if valid_name(os.path.basename(path)) and valid_path(path)][:MAX_RESULTS]
|
|
230
|
+
|
|
231
|
+
def run(self, request):
|
|
232
|
+
method = request["method"]
|
|
233
|
+
path = request["path"]
|
|
234
|
+
if not valid_path(path):
|
|
235
|
+
raise ValueError("Supply a valid absolute native path")
|
|
236
|
+
if method in ("readFile", "list"):
|
|
237
|
+
bound = request["maxBytes" if method == "readFile" else "limit"]
|
|
238
|
+
if type(bound) is not int or bound < 0 or bound > 9007199254740991:
|
|
239
|
+
raise ValueError("Supply a nonnegative integer byte or entry limit")
|
|
240
|
+
if method == "scan":
|
|
241
|
+
return self.scan(path)
|
|
242
|
+
try:
|
|
243
|
+
if method == "stat":
|
|
244
|
+
info = self.metadata(path)
|
|
245
|
+
return {"size": info.st_size, "isDir": stat.S_ISDIR(info.st_mode)}
|
|
246
|
+
if method == "list":
|
|
247
|
+
return self.listing(path, bound)
|
|
248
|
+
if method == "readFile":
|
|
249
|
+
fd = self.open(path)
|
|
250
|
+
try:
|
|
251
|
+
info = os.fstat(fd)
|
|
252
|
+
if stat.S_ISDIR(info.st_mode):
|
|
253
|
+
return None
|
|
254
|
+
if not stat.S_ISREG(info.st_mode):
|
|
255
|
+
raise ValueError("Native reads require a regular file")
|
|
256
|
+
want = min(info.st_size, bound)
|
|
257
|
+
data = bytearray()
|
|
258
|
+
while len(data) < want:
|
|
259
|
+
chunk = os.read(fd, want - len(data))
|
|
260
|
+
if not chunk:
|
|
261
|
+
break
|
|
262
|
+
data.extend(chunk)
|
|
263
|
+
finally:
|
|
264
|
+
os.close(fd)
|
|
265
|
+
return {"dataB64": base64.b64encode(data).decode("ascii"),
|
|
266
|
+
"truncated": info.st_size > bound}
|
|
267
|
+
if method == "writeFile":
|
|
268
|
+
data = base64.b64decode(request["dataB64"], validate=True)
|
|
269
|
+
fd = self.open(path, write=True)
|
|
270
|
+
try:
|
|
271
|
+
if not stat.S_ISREG(os.fstat(fd).st_mode):
|
|
272
|
+
raise ValueError("Native writes require a regular file")
|
|
273
|
+
os.ftruncate(fd, 0)
|
|
274
|
+
remaining = memoryview(data)
|
|
275
|
+
while remaining:
|
|
276
|
+
written = os.write(fd, remaining)
|
|
277
|
+
if written == 0:
|
|
278
|
+
raise OSError(errno.EIO, "Native write made no progress")
|
|
279
|
+
remaining = remaining[written:]
|
|
280
|
+
finally:
|
|
281
|
+
os.close(fd)
|
|
282
|
+
return None
|
|
283
|
+
raise ValueError("Unknown native method")
|
|
284
|
+
except FileNotFoundError:
|
|
285
|
+
if method != "writeFile":
|
|
286
|
+
return None
|
|
287
|
+
raise
|
|
288
|
+
except IsADirectoryError:
|
|
289
|
+
if method == "readFile":
|
|
290
|
+
return None
|
|
291
|
+
raise
|
|
292
|
+
|
|
293
|
+
def main():
|
|
294
|
+
try:
|
|
295
|
+
request = json.load(sys.stdin)
|
|
296
|
+
result = NativeFiles(request["roots"]).run(request)
|
|
297
|
+
response = {"result": result}
|
|
298
|
+
except Exception as error:
|
|
299
|
+
code = ("SCOPE_DENIED" if isinstance(error, ScopeDenied)
|
|
300
|
+
else errno.errorcode.get(getattr(error, "errno", None), "INVALID_NATIVE_REQUEST"))
|
|
301
|
+
# Do not expose symlink targets or other resolved paths in transport errors.
|
|
302
|
+
response = {"error": {"code": code, "message": "Native operation failed; check the path, scope and filesystem access"}}
|
|
303
|
+
print(json.dumps(response), flush=True)
|
|
304
|
+
|
|
305
|
+
if __name__ == "__main__":
|
|
306
|
+
main()
|
|
307
|
+
`;
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { type ExecResult, type SandboxActor, type SandboxHandle, type SandboxProvider } from "./sandbox.js";
|
|
2
|
+
/** The permission profile selected for a conversation. */
|
|
3
|
+
export type PermissionProfile = "request-approval" | "approve-for-me" | "full-access";
|
|
4
|
+
/** Accepts only the supported permission profile names. */
|
|
5
|
+
export declare function isPermissionProfile(value: unknown): value is PermissionProfile;
|
|
6
|
+
/** The provider cannot enforce the requested permission profile. */
|
|
7
|
+
export declare class SandboxPermissionUnsupportedError extends Error {
|
|
8
|
+
readonly sandboxPermissionUnsupported: true;
|
|
9
|
+
constructor(message: string, opts?: ErrorOptions);
|
|
10
|
+
}
|
|
11
|
+
/** Recognizes the name and tag across SDK copies without requiring this class's identity. */
|
|
12
|
+
export declare function isSandboxPermissionUnsupportedError(e: unknown): e is SandboxPermissionUnsupportedError;
|
|
13
|
+
/** The requested operation is outside the permitted scope. */
|
|
14
|
+
export declare class SandboxScopeDeniedError extends Error {
|
|
15
|
+
readonly sandboxScopeDenied: true;
|
|
16
|
+
constructor(message: string, opts?: ErrorOptions);
|
|
17
|
+
}
|
|
18
|
+
/** Recognizes the name and tag across SDK copies without requiring this class's identity. */
|
|
19
|
+
export declare function isSandboxScopeDeniedError(e: unknown): e is SandboxScopeDeniedError;
|
|
20
|
+
/** A scope or execution reference is malformed; validate it before performing any effects. */
|
|
21
|
+
export declare class SandboxScopeValidationError extends Error {
|
|
22
|
+
readonly sandboxScopeValidation: true;
|
|
23
|
+
constructor(message: string, opts?: ErrorOptions);
|
|
24
|
+
}
|
|
25
|
+
/** Recognizes validation errors across SDK copies. */
|
|
26
|
+
export declare function isSandboxScopeValidationError(e: unknown): e is SandboxScopeValidationError;
|
|
27
|
+
/** An operation was consumed but its outcome is unknown. Never automatically retry with a new ID. */
|
|
28
|
+
export declare class SandboxOperationOutcomeUnknownError extends Error {
|
|
29
|
+
readonly sandboxOperationOutcomeUnknown: true;
|
|
30
|
+
constructor(message: string, opts?: ErrorOptions);
|
|
31
|
+
}
|
|
32
|
+
/** Recognizes unknown outcomes across SDK copies; an unknown outcome is not a gone instance. */
|
|
33
|
+
export declare function isSandboxOperationOutcomeUnknownError(e: unknown): e is SandboxOperationOutcomeUnknownError;
|
|
34
|
+
/** Writable roots are also readable. Device scope uses the device's OS authority, never its host's. */
|
|
35
|
+
export type SandboxFileScope = {
|
|
36
|
+
readonly kind: "scoped";
|
|
37
|
+
readonly readRoots: readonly string[];
|
|
38
|
+
readonly writeRoots: readonly string[];
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "device";
|
|
41
|
+
};
|
|
42
|
+
/** Environment removes only the agent-specific filter; owner/org/provider ceilings still apply. */
|
|
43
|
+
export type SandboxNetworkScope = {
|
|
44
|
+
readonly kind: "none";
|
|
45
|
+
} | {
|
|
46
|
+
readonly kind: "allowlist";
|
|
47
|
+
readonly hosts: readonly string[];
|
|
48
|
+
} | {
|
|
49
|
+
readonly kind: "environment";
|
|
50
|
+
};
|
|
51
|
+
/** An operation locator for idempotent admission and revocation, never a credential. */
|
|
52
|
+
export interface SandboxOperationRef {
|
|
53
|
+
readonly operationId: string;
|
|
54
|
+
/** Absolute launch-admission deadline; does not shorten an already started execution's timeout. */
|
|
55
|
+
readonly admitBeforeMs: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A fresh grant for one method invocation. Providers must copy and freeze the input before use.
|
|
59
|
+
* Full access normally uses device/environment; explicit bounded grants may expand other profiles.
|
|
60
|
+
* Validation does not resolve authority or infer a grant from the profile name.
|
|
61
|
+
*/
|
|
62
|
+
export interface SandboxOperationScope extends SandboxOperationRef {
|
|
63
|
+
readonly deviceId: string;
|
|
64
|
+
readonly rootConversationId: string;
|
|
65
|
+
readonly profileRevision: number;
|
|
66
|
+
readonly ceilingRevision: string;
|
|
67
|
+
readonly profile: PermissionProfile;
|
|
68
|
+
readonly actor: Readonly<SandboxActor>;
|
|
69
|
+
readonly tag: string;
|
|
70
|
+
readonly filesystem: SandboxFileScope;
|
|
71
|
+
readonly network: SandboxNetworkScope;
|
|
72
|
+
}
|
|
73
|
+
/** Runtime support, not consent. Restricted support requires all four claims together. */
|
|
74
|
+
export interface SandboxPermissionSupport {
|
|
75
|
+
readonly version: 1;
|
|
76
|
+
readonly restricted: {
|
|
77
|
+
readonly filesystem: true;
|
|
78
|
+
readonly network: true;
|
|
79
|
+
readonly native: true;
|
|
80
|
+
readonly concurrentScopes: true;
|
|
81
|
+
} | null;
|
|
82
|
+
readonly fullAccess: boolean;
|
|
83
|
+
readonly background: boolean;
|
|
84
|
+
readonly unavailableReason?: string;
|
|
85
|
+
}
|
|
86
|
+
/** Actor and tag come only from the immutable operation scope. */
|
|
87
|
+
export type SandboxExecOptions = Omit<Parameters<SandboxProvider["exec"]>[1], "tag" | "actor">;
|
|
88
|
+
/**
|
|
89
|
+
* A lightweight factory result: no worker opens until a method is called. Factory and method
|
|
90
|
+
* signals jointly end the operation. Every method consumes its operation ID before effects;
|
|
91
|
+
* a matching retry returns the recorded result or SandboxOperationOutcomeUnknownError, never
|
|
92
|
+
* repeats effects. Missing operation support has no fallback to the provider's raw methods.
|
|
93
|
+
* Native results and exec abort/timeout/output semantics match the existing provider contract.
|
|
94
|
+
*/
|
|
95
|
+
export interface SandboxOperation {
|
|
96
|
+
exec(args: SandboxExecOptions): Promise<ExecResult>;
|
|
97
|
+
readFile(path: string, opts: {
|
|
98
|
+
maxBytes: number;
|
|
99
|
+
signal: AbortSignal;
|
|
100
|
+
}): Promise<{
|
|
101
|
+
data: Uint8Array;
|
|
102
|
+
truncated: boolean;
|
|
103
|
+
} | null>;
|
|
104
|
+
writeFile(path: string, data: Uint8Array, signal: AbortSignal): Promise<void>;
|
|
105
|
+
stat(path: string, signal: AbortSignal): Promise<{
|
|
106
|
+
size: number;
|
|
107
|
+
isDir: boolean;
|
|
108
|
+
} | null>;
|
|
109
|
+
/** List and scan are optional together; without both, projects are unavailable. */
|
|
110
|
+
list?(path: string, opts: {
|
|
111
|
+
limit: number;
|
|
112
|
+
signal: AbortSignal;
|
|
113
|
+
}): Promise<{
|
|
114
|
+
entries: {
|
|
115
|
+
name: string;
|
|
116
|
+
isDir: boolean;
|
|
117
|
+
}[];
|
|
118
|
+
truncated: boolean;
|
|
119
|
+
} | null>;
|
|
120
|
+
scan?(base: string, opts: {
|
|
121
|
+
signal: AbortSignal;
|
|
122
|
+
}): Promise<{
|
|
123
|
+
path: string;
|
|
124
|
+
suggestedName: string;
|
|
125
|
+
}[]>;
|
|
126
|
+
}
|
|
127
|
+
/** Trusted staging only: providers validate purpose-specific roots; user tools never supply this grant. */
|
|
128
|
+
export interface SandboxPreparationScope {
|
|
129
|
+
readonly operationId: string;
|
|
130
|
+
readonly deviceId: string;
|
|
131
|
+
readonly purpose: "skills" | "attachments";
|
|
132
|
+
readonly writeRoots: readonly string[];
|
|
133
|
+
readonly tag: string;
|
|
134
|
+
}
|
|
135
|
+
/** Marker reads and writes inside trusted preparation roots, with no exec or network capability. */
|
|
136
|
+
export type SandboxPreparation = Pick<SandboxOperation, "readFile" | "writeFile" | "stat">;
|
|
137
|
+
/** Owner-authenticated browsing, independent of a conversation or its profile/consent. */
|
|
138
|
+
export interface SandboxBrowseScope extends SandboxOperationRef {
|
|
139
|
+
readonly deviceId: string;
|
|
140
|
+
readonly accountId: string;
|
|
141
|
+
readonly ceilingRevision: string;
|
|
142
|
+
readonly readRoots: readonly string[];
|
|
143
|
+
readonly tag: string;
|
|
144
|
+
}
|
|
145
|
+
/** Browsing exposes metadata only: no file contents, writes, preparation or execution. */
|
|
146
|
+
export type SandboxBrowse = Pick<SandboxOperation, "stat"> & Required<Pick<SandboxOperation, "list" | "scan">>;
|
|
147
|
+
/** An opaque locator over authenticated transport; validate generation before status, tail or stop. */
|
|
148
|
+
export interface SandboxExecutionRef {
|
|
149
|
+
readonly executionId: string;
|
|
150
|
+
readonly operationId: string;
|
|
151
|
+
readonly instanceId: string;
|
|
152
|
+
readonly instanceGeneration: string;
|
|
153
|
+
}
|
|
154
|
+
/** A lost supervisor never binds this reference to a reused PID. */
|
|
155
|
+
export type SandboxExecutionStatus = {
|
|
156
|
+
state: "running";
|
|
157
|
+
} | {
|
|
158
|
+
state: "exited";
|
|
159
|
+
exitCode: number | null;
|
|
160
|
+
timedOut: boolean;
|
|
161
|
+
} | {
|
|
162
|
+
state: "lost";
|
|
163
|
+
};
|
|
164
|
+
/** Atomically claimed terminal outcome; retries preserve it, including a prior natural exit. */
|
|
165
|
+
export type SandboxStopResult = {
|
|
166
|
+
outcome: "already-exited";
|
|
167
|
+
exitCode: number | null;
|
|
168
|
+
timedOut: boolean;
|
|
169
|
+
} | {
|
|
170
|
+
outcome: "stopped";
|
|
171
|
+
} | {
|
|
172
|
+
outcome: "cancel-pending";
|
|
173
|
+
} | {
|
|
174
|
+
outcome: "lost";
|
|
175
|
+
};
|
|
176
|
+
/** Trusted exact-execution supervision. Status, tail and stop never provision or resume an instance. */
|
|
177
|
+
export interface SandboxBackground {
|
|
178
|
+
/**
|
|
179
|
+
* Persist exact ownership before acknowledging; retries of the same generation/operation/input
|
|
180
|
+
* return the same reference. Retain starting grants for the lifetime of the owned execution.
|
|
181
|
+
* Validate outputPath inside the scope. retainUntilMs bounds status/output record retention.
|
|
182
|
+
*/
|
|
183
|
+
start(h: SandboxHandle, scope: SandboxOperationScope, args: SandboxExecOptions & {
|
|
184
|
+
taskId: string;
|
|
185
|
+
outputPath: string;
|
|
186
|
+
retainUntilMs: number;
|
|
187
|
+
}): Promise<SandboxExecutionRef>;
|
|
188
|
+
status(h: SandboxHandle, ref: SandboxExecutionRef, signal: AbortSignal): Promise<SandboxExecutionStatus>;
|
|
189
|
+
/** At most 65,536 bytes, preserving UTF-8 boundaries and existing final-line limits; no caller path. */
|
|
190
|
+
tail(h: SandboxHandle, ref: SandboxExecutionRef, opts: {
|
|
191
|
+
maxBytes: number;
|
|
192
|
+
signal: AbortSignal;
|
|
193
|
+
}): Promise<{
|
|
194
|
+
data: Uint8Array;
|
|
195
|
+
truncated: boolean;
|
|
196
|
+
} | {
|
|
197
|
+
unavailable: "lost" | "expired";
|
|
198
|
+
}>;
|
|
199
|
+
/**
|
|
200
|
+
* Read retained raw merged-output bytes by exact reference, without a caller path, new scope,
|
|
201
|
+
* exec, provisioning or resume. Validate before I/O: offset is a nonnegative safe integer;
|
|
202
|
+
* maxBytes is an integer in [0, 65_536], including zero for a metadata-only probe. Invalid
|
|
203
|
+
* bounds throw SandboxScopeDeniedError. The byte budget includes any caller-requested overlap.
|
|
204
|
+
*
|
|
205
|
+
* totalBytes is one committed append-only prefix snapshot pinned at read admission. Return
|
|
206
|
+
* exactly min(maxBytes, max(totalBytes - offset, 0)) bytes starting at the requested offset,
|
|
207
|
+
* without UTF-8 trimming or decoding; retry short reads or report lost. nextOffset equals
|
|
208
|
+
* offset + data.byteLength. At/past the snapshot end, return empty data with unchanged offset.
|
|
209
|
+
* Reads are non-destructive and repeatable; concurrent appends cannot change returned bytes
|
|
210
|
+
* or this snapshot. Safe-integer position overflow fails collection rather than rounding.
|
|
211
|
+
*
|
|
212
|
+
* Missing/untrustworthy retained storage returns lost; a known expired record returns expired.
|
|
213
|
+
* Exact-ref/device/generation mismatches remain scope-denied errors; aborts propagate.
|
|
214
|
+
* Unlike tail, terminal reads retain every line. Current task access checks still apply.
|
|
215
|
+
*/
|
|
216
|
+
readOutput(h: SandboxHandle, ref: SandboxExecutionRef, opts: {
|
|
217
|
+
offset: number;
|
|
218
|
+
maxBytes: number;
|
|
219
|
+
signal: AbortSignal;
|
|
220
|
+
}): Promise<{
|
|
221
|
+
data: Uint8Array;
|
|
222
|
+
offset: number;
|
|
223
|
+
nextOffset: number;
|
|
224
|
+
totalBytes: number;
|
|
225
|
+
} | {
|
|
226
|
+
unavailable: "lost" | "expired";
|
|
227
|
+
}>;
|
|
228
|
+
/** Persist pending cancellation while unreachable; apply it before an explicit resume can run work. */
|
|
229
|
+
stop(h: SandboxHandle, ref: SandboxExecutionRef, opts: {
|
|
230
|
+
graceMs: number;
|
|
231
|
+
signal: AbortSignal;
|
|
232
|
+
}): Promise<SandboxStopResult>;
|
|
233
|
+
}
|
|
234
|
+
/** Pure structural validation and a frozen copy; no clock lookup or authority resolution. */
|
|
235
|
+
export declare function parseSandboxOperationRef(value: unknown): SandboxOperationRef;
|
|
236
|
+
/**
|
|
237
|
+
* Validates a scope and returns a deeply frozen copy, throwing SandboxScopeValidationError.
|
|
238
|
+
* IDs and ceiling revisions are bounded to 128 characters; roots to 64 paths of at most 4096 characters;
|
|
239
|
+
* hosts to 100 entries passing validateAllowHost. Empty grants stay empty, including deny-all.
|
|
240
|
+
* Performs no I/O, authority lookup or deadline refresh. Unknown fields are rejected at every level.
|
|
241
|
+
*/
|
|
242
|
+
export declare function parseSandboxOperationScope(value: unknown): SandboxOperationScope;
|
|
243
|
+
/** Validates an owner browsing grant and returns a deeply frozen copy; no conversation is required. */
|
|
244
|
+
export declare function parseSandboxBrowseScope(value: unknown): SandboxBrowseScope;
|
|
245
|
+
/** Validates trusted staging structure and returns a deeply frozen copy; does not authorize its roots. */
|
|
246
|
+
export declare function parseSandboxPreparationScope(value: unknown): SandboxPreparationScope;
|
|
247
|
+
/** Validates all four bounded locator fields and returns a frozen copy; does not authenticate the caller. */
|
|
248
|
+
export declare function parseSandboxExecutionRef(value: unknown): SandboxExecutionRef;
|
|
@@ -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,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Immutable portable native helper bytes for trusted consumer staging (requires Python 3).
|
|
3
|
+
* Consumers verify hashes before use and supply pinned, already-authorized root descriptors.
|
|
4
|
+
* This bundle declares no restricted-runtime support; enforcement and launch belong to providers.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SANDBOX_RUNTIME_SOURCE: {
|
|
7
|
+
readonly version: number;
|
|
8
|
+
readonly files: readonly {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly source: string;
|
|
11
|
+
readonly sha256: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NATIVE_FILES_SOURCE } from "./sandbox-native-runtime-source.js";
|
|
2
|
+
/**
|
|
3
|
+
* Immutable portable native helper bytes for trusted consumer staging (requires Python 3).
|
|
4
|
+
* Consumers verify hashes before use and supply pinned, already-authorized root descriptors.
|
|
5
|
+
* This bundle declares no restricted-runtime support; enforcement and launch belong to providers.
|
|
6
|
+
*/
|
|
7
|
+
export const SANDBOX_RUNTIME_SOURCE = Object.freeze({
|
|
8
|
+
version: 1,
|
|
9
|
+
files: Object.freeze([
|
|
10
|
+
Object.freeze({
|
|
11
|
+
name: "native-files.py",
|
|
12
|
+
source: NATIVE_FILES_SOURCE,
|
|
13
|
+
sha256: "601f51c1c46bedac5ab56f7ca38d7c15fdea8481efc6476d5a5b3243318ef79b",
|
|
14
|
+
}),
|
|
15
|
+
]),
|
|
16
|
+
});
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
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. */
|
|
@@ -23,6 +24,10 @@ export interface SandboxLimits {
|
|
|
23
24
|
/**
|
|
24
25
|
* `auto`: no OS sandbox (local: the owner; cloud: the container is the boundary);
|
|
25
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.
|
|
26
31
|
*/
|
|
27
32
|
mode: "auto" | "sandbox";
|
|
28
33
|
/**
|
|
@@ -172,6 +177,25 @@ export declare const SANDBOX_TAG_RE: RegExp;
|
|
|
172
177
|
* aborted `exec` kills only its own command.
|
|
173
178
|
*/
|
|
174
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;
|
|
175
199
|
/** `exec` / `readFile` / `writeFile` / `stat` may run concurrently on one instance (required). */
|
|
176
200
|
readonly concurrentExec: true;
|
|
177
201
|
/**
|
package/dist/storage.d.ts
CHANGED
|
@@ -67,6 +67,13 @@ export interface ObjectStore {
|
|
|
67
67
|
maxSize: number;
|
|
68
68
|
ttlSeconds: number;
|
|
69
69
|
}): Promise<PresignedUpload>;
|
|
70
|
+
/**
|
|
71
|
+
* The canonical URI of a key in this store: unsigned, stable, no credentials
|
|
72
|
+
* (`s3://bucket/key`). This is an identifier, never a presigned URL: it may be recorded in an
|
|
73
|
+
* event log and shown to a model, so it must stay valid and carry no secret. Optional: a store
|
|
74
|
+
* with no notion of URIs leaves it out and the kernel falls back to its own reference.
|
|
75
|
+
*/
|
|
76
|
+
uri?(key: string): string;
|
|
70
77
|
}
|
|
71
78
|
/** 预签名下载的选项。 */
|
|
72
79
|
export interface PresignGetOptions {
|