@capybara-hq/kernel 0.1.0-rc.54 → 0.1.0-rc.56

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 (156) 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/dist/ui/views.d.ts +3 -1
  147. package/dist/ui/views.js +2 -1
  148. package/package.json +4 -4
  149. package/src/migrations/0165_device_network_columns.sql +50 -0
  150. package/src/migrations/0166_permission_grant_full_access.sql +17 -0
  151. package/src/migrations/0167_device_network_backfill.sql +32 -0
  152. package/src/migrations/0168_binding_installed_connection.sql +6 -0
  153. package/dist/orgs/cloud-network-setting.d.ts +0 -33
  154. package/dist/orgs/cloud-network-setting.js +0 -47
  155. package/dist/sandbox/platform-full-access.d.ts +0 -110
  156. package/dist/sandbox/platform-full-access.js +0 -198
@@ -1,4 +1,6 @@
1
- import type { DeviceLocalPolicySummary, LocalizedName, SandboxLimits } from "@capybara-hq/plugin-sdk";
1
+ import type { DeviceLocalPolicySummary, LocalizedName, SandboxBrowseScope, SandboxLimits, SandboxOperationScope } from "@capybara-hq/plugin-sdk";
2
+ import { type Selectable } from "kysely";
3
+ import type { SandboxOperationIntentsTable } from "../db/kernel-schema.js";
2
4
  import { ExtensionDisplayNames } from "../extensions/display-name.js";
3
5
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
6
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -7,10 +9,12 @@ import { LockService } from "../infra/lock/lock.service.js";
7
9
  import { OutboxService } from "../infra/outbox/outbox.service.js";
8
10
  import { DevicePolicyService } from "../local-devices/device-policy.service.js";
9
11
  import { MachinesService } from "../local-devices/machines.js";
12
+ import { type OwnerFacts } from "../local-devices/owner-report.js";
10
13
  import type { DeviceModeLevel } from "../runtime/context/device-paths.js";
14
+ import type { DeviceSandbox, DeviceSandboxLayer, HostGrantCeiling } from "../sandbox/device-sandbox.js";
11
15
  import { SandboxJobs } from "../sandbox/jobs.js";
12
- import { type DeviceNetwork, type EffectiveDevicePolicy, type NetworkKind, type OrgDeviceSettings, type SandboxMode } from "../sandbox/modes.js";
13
16
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
17
+ import { PermissionFacts } from "../sandbox/permission-facts.js";
14
18
  import { SandboxProviders } from "../sandbox/providers.js";
15
19
  import { SandboxService } from "../sandbox/sandbox.service.js";
16
20
  import { DeviceAccess } from "./access.js";
@@ -55,14 +59,14 @@ export interface DeviceView {
55
59
  features: string[];
56
60
  policy: DeviceLocalPolicySummary | null;
57
61
  } | null;
58
- /** Its mode and network (auto mode spec §4.3). */
59
- mode: DeviceModeView;
62
+ /** Its effective device sandbox, the same under every permission profile. */
63
+ sandbox: DeviceSandboxView;
60
64
  /**
61
- * The device owner's ceiling as last reported (B2, read only): a local device's authenticated
62
- * owner report (`state: "report"`), a stale or conflicting report (`blocked`), only a protocol
63
- * 2 summary (`legacy`, translated exactly) or nothing (`missing`); a cloud device's explicit
64
- * Full ceiling once snapshotted. `stale` is true while the machine is offline or the report is
65
- * not current: last-known facts, never authority. null for a cloud device not snapshotted yet.
65
+ * A local device's owner ceiling as its machine last reported it (read only): an authenticated
66
+ * report (`state: "report"`), a stale or conflicting one (`blocked`) or nothing readable
67
+ * (`missing`). `stale` is true while the machine is offline or the report is not current:
68
+ * last-known facts, never authority. null for a cloud device (it has no machine) and for a local
69
+ * one without a connected machine.
66
70
  */
67
71
  ownerCeiling: DeviceOwnerCeilingView | null;
68
72
  /**
@@ -79,151 +83,133 @@ export interface DeviceView {
79
83
  lastUsedAt: string;
80
84
  } | null;
81
85
  /**
82
- * The sandbox limits of its effective mode (auto mode spec §4.2): what a cloud instance is
83
- * created with; for a local device the sandbox-mode allowlist.
86
+ * Its sandbox limits: the resources and network a cloud instance is created with; for a local
87
+ * device the network its commands carry (the machine intersects it with its owner's ceiling).
84
88
  */
85
89
  limits: SandboxLimits;
86
90
  createdAt: string;
87
91
  }
88
- /** {@link DeviceView.ownerCeiling}. */
89
- export interface DeviceOwnerCeilingView {
90
- state: "report" | "blocked" | "legacy" | "missing" | "cloud";
91
- revision: string | null;
92
- sequence: number | null;
93
- /** The owner's ceiling as stored or reported (a cloud device: the raw B1 ceiling). */
94
- fullAccess: boolean;
95
- /**
96
- * Whether the owner's side allows Full access as the kernel applies it: a cloud device's ceiling
97
- * narrowed by its old sandbox switch (`cloudChosenMode`); a local machine's derived mode
98
- * (`ownerModeOf`: its report, else an older program's mode or isolation), as admission reads it.
99
- * The platform and the org may still cut it ({@link DeviceModeView.allowedMode}).
100
- */
101
- effectiveFullAccess: boolean;
102
- /** Restricted project reach; a cloud device stays within its provisioned files (`workspace`). */
103
- restrictedProjectReach: "workspace" | "os-user";
104
- restrictedAllowedDomains: string[];
105
- observedAt: string | null;
106
- stale: boolean;
107
- }
108
92
  /**
109
- * A device's mode and network as its owner sees it (auto mode spec §4.1–§4.3).
93
+ * The effective device sandbox of a device as its owner sees it (approval-only profiles design,
94
+ * "Settings model" and "UI"): `effectiveDeviceSandbox` over the platform, org, device and provider
95
+ * layers.
110
96
  */
111
- export interface DeviceModeView {
112
- /**
113
- * The mode its commands run at: the local device's choice cut to {@link allowedMode}; a cloud
114
- * device has no choice, so it follows {@link allowedMode}.
115
- */
116
- mode: SandboxMode;
117
- /** `auto` only when the platform's and the org's `fullAccess` leave it allowed. */
118
- allowedMode: SandboxMode;
119
- /** Which layer allows auto mode (`org`: the org set it; `platform`: the org follows the platform); null when only sandbox mode is allowed. */
120
- allowedBy: "org" | "platform" | null;
121
- /** Its network (a cloud device's effective one; a local device's sandbox-mode allowlist). */
122
- network: {
123
- kind: NetworkKind;
124
- hosts: string[];
125
- source: "org" | "platform";
97
+ export interface DeviceSandboxView {
98
+ /** The sandbox network in effect: the open public internet, the allowlist, or closed. */
99
+ network: "open" | "allowlist" | "none";
100
+ /** The widest network the platform, the org and the provider leave this device. */
101
+ networkCeiling: "open" | "allowlist" | "none";
102
+ /** The allowlist hosts in effect (empty unless {@link network} is `allowlist`). */
103
+ hosts: string[];
104
+ /**
105
+ * The device's own network setting: a cloud device's stored choice (null follows its org), a
106
+ * local owner's reported network (null without a readable report).
107
+ */
108
+ ownNetwork: "open" | "allowlist" | "none" | null;
109
+ /**
110
+ * The device's own host list, which only narrows the org's hosts: a local owner's
111
+ * `allowedDomains` (its machine's ceiling while its network is the allowlist), a cloud device's
112
+ * stored hosts (empty: it follows its org's hosts).
113
+ */
114
+ allowedDomains: string[];
115
+ /** Whether a call may be granted escalation outside the sandbox (never on a cloud device). */
116
+ outsideSandbox: boolean;
117
+ /** How far restricted work may root outside the workspace. */
118
+ restrictedProjectReach: "workspace" | "os-user";
119
+ /** The layer that set each ceiling (a disabled option names it), or null when nothing did. */
120
+ layer: {
121
+ network: DeviceSandboxLayer | null;
122
+ outsideSandbox: DeviceSandboxLayer | null;
126
123
  };
127
- /** A local device: the mode its machine reported and its own sandbox-mode allowlist; null for cloud. */
128
- local: {
129
- reported: SandboxMode | null;
130
- allowedDomains: string[];
131
- } | null;
132
- /**
133
- * A cloud device: the network sandbox mode gives it, whatever mode it runs at now (the org's
134
- * `cloudNetwork`, open by default; the kill switch empties it) within its {@link outerNetwork},
135
- * so the page names exactly what turning Full access off reaches before it is done (hardening
136
- * spec D3). Null for a local device.
137
- */
138
- sandboxNetwork: {
139
- kind: NetworkKind;
140
- hosts: string[];
141
- } | null;
142
- /**
143
- * A cloud device: the network Full access gives it (the open public network, or the kill
144
- * switch's empty allowlist) within its {@link outerNetwork}. Null for a local device.
145
- */
146
- fullNetwork: {
147
- kind: NetworkKind;
148
- hosts: string[];
149
- } | null;
150
124
  /**
151
- * A cloud device's B1 outer network: the boundary no mode or ceiling change widens. Null for a
152
- * local device and for a cloud device not snapshotted yet.
153
- */
154
- outerNetwork: {
155
- kind: NetworkKind;
156
- hosts: string[];
157
- } | null;
158
- /**
159
- * A cloud device's instance runs another mode or network kind: its next use updates or recreates
160
- * it, files kept (「下次使用时生效,文件保留」).
125
+ * A cloud device's instance runs another network: its next use updates or recreates it, files
126
+ * kept (the page says it applies on next use).
161
127
  */
162
128
  pendingNextUse: boolean;
163
129
  /**
164
130
  * Its provider applies limits at its file system (`limitsApplyAt: "fileSystem"`) and the instance
165
- * runs another mode or network kind: only a file reset applies it (「重置文件后生效」).
131
+ * runs another network: only a file reset applies it (the page says it applies after a reset).
166
132
  */
167
133
  pendingFilesReset: boolean;
168
- /** Its last {@link RECENT_POLICY_CHANGES} mode and policy changes, newest first. */
169
- recent: DeviceModeChangeView[];
134
+ /** Its last {@link RECENT_POLICY_CHANGES} setting changes, newest first. */
135
+ recent: DeviceSettingChangeView[];
136
+ }
137
+ /** {@link DeviceView.ownerCeiling}: a local machine's owner ceiling as reported. */
138
+ export interface DeviceOwnerCeilingView {
139
+ state: "report" | "blocked" | "missing";
140
+ revision: string | null;
141
+ sequence: number | null;
142
+ /** The owner allows running outside the sandbox (fail closed: false). */
143
+ outsideSandbox: boolean;
144
+ /** The owner's sandbox network (fail closed: `allowlist`). */
145
+ network: "open" | "allowlist";
146
+ /** The owner's sandbox allowlist: the machine's host ceiling while its network is `allowlist`. */
147
+ allowedDomains: string[];
148
+ restrictedProjectReach: "workspace" | "os-user";
149
+ observedAt: string | null;
150
+ stale: boolean;
170
151
  }
171
- /** How many recent mode and policy changes a device view lists. */
152
+ /** How many recent setting changes a device view lists. */
172
153
  export declare const RECENT_POLICY_CHANGES = 10;
173
154
  /**
174
- * One mode or policy change of a device, as its owner sees it on the device page:
175
- * - `policy` (`device.policy_changed`): a local policy change sent to the machine (`web`, `im`), or
176
- * made on the machine by its owner (`device`, `capybara-device policy ...`); one sent whose
177
- * answer never came (`device.policy_unknown`) or that failed (`device.policy_failed`) too;
178
- * - `mode` (`device.mode_changed`): the device switched between auto and sandbox mode, on the
179
- * machine (`device`) or by a policy op (`web`, `im`);
180
- * - `ceiling` (`device.owner_ceiling_changed`): the owner ceiling changed, a cloud device's Full
181
- * ceiling on the device page (`web`) or a machine's authenticated report (`device`).
155
+ * One setting change of a device, as its owner sees it on the device page:
156
+ * - `policy` (`device.policy_changed`): hosts removed from a local machine's allowlist by the
157
+ * platform (`web`, `im`), or added or removed on the machine by its owner (`device`,
158
+ * `capybara-device policy ...`); one sent whose answer never came (`device.policy_unknown`) or
159
+ * that failed (`device.policy_failed`) too;
160
+ * - `ceiling` (`device.owner_ceiling_changed`): a machine's owner ceiling changed, narrowed from the
161
+ * device page (`web`) or on the machine (`device`);
162
+ * - `network` (`device.network_changed`): a cloud device's sandbox network changed on its device
163
+ * page (`web`), through an API token (`token`), or by an agent's Platform tool call (`agent`).
182
164
  */
183
- export interface DeviceModeChangeView {
165
+ export interface DeviceSettingChangeView {
184
166
  at: string;
185
- kind: "policy" | "mode" | "ceiling";
167
+ kind: "policy" | "ceiling" | "network";
186
168
  /** Hosts added to / removed from the local allowlist (`policy` only; else empty). */
187
169
  add: string[];
188
170
  remove: string[];
189
- /** The mode change (`from`: the previous mode the machine reported); null when it did not change. */
190
- mode: {
191
- from?: SandboxMode | null;
192
- to: SandboxMode;
193
- } | null;
194
- /**
195
- * The ceiling change (`ceiling` only; else null): Full access, and a machine's restricted project
196
- * reach (a cloud device has none). `from` is null when the row does not say.
197
- */
171
+ /** The owner ceiling change (`ceiling` only; else null). `from` is null when the row does not say. */
198
172
  ceiling: {
199
173
  from: DeviceCeilingFacts | null;
200
174
  to: DeviceCeilingFacts;
201
175
  } | null;
176
+ /** The cloud network change (`network` only; else null). */
177
+ network: {
178
+ from: DeviceNetworkSetting;
179
+ to: DeviceNetworkSetting;
180
+ } | null;
202
181
  /** The deciding account's display name (null when the account is gone). */
203
182
  by: string | null;
204
- /** `device`: made or reported on the machine itself. */
205
- via: "web" | "im" | "device";
183
+ /**
184
+ * `device`: made or reported on the machine itself; `token`: through an API token; `agent`: an
185
+ * agent's Platform tool call.
186
+ */
187
+ via: "web" | "im" | "device" | "token" | "agent";
206
188
  /**
207
189
  * What became of a `policy` change sent to the machine: `applied` (also every change made or
208
- * reported on the machine, and every mode row); `unknown`, its answer never came, `failed`, the
190
+ * reported on the machine, and every other row); `unknown`, its answer never came, `failed`, the
209
191
  * machine refused it, never received it or stopped while applying it.
210
192
  */
211
193
  outcome: "applied" | "unknown" | "failed";
212
194
  }
213
- /** One side of a {@link DeviceModeChangeView.ceiling} change. */
195
+ /** One side of a {@link DeviceSettingChangeView.ceiling} change. */
214
196
  export interface DeviceCeilingFacts {
215
- fullAccess: boolean;
197
+ outsideSandbox: boolean;
216
198
  restrictedProjectReach?: "workspace" | "os-user";
199
+ network?: "open" | "allowlist";
200
+ }
201
+ /** A cloud device's stored network setting: `mode` null follows its org. */
202
+ export interface DeviceNetworkSetting {
203
+ mode: "open" | "allowlist" | "none" | null;
204
+ hosts: string[];
217
205
  }
218
- /** A change of a local device's policy by its owner (`POST /devices/:id/policy`). */
206
+ /** A narrowing of a local device's policy by its owner (`POST /devices/:id/policy`). */
219
207
  export interface DevicePolicyChange {
220
- add?: string[] | undefined;
221
208
  remove?: string[] | undefined;
222
- /** Switch the sandbox back on; auto mode is turned on only on the machine. */
223
- mode?: "sandbox" | undefined;
224
- /** B2: narrow the owner ceiling (never widen; the schema refuses true and os-user). */
209
+ /** Narrow the owner ceiling (never widen; the schema refuses anything wider). */
225
210
  ownerCeiling?: {
226
- fullAccess?: false | undefined;
211
+ outsideSandbox?: false | undefined;
212
+ network?: "allowlist" | undefined;
227
213
  restrictedProjectReach?: "workspace" | undefined;
228
214
  } | undefined;
229
215
  }
@@ -231,20 +217,13 @@ export interface DevicePolicyChange {
231
217
  export interface DevicePatch {
232
218
  name?: string;
233
219
  /**
234
- * A cloud device's mode choice: `sandbox` narrows it (the org's `cloudNetwork` applies), `null`
235
- * clears the choice so it follows the org and the platform again (auto when they allow it;
236
- * hardening spec D2). Only a person in a web session sends it (the controller refuses a token).
237
- * A local device refuses it here (`device.mode_on_device`, its mode is its machine's).
238
- */
239
- mode?: "sandbox" | null;
240
- /**
241
- * B2: a cloud device's explicit Full ceiling. Narrowing applies; widening needs
242
- * `confirmWidening` and stays bounded by the platform, the org and the outer network.
220
+ * A cloud device's sandbox network, within its org's and the platform's ceilings. A local
221
+ * device refuses it here (`device.ceiling_on_machine`).
243
222
  */
244
- ownerCeiling?: {
245
- fullAccess: boolean;
223
+ network?: {
224
+ mode: "open" | "allowlist" | "none" | null;
225
+ hosts?: string[] | undefined;
246
226
  };
247
- confirmWidening?: true;
248
227
  }
249
228
  /** The machine connected to a local device, as its owner sees it. */
250
229
  export interface DeviceMachineView {
@@ -288,11 +267,12 @@ export declare class DevicesService {
288
267
  private readonly machines;
289
268
  private readonly policies;
290
269
  private readonly ceilings;
270
+ private readonly facts;
291
271
  constructor(db: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get" | "fieldSource">, providers: Pick<SandboxProviders, "cloud" | "forName">, sandbox: Pick<SandboxService, "devicePolicy" | "deviceLimits" | "limitsState">, sandboxJobs: Pick<SandboxJobs, "resetFiles">,
292
272
  /** Owes a deleted device's destruction in the delete's transaction. */
293
273
  outbox: Pick<OutboxService, "add">, access: Pick<DeviceAccess, "usable">, displayNames: Pick<ExtensionDisplayNames, "many">,
294
274
  /** Reads the device relay's lease (`online`). */
295
- locks: Pick<LockService, "holderOf">, machines: Pick<MachinesService, "revoke" | "revokeActive">, policies: Pick<DevicePolicyService, "apply" | "summary">, ceilings: PermissionCeilingWrites);
275
+ locks: Pick<LockService, "holderOf">, machines: Pick<MachinesService, "revoke" | "revokeActive">, policies: Pick<DevicePolicyService, "apply" | "summary">, ceilings: PermissionCeilingWrites, facts: Pick<PermissionFacts, "deviceSandbox" | "deviceSandboxFacts">);
296
276
  /**
297
277
  * The person's live devices in the org, the default first, then by creation. With a
298
278
  * current sandbox provider the default device is created first if missing (its first need,
@@ -348,23 +328,49 @@ export declare class DevicesService {
348
328
  rename(orgId: string, accountId: string, id: string, name: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<DeviceView>;
349
329
  private renameIn;
350
330
  /**
351
- * `PATCH /devices/:id`: renames one of the person's live devices ({@link rename}) and narrows a
352
- * cloud device to sandbox mode, in one transaction. A local device's mode lives on its machine,
353
- * so a `mode` for it is refused (`device.mode_on_device`; {@link changePolicy}); auto mode is
354
- * never set from the web (auto mode spec §4.3). Callers make sure only a person in a session
355
- * changes a device.
356
- */
357
- update(orgId: string, accountId: string, id: string, patch: DevicePatch, actorTokenId?: string): Promise<DeviceView>;
331
+ * `PATCH /devices/:id`: renames one of the person's live devices ({@link rename}) and sets a
332
+ * cloud device's sandbox network ({@link networkLocked}), in one transaction. A network change
333
+ * takes the membership, the device row and the device's permission write lock as the ordered
334
+ * prelude (`withOrderedLocks`): inside a run's fence (`devices.set-network`) they follow the org
335
+ * row and precede the conversation rows. A local device's network lives on its machine
336
+ * (`device.ceiling_on_machine`). `narrowOnly` (an API token, the Platform tool): the network may
337
+ * only narrow, stored and effective.
338
+ */
339
+ update(orgId: string, accountId: string, id: string, patch: DevicePatch, actorTokenId?: string, opts?: {
340
+ narrowOnly?: boolean;
341
+ auditDetail?: Record<string, unknown>;
342
+ }): Promise<DeviceView>;
343
+ /** The prelude of a network change: the membership, the device row, the device's write lock. */
344
+ private lockNetworkSubject;
358
345
  private updateIn;
359
346
  /**
360
- * B2 cloud owner ceiling (`PATCH ownerCeiling: {fullAccess}`), under the device authority
361
- * writer: a cloud device's explicit Full ceiling. Narrowing applies at once and revokes only Full
362
- * work; widening needs the person's explicit confirmation in a web session, is refused while
363
- * the platform or the org does not allow Full access, never touches the outer network, and
364
- * resets Full consent (conversations need fresh consent). A local device's ceiling is its
365
- * machine's (`device.mode_on_device`).
347
+ * Checks a cloud network change without writing anything and without locks (the Platform
348
+ * tool's precheck): the device is the person's live cloud device, and the change stays within
349
+ * the ceilings and, with `narrowOnly`, only narrows. Throws what {@link update} would; the
350
+ * write re-checks under its locks.
351
+ */
352
+ checkNetwork(orgId: string, accountId: string, id: string, network: NonNullable<DevicePatch["network"]>, narrowOnly: boolean): Promise<void>;
353
+ /**
354
+ * Decides a cloud network change (read only): the stored setting before and after, the
355
+ * effective device sandbox before and after (computed in memory from the patched setting), and
356
+ * whether it widens. Refuses, without writing: a local device (`device.ceiling_on_machine`),
357
+ * the open network above the ceilings or a host outside the org's list
358
+ * (`device.network_not_allowed`), and with `narrowOnly` a widening of the stored setting or of
359
+ * the effective network (`device.network_not_allowed`). Null when nothing changes.
360
+ */
361
+ private planNetwork;
362
+ /**
363
+ * A cloud device's sandbox network (approval-only profiles design, "Settings model"), under the
364
+ * device authority writer held since the prelude: its owner chooses `open`, `allowlist` (its
365
+ * org's hosts, narrowed by its own list: a device list never adds a host; an empty one follows
366
+ * the org's hosts), `none` (closed) or null (follow the org), in both directions within the
367
+ * org's and the platform's ceilings ({@link planNetwork}). The write and its publication are one
368
+ * transaction: a narrowing bumps the device epoch and revokes the admitted or started work it
369
+ * takes ({@link networkNarrowingRevokes}; the revocations are owed through the outbox) and keeps
370
+ * Full consent; a widening resets Full consent with a `permission_profile_changed` event.
371
+ * Audited `device.network_changed` (`via`: `web`, `token` for an API token, or the agent's).
366
372
  */
367
- private cloudOwnerCeilingLocked;
373
+ private networkLocked;
368
374
  /**
369
375
  * How far restricted work may root outside the device's workspace now (B2): a local machine's
370
376
  * owner reach within a platform and org that allow the wider device ceiling; a cloud device
@@ -372,11 +378,11 @@ export declare class DevicesService {
372
378
  */
373
379
  projectReach(orgId: string, deviceId: string): Promise<"workspace" | "os-user">;
374
380
  /**
375
- * The mode a sandbox call in the device runs at now, for the model (`device_paths`, auto mode
376
- * spec §4.2): the effective policy for the mode it runs at (a local machine's derived mode,
377
- * failing closed; a cloud device's narrowing switch, else the allowed mode), its network, and a
378
- * cloud device's pending file-reset state (the mode and network its instance still runs with).
379
- * Null when the device is not a live device of the org.
381
+ * The level a sandbox call in the device runs at now, for the model (legacy `device_paths`, auto
382
+ * mode spec §4.2): the kernel-internal tier (`SandboxMode`: a local machine's owner permission to
383
+ * run outside the sandbox, failing closed) with its device sandbox network, and a cloud device's
384
+ * pending file-reset state (the tier and network its instance still runs with). Null when the
385
+ * device is not a live device of the org.
380
386
  */
381
387
  modeLevel(orgId: string, deviceId: string): Promise<DeviceModeLevel | null>;
382
388
  /** Renames the device locked by {@link lockOwn} (`before`); see {@link rename}. */
@@ -403,14 +409,15 @@ export declare class DevicesService {
403
409
  */
404
410
  revokeMachine(orgId: string, accountId: string, id: string, actorTokenId?: string): Promise<void>;
405
411
  /**
406
- * The owner changes one of their own devices' local policy (network ask-to-allow spec §7, §13
407
- * Q6; auto mode spec §4.1): sent to the machine with the `policy` op, which is the authority and
408
- * answers with the policy as written. Anyone but the owner gets `device.not_found`. The owner may
409
- * add or remove sandbox-mode hosts, and turn the sandbox back on (`mode: "sandbox"`); auto mode
410
- * is turned on only on the machine. The machine offline → `device.offline`; a cloud device or a
411
- * program without the `policyOpId` feature → `device.policy_unsupported`; the machine's refusal →
412
- * `device.policy_refused` with its message. Callers are human sessions only (no personal access
413
- * token, no service token, no Platform op).
412
+ * The owner narrows one of their own local devices' sandbox from the web (approval-only
413
+ * profiles design, "Settings model"): sent to the machine with the `policy` op, which is the
414
+ * authority and answers with the policy as written. Anyone but the owner gets
415
+ * `device.not_found`. The owner may remove hosts from the machine's allowlist and narrow its
416
+ * owner ceiling (no running outside the sandbox, the allowlist network, the workspace reach);
417
+ * widening happens on the machine only. The machine offline → `device.offline`; a cloud device
418
+ * or a program without the `policyOpId` feature → `device.policy_unsupported`; the machine's
419
+ * refusal → `device.policy_refused` with its message. Callers are human sessions only (no
420
+ * personal access token, no service token, no Platform op).
414
421
  */
415
422
  changePolicy(orgId: string, account: {
416
423
  id: string;
@@ -492,12 +499,10 @@ export declare class DevicesService {
492
499
  /** The person's live devices (or the one `id`) as views. */
493
500
  private views;
494
501
  /**
495
- * The last {@link RECENT_POLICY_CHANGES} mode and policy changes of each device in the org
496
- * (audit rows `device.policy_changed`, `device.policy_unknown`, `device.policy_failed`,
497
- * `device.mode_changed`, `device.owner_ceiling_changed`), newest first, with the deciding
498
- * account's display name.
502
+ * The last {@link RECENT_POLICY_CHANGES} setting changes of each device in the org (audit rows
503
+ * {@link SETTING_CHANGE_ACTIONS}), newest first, with the deciding account's display name.
499
504
  */
500
- private recentModeChanges;
505
+ private recentChanges;
501
506
  /**
502
507
  * Serializes the person's device writes in the org: the org row (`FOR SHARE`), then their
503
508
  * membership row (`FOR NO KEY UPDATE`, or `FOR SHARE` with `mode` share: enough to keep the
@@ -510,20 +515,28 @@ export declare class DevicesService {
510
515
  private assertNameFree;
511
516
  }
512
517
  /**
513
- * The mode view of one device (auto mode spec §4.3): its effective policy with the mode its
514
- * machine reported (`summary`, local devices only), the network and where it comes from, and the
515
- * instance's pending change with the recent changes.
518
+ * Whether a cloud device's stored network setting widens from `a` to `b`, whatever the network in
519
+ * effect now (a stored widening takes effect when a ceiling opens later): a wider mode, where
520
+ * following the org (null) counts as wider than any explicit mode; or an explicit host list
521
+ * replaced by none of its own (follow the org's hosts) or gaining a host.
516
522
  */
517
- export declare function deviceModeViewOf(policy: EffectiveDevicePolicy, settings: OrgDeviceSettings, local: boolean, summary: DeviceLocalPolicySummary | null, extra: {
518
- pendingNextUse: boolean;
519
- pendingFilesReset: boolean;
520
- recent: DeviceModeChangeView[];
521
- /** The network sandbox mode gives a cloud device, within its outer network. */
522
- sandboxNetwork: DeviceNetwork;
523
- /** The network Full access gives a cloud device, within its outer network. */
524
- fullNetwork: DeviceNetwork;
525
- /** A cloud device's B1 outer network; null when not snapshotted. */
526
- outerNetwork: DeviceNetwork | null;
527
- },
528
- /** The platform kill switch (`sandbox.limits.egress: none`): the network is the platform's. */
529
- killSwitch?: boolean): DeviceModeView;
523
+ export declare function storedNetworkWidens(a: DeviceNetworkSetting, b: DeviceNetworkSetting): boolean;
524
+ /**
525
+ * What a cloud device's new network takes from admitted or started work (`next`: its sandbox
526
+ * after the change): open-network work once it is no longer open, and allowlist work naming a host
527
+ * its new hosts no longer cover, unless an independent grant the new per-call ceiling still allows
528
+ * holds it (`hostsNarrowed`).
529
+ */
530
+ export declare function networkNarrowingRevokes(next: {
531
+ box: Pick<DeviceSandbox, "networkMode" | "hosts">;
532
+ hostCeiling: HostGrantCeiling;
533
+ }, scope: SandboxOperationScope | SandboxBrowseScope, intent: Pick<Selectable<SandboxOperationIntentsTable>, "method" | "granted_hosts">): boolean;
534
+ /**
535
+ * The sandbox view of one device: its effective {@link DeviceSandbox} with its own network setting
536
+ * (`own`: a local machine's owner facts, a cloud device's stored choice) and the instance's pending
537
+ * change with the recent changes.
538
+ */
539
+ export declare function sandboxViewOf(box: DeviceSandbox, own: Pick<OwnerFacts, "state" | "network" | "allowedDomains"> | {
540
+ networkMode: "open" | "allowlist" | "none" | null;
541
+ networkHosts: readonly string[];
542
+ }, extra: Pick<DeviceSandboxView, "pendingNextUse" | "pendingFilesReset" | "recent">): DeviceSandboxView;