@capybara-hq/kernel 0.1.0-rc.54 → 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 (154) 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 +11 -1
  15. package/dist/config/schema.js +37 -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 +8 -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 +24 -19
  35. package/dist/errors.js +24 -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/identity/settings.d.ts +45 -18
  44. package/dist/identity/settings.js +151 -51
  45. package/dist/infra/config/kernel-config.service.d.ts +1 -1
  46. package/dist/infra/config/kernel-config.service.js +17 -5
  47. package/dist/local-devices/device-auth.controller.d.ts +1 -1
  48. package/dist/local-devices/device-auth.controller.js +1 -1
  49. package/dist/local-devices/device-auth.d.ts +4 -4
  50. package/dist/local-devices/device-auth.js +1 -1
  51. package/dist/local-devices/device-policy.service.d.ts +18 -9
  52. package/dist/local-devices/device-policy.service.js +21 -61
  53. package/dist/local-devices/device-routes.d.ts +3 -1
  54. package/dist/local-devices/device-routes.js +15 -4
  55. package/dist/local-devices/instance-bindings.js +5 -2
  56. package/dist/local-devices/local-device-gateway.d.ts +2 -2
  57. package/dist/local-devices/local-device-gateway.js +3 -3
  58. package/dist/local-devices/local-device-provider.d.ts +4 -4
  59. package/dist/local-devices/local-device-provider.js +23 -9
  60. package/dist/local-devices/local-devices.module.d.ts +1 -1
  61. package/dist/local-devices/local-devices.module.js +1 -1
  62. package/dist/local-devices/machines.d.ts +40 -16
  63. package/dist/local-devices/machines.js +89 -61
  64. package/dist/local-devices/owner-report.d.ts +16 -14
  65. package/dist/local-devices/owner-report.js +24 -30
  66. package/dist/local-devices/owner-reports.js +26 -8
  67. package/dist/local-devices/policy-summary.d.ts +25 -44
  68. package/dist/local-devices/policy-summary.js +26 -71
  69. package/dist/local-devices/relay.d.ts +6 -6
  70. package/dist/local-devices/relay.js +10 -8
  71. package/dist/net/public-address.d.ts +1 -1
  72. package/dist/net/public-address.js +5 -2
  73. package/dist/orgs/device-network-setting.d.ts +82 -0
  74. package/dist/orgs/device-network-setting.js +142 -0
  75. package/dist/orgs/settings.service.d.ts +103 -66
  76. package/dist/orgs/settings.service.js +201 -137
  77. package/dist/overrides.d.ts +5 -1
  78. package/dist/overrides.js +2 -0
  79. package/dist/platform/exclusions.js +1 -1
  80. package/dist/platform/operation.js +1 -1
  81. package/dist/platform/ops/admin.ops.js +20 -11
  82. package/dist/platform/ops/devices.ops.js +70 -5
  83. package/dist/platform/ops/org-settings.ops.js +10 -6
  84. package/dist/platform/ops/orgs.ops.js +2 -1
  85. package/dist/runtime/context/permission-profile.d.ts +17 -8
  86. package/dist/runtime/context/permission-profile.js +126 -45
  87. package/dist/runtime/permission-context.service.d.ts +1 -1
  88. package/dist/runtime/permission-context.service.js +5 -3
  89. package/dist/runtime/project/knowledge.d.ts +5 -4
  90. package/dist/runtime/project/knowledge.js +2 -1
  91. package/dist/runtime/project/knowledge.service.js +16 -13
  92. package/dist/sandbox/cloud-permission-snapshot.js +22 -3
  93. package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
  94. package/dist/sandbox/device-sandbox-settings.js +470 -0
  95. package/dist/sandbox/device-sandbox.d.ts +187 -0
  96. package/dist/sandbox/device-sandbox.js +236 -0
  97. package/dist/sandbox/held-operations.js +15 -7
  98. package/dist/sandbox/modes.d.ts +49 -24
  99. package/dist/sandbox/modes.js +27 -19
  100. package/dist/sandbox/operation-authority-types.d.ts +6 -5
  101. package/dist/sandbox/operation-authority-types.js +7 -8
  102. package/dist/sandbox/operation-authority.d.ts +23 -9
  103. package/dist/sandbox/operation-authority.js +179 -97
  104. package/dist/sandbox/permission-auto-grants.d.ts +42 -0
  105. package/dist/sandbox/permission-auto-grants.js +145 -0
  106. package/dist/sandbox/permission-call-grants.d.ts +12 -4
  107. package/dist/sandbox/permission-call-grants.js +84 -35
  108. package/dist/sandbox/permission-call-grants.module.js +10 -3
  109. package/dist/sandbox/permission-call-types.d.ts +39 -5
  110. package/dist/sandbox/permission-ceiling-writes.d.ts +29 -3
  111. package/dist/sandbox/permission-ceiling-writes.js +38 -4
  112. package/dist/sandbox/permission-config-publication.d.ts +44 -2
  113. package/dist/sandbox/permission-config-publication.js +230 -59
  114. package/dist/sandbox/permission-context-types.d.ts +2 -2
  115. package/dist/sandbox/permission-facts.d.ts +144 -15
  116. package/dist/sandbox/permission-facts.js +258 -70
  117. package/dist/sandbox/permission-runtime-reports.d.ts +5 -4
  118. package/dist/sandbox/permission-runtime-reports.js +19 -29
  119. package/dist/sandbox/review/classifier.d.ts +8 -0
  120. package/dist/sandbox/review/classifier.js +10 -0
  121. package/dist/sandbox/review/permission-candidate.d.ts +69 -5
  122. package/dist/sandbox/review/permission-candidate.js +153 -30
  123. package/dist/sandbox/review/review.service.d.ts +19 -3
  124. package/dist/sandbox/review/review.service.js +59 -11
  125. package/dist/sandbox/review/rules.js +23 -3
  126. package/dist/sandbox/sandbox.service.d.ts +29 -11
  127. package/dist/sandbox/sandbox.service.js +51 -26
  128. package/dist/skills/invoke.js +3 -2
  129. package/dist/tools/approvals.service.d.ts +26 -116
  130. package/dist/tools/approvals.service.js +42 -346
  131. package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
  132. package/dist/tools/builtins/sandbox/bash.js +80 -28
  133. package/dist/tools/builtins/sandbox/common.d.ts +39 -14
  134. package/dist/tools/builtins/sandbox/common.js +47 -24
  135. package/dist/tools/builtins/sandbox/deliver.js +7 -4
  136. package/dist/tools/builtins/skill-load.d.ts +2 -2
  137. package/dist/tools/builtins/skill-load.js +4 -3
  138. package/dist/tools/device-op-resolver.d.ts +4 -10
  139. package/dist/tools/device-op-resolver.js +8 -19
  140. package/dist/tools/network-asks.d.ts +52 -15
  141. package/dist/tools/network-asks.js +55 -25
  142. package/dist/tools/pipeline.d.ts +26 -14
  143. package/dist/tools/pipeline.js +144 -61
  144. package/dist/tools/registry.d.ts +6 -0
  145. package/dist/tools/tools.module.js +1 -1
  146. package/package.json +4 -4
  147. package/src/migrations/0165_device_network_columns.sql +50 -0
  148. package/src/migrations/0166_permission_grant_full_access.sql +17 -0
  149. package/src/migrations/0167_device_network_backfill.sql +32 -0
  150. package/src/migrations/0168_binding_installed_connection.sql +6 -0
  151. package/dist/orgs/cloud-network-setting.d.ts +0 -33
  152. package/dist/orgs/cloud-network-setting.js +0 -47
  153. package/dist/sandbox/platform-full-access.d.ts +0 -110
  154. package/dist/sandbox/platform-full-access.js +0 -198
@@ -84,10 +84,6 @@ export declare const projectUnavailable: {
84
84
  reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
85
85
  message: string;
86
86
  };
87
- readonly widerMode: (root: string) => {
88
- reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
89
- message: string;
90
- };
91
87
  readonly removed: (project: string) => {
92
88
  reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
93
89
  message: string;
@@ -97,6 +93,11 @@ export declare const projectUnavailable: {
97
93
  reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
98
94
  message: string;
99
95
  };
96
+ /** A device runtime that refused the kernel's read-only read scope (its text is logged). */
97
+ readonly refused: (root: string) => {
98
+ reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
99
+ message: string;
100
+ };
100
101
  readonly unsupported: () => {
101
102
  reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
102
103
  message: string;
@@ -41,10 +41,11 @@ export const projectUnavailable = {
41
41
  notDirectory: (root) => unavailable("unreadable", `The project's root ${clipped(root)} is not a directory.`),
42
42
  /** The device's own error text is logged, never recorded: the message stays the same per root. */
43
43
  unreadable: (root) => unavailable("unreadable", `The project's root ${clipped(root)} could not be read.`),
44
- widerMode: (root) => unavailable("outside_mode", `The project's root ${clipped(root)} was not read: the device runs a wider mode than the organization allows.`),
45
44
  removed: (project) => unavailable("removed", `The project "${clipped(project, 80)}" was removed from the device's projects.`),
46
45
  /** A host machine whose runtime cannot enforce the kernel's read-only read (gate on). */
47
46
  notEnforceable: (root) => unavailable("unreadable", `The project's root ${clipped(root)} was not read: this device's runtime cannot enforce a read-only read on its host; turn on its sandbox enforcement or use another device.`),
47
+ /** A device runtime that refused the kernel's read-only read scope (its text is logged). */
48
+ refused: (root) => unavailable("unreadable", `The project's root ${clipped(root)} was not read: this device's runtime refused the kernel's read-only read.`),
48
49
  unsupported: () => unavailable("unsupported", "The device does not offer projects; capybara-device on that machine needs an update."),
49
50
  };
50
51
  /** The snapshot of a project the run cannot use: the reason alone, no AGENTS.md, no skills. */
@@ -7,11 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { DeviceProtocolError } from "@capybara-hq/plugin-sdk";
10
+ import { DeviceProtocolError, isSandboxPermissionUnsupportedError } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable, Optional } from "@nestjs/common";
12
12
  import { EventLog } from "../../conversations/event-log.js";
13
13
  import { ConversationDevices } from "../../devices/conversation-devices.js";
14
- import { DeviceProjectsService, readModeOf, withinMode, } from "../../devices/device-projects.service.js";
14
+ import { DeviceProjectsService, withinMode } from "../../devices/device-projects.service.js";
15
15
  import { aboveHome } from "../../devices/working-root.js";
16
16
  import { ApiError } from "../../errors.js";
17
17
  import { KernelDb } from "../../infra/database/kernel-db.js";
@@ -194,15 +194,6 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
194
194
  });
195
195
  return unavailableProject(bound.project, bound.root, projectUnavailable.unsupported());
196
196
  }
197
- // A machine reporting a wider mode than the org allows is not read unasked. The local
198
- // provider rechecks the current ceiling on every readFile / stat request as well.
199
- if (scope.widerThanAllowed) {
200
- this.log.warn("project knowledge not read: the device runs a wider mode than allowed", {
201
- ...where,
202
- deviceId,
203
- });
204
- return unavailableProject(bound.project, bound.root, projectUnavailable.widerMode(bound.root));
205
- }
206
197
  const enter = await this.entry(input, bound.accountId, bound.root);
207
198
  return await enter({
208
199
  orgId: input.orgId,
@@ -231,16 +222,28 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
231
222
  stat: (path) => p.stat(h, path, sig),
232
223
  readFile: (path, maxBytes) => p.readFile(h, path, { maxBytes, signal: sig }),
233
224
  ...(list !== undefined && {
234
- list: (path, limit) => list.call(p, h, path, { limit, limits: { mode: readModeOf(scope) }, signal: sig }),
225
+ list: (path, limit) => list.call(p, h, path, { limit, signal: sig }),
235
226
  }),
236
227
  };
237
228
  try {
238
229
  return await readProjectKnowledge(files, target, {
239
230
  log: (msg, detail) => this.log.info(msg, { ...where, ...detail }),
240
- isDeviceFailure: (e) => sig.aborted || isDeviceFailure(e),
231
+ // a runtime refusing the read's scope refuses every read of it: thrown, so no
232
+ // half-read snapshot is recorded
233
+ isDeviceFailure: (e) => sig.aborted || isDeviceFailure(e) || isSandboxPermissionUnsupportedError(e),
241
234
  });
242
235
  }
243
236
  catch (e) {
237
+ // the device's runtime refused the kernel read's scope: the project is recorded
238
+ // unreadable (the provider's text is logged, never recorded) and the run goes on
239
+ if (isSandboxPermissionUnsupportedError(e) && !sig.aborted) {
240
+ this.log.warn("project knowledge not read: the device refused the read's scope", {
241
+ ...where,
242
+ deviceId,
243
+ reason: e.message,
244
+ });
245
+ return unavailableProject(bound.project, bound.root, projectUnavailable.refused(bound.root));
246
+ }
244
247
  // gate on: a host runtime without restricted enforcement gets no kernel read; the
245
248
  // project is recorded unreadable with the reason and the run goes on
246
249
  if (!(e instanceof KernelReadUnsupported))
@@ -227,6 +227,9 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
227
227
  .set({
228
228
  owner_full_access: snap.fullAccess,
229
229
  outer_network: JSON.stringify(snap.outerNetwork),
230
+ // the device's own sandbox network carries an allowlist snapshot (never wider): the
231
+ // device sandbox reads it, not `outer_network`
232
+ ...(device.network_mode === null && ownNetworkOf(snap.outerNetwork)),
230
233
  permission_migration: JSON.stringify({
231
234
  from: "auto-mode",
232
235
  old: { mode: old.mode, network: old.network },
@@ -257,9 +260,10 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
257
260
  return !snap.fullAccess;
258
261
  if (outer.kind !== "allowlist" || !("network" in scope) || !isExecutionMethod(row.method))
259
262
  return false;
260
- // an execution outside any allowlist (environment networking) is wider than the outer
261
- // allowlist; `none` is narrower; an allowlist must be covered host by host
262
- if (scope.network.kind === "environment")
263
+ // an execution outside any allowlist (environment networking, the open public network)
264
+ // is wider than the outer allowlist; `none` is narrower; an allowlist must be covered
265
+ // host by host
266
+ if (scope.network.kind === "environment" || scope.network.kind === "open-public")
263
267
  return true;
264
268
  if (scope.network.kind !== "allowlist")
265
269
  return false;
@@ -303,6 +307,8 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
303
307
  .set({
304
308
  owner_full_access: narrowed.fullAccess,
305
309
  outer_network: JSON.stringify(narrowed.outerNetwork),
310
+ // a narrower instance narrows the device's own network choice too
311
+ ...ownNetworkOf(narrowed.outerNetwork),
306
312
  })
307
313
  .where("id", "=", deviceId)
308
314
  .execute();
@@ -354,6 +360,7 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
354
360
  "mode",
355
361
  "owner_full_access",
356
362
  "outer_network",
363
+ "network_mode",
357
364
  "permission_reconcile_required",
358
365
  "deleted_at",
359
366
  ])
@@ -405,3 +412,15 @@ CloudPermissionSnapshots = __decorate([
405
412
  __param(9, Inject(SandboxProviders))
406
413
  ], CloudPermissionSnapshots);
407
414
  export { CloudPermissionSnapshots };
415
+ /**
416
+ * The device's own sandbox network columns for an allowlist snapshot, as migrations 0165 and 0167
417
+ * copy them: its hosts as an allowlist, or `none` (closed) for an empty one; nothing for an open
418
+ * one, which follows the org.
419
+ */
420
+ function ownNetworkOf(outer) {
421
+ if (outer.kind !== "allowlist")
422
+ return {};
423
+ return outer.hosts.length === 0
424
+ ? { network_mode: "none", network_hosts: "[]" }
425
+ : { network_mode: "allowlist", network_hosts: JSON.stringify([...outer.hosts]) };
426
+ }
@@ -0,0 +1,230 @@
1
+ import { z } from "zod";
2
+ import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
+ import type { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
+ import type { KernelLogger } from "../log.js";
5
+ import { type DeviceNetworkSetting } from "../orgs/device-network-setting.js";
6
+ import type { DeviceNetworkMode, DeviceSandboxSettings } from "./device-sandbox.js";
7
+ /**
8
+ * The platform's device sandbox settings (approval-only profiles design, "Settings model"): the
9
+ * outside-sandbox ceiling (`devices.outsideSandbox`) and the sandbox network's default and ceiling
10
+ * (`devices.network.default`, `devices.network.ceiling`). Each is both a startup config field and
11
+ * a deployment setting ({@link DEVICES_OUTSIDE_SANDBOX_SETTING}, {@link DEVICES_NETWORK_SETTING}),
12
+ * read live at every use: environment > config file / Nacos > the super admin's choice in the admin
13
+ * console > {@link DEVICE_SANDBOX_DEFAULTS}. A field set in the startup config is read-only in the
14
+ * admin console. An invalid stored value reads narrower with a warning (fail closed): `off`, and
15
+ * the allowlist.
16
+ *
17
+ * Before 0.1.0 the old keys are converted, never aliased: the deployment settings
18
+ * `devicesFullAccess` and `devicesAutoMode` and the org keys `fullAccess`, `autoMode` and
19
+ * `cloudNetwork` are read (the narrower wins) until the permission configuration publication
20
+ * converts them ({@link convertStoredPermissionKeys}); writes keep a still stored old key in step
21
+ * for replicas of the previous version. An old `off` kept every device on the allowlist, so it
22
+ * converts to `outsideSandbox: off` plus an allowlist network ceiling (never wider).
23
+ */
24
+ export type OutsideSandboxPermission = "allowed" | "off";
25
+ /** The `deployment_settings` key of the super admin's outside-sandbox choice. */
26
+ export declare const DEVICES_OUTSIDE_SANDBOX_SETTING = "devicesOutsideSandbox";
27
+ /** The `deployment_settings` key of the super admin's network choice. */
28
+ export declare const DEVICES_NETWORK_SETTING = "devicesNetwork";
29
+ /** The old key of the outside-sandbox choice (B1's Full switch), read only to convert it. */
30
+ export declare const LEGACY_DEVICES_FULL_ACCESS_SETTING = "devicesFullAccess";
31
+ /** The key B1 converted (the auto-mode switch), read only to convert it. */
32
+ export declare const LEGACY_DEVICES_AUTO_MODE_SETTING = "devicesAutoMode";
33
+ /** What a deployment with neither the startup config nor the stored choice says. */
34
+ export declare const DEVICE_SANDBOX_DEFAULTS: DeviceSandboxSettings;
35
+ /** The stored outside-sandbox choice: `permission` absent follows the default. */
36
+ export declare const DevicesOutsideSandboxStoredSchema: z.ZodObject<{
37
+ permission: z.ZodOptional<z.ZodEnum<{
38
+ allowed: "allowed";
39
+ off: "off";
40
+ }>>;
41
+ }, z.core.$strict>;
42
+ export type DevicesOutsideSandboxStored = z.infer<typeof DevicesOutsideSandboxStoredSchema>;
43
+ /** The stored network choice: a field absent follows the default. */
44
+ export declare const DevicesNetworkStoredSchema: z.ZodObject<{
45
+ default: z.ZodOptional<z.ZodEnum<{
46
+ allowlist: "allowlist";
47
+ open: "open";
48
+ }>>;
49
+ ceiling: z.ZodOptional<z.ZodEnum<{
50
+ allowlist: "allowlist";
51
+ open: "open";
52
+ }>>;
53
+ }, z.core.$strict>;
54
+ export type DevicesNetworkStored = z.infer<typeof DevicesNetworkStoredSchema>;
55
+ /** Both stored choices. */
56
+ export interface StoredDeviceSandbox {
57
+ outsideSandbox: DevicesOutsideSandboxStored;
58
+ network: DevicesNetworkStored;
59
+ }
60
+ /**
61
+ * A change of the stored outside-sandbox choice (`PUT /api/v1/admin/settings`
62
+ * `devicesOutsideSandbox`): `permission: null` clears it, back to the default `allowed`.
63
+ */
64
+ export declare const DEVICES_OUTSIDE_SANDBOX_PATCH: z.ZodObject<{
65
+ permission: z.ZodNullable<z.ZodEnum<{
66
+ allowed: "allowed";
67
+ off: "off";
68
+ }>>;
69
+ }, z.core.$strict>;
70
+ export type DevicesOutsideSandboxPatch = z.infer<typeof DEVICES_OUTSIDE_SANDBOX_PATCH>;
71
+ /**
72
+ * A change of the stored network choice (`devicesNetwork`): each given field replaces the stored
73
+ * one, null clears it (back to the default `open`); at least one field.
74
+ */
75
+ export declare const DEVICES_NETWORK_PATCH: z.ZodObject<{
76
+ default: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
77
+ allowlist: "allowlist";
78
+ open: "open";
79
+ }>>>;
80
+ ceiling: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
81
+ allowlist: "allowlist";
82
+ open: "open";
83
+ }>>>;
84
+ }, z.core.$strict>;
85
+ export type DevicesNetworkPatch = z.infer<typeof DEVICES_NETWORK_PATCH>;
86
+ /** Where an effective value comes from. */
87
+ export type DeviceSandboxSource = "env" | "file" | "nacos" | "db" | "default";
88
+ type ConfigSource = Exclude<DeviceSandboxSource, "db" | "default">;
89
+ /** The admin console's view of the outside-sandbox ceiling. */
90
+ export interface DevicesOutsideSandboxView {
91
+ permission: OutsideSandboxPermission;
92
+ source: DeviceSandboxSource;
93
+ }
94
+ /** The admin console's view of the network: effective values (the default within the ceiling). */
95
+ export interface DevicesNetworkView {
96
+ default: DeviceNetworkMode;
97
+ ceiling: DeviceNetworkMode;
98
+ sources: {
99
+ default: DeviceSandboxSource;
100
+ ceiling: DeviceSandboxSource;
101
+ };
102
+ }
103
+ export interface DeviceSandboxSettingsView {
104
+ outsideSandbox: DevicesOutsideSandboxView;
105
+ network: DevicesNetworkView;
106
+ }
107
+ /** The startup config's values and where each comes from (undefined: not set there). */
108
+ export interface ConfiguredDeviceSandbox {
109
+ outsideSandbox?: OutsideSandboxPermission | undefined;
110
+ networkDefault?: DeviceNetworkMode | undefined;
111
+ networkCeiling?: DeviceNetworkMode | undefined;
112
+ sources: {
113
+ outsideSandbox?: ConfigSource | undefined;
114
+ networkDefault?: ConfigSource | undefined;
115
+ networkCeiling?: ConfigSource | undefined;
116
+ };
117
+ }
118
+ /**
119
+ * Parses a stored outside-sandbox choice: missing -> `{}`; invalid -> `{ permission: "off" }` with
120
+ * a warning, narrower, never wider.
121
+ */
122
+ export declare function parseStoredDevicesOutsideSandbox(value: unknown, log?: Pick<KernelLogger, "warn">): DevicesOutsideSandboxStored;
123
+ /**
124
+ * Parses a stored network choice: missing -> `{}`; invalid -> the allowlist for both with a
125
+ * warning, narrower, never wider.
126
+ */
127
+ export declare function parseStoredDevicesNetwork(value: unknown, log?: Pick<KernelLogger, "warn">): DevicesNetworkStored;
128
+ /**
129
+ * Converts a stored old `devicesFullAccess` (`{ permission }`): the same permission, and an `off`
130
+ * also limits the network ceiling to the allowlist; an invalid value converts to `off` with a
131
+ * warning, never absent.
132
+ */
133
+ export declare function parseLegacyStoredDevicesFullAccess(value: unknown, log?: Pick<KernelLogger, "warn">): StoredDeviceSandbox;
134
+ /** Converts a stored old `devicesAutoMode` (`{ mode }`) like {@link parseLegacyStoredDevicesFullAccess}. */
135
+ export declare function parseLegacyStoredDevicesAutoMode(value: unknown, log?: Pick<KernelLogger, "warn">): StoredDeviceSandbox;
136
+ /** The stored outside-sandbox choice with `patch` applied (`permission: null` clears it). */
137
+ export declare function applyDevicesOutsideSandboxPatch(_stored: DevicesOutsideSandboxStored, patch: DevicesOutsideSandboxPatch): DevicesOutsideSandboxStored;
138
+ /** The stored network choice with `patch` applied (a null field clears it). */
139
+ export declare function applyDevicesNetworkPatch(stored: DevicesNetworkStored, patch: DevicesNetworkPatch): DevicesNetworkStored;
140
+ /**
141
+ * The narrower of two stored choices, field by field: `off` / `allowlist` when either says so;
142
+ * otherwise `a`'s value, else `b`'s (an absent value follows the default, the widest, so `allowed`
143
+ * or `open` over absent says the same and is kept, as a conversion must be exact).
144
+ */
145
+ export declare function narrowerStoredDeviceSandbox(a: StoredDeviceSandbox, b: StoredDeviceSandbox): StoredDeviceSandbox;
146
+ /**
147
+ * The effective settings and their sources, pure (the reader below adds the database read). The
148
+ * startup config fields are optional with no schema default, so a defined value with a source
149
+ * means the config sets it: it wins over the stored choice. The effective default never exceeds
150
+ * the effective ceiling (the narrower of the two is shown and applied).
151
+ */
152
+ export declare function resolveDeviceSandboxSettings(configured: ConfiguredDeviceSandbox, stored: StoredDeviceSandbox): DeviceSandboxSettingsView;
153
+ /** The plain settings of a view. */
154
+ export declare const deviceSandboxSettingsOf: (view: DeviceSandboxSettingsView) => DeviceSandboxSettings;
155
+ /** The startup config's values and sources. */
156
+ export declare function configuredDeviceSandbox(config: Pick<KernelConfigService, "get" | "fieldSource">): ConfiguredDeviceSandbox;
157
+ /**
158
+ * The old permission value written next to the new keys for replicas of the previous version
159
+ * (their Full switch): `allowed` only when running outside the sandbox is allowed AND the network
160
+ * ceiling is open, else `off`, so an old replica never reads Full where a new one keeps devices on
161
+ * the allowlist. `outside` absent with an open ceiling stays absent (follow the default).
162
+ */
163
+ export declare function legacyPermissionFor(outside: OutsideSandboxPermission | undefined, ceiling: DeviceNetworkMode | undefined): OutsideSandboxPermission | undefined;
164
+ /** The stored choices, read live (in the caller's transaction when there is one). */
165
+ export declare function readStoredDeviceSandbox(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">, configuredCeiling?: DeviceNetworkMode): Promise<StoredDeviceSandbox>;
166
+ /** The old platform keys still stored (a write then keeps them in step until they are converted). */
167
+ export declare function legacyPlatformKeysStored(db: KernelSchemaDb): Promise<string[]>;
168
+ /** The value an old platform key stores for `permission` (absent: follow the default). */
169
+ export declare const legacyPlatformValue: (key: string, permission: OutsideSandboxPermission | undefined) => unknown;
170
+ /**
171
+ * The platform's effective device sandbox settings with their sources, read live from PG at every
172
+ * use (so a change applies on every replica at once): see {@link resolveDeviceSandboxSettings}.
173
+ */
174
+ export declare function readDeviceSandboxSettingsView(db: KernelSchemaDb, config: Pick<KernelConfigService, "get" | "fieldSource">, log?: Pick<KernelLogger, "warn">): Promise<DeviceSandboxSettingsView>;
175
+ /** The platform's effective device sandbox settings (the layer `effectiveDeviceSandbox` takes). */
176
+ export declare function readDeviceSandboxSettings(db: KernelSchemaDb, config: Pick<KernelConfigService, "get" | "fieldSource">, log?: Pick<KernelLogger, "warn">): Promise<DeviceSandboxSettings>;
177
+ /** An org's stored device sandbox keys, as every reader sees them. */
178
+ export interface OrgDeviceSandboxStored {
179
+ outsideSandbox?: OutsideSandboxPermission | undefined;
180
+ deviceNetwork?: DeviceNetworkSetting | undefined;
181
+ }
182
+ /**
183
+ * An org's `outsideSandbox` and `deviceNetwork` read over the new and the old keys (fail closed).
184
+ * `deviceNetwork` present (a `{}` follow marker included) means this version wrote the settings:
185
+ * - absent: the old keys are all there is and convert in full (design, "Migration"):
186
+ * `fullAccess` / `autoMode` -> `outsideSandbox` (invalid: `off`), `cloudNetwork` ->
187
+ * {@link convertLegacyCloudNetwork}, and an old `off` also narrows the ceiling to the allowlist;
188
+ * - present: an old permission written in step ({@link legacyPermissionFor} `outsideSandbox` and
189
+ * the org's own ceiling; the platform's ceiling reaches old replicas through the platform's own
190
+ * old key) and a `cloudNetwork` written in step ({@link legacyCloudNetworkOf}) say nothing more;
191
+ * one that differs (an old replica wrote it) narrows as a conversion would.
192
+ */
193
+ export declare function orgDeviceSandboxOf(raw: unknown): OrgDeviceSandboxStored;
194
+ /** Whether an org's stored settings still hold an old permission key. */
195
+ export declare const orgLegacyKeysStored: (raw: unknown) => boolean;
196
+ /**
197
+ * The old org keys written next to the new ones while any of them is still stored (`written` is
198
+ * the settings object about to be stored; `stored` the one it replaces): `fullAccess` / `autoMode`
199
+ * carry {@link legacyPermissionFor} `outsideSandbox` and the org's ceiling, `cloudNetwork` carries
200
+ * {@link legacyCloudNetworkOf} `deviceNetwork`; a value that says nothing removes the old key.
201
+ * `deviceNetwork` cleared is stored as `{}`, the marker that this version wrote the settings.
202
+ */
203
+ export declare function keepOrgLegacyKeysInStep(written: Record<string, unknown>, stored: Record<string, unknown>): void;
204
+ /**
205
+ * Locks the org rows {@link convertStoredPermissionKeys} would convert, in id order, before the
206
+ * caller takes the platform authority write lock: the global lock order puts the org row before
207
+ * the permission authority locks (a fenced prelude holds an org row while it waits for its shared
208
+ * platform lock). The conversion itself then finds its rows already held.
209
+ */
210
+ export declare function lockOrgsWithStoredPermissionKeys(db: KernelSchemaDb): Promise<void>;
211
+ /** What the conversion needs of the startup config: the configured network ceiling. */
212
+ export interface PermissionKeyConversionContext {
213
+ configuredCeiling?: DeviceNetworkMode | undefined;
214
+ }
215
+ /**
216
+ * The conversion of the stored permission keys (design, "Migration"), run inside the permission
217
+ * configuration publication transaction under the platform authority write lock (which excludes
218
+ * every org and device writer; the caller locked the org rows to convert before it,
219
+ * {@link lockOrgsWithStoredPermissionKeys}), at every publication: old keys an old replica writes
220
+ * later are converted too. It stores exactly what every reader saw ({@link storedOf},
221
+ * {@link orgDeviceSandboxOf}), never wider, and removes the old keys:
222
+ * - the deployment settings `devicesAutoMode` / `devicesFullAccess` become `devicesOutsideSandbox`
223
+ * and `devicesNetwork` (an empty network removes the row);
224
+ * - every org's `autoMode` / `fullAccess` / `cloudNetwork` become `outsideSandbox` and
225
+ * `deviceNetwork` (absent stays absent: the org follows the platform).
226
+ * Each platform or org whose network an old `off` narrowed to the allowlist is named in one
227
+ * warning, with how to reopen it. Idempotent; never refuses.
228
+ */
229
+ export declare function convertStoredPermissionKeys(db: KernelSchemaDb, log?: Pick<KernelLogger, "warn">, context?: PermissionKeyConversionContext): Promise<void>;
230
+ export {};