@capybara-hq/kernel 0.1.0-rc.54 → 0.1.0-rc.55
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/dist/admin/admin.schemas.d.ts +11 -1
- package/dist/catalog/catalog.module.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/requests.service.d.ts +5 -5
- package/dist/catalog/requests.service.js +9 -9
- package/dist/channels/cards.d.ts +4 -3
- package/dist/channels/cards.js +25 -16
- package/dist/channels/phrases.d.ts +15 -4
- package/dist/channels/phrases.js +15 -1
- package/dist/config/load.d.ts +26 -7
- package/dist/config/load.js +60 -9
- package/dist/config/permission-migration.d.ts +17 -9
- package/dist/config/permission-migration.js +60 -9
- package/dist/config/schema.d.ts +11 -1
- package/dist/config/schema.js +37 -11
- package/dist/conversations/events.d.ts +247 -5
- package/dist/conversations/events.js +127 -16
- package/dist/conversations/permission-profiles.controller.d.ts +12 -2
- package/dist/conversations/permission-profiles.service.d.ts +12 -2
- package/dist/conversations/permission-profiles.service.js +11 -4
- package/dist/db/kernel-schema.d.ts +8 -2
- package/dist/devices/device-projects.service.d.ts +1 -1
- package/dist/devices/device-projects.service.js +6 -6
- package/dist/devices/devices.controller.d.ts +10 -8
- package/dist/devices/devices.controller.js +14 -18
- package/dist/devices/devices.schemas.d.ts +5 -5
- package/dist/devices/devices.schemas.js +5 -5
- package/dist/devices/devices.service.d.ts +188 -175
- package/dist/devices/devices.service.js +284 -292
- package/dist/devices/dto.d.ts +43 -23
- package/dist/devices/dto.js +45 -49
- package/dist/devices/project-rules.d.ts +0 -10
- package/dist/devices/project-rules.js +0 -5
- package/dist/errors.d.ts +24 -19
- package/dist/errors.js +24 -19
- package/dist/evals/reconstruct.d.ts +12 -3
- package/dist/evals/reconstruct.js +10 -6
- package/dist/evals/recorded-permission-context.d.ts +6 -4
- package/dist/evals/recorded-permission-context.js +15 -9
- package/dist/evals/run-replay.d.ts +6 -1
- package/dist/evals/run-replay.js +7 -2
- package/dist/evals/worker.js +3 -1
- package/dist/identity/settings.d.ts +45 -18
- package/dist/identity/settings.js +151 -51
- package/dist/infra/config/kernel-config.service.d.ts +1 -1
- package/dist/infra/config/kernel-config.service.js +17 -5
- package/dist/local-devices/device-auth.controller.d.ts +1 -1
- package/dist/local-devices/device-auth.controller.js +1 -1
- package/dist/local-devices/device-auth.d.ts +4 -4
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +18 -9
- package/dist/local-devices/device-policy.service.js +21 -61
- package/dist/local-devices/device-routes.d.ts +3 -1
- package/dist/local-devices/device-routes.js +15 -4
- package/dist/local-devices/instance-bindings.js +5 -2
- package/dist/local-devices/local-device-gateway.d.ts +2 -2
- package/dist/local-devices/local-device-gateway.js +3 -3
- package/dist/local-devices/local-device-provider.d.ts +4 -4
- package/dist/local-devices/local-device-provider.js +23 -9
- package/dist/local-devices/local-devices.module.d.ts +1 -1
- package/dist/local-devices/local-devices.module.js +1 -1
- package/dist/local-devices/machines.d.ts +40 -16
- package/dist/local-devices/machines.js +89 -61
- package/dist/local-devices/owner-report.d.ts +16 -14
- package/dist/local-devices/owner-report.js +24 -30
- package/dist/local-devices/owner-reports.js +26 -8
- package/dist/local-devices/policy-summary.d.ts +25 -44
- package/dist/local-devices/policy-summary.js +26 -71
- package/dist/local-devices/relay.d.ts +6 -6
- package/dist/local-devices/relay.js +10 -8
- package/dist/net/public-address.d.ts +1 -1
- package/dist/net/public-address.js +5 -2
- package/dist/orgs/device-network-setting.d.ts +82 -0
- package/dist/orgs/device-network-setting.js +142 -0
- package/dist/orgs/settings.service.d.ts +103 -66
- package/dist/orgs/settings.service.js +201 -137
- package/dist/overrides.d.ts +5 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +1 -1
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.js +20 -11
- package/dist/platform/ops/devices.ops.js +70 -5
- package/dist/platform/ops/org-settings.ops.js +10 -6
- package/dist/platform/ops/orgs.ops.js +2 -1
- package/dist/runtime/context/permission-profile.d.ts +17 -8
- package/dist/runtime/context/permission-profile.js +126 -45
- package/dist/runtime/permission-context.service.d.ts +1 -1
- package/dist/runtime/permission-context.service.js +5 -3
- package/dist/runtime/project/knowledge.d.ts +5 -4
- package/dist/runtime/project/knowledge.js +2 -1
- package/dist/runtime/project/knowledge.service.js +16 -13
- package/dist/sandbox/cloud-permission-snapshot.js +22 -3
- package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
- package/dist/sandbox/device-sandbox-settings.js +470 -0
- package/dist/sandbox/device-sandbox.d.ts +187 -0
- package/dist/sandbox/device-sandbox.js +236 -0
- package/dist/sandbox/held-operations.js +15 -7
- package/dist/sandbox/modes.d.ts +49 -24
- package/dist/sandbox/modes.js +27 -19
- package/dist/sandbox/operation-authority-types.d.ts +6 -5
- package/dist/sandbox/operation-authority-types.js +7 -8
- package/dist/sandbox/operation-authority.d.ts +23 -9
- package/dist/sandbox/operation-authority.js +179 -97
- package/dist/sandbox/permission-auto-grants.d.ts +42 -0
- package/dist/sandbox/permission-auto-grants.js +145 -0
- package/dist/sandbox/permission-call-grants.d.ts +12 -4
- package/dist/sandbox/permission-call-grants.js +84 -35
- package/dist/sandbox/permission-call-grants.module.js +10 -3
- package/dist/sandbox/permission-call-types.d.ts +39 -5
- package/dist/sandbox/permission-ceiling-writes.d.ts +29 -3
- package/dist/sandbox/permission-ceiling-writes.js +38 -4
- package/dist/sandbox/permission-config-publication.d.ts +44 -2
- package/dist/sandbox/permission-config-publication.js +230 -59
- package/dist/sandbox/permission-context-types.d.ts +2 -2
- package/dist/sandbox/permission-facts.d.ts +144 -15
- package/dist/sandbox/permission-facts.js +258 -70
- package/dist/sandbox/permission-runtime-reports.d.ts +5 -4
- package/dist/sandbox/permission-runtime-reports.js +19 -29
- package/dist/sandbox/review/classifier.d.ts +8 -0
- package/dist/sandbox/review/classifier.js +10 -0
- package/dist/sandbox/review/permission-candidate.d.ts +69 -5
- package/dist/sandbox/review/permission-candidate.js +153 -30
- package/dist/sandbox/review/review.service.d.ts +19 -3
- package/dist/sandbox/review/review.service.js +59 -11
- package/dist/sandbox/review/rules.js +23 -3
- package/dist/sandbox/sandbox.service.d.ts +29 -11
- package/dist/sandbox/sandbox.service.js +51 -26
- package/dist/skills/invoke.js +3 -2
- package/dist/tools/approvals.service.d.ts +26 -116
- package/dist/tools/approvals.service.js +42 -346
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
- package/dist/tools/builtins/sandbox/bash.js +80 -28
- package/dist/tools/builtins/sandbox/common.d.ts +39 -14
- package/dist/tools/builtins/sandbox/common.js +47 -24
- package/dist/tools/builtins/sandbox/deliver.js +7 -4
- package/dist/tools/builtins/skill-load.d.ts +2 -2
- package/dist/tools/builtins/skill-load.js +4 -3
- package/dist/tools/device-op-resolver.d.ts +4 -10
- package/dist/tools/device-op-resolver.js +8 -19
- package/dist/tools/network-asks.d.ts +52 -15
- package/dist/tools/network-asks.js +55 -25
- package/dist/tools/pipeline.d.ts +26 -14
- package/dist/tools/pipeline.js +144 -61
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/tools.module.js +1 -1
- package/package.json +4 -4
- package/src/migrations/0165_device_network_columns.sql +50 -0
- package/src/migrations/0166_permission_grant_full_access.sql +17 -0
- package/src/migrations/0167_device_network_backfill.sql +32 -0
- package/src/migrations/0168_binding_installed_connection.sql +6 -0
- package/dist/orgs/cloud-network-setting.d.ts +0 -33
- package/dist/orgs/cloud-network-setting.js +0 -47
- package/dist/sandbox/platform-full-access.d.ts +0 -110
- package/dist/sandbox/platform-full-access.js +0 -198
|
@@ -14,10 +14,11 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
|
14
14
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
15
15
|
import type { KernelLogger } from "../log.js";
|
|
16
16
|
import { CloudPermissionSnapshots, type CloudSnapshotOutcome } from "./cloud-permission-snapshot.js";
|
|
17
|
+
import type { DeviceSandbox, HostGrantCeiling } from "./device-sandbox.js";
|
|
17
18
|
import { type KernelReadInvocation } from "./kernel-read.js";
|
|
18
19
|
import { SandboxLeases, type SandboxPathLease } from "./leases.js";
|
|
19
20
|
import { LegacyRetirementStore } from "./legacy-retirement.js";
|
|
20
|
-
import { type AppliedLimits, type EffectiveDevicePolicy } from "./modes.js";
|
|
21
|
+
import { type AppliedLimits, type DeviceLimits, type EffectiveDevicePolicy } from "./modes.js";
|
|
21
22
|
import type { HeldDeviceContextEvidence } from "./permission-context-types.js";
|
|
22
23
|
import { PermissionFacts } from "./permission-facts.js";
|
|
23
24
|
import { SandboxProviders } from "./providers.js";
|
|
@@ -273,7 +274,7 @@ export declare class SandboxService {
|
|
|
273
274
|
/** The record of the instance each holder last used (`capk:sandbox-seen:…`). */
|
|
274
275
|
redis: Pick<Redis, "get" | "set" | "getdel">, leases: SandboxLeases,
|
|
275
276
|
/** The providers (read at every call: providers are ready after the extension load). */
|
|
276
|
-
providers: Pick<SandboxProviders, "cloud" | "forName">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
|
|
277
|
+
providers: Pick<SandboxProviders, "cloud" | "forName">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment" | "readDevice" | "deviceSandbox" | "deviceSandboxFacts" | "orgHostGrantCeiling">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
|
|
277
278
|
/** The retirement obligations every lifecycle acquisition is gated on (8.5). */
|
|
278
279
|
retirement: Pick<LegacyRetirementStore, "unresolved" | "hasUnresolved" | "settleRebooted" | "scanUntilStable" | "frozen" | "frozenAt" | "quarantine" | "noteFailure" | "resolveDestroyed" | "resolveCancelled" | "membersOf" | "recordDestruction" | "destructionRecorded">,
|
|
279
280
|
/** The cloud snapshot writer's reconcile, for the lifecycle reconcile of marked devices (B-12). */
|
|
@@ -307,15 +308,19 @@ export declare class SandboxService {
|
|
|
307
308
|
orgId: string;
|
|
308
309
|
deviceId?: string;
|
|
309
310
|
}): Promise<EffectiveDevicePolicy>;
|
|
311
|
+
/** The device's per-call host grant ceiling (`PermissionFacts.readDevice`). */
|
|
312
|
+
hostGrantCeiling(device: {
|
|
313
|
+
orgId: string;
|
|
314
|
+
deviceId: string;
|
|
315
|
+
}): Promise<HostGrantCeiling>;
|
|
310
316
|
/** The device's source (`local` for a connected machine, else `cloud`); cloud when unknown. */
|
|
311
317
|
private deviceSource;
|
|
312
318
|
/**
|
|
313
319
|
* The device's effective sandbox limits (spec §8.4; auto mode spec §4.2): the deployment's
|
|
314
320
|
* `sandbox.limits` resources, cpu / memory per the super admin's org override (C19 / Ruling
|
|
315
|
-
* M16), the effective mode and the network ({@link devicePolicy})
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* policy and source queries).
|
|
321
|
+
* M16), the effective mode and the device sandbox network ({@link devicePolicy}), for a local
|
|
322
|
+
* device too: the machine intersects it with its owner's ceiling. `opts.policy` / `opts.source`:
|
|
323
|
+
* what the caller already read (avoids the policy and source queries).
|
|
319
324
|
*/
|
|
320
325
|
deviceLimits(device: {
|
|
321
326
|
orgId: string;
|
|
@@ -323,13 +328,26 @@ export declare class SandboxService {
|
|
|
323
328
|
}, opts?: {
|
|
324
329
|
policy?: EffectiveDevicePolicy;
|
|
325
330
|
source?: "cloud" | "local";
|
|
326
|
-
}): Promise<
|
|
331
|
+
}): Promise<DeviceLimits>;
|
|
327
332
|
/**
|
|
328
|
-
* The org's
|
|
329
|
-
*
|
|
330
|
-
*
|
|
333
|
+
* The org's limits for a standing network grant (a scheduled task's grant, a network approval):
|
|
334
|
+
* {@link deviceLimits} with the org's per-call host ceiling as an allowlist (`hostGrantCeiling`
|
|
335
|
+
* with no device). Where that ceiling is bounded by the kernel only (`any`, which an allowlist
|
|
336
|
+
* cannot carry with its exclusions), the org's effective hosts: a standing grant never reaches
|
|
337
|
+
* past what the org lists. A device's own layers narrow it further at each exec.
|
|
331
338
|
*/
|
|
332
339
|
ceilingLimits(orgId: string): Promise<SandboxLimits>;
|
|
340
|
+
/**
|
|
341
|
+
* Why a per-call host grant for each host is unavailable on the device, naming who can add it
|
|
342
|
+
* (`hostGrantRefusal`; null: grantable): a network ask is made only for a grantable host.
|
|
343
|
+
*/
|
|
344
|
+
hostRefusal(device: {
|
|
345
|
+
orgId: string;
|
|
346
|
+
deviceId: string;
|
|
347
|
+
}): Promise<{
|
|
348
|
+
refusal: (host: string) => string | null;
|
|
349
|
+
box: DeviceSandbox;
|
|
350
|
+
}>;
|
|
333
351
|
/**
|
|
334
352
|
* The limits state of a device's instance for its page (auto mode spec §4.2), read without a
|
|
335
353
|
* lease: `applied` is what the instance or file system was made with or updated to (null:
|
|
@@ -354,7 +372,7 @@ export declare class SandboxService {
|
|
|
354
372
|
private fsBound;
|
|
355
373
|
/**
|
|
356
374
|
* Whether the running instance of `row` must get `want` before use (auto mode spec §4.2): a
|
|
357
|
-
* cloud instance whose recorded
|
|
375
|
+
* cloud instance whose recorded network kind differs (never the mode alone), or whose recorded limits are more
|
|
358
376
|
* permissive than `want` in any dimension (a host-only narrowing too, spec §124; a host-only
|
|
359
377
|
* widening still reaches instances created afterwards), unless only a file reset could apply it
|
|
360
378
|
* ({@link fsBound}). A provider bound to its file system still goes through the exclusive lease
|
|
@@ -8,7 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { posix } from "node:path";
|
|
11
|
-
import {
|
|
11
|
+
import { isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, parseSandboxBrowseScope, parseSandboxExecutionRef, parseSandboxOperationScope, parseSandboxPreparationScope, SandboxOperationOutcomeUnknownError, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, } from "@capybara-hq/plugin-sdk";
|
|
12
12
|
import { runOutsideTransaction } from "../infra/database/transaction-host.js";
|
|
13
13
|
import { createHeldOperations, createLegacyHeldProvider, withKernelGeneration, } from "./held-operations.js";
|
|
14
14
|
import { SandboxOperationAuthority } from "./operation-authority.js";
|
|
@@ -43,7 +43,7 @@ import { readSandboxLimitOverride } from "../identity/settings.js";
|
|
|
43
43
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
44
44
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
45
45
|
import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
|
|
46
|
-
import { effectiveSandboxLimits } from "../orgs/settings.service.js";
|
|
46
|
+
import { effectiveSandboxLimits, readOrgSettings } from "../orgs/settings.service.js";
|
|
47
47
|
import { isStorageError } from "../runtime/permission-context-errors.js";
|
|
48
48
|
import { canonicalJson } from "../tools/canonical-json.js";
|
|
49
49
|
import { attachmentsDir } from "./attachments-path.js";
|
|
@@ -52,8 +52,8 @@ import { isKernelReadMethod, KernelReadNotAdmitted, KernelReadUnsupported, } fro
|
|
|
52
52
|
import { SandboxLeases, SandboxLockLostError, sandboxBusy, } from "./leases.js";
|
|
53
53
|
import { isCloudProvider, LegacyRetirementStore } from "./legacy-retirement.js";
|
|
54
54
|
import { ManagedDeviceContextFailed } from "./managed-device-context.js";
|
|
55
|
-
import { appliedOf, appliedWider, instanceLimitsJson, readInstanceLimits, sameApplied, sameAppliedExact, sameAppliedExactly, } from "./modes.js";
|
|
56
|
-
import { PermissionFacts } from "./permission-facts.js";
|
|
55
|
+
import { appliedOf, appliedWider, instanceLimitsJson, orgEffectiveHosts, providerLimits, readInstanceLimits, sameApplied, sameAppliedExact, sameAppliedExactly, } from "./modes.js";
|
|
56
|
+
import { networkOfSandbox, PermissionFacts } from "./permission-facts.js";
|
|
57
57
|
import { cloudReportOwed, cloudSupportOf } from "./permission-runtime-reports.js";
|
|
58
58
|
import { isInternalProvider, LOCAL_PROVIDER, providerForDevice, SandboxProviders, } from "./providers.js";
|
|
59
59
|
import { isDeviceRequestNotSent } from "./request-not-sent.js";
|
|
@@ -202,16 +202,16 @@ export function sandboxConfigWarnings(cfg, providerPlugin) {
|
|
|
202
202
|
if (pc?.refuseOpenNetwork === true) {
|
|
203
203
|
out.push({
|
|
204
204
|
level: "warn",
|
|
205
|
-
message: `extensionConfig."${providerPlugin}".refuseOpenNetwork is true: the ${providerPlugin} plugin refuses cloud devices on the open public network, which every device
|
|
205
|
+
message: `extensionConfig."${providerPlugin}".refuseOpenNetwork is true: the ${providerPlugin} plugin refuses cloud devices on the open public network, which every device uses whose network is open (devices.network.default, open by default, and an organization's deviceNetwork); set refuseOpenNetwork to false, or set devices.network.ceiling to allowlist`,
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
if (cfg.sandbox.limits.orgHosts === "within" &&
|
|
210
210
|
cfg.sandbox.limits.egress !== "none" &&
|
|
211
|
-
cfg.devices?.
|
|
211
|
+
cfg.devices?.network?.ceiling !== "allowlist") {
|
|
212
212
|
out.push({
|
|
213
213
|
level: "warn",
|
|
214
|
-
message: "sandbox.limits.orgHosts is within but devices.
|
|
214
|
+
message: "sandbox.limits.orgHosts is within but devices.network.ceiling is not allowlist: the platform allowlist limits the hosts of the allowlist only; devices on the open network (the default) still reach any public host. Set devices.network.ceiling to allowlist (or in the admin console) for a hard ceiling",
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
217
|
const run = cfg.runtime.maxRunSeconds;
|
|
@@ -379,6 +379,10 @@ let SandboxService = class SandboxService {
|
|
|
379
379
|
async devicePolicy(device) {
|
|
380
380
|
return this.facts.devicePolicy(device);
|
|
381
381
|
}
|
|
382
|
+
/** The device's per-call host grant ceiling (`PermissionFacts.readDevice`). */
|
|
383
|
+
async hostGrantCeiling(device) {
|
|
384
|
+
return (await this.facts.readDevice(device.orgId, device.deviceId)).hostCeiling;
|
|
385
|
+
}
|
|
382
386
|
/** The device's source (`local` for a connected machine, else `cloud`); cloud when unknown. */
|
|
383
387
|
async deviceSource(device) {
|
|
384
388
|
if (device.deviceId === undefined)
|
|
@@ -394,10 +398,9 @@ let SandboxService = class SandboxService {
|
|
|
394
398
|
/**
|
|
395
399
|
* The device's effective sandbox limits (spec §8.4; auto mode spec §4.2): the deployment's
|
|
396
400
|
* `sandbox.limits` resources, cpu / memory per the super admin's org override (C19 / Ruling
|
|
397
|
-
* M16), the effective mode and the network ({@link devicePolicy})
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
* policy and source queries).
|
|
401
|
+
* M16), the effective mode and the device sandbox network ({@link devicePolicy}), for a local
|
|
402
|
+
* device too: the machine intersects it with its owner's ceiling. `opts.policy` / `opts.source`:
|
|
403
|
+
* what the caller already read (avoids the policy and source queries).
|
|
401
404
|
*/
|
|
402
405
|
async deviceLimits(device, opts = {}) {
|
|
403
406
|
const cfg = this.config.get().sandbox;
|
|
@@ -407,8 +410,10 @@ let SandboxService = class SandboxService {
|
|
|
407
410
|
opts.source ?? this.deviceSource(device),
|
|
408
411
|
]);
|
|
409
412
|
const local = source === "local";
|
|
410
|
-
|
|
411
|
-
|
|
413
|
+
// a local device's commands carry its device sandbox network (under the machine's current
|
|
414
|
+
// runtime report, as admission reads it); the machine intersects it with its owner's ceiling
|
|
415
|
+
const network = local && device.deviceId !== undefined
|
|
416
|
+
? networkOfSandbox(await this.facts.deviceSandbox(device.orgId, device.deviceId))
|
|
412
417
|
: policy.network;
|
|
413
418
|
return effectiveSandboxLimits({
|
|
414
419
|
cpu: cfg.limits.cpu,
|
|
@@ -421,24 +426,37 @@ let SandboxService = class SandboxService {
|
|
|
421
426
|
}, override);
|
|
422
427
|
}
|
|
423
428
|
/**
|
|
424
|
-
* The org's
|
|
425
|
-
*
|
|
426
|
-
*
|
|
429
|
+
* The org's limits for a standing network grant (a scheduled task's grant, a network approval):
|
|
430
|
+
* {@link deviceLimits} with the org's per-call host ceiling as an allowlist (`hostGrantCeiling`
|
|
431
|
+
* with no device). Where that ceiling is bounded by the kernel only (`any`, which an allowlist
|
|
432
|
+
* cannot carry with its exclusions), the org's effective hosts: a standing grant never reaches
|
|
433
|
+
* past what the org lists. A device's own layers narrow it further at each exec.
|
|
427
434
|
*/
|
|
428
435
|
async ceilingLimits(orgId) {
|
|
429
|
-
const [
|
|
430
|
-
this.
|
|
436
|
+
const [ceiling, override, { deviceNetwork: org }] = await Promise.all([
|
|
437
|
+
this.facts.orgHostGrantCeiling(orgId),
|
|
431
438
|
readSandboxLimitOverride(this.db.db, orgId),
|
|
439
|
+
readOrgSettings(this.db.db, orgId),
|
|
432
440
|
]);
|
|
433
441
|
const cfg = this.config.get().sandbox;
|
|
434
442
|
return effectiveSandboxLimits({
|
|
435
443
|
cpu: cfg.limits.cpu,
|
|
436
444
|
memoryMb: cfg.limits.memoryMb,
|
|
437
445
|
diskMb: cfg.limits.diskMb,
|
|
438
|
-
|
|
439
|
-
|
|
446
|
+
network: {
|
|
447
|
+
kind: "allowlist",
|
|
448
|
+
hosts: ceiling.kind === "any" ? orgEffectiveHosts(cfg.limits, org) : [...ceiling.hosts],
|
|
449
|
+
},
|
|
440
450
|
}, override);
|
|
441
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* Why a per-call host grant for each host is unavailable on the device, naming who can add it
|
|
454
|
+
* (`hostGrantRefusal`; null: grantable): a network ask is made only for a grantable host.
|
|
455
|
+
*/
|
|
456
|
+
async hostRefusal(device) {
|
|
457
|
+
const facts = await this.facts.deviceSandboxFacts(device.orgId, device.deviceId);
|
|
458
|
+
return { refusal: facts.refusal, box: facts.box };
|
|
459
|
+
}
|
|
442
460
|
/**
|
|
443
461
|
* The limits state of a device's instance for its page (auto mode spec §4.2), read without a
|
|
444
462
|
* lease: `applied` is what the instance or file system was made with or updated to (null:
|
|
@@ -490,7 +508,7 @@ let SandboxService = class SandboxService {
|
|
|
490
508
|
}
|
|
491
509
|
/**
|
|
492
510
|
* Whether the running instance of `row` must get `want` before use (auto mode spec §4.2): a
|
|
493
|
-
* cloud instance whose recorded
|
|
511
|
+
* cloud instance whose recorded network kind differs (never the mode alone), or whose recorded limits are more
|
|
494
512
|
* permissive than `want` in any dimension (a host-only narrowing too, spec §124; a host-only
|
|
495
513
|
* widening still reaches instances created afterwards), unless only a file reset could apply it
|
|
496
514
|
* ({@link fsBound}). A provider bound to its file system still goes through the exclusive lease
|
|
@@ -1983,7 +2001,7 @@ let SandboxService = class SandboxService {
|
|
|
1983
2001
|
// suspended: a failure is revoked again on the next resume)
|
|
1984
2002
|
if (suspended)
|
|
1985
2003
|
await this.revokeIncarnation(deviceId, { provider: p.plugin, generation: String(row.created_at.getTime()) }, handle, p, sig, false);
|
|
1986
|
-
answer = await update(handle, want, sig);
|
|
2004
|
+
answer = await update(handle, providerLimits(want), sig);
|
|
1987
2005
|
}
|
|
1988
2006
|
}
|
|
1989
2007
|
catch (err) {
|
|
@@ -2721,11 +2739,16 @@ let SandboxService = class SandboxService {
|
|
|
2721
2739
|
async create(ctx, p, held, row, fence, signal, want) {
|
|
2722
2740
|
const id = ctx.deviceId;
|
|
2723
2741
|
const name = deviceResourceName(id);
|
|
2742
|
+
// the roots the device's authority was last committed with; a device that never had an
|
|
2743
|
+
// instance has none yet (NULL), so the first commit compares the new instance's roots with
|
|
2744
|
+
// what the device displayed (a local machine's reported roots), not with placeholder defaults
|
|
2745
|
+
// a local machine never uses: its first start is no roots change (no consent reset, no revoke)
|
|
2746
|
+
const committedRoots = row.permission_roots ?? (row.handle ? rootsOf(row.handle) : null);
|
|
2724
2747
|
await this.fenced(held, id, fence, {
|
|
2725
2748
|
org_id: ctx.orgId,
|
|
2726
2749
|
provider: p.plugin,
|
|
2727
2750
|
handle: null,
|
|
2728
|
-
permission_roots:
|
|
2751
|
+
permission_roots: committedRoots === null ? null : JSON.stringify(committedRoots),
|
|
2729
2752
|
status: "creating",
|
|
2730
2753
|
last_used_at: sql `now()`,
|
|
2731
2754
|
running_since: null,
|
|
@@ -2735,13 +2758,15 @@ let SandboxService = class SandboxService {
|
|
|
2735
2758
|
});
|
|
2736
2759
|
// the device's effective limits apply at creation (a changed mode or network kind is applied
|
|
2737
2760
|
// on use, see applyLimits; other changes reach only instances created afterwards)
|
|
2738
|
-
const
|
|
2761
|
+
const wanted = want ??
|
|
2739
2762
|
(await this.deviceLimits(ctx, {
|
|
2740
2763
|
source: p.plugin === LOCAL_PROVIDER ? "local" : "cloud",
|
|
2741
2764
|
}));
|
|
2742
2765
|
// the record says what is in force: a provider whose limits are fixed at its file system
|
|
2743
2766
|
// records them with the file system, any other with the instance (spec §7.1)
|
|
2744
|
-
const record = instanceLimitsJson(appliedOf(
|
|
2767
|
+
const record = instanceLimitsJson(appliedOf(wanted));
|
|
2768
|
+
// the provider gets resources and the outer network only
|
|
2769
|
+
const limits = providerLimits(wanted);
|
|
2745
2770
|
const atFileSystem = p.impl.limitsApplyAt === "fileSystem";
|
|
2746
2771
|
const cfg = this.config.get().sandbox;
|
|
2747
2772
|
let fs = row.fs_status === "ready" && (row.provider === null || row.provider === p.plugin)
|
|
@@ -2841,7 +2866,7 @@ let SandboxService = class SandboxService {
|
|
|
2841
2866
|
let gone = false;
|
|
2842
2867
|
if (p.impl.update) {
|
|
2843
2868
|
try {
|
|
2844
|
-
if ((await p.impl.update(handle, want, signal)) === "updated") {
|
|
2869
|
+
if ((await p.impl.update(handle, providerLimits(want), signal)) === "updated") {
|
|
2845
2870
|
await this.fenced(held, id, fence, { instance_limits: instanceLimitsJson(target) });
|
|
2846
2871
|
this.log.info("sandbox instance limits updated", facts);
|
|
2847
2872
|
return null;
|
package/dist/skills/invoke.js
CHANGED
|
@@ -25,7 +25,7 @@ import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
|
25
25
|
import { SandboxProviderUnreachableError } from "../sandbox/unreachable.js";
|
|
26
26
|
import { StorageService } from "../storage/storage.service.js";
|
|
27
27
|
import { BUILTIN } from "../tools/builtin-names.js";
|
|
28
|
-
import { sessionWorkingRoot } from "../tools/builtins/sandbox/common.js";
|
|
28
|
+
import { sessionPathBound, sessionWorkingRoot } from "../tools/builtins/sandbox/common.js";
|
|
29
29
|
import { findSkillVersion, PROJECT_DIR_DIGEST, ProjectSkillReadError, readProjectSkill, readSkillFile, SkillIntegrityError, } from "../tools/builtins/skill-load.js";
|
|
30
30
|
import { invocationOf, resolveSkills } from "./catalog.js";
|
|
31
31
|
import { skillFileStore } from "./usable.js";
|
|
@@ -429,7 +429,8 @@ let SkillInvoker = class SkillInvoker {
|
|
|
429
429
|
actor: { accountId: a.accountId, conversationId: a.conversationId },
|
|
430
430
|
}, (h, p, info, signal) => readProjectSkill({
|
|
431
431
|
deviceId,
|
|
432
|
-
mode
|
|
432
|
+
// the legacy route (gate off): the fixed roots unless the device runs in auto mode
|
|
433
|
+
pathBound: sessionPathBound(false, mode),
|
|
433
434
|
h,
|
|
434
435
|
roots: info.roots,
|
|
435
436
|
// the working root a tool call of this conversation would get (one rule)
|
|
@@ -6,7 +6,6 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
6
6
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
7
7
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
8
8
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
9
|
-
import { DevicePolicyService, type PolicyOpResult } from "../local-devices/device-policy.service.js";
|
|
10
9
|
import { type OrgRole } from "../orgs/roles.js";
|
|
11
10
|
import { RunResume } from "../runtime/run-jobs.js";
|
|
12
11
|
import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
|
|
@@ -66,30 +65,8 @@ export interface NetworkAskDetail {
|
|
|
66
65
|
result: KeptToolResult;
|
|
67
66
|
/** The hosts the decision allowed (every approved decision writes them; none: nothing). */
|
|
68
67
|
grantedHosts?: string[];
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
* the device could not be reached or lacks the feature (`once_fallback`), or nothing because the
|
|
72
|
-
* device refused the change (`refused`: its owner takes no remote grants; no run grant either).
|
|
73
|
-
*/
|
|
74
|
-
outcome?: "once" | "always" | "once_fallback" | "refused";
|
|
75
|
-
/** Why 「一直允许」 did not reach the device's policy. */
|
|
76
|
-
fallback?: "offline" | "refused" | "unsupported";
|
|
77
|
-
/**
|
|
78
|
-
* Set while the ask is still pending: the last 「一直允许」 whose device change was recorded only
|
|
79
|
-
* after a crash (transactional outbox spec §7.4) and did not take effect: `failed` (the device
|
|
80
|
-
* refused it, never received it or stopped while applying it) or `unknown` (the device did not
|
|
81
|
-
* answer; its next connection tells), with the reason. The owner may decide again.
|
|
82
|
-
*/
|
|
83
|
-
attempt?: NetworkAskAttempt;
|
|
84
|
-
}
|
|
85
|
-
/** Why a pending network ask's last 「一直允许」 did not decide it ({@link NetworkAskDetail.attempt}). */
|
|
86
|
-
export interface NetworkAskAttempt {
|
|
87
|
-
/**
|
|
88
|
-
* `applied_undecided`: the device applied the change, but the account that chose it can no
|
|
89
|
-
* longer decide this ask (someone else must).
|
|
90
|
-
*/
|
|
91
|
-
outcome: "failed" | "unknown" | "applied_undecided";
|
|
92
|
-
message: string;
|
|
68
|
+
/** What took effect: a run grant (`once`, the only decision under device protocol 4). */
|
|
69
|
+
outcome?: "once";
|
|
93
70
|
}
|
|
94
71
|
/** A network ask's detail as the API shows it: without the kept command result. */
|
|
95
72
|
export type NetworkAskView = Omit<NetworkAskDetail, "result">;
|
|
@@ -130,11 +107,14 @@ export interface CommandAskDetail {
|
|
|
130
107
|
deviceId: string;
|
|
131
108
|
deviceName: string;
|
|
132
109
|
mode: "auto" | "sandbox";
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
110
|
+
/**
|
|
111
|
+
* A shell command (`Bash`), a file write outside the scope (`Write` / `Edit`) or a file read
|
|
112
|
+
* outside it (`Read`).
|
|
113
|
+
*/
|
|
114
|
+
kind: "command" | "write" | "read";
|
|
115
|
+
/** The command text (clipped), or the tool key of the write or read. */
|
|
136
116
|
command: string;
|
|
137
|
-
/** A write's target path. */
|
|
117
|
+
/** A write's or read's target path. */
|
|
138
118
|
path?: string;
|
|
139
119
|
/**
|
|
140
120
|
* The working root the call was reviewed against (project root spec §4.3), always recorded (the
|
|
@@ -304,18 +284,26 @@ export interface NetworkAskInput {
|
|
|
304
284
|
callId: string;
|
|
305
285
|
/** The device owner: the only person who may decide. */
|
|
306
286
|
requestedFor: string;
|
|
307
|
-
detail: Omit<NetworkAskDetail, "grantedHosts" | "outcome"
|
|
308
|
-
/**
|
|
309
|
-
|
|
287
|
+
detail: Omit<NetworkAskDetail, "grantedHosts" | "outcome">;
|
|
288
|
+
/**
|
|
289
|
+
* Always `["once"]`: a run grant (approval-only profiles design). The deployment never adds a
|
|
290
|
+
* host to a local device's own allowlist (device protocol 4), so "always" is never offered.
|
|
291
|
+
*/
|
|
292
|
+
scopes: "once"[];
|
|
310
293
|
}
|
|
311
294
|
/** The tool key a network ask is recorded under (the command ran in `Bash`). */
|
|
312
295
|
export declare const NETWORK_ASK_TOOL_KEY = "Bash";
|
|
313
296
|
/** The tool key a git ask is recorded under (the push ran in a `Bash` command). */
|
|
314
297
|
export declare const GIT_ASK_TOOL_KEY = "Bash";
|
|
315
|
-
/**
|
|
298
|
+
/**
|
|
299
|
+
* The tool key a command ask is recorded under (a command runs in `Bash`; a write under `Write`, a
|
|
300
|
+
* read under `Read`).
|
|
301
|
+
*/
|
|
316
302
|
export declare const COMMAND_ASK_TOOL_KEY = "Bash";
|
|
317
303
|
/** The tool key a file-write ask is recorded under. */
|
|
318
304
|
export declare const COMMAND_WRITE_TOOL_KEY = "Write";
|
|
305
|
+
/** The tool key a file-read ask is recorded under. */
|
|
306
|
+
export declare const COMMAND_READ_TOOL_KEY = "Read";
|
|
319
307
|
/** A new git push ask (sandbox git credentials spec §7), made by the tool pipeline. */
|
|
320
308
|
export interface GitAskInput {
|
|
321
309
|
orgId: string;
|
|
@@ -358,12 +346,7 @@ export declare class ApprovalsService {
|
|
|
358
346
|
private readonly schedules;
|
|
359
347
|
/** A trial approval is kept only for a tool the task may hold as a grant (its agent's tools). */
|
|
360
348
|
private readonly registry;
|
|
361
|
-
/**
|
|
362
|
-
* 「这台设备一直允许」 records the device change's intent, sends the `policy` op, then records
|
|
363
|
-
* its outcome with the decision.
|
|
364
|
-
*/
|
|
365
|
-
private readonly policies;
|
|
366
|
-
/** One decision of a network ask at a time, across replicas (the op is sent before the transaction). */
|
|
349
|
+
/** One decision of a network ask at a time, across replicas. */
|
|
367
350
|
readonly lockService: LockService;
|
|
368
351
|
/** A trial run's 「这次允许」 becomes a task grant only within the org's egress. */
|
|
369
352
|
private readonly sandbox;
|
|
@@ -374,12 +357,7 @@ export declare class ApprovalsService {
|
|
|
374
357
|
constructor(db: KernelDb, config: Pick<KernelConfigService, "get">, eventLog: Pick<EventLog, "appendIn" | "notify">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost, schedules: Pick<ScheduledTaskStore, "addGrant">,
|
|
375
358
|
/** A trial approval is kept only for a tool the task may hold as a grant (its agent's tools). */
|
|
376
359
|
registry: Pick<ToolRegistry, "forAgent">,
|
|
377
|
-
/**
|
|
378
|
-
* 「这台设备一直允许」 records the device change's intent, sends the `policy` op, then records
|
|
379
|
-
* its outcome with the decision.
|
|
380
|
-
*/
|
|
381
|
-
policies: Pick<DevicePolicyService, "begin" | "send" | "settleIn" | "summary" | "lockMachineDevice">,
|
|
382
|
-
/** One decision of a network ask at a time, across replicas (the op is sent before the transaction). */
|
|
360
|
+
/** One decision of a network ask at a time, across replicas. */
|
|
383
361
|
lockService: LockService,
|
|
384
362
|
/** A trial run's 「这次允许」 becomes a task grant only within the org's egress. */
|
|
385
363
|
sandbox: Pick<SandboxService, "ceilingLimits">,
|
|
@@ -434,13 +412,9 @@ export declare class ApprovalsService {
|
|
|
434
412
|
* A network ask's decision (network ask-to-allow spec §5.2), one at a time per ask across
|
|
435
413
|
* replicas: only the device owner (`requested_for`) decides, in a signed-in session (a personal
|
|
436
414
|
* access token is refused; the route already refuses service and embed tokens); the allowed
|
|
437
|
-
* hosts are a subset of those asked.
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
* remote grants) as `always` with outcome `refused` and nothing granted; the decision and the
|
|
441
|
-
* op's outcome are one transaction. Every decision resumes the run in its transaction and is
|
|
442
|
-
* announced after the commit; a change the device applied after the ask closed is audited
|
|
443
|
-
* (`late`) and answered with a 409 that says so.
|
|
415
|
+
* hosts are a subset of those asked. The decision is a run grant only (`once`): under device
|
|
416
|
+
* protocol 4 the deployment never adds a host to a local device, so `always` is refused. Every
|
|
417
|
+
* decision resumes the run in its transaction and is announced after the commit.
|
|
444
418
|
*/
|
|
445
419
|
private decideNetwork;
|
|
446
420
|
/**
|
|
@@ -461,70 +435,6 @@ export declare class ApprovalsService {
|
|
|
461
435
|
*/
|
|
462
436
|
private decideCommand;
|
|
463
437
|
private commandSubject;
|
|
464
|
-
/**
|
|
465
|
-
* 「这台设备一直允许」 (transactional outbox spec §7): the intent of the device change (naming the
|
|
466
|
-
* ask) is recorded, the `policy` op sent (no transaction open), then {@link settleNetworkOp}
|
|
467
|
-
* decides the ask and records the op's outcome in one transaction. When nothing could be sent
|
|
468
|
-
* (the device is offline, deleted, or its program lacks the feature) the decision is a run
|
|
469
|
-
* grant with the reason. The device's answer decides: applied → `always`; refused → `always`
|
|
470
|
-
* with outcome `refused`, nothing granted; no answer → a run grant (`once_fallback`, `offline`)
|
|
471
|
-
* while the op stays `unknown` for the machine's next hello or the resolver. A device that
|
|
472
|
-
* reconnects during the call and reports the op applied lets the resolver approve the ask as
|
|
473
|
-
* this owner first: that decision is returned (`toSeq` null: already announced), never a 409;
|
|
474
|
-
* when it granted other hosts than this call's (another of the owner's changes) and this call's
|
|
475
|
-
* change was not confirmed, `approval.already_decided` says so. A device deleted during the
|
|
476
|
-
* call is `device.not_found` (the op recorded unknown).
|
|
477
|
-
*/
|
|
478
|
-
private decideAlways;
|
|
479
|
-
/** Records only the op's outcome, in its own transaction (the ask is left as it is). */
|
|
480
|
-
private settleOpOnly;
|
|
481
|
-
/**
|
|
482
|
-
* {@link settleNetworkOp} with the device's permission authority lock as its ordered prelude
|
|
483
|
-
* (`DevicePolicyService.lockMachineDevice`): the global order puts it before the ask's
|
|
484
|
-
* conversation row, as a fenced device writer of the same tree takes it (device project writes).
|
|
485
|
-
*/
|
|
486
|
-
private settleNetworkOpOrdered;
|
|
487
|
-
/**
|
|
488
|
-
* The resolve transaction of a network ask's device change: the ask decided as `network` says
|
|
489
|
-
* ({@link decideTx}: lock order conversation → approval → run), then the op's outcome recorded
|
|
490
|
-
* (`DevicePolicyService.settleIn`: the machine's row). When the ask closed meanwhile (a reply,
|
|
491
|
-
* the expiry, a stop) only the op's outcome is recorded, and a change the device applied is
|
|
492
|
-
* audited `device.network_allowed` with `late: true` in the same transaction.
|
|
493
|
-
*/
|
|
494
|
-
private settleNetworkOp;
|
|
495
|
-
/**
|
|
496
|
-
* The op's outcome for an ask that is no longer pending (in the caller's transaction): recorded,
|
|
497
|
-
* and a change the device applied audited `device.network_allowed` `late` (the change stands:
|
|
498
|
-
* the owner chose it; no inverse change is sent). True when it was audited late. `undecided`:
|
|
499
|
-
* the ask is still pending but the op's account can no longer decide it; the allow is audited
|
|
500
|
-
* without `late` (it is not after the ask) and the caller gives the ask the reason.
|
|
501
|
-
*/
|
|
502
|
-
private settleClosedIn;
|
|
503
|
-
/** The live intent `opId` on machine `machineId` (null: settled already, or expired). */
|
|
504
|
-
private pendingOpOf;
|
|
505
|
-
/**
|
|
506
|
-
* The `device-op-resolve` job's outcome of an op that answers network ask `op.source.approvalId`
|
|
507
|
-
* (transactional outbox spec §7.4), in the resolver's transaction: under the ask's locks
|
|
508
|
-
* (conversation, then the approval) the op is read again (settled meanwhile: nothing to do).
|
|
509
|
-
* Applied, and the ask still pending → approved `always` by the op's account (`via` as it
|
|
510
|
-
* asked), the run resumed in this transaction as every decision does; the ask closed → audited
|
|
511
|
-
* `late`; still pending but the op's account can no longer decide it → the allow audited (not
|
|
512
|
-
* late) and the ask left pending with `applied_undecided`. Not applied (refused, never received,
|
|
513
|
-
* interrupted) or still unknown → the op's outcome recorded and the ask left pending with the
|
|
514
|
-
* reason (`detail.attempt`) and an `approval_updated` event so the card shows it: no person is
|
|
515
|
-
* there to fall back to a run grant (D2). The caller locked the machine's device first
|
|
516
|
-
* (`DevicePolicyService.lockMachineDevice`, before the ask's conversation row).
|
|
517
|
-
*/
|
|
518
|
-
settleFromResolver(ref: {
|
|
519
|
-
machineId: string;
|
|
520
|
-
opId: string;
|
|
521
|
-
approvalId: string;
|
|
522
|
-
}, result: PolicyOpResult): Promise<void>;
|
|
523
|
-
/**
|
|
524
|
-
* A pending network ask's reason (`detail.attempt`) and its `approval_updated` event (one per
|
|
525
|
-
* op and outcome), in the caller's transaction with the ask locked; notified after the commit.
|
|
526
|
-
*/
|
|
527
|
-
private attemptIn;
|
|
528
438
|
/** The owner of a live device of the org (null: none, deleted, or of another org). */
|
|
529
439
|
private deviceOwnerOf;
|
|
530
440
|
/** After the commit: the decision's events reach the page, the run's waits and IM delivery. */
|