@capybara-hq/kernel 0.1.0-rc.68 → 0.1.0-rc.69

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 (215) hide show
  1. package/dist/admin/admin.module.js +2 -0
  2. package/dist/admin/health.service.d.ts +11 -4
  3. package/dist/admin/health.service.js +33 -17
  4. package/dist/background/poll.job.js +2 -2
  5. package/dist/background/tasks.service.d.ts +5 -5
  6. package/dist/background/tasks.service.js +9 -8
  7. package/dist/catalog/marketplaces.service.d.ts +1 -1
  8. package/dist/catalog/requests.service.js +1 -1
  9. package/dist/config/schema.d.ts +1 -1
  10. package/dist/config/schema.js +9 -9
  11. package/dist/conversations/conversations.controller.d.ts +8 -3
  12. package/dist/conversations/conversations.controller.js +8 -3
  13. package/dist/conversations/conversations.service.d.ts +33 -15
  14. package/dist/conversations/conversations.service.js +60 -10
  15. package/dist/conversations/events.d.ts +21 -41
  16. package/dist/conversations/events.js +57 -31
  17. package/dist/conversations/permission-profiles.controller.d.ts +6 -4
  18. package/dist/conversations/permission-profiles.service.d.ts +6 -4
  19. package/dist/ctx/create-ctx.d.ts +20 -1
  20. package/dist/ctx/create-ctx.js +77 -6
  21. package/dist/ctx/device-provider-check.d.ts +6 -2
  22. package/dist/ctx/device-provider-check.js +17 -2
  23. package/dist/db/kernel-schema.d.ts +10 -48
  24. package/dist/devices/access.d.ts +3 -4
  25. package/dist/devices/access.js +3 -4
  26. package/dist/devices/conversation-devices.d.ts +1 -3
  27. package/dist/devices/conversation-devices.js +2 -7
  28. package/dist/devices/device-projects.service.js +24 -29
  29. package/dist/devices/device-provider-selection.d.ts +5 -6
  30. package/dist/devices/device-provider-selection.js +8 -9
  31. package/dist/devices/devices.controller.d.ts +8 -21
  32. package/dist/devices/devices.controller.js +9 -34
  33. package/dist/devices/devices.module.js +6 -4
  34. package/dist/devices/devices.schemas.d.ts +1 -5
  35. package/dist/devices/devices.schemas.js +1 -5
  36. package/dist/devices/devices.service.d.ts +84 -147
  37. package/dist/devices/devices.service.js +134 -229
  38. package/dist/devices/dto.d.ts +5 -32
  39. package/dist/devices/dto.js +5 -37
  40. package/dist/devices/errors.d.ts +6 -5
  41. package/dist/devices/errors.js +7 -8
  42. package/dist/devices/project-rules.d.ts +9 -11
  43. package/dist/devices/project-rules.js +7 -7
  44. package/dist/devices/working-root.d.ts +3 -6
  45. package/dist/devices/working-root.js +3 -8
  46. package/dist/dial-in/access.d.ts +23 -0
  47. package/dist/dial-in/access.js +64 -0
  48. package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
  49. package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
  50. package/dist/dial-in/auth.module.d.ts +7 -0
  51. package/dist/dial-in/auth.module.js +27 -0
  52. package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
  53. package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
  54. package/dist/dial-in/dial-in.module.d.ts +9 -0
  55. package/dist/dial-in/dial-in.module.js +37 -0
  56. package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
  57. package/dist/{local-devices → dial-in}/dto.js +14 -2
  58. package/dist/dial-in/envelope.d.ts +95 -0
  59. package/dist/dial-in/envelope.js +89 -0
  60. package/dist/dial-in/gateway.d.ts +214 -0
  61. package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
  62. package/dist/dial-in/handlers.d.ts +47 -0
  63. package/dist/dial-in/handlers.js +84 -0
  64. package/dist/dial-in/machines.d.ts +155 -0
  65. package/dist/dial-in/machines.js +383 -0
  66. package/dist/dial-in/relay.d.ts +135 -0
  67. package/dist/dial-in/relay.js +444 -0
  68. package/dist/dial-in/relay.module.d.ts +7 -0
  69. package/dist/dial-in/relay.module.js +24 -0
  70. package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
  71. package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
  72. package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
  73. package/dist/{local-devices → dial-in}/targets.js +3 -48
  74. package/dist/errors.d.ts +8 -27
  75. package/dist/errors.js +8 -27
  76. package/dist/extensions/bootstrap.d.ts +5 -0
  77. package/dist/extensions/bootstrap.js +10 -1
  78. package/dist/extensions/extensions.module.js +6 -0
  79. package/dist/extensions/host.d.ts +6 -0
  80. package/dist/extensions/host.js +12 -2
  81. package/dist/extensions/permission-set.d.ts +15 -1
  82. package/dist/extensions/permission-set.js +11 -1
  83. package/dist/extensions/permission-view.d.ts +1 -1
  84. package/dist/extensions/permission-view.js +4 -1
  85. package/dist/http/api.module.js +4 -4
  86. package/dist/http/gateway-routes.d.ts +1 -1
  87. package/dist/http/gateway-routes.js +1 -1
  88. package/dist/http/meta.controller.js +1 -1
  89. package/dist/identity/settings.d.ts +1 -1
  90. package/dist/identity/settings.js +6 -8
  91. package/dist/infra/config/kernel-config.service.js +2 -2
  92. package/dist/infra/outbox/registry.d.ts +0 -14
  93. package/dist/infra/outbox/registry.js +0 -15
  94. package/dist/infra/throttler/named-throttlers.d.ts +1 -1
  95. package/dist/infra/throttler/named-throttlers.js +1 -1
  96. package/dist/kernel.module.js +0 -3
  97. package/dist/orgs/settings.service.js +5 -10
  98. package/dist/overrides.d.ts +0 -4
  99. package/dist/overrides.js +0 -2
  100. package/dist/platform/exclusions.js +5 -5
  101. package/dist/platform/ops/admin.ops.js +1 -1
  102. package/dist/platform/ops/conversations.ops.js +5 -2
  103. package/dist/platform/ops/devices.ops.js +11 -24
  104. package/dist/platform/ops/inbox.ops.js +1 -1
  105. package/dist/roles/gateway-role.d.ts +3 -3
  106. package/dist/roles/gateway-role.js +4 -4
  107. package/dist/roles/gateway.module.d.ts +1 -1
  108. package/dist/roles/gateway.module.js +5 -5
  109. package/dist/runtime/context/device-paths.d.ts +4 -1
  110. package/dist/runtime/context/permission-profile.js +5 -5
  111. package/dist/runtime/maintenance.d.ts +2 -5
  112. package/dist/runtime/maintenance.js +9 -19
  113. package/dist/runtime/project/knowledge.js +4 -5
  114. package/dist/runtime/project/knowledge.service.js +2 -1
  115. package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
  116. package/dist/sandbox/cloud-permission-snapshot.js +1 -3
  117. package/dist/sandbox/device-reports.d.ts +74 -14
  118. package/dist/sandbox/device-reports.js +190 -33
  119. package/dist/sandbox/device-reports.module.d.ts +7 -0
  120. package/dist/sandbox/device-reports.module.js +25 -0
  121. package/dist/sandbox/device-sandbox.d.ts +39 -41
  122. package/dist/sandbox/device-sandbox.js +44 -83
  123. package/dist/sandbox/kernel-read.d.ts +2 -2
  124. package/dist/sandbox/legacy-retirement.d.ts +11 -59
  125. package/dist/sandbox/legacy-retirement.js +34 -186
  126. package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
  127. package/dist/sandbox/legacy-retirement.module.js +2 -2
  128. package/dist/sandbox/managed-device-context.d.ts +16 -4
  129. package/dist/sandbox/managed-device-context.js +25 -8
  130. package/dist/sandbox/managed-device-context.module.js +4 -0
  131. package/dist/sandbox/modes.d.ts +3 -12
  132. package/dist/sandbox/modes.js +2 -14
  133. package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
  134. package/dist/{local-devices → sandbox}/network-grants.js +4 -49
  135. package/dist/sandbox/operation-authority-types.d.ts +2 -1
  136. package/dist/sandbox/operation-authority.d.ts +6 -20
  137. package/dist/sandbox/operation-authority.js +43 -104
  138. package/dist/sandbox/operation-authority.module.js +1 -1
  139. package/dist/sandbox/operation-intents.d.ts +4 -1
  140. package/dist/sandbox/operation-intents.js +11 -2
  141. package/dist/sandbox/operation-reconcile.job.js +2 -4
  142. package/dist/sandbox/permission-availability.d.ts +6 -7
  143. package/dist/sandbox/permission-availability.js +7 -10
  144. package/dist/sandbox/permission-call-grants.d.ts +2 -1
  145. package/dist/sandbox/permission-call-grants.js +1 -7
  146. package/dist/sandbox/permission-call-types.d.ts +4 -4
  147. package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
  148. package/dist/sandbox/permission-ceiling-writes.js +8 -35
  149. package/dist/sandbox/permission-config-publication.d.ts +9 -1
  150. package/dist/sandbox/permission-config-publication.js +29 -21
  151. package/dist/sandbox/permission-context-types.d.ts +17 -10
  152. package/dist/sandbox/permission-facts.d.ts +98 -95
  153. package/dist/sandbox/permission-facts.js +160 -314
  154. package/dist/sandbox/permission-instance-writes.d.ts +23 -37
  155. package/dist/sandbox/permission-instance-writes.js +44 -121
  156. package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
  157. package/dist/sandbox/permission-runtime-reports.js +105 -122
  158. package/dist/sandbox/providers.d.ts +26 -38
  159. package/dist/sandbox/providers.js +36 -18
  160. package/dist/sandbox/request-not-sent.d.ts +2 -13
  161. package/dist/sandbox/request-not-sent.js +2 -13
  162. package/dist/sandbox/review/permission-candidate.d.ts +13 -8
  163. package/dist/sandbox/review/permission-candidate.js +38 -48
  164. package/dist/sandbox/sandbox.module.js +7 -3
  165. package/dist/sandbox/sandbox.service.d.ts +49 -59
  166. package/dist/sandbox/sandbox.service.js +139 -259
  167. package/dist/schedules/fire.d.ts +15 -6
  168. package/dist/schedules/fire.js +27 -13
  169. package/dist/schedules/grant-rules.js +1 -1
  170. package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
  171. package/dist/schedules/scheduled-tasks.service.js +1 -4
  172. package/dist/schedules/schedules.module.js +5 -3
  173. package/dist/skills/invoke.d.ts +1 -1
  174. package/dist/skills/invoke.js +2 -3
  175. package/dist/tools/approvals.service.d.ts +8 -5
  176. package/dist/tools/approvals.service.js +5 -5
  177. package/dist/tools/builtins/sandbox/bash.js +1 -2
  178. package/dist/tools/builtins/sandbox/common.d.ts +15 -9
  179. package/dist/tools/builtins/sandbox/common.js +37 -38
  180. package/dist/tools/network-asks.d.ts +19 -22
  181. package/dist/tools/network-asks.js +15 -21
  182. package/dist/tools/pipeline.d.ts +6 -7
  183. package/dist/tools/pipeline.js +17 -21
  184. package/dist/tools/tools.module.js +3 -7
  185. package/package.json +3 -4
  186. package/src/migrations/0177_dial_in_contract.sql +32 -0
  187. package/dist/local-devices/device-auth.module.d.ts +0 -7
  188. package/dist/local-devices/device-auth.module.js +0 -25
  189. package/dist/local-devices/device-policy.service.d.ts +0 -213
  190. package/dist/local-devices/device-policy.service.js +0 -605
  191. package/dist/local-devices/instance-bindings.d.ts +0 -82
  192. package/dist/local-devices/instance-bindings.js +0 -307
  193. package/dist/local-devices/local-device-gateway.d.ts +0 -153
  194. package/dist/local-devices/local-device-provider.d.ts +0 -122
  195. package/dist/local-devices/local-device-provider.js +0 -326
  196. package/dist/local-devices/local-devices.module.d.ts +0 -31
  197. package/dist/local-devices/local-devices.module.js +0 -100
  198. package/dist/local-devices/machines.d.ts +0 -211
  199. package/dist/local-devices/machines.js +0 -766
  200. package/dist/local-devices/owner-report.d.ts +0 -81
  201. package/dist/local-devices/owner-report.js +0 -150
  202. package/dist/local-devices/owner-reports.d.ts +0 -48
  203. package/dist/local-devices/owner-reports.js +0 -208
  204. package/dist/local-devices/policy-op-jobs.d.ts +0 -15
  205. package/dist/local-devices/policy-op-jobs.js +0 -12
  206. package/dist/local-devices/policy-summary.d.ts +0 -102
  207. package/dist/local-devices/policy-summary.js +0 -155
  208. package/dist/local-devices/relay.d.ts +0 -166
  209. package/dist/local-devices/relay.js +0 -559
  210. package/dist/tools/device-op-resolver.d.ts +0 -34
  211. package/dist/tools/device-op-resolver.js +0 -120
  212. /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
  213. /package/dist/{local-devices → dial-in}/keys.js +0 -0
  214. /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
  215. /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
@@ -18,10 +18,6 @@ export declare const PermissionContextSandboxSchema: z.ZodObject<{
18
18
  instance: "instance";
19
19
  operation: "operation";
20
20
  }>;
21
- location: z.ZodEnum<{
22
- cloud: "cloud";
23
- local: "local";
24
- }>;
25
21
  workingRoot: z.ZodString;
26
22
  network: z.ZodObject<{
27
23
  kind: z.ZodEnum<{
@@ -81,16 +77,15 @@ export declare const PermissionContextV2Schema: z.ZodObject<{
81
77
  reason: z.ZodString;
82
78
  }, z.core.$strict>], "state">;
83
79
  scope: z.ZodNullable<z.ZodObject<{
84
- location: z.ZodEnum<{
85
- cloud: "cloud";
86
- local: "local";
80
+ boundary: z.ZodEnum<{
81
+ instance: "instance";
82
+ operation: "operation";
87
83
  }>;
88
84
  workingRoot: z.ZodString;
89
85
  filesystem: z.ZodDiscriminatedUnion<[z.ZodObject<{
90
86
  kind: z.ZodLiteral<"device">;
91
87
  }, z.core.$strict>, z.ZodObject<{
92
88
  kind: z.ZodLiteral<"scoped">;
93
- readDirectories: z.ZodArray<z.ZodString>;
94
89
  writeDirectories: z.ZodArray<z.ZodString>;
95
90
  }, z.core.$strict>], "kind">;
96
91
  network: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -119,10 +114,6 @@ export declare const PermissionContextV2Schema: z.ZodObject<{
119
114
  instance: "instance";
120
115
  operation: "operation";
121
116
  }>;
122
- location: z.ZodEnum<{
123
- cloud: "cloud";
124
- local: "local";
125
- }>;
126
117
  workingRoot: z.ZodString;
127
118
  network: z.ZodObject<{
128
119
  kind: z.ZodEnum<{
@@ -150,7 +141,10 @@ export type PermissionContextV2 = z.infer<typeof PermissionContextV2Schema>;
150
141
  /**
151
142
  * Reads a recorded payload as version 2. Stored v1 rows exist on deployments and the log is never
152
143
  * rewritten: a v1 payload (`version: 1`, never a `sandbox` key) reads as v2 with `sandbox: null`,
153
- * which v2 accepts under exactly v1's rules. Anything else is left for the v2 schema to judge.
144
+ * which v2 accepts under exactly v1's rules. A payload recorded before device providers reported
145
+ * their boundary (a `location` of `local` / `cloud`, read roots in a scoped filesystem) reads with
146
+ * the boundary that location had (`operation` / `instance`) and without its read roots. Anything
147
+ * else is left for the v2 schema to judge.
154
148
  */
155
149
  export declare function upconvertPermissionContext(payload: unknown): unknown;
156
150
  /** A recorded `permission_context` payload as every reader parses it (v1 up-converted). */
@@ -185,16 +179,15 @@ export declare const RecordedPermissionContextSchema: z.ZodPreprocess<z.ZodObjec
185
179
  reason: z.ZodString;
186
180
  }, z.core.$strict>], "state">;
187
181
  scope: z.ZodNullable<z.ZodObject<{
188
- location: z.ZodEnum<{
189
- cloud: "cloud";
190
- local: "local";
182
+ boundary: z.ZodEnum<{
183
+ instance: "instance";
184
+ operation: "operation";
191
185
  }>;
192
186
  workingRoot: z.ZodString;
193
187
  filesystem: z.ZodDiscriminatedUnion<[z.ZodObject<{
194
188
  kind: z.ZodLiteral<"device">;
195
189
  }, z.core.$strict>, z.ZodObject<{
196
190
  kind: z.ZodLiteral<"scoped">;
197
- readDirectories: z.ZodArray<z.ZodString>;
198
191
  writeDirectories: z.ZodArray<z.ZodString>;
199
192
  }, z.core.$strict>], "kind">;
200
193
  network: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -223,10 +216,6 @@ export declare const RecordedPermissionContextSchema: z.ZodPreprocess<z.ZodObjec
223
216
  instance: "instance";
224
217
  operation: "operation";
225
218
  }>;
226
- location: z.ZodEnum<{
227
- cloud: "cloud";
228
- local: "local";
229
- }>;
230
219
  workingRoot: z.ZodString;
231
220
  network: z.ZodObject<{
232
221
  kind: z.ZodEnum<{
@@ -297,11 +286,10 @@ export declare const COMMAND_ASK_MAX_CHARS: number;
297
286
  * `commandHash` is the SHA-256 of the command text the approval holds in full, so an audit can
298
287
  * match a record to what ran.
299
288
  */
300
- export declare const PermissionExpansionSchema: z.ZodObject<{
301
- readDirectories: z.ZodArray<z.ZodString>;
289
+ export declare const PermissionExpansionSchema: z.ZodPreprocess<z.ZodObject<{
302
290
  writeDirectories: z.ZodArray<z.ZodString>;
303
291
  hosts: z.ZodArray<z.ZodString>;
304
- }, z.core.$strict>;
292
+ }, z.core.$strict>, unknown>;
305
293
  export declare const PermissionCallBindingSchema: z.ZodObject<{
306
294
  orgId: z.ZodString;
307
295
  rootConversationId: z.ZodString;
@@ -374,11 +362,10 @@ export declare const ReviewRecordSchema: z.ZodObject<{
374
362
  }, z.core.$strict>;
375
363
  /** The display-only `approval_requested.command` facts of a `command` ask (auto mode spec §5.4). */
376
364
  export declare const CommandAskSchema: z.ZodObject<{
377
- permissionScope: z.ZodOptional<z.ZodObject<{
378
- readDirectories: z.ZodArray<z.ZodString>;
365
+ permissionScope: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
379
366
  writeDirectories: z.ZodArray<z.ZodString>;
380
367
  hosts: z.ZodArray<z.ZodString>;
381
- }, z.core.$strict>>;
368
+ }, z.core.$strict>, unknown>>;
382
369
  targetPath: z.ZodOptional<z.ZodString>;
383
370
  candidateHash: z.ZodOptional<z.ZodString>;
384
371
  escalation: z.ZodOptional<z.ZodObject<{
@@ -706,16 +693,15 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
706
693
  reason: z.ZodString;
707
694
  }, z.core.$strict>], "state">;
708
695
  scope: z.ZodNullable<z.ZodObject<{
709
- location: z.ZodEnum<{
710
- cloud: "cloud";
711
- local: "local";
696
+ boundary: z.ZodEnum<{
697
+ instance: "instance";
698
+ operation: "operation";
712
699
  }>;
713
700
  workingRoot: z.ZodString;
714
701
  filesystem: z.ZodDiscriminatedUnion<[z.ZodObject<{
715
702
  kind: z.ZodLiteral<"device">;
716
703
  }, z.core.$strict>, z.ZodObject<{
717
704
  kind: z.ZodLiteral<"scoped">;
718
- readDirectories: z.ZodArray<z.ZodString>;
719
705
  writeDirectories: z.ZodArray<z.ZodString>;
720
706
  }, z.core.$strict>], "kind">;
721
707
  network: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -744,10 +730,6 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
744
730
  instance: "instance";
745
731
  operation: "operation";
746
732
  }>;
747
- location: z.ZodEnum<{
748
- cloud: "cloud";
749
- local: "local";
750
- }>;
751
733
  workingRoot: z.ZodString;
752
734
  network: z.ZodObject<{
753
735
  kind: z.ZodEnum<{
@@ -815,11 +797,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
815
797
  scopeRevision: z.ZodString;
816
798
  authorityRevision: z.ZodString;
817
799
  }, z.core.$strict>;
818
- permissionScope: z.ZodObject<{
819
- readDirectories: z.ZodArray<z.ZodString>;
800
+ permissionScope: z.ZodPreprocess<z.ZodObject<{
820
801
  writeDirectories: z.ZodArray<z.ZodString>;
821
802
  hosts: z.ZodArray<z.ZodString>;
822
- }, z.core.$strict>;
803
+ }, z.core.$strict>, unknown>;
823
804
  targetPath: z.ZodOptional<z.ZodString>;
824
805
  scopeKind: z.ZodEnum<{
825
806
  "directories-and-hosts": "directories-and-hosts";
@@ -1548,11 +1529,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1548
1529
  refs: z.ZodArray<z.ZodString>;
1549
1530
  }, z.core.$strip>>;
1550
1531
  command: z.ZodOptional<z.ZodObject<{
1551
- permissionScope: z.ZodOptional<z.ZodObject<{
1552
- readDirectories: z.ZodArray<z.ZodString>;
1532
+ permissionScope: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
1553
1533
  writeDirectories: z.ZodArray<z.ZodString>;
1554
1534
  hosts: z.ZodArray<z.ZodString>;
1555
- }, z.core.$strict>>;
1535
+ }, z.core.$strict>, unknown>>;
1556
1536
  targetPath: z.ZodOptional<z.ZodString>;
1557
1537
  candidateHash: z.ZodOptional<z.ZodString>;
1558
1538
  escalation: z.ZodOptional<z.ZodObject<{
@@ -55,16 +55,21 @@ const PermissionReason = z
55
55
  .max(1000)
56
56
  .refine((value) => value.trim().length > 0);
57
57
  const PermissionId = z.string().uuid();
58
+ /**
59
+ * The scope a recorded context reports. `boundary` is the device provider's (device-provider spec
60
+ * §6.7): `operation` runs every operation in its own restricted scope in the host environment,
61
+ * `instance` is a provisioned instance that is itself the sandbox. A scoped filesystem names its
62
+ * write roots only: what a sandboxed operation may read is the provider's rule.
63
+ */
58
64
  const PermissionScopeSchema = z
59
65
  .object({
60
- location: z.enum(["local", "cloud"]),
66
+ boundary: z.enum(["operation", "instance"]),
61
67
  workingRoot: PermissionPath,
62
68
  filesystem: z.discriminatedUnion("kind", [
63
69
  z.object({ kind: z.literal("device") }).strict(),
64
70
  z
65
71
  .object({
66
72
  kind: z.literal("scoped"),
67
- readDirectories: PermissionDirectories,
68
73
  writeDirectories: PermissionDirectories,
69
74
  })
70
75
  .strict(),
@@ -90,7 +95,6 @@ const PermissionScopeSchema = z
90
95
  export const PermissionContextSandboxSchema = z
91
96
  .object({
92
97
  boundary: z.enum(["operation", "instance"]),
93
- location: z.enum(["local", "cloud"]),
94
98
  workingRoot: z.string().min(1).max(4096),
95
99
  network: z
96
100
  .object({
@@ -205,35 +209,31 @@ export const PermissionContextV2Schema = z
205
209
  reject("A sandboxed context requires scoped filesystem and restricted networking");
206
210
  if (p.sandbox !== null) {
207
211
  const box = p.sandbox;
208
- if (box.location !== s.location || box.workingRoot !== s.workingRoot)
209
- reject("The sandbox must match the scope's location and working root");
212
+ if (box.boundary !== s.boundary || box.workingRoot !== s.workingRoot)
213
+ reject("The sandbox must match the scope's boundary and working root");
210
214
  if (canonicalOuter(box.outerNetwork) !== canonicalOuter(s.outerNetwork))
211
215
  reject("The sandbox must match the scope's outer network");
212
216
  // one canonical form: a scope without hosts is `none` in the block too
213
217
  const hosts = s.network.kind === "allowlist" ? s.network.hosts.length : 0;
214
218
  if (box.network.kind !== s.network.kind || box.network.hostsCount !== hosts)
215
219
  reject("The sandbox network must match the scope's network");
216
- if (box.boundary === "instance" && box.location !== "cloud")
217
- reject("An instance boundary is a cloud device's");
218
- // a cloud device has no outside: the provider's instance is the outermost boundary
219
- if (box.location === "cloud" && box.outsideSandbox)
220
- reject("A cloud device cannot run outside its sandbox");
220
+ // an instance boundary has no outside: the provider's instance is the outermost boundary
221
+ if (box.boundary === "instance" && box.outsideSandbox)
222
+ reject("An instance boundary cannot run outside its sandbox");
221
223
  }
222
224
  if (s.filesystem.kind === "scoped") {
223
- const { readDirectories, writeDirectories } = s.filesystem;
224
- if (!readDirectories.includes(s.workingRoot) ||
225
- !writeDirectories.includes(s.workingRoot) ||
226
- writeDirectories.some((p) => !readDirectories.includes(p)))
227
- reject("Writable roots must be readable and both must include the working root");
228
- if (new Set([...readDirectories, ...writeDirectories]).size > 64)
229
- reject("At most 64 combined roots are allowed");
225
+ const { writeDirectories } = s.filesystem;
226
+ if (!writeDirectories.includes(s.workingRoot))
227
+ reject("Writable roots must include the working root");
228
+ if (new Set(writeDirectories).size > 64)
229
+ reject("At most 64 roots are allowed");
230
230
  }
231
- if ((s.location === "local") !== (s.outerNetwork.kind === "host-environment"))
232
- reject("Outer boundary must match the device location");
231
+ if ((s.boundary === "operation") !== (s.outerNetwork.kind === "host-environment"))
232
+ reject("Outer boundary must match the provider's boundary");
233
233
  if (s.network.kind === "open-public" &&
234
234
  (s.outerNetwork.kind === "none" || s.outerNetwork.kind === "allowlist"))
235
235
  reject("An open network exceeds a disabled or allowlisted outer boundary");
236
- if (s.location === "cloud" && s.network.kind === "allowlist") {
236
+ if (s.boundary === "instance" && s.network.kind === "allowlist") {
237
237
  if (s.outerNetwork.kind === "none")
238
238
  reject("Network hosts exceed the disabled outer boundary");
239
239
  if (s.outerNetwork.kind === "allowlist") {
@@ -246,16 +246,35 @@ export const PermissionContextV2Schema = z
246
246
  /**
247
247
  * Reads a recorded payload as version 2. Stored v1 rows exist on deployments and the log is never
248
248
  * rewritten: a v1 payload (`version: 1`, never a `sandbox` key) reads as v2 with `sandbox: null`,
249
- * which v2 accepts under exactly v1's rules. Anything else is left for the v2 schema to judge.
249
+ * which v2 accepts under exactly v1's rules. A payload recorded before device providers reported
250
+ * their boundary (a `location` of `local` / `cloud`, read roots in a scoped filesystem) reads with
251
+ * the boundary that location had (`operation` / `instance`) and without its read roots. Anything
252
+ * else is left for the v2 schema to judge.
250
253
  */
251
254
  export function upconvertPermissionContext(payload) {
252
- if (typeof payload === "object" &&
253
- payload !== null &&
254
- !Array.isArray(payload) &&
255
- payload.version === 1 &&
256
- !Object.hasOwn(payload, "sandbox"))
257
- return { ...payload, version: 2, sandbox: null };
258
- return payload;
255
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload))
256
+ return payload;
257
+ let p = payload;
258
+ if (p.version === 1 && !Object.hasOwn(p, "sandbox"))
259
+ p = { ...p, version: 2, sandbox: null };
260
+ const boundaryOf = (location) => location === "local" ? "operation" : location === "cloud" ? "instance" : location;
261
+ const scope = p.scope;
262
+ if (scope && typeof scope === "object" && Object.hasOwn(scope, "location")) {
263
+ const { location, ...rest } = scope;
264
+ const fs = rest.filesystem;
265
+ let filesystem = fs;
266
+ if (fs && typeof fs === "object" && Object.hasOwn(fs, "readDirectories")) {
267
+ const { readDirectories: _reads, ...kept } = fs;
268
+ filesystem = kept;
269
+ }
270
+ p = { ...p, scope: { boundary: boundaryOf(location), ...rest, filesystem } };
271
+ }
272
+ const box = p.sandbox;
273
+ if (box && typeof box === "object" && Object.hasOwn(box, "location")) {
274
+ const { location: _location, ...kept } = box;
275
+ p = { ...p, sandbox: kept };
276
+ }
277
+ return p;
259
278
  }
260
279
  /** A recorded `permission_context` payload as every reader parses it (v1 up-converted). */
261
280
  export const RecordedPermissionContextSchema = z.preprocess(upconvertPermissionContext, PermissionContextV2Schema);
@@ -342,13 +361,20 @@ export const COMMAND_ASK_MAX_CHARS = 32 * 1024;
342
361
  * `commandHash` is the SHA-256 of the command text the approval holds in full, so an audit can
343
362
  * match a record to what ran.
344
363
  */
345
- export const PermissionExpansionSchema = z
364
+ export const PermissionExpansionSchema = z.preprocess(
365
+ // a scope recorded before read roots left the kernel (reads are the device provider's rule)
366
+ // carried `readDirectories`: read without it, as nothing grants a read any more
367
+ (value) => {
368
+ if (typeof value !== "object" || value === null || !Object.hasOwn(value, "readDirectories"))
369
+ return value;
370
+ const { readDirectories: _reads, ...rest } = value;
371
+ return rest;
372
+ }, z
346
373
  .object({
347
- readDirectories: z.array(z.string().max(4096)).max(64),
348
374
  writeDirectories: z.array(z.string().max(4096)).max(64),
349
375
  hosts: z.array(z.string().max(253)).max(100),
350
376
  })
351
- .strict();
377
+ .strict());
352
378
  export const PermissionCallBindingSchema = z
353
379
  .object({
354
380
  orgId: z.string(),
@@ -62,7 +62,12 @@ export declare class PermissionProfilesController {
62
62
  } | null;
63
63
  scopeRevision: string | null;
64
64
  outsideSandboxCeiling: boolean;
65
- broadProjectReach: boolean;
65
+ consentReach: {
66
+ outsideSandbox: boolean;
67
+ networkCeiling: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
68
+ networkMode: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
69
+ hostCeiling: import("../sandbox/device-sandbox.js").HostGrantCeiling;
70
+ } | null;
66
71
  sandbox: import("../sandbox/device-sandbox.js").DeviceSandbox | null;
67
72
  startingWorkNotice: string;
68
73
  }>;
@@ -78,13 +83,10 @@ export declare class PermissionProfilesController {
78
83
  outsideSandbox: boolean;
79
84
  networkCeiling: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
80
85
  networkMode: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
81
- restrictedProjectReach: "os-user" | "workspace";
82
86
  hostCeiling: import("../sandbox/device-sandbox.js").HostGrantCeiling;
83
87
  };
84
- location: "cloud" | "local";
85
88
  sandbox: import("../sandbox/device-sandbox.js").DeviceSandbox;
86
89
  outsideSandboxCeiling: boolean;
87
- broadProjectReach: boolean;
88
90
  availability: import("../sandbox/permission-availability.js").PermissionAvailability;
89
91
  }>;
90
92
  first(org: OrgContext, p: Principal, body: z.infer<typeof FirstMessageBody>, reply: FastifyReply): Promise<{
@@ -29,13 +29,10 @@ export declare class PermissionProfilesService {
29
29
  outsideSandbox: boolean;
30
30
  networkCeiling: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
31
31
  networkMode: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
32
- restrictedProjectReach: "os-user" | "workspace";
33
32
  hostCeiling: import("../sandbox/device-sandbox.js").HostGrantCeiling;
34
33
  };
35
- location: "cloud" | "local";
36
34
  sandbox: import("../sandbox/device-sandbox.js").DeviceSandbox;
37
35
  outsideSandboxCeiling: boolean;
38
- broadProjectReach: boolean;
39
36
  availability: import("../sandbox/permission-availability.js").PermissionAvailability;
40
37
  }>;
41
38
  get(orgId: string, id: string, accountId: string): Promise<{
@@ -50,7 +47,12 @@ export declare class PermissionProfilesService {
50
47
  } | null;
51
48
  scopeRevision: string | null;
52
49
  outsideSandboxCeiling: boolean;
53
- broadProjectReach: boolean;
50
+ consentReach: {
51
+ outsideSandbox: boolean;
52
+ networkCeiling: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
53
+ networkMode: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
54
+ hostCeiling: import("../sandbox/device-sandbox.js").HostGrantCeiling;
55
+ } | null;
54
56
  sandbox: import("../sandbox/device-sandbox.js").DeviceSandbox | null;
55
57
  startingWorkNotice: string;
56
58
  }>;
@@ -1,6 +1,7 @@
1
1
  import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec } from "@capybara-hq/plugin-sdk";
2
2
  import type { Redis } from "ioredis";
3
3
  import { Kysely } from "kysely";
4
+ import type { DialInAccess } from "../dial-in/access.js";
4
5
  import { type RegisteredHook } from "../extensions/hooks.js";
5
6
  import { RegistrationLedger } from "../extensions/ledger.js";
6
7
  import type { LockService } from "../infra/lock/lock.service.js";
@@ -8,6 +9,7 @@ import type { ModelEmbeddings } from "../models/embeddings.js";
8
9
  import type { ModelImages } from "../models/images.js";
9
10
  import type { OrgRole } from "../orgs/roles.js";
10
11
  import type { HookRunner } from "../runtime/hook-calls.js";
12
+ import type { DeviceReports } from "../sandbox/device-reports.js";
11
13
  import type { ShareLiveness } from "../shares/liveness.js";
12
14
  import type { EmbedTokens } from "../ui/embed-token.js";
13
15
  import { type UiActionHandler, type UiRender } from "../ui/registry.js";
@@ -55,6 +57,18 @@ export interface KernelDeps {
55
57
  * in a test) verifies no share token (fail closed).
56
58
  */
57
59
  shares: Pick<ShareLiveness, "embedLive"> | undefined;
60
+ /**
61
+ * What `ctx.dialIn` is built from (`DialInAccess`): the relay and the check that a device is
62
+ * served by the calling extension. Absent (a ctx built alone in a test): `ctx.dialIn` calls
63
+ * reject.
64
+ */
65
+ dialIn?: Pick<DialInAccess, "serves" | "request" | "online" | "stop">;
66
+ /**
67
+ * What `ctx.devices` is built from (`DeviceReports`): `changed` reads a device's report again
68
+ * from the calling provider and refuses (`not-served`) a device bound to another one. Absent
69
+ * (a ctx built alone in a test): `ctx.devices` calls reject.
70
+ */
71
+ devices?: Pick<DeviceReports, "changed">;
58
72
  runWorkers: boolean;
59
73
  /** 内核 logger(`debug` 可选:插件 Logger 没有它,测试可不给)。 */
60
74
  log: Logger & {
@@ -180,7 +194,12 @@ export declare class LiveConfig {
180
194
  * (through `deps.net`, see `ctx/net.ts`);
181
195
  * - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
182
196
  * only with `permissions.models` (`embed` only its `embedding` purposes, `generateImage` only its
183
- * `image_generation` ones, through `deps.models`); `http.route`
197
+ * `image_generation` ones, through `deps.models`); `dialIn` only with `permissions.dialIn`, each
198
+ * call only for a device whose provider is this extension and that it serves in the device's org
199
+ * (through `deps.dialIn`; another device throws `ExtensionPermissionError`); `devices` only for
200
+ * an extension that provides `device-provider@1`, `reportChanged` only for a live device bound to
201
+ * this extension (through `deps.devices`; another device throws `ExtensionPermissionError`);
202
+ * `http.route`
184
203
  * only the method + path declared in `permissions.http` (the record carries the declared access and
185
204
  * its mount, see {@link Route}); `tools.register` only names declared in
186
205
  * `permissions.tools`; `ui.view` / `ui.action` only ids declared in `permissions.ui.views` or
@@ -187,7 +187,12 @@ export class LiveConfig {
187
187
  * (through `deps.net`, see `ctx/net.ts`);
188
188
  * - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
189
189
  * only with `permissions.models` (`embed` only its `embedding` purposes, `generateImage` only its
190
- * `image_generation` ones, through `deps.models`); `http.route`
190
+ * `image_generation` ones, through `deps.models`); `dialIn` only with `permissions.dialIn`, each
191
+ * call only for a device whose provider is this extension and that it serves in the device's org
192
+ * (through `deps.dialIn`; another device throws `ExtensionPermissionError`); `devices` only for
193
+ * an extension that provides `device-provider@1`, `reportChanged` only for a live device bound to
194
+ * this extension (through `deps.devices`; another device throws `ExtensionPermissionError`);
195
+ * `http.route`
191
196
  * only the method + path declared in `permissions.http` (the record carries the declared access and
192
197
  * its mount, see {@link Route}); `tools.register` only names declared in
193
198
  * `permissions.tools`; `ui.view` / `ui.action` only ids declared in `permissions.ui.views` or
@@ -276,6 +281,70 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
276
281
  },
277
282
  }
278
283
  : undefined;
284
+ // ctx.dialIn: only with permissions.dialIn, and each call only for a device this extension serves:
285
+ // `devices.provider` is this extension and the extension is enabled in the device's org (read
286
+ // per call). The full availability check (valid org and effective config) runs at the machine's
287
+ // hello (`DialInHandlers`), so a machine of a provider that is not available never connects.
288
+ const dialInApi = perms.dialIn
289
+ ? (() => {
290
+ const access = deps.dialIn;
291
+ const served = async (deviceId) => {
292
+ if (!access)
293
+ throw new Error(`plugin ${name}: ctx.dialIn is not available`);
294
+ if (typeof deviceId !== "string" || !(await access.serves(name, deviceId))) {
295
+ const item = `dialIn:device ${String(deviceId)}`;
296
+ const p = recordDenial(deps, name, item).finally(() => audits.delete(p));
297
+ audits.add(p);
298
+ const e = new ExtensionPermissionError(name, "permissions.dialIn");
299
+ e.message = `device ${String(deviceId)} is not served by ${name}`;
300
+ throw e;
301
+ }
302
+ return deviceId;
303
+ };
304
+ return {
305
+ request: async (deviceId, frame, opts) => {
306
+ const id = await served(deviceId);
307
+ const signal = opts?.signal
308
+ ? AbortSignal.any([lifecycle.signal, opts.signal])
309
+ : lifecycle.signal;
310
+ // only the options an extension may pass: never the kernel's connection fences
311
+ return access.request(id, frame, {
312
+ timeoutMs: Number(opts?.timeoutMs),
313
+ signal,
314
+ });
315
+ },
316
+ online: async (deviceId) => access.online(await served(deviceId)),
317
+ stop: async (deviceId, reason) => {
318
+ if (reason !== "drain" && reason !== "stop")
319
+ throw new TypeError(`plugin ${name}: ctx.dialIn.stop reason must be drain or stop`);
320
+ await access.stop(await served(deviceId), reason);
321
+ },
322
+ };
323
+ })()
324
+ : undefined;
325
+ // ctx.devices: only for a device provider, and each call only for a device bound to it
326
+ // (`devices.provider`, read per call): the kernel reads the report again from this extension
327
+ // and, when its revision changed, moves the device authority epoch (device-provider spec §6.7)
328
+ const devicesApi = manifest.provides.includes(DEVICE_PROVIDER_EXTENSION_POINT)
329
+ ? {
330
+ reportChanged: async (deviceId) => {
331
+ const reports = deps.devices;
332
+ if (!reports)
333
+ throw new Error(`plugin ${name}: ctx.devices is not available`);
334
+ const outcome = typeof deviceId === "string"
335
+ ? await reports.changed(name, deviceId, lifecycle.signal)
336
+ : "not-served";
337
+ if (outcome === "not-served") {
338
+ const item = `devices:device ${String(deviceId)}`;
339
+ const p = recordDenial(deps, name, item).finally(() => audits.delete(p));
340
+ audits.add(p);
341
+ const e = new ExtensionPermissionError(name, `provides ${DEVICE_PROVIDER_EXTENSION_POINT}`);
342
+ e.message = `device ${String(deviceId)} is not served by ${name}`;
343
+ throw e;
344
+ }
345
+ },
346
+ }
347
+ : undefined;
279
348
  // "METHOD path" -> the access the manifest declares for it (the approved manifest)
280
349
  const declaredRoutes = new Map((perms.http ?? []).map((r) => [`${r.method} ${r.path}`, r.access]));
281
350
  const declaredTools = new Set(perms.tools ?? []);
@@ -660,7 +729,7 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
660
729
  const served = extensionPoint === FILE_PREVIEW_EXTENSION_POINT
661
730
  ? checkFilePreviewProvider(manifest, impl, uiResolution, deps.log)
662
731
  : extensionPoint === DEVICE_PROVIDER_EXTENSION_POINT
663
- ? checkDeviceProvider(name, impl)
732
+ ? checkDeviceProvider(name, impl, manifest.permissions?.dialIn)
664
733
  : impl;
665
734
  provided.set(extensionPoint, served);
666
735
  ledger.add({
@@ -721,15 +790,15 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
721
790
  return closing;
722
791
  },
723
792
  };
724
- // secrets / storage / models: a plain property when declared; otherwise a non-enumerable getter
725
- // that throws, so spreading or printing ctx triggers no denial and no audit
726
- const gated = (key, api) => {
793
+ // secrets / storage / models / dialIn / devices: a plain property when declared; otherwise a
794
+ // non-enumerable getter that throws, so spreading or printing ctx triggers no denial and no audit
795
+ const gated = (key, api, item = `permissions.${key}`) => {
727
796
  if (api) {
728
797
  Object.assign(ctx, { [key]: api });
729
798
  return;
730
799
  }
731
800
  Object.defineProperty(ctx, key, {
732
- get: () => deny(`permissions.${key}`),
801
+ get: () => deny(item),
733
802
  enumerable: false,
734
803
  configurable: false,
735
804
  });
@@ -737,6 +806,8 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
737
806
  gated("secrets", secretsApi);
738
807
  gated("storage", storageApi);
739
808
  gated("models", modelsApi);
809
+ gated("dialIn", dialInApi);
810
+ gated("devices", devicesApi, `provides ${DEVICE_PROVIDER_EXTENSION_POINT}`);
740
811
  return ctx;
741
812
  }
742
813
  /**
@@ -2,6 +2,10 @@ import type { DeviceProvider } from "@capybara-hq/plugin-sdk";
2
2
  /**
3
3
  * Checks a plugin's `device-provider@1` implementation when it is provided: the declarations
4
4
  * (`networkAllowlist`, `concurrentExec`) must be `true` and the required methods must exist. A
5
- * failure fails the plugin's setup, so it never loads.
5
+ * provider declaring `permissions.dialIn` (`dialIn` given) must implement `dialIn.onHello` (its
6
+ * `onFrame` and `onClose`, when present, are functions); one that does not declare it must not
7
+ * implement `dialIn`. A failure fails the plugin's setup, so it never loads.
6
8
  */
7
- export declare function checkDeviceProvider(plugin: string, impl: unknown): DeviceProvider;
9
+ export declare function checkDeviceProvider(plugin: string, impl: unknown, dialIn?: {
10
+ protocol: string;
11
+ }): DeviceProvider;
@@ -2,9 +2,11 @@ const REQUIRED_FUNCTIONS = ["report", "killTagged", "exec", "create", "createFil
2
2
  /**
3
3
  * Checks a plugin's `device-provider@1` implementation when it is provided: the declarations
4
4
  * (`networkAllowlist`, `concurrentExec`) must be `true` and the required methods must exist. A
5
- * failure fails the plugin's setup, so it never loads.
5
+ * provider declaring `permissions.dialIn` (`dialIn` given) must implement `dialIn.onHello` (its
6
+ * `onFrame` and `onClose`, when present, are functions); one that does not declare it must not
7
+ * implement `dialIn`. A failure fails the plugin's setup, so it never loads.
6
8
  */
7
- export function checkDeviceProvider(plugin, impl) {
9
+ export function checkDeviceProvider(plugin, impl, dialIn) {
8
10
  const p = (impl ?? {});
9
11
  const need = (member) => {
10
12
  throw new Error(`plugin ${plugin}: device-provider@1 requires ${member}`);
@@ -17,5 +19,18 @@ export function checkDeviceProvider(plugin, impl) {
17
19
  if (typeof p[m] !== "function")
18
20
  need(m);
19
21
  }
22
+ const handler = p.dialIn;
23
+ if (dialIn === undefined) {
24
+ if (handler !== undefined)
25
+ throw new Error(`plugin ${plugin}: device-provider@1 implements dialIn without declaring permissions.dialIn`);
26
+ return impl;
27
+ }
28
+ if (handler === null || typeof handler !== "object" || typeof handler.onHello !== "function")
29
+ need("dialIn.onHello (it declares permissions.dialIn)");
30
+ for (const m of ["onFrame", "onClose"]) {
31
+ const fn = handler[m];
32
+ if (fn !== undefined && typeof fn !== "function")
33
+ need(`dialIn.${m} to be a function`);
34
+ }
20
35
  return impl;
21
36
  }