@capybara-hq/plugin-sdk 0.1.0-rc.20 → 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");
@@ -0,0 +1,44 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The git source of a connector: the git hosts a connector's credential may be used for, and the
4
+ * HTTP basic username to present for each (spec 2026-11-12-sandbox-git-credentials §6.1). Pure
5
+ * validation; the kernel reuses {@link GitSourceSchema} for its connector create body.
6
+ */
7
+ /** Limits of {@link GitSourceSchema}. */
8
+ export declare const GIT_HOSTS_LIMITS: {
9
+ /** Hosts per connector. */
10
+ readonly hosts: 8;
11
+ /** Characters of a username. */
12
+ readonly usernameChars: 64;
13
+ };
14
+ /**
15
+ * The basic-auth usernames of well-known git hosts: a GitHub token (a PAT or an app installation
16
+ * token) is presented with the fixed username `x-access-token`. Documentation for template authors;
17
+ * a connector still states its username explicitly.
18
+ */
19
+ export declare const GIT_HOST_USERNAMES: {
20
+ readonly "github.com": "x-access-token";
21
+ readonly "*.ghe.com": "x-access-token";
22
+ };
23
+ /** One git host and the username its credential is presented with. */
24
+ export interface GitHostEntry {
25
+ /** Lower-case hostname with no scheme, port, path, wildcard or userinfo. */
26
+ host: string;
27
+ /** HTTP basic username, `^[A-Za-z0-9._-]{1,64}$`. */
28
+ username: string;
29
+ }
30
+ /** The git source of a connector (`git` on a connector template and on a custom connector). */
31
+ export interface GitSource {
32
+ hosts: GitHostEntry[];
33
+ }
34
+ /**
35
+ * The zod schema of {@link GitSource} (strict objects, 1 to {@link GIT_HOSTS_LIMITS}`.hosts` hosts,
36
+ * no duplicate host). Error messages never echo the offending value.
37
+ */
38
+ export declare const GitSourceSchema: z.ZodType<GitSource>;
39
+ /** Validates a `git` value; returns problems as `<path>: <message>` (empty means valid). */
40
+ export declare function validateGitSource(git: unknown, at?: string): string[];
41
+ /** Parses a `git` value: the value, or `{ errors }`. */
42
+ export declare function parseGitSource(git: unknown): GitSource | {
43
+ errors: string[];
44
+ };
@@ -0,0 +1,81 @@
1
+ import { z } from "zod";
2
+ import { validateAllowHost } from "./sandbox.js";
3
+ /**
4
+ * The git source of a connector: the git hosts a connector's credential may be used for, and the
5
+ * HTTP basic username to present for each (spec 2026-11-12-sandbox-git-credentials §6.1). Pure
6
+ * validation; the kernel reuses {@link GitSourceSchema} for its connector create body.
7
+ */
8
+ /** Limits of {@link GitSourceSchema}. */
9
+ export const GIT_HOSTS_LIMITS = {
10
+ /** Hosts per connector. */
11
+ hosts: 8,
12
+ /** Characters of a username. */
13
+ usernameChars: 64,
14
+ };
15
+ /**
16
+ * The basic-auth usernames of well-known git hosts: a GitHub token (a PAT or an app installation
17
+ * token) is presented with the fixed username `x-access-token`. Documentation for template authors;
18
+ * a connector still states its username explicitly.
19
+ */
20
+ export const GIT_HOST_USERNAMES = {
21
+ "github.com": "x-access-token",
22
+ "*.ghe.com": "x-access-token",
23
+ };
24
+ const USERNAME_RE = /^[A-Za-z0-9._-]{1,64}$/;
25
+ /** Why a host is refused; never echoes the value (it may be a pasted credential or URL). */
26
+ function hostProblems(h) {
27
+ if (/[@:/?#\s]/.test(h))
28
+ return ["host must be a bare hostname (no userinfo, port or path)"];
29
+ if (h.includes("*"))
30
+ return ["host must not contain a wildcard"];
31
+ if (h !== h.toLowerCase())
32
+ return ["host must be lower-case"];
33
+ return validateAllowHost(h);
34
+ }
35
+ const GitHostEntrySchema = z.strictObject({
36
+ host: z
37
+ .string()
38
+ .max(253, "host must be at most 253 characters")
39
+ .superRefine((h, ctx) => {
40
+ for (const message of hostProblems(h))
41
+ ctx.addIssue({ code: "custom", message });
42
+ }),
43
+ username: z
44
+ .string()
45
+ .regex(USERNAME_RE, "username must match ^[A-Za-z0-9._-]{1,64}$ (letters, digits, '.', '_', '-')"),
46
+ });
47
+ /**
48
+ * The zod schema of {@link GitSource} (strict objects, 1 to {@link GIT_HOSTS_LIMITS}`.hosts` hosts,
49
+ * no duplicate host). Error messages never echo the offending value.
50
+ */
51
+ export const GitSourceSchema = z
52
+ .strictObject({
53
+ hosts: z
54
+ .array(GitHostEntrySchema)
55
+ .min(1, "hosts must not be empty")
56
+ .max(GIT_HOSTS_LIMITS.hosts),
57
+ })
58
+ .superRefine((g, ctx) => {
59
+ const seen = new Set();
60
+ g.hosts.forEach((e, i) => {
61
+ if (seen.has(e.host)) {
62
+ ctx.addIssue({ code: "custom", path: ["hosts", i, "host"], message: "duplicate host" });
63
+ }
64
+ seen.add(e.host);
65
+ });
66
+ });
67
+ /** Validates a `git` value; returns problems as `<path>: <message>` (empty means valid). */
68
+ export function validateGitSource(git, at = "git") {
69
+ const r = GitSourceSchema.safeParse(git);
70
+ if (r.success)
71
+ return [];
72
+ return r.error.issues.map((i) => {
73
+ const path = i.path.map(String).join(".");
74
+ return `${path === "" ? at : `${at}.${path}`}: ${i.message}`;
75
+ });
76
+ }
77
+ /** Parses a `git` value: the value, or `{ errors }`. */
78
+ export function parseGitSource(git) {
79
+ const errors = validateGitSource(git);
80
+ return errors.length > 0 ? { errors } : GitSourceSchema.parse(git);
81
+ }
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.20";
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,11 +11,11 @@ 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";
18
17
  export * from "./file-preview.js";
18
+ export * from "./git-hosts.js";
19
19
  export * from "./hooks.js";
20
20
  export * from "./identity.js";
21
21
  export * from "./marketplace.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.20";
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,11 +11,11 @@ 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";
18
17
  export * from "./file-preview.js";
18
+ export * from "./git-hosts.js";
19
19
  export * from "./hooks.js";
20
20
  export * from "./identity.js";
21
21
  export * from "./marketplace.js";
@@ -4,6 +4,7 @@ import { AGENT_TEMPLATE_LIMITS } from "./agent-template.js";
4
4
  import { validateClientSection } from "./client-section.js";
5
5
  import { CONFIG_UI_LIMITS } from "./config-ui.js";
6
6
  import { defineExtension, EXTENSION_NAME_RE } from "./define-extension.js";
7
+ import { GitSourceSchema } from "./git-hosts.js";
7
8
  import { CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, isSafePackagePath, SEMVER_VERSION_RE, validateConnectorTemplate, } from "./plugin-package.js";
8
9
  import { hasUpperBound } from "./semver-range.js";
9
10
  import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACES } from "./setup-guide.js";
@@ -418,6 +419,7 @@ const template = z.strictObject({
418
419
  auth: z.record(z.string(), z.unknown()),
419
420
  ownership: z.enum(["org", "personal"]).optional(),
420
421
  defaultToolPolicies: z.record(z.string(), z.enum(["allow", "ask", "deny"])).optional(),
422
+ git: GitSourceSchema.optional(),
421
423
  icon: z.string().max(L.pathChars).optional(),
422
424
  });
423
425
  const templateFile = z
@@ -1,4 +1,5 @@
1
1
  import { type ExtensionManifest } from "./define-extension.js";
2
+ import { type GitSource } from "./git-hosts.js";
2
3
  import type { ExtensionPermissions } from "./permissions.js";
3
4
  import type { PluginManifest } from "./plugin-manifest.js";
4
5
  /**
@@ -98,6 +99,8 @@ export interface ConnectorTemplateSpec {
98
99
  ownership?: "org" | "personal";
99
100
  /** 工具名 → 默认策略(安装后记 `policy_source 'template'`)。 */
100
101
  defaultToolPolicies?: Record<string, "allow" | "ask" | "deny">;
102
+ /** Git hosts this connector's credential serves in sandboxes ({@link GitSource}). */
103
+ git?: GitSource;
101
104
  /** 包内路径,svg / png,≤ {@link CONNECTOR_TEMPLATE_LIMITS}`.iconBytes`。 */
102
105
  icon?: string;
103
106
  }
@@ -1,6 +1,7 @@
1
1
  import semver from "semver";
2
2
  import { ConnectorAuthSchema } from "./connector-auth.js";
3
3
  import { EXTENSION_NAME_RE } from "./define-extension.js";
4
+ import { validateGitSource } from "./git-hosts.js";
4
5
  /**
5
6
  * Plugin package (npm-pack tgz) rules shared by the SDK, the packer and the kernel (spec §4.1). Pure
6
7
  * functions only: the kernel reads the tgz and scans imports, `packages/plugin-tools` packs it. The
@@ -333,6 +334,7 @@ const TEMPLATE_KEYS = new Set([
333
334
  "auth",
334
335
  "ownership",
335
336
  "defaultToolPolicies",
337
+ "git",
336
338
  "icon",
337
339
  ]);
338
340
  /**
@@ -439,6 +441,8 @@ export function validateConnectorTemplate(t) {
439
441
  }
440
442
  }
441
443
  }
444
+ if (t.git !== undefined)
445
+ errs.push(...validateGitSource(t.git, "template.git"));
442
446
  if (t.icon !== undefined) {
443
447
  if (typeof t.icon !== "string" || !isSafePackagePath(t.icon) || !/\.(svg|png)$/i.test(t.icon)) {
444
448
  errs.push("template.icon must be a relative .svg or .png path inside the package");
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.20",
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": {
@@ -97,6 +97,38 @@
97
97
  ]
98
98
  }
99
99
  },
100
+ "git": {
101
+ "type": "object",
102
+ "properties": {
103
+ "hosts": {
104
+ "minItems": 1,
105
+ "maxItems": 8,
106
+ "type": "array",
107
+ "items": {
108
+ "type": "object",
109
+ "properties": {
110
+ "host": {
111
+ "type": "string",
112
+ "maxLength": 253
113
+ },
114
+ "username": {
115
+ "type": "string",
116
+ "pattern": "^[A-Za-z0-9._-]{1,64}$"
117
+ }
118
+ },
119
+ "required": [
120
+ "host",
121
+ "username"
122
+ ],
123
+ "additionalProperties": false
124
+ }
125
+ }
126
+ },
127
+ "required": [
128
+ "hosts"
129
+ ],
130
+ "additionalProperties": false
131
+ },
100
132
  "icon": {
101
133
  "type": "string",
102
134
  "maxLength": 512
@@ -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
- ]);