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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/admin/admin.schemas.d.ts +11 -1
  2. package/dist/catalog/catalog.module.js +1 -1
  3. package/dist/catalog/marketplaces.service.d.ts +1 -1
  4. package/dist/catalog/requests.service.d.ts +5 -5
  5. package/dist/catalog/requests.service.js +9 -9
  6. package/dist/channels/cards.d.ts +4 -3
  7. package/dist/channels/cards.js +25 -16
  8. package/dist/channels/phrases.d.ts +15 -4
  9. package/dist/channels/phrases.js +15 -1
  10. package/dist/config/load.d.ts +26 -7
  11. package/dist/config/load.js +60 -9
  12. package/dist/config/permission-migration.d.ts +17 -9
  13. package/dist/config/permission-migration.js +60 -9
  14. package/dist/config/schema.d.ts +11 -1
  15. package/dist/config/schema.js +37 -11
  16. package/dist/conversations/events.d.ts +247 -5
  17. package/dist/conversations/events.js +127 -16
  18. package/dist/conversations/permission-profiles.controller.d.ts +12 -2
  19. package/dist/conversations/permission-profiles.service.d.ts +12 -2
  20. package/dist/conversations/permission-profiles.service.js +11 -4
  21. package/dist/db/kernel-schema.d.ts +8 -2
  22. package/dist/devices/device-projects.service.d.ts +1 -1
  23. package/dist/devices/device-projects.service.js +6 -6
  24. package/dist/devices/devices.controller.d.ts +10 -8
  25. package/dist/devices/devices.controller.js +14 -18
  26. package/dist/devices/devices.schemas.d.ts +5 -5
  27. package/dist/devices/devices.schemas.js +5 -5
  28. package/dist/devices/devices.service.d.ts +188 -175
  29. package/dist/devices/devices.service.js +284 -292
  30. package/dist/devices/dto.d.ts +43 -23
  31. package/dist/devices/dto.js +45 -49
  32. package/dist/devices/project-rules.d.ts +0 -10
  33. package/dist/devices/project-rules.js +0 -5
  34. package/dist/errors.d.ts +24 -19
  35. package/dist/errors.js +24 -19
  36. package/dist/evals/reconstruct.d.ts +12 -3
  37. package/dist/evals/reconstruct.js +10 -6
  38. package/dist/evals/recorded-permission-context.d.ts +6 -4
  39. package/dist/evals/recorded-permission-context.js +15 -9
  40. package/dist/evals/run-replay.d.ts +6 -1
  41. package/dist/evals/run-replay.js +7 -2
  42. package/dist/evals/worker.js +3 -1
  43. package/dist/identity/settings.d.ts +45 -18
  44. package/dist/identity/settings.js +151 -51
  45. package/dist/infra/config/kernel-config.service.d.ts +1 -1
  46. package/dist/infra/config/kernel-config.service.js +17 -5
  47. package/dist/local-devices/device-auth.controller.d.ts +1 -1
  48. package/dist/local-devices/device-auth.controller.js +1 -1
  49. package/dist/local-devices/device-auth.d.ts +4 -4
  50. package/dist/local-devices/device-auth.js +1 -1
  51. package/dist/local-devices/device-policy.service.d.ts +18 -9
  52. package/dist/local-devices/device-policy.service.js +21 -61
  53. package/dist/local-devices/device-routes.d.ts +3 -1
  54. package/dist/local-devices/device-routes.js +15 -4
  55. package/dist/local-devices/instance-bindings.js +5 -2
  56. package/dist/local-devices/local-device-gateway.d.ts +2 -2
  57. package/dist/local-devices/local-device-gateway.js +3 -3
  58. package/dist/local-devices/local-device-provider.d.ts +4 -4
  59. package/dist/local-devices/local-device-provider.js +23 -9
  60. package/dist/local-devices/local-devices.module.d.ts +1 -1
  61. package/dist/local-devices/local-devices.module.js +1 -1
  62. package/dist/local-devices/machines.d.ts +40 -16
  63. package/dist/local-devices/machines.js +89 -61
  64. package/dist/local-devices/owner-report.d.ts +16 -14
  65. package/dist/local-devices/owner-report.js +24 -30
  66. package/dist/local-devices/owner-reports.js +26 -8
  67. package/dist/local-devices/policy-summary.d.ts +25 -44
  68. package/dist/local-devices/policy-summary.js +26 -71
  69. package/dist/local-devices/relay.d.ts +6 -6
  70. package/dist/local-devices/relay.js +10 -8
  71. package/dist/net/public-address.d.ts +1 -1
  72. package/dist/net/public-address.js +5 -2
  73. package/dist/orgs/device-network-setting.d.ts +82 -0
  74. package/dist/orgs/device-network-setting.js +142 -0
  75. package/dist/orgs/settings.service.d.ts +103 -66
  76. package/dist/orgs/settings.service.js +201 -137
  77. package/dist/overrides.d.ts +5 -1
  78. package/dist/overrides.js +2 -0
  79. package/dist/platform/exclusions.js +1 -1
  80. package/dist/platform/operation.js +1 -1
  81. package/dist/platform/ops/admin.ops.js +20 -11
  82. package/dist/platform/ops/devices.ops.js +70 -5
  83. package/dist/platform/ops/org-settings.ops.js +10 -6
  84. package/dist/platform/ops/orgs.ops.js +2 -1
  85. package/dist/runtime/context/permission-profile.d.ts +17 -8
  86. package/dist/runtime/context/permission-profile.js +126 -45
  87. package/dist/runtime/permission-context.service.d.ts +1 -1
  88. package/dist/runtime/permission-context.service.js +5 -3
  89. package/dist/runtime/project/knowledge.d.ts +5 -4
  90. package/dist/runtime/project/knowledge.js +2 -1
  91. package/dist/runtime/project/knowledge.service.js +16 -13
  92. package/dist/sandbox/cloud-permission-snapshot.js +22 -3
  93. package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
  94. package/dist/sandbox/device-sandbox-settings.js +470 -0
  95. package/dist/sandbox/device-sandbox.d.ts +187 -0
  96. package/dist/sandbox/device-sandbox.js +236 -0
  97. package/dist/sandbox/held-operations.js +15 -7
  98. package/dist/sandbox/modes.d.ts +49 -24
  99. package/dist/sandbox/modes.js +27 -19
  100. package/dist/sandbox/operation-authority-types.d.ts +6 -5
  101. package/dist/sandbox/operation-authority-types.js +7 -8
  102. package/dist/sandbox/operation-authority.d.ts +23 -9
  103. package/dist/sandbox/operation-authority.js +179 -97
  104. package/dist/sandbox/permission-auto-grants.d.ts +42 -0
  105. package/dist/sandbox/permission-auto-grants.js +145 -0
  106. package/dist/sandbox/permission-call-grants.d.ts +12 -4
  107. package/dist/sandbox/permission-call-grants.js +84 -35
  108. package/dist/sandbox/permission-call-grants.module.js +10 -3
  109. package/dist/sandbox/permission-call-types.d.ts +39 -5
  110. package/dist/sandbox/permission-ceiling-writes.d.ts +29 -3
  111. package/dist/sandbox/permission-ceiling-writes.js +38 -4
  112. package/dist/sandbox/permission-config-publication.d.ts +44 -2
  113. package/dist/sandbox/permission-config-publication.js +230 -59
  114. package/dist/sandbox/permission-context-types.d.ts +2 -2
  115. package/dist/sandbox/permission-facts.d.ts +144 -15
  116. package/dist/sandbox/permission-facts.js +258 -70
  117. package/dist/sandbox/permission-runtime-reports.d.ts +5 -4
  118. package/dist/sandbox/permission-runtime-reports.js +19 -29
  119. package/dist/sandbox/review/classifier.d.ts +8 -0
  120. package/dist/sandbox/review/classifier.js +10 -0
  121. package/dist/sandbox/review/permission-candidate.d.ts +69 -5
  122. package/dist/sandbox/review/permission-candidate.js +153 -30
  123. package/dist/sandbox/review/review.service.d.ts +19 -3
  124. package/dist/sandbox/review/review.service.js +59 -11
  125. package/dist/sandbox/review/rules.js +23 -3
  126. package/dist/sandbox/sandbox.service.d.ts +29 -11
  127. package/dist/sandbox/sandbox.service.js +51 -26
  128. package/dist/skills/invoke.js +3 -2
  129. package/dist/tools/approvals.service.d.ts +26 -116
  130. package/dist/tools/approvals.service.js +42 -346
  131. package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
  132. package/dist/tools/builtins/sandbox/bash.js +80 -28
  133. package/dist/tools/builtins/sandbox/common.d.ts +39 -14
  134. package/dist/tools/builtins/sandbox/common.js +47 -24
  135. package/dist/tools/builtins/sandbox/deliver.js +7 -4
  136. package/dist/tools/builtins/skill-load.d.ts +2 -2
  137. package/dist/tools/builtins/skill-load.js +4 -3
  138. package/dist/tools/device-op-resolver.d.ts +4 -10
  139. package/dist/tools/device-op-resolver.js +8 -19
  140. package/dist/tools/network-asks.d.ts +52 -15
  141. package/dist/tools/network-asks.js +55 -25
  142. package/dist/tools/pipeline.d.ts +26 -14
  143. package/dist/tools/pipeline.js +144 -61
  144. package/dist/tools/registry.d.ts +6 -0
  145. package/dist/tools/tools.module.js +1 -1
  146. package/dist/ui/views.d.ts +3 -1
  147. package/dist/ui/views.js +2 -1
  148. package/package.json +4 -4
  149. package/src/migrations/0165_device_network_columns.sql +50 -0
  150. package/src/migrations/0166_permission_grant_full_access.sql +17 -0
  151. package/src/migrations/0167_device_network_backfill.sql +32 -0
  152. package/src/migrations/0168_binding_installed_connection.sql +6 -0
  153. package/dist/orgs/cloud-network-setting.d.ts +0 -33
  154. package/dist/orgs/cloud-network-setting.js +0 -47
  155. package/dist/sandbox/platform-full-access.d.ts +0 -110
  156. package/dist/sandbox/platform-full-access.js +0 -198
@@ -8,32 +8,50 @@ export declare const DeviceParams: z.ZodObject<{
8
8
  id: z.ZodString;
9
9
  }, z.core.$strip>;
10
10
  /**
11
- * `PATCH /devices/:id`: a new name, and a cloud device's `mode`: `sandbox` narrows it, `null`
12
- * follows the org and the platform again (auto when they allow it; hardening spec D2). `auto` is
13
- * never stored. A local device's mode lives on its machine, so the service refuses a `mode` for it
14
- * (`device.mode_on_device`). The mode is a person's choice in a web session: an API token gets
15
- * `device.mode_requires_session`, and the Platform operation (`devices.rename`) omits it.
11
+ * A cloud device's sandbox network (approval-only profiles design, "Settings model"): `open` (the
12
+ * public internet), `allowlist` (its org's hosts, narrowed to `hosts` when given: a device list
13
+ * never adds a host, and an empty one follows the org's), `none` (closed), or `null` to follow its
14
+ * org again. `hosts` only with `allowlist`.
15
+ */
16
+ export declare const DeviceNetworkBody: z.ZodObject<{
17
+ mode: z.ZodNullable<z.ZodEnum<{
18
+ allowlist: "allowlist";
19
+ none: "none";
20
+ open: "open";
21
+ }>>;
22
+ hosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
23
+ }, z.core.$strict>;
24
+ /**
25
+ * `PATCH /devices/:id`: a new name, and a cloud device's sandbox `network`
26
+ * ({@link DeviceNetworkBody}), within its org's and the platform's ceilings (`device.network_not_allowed`
27
+ * above them). A local device's network lives on its machine (`device.ceiling_on_machine`: narrow
28
+ * it with `POST /devices/:id/policy`, widen it on the machine). Through an API token or the
29
+ * Platform tool (`devices.set-network`) the network may only narrow.
16
30
  */
17
31
  export declare const DevicePatchBody: z.ZodObject<{
18
32
  name: z.ZodOptional<z.ZodString>;
19
- mode: z.ZodOptional<z.ZodNullable<z.ZodLiteral<"sandbox">>>;
20
- ownerCeiling: z.ZodOptional<z.ZodObject<{
21
- fullAccess: z.ZodBoolean;
33
+ network: z.ZodOptional<z.ZodObject<{
34
+ mode: z.ZodNullable<z.ZodEnum<{
35
+ allowlist: "allowlist";
36
+ none: "none";
37
+ open: "open";
38
+ }>>;
39
+ hosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
40
  }, z.core.$strict>>;
23
- confirmWidening: z.ZodOptional<z.ZodLiteral<true>>;
24
41
  }, z.core.$strict>;
25
42
  /**
26
- * `POST /devices/:id/policy` (network ask-to-allow spec §7; auto mode spec §4.1): the device
27
- * owner's change of the machine's local policy. `add` and `remove` change its sandbox-mode
28
- * allowlist; `mode: "sandbox"` turns the sandbox back on (turning auto mode on is decided on the
29
- * machine only).
43
+ * `POST /devices/:id/policy` (approval-only profiles design, "Settings model"): the device owner
44
+ * narrows the local machine's sandbox from the web: `remove` hosts from its allowlist, and narrow
45
+ * its owner ceiling (`outsideSandbox: false`, `network: "allowlist"`, `restrictedProjectReach:
46
+ * "workspace"`). The web never widens it: the owner adds hosts, opens the network or allows
47
+ * running outside the sandbox on the machine (`capybara-device policy add allowedDomains`,
48
+ * `capybara-device ceiling set`).
30
49
  */
31
50
  export declare const DevicePolicyBody: z.ZodObject<{
32
- add: z.ZodOptional<z.ZodArray<z.ZodString>>;
33
51
  remove: z.ZodOptional<z.ZodArray<z.ZodString>>;
34
- mode: z.ZodOptional<z.ZodLiteral<"sandbox">>;
35
52
  ownerCeiling: z.ZodOptional<z.ZodObject<{
36
- fullAccess: z.ZodOptional<z.ZodLiteral<false>>;
53
+ outsideSandbox: z.ZodOptional<z.ZodLiteral<false>>;
54
+ network: z.ZodOptional<z.ZodLiteral<"allowlist">>;
37
55
  restrictedProjectReach: z.ZodOptional<z.ZodLiteral<"workspace">>;
38
56
  }, z.core.$strict>>;
39
57
  }, z.core.$strict>;
@@ -63,11 +81,14 @@ export declare class DeviceCreateBodyDto extends DeviceCreateBodyDto_base {
63
81
  }
64
82
  declare const DevicePatchBodyDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
65
83
  name: z.ZodOptional<z.ZodString>;
66
- mode: z.ZodOptional<z.ZodNullable<z.ZodLiteral<"sandbox">>>;
67
- ownerCeiling: z.ZodOptional<z.ZodObject<{
68
- fullAccess: z.ZodBoolean;
84
+ network: z.ZodOptional<z.ZodObject<{
85
+ mode: z.ZodNullable<z.ZodEnum<{
86
+ allowlist: "allowlist";
87
+ none: "none";
88
+ open: "open";
89
+ }>>;
90
+ hosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
91
  }, z.core.$strict>>;
70
- confirmWidening: z.ZodOptional<z.ZodLiteral<true>>;
71
92
  }, z.core.$strict>>;
72
93
  export declare class DevicePatchBodyDto extends DevicePatchBodyDto_base {
73
94
  }
@@ -77,11 +98,10 @@ declare const DeviceParamsDto_base: import("../infra/validation/create-zod-dto.j
77
98
  export declare class DeviceParamsDto extends DeviceParamsDto_base {
78
99
  }
79
100
  declare const DevicePolicyBodyDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
80
- add: z.ZodOptional<z.ZodArray<z.ZodString>>;
81
101
  remove: z.ZodOptional<z.ZodArray<z.ZodString>>;
82
- mode: z.ZodOptional<z.ZodLiteral<"sandbox">>;
83
102
  ownerCeiling: z.ZodOptional<z.ZodObject<{
84
- fullAccess: z.ZodOptional<z.ZodLiteral<false>>;
103
+ outsideSandbox: z.ZodOptional<z.ZodLiteral<false>>;
104
+ network: z.ZodOptional<z.ZodLiteral<"allowlist">>;
85
105
  restrictedProjectReach: z.ZodOptional<z.ZodLiteral<"workspace">>;
86
106
  }, z.core.$strict>>;
87
107
  }, z.core.$strict>>;
@@ -1,36 +1,10 @@
1
1
  import { isDeviceProjectName, MAX_DEVICE_PROJECT_NAME_LENGTH, validateAllowHost, } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
3
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
4
- import { publicSuffixWildcard } from "./public-suffix.js";
5
4
  /** A device's name: trimmed, 1-64 characters (unique per person, case-insensitive). */
6
5
  export const DeviceName = z.string().trim().min(1).max(64);
7
6
  export const DeviceNameBody = z.object({ name: DeviceName }).strict();
8
7
  export const DeviceParams = z.object({ id: z.string().min(1).max(100) });
9
- /**
10
- * `PATCH /devices/:id`: a new name, and a cloud device's `mode`: `sandbox` narrows it, `null`
11
- * follows the org and the platform again (auto when they allow it; hardening spec D2). `auto` is
12
- * never stored. A local device's mode lives on its machine, so the service refuses a `mode` for it
13
- * (`device.mode_on_device`). The mode is a person's choice in a web session: an API token gets
14
- * `device.mode_requires_session`, and the Platform operation (`devices.rename`) omits it.
15
- */
16
- export const DevicePatchBody = z
17
- .object({
18
- name: DeviceName.optional(),
19
- mode: z.literal("sandbox").nullable().optional(),
20
- /**
21
- * B2: a cloud device's explicit Full ceiling. `false` narrows; `true` widens and needs
22
- * `confirmWidening: true` (a person in a web session only); it never opens the outer network.
23
- */
24
- ownerCeiling: z.object({ fullAccess: z.boolean() }).strict().optional(),
25
- confirmWidening: z.literal(true).optional(),
26
- })
27
- .strict()
28
- .refine((b) => b.name !== undefined || b.mode !== undefined || b.ownerCeiling !== undefined, {
29
- message: "Give at least one of name, mode or ownerCeiling",
30
- })
31
- .refine((b) => b.mode === undefined || b.ownerCeiling === undefined, {
32
- message: "Give either mode or ownerCeiling, not both",
33
- });
34
8
  /** One host of a device's network allowlist (`validateAllowHost`: lowercase, `*.` allowed). */
35
9
  const PolicyHost = z
36
10
  .string()
@@ -39,44 +13,66 @@ const PolicyHost = z
39
13
  for (const message of validateAllowHost(h))
40
14
  ctx.addIssue({ code: "custom", message });
41
15
  });
42
- /** A host to add: also no `*.` wildcard over a whole public suffix (`*.com`, `*.co.uk`). */
43
- const AddHost = PolicyHost.superRefine((h, ctx) => {
44
- const tooBroad = publicSuffixWildcard(h);
45
- if (tooBroad !== null)
46
- ctx.addIssue({ code: "custom", message: tooBroad });
16
+ /**
17
+ * A cloud device's sandbox network (approval-only profiles design, "Settings model"): `open` (the
18
+ * public internet), `allowlist` (its org's hosts, narrowed to `hosts` when given: a device list
19
+ * never adds a host, and an empty one follows the org's), `none` (closed), or `null` to follow its
20
+ * org again. `hosts` only with `allowlist`.
21
+ */
22
+ export const DeviceNetworkBody = z
23
+ .object({
24
+ mode: z.enum(["open", "allowlist", "none"]).nullable(),
25
+ hosts: z.array(PolicyHost).max(100).optional(),
26
+ })
27
+ .strict()
28
+ .refine((n) => n.hosts === undefined || n.hosts.length === 0 || n.mode === "allowlist", {
29
+ message: "Give hosts only with the allowlist network",
47
30
  });
48
31
  /**
49
- * `POST /devices/:id/policy` (network ask-to-allow spec §7; auto mode spec §4.1): the device
50
- * owner's change of the machine's local policy. `add` and `remove` change its sandbox-mode
51
- * allowlist; `mode: "sandbox"` turns the sandbox back on (turning auto mode on is decided on the
52
- * machine only).
32
+ * `PATCH /devices/:id`: a new name, and a cloud device's sandbox `network`
33
+ * ({@link DeviceNetworkBody}), within its org's and the platform's ceilings (`device.network_not_allowed`
34
+ * above them). A local device's network lives on its machine (`device.ceiling_on_machine`: narrow
35
+ * it with `POST /devices/:id/policy`, widen it on the machine). Through an API token or the
36
+ * Platform tool (`devices.set-network`) the network may only narrow.
37
+ */
38
+ export const DevicePatchBody = z
39
+ .object({
40
+ name: DeviceName.optional(),
41
+ network: DeviceNetworkBody.optional(),
42
+ })
43
+ .strict()
44
+ .refine((b) => b.name !== undefined || b.network !== undefined, {
45
+ message: "Give at least one of name or network",
46
+ });
47
+ /**
48
+ * `POST /devices/:id/policy` (approval-only profiles design, "Settings model"): the device owner
49
+ * narrows the local machine's sandbox from the web: `remove` hosts from its allowlist, and narrow
50
+ * its owner ceiling (`outsideSandbox: false`, `network: "allowlist"`, `restrictedProjectReach:
51
+ * "workspace"`). The web never widens it: the owner adds hosts, opens the network or allows
52
+ * running outside the sandbox on the machine (`capybara-device policy add allowedDomains`,
53
+ * `capybara-device ceiling set`).
53
54
  */
54
55
  export const DevicePolicyBody = z
55
56
  .object({
56
- add: z.array(AddHost).min(1).max(20).optional(),
57
57
  remove: z.array(PolicyHost).min(1).max(100).optional(),
58
- mode: z.literal("sandbox").optional(),
59
- /**
60
- * B2: narrow the machine's owner ceiling. Only `fullAccess: false` and `workspace` reach are
61
- * accepted: the web never widens it (the owner does, on the machine, with `capybara-device
62
- * ceiling set`).
63
- */
64
58
  ownerCeiling: z
65
59
  .object({
66
- fullAccess: z.literal(false).optional(),
60
+ outsideSandbox: z.literal(false).optional(),
61
+ network: z.literal("allowlist").optional(),
67
62
  restrictedProjectReach: z.literal("workspace").optional(),
68
63
  })
69
64
  .strict()
70
- .refine((c) => c.fullAccess !== undefined || c.restrictedProjectReach !== undefined, {
71
- message: "Give fullAccess: false or restrictedProjectReach: workspace",
65
+ .refine((c) => c.outsideSandbox !== undefined ||
66
+ c.network !== undefined ||
67
+ c.restrictedProjectReach !== undefined, {
68
+ message: "Give outsideSandbox: false, network: allowlist or restrictedProjectReach: workspace",
72
69
  })
73
70
  .optional(),
74
71
  })
75
72
  .strict()
76
- .refine((b) => b.add !== undefined ||
77
- b.remove !== undefined ||
78
- b.mode !== undefined ||
79
- b.ownerCeiling !== undefined, { message: "Give at least one of add, remove, mode or ownerCeiling" });
73
+ .refine((b) => b.remove !== undefined || b.ownerCeiling !== undefined, {
74
+ message: "Give at least one of remove or ownerCeiling",
75
+ });
80
76
  /**
81
77
  * A project's name (project root §4.1, `isDeviceProjectName`): 1-64 UTF-16 code units, not `.` or
82
78
  * `..`, no `/`, no control characters, no leading or trailing whitespace; unique on its device.
@@ -14,18 +14,8 @@ export interface DeviceProjectScope {
14
14
  /** The owner's home a local machine reported; null when unknown (and for a cloud device). */
15
15
  home: string | null;
16
16
  supported: boolean;
17
- /**
18
- * A machine without an authenticated owner report whose own policy is auto mode while the
19
- * organization allows only sandbox mode: the kernel reads nothing on it unasked.
20
- */
21
- widerThanAllowed: boolean;
22
17
  }
23
18
  type Scope = DeviceProjectScope;
24
- /**
25
- * The protocol 2 read mode for list/scan on the device (`limits.mode`): the reach, encoded (B2: a
26
- * restricted OS-user read is never a Full grant; the v3 browse scope carries roots instead).
27
- */
28
- export declare const readModeOf: (s: Pick<Scope, "source" | "reach" | "mode">) => SandboxMode;
29
19
  /** The base a relative path is resolved against in the scope's mode (project root §4.2). */
30
20
  export declare const baseOf: (s: Scope, workspace?: string) => string | null;
31
21
  /**
@@ -1,11 +1,6 @@
1
1
  import { ApiError } from "../errors.js";
2
2
  /** Only the owner's home bounds nothing: OS-user reach on a machine reads what its owner can. */
3
3
  const homeBased = (s) => s.source === "local" && s.reach === "os-user";
4
- /**
5
- * The protocol 2 read mode for list/scan on the device (`limits.mode`): the reach, encoded (B2: a
6
- * restricted OS-user read is never a Full grant; the v3 browse scope carries roots instead).
7
- */
8
- export const readModeOf = (s) => s.source === "local" ? (s.reach === "os-user" ? "auto" : "sandbox") : s.mode;
9
4
  /** The base a relative path is resolved against in the scope's mode (project root §4.2). */
10
5
  export const baseOf = (s, workspace = s.workspace) => homeBased(s) ? s.home : workspace;
11
6
  /**
package/dist/errors.d.ts CHANGED
@@ -45,10 +45,15 @@ export declare const ERROR_CODES: {
45
45
  readonly "org.owner_required": 403;
46
46
  readonly "org.sandbox_egress_not_allowed": 400;
47
47
  /**
48
- * The org asked for Full permission (`fullAccess: allowed`) where the platform turned it off, or
49
- * widened it through an API token or the Platform tool.
48
+ * The org allowed running outside the sandbox (`outsideSandbox: allowed`) where the platform
49
+ * turned it off, or widened it through an API token or the Platform tool.
50
50
  */
51
- readonly "org.full_access_not_allowed": 400;
51
+ readonly "org.outside_sandbox_not_allowed": 400;
52
+ /**
53
+ * The org's device network default or ceiling is above the platform's ceiling, or was opened
54
+ * through an API token or the Platform tool.
55
+ */
56
+ readonly "org.network_not_allowed": 400;
52
57
  /** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
53
58
  readonly "org.network_allowance_invalid": 400;
54
59
  readonly "org.network_allowance_not_found": 404;
@@ -61,8 +66,13 @@ export declare const ERROR_CODES: {
61
66
  readonly "org.external_sharing_not_allowed": 400;
62
67
  /** A deployment setting set in the startup config (file, Nacos or env): read-only in the admin console. */
63
68
  readonly "deployment.setting_readonly": 409;
64
- /** Allowing the platform's Full permission through an API token or the Platform tool (only off). */
65
- readonly "deployment.full_access_not_allowed": 400;
69
+ /** Allowing outside-sandbox runs platform-wide through an API token or the Platform tool (only off). */
70
+ readonly "deployment.outside_sandbox_not_allowed": 400;
71
+ /**
72
+ * The platform's network default above its ceiling, or a default or ceiling opened through an API
73
+ * token or the Platform tool.
74
+ */
75
+ readonly "deployment.network_not_allowed": 400;
66
76
  /** Allowing external sharing at the platform level through an API token or the Platform tool. */
67
77
  readonly "deployment.external_sharing_not_allowed": 400;
68
78
  /**
@@ -432,11 +442,6 @@ export declare const ERROR_CODES: {
432
442
  * is admitted until a lifecycle action (a file reset) establishes them.
433
443
  */
434
444
  readonly "device.permission_reconcile_required": 409;
435
- /**
436
- * B1: a cloud device's owner ceiling PATCH before its snapshot exists (not migrated yet); the old
437
- * sandbox switch still narrows it. A file reset does not change this.
438
- */
439
- readonly "device.permission_not_migrated": 409;
440
445
  readonly "device.owner_report_stale": 409;
441
446
  /** A local device's old instance may still run legacy work until the computer restarts (8.5). */
442
447
  readonly "device.restart_required": 503;
@@ -444,19 +449,19 @@ export declare const ERROR_CODES: {
444
449
  readonly "device.replace_required": 503;
445
450
  /** A cloud device's earlier instance may run legacy work no evidence can cover (8.5). */
446
451
  readonly "device.recreate_required": 503;
447
- readonly "device.owner_ceiling_confirmation_required": 409;
448
- readonly "device.full_access_not_allowed": 409;
449
452
  /**
450
- * A device's mode is not a stored setting: a local device's mode lives on its machine
451
- * (`capybara-device ceiling set` or the device page's policy op), and a cloud device has none to
452
- * choose.
453
+ * A cloud device's network above its org's or the platform's ceiling, a host outside its org's
454
+ * list, or a widening through an API token or the Platform tool (narrow only).
453
455
  */
454
- readonly "device.mode_on_device": 409;
456
+ readonly "device.network_not_allowed": 400;
457
+ /** Running outside the sandbox where the device, its org, the platform or its provider forbids it. */
458
+ readonly "device.outside_sandbox_not_allowed": 409;
455
459
  /**
456
- * A cloud device's mode (`PATCH /devices/:id` `mode`, sandbox or null) sent with an API token:
457
- * only its owner in a web session changes it (hardening spec D2, K4).
460
+ * A local device's sandbox settings live on its machine: the web narrows them with
461
+ * `POST /devices/:id/policy`, the owner widens them on the machine (`capybara-device ceiling set`,
462
+ * `capybara-device policy add allowedDomains`).
458
463
  */
459
- readonly "device.mode_requires_session": 403;
464
+ readonly "device.ceiling_on_machine": 409;
460
465
  /**
461
466
  * The device offers no projects (project root §4.1): its `capybara-device` does not announce
462
467
  * `projects` (update it), or its cloud sandbox provider has no `list` / `scan`.
package/dist/errors.js CHANGED
@@ -45,10 +45,15 @@ export const ERROR_CODES = {
45
45
  "org.owner_required": 403,
46
46
  "org.sandbox_egress_not_allowed": 400,
47
47
  /**
48
- * The org asked for Full permission (`fullAccess: allowed`) where the platform turned it off, or
49
- * widened it through an API token or the Platform tool.
48
+ * The org allowed running outside the sandbox (`outsideSandbox: allowed`) where the platform
49
+ * turned it off, or widened it through an API token or the Platform tool.
50
50
  */
51
- "org.full_access_not_allowed": 400,
51
+ "org.outside_sandbox_not_allowed": 400,
52
+ /**
53
+ * The org's device network default or ceiling is above the platform's ceiling, or was opened
54
+ * through an API token or the Platform tool.
55
+ */
56
+ "org.network_not_allowed": 400,
52
57
  /** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
53
58
  "org.network_allowance_invalid": 400,
54
59
  "org.network_allowance_not_found": 404,
@@ -61,8 +66,13 @@ export const ERROR_CODES = {
61
66
  "org.external_sharing_not_allowed": 400,
62
67
  /** A deployment setting set in the startup config (file, Nacos or env): read-only in the admin console. */
63
68
  "deployment.setting_readonly": 409,
64
- /** Allowing the platform's Full permission through an API token or the Platform tool (only off). */
65
- "deployment.full_access_not_allowed": 400,
69
+ /** Allowing outside-sandbox runs platform-wide through an API token or the Platform tool (only off). */
70
+ "deployment.outside_sandbox_not_allowed": 400,
71
+ /**
72
+ * The platform's network default above its ceiling, or a default or ceiling opened through an API
73
+ * token or the Platform tool.
74
+ */
75
+ "deployment.network_not_allowed": 400,
66
76
  /** Allowing external sharing at the platform level through an API token or the Platform tool. */
67
77
  "deployment.external_sharing_not_allowed": 400,
68
78
  /**
@@ -432,11 +442,6 @@ export const ERROR_CODES = {
432
442
  * is admitted until a lifecycle action (a file reset) establishes them.
433
443
  */
434
444
  "device.permission_reconcile_required": 409,
435
- /**
436
- * B1: a cloud device's owner ceiling PATCH before its snapshot exists (not migrated yet); the old
437
- * sandbox switch still narrows it. A file reset does not change this.
438
- */
439
- "device.permission_not_migrated": 409,
440
445
  "device.owner_report_stale": 409,
441
446
  /** A local device's old instance may still run legacy work until the computer restarts (8.5). */
442
447
  "device.restart_required": 503,
@@ -444,19 +449,19 @@ export const ERROR_CODES = {
444
449
  "device.replace_required": 503,
445
450
  /** A cloud device's earlier instance may run legacy work no evidence can cover (8.5). */
446
451
  "device.recreate_required": 503,
447
- "device.owner_ceiling_confirmation_required": 409,
448
- "device.full_access_not_allowed": 409,
449
452
  /**
450
- * A device's mode is not a stored setting: a local device's mode lives on its machine
451
- * (`capybara-device ceiling set` or the device page's policy op), and a cloud device has none to
452
- * choose.
453
+ * A cloud device's network above its org's or the platform's ceiling, a host outside its org's
454
+ * list, or a widening through an API token or the Platform tool (narrow only).
453
455
  */
454
- "device.mode_on_device": 409,
456
+ "device.network_not_allowed": 400,
457
+ /** Running outside the sandbox where the device, its org, the platform or its provider forbids it. */
458
+ "device.outside_sandbox_not_allowed": 409,
455
459
  /**
456
- * A cloud device's mode (`PATCH /devices/:id` `mode`, sandbox or null) sent with an API token:
457
- * only its owner in a web session changes it (hardening spec D2, K4).
460
+ * A local device's sandbox settings live on its machine: the web narrows them with
461
+ * `POST /devices/:id/policy`, the owner widens them on the machine (`capybara-device ceiling set`,
462
+ * `capybara-device policy add allowedDomains`).
458
463
  */
459
- "device.mode_requires_session": 403,
464
+ "device.ceiling_on_machine": 409,
460
465
  /**
461
466
  * The device offers no projects (project root §4.1): its `capybara-device` does not announce
462
467
  * `projects` (update it), or its cloud sandbox provider has no `list` / `scan`.
@@ -17,7 +17,10 @@ import { type CaseSnapshot } from "./snapshot.js";
17
17
  * whose effective definition differs from the one frozen in its `subagent_started` (see
18
18
  * {@link subagentChanged}); the request still renders the logged definition and preamble. A child
19
19
  * case never consults `definitions` (no `definition_missing`);
20
- * - `params_changed`:没给候选参数时,记录的参数按所用模型的声明清洗后有键被丢弃或值变了(换了模型或模型声明变了);
20
+ * - `device_sandbox_changed`: the rebuilt permission context's `sandbox` block differs from the one
21
+ * the recorded metadata names (see {@link recordedPermissionContextDrift});
22
+ * - `params_changed`: without candidate params, sanitizing the recorded params against the model's
23
+ * declarations dropped a key or changed a value (another model, or its declarations changed);
21
24
  * - `media_missing`:某附件记录里不是「不再可用」,还原时却取不到;
22
25
  * - `media_changed`(只在基线判定):其余任何媒体结果与记录不同(按附件 id 比 outcome 与 etag:预算省略、
23
26
  * 图片数 / 页数上限、对象被替换后 etag 变了等);
@@ -30,7 +33,13 @@ export type DriftReason = "system_hash" | "tools_changed" | "tool_spec_missing"
30
33
  /** A child case's candidate has another effective definition than the logged one (phase C). */
31
34
  | "subagent_changed"
32
35
  /** Original bounded permission contributions or their recorded locator/hash differ. */
33
- | "permission_profile_changed" | "params_changed"
36
+ | "permission_profile_changed"
37
+ /**
38
+ * Approval-only profiles: the snapshot rebuilds another device `sandbox` block for the request
39
+ * than the one its recorded metadata names (`permissionContext.sandbox`). An ordinary sandbox
40
+ * change between runs is recorded input: zero drift.
41
+ */
42
+ | "device_sandbox_changed" | "params_changed"
34
43
  /**
35
44
  * UI refresh B: a non-baseline reconstruction whose run used a person's mid-conversation model
36
45
  * switch (`model_switched`) and whose candidate model (`modelRef`) replaces it.
@@ -104,7 +113,7 @@ type ModelCallEvent = Extract<ConversationEvent, {
104
113
  export declare function assertSnapshotPermissionEvents(events: readonly ConversationEvent[]): void;
105
114
  /**
106
115
  * Compare only the original request range, never live state or candidate-generated history.
107
- * Throws `eval.snapshot_invalid` first when any recorded v1 event in the snapshot
116
+ * Throws `eval.snapshot_invalid` first when any recorded permission event in the snapshot
108
117
  * (inside or outside the range, covered by a summary or not) fails its strict schema.
109
118
  */
110
119
  export declare function recordedPermissionContextDrift(events: readonly ConversationEvent[], call: ModelCallEvent): DriftReason[];
@@ -40,6 +40,7 @@ const DRIFT_ORDER = [
40
40
  "definition_missing",
41
41
  "subagent_changed",
42
42
  "permission_profile_changed",
43
+ "device_sandbox_changed",
43
44
  "params_changed",
44
45
  "model_switched",
45
46
  "media_missing",
@@ -76,7 +77,7 @@ export function assertSnapshotPermissionEvents(events) {
76
77
  }
77
78
  /**
78
79
  * Compare only the original request range, never live state or candidate-generated history.
79
- * Throws `eval.snapshot_invalid` first when any recorded v1 event in the snapshot
80
+ * Throws `eval.snapshot_invalid` first when any recorded permission event in the snapshot
80
81
  * (inside or outside the range, covered by a summary or not) fails its strict schema.
81
82
  */
82
83
  export function recordedPermissionContextDrift(events, call) {
@@ -87,12 +88,15 @@ export function recordedPermissionContextDrift(events, call) {
87
88
  if (recorded === undefined && rebuilt === undefined)
88
89
  return [];
89
90
  const parsed = PermissionContextMetaV1Schema.safeParse(recorded);
90
- if (!parsed.success ||
91
- rebuilt === undefined ||
92
- parsed.data.contextSeq !== rebuilt.contextSeq ||
93
- parsed.data.hash !== rebuilt.hash)
91
+ if (!parsed.success || rebuilt === undefined)
94
92
  return ["permission_profile_changed"];
95
- return [];
93
+ const drift = [];
94
+ if (parsed.data.contextSeq !== rebuilt.contextSeq || parsed.data.hash !== rebuilt.hash)
95
+ drift.push("permission_profile_changed");
96
+ // the sandbox block the request saw, against the one the snapshot rebuilds
97
+ if (parsed.data.sandbox !== rebuilt.sandbox)
98
+ drift.push("device_sandbox_changed");
99
+ return drift;
96
100
  }
97
101
  /** 该请求的 agent 版本:所属运行的 `run_started`;没有(不应出现)时用快照运行的版本。 */
98
102
  function recordedVersion(s, events, call) {
@@ -1,6 +1,7 @@
1
1
  import type { EventLog } from "../conversations/event-log.js";
2
2
  import type { ConversationEvent } from "../conversations/events.js";
3
3
  import type { PermissionContextPort } from "../runtime/model-call.js";
4
+ import { type DriftReason } from "./reconstruct.js";
4
5
  import { type CaseSnapshot } from "./snapshot.js";
5
6
  /**
6
7
  * Recorded-only permission context for a full-run replay (permission context replay spec B4).
@@ -63,11 +64,12 @@ export interface ReplayTarget {
63
64
  }
64
65
  /**
65
66
  * Recorded original-coordinate diagnostics over every original request of the replayed run (spec
66
- * "Replay and meaningful drift detection"): true when any of them cannot reproduce its recorded
67
- * permission metadata from its own bounded range. Throws `eval.snapshot_invalid` for a recorded
68
- * v1 event its strict schema rejects. Never compares generated seqs or hashes with the original.
67
+ * "Replay and meaningful drift detection"): the reasons (`permission_profile_changed`,
68
+ * `device_sandbox_changed`) of every request that cannot reproduce its recorded permission
69
+ * metadata from its own bounded range, deduplicated. Throws `eval.snapshot_invalid` for a recorded
70
+ * event its strict schema rejects. Never compares generated seqs or hashes with the original.
69
71
  */
70
- export declare function recordedRunPermissionDrift(s: CaseSnapshot): boolean;
72
+ export declare function recordedRunPermissionDrift(s: CaseSnapshot): DriftReason[];
71
73
  /**
72
74
  * The recorded-only feeder for the replay of `s` (spec B4) into `target`, or undefined for a
73
75
  * recording without any v1 permission marker, so the request boundary stays absent and old
@@ -1,5 +1,6 @@
1
1
  import { ApiError } from "../errors.js";
2
- import { assertSnapshotPermissionEvents, recordedPermissionContextDrift } from "./reconstruct.js";
2
+ import { readRecordedPermissionContext } from "../runtime/context/permission-profile.js";
3
+ import { assertSnapshotPermissionEvents, recordedPermissionContextDrift, } from "./reconstruct.js";
3
4
  import { toEvents } from "./snapshot.js";
4
5
  const invalid = (message) => new ApiError("eval.snapshot_invalid", message);
5
6
  /** Whether the recording holds any v1 permission marker (event, managed path or metadata). */
@@ -87,18 +88,22 @@ export function selectOriginalRequest(requests, step, attempt) {
87
88
  export const replayPermissionContextIdemKey = (generatedRunId, originalSeq) => `replay_permission_context:${generatedRunId}:${originalSeq}`;
88
89
  /**
89
90
  * Recorded original-coordinate diagnostics over every original request of the replayed run (spec
90
- * "Replay and meaningful drift detection"): true when any of them cannot reproduce its recorded
91
- * permission metadata from its own bounded range. Throws `eval.snapshot_invalid` for a recorded
92
- * v1 event its strict schema rejects. Never compares generated seqs or hashes with the original.
91
+ * "Replay and meaningful drift detection"): the reasons (`permission_profile_changed`,
92
+ * `device_sandbox_changed`) of every request that cannot reproduce its recorded permission
93
+ * metadata from its own bounded range, deduplicated. Throws `eval.snapshot_invalid` for a recorded
94
+ * event its strict schema rejects. Never compares generated seqs or hashes with the original.
93
95
  */
94
96
  export function recordedRunPermissionDrift(s) {
95
97
  const events = toEvents(s);
96
98
  if (!hasPermissionMarkers(events))
97
- return false;
99
+ return [];
98
100
  assertSnapshotPermissionEvents(events);
99
- return events.some((e) => e.type === "model_call" &&
100
- e.runId === s.runId &&
101
- recordedPermissionContextDrift(events, e).length > 0);
101
+ const drift = new Set();
102
+ for (const e of events)
103
+ if (e.type === "model_call" && e.runId === s.runId)
104
+ for (const reason of recordedPermissionContextDrift(events, e))
105
+ drift.add(reason);
106
+ return [...drift];
102
107
  }
103
108
  /**
104
109
  * The recorded-only feeder for the replay of `s` (spec B4) into `target`, or undefined for a
@@ -139,7 +144,8 @@ export function recordedPermissionContext(s, eventLog, target) {
139
144
  type: "permission_context",
140
145
  runId: target.runId,
141
146
  idemKey: replayPermissionContextIdemKey(target.runId, c.seq),
142
- payload: structuredClone(c.payload),
147
+ // the eval log is new: a stored v1 context is written as its v2 form (same text)
148
+ payload: readRecordedPermissionContext(c.payload),
143
149
  })));
144
150
  for (const [i, c] of due.entries()) {
145
151
  const w = written[i];
@@ -48,9 +48,14 @@ export interface RunReplayResult {
48
48
  * reports `permission_profile_changed`.
49
49
  */
50
50
  permissionContextDrift?: true;
51
+ /**
52
+ * Set when an original request of the run rebuilds another device sandbox block than its
53
+ * recorded metadata names; the result reports `device_sandbox_changed`.
54
+ */
55
+ deviceSandboxDrift?: true;
51
56
  }
52
57
  /** 原运行(基线)的同形摘要。 */
53
- export type RunBaseline = Omit<RunReplayResult, "conversationId" | "outcome" | "unmatched" | "permissionContextDrift">;
58
+ export type RunBaseline = Omit<RunReplayResult, "conversationId" | "outcome" | "unmatched" | "permissionContextDrift" | "deviceSandboxDrift">;
54
59
  /** 测试钩子。 */
55
60
  export interface EvalReplayHooks {
56
61
  /** 种子已写入(评测对话已记到结果上)、loop 开始之前调用:抛错即模拟此时崩溃。 */
@@ -375,7 +375,7 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
375
375
  // recorded permission context (spec B4), both before anything is seeded so an invalid recording
376
376
  // fails as `eval.snapshot_invalid` without an eval conversation: the original-coordinate
377
377
  // diagnostics, and the recorded-only feeder (undefined for a recording without markers)
378
- const permissionContextDrift = recordedRunPermissionDrift(s);
378
+ const permissionDrift = recordedRunPermissionDrift(s);
379
379
  const permissionContext = recordedPermissionContext(s, eventLog, { conversationId, runId });
380
380
  // the recorded tool results (reviews validated here) are read before the seed too, so an
381
381
  // invalid recording leaves no eval conversation either
@@ -677,6 +677,11 @@ export async function replayRun(d, s, candidate, evalRunId, signal) {
677
677
  outcome: outcome.kind,
678
678
  ...summary,
679
679
  unmatched: pipeline.unmatched(),
680
- ...(permissionContextDrift && { permissionContextDrift: true }),
680
+ ...(permissionDrift.includes("permission_profile_changed") && {
681
+ permissionContextDrift: true,
682
+ }),
683
+ ...(permissionDrift.includes("device_sandbox_changed") && {
684
+ deviceSandboxDrift: true,
685
+ }),
681
686
  };
682
687
  }
@@ -692,11 +692,13 @@ let EvalWorker = class EvalWorker {
692
692
  return;
693
693
  const baseline = runBaseline(s);
694
694
  // in DRIFT_ORDER: subagent_changed, permission_profile_changed (a recorded permission
695
- // context the snapshot cannot reproduce), model_switched (the candidate replaced the person's
695
+ // context the snapshot cannot reproduce), device_sandbox_changed (another rebuilt device
696
+ // sandbox block than the recorded one), model_switched (the candidate replaced the person's
696
697
  // switch), then tool_unmatched
697
698
  const drift = [
698
699
  ...(subagentCaseChanged(s, resolved) ? ["subagent_changed"] : []),
699
700
  ...(out.permissionContextDrift ? ["permission_profile_changed"] : []),
701
+ ...(out.deviceSandboxDrift ? ["device_sandbox_changed"] : []),
700
702
  ...(resolved.overridesSwitch ? ["model_switched"] : []),
701
703
  ...(out.unmatched > 0 ? ["tool_unmatched"] : []),
702
704
  ];