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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (359) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/admin/admin.schemas.d.ts +6 -0
  3. package/dist/admin/org-network.service.d.ts +3 -1
  4. package/dist/admin/org-network.service.js +10 -2
  5. package/dist/app.d.ts +4 -0
  6. package/dist/app.js +2 -0
  7. package/dist/background/finish.d.ts +9 -1
  8. package/dist/background/finish.js +57 -4
  9. package/dist/background/launch.d.ts +23 -0
  10. package/dist/background/launch.js +55 -1
  11. package/dist/background/managed-output.d.ts +110 -0
  12. package/dist/background/managed-output.js +219 -0
  13. package/dist/background/managed.d.ts +52 -0
  14. package/dist/background/managed.js +128 -0
  15. package/dist/background/poll.job.d.ts +35 -1
  16. package/dist/background/poll.job.js +174 -9
  17. package/dist/background/render.js +1 -0
  18. package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
  19. package/dist/background/retire-legacy-tasks.job.js +149 -0
  20. package/dist/background/session.d.ts +15 -5
  21. package/dist/background/session.js +22 -6
  22. package/dist/background/stop.d.ts +35 -5
  23. package/dist/background/stop.js +94 -8
  24. package/dist/background/store.d.ts +110 -3
  25. package/dist/background/store.js +205 -3
  26. package/dist/background/tasks.service.d.ts +18 -1
  27. package/dist/background/tasks.service.js +99 -9
  28. package/dist/catalog/marketplaces.service.d.ts +1 -1
  29. package/dist/channels/cards.js +1 -1
  30. package/dist/channels/inbound.js +2 -0
  31. package/dist/channels/phrases.d.ts +4 -0
  32. package/dist/channels/phrases.js +4 -0
  33. package/dist/config/load.d.ts +18 -0
  34. package/dist/config/load.js +39 -1
  35. package/dist/config/permission-migration.d.ts +26 -0
  36. package/dist/config/permission-migration.js +64 -0
  37. package/dist/config/schema.d.ts +4 -1
  38. package/dist/config/schema.js +41 -10
  39. package/dist/conversations/conversations.controller.d.ts +1 -1
  40. package/dist/conversations/conversations.controller.js +1 -1
  41. package/dist/conversations/conversations.module.js +12 -0
  42. package/dist/conversations/conversations.service.d.ts +11 -2
  43. package/dist/conversations/conversations.service.js +97 -27
  44. package/dist/conversations/event-log.d.ts +1 -1
  45. package/dist/conversations/event-log.js +10 -2
  46. package/dist/conversations/events.d.ts +307 -4
  47. package/dist/conversations/events.js +286 -32
  48. package/dist/conversations/permission-profile-store.d.ts +50 -0
  49. package/dist/conversations/permission-profile-store.js +67 -0
  50. package/dist/conversations/permission-profile-store.module.d.ts +2 -0
  51. package/dist/conversations/permission-profile-store.module.js +19 -0
  52. package/dist/conversations/permission-profiles.controller.d.ts +84 -0
  53. package/dist/conversations/permission-profiles.controller.js +105 -0
  54. package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
  55. package/dist/conversations/permission-profiles.schemas.js +23 -0
  56. package/dist/conversations/permission-profiles.service.d.ts +56 -0
  57. package/dist/conversations/permission-profiles.service.js +179 -0
  58. package/dist/ctx/create-ctx.d.ts +12 -5
  59. package/dist/ctx/create-ctx.js +21 -5
  60. package/dist/db/kernel-schema.d.ts +248 -3
  61. package/dist/devices/access.js +1 -1
  62. package/dist/devices/access.module.d.ts +2 -0
  63. package/dist/devices/access.module.js +19 -0
  64. package/dist/devices/conversation-devices.d.ts +8 -29
  65. package/dist/devices/conversation-devices.js +37 -73
  66. package/dist/devices/device-projects.service.d.ts +26 -28
  67. package/dist/devices/device-projects.service.js +123 -127
  68. package/dist/devices/devices.controller.js +3 -1
  69. package/dist/devices/devices.module.js +11 -9
  70. package/dist/devices/devices.service.d.ts +116 -8
  71. package/dist/devices/devices.service.js +252 -20
  72. package/dist/devices/dto.d.ts +16 -0
  73. package/dist/devices/dto.js +34 -6
  74. package/dist/devices/errors.d.ts +8 -0
  75. package/dist/devices/errors.js +10 -0
  76. package/dist/devices/project-rules.d.ts +44 -0
  77. package/dist/devices/project-rules.js +27 -0
  78. package/dist/devices/working-root.d.ts +6 -0
  79. package/dist/devices/working-root.js +12 -1
  80. package/dist/errors.d.ts +31 -0
  81. package/dist/errors.js +31 -0
  82. package/dist/evals/reconstruct.d.ts +19 -2
  83. package/dist/evals/reconstruct.js +40 -2
  84. package/dist/evals/recorded-permission-context.d.ts +77 -0
  85. package/dist/evals/recorded-permission-context.js +151 -0
  86. package/dist/evals/recorded-tools.d.ts +10 -1
  87. package/dist/evals/recorded-tools.js +27 -3
  88. package/dist/evals/run-replay.d.ts +8 -2
  89. package/dist/evals/run-replay.js +18 -2
  90. package/dist/evals/trajectory.d.ts +1 -1
  91. package/dist/evals/worker.d.ts +10 -1
  92. package/dist/evals/worker.js +23 -14
  93. package/dist/extensions/host.d.ts +4 -1
  94. package/dist/extensions/host.js +10 -6
  95. package/dist/http/api.module.js +2 -0
  96. package/dist/identity/accounts.d.ts +14 -1
  97. package/dist/identity/accounts.js +61 -5
  98. package/dist/identity/identity.module.js +2 -0
  99. package/dist/identity/settings.d.ts +28 -12
  100. package/dist/identity/settings.js +89 -33
  101. package/dist/index.d.ts +6 -0
  102. package/dist/index.js +5 -0
  103. package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
  104. package/dist/infra/cli/kernel-cli.module.js +5 -2
  105. package/dist/infra/cli/permission-cutover.d.ts +59 -0
  106. package/dist/infra/cli/permission-cutover.js +107 -0
  107. package/dist/infra/config/kernel-config.service.d.ts +2 -2
  108. package/dist/infra/config/kernel-config.service.js +35 -11
  109. package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
  110. package/dist/infra/database/startup-activation-transaction.js +242 -0
  111. package/dist/infra/database/transaction-host.d.ts +47 -0
  112. package/dist/infra/database/transaction-host.js +119 -0
  113. package/dist/infra/database/xact-lock.d.ts +1 -0
  114. package/dist/infra/database/xact-lock.js +6 -0
  115. package/dist/infra/outbox/registry.d.ts +39 -0
  116. package/dist/infra/outbox/registry.js +18 -0
  117. package/dist/kernel.module.js +2 -0
  118. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  119. package/dist/lifecycle/kernel-lifecycle.js +55 -28
  120. package/dist/local-devices/device-auth.js +1 -1
  121. package/dist/local-devices/device-policy.service.d.ts +35 -5
  122. package/dist/local-devices/device-policy.service.js +188 -13
  123. package/dist/local-devices/instance-bindings.d.ts +82 -0
  124. package/dist/local-devices/instance-bindings.js +304 -0
  125. package/dist/local-devices/keys.d.ts +5 -0
  126. package/dist/local-devices/keys.js +5 -0
  127. package/dist/local-devices/local-device-gateway.d.ts +19 -4
  128. package/dist/local-devices/local-device-gateway.js +185 -17
  129. package/dist/local-devices/local-device-provider.d.ts +42 -7
  130. package/dist/local-devices/local-device-provider.js +185 -10
  131. package/dist/local-devices/local-devices.module.d.ts +17 -2
  132. package/dist/local-devices/local-devices.module.js +49 -8
  133. package/dist/local-devices/machines.d.ts +35 -12
  134. package/dist/local-devices/machines.js +203 -8
  135. package/dist/local-devices/network-grants.js +3 -3
  136. package/dist/local-devices/network-grants.module.d.ts +2 -0
  137. package/dist/local-devices/network-grants.module.js +14 -0
  138. package/dist/local-devices/owner-report.d.ts +79 -0
  139. package/dist/local-devices/owner-report.js +155 -0
  140. package/dist/local-devices/owner-reports.d.ts +48 -0
  141. package/dist/local-devices/owner-reports.js +190 -0
  142. package/dist/local-devices/policy-summary.d.ts +24 -1
  143. package/dist/local-devices/policy-summary.js +48 -0
  144. package/dist/local-devices/relay.d.ts +82 -6
  145. package/dist/local-devices/relay.js +187 -16
  146. package/dist/local-devices/targets.d.ts +16 -1
  147. package/dist/local-devices/targets.js +35 -2
  148. package/dist/models/image-usable.d.ts +22 -0
  149. package/dist/models/image-usable.js +29 -0
  150. package/dist/models/images.d.ts +125 -0
  151. package/dist/models/images.js +440 -0
  152. package/dist/models/models.module.d.ts +3 -2
  153. package/dist/models/models.module.js +16 -5
  154. package/dist/models/org-models.schemas.js +1 -0
  155. package/dist/models/purposes.controller.d.ts +7 -0
  156. package/dist/models/purposes.controller.js +9 -0
  157. package/dist/models/purposes.d.ts +28 -3
  158. package/dist/models/purposes.js +40 -13
  159. package/dist/orgs/cloud-network-setting.d.ts +33 -0
  160. package/dist/orgs/cloud-network-setting.js +47 -0
  161. package/dist/orgs/offboarding.d.ts +3 -1
  162. package/dist/orgs/offboarding.js +8 -2
  163. package/dist/orgs/org-lock.d.ts +10 -4
  164. package/dist/orgs/org-lock.js +10 -4
  165. package/dist/orgs/orgs.service.d.ts +3 -1
  166. package/dist/orgs/orgs.service.js +8 -2
  167. package/dist/orgs/settings.controller.d.ts +4 -1
  168. package/dist/orgs/settings.controller.js +3 -3
  169. package/dist/orgs/settings.service.d.ts +48 -56
  170. package/dist/orgs/settings.service.js +144 -101
  171. package/dist/overrides.d.ts +6 -1
  172. package/dist/overrides.js +2 -0
  173. package/dist/platform/exclusions.js +20 -0
  174. package/dist/platform/ops/admin.ops.js +14 -11
  175. package/dist/platform/ops/agent-skills.ops.js +2 -0
  176. package/dist/platform/ops/devices.ops.js +10 -2
  177. package/dist/platform/ops/models.ops.js +10 -0
  178. package/dist/platform/ops/org-settings.ops.js +6 -6
  179. package/dist/platform/ops/orgs.ops.js +1 -0
  180. package/dist/roles/worker.module.js +4 -0
  181. package/dist/runtime/context/build.d.ts +3 -1
  182. package/dist/runtime/context/build.js +19 -3
  183. package/dist/runtime/context/compaction.js +5 -0
  184. package/dist/runtime/context/device-paths.d.ts +9 -2
  185. package/dist/runtime/context/device-paths.js +20 -0
  186. package/dist/runtime/context/permission-profile.d.ts +46 -0
  187. package/dist/runtime/context/permission-profile.js +194 -0
  188. package/dist/runtime/hook-calls.d.ts +11 -1
  189. package/dist/runtime/hook-calls.js +24 -1
  190. package/dist/runtime/maintenance.d.ts +7 -1
  191. package/dist/runtime/maintenance.js +43 -15
  192. package/dist/runtime/model-call.d.ts +32 -0
  193. package/dist/runtime/model-call.js +67 -0
  194. package/dist/runtime/permission-context-errors.d.ts +39 -0
  195. package/dist/runtime/permission-context-errors.js +67 -0
  196. package/dist/runtime/permission-context.service.d.ts +60 -0
  197. package/dist/runtime/permission-context.service.js +286 -0
  198. package/dist/runtime/project/knowledge.d.ts +7 -2
  199. package/dist/runtime/project/knowledge.js +5 -2
  200. package/dist/runtime/project/knowledge.service.d.ts +17 -2
  201. package/dist/runtime/project/knowledge.service.js +76 -12
  202. package/dist/runtime/providers.d.ts +9 -5
  203. package/dist/runtime/providers.js +22 -3
  204. package/dist/runtime/run-execution.d.ts +4 -1
  205. package/dist/runtime/run-execution.js +14 -5
  206. package/dist/runtime/run-steps.d.ts +11 -3
  207. package/dist/runtime/run-steps.js +27 -4
  208. package/dist/runtime/runtime.module.js +11 -0
  209. package/dist/runtime/usage-report.d.ts +10 -6
  210. package/dist/runtime/usage-report.js +31 -11
  211. package/dist/sandbox/attachments-path.d.ts +15 -0
  212. package/dist/sandbox/attachments-path.js +15 -0
  213. package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
  214. package/dist/sandbox/cloud-permission-snapshot.js +407 -0
  215. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
  216. package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
  217. package/dist/sandbox/held-operations.d.ts +39 -0
  218. package/dist/sandbox/held-operations.js +119 -0
  219. package/dist/sandbox/jobs.d.ts +14 -3
  220. package/dist/sandbox/jobs.js +20 -2
  221. package/dist/sandbox/kernel-read.d.ts +55 -0
  222. package/dist/sandbox/kernel-read.js +57 -0
  223. package/dist/sandbox/legacy-retirement.d.ts +336 -0
  224. package/dist/sandbox/legacy-retirement.js +1063 -0
  225. package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
  226. package/dist/sandbox/legacy-retirement.module.js +25 -0
  227. package/dist/sandbox/managed-device-context.d.ts +94 -0
  228. package/dist/sandbox/managed-device-context.js +308 -0
  229. package/dist/sandbox/managed-device-context.module.d.ts +6 -0
  230. package/dist/sandbox/managed-device-context.module.js +33 -0
  231. package/dist/sandbox/modes.d.ts +56 -8
  232. package/dist/sandbox/modes.js +92 -8
  233. package/dist/sandbox/operation-authority-types.d.ts +8 -0
  234. package/dist/sandbox/operation-authority-types.js +32 -0
  235. package/dist/sandbox/operation-authority.d.ts +145 -0
  236. package/dist/sandbox/operation-authority.js +783 -0
  237. package/dist/sandbox/operation-authority.module.d.ts +2 -0
  238. package/dist/sandbox/operation-authority.module.js +29 -0
  239. package/dist/sandbox/operation-intents.d.ts +206 -0
  240. package/dist/sandbox/operation-intents.js +1252 -0
  241. package/dist/sandbox/operation-intents.module.d.ts +2 -0
  242. package/dist/sandbox/operation-intents.module.js +21 -0
  243. package/dist/sandbox/operation-payloads.d.ts +33 -0
  244. package/dist/sandbox/operation-payloads.js +332 -0
  245. package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
  246. package/dist/sandbox/operation-reconcile.job.js +247 -0
  247. package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
  248. package/dist/sandbox/permission-authority-epochs.js +83 -0
  249. package/dist/sandbox/permission-authority-lock.d.ts +38 -0
  250. package/dist/sandbox/permission-authority-lock.js +147 -0
  251. package/dist/sandbox/permission-authority.module.d.ts +9 -0
  252. package/dist/sandbox/permission-authority.module.js +55 -0
  253. package/dist/sandbox/permission-availability.d.ts +18 -0
  254. package/dist/sandbox/permission-availability.js +19 -0
  255. package/dist/sandbox/permission-call-grants.d.ts +34 -0
  256. package/dist/sandbox/permission-call-grants.js +349 -0
  257. package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
  258. package/dist/sandbox/permission-call-grants.module.js +21 -0
  259. package/dist/sandbox/permission-call-types.d.ts +82 -0
  260. package/dist/sandbox/permission-call-types.js +1 -0
  261. package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
  262. package/dist/sandbox/permission-ceiling-writes.js +223 -0
  263. package/dist/sandbox/permission-config-publication.d.ts +76 -0
  264. package/dist/sandbox/permission-config-publication.js +339 -0
  265. package/dist/sandbox/permission-context-types.d.ts +64 -0
  266. package/dist/sandbox/permission-context-types.js +24 -0
  267. package/dist/sandbox/permission-facts.d.ts +206 -0
  268. package/dist/sandbox/permission-facts.js +627 -0
  269. package/dist/sandbox/permission-facts.module.d.ts +2 -0
  270. package/dist/sandbox/permission-facts.module.js +20 -0
  271. package/dist/sandbox/permission-instance-writes.d.ts +90 -0
  272. package/dist/sandbox/permission-instance-writes.js +305 -0
  273. package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
  274. package/dist/sandbox/permission-runtime-reports.js +354 -0
  275. package/dist/sandbox/permission-transitions.d.ts +31 -0
  276. package/dist/sandbox/permission-transitions.js +155 -0
  277. package/dist/sandbox/platform-full-access.d.ts +128 -0
  278. package/dist/sandbox/platform-full-access.js +210 -0
  279. package/dist/sandbox/providers.d.ts +22 -0
  280. package/dist/sandbox/providers.js +10 -2
  281. package/dist/sandbox/providers.module.d.ts +2 -0
  282. package/dist/sandbox/providers.module.js +19 -0
  283. package/dist/sandbox/request-not-sent.d.ts +13 -0
  284. package/dist/sandbox/request-not-sent.js +13 -0
  285. package/dist/sandbox/review/classifier.d.ts +2 -0
  286. package/dist/sandbox/review/classifier.js +8 -0
  287. package/dist/sandbox/review/permission-candidate.d.ts +12 -0
  288. package/dist/sandbox/review/permission-candidate.js +145 -0
  289. package/dist/sandbox/review/review.service.d.ts +5 -2
  290. package/dist/sandbox/review/review.service.js +60 -15
  291. package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
  292. package/dist/sandbox/sandbox-file-reader.js +51 -7
  293. package/dist/sandbox/sandbox.module.js +26 -6
  294. package/dist/sandbox/sandbox.service.d.ts +230 -34
  295. package/dist/sandbox/sandbox.service.js +1368 -199
  296. package/dist/sandbox/unreachable.js +17 -3
  297. package/dist/sandbox/use-context.d.ts +17 -0
  298. package/dist/sandbox/use-context.js +1 -0
  299. package/dist/skills/invoke.d.ts +27 -4
  300. package/dist/skills/invoke.js +72 -7
  301. package/dist/tools/approvals.controller.d.ts +1 -0
  302. package/dist/tools/approvals.schemas.d.ts +1 -0
  303. package/dist/tools/approvals.schemas.js +3 -1
  304. package/dist/tools/approvals.service.d.ts +23 -10
  305. package/dist/tools/approvals.service.js +104 -26
  306. package/dist/tools/builtin-names.d.ts +3 -1
  307. package/dist/tools/builtin-names.js +5 -1
  308. package/dist/tools/builtins/artifacts.d.ts +43 -0
  309. package/dist/tools/builtins/artifacts.js +67 -0
  310. package/dist/tools/builtins/builtin-tools.d.ts +20 -2
  311. package/dist/tools/builtins/builtin-tools.js +61 -10
  312. package/dist/tools/builtins/image/generate.d.ts +59 -0
  313. package/dist/tools/builtins/image/generate.js +535 -0
  314. package/dist/tools/builtins/image/index.d.ts +2 -0
  315. package/dist/tools/builtins/image/index.js +2 -0
  316. package/dist/tools/builtins/image/paths.d.ts +12 -0
  317. package/dist/tools/builtins/image/paths.js +26 -0
  318. package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
  319. package/dist/tools/builtins/sandbox/bash.js +201 -5
  320. package/dist/tools/builtins/sandbox/common.d.ts +92 -20
  321. package/dist/tools/builtins/sandbox/common.js +201 -17
  322. package/dist/tools/builtins/sandbox/deliver.js +9 -51
  323. package/dist/tools/builtins/sandbox/edit.js +2 -2
  324. package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
  325. package/dist/tools/builtins/sandbox/glob.js +2 -2
  326. package/dist/tools/builtins/sandbox/grep.js +2 -2
  327. package/dist/tools/builtins/sandbox/read.js +2 -2
  328. package/dist/tools/builtins/sandbox/task-list.js +7 -1
  329. package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
  330. package/dist/tools/builtins/sandbox/task-output.js +172 -0
  331. package/dist/tools/builtins/sandbox/task-stop.js +25 -3
  332. package/dist/tools/builtins/sandbox/write.js +2 -2
  333. package/dist/tools/builtins/skill-load.js +9 -6
  334. package/dist/tools/device-op-resolver.d.ts +1 -1
  335. package/dist/tools/device-op-resolver.js +13 -3
  336. package/dist/tools/permission-approval-jobs.d.ts +18 -0
  337. package/dist/tools/permission-approval-jobs.js +92 -0
  338. package/dist/tools/pipeline.d.ts +17 -2
  339. package/dist/tools/pipeline.js +315 -26
  340. package/dist/tools/registry.d.ts +9 -0
  341. package/dist/tools/tools.module.js +15 -0
  342. package/package.json +4 -3
  343. package/src/migrations/0146_permission_authority_epochs.sql +6 -0
  344. package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
  345. package/src/migrations/0148_first_message_request_hash.sql +2 -0
  346. package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
  347. package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
  348. package/src/migrations/0151_starting_execution_grants.sql +8 -0
  349. package/src/migrations/0152_background_launch_identity.sql +66 -0
  350. package/src/migrations/0153_background_cancel_requester.sql +13 -0
  351. package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
  352. package/src/migrations/0155_device_instance_generations.sql +30 -0
  353. package/src/migrations/0156_device_owner_report.sql +7 -0
  354. package/src/migrations/0157_legacy_retirement.sql +116 -0
  355. package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
  356. package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
  357. package/src/migrations/0160_model_usage_image_kind.sql +10 -0
  358. package/dist/sandbox/platform-auto-mode.d.ts +0 -63
  359. package/dist/sandbox/platform-auto-mode.js +0 -63
@@ -27,6 +27,7 @@ import { runContextIdemKey } from "../runtime/run-context.service.js";
27
27
  import { recordedSkillForks } from "../runtime/subagents/skill-fork.js";
28
28
  import { skillsCatalogIdemKey } from "../skills/catalog.js";
29
29
  import { ACTIVE_EVAL_STATUSES, addUsage, consumeTokens, TOO_MANY_ERRORS, usageTokens, } from "./budget.js";
30
+ import { recordedPermissionContext, recordedRunPermissionDrift, } from "./recorded-permission-context.js";
30
31
  import { RecordedToolPipeline, recordedCalls } from "./recorded-tools.js";
31
32
  import { toEvents } from "./snapshot.js";
32
33
  /** 写种子时发现已失去认领或运行已不在执行:本次执行停下,不留评测对话。 */
@@ -371,6 +372,14 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
371
372
  const source = s.source ?? (subagent === undefined ? "web" : "subagent");
372
373
  const conversationId = randomUUID();
373
374
  const runId = randomUUID();
375
+ // recorded permission context (spec B4), both before anything is seeded so an invalid recording
376
+ // fails as `eval.snapshot_invalid` without an eval conversation: the original-coordinate
377
+ // diagnostics, and the recorded-only feeder (undefined for a recording without markers)
378
+ const permissionContextDrift = recordedRunPermissionDrift(s);
379
+ const permissionContext = recordedPermissionContext(s, eventLog, { conversationId, runId });
380
+ // the recorded tool results (reviews validated here) are read before the seed too, so an
381
+ // invalid recording leaves no eval conversation either
382
+ const recordings = recordedCalls(s);
374
383
  await d.seeder.seed({
375
384
  evalRunId,
376
385
  orgId: s.orgId,
@@ -486,7 +495,7 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
486
495
  };
487
496
  const pipeline = new RecordedToolPipeline({
488
497
  eventLog,
489
- recordings: recordedCalls(s),
498
+ recordings,
490
499
  // 出错直接抛出:tools 节点的异常让 loop 抛出,按崩溃处理
491
500
  beforeStep: async () => {
492
501
  if (await allowed())
@@ -565,7 +574,13 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
565
574
  timer?.unref();
566
575
  // a fork invocation's report is the recorded one: a replay never dispatches a sub-agent (A5)
567
576
  const skillForks = recordedSkillForks(eventLog, s.events.filter((e) => e.runId === s.runId));
568
- const loop = d.loop({ toolPipeline: pipeline, registry, skillForks, ...(media && { media }) });
577
+ const loop = d.loop({
578
+ toolPipeline: pipeline,
579
+ registry,
580
+ skillForks,
581
+ ...(media && { media }),
582
+ ...(permissionContext !== undefined && { permissionContext }),
583
+ });
569
584
  // a replay never executes a tool, so the role only completes the context
570
585
  const membership = await db
571
586
  .selectFrom("memberships")
@@ -662,5 +677,6 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
662
677
  outcome: outcome.kind,
663
678
  ...summary,
664
679
  unmatched: pipeline.unmatched(),
680
+ ...(permissionContextDrift && { permissionContextDrift: true }),
665
681
  };
666
682
  }
@@ -54,7 +54,7 @@ export interface TrajectoryToolCall {
54
54
  approval: {
55
55
  approvalId: string;
56
56
  requestedAt: string;
57
- decision: "approved" | "denied" | "expired" | "cancelled" | "skipped" | null;
57
+ decision: "approved" | "denied" | "expired" | "cancelled" | "skipped" | "superseded" | null;
58
58
  scope?: "once" | "session" | "always";
59
59
  byAccountId: string | null;
60
60
  decidedAt: string | null;
@@ -7,6 +7,7 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
7
7
  import type { KernelLogger } from "../log.js";
8
8
  import { ModelPurposesService } from "../models/purposes.js";
9
9
  import { KyselyCheckpointSaver } from "../runtime/checkpointer.js";
10
+ import type { LoopDeps } from "../runtime/langgraph-loop.js";
10
11
  import { ProviderRegistry } from "../runtime/providers.js";
11
12
  import { type OrgQuota } from "../runtime/quota.js";
12
13
  import { RunFinish } from "../runtime/run-finish.js";
@@ -14,7 +15,7 @@ import { AgentLoops, RunSteps } from "../runtime/run-steps.js";
14
15
  import { EvalBudget } from "./budget.js";
15
16
  import { type EvalJobData } from "./jobs.js";
16
17
  import { type SubagentTemplateRef } from "./reconstruct.js";
17
- import { type EvalReplayHooks, EvalReplaySeeder } from "./run-replay.js";
18
+ import { type EvalReplayHooks, EvalReplaySeeder, type RunReplayDeps } from "./run-replay.js";
18
19
  import { type CaseSnapshot } from "./snapshot.js";
19
20
  /**
20
21
  * 评测 worker(C7,只在含 `worker` 角色的进程启动):领取 `cap-kernel-evals` 的任务,每个任务回放一个用例。
@@ -41,6 +42,14 @@ export declare const EVAL_MAX_STALLED_COUNT = 3;
41
42
  * (`overrides: [{ provide: EVAL_REPLAY_HOOKS, useValue }]`), absent in production.
42
43
  */
43
44
  export declare const EVAL_REPLAY_HOOKS: unique symbol;
45
+ /**
46
+ * The loop deps of a full-run replay: the run's own step deps without anything live that a replay
47
+ * must never trigger, then the replay's overrides. Removed: plugin hooks (P-18), sub-agent and
48
+ * compaction progress on a live stream, fork dispatch (run-replay passes the recorded reports) and
49
+ * the live permission context recorder (permission context replay spec B4): a replay gets only the
50
+ * recorded feeder `overrides.permissionContext`, and none at all for a recording without markers.
51
+ */
52
+ export declare function replayLoopDeps(stepDeps: LoopDeps, overrides: Parameters<RunReplayDeps["loop"]>[0]): LoopDeps;
44
53
  export declare class EvalWorker {
45
54
  readonly txHost: TransactionHost;
46
55
  private worker;
@@ -70,6 +70,25 @@ export const EVAL_REPLAY_HOOKS = Symbol("EVAL_REPLAY_HOOKS");
70
70
  /** 供应商插件在调用途中被撤销(错误本身或其 cause)。 */
71
71
  const isPluginUnloaded = (err) => err instanceof ExtensionUnloadedError ||
72
72
  (err instanceof Error && err.cause instanceof ExtensionUnloadedError);
73
+ /**
74
+ * The loop deps of a full-run replay: the run's own step deps without anything live that a replay
75
+ * must never trigger, then the replay's overrides. Removed: plugin hooks (P-18), sub-agent and
76
+ * compaction progress on a live stream, fork dispatch (run-replay passes the recorded reports) and
77
+ * the live permission context recorder (permission context replay spec B4): a replay gets only the
78
+ * recorded feeder `overrides.permissionContext`, and none at all for a recording without markers.
79
+ */
80
+ export function replayLoopDeps(stepDeps, overrides) {
81
+ const { db: _snapshot, hooks: _noHooks, subagentProgress: _noProgress, compactionProgress: _noCompactionProgress, skillForks: _noForks, permissionContext: _noLivePermissionContext, ...replayDeps } = stepDeps;
82
+ // the object rest above copied `db` as a value: read it through the step deps' getter
83
+ // instead, so the loop always resolves the context-aware handle
84
+ return {
85
+ ...replayDeps,
86
+ get db() {
87
+ return stepDeps.db;
88
+ },
89
+ ...overrides,
90
+ };
91
+ }
73
92
  /** 回放出错的分类(与运行时的降级梯子同一套码)。 */
74
93
  function classify(err) {
75
94
  if (isModelError(err)) {
@@ -201,19 +220,7 @@ let EvalWorker = class EvalWorker {
201
220
  checkpoints,
202
221
  // explicitly without plugin hooks: eval replays never fire them (P-18); nor do they
203
222
  // publish sub-agent progress on a live conversation's stream
204
- loop: (d) => {
205
- // nor dispatch fork invocations: run-replay passes the recorded reports instead
206
- const { db: _snapshot, hooks: _noHooks, subagentProgress: _noProgress, compactionProgress: _noCompactionProgress, skillForks: _noForks, ...replayDeps } = stepDeps;
207
- // the object rest above copied `db` as a value: read it through the step deps' getter
208
- // instead, so the loop always resolves the context-aware handle
209
- return loops.create({
210
- ...replayDeps,
211
- get db() {
212
- return stepDeps.db;
213
- },
214
- ...d,
215
- });
216
- },
223
+ loop: (d) => loops.create(replayLoopDeps(stepDeps, d)),
217
224
  ...(hooks !== undefined && { hooks }),
218
225
  },
219
226
  };
@@ -684,10 +691,12 @@ let EvalWorker = class EvalWorker {
684
691
  if (!(await held()))
685
692
  return;
686
693
  const baseline = runBaseline(s);
687
- // in DRIFT_ORDER: subagent_changed, then model_switched (the candidate replaced the person's
694
+ // in DRIFT_ORDER: subagent_changed, permission_profile_changed (a recorded permission
695
+ // context the snapshot cannot reproduce), model_switched (the candidate replaced the person's
688
696
  // switch), then tool_unmatched
689
697
  const drift = [
690
698
  ...(subagentCaseChanged(s, resolved) ? ["subagent_changed"] : []),
699
+ ...(out.permissionContextDrift ? ["permission_profile_changed"] : []),
691
700
  ...(resolved.overridesSwitch ? ["model_switched"] : []),
692
701
  ...(out.unmatched > 0 ? ["tool_unmatched"] : []),
693
702
  ];
@@ -12,6 +12,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
12
12
  import { LockService } from "../infra/lock/lock.service.js";
13
13
  import type { KernelLogger } from "../log.js";
14
14
  import { ModelEmbeddings } from "../models/embeddings.js";
15
+ import { ModelImages } from "../models/images.js";
15
16
  import { OrgNetworkAllowances } from "../orgs/network-allowances.service.js";
16
17
  import { EmbedTokens } from "../ui/embed-token.js";
17
18
  import type { UiActionHandler, UiRender } from "../ui/registry.js";
@@ -266,7 +267,9 @@ export declare class ExtensionHost {
266
267
  */
267
268
  effective: Pick<EffectiveConfigs, "get">,
268
269
  /** `ctx.models`: the embeddings broker (spec B §5.4). */
269
- models: Pick<ModelEmbeddings, "embed" | "describe">,
270
+ embeddings: Pick<ModelEmbeddings, "embed" | "describe">,
271
+ /** `ctx.models.generateImage`: the image generation calls (image generation spec §5.5). */
272
+ images: Pick<ModelImages, "generateForExtension" | "describeForExtension">,
270
273
  /** `ctx.net`: the internal endpoints each org's extension requests may reach (read per call). */
271
274
  allowances: OrgNetworkAllowances,
272
275
  /** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
@@ -26,6 +26,7 @@ import { LockService } from "../infra/lock/lock.service.js";
26
26
  import { KERNEL_LOGGER, KEYRING, REDIS, REDIS_SUBSCRIBER } from "../infra/tokens.js";
27
27
  import { KERNEL_APP_OPTIONS } from "../lifecycle/tokens.js";
28
28
  import { ModelEmbeddings } from "../models/embeddings.js";
29
+ import { ModelImages } from "../models/images.js";
29
30
  import { OrgNetworkAllowances } from "../orgs/network-allowances.service.js";
30
31
  import { packagePath } from "../packages/tgz.js";
31
32
  import { EmbedTokens } from "../ui/embed-token.js";
@@ -413,7 +414,9 @@ let ExtensionHost = class ExtensionHost {
413
414
  */
414
415
  effective,
415
416
  /** `ctx.models`: the embeddings broker (spec B §5.4). */
416
- models,
417
+ embeddings,
418
+ /** `ctx.models.generateImage`: the image generation calls (image generation spec §5.5). */
419
+ images,
417
420
  /** `ctx.net`: the internal endpoints each org's extension requests may reach (read per call). */
418
421
  allowances,
419
422
  /** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
@@ -445,8 +448,8 @@ let ExtensionHost = class ExtensionHost {
445
448
  redisUrl: c.redis.url,
446
449
  keyring,
447
450
  embedTokens,
448
- models,
449
- // ctx.models.embed fires model.request through the same registry (spec B §5.4)
451
+ models: { embeddings, images },
452
+ // ctx.models.embed and generateImage fire model.request through the same registry
450
453
  hooks: this.hooks,
451
454
  net: { config, allowances, ...(netSeams !== undefined && { seams: netSeams }) },
452
455
  locks,
@@ -2394,8 +2397,9 @@ ExtensionHost = __decorate([
2394
2397
  __param(12, Inject(KERNEL_APP_OPTIONS)),
2395
2398
  __param(13, Inject(EffectiveConfigs)),
2396
2399
  __param(14, Inject(ModelEmbeddings)),
2397
- __param(15, Inject(OrgNetworkAllowances)),
2398
- __param(16, Optional()),
2399
- __param(16, Inject(EXTENSION_NET_SEAMS))
2400
+ __param(15, Inject(ModelImages)),
2401
+ __param(16, Inject(OrgNetworkAllowances)),
2402
+ __param(17, Optional()),
2403
+ __param(17, Inject(EXTENSION_NET_SEAMS))
2400
2404
  ], ExtensionHost);
2401
2405
  export { ExtensionHost };
@@ -40,6 +40,7 @@ import { ClientDeliveryController } from "../client/client-delivery.controller.j
40
40
  import { AttachmentsController } from "../conversations/attachments.controller.js";
41
41
  import { ConversationsController } from "../conversations/conversations.controller.js";
42
42
  import { ConversationsModule } from "../conversations/conversations.module.js";
43
+ import { PermissionProfilesController } from "../conversations/permission-profiles.controller.js";
43
44
  import { DevicesController } from "../devices/devices.controller.js";
44
45
  import { DevicesModule } from "../devices/devices.module.js";
45
46
  import { EvalsModule } from "../evals/evals.module.js";
@@ -129,6 +130,7 @@ const CONTROLLERS = [
129
130
  ModelEnablementController,
130
131
  ReadinessController,
131
132
  ConversationsController,
133
+ PermissionProfilesController,
132
134
  BackgroundController,
133
135
  DevicesController,
134
136
  SchedulesController,
@@ -3,6 +3,7 @@ import { SetupLock } from "../admin/setup-lock.js";
3
3
  import type { AccountsTable } from "../db/kernel-schema.js";
4
4
  import { KernelDb } from "../infra/database/kernel-db.js";
5
5
  import { TransactionHost } from "../infra/database/transaction-host.js";
6
+ import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
6
7
  import { SuperAdminLock } from "./super-admin.js";
7
8
  export interface Account {
8
9
  id: string;
@@ -56,7 +57,8 @@ export declare class AccountsService {
56
57
  readonly txHost: TransactionHost;
57
58
  private readonly adminLock;
58
59
  private readonly setupLock;
59
- constructor(db: KernelDb, txHost: TransactionHost, adminLock: SuperAdminLock, setupLock: SetupLock);
60
+ private readonly ceilings;
61
+ constructor(db: KernelDb, txHost: TransactionHost, adminLock: SuperAdminLock, setupLock: SetupLock, ceilings: PermissionCeilingWrites);
60
62
  /** Checks the password length and hashes it (scrypt, slow): for callers that hash before their transaction opens. */
61
63
  hashNewPassword(password: string): Promise<string>;
62
64
  /**
@@ -140,6 +142,11 @@ export declare class AccountsService {
140
142
  * account's sessions (`sessions.revoked_at`) and personal tokens in **the same PG transaction**,
141
143
  * all or nothing; returns the revoked session ids, whose Redis markers the caller writes after
142
144
  * the commit (the fast path; a failure is only a warning: auth reads PG).
145
+ *
146
+ * The super admin lock and, for a status change, the platform permission authority lock are the
147
+ * transaction's ordered prelude (`withOrderedLocks`): inside a run's fence (the Platform tool's
148
+ * `accounts.disable` / `accounts.enable`) they follow the org row and precede the conversation
149
+ * rows.
143
150
  */
144
151
  updateAccount(id: string, patch: AccountPatch, actorAccountId: string, actorTokenId?: string, opts?: {
145
152
  auditDetail?: Record<string, unknown>;
@@ -147,6 +154,12 @@ export declare class AccountsService {
147
154
  account: Account;
148
155
  revokedSessionIds: string[];
149
156
  }>;
157
+ /**
158
+ * The prelude of {@link updateAccount}: the super admin lock (re-checking the actor), then the
159
+ * platform permission authority lock when the status changes; whether it locked it.
160
+ */
161
+ private lockForUpdate;
162
+ private updateAccountIn;
150
163
  /**
151
164
  * The CLI's `capybara admin grant|revoke <login>` (no actor account): changes the super
152
165
  * admin flag by local login under the super admin lock; revoking keeps the
@@ -13,8 +13,10 @@ import { sql } from "kysely";
13
13
  import { SetupLock, SetupLockModule } from "../admin/setup-lock.js";
14
14
  import { ApiError } from "../errors.js";
15
15
  import { KernelDb } from "../infra/database/kernel-db.js";
16
- import { TransactionHost } from "../infra/database/transaction-host.js";
16
+ import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
17
17
  import { Transactional } from "../infra/database/transactional.decorator.js";
18
+ import { PermissionCeilingWritesModule } from "../sandbox/permission-authority.module.js";
19
+ import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
18
20
  import { assertThemeOnForAccount } from "../themes/theme-state.js";
19
21
  import { audit } from "./audit.js";
20
22
  import { MAX_PASSWORD_LENGTH, normalizeLogin, validatePassword } from "./login.js";
@@ -65,11 +67,13 @@ let AccountsService = class AccountsService {
65
67
  txHost;
66
68
  adminLock;
67
69
  setupLock;
68
- constructor(db, txHost, adminLock, setupLock) {
70
+ ceilings;
71
+ constructor(db, txHost, adminLock, setupLock, ceilings) {
69
72
  this.db = db;
70
73
  this.txHost = txHost;
71
74
  this.adminLock = adminLock;
72
75
  this.setupLock = setupLock;
76
+ this.ceilings = ceilings;
73
77
  }
74
78
  /** Checks the password length and hashes it (scrypt, slow): for callers that hash before their transaction opens. */
75
79
  async hashNewPassword(password) {
@@ -329,12 +333,43 @@ let AccountsService = class AccountsService {
329
333
  * account's sessions (`sessions.revoked_at`) and personal tokens in **the same PG transaction**,
330
334
  * all or nothing; returns the revoked session ids, whose Redis markers the caller writes after
331
335
  * the commit (the fast path; a failure is only a warning: auth reads PG).
336
+ *
337
+ * The super admin lock and, for a status change, the platform permission authority lock are the
338
+ * transaction's ordered prelude (`withOrderedLocks`): inside a run's fence (the Platform tool's
339
+ * `accounts.disable` / `accounts.enable`) they follow the org row and precede the conversation
340
+ * rows.
332
341
  */
333
342
  async updateAccount(id, patch, actorAccountId, actorTokenId, opts = {}) {
343
+ // filled by the prelude, which runs once the body's transaction opens (after the call)
344
+ const locked = { platform: false };
345
+ return withOrderedLocks(async () => {
346
+ locked.platform = await this.lockForUpdate(id, patch, actorAccountId);
347
+ }, () => this.updateAccountIn(id, patch, actorAccountId, actorTokenId, opts, locked));
348
+ }
349
+ /**
350
+ * The prelude of {@link updateAccount}: the super admin lock (re-checking the actor), then the
351
+ * platform permission authority lock when the status changes; whether it locked it.
352
+ */
353
+ async lockForUpdate(id, patch, actorAccountId) {
334
354
  // Every super admin write is serialized by one lock and re-checks the actor under it: two
335
355
  // admins revoking each other concurrently cannot leave none, and a just-revoked admin's
336
356
  // request in flight fails
337
357
  await this.adminLock.lockAndAuthorize(actorAccountId);
358
+ if (patch.status === undefined)
359
+ return false;
360
+ const row = await this.db
361
+ .selectFrom("accounts")
362
+ .select("status")
363
+ .where("id", "=", id)
364
+ .executeTakeFirst();
365
+ if (row === undefined || row.status === patch.status)
366
+ return false;
367
+ await this.ceilings.lock({}, "platform");
368
+ return true;
369
+ }
370
+ async updateAccountIn(id, patch, actorAccountId, actorTokenId, opts, locked) {
371
+ // held since the prelude; taking it again re-checks the actor
372
+ await this.adminLock.lockAndAuthorize(actorAccountId);
338
373
  const before = await this.db
339
374
  .selectFrom("accounts")
340
375
  .selectAll()
@@ -342,6 +377,9 @@ let AccountsService = class AccountsService {
342
377
  .executeTakeFirst();
343
378
  if (!before)
344
379
  throw new ApiError("account.not_found", "Account not found");
380
+ // a status that changed since the prelude read it would need the platform lock it did not take
381
+ if (patch.status !== undefined && patch.status !== before.status && !locked.platform)
382
+ throw new ApiError("conflict", "The account's status changed; retry the change");
345
383
  return this.applyUpdate(before, patch, {
346
384
  actorAccountId,
347
385
  ...(actorTokenId !== undefined && { actorTokenId }),
@@ -470,6 +508,20 @@ let AccountsService = class AccountsService {
470
508
  const values = { updated_at: new Date() };
471
509
  if (patch.displayName !== undefined)
472
510
  values.display_name = patch.displayName;
511
+ if (patch.status !== undefined && patch.status !== before.status) {
512
+ await this.ceilings.lock({}, "platform");
513
+ await this.ceilings.publishLocked({}, "platform", patch.status === "disabled" ? (_scope, row) => row.account_id === id : false);
514
+ await this.db
515
+ .updateTable("conversations")
516
+ .set((eb) => ({
517
+ permission_profile: "approve-for-me",
518
+ permission_consent: null,
519
+ permission_revision: eb("permission_revision", "+", 1),
520
+ }))
521
+ .where("account_id", "=", id)
522
+ .where("permission_profile", "=", "full-access")
523
+ .execute();
524
+ }
473
525
  if (patch.status !== undefined)
474
526
  values.status = patch.status;
475
527
  if (patch.isSuperAdmin !== undefined)
@@ -527,9 +579,12 @@ __decorate([
527
579
  __decorate([
528
580
  Transactional()
529
581
  ], AccountsService.prototype, "changePasswordIn", null);
582
+ __decorate([
583
+ Transactional({ propagation: "mandatory" })
584
+ ], AccountsService.prototype, "lockForUpdate", null);
530
585
  __decorate([
531
586
  Transactional()
532
- ], AccountsService.prototype, "updateAccount", null);
587
+ ], AccountsService.prototype, "updateAccountIn", null);
533
588
  __decorate([
534
589
  Transactional()
535
590
  ], AccountsService.prototype, "setSuperAdminIn", null);
@@ -547,7 +602,8 @@ AccountsService = __decorate([
547
602
  __param(0, Inject(KernelDb)),
548
603
  __param(1, Inject(TransactionHost)),
549
604
  __param(2, Inject(SuperAdminLock)),
550
- __param(3, Inject(SetupLock))
605
+ __param(3, Inject(SetupLock)),
606
+ __param(4, Inject(PermissionCeilingWrites))
551
607
  ], AccountsService);
552
608
  export { AccountsService };
553
609
  /**
@@ -559,7 +615,7 @@ let AccountsModule = class AccountsModule {
559
615
  };
560
616
  AccountsModule = __decorate([
561
617
  Module({
562
- imports: [SetupLockModule, SuperAdminLockModule],
618
+ imports: [SetupLockModule, SuperAdminLockModule, PermissionCeilingWritesModule],
563
619
  providers: [AccountsService],
564
620
  exports: [AccountsService],
565
621
  })
@@ -8,6 +8,7 @@ import { Module } from "@nestjs/common";
8
8
  import { SetupLockModule } from "../admin/setup-lock.js";
9
9
  import { ExtensionRegistryModule } from "../extensions/registry.js";
10
10
  import { OrgLockModule } from "../orgs/org-lock.js";
11
+ import { PermissionAuthorityModule } from "../sandbox/permission-authority.module.js";
11
12
  import { AccountsModule } from "./accounts.js";
12
13
  import { ApiTokenService } from "./api-tokens.js";
13
14
  import { IdentityBinding } from "./binding.js";
@@ -27,6 +28,7 @@ let IdentityModule = class IdentityModule {
27
28
  IdentityModule = __decorate([
28
29
  Module({
29
30
  imports: [
31
+ PermissionAuthorityModule,
30
32
  AccountsModule,
31
33
  OrgLockModule,
32
34
  SetupLockModule,
@@ -5,7 +5,8 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
5
5
  import { KernelDb } from "../infra/database/kernel-db.js";
6
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
7
7
  import type { KernelLogger } from "../log.js";
8
- import { type DevicesAutoModePatch, type DevicesAutoModeStored, type DevicesAutoModeView } from "../sandbox/platform-auto-mode.js";
8
+ import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
9
+ import { type DevicesAutoModeView, type DevicesFullAccessPatch, type DevicesFullAccessStored, type DevicesFullAccessView } from "../sandbox/platform-full-access.js";
9
10
  import { type UiArrangement } from "../ui/arrangement.js";
10
11
  import { SuperAdminLock } from "./super-admin.js";
11
12
  /** 沙箱 cpu(核)与内存(MB)覆盖的范围(C19)。 */
@@ -166,6 +167,8 @@ export type DeploymentSettings = z.infer<typeof DEPLOYMENT_SETTINGS>;
166
167
  * attribution defaults with their sources the same way.
167
168
  */
168
169
  export type DeploymentSettingsView = DeploymentSettings & {
170
+ devicesFullAccess: DevicesFullAccessView;
171
+ /** The same switch under its old public name, until the old public readers are removed. */
169
172
  devicesAutoMode: DevicesAutoModeView;
170
173
  attribution: PlatformAttributionView;
171
174
  };
@@ -211,6 +214,12 @@ export declare const DEPLOYMENT_SETTINGS_PATCH: z.ZodObject<{
211
214
  enabled: z.ZodOptional<z.ZodBoolean>;
212
215
  disabled: z.ZodOptional<z.ZodArray<z.ZodString>>;
213
216
  }, z.core.$strict>>;
217
+ devicesFullAccess: z.ZodOptional<z.ZodObject<{
218
+ permission: z.ZodNullable<z.ZodEnum<{
219
+ allowed: "allowed";
220
+ off: "off";
221
+ }>>;
222
+ }, z.core.$strict>>;
214
223
  devicesAutoMode: z.ZodOptional<z.ZodObject<{
215
224
  mode: z.ZodNullable<z.ZodEnum<{
216
225
  allowed: "allowed";
@@ -280,31 +289,37 @@ export declare function readUiArrangement(db: KernelSchemaDb): Promise<UiArrange
280
289
  * {@link parseClientExtensions} (missing or invalid -> everything on; invalid also warns on `log`).
281
290
  */
282
291
  export declare function readClientExtensions(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">): Promise<ClientExtensionsKillSwitch>;
292
+ /**
293
+ * A patch with the old `devicesAutoMode` moved to `devicesFullAccess`; both together is a
294
+ * validation error (never pick one silently).
295
+ */
296
+ export declare function normalizeDeploymentSettingsPatch(patch: DeploymentSettingsPatch): DeploymentSettingsPatch;
283
297
  /** Deployment settings: one row per key, defaults for missing keys. */
284
298
  export declare class SettingsService {
285
299
  private readonly db;
286
300
  readonly txHost: TransactionHost;
287
301
  private readonly adminLock;
288
302
  private readonly log;
289
- /** The startup config's `devices.autoMode`, which wins over the stored choice. */
303
+ /** The startup config's `devices.fullAccess`, which wins over the stored choice. */
290
304
  private readonly config;
305
+ private readonly ceilings;
291
306
  constructor(db: KernelDb, txHost: TransactionHost, adminLock: SuperAdminLock, log: Pick<KernelLogger, "warn">,
292
- /** The startup config's `devices.autoMode`, which wins over the stored choice. */
293
- config: Pick<KernelConfigService, "get" | "fieldSource">);
294
- /** The settings with the platform's auto-mode switch and attribution defaults in effect. */
307
+ /** The startup config's `devices.fullAccess`, which wins over the stored choice. */
308
+ config: Pick<KernelConfigService, "get" | "fieldSource">, ceilings: PermissionCeilingWrites);
309
+ /** The settings with the platform's Full switch and attribution defaults in effect. */
295
310
  view(): Promise<DeploymentSettingsView>;
296
311
  private attributionView;
297
312
  /**
298
- * The refusals of a `devicesAutoMode` change: a value set in the startup config
313
+ * The refusals of a `devicesFullAccess` change: a value set in the startup config
299
314
  * (`deployment.setting_readonly`) and, with `onlyNarrows` (an API token, the Platform tool),
300
- * turning auto mode on where it is off (`deployment.auto_mode_not_allowed`). Returns the next
301
- * stored choice and the effective switch before it.
315
+ * allowing Full where it is off (`deployment.auto_mode_not_allowed`). Returns the next stored
316
+ * choice and the effective switch before it.
302
317
  */
303
- checkDevicesAutoMode(patch: DevicesAutoModePatch, opts?: {
318
+ checkDevicesFullAccess(patch: DevicesFullAccessPatch, opts?: {
304
319
  onlyNarrows?: boolean;
305
320
  }): Promise<{
306
- next: DevicesAutoModeStored;
307
- before: DevicesAutoModeView;
321
+ next: DevicesFullAccessStored;
322
+ before: DevicesFullAccessView;
308
323
  }>;
309
324
  /**
310
325
  * The refusals of an `attribution` change against the stored choice: a field set in the startup
@@ -320,12 +335,13 @@ export declare class SettingsService {
320
335
  get(): Promise<DeploymentSettings>;
321
336
  /**
322
337
  * Updates settings under the super admin lock, re-checking the actor (else `forbidden`).
323
- * `onlyNarrows` (an API token, the Platform tool): `devicesAutoMode` may only turn auto mode off.
338
+ * `onlyNarrows` (an API token, the Platform tool): `devicesFullAccess` may only turn Full off.
324
339
  */
325
340
  update(patch: DeploymentSettingsPatch, actorAccountId: string, actorTokenId?: string,
326
341
  /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
327
342
  auditDetail?: Record<string, unknown>, opts?: {
328
343
  onlyNarrows?: boolean;
329
344
  }): Promise<DeploymentSettingsView>;
345
+ private lockFor;
330
346
  private write;
331
347
  }