@capybara-hq/kernel 0.1.0-rc.131 → 0.1.0-rc.133

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.
Files changed (155) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.js +3 -0
  3. package/dist/admin/admin.schemas.d.ts +4 -0
  4. package/dist/admin/health.service.d.ts +2 -2
  5. package/dist/admin/health.service.js +6 -2
  6. package/dist/admin/setup.service.js +6 -1
  7. package/dist/agents/agents.controller.js +3 -2
  8. package/dist/agents/agents.service.d.ts +2 -0
  9. package/dist/agents/agents.service.js +7 -0
  10. package/dist/catalog/catalog.service.d.ts +2 -0
  11. package/dist/catalog/catalog.service.js +28 -5
  12. package/dist/catalog/marketplace-fetch.d.ts +2 -0
  13. package/dist/catalog/marketplace-fetch.js +15 -0
  14. package/dist/catalog/marketplaces.service.d.ts +4 -4
  15. package/dist/catalog/marketplaces.service.js +3 -2
  16. package/dist/catalog/owned-items.d.ts +2 -0
  17. package/dist/catalog/owned-items.js +30 -31
  18. package/dist/catalog/ownership.js +40 -38
  19. package/dist/catalog/plugin-import.d.ts +6 -5
  20. package/dist/catalog/plugin-import.js +69 -16
  21. package/dist/catalog/plugin-upgrade.d.ts +8 -0
  22. package/dist/catalog/plugin-upgrade.js +95 -7
  23. package/dist/catalog/publisher-policy.d.ts +9 -0
  24. package/dist/catalog/publisher-policy.js +12 -0
  25. package/dist/catalog/unshare.js +66 -58
  26. package/dist/client/client-access.service.js +5 -3
  27. package/dist/config/schema.d.ts +1 -0
  28. package/dist/config/schema.js +9 -1
  29. package/dist/conversations/conversations.controller.js +4 -14
  30. package/dist/conversations/conversations.service.d.ts +14 -0
  31. package/dist/conversations/conversations.service.js +20 -2
  32. package/dist/ctx/create-ctx.d.ts +14 -4
  33. package/dist/ctx/create-ctx.js +131 -59
  34. package/dist/ctx/queue.js +7 -4
  35. package/dist/db/extension-db.d.ts +30 -0
  36. package/dist/db/extension-db.js +91 -0
  37. package/dist/db/extension-rls-predicate.d.ts +1 -0
  38. package/dist/db/extension-rls-predicate.js +8 -0
  39. package/dist/db/extension-schema-transfer.d.ts +6 -0
  40. package/dist/db/extension-schema-transfer.js +141 -0
  41. package/dist/db/kernel-schema.d.ts +50 -4
  42. package/dist/db/migrator.d.ts +6 -0
  43. package/dist/db/migrator.js +35 -7
  44. package/dist/db/pool.d.ts +6 -2
  45. package/dist/db/pool.js +37 -2
  46. package/dist/db/sql-statements.d.ts +3 -0
  47. package/dist/db/sql-statements.js +15 -5
  48. package/dist/device-access/device-access.module.js +12 -2
  49. package/dist/device-access/device-access.service.d.ts +30 -2
  50. package/dist/device-access/device-access.service.js +38 -4
  51. package/dist/device-access/host-gate.d.ts +45 -0
  52. package/dist/device-access/host-gate.js +92 -0
  53. package/dist/device-access/host-service-stop-sweep.d.ts +33 -0
  54. package/dist/device-access/host-service-stop-sweep.js +112 -0
  55. package/dist/device-access/host-service-stop.d.ts +78 -0
  56. package/dist/device-access/host-service-stop.js +144 -0
  57. package/dist/device-access/host-services.d.ts +211 -0
  58. package/dist/device-access/host-services.js +803 -0
  59. package/dist/device-access/person-handles.d.ts +10 -0
  60. package/dist/device-access/person-handles.js +25 -0
  61. package/dist/device-access/service-events.d.ts +199 -0
  62. package/dist/device-access/service-events.js +704 -0
  63. package/dist/device-access/token.d.ts +5 -0
  64. package/dist/device-access/token.js +5 -0
  65. package/dist/devices/devices.service.js +3 -0
  66. package/dist/dial-in/access.d.ts +5 -5
  67. package/dist/dial-in/access.js +19 -12
  68. package/dist/dial-in/gateway.js +6 -2
  69. package/dist/dial-in/machines.d.ts +9 -2
  70. package/dist/dial-in/machines.js +27 -4
  71. package/dist/erasure/device-cleanup.js +12 -0
  72. package/dist/erasure/org-catalog.js +2 -2
  73. package/dist/erasure/org-rules.js +9 -0
  74. package/dist/errors.d.ts +2 -0
  75. package/dist/errors.js +2 -0
  76. package/dist/extensions/admin-ops.d.ts +3 -1
  77. package/dist/extensions/admin-ops.js +19 -9
  78. package/dist/extensions/deployed-snapshots.d.ts +4 -1
  79. package/dist/extensions/deployed-snapshots.js +7 -2
  80. package/dist/extensions/extensions.module.js +3 -0
  81. package/dist/extensions/host.d.ts +11 -3
  82. package/dist/extensions/host.js +40 -8
  83. package/dist/extensions/instance.d.ts +6 -0
  84. package/dist/extensions/instance.js +7 -1
  85. package/dist/extensions/ledger.d.ts +1 -1
  86. package/dist/extensions/lifecycle-hooks.js +3 -3
  87. package/dist/extensions/migrate-lock.d.ts +4 -1
  88. package/dist/extensions/migrate-lock.js +19 -2
  89. package/dist/extensions/org-config.js +6 -1
  90. package/dist/extensions/permission-set.d.ts +7 -0
  91. package/dist/extensions/permission-set.js +10 -0
  92. package/dist/extensions/permission-view.d.ts +1 -1
  93. package/dist/extensions/permission-view.js +10 -1
  94. package/dist/git/tickets.js +32 -27
  95. package/dist/http/app.js +5 -3
  96. package/dist/identity/accounts.d.ts +6 -1
  97. package/dist/identity/accounts.js +11 -2
  98. package/dist/identity/api-tokens.js +7 -6
  99. package/dist/identity/settings.d.ts +9 -1
  100. package/dist/identity/settings.js +16 -1
  101. package/dist/inbox/org-notices.js +3 -2
  102. package/dist/index.d.ts +1 -0
  103. package/dist/index.js +1 -0
  104. package/dist/infra/database/scoped-dialect.d.ts +3 -2
  105. package/dist/infra/database/scoped-dialect.js +260 -72
  106. package/dist/infra/database/startup-activation-transaction.d.ts +2 -0
  107. package/dist/infra/database/startup-activation-transaction.js +3 -2
  108. package/dist/infra/outbox/registry.d.ts +28 -14
  109. package/dist/infra/outbox/registry.js +30 -15
  110. package/dist/infra/queue/queue-names.d.ts +1 -1
  111. package/dist/infra/queue/queue-names.js +1 -0
  112. package/dist/infra/queue/run-job.d.ts +4 -1
  113. package/dist/infra/queue/run-job.js +10 -2
  114. package/dist/kernel.js +4 -0
  115. package/dist/kernel.module.js +3 -0
  116. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  117. package/dist/lifecycle/kernel-lifecycle.js +26 -21
  118. package/dist/orgs/offboarding.js +18 -9
  119. package/dist/orgs/settings.service.js +3 -0
  120. package/dist/packages/npm-publish-keys.json +27 -0
  121. package/dist/packages/official-publisher.d.ts +19 -0
  122. package/dist/packages/official-publisher.js +152 -0
  123. package/dist/packages/provenance.d.ts +7 -0
  124. package/dist/packages/provenance.js +22 -19
  125. package/dist/packages/sigstore-trusted-root.json +126 -0
  126. package/dist/platform/ops/admin.ops.js +2 -1
  127. package/dist/platform/ops/orgs.ops.js +1 -0
  128. package/dist/roles/worker-role.d.ts +6 -3
  129. package/dist/roles/worker-role.js +12 -4
  130. package/dist/roles/worker.module.js +7 -6
  131. package/dist/runtime/maintenance.d.ts +5 -4
  132. package/dist/runtime/maintenance.js +16 -13
  133. package/dist/sandbox/device-reports.d.ts +4 -4
  134. package/dist/sandbox/device-reports.js +40 -30
  135. package/dist/sandbox/device-services.d.ts +2 -1
  136. package/dist/sandbox/device-services.js +5 -1
  137. package/dist/sandbox/permission-ceiling-writes.d.ts +8 -0
  138. package/dist/sandbox/permission-ceiling-writes.js +21 -0
  139. package/dist/sandbox/permission-config-publication.js +5 -1
  140. package/dist/themes/theme-state.js +24 -13
  141. package/dist/tools/call-scope.d.ts +6 -0
  142. package/dist/tools/call-scope.js +22 -0
  143. package/dist/tools/registry.js +20 -2
  144. package/dist/ui/views.js +36 -8
  145. package/package.json +9 -4
  146. package/src/migrations/0219_event_org_constraint_check.sql +29 -0
  147. package/src/migrations/0220_require_event_org.sql +18 -0
  148. package/src/migrations/0221_drop_connector_declaration_policy.sql +2 -0
  149. package/src/migrations/0222_device_host_services.sql +27 -0
  150. package/src/migrations/0223_device_service_events.sql +54 -0
  151. package/src/migrations/0224_cache_conversation_rls_settings.sql +33 -0
  152. package/dist/conversations/event-org-backfill.d.ts +0 -111
  153. package/dist/conversations/event-org-backfill.js +0 -264
  154. package/dist/conversations/event-org-backfill.module.d.ts +0 -3
  155. package/dist/conversations/event-org-backfill.module.js +0 -18
@@ -0,0 +1,144 @@
1
+ import { sql } from "kysely";
2
+ import { asPlatform, withOrgScope } from "../infra/database/org-scope.js";
3
+ import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
4
+ /**
5
+ * The stops of host services the kernel owes (local agents spec, calls 1 and 5: a host service
6
+ * ends when its extension is switched off in the org, disabled on the deployment or uninstalled;
7
+ * when the host gate closes: a platform or org project reach cap narrows below `machine`, or
8
+ * running outside the sandbox is switched off there; and when its person or device goes: the
9
+ * device is deleted, the person is removed from the org, or their account is disabled). The owed
10
+ * stop is state, `device_host_services.stop_owed_at`, set in the transaction that makes the change
11
+ * and cleared only when the machine confirms the stop (or, for a deleted device, when the delivery
12
+ * finds the device gone: its machine is closed with 4003 or refused with 401, and `capybara-device`
13
+ * stops every host service it runs at that terminal end before it exits; a disabled account's
14
+ * devices stay owed until a machine confirms). The delivery is an
15
+ * outbox job on the maintenance queue (`HostServiceAccess.deliverOwedStops`), owed by the same
16
+ * transaction, again by every connect of a machine that still has owed stops
17
+ * (`DialInMachines.recordConnect`), so a machine offline at the change gets the stop when it comes
18
+ * back, and again by the periodic sweep (`HostServiceStopSweepJob`) for a machine that stayed
19
+ * connected while a delivery job ran out of retries. A file of its own (no Nest, no device graph),
20
+ * so the extension, identity, org and dial-in modules can owe it without importing the device
21
+ * access module.
22
+ */
23
+ export const HOST_SERVICES_STOP_JOB = "device-host-services-stop";
24
+ /**
25
+ * The mark of an owed stop as a job id part: `stop_owed_at` in microseconds since the epoch (the
26
+ * owing transaction's `now()`), selected with {@link owedMarkMicros}.
27
+ */
28
+ export const owedMarkMicros = sql `(extract(epoch from stop_owed_at) * 1000000)::bigint::text`;
29
+ /**
30
+ * The deterministic job id (no `:`): one delivery per narrowing and per mark, `mark` being the
31
+ * latest `stop_owed_at` it delivers ({@link owedMarkMicros}). A mark made while an earlier
32
+ * delivery of the same narrowing runs (or is still kept by the queue) gets a job of its own, so
33
+ * the queue never folds it into a delivery that already read its rows; owing the same mark again
34
+ * (a machine's reconnects) stays one job.
35
+ */
36
+ export const hostServicesStopJobId = (data, mark) => `dhs-stop-${data.orgId ?? "all"}-${data.extension ?? "any"}-${data.deviceId ?? "any"}-${mark}`;
37
+ /**
38
+ * Owes one delivery of the owed stops `data` narrows to, in the caller's transaction, under the
39
+ * latest mark among them (`mark`, {@link owedMarkMicros}).
40
+ */
41
+ export async function oweHostServicesDelivery(outbox, data, mark) {
42
+ await outbox.add({
43
+ queue: MAINTENANCE_QUEUE_NAME,
44
+ name: HOST_SERVICES_STOP_JOB,
45
+ jobId: hostServicesStopJobId(data, mark),
46
+ data,
47
+ ...(data.orgId !== undefined && { orgId: data.orgId }),
48
+ });
49
+ }
50
+ /** The latest of the marks `rows` returned, or null when no placement was marked. */
51
+ export function latestMark(rows) {
52
+ let latest = null;
53
+ for (const r of rows) {
54
+ const m = BigInt(r.mark);
55
+ if (latest === null || m > latest)
56
+ latest = m;
57
+ }
58
+ return latest === null ? null : latest.toString();
59
+ }
60
+ /**
61
+ * Owes the stop of host services, in the caller's transaction (`db`): marks every placement of
62
+ * `extension` (of every extension when absent: the host gate closed, a project reach cap narrowed
63
+ * below `machine` or running outside the sandbox switched off,
64
+ * `PermissionCeilingWrites.oweHostServiceStopsLocked`) in `orgId` (every org when absent) as
65
+ * owed, and owes their delivery. Nothing is owed where no placement was marked.
66
+ */
67
+ export async function oweHostServicesStop(db, outbox, data) {
68
+ const { extension, orgId } = data;
69
+ // always bumped: an earlier mark an ensure is clearing after its own stop never hides this one
70
+ const owed = { stop_owed_at: sql `now()` };
71
+ const rows = orgId !== undefined
72
+ ? // the org's own rows, in its scope (a writer reached without one, as from a test seam)
73
+ await withOrgScope(orgId, () => db
74
+ .updateTable("device_host_services")
75
+ .set(owed)
76
+ .where("org_id", "=", orgId)
77
+ .$if(extension !== undefined, (q) => q.where("extension", "=", extension))
78
+ .returning(owedMarkMicros.as("mark"))
79
+ .execute())
80
+ : await asPlatform("owe host service stops for a deployment-wide change", async () => {
81
+ // org-filter: deployment-wide: an extension disabled on the deployment, or a platform
82
+ // ceiling closing the host gate, stops host services in every organization
83
+ return await db
84
+ .updateTable("device_host_services")
85
+ .set(owed)
86
+ .$if(extension !== undefined, (q) => q.where("extension", "=", extension))
87
+ .returning(owedMarkMicros.as("mark"))
88
+ .execute();
89
+ });
90
+ const mark = latestMark(rows);
91
+ if (mark !== null)
92
+ await oweHostServicesDelivery(outbox, data, mark);
93
+ }
94
+ /**
95
+ * Owes the stop of every host service on `deviceIds` of `orgId`, in the caller's transaction
96
+ * (`db`): the devices are deleted, or their person leaves the org. Marks their placements owed and
97
+ * owes one delivery per device that had one.
98
+ */
99
+ export async function oweHostServicesStopOnDevices(db, outbox, data) {
100
+ if (data.deviceIds.length === 0)
101
+ return;
102
+ const rows = await withOrgScope(data.orgId, () => db
103
+ .updateTable("device_host_services")
104
+ .set({ stop_owed_at: sql `now()` })
105
+ .where("org_id", "=", data.orgId)
106
+ .where("device_id", "in", [...data.deviceIds])
107
+ .returning(["device_id", owedMarkMicros.as("mark")])
108
+ .execute());
109
+ await owePerDevice(outbox, rows.map((r) => ({ org_id: data.orgId, ...r })));
110
+ }
111
+ /**
112
+ * Owes the stop of every host service on the personal devices of `accountId`, in every org, in the
113
+ * caller's transaction (`db`): the account is disabled. One delivery per device that had one.
114
+ */
115
+ export async function oweHostServicesStopOfAccount(db, outbox, accountId) {
116
+ const rows = await asPlatform("owe host service stops of a disabled account", async () => {
117
+ // org-filter: deployment-wide: a disabled account's host services stop in every organization
118
+ return await db
119
+ .updateTable("device_host_services")
120
+ .set({ stop_owed_at: sql `now()` })
121
+ .where("device_id", "in", (eb) => eb
122
+ .selectFrom("devices")
123
+ .select("id")
124
+ .where("owner_kind", "=", "personal")
125
+ .where("owner_account_id", "=", accountId))
126
+ .returning(["org_id", "device_id", owedMarkMicros.as("mark")])
127
+ .execute();
128
+ });
129
+ await owePerDevice(outbox, rows);
130
+ }
131
+ /** One delivery per (org, device) among `rows`, under the latest mark of each. */
132
+ async function owePerDevice(outbox, rows) {
133
+ const byDevice = new Map();
134
+ for (const r of rows) {
135
+ const d = byDevice.get(r.device_id) ?? { orgId: r.org_id, marks: [] };
136
+ d.marks.push({ mark: r.mark });
137
+ byDevice.set(r.device_id, d);
138
+ }
139
+ for (const [deviceId, d] of byDevice) {
140
+ const mark = latestMark(d.marks);
141
+ if (mark !== null)
142
+ await oweHostServicesDelivery(outbox, { orgId: d.orgId, deviceId }, mark);
143
+ }
144
+ }
@@ -0,0 +1,211 @@
1
+ import { type DevicePersonScope, type DeviceServiceSpec, type DeviceServiceStatus, type DeviceToolScope, type PersonalDeviceView } from "@capybara-hq/plugin-sdk";
2
+ import { DeviceAccess } from "../devices/access.js";
3
+ import { DevicesService } from "../devices/devices.service.js";
4
+ import { KernelDb } from "../infra/database/kernel-db.js";
5
+ import { TransactionHost } from "../infra/database/transaction-host.js";
6
+ import { LockService } from "../infra/lock/lock.service.js";
7
+ import { OutboxService } from "../infra/outbox/outbox.service.js";
8
+ import type { KernelLogger } from "../log.js";
9
+ import { DeviceProviders } from "../sandbox/providers.js";
10
+ import { SandboxService } from "../sandbox/sandbox.service.js";
11
+ import type { DeviceAccessCaller } from "./device-access.service.js";
12
+ import { HostServiceGate } from "./host-gate.js";
13
+ import { type HostServicesStopJobData } from "./host-service-stop.js";
14
+ /** The audit action of a host service start (local agents spec, call 4). */
15
+ export declare const HOST_SERVICE_STARTED_ACTION = "device.host_service.started";
16
+ /** What a tool call by anyone but the conversation's owner is refused with. */
17
+ export declare const HOST_NOT_OWNER_TEXT = "Host services only run for the conversation's owner, on their own personal device.";
18
+ /** What a scope the kernel did not issue is refused with. */
19
+ export declare const HOST_SCOPE_TEXT = "A host service call takes { call, deviceId } with the tool call the kernel passed to the running tool handler, or { person, deviceId } with the person handle the kernel passed to the running page action or query; neither is valid after its handler settles.";
20
+ type HostAt = DeviceToolScope | DevicePersonScope;
21
+ /**
22
+ * Host device services (local agents spec, Part 1): a service of a platform-trusted extension that
23
+ * runs on its owner's personal machine outside the device sandbox, with the machine user's rights.
24
+ * Admission, in this order, each refusal a `DeviceAccessError`:
25
+ * 1. `host_not_declared`: the service is not in the approved manifest's
26
+ * `permissions.deviceAccess.hostServices`, a start's spec is not `host: true`, or the extension
27
+ * came from an org-owned catalog item (org uploads with code are refused at import; this is the
28
+ * backstop); `invalid_request`: a scope the kernel did not issue ({@link resolveAt});
29
+ * 2. `capability_missing`: the extension is not enabled in the org;
30
+ * 3. `not_owner`: a tool call whose trigger account is not the conversation's owner (calls act for
31
+ * the owner, unattended runs included);
32
+ * 4. `not_personal_device`: the device is not a live personal device of the person (the
33
+ * conversation's owner for a tool call) served by a dial-in provider (a machine of theirs);
34
+ * 5. `host_gate_closed`: {@link HostServiceGate} (a platform or org project reach cap below
35
+ * `machine`, or running outside the sandbox is off for the device), read inside the device's
36
+ * use under the shared permission authority locks, the provider call dispatched before they
37
+ * are released (a cap narrowed meanwhile owes the stop of what this call starts);
38
+ * 6. `host_consent_missing`: the machine's owner has not allowed these files of the service on the
39
+ * machine (`capybara-device services allow <extension>.<service>`), reported by the provider.
40
+ * A start passes no command review: the on-machine consent to the exact files is the check, and
41
+ * each new process is audited {@link HOST_SERVICE_STARTED_ACTION}. Where a host service runs is
42
+ * state (`device_host_services`): the row is written before the machine is asked to start it and
43
+ * deleted on a confirmed stop; a switch-off of the extension, the host gate closing (a project
44
+ * reach cap narrowed below `machine` or outside-sandbox work switched off,
45
+ * `PermissionCeilingWrites.publishLocked`), the device's deletion, its person's removal from the
46
+ * org or their account's disabling marks its rows owed in the same transaction, and
47
+ * {@link deliverOwedStops} delivers them (again on the machine's next connect when it is away, and
48
+ * by `HostServiceStopSweepJob` while it stays connected).
49
+ * The provider gets each service by its id (`<extension>.<name>`). Every call goes through the
50
+ * device's use ({@link SandboxService.withDeviceServices}: the instance is resumed, the lease and
51
+ * fencing apply), silently: a host service's lifetime is not the sandbox's, the machine keeps it
52
+ * across suspension.
53
+ */
54
+ export declare class HostServiceAccess {
55
+ private readonly kdb;
56
+ private readonly sandbox;
57
+ private readonly access;
58
+ private readonly devices;
59
+ private readonly providers;
60
+ private readonly gate;
61
+ private readonly log;
62
+ /** The placement lock ({@link withPlacement}). */
63
+ private readonly locks;
64
+ /** The delivery of a stop owed again after a start ({@link oweIfOff}). */
65
+ private readonly outbox;
66
+ readonly txHost: TransactionHost;
67
+ constructor(kdb: KernelDb, sandbox: Pick<SandboxService, "withDeviceServices">, access: Pick<DeviceAccess, "usable">, devices: Pick<DevicesService, "list">, providers: Pick<DeviceProviders, "forDevice">, gate: Pick<HostServiceGate, "admit" | "known">, log: KernelLogger,
68
+ /** The placement lock ({@link withPlacement}). */
69
+ locks: Pick<LockService, "run">,
70
+ /** The delivery of a stop owed again after a start ({@link oweIfOff}). */
71
+ outbox: Pick<OutboxService, "add">, txHost: TransactionHost);
72
+ private get db();
73
+ /**
74
+ * Starts the host service on the person's machine, or finds it running on these files. A
75
+ * service running other files (the extension was upgraded) is started again on the spec's
76
+ * files, which needs the owner's consent to them again. The placement row is written before the
77
+ * machine is asked to start anything, and the extension's enablement is read again after it,
78
+ * so a switch-off that commits meanwhile either marks the row owed or refuses this start. A
79
+ * start that made a new process writes one {@link HOST_SERVICE_STARTED_ACTION} audit row.
80
+ */
81
+ ensure(caller: DeviceAccessCaller, at: HostAt, spec: DeviceServiceSpec): Promise<DeviceServiceStatus>;
82
+ /**
83
+ * One request to the host service. `ifRunning` (forced in a watcher's call scope): a service
84
+ * that is not running is refused `not_running` and nothing is started.
85
+ */
86
+ request(caller: DeviceAccessCaller, at: HostAt, req: {
87
+ service: string;
88
+ body: Uint8Array;
89
+ timeoutMs: number;
90
+ ifRunning?: boolean;
91
+ }): Promise<Uint8Array>;
92
+ /**
93
+ * Stops the host service on the person's machine; a service that is not running is no error.
94
+ * No gate: a stop is always admitted for the person's own device. The placement row goes once
95
+ * the machine confirmed the stop.
96
+ */
97
+ stop(caller: DeviceAccessCaller, at: HostAt, service: string): Promise<void>;
98
+ /**
99
+ * The person's personal devices in the org, with what a host service needs on each: the machine
100
+ * is connected (`online`); it can run host services (`hostServices`: false off a machine of
101
+ * theirs or with its provider off, null otherwise, since the machine's announced features do
102
+ * not reach the kernel); the host gate is open (`outsideSandbox`, null while the machine's own
103
+ * setting is not known yet: it is read once the device has run). An admission reads the gate
104
+ * again inside the device's use.
105
+ */
106
+ personalDevices(caller: DeviceAccessCaller, args: {
107
+ orgId: string;
108
+ accountId: string;
109
+ }): Promise<PersonalDeviceView[]>;
110
+ /**
111
+ * The {@link HOST_SERVICES_STOP_JOB} body: delivers the owed stops `data` narrows to
112
+ * (`device_host_services.stop_owed_at`), each through the machine's provider; a confirmed stop
113
+ * deletes the row. A machine that is away (offline, its provider off or unavailable) keeps its
114
+ * rows owed: its next connect owes the delivery again. A provider that cannot run device
115
+ * services (`capability_missing`) keeps them owed without a retry. Any other failure fails the
116
+ * job after the others were tried, so the queue retries it; the rows stay owed either way, and
117
+ * the sweep (`HostServiceStopSweepJob`) owes them again while the machine stays connected.
118
+ *
119
+ * Only a confirmed stop clears a row, with one exception: a deleted device's rows are settled
120
+ * (deleted) without one, because the device record is gone and no machine can ever confirm
121
+ * them. That rests on the device side: the deletion revokes the machine and closes it with 4003
122
+ * "deleted" at once; a member's removal deletes their devices and the connection's credential
123
+ * re-check closes it with 4003 within a minute; a later connect is refused with 401. On each of
124
+ * those terminal ends (and on SIGTERM / SIGINT) `capybara-device` stops every service it runs,
125
+ * host services included, before it exits (`serveStaged` disposes the device; packages/device,
126
+ * "start: the program's end stops host services"); only a network loss keeps them running, and
127
+ * the next connect then ends that way. A disabled account's devices are not deleted: their rows
128
+ * stay owed until a machine confirms the stop.
129
+ */
130
+ deliverOwedStops(data: HostServicesStopJobData): Promise<void>;
131
+ /**
132
+ * One owed stop, under its placement lock: read again (an ensure may have delivered it), sent,
133
+ * and the row deleted once the machine confirmed it. Null when delivered or kept owed for an
134
+ * away machine; the error otherwise.
135
+ */
136
+ private deliverOne;
137
+ /** Deletes an owed placement whose stop was confirmed (or whose device is deleted). */
138
+ private settle;
139
+ /**
140
+ * Records the placement of the service on the admitted device: `null` writes the intent (the row
141
+ * as it is, or a new one with no start yet), a start its digest and time. It never touches an
142
+ * owed stop: only a confirmed stop clears that ({@link clearOwed}, {@link deliverOwedStops}).
143
+ * Its own transaction, under the placement lock taken outside it.
144
+ */
145
+ private place;
146
+ /**
147
+ * Runs `fn` under the placement lock of (device, extension, service): starts, explicit stops and
148
+ * owed stop deliveries of one placement never interleave. Taken outside any transaction, one at
149
+ * a time (never two placement locks at once).
150
+ */
151
+ private withPlacement;
152
+ /** The owed stop mark of the placement, or null. */
153
+ private owedMark;
154
+ /**
155
+ * After a confirmed stop: deletes the placement only while its owed mark is still `mark` (a
156
+ * switch-off that bumped it since keeps it). Whether it was deleted.
157
+ */
158
+ private clearOwed;
159
+ /**
160
+ * Whether the extension is on in the org and on the deployment now, read in a short transaction
161
+ * of its own that takes `FOR SHARE` on the org's `extension_org_configs` row and the
162
+ * `extension_installs` row: every switch-off writes one of them before it marks placements owed,
163
+ * so a switch-off still open waits this read out and is then seen (never a stale "enabled" while
164
+ * its placement UPDATE missed a row inserted meanwhile). Called with the placement lock held,
165
+ * never the other way round.
166
+ */
167
+ private enabledNow;
168
+ /**
169
+ * After a start or a found running service: when the extension is off now (switched off while
170
+ * the machine worked), the placement is marked owed and its delivery owed, so the switch-off's
171
+ * stop is never lost.
172
+ */
173
+ private oweIfOff;
174
+ private oweStop;
175
+ /** Deletes the placement (a confirmed stop, or a start refused before anything ran). */
176
+ private unplace;
177
+ /**
178
+ * Admits a call (steps 2 to 5 of the class comment; step 1 is the caller's): the person, the
179
+ * device and the use the call works on.
180
+ */
181
+ private admit;
182
+ /**
183
+ * The device is a live personal device of `accountId` in the org, on a dial-in provider (a
184
+ * machine of theirs) that serves the org now; `not_personal_device` otherwise (a device of
185
+ * someone else's reads the same as a missing one).
186
+ */
187
+ private assertPersonalMachine;
188
+ /**
189
+ * Runs `fn` on the admitted device's provider (a silent use of the device), after the host gate
190
+ * (step 5) when the call is gated: read inside the use, where the device's instance runs and its
191
+ * provider's support (the machine owner's outside-sandbox setting) is known, and before anything
192
+ * reaches the machine's services ({@link HostServiceGate.admit}: `fn` is dispatched under the
193
+ * gate's shared authority locks).
194
+ */
195
+ private onDevice;
196
+ /**
197
+ * One audit row per new process: whichever call saw the start first writes it (a check, then
198
+ * the insert, as `device.service_started` does), in one transaction.
199
+ */
200
+ private auditStart;
201
+ /**
202
+ * Step 1 of the admission: the service is one of the approved manifest's host services, and the
203
+ * extension did not come from an org-owned catalog item.
204
+ */
205
+ private assertDeclared;
206
+ /** Whether the extension came from an org-owned catalog item (its install's or a source's). */
207
+ private orgOwned;
208
+ private assertEnabled;
209
+ private isMember;
210
+ }
211
+ export {};