@capybara-hq/plugin-sdk 0.1.0-rc.4 → 0.1.0-rc.41
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.
- package/agent-docs/agent-templates.md +15 -3
- package/agent-docs/concepts.md +13 -3
- package/agent-docs/connector-templates.md +2 -1
- package/agent-docs/extension-points/channel.md +2 -2
- package/agent-docs/extension-points/config-source.md +1 -1
- package/agent-docs/extension-points/connector.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/counter.md +1 -1
- package/agent-docs/extension-points/directory.md +1 -1
- package/agent-docs/extension-points/file-preview.md +3 -1
- package/agent-docs/extension-points/identity-source.md +1 -1
- package/agent-docs/extension-points/model-provider.md +4 -2
- package/agent-docs/extension-points/object-store.md +3 -1
- package/agent-docs/extension-points/sandbox.md +3 -3
- package/agent-docs/extension-points/secret-store.md +1 -1
- package/agent-docs/extension-points/web-fetch.md +1 -1
- package/agent-docs/extension-points/web-search.md +1 -1
- package/agent-docs/extensions.md +29 -4
- package/agent-docs/plugin-format.md +43 -3
- package/agent-docs/setup.md +46 -0
- package/agent-docs/skills.md +1 -1
- package/agent-docs/tool-naming.md +1 -1
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/bootstrap.d.ts +15 -1
- package/dist/bootstrap.js +17 -1
- package/dist/cards.d.ts +67 -13
- package/dist/cards.js +91 -21
- package/dist/channel.d.ts +148 -48
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/connector-auth.d.ts +7 -2
- package/dist/connector-auth.js +29 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +120 -29
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +11 -4
- package/dist/device-denied-paths.d.ts +14 -0
- package/dist/device-denied-paths.js +41 -0
- package/dist/device-protocol.d.ts +481 -0
- package/dist/device-protocol.js +1113 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +5 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +44 -0
- package/dist/git-hosts.js +81 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +62 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +22 -9
- package/dist/index.d.ts +26 -1
- package/dist/index.js +26 -1
- package/dist/marketplace.d.ts +26 -0
- package/dist/marketplace.js +43 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +206 -71
- package/dist/model.js +152 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +41 -21
- package/dist/permissions.js +101 -42
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +169 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2318 -0
- package/dist/sandbox-native-runtime-source.d.ts +8 -0
- package/dist/sandbox-native-runtime-source.js +465 -0
- package/dist/sandbox-operation.d.ts +284 -0
- package/dist/sandbox-operation.js +262 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/sandbox.d.ts +190 -16
- package/dist/sandbox.js +89 -14
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +115 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +350 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +94 -0
- package/dist/setup-guide.js +336 -0
- package/dist/shell-capabilities.d.ts +88 -0
- package/dist/shell-capabilities.js +13 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +16 -0
- package/dist/skill-invocation.d.ts +4 -3
- package/dist/skill-invocation.js +5 -4
- package/dist/skill.d.ts +34 -21
- package/dist/skill.js +48 -31
- package/dist/storage.d.ts +52 -25
- package/dist/theme-assets.d.ts +39 -0
- package/dist/theme-assets.js +449 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +287 -0
- package/dist/theme-tokens.generated.js +176 -0
- package/dist/theme.d.ts +152 -0
- package/dist/theme.js +392 -0
- package/dist/tool.d.ts +69 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +348 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +212 -76
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +8 -1
- package/schemas/bootstrap.v1.schema.json +6 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +115 -3
- package/schemas/theme.v1.schema.json +225 -0
package/dist/define-extension.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import semver from "semver";
|
|
2
2
|
import { EXTENSION_POINTS, parseExtensionPoint, } from "./extension-point.js";
|
|
3
3
|
import { validatePermissions, validateUiContributions, } from "./permissions.js";
|
|
4
|
-
/**
|
|
4
|
+
/** The plugin manifest is invalid. */
|
|
5
5
|
export class ExtensionManifestError extends Error {
|
|
6
6
|
constructor(plugin, message) {
|
|
7
7
|
super(`extension ${plugin}: ${message}`);
|
|
8
8
|
this.name = "ExtensionManifestError";
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/** Plugin name rule (manifest `name`; a connector template's `plugin` is validated by it too). */
|
|
12
12
|
export const EXTENSION_NAME_RE = /^[a-z][a-z0-9-]{1,40}$/;
|
|
13
13
|
const NAME_RE = EXTENSION_NAME_RE;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Reserved plugin name: the kernel uses `kernel` as its own secrets namespace, so a plugin cannot
|
|
16
|
+
* take it.
|
|
17
|
+
*/
|
|
15
18
|
const RESERVED_NAMES = new Set(["kernel"]);
|
|
16
19
|
function checkRefs(label, refs, fail, forbidBrokered = false) {
|
|
17
20
|
for (const ref of refs) {
|
|
@@ -30,7 +33,10 @@ function checkRefs(label, refs, fail, forbidBrokered = false) {
|
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when
|
|
38
|
+
* invalid.
|
|
39
|
+
*/
|
|
34
40
|
export function defineExtension(m) {
|
|
35
41
|
const plugin = typeof m?.name === "string" && m.name !== "" ? m.name : "<unnamed>";
|
|
36
42
|
const fail = (msg) => {
|
|
@@ -78,6 +84,7 @@ export function defineExtension(m) {
|
|
|
78
84
|
if (errs.length > 0)
|
|
79
85
|
fail(`invalid permissions: ${errs.join("; ")}`);
|
|
80
86
|
}
|
|
87
|
+
// structural ui problems only; slot resolution never fails the extension (UI slots spec §3.2)
|
|
81
88
|
const uiErrs = validateUiContributions(m.ui, m.permissions);
|
|
82
89
|
if (uiErrs.length > 0)
|
|
83
90
|
fail(`invalid ui: ${uiErrs.join("; ")}`);
|
|
@@ -0,0 +1,14 @@
|
|
|
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, and the
|
|
5
|
+
* browser profile directories. One source for the device, which denies them (and its own state
|
|
6
|
+
* directory), and the kernel, which never proposes an approval for a path under one. Full access
|
|
7
|
+
* and auto mode run as the owner and do not apply them: the command review does.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEVICE_DENIED_SECRET_PATHS: readonly string[];
|
|
10
|
+
/**
|
|
11
|
+
* The device program's default state directory (`$XDG_CONFIG_HOME/capybara-device` when that is
|
|
12
|
+
* set), relative to `~`: denied to restricted work like the secret paths.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEVICE_DEFAULT_STATE_PATH = "~/.config/capybara-device";
|
|
@@ -0,0 +1,41 @@
|
|
|
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, and the
|
|
5
|
+
* browser profile directories. One source for the device, which denies them (and its own state
|
|
6
|
+
* directory), and the kernel, which never proposes an approval for a path under one. Full access
|
|
7
|
+
* and auto mode run as the owner and do not apply them: the command review does.
|
|
8
|
+
*/
|
|
9
|
+
export const DEVICE_DENIED_SECRET_PATHS = Object.freeze([
|
|
10
|
+
"~/.ssh",
|
|
11
|
+
"~/.aws",
|
|
12
|
+
"~/.config/gcloud",
|
|
13
|
+
"~/.azure",
|
|
14
|
+
"~/.kube",
|
|
15
|
+
"~/.docker/config.json",
|
|
16
|
+
"~/.netrc",
|
|
17
|
+
"~/.gnupg",
|
|
18
|
+
"~/Library/Application Support/Google/Chrome",
|
|
19
|
+
"~/Library/Application Support/Firefox",
|
|
20
|
+
"~/.mozilla",
|
|
21
|
+
"~/.config/google-chrome",
|
|
22
|
+
"~/.config/chromium",
|
|
23
|
+
// Ruling R19: more credential stores and browser data.
|
|
24
|
+
"~/.config/gh",
|
|
25
|
+
"~/.git-credentials",
|
|
26
|
+
"~/.npmrc",
|
|
27
|
+
"~/.pypirc",
|
|
28
|
+
"~/Library/Keychains",
|
|
29
|
+
"~/Library/Cookies",
|
|
30
|
+
"~/Library/Safari",
|
|
31
|
+
"~/Library/Application Support/BraveSoftware",
|
|
32
|
+
"~/Library/Application Support/Microsoft Edge",
|
|
33
|
+
"~/Library/Application Support/Arc",
|
|
34
|
+
"~/.config/BraveSoftware",
|
|
35
|
+
"~/.config/microsoft-edge",
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* The device program's default state directory (`$XDG_CONFIG_HOME/capybara-device` when that is
|
|
39
|
+
* set), relative to `~`: denied to restricted work like the secret paths.
|
|
40
|
+
*/
|
|
41
|
+
export const DEVICE_DEFAULT_STATE_PATH = "~/.config/capybara-device";
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The device protocol: 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
|
+
* Protocol 4 (the scope-bearing operations, `parseDeviceFrame`) is defined in the second half of
|
|
6
|
+
* this file. Protocol 2's frames keep a `Legacy` prefix where a newer name replaced them
|
|
7
|
+
* (`LegacyDeviceHello`, `parseLegacyDeviceFrame`, ...); protocol 4 reuses their value guards, and
|
|
8
|
+
* they go with the legacy device surface.
|
|
9
|
+
*/
|
|
10
|
+
import { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots } from "./sandbox.js";
|
|
11
|
+
import { type SandboxPermissionSupport } from "./sandbox-operation.js";
|
|
12
|
+
/** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
|
|
13
|
+
export declare const DEVICE_PROTOCOL_VERSION = 4;
|
|
14
|
+
/**
|
|
15
|
+
* Protocol 3's version, which a deployment speaking {@link DEVICE_PROTOCOL_VERSION} refuses (426
|
|
16
|
+
* on the header, a protocol close on the hello): its owner report and runtime support describe the
|
|
17
|
+
* removed Full access ceiling, so a protocol 3 program must be updated.
|
|
18
|
+
*/
|
|
19
|
+
export declare const LEGACY_DEVICE_PROTOCOL_VERSION = 3;
|
|
20
|
+
/** The operations the kernel asks a device to run. */
|
|
21
|
+
export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop" | "policy" | "policyStatus" | "list" | "scan";
|
|
22
|
+
/**
|
|
23
|
+
* Optional capabilities a device announces in its hello. `policyOp`: the device takes the `policy`
|
|
24
|
+
* op; `policyOpId`: it also logs each `policy` op's outcome by its `opId`, answers `policyStatus`
|
|
25
|
+
* and reports recent outcomes in its hello (`recentOps`); `networkReport` means exec results may
|
|
26
|
+
* carry `network`; `projects` means the device serves `list` and
|
|
27
|
+
* `scan` (the kernel keeps a device's projects itself and asks the device only what it can read).
|
|
28
|
+
* The kernel gates each op on its feature, as it gates `policy` on `policyOp` / `policyOpId`: it
|
|
29
|
+
* never sends `list` or `scan` to a device that did not announce `projects`.
|
|
30
|
+
*/
|
|
31
|
+
export type DeviceFeature = "networkReport" | "policyOp" | "policyOpId" | "projects";
|
|
32
|
+
/** The most entries a `list` op may ask for and its result may carry. */
|
|
33
|
+
export declare const MAX_DEVICE_LIST_ENTRIES = 1000;
|
|
34
|
+
/**
|
|
35
|
+
* What a device knows of its local policy and reports (in the hello or a `policy` op). The owner
|
|
36
|
+
* ceiling travels separately, in the owner report ({@link DeviceOwnerCeiling}).
|
|
37
|
+
*/
|
|
38
|
+
export interface DeviceLocalPolicySummary {
|
|
39
|
+
/** The device's sandbox allowlist (the owner's `allowedDomains`). */
|
|
40
|
+
allowedDomains: string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A directory a `scan` found that looks like a project (it holds `.git` or `AGENTS.md`): a
|
|
44
|
+
* suggestion, not a project. `path` is absolute ({@link validateSandboxPathShape});
|
|
45
|
+
* `suggestedName` is a guess from its basename ({@link isDeviceProjectName}) the owner may change.
|
|
46
|
+
*/
|
|
47
|
+
export interface DeviceProjectCandidate {
|
|
48
|
+
path: string;
|
|
49
|
+
suggestedName: string;
|
|
50
|
+
}
|
|
51
|
+
/** The most blocked hosts an exec result reports; the parser cuts longer lists. */
|
|
52
|
+
export declare const MAX_NETWORK_BLOCKED_HOSTS = 20;
|
|
53
|
+
/**
|
|
54
|
+
* Why a `policy` op naming hosts to `add` is refused: the deployment may only narrow a local
|
|
55
|
+
* device's sandbox; its owner widens it on the machine.
|
|
56
|
+
*/
|
|
57
|
+
export declare const POLICY_ADD_REFUSED = "The deployment may not add hosts to a device's sandbox allowlist: widening happens only on the machine (capybara-device policy add allowedDomains <host>)";
|
|
58
|
+
/** The longest `opId` a `policy` / `policyStatus` op may carry. */
|
|
59
|
+
export declare const MAX_POLICY_OP_ID_LENGTH = 128;
|
|
60
|
+
/** The most entries a hello's `recentOps` carries; the parser keeps the newest. */
|
|
61
|
+
export declare const MAX_RECENT_POLICY_OPS = 100;
|
|
62
|
+
/**
|
|
63
|
+
* What a device recorded of a `policy` op: `started` (written before the change, so an op the
|
|
64
|
+
* device was stopped in the middle of stays `started`), then `applied` or `refused`.
|
|
65
|
+
*/
|
|
66
|
+
export type DevicePolicyOpOutcome = "applied" | "refused" | "started";
|
|
67
|
+
/** One entry of a hello's `recentOps`. */
|
|
68
|
+
export interface DevicePolicyOpReport {
|
|
69
|
+
opId: string;
|
|
70
|
+
outcome: DevicePolicyOpOutcome;
|
|
71
|
+
}
|
|
72
|
+
/** First frame from the device after the WebSocket opens. */
|
|
73
|
+
export interface LegacyDeviceHello {
|
|
74
|
+
type: "hello";
|
|
75
|
+
protocol: number;
|
|
76
|
+
programVersion: string;
|
|
77
|
+
os: "darwin" | "linux";
|
|
78
|
+
arch: string;
|
|
79
|
+
mode: "os" | "docker";
|
|
80
|
+
roots: SandboxRoots;
|
|
81
|
+
sessionIsolation: boolean;
|
|
82
|
+
/** Optional capabilities (absent on older devices; unknown entries are dropped by the parser). */
|
|
83
|
+
features?: DeviceFeature[];
|
|
84
|
+
/** The device's local policy at connect time (absent on older devices). */
|
|
85
|
+
policy?: DeviceLocalPolicySummary;
|
|
86
|
+
/**
|
|
87
|
+
* The outcomes of the latest `policy` ops by op id, oldest first, at most
|
|
88
|
+
* {@link MAX_RECENT_POLICY_OPS} (devices with `policyOpId`; malformed entries are dropped by
|
|
89
|
+
* the parser).
|
|
90
|
+
*/
|
|
91
|
+
recentOps?: DevicePolicyOpReport[];
|
|
92
|
+
/**
|
|
93
|
+
* The owner's home directory, an absolute path (a local device; the base of an auto-mode
|
|
94
|
+
* project's relative path). A malformed value is dropped by the parser.
|
|
95
|
+
*/
|
|
96
|
+
home?: string;
|
|
97
|
+
/**
|
|
98
|
+
* The identity of the host's current OS boot (Linux `/proc/sys/kernel/random/boot_id`; macOS
|
|
99
|
+
* `kern.bootsessionuuid`): a value that differs from an earlier one of the
|
|
100
|
+
* same machine proves the host restarted since, so no process of that earlier boot can exist.
|
|
101
|
+
* A malformed value is dropped by the parser.
|
|
102
|
+
*/
|
|
103
|
+
bootId?: string;
|
|
104
|
+
}
|
|
105
|
+
/** A hello's `bootId`: 1 to 128 characters of letters, digits, `.`, `_`, `:` and `-`. */
|
|
106
|
+
export declare const DEVICE_BOOT_ID_RE: RegExp;
|
|
107
|
+
/** Whether `v` is a well-formed {@link LegacyDeviceHello.bootId}. */
|
|
108
|
+
export declare function isDeviceBootId(v: unknown): v is string;
|
|
109
|
+
/** Error kinds a device reports for a failed request. */
|
|
110
|
+
export type DeviceErrorKind = "gone" | "fs_gone" | "policy" | "error";
|
|
111
|
+
/** The device's answer to a {@link KernelReq}. */
|
|
112
|
+
export type DeviceRes = {
|
|
113
|
+
type: "res";
|
|
114
|
+
id: string;
|
|
115
|
+
ok: true;
|
|
116
|
+
result: unknown;
|
|
117
|
+
} | {
|
|
118
|
+
type: "res";
|
|
119
|
+
id: string;
|
|
120
|
+
ok: false;
|
|
121
|
+
error: {
|
|
122
|
+
kind: DeviceErrorKind;
|
|
123
|
+
message: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
/** A request from the kernel. */
|
|
127
|
+
export interface KernelReq {
|
|
128
|
+
type: "req";
|
|
129
|
+
id: string;
|
|
130
|
+
op: DeviceOp;
|
|
131
|
+
args: unknown;
|
|
132
|
+
deadlineMs: number;
|
|
133
|
+
}
|
|
134
|
+
/** The kernel gives up on a request (abort or deadline). */
|
|
135
|
+
export interface KernelCancel {
|
|
136
|
+
type: "cancel";
|
|
137
|
+
id: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The device's local policy changed while connected (its file was edited on the machine, the owner
|
|
141
|
+
* switched mode): the summary as it is now, sent only when it differs from the last one sent on
|
|
142
|
+
* this connection. `policy` is absent when the frame's summary was unreadable; the kernel then
|
|
143
|
+
* learns the policy later, as for the hello.
|
|
144
|
+
*/
|
|
145
|
+
export interface LegacyDevicePolicyChanged {
|
|
146
|
+
type: "policy";
|
|
147
|
+
policy?: DeviceLocalPolicySummary;
|
|
148
|
+
}
|
|
149
|
+
export type LegacyDeviceFrame = LegacyDeviceHello | DeviceRes | LegacyDevicePolicyChanged | KernelReq | KernelCancel;
|
|
150
|
+
export interface DeviceExecArgs {
|
|
151
|
+
command: string;
|
|
152
|
+
cwd?: string;
|
|
153
|
+
env?: Record<string, string>;
|
|
154
|
+
timeoutMs: number;
|
|
155
|
+
maxOutputBytes: number;
|
|
156
|
+
tag: string;
|
|
157
|
+
actor: SandboxActor;
|
|
158
|
+
limits: SandboxLimits;
|
|
159
|
+
/**
|
|
160
|
+
* Hosts the kernel allows for this command beyond the local policy (a run's "Allow this time" or
|
|
161
|
+
* a
|
|
162
|
+
* scheduled task's grants). A device applies them only in sandbox mode, within `limits`; a
|
|
163
|
+
* device without the feature ignores the field.
|
|
164
|
+
*/
|
|
165
|
+
grants?: DeviceExecGrants;
|
|
166
|
+
}
|
|
167
|
+
/** Extra hosts for one exec and where they come from (logged by the device with the command). */
|
|
168
|
+
export interface DeviceExecGrants {
|
|
169
|
+
hosts: string[];
|
|
170
|
+
source: {
|
|
171
|
+
kind: "run" | "task";
|
|
172
|
+
id: string;
|
|
173
|
+
accountId: string;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
export type DeviceExecResult = ExecResult;
|
|
177
|
+
export interface DeviceReadFileArgs {
|
|
178
|
+
path: string;
|
|
179
|
+
maxBytes: number;
|
|
180
|
+
}
|
|
181
|
+
export type DeviceReadFileResult = {
|
|
182
|
+
dataB64: string;
|
|
183
|
+
truncated: boolean;
|
|
184
|
+
} | null;
|
|
185
|
+
export interface DeviceWriteFileArgs {
|
|
186
|
+
path: string;
|
|
187
|
+
dataB64: string;
|
|
188
|
+
}
|
|
189
|
+
export type DeviceWriteFileResult = null;
|
|
190
|
+
export interface DeviceStatArgs {
|
|
191
|
+
path: string;
|
|
192
|
+
}
|
|
193
|
+
export type DeviceStatResult = {
|
|
194
|
+
size: number;
|
|
195
|
+
isDir: boolean;
|
|
196
|
+
} | null;
|
|
197
|
+
export interface DeviceKillTaggedArgs {
|
|
198
|
+
tags: string[];
|
|
199
|
+
}
|
|
200
|
+
export type DeviceKillAllArgs = Record<string, never>;
|
|
201
|
+
export interface DeviceCreateArgs {
|
|
202
|
+
limits: SandboxLimits;
|
|
203
|
+
}
|
|
204
|
+
export interface DeviceCreateResult {
|
|
205
|
+
roots: SandboxRoots;
|
|
206
|
+
}
|
|
207
|
+
export interface DeviceStopArgs {
|
|
208
|
+
reason: "revoked" | "deleted";
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Edits the device's local policy. The kernel may only narrow: it removes hosts from the sandbox
|
|
212
|
+
* allowlist and narrows the owner ceiling ({@link DevicePolicyArgs}). Widening happens only on the
|
|
213
|
+
* machine (`capybara-device policy add`, `capybara-device ceiling set`): the frame parser refuses
|
|
214
|
+
* an `add` and the protocol 3 `mode`.
|
|
215
|
+
*/
|
|
216
|
+
export interface LegacyDevicePolicyArgs {
|
|
217
|
+
/**
|
|
218
|
+
* The kernel's id of this change (non-empty, no `:`, at most {@link MAX_POLICY_OP_ID_LENGTH}
|
|
219
|
+
* characters): the device logs the op's outcome under it, for `policyStatus` and the hello's
|
|
220
|
+
* `recentOps`.
|
|
221
|
+
*/
|
|
222
|
+
opId: string;
|
|
223
|
+
/** Hosts to remove from `allowedDomains`. */
|
|
224
|
+
remove?: string[];
|
|
225
|
+
/** Who decided, for the device's local audit line. */
|
|
226
|
+
source: {
|
|
227
|
+
approvalId?: string;
|
|
228
|
+
accountId: string;
|
|
229
|
+
accountName: string;
|
|
230
|
+
via: "web" | "im";
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/** The policy as the device wrote it. */
|
|
234
|
+
export interface LegacyDevicePolicyResult {
|
|
235
|
+
policy: DeviceLocalPolicySummary;
|
|
236
|
+
}
|
|
237
|
+
/** Asks what became of the `policy` op with this id. Read-only on the device. */
|
|
238
|
+
export interface DevicePolicyStatusArgs {
|
|
239
|
+
opId: string;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* What the device logged of a `policy` op: its {@link DevicePolicyOpOutcome}, or `unknown` when
|
|
243
|
+
* the id is not in its log (never received, or dropped from the log since). `policy` is the
|
|
244
|
+
* device's summary now; `message` the refusal's.
|
|
245
|
+
*/
|
|
246
|
+
export interface LegacyDevicePolicyStatus {
|
|
247
|
+
outcome: DevicePolicyOpOutcome | "unknown";
|
|
248
|
+
policy?: DeviceLocalPolicySummary;
|
|
249
|
+
message?: string;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Lists one directory (absolute `path`, {@link validateSandboxPathShape}): at most `limit` entries
|
|
253
|
+
* (at most {@link MAX_DEVICE_LIST_ENTRIES}), read within the operation's scope. See
|
|
254
|
+
* `SandboxProvider.list` for the semantics.
|
|
255
|
+
*/
|
|
256
|
+
export interface DeviceListArgs {
|
|
257
|
+
path: string;
|
|
258
|
+
limit: number;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* One entry of a listed directory: `name` is never empty, `.` or `..` and holds no `/`. `isDir`
|
|
262
|
+
* follows symbolic links (stat semantics): a link to a directory is `true`, a dangling link `false`,
|
|
263
|
+
* and so is a link whose target the request's mode cannot reach.
|
|
264
|
+
*/
|
|
265
|
+
export interface DeviceListEntry {
|
|
266
|
+
name: string;
|
|
267
|
+
isDir: boolean;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The directory's entries sorted by code unit, `truncated` when more than `limit` exist; null only
|
|
271
|
+
* when the path does not exist and the request's mode could reach it (like `stat` / `readFile`).
|
|
272
|
+
* A file, an unreadable directory, or a path the request's mode cannot reach is an error (the
|
|
273
|
+
* latter a `policy` refusal), never null.
|
|
274
|
+
*/
|
|
275
|
+
export type DeviceListResult = {
|
|
276
|
+
entries: DeviceListEntry[];
|
|
277
|
+
truncated: boolean;
|
|
278
|
+
} | null;
|
|
279
|
+
/**
|
|
280
|
+
* Looks for project-like directories under `base` (absolute, {@link validateSandboxPathShape}),
|
|
281
|
+
* read within the operation's scope. A `base` that does not exist answers `[]`; a `base` that is a
|
|
282
|
+
* file, unreadable, or outside the request's scope is an error. See `SandboxProvider.scan` for the
|
|
283
|
+
* traversal.
|
|
284
|
+
*/
|
|
285
|
+
export interface DeviceScanArgs {
|
|
286
|
+
base: string;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH} levels below it that
|
|
290
|
+
* hold a `.git` entry or an `AGENTS.md` file, sorted by `path` in code-unit order and cut to the
|
|
291
|
+
* first {@link MAX_DEVICE_SCAN_RESULTS}. Never file contents. See `SandboxProvider.scan`.
|
|
292
|
+
*/
|
|
293
|
+
export type DeviceScanResult = DeviceProjectCandidate[];
|
|
294
|
+
/** A frame that is not valid device protocol (or came from the wrong side). */
|
|
295
|
+
export declare class DeviceProtocolError extends Error {
|
|
296
|
+
constructor(message: string);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Whether `v` is a valid policy op id: non-empty, no `:`, at most
|
|
300
|
+
* {@link MAX_POLICY_OP_ID_LENGTH} characters.
|
|
301
|
+
*/
|
|
302
|
+
export declare function isPolicyOpId(v: unknown): v is string;
|
|
303
|
+
/** Result type per op. */
|
|
304
|
+
export interface DeviceOpResults {
|
|
305
|
+
create: DeviceCreateResult;
|
|
306
|
+
exec: DeviceExecResult;
|
|
307
|
+
readFile: DeviceReadFileResult;
|
|
308
|
+
writeFile: DeviceWriteFileResult;
|
|
309
|
+
stat: DeviceStatResult;
|
|
310
|
+
killTagged: null;
|
|
311
|
+
killAll: null;
|
|
312
|
+
stop: null;
|
|
313
|
+
policy: LegacyDevicePolicyResult;
|
|
314
|
+
policyStatus: LegacyDevicePolicyStatus;
|
|
315
|
+
list: DeviceListResult;
|
|
316
|
+
scan: DeviceScanResult;
|
|
317
|
+
}
|
|
318
|
+
/** Validates the `result` of a successful `res` for `op`; throws {@link DeviceProtocolError}. */
|
|
319
|
+
export declare function parseOpResult<Op extends DeviceOp>(op: Op, result: unknown): DeviceOpResults[Op];
|
|
320
|
+
/**
|
|
321
|
+
* Parses one WebSocket text frame. `from` is the sender: a device may send `hello`, `res` and
|
|
322
|
+
* `policy`, the
|
|
323
|
+
* kernel `req` and `cancel`. Throws {@link DeviceProtocolError} on bad JSON, an unknown `type`,
|
|
324
|
+
* missing fields or a frame of the wrong direction.
|
|
325
|
+
*/
|
|
326
|
+
export declare function parseLegacyDeviceFrame(raw: string, from: "device" | "kernel"): LegacyDeviceFrame;
|
|
327
|
+
/**
|
|
328
|
+
* The operations the kernel asks a protocol 4 device to run: every user operation carries its
|
|
329
|
+
* admitted scope; there is no broad kill (`killTagged` / `killAll`).
|
|
330
|
+
*/
|
|
331
|
+
export type DeviceOperation = Exclude<DeviceOp, "killTagged" | "killAll"> | "prepareReadFile" | "prepareWriteFile" | "prepareStat" | "browseStat" | "browseList" | "browseScan" | "backgroundStart" | "backgroundStatus" | "backgroundTail" | "backgroundReadOutput" | "backgroundStop" | "revokeOperation" | "bindInstance";
|
|
332
|
+
/** The sandbox network of a device: the open public internet or an allowlist. */
|
|
333
|
+
export type DeviceNetworkMode = "open" | "allowlist";
|
|
334
|
+
/**
|
|
335
|
+
* The owner ceiling of protocol 4 (approval-only profiles design, "Settings model"): the device
|
|
336
|
+
* sandbox for every profile. `outsideSandbox` is whether a call may be granted escalation outside
|
|
337
|
+
* the sandbox; `network` and `allowedDomains` are the sandbox network.
|
|
338
|
+
*/
|
|
339
|
+
export interface DeviceOwnerCeiling {
|
|
340
|
+
readonly version: 3;
|
|
341
|
+
readonly sequence: number;
|
|
342
|
+
readonly revision: string;
|
|
343
|
+
readonly outsideSandbox: boolean;
|
|
344
|
+
readonly network: DeviceNetworkMode;
|
|
345
|
+
readonly allowedDomains: readonly string[];
|
|
346
|
+
readonly restrictedProjectReach: "workspace" | "os-user";
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* The narrowing of protocol 4: the kernel may switch the network to `allowlist`, remove hosts, turn
|
|
350
|
+
* `outsideSandbox` off or narrow the project reach. Never a widening: widening is decided on the
|
|
351
|
+
* machine by its owner (`capybara-device ceiling set`), never over the wire.
|
|
352
|
+
*/
|
|
353
|
+
export interface DeviceOwnerCeilingNarrowing {
|
|
354
|
+
readonly outsideSandbox?: false;
|
|
355
|
+
readonly network?: "allowlist";
|
|
356
|
+
/** Hosts to remove from `allowedDomains`; a host not on the list is ignored. */
|
|
357
|
+
readonly removeAllowedDomains?: readonly string[];
|
|
358
|
+
readonly restrictedProjectReach?: "workspace";
|
|
359
|
+
}
|
|
360
|
+
/** A staged `policy` op: the protocol 2 change plus an optional owner-ceiling narrowing. */
|
|
361
|
+
export interface DevicePolicyArgs extends LegacyDevicePolicyArgs {
|
|
362
|
+
ownerCeiling?: DeviceOwnerCeilingNarrowing;
|
|
363
|
+
}
|
|
364
|
+
/** A staged `policy` answer: the policy as written and the owner report issued for it. */
|
|
365
|
+
export interface DevicePolicyResult {
|
|
366
|
+
policy: DeviceLocalPolicySummary;
|
|
367
|
+
ownerCeiling: DeviceOwnerCeiling;
|
|
368
|
+
}
|
|
369
|
+
/** A staged `policyStatus` answer: an `applied` outcome carries the current owner report. */
|
|
370
|
+
export interface DevicePolicyStatus extends LegacyDevicePolicyStatus {
|
|
371
|
+
ownerCeiling?: DeviceOwnerCeiling;
|
|
372
|
+
}
|
|
373
|
+
/** The device pushed a policy change: the owner report for the newly observed revision. */
|
|
374
|
+
export interface DevicePolicyChanged {
|
|
375
|
+
type: "policy";
|
|
376
|
+
policy?: DeviceLocalPolicySummary;
|
|
377
|
+
ownerCeiling: DeviceOwnerCeiling;
|
|
378
|
+
}
|
|
379
|
+
export interface DeviceHello extends LegacyDeviceHello {
|
|
380
|
+
protocol: 4;
|
|
381
|
+
permissionSupport: SandboxPermissionSupport;
|
|
382
|
+
ownerCeiling: DeviceOwnerCeiling;
|
|
383
|
+
instanceGeneration: string | null;
|
|
384
|
+
transport: {
|
|
385
|
+
maxFrameBytes: number;
|
|
386
|
+
};
|
|
387
|
+
/** Absent until the program can attest actual installed runtime/helper/environment bytes. */
|
|
388
|
+
runtimeIdentity?: DeviceRuntimeIdentity;
|
|
389
|
+
}
|
|
390
|
+
/** A verified installed runtime/helper/environment identity bound to one instance generation. */
|
|
391
|
+
export interface DeviceRuntimeIdentity {
|
|
392
|
+
runtimeHash: string;
|
|
393
|
+
helperHash: string;
|
|
394
|
+
imageFingerprint: string;
|
|
395
|
+
instanceGeneration: string;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Private lifecycle request (permission runtime cutover B4): binds the kernel's committed instance
|
|
399
|
+
* generation to the device after commit. It carries no path, policy or manifest.
|
|
400
|
+
*/
|
|
401
|
+
export interface BindInstanceRequest {
|
|
402
|
+
instanceId: string;
|
|
403
|
+
instanceGeneration: string;
|
|
404
|
+
bindingId: string;
|
|
405
|
+
expectedPreviousGeneration: string | null;
|
|
406
|
+
}
|
|
407
|
+
export interface BindInstanceResult {
|
|
408
|
+
instanceId: string;
|
|
409
|
+
instanceGeneration: string;
|
|
410
|
+
bindingId: string;
|
|
411
|
+
runtimeIdentity: DeviceRuntimeIdentity;
|
|
412
|
+
permissionSupport: SandboxPermissionSupport;
|
|
413
|
+
ownerCeiling: DeviceOwnerCeiling;
|
|
414
|
+
}
|
|
415
|
+
export interface KernelReady {
|
|
416
|
+
type: "ready";
|
|
417
|
+
connectionId: string;
|
|
418
|
+
maxFrameBytes: number;
|
|
419
|
+
}
|
|
420
|
+
export interface BackgroundReadOutputRequest {
|
|
421
|
+
offset: number;
|
|
422
|
+
maxBytes: number;
|
|
423
|
+
}
|
|
424
|
+
export type BackgroundReadOutputResult = {
|
|
425
|
+
dataB64: string;
|
|
426
|
+
offset: number;
|
|
427
|
+
nextOffset: number;
|
|
428
|
+
totalBytes: number;
|
|
429
|
+
} | {
|
|
430
|
+
unavailable: "lost" | "expired";
|
|
431
|
+
};
|
|
432
|
+
export interface KernelRequest {
|
|
433
|
+
type: "req";
|
|
434
|
+
id: string;
|
|
435
|
+
op: DeviceOperation;
|
|
436
|
+
args: Readonly<Record<string, unknown>>;
|
|
437
|
+
deadlineMs: number;
|
|
438
|
+
}
|
|
439
|
+
export type DeviceResponse = Exclude<DeviceRes, {
|
|
440
|
+
ok: false;
|
|
441
|
+
}> | {
|
|
442
|
+
type: "res";
|
|
443
|
+
id: string;
|
|
444
|
+
ok: false;
|
|
445
|
+
error: {
|
|
446
|
+
/**
|
|
447
|
+
* The typed failure: `denied`, `unsupported`, `unknown` and `invalid` carry the SDK's
|
|
448
|
+
* scope denial, unsupported permission, unknown outcome and scope validation errors.
|
|
449
|
+
* `invalid` never proves the operation had no effect (a skewed device may have parsed
|
|
450
|
+
* part of it): it must never join the not-run refusals (`isRefusal`, `failureKindOf`).
|
|
451
|
+
*/
|
|
452
|
+
kind: "gone" | "fs_gone" | "policy" | "error" | "denied" | "unsupported" | "unknown" | "invalid";
|
|
453
|
+
message: string;
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
export type DeviceFrame = DeviceHello | KernelReady | KernelRequest | KernelCancel | DeviceResponse | DevicePolicyChanged;
|
|
457
|
+
/**
|
|
458
|
+
* Strictly parses a runtime permission report, version 2 (the protocol 4 `permissionSupport`, also
|
|
459
|
+
* the shape a cloud provider reports), and returns a frozen copy; throws {@link DeviceProtocolError}.
|
|
460
|
+
* Restricted support is all four claims or `null`; per-operation hosts need the allowlist; an
|
|
461
|
+
* operation boundary without restricted support claims no sandbox network at all. An
|
|
462
|
+
* instance boundary is the whole instance: it claims no restricted per-operation scope, no
|
|
463
|
+
* outside-sandbox escalation and no per-operation hosts (a host joins the device's list instead).
|
|
464
|
+
*/
|
|
465
|
+
export declare function parseSandboxPermissionSupport(value: unknown): SandboxPermissionSupport;
|
|
466
|
+
/**
|
|
467
|
+
* Strictly parses one authenticated owner-ceiling report of protocol 4 and returns a frozen copy;
|
|
468
|
+
* throws {@link DeviceProtocolError}. Unknown fields (the protocol 3 `fullAccess` and
|
|
469
|
+
* `restrictedAllowedDomains` among them) are refused.
|
|
470
|
+
*/
|
|
471
|
+
export declare function parseOwnerCeilingReport(value: unknown): DeviceOwnerCeiling;
|
|
472
|
+
/**
|
|
473
|
+
* Strictly parses an owner-ceiling narrowing of protocol 4 and returns a frozen copy; throws
|
|
474
|
+
* {@link DeviceProtocolError}. Every field can only narrow: `outsideSandbox` only to `false`,
|
|
475
|
+
* `network` only to `allowlist`, the project reach only to `workspace`, and hosts only removed.
|
|
476
|
+
* There is no way to name a host to add or a list to replace.
|
|
477
|
+
*/
|
|
478
|
+
export declare function parseOwnerCeilingNarrowing(value: unknown): DeviceOwnerCeilingNarrowing;
|
|
479
|
+
/** Strictly parses one protocol 4 frame; throws {@link DeviceProtocolError}. */
|
|
480
|
+
export declare function parseDeviceFrame(raw: string, from: "device" | "kernel", maxFrameBytes?: number): DeviceFrame;
|
|
481
|
+
export declare function parseOperationResult(op: DeviceOperation, result: unknown, request?: BackgroundReadOutputRequest | BindInstanceRequest): unknown;
|