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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. package/bootstrap.json +10 -1
  2. package/dist/admin/admin.schemas.d.ts +6 -0
  3. package/dist/admin/org-network.service.d.ts +3 -1
  4. package/dist/admin/org-network.service.js +10 -2
  5. package/dist/app.d.ts +4 -0
  6. package/dist/app.js +2 -0
  7. package/dist/background/finish.d.ts +9 -1
  8. package/dist/background/finish.js +57 -4
  9. package/dist/background/launch.d.ts +23 -0
  10. package/dist/background/launch.js +55 -1
  11. package/dist/background/managed-output.d.ts +110 -0
  12. package/dist/background/managed-output.js +219 -0
  13. package/dist/background/managed.d.ts +52 -0
  14. package/dist/background/managed.js +128 -0
  15. package/dist/background/poll.job.d.ts +35 -1
  16. package/dist/background/poll.job.js +174 -9
  17. package/dist/background/render.js +1 -0
  18. package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
  19. package/dist/background/retire-legacy-tasks.job.js +149 -0
  20. package/dist/background/session.d.ts +15 -5
  21. package/dist/background/session.js +22 -6
  22. package/dist/background/stop.d.ts +35 -5
  23. package/dist/background/stop.js +94 -8
  24. package/dist/background/store.d.ts +110 -3
  25. package/dist/background/store.js +205 -3
  26. package/dist/background/tasks.service.d.ts +18 -1
  27. package/dist/background/tasks.service.js +99 -9
  28. package/dist/catalog/marketplaces.service.d.ts +1 -1
  29. package/dist/channels/cards.js +1 -1
  30. package/dist/channels/inbound.js +2 -0
  31. package/dist/channels/phrases.d.ts +4 -0
  32. package/dist/channels/phrases.js +4 -0
  33. package/dist/config/load.d.ts +18 -0
  34. package/dist/config/load.js +39 -1
  35. package/dist/config/permission-migration.d.ts +26 -0
  36. package/dist/config/permission-migration.js +64 -0
  37. package/dist/config/schema.d.ts +1 -1
  38. package/dist/config/schema.js +11 -10
  39. package/dist/conversations/conversations.controller.d.ts +1 -1
  40. package/dist/conversations/conversations.controller.js +1 -1
  41. package/dist/conversations/conversations.module.js +12 -0
  42. package/dist/conversations/conversations.service.d.ts +11 -2
  43. package/dist/conversations/conversations.service.js +97 -27
  44. package/dist/conversations/event-log.d.ts +1 -1
  45. package/dist/conversations/event-log.js +10 -2
  46. package/dist/conversations/events.d.ts +304 -4
  47. package/dist/conversations/events.js +279 -29
  48. package/dist/conversations/permission-profile-store.d.ts +50 -0
  49. package/dist/conversations/permission-profile-store.js +67 -0
  50. package/dist/conversations/permission-profile-store.module.d.ts +2 -0
  51. package/dist/conversations/permission-profile-store.module.js +19 -0
  52. package/dist/conversations/permission-profiles.controller.d.ts +84 -0
  53. package/dist/conversations/permission-profiles.controller.js +105 -0
  54. package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
  55. package/dist/conversations/permission-profiles.schemas.js +23 -0
  56. package/dist/conversations/permission-profiles.service.d.ts +56 -0
  57. package/dist/conversations/permission-profiles.service.js +179 -0
  58. package/dist/db/kernel-schema.d.ts +238 -3
  59. package/dist/devices/access.js +1 -1
  60. package/dist/devices/access.module.d.ts +2 -0
  61. package/dist/devices/access.module.js +19 -0
  62. package/dist/devices/conversation-devices.d.ts +8 -29
  63. package/dist/devices/conversation-devices.js +37 -73
  64. package/dist/devices/device-projects.service.d.ts +26 -28
  65. package/dist/devices/device-projects.service.js +123 -127
  66. package/dist/devices/devices.controller.js +3 -1
  67. package/dist/devices/devices.module.js +11 -9
  68. package/dist/devices/devices.service.d.ts +116 -8
  69. package/dist/devices/devices.service.js +252 -20
  70. package/dist/devices/dto.d.ts +16 -0
  71. package/dist/devices/dto.js +34 -6
  72. package/dist/devices/errors.d.ts +8 -0
  73. package/dist/devices/errors.js +10 -0
  74. package/dist/devices/project-rules.d.ts +44 -0
  75. package/dist/devices/project-rules.js +27 -0
  76. package/dist/devices/working-root.d.ts +6 -0
  77. package/dist/devices/working-root.js +12 -1
  78. package/dist/errors.d.ts +31 -0
  79. package/dist/errors.js +31 -0
  80. package/dist/evals/reconstruct.d.ts +19 -2
  81. package/dist/evals/reconstruct.js +40 -2
  82. package/dist/evals/recorded-permission-context.d.ts +77 -0
  83. package/dist/evals/recorded-permission-context.js +151 -0
  84. package/dist/evals/recorded-tools.d.ts +10 -1
  85. package/dist/evals/recorded-tools.js +27 -3
  86. package/dist/evals/run-replay.d.ts +8 -2
  87. package/dist/evals/run-replay.js +18 -2
  88. package/dist/evals/trajectory.d.ts +1 -1
  89. package/dist/evals/worker.d.ts +10 -1
  90. package/dist/evals/worker.js +23 -14
  91. package/dist/http/api.module.js +2 -0
  92. package/dist/identity/accounts.d.ts +14 -1
  93. package/dist/identity/accounts.js +61 -5
  94. package/dist/identity/identity.module.js +2 -0
  95. package/dist/identity/settings.d.ts +28 -12
  96. package/dist/identity/settings.js +89 -33
  97. package/dist/index.d.ts +6 -0
  98. package/dist/index.js +5 -0
  99. package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
  100. package/dist/infra/cli/kernel-cli.module.js +5 -2
  101. package/dist/infra/cli/permission-cutover.d.ts +59 -0
  102. package/dist/infra/cli/permission-cutover.js +107 -0
  103. package/dist/infra/config/kernel-config.service.d.ts +2 -2
  104. package/dist/infra/config/kernel-config.service.js +31 -11
  105. package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
  106. package/dist/infra/database/startup-activation-transaction.js +242 -0
  107. package/dist/infra/database/transaction-host.d.ts +47 -0
  108. package/dist/infra/database/transaction-host.js +119 -0
  109. package/dist/infra/database/xact-lock.d.ts +1 -0
  110. package/dist/infra/database/xact-lock.js +6 -0
  111. package/dist/infra/outbox/registry.d.ts +39 -0
  112. package/dist/infra/outbox/registry.js +18 -0
  113. package/dist/kernel.module.js +2 -0
  114. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  115. package/dist/lifecycle/kernel-lifecycle.js +55 -28
  116. package/dist/local-devices/device-auth.js +1 -1
  117. package/dist/local-devices/device-policy.service.d.ts +35 -5
  118. package/dist/local-devices/device-policy.service.js +188 -13
  119. package/dist/local-devices/instance-bindings.d.ts +82 -0
  120. package/dist/local-devices/instance-bindings.js +304 -0
  121. package/dist/local-devices/keys.d.ts +5 -0
  122. package/dist/local-devices/keys.js +5 -0
  123. package/dist/local-devices/local-device-gateway.d.ts +19 -4
  124. package/dist/local-devices/local-device-gateway.js +185 -17
  125. package/dist/local-devices/local-device-provider.d.ts +42 -7
  126. package/dist/local-devices/local-device-provider.js +185 -10
  127. package/dist/local-devices/local-devices.module.d.ts +17 -2
  128. package/dist/local-devices/local-devices.module.js +49 -8
  129. package/dist/local-devices/machines.d.ts +35 -12
  130. package/dist/local-devices/machines.js +203 -8
  131. package/dist/local-devices/network-grants.js +3 -3
  132. package/dist/local-devices/network-grants.module.d.ts +2 -0
  133. package/dist/local-devices/network-grants.module.js +14 -0
  134. package/dist/local-devices/owner-report.d.ts +79 -0
  135. package/dist/local-devices/owner-report.js +155 -0
  136. package/dist/local-devices/owner-reports.d.ts +48 -0
  137. package/dist/local-devices/owner-reports.js +190 -0
  138. package/dist/local-devices/policy-summary.d.ts +24 -1
  139. package/dist/local-devices/policy-summary.js +48 -0
  140. package/dist/local-devices/relay.d.ts +82 -6
  141. package/dist/local-devices/relay.js +187 -16
  142. package/dist/local-devices/targets.d.ts +16 -1
  143. package/dist/local-devices/targets.js +35 -2
  144. package/dist/orgs/cloud-network-setting.d.ts +33 -0
  145. package/dist/orgs/cloud-network-setting.js +47 -0
  146. package/dist/orgs/offboarding.d.ts +3 -1
  147. package/dist/orgs/offboarding.js +8 -2
  148. package/dist/orgs/org-lock.d.ts +10 -4
  149. package/dist/orgs/org-lock.js +10 -4
  150. package/dist/orgs/orgs.service.d.ts +3 -1
  151. package/dist/orgs/orgs.service.js +8 -2
  152. package/dist/orgs/settings.controller.d.ts +4 -1
  153. package/dist/orgs/settings.controller.js +3 -3
  154. package/dist/orgs/settings.service.d.ts +48 -56
  155. package/dist/orgs/settings.service.js +144 -101
  156. package/dist/overrides.d.ts +6 -1
  157. package/dist/overrides.js +2 -0
  158. package/dist/platform/exclusions.js +20 -0
  159. package/dist/platform/ops/admin.ops.js +14 -11
  160. package/dist/platform/ops/agent-skills.ops.js +2 -0
  161. package/dist/platform/ops/devices.ops.js +10 -2
  162. package/dist/platform/ops/org-settings.ops.js +6 -6
  163. package/dist/platform/ops/orgs.ops.js +1 -0
  164. package/dist/roles/worker.module.js +4 -0
  165. package/dist/runtime/context/build.d.ts +3 -1
  166. package/dist/runtime/context/build.js +19 -3
  167. package/dist/runtime/context/compaction.js +5 -0
  168. package/dist/runtime/context/device-paths.d.ts +9 -2
  169. package/dist/runtime/context/device-paths.js +20 -0
  170. package/dist/runtime/context/permission-profile.d.ts +46 -0
  171. package/dist/runtime/context/permission-profile.js +194 -0
  172. package/dist/runtime/maintenance.d.ts +7 -1
  173. package/dist/runtime/maintenance.js +43 -15
  174. package/dist/runtime/model-call.d.ts +32 -0
  175. package/dist/runtime/model-call.js +67 -0
  176. package/dist/runtime/permission-context-errors.d.ts +39 -0
  177. package/dist/runtime/permission-context-errors.js +67 -0
  178. package/dist/runtime/permission-context.service.d.ts +60 -0
  179. package/dist/runtime/permission-context.service.js +286 -0
  180. package/dist/runtime/project/knowledge.d.ts +7 -2
  181. package/dist/runtime/project/knowledge.js +5 -2
  182. package/dist/runtime/project/knowledge.service.d.ts +17 -2
  183. package/dist/runtime/project/knowledge.service.js +76 -12
  184. package/dist/runtime/run-execution.d.ts +4 -1
  185. package/dist/runtime/run-execution.js +14 -5
  186. package/dist/runtime/run-steps.d.ts +11 -3
  187. package/dist/runtime/run-steps.js +27 -4
  188. package/dist/runtime/runtime.module.js +11 -0
  189. package/dist/sandbox/attachments-path.d.ts +15 -0
  190. package/dist/sandbox/attachments-path.js +15 -0
  191. package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
  192. package/dist/sandbox/cloud-permission-snapshot.js +407 -0
  193. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
  194. package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
  195. package/dist/sandbox/held-operations.d.ts +39 -0
  196. package/dist/sandbox/held-operations.js +119 -0
  197. package/dist/sandbox/jobs.d.ts +14 -3
  198. package/dist/sandbox/jobs.js +20 -2
  199. package/dist/sandbox/kernel-read.d.ts +55 -0
  200. package/dist/sandbox/kernel-read.js +57 -0
  201. package/dist/sandbox/legacy-retirement.d.ts +336 -0
  202. package/dist/sandbox/legacy-retirement.js +1063 -0
  203. package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
  204. package/dist/sandbox/legacy-retirement.module.js +25 -0
  205. package/dist/sandbox/managed-device-context.d.ts +94 -0
  206. package/dist/sandbox/managed-device-context.js +308 -0
  207. package/dist/sandbox/managed-device-context.module.d.ts +6 -0
  208. package/dist/sandbox/managed-device-context.module.js +33 -0
  209. package/dist/sandbox/modes.d.ts +56 -8
  210. package/dist/sandbox/modes.js +92 -8
  211. package/dist/sandbox/operation-authority-types.d.ts +8 -0
  212. package/dist/sandbox/operation-authority-types.js +32 -0
  213. package/dist/sandbox/operation-authority.d.ts +145 -0
  214. package/dist/sandbox/operation-authority.js +783 -0
  215. package/dist/sandbox/operation-authority.module.d.ts +2 -0
  216. package/dist/sandbox/operation-authority.module.js +29 -0
  217. package/dist/sandbox/operation-intents.d.ts +206 -0
  218. package/dist/sandbox/operation-intents.js +1252 -0
  219. package/dist/sandbox/operation-intents.module.d.ts +2 -0
  220. package/dist/sandbox/operation-intents.module.js +21 -0
  221. package/dist/sandbox/operation-payloads.d.ts +33 -0
  222. package/dist/sandbox/operation-payloads.js +332 -0
  223. package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
  224. package/dist/sandbox/operation-reconcile.job.js +247 -0
  225. package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
  226. package/dist/sandbox/permission-authority-epochs.js +83 -0
  227. package/dist/sandbox/permission-authority-lock.d.ts +38 -0
  228. package/dist/sandbox/permission-authority-lock.js +147 -0
  229. package/dist/sandbox/permission-authority.module.d.ts +9 -0
  230. package/dist/sandbox/permission-authority.module.js +55 -0
  231. package/dist/sandbox/permission-availability.d.ts +18 -0
  232. package/dist/sandbox/permission-availability.js +19 -0
  233. package/dist/sandbox/permission-call-grants.d.ts +34 -0
  234. package/dist/sandbox/permission-call-grants.js +349 -0
  235. package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
  236. package/dist/sandbox/permission-call-grants.module.js +21 -0
  237. package/dist/sandbox/permission-call-types.d.ts +82 -0
  238. package/dist/sandbox/permission-call-types.js +1 -0
  239. package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
  240. package/dist/sandbox/permission-ceiling-writes.js +223 -0
  241. package/dist/sandbox/permission-config-publication.d.ts +76 -0
  242. package/dist/sandbox/permission-config-publication.js +339 -0
  243. package/dist/sandbox/permission-context-types.d.ts +64 -0
  244. package/dist/sandbox/permission-context-types.js +24 -0
  245. package/dist/sandbox/permission-facts.d.ts +206 -0
  246. package/dist/sandbox/permission-facts.js +627 -0
  247. package/dist/sandbox/permission-facts.module.d.ts +2 -0
  248. package/dist/sandbox/permission-facts.module.js +20 -0
  249. package/dist/sandbox/permission-instance-writes.d.ts +90 -0
  250. package/dist/sandbox/permission-instance-writes.js +305 -0
  251. package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
  252. package/dist/sandbox/permission-runtime-reports.js +354 -0
  253. package/dist/sandbox/permission-transitions.d.ts +31 -0
  254. package/dist/sandbox/permission-transitions.js +155 -0
  255. package/dist/sandbox/platform-full-access.d.ts +128 -0
  256. package/dist/sandbox/platform-full-access.js +210 -0
  257. package/dist/sandbox/providers.d.ts +22 -0
  258. package/dist/sandbox/providers.js +10 -2
  259. package/dist/sandbox/providers.module.d.ts +2 -0
  260. package/dist/sandbox/providers.module.js +19 -0
  261. package/dist/sandbox/request-not-sent.d.ts +13 -0
  262. package/dist/sandbox/request-not-sent.js +13 -0
  263. package/dist/sandbox/review/classifier.d.ts +2 -0
  264. package/dist/sandbox/review/classifier.js +8 -0
  265. package/dist/sandbox/review/permission-candidate.d.ts +12 -0
  266. package/dist/sandbox/review/permission-candidate.js +129 -0
  267. package/dist/sandbox/review/review.service.d.ts +4 -1
  268. package/dist/sandbox/review/review.service.js +19 -5
  269. package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
  270. package/dist/sandbox/sandbox-file-reader.js +51 -7
  271. package/dist/sandbox/sandbox.module.js +26 -6
  272. package/dist/sandbox/sandbox.service.d.ts +230 -34
  273. package/dist/sandbox/sandbox.service.js +1368 -199
  274. package/dist/sandbox/unreachable.js +17 -3
  275. package/dist/sandbox/use-context.d.ts +17 -0
  276. package/dist/sandbox/use-context.js +1 -0
  277. package/dist/skills/invoke.d.ts +27 -4
  278. package/dist/skills/invoke.js +72 -7
  279. package/dist/tools/approvals.controller.d.ts +1 -0
  280. package/dist/tools/approvals.schemas.d.ts +1 -0
  281. package/dist/tools/approvals.schemas.js +3 -1
  282. package/dist/tools/approvals.service.d.ts +23 -10
  283. package/dist/tools/approvals.service.js +104 -26
  284. package/dist/tools/builtins/builtin-tools.d.ts +16 -2
  285. package/dist/tools/builtins/builtin-tools.js +38 -10
  286. package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
  287. package/dist/tools/builtins/sandbox/bash.js +201 -5
  288. package/dist/tools/builtins/sandbox/common.d.ts +92 -20
  289. package/dist/tools/builtins/sandbox/common.js +201 -17
  290. package/dist/tools/builtins/sandbox/deliver.js +2 -2
  291. package/dist/tools/builtins/sandbox/edit.js +2 -2
  292. package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
  293. package/dist/tools/builtins/sandbox/glob.js +2 -2
  294. package/dist/tools/builtins/sandbox/grep.js +2 -2
  295. package/dist/tools/builtins/sandbox/read.js +2 -2
  296. package/dist/tools/builtins/sandbox/task-list.js +7 -1
  297. package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
  298. package/dist/tools/builtins/sandbox/task-output.js +172 -0
  299. package/dist/tools/builtins/sandbox/task-stop.js +25 -3
  300. package/dist/tools/builtins/sandbox/write.js +2 -2
  301. package/dist/tools/builtins/skill-load.js +9 -6
  302. package/dist/tools/device-op-resolver.d.ts +1 -1
  303. package/dist/tools/device-op-resolver.js +13 -3
  304. package/dist/tools/permission-approval-jobs.d.ts +18 -0
  305. package/dist/tools/permission-approval-jobs.js +92 -0
  306. package/dist/tools/pipeline.d.ts +17 -2
  307. package/dist/tools/pipeline.js +300 -19
  308. package/dist/tools/registry.d.ts +9 -0
  309. package/dist/tools/tools.module.js +12 -0
  310. package/package.json +4 -3
  311. package/src/migrations/0146_permission_authority_epochs.sql +6 -0
  312. package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
  313. package/src/migrations/0148_first_message_request_hash.sql +2 -0
  314. package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
  315. package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
  316. package/src/migrations/0151_starting_execution_grants.sql +8 -0
  317. package/src/migrations/0152_background_launch_identity.sql +66 -0
  318. package/src/migrations/0153_background_cancel_requester.sql +13 -0
  319. package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
  320. package/src/migrations/0155_device_instance_generations.sql +30 -0
  321. package/src/migrations/0156_device_owner_report.sql +7 -0
  322. package/src/migrations/0157_legacy_retirement.sql +116 -0
  323. package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
  324. package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
  325. package/dist/sandbox/platform-auto-mode.d.ts +0 -63
  326. package/dist/sandbox/platform-auto-mode.js +0 -63
@@ -1,4 +1,4 @@
1
- import { readDevicesAutoMode } from "./platform-auto-mode.js";
1
+ import { readDevicesFullAccess } from "./platform-full-access.js";
2
2
  /** Whether the allowlist entry `pattern` admits `host` (`*.x.com`: subdomains, never the apex). */
3
3
  export const coversHost = (pattern, host) => pattern === host || (pattern.startsWith("*.") && host.endsWith(pattern.slice(1)));
4
4
  /**
@@ -41,8 +41,19 @@ export function orgCloudMode(limits, org) {
41
41
  * `sandbox.limits` network fields (in the caller's transaction when there is one).
42
42
  */
43
43
  export async function readDeploymentDevicePolicy(db, config) {
44
- const autoMode = await readDevicesAutoMode(db, config);
45
- return { autoMode: autoMode.mode, limits: config.get().sandbox.limits };
44
+ const fullAccess = await readDevicesFullAccess(db, config);
45
+ return { fullAccess: fullAccess.permission, limits: config.get().sandbox.limits };
46
+ }
47
+ /**
48
+ * How far restricted work may root outside the workspace now (B2), the one rule the command
49
+ * review (`DevicesService.projectReach`) and admission's working root both read: a local device
50
+ * follows its owner's reported reach within a device ceiling that allows auto; a cloud device
51
+ * reaches beyond its workspace only in auto mode.
52
+ */
53
+ export function projectReachOf(source, policy, ownerReach) {
54
+ if (source !== "local")
55
+ return policy.mode === "auto" ? "os-user" : "workspace";
56
+ return policy.allowedMode === "auto" && ownerReach === "os-user" ? "os-user" : "workspace";
46
57
  }
47
58
  /** The mode the platform and the org allow: `auto` only when neither turns it off. */
48
59
  export function allowedDeviceMode(platform, org) {
@@ -73,28 +84,80 @@ export function deviceNetwork(deployment, org, mode) {
73
84
  * reported mode; null = follow the platform and the org). A stored mode the ceiling forbids is cut,
74
85
  * never honoured; the network follows the resulting mode.
75
86
  */
76
- export function effectiveDevicePolicy(deployment, org, deviceMode) {
77
- const allowedMode = allowedDeviceMode(deployment.autoMode, org.autoMode);
87
+ export function effectiveDevicePolicy(deployment, org, deviceMode,
88
+ /** A cloud device's B1 outer network snapshot: the network never goes beyond it. */
89
+ outer = null) {
90
+ const allowedMode = allowedDeviceMode(deployment.fullAccess, org.fullAccess);
78
91
  const mode = allowedMode === "sandbox" ? "sandbox" : (deviceMode ?? "auto");
79
92
  const modeSource = mode === "sandbox"
80
93
  ? deviceMode === "sandbox" && allowedMode === "auto"
81
94
  ? "device"
82
- : deployment.autoMode === "allowed"
95
+ : deployment.fullAccess === "allowed"
83
96
  ? "org"
84
97
  : "platform"
85
98
  : deviceMode === "auto"
86
99
  ? "device"
87
- : org.autoMode === "allowed"
100
+ : org.fullAccess === "allowed"
88
101
  ? "org"
89
102
  : "platform";
90
103
  return {
91
104
  mode,
92
105
  allowedMode,
93
106
  modeSource,
94
- network: deviceNetwork(deployment, org, mode),
107
+ network: outer === null
108
+ ? deviceNetwork(deployment, org, mode)
109
+ : intersectNetworks(deviceNetwork(deployment, org, mode), outer),
95
110
  localAllowedDomains: orgAllowedDomains(deployment, org),
96
111
  };
97
112
  }
113
+ /** A network with its hosts lowercased, sorted and deduplicated (`open-public` carries none). */
114
+ export const normalizeNetwork = (n) => n.kind === "open-public"
115
+ ? { kind: "open-public", hosts: [] }
116
+ : { kind: "allowlist", hosts: [...new Set(n.hosts.map((h) => h.toLowerCase()))].sort() };
117
+ /**
118
+ * The narrower of two networks (B1): the open public network is no limit; two allowlists keep the
119
+ * hosts (or wildcards) of each that the other covers. Never wider than either.
120
+ */
121
+ export function intersectNetworks(a, b) {
122
+ if (a.kind === "open-public")
123
+ return normalizeNetwork(b);
124
+ if (b.kind === "open-public")
125
+ return normalizeNetwork(a);
126
+ const x = normalizeNetwork(a).hosts;
127
+ const y = normalizeNetwork(b).hosts;
128
+ return normalizeNetwork({
129
+ kind: "allowlist",
130
+ hosts: [
131
+ ...x.filter((h) => y.some((p) => coversHost(p, h))),
132
+ ...y.filter((h) => x.some((p) => coversHost(p, h))),
133
+ ],
134
+ });
135
+ }
136
+ /** Whether `a` and `b` are the same mode, network kind and host set (null is never the same). */
137
+ export const sameAppliedExactly = (a, b) => a != null &&
138
+ a.mode === b.mode &&
139
+ JSON.stringify(normalizeNetwork(a.network)) === JSON.stringify(normalizeNetwork(b.network));
140
+ /**
141
+ * The B1 snapshot of a cloud device from its old effective policy (computed by the old algorithm,
142
+ * `egress: none` included): Full where the old mode was auto, the old effective network as the
143
+ * outer boundary. Known applied limits narrow it by intersection, never widen it: an instance that
144
+ * really ran stricter keeps that boundary (`applied` null: unknown, nothing to intersect).
145
+ */
146
+ export function cloudSnapshotOf(old, applied = null) {
147
+ const fullAccess = old.mode === "auto" && (applied === null || applied.mode === "auto");
148
+ return {
149
+ fullAccess,
150
+ outerNetwork: applied === null
151
+ ? normalizeNetwork(old.network)
152
+ : intersectNetworks(old.network, applied.network),
153
+ };
154
+ }
155
+ /**
156
+ * The mode a cloud device chose: the narrower of its old narrowing switch and its B1 owner
157
+ * ceiling (false narrows to sandbox, true or not snapshotted follows the platform and the org). An
158
+ * explicit sandbox switch (an old replica's write included) is never overridden.
159
+ */
160
+ export const cloudChosenMode = (row) => row.mode === "sandbox" || row.owner_full_access === false ? "sandbox" : null;
98
161
  /** The {@link AppliedLimits} of `limits`. */
99
162
  export const appliedOf = (limits) => ({
100
163
  mode: limits.mode,
@@ -102,6 +165,27 @@ export const appliedOf = (limits) => ({
102
165
  });
103
166
  /** Whether `a` and `b` are the same mode and network kind (null, unknown, is never the same). */
104
167
  export const sameApplied = (a, b) => a != null && a.mode === b.mode && a.network.kind === b.network.kind;
168
+ /** Whether `a` and `b` are the same mode, network kind and host set (null is never the same). */
169
+ export const sameAppliedExact = (a, b) => sameApplied(a, b) &&
170
+ [...new Set(a?.network.hosts ?? [])].sort().join("\n") ===
171
+ [...new Set(b.network.hosts)].sort().join("\n");
172
+ /**
173
+ * Whether applied limits `a` are more permissive than desired limits `b` in any dimension (spec
174
+ * §124): auto where `b` is sandbox, open public addresses where `b` is an allowlist, or an
175
+ * allowlisted host `b`'s allowlist does not cover. Narrower or equal is false; unknown (null) is
176
+ * false here (callers treat unknown separately).
177
+ */
178
+ export function appliedWider(a, b) {
179
+ if (a == null)
180
+ return false;
181
+ if (a.mode === "auto" && b.mode === "sandbox")
182
+ return true;
183
+ if (b.network.kind === "open-public")
184
+ return false;
185
+ if (a.network.kind === "open-public")
186
+ return true;
187
+ return a.network.hosts.some((host) => !b.network.hosts.some((p) => coversHost(p, host)));
188
+ }
105
189
  const isMode = (v) => v === "auto" || v === "sandbox";
106
190
  function appliedFrom(v) {
107
191
  if (typeof v !== "object" || v === null)
@@ -0,0 +1,8 @@
1
+ import { type DeviceExecGrants } from "@capybara-hq/plugin-sdk";
2
+ export declare const isExecutionMethod: (method: string) => method is "exec" | "backgroundStart";
3
+ /** Null column means absent historical/native provenance; grants:null records an explicit absence. */
4
+ export interface StartingExecutionGrants {
5
+ version: 1;
6
+ grants: DeviceExecGrants | null;
7
+ }
8
+ export declare function parseStartingExecutionGrants(value: unknown): StartingExecutionGrants;
@@ -0,0 +1,32 @@
1
+ import { validateAllowHost } from "@capybara-hq/plugin-sdk";
2
+ export const isExecutionMethod = (method) => method === "exec" || method === "backgroundStart";
3
+ export function parseStartingExecutionGrants(value) {
4
+ const record = (v, keys) => {
5
+ if (!v ||
6
+ typeof v !== "object" ||
7
+ Array.isArray(v) ||
8
+ Object.keys(v).some((k) => !keys.includes(k)))
9
+ throw new Error("Missing or invalid starting execution provenance; check the original admission before retrying");
10
+ return v;
11
+ };
12
+ const o = record(value, ["version", "grants"]);
13
+ if (o.version !== 1)
14
+ throw new Error("Unknown starting execution provenance; check the original admission");
15
+ if (o.grants === null)
16
+ return { version: 1, grants: null };
17
+ const g = record(o.grants, ["hosts", "source"]), source = record(g.source, ["kind", "id", "accountId"]);
18
+ if (!Array.isArray(g.hosts) ||
19
+ g.hosts.length > 100 ||
20
+ g.hosts.some((h) => typeof h !== "string" || h.startsWith("*.") || validateAllowHost(h).length) ||
21
+ new Set(g.hosts).size !== g.hosts.length ||
22
+ !["run", "task"].includes(String(source.kind)) ||
23
+ [source.id, source.accountId].some((v) => typeof v !== "string" || !v.length || v.length > 128))
24
+ throw new Error("Invalid starting grant source or hosts; check the original admission");
25
+ return {
26
+ version: 1,
27
+ grants: {
28
+ hosts: [...g.hosts],
29
+ source: source,
30
+ },
31
+ };
32
+ }
@@ -0,0 +1,145 @@
1
+ import { type PermissionProfile, type SandboxActor, type SandboxBrowseScope, type SandboxOperationScope } from "@capybara-hq/plugin-sdk";
2
+ import { type PermissionContextV1 } from "../conversations/events.js";
3
+ import { PermissionProfileStore } from "../conversations/permission-profile-store.js";
4
+ import { KernelDb } from "../infra/database/kernel-db.js";
5
+ import { TransactionHost } from "../infra/database/transaction-host.js";
6
+ import { NetworkGrants } from "../local-devices/network-grants.js";
7
+ import { type KernelReadInvocation, type KernelReadMethod } from "./kernel-read.js";
8
+ import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
9
+ import { PermissionAuthorityLock } from "./permission-authority-lock.js";
10
+ import { PermissionCallGrants } from "./permission-call-grants.js";
11
+ import type { PermissionCallRef, PermissionReviewSnapshot } from "./permission-call-types.js";
12
+ import { PermissionConfigPublication } from "./permission-config-publication.js";
13
+ import { type PermissionContextSubject } from "./permission-context-types.js";
14
+ import { PermissionFacts } from "./permission-facts.js";
15
+ import type { SandboxUseContext } from "./use-context.js";
16
+ export type SandboxAuthorityOperation = "exec" | "readFile" | "writeFile" | "stat" | "list" | "scan" | "backgroundStart";
17
+ export interface PermissionScopeFacts {
18
+ operationId: string;
19
+ admitBeforeMs: number;
20
+ deviceId: string;
21
+ rootConversationId: string;
22
+ profileRevision: number;
23
+ ceilingRevision: string;
24
+ profile: PermissionProfile;
25
+ actor: SandboxActor;
26
+ tag: string;
27
+ workingRoot: string;
28
+ readRoots: readonly string[];
29
+ writeRoots: readonly string[];
30
+ allowedHosts: readonly string[];
31
+ fullAccessCeiling: boolean;
32
+ fullConsent?: boolean;
33
+ }
34
+ /** Only server-resolved facts enter this constructor; callers never submit roots or profile. */
35
+ export declare function intersectPermissionScope(f: PermissionScopeFacts): SandboxOperationScope;
36
+ /** Fresh authority shape only. Provider dispatch must add durable admission fencing before use. */
37
+ export declare class SandboxOperationAuthority {
38
+ private readonly callGrants;
39
+ private readonly publication;
40
+ private readonly db;
41
+ readonly txHost: TransactionHost;
42
+ private readonly profiles;
43
+ private readonly facts;
44
+ private readonly grants;
45
+ private readonly locks;
46
+ private readonly epochs;
47
+ constructor(callGrants: PermissionCallGrants, publication: PermissionConfigPublication, db: KernelDb, txHost: TransactionHost, profiles: PermissionProfileStore, facts: PermissionFacts, grants: NetworkGrants, locks: PermissionAuthorityLock, epochs: PermissionAuthorityEpochStore);
48
+ /** Owner project browsing has no conversation, profile, or fabricated root identity. */
49
+ resolveBrowse(ctx: {
50
+ orgId: string;
51
+ deviceId: string;
52
+ accountId: string;
53
+ }, signal: AbortSignal): Promise<SandboxBrowseScope>;
54
+ /**
55
+ * The one actor liveness predicate of owner browsing, the recorded permission context and the
56
+ * managed device context writer: an active account that is still a member of a live org.
57
+ */
58
+ isActiveMember(orgId: string, accountId: string): Promise<boolean>;
59
+ subjectFor(ctx: SandboxUseContext): Promise<{
60
+ orgId: string;
61
+ deviceId: string;
62
+ rootConversationId: string;
63
+ }>;
64
+ previewCall(ctx: SandboxUseContext, call: PermissionCallRef, signal: AbortSignal): Promise<PermissionReviewSnapshot>;
65
+ private previewLocked;
66
+ resolve(ctx: SandboxUseContext, operation: SandboxAuthorityOperation, signal: AbortSignal): Promise<SandboxOperationScope>;
67
+ resolveInvocation(ctx: SandboxUseContext, operation: SandboxAuthorityOperation, call: PermissionCallRef, signal: AbortSignal): Promise<{
68
+ scope: SandboxOperationScope;
69
+ permissionGrantId: string | null;
70
+ grantedHosts: string[];
71
+ executionGrants: import("./operation-authority-types.js").StartingExecutionGrants | null;
72
+ }>;
73
+ /**
74
+ * The scope of one kernel read (permission activation L2, Hook 1): the conversation's profile
75
+ * scope from the same authority snapshot admission reads, with the bound project as the working
76
+ * root it becomes once read (the review's fallbacks apply: a root outside the mode or above the
77
+ * home is refused), intersected with the one path the read may reach
78
+ * ({@link kernelReadRoot}: the root's `stat`, `AGENTS.md`, `.agents/skills/**`). The restricted
79
+ * {@link KERNEL_READ_PROFILE} whenever the runtime enforces it (the runtime then enforces the
80
+ * read root, symlinks included); the conversation's admitted Full access only on an isolated
81
+ * Full-only runtime; a host machine without restricted enforcement throws
82
+ * {@link KernelReadUnsupported} ({@link kernelReadRoute}). No write roots, no hosts, never a
83
+ * per-call grant. Called under the run start's claim only (the intents
84
+ * check that its run is still `queued`).
85
+ */
86
+ resolveKernelRead(ctx: SandboxUseContext, read: Pick<KernelReadInvocation, "purpose" | "root">, method: KernelReadMethod, path: string, signal: AbortSignal): Promise<SandboxOperationScope>;
87
+ /**
88
+ * Whether the device's runtime is isolated from its host's files (a kernel read may then go
89
+ * under the conversation's Full access on a Full-only runtime): a cloud device, or a local
90
+ * machine whose authenticated connection recorded its Docker mode (`device_machines.mode`,
91
+ * written at hello; a mode change resets the device's files).
92
+ */
93
+ private isolatedRuntime;
94
+ private scopeOf;
95
+ private snapshot;
96
+ /**
97
+ * The actual run of an operation or context read: still this conversation's, triggered by this
98
+ * actor and not ended; true when it serves a scheduled task run (an unattended child or wake
99
+ * included). Shared by admission and the recorded permission context.
100
+ */
101
+ private runScheduledLocked;
102
+ /**
103
+ * The call-independent base authority of a device for one root (B1): the device's policy and
104
+ * owner facts, its working root (the validated project binding, else the recorded or reported
105
+ * workspace) and the restricted base hosts after the owner and organization ceilings, including
106
+ * the run's network grants and an unattended run's explicit task grants. No call expansion, no
107
+ * operation, no provider call. Admission and the recorded permission context both read it here.
108
+ */
109
+ private baseScopeLocked;
110
+ /**
111
+ * The working root of the base authority (B1), decided exactly as the command review decides it
112
+ * (`devices/working-root.ts` `workingRootOf`, permission activation L2): the bound project's
113
+ * root when the root conversation's latest `project_root` snapshot is usable and names that
114
+ * root, else the recorded or reported workspace. A bound project before its first snapshot, an
115
+ * unavailable one, one outside the workspace without the os-user reach and one above the
116
+ * owner's home all work in the workspace, so a call the review judged against the workspace is
117
+ * not stale at admission. Narrowing only: no root other than the binding's or the workspace is
118
+ * ever named. `projectUsable` (a kernel read of the bound project) takes the binding as its
119
+ * snapshot. `projectRoot` is the bound project path when it is the working root, else null.
120
+ * Admission, the recorded permission context and the managed device context evidence all
121
+ * resolve it here, so none of them can name a wider root than admission.
122
+ */
123
+ private workingRootOf;
124
+ /**
125
+ * The base working root of the calling conversation's tree on `deviceId` (see
126
+ * {@link workingRootOf}): read without locks as a managed operation's held evidence, and again
127
+ * under the complete authority subject by the managed device context writer, which compares the
128
+ * two. Throws `conflict` when the project binding no longer matches the device.
129
+ */
130
+ workingRootFor(input: {
131
+ orgId: string;
132
+ deviceId: string;
133
+ conversationId: string;
134
+ }): Promise<string>;
135
+ /**
136
+ * The recorded permission context of a run's next request (B1): the same base facts admission
137
+ * reads, projected without any call, operation, grant expansion or provider effect. The caller
138
+ * already holds the complete authority subject (platform, org, device when selected, root) in
139
+ * this transaction; a subject those locks do not cover throws
140
+ * {@link PermissionContextSubjectChanged}. A missing or inaccessible actor, root or run throws
141
+ * (no request is sent); a device this actor cannot use is the logged access refusal; device
142
+ * states admission refuses are unsupported or unprobed contexts without a scope.
143
+ */
144
+ readContextLocked(input: PermissionContextSubject, signal: AbortSignal): Promise<PermissionContextV1>;
145
+ }