@capybara-hq/plugin-sdk 0.1.0-rc.5 → 0.1.0-rc.51

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.
Files changed (134) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +4 -1
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +2 -0
  9. package/agent-docs/extension-points/model-provider.md +3 -1
  10. package/agent-docs/extension-points/object-store.md +2 -0
  11. package/agent-docs/extension-points/push-provider.md +17 -0
  12. package/agent-docs/extensions.md +29 -3
  13. package/agent-docs/plugin-format.md +53 -2
  14. package/agent-docs/setup.md +54 -0
  15. package/dist/agent-template.d.ts +15 -6
  16. package/dist/agent-template.js +32 -13
  17. package/dist/avatar-presets.d.ts +8 -0
  18. package/dist/avatar-presets.js +17 -0
  19. package/dist/bootstrap.d.ts +86 -1
  20. package/dist/bootstrap.js +161 -2
  21. package/dist/cards.d.ts +67 -13
  22. package/dist/cards.js +91 -21
  23. package/dist/channel.d.ts +148 -48
  24. package/dist/channel.js +10 -5
  25. package/dist/client-css.d.ts +36 -0
  26. package/dist/client-css.js +326 -0
  27. package/dist/client-section.d.ts +35 -0
  28. package/dist/client-section.js +133 -0
  29. package/dist/config-ui.d.ts +22 -0
  30. package/dist/config-ui.js +64 -4
  31. package/dist/connector-auth.d.ts +7 -2
  32. package/dist/connector-auth.js +29 -8
  33. package/dist/connector.d.ts +74 -32
  34. package/dist/context.d.ts +40 -0
  35. package/dist/context.js +2 -0
  36. package/dist/ctx.d.ts +120 -29
  37. package/dist/define-extension.d.ts +26 -12
  38. package/dist/define-extension.js +11 -4
  39. package/dist/device-denied-paths.d.ts +14 -0
  40. package/dist/device-denied-paths.js +41 -0
  41. package/dist/device-operation.d.ts +302 -0
  42. package/dist/device-operation.js +292 -0
  43. package/dist/device-protocol.d.ts +490 -0
  44. package/dist/device-protocol.js +1117 -0
  45. package/dist/device-provider.d.ts +472 -0
  46. package/dist/device-provider.js +283 -0
  47. package/dist/extension-point.d.ts +2 -0
  48. package/dist/extension-point.js +6 -2
  49. package/dist/file-preview.d.ts +23 -6
  50. package/dist/git-hosts.d.ts +53 -0
  51. package/dist/git-hosts.js +98 -0
  52. package/dist/hooks.d.ts +125 -20
  53. package/dist/hooks.js +5 -0
  54. package/dist/http-access.d.ts +62 -0
  55. package/dist/http-access.js +12 -0
  56. package/dist/identity.d.ts +38 -9
  57. package/dist/identity.js +21 -1
  58. package/dist/index.d.ts +29 -2
  59. package/dist/index.js +29 -2
  60. package/dist/marketplace.d.ts +26 -0
  61. package/dist/marketplace.js +43 -1
  62. package/dist/model-params.d.ts +41 -22
  63. package/dist/model-params.js +28 -15
  64. package/dist/model.d.ts +206 -71
  65. package/dist/model.js +152 -19
  66. package/dist/net.d.ts +52 -0
  67. package/dist/net.js +34 -0
  68. package/dist/network-classes.d.ts +98 -0
  69. package/dist/network-classes.js +291 -0
  70. package/dist/permissions.d.ts +41 -21
  71. package/dist/permissions.js +101 -42
  72. package/dist/plugin-manifest.d.ts +45 -5
  73. package/dist/plugin-manifest.js +169 -6
  74. package/dist/plugin-package.d.ts +82 -38
  75. package/dist/plugin-package.js +61 -29
  76. package/dist/push.d.ts +75 -0
  77. package/dist/push.js +87 -0
  78. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  79. package/dist/sandbox-linux-runtime-source.js +2318 -0
  80. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  81. package/dist/sandbox-native-runtime-source.js +476 -0
  82. package/dist/sandbox-runtime-source.d.ts +19 -0
  83. package/dist/sandbox-runtime-source.js +28 -0
  84. package/dist/sandbox-write-denies.d.ts +139 -0
  85. package/dist/sandbox-write-denies.js +869 -0
  86. package/dist/secret.d.ts +4 -1
  87. package/dist/secret.js +4 -1
  88. package/dist/setup-check.d.ts +128 -0
  89. package/dist/setup-check.js +142 -0
  90. package/dist/setup-guide-parse.d.ts +135 -0
  91. package/dist/setup-guide-parse.js +413 -0
  92. package/dist/setup-guide-render.d.ts +50 -0
  93. package/dist/setup-guide-render.js +367 -0
  94. package/dist/setup-guide.d.ts +109 -0
  95. package/dist/setup-guide.js +377 -0
  96. package/dist/shell-capabilities.d.ts +231 -0
  97. package/dist/shell-capabilities.js +37 -0
  98. package/dist/shell-environment.d.ts +57 -0
  99. package/dist/shell-environment.js +22 -0
  100. package/dist/skill-invocation.d.ts +4 -3
  101. package/dist/skill-invocation.js +5 -4
  102. package/dist/skill.d.ts +34 -21
  103. package/dist/skill.js +49 -32
  104. package/dist/storage.d.ts +52 -25
  105. package/dist/theme-assets.d.ts +55 -0
  106. package/dist/theme-assets.js +507 -0
  107. package/dist/theme-readability.d.ts +37 -0
  108. package/dist/theme-readability.js +145 -0
  109. package/dist/theme-tokens.generated.d.ts +299 -0
  110. package/dist/theme-tokens.generated.js +184 -0
  111. package/dist/theme.d.ts +190 -0
  112. package/dist/theme.js +471 -0
  113. package/dist/tool.d.ts +69 -26
  114. package/dist/tool.js +29 -9
  115. package/dist/ui-parts.d.ts +23 -0
  116. package/dist/ui-parts.js +348 -0
  117. package/dist/ui-resolve.d.ts +35 -0
  118. package/dist/ui-resolve.js +42 -0
  119. package/dist/ui-slots.d.ts +65 -0
  120. package/dist/ui-slots.js +261 -0
  121. package/dist/ui.d.ts +212 -76
  122. package/dist/ui.js +101 -27
  123. package/dist/url.d.ts +4 -1
  124. package/dist/url.js +4 -1
  125. package/package.json +8 -1
  126. package/schemas/bootstrap-extra.v1.schema.json +172 -0
  127. package/schemas/bootstrap.v1.schema.json +6 -0
  128. package/schemas/connector-template.v1.schema.json +35 -0
  129. package/schemas/marketplace.v1.schema.json +14 -0
  130. package/schemas/plugin.v1.schema.json +117 -3
  131. package/schemas/theme.v1.schema.json +302 -0
  132. package/agent-docs/extension-points/sandbox.md +0 -15
  133. package/dist/sandbox.d.ts +0 -232
  134. package/dist/sandbox.js +0 -120
@@ -0,0 +1,490 @@
1
+ /**
2
+ * The device protocol: the WebSocket frames between the kernel and a `capybara-device` program
3
+ * (a connected machine that serves as a device). Pure types and hand-written guards.
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.
9
+ */
10
+ import { type SandboxPermissionSupport } from "./device-operation.js";
11
+ 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. */
13
+ export declare const DEVICE_PROTOCOL_VERSION = 5;
14
+ /**
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.
19
+ */
20
+ export declare const LEGACY_DEVICE_PROTOCOL_VERSION = 4;
21
+ /** 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";
23
+ /**
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`.
31
+ */
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;
35
+ /**
36
+ * What a device knows of its local policy and reports (in the hello or a `policy` op). The owner
37
+ * ceiling travels separately, in the owner report ({@link DeviceOwnerCeiling}).
38
+ */
39
+ export interface DeviceLocalPolicySummary {
40
+ /** The device's sandbox allowlist (the owner's `allowedDomains`). */
41
+ allowedDomains: string[];
42
+ }
43
+ /**
44
+ * A directory a `scan` found that looks like a project (it holds `.git` or `AGENTS.md`): a
45
+ * suggestion, not a project. `path` is absolute ({@link validateSandboxPathShape});
46
+ * `suggestedName` is a guess from its basename ({@link isDeviceProjectName}) the owner may change.
47
+ */
48
+ export interface DeviceProjectCandidate {
49
+ path: string;
50
+ suggestedName: string;
51
+ }
52
+ /** The most blocked hosts an exec result reports; the parser cuts longer lists. */
53
+ export declare const MAX_NETWORK_BLOCKED_HOSTS = 20;
54
+ /**
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.
57
+ */
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
+ export declare const DEVICE_BOOT_ID_RE: RegExp;
116
+ /** Whether `v` is a well-formed {@link LegacyDeviceHello.bootId}. */
117
+ export declare function isDeviceBootId(v: unknown): v is string;
118
+ /** Error kinds a device reports for a failed request. */
119
+ 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
+ export interface DeviceExecArgs {
160
+ command: string;
161
+ cwd?: string;
162
+ env?: Record<string, string>;
163
+ timeoutMs: number;
164
+ maxOutputBytes: number;
165
+ tag: string;
166
+ actor: SandboxActor;
167
+ limits: SandboxLimits;
168
+ /**
169
+ * Hosts the kernel allows for this command beyond the local policy (a run's "Allow this time" or
170
+ * a
171
+ * scheduled task's grants). A device applies them only in sandbox mode, within `limits`; a
172
+ * device without the feature ignores the field.
173
+ */
174
+ grants?: DeviceExecGrants;
175
+ }
176
+ /** Extra hosts for one exec and where they come from (logged by the device with the command). */
177
+ export interface DeviceExecGrants {
178
+ hosts: string[];
179
+ source: {
180
+ kind: "run" | "task";
181
+ id: string;
182
+ accountId: string;
183
+ };
184
+ }
185
+ export type DeviceExecResult = ExecResult;
186
+ export interface DeviceReadFileArgs {
187
+ path: string;
188
+ maxBytes: number;
189
+ }
190
+ export type DeviceReadFileResult = {
191
+ dataB64: string;
192
+ truncated: boolean;
193
+ } | null;
194
+ export interface DeviceWriteFileArgs {
195
+ path: string;
196
+ dataB64: string;
197
+ }
198
+ export type DeviceWriteFileResult = null;
199
+ export interface DeviceStatArgs {
200
+ path: string;
201
+ }
202
+ export type DeviceStatResult = {
203
+ size: number;
204
+ isDir: boolean;
205
+ } | null;
206
+ export interface DeviceKillTaggedArgs {
207
+ tags: string[];
208
+ }
209
+ export type DeviceKillAllArgs = Record<string, never>;
210
+ export interface DeviceCreateArgs {
211
+ limits: SandboxLimits;
212
+ }
213
+ export interface DeviceCreateResult {
214
+ roots: SandboxRoots;
215
+ }
216
+ export interface DeviceStopArgs {
217
+ reason: "revoked" | "deleted";
218
+ }
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
+ /**
261
+ * Lists one directory (absolute `path`, {@link validateSandboxPathShape}): at most `limit` entries
262
+ * (at most {@link MAX_DEVICE_LIST_ENTRIES}), read within the operation's scope. See
263
+ * `DeviceProvider.list` for the semantics.
264
+ */
265
+ export interface DeviceListArgs {
266
+ path: string;
267
+ limit: number;
268
+ }
269
+ /**
270
+ * One entry of a listed directory: `name` is never empty, `.` or `..` and holds no `/`. `isDir`
271
+ * follows symbolic links (stat semantics): a link to a directory is `true`, a dangling link `false`,
272
+ * and so is a link whose target the request's mode cannot reach.
273
+ */
274
+ export interface DeviceListEntry {
275
+ name: string;
276
+ isDir: boolean;
277
+ }
278
+ /**
279
+ * The directory's entries sorted by code unit, `truncated` when more than `limit` exist; null only
280
+ * when the path does not exist and the request's mode could reach it (like `stat` / `readFile`).
281
+ * A file, an unreadable directory, or a path the request's mode cannot reach is an error (the
282
+ * latter a `policy` refusal), never null.
283
+ */
284
+ export type DeviceListResult = {
285
+ entries: DeviceListEntry[];
286
+ truncated: boolean;
287
+ } | null;
288
+ /**
289
+ * Looks for project-like directories under `base` (absolute, {@link validateSandboxPathShape}),
290
+ * read within the operation's scope. A `base` that does not exist answers `[]`; a `base` that is a
291
+ * file, unreadable, or outside the request's scope is an error. See `DeviceProvider.scan` for the
292
+ * traversal.
293
+ */
294
+ export interface DeviceScanArgs {
295
+ base: string;
296
+ }
297
+ /**
298
+ * `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH} levels below it that
299
+ * hold a `.git` entry or an `AGENTS.md` file, sorted by `path` in code-unit order and cut to the
300
+ * first {@link MAX_DEVICE_SCAN_RESULTS}. Never file contents. See `DeviceProvider.scan`.
301
+ */
302
+ export type DeviceScanResult = DeviceProjectCandidate[];
303
+ /** A frame that is not valid device protocol (or came from the wrong side). */
304
+ export declare class DeviceProtocolError extends Error {
305
+ constructor(message: string);
306
+ }
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
+ /** Result type per op. */
313
+ export interface DeviceOpResults {
314
+ create: DeviceCreateResult;
315
+ exec: DeviceExecResult;
316
+ readFile: DeviceReadFileResult;
317
+ writeFile: DeviceWriteFileResult;
318
+ stat: DeviceStatResult;
319
+ killTagged: null;
320
+ killAll: null;
321
+ stop: null;
322
+ policy: LegacyDevicePolicyResult;
323
+ policyStatus: LegacyDevicePolicyStatus;
324
+ list: DeviceListResult;
325
+ scan: DeviceScanResult;
326
+ }
327
+ /** Validates the `result` of a successful `res` for `op`; throws {@link DeviceProtocolError}. */
328
+ export declare function parseOpResult<Op extends DeviceOp>(op: Op, result: unknown): DeviceOpResults[Op];
329
+ /**
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`).
339
+ */
340
+ export type DeviceOperation = Exclude<DeviceOp, "killTagged" | "killAll"> | "prepareReadFile" | "prepareWriteFile" | "prepareStat" | "browseStat" | "browseList" | "browseScan" | "backgroundStart" | "backgroundStatus" | "backgroundTail" | "backgroundReadOutput" | "backgroundStop" | "revokeOperation" | "bindInstance";
341
+ /** The sandbox network of a device: the open public internet or an allowlist. */
342
+ export type DeviceNetworkMode = "open" | "allowlist";
343
+ /**
344
+ * The owner ceiling of protocol 4 (approval-only profiles design, "Settings model"): the device
345
+ * sandbox for every profile. `outsideSandbox` is whether a call may be granted escalation outside
346
+ * the sandbox; `network` and `allowedDomains` are the sandbox network.
347
+ */
348
+ export interface DeviceOwnerCeiling {
349
+ readonly version: 3;
350
+ readonly sequence: number;
351
+ readonly revision: string;
352
+ readonly outsideSandbox: boolean;
353
+ readonly network: DeviceNetworkMode;
354
+ readonly allowedDomains: readonly string[];
355
+ readonly restrictedProjectReach: "workspace" | "os-user";
356
+ }
357
+ /**
358
+ * The narrowing of protocol 4: the kernel may switch the network to `allowlist`, remove hosts, turn
359
+ * `outsideSandbox` off or narrow the project reach. Never a widening: widening is decided on the
360
+ * machine by its owner (`capybara-device ceiling set`), never over the wire.
361
+ */
362
+ export interface DeviceOwnerCeilingNarrowing {
363
+ readonly outsideSandbox?: false;
364
+ readonly network?: "allowlist";
365
+ /** Hosts to remove from `allowedDomains`; a host not on the list is ignored. */
366
+ readonly removeAllowedDomains?: readonly string[];
367
+ readonly restrictedProjectReach?: "workspace";
368
+ }
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. */
383
+ export interface DevicePolicyChanged {
384
+ type: "policy";
385
+ policy?: DeviceLocalPolicySummary;
386
+ ownerCeiling: DeviceOwnerCeiling;
387
+ }
388
+ export interface DeviceHello extends LegacyDeviceHello {
389
+ protocol: typeof DEVICE_PROTOCOL_VERSION;
390
+ permissionSupport: SandboxPermissionSupport;
391
+ ownerCeiling: DeviceOwnerCeiling;
392
+ instanceGeneration: string | null;
393
+ transport: {
394
+ maxFrameBytes: number;
395
+ };
396
+ /** Absent until the program can attest actual installed runtime/helper/environment bytes. */
397
+ runtimeIdentity?: DeviceRuntimeIdentity;
398
+ }
399
+ /** A verified installed runtime/helper/environment identity bound to one instance generation. */
400
+ export interface DeviceRuntimeIdentity {
401
+ runtimeHash: string;
402
+ helperHash: string;
403
+ imageFingerprint: string;
404
+ instanceGeneration: string;
405
+ }
406
+ /**
407
+ * Private lifecycle request (permission runtime cutover B4): binds the kernel's committed instance
408
+ * generation to the device after commit. It carries no path, policy or manifest.
409
+ */
410
+ export interface BindInstanceRequest {
411
+ instanceId: string;
412
+ instanceGeneration: string;
413
+ bindingId: string;
414
+ expectedPreviousGeneration: string | null;
415
+ }
416
+ export interface BindInstanceResult {
417
+ instanceId: string;
418
+ instanceGeneration: string;
419
+ bindingId: string;
420
+ runtimeIdentity: DeviceRuntimeIdentity;
421
+ permissionSupport: SandboxPermissionSupport;
422
+ ownerCeiling: DeviceOwnerCeiling;
423
+ }
424
+ export interface KernelReady {
425
+ type: "ready";
426
+ connectionId: string;
427
+ maxFrameBytes: number;
428
+ }
429
+ export interface BackgroundReadOutputRequest {
430
+ offset: number;
431
+ maxBytes: number;
432
+ }
433
+ export type BackgroundReadOutputResult = {
434
+ dataB64: string;
435
+ offset: number;
436
+ nextOffset: number;
437
+ totalBytes: number;
438
+ } | {
439
+ unavailable: "lost" | "expired";
440
+ };
441
+ export interface KernelRequest {
442
+ type: "req";
443
+ id: string;
444
+ op: DeviceOperation;
445
+ args: Readonly<Record<string, unknown>>;
446
+ deadlineMs: number;
447
+ }
448
+ export type DeviceResponse = Exclude<DeviceRes, {
449
+ ok: false;
450
+ }> | {
451
+ type: "res";
452
+ id: string;
453
+ ok: false;
454
+ error: {
455
+ /**
456
+ * The typed failure: `denied`, `unsupported`, `unknown` and `invalid` carry the SDK's
457
+ * scope denial, unsupported permission, unknown outcome and scope validation errors.
458
+ * `invalid` never proves the operation had no effect (a skewed device may have parsed
459
+ * part of it): it must never join the not-run refusals (`isRefusal`, `failureKindOf`).
460
+ */
461
+ kind: "gone" | "fs_gone" | "policy" | "error" | "denied" | "unsupported" | "unsettled" | "unknown" | "invalid";
462
+ message: string;
463
+ };
464
+ };
465
+ export type DeviceFrame = DeviceHello | KernelReady | KernelRequest | KernelCancel | DeviceResponse | DevicePolicyChanged;
466
+ /**
467
+ * Strictly parses a runtime permission report, version 2 (the protocol 4 `permissionSupport`, also
468
+ * the shape a cloud provider reports), and returns a frozen copy; throws {@link DeviceProtocolError}.
469
+ * Restricted support is all four claims or `null`; per-operation hosts need the allowlist; an
470
+ * operation boundary without restricted support claims no sandbox network at all. An
471
+ * instance boundary is the whole instance: it claims no restricted per-operation scope, no
472
+ * outside-sandbox escalation and no per-operation hosts (a host joins the device's list instead).
473
+ */
474
+ export declare function parseSandboxPermissionSupport(value: unknown): SandboxPermissionSupport;
475
+ /**
476
+ * Strictly parses one authenticated owner-ceiling report of protocol 4 and returns a frozen copy;
477
+ * throws {@link DeviceProtocolError}. Unknown fields (the protocol 3 `fullAccess` and
478
+ * `restrictedAllowedDomains` among them) are refused.
479
+ */
480
+ export declare function parseOwnerCeilingReport(value: unknown): DeviceOwnerCeiling;
481
+ /**
482
+ * Strictly parses an owner-ceiling narrowing of protocol 4 and returns a frozen copy; throws
483
+ * {@link DeviceProtocolError}. Every field can only narrow: `outsideSandbox` only to `false`,
484
+ * `network` only to `allowlist`, the project reach only to `workspace`, and hosts only removed.
485
+ * There is no way to name a host to add or a list to replace.
486
+ */
487
+ 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;
490
+ export declare function parseOperationResult(op: DeviceOperation, result: unknown, request?: BackgroundReadOutputRequest | BindInstanceRequest): unknown;