@capybara-hq/kernel 0.1.0-rc.67 → 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.
Files changed (226) hide show
  1. package/bootstrap.json +9 -1
  2. package/dist/admin/admin.module.js +2 -0
  3. package/dist/admin/health.service.d.ts +11 -4
  4. package/dist/admin/health.service.js +33 -17
  5. package/dist/background/poll.job.js +2 -2
  6. package/dist/background/tasks.service.d.ts +5 -5
  7. package/dist/background/tasks.service.js +9 -8
  8. package/dist/catalog/credential-key.d.ts +10 -0
  9. package/dist/catalog/credential-key.js +28 -0
  10. package/dist/catalog/marketplaces.service.d.ts +1 -1
  11. package/dist/catalog/plugin-upgrade.js +1 -19
  12. package/dist/catalog/requests.service.js +1 -1
  13. package/dist/config/schema.d.ts +1 -1
  14. package/dist/config/schema.js +9 -9
  15. package/dist/conversations/conversations.controller.d.ts +8 -3
  16. package/dist/conversations/conversations.controller.js +8 -3
  17. package/dist/conversations/conversations.service.d.ts +33 -15
  18. package/dist/conversations/conversations.service.js +60 -10
  19. package/dist/conversations/events.d.ts +21 -41
  20. package/dist/conversations/events.js +57 -31
  21. package/dist/conversations/permission-profiles.controller.d.ts +6 -4
  22. package/dist/conversations/permission-profiles.service.d.ts +6 -4
  23. package/dist/ctx/create-ctx.d.ts +20 -1
  24. package/dist/ctx/create-ctx.js +77 -6
  25. package/dist/ctx/device-provider-check.d.ts +6 -2
  26. package/dist/ctx/device-provider-check.js +17 -2
  27. package/dist/db/kernel-schema.d.ts +10 -48
  28. package/dist/devices/access.d.ts +3 -4
  29. package/dist/devices/access.js +3 -4
  30. package/dist/devices/conversation-devices.d.ts +1 -3
  31. package/dist/devices/conversation-devices.js +2 -7
  32. package/dist/devices/device-projects.service.js +24 -29
  33. package/dist/devices/device-provider-selection.d.ts +5 -6
  34. package/dist/devices/device-provider-selection.js +8 -9
  35. package/dist/devices/devices.controller.d.ts +8 -21
  36. package/dist/devices/devices.controller.js +9 -34
  37. package/dist/devices/devices.module.js +6 -4
  38. package/dist/devices/devices.schemas.d.ts +1 -5
  39. package/dist/devices/devices.schemas.js +1 -5
  40. package/dist/devices/devices.service.d.ts +84 -147
  41. package/dist/devices/devices.service.js +134 -229
  42. package/dist/devices/dto.d.ts +5 -32
  43. package/dist/devices/dto.js +5 -37
  44. package/dist/devices/errors.d.ts +6 -5
  45. package/dist/devices/errors.js +7 -8
  46. package/dist/devices/project-rules.d.ts +9 -11
  47. package/dist/devices/project-rules.js +7 -7
  48. package/dist/devices/working-root.d.ts +3 -6
  49. package/dist/devices/working-root.js +3 -8
  50. package/dist/dial-in/access.d.ts +23 -0
  51. package/dist/dial-in/access.js +64 -0
  52. package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
  53. package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
  54. package/dist/dial-in/auth.module.d.ts +7 -0
  55. package/dist/dial-in/auth.module.js +27 -0
  56. package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
  57. package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
  58. package/dist/dial-in/dial-in.module.d.ts +9 -0
  59. package/dist/dial-in/dial-in.module.js +37 -0
  60. package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
  61. package/dist/{local-devices → dial-in}/dto.js +14 -2
  62. package/dist/dial-in/envelope.d.ts +95 -0
  63. package/dist/dial-in/envelope.js +89 -0
  64. package/dist/dial-in/gateway.d.ts +214 -0
  65. package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
  66. package/dist/dial-in/handlers.d.ts +47 -0
  67. package/dist/dial-in/handlers.js +84 -0
  68. package/dist/dial-in/machines.d.ts +155 -0
  69. package/dist/dial-in/machines.js +383 -0
  70. package/dist/dial-in/relay.d.ts +135 -0
  71. package/dist/dial-in/relay.js +444 -0
  72. package/dist/dial-in/relay.module.d.ts +7 -0
  73. package/dist/dial-in/relay.module.js +24 -0
  74. package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
  75. package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
  76. package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
  77. package/dist/{local-devices → dial-in}/targets.js +3 -48
  78. package/dist/errors.d.ts +8 -27
  79. package/dist/errors.js +8 -27
  80. package/dist/extensions/bootstrap.d.ts +5 -0
  81. package/dist/extensions/bootstrap.js +10 -1
  82. package/dist/extensions/extensions.module.js +6 -0
  83. package/dist/extensions/host.d.ts +6 -0
  84. package/dist/extensions/host.js +12 -2
  85. package/dist/extensions/permission-set.d.ts +15 -1
  86. package/dist/extensions/permission-set.js +11 -1
  87. package/dist/extensions/permission-view.d.ts +1 -1
  88. package/dist/extensions/permission-view.js +4 -1
  89. package/dist/http/api.module.js +4 -4
  90. package/dist/http/gateway-routes.d.ts +1 -1
  91. package/dist/http/gateway-routes.js +1 -1
  92. package/dist/http/meta.controller.js +1 -1
  93. package/dist/identity/settings.d.ts +1 -1
  94. package/dist/identity/settings.js +6 -8
  95. package/dist/infra/config/kernel-config.service.js +2 -2
  96. package/dist/infra/outbox/registry.d.ts +0 -14
  97. package/dist/infra/outbox/registry.js +0 -15
  98. package/dist/infra/throttler/named-throttlers.d.ts +1 -1
  99. package/dist/infra/throttler/named-throttlers.js +1 -1
  100. package/dist/kernel.module.js +0 -3
  101. package/dist/orgs/settings.service.js +5 -10
  102. package/dist/overrides.d.ts +0 -4
  103. package/dist/overrides.js +0 -2
  104. package/dist/platform/exclusions.js +5 -5
  105. package/dist/platform/ops/admin.ops.js +1 -1
  106. package/dist/platform/ops/conversations.ops.js +5 -2
  107. package/dist/platform/ops/devices.ops.js +11 -24
  108. package/dist/platform/ops/inbox.ops.js +1 -1
  109. package/dist/roles/gateway-role.d.ts +3 -3
  110. package/dist/roles/gateway-role.js +4 -4
  111. package/dist/roles/gateway.module.d.ts +1 -1
  112. package/dist/roles/gateway.module.js +5 -5
  113. package/dist/runtime/context/device-paths.d.ts +4 -1
  114. package/dist/runtime/context/permission-profile.js +5 -5
  115. package/dist/runtime/maintenance.d.ts +2 -5
  116. package/dist/runtime/maintenance.js +9 -19
  117. package/dist/runtime/project/knowledge.js +4 -5
  118. package/dist/runtime/project/knowledge.service.js +2 -1
  119. package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
  120. package/dist/sandbox/cloud-permission-snapshot.js +1 -3
  121. package/dist/sandbox/device-reports.d.ts +74 -14
  122. package/dist/sandbox/device-reports.js +190 -33
  123. package/dist/sandbox/device-reports.module.d.ts +7 -0
  124. package/dist/sandbox/device-reports.module.js +25 -0
  125. package/dist/sandbox/device-sandbox.d.ts +39 -41
  126. package/dist/sandbox/device-sandbox.js +44 -83
  127. package/dist/sandbox/kernel-read.d.ts +2 -2
  128. package/dist/sandbox/legacy-retirement.d.ts +11 -59
  129. package/dist/sandbox/legacy-retirement.js +34 -186
  130. package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
  131. package/dist/sandbox/legacy-retirement.module.js +2 -2
  132. package/dist/sandbox/managed-device-context.d.ts +16 -4
  133. package/dist/sandbox/managed-device-context.js +25 -8
  134. package/dist/sandbox/managed-device-context.module.js +4 -0
  135. package/dist/sandbox/modes.d.ts +3 -12
  136. package/dist/sandbox/modes.js +2 -14
  137. package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
  138. package/dist/{local-devices → sandbox}/network-grants.js +4 -49
  139. package/dist/sandbox/operation-authority-types.d.ts +2 -1
  140. package/dist/sandbox/operation-authority.d.ts +6 -20
  141. package/dist/sandbox/operation-authority.js +43 -104
  142. package/dist/sandbox/operation-authority.module.js +1 -1
  143. package/dist/sandbox/operation-intents.d.ts +4 -1
  144. package/dist/sandbox/operation-intents.js +11 -2
  145. package/dist/sandbox/operation-reconcile.job.js +2 -4
  146. package/dist/sandbox/permission-availability.d.ts +6 -7
  147. package/dist/sandbox/permission-availability.js +7 -10
  148. package/dist/sandbox/permission-call-grants.d.ts +2 -1
  149. package/dist/sandbox/permission-call-grants.js +1 -7
  150. package/dist/sandbox/permission-call-types.d.ts +4 -4
  151. package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
  152. package/dist/sandbox/permission-ceiling-writes.js +8 -35
  153. package/dist/sandbox/permission-config-publication.d.ts +9 -1
  154. package/dist/sandbox/permission-config-publication.js +29 -21
  155. package/dist/sandbox/permission-context-types.d.ts +17 -10
  156. package/dist/sandbox/permission-facts.d.ts +98 -95
  157. package/dist/sandbox/permission-facts.js +160 -314
  158. package/dist/sandbox/permission-instance-writes.d.ts +23 -37
  159. package/dist/sandbox/permission-instance-writes.js +44 -121
  160. package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
  161. package/dist/sandbox/permission-runtime-reports.js +105 -122
  162. package/dist/sandbox/providers.d.ts +26 -38
  163. package/dist/sandbox/providers.js +36 -18
  164. package/dist/sandbox/request-not-sent.d.ts +2 -13
  165. package/dist/sandbox/request-not-sent.js +2 -13
  166. package/dist/sandbox/review/permission-candidate.d.ts +13 -8
  167. package/dist/sandbox/review/permission-candidate.js +38 -48
  168. package/dist/sandbox/sandbox.module.js +7 -3
  169. package/dist/sandbox/sandbox.service.d.ts +49 -59
  170. package/dist/sandbox/sandbox.service.js +139 -259
  171. package/dist/schedules/fire.d.ts +15 -6
  172. package/dist/schedules/fire.js +27 -13
  173. package/dist/schedules/grant-rules.js +1 -1
  174. package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
  175. package/dist/schedules/scheduled-tasks.service.js +1 -4
  176. package/dist/schedules/schedules.module.js +5 -3
  177. package/dist/skills/invoke.d.ts +1 -1
  178. package/dist/skills/invoke.js +2 -3
  179. package/dist/tools/approvals.service.d.ts +8 -5
  180. package/dist/tools/approvals.service.js +5 -5
  181. package/dist/tools/builtins/sandbox/bash.js +1 -2
  182. package/dist/tools/builtins/sandbox/common.d.ts +15 -9
  183. package/dist/tools/builtins/sandbox/common.js +37 -38
  184. package/dist/tools/connectors.controller.d.ts +2 -0
  185. package/dist/tools/connectors.schemas.d.ts +2 -0
  186. package/dist/tools/credentials.d.ts +2 -0
  187. package/dist/tools/network-asks.d.ts +19 -22
  188. package/dist/tools/network-asks.js +15 -21
  189. package/dist/tools/oauth/authorization-params.d.ts +7 -0
  190. package/dist/tools/oauth/authorization-params.js +19 -0
  191. package/dist/tools/oauth/flow.js +7 -0
  192. package/dist/tools/oauth/tokens.js +2 -1
  193. package/dist/tools/pipeline.d.ts +6 -7
  194. package/dist/tools/pipeline.js +17 -21
  195. package/dist/tools/tools.module.js +3 -7
  196. package/package.json +3 -4
  197. package/src/migrations/0177_dial_in_contract.sql +32 -0
  198. package/dist/local-devices/device-auth.module.d.ts +0 -7
  199. package/dist/local-devices/device-auth.module.js +0 -25
  200. package/dist/local-devices/device-policy.service.d.ts +0 -213
  201. package/dist/local-devices/device-policy.service.js +0 -605
  202. package/dist/local-devices/instance-bindings.d.ts +0 -82
  203. package/dist/local-devices/instance-bindings.js +0 -307
  204. package/dist/local-devices/local-device-gateway.d.ts +0 -153
  205. package/dist/local-devices/local-device-provider.d.ts +0 -122
  206. package/dist/local-devices/local-device-provider.js +0 -326
  207. package/dist/local-devices/local-devices.module.d.ts +0 -31
  208. package/dist/local-devices/local-devices.module.js +0 -100
  209. package/dist/local-devices/machines.d.ts +0 -211
  210. package/dist/local-devices/machines.js +0 -766
  211. package/dist/local-devices/owner-report.d.ts +0 -81
  212. package/dist/local-devices/owner-report.js +0 -150
  213. package/dist/local-devices/owner-reports.d.ts +0 -48
  214. package/dist/local-devices/owner-reports.js +0 -208
  215. package/dist/local-devices/policy-op-jobs.d.ts +0 -15
  216. package/dist/local-devices/policy-op-jobs.js +0 -12
  217. package/dist/local-devices/policy-summary.d.ts +0 -102
  218. package/dist/local-devices/policy-summary.js +0 -155
  219. package/dist/local-devices/relay.d.ts +0 -166
  220. package/dist/local-devices/relay.js +0 -559
  221. package/dist/tools/device-op-resolver.d.ts +0 -34
  222. package/dist/tools/device-op-resolver.js +0 -120
  223. /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
  224. /package/dist/{local-devices → dial-in}/keys.js +0 -0
  225. /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
  226. /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
@@ -15,7 +15,10 @@ export interface DeviceModeLevel {
15
15
  mode: SandboxMode;
16
16
  allowedMode: SandboxMode;
17
17
  network: DeviceNetwork;
18
- /** A connected machine (`true`) rather than a cloud container. */
18
+ /**
19
+ * Its provider runs each operation on its host machine (an operation boundary, `true`) rather
20
+ * than in an instance of its own (a container).
21
+ */
19
22
  local: boolean;
20
23
  }
21
24
  /** The payload of a `device_paths` event; the mode fields are absent on events before auto mode. */
@@ -50,7 +50,7 @@ function networkLine(s) {
50
50
  case "open-public":
51
51
  return "Network: the open public internet; private, LAN, loopback, link-local and metadata addresses are closed inside the sandbox.";
52
52
  case "environment":
53
- return s.location === "local"
53
+ return s.boundary === "operation"
54
54
  ? "Network: the host environment; restricted-profile host lists do not restrict Full access."
55
55
  : "Network: the provisioned environment, subject to its outer network boundary.";
56
56
  }
@@ -102,11 +102,11 @@ function approverLines(p, box) {
102
102
  : "a separate reviewer approves; uncertainty asks the person";
103
103
  const lines = [];
104
104
  if (!instance)
105
- lines.push(`Directories outside the readable or writable directories: ${approver}.`);
105
+ lines.push(`Directories outside the writable directories: ${approver}.`);
106
106
  // `none` is both an allowlist without hosts and the kill switch, which the block does not tell
107
107
  // apart: the line names the approver and leaves the device's network switch to the device
108
108
  if (box.network.kind !== "open-public")
109
- lines.push(instance
109
+ lines.push(instance || box.perCallHosts === false
110
110
  ? instanceHostsLine(box)
111
111
  : box.network.kind === "none"
112
112
  ? `Network hosts (none authorized yet): ${approver}, where this device allows network access.`
@@ -151,10 +151,10 @@ export function permissionContextText(payload) {
151
151
  : "Sandbox: the same under every profile; new commands run in the device's OS sandbox, limited to the directories and network below.");
152
152
  lines.push(`Working directory: ${permissionQuote(s.workingRoot)}.`);
153
153
  if (s.filesystem.kind === "scoped") {
154
- lines.push(`Readable directories: ${arrayText(s.filesystem.readDirectories)}.`, `Writable directories: ${arrayText(s.filesystem.writeDirectories)}.`);
154
+ lines.push("Readable files: set by this device's provider, not by the permission profile.", `Writable directories: ${arrayText(s.filesystem.writeDirectories)}.`);
155
155
  }
156
156
  else
157
- lines.push(s.location === "local"
157
+ lines.push(s.boundary === "operation"
158
158
  ? "Filesystem: this device as the existing OS user; no additional OS privileges."
159
159
  : "Filesystem: the provisioned device environment as its existing OS user; no additional OS privileges.");
160
160
  lines.push(networkLine(s), outerLine(s.outerNetwork));
@@ -11,7 +11,6 @@ import { SandboxService } from "../sandbox/sandbox.service.js";
11
11
  import { ScheduledTaskFirer } from "../schedules/fire.js";
12
12
  import { ShareObjects } from "../shares/share-objects.js";
13
13
  import { PlatformIconObjects } from "../themes/platform-icon-objects.js";
14
- import { DeviceOpResolver } from "../tools/device-op-resolver.js";
15
14
  import { ToolDrift } from "../tools/drift.js";
16
15
  import { PermissionApprovalJobs } from "../tools/permission-approval-jobs.js";
17
16
  import { RunDeletion } from "./run-deletion.js";
@@ -27,8 +26,7 @@ export declare const MAINTENANCE_CONCURRENCY = 5;
27
26
  * {@link DirectorySync}, `run-stop` → {@link Offboarding.stopRun}, `bg-wake` and `ensure-run` → {@link RunQueue.ensureRun}, `stop-tree` →
28
27
  * {@link processStopTree} and `deliver-to-parent` → {@link processDeliverToParent} (both in
29
28
  * runtime/subagents/tree-jobs.ts, over {@link Waits}), `owned-plugin-cleanup` →
30
- * {@link OwnedPluginCleanup}, `sched-fire` and `sched-settle` → {@link ScheduledTaskFirer}, `device-op-resolve` →
31
- * {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}, `platform-icon-delete` →
29
+ * {@link OwnedPluginCleanup}, `sched-fire` and `sched-settle` → {@link ScheduledTaskFirer}, `share-object-delete` → {@link ShareObjects}, `platform-icon-delete` →
32
30
  * {@link PlatformIconObjects}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
33
31
  * such as `sandbox-suspend-idle`) runs that job's body once ({@link ScheduledRuns.runNow}), as the
34
32
  * maintenance handlers did when those jobs were schedulers on this queue: an operator's or a
@@ -46,14 +44,13 @@ export declare class MaintenanceProcessor extends WorkerHost<Worker> {
46
44
  private readonly runs;
47
45
  private readonly ownedCleanup;
48
46
  private readonly scheduledTasks;
49
- private readonly deviceOps;
50
47
  private readonly scheduled;
51
48
  private readonly log;
52
49
  private readonly operations;
53
50
  private readonly shareObjects;
54
51
  private readonly platformIcons;
55
52
  private readonly snapshots?;
56
- constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem" | "revokeDeadHolder">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, deviceOps: Pick<DeviceOpResolver, "resolve">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke">, shareObjects: Pick<ShareObjects, "deleteObject">, platformIcons: Pick<PlatformIconObjects, "deleteObject">, snapshots?: Pick<CloudPermissionSnapshots, "reconcileDevice"> | undefined);
53
+ constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem" | "revokeDeadHolder">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke">, shareObjects: Pick<ShareObjects, "deleteObject">, platformIcons: Pick<PlatformIconObjects, "deleteObject">, snapshots?: Pick<CloudPermissionSnapshots, "reconcileDevice"> | undefined);
57
54
  process(job: Job, token?: string): Promise<void>;
58
55
  /** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
59
56
  start(): void;
@@ -19,7 +19,6 @@ import { runJob } from "../infra/queue/run-job.js";
19
19
  import { KernelScheduleModule } from "../infra/schedule/schedule.module.js";
20
20
  import { ScheduledRuns } from "../infra/schedule/scheduled-runs.js";
21
21
  import { KERNEL_LOGGER } from "../infra/tokens.js";
22
- import { DEVICE_OP_RESOLVE_JOB, } from "../local-devices/policy-op-jobs.js";
23
22
  import { DIRECTORY_SYNC_JOB, DirectorySync } from "../orgs/directory-sync.js";
24
23
  import { Offboarding, RUN_STOP_JOB } from "../orgs/offboarding.js";
25
24
  import { OrgsModule } from "../orgs/orgs.module.js";
@@ -34,7 +33,6 @@ import { ScheduledTaskFireModule, ScheduledTaskFirer } from "../schedules/fire.j
34
33
  import { SCHED_FIRE_JOB, SCHED_SETTLE_JOB, } from "../schedules/job-ids.js";
35
34
  import { SHARE_OBJECT_DELETE_JOB, ShareObjects, ShareObjectsModule, } from "../shares/share-objects.js";
36
35
  import { PLATFORM_ICON_DELETE_JOB, PlatformIconObjects, PlatformIconObjectsModule, } from "../themes/platform-icon-objects.js";
37
- import { DeviceOpResolver } from "../tools/device-op-resolver.js";
38
36
  import { ToolDrift } from "../tools/drift.js";
39
37
  import { DRIFT_CONNECTOR_JOB } from "../tools/job-ids.js";
40
38
  import { PermissionApprovalJobs, } from "../tools/permission-approval-jobs.js";
@@ -55,8 +53,7 @@ export const MAINTENANCE_CONCURRENCY = 5;
55
53
  * {@link DirectorySync}, `run-stop` → {@link Offboarding.stopRun}, `bg-wake` and `ensure-run` → {@link RunQueue.ensureRun}, `stop-tree` →
56
54
  * {@link processStopTree} and `deliver-to-parent` → {@link processDeliverToParent} (both in
57
55
  * runtime/subagents/tree-jobs.ts, over {@link Waits}), `owned-plugin-cleanup` →
58
- * {@link OwnedPluginCleanup}, `sched-fire` and `sched-settle` → {@link ScheduledTaskFirer}, `device-op-resolve` →
59
- * {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}, `platform-icon-delete` →
56
+ * {@link OwnedPluginCleanup}, `sched-fire` and `sched-settle` → {@link ScheduledTaskFirer}, `share-object-delete` → {@link ShareObjects}, `platform-icon-delete` →
60
57
  * {@link PlatformIconObjects}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
61
58
  * such as `sandbox-suspend-idle`) runs that job's body once ({@link ScheduledRuns.runNow}), as the
62
59
  * maintenance handlers did when those jobs were schedulers on this queue: an operator's or a
@@ -74,14 +71,13 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
74
71
  runs;
75
72
  ownedCleanup;
76
73
  scheduledTasks;
77
- deviceOps;
78
74
  scheduled;
79
75
  log;
80
76
  operations;
81
77
  shareObjects;
82
78
  platformIcons;
83
79
  snapshots;
84
- constructor(permissionApprovals, waits, sandbox, drift, directory, deletion, offboarding, runs, ownedCleanup, scheduledTasks, deviceOps, scheduled, log, operations, shareObjects, platformIcons, snapshots) {
80
+ constructor(permissionApprovals, waits, sandbox, drift, directory, deletion, offboarding, runs, ownedCleanup, scheduledTasks, scheduled, log, operations, shareObjects, platformIcons, snapshots) {
85
81
  super();
86
82
  this.permissionApprovals = permissionApprovals;
87
83
  this.waits = waits;
@@ -93,7 +89,6 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
93
89
  this.runs = runs;
94
90
  this.ownedCleanup = ownedCleanup;
95
91
  this.scheduledTasks = scheduledTasks;
96
- this.deviceOps = deviceOps;
97
92
  this.scheduled = scheduled;
98
93
  this.log = log;
99
94
  this.operations = operations;
@@ -193,10 +188,6 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
193
188
  case SCHED_SETTLE_JOB:
194
189
  await this.scheduledTasks.settle(job.data);
195
190
  return;
196
- // a device policy op whose outcome was not recorded (transactional outbox spec §7)
197
- case DEVICE_OP_RESOLVE_JOB:
198
- await this.deviceOps.resolve(job.data);
199
- return;
200
191
  // a share snapshot a refresh or revoke stopped using (file sharing spec §2)
201
192
  case SHARE_OBJECT_DELETE_JOB:
202
193
  await this.shareObjects.deleteObject(job.data);
@@ -239,14 +230,13 @@ MaintenanceProcessor = __decorate([
239
230
  __param(7, Inject(RunQueue)),
240
231
  __param(8, Inject(OwnedPluginCleanup)),
241
232
  __param(9, Inject(ScheduledTaskFirer)),
242
- __param(10, Inject(DeviceOpResolver)),
243
- __param(11, Inject(ScheduledRuns)),
244
- __param(12, Inject(KERNEL_LOGGER)),
245
- __param(13, Inject(SandboxOperationReconcileJob)),
246
- __param(14, Inject(ShareObjects)),
247
- __param(15, Inject(PlatformIconObjects)),
248
- __param(16, Optional()),
249
- __param(16, Inject(CloudPermissionSnapshots))
233
+ __param(10, Inject(ScheduledRuns)),
234
+ __param(11, Inject(KERNEL_LOGGER)),
235
+ __param(12, Inject(SandboxOperationReconcileJob)),
236
+ __param(13, Inject(ShareObjects)),
237
+ __param(14, Inject(PlatformIconObjects)),
238
+ __param(15, Optional()),
239
+ __param(15, Inject(CloudPermissionSnapshots))
250
240
  ], MaintenanceProcessor);
251
241
  export { MaintenanceProcessor };
252
242
  /**
@@ -1,6 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { isFileSystemGoneError, isSandboxGoneError, MAX_DEVICE_LIST_ENTRIES, parseSkillMd, SKILL_ENTRY_FILE, } from "@capybara-hq/plugin-sdk";
3
- import { POLICY_REFUSAL_PREFIX } from "../../local-devices/relay.js";
2
+ import { isFileSystemGoneError, isProjectPathRefusedError, isSandboxGoneError, MAX_DEVICE_LIST_ENTRIES, parseSkillMd, SKILL_ENTRY_FILE, } from "@capybara-hq/plugin-sdk";
4
3
  import { PROJECT_SKILLS_DIR } from "../../sandbox/kernel-read.js";
5
4
  /** The most of a project's `AGENTS.md` a `project_root` event carries, in UTF-8 bytes (marker included). */
6
5
  export const AGENTS_MD_MAX_BYTES = 64 * 1024;
@@ -46,14 +45,13 @@ export const projectUnavailable = {
46
45
  notEnforceable: (root) => unavailable("unreadable", `The project's root ${clipped(root)} was not read: this device's runtime cannot enforce a read-only read on its host; turn on its sandbox enforcement or use another device.`),
47
46
  /** A device runtime that refused the kernel's read-only read scope (its text is logged). */
48
47
  refused: (root) => unavailable("unreadable", `The project's root ${clipped(root)} was not read: this device's runtime refused the kernel's read-only read.`),
49
- unsupported: () => unavailable("unsupported", "The device does not offer projects; capybara-device on that machine needs an update."),
48
+ unsupported: () => unavailable("unsupported", "The device's provider does not offer projects."),
50
49
  };
51
50
  /** The snapshot of a project the run cannot use: the reason alone, no AGENTS.md, no skills. */
52
51
  export const unavailableProject = (project, root, why) => ({ project, root, unavailable: why, skills: [] });
53
52
  /** A lost instance or file system: passed on, so the sandbox service recovers or records it. */
54
53
  const isGone = (e) => isSandboxGoneError(e) || isFileSystemGoneError(e);
55
54
  const messageOf = (e) => (e instanceof Error ? e.message : String(e));
56
- const isPolicyRefusal = (e) => e instanceof Error && e.message.startsWith(POLICY_REFUSAL_PREFIX);
57
55
  /** The hex sha256 of a file's bytes: a skill's digest. */
58
56
  const digestOf = (data) => createHash("sha256").update(data).digest("hex");
59
57
  /**
@@ -110,7 +108,8 @@ export async function readProjectKnowledge(files, target, opts = {}) {
110
108
  catch (e) {
111
109
  if (r.fatal(e))
112
110
  throw e;
113
- if (isPolicyRefusal(e))
111
+ // the device's provider refusing the project's directory (its reason is not model text)
112
+ if (isProjectPathRefusedError(e))
114
113
  return cannot(projectUnavailable.outsideMode(root, mode));
115
114
  r.log("project root could not be read", { path: root, reason: messageOf(e) });
116
115
  return cannot(projectUnavailable.unreadable(root));
@@ -7,7 +7,8 @@ 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 { DeviceProtocolError, isSandboxPermissionUnsupportedError } from "@capybara-hq/plugin-sdk";
10
+ import { isSandboxPermissionUnsupportedError } from "@capybara-hq/plugin-sdk";
11
+ import { DeviceProtocolError } from "@capybara-hq/plugin-sdk/device-protocol";
11
12
  import { Inject, Injectable, Optional } from "@nestjs/common";
12
13
  import { EventLog } from "../../conversations/event-log.js";
13
14
  import { ConversationDevices } from "../../devices/conversation-devices.js";
@@ -57,7 +57,7 @@ export interface CloudSnapshotProgress {
57
57
  /** Live cloud devices carrying `permission_reconcile_required`. */
58
58
  reconcileRequired: string[];
59
59
  }
60
- /** The live (not deleted) cloud devices of orgs that still exist. */
60
+ /** The live (not deleted) devices of orgs that still exist, whatever their provider. */
61
61
  type DeviceReader = Pick<KernelDb, "selectFrom">;
62
62
  /** Reads the cloud snapshot's progress; no lock, no lease (a report). */
63
63
  export declare function readCloudSnapshotProgress(db: DeviceReader): Promise<CloudSnapshotProgress>;
@@ -31,7 +31,6 @@ const DRIVER_PAGE = 100;
31
31
  const liveCloud = (db) => db
32
32
  .selectFrom("devices as d")
33
33
  .innerJoin("orgs as g", "g.id", "d.org_id")
34
- .where("d.source", "=", "cloud")
35
34
  .where("d.deleted_at", "is", null)
36
35
  .where("g.deleted_at", "is", null);
37
36
  /** Reads the cloud snapshot's progress; no lock, no lease (a report). */
@@ -355,7 +354,6 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
355
354
  const device = await this.db
356
355
  .selectFrom("devices")
357
356
  .select([
358
- "source",
359
357
  "provider",
360
358
  "mode",
361
359
  "owner_full_access",
@@ -368,7 +366,7 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
368
366
  .where("org_id", "=", orgId)
369
367
  .forNoKeyUpdate()
370
368
  .executeTakeFirst();
371
- if (device === undefined || device.deleted_at !== null || device.source !== "cloud")
369
+ if (device === undefined || device.deleted_at !== null)
372
370
  return undefined;
373
371
  return device;
374
372
  }
@@ -1,38 +1,81 @@
1
- import { type DeviceRef, type DeviceReport } from "@capybara-hq/plugin-sdk";
1
+ import { type DeviceRef, type DeviceReport, type SandboxPermissionSupport } from "@capybara-hq/plugin-sdk";
2
2
  import { KernelDb } from "../infra/database/kernel-db.js";
3
3
  import { TransactionHost } from "../infra/database/transaction-host.js";
4
4
  import { LockService } from "../infra/lock/lock.service.js";
5
5
  import type { KernelLogger } from "../log.js";
6
- import type { DeviceProviderEntry } from "./providers.js";
6
+ import { PermissionCeilingWrites } from "./permission-ceiling-writes.js";
7
+ import { type DeviceProviderEntry, DeviceProviders } from "./providers.js";
7
8
  /** How long a provider's `report` may take before the refresh gives up (keeps the stored one). */
8
9
  export declare const DEVICE_REPORT_TIMEOUT_MS = 10000;
9
10
  /** Overrides {@link DEVICE_REPORT_TIMEOUT_MS} (ms; tests only). */
10
11
  export declare const DEVICE_REPORT_TIMEOUT: unique symbol;
12
+ /** The revision of a stored report, or null when none (or not a readable one) is stored. */
13
+ export declare function storedRevision(stored: unknown): string | null;
14
+ /** The permission support stored with a report (its `support` key), or null when none passes. */
15
+ export declare function storedSupport(stored: unknown): SandboxPermissionSupport | null;
11
16
  /**
12
- * The stored device report (`devices.report`, `report_at`; device-provider spec §6.1): what a
13
- * device's provider last told about it (`device-provider@1` `report()`), shown to people and never
14
- * used for enforcement. {@link refresh} asks the provider and stores the answer; request paths
15
- * {@link read} the stored copy from PG and never call the provider.
17
+ * A stored report (`devices.report`) checked again ({@link parseDeviceReport}) without its
18
+ * `support` key; null when none is stored or it no longer passes.
19
+ */
20
+ export declare function storedReport(stored: unknown): DeviceReport | null;
21
+ /**
22
+ * What {@link DeviceReports.changed} did: `bumped` (the revision changed and the device authority
23
+ * epoch moved), `same` (stored again, nothing published), `not-served` (the device is not a live
24
+ * device bound to the calling provider; nothing read or written).
25
+ */
26
+ export type DeviceReportChange = "bumped" | "same" | "not-served";
27
+ /**
28
+ * The stored device report (`devices.report`, `report_at`; device-provider spec §6.1, §6.7): what a
29
+ * device's provider last told about it (`device-provider@1` `report()`, with the instance's
30
+ * `permissionSupport()` read at the last {@link changed} that had an instance, kept under the key
31
+ * `support`). The report's text is shown to people; its revision and the stored support drive
32
+ * the device authority epoch below (what an operation may do is still decided by the authority
33
+ * and the provider's own enforcement, never read from here). {@link refresh} (the kernel, on a create or resume) and {@link changed} (the
34
+ * provider, through `ctx.devices.reportChanged`) ask the provider and store the answer; request
35
+ * paths {@link read} the stored copy from PG and never call the provider.
36
+ *
37
+ * The report's revision drives the provider-neutral device authority epoch (§6.7): a stored
38
+ * revision replaced by another one publishes a device ceiling change in the same transaction
39
+ * (`PermissionCeilingWrites.publishLocked`), so approvals, grants and pending admissions bound to
40
+ * the old epoch are stale. Running work is revoked only for the crossings the new support cannot
41
+ * enforce (outside the sandbox, per-call hosts); Full consent is reset when the outside-sandbox
42
+ * crossing changes either way or per-call hosts become possible. A first report replaces no
43
+ * revision and publishes nothing. No in-process state: every comparison reads PG under the device
44
+ * authority writer lock and the row lock.
16
45
  */
17
46
  export declare class DeviceReports {
18
47
  private readonly db;
19
48
  readonly txHost: TransactionHost;
20
49
  private readonly locks;
21
50
  private readonly log;
51
+ private readonly ceilings;
52
+ private readonly providers;
22
53
  private readonly timeoutMs;
23
- constructor(db: KernelDb, txHost: TransactionHost, locks: Pick<LockService, "lease">, log: Pick<KernelLogger, "warn">, timeoutMs?: number);
54
+ constructor(db: KernelDb, txHost: TransactionHost, locks: Pick<LockService, "lease">, log: Pick<KernelLogger, "warn">, ceilings: Pick<PermissionCeilingWrites, "lock" | "publishLocked">, providers: Pick<DeviceProviders, "forDevice">, timeoutMs?: number);
24
55
  /**
25
56
  * Asks `entry` for the report of `ref`'s device (given up after {@link DEVICE_REPORT_TIMEOUT_MS}
26
- * or on `signal`, even when the provider ignores its signal), checks it ({@link parseDeviceReport}) and stores it with `report_at`, only
27
- * while the device is live and still bound to `entry` (`devices.provider = entry.plugin`).
57
+ * or on `signal`, even when the provider ignores its signal), checks it ({@link parseDeviceReport})
58
+ * and stores it with `report_at`, keeping the permission support stored before (the lifecycle
59
+ * reads the instance's support itself; a refresh adds no provider probe),
60
+ * only while the device is live and still bound to `entry` (`devices.provider = entry.plugin`);
61
+ * a replaced revision publishes the device authority change (see the class).
28
62
  * `changed`: the stored revision differs from the one before (true for a first report). Never
29
- * throws: a failing or invalid answer leaves the stored report as it was and is logged at most
63
+ * throws: a failing or invalid report leaves the stored one as it was and is logged at most
30
64
  * once per device per hour; an abort of `signal` is not logged. Call it outside any transaction
31
- * (the provider call must not hold one open).
65
+ * (the provider calls must not hold one open).
32
66
  */
33
67
  refresh(entry: DeviceProviderEntry, ref: DeviceRef, signal: AbortSignal): Promise<{
34
68
  changed: boolean;
35
69
  }>;
70
+ /**
71
+ * `ctx.devices.reportChanged(deviceId)` of the extension `plugin`: `not-served` unless the
72
+ * device is live and bound to `plugin` (the caller refuses it); otherwise reads the device's
73
+ * report and permission support from `plugin` (its current instance's handle, if any) outside
74
+ * any transaction and stores them as {@link refresh} does. Throws when the report cannot be read
75
+ * or does not pass, so the provider may tell again; a failed support read stores no support
76
+ * (no crossing enforceable: revocation fails closed).
77
+ */
78
+ changed(plugin: string, deviceId: string, signal?: AbortSignal): Promise<DeviceReportChange>;
36
79
  /**
37
80
  * The stored report of a live device of `orgId`, checked again ({@link parseDeviceReport});
38
81
  * null when none is stored, the stored one no longer passes, or there is no such device.
@@ -40,9 +83,26 @@ export declare class DeviceReports {
40
83
  */
41
84
  read(orgId: string, deviceId: string): Promise<DeviceReport | null>;
42
85
  /**
43
- * Writes `report` on the device if it is live and bound to `plugin`; whether its revision
44
- * differs from the stored one. The row is locked first, so two refreshes of one device compare
45
- * against each other's writes, never against the same old value.
86
+ * The stored revision of a live device and the permission support stored with it (null when
87
+ * none was read); null when no report is stored. Reads PG only.
88
+ */
89
+ current(deviceId: string): Promise<{
90
+ revision: string;
91
+ support: SandboxPermissionSupport | null;
92
+ } | null>;
93
+ /**
94
+ * The provider's report (checked; throws when it fails or does not pass) and, with
95
+ * `withSupport`, the instance's permission support (null when the provider has none or the read
96
+ * fails or does not pass; absent without `withSupport` or without an instance: the stored one
97
+ * is kept), each bounded and raced so a provider ignoring the signal holds nothing.
98
+ */
99
+ private ask;
100
+ /**
101
+ * Writes the answer on the device if it is live and bound to `plugin`, under the row lock and
102
+ * then the device authority writer lock, so two stores of one device compare against each
103
+ * other's writes, never against the same old value.
104
+ * `changed`: the revision differs from the stored one; `published`: a stored revision was
105
+ * replaced, so the device authority change was published in this transaction.
46
106
  */
47
107
  private store;
48
108
  /** Logs a refresh failure, at most once per device per hour (a Redis key with a TTL). */