@capybara-hq/plugin-sdk 0.1.0-rc.53 → 0.1.0-rc.55

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.
@@ -17,11 +17,18 @@ import { z } from "zod";
17
17
  * `all`, on in every org, not switchable) and are imported again when missing. An entry is never
18
18
  * both.
19
19
  *
20
+ * An optional preinstall (neither) may carry `scope: "all"`: its catalog item is then created with
21
+ * scope `all` (on in every org, an org admin may switch it off) instead of `optional` (off until
22
+ * switched on). The scope is read only at the first import; a later change in the manifest never
23
+ * rewrites the item, the super admin owns it after that. `scope` on a required or builtin entry
24
+ * is refused.
25
+ *
20
26
  * Objects are strict (unknown keys rejected, `$schema` allowed): the manifest ships with core, so
21
27
  * there is no older reader to stay compatible with and a misspelt key is a mistake. The committed
22
28
  * JSON Schema (`schemas/bootstrap.v1.schema.json`) is generated from {@link BootstrapManifestSchema}
23
29
  * by `pnpm gen:package-schemas`; the cross-field rules (unique names, `marketplace` required with an
24
- * npm entry, not both `required` and `builtin`) are decided only by {@link parseBootstrapManifest}.
30
+ * npm entry, not both `required` and `builtin`, `scope` only on an optional preinstall) are
31
+ * decided only by {@link parseBootstrapManifest}.
25
32
  */
26
33
  /** Manifest format version. */
27
34
  export declare const BOOTSTRAP_MANIFEST_SCHEMA_VERSION = 1;
@@ -43,6 +50,13 @@ export type BootstrapEntry = {
43
50
  * catalog item builtin; a failure does not stop the start. Never together with `required`.
44
51
  */
45
52
  builtin?: boolean;
53
+ /**
54
+ * Only for an optional preinstall (neither `required` nor `builtin`): the scope its catalog
55
+ * item gets when first imported (default `optional`: off in every org until switched on).
56
+ * `all` is on in every org and an org admin may switch it off. Read only at the first
57
+ * import: a later change here never rewrites the item (the super admin owns it then).
58
+ */
59
+ scope?: "all" | "optional";
46
60
  } | {
47
61
  name: string;
48
62
  source: "workspace";
@@ -52,6 +66,13 @@ export type BootstrapEntry = {
52
66
  integrity: string;
53
67
  required: boolean;
54
68
  builtin?: boolean;
69
+ /**
70
+ * Only for an optional preinstall (neither `required` nor `builtin`): the scope its catalog
71
+ * item gets when first imported (default `optional`: off in every org until switched on).
72
+ * `all` is on in every org and an org admin may switch it off. Read only at the first
73
+ * import: a later change here never rewrites the item (the super admin owns it then).
74
+ */
75
+ scope?: "all" | "optional";
55
76
  };
56
77
  /** `bootstrap.json`. */
57
78
  export interface BootstrapManifest {
@@ -98,6 +119,8 @@ export interface BootstrapGitEntry {
98
119
  integrity: string;
99
120
  required?: boolean;
100
121
  builtin?: boolean;
122
+ /** As on {@link BootstrapEntry}: only for an optional preinstall. */
123
+ scope?: "all" | "optional";
101
124
  }
102
125
  /** An entry of the extra manifest: npm (`required` optional) or git. */
103
126
  export type BootstrapExtraEntry = (Omit<Extract<BootstrapEntry, {
package/dist/bootstrap.js CHANGED
@@ -19,15 +19,23 @@ import { CATALOG_ITEM_NAME_RE, isSafePackagePath, NPM_PACKAGE_NAME_RE, SEMVER_VE
19
19
  * `all`, on in every org, not switchable) and are imported again when missing. An entry is never
20
20
  * both.
21
21
  *
22
+ * An optional preinstall (neither) may carry `scope: "all"`: its catalog item is then created with
23
+ * scope `all` (on in every org, an org admin may switch it off) instead of `optional` (off until
24
+ * switched on). The scope is read only at the first import; a later change in the manifest never
25
+ * rewrites the item, the super admin owns it after that. `scope` on a required or builtin entry
26
+ * is refused.
27
+ *
22
28
  * Objects are strict (unknown keys rejected, `$schema` allowed): the manifest ships with core, so
23
29
  * there is no older reader to stay compatible with and a misspelt key is a mistake. The committed
24
30
  * JSON Schema (`schemas/bootstrap.v1.schema.json`) is generated from {@link BootstrapManifestSchema}
25
31
  * by `pnpm gen:package-schemas`; the cross-field rules (unique names, `marketplace` required with an
26
- * npm entry, not both `required` and `builtin`) are decided only by {@link parseBootstrapManifest}.
32
+ * npm entry, not both `required` and `builtin`, `scope` only on an optional preinstall) are
33
+ * decided only by {@link parseBootstrapManifest}.
27
34
  */
28
35
  /** Manifest format version. */
29
36
  export const BOOTSTRAP_MANIFEST_SCHEMA_VERSION = 1;
30
37
  const MAX_ERRORS = 50;
38
+ const SCOPE_MESSAGE = "scope applies only to optional preinstalls";
31
39
  const URL_CHARS = 2000;
32
40
  const COMMIT_RE = /^[0-9a-f]{40}$/;
33
41
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
@@ -45,6 +53,7 @@ const common = {
45
53
  .regex(SHA512_INTEGRITY_RE, { message: "integrity must be sha512-<86 base64 chars>==" }),
46
54
  required: z.boolean(),
47
55
  builtin: z.boolean().optional(),
56
+ scope: z.enum(["all", "optional"]).optional(),
48
57
  };
49
58
  const entry = z.discriminatedUnion("source", [
50
59
  z.strictObject({
@@ -91,6 +100,13 @@ const schema = z
91
100
  message: "an entry is either required or builtin, not both",
92
101
  });
93
102
  }
103
+ if (e.scope !== undefined && (e.required || e.builtin === true)) {
104
+ ctx.addIssue({
105
+ code: "custom",
106
+ path: ["plugins", i, "scope"],
107
+ message: SCOPE_MESSAGE,
108
+ });
109
+ }
94
110
  });
95
111
  if (m.marketplace === undefined && m.plugins.some((e) => e.source === "npm")) {
96
112
  ctx.addIssue({
@@ -133,6 +149,7 @@ const extraCommon = {
133
149
  integrity: common.integrity,
134
150
  required: z.boolean().optional(),
135
151
  builtin: common.builtin,
152
+ scope: common.scope,
136
153
  };
137
154
  const extraEntry = z.discriminatedUnion("source", [
138
155
  z.strictObject({
@@ -227,6 +244,13 @@ const extraSchema = z
227
244
  message: "an entry is either required or builtin, not both",
228
245
  });
229
246
  }
247
+ if (e.scope !== undefined && (e.required === true || e.builtin === true)) {
248
+ ctx.addIssue({
249
+ code: "custom",
250
+ path: ["plugins", i, "scope"],
251
+ message: SCOPE_MESSAGE,
252
+ });
253
+ }
230
254
  if (e.source === "git" && !marketplaces.has(e.marketplace)) {
231
255
  ctx.addIssue({
232
256
  code: "custom",
package/dist/ctx.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Kysely } from "kysely";
2
+ import type { DevicesCtx, DialInChannel } from "./dial-in.js";
2
3
  import type { ExtensionPointRef } from "./extension-point.js";
3
4
  import type { AvailableHook, HookHandler, HookOptions } from "./hooks.js";
4
5
  import type { RouteCaller } from "./http-access.js";
@@ -310,6 +311,17 @@ export interface ExtensionContext {
310
311
  hooks: {
311
312
  on<K extends AvailableHook>(mount: K, handler: HookHandler<K>, opts: HookOptions): void;
312
313
  };
314
+ /**
315
+ * The dial-in channel to the machines serving this extension's devices (requires
316
+ * `permissions.dialIn`, see {@link DialInChannel}): every call is refused for a device another
317
+ * extension serves.
318
+ */
319
+ dialIn: DialInChannel;
320
+ /**
321
+ * Tells the kernel about this extension's devices (requires `provides` to include
322
+ * `device-provider@1`, see {@link DevicesCtx}).
323
+ */
324
+ devices: DevicesCtx;
313
325
  provide(extensionPoint: ExtensionPointRef, impl: unknown): void;
314
326
  /**
315
327
  * The lifecycle signal of this plugin instance: aborted when the instance is revoked (disabled,
@@ -80,7 +80,7 @@ export function defineExtension(m) {
80
80
  }
81
81
  }
82
82
  if (m.permissions !== undefined) {
83
- const errs = validatePermissions(plugin, m.permissions);
83
+ const errs = validatePermissions(plugin, m.permissions, m.provides);
84
84
  if (errs.length > 0)
85
85
  fail(`invalid permissions: ${errs.join("; ")}`);
86
86
  }
@@ -31,6 +31,18 @@ export declare class SandboxScopeDeniedError extends Error {
31
31
  }
32
32
  /** Recognizes the name and tag across SDK copies without requiring this class's identity. */
33
33
  export declare function isSandboxScopeDeniedError(e: unknown): e is SandboxScopeDeniedError;
34
+ /**
35
+ * A request refused because the machine's connection changed before it was sent: the request
36
+ * never reached the machine, so it ran nothing. A scope refusal (it keeps that error's name, so
37
+ * every scope check treats it as the definite pre-effect failure it is) that the operation path
38
+ * records as `not_sent`, never as an unknown outcome. It says nothing about an earlier request of
39
+ * the same operation, so a recovery tells it apart ({@link isDeviceRequestNotSent}).
40
+ */
41
+ export declare class DeviceRequestNotSentError extends SandboxScopeDeniedError {
42
+ readonly notSent: true;
43
+ }
44
+ /** Recognizes {@link DeviceRequestNotSentError} by its scope refusal's name and tags, across SDK copies. */
45
+ export declare function isDeviceRequestNotSent(e: unknown): boolean;
34
46
  /** A scope or execution reference is malformed; validate it before performing any effects. */
35
47
  export declare class SandboxScopeValidationError extends Error {
36
48
  readonly sandboxScopeValidation: true;
@@ -51,6 +51,20 @@ export function isSandboxScopeDeniedError(e) {
51
51
  e.name === "SandboxScopeDeniedError" &&
52
52
  e.sandboxScopeDenied === true);
53
53
  }
54
+ /**
55
+ * A request refused because the machine's connection changed before it was sent: the request
56
+ * never reached the machine, so it ran nothing. A scope refusal (it keeps that error's name, so
57
+ * every scope check treats it as the definite pre-effect failure it is) that the operation path
58
+ * records as `not_sent`, never as an unknown outcome. It says nothing about an earlier request of
59
+ * the same operation, so a recovery tells it apart ({@link isDeviceRequestNotSent}).
60
+ */
61
+ export class DeviceRequestNotSentError extends SandboxScopeDeniedError {
62
+ notSent = true;
63
+ }
64
+ /** Recognizes {@link DeviceRequestNotSentError} by its scope refusal's name and tags, across SDK copies. */
65
+ export function isDeviceRequestNotSent(e) {
66
+ return isSandboxScopeDeniedError(e) && e.notSent === true;
67
+ }
54
68
  /** A scope or execution reference is malformed; validate it before performing any effects. */
55
69
  export class SandboxScopeValidationError extends Error {
56
70
  sandboxScopeValidation = true;
@@ -2,38 +2,31 @@
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
4
  *
5
- * Protocol 4 (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 newer name replaced them
7
- * (`LegacyDeviceHello`, `parseLegacyDeviceFrame`, ...); protocol 4 reuses their value guards, and
8
- * they go with the legacy device surface.
5
+ * The bodies of the dial-in envelope are parsed by `parseDeviceFrame` (second half of this file);
6
+ * the per-operation argument and result guards of the first half are its value guards.
9
7
  */
10
8
  import { type SandboxPermissionSupport } from "./device-operation.js";
11
9
  import { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots } from "./device-provider.js";
12
- /** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
10
+ /** The major version of {@link DEVICE_DIAL_IN_PROTOCOL}. */
13
11
  export declare const DEVICE_PROTOCOL_VERSION = 5;
14
12
  /**
15
- * Protocol 4's version, which a deployment speaking {@link DEVICE_PROTOCOL_VERSION} refuses (426
16
- * on the header, a protocol close on the hello): its operation frames carry read roots in the
17
- * filesystem scope, which protocol 5 replaced with the project root, so a protocol 4 program must
18
- * be updated.
13
+ * The dial-in protocol `capybara-device` speaks (`<name>/<major>`, see `DIAL_IN_PROTOCOL_RE`): the
14
+ * value of the `X-Capybara-Device-Protocol` header, of the hello envelope's `protocol` and of the
15
+ * sign-in's `protocol`. The provider serving its devices declares it as `permissions.dialIn`.
16
+ * The kernel checks only the envelope (`DialInMachineFrame`); the bodies the envelope carries are
17
+ * this module's ({@link parseDeviceFrame}).
19
18
  */
20
- export declare const LEGACY_DEVICE_PROTOCOL_VERSION = 4;
19
+ export declare const DEVICE_DIAL_IN_PROTOCOL: "capybara-device/5";
21
20
  /** The operations the kernel asks a device to run. */
22
- export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop" | "policy" | "policyStatus" | "list" | "scan";
21
+ export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop" | "list" | "scan";
23
22
  /**
24
- * Optional capabilities a device announces in its hello. `policyOp`: the device takes the `policy`
25
- * op; `policyOpId`: it also logs each `policy` op's outcome by its `opId`, answers `policyStatus`
26
- * and reports recent outcomes in its hello (`recentOps`); `networkReport` means exec results may
27
- * carry `network`; `projects` means the device serves `list` and
28
- * `scan` (the kernel keeps a device's projects itself and asks the device only what it can read).
29
- * The kernel gates each op on its feature, as it gates `policy` on `policyOp` / `policyOpId`: it
30
- * never sends `list` or `scan` to a device that did not announce `projects`.
23
+ * Optional capabilities a device announces in its hello: `networkReport` means exec results may
24
+ * carry `network`; `projects` means the device serves `list` and `scan` (the provider never sends
25
+ * `list` or `scan` to a device that did not announce `projects`).
31
26
  */
32
- export type DeviceFeature = "networkReport" | "policyOp" | "policyOpId" | "projects";
33
- /** The most entries a `list` op may ask for and its result may carry. */
34
- export declare const MAX_DEVICE_LIST_ENTRIES = 1000;
27
+ export type DeviceFeature = "networkReport" | "projects";
35
28
  /**
36
- * What a device knows of its local policy and reports (in the hello or a `policy` op). The owner
29
+ * What a device knows of its local policy and reports (in the hello or a `policy` event). The owner
37
30
  * ceiling travels separately, in the owner report ({@link DeviceOwnerCeiling}).
38
31
  */
39
32
  export interface DeviceLocalPolicySummary {
@@ -52,110 +45,14 @@ export interface DeviceProjectCandidate {
52
45
  /** The most blocked hosts an exec result reports; the parser cuts longer lists. */
53
46
  export declare const MAX_NETWORK_BLOCKED_HOSTS = 20;
54
47
  /**
55
- * Why a `policy` op naming hosts to `add` is refused: the deployment may only narrow a local
56
- * device's sandbox; its owner widens it on the machine.
48
+ * The identity of a host's OS boot or of a program run: 1 to 128 characters of letters, digits,
49
+ * `.`, `_`, `:` and `-`.
57
50
  */
58
- export declare const POLICY_ADD_REFUSED = "The deployment may not add hosts to a device's sandbox allowlist: widening happens only on the machine (capybara-device policy add allowedDomains <host>)";
59
- /** The longest `opId` a `policy` / `policyStatus` op may carry. */
60
- export declare const MAX_POLICY_OP_ID_LENGTH = 128;
61
- /** The most entries a hello's `recentOps` carries; the parser keeps the newest. */
62
- export declare const MAX_RECENT_POLICY_OPS = 100;
63
- /**
64
- * What a device recorded of a `policy` op: `started` (written before the change, so an op the
65
- * device was stopped in the middle of stays `started`), then `applied` or `refused`.
66
- */
67
- export type DevicePolicyOpOutcome = "applied" | "refused" | "started";
68
- /** One entry of a hello's `recentOps`. */
69
- export interface DevicePolicyOpReport {
70
- opId: string;
71
- outcome: DevicePolicyOpOutcome;
72
- }
73
- /** First frame from the device after the WebSocket opens. */
74
- export interface LegacyDeviceHello {
75
- type: "hello";
76
- protocol: number;
77
- programVersion: string;
78
- os: "darwin" | "linux";
79
- arch: string;
80
- mode: "os" | "docker";
81
- roots: SandboxRoots;
82
- sessionIsolation: boolean;
83
- /** Optional capabilities (absent on older devices; unknown entries are dropped by the parser). */
84
- features?: DeviceFeature[];
85
- /** The device's local policy at connect time (absent on older devices). */
86
- policy?: DeviceLocalPolicySummary;
87
- /**
88
- * The outcomes of the latest `policy` ops by op id, oldest first, at most
89
- * {@link MAX_RECENT_POLICY_OPS} (devices with `policyOpId`; malformed entries are dropped by
90
- * the parser).
91
- */
92
- recentOps?: DevicePolicyOpReport[];
93
- /**
94
- * The owner's home directory, an absolute path (a local device; the base of an auto-mode
95
- * project's relative path). A malformed value is dropped by the parser.
96
- */
97
- home?: string;
98
- /**
99
- * The identity of the host's current OS boot (Linux `/proc/sys/kernel/random/boot_id`; macOS
100
- * `kern.bootsessionuuid`): a value that differs from an earlier one of the
101
- * same machine proves the host restarted since, so no process of that earlier boot can exist.
102
- * A malformed value is dropped by the parser.
103
- */
104
- bootId?: string;
105
- /**
106
- * The identity of this run of the program: random, chosen once when the process starts and
107
- * the same on every connection it makes (never the OS pid). The results a program keeps for a
108
- * reconnect live in its memory, so a value that differs from the one a request was sent to
109
- * proves that request's result can no longer arrive: the kernel ends its wait at once instead of
110
- * at the deadline. Same format as {@link bootId}; a malformed value is dropped by the parser.
111
- */
112
- programRunId?: string;
113
- }
114
- /** A hello's `bootId`: 1 to 128 characters of letters, digits, `.`, `_`, `:` and `-`. */
115
51
  export declare const DEVICE_BOOT_ID_RE: RegExp;
116
- /** Whether `v` is a well-formed {@link LegacyDeviceHello.bootId}. */
52
+ /** Whether `v` is a well-formed boot or program-run identity ({@link DEVICE_BOOT_ID_RE}). */
117
53
  export declare function isDeviceBootId(v: unknown): v is string;
118
54
  /** Error kinds a device reports for a failed request. */
119
55
  export type DeviceErrorKind = "gone" | "fs_gone" | "policy" | "error";
120
- /** The device's answer to a {@link KernelReq}. */
121
- export type DeviceRes = {
122
- type: "res";
123
- id: string;
124
- ok: true;
125
- result: unknown;
126
- } | {
127
- type: "res";
128
- id: string;
129
- ok: false;
130
- error: {
131
- kind: DeviceErrorKind;
132
- message: string;
133
- };
134
- };
135
- /** A request from the kernel. */
136
- export interface KernelReq {
137
- type: "req";
138
- id: string;
139
- op: DeviceOp;
140
- args: unknown;
141
- deadlineMs: number;
142
- }
143
- /** The kernel gives up on a request (abort or deadline). */
144
- export interface KernelCancel {
145
- type: "cancel";
146
- id: string;
147
- }
148
- /**
149
- * The device's local policy changed while connected (its file was edited on the machine, the owner
150
- * switched mode): the summary as it is now, sent only when it differs from the last one sent on
151
- * this connection. `policy` is absent when the frame's summary was unreadable; the kernel then
152
- * learns the policy later, as for the hello.
153
- */
154
- export interface LegacyDevicePolicyChanged {
155
- type: "policy";
156
- policy?: DeviceLocalPolicySummary;
157
- }
158
- export type LegacyDeviceFrame = LegacyDeviceHello | DeviceRes | LegacyDevicePolicyChanged | KernelReq | KernelCancel;
159
56
  export interface DeviceExecArgs {
160
57
  command: string;
161
58
  cwd?: string;
@@ -216,47 +113,6 @@ export interface DeviceCreateResult {
216
113
  export interface DeviceStopArgs {
217
114
  reason: "revoked" | "deleted";
218
115
  }
219
- /**
220
- * Edits the device's local policy. The kernel may only narrow: it removes hosts from the sandbox
221
- * allowlist and narrows the owner ceiling ({@link DevicePolicyArgs}). Widening happens only on the
222
- * machine (`capybara-device policy add`, `capybara-device ceiling set`): the frame parser refuses
223
- * an `add` and the protocol 3 `mode`.
224
- */
225
- export interface LegacyDevicePolicyArgs {
226
- /**
227
- * The kernel's id of this change (non-empty, no `:`, at most {@link MAX_POLICY_OP_ID_LENGTH}
228
- * characters): the device logs the op's outcome under it, for `policyStatus` and the hello's
229
- * `recentOps`.
230
- */
231
- opId: string;
232
- /** Hosts to remove from `allowedDomains`. */
233
- remove?: string[];
234
- /** Who decided, for the device's local audit line. */
235
- source: {
236
- approvalId?: string;
237
- accountId: string;
238
- accountName: string;
239
- via: "web" | "im";
240
- };
241
- }
242
- /** The policy as the device wrote it. */
243
- export interface LegacyDevicePolicyResult {
244
- policy: DeviceLocalPolicySummary;
245
- }
246
- /** Asks what became of the `policy` op with this id. Read-only on the device. */
247
- export interface DevicePolicyStatusArgs {
248
- opId: string;
249
- }
250
- /**
251
- * What the device logged of a `policy` op: its {@link DevicePolicyOpOutcome}, or `unknown` when
252
- * the id is not in its log (never received, or dropped from the log since). `policy` is the
253
- * device's summary now; `message` the refusal's.
254
- */
255
- export interface LegacyDevicePolicyStatus {
256
- outcome: DevicePolicyOpOutcome | "unknown";
257
- policy?: DeviceLocalPolicySummary;
258
- message?: string;
259
- }
260
116
  /**
261
117
  * Lists one directory (absolute `path`, {@link validateSandboxPathShape}): at most `limit` entries
262
118
  * (at most {@link MAX_DEVICE_LIST_ENTRIES}), read within the operation's scope. See
@@ -304,11 +160,6 @@ export type DeviceScanResult = DeviceProjectCandidate[];
304
160
  export declare class DeviceProtocolError extends Error {
305
161
  constructor(message: string);
306
162
  }
307
- /**
308
- * Whether `v` is a valid policy op id: non-empty, no `:`, at most
309
- * {@link MAX_POLICY_OP_ID_LENGTH} characters.
310
- */
311
- export declare function isPolicyOpId(v: unknown): v is string;
312
163
  /** Result type per op. */
313
164
  export interface DeviceOpResults {
314
165
  create: DeviceCreateResult;
@@ -319,23 +170,16 @@ export interface DeviceOpResults {
319
170
  killTagged: null;
320
171
  killAll: null;
321
172
  stop: null;
322
- policy: LegacyDevicePolicyResult;
323
- policyStatus: LegacyDevicePolicyStatus;
324
173
  list: DeviceListResult;
325
174
  scan: DeviceScanResult;
326
175
  }
327
176
  /** Validates the `result` of a successful `res` for `op`; throws {@link DeviceProtocolError}. */
328
177
  export declare function parseOpResult<Op extends DeviceOp>(op: Op, result: unknown): DeviceOpResults[Op];
329
178
  /**
330
- * Parses one WebSocket text frame. `from` is the sender: a device may send `hello`, `res` and
331
- * `policy`, the
332
- * kernel `req` and `cancel`. Throws {@link DeviceProtocolError} on bad JSON, an unknown `type`,
333
- * missing fields or a frame of the wrong direction.
334
- */
335
- export declare function parseLegacyDeviceFrame(raw: string, from: "device" | "kernel"): LegacyDeviceFrame;
336
- /**
337
- * The operations the kernel asks a protocol 4 device to run: every user operation carries its
338
- * admitted scope; there is no broad kill (`killTagged` / `killAll`).
179
+ * The operations the kernel asks a protocol 5 device to run: every user operation carries its
180
+ * admitted scope; there is no broad kill (`killTagged` / `killAll`) and no deployment-side change
181
+ * of the machine's policy: the owner changes it on the machine and the device reports the change
182
+ * ({@link DevicePolicyChanged}).
339
183
  */
340
184
  export type DeviceOperation = Exclude<DeviceOp, "killTagged" | "killAll"> | "prepareReadFile" | "prepareWriteFile" | "prepareStat" | "browseStat" | "browseList" | "browseScan" | "backgroundStart" | "backgroundStatus" | "backgroundTail" | "backgroundReadOutput" | "backgroundStop" | "revokeOperation" | "bindInstance";
341
185
  /** The sandbox network of a device: the open public internet or an allowlist. */
@@ -366,33 +210,36 @@ export interface DeviceOwnerCeilingNarrowing {
366
210
  readonly removeAllowedDomains?: readonly string[];
367
211
  readonly restrictedProjectReach?: "workspace";
368
212
  }
369
- /** A staged `policy` op: the protocol 2 change plus an optional owner-ceiling narrowing. */
370
- export interface DevicePolicyArgs extends LegacyDevicePolicyArgs {
371
- ownerCeiling?: DeviceOwnerCeilingNarrowing;
372
- }
373
- /** A staged `policy` answer: the policy as written and the owner report issued for it. */
374
- export interface DevicePolicyResult {
375
- policy: DeviceLocalPolicySummary;
376
- ownerCeiling: DeviceOwnerCeiling;
377
- }
378
- /** A staged `policyStatus` answer: an `applied` outcome carries the current owner report. */
379
- export interface DevicePolicyStatus extends LegacyDevicePolicyStatus {
380
- ownerCeiling?: DeviceOwnerCeiling;
381
- }
382
- /** The device pushed a policy change: the owner report for the newly observed revision. */
213
+ /**
214
+ * An event body (the envelope's `event`): the owner changed the machine's policy or owner ceiling
215
+ * while connected. `policy` is absent when the summary was unreadable.
216
+ */
383
217
  export interface DevicePolicyChanged {
384
218
  type: "policy";
385
219
  policy?: DeviceLocalPolicySummary;
386
220
  ownerCeiling: DeviceOwnerCeiling;
387
221
  }
388
- export interface DeviceHello extends LegacyDeviceHello {
389
- protocol: typeof DEVICE_PROTOCOL_VERSION;
222
+ /**
223
+ * The hello body (the envelope's `hello` carries the program facts: protocol, program version,
224
+ * os, arch, boot and run identities, frame capacity). `policy` and `ownerCeiling` are the
225
+ * machine's own narrowing, read by the provider serving the device.
226
+ */
227
+ export interface DeviceHello {
228
+ mode: "os" | "docker";
229
+ roots: SandboxRoots;
230
+ sessionIsolation: boolean;
231
+ /** Optional capabilities (unknown entries are dropped by the parser). */
232
+ features?: DeviceFeature[];
233
+ /** The device's local policy summary (dropped by the parser when unreadable). */
234
+ policy?: DeviceLocalPolicySummary;
235
+ /**
236
+ * The owner's home directory, an absolute path (a local device; the base of an auto-mode
237
+ * project's relative path). A malformed value is dropped by the parser.
238
+ */
239
+ home?: string;
390
240
  permissionSupport: SandboxPermissionSupport;
391
241
  ownerCeiling: DeviceOwnerCeiling;
392
242
  instanceGeneration: string | null;
393
- transport: {
394
- maxFrameBytes: number;
395
- };
396
243
  /** Absent until the program can attest actual installed runtime/helper/environment bytes. */
397
244
  runtimeIdentity?: DeviceRuntimeIdentity;
398
245
  }
@@ -421,11 +268,6 @@ export interface BindInstanceResult {
421
268
  permissionSupport: SandboxPermissionSupport;
422
269
  ownerCeiling: DeviceOwnerCeiling;
423
270
  }
424
- export interface KernelReady {
425
- type: "ready";
426
- connectionId: string;
427
- maxFrameBytes: number;
428
- }
429
271
  export interface BackgroundReadOutputRequest {
430
272
  offset: number;
431
273
  maxBytes: number;
@@ -438,18 +280,22 @@ export type BackgroundReadOutputResult = {
438
280
  } | {
439
281
  unavailable: "lost" | "expired";
440
282
  };
441
- export interface KernelRequest {
442
- type: "req";
443
- id: string;
283
+ /** A request body (the envelope's `req`): one operation and its arguments. */
284
+ export interface DeviceRequestBody {
444
285
  op: DeviceOperation;
445
286
  args: Readonly<Record<string, unknown>>;
446
- deadlineMs: number;
447
287
  }
448
- export type DeviceResponse = Exclude<DeviceRes, {
449
- ok: false;
450
- }> | {
451
- type: "res";
288
+ /** A request as the device serves it: its body with the envelope's `id` and `deadlineMs`. */
289
+ export interface KernelRequest extends DeviceRequestBody {
290
+ type: "req";
452
291
  id: string;
292
+ deadlineMs: number;
293
+ }
294
+ /** A response body (the envelope's `res`): the result, or the typed failure. */
295
+ export type DeviceResponseBody = {
296
+ ok: true;
297
+ result: unknown;
298
+ } | {
453
299
  ok: false;
454
300
  error: {
455
301
  /**
@@ -462,7 +308,18 @@ export type DeviceResponse = Exclude<DeviceRes, {
462
308
  message: string;
463
309
  };
464
310
  };
465
- export type DeviceFrame = DeviceHello | KernelReady | KernelRequest | KernelCancel | DeviceResponse | DevicePolicyChanged;
311
+ /** A response as the device produces it: its body with the envelope's `id`. */
312
+ export type DeviceResponse = {
313
+ type: "res";
314
+ id: string;
315
+ } & DeviceResponseBody;
316
+ /** The bodies of protocol 5, by the envelope frame that carries them. */
317
+ export interface DeviceBodies {
318
+ hello: DeviceHello;
319
+ req: DeviceRequestBody;
320
+ res: DeviceResponseBody;
321
+ event: DevicePolicyChanged;
322
+ }
466
323
  /**
467
324
  * Strictly parses a runtime permission report, version 2 (the protocol 4 `permissionSupport`, also
468
325
  * the shape a cloud provider reports), and returns a frozen copy; throws {@link DeviceProtocolError}.
@@ -485,6 +342,11 @@ export declare function parseOwnerCeilingReport(value: unknown): DeviceOwnerCeil
485
342
  * There is no way to name a host to add or a list to replace.
486
343
  */
487
344
  export declare function parseOwnerCeilingNarrowing(value: unknown): DeviceOwnerCeilingNarrowing;
488
- /** Strictly parses one protocol 4 frame; throws {@link DeviceProtocolError}. */
489
- export declare function parseDeviceFrame(raw: string, from: "device" | "kernel", maxFrameBytes?: number): DeviceFrame;
345
+ /**
346
+ * Strictly parses one protocol 5 body, as carried by the dial-in envelope frame of type `kind`
347
+ * (`hello`, `event` and `res` from the device, `req` from the kernel), and returns a frozen copy;
348
+ * throws {@link DeviceProtocolError}. The envelope (its ids, deadline and size bound) is checked
349
+ * before: `parseDialInMachineFrame` on the kernel, `parseDialInKernelFrame` on the machine.
350
+ */
351
+ export declare function parseDeviceFrame<K extends keyof DeviceBodies>(body: unknown, kind: K): DeviceBodies[K];
490
352
  export declare function parseOperationResult(op: DeviceOperation, result: unknown, request?: BackgroundReadOutputRequest | BindInstanceRequest): unknown;