@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
@@ -2,9 +2,12 @@ import { ApiError } from "../errors.js";
2
2
  import { KernelDb } from "../infra/database/kernel-db.js";
3
3
  import { TransactionHost } from "../infra/database/transaction-host.js";
4
4
  import type { SandboxMode } from "../sandbox/modes.js";
5
- import { SandboxProviders } from "../sandbox/providers.js";
5
+ import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
6
+ import { PermissionFacts } from "../sandbox/permission-facts.js";
6
7
  import { SandboxService } from "../sandbox/sandbox.service.js";
7
8
  import { DeviceAccess } from "./access.js";
9
+ import { type DeviceProjectScope } from "./project-rules.js";
10
+ export { type DeviceProjectScope, readModeOf, withinMode } from "./project-rules.js";
8
11
  /** The most projects one device keeps (project root §4.1). */
9
12
  export declare const MAX_DEVICE_PROJECTS = 100;
10
13
  /** A project as the web and the Platform tool see it. */
@@ -45,27 +48,6 @@ export interface DeviceProjectCandidates {
45
48
  base: string | null;
46
49
  supported: boolean;
47
50
  }
48
- /** What a project's scope is read from: the device's mode now and the bases it gives. */
49
- export interface DeviceProjectScope {
50
- source: "cloud" | "local";
51
- mode: SandboxMode;
52
- /** The workspace root as last known (a machine's hello, a cloud instance's handle). */
53
- workspace: string;
54
- /** The owner's home a local machine reported; null when unknown (and for a cloud device). */
55
- home: string | null;
56
- supported: boolean;
57
- /**
58
- * A machine whose own policy is auto mode while the organization allows only sandbox mode: exec
59
- * refuses it (`device.auto_mode_not_allowed`), and the kernel reads nothing on it unasked.
60
- */
61
- widerThanAllowed: boolean;
62
- }
63
- type Scope = DeviceProjectScope;
64
- /**
65
- * `path` lies inside what the scope's mode may read (sandbox mode and cloud: the workspace, as the
66
- * held instance reports it when given).
67
- */
68
- export declare const withinMode: (s: Scope, path: string, workspace?: string) => boolean;
69
51
  /**
70
52
  * A device's projects (project root design §4.1, §4.2, §6): kept in `device_projects`, keyed by the
71
53
  * device's id, written only here. Only the device's owner reads or changes them (anyone else gets
@@ -79,10 +61,15 @@ export declare const withinMode: (s: Scope, path: string, workspace?: string) =>
79
61
  export declare class DeviceProjectsService {
80
62
  private readonly db;
81
63
  readonly txHost: TransactionHost;
82
- private readonly providers;
83
64
  private readonly sandbox;
84
65
  private readonly access;
85
- constructor(db: KernelDb, txHost: TransactionHost, providers: Pick<SandboxProviders, "cloud" | "forName">, sandbox: Pick<SandboxService, "withSandbox" | "devicePolicy">, access: Pick<DeviceAccess, "usable">);
66
+ private readonly facts;
67
+ private readonly ceilings;
68
+ /** The paired activation gate: once on, every device read is an owner browse. */
69
+ private readonly activation?;
70
+ constructor(db: KernelDb, txHost: TransactionHost, sandbox: Pick<SandboxService, "withSandbox" | "withBrowse" | "ensureRunningForOwner">, access: Pick<DeviceAccess, "usable">, facts: Pick<PermissionFacts, "resolveProjectForBinding" | "projectMatches" | "projectScope">, ceilings: PermissionCeilingWrites,
71
+ /** The paired activation gate: once on, every device read is an owner browse. */
72
+ activation?: boolean | undefined);
86
73
  /** The projects the device's current mode can read; see {@link DeviceProjectList}. */
87
74
  list(orgId: string, accountId: string, deviceId: string): Promise<DeviceProjectList>;
88
75
  /**
@@ -110,10 +97,18 @@ export declare class DeviceProjectsService {
110
97
  path: string;
111
98
  name?: string;
112
99
  }, actorTokenId?: string, auditDetail?: Record<string, unknown>, signal?: AbortSignal): Promise<DeviceProjectView>;
100
+ /**
101
+ * The owner's live device row, then its permission authority lock: the ordered prelude of the
102
+ * project writes (`withOrderedLocks`), so inside a run's fence (the Platform tool's
103
+ * `devices.add-project` / `devices.remove-project`) they follow the org row and precede the
104
+ * conversation rows. The writes name both again (already held: a re-check).
105
+ */
106
+ private lockSubject;
113
107
  /** The insert of {@link add}: the owner's live device locked, the count and the name checked. */
114
108
  private insert;
115
109
  /** Removes a project of the owner's device; removing one that is not there succeeds. */
116
110
  remove(orgId: string, accountId: string, deviceId: string, name: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<void>;
111
+ private removeIn;
117
112
  /**
118
113
  * The project a new conversation of `accountId` binds to (project root §4.3): one of the
119
114
  * owner's device's projects that its current mode can read. Refused with `device.not_found`
@@ -145,9 +140,13 @@ export declare class DeviceProjectsService {
145
140
  */
146
141
  private scope;
147
142
  /**
148
- * Runs `fn` on the device (`SandboxService.withSandbox`: its instance made or resumed as for a
149
- * tool call) with the workspace root its instance reports. Kernel refusals (offline, files lost,
150
- * busy, unavailable) stay as they are; anything else becomes a readable
143
+ * Runs `fn` on the device with a {@link ProjectReader}. While the activation gate is off:
144
+ * `SandboxService.withSandbox` (its instance made or resumed as for a tool call) with the
145
+ * workspace root its instance reports. Once it is on: the device started for its owner
146
+ * (`SandboxService.ensureRunningForOwner`), then the owner browse (`SandboxService.withBrowse`,
147
+ * as the device's owner, on the instance that runs) with the last known workspace; an instance
148
+ * that stopped in between is `device.not_running`. Kernel refusals (offline, files lost, busy,
149
+ * unavailable) stay as they are; anything else becomes a readable
151
150
  * `device.projects_unavailable`, never a 500.
152
151
  */
153
152
  private onDevice;
@@ -159,4 +158,3 @@ export declare class DeviceProjectsService {
159
158
  * person's project skill invocation).
160
159
  */
161
160
  export declare const providerUnreachable: () => ApiError;
162
- export {};
@@ -8,53 +8,60 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { posix } from "node:path";
11
- import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isDeviceProjectName, isFileSystemGoneError, isSandboxGoneError, MAX_DEVICE_SCAN_RESULTS, rootsOf, ToolError, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
12
- import { Inject, Injectable } from "@nestjs/common";
11
+ import { DeviceProtocolError, isDeviceProjectName, isFileSystemGoneError, isSandboxGoneError, isSandboxScopeDeniedError, MAX_DEVICE_SCAN_RESULTS, ToolError, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
12
+ import { Inject, Injectable, Optional } from "@nestjs/common";
13
13
  import { sql } from "kysely";
14
14
  import { ApiError } from "../errors.js";
15
15
  import { audit } from "../identity/audit.js";
16
16
  import { KernelDb } from "../infra/database/kernel-db.js";
17
- import { TransactionHost } from "../infra/database/transaction-host.js";
17
+ import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
18
18
  import { Transactional } from "../infra/database/transactional.decorator.js";
19
19
  import { projectsUnsupported } from "../local-devices/local-device-provider.js";
20
- import { deviceFeaturesOf, localModeOf } from "../local-devices/policy-summary.js";
21
20
  import { POLICY_REFUSAL_PREFIX } from "../local-devices/relay.js";
22
- import { providerForDevice, SandboxProviders } from "../sandbox/providers.js";
21
+ import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
22
+ import { PERMISSION_CONTEXT_ACTIVATION, permissionContextActive, } from "../sandbox/permission-context-types.js";
23
+ import { PermissionFacts } from "../sandbox/permission-facts.js";
23
24
  import { deviceNotFound, SandboxService } from "../sandbox/sandbox.service.js";
24
25
  import { SandboxProviderUnreachableError } from "../sandbox/unreachable.js";
25
26
  import { DeviceAccess } from "./access.js";
27
+ import { baseOf, clipped, homeUnknown, nameInvalid, nameTaken, outsideMode, readModeOf, tooBroad, withinMode, } from "./project-rules.js";
26
28
  // a path above the owner's home is never stored as a project: the working root would fall back for
27
29
  // it anyway (project root §4.3), so both use the one rule; the home itself may be one
28
30
  import { aboveHome } from "./working-root.js";
31
+ export { readModeOf, withinMode } from "./project-rules.js";
29
32
  /** The most projects one device keeps (project root §4.1). */
30
33
  export const MAX_DEVICE_PROJECTS = 100;
31
34
  /**
32
35
  * The holder name the projects service enters a device's sandbox under (`SandboxService`
33
- * `withSandbox`): it only lists directories, never runs a command, so no conversation holds it.
36
+ * `withSandbox`) while the activation gate is off: it only lists directories, never runs a
37
+ * command, so no conversation holds it. Once the gate is on the owner browse route has no holder.
34
38
  */
35
39
  const PROJECTS_HOLDER = "device-projects";
36
- /** Only the owner's home bounds nothing: auto mode on a machine reads what its owner can. */
37
- const homeBased = (s) => s.source === "local" && s.mode === "auto";
38
- /** The base a relative path is resolved against in the scope's mode (project root §4.2). */
39
- const baseOf = (s, workspace = s.workspace) => homeBased(s) ? s.home : workspace;
40
- /**
41
- * `path` lies inside what the scope's mode may read (sandbox mode and cloud: the workspace, as the
42
- * held instance reports it when given).
43
- */
44
- export const withinMode = (s, path, workspace = s.workspace) => homeBased(s) || path === workspace || path.startsWith(workspace === "/" ? "/" : `${workspace}/`);
45
- /** `path` relative to `base` ("" for the base itself); `path` must lie under it. */
46
- const relativeTo = (base, path) => path === base ? "" : posix.relative(base, path);
47
- const nameInvalid = (name) => new ApiError("device.project_name_invalid", `"${clipped(name)}" is not a valid project name: use 1-64 characters, not . or .., without / or control characters, and without leading or trailing spaces`);
48
- const nameTaken = (name) => new ApiError("device.project_name_taken", `This device already has a project named "${clipped(name)}"; pick another name`);
49
- const projectNotFound = (name) => new ApiError("device.project_not_found", `This device has no project named "${clipped(name)}"`);
50
- const outsideMode = (path, mode) => new ApiError("device.project_outside_mode", mode === "sandbox"
51
- ? `${clipped(path)} is outside the device's workspace, the only directory it can read in sandbox mode`
52
- : `${clipped(path)} is outside the device's workspace, the only directory a cloud device can read`);
53
- const tooBroad = (path) => new ApiError("device.project_path_too_broad", `${clipped(path)} holds the owner's home directory (or other people's): pick the project's own directory, the home or below it`);
54
- const homeUnknown = () => new ApiError("device.project_home_unknown", "In auto mode a project's path is relative to the owner's home directory, which this device has not reported; update capybara-device on that machine and reconnect it");
55
- /** A device-supplied or person-supplied string inside a message, bounded. */
56
- function clipped(s, max = 200) {
57
- return s.length <= max ? s : `${s.slice(0, max)}…`;
40
+ /** The raw route's reader over a held provider (gate off): the protocol 2 calls, unchanged. */
41
+ function heldReader(scope, h, p, workspace) {
42
+ const list = p.list;
43
+ const scan = p.scan;
44
+ return {
45
+ workspace,
46
+ browse: false,
47
+ ...(list !== undefined && {
48
+ list: (path, limit, signal) => list.call(p, h, path, { limit, limits: { mode: readModeOf(scope) }, signal }),
49
+ }),
50
+ ...(scan !== undefined && {
51
+ scan: (base, signal) => scan.call(p, h, base, { limits: { mode: readModeOf(scope) }, signal }),
52
+ }),
53
+ stat: (path, signal) => p.stat(h, path, signal),
54
+ };
55
+ }
56
+ /** The owner browse route's reader (gate on): the browse scope's stat / list / scan only. */
57
+ function browseReader(b, workspace) {
58
+ return {
59
+ workspace,
60
+ browse: true,
61
+ list: (path, limit, signal) => b.list(path, { limit, signal }),
62
+ scan: (base, signal) => b.scan(base, { signal }),
63
+ stat: (path, signal) => b.stat(path, signal),
64
+ };
58
65
  }
59
66
  /**
60
67
  * A device's projects (project root design §4.1, §4.2, §6): kept in `device_projects`, keyed by the
@@ -69,15 +76,21 @@ function clipped(s, max = 200) {
69
76
  let DeviceProjectsService = class DeviceProjectsService {
70
77
  db;
71
78
  txHost;
72
- providers;
73
79
  sandbox;
74
80
  access;
75
- constructor(db, txHost, providers, sandbox, access) {
81
+ facts;
82
+ ceilings;
83
+ activation;
84
+ constructor(db, txHost, sandbox, access, facts, ceilings,
85
+ /** The paired activation gate: once on, every device read is an owner browse. */
86
+ activation) {
76
87
  this.db = db;
77
88
  this.txHost = txHost;
78
- this.providers = providers;
79
89
  this.sandbox = sandbox;
80
90
  this.access = access;
91
+ this.facts = facts;
92
+ this.ceilings = ceilings;
93
+ this.activation = activation;
81
94
  }
82
95
  /** The projects the device's current mode can read; see {@link DeviceProjectList}. */
83
96
  async list(orgId, accountId, deviceId) {
@@ -114,14 +127,15 @@ let DeviceProjectsService = class DeviceProjectsService {
114
127
  }
115
128
  if (baseOf(scope) === null)
116
129
  throw homeUnknown();
117
- return this.onDevice(orgId, accountId, deviceId, signal, async (h, p, workspace, sig) => {
130
+ return this.onDevice(orgId, accountId, deviceId, scope, signal, async (r, sig) => {
131
+ const workspace = r.workspace;
118
132
  const base = baseOf(scope, workspace);
119
- const scan = p.scan;
133
+ const scan = r.scan;
120
134
  if (scan === undefined)
121
135
  throw projectsUnsupported(false);
122
136
  let found;
123
137
  try {
124
- found = await scan.call(p, h, base, { limits: { mode: scope.mode }, signal: sig });
138
+ found = await scan(base, sig);
125
139
  }
126
140
  catch (e) {
127
141
  // the base is the device's own workspace or home: a refusal there is not the person's path
@@ -190,34 +204,41 @@ let DeviceProjectsService = class DeviceProjectsService {
190
204
  if (withinMode(scope, path) && aboveHome(path, scope.home))
191
205
  throw tooBroad(path);
192
206
  }
193
- const resolved = await this.onDevice(orgId, accountId, deviceId, signal, async (h, p, workspace, sig) => {
194
- const path = resolve(scope, workspace, input.path);
207
+ const resolved = await this.onDevice(orgId, accountId, deviceId, scope, signal, async (r, sig) => {
208
+ const path = resolve(scope, r.workspace, input.path);
195
209
  const name = input.name ?? posix.basename(path);
196
210
  if (!isDeviceProjectName(name))
197
211
  throw nameInvalid(name);
198
- const list = p.list;
212
+ const list = r.list;
199
213
  if (list === undefined)
200
214
  throw projectsUnsupported(false);
201
215
  let answer;
202
216
  try {
203
- answer = await list.call(p, h, path, {
204
- limit: 1,
205
- limits: { mode: scope.mode },
206
- signal: sig,
207
- });
217
+ answer = await list(path, 1, sig);
208
218
  }
209
219
  catch (e) {
210
- throw await listFailure(e, p, h, path, scope.mode, sig);
220
+ throw await listFailure(e, r, path, scope.mode, sig);
211
221
  }
212
222
  if (answer === null)
213
223
  throw pathMissing(path);
214
224
  return { path, name };
215
225
  });
216
- return this.insert(orgId, accountId, deviceId, resolved, actorTokenId, auditDetail);
226
+ return withOrderedLocks(() => this.lockSubject(orgId, accountId, deviceId), () => this.insert(orgId, accountId, deviceId, resolved, actorTokenId, auditDetail));
227
+ }
228
+ /**
229
+ * The owner's live device row, then its permission authority lock: the ordered prelude of the
230
+ * project writes (`withOrderedLocks`), so inside a run's fence (the Platform tool's
231
+ * `devices.add-project` / `devices.remove-project`) they follow the org row and precede the
232
+ * conversation rows. The writes name both again (already held: a re-check).
233
+ */
234
+ async lockSubject(orgId, accountId, deviceId) {
235
+ await this.lockOwn(orgId, accountId, deviceId);
236
+ await this.ceilings.lock({ orgId, deviceId }, "device");
217
237
  }
218
238
  /** The insert of {@link add}: the owner's live device locked, the count and the name checked. */
219
239
  async insert(orgId, accountId, deviceId, p, actorTokenId, auditDetail) {
220
240
  await this.lockOwn(orgId, accountId, deviceId);
241
+ await this.ceilings.lock({ orgId, deviceId }, "device");
221
242
  const count = await this.db
222
243
  .selectFrom("device_projects")
223
244
  .select(sql `count(*)::int`.as("n"))
@@ -233,6 +254,7 @@ let DeviceProjectsService = class DeviceProjectsService {
233
254
  .executeTakeFirst();
234
255
  if (row === undefined)
235
256
  throw nameTaken(p.name);
257
+ await this.ceilings.publishLocked({ orgId, deviceId }, "device", false);
236
258
  await audit(this.db.db, {
237
259
  actorAccountId: accountId,
238
260
  ...(actorTokenId !== undefined && { actorTokenId }),
@@ -245,7 +267,11 @@ let DeviceProjectsService = class DeviceProjectsService {
245
267
  }
246
268
  /** Removes a project of the owner's device; removing one that is not there succeeds. */
247
269
  async remove(orgId, accountId, deviceId, name, actorTokenId, auditDetail) {
270
+ await withOrderedLocks(() => this.lockSubject(orgId, accountId, deviceId), () => this.removeIn(orgId, accountId, deviceId, name, actorTokenId, auditDetail));
271
+ }
272
+ async removeIn(orgId, accountId, deviceId, name, actorTokenId, auditDetail) {
248
273
  await this.lockOwn(orgId, accountId, deviceId);
274
+ await this.ceilings.lock({ orgId, deviceId }, "device");
249
275
  const gone = await this.db
250
276
  .deleteFrom("device_projects")
251
277
  .where("device_id", "=", deviceId)
@@ -254,6 +280,26 @@ let DeviceProjectsService = class DeviceProjectsService {
254
280
  .executeTakeFirst();
255
281
  if (gone === undefined)
256
282
  return;
283
+ const roots = await this.db
284
+ .selectFrom("conversations")
285
+ .select("id")
286
+ .where("device_id", "=", deviceId)
287
+ .where("project_name", "=", name)
288
+ .where("project_path", "=", gone.path)
289
+ .execute();
290
+ const affected = new Set(roots.map((r) => r.id));
291
+ await this.ceilings.publishLocked({ orgId, deviceId }, "device", (_scope, row) => row.root_conversation_id !== null && affected.has(row.root_conversation_id));
292
+ if (affected.size)
293
+ await this.db
294
+ .updateTable("conversations")
295
+ .set((eb) => ({
296
+ permission_profile: "approve-for-me",
297
+ permission_consent: null,
298
+ permission_revision: eb("permission_revision", "+", 1),
299
+ }))
300
+ .where("id", "in", [...affected])
301
+ .where("permission_profile", "=", "full-access")
302
+ .execute();
257
303
  await audit(this.db.db, {
258
304
  actorAccountId: accountId,
259
305
  ...(actorTokenId !== undefined && { actorTokenId }),
@@ -271,24 +317,7 @@ let DeviceProjectsService = class DeviceProjectsService {
271
317
  * not asked: it enforces its mode on every access anyway.
272
318
  */
273
319
  async resolveForBinding(orgId, deviceId, accountId, name) {
274
- const scope = await this.scope(orgId, accountId, deviceId);
275
- if (!scope.supported)
276
- throw projectsUnsupported(scope.source === "local");
277
- const row = await this.db
278
- .selectFrom("device_projects")
279
- .select(["name", "path"])
280
- .where("device_id", "=", deviceId)
281
- .where("name", "=", name)
282
- .executeTakeFirst();
283
- if (row === undefined)
284
- throw projectNotFound(name);
285
- if (!withinMode(scope, row.path))
286
- throw outsideMode(row.path, scope.mode);
287
- // a home reported after the project was added can put it above the home: the working root
288
- // would fall back for it, so it is not bound (the add rule, project root §4.3)
289
- if (aboveHome(row.path, scope.home))
290
- throw tooBroad(row.path);
291
- return { name: row.name, path: row.path };
320
+ return this.facts.resolveProjectForBinding(orgId, deviceId, accountId, name);
292
321
  }
293
322
  /**
294
323
  * Whether the device still keeps the project `name` at `path` (project root §4.3): a binding is
@@ -296,14 +325,7 @@ let DeviceProjectsService = class DeviceProjectsService {
296
325
  * longer serves the conversations bound to it. Reads only.
297
326
  */
298
327
  async keeps(deviceId, name, path) {
299
- const row = await this.db
300
- .selectFrom("device_projects")
301
- .select("name")
302
- .where("device_id", "=", deviceId)
303
- .where("name", "=", name)
304
- .where("path", "=", path)
305
- .executeTakeFirst();
306
- return row !== undefined;
328
+ return this.facts.projectMatches(deviceId, name, path);
307
329
  }
308
330
  /**
309
331
  * The owner's live device's scope now ({@link scope}), for a run start's read of its bound
@@ -320,66 +342,31 @@ let DeviceProjectsService = class DeviceProjectsService {
320
342
  * offers projects. Anyone else's device (or a missing one) → `device.not_found`.
321
343
  */
322
344
  async scope(orgId, accountId, deviceId) {
323
- const row = await this.db
324
- .selectFrom("devices as e")
325
- .leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
326
- .leftJoin("device_instances as i", "i.device_id", "e.id")
327
- .select([
328
- "e.source",
329
- "e.provider",
330
- "m.features",
331
- "m.local_policy",
332
- "m.home",
333
- sql `m.roots->>'workspace'`.as("machine_workspace"),
334
- "i.handle",
335
- ])
336
- .where("e.id", "=", deviceId)
337
- .where("e.org_id", "=", orgId)
338
- .where("e.owner_kind", "=", "personal")
339
- .where("e.owner_account_id", "=", accountId)
340
- .where("e.deleted_at", "is", null)
341
- .executeTakeFirst();
342
- if (row === undefined)
343
- throw deviceNotFound();
344
- // `devicePolicy`, not `modeLevel` as the command review reads: a cloud device with a pending
345
- // files reset is scoped by the narrower mode it will run at, never the wider one its instance
346
- // still has, on purpose (projects are offered for what the device will read; no effect today)
347
- const { mode, allowedMode } = await this.sandbox.devicePolicy({ orgId, deviceId });
348
- if (row.source === "local") {
349
- return {
350
- source: "local",
351
- mode,
352
- widerThanAllowed: allowedMode === "sandbox" && localModeOf(row.features, row.local_policy) === "auto",
353
- workspace: row.machine_workspace ?? DEFAULT_SANDBOX_ROOTS.workspace,
354
- home: row.home,
355
- supported: deviceFeaturesOf(row.features).includes("projects"),
356
- };
357
- }
358
- const impl = providerForDevice(this.providers, row.provider)?.impl;
359
- const handle = row.handle;
360
- return {
361
- source: "cloud",
362
- mode,
363
- widerThanAllowed: false,
364
- workspace: handle === null ? DEFAULT_SANDBOX_ROOTS.workspace : rootsOf(handle).workspace,
365
- home: null,
366
- supported: typeof impl?.list === "function" && typeof impl.scan === "function",
367
- };
345
+ return this.facts.projectScope(orgId, accountId, deviceId);
368
346
  }
369
347
  /**
370
- * Runs `fn` on the device (`SandboxService.withSandbox`: its instance made or resumed as for a
371
- * tool call) with the workspace root its instance reports. Kernel refusals (offline, files lost,
372
- * busy, unavailable) stay as they are; anything else becomes a readable
348
+ * Runs `fn` on the device with a {@link ProjectReader}. While the activation gate is off:
349
+ * `SandboxService.withSandbox` (its instance made or resumed as for a tool call) with the
350
+ * workspace root its instance reports. Once it is on: the device started for its owner
351
+ * (`SandboxService.ensureRunningForOwner`), then the owner browse (`SandboxService.withBrowse`,
352
+ * as the device's owner, on the instance that runs) with the last known workspace; an instance
353
+ * that stopped in between is `device.not_running`. Kernel refusals (offline, files lost, busy,
354
+ * unavailable) stay as they are; anything else becomes a readable
373
355
  * `device.projects_unavailable`, never a 500.
374
356
  */
375
- async onDevice(orgId, accountId, deviceId, signal, fn) {
357
+ async onDevice(orgId, accountId, deviceId, scope, signal, fn) {
376
358
  try {
359
+ if (permissionContextActive(this.activation)) {
360
+ // a stopped device is started for its owner first, as the raw route's use did
361
+ await this.sandbox.ensureRunningForOwner({ orgId, deviceId, accountId }, signal);
362
+ return await this.sandbox.withBrowse({ orgId, deviceId, accountId }, (b, sig) => fn(browseReader(b, scope.workspace), sig), signal);
363
+ }
377
364
  return await this.sandbox.withSandbox({
378
365
  orgId,
379
366
  deviceId,
380
367
  holderConversationId: PROJECTS_HOLDER,
381
368
  actor: { accountId, conversationId: PROJECTS_HOLDER },
382
- }, (h, p, info, sig) => fn(h, p, info.roots.workspace, sig), signal);
369
+ }, (h, p, info, sig) => fn(heldReader(scope, h, p, info.roots.workspace), sig), signal);
383
370
  }
384
371
  catch (e) {
385
372
  if (e instanceof ApiError)
@@ -405,19 +392,25 @@ let DeviceProjectsService = class DeviceProjectsService {
405
392
  throw deviceNotFound();
406
393
  }
407
394
  };
395
+ __decorate([
396
+ Transactional({ propagation: "mandatory" })
397
+ ], DeviceProjectsService.prototype, "lockSubject", null);
408
398
  __decorate([
409
399
  Transactional()
410
400
  ], DeviceProjectsService.prototype, "insert", null);
411
401
  __decorate([
412
402
  Transactional()
413
- ], DeviceProjectsService.prototype, "remove", null);
403
+ ], DeviceProjectsService.prototype, "removeIn", null);
414
404
  DeviceProjectsService = __decorate([
415
405
  Injectable(),
416
406
  __param(0, Inject(KernelDb)),
417
407
  __param(1, Inject(TransactionHost)),
418
- __param(2, Inject(SandboxProviders)),
419
- __param(3, Inject(SandboxService)),
420
- __param(4, Inject(DeviceAccess))
408
+ __param(2, Inject(SandboxService)),
409
+ __param(3, Inject(DeviceAccess)),
410
+ __param(4, Inject(PermissionFacts)),
411
+ __param(5, Inject(PermissionCeilingWrites)),
412
+ __param(6, Optional()),
413
+ __param(6, Inject(PERMISSION_CONTEXT_ACTIVATION))
421
414
  ], DeviceProjectsService);
422
415
  export { DeviceProjectsService };
423
416
  /**
@@ -480,17 +473,19 @@ const pathMissing = (path) => new ApiError("device.project_path_missing", `${cli
480
473
  * missing path `device.project_path_missing`, and a `stat` that fails too means the device could
481
474
  * not be asked (503 `device.projects_unavailable`).
482
475
  */
483
- async function listFailure(e, p, h, path, mode, signal) {
476
+ async function listFailure(e, r, path, mode, signal) {
484
477
  const passed = passThrough(e);
485
478
  if (passed !== undefined)
486
479
  return passed;
487
480
  const why = e instanceof ToolError ? ` (${clipped(e.message)})` : "";
488
- if (e instanceof ToolError && e.message.startsWith(POLICY_REFUSAL_PREFIX)) {
481
+ // the owner browse scope refusing the path is the device refusing it (gate on only)
482
+ if ((e instanceof ToolError && e.message.startsWith(POLICY_REFUSAL_PREFIX)) ||
483
+ (r.browse && isSandboxScopeDeniedError(e))) {
489
484
  return new ApiError("device.project_outside_mode", `The device refused ${clipped(path)} in ${mode} mode${why}`);
490
485
  }
491
486
  let st;
492
487
  try {
493
- st = await p.stat(h, path, signal);
488
+ st = await r.stat(path, signal);
494
489
  }
495
490
  catch (e2) {
496
491
  return passThrough(e2) ?? unavailable(e);
@@ -501,3 +496,4 @@ async function listFailure(e, p, h, path, mode, signal) {
501
496
  ? `${clipped(path)} is a directory the device cannot read${why}`
502
497
  : `${clipped(path)} is a file, not a directory`);
503
498
  }
499
+ const relativeTo = (base, path) => path === base ? "" : posix.relative(base, path);
@@ -72,13 +72,15 @@ let DevicesController = class DevicesController {
72
72
  const tokenId = patTokenId(p);
73
73
  // a person changes their device's mode in a web session, narrowing or widening (auto mode
74
74
  // spec §4.3, hardening D2): never an API token
75
- if (body.mode !== undefined && tokenId !== undefined) {
75
+ if ((body.mode !== undefined || body.ownerCeiling !== undefined) && tokenId !== undefined) {
76
76
  throw new ApiError("device.mode_requires_session", "A device's mode is changed by its owner on the device page, not with an API token");
77
77
  }
78
78
  return {
79
79
  device: await this.devices.update(org.orgId, p.account.id, params.id, {
80
80
  ...(body.name !== undefined && { name: body.name }),
81
81
  ...(body.mode !== undefined && { mode: body.mode }),
82
+ ...(body.ownerCeiling !== undefined && { ownerCeiling: body.ownerCeiling }),
83
+ ...(body.confirmWidening === true && { confirmWidening: true }),
82
84
  }, tokenId),
83
85
  };
84
86
  }
@@ -7,9 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { Module } from "@nestjs/common";
8
8
  import { ExtensionsModule } from "../extensions/extensions.module.js";
9
9
  import { LocalDevicesModule } from "../local-devices/local-devices.module.js";
10
+ import { PermissionFactsModule } from "../sandbox/permission-facts.module.js";
10
11
  import { SandboxModule } from "../sandbox/sandbox.module.js";
11
12
  import { SandboxFileReader } from "../sandbox/sandbox-file-reader.js";
12
13
  import { DeviceAccess } from "./access.js";
14
+ import { DeviceAccessModule } from "./access.module.js";
13
15
  import { ConversationDevices } from "./conversation-devices.js";
14
16
  import { DeviceProjectsService } from "./device-projects.service.js";
15
17
  import { DevicesService } from "./devices.service.js";
@@ -25,18 +27,18 @@ DevicesModule = __decorate([
25
27
  Module({
26
28
  // ExtensionsModule: the provider display names of demoted defaults; LocalDevicesModule: deleting
27
29
  // a local device revokes its machine
28
- imports: [SandboxModule, ExtensionsModule, LocalDevicesModule],
30
+ imports: [
31
+ SandboxModule,
32
+ ExtensionsModule,
33
+ LocalDevicesModule,
34
+ DeviceAccessModule,
35
+ PermissionFactsModule,
36
+ ],
29
37
  // SandboxFileReader lives here, not in SandboxModule: it needs ConversationDevices, and this
30
38
  // module already imports SandboxModule (the other way would be a module cycle)
31
- providers: [
32
- DeviceAccess,
33
- DevicesService,
34
- ConversationDevices,
35
- SandboxFileReader,
36
- DeviceProjectsService,
37
- ],
39
+ providers: [DevicesService, ConversationDevices, SandboxFileReader, DeviceProjectsService],
38
40
  exports: [
39
- DeviceAccess,
41
+ DeviceAccessModule,
40
42
  DevicesService,
41
43
  ConversationDevices,
42
44
  SandboxFileReader,