@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
@@ -85,7 +85,7 @@ export const PLATFORM_DOMAINS = [
85
85
  },
86
86
  {
87
87
  id: "devices",
88
- description: "Your own cloud devices (the workspaces your conversations run in): list, read, create, rename, delete, wipe the files.",
88
+ description: "Your own cloud devices (the workspaces your conversations run in): list, read, create, rename, narrow the sandbox network, delete, wipe the files.",
89
89
  },
90
90
  {
91
91
  id: "schedules",
@@ -43,7 +43,8 @@ const SettingsInput = DEPLOYMENT_SETTINGS_PATCH.pick({
43
43
  uiTheme: true,
44
44
  uiArrangement: true,
45
45
  clientExtensions: true,
46
- devicesFullAccess: true,
46
+ devicesOutsideSandbox: true,
47
+ devicesNetwork: true,
47
48
  attribution: true,
48
49
  externalSharing: true,
49
50
  shareMaxExpiryDays: true,
@@ -207,7 +208,7 @@ let AdminOperations = class AdminOperations {
207
208
  }),
208
209
  defineOperation({
209
210
  id: "admin.settings",
210
- description: "Read the deployment settings (super admin): who may create orgs (orgCreation), the price currency, whether orgs may create their own connectors and skills, whether org admins may browse the marketplaces, the per-org limit overrides keyed by org id (orgs.get reads one org's), the platform's Full permission switch in effect (devicesFullAccess: permission allowed or off), the platform's attribution defaults for agent-created git commits and pull requests (attribution: commit, pr, sessionUrl), file sharing (externalSharing: value allow or deny, whether orgs may turn on public links to conversation files; shareMaxExpiryDays: value, the longest expiry a share may take in days), htmlRenderCdnAllowlist (the https origins a rendered HTML file may load libraries, styles, fonts and images from) and promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; an org's own promptSuggestions must be on too); the switches each with sources: env, file or nacos are set in the startup config and read-only, db chosen in the admin console, default.",
211
+ description: "Read the deployment settings (super admin): who may create orgs (orgCreation), the price currency, whether orgs may create their own connectors and skills, whether org admins may browse the marketplaces, the per-org limit overrides keyed by org id (orgs.get reads one org's), the platform's device sandbox settings in effect (devicesOutsideSandbox: permission allowed or off, whether a device may be granted running a call outside its sandbox; devicesNetwork: default and ceiling, open for the public internet with private addresses closed or allowlist, the network a device gets and the widest an org or device may choose), the platform's attribution defaults for agent-created git commits and pull requests (attribution: commit, pr, sessionUrl), file sharing (externalSharing: value allow or deny, whether orgs may turn on public links to conversation files; shareMaxExpiryDays: value, the longest expiry a share may take in days), htmlRenderCdnAllowlist (the https origins a rendered HTML file may load libraries, styles, fonts and images from) and promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; an org's own promptSuggestions must be on too); the switches each with sources: env, file or nacos are set in the startup config and read-only, db chosen in the admin console, default.",
211
212
  input: z.object({}).strict(),
212
213
  example: {},
213
214
  authz: { superAdmin: true },
@@ -217,7 +218,7 @@ let AdminOperations = class AdminOperations {
217
218
  }),
218
219
  defineOperation({
219
220
  id: "admin.update-settings",
220
- description: "Change deployment settings (super admin); give only the keys to change: orgCreation (anyone or super_admin), priceCurrency (ISO 4217 code), customConnectors / customSkills (allow or deny: whether orgs may create their own instead of installing from the catalog), orgMarketplaceBrowse (true or false), uiTheme ({ id }: the platform default theme, a platform theme whose scope is all, or null for the built-in theme; it is what every org falls back to and what the sign-in pages show), uiArrangement ({ <slot>: { hidden, order } } for a list slot, { <slot>: { use } } for a single slot: the platform default arrangement of UI slots, with contribution keys <extension>/<contribution>; hidden ones are not listed but still open by URL; use names the contribution that replaces the built-in, null for the built-in; null for a slot removes its entry), clientExtensions ({ enabled?, disabled? }: the kill switch of plugin client code; enabled false stops every plugin's interface code in every browser, disabled is the whole list of plugins whose interface code alone is stopped while their tools keep working; read the current list from admin.settings first), devicesFullAccess ({ permission }: the platform's Full permission switch, allowed or off; null clears it back to the default, allowed; through this tool it may only be turned off, never allowed, and a value set in the startup config is read-only), attribution ({ commit?, pr?, sessionUrl? }: the platform's defaults for agent-created git commits and pull requests; null clears a field back to its default, an empty string turns that line off, and fields set in the startup config are read-only), externalSharing (allow or deny: whether orgs may turn on public links to conversation files; null clears it back to the default, deny; externalSharing may only be turned off through this tool, and a value set in the startup config is read-only), shareMaxExpiryDays (1 to 365: the longest expiry a share may take, in days; null clears it back to 30; through this tool it may only be lowered, never raised, and it is read-only when set in the startup config), htmlRenderCdnAllowlist (the whole list of https origins, scheme and host with an optional port and nothing else, that a rendered HTML file may load from; at most 50; through this tool origins may only be removed, never added, so read the current list from admin.settings first and send it without the ones to drop). promptSuggestions (on or off; null clears it, absent meaning on: whether the composer suggests the person's next message after a completed run; an org's own promptSuggestions must be on too) may be set either way. Per-org limits are orgs.set-limits.",
221
+ description: "Change deployment settings (super admin); give only the keys to change: orgCreation (anyone or super_admin), priceCurrency (ISO 4217 code), customConnectors / customSkills (allow or deny: whether orgs may create their own instead of installing from the catalog), orgMarketplaceBrowse (true or false), uiTheme ({ id }: the platform default theme, a platform theme whose scope is all, or null for the built-in theme; it is what every org falls back to and what the sign-in pages show), uiArrangement ({ <slot>: { hidden, order } } for a list slot, { <slot>: { use } } for a single slot: the platform default arrangement of UI slots, with contribution keys <extension>/<contribution>; hidden ones are not listed but still open by URL; use names the contribution that replaces the built-in, null for the built-in; null for a slot removes its entry), clientExtensions ({ enabled?, disabled? }: the kill switch of plugin client code; enabled false stops every plugin's interface code in every browser, disabled is the whole list of plugins whose interface code alone is stopped while their tools keep working; read the current list from admin.settings first), devicesOutsideSandbox ({ permission }: whether a device may be granted running a call outside its sandbox, allowed or off; null clears it back to the default, allowed; through this tool it may only be turned off, never allowed, and a value set in the startup config is read-only), devicesNetwork ({ default?, ceiling? }: the device sandbox network, open or allowlist; null clears a field back to the default, open; the default may not be above the ceiling; through this tool either may only be narrowed to allowlist, never opened, and a field set in the startup config is read-only), attribution ({ commit?, pr?, sessionUrl? }: the platform's defaults for agent-created git commits and pull requests; null clears a field back to its default, an empty string turns that line off, and fields set in the startup config are read-only), externalSharing (allow or deny: whether orgs may turn on public links to conversation files; null clears it back to the default, deny; externalSharing may only be turned off through this tool, and a value set in the startup config is read-only), shareMaxExpiryDays (1 to 365: the longest expiry a share may take, in days; null clears it back to 30; through this tool it may only be lowered, never raised, and it is read-only when set in the startup config), htmlRenderCdnAllowlist (the whole list of https origins, scheme and host with an optional port and nothing else, that a rendered HTML file may load from; at most 50; through this tool origins may only be removed, never added, so read the current list from admin.settings first and send it without the ones to drop). promptSuggestions (on or off; null clears it, absent meaning on: whether the composer suggests the person's next message after a completed run; an org's own promptSuggestions must be on too) may be set either way. Per-org limits are orgs.set-limits.",
221
222
  input: SettingsInput.refine((b) => Object.keys(b).length > 0, {
222
223
  message: "at least one setting is required",
223
224
  }),
@@ -239,8 +240,12 @@ let AdminOperations = class AdminOperations {
239
240
  next: "Fix the values as the message says (admin.settings shows the current ones).",
240
241
  },
241
242
  {
242
- code: "deployment.full_access_not_allowed",
243
- next: "Through this tool the platform's Full permission switch may only be turned off; to allow it, ask a super admin to change it in the admin console settings on the web.",
243
+ code: "deployment.outside_sandbox_not_allowed",
244
+ next: "Through this tool running outside the sandbox (devicesOutsideSandbox) may only be turned off; to allow it, ask a super admin to change it in the admin console settings on the web.",
245
+ },
246
+ {
247
+ code: "deployment.network_not_allowed",
248
+ next: "Through this tool the device network (devicesNetwork) may only be narrowed to allowlist, and its default may never be above its ceiling (admin.settings shows both); to open it, ask a super admin to change it in the admin console settings on the web.",
244
249
  },
245
250
  {
246
251
  code: "deployment.external_sharing_not_allowed",
@@ -269,20 +274,24 @@ let AdminOperations = class AdminOperations {
269
274
  };
270
275
  }
271
276
  return precheckBy(async () => {
272
- const full = i.devicesFullAccess;
273
- if (full !== undefined)
274
- await this.settings.checkDevicesFullAccess(full, { onlyNarrows: true });
277
+ if (i.devicesOutsideSandbox !== undefined || i.devicesNetwork !== undefined)
278
+ await this.settings.checkDeviceSandbox(i, { onlyNarrows: true });
275
279
  await this.settings.checkSharing(i, { onlyNarrows: true });
276
280
  });
277
281
  },
278
282
  summary: async (i) => {
279
- const { uiTheme, uiArrangement, clientExtensions, devicesFullAccess, attribution, htmlRenderCdnAllowlist, ...rest } = i;
283
+ const { uiTheme, uiArrangement, clientExtensions, devicesOutsideSandbox, devicesNetwork, attribution, htmlRenderCdnAllowlist, ...rest } = i;
280
284
  const parts = Object.entries(rest).map(([k, v]) => `${k}=${String(v)}`);
281
285
  if (htmlRenderCdnAllowlist !== undefined) {
282
286
  parts.push(`htmlRenderCdnAllowlist=[${htmlRenderCdnAllowlist.join(", ")}]`);
283
287
  }
284
- if (devicesFullAccess !== undefined) {
285
- parts.push(`devicesFullAccess=${String(devicesFullAccess.permission)}`);
288
+ if (devicesOutsideSandbox !== undefined) {
289
+ parts.push(`devicesOutsideSandbox=${String(devicesOutsideSandbox.permission)}`);
290
+ }
291
+ if (devicesNetwork !== undefined) {
292
+ for (const field of ["default", "ceiling"])
293
+ if (devicesNetwork[field] !== undefined)
294
+ parts.push(`devicesNetwork.${field}=${String(devicesNetwork[field])}`);
286
295
  }
287
296
  const zh = [...parts];
288
297
  const en = [...parts];
@@ -11,7 +11,7 @@ import { Inject, Injectable } from "@nestjs/common";
11
11
  import { z } from "zod";
12
12
  import { DeviceProjectsService } from "../../devices/device-projects.service.js";
13
13
  import { DevicesService } from "../../devices/devices.service.js";
14
- import { DeviceNameBody, DeviceParams, DeviceProjectAddBody, DeviceProjectParams, } from "../../devices/dto.js";
14
+ import { DeviceNameBody, DeviceNetworkBody, DeviceParams, DeviceProjectAddBody, DeviceProjectParams, } from "../../devices/dto.js";
15
15
  import { deviceLabel } from "../../devices/label.js";
16
16
  import { KernelDb } from "../../infra/database/kernel-db.js";
17
17
  import { rootConversationOf } from "../../runtime/subagents/child.js";
@@ -141,7 +141,7 @@ let DevicesOperations = class DevicesOperations {
141
141
  }),
142
142
  defineOperation({
143
143
  id: "devices.get",
144
- description: "Read one of your devices with its source (cloud or local), provider, state, instance, the machine of a local one and whether it is online, limits, its mode (the one its commands run at and the one this org allows, and which layer allows auto mode), its network and where that comes from, a pending change that applies on its next use, its recent mode and policy changes, and creation time. Takes the id from devices.list. Only the person changes a device's mode: a local device's on the machine (auto mode is enabled only there), a cloud device's on its device page (to sandbox, or back to following the org's mode).",
144
+ description: "Read one of your devices with its source (cloud or local), provider, state, instance, the machine of a local one and whether it is online, limits, its sandbox (the network in effect and its ceiling: open, allowlist or none, with the allowlist hosts; the device's own network setting and host list; whether a call may run outside the sandbox; which layer set each ceiling; a pending change that applies on its next use; its recent setting changes), a local machine's owner ceiling, and creation time. Takes the id from devices.list. A local device's sandbox is widened only on its machine; a cloud device's network can be narrowed with devices.set-network.",
145
145
  input: DeviceId,
146
146
  example: { deviceId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20" },
147
147
  authz: { orgAction: "agents.use" },
@@ -286,9 +286,8 @@ let DevicesOperations = class DevicesOperations {
286
286
  authz: { orgAction: "agents.use" },
287
287
  mirrors: ["PATCH /api/v1/orgs/:orgId/devices/:id"],
288
288
  renames: { deviceId: "id" },
289
- // a person changes their own device's mode or owner ceiling in a web session; widening a
290
- // machine's ceiling happens on the machine (B2)
291
- omits: ["mode", "ownerCeiling", "confirmWidening"],
289
+ // the network is devices.set-network's (narrow only)
290
+ omits: ["network"],
292
291
  confirm: "personal",
293
292
  errors: [
294
293
  {
@@ -312,6 +311,72 @@ let DevicesOperations = class DevicesOperations {
312
311
  device: row(await this.devices.rename(ctx.orgId, ctx.actorAccountId, input.deviceId, input.name, undefined, viaAgent("devices.rename", ctx))),
313
312
  }),
314
313
  }),
314
+ defineOperation({
315
+ id: "devices.set-network",
316
+ description: "Narrow the sandbox network of one of your cloud devices: mode allowlist (its organization's allowed hosts, optionally narrowed to hosts: a device's list never adds a host) or none (no network). Only narrowing is allowed here, in its stored setting and in effect: opening the network, adding a host, dropping its own host list or following the organization again (mode null) is refused and needs the person on the device's page. A local device's network is kept on its machine. Takes the id from devices.list; devices.get shows the network in effect.",
317
+ input: DeviceId.extend({ network: DeviceNetworkBody }).strict(),
318
+ example: {
319
+ deviceId: "4e8a0c1d-6b2f-4a37-8d19-3c5e7f9a1b20",
320
+ network: { mode: "allowlist", hosts: ["registry.npmjs.org"] },
321
+ },
322
+ authz: { orgAction: "agents.use" },
323
+ mirrors: ["PATCH /api/v1/orgs/:orgId/devices/:id"],
324
+ renames: { deviceId: "id" },
325
+ omits: ["name"],
326
+ confirm: "personal",
327
+ errors: [
328
+ {
329
+ code: "device.not_found",
330
+ next: "Check the id with devices.list: you only see your own devices.",
331
+ },
332
+ {
333
+ code: "device.network_not_allowed",
334
+ next: "Through this tool a device's network may only narrow, within its organization's hosts: pick allowlist or none, or hosts its organization allows (devices.get shows them). To open it, ask the person to change it on the device's page; a host outside the organization's list needs an org admin.",
335
+ },
336
+ {
337
+ code: "device.ceiling_on_machine",
338
+ next: "This is a local device: its network is kept on its machine. Ask the person to narrow it on the device's page or on the machine.",
339
+ },
340
+ ],
341
+ precheck: (i, ctx) => precheckBy(() => this.devices.checkNetwork(ctx.orgId, ctx.actorAccountId, i.deviceId, i.network, true)),
342
+ summary: async (i, ctx) => {
343
+ const name = await orElse(async () => named(labelOf(await this.devices.get(ctx.orgId, ctx.actorAccountId, i.deviceId))), i.deviceId);
344
+ const hosts = i.network.hosts?.length ? i.network.hosts.join(", ") : null;
345
+ const zh = i.network.mode === "none"
346
+ ? "关闭网络"
347
+ : i.network.mode === "allowlist"
348
+ ? `仅白名单${hosts ? `(${hosts})` : ""}`
349
+ : i.network.mode === "open"
350
+ ? "开放互联网"
351
+ : "跟随组织";
352
+ const en = i.network.mode === "none"
353
+ ? "no network"
354
+ : i.network.mode === "allowlist"
355
+ ? `the allowlist only${hosts ? ` (${hosts})` : ""}`
356
+ : i.network.mode === "open"
357
+ ? "the open internet"
358
+ : "follow the organization";
359
+ // neutral wording: the precheck and the run refuse anything but a narrowing
360
+ return {
361
+ zh: `将设备「${name}」的沙箱网络设为:${zh}`,
362
+ en: `Set the sandbox network of device "${name}" to ${en}`,
363
+ };
364
+ },
365
+ run: async (input, ctx) => {
366
+ const e = await this.devices.update(ctx.orgId, ctx.actorAccountId, input.deviceId, {
367
+ network: {
368
+ mode: input.network.mode,
369
+ ...(input.network.hosts !== undefined && { hosts: input.network.hosts }),
370
+ },
371
+ }, undefined, { narrowOnly: true, auditDetail: viaAgent("devices.set-network", ctx) });
372
+ return {
373
+ device: {
374
+ ...row(e),
375
+ sandbox: { network: e.sandbox.network, hosts: e.sandbox.hosts },
376
+ },
377
+ };
378
+ },
379
+ }),
315
380
  defineOperation({
316
381
  id: "devices.list-projects",
317
382
  description: "List the projects of one of your devices that its current mode can read (name and absolute path), plus the mode, the base a new project's path is relative to (the workspace in sandbox mode and on a cloud device, your home directory in auto mode), how many stored projects the mode hides, and whether the device offers projects at all. Takes the id from devices.list.",
@@ -39,7 +39,7 @@ let OrgSettingsOperations = class OrgSettingsOperations {
39
39
  this.registry.register([
40
40
  defineOperation({
41
41
  id: "org-settings.get",
42
- description: "Read this org's settings: toolSearch, locale, sandboxToolPolicy, platformTool (on, read-only or off), fullAccess (allowed or off: whether the org's devices may run with Full permission; absent follows the deployment's switch, and the org may never exceed it), cloudNetwork (the org's sandbox-mode network stored as a delta over the platform's allowlist: mode open or allowlist for a cloud device in sandbox mode, absent following the platform; base platform or none; extraHosts the org adds; excludedHosts platform hosts it drops; open means any public host, while loopback, private and cloud metadata addresses stay blocked), wakeOnBackgroundTask (absent means it follows the deployment), theme (the org's default theme id, null or absent following the platform, and personal: allowed or locked), uiArrangement (per list slot, the extension contributions the org hides and their order; per single slot, the contribution that replaces the built-in as use, null for the built-in; a slot not listed follows the platform), the deployment's Full switch (fullAccess) and network (its allowlist, orgHosts: extend lets the org go beyond it, within makes it the ceiling, and off for the platform kill switch), effectiveNetwork (the mode and hosts the org's sandbox mode really gets), externalSharing (on or off, absent meaning off: whether members may share conversation files through public links; the deployment's externalSharing must be allow too) with the deployment's externalSharing and shareMaxExpiryDays, promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) with the deployment's promptSuggestions, and the sandbox cpu / memory limits in effect.",
42
+ description: "Read this org's settings: toolSearch, locale, sandboxToolPolicy, platformTool (on, read-only or off), outsideSandbox (allowed or off: whether the org's devices may be granted running a call outside their sandbox; absent follows the deployment, and the org may never exceed it), deviceNetwork (the org's device sandbox network: default, the network a device gets when its owner chooses none, and ceiling, the widest a device may choose, each open or allowlist and absent following the platform; base platform or none; extraHosts the org adds; excludedHosts platform hosts it drops; open means any public host, while loopback, private and cloud metadata addresses stay closed), wakeOnBackgroundTask (absent means it follows the deployment), theme (the org's default theme id, null or absent following the platform, and personal: allowed or locked), uiArrangement (per list slot, the extension contributions the org hides and their order; per single slot, the contribution that replaces the built-in as use, null for the built-in; a slot not listed follows the platform), the deployment's outside-sandbox switch (outsideSandbox) and device network (deviceNetwork: its default and ceiling, its allowlist, orgHosts: extend lets the org go beyond the allowlist, within makes it the hosts' ceiling, and off for the platform kill switch), effectiveNetwork (the mode and hosts the org's devices really get), externalSharing (on or off, absent meaning off: whether members may share conversation files through public links; the deployment's externalSharing must be allow too) with the deployment's externalSharing and shareMaxExpiryDays, promptSuggestions (on or off, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) with the deployment's promptSuggestions, and the sandbox cpu / memory limits in effect.",
43
43
  input: z.object({}).strict(),
44
44
  example: {},
45
45
  authz: { orgAction: "org.read" },
@@ -57,7 +57,7 @@ let OrgSettingsOperations = class OrgSettingsOperations {
57
57
  }),
58
58
  defineOperation({
59
59
  id: "org-settings.update",
60
- description: "Change this org's settings (org admins). Give only the settings to change; null clears fullAccess, cloudNetwork or wakeOnBackgroundTask so they follow the deployment again (refused when the deployment value is wider than what this tool may set). fullAccess (allowed or off; the platform must allow it) and cloudNetwork ({ mode?, base?: platform | none, extraHosts?, excludedHosts? }, replaced whole, so send the stored fields you keep) may only narrow the org's devices here: allowing Full where the org has it off, switching the cloud network from allowlist to open, adding an extra host, dropping an exclusion or moving base from none to platform is refused and needs a person in the organization settings on the web. theme: { id, personal } sets the org's default theme (a theme id from themes.list, or null to follow the platform) and whether members may pick their own (allowed) or not (locked); null clears it. uiArrangement: { <slot>: { hidden, order } } (a list slot) or { <slot>: { use } } (a single slot: shell.brand, conversation.empty, conversation.composer.frame) replaces that slot's entry, where hidden, order and use name contribution keys <extension>/<contribution> (hidden ones are not listed in the web UI but their pages still open by URL; use null is the built-in); null for a slot makes it follow the platform again; platform.page is refused. externalSharing (on or off; null clears it, off) may only be turned off through this tool: turning it on needs a person in the organization settings on the web, and the platform must allow it. promptSuggestions (on or off; null clears it, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) may be set either way through this tool. Setting platformTool to off or read-only takes effect from the next call and cuts this Platform tool off in the org; an org admin switches it back on in the web settings.",
60
+ description: "Change this org's settings (org admins). Give only the settings to change; null clears outsideSandbox, deviceNetwork or wakeOnBackgroundTask so they follow the deployment again (refused when the deployment value is wider than what this tool may set). outsideSandbox (allowed or off; the platform must allow it) and deviceNetwork ({ default?, ceiling?: open | allowlist, base?: platform | none, extraHosts?, excludedHosts? }, replaced whole, so send the stored fields you keep; neither default nor ceiling may be open where the platform's ceiling is allowlist, and the default may not be above the ceiling) may only narrow the org's devices here: allowing outside-sandbox runs where the org has them off, opening the default or the ceiling, adding an extra host, dropping an exclusion or moving base from none to platform is refused and needs a person in the organization settings on the web. theme: { id, personal } sets the org's default theme (a theme id from themes.list, or null to follow the platform) and whether members may pick their own (allowed) or not (locked); null clears it. uiArrangement: { <slot>: { hidden, order } } (a list slot) or { <slot>: { use } } (a single slot: shell.brand, conversation.empty, conversation.composer.frame) replaces that slot's entry, where hidden, order and use name contribution keys <extension>/<contribution> (hidden ones are not listed in the web UI but their pages still open by URL; use null is the built-in); null for a slot makes it follow the platform again; platform.page is refused. externalSharing (on or off; null clears it, off) may only be turned off through this tool: turning it on needs a person in the organization settings on the web, and the platform must allow it. promptSuggestions (on or off; null clears it, absent meaning on: whether the composer suggests the person's next message after a completed run; the deployment's promptSuggestions must be on too) may be set either way through this tool. Setting platformTool to off or read-only takes effect from the next call and cuts this Platform tool off in the org; an org admin switches it back on in the web settings.",
61
61
  input: OrgSettingsPatchSchema.refine((i) => Object.values(i).some((v) => v !== undefined), {
62
62
  message: "give at least one setting",
63
63
  }),
@@ -68,11 +68,15 @@ let OrgSettingsOperations = class OrgSettingsOperations {
68
68
  errors: [
69
69
  {
70
70
  code: "org.sandbox_egress_not_allowed",
71
- next: "Through this tool the org's cloud network may only be narrowed: it may drop extra hosts, exclude platform hosts, move base to none or switch open to allowlist, but never add an extra host, drop an exclusion or switch back to open (the hosts are the local sandbox-mode ceiling whatever the cloud mode). To widen it, ask an org admin to change it in the organization settings on the web. When the platform limits hosts to its allowlist (deployment.cloudNetwork.orgHosts within), a host outside it needs a super admin.",
71
+ next: "Through this tool the org's device network hosts may only be narrowed: it may drop extra hosts, exclude platform hosts or move base to none, but never add an extra host or drop an exclusion. To widen them, ask an org admin to change them in the organization settings on the web. When the platform limits hosts to its allowlist (deployment.deviceNetwork.orgHosts within), a host outside it needs a super admin.",
72
72
  },
73
73
  {
74
- code: "org.full_access_not_allowed",
75
- next: "Through this tool the org's Full permission (fullAccess) may only be turned off, never allowed (the platform may turn it off too; org-settings.get shows both); to allow it, ask an org admin to change it in the organization settings on the web.",
74
+ code: "org.network_not_allowed",
75
+ next: "The org's device network default and ceiling may not be open where the platform's ceiling is allowlist (org-settings.get shows deployment.deviceNetwork), and through this tool they may only be narrowed to allowlist, never opened; to open them, ask an org admin in the organization settings on the web, and a super admin when the platform limits them.",
76
+ },
77
+ {
78
+ code: "org.outside_sandbox_not_allowed",
79
+ next: "Through this tool running outside the sandbox (outsideSandbox) may only be turned off, never allowed (the platform may turn it off too; org-settings.get shows both); to allow it, ask an org admin to change it in the organization settings on the web.",
76
80
  },
77
81
  {
78
82
  code: "org.external_sharing_not_allowed",
@@ -124,7 +128,7 @@ let OrgSettingsOperations = class OrgSettingsOperations {
124
128
  },
125
129
  run: async (input, ctx) => {
126
130
  const settings = await this.settings.update(ctx.orgId, input, ctx.actorAccountId, undefined, viaAgent("org-settings.update", ctx),
127
- // a person widens auto mode or the cloud network, never an agent (auto mode spec §4.3)
131
+ // a person widens the device sandbox settings, never an agent
128
132
  { onlyNarrows: true });
129
133
  const note = input.platformTool === undefined
130
134
  ? undefined
@@ -180,7 +180,8 @@ let OrgsOperations = class OrgsOperations {
180
180
  "uiTheme",
181
181
  "uiArrangement",
182
182
  "clientExtensions",
183
- "devicesFullAccess",
183
+ "devicesOutsideSandbox",
184
+ "devicesNetwork",
184
185
  "attribution",
185
186
  "compaction",
186
187
  "externalSharing",
@@ -1,27 +1,36 @@
1
- import { type ConversationEvent, type ManagedDevicePathsV1, type PermissionContextMetaV1, type PermissionContextV1 } from "../../conversations/events.js";
2
- /** A recorded log carries a present v1 marker or version that its strict schema rejects. */
1
+ import { type ConversationEvent, type ManagedDevicePathsV1, type PermissionContextMetaV1, type PermissionContextSandbox, type PermissionContextV2 } from "../../conversations/events.js";
2
+ /** A recorded log carries a present marker or version that its strict schema rejects. */
3
3
  export declare class RecordedPermissionContextError extends Error {
4
4
  readonly seq: number;
5
5
  readonly eventType: "permission_context" | "device_paths";
6
6
  readonly name = "RecordedPermissionContextError";
7
7
  constructor(seq: number, eventType: "permission_context" | "device_paths");
8
8
  }
9
- /** Canonical v1 bytes: explicit nulls, code-point object keys, validated array order. */
9
+ /** Canonical bytes: explicit nulls, code-point object keys, validated array order. */
10
10
  export declare function canonicalPermissionJson(value: unknown): string;
11
11
  /** JSON quoting makes recorded values inert, including markup and Unicode line separators. */
12
12
  export declare const permissionQuote: (value: string) => string;
13
- export declare function permissionContextText(payload: PermissionContextV1): string;
13
+ /**
14
+ * The model-facing text of a recorded context: the sandbox once (its boundary, directories and
15
+ * network), then the approver per crossing kind. A supported context without a sandbox block
16
+ * keeps the profile-level policy line.
17
+ */
18
+ export declare function permissionContextText(payload: PermissionContextV2): string;
14
19
  export declare function managedDevicePathsText(payload: ManagedDevicePathsV1): string;
15
- export declare const permissionContextHash: (payload: PermissionContextV1) => string;
20
+ /** A recorded payload read as v2 (a stored v1 one up-converted with `sandbox: null`); throws. */
21
+ export declare function readRecordedPermissionContext(payload: unknown): PermissionContextV2;
22
+ /** The canonical hash of a recorded device sandbox block (request metadata `sandbox`). */
23
+ export declare const permissionSandboxHash: (sandbox: PermissionContextSandbox) => string;
24
+ export declare const permissionContextHash: (payload: PermissionContextV2) => string;
16
25
  export declare const managedDevicePathsHash: (payload: ManagedDevicePathsV1) => string;
17
- export declare const permissionContextIdemKey: (payload: PermissionContextV1, previousSeq: number) => string;
26
+ export declare const permissionContextIdemKey: (payload: PermissionContextV2, previousSeq: number) => string;
18
27
  export declare const managedDevicePathsIdemKey: (payload: ManagedDevicePathsV1, previousSeq: number) => string;
19
28
  export declare function permissionContextAt(events: readonly ConversationEvent[], seq: number): Extract<ConversationEvent, {
20
29
  type: "permission_context";
21
30
  }> | undefined;
22
31
  /**
23
32
  * Snapshot validation for raw (cast) events: every `permission_context` and every `device_paths`
24
- * carrying a marker must satisfy its strict v1 schema, covered or not, before any rendering; an
33
+ * carrying a marker must satisfy its strict schema, covered or not, before any rendering; an
25
34
  * unsupported version must never fall back to historical text. Unmarked paths keep their parser.
26
35
  */
27
36
  export declare function assertRecordedPermissionEvents(events: readonly ConversationEvent[]): void;
@@ -32,7 +41,7 @@ export interface PermissionContribution {
32
41
  export declare function permissionContextMeta(events: readonly ConversationEvent[], contributions: readonly PermissionContribution[]): PermissionContextMetaV1 | undefined;
33
42
  /**
34
43
  * One traversal for request rendering and original-coordinate replay diagnostics. Both callers get
35
- * the same marker rule: a present marker or version that fails its strict v1 schema (covered by a
44
+ * the same marker rule: a present marker or version that fails its strict schema (covered by a
36
45
  * summary or not) throws {@link RecordedPermissionContextError} before anything renders, so it is
37
46
  * never shown as historical device-mode text nor surfaces as a raw schema error. Unmarked events
38
47
  * are left to their historical rendering.
@@ -1,17 +1,17 @@
1
1
  import { createHash } from "node:crypto";
2
- import { ManagedDevicePathsV1Schema, PermissionContextV1Schema, permissionCodePointCompare, } from "../../conversations/events.js";
3
- /** A recorded log carries a present v1 marker or version that its strict schema rejects. */
2
+ import { ManagedDevicePathsV1Schema, PermissionContextV2Schema, permissionCodePointCompare, RecordedPermissionContextSchema, } from "../../conversations/events.js";
3
+ /** A recorded log carries a present marker or version that its strict schema rejects. */
4
4
  export class RecordedPermissionContextError extends Error {
5
5
  seq;
6
6
  eventType;
7
7
  name = "RecordedPermissionContextError";
8
8
  constructor(seq, eventType) {
9
- super(`Recorded ${eventType} event at seq ${seq} has an unsupported version or an invalid v1 payload`);
9
+ super(`Recorded ${eventType} event at seq ${seq} has an unsupported version or an invalid payload`);
10
10
  this.seq = seq;
11
11
  this.eventType = eventType;
12
12
  }
13
13
  }
14
- /** Canonical v1 bytes: explicit nulls, code-point object keys, validated array order. */
14
+ /** Canonical bytes: explicit nulls, code-point object keys, validated array order. */
15
15
  export function canonicalPermissionJson(value) {
16
16
  if (value === null || typeof value === "string" || typeof value === "boolean")
17
17
  return JSON.stringify(value);
@@ -40,14 +40,115 @@ const labels = {
40
40
  "approve-for-me": "Approve for me",
41
41
  "full-access": "Full access",
42
42
  };
43
+ const ESCALATE = 'set `sandbox: "escalated"` with a justification';
44
+ function networkLine(s) {
45
+ switch (s.network.kind) {
46
+ case "none":
47
+ return "Network: no destinations are authorized for new commands.";
48
+ case "allowlist":
49
+ return `Network: new commands may reach only these authorized hosts: ${arrayText(s.network.hosts)}.`;
50
+ case "open-public":
51
+ return "Network: the open public internet; private, LAN, loopback, link-local and metadata addresses are closed inside the sandbox.";
52
+ case "environment":
53
+ return s.location === "local"
54
+ ? "Network: the host environment; restricted-profile host lists do not restrict Full access."
55
+ : "Network: the provisioned environment, subject to its outer network boundary.";
56
+ }
57
+ }
58
+ function outerLine(outer) {
59
+ switch (outer.kind) {
60
+ case "host-environment":
61
+ return "Outer network boundary: the host environment.";
62
+ case "none":
63
+ return "Outer network boundary: network access is disabled.";
64
+ case "allowlist":
65
+ return `Outer network boundary: allowed hosts ${arrayText(outer.hosts)}.`;
66
+ case "open-public":
67
+ return "Outer network boundary: public addresses only.";
68
+ }
69
+ }
70
+ /** Hosts on a sandbox whose network covers the whole instance: no call can add one. */
71
+ const instanceHostsLine = (box) => `${box.network.kind === "none" ? "Network hosts" : "Hosts outside the network allowlist"}: not approvable per call on this device; the device's host list must include them.`;
72
+ /**
73
+ * Who approves each crossing kind under the recorded sandbox (approval-only profiles design,
74
+ * "Profiles"). The escalation clause appears only where running outside the sandbox is available:
75
+ * an operation-boundary sandbox whose device allows it, in an interactive run.
76
+ */
77
+ function approverLines(p, box) {
78
+ if (p.execution === "scheduled")
79
+ return [
80
+ "Scheduled run: only the unattended policy and explicit task grants apply; interactive approvals and chat Full access do not apply.",
81
+ ];
82
+ const instance = box.boundary === "instance";
83
+ const escalation = box.outsideSandbox && !instance;
84
+ if (p.effectiveProfile === "full-access") {
85
+ const lines = [
86
+ `Full access: commands run in the sandbox; crossings this device allows are approved automatically${escalation ? `; to run a command outside the sandbox ${ESCALATE}` : ""}.`,
87
+ ];
88
+ // a host no call can add (an instance-boundary allowlist) is not approved automatically
89
+ // either; only a block that records `perCallHosts` says so (a stored one renders its bytes)
90
+ if (box.perCallHosts === false && box.network.kind !== "open-public")
91
+ lines.push(instanceHostsLine(box));
92
+ // a sub-agent's escalation is never auto-granted: the review model decides it; nor is an
93
+ // escalation that touches credentials (maintainer ruling 2026-11-19)
94
+ if (escalation && p.inherited)
95
+ lines.push("In this sub-agent, a separate reviewer decides each escalation; uncertainty asks the person.");
96
+ else if (escalation)
97
+ lines.push("An escalation that reads, prints or links credentials goes to a separate reviewer instead; uncertainty asks the person.");
98
+ return lines;
99
+ }
100
+ const approver = p.effectiveProfile === "request-approval"
101
+ ? "the person approves"
102
+ : "a separate reviewer approves; uncertainty asks the person";
103
+ const lines = [];
104
+ if (!instance)
105
+ lines.push(`Directories outside the readable or writable directories: ${approver}.`);
106
+ // `none` is both an allowlist without hosts and the kill switch, which the block does not tell
107
+ // apart: the line names the approver and leaves the device's network switch to the device
108
+ if (box.network.kind !== "open-public")
109
+ lines.push(instance
110
+ ? instanceHostsLine(box)
111
+ : box.network.kind === "none"
112
+ ? `Network hosts (none authorized yet): ${approver}, where this device allows network access.`
113
+ : `Hosts outside the network allowlist: ${approver}.`);
114
+ if (escalation)
115
+ lines.push(`Running a command outside the sandbox: ${approver}; ${ESCALATE}.`);
116
+ lines.push(`Sensitive commands: ${approver}.`);
117
+ return lines;
118
+ }
119
+ /**
120
+ * The policy line of a supported context that records no sandbox block: only a stored version 1
121
+ * context read as version 2 (the producer always records the block). It renders the bytes that
122
+ * context rendered as version 1, so replaying a stored log never drifts.
123
+ */
124
+ function unsandboxedPolicyLine(p) {
125
+ return p.execution === "scheduled"
126
+ ? "Scheduled run: only the unattended policy and explicit task grants apply; interactive approvals and chat Full access do not apply."
127
+ : p.effectiveProfile === "request-approval"
128
+ ? "Extra filesystem or network scope requires the person's approval."
129
+ : p.effectiveProfile === "approve-for-me"
130
+ ? "A separate reviewer may approve eligible extra scope; uncertainty asks the person."
131
+ : "No discretionary command approval; explicit policy, device-owner limits and OS permissions still apply.";
132
+ }
133
+ /**
134
+ * The model-facing text of a recorded context: the sandbox once (its boundary, directories and
135
+ * network), then the approver per crossing kind. A supported context without a sandbox block
136
+ * keeps the profile-level policy line.
137
+ */
43
138
  export function permissionContextText(payload) {
44
- const p = PermissionContextV1Schema.parse(payload);
139
+ // a stored v1 payload renders as its up-converted form: the same bytes it rendered as v1
140
+ const p = readRecordedPermissionContext(payload);
45
141
  const s = p.scope;
142
+ const box = p.sandbox;
46
143
  const lines = [
47
144
  `Permission context for new operations: ${p.availability.state === "supported" && p.effectiveProfile !== null ? labels[p.effectiveProfile] : "unavailable"}.`,
48
145
  "This context supersedes earlier device-mode descriptions for new operations.",
49
146
  ];
50
147
  if (s !== null) {
148
+ if (box !== null)
149
+ lines.push(box.boundary === "instance"
150
+ ? "Sandbox: the same under every profile; the provisioned device instance is the sandbox, its whole filesystem is in scope and its outer network applies."
151
+ : "Sandbox: the same under every profile; new commands run in the device's OS sandbox, limited to the directories and network below.");
51
152
  lines.push(`Working directory: ${permissionQuote(s.workingRoot)}.`);
52
153
  if (s.filesystem.kind === "scoped") {
53
154
  lines.push(`Readable directories: ${arrayText(s.filesystem.readDirectories)}.`, `Writable directories: ${arrayText(s.filesystem.writeDirectories)}.`);
@@ -56,40 +157,11 @@ export function permissionContextText(payload) {
56
157
  lines.push(s.location === "local"
57
158
  ? "Filesystem: this device as the existing OS user; no additional OS privileges."
58
159
  : "Filesystem: the provisioned device environment as its existing OS user; no additional OS privileges.");
59
- switch (s.network.kind) {
60
- case "none":
61
- lines.push("Network: no destinations are authorized for new commands.");
62
- break;
63
- case "allowlist":
64
- lines.push(`Network: new commands may reach only these authorized hosts: ${arrayText(s.network.hosts)}.`);
65
- break;
66
- case "environment":
67
- lines.push(s.location === "local"
68
- ? "Network: the host environment; restricted-profile host lists do not restrict Full access."
69
- : "Network: the provisioned environment, subject to its outer network boundary.");
70
- break;
71
- }
72
- switch (s.outerNetwork.kind) {
73
- case "host-environment":
74
- lines.push("Outer network boundary: the host environment.");
75
- break;
76
- case "none":
77
- lines.push("Outer network boundary: network access is disabled.");
78
- break;
79
- case "allowlist":
80
- lines.push(`Outer network boundary: allowed hosts ${arrayText(s.outerNetwork.hosts)}.`);
81
- break;
82
- case "open-public":
83
- lines.push("Outer network boundary: public addresses only.");
84
- break;
85
- }
86
- lines.push(p.execution === "scheduled"
87
- ? "Scheduled run: only the unattended policy and explicit task grants apply; interactive approvals and chat Full access do not apply."
88
- : p.effectiveProfile === "request-approval"
89
- ? "Extra filesystem or network scope requires the person's approval."
90
- : p.effectiveProfile === "approve-for-me"
91
- ? "A separate reviewer may approve eligible extra scope; uncertainty asks the person."
92
- : "No discretionary command approval; explicit policy, device-owner limits and OS permissions still apply.");
160
+ lines.push(networkLine(s), outerLine(s.outerNetwork));
161
+ if (box !== null)
162
+ lines.push(...approverLines(p, box));
163
+ else
164
+ lines.push(unsandboxedPolicyLine(p));
93
165
  }
94
166
  else if (p.availability.state !== "supported") {
95
167
  lines.push(`Device operations are ${p.availability.state === "unprobed" ? "unverified" : "unavailable"}: ${permissionQuote(p.availability.reason)}.`);
@@ -101,14 +173,20 @@ export function managedDevicePathsText(payload) {
101
173
  const p = ManagedDevicePathsV1Schema.parse(payload);
102
174
  return `Device directories: workspace ${permissionQuote(p.roots.workspace)}, skills ${permissionQuote(p.roots.skills)}, temporary files ${permissionQuote(p.roots.tmp)}.\nSelected working directory: ${permissionQuote(p.workingRoot)}. These paths do not grant access; the current permission context governs new operations.`;
103
175
  }
104
- export const permissionContextHash = (payload) => hash(["permission_context", 1, PermissionContextV1Schema.parse(payload)]);
176
+ /** A recorded payload read as v2 (a stored v1 one up-converted with `sandbox: null`); throws. */
177
+ export function readRecordedPermissionContext(payload) {
178
+ return RecordedPermissionContextSchema.parse(payload);
179
+ }
180
+ /** The canonical hash of a recorded device sandbox block (request metadata `sandbox`). */
181
+ export const permissionSandboxHash = (sandbox) => hash(["permission_sandbox", 2, sandbox]);
182
+ export const permissionContextHash = (payload) => hash(["permission_context", 2, PermissionContextV2Schema.parse(payload)]);
105
183
  export const managedDevicePathsHash = (payload) => hash(["device_paths", 1, ManagedDevicePathsV1Schema.parse(payload)]);
106
184
  function predecessor(seq) {
107
185
  if (!Number.isSafeInteger(seq) || seq < 0)
108
186
  throw new TypeError("Permission predecessor must be a nonnegative safe integer");
109
187
  return seq;
110
188
  }
111
- export const permissionContextIdemKey = (payload, previousSeq) => `permission_context:v1:${permissionContextHash(payload)}:${predecessor(previousSeq)}`;
189
+ export const permissionContextIdemKey = (payload, previousSeq) => `permission_context:v2:${permissionContextHash(payload)}:${predecessor(previousSeq)}`;
112
190
  export const managedDevicePathsIdemKey = (payload, previousSeq) => `device_paths:permission-v1:${managedDevicePathsHash(payload)}:${predecessor(previousSeq)}`;
113
191
  export function permissionContextAt(events, seq) {
114
192
  let latest;
@@ -121,13 +199,13 @@ export function permissionContextAt(events, seq) {
121
199
  }
122
200
  /**
123
201
  * Snapshot validation for raw (cast) events: every `permission_context` and every `device_paths`
124
- * carrying a marker must satisfy its strict v1 schema, covered or not, before any rendering; an
202
+ * carrying a marker must satisfy its strict schema, covered or not, before any rendering; an
125
203
  * unsupported version must never fall back to historical text. Unmarked paths keep their parser.
126
204
  */
127
205
  export function assertRecordedPermissionEvents(events) {
128
206
  for (const e of events) {
129
207
  if (e.type === "permission_context") {
130
- if (!PermissionContextV1Schema.safeParse(e.payload).success)
208
+ if (!RecordedPermissionContextSchema.safeParse(e.payload).success)
131
209
  throw new RecordedPermissionContextError(e.seq, e.type);
132
210
  }
133
211
  else if (e.type === "device_paths" &&
@@ -142,15 +220,18 @@ export function assertRecordedPermissionEvents(events) {
142
220
  export function permissionContextMeta(events, contributions) {
143
221
  if (contributions.length === 0)
144
222
  return undefined;
223
+ const located = permissionContextAt(events, Number.POSITIVE_INFINITY);
224
+ const sandbox = located?.payload.sandbox ?? null;
145
225
  return {
146
226
  version: 1,
147
- contextSeq: permissionContextAt(events, Number.POSITIVE_INFINITY)?.seq ?? null,
227
+ contextSeq: located?.seq ?? null,
148
228
  hash: hash([1, contributions.map(({ type, text }) => [type, text])]),
229
+ ...(sandbox !== null && { sandbox: permissionSandboxHash(sandbox) }),
149
230
  };
150
231
  }
151
232
  /**
152
233
  * One traversal for request rendering and original-coordinate replay diagnostics. Both callers get
153
- * the same marker rule: a present marker or version that fails its strict v1 schema (covered by a
234
+ * the same marker rule: a present marker or version that fails its strict schema (covered by a
154
235
  * summary or not) throws {@link RecordedPermissionContextError} before anything renders, so it is
155
236
  * never shown as historical device-mode text nor surfaces as a raw schema error. Unmarked events
156
237
  * are left to their historical rendering.
@@ -14,7 +14,7 @@ export { PERMISSION_CONTEXT_RUN_ERRORS };
14
14
  * to what the run sees, before any request is sent: a revoked or replaced execution keeps its
15
15
  * identical `ExecutionRevoked` object, an abort keeps its reason, a `RunError` passes, and every
16
16
  * other failure becomes one of the named run errors. A recorded `permission_context` (or marked
17
- * path) the strict v1 schema rejects is `run.permission_context_invalid`, never a provider error
17
+ * path) its strict schema rejects is `run.permission_context_invalid`, never a provider error
18
18
  * and never rendered as historical text.
19
19
  */
20
20
  export declare function permissionContextFailure(error: unknown, signal?: AbortSignal): unknown;
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { SandboxScopeDeniedError } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { EventLog } from "../conversations/event-log.js";
13
- import { PermissionContextV1Schema } from "../conversations/events.js";
13
+ import { RecordedPermissionContextSchema } from "../conversations/events.js";
14
14
  import { PermissionProfileStore } from "../conversations/permission-profile-store.js";
15
15
  import { ApiError } from "../errors.js";
16
16
  import { afterCommit } from "../infra/database/after-commit.js";
@@ -37,7 +37,7 @@ class RecorderRefused extends Error {
37
37
  * to what the run sees, before any request is sent: a revoked or replaced execution keeps its
38
38
  * identical `ExecutionRevoked` object, an abort keeps its reason, a `RunError` passes, and every
39
39
  * other failure becomes one of the named run errors. A recorded `permission_context` (or marked
40
- * path) the strict v1 schema rejects is `run.permission_context_invalid`, never a provider error
40
+ * path) its strict schema rejects is `run.permission_context_invalid`, never a provider error
41
41
  * and never rendered as historical text.
42
42
  */
43
43
  export function permissionContextFailure(error, signal) {
@@ -242,9 +242,11 @@ let PermissionContextRecorder = class PermissionContextRecorder {
242
242
  .executeTakeFirst();
243
243
  const previousSeq = latest ? Number(latest.seq) : 0;
244
244
  if (latest) {
245
- const prior = PermissionContextV1Schema.safeParse(latest.payload);
245
+ const prior = RecordedPermissionContextSchema.safeParse(latest.payload);
246
246
  if (!prior.success)
247
247
  throw new RecordedPermissionContextError(previousSeq, "permission_context");
248
+ // a stored v1 prior compares as its up-converted form (v2, sandbox null): identical
249
+ // content appends nothing, whatever version the row was written in
248
250
  if (permissionContextHash(prior.data) === permissionContextHash(payload))
249
251
  return null;
250
252
  }