@capybara-hq/plugin-sdk 0.1.0-rc.2 → 0.1.0-rc.20

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 (104) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +59 -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/context.md +15 -0
  9. package/agent-docs/extension-points/counter.md +15 -0
  10. package/agent-docs/extension-points/directory.md +15 -0
  11. package/agent-docs/extension-points/file-preview.md +15 -0
  12. package/agent-docs/extension-points/identity-source.md +15 -0
  13. package/agent-docs/extension-points/model-provider.md +15 -0
  14. package/agent-docs/extension-points/object-store.md +15 -0
  15. package/agent-docs/extension-points/sandbox.md +15 -0
  16. package/agent-docs/extension-points/secret-store.md +15 -0
  17. package/agent-docs/extension-points/web-fetch.md +15 -0
  18. package/agent-docs/extension-points/web-search.md +15 -0
  19. package/agent-docs/extensions.md +88 -0
  20. package/agent-docs/plugin-format.md +100 -0
  21. package/agent-docs/setup.md +46 -0
  22. package/agent-docs/skills.md +44 -0
  23. package/agent-docs/tool-naming.md +21 -0
  24. package/dist/agent-template.d.ts +96 -2
  25. package/dist/agent-template.js +381 -3
  26. package/dist/bootstrap.d.ts +15 -1
  27. package/dist/bootstrap.js +17 -1
  28. package/dist/cards.d.ts +39 -5
  29. package/dist/cards.js +70 -11
  30. package/dist/channel.d.ts +20 -1
  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 +24 -1
  36. package/dist/config-ui.js +89 -11
  37. package/dist/connector-auth.d.ts +2 -0
  38. package/dist/connector-auth.js +15 -0
  39. package/dist/context.d.ts +40 -0
  40. package/dist/context.js +2 -0
  41. package/dist/ctx.d.ts +86 -4
  42. package/dist/define-extension.d.ts +5 -1
  43. package/dist/define-extension.js +1 -0
  44. package/dist/dev-hosts.d.ts +6 -0
  45. package/dist/dev-hosts.js +48 -0
  46. package/dist/device-protocol.d.ts +260 -0
  47. package/dist/device-protocol.js +496 -0
  48. package/dist/directory.d.ts +11 -2
  49. package/dist/extension-point.d.ts +6 -0
  50. package/dist/extension-point.js +19 -14
  51. package/dist/file-preview.d.ts +9 -1
  52. package/dist/hooks.d.ts +111 -15
  53. package/dist/hooks.js +5 -0
  54. package/dist/index.d.ts +18 -1
  55. package/dist/index.js +18 -1
  56. package/dist/marketplace.d.ts +55 -2
  57. package/dist/marketplace.js +73 -3
  58. package/dist/model.d.ts +60 -2
  59. package/dist/model.js +22 -0
  60. package/dist/org-access.d.ts +27 -0
  61. package/dist/org-access.js +35 -0
  62. package/dist/permissions.d.ts +33 -8
  63. package/dist/permissions.js +89 -22
  64. package/dist/plugin-manifest.d.ts +60 -7
  65. package/dist/plugin-manifest.js +178 -7
  66. package/dist/sandbox.d.ts +239 -62
  67. package/dist/sandbox.js +99 -14
  68. package/dist/setup-check.d.ts +115 -0
  69. package/dist/setup-check.js +142 -0
  70. package/dist/setup-guide-parse.d.ts +121 -0
  71. package/dist/setup-guide-parse.js +350 -0
  72. package/dist/setup-guide-render.d.ts +45 -0
  73. package/dist/setup-guide-render.js +351 -0
  74. package/dist/setup-guide.d.ts +94 -0
  75. package/dist/setup-guide.js +336 -0
  76. package/dist/skill-invocation.d.ts +9 -5
  77. package/dist/skill-invocation.js +18 -8
  78. package/dist/skill.d.ts +23 -3
  79. package/dist/skill.js +31 -6
  80. package/dist/theme-assets.d.ts +39 -0
  81. package/dist/theme-assets.js +449 -0
  82. package/dist/theme-readability.d.ts +37 -0
  83. package/dist/theme-readability.js +145 -0
  84. package/dist/theme-tokens.generated.d.ts +275 -0
  85. package/dist/theme-tokens.generated.js +172 -0
  86. package/dist/theme.d.ts +152 -0
  87. package/dist/theme.js +392 -0
  88. package/dist/tool.d.ts +26 -3
  89. package/dist/tool.js +8 -0
  90. package/dist/ui-parts.d.ts +23 -0
  91. package/dist/ui-parts.js +337 -0
  92. package/dist/ui-resolve.d.ts +40 -0
  93. package/dist/ui-resolve.js +54 -0
  94. package/dist/ui-slots.d.ts +55 -0
  95. package/dist/ui-slots.js +247 -0
  96. package/dist/ui.d.ts +143 -37
  97. package/dist/ui.js +65 -5
  98. package/dist/web.d.ts +30 -5
  99. package/package.json +10 -2
  100. package/schemas/bootstrap.v1.schema.json +6 -0
  101. package/schemas/connector-template.v1.schema.json +3 -0
  102. package/schemas/marketplace.v1.schema.json +50 -0
  103. package/schemas/plugin.v1.schema.json +144 -7
  104. package/schemas/theme.v1.schema.json +225 -0
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The dev hosts preset: common package registries, source hosts and tool downloads the `dev`
3
+ * sandbox tier adds to the org's allowlist. The kernel's `sandbox.limits.devHosts` defaults to it;
4
+ * the device and the sandbox plugins read the same list. Every entry passes `validateAllowHost`.
5
+ */
6
+ export const DEV_HOSTS = Object.freeze([
7
+ // npm / Node
8
+ "registry.npmjs.org",
9
+ "registry.yarnpkg.com",
10
+ "repo.yarnpkg.com",
11
+ "nodejs.org",
12
+ // Python
13
+ "pypi.org",
14
+ "files.pythonhosted.org",
15
+ // GitHub
16
+ "github.com",
17
+ "api.github.com",
18
+ "codeload.github.com",
19
+ "raw.githubusercontent.com",
20
+ "objects.githubusercontent.com",
21
+ "release-assets.githubusercontent.com",
22
+ "ghcr.io",
23
+ "pkg-containers.githubusercontent.com",
24
+ // Rust
25
+ "crates.io",
26
+ "index.crates.io",
27
+ "static.crates.io",
28
+ "static.rust-lang.org",
29
+ // Go
30
+ "proxy.golang.org",
31
+ "sum.golang.org",
32
+ // JVM
33
+ "repo.maven.apache.org",
34
+ "repo1.maven.org",
35
+ "plugins.gradle.org",
36
+ "services.gradle.org",
37
+ "downloads.gradle.org",
38
+ // Docker Hub (image metadata and layers for tools such as crane)
39
+ "registry-1.docker.io",
40
+ "auth.docker.io",
41
+ "production.cloudflare.docker.com",
42
+ // Playwright browsers (`npx playwright install`, checked against playwright-core 1.64): Firefox,
43
+ // WebKit and ffmpeg come from the Playwright CDN and its Microsoft mirror; Chromium is Chrome
44
+ // for Testing, which cdn.playwright.dev redirects to storage.googleapis.com
45
+ "cdn.playwright.dev",
46
+ "playwright.download.prss.microsoft.com",
47
+ "storage.googleapis.com",
48
+ ]);
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Device protocol v1: 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, type SandboxTier } from "./sandbox.js";
6
+ /** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
7
+ export declare const DEVICE_PROTOCOL_VERSION = 1;
8
+ /** The operations the kernel asks a device to run. */
9
+ export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop" | "policy" | "policyStatus";
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`; `tiers` means the device applies `limits.tier` / `defaultTier` / `devHosts`
15
+ * (without it the device behaves as `strict`).
16
+ */
17
+ export type DeviceFeature = "networkReport" | "policyOp" | "policyOpId" | "tiers";
18
+ /**
19
+ * Whether the device accepts widening its local policy from the kernel (the `policy` op's `add`
20
+ * and a higher `tier`, run and task grants): `owner` (default, decided by the device owner in a
21
+ * signed-in session) or `off` (only the machine's user widens it, with the CLI).
22
+ */
23
+ export type DeviceRemoteGrants = "owner" | "off";
24
+ /** What the kernel knows of a device's local policy (from the hello or a `policy` op). */
25
+ export interface DeviceLocalPolicySummary {
26
+ /** The tier the device owner chose; absent = follows the org's default. */
27
+ tier?: SandboxTier;
28
+ /** The tier the device ran its last command at (its choice cut to the org's ceiling). */
29
+ effectiveTier: SandboxTier;
30
+ /** `none` = the device runs commands without a sandbox (only with tier `open`, OS mode). */
31
+ isolation: "sandbox" | "none";
32
+ /** Whether sandboxed commands may bind and reach localhost on this machine. */
33
+ localhost: "on" | "off-proxy-detected" | "off";
34
+ /** Unix socket access: within the roots, every socket masked, or none. */
35
+ unixSockets: "roots" | "all-masked" | "off";
36
+ allowedDomains: string[];
37
+ remoteGrants: DeviceRemoteGrants;
38
+ }
39
+ /**
40
+ * The first line of the kernel's background task launch command (`Bash` `run_in_background`), a
41
+ * shell comment. A device kills what a foreground exec leaves running once the exec ends; an exec
42
+ * whose command starts with this line detaches a task on purpose, and its processes are left alone.
43
+ */
44
+ export declare const BACKGROUND_LAUNCH_LINE = "# capybara: background task launch";
45
+ /** Whether an exec's command is a background task launch ({@link BACKGROUND_LAUNCH_LINE}). */
46
+ export declare function isBackgroundLaunch(command: string): boolean;
47
+ /** The most blocked hosts an exec result reports; the parser cuts longer lists. */
48
+ export declare const MAX_NETWORK_BLOCKED_HOSTS = 20;
49
+ /** The longest `opId` a `policy` / `policyStatus` op may carry. */
50
+ export declare const MAX_POLICY_OP_ID_LENGTH = 128;
51
+ /** The most entries a hello's `recentOps` carries; the parser keeps the newest. */
52
+ export declare const MAX_RECENT_POLICY_OPS = 100;
53
+ /**
54
+ * What a device recorded of a `policy` op: `started` (written before the change, so an op the
55
+ * device was stopped in the middle of stays `started`), then `applied` or `refused`.
56
+ */
57
+ export type DevicePolicyOpOutcome = "applied" | "refused" | "started";
58
+ /** One entry of a hello's `recentOps`. */
59
+ export interface DevicePolicyOpReport {
60
+ opId: string;
61
+ outcome: DevicePolicyOpOutcome;
62
+ }
63
+ /** First frame from the device after the WebSocket opens. */
64
+ export interface DeviceHello {
65
+ type: "hello";
66
+ protocol: number;
67
+ programVersion: string;
68
+ os: "darwin" | "linux";
69
+ arch: string;
70
+ mode: "os" | "docker";
71
+ roots: SandboxRoots;
72
+ sessionIsolation: boolean;
73
+ /** Optional capabilities (absent on older devices; unknown entries are dropped by the parser). */
74
+ features?: DeviceFeature[];
75
+ /** The device's local policy at connect time (absent on older devices). */
76
+ policy?: DeviceLocalPolicySummary;
77
+ /**
78
+ * The outcomes of the latest `policy` ops by op id, oldest first, at most
79
+ * {@link MAX_RECENT_POLICY_OPS} (devices with `policyOpId`; malformed entries are dropped by
80
+ * the parser).
81
+ */
82
+ recentOps?: DevicePolicyOpReport[];
83
+ }
84
+ /** Error kinds a device reports for a failed request. */
85
+ export type DeviceErrorKind = "gone" | "fs_gone" | "policy" | "error";
86
+ /** The device's answer to a {@link KernelReq}. */
87
+ export type DeviceRes = {
88
+ type: "res";
89
+ id: string;
90
+ ok: true;
91
+ result: unknown;
92
+ } | {
93
+ type: "res";
94
+ id: string;
95
+ ok: false;
96
+ error: {
97
+ kind: DeviceErrorKind;
98
+ message: string;
99
+ };
100
+ };
101
+ /** A request from the kernel. */
102
+ export interface KernelReq {
103
+ type: "req";
104
+ id: string;
105
+ op: DeviceOp;
106
+ args: unknown;
107
+ deadlineMs: number;
108
+ }
109
+ /** The kernel gives up on a request (abort or deadline). */
110
+ export interface KernelCancel {
111
+ type: "cancel";
112
+ id: string;
113
+ }
114
+ /**
115
+ * The device's local policy changed while connected (its file was edited on the machine, the
116
+ * localhost proxy guard flipped, a new tier ceiling): the summary as it is now, sent only when it
117
+ * differs from the last one sent on this connection. `policy` is absent when the frame's summary
118
+ * was unreadable; the kernel then keeps only its isolation, from the raw frame, as for the hello.
119
+ */
120
+ export interface DevicePolicyChanged {
121
+ type: "policy";
122
+ policy?: DeviceLocalPolicySummary;
123
+ }
124
+ export type DeviceFrame = DeviceHello | DeviceRes | DevicePolicyChanged | KernelReq | KernelCancel;
125
+ export interface DeviceExecArgs {
126
+ command: string;
127
+ cwd?: string;
128
+ env?: Record<string, string>;
129
+ timeoutMs: number;
130
+ maxOutputBytes: number;
131
+ tag: string;
132
+ actor: SandboxActor;
133
+ limits: SandboxLimits;
134
+ /**
135
+ * Hosts the kernel allows for this command beyond the local policy (a run's 「这次允许」 or a
136
+ * scheduled task's grants). A device applies them only when its `remoteGrants` is `owner` and
137
+ * only within `limits`; a device without the feature ignores the field.
138
+ */
139
+ grants?: DeviceExecGrants;
140
+ }
141
+ /** Extra hosts for one exec and where they come from (logged by the device with the command). */
142
+ export interface DeviceExecGrants {
143
+ hosts: string[];
144
+ source: {
145
+ kind: "run" | "task";
146
+ id: string;
147
+ accountId: string;
148
+ };
149
+ }
150
+ export type DeviceExecResult = ExecResult;
151
+ export interface DeviceReadFileArgs {
152
+ path: string;
153
+ maxBytes: number;
154
+ }
155
+ export type DeviceReadFileResult = {
156
+ dataB64: string;
157
+ truncated: boolean;
158
+ } | null;
159
+ export interface DeviceWriteFileArgs {
160
+ path: string;
161
+ dataB64: string;
162
+ }
163
+ export type DeviceWriteFileResult = null;
164
+ export interface DeviceStatArgs {
165
+ path: string;
166
+ }
167
+ export type DeviceStatResult = {
168
+ size: number;
169
+ isDir: boolean;
170
+ } | null;
171
+ export interface DeviceKillTaggedArgs {
172
+ tags: string[];
173
+ }
174
+ export type DeviceKillAllArgs = Record<string, never>;
175
+ export interface DeviceCreateArgs {
176
+ limits: SandboxLimits;
177
+ }
178
+ export interface DeviceCreateResult {
179
+ roots: SandboxRoots;
180
+ }
181
+ export interface DeviceStopArgs {
182
+ reason: "revoked" | "deleted";
183
+ }
184
+ /**
185
+ * Edits the device's local policy. The device refuses widening (`add`, a higher `tier`) unless
186
+ * its `remoteGrants` is `owner`; narrowing is always accepted. `isolation` may only turn the
187
+ * sandbox back on: turning it off is decided on the machine.
188
+ */
189
+ export interface DevicePolicyArgs {
190
+ /**
191
+ * The kernel's id of this change (non-empty, no `:`, at most {@link MAX_POLICY_OP_ID_LENGTH}
192
+ * characters): the device logs the op's outcome under it, for `policyStatus` and the hello's
193
+ * `recentOps`.
194
+ */
195
+ opId: string;
196
+ /** Hosts to add to `allowedDomains`. */
197
+ add?: string[];
198
+ /** Hosts to remove from `allowedDomains`. */
199
+ remove?: string[];
200
+ /** The device's tier; null = follow the org's default. */
201
+ tier?: SandboxTier | null;
202
+ /** Only `sandbox`: the kernel never turns the sandbox off. */
203
+ isolation?: "sandbox";
204
+ /** Who decided, for the device's local audit line. */
205
+ source: {
206
+ approvalId?: string;
207
+ accountId: string;
208
+ accountName: string;
209
+ via: "web" | "im";
210
+ };
211
+ }
212
+ /** The policy as the device wrote it. */
213
+ export interface DevicePolicyResult {
214
+ policy: DeviceLocalPolicySummary;
215
+ }
216
+ /** Asks what became of the `policy` op with this id. Read-only on the device. */
217
+ export interface DevicePolicyStatusArgs {
218
+ opId: string;
219
+ }
220
+ /**
221
+ * What the device logged of a `policy` op: its {@link DevicePolicyOpOutcome}, or `unknown` when
222
+ * the id is not in its log (never received, or dropped from the log since). `policy` is the
223
+ * device's summary now; `message` the refusal's.
224
+ */
225
+ export interface DevicePolicyStatus {
226
+ outcome: DevicePolicyOpOutcome | "unknown";
227
+ policy?: DeviceLocalPolicySummary;
228
+ message?: string;
229
+ }
230
+ /** A frame that is not valid protocol v1 (or came from the wrong side). */
231
+ export declare class DeviceProtocolError extends Error {
232
+ constructor(message: string);
233
+ }
234
+ /**
235
+ * Whether `v` is a valid policy op id: non-empty, no `:`, at most
236
+ * {@link MAX_POLICY_OP_ID_LENGTH} characters.
237
+ */
238
+ export declare function isPolicyOpId(v: unknown): v is string;
239
+ /** Result type per op. */
240
+ export interface DeviceOpResults {
241
+ create: DeviceCreateResult;
242
+ exec: DeviceExecResult;
243
+ readFile: DeviceReadFileResult;
244
+ writeFile: DeviceWriteFileResult;
245
+ stat: DeviceStatResult;
246
+ killTagged: null;
247
+ killAll: null;
248
+ stop: null;
249
+ policy: DevicePolicyResult;
250
+ policyStatus: DevicePolicyStatus;
251
+ }
252
+ /** Validates the `result` of a successful `res` for `op`; throws {@link DeviceProtocolError}. */
253
+ export declare function parseOpResult<Op extends DeviceOp>(op: Op, result: unknown): DeviceOpResults[Op];
254
+ /**
255
+ * Parses one WebSocket text frame. `from` is the sender: a device may send `hello`, `res` and
256
+ * `policy`, the
257
+ * kernel `req` and `cancel`. Throws {@link DeviceProtocolError} on bad JSON, an unknown `type`,
258
+ * missing fields or a frame of the wrong direction.
259
+ */
260
+ export declare function parseDeviceFrame(raw: string, from: "device" | "kernel"): DeviceFrame;