@capybara-hq/plugin-sdk 0.1.0-rc.21 → 0.1.0-rc.22

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.
@@ -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 { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots, type SandboxTier } from "./sandbox.js";
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
7
  export declare const DEVICE_PROTOCOL_VERSION = 1;
8
8
  /** The operations the kernel asks a device to run. */
@@ -11,30 +11,16 @@ export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "
11
11
  * Optional capabilities a device announces in its hello. `policyOp`: the device takes the `policy`
12
12
  * op; `policyOpId`: it also logs each `policy` op's outcome by its `opId`, answers `policyStatus`
13
13
  * and reports recent outcomes in its hello (`recentOps`); `networkReport` means exec results may
14
- * carry `network`; `tiers` means the device applies `limits.tier` / `defaultTier` / `devHosts`
15
- * (without it the device behaves as `strict`).
14
+ * carry `network`; `mode` means the device applies `limits.mode` / `limits.network` (without it
15
+ * the device behaves as an allowlisted sandbox).
16
16
  */
17
- export type DeviceFeature = "networkReport" | "policyOp" | "policyOpId" | "tiers";
18
- /**
19
- * Whether the device accepts widening its local policy from the kernel (the `policy` op's `add`
20
- * and a higher `tier`, run and task grants): `owner` (default, decided by the device owner in a
21
- * signed-in session) or `off` (only the machine's user widens it, with the CLI).
22
- */
23
- export type DeviceRemoteGrants = "owner" | "off";
17
+ export type DeviceFeature = "networkReport" | "policyOp" | "policyOpId" | "mode";
24
18
  /** What the kernel knows of a device's local policy (from the hello or a `policy` op). */
25
19
  export interface DeviceLocalPolicySummary {
26
- /** The tier the device owner chose; absent = follows the org's default. */
27
- tier?: SandboxTier;
28
- /** The tier the device ran its last command at (its choice cut to the org's ceiling). */
29
- effectiveTier: SandboxTier;
30
- /** `none` = the device runs commands without a sandbox (only with tier `open`, OS mode). */
31
- isolation: "sandbox" | "none";
32
- /** Whether sandboxed commands may bind and reach localhost on this machine. */
33
- localhost: "on" | "off-proxy-detected" | "off";
34
- /** Unix socket access: within the roots, every socket masked, or none. */
35
- unixSockets: "roots" | "all-masked" | "off";
20
+ /** `auto` = no OS sandbox (the owner's machine); `sandbox` = the OS sandbox. */
21
+ mode: "auto" | "sandbox";
22
+ /** The device's sandbox-mode allowlist; meaningful in sandbox mode only. */
36
23
  allowedDomains: string[];
37
- remoteGrants: DeviceRemoteGrants;
38
24
  }
39
25
  /**
40
26
  * The first line of the kernel's background task launch command (`Bash` `run_in_background`), a
@@ -112,10 +98,10 @@ export interface KernelCancel {
112
98
  id: string;
113
99
  }
114
100
  /**
115
- * The device's local policy changed while connected (its file was edited on the machine, the
116
- * localhost proxy guard flipped, a new tier ceiling): the summary as it is now, sent only when it
117
- * differs from the last one sent on this connection. `policy` is absent when the frame's summary
118
- * was unreadable; the kernel then keeps only its isolation, from the raw frame, as for the hello.
101
+ * The device's local policy changed while connected (its file was edited on the machine, the owner
102
+ * switched mode): the summary as it is now, sent only when it differs from the last one sent on
103
+ * this connection. `policy` is absent when the frame's summary was unreadable; the kernel then
104
+ * learns the policy later, as for the hello.
119
105
  */
120
106
  export interface DevicePolicyChanged {
121
107
  type: "policy";
@@ -133,8 +119,8 @@ export interface DeviceExecArgs {
133
119
  limits: SandboxLimits;
134
120
  /**
135
121
  * Hosts the kernel allows for this command beyond the local policy (a run's 「这次允许」 or a
136
- * scheduled task's grants). A device applies them only when its `remoteGrants` is `owner` and
137
- * only within `limits`; a device without the feature ignores the field.
122
+ * scheduled task's grants). A device applies them only in sandbox mode, within `limits`; a
123
+ * device without the feature ignores the field.
138
124
  */
139
125
  grants?: DeviceExecGrants;
140
126
  }
@@ -182,9 +168,9 @@ export interface DeviceStopArgs {
182
168
  reason: "revoked" | "deleted";
183
169
  }
184
170
  /**
185
- * Edits the device's local policy. The device refuses widening (`add`, a higher `tier`) unless
186
- * its `remoteGrants` is `owner`; narrowing is always accepted. `isolation` may only turn the
187
- * sandbox back on: turning it off is decided on the machine.
171
+ * Edits the device's local policy. The kernel may only narrow: `mode` may turn the sandbox back on
172
+ * (`"sandbox"`), never off (turning auto mode on is decided on the machine), and `add` extends the
173
+ * sandbox-mode allowlist only. Narrowing is always accepted.
188
174
  */
189
175
  export interface DevicePolicyArgs {
190
176
  /**
@@ -197,10 +183,8 @@ export interface DevicePolicyArgs {
197
183
  add?: string[];
198
184
  /** Hosts to remove from `allowedDomains`. */
199
185
  remove?: string[];
200
- /** The device's tier; null = follow the org's default. */
201
- tier?: SandboxTier | null;
202
- /** Only `sandbox`: the kernel never turns the sandbox off. */
203
- isolation?: "sandbox";
186
+ /** Only `"sandbox"`: the kernel may narrow, never turn auto mode on. */
187
+ mode?: "sandbox";
204
188
  /** Who decided, for the device's local audit line. */
205
189
  source: {
206
190
  approvalId?: string;
@@ -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 { isSandboxTier, validateAllowHost, validateSandboxPathShape, } from "./sandbox.js";
5
+ import { 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 = [
@@ -21,7 +21,7 @@ const DEVICE_FEATURES = [
21
21
  "networkReport",
22
22
  "policyOp",
23
23
  "policyOpId",
24
- "tiers",
24
+ "mode",
25
25
  ];
26
26
  /**
27
27
  * The first line of the kernel's background task launch command (`Bash` `run_in_background`), a
@@ -81,46 +81,31 @@ function bool(o, k) {
81
81
  throw new DeviceProtocolError(`field "${k}" must be a boolean`);
82
82
  return v;
83
83
  }
84
- function strArray(o, k) {
84
+ function strArray(o, k, label = k) {
85
85
  const v = o[k];
86
86
  if (!Array.isArray(v) || v.some((x) => typeof x !== "string")) {
87
- throw new DeviceProtocolError(`field "${k}" must be an array of strings`);
87
+ throw new DeviceProtocolError(`field "${label}" must be an array of strings`);
88
88
  }
89
89
  return v;
90
90
  }
91
91
  function parseLimits(v) {
92
92
  const o = obj(v, 'field "limits"');
93
- const egress = str(o, "egress");
94
- if (egress !== "none" && egress !== "allowlist" && egress !== "open") {
95
- throw new DeviceProtocolError(`unknown egress "${egress}"`);
96
- }
97
- const devHosts = strArray(o, "devHosts");
98
- for (const h of devHosts) {
93
+ const network = obj(o.network, 'field "network"');
94
+ const kind = oneOf(network, "kind", ["open-public", "allowlist"]);
95
+ const hosts = strArray(network, "hosts", "network.hosts");
96
+ for (const h of hosts) {
99
97
  const problems = validateAllowHost(h);
100
98
  if (problems.length > 0) {
101
- throw new DeviceProtocolError(`invalid dev host "${h}": ${problems.join("; ")}`);
99
+ throw new DeviceProtocolError(`invalid network host "${h}": ${problems.join("; ")}`);
102
100
  }
103
101
  }
104
- const out = {
102
+ return {
105
103
  cpu: num(o, "cpu"),
106
104
  memoryMb: num(o, "memoryMb"),
107
105
  diskMb: num(o, "diskMb"),
108
- egress,
109
- allowHosts: strArray(o, "allowHosts"),
110
- tier: parseTier(o, "tier"),
111
- devHosts,
106
+ mode: oneOf(o, "mode", ["auto", "sandbox"]),
107
+ network: { kind, hosts },
112
108
  };
113
- if (o.defaultTier !== undefined)
114
- out.defaultTier = parseTier(o, "defaultTier");
115
- if (o.allowUnsandboxed !== undefined)
116
- out.allowUnsandboxed = bool(o, "allowUnsandboxed");
117
- return out;
118
- }
119
- function parseTier(o, k) {
120
- const v = str(o, k);
121
- if (!isSandboxTier(v))
122
- throw new DeviceProtocolError(`unknown tier "${v}"`);
123
- return v;
124
109
  }
125
110
  function oneOf(o, k, values) {
126
111
  const v = str(o, k);
@@ -166,21 +151,10 @@ function hostArray(o, k) {
166
151
  }
167
152
  function parsePolicySummary(v) {
168
153
  const o = obj(v, 'field "policy"');
169
- const remoteGrants = str(o, "remoteGrants");
170
- if (remoteGrants !== "owner" && remoteGrants !== "off") {
171
- throw new DeviceProtocolError(`unknown remoteGrants "${remoteGrants}"`);
172
- }
173
- const out = {
174
- effectiveTier: parseTier(o, "effectiveTier"),
175
- isolation: oneOf(o, "isolation", ["sandbox", "none"]),
176
- localhost: oneOf(o, "localhost", ["on", "off-proxy-detected", "off"]),
177
- unixSockets: oneOf(o, "unixSockets", ["roots", "all-masked", "off"]),
154
+ return {
155
+ mode: oneOf(o, "mode", ["auto", "sandbox"]),
178
156
  allowedDomains: strArray(o, "allowedDomains"),
179
- remoteGrants,
180
157
  };
181
- if (o.tier !== undefined)
182
- out.tier = parseTier(o, "tier");
183
- return out;
184
158
  }
185
159
  /**
186
160
  * Whether `v` is a valid policy op id: non-empty, no `:`, at most
@@ -385,10 +359,8 @@ function validateArgs(op, a) {
385
359
  hostArray(a, "add");
386
360
  if (a.remove !== undefined)
387
361
  hostArray(a, "remove");
388
- if (a.tier !== undefined && a.tier !== null)
389
- parseTier(a, "tier");
390
- if (a.isolation !== undefined && a.isolation !== "sandbox") {
391
- throw new DeviceProtocolError('field "isolation" may only be "sandbox"');
362
+ if (a.mode !== undefined && a.mode !== "sandbox") {
363
+ throw new DeviceProtocolError('field "mode" may only be "sandbox"');
392
364
  }
393
365
  const src = obj(a.source, 'field "source"');
394
366
  nonEmptyStr(src, "accountId");
package/dist/hooks.d.ts CHANGED
@@ -38,9 +38,10 @@ export interface HookScope {
38
38
  * that summarizes earlier history before a step when the context grows too large, `title` is the call
39
39
  * that writes a conversation's title after its first completed run (no run: `runId` is "", `step` 0,
40
40
  * `attempt` 1), `web_fetch` is the call that extracts an answer from a fetched web page for the
41
- * `WebFetch` tool.
41
+ * `WebFetch` tool, `review` is the command-review classifier's call (`review` purpose, no run
42
+ * step; absent = no classifier).
42
43
  */
43
- export type ModelCallPurpose = "step" | "compaction" | "title" | "web_fetch";
44
+ export type ModelCallPurpose = "step" | "compaction" | "title" | "web_fetch" | "review";
44
45
  /**
45
46
  * What a reported or requested model call was for: the {@link ModelCallPurpose} values, or
46
47
  * `embedding` for an embedding call an extension made through `ctx.models` (`usage.report`, and
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.21";
1
+ export declare const SDK_VERSION = "0.1.0-rc.22";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
@@ -11,7 +11,6 @@ export * from "./connector-auth.js";
11
11
  export * from "./context.js";
12
12
  export * from "./ctx.js";
13
13
  export * from "./define-extension.js";
14
- export * from "./dev-hosts.js";
15
14
  export * from "./device-protocol.js";
16
15
  export * from "./directory.js";
17
16
  export * from "./extension-point.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.21";
1
+ export const SDK_VERSION = "0.1.0-rc.22";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
@@ -11,7 +11,6 @@ export * from "./connector-auth.js";
11
11
  export * from "./context.js";
12
12
  export * from "./ctx.js";
13
13
  export * from "./define-extension.js";
14
- export * from "./dev-hosts.js";
15
14
  export * from "./device-protocol.js";
16
15
  export * from "./directory.js";
17
16
  export * from "./extension-point.js";
package/dist/sandbox.d.ts CHANGED
@@ -13,52 +13,28 @@ 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
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.
16
+ * Sandbox resource and network limits. A provider that ignores `mode` and `network` still runs:
17
+ * it then behaves as an allowlisted sandbox (the safe direction).
19
18
  */
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;
31
- /** Sandbox resource and egress limits. */
32
19
  export interface SandboxLimits {
33
20
  cpu: number;
34
21
  memoryMb: number;
35
22
  diskMb: number;
36
- egress: "none" | "allowlist" | "open";
37
- /** Egress allowlist (used when `egress` is `allowlist`); each entry passes {@link validateAllowHost}. */
38
- allowHosts: string[];
39
23
  /**
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.
24
+ * `auto`: no OS sandbox (local: the owner; cloud: the container is the boundary);
25
+ * `sandbox`: the OS sandbox with the network limited by {@link SandboxLimits.network}.
42
26
  */
43
- tier: SandboxTier;
44
- /** Local exec args only: the org's default tier, used when the device chose none. */
45
- defaultTier?: SandboxTier;
27
+ mode: "auto" | "sandbox";
46
28
  /**
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}.
29
+ * The network the instance (cloud) must enforce, or the allowlist a local device's sandbox mode
30
+ * intersects with its own list (`open-public` is for cloud instances only). Each entry of
31
+ * `hosts` passes {@link validateAllowHost}.
51
32
  */
52
- allowUnsandboxed?: boolean;
53
- /** The dev hosts preset; cloud providers ignore it (`allowHosts` is final for them). */
54
- devHosts: string[];
33
+ network: {
34
+ kind: "open-public" | "allowlist";
35
+ hosts: string[];
36
+ };
55
37
  }
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`.";
62
38
  /** The absolute roots inside one instance (a device may place them anywhere on its host). */
63
39
  export interface SandboxRoots {
64
40
  workspace: string;
package/dist/sandbox.js CHANGED
@@ -13,34 +13,6 @@ 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`.";
44
16
  /** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
45
17
  export const DEFAULT_SANDBOX_ROOTS = Object.freeze({
46
18
  workspace: "/workspace",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.21",
3
+ "version": "0.1.0-rc.22",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1,6 +0,0 @@
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[];
package/dist/dev-hosts.js DELETED
@@ -1,48 +0,0 @@
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 (`npx playwright install`, checked against playwright-core 1.64): Firefox,
43
- // WebKit and ffmpeg come from the Playwright CDN and its Microsoft mirror; Chromium is Chrome
44
- // for Testing, which cdn.playwright.dev redirects to storage.googleapis.com
45
- "cdn.playwright.dev",
46
- "playwright.download.prss.microsoft.com",
47
- "storage.googleapis.com",
48
- ]);