@capybara-hq/kernel 0.1.0-rc.53 → 0.1.0-rc.55

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 (190) hide show
  1. package/dist/admin/admin.schemas.d.ts +11 -1
  2. package/dist/catalog/catalog.module.js +1 -1
  3. package/dist/catalog/marketplaces.service.d.ts +1 -1
  4. package/dist/catalog/requests.service.d.ts +5 -5
  5. package/dist/catalog/requests.service.js +9 -9
  6. package/dist/channels/cards.d.ts +4 -3
  7. package/dist/channels/cards.js +25 -16
  8. package/dist/channels/phrases.d.ts +15 -4
  9. package/dist/channels/phrases.js +15 -1
  10. package/dist/config/load.d.ts +26 -7
  11. package/dist/config/load.js +60 -9
  12. package/dist/config/permission-migration.d.ts +17 -9
  13. package/dist/config/permission-migration.js +60 -9
  14. package/dist/config/schema.d.ts +15 -1
  15. package/dist/config/schema.js +66 -11
  16. package/dist/conversations/events.d.ts +247 -5
  17. package/dist/conversations/events.js +127 -16
  18. package/dist/conversations/permission-profiles.controller.d.ts +12 -2
  19. package/dist/conversations/permission-profiles.service.d.ts +12 -2
  20. package/dist/conversations/permission-profiles.service.js +11 -4
  21. package/dist/db/kernel-schema.d.ts +18 -2
  22. package/dist/devices/device-projects.service.d.ts +1 -1
  23. package/dist/devices/device-projects.service.js +6 -6
  24. package/dist/devices/devices.controller.d.ts +10 -8
  25. package/dist/devices/devices.controller.js +14 -18
  26. package/dist/devices/devices.schemas.d.ts +5 -5
  27. package/dist/devices/devices.schemas.js +5 -5
  28. package/dist/devices/devices.service.d.ts +188 -175
  29. package/dist/devices/devices.service.js +284 -292
  30. package/dist/devices/dto.d.ts +43 -23
  31. package/dist/devices/dto.js +45 -49
  32. package/dist/devices/project-rules.d.ts +0 -10
  33. package/dist/devices/project-rules.js +0 -5
  34. package/dist/errors.d.ts +43 -19
  35. package/dist/errors.js +43 -19
  36. package/dist/evals/reconstruct.d.ts +12 -3
  37. package/dist/evals/reconstruct.js +10 -6
  38. package/dist/evals/recorded-permission-context.d.ts +6 -4
  39. package/dist/evals/recorded-permission-context.js +15 -9
  40. package/dist/evals/run-replay.d.ts +6 -1
  41. package/dist/evals/run-replay.js +7 -2
  42. package/dist/evals/worker.js +3 -1
  43. package/dist/http/api.module.js +8 -0
  44. package/dist/http/app.js +9 -0
  45. package/dist/http/meta.controller.d.ts +33 -0
  46. package/dist/http/meta.controller.js +72 -0
  47. package/dist/identity/app-auth.controller.d.ts +25 -0
  48. package/dist/identity/app-auth.controller.js +64 -0
  49. package/dist/identity/app-auth.d.ts +66 -0
  50. package/dist/identity/app-auth.js +203 -0
  51. package/dist/identity/app-auth.schemas.d.ts +47 -0
  52. package/dist/identity/app-auth.schemas.js +43 -0
  53. package/dist/identity/identity.module.d.ts +1 -1
  54. package/dist/identity/identity.module.js +4 -1
  55. package/dist/identity/settings.d.ts +45 -18
  56. package/dist/identity/settings.js +151 -51
  57. package/dist/infra/config/kernel-config.service.d.ts +1 -1
  58. package/dist/infra/config/kernel-config.service.js +19 -5
  59. package/dist/infra/outbox/registry.d.ts +14 -0
  60. package/dist/infra/outbox/registry.js +15 -0
  61. package/dist/infra/throttler/named-throttlers.d.ts +3 -2
  62. package/dist/infra/throttler/named-throttlers.js +14 -2
  63. package/dist/local-devices/device-auth.controller.d.ts +1 -1
  64. package/dist/local-devices/device-auth.controller.js +1 -1
  65. package/dist/local-devices/device-auth.d.ts +4 -4
  66. package/dist/local-devices/device-auth.js +1 -1
  67. package/dist/local-devices/device-policy.service.d.ts +18 -9
  68. package/dist/local-devices/device-policy.service.js +21 -61
  69. package/dist/local-devices/device-routes.d.ts +3 -1
  70. package/dist/local-devices/device-routes.js +15 -4
  71. package/dist/local-devices/instance-bindings.js +5 -2
  72. package/dist/local-devices/local-device-gateway.d.ts +2 -2
  73. package/dist/local-devices/local-device-gateway.js +3 -3
  74. package/dist/local-devices/local-device-provider.d.ts +4 -4
  75. package/dist/local-devices/local-device-provider.js +23 -9
  76. package/dist/local-devices/local-devices.module.d.ts +1 -1
  77. package/dist/local-devices/local-devices.module.js +1 -1
  78. package/dist/local-devices/machines.d.ts +40 -16
  79. package/dist/local-devices/machines.js +89 -61
  80. package/dist/local-devices/owner-report.d.ts +16 -14
  81. package/dist/local-devices/owner-report.js +24 -30
  82. package/dist/local-devices/owner-reports.js +26 -8
  83. package/dist/local-devices/policy-summary.d.ts +25 -44
  84. package/dist/local-devices/policy-summary.js +26 -71
  85. package/dist/local-devices/relay.d.ts +6 -6
  86. package/dist/local-devices/relay.js +10 -8
  87. package/dist/net/public-address.d.ts +1 -1
  88. package/dist/net/public-address.js +5 -2
  89. package/dist/orgs/device-network-setting.d.ts +82 -0
  90. package/dist/orgs/device-network-setting.js +142 -0
  91. package/dist/orgs/settings.service.d.ts +103 -66
  92. package/dist/orgs/settings.service.js +201 -137
  93. package/dist/overrides.d.ts +5 -1
  94. package/dist/overrides.js +2 -0
  95. package/dist/platform/exclusions.js +24 -1
  96. package/dist/platform/operation.js +2 -2
  97. package/dist/platform/ops/admin.ops.js +20 -11
  98. package/dist/platform/ops/devices.ops.js +70 -5
  99. package/dist/platform/ops/org-settings.ops.js +10 -6
  100. package/dist/platform/ops/orgs.ops.js +2 -1
  101. package/dist/platform/ops/platform-icons.ops.d.ts +14 -0
  102. package/dist/platform/ops/platform-icons.ops.js +117 -0
  103. package/dist/platform/platform-ops.module.d.ts +2 -1
  104. package/dist/platform/platform-ops.module.js +3 -0
  105. package/dist/platform/route-schemas.js +3 -0
  106. package/dist/runtime/context/permission-profile.d.ts +17 -8
  107. package/dist/runtime/context/permission-profile.js +126 -45
  108. package/dist/runtime/maintenance.d.ts +5 -2
  109. package/dist/runtime/maintenance.js +15 -4
  110. package/dist/runtime/permission-context.service.d.ts +1 -1
  111. package/dist/runtime/permission-context.service.js +5 -3
  112. package/dist/runtime/project/knowledge.d.ts +5 -4
  113. package/dist/runtime/project/knowledge.js +2 -1
  114. package/dist/runtime/project/knowledge.service.js +16 -13
  115. package/dist/sandbox/cloud-permission-snapshot.js +22 -3
  116. package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
  117. package/dist/sandbox/device-sandbox-settings.js +470 -0
  118. package/dist/sandbox/device-sandbox.d.ts +187 -0
  119. package/dist/sandbox/device-sandbox.js +236 -0
  120. package/dist/sandbox/held-operations.js +15 -7
  121. package/dist/sandbox/modes.d.ts +49 -24
  122. package/dist/sandbox/modes.js +27 -19
  123. package/dist/sandbox/operation-authority-types.d.ts +6 -5
  124. package/dist/sandbox/operation-authority-types.js +7 -8
  125. package/dist/sandbox/operation-authority.d.ts +23 -9
  126. package/dist/sandbox/operation-authority.js +179 -97
  127. package/dist/sandbox/permission-auto-grants.d.ts +42 -0
  128. package/dist/sandbox/permission-auto-grants.js +145 -0
  129. package/dist/sandbox/permission-call-grants.d.ts +12 -4
  130. package/dist/sandbox/permission-call-grants.js +84 -35
  131. package/dist/sandbox/permission-call-grants.module.js +10 -3
  132. package/dist/sandbox/permission-call-types.d.ts +39 -5
  133. package/dist/sandbox/permission-ceiling-writes.d.ts +29 -3
  134. package/dist/sandbox/permission-ceiling-writes.js +38 -4
  135. package/dist/sandbox/permission-config-publication.d.ts +44 -2
  136. package/dist/sandbox/permission-config-publication.js +230 -59
  137. package/dist/sandbox/permission-context-types.d.ts +2 -2
  138. package/dist/sandbox/permission-facts.d.ts +144 -15
  139. package/dist/sandbox/permission-facts.js +258 -70
  140. package/dist/sandbox/permission-runtime-reports.d.ts +5 -4
  141. package/dist/sandbox/permission-runtime-reports.js +19 -29
  142. package/dist/sandbox/review/classifier.d.ts +8 -0
  143. package/dist/sandbox/review/classifier.js +10 -0
  144. package/dist/sandbox/review/permission-candidate.d.ts +69 -5
  145. package/dist/sandbox/review/permission-candidate.js +153 -30
  146. package/dist/sandbox/review/review.service.d.ts +19 -3
  147. package/dist/sandbox/review/review.service.js +59 -11
  148. package/dist/sandbox/review/rules.js +23 -3
  149. package/dist/sandbox/sandbox.service.d.ts +29 -11
  150. package/dist/sandbox/sandbox.service.js +51 -26
  151. package/dist/skills/invoke.js +3 -2
  152. package/dist/themes/platform-icon-objects.d.ts +51 -0
  153. package/dist/themes/platform-icon-objects.js +113 -0
  154. package/dist/themes/platform-icon-public.controller.d.ts +17 -0
  155. package/dist/themes/platform-icon-public.controller.js +58 -0
  156. package/dist/themes/platform-icon.controller.d.ts +22 -0
  157. package/dist/themes/platform-icon.controller.js +65 -0
  158. package/dist/themes/platform-icon.schemas.d.ts +48 -0
  159. package/dist/themes/platform-icon.schemas.js +53 -0
  160. package/dist/themes/platform-icon.service.d.ts +83 -0
  161. package/dist/themes/platform-icon.service.js +301 -0
  162. package/dist/themes/themes.module.d.ts +4 -1
  163. package/dist/themes/themes.module.js +9 -4
  164. package/dist/tools/approvals.service.d.ts +26 -116
  165. package/dist/tools/approvals.service.js +42 -346
  166. package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
  167. package/dist/tools/builtins/sandbox/bash.js +80 -28
  168. package/dist/tools/builtins/sandbox/common.d.ts +39 -14
  169. package/dist/tools/builtins/sandbox/common.js +47 -24
  170. package/dist/tools/builtins/sandbox/deliver.js +7 -4
  171. package/dist/tools/builtins/skill-load.d.ts +2 -2
  172. package/dist/tools/builtins/skill-load.js +4 -3
  173. package/dist/tools/device-op-resolver.d.ts +4 -10
  174. package/dist/tools/device-op-resolver.js +8 -19
  175. package/dist/tools/network-asks.d.ts +52 -15
  176. package/dist/tools/network-asks.js +55 -25
  177. package/dist/tools/pipeline.d.ts +26 -14
  178. package/dist/tools/pipeline.js +144 -61
  179. package/dist/tools/registry.d.ts +6 -0
  180. package/dist/tools/tools.module.js +1 -1
  181. package/package.json +4 -4
  182. package/src/migrations/0164_platform_icons.sql +10 -0
  183. package/src/migrations/0165_device_network_columns.sql +50 -0
  184. package/src/migrations/0166_permission_grant_full_access.sql +17 -0
  185. package/src/migrations/0167_device_network_backfill.sql +32 -0
  186. package/src/migrations/0168_binding_installed_connection.sql +6 -0
  187. package/dist/orgs/cloud-network-setting.d.ts +0 -33
  188. package/dist/orgs/cloud-network-setting.js +0 -47
  189. package/dist/sandbox/platform-full-access.d.ts +0 -110
  190. package/dist/sandbox/platform-full-access.js +0 -198
@@ -0,0 +1,236 @@
1
+ import { coversHost, orgEffectiveHosts } from "./modes.js";
2
+ /**
3
+ * The hosts of `a` the list `b` covers and the hosts of `b` that `a` covers (wildcards included),
4
+ * lowercased, deduplicated and sorted: never wider than either list.
5
+ */
6
+ export function intersectHosts(a, b) {
7
+ const x = a.map((h) => h.toLowerCase());
8
+ const y = b.map((h) => h.toLowerCase());
9
+ return [
10
+ ...new Set([
11
+ ...x.filter((h) => y.some((p) => coversHost(p, h))),
12
+ ...y.filter((h) => x.some((p) => coversHost(p, h))),
13
+ ]),
14
+ ].sort();
15
+ }
16
+ /** The org's effective allowlist: the platform's list minus its exclusions, plus its extras. */
17
+ export function orgHostsOf(platform, org) {
18
+ return orgEffectiveHosts({ egress: platform.egress, allowHosts: [...platform.allowHosts], orgHosts: platform.orgHosts }, org.deviceNetwork === undefined
19
+ ? undefined
20
+ : {
21
+ ...(org.deviceNetwork.base !== undefined && { base: org.deviceNetwork.base }),
22
+ extraHosts: [...(org.deviceNetwork.extraHosts ?? [])],
23
+ excludedHosts: [...(org.deviceNetwork.excludedHosts ?? [])],
24
+ });
25
+ }
26
+ /**
27
+ * Computes the effective device sandbox from its four layers. Pure; no I/O.
28
+ *
29
+ * - `outsideSandbox`: only when the platform, the org, the device owner and the provider all allow
30
+ * it; a cloud device and an instance-boundary provider never do.
31
+ * - The network ceiling is the narrower of the platform's and the org's (and what the provider can
32
+ * enforce); the kill switch closes it (`none`).
33
+ * - The mode is the device's choice (a local owner's network, a cloud device's `network_mode`),
34
+ * else the org default, else the platform default, clamped to the ceiling.
35
+ * - Allowlist hosts are the org's effective hosts, narrowed by the device's own list: a device list
36
+ * never adds a host. A cloud device's empty list adds no narrowing; a local owner's allowlist is
37
+ * the machine's ceiling, so an empty one allows no host (as the device enforces it).
38
+ */
39
+ export function effectiveDeviceSandbox(platform, org, device, provider) {
40
+ const instance = provider.boundary === "instance";
41
+ // running outside the sandbox: the first layer that forbids it names the ceiling
42
+ const outsideLayer = platform.settings.outsideSandbox !== "allowed"
43
+ ? "platform"
44
+ : org.outsideSandbox === "off"
45
+ ? "org"
46
+ : !provider.outsideSandbox || instance
47
+ ? "provider"
48
+ : device.location === "cloud" || !device.outsideSandbox
49
+ ? "device"
50
+ : null;
51
+ // the network ceiling: platform, then org, then what the provider can enforce
52
+ let ceiling;
53
+ let networkLayer = null;
54
+ if (platform.egress === "none") {
55
+ ceiling = "none";
56
+ networkLayer = "platform";
57
+ }
58
+ else if (platform.settings.network.ceiling === "allowlist") {
59
+ ceiling = "allowlist";
60
+ networkLayer = "platform";
61
+ }
62
+ else if (org.deviceNetwork?.ceiling === "allowlist") {
63
+ ceiling = "allowlist";
64
+ networkLayer = "org";
65
+ }
66
+ else
67
+ ceiling = "open";
68
+ if (ceiling !== "none" && !provider.network.allowlist && !provider.network.openPublic) {
69
+ ceiling = "none";
70
+ networkLayer = "provider";
71
+ }
72
+ else if (ceiling === "open" && !provider.network.openPublic) {
73
+ ceiling = "allowlist";
74
+ networkLayer = "provider";
75
+ }
76
+ // the device's choice, else the org default, else the platform default; then the ceiling
77
+ const chosen = device.location === "local"
78
+ ? device.network
79
+ : (device.networkMode ?? org.deviceNetwork?.default ?? platform.settings.network.default);
80
+ let networkMode = ceiling === "none" || chosen === "none"
81
+ ? "none"
82
+ : ceiling === "allowlist"
83
+ ? "allowlist"
84
+ : chosen;
85
+ if (networkMode === "allowlist" && !provider.network.allowlist)
86
+ networkMode = "none";
87
+ // a local owner's allowlist is a ceiling only the machine widens
88
+ if (networkLayer === null && device.location === "local" && device.network === "allowlist")
89
+ networkLayer = "device";
90
+ let hosts = [];
91
+ if (networkMode === "allowlist") {
92
+ const orgHosts = orgHostsOf(platform, org);
93
+ // a local owner's allowlist is the machine's own ceiling, which the device enforces on every
94
+ // request (an empty one allows nothing); a cloud device's empty list follows its org's hosts
95
+ // (an owner whose network is open narrows nothing: the device takes the kernel's hosts)
96
+ const own = device.location === "local"
97
+ ? device.network === "allowlist"
98
+ ? device.allowedDomains
99
+ : null
100
+ : device.networkHosts.length > 0
101
+ ? device.networkHosts
102
+ : null;
103
+ hosts =
104
+ own === null
105
+ ? [...new Set(orgHosts.map((h) => h.toLowerCase()))]
106
+ : intersectHosts(orgHosts, own);
107
+ }
108
+ return {
109
+ boundary: provider.boundary,
110
+ networkMode,
111
+ networkCeiling: ceiling,
112
+ hosts,
113
+ outsideSandbox: outsideLayer === null,
114
+ restrictedProjectReach: device.location === "local" &&
115
+ platform.settings.outsideSandbox === "allowed" &&
116
+ org.outsideSandbox !== "off" &&
117
+ device.restrictedProjectReach === "os-user"
118
+ ? "os-user"
119
+ : "workspace",
120
+ layer: { network: networkLayer, outsideSandbox: outsideLayer },
121
+ };
122
+ }
123
+ /**
124
+ * The provider layer of a device: its recorded runtime report (support v2) when one is current,
125
+ * else what the kernel assumes before the device starts (the device and its provider still
126
+ * enforce, and admission refuses until a report is recorded): a local device runs per operation
127
+ * and may run outside; a cloud device's instance is its sandbox.
128
+ */
129
+ export function providerLayerOf(report, location) {
130
+ if (report !== null)
131
+ return {
132
+ boundary: report.boundary,
133
+ network: { ...report.network },
134
+ outsideSandbox: report.outsideSandbox,
135
+ };
136
+ return location === "local"
137
+ ? {
138
+ boundary: "operation",
139
+ network: { openPublic: true, allowlist: true, perOperationHosts: true },
140
+ outsideSandbox: true,
141
+ }
142
+ : {
143
+ boundary: "instance",
144
+ network: { openPublic: true, allowlist: true, perOperationHosts: false },
145
+ outsideSandbox: false,
146
+ };
147
+ }
148
+ export function hostGrantCeiling(box, platform, org, owner) {
149
+ if (box.boundary === "instance" || box.networkMode === "none" || platform.egress === "none")
150
+ return { kind: "hosts", hosts: [] };
151
+ // the platform's or org's allowlist ceiling is hard; a provider that cannot enforce the open
152
+ // network clamps the sandbox network, not what an org allows per call
153
+ const hard = box.networkCeiling === "allowlist" && box.layer?.network !== "provider";
154
+ let ceiling = hard || platform.orgHosts === "within"
155
+ ? { kind: "hosts", hosts: orgHostsOf(platform, org) }
156
+ : {
157
+ kind: "any",
158
+ excluded: [...(org.deviceNetwork?.excludedHosts ?? [])].map((h) => h.toLowerCase()),
159
+ };
160
+ if (owner?.network === "allowlist") {
161
+ const own = owner.allowedDomains;
162
+ if (ceiling.kind === "any") {
163
+ const excluded = ceiling.excluded;
164
+ // an own entry an exclusion covers is dropped; an own wildcard that covers an excluded host
165
+ // stays, with the exclusion carried so that host is still refused
166
+ const hosts = own
167
+ .map((h) => h.toLowerCase())
168
+ .filter((h) => !excluded.some((x) => coversHost(x, h)));
169
+ ceiling = excluded.length ? { kind: "hosts", hosts, excluded } : { kind: "hosts", hosts };
170
+ }
171
+ else
172
+ ceiling = { kind: "hosts", hosts: intersectHosts(ceiling.hosts, own) };
173
+ }
174
+ return ceiling;
175
+ }
176
+ /** Whether a per-call grant may name `host` under `ceiling`. */
177
+ export function hostGrantable(ceiling, host) {
178
+ const h = host.toLowerCase();
179
+ if ((ceiling.excluded ?? []).some((x) => coversHost(x.toLowerCase(), h)))
180
+ return false;
181
+ if (ceiling.kind === "any")
182
+ return true;
183
+ return ceiling.hosts.some((p) => coversHost(p.toLowerCase(), h));
184
+ }
185
+ /** A canonical form of a ceiling (sorted, deduplicated, lowercased) for the consent fingerprint. */
186
+ export function canonicalHostCeiling(ceiling) {
187
+ const norm = (l) => [...new Set(l.map((h) => h.toLowerCase()))].sort();
188
+ if (ceiling.kind === "any")
189
+ return { kind: "any", excluded: norm(ceiling.excluded) };
190
+ return ceiling.excluded?.length
191
+ ? { kind: "hosts", hosts: norm(ceiling.hosts), excluded: norm(ceiling.excluded) }
192
+ : { kind: "hosts", hosts: norm(ceiling.hosts) };
193
+ }
194
+ /**
195
+ * Why a per-call grant for `host` is unavailable on this device, naming who can add it, or null
196
+ * when the grant ceiling covers it ({@link hostGrantCeiling}). The org's and platform's layers are
197
+ * named first: the machine's owner can widen only within them.
198
+ */
199
+ export function hostGrantRefusal(host, box, platform, org, owner) {
200
+ if (hostGrantable(hostGrantCeiling(box, platform, org, owner), host))
201
+ return null;
202
+ if (box.networkMode === "none" || platform.egress === "none")
203
+ return "network access is turned off for this device's sandbox";
204
+ if (box.boundary === "instance")
205
+ return `a host cannot be granted per call on this device; add ${host} to the device's network list`;
206
+ const orgLevel = hostGrantCeiling(box, platform, org, null);
207
+ if (!hostGrantable(orgLevel, host))
208
+ return (box.networkCeiling === "allowlist" && box.layer?.network !== "provider") ||
209
+ orgLevel.kind === "any"
210
+ ? `an organization admin adds ${host} to the organization's device network list`
211
+ : `${host} is outside the platform's host list; a super admin adds the host`;
212
+ return `the device owner adds it on the machine: capybara-device policy add allowedDomains ${host}`;
213
+ }
214
+ const MODE_RANK = { none: 0, allowlist: 1, open: 2 };
215
+ /**
216
+ * Whether `now` is within `consented` in every dimension: a narrowing keeps the consent, a widening
217
+ * of any dimension needs a new one (Full access would otherwise auto-approve more).
218
+ */
219
+ export function reachWithin(now, consented) {
220
+ if (now.outsideSandbox && !consented.outsideSandbox)
221
+ return false;
222
+ if (MODE_RANK[now.networkCeiling] > MODE_RANK[consented.networkCeiling])
223
+ return false;
224
+ if (MODE_RANK[now.networkMode] > MODE_RANK[consented.networkMode])
225
+ return false;
226
+ if (now.restrictedProjectReach === "os-user" && consented.restrictedProjectReach !== "os-user")
227
+ return false;
228
+ const a = now.hostCeiling, b = consented.hostCeiling;
229
+ // every exclusion consented to still holds now: no host it covers became grantable
230
+ const keepsExclusions = (b.excluded ?? []).every((x) => (a.excluded ?? []).some((y) => coversHost(y, x)) || !hostGrantable(a, x));
231
+ if (!keepsExclusions)
232
+ return false;
233
+ if (a.kind === "any")
234
+ return b.kind === "any";
235
+ return a.hosts.every((h) => hostGrantable(b, h));
236
+ }
@@ -1,4 +1,4 @@
1
- import { SandboxPermissionUnsupportedError, SandboxScopeDeniedError, } from "@capybara-hq/plugin-sdk";
1
+ import { instanceSupported, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, } from "@capybara-hq/plugin-sdk";
2
2
  import { assertManagedArtifactAdmitted } from "../background/launch.js";
3
3
  import { isFullExecutionScope } from "./operation-authority-types.js";
4
4
  /** The provider's runtime must enforce the scope's profile (and own background executions). */
@@ -6,14 +6,22 @@ export async function assertPermissionSupport(provider, handle, scope, method, s
6
6
  if (!provider.operation || !provider.permissionSupport || !provider.revokeOperation)
7
7
  throw new SandboxPermissionUnsupportedError("This provider does not support permission operations");
8
8
  const support = await provider.permissionSupport(handle, signal);
9
- if (support.version !== 1 ||
9
+ // the sandbox is the same under every profile: an escalated call needs the runtime to run
10
+ // outside it; every other call needs per-operation enforcement, or an instance that is itself
11
+ // the sandbox (one whose report names no reason it is unavailable), and the sandbox network
12
+ // it names
13
+ const sandboxed = instanceSupported(support) ||
14
+ (support.restricted?.filesystem === true &&
15
+ support.restricted.network &&
16
+ support.restricted.native &&
17
+ support.restricted.concurrentScopes);
18
+ if (support.version !== 2 ||
10
19
  (method === "backgroundStart" && (!support.background || !provider.background)) ||
11
20
  (isFullExecutionScope(scope)
12
- ? !support.fullAccess
13
- : !support.restricted?.filesystem ||
14
- !support.restricted.network ||
15
- !support.restricted.native ||
16
- !support.restricted.concurrentScopes))
21
+ ? !support.outsideSandbox || support.boundary === "instance"
22
+ : !sandboxed ||
23
+ (scope.network.kind === "open-public" && !support.network.openPublic) ||
24
+ (scope.network.kind === "allowlist" && !support.network.allowlist)))
17
25
  throw new SandboxPermissionUnsupportedError(support.unavailableReason ?? "This runtime cannot enforce the selected permissions");
18
26
  }
19
27
  /**
@@ -1,17 +1,26 @@
1
+ import type { SandboxLimits } from "@capybara-hq/plugin-sdk";
1
2
  import type { KernelConfig } from "../config/schema.js";
2
3
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
4
  import type { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
- import type { CloudNetworkSetting, OrgSettings } from "../orgs/settings.service.js";
5
- import { type FullAccessPermission } from "./platform-full-access.js";
5
+ import type { DeviceNetworkSetting, OrgSettings } from "../orgs/settings.service.js";
6
+ import { type OutsideSandboxPermission as FullAccessPermission } from "./device-sandbox-settings.js";
6
7
  /**
7
8
  * Device modes (auto mode spec §4.1–§4.3): who may choose auto mode, and the network each mode
8
9
  * gets. One pure function, {@link effectiveDevicePolicy}, combines the platform's switch
9
- * (`devices.fullAccess`), the org's (`fullAccess`, `cloudNetwork`) and the device's owner ceiling (a
10
- * local machine's owner report, a cloud device's B1 snapshot; null follows the platform and the org).
10
+ * (`devices.outsideSandbox`), the org's (`outsideSandbox`, `deviceNetwork`) and the device's owner
11
+ * ceiling (a local machine's owner report, a cloud device's B1 snapshot; null follows the platform
12
+ * and the org).
11
13
  * It is a ceiling only: no device-chosen default mode selects how an operation runs (permission
12
14
  * runtime cutover 8.6); the conversation's permission profile does, within this ceiling.
13
15
  */
14
- /** A device mode. Not `DeviceMode`, which is the program's os | docker run mode. */
16
+ /**
17
+ * The kernel-internal tier of a device (not `DeviceMode`, the program's os | docker run mode). It
18
+ * is no longer a mode the person picks or the model runs at (approval-only profiles design: every
19
+ * profile is sandboxed): `auto` only records that the platform, the org and a local owner allow
20
+ * running outside the sandbox. It survives as the instance-limits tier (recorded with a cloud
21
+ * instance's applied limits, so a changed tier updates or recreates it), the working root's reach
22
+ * and the legacy `device_paths` text; the device sandbox (`device-sandbox.ts`) decides scope.
23
+ */
15
24
  export type SandboxMode = "auto" | "sandbox";
16
25
  /** A device network: any public address (cloud only), or an allowlist. */
17
26
  export type NetworkKind = "open-public" | "allowlist";
@@ -47,19 +56,19 @@ export declare function orgHostOutsideCeiling(limits: NetworkLimits, host: strin
47
56
  * minus the org's exclusions, or the extras alone when the org's base is `none`. The one place
48
57
  * that combines the platform's hosts with the org's.
49
58
  */
50
- export declare function orgEffectiveHosts(limits: NetworkLimits, org: CloudNetworkSetting | undefined): string[];
59
+ export declare function orgEffectiveHosts(limits: NetworkLimits, org: DeviceNetworkSetting | undefined): string[];
51
60
  /**
52
61
  * The org's cloud network in sandbox mode (spec §D2): the allowlist under the kill switch or the
53
62
  * platform ceiling (`orgHosts: within`), else the org's mode (open by default).
54
63
  */
55
- export declare function orgCloudMode(limits: NetworkLimits, org: CloudNetworkSetting | undefined): "open" | "allowlist";
64
+ export declare function orgCloudMode(limits: NetworkLimits, org: DeviceNetworkSetting | undefined): "open" | "allowlist";
56
65
  /**
57
66
  * The platform side of the policy, read live: the effective auto-mode switch and the
58
67
  * `sandbox.limits` network fields (in the caller's transaction when there is one).
59
68
  */
60
69
  export declare function readDeploymentDevicePolicy(db: KernelSchemaDb, config: Pick<KernelConfigService, "get" | "fieldSource">): Promise<DeploymentDevicePolicy>;
61
70
  /** The org settings the policy reads. */
62
- export type OrgDeviceSettings = Pick<OrgSettings, "fullAccess" | "cloudNetwork">;
71
+ export type OrgDeviceSettings = Pick<OrgSettings, "outsideSandbox" | "deviceNetwork">;
63
72
  /** The effective device policy of one device (or of a new device, with no choice of its own). */
64
73
  export interface EffectiveDevicePolicy {
65
74
  /** min(the device's owner ceiling, {@link allowedMode}); `auto` unless that ceiling is sandbox. */
@@ -68,12 +77,6 @@ export interface EffectiveDevicePolicy {
68
77
  allowedMode: SandboxMode;
69
78
  /** The cloud network (auto mode's open network, the org's allowlist, or the kill switch). */
70
79
  network: DeviceNetwork;
71
- /**
72
- * The allowlist a local device's sandbox mode intersects with its own (`sandbox.limits.egress:
73
- * none` empties it). The exec args always carry it, even when the ceiling is auto: the device
74
- * may run stricter than the ceiling.
75
- */
76
- localAllowedDomains: string[];
77
80
  }
78
81
  /**
79
82
  * How far restricted work may root outside the workspace now (B2), the one rule the command
@@ -83,7 +86,7 @@ export interface EffectiveDevicePolicy {
83
86
  */
84
87
  export declare function projectReachOf(source: string, policy: Pick<EffectiveDevicePolicy, "mode" | "allowedMode">, ownerReach: string | null | undefined): "workspace" | "os-user";
85
88
  /** The mode the platform and the org allow: `auto` only when neither turns it off. */
86
- export declare function allowedDeviceMode(platform: FullAccessPermission, org: OrgDeviceSettings["fullAccess"]): SandboxMode;
89
+ export declare function allowedDeviceMode(platform: FullAccessPermission, org: OrgDeviceSettings["outsideSandbox"]): SandboxMode;
87
90
  /** The org's allowlist (the hosts a local device in sandbox mode may reach): {@link orgEffectiveHosts}. */
88
91
  export declare function orgAllowedDomains(deployment: DeploymentDevicePolicy, org: OrgDeviceSettings): string[];
89
92
  /**
@@ -108,7 +111,12 @@ export declare const normalizeNetwork: (n: DeviceNetwork) => DeviceNetwork;
108
111
  * hosts (or wildcards) of each that the other covers. Never wider than either.
109
112
  */
110
113
  export declare function intersectNetworks(a: DeviceNetwork, b: DeviceNetwork): DeviceNetwork;
111
- /** Whether `a` and `b` are the same mode, network kind and host set (null is never the same). */
114
+ /**
115
+ * Whether `a` and `b` are the same mode, network kind and host set (null is never the same): the
116
+ * one-time B1 reconciliation's exactness (`CloudPermissionSnapshots`), which still binds a migrated
117
+ * instance to the exact limits it recorded. A running instance's change ignores the mode
118
+ * ({@link AppliedLimits}).
119
+ */
112
120
  export declare const sameAppliedExactly: (a: AppliedLimits | null | undefined, b: AppliedLimits) => boolean;
113
121
  /** A cloud device's B1 per-device authority: its owner Full ceiling and its outer network. */
114
122
  export interface CloudOwnerSnapshot {
@@ -132,8 +140,25 @@ export declare const cloudChosenMode: (row: {
132
140
  owner_full_access: boolean | null;
133
141
  }) => SandboxMode | null;
134
142
  /**
135
- * What decides whether a running cloud instance must change (auto mode spec §4.2): its mode and
136
- * the kind of its network only. `hosts` and resources reach instances created afterwards.
143
+ * The limits the kernel wants for a device: what lifecycle create and update carry
144
+ * ({@link SandboxLimits}: resources and the outer network) plus the mode the kernel records with a
145
+ * cloud instance's applied limits ({@link AppliedLimits}). The mode never reaches a provider:
146
+ * {@link providerLimits} drops it.
147
+ */
148
+ export interface DeviceLimits extends SandboxLimits {
149
+ mode: SandboxMode;
150
+ }
151
+ /** What a provider's create and update get of {@link DeviceLimits}: resources and the network. */
152
+ export declare function providerLimits(limits: DeviceLimits): SandboxLimits;
153
+ /**
154
+ * What the kernel records of a cloud instance's limits (auto mode spec §4.2). Only the kind of its
155
+ * network decides whether a running instance must change; `hosts` and resources reach instances
156
+ * created afterwards. `mode` is recorded but never decides a change ({@link sameApplied},
157
+ * {@link appliedWider}; only the one-time B1 reconciliation compares it, {@link sameAppliedExactly}):
158
+ * a cloud device has no outside of its sandbox and the mode never reaches a provider
159
+ * ({@link providerLimits}), so a mode that follows the platform's or org's outside-sandbox setting
160
+ * must not update every cloud instance when that setting is toggled (Docker would recreate it
161
+ * without its egress proxy; approval-only profiles design).
137
162
  */
138
163
  export interface AppliedLimits {
139
164
  mode: SandboxMode;
@@ -144,15 +169,15 @@ export declare const appliedOf: (limits: {
144
169
  mode: SandboxMode;
145
170
  network: DeviceNetwork;
146
171
  }) => AppliedLimits;
147
- /** Whether `a` and `b` are the same mode and network kind (null, unknown, is never the same). */
172
+ /** Whether `a` and `b` are the same network kind (null, unknown, is never the same; no mode). */
148
173
  export declare const sameApplied: (a: AppliedLimits | null | undefined, b: AppliedLimits) => boolean;
149
- /** Whether `a` and `b` are the same mode, network kind and host set (null is never the same). */
174
+ /** Whether `a` and `b` are the same network kind and host set (null is never the same; no mode). */
150
175
  export declare const sameAppliedExact: (a: AppliedLimits | null | undefined, b: AppliedLimits) => boolean;
151
176
  /**
152
- * Whether applied limits `a` are more permissive than desired limits `b` in any dimension (spec
153
- * §124): auto where `b` is sandbox, open public addresses where `b` is an allowlist, or an
154
- * allowlisted host `b`'s allowlist does not cover. Narrower or equal is false; unknown (null) is
155
- * false here (callers treat unknown separately).
177
+ * Whether applied limits `a` are more permissive than desired limits `b` in its network (spec
178
+ * §124): open public addresses where `b` is an allowlist, or an allowlisted host `b`'s allowlist
179
+ * does not cover. Narrower or equal is false; unknown (null) is false here (callers treat unknown
180
+ * separately). The mode is not a dimension ({@link AppliedLimits}).
156
181
  */
157
182
  export declare function appliedWider(a: AppliedLimits | null | undefined, b: AppliedLimits): boolean;
158
183
  /**
@@ -1,4 +1,4 @@
1
- import { readDevicesFullAccess } from "./platform-full-access.js";
1
+ import { readDeviceSandboxSettings, } from "./device-sandbox-settings.js";
2
2
  /** Whether the allowlist entry `pattern` admits `host` (`*.x.com`: subdomains, never the apex). */
3
3
  export const coversHost = (pattern, host) => pattern === host || (pattern.startsWith("*.") && host.endsWith(pattern.slice(1)));
4
4
  /**
@@ -34,15 +34,15 @@ export function orgEffectiveHosts(limits, org) {
34
34
  export function orgCloudMode(limits, org) {
35
35
  if (limits.egress === "none" || limits.orgHosts === "within")
36
36
  return "allowlist";
37
- return org?.mode ?? "open";
37
+ return org?.ceiling === "allowlist" || org?.default === "allowlist" ? "allowlist" : "open";
38
38
  }
39
39
  /**
40
40
  * The platform side of the policy, read live: the effective auto-mode switch and the
41
41
  * `sandbox.limits` network fields (in the caller's transaction when there is one).
42
42
  */
43
43
  export async function readDeploymentDevicePolicy(db, config) {
44
- const fullAccess = await readDevicesFullAccess(db, config);
45
- return { fullAccess: fullAccess.permission, limits: config.get().sandbox.limits };
44
+ const settings = await readDeviceSandboxSettings(db, config);
45
+ return { fullAccess: settings.outsideSandbox, limits: config.get().sandbox.limits };
46
46
  }
47
47
  /**
48
48
  * How far restricted work may root outside the workspace now (B2), the one rule the command
@@ -61,7 +61,7 @@ export function allowedDeviceMode(platform, org) {
61
61
  }
62
62
  /** The org's allowlist (the hosts a local device in sandbox mode may reach): {@link orgEffectiveHosts}. */
63
63
  export function orgAllowedDomains(deployment, org) {
64
- return orgEffectiveHosts(deployment.limits, org.cloudNetwork);
64
+ return orgEffectiveHosts(deployment.limits, org.deviceNetwork);
65
65
  }
66
66
  /**
67
67
  * The cloud network (auto mode spec §4.3): `open-public` in auto mode; in sandbox mode the org's
@@ -71,10 +71,11 @@ export function orgAllowedDomains(deployment, org) {
71
71
  export function deviceNetwork(deployment, org, mode) {
72
72
  if (deployment.limits.egress === "none")
73
73
  return { kind: "allowlist", hosts: [] };
74
- // auto mode is 开放挡内网 whatever the org says; only sandbox mode applies `cloudNetwork`
74
+ // auto mode is the open public network (private ranges closed) whatever the org says; only
75
+ // sandbox mode applies `deviceNetwork`
75
76
  if (mode === "auto")
76
77
  return { kind: "open-public", hosts: [] };
77
- if (orgCloudMode(deployment.limits, org.cloudNetwork) === "open") {
78
+ if (orgCloudMode(deployment.limits, org.deviceNetwork) === "open") {
78
79
  return { kind: "open-public", hosts: [] };
79
80
  }
80
81
  return { kind: "allowlist", hosts: orgAllowedDomains(deployment, org) };
@@ -88,7 +89,7 @@ export function deviceNetwork(deployment, org, mode) {
88
89
  export function effectiveDevicePolicy(deployment, org, deviceMode,
89
90
  /** A cloud device's B1 outer network snapshot: the network never goes beyond it. */
90
91
  outer = null) {
91
- const allowedMode = allowedDeviceMode(deployment.fullAccess, org.fullAccess);
92
+ const allowedMode = allowedDeviceMode(deployment.fullAccess, org.outsideSandbox);
92
93
  const mode = allowedMode === "sandbox" ? "sandbox" : (deviceMode ?? "auto");
93
94
  return {
94
95
  mode,
@@ -96,7 +97,6 @@ outer = null) {
96
97
  network: outer === null
97
98
  ? deviceNetwork(deployment, org, mode)
98
99
  : intersectNetworks(deviceNetwork(deployment, org, mode), outer),
99
- localAllowedDomains: orgAllowedDomains(deployment, org),
100
100
  };
101
101
  }
102
102
  /** A network with its hosts lowercased, sorted and deduplicated (`open-public` carries none). */
@@ -122,7 +122,12 @@ export function intersectNetworks(a, b) {
122
122
  ],
123
123
  });
124
124
  }
125
- /** Whether `a` and `b` are the same mode, network kind and host set (null is never the same). */
125
+ /**
126
+ * Whether `a` and `b` are the same mode, network kind and host set (null is never the same): the
127
+ * one-time B1 reconciliation's exactness (`CloudPermissionSnapshots`), which still binds a migrated
128
+ * instance to the exact limits it recorded. A running instance's change ignores the mode
129
+ * ({@link AppliedLimits}).
130
+ */
126
131
  export const sameAppliedExactly = (a, b) => a != null &&
127
132
  a.mode === b.mode &&
128
133
  JSON.stringify(normalizeNetwork(a.network)) === JSON.stringify(normalizeNetwork(b.network));
@@ -147,28 +152,31 @@ export function cloudSnapshotOf(old, applied = null) {
147
152
  * explicit sandbox switch (an old replica's write included) is never overridden.
148
153
  */
149
154
  export const cloudChosenMode = (row) => row.mode === "sandbox" || row.owner_full_access === false ? "sandbox" : null;
155
+ /** What a provider's create and update get of {@link DeviceLimits}: resources and the network. */
156
+ export function providerLimits(limits) {
157
+ const { mode: _kernelOnly, ...rest } = limits;
158
+ return { ...rest, network: { kind: rest.network.kind, hosts: [...rest.network.hosts] } };
159
+ }
150
160
  /** The {@link AppliedLimits} of `limits`. */
151
161
  export const appliedOf = (limits) => ({
152
162
  mode: limits.mode,
153
163
  network: { kind: limits.network.kind, hosts: [...limits.network.hosts] },
154
164
  });
155
- /** Whether `a` and `b` are the same mode and network kind (null, unknown, is never the same). */
156
- export const sameApplied = (a, b) => a != null && a.mode === b.mode && a.network.kind === b.network.kind;
157
- /** Whether `a` and `b` are the same mode, network kind and host set (null is never the same). */
165
+ /** Whether `a` and `b` are the same network kind (null, unknown, is never the same; no mode). */
166
+ export const sameApplied = (a, b) => a != null && a.network.kind === b.network.kind;
167
+ /** Whether `a` and `b` are the same network kind and host set (null is never the same; no mode). */
158
168
  export const sameAppliedExact = (a, b) => sameApplied(a, b) &&
159
169
  [...new Set(a?.network.hosts ?? [])].sort().join("\n") ===
160
170
  [...new Set(b.network.hosts)].sort().join("\n");
161
171
  /**
162
- * Whether applied limits `a` are more permissive than desired limits `b` in any dimension (spec
163
- * §124): auto where `b` is sandbox, open public addresses where `b` is an allowlist, or an
164
- * allowlisted host `b`'s allowlist does not cover. Narrower or equal is false; unknown (null) is
165
- * false here (callers treat unknown separately).
172
+ * Whether applied limits `a` are more permissive than desired limits `b` in its network (spec
173
+ * §124): open public addresses where `b` is an allowlist, or an allowlisted host `b`'s allowlist
174
+ * does not cover. Narrower or equal is false; unknown (null) is false here (callers treat unknown
175
+ * separately). The mode is not a dimension ({@link AppliedLimits}).
166
176
  */
167
177
  export function appliedWider(a, b) {
168
178
  if (a == null)
169
179
  return false;
170
- if (a.mode === "auto" && b.mode === "sandbox")
171
- return true;
172
180
  if (b.network.kind === "open-public")
173
181
  return false;
174
182
  if (a.network.kind === "open-public")
@@ -1,7 +1,7 @@
1
1
  import { type DeviceExecGrants, type SandboxBrowseScope, type SandboxOperationScope, SandboxScopeDeniedError } from "@capybara-hq/plugin-sdk";
2
2
  /**
3
3
  * A call that asked to run outside the sandbox (`sandbox: "escalated"`) whose escalation grant no
4
- * longer matches at admission: the device, its Full access ceiling or the permission scope
4
+ * longer matches at admission: the device, its outside-sandbox setting or the permission scope
5
5
  * changed after the approval. A typed pre-effect scope refusal (nothing ran), never a silent
6
6
  * downgrade to the restricted scope; the tool tells the model to ask again.
7
7
  */
@@ -10,12 +10,13 @@ export declare class EscalationGrantMissingError extends SandboxScopeDeniedError
10
10
  }
11
11
  export declare const isEscalationGrantMissing: (e: unknown) => boolean;
12
12
  /**
13
- * Whether an operation scope needs the Full access ceiling and the runtime's Full support: a Full
14
- * access operation (its reach is full, or narrowed for a kernel read on a Full-only runtime), or a
15
- * per-call sandbox escalation under a restricted profile, whose reach is full (`filesystem:
16
- * device`, `network: environment`) while it keeps its conversation's restricted profile.
13
+ * Whether an operation scope runs outside the sandbox and so needs the outside-sandbox ceiling and
14
+ * the runtime's support for it: only an escalated call (`filesystem: device`, `network:
15
+ * environment`), under any profile. A Full access call is sandboxed like any other.
17
16
  */
18
17
  export declare const isFullExecutionScope: (scope: SandboxOperationScope | SandboxBrowseScope) => boolean;
18
+ /** Whether an operation scope uses the open public network (what an allowlist narrowing takes). */
19
+ export declare const usesOpenNetwork: (scope: SandboxOperationScope | SandboxBrowseScope) => boolean;
19
20
  export declare const isExecutionMethod: (method: string) => method is "exec" | "backgroundStart";
20
21
  /** Null column means absent historical/native provenance; grants:null records an explicit absence. */
21
22
  export interface StartingExecutionGrants {
@@ -1,7 +1,7 @@
1
1
  import { SandboxScopeDeniedError, validateAllowHost, } from "@capybara-hq/plugin-sdk";
2
2
  /**
3
3
  * A call that asked to run outside the sandbox (`sandbox: "escalated"`) whose escalation grant no
4
- * longer matches at admission: the device, its Full access ceiling or the permission scope
4
+ * longer matches at admission: the device, its outside-sandbox setting or the permission scope
5
5
  * changed after the approval. A typed pre-effect scope refusal (nothing ran), never a silent
6
6
  * downgrade to the restricted scope; the tool tells the model to ask again.
7
7
  */
@@ -10,14 +10,13 @@ export class EscalationGrantMissingError extends SandboxScopeDeniedError {
10
10
  }
11
11
  export const isEscalationGrantMissing = (e) => e instanceof Error && e.escalationGrantMissing === true;
12
12
  /**
13
- * Whether an operation scope needs the Full access ceiling and the runtime's Full support: a Full
14
- * access operation (its reach is full, or narrowed for a kernel read on a Full-only runtime), or a
15
- * per-call sandbox escalation under a restricted profile, whose reach is full (`filesystem:
16
- * device`, `network: environment`) while it keeps its conversation's restricted profile.
13
+ * Whether an operation scope runs outside the sandbox and so needs the outside-sandbox ceiling and
14
+ * the runtime's support for it: only an escalated call (`filesystem: device`, `network:
15
+ * environment`), under any profile. A Full access call is sandboxed like any other.
17
16
  */
18
- export const isFullExecutionScope = (scope) => "profile" in scope &&
19
- (scope.profile === "full-access" ||
20
- (scope.filesystem.kind === "device" && scope.network.kind === "environment"));
17
+ export const isFullExecutionScope = (scope) => "profile" in scope && scope.filesystem.kind === "device" && scope.network.kind === "environment";
18
+ /** Whether an operation scope uses the open public network (what an allowlist narrowing takes). */
19
+ export const usesOpenNetwork = (scope) => "profile" in scope && scope.network.kind === "open-public";
21
20
  export const isExecutionMethod = (method) => method === "exec" || method === "backgroundStart";
22
21
  export function parseStartingExecutionGrants(value) {
23
22
  const record = (v, keys) => {