@capybara-hq/kernel 0.1.0-rc.67 → 0.1.0-rc.69
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/bootstrap.json +9 -1
- package/dist/admin/admin.module.js +2 -0
- package/dist/admin/health.service.d.ts +11 -4
- package/dist/admin/health.service.js +33 -17
- package/dist/background/poll.job.js +2 -2
- package/dist/background/tasks.service.d.ts +5 -5
- package/dist/background/tasks.service.js +9 -8
- package/dist/catalog/credential-key.d.ts +10 -0
- package/dist/catalog/credential-key.js +28 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-upgrade.js +1 -19
- package/dist/catalog/requests.service.js +1 -1
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +9 -9
- package/dist/conversations/conversations.controller.d.ts +8 -3
- package/dist/conversations/conversations.controller.js +8 -3
- package/dist/conversations/conversations.service.d.ts +33 -15
- package/dist/conversations/conversations.service.js +60 -10
- package/dist/conversations/events.d.ts +21 -41
- package/dist/conversations/events.js +57 -31
- package/dist/conversations/permission-profiles.controller.d.ts +6 -4
- package/dist/conversations/permission-profiles.service.d.ts +6 -4
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +77 -6
- package/dist/ctx/device-provider-check.d.ts +6 -2
- package/dist/ctx/device-provider-check.js +17 -2
- package/dist/db/kernel-schema.d.ts +10 -48
- package/dist/devices/access.d.ts +3 -4
- package/dist/devices/access.js +3 -4
- package/dist/devices/conversation-devices.d.ts +1 -3
- package/dist/devices/conversation-devices.js +2 -7
- package/dist/devices/device-projects.service.js +24 -29
- package/dist/devices/device-provider-selection.d.ts +5 -6
- package/dist/devices/device-provider-selection.js +8 -9
- package/dist/devices/devices.controller.d.ts +8 -21
- package/dist/devices/devices.controller.js +9 -34
- package/dist/devices/devices.module.js +6 -4
- package/dist/devices/devices.schemas.d.ts +1 -5
- package/dist/devices/devices.schemas.js +1 -5
- package/dist/devices/devices.service.d.ts +84 -147
- package/dist/devices/devices.service.js +134 -229
- package/dist/devices/dto.d.ts +5 -32
- package/dist/devices/dto.js +5 -37
- package/dist/devices/errors.d.ts +6 -5
- package/dist/devices/errors.js +7 -8
- package/dist/devices/project-rules.d.ts +9 -11
- package/dist/devices/project-rules.js +7 -7
- package/dist/devices/working-root.d.ts +3 -6
- package/dist/devices/working-root.js +3 -8
- package/dist/dial-in/access.d.ts +23 -0
- package/dist/dial-in/access.js +64 -0
- package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
- package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
- package/dist/dial-in/auth.module.d.ts +7 -0
- package/dist/dial-in/auth.module.js +27 -0
- package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
- package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
- package/dist/dial-in/dial-in.module.d.ts +9 -0
- package/dist/dial-in/dial-in.module.js +37 -0
- package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
- package/dist/{local-devices → dial-in}/dto.js +14 -2
- package/dist/dial-in/envelope.d.ts +95 -0
- package/dist/dial-in/envelope.js +89 -0
- package/dist/dial-in/gateway.d.ts +214 -0
- package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
- package/dist/dial-in/handlers.d.ts +47 -0
- package/dist/dial-in/handlers.js +84 -0
- package/dist/dial-in/machines.d.ts +155 -0
- package/dist/dial-in/machines.js +383 -0
- package/dist/dial-in/relay.d.ts +135 -0
- package/dist/dial-in/relay.js +444 -0
- package/dist/dial-in/relay.module.d.ts +7 -0
- package/dist/dial-in/relay.module.js +24 -0
- package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
- package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
- package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
- package/dist/{local-devices → dial-in}/targets.js +3 -48
- package/dist/errors.d.ts +8 -27
- package/dist/errors.js +8 -27
- package/dist/extensions/bootstrap.d.ts +5 -0
- package/dist/extensions/bootstrap.js +10 -1
- package/dist/extensions/extensions.module.js +6 -0
- package/dist/extensions/host.d.ts +6 -0
- package/dist/extensions/host.js +12 -2
- package/dist/extensions/permission-set.d.ts +15 -1
- package/dist/extensions/permission-set.js +11 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/http/api.module.js +4 -4
- package/dist/http/gateway-routes.d.ts +1 -1
- package/dist/http/gateway-routes.js +1 -1
- package/dist/http/meta.controller.js +1 -1
- package/dist/identity/settings.d.ts +1 -1
- package/dist/identity/settings.js +6 -8
- package/dist/infra/config/kernel-config.service.js +2 -2
- package/dist/infra/outbox/registry.d.ts +0 -14
- package/dist/infra/outbox/registry.js +0 -15
- package/dist/infra/throttler/named-throttlers.d.ts +1 -1
- package/dist/infra/throttler/named-throttlers.js +1 -1
- package/dist/kernel.module.js +0 -3
- package/dist/orgs/settings.service.js +5 -10
- package/dist/overrides.d.ts +0 -4
- package/dist/overrides.js +0 -2
- package/dist/platform/exclusions.js +5 -5
- package/dist/platform/ops/admin.ops.js +1 -1
- package/dist/platform/ops/conversations.ops.js +5 -2
- package/dist/platform/ops/devices.ops.js +11 -24
- package/dist/platform/ops/inbox.ops.js +1 -1
- package/dist/roles/gateway-role.d.ts +3 -3
- package/dist/roles/gateway-role.js +4 -4
- package/dist/roles/gateway.module.d.ts +1 -1
- package/dist/roles/gateway.module.js +5 -5
- package/dist/runtime/context/device-paths.d.ts +4 -1
- package/dist/runtime/context/permission-profile.js +5 -5
- package/dist/runtime/maintenance.d.ts +2 -5
- package/dist/runtime/maintenance.js +9 -19
- package/dist/runtime/project/knowledge.js +4 -5
- package/dist/runtime/project/knowledge.service.js +2 -1
- package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
- package/dist/sandbox/cloud-permission-snapshot.js +1 -3
- package/dist/sandbox/device-reports.d.ts +74 -14
- package/dist/sandbox/device-reports.js +190 -33
- package/dist/sandbox/device-reports.module.d.ts +7 -0
- package/dist/sandbox/device-reports.module.js +25 -0
- package/dist/sandbox/device-sandbox.d.ts +39 -41
- package/dist/sandbox/device-sandbox.js +44 -83
- package/dist/sandbox/kernel-read.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.d.ts +11 -59
- package/dist/sandbox/legacy-retirement.js +34 -186
- package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.module.js +2 -2
- package/dist/sandbox/managed-device-context.d.ts +16 -4
- package/dist/sandbox/managed-device-context.js +25 -8
- package/dist/sandbox/managed-device-context.module.js +4 -0
- package/dist/sandbox/modes.d.ts +3 -12
- package/dist/sandbox/modes.js +2 -14
- package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
- package/dist/{local-devices → sandbox}/network-grants.js +4 -49
- package/dist/sandbox/operation-authority-types.d.ts +2 -1
- package/dist/sandbox/operation-authority.d.ts +6 -20
- package/dist/sandbox/operation-authority.js +43 -104
- package/dist/sandbox/operation-authority.module.js +1 -1
- package/dist/sandbox/operation-intents.d.ts +4 -1
- package/dist/sandbox/operation-intents.js +11 -2
- package/dist/sandbox/operation-reconcile.job.js +2 -4
- package/dist/sandbox/permission-availability.d.ts +6 -7
- package/dist/sandbox/permission-availability.js +7 -10
- package/dist/sandbox/permission-call-grants.d.ts +2 -1
- package/dist/sandbox/permission-call-grants.js +1 -7
- package/dist/sandbox/permission-call-types.d.ts +4 -4
- package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
- package/dist/sandbox/permission-ceiling-writes.js +8 -35
- package/dist/sandbox/permission-config-publication.d.ts +9 -1
- package/dist/sandbox/permission-config-publication.js +29 -21
- package/dist/sandbox/permission-context-types.d.ts +17 -10
- package/dist/sandbox/permission-facts.d.ts +98 -95
- package/dist/sandbox/permission-facts.js +160 -314
- package/dist/sandbox/permission-instance-writes.d.ts +23 -37
- package/dist/sandbox/permission-instance-writes.js +44 -121
- package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
- package/dist/sandbox/permission-runtime-reports.js +105 -122
- package/dist/sandbox/providers.d.ts +26 -38
- package/dist/sandbox/providers.js +36 -18
- package/dist/sandbox/request-not-sent.d.ts +2 -13
- package/dist/sandbox/request-not-sent.js +2 -13
- package/dist/sandbox/review/permission-candidate.d.ts +13 -8
- package/dist/sandbox/review/permission-candidate.js +38 -48
- package/dist/sandbox/sandbox.module.js +7 -3
- package/dist/sandbox/sandbox.service.d.ts +49 -59
- package/dist/sandbox/sandbox.service.js +139 -259
- package/dist/schedules/fire.d.ts +15 -6
- package/dist/schedules/fire.js +27 -13
- package/dist/schedules/grant-rules.js +1 -1
- package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
- package/dist/schedules/scheduled-tasks.service.js +1 -4
- package/dist/schedules/schedules.module.js +5 -3
- package/dist/skills/invoke.d.ts +1 -1
- package/dist/skills/invoke.js +2 -3
- package/dist/tools/approvals.service.d.ts +8 -5
- package/dist/tools/approvals.service.js +5 -5
- package/dist/tools/builtins/sandbox/bash.js +1 -2
- package/dist/tools/builtins/sandbox/common.d.ts +15 -9
- package/dist/tools/builtins/sandbox/common.js +37 -38
- package/dist/tools/connectors.controller.d.ts +2 -0
- package/dist/tools/connectors.schemas.d.ts +2 -0
- package/dist/tools/credentials.d.ts +2 -0
- package/dist/tools/network-asks.d.ts +19 -22
- package/dist/tools/network-asks.js +15 -21
- package/dist/tools/oauth/authorization-params.d.ts +7 -0
- package/dist/tools/oauth/authorization-params.js +19 -0
- package/dist/tools/oauth/flow.js +7 -0
- package/dist/tools/oauth/tokens.js +2 -1
- package/dist/tools/pipeline.d.ts +6 -7
- package/dist/tools/pipeline.js +17 -21
- package/dist/tools/tools.module.js +3 -7
- package/package.json +3 -4
- package/src/migrations/0177_dial_in_contract.sql +32 -0
- package/dist/local-devices/device-auth.module.d.ts +0 -7
- package/dist/local-devices/device-auth.module.js +0 -25
- package/dist/local-devices/device-policy.service.d.ts +0 -213
- package/dist/local-devices/device-policy.service.js +0 -605
- package/dist/local-devices/instance-bindings.d.ts +0 -82
- package/dist/local-devices/instance-bindings.js +0 -307
- package/dist/local-devices/local-device-gateway.d.ts +0 -153
- package/dist/local-devices/local-device-provider.d.ts +0 -122
- package/dist/local-devices/local-device-provider.js +0 -326
- package/dist/local-devices/local-devices.module.d.ts +0 -31
- package/dist/local-devices/local-devices.module.js +0 -100
- package/dist/local-devices/machines.d.ts +0 -211
- package/dist/local-devices/machines.js +0 -766
- package/dist/local-devices/owner-report.d.ts +0 -81
- package/dist/local-devices/owner-report.js +0 -150
- package/dist/local-devices/owner-reports.d.ts +0 -48
- package/dist/local-devices/owner-reports.js +0 -208
- package/dist/local-devices/policy-op-jobs.d.ts +0 -15
- package/dist/local-devices/policy-op-jobs.js +0 -12
- package/dist/local-devices/policy-summary.d.ts +0 -102
- package/dist/local-devices/policy-summary.js +0 -155
- package/dist/local-devices/relay.d.ts +0 -166
- package/dist/local-devices/relay.js +0 -559
- package/dist/tools/device-op-resolver.d.ts +0 -34
- package/dist/tools/device-op-resolver.js +0 -120
- /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
- /package/dist/{local-devices → dial-in}/keys.js +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
-
};
|
|
10
|
-
import { parseDeviceFrame, parseOperationResult, parseSandboxBrowseScope, parseSandboxOperationScope, parseSandboxPreparationScope, SandboxPermissionUnsupportedError, } from "@capybara-hq/plugin-sdk";
|
|
11
|
-
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
|
-
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
13
|
-
import { hostGrantable } from "../sandbox/device-sandbox.js";
|
|
14
|
-
import { providerLimits } from "../sandbox/modes.js";
|
|
15
|
-
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
16
|
-
import { deviceNotFound, SandboxService } from "../sandbox/sandbox.service.js";
|
|
17
|
-
import { relayer } from "./network-grants.js";
|
|
18
|
-
import { deviceOffline, LocalDeviceRelay } from "./relay.js";
|
|
19
|
-
import { DeviceTargets, sameRoots } from "./targets.js";
|
|
20
|
-
/** Extra time the machine gets beyond a command's own timeout (spawn, output, the trip back). */
|
|
21
|
-
export const EXEC_DEADLINE_MARGIN_MS = 5000;
|
|
22
|
-
/** How long the machine may take for one non-exec operation. */
|
|
23
|
-
export const OP_DEADLINE_MS = 30_000;
|
|
24
|
-
/**
|
|
25
|
-
* Room left in a frame for everything around a `readFile` result's base64 data (the `res`
|
|
26
|
-
* envelope): a read is clamped so the machine's answer fits `devices.local.maxFrameBytes`
|
|
27
|
-
* (ruling R26).
|
|
28
|
-
*/
|
|
29
|
-
export const FRAME_ENVELOPE_BYTES = 64 * 1024;
|
|
30
|
-
export { projectsUnsupported } from "../devices/errors.js";
|
|
31
|
-
/** The most raw bytes whose base64 plus {@link FRAME_ENVELOPE_BYTES} fit in `maxFrameBytes`. */
|
|
32
|
-
export const maxReadBytes = (maxFrameBytes) => Math.max(0, Math.floor((maxFrameBytes - FRAME_ENVELOPE_BYTES) / 4) * 3);
|
|
33
|
-
const NAME_PREFIX = "cap-device-";
|
|
34
|
-
/**
|
|
35
|
-
* A raw protocol 2 method: refused before anything is queued (a v3 machine runs work only under
|
|
36
|
-
* an admitted operation scope; there is no raw fallback).
|
|
37
|
-
*/
|
|
38
|
-
const refuseRaw = (method) => async (..._args) => {
|
|
39
|
-
throw new SandboxPermissionUnsupportedError(`${method} without an operation scope is not available on a protocol 4 device; run it through an admitted operation scope`);
|
|
40
|
-
};
|
|
41
|
-
/** The device id of a `cap-device-<deviceId>` name; undefined for any other name. */
|
|
42
|
-
export const deviceIdOfName = (name) => name.startsWith(NAME_PREFIX) && name.length > NAME_PREFIX.length
|
|
43
|
-
? name.slice(NAME_PREFIX.length)
|
|
44
|
-
: undefined;
|
|
45
|
-
const rootsOf = (h) => h.roots;
|
|
46
|
-
const bytesOf = (b64) => new Uint8Array(Buffer.from(b64, "base64"));
|
|
47
|
-
/**
|
|
48
|
-
* The kernel-internal provider `@local` (environments spec §13.5): every operation runs on the
|
|
49
|
-
* device's connected machine through the {@link LocalDeviceRelay}. The file system is the
|
|
50
|
-
* machine's device directory (the program creates it on first use), so `createFileSystem`
|
|
51
|
-
* touches nothing; `suspend` and `destroy` do nothing (the machine is not the platform's to stop);
|
|
52
|
-
* deleting the device leaves the files on the machine where they are. Nothing here throws `device.offline` on the cleanup paths (ruling R9).
|
|
53
|
-
*
|
|
54
|
-
* The files on a machine are its owner's: `destroyFileSystem` (a files reset, the deletion sweep)
|
|
55
|
-
* does nothing; the deletion's `stop` comes from `MachinesService.revokeActive` (ruling R24).
|
|
56
|
-
*/
|
|
57
|
-
let LocalDeviceProvider = class LocalDeviceProvider {
|
|
58
|
-
relay;
|
|
59
|
-
targets;
|
|
60
|
-
sandbox;
|
|
61
|
-
config;
|
|
62
|
-
callGrants;
|
|
63
|
-
concurrentExec = true;
|
|
64
|
-
networkAllowlist = true;
|
|
65
|
-
sessionIsolation = false;
|
|
66
|
-
/** What the kernel tells about a local device: fixed text, the machine's home, nothing to reset. */
|
|
67
|
-
async report(device, _signal) {
|
|
68
|
-
return {
|
|
69
|
-
revision: "local-1",
|
|
70
|
-
description: {
|
|
71
|
-
en: "Runs on a computer connected with capybara-device; the computer's owner limits it there.",
|
|
72
|
-
zh: "运行在用 capybara-device 连接的电脑上,电脑的主人在本机限制它。",
|
|
73
|
-
},
|
|
74
|
-
home: await this.targets.machineHome(device.deviceId),
|
|
75
|
-
limits: [],
|
|
76
|
-
reset: false,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
constructor(relay, targets, sandbox, config, callGrants) {
|
|
80
|
-
this.relay = relay;
|
|
81
|
-
this.targets = targets;
|
|
82
|
-
this.sandbox = sandbox;
|
|
83
|
-
this.config = config;
|
|
84
|
-
this.callGrants = callGrants;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* The `@local` provider as the staged (protocol 4) registration hands it out
|
|
88
|
-
* (`LocalDevicesModule`): the protocol 2 lifecycle methods that send no frame (file system,
|
|
89
|
-
* resume, suspend, destroy), the v3 operation adapter ({@link stagedOperations}), `create` as a
|
|
90
|
-
* protocol 4 request, no raw protocol 2 call and no broad kill. Dormant until the protocol gate
|
|
91
|
-
* selects it.
|
|
92
|
-
*
|
|
93
|
-
* The raw methods (`exec`, `readFile`, `writeFile`, `stat`, `list`, `scan`) refuse before
|
|
94
|
-
* anything is queued: a v3 machine runs work only under an admitted operation scope, and
|
|
95
|
-
* missing operation support never falls back to them.
|
|
96
|
-
*
|
|
97
|
-
* A v3 machine has no `killAll` / `killTagged` (permission runtime cutover B-1), so both are
|
|
98
|
-
* no-ops that queue nothing; the kernel never calls them anyway. What reaches the machine is
|
|
99
|
-
* only what the kernel revokes exactly (`revokeOperation` per intent): `SandboxService` owes a
|
|
100
|
-
* crashed holder's revocation in an outbox row before it forgets the holder record, revokes that
|
|
101
|
-
* holder's admitted, dispatching and started-or-unknown intents, and, under the exclusive lease
|
|
102
|
-
* on an incarnation nobody else holds (a resume, a failed limits change, a quarantine), every
|
|
103
|
-
* started-or-unknown intent of that generation; the owed revokes are delivered by operation id.
|
|
104
|
-
*/
|
|
105
|
-
staged(transport) {
|
|
106
|
-
const ops = this.stagedOperations(transport);
|
|
107
|
-
const overrides = {
|
|
108
|
-
...ops,
|
|
109
|
-
create: async (args) => {
|
|
110
|
-
const id = args.fileSystem.id;
|
|
111
|
-
const r = parseOperationResult("create", await transport.call(id, "create", { limits: args.limits }, { deadlineMs: OP_DEADLINE_MS, signal: args.signal }));
|
|
112
|
-
return { id, roots: r.roots, limits: args.limits };
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
// the shared lifecycle methods keep this provider as their receiver (relay, targets, config)
|
|
116
|
-
return Object.assign(Object.create(this), overrides);
|
|
117
|
-
}
|
|
118
|
-
/** Dormant v3 adapter. It is not installed on the active v2 registered provider. */
|
|
119
|
-
stagedOperations(transport) {
|
|
120
|
-
const native = (h, scope, prefix, factorySignal) => {
|
|
121
|
-
const send = async (op, args, signal) => {
|
|
122
|
-
const name = (prefix ? prefix + op.charAt(0).toUpperCase() + op.slice(1) : op);
|
|
123
|
-
const result = await transport.call(h.id, name, { scope, ...args }, { deadlineMs: OP_DEADLINE_MS, signal: AbortSignal.any([factorySignal, signal]) });
|
|
124
|
-
return parseOperationResult(name, result);
|
|
125
|
-
};
|
|
126
|
-
return {
|
|
127
|
-
exec: async () => {
|
|
128
|
-
throw new Error("Execution requires its request-bound authority adapter");
|
|
129
|
-
},
|
|
130
|
-
readFile: async (path, opts) => {
|
|
131
|
-
const r = (await send("readFile", {
|
|
132
|
-
path,
|
|
133
|
-
maxBytes: Math.min(opts.maxBytes, maxReadBytes(this.config.get().devices.local.maxFrameBytes)),
|
|
134
|
-
}, opts.signal));
|
|
135
|
-
return r === null ? null : { data: bytesOf(r.dataB64), truncated: r.truncated };
|
|
136
|
-
},
|
|
137
|
-
writeFile: async (path, data, signal) => {
|
|
138
|
-
await send("writeFile", { path, dataB64: Buffer.from(data).toString("base64") }, signal);
|
|
139
|
-
},
|
|
140
|
-
stat: async (path, signal) => (await send("stat", { path }, signal)),
|
|
141
|
-
list: async (path, opts) => (await send("list", { path, limit: opts.limit }, opts.signal)),
|
|
142
|
-
scan: async (base, opts) => (await send("scan", { base }, opts.signal)),
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
const execArgs = async (deviceId, scope, method, input) => {
|
|
146
|
-
const orgId = await this.targets.orgOf(deviceId);
|
|
147
|
-
if (orgId === null)
|
|
148
|
-
throw deviceNotFound();
|
|
149
|
-
const policy = await this.sandbox.devicePolicy({ orgId, deviceId });
|
|
150
|
-
const limits = await this.sandbox.deviceLimits({ orgId, deviceId }, { policy, source: "local" });
|
|
151
|
-
if (!this.callGrants)
|
|
152
|
-
throw new Error("Admitted execution authority is unavailable; check the device operation configuration");
|
|
153
|
-
const original = await this.callGrants.forExecution(scope.operationId, deviceId, method, scope, input);
|
|
154
|
-
// explicit hosts are checked against the per-call host ceiling (the org's hard allowlist
|
|
155
|
-
// ceiling and exclusions, the owner's list), never against the sandbox's own allowlist
|
|
156
|
-
const ceiling = await this.sandbox.hostGrantCeiling({ orgId, deviceId });
|
|
157
|
-
const ceilingNetwork = ceiling.kind === "any"
|
|
158
|
-
? { kind: "open-public", hosts: [] }
|
|
159
|
-
: { kind: "allowlist", hosts: [...ceiling.hosts] };
|
|
160
|
-
const kept = original?.hosts.filter((host) => hostGrantable(ceiling, host)) ?? [];
|
|
161
|
-
const grants = original && kept.length ? { ...original, hosts: kept } : undefined;
|
|
162
|
-
if (original?.hosts.some((host) => !grants?.hosts.includes(host)))
|
|
163
|
-
throw new Error("Current organization limits refuse the admitted explicit hosts; review the operation again");
|
|
164
|
-
// the wire carries resources and the device sandbox network only: the mode tier is
|
|
165
|
-
// kernel-internal
|
|
166
|
-
return {
|
|
167
|
-
wire: { limits: providerLimits(limits), ...(grants === undefined ? {} : { grants }) },
|
|
168
|
-
ceiling: { network: ceilingNetwork },
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
const background = {
|
|
172
|
-
start: async (h, input, args) => {
|
|
173
|
-
const scope = parseSandboxOperationScope(input);
|
|
174
|
-
// the device knows its bound generation: a kernel generation never goes on the wire
|
|
175
|
-
const { signal, instanceGeneration: _generation, ...rest } = args;
|
|
176
|
-
const authority = await execArgs(h.id, scope, "backgroundStart", rest);
|
|
177
|
-
signal.throwIfAborted();
|
|
178
|
-
return parseOperationResult("backgroundStart", await transport.call(h.id, "backgroundStart", { scope, ...rest, ...authority.wire }, { deadlineMs: args.timeoutMs + EXEC_DEADLINE_MARGIN_MS, signal }));
|
|
179
|
-
},
|
|
180
|
-
status: async (h, ref, signal) => parseOperationResult("backgroundStatus", await transport.call(h.id, "backgroundStatus", { ref }, { deadlineMs: OP_DEADLINE_MS, signal })),
|
|
181
|
-
readOutput: async (h, ref, opts) => {
|
|
182
|
-
opts.signal.throwIfAborted();
|
|
183
|
-
parseDeviceFrame(JSON.stringify({
|
|
184
|
-
type: "req",
|
|
185
|
-
id: "validate",
|
|
186
|
-
op: "backgroundReadOutput",
|
|
187
|
-
args: { ref, offset: opts.offset, maxBytes: opts.maxBytes },
|
|
188
|
-
deadlineMs: OP_DEADLINE_MS,
|
|
189
|
-
}), "kernel");
|
|
190
|
-
// liveness first (R27): a deleted or revoked device keeps its typed error
|
|
191
|
-
const connection = await this.relay.connection(h.id);
|
|
192
|
-
const capacity = Math.min(65536, maxReadBytes(connection.maxFrameBytes));
|
|
193
|
-
const request = { ref, offset: opts.offset, maxBytes: Math.min(opts.maxBytes, capacity) };
|
|
194
|
-
const result = parseOperationResult("backgroundReadOutput", await transport.call(h.id, "backgroundReadOutput", request, {
|
|
195
|
-
deadlineMs: OP_DEADLINE_MS,
|
|
196
|
-
signal: opts.signal,
|
|
197
|
-
connection,
|
|
198
|
-
}), request);
|
|
199
|
-
if ("unavailable" in result)
|
|
200
|
-
return result;
|
|
201
|
-
// A zero-capacity probe can establish EOF, but never reports unread bytes as EOF.
|
|
202
|
-
if (opts.maxBytes > 0 && capacity === 0 && result.totalBytes > opts.offset)
|
|
203
|
-
throw new Error("Managed output cannot fit the negotiated transport capacity; increase device and deployment frame limits and retry the same offset");
|
|
204
|
-
return {
|
|
205
|
-
data: bytesOf(result.dataB64),
|
|
206
|
-
offset: result.offset,
|
|
207
|
-
nextOffset: result.nextOffset,
|
|
208
|
-
totalBytes: result.totalBytes,
|
|
209
|
-
};
|
|
210
|
-
},
|
|
211
|
-
tail: async (h, ref, opts) => {
|
|
212
|
-
const r = parseOperationResult("backgroundTail", await transport.call(h.id, "backgroundTail", { ref, maxBytes: opts.maxBytes }, { deadlineMs: OP_DEADLINE_MS, signal: opts.signal }));
|
|
213
|
-
return "unavailable" in r ? r : { data: bytesOf(r.dataB64), truncated: r.truncated };
|
|
214
|
-
},
|
|
215
|
-
stop: async (h, ref, opts) => parseOperationResult("backgroundStop", await transport.call(h.id, "backgroundStop", { ref, graceMs: opts.graceMs }, { deadlineMs: OP_DEADLINE_MS, signal: opts.signal })),
|
|
216
|
-
};
|
|
217
|
-
return {
|
|
218
|
-
permissionSupport: (h, signal) => transport.permissionSupport(h.id, signal),
|
|
219
|
-
operation: async (h, input, signal) => {
|
|
220
|
-
const scope = parseSandboxOperationScope(input);
|
|
221
|
-
const methods = native(h, scope, "", signal);
|
|
222
|
-
return {
|
|
223
|
-
...methods,
|
|
224
|
-
exec: async (args) => {
|
|
225
|
-
const { signal: callSignal, ...rest } = args;
|
|
226
|
-
const authority = await execArgs(h.id, scope, "exec", rest);
|
|
227
|
-
const combined = AbortSignal.any([signal, callSignal]);
|
|
228
|
-
combined.throwIfAborted();
|
|
229
|
-
const result = parseOperationResult("exec", await transport.call(h.id, "exec", { scope, ...rest, ...authority.wire }, { deadlineMs: args.timeoutMs + EXEC_DEADLINE_MARGIN_MS, signal: combined }));
|
|
230
|
-
// the kernel's own layer for the machine's report, as on protocol 2: a host the org
|
|
231
|
-
// does not allow is `org` (only an admin can lift it), never a question to the owner
|
|
232
|
-
if (result.network?.blocked === undefined)
|
|
233
|
-
return result;
|
|
234
|
-
return {
|
|
235
|
-
...result,
|
|
236
|
-
network: { blocked: relayer(result.network.blocked, authority.ceiling) },
|
|
237
|
-
};
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
},
|
|
241
|
-
prepare: async (h, input, signal) => {
|
|
242
|
-
const n = native(h, parseSandboxPreparationScope(input), "prepare", signal);
|
|
243
|
-
return {
|
|
244
|
-
readFile: n.readFile,
|
|
245
|
-
writeFile: n.writeFile,
|
|
246
|
-
stat: n.stat,
|
|
247
|
-
};
|
|
248
|
-
},
|
|
249
|
-
browse: async (h, input, signal) => {
|
|
250
|
-
const n = native(h, parseSandboxBrowseScope(input), "browse", signal);
|
|
251
|
-
return { stat: n.stat, list: n.list, scan: n.scan };
|
|
252
|
-
},
|
|
253
|
-
revokeOperation: async (h, ref, signal) => {
|
|
254
|
-
await transport.call(h.id, "revokeOperation", { ref }, { deadlineMs: OP_DEADLINE_MS, signal });
|
|
255
|
-
},
|
|
256
|
-
background,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
async createFileSystem(args) {
|
|
260
|
-
args.signal.throwIfAborted();
|
|
261
|
-
const id = deviceIdOfName(args.name);
|
|
262
|
-
if (id === undefined)
|
|
263
|
-
throw new Error(`not a device name: ${args.name}`);
|
|
264
|
-
return { id };
|
|
265
|
-
}
|
|
266
|
-
/** The files are the machine owner's: nothing to do (ruling R24; never a `stop`). */
|
|
267
|
-
async destroyFileSystem(_fs, signal) {
|
|
268
|
-
signal.throwIfAborted();
|
|
269
|
-
}
|
|
270
|
-
async destroyFileSystemByName(_name, signal) {
|
|
271
|
-
signal.throwIfAborted();
|
|
272
|
-
}
|
|
273
|
-
async create(args) {
|
|
274
|
-
const id = args.fileSystem.id;
|
|
275
|
-
const r = await this.relay.call(id, "create", { limits: args.limits }, { deadlineMs: OP_DEADLINE_MS, signal: args.signal });
|
|
276
|
-
return { id, roots: r.roots, limits: args.limits };
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Needs the machine online. `gone` (the kernel recreates the instance) when the active machine
|
|
280
|
-
* last reported other roots than the instance was created with (a new login into another
|
|
281
|
-
* directory or mode, ruling R23).
|
|
282
|
-
*/
|
|
283
|
-
async resume(h, signal) {
|
|
284
|
-
signal.throwIfAborted();
|
|
285
|
-
if (!(await this.relay.holderLive(h.id)))
|
|
286
|
-
throw deviceOffline();
|
|
287
|
-
const had = rootsOf(h);
|
|
288
|
-
const now = await this.targets.machineRoots(h.id);
|
|
289
|
-
if (had === undefined || (now !== null && !sameRoots(had, now)))
|
|
290
|
-
return "gone";
|
|
291
|
-
return "resumed";
|
|
292
|
-
}
|
|
293
|
-
async suspend(_h, signal) {
|
|
294
|
-
signal.throwIfAborted();
|
|
295
|
-
}
|
|
296
|
-
async destroy(_h, signal) {
|
|
297
|
-
signal.throwIfAborted();
|
|
298
|
-
}
|
|
299
|
-
async destroyByName(_name, signal) {
|
|
300
|
-
signal.throwIfAborted();
|
|
301
|
-
}
|
|
302
|
-
/** A v3 machine has no broad kill (permission runtime cutover B-1): nothing is queued. */
|
|
303
|
-
async killAll(_h, signal) {
|
|
304
|
-
signal.throwIfAborted();
|
|
305
|
-
}
|
|
306
|
-
async killTagged(_h, _tags, signal) {
|
|
307
|
-
signal.throwIfAborted();
|
|
308
|
-
}
|
|
309
|
-
// The raw protocol 2 methods: a v3 machine runs work only under an admitted operation scope
|
|
310
|
-
exec = refuseRaw("exec");
|
|
311
|
-
readFile = refuseRaw("readFile");
|
|
312
|
-
writeFile = refuseRaw("writeFile");
|
|
313
|
-
stat = refuseRaw("stat");
|
|
314
|
-
list = refuseRaw("list");
|
|
315
|
-
scan = refuseRaw("scan");
|
|
316
|
-
};
|
|
317
|
-
LocalDeviceProvider = __decorate([
|
|
318
|
-
Injectable(),
|
|
319
|
-
__param(0, Inject(LocalDeviceRelay)),
|
|
320
|
-
__param(1, Inject(DeviceTargets)),
|
|
321
|
-
__param(2, Inject(SandboxService)),
|
|
322
|
-
__param(3, Inject(KernelConfigService)),
|
|
323
|
-
__param(4, Optional()),
|
|
324
|
-
__param(4, Inject(PermissionCallGrants))
|
|
325
|
-
], LocalDeviceProvider);
|
|
326
|
-
export { LocalDeviceProvider };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type OnModuleInit } from "@nestjs/common";
|
|
2
|
-
import { type DeviceProviderEntry, DeviceProviders } from "../sandbox/providers.js";
|
|
3
|
-
import { LocalInstanceBindings } from "./instance-bindings.js";
|
|
4
|
-
import { LocalDeviceProvider } from "./local-device-provider.js";
|
|
5
|
-
import { LocalDeviceRelay } from "./relay.js";
|
|
6
|
-
/**
|
|
7
|
-
* Connected machines (environments spec §6, §13): the caller side of the device relay and the
|
|
8
|
-
* kernel-internal `@local` sandbox provider, registered with {@link DeviceProviders} on init, and
|
|
9
|
-
* the machines and their credentials ({@link MachinesService}), changes to a device's network
|
|
10
|
-
* policy ({@link DevicePolicyService}) and the run grants sent with each exec ({@link NetworkGrants}).
|
|
11
|
-
* Imported on every role: any replica may run a sandbox operation on a local device
|
|
12
|
-
* (the socket itself is held by the gateway role).
|
|
13
|
-
*/
|
|
14
|
-
export declare class LocalDevicesModule implements OnModuleInit {
|
|
15
|
-
private readonly providers;
|
|
16
|
-
private readonly provider;
|
|
17
|
-
private readonly relay;
|
|
18
|
-
private readonly bindings;
|
|
19
|
-
constructor(providers: DeviceProviders, provider: LocalDeviceProvider, relay: LocalDeviceRelay, bindings: LocalInstanceBindings);
|
|
20
|
-
onModuleInit(): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The `@local` registration: the protocol 4 provider ({@link LocalDeviceProvider.staged}: scoped
|
|
24
|
-
* operations, no broad kill) with its instance binder, which binds every committed generation
|
|
25
|
-
* before shared use (B-8).
|
|
26
|
-
*/
|
|
27
|
-
export declare function localProviderEntry(deps: {
|
|
28
|
-
provider: LocalDeviceProvider;
|
|
29
|
-
relay: LocalDeviceRelay;
|
|
30
|
-
bindings: LocalInstanceBindings;
|
|
31
|
-
}): DeviceProviderEntry;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
-
};
|
|
10
|
-
import { Inject, Module } from "@nestjs/common";
|
|
11
|
-
import { PermissionCallGrantsModule } from "../sandbox/permission-call-grants.module.js";
|
|
12
|
-
import { DeviceProviders, LOCAL_PROVIDER } from "../sandbox/providers.js";
|
|
13
|
-
import { SandboxProviderRegistryModule } from "../sandbox/providers.module.js";
|
|
14
|
-
import { SandboxModule } from "../sandbox/sandbox.module.js";
|
|
15
|
-
import { KERNEL_VERSION } from "../version.js";
|
|
16
|
-
import { DevicePolicyService } from "./device-policy.service.js";
|
|
17
|
-
import { LocalInstanceBindings } from "./instance-bindings.js";
|
|
18
|
-
import { LocalDeviceProvider } from "./local-device-provider.js";
|
|
19
|
-
import { MachinesService } from "./machines.js";
|
|
20
|
-
import { NetworkGrants } from "./network-grants.js";
|
|
21
|
-
import { NetworkGrantsModule } from "./network-grants.module.js";
|
|
22
|
-
import { OwnerReports } from "./owner-reports.js";
|
|
23
|
-
import { LocalDeviceRelay } from "./relay.js";
|
|
24
|
-
import { DeviceTargets } from "./targets.js";
|
|
25
|
-
/**
|
|
26
|
-
* Connected machines (environments spec §6, §13): the caller side of the device relay and the
|
|
27
|
-
* kernel-internal `@local` sandbox provider, registered with {@link DeviceProviders} on init, and
|
|
28
|
-
* the machines and their credentials ({@link MachinesService}), changes to a device's network
|
|
29
|
-
* policy ({@link DevicePolicyService}) and the run grants sent with each exec ({@link NetworkGrants}).
|
|
30
|
-
* Imported on every role: any replica may run a sandbox operation on a local device
|
|
31
|
-
* (the socket itself is held by the gateway role).
|
|
32
|
-
*/
|
|
33
|
-
let LocalDevicesModule = class LocalDevicesModule {
|
|
34
|
-
providers;
|
|
35
|
-
provider;
|
|
36
|
-
relay;
|
|
37
|
-
bindings;
|
|
38
|
-
constructor(providers, provider, relay, bindings) {
|
|
39
|
-
this.providers = providers;
|
|
40
|
-
this.provider = provider;
|
|
41
|
-
this.relay = relay;
|
|
42
|
-
this.bindings = bindings;
|
|
43
|
-
}
|
|
44
|
-
onModuleInit() {
|
|
45
|
-
this.providers.register(localProviderEntry({
|
|
46
|
-
provider: this.provider,
|
|
47
|
-
relay: this.relay,
|
|
48
|
-
bindings: this.bindings,
|
|
49
|
-
}));
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
LocalDevicesModule = __decorate([
|
|
53
|
-
Module({
|
|
54
|
-
imports: [
|
|
55
|
-
PermissionCallGrantsModule,
|
|
56
|
-
SandboxModule,
|
|
57
|
-
SandboxProviderRegistryModule,
|
|
58
|
-
NetworkGrantsModule,
|
|
59
|
-
],
|
|
60
|
-
providers: [
|
|
61
|
-
DeviceTargets,
|
|
62
|
-
LocalDeviceRelay,
|
|
63
|
-
LocalDeviceProvider,
|
|
64
|
-
MachinesService,
|
|
65
|
-
DevicePolicyService,
|
|
66
|
-
LocalInstanceBindings,
|
|
67
|
-
OwnerReports,
|
|
68
|
-
],
|
|
69
|
-
exports: [
|
|
70
|
-
NetworkGrantsModule,
|
|
71
|
-
LocalDeviceRelay,
|
|
72
|
-
LocalDeviceProvider,
|
|
73
|
-
MachinesService,
|
|
74
|
-
DevicePolicyService,
|
|
75
|
-
LocalInstanceBindings,
|
|
76
|
-
OwnerReports,
|
|
77
|
-
],
|
|
78
|
-
}),
|
|
79
|
-
__param(0, Inject(DeviceProviders)),
|
|
80
|
-
__param(1, Inject(LocalDeviceProvider)),
|
|
81
|
-
__param(2, Inject(LocalDeviceRelay)),
|
|
82
|
-
__param(3, Inject(LocalInstanceBindings))
|
|
83
|
-
], LocalDevicesModule);
|
|
84
|
-
export { LocalDevicesModule };
|
|
85
|
-
/**
|
|
86
|
-
* The `@local` registration: the protocol 4 provider ({@link LocalDeviceProvider.staged}: scoped
|
|
87
|
-
* operations, no broad kill) with its instance binder, which binds every committed generation
|
|
88
|
-
* before shared use (B-8).
|
|
89
|
-
*/
|
|
90
|
-
export function localProviderEntry(deps) {
|
|
91
|
-
return {
|
|
92
|
-
plugin: LOCAL_PROVIDER,
|
|
93
|
-
version: KERNEL_VERSION,
|
|
94
|
-
impl: deps.provider.staged({
|
|
95
|
-
call: deps.relay.callV3.bind(deps.relay),
|
|
96
|
-
permissionSupport: (deviceId) => deps.bindings.permissionSupport(deviceId),
|
|
97
|
-
}),
|
|
98
|
-
binder: deps.bindings,
|
|
99
|
-
};
|
|
100
|
-
}
|