@capybara-hq/plugin-sdk 0.1.0-rc.3 → 0.1.0-rc.31

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 (127) hide show
  1. package/agent-docs/agent-templates.md +15 -3
  2. package/agent-docs/concepts.md +5 -0
  3. package/agent-docs/connector-templates.md +2 -1
  4. package/agent-docs/extension-points/channel.md +1 -1
  5. package/agent-docs/extension-points/config-source.md +1 -1
  6. package/agent-docs/extension-points/connector.md +1 -1
  7. package/agent-docs/extension-points/context.md +15 -0
  8. package/agent-docs/extension-points/counter.md +1 -1
  9. package/agent-docs/extension-points/directory.md +1 -1
  10. package/agent-docs/extension-points/file-preview.md +1 -1
  11. package/agent-docs/extension-points/identity-source.md +1 -1
  12. package/agent-docs/extension-points/model-provider.md +4 -2
  13. package/agent-docs/extension-points/object-store.md +3 -1
  14. package/agent-docs/extension-points/sandbox.md +3 -3
  15. package/agent-docs/extension-points/secret-store.md +1 -1
  16. package/agent-docs/extension-points/web-fetch.md +1 -1
  17. package/agent-docs/extension-points/web-search.md +1 -1
  18. package/agent-docs/extensions.md +29 -4
  19. package/agent-docs/plugin-format.md +43 -3
  20. package/agent-docs/setup.md +46 -0
  21. package/agent-docs/skills.md +1 -1
  22. package/agent-docs/tool-naming.md +1 -1
  23. package/dist/agent-template.d.ts +15 -6
  24. package/dist/agent-template.js +32 -13
  25. package/dist/bootstrap.d.ts +15 -1
  26. package/dist/bootstrap.js +17 -1
  27. package/dist/cards.d.ts +56 -13
  28. package/dist/cards.js +90 -20
  29. package/dist/channel.d.ts +111 -48
  30. package/dist/channel.js +10 -5
  31. package/dist/client-css.d.ts +36 -0
  32. package/dist/client-css.js +326 -0
  33. package/dist/client-section.d.ts +35 -0
  34. package/dist/client-section.js +133 -0
  35. package/dist/config-ui.d.ts +22 -0
  36. package/dist/config-ui.js +64 -4
  37. package/dist/connector-auth.d.ts +7 -2
  38. package/dist/connector-auth.js +29 -8
  39. package/dist/connector.d.ts +74 -32
  40. package/dist/context.d.ts +40 -0
  41. package/dist/context.js +2 -0
  42. package/dist/ctx.d.ts +135 -26
  43. package/dist/define-extension.d.ts +26 -12
  44. package/dist/define-extension.js +11 -4
  45. package/dist/device-protocol-v3.d.ts +117 -0
  46. package/dist/device-protocol-v3.js +409 -0
  47. package/dist/device-protocol.d.ts +330 -0
  48. package/dist/device-protocol.js +567 -0
  49. package/dist/extension-point.d.ts +2 -0
  50. package/dist/extension-point.js +5 -2
  51. package/dist/file-preview.d.ts +1 -1
  52. package/dist/git-hosts.d.ts +44 -0
  53. package/dist/git-hosts.js +81 -0
  54. package/dist/hooks.d.ts +111 -21
  55. package/dist/hooks.js +5 -0
  56. package/dist/http-access.d.ts +52 -0
  57. package/dist/http-access.js +12 -0
  58. package/dist/identity.d.ts +22 -9
  59. package/dist/index.d.ts +23 -1
  60. package/dist/index.js +24 -1
  61. package/dist/marketplace.d.ts +26 -0
  62. package/dist/marketplace.js +43 -1
  63. package/dist/model-params.d.ts +41 -22
  64. package/dist/model-params.js +28 -15
  65. package/dist/model.d.ts +180 -71
  66. package/dist/model.js +71 -19
  67. package/dist/net.d.ts +52 -0
  68. package/dist/net.js +34 -0
  69. package/dist/permissions.d.ts +42 -20
  70. package/dist/permissions.js +97 -40
  71. package/dist/plugin-manifest.d.ts +45 -5
  72. package/dist/plugin-manifest.js +169 -6
  73. package/dist/plugin-package.d.ts +82 -38
  74. package/dist/plugin-package.js +61 -29
  75. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  76. package/dist/sandbox-linux-runtime-source.js +1886 -0
  77. package/dist/sandbox-native-runtime-source.d.ts +8 -0
  78. package/dist/sandbox-native-runtime-source.js +325 -0
  79. package/dist/sandbox-operation.d.ts +248 -0
  80. package/dist/sandbox-operation.js +245 -0
  81. package/dist/sandbox-runtime-source.d.ts +19 -0
  82. package/dist/sandbox-runtime-source.js +28 -0
  83. package/dist/sandbox-write-denies.d.ts +60 -0
  84. package/dist/sandbox-write-denies.js +630 -0
  85. package/dist/sandbox.d.ts +201 -16
  86. package/dist/sandbox.js +89 -14
  87. package/dist/secret.d.ts +4 -1
  88. package/dist/secret.js +4 -1
  89. package/dist/setup-check.d.ts +115 -0
  90. package/dist/setup-check.js +142 -0
  91. package/dist/setup-guide-parse.d.ts +121 -0
  92. package/dist/setup-guide-parse.js +350 -0
  93. package/dist/setup-guide-render.d.ts +45 -0
  94. package/dist/setup-guide-render.js +351 -0
  95. package/dist/setup-guide.d.ts +94 -0
  96. package/dist/setup-guide.js +336 -0
  97. package/dist/skill-invocation.d.ts +4 -3
  98. package/dist/skill-invocation.js +5 -4
  99. package/dist/skill.d.ts +34 -21
  100. package/dist/skill.js +48 -31
  101. package/dist/storage.d.ts +52 -25
  102. package/dist/theme-assets.d.ts +39 -0
  103. package/dist/theme-assets.js +449 -0
  104. package/dist/theme-readability.d.ts +37 -0
  105. package/dist/theme-readability.js +145 -0
  106. package/dist/theme-tokens.generated.d.ts +279 -0
  107. package/dist/theme-tokens.generated.js +174 -0
  108. package/dist/theme.d.ts +152 -0
  109. package/dist/theme.js +392 -0
  110. package/dist/tool.d.ts +69 -26
  111. package/dist/tool.js +29 -9
  112. package/dist/ui-parts.d.ts +23 -0
  113. package/dist/ui-parts.js +337 -0
  114. package/dist/ui-resolve.d.ts +35 -0
  115. package/dist/ui-resolve.js +42 -0
  116. package/dist/ui-slots.d.ts +53 -0
  117. package/dist/ui-slots.js +238 -0
  118. package/dist/ui.d.ts +191 -79
  119. package/dist/ui.js +101 -27
  120. package/dist/url.d.ts +4 -1
  121. package/dist/url.js +4 -1
  122. package/package.json +7 -1
  123. package/schemas/bootstrap.v1.schema.json +6 -0
  124. package/schemas/connector-template.v1.schema.json +35 -0
  125. package/schemas/marketplace.v1.schema.json +14 -0
  126. package/schemas/plugin.v1.schema.json +115 -3
  127. package/schemas/theme.v1.schema.json +225 -0
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Device protocol v2: the WebSocket frames between the kernel and a `capybara-device` program
3
+ * (a connected machine that serves as a device). Pure types and hand-written guards.
4
+ */
5
+ import { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots } from "./sandbox.js";
6
+ /** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
7
+ export declare const DEVICE_PROTOCOL_VERSION = 2;
8
+ /** The operations the kernel asks a device to run. */
9
+ export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop" | "policy" | "policyStatus" | "list" | "scan";
10
+ /**
11
+ * Optional capabilities a device announces in its hello. `policyOp`: the device takes the `policy`
12
+ * op; `policyOpId`: it also logs each `policy` op's outcome by its `opId`, answers `policyStatus`
13
+ * and reports recent outcomes in its hello (`recentOps`); `networkReport` means exec results may
14
+ * carry `network`; `mode` means the device applies `limits.mode` / `limits.network` (without it
15
+ * the device behaves as an allowlisted sandbox); `projects` means the device serves `list` and
16
+ * `scan` (the kernel keeps a device's projects itself and asks the device only what it can read).
17
+ * The kernel gates each op on its feature, as it gates `policy` on `policyOp` / `policyOpId`: it
18
+ * never sends `list` or `scan` to a device that did not announce `projects`.
19
+ */
20
+ export type DeviceFeature = "networkReport" | "policyOp" | "policyOpId" | "mode" | "projects";
21
+ /** The most entries a `list` op may ask for and its result may carry. */
22
+ export declare const MAX_DEVICE_LIST_ENTRIES = 1000;
23
+ /** What a device knows of its local policy and reports (in the hello or a `policy` op). */
24
+ export interface DeviceLocalPolicySummary {
25
+ /** `auto` = no OS sandbox (the owner's machine); `sandbox` = the OS sandbox. */
26
+ mode: "auto" | "sandbox";
27
+ /** The device's sandbox-mode allowlist; meaningful in sandbox mode only. */
28
+ allowedDomains: string[];
29
+ }
30
+ /**
31
+ * A directory a `scan` found that looks like a project (it holds `.git` or `AGENTS.md`): a
32
+ * suggestion, not a project. `path` is absolute ({@link validateSandboxPathShape});
33
+ * `suggestedName` is a guess from its basename ({@link isDeviceProjectName}) the owner may change.
34
+ */
35
+ export interface DeviceProjectCandidate {
36
+ path: string;
37
+ suggestedName: string;
38
+ }
39
+ /**
40
+ * The kernel's current ceiling on a request that reads the device's file system outside a command
41
+ * (`readFile`, `stat`, `list`, `scan`): the device answers in the mode it would run this request in, the owner's
42
+ * choice cut to `mode`, never by a ceiling it saw on an earlier command.
43
+ */
44
+ export type DeviceRequestCeiling = Pick<SandboxLimits, "mode">;
45
+ /**
46
+ * The first line of the kernel's background task launch command (`Bash` `run_in_background`), a
47
+ * shell comment. A device kills what a foreground exec leaves running once the exec ends; an exec
48
+ * whose command starts with this line detaches a task on purpose, and its processes are left alone.
49
+ */
50
+ export declare const BACKGROUND_LAUNCH_LINE = "# capybara: background task launch";
51
+ /** Whether an exec's command is a background task launch ({@link BACKGROUND_LAUNCH_LINE}). */
52
+ export declare function isBackgroundLaunch(command: string): boolean;
53
+ /** The most blocked hosts an exec result reports; the parser cuts longer lists. */
54
+ export declare const MAX_NETWORK_BLOCKED_HOSTS = 20;
55
+ /** The longest `opId` a `policy` / `policyStatus` op may carry. */
56
+ export declare const MAX_POLICY_OP_ID_LENGTH = 128;
57
+ /** The most entries a hello's `recentOps` carries; the parser keeps the newest. */
58
+ export declare const MAX_RECENT_POLICY_OPS = 100;
59
+ /**
60
+ * What a device recorded of a `policy` op: `started` (written before the change, so an op the
61
+ * device was stopped in the middle of stays `started`), then `applied` or `refused`.
62
+ */
63
+ export type DevicePolicyOpOutcome = "applied" | "refused" | "started";
64
+ /** One entry of a hello's `recentOps`. */
65
+ export interface DevicePolicyOpReport {
66
+ opId: string;
67
+ outcome: DevicePolicyOpOutcome;
68
+ }
69
+ /** First frame from the device after the WebSocket opens. */
70
+ export interface DeviceHello {
71
+ type: "hello";
72
+ protocol: number;
73
+ programVersion: string;
74
+ os: "darwin" | "linux";
75
+ arch: string;
76
+ mode: "os" | "docker";
77
+ roots: SandboxRoots;
78
+ sessionIsolation: boolean;
79
+ /** Optional capabilities (absent on older devices; unknown entries are dropped by the parser). */
80
+ features?: DeviceFeature[];
81
+ /** The device's local policy at connect time (absent on older devices). */
82
+ policy?: DeviceLocalPolicySummary;
83
+ /**
84
+ * The outcomes of the latest `policy` ops by op id, oldest first, at most
85
+ * {@link MAX_RECENT_POLICY_OPS} (devices with `policyOpId`; malformed entries are dropped by
86
+ * the parser).
87
+ */
88
+ recentOps?: DevicePolicyOpReport[];
89
+ /**
90
+ * The owner's home directory, an absolute path (a local device; the base of an auto-mode
91
+ * project's relative path). A malformed value is dropped by the parser.
92
+ */
93
+ home?: string;
94
+ /**
95
+ * The identity of the host's current OS boot (Linux `/proc/sys/kernel/random/boot_id`; macOS
96
+ * `kern.bootsessionuuid`): a value that differs from an earlier one of the
97
+ * same machine proves the host restarted since, so no process of that earlier boot can exist.
98
+ * A malformed value is dropped by the parser.
99
+ */
100
+ bootId?: string;
101
+ }
102
+ /** A hello's `bootId`: 1 to 128 characters of letters, digits, `.`, `_`, `:` and `-`. */
103
+ export declare const DEVICE_BOOT_ID_RE: RegExp;
104
+ /** Whether `v` is a well-formed {@link DeviceHello.bootId}. */
105
+ export declare function isDeviceBootId(v: unknown): v is string;
106
+ /** Error kinds a device reports for a failed request. */
107
+ export type DeviceErrorKind = "gone" | "fs_gone" | "policy" | "error";
108
+ /** The device's answer to a {@link KernelReq}. */
109
+ export type DeviceRes = {
110
+ type: "res";
111
+ id: string;
112
+ ok: true;
113
+ result: unknown;
114
+ } | {
115
+ type: "res";
116
+ id: string;
117
+ ok: false;
118
+ error: {
119
+ kind: DeviceErrorKind;
120
+ message: string;
121
+ };
122
+ };
123
+ /** A request from the kernel. */
124
+ export interface KernelReq {
125
+ type: "req";
126
+ id: string;
127
+ op: DeviceOp;
128
+ args: unknown;
129
+ deadlineMs: number;
130
+ }
131
+ /** The kernel gives up on a request (abort or deadline). */
132
+ export interface KernelCancel {
133
+ type: "cancel";
134
+ id: string;
135
+ }
136
+ /**
137
+ * The device's local policy changed while connected (its file was edited on the machine, the owner
138
+ * switched mode): the summary as it is now, sent only when it differs from the last one sent on
139
+ * this connection. `policy` is absent when the frame's summary was unreadable; the kernel then
140
+ * learns the policy later, as for the hello.
141
+ */
142
+ export interface DevicePolicyChanged {
143
+ type: "policy";
144
+ policy?: DeviceLocalPolicySummary;
145
+ }
146
+ export type DeviceFrame = DeviceHello | DeviceRes | DevicePolicyChanged | KernelReq | KernelCancel;
147
+ export interface DeviceExecArgs {
148
+ command: string;
149
+ cwd?: string;
150
+ env?: Record<string, string>;
151
+ timeoutMs: number;
152
+ maxOutputBytes: number;
153
+ tag: string;
154
+ actor: SandboxActor;
155
+ limits: SandboxLimits;
156
+ /**
157
+ * Hosts the kernel allows for this command beyond the local policy (a run's "Allow this time" or
158
+ * a
159
+ * scheduled task's grants). A device applies them only in sandbox mode, within `limits`; a
160
+ * device without the feature ignores the field.
161
+ */
162
+ grants?: DeviceExecGrants;
163
+ }
164
+ /** Extra hosts for one exec and where they come from (logged by the device with the command). */
165
+ export interface DeviceExecGrants {
166
+ hosts: string[];
167
+ source: {
168
+ kind: "run" | "task";
169
+ id: string;
170
+ accountId: string;
171
+ };
172
+ }
173
+ export type DeviceExecResult = ExecResult;
174
+ export interface DeviceReadFileArgs {
175
+ path: string;
176
+ limits: DeviceRequestCeiling;
177
+ maxBytes: number;
178
+ }
179
+ export type DeviceReadFileResult = {
180
+ dataB64: string;
181
+ truncated: boolean;
182
+ } | null;
183
+ export interface DeviceWriteFileArgs {
184
+ path: string;
185
+ dataB64: string;
186
+ }
187
+ export type DeviceWriteFileResult = null;
188
+ export interface DeviceStatArgs {
189
+ path: string;
190
+ limits: DeviceRequestCeiling;
191
+ }
192
+ export type DeviceStatResult = {
193
+ size: number;
194
+ isDir: boolean;
195
+ } | null;
196
+ export interface DeviceKillTaggedArgs {
197
+ tags: string[];
198
+ }
199
+ export type DeviceKillAllArgs = Record<string, never>;
200
+ export interface DeviceCreateArgs {
201
+ limits: SandboxLimits;
202
+ }
203
+ export interface DeviceCreateResult {
204
+ roots: SandboxRoots;
205
+ }
206
+ export interface DeviceStopArgs {
207
+ reason: "revoked" | "deleted";
208
+ }
209
+ /**
210
+ * Edits the device's local policy. The kernel may only narrow: `mode` may turn the sandbox back on
211
+ * (`"sandbox"`), never off (turning auto mode on is decided on the machine), and `add` extends the
212
+ * sandbox-mode allowlist only. Narrowing is always accepted.
213
+ */
214
+ export interface DevicePolicyArgs {
215
+ /**
216
+ * The kernel's id of this change (non-empty, no `:`, at most {@link MAX_POLICY_OP_ID_LENGTH}
217
+ * characters): the device logs the op's outcome under it, for `policyStatus` and the hello's
218
+ * `recentOps`.
219
+ */
220
+ opId: string;
221
+ /** Hosts to add to `allowedDomains`. */
222
+ add?: string[];
223
+ /** Hosts to remove from `allowedDomains`. */
224
+ remove?: string[];
225
+ /** Only `"sandbox"`: the kernel may narrow, never turn auto mode on. */
226
+ mode?: "sandbox";
227
+ /** Who decided, for the device's local audit line. */
228
+ source: {
229
+ approvalId?: string;
230
+ accountId: string;
231
+ accountName: string;
232
+ via: "web" | "im";
233
+ };
234
+ }
235
+ /** The policy as the device wrote it. */
236
+ export interface DevicePolicyResult {
237
+ policy: DeviceLocalPolicySummary;
238
+ }
239
+ /** Asks what became of the `policy` op with this id. Read-only on the device. */
240
+ export interface DevicePolicyStatusArgs {
241
+ opId: string;
242
+ }
243
+ /**
244
+ * What the device logged of a `policy` op: its {@link DevicePolicyOpOutcome}, or `unknown` when
245
+ * the id is not in its log (never received, or dropped from the log since). `policy` is the
246
+ * device's summary now; `message` the refusal's.
247
+ */
248
+ export interface DevicePolicyStatus {
249
+ outcome: DevicePolicyOpOutcome | "unknown";
250
+ policy?: DeviceLocalPolicySummary;
251
+ message?: string;
252
+ }
253
+ /**
254
+ * Lists one directory (absolute `path`, {@link validateSandboxPathShape}): at most `limit` entries
255
+ * (at most {@link MAX_DEVICE_LIST_ENTRIES}), read in the mode `limits` gives. See
256
+ * `SandboxProvider.list` for the semantics.
257
+ */
258
+ export interface DeviceListArgs {
259
+ path: string;
260
+ limit: number;
261
+ limits: DeviceRequestCeiling;
262
+ }
263
+ /**
264
+ * One entry of a listed directory: `name` is never empty, `.` or `..` and holds no `/`. `isDir`
265
+ * follows symbolic links (stat semantics): a link to a directory is `true`, a dangling link `false`,
266
+ * and so is a link whose target the request's mode cannot reach.
267
+ */
268
+ export interface DeviceListEntry {
269
+ name: string;
270
+ isDir: boolean;
271
+ }
272
+ /**
273
+ * The directory's entries sorted by code unit, `truncated` when more than `limit` exist; null only
274
+ * when the path does not exist and the request's mode could reach it (like `stat` / `readFile`).
275
+ * A file, an unreadable directory, or a path the request's mode cannot reach is an error (the
276
+ * latter a `policy` refusal), never null.
277
+ */
278
+ export type DeviceListResult = {
279
+ entries: DeviceListEntry[];
280
+ truncated: boolean;
281
+ } | null;
282
+ /**
283
+ * Looks for project-like directories under `base` (absolute, {@link validateSandboxPathShape}),
284
+ * read in the mode `limits` gives. A `base` that does not exist answers `[]`; a `base` that is a
285
+ * file, unreadable, or outside the request's mode is an error. See `SandboxProvider.scan` for the
286
+ * traversal.
287
+ */
288
+ export interface DeviceScanArgs {
289
+ base: string;
290
+ limits: DeviceRequestCeiling;
291
+ }
292
+ /**
293
+ * `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH} levels below it that
294
+ * hold a `.git` entry or an `AGENTS.md` file, sorted by `path` in code-unit order and cut to the
295
+ * first {@link MAX_DEVICE_SCAN_RESULTS}. Never file contents. See `SandboxProvider.scan`.
296
+ */
297
+ export type DeviceScanResult = DeviceProjectCandidate[];
298
+ /** A frame that is not valid device protocol (or came from the wrong side). */
299
+ export declare class DeviceProtocolError extends Error {
300
+ constructor(message: string);
301
+ }
302
+ /**
303
+ * Whether `v` is a valid policy op id: non-empty, no `:`, at most
304
+ * {@link MAX_POLICY_OP_ID_LENGTH} characters.
305
+ */
306
+ export declare function isPolicyOpId(v: unknown): v is string;
307
+ /** Result type per op. */
308
+ export interface DeviceOpResults {
309
+ create: DeviceCreateResult;
310
+ exec: DeviceExecResult;
311
+ readFile: DeviceReadFileResult;
312
+ writeFile: DeviceWriteFileResult;
313
+ stat: DeviceStatResult;
314
+ killTagged: null;
315
+ killAll: null;
316
+ stop: null;
317
+ policy: DevicePolicyResult;
318
+ policyStatus: DevicePolicyStatus;
319
+ list: DeviceListResult;
320
+ scan: DeviceScanResult;
321
+ }
322
+ /** Validates the `result` of a successful `res` for `op`; throws {@link DeviceProtocolError}. */
323
+ export declare function parseOpResult<Op extends DeviceOp>(op: Op, result: unknown): DeviceOpResults[Op];
324
+ /**
325
+ * Parses one WebSocket text frame. `from` is the sender: a device may send `hello`, `res` and
326
+ * `policy`, the
327
+ * kernel `req` and `cancel`. Throws {@link DeviceProtocolError} on bad JSON, an unknown `type`,
328
+ * missing fields or a frame of the wrong direction.
329
+ */
330
+ export declare function parseDeviceFrame(raw: string, from: "device" | "kernel"): DeviceFrame;