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

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 (130) hide show
  1. package/agent-docs/agent-templates.md +14 -2
  2. package/agent-docs/concepts.md +14 -5
  3. package/agent-docs/connector-templates.md +4 -1
  4. package/agent-docs/extension-points/channel.md +1 -1
  5. package/agent-docs/extension-points/context.md +15 -0
  6. package/agent-docs/extension-points/file-preview.md +2 -0
  7. package/agent-docs/extension-points/model-provider.md +3 -1
  8. package/agent-docs/extension-points/object-store.md +2 -0
  9. package/agent-docs/extension-points/push-provider.md +17 -0
  10. package/agent-docs/extension-points/sandbox.md +2 -2
  11. package/agent-docs/extensions.md +29 -3
  12. package/agent-docs/plugin-format.md +48 -2
  13. package/agent-docs/setup.md +54 -0
  14. package/dist/agent-template.d.ts +15 -6
  15. package/dist/agent-template.js +32 -13
  16. package/dist/avatar-presets.d.ts +8 -0
  17. package/dist/avatar-presets.js +17 -0
  18. package/dist/bootstrap.d.ts +86 -1
  19. package/dist/bootstrap.js +161 -2
  20. package/dist/cards.d.ts +67 -13
  21. package/dist/cards.js +91 -21
  22. package/dist/channel.d.ts +148 -48
  23. package/dist/channel.js +10 -5
  24. package/dist/client-css.d.ts +36 -0
  25. package/dist/client-css.js +326 -0
  26. package/dist/client-section.d.ts +35 -0
  27. package/dist/client-section.js +133 -0
  28. package/dist/config-ui.d.ts +22 -0
  29. package/dist/config-ui.js +64 -4
  30. package/dist/connector-auth.d.ts +7 -2
  31. package/dist/connector-auth.js +29 -8
  32. package/dist/connector.d.ts +74 -32
  33. package/dist/context.d.ts +40 -0
  34. package/dist/context.js +2 -0
  35. package/dist/ctx.d.ts +120 -29
  36. package/dist/define-extension.d.ts +26 -12
  37. package/dist/define-extension.js +11 -4
  38. package/dist/device-denied-paths.d.ts +14 -0
  39. package/dist/device-denied-paths.js +41 -0
  40. package/dist/device-protocol.d.ts +489 -0
  41. package/dist/device-protocol.js +1116 -0
  42. package/dist/extension-point.d.ts +2 -0
  43. package/dist/extension-point.js +6 -2
  44. package/dist/file-preview.d.ts +23 -6
  45. package/dist/git-hosts.d.ts +53 -0
  46. package/dist/git-hosts.js +98 -0
  47. package/dist/hooks.d.ts +125 -20
  48. package/dist/hooks.js +5 -0
  49. package/dist/http-access.d.ts +62 -0
  50. package/dist/http-access.js +12 -0
  51. package/dist/identity.d.ts +38 -9
  52. package/dist/identity.js +21 -1
  53. package/dist/index.d.ts +28 -1
  54. package/dist/index.js +28 -1
  55. package/dist/marketplace.d.ts +26 -0
  56. package/dist/marketplace.js +43 -1
  57. package/dist/model-params.d.ts +41 -22
  58. package/dist/model-params.js +28 -15
  59. package/dist/model.d.ts +206 -71
  60. package/dist/model.js +152 -19
  61. package/dist/net.d.ts +52 -0
  62. package/dist/net.js +34 -0
  63. package/dist/network-classes.d.ts +98 -0
  64. package/dist/network-classes.js +291 -0
  65. package/dist/permissions.d.ts +41 -21
  66. package/dist/permissions.js +101 -42
  67. package/dist/plugin-manifest.d.ts +45 -5
  68. package/dist/plugin-manifest.js +169 -6
  69. package/dist/plugin-package.d.ts +82 -38
  70. package/dist/plugin-package.js +61 -29
  71. package/dist/push.d.ts +75 -0
  72. package/dist/push.js +87 -0
  73. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  74. package/dist/sandbox-linux-runtime-source.js +2318 -0
  75. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  76. package/dist/sandbox-native-runtime-source.js +476 -0
  77. package/dist/sandbox-operation.d.ts +298 -0
  78. package/dist/sandbox-operation.js +282 -0
  79. package/dist/sandbox-runtime-source.d.ts +19 -0
  80. package/dist/sandbox-runtime-source.js +28 -0
  81. package/dist/sandbox-write-denies.d.ts +139 -0
  82. package/dist/sandbox-write-denies.js +869 -0
  83. package/dist/sandbox.d.ts +190 -16
  84. package/dist/sandbox.js +89 -14
  85. package/dist/secret.d.ts +4 -1
  86. package/dist/secret.js +4 -1
  87. package/dist/setup-check.d.ts +128 -0
  88. package/dist/setup-check.js +142 -0
  89. package/dist/setup-guide-parse.d.ts +121 -0
  90. package/dist/setup-guide-parse.js +350 -0
  91. package/dist/setup-guide-render.d.ts +45 -0
  92. package/dist/setup-guide-render.js +351 -0
  93. package/dist/setup-guide.d.ts +96 -0
  94. package/dist/setup-guide.js +348 -0
  95. package/dist/shell-capabilities.d.ts +231 -0
  96. package/dist/shell-capabilities.js +37 -0
  97. package/dist/shell-environment.d.ts +57 -0
  98. package/dist/shell-environment.js +22 -0
  99. package/dist/skill-invocation.d.ts +4 -3
  100. package/dist/skill-invocation.js +5 -4
  101. package/dist/skill.d.ts +34 -21
  102. package/dist/skill.js +48 -31
  103. package/dist/storage.d.ts +52 -25
  104. package/dist/theme-assets.d.ts +55 -0
  105. package/dist/theme-assets.js +507 -0
  106. package/dist/theme-readability.d.ts +37 -0
  107. package/dist/theme-readability.js +145 -0
  108. package/dist/theme-tokens.generated.d.ts +299 -0
  109. package/dist/theme-tokens.generated.js +184 -0
  110. package/dist/theme.d.ts +190 -0
  111. package/dist/theme.js +471 -0
  112. package/dist/tool.d.ts +69 -26
  113. package/dist/tool.js +29 -9
  114. package/dist/ui-parts.d.ts +23 -0
  115. package/dist/ui-parts.js +348 -0
  116. package/dist/ui-resolve.d.ts +35 -0
  117. package/dist/ui-resolve.js +42 -0
  118. package/dist/ui-slots.d.ts +65 -0
  119. package/dist/ui-slots.js +261 -0
  120. package/dist/ui.d.ts +212 -76
  121. package/dist/ui.js +101 -27
  122. package/dist/url.d.ts +4 -1
  123. package/dist/url.js +4 -1
  124. package/package.json +8 -1
  125. package/schemas/bootstrap-extra.v1.schema.json +172 -0
  126. package/schemas/bootstrap.v1.schema.json +6 -0
  127. package/schemas/connector-template.v1.schema.json +35 -0
  128. package/schemas/marketplace.v1.schema.json +14 -0
  129. package/schemas/plugin.v1.schema.json +116 -3
  130. package/schemas/theme.v1.schema.json +302 -0
package/dist/sandbox.d.ts CHANGED
@@ -4,29 +4,52 @@
4
4
  * primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
5
5
  * `writeFile`.
6
6
  *
7
- * `@2` separates an environment's **file system** from its **instance**: the file system
8
- * (`createFileSystem`) lives until the environment is deleted (`destroyFileSystem`); instances
7
+ * `@2` separates a device's **file system** from its **instance**: the file system
8
+ * (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
9
9
  * (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
10
10
  */
11
+ import type { SandboxBackground, SandboxBrowse, SandboxBrowseScope, SandboxOperation, SandboxOperationRef, SandboxOperationScope, SandboxPermissionSupport, SandboxPreparation, SandboxPreparationScope } from "./sandbox-operation.js";
11
12
  /** Sandbox extension point ref. */
12
13
  export declare const SANDBOX_EXTENSION_POINT = "sandbox@2";
13
14
  /** The roots inside the sandbox the model may access. */
14
15
  export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
15
- /** Sandbox resource and egress limits. */
16
+ /**
17
+ * Sandbox resource and network limits: what lifecycle create and update carry (resources and the
18
+ * outer network only; each operation's scope says how it runs). A provider that ignores `network`
19
+ * still runs: it then behaves as an allowlisted sandbox (the safe direction).
20
+ */
16
21
  export interface SandboxLimits {
17
22
  cpu: number;
18
23
  memoryMb: number;
19
24
  diskMb: number;
20
- egress: "none" | "allowlist" | "open";
21
- /** Egress allowlist (used when `egress` is `allowlist`); each entry passes {@link validateAllowHost}. */
22
- allowHosts: string[];
25
+ /**
26
+ * The network the instance (cloud) must enforce, or the allowlist a local device's sandbox
27
+ * intersects with its own list (`open-public` is for cloud instances only). Each entry of
28
+ * `hosts` passes {@link validateAllowHost}.
29
+ */
30
+ network: {
31
+ kind: "open-public" | "allowlist";
32
+ hosts: string[];
33
+ };
34
+ }
35
+ /** The absolute roots inside one instance (a device may place them anywhere on its host). */
36
+ export interface SandboxRoots {
37
+ workspace: string;
38
+ skills: string;
39
+ tmp: string;
23
40
  }
41
+ /** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
42
+ export declare const DEFAULT_SANDBOX_ROOTS: Readonly<SandboxRoots>;
24
43
  /** The provider's instance handle. */
25
44
  export interface SandboxHandle {
26
45
  /** The provider's instance id. */
27
46
  id: string;
47
+ /** The instance's roots; absent means {@link DEFAULT_SANDBOX_ROOTS}. */
48
+ roots?: SandboxRoots;
28
49
  }
29
- /** The provider's file system handle (an environment's files, independent of any instance). */
50
+ /** The roots of an instance, falling back to {@link DEFAULT_SANDBOX_ROOTS}. */
51
+ export declare function rootsOf(h: SandboxHandle): SandboxRoots;
52
+ /** The provider's file system handle (a device's files, independent of any instance). */
30
53
  export interface FileSystemHandle {
31
54
  /** The provider's file system id. */
32
55
  id: string;
@@ -35,6 +58,24 @@ export interface FileSystemHandle {
35
58
  export interface SandboxActor {
36
59
  accountId: string;
37
60
  conversationId: string;
61
+ /**
62
+ * The run the command serves. The kernel uses it to route run grants (network hosts allowed
63
+ * for the rest of a run) to a connected device; informational for other providers.
64
+ */
65
+ runId?: string;
66
+ }
67
+ /**
68
+ * The layer that refused a network host: `device` (the org allows it, the device's local policy
69
+ * does not), `org` (not in the org's effective egress), `address` (an IP literal or a name that
70
+ * points to a private or local address; never grantable), `unknown`.
71
+ */
72
+ export type NetworkBlockLayer = "device" | "org" | "address" | "unknown";
73
+ /** A host a command was refused, as the provider reports it. */
74
+ export interface NetworkBlockedHost {
75
+ /** The host as the proxy saw it (IPv6 literals bracketed). */
76
+ host: string;
77
+ port: number;
78
+ layer: NetworkBlockLayer;
38
79
  }
39
80
  /** Result of a command. */
40
81
  export interface ExecResult {
@@ -44,6 +85,14 @@ export interface ExecResult {
44
85
  stderr: string;
45
86
  truncated: boolean;
46
87
  timedOut: boolean;
88
+ /**
89
+ * Network refusals during the command (optional for every provider): at most
90
+ * `MAX_NETWORK_BLOCKED_HOSTS` hosts, deduped by host. The kernel recomputes the `org` layer
91
+ * itself and never trusts a provider's word that the org allows a host.
92
+ */
93
+ network?: {
94
+ blocked: NetworkBlockedHost[];
95
+ };
47
96
  }
48
97
  /**
49
98
  * The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
@@ -62,7 +111,7 @@ export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
62
111
  /**
63
112
  * The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
64
113
  * `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
65
- * reports the environment's files as lost rather than handing out a silently empty workspace.
114
+ * reports the device's files as lost rather than handing out a silently empty workspace.
66
115
  */
67
116
  export declare class FileSystemGoneError extends Error {
68
117
  readonly fileSystemGone: true;
@@ -81,8 +130,8 @@ export declare const SANDBOX_TAG_RE: RegExp;
81
130
  /**
82
131
  * The `sandbox@2` implementation (provided by a sandbox plugin such as Docker or E2B).
83
132
  *
84
- * **File systems and instances.** `createFileSystem` makes an environment's files; they live until
85
- * `destroyFileSystem` (the environment is deleted). `create` makes an instance attached to an
133
+ * **File systems and instances.** `createFileSystem` makes a device's files; they live until
134
+ * `destroyFileSystem` (the device is deleted). `create` makes an instance attached to an
86
135
  * existing file system; `destroy` / `destroyByName` drop the instance only and keep the files, and
87
136
  * `suspend` keeps them too. When the file system is gone, `create` must throw
88
137
  * {@link FileSystemGoneError} and never create an empty one in its place (a Docker provider checks
@@ -114,21 +163,51 @@ export declare const SANDBOX_TAG_RE: RegExp;
114
163
  * `exitCode: null`, `timedOut: false` (and the output collected so far), it does not reject. An
115
164
  * `exec` called with an already aborted signal rejects at once.
116
165
  *
117
- * **Concurrent use** (required in `@2`): the sessions of one environment share its instance, so the
166
+ * **Concurrent use** (required in `@2`): the sessions of one device share its instance, so the
118
167
  * kernel calls `exec`, `readFile`, `writeFile` and `stat` concurrently on one instance. Those four
119
168
  * methods must be safe to call concurrently. Each `exec` labels its command with its `tag`, and an
120
169
  * aborted `exec` kills only its own command.
121
170
  */
122
171
  export interface SandboxProvider {
172
+ /** Runtime permission support for this instance; does not grant consent or provision an instance. */
173
+ permissionSupport?(h: SandboxHandle, signal: AbortSignal): Promise<SandboxPermissionSupport>;
174
+ /**
175
+ * Fresh immutable grant for one actual method invocation. Lightweight until a method is called;
176
+ * never cache grants on the handle or fall back to raw methods when unsupported.
177
+ */
178
+ operation?(h: SandboxHandle, scope: SandboxOperationScope, signal: AbortSignal): Promise<SandboxOperation>;
179
+ /** Trusted skill/attachment staging only; never exposed to user operations. */
180
+ prepare?(h: SandboxHandle, scope: SandboxPreparationScope, signal: AbortSignal): Promise<SandboxPreparation>;
181
+ /** Owner-authenticated metadata browsing without conversation/profile consent. */
182
+ browse?(h: SandboxHandle, scope: SandboxBrowseScope, signal: AbortSignal): Promise<SandboxBrowse>;
183
+ /**
184
+ * Required for permission support: idempotently persist an operation-ID tombstone before
185
+ * cancelling exact owned work. A delayed launch checks it before effects; retain it through
186
+ * admitBeforeMs and any owned execution's lifetime, including across kernel restarts.
187
+ */
188
+ revokeOperation?(h: SandboxHandle, ref: SandboxOperationRef, signal: AbortSignal): Promise<void>;
189
+ /** Exact registered background ownership; missing support must not fall back to shell launch. */
190
+ background?: SandboxBackground;
123
191
  /** `exec` / `readFile` / `writeFile` / `stat` may run concurrently on one instance (required). */
124
192
  readonly concurrentExec: true;
125
193
  /**
126
- * Whether the provider isolates the sessions of one environment from each other inside the
194
+ * Whether the provider isolates the sessions of one device from each other inside the
127
195
  * instance (a declared capability; absent means false).
128
196
  */
129
197
  readonly sessionIsolation?: boolean;
130
198
  /**
131
- * Creates an environment's file system. `name` looks like `cap-env-<environmentId>`. If a file
199
+ * Where `create`-time limits are fixed: `instance` (absent; Docker: a new instance applies new
200
+ * limits) or `fileSystem` (E2B: the instance is the file system, so only a file reset applies
201
+ * them without {@link SandboxProvider.update}).
202
+ */
203
+ readonly limitsApplyAt?: "instance" | "fileSystem";
204
+ /**
205
+ * Applies new limits to a running instance without recreating it (optional). `recreate` asks
206
+ * the kernel to destroy the instance and create one on the same files instead.
207
+ */
208
+ update?(h: SandboxHandle, limits: SandboxLimits, signal: AbortSignal): Promise<"updated" | "recreate">;
209
+ /**
210
+ * Creates a device's file system. `name` looks like `cap-device-<deviceId>`. If a file
132
211
  * system with this name already exists, return it.
133
212
  */
134
213
  createFileSystem(args: {
@@ -225,8 +304,103 @@ export interface SandboxProvider {
225
304
  size: number;
226
305
  isDir: boolean;
227
306
  } | null>;
307
+ /**
308
+ * Lists one directory's entries — each entry's `name` and whether it `isDir` — sorted by code
309
+ * unit (locale-independent), at most `limit` of them; `truncated` is true when the directory has
310
+ * more. Entries only: never file contents, never a recursive walk. A `name` is never `.` or `..`;
311
+ * `isDir` follows symbolic links (stat semantics: a link to a directory is `true`, a dangling link
312
+ * `false`, and so is a link whose target the device cannot reach). Returns null only when the
313
+ * path does not exist and the device could reach it; a path it cannot reach throws (a policy
314
+ * refusal), as does a path that is a file or a directory that cannot be read.
315
+ *
316
+ * Optional: a provider without it (or without {@link SandboxProvider.scan}) offers no projects,
317
+ * and its conversations stay in free mode.
318
+ */
319
+ list?(h: SandboxHandle, path: string, opts: {
320
+ limit: number;
321
+ signal: AbortSignal;
322
+ }): Promise<{
323
+ entries: {
324
+ name: string;
325
+ isDir: boolean;
326
+ }[];
327
+ truncated: boolean;
328
+ } | null>;
329
+ /**
330
+ * Looks for project-like directories, read as for {@link SandboxProvider.list}. Every provider traverses the same way:
331
+ *
332
+ * - Candidates are `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH}
333
+ * levels below it that hold a `.git` entry (directory or file) or an `AGENTS.md` file.
334
+ * - The walk does not follow symbolic links and does not enter hidden directories (names
335
+ * starting with `.`); a candidate does not stop the descent (a monorepo's sub-projects are
336
+ * candidates too). It never enters a directory named in {@link DEVICE_SCAN_SKIPPED_DIRS}, at
337
+ * any depth, nor one named in {@link DEVICE_SCAN_SKIPPED_BASE_DIRS} directly under `base`;
338
+ * every provider skips exactly these. Paths under `base` the device cannot reach are skipped,
339
+ * never an error.
340
+ * - A directory whose basename does not satisfy {@link isDeviceProjectName} is not returned as
341
+ * a candidate (never with a changed name), but it is still traversed.
342
+ * - Directories are visited breadth-first, each level in code-unit order of `path`, `base`
343
+ * counting as the first visit (visiting a directory reads its entries; one that cannot be read
344
+ * still counts as a visit); the walk stops after {@link MAX_DEVICE_SCAN_DIRS} visits, so a
345
+ * huge tree answers what was found by then.
346
+ * - Each candidate is its absolute `path` and its basename as `suggestedName`; the candidates
347
+ * found are sorted by `path` in code-unit order and cut to the first
348
+ * {@link MAX_DEVICE_SCAN_RESULTS}.
349
+ *
350
+ * Directory entries only, never file contents. A `base` that does not exist answers `[]`; a
351
+ * `base` that is a file, cannot be read, or lies outside what the device reaches throws.
352
+ * Optional, like `list`.
353
+ */
354
+ scan?(h: SandboxHandle, base: string, opts: {
355
+ signal: AbortSignal;
356
+ }): Promise<{
357
+ path: string;
358
+ suggestedName: string;
359
+ }[]>;
228
360
  }
229
- /** 校验沙箱内路径:返回错误列表,空数组表示合法。 */
230
- export declare function validateSandboxPath(p: string): string[];
231
- /** 校验出站白名单主机名:小写、无协议与端口、可选前导 `*.`、IDN 只认 punycode。 */
361
+ /** The longest project name, in UTF-16 code units. */
362
+ export declare const MAX_DEVICE_PROJECT_NAME_LENGTH = 64;
363
+ /** The most candidates a `scan` answers ({@link SandboxProvider.scan}). */
364
+ export declare const MAX_DEVICE_SCAN_RESULTS = 50;
365
+ /**
366
+ * Directory names a `scan` never enters, at any depth ({@link SandboxProvider.scan}): dependency
367
+ * trees, not projects. Every provider skips exactly these.
368
+ */
369
+ export declare const DEVICE_SCAN_SKIPPED_DIRS: readonly string[];
370
+ /**
371
+ * Directory names a `scan` does not enter directly under its `base` ({@link SandboxProvider.scan}):
372
+ * the owner's macOS `Library` (app data, huge, partly privacy-protected) is not where projects
373
+ * live. Every provider skips exactly these.
374
+ */
375
+ export declare const DEVICE_SCAN_SKIPPED_BASE_DIRS: readonly string[];
376
+ /** How far below its base a `scan` looks: the base's children and their children. */
377
+ export declare const MAX_DEVICE_SCAN_DEPTH = 2;
378
+ /**
379
+ * The most directories one `scan` visits (reads the entries of), its `base` included
380
+ * ({@link SandboxProvider.scan}): breadth-first, each level in code-unit order of path.
381
+ */
382
+ export declare const MAX_DEVICE_SCAN_DIRS = 500;
383
+ /**
384
+ * Whether `v` is a valid project name (a project's identity on its device, and a `scan`
385
+ * candidate's `suggestedName`): non-empty, at most {@link MAX_DEVICE_PROJECT_NAME_LENGTH} UTF-16
386
+ * code units, not `.` or `..`, no `/`, no control characters, and no leading or trailing
387
+ * whitespace.
388
+ */
389
+ export declare function isDeviceProjectName(v: unknown): v is string;
390
+ /**
391
+ * The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
392
+ * control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
393
+ * empty when valid. {@link validateSandboxPath} adds root membership.
394
+ */
395
+ export declare function validateSandboxPathShape(p: string): string[];
396
+ /**
397
+ * Checks a path inside an instance; returns the errors, empty when valid: the
398
+ * {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
399
+ * ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
400
+ */
401
+ export declare function validateSandboxPath(p: string, roots?: SandboxRoots): string[];
402
+ /**
403
+ * Validates an outbound allowlist host name: lowercase, no protocol or port, optional leading `*.`,
404
+ * IDN accepted only as punycode.
405
+ */
232
406
  export declare function validateAllowHost(h: string): string[];
package/dist/sandbox.js CHANGED
@@ -4,8 +4,8 @@
4
4
  * primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
5
5
  * `writeFile`.
6
6
  *
7
- * `@2` separates an environment's **file system** from its **instance**: the file system
8
- * (`createFileSystem`) lives until the environment is deleted (`destroyFileSystem`); instances
7
+ * `@2` separates a device's **file system** from its **instance**: the file system
8
+ * (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
9
9
  * (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
10
10
  */
11
11
  /** Sandbox extension point ref. */
@@ -13,6 +13,16 @@ export const SANDBOX_EXTENSION_POINT = "sandbox@2";
13
13
  /** The roots inside the sandbox the model may access. */
14
14
  export const SANDBOX_ROOTS = ["/workspace", "/skills", "/tmp"];
15
15
  const MAX_PATH_LENGTH = 4096;
16
+ /** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
17
+ export const DEFAULT_SANDBOX_ROOTS = Object.freeze({
18
+ workspace: "/workspace",
19
+ skills: "/skills",
20
+ tmp: "/tmp",
21
+ });
22
+ /** The roots of an instance, falling back to {@link DEFAULT_SANDBOX_ROOTS}. */
23
+ export function rootsOf(h) {
24
+ return h.roots ?? DEFAULT_SANDBOX_ROOTS;
25
+ }
16
26
  /**
17
27
  * The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
18
28
  * `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
@@ -35,7 +45,7 @@ export function isSandboxGoneError(e) {
35
45
  /**
36
46
  * The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
37
47
  * `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
38
- * reports the environment's files as lost rather than handing out a silently empty workspace.
48
+ * reports the device's files as lost rather than handing out a silently empty workspace.
39
49
  */
40
50
  export class FileSystemGoneError extends Error {
41
51
  fileSystemGone = true;
@@ -56,10 +66,52 @@ export function isFileSystemGoneError(e) {
56
66
  * kill pattern.
57
67
  */
58
68
  export const SANDBOX_TAG_RE = /^[a-z0-9-]{1,64}$/;
59
- // biome-ignore lint/suspicious/noControlCharactersInRegex: 正是要拦控制字符
69
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are exactly what must be blocked
60
70
  const CONTROL = /[\u0000-\u001f\u007f]/;
61
- /** 校验沙箱内路径:返回错误列表,空数组表示合法。 */
62
- export function validateSandboxPath(p) {
71
+ /** The longest project name, in UTF-16 code units. */
72
+ export const MAX_DEVICE_PROJECT_NAME_LENGTH = 64;
73
+ /** The most candidates a `scan` answers ({@link SandboxProvider.scan}). */
74
+ export const MAX_DEVICE_SCAN_RESULTS = 50;
75
+ /**
76
+ * Directory names a `scan` never enters, at any depth ({@link SandboxProvider.scan}): dependency
77
+ * trees, not projects. Every provider skips exactly these.
78
+ */
79
+ export const DEVICE_SCAN_SKIPPED_DIRS = Object.freeze(["node_modules"]);
80
+ /**
81
+ * Directory names a `scan` does not enter directly under its `base` ({@link SandboxProvider.scan}):
82
+ * the owner's macOS `Library` (app data, huge, partly privacy-protected) is not where projects
83
+ * live. Every provider skips exactly these.
84
+ */
85
+ export const DEVICE_SCAN_SKIPPED_BASE_DIRS = Object.freeze(["Library"]);
86
+ /** How far below its base a `scan` looks: the base's children and their children. */
87
+ export const MAX_DEVICE_SCAN_DEPTH = 2;
88
+ /**
89
+ * The most directories one `scan` visits (reads the entries of), its `base` included
90
+ * ({@link SandboxProvider.scan}): breadth-first, each level in code-unit order of path.
91
+ */
92
+ export const MAX_DEVICE_SCAN_DIRS = 500;
93
+ /**
94
+ * Whether `v` is a valid project name (a project's identity on its device, and a `scan`
95
+ * candidate's `suggestedName`): non-empty, at most {@link MAX_DEVICE_PROJECT_NAME_LENGTH} UTF-16
96
+ * code units, not `.` or `..`, no `/`, no control characters, and no leading or trailing
97
+ * whitespace.
98
+ */
99
+ export function isDeviceProjectName(v) {
100
+ return (typeof v === "string" &&
101
+ v !== "" &&
102
+ v !== "." &&
103
+ v !== ".." &&
104
+ v.length <= MAX_DEVICE_PROJECT_NAME_LENGTH &&
105
+ !CONTROL.test(v) &&
106
+ !v.includes("/") &&
107
+ !/^\s|\s$/.test(v));
108
+ }
109
+ /**
110
+ * The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
111
+ * control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
112
+ * empty when valid. {@link validateSandboxPath} adds root membership.
113
+ */
114
+ export function validateSandboxPathShape(p) {
63
115
  if (typeof p !== "string" || p.length === 0)
64
116
  return ["path must be a non-empty string"];
65
117
  if (p.length > MAX_PATH_LENGTH)
@@ -72,27 +124,49 @@ export function validateSandboxPath(p) {
72
124
  return ["path must be absolute"];
73
125
  if (p.includes("//"))
74
126
  return ["path must not contain empty segments"];
75
- const errors = [];
76
127
  for (const seg of p.split("/")) {
77
128
  let decoded = seg;
78
129
  try {
79
130
  decoded = decodeURIComponent(seg);
80
131
  }
81
132
  catch {
82
- // 非法百分号编码按字面处理
133
+ // invalid percent-encoding is taken literally
83
134
  }
84
135
  if (seg === ".." || decoded === ".." || decoded.includes("/") || decoded.includes("\\")) {
85
- errors.push("path must not contain '..' segments");
86
- break;
136
+ return ["path must not contain '..' segments"];
87
137
  }
88
138
  }
89
- if (!SANDBOX_ROOTS.some((r) => p === r || p.startsWith(`${r}/`))) {
90
- errors.push(`path must be under ${SANDBOX_ROOTS.join(", ")}`);
139
+ return [];
140
+ }
141
+ /** A structural error after which {@link validateSandboxPath} stops (before the root check). */
142
+ const STOPS = new Set([
143
+ "path must be a non-empty string",
144
+ `path must be at most ${MAX_PATH_LENGTH} characters`,
145
+ "path must not contain control characters",
146
+ "path must not contain backslashes",
147
+ "path must be absolute",
148
+ "path must not contain empty segments",
149
+ ]);
150
+ /**
151
+ * Checks a path inside an instance; returns the errors, empty when valid: the
152
+ * {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
153
+ * ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
154
+ */
155
+ export function validateSandboxPath(p, roots) {
156
+ const errors = validateSandboxPathShape(p);
157
+ if (errors.some((e) => STOPS.has(e)))
158
+ return errors;
159
+ const allowed = roots === undefined ? SANDBOX_ROOTS : [roots.workspace, roots.skills, roots.tmp];
160
+ if (!allowed.some((r) => p === r || p.startsWith(`${r}/`))) {
161
+ errors.push(`path must be under ${allowed.join(", ")}`);
91
162
  }
92
163
  return errors;
93
164
  }
94
165
  const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
95
- /** 校验出站白名单主机名:小写、无协议与端口、可选前导 `*.`、IDN 只认 punycode。 */
166
+ /**
167
+ * Validates an outbound allowlist host name: lowercase, no protocol or port, optional leading `*.`,
168
+ * IDN accepted only as punycode.
169
+ */
96
170
  export function validateAllowHost(h) {
97
171
  if (typeof h !== "string" || h.length === 0)
98
172
  return ["host must be a non-empty string"];
@@ -106,7 +180,8 @@ export function validateAllowHost(h) {
106
180
  const tld = labels[labels.length - 1];
107
181
  if (labels.length < 2)
108
182
  return ["host must have at least two labels (no single-label names)"];
109
- // 末段必须以字母开头:挡住 IPv4 的十进制 / 八进制 / 十六进制写法
183
+ // The last label must start with a letter: this blocks the decimal / octal / hexadecimal
184
+ // spellings of IPv4
110
185
  if (!/^[a-z]/.test(tld))
111
186
  return ["host must not be an IP address literal"];
112
187
  if (["local", "internal", "localhost"].includes(tld)) {
package/dist/secret.d.ts CHANGED
@@ -4,5 +4,8 @@ import type { z } from "zod";
4
4
  * (`ui` hints, `hot`), so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
5
5
  */
6
6
  export declare function secret<T extends z.ZodTypeAny>(schema: T): T;
7
- /** 读取 schema 的 meta,判断是否敏感;内核 `meta({secret:true})` 同样可识别。 */
7
+ /**
8
+ * Reads the schema's meta to tell whether it is sensitive; the kernel's `meta({secret:true})` is
9
+ * recognized the same way.
10
+ */
8
11
  export declare function isSecret(schema: z.ZodTypeAny): boolean;
package/dist/secret.js CHANGED
@@ -5,7 +5,10 @@
5
5
  export function secret(schema) {
6
6
  return schema.meta({ ...(schema.meta() ?? {}), secret: true });
7
7
  }
8
- /** 读取 schema 的 meta,判断是否敏感;内核 `meta({secret:true})` 同样可识别。 */
8
+ /**
9
+ * Reads the schema's meta to tell whether it is sensitive; the kernel's `meta({secret:true})` is
10
+ * recognized the same way.
11
+ */
9
12
  export function isSecret(schema) {
10
13
  return schema.meta()?.secret === true;
11
14
  }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Setup checks (spec `2026-11-09-setup-guides-v2-design.md` §10): a check answers one question
3
+ * about one target ("does this bot token work?") for a `::check` line of a setup guide. An
4
+ * extension registers its checks in `setup` with `ctx.setup.check(id, def)`; each id must be
5
+ * listed in `permissions.setupChecks`. The kernel runs a check only when a person or an agent asks
6
+ * (never in the background), caches, single-flights and rate-limits it, and redacts the result.
7
+ *
8
+ * Contract rules (backed by review and kernel redaction, not by isolation: extensions are fully
9
+ * trusted):
10
+ * - A check never writes, at the third party or in Capybara, and stays cheap (one or two reads).
11
+ * - Pass `signal` to every request; the kernel aborts it at {@link SETUP_CHECK_LIMITS}.timeoutMs.
12
+ * - No retries inside the check: the person retries, retry policy is the kernel's.
13
+ * - Never put a secret, or any part of one, in `reason` or `fix`: the result is shown to people
14
+ * and to models (the `Platform` tool returns it). The kernel replaces known secret values with
15
+ * `[REDACTED]` before caching or returning, but only as exact matches of whole values of 8
16
+ * characters or more: a prefix, suffix, shorter secret or transformed copy is not redacted.
17
+ *
18
+ * What a check receives is what the extension already receives for the same target, nothing more:
19
+ * a channel connection's config (as `channel@1` `verify` and `connect` get it), a connector's
20
+ * ids and OAuth client id, or the extension's own platform deployment config (as its `ctx.config`,
21
+ * for the `extension-deployment` place, run only by a super admin). A check never gets the OAuth client secret or a member's token; those
22
+ * stay with the kernel and the connector extension's `auth()` (decided 2026-11-09).
23
+ */
24
+ import type { SetupGuidePlace } from "./setup-guide.js";
25
+ /**
26
+ * `ok`: verified now. `failing`: verified wrong (needs a reason; should have a fix). `unknown`:
27
+ * could not tell (third party down, rate limited, the check does not apply yet); never a failure
28
+ * the person must act on.
29
+ */
30
+ export type SetupCheckStatus = "ok" | "failing" | "unknown";
31
+ /** Plain text in English (required) and optionally Chinese; rendered as text, never Markdown. */
32
+ export interface SetupCheckText {
33
+ readonly en: string;
34
+ readonly zh?: string;
35
+ }
36
+ /**
37
+ * The answer of a check. There is deliberately no structured details field: a result has nowhere
38
+ * for a token to hide. {@link validateSetupCheckResult} refuses any other key.
39
+ */
40
+ export interface SetupCheckResult {
41
+ readonly status: SetupCheckStatus;
42
+ /** Why, in a sentence. At most `reasonChars` per language. Required when `failing`. */
43
+ readonly reason?: SetupCheckText;
44
+ /** What to do when failing. At most `fixChars` per language. */
45
+ readonly fix?: SetupCheckText;
46
+ }
47
+ /**
48
+ * What a check is about. The kernel builds it field by field; it only ever names targets of the
49
+ * check's own plugin (a channel connection on the plugin, a connector made from one of its
50
+ * templates, the plugin's own deployment).
51
+ */
52
+ export type SetupCheckTarget = {
53
+ readonly kind: "channel-connection";
54
+ readonly connectionId: string;
55
+ /** The connection config as `channel@1` `verify` and `connect` receive it, secrets included. */
56
+ readonly config: unknown;
57
+ } | {
58
+ readonly kind: "connector";
59
+ readonly connectorId: string;
60
+ readonly templateId: string;
61
+ /** The OAuth client id when the template uses a manual client; never the client secret. */
62
+ readonly clientId: string | null;
63
+ /** The viewing member's account, for member-audience checks; never their token. */
64
+ readonly accountId: string | null;
65
+ } | {
66
+ readonly kind: "extension-deployment";
67
+ /** The check's own plugin. */
68
+ readonly plugin: string;
69
+ /** The extension's platform deployment config as its `ctx.config` holds it, secrets included. */
70
+ readonly config: unknown;
71
+ };
72
+ /** What `run` receives. */
73
+ export interface SetupCheckArgs {
74
+ /** The org the check runs for; null for the `extension-deployment` place (the platform). */
75
+ readonly orgId: string | null;
76
+ /**
77
+ * The extension's effective config for the org (platform config plus the org's copy); for the
78
+ * `extension-deployment` place, its platform deployment config.
79
+ */
80
+ readonly config: unknown;
81
+ readonly locale: "en" | "zh";
82
+ /** The guide's mode (`long_connection`, `webhook`), or null when the place has none. */
83
+ readonly mode: string | null;
84
+ readonly target: SetupCheckTarget;
85
+ /** Aborted at the kernel's timeout or when the extension is disposed. Pass it to every request. */
86
+ readonly signal: AbortSignal;
87
+ }
88
+ /** A check registered with `ctx.setup.check`. */
89
+ export interface SetupCheckDefinition {
90
+ /** The place whose guides may use the check; the kernel runs it only for targets of that place. */
91
+ place: SetupGuidePlace;
92
+ /** Never writes, passes `signal` on, does not retry, never puts a secret in the result. */
93
+ run(args: SetupCheckArgs): Promise<SetupCheckResult>;
94
+ }
95
+ /**
96
+ * A check id an extension declares and registers. Ids with `:` belong to the kernel
97
+ * (`capybara:*`), so an extension cannot shadow a kernel check.
98
+ */
99
+ export declare const SETUP_CHECK_ID_RE: RegExp;
100
+ /** Limits of setup checks (spec §10.5). Characters are UTF-16 code units. */
101
+ export declare const SETUP_CHECK_LIMITS: Readonly<{
102
+ /** Per run; the kernel aborts `signal` and records `unknown`. */
103
+ readonly timeoutMs: 10000;
104
+ /** Characters of `reason`, per language. */
105
+ readonly reasonChars: 300;
106
+ /** Characters of `fix`, per language. */
107
+ readonly fixChars: 500;
108
+ /** A cached result stays fresh this long (and for the same input fingerprint). */
109
+ readonly freshMs: 300000;
110
+ /** A forced rerun of one check and target at most this often. */
111
+ readonly cooldownMs: 10000;
112
+ /** Concurrent runs per org across all replicas. */
113
+ readonly orgConcurrency: 8;
114
+ /** Run requests per account per minute. */
115
+ readonly perAccountPerMinute: 30;
116
+ /** Ids in `permissions.setupChecks`. */
117
+ readonly idsPerExtension: 32;
118
+ }>;
119
+ type Problem = {
120
+ problem: string;
121
+ };
122
+ /**
123
+ * The result as a fresh plain object holding only `status`, `reason` and `fix`, or why it is
124
+ * invalid (English). The kernel treats an invalid result as `unknown` and logs the problem. Run
125
+ * kernel redaction on the returned copy, then validate again (redaction can change the length).
126
+ */
127
+ export declare function validateSetupCheckResult(x: unknown): SetupCheckResult | Problem;
128
+ export {};