@capybara-hq/plugin-sdk 0.1.0-rc.35 → 0.1.0-rc.37

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.
@@ -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
- * Device protocol v2: the WebSocket frames between the kernel and a `capybara-device` program
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 = 2;
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 DeviceHello {
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 DeviceHello.bootId}. */
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 DevicePolicyChanged {
145
+ export interface LegacyDevicePolicyChanged {
143
146
  type: "policy";
144
147
  policy?: DeviceLocalPolicySummary;
145
148
  }
146
- export type DeviceFrame = DeviceHello | DeviceRes | DevicePolicyChanged | KernelReq | KernelCancel;
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 DevicePolicyArgs {
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 DevicePolicyResult {
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 DevicePolicyStatus {
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: DevicePolicyResult;
318
- policyStatus: DevicePolicyStatus;
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 parseDeviceFrame(raw: string, from: "device" | "kernel"): DeviceFrame;
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;