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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/admin/admin.schemas.d.ts +11 -1
  2. package/dist/catalog/catalog.module.js +1 -1
  3. package/dist/catalog/marketplaces.service.d.ts +1 -1
  4. package/dist/catalog/requests.service.d.ts +5 -5
  5. package/dist/catalog/requests.service.js +9 -9
  6. package/dist/channels/cards.d.ts +4 -3
  7. package/dist/channels/cards.js +25 -16
  8. package/dist/channels/phrases.d.ts +15 -4
  9. package/dist/channels/phrases.js +15 -1
  10. package/dist/config/load.d.ts +26 -7
  11. package/dist/config/load.js +60 -9
  12. package/dist/config/permission-migration.d.ts +17 -9
  13. package/dist/config/permission-migration.js +60 -9
  14. package/dist/config/schema.d.ts +15 -1
  15. package/dist/config/schema.js +66 -11
  16. package/dist/conversations/events.d.ts +247 -5
  17. package/dist/conversations/events.js +127 -16
  18. package/dist/conversations/permission-profiles.controller.d.ts +12 -2
  19. package/dist/conversations/permission-profiles.service.d.ts +12 -2
  20. package/dist/conversations/permission-profiles.service.js +11 -4
  21. package/dist/db/kernel-schema.d.ts +18 -2
  22. package/dist/devices/device-projects.service.d.ts +1 -1
  23. package/dist/devices/device-projects.service.js +6 -6
  24. package/dist/devices/devices.controller.d.ts +10 -8
  25. package/dist/devices/devices.controller.js +14 -18
  26. package/dist/devices/devices.schemas.d.ts +5 -5
  27. package/dist/devices/devices.schemas.js +5 -5
  28. package/dist/devices/devices.service.d.ts +188 -175
  29. package/dist/devices/devices.service.js +284 -292
  30. package/dist/devices/dto.d.ts +43 -23
  31. package/dist/devices/dto.js +45 -49
  32. package/dist/devices/project-rules.d.ts +0 -10
  33. package/dist/devices/project-rules.js +0 -5
  34. package/dist/errors.d.ts +43 -19
  35. package/dist/errors.js +43 -19
  36. package/dist/evals/reconstruct.d.ts +12 -3
  37. package/dist/evals/reconstruct.js +10 -6
  38. package/dist/evals/recorded-permission-context.d.ts +6 -4
  39. package/dist/evals/recorded-permission-context.js +15 -9
  40. package/dist/evals/run-replay.d.ts +6 -1
  41. package/dist/evals/run-replay.js +7 -2
  42. package/dist/evals/worker.js +3 -1
  43. package/dist/http/api.module.js +8 -0
  44. package/dist/http/app.js +9 -0
  45. package/dist/http/meta.controller.d.ts +33 -0
  46. package/dist/http/meta.controller.js +72 -0
  47. package/dist/identity/app-auth.controller.d.ts +25 -0
  48. package/dist/identity/app-auth.controller.js +64 -0
  49. package/dist/identity/app-auth.d.ts +66 -0
  50. package/dist/identity/app-auth.js +203 -0
  51. package/dist/identity/app-auth.schemas.d.ts +47 -0
  52. package/dist/identity/app-auth.schemas.js +43 -0
  53. package/dist/identity/identity.module.d.ts +1 -1
  54. package/dist/identity/identity.module.js +4 -1
  55. package/dist/identity/settings.d.ts +45 -18
  56. package/dist/identity/settings.js +151 -51
  57. package/dist/infra/config/kernel-config.service.d.ts +1 -1
  58. package/dist/infra/config/kernel-config.service.js +19 -5
  59. package/dist/infra/outbox/registry.d.ts +14 -0
  60. package/dist/infra/outbox/registry.js +15 -0
  61. package/dist/infra/throttler/named-throttlers.d.ts +3 -2
  62. package/dist/infra/throttler/named-throttlers.js +14 -2
  63. package/dist/local-devices/device-auth.controller.d.ts +1 -1
  64. package/dist/local-devices/device-auth.controller.js +1 -1
  65. package/dist/local-devices/device-auth.d.ts +4 -4
  66. package/dist/local-devices/device-auth.js +1 -1
  67. package/dist/local-devices/device-policy.service.d.ts +18 -9
  68. package/dist/local-devices/device-policy.service.js +21 -61
  69. package/dist/local-devices/device-routes.d.ts +3 -1
  70. package/dist/local-devices/device-routes.js +15 -4
  71. package/dist/local-devices/instance-bindings.js +5 -2
  72. package/dist/local-devices/local-device-gateway.d.ts +2 -2
  73. package/dist/local-devices/local-device-gateway.js +3 -3
  74. package/dist/local-devices/local-device-provider.d.ts +4 -4
  75. package/dist/local-devices/local-device-provider.js +23 -9
  76. package/dist/local-devices/local-devices.module.d.ts +1 -1
  77. package/dist/local-devices/local-devices.module.js +1 -1
  78. package/dist/local-devices/machines.d.ts +40 -16
  79. package/dist/local-devices/machines.js +89 -61
  80. package/dist/local-devices/owner-report.d.ts +16 -14
  81. package/dist/local-devices/owner-report.js +24 -30
  82. package/dist/local-devices/owner-reports.js +26 -8
  83. package/dist/local-devices/policy-summary.d.ts +25 -44
  84. package/dist/local-devices/policy-summary.js +26 -71
  85. package/dist/local-devices/relay.d.ts +6 -6
  86. package/dist/local-devices/relay.js +10 -8
  87. package/dist/net/public-address.d.ts +1 -1
  88. package/dist/net/public-address.js +5 -2
  89. package/dist/orgs/device-network-setting.d.ts +82 -0
  90. package/dist/orgs/device-network-setting.js +142 -0
  91. package/dist/orgs/settings.service.d.ts +103 -66
  92. package/dist/orgs/settings.service.js +201 -137
  93. package/dist/overrides.d.ts +5 -1
  94. package/dist/overrides.js +2 -0
  95. package/dist/platform/exclusions.js +24 -1
  96. package/dist/platform/operation.js +2 -2
  97. package/dist/platform/ops/admin.ops.js +20 -11
  98. package/dist/platform/ops/devices.ops.js +70 -5
  99. package/dist/platform/ops/org-settings.ops.js +10 -6
  100. package/dist/platform/ops/orgs.ops.js +2 -1
  101. package/dist/platform/ops/platform-icons.ops.d.ts +14 -0
  102. package/dist/platform/ops/platform-icons.ops.js +117 -0
  103. package/dist/platform/platform-ops.module.d.ts +2 -1
  104. package/dist/platform/platform-ops.module.js +3 -0
  105. package/dist/platform/route-schemas.js +3 -0
  106. package/dist/runtime/context/permission-profile.d.ts +17 -8
  107. package/dist/runtime/context/permission-profile.js +126 -45
  108. package/dist/runtime/maintenance.d.ts +5 -2
  109. package/dist/runtime/maintenance.js +15 -4
  110. package/dist/runtime/permission-context.service.d.ts +1 -1
  111. package/dist/runtime/permission-context.service.js +5 -3
  112. package/dist/runtime/project/knowledge.d.ts +5 -4
  113. package/dist/runtime/project/knowledge.js +2 -1
  114. package/dist/runtime/project/knowledge.service.js +16 -13
  115. package/dist/sandbox/cloud-permission-snapshot.js +22 -3
  116. package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
  117. package/dist/sandbox/device-sandbox-settings.js +470 -0
  118. package/dist/sandbox/device-sandbox.d.ts +187 -0
  119. package/dist/sandbox/device-sandbox.js +236 -0
  120. package/dist/sandbox/held-operations.js +15 -7
  121. package/dist/sandbox/modes.d.ts +49 -24
  122. package/dist/sandbox/modes.js +27 -19
  123. package/dist/sandbox/operation-authority-types.d.ts +6 -5
  124. package/dist/sandbox/operation-authority-types.js +7 -8
  125. package/dist/sandbox/operation-authority.d.ts +23 -9
  126. package/dist/sandbox/operation-authority.js +179 -97
  127. package/dist/sandbox/permission-auto-grants.d.ts +42 -0
  128. package/dist/sandbox/permission-auto-grants.js +145 -0
  129. package/dist/sandbox/permission-call-grants.d.ts +12 -4
  130. package/dist/sandbox/permission-call-grants.js +84 -35
  131. package/dist/sandbox/permission-call-grants.module.js +10 -3
  132. package/dist/sandbox/permission-call-types.d.ts +39 -5
  133. package/dist/sandbox/permission-ceiling-writes.d.ts +29 -3
  134. package/dist/sandbox/permission-ceiling-writes.js +38 -4
  135. package/dist/sandbox/permission-config-publication.d.ts +44 -2
  136. package/dist/sandbox/permission-config-publication.js +230 -59
  137. package/dist/sandbox/permission-context-types.d.ts +2 -2
  138. package/dist/sandbox/permission-facts.d.ts +144 -15
  139. package/dist/sandbox/permission-facts.js +258 -70
  140. package/dist/sandbox/permission-runtime-reports.d.ts +5 -4
  141. package/dist/sandbox/permission-runtime-reports.js +19 -29
  142. package/dist/sandbox/review/classifier.d.ts +8 -0
  143. package/dist/sandbox/review/classifier.js +10 -0
  144. package/dist/sandbox/review/permission-candidate.d.ts +69 -5
  145. package/dist/sandbox/review/permission-candidate.js +153 -30
  146. package/dist/sandbox/review/review.service.d.ts +19 -3
  147. package/dist/sandbox/review/review.service.js +59 -11
  148. package/dist/sandbox/review/rules.js +23 -3
  149. package/dist/sandbox/sandbox.service.d.ts +29 -11
  150. package/dist/sandbox/sandbox.service.js +51 -26
  151. package/dist/skills/invoke.js +3 -2
  152. package/dist/themes/platform-icon-objects.d.ts +51 -0
  153. package/dist/themes/platform-icon-objects.js +113 -0
  154. package/dist/themes/platform-icon-public.controller.d.ts +17 -0
  155. package/dist/themes/platform-icon-public.controller.js +58 -0
  156. package/dist/themes/platform-icon.controller.d.ts +22 -0
  157. package/dist/themes/platform-icon.controller.js +65 -0
  158. package/dist/themes/platform-icon.schemas.d.ts +48 -0
  159. package/dist/themes/platform-icon.schemas.js +53 -0
  160. package/dist/themes/platform-icon.service.d.ts +83 -0
  161. package/dist/themes/platform-icon.service.js +301 -0
  162. package/dist/themes/themes.module.d.ts +4 -1
  163. package/dist/themes/themes.module.js +9 -4
  164. package/dist/tools/approvals.service.d.ts +26 -116
  165. package/dist/tools/approvals.service.js +42 -346
  166. package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
  167. package/dist/tools/builtins/sandbox/bash.js +80 -28
  168. package/dist/tools/builtins/sandbox/common.d.ts +39 -14
  169. package/dist/tools/builtins/sandbox/common.js +47 -24
  170. package/dist/tools/builtins/sandbox/deliver.js +7 -4
  171. package/dist/tools/builtins/skill-load.d.ts +2 -2
  172. package/dist/tools/builtins/skill-load.js +4 -3
  173. package/dist/tools/device-op-resolver.d.ts +4 -10
  174. package/dist/tools/device-op-resolver.js +8 -19
  175. package/dist/tools/network-asks.d.ts +52 -15
  176. package/dist/tools/network-asks.js +55 -25
  177. package/dist/tools/pipeline.d.ts +26 -14
  178. package/dist/tools/pipeline.js +144 -61
  179. package/dist/tools/registry.d.ts +6 -0
  180. package/dist/tools/tools.module.js +1 -1
  181. package/package.json +4 -4
  182. package/src/migrations/0164_platform_icons.sql +10 -0
  183. package/src/migrations/0165_device_network_columns.sql +50 -0
  184. package/src/migrations/0166_permission_grant_full_access.sql +17 -0
  185. package/src/migrations/0167_device_network_backfill.sql +32 -0
  186. package/src/migrations/0168_binding_installed_connection.sql +6 -0
  187. package/dist/orgs/cloud-network-setting.d.ts +0 -33
  188. package/dist/orgs/cloud-network-setting.js +0 -47
  189. package/dist/sandbox/platform-full-access.d.ts +0 -110
  190. package/dist/sandbox/platform-full-access.js +0 -198
@@ -1,16 +1,17 @@
1
- import { type PermissionProfile, type SandboxActor, type SandboxBrowseScope, type SandboxOperationScope } from "@capybara-hq/plugin-sdk";
2
- import { type PermissionContextV1 } from "../conversations/events.js";
1
+ import { type PermissionProfile, type SandboxActor, type SandboxBoundary, type SandboxBrowseScope, type SandboxOperationScope } from "@capybara-hq/plugin-sdk";
2
+ import { type PermissionContextV2 } from "../conversations/events.js";
3
3
  import { PermissionProfileStore } from "../conversations/permission-profile-store.js";
4
4
  import { KernelDb } from "../infra/database/kernel-db.js";
5
5
  import { TransactionHost } from "../infra/database/transaction-host.js";
6
6
  import { NetworkGrants } from "../local-devices/network-grants.js";
7
+ import type { DeviceSandbox } from "./device-sandbox.js";
7
8
  import { type KernelReadInvocation, type KernelReadMethod } from "./kernel-read.js";
8
9
  import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
9
10
  import { PermissionAuthorityLock } from "./permission-authority-lock.js";
10
11
  import { PermissionCallGrants } from "./permission-call-grants.js";
11
12
  import type { PermissionCallRef, PermissionReviewSnapshot } from "./permission-call-types.js";
12
13
  import { PermissionConfigPublication } from "./permission-config-publication.js";
13
- import type { AppliedEnvironment } from "./permission-context-types.js";
14
+ import type { AppliedEnvironment, AppliedOuterNetwork } from "./permission-context-types.js";
14
15
  import { type PermissionContextSubject } from "./permission-context-types.js";
15
16
  import { PermissionFacts } from "./permission-facts.js";
16
17
  import type { SandboxUseContext } from "./use-context.js";
@@ -29,16 +30,29 @@ export interface PermissionScopeFacts {
29
30
  readRoots: readonly string[];
30
31
  writeRoots: readonly string[];
31
32
  allowedHosts: readonly string[];
32
- fullAccessCeiling: boolean;
33
- fullConsent?: boolean;
33
+ /** The sandbox network of the call ({@link sandboxNetworkOf}); `allowlist` uses `allowedHosts`. */
34
+ network: "open-public" | "allowlist" | "none";
35
+ /** The provider's boundary: an `instance` device's scope is its whole filesystem. */
36
+ boundary: SandboxBoundary;
37
+ outsideSandboxCeiling: boolean;
34
38
  /**
35
39
  * An approved per-call sandbox escalation of this exact call (its immutable call grant): the
36
- * operation gets full execution under the conversation's restricted profile, within the same
37
- * Full access ceiling. Only admission sets it, from the grant row; never a caller.
40
+ * operation runs outside the sandbox, within the device's outside-sandbox ceiling, under any
41
+ * profile. Only admission sets it, from the grant row; never a caller.
38
42
  */
39
43
  escalated?: boolean;
40
44
  }
41
- /** Only server-resolved facts enter this constructor; callers never submit roots or profile. */
45
+ /**
46
+ * The sandbox network of a call: the device sandbox's mode within a cloud instance's applied outer
47
+ * boundary (an open network never sits inside an allowlisted or disabled one); `allowlist` takes
48
+ * the call's hosts, and an allowlist without hosts is `none` at the scope.
49
+ */
50
+ export declare function sandboxNetworkOf(box: Pick<DeviceSandbox, "networkMode">, outer: AppliedOuterNetwork | null | undefined): "open-public" | "allowlist" | "none";
51
+ /**
52
+ * Only server-resolved facts enter this constructor; callers never submit roots or profile. It
53
+ * never branches on the profile: every call is sandboxed (scoped filesystem, the sandbox network),
54
+ * and only an escalated call within the outside-sandbox ceiling gets the device pair.
55
+ */
42
56
  export declare function intersectPermissionScope(f: PermissionScopeFacts): SandboxOperationScope;
43
57
  /** Fresh authority shape only. Provider dispatch must add durable admission fencing before use. */
44
58
  /**
@@ -155,5 +169,5 @@ export declare class SandboxOperationAuthority {
155
169
  * (no request is sent); a device this actor cannot use is the logged access refusal; device
156
170
  * states admission refuses are unsupported or unprobed contexts without a scope.
157
171
  */
158
- readContextLocked(input: PermissionContextSubject, signal: AbortSignal): Promise<PermissionContextV1>;
172
+ readContextLocked(input: PermissionContextSubject, signal: AbortSignal): Promise<PermissionContextV2>;
159
173
  }
@@ -8,10 +8,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { randomUUID } from "node:crypto";
11
- import { parseSandboxBrowseScope, parseSandboxOperationScope, SandboxPermissionUnsupportedError, } from "@capybara-hq/plugin-sdk";
11
+ import { instanceSupported, parseSandboxBrowseScope, parseSandboxOperationScope, SandboxPermissionUnsupportedError, } from "@capybara-hq/plugin-sdk";
12
12
  import { Inject, Injectable } from "@nestjs/common";
13
13
  import { sql } from "kysely";
14
- import { ACTOR_DEVICE_ACCESS_REASON, ACTOR_NOT_DEVICE_OWNER_REASON, PermissionContextV1Schema, permissionCodePointCompare, } from "../conversations/events.js";
14
+ import { ACTOR_DEVICE_ACCESS_REASON, ACTOR_NOT_DEVICE_OWNER_REASON, PermissionContextV2Schema, permissionCodePointCompare, } from "../conversations/events.js";
15
15
  import { PermissionProfileStore, } from "../conversations/permission-profile-store.js";
16
16
  import { canonicalRoot, workingRootOf as reviewWorkingRootOf } from "../devices/working-root.js";
17
17
  import { ApiError } from "../errors.js";
@@ -19,6 +19,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
19
19
  import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
20
20
  import { Transactional } from "../infra/database/transactional.decorator.js";
21
21
  import { NetworkGrants } from "../local-devices/network-grants.js";
22
+ import { hostGrantable } from "./device-sandbox.js";
22
23
  import { KernelReadUnsupported, kernelReadRoot, kernelReadRoute, } from "./kernel-read.js";
23
24
  import { coversHost, projectReachOf } from "./modes.js";
24
25
  import { EscalationGrantMissingError, isExecutionMethod, parseStartingExecutionGrants, } from "./operation-authority-types.js";
@@ -28,7 +29,7 @@ import { PermissionCallGrants } from "./permission-call-grants.js";
28
29
  import { PermissionConfigPublication } from "./permission-config-publication.js";
29
30
  import { PermissionContextSubjectChanged, } from "./permission-context-types.js";
30
31
  import { hostsWithinOuter, PermissionFacts, permissionScopeHash } from "./permission-facts.js";
31
- import { ESCALATION_CEILING_WHY, ESCALATION_UNATTENDED_WHY, escalationRuntimeWhy, normalizePermissionExpansion, withinDirectory, } from "./review/permission-candidate.js";
32
+ import { ESCALATION_UNATTENDED_WHY, escalationCeilingWhy, escalationRuntimeWhy, normalizePermissionExpansion, runtimeWriteRootRefusal, withinDirectory, } from "./review/permission-candidate.js";
32
33
  const UNPROVED_ENVIRONMENT = "The device's installed environment is not verified yet; it is checked when the device starts";
33
34
  /**
34
35
  * The one verdict over a device's runtime report and its applied environment (B1, B-16): the
@@ -36,7 +37,8 @@ const UNPROVED_ENVIRONMENT = "The device's installed environment is not verified
36
37
  * admission refuses with the same reason, so the model is never told it can do what admission
37
38
  * refuses, nor the reverse (local and cloud devices alike, B-15). Unknown applied facts precede a
38
39
  * positive capability report; a working root that is not the installed workspace (no project) is
39
- * never installed scope.
40
+ * never installed scope. The sandbox is the same under every profile (support v2): a runtime that
41
+ * enforces per-operation scopes, or an instance-boundary provider whose instance is the sandbox.
40
42
  */
41
43
  function withheldScope(input) {
42
44
  const { availability, applied } = input;
@@ -46,14 +48,13 @@ function withheldScope(input) {
46
48
  applied.location !== input.location ||
47
49
  (input.projectPath === null && input.workingRoot !== applied.roots.workspace))
48
50
  return { state: "unprobed", reason: UNPROVED_ENVIRONMENT };
49
- if (input.effectiveProfile === "full-access") {
50
- if (!availability.report.fullAccess)
51
- return { state: "unsupported", reason: "This device's runtime cannot run Full access" };
52
- }
53
- else if (availability.report.restricted === null)
51
+ // a local machine's sandbox is per operation; only a cloud provider's instance is the sandbox
52
+ if (availability.report.boundary === "instance" && input.location === "local")
53
+ return { state: "unsupported", reason: "A local device cannot report an instance boundary" };
54
+ if (availability.report.restricted === null && !instanceSupported(availability.report))
54
55
  return {
55
56
  state: "unsupported",
56
- reason: "This device's runtime cannot enforce the restricted permission profiles",
57
+ reason: availability.report.unavailableReason ?? "This device's runtime cannot enforce its sandbox",
57
58
  };
58
59
  return null;
59
60
  }
@@ -62,15 +63,30 @@ function withheldScope(input) {
62
63
  * read root (a symlink out of the project is refused) whatever the conversation selected.
63
64
  */
64
65
  const KERNEL_READ_PROFILE = "request-approval";
65
- /** Only server-resolved facts enter this constructor; callers never submit roots or profile. */
66
+ /**
67
+ * The sandbox network of a call: the device sandbox's mode within a cloud instance's applied outer
68
+ * boundary (an open network never sits inside an allowlisted or disabled one); `allowlist` takes
69
+ * the call's hosts, and an allowlist without hosts is `none` at the scope.
70
+ */
71
+ export function sandboxNetworkOf(box, outer) {
72
+ if (box.networkMode === "none" || outer?.kind === "none")
73
+ return "none";
74
+ if (box.networkMode === "open" && outer?.kind !== "allowlist")
75
+ return "open-public";
76
+ return "allowlist";
77
+ }
78
+ /** An instance-boundary device's scope: its whole filesystem, plus the working root it names. */
79
+ const instanceRoots = (workingRoot) => [...new Set(["/", workingRoot])].sort(permissionCodePointCompare);
80
+ /**
81
+ * Only server-resolved facts enter this constructor; callers never submit roots or profile. It
82
+ * never branches on the profile: every call is sandboxed (scoped filesystem, the sandbox network),
83
+ * and only an escalated call within the outside-sandbox ceiling gets the device pair.
84
+ */
66
85
  export function intersectPermissionScope(f) {
67
- if (f.profile === "full-access" && (!f.fullConsent || !f.fullAccessCeiling))
68
- throw new ApiError("forbidden", "Full access requires current device authority and matching consent");
69
- // an escalated call runs with full execution: the same device, org and platform ceiling as Full
70
- // access, its consent the exact call grant (bound to the scope revision) instead of the profile's
71
- if (f.escalated && (f.profile === "full-access" || !f.fullAccessCeiling))
72
- throw new ApiError("forbidden", "A sandbox escalation requires a restricted profile and the current Full access ceiling");
73
- const full = f.profile === "full-access" || f.escalated === true;
86
+ if (f.escalated && (!f.outsideSandboxCeiling || f.boundary === "instance"))
87
+ throw new ApiError("forbidden", "Running outside the sandbox requires the device's current outside-sandbox ceiling");
88
+ const escalated = f.escalated === true;
89
+ const hosts = [...new Set(f.allowedHosts)].sort();
74
90
  return parseSandboxOperationScope({
75
91
  operationId: f.operationId,
76
92
  admitBeforeMs: f.admitBeforeMs,
@@ -81,18 +97,26 @@ export function intersectPermissionScope(f) {
81
97
  profile: f.profile,
82
98
  actor: f.actor,
83
99
  tag: f.tag,
84
- filesystem: full
100
+ filesystem: escalated
85
101
  ? { kind: "device" }
86
- : {
87
- kind: "scoped",
88
- readRoots: [...new Set([...f.readRoots, ...f.writeRoots])].sort(),
89
- writeRoots: [...new Set(f.writeRoots)].sort(),
90
- },
91
- network: full
102
+ : f.boundary === "instance"
103
+ ? {
104
+ kind: "scoped",
105
+ readRoots: instanceRoots(f.workingRoot),
106
+ writeRoots: instanceRoots(f.workingRoot),
107
+ }
108
+ : {
109
+ kind: "scoped",
110
+ readRoots: [...new Set([...f.readRoots, ...f.writeRoots])].sort(),
111
+ writeRoots: [...new Set(f.writeRoots)].sort(),
112
+ },
113
+ network: escalated
92
114
  ? { kind: "environment" }
93
- : f.allowedHosts.length
94
- ? { kind: "allowlist", hosts: [...new Set(f.allowedHosts)].sort() }
95
- : { kind: "none" },
115
+ : f.network === "open-public"
116
+ ? { kind: "open-public" }
117
+ : f.network === "allowlist" && hosts.length
118
+ ? { kind: "allowlist", hosts }
119
+ : { kind: "none" },
96
120
  });
97
121
  }
98
122
  /** Fresh authority shape only. Provider dispatch must add durable admission fencing before use. */
@@ -141,7 +165,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
141
165
  throw new ApiError("device.not_found", "Device not found");
142
166
  await this.facts.preview(ctx.orgId, ctx.accountId, ctx.deviceId);
143
167
  const scope = await this.facts.projectScope(ctx.orgId, ctx.accountId, ctx.deviceId);
144
- if (!scope.supported || scope.widerThanAllowed)
168
+ if (!scope.supported)
145
169
  throw new ApiError("device.projects_unsupported", "Current owner and organization ceilings do not permit browsing");
146
170
  const operationId = randomUUID();
147
171
  const vector = await this.epochs.readLocked({ orgId: ctx.orgId, deviceId: ctx.deviceId });
@@ -247,14 +271,13 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
247
271
  resolvedInputHash: permissionInput.resolvedInputHash,
248
272
  })
249
273
  : null;
250
- // full execution for this exact call's command only (a native method of the same call keeps
251
- // the base scope): the same checks as Full access, now
274
+ // outside the sandbox for this exact call's command only (a native method of the same call
275
+ // keeps the base scope), under any profile: Full access auto-grants it, never skips the grant
252
276
  const escalated = grant?.scopeKind === "sandbox-escalation" && isExecutionMethod(operation);
253
- // a call that asked to run outside the sandbox under a restricted profile runs escalated or
254
- // not at all: a missed grant (the device, ceiling or scope changed since the approval) or a
255
- // ceiling that no longer allows it is a pre-effect refusal, never a sandboxed run
277
+ // a call that asked to run outside the sandbox runs escalated or not at all: a missed grant
278
+ // (the device, ceiling or scope changed since the approval) or a ceiling that no longer allows
279
+ // it is a pre-effect refusal, never a sandboxed run
256
280
  if (requested === "escalated" &&
257
- f.profile !== "full-access" &&
258
281
  isExecutionMethod(operation) &&
259
282
  (!escalated || f.escalationRefusal))
260
283
  throw new EscalationGrantMissingError(f.escalationRefusal
@@ -262,15 +285,26 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
262
285
  : "The call's sandbox escalation grant no longer matches");
263
286
  if (!escalated && grant && grant.scopeKind !== "sandbox-escalation") {
264
287
  normalizePermissionExpansion(grant.expansion, f);
288
+ // never a system runtime or socket directory as a write root, whatever approved it
289
+ const runtime = grant.expansion.writeDirectories
290
+ .map((root) => runtimeWriteRootRefusal(root))
291
+ .find((refusal) => refusal !== null);
292
+ if (runtime)
293
+ throw new ApiError("forbidden", runtime);
265
294
  if ((!f.broadProjectReach &&
266
295
  (grant.expansion.readDirectories.length || grant.expansion.writeDirectories.length)) ||
267
- grant.expansion.hosts.some((host) => f.policy.network.kind !== "open-public" &&
268
- !f.policy.network.hosts.some((pattern) => coversHost(pattern, host))))
296
+ grant.expansion.hosts.some((host) => f.hostCeiling
297
+ ? !hostGrantable(f.hostCeiling, host)
298
+ : f.policy.network.kind !== "open-public" &&
299
+ !f.policy.network.hosts.some((pattern) => coversHost(pattern, host))))
269
300
  throw new ApiError("forbidden", "Permission expansion exceeds the current ceiling");
270
301
  }
271
302
  // an accepted host addition the applied cloud outer boundary does not cover cannot be
272
- // reached: cut like the base hosts, so admission never names more than the context (B-15)
273
- const expansionHosts = hostsWithinOuter(grant?.expansion.hosts ?? [], f.outerNetwork ?? undefined);
303
+ // reached: cut like the base hosts, so admission never names more than the context (B-15);
304
+ // an open sandbox network needs none, and an instance-boundary device takes none per call
305
+ const expansionHosts = f.network === "allowlist" && f.boundary !== "instance"
306
+ ? hostsWithinOuter(grant?.expansion.hosts ?? [], f.outerNetwork ?? undefined)
307
+ : [];
274
308
  const scope = this.scopeOf(ctx, operation, {
275
309
  ...f,
276
310
  baseReadDirectories: [
@@ -332,11 +366,14 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
332
366
  // the recorded runtime support decides the route: restricted when enforced, Full access only
333
367
  // on an isolated Full-only runtime, nothing on a host machine without restricted enforcement
334
368
  const availability = f.availability;
369
+ // a runtime that cannot enforce its sandbox (one that only runs outside it) gets no read
370
+ if (availability.state === "unsupported")
371
+ throw new KernelReadUnsupported();
335
372
  let route = "restricted";
336
373
  if (availability.state === "supported") {
337
374
  route = kernelReadRoute({
338
- restricted: availability.report.restricted !== null,
339
- fullAccess: availability.report.fullAccess,
375
+ restricted: availability.report.restricted !== null || instanceSupported(availability.report),
376
+ fullAccess: availability.report.outsideSandbox,
340
377
  isolated: await this.isolatedRuntime(ctx.orgId, ctx.deviceId),
341
378
  });
342
379
  if (route === "refused")
@@ -348,11 +385,20 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
348
385
  throw new ApiError("forbidden", "The kernel read is outside the conversation's profile");
349
386
  // a restricted read-only scope whenever the runtime enforces it, whatever the conversation's
350
387
  // profile: a runtime keyed on Full access may follow a symlinked AGENTS.md or SKILL.md out of
351
- // the project, and a kernel read has no tool call or review to show for it
388
+ // the project, and a kernel read has no tool call or review to show for it. An instance
389
+ // boundary runs only its instance scope (the instance is the sandbox, a narrower scope is
390
+ // refused by the provider); the covering-path check above confines the read's path
391
+ const instance = availability.state === "supported" && instanceSupported(availability.report);
352
392
  return parseSandboxOperationScope({
353
393
  ...profile,
354
394
  profile: route === "full" ? profile.profile : KERNEL_READ_PROFILE,
355
- filesystem: { kind: "scoped", readRoots: [covering], writeRoots: [] },
395
+ filesystem: instance
396
+ ? {
397
+ kind: "scoped",
398
+ readRoots: instanceRoots(f.workingRoot),
399
+ writeRoots: instanceRoots(f.workingRoot),
400
+ }
401
+ : { kind: "scoped", readRoots: [covering], writeRoots: [] },
356
402
  network: { kind: "none" },
357
403
  });
358
404
  }
@@ -398,8 +444,10 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
398
444
  readRoots: f.baseReadDirectories,
399
445
  writeRoots: f.baseWriteDirectories,
400
446
  allowedHosts: isExecutionMethod(operation) ? f.baseHosts : [],
401
- fullAccessCeiling: f.fullAccessCeiling,
402
- fullConsent: f.fullConsent,
447
+ // a native method reaches no network: only executions carry the sandbox network
448
+ network: isExecutionMethod(operation) ? (f.network ?? "none") : "none",
449
+ boundary: f.boundary ?? "operation",
450
+ outsideSandboxCeiling: f.outsideSandboxCeiling,
403
451
  ...(escalated ? { escalated: true } : {}),
404
452
  });
405
453
  }
@@ -443,7 +491,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
443
491
  runId: ctx.actor.runId,
444
492
  ...opts,
445
493
  });
446
- const { policy, device, workingRoot, projectRoot, grant } = base;
494
+ const { policy, device, workingRoot, projectRoot, grant, sandbox } = base;
447
495
  const applied = await this.facts.readAppliedEnvironmentLocked({
448
496
  orgId: ctx.orgId,
449
497
  deviceId: ctx.deviceId,
@@ -451,9 +499,10 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
451
499
  // admission's hosts, as the recorded context names them: within a cloud instance's applied
452
500
  // outer boundary
453
501
  const allowedHosts = hostsWithinOuter(base.allowedHosts, applied?.outerNetwork);
502
+ const grantHosts = hostsWithinOuter(base.grantHosts, applied?.outerNetwork);
454
503
  captureGrant?.(grant
455
504
  ? {
456
- hosts: grant.hosts.filter((host) => allowedHosts.includes(host)).sort(),
505
+ hosts: grant.hosts.filter((host) => grantHosts.includes(host)).sort(),
457
506
  source: { ...grant.source },
458
507
  }
459
508
  : undefined);
@@ -463,28 +512,23 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
463
512
  // lease creates the instance and records its evidence before the first operation is admitted
464
513
  const withheld = withheldScope({
465
514
  availability: view.availability,
466
- effectiveProfile,
467
- location: device.source === "local" ? "local" : "cloud",
468
- workingRoot,
469
- projectPath: projectRoot,
470
- applied,
471
- });
472
- // whether this call could run outside the sandbox (per-call escalation): the Full access
473
- // ceiling and the runtime's Full support, judged as for Full access itself
474
- const fullWithheld = withheldScope({
475
- availability: view.availability,
476
- effectiveProfile: "full-access",
477
515
  location: device.source === "local" ? "local" : "cloud",
478
516
  workingRoot,
479
517
  projectPath: projectRoot,
480
518
  applied,
481
519
  });
520
+ // whether this call could run outside the sandbox (per-call escalation): the device's
521
+ // outside-sandbox ceiling, which already holds the provider's support for it
482
522
  const escalationRefusal = unattended
483
523
  ? ESCALATION_UNATTENDED_WHY
484
- : !view.fullAccessCeiling
485
- ? ESCALATION_CEILING_WHY
486
- : fullWithheld
487
- ? escalationRuntimeWhy(fullWithheld.reason)
524
+ : withheld
525
+ ? escalationRuntimeWhy(withheld.reason)
526
+ : !view.outsideSandboxCeiling
527
+ ? escalationCeilingWhy({
528
+ layer: sandbox.layer.outsideSandbox,
529
+ location: device.source === "local" ? "local" : "cloud",
530
+ boundary: sandbox.boundary,
531
+ })
488
532
  : null;
489
533
  const vector = await this.epochs.readLocked(subject);
490
534
  signal.throwIfAborted();
@@ -506,18 +550,29 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
506
550
  baseReadDirectories: restrictedReadRoots(workingRoot, applied),
507
551
  baseWriteDirectories: [workingRoot],
508
552
  baseHosts: allowedHosts,
509
- fullAccessCeiling: view.fullAccessCeiling,
553
+ network: sandboxNetworkOf(sandbox, applied?.outerNetwork),
554
+ boundary: sandbox.boundary,
555
+ outsideSandboxCeiling: view.outsideSandboxCeiling,
510
556
  broadProjectReach: view.broadProjectReach,
511
- fullConsent: view.profile === "full-access" && view.consentScope?.scopeRevision === view.scopeRevision,
557
+ // the view keeps Full access only while its consent covers the device's ceilings
558
+ fullConsent: view.profile === "full-access",
512
559
  unattended,
513
560
  // the review and admission see the recorded context's verdict, never a wider one
514
561
  availability: withheld ?? view.availability,
515
562
  admissionRefusal: withheld?.reason ?? null,
516
563
  outerNetwork: applied?.outerNetwork ?? null,
517
564
  escalationRefusal,
518
- policy: device.source === "local"
519
- ? { ...policy, network: { kind: "allowlist", hosts: policy.localAllowedDomains } }
520
- : policy,
565
+ // the host ceiling a per-call grant is checked against, the one rule the candidate builder,
566
+ // grant issuance and admission read (`policy.network` is its network form: `open-public`
567
+ // for the kernel's bounds; `hostCeiling` keeps the org's exclusions, `hostRefusal` the text)
568
+ policy: {
569
+ ...policy,
570
+ network: base.hostCeiling.kind === "any"
571
+ ? { kind: "open-public", hosts: [] }
572
+ : { kind: "allowlist", hosts: [...base.hostCeiling.hosts] },
573
+ },
574
+ hostCeiling: base.hostCeiling,
575
+ hostRefusal: base.hostRefusal,
521
576
  };
522
577
  }
523
578
  /**
@@ -547,7 +602,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
547
602
  */
548
603
  async baseScopeLocked(input) {
549
604
  const { orgId, deviceId } = input;
550
- const { policy, owner } = await this.facts.readDevice(orgId, deviceId);
605
+ const { policy, owner, sandbox, hostCeiling, hostRefusal } = await this.facts.readDevice(orgId, deviceId);
551
606
  const device = await this.db
552
607
  .selectFrom("devices")
553
608
  .select("source")
@@ -561,13 +616,23 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
561
616
  const grant = input.runId
562
617
  ? await this.grants.forExec({ orgId, deviceId, runId: input.runId })
563
618
  : undefined;
564
- const baseHosts = owner ? owner.allowedDomains : policy.localAllowedDomains;
565
- const requested = [...baseHosts, ...(grant?.hosts ?? [])];
566
- const allowedHosts = requested.filter((host) => (policy.localAllowedDomains.some((pattern) => coversHost(pattern, host)) ||
567
- grant?.hosts.includes(host)) &&
568
- (policy.network.kind === "open-public" ||
569
- policy.network.hosts.some((pattern) => coversHost(pattern, host))));
570
- return { policy, device, workingRoot, projectRoot, grant, allowedHosts };
619
+ // the run's or task's explicit host grants within the per-call ceiling: carried as the exec's
620
+ // grants under any open network too (redundant there, so a later narrowing keeps them working)
621
+ const grantHosts = (grant?.hosts ?? []).filter((host) => hostGrantable(hostCeiling, host));
622
+ // the device sandbox's allowlist plus those grants; an open or closed network names no hosts
623
+ const allowedHosts = sandbox.networkMode !== "allowlist" ? [] : [...new Set([...sandbox.hosts, ...grantHosts])];
624
+ return {
625
+ policy,
626
+ device,
627
+ workingRoot,
628
+ projectRoot,
629
+ grant,
630
+ grantHosts,
631
+ allowedHosts,
632
+ sandbox,
633
+ hostCeiling,
634
+ hostRefusal,
635
+ };
571
636
  }
572
637
  /**
573
638
  * The working root of the base authority (B1), decided exactly as the command review decides it
@@ -685,14 +750,20 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
685
750
  const scheduled = (await this.runScheduledLocked(input.conversationId, input.accountId, input.runId)) ||
686
751
  root.scheduled_task_id !== null;
687
752
  const header = {
688
- version: 1,
753
+ version: 2,
754
+ // only a supported context carries the device sandbox block (below)
755
+ sandbox: null,
689
756
  rootConversationId: root.id,
690
757
  execution: scheduled ? "scheduled" : "interactive",
691
758
  inherited: input.conversationId !== root.id,
692
759
  };
693
760
  const parse = (payload) => {
694
761
  signal.throwIfAborted();
695
- return PermissionContextV1Schema.parse(payload);
762
+ // every supported context this producer records carries its device sandbox block: the
763
+ // block-less form exists only as a stored version 1 context read as version 2
764
+ if ((payload.availability.state === "supported") !== (payload.sandbox !== null))
765
+ throw new Error("A supported permission context must record its device sandbox");
766
+ return PermissionContextV2Schema.parse(payload);
696
767
  };
697
768
  if (foreign && root.device_id !== null)
698
769
  return parse({
@@ -809,7 +880,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
809
880
  // the verdict admission refuses with (B-16)
810
881
  const withheld = withheldScope({
811
882
  availability,
812
- effectiveProfile,
813
883
  location,
814
884
  workingRoot: base.workingRoot,
815
885
  projectPath: base.projectRoot,
@@ -819,32 +889,44 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
819
889
  return without(withheld.state, withheld.reason);
820
890
  if (applied === null)
821
891
  throw new Error("A supported context needs its applied environment");
822
- const full = effectiveProfile === "full-access";
823
- if (full &&
824
- (!view.fullAccessCeiling ||
825
- view.consentScope?.deviceId !== deviceId ||
826
- view.consentScope.scopeRevision !== scopeRevision))
827
- throw new Error("Full access lost its ceiling or consent inside one authority read");
828
- const hosts = [...new Set(allowedHosts)].sort(permissionCodePointCompare);
892
+ if (effectiveProfile === "full-access" && view.consentScope?.deviceId !== deviceId)
893
+ throw new Error("Full access lost its consent inside one authority read");
894
+ const box = base.sandbox;
895
+ const kind = sandboxNetworkOf(box, applied.outerNetwork);
896
+ const hosts = kind === "allowlist" ? [...new Set(allowedHosts)].sort(permissionCodePointCompare) : [];
897
+ // the same scope admission builds for every profile ({@link intersectPermissionScope})
898
+ const network = kind === "open-public"
899
+ ? { kind: "open-public" }
900
+ : hosts.length
901
+ ? { kind: "allowlist", hosts }
902
+ : { kind: "none" };
903
+ const directories = box.boundary === "instance"
904
+ ? instanceRoots(base.workingRoot)
905
+ : restrictedReadRoots(base.workingRoot, applied);
829
906
  return parse({
830
907
  ...known,
831
908
  availability: { state: "supported" },
832
909
  scope: {
833
910
  location,
834
911
  workingRoot: base.workingRoot,
835
- filesystem: full
836
- ? { kind: "device" }
837
- : {
838
- kind: "scoped",
839
- readDirectories: restrictedReadRoots(base.workingRoot, applied),
840
- writeDirectories: [base.workingRoot],
841
- },
842
- network: full
843
- ? { kind: "environment" }
844
- : hosts.length
845
- ? { kind: "allowlist", hosts }
846
- : { kind: "none" },
912
+ filesystem: {
913
+ kind: "scoped",
914
+ readDirectories: directories,
915
+ writeDirectories: box.boundary === "instance" ? directories : [base.workingRoot],
916
+ },
917
+ network,
918
+ outerNetwork: applied.outerNetwork,
919
+ },
920
+ sandbox: {
921
+ boundary: box.boundary,
922
+ location,
923
+ workingRoot: base.workingRoot,
924
+ network: { kind: network.kind, hostsCount: hosts.length },
925
+ // a cloud device has no outside: its provider's instance is the outermost boundary
926
+ outsideSandbox: location === "local" && box.outsideSandbox,
847
927
  outerNetwork: applied.outerNetwork,
928
+ // the provider's network covers a whole instance: no host is granted per call there
929
+ perCallHosts: box.boundary !== "instance",
848
930
  },
849
931
  });
850
932
  }
@@ -0,0 +1,42 @@
1
+ import { EventLog } from "../conversations/event-log.js";
2
+ import { KernelDb } from "../infra/database/kernel-db.js";
3
+ import { TransactionHost } from "../infra/database/transaction-host.js";
4
+ import { PermissionAuthorityLock } from "./permission-authority-lock.js";
5
+ import { PermissionCallGrants } from "./permission-call-grants.js";
6
+ import type { PermissionCallBinding, PermissionCandidate } from "./permission-call-types.js";
7
+ /** Test seams of {@link PermissionAutoGrants} (optional provider {@link PERMISSION_AUTO_GRANT_HOOKS}). */
8
+ export interface PermissionAutoGrantHooks {
9
+ /**
10
+ * Called inside the issuing transaction once the precheck found no grant for the binding,
11
+ * before anything is written: a barrier here makes two replicas pass the precheck together.
12
+ */
13
+ afterPrecheck?(binding: PermissionCallBinding): Promise<void>;
14
+ }
15
+ /** Optional provider: the {@link PermissionAutoGrantHooks} (tests). */
16
+ export declare const PERMISSION_AUTO_GRANT_HOOKS: unique symbol;
17
+ /**
18
+ * Full access auto-grants (approval-only profiles design, "Kernel: decision, admission and
19
+ * records"): one crossing granted for one call within the device's ceilings, recorded exactly once
20
+ * in one fenced transaction under the shared authority lock: the `permission_reviewed` event
21
+ * (decision source `full-access`, its crossing and any sensitive consents it skipped), the audit
22
+ * row `permission.crossing_auto_granted` and the grant itself (source `full-access`). The event is
23
+ * announced after the commit. A replica that lost the race for the same binding rolls back on the
24
+ * grant's immutable evidence (its event and audit row with it) and finds the winner's grant.
25
+ */
26
+ export declare class PermissionAutoGrants {
27
+ private readonly db;
28
+ readonly txHost: TransactionHost;
29
+ private readonly eventLog;
30
+ private readonly grants;
31
+ private readonly locks;
32
+ private readonly hooks?;
33
+ constructor(db: KernelDb, txHost: TransactionHost, eventLog: EventLog, grants: PermissionCallGrants, locks: PermissionAuthorityLock, hooks?: PermissionAutoGrantHooks | undefined);
34
+ /**
35
+ * Records the auto-grant of `candidate`. `sensitive` are the sensitive-command consents (rule
36
+ * ids) Full access skipped for this call. Resolves once this call's grant exists, from this
37
+ * replica or another; anything else (a changed permission state, other evidence) throws.
38
+ */
39
+ record(candidate: PermissionCandidate, sensitive?: readonly string[]): Promise<void>;
40
+ private findIn;
41
+ private recordIn;
42
+ }