@capybara-hq/plugin-sdk 0.1.0-rc.15 → 0.1.0-rc.16
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 +14 -2
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/cards.d.ts +9 -1
- package/dist/cards.js +31 -1
- package/dist/dev-hosts.d.ts +6 -0
- package/dist/dev-hosts.js +45 -0
- package/dist/device-protocol.d.ts +78 -2
- package/dist/device-protocol.js +146 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/plugin-manifest.d.ts +0 -2
- package/dist/plugin-manifest.js +1 -1
- package/dist/sandbox.d.ts +75 -0
- package/dist/sandbox.js +28 -0
- package/package.json +1 -1
- package/schemas/plugin.v1.schema.json +0 -3
|
@@ -30,8 +30,8 @@ You are a careful researcher. ...
|
|
|
30
30
|
| `model` | `inherit` \| `fast` \| `standard` \| `capable` | no | A purpose tier, never a model id; default `inherit`. |
|
|
31
31
|
| `effort` | `low` \| `medium` \| `high` \| `xhigh` \| `max` | no | Reasoning effort. |
|
|
32
32
|
| `maxSteps` | integer | no | Step limit; the kernel caps it. |
|
|
33
|
-
| `skills` | array of skill names | no | At most 3
|
|
34
|
-
| `
|
|
33
|
+
| `skills` | array of skill names | no | At most 3; the sub-agent is told to load them with `Skill` before it starts. |
|
|
34
|
+
| `disallowedSkills` | array of skill references | no | At most 64 skills turned off (all others on in the org are on): `<plugin>:<name>`, `<plugin>:*` (the whole plugin, later skills included) or a bare `<name>` (an org skill without a plugin). |
|
|
35
35
|
| `connectors` | array of objects | no | At most 16: `{ template, tools?, policies? }` for a connector template (`<id>` or `<plugin>:<id>`), or `{ needs: { protocol, endpoint, tools, label }, policies? }` for a described need. |
|
|
36
36
|
| `subagents` | object | no | `{ general?, types?, inline? }`: the sub-agents in its roster (at most 16 types plus inline). |
|
|
37
37
|
| `modelRef` | string | no | `provider/model`; set on org templates saved from an agent. |
|
|
@@ -41,6 +41,18 @@ You are a careful researcher. ...
|
|
|
41
41
|
|
|
42
42
|
Unknown keys are ignored. The body is at most 100,000 characters.
|
|
43
43
|
|
|
44
|
+
## Skills
|
|
45
|
+
|
|
46
|
+
An agent has every skill that is on in its org; nothing is pinned into its context. A template
|
|
47
|
+
only turns skills off, with `disallowedSkills`: `<plugin>:<name>` for one skill of a plugin,
|
|
48
|
+
`<plugin>:*` for the whole plugin (skills it gains later included) or a bare `<name>` for an org
|
|
49
|
+
skill without a plugin. Saving an agent as an org template writes its off-list here.
|
|
50
|
+
|
|
51
|
+
`skills` keeps Claude Code's meaning for sub-agent use: when the template runs as a sub-agent, the
|
|
52
|
+
child is told to load these skills with `Skill` before it starts. When a member creates an agent
|
|
53
|
+
from the template, each name in `skills` (and in its sub-agents' `skills`) is reported as carried
|
|
54
|
+
or as unavailable in the org; it narrows nothing.
|
|
55
|
+
|
|
44
56
|
## Creating an agent from a template
|
|
45
57
|
|
|
46
58
|
A connector the org does not have becomes a pending entry, and a setup request goes to the org
|
package/dist/agent-template.d.ts
CHANGED
|
@@ -19,10 +19,14 @@ export interface AgentTemplate {
|
|
|
19
19
|
effort?: "low" | "medium" | "high" | "xhigh" | "max";
|
|
20
20
|
/** Step limit (the kernel caps it at `runtime.maxSteps`). */
|
|
21
21
|
maxSteps?: number;
|
|
22
|
-
/** Skill names
|
|
22
|
+
/** Skill names the sub-agent is told to load with `Skill` before it starts (Claude Code's field). */
|
|
23
23
|
skills?: string[];
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Skills turned off for the agent (every skill on in the org is on otherwise):
|
|
26
|
+
* `<plugin>:<name>`, `<plugin>:*` (the whole plugin, skills it gains later included) or a bare
|
|
27
|
+
* `<name>` (an org skill without a plugin).
|
|
28
|
+
*/
|
|
29
|
+
disallowedSkills?: string[];
|
|
26
30
|
/** Connectors the agent needs: a connector template of the plugin, or a described need. */
|
|
27
31
|
connectors?: AgentTemplateConnector[];
|
|
28
32
|
/** The sub-agents the agent gets in its roster. */
|
|
@@ -85,12 +89,12 @@ export declare const AGENT_TEMPLATE_LIMITS: {
|
|
|
85
89
|
readonly descriptionChars: 4096;
|
|
86
90
|
/** Templates in one plugin. */
|
|
87
91
|
readonly perPlugin: 64;
|
|
88
|
-
/**
|
|
92
|
+
/** Skills the sub-agent loads first. */
|
|
89
93
|
readonly skills: 3;
|
|
90
94
|
/** Entries of `tools` and of `disallowedTools`. */
|
|
91
95
|
readonly tools: 200;
|
|
92
|
-
/** Entries of `
|
|
93
|
-
readonly
|
|
96
|
+
/** Entries of `disallowedSkills`. */
|
|
97
|
+
readonly disallowedSkills: 64;
|
|
94
98
|
/** Entries of `connectors`. */
|
|
95
99
|
readonly connectors: 16;
|
|
96
100
|
/** `subagents.types` plus `subagents.inline`. */
|
|
@@ -119,6 +123,11 @@ export interface AgentTemplateField {
|
|
|
119
123
|
export declare const AGENT_TEMPLATE_FIELDS: readonly AgentTemplateField[];
|
|
120
124
|
/** The name rule of a template (the catalog item name rule). */
|
|
121
125
|
export declare const AGENT_TEMPLATE_NAME_RE: RegExp;
|
|
126
|
+
/**
|
|
127
|
+
* A `disallowedSkills` entry: `<plugin>:<name>`, `<plugin>:*` (the whole plugin) or a bare skill
|
|
128
|
+
* `<name>` (an org skill without a plugin).
|
|
129
|
+
*/
|
|
130
|
+
export declare function isDisallowedSkillRef(v: unknown): v is string;
|
|
122
131
|
/** The name rule of an instruction file (the agent's rule, mirrored). */
|
|
123
132
|
export declare const AGENT_TEMPLATE_INSTRUCTION_FILE_NAME_RE: RegExp;
|
|
124
133
|
/**
|
package/dist/agent-template.js
CHANGED
|
@@ -13,12 +13,12 @@ export const AGENT_TEMPLATE_LIMITS = {
|
|
|
13
13
|
descriptionChars: 4096,
|
|
14
14
|
/** Templates in one plugin. */
|
|
15
15
|
perPlugin: 64,
|
|
16
|
-
/**
|
|
16
|
+
/** Skills the sub-agent loads first. */
|
|
17
17
|
skills: 3,
|
|
18
18
|
/** Entries of `tools` and of `disallowedTools`. */
|
|
19
19
|
tools: 200,
|
|
20
|
-
/** Entries of `
|
|
21
|
-
|
|
20
|
+
/** Entries of `disallowedSkills`. */
|
|
21
|
+
disallowedSkills: 64,
|
|
22
22
|
/** Entries of `connectors`. */
|
|
23
23
|
connectors: 16,
|
|
24
24
|
/** `subagents.types` plus `subagents.inline`. */
|
|
@@ -89,13 +89,13 @@ export const AGENT_TEMPLATE_FIELDS = [
|
|
|
89
89
|
name: "skills",
|
|
90
90
|
type: "array of skill names",
|
|
91
91
|
required: false,
|
|
92
|
-
description: "At most 3
|
|
92
|
+
description: "At most 3; the sub-agent is told to load them with `Skill` before it starts.",
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
|
-
name: "
|
|
96
|
-
type: "array of skill
|
|
95
|
+
name: "disallowedSkills",
|
|
96
|
+
type: "array of skill references",
|
|
97
97
|
required: false,
|
|
98
|
-
description: "At most
|
|
98
|
+
description: "At most 64 skills turned off (all others on in the org are on): `<plugin>:<name>`, `<plugin>:*` (the whole plugin, later skills included) or a bare `<name>` (an org skill without a plugin).",
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
101
|
name: "connectors",
|
|
@@ -139,6 +139,21 @@ const TOOL_KEY_RE = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
|
139
139
|
const distinct = (v) => new Set(v).size === v.length;
|
|
140
140
|
const NAME_REF_RE = /^[a-z0-9][a-z0-9-]{0,63}(:[a-z0-9][a-z0-9-]{0,63})?$/;
|
|
141
141
|
const MODEL_REF_RE = /^[^/\s]+\/\S+$/;
|
|
142
|
+
const PLUGIN_REF_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
143
|
+
/**
|
|
144
|
+
* A `disallowedSkills` entry: `<plugin>:<name>`, `<plugin>:*` (the whole plugin) or a bare skill
|
|
145
|
+
* `<name>` (an org skill without a plugin).
|
|
146
|
+
*/
|
|
147
|
+
export function isDisallowedSkillRef(v) {
|
|
148
|
+
if (typeof v !== "string")
|
|
149
|
+
return false;
|
|
150
|
+
const i = v.indexOf(":");
|
|
151
|
+
if (i < 0)
|
|
152
|
+
return isSkillName(v);
|
|
153
|
+
const plugin = v.slice(0, i);
|
|
154
|
+
const name = v.slice(i + 1);
|
|
155
|
+
return PLUGIN_REF_RE.test(plugin) && (name === "*" || isSkillName(name));
|
|
156
|
+
}
|
|
142
157
|
/** The name rule of an instruction file (the agent's rule, mirrored). */
|
|
143
158
|
export const AGENT_TEMPLATE_INSTRUCTION_FILE_NAME_RE = /^[^/\\]{1,64}\.md$/;
|
|
144
159
|
const chars = (s) => [...s].length;
|
|
@@ -233,13 +248,17 @@ export function parseAgentTemplate(text) {
|
|
|
233
248
|
else
|
|
234
249
|
errors.push(`skills must list at most ${L.skills} skill names`);
|
|
235
250
|
}
|
|
236
|
-
if (fm.
|
|
237
|
-
const s = fm.
|
|
238
|
-
if (Array.isArray(s) &&
|
|
239
|
-
|
|
251
|
+
if (fm.disallowedSkills !== undefined) {
|
|
252
|
+
const s = fm.disallowedSkills;
|
|
253
|
+
if (Array.isArray(s) &&
|
|
254
|
+
s.length <= L.disallowedSkills &&
|
|
255
|
+
s.every(isDisallowedSkillRef) &&
|
|
256
|
+
distinct(s)) {
|
|
257
|
+
out.disallowedSkills = s;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
errors.push(`disallowedSkills must list at most ${L.disallowedSkills} distinct entries, each <plugin>:<name>, <plugin>:* or <name>`);
|
|
240
261
|
}
|
|
241
|
-
else
|
|
242
|
-
errors.push(`selectedSkills must list at most ${L.selectedSkills} skill names`);
|
|
243
262
|
}
|
|
244
263
|
if (fm.connectors !== undefined) {
|
|
245
264
|
const c = readConnectors(fm.connectors, errors);
|
package/dist/cards.d.ts
CHANGED
|
@@ -19,8 +19,16 @@ export type ChannelCard = {
|
|
|
19
19
|
*/
|
|
20
20
|
inputPreview: string;
|
|
21
21
|
scopes: ("once" | "session" | "always")[];
|
|
22
|
+
/**
|
|
23
|
+
* The kernel's names for the scopes when they mean something other than the default (a
|
|
24
|
+
* network ask: `once` = "Allow this time", `always` = "Always allow on this device"). Plain
|
|
25
|
+
* text, 1 to 40 characters; a channel that does not know the field renders its default
|
|
26
|
+
* scope labels. Kernel-written, never model-controlled.
|
|
27
|
+
*/
|
|
28
|
+
scopeLabels?: Partial<Record<"once" | "session" | "always", string>>;
|
|
22
29
|
expiresAt: string;
|
|
23
|
-
|
|
30
|
+
/** `skipped`: the person sent a message instead of deciding (the run went on with it). */
|
|
31
|
+
state: "pending" | "approved" | "denied" | "expired" | "cancelled" | "skipped";
|
|
24
32
|
decidedBy?: string;
|
|
25
33
|
/** A denied approval: the reason the person gave (plain text, never formatted). */
|
|
26
34
|
denyReason?: string;
|
package/dist/cards.js
CHANGED
|
@@ -21,7 +21,15 @@ export function questionRenderableInline(form, opts) {
|
|
|
21
21
|
}
|
|
22
22
|
const KINDS = ["approval", "question", "connect", "bind"];
|
|
23
23
|
const SCOPES = ["once", "session", "always"];
|
|
24
|
-
const APPROVAL_STATES = [
|
|
24
|
+
const APPROVAL_STATES = [
|
|
25
|
+
"pending",
|
|
26
|
+
"approved",
|
|
27
|
+
"denied",
|
|
28
|
+
"expired",
|
|
29
|
+
"cancelled",
|
|
30
|
+
"skipped",
|
|
31
|
+
];
|
|
32
|
+
const MAX_SCOPE_LABEL = 40;
|
|
25
33
|
const QUESTION_STATES = ["pending", "answered", "skipped", "expired", "cancelled"];
|
|
26
34
|
const TEXT_REPLY = ["plain", "mention"];
|
|
27
35
|
const ISO_8601 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|
|
@@ -61,6 +69,16 @@ export function validateChannelCard(card) {
|
|
|
61
69
|
new Set(s).size !== s.length ||
|
|
62
70
|
s.some((x) => !SCOPES.includes(x)))
|
|
63
71
|
out.push(`scopes must be a non-empty array of ${list(SCOPES)} without duplicates`);
|
|
72
|
+
const labels = c.scopeLabels;
|
|
73
|
+
if (labels !== undefined &&
|
|
74
|
+
(typeof labels !== "object" ||
|
|
75
|
+
labels === null ||
|
|
76
|
+
Array.isArray(labels) ||
|
|
77
|
+
Object.entries(labels).some(([k, v]) => !SCOPES.includes(k) ||
|
|
78
|
+
typeof v !== "string" ||
|
|
79
|
+
v.length === 0 ||
|
|
80
|
+
v.length > MAX_SCOPE_LABEL)))
|
|
81
|
+
out.push(`scopeLabels must map ${list(SCOPES)} to strings of 1 to ${MAX_SCOPE_LABEL} characters`);
|
|
64
82
|
if (typeof c.expiresAt !== "string" ||
|
|
65
83
|
!ISO_8601.test(c.expiresAt) ||
|
|
66
84
|
Number.isNaN(Date.parse(c.expiresAt)))
|
|
@@ -133,12 +151,15 @@ const TEXT = {
|
|
|
133
151
|
answerOnWeb: "Answer on the web",
|
|
134
152
|
details: "Details",
|
|
135
153
|
connectLink: "Connect",
|
|
154
|
+
options: "Options",
|
|
155
|
+
scopes: { once: "Once", session: "This session", always: "Always" },
|
|
136
156
|
approvalStates: {
|
|
137
157
|
pending: "Pending",
|
|
138
158
|
approved: "Approved",
|
|
139
159
|
denied: "Denied",
|
|
140
160
|
expired: "Expired",
|
|
141
161
|
cancelled: "Cancelled",
|
|
162
|
+
skipped: "Skipped",
|
|
142
163
|
},
|
|
143
164
|
questionStates: {
|
|
144
165
|
pending: "Pending",
|
|
@@ -168,12 +189,15 @@ const TEXT = {
|
|
|
168
189
|
answerOnWeb: "到网页上回答",
|
|
169
190
|
details: "详情",
|
|
170
191
|
connectLink: "连接",
|
|
192
|
+
options: "选项",
|
|
193
|
+
scopes: { once: "这次", session: "本会话", always: "一直" },
|
|
171
194
|
approvalStates: {
|
|
172
195
|
pending: "待审批",
|
|
173
196
|
approved: "已批准",
|
|
174
197
|
denied: "已拒绝",
|
|
175
198
|
expired: "已过期",
|
|
176
199
|
cancelled: "已取消",
|
|
200
|
+
skipped: "已跳过",
|
|
177
201
|
},
|
|
178
202
|
questionStates: {
|
|
179
203
|
pending: "待回答",
|
|
@@ -219,6 +243,12 @@ export function renderCardAsText(card, locale) {
|
|
|
219
243
|
];
|
|
220
244
|
if (card.state === "denied" && card.denyReason)
|
|
221
245
|
lines.push(line(t.reason, asCode(card.denyReason)));
|
|
246
|
+
// the scopes are listed only when the kernel named them (a network ask): the default
|
|
247
|
+
// approval text stays as it was
|
|
248
|
+
if (card.state === "pending" && card.scopeLabels) {
|
|
249
|
+
const labels = card.scopes.map((s) => card.scopeLabels?.[s] ?? t.scopes[s]);
|
|
250
|
+
lines.push(line(t.options, labels.join(" / ")));
|
|
251
|
+
}
|
|
222
252
|
if (card.state === "pending")
|
|
223
253
|
lines.push(line(t.expires, card.expiresAt), line(t.approveOnWeb, card.webUrl));
|
|
224
254
|
else
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dev hosts preset: common package registries, source hosts and tool downloads the `dev`
|
|
3
|
+
* sandbox tier adds to the org's allowlist. The kernel's `sandbox.limits.devHosts` defaults to it;
|
|
4
|
+
* the device and the sandbox plugins read the same list. Every entry passes `validateAllowHost`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEV_HOSTS: readonly string[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dev hosts preset: common package registries, source hosts and tool downloads the `dev`
|
|
3
|
+
* sandbox tier adds to the org's allowlist. The kernel's `sandbox.limits.devHosts` defaults to it;
|
|
4
|
+
* the device and the sandbox plugins read the same list. Every entry passes `validateAllowHost`.
|
|
5
|
+
*/
|
|
6
|
+
export const DEV_HOSTS = Object.freeze([
|
|
7
|
+
// npm / Node
|
|
8
|
+
"registry.npmjs.org",
|
|
9
|
+
"registry.yarnpkg.com",
|
|
10
|
+
"repo.yarnpkg.com",
|
|
11
|
+
"nodejs.org",
|
|
12
|
+
// Python
|
|
13
|
+
"pypi.org",
|
|
14
|
+
"files.pythonhosted.org",
|
|
15
|
+
// GitHub
|
|
16
|
+
"github.com",
|
|
17
|
+
"api.github.com",
|
|
18
|
+
"codeload.github.com",
|
|
19
|
+
"raw.githubusercontent.com",
|
|
20
|
+
"objects.githubusercontent.com",
|
|
21
|
+
"release-assets.githubusercontent.com",
|
|
22
|
+
"ghcr.io",
|
|
23
|
+
"pkg-containers.githubusercontent.com",
|
|
24
|
+
// Rust
|
|
25
|
+
"crates.io",
|
|
26
|
+
"index.crates.io",
|
|
27
|
+
"static.crates.io",
|
|
28
|
+
"static.rust-lang.org",
|
|
29
|
+
// Go
|
|
30
|
+
"proxy.golang.org",
|
|
31
|
+
"sum.golang.org",
|
|
32
|
+
// JVM
|
|
33
|
+
"repo.maven.apache.org",
|
|
34
|
+
"repo1.maven.org",
|
|
35
|
+
"plugins.gradle.org",
|
|
36
|
+
"services.gradle.org",
|
|
37
|
+
"downloads.gradle.org",
|
|
38
|
+
// Docker Hub (image metadata and layers for tools such as crane)
|
|
39
|
+
"registry-1.docker.io",
|
|
40
|
+
"auth.docker.io",
|
|
41
|
+
"production.cloudflare.docker.com",
|
|
42
|
+
// Playwright browsers
|
|
43
|
+
"cdn.playwright.dev",
|
|
44
|
+
"playwright.download.prss.microsoft.com",
|
|
45
|
+
]);
|
|
@@ -2,11 +2,41 @@
|
|
|
2
2
|
* Device protocol v1: 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
|
-
import { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots } from "./sandbox.js";
|
|
5
|
+
import { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots, type SandboxTier } from "./sandbox.js";
|
|
6
6
|
/** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
|
|
7
7
|
export declare const DEVICE_PROTOCOL_VERSION = 1;
|
|
8
8
|
/** The operations the kernel asks a device to run. */
|
|
9
|
-
export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop";
|
|
9
|
+
export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop" | "policy";
|
|
10
|
+
/**
|
|
11
|
+
* Optional capabilities a device announces in its hello. A kernel sends the `policy` op only to a
|
|
12
|
+
* device with `policyOp`; `networkReport` means exec results may carry `network`; `tiers` means the
|
|
13
|
+
* device applies `limits.tier` / `defaultTier` / `devHosts` (without it the device behaves as
|
|
14
|
+
* `strict`).
|
|
15
|
+
*/
|
|
16
|
+
export type DeviceFeature = "networkReport" | "policyOp" | "tiers";
|
|
17
|
+
/**
|
|
18
|
+
* Whether the device accepts widening its local policy from the kernel (the `policy` op's `add`
|
|
19
|
+
* and a higher `tier`, run and task grants): `owner` (default, decided by the device owner in a
|
|
20
|
+
* signed-in session) or `off` (only the machine's user widens it, with the CLI).
|
|
21
|
+
*/
|
|
22
|
+
export type DeviceRemoteGrants = "owner" | "off";
|
|
23
|
+
/** What the kernel knows of a device's local policy (from the hello or a `policy` op). */
|
|
24
|
+
export interface DeviceLocalPolicySummary {
|
|
25
|
+
/** The tier the device owner chose; absent = follows the org's default. */
|
|
26
|
+
tier?: SandboxTier;
|
|
27
|
+
/** The tier the device ran its last command at (its choice cut to the org's ceiling). */
|
|
28
|
+
effectiveTier: SandboxTier;
|
|
29
|
+
/** `none` = the device runs commands without a sandbox (only with tier `open`, OS mode). */
|
|
30
|
+
isolation: "sandbox" | "none";
|
|
31
|
+
/** Whether sandboxed commands may bind and reach localhost on this machine. */
|
|
32
|
+
localhost: "on" | "off-proxy-detected" | "off";
|
|
33
|
+
/** Unix socket access: within the roots, every socket masked, or none. */
|
|
34
|
+
unixSockets: "roots" | "all-masked" | "off";
|
|
35
|
+
allowedDomains: string[];
|
|
36
|
+
remoteGrants: DeviceRemoteGrants;
|
|
37
|
+
}
|
|
38
|
+
/** The most blocked hosts an exec result reports; the parser cuts longer lists. */
|
|
39
|
+
export declare const MAX_NETWORK_BLOCKED_HOSTS = 20;
|
|
10
40
|
/** First frame from the device after the WebSocket opens. */
|
|
11
41
|
export interface DeviceHello {
|
|
12
42
|
type: "hello";
|
|
@@ -17,6 +47,10 @@ export interface DeviceHello {
|
|
|
17
47
|
mode: "os" | "docker";
|
|
18
48
|
roots: SandboxRoots;
|
|
19
49
|
sessionIsolation: boolean;
|
|
50
|
+
/** Optional capabilities (absent on older devices; unknown entries are dropped by the parser). */
|
|
51
|
+
features?: DeviceFeature[];
|
|
52
|
+
/** The device's local policy at connect time (absent on older devices). */
|
|
53
|
+
policy?: DeviceLocalPolicySummary;
|
|
20
54
|
}
|
|
21
55
|
/** Error kinds a device reports for a failed request. */
|
|
22
56
|
export type DeviceErrorKind = "gone" | "fs_gone" | "policy" | "error";
|
|
@@ -58,6 +92,21 @@ export interface DeviceExecArgs {
|
|
|
58
92
|
tag: string;
|
|
59
93
|
actor: SandboxActor;
|
|
60
94
|
limits: SandboxLimits;
|
|
95
|
+
/**
|
|
96
|
+
* Hosts the kernel allows for this command beyond the local policy (a run's 「这次允许」 or a
|
|
97
|
+
* scheduled task's grants). A device applies them only when its `remoteGrants` is `owner` and
|
|
98
|
+
* only within `limits`; a device without the feature ignores the field.
|
|
99
|
+
*/
|
|
100
|
+
grants?: DeviceExecGrants;
|
|
101
|
+
}
|
|
102
|
+
/** Extra hosts for one exec and where they come from (logged by the device with the command). */
|
|
103
|
+
export interface DeviceExecGrants {
|
|
104
|
+
hosts: string[];
|
|
105
|
+
source: {
|
|
106
|
+
kind: "run" | "task";
|
|
107
|
+
id: string;
|
|
108
|
+
accountId: string;
|
|
109
|
+
};
|
|
61
110
|
}
|
|
62
111
|
export type DeviceExecResult = ExecResult;
|
|
63
112
|
export interface DeviceReadFileArgs {
|
|
@@ -93,6 +142,32 @@ export interface DeviceCreateResult {
|
|
|
93
142
|
export interface DeviceStopArgs {
|
|
94
143
|
reason: "revoked" | "deleted";
|
|
95
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Edits the device's local policy. The device refuses widening (`add`, a higher `tier`) unless
|
|
147
|
+
* its `remoteGrants` is `owner`; narrowing is always accepted. `isolation` may only turn the
|
|
148
|
+
* sandbox back on: turning it off is decided on the machine.
|
|
149
|
+
*/
|
|
150
|
+
export interface DevicePolicyArgs {
|
|
151
|
+
/** Hosts to add to `allowedDomains`. */
|
|
152
|
+
add?: string[];
|
|
153
|
+
/** Hosts to remove from `allowedDomains`. */
|
|
154
|
+
remove?: string[];
|
|
155
|
+
/** The device's tier; null = follow the org's default. */
|
|
156
|
+
tier?: SandboxTier | null;
|
|
157
|
+
/** Only `sandbox`: the kernel never turns the sandbox off. */
|
|
158
|
+
isolation?: "sandbox";
|
|
159
|
+
/** Who decided, for the device's local audit line. */
|
|
160
|
+
source: {
|
|
161
|
+
approvalId?: string;
|
|
162
|
+
accountId: string;
|
|
163
|
+
accountName: string;
|
|
164
|
+
via: "web" | "im";
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/** The policy as the device wrote it. */
|
|
168
|
+
export interface DevicePolicyResult {
|
|
169
|
+
policy: DeviceLocalPolicySummary;
|
|
170
|
+
}
|
|
96
171
|
/** A frame that is not valid protocol v1 (or came from the wrong side). */
|
|
97
172
|
export declare class DeviceProtocolError extends Error {
|
|
98
173
|
constructor(message: string);
|
|
@@ -107,6 +182,7 @@ export interface DeviceOpResults {
|
|
|
107
182
|
killTagged: null;
|
|
108
183
|
killAll: null;
|
|
109
184
|
stop: null;
|
|
185
|
+
policy: DevicePolicyResult;
|
|
110
186
|
}
|
|
111
187
|
/** Validates the `result` of a successful `res` for `op`; throws {@link DeviceProtocolError}. */
|
|
112
188
|
export declare function parseOpResult<Op extends DeviceOp>(op: Op, result: unknown): DeviceOpResults[Op];
|
package/dist/device-protocol.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Device protocol v1: 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
|
-
import { validateSandboxPathShape, } from "./sandbox.js";
|
|
5
|
+
import { isSandboxTier, validateAllowHost, validateSandboxPathShape, } from "./sandbox.js";
|
|
6
6
|
/** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
|
|
7
7
|
export const DEVICE_PROTOCOL_VERSION = 1;
|
|
8
8
|
const DEVICE_OPS = [
|
|
@@ -14,7 +14,13 @@ const DEVICE_OPS = [
|
|
|
14
14
|
"killTagged",
|
|
15
15
|
"killAll",
|
|
16
16
|
"stop",
|
|
17
|
+
"policy",
|
|
17
18
|
];
|
|
19
|
+
const DEVICE_FEATURES = ["networkReport", "policyOp", "tiers"];
|
|
20
|
+
/** The most blocked hosts an exec result reports; the parser cuts longer lists. */
|
|
21
|
+
export const MAX_NETWORK_BLOCKED_HOSTS = 20;
|
|
22
|
+
/** The most hosts a `policy` op's `add` / `remove` or an exec's `grants` may carry. */
|
|
23
|
+
const MAX_POLICY_HOSTS = 100;
|
|
18
24
|
/** A frame that is not valid protocol v1 (or came from the wrong side). */
|
|
19
25
|
export class DeviceProtocolError extends Error {
|
|
20
26
|
constructor(message) {
|
|
@@ -68,13 +74,40 @@ function parseLimits(v) {
|
|
|
68
74
|
if (egress !== "none" && egress !== "allowlist" && egress !== "open") {
|
|
69
75
|
throw new DeviceProtocolError(`unknown egress "${egress}"`);
|
|
70
76
|
}
|
|
71
|
-
|
|
77
|
+
const devHosts = strArray(o, "devHosts");
|
|
78
|
+
for (const h of devHosts) {
|
|
79
|
+
const problems = validateAllowHost(h);
|
|
80
|
+
if (problems.length > 0) {
|
|
81
|
+
throw new DeviceProtocolError(`invalid dev host "${h}": ${problems.join("; ")}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const out = {
|
|
72
85
|
cpu: num(o, "cpu"),
|
|
73
86
|
memoryMb: num(o, "memoryMb"),
|
|
74
87
|
diskMb: num(o, "diskMb"),
|
|
75
88
|
egress,
|
|
76
89
|
allowHosts: strArray(o, "allowHosts"),
|
|
90
|
+
tier: parseTier(o, "tier"),
|
|
91
|
+
devHosts,
|
|
77
92
|
};
|
|
93
|
+
if (o.defaultTier !== undefined)
|
|
94
|
+
out.defaultTier = parseTier(o, "defaultTier");
|
|
95
|
+
if (o.allowUnsandboxed !== undefined)
|
|
96
|
+
out.allowUnsandboxed = bool(o, "allowUnsandboxed");
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
function parseTier(o, k) {
|
|
100
|
+
const v = str(o, k);
|
|
101
|
+
if (!isSandboxTier(v))
|
|
102
|
+
throw new DeviceProtocolError(`unknown tier "${v}"`);
|
|
103
|
+
return v;
|
|
104
|
+
}
|
|
105
|
+
function oneOf(o, k, values) {
|
|
106
|
+
const v = str(o, k);
|
|
107
|
+
if (!values.includes(v)) {
|
|
108
|
+
throw new DeviceProtocolError(`unknown ${k} "${v}"`);
|
|
109
|
+
}
|
|
110
|
+
return v;
|
|
78
111
|
}
|
|
79
112
|
function num(o, k) {
|
|
80
113
|
const v = o[k];
|
|
@@ -104,6 +137,75 @@ function parseRoots(v) {
|
|
|
104
137
|
}
|
|
105
138
|
return roots;
|
|
106
139
|
}
|
|
140
|
+
function hostArray(o, k) {
|
|
141
|
+
const v = strArray(o, k);
|
|
142
|
+
if (v.length > MAX_POLICY_HOSTS) {
|
|
143
|
+
throw new DeviceProtocolError(`field "${k}" must have at most ${MAX_POLICY_HOSTS} entries`);
|
|
144
|
+
}
|
|
145
|
+
return v;
|
|
146
|
+
}
|
|
147
|
+
function parsePolicySummary(v) {
|
|
148
|
+
const o = obj(v, 'field "policy"');
|
|
149
|
+
const remoteGrants = str(o, "remoteGrants");
|
|
150
|
+
if (remoteGrants !== "owner" && remoteGrants !== "off") {
|
|
151
|
+
throw new DeviceProtocolError(`unknown remoteGrants "${remoteGrants}"`);
|
|
152
|
+
}
|
|
153
|
+
const out = {
|
|
154
|
+
effectiveTier: parseTier(o, "effectiveTier"),
|
|
155
|
+
isolation: oneOf(o, "isolation", ["sandbox", "none"]),
|
|
156
|
+
localhost: oneOf(o, "localhost", ["on", "off-proxy-detected", "off"]),
|
|
157
|
+
unixSockets: oneOf(o, "unixSockets", ["roots", "all-masked", "off"]),
|
|
158
|
+
allowedDomains: strArray(o, "allowedDomains"),
|
|
159
|
+
remoteGrants,
|
|
160
|
+
};
|
|
161
|
+
if (o.tier !== undefined)
|
|
162
|
+
out.tier = parseTier(o, "tier");
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
/** Optional hello fields: malformed values are ignored so old and new peers interoperate. */
|
|
166
|
+
function optionalHelloFields(o) {
|
|
167
|
+
const out = {};
|
|
168
|
+
if (Array.isArray(o.features)) {
|
|
169
|
+
out.features = DEVICE_FEATURES.filter((f) => o.features.includes(f));
|
|
170
|
+
}
|
|
171
|
+
if (o.policy !== undefined) {
|
|
172
|
+
try {
|
|
173
|
+
out.policy = parsePolicySummary(o.policy);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// an unreadable summary is the same as none: the kernel learns the policy later
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
const BLOCK_LAYERS = ["device", "org", "address", "unknown"];
|
|
182
|
+
/**
|
|
183
|
+
* The valid entries of an exec result's `network.blocked`: a host that fails
|
|
184
|
+
* {@link validateAllowHost} is kept only with layer `address`; anything malformed is dropped;
|
|
185
|
+
* at most {@link MAX_NETWORK_BLOCKED_HOSTS}. Undefined when the field is not a report at all.
|
|
186
|
+
*/
|
|
187
|
+
function parseNetworkReport(v) {
|
|
188
|
+
if (!isRecord(v) || !Array.isArray(v.blocked))
|
|
189
|
+
return undefined;
|
|
190
|
+
const blocked = [];
|
|
191
|
+
for (const e of v.blocked) {
|
|
192
|
+
if (blocked.length >= MAX_NETWORK_BLOCKED_HOSTS)
|
|
193
|
+
break;
|
|
194
|
+
if (!isRecord(e))
|
|
195
|
+
continue;
|
|
196
|
+
const { host, port, layer } = e;
|
|
197
|
+
if (typeof host !== "string" || host === "" || host.length > 255)
|
|
198
|
+
continue;
|
|
199
|
+
if (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)
|
|
200
|
+
continue;
|
|
201
|
+
if (!BLOCK_LAYERS.includes(layer))
|
|
202
|
+
continue;
|
|
203
|
+
if (layer !== "address" && validateAllowHost(host).length > 0)
|
|
204
|
+
continue;
|
|
205
|
+
blocked.push({ host, port, layer: layer });
|
|
206
|
+
}
|
|
207
|
+
return { blocked };
|
|
208
|
+
}
|
|
107
209
|
function parseHello(o) {
|
|
108
210
|
const os = str(o, "os");
|
|
109
211
|
if (os !== "darwin" && os !== "linux")
|
|
@@ -124,6 +226,7 @@ function parseHello(o) {
|
|
|
124
226
|
mode,
|
|
125
227
|
roots: parseRoots(o.roots),
|
|
126
228
|
sessionIsolation: o.sessionIsolation,
|
|
229
|
+
...optionalHelloFields(o),
|
|
127
230
|
};
|
|
128
231
|
}
|
|
129
232
|
function parseRes(o) {
|
|
@@ -165,7 +268,20 @@ function validateArgs(op, a) {
|
|
|
165
268
|
const actor = obj(a.actor, 'field "actor"');
|
|
166
269
|
str(actor, "accountId");
|
|
167
270
|
str(actor, "conversationId");
|
|
271
|
+
if (actor.runId !== undefined)
|
|
272
|
+
str(actor, "runId");
|
|
168
273
|
parseLimits(a.limits);
|
|
274
|
+
if (a.grants !== undefined) {
|
|
275
|
+
const g = obj(a.grants, 'field "grants"');
|
|
276
|
+
hostArray(g, "hosts");
|
|
277
|
+
const src = obj(g.source, 'field "grants.source"');
|
|
278
|
+
const kind = str(src, "kind");
|
|
279
|
+
if (kind !== "run" && kind !== "task") {
|
|
280
|
+
throw new DeviceProtocolError(`unknown grant source kind "${kind}"`);
|
|
281
|
+
}
|
|
282
|
+
nonEmptyStr(src, "id");
|
|
283
|
+
nonEmptyStr(src, "accountId");
|
|
284
|
+
}
|
|
169
285
|
if (a.cwd !== undefined)
|
|
170
286
|
str(a, "cwd");
|
|
171
287
|
if (a.env !== undefined) {
|
|
@@ -205,6 +321,26 @@ function validateArgs(op, a) {
|
|
|
205
321
|
}
|
|
206
322
|
return;
|
|
207
323
|
}
|
|
324
|
+
case "policy": {
|
|
325
|
+
if (a.add !== undefined)
|
|
326
|
+
hostArray(a, "add");
|
|
327
|
+
if (a.remove !== undefined)
|
|
328
|
+
hostArray(a, "remove");
|
|
329
|
+
if (a.tier !== undefined && a.tier !== null)
|
|
330
|
+
parseTier(a, "tier");
|
|
331
|
+
if (a.isolation !== undefined && a.isolation !== "sandbox") {
|
|
332
|
+
throw new DeviceProtocolError('field "isolation" may only be "sandbox"');
|
|
333
|
+
}
|
|
334
|
+
const src = obj(a.source, 'field "source"');
|
|
335
|
+
nonEmptyStr(src, "accountId");
|
|
336
|
+
str(src, "accountName");
|
|
337
|
+
const via = str(src, "via");
|
|
338
|
+
if (via !== "web" && via !== "im")
|
|
339
|
+
throw new DeviceProtocolError(`unknown via "${via}"`);
|
|
340
|
+
if (src.approvalId !== undefined)
|
|
341
|
+
str(src, "approvalId");
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
208
344
|
}
|
|
209
345
|
}
|
|
210
346
|
export function parseOpResult(op, result) {
|
|
@@ -215,14 +351,21 @@ export function parseOpResult(op, result) {
|
|
|
215
351
|
if (exitCode !== null && (typeof exitCode !== "number" || !Number.isFinite(exitCode))) {
|
|
216
352
|
throw new DeviceProtocolError('field "exitCode" must be a number or null');
|
|
217
353
|
}
|
|
218
|
-
|
|
354
|
+
const out = {
|
|
219
355
|
exitCode: exitCode,
|
|
220
356
|
stdout: str(r, "stdout"),
|
|
221
357
|
stderr: str(r, "stderr"),
|
|
222
358
|
truncated: bool(r, "truncated"),
|
|
223
359
|
timedOut: bool(r, "timedOut"),
|
|
224
360
|
};
|
|
361
|
+
// an optional report: a malformed one is dropped, never failing the command's result
|
|
362
|
+
const network = parseNetworkReport(r.network);
|
|
363
|
+
if (network)
|
|
364
|
+
out.network = network;
|
|
365
|
+
return out;
|
|
225
366
|
}
|
|
367
|
+
case "policy":
|
|
368
|
+
return { policy: parsePolicySummary(obj(result, "policy result").policy) };
|
|
226
369
|
case "readFile": {
|
|
227
370
|
if (result === null)
|
|
228
371
|
return null;
|
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.16";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -10,6 +10,7 @@ export * from "./connector.js";
|
|
|
10
10
|
export * from "./connector-auth.js";
|
|
11
11
|
export * from "./ctx.js";
|
|
12
12
|
export * from "./define-extension.js";
|
|
13
|
+
export * from "./dev-hosts.js";
|
|
13
14
|
export * from "./device-protocol.js";
|
|
14
15
|
export * from "./directory.js";
|
|
15
16
|
export * from "./extension-point.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.16";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -10,6 +10,7 @@ export * from "./connector.js";
|
|
|
10
10
|
export * from "./connector-auth.js";
|
|
11
11
|
export * from "./ctx.js";
|
|
12
12
|
export * from "./define-extension.js";
|
|
13
|
+
export * from "./dev-hosts.js";
|
|
13
14
|
export * from "./device-protocol.js";
|
|
14
15
|
export * from "./directory.js";
|
|
15
16
|
export * from "./extension-point.js";
|
|
@@ -63,8 +63,6 @@ export interface PluginDependency {
|
|
|
63
63
|
/** A skill of the plugin: a `./…` directory holding SKILL.md. */
|
|
64
64
|
export interface PluginSkillRef {
|
|
65
65
|
path: string;
|
|
66
|
-
/** Suggested as pinned when an agent selects the skill (spec §9.1). */
|
|
67
|
-
pinned?: boolean;
|
|
68
66
|
}
|
|
69
67
|
/** A connector template of the plugin: a `./…/<id>.json` file ({@link ConnectorTemplateFile}). */
|
|
70
68
|
export interface PluginConnectorTemplateRef {
|
package/dist/plugin-manifest.js
CHANGED
|
@@ -194,7 +194,7 @@ const schema = z
|
|
|
194
194
|
.max(L.dependencies)
|
|
195
195
|
.optional(),
|
|
196
196
|
skills: z
|
|
197
|
-
.array(z.strictObject({ path: dotPath("path")
|
|
197
|
+
.array(z.strictObject({ path: dotPath("path") }))
|
|
198
198
|
.max(L.skills)
|
|
199
199
|
.optional(),
|
|
200
200
|
connectorTemplates: z
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -12,6 +12,22 @@
|
|
|
12
12
|
export declare const SANDBOX_EXTENSION_POINT = "sandbox@2";
|
|
13
13
|
/** The roots inside the sandbox the model may access. */
|
|
14
14
|
export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
|
|
15
|
+
/**
|
|
16
|
+
* A sandbox tier, ordered `strict` < `dev` < `open`: how much a device's commands may reach.
|
|
17
|
+
* `strict` is the org's allowlist only; `dev` adds the dev hosts (`DEV_HOSTS`) and local
|
|
18
|
+
* development affordances; `open` reaches any public host.
|
|
19
|
+
*/
|
|
20
|
+
export type SandboxTier = "strict" | "dev" | "open";
|
|
21
|
+
/** Every tier, lowest first. */
|
|
22
|
+
export declare const SANDBOX_TIERS: readonly SandboxTier[];
|
|
23
|
+
/** Whether `v` is a {@link SandboxTier}. */
|
|
24
|
+
export declare function isSandboxTier(v: unknown): v is SandboxTier;
|
|
25
|
+
/** Negative when `a` is lower than `b`, 0 when equal, positive when higher. */
|
|
26
|
+
export declare function compareTiers(a: SandboxTier, b: SandboxTier): number;
|
|
27
|
+
/** Whether `a` is at most `b`. */
|
|
28
|
+
export declare function tierAtMost(a: SandboxTier, b: SandboxTier): boolean;
|
|
29
|
+
/** The lowest of the given tiers. */
|
|
30
|
+
export declare function minTier(first: SandboxTier, ...rest: SandboxTier[]): SandboxTier;
|
|
15
31
|
/** Sandbox resource and egress limits. */
|
|
16
32
|
export interface SandboxLimits {
|
|
17
33
|
cpu: number;
|
|
@@ -20,7 +36,29 @@ export interface SandboxLimits {
|
|
|
20
36
|
egress: "none" | "allowlist" | "open";
|
|
21
37
|
/** Egress allowlist (used when `egress` is `allowlist`); each entry passes {@link validateAllowHost}. */
|
|
22
38
|
allowHosts: string[];
|
|
39
|
+
/**
|
|
40
|
+
* The effective tier (cloud `create`) or the ceiling the device may reach (local exec args). A
|
|
41
|
+
* provider that ignores it behaves as `strict` plus whatever `egress` says.
|
|
42
|
+
*/
|
|
43
|
+
tier: SandboxTier;
|
|
44
|
+
/** Local exec args only: the org's default tier, used when the device chose none. */
|
|
45
|
+
defaultTier?: SandboxTier;
|
|
46
|
+
/**
|
|
47
|
+
* Local exec args only: whether this command may run without a sandbox (the platform and the
|
|
48
|
+
* org allow it, the ceiling is `open`, and an unattended run has the `tier:open` grant). A device
|
|
49
|
+
* whose local policy asks for no sandbox refuses the command unless this is `true` (absent counts
|
|
50
|
+
* as `false`), with {@link UNSANDBOXED_NOT_ALLOWED_MESSAGE}.
|
|
51
|
+
*/
|
|
52
|
+
allowUnsandboxed?: boolean;
|
|
53
|
+
/** The dev hosts preset; cloud providers ignore it (`allowHosts` is final for them). */
|
|
54
|
+
devHosts: string[];
|
|
23
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The refusal of a command that would run without a sandbox where the org does not allow it
|
|
58
|
+
* (sandbox dev tiers spec §4.3): the kernel's `device.unsandboxed_not_allowed` text, and the
|
|
59
|
+
* message a device sends with a `policy` error when `allowUnsandboxed` is not `true`.
|
|
60
|
+
*/
|
|
61
|
+
export declare const UNSANDBOXED_NOT_ALLOWED_MESSAGE = "This device runs commands without a sandbox, which your organization does not allow. Its owner can turn the sandbox back on with `capybara-device policy set isolation sandbox`.";
|
|
24
62
|
/** The absolute roots inside one instance (a device may place them anywhere on its host). */
|
|
25
63
|
export interface SandboxRoots {
|
|
26
64
|
workspace: string;
|
|
@@ -47,6 +85,24 @@ export interface FileSystemHandle {
|
|
|
47
85
|
export interface SandboxActor {
|
|
48
86
|
accountId: string;
|
|
49
87
|
conversationId: string;
|
|
88
|
+
/**
|
|
89
|
+
* The run the command serves. The kernel uses it to route run grants (network hosts allowed
|
|
90
|
+
* for the rest of a run) to a connected device; informational for other providers.
|
|
91
|
+
*/
|
|
92
|
+
runId?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The layer that refused a network host: `device` (the org allows it, the device's local policy
|
|
96
|
+
* does not), `org` (not in the org's effective egress), `address` (an IP literal or a name that
|
|
97
|
+
* points to a private or local address; never grantable), `unknown`.
|
|
98
|
+
*/
|
|
99
|
+
export type NetworkBlockLayer = "device" | "org" | "address" | "unknown";
|
|
100
|
+
/** A host a command was refused, as the provider reports it. */
|
|
101
|
+
export interface NetworkBlockedHost {
|
|
102
|
+
/** The host as the proxy saw it (IPv6 literals bracketed). */
|
|
103
|
+
host: string;
|
|
104
|
+
port: number;
|
|
105
|
+
layer: NetworkBlockLayer;
|
|
50
106
|
}
|
|
51
107
|
/** Result of a command. */
|
|
52
108
|
export interface ExecResult {
|
|
@@ -56,6 +112,14 @@ export interface ExecResult {
|
|
|
56
112
|
stderr: string;
|
|
57
113
|
truncated: boolean;
|
|
58
114
|
timedOut: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Network refusals during the command (optional for every provider): at most
|
|
117
|
+
* `MAX_NETWORK_BLOCKED_HOSTS` hosts, deduped by host. The kernel recomputes the `org` layer
|
|
118
|
+
* itself and never trusts a provider's word that the org allows a host.
|
|
119
|
+
*/
|
|
120
|
+
network?: {
|
|
121
|
+
blocked: NetworkBlockedHost[];
|
|
122
|
+
};
|
|
59
123
|
}
|
|
60
124
|
/**
|
|
61
125
|
* The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
|
|
@@ -139,6 +203,17 @@ export interface SandboxProvider {
|
|
|
139
203
|
* instance (a declared capability; absent means false).
|
|
140
204
|
*/
|
|
141
205
|
readonly sessionIsolation?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Where `create`-time limits are fixed: `instance` (absent; Docker: a new instance applies new
|
|
208
|
+
* limits) or `fileSystem` (E2B: the instance is the file system, so only a file reset applies
|
|
209
|
+
* them without {@link SandboxProvider.update}).
|
|
210
|
+
*/
|
|
211
|
+
readonly limitsApplyAt?: "instance" | "fileSystem";
|
|
212
|
+
/**
|
|
213
|
+
* Applies new limits to a running instance without recreating it (optional). `recreate` asks
|
|
214
|
+
* the kernel to destroy the instance and create one on the same files instead.
|
|
215
|
+
*/
|
|
216
|
+
update?(h: SandboxHandle, limits: SandboxLimits, signal: AbortSignal): Promise<"updated" | "recreate">;
|
|
142
217
|
/**
|
|
143
218
|
* Creates a device's file system. `name` looks like `cap-device-<deviceId>`. If a file
|
|
144
219
|
* system with this name already exists, return it.
|
package/dist/sandbox.js
CHANGED
|
@@ -13,6 +13,34 @@ export const SANDBOX_EXTENSION_POINT = "sandbox@2";
|
|
|
13
13
|
/** The roots inside the sandbox the model may access. */
|
|
14
14
|
export const SANDBOX_ROOTS = ["/workspace", "/skills", "/tmp"];
|
|
15
15
|
const MAX_PATH_LENGTH = 4096;
|
|
16
|
+
/** Every tier, lowest first. */
|
|
17
|
+
export const SANDBOX_TIERS = Object.freeze(["strict", "dev", "open"]);
|
|
18
|
+
/** Whether `v` is a {@link SandboxTier}. */
|
|
19
|
+
export function isSandboxTier(v) {
|
|
20
|
+
return typeof v === "string" && SANDBOX_TIERS.includes(v);
|
|
21
|
+
}
|
|
22
|
+
/** Negative when `a` is lower than `b`, 0 when equal, positive when higher. */
|
|
23
|
+
export function compareTiers(a, b) {
|
|
24
|
+
return SANDBOX_TIERS.indexOf(a) - SANDBOX_TIERS.indexOf(b);
|
|
25
|
+
}
|
|
26
|
+
/** Whether `a` is at most `b`. */
|
|
27
|
+
export function tierAtMost(a, b) {
|
|
28
|
+
return compareTiers(a, b) <= 0;
|
|
29
|
+
}
|
|
30
|
+
/** The lowest of the given tiers. */
|
|
31
|
+
export function minTier(first, ...rest) {
|
|
32
|
+
let out = first;
|
|
33
|
+
for (const t of rest)
|
|
34
|
+
if (compareTiers(t, out) < 0)
|
|
35
|
+
out = t;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The refusal of a command that would run without a sandbox where the org does not allow it
|
|
40
|
+
* (sandbox dev tiers spec §4.3): the kernel's `device.unsandboxed_not_allowed` text, and the
|
|
41
|
+
* message a device sends with a `policy` error when `allowUnsandboxed` is not `true`.
|
|
42
|
+
*/
|
|
43
|
+
export const UNSANDBOXED_NOT_ALLOWED_MESSAGE = "This device runs commands without a sandbox, which your organization does not allow. Its owner can turn the sandbox back on with `capybara-device policy set isolation sandbox`.";
|
|
16
44
|
/** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
|
|
17
45
|
export const DEFAULT_SANDBOX_ROOTS = Object.freeze({
|
|
18
46
|
workspace: "/workspace",
|
package/package.json
CHANGED