@capybara-hq/plugin-sdk 0.1.0-rc.21 → 0.1.0-rc.23
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/dist/ctx.d.ts +7 -2
- package/dist/device-protocol.d.ts +18 -34
- package/dist/device-protocol.js +16 -44
- package/dist/hooks.d.ts +3 -2
- package/dist/http-access.d.ts +52 -0
- package/dist/http-access.js +12 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/permissions.d.ts +3 -6
- package/dist/permissions.js +18 -4
- package/dist/sandbox.d.ts +12 -36
- package/dist/sandbox.js +0 -28
- package/package.json +1 -1
- package/dist/dev-hosts.d.ts +0 -6
- package/dist/dev-hosts.js +0 -48
package/dist/ctx.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Kysely } from "kysely";
|
|
2
2
|
import type { ExtensionPointRef } from "./extension-point.js";
|
|
3
3
|
import type { AvailableHook, HookHandler, HookOptions } from "./hooks.js";
|
|
4
|
+
import type { RouteCaller } from "./http-access.js";
|
|
4
5
|
import type { ModelEmbeddingInfo, ModelKind } from "./model.js";
|
|
5
6
|
import type { SetupCheckDefinition } from "./setup-check.js";
|
|
6
7
|
import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
|
|
@@ -160,8 +161,12 @@ export interface ExtensionContext {
|
|
|
160
161
|
/** 已切到本插件 schema(withSchema)的 Kysely 实例。 */
|
|
161
162
|
db: Kysely<any>;
|
|
162
163
|
http: {
|
|
163
|
-
/**
|
|
164
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Mounted at `/plugins/<name><path>` (`public`, `embed`) or `/plugins/<name>/orgs/:orgId<path>`
|
|
166
|
+
* (`member`, `admin`), as `permissions.http` declares. The kernel enforces the access before
|
|
167
|
+
* the handler runs and passes the resolved caller; trust only `caller`.
|
|
168
|
+
*/
|
|
169
|
+
route(method: "GET" | "POST" | "PUT" | "DELETE", path: string, handler: (req: Request, caller: RouteCaller) => Promise<Response>): void;
|
|
165
170
|
};
|
|
166
171
|
tools: {
|
|
167
172
|
/** 注册一个工具;只能在 `setup` 期间调用,名称不可重复。 */
|
|
@@ -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
|
|
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`; `
|
|
15
|
-
*
|
|
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" | "
|
|
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
|
-
/**
|
|
27
|
-
|
|
28
|
-
/** The
|
|
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
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
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
|
|
137
|
-
*
|
|
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
|
|
186
|
-
*
|
|
187
|
-
* sandbox
|
|
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
|
-
/**
|
|
201
|
-
|
|
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;
|
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 {
|
|
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
|
-
"
|
|
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 "${
|
|
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
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
99
|
+
throw new DeviceProtocolError(`invalid network host "${h}": ${problems.join("; ")}`);
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
|
-
|
|
102
|
+
return {
|
|
105
103
|
cpu: num(o, "cpu"),
|
|
106
104
|
memoryMb: num(o, "memoryMb"),
|
|
107
105
|
diskMb: num(o, "diskMb"),
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
170
|
-
|
|
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.
|
|
389
|
-
|
|
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
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { UiRole } from "./ui.js";
|
|
2
|
+
/**
|
|
3
|
+
* Who may call an extension route (declared per route in `permissions.http`, enforced by the
|
|
4
|
+
* kernel before the handler runs and before the body is read):
|
|
5
|
+
*
|
|
6
|
+
* - `public`: anyone; unsafe methods are rate-limited per client IP. Mounted at
|
|
7
|
+
* `/plugins/<name><path>`.
|
|
8
|
+
* - `embed`: the holder of an embed token (see `ctx.ui`); path under `/ui/`. Mounted at
|
|
9
|
+
* `/plugins/<name><path>`.
|
|
10
|
+
* - `member` / `admin`: an org member (admin: org admin and up) with a personal access token.
|
|
11
|
+
* Mounted at `/plugins/<name>/orgs/:orgId<path>`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const HTTP_ACCESS: readonly ["public", "embed", "member", "admin"];
|
|
14
|
+
export type HttpAccess = (typeof HTTP_ACCESS)[number];
|
|
15
|
+
/** One entry of `permissions.http`. */
|
|
16
|
+
export interface HttpPermission {
|
|
17
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
18
|
+
path: string;
|
|
19
|
+
access: HttpAccess;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The caller the kernel resolved for a route, passed to the handler as its second argument.
|
|
23
|
+
* Trust only this (`caller.orgId`, never an org id in the body or query).
|
|
24
|
+
*/
|
|
25
|
+
export type RouteCaller = {
|
|
26
|
+
access: "public";
|
|
27
|
+
} | {
|
|
28
|
+
access: "embed";
|
|
29
|
+
scope: "org";
|
|
30
|
+
orgId: string;
|
|
31
|
+
accountId: string;
|
|
32
|
+
role: UiRole;
|
|
33
|
+
contribution: string;
|
|
34
|
+
conversationId?: string;
|
|
35
|
+
/** The token's expiry (Unix seconds): a long-lived response (SSE) ends by then. */
|
|
36
|
+
exp: number;
|
|
37
|
+
config: unknown;
|
|
38
|
+
} | {
|
|
39
|
+
access: "embed";
|
|
40
|
+
scope: "platform";
|
|
41
|
+
accountId: string;
|
|
42
|
+
role: "superAdmin";
|
|
43
|
+
contribution: string;
|
|
44
|
+
/** The token's expiry (Unix seconds): a long-lived response (SSE) ends by then. */
|
|
45
|
+
exp: number;
|
|
46
|
+
} | {
|
|
47
|
+
access: "member" | "admin";
|
|
48
|
+
orgId: string;
|
|
49
|
+
accountId: string;
|
|
50
|
+
role: UiRole;
|
|
51
|
+
config: unknown;
|
|
52
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who may call an extension route (declared per route in `permissions.http`, enforced by the
|
|
3
|
+
* kernel before the handler runs and before the body is read):
|
|
4
|
+
*
|
|
5
|
+
* - `public`: anyone; unsafe methods are rate-limited per client IP. Mounted at
|
|
6
|
+
* `/plugins/<name><path>`.
|
|
7
|
+
* - `embed`: the holder of an embed token (see `ctx.ui`); path under `/ui/`. Mounted at
|
|
8
|
+
* `/plugins/<name><path>`.
|
|
9
|
+
* - `member` / `admin`: an org member (admin: org admin and up) with a personal access token.
|
|
10
|
+
* Mounted at `/plugins/<name>/orgs/:orgId<path>`.
|
|
11
|
+
*/
|
|
12
|
+
export const HTTP_ACCESS = ["public", "embed", "member", "admin"];
|
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.23";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -11,13 +11,13 @@ 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";
|
|
19
18
|
export * from "./git-hosts.js";
|
|
20
19
|
export * from "./hooks.js";
|
|
20
|
+
export * from "./http-access.js";
|
|
21
21
|
export * from "./identity.js";
|
|
22
22
|
export * from "./marketplace.js";
|
|
23
23
|
export * from "./model.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.23";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./bootstrap.js";
|
|
4
4
|
export * from "./cards.js";
|
|
@@ -11,13 +11,13 @@ 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";
|
|
19
18
|
export * from "./git-hosts.js";
|
|
20
19
|
export * from "./hooks.js";
|
|
20
|
+
export * from "./http-access.js";
|
|
21
21
|
export * from "./identity.js";
|
|
22
22
|
export * from "./marketplace.js";
|
|
23
23
|
export * from "./model.js";
|
package/dist/permissions.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { type PolicyHook } from "./hooks.js";
|
|
2
|
+
import { type HttpPermission } from "./http-access.js";
|
|
2
3
|
/** Extension permission manifest: governance, not a sandbox; using an undeclared platform API throws ExtensionPermissionError. */
|
|
3
4
|
export interface ExtensionPermissions {
|
|
4
5
|
/** ctx.secrets */
|
|
5
6
|
secrets?: boolean;
|
|
6
|
-
/** ctx.http.route
|
|
7
|
-
http?:
|
|
8
|
-
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
9
|
-
path: string;
|
|
10
|
-
public?: boolean;
|
|
11
|
-
}[];
|
|
7
|
+
/** Routes registered with ctx.http.route; each declares who may call it (`access`). */
|
|
8
|
+
http?: HttpPermission[];
|
|
12
9
|
/** ctx.tools.register 的工具名。 */
|
|
13
10
|
tools?: string[];
|
|
14
11
|
/**
|
package/dist/permissions.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { POLICY_HOOKS } from "./hooks.js";
|
|
2
|
+
import { HTTP_ACCESS } from "./http-access.js";
|
|
2
3
|
import { SETUP_CHECK_ID_RE, SETUP_CHECK_LIMITS } from "./setup-check.js";
|
|
3
4
|
import { UI_ICONS } from "./ui.js";
|
|
4
5
|
import { PLACE_SLOTS, parseSlotRef, uiSlot } from "./ui-slots.js";
|
|
@@ -117,14 +118,27 @@ export function validatePermissions(plugin, p) {
|
|
|
117
118
|
!METHODS.has(r.method) ||
|
|
118
119
|
typeof r.path !== "string" ||
|
|
119
120
|
!r.path.startsWith("/") ||
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
typeof r.access !== "string" ||
|
|
122
|
+
!HTTP_ACCESS.includes(r.access)) {
|
|
123
|
+
errs.push("permissions.http entries need method GET/POST/PUT/DELETE, a path starting with /, and access public/embed/member/admin");
|
|
122
124
|
continue;
|
|
123
125
|
}
|
|
124
126
|
const key = `${r.method} ${r.path}`;
|
|
125
127
|
if (seen.has(key))
|
|
126
128
|
errs.push(`permissions.http has duplicate route "${key}"`);
|
|
127
129
|
seen.add(key);
|
|
130
|
+
if (r.path === "/orgs" || r.path.startsWith("/orgs/")) {
|
|
131
|
+
errs.push(`permissions.http route "${key}" must not start with /orgs/ (reserved for org routes)`);
|
|
132
|
+
}
|
|
133
|
+
if (r.access === "embed" && !r.path.startsWith(UI_EMBED_PREFIX)) {
|
|
134
|
+
errs.push(`permissions.http embed route "${key}" must be under ${UI_EMBED_PREFIX}`);
|
|
135
|
+
}
|
|
136
|
+
if ((r.access === "member" || r.access === "admin") &&
|
|
137
|
+
// anywhere, not only after a slash: find-my-way lets a later duplicate param win, so
|
|
138
|
+
// `/x-:orgId` would override the mount's `:orgId`
|
|
139
|
+
/:orgId(?![A-Za-z0-9_])/.test(r.path)) {
|
|
140
|
+
errs.push(`permissions.http route "${key}" must not contain :orgId (the org comes from the mount)`);
|
|
141
|
+
}
|
|
128
142
|
}
|
|
129
143
|
}
|
|
130
144
|
}
|
|
@@ -220,7 +234,7 @@ export function validateUiContributions(ui, permissions) {
|
|
|
220
234
|
multiListed.add(id);
|
|
221
235
|
}
|
|
222
236
|
const gets = new Set((Array.isArray(perms.http) ? perms.http : [])
|
|
223
|
-
.filter((r) => isObj(r) && r.method === "GET")
|
|
237
|
+
.filter((r) => isObj(r) && r.method === "GET" && r.access === "public")
|
|
224
238
|
.map((r) => r.path));
|
|
225
239
|
const errs = [];
|
|
226
240
|
for (const id of multiListed)
|
|
@@ -310,7 +324,7 @@ export function validateUiContributions(ui, permissions) {
|
|
|
310
324
|
errs.push(`ui "${id}" (embed) path must start with "${UI_EMBED_PREFIX}"`);
|
|
311
325
|
}
|
|
312
326
|
else if (!gets.has(c.path)) {
|
|
313
|
-
errs.push(`ui "${id}"
|
|
327
|
+
errs.push(`ui "${id}" embed path "${c.path}" must be declared in permissions.http as GET with access public`);
|
|
314
328
|
}
|
|
315
329
|
});
|
|
316
330
|
const aliasIds = new Set(aliases.map((a) => a.id));
|
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
|
|
17
|
-
*
|
|
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
|
-
*
|
|
41
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
package/dist/dev-hosts.d.ts
DELETED
|
@@ -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
|
-
]);
|