@capybara-hq/kernel 0.1.0-rc.40 → 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 +10 -1
  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
@@ -0,0 +1,223 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable } from "@nestjs/common";
11
+ import { KernelDb } from "../infra/database/kernel-db.js";
12
+ import { TransactionHost } from "../infra/database/transaction-host.js";
13
+ import { Transactional } from "../infra/database/transactional.decorator.js";
14
+ import { OutboxService } from "../infra/outbox/outbox.service.js";
15
+ import { machineRootList, outsideMachineRoots } from "../local-devices/owner-report.js";
16
+ import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
17
+ import { PermissionAuthorityLock } from "./permission-authority-lock.js";
18
+ import { PermissionTransitions } from "./permission-transitions.js";
19
+ const required = (value) => {
20
+ if (value === undefined || value === null)
21
+ throw new Error("The authority subject is incomplete");
22
+ return value;
23
+ };
24
+ /** Lower-level publication shared by ceiling writers; imports no facts, profiles or lifecycle. */
25
+ let PermissionCeilingWrites = class PermissionCeilingWrites {
26
+ transitions;
27
+ db;
28
+ txHost;
29
+ locks;
30
+ epochs;
31
+ outbox;
32
+ constructor(transitions, db, txHost, locks, epochs, outbox) {
33
+ this.transitions = transitions;
34
+ this.db = db;
35
+ this.txHost = txHost;
36
+ this.locks = locks;
37
+ this.epochs = epochs;
38
+ this.outbox = outbox;
39
+ }
40
+ async lock(subject, level) {
41
+ await this.locks.acquire(subject, { kind: "write", level });
42
+ }
43
+ /** The platform writer excludes every descendant; only these environments changed Full reach. */
44
+ async invalidateDeviceConsentUnderPlatform(deviceIds) {
45
+ this.locks.assertHeld("platform", "platform", true);
46
+ for (const id of deviceIds)
47
+ await this.db
48
+ .insertInto("permission_authority_epochs")
49
+ .values({ kind: "device", id, full_revision: 1 })
50
+ .onConflict((oc) => oc.columns(["kind", "id"]).doUpdateSet((eb) => ({
51
+ full_revision: eb("permission_authority_epochs.full_revision", "+", 1),
52
+ })))
53
+ .execute();
54
+ if (deviceIds.length) {
55
+ const roots = await this.db
56
+ .selectFrom("conversations")
57
+ .selectAll()
58
+ .where("device_id", "in", [...deviceIds])
59
+ .where("parent_conversation_id", "is", null)
60
+ .where("permission_profile", "=", "full-access")
61
+ .orderBy("org_id")
62
+ .orderBy("id")
63
+ .forUpdate()
64
+ .execute();
65
+ for (const root of roots)
66
+ await this.resetRoot(root, {}, "platform");
67
+ }
68
+ }
69
+ async publishLocked(subject, level, revoke = true, invalidateFullConsent = false) {
70
+ const id = level === "platform"
71
+ ? "platform"
72
+ : level === "org"
73
+ ? subject.orgId
74
+ : level === "device"
75
+ ? subject.deviceId
76
+ : subject.rootConversationId;
77
+ if (!id)
78
+ throw new Error("Ceiling publication requires its actual subject");
79
+ this.locks.assertHeld(level, id, true);
80
+ const vector = await this.epochs.readLocked(subject);
81
+ await this.epochs.bumpLocked(level, id, required(vector[level]));
82
+ if (invalidateFullConsent) {
83
+ await this.db
84
+ .updateTable("permission_authority_epochs")
85
+ .set((eb) => ({ full_revision: eb("full_revision", "+", 1) }))
86
+ .where("kind", "=", level)
87
+ .where("id", "=", id)
88
+ .execute();
89
+ let roots = this.db
90
+ .selectFrom("conversations")
91
+ .selectAll()
92
+ .where("parent_conversation_id", "is", null)
93
+ .where("permission_profile", "=", "full-access");
94
+ if (level !== "platform")
95
+ roots = roots.where("org_id", "=", required(subject.orgId));
96
+ if (level === "device")
97
+ roots = roots.where("device_id", "=", required(subject.deviceId));
98
+ if (level === "root")
99
+ roots = roots.where("id", "=", required(subject.rootConversationId));
100
+ for (const root of await roots.orderBy("org_id").orderBy("id").forUpdate().execute())
101
+ await this.resetRoot(root, subject, level);
102
+ }
103
+ if (!revoke)
104
+ return;
105
+ // Acknowledged background starts stay revocable by every actual revoking writer (deletion is
106
+ // the root-level one). Profile changes never reach here: they only bump the root epoch.
107
+ let candidates = this.db
108
+ .selectFrom("sandbox_operation_intents")
109
+ .selectAll()
110
+ .where("state", "in", [
111
+ "admitted",
112
+ "dispatching",
113
+ "started-or-unknown",
114
+ "background-running",
115
+ ]);
116
+ if (level !== "platform")
117
+ candidates = candidates.where("org_id", "=", required(subject.orgId));
118
+ if (level === "device")
119
+ candidates = candidates.where("device_id", "=", required(subject.deviceId));
120
+ if (level === "root")
121
+ candidates = candidates.where("root_conversation_id", "=", required(subject.rootConversationId));
122
+ for (const row of await candidates.forUpdate().execute()) {
123
+ if (typeof revoke === "function" && !revoke(row.scope, row))
124
+ continue;
125
+ await this.db
126
+ .updateTable("sandbox_operation_intents")
127
+ .set({
128
+ state: "revoked",
129
+ outcome_unknown: row.state !== "admitted",
130
+ updated_at: new Date(),
131
+ })
132
+ .where("operation_id", "=", row.operation_id)
133
+ .execute();
134
+ if (row.state === "background-running")
135
+ await this.db
136
+ .updateTable("background_tasks")
137
+ .set({ launch_state: "cancel-pending", cancel_requested_at: new Date() })
138
+ .where("operation_id", "=", row.operation_id)
139
+ .where("launch_state", "=", "acknowledged")
140
+ .execute();
141
+ await this.outbox.add({
142
+ queue: "cap-kernel-maintenance",
143
+ name: "sandbox-operation-revoke",
144
+ jobId: `sandbox-operation-revoke-${row.operation_id}`,
145
+ data: { operationId: row.operation_id },
146
+ });
147
+ }
148
+ }
149
+ async resetRoot(root, subject, level) {
150
+ const revision = root.permission_revision + 1;
151
+ await this.db
152
+ .updateTable("conversations")
153
+ .set({
154
+ permission_profile: "approve-for-me",
155
+ permission_consent: null,
156
+ permission_revision: revision,
157
+ })
158
+ .where("id", "=", root.id)
159
+ .execute();
160
+ await this.transitions.recordLocked({
161
+ orgId: root.org_id,
162
+ rootConversationId: root.id,
163
+ deviceId: root.device_id,
164
+ oldProfile: "full-access",
165
+ newProfile: "approve-for-me",
166
+ revision,
167
+ scopeRevision: null,
168
+ actorAccountId: null,
169
+ reason: "authority-changed",
170
+ }, { subject, level });
171
+ }
172
+ };
173
+ __decorate([
174
+ Transactional({ propagation: "mandatory" })
175
+ ], PermissionCeilingWrites.prototype, "lock", null);
176
+ __decorate([
177
+ Transactional({ propagation: "mandatory" })
178
+ ], PermissionCeilingWrites.prototype, "invalidateDeviceConsentUnderPlatform", null);
179
+ __decorate([
180
+ Transactional({ propagation: "mandatory" })
181
+ ], PermissionCeilingWrites.prototype, "publishLocked", null);
182
+ PermissionCeilingWrites = __decorate([
183
+ Injectable(),
184
+ __param(0, Inject(PermissionTransitions)),
185
+ __param(1, Inject(KernelDb)),
186
+ __param(2, Inject(TransactionHost)),
187
+ __param(3, Inject(PermissionAuthorityLock)),
188
+ __param(4, Inject(PermissionAuthorityEpochStore)),
189
+ __param(5, Inject(OutboxService))
190
+ ], PermissionCeilingWrites);
191
+ export { PermissionCeilingWrites };
192
+ /**
193
+ * The active local machines' reported roots by device (one org, or all): what the Full-off writers
194
+ * compare running restricted scopes against (B2 reach narrowing). Cloud devices have none.
195
+ */
196
+ export async function localMachineRoots(db, orgId) {
197
+ let q = db
198
+ .selectFrom("device_machines")
199
+ .select(["device_id", "roots"])
200
+ .where("revoked_at", "is", null);
201
+ if (orgId !== undefined)
202
+ q = q.where("org_id", "=", orgId);
203
+ const rows = await q.execute();
204
+ return new Map(rows.map((r) => [r.device_id, machineRootList(r.roots)]));
205
+ }
206
+ /**
207
+ * What a platform or org Full ceiling turning off takes away (B2, same split as the owner writer):
208
+ * Full execution, broad browsing, and running restricted work outside the machine's roots, since
209
+ * the effective restricted reach narrows to the workspace.
210
+ */
211
+ export const needsWiderDeviceCeiling = (scope, machineRoots) => needsFullCeiling(scope) || outsideMachineRoots(scope, machineRoots);
212
+ /** Full execution: a Full-profile operation (B2: decided by Full permission alone). */
213
+ export const requiresFullExecution = (scope) => "profile" in scope && scope.profile === "full-access";
214
+ /**
215
+ * Broad project reach: owner browsing outside the restricted workspace (B2: decided by the reach
216
+ * and the platform/org device ceiling, never by the owner's Full permission).
217
+ */
218
+ export const requiresBroadProjectReach = (scope) => !("profile" in scope) && scope.readRoots.includes("/");
219
+ /**
220
+ * What a platform or org Full ceiling turning off takes away: Full execution and, as before, the
221
+ * wider device ceiling restricted reach depended on.
222
+ */
223
+ export const needsFullCeiling = (scope) => requiresFullExecution(scope) || requiresBroadProjectReach(scope);
@@ -0,0 +1,76 @@
1
+ import { z } from "zod";
2
+ import type { KernelConfig } from "../config/schema.js";
3
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
+ import { KernelDb } from "../infra/database/kernel-db.js";
5
+ import { TransactionHost } from "../infra/database/transaction-host.js";
6
+ import type { KernelLogger } from "../log.js";
7
+ import { PermissionCeilingWrites } from "./permission-ceiling-writes.js";
8
+ declare const ProjectionSchema: z.ZodObject<{
9
+ version: z.ZodLiteral<2>;
10
+ fullAccess: z.ZodDiscriminatedUnion<[z.ZodObject<{
11
+ kind: z.ZodLiteral<"deployment-setting">;
12
+ }, z.core.$strict>, z.ZodObject<{
13
+ kind: z.ZodLiteral<"configured">;
14
+ value: z.ZodEnum<{
15
+ allowed: "allowed";
16
+ off: "off";
17
+ }>;
18
+ }, z.core.$strict>], "kind">;
19
+ egress: z.ZodEnum<{
20
+ allowlist: "allowlist";
21
+ none: "none";
22
+ }>;
23
+ orgHosts: z.ZodEnum<{
24
+ extend: "extend";
25
+ within: "within";
26
+ }>;
27
+ allowHosts: z.ZodArray<z.ZodString>;
28
+ }, z.core.$strict>;
29
+ export type PermissionConfigProjection = z.infer<typeof ProjectionSchema>;
30
+ /** Validated nonsecret winning config inputs; PG fallback is read separately under the writer lock. */
31
+ export declare function parsePermissionConfigProjection(input: unknown): PermissionConfigProjection;
32
+ export declare function permissionConfigProjection(config: KernelConfig): PermissionConfigProjection;
33
+ export declare function permissionProjectionFingerprint(projection: PermissionConfigProjection): string;
34
+ /** Only independent platform permission inputs, never resource sizing, secrets or resolved PG fallback. */
35
+ export declare function permissionConfigFingerprint(config: KernelConfig): string;
36
+ export type PermissionConfigInitialization = {
37
+ outcome: "initialized" | "matching" | "already-active" | "activated" | "migrated";
38
+ activeHash: string;
39
+ } | {
40
+ outcome: "mismatch";
41
+ activeHash: string;
42
+ candidateHash: string;
43
+ };
44
+ export interface PermissionConfigInitializeOptions {
45
+ activation?: Readonly<{
46
+ expectedActiveHash: string;
47
+ }>;
48
+ startup?: {
49
+ signal: AbortSignal;
50
+ remainingMs: () => number;
51
+ };
52
+ }
53
+ export declare function validatePermissionConfigActivation(activation: unknown): void;
54
+ export declare class PermissionConfigActivationConflict extends Error {
55
+ constructor(activeHash: string | undefined, candidateHash: string);
56
+ }
57
+ export declare class PermissionConfigPublication {
58
+ private readonly db;
59
+ readonly txHost: TransactionHost;
60
+ private readonly config;
61
+ private readonly ceilings;
62
+ private readonly log?;
63
+ constructor(db: KernelDb, txHost: TransactionHost, config: KernelConfigService, ceilings: PermissionCeilingWrites, log?: Pick<KernelLogger, "warn"> | undefined);
64
+ /** Capture the actual validated startup projection once, before waiting for authority. */
65
+ initialize(options?: PermissionConfigInitializeOptions): Promise<PermissionConfigInitialization>;
66
+ private initializeLocked;
67
+ /** CAS publication precedes exposing the new local config. Same-next replicas converge idempotently. */
68
+ publish(before: KernelConfig, next: KernelConfig): Promise<void>;
69
+ /** Validates the stored publication with the algorithm of its own version. */
70
+ private validateStored;
71
+ /** Compare-and-set of the publication row; the caller holds the platform write lock. */
72
+ private replaceLocked;
73
+ private publishLocked;
74
+ assertCurrent(): Promise<void>;
75
+ }
76
+ export {};
@@ -0,0 +1,339 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { createHash } from "node:crypto";
11
+ import { SandboxScopeDeniedError, validateAllowHost } from "@capybara-hq/plugin-sdk";
12
+ import { Inject, Injectable, Optional } from "@nestjs/common";
13
+ import { z } from "zod";
14
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
15
+ import { KernelDb } from "../infra/database/kernel-db.js";
16
+ import { TransactionHost } from "../infra/database/transaction-host.js";
17
+ import { Transactional } from "../infra/database/transactional.decorator.js";
18
+ import { KERNEL_LOGGER } from "../infra/tokens.js";
19
+ import { CloudNetworkSettingSchema, invalidCloudNetwork } from "../orgs/cloud-network-setting.js";
20
+ import { coversHost, orgEffectiveHosts } from "./modes.js";
21
+ import { isExecutionMethod } from "./operation-authority-types.js";
22
+ import { localMachineRoots, needsFullCeiling, needsWiderDeviceCeiling, PermissionCeilingWrites, } from "./permission-ceiling-writes.js";
23
+ import { convertStoredPermissionKeys, lockOrgsWithStoredPermissionKeys, readStoredDevicesFullAccess, resolveDevicesFullAccess, } from "./platform-full-access.js";
24
+ const FullAccessSource = z.discriminatedUnion("kind", [
25
+ z.object({ kind: z.literal("deployment-setting") }).strict(),
26
+ z.object({ kind: z.literal("configured"), value: z.enum(["allowed", "off"]) }).strict(),
27
+ ]);
28
+ const AllowHosts = z
29
+ .array(z
30
+ .string()
31
+ .max(253)
32
+ .refine((host) => validateAllowHost(host).length === 0))
33
+ .max(4096);
34
+ const ProjectionSchema = z
35
+ .object({
36
+ version: z.literal(2),
37
+ fullAccess: FullAccessSource,
38
+ egress: z.enum(["none", "allowlist"]),
39
+ orgHosts: z.enum(["extend", "within"]),
40
+ allowHosts: AllowHosts,
41
+ })
42
+ .strict();
43
+ /**
44
+ * The 6c projection released replicas published (version 1, no version field). It is read only to
45
+ * convert it (B1): validated with its own canonical algorithm and exact fingerprint, never
46
+ * published again.
47
+ */
48
+ const LegacyProjectionSchema = z
49
+ .object({
50
+ autoMode: FullAccessSource,
51
+ egress: z.enum(["none", "allowlist"]),
52
+ orgHosts: z.enum(["extend", "within"]),
53
+ allowHosts: AllowHosts,
54
+ })
55
+ .strict();
56
+ const bounded = (projection) => {
57
+ if (Buffer.byteLength(JSON.stringify(projection)) > 65536)
58
+ throw new SandboxScopeDeniedError("Permission configuration projection exceeds 64 KiB");
59
+ return projection;
60
+ };
61
+ /** Validated nonsecret winning config inputs; PG fallback is read separately under the writer lock. */
62
+ export function parsePermissionConfigProjection(input) {
63
+ const parsed = ProjectionSchema.parse(input);
64
+ // the fixed property order is the canonical form the fingerprint hashes
65
+ return bounded({
66
+ version: 2,
67
+ fullAccess: parsed.fullAccess,
68
+ egress: parsed.egress,
69
+ orgHosts: parsed.orgHosts,
70
+ allowHosts: [...new Set(parsed.allowHosts)].sort(),
71
+ });
72
+ }
73
+ function parseLegacyProjection(input) {
74
+ const parsed = LegacyProjectionSchema.parse(input);
75
+ return bounded({
76
+ autoMode: parsed.autoMode,
77
+ egress: parsed.egress,
78
+ orgHosts: parsed.orgHosts,
79
+ allowHosts: [...new Set(parsed.allowHosts)].sort(),
80
+ });
81
+ }
82
+ /** The version 2 projection that says exactly what a version 1 projection said. */
83
+ const ofLegacy = (p) => ({
84
+ version: 2,
85
+ fullAccess: p.autoMode,
86
+ egress: p.egress,
87
+ orgHosts: p.orgHosts,
88
+ allowHosts: p.allowHosts,
89
+ });
90
+ export function permissionConfigProjection(config) {
91
+ const { egress, orgHosts, allowHosts } = config.sandbox.limits;
92
+ return parsePermissionConfigProjection({
93
+ version: 2,
94
+ fullAccess: config.devices.fullAccess === undefined
95
+ ? { kind: "deployment-setting" }
96
+ : { kind: "configured", value: config.devices.fullAccess },
97
+ egress,
98
+ orgHosts,
99
+ allowHosts,
100
+ });
101
+ }
102
+ const sha256 = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
103
+ export function permissionProjectionFingerprint(projection) {
104
+ return sha256(parsePermissionConfigProjection(projection));
105
+ }
106
+ /** Only independent platform permission inputs, never resource sizing, secrets or resolved PG fallback. */
107
+ export function permissionConfigFingerprint(config) {
108
+ return permissionProjectionFingerprint(permissionConfigProjection(config));
109
+ }
110
+ export function validatePermissionConfigActivation(activation) {
111
+ if (activation === undefined)
112
+ return;
113
+ if (activation === null ||
114
+ typeof activation !== "object" ||
115
+ !("expectedActiveHash" in activation) ||
116
+ typeof activation.expectedActiveHash !== "string" ||
117
+ !/^[a-f0-9]{64}$/.test(activation.expectedActiveHash))
118
+ throw new Error("Permission configuration activation requires a lowercase 64-hex active hash");
119
+ }
120
+ export class PermissionConfigActivationConflict extends Error {
121
+ constructor(activeHash, candidateHash) {
122
+ super(activeHash === undefined
123
+ ? "Permission configuration is not initialized; run the first startup normally without --activate-permission-config"
124
+ : `Permission configuration differs from the active deployment configuration. active=${activeHash}; candidate=${candidateHash}. To intentionally activate this resolved startup configuration, run: capybara start --activate-permission-config ${activeHash}`);
125
+ this.name = "PermissionConfigActivationConflict";
126
+ }
127
+ }
128
+ let PermissionConfigPublication = class PermissionConfigPublication {
129
+ db;
130
+ txHost;
131
+ config;
132
+ ceilings;
133
+ log;
134
+ constructor(db, txHost, config, ceilings, log) {
135
+ this.db = db;
136
+ this.txHost = txHost;
137
+ this.config = config;
138
+ this.ceilings = ceilings;
139
+ this.log = log;
140
+ }
141
+ /** Capture the actual validated startup projection once, before waiting for authority. */
142
+ async initialize(options = {}) {
143
+ validatePermissionConfigActivation(options.activation);
144
+ const projection = permissionConfigProjection(this.config.get());
145
+ const initialize = () => this.initializeLocked(projection, options.activation);
146
+ if (options.startup) {
147
+ const { url, connectTimeoutMs } = this.config.get().db;
148
+ return this.txHost.runStartupActivation(initialize, {
149
+ connectionString: url,
150
+ connectTimeoutMs,
151
+ ...options.startup,
152
+ });
153
+ }
154
+ return this.txHost.run(initialize, { propagation: "requires_new" });
155
+ }
156
+ async initializeLocked(projection, activation) {
157
+ // the org rows a key conversion writes, before the platform lock (org row -> permission locks)
158
+ await lockOrgsWithStoredPermissionKeys(this.db.db);
159
+ await this.ceilings.lock({}, "platform");
160
+ const candidateHash = permissionProjectionFingerprint(projection);
161
+ const row = await this.db
162
+ .selectFrom("permission_config_publication")
163
+ .select(["fingerprint", "projection"])
164
+ .where("id", "=", "platform")
165
+ .executeTakeFirst();
166
+ if (activation) {
167
+ if (!row)
168
+ throw new PermissionConfigActivationConflict(undefined, candidateHash);
169
+ const outcome = await this.publishLocked(activation.expectedActiveHash, projection);
170
+ return {
171
+ outcome: outcome === "matching" ? "already-active" : "activated",
172
+ activeHash: candidateHash,
173
+ };
174
+ }
175
+ if (row) {
176
+ const stored = this.validateStored(row);
177
+ if (row.fingerprint === candidateHash)
178
+ return { outcome: "matching", activeHash: candidateHash };
179
+ // B1: a released version 1 publication that says exactly what this replica says converts
180
+ // in place (format only: no epoch, no Full reset, no revocation)
181
+ if (stored.legacy && permissionProjectionFingerprint(stored.projection) === candidateHash) {
182
+ await this.replaceLocked(row.fingerprint, projection);
183
+ await convertStoredPermissionKeys(this.db.db, this.log);
184
+ return { outcome: "migrated", activeHash: candidateHash };
185
+ }
186
+ return { outcome: "mismatch", activeHash: row.fingerprint, candidateHash };
187
+ }
188
+ await this.db
189
+ .insertInto("permission_config_publication")
190
+ .values({
191
+ id: "platform",
192
+ fingerprint: candidateHash,
193
+ projection: JSON.stringify(projection),
194
+ })
195
+ .onConflict((oc) => oc.column("id").doNothing())
196
+ .execute();
197
+ const inserted = await this.db
198
+ .selectFrom("permission_config_publication")
199
+ .select("fingerprint")
200
+ .where("id", "=", "platform")
201
+ .executeTakeFirstOrThrow();
202
+ if (inserted.fingerprint !== candidateHash)
203
+ return { outcome: "mismatch", activeHash: inserted.fingerprint, candidateHash };
204
+ await convertStoredPermissionKeys(this.db.db, this.log);
205
+ return { outcome: "initialized", activeHash: candidateHash };
206
+ }
207
+ /** CAS publication precedes exposing the new local config. Same-next replicas converge idempotently. */
208
+ async publish(before, next) {
209
+ await lockOrgsWithStoredPermissionKeys(this.db.db);
210
+ await this.ceilings.lock({}, "platform");
211
+ try {
212
+ await this.publishLocked(permissionConfigFingerprint(before), permissionConfigProjection(next));
213
+ }
214
+ catch (error) {
215
+ if (error instanceof PermissionConfigActivationConflict)
216
+ throw new SandboxScopeDeniedError("Permission configuration changed on another replica; wait for its current source revision");
217
+ throw error;
218
+ }
219
+ }
220
+ /** Validates the stored publication with the algorithm of its own version. */
221
+ validateStored(row) {
222
+ const corrupt = () => new SandboxScopeDeniedError("Published permission projection does not match its fingerprint");
223
+ const raw = row.projection;
224
+ if (raw !== null && typeof raw === "object" && "version" in raw) {
225
+ const projection = parsePermissionConfigProjection(raw);
226
+ if (permissionProjectionFingerprint(projection) !== row.fingerprint)
227
+ throw corrupt();
228
+ return { fingerprint: row.fingerprint, projection, legacy: false };
229
+ }
230
+ const legacy = parseLegacyProjection(raw);
231
+ if (sha256(legacy) !== row.fingerprint)
232
+ throw corrupt();
233
+ return { fingerprint: row.fingerprint, projection: ofLegacy(legacy), legacy: true };
234
+ }
235
+ /** Compare-and-set of the publication row; the caller holds the platform write lock. */
236
+ async replaceLocked(previous, next) {
237
+ const fingerprint = permissionProjectionFingerprint(next);
238
+ const changed = await this.db
239
+ .updateTable("permission_config_publication")
240
+ .set({ fingerprint, projection: JSON.stringify(next), updated_at: new Date() })
241
+ .where("id", "=", "platform")
242
+ .where("fingerprint", "=", previous)
243
+ .executeTakeFirstOrThrow();
244
+ if (changed.numUpdatedRows !== 1n)
245
+ throw new PermissionConfigActivationConflict(previous, fingerprint);
246
+ }
247
+ async publishLocked(previous, next) {
248
+ const fingerprint = permissionProjectionFingerprint(next);
249
+ const row = await this.db
250
+ .selectFrom("permission_config_publication")
251
+ .select(["fingerprint", "projection"])
252
+ .where("id", "=", "platform")
253
+ .executeTakeFirst();
254
+ if (!row)
255
+ throw new PermissionConfigActivationConflict(undefined, fingerprint);
256
+ const stored = this.validateStored(row);
257
+ const before = stored.projection;
258
+ if (row.fingerprint === fingerprint)
259
+ return "matching";
260
+ if (row.fingerprint !== previous)
261
+ throw new PermissionConfigActivationConflict(row.fingerprint, fingerprint);
262
+ await this.replaceLocked(previous, next);
263
+ // a version 1 predecessor converts its stored keys in this same transaction (B1)
264
+ if (stored.legacy)
265
+ await convertStoredPermissionKeys(this.db.db, this.log);
266
+ // format only: the same semantics publish the new fingerprint (the barrier) and nothing else
267
+ if (permissionProjectionFingerprint(before) === fingerprint)
268
+ return "activated";
269
+ const storedChoice = await readStoredDevicesFullAccess(this.db.db, this.log);
270
+ const effective = (projection) => resolveDevicesFullAccess(projection.fullAccess.kind === "configured" ? projection.fullAccess.value : undefined, projection.fullAccess.kind === "configured" ? "file" : undefined, storedChoice).permission;
271
+ const beforeMode = effective(before), nextMode = effective(next);
272
+ const orgs = await this.db.selectFrom("orgs").select(["id", "settings"]).execute();
273
+ const settings = new Map(orgs.map((org) => {
274
+ const raw = org.settings?.cloudNetwork;
275
+ const parsed = CloudNetworkSettingSchema.safeParse(raw);
276
+ return [
277
+ org.id,
278
+ raw === undefined ? undefined : parsed.success ? parsed.data : invalidCloudNetwork(),
279
+ ];
280
+ }));
281
+ const devices = await this.db.selectFrom("devices").select(["id", "source"]).execute();
282
+ const machineRoots = await localMachineRoots(this.db.db);
283
+ const sources = new Map(devices.map((device) => [device.id, device.source]));
284
+ if (before.egress !== next.egress)
285
+ await this.ceilings.invalidateDeviceConsentUnderPlatform(devices.filter((device) => device.source === "cloud").map((device) => device.id));
286
+ await this.ceilings.publishLocked({}, "platform", (scope, row) => {
287
+ // Full off also narrows restricted reach to the workspace (B2): running restricted work
288
+ // outside a machine's roots goes with Full work, as the owner writer decides
289
+ if (nextMode === "off" && needsWiderDeviceCeiling(scope, machineRoots.get(row.device_id)))
290
+ return true;
291
+ if (needsFullCeiling(scope))
292
+ return (nextMode === "off" ||
293
+ (sources.get(row.device_id) === "cloud" &&
294
+ before.egress !== "none" &&
295
+ next.egress === "none"));
296
+ if (!isExecutionMethod(row.method) ||
297
+ !("network" in scope) ||
298
+ scope.network.kind !== "allowlist")
299
+ return false;
300
+ const hosts = orgEffectiveHosts(next, settings.get(row.org_id));
301
+ return scope.network.hosts.some((host) => !hosts.some((pattern) => coversHost(pattern, host)) &&
302
+ !(next.egress !== "none" &&
303
+ next.orgHosts !== "within" &&
304
+ row.granted_hosts.includes(host)));
305
+ }, beforeMode !== nextMode);
306
+ return "activated";
307
+ }
308
+ async assertCurrent() {
309
+ const row = await this.db
310
+ .selectFrom("permission_config_publication")
311
+ .select("fingerprint")
312
+ .where("id", "=", "platform")
313
+ .executeTakeFirst();
314
+ if (!row || row.fingerprint !== permissionConfigFingerprint(this.config.get()))
315
+ throw new SandboxScopeDeniedError("This replica has not applied the current permission configuration");
316
+ }
317
+ };
318
+ __decorate([
319
+ Transactional({ propagation: "mandatory" })
320
+ ], PermissionConfigPublication.prototype, "initializeLocked", null);
321
+ __decorate([
322
+ Transactional({ propagation: "requires_new" })
323
+ ], PermissionConfigPublication.prototype, "publish", null);
324
+ __decorate([
325
+ Transactional({ propagation: "mandatory" })
326
+ ], PermissionConfigPublication.prototype, "replaceLocked", null);
327
+ __decorate([
328
+ Transactional({ propagation: "mandatory" })
329
+ ], PermissionConfigPublication.prototype, "publishLocked", null);
330
+ PermissionConfigPublication = __decorate([
331
+ Injectable(),
332
+ __param(0, Inject(KernelDb)),
333
+ __param(1, Inject(TransactionHost)),
334
+ __param(2, Inject(KernelConfigService)),
335
+ __param(3, Inject(PermissionCeilingWrites)),
336
+ __param(4, Optional()),
337
+ __param(4, Inject(KERNEL_LOGGER))
338
+ ], PermissionConfigPublication);
339
+ export { PermissionConfigPublication };