@capybara-hq/kernel 0.1.0-rc.66 → 0.1.0-rc.67

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 (139) hide show
  1. package/bootstrap.json +0 -8
  2. package/dist/admin/admin.schemas.d.ts +3 -0
  3. package/dist/agents/admin-agents.d.ts +2 -2
  4. package/dist/agents/admin-agents.js +2 -1
  5. package/dist/agents/agent-lookup.js +2 -1
  6. package/dist/agents/agent-profile.service.d.ts +5 -2
  7. package/dist/agents/agent-profile.service.js +13 -2
  8. package/dist/agents/agents.controller.d.ts +4 -3
  9. package/dist/agents/agents.controller.js +7 -3
  10. package/dist/agents/agents.module.js +3 -0
  11. package/dist/agents/agents.schemas.d.ts +6 -6
  12. package/dist/agents/agents.service.d.ts +23 -2
  13. package/dist/agents/agents.service.js +61 -6
  14. package/dist/agents/avatar-view.d.ts +8 -0
  15. package/dist/agents/avatar-view.js +12 -0
  16. package/dist/agents/profile.d.ts +38 -13
  17. package/dist/agents/profile.js +31 -20
  18. package/dist/background/poll.job.d.ts +1 -1
  19. package/dist/background/poll.job.js +8 -6
  20. package/dist/background/tasks.service.js +1 -1
  21. package/dist/catalog/marketplaces.service.d.ts +1 -1
  22. package/dist/channels/inbound.d.ts +2 -3
  23. package/dist/channels/inbound.js +2 -3
  24. package/dist/channels/phrases.d.ts +3 -3
  25. package/dist/channels/phrases.js +3 -3
  26. package/dist/config/schema.d.ts +1 -0
  27. package/dist/config/schema.js +14 -1
  28. package/dist/conversations/conversations.service.d.ts +4 -3
  29. package/dist/conversations/conversations.service.js +4 -2
  30. package/dist/ctx/create-ctx.js +5 -2
  31. package/dist/ctx/device-provider-check.d.ts +7 -0
  32. package/dist/ctx/device-provider-check.js +21 -0
  33. package/dist/db/kernel-schema.d.ts +7 -0
  34. package/dist/devices/access.d.ts +16 -46
  35. package/dist/devices/access.js +26 -62
  36. package/dist/devices/access.module.js +2 -2
  37. package/dist/devices/conversation-devices.d.ts +38 -18
  38. package/dist/devices/conversation-devices.js +69 -51
  39. package/dist/devices/default-provider-setting.d.ts +45 -0
  40. package/dist/devices/default-provider-setting.js +59 -0
  41. package/dist/devices/device-projects.service.js +7 -2
  42. package/dist/devices/device-provider-selection.d.ts +37 -0
  43. package/dist/devices/device-provider-selection.js +86 -0
  44. package/dist/devices/device-provider-selection.module.d.ts +3 -0
  45. package/dist/devices/device-provider-selection.module.js +22 -0
  46. package/dist/devices/devices.controller.d.ts +8 -5
  47. package/dist/devices/devices.controller.js +7 -4
  48. package/dist/devices/devices.module.js +3 -1
  49. package/dist/devices/devices.schemas.js +2 -2
  50. package/dist/devices/devices.service.d.ts +72 -83
  51. package/dist/devices/devices.service.js +139 -248
  52. package/dist/devices/dto.d.ts +9 -0
  53. package/dist/devices/dto.js +15 -2
  54. package/dist/devices/label.d.ts +3 -5
  55. package/dist/devices/label.js +3 -14
  56. package/dist/devices/legacy-cleanup.job.d.ts +2 -2
  57. package/dist/devices/legacy-cleanup.job.js +6 -6
  58. package/dist/errors.d.ts +15 -1
  59. package/dist/errors.js +15 -1
  60. package/dist/extensions/guide-places.d.ts +2 -1
  61. package/dist/extensions/guide-places.js +8 -2
  62. package/dist/extensions/locks.d.ts +1 -1
  63. package/dist/extensions/locks.js +1 -1
  64. package/dist/extensions/org-config.d.ts +20 -4
  65. package/dist/extensions/org-config.js +23 -6
  66. package/dist/extensions/permission-view.d.ts +2 -2
  67. package/dist/extensions/permission-view.js +2 -2
  68. package/dist/extensions/plugin-guides.d.ts +1 -1
  69. package/dist/extensions/plugin-guides.js +11 -3
  70. package/dist/extensions/point-defaults.d.ts +14 -0
  71. package/dist/extensions/point-defaults.js +70 -47
  72. package/dist/extensions/resolve.js +7 -2
  73. package/dist/identity/settings.d.ts +8 -0
  74. package/dist/identity/settings.js +24 -1
  75. package/dist/infra/config/kernel-config.service.js +2 -0
  76. package/dist/lifecycle/kernel-lifecycle.js +7 -6
  77. package/dist/local-devices/device-routes.d.ts +1 -1
  78. package/dist/local-devices/device-routes.js +1 -1
  79. package/dist/local-devices/local-device-provider.d.ts +14 -11
  80. package/dist/local-devices/local-device-provider.js +14 -0
  81. package/dist/local-devices/local-devices.module.d.ts +4 -4
  82. package/dist/local-devices/local-devices.module.js +5 -3
  83. package/dist/local-devices/owner-report.js +2 -1
  84. package/dist/local-devices/targets.d.ts +2 -0
  85. package/dist/local-devices/targets.js +10 -0
  86. package/dist/orgs/settings.service.d.ts +26 -1
  87. package/dist/orgs/settings.service.js +44 -3
  88. package/dist/platform/ops/admin.ops.js +8 -3
  89. package/dist/platform/ops/agents.ops.d.ts +6 -1
  90. package/dist/platform/ops/agents.ops.js +38 -11
  91. package/dist/platform/ops/devices.ops.js +25 -20
  92. package/dist/platform/ops/orgs.ops.js +1 -0
  93. package/dist/platform/ops/themes.ops.js +1 -1
  94. package/dist/runtime/plugin-context.service.js +1 -12
  95. package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
  96. package/dist/sandbox/cloud-permission-snapshot.js +3 -3
  97. package/dist/sandbox/device-reports.d.ts +50 -0
  98. package/dist/sandbox/device-reports.js +157 -0
  99. package/dist/sandbox/held-operations.d.ts +8 -8
  100. package/dist/sandbox/leases.d.ts +1 -1
  101. package/dist/sandbox/leases.js +1 -1
  102. package/dist/sandbox/operation-authority.d.ts +5 -2
  103. package/dist/sandbox/operation-authority.js +12 -11
  104. package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
  105. package/dist/sandbox/operation-reconcile.job.js +5 -5
  106. package/dist/sandbox/permission-availability.d.ts +2 -2
  107. package/dist/sandbox/permission-call-types.d.ts +5 -0
  108. package/dist/sandbox/permission-facts.d.ts +2 -2
  109. package/dist/sandbox/permission-facts.js +5 -5
  110. package/dist/sandbox/providers.d.ts +23 -24
  111. package/dist/sandbox/providers.js +38 -46
  112. package/dist/sandbox/providers.module.js +3 -3
  113. package/dist/sandbox/sandbox.module.d.ts +1 -1
  114. package/dist/sandbox/sandbox.module.js +7 -2
  115. package/dist/sandbox/sandbox.service.d.ts +95 -68
  116. package/dist/sandbox/sandbox.service.js +212 -208
  117. package/dist/setup/setup-guides.service.d.ts +4 -1
  118. package/dist/setup/setup-guides.service.js +6 -1
  119. package/dist/themes/avatar-preset-key.d.ts +6 -0
  120. package/dist/themes/avatar-preset-key.js +9 -0
  121. package/dist/themes/theme-state.d.ts +29 -1
  122. package/dist/themes/theme-state.js +40 -1
  123. package/dist/themes/themes.service.d.ts +28 -1
  124. package/dist/themes/themes.service.js +36 -2
  125. package/dist/tools/builtins/image/generate.d.ts +3 -0
  126. package/dist/tools/builtins/image/generate.js +21 -11
  127. package/dist/tools/builtins/image/index.d.ts +1 -1
  128. package/dist/tools/builtins/image/index.js +1 -1
  129. package/dist/tools/builtins/sandbox/common.d.ts +36 -12
  130. package/dist/tools/builtins/sandbox/common.js +62 -18
  131. package/dist/tools/builtins/sandbox/read.d.ts +5 -2
  132. package/dist/tools/builtins/sandbox/read.js +9 -6
  133. package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
  134. package/dist/tools/builtins/sandbox/task-output.js +6 -5
  135. package/dist/tools/builtins/skill-load.js +13 -4
  136. package/dist/until-aborted.d.ts +5 -0
  137. package/dist/until-aborted.js +16 -0
  138. package/package.json +4 -4
  139. package/src/migrations/0176_device_report.sql +6 -0
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { SANDBOX_EXTENSION_POINT } from "@capybara-hq/plugin-sdk";
10
+ import { DEVICE_PROVIDER_EXTENSION_POINT } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { ExtensionRegistry } from "../extensions/registry.js";
13
13
  import { guardProviderConnection } from "./unreachable.js";
@@ -15,21 +15,22 @@ import { guardProviderConnection } from "./unreachable.js";
15
15
  export const LOCAL_PROVIDER = "@local";
16
16
  /**
17
17
  * A kernel-internal provider name: it starts with `@`, which no extension name can
18
- * (`EXTENSION_NAME_RE`), so it never collides with a loaded `sandbox@2` plugin.
18
+ * (`EXTENSION_NAME_RE`), so it never collides with a loaded `device-provider@1` plugin.
19
19
  */
20
20
  export const isInternalProvider = (name) => name.startsWith("@");
21
21
  /**
22
- * The sandbox providers of this process. The cloud provider is the loaded `sandbox@2` extension,
22
+ * The device providers of this process (a registry: which of them serve an org is
23
+ * `DeviceProviderSelection`). A cloud provider is a loaded `device-provider@1` extension,
23
24
  * read from the {@link ExtensionRegistry} at every call (providers are ready only after the
24
- * extension load, and change with installs). Kernel-internal providers (`@local`) are registered
25
- * by their module on init, in every replica: they are code, not shared state.
25
+ * extension load, and change with installs). Kernel-internal providers (`@local`) are registered by their
26
+ * module on init, in every replica: they are code, not shared state.
26
27
  *
27
- * Every `sandbox@2` extension is handed out guarded: a network-level failure to reach it is
28
+ * Every `device-provider@1` extension is handed out guarded: a network-level failure to reach it is
28
29
  * rethrown as `SandboxProviderUnreachableError` (`./unreachable.ts`), so the tools can tell it
29
30
  * apart. Internal providers are not: their failures (the device relay's Redis, the machine's
30
31
  * connection) are the kernel's own and have their own errors.
31
32
  */
32
- let SandboxProviders = class SandboxProviders {
33
+ let DeviceProviders = class DeviceProviders {
33
34
  registry;
34
35
  internal = new Map();
35
36
  constructor(registry) {
@@ -38,54 +39,45 @@ let SandboxProviders = class SandboxProviders {
38
39
  /** Registers a kernel-internal provider (an `@…` name); a later registration replaces it. */
39
40
  register(entry) {
40
41
  if (!isInternalProvider(entry.plugin)) {
41
- throw new Error(`an internal sandbox provider name starts with @: ${entry.plugin}`);
42
+ throw new Error(`an internal device provider name starts with @: ${entry.plugin}`);
42
43
  }
43
44
  this.internal.set(entry.plugin, entry);
44
45
  }
45
- /** The cloud provider (the loaded `sandbox@2` extension); undefined without one. */
46
- cloud() {
47
- const e = this.registry.list("sandbox").find((x) => x.capability === SANDBOX_EXTENSION_POINT);
48
- return e
49
- ? {
50
- plugin: e.plugin,
51
- version: e.version,
52
- impl: guardProviderConnection(e.impl),
53
- }
54
- : undefined;
55
- }
56
46
  /**
57
- * A provider by name: a registered internal provider, else a still-loaded `sandbox@2` extension
58
- * of that plugin name (to destroy an earlier provider's resources).
47
+ * The provider of a device, from its `devices.provider` (fixed at creation): a registered
48
+ * internal one (`@local`), else the loaded `device-provider@1` extension of that plugin name,
49
+ * on in no org in particular (whether it serves the device's org is
50
+ * `DeviceProviderSelection.isOnInOrg`). Undefined when neither exists, or for a device without
51
+ * a provider (`null`). Never another provider in its place.
59
52
  */
60
- forName(name) {
61
- const own = this.internal.get(name);
53
+ forDevice(provider) {
54
+ if (provider === null)
55
+ return undefined;
56
+ const own = this.internal.get(provider);
62
57
  if (own)
63
58
  return own;
64
59
  const e = this.registry
65
- .list("sandbox")
66
- .find((x) => x.capability === SANDBOX_EXTENSION_POINT && x.plugin === name);
67
- return e
68
- ? {
69
- plugin: e.plugin,
70
- version: e.version,
71
- impl: guardProviderConnection(e.impl),
72
- }
73
- : undefined;
60
+ .list("device-provider")
61
+ .find((x) => x.capability === DEVICE_PROVIDER_EXTENSION_POINT && x.plugin === provider);
62
+ return e ? this.guarded(e) : undefined;
63
+ }
64
+ /** Every loaded `device-provider@1` extension (no internal ones), in registry order: the sweeps. */
65
+ loaded() {
66
+ return this.registry
67
+ .list("device-provider")
68
+ .filter((x) => x.capability === DEVICE_PROVIDER_EXTENSION_POINT)
69
+ .map((e) => this.guarded(e));
70
+ }
71
+ guarded(e) {
72
+ return {
73
+ plugin: e.plugin,
74
+ version: e.version,
75
+ impl: guardProviderConnection(e.impl),
76
+ };
74
77
  }
75
78
  };
76
- SandboxProviders = __decorate([
79
+ DeviceProviders = __decorate([
77
80
  Injectable(),
78
81
  __param(0, Inject(ExtensionRegistry))
79
- ], SandboxProviders);
80
- export { SandboxProviders };
81
- /**
82
- * The provider a device works with, from its `devices.provider`: an internal one
83
- * (`@local`) by that name only, never falling back to the cloud provider; any other device
84
- * is a cloud device and uses the current cloud provider (files kept by another provider are
85
- * refused by the sandbox service, `device.unavailable`).
86
- */
87
- export function providerForDevice(providers, provider) {
88
- if (provider !== null && isInternalProvider(provider))
89
- return providers.forName(provider);
90
- return providers.cloud();
91
- }
82
+ ], DeviceProviders);
83
+ export { DeviceProviders };
@@ -6,14 +6,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { Module } from "@nestjs/common";
8
8
  import { ExtensionRegistryModule } from "../extensions/registry.js";
9
- import { SandboxProviders } from "./providers.js";
9
+ import { DeviceProviders } from "./providers.js";
10
10
  let SandboxProviderRegistryModule = class SandboxProviderRegistryModule {
11
11
  };
12
12
  SandboxProviderRegistryModule = __decorate([
13
13
  Module({
14
14
  imports: [ExtensionRegistryModule],
15
- providers: [SandboxProviders],
16
- exports: [SandboxProviders],
15
+ providers: [DeviceProviders],
16
+ exports: [DeviceProviders],
17
17
  })
18
18
  ], SandboxProviderRegistryModule);
19
19
  export { SandboxProviderRegistryModule };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Sandboxes: the one {@link SandboxService} (a device's file system and instance over the
3
- * `sandbox@2` provider, with the shared / exclusive leases of {@link SandboxLeases}), the review
3
+ * `device-provider@1` provider, with the shared / exclusive leases of {@link SandboxLeases}), the review
4
4
  * every command passes in auto mode ({@link CommandReviewService}), and the producer of the
5
5
  * one-off `sandbox-destroy-for` jobs (`MaintenanceProcessor` consumes them). The sweeps
6
6
  * (`SandboxSweepJobs`) are the worker role's (`WorkerModule`).
@@ -7,12 +7,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { Module } from "@nestjs/common";
8
8
  import { BackgroundStoreModule } from "../background/store.module.js";
9
9
  import { EventLogModule } from "../conversations/event-log.js";
10
+ import { DeviceProviderSelectionModule } from "../devices/device-provider-selection.module.js";
10
11
  import { ExtensionsModule } from "../extensions/extensions.module.js";
11
12
  import { QueueModule } from "../infra/queue/queue.module.js";
12
13
  import { ModelsModule } from "../models/models.module.js";
13
14
  import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
14
15
  import { StepLogModule } from "../runtime/step-log.js";
15
16
  import { CloudPermissionSnapshotsModule } from "./cloud-permission-snapshot.module.js";
17
+ import { DeviceReports } from "./device-reports.js";
16
18
  import { SandboxJobs } from "./jobs.js";
17
19
  import { LegacyRetirementModule } from "./legacy-retirement.module.js";
18
20
  import { OperationAuthorityModule } from "./operation-authority.module.js";
@@ -24,7 +26,7 @@ import { CommandReviewService } from "./review/review.service.js";
24
26
  import { SandboxService } from "./sandbox.service.js";
25
27
  /**
26
28
  * Sandboxes: the one {@link SandboxService} (a device's file system and instance over the
27
- * `sandbox@2` provider, with the shared / exclusive leases of {@link SandboxLeases}), the review
29
+ * `device-provider@1` provider, with the shared / exclusive leases of {@link SandboxLeases}), the review
28
30
  * every command passes in auto mode ({@link CommandReviewService}), and the producer of the
29
31
  * one-off `sandbox-destroy-for` jobs (`MaintenanceProcessor` consumes them). The sweeps
30
32
  * (`SandboxSweepJobs`) are the worker role's (`WorkerModule`).
@@ -34,6 +36,8 @@ let SandboxModule = class SandboxModule {
34
36
  SandboxModule = __decorate([
35
37
  Module({
36
38
  imports: [
39
+ // which providers serve an org: a use needs the device's provider on in its org
40
+ DeviceProviderSelectionModule,
37
41
  SandboxProviderRegistryModule,
38
42
  PermissionAuthorityModule,
39
43
  PermissionFactsModule,
@@ -49,7 +53,7 @@ SandboxModule = __decorate([
49
53
  StepLogModule,
50
54
  QueueModule.registerQueue(MAINTENANCE_QUEUE_NAME),
51
55
  ],
52
- providers: [SandboxService, SandboxJobs, CommandReviewService],
56
+ providers: [SandboxService, SandboxJobs, CommandReviewService, DeviceReports],
53
57
  exports: [
54
58
  SandboxProviderRegistryModule,
55
59
  LegacyRetirementModule,
@@ -60,6 +64,7 @@ SandboxModule = __decorate([
60
64
  SandboxJobs,
61
65
  CommandReviewService,
62
66
  CloudPermissionSnapshotsModule,
67
+ DeviceReports,
63
68
  ],
64
69
  })
65
70
  ], SandboxModule);
@@ -4,16 +4,18 @@ import { SandboxOperationAuthority } from "./operation-authority.js";
4
4
  import { type OperationInvocation, SandboxOperationIntents } from "./operation-intents.js";
5
5
  import { PermissionInstanceWrites } from "./permission-instance-writes.js";
6
6
  export type { HeldProvider } from "./held-operations.js";
7
- import { type ExecResult, type SandboxHandle, type SandboxLimits, type SandboxProvider, type SandboxRoots } from "@capybara-hq/plugin-sdk";
7
+ import { type DeviceProvider, type ExecResult, type SandboxHandle, type SandboxLimits, type SandboxRoots } from "@capybara-hq/plugin-sdk";
8
8
  import type { Redis } from "ioredis";
9
9
  import { type Selectable } from "kysely";
10
10
  import type { KernelConfig } from "../config/schema.js";
11
11
  import type { DeviceInstancesTable } from "../db/kernel-schema.js";
12
+ import { DeviceProviderSelection } from "../devices/device-provider-selection.js";
12
13
  import { ApiError } from "../errors.js";
13
14
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
14
15
  import { KernelDb } from "../infra/database/kernel-db.js";
15
16
  import type { KernelLogger } from "../log.js";
16
17
  import { CloudPermissionSnapshots, type CloudSnapshotOutcome } from "./cloud-permission-snapshot.js";
18
+ import { DeviceReports } from "./device-reports.js";
17
19
  import type { DeviceSandbox, HostGrantCeiling } from "./device-sandbox.js";
18
20
  import { type KernelReadInvocation } from "./kernel-read.js";
19
21
  import { SandboxLeases, type SandboxPathLease } from "./leases.js";
@@ -21,7 +23,7 @@ import { LegacyRetirementStore } from "./legacy-retirement.js";
21
23
  import { type AppliedLimits, type DeviceLimits, type EffectiveDevicePolicy } from "./modes.js";
22
24
  import type { HeldDeviceContextEvidence } from "./permission-context-types.js";
23
25
  import { PermissionFacts } from "./permission-facts.js";
24
- import { SandboxProviders } from "./providers.js";
26
+ import { DeviceProviders } from "./providers.js";
25
27
  import type { SandboxUseContext } from "./use-context.js";
26
28
  export { deviceNotFound } from "../devices/errors.js";
27
29
  export { SANDBOX_LOCK_PREFIX, SANDBOX_LOCK_TTL_MS, SandboxLockLostError, sandboxBusy, } from "./leases.js";
@@ -54,9 +56,8 @@ export interface SandboxUseInfo {
54
56
  */
55
57
  contextEvidence?: HeldDeviceContextEvidence;
56
58
  }
57
- export type { SandboxProviderEntry } from "./providers.js";
58
59
  type Row = Selectable<DeviceInstancesTable>;
59
- type ExecArgs = Parameters<SandboxProvider["exec"]>[1];
60
+ type ExecArgs = Parameters<DeviceProvider["exec"]>[1];
60
61
  /**
61
62
  * One instance of a device: its handle and the row's `created_at`, which the fenced write
62
63
  * after every `create` sets. The handle alone is not enough: sandbox-docker's handle is the
@@ -74,7 +75,7 @@ interface Instance {
74
75
  * The provider {@link SandboxService.ifRunning} passes to its callback: every `exec` carries the
75
76
  * holder's tag; the caller names the actor.
76
77
  */
77
- export type TaggedProvider = Omit<SandboxProvider, "exec"> & {
78
+ export type TaggedProvider = Omit<DeviceProvider, "exec"> & {
78
79
  exec(h: SandboxHandle, args: Omit<ExecArgs, "tag">): Promise<ExecResult>;
79
80
  };
80
81
  /** What {@link SandboxService.ifRunning} did. */
@@ -135,8 +136,8 @@ export declare const isInstance: (row: Pick<Row, "handle" | "created_at">, gone:
135
136
  * Sandbox config problems to tell operators at startup (English log lines):
136
137
  * - `runtime.maxRunSeconds` below `sandbox.limits.maxCommandSeconds`: long commands are cut by the
137
138
  * run time limit (Ruling M20);
138
- * - the current provider plugin refuses the open public network (`refuseOpenNetwork: true` in its
139
- * startup config) while an org can be on it: auto mode always is, and a sandbox-mode cloud device
139
+ * - a loaded provider plugin refuses the open public network (`refuseOpenNetwork: true` in its
140
+ * startup config; one line per such provider) while an org can be on it: auto mode always is, and a sandbox-mode cloud device
140
141
  * keeps its org's cloud network, open by default, so turning auto mode off does not avoid it
141
142
  * (auto mode hardening spec K3). Only the kill switch (`sandbox.limits.egress: none`) does.
142
143
  * - `sandbox.limits.orgHosts: within` while the startup config does not turn auto mode off: the
@@ -145,11 +146,11 @@ export declare const isInstance: (row: Pick<Row, "handle" | "created_at">, gone:
145
146
  * No run duration limit (`runtime.maxRunSeconds` 0, the default) cuts no command, so there is
146
147
  * nothing to tell.
147
148
  */
148
- export declare function sandboxConfigWarnings(cfg: Pick<KernelConfig, "runtime" | "sandbox" | "extensionConfig"> & Partial<Pick<KernelConfig, "devices">>, providerPlugin?: string): {
149
+ export declare function sandboxConfigWarnings(cfg: Pick<KernelConfig, "runtime" | "sandbox" | "extensionConfig"> & Partial<Pick<KernelConfig, "devices">>, providerPlugins?: readonly string[]): {
149
150
  level: "warn";
150
151
  message: string;
151
152
  }[];
152
- /** No sandbox provider (503). */
153
+ /** No device to run on: none bound and none can be made (no device provider on in the org; 503). */
153
154
  export declare const sandboxUnavailable: () => ApiError;
154
155
  /**
155
156
  * An owner browse found no running instance of the device (409): the picker starts the device
@@ -184,7 +185,7 @@ export declare const recreateRequired: () => ApiError;
184
185
  */
185
186
  export declare const replaceRequired: () => ApiError;
186
187
  /**
187
- * The kernel's sandbox service over the `sandbox@2` provider, keyed by **device** (spec
188
+ * The kernel's sandbox service over the `device-provider@1` provider, keyed by **device** (spec
188
189
  * 2026-11-07-environments-design §4.2, §5.1): one file system kept until the device is
189
190
  * deleted, plus one instance attached to it that comes and goes; all conversations bound to the
190
191
  * device (and their sub-agents) share both.
@@ -195,7 +196,7 @@ export declare const replaceRequired: () => ApiError;
195
196
  * `fs_status` becomes `lost` and uses fail with `device.files_lost` until
196
197
  * {@link resetFileSystem}.
197
198
  * - **Leases** (phase C, spec §10, {@link SandboxLeases}), keyed by device id: using an
198
- * instance recorded `running` with the current provider takes a **shared** lease, so up to
199
+ * instance recorded `running` with the device's provider takes a **shared** lease, so up to
199
200
  * `sandbox.maxConcurrentCommands` holders (all sessions of the device) run at once. Every
200
201
  * lifecycle change (create, resume, rebuild, suspend, destroy, reset) takes the **exclusive**
201
202
  * lease, alone; a caller that needs one on the use path sets the intent so new shared leases wait
@@ -231,18 +232,20 @@ export declare const replaceRequired: () => ApiError;
231
232
  * row's `created_at` (set by the fenced write after each `create`); the handle alone is the same
232
233
  * after a rebuild on providers whose handle is the instance name (sandbox-docker).
233
234
  *
234
- * - **Provider per device** (environments spec §6): each call resolves the provider from
235
- * the device's `devices.provider` ({@link providerForDevice}): a `device`
236
- * device runs on the kernel-internal `@local` provider (never the cloud one), a cloud
237
- * device on the loaded `sandbox@2` extension. A `@local` instance is never suspended or
238
- * destroyed for inactivity; a deleted `@local` device (or one of a deleted org) is
239
- * destroyed by the sweep like any other.
235
+ * - **Provider per device** (device-provider spec §6.1): a device is bound to its provider
236
+ * (`devices.provider`, fixed at creation) for life, resolved at every call
237
+ * ({@link DeviceProviders.forDevice}): a local device runs on the kernel-internal `@local`
238
+ * provider, any other on the loaded `device-provider@1` extension of that name. Several
239
+ * providers serve one org side by side. A use needs the provider loaded **and** on in the
240
+ * device's org ({@link DeviceProviderSelection.isOnInOrg}); otherwise, and for an instance row
241
+ * naming another provider, the use fails `device.unavailable` (503) and nothing changes: the
242
+ * files and instance stay, nothing is demoted, recreated or moved to another provider.
243
+ * Lifecycle cleanup (destroy, sweeps, reset) only needs the provider loaded. The sweeps run
244
+ * per loaded provider over its own rows; rows of a provider that is not loaded are never
245
+ * touched. A `@local` instance is never suspended or destroyed for inactivity; a deleted
246
+ * `@local` device (or one of a deleted org) is destroyed by the sweep like any other.
240
247
  *
241
- * Files kept by another provider than the current one make the device unusable
242
- * (`device.unavailable`) until that provider is back; deleting it still works while that
243
- * provider is loaded ({@link SandboxProviders.forName}). Without the device's provider
244
- * {@link availableFor} is false and uses throw `sandbox.unavailable` (503). No in-process state:
245
- * replicas share it through PG and Redis.
248
+ * No in-process state: replicas share it through PG and Redis.
246
249
  */
247
250
  /** Available only to kernel staging callbacks, never to a held user-operation callback. */
248
251
  export interface SandboxStaging {
@@ -260,6 +263,8 @@ export declare class SandboxService {
260
263
  private readonly leases;
261
264
  /** The providers (read at every call: providers are ready after the extension load). */
262
265
  private readonly providers;
266
+ /** Whether a device's provider serves its org now (read at every use, never cached). */
267
+ private readonly selection;
263
268
  private readonly config;
264
269
  private readonly log;
265
270
  private readonly facts;
@@ -270,33 +275,57 @@ export declare class SandboxService {
270
275
  private readonly retirement;
271
276
  /** The cloud snapshot writer's reconcile, for the lifecycle reconcile of marked devices (B-12). */
272
277
  private readonly snapshots;
278
+ /** The stored device report, refreshed after a create or a resume (never fails the use). */
279
+ private readonly reports;
273
280
  constructor(db: KernelDb,
274
281
  /** The record of the instance each holder last used (`capk:sandbox-seen:…`). */
275
282
  redis: Pick<Redis, "get" | "set" | "getdel">, leases: SandboxLeases,
276
283
  /** The providers (read at every call: providers are ready after the extension load). */
277
- providers: Pick<SandboxProviders, "cloud" | "forName">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment" | "readDevice" | "deviceSandbox" | "deviceSandboxFacts" | "orgHostGrantCeiling">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
284
+ providers: Pick<DeviceProviders, "forDevice" | "loaded">,
285
+ /** Whether a device's provider serves its org now (read at every use, never cached). */
286
+ selection: Pick<DeviceProviderSelection, "isOnInOrg">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment" | "readDevice" | "deviceSandbox" | "deviceSandboxFacts" | "orgHostGrantCeiling">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
278
287
  /** The retirement obligations every lifecycle acquisition is gated on (8.5). */
279
288
  retirement: Pick<LegacyRetirementStore, "unresolved" | "hasUnresolved" | "settleRebooted" | "scanUntilStable" | "frozen" | "frozenAt" | "quarantine" | "noteFailure" | "resolveDestroyed" | "resolveCancelled" | "membersOf" | "recordDestruction" | "destructionRecorded">,
280
289
  /** The cloud snapshot writer's reconcile, for the lifecycle reconcile of marked devices (B-12). */
281
- snapshots: Pick<CloudPermissionSnapshots, "reconcileHeld">);
290
+ snapshots: Pick<CloudPermissionSnapshots, "reconcileHeld">,
291
+ /** The stored device report, refreshed after a create or a resume (never fails the use). */
292
+ reports: Pick<DeviceReports, "refresh">);
282
293
  /** Poll interval while waiting for a lease (the leases' own). */
283
294
  private get pollMs();
284
295
  /**
285
- * Whether there is a cloud sandbox provider (a loaded `sandbox@2` extension). For gates that have
286
- * no device yet (tool listing, skill files); a call on a device asks
287
- * {@link availableFor}.
296
+ * Whether the device of `orgId` can be used now: its provider is loaded and on in the org
297
+ * ({@link DeviceProviderSelection.isOnInOrg}; `@local`: registered). A missing device, one of
298
+ * another org or one without a provider is not.
288
299
  */
289
- get cloudAvailable(): boolean;
290
- /** Whether the device's provider is there (`@local` registered, or a cloud provider). */
291
- availableFor(deviceId: string): Promise<boolean>;
300
+ availableFor(deviceId: string, orgId: string): Promise<boolean>;
292
301
  /**
293
- * The provider the device works with, read from its row ({@link providerForDevice});
294
- * a missing row (or one of another org, with `orgId`) reads as a cloud device, whose use
295
- * then fails as not found.
302
+ * Whether the provider the device is bound to is loaded here (`@local`: registered), whatever
303
+ * its org says: for lifecycle work that goes on while the org has the provider off (owed
304
+ * revocations, cleanup).
305
+ */
306
+ providerLoaded(deviceId: string): Promise<boolean>;
307
+ /**
308
+ * The device's `devices.provider` (null: none recorded; undefined: no such device, or one of
309
+ * another org with `orgId`).
310
+ */
311
+ private deviceProvider;
312
+ /**
313
+ * The loaded provider the device is bound to (no org check: lifecycle work and reads that
314
+ * need no use); undefined when the device is missing, has none or its provider is not loaded.
296
315
  */
297
316
  private providerOf;
298
- /** {@link providerOf}, or `sandbox.unavailable` (503) without it. */
317
+ /**
318
+ * The provider a use of the device of `orgId` runs on: loaded and on in the org, else
319
+ * `device.unavailable` (503, files kept); a missing device or one of another org is
320
+ * `device.not_found`.
321
+ */
299
322
  private require;
323
+ /**
324
+ * The loaded provider for lifecycle work on the device (no org check: cleanup and maintenance
325
+ * go on while its org has the provider off), else `device.unavailable`; a missing device is
326
+ * `device.not_found`.
327
+ */
328
+ private loadedFor;
300
329
  /** Concurrent holders of one device (`sandbox.maxConcurrentCommands`, read at every use). */
301
330
  private get cap();
302
331
  /**
@@ -545,7 +574,7 @@ export declare class SandboxService {
545
574
  private readHeldContextEvidence;
546
575
  /**
547
576
  * Becomes a holder: loops until it has a shared lease on a running instance, or `sandbox.busy`.
548
- * An instance recorded `running` (with the current provider, not the `gone` instance) is used
577
+ * An instance recorded `running` (with the device's provider, not the `gone` instance) is used
549
578
  * under a shared lease; otherwise the exclusive lease (with intent) makes it run and is
550
579
  * downgraded. One token serves both, so the waiter passes its own intent. `wantNow` reads the
551
580
  * limits this use wants ({@link wantedLimits}), again after each wait, so a mode narrowed
@@ -583,7 +612,7 @@ export declare class SandboxService {
583
612
  /** The instance row belongs to another org: reported as not found, so ids cannot be probed. */
584
613
  private foreign;
585
614
  /**
586
- * Recorded running with the current provider on files not lost (lost ones go through the
615
+ * Recorded running with the device's provider on files not lost (lost ones go through the
587
616
  * exclusive path, which refuses them), and not the instance found gone.
588
617
  */
589
618
  private usable;
@@ -652,6 +681,8 @@ export declare class SandboxService {
652
681
  * many it suspended. Called every minute by the `sandbox-suspend-idle` cron.
653
682
  */
654
683
  suspendIdle(now: Date): Promise<number>;
684
+ /** {@link suspendIdle} for the rows of one provider. */
685
+ private suspendIdleOf;
655
686
  /**
656
687
  * Destruction sweep: an instance unused for longer than `destroyAfterInactiveDays` is destroyed
657
688
  * (the instance only; the file system is kept and the next use builds a new instance on it); an
@@ -662,21 +693,27 @@ export declare class SandboxService {
662
693
  * hourly by the `sandbox-destroy-inactive` cron.
663
694
  */
664
695
  destroyInactive(now: Date): Promise<number>;
696
+ /**
697
+ * One destruction sweep over the rows of provider `p` matching `due` (never another provider's
698
+ * row: the row's provider is part of the condition, read again under the lease).
699
+ */
700
+ private sweepRows;
665
701
  /**
666
702
  * Destroys the device's instance, then its file system, then deletes its instance row
667
703
  * (device deletion, offboarding); nothing to do without a row. Waits for the exclusive lease
668
704
  * (with intent, so running commands finish and new ones wait) up to 10 minutes. Without the
669
- * device's provider it throws and the row stays, marked `sweep_failed_at` (the job is
670
- * retried, and the destruction sweep finishes a deleted device once the provider is back).
671
- * Files kept by another provider that is not loaded cannot be destroyed: it throws and the row
672
- * stays.
705
+ * provider of its instance row loaded it throws and the row stays, marked `sweep_failed_at` (the
706
+ * job is retried, and the destruction sweep finishes a deleted device once the provider is
707
+ * back). The provider only needs to be loaded: a device is deleted while its org has the
708
+ * provider off too.
673
709
  */
674
710
  destroyDevice(deviceId: string): Promise<void>;
675
711
  /**
676
712
  * Starts the device over with empty files (after `device.files_lost`, or on request):
677
713
  * under the exclusive lease (waited for like {@link destroyDevice}) destroys any instance and
678
714
  * the file system (a `lost` one is only dropped), and records no file system; the next use
679
- * creates a new one. Nothing to do without a row. Throws `sandbox.unavailable` without a provider.
715
+ * creates a new one. Nothing to do without a row. Throws `device.unavailable` while the device's
716
+ * provider is not loaded, or when its instance row names another provider.
680
717
  */
681
718
  resetFileSystem(deviceId: string): Promise<void>;
682
719
  /**
@@ -704,13 +741,16 @@ export declare class SandboxService {
704
741
  */
705
742
  reconcileLimits(deviceId: string, signal?: AbortSignal): Promise<CloudSnapshotOutcome | "busy">;
706
743
  /**
707
- * The worker's sweep of {@link reconcileLimits} (`sandbox-reconcile-limits`): up to `limit`
708
- * live cloud devices of the loaded cloud provider carrying the marker on a live instance, in
709
- * id order from a shared keyset cursor that wraps around (no starvation), each tried at most
710
- * once per {@link RECONCILE_RETRY_SECONDS} across replicas (a Redis marker).
711
- * Nothing without a cloud provider that can `update`. Returns how many it reconciled.
744
+ * The worker's sweep of {@link reconcileLimits} (`sandbox-reconcile-limits`): for each loaded
745
+ * provider that can `update`, up to `limit` live cloud devices of its own carrying the marker on
746
+ * a live instance, in id order from that provider's shared keyset cursor that wraps around (no
747
+ * starvation), each tried at most once per {@link RECONCILE_RETRY_SECONDS} across replicas (a
748
+ * Redis marker). Rows of a provider that is not loaded are never touched. Returns how many it
749
+ * reconciled.
712
750
  */
713
751
  reconcileMarked(limit?: number): Promise<number>;
752
+ /** {@link reconcileMarked} for the devices of one provider. */
753
+ private reconcileMarkedOf;
714
754
  /**
715
755
  * The retirement gate (permission runtime cutover 8.5), under the exclusive lifecycle lease and
716
756
  * before the instance is used, resumed, rebuilt, switched to another provider, bound or
@@ -786,28 +826,20 @@ export declare class SandboxService {
786
826
  /** Runs `call` with its own short signal; a failure is warned and returns false. */
787
827
  private bestEffort;
788
828
  /**
789
- * Destroys the file system another provider may have made under the device's name without
790
- * the kernel recording it (`destroyFileSystemByName`; not there is success). That provider not
791
- * loaded, or a failure, is only warned (the files may leak there) so the device stays
792
- * usable; an abort is thrown.
793
- */
794
- private dropUnrecordedFiles;
795
- /**
796
- * Destroys an instance of another provider with that provider: still loaded and destroyed →
797
- * false; otherwise warns and returns true (the record must be kept).
829
+ * Destroys an instance an earlier kernel recorded in `prev_*` (left by a provider replaced back
830
+ * then) with that provider: still loaded and destroyed → false; otherwise warns and returns true
831
+ * (the record must be kept).
798
832
  */
799
833
  private retire;
800
834
  /**
801
- * Under the lease: destroys the row's instance (and a leaked one of an earlier provider). An
802
- * instance without a handle (a create that ended before the handle was recorded) is destroyed by
803
- * name. Returns the `prev_*` patch for instances that could not be destroyed.
835
+ * Under the lease: destroys the row's instance with its own provider `p` (and an instance an
836
+ * earlier kernel recorded in `prev_*`). An instance without a handle (a create that ended before
837
+ * the handle was recorded) is destroyed by name. Returns the `prev_*` patch.
804
838
  */
805
839
  private destroyInstance;
806
840
  /**
807
- * Under the lease: destroys the row's file system with the provider that made it (by name when
808
- * no handle was recorded: `createFileSystem` may have finished before the kernel stopped). With
809
- * that provider not loaded it throws (the row must stay for a retry), or with `lenient` only
810
- * warns (the files leak at that provider).
841
+ * Under the lease: destroys the row's file system with its own provider `p` (by name when no
842
+ * handle was recorded: `createFileSystem` may have finished before the kernel stopped).
811
843
  */
812
844
  private destroyFiles;
813
845
  /**
@@ -817,13 +849,8 @@ export declare class SandboxService {
817
849
  private destroyRow;
818
850
  /** Due for suspension: made by this provider, running, and idle or running for too long. */
819
851
  private suspendDue;
820
- /** The provider of an instance row: an internal one (`@local`) by name, else the cloud one. */
852
+ /** The loaded provider of an instance row (its own `provider`); undefined when not loaded. */
821
853
  private rowProvider;
822
- /**
823
- * A row the idle sweeps may touch: not on a kernel-internal provider (`@local` instances live on
824
- * people's machines and are never suspended or destroyed for inactivity).
825
- */
826
- private cloudRow;
827
854
  /** The device was deleted, or its org was: the instance and the files go. */
828
855
  private deviceGone;
829
856
  /** Due for instance destruction: an instance (or a create in progress) unused for too long. */