@capybara-hq/plugin-sdk 0.1.0-rc.0 → 0.1.0-rc.10

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 (93) hide show
  1. package/README.md +3 -3
  2. package/agent-docs/agent-templates.md +47 -0
  3. package/agent-docs/concepts.md +63 -0
  4. package/agent-docs/connector-templates.md +48 -0
  5. package/agent-docs/extension-points/channel.md +15 -0
  6. package/agent-docs/extension-points/config-source.md +15 -0
  7. package/agent-docs/extension-points/connector.md +15 -0
  8. package/agent-docs/extension-points/counter.md +15 -0
  9. package/agent-docs/extension-points/directory.md +15 -0
  10. package/agent-docs/extension-points/file-preview.md +15 -0
  11. package/agent-docs/extension-points/identity-source.md +15 -0
  12. package/agent-docs/extension-points/model-provider.md +15 -0
  13. package/agent-docs/extension-points/object-store.md +15 -0
  14. package/agent-docs/extension-points/sandbox.md +15 -0
  15. package/agent-docs/extension-points/secret-store.md +15 -0
  16. package/agent-docs/extension-points/web-fetch.md +15 -0
  17. package/agent-docs/extension-points/web-search.md +15 -0
  18. package/agent-docs/extensions.md +87 -0
  19. package/agent-docs/plugin-format.md +99 -0
  20. package/agent-docs/setup.md +46 -0
  21. package/agent-docs/skills.md +44 -0
  22. package/agent-docs/tool-naming.md +21 -0
  23. package/dist/agent-template.d.ts +85 -0
  24. package/dist/agent-template.js +362 -3
  25. package/dist/cards.d.ts +7 -0
  26. package/dist/cards.js +4 -4
  27. package/dist/channel.d.ts +20 -1
  28. package/dist/config-ui.d.ts +131 -0
  29. package/dist/config-ui.js +602 -0
  30. package/dist/connector-auth.d.ts +2 -0
  31. package/dist/connector-auth.js +15 -0
  32. package/dist/ctx.d.ts +86 -4
  33. package/dist/define-extension.d.ts +5 -1
  34. package/dist/define-extension.js +1 -0
  35. package/dist/device-protocol.d.ts +118 -0
  36. package/dist/device-protocol.js +276 -0
  37. package/dist/directory.d.ts +11 -2
  38. package/dist/extension-point.d.ts +9 -0
  39. package/dist/extension-point.js +17 -12
  40. package/dist/file-preview.d.ts +9 -1
  41. package/dist/hooks.d.ts +79 -18
  42. package/dist/index.d.ts +16 -1
  43. package/dist/index.js +16 -1
  44. package/dist/marketplace.d.ts +55 -2
  45. package/dist/marketplace.js +73 -3
  46. package/dist/model.d.ts +60 -2
  47. package/dist/model.js +22 -0
  48. package/dist/org-access.d.ts +27 -0
  49. package/dist/org-access.js +35 -0
  50. package/dist/permissions.d.ts +20 -5
  51. package/dist/permissions.js +51 -15
  52. package/dist/plugin-manifest.d.ts +48 -5
  53. package/dist/plugin-manifest.js +93 -6
  54. package/dist/sandbox.d.ts +164 -62
  55. package/dist/sandbox.js +71 -14
  56. package/dist/secret.d.ts +4 -1
  57. package/dist/secret.js +5 -2
  58. package/dist/setup-check.d.ts +115 -0
  59. package/dist/setup-check.js +142 -0
  60. package/dist/setup-guide-parse.d.ts +121 -0
  61. package/dist/setup-guide-parse.js +350 -0
  62. package/dist/setup-guide-render.d.ts +45 -0
  63. package/dist/setup-guide-render.js +351 -0
  64. package/dist/setup-guide.d.ts +94 -0
  65. package/dist/setup-guide.js +336 -0
  66. package/dist/skill-invocation.d.ts +12 -8
  67. package/dist/skill-invocation.js +19 -9
  68. package/dist/skill.d.ts +23 -3
  69. package/dist/skill.js +31 -6
  70. package/dist/theme-assets.d.ts +39 -0
  71. package/dist/theme-assets.js +449 -0
  72. package/dist/theme-readability.d.ts +37 -0
  73. package/dist/theme-readability.js +145 -0
  74. package/dist/theme-tokens.generated.d.ts +275 -0
  75. package/dist/theme-tokens.generated.js +167 -0
  76. package/dist/theme.d.ts +152 -0
  77. package/dist/theme.js +392 -0
  78. package/dist/tool-key.d.ts +28 -0
  79. package/dist/tool-key.js +40 -0
  80. package/dist/tool.d.ts +11 -3
  81. package/dist/ui-resolve.d.ts +40 -0
  82. package/dist/ui-resolve.js +54 -0
  83. package/dist/ui-slots.d.ts +43 -0
  84. package/dist/ui-slots.js +168 -0
  85. package/dist/ui.d.ts +114 -31
  86. package/dist/ui.js +0 -4
  87. package/dist/web.d.ts +105 -0
  88. package/dist/web.js +135 -0
  89. package/package.json +10 -2
  90. package/schemas/connector-template.v1.schema.json +3 -0
  91. package/schemas/marketplace.v1.schema.json +50 -0
  92. package/schemas/plugin.v1.schema.json +97 -4
  93. package/schemas/theme.v1.schema.json +225 -0
package/dist/sandbox.d.ts CHANGED
@@ -1,30 +1,56 @@
1
1
  /**
2
- * Sandbox contract `sandbox@1`: a single-select, brokered extension point (extensions may not
2
+ * Sandbox contract `sandbox@2`: a single-select, brokered extension point (extensions may not
3
3
  * `requires` it; the kernel's `SandboxService` consumes it). The provider implements only the
4
4
  * primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
5
5
  * `writeFile`.
6
+ *
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
+ * (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
6
10
  */
7
11
  /** Sandbox extension point ref. */
8
- export declare const SANDBOX_EXTENSION_POINT = "sandbox@1";
9
- /** 沙箱内允许模型访问的根目录。 */
12
+ export declare const SANDBOX_EXTENSION_POINT = "sandbox@2";
13
+ /** The roots inside the sandbox the model may access. */
10
14
  export declare const SANDBOX_ROOTS: readonly ["/workspace", "/skills", "/tmp"];
11
- /** 沙箱资源与出站限制。 */
15
+ /** Sandbox resource and egress limits. */
12
16
  export interface SandboxLimits {
13
17
  cpu: number;
14
18
  memoryMb: number;
15
19
  diskMb: number;
16
20
  egress: "none" | "allowlist" | "open";
17
- /** 出站白名单(`egress` 为 `allowlist` 时生效);每项须通过 {@link validateAllowHost}。 */
21
+ /** Egress allowlist (used when `egress` is `allowlist`); each entry passes {@link validateAllowHost}. */
18
22
  allowHosts: string[];
19
23
  }
20
- /** 提供方的实例句柄。 */
24
+ /** The absolute roots inside one instance (a device may place them anywhere on its host). */
25
+ export interface SandboxRoots {
26
+ workspace: string;
27
+ skills: string;
28
+ tmp: string;
29
+ }
30
+ /** The roots every container-like provider uses; the same paths as {@link SANDBOX_ROOTS}. */
31
+ export declare const DEFAULT_SANDBOX_ROOTS: Readonly<SandboxRoots>;
32
+ /** The provider's instance handle. */
21
33
  export interface SandboxHandle {
22
- /** 提供方的实例 id。 */
34
+ /** The provider's instance id. */
35
+ id: string;
36
+ /** The instance's roots; absent means {@link DEFAULT_SANDBOX_ROOTS}. */
37
+ roots?: SandboxRoots;
38
+ }
39
+ /** The roots of an instance, falling back to {@link DEFAULT_SANDBOX_ROOTS}. */
40
+ export declare function rootsOf(h: SandboxHandle): SandboxRoots;
41
+ /** The provider's file system handle (a device's files, independent of any instance). */
42
+ export interface FileSystemHandle {
43
+ /** The provider's file system id. */
23
44
  id: string;
24
45
  }
25
- /** 命令执行结果。 */
46
+ /** Who runs an `exec` (informational in phase 1: audit and attribution). */
47
+ export interface SandboxActor {
48
+ accountId: string;
49
+ conversationId: string;
50
+ }
51
+ /** Result of a command. */
26
52
  export interface ExecResult {
27
- /** 超时或在执行中被中止为 null(此时 `timedOut` 分别为 true / false)。 */
53
+ /** null on timeout or when aborted while running (`timedOut` is then true / false). */
28
54
  exitCode: number | null;
29
55
  stdout: string;
30
56
  stderr: string;
@@ -32,8 +58,10 @@ export interface ExecResult {
32
58
  timedOut: boolean;
33
59
  }
34
60
  /**
35
- * 实例在提供方那边确定已经不在了(容器被删、E2B 沙箱过期)。`exec` / `readFile` / `writeFile` / `stat`
36
- * 发现实例不在时必须抛它(而不是普通 Error),内核据此重建沙箱并重试一次;只是暂时连不上时抛普通错误。
61
+ * The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
62
+ * `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
63
+ * instance gone; the kernel then rebuilds the instance and retries once. A transient connection
64
+ * failure throws a plain error.
37
65
  */
38
66
  export declare class SandboxGoneError extends Error {
39
67
  readonly sandboxGone: true;
@@ -41,8 +69,21 @@ export declare class SandboxGoneError extends Error {
41
69
  cause?: unknown;
42
70
  });
43
71
  }
44
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
72
+ /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
45
73
  export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
74
+ /**
75
+ * The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
76
+ * `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
77
+ * reports the device's files as lost rather than handing out a silently empty workspace.
78
+ */
79
+ export declare class FileSystemGoneError extends Error {
80
+ readonly fileSystemGone: true;
81
+ constructor(message: string, opts?: {
82
+ cause?: unknown;
83
+ });
84
+ }
85
+ /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
86
+ export declare function isFileSystemGoneError(e: unknown): e is FileSystemGoneError;
46
87
  /**
47
88
  * A holder tag (`exec` argument `tag`, {@link SandboxProvider.killTagged}): the kernel passes its
48
89
  * lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
@@ -50,73 +91,119 @@ export declare function isSandboxGoneError(e: unknown): e is SandboxGoneError;
50
91
  */
51
92
  export declare const SANDBOX_TAG_RE: RegExp;
52
93
  /**
53
- * `sandbox@1` 的实现(由沙箱插件提供,如 Docker、E2B)。
54
- * 实例确定不在时:`resume` 返回 `gone`;`exec` / `readFile` / `writeFile` / `stat` 抛 {@link SandboxGoneError};
55
- * `suspend` / `destroy` 照常成功。
94
+ * The `sandbox@2` implementation (provided by a sandbox plugin such as Docker or E2B).
56
95
  *
57
- * **自动启动**:实例还在、但已停止 / 暂停(被内核之外的原因停掉:宿主机重启、守护进程重启、沙箱里的进程把
58
- * 自己的 init 弄停了、休眠扫描停了实例却没来得及记下 `suspended`……)时,`exec` / `readFile` / `writeFile` /
59
- * `stat` 必须先透明地把它启动起来(同 `resume`,文件保留)再执行,而不是报错——内核只信自己记的 `running`。
96
+ * **File systems and instances.** `createFileSystem` makes a device's files; they live until
97
+ * `destroyFileSystem` (the device is deleted). `create` makes an instance attached to an
98
+ * existing file system; `destroy` / `destroyByName` drop the instance only and keep the files, and
99
+ * `suspend` keeps them too. When the file system is gone, `create` must throw
100
+ * {@link FileSystemGoneError} and never create an empty one in its place (a Docker provider checks
101
+ * its volumes exist before mounting them, because Docker would otherwise create empty volumes).
60
102
  *
61
- * **命令时限在沙箱里也要生效**:`exec` 除了在提供方这边按 `timeoutMs` 停掉命令,还必须让沙箱里的命令自己在
62
- * `timeoutMs` 之后不久(几秒的余量)被杀掉。内核副本崩溃时提供方这边的计时随之消失,断开连接也不会结束命令;
63
- * 沙箱里的时限保证它不会无限期地与下一个持锁方的命令同时运行。
103
+ * **Gone instances.** When the instance is definitely gone: `resume` returns `gone`; `exec` /
104
+ * `readFile` / `writeFile` / `stat` / `killAll` / `killTagged` throw {@link SandboxGoneError};
105
+ * `suspend` / `destroy` succeed as usual.
64
106
  *
65
- * **中止**:每个方法都必须及时响应 `signal`(已中止就立即失败,进行中被中止就尽快以中止原因结束)——内核在锁丢失、
66
- * 运行被中止或超时时靠它停下,不响应就可能与新的持锁方同时操作同一实例。`exec` 被中止时必须杀掉正在跑的命令
67
- * (连同它派生的进程),而不只是不再等待它的输出;命令启动后才被中止的 `exec` 以 `exitCode: null`、
68
- * `timedOut: false` 正常 resolve(带上已收集的输出),不 reject。调用时 signal 已中止则立即 reject。
107
+ * **Auto-start**: when the instance still exists but is stopped or paused (for a reason outside the
108
+ * kernel: host or daemon restart, a process in the sandbox stopping its init, an idle sweep that
109
+ * stopped the instance before recording `suspended`...), `exec` / `readFile` / `writeFile` /
110
+ * `stat` / `killAll` / `killTagged` must start it transparently first (like `resume`, files kept)
111
+ * and then run, never fail: the kernel trusts only the `running` it recorded itself. Auto-start
112
+ * must be idempotent under concurrent calls: two calls that both find the instance stopped both
113
+ * start it without failing.
69
114
  *
70
- * **Concurrent use (optional)**: a provider that declares {@link SandboxProvider.concurrentExec}
71
- * lets the kernel call `exec`, `readFile`, `writeFile` and `stat` concurrently on one instance
72
- * (commands of parallel sub-agents sharing their parent conversation's sandbox). Then those four
73
- * methods must be safe to call concurrently, and **auto-start must be idempotent under concurrent
74
- * calls**: two calls that both find the instance stopped both start it without failing. Each
75
- * `exec` labels its command with its `tag`, and an aborted `exec` kills only its own command.
76
- * `concurrentExec` requires {@link SandboxProvider.killTagged}; a provider that declares one
77
- * without the other, or neither, is used one call at a time (the behavior without them).
115
+ * **Time limits apply inside the sandbox too**: besides stopping a command after `timeoutMs` on the
116
+ * provider's side, `exec` must make the command in the sandbox kill itself shortly (a few seconds)
117
+ * after `timeoutMs`. When a kernel replica crashes, the provider-side timer goes with it, and a
118
+ * dropped connection does not end the command; the in-sandbox limit keeps it from running
119
+ * indefinitely next to the next holder's commands.
120
+ *
121
+ * **Abort**: every method must respond to `signal` promptly (fail at once when already aborted, end
122
+ * with the abort reason as soon as possible when aborted mid-way): the kernel relies on it to stop
123
+ * on lock loss, run abort or timeout, and ignoring it may let two holders operate on one instance.
124
+ * An aborted `exec` must kill its running command (and the processes it spawned), not just stop
125
+ * waiting for its output; an `exec` aborted after its command started resolves normally with
126
+ * `exitCode: null`, `timedOut: false` (and the output collected so far), it does not reject. An
127
+ * `exec` called with an already aborted signal rejects at once.
128
+ *
129
+ * **Concurrent use** (required in `@2`): the sessions of one device share its instance, so the
130
+ * kernel calls `exec`, `readFile`, `writeFile` and `stat` concurrently on one instance. Those four
131
+ * methods must be safe to call concurrently. Each `exec` labels its command with its `tag`, and an
132
+ * aborted `exec` kills only its own command.
78
133
  */
79
134
  export interface SandboxProvider {
135
+ /** `exec` / `readFile` / `writeFile` / `stat` may run concurrently on one instance (required). */
136
+ readonly concurrentExec: true;
137
+ /**
138
+ * Whether the provider isolates the sessions of one device from each other inside the
139
+ * instance (a declared capability; absent means false).
140
+ */
141
+ readonly sessionIsolation?: boolean;
142
+ /**
143
+ * Creates a device's file system. `name` looks like `cap-device-<deviceId>`. If a file
144
+ * system with this name already exists, return it.
145
+ */
146
+ createFileSystem(args: {
147
+ name: string;
148
+ limits: SandboxLimits;
149
+ signal: AbortSignal;
150
+ }): Promise<FileSystemHandle>;
151
+ /** Deletes the file system and its files. Succeeds when it does not exist. */
152
+ destroyFileSystem(fs: FileSystemHandle, signal: AbortSignal): Promise<void>;
153
+ /**
154
+ * Deletes the file system made under `name` by `createFileSystem`; succeeds when there is none.
155
+ * The kernel uses it when it has no handle (`createFileSystem` finished on the provider's side
156
+ * but the kernel stopped before recording the handle), and in its one-off cleanup of
157
+ * per-conversation sandboxes with `cap-<conversationId>` names that a `sandbox@1` provider's
158
+ * `create` made together with their files (Docker: the `cap-<conversationId>-workspace` and
159
+ * `-skills` volumes); a provider removes those under the same call.
160
+ */
161
+ destroyFileSystemByName(name: string, signal: AbortSignal): Promise<void>;
80
162
  /**
81
- * Declares that `exec` / `readFile` / `writeFile` / `stat` may run concurrently on one instance
82
- * (see the contract above). Requires {@link SandboxProvider.killTagged}.
163
+ * Creates an instance attached to `fileSystem`. Without `image` the provider uses its own
164
+ * published image. Throws {@link FileSystemGoneError} when the file system is gone.
83
165
  */
84
- readonly concurrentExec?: boolean;
85
- /** `name` 形如 `cap-<conversationId>`。 */
86
166
  create(args: {
87
167
  name: string;
88
- image: string;
168
+ image?: string;
89
169
  limits: SandboxLimits;
170
+ fileSystem: FileSystemHandle;
90
171
  signal: AbortSignal;
91
172
  }): Promise<SandboxHandle>;
92
- /** `gone` 表示提供方那边已经没有这个实例。 */
173
+ /** `gone` means the provider no longer has this instance. */
93
174
  resume(h: SandboxHandle, signal: AbortSignal): Promise<"resumed" | "gone">;
94
- /** 文件必须保留。实例不存在也算成功。 */
175
+ /** Files must be kept. Succeeds when the instance does not exist. */
95
176
  suspend(h: SandboxHandle, signal: AbortSignal): Promise<void>;
96
- /** 不存在也算成功。 */
177
+ /** Drops the instance only; the file system and its files are kept. Succeeds when it does not exist. */
97
178
  destroy(h: SandboxHandle, signal: AbortSignal): Promise<void>;
98
179
  /**
99
- * 可选:按 `create` 时的 `name`(`cap-<conversationId>`)销毁实例,不存在也算成功。
100
- * 内核在拿不到句柄时用它清理(例如 `create` 已在提供方那边完成、内核却在记下句柄前退出)。
180
+ * Drops the instance made under `name` by `create` (instance only, files kept); succeeds when
181
+ * there is none. The kernel uses it when it has no handle (`create` finished on the provider's
182
+ * side but the kernel stopped before recording the handle), and in its one-off cleanup of
183
+ * per-conversation sandboxes with `cap-<conversationId>` names made by a `sandbox@1` provider's
184
+ * `create`.
101
185
  */
102
- destroyByName?(name: string, signal: AbortSignal): Promise<void>;
186
+ destroyByName(name: string, signal: AbortSignal): Promise<void>;
103
187
  /**
104
- * 可选:杀掉这个实例里经 `exec` 启动、仍在运行的全部命令(连同它们派生的、没有自己另起会话的进程)。
105
- * 内核在接手一个前任持锁方没有正常结束的沙箱(前任崩溃)时、第一次执行前调用,清掉前任遗留的命令;
106
- * 命令自己放到后台、另起会话的进程不保证被杀。实例已停止时同样先启动;不在时抛 {@link SandboxGoneError}。
188
+ * Kills every running command started through `exec` in this instance (and the processes they
189
+ * spawned that did not start their own session). The kernel calls it only when no other holder
190
+ * can be running commands (an instance just resumed from `suspended`, or under the exclusive
191
+ * lease), never while another session may be; to clean up after one crashed holder it uses
192
+ * {@link SandboxProvider.killTagged}. Processes a command put in the background in their own
193
+ * session are not guaranteed to be killed.
107
194
  */
108
- killAll?(h: SandboxHandle, signal: AbortSignal): Promise<void>;
195
+ killAll(h: SandboxHandle, signal: AbortSignal): Promise<void>;
109
196
  /**
110
- * Optional: kill every running `exec` command labelled with one of `tags` (and its process
111
- * tree), leaving other commands running. The kernel calls it for the tags of holders that
112
- * crashed while live holders keep running commands. Tags match {@link SANDBOX_TAG_RE}. Match
113
- * whole tags: one tag may be a prefix of another (`ab` of `ab-cd`), and killing `ab` must not
114
- * touch `ab-cd`'s commands. Starts a stopped instance first; throws {@link SandboxGoneError}
115
- * when the instance is gone.
197
+ * Kills every running `exec` command labelled with one of `tags` (and its process tree), leaving
198
+ * other commands running. The kernel calls it for the tags of holders that crashed while live
199
+ * holders keep running commands. Tags match {@link SANDBOX_TAG_RE}. Match whole tags: one tag
200
+ * may be a prefix of another (`ab` of `ab-cd`), and killing `ab` must not touch `ab-cd`'s
201
+ * commands.
116
202
  */
117
- killTagged?(h: SandboxHandle, tags: string[], signal: AbortSignal): Promise<void>;
203
+ killTagged(h: SandboxHandle, tags: string[], signal: AbortSignal): Promise<void>;
118
204
  /**
119
- * 执行一条命令。`maxOutputBytes` 是 stdout 与 stderr **合计**最多收集的字节,超出的丢弃、`truncated` 为 true。
205
+ * Runs a command. `maxOutputBytes` caps stdout and stderr **combined**; the rest is dropped and
206
+ * `truncated` is true.
120
207
  */
121
208
  exec(h: SandboxHandle, args: {
122
209
  command: string;
@@ -127,11 +214,16 @@ export interface SandboxProvider {
127
214
  signal: AbortSignal;
128
215
  /**
129
216
  * The holder's tag ({@link SANDBOX_TAG_RE}); label the command with it so
130
- * {@link SandboxProvider.killTagged} can find it. Absent from kernels before phase C.
217
+ * {@link SandboxProvider.killTagged} can find it.
131
218
  */
132
- tag?: string;
219
+ tag: string;
220
+ /** Who runs the command; informational in phase 1 (record it, do not act on it). */
221
+ actor: SandboxActor;
133
222
  }): Promise<ExecResult>;
134
- /** 读文件(最多 `maxBytes` 字节,更长的截断、`truncated` 为 true)。不存在、或是目录时返回 null。 */
223
+ /**
224
+ * Reads a file (at most `maxBytes`; longer files are truncated and `truncated` is true). Returns
225
+ * null when it does not exist or is a directory.
226
+ */
135
227
  readFile(h: SandboxHandle, path: string, opts: {
136
228
  maxBytes: number;
137
229
  signal: AbortSignal;
@@ -139,14 +231,24 @@ export interface SandboxProvider {
139
231
  data: Uint8Array;
140
232
  truncated: boolean;
141
233
  } | null>;
142
- /** 父目录自动创建。 */
234
+ /** Parent directories are created. */
143
235
  writeFile(h: SandboxHandle, path: string, data: Uint8Array, signal: AbortSignal): Promise<void>;
144
236
  stat(h: SandboxHandle, path: string, signal: AbortSignal): Promise<{
145
237
  size: number;
146
238
  isDir: boolean;
147
239
  } | null>;
148
240
  }
149
- /** 校验沙箱内路径:返回错误列表,空数组表示合法。 */
150
- export declare function validateSandboxPath(p: string): string[];
241
+ /**
242
+ * The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
243
+ * control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
244
+ * empty when valid. {@link validateSandboxPath} adds root membership.
245
+ */
246
+ export declare function validateSandboxPathShape(p: string): string[];
247
+ /**
248
+ * Checks a path inside an instance; returns the errors, empty when valid: the
249
+ * {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
250
+ * ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
251
+ */
252
+ export declare function validateSandboxPath(p: string, roots?: SandboxRoots): string[];
151
253
  /** 校验出站白名单主机名:小写、无协议与端口、可选前导 `*.`、IDN 只认 punycode。 */
152
254
  export declare function validateAllowHost(h: string): string[];
package/dist/sandbox.js CHANGED
@@ -1,17 +1,33 @@
1
1
  /**
2
- * Sandbox contract `sandbox@1`: a single-select, brokered extension point (extensions may not
2
+ * Sandbox contract `sandbox@2`: a single-select, brokered extension point (extensions may not
3
3
  * `requires` it; the kernel's `SandboxService` consumes it). The provider implements only the
4
4
  * primitives below; the kernel builds `glob` / `grep` / `edit` from `exec` plus `readFile` /
5
5
  * `writeFile`.
6
+ *
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
+ * (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
6
10
  */
7
11
  /** Sandbox extension point ref. */
8
- export const SANDBOX_EXTENSION_POINT = "sandbox@1";
9
- /** 沙箱内允许模型访问的根目录。 */
12
+ export const SANDBOX_EXTENSION_POINT = "sandbox@2";
13
+ /** The roots inside the sandbox the model may access. */
10
14
  export const SANDBOX_ROOTS = ["/workspace", "/skills", "/tmp"];
11
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
+ }
12
26
  /**
13
- * 实例在提供方那边确定已经不在了(容器被删、E2B 沙箱过期)。`exec` / `readFile` / `writeFile` / `stat`
14
- * 发现实例不在时必须抛它(而不是普通 Error),内核据此重建沙箱并重试一次;只是暂时连不上时抛普通错误。
27
+ * The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
28
+ * `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
29
+ * instance gone; the kernel then rebuilds the instance and retries once. A transient connection
30
+ * failure throws a plain error.
15
31
  */
16
32
  export class SandboxGoneError extends Error {
17
33
  sandboxGone = true;
@@ -20,12 +36,30 @@ export class SandboxGoneError extends Error {
20
36
  this.name = "SandboxGoneError";
21
37
  }
22
38
  }
23
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
39
+ /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
24
40
  export function isSandboxGoneError(e) {
25
41
  return (e instanceof Error &&
26
42
  e.name === "SandboxGoneError" &&
27
43
  e.sandboxGone === true);
28
44
  }
45
+ /**
46
+ * The file system is definitely gone on the provider's side (volume removed, E2B sandbox killed).
47
+ * `create` throws it instead of attaching the instance to a new, empty file system; the kernel then
48
+ * reports the device's files as lost rather than handing out a silently empty workspace.
49
+ */
50
+ export class FileSystemGoneError extends Error {
51
+ fileSystemGone = true;
52
+ constructor(message, opts) {
53
+ super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
54
+ this.name = "FileSystemGoneError";
55
+ }
56
+ }
57
+ /** Duck-typed check (not instanceof), so a plugin bundling another plugin-sdk copy still matches. */
58
+ export function isFileSystemGoneError(e) {
59
+ return (e instanceof Error &&
60
+ e.name === "FileSystemGoneError" &&
61
+ e.fileSystemGone === true);
62
+ }
29
63
  /**
30
64
  * A holder tag (`exec` argument `tag`, {@link SandboxProvider.killTagged}): the kernel passes its
31
65
  * lease tokens (UUIDs). Providers check tags against it before putting them in a command line or a
@@ -34,8 +68,12 @@ export function isSandboxGoneError(e) {
34
68
  export const SANDBOX_TAG_RE = /^[a-z0-9-]{1,64}$/;
35
69
  // biome-ignore lint/suspicious/noControlCharactersInRegex: 正是要拦控制字符
36
70
  const CONTROL = /[\u0000-\u001f\u007f]/;
37
- /** 校验沙箱内路径:返回错误列表,空数组表示合法。 */
38
- export function validateSandboxPath(p) {
71
+ /**
72
+ * The root-independent checks of a path inside an instance (non-empty, at most 4096 characters, no
73
+ * control characters or backslashes, absolute, no empty or `..` segments); returns the errors,
74
+ * empty when valid. {@link validateSandboxPath} adds root membership.
75
+ */
76
+ export function validateSandboxPathShape(p) {
39
77
  if (typeof p !== "string" || p.length === 0)
40
78
  return ["path must be a non-empty string"];
41
79
  if (p.length > MAX_PATH_LENGTH)
@@ -48,22 +86,41 @@ export function validateSandboxPath(p) {
48
86
  return ["path must be absolute"];
49
87
  if (p.includes("//"))
50
88
  return ["path must not contain empty segments"];
51
- const errors = [];
52
89
  for (const seg of p.split("/")) {
53
90
  let decoded = seg;
54
91
  try {
55
92
  decoded = decodeURIComponent(seg);
56
93
  }
57
94
  catch {
58
- // 非法百分号编码按字面处理
95
+ // invalid percent-encoding is taken literally
59
96
  }
60
97
  if (seg === ".." || decoded === ".." || decoded.includes("/") || decoded.includes("\\")) {
61
- errors.push("path must not contain '..' segments");
62
- break;
98
+ return ["path must not contain '..' segments"];
63
99
  }
64
100
  }
65
- if (!SANDBOX_ROOTS.some((r) => p === r || p.startsWith(`${r}/`))) {
66
- errors.push(`path must be under ${SANDBOX_ROOTS.join(", ")}`);
101
+ return [];
102
+ }
103
+ /** A structural error after which {@link validateSandboxPath} stops (before the root check). */
104
+ const STOPS = new Set([
105
+ "path must be a non-empty string",
106
+ `path must be at most ${MAX_PATH_LENGTH} characters`,
107
+ "path must not contain control characters",
108
+ "path must not contain backslashes",
109
+ "path must be absolute",
110
+ "path must not contain empty segments",
111
+ ]);
112
+ /**
113
+ * Checks a path inside an instance; returns the errors, empty when valid: the
114
+ * {@link validateSandboxPathShape} checks, then root membership. `roots`: the instance's roots
115
+ * ({@link rootsOf}); absent means {@link SANDBOX_ROOTS}. The path must be one of them or under one.
116
+ */
117
+ export function validateSandboxPath(p, roots) {
118
+ const errors = validateSandboxPathShape(p);
119
+ if (errors.some((e) => STOPS.has(e)))
120
+ return errors;
121
+ const allowed = roots === undefined ? SANDBOX_ROOTS : [roots.workspace, roots.skills, roots.tmp];
122
+ if (!allowed.some((r) => p === r || p.startsWith(`${r}/`))) {
123
+ errors.push(`path must be under ${allowed.join(", ")}`);
67
124
  }
68
125
  return errors;
69
126
  }
package/dist/secret.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import type { z } from "zod";
2
- /** 标记一个 schema 为敏感字段(Zod 4 meta `{ secret: true }`)。 */
2
+ /**
3
+ * Marks a schema as a secret field (Zod 4 meta `{ secret: true }`), merging with existing meta
4
+ * (`ui` hints, `hot`), so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
5
+ */
3
6
  export declare function secret<T extends z.ZodTypeAny>(schema: T): T;
4
7
  /** 读取 schema 的 meta,判断是否敏感;内核 `meta({secret:true})` 同样可识别。 */
5
8
  export declare function isSecret(schema: z.ZodTypeAny): boolean;
package/dist/secret.js CHANGED
@@ -1,6 +1,9 @@
1
- /** 标记一个 schema 为敏感字段(Zod 4 meta `{ secret: true }`)。 */
1
+ /**
2
+ * Marks a schema as a secret field (Zod 4 meta `{ secret: true }`), merging with existing meta
3
+ * (`ui` hints, `hot`), so `secret(ui(x, …))` and `ui(secret(x), …)` are the same.
4
+ */
2
5
  export function secret(schema) {
3
- return schema.meta({ secret: true });
6
+ return schema.meta({ ...(schema.meta() ?? {}), secret: true });
4
7
  }
5
8
  /** 读取 schema 的 meta,判断是否敏感;内核 `meta({secret:true})` 同样可识别。 */
6
9
  export function isSecret(schema) {
@@ -0,0 +1,115 @@
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 in `reason` or `fix`. The kernel replaces known secret values with
14
+ * `[REDACTED]` before caching or returning, but it can only redact what it knows.
15
+ *
16
+ * What a check receives is what the extension already receives for the same target, nothing more:
17
+ * a channel connection's config (as `channel@1` `verify` and `connect` get it), or a connector's
18
+ * ids and OAuth client id. A check never gets the OAuth client secret or a member's token; those
19
+ * stay with the kernel and the connector extension's `auth()` (decided 2026-11-09).
20
+ */
21
+ import type { SetupGuidePlace } from "./setup-guide.js";
22
+ /**
23
+ * `ok`: verified now. `failing`: verified wrong (needs a reason; should have a fix). `unknown`:
24
+ * could not tell (third party down, rate limited, the check does not apply yet); never a failure
25
+ * the person must act on.
26
+ */
27
+ export type SetupCheckStatus = "ok" | "failing" | "unknown";
28
+ /** Plain text in English (required) and optionally Chinese; rendered as text, never Markdown. */
29
+ export interface SetupCheckText {
30
+ readonly en: string;
31
+ readonly zh?: string;
32
+ }
33
+ /**
34
+ * The answer of a check. There is deliberately no structured details field: a result has nowhere
35
+ * for a token to hide. {@link validateSetupCheckResult} refuses any other key.
36
+ */
37
+ export interface SetupCheckResult {
38
+ readonly status: SetupCheckStatus;
39
+ /** Why, in a sentence. At most `reasonChars` per language. Required when `failing`. */
40
+ readonly reason?: SetupCheckText;
41
+ /** What to do when failing. At most `fixChars` per language. */
42
+ readonly fix?: SetupCheckText;
43
+ }
44
+ /**
45
+ * What a check is about. The kernel builds it field by field; it only ever names targets of the
46
+ * check's own plugin (a channel connection on the plugin, a connector made from one of its
47
+ * templates).
48
+ */
49
+ export type SetupCheckTarget = {
50
+ readonly kind: "channel-connection";
51
+ readonly connectionId: string;
52
+ /** The connection config as `channel@1` `verify` and `connect` receive it, secrets included. */
53
+ readonly config: unknown;
54
+ } | {
55
+ readonly kind: "connector";
56
+ readonly connectorId: string;
57
+ readonly templateId: string;
58
+ /** The OAuth client id when the template uses a manual client; never the client secret. */
59
+ readonly clientId: string | null;
60
+ /** The viewing member's account, for member-audience checks; never their token. */
61
+ readonly accountId: string | null;
62
+ };
63
+ /** What `run` receives. */
64
+ export interface SetupCheckArgs {
65
+ readonly orgId: string;
66
+ /** The extension's effective config for the org (platform config plus the org's copy). */
67
+ readonly config: unknown;
68
+ readonly locale: "en" | "zh";
69
+ /** The guide's mode (`long_connection`, `webhook`), or null when the place has none. */
70
+ readonly mode: string | null;
71
+ readonly target: SetupCheckTarget;
72
+ /** Aborted at the kernel's timeout or when the extension is disposed. Pass it to every request. */
73
+ readonly signal: AbortSignal;
74
+ }
75
+ /** A check registered with `ctx.setup.check`. */
76
+ export interface SetupCheckDefinition {
77
+ /** The place whose guides may use the check; the kernel runs it only for targets of that place. */
78
+ place: SetupGuidePlace;
79
+ /** Never writes, passes `signal` on, does not retry, never puts a secret in the result. */
80
+ run(args: SetupCheckArgs): Promise<SetupCheckResult>;
81
+ }
82
+ /**
83
+ * A check id an extension declares and registers. Ids with `:` belong to the kernel
84
+ * (`capybara:*`), so an extension cannot shadow a kernel check.
85
+ */
86
+ export declare const SETUP_CHECK_ID_RE: RegExp;
87
+ /** Limits of setup checks (spec §10.5). Characters are UTF-16 code units. */
88
+ export declare const SETUP_CHECK_LIMITS: Readonly<{
89
+ /** Per run; the kernel aborts `signal` and records `unknown`. */
90
+ readonly timeoutMs: 10000;
91
+ /** Characters of `reason`, per language. */
92
+ readonly reasonChars: 300;
93
+ /** Characters of `fix`, per language. */
94
+ readonly fixChars: 500;
95
+ /** A cached result stays fresh this long (and for the same input fingerprint). */
96
+ readonly freshMs: 300000;
97
+ /** A forced rerun of one check and target at most this often. */
98
+ readonly cooldownMs: 10000;
99
+ /** Concurrent runs per org across all replicas. */
100
+ readonly orgConcurrency: 8;
101
+ /** Run requests per account per minute. */
102
+ readonly perAccountPerMinute: 30;
103
+ /** Ids in `permissions.setupChecks`. */
104
+ readonly idsPerExtension: 32;
105
+ }>;
106
+ type Problem = {
107
+ problem: string;
108
+ };
109
+ /**
110
+ * The result as a fresh plain object holding only `status`, `reason` and `fix`, or why it is
111
+ * invalid (English). The kernel treats an invalid result as `unknown` and logs the problem. Run
112
+ * kernel redaction on the returned copy, then validate again (redaction can change the length).
113
+ */
114
+ export declare function validateSetupCheckResult(x: unknown): SetupCheckResult | Problem;
115
+ export {};