@capybara-hq/kernel 0.1.0-rc.68 → 0.1.0-rc.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/admin.module.js +2 -0
- package/dist/admin/health.service.d.ts +11 -4
- package/dist/admin/health.service.js +33 -17
- package/dist/background/poll.job.js +2 -2
- package/dist/background/tasks.service.d.ts +5 -5
- package/dist/background/tasks.service.js +9 -8
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/requests.service.js +1 -1
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +9 -9
- package/dist/conversations/conversations.controller.d.ts +8 -3
- package/dist/conversations/conversations.controller.js +8 -3
- package/dist/conversations/conversations.service.d.ts +33 -15
- package/dist/conversations/conversations.service.js +60 -10
- package/dist/conversations/events.d.ts +21 -41
- package/dist/conversations/events.js +57 -31
- package/dist/conversations/permission-profiles.controller.d.ts +6 -4
- package/dist/conversations/permission-profiles.service.d.ts +6 -4
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +77 -6
- package/dist/ctx/device-provider-check.d.ts +6 -2
- package/dist/ctx/device-provider-check.js +17 -2
- package/dist/db/kernel-schema.d.ts +10 -48
- package/dist/devices/access.d.ts +3 -4
- package/dist/devices/access.js +3 -4
- package/dist/devices/conversation-devices.d.ts +1 -3
- package/dist/devices/conversation-devices.js +2 -7
- package/dist/devices/device-projects.service.js +24 -29
- package/dist/devices/device-provider-selection.d.ts +5 -6
- package/dist/devices/device-provider-selection.js +8 -9
- package/dist/devices/devices.controller.d.ts +8 -21
- package/dist/devices/devices.controller.js +9 -34
- package/dist/devices/devices.module.js +6 -4
- package/dist/devices/devices.schemas.d.ts +1 -5
- package/dist/devices/devices.schemas.js +1 -5
- package/dist/devices/devices.service.d.ts +84 -147
- package/dist/devices/devices.service.js +134 -229
- package/dist/devices/dto.d.ts +5 -32
- package/dist/devices/dto.js +5 -37
- package/dist/devices/errors.d.ts +6 -5
- package/dist/devices/errors.js +7 -8
- package/dist/devices/project-rules.d.ts +9 -11
- package/dist/devices/project-rules.js +7 -7
- package/dist/devices/working-root.d.ts +3 -6
- package/dist/devices/working-root.js +3 -8
- package/dist/dial-in/access.d.ts +23 -0
- package/dist/dial-in/access.js +64 -0
- package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
- package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
- package/dist/dial-in/auth.module.d.ts +7 -0
- package/dist/dial-in/auth.module.js +27 -0
- package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
- package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
- package/dist/dial-in/dial-in.module.d.ts +9 -0
- package/dist/dial-in/dial-in.module.js +37 -0
- package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
- package/dist/{local-devices → dial-in}/dto.js +14 -2
- package/dist/dial-in/envelope.d.ts +95 -0
- package/dist/dial-in/envelope.js +89 -0
- package/dist/dial-in/gateway.d.ts +214 -0
- package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
- package/dist/dial-in/handlers.d.ts +47 -0
- package/dist/dial-in/handlers.js +84 -0
- package/dist/dial-in/machines.d.ts +155 -0
- package/dist/dial-in/machines.js +383 -0
- package/dist/dial-in/relay.d.ts +135 -0
- package/dist/dial-in/relay.js +444 -0
- package/dist/dial-in/relay.module.d.ts +7 -0
- package/dist/dial-in/relay.module.js +24 -0
- package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
- package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
- package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
- package/dist/{local-devices → dial-in}/targets.js +3 -48
- package/dist/errors.d.ts +8 -27
- package/dist/errors.js +8 -27
- package/dist/extensions/bootstrap.d.ts +5 -0
- package/dist/extensions/bootstrap.js +10 -1
- package/dist/extensions/extensions.module.js +6 -0
- package/dist/extensions/host.d.ts +6 -0
- package/dist/extensions/host.js +12 -2
- package/dist/extensions/permission-set.d.ts +15 -1
- package/dist/extensions/permission-set.js +11 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/http/api.module.js +4 -4
- package/dist/http/gateway-routes.d.ts +1 -1
- package/dist/http/gateway-routes.js +1 -1
- package/dist/http/meta.controller.js +1 -1
- package/dist/identity/settings.d.ts +1 -1
- package/dist/identity/settings.js +6 -8
- package/dist/infra/config/kernel-config.service.js +2 -2
- package/dist/infra/outbox/registry.d.ts +0 -14
- package/dist/infra/outbox/registry.js +0 -15
- package/dist/infra/throttler/named-throttlers.d.ts +1 -1
- package/dist/infra/throttler/named-throttlers.js +1 -1
- package/dist/kernel.module.js +0 -3
- package/dist/orgs/settings.service.js +5 -10
- package/dist/overrides.d.ts +0 -4
- package/dist/overrides.js +0 -2
- package/dist/platform/exclusions.js +5 -5
- package/dist/platform/ops/admin.ops.js +1 -1
- package/dist/platform/ops/conversations.ops.js +5 -2
- package/dist/platform/ops/devices.ops.js +11 -24
- package/dist/platform/ops/inbox.ops.js +1 -1
- package/dist/roles/gateway-role.d.ts +3 -3
- package/dist/roles/gateway-role.js +4 -4
- package/dist/roles/gateway.module.d.ts +1 -1
- package/dist/roles/gateway.module.js +5 -5
- package/dist/runtime/context/device-paths.d.ts +4 -1
- package/dist/runtime/context/permission-profile.js +5 -5
- package/dist/runtime/maintenance.d.ts +2 -5
- package/dist/runtime/maintenance.js +9 -19
- package/dist/runtime/project/knowledge.js +4 -5
- package/dist/runtime/project/knowledge.service.js +2 -1
- package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
- package/dist/sandbox/cloud-permission-snapshot.js +1 -3
- package/dist/sandbox/device-reports.d.ts +74 -14
- package/dist/sandbox/device-reports.js +190 -33
- package/dist/sandbox/device-reports.module.d.ts +7 -0
- package/dist/sandbox/device-reports.module.js +25 -0
- package/dist/sandbox/device-sandbox.d.ts +39 -41
- package/dist/sandbox/device-sandbox.js +44 -83
- package/dist/sandbox/kernel-read.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.d.ts +11 -59
- package/dist/sandbox/legacy-retirement.js +34 -186
- package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.module.js +2 -2
- package/dist/sandbox/managed-device-context.d.ts +16 -4
- package/dist/sandbox/managed-device-context.js +25 -8
- package/dist/sandbox/managed-device-context.module.js +4 -0
- package/dist/sandbox/modes.d.ts +3 -12
- package/dist/sandbox/modes.js +2 -14
- package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
- package/dist/{local-devices → sandbox}/network-grants.js +4 -49
- package/dist/sandbox/operation-authority-types.d.ts +2 -1
- package/dist/sandbox/operation-authority.d.ts +6 -20
- package/dist/sandbox/operation-authority.js +43 -104
- package/dist/sandbox/operation-authority.module.js +1 -1
- package/dist/sandbox/operation-intents.d.ts +4 -1
- package/dist/sandbox/operation-intents.js +11 -2
- package/dist/sandbox/operation-reconcile.job.js +2 -4
- package/dist/sandbox/permission-availability.d.ts +6 -7
- package/dist/sandbox/permission-availability.js +7 -10
- package/dist/sandbox/permission-call-grants.d.ts +2 -1
- package/dist/sandbox/permission-call-grants.js +1 -7
- package/dist/sandbox/permission-call-types.d.ts +4 -4
- package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
- package/dist/sandbox/permission-ceiling-writes.js +8 -35
- package/dist/sandbox/permission-config-publication.d.ts +9 -1
- package/dist/sandbox/permission-config-publication.js +29 -21
- package/dist/sandbox/permission-context-types.d.ts +17 -10
- package/dist/sandbox/permission-facts.d.ts +98 -95
- package/dist/sandbox/permission-facts.js +160 -314
- package/dist/sandbox/permission-instance-writes.d.ts +23 -37
- package/dist/sandbox/permission-instance-writes.js +44 -121
- package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
- package/dist/sandbox/permission-runtime-reports.js +105 -122
- package/dist/sandbox/providers.d.ts +26 -38
- package/dist/sandbox/providers.js +36 -18
- package/dist/sandbox/request-not-sent.d.ts +2 -13
- package/dist/sandbox/request-not-sent.js +2 -13
- package/dist/sandbox/review/permission-candidate.d.ts +13 -8
- package/dist/sandbox/review/permission-candidate.js +38 -48
- package/dist/sandbox/sandbox.module.js +7 -3
- package/dist/sandbox/sandbox.service.d.ts +49 -59
- package/dist/sandbox/sandbox.service.js +139 -259
- package/dist/schedules/fire.d.ts +15 -6
- package/dist/schedules/fire.js +27 -13
- package/dist/schedules/grant-rules.js +1 -1
- package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
- package/dist/schedules/scheduled-tasks.service.js +1 -4
- package/dist/schedules/schedules.module.js +5 -3
- package/dist/skills/invoke.d.ts +1 -1
- package/dist/skills/invoke.js +2 -3
- package/dist/tools/approvals.service.d.ts +8 -5
- package/dist/tools/approvals.service.js +5 -5
- package/dist/tools/builtins/sandbox/bash.js +1 -2
- package/dist/tools/builtins/sandbox/common.d.ts +15 -9
- package/dist/tools/builtins/sandbox/common.js +37 -38
- package/dist/tools/network-asks.d.ts +19 -22
- package/dist/tools/network-asks.js +15 -21
- package/dist/tools/pipeline.d.ts +6 -7
- package/dist/tools/pipeline.js +17 -21
- package/dist/tools/tools.module.js +3 -7
- package/package.json +3 -4
- package/src/migrations/0177_dial_in_contract.sql +32 -0
- package/dist/local-devices/device-auth.module.d.ts +0 -7
- package/dist/local-devices/device-auth.module.js +0 -25
- package/dist/local-devices/device-policy.service.d.ts +0 -213
- package/dist/local-devices/device-policy.service.js +0 -605
- package/dist/local-devices/instance-bindings.d.ts +0 -82
- package/dist/local-devices/instance-bindings.js +0 -307
- package/dist/local-devices/local-device-gateway.d.ts +0 -153
- package/dist/local-devices/local-device-provider.d.ts +0 -122
- package/dist/local-devices/local-device-provider.js +0 -326
- package/dist/local-devices/local-devices.module.d.ts +0 -31
- package/dist/local-devices/local-devices.module.js +0 -100
- package/dist/local-devices/machines.d.ts +0 -211
- package/dist/local-devices/machines.js +0 -766
- package/dist/local-devices/owner-report.d.ts +0 -81
- package/dist/local-devices/owner-report.js +0 -150
- package/dist/local-devices/owner-reports.d.ts +0 -48
- package/dist/local-devices/owner-reports.js +0 -208
- package/dist/local-devices/policy-op-jobs.d.ts +0 -15
- package/dist/local-devices/policy-op-jobs.js +0 -12
- package/dist/local-devices/policy-summary.d.ts +0 -102
- package/dist/local-devices/policy-summary.js +0 -155
- package/dist/local-devices/relay.d.ts +0 -166
- package/dist/local-devices/relay.js +0 -559
- package/dist/tools/device-op-resolver.d.ts +0 -34
- package/dist/tools/device-op-resolver.js +0 -120
- /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
- /package/dist/{local-devices → dial-in}/keys.js +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { type BindInstanceRequest, type BindInstanceResult, type SandboxPermissionSupport } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
4
|
-
import { LegacyRetirementStore } from "../sandbox/legacy-retirement.js";
|
|
5
|
-
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
6
|
-
import { PermissionRuntimeReports } from "../sandbox/permission-runtime-reports.js";
|
|
7
|
-
import { type SandboxInstanceBinder } from "../sandbox/providers.js";
|
|
8
|
-
import { OwnerReports } from "./owner-reports.js";
|
|
9
|
-
import { LocalDeviceRelay } from "./relay.js";
|
|
10
|
-
/** The committed binding of a local instance generation, as the coordinator sends it. */
|
|
11
|
-
export interface CommittedBinding {
|
|
12
|
-
orgId: string;
|
|
13
|
-
request: BindInstanceRequest;
|
|
14
|
-
status: "awaiting-device" | "installed";
|
|
15
|
-
/** The machine the binding was committed for (null: none was active). */
|
|
16
|
-
machineId: string | null;
|
|
17
|
-
}
|
|
18
|
-
/** The binding cannot be completed; the instance stays unprobed and admits nothing. */
|
|
19
|
-
export declare class InstanceBindingError extends Error {
|
|
20
|
-
name: string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Post-commit binding of a local instance generation (permission runtime cutover B4, staged on the
|
|
24
|
-
* v3 path; protocol 2 stays active). `commitHandle` allocated the generation and committed an
|
|
25
|
-
* `awaiting-device` binding; before the lifecycle holder downgrades to shared use it calls
|
|
26
|
-
* {@link bind}, which sends the private `bindInstance` RPC to the authenticated machine outside
|
|
27
|
-
* any transaction and then, under the device authority writer, verifies the exact instance row,
|
|
28
|
-
* generation, binding id and machine, records the runtime report and marks the binding
|
|
29
|
-
* `installed`. A retry (reconnect, lost reply, another replica) resends the identical binding; it
|
|
30
|
-
* never allocates a new generation. A delayed answer for an old generation cannot populate a
|
|
31
|
-
* replacement row.
|
|
32
|
-
*/
|
|
33
|
-
export declare class LocalInstanceBindings implements SandboxInstanceBinder {
|
|
34
|
-
private readonly db;
|
|
35
|
-
readonly txHost: TransactionHost;
|
|
36
|
-
private readonly relay;
|
|
37
|
-
private readonly ceilings;
|
|
38
|
-
private readonly reports;
|
|
39
|
-
private readonly owners;
|
|
40
|
-
/** The durable legacy gate checked before any bind is sent (8.5). */
|
|
41
|
-
private readonly retirement;
|
|
42
|
-
constructor(db: KernelDb, txHost: TransactionHost, relay: Pick<LocalDeviceRelay, "callV3" | "connection">, ceilings: PermissionCeilingWrites, reports: PermissionRuntimeReports, owners: Pick<OwnerReports, "recordLocked">,
|
|
43
|
-
/** The durable legacy gate checked before any bind is sent (8.5). */
|
|
44
|
-
retirement: Pick<LegacyRetirementStore, "hasUnresolved">);
|
|
45
|
-
/** The binding committed for the device's current local instance, or null (no allocation). */
|
|
46
|
-
committed(deviceId: string): Promise<CommittedBinding | null>;
|
|
47
|
-
/**
|
|
48
|
-
* Whether the device's current local instance generation has an installed binding (the staged
|
|
49
|
-
* acquire path's shared-use condition). No committed binding reads as not installed.
|
|
50
|
-
*/
|
|
51
|
-
installed(deviceId: string): Promise<boolean>;
|
|
52
|
-
/** The current generation's committed binding status, or null when none was committed. */
|
|
53
|
-
status(deviceId: string): Promise<"installed" | "awaiting-device" | null>;
|
|
54
|
-
/**
|
|
55
|
-
* The permission support the device attested for its current instance generation (the staged
|
|
56
|
-
* provider's `permissionSupport`): only the report recorded with an installed binding of that
|
|
57
|
-
* generation, for the active machine's program version. Anything else (unbound, awaiting, a
|
|
58
|
-
* changed identity) reads as no support with its reason: nothing is probed, and a missing
|
|
59
|
-
* report never admits an operation.
|
|
60
|
-
*/
|
|
61
|
-
permissionSupport(deviceId: string): Promise<SandboxPermissionSupport>;
|
|
62
|
-
/**
|
|
63
|
-
* Sends the committed binding and installs the verified answer. The caller holds the device's
|
|
64
|
-
* lifecycle lease; no transaction is open across the RPC.
|
|
65
|
-
*/
|
|
66
|
-
bind(deviceId: string, signal: AbortSignal): Promise<BindInstanceResult | null>;
|
|
67
|
-
/**
|
|
68
|
-
* Moves a still awaiting binding to the active machine: its previous becomes the last binding
|
|
69
|
-
* committed for that machine. Under the device writer, against the exact generation and id.
|
|
70
|
-
*/
|
|
71
|
-
retarget(deviceId: string, committed: CommittedBinding, machineId: string): Promise<void>;
|
|
72
|
-
private activeMachine;
|
|
73
|
-
/**
|
|
74
|
-
* Under the device authority writer: the answer must be for the exact committed generation and
|
|
75
|
-
* binding of the current row, from the machine the request went to. A different environment
|
|
76
|
-
* fingerprint than the previous installed generation resets Full consent; the first verified
|
|
77
|
-
* proof of an unprobed device does not (its semantic scope was what the person consented to).
|
|
78
|
-
*/
|
|
79
|
-
install(deviceId: string, machineId: string, committed: CommittedBinding, answer: BindInstanceResult,
|
|
80
|
-
/** The authenticated connection the answer came on (recorded with its owner report). */
|
|
81
|
-
connectionId?: string | null): Promise<void>;
|
|
82
|
-
}
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
-
};
|
|
10
|
-
import { DeviceProtocolError, parseOperationResult, } from "@capybara-hq/plugin-sdk";
|
|
11
|
-
import { Inject, Injectable } from "@nestjs/common";
|
|
12
|
-
import { sql } from "kysely";
|
|
13
|
-
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
|
-
import { runOutsideTransaction, TransactionHost } from "../infra/database/transaction-host.js";
|
|
15
|
-
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
16
|
-
import { LegacyRetirementStore } from "../sandbox/legacy-retirement.js";
|
|
17
|
-
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
18
|
-
import { PermissionRuntimeReports, readCurrentReport, runtimeIdentity, } from "../sandbox/permission-runtime-reports.js";
|
|
19
|
-
import { LOCAL_PROVIDER } from "../sandbox/providers.js";
|
|
20
|
-
import { OP_DEADLINE_MS } from "./local-device-provider.js";
|
|
21
|
-
import { OwnerReports } from "./owner-reports.js";
|
|
22
|
-
import { LocalDeviceRelay } from "./relay.js";
|
|
23
|
-
/** The binding cannot be completed; the instance stays unprobed and admits nothing. */
|
|
24
|
-
export class InstanceBindingError extends Error {
|
|
25
|
-
name = "InstanceBindingError";
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Post-commit binding of a local instance generation (permission runtime cutover B4, staged on the
|
|
29
|
-
* v3 path; protocol 2 stays active). `commitHandle` allocated the generation and committed an
|
|
30
|
-
* `awaiting-device` binding; before the lifecycle holder downgrades to shared use it calls
|
|
31
|
-
* {@link bind}, which sends the private `bindInstance` RPC to the authenticated machine outside
|
|
32
|
-
* any transaction and then, under the device authority writer, verifies the exact instance row,
|
|
33
|
-
* generation, binding id and machine, records the runtime report and marks the binding
|
|
34
|
-
* `installed`. A retry (reconnect, lost reply, another replica) resends the identical binding; it
|
|
35
|
-
* never allocates a new generation. A delayed answer for an old generation cannot populate a
|
|
36
|
-
* replacement row.
|
|
37
|
-
*/
|
|
38
|
-
let LocalInstanceBindings = class LocalInstanceBindings {
|
|
39
|
-
db;
|
|
40
|
-
txHost;
|
|
41
|
-
relay;
|
|
42
|
-
ceilings;
|
|
43
|
-
reports;
|
|
44
|
-
owners;
|
|
45
|
-
retirement;
|
|
46
|
-
constructor(db, txHost, relay, ceilings, reports, owners,
|
|
47
|
-
/** The durable legacy gate checked before any bind is sent (8.5). */
|
|
48
|
-
retirement) {
|
|
49
|
-
this.db = db;
|
|
50
|
-
this.txHost = txHost;
|
|
51
|
-
this.relay = relay;
|
|
52
|
-
this.ceilings = ceilings;
|
|
53
|
-
this.reports = reports;
|
|
54
|
-
this.owners = owners;
|
|
55
|
-
this.retirement = retirement;
|
|
56
|
-
}
|
|
57
|
-
/** The binding committed for the device's current local instance, or null (no allocation). */
|
|
58
|
-
async committed(deviceId) {
|
|
59
|
-
const instance = await this.db
|
|
60
|
-
.selectFrom("device_instances")
|
|
61
|
-
.select(["org_id", "handle", "provider", "created_at"])
|
|
62
|
-
.where("device_id", "=", deviceId)
|
|
63
|
-
.where("status", "in", ["running", "suspended"])
|
|
64
|
-
.executeTakeFirst();
|
|
65
|
-
if (!instance || instance.provider !== LOCAL_PROVIDER || !instance.handle)
|
|
66
|
-
return null;
|
|
67
|
-
const binding = await this.db
|
|
68
|
-
.selectFrom("device_instance_bindings")
|
|
69
|
-
.select(["instance_generation", "binding_id", "previous_generation", "status", "machine_id"])
|
|
70
|
-
.where("device_id", "=", deviceId)
|
|
71
|
-
.where("instance_generation", "=", String(instance.created_at.getTime()))
|
|
72
|
-
.executeTakeFirst();
|
|
73
|
-
if (!binding)
|
|
74
|
-
return null;
|
|
75
|
-
const row = { ...instance, ...binding };
|
|
76
|
-
return {
|
|
77
|
-
orgId: row.org_id,
|
|
78
|
-
status: row.status,
|
|
79
|
-
machineId: row.machine_id,
|
|
80
|
-
request: {
|
|
81
|
-
instanceId: instance.handle.id,
|
|
82
|
-
instanceGeneration: row.instance_generation,
|
|
83
|
-
bindingId: row.binding_id,
|
|
84
|
-
expectedPreviousGeneration: row.previous_generation,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Whether the device's current local instance generation has an installed binding (the staged
|
|
90
|
-
* acquire path's shared-use condition). No committed binding reads as not installed.
|
|
91
|
-
*/
|
|
92
|
-
async installed(deviceId) {
|
|
93
|
-
return (await this.status(deviceId)) === "installed";
|
|
94
|
-
}
|
|
95
|
-
/** The current generation's committed binding status, or null when none was committed. */
|
|
96
|
-
async status(deviceId) {
|
|
97
|
-
return (await this.committed(deviceId))?.status ?? null;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The permission support the device attested for its current instance generation (the staged
|
|
101
|
-
* provider's `permissionSupport`): only the report recorded with an installed binding of that
|
|
102
|
-
* generation, for the active machine's program version. Anything else (unbound, awaiting, a
|
|
103
|
-
* changed identity) reads as no support with its reason: nothing is probed, and a missing
|
|
104
|
-
* report never admits an operation.
|
|
105
|
-
*/
|
|
106
|
-
async permissionSupport(deviceId) {
|
|
107
|
-
const machine = await this.db
|
|
108
|
-
.selectFrom("device_machines")
|
|
109
|
-
.select("program_version")
|
|
110
|
-
.where("device_id", "=", deviceId)
|
|
111
|
-
.where("revoked_at", "is", null)
|
|
112
|
-
.executeTakeFirst();
|
|
113
|
-
const { availability } = await readCurrentReport(this.db.db, deviceId, LOCAL_PROVIDER, machine?.program_version ?? undefined);
|
|
114
|
-
if (availability.state === "supported")
|
|
115
|
-
return availability.report;
|
|
116
|
-
return {
|
|
117
|
-
version: 2,
|
|
118
|
-
boundary: "operation",
|
|
119
|
-
restricted: null,
|
|
120
|
-
network: { openPublic: false, allowlist: false, perOperationHosts: false },
|
|
121
|
-
outsideSandbox: false,
|
|
122
|
-
background: false,
|
|
123
|
-
unavailableReason: availability.state === "unsupported"
|
|
124
|
-
? availability.reason
|
|
125
|
-
: "The device has not attested an installed runtime for this instance yet; reconnect capybara-device and retry",
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Sends the committed binding and installs the verified answer. The caller holds the device's
|
|
130
|
-
* lifecycle lease; no transaction is open across the RPC.
|
|
131
|
-
*/
|
|
132
|
-
async bind(deviceId, signal) {
|
|
133
|
-
// the device round trip may take the whole operation deadline: never inside a transaction
|
|
134
|
-
if (this.txHost.current())
|
|
135
|
-
throw new InstanceBindingError("bindInstance must not run inside a transaction");
|
|
136
|
-
const found = await this.committed(deviceId);
|
|
137
|
-
if (!found)
|
|
138
|
-
throw new InstanceBindingError("No committed local instance to bind");
|
|
139
|
-
if (found.status === "installed")
|
|
140
|
-
return null;
|
|
141
|
-
// the kernel's durable legacy gate (8.5): an old incarnation of this device that may still
|
|
142
|
-
// run legacy work blocks every new binding; a new generation never clears it
|
|
143
|
-
if (await this.retirement.hasUnresolved(deviceId))
|
|
144
|
-
throw new InstanceBindingError("The device has an unresolved legacy retirement obligation; no instance can be bound");
|
|
145
|
-
const machineId = await this.activeMachine(deviceId);
|
|
146
|
-
let committed = found;
|
|
147
|
-
// a re-login since the commit: the binding follows the machine it is sent to, before the
|
|
148
|
-
// send, so a lost answer leaves the chain naming what that machine's device may have stored
|
|
149
|
-
if (committed.machineId !== machineId) {
|
|
150
|
-
await runOutsideTransaction(() => this.retarget(deviceId, committed, machineId));
|
|
151
|
-
const again = await this.committed(deviceId);
|
|
152
|
-
if (!again)
|
|
153
|
-
throw new InstanceBindingError("No committed local instance to bind");
|
|
154
|
-
committed = again;
|
|
155
|
-
}
|
|
156
|
-
const connection = await this.relay.connection(deviceId);
|
|
157
|
-
const answer = parseOperationResult("bindInstance", await this.relay.callV3(deviceId, "bindInstance", { ...committed.request }, {
|
|
158
|
-
deadlineMs: OP_DEADLINE_MS,
|
|
159
|
-
signal,
|
|
160
|
-
connection,
|
|
161
|
-
}), committed.request);
|
|
162
|
-
await runOutsideTransaction(() => this.install(deviceId, machineId, committed, answer, connection.connectionId));
|
|
163
|
-
return answer;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Moves a still awaiting binding to the active machine: its previous becomes the last binding
|
|
167
|
-
* committed for that machine. Under the device writer, against the exact generation and id.
|
|
168
|
-
*/
|
|
169
|
-
async retarget(deviceId, committed, machineId) {
|
|
170
|
-
await this.ceilings.lock({ orgId: committed.orgId, deviceId }, "device");
|
|
171
|
-
const { instanceGeneration, bindingId } = committed.request;
|
|
172
|
-
const previous = await this.db
|
|
173
|
-
.selectFrom("device_instance_bindings")
|
|
174
|
-
.select("instance_generation")
|
|
175
|
-
.where("device_id", "=", deviceId)
|
|
176
|
-
.where("machine_id", "=", machineId)
|
|
177
|
-
.where(sql `instance_generation::bigint < ${instanceGeneration}::bigint`)
|
|
178
|
-
.orderBy(sql `instance_generation::bigint`, "desc")
|
|
179
|
-
.limit(1)
|
|
180
|
-
.executeTakeFirst();
|
|
181
|
-
const moved = await this.db
|
|
182
|
-
.updateTable("device_instance_bindings")
|
|
183
|
-
.set({ machine_id: machineId, previous_generation: previous?.instance_generation ?? null })
|
|
184
|
-
.where("device_id", "=", deviceId)
|
|
185
|
-
.where("instance_generation", "=", instanceGeneration)
|
|
186
|
-
.where("binding_id", "=", bindingId)
|
|
187
|
-
.where("status", "=", "awaiting-device")
|
|
188
|
-
.executeTakeFirst();
|
|
189
|
-
if (!moved.numUpdatedRows)
|
|
190
|
-
throw new InstanceBindingError("The binding changed before it could follow the new machine");
|
|
191
|
-
}
|
|
192
|
-
async activeMachine(deviceId) {
|
|
193
|
-
const machine = await this.db
|
|
194
|
-
.selectFrom("device_machines")
|
|
195
|
-
.select("id")
|
|
196
|
-
.where("device_id", "=", deviceId)
|
|
197
|
-
.where("revoked_at", "is", null)
|
|
198
|
-
.executeTakeFirst();
|
|
199
|
-
if (!machine)
|
|
200
|
-
throw new InstanceBindingError("The device has no active machine to bind");
|
|
201
|
-
return machine.id;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Under the device authority writer: the answer must be for the exact committed generation and
|
|
205
|
-
* binding of the current row, from the machine the request went to. A different environment
|
|
206
|
-
* fingerprint than the previous installed generation resets Full consent; the first verified
|
|
207
|
-
* proof of an unprobed device does not (its semantic scope was what the person consented to).
|
|
208
|
-
*/
|
|
209
|
-
async install(deviceId, machineId, committed, answer,
|
|
210
|
-
/** The authenticated connection the answer came on (recorded with its owner report). */
|
|
211
|
-
connectionId = null) {
|
|
212
|
-
const subject = { orgId: committed.orgId, deviceId };
|
|
213
|
-
await this.ceilings.lock(subject, "device");
|
|
214
|
-
const { request } = committed;
|
|
215
|
-
const identity = runtimeIdentity(answer.runtimeIdentity);
|
|
216
|
-
if (answer.bindingId !== request.bindingId ||
|
|
217
|
-
answer.instanceGeneration !== request.instanceGeneration ||
|
|
218
|
-
answer.instanceId !== request.instanceId ||
|
|
219
|
-
identity.instanceGeneration !== request.instanceGeneration)
|
|
220
|
-
throw new DeviceProtocolError("Binding answer belongs to another instance generation");
|
|
221
|
-
const instance = await this.db
|
|
222
|
-
.selectFrom("device_instances")
|
|
223
|
-
.select(["provider", "created_at", "handle", "status"])
|
|
224
|
-
.where("device_id", "=", deviceId)
|
|
225
|
-
.forUpdate()
|
|
226
|
-
.executeTakeFirst();
|
|
227
|
-
if (!instance ||
|
|
228
|
-
instance.provider !== LOCAL_PROVIDER ||
|
|
229
|
-
String(instance.created_at.getTime()) !== request.instanceGeneration ||
|
|
230
|
-
instance.handle?.id !== request.instanceId ||
|
|
231
|
-
!["running", "suspended"].includes(instance.status))
|
|
232
|
-
throw new InstanceBindingError("The instance was replaced before its binding completed");
|
|
233
|
-
const binding = await this.db
|
|
234
|
-
.selectFrom("device_instance_bindings")
|
|
235
|
-
.select(["binding_id", "status", "runtime_identity"])
|
|
236
|
-
.where("device_id", "=", deviceId)
|
|
237
|
-
.where("instance_generation", "=", request.instanceGeneration)
|
|
238
|
-
.forUpdate()
|
|
239
|
-
.executeTakeFirst();
|
|
240
|
-
if (!binding || binding.binding_id !== request.bindingId)
|
|
241
|
-
throw new InstanceBindingError("The binding id does not match the committed binding");
|
|
242
|
-
const machine = await this.db
|
|
243
|
-
.selectFrom("device_machines")
|
|
244
|
-
.select(["id", "program_version"])
|
|
245
|
-
.where("device_id", "=", deviceId)
|
|
246
|
-
.where("revoked_at", "is", null)
|
|
247
|
-
.executeTakeFirst();
|
|
248
|
-
if (machine?.id !== machineId)
|
|
249
|
-
throw new InstanceBindingError("The device's machine changed before its binding completed");
|
|
250
|
-
if (!machine.program_version)
|
|
251
|
-
throw new InstanceBindingError("The machine has not reported its program version");
|
|
252
|
-
if (binding.status === "installed")
|
|
253
|
-
return;
|
|
254
|
-
// B2: the answer's authenticated owner report enters the common owner writer; a lower
|
|
255
|
-
// sequence is ignored there and a conflicting one blocks new authority, neither failing the
|
|
256
|
-
// installation
|
|
257
|
-
await this.owners.recordLocked(machineId, answer.ownerCeiling, {
|
|
258
|
-
connectionId,
|
|
259
|
-
via: "bind",
|
|
260
|
-
});
|
|
261
|
-
// the environment this device last proved, whichever generation that was: the chain's
|
|
262
|
-
// previous may be a binding whose answer never arrived (never installed)
|
|
263
|
-
const previous = await this.db
|
|
264
|
-
.selectFrom("device_instance_bindings")
|
|
265
|
-
.select("runtime_identity")
|
|
266
|
-
.where("device_id", "=", deviceId)
|
|
267
|
-
.where("status", "=", "installed")
|
|
268
|
-
.where(sql `instance_generation::bigint < ${request.instanceGeneration}::bigint`)
|
|
269
|
-
.orderBy(sql `instance_generation::bigint`, "desc")
|
|
270
|
-
.limit(1)
|
|
271
|
-
.executeTakeFirst();
|
|
272
|
-
if (previous?.runtime_identity &&
|
|
273
|
-
previous.runtime_identity.imageFingerprint !== identity.imageFingerprint)
|
|
274
|
-
await this.ceilings.publishLocked(subject, "device", true, true);
|
|
275
|
-
await this.db
|
|
276
|
-
.updateTable("device_instance_bindings")
|
|
277
|
-
.set({
|
|
278
|
-
status: "installed",
|
|
279
|
-
machine_id: machineId,
|
|
280
|
-
runtime_identity: JSON.stringify(identity),
|
|
281
|
-
installed_at: sql `now()`,
|
|
282
|
-
installed_connection_id: connectionId,
|
|
283
|
-
})
|
|
284
|
-
.where("device_id", "=", deviceId)
|
|
285
|
-
.where("instance_generation", "=", request.instanceGeneration)
|
|
286
|
-
.where("binding_id", "=", request.bindingId)
|
|
287
|
-
.execute();
|
|
288
|
-
await this.reports.record(deviceId, LOCAL_PROVIDER, machine.program_version, identity, answer.permissionSupport);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
__decorate([
|
|
292
|
-
Transactional()
|
|
293
|
-
], LocalInstanceBindings.prototype, "retarget", null);
|
|
294
|
-
__decorate([
|
|
295
|
-
Transactional()
|
|
296
|
-
], LocalInstanceBindings.prototype, "install", null);
|
|
297
|
-
LocalInstanceBindings = __decorate([
|
|
298
|
-
Injectable(),
|
|
299
|
-
__param(0, Inject(KernelDb)),
|
|
300
|
-
__param(1, Inject(TransactionHost)),
|
|
301
|
-
__param(2, Inject(LocalDeviceRelay)),
|
|
302
|
-
__param(3, Inject(PermissionCeilingWrites)),
|
|
303
|
-
__param(4, Inject(PermissionRuntimeReports)),
|
|
304
|
-
__param(5, Inject(OwnerReports)),
|
|
305
|
-
__param(6, Inject(LegacyRetirementStore))
|
|
306
|
-
], LocalInstanceBindings);
|
|
307
|
-
export { LocalInstanceBindings };
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { type ExtensionContext } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import type { WebSocket } from "@fastify/websocket";
|
|
3
|
-
import type { Redis } from "ioredis";
|
|
4
|
-
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
5
|
-
import { LockService } from "../infra/lock/lock.service.js";
|
|
6
|
-
import type { KernelLogger } from "../log.js";
|
|
7
|
-
import { type MachineIdentity, MachinesService } from "./machines.js";
|
|
8
|
-
/** WebSocket close codes the gateway uses (the program reads 4002 and 4003). */
|
|
9
|
-
export declare const DEVICE_CLOSE: {
|
|
10
|
-
/** The kernel is shutting down: reconnect (another gateway replica takes over). */
|
|
11
|
-
readonly shutdown: 1001;
|
|
12
|
-
/** A frame larger than `devices.local.maxFrameBytes` (sent by `ws` itself). */
|
|
13
|
-
readonly tooBig: 1009;
|
|
14
|
-
/** The kernel failed (e.g. the database): reconnect. */
|
|
15
|
-
readonly internal: 1011;
|
|
16
|
-
/** The lease was lost (renewal kept failing or the key was taken): reconnect. */
|
|
17
|
-
readonly leaseLost: 4001;
|
|
18
|
-
/** A newer connection of the device took over: the program exits. */
|
|
19
|
-
readonly replaced: 4002;
|
|
20
|
-
/** The machine's credential was revoked: the program exits. */
|
|
21
|
-
readonly revoked: 4003;
|
|
22
|
-
/** No valid `hello` first, or a frame that is not the current protocol from a device. */
|
|
23
|
-
readonly protocol: 4400;
|
|
24
|
-
/** The lease could not be claimed in time: reconnect. */
|
|
25
|
-
readonly claimTimeout: 4409;
|
|
26
|
-
};
|
|
27
|
-
/** How long the program has to send `hello` after the upgrade. */
|
|
28
|
-
export declare const HELLO_TIMEOUT_MS = 10000;
|
|
29
|
-
/** How often a connection is pinged; two pings without a pong close it. */
|
|
30
|
-
export declare const PING_INTERVAL_MS = 20000;
|
|
31
|
-
/** How long a new connection retries the lease after asking the holder to let go. */
|
|
32
|
-
export declare const CLAIM_TIMEOUT_MS = 5000;
|
|
33
|
-
/** The pause between two tries at the lease while claiming. */
|
|
34
|
-
export declare const CLAIM_RETRY_MS = 250;
|
|
35
|
-
type State = "hello" | "claiming" | "holding" | "closed";
|
|
36
|
-
/**
|
|
37
|
-
* One machine connection on this replica. Its state (the socket, the lease handle, the requests
|
|
38
|
-
* it forwarded) is the socket's own and lives exactly as long as the socket.
|
|
39
|
-
*/
|
|
40
|
-
declare class DeviceConnection {
|
|
41
|
-
private readonly gw;
|
|
42
|
-
private readonly socket;
|
|
43
|
-
readonly identity: MachineIdentity;
|
|
44
|
-
private readonly credential;
|
|
45
|
-
readonly token: `${string}-${string}-${string}-${string}-${string}`;
|
|
46
|
-
state: State;
|
|
47
|
-
private lease;
|
|
48
|
-
private readonly unsubscribes;
|
|
49
|
-
private helloTimer;
|
|
50
|
-
private pingTimer;
|
|
51
|
-
private missedPongs;
|
|
52
|
-
private lastTouch;
|
|
53
|
-
private lastAuth;
|
|
54
|
-
/** The drains (and the close after a revocation) run one after another. */
|
|
55
|
-
private chain;
|
|
56
|
-
/** Resolves once the lease is handed back (or was never held). */
|
|
57
|
-
private released;
|
|
58
|
-
/** The hello's record, then each policy frame's, one after another (never rejects). */
|
|
59
|
-
private recorded;
|
|
60
|
-
constructor(gw: LocalDeviceGateway, socket: WebSocket, identity: MachineIdentity, credential: string);
|
|
61
|
-
/**
|
|
62
|
-
* The id a connection fences requests and results with (sent to the machine in `ready`).
|
|
63
|
-
* Random and separate from the lease token, which stays internal to the kernel.
|
|
64
|
-
*/
|
|
65
|
-
readonly connectionId: `${string}-${string}-${string}-${string}-${string}`;
|
|
66
|
-
private effectiveCap;
|
|
67
|
-
/** The program run the hello named (`programRunId`), published with the capacity. */
|
|
68
|
-
private programRunId;
|
|
69
|
-
private ready;
|
|
70
|
-
/** Consecutive failed capacity publications on ping (this socket's own state). */
|
|
71
|
-
private publishFailures;
|
|
72
|
-
private publishCapacity;
|
|
73
|
-
get deviceId(): string;
|
|
74
|
-
start(): void;
|
|
75
|
-
private onFrame;
|
|
76
|
-
/**
|
|
77
|
-
* Stores one result and announces it (the relay's wire, relay.ts), only for a request taken for
|
|
78
|
-
* this device (ruling R20); anything else is dropped.
|
|
79
|
-
*/
|
|
80
|
-
private store;
|
|
81
|
-
/**
|
|
82
|
-
* Claims the device's lease; true when this connection holds it. The newest connection
|
|
83
|
-
* wins (ruling R21): when another connection holds the lease, a takeover is published (the
|
|
84
|
-
* holder yields to any takeover) and the lease retried every {@link CLAIM_RETRY_MS} for
|
|
85
|
-
* {@link CLAIM_TIMEOUT_MS}, then 4409 (the program reconnects). A claimer never yields.
|
|
86
|
-
*/
|
|
87
|
-
private claim;
|
|
88
|
-
/** Subscribes for this connection; a subscription that completes after the close is ended. */
|
|
89
|
-
private subscribe;
|
|
90
|
-
/** Queues one drain of the request list after the ones already queued. */
|
|
91
|
-
private drain;
|
|
92
|
-
private drainOnce;
|
|
93
|
-
/** The next ping (a chain of timeouts; the lease renewal is LockService's, not this timer's). */
|
|
94
|
-
private schedulePing;
|
|
95
|
-
private ping;
|
|
96
|
-
/** The credential still stands (membership, org and device are read live). */
|
|
97
|
-
private reauthenticate;
|
|
98
|
-
private traffic;
|
|
99
|
-
/** Closes the socket with `code` and hands the lease back; idempotent. */
|
|
100
|
-
close(code: number, reason: string): Promise<void>;
|
|
101
|
-
/** Stops timers and subscriptions and releases the lease (a lost one is abandoned). */
|
|
102
|
-
shutdown(): Promise<void>;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* The gateway role's half of the device relay (environments spec §13.4): holds the WebSocket
|
|
106
|
-
* connections of connected machines (`GET /device/connect`, device-routes.ts). One connection per
|
|
107
|
-
* device across replicas, under the lease `capk:device-lease:<deviceId>` (the newest
|
|
108
|
-
* connection wins: it publishes `device.takeover.<deviceId>` and the holder lets go). The
|
|
109
|
-
* holder drains `capk:device-req:<deviceId>` on every `device.req.<deviceId>` nudge,
|
|
110
|
-
* once after claiming and on every ping, marking each forwarded request taken for its device
|
|
111
|
-
* (`capk:device-taken:<id>`, TTL the reconnect grace plus the request's deadline plus a margin).
|
|
112
|
-
* A `res` is accepted only for a request taken for the socket's device: it is stored under
|
|
113
|
-
* `capk:device-res:<id>` for the rest of that TTL and published on `device.res.<id>`.
|
|
114
|
-
* `device.revoked.<deviceId>` closes the connection of that machine only (ruling R16). The
|
|
115
|
-
* sockets are this process's own; everything other replicas need is in Redis.
|
|
116
|
-
*/
|
|
117
|
-
export declare class LocalDeviceGateway {
|
|
118
|
-
readonly machines: Pick<MachinesService, "authenticate" | "recordHelloV3" | "recordPolicyV3" | "touch">;
|
|
119
|
-
readonly locks: Pick<LockService, "hold">;
|
|
120
|
-
readonly bus: ExtensionContext["bus"];
|
|
121
|
-
readonly redis: Redis;
|
|
122
|
-
private readonly config;
|
|
123
|
-
readonly log: Pick<KernelLogger, "info" | "warn">;
|
|
124
|
-
/** This replica's open connections (the sockets cannot live anywhere else). */
|
|
125
|
-
private readonly connections;
|
|
126
|
-
private stopping;
|
|
127
|
-
/** How often connections are pinged ({@link PING_INTERVAL_MS}; a test seam). */
|
|
128
|
-
pingIntervalMs: number;
|
|
129
|
-
constructor(machines: Pick<MachinesService, "authenticate" | "recordHelloV3" | "recordPolicyV3" | "touch">, locks: Pick<LockService, "hold">, bus: ExtensionContext["bus"], redis: Redis, config: KernelConfigService, log: Pick<KernelLogger, "info" | "warn">);
|
|
130
|
-
graceMs(): number;
|
|
131
|
-
leaseTtlMs(): number;
|
|
132
|
-
maxFrameBytes(): number;
|
|
133
|
-
/** Who a `Bearer` machine credential stands for, or null (checked before the upgrade). */
|
|
134
|
-
authenticate(credential: string): Promise<MachineIdentity | null>;
|
|
135
|
-
/**
|
|
136
|
-
* Serves one upgraded socket of a machine until it closes (protocol 4 only: the route refused any
|
|
137
|
-
* other header with 426, and a hello that is not protocol 4 closes 4400). The credential is
|
|
138
|
-
* checked again here, with the socket paused, so a credential revoked since the upgrade check
|
|
139
|
-
* never gets a connection.
|
|
140
|
-
*/
|
|
141
|
-
accept(socket: WebSocket, credential: string): Promise<void>;
|
|
142
|
-
/**
|
|
143
|
-
* How many devices this process holds the connection of (replica presence reports it): only
|
|
144
|
-
* sockets past the hello that hold their device's lease, so a socket still claiming or being
|
|
145
|
-
* replaced by a newer one does not count a device twice.
|
|
146
|
-
*/
|
|
147
|
-
connectionCount(): number;
|
|
148
|
-
/** @internal a connection that ended. */
|
|
149
|
-
forget(conn: DeviceConnection): void;
|
|
150
|
-
/** Closes every connection (1001) and hands their leases back. */
|
|
151
|
-
stop(): Promise<void>;
|
|
152
|
-
}
|
|
153
|
-
export {};
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import type { DeviceProvider, DeviceRef, DeviceReport, FileSystemHandle, SandboxHandle, SandboxLimits, SandboxRoots } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import { type DeviceOperation, type SandboxPermissionSupport } from "@capybara-hq/plugin-sdk";
|
|
3
|
-
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
4
|
-
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
5
|
-
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
6
|
-
import { LocalDeviceRelay } from "./relay.js";
|
|
7
|
-
import { DeviceTargets } from "./targets.js";
|
|
8
|
-
/** Extra time the machine gets beyond a command's own timeout (spawn, output, the trip back). */
|
|
9
|
-
export declare const EXEC_DEADLINE_MARGIN_MS = 5000;
|
|
10
|
-
/** How long the machine may take for one non-exec operation. */
|
|
11
|
-
export declare const OP_DEADLINE_MS = 30000;
|
|
12
|
-
/**
|
|
13
|
-
* Room left in a frame for everything around a `readFile` result's base64 data (the `res`
|
|
14
|
-
* envelope): a read is clamped so the machine's answer fits `devices.local.maxFrameBytes`
|
|
15
|
-
* (ruling R26).
|
|
16
|
-
*/
|
|
17
|
-
export declare const FRAME_ENVELOPE_BYTES: number;
|
|
18
|
-
export { projectsUnsupported } from "../devices/errors.js";
|
|
19
|
-
/** The most raw bytes whose base64 plus {@link FRAME_ENVELOPE_BYTES} fit in `maxFrameBytes`. */
|
|
20
|
-
export declare const maxReadBytes: (maxFrameBytes: number) => number;
|
|
21
|
-
/** What the staged provider sends through: the relay's protocol 4 call and the attested support. */
|
|
22
|
-
export interface StagedDeviceTransport {
|
|
23
|
-
call(deviceId: string, op: DeviceOperation, args: Record<string, unknown>, opts: {
|
|
24
|
-
deadlineMs: number;
|
|
25
|
-
signal: AbortSignal;
|
|
26
|
-
connection?: {
|
|
27
|
-
connectionId: string;
|
|
28
|
-
maxFrameBytes: number;
|
|
29
|
-
};
|
|
30
|
-
}): Promise<unknown>;
|
|
31
|
-
permissionSupport(deviceId: string, signal: AbortSignal): Promise<SandboxPermissionSupport>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* The handle of an instance on a machine: the device id (ruling R1: the relay is keyed by
|
|
35
|
-
* device), the roots the machine reported at `create`, and the org's effective limits at
|
|
36
|
-
* creation (for the record: every `exec` carries the org's limits read at that moment, ruling
|
|
37
|
-
* R27, so the machine intersects its local policy with the current egress).
|
|
38
|
-
*/
|
|
39
|
-
export interface LocalDeviceHandle extends SandboxHandle {
|
|
40
|
-
roots: SandboxRoots;
|
|
41
|
-
limits: SandboxLimits;
|
|
42
|
-
}
|
|
43
|
-
/** The device id of a `cap-device-<deviceId>` name; undefined for any other name. */
|
|
44
|
-
export declare const deviceIdOfName: (name: string) => string | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* The kernel-internal provider `@local` (environments spec §13.5): every operation runs on the
|
|
47
|
-
* device's connected machine through the {@link LocalDeviceRelay}. The file system is the
|
|
48
|
-
* machine's device directory (the program creates it on first use), so `createFileSystem`
|
|
49
|
-
* touches nothing; `suspend` and `destroy` do nothing (the machine is not the platform's to stop);
|
|
50
|
-
* deleting the device leaves the files on the machine where they are. Nothing here throws `device.offline` on the cleanup paths (ruling R9).
|
|
51
|
-
*
|
|
52
|
-
* The files on a machine are its owner's: `destroyFileSystem` (a files reset, the deletion sweep)
|
|
53
|
-
* does nothing; the deletion's `stop` comes from `MachinesService.revokeActive` (ruling R24).
|
|
54
|
-
*/
|
|
55
|
-
export declare class LocalDeviceProvider implements DeviceProvider {
|
|
56
|
-
private readonly relay;
|
|
57
|
-
private readonly targets;
|
|
58
|
-
private readonly sandbox;
|
|
59
|
-
private readonly config;
|
|
60
|
-
private readonly callGrants?;
|
|
61
|
-
readonly concurrentExec: true;
|
|
62
|
-
readonly networkAllowlist: true;
|
|
63
|
-
readonly sessionIsolation = false;
|
|
64
|
-
/** What the kernel tells about a local device: fixed text, the machine's home, nothing to reset. */
|
|
65
|
-
report(device: DeviceRef, _signal: AbortSignal): Promise<DeviceReport>;
|
|
66
|
-
constructor(relay: LocalDeviceRelay, targets: Pick<DeviceTargets, "orgOf" | "machineRoots" | "machineHome">, sandbox: Pick<SandboxService, "devicePolicy" | "deviceLimits" | "hostGrantCeiling">, config: Pick<KernelConfigService, "get">, callGrants?: PermissionCallGrants | undefined);
|
|
67
|
-
/**
|
|
68
|
-
* The `@local` provider as the staged (protocol 4) registration hands it out
|
|
69
|
-
* (`LocalDevicesModule`): the protocol 2 lifecycle methods that send no frame (file system,
|
|
70
|
-
* resume, suspend, destroy), the v3 operation adapter ({@link stagedOperations}), `create` as a
|
|
71
|
-
* protocol 4 request, no raw protocol 2 call and no broad kill. Dormant until the protocol gate
|
|
72
|
-
* selects it.
|
|
73
|
-
*
|
|
74
|
-
* The raw methods (`exec`, `readFile`, `writeFile`, `stat`, `list`, `scan`) refuse before
|
|
75
|
-
* anything is queued: a v3 machine runs work only under an admitted operation scope, and
|
|
76
|
-
* missing operation support never falls back to them.
|
|
77
|
-
*
|
|
78
|
-
* A v3 machine has no `killAll` / `killTagged` (permission runtime cutover B-1), so both are
|
|
79
|
-
* no-ops that queue nothing; the kernel never calls them anyway. What reaches the machine is
|
|
80
|
-
* only what the kernel revokes exactly (`revokeOperation` per intent): `SandboxService` owes a
|
|
81
|
-
* crashed holder's revocation in an outbox row before it forgets the holder record, revokes that
|
|
82
|
-
* holder's admitted, dispatching and started-or-unknown intents, and, under the exclusive lease
|
|
83
|
-
* on an incarnation nobody else holds (a resume, a failed limits change, a quarantine), every
|
|
84
|
-
* started-or-unknown intent of that generation; the owed revokes are delivered by operation id.
|
|
85
|
-
*/
|
|
86
|
-
staged(transport: StagedDeviceTransport): DeviceProvider;
|
|
87
|
-
/** Dormant v3 adapter. It is not installed on the active v2 registered provider. */
|
|
88
|
-
stagedOperations(transport: StagedDeviceTransport): Required<Pick<DeviceProvider, "operation" | "prepare" | "browse" | "permissionSupport" | "revokeOperation" | "background">>;
|
|
89
|
-
createFileSystem(args: {
|
|
90
|
-
name: string;
|
|
91
|
-
limits: SandboxLimits;
|
|
92
|
-
signal: AbortSignal;
|
|
93
|
-
}): Promise<FileSystemHandle>;
|
|
94
|
-
/** The files are the machine owner's: nothing to do (ruling R24; never a `stop`). */
|
|
95
|
-
destroyFileSystem(_fs: FileSystemHandle, signal: AbortSignal): Promise<void>;
|
|
96
|
-
destroyFileSystemByName(_name: string, signal: AbortSignal): Promise<void>;
|
|
97
|
-
create(args: {
|
|
98
|
-
name: string;
|
|
99
|
-
image?: string;
|
|
100
|
-
limits: SandboxLimits;
|
|
101
|
-
fileSystem: FileSystemHandle;
|
|
102
|
-
signal: AbortSignal;
|
|
103
|
-
}): Promise<LocalDeviceHandle>;
|
|
104
|
-
/**
|
|
105
|
-
* Needs the machine online. `gone` (the kernel recreates the instance) when the active machine
|
|
106
|
-
* last reported other roots than the instance was created with (a new login into another
|
|
107
|
-
* directory or mode, ruling R23).
|
|
108
|
-
*/
|
|
109
|
-
resume(h: SandboxHandle, signal: AbortSignal): Promise<"resumed" | "gone">;
|
|
110
|
-
suspend(_h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
111
|
-
destroy(_h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
112
|
-
destroyByName(_name: string, signal: AbortSignal): Promise<void>;
|
|
113
|
-
/** A v3 machine has no broad kill (permission runtime cutover B-1): nothing is queued. */
|
|
114
|
-
killAll(_h: SandboxHandle, signal: AbortSignal): Promise<void>;
|
|
115
|
-
killTagged(_h: SandboxHandle, _tags: string[], signal: AbortSignal): Promise<void>;
|
|
116
|
-
readonly exec: DeviceProvider["exec"];
|
|
117
|
-
readonly readFile: DeviceProvider["readFile"];
|
|
118
|
-
readonly writeFile: DeviceProvider["writeFile"];
|
|
119
|
-
readonly stat: DeviceProvider["stat"];
|
|
120
|
-
readonly list: NonNullable<DeviceProvider["list"]>;
|
|
121
|
-
readonly scan: NonNullable<DeviceProvider["scan"]>;
|
|
122
|
-
}
|