@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
@@ -22,7 +22,7 @@ import { audit } from "../identity/audit.js";
22
22
  import { sha256Hex } from "../identity/hash.js";
23
23
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
24
24
  import { KernelDb } from "../infra/database/kernel-db.js";
25
- import { TransactionHost } from "../infra/database/transaction-host.js";
25
+ import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
26
26
  import { Transactional } from "../infra/database/transactional.decorator.js";
27
27
  import { KERNEL_LOGGER } from "../infra/tokens.js";
28
28
  import { DevicePolicyService } from "../local-devices/device-policy.service.js";
@@ -31,12 +31,18 @@ import { UNKNOWN_RESULT_TEXT } from "../runtime/context/pairing.js";
31
31
  import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookScope, } from "../runtime/hook-calls.js";
32
32
  import { subagentWaitingIdemKey } from "../runtime/loop.js";
33
33
  import { assistantIdemKey, MAX_STEP_MODEL_CALLS, modelCallIdemKey } from "../runtime/model-call.js";
34
+ import { currentExecutionClaim } from "../runtime/run-execution.js";
34
35
  import { rootSurfaceOf } from "../runtime/subagents/child.js";
35
36
  import { SubagentMessages } from "../runtime/subagents/messages.js";
36
37
  import { pairStoppedForks } from "../runtime/subagents/skill-fork.js";
37
38
  import { SubagentsService } from "../runtime/subagents/subagents.service.js";
38
39
  import { orgHostOutsideCeiling } from "../sandbox/modes.js";
40
+ import { SandboxOperationAuthority } from "../sandbox/operation-authority.js";
41
+ import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
42
+ import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
43
+ import { permissionScopeHash } from "../sandbox/permission-facts.js";
39
44
  import { isSessionGrantableRule, } from "../sandbox/review/index.js";
45
+ import { buildPermissionCandidate } from "../sandbox/review/permission-candidate.js";
40
46
  import { CommandReviewService } from "../sandbox/review/review.service.js";
41
47
  import { appendMissingGrant, connectionGrantKey, UNATTENDED_CONNECTION_ERROR, UNATTENDED_ELICITATION_NOTE, UNATTENDED_QUESTION_ERROR, unattendedFails, unattendedRunOf, } from "../schedules/unattended.js";
42
48
  import { skillLoadOfferedIn } from "../skills/catalog.js";
@@ -157,6 +163,20 @@ const personalMissingText = (connectorName) => `The user has not connected ${con
157
163
  const orgMissingText = (connectorName) => `${connectorName} has no organization credential configured; ask an organization admin to set it up.`;
158
164
  /** Optional provider: the pipeline's {@link ToolPipelineHooks} (tests). */
159
165
  export const TOOL_PIPELINE_HOOKS = Symbol("TOOL_PIPELINE_HOOKS");
166
+ /** Review usage and hooks retain the same tree ancestry on both review routes. */
167
+ function reviewParentOf(parent) {
168
+ return parent === undefined
169
+ ? {}
170
+ : {
171
+ parentRunId: parent.runId,
172
+ ...(parent.budgetRunId !== undefined && { budgetRunId: parent.budgetRunId }),
173
+ parent: {
174
+ conversationId: parent.conversationId,
175
+ runId: parent.runId,
176
+ callId: parent.callId,
177
+ },
178
+ };
179
+ }
160
180
  /**
161
181
  * The tools the command review covers (auto mode spec §5.1): the shell and the file tools whose
162
182
  * writes may leave the workspace. Any other tool call is not reviewed (the review service answers
@@ -315,6 +335,9 @@ const inputWait = (q) => ({
315
335
  let ToolPipeline = class ToolPipeline {
316
336
  config;
317
337
  txHost;
338
+ permissionAuthority;
339
+ permissionGrants;
340
+ permissionLocks;
318
341
  decide;
319
342
  deps;
320
343
  constructor(kdb, eventLog,
@@ -327,9 +350,12 @@ let ToolPipeline = class ToolPipeline {
327
350
  /** The command review (auto mode spec §5.4); absent in hand-built pipelines. */
328
351
  review,
329
352
  /** The reviewed call's device facts; absent in hand-built pipelines. */
330
- devices) {
353
+ devices, permissionAuthority, permissionGrants, permissionLocks) {
331
354
  this.config = config;
332
355
  this.txHost = txHost;
356
+ this.permissionAuthority = permissionAuthority;
357
+ this.permissionGrants = permissionGrants;
358
+ this.permissionLocks = permissionLocks;
333
359
  this.deps = {
334
360
  get db() {
335
361
  return kdb.db;
@@ -668,7 +694,7 @@ let ToolPipeline = class ToolPipeline {
668
694
  return fail(reviewed.content, outKey);
669
695
  }
670
696
  review = reviewed.review;
671
- const reviewedWorkingRoot = reviewed.workingRoot;
697
+ const reviewedRoots = { workingRoot: reviewed.workingRoot, against: reviewed.reviewedAgainst };
672
698
  if (reviewed.commandAsk !== undefined)
673
699
  authorization = approvalAuthorization(reviewed.commandAsk);
674
700
  // tool.preExecute after policy and approval, before tool_call_started (F10)
@@ -801,11 +827,24 @@ let ToolPipeline = class ToolPipeline {
801
827
  type: "tool_call_started",
802
828
  runId: ctx.runId,
803
829
  idemKey: idem.started(ctx.runId, call.id, attempt),
804
- payload: { step: ctx.step, callId: call.id, toolKey: tool.key, specHash: tool.specHash },
830
+ payload: {
831
+ step: ctx.step,
832
+ callId: call.id,
833
+ toolKey: tool.key,
834
+ specHash: tool.specHash,
835
+ ...(this.operationScoped(tool)
836
+ ? {
837
+ permissionInput: {
838
+ callInputHash: permissionScopeHash(call.input),
839
+ resolvedInputHash: permissionScopeHash(input),
840
+ },
841
+ }
842
+ : {}),
843
+ },
805
844
  },
806
845
  ]);
807
846
  const t0 = Date.now();
808
- let outcome = await this.execute(tool, input, ctx, call.id, resume, resolved.tools, reviewedWorkingRoot);
847
+ let outcome = await this.execute(tool, input, ctx, call.id, resume, resolved.tools, reviewedRoots);
809
848
  const durationMs = Date.now() - t0;
810
849
  await this.deps.hooks?.afterExecute?.(ctx.runId, call.id);
811
850
  // scheduled tasks spec §7, `fail` mode: no one answers an input request or connects an app
@@ -953,6 +992,11 @@ let ToolPipeline = class ToolPipeline {
953
992
  * asked is the whole truth on a resume: the call is never reviewed twice.
954
993
  */
955
994
  async reviewCall(ctx, call, tool, input) {
995
+ if (this.operationScoped(tool)) {
996
+ const scoped = await this.reviewPermissionCall(ctx, call, tool, input);
997
+ if (scoped)
998
+ return scoped;
999
+ }
956
1000
  const review = this.deps.review;
957
1001
  const devices = this.deps.devices;
958
1002
  if (review === undefined || devices === undefined)
@@ -961,7 +1005,7 @@ let ToolPipeline = class ToolPipeline {
961
1005
  return { kind: "continue" };
962
1006
  const asked = await this.deps.approvals.commandForCall(ctx.runId, call.id);
963
1007
  const rootConversationId = ctx.parent?.rootConversationId ?? ctx.conversationId;
964
- if (asked !== null) {
1008
+ if (asked !== null && asked.status !== "superseded") {
965
1009
  const settled = this.settledCommandAsk(asked, tool.key);
966
1010
  // an approved call runs in the root it was reviewed against only while the device still runs
967
1011
  // in the mode recorded with the ask; otherwise the tool decides its working root afresh. A
@@ -972,6 +1016,7 @@ let ToolPipeline = class ToolPipeline {
972
1016
  if (now === null ||
973
1017
  now.mode !== asked.command?.mode ||
974
1018
  carriedRoot({ workspace: now.workspace, workingRoot: settled.workingRoot }) === undefined) {
1019
+ // the root the person approved stays the one judged (B-18): only the carried root goes
975
1020
  return { ...settled, workingRoot: undefined };
976
1021
  }
977
1022
  }
@@ -1012,21 +1057,18 @@ let ToolPipeline = class ToolPipeline {
1012
1057
  step: ctx.step,
1013
1058
  callId: call.id,
1014
1059
  signal: ctx.signal,
1015
- ...(ctx.parent !== undefined && {
1016
- parentRunId: ctx.parent.runId,
1017
- ...(ctx.parent.budgetRunId !== undefined && { budgetRunId: ctx.parent.budgetRunId }),
1018
- parent: {
1019
- conversationId: ctx.parent.conversationId,
1020
- runId: ctx.parent.runId,
1021
- callId: ctx.parent.callId,
1022
- },
1023
- }),
1060
+ ...reviewParentOf(ctx.parent),
1024
1061
  agentId: ctx.agentId,
1025
1062
  agentVersion: ctx.agentVersion,
1026
1063
  ...(ctx.conversationKind !== undefined && { conversationKind: ctx.conversationKind }),
1027
1064
  });
1028
1065
  if (verdict.decision === "allow") {
1029
- return { kind: "continue", review: allowRecord(verdict), workingRoot: carriedRoot(facts) };
1066
+ return {
1067
+ kind: "continue",
1068
+ review: allowRecord(verdict),
1069
+ workingRoot: carriedRoot(facts),
1070
+ reviewedAgainst: facts.workingRoot,
1071
+ };
1030
1072
  }
1031
1073
  if (verdict.decision === "deny") {
1032
1074
  return {
@@ -1094,6 +1136,215 @@ let ToolPipeline = class ToolPipeline {
1094
1136
  }
1095
1137
  return { kind: "wait", wait: approvalWait(ask) };
1096
1138
  }
1139
+ operationScoped(tool) {
1140
+ return tool.source.kind === "builtin" && this.deps.permissionOperations?.has(tool.key) === true;
1141
+ }
1142
+ /** This branch is unreachable for production legacy handlers until the caller cutover. */
1143
+ async reviewPermissionCall(ctx, call, tool, input) {
1144
+ if (!this.permissionAuthority ||
1145
+ !this.permissionGrants ||
1146
+ !this.permissionLocks ||
1147
+ !this.deps.devices ||
1148
+ !this.deps.review)
1149
+ return null;
1150
+ const permissionLocks = this.permissionLocks;
1151
+ const previous = await this.deps.approvals.commandForCall(ctx.runId, call.id);
1152
+ // A settled refusal belongs to this call, not to a replaceable permission revision.
1153
+ if (previous && !["pending", "approved", "superseded"].includes(previous.status))
1154
+ return this.settledCommandAsk(previous, tool.key);
1155
+ const device = await this.deps.devices.reviewFacts(ctx.orgId, ctx.parent?.rootConversationId ?? ctx.conversationId, ctx.conversationId);
1156
+ if (!device)
1157
+ return null;
1158
+ const use = {
1159
+ orgId: ctx.orgId,
1160
+ deviceId: device.deviceId,
1161
+ holderConversationId: ctx.conversationId,
1162
+ actor: { accountId: ctx.accountId, conversationId: ctx.conversationId, runId: ctx.runId },
1163
+ };
1164
+ const facts = await this.permissionAuthority.previewCall(use, { runId: ctx.runId, callId: call.id }, ctx.signal);
1165
+ if (facts.availability.state !== "supported" || facts.unattended)
1166
+ return null;
1167
+ if (tool.key === "Bash" && textField(input, "command").length > COMMAND_ASK_MAX_CHARS)
1168
+ return {
1169
+ kind: "result",
1170
+ content: commandTooLongText(textField(input, "command").length),
1171
+ review: denyRecord("rule", null, "The command exceeds the review limit"),
1172
+ };
1173
+ const built = facts.profile === "full-access"
1174
+ ? { kind: "in-scope" }
1175
+ : buildPermissionCandidate({
1176
+ toolKey: tool.key,
1177
+ specHash: tool.specHash,
1178
+ rawInput: call.input,
1179
+ validatedInput: input,
1180
+ }, facts);
1181
+ if (built.kind === "unsupported")
1182
+ return {
1183
+ kind: "result",
1184
+ content: built.message,
1185
+ review: denyRecord("rule", null, built.message),
1186
+ };
1187
+ const candidate = built.kind === "proposal" ? built.candidate : undefined;
1188
+ if (previous &&
1189
+ previous.status !== "superseded" &&
1190
+ candidate &&
1191
+ previous.command?.permissionCandidate?.candidateHash === candidate.candidateHash) {
1192
+ if (previous.status !== "approved")
1193
+ return this.settledCommandAsk(previous, tool.key);
1194
+ const grant = await withTransactionFencePrelude(() => permissionLocks.acquire({
1195
+ orgId: facts.orgId,
1196
+ deviceId: facts.deviceId,
1197
+ rootConversationId: facts.rootConversationId,
1198
+ }, { kind: "admit" }), () => this.findPermissionGrant(candidate));
1199
+ if (grant)
1200
+ return this.settledCommandAsk(previous, tool.key);
1201
+ }
1202
+ if (candidate) {
1203
+ const existingGrant = await withTransactionFencePrelude(() => permissionLocks.acquire({
1204
+ orgId: facts.orgId,
1205
+ deviceId: facts.deviceId,
1206
+ rootConversationId: facts.rootConversationId,
1207
+ }, { kind: "admit" }), () => this.findPermissionGrant(candidate));
1208
+ if (existingGrant) {
1209
+ if (permissionScopeHash(existingGrant.expansion) !==
1210
+ permissionScopeHash(candidate.permissionScope))
1211
+ return {
1212
+ kind: "result",
1213
+ content: "This call already has different permission evidence; submit a new call with the intended directory scope.",
1214
+ review: denyRecord("rule", null, "Conflicting permission evidence"),
1215
+ };
1216
+ return {
1217
+ kind: "continue",
1218
+ workingRoot: carriedRoot(device),
1219
+ reviewedAgainst: facts.workingRoot,
1220
+ review: {
1221
+ decision: "allow",
1222
+ by: "classifier",
1223
+ rule: null,
1224
+ reason: "The exact current call already has approved permission evidence.",
1225
+ profile: facts.profile,
1226
+ profileRevision: facts.profileRevision,
1227
+ scopeRevision: facts.scopeRevision,
1228
+ decisionSource: "review-model",
1229
+ },
1230
+ };
1231
+ }
1232
+ }
1233
+ const verdict = await this.deps.review.review({
1234
+ orgId: ctx.orgId,
1235
+ conversationId: facts.rootConversationId,
1236
+ runId: ctx.runId,
1237
+ accountId: ctx.accountId,
1238
+ toolKey: tool.key,
1239
+ input,
1240
+ mode: device.mode,
1241
+ workspace: facts.workingRoot,
1242
+ home: device.home,
1243
+ deviceHome: device.deviceHome,
1244
+ attended: true,
1245
+ step: ctx.step,
1246
+ callId: call.id,
1247
+ signal: ctx.signal,
1248
+ ...reviewParentOf(ctx.parent),
1249
+ agentId: ctx.agentId,
1250
+ agentVersion: ctx.agentVersion,
1251
+ ...(ctx.conversationKind ? { conversationKind: ctx.conversationKind } : {}),
1252
+ permissionProfile: facts.profile,
1253
+ ...(candidate ? { permissionCandidate: candidate } : {}),
1254
+ });
1255
+ if (candidate && facts.profile === "approve-for-me") {
1256
+ await withTransactionFencePrelude(() => permissionLocks.acquire({
1257
+ orgId: facts.orgId,
1258
+ deviceId: facts.deviceId,
1259
+ rootConversationId: facts.rootConversationId,
1260
+ }, { kind: "admit" }), () => this.recordPermissionReview(candidate, verdict));
1261
+ }
1262
+ const provenance = {
1263
+ profile: facts.profile,
1264
+ profileRevision: facts.profileRevision,
1265
+ scopeRevision: facts.scopeRevision,
1266
+ };
1267
+ if (verdict.decision === "deny")
1268
+ return {
1269
+ kind: "result",
1270
+ content: commandDeniedText(verdict.reason, reviewKindOf(tool.key)),
1271
+ review: { ...denyRecord(verdict.by, verdict.rule, verdict.reason), ...provenance },
1272
+ };
1273
+ if (verdict.decision === "allow")
1274
+ return {
1275
+ kind: "continue",
1276
+ workingRoot: carriedRoot(device),
1277
+ reviewedAgainst: facts.workingRoot,
1278
+ review: {
1279
+ ...allowRecord(verdict),
1280
+ ...provenance,
1281
+ decisionSource: facts.profile === "full-access" ? "full-access" : candidate ? "review-model" : "scope",
1282
+ },
1283
+ };
1284
+ if (!candidate)
1285
+ return {
1286
+ kind: "result",
1287
+ content: "Current permission review could not decide; retry with an explicit bounded directory or host.",
1288
+ review: denyRecord(verdict.by, verdict.rule, verdict.reason),
1289
+ };
1290
+ const ask = await this.deps.approvals.requestCommand({
1291
+ orgId: ctx.orgId,
1292
+ conversationId: ctx.conversationId,
1293
+ runId: ctx.runId,
1294
+ step: ctx.step,
1295
+ callId: call.id,
1296
+ requestedFor: ctx.accountId,
1297
+ scopes: ["once"],
1298
+ detail: {
1299
+ deviceId: device.deviceId,
1300
+ deviceName: device.deviceName,
1301
+ mode: device.mode,
1302
+ kind: reviewKindOf(tool.key),
1303
+ command: tool.key === "Bash" ? textField(input, "command") : tool.key,
1304
+ rule: verdict.rule,
1305
+ reason: verdict.reason,
1306
+ workingRoot: facts.workingRoot,
1307
+ permissionCandidate: candidate,
1308
+ permissionScope: candidate.permissionScope,
1309
+ candidateHash: candidate.candidateHash,
1310
+ ...(candidate.targetPath
1311
+ ? { targetPath: candidate.targetPath, path: candidate.targetPath }
1312
+ : {}),
1313
+ },
1314
+ });
1315
+ return { kind: "wait", wait: approvalWait(ask) };
1316
+ }
1317
+ findPermissionGrant(candidate) {
1318
+ if (!this.permissionGrants)
1319
+ throw new Error("Permission grants are unavailable");
1320
+ return this.permissionGrants.findForAdmission(candidate.binding);
1321
+ }
1322
+ async recordPermissionReview(candidate, verdict) {
1323
+ if (!this.permissionGrants)
1324
+ throw new Error("Permission grants are unavailable");
1325
+ await this.permissionGrants.assertCurrent(candidate.binding);
1326
+ const events = await this.deps.eventLog.appendIn(candidate.binding.conversationId, [
1327
+ {
1328
+ type: "permission_reviewed",
1329
+ runId: candidate.binding.runId,
1330
+ payload: {
1331
+ ...candidate,
1332
+ outcome: verdict.decision,
1333
+ reason: verdict.reason,
1334
+ decisionSource: "review-model",
1335
+ },
1336
+ },
1337
+ ]);
1338
+ const event = events[0];
1339
+ if (!event)
1340
+ throw new Error("The review event was not recorded");
1341
+ if (verdict.decision === "allow")
1342
+ await this.permissionGrants.issueLocked(candidate, {
1343
+ source: "review-model",
1344
+ reviewEventSeq: event.seq,
1345
+ decidedBy: null,
1346
+ });
1347
+ }
1097
1348
  /** The outcome of a call whose `command` approval was already asked (a resume). */
1098
1349
  settledCommandAsk(ask, toolKey) {
1099
1350
  const kind = reviewKindOf(toolKey);
@@ -1106,6 +1357,7 @@ let ToolPipeline = class ToolPipeline {
1106
1357
  commandAsk: ask,
1107
1358
  review: this.personAllowRecord(ask),
1108
1359
  workingRoot: ask.command?.workingRoot,
1360
+ reviewedAgainst: ask.command?.workingRoot,
1109
1361
  };
1110
1362
  }
1111
1363
  if (ask.status === "denied") {
@@ -1124,7 +1376,16 @@ let ToolPipeline = class ToolPipeline {
1124
1376
  * command the SHA-256 of the text the ask holds in full, so an audit can match record and text.
1125
1377
  */
1126
1378
  personAllowRecord(ask) {
1379
+ const binding = ask.command?.permissionCandidate?.binding;
1127
1380
  return {
1381
+ ...(binding
1382
+ ? {
1383
+ profile: binding.profile,
1384
+ profileRevision: binding.profileRevision,
1385
+ scopeRevision: binding.scopeRevision,
1386
+ decisionSource: "human",
1387
+ }
1388
+ : {}),
1128
1389
  decision: "allow",
1129
1390
  by: "person",
1130
1391
  rule: ask.command?.rule ?? null,
@@ -1317,7 +1578,9 @@ let ToolPipeline = class ToolPipeline {
1317
1578
  * 带 `tools.timeoutMs` 超时与 run 的中止信号(合并后传给处理函数 / 连接器,不响应信号的也按时结束)。
1318
1579
  * 熔断只作用于连接器工具(键为组织 × 连接器)。
1319
1580
  */
1320
- async execute(tool, input, ctx, callId, resume, stepTools, reviewedWorkingRoot) {
1581
+ async execute(tool, input, ctx, callId, resume, stepTools, reviewed) {
1582
+ const reviewedWorkingRoot = reviewed?.workingRoot;
1583
+ const reviewedAgainstRoot = reviewed?.against;
1321
1584
  if (tool.source.kind === "connector") {
1322
1585
  return this.executeConnector(tool, tool.source, input, ctx, resume);
1323
1586
  }
@@ -1337,12 +1600,18 @@ let ToolPipeline = class ToolPipeline {
1337
1600
  ownerAccountId: ctx.ownerAccountId,
1338
1601
  role: ctx.role,
1339
1602
  ...(tool.source.kind === "builtin" && stepTools !== undefined && { tools: stepTools }),
1340
- ...(tool.source.kind === "builtin" && { runId: ctx.runId }),
1603
+ ...(tool.source.kind === "builtin" && {
1604
+ runId: ctx.runId,
1605
+ executionClaim: currentExecutionClaim(),
1606
+ }),
1341
1607
  ...(tool.source.kind === "builtin" &&
1342
1608
  ctx.deadline !== undefined && { runDeadline: ctx.deadline }),
1343
1609
  // a reviewed call runs in the working root its review judged (project root spec §4.3)
1344
1610
  ...(tool.source.kind === "builtin" &&
1345
1611
  reviewedWorkingRoot !== undefined && { reviewedWorkingRoot }),
1612
+ // and the root it was judged against, workspace included (B-18, the managed route)
1613
+ ...(tool.source.kind === "builtin" &&
1614
+ reviewedAgainstRoot !== undefined && { reviewedAgainstRoot }),
1346
1615
  // a sub-agent works in its root conversation's sandbox (spec §10.1, at every depth)
1347
1616
  ...(tool.source.kind === "builtin" &&
1348
1617
  ctx.parent !== undefined && { sandboxConversationId: ctx.parent.rootConversationId }),
@@ -1758,6 +2027,12 @@ let ToolPipeline = class ToolPipeline {
1758
2027
  __decorate([
1759
2028
  Transactional({ propagation: "mandatory" })
1760
2029
  ], ToolPipeline.prototype, "stopOpenAgentCalls", null);
2030
+ __decorate([
2031
+ Transactional()
2032
+ ], ToolPipeline.prototype, "findPermissionGrant", null);
2033
+ __decorate([
2034
+ Transactional()
2035
+ ], ToolPipeline.prototype, "recordPermissionReview", null);
1761
2036
  __decorate([
1762
2037
  Transactional()
1763
2038
  ], ToolPipeline.prototype, "writeResultIn", null);
@@ -1789,6 +2064,12 @@ ToolPipeline = __decorate([
1789
2064
  __param(20, Optional()),
1790
2065
  __param(20, Inject(CommandReviewService)),
1791
2066
  __param(21, Optional()),
1792
- __param(21, Inject(ConversationDevices))
2067
+ __param(21, Inject(ConversationDevices)),
2068
+ __param(22, Optional()),
2069
+ __param(22, Inject(SandboxOperationAuthority)),
2070
+ __param(23, Optional()),
2071
+ __param(23, Inject(PermissionCallGrants)),
2072
+ __param(24, Optional()),
2073
+ __param(24, Inject(PermissionAuthorityLock))
1793
2074
  ], ToolPipeline);
1794
2075
  export { ToolPipeline };
@@ -8,6 +8,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
8
8
  import { KernelDb } from "../infra/database/kernel-db.js";
9
9
  import type { OrgRole } from "../orgs/roles.js";
10
10
  import type { ConversationKindForHooks } from "../runtime/hook-calls.js";
11
+ import type { ExecutionClaim } from "../runtime/run-execution.js";
11
12
  import { BuiltinTools } from "./builtins/builtin-tools.js";
12
13
  import { OrgToolSwitches } from "./org-tool-switches.js";
13
14
  export { BUILTIN_TOOL_NAMES } from "./builtin-names.js";
@@ -34,6 +35,8 @@ export interface ToolRefIssue {
34
35
  * (`ToolSearch` 据此搜索)。插件处理函数收到的仍是 `ToolCallContext`。
35
36
  */
36
37
  export interface BuiltinCallContext extends ToolCallContext {
38
+ /** Server execution identity only; operation admission revalidates current PG ownership. */
39
+ executionClaim?: Readonly<ExecutionClaim> | undefined;
37
40
  tools?: readonly ResolvedTool[];
38
41
  /** 本次运行 id(内置工具写自己的事件时用,如沙箱 deliver 的 `artifact_created`)。 */
39
42
  runId?: string;
@@ -56,6 +59,12 @@ export interface BuiltinCallContext extends ToolCallContext {
56
59
  * was reviewed. Absent for a call the review does not cover.
57
60
  */
58
61
  reviewedWorkingRoot?: string;
62
+ /**
63
+ * The root the command review judged the call against, the workspace included (B-18): on the
64
+ * managed route a held device context naming another root refuses the call as stale before it
65
+ * runs. Absent for a call the review does not cover.
66
+ */
67
+ reviewedAgainstRoot?: string;
59
68
  /** The parent run of a sub-agent's run (absent for a top-level run). */
60
69
  parentRunId?: string;
61
70
  /**
@@ -20,6 +20,10 @@ import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
20
20
  import { RunJobsModule } from "../runtime/run-jobs.js";
21
21
  import { StepLogModule } from "../runtime/step-log.js";
22
22
  import { SubagentsModule } from "../runtime/subagents/subagents.service.js";
23
+ import { ManagedDeviceContextModule } from "../sandbox/managed-device-context.module.js";
24
+ import { OperationAuthorityModule } from "../sandbox/operation-authority.module.js";
25
+ import { PermissionAuthorityModule } from "../sandbox/permission-authority.module.js";
26
+ import { PermissionCallGrantsModule } from "../sandbox/permission-call-grants.module.js";
23
27
  import { SandboxModule } from "../sandbox/sandbox.module.js";
24
28
  import { ScheduledTaskStoreModule } from "../schedules/store.module.js";
25
29
  import { SkillsModule } from "../skills/skills.module.js";
@@ -40,6 +44,7 @@ import { ConversationToolInfo, OrgExtensionTools } from "./info.js";
40
44
  import { OAuthFlow } from "./oauth/flow.js";
41
45
  import { OrgToolSwitches } from "./org-tool-switches.js";
42
46
  import { ToolOutputs } from "./outputs.js";
47
+ import { PermissionApprovalJobs } from "./permission-approval-jobs.js";
43
48
  import { ToolPipeline } from "./pipeline.js";
44
49
  import { QuestionsService } from "./questions.service.js";
45
50
  import { ToolRegistry } from "./registry.js";
@@ -56,6 +61,9 @@ let ToolsModule = class ToolsModule {
56
61
  ToolsModule = __decorate([
57
62
  Module({
58
63
  imports: [
64
+ PermissionCallGrantsModule,
65
+ PermissionAuthorityModule,
66
+ OperationAuthorityModule,
59
67
  EventLogModule,
60
68
  AttachmentsModule,
61
69
  ExtensionsModule,
@@ -66,6 +74,8 @@ ToolsModule = __decorate([
66
74
  SubagentsModule,
67
75
  // the builtin sandbox and skill tools run in the conversation's device
68
76
  SandboxModule,
77
+ // the managed sandbox route's device context writer (passed only once activated)
78
+ ManagedDeviceContextModule,
69
79
  DevicesModule,
70
80
  // 「这台设备一直允许」 changes the device's local policy (network asks)
71
81
  LocalDevicesModule,
@@ -87,6 +97,7 @@ ToolsModule = __decorate([
87
97
  CredentialsModule,
88
98
  ],
89
99
  providers: [
100
+ PermissionApprovalJobs,
90
101
  ToolOutputs,
91
102
  BuiltinTools,
92
103
  // `ScheduleUpdate`'s write in one transaction (scheduled tasks spec §11)
@@ -112,6 +123,7 @@ ToolsModule = __decorate([
112
123
  DeviceOpResolver,
113
124
  ],
114
125
  exports: [
126
+ PermissionApprovalJobs,
115
127
  ScheduleToolsPort,
116
128
  CredentialsModule,
117
129
  ToolOutputs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.41",
3
+ "version": "0.1.0-rc.42",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -65,7 +65,7 @@
65
65
  "yaml": "^2.9.1",
66
66
  "yauzl": "3.4.0",
67
67
  "zod": "^4.6.7",
68
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.30"
68
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.31"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -74,7 +74,8 @@
74
74
  "@types/ws": "^8.18.2",
75
75
  "@types/yauzl": "3.4.0",
76
76
  "ws": "^8.22.0",
77
- "@capybara-hq/testing": "0.1.0-rc.23"
77
+ "@capybara-hq/testing": "0.1.0-rc.24",
78
+ "@capybara-hq/device": "0.1.0-rc.14"
78
79
  },
79
80
  "scripts": {
80
81
  "build": "tsc -b"
@@ -0,0 +1,6 @@
1
+ CREATE TABLE IF NOT EXISTS permission_authority_epochs (
2
+ kind text NOT NULL CHECK (kind IN ('platform', 'org', 'device', 'root')),
3
+ id text NOT NULL,
4
+ revision integer NOT NULL DEFAULT 0 CHECK (revision >= 0),
5
+ PRIMARY KEY (kind, id)
6
+ );
@@ -0,0 +1,4 @@
1
+ -- Preserve existing independent device/org ceilings; profiles grant no device authority.
2
+ ALTER TABLE conversations ADD COLUMN IF NOT EXISTS permission_profile text NOT NULL DEFAULT 'approve-for-me' CHECK (permission_profile IN ('request-approval', 'approve-for-me', 'full-access'));
3
+ ALTER TABLE conversations ADD COLUMN IF NOT EXISTS permission_revision integer NOT NULL DEFAULT 0;
4
+ ALTER TABLE conversations ADD COLUMN IF NOT EXISTS permission_consent jsonb;
@@ -0,0 +1,2 @@
1
+ -- 0057 already owns the unique (org_id, account_id, create_request_id) index.
2
+ ALTER TABLE conversations ADD COLUMN IF NOT EXISTS create_request_hash text;
@@ -0,0 +1,66 @@
1
+ CREATE TABLE IF NOT EXISTS sandbox_operation_intents (
2
+ operation_id text PRIMARY KEY,
3
+ org_id text NOT NULL,
4
+ account_id text NOT NULL,
5
+ device_id text NOT NULL,
6
+ root_conversation_id text,
7
+ conversation_id text,
8
+ run_id text,
9
+ call_id text,
10
+ ordinal integer NOT NULL CHECK (ordinal >= 0),
11
+ method text NOT NULL CHECK (method IN ('exec','readFile','writeFile','stat','list','scan')),
12
+ input_hash text NOT NULL,
13
+ admission_hash text NOT NULL,
14
+ granted_hosts jsonb NOT NULL DEFAULT '[]'::jsonb CHECK (jsonb_typeof(granted_hosts) = 'array'),
15
+ input jsonb NOT NULL,
16
+ scope jsonb NOT NULL,
17
+ epochs jsonb NOT NULL,
18
+ provider text NOT NULL,
19
+ provider_version text NOT NULL,
20
+ instance_generation text NOT NULL,
21
+ deadline timestamptz NOT NULL,
22
+ retain_until timestamptz NOT NULL,
23
+ state text NOT NULL DEFAULT 'pending' CHECK (state IN ('pending','admitted','dispatching','started-or-unknown','completed','revoked')),
24
+ execution_id text NOT NULL,
25
+ holder_token text NOT NULL DEFAULT '',
26
+ result jsonb,
27
+ outcome_unknown boolean NOT NULL DEFAULT false,
28
+ reconcile_attempt integer NOT NULL DEFAULT 0,
29
+ revoke_acknowledged boolean NOT NULL DEFAULT false,
30
+ created_at timestamptz NOT NULL DEFAULT now(),
31
+ updated_at timestamptz NOT NULL DEFAULT now(),
32
+ UNIQUE(run_id, call_id, ordinal),
33
+ CHECK (octet_length(input::text) <= 1048576),
34
+ CHECK (result IS NULL OR octet_length(result::text) <= 1048576)
35
+ );
36
+ CREATE INDEX IF NOT EXISTS sandbox_operation_active_ceiling ON sandbox_operation_intents(org_id, device_id, state);
37
+ CREATE INDEX IF NOT EXISTS sandbox_operation_retention ON sandbox_operation_intents(retain_until);
38
+ CREATE TABLE IF NOT EXISTS permission_config_publication (
39
+ id text PRIMARY KEY CHECK (id = 'platform'),
40
+ fingerprint text NOT NULL,
41
+ projection jsonb NOT NULL CHECK (jsonb_typeof(projection) = 'object' AND octet_length(projection::text) <= 131072),
42
+ updated_at timestamptz NOT NULL DEFAULT now()
43
+ );
44
+
45
+ ALTER TABLE permission_authority_epochs ADD COLUMN IF NOT EXISTS full_revision integer NOT NULL DEFAULT 0 CHECK (full_revision >= 0);
46
+
47
+ ALTER TABLE device_instances ADD COLUMN IF NOT EXISTS permission_runtime_identity jsonb;
48
+ CREATE TABLE IF NOT EXISTS device_permission_reports (
49
+ device_id text PRIMARY KEY,
50
+ provider text NOT NULL,
51
+ provider_version text NOT NULL,
52
+ instance_generation text NOT NULL,
53
+ identity_hash text NOT NULL,
54
+ report jsonb NOT NULL CHECK (octet_length(report::text) <= 16384),
55
+ observed_at timestamptz NOT NULL DEFAULT now()
56
+ );
57
+
58
+ ALTER TABLE device_instances ADD COLUMN IF NOT EXISTS permission_roots jsonb;
59
+
60
+ CREATE TABLE IF NOT EXISTS sandbox_operation_payload_chunks (
61
+ operation_id text NOT NULL REFERENCES sandbox_operation_intents(operation_id) ON DELETE CASCADE,
62
+ slot text NOT NULL CHECK (slot IN ('input','result')),
63
+ sequence integer NOT NULL CHECK (sequence >= 0),
64
+ data bytea NOT NULL CHECK (octet_length(data) BETWEEN 1 AND 65536),
65
+ PRIMARY KEY(operation_id, slot, sequence)
66
+ );