@capybara-hq/kernel 0.1.0-rc.121 → 0.1.0-rc.122

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 (229) hide show
  1. package/dist/background/finish.d.ts +5 -1
  2. package/dist/background/finish.js +29 -18
  3. package/dist/background/launch.d.ts +0 -5
  4. package/dist/background/launch.js +1 -6
  5. package/dist/background/managed.js +1 -4
  6. package/dist/background/poll.job.d.ts +3 -25
  7. package/dist/background/poll.job.js +20 -112
  8. package/dist/background/render.d.ts +2 -8
  9. package/dist/background/render.js +3 -17
  10. package/dist/background/stop.d.ts +15 -16
  11. package/dist/background/stop.js +39 -76
  12. package/dist/background/store.d.ts +17 -45
  13. package/dist/background/store.js +60 -94
  14. package/dist/background/tasks.service.d.ts +2 -5
  15. package/dist/background/tasks.service.js +9 -20
  16. package/dist/background/wake.js +3 -2
  17. package/dist/catalog/admin-catalog.controller.d.ts +2 -18
  18. package/dist/catalog/admin-catalog.controller.js +2 -28
  19. package/dist/catalog/catalog-content.d.ts +1 -5
  20. package/dist/catalog/catalog-items.d.ts +2 -6
  21. package/dist/catalog/catalog-items.js +5 -26
  22. package/dist/catalog/catalog-scope.service.d.ts +1 -121
  23. package/dist/catalog/catalog-scope.service.js +12 -552
  24. package/dist/catalog/catalog.service.d.ts +4 -15
  25. package/dist/catalog/catalog.service.js +7 -35
  26. package/dist/catalog/job-ids.d.ts +0 -18
  27. package/dist/catalog/job-ids.js +0 -20
  28. package/dist/catalog/marketplaces.service.d.ts +1 -1
  29. package/dist/catalog/org-catalog.service.js +6 -20
  30. package/dist/catalog/org-plugin-uploads.controller.d.ts +4 -19
  31. package/dist/catalog/org-plugin-uploads.controller.js +6 -34
  32. package/dist/catalog/org-plugin-uploads.d.ts +3 -10
  33. package/dist/catalog/org-plugin-uploads.js +4 -18
  34. package/dist/catalog/org-plugin-uploads.schemas.js +0 -1
  35. package/dist/catalog/owned-items.d.ts +6 -11
  36. package/dist/catalog/owned-items.js +10 -20
  37. package/dist/catalog/ownership.d.ts +3 -29
  38. package/dist/catalog/ownership.js +4 -54
  39. package/dist/catalog/platform-components.d.ts +5 -11
  40. package/dist/catalog/platform-components.js +8 -15
  41. package/dist/catalog/plugin-import.d.ts +3 -42
  42. package/dist/catalog/plugin-import.js +26 -195
  43. package/dist/catalog/plugin-install.js +1 -6
  44. package/dist/catalog/plugin-package.d.ts +1 -0
  45. package/dist/catalog/plugin-package.js +5 -0
  46. package/dist/catalog/plugin-upgrade.d.ts +3 -26
  47. package/dist/catalog/plugin-upgrade.js +20 -103
  48. package/dist/catalog/request-rules.js +4 -6
  49. package/dist/catalog/scope-sync.js +2 -4
  50. package/dist/catalog/scope.d.ts +2 -5
  51. package/dist/channels/jobs.d.ts +3 -3
  52. package/dist/channels/jobs.js +4 -3
  53. package/dist/channels/outbound.d.ts +1 -0
  54. package/dist/channels/outbound.js +32 -8
  55. package/dist/config/load.d.ts +0 -25
  56. package/dist/config/load.js +0 -57
  57. package/dist/config/schema.js +2 -3
  58. package/dist/conversations/attachments.service.js +3 -5
  59. package/dist/conversations/conversations.service.d.ts +3 -3
  60. package/dist/conversations/conversations.service.js +3 -3
  61. package/dist/conversations/job-org.d.ts +3 -0
  62. package/dist/conversations/job-org.js +11 -0
  63. package/dist/conversations/prompt-suggestions.d.ts +2 -7
  64. package/dist/conversations/prompt-suggestions.js +29 -27
  65. package/dist/conversations/titles.d.ts +3 -4
  66. package/dist/conversations/titles.js +19 -30
  67. package/dist/db/kernel-schema.d.ts +6 -16
  68. package/dist/db/pool.js +7 -2
  69. package/dist/devices/devices.controller.d.ts +0 -5
  70. package/dist/devices/devices.controller.js +2 -20
  71. package/dist/devices/devices.service.d.ts +1 -17
  72. package/dist/devices/devices.service.js +0 -22
  73. package/dist/errors.d.ts +1 -5
  74. package/dist/errors.js +1 -5
  75. package/dist/evals/judge.d.ts +3 -0
  76. package/dist/evals/judge.js +1 -1
  77. package/dist/evals/run-replay.d.ts +1 -1
  78. package/dist/evals/run-replay.js +26 -29
  79. package/dist/evals/step-replay.d.ts +3 -1
  80. package/dist/evals/step-replay.js +10 -1
  81. package/dist/evals/worker.d.ts +3 -1
  82. package/dist/evals/worker.js +53 -21
  83. package/dist/extensions/deployment-config-store.js +18 -14
  84. package/dist/extensions/effective-config.d.ts +1 -5
  85. package/dist/extensions/effective-config.js +1 -5
  86. package/dist/extensions/hooks.d.ts +3 -1
  87. package/dist/extensions/hooks.js +7 -2
  88. package/dist/extensions/installs.d.ts +2 -14
  89. package/dist/extensions/installs.js +10 -32
  90. package/dist/extensions/org-config.d.ts +3 -4
  91. package/dist/extensions/org-config.js +3 -4
  92. package/dist/extensions/plugin-guides.d.ts +0 -1
  93. package/dist/extensions/plugin-guides.js +0 -1
  94. package/dist/extensions/plugin-icons.d.ts +0 -1
  95. package/dist/extensions/plugin-icons.js +0 -3
  96. package/dist/files/blob-sweep.job.d.ts +2 -11
  97. package/dist/files/blob-sweep.job.js +7 -21
  98. package/dist/files/hash-job.d.ts +5 -15
  99. package/dist/files/hash-job.js +14 -33
  100. package/dist/files/library-jobs.module.d.ts +1 -6
  101. package/dist/files/library-jobs.module.js +3 -9
  102. package/dist/identity/api-tokens.js +54 -40
  103. package/dist/identity/auth.guard.js +2 -2
  104. package/dist/identity/sessions.js +7 -3
  105. package/dist/identity/settings.js +5 -21
  106. package/dist/inbox/inbox.service.d.ts +2 -3
  107. package/dist/inbox/org-notices.d.ts +0 -14
  108. package/dist/inbox/platform-inbox.service.d.ts +1 -8
  109. package/dist/inbox/platform-inbox.service.js +2 -6
  110. package/dist/inbox/platform-notices.d.ts +3 -3
  111. package/dist/index.d.ts +0 -4
  112. package/dist/index.js +0 -3
  113. package/dist/infra/database/database.module.js +2 -1
  114. package/dist/infra/database/org-scope.d.ts +5 -3
  115. package/dist/infra/database/org-scope.js +7 -1
  116. package/dist/infra/database/scoped-dialect.d.ts +3 -1
  117. package/dist/infra/database/scoped-dialect.js +17 -5
  118. package/dist/infra/events/kernel-events.d.ts +2 -0
  119. package/dist/infra/outbox/outbox.service.d.ts +2 -0
  120. package/dist/infra/outbox/outbox.service.js +10 -0
  121. package/dist/infra/outbox/registry.d.ts +0 -41
  122. package/dist/infra/outbox/registry.js +0 -37
  123. package/dist/models/embeddings.d.ts +0 -5
  124. package/dist/models/embeddings.js +28 -35
  125. package/dist/models/images.d.ts +3 -8
  126. package/dist/models/images.js +19 -37
  127. package/dist/models/purposes.d.ts +7 -2
  128. package/dist/models/purposes.js +16 -3
  129. package/dist/orgs/device-network-setting.d.ts +0 -44
  130. package/dist/orgs/device-network-setting.js +0 -83
  131. package/dist/orgs/invitations.service.js +34 -30
  132. package/dist/orgs/offboarding.d.ts +2 -2
  133. package/dist/orgs/offboarding.js +2 -2
  134. package/dist/orgs/orgs.service.d.ts +1 -1
  135. package/dist/orgs/orgs.service.js +19 -15
  136. package/dist/orgs/settings.service.d.ts +19 -14
  137. package/dist/orgs/settings.service.js +12 -37
  138. package/dist/platform/exclusions.js +0 -11
  139. package/dist/platform/ops/catalog-admin.ops.js +0 -8
  140. package/dist/platform/ops/devices.ops.js +0 -28
  141. package/dist/platform/ops/extensions-admin.ops.js +3 -3
  142. package/dist/platform/ops/inbox.ops.js +5 -22
  143. package/dist/platform/ops/org-plugins.ops.d.ts +1 -3
  144. package/dist/platform/ops/org-plugins.ops.js +11 -67
  145. package/dist/roles/worker.module.js +0 -9
  146. package/dist/runtime/hook-calls.d.ts +13 -6
  147. package/dist/runtime/hook-calls.js +26 -4
  148. package/dist/runtime/maintenance.d.ts +3 -12
  149. package/dist/runtime/maintenance.js +25 -55
  150. package/dist/runtime/model-call.d.ts +4 -2
  151. package/dist/runtime/model-call.js +59 -58
  152. package/dist/runtime/providers.d.ts +27 -1
  153. package/dist/runtime/providers.js +57 -0
  154. package/dist/runtime/run-jobs.d.ts +1 -1
  155. package/dist/runtime/run-processors.d.ts +3 -9
  156. package/dist/runtime/run-worker.d.ts +2 -0
  157. package/dist/runtime/run-worker.js +23 -8
  158. package/dist/runtime/subagents/deliveries.js +6 -1
  159. package/dist/runtime/subagents/dispatch.d.ts +3 -3
  160. package/dist/runtime/write-base.service.d.ts +2 -3
  161. package/dist/runtime/write-base.service.js +3 -5
  162. package/dist/sandbox/device-sandbox-settings.d.ts +38 -92
  163. package/dist/sandbox/device-sandbox-settings.js +19 -325
  164. package/dist/sandbox/jobs.d.ts +3 -14
  165. package/dist/sandbox/jobs.js +2 -20
  166. package/dist/sandbox/modes.d.ts +5 -45
  167. package/dist/sandbox/modes.js +3 -60
  168. package/dist/sandbox/operation-authority.js +0 -11
  169. package/dist/sandbox/operation-intents.d.ts +32 -9
  170. package/dist/sandbox/operation-intents.js +241 -32
  171. package/dist/sandbox/operation-intents.module.js +2 -1
  172. package/dist/sandbox/operation-reconcile.job.d.ts +9 -11
  173. package/dist/sandbox/operation-reconcile.job.js +119 -33
  174. package/dist/sandbox/operation-revoke.d.ts +20 -0
  175. package/dist/sandbox/operation-revoke.js +3 -0
  176. package/dist/sandbox/permission-ceiling-writes.d.ts +1 -2
  177. package/dist/sandbox/permission-ceiling-writes.js +3 -6
  178. package/dist/sandbox/permission-config-publication.d.ts +1 -28
  179. package/dist/sandbox/permission-config-publication.js +14 -211
  180. package/dist/sandbox/permission-facts.d.ts +4 -15
  181. package/dist/sandbox/permission-facts.js +7 -29
  182. package/dist/sandbox/permission-instance-writes.d.ts +1 -4
  183. package/dist/sandbox/permission-instance-writes.js +1 -55
  184. package/dist/sandbox/providers.d.ts +1 -6
  185. package/dist/sandbox/providers.js +1 -15
  186. package/dist/sandbox/review/classifier.js +12 -13
  187. package/dist/sandbox/sandbox.module.js +3 -6
  188. package/dist/sandbox/sandbox.service.d.ts +17 -123
  189. package/dist/sandbox/sandbox.service.js +239 -998
  190. package/dist/shares/liveness.d.ts +1 -2
  191. package/dist/shares/liveness.js +1 -2
  192. package/dist/shares/shares.module.d.ts +1 -2
  193. package/dist/shares/shares.module.js +2 -5
  194. package/dist/shares/shares.service.js +1 -2
  195. package/dist/tools/builtins/image/generate.js +7 -15
  196. package/dist/tools/builtins/sandbox/common.d.ts +0 -2
  197. package/dist/tools/builtins/sandbox/common.js +1 -27
  198. package/dist/tools/builtins/sandbox/task-list.js +10 -10
  199. package/dist/tools/builtins/sandbox/task-output.d.ts +3 -10
  200. package/dist/tools/builtins/sandbox/task-output.js +13 -83
  201. package/dist/tools/builtins/sandbox/task-stop.js +18 -22
  202. package/dist/tools/builtins/vision/read-image.js +9 -10
  203. package/dist/tools/builtins/web/extract.js +9 -10
  204. package/package.json +3 -3
  205. package/src/migrations/0206_retire_org_extension_uploads.sql +125 -0
  206. package/src/migrations/0207_confirm_device_instance_destruction.sql +25 -0
  207. package/src/migrations/0208_convert_stored_permission_settings.sql +189 -0
  208. package/dist/background/retire-legacy-tasks.job.d.ts +0 -57
  209. package/dist/background/retire-legacy-tasks.job.js +0 -149
  210. package/dist/catalog/owned-plugin-cleanup.d.ts +0 -47
  211. package/dist/catalog/owned-plugin-cleanup.js +0 -140
  212. package/dist/config/permission-migration.d.ts +0 -34
  213. package/dist/config/permission-migration.js +0 -115
  214. package/dist/devices/legacy-cleanup.job.d.ts +0 -34
  215. package/dist/devices/legacy-cleanup.job.js +0 -147
  216. package/dist/files/library-backfill.d.ts +0 -63
  217. package/dist/files/library-backfill.js +0 -143
  218. package/dist/infra/cli/permission-cutover.d.ts +0 -59
  219. package/dist/infra/cli/permission-cutover.js +0 -107
  220. package/dist/sandbox/cloud-permission-snapshot.d.ts +0 -159
  221. package/dist/sandbox/cloud-permission-snapshot.js +0 -430
  222. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +0 -8
  223. package/dist/sandbox/cloud-permission-snapshot.module.js +0 -34
  224. package/dist/sandbox/legacy-retirement.d.ts +0 -284
  225. package/dist/sandbox/legacy-retirement.js +0 -1165
  226. package/dist/sandbox/legacy-retirement.module.d.ts +0 -8
  227. package/dist/sandbox/legacy-retirement.module.js +0 -25
  228. package/dist/shares/share-objects.d.ts +0 -47
  229. package/dist/shares/share-objects.js +0 -93
@@ -16,11 +16,6 @@ import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
16
16
  import { SandboxService } from "./sandbox.service.js";
17
17
  /** The idle suspension sweep (every minute, once per tick across replicas). */
18
18
  export const SANDBOX_SUSPEND_JOB = "sandbox-suspend-idle";
19
- /**
20
- * The lifecycle reconcile of cloud devices carrying the reconcile marker through their provider's
21
- * `update` (permission activation B-12; every minute, once per tick across replicas).
22
- */
23
- export const SANDBOX_RECONCILE_JOB = "sandbox-reconcile-limits";
24
19
  /** The inactivity destruction sweep (hourly, once per tick across replicas). */
25
20
  export const SANDBOX_DESTROY_JOB = "sandbox-destroy-inactive";
26
21
  /**
@@ -90,14 +85,11 @@ export { SandboxJobs };
90
85
  * The worker side of {@link SANDBOX_RESET_FILES_JOB}: `resetFileSystem` under the exclusive lease;
91
86
  * a failure fails the job (retried).
92
87
  */
93
- export async function runSandboxResetFiles(sandbox, job,
94
- /** B1: a reset establishes the device's exact limits; clears its reconciliation marker. */
95
- snapshots) {
88
+ export async function runSandboxResetFiles(sandbox, job) {
96
89
  const id = job.data.deviceId;
97
90
  if (typeof id !== "string")
98
91
  return;
99
92
  await sandbox.resetFileSystem(id);
100
- await snapshots?.reconcileDevice(id);
101
93
  }
102
94
  /**
103
95
  * The worker side of {@link SANDBOX_DESTROY_FOR_JOB}: `destroyDevice` one by one; a failure is
@@ -125,9 +117,7 @@ export async function runSandboxDestroyFor(sandbox, log, job) {
125
117
  /**
126
118
  * The sandbox sweeps (exactly once per tick across replicas): every minute the idle and overdue
127
119
  * running instances are suspended, every hour the inactive instances are destroyed (files kept)
128
- * and deleted devices, or those of deleted orgs, are destroyed with their files. Every minute,
129
- * too, cloud devices whose limits must be established again get them through their provider's
130
- * `update` when it has one (B-12). All do nothing without a sandbox provider. They replace the
120
+ * and deleted devices, or those of deleted orgs, are destroyed with their files. They replace the
131
121
  * maintenance schedulers `sandbox-suspend-idle-every-minute` and `sandbox-destroy-inactive-hourly`
132
122
  * (retired at worker start).
133
123
  */
@@ -145,11 +135,6 @@ let SandboxSweepJobs = class SandboxSweepJobs {
145
135
  if (n > 0)
146
136
  this.log.info("idle sandboxes suspended", { count: n });
147
137
  }
148
- async reconcileLimits() {
149
- const n = await this.sandbox.reconcileMarked();
150
- if (n > 0)
151
- this.log.info("cloud device limits reconciled", { count: n });
152
- }
153
138
  async destroyInactive() {
154
139
  const n = await this.sandbox.destroyInactive(new Date());
155
140
  if (n > 0)
@@ -159,9 +144,6 @@ let SandboxSweepJobs = class SandboxSweepJobs {
159
144
  __decorate([
160
145
  LockedCron("* * * * *", { name: SANDBOX_SUSPEND_JOB })
161
146
  ], SandboxSweepJobs.prototype, "suspendIdle", null);
162
- __decorate([
163
- LockedCron("* * * * *", { name: SANDBOX_RECONCILE_JOB })
164
- ], SandboxSweepJobs.prototype, "reconcileLimits", null);
165
147
  __decorate([
166
148
  LockedCron("0 * * * *", { name: SANDBOX_DESTROY_JOB })
167
149
  ], SandboxSweepJobs.prototype, "destroyInactive", null);
@@ -7,8 +7,8 @@ import { type OutsideSandboxPermission as FullAccessPermission } from "./device-
7
7
  /**
8
8
  * Device modes (auto mode spec §4.1–§4.3): who may choose auto mode, and the network each mode
9
9
  * gets. One pure function, {@link effectiveDevicePolicy}, combines the platform's switch
10
- * (`devices.outsideSandbox`), the org's (`outsideSandbox`, `deviceNetwork`) and the device's owner
11
- * ceiling (its B1 snapshot; null follows the platform and the org).
10
+ * (`devices.outsideSandbox`), the org's (`outsideSandbox`, `deviceNetwork`) and the device's
11
+ * mode. A device with no chosen mode follows the platform and the org.
12
12
  * It is a ceiling only: no device-chosen default mode selects how an operation runs (permission
13
13
  * runtime cutover 8.6); the conversation's permission profile does, within this ceiling.
14
14
  */
@@ -87,49 +87,10 @@ export declare function orgAllowedDomains(deployment: DeploymentDevicePolicy, or
87
87
  * (the platform kill switch, R20).
88
88
  */
89
89
  export declare function deviceNetwork(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings, mode: SandboxMode): DeviceNetwork;
90
- /**
91
- * The effective device policy. `deviceMode` is the device's owner ceiling (its B1 snapshot or
92
- * narrowing switch; null = follow the platform and the org). A stored mode the platform or org forbids is cut, never honoured; the network follows the
93
- * resulting mode.
94
- */
95
- export declare function effectiveDevicePolicy(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings, deviceMode: SandboxMode | null,
96
- /** A cloud device's B1 outer network snapshot: the network never goes beyond it. */
97
- outer?: DeviceNetwork | null): EffectiveDevicePolicy;
90
+ /** Resolve the device's chosen mode under the platform and org ceilings, then its network. */
91
+ export declare function effectiveDevicePolicy(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings, deviceMode: SandboxMode | null): EffectiveDevicePolicy;
98
92
  /** A network with its hosts lowercased, sorted and deduplicated (`open-public` carries none). */
99
93
  export declare const normalizeNetwork: (n: DeviceNetwork) => DeviceNetwork;
100
- /**
101
- * The narrower of two networks (B1): the open public network is no limit; two allowlists keep the
102
- * hosts (or wildcards) of each that the other covers. Never wider than either.
103
- */
104
- export declare function intersectNetworks(a: DeviceNetwork, b: DeviceNetwork): DeviceNetwork;
105
- /**
106
- * Whether `a` and `b` are the same mode, network kind and host set (null is never the same): the
107
- * one-time B1 reconciliation's exactness (`CloudPermissionSnapshots`), which still binds a migrated
108
- * instance to the exact limits it recorded. A running instance's change ignores the mode
109
- * ({@link AppliedLimits}).
110
- */
111
- export declare const sameAppliedExactly: (a: AppliedLimits | null | undefined, b: AppliedLimits) => boolean;
112
- /** A cloud device's B1 per-device authority: its owner Full ceiling and its outer network. */
113
- export interface CloudOwnerSnapshot {
114
- fullAccess: boolean;
115
- outerNetwork: DeviceNetwork;
116
- }
117
- /**
118
- * The B1 snapshot of a cloud device from its old effective policy (computed by the old algorithm,
119
- * `egress: none` included): Full where the old mode was auto, the old effective network as the
120
- * outer boundary. Known applied limits narrow it by intersection, never widen it: an instance that
121
- * really ran stricter keeps that boundary (`applied` null: unknown, nothing to intersect).
122
- */
123
- export declare function cloudSnapshotOf(old: Pick<EffectiveDevicePolicy, "mode" | "network">, applied?: AppliedLimits | null): CloudOwnerSnapshot;
124
- /**
125
- * The mode a cloud device chose: the narrower of its old narrowing switch and its B1 owner
126
- * ceiling (false narrows to sandbox, true or not snapshotted follows the platform and the org). An
127
- * explicit sandbox switch (an old replica's write included) is never overridden.
128
- */
129
- export declare const cloudChosenMode: (row: {
130
- mode: "sandbox" | null;
131
- owner_full_access: boolean | null;
132
- }) => SandboxMode | null;
133
94
  /**
134
95
  * The limits the kernel wants for a device: what lifecycle create and update carry
135
96
  * ({@link SandboxLimits}: resources and the outer network) plus the mode the kernel records with a
@@ -148,8 +109,7 @@ export declare function providerLimits(limits: DeviceLimits): SandboxLimits;
148
109
  * a desired host the instance's list does not cover ({@link appliedLacksHost}, a host added to the
149
110
  * device's or the org's list, applied per the provider's `limitsApplyAt`: at the next use, or
150
111
  * after a file reset). Resources reach instances created afterwards. `mode` is recorded but never
151
- * decides a change ({@link sameApplied}, {@link appliedWider}; only the one-time B1 reconciliation
152
- * compares it, {@link sameAppliedExactly}):
112
+ * decides a change ({@link sameApplied}, {@link appliedWider}):
153
113
  * a cloud device has no outside of its sandbox and the mode never reaches a provider
154
114
  * ({@link providerLimits}), so a mode that follows the platform's or org's outside-sandbox setting
155
115
  * must not update every cloud instance when that setting is toggled (Docker would recreate it
@@ -69,77 +69,20 @@ export function deviceNetwork(deployment, org, mode) {
69
69
  }
70
70
  return { kind: "allowlist", hosts: orgAllowedDomains(deployment, org) };
71
71
  }
72
- /**
73
- * The effective device policy. `deviceMode` is the device's owner ceiling (its B1 snapshot or
74
- * narrowing switch; null = follow the platform and the org). A stored mode the platform or org forbids is cut, never honoured; the network follows the
75
- * resulting mode.
76
- */
77
- export function effectiveDevicePolicy(deployment, org, deviceMode,
78
- /** A cloud device's B1 outer network snapshot: the network never goes beyond it. */
79
- outer = null) {
72
+ /** Resolve the device's chosen mode under the platform and org ceilings, then its network. */
73
+ export function effectiveDevicePolicy(deployment, org, deviceMode) {
80
74
  const allowedMode = allowedDeviceMode(deployment.fullAccess, org.outsideSandbox);
81
75
  const mode = allowedMode === "sandbox" ? "sandbox" : (deviceMode ?? "auto");
82
76
  return {
83
77
  mode,
84
78
  allowedMode,
85
- network: outer === null
86
- ? deviceNetwork(deployment, org, mode)
87
- : intersectNetworks(deviceNetwork(deployment, org, mode), outer),
79
+ network: deviceNetwork(deployment, org, mode),
88
80
  };
89
81
  }
90
82
  /** A network with its hosts lowercased, sorted and deduplicated (`open-public` carries none). */
91
83
  export const normalizeNetwork = (n) => n.kind === "open-public"
92
84
  ? { kind: "open-public", hosts: [] }
93
85
  : { kind: "allowlist", hosts: [...new Set(n.hosts.map((h) => h.toLowerCase()))].sort() };
94
- /**
95
- * The narrower of two networks (B1): the open public network is no limit; two allowlists keep the
96
- * hosts (or wildcards) of each that the other covers. Never wider than either.
97
- */
98
- export function intersectNetworks(a, b) {
99
- if (a.kind === "open-public")
100
- return normalizeNetwork(b);
101
- if (b.kind === "open-public")
102
- return normalizeNetwork(a);
103
- const x = normalizeNetwork(a).hosts;
104
- const y = normalizeNetwork(b).hosts;
105
- return normalizeNetwork({
106
- kind: "allowlist",
107
- hosts: [
108
- ...x.filter((h) => y.some((p) => coversHost(p, h))),
109
- ...y.filter((h) => x.some((p) => coversHost(p, h))),
110
- ],
111
- });
112
- }
113
- /**
114
- * Whether `a` and `b` are the same mode, network kind and host set (null is never the same): the
115
- * one-time B1 reconciliation's exactness (`CloudPermissionSnapshots`), which still binds a migrated
116
- * instance to the exact limits it recorded. A running instance's change ignores the mode
117
- * ({@link AppliedLimits}).
118
- */
119
- export const sameAppliedExactly = (a, b) => a != null &&
120
- a.mode === b.mode &&
121
- JSON.stringify(normalizeNetwork(a.network)) === JSON.stringify(normalizeNetwork(b.network));
122
- /**
123
- * The B1 snapshot of a cloud device from its old effective policy (computed by the old algorithm,
124
- * `egress: none` included): Full where the old mode was auto, the old effective network as the
125
- * outer boundary. Known applied limits narrow it by intersection, never widen it: an instance that
126
- * really ran stricter keeps that boundary (`applied` null: unknown, nothing to intersect).
127
- */
128
- export function cloudSnapshotOf(old, applied = null) {
129
- const fullAccess = old.mode === "auto" && (applied === null || applied.mode === "auto");
130
- return {
131
- fullAccess,
132
- outerNetwork: applied === null
133
- ? normalizeNetwork(old.network)
134
- : intersectNetworks(old.network, applied.network),
135
- };
136
- }
137
- /**
138
- * The mode a cloud device chose: the narrower of its old narrowing switch and its B1 owner
139
- * ceiling (false narrows to sandbox, true or not snapshotted follows the platform and the org). An
140
- * explicit sandbox switch (an old replica's write included) is never overridden.
141
- */
142
- export const cloudChosenMode = (row) => row.mode === "sandbox" || row.owner_full_access === false ? "sandbox" : null;
143
86
  /** What a provider's create and update get of {@link DeviceLimits}: resources and the network. */
144
87
  export function providerLimits(limits) {
145
88
  const { mode: _kernelOnly, ...rest } = limits;
@@ -156,7 +156,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
156
156
  signal.throwIfAborted();
157
157
  await this.locks.acquire({ orgId: ctx.orgId, deviceId: ctx.deviceId }, { kind: "admit" });
158
158
  await this.publication.assertCurrent();
159
- await this.facts.assertCloudReconciled(ctx.orgId, ctx.deviceId);
160
159
  if (!(await this.isActiveMember(ctx.orgId, ctx.accountId)))
161
160
  throw new ApiError("device.not_found", "Device not found");
162
161
  await this.facts.preview(ctx.orgId, ctx.accountId, ctx.deviceId);
@@ -466,7 +465,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
466
465
  if (!(await this.isActiveMember(ctx.orgId, ctx.actor.accountId)))
467
466
  throw new ApiError("forbidden", "This run's actor is no longer authorized");
468
467
  await this.publication.assertCurrent();
469
- await this.facts.assertCloudReconciled(ctx.orgId, ctx.deviceId);
470
468
  const root = await this.profiles.readOwnedRoot(ctx.orgId, ctx.holderConversationId, ctx.actor.accountId);
471
469
  const view = await this.facts.view(ctx.orgId, ctx.actor.accountId, root);
472
470
  if (view.deviceId !== ctx.deviceId)
@@ -825,15 +823,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
825
823
  : availability.reason);
826
824
  if (availability.state !== "supported")
827
825
  return without(availability.state, availability.reason);
828
- // states admission refuses before any operation: the device is not verified for new work
829
- try {
830
- await this.facts.assertCloudReconciled(input.orgId, deviceId);
831
- }
832
- catch (error) {
833
- if (!(error instanceof ApiError))
834
- throw error;
835
- return without("unprobed", error.message);
836
- }
837
826
  let base;
838
827
  try {
839
828
  await this.facts.preview(input.orgId, input.accountId, deviceId, root.project_name ?? undefined);
@@ -1,5 +1,6 @@
1
1
  import { type SandboxExecutionRef, type ToolErrorKind } from "@capybara-hq/plugin-sdk";
2
2
  import type { Selectable } from "kysely";
3
+ import { EventLog } from "../conversations/event-log.js";
3
4
  import type { SandboxOperationIntentsTable } from "../db/kernel-schema.js";
4
5
  import { KernelDb } from "../infra/database/kernel-db.js";
5
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
@@ -9,13 +10,14 @@ import type { KernelReadInvocation, KernelReadMethod } from "./kernel-read.js";
9
10
  import type { SandboxAuthorityOperation } from "./operation-authority.js";
10
11
  import { SandboxOperationAuthority } from "./operation-authority.js";
11
12
  import { OperationPayloads } from "./operation-payloads.js";
13
+ import { type ResumeStopProof } from "./operation-revoke.js";
12
14
  import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
13
15
  import { PermissionAuthorityLock } from "./permission-authority-lock.js";
14
16
  import type { SandboxUseContext } from "./use-context.js";
15
17
  export declare class PermissionAdmissionStale extends Error {
16
18
  }
17
19
  export declare const OPERATION_RECONCILE = "sandbox-operation-reconcile";
18
- export declare const OPERATION_REVOKE = "sandbox-operation-revoke";
20
+ export { OPERATION_REVOKE } from "./operation-revoke.js";
19
21
  /**
20
22
  * The owed revocation of one crashed holder's intents (`revokeHolders`), written before its holder
21
23
  * record is forgotten, under the job id `sandbox-holder-revoke-<deviceId>-<token>`.
@@ -33,6 +35,12 @@ export interface RevokedIncarnation {
33
35
  generation: string;
34
36
  }
35
37
  export type OperationIntent = Selectable<SandboxOperationIntentsTable>;
38
+ type RevocationRetry = {
39
+ row: OperationIntent;
40
+ exhausted: () => Promise<void>;
41
+ } | {
42
+ retry: number;
43
+ };
36
44
  /** Supplied only by the executing tool worker, never tool/model arguments. */
37
45
  export interface OperationInvocation {
38
46
  claim: ExecutionClaim;
@@ -93,7 +101,8 @@ export declare class SandboxOperationIntents {
93
101
  private readonly authority;
94
102
  private readonly outbox;
95
103
  private readonly payloads;
96
- constructor(db: KernelDb, txHost: TransactionHost, locks: PermissionAuthorityLock, epochs: PermissionAuthorityEpochStore, authority: SandboxOperationAuthority, outbox: OutboxService, payloads: OperationPayloads);
104
+ private readonly events;
105
+ constructor(db: KernelDb, txHost: TransactionHost, locks: PermissionAuthorityLock, epochs: PermissionAuthorityEpochStore, authority: SandboxOperationAuthority, outbox: OutboxService, payloads: OperationPayloads, events: Pick<EventLog, "publishChanged">);
97
106
  /** Current run claim plus its actual tool_call_started row authorize an internal invocation identity. */
98
107
  private assertClaim;
99
108
  pending(ctx: SandboxUseContext, invocation: OperationInvocation, instance: OperationInstance, method: SandboxAuthorityOperation, input: unknown, holderTag: string, signal: AbortSignal): Promise<OperationIntent>;
@@ -243,6 +252,8 @@ export declare class SandboxOperationIntents {
243
252
  revokeIncarnation(deviceId: string, instance: RevokedIncarnation): Promise<void>;
244
253
  /** Revokes the device's intents `where` selects and owes each its exact revoke job. */
245
254
  private revokeMatching;
255
+ /** Confirmed destruction wakes exact revokes even after a device deletion stopped their retries. */
256
+ recordDestruction(orgId: string, deviceId: string, instance: RevokedIncarnation): Promise<void>;
246
257
  /**
247
258
  * The revoked, unacknowledged operation revokes owed on one instance generation (oldest first,
248
259
  * at most `limit`), which a lifecycle holder delivers before anything else runs there. A
@@ -251,15 +262,27 @@ export declare class SandboxOperationIntents {
251
262
  owedRevocations(deviceId: string, instance: RevokedIncarnation, limit: number): Promise<{
252
263
  operationId: string;
253
264
  deadline: Date;
265
+ method: OperationIntent["method"];
254
266
  }[]>;
267
+ /** A person's or tool's stop can outlive the replica which first tried it. */
268
+ adoptOwedStop(row: OperationIntent): Promise<boolean>;
269
+ /** Hand authoritative pre-resume evidence to the worker before admitting new work. */
270
+ recordResumeProof(orgId: string, operationId: string, proof: ResumeStopProof, repair?: number): Promise<void>;
271
+ /** The intent lock orders proof settlement with exhaustion, late ref attachment, and stops. */
272
+ applyResumeProof(orgId: string, operationId: string, proof: ResumeStopProof, settle: () => Promise<void>): Promise<void>;
255
273
  /**
256
274
  * A disconnected or still-pending revoke remains owed; every retry is a new deterministic
257
- * persisted attempt, backing off (30 s doubling, at most an hour) so an obligation that only
258
- * retirement can resolve (a lost or replaced instance) never spins. Retries stop once the
259
- * device or its org is deleted: nothing can reach its instance any more, the revoke stays
260
- * unacknowledged (no cleanup is claimed) and the retirement settles it from the device's
261
- * recorded destruction, if any.
275
+ * persisted attempt, backing off from 30 seconds to one hour. After device or org deletion,
276
+ * only recorded destruction can settle the operation. Recording it wakes a suppressed retry.
277
+ * If settlement itself fails, the proof keeps its retry owed even after deletion.
262
278
  */
263
- deferRevocation(id: string): Promise<void>;
264
- acknowledgeRevocation(id: string): Promise<void>;
279
+ deferRevocation(id: string, delivery?: RevocationRetry): Promise<void>;
280
+ acknowledgeRevocation(id: string, opts?: {
281
+ withoutRef?: boolean;
282
+ destroyed?: boolean;
283
+ }): Promise<void>;
284
+ private acknowledgeRevocationIn;
285
+ private removeDeadRevocation;
286
+ /** Reclassify a lost task without appending a second finish or waking its conversation. */
287
+ private updateStopReason;
265
288
  }