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

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 (359) 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 +4 -1
  38. package/dist/config/schema.js +41 -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 +307 -4
  47. package/dist/conversations/events.js +286 -32
  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/ctx/create-ctx.d.ts +12 -5
  59. package/dist/ctx/create-ctx.js +21 -5
  60. package/dist/db/kernel-schema.d.ts +248 -3
  61. package/dist/devices/access.js +1 -1
  62. package/dist/devices/access.module.d.ts +2 -0
  63. package/dist/devices/access.module.js +19 -0
  64. package/dist/devices/conversation-devices.d.ts +8 -29
  65. package/dist/devices/conversation-devices.js +37 -73
  66. package/dist/devices/device-projects.service.d.ts +26 -28
  67. package/dist/devices/device-projects.service.js +123 -127
  68. package/dist/devices/devices.controller.js +3 -1
  69. package/dist/devices/devices.module.js +11 -9
  70. package/dist/devices/devices.service.d.ts +116 -8
  71. package/dist/devices/devices.service.js +252 -20
  72. package/dist/devices/dto.d.ts +16 -0
  73. package/dist/devices/dto.js +34 -6
  74. package/dist/devices/errors.d.ts +8 -0
  75. package/dist/devices/errors.js +10 -0
  76. package/dist/devices/project-rules.d.ts +44 -0
  77. package/dist/devices/project-rules.js +27 -0
  78. package/dist/devices/working-root.d.ts +6 -0
  79. package/dist/devices/working-root.js +12 -1
  80. package/dist/errors.d.ts +31 -0
  81. package/dist/errors.js +31 -0
  82. package/dist/evals/reconstruct.d.ts +19 -2
  83. package/dist/evals/reconstruct.js +40 -2
  84. package/dist/evals/recorded-permission-context.d.ts +77 -0
  85. package/dist/evals/recorded-permission-context.js +151 -0
  86. package/dist/evals/recorded-tools.d.ts +10 -1
  87. package/dist/evals/recorded-tools.js +27 -3
  88. package/dist/evals/run-replay.d.ts +8 -2
  89. package/dist/evals/run-replay.js +18 -2
  90. package/dist/evals/trajectory.d.ts +1 -1
  91. package/dist/evals/worker.d.ts +10 -1
  92. package/dist/evals/worker.js +23 -14
  93. package/dist/extensions/host.d.ts +4 -1
  94. package/dist/extensions/host.js +10 -6
  95. package/dist/http/api.module.js +2 -0
  96. package/dist/identity/accounts.d.ts +14 -1
  97. package/dist/identity/accounts.js +61 -5
  98. package/dist/identity/identity.module.js +2 -0
  99. package/dist/identity/settings.d.ts +28 -12
  100. package/dist/identity/settings.js +89 -33
  101. package/dist/index.d.ts +6 -0
  102. package/dist/index.js +5 -0
  103. package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
  104. package/dist/infra/cli/kernel-cli.module.js +5 -2
  105. package/dist/infra/cli/permission-cutover.d.ts +59 -0
  106. package/dist/infra/cli/permission-cutover.js +107 -0
  107. package/dist/infra/config/kernel-config.service.d.ts +2 -2
  108. package/dist/infra/config/kernel-config.service.js +35 -11
  109. package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
  110. package/dist/infra/database/startup-activation-transaction.js +242 -0
  111. package/dist/infra/database/transaction-host.d.ts +47 -0
  112. package/dist/infra/database/transaction-host.js +119 -0
  113. package/dist/infra/database/xact-lock.d.ts +1 -0
  114. package/dist/infra/database/xact-lock.js +6 -0
  115. package/dist/infra/outbox/registry.d.ts +39 -0
  116. package/dist/infra/outbox/registry.js +18 -0
  117. package/dist/kernel.module.js +2 -0
  118. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  119. package/dist/lifecycle/kernel-lifecycle.js +55 -28
  120. package/dist/local-devices/device-auth.js +1 -1
  121. package/dist/local-devices/device-policy.service.d.ts +35 -5
  122. package/dist/local-devices/device-policy.service.js +188 -13
  123. package/dist/local-devices/instance-bindings.d.ts +82 -0
  124. package/dist/local-devices/instance-bindings.js +304 -0
  125. package/dist/local-devices/keys.d.ts +5 -0
  126. package/dist/local-devices/keys.js +5 -0
  127. package/dist/local-devices/local-device-gateway.d.ts +19 -4
  128. package/dist/local-devices/local-device-gateway.js +185 -17
  129. package/dist/local-devices/local-device-provider.d.ts +42 -7
  130. package/dist/local-devices/local-device-provider.js +185 -10
  131. package/dist/local-devices/local-devices.module.d.ts +17 -2
  132. package/dist/local-devices/local-devices.module.js +49 -8
  133. package/dist/local-devices/machines.d.ts +35 -12
  134. package/dist/local-devices/machines.js +203 -8
  135. package/dist/local-devices/network-grants.js +3 -3
  136. package/dist/local-devices/network-grants.module.d.ts +2 -0
  137. package/dist/local-devices/network-grants.module.js +14 -0
  138. package/dist/local-devices/owner-report.d.ts +79 -0
  139. package/dist/local-devices/owner-report.js +155 -0
  140. package/dist/local-devices/owner-reports.d.ts +48 -0
  141. package/dist/local-devices/owner-reports.js +190 -0
  142. package/dist/local-devices/policy-summary.d.ts +24 -1
  143. package/dist/local-devices/policy-summary.js +48 -0
  144. package/dist/local-devices/relay.d.ts +82 -6
  145. package/dist/local-devices/relay.js +187 -16
  146. package/dist/local-devices/targets.d.ts +16 -1
  147. package/dist/local-devices/targets.js +35 -2
  148. package/dist/models/image-usable.d.ts +22 -0
  149. package/dist/models/image-usable.js +29 -0
  150. package/dist/models/images.d.ts +125 -0
  151. package/dist/models/images.js +440 -0
  152. package/dist/models/models.module.d.ts +3 -2
  153. package/dist/models/models.module.js +16 -5
  154. package/dist/models/org-models.schemas.js +1 -0
  155. package/dist/models/purposes.controller.d.ts +7 -0
  156. package/dist/models/purposes.controller.js +9 -0
  157. package/dist/models/purposes.d.ts +28 -3
  158. package/dist/models/purposes.js +40 -13
  159. package/dist/orgs/cloud-network-setting.d.ts +33 -0
  160. package/dist/orgs/cloud-network-setting.js +47 -0
  161. package/dist/orgs/offboarding.d.ts +3 -1
  162. package/dist/orgs/offboarding.js +8 -2
  163. package/dist/orgs/org-lock.d.ts +10 -4
  164. package/dist/orgs/org-lock.js +10 -4
  165. package/dist/orgs/orgs.service.d.ts +3 -1
  166. package/dist/orgs/orgs.service.js +8 -2
  167. package/dist/orgs/settings.controller.d.ts +4 -1
  168. package/dist/orgs/settings.controller.js +3 -3
  169. package/dist/orgs/settings.service.d.ts +48 -56
  170. package/dist/orgs/settings.service.js +144 -101
  171. package/dist/overrides.d.ts +6 -1
  172. package/dist/overrides.js +2 -0
  173. package/dist/platform/exclusions.js +20 -0
  174. package/dist/platform/ops/admin.ops.js +14 -11
  175. package/dist/platform/ops/agent-skills.ops.js +2 -0
  176. package/dist/platform/ops/devices.ops.js +10 -2
  177. package/dist/platform/ops/models.ops.js +10 -0
  178. package/dist/platform/ops/org-settings.ops.js +6 -6
  179. package/dist/platform/ops/orgs.ops.js +1 -0
  180. package/dist/roles/worker.module.js +4 -0
  181. package/dist/runtime/context/build.d.ts +3 -1
  182. package/dist/runtime/context/build.js +19 -3
  183. package/dist/runtime/context/compaction.js +5 -0
  184. package/dist/runtime/context/device-paths.d.ts +9 -2
  185. package/dist/runtime/context/device-paths.js +20 -0
  186. package/dist/runtime/context/permission-profile.d.ts +46 -0
  187. package/dist/runtime/context/permission-profile.js +194 -0
  188. package/dist/runtime/hook-calls.d.ts +11 -1
  189. package/dist/runtime/hook-calls.js +24 -1
  190. package/dist/runtime/maintenance.d.ts +7 -1
  191. package/dist/runtime/maintenance.js +43 -15
  192. package/dist/runtime/model-call.d.ts +32 -0
  193. package/dist/runtime/model-call.js +67 -0
  194. package/dist/runtime/permission-context-errors.d.ts +39 -0
  195. package/dist/runtime/permission-context-errors.js +67 -0
  196. package/dist/runtime/permission-context.service.d.ts +60 -0
  197. package/dist/runtime/permission-context.service.js +286 -0
  198. package/dist/runtime/project/knowledge.d.ts +7 -2
  199. package/dist/runtime/project/knowledge.js +5 -2
  200. package/dist/runtime/project/knowledge.service.d.ts +17 -2
  201. package/dist/runtime/project/knowledge.service.js +76 -12
  202. package/dist/runtime/providers.d.ts +9 -5
  203. package/dist/runtime/providers.js +22 -3
  204. package/dist/runtime/run-execution.d.ts +4 -1
  205. package/dist/runtime/run-execution.js +14 -5
  206. package/dist/runtime/run-steps.d.ts +11 -3
  207. package/dist/runtime/run-steps.js +27 -4
  208. package/dist/runtime/runtime.module.js +11 -0
  209. package/dist/runtime/usage-report.d.ts +10 -6
  210. package/dist/runtime/usage-report.js +31 -11
  211. package/dist/sandbox/attachments-path.d.ts +15 -0
  212. package/dist/sandbox/attachments-path.js +15 -0
  213. package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
  214. package/dist/sandbox/cloud-permission-snapshot.js +407 -0
  215. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
  216. package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
  217. package/dist/sandbox/held-operations.d.ts +39 -0
  218. package/dist/sandbox/held-operations.js +119 -0
  219. package/dist/sandbox/jobs.d.ts +14 -3
  220. package/dist/sandbox/jobs.js +20 -2
  221. package/dist/sandbox/kernel-read.d.ts +55 -0
  222. package/dist/sandbox/kernel-read.js +57 -0
  223. package/dist/sandbox/legacy-retirement.d.ts +336 -0
  224. package/dist/sandbox/legacy-retirement.js +1063 -0
  225. package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
  226. package/dist/sandbox/legacy-retirement.module.js +25 -0
  227. package/dist/sandbox/managed-device-context.d.ts +94 -0
  228. package/dist/sandbox/managed-device-context.js +308 -0
  229. package/dist/sandbox/managed-device-context.module.d.ts +6 -0
  230. package/dist/sandbox/managed-device-context.module.js +33 -0
  231. package/dist/sandbox/modes.d.ts +56 -8
  232. package/dist/sandbox/modes.js +92 -8
  233. package/dist/sandbox/operation-authority-types.d.ts +8 -0
  234. package/dist/sandbox/operation-authority-types.js +32 -0
  235. package/dist/sandbox/operation-authority.d.ts +145 -0
  236. package/dist/sandbox/operation-authority.js +783 -0
  237. package/dist/sandbox/operation-authority.module.d.ts +2 -0
  238. package/dist/sandbox/operation-authority.module.js +29 -0
  239. package/dist/sandbox/operation-intents.d.ts +206 -0
  240. package/dist/sandbox/operation-intents.js +1252 -0
  241. package/dist/sandbox/operation-intents.module.d.ts +2 -0
  242. package/dist/sandbox/operation-intents.module.js +21 -0
  243. package/dist/sandbox/operation-payloads.d.ts +33 -0
  244. package/dist/sandbox/operation-payloads.js +332 -0
  245. package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
  246. package/dist/sandbox/operation-reconcile.job.js +247 -0
  247. package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
  248. package/dist/sandbox/permission-authority-epochs.js +83 -0
  249. package/dist/sandbox/permission-authority-lock.d.ts +38 -0
  250. package/dist/sandbox/permission-authority-lock.js +147 -0
  251. package/dist/sandbox/permission-authority.module.d.ts +9 -0
  252. package/dist/sandbox/permission-authority.module.js +55 -0
  253. package/dist/sandbox/permission-availability.d.ts +18 -0
  254. package/dist/sandbox/permission-availability.js +19 -0
  255. package/dist/sandbox/permission-call-grants.d.ts +34 -0
  256. package/dist/sandbox/permission-call-grants.js +349 -0
  257. package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
  258. package/dist/sandbox/permission-call-grants.module.js +21 -0
  259. package/dist/sandbox/permission-call-types.d.ts +82 -0
  260. package/dist/sandbox/permission-call-types.js +1 -0
  261. package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
  262. package/dist/sandbox/permission-ceiling-writes.js +223 -0
  263. package/dist/sandbox/permission-config-publication.d.ts +76 -0
  264. package/dist/sandbox/permission-config-publication.js +339 -0
  265. package/dist/sandbox/permission-context-types.d.ts +64 -0
  266. package/dist/sandbox/permission-context-types.js +24 -0
  267. package/dist/sandbox/permission-facts.d.ts +206 -0
  268. package/dist/sandbox/permission-facts.js +627 -0
  269. package/dist/sandbox/permission-facts.module.d.ts +2 -0
  270. package/dist/sandbox/permission-facts.module.js +20 -0
  271. package/dist/sandbox/permission-instance-writes.d.ts +90 -0
  272. package/dist/sandbox/permission-instance-writes.js +305 -0
  273. package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
  274. package/dist/sandbox/permission-runtime-reports.js +354 -0
  275. package/dist/sandbox/permission-transitions.d.ts +31 -0
  276. package/dist/sandbox/permission-transitions.js +155 -0
  277. package/dist/sandbox/platform-full-access.d.ts +128 -0
  278. package/dist/sandbox/platform-full-access.js +210 -0
  279. package/dist/sandbox/providers.d.ts +22 -0
  280. package/dist/sandbox/providers.js +10 -2
  281. package/dist/sandbox/providers.module.d.ts +2 -0
  282. package/dist/sandbox/providers.module.js +19 -0
  283. package/dist/sandbox/request-not-sent.d.ts +13 -0
  284. package/dist/sandbox/request-not-sent.js +13 -0
  285. package/dist/sandbox/review/classifier.d.ts +2 -0
  286. package/dist/sandbox/review/classifier.js +8 -0
  287. package/dist/sandbox/review/permission-candidate.d.ts +12 -0
  288. package/dist/sandbox/review/permission-candidate.js +145 -0
  289. package/dist/sandbox/review/review.service.d.ts +5 -2
  290. package/dist/sandbox/review/review.service.js +60 -15
  291. package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
  292. package/dist/sandbox/sandbox-file-reader.js +51 -7
  293. package/dist/sandbox/sandbox.module.js +26 -6
  294. package/dist/sandbox/sandbox.service.d.ts +230 -34
  295. package/dist/sandbox/sandbox.service.js +1368 -199
  296. package/dist/sandbox/unreachable.js +17 -3
  297. package/dist/sandbox/use-context.d.ts +17 -0
  298. package/dist/sandbox/use-context.js +1 -0
  299. package/dist/skills/invoke.d.ts +27 -4
  300. package/dist/skills/invoke.js +72 -7
  301. package/dist/tools/approvals.controller.d.ts +1 -0
  302. package/dist/tools/approvals.schemas.d.ts +1 -0
  303. package/dist/tools/approvals.schemas.js +3 -1
  304. package/dist/tools/approvals.service.d.ts +23 -10
  305. package/dist/tools/approvals.service.js +104 -26
  306. package/dist/tools/builtin-names.d.ts +3 -1
  307. package/dist/tools/builtin-names.js +5 -1
  308. package/dist/tools/builtins/artifacts.d.ts +43 -0
  309. package/dist/tools/builtins/artifacts.js +67 -0
  310. package/dist/tools/builtins/builtin-tools.d.ts +20 -2
  311. package/dist/tools/builtins/builtin-tools.js +61 -10
  312. package/dist/tools/builtins/image/generate.d.ts +59 -0
  313. package/dist/tools/builtins/image/generate.js +535 -0
  314. package/dist/tools/builtins/image/index.d.ts +2 -0
  315. package/dist/tools/builtins/image/index.js +2 -0
  316. package/dist/tools/builtins/image/paths.d.ts +12 -0
  317. package/dist/tools/builtins/image/paths.js +26 -0
  318. package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
  319. package/dist/tools/builtins/sandbox/bash.js +201 -5
  320. package/dist/tools/builtins/sandbox/common.d.ts +92 -20
  321. package/dist/tools/builtins/sandbox/common.js +201 -17
  322. package/dist/tools/builtins/sandbox/deliver.js +9 -51
  323. package/dist/tools/builtins/sandbox/edit.js +2 -2
  324. package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
  325. package/dist/tools/builtins/sandbox/glob.js +2 -2
  326. package/dist/tools/builtins/sandbox/grep.js +2 -2
  327. package/dist/tools/builtins/sandbox/read.js +2 -2
  328. package/dist/tools/builtins/sandbox/task-list.js +7 -1
  329. package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
  330. package/dist/tools/builtins/sandbox/task-output.js +172 -0
  331. package/dist/tools/builtins/sandbox/task-stop.js +25 -3
  332. package/dist/tools/builtins/sandbox/write.js +2 -2
  333. package/dist/tools/builtins/skill-load.js +9 -6
  334. package/dist/tools/device-op-resolver.d.ts +1 -1
  335. package/dist/tools/device-op-resolver.js +13 -3
  336. package/dist/tools/permission-approval-jobs.d.ts +18 -0
  337. package/dist/tools/permission-approval-jobs.js +92 -0
  338. package/dist/tools/pipeline.d.ts +17 -2
  339. package/dist/tools/pipeline.js +315 -26
  340. package/dist/tools/registry.d.ts +9 -0
  341. package/dist/tools/tools.module.js +15 -0
  342. package/package.json +4 -3
  343. package/src/migrations/0146_permission_authority_epochs.sql +6 -0
  344. package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
  345. package/src/migrations/0148_first_message_request_hash.sql +2 -0
  346. package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
  347. package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
  348. package/src/migrations/0151_starting_execution_grants.sql +8 -0
  349. package/src/migrations/0152_background_launch_identity.sql +66 -0
  350. package/src/migrations/0153_background_cancel_requester.sql +13 -0
  351. package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
  352. package/src/migrations/0155_device_instance_generations.sql +30 -0
  353. package/src/migrations/0156_device_owner_report.sql +7 -0
  354. package/src/migrations/0157_legacy_retirement.sql +116 -0
  355. package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
  356. package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
  357. package/src/migrations/0160_model_usage_image_kind.sql +10 -0
  358. package/dist/sandbox/platform-auto-mode.d.ts +0 -63
  359. package/dist/sandbox/platform-auto-mode.js +0 -63
@@ -7,7 +7,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { validateAllowHost } from "@capybara-hq/plugin-sdk";
11
10
  import { Inject, Injectable, Module, Optional } from "@nestjs/common";
12
11
  import { z } from "zod";
13
12
  import { readPlatformAttribution, } from "../attribution/platform-attribution.js";
@@ -16,14 +15,18 @@ import { audit } from "../identity/audit.js";
16
15
  import { COMPACTION_SETTINGS_PARTIAL, COMPACTION_SETTINGS_PATCH, readPlatformCompactionSettings, readSandboxLimitOverride, } from "../identity/settings.js";
17
16
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
18
17
  import { KernelDb } from "../infra/database/kernel-db.js";
19
- import { TransactionHost } from "../infra/database/transaction-host.js";
18
+ import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
20
19
  import { Transactional } from "../infra/database/transactional.decorator.js";
21
20
  import { KERNEL_LOGGER } from "../infra/tokens.js";
22
21
  import { coversHost, orgCloudMode, orgEffectiveHosts, orgHostOutsideCeiling, } from "../sandbox/modes.js";
23
- import { readDevicesAutoMode, } from "../sandbox/platform-auto-mode.js";
22
+ import { isExecutionMethod } from "../sandbox/operation-authority-types.js";
23
+ import { PermissionAuthorityModule } from "../sandbox/permission-authority.module.js";
24
+ import { localMachineRoots, needsFullCeiling, needsWiderDeviceCeiling, PermissionCeilingWrites, } from "../sandbox/permission-ceiling-writes.js";
25
+ import { legacyAutoModeView, narrowedOrgFullAccess, readDevicesFullAccess, } from "../sandbox/platform-full-access.js";
24
26
  import { assertThemeOnIn } from "../themes/theme-state.js";
25
27
  import { IanaTimeZone } from "../time-zone.js";
26
28
  import { mergeArrangement, OrgUiArrangementPatchSchema, UiArrangementSchema, } from "../ui/arrangement.js";
29
+ import { CloudNetworkSettingSchema, invalidCloudNetwork, } from "./cloud-network-setting.js";
27
30
  import { OrgLock, OrgLockModule } from "./org-lock.js";
28
31
  /**
29
32
  * Org settings (`capybara.orgs.settings` jsonb). Read leniently: a missing or invalid field reads
@@ -38,9 +41,10 @@ import { OrgLock, OrgLockModule } from "./org-lock.js";
38
41
  * execution). An invalid stored value reads as `ask` (narrower, never wider) and is logged.
39
42
  * - `wakeOnBackgroundTask`: the org's override of `runtime.wakeOnBackgroundTask` (absent follows
40
43
  * the deployment), see {@link effectiveWakeOnBackgroundTask}.
41
- * - `autoMode`: whether devices of the org may run in auto mode (auto mode spec §4.3); absent
42
- * follows the platform's `devices.autoMode`, and an invalid stored value reads as `off`
43
- * (narrower, never wider). Setting `allowed` while the platform is `off` is refused.
44
+ * - `fullAccess`: whether devices of the org may run with Full permission (permission runtime
45
+ * cutover B1, replacing `autoMode`); absent follows the platform's `devices.fullAccess`, and an
46
+ * invalid stored value reads as `off` (narrower, never wider). Setting `allowed` while the
47
+ * platform is `off` is refused.
44
48
  * - `cloudNetwork`: the org's sandbox-mode network as a delta over the platform's allowlist (org
45
49
  * egress ceiling spec §D1, {@link CloudNetworkSettingSchema}). An invalid stored value reads as
46
50
  * `{ mode: "allowlist", base: "none" }`, the empty allowlist (narrower, never wider).
@@ -55,56 +59,15 @@ import { OrgLock, OrgLockModule } from "./org-lock.js";
55
59
  * - `gitGateway`: the org's git gateway switch and host sources (sandbox git credentials spec §9);
56
60
  * not in the PATCH yet; an invalid stored value reads as `{ enabled: false }` (fails closed).
57
61
  */
58
- /** The org cloud-network allowlist's host limit. */
59
- export const ORG_SANDBOX_ALLOW_HOSTS_MAX = 200;
60
- /** One host list of the org's cloud network: at most {@link ORG_SANDBOX_ALLOW_HOSTS_MAX} valid, unique hosts. */
61
- const orgHostList = (name) => z
62
- .array(z.string())
63
- .max(ORG_SANDBOX_ALLOW_HOSTS_MAX)
64
- .superRefine((hosts, ctx) => {
65
- hosts.forEach((h, i) => {
66
- for (const message of validateAllowHost(h)) {
67
- ctx.addIssue({ code: "custom", path: [i], message: `${h}: ${message}` });
68
- }
69
- });
70
- if (new Set(hosts).size !== hosts.length) {
71
- ctx.addIssue({ code: "custom", message: `${name} must not contain duplicates` });
72
- }
73
- })
74
- .optional();
75
- /**
76
- * The org's sandbox-mode network (org egress ceiling spec §D1), stored as a delta over the
77
- * platform's `sandbox.limits.allowHosts`, never a copy of it, so platform changes keep reaching the
78
- * org:
79
- * - `mode`: the cloud network of a cloud device in sandbox mode, `open` (any public host; loopback,
80
- * private and cloud metadata addresses are blocked outside the container) or `allowlist`; absent
81
- * follows the platform's default (open). `sandbox.limits.orgHosts: within` makes it the allowlist.
82
- * - `base`: `platform` (the default: start from the platform's list) or `none` (only the org's own
83
- * hosts).
84
- * - `extraHosts`: hosts the org adds (ignored outside the platform list under `within`).
85
- * - `excludedHosts`: platform entries the org drops (exact entries; any host is accepted, since the
86
- * platform may drop an entry later).
87
- * The effective hosts ({@link orgEffectiveHosts} in `sandbox/modes.ts`) are also the ceiling a local
88
- * device in sandbox mode reaches (the device intersects them with its own list).
89
- */
90
- export const CloudNetworkSettingSchema = z
91
- .object({
92
- mode: z.enum(["open", "allowlist"]).optional(),
93
- base: z.enum(["platform", "none"]).optional(),
94
- extraHosts: orgHostList("extraHosts"),
95
- excludedHosts: orgHostList("excludedHosts"),
96
- })
97
- .strict();
98
- /** What an invalid stored `cloudNetwork` reads as: the allowlist with no host (never wider). */
99
- export const invalidCloudNetwork = () => ({
100
- mode: "allowlist",
101
- base: "none",
102
- });
62
+ export { CloudNetworkSettingSchema, invalidCloudNetwork, ORG_SANDBOX_ALLOW_HOSTS_MAX, } from "./cloud-network-setting.js";
103
63
  /**
104
- * The org's auto-mode switch (auto mode spec §4.3): `allowed` or `off`; absent follows the
105
- * platform's `devices.autoMode`. An invalid stored value reads as `off` (narrower, never wider).
64
+ * The org's Full permission switch (B1): `allowed` or `off`; absent follows the platform's
65
+ * `devices.fullAccess`. An invalid stored value reads as `off` (narrower, never wider).
106
66
  */
107
- export const AutoModeSetting = z.enum(["allowed", "off"]);
67
+ export const FullAccessSetting = z.enum([
68
+ "allowed",
69
+ "off",
70
+ ]);
108
71
  /**
109
72
  * The org's theme setting (themes spec §7): `id` a theme on in the org (a `platform_themes` id),
110
73
  * null = follow the platform's default; `personal: "locked"` hides the personal picker in the org
@@ -180,8 +143,8 @@ export const OrgSettingsSchema = z.object({
180
143
  /** Absent = `allow`; an invalid stored value reads as `ask` (narrower, never wider). */
181
144
  sandboxToolPolicy: z.enum(["allow", "ask"]).default("allow").catch("ask"),
182
145
  platformTool: z.enum(["on", "read-only", "off"]).default("on").catch("on"),
183
- /** The org's auto-mode switch (auto mode spec §4.3); absent follows the platform. */
184
- autoMode: AutoModeSetting.optional().catch("off"),
146
+ /** The org's Full permission switch (B1); absent follows the platform. */
147
+ fullAccess: FullAccessSetting.optional().catch("off"),
185
148
  /** The org's network for cloud devices (auto mode spec §4.3); absent = open (the default). */
186
149
  cloudNetwork: CloudNetworkSettingSchema.optional().catch(invalidCloudNetwork),
187
150
  /** Overrides `runtime.wakeOnBackgroundTask`; absent follows the deployment. */
@@ -219,10 +182,12 @@ export const OrgSettingsPatchSchema = z
219
182
  /** null clears (follow the deployment again). */
220
183
  wakeOnBackgroundTask: z.boolean().nullable().optional(),
221
184
  /**
222
- * The org's auto-mode switch; null clears it (follow the platform). `allowed` while the
185
+ * The org's Full permission switch; null clears it (follow the platform). `allowed` while the
223
186
  * platform is `off` -> 400 `org.auto_mode_not_allowed`.
224
187
  */
225
- autoMode: AutoModeSetting.nullable().optional(),
188
+ fullAccess: FullAccessSetting.nullable().optional(),
189
+ /** The old name of `fullAccess`, still accepted (never together with it). */
190
+ autoMode: FullAccessSetting.nullable().optional(),
226
191
  /**
227
192
  * The org's network for cloud devices, replaced whole (hosts left out follow the deployment);
228
193
  * null clears it (open). Through the Platform tool or an API token it may only narrow.
@@ -249,7 +214,26 @@ export const OrgSettingsPatchSchema = z
249
214
  */
250
215
  compaction: COMPACTION_SETTINGS_PATCH.nullable().optional(),
251
216
  })
252
- .strict();
217
+ .strict()
218
+ .refine((p) => p.autoMode === undefined || p.fullAccess === undefined, {
219
+ message: "give fullAccess only: autoMode is its old name",
220
+ path: ["autoMode"],
221
+ });
222
+ /** A patch with the old `autoMode` moved to `fullAccess` (the schema refuses both together). */
223
+ export function normalizeOrgSettingsPatch(patch) {
224
+ if (patch.autoMode === undefined)
225
+ return patch;
226
+ const { autoMode, ...rest } = patch;
227
+ return { ...rest, fullAccess: autoMode };
228
+ }
229
+ /**
230
+ * The settings as the API answers them ({@link OrgSettingsView}), plus the old public name
231
+ * `autoMode` mirroring `fullAccess` until the old public readers are removed.
232
+ */
233
+ export const orgSettingsView = (settings) => ({
234
+ ...settings,
235
+ ...(settings.fullAccess !== undefined && { autoMode: settings.fullAccess }),
236
+ });
253
237
  /** Whether a finished background task wakes an idle conversation: the org's setting, else the deployment's. */
254
238
  export function effectiveWakeOnBackgroundTask(deployment, org) {
255
239
  return org ?? deployment;
@@ -270,9 +254,19 @@ export function effectiveSandboxLimits(deployment, override) {
270
254
  /** Compare by value (`cloudNetwork` is an object); the schema fixes the key order. */
271
255
  const sameSettings = (a, b) => JSON.stringify(OrgSettingsSchema.parse(a)) === JSON.stringify(OrgSettingsSchema.parse(b));
272
256
  const asObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
273
- /** 把存储的 jsonb 解析为设置(宽松,见 {@link OrgSettingsSchema})。 */
257
+ /**
258
+ * Parses the stored jsonb into settings (leniently, see {@link OrgSettingsSchema}). Until 8.6 `fullAccess` is read
259
+ * over both keys, the narrower of it and the old `autoMode` ({@link narrowedOrgFullAccess}).
260
+ */
274
261
  export function parseOrgSettings(raw) {
275
- return OrgSettingsSchema.parse(asObject(raw));
262
+ const stored = asObject(raw);
263
+ const settings = OrgSettingsSchema.parse(stored);
264
+ const fullAccess = narrowedOrgFullAccess(settings.fullAccess, stored.autoMode);
265
+ if (fullAccess === undefined)
266
+ delete settings.fullAccess;
267
+ else
268
+ settings.fullAccess = fullAccess;
269
+ return settings;
276
270
  }
277
271
  /** The org's stored settings jsonb, read live; undefined when the org is missing or deleted. */
278
272
  export async function readStoredOrgSettings(db, orgId) {
@@ -335,10 +329,10 @@ export function logUnreadableSecuritySettings(log, orgId, raw) {
335
329
  }
336
330
  }
337
331
  const autoModeNotAllowed = (message) => new ApiError("org.auto_mode_not_allowed", message);
338
- /** Whether a stored settings object holds an `autoMode` this version reads as `off`. */
339
- export function invalidStoredAutoMode(raw) {
340
- const v = asObject(raw).autoMode;
341
- return v !== undefined && !AutoModeSetting.safeParse(v).success;
332
+ /** Whether a stored settings object holds a `fullAccess` this version reads as `off`. */
333
+ export function invalidStoredFullAccess(raw) {
334
+ const v = asObject(raw).fullAccess;
335
+ return v !== undefined && !FullAccessSetting.safeParse(v).success;
342
336
  }
343
337
  /** Whether a stored settings object holds a `cloudNetwork` this version reads as an empty allowlist. */
344
338
  export function invalidStoredCloudNetwork(raw) {
@@ -373,25 +367,27 @@ let OrgSettingsService = class OrgSettingsService {
373
367
  txHost;
374
368
  orgLock;
375
369
  config;
370
+ ceilings;
376
371
  log;
377
372
  constructor(db, txHost, orgLock,
378
373
  /**
379
- * The deployment config: `sandbox.limits` and the platform's auto-mode switch
380
- * (`devices.autoMode`; the org may follow it, never exceed it).
374
+ * The deployment config: `sandbox.limits` and the platform's Full switch
375
+ * (`devices.fullAccess`; the org may follow it, never exceed it).
381
376
  */
382
- config, log) {
377
+ config, ceilings, log) {
383
378
  this.db = db;
384
379
  this.txHost = txHost;
385
380
  this.orgLock = orgLock;
386
381
  this.config = config;
382
+ this.ceilings = ceilings;
387
383
  this.log = log;
388
384
  }
389
- /** Parses stored settings, warning when an invalid `autoMode` narrows to `off`, an invalid
385
+ /** Parses stored settings, warning when an invalid `fullAccess` narrows to `off`, an invalid
390
386
  * `cloudNetwork` to an empty allowlist, or a security setting reads narrower
391
387
  * ({@link logUnreadableSecuritySettings}, warn). */
392
388
  parseStored(orgId, raw) {
393
- if (invalidStoredAutoMode(raw)) {
394
- this.log?.warn("org settings: stored autoMode is invalid; it reads as off", { orgId });
389
+ if (invalidStoredFullAccess(raw)) {
390
+ this.log?.warn("org settings: stored fullAccess is invalid; it reads as off", { orgId });
395
391
  }
396
392
  if (invalidStoredCloudNetwork(raw)) {
397
393
  this.log?.warn("org settings: stored cloudNetwork is invalid; it reads as an empty allowlist", {
@@ -406,13 +402,14 @@ let OrgSettingsService = class OrgSettingsService {
406
402
  /** 部署默认值(设置页展示「跟随部署」时的实际取值)。 */
407
403
  async deployment() {
408
404
  const lim = this.config.get().sandbox.limits;
409
- const [autoMode, attribution, compaction] = await Promise.all([
410
- readDevicesAutoMode(this.db.db, this.config, this.log),
405
+ const [fullAccess, attribution, compaction] = await Promise.all([
406
+ readDevicesFullAccess(this.db.db, this.config, this.log),
411
407
  readPlatformAttribution(this.db.db, this.config, this.log),
412
408
  readPlatformCompactionSettings(this.db.db),
413
409
  ]);
414
410
  return {
415
- autoMode,
411
+ fullAccess,
412
+ autoMode: legacyAutoModeView(fullAccess),
416
413
  cloudNetwork: {
417
414
  allowHosts: [...lim.allowHosts],
418
415
  orgHosts: lim.orgHosts,
@@ -459,12 +456,13 @@ let OrgSettingsService = class OrgSettingsService {
459
456
  * The refusals of {@link update} that need no read of the org (the Platform tool's precheck):
460
457
  * auto mode where the platform turned it off.
461
458
  */
462
- async check(patch) {
463
- // turning auto mode on where the platform turned it off is wider than the platform allows
464
- if (patch.autoMode === "allowed") {
465
- const platform = await readDevicesAutoMode(this.db.db, this.config, this.log);
466
- if (platform.mode === "off") {
467
- throw autoModeNotAllowed("The platform does not allow auto mode");
459
+ async check(input) {
460
+ const patch = normalizeOrgSettingsPatch(input);
461
+ // allowing Full where the platform turned it off is wider than the platform allows
462
+ if (patch.fullAccess === "allowed") {
463
+ const platform = await readDevicesFullAccess(this.db.db, this.config, this.log);
464
+ if (platform.permission === "off") {
465
+ throw autoModeNotAllowed("The platform does not allow Full permission");
468
466
  }
469
467
  }
470
468
  }
@@ -491,32 +489,42 @@ let OrgSettingsService = class OrgSettingsService {
491
489
  throw new ApiError("org.sandbox_egress_not_allowed", `The platform limits sandbox hosts to its allowlist; ask a super admin to add ${outside.join(", ")} to sandbox.limits.allowHosts`, [{ reason: "outside_ceiling", hosts: outside }]);
492
490
  }
493
491
  }
494
- async update(orgId, patch, actorAccountId, actorTokenId,
492
+ async update(orgId, input, actorAccountId, actorTokenId,
495
493
  /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
496
494
  auditDetail,
497
495
  /**
498
- * `onlyNarrows` (the Platform tool, API tokens): refuse an `autoMode` or `cloudNetwork`
496
+ * `onlyNarrows` (the Platform tool, API tokens): refuse a `fullAccess` or `cloudNetwork`
499
497
  * change that widens (see {@link assertOnlyNarrows}); only a person in a session widens.
500
498
  */
501
499
  opts) {
500
+ const patch = normalizeOrgSettingsPatch(input);
502
501
  await this.check(patch);
503
- return this.updateIn(orgId, patch, actorAccountId, actorTokenId, auditDetail, opts);
502
+ // the org row, then (for a Full or cloud network change) the org's permission authority lock:
503
+ // the ordered prelude, so inside a run's fence (the Platform tool's `org-settings.update`) they
504
+ // precede the conversation rows; the patch decides the lock, so nothing can change it
505
+ return withOrderedLocks(() => this.lockFor(orgId, patch, actorAccountId), () => this.updateIn(orgId, patch, actorAccountId, actorTokenId, auditDetail, opts));
506
+ }
507
+ async lockFor(orgId, patch, actorAccountId) {
508
+ await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "org.update");
509
+ if (patch.fullAccess !== undefined || patch.cloudNetwork !== undefined)
510
+ await this.ceilings.lock({ orgId }, "org");
504
511
  }
505
512
  /**
506
513
  * Refuses a patch that widens the org's sandbox (auto mode spec §4.3: only a person widens it,
507
514
  * never the Platform tool or an API token):
508
- * - `autoMode`: `allowed` where the organization runs `off` (an absent value follows the
515
+ * - `fullAccess`: `allowed` where the organization runs `off` (an absent value follows the
509
516
  * platform); clearing it follows the platform too, never wider than the platform allows;
510
517
  * - `cloudNetwork`: compared as stored deltas ({@link cloudNetworkWidens}), never as effective
511
518
  * values: under the kill switch or the platform ceiling the effective values hide a widening
512
519
  * that takes effect when the platform relaxes (org egress ceiling spec §D3).
513
520
  */
514
- async assertOnlyNarrows(before, patch) {
515
- if (patch.autoMode !== undefined) {
516
- const platform = await readDevicesAutoMode(this.db.db, this.config, this.log);
517
- const next = patch.autoMode === null ? platform.mode : patch.autoMode;
518
- if ((before.autoMode ?? platform.mode) !== "allowed" && next === "allowed") {
519
- throw autoModeNotAllowed("Turning auto mode on needs a person in the organization settings.");
521
+ async assertOnlyNarrows(before, input) {
522
+ const patch = normalizeOrgSettingsPatch(input);
523
+ if (patch.fullAccess !== undefined) {
524
+ const platform = await readDevicesFullAccess(this.db.db, this.config, this.log);
525
+ const next = patch.fullAccess === null ? platform.permission : patch.fullAccess;
526
+ if ((before.fullAccess ?? platform.permission) !== "allowed" && next === "allowed") {
527
+ throw autoModeNotAllowed("Allowing Full permission needs a person in the organization settings.");
520
528
  }
521
529
  }
522
530
  if (patch.cloudNetwork !== undefined &&
@@ -525,7 +533,8 @@ let OrgSettingsService = class OrgSettingsService {
525
533
  }
526
534
  }
527
535
  async updateIn(orgId, patch, actorAccountId, actorTokenId, auditDetail, opts) {
528
- await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "org.update");
536
+ // held since the prelude (`lockFor`); naming them again re-checks the actor's role
537
+ await this.lockFor(orgId, patch, actorAccountId);
529
538
  const row = await this.db
530
539
  .selectFrom("orgs")
531
540
  .select("settings")
@@ -541,7 +550,7 @@ let OrgSettingsService = class OrgSettingsService {
541
550
  await this.assertOnlyNarrows(before, patch);
542
551
  const changes = Object.fromEntries(Object.entries(patch)
543
552
  .filter(([, v]) => v !== undefined)
544
- // null clears autoMode / cloudNetwork / wakeOnBackgroundTask: follow the deployment again
553
+ // null clears fullAccess / cloudNetwork / wakeOnBackgroundTask: follow the deployment again
545
554
  .map(([k, v]) => [k, v === null ? undefined : v]));
546
555
  const arrangementPatch = patch.uiArrangement;
547
556
  const compactionPatch = patch.compaction;
@@ -567,8 +576,15 @@ let OrgSettingsService = class OrgSettingsService {
567
576
  if (Object.keys(after.uiArrangement).length === 0)
568
577
  delete after.uiArrangement;
569
578
  }
570
- if (after.autoMode === undefined)
571
- delete after.autoMode;
579
+ // Until 8.6 a stored old `autoMode` is never dropped: an unconverted key (or one an old
580
+ // replica wrote again) is carried in step with `fullAccess`, since old replicas still read it.
581
+ // A write that does not choose the value stores what every reader already sees: the narrower
582
+ // of the two (never refused, never wider).
583
+ const legacy = "autoMode" in stored;
584
+ if (legacy && patch.fullAccess === undefined)
585
+ after.fullAccess = narrowedOrgFullAccess(before.fullAccess, stored.autoMode);
586
+ if (after.fullAccess === undefined)
587
+ delete after.fullAccess;
572
588
  if (after.cloudNetwork === undefined)
573
589
  delete after.cloudNetwork;
574
590
  if (after.wakeOnBackgroundTask === undefined)
@@ -597,10 +613,14 @@ let OrgSettingsService = class OrgSettingsService {
597
613
  if (patch.theme?.id != null && patch.theme.id !== before.theme?.id) {
598
614
  await assertThemeOnIn(this.db.db, orgId, patch.theme.id);
599
615
  }
600
- // Merge with the stored value: keep the keys this version does not know (a cleared autoMode /
601
- // cloudNetwork is not kept)
602
- const { autoMode: _oldAutoMode, cloudNetwork: _oldNetwork, wakeOnBackgroundTask: _oldWake, timeZone: _oldZone, theme: _oldTheme, uiArrangement: _oldArrangement, scheduledTasks: _oldScheduled, compaction: _oldCompaction, ...rest } = stored;
603
- const written = { ...rest, ...after };
616
+ // Merge with the stored value: keep the keys this version does not know (a cleared fullAccess /
617
+ // cloudNetwork is not kept, nor the old name autoMode)
618
+ const { autoMode: _legacyAutoMode, fullAccess: _oldFullAccess, cloudNetwork: _oldNetwork, wakeOnBackgroundTask: _oldWake, timeZone: _oldZone, theme: _oldTheme, uiArrangement: _oldArrangement, scheduledTasks: _oldScheduled, compaction: _oldCompaction, ...rest } = stored;
619
+ const written = {
620
+ ...rest,
621
+ ...after,
622
+ ...(legacy && after.fullAccess !== undefined && { autoMode: after.fullAccess }),
623
+ };
604
624
  // An unreadable forbiddenTools reads as [] for display only: a write that does not replace the
605
625
  // list keeps it unreadable (never healed to "nothing forbidden"); saving the list fixes it
606
626
  if (invalidStoredForbiddenTools(stored) && patch.scheduledTasks?.forbiddenTools === undefined) {
@@ -623,9 +643,31 @@ let OrgSettingsService = class OrgSettingsService {
623
643
  target: orgId,
624
644
  detail: { before, after, ...(repairs && { repaired: true }), ...auditDetail },
625
645
  });
646
+ if (patch.fullAccess !== undefined || patch.cloudNetwork !== undefined) {
647
+ const machineRoots = await localMachineRoots(this.db.db, orgId);
648
+ await this.ceilings.publishLocked({ orgId }, "org", (scope, row) => {
649
+ // Full off takes Full work and restricted work outside the machine's roots; anything
650
+ // else (Full on) still goes through the host check below
651
+ if (after.fullAccess === "off" &&
652
+ needsWiderDeviceCeiling(scope, machineRoots.get(row.device_id)))
653
+ return true;
654
+ if (needsFullCeiling(scope))
655
+ return after.fullAccess === "off";
656
+ if (!("network" in scope) ||
657
+ !isExecutionMethod(row.method) ||
658
+ scope.network.kind !== "allowlist")
659
+ return false;
660
+ const hosts = this.effectiveNetwork(after).hosts;
661
+ return scope.network.hosts.some((host) => !hosts.some((pattern) => coversHost(pattern, host)) &&
662
+ !(this.effectiveNetwork(after).mode === "open" && row.granted_hosts.includes(host)));
663
+ }, before.fullAccess !== after.fullAccess);
664
+ }
626
665
  return viewOf(after, written);
627
666
  }
628
667
  };
668
+ __decorate([
669
+ Transactional({ propagation: "mandatory" })
670
+ ], OrgSettingsService.prototype, "lockFor", null);
629
671
  __decorate([
630
672
  Transactional()
631
673
  ], OrgSettingsService.prototype, "updateIn", null);
@@ -635,8 +677,9 @@ OrgSettingsService = __decorate([
635
677
  __param(1, Inject(TransactionHost)),
636
678
  __param(2, Inject(OrgLock)),
637
679
  __param(3, Inject(KernelConfigService)),
638
- __param(4, Optional()),
639
- __param(4, Inject(KERNEL_LOGGER))
680
+ __param(4, Inject(PermissionCeilingWrites)),
681
+ __param(5, Optional()),
682
+ __param(5, Inject(KERNEL_LOGGER))
640
683
  ], OrgSettingsService);
641
684
  export { OrgSettingsService };
642
685
  /**
@@ -648,7 +691,7 @@ let OrgSettingsModule = class OrgSettingsModule {
648
691
  };
649
692
  OrgSettingsModule = __decorate([
650
693
  Module({
651
- imports: [OrgLockModule],
694
+ imports: [OrgLockModule, PermissionAuthorityModule],
652
695
  providers: [OrgSettingsService],
653
696
  exports: [OrgSettingsService],
654
697
  })
@@ -25,6 +25,7 @@ import { AGENT_LOOP_FACTORY, type AgentLoopFactory } from "./runtime/run-steps.j
25
25
  import { RUN_HOOKS, type RunHooks } from "./runtime/run-worker.js";
26
26
  import { SUBAGENT_MESSAGES_HOOKS, type SubagentMessagesHooks } from "./runtime/subagents/messages.js";
27
27
  import { SANDBOX_LEASE_TIMINGS, type SandboxLeaseTimings } from "./sandbox/leases.js";
28
+ import { PERMISSION_CONTEXT_ACTIVATION } from "./sandbox/permission-context-types.js";
28
29
  import { SETUP_CHECK_TIMEOUT } from "./setup/setup-checks.service.js";
29
30
  import { TOOL_PIPELINE_HOOKS, type ToolPipelineHooks } from "./tools/pipeline.js";
30
31
  import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
@@ -60,7 +61,10 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
60
61
  * - `SCOPE_ORG_CHUNK_SIZE`: fewer orgs per plugin scope sync chunk job (several chunks in a test);
61
62
  * - `EXTENSION_NET_SEAMS`: `ctx.net`'s DNS and dispatcher (a hostname resolving to a private address
62
63
  * served by a loopback fake);
63
- * - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes).
64
+ * - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes);
65
+ * - `PERMISSION_CONTEXT_ACTIVATION`: turns the dormant recorded permission context producers on
66
+ * (the request boundary and the managed device context writer) before their paired activation
67
+ * flips the production default.
64
68
  */
65
69
  interface KernelSeams {
66
70
  [AGENT_LOOP_FACTORY]: AgentLoopFactory;
@@ -90,6 +94,7 @@ interface KernelSeams {
90
94
  [DEVICE_POLICY_AFTER_CALL]: (opId: string) => void;
91
95
  [EXTENSION_NET_SEAMS]: ExtensionNetSeams;
92
96
  [APP_INTERCEPTOR]: NestInterceptor;
97
+ [PERMISSION_CONTEXT_ACTIVATION]: boolean;
93
98
  }
94
99
  /**
95
100
  * A seam of the kernel's own tests (`KernelAppOptions.overrides`): a value for one of the named
package/dist/overrides.js CHANGED
@@ -22,6 +22,7 @@ import { AGENT_LOOP_FACTORY } from "./runtime/run-steps.js";
22
22
  import { RUN_HOOKS } from "./runtime/run-worker.js";
23
23
  import { SUBAGENT_MESSAGES_HOOKS, } from "./runtime/subagents/messages.js";
24
24
  import { SANDBOX_LEASE_TIMINGS } from "./sandbox/leases.js";
25
+ import { PERMISSION_CONTEXT_ACTIVATION } from "./sandbox/permission-context-types.js";
25
26
  import { SETUP_CHECK_TIMEOUT } from "./setup/setup-checks.service.js";
26
27
  import { TOOL_PIPELINE_HOOKS } from "./tools/pipeline.js";
27
28
  import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
@@ -53,6 +54,7 @@ const SEAM_TOKENS = [
53
54
  DEVICE_POLICY_AFTER_CALL,
54
55
  EXTENSION_NET_SEAMS,
55
56
  APP_INTERCEPTOR,
57
+ PERMISSION_CONTEXT_ACTIVATION,
56
58
  ];
57
59
  const allSeamsListed = true;
58
60
  void allSeamsListed;
@@ -4,6 +4,26 @@
4
4
  * Every exclusion is for good: there is no "later" (rule `platform-op-later`).
5
5
  */
6
6
  export const PLATFORM_EXCLUSIONS = [
7
+ {
8
+ route: "GET /api/v1/orgs/:orgId/conversations/:id/permissions",
9
+ category: "human-only",
10
+ reason: "Interactive owner session permission selection and device-bound consent",
11
+ },
12
+ {
13
+ route: "PATCH /api/v1/orgs/:orgId/conversations/:id/permissions",
14
+ category: "human-only",
15
+ reason: "Interactive owner session permission selection and device-bound consent",
16
+ },
17
+ {
18
+ route: "GET /api/v1/orgs/:orgId/conversation-permission-preview",
19
+ category: "human-only",
20
+ reason: "Interactive owner session permission selection and device-bound consent",
21
+ },
22
+ {
23
+ route: "POST /api/v1/orgs/:orgId/conversations/first-message",
24
+ category: "human-only",
25
+ reason: "Interactive owner session permission selection and device-bound consent",
26
+ },
7
27
  // platform-admin: every route is an operation (Task 7)
8
28
  // extensions-admin
9
29
  {
@@ -19,7 +19,7 @@ import { AdminUsageService } from "../../admin/usage.service.js";
19
19
  import { ApiError } from "../../errors.js";
20
20
  import { ExtensionDisplayNames } from "../../extensions/display-name.js";
21
21
  import { ExtensionRegistry } from "../../extensions/registry.js";
22
- import { DEPLOYMENT_SETTINGS_PATCH, SettingsService } from "../../identity/settings.js";
22
+ import { DEPLOYMENT_SETTINGS_PATCH, normalizeDeploymentSettingsPatch, SettingsService, } from "../../identity/settings.js";
23
23
  import { ModelDisabledPatch, ModelProviderParams } from "../../models/enablement.controller.js";
24
24
  import { ModelEnablement } from "../../models/enablement.js";
25
25
  import { MODEL_PRICE_PUT, PricesService } from "../../models/prices.js";
@@ -43,6 +43,7 @@ const SettingsInput = DEPLOYMENT_SETTINGS_PATCH.pick({
43
43
  uiTheme: true,
44
44
  uiArrangement: true,
45
45
  clientExtensions: true,
46
+ devicesFullAccess: true,
46
47
  devicesAutoMode: true,
47
48
  attribution: true,
48
49
  }).strict();
@@ -203,7 +204,7 @@ let AdminOperations = class AdminOperations {
203
204
  }),
204
205
  defineOperation({
205
206
  id: "admin.settings",
206
- description: "Read the deployment settings (super admin): who may create orgs (orgCreation), the price currency, whether orgs may create their own connectors and skills, whether org admins may browse the marketplaces, the per-org limit overrides keyed by org id (orgs.get reads one org's), the platform's auto-mode switch in effect (devicesAutoMode: mode allowed or off), and the platform's attribution defaults for agent-created git commits and pull requests (attribution: commit, pr, sessionUrl); each with sources: env, file or nacos are set in the startup config and read-only, db chosen in the admin console, default.",
207
+ description: "Read the deployment settings (super admin): who may create orgs (orgCreation), the price currency, whether orgs may create their own connectors and skills, whether org admins may browse the marketplaces, the per-org limit overrides keyed by org id (orgs.get reads one org's), the platform's Full permission switch in effect (devicesFullAccess: permission allowed or off; devicesAutoMode is its old name with mode), and the platform's attribution defaults for agent-created git commits and pull requests (attribution: commit, pr, sessionUrl); each with sources: env, file or nacos are set in the startup config and read-only, db chosen in the admin console, default.",
207
208
  input: z.object({}).strict(),
208
209
  example: {},
209
210
  authz: { superAdmin: true },
@@ -213,7 +214,7 @@ let AdminOperations = class AdminOperations {
213
214
  }),
214
215
  defineOperation({
215
216
  id: "admin.update-settings",
216
- description: "Change deployment settings (super admin); give only the keys to change: orgCreation (anyone or super_admin), priceCurrency (ISO 4217 code), customConnectors / customSkills (allow or deny: whether orgs may create their own instead of installing from the catalog), orgMarketplaceBrowse (true or false), uiTheme ({ id }: the platform default theme, a platform theme whose scope is all, or null for the built-in theme; it is what every org falls back to and what the sign-in pages show), uiArrangement ({ <slot>: { hidden, order } } for a list slot, { <slot>: { use } } for a single slot: the platform default arrangement of UI slots, with contribution keys <extension>/<contribution>; hidden ones are not listed but still open by URL; use names the contribution that replaces the built-in, null for the built-in; null for a slot removes its entry), clientExtensions ({ enabled?, disabled? }: the kill switch of plugin client code; enabled false stops every plugin's interface code in every browser, disabled is the whole list of plugins whose interface code alone is stopped while their tools keep working; read the current list from admin.settings first), devicesAutoMode ({ mode }: the platform's auto-mode switch, allowed or off; null clears it back to the default, allowed; through this tool it may only be turned off, never on, and a value set in the startup config is read-only), attribution ({ commit?, pr?, sessionUrl? }: the platform's defaults for agent-created git commits and pull requests; null clears a field back to its default, an empty string turns that line off, and fields set in the startup config are read-only). Per-org limits are orgs.set-limits.",
217
+ description: "Change deployment settings (super admin); give only the keys to change: orgCreation (anyone or super_admin), priceCurrency (ISO 4217 code), customConnectors / customSkills (allow or deny: whether orgs may create their own instead of installing from the catalog), orgMarketplaceBrowse (true or false), uiTheme ({ id }: the platform default theme, a platform theme whose scope is all, or null for the built-in theme; it is what every org falls back to and what the sign-in pages show), uiArrangement ({ <slot>: { hidden, order } } for a list slot, { <slot>: { use } } for a single slot: the platform default arrangement of UI slots, with contribution keys <extension>/<contribution>; hidden ones are not listed but still open by URL; use names the contribution that replaces the built-in, null for the built-in; null for a slot removes its entry), clientExtensions ({ enabled?, disabled? }: the kill switch of plugin client code; enabled false stops every plugin's interface code in every browser, disabled is the whole list of plugins whose interface code alone is stopped while their tools keep working; read the current list from admin.settings first), devicesFullAccess ({ permission }: the platform's Full permission switch, allowed or off; null clears it back to the default, allowed; through this tool it may only be turned off, never allowed, and a value set in the startup config is read-only; devicesAutoMode ({ mode }) is its old name, never both), attribution ({ commit?, pr?, sessionUrl? }: the platform's defaults for agent-created git commits and pull requests; null clears a field back to its default, an empty string turns that line off, and fields set in the startup config are read-only). Per-org limits are orgs.set-limits.",
217
218
  input: SettingsInput.refine((b) => Object.keys(b).length > 0, {
218
219
  message: "at least one setting is required",
219
220
  }),
@@ -236,7 +237,7 @@ let AdminOperations = class AdminOperations {
236
237
  },
237
238
  {
238
239
  code: "deployment.auto_mode_not_allowed",
239
- next: "Through this tool the platform's auto-mode switch may only be turned off; to turn it on, ask a super admin to change it in the admin console settings on the web.",
240
+ next: "Through this tool the platform's Full permission switch may only be turned off; to allow it, ask a super admin to change it in the admin console settings on the web.",
240
241
  },
241
242
  {
242
243
  code: "deployment.setting_readonly",
@@ -256,16 +257,18 @@ let AdminOperations = class AdminOperations {
256
257
  message: r.error.issues[0]?.message ?? "",
257
258
  };
258
259
  }
259
- const autoMode = i.devicesAutoMode;
260
- return autoMode === undefined
261
- ? { ok: true }
262
- : precheckBy(() => this.settings.checkDevicesAutoMode(autoMode, { onlyNarrows: true }));
260
+ return precheckBy(async () => {
261
+ const full = normalizeDeploymentSettingsPatch(i).devicesFullAccess;
262
+ if (full !== undefined)
263
+ await this.settings.checkDevicesFullAccess(full, { onlyNarrows: true });
264
+ });
263
265
  },
264
266
  summary: async (i) => {
265
- const { uiTheme, uiArrangement, clientExtensions, devicesAutoMode, attribution, ...rest } = i;
267
+ const { uiTheme, uiArrangement, clientExtensions, devicesFullAccess, devicesAutoMode, attribution, ...rest } = i;
266
268
  const parts = Object.entries(rest).map(([k, v]) => `${k}=${String(v)}`);
267
- if (devicesAutoMode !== undefined) {
268
- parts.push(`devicesAutoMode=${String(devicesAutoMode.mode)}`);
269
+ const full = devicesFullAccess?.permission ?? devicesAutoMode?.mode;
270
+ if (devicesFullAccess !== undefined || devicesAutoMode !== undefined) {
271
+ parts.push(`devicesFullAccess=${String(full)}`);
269
272
  }
270
273
  const zh = [...parts];
271
274
  const en = [...parts];
@@ -343,6 +343,8 @@ let AgentSkillsOperations = class AgentSkillsOperations {
343
343
  path: input.filePath,
344
344
  maxBytes: SKILL_PACKAGE_MAX_BYTES,
345
345
  signal: ctx.signal,
346
+ // the read is this call's managed operation once the activation gate is on
347
+ ...(ctx.callId !== undefined && { callId: ctx.callId }),
346
348
  });
347
349
  const o = await this.agentSkills.register({
348
350
  orgId: ctx.orgId,
@@ -49,6 +49,13 @@ function stateOf(e) {
49
49
  next: "Wipe its files with devices.reset-files to use it again.",
50
50
  };
51
51
  }
52
+ if (e.reconcileRequired) {
53
+ return {
54
+ state: "reconcile_required",
55
+ reason: "Its sandbox limits must be established again after the permission migration; nothing runs on it until then.",
56
+ next: "Rebuild its files with devices.reset-files (the workspace is wiped), or ask the person to do it on its device page.",
57
+ };
58
+ }
52
59
  return { state: e.instance?.status ?? "ready" };
53
60
  }
54
61
  const row = (e) => ({
@@ -279,8 +286,9 @@ let DevicesOperations = class DevicesOperations {
279
286
  authz: { orgAction: "agents.use" },
280
287
  mirrors: ["PATCH /api/v1/orgs/:orgId/devices/:id"],
281
288
  renames: { deviceId: "id" },
282
- // a person changes their own machine's mode; enabling auto mode happens on the machine
283
- omits: ["mode"],
289
+ // a person changes their own device's mode or owner ceiling in a web session; widening a
290
+ // machine's ceiling happens on the machine (B2)
291
+ omits: ["mode", "ownerCeiling", "confirmWidening"],
284
292
  confirm: "personal",
285
293
  errors: [
286
294
  {
@@ -86,6 +86,16 @@ let ModelsOperations = class ModelsOperations {
86
86
  purposes: await withDeclaredByNames(await this.purposes.list(ctx.orgId), this.displayNames),
87
87
  }),
88
88
  }),
89
+ defineOperation({
90
+ id: "models.purpose-availability",
91
+ description: "Whether each model purpose (such as image generation) has a usable model in this org now, without naming models.",
92
+ input: z.object({}).strict(),
93
+ example: {},
94
+ authz: { orgAction: "agents.use" },
95
+ mirrors: ["GET /api/v1/orgs/:orgId/model-purposes/available"],
96
+ confirm: "read",
97
+ run: async (_input, ctx) => ({ purposes: await this.purposes.availability(ctx.orgId) }),
98
+ }),
89
99
  defineOperation({
90
100
  id: "models.set-purpose",
91
101
  description: "Set the org's model for one purpose (org admins): target.model is { provider, model } with optional params, or target null to clear the override and fall back to the platform default. The model must be usable in the org and of the purpose's kind.",