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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/admin/admin.schemas.d.ts +6 -0
  3. package/dist/admin/org-network.service.d.ts +3 -1
  4. package/dist/admin/org-network.service.js +10 -2
  5. package/dist/app.d.ts +4 -0
  6. package/dist/app.js +2 -0
  7. package/dist/background/finish.d.ts +9 -1
  8. package/dist/background/finish.js +57 -4
  9. package/dist/background/launch.d.ts +23 -0
  10. package/dist/background/launch.js +55 -1
  11. package/dist/background/managed-output.d.ts +110 -0
  12. package/dist/background/managed-output.js +219 -0
  13. package/dist/background/managed.d.ts +52 -0
  14. package/dist/background/managed.js +128 -0
  15. package/dist/background/poll.job.d.ts +35 -1
  16. package/dist/background/poll.job.js +174 -9
  17. package/dist/background/render.js +1 -0
  18. package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
  19. package/dist/background/retire-legacy-tasks.job.js +149 -0
  20. package/dist/background/session.d.ts +15 -5
  21. package/dist/background/session.js +22 -6
  22. package/dist/background/stop.d.ts +35 -5
  23. package/dist/background/stop.js +94 -8
  24. package/dist/background/store.d.ts +110 -3
  25. package/dist/background/store.js +205 -3
  26. package/dist/background/tasks.service.d.ts +18 -1
  27. package/dist/background/tasks.service.js +99 -9
  28. package/dist/catalog/marketplaces.service.d.ts +1 -1
  29. package/dist/channels/cards.js +1 -1
  30. package/dist/channels/inbound.js +2 -0
  31. package/dist/channels/phrases.d.ts +4 -0
  32. package/dist/channels/phrases.js +4 -0
  33. package/dist/config/load.d.ts +18 -0
  34. package/dist/config/load.js +39 -1
  35. package/dist/config/permission-migration.d.ts +26 -0
  36. package/dist/config/permission-migration.js +64 -0
  37. package/dist/config/schema.d.ts +1 -1
  38. package/dist/config/schema.js +11 -10
  39. package/dist/conversations/conversations.controller.d.ts +1 -1
  40. package/dist/conversations/conversations.controller.js +1 -1
  41. package/dist/conversations/conversations.module.js +12 -0
  42. package/dist/conversations/conversations.service.d.ts +11 -2
  43. package/dist/conversations/conversations.service.js +97 -27
  44. package/dist/conversations/event-log.d.ts +1 -1
  45. package/dist/conversations/event-log.js +10 -2
  46. package/dist/conversations/events.d.ts +304 -4
  47. package/dist/conversations/events.js +279 -29
  48. package/dist/conversations/permission-profile-store.d.ts +50 -0
  49. package/dist/conversations/permission-profile-store.js +67 -0
  50. package/dist/conversations/permission-profile-store.module.d.ts +2 -0
  51. package/dist/conversations/permission-profile-store.module.js +19 -0
  52. package/dist/conversations/permission-profiles.controller.d.ts +84 -0
  53. package/dist/conversations/permission-profiles.controller.js +105 -0
  54. package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
  55. package/dist/conversations/permission-profiles.schemas.js +23 -0
  56. package/dist/conversations/permission-profiles.service.d.ts +56 -0
  57. package/dist/conversations/permission-profiles.service.js +179 -0
  58. package/dist/db/kernel-schema.d.ts +238 -3
  59. package/dist/devices/access.js +1 -1
  60. package/dist/devices/access.module.d.ts +2 -0
  61. package/dist/devices/access.module.js +19 -0
  62. package/dist/devices/conversation-devices.d.ts +8 -29
  63. package/dist/devices/conversation-devices.js +37 -73
  64. package/dist/devices/device-projects.service.d.ts +26 -28
  65. package/dist/devices/device-projects.service.js +123 -127
  66. package/dist/devices/devices.controller.js +3 -1
  67. package/dist/devices/devices.module.js +11 -9
  68. package/dist/devices/devices.service.d.ts +116 -8
  69. package/dist/devices/devices.service.js +252 -20
  70. package/dist/devices/dto.d.ts +16 -0
  71. package/dist/devices/dto.js +34 -6
  72. package/dist/devices/errors.d.ts +8 -0
  73. package/dist/devices/errors.js +10 -0
  74. package/dist/devices/project-rules.d.ts +44 -0
  75. package/dist/devices/project-rules.js +27 -0
  76. package/dist/devices/working-root.d.ts +6 -0
  77. package/dist/devices/working-root.js +12 -1
  78. package/dist/errors.d.ts +31 -0
  79. package/dist/errors.js +31 -0
  80. package/dist/evals/reconstruct.d.ts +19 -2
  81. package/dist/evals/reconstruct.js +40 -2
  82. package/dist/evals/recorded-permission-context.d.ts +77 -0
  83. package/dist/evals/recorded-permission-context.js +151 -0
  84. package/dist/evals/recorded-tools.d.ts +10 -1
  85. package/dist/evals/recorded-tools.js +27 -3
  86. package/dist/evals/run-replay.d.ts +8 -2
  87. package/dist/evals/run-replay.js +18 -2
  88. package/dist/evals/trajectory.d.ts +1 -1
  89. package/dist/evals/worker.d.ts +10 -1
  90. package/dist/evals/worker.js +23 -14
  91. package/dist/http/api.module.js +2 -0
  92. package/dist/identity/accounts.d.ts +14 -1
  93. package/dist/identity/accounts.js +61 -5
  94. package/dist/identity/identity.module.js +2 -0
  95. package/dist/identity/settings.d.ts +28 -12
  96. package/dist/identity/settings.js +89 -33
  97. package/dist/index.d.ts +6 -0
  98. package/dist/index.js +5 -0
  99. package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
  100. package/dist/infra/cli/kernel-cli.module.js +5 -2
  101. package/dist/infra/cli/permission-cutover.d.ts +59 -0
  102. package/dist/infra/cli/permission-cutover.js +107 -0
  103. package/dist/infra/config/kernel-config.service.d.ts +2 -2
  104. package/dist/infra/config/kernel-config.service.js +31 -11
  105. package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
  106. package/dist/infra/database/startup-activation-transaction.js +242 -0
  107. package/dist/infra/database/transaction-host.d.ts +47 -0
  108. package/dist/infra/database/transaction-host.js +119 -0
  109. package/dist/infra/database/xact-lock.d.ts +1 -0
  110. package/dist/infra/database/xact-lock.js +6 -0
  111. package/dist/infra/outbox/registry.d.ts +39 -0
  112. package/dist/infra/outbox/registry.js +18 -0
  113. package/dist/kernel.module.js +2 -0
  114. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  115. package/dist/lifecycle/kernel-lifecycle.js +55 -28
  116. package/dist/local-devices/device-auth.js +1 -1
  117. package/dist/local-devices/device-policy.service.d.ts +35 -5
  118. package/dist/local-devices/device-policy.service.js +188 -13
  119. package/dist/local-devices/instance-bindings.d.ts +82 -0
  120. package/dist/local-devices/instance-bindings.js +304 -0
  121. package/dist/local-devices/keys.d.ts +5 -0
  122. package/dist/local-devices/keys.js +5 -0
  123. package/dist/local-devices/local-device-gateway.d.ts +19 -4
  124. package/dist/local-devices/local-device-gateway.js +185 -17
  125. package/dist/local-devices/local-device-provider.d.ts +42 -7
  126. package/dist/local-devices/local-device-provider.js +185 -10
  127. package/dist/local-devices/local-devices.module.d.ts +17 -2
  128. package/dist/local-devices/local-devices.module.js +49 -8
  129. package/dist/local-devices/machines.d.ts +35 -12
  130. package/dist/local-devices/machines.js +203 -8
  131. package/dist/local-devices/network-grants.js +3 -3
  132. package/dist/local-devices/network-grants.module.d.ts +2 -0
  133. package/dist/local-devices/network-grants.module.js +14 -0
  134. package/dist/local-devices/owner-report.d.ts +79 -0
  135. package/dist/local-devices/owner-report.js +155 -0
  136. package/dist/local-devices/owner-reports.d.ts +48 -0
  137. package/dist/local-devices/owner-reports.js +190 -0
  138. package/dist/local-devices/policy-summary.d.ts +24 -1
  139. package/dist/local-devices/policy-summary.js +48 -0
  140. package/dist/local-devices/relay.d.ts +82 -6
  141. package/dist/local-devices/relay.js +187 -16
  142. package/dist/local-devices/targets.d.ts +16 -1
  143. package/dist/local-devices/targets.js +35 -2
  144. package/dist/orgs/cloud-network-setting.d.ts +33 -0
  145. package/dist/orgs/cloud-network-setting.js +47 -0
  146. package/dist/orgs/offboarding.d.ts +3 -1
  147. package/dist/orgs/offboarding.js +8 -2
  148. package/dist/orgs/org-lock.d.ts +10 -4
  149. package/dist/orgs/org-lock.js +10 -4
  150. package/dist/orgs/orgs.service.d.ts +3 -1
  151. package/dist/orgs/orgs.service.js +8 -2
  152. package/dist/orgs/settings.controller.d.ts +4 -1
  153. package/dist/orgs/settings.controller.js +3 -3
  154. package/dist/orgs/settings.service.d.ts +48 -56
  155. package/dist/orgs/settings.service.js +144 -101
  156. package/dist/overrides.d.ts +6 -1
  157. package/dist/overrides.js +2 -0
  158. package/dist/platform/exclusions.js +20 -0
  159. package/dist/platform/ops/admin.ops.js +14 -11
  160. package/dist/platform/ops/agent-skills.ops.js +2 -0
  161. package/dist/platform/ops/devices.ops.js +10 -2
  162. package/dist/platform/ops/org-settings.ops.js +6 -6
  163. package/dist/platform/ops/orgs.ops.js +1 -0
  164. package/dist/roles/worker.module.js +4 -0
  165. package/dist/runtime/context/build.d.ts +3 -1
  166. package/dist/runtime/context/build.js +19 -3
  167. package/dist/runtime/context/compaction.js +5 -0
  168. package/dist/runtime/context/device-paths.d.ts +9 -2
  169. package/dist/runtime/context/device-paths.js +20 -0
  170. package/dist/runtime/context/permission-profile.d.ts +46 -0
  171. package/dist/runtime/context/permission-profile.js +194 -0
  172. package/dist/runtime/maintenance.d.ts +7 -1
  173. package/dist/runtime/maintenance.js +43 -15
  174. package/dist/runtime/model-call.d.ts +32 -0
  175. package/dist/runtime/model-call.js +67 -0
  176. package/dist/runtime/permission-context-errors.d.ts +39 -0
  177. package/dist/runtime/permission-context-errors.js +67 -0
  178. package/dist/runtime/permission-context.service.d.ts +60 -0
  179. package/dist/runtime/permission-context.service.js +286 -0
  180. package/dist/runtime/project/knowledge.d.ts +7 -2
  181. package/dist/runtime/project/knowledge.js +5 -2
  182. package/dist/runtime/project/knowledge.service.d.ts +17 -2
  183. package/dist/runtime/project/knowledge.service.js +76 -12
  184. package/dist/runtime/run-execution.d.ts +4 -1
  185. package/dist/runtime/run-execution.js +14 -5
  186. package/dist/runtime/run-steps.d.ts +11 -3
  187. package/dist/runtime/run-steps.js +27 -4
  188. package/dist/runtime/runtime.module.js +11 -0
  189. package/dist/sandbox/attachments-path.d.ts +15 -0
  190. package/dist/sandbox/attachments-path.js +15 -0
  191. package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
  192. package/dist/sandbox/cloud-permission-snapshot.js +407 -0
  193. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
  194. package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
  195. package/dist/sandbox/held-operations.d.ts +39 -0
  196. package/dist/sandbox/held-operations.js +119 -0
  197. package/dist/sandbox/jobs.d.ts +14 -3
  198. package/dist/sandbox/jobs.js +20 -2
  199. package/dist/sandbox/kernel-read.d.ts +55 -0
  200. package/dist/sandbox/kernel-read.js +57 -0
  201. package/dist/sandbox/legacy-retirement.d.ts +336 -0
  202. package/dist/sandbox/legacy-retirement.js +1063 -0
  203. package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
  204. package/dist/sandbox/legacy-retirement.module.js +25 -0
  205. package/dist/sandbox/managed-device-context.d.ts +94 -0
  206. package/dist/sandbox/managed-device-context.js +308 -0
  207. package/dist/sandbox/managed-device-context.module.d.ts +6 -0
  208. package/dist/sandbox/managed-device-context.module.js +33 -0
  209. package/dist/sandbox/modes.d.ts +56 -8
  210. package/dist/sandbox/modes.js +92 -8
  211. package/dist/sandbox/operation-authority-types.d.ts +8 -0
  212. package/dist/sandbox/operation-authority-types.js +32 -0
  213. package/dist/sandbox/operation-authority.d.ts +145 -0
  214. package/dist/sandbox/operation-authority.js +783 -0
  215. package/dist/sandbox/operation-authority.module.d.ts +2 -0
  216. package/dist/sandbox/operation-authority.module.js +29 -0
  217. package/dist/sandbox/operation-intents.d.ts +206 -0
  218. package/dist/sandbox/operation-intents.js +1252 -0
  219. package/dist/sandbox/operation-intents.module.d.ts +2 -0
  220. package/dist/sandbox/operation-intents.module.js +21 -0
  221. package/dist/sandbox/operation-payloads.d.ts +33 -0
  222. package/dist/sandbox/operation-payloads.js +332 -0
  223. package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
  224. package/dist/sandbox/operation-reconcile.job.js +247 -0
  225. package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
  226. package/dist/sandbox/permission-authority-epochs.js +83 -0
  227. package/dist/sandbox/permission-authority-lock.d.ts +38 -0
  228. package/dist/sandbox/permission-authority-lock.js +147 -0
  229. package/dist/sandbox/permission-authority.module.d.ts +9 -0
  230. package/dist/sandbox/permission-authority.module.js +55 -0
  231. package/dist/sandbox/permission-availability.d.ts +18 -0
  232. package/dist/sandbox/permission-availability.js +19 -0
  233. package/dist/sandbox/permission-call-grants.d.ts +34 -0
  234. package/dist/sandbox/permission-call-grants.js +349 -0
  235. package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
  236. package/dist/sandbox/permission-call-grants.module.js +21 -0
  237. package/dist/sandbox/permission-call-types.d.ts +82 -0
  238. package/dist/sandbox/permission-call-types.js +1 -0
  239. package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
  240. package/dist/sandbox/permission-ceiling-writes.js +223 -0
  241. package/dist/sandbox/permission-config-publication.d.ts +76 -0
  242. package/dist/sandbox/permission-config-publication.js +339 -0
  243. package/dist/sandbox/permission-context-types.d.ts +64 -0
  244. package/dist/sandbox/permission-context-types.js +24 -0
  245. package/dist/sandbox/permission-facts.d.ts +206 -0
  246. package/dist/sandbox/permission-facts.js +627 -0
  247. package/dist/sandbox/permission-facts.module.d.ts +2 -0
  248. package/dist/sandbox/permission-facts.module.js +20 -0
  249. package/dist/sandbox/permission-instance-writes.d.ts +90 -0
  250. package/dist/sandbox/permission-instance-writes.js +305 -0
  251. package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
  252. package/dist/sandbox/permission-runtime-reports.js +354 -0
  253. package/dist/sandbox/permission-transitions.d.ts +31 -0
  254. package/dist/sandbox/permission-transitions.js +155 -0
  255. package/dist/sandbox/platform-full-access.d.ts +128 -0
  256. package/dist/sandbox/platform-full-access.js +210 -0
  257. package/dist/sandbox/providers.d.ts +22 -0
  258. package/dist/sandbox/providers.js +10 -2
  259. package/dist/sandbox/providers.module.d.ts +2 -0
  260. package/dist/sandbox/providers.module.js +19 -0
  261. package/dist/sandbox/request-not-sent.d.ts +13 -0
  262. package/dist/sandbox/request-not-sent.js +13 -0
  263. package/dist/sandbox/review/classifier.d.ts +2 -0
  264. package/dist/sandbox/review/classifier.js +8 -0
  265. package/dist/sandbox/review/permission-candidate.d.ts +12 -0
  266. package/dist/sandbox/review/permission-candidate.js +129 -0
  267. package/dist/sandbox/review/review.service.d.ts +4 -1
  268. package/dist/sandbox/review/review.service.js +19 -5
  269. package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
  270. package/dist/sandbox/sandbox-file-reader.js +51 -7
  271. package/dist/sandbox/sandbox.module.js +26 -6
  272. package/dist/sandbox/sandbox.service.d.ts +230 -34
  273. package/dist/sandbox/sandbox.service.js +1368 -199
  274. package/dist/sandbox/unreachable.js +17 -3
  275. package/dist/sandbox/use-context.d.ts +17 -0
  276. package/dist/sandbox/use-context.js +1 -0
  277. package/dist/skills/invoke.d.ts +27 -4
  278. package/dist/skills/invoke.js +72 -7
  279. package/dist/tools/approvals.controller.d.ts +1 -0
  280. package/dist/tools/approvals.schemas.d.ts +1 -0
  281. package/dist/tools/approvals.schemas.js +3 -1
  282. package/dist/tools/approvals.service.d.ts +23 -10
  283. package/dist/tools/approvals.service.js +104 -26
  284. package/dist/tools/builtins/builtin-tools.d.ts +16 -2
  285. package/dist/tools/builtins/builtin-tools.js +38 -10
  286. package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
  287. package/dist/tools/builtins/sandbox/bash.js +201 -5
  288. package/dist/tools/builtins/sandbox/common.d.ts +92 -20
  289. package/dist/tools/builtins/sandbox/common.js +201 -17
  290. package/dist/tools/builtins/sandbox/deliver.js +2 -2
  291. package/dist/tools/builtins/sandbox/edit.js +2 -2
  292. package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
  293. package/dist/tools/builtins/sandbox/glob.js +2 -2
  294. package/dist/tools/builtins/sandbox/grep.js +2 -2
  295. package/dist/tools/builtins/sandbox/read.js +2 -2
  296. package/dist/tools/builtins/sandbox/task-list.js +7 -1
  297. package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
  298. package/dist/tools/builtins/sandbox/task-output.js +172 -0
  299. package/dist/tools/builtins/sandbox/task-stop.js +25 -3
  300. package/dist/tools/builtins/sandbox/write.js +2 -2
  301. package/dist/tools/builtins/skill-load.js +9 -6
  302. package/dist/tools/device-op-resolver.d.ts +1 -1
  303. package/dist/tools/device-op-resolver.js +13 -3
  304. package/dist/tools/permission-approval-jobs.d.ts +18 -0
  305. package/dist/tools/permission-approval-jobs.js +92 -0
  306. package/dist/tools/pipeline.d.ts +17 -2
  307. package/dist/tools/pipeline.js +300 -19
  308. package/dist/tools/registry.d.ts +9 -0
  309. package/dist/tools/tools.module.js +12 -0
  310. package/package.json +4 -3
  311. package/src/migrations/0146_permission_authority_epochs.sql +6 -0
  312. package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
  313. package/src/migrations/0148_first_message_request_hash.sql +2 -0
  314. package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
  315. package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
  316. package/src/migrations/0151_starting_execution_grants.sql +8 -0
  317. package/src/migrations/0152_background_launch_identity.sql +66 -0
  318. package/src/migrations/0153_background_cancel_requester.sql +13 -0
  319. package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
  320. package/src/migrations/0155_device_instance_generations.sql +30 -0
  321. package/src/migrations/0156_device_owner_report.sql +7 -0
  322. package/src/migrations/0157_legacy_retirement.sql +116 -0
  323. package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
  324. package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
  325. package/dist/sandbox/platform-auto-mode.d.ts +0 -63
  326. package/dist/sandbox/platform-auto-mode.js +0 -63
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The legacy-launch freeze and the retirement obligations (permission runtime cutover 8.5), with
3
+ * only the authority lock they publish and check under: the sandbox service gates every
4
+ * lifecycle acquisition on it, the legacy launch checks the freeze, the local binder refuses to
5
+ * bind over an obligation and the worker's retirement job drives it.
6
+ */
7
+ export declare class LegacyRetirementModule {
8
+ }
@@ -0,0 +1,25 @@
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
+ import { Module } from "@nestjs/common";
8
+ import { LegacyRetirementStore } from "./legacy-retirement.js";
9
+ import { PermissionCeilingWritesModule } from "./permission-authority.module.js";
10
+ /**
11
+ * The legacy-launch freeze and the retirement obligations (permission runtime cutover 8.5), with
12
+ * only the authority lock they publish and check under: the sandbox service gates every
13
+ * lifecycle acquisition on it, the legacy launch checks the freeze, the local binder refuses to
14
+ * bind over an obligation and the worker's retirement job drives it.
15
+ */
16
+ let LegacyRetirementModule = class LegacyRetirementModule {
17
+ };
18
+ LegacyRetirementModule = __decorate([
19
+ Module({
20
+ imports: [PermissionCeilingWritesModule],
21
+ providers: [LegacyRetirementStore],
22
+ exports: [LegacyRetirementStore],
23
+ })
24
+ ], LegacyRetirementModule);
25
+ export { LegacyRetirementModule };
@@ -0,0 +1,94 @@
1
+ import { EventLog } from "../conversations/event-log.js";
2
+ import { PermissionProfileStore } from "../conversations/permission-profile-store.js";
3
+ import { KernelDb } from "../infra/database/kernel-db.js";
4
+ import { TransactionHost } from "../infra/database/transaction-host.js";
5
+ import type { KernelLogger } from "../log.js";
6
+ import { type PermissionContextFailureKind } from "../runtime/permission-context-errors.js";
7
+ import { SandboxOperationAuthority } from "./operation-authority.js";
8
+ import { PermissionAuthorityLock } from "./permission-authority-lock.js";
9
+ import { PermissionConfigPublication } from "./permission-config-publication.js";
10
+ import { type HeldDeviceContextEvidence, type PermissionContextSubject } from "./permission-context-types.js";
11
+ import { PermissionFacts } from "./permission-facts.js";
12
+ /** The tool error text of a managed operation whose held device context went stale (spec B3). */
13
+ export declare const MANAGED_DEVICE_CONTEXT_STALE_TEXT = "Device context changed before this operation. Retry the tool call.";
14
+ /**
15
+ * The tool error text of a managed operation on a device whose held instance has no installed
16
+ * runtime binding (a pending local binding, a cloud device without installed evidence): retrying
17
+ * the same call cannot help.
18
+ */
19
+ export declare const MANAGED_DEVICE_CONTEXT_UNAVAILABLE_TEXT = "This device has no installed runtime binding that can describe its permissions, so the operation did not start. Ask the device owner to finish setting up the device runtime before using it.";
20
+ /** The tool error text of a managed operation whose device context could not be recorded. */
21
+ export declare const MANAGED_DEVICE_CONTEXT_FAILED_TEXT = "Device context could not be recorded, so the operation did not start. Retry the tool call.";
22
+ /**
23
+ * The managed operation's held evidence (its device, provider, instance incarnation, installed
24
+ * binding, roots or working root) is not the conversation's current one under the authority locks.
25
+ * Thrown before any preparation or user callback; nothing was recorded and nothing ran.
26
+ */
27
+ export declare class ManagedDeviceContextStale extends Error {
28
+ readonly name = "ManagedDeviceContextStale";
29
+ constructor();
30
+ }
31
+ /**
32
+ * The device context could not be recorded (stale publication, storage, an invalid recorded
33
+ * payload, an unauthorized actor, a missing claim). Thrown before any preparation or user callback.
34
+ */
35
+ export declare class ManagedDeviceContextFailed extends Error {
36
+ readonly kind: PermissionContextFailureKind | "refused";
37
+ readonly name = "ManagedDeviceContextFailed";
38
+ constructor(kind: PermissionContextFailureKind | "refused");
39
+ }
40
+ /**
41
+ * The held instance carries no device context evidence (no installed binding of its generation):
42
+ * the managed path is unavailable on this device until its runtime is installed. Thrown before any
43
+ * preparation or user callback.
44
+ */
45
+ export declare class ManagedDeviceContextUnavailable extends Error {
46
+ readonly name = "ManagedDeviceContextUnavailable";
47
+ constructor();
48
+ }
49
+ /** The managed dependency `common.ts` requires on an activated managed route (spec B3). */
50
+ export type ManagedDeviceContextPort = Pick<ManagedDeviceContextRecorder, "record">;
51
+ /**
52
+ * The writer of a managed operation's model-facing device paths (permission context replay spec,
53
+ * "Task 8 exact common.ts handoff"): after a managed tool entered its held instance and before any
54
+ * preparation or user callback, it records the marked `device_paths` payload (device, roots, working
55
+ * root) into the calling conversation's log, or nothing when the latest one already equals it.
56
+ *
57
+ * One record attempt discovers the root without locks, then opens exactly one transaction whose
58
+ * fence prelude takes the complete authority subject (platform, org, device, root) inside the
59
+ * inherited run fence, after its org row and before its conversation rows. Inside it: the
60
+ * publication is current, the claim, run and actor are this call's (the actor still an active
61
+ * member, the recorded context's predicate), and the held evidence equals the device's current
62
+ * installed environment (provider, instance id, generation, installed binding, roots;
63
+ * `PermissionFacts.readAppliedEnvironmentLocked`, the reader the recorded permission context and
64
+ * admission use) and admission's working root. Any difference is
65
+ * {@link ManagedDeviceContextStale}: no rediscovery, no provisioning, no whole-handler retry. The
66
+ * bus hint follows the commit and is lossy. A lower event writer, not a permission context
67
+ * publisher; dormant until the paired activation passes it to `common.ts`.
68
+ */
69
+ export declare class ManagedDeviceContextRecorder {
70
+ private readonly db;
71
+ readonly txHost: TransactionHost;
72
+ private readonly events;
73
+ private readonly profiles;
74
+ private readonly locks;
75
+ private readonly publication;
76
+ private readonly facts;
77
+ private readonly authority;
78
+ private readonly log;
79
+ constructor(db: KernelDb, txHost: TransactionHost, events: Pick<EventLog, "appendIn" | "notify">, profiles: Pick<PermissionProfileStore, "readRoot">, locks: Pick<PermissionAuthorityLock, "acquire">, publication: Pick<PermissionConfigPublication, "assertCurrent">, facts: Pick<PermissionFacts, "readAppliedEnvironmentLocked">, authority: Pick<SandboxOperationAuthority, "workingRootFor" | "isActiveMember">, log: Pick<KernelLogger, "warn">);
80
+ /**
81
+ * Records the managed device paths of `held` into the calling conversation's log, or nothing
82
+ * when unchanged. Requires the run's real execution claim (`RunExecution.withClaim`) and no open
83
+ * transaction. A revoked execution keeps its identical `ExecutionRevoked`, an abort its reason.
84
+ */
85
+ record(input: PermissionContextSubject, held: Readonly<HeldDeviceContextEvidence>, signal: AbortSignal): Promise<void>;
86
+ private mapped;
87
+ /** The complete authority subject, read without locks; validated again under them. */
88
+ private discover;
89
+ /**
90
+ * The one transaction of a record attempt: its fence already holds the complete authority
91
+ * subject and the inherited run fence. Returns the appended seq, or null when unchanged.
92
+ */
93
+ private appendLocked;
94
+ }
@@ -0,0 +1,308 @@
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 { SandboxScopeDeniedError } from "@capybara-hq/plugin-sdk";
11
+ import { Inject, Injectable } from "@nestjs/common";
12
+ import { EventLog } from "../conversations/event-log.js";
13
+ import { ManagedDevicePathsV1Schema, } from "../conversations/events.js";
14
+ import { PermissionProfileStore } from "../conversations/permission-profile-store.js";
15
+ import { ApiError } from "../errors.js";
16
+ import { afterCommit } from "../infra/database/after-commit.js";
17
+ import { KernelDb } from "../infra/database/kernel-db.js";
18
+ import { hasTransactionFence, TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
19
+ import { Transactional } from "../infra/database/transactional.decorator.js";
20
+ import { KERNEL_LOGGER } from "../infra/tokens.js";
21
+ import { devicePathsChangeFromPayload, sameRoots, } from "../runtime/context/device-paths.js";
22
+ import { PublicationStale, permissionContextFailureKind, } from "../runtime/permission-context-errors.js";
23
+ import { currentExecutionClaim, ExecutionRevoked } from "../runtime/run-execution.js";
24
+ import { SandboxOperationAuthority } from "./operation-authority.js";
25
+ import { PermissionAuthorityLock } from "./permission-authority-lock.js";
26
+ import { PermissionConfigPublication } from "./permission-config-publication.js";
27
+ import { PermissionContextSubjectChanged, } from "./permission-context-types.js";
28
+ import { PermissionFacts } from "./permission-facts.js";
29
+ /** The tool error text of a managed operation whose held device context went stale (spec B3). */
30
+ export const MANAGED_DEVICE_CONTEXT_STALE_TEXT = "Device context changed before this operation. Retry the tool call.";
31
+ /**
32
+ * The tool error text of a managed operation on a device whose held instance has no installed
33
+ * runtime binding (a pending local binding, a cloud device without installed evidence): retrying
34
+ * the same call cannot help.
35
+ */
36
+ export const MANAGED_DEVICE_CONTEXT_UNAVAILABLE_TEXT = "This device has no installed runtime binding that can describe its permissions, so the operation did not start. Ask the device owner to finish setting up the device runtime before using it.";
37
+ /** The tool error text of a managed operation whose device context could not be recorded. */
38
+ export const MANAGED_DEVICE_CONTEXT_FAILED_TEXT = "Device context could not be recorded, so the operation did not start. Retry the tool call.";
39
+ /**
40
+ * The managed operation's held evidence (its device, provider, instance incarnation, installed
41
+ * binding, roots or working root) is not the conversation's current one under the authority locks.
42
+ * Thrown before any preparation or user callback; nothing was recorded and nothing ran.
43
+ */
44
+ export class ManagedDeviceContextStale extends Error {
45
+ name = "ManagedDeviceContextStale";
46
+ constructor() {
47
+ super(MANAGED_DEVICE_CONTEXT_STALE_TEXT);
48
+ }
49
+ }
50
+ /**
51
+ * The device context could not be recorded (stale publication, storage, an invalid recorded
52
+ * payload, an unauthorized actor, a missing claim). Thrown before any preparation or user callback.
53
+ */
54
+ export class ManagedDeviceContextFailed extends Error {
55
+ kind;
56
+ name = "ManagedDeviceContextFailed";
57
+ constructor(kind) {
58
+ super(MANAGED_DEVICE_CONTEXT_FAILED_TEXT);
59
+ this.kind = kind;
60
+ }
61
+ }
62
+ /**
63
+ * The held instance carries no device context evidence (no installed binding of its generation):
64
+ * the managed path is unavailable on this device until its runtime is installed. Thrown before any
65
+ * preparation or user callback.
66
+ */
67
+ export class ManagedDeviceContextUnavailable extends Error {
68
+ name = "ManagedDeviceContextUnavailable";
69
+ constructor() {
70
+ super(MANAGED_DEVICE_CONTEXT_UNAVAILABLE_TEXT);
71
+ }
72
+ }
73
+ /** A writer reached a conversation or claim it must never write. */
74
+ class ManagedWriterRefused extends Error {
75
+ name = "ManagedWriterRefused";
76
+ }
77
+ /**
78
+ * The writer of a managed operation's model-facing device paths (permission context replay spec,
79
+ * "Task 8 exact common.ts handoff"): after a managed tool entered its held instance and before any
80
+ * preparation or user callback, it records the marked `device_paths` payload (device, roots, working
81
+ * root) into the calling conversation's log, or nothing when the latest one already equals it.
82
+ *
83
+ * One record attempt discovers the root without locks, then opens exactly one transaction whose
84
+ * fence prelude takes the complete authority subject (platform, org, device, root) inside the
85
+ * inherited run fence, after its org row and before its conversation rows. Inside it: the
86
+ * publication is current, the claim, run and actor are this call's (the actor still an active
87
+ * member, the recorded context's predicate), and the held evidence equals the device's current
88
+ * installed environment (provider, instance id, generation, installed binding, roots;
89
+ * `PermissionFacts.readAppliedEnvironmentLocked`, the reader the recorded permission context and
90
+ * admission use) and admission's working root. Any difference is
91
+ * {@link ManagedDeviceContextStale}: no rediscovery, no provisioning, no whole-handler retry. The
92
+ * bus hint follows the commit and is lossy. A lower event writer, not a permission context
93
+ * publisher; dormant until the paired activation passes it to `common.ts`.
94
+ */
95
+ let ManagedDeviceContextRecorder = class ManagedDeviceContextRecorder {
96
+ db;
97
+ txHost;
98
+ events;
99
+ profiles;
100
+ locks;
101
+ publication;
102
+ facts;
103
+ authority;
104
+ log;
105
+ constructor(db, txHost, events, profiles, locks, publication, facts, authority, log) {
106
+ this.db = db;
107
+ this.txHost = txHost;
108
+ this.events = events;
109
+ this.profiles = profiles;
110
+ this.locks = locks;
111
+ this.publication = publication;
112
+ this.facts = facts;
113
+ this.authority = authority;
114
+ this.log = log;
115
+ }
116
+ /**
117
+ * Records the managed device paths of `held` into the calling conversation's log, or nothing
118
+ * when unchanged. Requires the run's real execution claim (`RunExecution.withClaim`) and no open
119
+ * transaction. A revoked execution keeps its identical `ExecutionRevoked`, an abort its reason.
120
+ */
121
+ async record(input, held, signal) {
122
+ try {
123
+ signal.throwIfAborted();
124
+ const claim = currentExecutionClaim();
125
+ if (!claim ||
126
+ claim.orgId !== input.orgId ||
127
+ claim.runId !== input.runId ||
128
+ claim.conversationId !== input.conversationId)
129
+ throw new ManagedWriterRefused("Managed device context requires this run's claim");
130
+ if (this.txHost.current())
131
+ throw new ManagedWriterRefused("Managed device context is recorded outside a transaction");
132
+ // the run fence takes the org row before the prelude's authority locks; without it the
133
+ // append's org row would follow them (inverting the global lock order)
134
+ if (!hasTransactionFence())
135
+ throw new ManagedWriterRefused("Managed device context requires the run's inherited fence");
136
+ const subject = await this.discover(input, held, claim.rootId);
137
+ await withTransactionFencePrelude(() => this.locks.acquire(subject, { kind: "admit" }), () => this.appendLocked(input, subject, held, signal));
138
+ }
139
+ catch (error) {
140
+ throw this.mapped(error, input, signal);
141
+ }
142
+ }
143
+ mapped(error, input, signal) {
144
+ if (error instanceof ExecutionRevoked)
145
+ return error;
146
+ if (signal.aborted && (error === signal.reason || error?.name === "AbortError"))
147
+ return error;
148
+ if (error instanceof ManagedDeviceContextStale ||
149
+ error instanceof PermissionContextSubjectChanged ||
150
+ (error instanceof ApiError && ["device.not_found", "conflict"].includes(error.code)))
151
+ return new ManagedDeviceContextStale();
152
+ const kind = error instanceof ManagedWriterRefused ? "refused" : permissionContextFailureKind(error);
153
+ this.log.warn("managed device context not recorded", {
154
+ conversationId: input.conversationId,
155
+ runId: input.runId,
156
+ kind,
157
+ cause: error instanceof Error ? `${error.name}: ${error.message}`.slice(0, 500) : "",
158
+ });
159
+ return new ManagedDeviceContextFailed(kind);
160
+ }
161
+ /** The complete authority subject, read without locks; validated again under them. */
162
+ async discover(input, held, claimRootId) {
163
+ const conv = await this.db
164
+ .selectFrom("conversations")
165
+ .select(["org_id", "kind", "eval_run_id"])
166
+ .where("id", "=", input.conversationId)
167
+ .executeTakeFirst();
168
+ if (!conv || conv.org_id !== input.orgId)
169
+ throw new ApiError("conversation.not_found", "Conversation not found");
170
+ if (conv.kind === "eval" || conv.eval_run_id !== null)
171
+ throw new ManagedWriterRefused("A replay conversation never records live device context");
172
+ const root = await this.profiles.readRoot(input.orgId, input.conversationId);
173
+ if (root.id !== claimRootId)
174
+ throw new ManagedWriterRefused("The execution claim belongs to another conversation tree");
175
+ if (root.device_id !== held.deviceId)
176
+ throw new ManagedDeviceContextStale();
177
+ return { orgId: input.orgId, deviceId: held.deviceId, rootConversationId: root.id };
178
+ }
179
+ /**
180
+ * The one transaction of a record attempt: its fence already holds the complete authority
181
+ * subject and the inherited run fence. Returns the appended seq, or null when unchanged.
182
+ */
183
+ async appendLocked(input, subject, held, signal) {
184
+ signal.throwIfAborted();
185
+ try {
186
+ await this.publication.assertCurrent();
187
+ }
188
+ catch (error) {
189
+ if (error instanceof SandboxScopeDeniedError)
190
+ throw new PublicationStale(error.message);
191
+ throw error;
192
+ }
193
+ const claim = currentExecutionClaim();
194
+ if (!claim || claim.runId !== input.runId || claim.conversationId !== input.conversationId)
195
+ throw new ManagedWriterRefused("Managed device context requires this run's claim");
196
+ // the run fence's order (org, root, calling conversation), then the explicit claim comparison
197
+ const org = await this.db
198
+ .selectFrom("orgs")
199
+ .select("deleted_at")
200
+ .where("id", "=", input.orgId)
201
+ .forNoKeyUpdate()
202
+ .executeTakeFirst();
203
+ if (!org || org.deleted_at !== null)
204
+ throw new ExecutionRevoked();
205
+ const rootRow = await this.db
206
+ .selectFrom("conversations")
207
+ .select(["deleted_at", "kind", "eval_run_id"])
208
+ .where("id", "=", subject.rootConversationId)
209
+ .where("org_id", "=", input.orgId)
210
+ .forNoKeyUpdate()
211
+ .executeTakeFirst();
212
+ const conv = await this.db
213
+ .selectFrom("conversations")
214
+ .select(["deleted_at", "kind", "eval_run_id"])
215
+ .where("id", "=", input.conversationId)
216
+ .where("org_id", "=", input.orgId)
217
+ .forUpdate()
218
+ .executeTakeFirst();
219
+ if (!rootRow || rootRow.deleted_at !== null || !conv || conv.deleted_at !== null)
220
+ throw new ExecutionRevoked();
221
+ if (conv.kind === "eval" ||
222
+ conv.eval_run_id !== null ||
223
+ rootRow.kind === "eval" ||
224
+ rootRow.eval_run_id !== null)
225
+ throw new ManagedWriterRefused("A replay conversation never records live device context");
226
+ const run = await this.db
227
+ .selectFrom("runs")
228
+ .select(["conversation_id", "status", "execution_id", "trigger_account_id"])
229
+ .where("id", "=", input.runId)
230
+ .executeTakeFirst();
231
+ if (!run ||
232
+ run.conversation_id !== input.conversationId ||
233
+ run.status !== "running" ||
234
+ run.execution_id !== claim.executionId)
235
+ throw new ExecutionRevoked();
236
+ // the actor's identity and its liveness, with the recorded permission context's predicate
237
+ if (run.trigger_account_id !== input.accountId ||
238
+ !(await this.authority.isActiveMember(input.orgId, input.accountId)))
239
+ throw new ApiError("forbidden", "This run's actor is no longer authorized");
240
+ // every comparison under the complete authority subject, before the latest event is read
241
+ const root = await this.profiles.readRoot(input.orgId, input.conversationId);
242
+ if (root.id !== subject.rootConversationId || root.device_id !== held.deviceId)
243
+ throw new ManagedDeviceContextStale();
244
+ const applied = await this.facts.readAppliedEnvironmentLocked({
245
+ orgId: input.orgId,
246
+ deviceId: held.deviceId,
247
+ });
248
+ // identical paths cannot satisfy a replaced binding or generation
249
+ if (applied === null ||
250
+ applied.provider !== held.provider ||
251
+ applied.instanceId !== held.instanceId ||
252
+ applied.instanceGeneration !== held.instanceGeneration ||
253
+ applied.bindingId !== held.bindingId ||
254
+ !sameRoots(applied.roots, held.roots))
255
+ throw new ManagedDeviceContextStale();
256
+ const workingRoot = await this.authority.workingRootFor({
257
+ orgId: input.orgId,
258
+ deviceId: held.deviceId,
259
+ conversationId: input.conversationId,
260
+ });
261
+ if (workingRoot !== held.workingRoot)
262
+ throw new ManagedDeviceContextStale();
263
+ const payload = ManagedDevicePathsV1Schema.parse({
264
+ permissionContextVersion: 1,
265
+ deviceId: held.deviceId,
266
+ roots: { workspace: held.roots.workspace, skills: held.roots.skills, tmp: held.roots.tmp },
267
+ workingRoot: held.workingRoot,
268
+ });
269
+ // the persisted log decides (old to marked appends even for identical roots; A to B to A too)
270
+ const latest = await this.db
271
+ .selectFrom("conversation_events")
272
+ .select(["seq", "payload"])
273
+ .where("conversation_id", "=", input.conversationId)
274
+ .where("type", "=", "device_paths")
275
+ .orderBy("seq", "desc")
276
+ .limit(1)
277
+ .executeTakeFirst();
278
+ const change = devicePathsChangeFromPayload(latest
279
+ ? { seq: Number(latest.seq), payload: latest.payload }
280
+ : undefined, payload, input.runId);
281
+ if (change === null)
282
+ return null;
283
+ signal.throwIfAborted();
284
+ const [event] = await this.events.appendIn(input.conversationId, [change]);
285
+ if (!event)
286
+ throw new Error("The managed device paths append returned no event");
287
+ const conversationId = input.conversationId;
288
+ // a lossy hint after the commit; a rollback drops it, a failure never replays anything
289
+ afterCommit(() => this.events.notify(conversationId, event.seq));
290
+ return event.seq;
291
+ }
292
+ };
293
+ __decorate([
294
+ Transactional()
295
+ ], ManagedDeviceContextRecorder.prototype, "appendLocked", null);
296
+ ManagedDeviceContextRecorder = __decorate([
297
+ Injectable(),
298
+ __param(0, Inject(KernelDb)),
299
+ __param(1, Inject(TransactionHost)),
300
+ __param(2, Inject(EventLog)),
301
+ __param(3, Inject(PermissionProfileStore)),
302
+ __param(4, Inject(PermissionAuthorityLock)),
303
+ __param(5, Inject(PermissionConfigPublication)),
304
+ __param(6, Inject(PermissionFacts)),
305
+ __param(7, Inject(SandboxOperationAuthority)),
306
+ __param(8, Inject(KERNEL_LOGGER))
307
+ ], ManagedDeviceContextRecorder);
308
+ export { ManagedDeviceContextRecorder };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The managed device context writer (a leaf: no runtime or tools import), which `ToolsModule`
3
+ * imports so `BuiltinTools` can hand it to the managed sandbox route.
4
+ */
5
+ export declare class ManagedDeviceContextModule {
6
+ }
@@ -0,0 +1,33 @@
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
+ import { Module } from "@nestjs/common";
8
+ import { EventLogModule } from "../conversations/event-log.js";
9
+ import { PermissionProfileStoreModule } from "../conversations/permission-profile-store.module.js";
10
+ import { ManagedDeviceContextRecorder } from "./managed-device-context.js";
11
+ import { OperationAuthorityModule } from "./operation-authority.module.js";
12
+ import { PermissionAuthorityModule } from "./permission-authority.module.js";
13
+ import { PermissionFactsModule } from "./permission-facts.module.js";
14
+ /**
15
+ * The managed device context writer (a leaf: no runtime or tools import), which `ToolsModule`
16
+ * imports so `BuiltinTools` can hand it to the managed sandbox route.
17
+ */
18
+ let ManagedDeviceContextModule = class ManagedDeviceContextModule {
19
+ };
20
+ ManagedDeviceContextModule = __decorate([
21
+ Module({
22
+ imports: [
23
+ EventLogModule,
24
+ PermissionProfileStoreModule,
25
+ PermissionAuthorityModule,
26
+ OperationAuthorityModule,
27
+ PermissionFactsModule,
28
+ ],
29
+ providers: [ManagedDeviceContextRecorder],
30
+ exports: [ManagedDeviceContextRecorder],
31
+ })
32
+ ], ManagedDeviceContextModule);
33
+ export { ManagedDeviceContextModule };
@@ -2,11 +2,11 @@ import type { KernelConfig } from "../config/schema.js";
2
2
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
3
  import type { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
4
  import type { CloudNetworkSetting, OrgSettings } from "../orgs/settings.service.js";
5
- import { type DevicesAutoMode } from "./platform-auto-mode.js";
5
+ import { type FullAccessPermission } from "./platform-full-access.js";
6
6
  /**
7
7
  * Device modes (auto mode spec §4.1–§4.3): who may choose auto mode, and the network each mode
8
8
  * gets. One pure function, {@link effectiveDevicePolicy}, combines the platform's switch
9
- * (`devices.autoMode`), the org's (`autoMode`, `cloudNetwork`) and the device's own choice (a local
9
+ * (`devices.fullAccess`), the org's (`fullAccess`, `cloudNetwork`) and the device's own choice (a local
10
10
  * machine's reported mode; null follows the platform and the org).
11
11
  */
12
12
  /** A device mode. Not `DeviceMode`, which is the program's os | docker run mode. */
@@ -19,11 +19,11 @@ export interface DeviceNetwork {
19
19
  hosts: string[];
20
20
  }
21
21
  /**
22
- * What the policy reads of the platform: the effective auto-mode switch (`readDevicesAutoMode`:
22
+ * What the policy reads of the platform: the effective Full switch (`readDevicesFullAccess`:
23
23
  * the startup config over the admin console's choice) and the `sandbox.limits` network fields.
24
24
  */
25
25
  export interface DeploymentDevicePolicy {
26
- autoMode: DevicesAutoMode;
26
+ fullAccess: FullAccessPermission;
27
27
  limits: NetworkLimits;
28
28
  }
29
29
  /**
@@ -57,12 +57,12 @@ export declare function orgCloudMode(limits: NetworkLimits, org: CloudNetworkSet
57
57
  */
58
58
  export declare function readDeploymentDevicePolicy(db: KernelSchemaDb, config: Pick<KernelConfigService, "get" | "fieldSource">): Promise<DeploymentDevicePolicy>;
59
59
  /** The org settings the policy reads. */
60
- export type OrgDeviceSettings = Pick<OrgSettings, "autoMode" | "cloudNetwork">;
60
+ export type OrgDeviceSettings = Pick<OrgSettings, "fullAccess" | "cloudNetwork">;
61
61
  /** The effective device policy of one device (or of a new device, with no choice of its own). */
62
62
  export interface EffectiveDevicePolicy {
63
63
  /** min(the device's choice, {@link allowedMode}); `auto` unless the device chose sandbox. */
64
64
  mode: SandboxMode;
65
- /** `auto` only when the platform's and the org's `autoMode` both allow it. */
65
+ /** `auto` only when the platform's and the org's `fullAccess` both allow it. */
66
66
  allowedMode: SandboxMode;
67
67
  /** Which layer decided {@link mode}. */
68
68
  modeSource: "device" | "org" | "platform";
@@ -75,8 +75,15 @@ export interface EffectiveDevicePolicy {
75
75
  */
76
76
  localAllowedDomains: string[];
77
77
  }
78
+ /**
79
+ * How far restricted work may root outside the workspace now (B2), the one rule the command
80
+ * review (`DevicesService.projectReach`) and admission's working root both read: a local device
81
+ * follows its owner's reported reach within a device ceiling that allows auto; a cloud device
82
+ * reaches beyond its workspace only in auto mode.
83
+ */
84
+ export declare function projectReachOf(source: string, policy: Pick<EffectiveDevicePolicy, "mode" | "allowedMode">, ownerReach: string | null | undefined): "workspace" | "os-user";
78
85
  /** The mode the platform and the org allow: `auto` only when neither turns it off. */
79
- export declare function allowedDeviceMode(platform: DevicesAutoMode, org: OrgDeviceSettings["autoMode"]): SandboxMode;
86
+ export declare function allowedDeviceMode(platform: FullAccessPermission, org: OrgDeviceSettings["fullAccess"]): SandboxMode;
80
87
  /** The org's allowlist (the hosts a local device in sandbox mode may reach): {@link orgEffectiveHosts}. */
81
88
  export declare function orgAllowedDomains(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings): string[];
82
89
  /**
@@ -90,7 +97,39 @@ export declare function deviceNetwork(deployment: DeploymentDevicePolicy, org: O
90
97
  * reported mode; null = follow the platform and the org). A stored mode the ceiling forbids is cut,
91
98
  * never honoured; the network follows the resulting mode.
92
99
  */
93
- export declare function effectiveDevicePolicy(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings, deviceMode: SandboxMode | null): EffectiveDevicePolicy;
100
+ export declare function effectiveDevicePolicy(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings, deviceMode: SandboxMode | null,
101
+ /** A cloud device's B1 outer network snapshot: the network never goes beyond it. */
102
+ outer?: DeviceNetwork | null): EffectiveDevicePolicy;
103
+ /** A network with its hosts lowercased, sorted and deduplicated (`open-public` carries none). */
104
+ export declare const normalizeNetwork: (n: DeviceNetwork) => DeviceNetwork;
105
+ /**
106
+ * The narrower of two networks (B1): the open public network is no limit; two allowlists keep the
107
+ * hosts (or wildcards) of each that the other covers. Never wider than either.
108
+ */
109
+ export declare function intersectNetworks(a: DeviceNetwork, b: DeviceNetwork): DeviceNetwork;
110
+ /** Whether `a` and `b` are the same mode, network kind and host set (null is never the same). */
111
+ export declare const sameAppliedExactly: (a: AppliedLimits | null | undefined, b: AppliedLimits) => boolean;
112
+ /** A cloud device's B1 per-device authority: its owner Full ceiling and its outer network. */
113
+ export interface CloudOwnerSnapshot {
114
+ fullAccess: boolean;
115
+ outerNetwork: DeviceNetwork;
116
+ }
117
+ /**
118
+ * The B1 snapshot of a cloud device from its old effective policy (computed by the old algorithm,
119
+ * `egress: none` included): Full where the old mode was auto, the old effective network as the
120
+ * outer boundary. Known applied limits narrow it by intersection, never widen it: an instance that
121
+ * really ran stricter keeps that boundary (`applied` null: unknown, nothing to intersect).
122
+ */
123
+ export declare function cloudSnapshotOf(old: Pick<EffectiveDevicePolicy, "mode" | "network">, applied?: AppliedLimits | null): CloudOwnerSnapshot;
124
+ /**
125
+ * The mode a cloud device chose: the narrower of its old narrowing switch and its B1 owner
126
+ * ceiling (false narrows to sandbox, true or not snapshotted follows the platform and the org). An
127
+ * explicit sandbox switch (an old replica's write included) is never overridden.
128
+ */
129
+ export declare const cloudChosenMode: (row: {
130
+ mode: "sandbox" | null;
131
+ owner_full_access: boolean | null;
132
+ }) => SandboxMode | null;
94
133
  /**
95
134
  * What decides whether a running cloud instance must change (auto mode spec §4.2): its mode and
96
135
  * the kind of its network only. `hosts` and resources reach instances created afterwards.
@@ -106,6 +145,15 @@ export declare const appliedOf: (limits: {
106
145
  }) => AppliedLimits;
107
146
  /** Whether `a` and `b` are the same mode and network kind (null, unknown, is never the same). */
108
147
  export declare const sameApplied: (a: AppliedLimits | null | undefined, b: AppliedLimits) => boolean;
148
+ /** Whether `a` and `b` are the same mode, network kind and host set (null is never the same). */
149
+ export declare const sameAppliedExact: (a: AppliedLimits | null | undefined, b: AppliedLimits) => boolean;
150
+ /**
151
+ * Whether applied limits `a` are more permissive than desired limits `b` in any dimension (spec
152
+ * §124): auto where `b` is sandbox, open public addresses where `b` is an allowlist, or an
153
+ * allowlisted host `b`'s allowlist does not cover. Narrower or equal is false; unknown (null) is
154
+ * false here (callers treat unknown separately).
155
+ */
156
+ export declare function appliedWider(a: AppliedLimits | null | undefined, b: AppliedLimits): boolean;
109
157
  /**
110
158
  * `device_instances.instance_limits` read leniently: `applied` is what the instance runs with
111
159
  * (null: unknown, e.g. an instance made before auto mode recorded tiers, which differs from every