@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
@@ -7,8 +7,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { isSandboxGoneError, rootsOf } from "@capybara-hq/plugin-sdk";
11
- import { Inject, Injectable } from "@nestjs/common";
10
+ import { DeviceProtocolError, isSandboxGoneError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, rootsOf, ToolError, } from "@capybara-hq/plugin-sdk";
11
+ import { Inject, Injectable, Optional } from "@nestjs/common";
12
12
  import { ConversationAccess } from "../conversations/access.js";
13
13
  import { EventLog } from "../conversations/event-log.js";
14
14
  import { conversationTree } from "../conversations/tree.js";
@@ -17,13 +17,16 @@ import { ApiError } from "../errors.js";
17
17
  import { audit } from "../identity/audit.js";
18
18
  import { KernelDb } from "../infra/database/kernel-db.js";
19
19
  import { rootConversationOf } from "../runtime/subagents/child.js";
20
- import { SandboxService } from "../sandbox/sandbox.service.js";
20
+ import { PERMISSION_CONTEXT_ACTIVATION } from "../sandbox/permission-context-types.js";
21
+ import { retirementPending, SandboxService } from "../sandbox/sandbox.service.js";
21
22
  import { UUID_RE } from "../ui/registry.js";
22
23
  import { finishedEventKey } from "./finish.js";
23
24
  import { TASK_ID_RE, TASKS_DIR } from "./launch.js";
24
- import { actingAs } from "./session.js";
25
+ import { ManagedInstanceMismatchError, ManagedRefError, onManagedInstance, readerOf, } from "./managed.js";
26
+ import { assembleOutputSuffix, ManagedOutputCapacityError, ManagedOutputUnavailableError, } from "./managed-output.js";
27
+ import { actingAs, legacyBackgroundAllowed } from "./session.js";
25
28
  import { BackgroundTaskStopper } from "./stop.js";
26
- import { BackgroundTaskStore } from "./store.js";
29
+ import { BackgroundTaskStore, isManagedTask, } from "./store.js";
27
30
  /** The most bytes of output one read returns. */
28
31
  export const OUTPUT_TAIL_MAX_BYTES = 65_536;
29
32
  /** The time limit of reading an output (the exec and the wait for the sandbox's lease). */
@@ -45,7 +48,13 @@ let BackgroundTasks = class BackgroundTasks {
45
48
  eventLog;
46
49
  db;
47
50
  devices;
48
- constructor(access, store, stopper, sandbox, eventLog, db, devices) {
51
+ activation;
52
+ constructor(access, store, stopper, sandbox, eventLog, db, devices,
53
+ /**
54
+ * The paired activation gate: once on, a legacy (SID) task is never read or stopped by a raw
55
+ * exec (the retirement gate owns it); a managed task always goes by its exact ref.
56
+ */
57
+ activation) {
49
58
  this.access = access;
50
59
  this.store = store;
51
60
  this.stopper = stopper;
@@ -53,6 +62,7 @@ let BackgroundTasks = class BackgroundTasks {
53
62
  this.eventLog = eventLog;
54
63
  this.db = db;
55
64
  this.devices = devices;
65
+ this.activation = activation;
56
66
  }
57
67
  /**
58
68
  * The conversation and every sub-agent conversation below it (grandchildren too: their tasks run
@@ -78,7 +88,9 @@ let BackgroundTasks = class BackgroundTasks {
78
88
  lostReason: task.lostReason,
79
89
  startedAt: task.startedAt.toISOString(),
80
90
  finishedAt: task.finishedAt === null ? null : task.finishedAt.toISOString(),
81
- stopping: task.status === "running" && task.stoppingAt !== null,
91
+ // a managed task's owed cancellation is a stop in progress too
92
+ stopping: task.status === "running" &&
93
+ (task.stoppingAt !== null || task.launchState === "cancel-pending"),
82
94
  };
83
95
  }
84
96
  async owned(orgId, conversationId, accountId, taskId) {
@@ -102,6 +114,8 @@ let BackgroundTasks = class BackgroundTasks {
102
114
  */
103
115
  async stop(orgId, conversationId, accountId, taskId, actorTokenId, auditDetail) {
104
116
  const task = await this.owned(orgId, conversationId, accountId, taskId);
117
+ // once activated, the stopper refuses a legacy task's stop with the retirement refusal
118
+ // exactly when it would signal its session (BackgroundTaskStopper's paired gate)
105
119
  const after = await this.stopper.stop(task, "person");
106
120
  await audit(this.db.db, {
107
121
  actorAccountId: accountId,
@@ -169,6 +183,15 @@ let BackgroundTasks = class BackgroundTasks {
169
183
  }
170
184
  /** Reads the output from the task's running instance, or says why it cannot. */
171
185
  async readLive(orgId, accountId, task, tail) {
186
+ if (isManagedTask(task))
187
+ return this.readManaged(orgId, task, tail);
188
+ // once activated a legacy task's output is never read by a raw exec: a running one is the
189
+ // retirement gate's (its actionable refusal), a finished one answers with its finish summary
190
+ if (!legacyBackgroundAllowed(this.activation)) {
191
+ if (task.status === "running")
192
+ throw retirementPending();
193
+ return { kind: "unavailable", reason: "read_failed" };
194
+ }
172
195
  if (task.sid === null || task.sandboxCreatedAt === null || task.deviceId === null) {
173
196
  // a reservation the launch has not finished, or a launch that failed
174
197
  return {
@@ -187,7 +210,7 @@ let BackgroundTasks = class BackgroundTasks {
187
210
  const actor = { accountId, conversationId: task.conversationId };
188
211
  try {
189
212
  const r = await this.sandbox.ifRunning(task.deviceId, { createdAt }, async (p, h, signal) => {
190
- const res = await actingAs(p, actor).exec(h, {
213
+ const res = await actingAs(p, actor, this.activation).exec(h, {
191
214
  command: tailScript(task.id, tail),
192
215
  cwd: rootsOf(h).workspace,
193
216
  timeoutMs: OUTPUT_READ_TIMEOUT_MS,
@@ -221,6 +244,71 @@ let BackgroundTasks = class BackgroundTasks {
221
244
  throw e;
222
245
  }
223
246
  }
247
+ /**
248
+ * A managed task's live suffix (permission runtime cutover phase 8.3): by its exact ref on its
249
+ * exact instance only (never resumed, no exec, no path), the metadata total N first, then every
250
+ * byte of the last `tail` bytes before N through bounded reads; N stays the end however the
251
+ * output grows meanwhile. The task's ref is loaded from its authorized row, never supplied.
252
+ */
253
+ async readManaged(orgId, task, tail) {
254
+ if (task.executionRef === null || task.deviceId === null) {
255
+ return {
256
+ kind: "unavailable",
257
+ reason: task.status === "running" ? "starting" : "not_started",
258
+ };
259
+ }
260
+ if (!(await this.sandbox.availableFor(task.deviceId))) {
261
+ return { kind: "unavailable", reason: "unavailable" };
262
+ }
263
+ if (!(await this.deviceUsable(orgId, task.conversationId))) {
264
+ return { kind: "unavailable", reason: "no_access" };
265
+ }
266
+ try {
267
+ const r = await onManagedInstance(this.sandbox.ifRunning.bind(this.sandbox), task, async (bg, h, ref, signal) => {
268
+ try {
269
+ return await assembleOutputSuffix(readerOf(bg, h, ref, signal), tail, signal);
270
+ }
271
+ catch (e) {
272
+ if (e instanceof ManagedOutputUnavailableError)
273
+ return null;
274
+ throw e;
275
+ }
276
+ }, AbortSignal.timeout(OUTPUT_READ_TIMEOUT_MS));
277
+ if (r.kind === "other_instance")
278
+ return { kind: "unavailable", reason: "rebuilt" };
279
+ if (r.kind === "not_running") {
280
+ return { kind: "unavailable", reason: r.status === "suspended" ? "suspended" : "rebuilt" };
281
+ }
282
+ if (r.value === null)
283
+ return { kind: "unavailable", reason: "output_missing" };
284
+ return { kind: "ok", value: { text: r.value.text, truncated: r.value.truncated } };
285
+ }
286
+ catch (e) {
287
+ if (isSandboxGoneError(e))
288
+ return { kind: "unavailable", reason: "rebuilt" };
289
+ if (e instanceof ApiError && e.code.startsWith("device.")) {
290
+ return {
291
+ kind: "unavailable",
292
+ reason: e.code === "device.offline" ? "device_offline" : "no_access",
293
+ };
294
+ }
295
+ // a provider's typed refusal is no access; the kernel's own instance check, a missing
296
+ // background capability, a protocol or transport failure, a bad ref, capacity or a timeout
297
+ // is a failed read: never a 500, and a finished task still gets its finish summary
298
+ if (isSandboxScopeDeniedError(e))
299
+ return { kind: "unavailable", reason: "no_access" };
300
+ if (e instanceof ManagedRefError ||
301
+ e instanceof ManagedInstanceMismatchError ||
302
+ e instanceof ManagedOutputCapacityError ||
303
+ isSandboxPermissionUnsupportedError(e) ||
304
+ e instanceof DeviceProtocolError ||
305
+ e instanceof ToolError ||
306
+ (e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError"))) {
307
+ return { kind: "unavailable", reason: "read_failed" };
308
+ }
309
+ throw e;
310
+ }
311
+ }
224
312
  };
225
313
  BackgroundTasks = __decorate([
226
314
  Injectable(),
@@ -230,7 +318,9 @@ BackgroundTasks = __decorate([
230
318
  __param(3, Inject(SandboxService)),
231
319
  __param(4, Inject(EventLog)),
232
320
  __param(5, Inject(KernelDb)),
233
- __param(6, Inject(ConversationDevices))
321
+ __param(6, Inject(ConversationDevices)),
322
+ __param(7, Optional()),
323
+ __param(7, Inject(PERMISSION_CONTEXT_ACTIVATION))
234
324
  ], BackgroundTasks);
235
325
  export { BackgroundTasks };
236
326
  /**
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
188
188
  /** The host versions (an entry's `minKernel` is judged against them). */
189
189
  export declare const HOST_VERSIONS: {
190
190
  readonly kernel: string;
191
- readonly sdk: "0.1.0-rc.30";
191
+ readonly sdk: "0.1.0-rc.31";
192
192
  };
193
193
  /** Whether this deployment satisfies the entry's `minKernel`. */
194
194
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -279,7 +279,7 @@ export async function approvalCard(d, approvalId, base, locale, redact) {
279
279
  scopeLabels: Object.fromEntries(Object.entries(special.scopeLabels).filter(([k]) => v.scopes.includes(k))),
280
280
  }),
281
281
  expiresAt: v.expiresAt,
282
- state: v.status,
282
+ state: v.status === "superseded" ? "cancelled" : v.status,
283
283
  ...(decidedBy !== undefined && { decidedBy }),
284
284
  // a denial's reason, as the web shows it (UI refresh B); redacted like the input
285
285
  ...(v.status === "denied" &&
@@ -81,6 +81,8 @@ function projectSkillPhrase(err) {
81
81
  return "projectSkillUnsupported";
82
82
  case "removed":
83
83
  return "projectSkillRemoved";
84
+ case "skill_tool_off":
85
+ return "projectSkillToolOff";
84
86
  default:
85
87
  return "projectSkillUnreadable";
86
88
  }
@@ -203,6 +203,10 @@ export declare const CHANNEL_PHRASES: {
203
203
  readonly zh: "项目技能没有运行:这个项目已从设备的项目中移除。你的消息没有发送。";
204
204
  readonly en: "The project skill was not run: the project was removed from the device's projects. Your message was not sent.";
205
205
  };
206
+ readonly projectSkillToolOff: {
207
+ readonly zh: "项目技能没有运行:这个智能体不能加载项目技能,请为它打开 Skill 工具。你的消息没有发送。";
208
+ readonly en: "The project skill was not run: this agent cannot load project skills; turn on its Skill tool. Your message was not sent.";
209
+ };
206
210
  /** 运行被中止(收尾挂着的草稿时附在已有文本之后)。 */
207
211
  readonly runStopped: {
208
212
  readonly zh: "已停止。";
@@ -165,6 +165,10 @@ export const CHANNEL_PHRASES = {
165
165
  zh: "项目技能没有运行:这个项目已从设备的项目中移除。你的消息没有发送。",
166
166
  en: "The project skill was not run: the project was removed from the device's projects. Your message was not sent.",
167
167
  },
168
+ projectSkillToolOff: {
169
+ zh: "项目技能没有运行:这个智能体不能加载项目技能,请为它打开 Skill 工具。你的消息没有发送。",
170
+ en: "The project skill was not run: this agent cannot load project skills; turn on its Skill tool. Your message was not sent.",
171
+ },
168
172
  /** 运行被中止(收尾挂着的草稿时附在已有文本之后)。 */
169
173
  runStopped: { zh: "已停止。", en: "Stopped." },
170
174
  /** 运行失败。 */
@@ -6,6 +6,24 @@ export { ConfigError, type ConfigSource };
6
6
  export declare function selectConfigSource(env: NodeJS.ProcessEnv): ConfigSource;
7
7
  /** 深合并:对象递归合并,其余(含数组)由 override 整体替换。 */
8
8
  export declare function deepMerge(base: unknown, override: unknown): unknown;
9
+ /**
10
+ * The permission keys B1 replaced, each with its replacement. Until the old public inputs are
11
+ * removed, {@link translateLegacyPermissionKeys} reads the old key of a source as the new one.
12
+ */
13
+ export declare const LEGACY_PERMISSION_KEYS: readonly [{
14
+ readonly path: readonly ["devices", "autoMode"];
15
+ readonly replacement: readonly ["devices", "fullAccess"];
16
+ readonly env: "CAPYBARA_DEVICES__AUTO_MODE";
17
+ readonly replacementEnv: "CAPYBARA_DEVICES__FULL_ACCESS";
18
+ }];
19
+ /**
20
+ * Translates the old permission keys of ONE config source (the file / Nacos document, or the
21
+ * environment overrides) to their replacements, before the sources are merged: the old key keeps
22
+ * its source's place in the precedence (env > file / Nacos), never its own. An old and a new key
23
+ * in the same source must agree, else the config fails (never pick the wider one). The value is
24
+ * not checked here: the schema refuses an invalid one under the new key.
25
+ */
26
+ export declare function translateLegacyPermissionKeys(source: Record<string, unknown>, label: "file" | "env"): Record<string, unknown>;
9
27
  /** 原始配置深合并环境变量覆盖(优先级最高)后校验;热更新与启动共用。错误只列路径不列值。 */
10
28
  export declare function resolveConfig(raw: unknown, env: NodeJS.ProcessEnv): KernelConfig;
11
29
  /** 选来源 → 深合并环境变量覆盖(优先级最高)→ 校验。 */
@@ -63,11 +63,49 @@ export function deepMerge(base, override) {
63
63
  }
64
64
  return out;
65
65
  }
66
+ /**
67
+ * The permission keys B1 replaced, each with its replacement. Until the old public inputs are
68
+ * removed, {@link translateLegacyPermissionKeys} reads the old key of a source as the new one.
69
+ */
70
+ export const LEGACY_PERMISSION_KEYS = [
71
+ {
72
+ path: ["devices", "autoMode"],
73
+ replacement: ["devices", "fullAccess"],
74
+ env: "CAPYBARA_DEVICES__AUTO_MODE",
75
+ replacementEnv: "CAPYBARA_DEVICES__FULL_ACCESS",
76
+ },
77
+ ];
78
+ /**
79
+ * Translates the old permission keys of ONE config source (the file / Nacos document, or the
80
+ * environment overrides) to their replacements, before the sources are merged: the old key keeps
81
+ * its source's place in the precedence (env > file / Nacos), never its own. An old and a new key
82
+ * in the same source must agree, else the config fails (never pick the wider one). The value is
83
+ * not checked here: the schema refuses an invalid one under the new key.
84
+ */
85
+ export function translateLegacyPermissionKeys(source, label) {
86
+ let out = source;
87
+ for (const key of LEGACY_PERMISSION_KEYS) {
88
+ const [section, old] = key.path;
89
+ const [, next] = key.replacement;
90
+ const parent = out[section];
91
+ if (!isPlainObject(parent) || !(old in parent))
92
+ continue;
93
+ const { [old]: value, ...rest } = parent;
94
+ if (next in rest && rest[next] !== value) {
95
+ const [a, b] = label === "env"
96
+ ? [key.env, key.replacementEnv]
97
+ : [key.path.join("."), key.replacement.join(".")];
98
+ throw new ConfigError(`invalid configuration:\n - ${a} and ${b} are both set and differ; remove ${a} (it is replaced by ${b})`);
99
+ }
100
+ out = { ...out, [section]: { ...rest, [next]: rest[next] ?? value } };
101
+ }
102
+ return out;
103
+ }
66
104
  /** 原始配置深合并环境变量覆盖(优先级最高)后校验;热更新与启动共用。错误只列路径不列值。 */
67
105
  export function resolveConfig(raw, env) {
68
106
  if (!isPlainObject(raw))
69
107
  throw new ConfigError("config file root must be a mapping");
70
- const merged = deepMerge(raw, envOverrides(env));
108
+ const merged = deepMerge(translateLegacyPermissionKeys(raw, "file"), translateLegacyPermissionKeys(envOverrides(env), "env"));
71
109
  const result = KernelConfigSchema.safeParse(merged);
72
110
  if (!result.success) {
73
111
  // The schema is strict: an unknown key (a typo, or a removed setting) is an error that names
@@ -0,0 +1,26 @@
1
+ /** What {@link migratePermissionConfigText} did: the converted text and the keys it renamed. */
2
+ export interface PermissionConfigMigration {
3
+ text: string;
4
+ /** `old -> new` per converted key; empty when the document has no old key. */
5
+ changed: string[];
6
+ }
7
+ /**
8
+ * The offline conversion of one config document (a config file, or a Nacos data id's content) to
9
+ * the permission keys B1 introduced (`capybara config migrate-permissions`): every old key is
10
+ * renamed in place to its replacement, so unrelated keys, values, order and comments stay as they
11
+ * were. An old key equal to an already present new key is dropped; a different one, or an invalid
12
+ * old value, is refused (never pick the wider one, never guess). Nothing is read from or written
13
+ * to the environment, PG or Nacos here: applying the result is the operator's reviewed change.
14
+ */
15
+ export declare function migratePermissionConfigText(text: string): PermissionConfigMigration;
16
+ /** One environment variable the operator must rename before the old one stops being read. */
17
+ export interface PermissionEnvRename {
18
+ from: string;
19
+ to: string;
20
+ }
21
+ /**
22
+ * The old permission environment variables set in `env`, each with its replacement. The values
23
+ * are never returned (the operator renames the variable and keeps its value). Both set with
24
+ * different values is refused, like the startup config does.
25
+ */
26
+ export declare function legacyPermissionEnvRenames(env: NodeJS.ProcessEnv): PermissionEnvRename[];
@@ -0,0 +1,64 @@
1
+ import { isMap, isScalar, parseDocument } from "yaml";
2
+ import { LEGACY_PERMISSION_KEYS } from "./load.js";
3
+ import { ConfigError } from "./types.js";
4
+ const VALUES = ["allowed", "off"];
5
+ /**
6
+ * The offline conversion of one config document (a config file, or a Nacos data id's content) to
7
+ * the permission keys B1 introduced (`capybara config migrate-permissions`): every old key is
8
+ * renamed in place to its replacement, so unrelated keys, values, order and comments stay as they
9
+ * were. An old key equal to an already present new key is dropped; a different one, or an invalid
10
+ * old value, is refused (never pick the wider one, never guess). Nothing is read from or written
11
+ * to the environment, PG or Nacos here: applying the result is the operator's reviewed change.
12
+ */
13
+ export function migratePermissionConfigText(text) {
14
+ const doc = parseDocument(text);
15
+ if (doc.errors.length > 0)
16
+ throw new ConfigError("invalid YAML in the config document");
17
+ const changed = [];
18
+ for (const key of LEGACY_PERMISSION_KEYS) {
19
+ const [section, old] = key.path;
20
+ const [, next] = key.replacement;
21
+ const parent = doc.get(section, true);
22
+ if (!isMap(parent) || !parent.has(old))
23
+ continue;
24
+ const from = key.path.join(".");
25
+ const to = key.replacement.join(".");
26
+ const value = parent.get(old);
27
+ if (typeof value !== "string" || !VALUES.includes(value))
28
+ throw new ConfigError(`${from} must be allowed or off; fix it before converting`);
29
+ if (parent.has(next)) {
30
+ if (parent.get(next) !== value)
31
+ throw new ConfigError(`${from} and ${to} are both set and differ; keep one of them before converting`);
32
+ parent.delete(old);
33
+ }
34
+ else {
35
+ const pair = parent.items.find((p) => (isScalar(p.key) ? p.key.value : p.key) === old);
36
+ if (pair === undefined)
37
+ continue;
38
+ if (isScalar(pair.key))
39
+ pair.key.value = next;
40
+ else
41
+ pair.key = doc.createNode(next);
42
+ }
43
+ changed.push(`${from} -> ${to}`);
44
+ }
45
+ return { text: changed.length === 0 ? text : doc.toString(), changed };
46
+ }
47
+ /**
48
+ * The old permission environment variables set in `env`, each with its replacement. The values
49
+ * are never returned (the operator renames the variable and keeps its value). Both set with
50
+ * different values is refused, like the startup config does.
51
+ */
52
+ export function legacyPermissionEnvRenames(env) {
53
+ const out = [];
54
+ for (const key of LEGACY_PERMISSION_KEYS) {
55
+ const old = env[key.env];
56
+ if (old === undefined)
57
+ continue;
58
+ const current = env[key.replacementEnv];
59
+ if (current !== undefined && current !== old)
60
+ throw new ConfigError(`${key.env} and ${key.replacementEnv} are both set and differ; keep one of them`);
61
+ out.push({ from: key.env, to: key.replacementEnv });
62
+ }
63
+ return out;
64
+ }
@@ -255,7 +255,7 @@ export declare const KernelConfigSchema: z.ZodObject<{
255
255
  }, z.core.$strict>>;
256
256
  }, z.core.$strict>>;
257
257
  devices: z.ZodPrefault<z.ZodObject<{
258
- autoMode: z.ZodOptional<z.ZodEnum<{
258
+ fullAccess: z.ZodOptional<z.ZodEnum<{
259
259
  allowed: "allowed";
260
260
  off: "off";
261
261
  }>>;
@@ -1475,7 +1475,7 @@ export const KernelConfigSchema = z.strictObject({
1475
1475
  egress: z
1476
1476
  .enum(["none", "allowlist"], {
1477
1477
  error: (iss) => iss.input === "open"
1478
- ? 'sandbox.limits.egress does not take "open": the open public network is set by devices.autoMode and an organization\'s cloudNetwork; use "allowlist" or "none"'
1478
+ ? 'sandbox.limits.egress does not take "open": the open public network is set by devices.fullAccess and an organization\'s cloudNetwork; use "allowlist" or "none"'
1479
1479
  : undefined,
1480
1480
  })
1481
1481
  .default("allowlist")
@@ -1499,7 +1499,7 @@ export const KernelConfigSchema = z.strictObject({
1499
1499
  .enum(["extend", "within"])
1500
1500
  .default("extend")
1501
1501
  .meta(meta({
1502
- description: "Whether organizations may go beyond allowHosts in sandbox mode: extend (the default: an organization may use the open cloud network and add hosts, and its admins approve network requests) or within (allowHosts is the ceiling: an organization's cloud network in sandbox mode is the allowlist, and it may only keep or drop hosts the list covers; only a super admin adds others). Auto mode is not limited by it: devices.autoMode governs auto mode's open network, so set devices.autoMode off as well for a hard ceiling",
1502
+ description: "Whether organizations may go beyond allowHosts in sandbox mode: extend (the default: an organization may use the open cloud network and add hosts, and its admins approve network requests) or within (allowHosts is the ceiling: an organization's cloud network in sandbox mode is the allowlist, and it may only keep or drop hosts the list covers; only a super admin adds others). Auto mode is not limited by it: devices.fullAccess governs Full permission's open network, so set devices.fullAccess off as well for a hard ceiling",
1503
1503
  })),
1504
1504
  })
1505
1505
  .prefault({}),
@@ -1508,19 +1508,20 @@ export const KernelConfigSchema = z.strictObject({
1508
1508
  devices: z
1509
1509
  .strictObject({
1510
1510
  /**
1511
- * The platform's auto-mode switch (auto mode spec §4.3): whether a device may run in auto
1512
- * mode; when off, a cloud device keeps its org's cloudNetwork (open by default). Also a deployment setting the super admin changes
1513
- * in the admin console; the startup config wins over it, so this field is optional with no
1514
- * schema default (the default `allowed` is applied by `readDevicesAutoMode`: a schema default
1515
- * would be indistinguishable from a value the config source set, and the stored choice may
1516
- * only apply when the source is silent).
1511
+ * The platform's Full permission switch (permission runtime cutover B1): whether a device's
1512
+ * owner ceiling may allow Full permission. Also a deployment setting the super admin changes
1513
+ * in the admin console (`devicesFullAccess`); the startup config wins over it, so this field
1514
+ * is optional with no schema default (the default `allowed` is applied by
1515
+ * `readDevicesFullAccess`: a schema default would be indistinguishable from a value the config
1516
+ * source set). The old key `devices.autoMode` (`CAPYBARA_DEVICES__AUTO_MODE`) is translated
1517
+ * per source by `translateLegacyPermissionKeys` until it is removed.
1517
1518
  */
1518
- autoMode: z
1519
+ fullAccess: z
1519
1520
  .enum(["allowed", "off"])
1520
1521
  .optional()
1521
1522
  .meta(meta({
1522
1523
  hot: true,
1523
- description: "Whether devices may run in auto mode (default allowed): auto mode is the default of a new local device and of a cloud device, whose network in auto mode is the open public network (private and internal addresses blocked). When off, devices run in sandbox mode: local devices on their allowlist, cloud devices on their organization's cloud network (cloudNetwork, open by default, or the allowlist the organization sets). An organization may turn it off and follow the platform; only capybara-device on the machine turns auto mode on for a local device. Set here, it is read-only in the admin console",
1524
+ description: "Whether devices may run with Full permission (default allowed): a device whose owner allows Full may then run a conversation with Full permission; a cloud device on Full reaches the open public network (private and internal addresses blocked) unless sandbox.limits.egress is none. When off, devices run restricted: local devices on their allowlist, cloud devices on their organization's cloud network (cloudNetwork). An organization may turn it off and follow the platform. Set here, it is read-only in the admin console. Replaces devices.autoMode (CAPYBARA_DEVICES__AUTO_MODE), which is still read with the same values; capybara config migrate-permissions converts a config file",
1524
1525
  })),
1525
1526
  maxPersonal: z
1526
1527
  .number()
@@ -83,7 +83,7 @@ declare const MessageBody: z.ZodObject<{
83
83
  * (project root design §4.3; the device's owner only, refused when the device's current mode
84
84
  * cannot read it); without it the conversation runs in free mode.
85
85
  */
86
- declare const CreateBody: z.ZodObject<{
86
+ export declare const CreateBody: z.ZodObject<{
87
87
  agentId: z.ZodString;
88
88
  deviceId: z.ZodOptional<z.ZodString>;
89
89
  project: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
@@ -112,7 +112,7 @@ const MessageBody = MessageFields.strict().refine(...textRule);
112
112
  * (project root design §4.3; the device's owner only, refused when the device's current mode
113
113
  * cannot read it); without it the conversation runs in free mode.
114
114
  */
115
- const CreateBody = z
115
+ export const CreateBody = z
116
116
  .object({
117
117
  agentId: z.string().min(1).max(100),
118
118
  deviceId: z.string().min(1).max(100).optional(),
@@ -10,6 +10,9 @@ import { BackgroundModule } from "../background/background.module.js";
10
10
  import { DevicesModule } from "../devices/devices.module.js";
11
11
  import { ProvidersModule } from "../runtime/providers.js";
12
12
  import { RuntimeModule } from "../runtime/runtime.module.js";
13
+ import { OperationAuthorityModule } from "../sandbox/operation-authority.module.js";
14
+ import { PermissionAuthorityModule } from "../sandbox/permission-authority.module.js";
15
+ import { PermissionFactsModule } from "../sandbox/permission-facts.module.js";
13
16
  import { SkillsModule } from "../skills/skills.module.js";
14
17
  import { StorageModule } from "../storage/storage.module.js";
15
18
  import { ToolsModule } from "../tools/tools.module.js";
@@ -21,6 +24,8 @@ import { ConversationDeviceStatus } from "./device-status.js";
21
24
  import { EventLogModule } from "./event-log.js";
22
25
  import { ConversationFiles } from "./files.js";
23
26
  import { ConversationOutputs } from "./outputs-read.js";
27
+ import { PermissionProfileStoreModule } from "./permission-profile-store.module.js";
28
+ import { PermissionProfilesService } from "./permission-profiles.service.js";
24
29
  import { ConversationQueue } from "./queue.service.js";
25
30
  /**
26
31
  * Conversations: the one {@link ConversationsService} (messages, model switches, skill
@@ -33,6 +38,10 @@ let ConversationsModule = class ConversationsModule {
33
38
  ConversationsModule = __decorate([
34
39
  Module({
35
40
  imports: [
41
+ OperationAuthorityModule,
42
+ PermissionFactsModule,
43
+ PermissionProfileStoreModule,
44
+ PermissionAuthorityModule,
36
45
  EventLogModule,
37
46
  ConversationAccessModule,
38
47
  AttachmentsModule,
@@ -49,6 +58,7 @@ ConversationsModule = __decorate([
49
58
  BackgroundModule,
50
59
  ],
51
60
  providers: [
61
+ PermissionProfilesService,
52
62
  ConversationsService,
53
63
  ConversationQueue,
54
64
  ConversationOutputs,
@@ -57,6 +67,8 @@ ConversationsModule = __decorate([
57
67
  ConversationDeviceStatus,
58
68
  ],
59
69
  exports: [
70
+ OperationAuthorityModule,
71
+ PermissionProfilesService,
60
72
  EventLogModule,
61
73
  ConversationAccessModule,
62
74
  AttachmentsModule,
@@ -10,6 +10,7 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
10
10
  import { KernelEvents } from "../infra/events/kernel-events.js";
11
11
  import { ProviderRegistry } from "../runtime/providers.js";
12
12
  import { RunDeletion } from "../runtime/run-deletion.js";
13
+ import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
13
14
  import type { ScheduleMarker } from "../schedules/types.js";
14
15
  import { type RenderedInvocation, SkillInvoker } from "../skills/invoke.js";
15
16
  import { type ApprovalRecord, ApprovalsService } from "../tools/approvals.service.js";
@@ -21,6 +22,8 @@ import { AttachmentsService } from "./attachments.service.js";
21
22
  import { EventLog } from "./event-log.js";
22
23
  import type { ConversationEvent, LogContentBlock } from "./events.js";
23
24
  import { type ImSenderContext } from "./message-context.js";
25
+ import type { PermissionSelection } from "./permission-profiles.schemas.js";
26
+ import { PermissionProfilesService } from "./permission-profiles.service.js";
24
27
  import { type Selection } from "./selection.js";
25
28
  /** 对外的会话视图。 */
26
29
  export interface ConversationView {
@@ -257,6 +260,8 @@ export interface UserMessageInput {
257
260
  * source of the message's `timeZone` (`readMessageContext`).
258
261
  */
259
262
  export interface InternalMessageOptions {
263
+ initialPermission?: PermissionSelection;
264
+ createRequestHash?: string;
260
265
  schedule?: ScheduleMarker;
261
266
  timeZoneOverride?: string;
262
267
  }
@@ -273,6 +278,7 @@ export interface NewConversationOptions {
273
278
  * 不可用时会话也按不存在处理(`conversation.not_found`)。
274
279
  */
275
280
  export declare class ConversationsService {
281
+ private readonly permissions;
276
282
  private readonly db;
277
283
  private readonly eventLog;
278
284
  private readonly agents;
@@ -299,7 +305,8 @@ export declare class ConversationsService {
299
305
  private readonly approvals;
300
306
  private readonly events;
301
307
  readonly txHost: TransactionHost;
302
- constructor(db: KernelDb, eventLog: EventLog, agents: Pick<AgentLookup, "get">, access: Pick<ConversationAccess, "isAccessible">,
308
+ private readonly ceilings;
309
+ constructor(permissions: Pick<PermissionProfilesService, "initialize" | "lockInitial">, db: KernelDb, eventLog: EventLog, agents: Pick<AgentLookup, "get">, access: Pick<ConversationAccess, "isAccessible">,
303
310
  /** Starts and stops the conversation's runs. */
304
311
  runs: RunControl,
305
312
  /** Resolves a switched-to model and its declared parameters (UI refresh B). */
@@ -319,7 +326,7 @@ export declare class ConversationsService {
319
326
  /** A starter's message skips the run's pending questions (reply-while-question spec §8.1). */
320
327
  questions: Pick<QuestionsService, "skipPendingIn">,
321
328
  /** ... and its pending network asks (network ask-to-allow spec §6.7). */
322
- approvals: Pick<ApprovalsService, "skipNetworkIn">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost);
329
+ approvals: Pick<ApprovalsService, "skipNetworkIn">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost, ceilings: PermissionCeilingWrites);
323
330
  /**
324
331
  * Creates an empty conversation bound to its device (`pick`, see
325
332
  * {@link ConversationDevices.forNew}); an agent the account cannot use →
@@ -395,6 +402,8 @@ export declare class ConversationsService {
395
402
  * log, runs and trajectory stay (super admins still see them).
396
403
  */
397
404
  remove(orgId: string, conversationId: string, accountId: string): Promise<void>;
405
+ /** The authority subject a deletion locks: the tree's root and its device, read without locks. */
406
+ private deletionSubject;
398
407
  private markDeleted;
399
408
  /** 读会话:非所有者、或 agent 已对所有者不可用 → `conversation.not_found`。 */
400
409
  get(orgId: string, conversationId: string, viewerAccountId: string): Promise<ConversationView>;