@capybara-hq/plugin-sdk 0.1.0-rc.34 → 0.1.0-rc.36
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/concepts.md +9 -4
- package/agent-docs/extension-points/sandbox.md +1 -1
- package/agent-docs/plugin-format.md +1 -1
- package/dist/device-denied-paths.d.ts +14 -0
- package/dist/device-denied-paths.js +41 -0
- package/dist/device-protocol.d.ts +140 -20
- package/dist/device-protocol.js +419 -14
- package/dist/hooks.d.ts +13 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -3
- package/dist/model.d.ts +4 -3
- package/dist/sandbox-operation.d.ts +4 -0
- package/package.json +1 -1
- package/dist/device-protocol-v3.d.ts +0 -117
- package/dist/device-protocol-v3.js +0 -409
package/agent-docs/concepts.md
CHANGED
|
@@ -52,10 +52,15 @@ When a person cannot do something themselves (install a plugin that is not on in
|
|
|
52
52
|
approve extension permissions), they file a **request**. Org admins or the super admin decide it
|
|
53
53
|
on the web. Agents can file requests but never decide them.
|
|
54
54
|
|
|
55
|
-
##
|
|
56
|
-
|
|
57
|
-
Agents run commands and keep files
|
|
58
|
-
|
|
55
|
+
## Devices
|
|
56
|
+
|
|
57
|
+
Agents run commands and keep files on a **device**: one instance plus a file system that is kept
|
|
58
|
+
until the device is deleted. A device is a cloud sandbox (from the deployment's sandbox provider)
|
|
59
|
+
or a machine connected with `capybara-device`, and the conversations that use it share its files.
|
|
60
|
+
A device runs in one of two modes: auto (the environment's own capability) or sandbox (an OS
|
|
61
|
+
sandbox with an allowlist network). Skill files are read-only in the device's skills directory;
|
|
62
|
+
each conversation is told the device's directories, mode and network. Sandbox limits and the
|
|
63
|
+
cloud network are set per org by admins.
|
|
59
64
|
|
|
60
65
|
## What agents may not do
|
|
61
66
|
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
Contract: SandboxProvider (`sandbox.ts`)
|
|
12
12
|
|
|
13
|
-
The kernel accepts only `sandbox@2`. A device is one instance plus a file system that outlives it. Implement the file system (`createFileSystem`, `destroyFileSystem`, `destroyFileSystemByName`), the instance on it (`create`, which throws `FileSystemGoneError` when the file system is gone instead of making an empty one; `resume`, `suspend`; `destroy` and `destroyByName`, which drop the instance and keep the files), and the instance's `exec`, `readFile`, `writeFile`, `stat`, `killAll` and `killTagged` (`concurrentExec` is required: several conversations share one instance). Aborting a command must kill it. Locking, suspension timing and destruction are the kernel's job, not yours.
|
|
13
|
+
The kernel accepts only `sandbox@2`. A device is one instance plus a file system that outlives it. Implement the file system (`createFileSystem`, `destroyFileSystem`, `destroyFileSystemByName`), the instance on it (`create`, which throws `FileSystemGoneError` when the file system is gone instead of making an empty one; `resume`, `suspend`; `destroy` and `destroyByName`, which drop the instance and keep the files), and the instance's `exec`, `readFile`, `writeFile`, `stat`, `killAll` and `killTagged` (`concurrentExec` is required: several conversations share one instance). Aborting a command must kill it. Locking, suspension timing and destruction are the kernel's job, not yours.
|
|
14
14
|
|
|
15
15
|
See `extensions` for the rules every extension follows.
|
|
@@ -59,7 +59,7 @@ Rules that the schema cannot show:
|
|
|
59
59
|
by `parseThemeFile` (schema `https://capybarahq.com/schemas/theme.v1.schema.json`).
|
|
60
60
|
- `setupGuides` (at most 8): `{ id, place, template? }`. Each guide is a Markdown document at
|
|
61
61
|
`guides/<id>.md` (English, required) and `guides/<id>.zh.md` (Chinese, optional), shown where a
|
|
62
|
-
person sets up what the plugin brings. `place` is `channel-connection` (
|
|
62
|
+
person sets up what the plugin brings. `place` is `channel-connection` (New channel and the channel
|
|
63
63
|
detail; the extension must provide `channel@1`; one per plugin) or `connector-template`
|
|
64
64
|
(`template` names one of the plugin's `connectors/<id>.json`; one per template). See "Setup
|
|
65
65
|
guides" below.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths a local device never opens to restricted work (Request approval, Approve for me), relative
|
|
3
|
+
* to `~` (spec §13.6, extended by ruling R19): SSH keys, cloud CLI credentials, container and
|
|
4
|
+
* Kubernetes credentials, netrc, GnuPG, git / npm / PyPI tokens, the macOS keychains, and the
|
|
5
|
+
* browser profile directories. One source for the device, which denies them (and its own state
|
|
6
|
+
* directory), and the kernel, which never proposes an approval for a path under one. Full access
|
|
7
|
+
* and auto mode run as the owner and do not apply them: the command review does.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEVICE_DENIED_SECRET_PATHS: readonly string[];
|
|
10
|
+
/**
|
|
11
|
+
* The device program's default state directory (`$XDG_CONFIG_HOME/capybara-device` when that is
|
|
12
|
+
* set), relative to `~`: denied to restricted work like the secret paths.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEVICE_DEFAULT_STATE_PATH = "~/.config/capybara-device";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paths a local device never opens to restricted work (Request approval, Approve for me), relative
|
|
3
|
+
* to `~` (spec §13.6, extended by ruling R19): SSH keys, cloud CLI credentials, container and
|
|
4
|
+
* Kubernetes credentials, netrc, GnuPG, git / npm / PyPI tokens, the macOS keychains, and the
|
|
5
|
+
* browser profile directories. One source for the device, which denies them (and its own state
|
|
6
|
+
* directory), and the kernel, which never proposes an approval for a path under one. Full access
|
|
7
|
+
* and auto mode run as the owner and do not apply them: the command review does.
|
|
8
|
+
*/
|
|
9
|
+
export const DEVICE_DENIED_SECRET_PATHS = Object.freeze([
|
|
10
|
+
"~/.ssh",
|
|
11
|
+
"~/.aws",
|
|
12
|
+
"~/.config/gcloud",
|
|
13
|
+
"~/.azure",
|
|
14
|
+
"~/.kube",
|
|
15
|
+
"~/.docker/config.json",
|
|
16
|
+
"~/.netrc",
|
|
17
|
+
"~/.gnupg",
|
|
18
|
+
"~/Library/Application Support/Google/Chrome",
|
|
19
|
+
"~/Library/Application Support/Firefox",
|
|
20
|
+
"~/.mozilla",
|
|
21
|
+
"~/.config/google-chrome",
|
|
22
|
+
"~/.config/chromium",
|
|
23
|
+
// Ruling R19: more credential stores and browser data.
|
|
24
|
+
"~/.config/gh",
|
|
25
|
+
"~/.git-credentials",
|
|
26
|
+
"~/.npmrc",
|
|
27
|
+
"~/.pypirc",
|
|
28
|
+
"~/Library/Keychains",
|
|
29
|
+
"~/Library/Cookies",
|
|
30
|
+
"~/Library/Safari",
|
|
31
|
+
"~/Library/Application Support/BraveSoftware",
|
|
32
|
+
"~/Library/Application Support/Microsoft Edge",
|
|
33
|
+
"~/Library/Application Support/Arc",
|
|
34
|
+
"~/.config/BraveSoftware",
|
|
35
|
+
"~/.config/microsoft-edge",
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* The device program's default state directory (`$XDG_CONFIG_HOME/capybara-device` when that is
|
|
39
|
+
* set), relative to `~`: denied to restricted work like the secret paths.
|
|
40
|
+
*/
|
|
41
|
+
export const DEVICE_DEFAULT_STATE_PATH = "~/.config/capybara-device";
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The device protocol: 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
|
+
*
|
|
5
|
+
* Protocol 3 (the scope-bearing operations, `parseDeviceFrame`) is defined in the second half of
|
|
6
|
+
* this file. Protocol 2's frames keep a `Legacy` prefix where a protocol 3 name replaced them
|
|
7
|
+
* (`LegacyDeviceHello`, `parseLegacyDeviceFrame`, ...); protocol 3 reuses their value guards, and
|
|
8
|
+
* they go with the legacy device surface.
|
|
4
9
|
*/
|
|
5
10
|
import { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots } from "./sandbox.js";
|
|
11
|
+
import { type SandboxPermissionSupport } from "./sandbox-operation.js";
|
|
6
12
|
/** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
|
|
7
|
-
export declare const DEVICE_PROTOCOL_VERSION =
|
|
13
|
+
export declare const DEVICE_PROTOCOL_VERSION = 3;
|
|
14
|
+
/**
|
|
15
|
+
* Protocol 2's version, which a deployment speaking {@link DEVICE_PROTOCOL_VERSION} refuses (426
|
|
16
|
+
* on the header, a protocol close on the hello). Kept only for the legacy device surface.
|
|
17
|
+
*/
|
|
18
|
+
export declare const LEGACY_DEVICE_PROTOCOL_VERSION = 2;
|
|
8
19
|
/** The operations the kernel asks a device to run. */
|
|
9
20
|
export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop" | "policy" | "policyStatus" | "list" | "scan";
|
|
10
21
|
/**
|
|
@@ -42,14 +53,6 @@ export interface DeviceProjectCandidate {
|
|
|
42
53
|
* choice cut to `mode`, never by a ceiling it saw on an earlier command.
|
|
43
54
|
*/
|
|
44
55
|
export type DeviceRequestCeiling = Pick<SandboxLimits, "mode">;
|
|
45
|
-
/**
|
|
46
|
-
* The first line of the kernel's background task launch command (`Bash` `run_in_background`), a
|
|
47
|
-
* shell comment. A device kills what a foreground exec leaves running once the exec ends; an exec
|
|
48
|
-
* whose command starts with this line detaches a task on purpose, and its processes are left alone.
|
|
49
|
-
*/
|
|
50
|
-
export declare const BACKGROUND_LAUNCH_LINE = "# capybara: background task launch";
|
|
51
|
-
/** Whether an exec's command is a background task launch ({@link BACKGROUND_LAUNCH_LINE}). */
|
|
52
|
-
export declare function isBackgroundLaunch(command: string): boolean;
|
|
53
56
|
/** The most blocked hosts an exec result reports; the parser cuts longer lists. */
|
|
54
57
|
export declare const MAX_NETWORK_BLOCKED_HOSTS = 20;
|
|
55
58
|
/** The longest `opId` a `policy` / `policyStatus` op may carry. */
|
|
@@ -67,7 +70,7 @@ export interface DevicePolicyOpReport {
|
|
|
67
70
|
outcome: DevicePolicyOpOutcome;
|
|
68
71
|
}
|
|
69
72
|
/** First frame from the device after the WebSocket opens. */
|
|
70
|
-
export interface
|
|
73
|
+
export interface LegacyDeviceHello {
|
|
71
74
|
type: "hello";
|
|
72
75
|
protocol: number;
|
|
73
76
|
programVersion: string;
|
|
@@ -101,7 +104,7 @@ export interface DeviceHello {
|
|
|
101
104
|
}
|
|
102
105
|
/** A hello's `bootId`: 1 to 128 characters of letters, digits, `.`, `_`, `:` and `-`. */
|
|
103
106
|
export declare const DEVICE_BOOT_ID_RE: RegExp;
|
|
104
|
-
/** Whether `v` is a well-formed {@link
|
|
107
|
+
/** Whether `v` is a well-formed {@link LegacyDeviceHello.bootId}. */
|
|
105
108
|
export declare function isDeviceBootId(v: unknown): v is string;
|
|
106
109
|
/** Error kinds a device reports for a failed request. */
|
|
107
110
|
export type DeviceErrorKind = "gone" | "fs_gone" | "policy" | "error";
|
|
@@ -139,11 +142,11 @@ export interface KernelCancel {
|
|
|
139
142
|
* this connection. `policy` is absent when the frame's summary was unreadable; the kernel then
|
|
140
143
|
* learns the policy later, as for the hello.
|
|
141
144
|
*/
|
|
142
|
-
export interface
|
|
145
|
+
export interface LegacyDevicePolicyChanged {
|
|
143
146
|
type: "policy";
|
|
144
147
|
policy?: DeviceLocalPolicySummary;
|
|
145
148
|
}
|
|
146
|
-
export type
|
|
149
|
+
export type LegacyDeviceFrame = LegacyDeviceHello | DeviceRes | LegacyDevicePolicyChanged | KernelReq | KernelCancel;
|
|
147
150
|
export interface DeviceExecArgs {
|
|
148
151
|
command: string;
|
|
149
152
|
cwd?: string;
|
|
@@ -211,7 +214,7 @@ export interface DeviceStopArgs {
|
|
|
211
214
|
* (`"sandbox"`), never off (turning auto mode on is decided on the machine), and `add` extends the
|
|
212
215
|
* sandbox-mode allowlist only. Narrowing is always accepted.
|
|
213
216
|
*/
|
|
214
|
-
export interface
|
|
217
|
+
export interface LegacyDevicePolicyArgs {
|
|
215
218
|
/**
|
|
216
219
|
* The kernel's id of this change (non-empty, no `:`, at most {@link MAX_POLICY_OP_ID_LENGTH}
|
|
217
220
|
* characters): the device logs the op's outcome under it, for `policyStatus` and the hello's
|
|
@@ -233,7 +236,7 @@ export interface DevicePolicyArgs {
|
|
|
233
236
|
};
|
|
234
237
|
}
|
|
235
238
|
/** The policy as the device wrote it. */
|
|
236
|
-
export interface
|
|
239
|
+
export interface LegacyDevicePolicyResult {
|
|
237
240
|
policy: DeviceLocalPolicySummary;
|
|
238
241
|
}
|
|
239
242
|
/** Asks what became of the `policy` op with this id. Read-only on the device. */
|
|
@@ -245,7 +248,7 @@ export interface DevicePolicyStatusArgs {
|
|
|
245
248
|
* the id is not in its log (never received, or dropped from the log since). `policy` is the
|
|
246
249
|
* device's summary now; `message` the refusal's.
|
|
247
250
|
*/
|
|
248
|
-
export interface
|
|
251
|
+
export interface LegacyDevicePolicyStatus {
|
|
249
252
|
outcome: DevicePolicyOpOutcome | "unknown";
|
|
250
253
|
policy?: DeviceLocalPolicySummary;
|
|
251
254
|
message?: string;
|
|
@@ -314,8 +317,8 @@ export interface DeviceOpResults {
|
|
|
314
317
|
killTagged: null;
|
|
315
318
|
killAll: null;
|
|
316
319
|
stop: null;
|
|
317
|
-
policy:
|
|
318
|
-
policyStatus:
|
|
320
|
+
policy: LegacyDevicePolicyResult;
|
|
321
|
+
policyStatus: LegacyDevicePolicyStatus;
|
|
319
322
|
list: DeviceListResult;
|
|
320
323
|
scan: DeviceScanResult;
|
|
321
324
|
}
|
|
@@ -327,4 +330,121 @@ export declare function parseOpResult<Op extends DeviceOp>(op: Op, result: unkno
|
|
|
327
330
|
* kernel `req` and `cancel`. Throws {@link DeviceProtocolError} on bad JSON, an unknown `type`,
|
|
328
331
|
* missing fields or a frame of the wrong direction.
|
|
329
332
|
*/
|
|
330
|
-
export declare function
|
|
333
|
+
export declare function parseLegacyDeviceFrame(raw: string, from: "device" | "kernel"): LegacyDeviceFrame;
|
|
334
|
+
/**
|
|
335
|
+
* The operations the kernel asks a protocol 3 device to run: every user operation carries its
|
|
336
|
+
* admitted scope; there is no broad kill (`killTagged` / `killAll`).
|
|
337
|
+
*/
|
|
338
|
+
export type DeviceOperation = Exclude<DeviceOp, "killTagged" | "killAll"> | "prepareReadFile" | "prepareWriteFile" | "prepareStat" | "browseStat" | "browseList" | "browseScan" | "backgroundStart" | "backgroundStatus" | "backgroundTail" | "backgroundReadOutput" | "backgroundStop" | "revokeOperation" | "bindInstance";
|
|
339
|
+
export interface DeviceOwnerCeiling {
|
|
340
|
+
readonly version: 2;
|
|
341
|
+
readonly sequence: number;
|
|
342
|
+
readonly restrictedProjectReach: "workspace" | "os-user";
|
|
343
|
+
readonly revision: string;
|
|
344
|
+
readonly fullAccess: boolean;
|
|
345
|
+
readonly restrictedAllowedDomains: readonly string[];
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* The only owner-ceiling change the kernel may ask of a machine (B2): narrowing. Widening is decided
|
|
349
|
+
* on the machine by its owner (`capybara-device ceiling set`), never over the wire.
|
|
350
|
+
*/
|
|
351
|
+
export interface DeviceOwnerCeilingNarrowing {
|
|
352
|
+
readonly fullAccess?: false;
|
|
353
|
+
readonly restrictedProjectReach?: "workspace";
|
|
354
|
+
}
|
|
355
|
+
/** A staged `policy` op: the protocol 2 change plus an optional owner-ceiling narrowing. */
|
|
356
|
+
export interface DevicePolicyArgs extends LegacyDevicePolicyArgs {
|
|
357
|
+
ownerCeiling?: DeviceOwnerCeilingNarrowing;
|
|
358
|
+
}
|
|
359
|
+
/** A staged `policy` answer: the policy as written and the owner report issued for it. */
|
|
360
|
+
export interface DevicePolicyResult {
|
|
361
|
+
policy: DeviceLocalPolicySummary;
|
|
362
|
+
ownerCeiling: DeviceOwnerCeiling;
|
|
363
|
+
}
|
|
364
|
+
/** A staged `policyStatus` answer: an `applied` outcome carries the current owner report. */
|
|
365
|
+
export interface DevicePolicyStatus extends LegacyDevicePolicyStatus {
|
|
366
|
+
ownerCeiling?: DeviceOwnerCeiling;
|
|
367
|
+
}
|
|
368
|
+
/** The device pushed a policy change: the owner report for the newly observed revision. */
|
|
369
|
+
export interface DevicePolicyChanged {
|
|
370
|
+
type: "policy";
|
|
371
|
+
policy?: DeviceLocalPolicySummary;
|
|
372
|
+
ownerCeiling: DeviceOwnerCeiling;
|
|
373
|
+
}
|
|
374
|
+
export interface DeviceHello extends LegacyDeviceHello {
|
|
375
|
+
protocol: 3;
|
|
376
|
+
permissionSupport: SandboxPermissionSupport;
|
|
377
|
+
ownerCeiling: DeviceOwnerCeiling;
|
|
378
|
+
instanceGeneration: string | null;
|
|
379
|
+
transport: {
|
|
380
|
+
maxFrameBytes: number;
|
|
381
|
+
};
|
|
382
|
+
/** Absent until the program can attest actual installed runtime/helper/environment bytes. */
|
|
383
|
+
runtimeIdentity?: DeviceRuntimeIdentity;
|
|
384
|
+
}
|
|
385
|
+
/** A verified installed runtime/helper/environment identity bound to one instance generation. */
|
|
386
|
+
export interface DeviceRuntimeIdentity {
|
|
387
|
+
runtimeHash: string;
|
|
388
|
+
helperHash: string;
|
|
389
|
+
imageFingerprint: string;
|
|
390
|
+
instanceGeneration: string;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Private lifecycle request (permission runtime cutover B4): binds the kernel's committed instance
|
|
394
|
+
* generation to the device after commit. It carries no path, policy or manifest.
|
|
395
|
+
*/
|
|
396
|
+
export interface BindInstanceRequest {
|
|
397
|
+
instanceId: string;
|
|
398
|
+
instanceGeneration: string;
|
|
399
|
+
bindingId: string;
|
|
400
|
+
expectedPreviousGeneration: string | null;
|
|
401
|
+
}
|
|
402
|
+
export interface BindInstanceResult {
|
|
403
|
+
instanceId: string;
|
|
404
|
+
instanceGeneration: string;
|
|
405
|
+
bindingId: string;
|
|
406
|
+
runtimeIdentity: DeviceRuntimeIdentity;
|
|
407
|
+
permissionSupport: SandboxPermissionSupport;
|
|
408
|
+
ownerCeiling: DeviceOwnerCeiling;
|
|
409
|
+
}
|
|
410
|
+
export interface KernelReady {
|
|
411
|
+
type: "ready";
|
|
412
|
+
connectionId: string;
|
|
413
|
+
maxFrameBytes: number;
|
|
414
|
+
}
|
|
415
|
+
export interface BackgroundReadOutputRequest {
|
|
416
|
+
offset: number;
|
|
417
|
+
maxBytes: number;
|
|
418
|
+
}
|
|
419
|
+
export type BackgroundReadOutputResult = {
|
|
420
|
+
dataB64: string;
|
|
421
|
+
offset: number;
|
|
422
|
+
nextOffset: number;
|
|
423
|
+
totalBytes: number;
|
|
424
|
+
} | {
|
|
425
|
+
unavailable: "lost" | "expired";
|
|
426
|
+
};
|
|
427
|
+
export interface KernelRequest {
|
|
428
|
+
type: "req";
|
|
429
|
+
id: string;
|
|
430
|
+
op: DeviceOperation;
|
|
431
|
+
args: Readonly<Record<string, unknown>>;
|
|
432
|
+
deadlineMs: number;
|
|
433
|
+
}
|
|
434
|
+
export type DeviceResponse = Exclude<DeviceRes, {
|
|
435
|
+
ok: false;
|
|
436
|
+
}> | {
|
|
437
|
+
type: "res";
|
|
438
|
+
id: string;
|
|
439
|
+
ok: false;
|
|
440
|
+
error: {
|
|
441
|
+
kind: "gone" | "fs_gone" | "policy" | "error" | "denied" | "unsupported" | "unknown";
|
|
442
|
+
message: string;
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
export type DeviceFrame = DeviceHello | KernelReady | KernelRequest | KernelCancel | DeviceResponse | DevicePolicyChanged;
|
|
446
|
+
/** Strictly parses one authenticated owner-ceiling report (B2); throws {@link DeviceProtocolError}. */
|
|
447
|
+
export declare function parseOwnerCeilingReport(value: unknown): DeviceOwnerCeiling;
|
|
448
|
+
/** Strictly parses one protocol 3 frame; throws {@link DeviceProtocolError}. */
|
|
449
|
+
export declare function parseDeviceFrame(raw: string, from: "device" | "kernel", maxFrameBytes?: number): DeviceFrame;
|
|
450
|
+
export declare function parseOperationResult(op: DeviceOperation, result: unknown, request?: BackgroundReadOutputRequest | BindInstanceRequest): unknown;
|