@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,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;
|