@capybara-hq/kernel 0.1.0-rc.41 → 0.1.0-rc.42

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 (326) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/admin/admin.schemas.d.ts +6 -0
  3. package/dist/admin/org-network.service.d.ts +3 -1
  4. package/dist/admin/org-network.service.js +10 -2
  5. package/dist/app.d.ts +4 -0
  6. package/dist/app.js +2 -0
  7. package/dist/background/finish.d.ts +9 -1
  8. package/dist/background/finish.js +57 -4
  9. package/dist/background/launch.d.ts +23 -0
  10. package/dist/background/launch.js +55 -1
  11. package/dist/background/managed-output.d.ts +110 -0
  12. package/dist/background/managed-output.js +219 -0
  13. package/dist/background/managed.d.ts +52 -0
  14. package/dist/background/managed.js +128 -0
  15. package/dist/background/poll.job.d.ts +35 -1
  16. package/dist/background/poll.job.js +174 -9
  17. package/dist/background/render.js +1 -0
  18. package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
  19. package/dist/background/retire-legacy-tasks.job.js +149 -0
  20. package/dist/background/session.d.ts +15 -5
  21. package/dist/background/session.js +22 -6
  22. package/dist/background/stop.d.ts +35 -5
  23. package/dist/background/stop.js +94 -8
  24. package/dist/background/store.d.ts +110 -3
  25. package/dist/background/store.js +205 -3
  26. package/dist/background/tasks.service.d.ts +18 -1
  27. package/dist/background/tasks.service.js +99 -9
  28. package/dist/catalog/marketplaces.service.d.ts +1 -1
  29. package/dist/channels/cards.js +1 -1
  30. package/dist/channels/inbound.js +2 -0
  31. package/dist/channels/phrases.d.ts +4 -0
  32. package/dist/channels/phrases.js +4 -0
  33. package/dist/config/load.d.ts +18 -0
  34. package/dist/config/load.js +39 -1
  35. package/dist/config/permission-migration.d.ts +26 -0
  36. package/dist/config/permission-migration.js +64 -0
  37. package/dist/config/schema.d.ts +1 -1
  38. package/dist/config/schema.js +11 -10
  39. package/dist/conversations/conversations.controller.d.ts +1 -1
  40. package/dist/conversations/conversations.controller.js +1 -1
  41. package/dist/conversations/conversations.module.js +12 -0
  42. package/dist/conversations/conversations.service.d.ts +11 -2
  43. package/dist/conversations/conversations.service.js +97 -27
  44. package/dist/conversations/event-log.d.ts +1 -1
  45. package/dist/conversations/event-log.js +10 -2
  46. package/dist/conversations/events.d.ts +304 -4
  47. package/dist/conversations/events.js +279 -29
  48. package/dist/conversations/permission-profile-store.d.ts +50 -0
  49. package/dist/conversations/permission-profile-store.js +67 -0
  50. package/dist/conversations/permission-profile-store.module.d.ts +2 -0
  51. package/dist/conversations/permission-profile-store.module.js +19 -0
  52. package/dist/conversations/permission-profiles.controller.d.ts +84 -0
  53. package/dist/conversations/permission-profiles.controller.js +105 -0
  54. package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
  55. package/dist/conversations/permission-profiles.schemas.js +23 -0
  56. package/dist/conversations/permission-profiles.service.d.ts +56 -0
  57. package/dist/conversations/permission-profiles.service.js +179 -0
  58. package/dist/db/kernel-schema.d.ts +238 -3
  59. package/dist/devices/access.js +1 -1
  60. package/dist/devices/access.module.d.ts +2 -0
  61. package/dist/devices/access.module.js +19 -0
  62. package/dist/devices/conversation-devices.d.ts +8 -29
  63. package/dist/devices/conversation-devices.js +37 -73
  64. package/dist/devices/device-projects.service.d.ts +26 -28
  65. package/dist/devices/device-projects.service.js +123 -127
  66. package/dist/devices/devices.controller.js +3 -1
  67. package/dist/devices/devices.module.js +11 -9
  68. package/dist/devices/devices.service.d.ts +116 -8
  69. package/dist/devices/devices.service.js +252 -20
  70. package/dist/devices/dto.d.ts +16 -0
  71. package/dist/devices/dto.js +34 -6
  72. package/dist/devices/errors.d.ts +8 -0
  73. package/dist/devices/errors.js +10 -0
  74. package/dist/devices/project-rules.d.ts +44 -0
  75. package/dist/devices/project-rules.js +27 -0
  76. package/dist/devices/working-root.d.ts +6 -0
  77. package/dist/devices/working-root.js +12 -1
  78. package/dist/errors.d.ts +31 -0
  79. package/dist/errors.js +31 -0
  80. package/dist/evals/reconstruct.d.ts +19 -2
  81. package/dist/evals/reconstruct.js +40 -2
  82. package/dist/evals/recorded-permission-context.d.ts +77 -0
  83. package/dist/evals/recorded-permission-context.js +151 -0
  84. package/dist/evals/recorded-tools.d.ts +10 -1
  85. package/dist/evals/recorded-tools.js +27 -3
  86. package/dist/evals/run-replay.d.ts +8 -2
  87. package/dist/evals/run-replay.js +18 -2
  88. package/dist/evals/trajectory.d.ts +1 -1
  89. package/dist/evals/worker.d.ts +10 -1
  90. package/dist/evals/worker.js +23 -14
  91. package/dist/http/api.module.js +2 -0
  92. package/dist/identity/accounts.d.ts +14 -1
  93. package/dist/identity/accounts.js +61 -5
  94. package/dist/identity/identity.module.js +2 -0
  95. package/dist/identity/settings.d.ts +28 -12
  96. package/dist/identity/settings.js +89 -33
  97. package/dist/index.d.ts +6 -0
  98. package/dist/index.js +5 -0
  99. package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
  100. package/dist/infra/cli/kernel-cli.module.js +5 -2
  101. package/dist/infra/cli/permission-cutover.d.ts +59 -0
  102. package/dist/infra/cli/permission-cutover.js +107 -0
  103. package/dist/infra/config/kernel-config.service.d.ts +2 -2
  104. package/dist/infra/config/kernel-config.service.js +31 -11
  105. package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
  106. package/dist/infra/database/startup-activation-transaction.js +242 -0
  107. package/dist/infra/database/transaction-host.d.ts +47 -0
  108. package/dist/infra/database/transaction-host.js +119 -0
  109. package/dist/infra/database/xact-lock.d.ts +1 -0
  110. package/dist/infra/database/xact-lock.js +6 -0
  111. package/dist/infra/outbox/registry.d.ts +39 -0
  112. package/dist/infra/outbox/registry.js +18 -0
  113. package/dist/kernel.module.js +2 -0
  114. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  115. package/dist/lifecycle/kernel-lifecycle.js +55 -28
  116. package/dist/local-devices/device-auth.js +1 -1
  117. package/dist/local-devices/device-policy.service.d.ts +35 -5
  118. package/dist/local-devices/device-policy.service.js +188 -13
  119. package/dist/local-devices/instance-bindings.d.ts +82 -0
  120. package/dist/local-devices/instance-bindings.js +304 -0
  121. package/dist/local-devices/keys.d.ts +5 -0
  122. package/dist/local-devices/keys.js +5 -0
  123. package/dist/local-devices/local-device-gateway.d.ts +19 -4
  124. package/dist/local-devices/local-device-gateway.js +185 -17
  125. package/dist/local-devices/local-device-provider.d.ts +42 -7
  126. package/dist/local-devices/local-device-provider.js +185 -10
  127. package/dist/local-devices/local-devices.module.d.ts +17 -2
  128. package/dist/local-devices/local-devices.module.js +49 -8
  129. package/dist/local-devices/machines.d.ts +35 -12
  130. package/dist/local-devices/machines.js +203 -8
  131. package/dist/local-devices/network-grants.js +3 -3
  132. package/dist/local-devices/network-grants.module.d.ts +2 -0
  133. package/dist/local-devices/network-grants.module.js +14 -0
  134. package/dist/local-devices/owner-report.d.ts +79 -0
  135. package/dist/local-devices/owner-report.js +155 -0
  136. package/dist/local-devices/owner-reports.d.ts +48 -0
  137. package/dist/local-devices/owner-reports.js +190 -0
  138. package/dist/local-devices/policy-summary.d.ts +24 -1
  139. package/dist/local-devices/policy-summary.js +48 -0
  140. package/dist/local-devices/relay.d.ts +82 -6
  141. package/dist/local-devices/relay.js +187 -16
  142. package/dist/local-devices/targets.d.ts +16 -1
  143. package/dist/local-devices/targets.js +35 -2
  144. package/dist/orgs/cloud-network-setting.d.ts +33 -0
  145. package/dist/orgs/cloud-network-setting.js +47 -0
  146. package/dist/orgs/offboarding.d.ts +3 -1
  147. package/dist/orgs/offboarding.js +8 -2
  148. package/dist/orgs/org-lock.d.ts +10 -4
  149. package/dist/orgs/org-lock.js +10 -4
  150. package/dist/orgs/orgs.service.d.ts +3 -1
  151. package/dist/orgs/orgs.service.js +8 -2
  152. package/dist/orgs/settings.controller.d.ts +4 -1
  153. package/dist/orgs/settings.controller.js +3 -3
  154. package/dist/orgs/settings.service.d.ts +48 -56
  155. package/dist/orgs/settings.service.js +144 -101
  156. package/dist/overrides.d.ts +6 -1
  157. package/dist/overrides.js +2 -0
  158. package/dist/platform/exclusions.js +20 -0
  159. package/dist/platform/ops/admin.ops.js +14 -11
  160. package/dist/platform/ops/agent-skills.ops.js +2 -0
  161. package/dist/platform/ops/devices.ops.js +10 -2
  162. package/dist/platform/ops/org-settings.ops.js +6 -6
  163. package/dist/platform/ops/orgs.ops.js +1 -0
  164. package/dist/roles/worker.module.js +4 -0
  165. package/dist/runtime/context/build.d.ts +3 -1
  166. package/dist/runtime/context/build.js +19 -3
  167. package/dist/runtime/context/compaction.js +5 -0
  168. package/dist/runtime/context/device-paths.d.ts +9 -2
  169. package/dist/runtime/context/device-paths.js +20 -0
  170. package/dist/runtime/context/permission-profile.d.ts +46 -0
  171. package/dist/runtime/context/permission-profile.js +194 -0
  172. package/dist/runtime/maintenance.d.ts +7 -1
  173. package/dist/runtime/maintenance.js +43 -15
  174. package/dist/runtime/model-call.d.ts +32 -0
  175. package/dist/runtime/model-call.js +67 -0
  176. package/dist/runtime/permission-context-errors.d.ts +39 -0
  177. package/dist/runtime/permission-context-errors.js +67 -0
  178. package/dist/runtime/permission-context.service.d.ts +60 -0
  179. package/dist/runtime/permission-context.service.js +286 -0
  180. package/dist/runtime/project/knowledge.d.ts +7 -2
  181. package/dist/runtime/project/knowledge.js +5 -2
  182. package/dist/runtime/project/knowledge.service.d.ts +17 -2
  183. package/dist/runtime/project/knowledge.service.js +76 -12
  184. package/dist/runtime/run-execution.d.ts +4 -1
  185. package/dist/runtime/run-execution.js +14 -5
  186. package/dist/runtime/run-steps.d.ts +11 -3
  187. package/dist/runtime/run-steps.js +27 -4
  188. package/dist/runtime/runtime.module.js +11 -0
  189. package/dist/sandbox/attachments-path.d.ts +15 -0
  190. package/dist/sandbox/attachments-path.js +15 -0
  191. package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
  192. package/dist/sandbox/cloud-permission-snapshot.js +407 -0
  193. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
  194. package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
  195. package/dist/sandbox/held-operations.d.ts +39 -0
  196. package/dist/sandbox/held-operations.js +119 -0
  197. package/dist/sandbox/jobs.d.ts +14 -3
  198. package/dist/sandbox/jobs.js +20 -2
  199. package/dist/sandbox/kernel-read.d.ts +55 -0
  200. package/dist/sandbox/kernel-read.js +57 -0
  201. package/dist/sandbox/legacy-retirement.d.ts +336 -0
  202. package/dist/sandbox/legacy-retirement.js +1063 -0
  203. package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
  204. package/dist/sandbox/legacy-retirement.module.js +25 -0
  205. package/dist/sandbox/managed-device-context.d.ts +94 -0
  206. package/dist/sandbox/managed-device-context.js +308 -0
  207. package/dist/sandbox/managed-device-context.module.d.ts +6 -0
  208. package/dist/sandbox/managed-device-context.module.js +33 -0
  209. package/dist/sandbox/modes.d.ts +56 -8
  210. package/dist/sandbox/modes.js +92 -8
  211. package/dist/sandbox/operation-authority-types.d.ts +8 -0
  212. package/dist/sandbox/operation-authority-types.js +32 -0
  213. package/dist/sandbox/operation-authority.d.ts +145 -0
  214. package/dist/sandbox/operation-authority.js +783 -0
  215. package/dist/sandbox/operation-authority.module.d.ts +2 -0
  216. package/dist/sandbox/operation-authority.module.js +29 -0
  217. package/dist/sandbox/operation-intents.d.ts +206 -0
  218. package/dist/sandbox/operation-intents.js +1252 -0
  219. package/dist/sandbox/operation-intents.module.d.ts +2 -0
  220. package/dist/sandbox/operation-intents.module.js +21 -0
  221. package/dist/sandbox/operation-payloads.d.ts +33 -0
  222. package/dist/sandbox/operation-payloads.js +332 -0
  223. package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
  224. package/dist/sandbox/operation-reconcile.job.js +247 -0
  225. package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
  226. package/dist/sandbox/permission-authority-epochs.js +83 -0
  227. package/dist/sandbox/permission-authority-lock.d.ts +38 -0
  228. package/dist/sandbox/permission-authority-lock.js +147 -0
  229. package/dist/sandbox/permission-authority.module.d.ts +9 -0
  230. package/dist/sandbox/permission-authority.module.js +55 -0
  231. package/dist/sandbox/permission-availability.d.ts +18 -0
  232. package/dist/sandbox/permission-availability.js +19 -0
  233. package/dist/sandbox/permission-call-grants.d.ts +34 -0
  234. package/dist/sandbox/permission-call-grants.js +349 -0
  235. package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
  236. package/dist/sandbox/permission-call-grants.module.js +21 -0
  237. package/dist/sandbox/permission-call-types.d.ts +82 -0
  238. package/dist/sandbox/permission-call-types.js +1 -0
  239. package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
  240. package/dist/sandbox/permission-ceiling-writes.js +223 -0
  241. package/dist/sandbox/permission-config-publication.d.ts +76 -0
  242. package/dist/sandbox/permission-config-publication.js +339 -0
  243. package/dist/sandbox/permission-context-types.d.ts +64 -0
  244. package/dist/sandbox/permission-context-types.js +24 -0
  245. package/dist/sandbox/permission-facts.d.ts +206 -0
  246. package/dist/sandbox/permission-facts.js +627 -0
  247. package/dist/sandbox/permission-facts.module.d.ts +2 -0
  248. package/dist/sandbox/permission-facts.module.js +20 -0
  249. package/dist/sandbox/permission-instance-writes.d.ts +90 -0
  250. package/dist/sandbox/permission-instance-writes.js +305 -0
  251. package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
  252. package/dist/sandbox/permission-runtime-reports.js +354 -0
  253. package/dist/sandbox/permission-transitions.d.ts +31 -0
  254. package/dist/sandbox/permission-transitions.js +155 -0
  255. package/dist/sandbox/platform-full-access.d.ts +128 -0
  256. package/dist/sandbox/platform-full-access.js +210 -0
  257. package/dist/sandbox/providers.d.ts +22 -0
  258. package/dist/sandbox/providers.js +10 -2
  259. package/dist/sandbox/providers.module.d.ts +2 -0
  260. package/dist/sandbox/providers.module.js +19 -0
  261. package/dist/sandbox/request-not-sent.d.ts +13 -0
  262. package/dist/sandbox/request-not-sent.js +13 -0
  263. package/dist/sandbox/review/classifier.d.ts +2 -0
  264. package/dist/sandbox/review/classifier.js +8 -0
  265. package/dist/sandbox/review/permission-candidate.d.ts +12 -0
  266. package/dist/sandbox/review/permission-candidate.js +129 -0
  267. package/dist/sandbox/review/review.service.d.ts +4 -1
  268. package/dist/sandbox/review/review.service.js +19 -5
  269. package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
  270. package/dist/sandbox/sandbox-file-reader.js +51 -7
  271. package/dist/sandbox/sandbox.module.js +26 -6
  272. package/dist/sandbox/sandbox.service.d.ts +230 -34
  273. package/dist/sandbox/sandbox.service.js +1368 -199
  274. package/dist/sandbox/unreachable.js +17 -3
  275. package/dist/sandbox/use-context.d.ts +17 -0
  276. package/dist/sandbox/use-context.js +1 -0
  277. package/dist/skills/invoke.d.ts +27 -4
  278. package/dist/skills/invoke.js +72 -7
  279. package/dist/tools/approvals.controller.d.ts +1 -0
  280. package/dist/tools/approvals.schemas.d.ts +1 -0
  281. package/dist/tools/approvals.schemas.js +3 -1
  282. package/dist/tools/approvals.service.d.ts +23 -10
  283. package/dist/tools/approvals.service.js +104 -26
  284. package/dist/tools/builtins/builtin-tools.d.ts +16 -2
  285. package/dist/tools/builtins/builtin-tools.js +38 -10
  286. package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
  287. package/dist/tools/builtins/sandbox/bash.js +201 -5
  288. package/dist/tools/builtins/sandbox/common.d.ts +92 -20
  289. package/dist/tools/builtins/sandbox/common.js +201 -17
  290. package/dist/tools/builtins/sandbox/deliver.js +2 -2
  291. package/dist/tools/builtins/sandbox/edit.js +2 -2
  292. package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
  293. package/dist/tools/builtins/sandbox/glob.js +2 -2
  294. package/dist/tools/builtins/sandbox/grep.js +2 -2
  295. package/dist/tools/builtins/sandbox/read.js +2 -2
  296. package/dist/tools/builtins/sandbox/task-list.js +7 -1
  297. package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
  298. package/dist/tools/builtins/sandbox/task-output.js +172 -0
  299. package/dist/tools/builtins/sandbox/task-stop.js +25 -3
  300. package/dist/tools/builtins/sandbox/write.js +2 -2
  301. package/dist/tools/builtins/skill-load.js +9 -6
  302. package/dist/tools/device-op-resolver.d.ts +1 -1
  303. package/dist/tools/device-op-resolver.js +13 -3
  304. package/dist/tools/permission-approval-jobs.d.ts +18 -0
  305. package/dist/tools/permission-approval-jobs.js +92 -0
  306. package/dist/tools/pipeline.d.ts +17 -2
  307. package/dist/tools/pipeline.js +300 -19
  308. package/dist/tools/registry.d.ts +9 -0
  309. package/dist/tools/tools.module.js +12 -0
  310. package/package.json +4 -3
  311. package/src/migrations/0146_permission_authority_epochs.sql +6 -0
  312. package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
  313. package/src/migrations/0148_first_message_request_hash.sql +2 -0
  314. package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
  315. package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
  316. package/src/migrations/0151_starting_execution_grants.sql +8 -0
  317. package/src/migrations/0152_background_launch_identity.sql +66 -0
  318. package/src/migrations/0153_background_cancel_requester.sql +13 -0
  319. package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
  320. package/src/migrations/0155_device_instance_generations.sql +30 -0
  321. package/src/migrations/0156_device_owner_report.sql +7 -0
  322. package/src/migrations/0157_legacy_retirement.sql +116 -0
  323. package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
  324. package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
  325. package/dist/sandbox/platform-auto-mode.d.ts +0 -63
  326. package/dist/sandbox/platform-auto-mode.js +0 -63
@@ -16,6 +16,11 @@ 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";
19
24
  /** The inactivity destruction sweep (hourly, once per tick across replicas). */
20
25
  export const SANDBOX_DESTROY_JOB = "sandbox-destroy-inactive";
21
26
  /**
@@ -85,11 +90,14 @@ export { SandboxJobs };
85
90
  * The worker side of {@link SANDBOX_RESET_FILES_JOB}: `resetFileSystem` under the exclusive lease;
86
91
  * a failure fails the job (retried).
87
92
  */
88
- export async function runSandboxResetFiles(sandbox, job) {
93
+ export async function runSandboxResetFiles(sandbox, job,
94
+ /** B1: a reset establishes the device's exact limits; clears its reconciliation marker. */
95
+ snapshots) {
89
96
  const id = job.data.deviceId;
90
97
  if (typeof id !== "string")
91
98
  return;
92
99
  await sandbox.resetFileSystem(id);
100
+ await snapshots?.reconcileDevice(id);
93
101
  }
94
102
  /**
95
103
  * The worker side of {@link SANDBOX_DESTROY_FOR_JOB}: `destroyDevice` one by one; a failure is
@@ -117,7 +125,9 @@ export async function runSandboxDestroyFor(sandbox, log, job) {
117
125
  /**
118
126
  * The sandbox sweeps (exactly once per tick across replicas): every minute the idle and overdue
119
127
  * running instances are suspended, every hour the inactive instances are destroyed (files kept)
120
- * and deleted devices, or those of deleted orgs, are destroyed with their files. Both do nothing without a sandbox provider. They replace the
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
121
131
  * maintenance schedulers `sandbox-suspend-idle-every-minute` and `sandbox-destroy-inactive-hourly`
122
132
  * (retired at worker start).
123
133
  */
@@ -135,6 +145,11 @@ let SandboxSweepJobs = class SandboxSweepJobs {
135
145
  if (n > 0)
136
146
  this.log.info("idle sandboxes suspended", { count: n });
137
147
  }
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
+ }
138
153
  async destroyInactive() {
139
154
  const n = await this.sandbox.destroyInactive(new Date());
140
155
  if (n > 0)
@@ -144,6 +159,9 @@ let SandboxSweepJobs = class SandboxSweepJobs {
144
159
  __decorate([
145
160
  LockedCron("* * * * *", { name: SANDBOX_SUSPEND_JOB })
146
161
  ], SandboxSweepJobs.prototype, "suspendIdle", null);
162
+ __decorate([
163
+ LockedCron("* * * * *", { name: SANDBOX_RECONCILE_JOB })
164
+ ], SandboxSweepJobs.prototype, "reconcileLimits", null);
147
165
  __decorate([
148
166
  LockedCron("0 * * * *", { name: SANDBOX_DESTROY_JOB })
149
167
  ], SandboxSweepJobs.prototype, "destroyInactive", null);
@@ -0,0 +1,55 @@
1
+ import type { ExecutionClaim } from "../runtime/run-execution.js";
2
+ /**
3
+ * A kernel read of a device on behalf of a run start (permission activation L2, Hook 1): the
4
+ * run's current execution claim and what is read. Only `project_root` exists: the bound project's
5
+ * `AGENTS.md` and `.agents/skills/**` read before the run's first model call. Supplied only by
6
+ * `ProjectKnowledgeService`, never by a tool, a Platform operation or an HTTP route.
7
+ */
8
+ export interface KernelReadInvocation {
9
+ claim: ExecutionClaim;
10
+ purpose: "project_root";
11
+ /** The conversation's bound project root (`conversations.project_path`). */
12
+ root: string;
13
+ }
14
+ /** The directory of a project's skills, relative to its root (project root spec §4.7). */
15
+ export declare const PROJECT_SKILLS_DIR = ".agents/skills";
16
+ /** The methods a kernel read may use: never a write, an exec or a scan. */
17
+ export type KernelReadMethod = "stat" | "readFile" | "list";
18
+ export declare const isKernelReadMethod: (method: string) => method is KernelReadMethod;
19
+ /**
20
+ * The one path a kernel read of `root` may reach with `method` that covers `path`, the operation's
21
+ * only read root; null when the read is outside it. A `stat` of the root itself (whether the
22
+ * project is still there); `stat` and `readFile` of `<root>/AGENTS.md`; any of the three inside
23
+ * `<root>/.agents/skills`. Never anything else under the root, and never a path that is not
24
+ * clean and absolute.
25
+ */
26
+ export declare function kernelReadRoot(root: string, method: KernelReadMethod, path: string): string | null;
27
+ /**
28
+ * A kernel read that was not admitted (its run is no longer the claim's queued run start, the
29
+ * authority refused it, its scope changed before dispatch): nothing was sent to the device. The
30
+ * knowledge read treats it as a device that could not be asked, never as an unreadable project.
31
+ */
32
+ export declare class KernelReadNotAdmitted extends Error {
33
+ constructor(cause: unknown);
34
+ }
35
+ /**
36
+ * How a kernel read is sent, from the device's recorded runtime support and whether its runtime is
37
+ * isolated (its file system holds no host home: a cloud device, or a local machine recorded in its
38
+ * Docker mode): `restricted` whenever the runtime enforces the restricted profiles (the read-only
39
+ * scope, whatever the conversation selected); `full` only for an isolated Full-only runtime (the
40
+ * conversation's admitted Full access, still with the one covering path and the read methods);
41
+ * `refused` otherwise (a host machine without restricted enforcement: fail closed).
42
+ */
43
+ export type KernelReadRoute = "restricted" | "full" | "refused";
44
+ export declare function kernelReadRoute(support: {
45
+ restricted: boolean;
46
+ fullAccess: boolean;
47
+ isolated: boolean;
48
+ }): KernelReadRoute;
49
+ /**
50
+ * The device's runtime cannot enforce a read-only kernel read of the project (a host machine
51
+ * without restricted enforcement): nothing is sent, and the project is recorded unreadable.
52
+ */
53
+ export declare class KernelReadUnsupported extends Error {
54
+ constructor();
55
+ }
@@ -0,0 +1,57 @@
1
+ import { posix } from "node:path";
2
+ import { validateSandboxPathShape } from "@capybara-hq/plugin-sdk";
3
+ import { canonicalRoot } from "../devices/working-root.js";
4
+ /** The directory of a project's skills, relative to its root (project root spec §4.7). */
5
+ export const PROJECT_SKILLS_DIR = ".agents/skills";
6
+ export const isKernelReadMethod = (method) => method === "stat" || method === "readFile" || method === "list";
7
+ /**
8
+ * The one path a kernel read of `root` may reach with `method` that covers `path`, the operation's
9
+ * only read root; null when the read is outside it. A `stat` of the root itself (whether the
10
+ * project is still there); `stat` and `readFile` of `<root>/AGENTS.md`; any of the three inside
11
+ * `<root>/.agents/skills`. Never anything else under the root, and never a path that is not
12
+ * clean and absolute.
13
+ */
14
+ export function kernelReadRoot(root, method, path) {
15
+ const base = canonicalRoot(root);
16
+ if (validateSandboxPathShape(base).length > 0)
17
+ return null;
18
+ if (validateSandboxPathShape(path).length > 0 || posix.normalize(path) !== path)
19
+ return null;
20
+ if (path === base)
21
+ return method === "stat" ? base : null;
22
+ const agents = `${base === "/" ? "" : base}/AGENTS.md`;
23
+ if (path === agents)
24
+ return method === "list" ? null : agents;
25
+ const skills = `${base === "/" ? "" : base}/${PROJECT_SKILLS_DIR}`;
26
+ if (path === skills || path.startsWith(`${skills}/`))
27
+ return skills;
28
+ return null;
29
+ }
30
+ /**
31
+ * A kernel read that was not admitted (its run is no longer the claim's queued run start, the
32
+ * authority refused it, its scope changed before dispatch): nothing was sent to the device. The
33
+ * knowledge read treats it as a device that could not be asked, never as an unreadable project.
34
+ */
35
+ export class KernelReadNotAdmitted extends Error {
36
+ constructor(cause) {
37
+ super("The kernel read was not admitted; nothing was sent to the device", { cause });
38
+ this.name = "KernelReadNotAdmitted";
39
+ }
40
+ }
41
+ export function kernelReadRoute(support) {
42
+ if (support.restricted)
43
+ return "restricted";
44
+ if (support.fullAccess && support.isolated)
45
+ return "full";
46
+ return "refused";
47
+ }
48
+ /**
49
+ * The device's runtime cannot enforce a read-only kernel read of the project (a host machine
50
+ * without restricted enforcement): nothing is sent, and the project is recorded unreadable.
51
+ */
52
+ export class KernelReadUnsupported extends Error {
53
+ constructor() {
54
+ super("This device's runtime cannot enforce a read-only kernel read on its host");
55
+ this.name = "KernelReadUnsupported";
56
+ }
57
+ }
@@ -0,0 +1,336 @@
1
+ import { KernelDb } from "../infra/database/kernel-db.js";
2
+ import { TransactionHost } from "../infra/database/transaction-host.js";
3
+ import { PermissionAuthorityLock } from "./permission-authority-lock.js";
4
+ /** An unresolved or resolved obligation as the gate reads it. */
5
+ export interface RetirementObligation {
6
+ id: string;
7
+ deviceId: string;
8
+ orgId: string;
9
+ provider: string;
10
+ /** The exact instance generation (epoch ms as decimal text), or `unknown`. */
11
+ instanceGeneration: string;
12
+ state: "open" | "quarantined" | "resolved" | "abandoned";
13
+ reason: string | null;
14
+ attempts: number;
15
+ /** A local incarnation's boot identity when recorded; null: none (never resolves by itself). */
16
+ bootId: string | null;
17
+ /** When it was recorded (a cloud `unknown` one resolves only if recorded after the freeze). */
18
+ createdAt: Date;
19
+ }
20
+ /** {@link LegacyRetirementStore.recordBoot}'s answer. */
21
+ export type BootReport =
22
+ /** First seen for the machine: its current boot now (a restart when one was seen before). */
23
+ "new"
24
+ /** The machine's current boot again (a reconnect). */
25
+ | "current"
26
+ /** A boot seen before a later one (stale or replayed): ignored. */
27
+ | "stale"
28
+ /** Malformed, or the machine is unknown or revoked: ignored. */
29
+ | "ignored";
30
+ /** {@link LegacyRetirementStore.admitLegacyDispatch}'s answer. */
31
+ export type LegacyDispatchAdmission =
32
+ /** The launch may dispatch; its row is marked `dispatched` first. */
33
+ "admitted"
34
+ /** The legacy-launch freeze is published: the launch must not dispatch. */
35
+ | "frozen"
36
+ /** The reservation is no longer a launchable legacy row (finished meanwhile). */
37
+ | "gone";
38
+ /** {@link LegacyRetirementStore.freeze}'s answer: the freeze is published and enumerated. */
39
+ export interface LegacyFreezeResult {
40
+ /** When the freeze was first published (a rerun keeps it). */
41
+ frozenAt: Date;
42
+ /** New obligation members this run's enumeration recorded. */
43
+ added: number;
44
+ stable: true;
45
+ }
46
+ /** Where the freeze stands: published (`frozenAt`) and its enumeration completed (`enumeratedAt`). */
47
+ export interface LegacyFreezeState {
48
+ frozenAt: Date | null;
49
+ /** When the freeze's own enumeration last completed with a stable pass; null: never. */
50
+ enumeratedAt: Date | null;
51
+ }
52
+ /**
53
+ * The cutover barrier is not in place: legacy admission is still open (no freeze), or the freeze
54
+ * is published but its enumeration never completed. Nothing that depends on closed admission
55
+ * (the cloud snapshot) may run.
56
+ */
57
+ export declare class CutoverBarrierError extends Error {
58
+ constructor(message: string);
59
+ }
60
+ /**
61
+ * The freeze is published, but its enumeration kept finding new rows for every pass (legacy rows,
62
+ * for example of a replica without the freeze code, or revoked managed starts). The freeze stays published (it
63
+ * is never undone) and is not marked enumerated; stop that replica and run the freeze again.
64
+ */
65
+ export declare class LegacyFreezeUnsettledError extends Error {
66
+ constructor(passes: number, added: number);
67
+ }
68
+ /** What the release gate reads: unresolved obligations are reported, never called retired. */
69
+ export interface LegacyRetirementReport {
70
+ frozen: boolean;
71
+ /** When the freeze was published; null before. */
72
+ frozenAt: Date | null;
73
+ /**
74
+ * When the freeze's own enumeration last completed stable; null while it never did (the cloud
75
+ * snapshot refuses until then: run the freeze again).
76
+ */
77
+ freezeEnumeratedAt: Date | null;
78
+ /**
79
+ * Running legacy launches reserved by fenced code and never admitted for dispatch: the freeze
80
+ * refuses their dispatch (the pending producers it fences).
81
+ */
82
+ fencedReservations: number;
83
+ /**
84
+ * Evidence of replicas without the 8.5 code (they are not fenced by the freeze): legacy rows
85
+ * without the dispatch marker (`legacy_dispatch = 'unknown'`) started after migration 0157 was
86
+ * applied (only such a replica writes them); how many of those started after the freeze, after
87
+ * its enumeration (the barrier refuses then) and in the last 15 minutes by the database clock;
88
+ * and the latest one's start. Nonzero `afterFreeze` or `recent`: an old replica still runs; stop
89
+ * it. Rows of an old replica that never starts a legacy task are not detectable here.
90
+ */
91
+ unfencedWriters: {
92
+ sinceMigration: number;
93
+ afterFreeze: number;
94
+ afterEnumeration: number;
95
+ recent: number;
96
+ latestAt: Date | null;
97
+ };
98
+ open: number;
99
+ quarantined: number;
100
+ resolved: number;
101
+ /** Members of resolved obligations whose own records are not settled yet. */
102
+ unsettledMembers: number;
103
+ /**
104
+ * True only with the freeze published and every obligation not abandoned resolved and settled.
105
+ * Abandoned ones are excluded: see {@link cleanRetirement}.
106
+ */
107
+ retired: boolean;
108
+ /** {@link retired} with no abandoned obligation either. */
109
+ cleanRetirement: boolean;
110
+ /** Obligations abandoned with their deleted devices: never evidence the processes ended. */
111
+ abandoned: number;
112
+ /** Members of abandoned obligations (left unsettled; not in {@link unsettledMembers}). */
113
+ abandonedMembers: number;
114
+ abandonedList: {
115
+ deviceId: string;
116
+ provider: string;
117
+ instanceGeneration: string;
118
+ local: boolean;
119
+ bootKnown: boolean;
120
+ abandonedAt: Date;
121
+ }[];
122
+ /**
123
+ * The cloud pre-check (before the freeze, too): cloud devices with legacy rows whose incarnation
124
+ * or provider is unknown. It reads the task rows, so it lists what the freeze will turn into
125
+ * such obligations; it does not empty by itself. After the freeze such an obligation resolves
126
+ * only once the device's current incarnation is destroyed with confirmation, it keeps no earlier
127
+ * provider's instance (`prevHandle`) and it has an instance record that once had an instance
128
+ * (`noInstance`); a device with either must be deleted and created again
129
+ * (`device.recreate_required`).
130
+ * `currentUnconfirmed`: the current row is not live and no destruction of it is recorded (the
131
+ * inactivity sweep before 0157, or a failed create); the gate then destroys by the device's
132
+ * instance name with the row's provider, which must be loaded (`device.unavailable` until then).
133
+ */
134
+ cloudUnknown: {
135
+ deviceId: string;
136
+ prevHandle: boolean;
137
+ noInstance: boolean;
138
+ currentUnconfirmed: boolean;
139
+ }[];
140
+ /**
141
+ * The cutover pre-check (before the freeze, too): local devices with legacy rows whose processes
142
+ * may still exist and whose current machine has no recorded boot identity. Their obligations
143
+ * could never resolve by a restart: ship the boot-reporting device build and wait for these to
144
+ * report before publishing the freeze.
145
+ */
146
+ localWithoutBoot: {
147
+ deviceId: string;
148
+ machineId: string | null;
149
+ }[];
150
+ unresolved: {
151
+ deviceId: string;
152
+ provider: string;
153
+ instanceGeneration: string;
154
+ state: "open" | "quarantined";
155
+ reason: string | null;
156
+ /** A local incarnation with a recorded boot: a restart of that computer resolves it. */
157
+ bootKnown: boolean;
158
+ }[];
159
+ }
160
+ /** A member of an obligation (a legacy task row, or a revoked managed start). */
161
+ export interface RetirementMember {
162
+ obligationId: string;
163
+ kind: "legacy-task" | "revoked-start";
164
+ refId: string;
165
+ }
166
+ /** Whether `provider` is a cloud provider (one whose whole-instance destroy is confirmed). */
167
+ export declare const isCloudProvider: (provider: string) => boolean;
168
+ export declare class LegacyRetirementStore {
169
+ private readonly db;
170
+ readonly txHost: TransactionHost;
171
+ private readonly locks;
172
+ constructor(db: KernelDb, txHost: TransactionHost, locks: PermissionAuthorityLock);
173
+ /**
174
+ * Publishes the legacy-launch freeze under the platform authority writer, then enumerates every
175
+ * legacy row and revoked start until stable; idempotent. Returns when it was first published.
176
+ * Never undone.
177
+ */
178
+ freeze(by: string): Promise<LegacyFreezeResult>;
179
+ /** Whether the freeze is published and whether its enumeration completed. */
180
+ freezeState(): Promise<LegacyFreezeState>;
181
+ /**
182
+ * The cutover barrier (B-10): legacy admission is closed (the freeze is published), the
183
+ * freeze's own enumeration completed, and no unmarked legacy row (only an old, unfenced replica
184
+ * writes one) started after that enumeration. Throws {@link CutoverBarrierError} otherwise. The
185
+ * freeze is never undone; a later legacy row is still enumerated by the gate before any use.
186
+ */
187
+ assertCutoverBarrier(): Promise<void>;
188
+ private publishFreeze;
189
+ /** When the freeze was published; null before. */
190
+ frozenAt(): Promise<Date | null>;
191
+ /**
192
+ * The worker's sweep of obligations whose device is gone (its row missing, `deleted_at` set, or
193
+ * its org soft-deleted), at most `limit` per call:
194
+ * - a cloud one (any provider not kernel-internal) waits while the device's instance row exists:
195
+ * its destroy is still owed (the destroy job or the destruction sweep deletes the row when it
196
+ * is done) and records the destruction then;
197
+ * - one whose exact incarnation has a recorded confirmed destruction resolves
198
+ * `provider-destroyed`, an already `abandoned` cloud one too (provider evidence, not a
199
+ * reopen);
200
+ * - every other one becomes `abandoned`. Device ids are never reused, so no device can acquire
201
+ * that incarnation again, but abandonment is no evidence that its processes ended (they may
202
+ * still run on that computer); its members stay unsettled.
203
+ * Returns the counts.
204
+ */
205
+ abandonDeleted(limit: number): Promise<{
206
+ resolved: number;
207
+ abandoned: number;
208
+ }>;
209
+ frozen(): Promise<boolean>;
210
+ /**
211
+ * The check every legacy SID launch makes immediately before it dispatches its command: under
212
+ * the shared platform authority lock (so a concurrent {@link freeze} waits for it), refuses once
213
+ * the freeze is published; otherwise marks the reservation `dispatched` in the same transaction.
214
+ */
215
+ admitLegacyDispatch(orgId: string, taskId: string,
216
+ /** The exact incarnation the launch dispatches into (read under its shared lease). */
217
+ instance: {
218
+ provider: string;
219
+ generation: string;
220
+ }): Promise<LegacyDispatchAdmission>;
221
+ /**
222
+ * One enumeration pass: every legacy row (only once the freeze is published) and every revoked
223
+ * managed start that may still own processes on an incarnation that no longer runs, recorded as
224
+ * members of their obligations. Idempotent; returns how many new members it recorded. The
225
+ * worker repeats it every tick, so a row an old unfenced replica writes later is still found.
226
+ */
227
+ scan(deviceId?: string): Promise<{
228
+ added: number;
229
+ }>;
230
+ /** Repeats {@link scan} until a pass adds nothing (at most `maxPasses`). */
231
+ scanUntilStable(maxPasses?: number, deviceId?: string): Promise<{
232
+ added: number;
233
+ stable: boolean;
234
+ }>;
235
+ /**
236
+ * Legacy rows whose processes may still exist and that are not members yet (one device's, or
237
+ * all). The `(status = 'running' OR kill_pending OR sid IS NULL)` conjunct is the partial index's
238
+ * predicate (0157), stated as is so the planner can use it.
239
+ */
240
+ private legacyCandidates;
241
+ private scanLegacyTasks;
242
+ /** Revoked managed starts on an incarnation that no longer runs, not members yet. */
243
+ private revokedCandidates;
244
+ private scanRevokedStarts;
245
+ /** The obligation of the incarnation (created when missing), with the member added. */
246
+ private addMember;
247
+ /** The device's active machine and the boot it reported last (null: no machine). */
248
+ private currentBoot;
249
+ /**
250
+ * Records the OS boot identity an authenticated hello of `machineId` reported. The caller is the
251
+ * gateway's hello record, after the connection authenticated with the machine's credential and
252
+ * claimed the device, inside its transaction with the machine row locked. A boot first seen for
253
+ * the machine becomes its current one; the current one again is a reconnect; one seen before a
254
+ * later one (stale, replayed) changes nothing. A new or current boot then settles the device's
255
+ * local obligations recorded under another boot of the computer ({@link settleRebooted}).
256
+ */
257
+ recordBoot(machineId: string, bootId: unknown): Promise<BootReport>;
258
+ /**
259
+ * A hello without a boot identity: the machine has no current boot any more, so a boot it
260
+ * reported earlier is never taken as the one its later work ran under (M2).
261
+ */
262
+ clearBoot(machineId: string): Promise<void>;
263
+ /**
264
+ * Resolves (`host-rebooted`) every unresolved local obligation of the device for which a current
265
+ * (non-revoked) machine of the device has recorded a boot other than the obligation's: the
266
+ * evidence is the OS instance, not the credential, so a re-login on the same computer reporting
267
+ * the same boot changes nothing, and one after a restart (or any later boot) resolves it. A boot
268
+ * that some machine of the device had already reported when the obligation's boot was first
269
+ * seen is an older boot, never evidence (a replay through another credential). An obligation
270
+ * without a recorded boot never resolves here. Returns how many resolved.
271
+ */
272
+ settleRebooted(deviceId: string): Promise<number>;
273
+ /** The device's unresolved obligations (open and quarantined), oldest first. */
274
+ unresolved(deviceId: string): Promise<RetirementObligation[]>;
275
+ /**
276
+ * Whether the device has an unresolved obligation, or a candidate not enumerated yet (a legacy
277
+ * row once frozen, a revoked start): the shared-path check. A candidate counts as unresolved, so
278
+ * the device goes to the gate, which enumerates it under the exclusive lease (C1).
279
+ */
280
+ hasUnresolved(deviceId: string): Promise<boolean>;
281
+ /**
282
+ * No trusted way to establish termination: the obligation is quarantined (the device stays
283
+ * unavailable). A resolved obligation is left as it is.
284
+ */
285
+ quarantine(id: string, reason: string): Promise<void>;
286
+ /** A failed destroy or verification: the obligation stays as it is, the attempt is recorded. */
287
+ noteFailure(id: string, error: unknown): Promise<void>;
288
+ /** The provider confirmed the incarnation destroyed: the obligation resolves. */
289
+ resolveDestroyed(id: string): Promise<void>;
290
+ /**
291
+ * The provider confirmed the exact cancellation of the revoked managed starts `covered` on the
292
+ * resumed incarnation (B-22): under the obligation's row lock (the lock {@link addMember} takes
293
+ * before it adds a member), resolves it as `exact-cancelled` and acknowledges those
294
+ * revocations, only while every member is one of them. False (nothing changed) when a member
295
+ * outside `covered` exists, which was never stopped: the caller destroys the incarnation
296
+ * instead. Acknowledging here is what tells a member added later apart ({@link scan}).
297
+ */
298
+ resolveCancelled(id: string, covered: readonly string[]): Promise<boolean>;
299
+ /**
300
+ * Reopens `exact-cancelled` obligations holding a member nobody stopped: a legacy row, or a
301
+ * revoked start whose intent is not there acknowledged, a missing intent included (every
302
+ * member the cancel covered was acknowledged with the resolution). A replica without the reopen in {@link addMember} (a
303
+ * rolling upgrade) adds such members to a resolved obligation; the next scan of a new one
304
+ * reopens it. Returns how many it reopened.
305
+ */
306
+ private reopenLateMembers;
307
+ /**
308
+ * A member of obligation `o` an exact cancel never covered (see {@link reopenLateMembers}),
309
+ * correlated on `o.id`.
310
+ */
311
+ private lateMember;
312
+ /** The members of one obligation, oldest first. */
313
+ membersOf(obligationId: string): Promise<RetirementMember[]>;
314
+ /**
315
+ * Records the provider-confirmed destruction of a cloud incarnation. A kernel-internal
316
+ * provider's destroy (a local machine: a no-op) is never evidence and is refused.
317
+ */
318
+ recordDestruction(deviceId: string, provider: string, generation: string): Promise<void>;
319
+ /** Whether a confirmed destruction of exactly that cloud incarnation was recorded. */
320
+ destructionRecorded(deviceId: string, provider: string, generation: string): Promise<boolean>;
321
+ /**
322
+ * Devices with an unresolved obligation the worker should try now: never attempted, or last
323
+ * attempted longer ago than the backoff (30 s doubling per attempt, at most an hour).
324
+ */
325
+ due(limit: number): Promise<string[]>;
326
+ /** Members of resolved obligations whose own records are not settled yet. */
327
+ unsettledMembers(limit: number): Promise<RetirementMember[]>;
328
+ markSettled(m: RetirementMember): Promise<void>;
329
+ /**
330
+ * Legacy rows without the dispatch marker started after the marker's migration was applied:
331
+ * only a replica without the 8.5 code writes them (see {@link LegacyRetirementReport}).
332
+ */
333
+ private unfencedWriters;
334
+ /** The release gate's honest view (a quarantined device is unavailable, not retired). */
335
+ report(): Promise<LegacyRetirementReport>;
336
+ }