@capybara-hq/plugin-device-local 0.1.0-rc.1 → 0.1.0-rc.2
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/.capybara-plugin/plugin.json +3 -3
- package/README.md +10 -5
- package/dist/index.mjs +72 -22
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"name": "device-local",
|
|
4
|
-
"version": "0.1.0-rc.
|
|
4
|
+
"version": "0.1.0-rc.2",
|
|
5
5
|
"publisher": "Capybara",
|
|
6
6
|
"description": {
|
|
7
7
|
"en": "Devices on people's own computers: a machine connected with capybara-device serves the device over the dial-in channel, and its owner limits it there",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"entry": "./dist/index.mjs",
|
|
24
24
|
"manifest": {
|
|
25
25
|
"name": "device-local",
|
|
26
|
-
"version": "0.1.0-rc.
|
|
26
|
+
"version": "0.1.0-rc.2",
|
|
27
27
|
"sdk": "^0.1.0-rc.56",
|
|
28
28
|
"provides": [
|
|
29
29
|
"device-provider@1"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"optional": [],
|
|
33
33
|
"permissions": {
|
|
34
34
|
"dialIn": {
|
|
35
|
-
"protocol": "capybara-device/
|
|
35
|
+
"protocol": "capybara-device/6"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"config": {
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Devices on people's own computers (`device-provider@1` over the kernel's dial-in channel). A machine
|
|
4
4
|
signs in with [`capybara-device`](https://www.npmjs.com/package/@capybara-hq/device) (protocol
|
|
5
|
-
`capybara-device/
|
|
5
|
+
`capybara-device/6`, declared as `permissions.dialIn`) and serves one device; every operation of the
|
|
6
6
|
device is relayed to it through `ctx.dialIn`. The kernel holds the machine's socket and relays the
|
|
7
7
|
frames without reading them; this plugin checks every request before it is sent and parses every
|
|
8
8
|
answer strictly (the machine is not trusted).
|
|
@@ -15,8 +15,8 @@ answer strictly (the machine is not trusted).
|
|
|
15
15
|
| `create` | `create` (ends the previous generation's background work, answers the directory's roots), then `bindInstance` of a new instance generation; the handle is handed out only once the machine attested the binding |
|
|
16
16
|
| `resume` | Needs the machine online. `create` again (ends any background work a suspension could not reach), then the identical `bindInstance`; `gone` when the roots changed (a new login into another directory or mode) or the machine can no longer hold the generation (its runtime changed) |
|
|
17
17
|
| `suspend` / `destroy` | `create` when the machine is online: the generation's tracked background work ends, files are kept. Never fails while the machine is offline |
|
|
18
|
-
| `operation` / `prepare` / `browse` / `background` / `revokeOperation` | The scoped protocol
|
|
19
|
-
| raw `exec` / `readFile` / … , `killAll` / `killTagged` | Refused or nothing: a protocol
|
|
18
|
+
| `operation` / `prepare` / `browse` / `background` / `revokeOperation` | The scoped protocol 6 operations, each with its admitted scope |
|
|
19
|
+
| raw `exec` / `readFile` / … , `killAll` / `killTagged` | Refused or nothing: a protocol 6 machine runs work only under an admitted operation scope |
|
|
20
20
|
|
|
21
21
|
A command carries the instance's resources and, as its outer network, the network the kernel
|
|
22
22
|
admitted for the operation (its scope); the machine intersects it with its owner's ceiling. The
|
|
@@ -55,14 +55,19 @@ generation under another runtime identity is refused (`local.invalid_hello`,
|
|
|
55
55
|
- **Attestation.** An unbound hello (the program restarted, typically under a new runtime after an
|
|
56
56
|
upgrade) marks the installed binding unattested: the instance is gone and the kernel recreates
|
|
57
57
|
it, which binds a new generation.
|
|
58
|
-
- **`report()`** answers from the rows only: a description of the owner's ceiling (reach
|
|
59
|
-
|
|
58
|
+
- **`report()`** answers from the rows only: a description of the owner's ceiling (project reach
|
|
59
|
+
`machine` / `paths` / `workspace`, always `workspace` in Docker mode; outside the sandbox;
|
|
60
|
+
network) in English and Chinese, the owner's home (OS mode), the machine's own
|
|
60
61
|
narrowing as read-only limits and `reset: false`. Its revision is a hash of everything it is made
|
|
61
62
|
of plus the machine epoch (moved when the machine is revoked or replaced), the instance
|
|
62
63
|
generation, its runtime identity and its stored support; times and connection ids are left out,
|
|
63
64
|
so a reconnect with the same facts keeps it. After a hello or event moved the revision the
|
|
64
65
|
provider calls `ctx.devices.reportChanged`; after a create or resume the kernel reads the report
|
|
65
66
|
again itself.
|
|
67
|
+
- **Refused project paths.** A machine's `project_refused` outcome becomes
|
|
68
|
+
`ProjectPathRefusedError` with the fixed English and Chinese text of its refusal code
|
|
69
|
+
(`other-connection`, `outside-reach`, `denied`; `PROJECT_REFUSAL_TEXT`): the machine is not
|
|
70
|
+
trusted, so its message text never reaches the person.
|
|
66
71
|
- **`permissionSupport()`** answers from the rows only, never a machine round trip: the support the
|
|
67
72
|
machine attested for the installed binding, with outside-the-sandbox and the open public
|
|
68
73
|
internet narrowed to what the owner allows now (no open public internet while the owner's
|
package/dist/index.mjs
CHANGED
|
@@ -49,7 +49,7 @@ var canonicalReport = (r) => ({
|
|
|
49
49
|
outsideSandbox: r.outsideSandbox,
|
|
50
50
|
network: r.network,
|
|
51
51
|
allowedDomains: [...r.allowedDomains],
|
|
52
|
-
|
|
52
|
+
projectReach: r.projectReach
|
|
53
53
|
});
|
|
54
54
|
var sameOwnerReport = (a, b) => JSON.stringify(canonicalReport(a)) === JSON.stringify(canonicalReport(b));
|
|
55
55
|
function decideOwnerReport(stored, incoming) {
|
|
@@ -61,7 +61,7 @@ function decideOwnerReport(stored, incoming) {
|
|
|
61
61
|
}
|
|
62
62
|
var FAIL_CLOSED = {
|
|
63
63
|
outsideSandbox: false,
|
|
64
|
-
|
|
64
|
+
projectReach: "workspace",
|
|
65
65
|
allowedDomains: [],
|
|
66
66
|
network: "allowlist"
|
|
67
67
|
};
|
|
@@ -77,7 +77,7 @@ function ownerFactsOf(stored) {
|
|
|
77
77
|
return {
|
|
78
78
|
state: "report",
|
|
79
79
|
outsideSandbox: stored.report.outsideSandbox,
|
|
80
|
-
|
|
80
|
+
projectReach: stored.report.projectReach,
|
|
81
81
|
allowedDomains: [...stored.report.allowedDomains],
|
|
82
82
|
network: stored.report.network,
|
|
83
83
|
revision: stored.report.revision,
|
|
@@ -101,7 +101,9 @@ function applyOwnerReport(stored, incoming, via, now) {
|
|
|
101
101
|
|
|
102
102
|
// src/report.ts
|
|
103
103
|
import { createHash } from "node:crypto";
|
|
104
|
-
import {
|
|
104
|
+
import {
|
|
105
|
+
parseSandboxPermissionSupport
|
|
106
|
+
} from "@capybara-hq/plugin-sdk/device-protocol";
|
|
105
107
|
function closedSupport(unavailableReason) {
|
|
106
108
|
return parseSandboxPermissionSupport({
|
|
107
109
|
version: 2,
|
|
@@ -148,7 +150,7 @@ function revisionFacts(c, b) {
|
|
|
148
150
|
sequence: owner.sequence,
|
|
149
151
|
revision: owner.revision,
|
|
150
152
|
outsideSandbox: owner.outsideSandbox,
|
|
151
|
-
|
|
153
|
+
projectReach: owner.projectReach,
|
|
152
154
|
network: owner.network,
|
|
153
155
|
allowedDomains: [...owner.allowedDomains].sort()
|
|
154
156
|
}
|
|
@@ -168,6 +170,26 @@ function revisionFacts(c, b) {
|
|
|
168
170
|
}
|
|
169
171
|
var revisionOf = (c, b) => createHash("sha256").update(JSON.stringify(revisionFacts(c, b))).digest("hex");
|
|
170
172
|
var hosts = (n) => n === 1 ? { en: "1 allowed host", zh: "允许 1 个主机" } : { en: `${n} allowed hosts`, zh: `允许 ${n} 个主机` };
|
|
173
|
+
var effectiveReach = (mode, reach) => mode === "docker" ? "workspace" : reach;
|
|
174
|
+
var READS = {
|
|
175
|
+
machine: {
|
|
176
|
+
en: "Reads the whole machine except secrets and other connections; writes only in the project and workspace",
|
|
177
|
+
zh: "读取本机全部文件(密钥和其他连接除外);只在项目和工作区写入"
|
|
178
|
+
},
|
|
179
|
+
paths: {
|
|
180
|
+
en: "Reads only the project directories the machine's owner listed; writes only in the project and workspace",
|
|
181
|
+
zh: "只读取本机所有者列出的项目目录;只在项目和工作区写入"
|
|
182
|
+
},
|
|
183
|
+
workspace: { en: "Reads and writes only the device's workspace", zh: "只读写设备的工作区" }
|
|
184
|
+
};
|
|
185
|
+
function describeLocalDevice(c) {
|
|
186
|
+
const reads = READS[effectiveReach(c.mode, c.projectReach)];
|
|
187
|
+
const outside = c.outsideSandbox ? {
|
|
188
|
+
en: "runs outside the sandbox only per approved call",
|
|
189
|
+
zh: "仅在获批的单次调用中在沙箱外运行"
|
|
190
|
+
} : { en: "never runs outside the sandbox", zh: "从不在沙箱外运行" };
|
|
191
|
+
return { en: `${reads.en}; ${outside.en}`, zh: `${reads.zh};${outside.zh}` };
|
|
192
|
+
}
|
|
171
193
|
function describe(c, owner) {
|
|
172
194
|
const docker = c.mode === "docker";
|
|
173
195
|
if (owner.state !== "report")
|
|
@@ -175,20 +197,22 @@ function describe(c, owner) {
|
|
|
175
197
|
en: "The computer's owner settings are unreadable or arrived out of order, so it runs as narrowly as possible (workspace only, never outside the sandbox) until it reports them again.",
|
|
176
198
|
zh: "电脑所有者的设置无法读取或报告顺序异常,在重新报告前按最窄的方式运行(只用工作区,从不在沙箱外运行)。"
|
|
177
199
|
};
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
en: "runs outside the sandbox only per approved call",
|
|
184
|
-
zh: "仅对批准的单次调用在沙箱外运行"
|
|
185
|
-
} : { en: "never runs outside the sandbox", zh: "从不在沙箱外运行" };
|
|
200
|
+
const what = describeLocalDevice({
|
|
201
|
+
projectReach: owner.projectReach,
|
|
202
|
+
outsideSandbox: owner.outsideSandbox,
|
|
203
|
+
mode: c.mode
|
|
204
|
+
});
|
|
186
205
|
const net = owner.network === "open" ? { en: "the open internet", zh: "开放的互联网" } : hosts(owner.allowedDomains.length);
|
|
187
206
|
return {
|
|
188
|
-
en: `${docker ? "In a Docker container: " : ""}${
|
|
189
|
-
zh: `${docker ? "在 Docker 容器中:" : ""}${
|
|
207
|
+
en: `${docker ? "In a Docker container: " : ""}${what.en}; network: ${net.en}.`,
|
|
208
|
+
zh: `${docker ? "在 Docker 容器中:" : ""}${what.zh};网络:${net.zh}。`
|
|
190
209
|
};
|
|
191
210
|
}
|
|
211
|
+
var REACH_VALUE = {
|
|
212
|
+
machine: "machine",
|
|
213
|
+
paths: "listed directories",
|
|
214
|
+
workspace: "workspace"
|
|
215
|
+
};
|
|
192
216
|
function limitsOf(c, owner) {
|
|
193
217
|
const lines = [
|
|
194
218
|
{ label: { en: "Mode", zh: "模式" }, value: c.mode },
|
|
@@ -198,7 +222,7 @@ function limitsOf(c, owner) {
|
|
|
198
222
|
},
|
|
199
223
|
{
|
|
200
224
|
label: { en: "Project reach", zh: "项目范围" },
|
|
201
|
-
value: owner.
|
|
225
|
+
value: REACH_VALUE[effectiveReach(c.mode, owner.projectReach)]
|
|
202
226
|
},
|
|
203
227
|
{ label: { en: "Network", zh: "网络" }, value: owner.network }
|
|
204
228
|
];
|
|
@@ -4344,7 +4368,6 @@ import {
|
|
|
4344
4368
|
// src/frames.ts
|
|
4345
4369
|
import {
|
|
4346
4370
|
FileSystemGoneError,
|
|
4347
|
-
ProjectPathRefusedError,
|
|
4348
4371
|
SandboxGoneError,
|
|
4349
4372
|
SandboxOperationOutcomeUnknownError,
|
|
4350
4373
|
SandboxPermissionUnsupportedError,
|
|
@@ -4357,6 +4380,29 @@ import {
|
|
|
4357
4380
|
parseDeviceFrame as parseDeviceFrame2,
|
|
4358
4381
|
parseOperationResult
|
|
4359
4382
|
} from "@capybara-hq/plugin-sdk/device-protocol";
|
|
4383
|
+
|
|
4384
|
+
// src/project-refusal.ts
|
|
4385
|
+
import { ProjectPathRefusedError } from "@capybara-hq/plugin-sdk";
|
|
4386
|
+
var PROJECT_REFUSAL_TEXT = Object.freeze({
|
|
4387
|
+
"other-connection": Object.freeze({
|
|
4388
|
+
en: "This directory belongs to another connection on this machine.",
|
|
4389
|
+
zh: "这个目录属于本机上的另一个连接。"
|
|
4390
|
+
}),
|
|
4391
|
+
"outside-reach": Object.freeze({
|
|
4392
|
+
en: "This directory is outside the project reach the machine's owner set for this device.",
|
|
4393
|
+
zh: "这个目录不在本机所有者为此设备设定的项目范围内。"
|
|
4394
|
+
}),
|
|
4395
|
+
denied: Object.freeze({
|
|
4396
|
+
en: "This directory holds secrets or the device program's own state.",
|
|
4397
|
+
zh: "这个目录存放密钥或设备程序自身的状态。"
|
|
4398
|
+
})
|
|
4399
|
+
});
|
|
4400
|
+
function projectRefusalError(refusal) {
|
|
4401
|
+
const text = PROJECT_REFUSAL_TEXT[refusal];
|
|
4402
|
+
return new ProjectPathRefusedError({ en: text.en, zh: text.zh });
|
|
4403
|
+
}
|
|
4404
|
+
|
|
4405
|
+
// src/frames.ts
|
|
4360
4406
|
var POLICY_REFUSAL_PREFIX = "Refused by the machine's local policy: ";
|
|
4361
4407
|
var ON_MACHINE_PREFIX = "On the connected machine: ";
|
|
4362
4408
|
var EXEC_DEADLINE_MARGIN_MS = 5e3;
|
|
@@ -4391,9 +4437,12 @@ function requestOf(op, args) {
|
|
|
4391
4437
|
if (op === "bindInstance") return args;
|
|
4392
4438
|
return void 0;
|
|
4393
4439
|
}
|
|
4394
|
-
var isProjectListing = (op) => op === "list" || op === "scan" || op === "browseList" || op === "browseScan";
|
|
4395
4440
|
function failureOf(error, op) {
|
|
4396
4441
|
const { kind, message } = error;
|
|
4442
|
+
if (kind === "project_refused") {
|
|
4443
|
+
if (error.refusal === void 0) return invalidAnswer(op, "a project refusal without a code");
|
|
4444
|
+
return projectRefusalError(error.refusal);
|
|
4445
|
+
}
|
|
4397
4446
|
switch (kind) {
|
|
4398
4447
|
case "denied":
|
|
4399
4448
|
return new SandboxScopeDeniedError(message);
|
|
@@ -4410,8 +4459,6 @@ function failureOf(error, op) {
|
|
|
4410
4459
|
case "fs_gone":
|
|
4411
4460
|
return new FileSystemGoneError(message);
|
|
4412
4461
|
case "policy":
|
|
4413
|
-
if (isProjectListing(op))
|
|
4414
|
-
return new ProjectPathRefusedError({ en: `${POLICY_REFUSAL_PREFIX}${message}` });
|
|
4415
4462
|
return new ToolError(
|
|
4416
4463
|
`${POLICY_REFUSAL_PREFIX}${message} (ask the machine's owner to allow it, or use another way)`
|
|
4417
4464
|
);
|
|
@@ -4800,7 +4847,7 @@ function createDeviceLocalProvider(ctx, store, opts = {}) {
|
|
|
4800
4847
|
async destroyByName(_name, signal) {
|
|
4801
4848
|
signal.throwIfAborted();
|
|
4802
4849
|
},
|
|
4803
|
-
/** A protocol
|
|
4850
|
+
/** A protocol 6 machine has no broad kill: the kernel revokes exact operations instead. */
|
|
4804
4851
|
async killAll(_h, signal) {
|
|
4805
4852
|
signal.throwIfAborted();
|
|
4806
4853
|
},
|
|
@@ -4819,7 +4866,7 @@ function createDeviceLocalProvider(ctx, store, opts = {}) {
|
|
|
4819
4866
|
// src/index.ts
|
|
4820
4867
|
var plugin = defineExtension({
|
|
4821
4868
|
name: "device-local",
|
|
4822
|
-
version: "0.1.0-rc.
|
|
4869
|
+
version: "0.1.0-rc.2",
|
|
4823
4870
|
// ctx.dialIn.capacity and the handlers' connection argument are the rc.56 SDK's
|
|
4824
4871
|
sdk: "^0.1.0-rc.56",
|
|
4825
4872
|
provides: [DEVICE_PROVIDER_EXTENSION_POINT],
|
|
@@ -4852,6 +4899,7 @@ export {
|
|
|
4852
4899
|
ON_MACHINE_PREFIX,
|
|
4853
4900
|
OP_DEADLINE_MS,
|
|
4854
4901
|
POLICY_REFUSAL_PREFIX,
|
|
4902
|
+
PROJECT_REFUSAL_TEXT,
|
|
4855
4903
|
applyOwnerReport,
|
|
4856
4904
|
closedSupport,
|
|
4857
4905
|
commandLimits,
|
|
@@ -4861,6 +4909,7 @@ export {
|
|
|
4861
4909
|
decideHello,
|
|
4862
4910
|
decideOwnerReport,
|
|
4863
4911
|
index_default as default,
|
|
4912
|
+
describeLocalDevice,
|
|
4864
4913
|
deviceIdOfName,
|
|
4865
4914
|
deviceReportOf,
|
|
4866
4915
|
failureOf,
|
|
@@ -4870,6 +4919,7 @@ export {
|
|
|
4870
4919
|
nextGeneration,
|
|
4871
4920
|
ownerFactsOf,
|
|
4872
4921
|
pgRows,
|
|
4922
|
+
projectRefusalError,
|
|
4873
4923
|
relayer,
|
|
4874
4924
|
reportFor,
|
|
4875
4925
|
revisionOf,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/plugin-device-local",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Devices on people's own computers: a machine connected with capybara-device serves the device over the dial-in channel, and its owner limits it there",
|