@capybara-hq/plugin-sdk 0.1.0-rc.6 → 0.1.0-rc.60

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 (136) 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 +7 -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 +52 -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 +109 -1
  20. package/dist/bootstrap.js +185 -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 +15 -2
  32. package/dist/connector-auth.js +97 -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 +132 -29
  37. package/dist/define-extension.d.ts +26 -12
  38. package/dist/define-extension.js +12 -5
  39. package/dist/device-denied-paths.d.ts +18 -0
  40. package/dist/device-denied-paths.js +84 -0
  41. package/dist/device-operation.d.ts +333 -0
  42. package/dist/device-operation.js +312 -0
  43. package/dist/device-protocol.d.ts +285 -50
  44. package/dist/device-protocol.js +755 -90
  45. package/dist/device-provider.d.ts +500 -0
  46. package/dist/device-provider.js +302 -0
  47. package/dist/dial-in.d.ts +176 -0
  48. package/dist/dial-in.js +115 -0
  49. package/dist/extension-point.d.ts +2 -0
  50. package/dist/extension-point.js +6 -2
  51. package/dist/file-preview.d.ts +23 -6
  52. package/dist/git-hosts.d.ts +53 -0
  53. package/dist/git-hosts.js +98 -0
  54. package/dist/hooks.d.ts +125 -20
  55. package/dist/hooks.js +5 -0
  56. package/dist/http-access.d.ts +62 -0
  57. package/dist/http-access.js +12 -0
  58. package/dist/identity.d.ts +38 -9
  59. package/dist/identity.js +21 -1
  60. package/dist/index.d.ts +29 -3
  61. package/dist/index.js +29 -3
  62. package/dist/marketplace.d.ts +26 -0
  63. package/dist/marketplace.js +43 -1
  64. package/dist/model-params.d.ts +41 -22
  65. package/dist/model-params.js +28 -15
  66. package/dist/model.d.ts +206 -71
  67. package/dist/model.js +152 -19
  68. package/dist/net.d.ts +52 -0
  69. package/dist/net.js +34 -0
  70. package/dist/network-classes.d.ts +98 -0
  71. package/dist/network-classes.js +291 -0
  72. package/dist/permissions.d.ts +54 -22
  73. package/dist/permissions.js +119 -43
  74. package/dist/plugin-manifest.d.ts +45 -5
  75. package/dist/plugin-manifest.js +174 -6
  76. package/dist/plugin-package.d.ts +82 -38
  77. package/dist/plugin-package.js +61 -29
  78. package/dist/push.d.ts +75 -0
  79. package/dist/push.js +87 -0
  80. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  81. package/dist/sandbox-linux-runtime-source.js +2318 -0
  82. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  83. package/dist/sandbox-native-runtime-source.js +476 -0
  84. package/dist/sandbox-runtime-source.d.ts +19 -0
  85. package/dist/sandbox-runtime-source.js +28 -0
  86. package/dist/sandbox-write-denies.d.ts +139 -0
  87. package/dist/sandbox-write-denies.js +869 -0
  88. package/dist/secret.d.ts +4 -1
  89. package/dist/secret.js +4 -1
  90. package/dist/setup-check.d.ts +128 -0
  91. package/dist/setup-check.js +142 -0
  92. package/dist/setup-guide-parse.d.ts +121 -0
  93. package/dist/setup-guide-parse.js +356 -0
  94. package/dist/setup-guide-render.d.ts +45 -0
  95. package/dist/setup-guide-render.js +351 -0
  96. package/dist/setup-guide.d.ts +108 -0
  97. package/dist/setup-guide.js +367 -0
  98. package/dist/shell-capabilities.d.ts +211 -0
  99. package/dist/shell-capabilities.js +44 -0
  100. package/dist/shell-environment.d.ts +57 -0
  101. package/dist/shell-environment.js +21 -0
  102. package/dist/skill.d.ts +27 -17
  103. package/dist/skill.js +40 -26
  104. package/dist/storage.d.ts +52 -25
  105. package/dist/svg-viewbox.d.ts +10 -0
  106. package/dist/svg-viewbox.js +24 -0
  107. package/dist/theme-assets.d.ts +55 -0
  108. package/dist/theme-assets.js +489 -0
  109. package/dist/theme-readability.d.ts +37 -0
  110. package/dist/theme-readability.js +145 -0
  111. package/dist/theme-tokens.generated.d.ts +299 -0
  112. package/dist/theme-tokens.generated.js +184 -0
  113. package/dist/theme.d.ts +190 -0
  114. package/dist/theme.js +471 -0
  115. package/dist/tool.d.ts +99 -26
  116. package/dist/tool.js +29 -9
  117. package/dist/ui-parts.d.ts +23 -0
  118. package/dist/ui-parts.js +385 -0
  119. package/dist/ui-resolve.d.ts +35 -0
  120. package/dist/ui-resolve.js +42 -0
  121. package/dist/ui-slots.d.ts +65 -0
  122. package/dist/ui-slots.js +261 -0
  123. package/dist/ui.d.ts +212 -76
  124. package/dist/ui.js +101 -27
  125. package/dist/url.d.ts +4 -1
  126. package/dist/url.js +4 -1
  127. package/package.json +13 -1
  128. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  129. package/schemas/bootstrap.v1.schema.json +20 -0
  130. package/schemas/connector-template.v1.schema.json +35 -0
  131. package/schemas/marketplace.v1.schema.json +14 -0
  132. package/schemas/plugin.v1.schema.json +122 -3
  133. package/schemas/theme.v1.schema.json +302 -0
  134. package/agent-docs/extension-points/sandbox.md +0 -15
  135. package/dist/sandbox.d.ts +0 -254
  136. package/dist/sandbox.js +0 -153
@@ -0,0 +1,500 @@
1
+ /**
2
+ * Device provider contract `device-provider@1`: a multi, brokered, org-scoped extension point
3
+ * (extensions may not `requires` it; the kernel's `SandboxService` consumes it). The provider implements only the
4
+ * primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
5
+ * `writeFile`.
6
+ *
7
+ * A device separates its **file system** from its **instance**: the file system
8
+ * (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
9
+ * (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
10
+ */
11
+ import type { SandboxBackground, SandboxBrowse, SandboxBrowseScope, SandboxOperation, SandboxOperationRef, SandboxOperationScope, SandboxPermissionSupport, SandboxPreparation, SandboxPreparationScope } from "./device-operation.js";
12
+ import type { DialInHandler } from "./dial-in.js";
13
+ /** Device provider extension point ref. */
14
+ export declare const DEVICE_PROVIDER_EXTENSION_POINT = "device-provider@1";
15
+ /** The roots inside the sandbox the model may access. */
16
+ export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
17
+ /**
18
+ * Sandbox resource and network limits: what lifecycle create and update carry (resources and the
19
+ * outer network only; each operation's scope says how it runs). A provider that ignores `network`
20
+ * still runs: it then behaves as an allowlisted sandbox (the safe direction).
21
+ */
22
+ export interface SandboxLimits {
23
+ cpu: number;
24
+ memoryMb: number;
25
+ diskMb: number;
26
+ /**
27
+ * The network the instance (cloud) must enforce, or the allowlist a local device's sandbox
28
+ * intersects with its own list (`open-public` is for cloud instances only). Each entry of
29
+ * `hosts` passes {@link validateAllowHost}.
30
+ */
31
+ network: {
32
+ kind: "open-public" | "allowlist";
33
+ hosts: string[];
34
+ };
35
+ }
36
+ /** The absolute roots inside one instance (a device may place them anywhere on its host). */
37
+ export interface SandboxRoots {
38
+ workspace: string;
39
+ skills: string;
40
+ tmp: string;
41
+ }
42
+ /** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
43
+ export declare const DEFAULT_SANDBOX_ROOTS: Readonly<SandboxRoots>;
44
+ /** The provider's instance handle. */
45
+ export interface SandboxHandle {
46
+ /** The provider's instance id. */
47
+ id: string;
48
+ /** The instance's roots; absent means {@link DEFAULT_SANDBOX_ROOTS}. */
49
+ roots?: SandboxRoots;
50
+ }
51
+ /** The roots of an instance, falling back to {@link DEFAULT_SANDBOX_ROOTS}. */
52
+ export declare function rootsOf(h: SandboxHandle): SandboxRoots;
53
+ /** The provider's file system handle (a device's files, independent of any instance). */
54
+ export interface FileSystemHandle {
55
+ /** The provider's file system id. */
56
+ id: string;
57
+ }
58
+ /** Who runs an `exec` (informational in phase 1: audit and attribution). */
59
+ export interface SandboxActor {
60
+ accountId: string;
61
+ conversationId: string;
62
+ /**
63
+ * The run the command serves. The kernel uses it to route run grants (network hosts allowed
64
+ * for the rest of a run) to a connected device; informational for other providers.
65
+ */
66
+ runId?: string;
67
+ }
68
+ /**
69
+ * The layer that refused a network host: `device` (the org allows it, the device's local policy
70
+ * does not), `org` (not in the org's effective egress), `address` (an IP literal or a name that
71
+ * points to a private or local address; never grantable), `unknown`.
72
+ */
73
+ export type NetworkBlockLayer = "device" | "org" | "address" | "unknown";
74
+ /** A host a command was refused, as the provider reports it. */
75
+ export interface NetworkBlockedHost {
76
+ /** The host as the proxy saw it (IPv6 literals bracketed). */
77
+ host: string;
78
+ port: number;
79
+ layer: NetworkBlockLayer;
80
+ }
81
+ /** Result of a command. */
82
+ export interface ExecResult {
83
+ /** null on timeout or when aborted while running (`timedOut` is then true / false). */
84
+ exitCode: number | null;
85
+ stdout: string;
86
+ stderr: string;
87
+ truncated: boolean;
88
+ timedOut: boolean;
89
+ /**
90
+ * Network refusals during the command (optional for every provider): at most
91
+ * `MAX_NETWORK_BLOCKED_HOSTS` hosts, deduped by host. The kernel recomputes the `org` layer
92
+ * itself and never trusts a provider's word that the org allows a host.
93
+ */
94
+ network?: {
95
+ blocked: NetworkBlockedHost[];
96
+ };
97
+ }
98
+ /**
99
+ * The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
100
+ * `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
101
+ * instance gone; the kernel then rebuilds the instance and retries once. A transient connection
102
+ * failure throws a plain error. In a managed operation (`operation()`), a gone instance found
103
+ * **before** the request reached the machine throws a `DeviceRequestNotSentError` with this error
104
+ * as its `cause`: the operation is then recorded as not started rather than as an unknown outcome,
105
+ * and the instance is still rebuilt, so the call can be retried on it.
106
+ */
107
+ export declare class SandboxGoneError extends Error {
108
+ readonly sandboxGone: true;
109
+ constructor(message: string, opts?: {
110
+ cause?: unknown;
111
+ });
112
+ }
113
+ /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
114
+ export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
115
+ /**
116
+ * The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
117
+ * `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
118
+ * reports the device's files as lost rather than handing out a silently empty workspace.
119
+ */
120
+ export declare class FileSystemGoneError extends Error {
121
+ readonly fileSystemGone: true;
122
+ constructor(message: string, opts?: {
123
+ cause?: unknown;
124
+ });
125
+ }
126
+ /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
127
+ export declare function isFileSystemGoneError(e: unknown): e is FileSystemGoneError;
128
+ /**
129
+ * A holder tag (`exec` argument `tag`, {@link DeviceProvider.killTagged}): the kernel passes its
130
+ * lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
131
+ * kill pattern.
132
+ */
133
+ export declare const SANDBOX_TAG_RE: RegExp;
134
+ /** Text in English with an optional Chinese translation (what a person reads). */
135
+ export interface DeviceText {
136
+ en: string;
137
+ zh?: string;
138
+ }
139
+ /** The device a provider answers about: the kernel's device id, its org and the instance, if any. */
140
+ export interface DeviceRef {
141
+ deviceId: string;
142
+ orgId: string;
143
+ /** The current instance, or null when the device has none. */
144
+ handle: SandboxHandle | null;
145
+ }
146
+ /** One limit line of a {@link DeviceReport} (shown as is; the provider enforces it). */
147
+ export interface DeviceReportLimit {
148
+ label: DeviceText;
149
+ value: string;
150
+ }
151
+ /**
152
+ * What a provider tells about a device ({@link DeviceProvider.report}): shown to people, never
153
+ * used for enforcement. `revision` must change whenever anything that affects what was approved
154
+ * against the report changes (how operations are confined, what the device may reach): a new
155
+ * revision invalidates the approvals, grants and pending admissions bound to the old one.
156
+ * Display-only facts (for example the shared project roots shown as a limit line) may change
157
+ * without a revision change: announce such a change with `ctx.devices.reportChanged`, and the
158
+ * kernel stores the new text without invalidating anything. `home` is the owner's home directory
159
+ * (absolute) or null; `reset` says whether the provider can reset the device's files.
160
+ *
161
+ * `changeHint` (optional) says in the provider's own words who can change the device's limits and
162
+ * how (for a local connection: the machine's owner, with a command on that machine; for a
163
+ * container: the super admin's deployment config of the extension). The device page shows it
164
+ * under the limits, and the kernel appends it to a refusal that cites the report (an escalated
165
+ * call the provider does not allow now), so a person and the model learn the way out. State the
166
+ * mechanism, not advice for one situation.
167
+ */
168
+ export interface DeviceReport {
169
+ revision: string;
170
+ description: DeviceText;
171
+ home: string | null;
172
+ limits: DeviceReportLimit[];
173
+ reset: boolean;
174
+ changeHint?: DeviceText;
175
+ }
176
+ /** Size limits {@link parseDeviceReport} enforces. */
177
+ export declare const DEVICE_REPORT_LIMITS: Readonly<{
178
+ revisionChars: 128;
179
+ descriptionChars: 300;
180
+ limits: 8;
181
+ limitLabelChars: 60;
182
+ limitValueChars: 60;
183
+ homeChars: 4096;
184
+ changeHintChars: 400;
185
+ }>;
186
+ /** Checks a provider's report; throws `TypeError` on any other shape, returns a clean copy. */
187
+ export declare function parseDeviceReport(value: unknown): DeviceReport;
188
+ /**
189
+ * The provider refuses a project directory (`projects` operations: it lies where the provider
190
+ * will not serve, for example another connection's directory). `reason` is shown to the person.
191
+ * The kernel answers it as `device.project_refused` (422).
192
+ */
193
+ export declare class ProjectPathRefusedError extends Error {
194
+ readonly projectPathRefused: true;
195
+ readonly reason: DeviceText;
196
+ constructor(reason: DeviceText, opts?: {
197
+ cause?: unknown;
198
+ });
199
+ }
200
+ /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
201
+ export declare function isProjectPathRefusedError(e: unknown): e is ProjectPathRefusedError;
202
+ /**
203
+ * The `device-provider@1` implementation (provided by a sandbox plugin such as Docker or E2B).
204
+ *
205
+ * **File systems and instances.** `createFileSystem` makes a device's files; they live until
206
+ * `destroyFileSystem` (the device is deleted). `create` makes an instance attached to an
207
+ * existing file system; `destroy` / `destroyByName` drop the instance only and keep the files, and
208
+ * `suspend` keeps them too. When the file system is gone, `create` must throw
209
+ * {@link FileSystemGoneError} and never create an empty one in its place (a Docker provider checks
210
+ * its volumes exist before mounting them, because Docker would otherwise create empty volumes).
211
+ *
212
+ * **Gone instances.** When the instance is definitely gone: `resume` returns `gone`; `exec` /
213
+ * `readFile` / `writeFile` / `stat` / `killAll` / `killTagged` throw {@link SandboxGoneError};
214
+ * `suspend` / `destroy` succeed as usual.
215
+ *
216
+ * **Auto-start**: when the instance still exists but is stopped or paused (for a reason outside the
217
+ * kernel: host or daemon restart, a process in the sandbox stopping its init, an idle sweep that
218
+ * stopped the instance before recording `suspended`...), `exec` / `readFile` / `writeFile` /
219
+ * `stat` / `killAll` / `killTagged` must start it transparently first (like `resume`, files kept)
220
+ * and then run, never fail: the kernel trusts only the `running` it recorded itself. Auto-start
221
+ * must be idempotent under concurrent calls: two calls that both find the instance stopped both
222
+ * start it without failing.
223
+ *
224
+ * **Time limits apply inside the sandbox too**: besides stopping a command after `timeoutMs` on the
225
+ * provider's side, `exec` must make the command in the sandbox kill itself shortly (a few seconds)
226
+ * after `timeoutMs`. When a kernel replica crashes, the provider-side timer goes with it, and a
227
+ * dropped connection does not end the command; the in-sandbox limit keeps it from running
228
+ * indefinitely next to the next holder's commands.
229
+ *
230
+ * **Abort**: every method must respond to `signal` promptly (fail at once when already aborted, end
231
+ * with the abort reason as soon as possible when aborted mid-way): the kernel relies on it to stop
232
+ * on lock loss, run abort or timeout, and ignoring it may let two holders operate on one instance.
233
+ * An aborted `exec` must kill its running command (and the processes it spawned), not just stop
234
+ * waiting for its output; an `exec` aborted after its command started resolves normally with
235
+ * `exitCode: null`, `timedOut: false` (and the output collected so far), it does not reject. An
236
+ * `exec` called with an already aborted signal rejects at once.
237
+ *
238
+ * **Concurrent use** (required in `@2`): the sessions of one device share its instance, so the
239
+ * kernel calls `exec`, `readFile`, `writeFile` and `stat` concurrently on one instance. Those four
240
+ * methods must be safe to call concurrently. Each `exec` labels its command with its `tag`, and an
241
+ * aborted `exec` kills only its own command.
242
+ */
243
+ export interface DeviceProvider {
244
+ /** Runtime permission support for this instance; does not grant consent or provision an instance. */
245
+ permissionSupport?(h: SandboxHandle, signal: AbortSignal): Promise<SandboxPermissionSupport>;
246
+ /**
247
+ * Fresh immutable grant for one actual method invocation. Lightweight until a method is called;
248
+ * never cache grants on the handle or fall back to raw methods when unsupported.
249
+ */
250
+ operation?(h: SandboxHandle, scope: SandboxOperationScope, signal: AbortSignal): Promise<SandboxOperation>;
251
+ /** Trusted skill/attachment staging only; never exposed to user operations. */
252
+ prepare?(h: SandboxHandle, scope: SandboxPreparationScope, signal: AbortSignal): Promise<SandboxPreparation>;
253
+ /** Owner-authenticated metadata browsing without conversation/profile consent. */
254
+ browse?(h: SandboxHandle, scope: SandboxBrowseScope, signal: AbortSignal): Promise<SandboxBrowse>;
255
+ /**
256
+ * Required for permission support: idempotently persist an operation-ID tombstone before
257
+ * cancelling exact owned work. A delayed launch checks it before effects; retain it through
258
+ * admitBeforeMs and any owned execution's lifetime, including across kernel restarts.
259
+ */
260
+ revokeOperation?(h: SandboxHandle, ref: SandboxOperationRef, signal: AbortSignal): Promise<void>;
261
+ /** Exact registered background ownership; missing support must not fall back to shell launch. */
262
+ background?: SandboxBackground;
263
+ /** `exec` / `readFile` / `writeFile` / `stat` may run concurrently on one instance (required). */
264
+ readonly concurrentExec: true;
265
+ /**
266
+ * Declares that the provider enforces `limits.network` allowlists (required, always `true`):
267
+ * a provider that cannot restrict outbound hosts does not implement `device-provider@1`.
268
+ */
269
+ readonly networkAllowlist: true;
270
+ /**
271
+ * What the provider tells about the device: a description, the owner's home, limits and whether
272
+ * files can be reset ({@link DeviceReport}). Shown to people only; the answer passes
273
+ * {@link parseDeviceReport}. Must respond to `signal`.
274
+ */
275
+ report(device: DeviceRef, signal: AbortSignal): Promise<DeviceReport>;
276
+ /**
277
+ * The dial-in side of the provider, for an extension declaring `permissions.dialIn`: the kernel
278
+ * hands it the hellos and unsolicited frames of the machines serving its devices.
279
+ */
280
+ readonly dialIn?: DialInHandler;
281
+ /**
282
+ * Whether the provider isolates the sessions of one device from each other inside the
283
+ * instance (a declared capability; absent means false).
284
+ */
285
+ readonly sessionIsolation?: boolean;
286
+ /**
287
+ * Where `create`-time limits are fixed: `instance` (absent; Docker: a new instance applies new
288
+ * limits) or `fileSystem` (E2B: the instance is the file system, so only a file reset applies
289
+ * them without {@link DeviceProvider.update}).
290
+ */
291
+ readonly limitsApplyAt?: "instance" | "fileSystem";
292
+ /**
293
+ * Applies new limits to a running instance without recreating it (optional). `recreate` asks
294
+ * the kernel to destroy the instance and create one on the same files instead.
295
+ */
296
+ update?(h: SandboxHandle, limits: SandboxLimits, signal: AbortSignal): Promise<"updated" | "recreate">;
297
+ /**
298
+ * Creates a device's file system. `name` looks like `cap-device-<deviceId>`. If a file
299
+ * system with this name already exists, return it.
300
+ */
301
+ createFileSystem(args: {
302
+ name: string;
303
+ limits: SandboxLimits;
304
+ signal: AbortSignal;
305
+ }): Promise<FileSystemHandle>;
306
+ /** Deletes the file system and its files. Succeeds when it does not exist. */
307
+ destroyFileSystem(fs: FileSystemHandle, signal: AbortSignal): Promise<void>;
308
+ /**
309
+ * Deletes the file system made under `name` by `createFileSystem`; succeeds when there is none.
310
+ * The kernel uses it when it has no handle (`createFileSystem` finished on the provider's side
311
+ * but the kernel stopped before recording the handle), and in its one-off cleanup of
312
+ * per-conversation sandboxes with `cap-<conversationId>` names that a `sandbox@1` provider's
313
+ * `create` made together with their files (Docker: the `cap-<conversationId>-workspace` and
314
+ * `-skills` volumes); a provider removes those under the same call.
315
+ */
316
+ destroyFileSystemByName(name: string, signal: AbortSignal): Promise<void>;
317
+ /**
318
+ * Creates an instance attached to `fileSystem`. Without `image` the provider uses its own
319
+ * published image. Throws {@link FileSystemGoneError} when the file system is gone.
320
+ */
321
+ create(args: {
322
+ name: string;
323
+ image?: string;
324
+ limits: SandboxLimits;
325
+ fileSystem: FileSystemHandle;
326
+ signal: AbortSignal;
327
+ }): Promise<SandboxHandle>;
328
+ /** `gone` means the provider no longer has this instance. */
329
+ resume(h: SandboxHandle, signal: AbortSignal): Promise<"resumed" | "gone">;
330
+ /** Files must be kept. Succeeds when the instance does not exist. */
331
+ suspend(h: SandboxHandle, signal: AbortSignal): Promise<void>;
332
+ /** Drops the instance only; the file system and its files are kept. Succeeds when it does not exist. */
333
+ destroy(h: SandboxHandle, signal: AbortSignal): Promise<void>;
334
+ /**
335
+ * Drops the instance made under `name` by `create` (instance only, files kept); succeeds when
336
+ * there is none. The kernel uses it when it has no handle (`create` finished on the provider's
337
+ * side but the kernel stopped before recording the handle), and in its one-off cleanup of
338
+ * per-conversation sandboxes with `cap-<conversationId>` names made by a `sandbox@1` provider's
339
+ * `create`.
340
+ */
341
+ destroyByName(name: string, signal: AbortSignal): Promise<void>;
342
+ /**
343
+ * Kills every running command started through `exec` in this instance (and the processes they
344
+ * spawned that did not start their own session). The kernel calls it only when no other holder
345
+ * can be running commands (an instance just resumed from `suspended`, or under the exclusive
346
+ * lease), never while another session may be; to clean up after one crashed holder it uses
347
+ * {@link DeviceProvider.killTagged}. Processes a command put in the background in their own
348
+ * session are not guaranteed to be killed.
349
+ */
350
+ killAll(h: SandboxHandle, signal: AbortSignal): Promise<void>;
351
+ /**
352
+ * Kills every running `exec` command labelled with one of `tags` (and its process tree), leaving
353
+ * other commands running. The kernel calls it for the tags of holders that crashed while live
354
+ * holders keep running commands. Tags match {@link SANDBOX_TAG_RE}. Match whole tags: one tag
355
+ * may be a prefix of another (`ab` of `ab-cd`), and killing `ab` must not touch `ab-cd`'s
356
+ * commands.
357
+ */
358
+ killTagged(h: SandboxHandle, tags: string[], signal: AbortSignal): Promise<void>;
359
+ /**
360
+ * Runs a command. `maxOutputBytes` caps stdout and stderr **combined**; the rest is dropped and
361
+ * `truncated` is true.
362
+ */
363
+ exec(h: SandboxHandle, args: {
364
+ command: string;
365
+ cwd?: string;
366
+ env?: Record<string, string>;
367
+ timeoutMs: number;
368
+ maxOutputBytes: number;
369
+ signal: AbortSignal;
370
+ /**
371
+ * The holder's tag ({@link SANDBOX_TAG_RE}); label the command with it so
372
+ * {@link DeviceProvider.killTagged} can find it.
373
+ */
374
+ tag: string;
375
+ /** Who runs the command; informational in phase 1 (record it, do not act on it). */
376
+ actor: SandboxActor;
377
+ }): Promise<ExecResult>;
378
+ /**
379
+ * Reads a file (at most `maxBytes`; longer files are truncated and `truncated` is true). Returns
380
+ * null when it does not exist or is a directory.
381
+ */
382
+ readFile(h: SandboxHandle, path: string, opts: {
383
+ maxBytes: number;
384
+ signal: AbortSignal;
385
+ }): Promise<{
386
+ data: Uint8Array;
387
+ truncated: boolean;
388
+ } | null>;
389
+ /** Parent directories are created. */
390
+ writeFile(h: SandboxHandle, path: string, data: Uint8Array, signal: AbortSignal): Promise<void>;
391
+ stat(h: SandboxHandle, path: string, signal: AbortSignal): Promise<{
392
+ size: number;
393
+ isDir: boolean;
394
+ } | null>;
395
+ /**
396
+ * Lists one directory's entries — each entry's `name` and whether it `isDir` — sorted by code
397
+ * unit (locale-independent), at most `limit` of them; `truncated` is true when the directory has
398
+ * more. Entries only: never file contents, never a recursive walk. A `name` is never `.` or `..`;
399
+ * `isDir` follows symbolic links (stat semantics: a link to a directory is `true`, a dangling link
400
+ * `false`, and so is a link whose target the device cannot reach). Returns null only when the
401
+ * path does not exist and the device could reach it; a path it cannot reach throws (a policy
402
+ * refusal), as does a path that is a file or a directory that cannot be read.
403
+ *
404
+ * Optional: a provider without it (or without {@link DeviceProvider.scan}) offers no projects,
405
+ * and its conversations stay in free mode.
406
+ */
407
+ list?(h: SandboxHandle, path: string, opts: {
408
+ limit: number;
409
+ signal: AbortSignal;
410
+ }): Promise<{
411
+ entries: {
412
+ name: string;
413
+ isDir: boolean;
414
+ }[];
415
+ truncated: boolean;
416
+ } | null>;
417
+ /**
418
+ * Looks for project-like directories, read as for {@link DeviceProvider.list}. Every provider
419
+ * traverses the same way:
420
+ *
421
+ * - Candidates are `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH}
422
+ * levels below it that hold a `.git` entry (directory or file) or an `AGENTS.md` file.
423
+ * - The walk does not follow symbolic links and does not enter hidden directories (names
424
+ * starting with `.`); a candidate does not stop the descent (a monorepo's sub-projects are
425
+ * candidates too). It never enters a directory named in {@link DEVICE_SCAN_SKIPPED_DIRS}, at
426
+ * any depth, nor one named in {@link DEVICE_SCAN_SKIPPED_BASE_DIRS} directly under `base`;
427
+ * every provider skips exactly these. Paths under `base` the device cannot reach are skipped,
428
+ * never an error.
429
+ * - A directory whose basename does not satisfy {@link isDeviceProjectName} is not returned as
430
+ * a candidate (never with a changed name), but it is still traversed.
431
+ * - Directories are visited breadth-first, each level in code-unit order of `path`, `base`
432
+ * counting as the first visit (visiting a directory reads its entries; one that cannot be read
433
+ * still counts as a visit); the walk stops after {@link MAX_DEVICE_SCAN_DIRS} visits, so a
434
+ * huge tree answers what was found by then.
435
+ * - Each candidate is its absolute `path` and its basename as `suggestedName`; the candidates
436
+ * found are sorted by `path` in code-unit order and cut to the first
437
+ * {@link MAX_DEVICE_SCAN_RESULTS}.
438
+ *
439
+ * Directory entries only, never file contents. A `base` that does not exist answers `[]`; a
440
+ * `base` that is a file, cannot be read, or lies outside what the device reaches throws.
441
+ * Optional, like `list`.
442
+ */
443
+ scan?(h: SandboxHandle, base: string, opts: {
444
+ signal: AbortSignal;
445
+ }): Promise<{
446
+ path: string;
447
+ suggestedName: string;
448
+ }[]>;
449
+ }
450
+ /**
451
+ * The most entries a `list` may ask for and its result may carry ({@link DeviceProvider.list}):
452
+ * part of the provider contract, which the device protocol's `list` op also honors.
453
+ */
454
+ export declare const MAX_DEVICE_LIST_ENTRIES = 1000;
455
+ /** The longest project name, in UTF-16 code units. */
456
+ export declare const MAX_DEVICE_PROJECT_NAME_LENGTH = 64;
457
+ /** The most candidates a `scan` answers ({@link DeviceProvider.scan}). */
458
+ export declare const MAX_DEVICE_SCAN_RESULTS = 50;
459
+ /**
460
+ * Directory names a `scan` never enters, at any depth ({@link DeviceProvider.scan}): dependency
461
+ * trees, not projects. Every provider skips exactly these.
462
+ */
463
+ export declare const DEVICE_SCAN_SKIPPED_DIRS: readonly string[];
464
+ /**
465
+ * Directory names a `scan` does not enter directly under its `base` ({@link DeviceProvider.scan}):
466
+ * the owner's macOS `Library` (app data, huge, partly privacy-protected) is not where projects
467
+ * live. Every provider skips exactly these.
468
+ */
469
+ export declare const DEVICE_SCAN_SKIPPED_BASE_DIRS: readonly string[];
470
+ /** How far below its base a `scan` looks: the base's children and their children. */
471
+ export declare const MAX_DEVICE_SCAN_DEPTH = 2;
472
+ /**
473
+ * The most directories one `scan` visits (reads the entries of), its `base` included
474
+ * ({@link DeviceProvider.scan}): breadth-first, each level in code-unit order of path.
475
+ */
476
+ export declare const MAX_DEVICE_SCAN_DIRS = 500;
477
+ /**
478
+ * Whether `v` is a valid project name (a project's identity on its device, and a `scan`
479
+ * candidate's `suggestedName`): non-empty, at most {@link MAX_DEVICE_PROJECT_NAME_LENGTH} UTF-16
480
+ * code units, not `.` or `..`, no `/`, no control characters, and no leading or trailing
481
+ * whitespace.
482
+ */
483
+ export declare function isDeviceProjectName(v: unknown): v is string;
484
+ /**
485
+ * The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
486
+ * control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
487
+ * empty when valid. {@link validateSandboxPath} adds root membership.
488
+ */
489
+ export declare function validateSandboxPathShape(p: string): string[];
490
+ /**
491
+ * Checks a path inside an instance; returns the errors, empty when valid: the
492
+ * {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
493
+ * ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
494
+ */
495
+ export declare function validateSandboxPath(p: string, roots?: SandboxRoots): string[];
496
+ /**
497
+ * Validates an outbound allowlist host name: lowercase, no protocol or port, optional leading `*.`,
498
+ * IDN accepted only as punycode.
499
+ */
500
+ export declare function validateAllowHost(h: string): string[];