@capybara-hq/kernel 0.1.0-rc.49 → 0.1.0-rc.50
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 +0 -6
- package/dist/background/launch.d.ts +7 -61
- package/dist/background/launch.js +8 -133
- package/dist/background/poll.job.d.ts +19 -23
- package/dist/background/poll.job.js +30 -66
- package/dist/background/render.d.ts +9 -0
- package/dist/background/render.js +19 -0
- package/dist/background/session.d.ts +3 -66
- package/dist/background/session.js +3 -114
- package/dist/background/stop.d.ts +26 -33
- package/dist/background/stop.js +59 -90
- package/dist/background/store.d.ts +26 -60
- package/dist/background/store.js +23 -108
- package/dist/background/tasks.service.d.ts +9 -29
- package/dist/background/tasks.service.js +18 -115
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.d.ts +3 -0
- package/dist/channels/cards.js +29 -2
- package/dist/channels/phrases.d.ts +35 -0
- package/dist/channels/phrases.js +32 -0
- package/dist/config/load.d.ts +3 -10
- package/dist/config/load.js +26 -21
- package/dist/config/schema.js +3 -3
- package/dist/conversations/events.d.ts +45 -2
- package/dist/conversations/events.js +44 -4
- package/dist/db/kernel-schema.d.ts +9 -4
- package/dist/devices/devices.service.js +1 -1
- package/dist/devices/errors.d.ts +5 -0
- package/dist/devices/errors.js +5 -0
- package/dist/devices/project-rules.d.ts +2 -2
- package/dist/errors.d.ts +9 -11
- package/dist/errors.js +9 -11
- package/dist/identity/settings.d.ts +4 -17
- package/dist/identity/settings.js +9 -32
- package/dist/infra/config/kernel-config.service.js +2 -9
- package/dist/infra/outbox/registry.d.ts +13 -0
- package/dist/infra/outbox/registry.js +8 -0
- 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 -3
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +6 -6
- package/dist/local-devices/device-routes.d.ts +4 -2
- package/dist/local-devices/device-routes.js +7 -6
- package/dist/local-devices/instance-bindings.d.ts +4 -4
- package/dist/local-devices/instance-bindings.js +2 -2
- package/dist/local-devices/local-device-gateway.d.ts +12 -12
- package/dist/local-devices/local-device-gateway.js +94 -129
- package/dist/local-devices/local-device-provider.d.ts +19 -87
- package/dist/local-devices/local-device-provider.js +43 -158
- package/dist/local-devices/local-devices.module.d.ts +4 -5
- package/dist/local-devices/local-devices.module.js +6 -9
- package/dist/local-devices/machines.d.ts +6 -6
- package/dist/local-devices/machines.js +4 -4
- package/dist/local-devices/owner-report.d.ts +3 -3
- package/dist/local-devices/owner-report.js +4 -4
- package/dist/local-devices/owner-reports.js +2 -2
- package/dist/local-devices/policy-summary.js +2 -2
- package/dist/local-devices/relay.d.ts +12 -25
- package/dist/local-devices/relay.js +17 -31
- package/dist/orgs/settings.controller.d.ts +1 -4
- package/dist/orgs/settings.controller.js +3 -3
- package/dist/orgs/settings.service.d.ts +7 -21
- package/dist/orgs/settings.service.js +16 -40
- package/dist/overrides.d.ts +3 -3
- package/dist/platform/ops/admin.ops.js +6 -8
- package/dist/platform/ops/org-settings.ops.js +4 -4
- package/dist/platform/ops/orgs.ops.js +0 -1
- package/dist/runtime/maintenance.d.ts +1 -1
- package/dist/runtime/maintenance.js +7 -1
- package/dist/runtime/run-steps.js +2 -2
- package/dist/sandbox/held-operations.d.ts +7 -0
- package/dist/sandbox/held-operations.js +25 -1
- package/dist/sandbox/leases.d.ts +6 -3
- package/dist/sandbox/leases.js +16 -10
- package/dist/sandbox/legacy-retirement.d.ts +0 -19
- package/dist/sandbox/legacy-retirement.js +6 -37
- package/dist/sandbox/managed-device-context.d.ts +12 -0
- package/dist/sandbox/managed-device-context.js +49 -1
- package/dist/sandbox/modes.d.ts +9 -8
- package/dist/sandbox/modes.js +4 -15
- package/dist/sandbox/operation-authority-types.d.ts +18 -1
- package/dist/sandbox/operation-authority-types.js +20 -1
- package/dist/sandbox/operation-authority.d.ts +14 -0
- package/dist/sandbox/operation-authority.js +120 -18
- package/dist/sandbox/operation-intents.d.ts +43 -0
- package/dist/sandbox/operation-intents.js +107 -4
- package/dist/sandbox/operation-reconcile.job.d.ts +12 -1
- package/dist/sandbox/operation-reconcile.job.js +53 -6
- package/dist/sandbox/permission-call-grants.d.ts +4 -0
- package/dist/sandbox/permission-call-grants.js +32 -3
- package/dist/sandbox/permission-call-types.d.ts +27 -2
- package/dist/sandbox/permission-ceiling-writes.js +2 -1
- package/dist/sandbox/permission-context-types.d.ts +2 -2
- package/dist/sandbox/permission-context-types.js +2 -2
- package/dist/sandbox/permission-facts.js +10 -2
- package/dist/sandbox/platform-full-access.d.ts +8 -26
- package/dist/sandbox/platform-full-access.js +8 -20
- package/dist/sandbox/review/classifier.d.ts +2 -2
- package/dist/sandbox/review/classifier.js +18 -5
- package/dist/sandbox/review/permission-candidate.d.ts +59 -3
- package/dist/sandbox/review/permission-candidate.js +192 -25
- package/dist/sandbox/review/review.service.d.ts +18 -0
- package/dist/sandbox/review/review.service.js +158 -12
- package/dist/sandbox/sandbox.service.d.ts +71 -47
- package/dist/sandbox/sandbox.service.js +234 -133
- package/dist/tools/approvals.service.d.ts +6 -1
- package/dist/tools/approvals.service.js +10 -0
- package/dist/tools/builtins/builtin-tools.d.ts +1 -4
- package/dist/tools/builtins/builtin-tools.js +13 -18
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
- package/dist/tools/builtins/sandbox/bash.js +92 -270
- package/dist/tools/builtins/sandbox/common.d.ts +15 -9
- package/dist/tools/builtins/sandbox/common.js +55 -19
- package/dist/tools/builtins/sandbox/device-owner.d.ts +13 -0
- package/dist/tools/builtins/sandbox/device-owner.js +14 -0
- package/dist/tools/builtins/sandbox/task-list.js +2 -2
- package/dist/tools/builtins/sandbox/task-output.d.ts +14 -57
- package/dist/tools/builtins/sandbox/task-output.js +88 -210
- package/dist/tools/builtins/sandbox/task-stop.d.ts +2 -2
- package/dist/tools/builtins/sandbox/task-stop.js +15 -26
- package/dist/tools/pipeline.d.ts +31 -2
- package/dist/tools/pipeline.js +273 -43
- package/dist/tools/registry.d.ts +7 -0
- package/package.json +4 -4
- package/src/migrations/0162_permission_call_escalation.sql +9 -0
- package/dist/background/status.d.ts +0 -35
- package/dist/background/status.js +0 -57
package/dist/sandbox/leases.js
CHANGED
|
@@ -78,19 +78,19 @@ redis.call('HSET', KEYS[1], ARGV[1], now + ttl)
|
|
|
78
78
|
if redis.call('PTTL', KEYS[1]) < ttl then redis.call('PEXPIRE', KEYS[1], ttl) end
|
|
79
79
|
return 1`);
|
|
80
80
|
/**
|
|
81
|
-
* KEYS lock, users, holders.
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
81
|
+
* KEYS lock, users, holders. Returns the holder fields without a live lease, leaving them in place
|
|
82
|
+
* (the caller forgets them only once their revocation is owed durably, {@link
|
|
83
|
+
* SandboxLeases.forgetHolders}); expired fields are dropped without being returned (their
|
|
84
|
+
* operations are past the deadline the device enforces). The caller's own token is live (a shared
|
|
85
|
+
* lease, or the exclusive token in the lock key), so it is never returned.
|
|
85
86
|
*/
|
|
86
|
-
const
|
|
87
|
+
const DEAD = sharedLeaseReadScript(`local out = {}
|
|
87
88
|
local f = redis.call('HGETALL', KEYS[3])
|
|
88
89
|
for i = 1, #f, 2 do
|
|
89
90
|
local tok = f[i]
|
|
90
91
|
if tonumber(f[i + 1]) <= now then
|
|
91
92
|
redis.call('HDEL', KEYS[3], tok)
|
|
92
93
|
elseif tok ~= cur and not redis.call('ZSCORE', KEYS[2], tok) then
|
|
93
|
-
redis.call('HDEL', KEYS[3], tok)
|
|
94
94
|
table.insert(out, tok)
|
|
95
95
|
end
|
|
96
96
|
end
|
|
@@ -251,12 +251,18 @@ let SandboxLeases = class SandboxLeases {
|
|
|
251
251
|
await this.redis.hdel(`${HOLDERS_PREFIX}${env}`, token);
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
254
|
+
* Tokens of holders without a live lease (crashed holders), read without removing them: a token
|
|
255
|
+
* dies only once, so two readers may both see it and both owe its revocation under the same
|
|
256
|
+
* deterministic job id; {@link forgetHolders} removes them once that is durable.
|
|
256
257
|
*/
|
|
257
|
-
async
|
|
258
|
+
async deadHolders(env) {
|
|
258
259
|
const { lock, users } = this.keys(env);
|
|
259
|
-
return (await this.redis.eval(
|
|
260
|
+
return (await this.redis.eval(DEAD, 3, lock, users, `${HOLDERS_PREFIX}${env}`));
|
|
261
|
+
}
|
|
262
|
+
/** Removes crashed holders' records whose revocation is owed durably ({@link deadHolders}). */
|
|
263
|
+
async forgetHolders(env, tokens) {
|
|
264
|
+
if (tokens.length > 0)
|
|
265
|
+
await this.redis.hdel(`${HOLDERS_PREFIX}${env}`, ...tokens);
|
|
260
266
|
}
|
|
261
267
|
/**
|
|
262
268
|
* A short lease on one path of the sandbox (the kernel's own read-modify-write of a file); waits
|
|
@@ -27,14 +27,6 @@ export type BootReport =
|
|
|
27
27
|
| "stale"
|
|
28
28
|
/** Malformed, or the machine is unknown or revoked: ignored. */
|
|
29
29
|
| "ignored";
|
|
30
|
-
/** {@link LegacyRetirementStore.admitLegacyDispatch}'s answer. */
|
|
31
|
-
export type LegacyDispatchAdmission =
|
|
32
|
-
/** The launch may dispatch; its row is marked `dispatched` first. */
|
|
33
|
-
"admitted"
|
|
34
|
-
/** The legacy-launch freeze is published: the launch must not dispatch. */
|
|
35
|
-
| "frozen"
|
|
36
|
-
/** The reservation is no longer a launchable legacy row (finished meanwhile). */
|
|
37
|
-
| "gone";
|
|
38
30
|
/** {@link LegacyRetirementStore.freeze}'s answer: the freeze is published and enumerated. */
|
|
39
31
|
export interface LegacyFreezeResult {
|
|
40
32
|
/** When the freeze was first published (a rerun keeps it). */
|
|
@@ -207,17 +199,6 @@ export declare class LegacyRetirementStore {
|
|
|
207
199
|
abandoned: number;
|
|
208
200
|
}>;
|
|
209
201
|
frozen(): Promise<boolean>;
|
|
210
|
-
/**
|
|
211
|
-
* The check every legacy SID launch makes immediately before it dispatches its command: under
|
|
212
|
-
* the shared platform authority lock (so a concurrent {@link freeze} waits for it), refuses once
|
|
213
|
-
* the freeze is published; otherwise marks the reservation `dispatched` in the same transaction.
|
|
214
|
-
*/
|
|
215
|
-
admitLegacyDispatch(orgId: string, taskId: string,
|
|
216
|
-
/** The exact incarnation the launch dispatches into (read under its shared lease). */
|
|
217
|
-
instance: {
|
|
218
|
-
provider: string;
|
|
219
|
-
generation: string;
|
|
220
|
-
}): Promise<LegacyDispatchAdmission>;
|
|
221
202
|
/**
|
|
222
203
|
* One enumeration pass: every legacy row (only once the freeze is published) and every revoked
|
|
223
204
|
* managed start that may still own processes on an incarnation that no longer runs, recorded as
|
|
@@ -20,12 +20,12 @@ import { isInternalProvider, LOCAL_PROVIDER } from "./providers.js";
|
|
|
20
20
|
* the physical no-reuse obligations of old instance incarnations (migration 0157).
|
|
21
21
|
*
|
|
22
22
|
* - **Freeze.** {@link freeze} writes the one freeze row under the platform authority writer (the
|
|
23
|
-
* exclusive platform permission lock).
|
|
24
|
-
*
|
|
25
|
-
* row
|
|
26
|
-
*
|
|
27
|
-
* be stopped or drained before the freeze (the rows it writes still read `unknown`,
|
|
28
|
-
* "not dispatched", and the periodic re-scan picks them up).
|
|
23
|
+
* exclusive platform permission lock). An R1 (protocol 2) kernel admitted each legacy SID
|
|
24
|
+
* launch under the shared platform lock immediately before its dispatch and refused once the
|
|
25
|
+
* row existed, marking an admitted reservation `dispatched` with the incarnation it dispatched
|
|
26
|
+
* into; this release launches no SID task, so it only reads those marks. A replica without the
|
|
27
|
+
* fence must be stopped or drained before the freeze (the rows it writes still read `unknown`,
|
|
28
|
+
* never "not dispatched", and the periodic re-scan picks them up).
|
|
29
29
|
* - **Obligations.** {@link scan} enumerates, under the freeze, every legacy row whose processes
|
|
30
30
|
* may still exist (running with a SID, a reservation that may have dispatched, a stop in flight,
|
|
31
31
|
* `kill_pending` including terminal rows, a possibly dispatched launch that failed), and every
|
|
@@ -289,34 +289,6 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
289
289
|
.executeTakeFirst();
|
|
290
290
|
return row !== undefined;
|
|
291
291
|
}
|
|
292
|
-
/**
|
|
293
|
-
* The check every legacy SID launch makes immediately before it dispatches its command: under
|
|
294
|
-
* the shared platform authority lock (so a concurrent {@link freeze} waits for it), refuses once
|
|
295
|
-
* the freeze is published; otherwise marks the reservation `dispatched` in the same transaction.
|
|
296
|
-
*/
|
|
297
|
-
async admitLegacyDispatch(orgId, taskId,
|
|
298
|
-
/** The exact incarnation the launch dispatches into (read under its shared lease). */
|
|
299
|
-
instance) {
|
|
300
|
-
await this.locks.acquire({ orgId }, { kind: "admit" });
|
|
301
|
-
if (await this.frozen())
|
|
302
|
-
return "frozen";
|
|
303
|
-
const r = await this.db
|
|
304
|
-
.updateTable("background_tasks")
|
|
305
|
-
.set({
|
|
306
|
-
legacy_dispatch: "dispatched",
|
|
307
|
-
legacy_dispatch_provider: instance.provider,
|
|
308
|
-
legacy_dispatch_generation: GENERATION_RE.test(instance.generation)
|
|
309
|
-
? instance.generation
|
|
310
|
-
: null,
|
|
311
|
-
})
|
|
312
|
-
.where("id", "=", taskId)
|
|
313
|
-
.where("org_id", "=", orgId)
|
|
314
|
-
.where("status", "=", "running")
|
|
315
|
-
.where("sid", "is", null)
|
|
316
|
-
.where("launch_state", "=", "legacy")
|
|
317
|
-
.executeTakeFirst();
|
|
318
|
-
return Number(r.numUpdatedRows) === 1 ? "admitted" : "gone";
|
|
319
|
-
}
|
|
320
292
|
/**
|
|
321
293
|
* One enumeration pass: every legacy row (only once the freeze is published) and every revoked
|
|
322
294
|
* managed start that may still own processes on an incarnation that no longer runs, recorded as
|
|
@@ -1045,9 +1017,6 @@ let LegacyRetirementStore = class LegacyRetirementStore {
|
|
|
1045
1017
|
__decorate([
|
|
1046
1018
|
Transactional({ propagation: "requires_new" })
|
|
1047
1019
|
], LegacyRetirementStore.prototype, "publishFreeze", null);
|
|
1048
|
-
__decorate([
|
|
1049
|
-
Transactional({ propagation: "requires_new" })
|
|
1050
|
-
], LegacyRetirementStore.prototype, "admitLegacyDispatch", null);
|
|
1051
1020
|
__decorate([
|
|
1052
1021
|
Transactional({ propagation: "requires_new" })
|
|
1053
1022
|
], LegacyRetirementStore.prototype, "addMember", null);
|
|
@@ -83,6 +83,18 @@ export declare class ManagedDeviceContextRecorder {
|
|
|
83
83
|
* transaction. A revoked execution keeps its identical `ExecutionRevoked`, an abort its reason.
|
|
84
84
|
*/
|
|
85
85
|
record(input: PermissionContextSubject, held: Readonly<HeldDeviceContextEvidence>, signal: AbortSignal): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* The gone error to answer instead of a stale context: only while the conversation's root still
|
|
88
|
+
* works on the held device (a conversation moved to another device keeps the stale "retry", the
|
|
89
|
+
* retry runs on the new one). Any failure of these reads keeps the stale answer.
|
|
90
|
+
*/
|
|
91
|
+
private goneInstead;
|
|
92
|
+
/**
|
|
93
|
+
* The error of a device state that never comes back: the device (or its org) deleted, or a
|
|
94
|
+
* local device without an active machine (revoked, signed out). Undefined while it is live; a
|
|
95
|
+
* cloud device has no machine.
|
|
96
|
+
*/
|
|
97
|
+
private goneError;
|
|
86
98
|
private mapped;
|
|
87
99
|
/** The complete authority subject, read without locks; validated again under them. */
|
|
88
100
|
private discover;
|
|
@@ -12,6 +12,7 @@ import { Inject, Injectable } from "@nestjs/common";
|
|
|
12
12
|
import { EventLog } from "../conversations/event-log.js";
|
|
13
13
|
import { ManagedDevicePathsV1Schema, } from "../conversations/events.js";
|
|
14
14
|
import { PermissionProfileStore } from "../conversations/permission-profile-store.js";
|
|
15
|
+
import { deviceNotFound, machineRevoked } from "../devices/errors.js";
|
|
15
16
|
import { ApiError } from "../errors.js";
|
|
16
17
|
import { afterCommit } from "../infra/database/after-commit.js";
|
|
17
18
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -137,9 +138,56 @@ let ManagedDeviceContextRecorder = class ManagedDeviceContextRecorder {
|
|
|
137
138
|
await withTransactionFencePrelude(() => this.locks.acquire(subject, { kind: "admit" }), () => this.appendLocked(input, subject, held, signal));
|
|
138
139
|
}
|
|
139
140
|
catch (error) {
|
|
140
|
-
|
|
141
|
+
const mapped = this.mapped(error, input, signal);
|
|
142
|
+
// R27: a deleted device or a disconnected machine never comes back, so the call says so
|
|
143
|
+
// (actionable, nothing to retry) instead of the stale context's "retry"
|
|
144
|
+
if (mapped instanceof ManagedDeviceContextStale)
|
|
145
|
+
throw (await this.goneInstead(input, held.deviceId)) ?? mapped;
|
|
146
|
+
throw mapped;
|
|
141
147
|
}
|
|
142
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* The gone error to answer instead of a stale context: only while the conversation's root still
|
|
151
|
+
* works on the held device (a conversation moved to another device keeps the stale "retry", the
|
|
152
|
+
* retry runs on the new one). Any failure of these reads keeps the stale answer.
|
|
153
|
+
*/
|
|
154
|
+
async goneInstead(input, deviceId) {
|
|
155
|
+
try {
|
|
156
|
+
const root = await this.profiles.readRoot(input.orgId, input.conversationId);
|
|
157
|
+
if (root.device_id !== deviceId)
|
|
158
|
+
return undefined;
|
|
159
|
+
return await this.goneError(input.orgId, deviceId);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
this.log.warn("managed device context: the device check failed", {
|
|
163
|
+
conversationId: input.conversationId,
|
|
164
|
+
cause: error instanceof Error ? `${error.name}: ${error.message}`.slice(0, 500) : "",
|
|
165
|
+
});
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The error of a device state that never comes back: the device (or its org) deleted, or a
|
|
171
|
+
* local device without an active machine (revoked, signed out). Undefined while it is live; a
|
|
172
|
+
* cloud device has no machine.
|
|
173
|
+
*/
|
|
174
|
+
async goneError(orgId, deviceId) {
|
|
175
|
+
const row = await this.db
|
|
176
|
+
.selectFrom("devices as e")
|
|
177
|
+
.innerJoin("orgs as o", "o.id", "e.org_id")
|
|
178
|
+
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
|
|
179
|
+
.select(["e.source", "m.id as machine_id"])
|
|
180
|
+
.where("e.id", "=", deviceId)
|
|
181
|
+
.where("e.org_id", "=", orgId)
|
|
182
|
+
.where("e.deleted_at", "is", null)
|
|
183
|
+
.where("o.deleted_at", "is", null)
|
|
184
|
+
.executeTakeFirst();
|
|
185
|
+
if (row === undefined)
|
|
186
|
+
return deviceNotFound();
|
|
187
|
+
if (row.source === "local" && row.machine_id === null)
|
|
188
|
+
return machineRevoked();
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
143
191
|
mapped(error, input, signal) {
|
|
144
192
|
if (error instanceof ExecutionRevoked)
|
|
145
193
|
return error;
|
package/dist/sandbox/modes.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ import { type FullAccessPermission } from "./platform-full-access.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* Device modes (auto mode spec §4.1–§4.3): who may choose auto mode, and the network each mode
|
|
8
8
|
* gets. One pure function, {@link effectiveDevicePolicy}, combines the platform's switch
|
|
9
|
-
* (`devices.fullAccess`), the org's (`fullAccess`, `cloudNetwork`) and the device's
|
|
10
|
-
* machine's
|
|
9
|
+
* (`devices.fullAccess`), the org's (`fullAccess`, `cloudNetwork`) and the device's owner ceiling (a
|
|
10
|
+
* local machine's owner report, a cloud device's B1 snapshot; null follows the platform and the org).
|
|
11
|
+
* It is a ceiling only: no device-chosen default mode selects how an operation runs (permission
|
|
12
|
+
* runtime cutover 8.6); the conversation's permission profile does, within this ceiling.
|
|
11
13
|
*/
|
|
12
14
|
/** A device mode. Not `DeviceMode`, which is the program's os | docker run mode. */
|
|
13
15
|
export type SandboxMode = "auto" | "sandbox";
|
|
@@ -60,12 +62,10 @@ export declare function readDeploymentDevicePolicy(db: KernelSchemaDb, config: P
|
|
|
60
62
|
export type OrgDeviceSettings = Pick<OrgSettings, "fullAccess" | "cloudNetwork">;
|
|
61
63
|
/** The effective device policy of one device (or of a new device, with no choice of its own). */
|
|
62
64
|
export interface EffectiveDevicePolicy {
|
|
63
|
-
/** min(the device's
|
|
65
|
+
/** min(the device's owner ceiling, {@link allowedMode}); `auto` unless that ceiling is sandbox. */
|
|
64
66
|
mode: SandboxMode;
|
|
65
67
|
/** `auto` only when the platform's and the org's `fullAccess` both allow it. */
|
|
66
68
|
allowedMode: SandboxMode;
|
|
67
|
-
/** Which layer decided {@link mode}. */
|
|
68
|
-
modeSource: "device" | "org" | "platform";
|
|
69
69
|
/** The cloud network (auto mode's open network, the org's allowlist, or the kill switch). */
|
|
70
70
|
network: DeviceNetwork;
|
|
71
71
|
/**
|
|
@@ -93,9 +93,10 @@ export declare function orgAllowedDomains(deployment: DeploymentDevicePolicy, or
|
|
|
93
93
|
*/
|
|
94
94
|
export declare function deviceNetwork(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings, mode: SandboxMode): DeviceNetwork;
|
|
95
95
|
/**
|
|
96
|
-
* The effective device policy. `deviceMode` is the device's
|
|
97
|
-
*
|
|
98
|
-
* never honoured; the network follows the
|
|
96
|
+
* The effective device policy. `deviceMode` is the device's owner ceiling (a local machine's owner
|
|
97
|
+
* report, a cloud device's B1 snapshot or narrowing switch; null = follow the platform and the
|
|
98
|
+
* org). A stored mode the platform or org forbids is cut, never honoured; the network follows the
|
|
99
|
+
* resulting mode.
|
|
99
100
|
*/
|
|
100
101
|
export declare function effectiveDevicePolicy(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings, deviceMode: SandboxMode | null,
|
|
101
102
|
/** A cloud device's B1 outer network snapshot: the network never goes beyond it. */
|
package/dist/sandbox/modes.js
CHANGED
|
@@ -80,30 +80,19 @@ export function deviceNetwork(deployment, org, mode) {
|
|
|
80
80
|
return { kind: "allowlist", hosts: orgAllowedDomains(deployment, org) };
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
|
-
* The effective device policy. `deviceMode` is the device's
|
|
84
|
-
*
|
|
85
|
-
* never honoured; the network follows the
|
|
83
|
+
* The effective device policy. `deviceMode` is the device's owner ceiling (a local machine's owner
|
|
84
|
+
* report, a cloud device's B1 snapshot or narrowing switch; null = follow the platform and the
|
|
85
|
+
* org). A stored mode the platform or org forbids is cut, never honoured; the network follows the
|
|
86
|
+
* resulting mode.
|
|
86
87
|
*/
|
|
87
88
|
export function effectiveDevicePolicy(deployment, org, deviceMode,
|
|
88
89
|
/** A cloud device's B1 outer network snapshot: the network never goes beyond it. */
|
|
89
90
|
outer = null) {
|
|
90
91
|
const allowedMode = allowedDeviceMode(deployment.fullAccess, org.fullAccess);
|
|
91
92
|
const mode = allowedMode === "sandbox" ? "sandbox" : (deviceMode ?? "auto");
|
|
92
|
-
const modeSource = mode === "sandbox"
|
|
93
|
-
? deviceMode === "sandbox" && allowedMode === "auto"
|
|
94
|
-
? "device"
|
|
95
|
-
: deployment.fullAccess === "allowed"
|
|
96
|
-
? "org"
|
|
97
|
-
: "platform"
|
|
98
|
-
: deviceMode === "auto"
|
|
99
|
-
? "device"
|
|
100
|
-
: org.fullAccess === "allowed"
|
|
101
|
-
? "org"
|
|
102
|
-
: "platform";
|
|
103
93
|
return {
|
|
104
94
|
mode,
|
|
105
95
|
allowedMode,
|
|
106
|
-
modeSource,
|
|
107
96
|
network: outer === null
|
|
108
97
|
? deviceNetwork(deployment, org, mode)
|
|
109
98
|
: intersectNetworks(deviceNetwork(deployment, org, mode), outer),
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import { type DeviceExecGrants } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type DeviceExecGrants, type SandboxBrowseScope, type SandboxOperationScope, SandboxScopeDeniedError } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* A call that asked to run outside the sandbox (`sandbox: "escalated"`) whose escalation grant no
|
|
4
|
+
* longer matches at admission: the device, its Full access ceiling or the permission scope
|
|
5
|
+
* changed after the approval. A typed pre-effect scope refusal (nothing ran), never a silent
|
|
6
|
+
* downgrade to the restricted scope; the tool tells the model to ask again.
|
|
7
|
+
*/
|
|
8
|
+
export declare class EscalationGrantMissingError extends SandboxScopeDeniedError {
|
|
9
|
+
readonly escalationGrantMissing: true;
|
|
10
|
+
}
|
|
11
|
+
export declare const isEscalationGrantMissing: (e: unknown) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether an operation scope needs the Full access ceiling and the runtime's Full support: a Full
|
|
14
|
+
* access operation (its reach is full, or narrowed for a kernel read on a Full-only runtime), or a
|
|
15
|
+
* per-call sandbox escalation under a restricted profile, whose reach is full (`filesystem:
|
|
16
|
+
* device`, `network: environment`) while it keeps its conversation's restricted profile.
|
|
17
|
+
*/
|
|
18
|
+
export declare const isFullExecutionScope: (scope: SandboxOperationScope | SandboxBrowseScope) => boolean;
|
|
2
19
|
export declare const isExecutionMethod: (method: string) => method is "exec" | "backgroundStart";
|
|
3
20
|
/** Null column means absent historical/native provenance; grants:null records an explicit absence. */
|
|
4
21
|
export interface StartingExecutionGrants {
|
|
@@ -1,4 +1,23 @@
|
|
|
1
|
-
import { validateAllowHost } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { SandboxScopeDeniedError, validateAllowHost, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* A call that asked to run outside the sandbox (`sandbox: "escalated"`) whose escalation grant no
|
|
4
|
+
* longer matches at admission: the device, its Full access ceiling or the permission scope
|
|
5
|
+
* changed after the approval. A typed pre-effect scope refusal (nothing ran), never a silent
|
|
6
|
+
* downgrade to the restricted scope; the tool tells the model to ask again.
|
|
7
|
+
*/
|
|
8
|
+
export class EscalationGrantMissingError extends SandboxScopeDeniedError {
|
|
9
|
+
escalationGrantMissing = true;
|
|
10
|
+
}
|
|
11
|
+
export const isEscalationGrantMissing = (e) => e instanceof Error && e.escalationGrantMissing === true;
|
|
12
|
+
/**
|
|
13
|
+
* Whether an operation scope needs the Full access ceiling and the runtime's Full support: a Full
|
|
14
|
+
* access operation (its reach is full, or narrowed for a kernel read on a Full-only runtime), or a
|
|
15
|
+
* per-call sandbox escalation under a restricted profile, whose reach is full (`filesystem:
|
|
16
|
+
* device`, `network: environment`) while it keeps its conversation's restricted profile.
|
|
17
|
+
*/
|
|
18
|
+
export const isFullExecutionScope = (scope) => "profile" in scope &&
|
|
19
|
+
(scope.profile === "full-access" ||
|
|
20
|
+
(scope.filesystem.kind === "device" && scope.network.kind === "environment"));
|
|
2
21
|
export const isExecutionMethod = (method) => method === "exec" || method === "backgroundStart";
|
|
3
22
|
export function parseStartingExecutionGrants(value) {
|
|
4
23
|
const record = (v, keys) => {
|
|
@@ -10,6 +10,7 @@ import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
|
10
10
|
import { PermissionCallGrants } from "./permission-call-grants.js";
|
|
11
11
|
import type { PermissionCallRef, PermissionReviewSnapshot } from "./permission-call-types.js";
|
|
12
12
|
import { PermissionConfigPublication } from "./permission-config-publication.js";
|
|
13
|
+
import type { AppliedEnvironment } from "./permission-context-types.js";
|
|
13
14
|
import { type PermissionContextSubject } from "./permission-context-types.js";
|
|
14
15
|
import { PermissionFacts } from "./permission-facts.js";
|
|
15
16
|
import type { SandboxUseContext } from "./use-context.js";
|
|
@@ -30,10 +31,23 @@ export interface PermissionScopeFacts {
|
|
|
30
31
|
allowedHosts: readonly string[];
|
|
31
32
|
fullAccessCeiling: boolean;
|
|
32
33
|
fullConsent?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* An approved per-call sandbox escalation of this exact call (its immutable call grant): the
|
|
36
|
+
* operation gets full execution under the conversation's restricted profile, within the same
|
|
37
|
+
* Full access ceiling. Only admission sets it, from the grant row; never a caller.
|
|
38
|
+
*/
|
|
39
|
+
escalated?: boolean;
|
|
33
40
|
}
|
|
34
41
|
/** Only server-resolved facts enter this constructor; callers never submit roots or profile. */
|
|
35
42
|
export declare function intersectPermissionScope(f: PermissionScopeFacts): SandboxOperationScope;
|
|
36
43
|
/** Fresh authority shape only. Provider dispatch must add durable admission fencing before use. */
|
|
44
|
+
/**
|
|
45
|
+
* The read roots of a restricted profile: the working root, plus the held instance's
|
|
46
|
+
* kernel-staged skills root (its committed roots), read-only, so a staged skill's scripts run
|
|
47
|
+
* (`sh /skills/<name>@<digest>/…`). Never writable; nothing else is added. Sorted by code point,
|
|
48
|
+
* as the recorded context requires.
|
|
49
|
+
*/
|
|
50
|
+
export declare function restrictedReadRoots(workingRoot: string, applied: Pick<AppliedEnvironment, "roots"> | null | undefined): string[];
|
|
37
51
|
export declare class SandboxOperationAuthority {
|
|
38
52
|
private readonly callGrants;
|
|
39
53
|
private readonly publication;
|