@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,470 @@
1
+ import { sql } from "kysely";
2
+ import { z } from "zod";
3
+ import { convertLegacyCloudNetwork, DeviceNetworkSettingSchema, invalidDeviceNetwork, legacyCloudNetworkOf, narrowerDeviceNetwork, withAllowlistCeiling, } from "../orgs/device-network-setting.js";
4
+ /** The `deployment_settings` key of the super admin's outside-sandbox choice. */
5
+ export const DEVICES_OUTSIDE_SANDBOX_SETTING = "devicesOutsideSandbox";
6
+ /** The `deployment_settings` key of the super admin's network choice. */
7
+ export const DEVICES_NETWORK_SETTING = "devicesNetwork";
8
+ /** The old key of the outside-sandbox choice (B1's Full switch), read only to convert it. */
9
+ export const LEGACY_DEVICES_FULL_ACCESS_SETTING = "devicesFullAccess";
10
+ /** The key B1 converted (the auto-mode switch), read only to convert it. */
11
+ export const LEGACY_DEVICES_AUTO_MODE_SETTING = "devicesAutoMode";
12
+ /** The org settings keys the publication converts. */
13
+ const LEGACY_ORG_KEYS = ["autoMode", "fullAccess", "cloudNetwork"];
14
+ /** What a deployment with neither the startup config nor the stored choice says. */
15
+ export const DEVICE_SANDBOX_DEFAULTS = {
16
+ outsideSandbox: "allowed",
17
+ network: { default: "open", ceiling: "open" },
18
+ };
19
+ const Permission = z.enum(["allowed", "off"]);
20
+ const Mode = z.enum(["open", "allowlist"]);
21
+ /** The stored outside-sandbox choice: `permission` absent follows the default. */
22
+ export const DevicesOutsideSandboxStoredSchema = z
23
+ .object({ permission: Permission.optional() })
24
+ .strict();
25
+ /** The stored network choice: a field absent follows the default. */
26
+ export const DevicesNetworkStoredSchema = z
27
+ .object({ default: Mode.optional(), ceiling: Mode.optional() })
28
+ .strict();
29
+ /**
30
+ * A change of the stored outside-sandbox choice (`PUT /api/v1/admin/settings`
31
+ * `devicesOutsideSandbox`): `permission: null` clears it, back to the default `allowed`.
32
+ */
33
+ export const DEVICES_OUTSIDE_SANDBOX_PATCH = z
34
+ .object({ permission: Permission.nullable() })
35
+ .strict();
36
+ /**
37
+ * A change of the stored network choice (`devicesNetwork`): each given field replaces the stored
38
+ * one, null clears it (back to the default `open`); at least one field.
39
+ */
40
+ export const DEVICES_NETWORK_PATCH = z
41
+ .object({ default: Mode.nullable().optional(), ceiling: Mode.nullable().optional() })
42
+ .strict()
43
+ .refine((p) => p.default !== undefined || p.ceiling !== undefined, {
44
+ message: "give default, ceiling or both",
45
+ });
46
+ /**
47
+ * Parses a stored outside-sandbox choice: missing -> `{}`; invalid -> `{ permission: "off" }` with
48
+ * a warning, narrower, never wider.
49
+ */
50
+ export function parseStoredDevicesOutsideSandbox(value, log) {
51
+ if (value === undefined)
52
+ return {};
53
+ const parsed = DevicesOutsideSandboxStoredSchema.safeParse(value);
54
+ if (parsed.success)
55
+ return parsed.data;
56
+ log?.warn("invalid deployment setting; it reads as running outside the sandbox off", {
57
+ key: DEVICES_OUTSIDE_SANDBOX_SETTING,
58
+ });
59
+ return { permission: "off" };
60
+ }
61
+ /**
62
+ * Parses a stored network choice: missing -> `{}`; invalid -> the allowlist for both with a
63
+ * warning, narrower, never wider.
64
+ */
65
+ export function parseStoredDevicesNetwork(value, log) {
66
+ if (value === undefined)
67
+ return {};
68
+ const parsed = DevicesNetworkStoredSchema.safeParse(value);
69
+ if (parsed.success)
70
+ return parsed.data;
71
+ log?.warn("invalid deployment setting; it reads as the allowlist", {
72
+ key: DEVICES_NETWORK_SETTING,
73
+ });
74
+ return { default: "allowlist", ceiling: "allowlist" };
75
+ }
76
+ /** What an old outside-sandbox value converts to: `off` also narrows the network ceiling. */
77
+ const ofLegacyPermission = (permission) => permission === undefined
78
+ ? { outsideSandbox: {}, network: {} }
79
+ : {
80
+ outsideSandbox: { permission },
81
+ network: permission === "off" ? { ceiling: "allowlist" } : {},
82
+ };
83
+ /**
84
+ * Converts a stored old `devicesFullAccess` (`{ permission }`): the same permission, and an `off`
85
+ * also limits the network ceiling to the allowlist; an invalid value converts to `off` with a
86
+ * warning, never absent.
87
+ */
88
+ export function parseLegacyStoredDevicesFullAccess(value, log) {
89
+ const parsed = DevicesOutsideSandboxStoredSchema.safeParse(value);
90
+ if (parsed.success)
91
+ return ofLegacyPermission(parsed.data.permission);
92
+ log?.warn("invalid deployment setting devicesFullAccess; it converts to off", {
93
+ key: LEGACY_DEVICES_FULL_ACCESS_SETTING,
94
+ });
95
+ return ofLegacyPermission("off");
96
+ }
97
+ /** Converts a stored old `devicesAutoMode` (`{ mode }`) like {@link parseLegacyStoredDevicesFullAccess}. */
98
+ export function parseLegacyStoredDevicesAutoMode(value, log) {
99
+ const parsed = z.object({ mode: Permission.optional() }).strict().safeParse(value);
100
+ if (parsed.success)
101
+ return ofLegacyPermission(parsed.data.mode);
102
+ log?.warn("invalid deployment setting devicesAutoMode; it converts to off", {
103
+ key: LEGACY_DEVICES_AUTO_MODE_SETTING,
104
+ });
105
+ return ofLegacyPermission("off");
106
+ }
107
+ /** The stored outside-sandbox choice with `patch` applied (`permission: null` clears it). */
108
+ export function applyDevicesOutsideSandboxPatch(_stored, patch) {
109
+ return patch.permission === null ? {} : { permission: patch.permission };
110
+ }
111
+ /** The stored network choice with `patch` applied (a null field clears it). */
112
+ export function applyDevicesNetworkPatch(stored, patch) {
113
+ const next = { ...stored };
114
+ for (const field of ["default", "ceiling"]) {
115
+ const value = patch[field];
116
+ if (value === null)
117
+ delete next[field];
118
+ else if (value !== undefined)
119
+ next[field] = value;
120
+ }
121
+ return next;
122
+ }
123
+ const narrowerMode = (a, b) => a === "allowlist" || b === "allowlist" ? "allowlist" : (a ?? b);
124
+ /**
125
+ * The narrower of two stored choices, field by field: `off` / `allowlist` when either says so;
126
+ * otherwise `a`'s value, else `b`'s (an absent value follows the default, the widest, so `allowed`
127
+ * or `open` over absent says the same and is kept, as a conversion must be exact).
128
+ */
129
+ export function narrowerStoredDeviceSandbox(a, b) {
130
+ const permission = a.outsideSandbox.permission === "off" || b.outsideSandbox.permission === "off"
131
+ ? "off"
132
+ : (a.outsideSandbox.permission ?? b.outsideSandbox.permission);
133
+ const def = narrowerMode(a.network.default, b.network.default);
134
+ const ceiling = narrowerMode(a.network.ceiling, b.network.ceiling);
135
+ return {
136
+ outsideSandbox: permission === undefined ? {} : { permission },
137
+ network: {
138
+ ...(def !== undefined && { default: def }),
139
+ ...(ceiling !== undefined && { ceiling }),
140
+ },
141
+ };
142
+ }
143
+ /**
144
+ * The effective settings and their sources, pure (the reader below adds the database read). The
145
+ * startup config fields are optional with no schema default, so a defined value with a source
146
+ * means the config sets it: it wins over the stored choice. The effective default never exceeds
147
+ * the effective ceiling (the narrower of the two is shown and applied).
148
+ */
149
+ export function resolveDeviceSandboxSettings(configured, stored) {
150
+ const pick = (value, source, fromDb, fallback) => value !== undefined && source !== undefined
151
+ ? { value, source }
152
+ : fromDb !== undefined
153
+ ? { value: fromDb, source: "db" }
154
+ : { value: fallback, source: "default" };
155
+ const outside = pick(configured.outsideSandbox, configured.sources.outsideSandbox, stored.outsideSandbox.permission, DEVICE_SANDBOX_DEFAULTS.outsideSandbox);
156
+ const ceiling = pick(configured.networkCeiling, configured.sources.networkCeiling, stored.network.ceiling, DEVICE_SANDBOX_DEFAULTS.network.ceiling);
157
+ const def = pick(configured.networkDefault, configured.sources.networkDefault, stored.network.default, DEVICE_SANDBOX_DEFAULTS.network.default);
158
+ return {
159
+ outsideSandbox: { permission: outside.value, source: outside.source },
160
+ network: {
161
+ default: ceiling.value === "allowlist" ? "allowlist" : def.value,
162
+ ceiling: ceiling.value,
163
+ sources: { default: def.source, ceiling: ceiling.source },
164
+ },
165
+ };
166
+ }
167
+ /** The plain settings of a view. */
168
+ export const deviceSandboxSettingsOf = (view) => ({
169
+ outsideSandbox: view.outsideSandbox.permission,
170
+ network: { default: view.network.default, ceiling: view.network.ceiling },
171
+ });
172
+ /** The startup config's values and sources. */
173
+ export function configuredDeviceSandbox(config) {
174
+ // optional chaining: partial config stubs (tests, the CLI) may leave the section out
175
+ const d = config.get().devices;
176
+ return {
177
+ outsideSandbox: d?.outsideSandbox,
178
+ networkDefault: d?.network?.default,
179
+ networkCeiling: d?.network?.ceiling,
180
+ sources: {
181
+ outsideSandbox: config.fieldSource("devices.outsideSandbox"),
182
+ networkDefault: config.fieldSource("devices.network.default"),
183
+ networkCeiling: config.fieldSource("devices.network.ceiling"),
184
+ },
185
+ };
186
+ }
187
+ /** The stored platform rows, by key. */
188
+ async function storedRows(db, forUpdate = false) {
189
+ let q = db
190
+ .selectFrom("deployment_settings")
191
+ .select(["key", "value"])
192
+ .where("key", "in", [
193
+ DEVICES_OUTSIDE_SANDBOX_SETTING,
194
+ DEVICES_NETWORK_SETTING,
195
+ LEGACY_DEVICES_FULL_ACCESS_SETTING,
196
+ LEGACY_DEVICES_AUTO_MODE_SETTING,
197
+ ]);
198
+ if (forUpdate)
199
+ q = q.forUpdate();
200
+ const rows = await q.execute();
201
+ return new Map(rows.map((r) => [r.key, r.value]));
202
+ }
203
+ /** The old platform keys of `rows`, each converted. */
204
+ function legacyOf(rows, log) {
205
+ const out = [];
206
+ if (rows.has(LEGACY_DEVICES_AUTO_MODE_SETTING))
207
+ out.push({
208
+ key: LEGACY_DEVICES_AUTO_MODE_SETTING,
209
+ value: parseLegacyStoredDevicesAutoMode(rows.get(LEGACY_DEVICES_AUTO_MODE_SETTING), log),
210
+ });
211
+ if (rows.has(LEGACY_DEVICES_FULL_ACCESS_SETTING))
212
+ out.push({
213
+ key: LEGACY_DEVICES_FULL_ACCESS_SETTING,
214
+ value: parseLegacyStoredDevicesFullAccess(rows.get(LEGACY_DEVICES_FULL_ACCESS_SETTING), log),
215
+ });
216
+ return out;
217
+ }
218
+ /**
219
+ * The old permission value written next to the new keys for replicas of the previous version
220
+ * (their Full switch): `allowed` only when running outside the sandbox is allowed AND the network
221
+ * ceiling is open, else `off`, so an old replica never reads Full where a new one keeps devices on
222
+ * the allowlist. `outside` absent with an open ceiling stays absent (follow the default).
223
+ */
224
+ export function legacyPermissionFor(outside, ceiling) {
225
+ return outside === "off" || ceiling === "allowlist" ? "off" : outside;
226
+ }
227
+ /**
228
+ * The stored choices of `rows` over every key (fail closed). Without `devicesOutsideSandbox` the
229
+ * old keys are all there is: each converts in full (an `off` also narrows the network ceiling).
230
+ * With it, an old key written in step ({@link legacyPermissionFor} the new keys and the effective
231
+ * ceiling, `configuredCeiling` from the startup config winning over the stored one) says nothing
232
+ * more; one that differs (an old replica wrote it) narrows as a conversion would.
233
+ */
234
+ function storedOf(rows, log, configuredCeiling) {
235
+ const current = {
236
+ outsideSandbox: parseStoredDevicesOutsideSandbox(rows.get(DEVICES_OUTSIDE_SANDBOX_SETTING), log),
237
+ network: parseStoredDevicesNetwork(rows.get(DEVICES_NETWORK_SETTING), log),
238
+ };
239
+ const marked = rows.has(DEVICES_OUTSIDE_SANDBOX_SETTING);
240
+ const inStep = legacyPermissionFor(current.outsideSandbox.permission, configuredCeiling ?? current.network.ceiling);
241
+ let out = current;
242
+ for (const { value } of legacyOf(rows, log)) {
243
+ if (marked && value.outsideSandbox.permission === inStep)
244
+ continue;
245
+ out = narrowerStoredDeviceSandbox(out, value);
246
+ }
247
+ return out;
248
+ }
249
+ /** The stored choices, read live (in the caller's transaction when there is one). */
250
+ export async function readStoredDeviceSandbox(db, log, configuredCeiling) {
251
+ return storedOf(await storedRows(db), log, configuredCeiling);
252
+ }
253
+ /** The old platform keys still stored (a write then keeps them in step until they are converted). */
254
+ export async function legacyPlatformKeysStored(db) {
255
+ return [...(await storedRows(db)).keys()].filter((k) => k === LEGACY_DEVICES_FULL_ACCESS_SETTING || k === LEGACY_DEVICES_AUTO_MODE_SETTING);
256
+ }
257
+ /** The value an old platform key stores for `permission` (absent: follow the default). */
258
+ export const legacyPlatformValue = (key, permission) => key === LEGACY_DEVICES_AUTO_MODE_SETTING
259
+ ? permission === undefined
260
+ ? {}
261
+ : { mode: permission }
262
+ : permission === undefined
263
+ ? {}
264
+ : { permission };
265
+ /** The configured network ceiling (it wins over the stored one), or undefined. */
266
+ const configuredCeilingOf = (c) => c.sources.networkCeiling !== undefined ? c.networkCeiling : undefined;
267
+ /**
268
+ * The platform's effective device sandbox settings with their sources, read live from PG at every
269
+ * use (so a change applies on every replica at once): see {@link resolveDeviceSandboxSettings}.
270
+ */
271
+ export async function readDeviceSandboxSettingsView(db, config, log) {
272
+ const configured = configuredDeviceSandbox(config);
273
+ return resolveDeviceSandboxSettings(configured, await readStoredDeviceSandbox(db, log, configuredCeilingOf(configured)));
274
+ }
275
+ /** The platform's effective device sandbox settings (the layer `effectiveDeviceSandbox` takes). */
276
+ export async function readDeviceSandboxSettings(db, config, log) {
277
+ return deviceSandboxSettingsOf(await readDeviceSandboxSettingsView(db, config, log));
278
+ }
279
+ const asObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
280
+ /** JSON with object keys sorted (PG's jsonb reorders them), for comparing stored values. */
281
+ const canonical = (v) => JSON.stringify(v, (_k, x) => x !== null && typeof x === "object" && !Array.isArray(x)
282
+ ? Object.fromEntries(Object.entries(x).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
283
+ : x);
284
+ /** An old org permission value converted: invalid reads as `off`. */
285
+ const legacyOrgPermission = (v) => {
286
+ const parsed = Permission.safeParse(v);
287
+ return parsed.success ? parsed.data : "off";
288
+ };
289
+ /**
290
+ * An org's `outsideSandbox` and `deviceNetwork` read over the new and the old keys (fail closed).
291
+ * `deviceNetwork` present (a `{}` follow marker included) means this version wrote the settings:
292
+ * - absent: the old keys are all there is and convert in full (design, "Migration"):
293
+ * `fullAccess` / `autoMode` -> `outsideSandbox` (invalid: `off`), `cloudNetwork` ->
294
+ * {@link convertLegacyCloudNetwork}, and an old `off` also narrows the ceiling to the allowlist;
295
+ * - present: an old permission written in step ({@link legacyPermissionFor} `outsideSandbox` and
296
+ * the org's own ceiling; the platform's ceiling reaches old replicas through the platform's own
297
+ * old key) and a `cloudNetwork` written in step ({@link legacyCloudNetworkOf}) say nothing more;
298
+ * one that differs (an old replica wrote it) narrows as a conversion would.
299
+ */
300
+ export function orgDeviceSandboxOf(raw) {
301
+ const stored = asObject(raw);
302
+ const parsedOutside = Permission.optional().safeParse(stored.outsideSandbox);
303
+ const current = parsedOutside.success
304
+ ? parsedOutside.data
305
+ : "off";
306
+ const legacy = ["autoMode", "fullAccess"]
307
+ .filter((k) => k in stored)
308
+ .map((k) => legacyOrgPermission(stored[k]));
309
+ const marked = "deviceNetwork" in stored && stored.deviceNetwork !== undefined;
310
+ if (!marked) {
311
+ const outsideSandbox = current === "off" || legacy.includes("off") ? "off" : (current ?? legacy[0]);
312
+ let deviceNetwork = convertLegacyCloudNetwork(stored.cloudNetwork);
313
+ if (legacy.includes("off"))
314
+ deviceNetwork = withAllowlistCeiling(deviceNetwork);
315
+ return {
316
+ ...(outsideSandbox !== undefined && { outsideSandbox }),
317
+ ...(deviceNetwork !== undefined && { deviceNetwork }),
318
+ };
319
+ }
320
+ const parsed = DeviceNetworkSettingSchema.safeParse(stored.deviceNetwork);
321
+ let deviceNetwork = parsed.success
322
+ ? parsed.data
323
+ : invalidDeviceNetwork();
324
+ if (deviceNetwork !== undefined && Object.keys(deviceNetwork).length === 0)
325
+ deviceNetwork = undefined;
326
+ // what the new keys alone would have written in step, before any old key narrows them
327
+ const inStep = legacyPermissionFor(current, deviceNetwork?.ceiling);
328
+ if ("cloudNetwork" in stored &&
329
+ canonical(stored.cloudNetwork) !== canonical(legacyCloudNetworkOf(deviceNetwork)))
330
+ deviceNetwork = narrowerDeviceNetwork(deviceNetwork ?? {}, convertLegacyCloudNetwork(stored.cloudNetwork));
331
+ let outsideSandbox = current;
332
+ for (const value of legacy) {
333
+ if (value === inStep)
334
+ continue;
335
+ if (value === "off") {
336
+ outsideSandbox = "off";
337
+ deviceNetwork = withAllowlistCeiling(deviceNetwork);
338
+ }
339
+ else
340
+ outsideSandbox ??= value;
341
+ }
342
+ return {
343
+ ...(outsideSandbox !== undefined && { outsideSandbox }),
344
+ ...(deviceNetwork !== undefined && { deviceNetwork }),
345
+ };
346
+ }
347
+ /** Whether an org's stored settings still hold an old permission key. */
348
+ export const orgLegacyKeysStored = (raw) => LEGACY_ORG_KEYS.some((k) => k in asObject(raw));
349
+ /**
350
+ * The old org keys written next to the new ones while any of them is still stored (`written` is
351
+ * the settings object about to be stored; `stored` the one it replaces): `fullAccess` / `autoMode`
352
+ * carry {@link legacyPermissionFor} `outsideSandbox` and the org's ceiling, `cloudNetwork` carries
353
+ * {@link legacyCloudNetworkOf} `deviceNetwork`; a value that says nothing removes the old key.
354
+ * `deviceNetwork` cleared is stored as `{}`, the marker that this version wrote the settings.
355
+ */
356
+ export function keepOrgLegacyKeysInStep(written, stored) {
357
+ if (!orgLegacyKeysStored(stored))
358
+ return;
359
+ const outside = written.outsideSandbox;
360
+ const network = written.deviceNetwork;
361
+ const legacy = legacyPermissionFor(outside, network?.ceiling);
362
+ for (const k of ["autoMode", "fullAccess"]) {
363
+ if (!(k in stored))
364
+ continue;
365
+ if (legacy === undefined)
366
+ delete written[k];
367
+ else
368
+ written[k] = legacy;
369
+ }
370
+ if ("cloudNetwork" in stored) {
371
+ const old = legacyCloudNetworkOf(network);
372
+ if (old === undefined)
373
+ delete written.cloudNetwork;
374
+ else
375
+ written.cloudNetwork = old;
376
+ }
377
+ if (network === undefined)
378
+ written.deviceNetwork = {};
379
+ }
380
+ /**
381
+ * Locks the org rows {@link convertStoredPermissionKeys} would convert, in id order, before the
382
+ * caller takes the platform authority write lock: the global lock order puts the org row before
383
+ * the permission authority locks (a fenced prelude holds an org row while it waits for its shared
384
+ * platform lock). The conversion itself then finds its rows already held.
385
+ */
386
+ export async function lockOrgsWithStoredPermissionKeys(db) {
387
+ await db
388
+ .selectFrom("orgs")
389
+ .select("id")
390
+ .where(sql `settings ?| ${sql.val([...LEGACY_ORG_KEYS])}::text[]`)
391
+ .orderBy("id")
392
+ // the conversion updates only `settings`, a non-key column: the org row lock's mode (OrgLock),
393
+ // which leaves foreign key checks against the org (FOR KEY SHARE) unblocked
394
+ .forNoKeyUpdate()
395
+ .execute();
396
+ }
397
+ /**
398
+ * The conversion of the stored permission keys (design, "Migration"), run inside the permission
399
+ * configuration publication transaction under the platform authority write lock (which excludes
400
+ * every org and device writer; the caller locked the org rows to convert before it,
401
+ * {@link lockOrgsWithStoredPermissionKeys}), at every publication: old keys an old replica writes
402
+ * later are converted too. It stores exactly what every reader saw ({@link storedOf},
403
+ * {@link orgDeviceSandboxOf}), never wider, and removes the old keys:
404
+ * - the deployment settings `devicesAutoMode` / `devicesFullAccess` become `devicesOutsideSandbox`
405
+ * and `devicesNetwork` (an empty network removes the row);
406
+ * - every org's `autoMode` / `fullAccess` / `cloudNetwork` become `outsideSandbox` and
407
+ * `deviceNetwork` (absent stays absent: the org follows the platform).
408
+ * Each platform or org whose network an old `off` narrowed to the allowlist is named in one
409
+ * warning, with how to reopen it. Idempotent; never refuses.
410
+ */
411
+ export async function convertStoredPermissionKeys(db, log, context = {}) {
412
+ const rows = await storedRows(db, true);
413
+ const legacy = legacyOf(rows, log);
414
+ if (legacy.length > 0) {
415
+ const converted = storedOf(rows, log, context.configuredCeiling);
416
+ const before = parseStoredDevicesNetwork(rows.get(DEVICES_NETWORK_SETTING));
417
+ const upsert = (key, value) => db
418
+ .insertInto("deployment_settings")
419
+ .values({ key, value: JSON.stringify(value) })
420
+ .onConflict((oc) => oc.column("key").doUpdateSet({ value: JSON.stringify(value) }))
421
+ .execute();
422
+ await upsert(DEVICES_OUTSIDE_SANDBOX_SETTING, converted.outsideSandbox);
423
+ if (Object.keys(converted.network).length > 0)
424
+ await upsert(DEVICES_NETWORK_SETTING, converted.network);
425
+ else
426
+ await db
427
+ .deleteFrom("deployment_settings")
428
+ .where("key", "=", DEVICES_NETWORK_SETTING)
429
+ .execute();
430
+ await db
431
+ .deleteFrom("deployment_settings")
432
+ .where("key", "in", [LEGACY_DEVICES_AUTO_MODE_SETTING, LEGACY_DEVICES_FULL_ACCESS_SETTING])
433
+ .execute();
434
+ if (converted.network.ceiling === "allowlist" && before.ceiling !== "allowlist")
435
+ log?.warn("permission configuration conversion: the platform's old Full access off now keeps every device on the allowlist network (devicesNetwork ceiling allowlist); a super admin reopens it in the admin console settings (devicesNetwork.ceiling open)", { key: DEVICES_NETWORK_SETTING });
436
+ }
437
+ const orgs = await db
438
+ .selectFrom("orgs")
439
+ .select(["id", "settings"])
440
+ .where(sql `settings ?| ${sql.val([...LEGACY_ORG_KEYS])}::text[]`)
441
+ .orderBy("id")
442
+ .forNoKeyUpdate()
443
+ .execute();
444
+ for (const org of orgs) {
445
+ const stored = asObject(org.settings);
446
+ for (const k of ["autoMode", "fullAccess"])
447
+ if (k in stored && !Permission.safeParse(stored[k]).success)
448
+ log?.warn(`org settings: stored ${k} is invalid; it converts to outsideSandbox off`, {
449
+ orgId: org.id,
450
+ });
451
+ const { outsideSandbox, deviceNetwork } = orgDeviceSandboxOf(stored);
452
+ const { autoMode: _a, fullAccess: _f, ...withoutPermission } = stored;
453
+ // the network without the old permission: what an old off narrowed, for the warning
454
+ const was = orgDeviceSandboxOf(withoutPermission).deviceNetwork;
455
+ const { cloudNetwork: _c, outsideSandbox: _o, deviceNetwork: _d, ...rest } = withoutPermission;
456
+ await db
457
+ .updateTable("orgs")
458
+ .set({
459
+ settings: JSON.stringify({
460
+ ...rest,
461
+ ...(outsideSandbox !== undefined && { outsideSandbox }),
462
+ ...(deviceNetwork !== undefined && { deviceNetwork }),
463
+ }),
464
+ })
465
+ .where("id", "=", org.id)
466
+ .execute();
467
+ if (deviceNetwork?.ceiling === "allowlist" && was?.ceiling !== "allowlist")
468
+ log?.warn(`permission configuration conversion: org ${org.id}'s old Full access off now keeps its devices on the allowlist network (deviceNetwork ceiling allowlist); an org admin reopens it in the organization settings (deviceNetwork.ceiling open)`, { orgId: org.id });
469
+ }
470
+ }
@@ -0,0 +1,187 @@
1
+ import type { SandboxBoundary, SandboxPermissionSupport } from "@capybara-hq/plugin-sdk";
2
+ /**
3
+ * The device sandbox (approval-only profiles design, "Settings model"): one pure function computes
4
+ * the effective scope boundary, sandbox network and outside-sandbox ceiling of a device from the
5
+ * platform, org, device and provider layers. The device mirrors it in `intersectOperation`.
6
+ *
7
+ * The settings reader (`device-sandbox-settings.ts`) fills {@link DeviceSandboxSettings}; the
8
+ * permission facts assemble the four layers and read the result for admission, the recorded
9
+ * context and the consent fingerprint.
10
+ */
11
+ /** The sandbox network: the open public internet or an allowlist. `allowlist` is narrower. */
12
+ export type DeviceNetworkMode = "open" | "allowlist";
13
+ /** The layer that set a ceiling, named by a disabled option and an actionable error. */
14
+ export type DeviceSandboxLayer = "platform" | "org" | "device" | "provider";
15
+ /**
16
+ * The platform's device sandbox settings, as the settings reader returns them (env > file / Nacos >
17
+ * the super admin's stored choice > default `allowed`, `open`, `open`).
18
+ */
19
+ export interface DeviceSandboxSettings {
20
+ /** `devices.outsideSandbox`: whether any device may be granted escalation outside the sandbox. */
21
+ outsideSandbox: "allowed" | "off";
22
+ network: {
23
+ /** `devices.network.default`: the mode a device follows when nothing narrower chooses. */
24
+ default: DeviceNetworkMode;
25
+ /** `devices.network.ceiling`: the widest mode an org or device may choose. */
26
+ ceiling: DeviceNetworkMode;
27
+ };
28
+ }
29
+ /** The platform layer: the settings plus the host list and the egress kill switch. */
30
+ export interface DeviceSandboxPlatformLayer {
31
+ settings: DeviceSandboxSettings;
32
+ /** `sandbox.limits.allowHosts`. */
33
+ allowHosts: readonly string[];
34
+ /** `sandbox.limits.orgHosts`: whether an org (and a per-call grant) may go beyond `allowHosts`. */
35
+ orgHosts: "extend" | "within";
36
+ /** `sandbox.limits.egress`: `none` closes every sandbox network (the kill switch). */
37
+ egress: "allowlist" | "none";
38
+ }
39
+ /** The org layer: absent fields follow the platform. */
40
+ export interface DeviceSandboxOrgLayer {
41
+ outsideSandbox?: "allowed" | "off";
42
+ deviceNetwork?: {
43
+ default?: DeviceNetworkMode | undefined;
44
+ ceiling?: DeviceNetworkMode | undefined;
45
+ base?: "platform" | "none" | undefined;
46
+ extraHosts?: readonly string[] | undefined;
47
+ excludedHosts?: readonly string[] | undefined;
48
+ };
49
+ }
50
+ /**
51
+ * The device layer: a local device's owner ceiling (on-disk, reported over the protocol), or a cloud
52
+ * device's stored network choice (`devices.network_mode`, `devices.network_hosts`).
53
+ */
54
+ export type DeviceSandboxDeviceLayer = {
55
+ location: "local";
56
+ outsideSandbox: boolean;
57
+ network: DeviceNetworkMode;
58
+ allowedDomains: readonly string[];
59
+ restrictedProjectReach: "workspace" | "os-user";
60
+ } | {
61
+ location: "cloud";
62
+ /**
63
+ * Null follows the org; `none` is a closed network (a snapshot that ran on an empty or
64
+ * unreadable allowlist). An `allowlist` with no hosts of its own follows its org's hosts.
65
+ */
66
+ networkMode: DeviceNetworkMode | "none" | null;
67
+ networkHosts: readonly string[];
68
+ };
69
+ /** The provider layer: what the runtime reports (support v2) and, for a cloud device, its outer network. */
70
+ export interface DeviceSandboxProviderLayer {
71
+ boundary: SandboxBoundary;
72
+ network: {
73
+ openPublic: boolean;
74
+ allowlist: boolean;
75
+ perOperationHosts: boolean;
76
+ };
77
+ outsideSandbox: boolean;
78
+ }
79
+ /** The effective device sandbox: the same under every permission profile. */
80
+ export interface DeviceSandbox {
81
+ boundary: SandboxBoundary;
82
+ /** The effective mode after every ceiling; `allowlist` with no hosts under the kill switch. */
83
+ networkMode: DeviceNetworkMode | "none";
84
+ /** The narrower of the platform and org ceilings (and the provider's outer network). */
85
+ networkCeiling: DeviceNetworkMode | "none";
86
+ /** The allowlist hosts, empty unless `networkMode` is `allowlist`. */
87
+ hosts: readonly string[];
88
+ /** Whether a call may be granted escalation outside the sandbox. */
89
+ outsideSandbox: boolean;
90
+ restrictedProjectReach: "workspace" | "os-user";
91
+ /** The layer that set each ceiling, or null when nothing narrowed it. */
92
+ layer: {
93
+ network: DeviceSandboxLayer | null;
94
+ outsideSandbox: DeviceSandboxLayer | null;
95
+ };
96
+ }
97
+ /**
98
+ * The hosts of `a` the list `b` covers and the hosts of `b` that `a` covers (wildcards included),
99
+ * lowercased, deduplicated and sorted: never wider than either list.
100
+ */
101
+ export declare function intersectHosts(a: readonly string[], b: readonly string[]): string[];
102
+ /** The org's effective allowlist: the platform's list minus its exclusions, plus its extras. */
103
+ export declare function orgHostsOf(platform: Pick<DeviceSandboxPlatformLayer, "egress" | "allowHosts" | "orgHosts">, org: DeviceSandboxOrgLayer): string[];
104
+ /**
105
+ * Computes the effective device sandbox from its four layers. Pure; no I/O.
106
+ *
107
+ * - `outsideSandbox`: only when the platform, the org, the device owner and the provider all allow
108
+ * it; a cloud device and an instance-boundary provider never do.
109
+ * - The network ceiling is the narrower of the platform's and the org's (and what the provider can
110
+ * enforce); the kill switch closes it (`none`).
111
+ * - The mode is the device's choice (a local owner's network, a cloud device's `network_mode`),
112
+ * else the org default, else the platform default, clamped to the ceiling.
113
+ * - Allowlist hosts are the org's effective hosts, narrowed by the device's own list: a device list
114
+ * never adds a host. A cloud device's empty list adds no narrowing; a local owner's allowlist is
115
+ * the machine's ceiling, so an empty one allows no host (as the device enforces it).
116
+ */
117
+ export declare function effectiveDeviceSandbox(platform: DeviceSandboxPlatformLayer, org: DeviceSandboxOrgLayer, device: DeviceSandboxDeviceLayer, provider: DeviceSandboxProviderLayer): DeviceSandbox;
118
+ /**
119
+ * The provider layer of a device: its recorded runtime report (support v2) when one is current,
120
+ * else what the kernel assumes before the device starts (the device and its provider still
121
+ * enforce, and admission refuses until a report is recorded): a local device runs per operation
122
+ * and may run outside; a cloud device's instance is its sandbox.
123
+ */
124
+ export declare function providerLayerOf(report: SandboxPermissionSupport | null, location: "local" | "cloud"): DeviceSandboxProviderLayer;
125
+ /**
126
+ * The ceiling of a per-call host grant (approval-only profiles design, "Per-call host grant"):
127
+ * `any` (bounded by the kernel only, minus the org's exclusions) or exactly the `hosts` a grant may
128
+ * name.
129
+ * - Nothing on an instance-boundary device (its provider's network covers the whole instance) or
130
+ * on a closed network.
131
+ * - An allowlist network ceiling (platform or org) is a hard ceiling: only the org's effective
132
+ * hosts.
133
+ * - Under an open ceiling, `orgHosts: within` keeps grants within the org's effective hosts (the
134
+ * platform list minus exclusions, or only the extras the platform list covers under `base:
135
+ * none`); `extend` allows any host the org does not exclude.
136
+ * - A local owner's allowlist is the machine's ceiling: intersected with the owner's list, and
137
+ * under an open ceiling still minus the org's exclusions (`excluded`).
138
+ *
139
+ * An excluded entry is a pattern like an allowlist entry (`*.example.com` excludes every
140
+ * subdomain, never the apex): a host is grantable only when no excluded entry covers it.
141
+ */
142
+ export type HostGrantCeiling = {
143
+ kind: "any";
144
+ excluded: readonly string[];
145
+ } | {
146
+ kind: "hosts";
147
+ hosts: readonly string[];
148
+ excluded?: readonly string[];
149
+ };
150
+ export declare function hostGrantCeiling(box: Pick<DeviceSandbox, "boundary" | "networkMode" | "networkCeiling"> & {
151
+ layer?: Pick<DeviceSandbox["layer"], "network">;
152
+ }, platform: Pick<DeviceSandboxPlatformLayer, "egress" | "allowHosts" | "orgHosts">, org: DeviceSandboxOrgLayer, owner: {
153
+ network: DeviceNetworkMode;
154
+ allowedDomains: readonly string[];
155
+ } | null): HostGrantCeiling;
156
+ /** Whether a per-call grant may name `host` under `ceiling`. */
157
+ export declare function hostGrantable(ceiling: HostGrantCeiling, host: string): boolean;
158
+ /** A canonical form of a ceiling (sorted, deduplicated, lowercased) for the consent fingerprint. */
159
+ export declare function canonicalHostCeiling(ceiling: HostGrantCeiling): HostGrantCeiling;
160
+ /**
161
+ * Why a per-call grant for `host` is unavailable on this device, naming who can add it, or null
162
+ * when the grant ceiling covers it ({@link hostGrantCeiling}). The org's and platform's layers are
163
+ * named first: the machine's owner can widen only within them.
164
+ */
165
+ export declare function hostGrantRefusal(host: string, box: Pick<DeviceSandbox, "boundary" | "networkMode" | "networkCeiling"> & {
166
+ layer?: Pick<DeviceSandbox["layer"], "network">;
167
+ }, platform: Pick<DeviceSandboxPlatformLayer, "egress" | "allowHosts" | "orgHosts">, org: DeviceSandboxOrgLayer, owner: {
168
+ network: DeviceNetworkMode;
169
+ allowedDomains: readonly string[];
170
+ } | null): string | null;
171
+ /**
172
+ * The crossing ceilings a Full access consent covers (approval-only profiles design, "Consent
173
+ * fingerprint"): running outside, the network ceiling and mode, the project reach and the per-call
174
+ * host ceiling.
175
+ */
176
+ export interface ConsentReach {
177
+ outsideSandbox: boolean;
178
+ networkCeiling: DeviceNetworkMode | "none";
179
+ networkMode: DeviceNetworkMode | "none";
180
+ restrictedProjectReach: "workspace" | "os-user";
181
+ hostCeiling: HostGrantCeiling;
182
+ }
183
+ /**
184
+ * Whether `now` is within `consented` in every dimension: a narrowing keeps the consent, a widening
185
+ * of any dimension needs a new one (Full access would otherwise auto-approve more).
186
+ */
187
+ export declare function reachWithin(now: ConsentReach, consented: ConsentReach): boolean;