@capybara-hq/kernel 0.1.0-rc.73 → 0.1.0-rc.74
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 +5 -5
- package/dist/catalog/admin-catalog.schemas.d.ts +3 -1
- package/dist/catalog/admin-catalog.schemas.js +6 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.schemas.d.ts +3 -1
- package/dist/catalog/org-catalog.schemas.js +3 -1
- package/dist/catalog/plugin-package.js +7 -5
- package/dist/catalog/reserved-names.js +3 -9
- package/dist/channels/actions.js +4 -0
- package/dist/channels/cards.d.ts +10 -7
- package/dist/channels/cards.js +23 -12
- package/dist/channels/phrases.d.ts +24 -2
- package/dist/channels/phrases.js +12 -2
- package/dist/ctx/secrets.d.ts +4 -2
- package/dist/ctx/secrets.js +19 -5
- package/dist/db/kernel-schema.d.ts +14 -0
- package/dist/devices/conversation-devices.d.ts +3 -2
- package/dist/devices/conversation-devices.js +9 -4
- package/dist/devices/device-projects.service.d.ts +22 -27
- package/dist/devices/device-projects.service.js +36 -41
- package/dist/devices/devices.controller.d.ts +3 -5
- package/dist/devices/devices.controller.js +4 -17
- package/dist/devices/devices.schemas.d.ts +1 -1
- package/dist/devices/devices.schemas.js +1 -1
- package/dist/devices/devices.service.d.ts +72 -52
- package/dist/devices/devices.service.js +158 -93
- package/dist/devices/project-rules.d.ts +6 -8
- package/dist/devices/project-rules.js +5 -11
- package/dist/dial-in/auth.service.js +1 -1
- package/dist/dial-in/machines.d.ts +5 -4
- package/dist/dial-in/machines.js +5 -4
- package/dist/errors.d.ts +8 -3
- package/dist/errors.js +8 -3
- package/dist/extensions/admin-ops.js +2 -1
- package/dist/extensions/bootstrap-extra.d.ts +11 -1
- package/dist/extensions/bootstrap-extra.js +21 -1
- package/dist/extensions/bootstrap-manifest.d.ts +14 -0
- package/dist/extensions/bootstrap-manifest.js +23 -0
- package/dist/extensions/bootstrap-packages.d.ts +87 -0
- package/dist/extensions/bootstrap-packages.js +263 -0
- package/dist/extensions/bootstrap.d.ts +27 -71
- package/dist/extensions/bootstrap.js +85 -329
- package/dist/extensions/guide-places.d.ts +9 -0
- package/dist/extensions/guide-places.js +32 -22
- package/dist/extensions/plugin-guides.d.ts +20 -2
- package/dist/extensions/plugin-guides.js +39 -14
- package/dist/identity/sso-paths.d.ts +7 -0
- package/dist/identity/sso-paths.js +13 -0
- package/dist/identity/sso.js +3 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +2 -2
- package/dist/platform/exclusions.js +2 -7
- package/dist/platform/ops/devices.ops.js +11 -7
- package/dist/platform/ops/setup.ops.js +1 -1
- package/dist/runtime/project/knowledge.service.js +6 -5
- package/dist/sandbox/device-sandbox.d.ts +11 -0
- package/dist/sandbox/device-sandbox.js +29 -0
- package/dist/sandbox/modes.d.ts +16 -4
- package/dist/sandbox/modes.js +12 -0
- package/dist/sandbox/permission-facts.d.ts +12 -2
- package/dist/sandbox/permission-facts.js +14 -4
- package/dist/sandbox/sandbox.service.d.ts +18 -11
- package/dist/sandbox/sandbox.service.js +51 -24
- package/dist/setup/setup-guides.service.d.ts +2 -2
- package/dist/setup/setup-guides.service.js +1 -1
- package/dist/tools/approvals.service.d.ts +31 -11
- package/dist/tools/approvals.service.js +55 -19
- package/dist/tools/builtins/sandbox/common.d.ts +2 -2
- package/dist/tools/builtins/sandbox/common.js +2 -2
- package/dist/tools/network-asks.d.ts +103 -20
- package/dist/tools/network-asks.js +133 -18
- package/dist/tools/pipeline.d.ts +5 -0
- package/dist/tools/pipeline.js +15 -8
- package/package.json +3 -3
- package/src/migrations/0178_bootstrap_run_extra.sql +17 -0
package/dist/sandbox/modes.js
CHANGED
|
@@ -171,6 +171,18 @@ export function appliedWider(a, b) {
|
|
|
171
171
|
return true;
|
|
172
172
|
return a.network.hosts.some((host) => !b.network.hosts.some((p) => coversHost(p, host)));
|
|
173
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Whether desired limits `b` allow a host that applied limits `a` do not cover, both allowlists
|
|
176
|
+
* (device-provider spec §6.3): a host added to the device's own list, or to the org's or the
|
|
177
|
+
* platform's, which the instance gets at its next use (or, with limits fixed at its file system,
|
|
178
|
+
* after a file reset). Unknown (null) is false here, as for {@link appliedWider}; a change of kind
|
|
179
|
+
* is {@link sameApplied}'s. The mode is not a dimension ({@link AppliedLimits}).
|
|
180
|
+
*/
|
|
181
|
+
export function appliedLacksHost(a, b) {
|
|
182
|
+
if (a == null || a.network.kind !== "allowlist" || b.network.kind !== "allowlist")
|
|
183
|
+
return false;
|
|
184
|
+
return b.network.hosts.some((host) => !a.network.hosts.some((p) => coversHost(p, host)));
|
|
185
|
+
}
|
|
174
186
|
const isMode = (v) => v === "auto" || v === "sandbox";
|
|
175
187
|
function appliedFrom(v) {
|
|
176
188
|
if (typeof v !== "object" || v === null)
|
|
@@ -80,9 +80,19 @@ export declare class PermissionFacts {
|
|
|
80
80
|
/** The org's effective hosts: what a device's own host list may narrow, never add to. */
|
|
81
81
|
orgHosts: string[];
|
|
82
82
|
refusal: (host: string) => string | null;
|
|
83
|
+
/** Why a host cannot be added to the device's own network list ({@link deviceListAddRefusal}). */
|
|
84
|
+
listAddRefusal: (host: string) => string | null;
|
|
83
85
|
description: string | null;
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
+
/**
|
|
87
|
+
* The device's network is an allowlist with a host list of its own: only then can a host
|
|
88
|
+
* join that list (`DevicesService.addNetworkHostsIn`); a device following its org's hosts
|
|
89
|
+
* already allows every host its list could name.
|
|
90
|
+
*/
|
|
91
|
+
ownList: boolean;
|
|
92
|
+
/** The device's own host list (empty unless its network is an allowlist of its own). */
|
|
93
|
+
ownHosts: string[];
|
|
94
|
+
/** Where its provider applies new limits (`limitsApplyAt`; absent: at its instance). */
|
|
95
|
+
limitsApplyAt: "fileSystem" | "instance" | undefined;
|
|
86
96
|
reach: {
|
|
87
97
|
outsideSandbox: boolean;
|
|
88
98
|
networkCeiling: "none" | import("./device-sandbox.js").DeviceNetworkMode;
|
|
@@ -21,7 +21,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
|
21
21
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
22
22
|
import { readOrgSettings } from "../orgs/settings.service.js";
|
|
23
23
|
import { storedReport, storedSupport } from "./device-reports.js";
|
|
24
|
-
import { canonicalHostCeiling, effectiveDeviceSandbox, hostGrantCeiling, hostGrantRefusal, orgHostsOf, providerLayerOf, reachWithin, } from "./device-sandbox.js";
|
|
24
|
+
import { canonicalHostCeiling, deviceListAddRefusal, effectiveDeviceSandbox, hostGrantCeiling, hostGrantRefusal, orgHostsOf, providerLayerOf, reachWithin, } from "./device-sandbox.js";
|
|
25
25
|
import { readDeviceSandboxSettings } from "./device-sandbox-settings.js";
|
|
26
26
|
import { appliedOf, appliedWider, cloudChosenMode, coversHost, effectiveDevicePolicy, readDeploymentDevicePolicy, readInstanceLimits, } from "./modes.js";
|
|
27
27
|
import { assertAuthorityHeld } from "./permission-authority-lock.js";
|
|
@@ -106,7 +106,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
106
106
|
readOrgSettings(this.db.db, orgId),
|
|
107
107
|
this.db
|
|
108
108
|
.selectFrom("devices")
|
|
109
|
-
.select(["network_mode", "network_hosts", "report"])
|
|
109
|
+
.select(["network_mode", "network_hosts", "report", "provider"])
|
|
110
110
|
.where("id", "=", deviceId)
|
|
111
111
|
.where("org_id", "=", orgId)
|
|
112
112
|
.executeTakeFirst(),
|
|
@@ -138,9 +138,19 @@ let PermissionFacts = class PermissionFacts {
|
|
|
138
138
|
/** The org's effective hosts: what a device's own host list may narrow, never add to. */
|
|
139
139
|
orgHosts: orgHostsOf(platform, orgLayer),
|
|
140
140
|
refusal: (host) => hostGrantRefusal(host, box, platform, orgLayer),
|
|
141
|
+
/** Why a host cannot be added to the device's own network list ({@link deviceListAddRefusal}). */
|
|
142
|
+
listAddRefusal: (host) => deviceListAddRefusal(host, box, platform, orgLayer),
|
|
141
143
|
description: storedReport(row?.report)?.description.en ?? null,
|
|
142
|
-
/**
|
|
143
|
-
|
|
144
|
+
/**
|
|
145
|
+
* The device's network is an allowlist with a host list of its own: only then can a host
|
|
146
|
+
* join that list (`DevicesService.addNetworkHostsIn`); a device following its org's hosts
|
|
147
|
+
* already allows every host its list could name.
|
|
148
|
+
*/
|
|
149
|
+
ownList: device.networkMode === "allowlist" && device.networkHosts.length > 0,
|
|
150
|
+
/** The device's own host list (empty unless its network is an allowlist of its own). */
|
|
151
|
+
ownHosts: device.networkMode === "allowlist" ? [...device.networkHosts] : [],
|
|
152
|
+
/** Where its provider applies new limits (`limitsApplyAt`; absent: at its instance). */
|
|
153
|
+
limitsApplyAt: row ? this.providers.forDevice(row.provider)?.impl.limitsApplyAt : undefined,
|
|
144
154
|
reach: {
|
|
145
155
|
outsideSandbox: box.outsideSandbox,
|
|
146
156
|
networkCeiling: box.networkCeiling,
|
|
@@ -26,7 +26,6 @@ import type { HeldDeviceContextEvidence } from "./permission-context-types.js";
|
|
|
26
26
|
import { PermissionFacts } from "./permission-facts.js";
|
|
27
27
|
import { DeviceProviders } from "./providers.js";
|
|
28
28
|
import type { SandboxUseContext } from "./use-context.js";
|
|
29
|
-
export { deviceNotFound } from "../devices/errors.js";
|
|
30
29
|
export { SANDBOX_LOCK_PREFIX, SANDBOX_LOCK_TTL_MS, SandboxLockLostError, sandboxBusy, } from "./leases.js";
|
|
31
30
|
export type { SandboxUseContext } from "./use-context.js";
|
|
32
31
|
/** The third argument of the `withSandbox` callback. */
|
|
@@ -362,17 +361,23 @@ export declare class SandboxService {
|
|
|
362
361
|
*/
|
|
363
362
|
ceilingLimits(orgId: string): Promise<SandboxLimits>;
|
|
364
363
|
/**
|
|
365
|
-
*
|
|
366
|
-
* (`hostGrantRefusal`; null: grantable)
|
|
367
|
-
*
|
|
364
|
+
* What a network ask may offer on the device (device-provider spec §6.3): why a per-call host
|
|
365
|
+
* grant is unavailable (`hostGrantRefusal`; null: grantable), why a host cannot join the
|
|
366
|
+
* device's own list (`deviceListAddRefusal`), whether it has a list of its own (`ownList`) and
|
|
367
|
+
* its hosts (`ownHosts`),
|
|
368
|
+
* where its provider applies new limits (`limitsApplyAt`) and its sandbox (`box.perCallHosts`:
|
|
369
|
+
* the provider's per-operation hosts).
|
|
368
370
|
*/
|
|
369
371
|
hostRefusal(device: {
|
|
370
372
|
orgId: string;
|
|
371
373
|
deviceId: string;
|
|
372
374
|
}): Promise<{
|
|
373
375
|
refusal: (host: string) => string | null;
|
|
376
|
+
listAddRefusal: (host: string) => string | null;
|
|
374
377
|
box: DeviceSandbox;
|
|
375
|
-
|
|
378
|
+
ownList: boolean;
|
|
379
|
+
ownHosts: string[];
|
|
380
|
+
limitsApplyAt: "instance" | "fileSystem" | undefined;
|
|
376
381
|
}>;
|
|
377
382
|
/**
|
|
378
383
|
* The limits state of a device's instance for its page (auto mode spec §4.2), read without a
|
|
@@ -397,12 +402,14 @@ export declare class SandboxService {
|
|
|
397
402
|
private fsBound;
|
|
398
403
|
/**
|
|
399
404
|
* Whether the running instance of `row` must get `want` before use (auto mode spec §4.2): a
|
|
400
|
-
* cloud instance whose recorded network kind differs (never the mode alone),
|
|
401
|
-
* permissive than `want` in any dimension (a host-only narrowing too, spec
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
405
|
+
* cloud instance whose recorded network kind differs (never the mode alone), whose recorded
|
|
406
|
+
* limits are more permissive than `want` in any dimension (a host-only narrowing too, spec
|
|
407
|
+
* §124), or whose recorded allowlist lacks a host `want` allows (a host added to the device's or
|
|
408
|
+
* the org's list, device-provider spec §6.3; applied once, then recorded), unless only a file
|
|
409
|
+
* reset could apply it ({@link fsBound}). A provider bound to its file system still goes through
|
|
410
|
+
* the exclusive lease once for a narrowing, so `applyLimits` records it as `unapplied` (the
|
|
411
|
+
* device is then unprobed until the reset, never silently supported); an added host there only
|
|
412
|
+
* waits for the reset (`pendingFilesReset`).
|
|
406
413
|
*/
|
|
407
414
|
private mustApply;
|
|
408
415
|
/**
|
|
@@ -24,6 +24,12 @@ const failureKindOf = (error) => isDeviceRequestNotSent(error)
|
|
|
24
24
|
: isSandboxScopeDeniedError(error)
|
|
25
25
|
? "denied"
|
|
26
26
|
: "unsupported";
|
|
27
|
+
/**
|
|
28
|
+
* A provider found the instance gone before it sent the request (#643): a
|
|
29
|
+
* `DeviceRequestNotSentError` whose `cause` is a `SandboxGoneError`. Nothing ran, so the operation
|
|
30
|
+
* is a definite `not_sent` failure, and the instance is rebuilt like any gone one.
|
|
31
|
+
*/
|
|
32
|
+
const goneBeforeSent = (error) => isDeviceRequestNotSent(error) && isSandboxGoneError(error.cause);
|
|
27
33
|
/** The reservation fields a managed start's dispatch must match (its stable input). */
|
|
28
34
|
const backgroundBinding = (args, instanceId) => ({
|
|
29
35
|
taskId: args.taskId,
|
|
@@ -56,13 +62,12 @@ import { isKernelReadMethod, KernelReadNotAdmitted, KernelReadUnsupported, } fro
|
|
|
56
62
|
import { SandboxLeases, SandboxLockLostError, sandboxBusy, } from "./leases.js";
|
|
57
63
|
import { isKnownProvider, LegacyRetirementStore } from "./legacy-retirement.js";
|
|
58
64
|
import { ManagedDeviceContextFailed } from "./managed-device-context.js";
|
|
59
|
-
import { appliedOf, appliedWider, instanceLimitsJson, orgEffectiveHosts, providerLimits, readInstanceLimits, sameApplied, sameAppliedExact, sameAppliedExactly, } from "./modes.js";
|
|
65
|
+
import { appliedLacksHost, appliedOf, appliedWider, instanceLimitsJson, orgEffectiveHosts, providerLimits, readInstanceLimits, sameApplied, sameAppliedExact, sameAppliedExactly, } from "./modes.js";
|
|
60
66
|
import { PermissionFacts } from "./permission-facts.js";
|
|
61
67
|
import { reportOwed, supportOf } from "./permission-runtime-reports.js";
|
|
62
68
|
import { DeviceProviders, servesDialIn } from "./providers.js";
|
|
63
69
|
import { isDeviceRequestNotSent } from "./request-not-sent.js";
|
|
64
70
|
import { SandboxProviderUnreachableError } from "./unreachable.js";
|
|
65
|
-
export { deviceNotFound } from "../devices/errors.js";
|
|
66
71
|
// Moved to leases.ts (phase C); re-exported for existing importers
|
|
67
72
|
export { SANDBOX_LOCK_PREFIX, SANDBOX_LOCK_TTL_MS, SandboxLockLostError, sandboxBusy, } from "./leases.js";
|
|
68
73
|
/** Margin (ms) of a holder record's TTL beyond the longest command: by then the in-sandbox limit has ended its commands. */
|
|
@@ -474,13 +479,23 @@ let SandboxService = class SandboxService {
|
|
|
474
479
|
}, override);
|
|
475
480
|
}
|
|
476
481
|
/**
|
|
477
|
-
*
|
|
478
|
-
* (`hostGrantRefusal`; null: grantable)
|
|
479
|
-
*
|
|
482
|
+
* What a network ask may offer on the device (device-provider spec §6.3): why a per-call host
|
|
483
|
+
* grant is unavailable (`hostGrantRefusal`; null: grantable), why a host cannot join the
|
|
484
|
+
* device's own list (`deviceListAddRefusal`), whether it has a list of its own (`ownList`) and
|
|
485
|
+
* its hosts (`ownHosts`),
|
|
486
|
+
* where its provider applies new limits (`limitsApplyAt`) and its sandbox (`box.perCallHosts`:
|
|
487
|
+
* the provider's per-operation hosts).
|
|
480
488
|
*/
|
|
481
489
|
async hostRefusal(device) {
|
|
482
490
|
const facts = await this.facts.deviceSandboxFacts(device.orgId, device.deviceId);
|
|
483
|
-
return {
|
|
491
|
+
return {
|
|
492
|
+
refusal: facts.refusal,
|
|
493
|
+
listAddRefusal: facts.listAddRefusal,
|
|
494
|
+
box: facts.box,
|
|
495
|
+
ownList: facts.ownList,
|
|
496
|
+
ownHosts: facts.ownHosts,
|
|
497
|
+
limitsApplyAt: facts.limitsApplyAt,
|
|
498
|
+
};
|
|
484
499
|
}
|
|
485
500
|
/**
|
|
486
501
|
* The limits state of a device's instance for its page (auto mode spec §4.2), read without a
|
|
@@ -511,7 +526,12 @@ let SandboxService = class SandboxService {
|
|
|
511
526
|
return { applied: null, effective, pendingNextUse: false, pendingFilesReset: false };
|
|
512
527
|
}
|
|
513
528
|
const rec = readInstanceLimits(row.instance_limits);
|
|
514
|
-
|
|
529
|
+
// what mustApply applies at the next use: another kind, a host the instance allows that the
|
|
530
|
+
// desired list does not (a narrowing), or a desired host it lacks (a host added to a list)
|
|
531
|
+
const differs = row.provider === p.plugin &&
|
|
532
|
+
(!sameApplied(rec.applied, effective) ||
|
|
533
|
+
appliedWider(rec.applied, effective) ||
|
|
534
|
+
appliedLacksHost(rec.applied, effective));
|
|
515
535
|
const fsBound = differs && row.fs_status === "ready" && this.fsBound(p, rec, effective);
|
|
516
536
|
const hasInstance = row.handle !== null && (row.status === "running" || row.status === "suspended");
|
|
517
537
|
return {
|
|
@@ -532,18 +552,20 @@ let SandboxService = class SandboxService {
|
|
|
532
552
|
}
|
|
533
553
|
/**
|
|
534
554
|
* Whether the running instance of `row` must get `want` before use (auto mode spec §4.2): a
|
|
535
|
-
* cloud instance whose recorded network kind differs (never the mode alone),
|
|
536
|
-
* permissive than `want` in any dimension (a host-only narrowing too, spec
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
555
|
+
* cloud instance whose recorded network kind differs (never the mode alone), whose recorded
|
|
556
|
+
* limits are more permissive than `want` in any dimension (a host-only narrowing too, spec
|
|
557
|
+
* §124), or whose recorded allowlist lacks a host `want` allows (a host added to the device's or
|
|
558
|
+
* the org's list, device-provider spec §6.3; applied once, then recorded), unless only a file
|
|
559
|
+
* reset could apply it ({@link fsBound}). A provider bound to its file system still goes through
|
|
560
|
+
* the exclusive lease once for a narrowing, so `applyLimits` records it as `unapplied` (the
|
|
561
|
+
* device is then unprobed until the reset, never silently supported); an added host there only
|
|
562
|
+
* waits for the reset (`pendingFilesReset`).
|
|
541
563
|
*/
|
|
542
564
|
mustApply(row, p, want) {
|
|
543
565
|
const rec = readInstanceLimits(row.instance_limits);
|
|
544
566
|
const target = appliedOf(want);
|
|
545
567
|
const wider = appliedWider(rec.applied, target);
|
|
546
|
-
if (sameApplied(rec.applied, target) && !wider)
|
|
568
|
+
if (sameApplied(rec.applied, target) && !wider && !appliedLacksHost(rec.applied, target))
|
|
547
569
|
return false;
|
|
548
570
|
if (!this.fsBound(p, rec, target))
|
|
549
571
|
return true;
|
|
@@ -846,15 +868,20 @@ let SandboxService = class SandboxService {
|
|
|
846
868
|
catch (err) {
|
|
847
869
|
if (isFileSystemGoneError(err))
|
|
848
870
|
throw await this.filesGone(env, p, e);
|
|
849
|
-
|
|
850
|
-
|
|
871
|
+
const notSentGone = goneBeforeSent(err);
|
|
872
|
+
if (notSentGone ||
|
|
873
|
+
(isSandboxOperationOutcomeUnknownError(err) &&
|
|
874
|
+
(isSandboxGoneError(err.cause) ||
|
|
875
|
+
goneBeforeSent(err.cause)))) {
|
|
851
876
|
// gone after a durable dispatch: the outcome stays unknown and the call is never retried
|
|
852
|
-
// under a new identity
|
|
853
|
-
//
|
|
854
|
-
// the
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
877
|
+
// under a new identity. Gone before the request was sent (#643): the operation is
|
|
878
|
+
// recorded as not sent, and the call answers that nothing ran. Either way the gone
|
|
879
|
+
// instance is rebuilt on the kept files now, so the holder's next call (a retry
|
|
880
|
+
// included) runs on it and is told of the restart (its seen record still names the
|
|
881
|
+
// gone instance)
|
|
882
|
+
this.log.info(notSentGone
|
|
883
|
+
? "sandbox instance is gone before an operation was sent; recreating"
|
|
884
|
+
: "sandbox instance is gone after a dispatched operation; recreating", { deviceId: env });
|
|
858
885
|
const gone = { handle: e.handle, createdAt: e.createdAt };
|
|
859
886
|
await this.leave(env, e);
|
|
860
887
|
left = true;
|
|
@@ -2696,8 +2723,8 @@ let SandboxService = class SandboxService {
|
|
|
2696
2723
|
destroyed_at: null,
|
|
2697
2724
|
sweep_failed_at: null,
|
|
2698
2725
|
});
|
|
2699
|
-
// the device's effective limits apply at creation (a changed
|
|
2700
|
-
// on use, see applyLimits;
|
|
2726
|
+
// the device's effective limits apply at creation (a changed network kind or host list is
|
|
2727
|
+
// applied on use, see applyLimits; resources reach only instances created afterwards)
|
|
2701
2728
|
const wanted = want;
|
|
2702
2729
|
// the record says what is in force: a provider whose limits are fixed at its file system
|
|
2703
2730
|
// records them with the file system, any other with the instance (spec §7.1)
|
|
@@ -34,8 +34,8 @@ export interface SetupGuideListEntry {
|
|
|
34
34
|
plugin: string;
|
|
35
35
|
guideId: string;
|
|
36
36
|
place: SetupGuidePlace;
|
|
37
|
-
/** The connector
|
|
38
|
-
|
|
37
|
+
/** The connector templates a `connector-template` guide covers; empty for other places. */
|
|
38
|
+
templates: string[];
|
|
39
39
|
/** The section rendered: org admins get the admin guides, members their member sections. */
|
|
40
40
|
audience: SetupGuideAudience;
|
|
41
41
|
title: string;
|
|
@@ -2,6 +2,7 @@ import { type LocalizedName, type ToolDisplay } from "@capybara-hq/plugin-sdk";
|
|
|
2
2
|
import { EventLog } from "../conversations/event-log.js";
|
|
3
3
|
import { type ReviewRecord, type ToolView } from "../conversations/events.js";
|
|
4
4
|
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
5
|
+
import { DevicesService } from "../devices/devices.service.js";
|
|
5
6
|
import { type PersonRef } from "../identity/account-avatar.js";
|
|
6
7
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
7
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -54,10 +55,17 @@ export interface KeptToolResult {
|
|
|
54
55
|
code: string;
|
|
55
56
|
};
|
|
56
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* When hosts added to a device's own network list take effect (device-provider spec §6.3): from
|
|
60
|
+
* the next command (per-operation hosts), the next time the device is used (an instance boundary),
|
|
61
|
+
* or after its files are rebuilt (a provider that fixes limits at its file system).
|
|
62
|
+
*/
|
|
63
|
+
export type NetworkAppliesAt = "next-command" | "next-use" | "files-reset";
|
|
57
64
|
/**
|
|
58
65
|
* A network ask's `detail` (network ask-to-allow spec §6.1, P-D2): the device, the refused hosts,
|
|
59
66
|
* the command and its kept `tool_result` (written with a note when the ask settles; the command is
|
|
60
|
-
* never run again), and once approved what took
|
|
67
|
+
* never run again), when "add to this device's list" would apply, and once approved what took
|
|
68
|
+
* effect.
|
|
61
69
|
*/
|
|
62
70
|
export interface NetworkAskDetail {
|
|
63
71
|
deviceId: string;
|
|
@@ -67,15 +75,17 @@ export interface NetworkAskDetail {
|
|
|
67
75
|
}[];
|
|
68
76
|
command: string;
|
|
69
77
|
description: string | null;
|
|
78
|
+
/** When hosts added to the device's own list apply ({@link NetworkAppliesAt}). */
|
|
79
|
+
appliesAt: NetworkAppliesAt;
|
|
70
80
|
/** The formatted `tool_result` of the command and its display-only fields. */
|
|
71
81
|
result: KeptToolResult;
|
|
72
82
|
/** The hosts the decision allowed (every approved decision writes them; none: nothing). */
|
|
73
83
|
grantedHosts?: string[];
|
|
74
84
|
/**
|
|
75
|
-
* What took effect: a run grant (`once
|
|
76
|
-
*
|
|
85
|
+
* What took effect: a run grant (`once`), or the hosts added to the device's own network list
|
|
86
|
+
* (`always`, applying at `appliesAt`; no run grant).
|
|
77
87
|
*/
|
|
78
|
-
outcome?: "once";
|
|
88
|
+
outcome?: "once" | "always";
|
|
79
89
|
}
|
|
80
90
|
/** A network ask's detail as the API shows it: without the kept command result. */
|
|
81
91
|
export type NetworkAskView = Omit<NetworkAskDetail, "result">;
|
|
@@ -379,10 +389,11 @@ export interface NetworkAskInput {
|
|
|
379
389
|
requestedFor: string;
|
|
380
390
|
detail: Omit<NetworkAskDetail, "grantedHosts" | "outcome">;
|
|
381
391
|
/**
|
|
382
|
-
*
|
|
383
|
-
*
|
|
392
|
+
* What the device's provider enforces (device-provider spec §6.3, `networkAskOffer`): `once` (a
|
|
393
|
+
* run grant) only with per-operation hosts, `always` (add to the device's own list) only when
|
|
394
|
+
* every asked host may join it.
|
|
384
395
|
*/
|
|
385
|
-
scopes: "once"[];
|
|
396
|
+
scopes: ("once" | "always")[];
|
|
386
397
|
}
|
|
387
398
|
/** The tool key a network ask is recorded under (the command ran in `Bash`). */
|
|
388
399
|
export declare const NETWORK_ASK_TOOL_KEY = "Bash";
|
|
@@ -449,6 +460,8 @@ export declare class ApprovalsService {
|
|
|
449
460
|
private readonly leakCheck;
|
|
450
461
|
/** A person's entered values are sealed in the decision's transaction (§4.3). */
|
|
451
462
|
private readonly sealed;
|
|
463
|
+
/** A network ask's "add to this device's list" writes the device's own network list. */
|
|
464
|
+
private readonly devices;
|
|
452
465
|
private readonly permissionLocks?;
|
|
453
466
|
private readonly permissionGrants?;
|
|
454
467
|
constructor(db: KernelDb, config: Pick<KernelConfigService, "get">, eventLog: Pick<EventLog, "appendIn" | "notify">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost, schedules: Pick<ScheduledTaskStore, "addGrant">,
|
|
@@ -463,7 +476,9 @@ export declare class ApprovalsService {
|
|
|
463
476
|
/** An entered person value seen in the conversation is refused (§4.5). */
|
|
464
477
|
leakCheck: Pick<ConversationLeakCheck, "leaked">,
|
|
465
478
|
/** A person's entered values are sealed in the decision's transaction (§4.3). */
|
|
466
|
-
sealed: Pick<SealedInputs, "sealIn">,
|
|
479
|
+
sealed: Pick<SealedInputs, "sealIn">,
|
|
480
|
+
/** A network ask's "add to this device's list" writes the device's own network list. */
|
|
481
|
+
devices: Pick<DevicesService, "lockNetworkAddSubject" | "addNetworkHostsIn">, permissionLocks?: PermissionAuthorityLock | undefined, permissionGrants?: PermissionCallGrants | undefined);
|
|
467
482
|
/**
|
|
468
483
|
* 新建 pending 审批(`expires_at` = 现在 + `tools.approvalTimeoutHours`)并写 `approval_requested`,同一事务。
|
|
469
484
|
* 按 (run_id, call_id, attempt) 幂等:已存在则返回已有记录(不覆盖),事件按 `approval_requested:<approvalId>` 幂等。
|
|
@@ -524,9 +539,14 @@ export declare class ApprovalsService {
|
|
|
524
539
|
* A network ask's decision (network ask-to-allow spec §5.2), one at a time per ask across
|
|
525
540
|
* replicas: only the device owner (`requested_for`) decides, in a signed-in session (a personal
|
|
526
541
|
* access token is refused; the route already refuses service and embed tokens); the allowed
|
|
527
|
-
* hosts are a subset of those asked
|
|
528
|
-
*
|
|
529
|
-
*
|
|
542
|
+
* hosts are a subset of those asked, and the scope one the ask offers (device-provider spec
|
|
543
|
+
* §6.3). `once` is a run grant (the row itself); `always` adds the hosts to the device's own
|
|
544
|
+
* network list in the decision's transaction (`DevicesService.addNetworkHostsIn`, no run grant;
|
|
545
|
+
* the command that asked is not run again and the hosts apply at the ask's `appliesAt`). For
|
|
546
|
+
* `always` the transaction opens with the device's ordered prelude (`lockNetworkAddSubject`: the
|
|
547
|
+
* owner's membership, the device row, its permission write lock) before the conversation,
|
|
548
|
+
* approval and run rows; this method's distributed lock stays outside it. Every decision
|
|
549
|
+
* resumes the run in its transaction and is announced after the commit.
|
|
530
550
|
*/
|
|
531
551
|
private decideNetwork;
|
|
532
552
|
/**
|
|
@@ -16,6 +16,7 @@ import { EventLog } from "../conversations/event-log.js";
|
|
|
16
16
|
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, SECURE_INPUT_MAX_FIELDS, } from "../conversations/events.js";
|
|
17
17
|
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
18
18
|
import { conversationSourceOf } from "../conversations/source.js";
|
|
19
|
+
import { DevicesService } from "../devices/devices.service.js";
|
|
19
20
|
import { ApiError } from "../errors.js";
|
|
20
21
|
import { clipText } from "../extensions/hooks.js";
|
|
21
22
|
import { loadPeople } from "../identity/account-avatar.js";
|
|
@@ -23,7 +24,7 @@ import { audit } from "../identity/audit.js";
|
|
|
23
24
|
import { sha256Hex } from "../identity/hash.js";
|
|
24
25
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
25
26
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
26
|
-
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
27
|
+
import { TransactionHost, withOrderedLocks, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
27
28
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
28
29
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
29
30
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
@@ -109,6 +110,11 @@ function personFieldsOf(detail) {
|
|
|
109
110
|
d.leakedFields.length > 0 && { leakedFields: d.leakedFields }),
|
|
110
111
|
};
|
|
111
112
|
}
|
|
113
|
+
const NETWORK_APPLIES_AT = new Set([
|
|
114
|
+
"next-command",
|
|
115
|
+
"next-use",
|
|
116
|
+
"files-reset",
|
|
117
|
+
]);
|
|
112
118
|
/** The tool key a network ask is recorded under (the command ran in `Bash`). */
|
|
113
119
|
export const NETWORK_ASK_TOOL_KEY = "Bash";
|
|
114
120
|
/** The spec hash of a network ask (no tool definition is approved). */
|
|
@@ -215,6 +221,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
215
221
|
resumes;
|
|
216
222
|
leakCheck;
|
|
217
223
|
sealed;
|
|
224
|
+
devices;
|
|
218
225
|
permissionLocks;
|
|
219
226
|
permissionGrants;
|
|
220
227
|
constructor(db, config, eventLog, events, txHost, schedules,
|
|
@@ -229,7 +236,9 @@ let ApprovalsService = class ApprovalsService {
|
|
|
229
236
|
/** An entered person value seen in the conversation is refused (§4.5). */
|
|
230
237
|
leakCheck,
|
|
231
238
|
/** A person's entered values are sealed in the decision's transaction (§4.3). */
|
|
232
|
-
sealed,
|
|
239
|
+
sealed,
|
|
240
|
+
/** A network ask's "add to this device's list" writes the device's own network list. */
|
|
241
|
+
devices, permissionLocks, permissionGrants) {
|
|
233
242
|
this.db = db;
|
|
234
243
|
this.config = config;
|
|
235
244
|
this.eventLog = eventLog;
|
|
@@ -242,6 +251,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
242
251
|
this.resumes = resumes;
|
|
243
252
|
this.leakCheck = leakCheck;
|
|
244
253
|
this.sealed = sealed;
|
|
254
|
+
this.devices = devices;
|
|
245
255
|
this.permissionLocks = permissionLocks;
|
|
246
256
|
this.permissionGrants = permissionGrants;
|
|
247
257
|
}
|
|
@@ -425,8 +435,14 @@ let ApprovalsService = class ApprovalsService {
|
|
|
425
435
|
if (hosts.some((h) => h.host.length === 0 || h.host.length > NETWORK_HOST_MAX_CHARS)) {
|
|
426
436
|
throw new Error("a network ask's host is 1 to 255 characters");
|
|
427
437
|
}
|
|
428
|
-
|
|
429
|
-
|
|
438
|
+
const scopes = new Set(input.scopes);
|
|
439
|
+
if (scopes.size === 0 ||
|
|
440
|
+
scopes.size !== input.scopes.length ||
|
|
441
|
+
[...scopes].some((k) => k !== "once" && k !== "always")) {
|
|
442
|
+
throw new Error('a network ask offers "once", "always" or both, each once');
|
|
443
|
+
}
|
|
444
|
+
if (!NETWORK_APPLIES_AT.has(input.detail.appliesAt)) {
|
|
445
|
+
throw new Error(`a network ask's appliesAt is one of ${[...NETWORK_APPLIES_AT].join(", ")}`);
|
|
430
446
|
}
|
|
431
447
|
const { record, toSeq } = await this.requestNetworkIn(input);
|
|
432
448
|
if (toSeq !== null)
|
|
@@ -850,9 +866,14 @@ let ApprovalsService = class ApprovalsService {
|
|
|
850
866
|
* A network ask's decision (network ask-to-allow spec §5.2), one at a time per ask across
|
|
851
867
|
* replicas: only the device owner (`requested_for`) decides, in a signed-in session (a personal
|
|
852
868
|
* access token is refused; the route already refuses service and embed tokens); the allowed
|
|
853
|
-
* hosts are a subset of those asked
|
|
854
|
-
*
|
|
855
|
-
*
|
|
869
|
+
* hosts are a subset of those asked, and the scope one the ask offers (device-provider spec
|
|
870
|
+
* §6.3). `once` is a run grant (the row itself); `always` adds the hosts to the device's own
|
|
871
|
+
* network list in the decision's transaction (`DevicesService.addNetworkHostsIn`, no run grant;
|
|
872
|
+
* the command that asked is not run again and the hosts apply at the ask's `appliesAt`). For
|
|
873
|
+
* `always` the transaction opens with the device's ordered prelude (`lockNetworkAddSubject`: the
|
|
874
|
+
* owner's membership, the device row, its permission write lock) before the conversation,
|
|
875
|
+
* approval and run rows; this method's distributed lock stays outside it. Every decision
|
|
876
|
+
* resumes the run in its transaction and is announced after the commit.
|
|
856
877
|
*/
|
|
857
878
|
async decideNetwork(orgId, id, accountId, body, actorTokenId, via) {
|
|
858
879
|
const row = await this.db
|
|
@@ -896,11 +917,9 @@ let ApprovalsService = class ApprovalsService {
|
|
|
896
917
|
let network;
|
|
897
918
|
if (body.decision === "approve") {
|
|
898
919
|
const scope = body.scope ?? "once";
|
|
899
|
-
//
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if (scope !== "once" || !ask.scopes.includes(scope)) {
|
|
903
|
-
throw new ApiError("approval.scope_not_allowed", `Scope "${scope}" is not allowed for this approval; allowed: once`);
|
|
920
|
+
// only what the ask offers: what the device's provider enforces (device-provider spec §6.3)
|
|
921
|
+
if ((scope !== "once" && scope !== "always") || !ask.scopes.includes(scope)) {
|
|
922
|
+
throw new ApiError("approval.scope_not_allowed", `Scope "${scope}" is not allowed for this approval; allowed: ${ask.scopes.join(", ")}`);
|
|
904
923
|
}
|
|
905
924
|
const unknown = (body.hosts ?? []).filter((h) => !asked.includes(h));
|
|
906
925
|
if (unknown.length > 0) {
|
|
@@ -915,7 +934,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
915
934
|
{ path: "hosts", message: "Choose at least one host" },
|
|
916
935
|
]);
|
|
917
936
|
}
|
|
918
|
-
network = { wanted: granted, granted, outcome:
|
|
937
|
+
network = { wanted: granted, granted, outcome: scope, via };
|
|
919
938
|
}
|
|
920
939
|
else {
|
|
921
940
|
if (body.hosts !== undefined) {
|
|
@@ -925,7 +944,22 @@ let ApprovalsService = class ApprovalsService {
|
|
|
925
944
|
}
|
|
926
945
|
network = { wanted: [], granted: [], outcome: null, via };
|
|
927
946
|
}
|
|
928
|
-
const
|
|
947
|
+
const decide = () => this.decideIn(orgId, id, accountId, body, actorTokenId, network);
|
|
948
|
+
let decided;
|
|
949
|
+
if (network.outcome === "always") {
|
|
950
|
+
const granted = network.granted;
|
|
951
|
+
// the decider is the device's owner (checked above; the prelude checks it again under the
|
|
952
|
+
// device row's lock). The device write is the prelude's, before any conversation row: a
|
|
953
|
+
// widening locks the device's Full access root conversations (global order device →
|
|
954
|
+
// authority → root conversation → conversation), so it must precede the asking
|
|
955
|
+
// conversation's row. A refusal of the decision below rolls the addition back with it.
|
|
956
|
+
decided = await withOrderedLocks(async () => {
|
|
957
|
+
await this.devices.lockNetworkAddSubject(orgId, accountId, detail.deviceId);
|
|
958
|
+
await this.devices.addNetworkHostsIn(orgId, accountId, detail.deviceId, granted, via);
|
|
959
|
+
}, decide);
|
|
960
|
+
}
|
|
961
|
+
else
|
|
962
|
+
decided = await decide();
|
|
929
963
|
await this.announceDecided(decided.record, decided.toSeq);
|
|
930
964
|
return decided.record;
|
|
931
965
|
}
|
|
@@ -1203,7 +1237,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1203
1237
|
? (command.scope ?? "once")
|
|
1204
1238
|
: network === undefined
|
|
1205
1239
|
? (body.scope ?? "once")
|
|
1206
|
-
: "once";
|
|
1240
|
+
: (network.outcome ?? "once");
|
|
1207
1241
|
// 按角色升级的批准只对这一次有效:授权记在发起人名下会让其以后绕过角色要求
|
|
1208
1242
|
if (scope !== null && scope !== "once" && before.requestedFor === null) {
|
|
1209
1243
|
throw new ApiError("validation_failed", 'Only scope "once" is allowed for role-escalated approvals', [{ path: "scope", message: 'Only "once" is allowed for role-escalated approvals' }]);
|
|
@@ -1258,7 +1292,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1258
1292
|
const hash = before.specHash;
|
|
1259
1293
|
const connectorId = before.connectorId;
|
|
1260
1294
|
if (network !== undefined) {
|
|
1261
|
-
// a network ask grants nothing of the tool kind: its run grant is the row itself
|
|
1295
|
+
// a network ask grants nothing of the tool kind: its run grant is the row itself (`once`);
|
|
1296
|
+
// `always` added the hosts to the device's list in the decision's prelude
|
|
1262
1297
|
}
|
|
1263
1298
|
else if (git !== undefined) {
|
|
1264
1299
|
// a git ask's run grant is the row itself; `always` is the actor's standing allow for the
|
|
@@ -2111,9 +2146,10 @@ ApprovalsService = __decorate([
|
|
|
2111
2146
|
__param(9, Inject(RunResume)),
|
|
2112
2147
|
__param(10, Inject(ConversationLeakCheck)),
|
|
2113
2148
|
__param(11, Inject(SealedInputs)),
|
|
2114
|
-
__param(12,
|
|
2115
|
-
__param(12, Inject(PermissionAuthorityLock)),
|
|
2149
|
+
__param(12, Inject(DevicesService)),
|
|
2116
2150
|
__param(13, Optional()),
|
|
2117
|
-
__param(13, Inject(
|
|
2151
|
+
__param(13, Inject(PermissionAuthorityLock)),
|
|
2152
|
+
__param(14, Optional()),
|
|
2153
|
+
__param(14, Inject(PermissionCallGrants))
|
|
2118
2154
|
], ApprovalsService);
|
|
2119
2155
|
export { ApprovalsService };
|
|
@@ -283,8 +283,8 @@ export declare const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside th
|
|
|
283
283
|
export declare const ESCALATION_GRANT_MISSING_TEXT = "This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation's permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: \"escalated\" and a justification to ask again, or call it without sandbox to run it inside the sandbox.";
|
|
284
284
|
/** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
|
|
285
285
|
export declare const ESCALATION_GRANT_MISSING_LAUNCH_WHY = "its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: \"escalated\" and a justification to ask again";
|
|
286
|
-
/** A
|
|
287
|
-
export declare const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
|
|
286
|
+
/** A request the machine never got: it reconnected, or its instance was gone, before it was sent. */
|
|
287
|
+
export declare const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected or changed before this operation was sent, so nothing ran. Retry the tool call.";
|
|
288
288
|
/** The device itself refused: it cannot enforce its sandbox (`SandboxPermissionUnsupportedError`). */
|
|
289
289
|
export declare const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update its device program (or a super admin to update its device plugin), or continue without the device.";
|
|
290
290
|
/** Earlier work on the device blocks a new operation (`SandboxWorkUnsettledError`). */
|
|
@@ -314,8 +314,8 @@ export const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside the scope
|
|
|
314
314
|
export const ESCALATION_GRANT_MISSING_TEXT = 'This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation\'s permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: "escalated" and a justification to ask again, or call it without sandbox to run it inside the sandbox.';
|
|
315
315
|
/** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
|
|
316
316
|
export const ESCALATION_GRANT_MISSING_LAUNCH_WHY = 'its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: "escalated" and a justification to ask again';
|
|
317
|
-
/** A
|
|
318
|
-
export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
|
|
317
|
+
/** A request the machine never got: it reconnected, or its instance was gone, before it was sent. */
|
|
318
|
+
export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected or changed before this operation was sent, so nothing ran. Retry the tool call.";
|
|
319
319
|
/** The device itself refused: it cannot enforce its sandbox (`SandboxPermissionUnsupportedError`). */
|
|
320
320
|
export const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update its device program (or a super admin to update its device plugin), or continue without the device.";
|
|
321
321
|
/** Earlier work on the device blocks a new operation (`SandboxWorkUnsettledError`). */
|