@capybara-hq/plugin-sdk 0.1.0-rc.9 → 0.1.0-rc.90

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 (159) hide show
  1. package/README.md +3 -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 +11 -3
  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 +3 -1
  9. package/agent-docs/extension-points/identity-source.md +2 -0
  10. package/agent-docs/extension-points/model-provider.md +5 -1
  11. package/agent-docs/extension-points/object-store.md +2 -0
  12. package/agent-docs/extension-points/push-provider.md +17 -0
  13. package/agent-docs/extension-points/trigger-source.md +19 -0
  14. package/agent-docs/extensions.md +98 -4
  15. package/agent-docs/plugin-format.md +45 -10
  16. package/agent-docs/setup.md +54 -0
  17. package/api/plugin-sdk.api.md +5983 -0
  18. package/dist/agent-template.d.ts +15 -6
  19. package/dist/agent-template.js +32 -13
  20. package/dist/agents-ctx.d.ts +116 -0
  21. package/dist/agents-ctx.js +22 -0
  22. package/dist/avatar-presets.d.ts +8 -0
  23. package/dist/avatar-presets.js +17 -0
  24. package/dist/bootstrap.d.ts +109 -1
  25. package/dist/bootstrap.js +185 -2
  26. package/dist/cards.d.ts +121 -13
  27. package/dist/cards.js +161 -19
  28. package/dist/channel.d.ts +133 -47
  29. package/dist/channel.js +10 -5
  30. package/dist/client-css.d.ts +36 -0
  31. package/dist/client-css.js +326 -0
  32. package/dist/client-section.d.ts +35 -0
  33. package/dist/client-section.js +133 -0
  34. package/dist/config-ui.d.ts +28 -6
  35. package/dist/config-ui.js +88 -25
  36. package/dist/config-url-fetch.d.ts +19 -0
  37. package/dist/config-url-fetch.js +43 -0
  38. package/dist/connector-auth.d.ts +13 -2
  39. package/dist/connector-auth.js +82 -8
  40. package/dist/connector.d.ts +74 -32
  41. package/dist/context.d.ts +40 -0
  42. package/dist/context.js +2 -0
  43. package/dist/ctx.d.ts +344 -31
  44. package/dist/ctx.js +9 -1
  45. package/dist/define-extension.d.ts +18 -12
  46. package/dist/define-extension.js +18 -5
  47. package/dist/device-denied-paths.d.ts +20 -0
  48. package/dist/device-denied-paths.js +118 -0
  49. package/dist/device-operation.d.ts +348 -0
  50. package/dist/device-operation.js +312 -0
  51. package/dist/device-protocol.d.ts +286 -49
  52. package/dist/device-protocol.js +766 -89
  53. package/dist/device-provider.d.ts +820 -0
  54. package/dist/device-provider.js +432 -0
  55. package/dist/device-service.d.ts +204 -0
  56. package/dist/device-service.js +291 -0
  57. package/dist/dial-in.d.ts +286 -0
  58. package/dist/dial-in.js +213 -0
  59. package/dist/directory.d.ts +15 -12
  60. package/dist/extension-point.d.ts +2 -0
  61. package/dist/extension-point.js +8 -3
  62. package/dist/field-meta.d.ts +19 -0
  63. package/dist/field-meta.js +54 -0
  64. package/dist/file-preview.d.ts +46 -9
  65. package/dist/git-hosts.d.ts +53 -0
  66. package/dist/git-hosts.js +98 -0
  67. package/dist/hooks.d.ts +185 -22
  68. package/dist/hooks.js +6 -0
  69. package/dist/http-access.d.ts +71 -0
  70. package/dist/http-access.js +12 -0
  71. package/dist/identity.d.ts +70 -9
  72. package/dist/identity.js +46 -1
  73. package/dist/inbox.d.ts +103 -0
  74. package/dist/inbox.js +173 -0
  75. package/dist/index.d.ts +30 -4
  76. package/dist/index.js +30 -4
  77. package/dist/model-params.d.ts +41 -22
  78. package/dist/model-params.js +28 -15
  79. package/dist/model.d.ts +295 -77
  80. package/dist/model.js +249 -21
  81. package/dist/native-failure.d.ts +13 -0
  82. package/dist/native-failure.js +31 -0
  83. package/dist/net.d.ts +52 -0
  84. package/dist/net.js +34 -0
  85. package/dist/network-classes.d.ts +98 -0
  86. package/dist/network-classes.js +291 -0
  87. package/dist/permissions.d.ts +95 -25
  88. package/dist/permissions.js +175 -54
  89. package/dist/platform-only.d.ts +27 -0
  90. package/dist/platform-only.js +35 -0
  91. package/dist/plugin-manifest.d.ts +30 -6
  92. package/dist/plugin-manifest.js +147 -55
  93. package/dist/plugin-package.d.ts +82 -39
  94. package/dist/plugin-package.js +68 -41
  95. package/dist/push.d.ts +75 -0
  96. package/dist/push.js +87 -0
  97. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  98. package/dist/sandbox-linux-runtime-source.js +2343 -0
  99. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  100. package/dist/sandbox-native-runtime-source.js +480 -0
  101. package/dist/sandbox-runtime-source.d.ts +47 -0
  102. package/dist/sandbox-runtime-source.js +73 -0
  103. package/dist/sandbox-write-denies.d.ts +139 -0
  104. package/dist/sandbox-write-denies.js +869 -0
  105. package/dist/secret.d.ts +8 -2
  106. package/dist/secret.js +11 -4
  107. package/dist/setup-check.d.ts +128 -0
  108. package/dist/setup-check.js +142 -0
  109. package/dist/setup-guide-parse.d.ts +121 -0
  110. package/dist/setup-guide-parse.js +356 -0
  111. package/dist/setup-guide-render.d.ts +45 -0
  112. package/dist/setup-guide-render.js +351 -0
  113. package/dist/setup-guide.d.ts +86 -72
  114. package/dist/setup-guide.js +340 -108
  115. package/dist/shell-capabilities.d.ts +216 -0
  116. package/dist/shell-capabilities.js +44 -0
  117. package/dist/shell-environment.d.ts +57 -0
  118. package/dist/shell-environment.js +21 -0
  119. package/dist/skill-invocation.d.ts +5 -0
  120. package/dist/skill-invocation.js +4 -3
  121. package/dist/skill.d.ts +27 -17
  122. package/dist/skill.js +40 -26
  123. package/dist/storage.d.ts +52 -25
  124. package/dist/svg-viewbox.d.ts +10 -0
  125. package/dist/svg-viewbox.js +24 -0
  126. package/dist/theme-assets.d.ts +25 -9
  127. package/dist/theme-assets.js +87 -47
  128. package/dist/theme-tokens.generated.d.ts +40 -12
  129. package/dist/theme-tokens.generated.js +36 -8
  130. package/dist/theme.d.ts +56 -10
  131. package/dist/theme.js +117 -23
  132. package/dist/tool.d.ts +242 -28
  133. package/dist/tool.js +135 -13
  134. package/dist/trigger-source.d.ts +35 -0
  135. package/dist/trigger-source.js +2 -0
  136. package/dist/triggers.d.ts +88 -0
  137. package/dist/triggers.js +71 -0
  138. package/dist/ui-parts.d.ts +23 -0
  139. package/dist/ui-parts.js +374 -0
  140. package/dist/ui-resolve.d.ts +2 -7
  141. package/dist/ui-resolve.js +7 -19
  142. package/dist/ui-slots.d.ts +27 -5
  143. package/dist/ui-slots.js +112 -19
  144. package/dist/ui.d.ts +203 -64
  145. package/dist/ui.js +117 -23
  146. package/dist/url.d.ts +4 -1
  147. package/dist/url.js +4 -1
  148. package/dist/web.d.ts +26 -20
  149. package/package.json +13 -1
  150. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  151. package/schemas/bootstrap.v1.schema.json +20 -0
  152. package/schemas/connector-template.v1.schema.json +62 -4
  153. package/schemas/plugin.v1.schema.json +74 -143
  154. package/schemas/theme.v1.schema.json +77 -0
  155. package/agent-docs/extension-points/sandbox.md +0 -15
  156. package/dist/org-access.d.ts +0 -27
  157. package/dist/org-access.js +0 -35
  158. package/dist/sandbox.d.ts +0 -254
  159. package/dist/sandbox.js +0 -153
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Paths a local device never opens to restricted work (Request approval, Approve for me), relative
3
+ * to `~` (spec §13.6, extended by ruling R19): SSH keys, cloud CLI credentials, container and
4
+ * Kubernetes credentials, netrc, GnuPG, git / npm / PyPI tokens, the macOS keychains, the
5
+ * browser profile directories, other tool credential stores (cargo, 1Password, Vault, Terraform,
6
+ * Claude, Codex, keyrings, pass, rclone, s3cmd), mise's config directory and the config files it
7
+ * loads from the home (an `[env]` section may hold tokens; globbed names like `~/mise.<env>.toml`
8
+ * are not listed), Maven and Gradle credential files, database and X11 credential files, and
9
+ * shell and REPL histories. Secrets a shell start file exports (`export TOKEN=…` in `~/.bashrc`)
10
+ * are not covered: start files stay readable so sandboxed shells behave as the owner's. One source for
11
+ * the device, which denies them (and its own state directory), and the kernel, which never proposes
12
+ * an approval for a path under one. Full access and auto mode run as the owner and do not apply
13
+ * them: the command review does.
14
+ */
15
+ export const DEVICE_DENIED_SECRET_PATHS = Object.freeze([
16
+ "~/.ssh",
17
+ "~/.aws",
18
+ "~/.config/gcloud",
19
+ "~/.azure",
20
+ "~/.kube",
21
+ "~/.docker/config.json",
22
+ "~/.netrc",
23
+ "~/.gnupg",
24
+ "~/Library/Application Support/Google/Chrome",
25
+ "~/Library/Application Support/Firefox",
26
+ "~/.mozilla",
27
+ "~/.config/google-chrome",
28
+ "~/.config/chromium",
29
+ // Ruling R19: more credential stores and browser data.
30
+ "~/.config/gh",
31
+ "~/.git-credentials",
32
+ "~/.npmrc",
33
+ "~/.pypirc",
34
+ "~/Library/Keychains",
35
+ "~/Library/Cookies",
36
+ "~/Library/Safari",
37
+ "~/Library/Application Support/BraveSoftware",
38
+ "~/Library/Application Support/Microsoft Edge",
39
+ "~/Library/Application Support/Arc",
40
+ "~/.config/BraveSoftware",
41
+ "~/.config/microsoft-edge",
42
+ // Machine reach reads the whole home, so more tool credential stores and shell histories.
43
+ "~/.cargo/credentials",
44
+ "~/.cargo/credentials.toml",
45
+ "~/.config/op",
46
+ "~/.vault-token",
47
+ "~/.terraform.d/credentials.tfrc.json",
48
+ "~/.claude/.credentials.json",
49
+ "~/.codex/auth.json",
50
+ "~/.local/share/keyrings",
51
+ "~/.password-store",
52
+ "~/.config/rclone",
53
+ "~/.s3cfg",
54
+ // mise: its whole config directory (config files with [env] sections, the sops age key; its
55
+ // data lives in ~/.local/share/mise) and the config files it walks up to in the home. Globbed
56
+ // spellings such as ~/mise.<env>.toml cannot be listed here and stay readable.
57
+ "~/.config/mise",
58
+ "~/.config/mise.toml",
59
+ "~/.config/mise.local.toml",
60
+ "~/.mise.toml",
61
+ "~/.mise.local.toml",
62
+ "~/.mise",
63
+ "~/mise.toml",
64
+ "~/mise.local.toml",
65
+ "~/mise/config.toml",
66
+ "~/mise/config.local.toml",
67
+ "~/mise/conf.d",
68
+ // mise's legacy (rtx) names
69
+ "~/.rtx.toml",
70
+ "~/.rtx.local.toml",
71
+ // Maven server passwords (and their master keys), Gradle repository credentials and Develocity
72
+ // (Gradle Enterprise) access keys
73
+ "~/.m2/settings.xml",
74
+ "~/.m2/settings-security.xml",
75
+ "~/.m2/settings-security4.xml",
76
+ "~/.gradle/gradle.properties",
77
+ "~/.gradle/develocity/keys.properties",
78
+ "~/.gradle/enterprise/keys.properties",
79
+ // Database, X11 session and other credential files directly in the home (machine reach on
80
+ // Linux grants the files beside a denied path one by one)
81
+ "~/.pgpass",
82
+ "~/.my.cnf",
83
+ "~/.Xauthority",
84
+ "~/.ICEauthority",
85
+ "~/.config/hub",
86
+ "~/.boto",
87
+ "~/.dockercfg",
88
+ "~/.smbcredentials",
89
+ "~/.terraformrc",
90
+ "~/.yarnrc.yml",
91
+ "~/.databrickscfg",
92
+ "~/.passwd-s3fs",
93
+ "~/.erlang.cookie",
94
+ "~/.curlrc",
95
+ "~/.wgetrc",
96
+ "~/.claude.json",
97
+ // shell and REPL histories (commands with inlined secrets)
98
+ "~/.bash_history",
99
+ "~/.zsh_history",
100
+ "~/.psql_history",
101
+ "~/.mysql_history",
102
+ "~/.python_history",
103
+ "~/.node_repl_history",
104
+ "~/.sqlite_history",
105
+ "~/.histfile",
106
+ "~/.zhistory",
107
+ "~/.sh_history",
108
+ "~/.lesshst",
109
+ "~/.viminfo",
110
+ "~/.rediscli_history",
111
+ "~/.irb_history",
112
+ "~/.Rhistory",
113
+ ]);
114
+ /**
115
+ * The device program's default state directory (`$XDG_CONFIG_HOME/capybara-device` when that is
116
+ * set), relative to `~`: denied to restricted work like the secret paths.
117
+ */
118
+ export const DEVICE_DEFAULT_STATE_PATH = "~/.config/capybara-device";
@@ -0,0 +1,348 @@
1
+ import { type DeviceProvider, type ExecResult, type SandboxActor, type SandboxHandle } from "./device-provider.js";
2
+ /** The permission profile selected for a conversation. */
3
+ export type PermissionProfile = "request-approval" | "approve-for-me" | "full-access";
4
+ /** Accepts only the supported permission profile names. */
5
+ export declare function isPermissionProfile(value: unknown): value is PermissionProfile;
6
+ /** The provider cannot enforce the requested permission profile. */
7
+ export declare class SandboxPermissionUnsupportedError extends Error {
8
+ readonly sandboxPermissionUnsupported: true;
9
+ constructor(message: string, opts?: ErrorOptions);
10
+ }
11
+ /**
12
+ * Recognizes the inherited tag across SDK copies without requiring this class's identity, so every
13
+ * subclass counts too (for example {@link SandboxWorkUnsettledError}: the same definite refusal).
14
+ */
15
+ export declare function isSandboxPermissionUnsupportedError(e: unknown): e is SandboxPermissionUnsupportedError;
16
+ /**
17
+ * Earlier work on the device has not settled, so it refused to start a new operation. It extends
18
+ * {@link SandboxPermissionUnsupportedError} so every check that treats that error as a definite
19
+ * refusal (nothing ran) treats this one the same way.
20
+ */
21
+ export declare class SandboxWorkUnsettledError extends SandboxPermissionUnsupportedError {
22
+ readonly sandboxWorkUnsettled: true;
23
+ constructor(message: string, opts?: ErrorOptions);
24
+ }
25
+ /** Recognizes the name and tag across SDK copies without requiring this class's identity. */
26
+ export declare function isSandboxWorkUnsettledError(e: unknown): e is SandboxWorkUnsettledError;
27
+ /** The requested operation is outside the permitted scope. */
28
+ export declare class SandboxScopeDeniedError extends Error {
29
+ readonly sandboxScopeDenied: true;
30
+ constructor(message: string, opts?: ErrorOptions);
31
+ }
32
+ /** Recognizes the name and tag across SDK copies without requiring this class's identity. */
33
+ export declare function isSandboxScopeDeniedError(e: unknown): e is SandboxScopeDeniedError;
34
+ /**
35
+ * A request refused because the machine's connection changed before it was sent: the request
36
+ * never reached the machine, so it ran nothing. A scope refusal (it keeps that error's name, so
37
+ * every scope check treats it as the definite pre-effect failure it is) that the operation path
38
+ * records as `not_sent`, never as an unknown outcome. It says nothing about an earlier request of
39
+ * the same operation, so a recovery tells it apart ({@link isDeviceRequestNotSent}).
40
+ *
41
+ * A provider throws it too when it finds the instance gone before contacting the machine (for
42
+ * example the machine's runtime changed since the instance was created), with a
43
+ * `SandboxGoneError` as its `cause`: nothing ran, and the kernel also rebuilds the instance so a
44
+ * retry of the call runs on the new one. A gone instance found after the request was sent is a
45
+ * bare `SandboxGoneError` (its outcome is unknown).
46
+ */
47
+ export declare class DeviceRequestNotSentError extends SandboxScopeDeniedError {
48
+ readonly notSent: true;
49
+ }
50
+ /** Recognizes {@link DeviceRequestNotSentError} by its scope refusal's name and tags, across SDK copies. */
51
+ export declare function isDeviceRequestNotSent(e: unknown): boolean;
52
+ /** A scope or execution reference is malformed; validate it before performing any effects. */
53
+ export declare class SandboxScopeValidationError extends Error {
54
+ readonly sandboxScopeValidation: true;
55
+ constructor(message: string, opts?: ErrorOptions);
56
+ }
57
+ /** Recognizes validation errors across SDK copies. */
58
+ export declare function isSandboxScopeValidationError(e: unknown): e is SandboxScopeValidationError;
59
+ /** An operation was consumed but its outcome is unknown. Never automatically retry with a new ID. */
60
+ export declare class SandboxOperationOutcomeUnknownError extends Error {
61
+ readonly sandboxOperationOutcomeUnknown: true;
62
+ constructor(message: string, opts?: ErrorOptions);
63
+ }
64
+ /** Recognizes unknown outcomes across SDK copies; an unknown outcome is not a gone instance. */
65
+ export declare function isSandboxOperationOutcomeUnknownError(e: unknown): e is SandboxOperationOutcomeUnknownError;
66
+ /**
67
+ * A scoped operation names the project root (null in free mode) and the roots it may write; what
68
+ * it may read is the provider's rule. Writable roots are also readable. Device scope uses the
69
+ * device's OS authority, never its host's.
70
+ */
71
+ export type SandboxFileScope = {
72
+ readonly kind: "scoped";
73
+ readonly projectRoot: string | null;
74
+ readonly writeRoots: readonly string[];
75
+ } | {
76
+ readonly kind: "device";
77
+ };
78
+ /** Environment removes only the agent-specific filter; owner/org/provider ceilings still apply. */
79
+ export type SandboxNetworkScope = {
80
+ readonly kind: "none";
81
+ } | {
82
+ readonly kind: "allowlist";
83
+ readonly hosts: readonly string[];
84
+ }
85
+ /**
86
+ * The public internet, decided on the resolved address against `AddressClass`
87
+ * (`network-classes.ts`): every class in `OPEN_PUBLIC_DENIED_CLASSES` stays closed.
88
+ */
89
+ | {
90
+ readonly kind: "open-public";
91
+ }
92
+ /** Only with `filesystem: { kind: "device" }` (and the reverse): the escalated (outside) call. */
93
+ | {
94
+ readonly kind: "environment";
95
+ };
96
+ /** An operation locator for idempotent admission and revocation, never a credential. */
97
+ export interface SandboxOperationRef {
98
+ readonly operationId: string;
99
+ /** Absolute launch-admission deadline; does not shorten an already started execution's timeout. */
100
+ readonly admitBeforeMs: number;
101
+ }
102
+ /**
103
+ * A fresh grant for one method invocation. Providers must copy and freeze the input before use.
104
+ * Full access normally uses device/environment; explicit bounded grants may expand other profiles.
105
+ * Validation does not resolve authority or infer a grant from the profile name.
106
+ */
107
+ export interface SandboxOperationScope extends SandboxOperationRef {
108
+ readonly deviceId: string;
109
+ readonly rootConversationId: string;
110
+ readonly profileRevision: number;
111
+ readonly ceilingRevision: string;
112
+ readonly profile: PermissionProfile;
113
+ readonly actor: Readonly<SandboxActor>;
114
+ readonly tag: string;
115
+ readonly filesystem: SandboxFileScope;
116
+ readonly network: SandboxNetworkScope;
117
+ }
118
+ /**
119
+ * Where a provider's sandbox boundary lies: around each operation (the OS sandbox of a local device,
120
+ * the Linux per-operation runtime) or around the whole instance (a cloud container or microVM).
121
+ */
122
+ export type SandboxBoundary = "operation" | "instance";
123
+ /**
124
+ * Runtime support, version 2 (approval-only profiles design, "SDK and protocol"). `boundary:
125
+ * "instance"` with `restricted: null` is a supported device whose scope is the whole instance.
126
+ * `outsideSandbox` says whether a call can run outside the sandbox (an escalated call). Runtime
127
+ * support, not consent. `limitedBy` names who keeps a crossing closed when it is not the provider
128
+ * itself ({@link SandboxSupportLimitedBy}); absent, a closed crossing is the provider's own limit.
129
+ */
130
+ export interface SandboxPermissionSupport {
131
+ readonly version: 2;
132
+ readonly boundary: SandboxBoundary;
133
+ readonly restricted: {
134
+ readonly filesystem: true;
135
+ readonly network: true;
136
+ readonly native: true;
137
+ readonly concurrentScopes: true;
138
+ } | null;
139
+ readonly network: {
140
+ readonly openPublic: boolean;
141
+ readonly allowlist: boolean;
142
+ readonly perOperationHosts: boolean;
143
+ /**
144
+ * Whether a device service can be granted exact loopback ports
145
+ * (`DeviceProvider.ensureService` `loopbackPorts`). Needs `outsideSandbox` on an operation
146
+ * boundary; absent means false (a provider built on an earlier SDK).
147
+ */
148
+ readonly loopbackPorts?: boolean;
149
+ };
150
+ readonly outsideSandbox: boolean;
151
+ readonly background: boolean;
152
+ readonly unavailableReason?: string;
153
+ readonly limitedBy?: SandboxSupportLimitedBy;
154
+ }
155
+ /**
156
+ * Who keeps a closed crossing of a {@link SandboxPermissionSupport} closed, when it is not the
157
+ * provider itself: `owner` is the owner of the machine the device runs on (for example a local
158
+ * connection's owner ceiling, set on that machine); `device-update` means the program on that
159
+ * machine is too old to offer it (an update would). Only a closed crossing may name one:
160
+ * `outsideSandbox` with `outsideSandbox: false`, `openPublic` with `network.openPublic: false`,
161
+ * `loopbackPorts` with `network.loopbackPorts` false or absent.
162
+ * Display only: the kernel names that layer in its refusals and never enforces from it.
163
+ */
164
+ export interface SandboxSupportLimitedBy {
165
+ readonly outsideSandbox?: "owner";
166
+ readonly openPublic?: "owner";
167
+ readonly loopbackPorts?: "device-update";
168
+ }
169
+ /**
170
+ * Whether a report is a supported instance boundary: `boundary: "instance"` with no
171
+ * `unavailableReason`. An instance report naming a reason (a stale image, a digest mismatch)
172
+ * claims nothing, so a device reporting it is unsupported, never the whole-instance sandbox.
173
+ */
174
+ export declare function instanceSupported(report: SandboxPermissionSupport): boolean;
175
+ /** Actor and tag come only from the immutable operation scope. */
176
+ export type SandboxExecOptions = Omit<Parameters<DeviceProvider["exec"]>[1], "tag" | "actor">;
177
+ /**
178
+ * A lightweight factory result: no worker opens until a method is called. Factory and method
179
+ * signals jointly end the operation. Every method consumes its operation ID before effects;
180
+ * a matching retry returns the recorded result or SandboxOperationOutcomeUnknownError, never
181
+ * repeats effects. Missing operation support has no fallback to the provider's raw methods.
182
+ * Native results and exec abort/timeout/output semantics match the existing provider contract.
183
+ */
184
+ export interface SandboxOperation {
185
+ exec(args: SandboxExecOptions): Promise<ExecResult>;
186
+ readFile(path: string, opts: {
187
+ maxBytes: number;
188
+ signal: AbortSignal;
189
+ }): Promise<{
190
+ data: Uint8Array;
191
+ truncated: boolean;
192
+ } | null>;
193
+ writeFile(path: string, data: Uint8Array, signal: AbortSignal): Promise<void>;
194
+ stat(path: string, signal: AbortSignal): Promise<{
195
+ size: number;
196
+ isDir: boolean;
197
+ } | null>;
198
+ /** List and scan are optional together; without both, projects are unavailable. */
199
+ list?(path: string, opts: {
200
+ limit: number;
201
+ signal: AbortSignal;
202
+ }): Promise<{
203
+ entries: {
204
+ name: string;
205
+ isDir: boolean;
206
+ }[];
207
+ truncated: boolean;
208
+ } | null>;
209
+ scan?(base: string, opts: {
210
+ signal: AbortSignal;
211
+ }): Promise<{
212
+ path: string;
213
+ suggestedName: string;
214
+ }[]>;
215
+ }
216
+ /** Trusted staging only: providers validate purpose-specific roots; user tools never supply this grant. */
217
+ export interface SandboxPreparationScope {
218
+ readonly operationId: string;
219
+ readonly deviceId: string;
220
+ readonly purpose: "skills" | "attachments";
221
+ readonly writeRoots: readonly string[];
222
+ readonly tag: string;
223
+ }
224
+ /** Marker reads and writes inside trusted preparation roots, with no exec or network capability. */
225
+ export type SandboxPreparation = Pick<SandboxOperation, "readFile" | "writeFile" | "stat">;
226
+ /** Owner-authenticated browsing, independent of a conversation or its profile/consent. */
227
+ export interface SandboxBrowseScope extends SandboxOperationRef {
228
+ readonly deviceId: string;
229
+ readonly accountId: string;
230
+ readonly ceilingRevision: string;
231
+ readonly readRoots: readonly string[];
232
+ readonly tag: string;
233
+ }
234
+ /** Browsing exposes metadata only: no file contents, writes, preparation or execution. */
235
+ export type SandboxBrowse = Pick<SandboxOperation, "stat"> & Required<Pick<SandboxOperation, "list" | "scan">>;
236
+ /**
237
+ * An opaque locator over authenticated transport; validate generation before status, tail or stop.
238
+ * `instanceGeneration` is the provider's own generation of the instance (the kernel's when the
239
+ * provider keeps none); the kernel stores the ref as returned and never compares it with its own.
240
+ */
241
+ export interface SandboxExecutionRef {
242
+ readonly executionId: string;
243
+ readonly operationId: string;
244
+ readonly instanceId: string;
245
+ readonly instanceGeneration: string;
246
+ }
247
+ /** A lost supervisor never binds this reference to a reused PID. */
248
+ export type SandboxExecutionStatus = {
249
+ state: "running";
250
+ } | {
251
+ state: "exited";
252
+ exitCode: number | null;
253
+ timedOut: boolean;
254
+ } | {
255
+ state: "lost";
256
+ };
257
+ /** Atomically claimed terminal outcome; retries preserve it, including a prior natural exit. */
258
+ export type SandboxStopResult = {
259
+ outcome: "already-exited";
260
+ exitCode: number | null;
261
+ timedOut: boolean;
262
+ } | {
263
+ outcome: "stopped";
264
+ } | {
265
+ outcome: "cancel-pending";
266
+ } | {
267
+ outcome: "lost";
268
+ };
269
+ /** Trusted exact-execution supervision. Status, tail and stop never provision or resume an instance. */
270
+ export interface SandboxBackground {
271
+ /**
272
+ * Persist exact ownership before acknowledging; retries of the same generation/operation/input
273
+ * return the same reference. Retain starting grants for the lifetime of the owned execution.
274
+ * Validate outputPath inside the scope. retainUntilMs bounds status/output record retention.
275
+ * instanceGeneration is the kernel's generation of the held instance `h` (the kernel always
276
+ * passes it, and allocates it only after `create` returns): a provider that keeps no generation
277
+ * of its own (a cloud provider) returns it in the reference and keys start idempotency by it; one
278
+ * that keeps its own (device-local's bound machine generation) returns that one instead. The
279
+ * kernel pins the task to its own generation and the held handle's id, not the ref's generation.
280
+ */
281
+ start(h: SandboxHandle, scope: SandboxOperationScope, args: SandboxExecOptions & {
282
+ taskId: string;
283
+ outputPath: string;
284
+ retainUntilMs: number;
285
+ instanceGeneration?: string;
286
+ }): Promise<SandboxExecutionRef>;
287
+ status(h: SandboxHandle, ref: SandboxExecutionRef, signal: AbortSignal): Promise<SandboxExecutionStatus>;
288
+ /** At most 65,536 bytes, preserving UTF-8 boundaries and existing final-line limits; no caller path. */
289
+ tail(h: SandboxHandle, ref: SandboxExecutionRef, opts: {
290
+ maxBytes: number;
291
+ signal: AbortSignal;
292
+ }): Promise<{
293
+ data: Uint8Array;
294
+ truncated: boolean;
295
+ } | {
296
+ unavailable: "lost" | "expired";
297
+ }>;
298
+ /**
299
+ * Read retained raw merged-output bytes by exact reference, without a caller path, new scope,
300
+ * exec, provisioning or resume. Validate before I/O: offset is a nonnegative safe integer;
301
+ * maxBytes is an integer in [0, 65_536], including zero for a metadata-only probe. Invalid
302
+ * bounds throw SandboxScopeDeniedError. The byte budget includes any caller-requested overlap.
303
+ *
304
+ * totalBytes is one committed append-only prefix snapshot pinned at read admission. Return
305
+ * exactly min(maxBytes, max(totalBytes - offset, 0)) bytes starting at the requested offset,
306
+ * without UTF-8 trimming or decoding; retry short reads or report lost. nextOffset equals
307
+ * offset + data.byteLength. At/past the snapshot end, return empty data with unchanged offset.
308
+ * Reads are non-destructive and repeatable; concurrent appends cannot change returned bytes
309
+ * or this snapshot. Safe-integer position overflow fails collection rather than rounding.
310
+ *
311
+ * Missing/untrustworthy retained storage returns lost; a known expired record returns expired.
312
+ * Exact-ref/device/generation mismatches remain scope-denied errors; aborts propagate.
313
+ * Unlike tail, terminal reads retain every line. Current task access checks still apply.
314
+ */
315
+ readOutput(h: SandboxHandle, ref: SandboxExecutionRef, opts: {
316
+ offset: number;
317
+ maxBytes: number;
318
+ signal: AbortSignal;
319
+ }): Promise<{
320
+ data: Uint8Array;
321
+ offset: number;
322
+ nextOffset: number;
323
+ totalBytes: number;
324
+ } | {
325
+ unavailable: "lost" | "expired";
326
+ }>;
327
+ /** Persist pending cancellation while unreachable; apply it before an explicit resume can run work. */
328
+ stop(h: SandboxHandle, ref: SandboxExecutionRef, opts: {
329
+ graceMs: number;
330
+ signal: AbortSignal;
331
+ }): Promise<SandboxStopResult>;
332
+ }
333
+ /** Pure structural validation and a frozen copy; no clock lookup or authority resolution. */
334
+ export declare function parseSandboxOperationRef(value: unknown): SandboxOperationRef;
335
+ /**
336
+ * Validates a scope and returns a deeply frozen copy, throwing SandboxScopeValidationError.
337
+ * IDs and ceiling revisions are bounded to 128 characters; roots to 64 paths of at most 4096 characters;
338
+ * hosts to 100 entries passing validateAllowHost. Empty grants stay empty, including deny-all.
339
+ * Performs no I/O, authority lookup or deadline refresh. Unknown fields are rejected at every level.
340
+ * The `environment` network and the `device` filesystem are accepted only together.
341
+ */
342
+ export declare function parseSandboxOperationScope(value: unknown): SandboxOperationScope;
343
+ /** Validates an owner browsing grant and returns a deeply frozen copy; no conversation is required. */
344
+ export declare function parseSandboxBrowseScope(value: unknown): SandboxBrowseScope;
345
+ /** Validates trusted staging structure and returns a deeply frozen copy; does not authorize its roots. */
346
+ export declare function parseSandboxPreparationScope(value: unknown): SandboxPreparationScope;
347
+ /** Validates all four bounded locator fields and returns a frozen copy; does not authenticate the caller. */
348
+ export declare function parseSandboxExecutionRef(value: unknown): SandboxExecutionRef;