@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,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.
@@ -10,6 +10,7 @@ import { SandboxOperationReconcileJob } from "../sandbox/operation-reconcile.job
10
10
  import { SandboxService } from "../sandbox/sandbox.service.js";
11
11
  import { ScheduledTaskFirer } from "../schedules/fire.js";
12
12
  import { ShareObjects } from "../shares/share-objects.js";
13
+ import { PlatformIconObjects } from "../themes/platform-icon-objects.js";
13
14
  import { DeviceOpResolver } from "../tools/device-op-resolver.js";
14
15
  import { ToolDrift } from "../tools/drift.js";
15
16
  import { PermissionApprovalJobs } from "../tools/permission-approval-jobs.js";
@@ -27,7 +28,8 @@ export declare const MAINTENANCE_CONCURRENCY = 5;
27
28
  * {@link processStopTree} and `deliver-to-parent` → {@link processDeliverToParent} (both in
28
29
  * runtime/subagents/tree-jobs.ts, over {@link Waits}), `owned-plugin-cleanup` →
29
30
  * {@link OwnedPluginCleanup}, `sched-fire` and `sched-settle` → {@link ScheduledTaskFirer}, `device-op-resolve` →
30
- * {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
31
+ * {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}, `platform-icon-delete` →
32
+ * {@link PlatformIconObjects}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
31
33
  * such as `sandbox-suspend-idle`) runs that job's body once ({@link ScheduledRuns.runNow}), as the
32
34
  * maintenance handlers did when those jobs were schedulers on this queue: an operator's or a
33
35
  * test's one-off run, not a second schedule (decision R23 of the Nest kernel spec). Any other
@@ -49,8 +51,9 @@ export declare class MaintenanceProcessor extends WorkerHost<Worker> {
49
51
  private readonly log;
50
52
  private readonly operations;
51
53
  private readonly shareObjects;
54
+ private readonly platformIcons;
52
55
  private readonly snapshots?;
53
- constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem" | "revokeDeadHolder">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, deviceOps: Pick<DeviceOpResolver, "resolve">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke">, shareObjects: Pick<ShareObjects, "deleteObject">, snapshots?: Pick<CloudPermissionSnapshots, "reconcileDevice"> | undefined);
56
+ constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem" | "revokeDeadHolder">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, deviceOps: Pick<DeviceOpResolver, "resolve">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke">, shareObjects: Pick<ShareObjects, "deleteObject">, platformIcons: Pick<PlatformIconObjects, "deleteObject">, snapshots?: Pick<CloudPermissionSnapshots, "reconcileDevice"> | undefined);
54
57
  process(job: Job, token?: string): Promise<void>;
55
58
  /** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
56
59
  start(): void;
@@ -33,6 +33,7 @@ import { SandboxService } from "../sandbox/sandbox.service.js";
33
33
  import { ScheduledTaskFireModule, ScheduledTaskFirer } from "../schedules/fire.js";
34
34
  import { SCHED_FIRE_JOB, SCHED_SETTLE_JOB, } from "../schedules/job-ids.js";
35
35
  import { SHARE_OBJECT_DELETE_JOB, ShareObjects, ShareObjectsModule, } from "../shares/share-objects.js";
36
+ import { PLATFORM_ICON_DELETE_JOB, PlatformIconObjects, PlatformIconObjectsModule, } from "../themes/platform-icon-objects.js";
36
37
  import { DeviceOpResolver } from "../tools/device-op-resolver.js";
37
38
  import { ToolDrift } from "../tools/drift.js";
38
39
  import { DRIFT_CONNECTOR_JOB } from "../tools/job-ids.js";
@@ -55,7 +56,8 @@ export const MAINTENANCE_CONCURRENCY = 5;
55
56
  * {@link processStopTree} and `deliver-to-parent` → {@link processDeliverToParent} (both in
56
57
  * runtime/subagents/tree-jobs.ts, over {@link Waits}), `owned-plugin-cleanup` →
57
58
  * {@link OwnedPluginCleanup}, `sched-fire` and `sched-settle` → {@link ScheduledTaskFirer}, `device-op-resolve` →
58
- * {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
59
+ * {@link DeviceOpResolver}, `share-object-delete` → {@link ShareObjects}, `platform-icon-delete` →
60
+ * {@link PlatformIconObjects}). The name of a periodic job (a `@LockedCron` / `@LockedInterval` job,
59
61
  * such as `sandbox-suspend-idle`) runs that job's body once ({@link ScheduledRuns.runNow}), as the
60
62
  * maintenance handlers did when those jobs were schedulers on this queue: an operator's or a
61
63
  * test's one-off run, not a second schedule (decision R23 of the Nest kernel spec). Any other
@@ -77,8 +79,9 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
77
79
  log;
78
80
  operations;
79
81
  shareObjects;
82
+ platformIcons;
80
83
  snapshots;
81
- constructor(permissionApprovals, waits, sandbox, drift, directory, deletion, offboarding, runs, ownedCleanup, scheduledTasks, deviceOps, scheduled, log, operations, shareObjects, snapshots) {
84
+ constructor(permissionApprovals, waits, sandbox, drift, directory, deletion, offboarding, runs, ownedCleanup, scheduledTasks, deviceOps, scheduled, log, operations, shareObjects, platformIcons, snapshots) {
82
85
  super();
83
86
  this.permissionApprovals = permissionApprovals;
84
87
  this.waits = waits;
@@ -95,6 +98,7 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
95
98
  this.log = log;
96
99
  this.operations = operations;
97
100
  this.shareObjects = shareObjects;
101
+ this.platformIcons = platformIcons;
98
102
  this.snapshots = snapshots;
99
103
  }
100
104
  process(job, token) {
@@ -197,6 +201,10 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
197
201
  case SHARE_OBJECT_DELETE_JOB:
198
202
  await this.shareObjects.deleteObject(job.data);
199
203
  return;
204
+ // a platform icon object no row names any more, or an upload's orphan check (§10.2.1)
205
+ case PLATFORM_ICON_DELETE_JOB:
206
+ await this.platformIcons.deleteObject(job.data);
207
+ return;
200
208
  default:
201
209
  if (await this.scheduled.runNow(job.name))
202
210
  return;
@@ -236,8 +244,9 @@ MaintenanceProcessor = __decorate([
236
244
  __param(12, Inject(KERNEL_LOGGER)),
237
245
  __param(13, Inject(SandboxOperationReconcileJob)),
238
246
  __param(14, Inject(ShareObjects)),
239
- __param(15, Optional()),
240
- __param(15, Inject(CloudPermissionSnapshots))
247
+ __param(15, Inject(PlatformIconObjects)),
248
+ __param(16, Optional()),
249
+ __param(16, Inject(CloudPermissionSnapshots))
241
250
  ], MaintenanceProcessor);
242
251
  export { MaintenanceProcessor };
243
252
  /**
@@ -264,6 +273,8 @@ MaintenanceModule = __decorate([
264
273
  ScheduledTaskFireModule,
265
274
  // the share snapshot deletion
266
275
  ShareObjectsModule,
276
+ // the platform icon object deletion
277
+ PlatformIconObjectsModule,
267
278
  QueueModule.registerQueue(MAINTENANCE_QUEUE_NAME),
268
279
  ],
269
280
  providers: [
@@ -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
  }
@@ -84,10 +84,6 @@ export declare const projectUnavailable: {
84
84
  reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
85
85
  message: string;
86
86
  };
87
- readonly widerMode: (root: string) => {
88
- reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
89
- message: string;
90
- };
91
87
  readonly removed: (project: string) => {
92
88
  reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
93
89
  message: string;
@@ -97,6 +93,11 @@ export declare const projectUnavailable: {
97
93
  reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
98
94
  message: string;
99
95
  };
96
+ /** A device runtime that refused the kernel's read-only read scope (its text is logged). */
97
+ readonly refused: (root: string) => {
98
+ reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
99
+ message: string;
100
+ };
100
101
  readonly unsupported: () => {
101
102
  reason: "gone" | "outside_mode" | "removed" | "unreadable" | "unsupported";
102
103
  message: string;
@@ -41,10 +41,11 @@ export const projectUnavailable = {
41
41
  notDirectory: (root) => unavailable("unreadable", `The project's root ${clipped(root)} is not a directory.`),
42
42
  /** The device's own error text is logged, never recorded: the message stays the same per root. */
43
43
  unreadable: (root) => unavailable("unreadable", `The project's root ${clipped(root)} could not be read.`),
44
- widerMode: (root) => unavailable("outside_mode", `The project's root ${clipped(root)} was not read: the device runs a wider mode than the organization allows.`),
45
44
  removed: (project) => unavailable("removed", `The project "${clipped(project, 80)}" was removed from the device's projects.`),
46
45
  /** A host machine whose runtime cannot enforce the kernel's read-only read (gate on). */
47
46
  notEnforceable: (root) => unavailable("unreadable", `The project's root ${clipped(root)} was not read: this device's runtime cannot enforce a read-only read on its host; turn on its sandbox enforcement or use another device.`),
47
+ /** A device runtime that refused the kernel's read-only read scope (its text is logged). */
48
+ refused: (root) => unavailable("unreadable", `The project's root ${clipped(root)} was not read: this device's runtime refused the kernel's read-only read.`),
48
49
  unsupported: () => unavailable("unsupported", "The device does not offer projects; capybara-device on that machine needs an update."),
49
50
  };
50
51
  /** The snapshot of a project the run cannot use: the reason alone, no AGENTS.md, no skills. */
@@ -7,11 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { DeviceProtocolError } from "@capybara-hq/plugin-sdk";
10
+ import { DeviceProtocolError, isSandboxPermissionUnsupportedError } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable, Optional } from "@nestjs/common";
12
12
  import { EventLog } from "../../conversations/event-log.js";
13
13
  import { ConversationDevices } from "../../devices/conversation-devices.js";
14
- import { DeviceProjectsService, readModeOf, withinMode, } from "../../devices/device-projects.service.js";
14
+ import { DeviceProjectsService, withinMode } from "../../devices/device-projects.service.js";
15
15
  import { aboveHome } from "../../devices/working-root.js";
16
16
  import { ApiError } from "../../errors.js";
17
17
  import { KernelDb } from "../../infra/database/kernel-db.js";
@@ -194,15 +194,6 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
194
194
  });
195
195
  return unavailableProject(bound.project, bound.root, projectUnavailable.unsupported());
196
196
  }
197
- // A machine reporting a wider mode than the org allows is not read unasked. The local
198
- // provider rechecks the current ceiling on every readFile / stat request as well.
199
- if (scope.widerThanAllowed) {
200
- this.log.warn("project knowledge not read: the device runs a wider mode than allowed", {
201
- ...where,
202
- deviceId,
203
- });
204
- return unavailableProject(bound.project, bound.root, projectUnavailable.widerMode(bound.root));
205
- }
206
197
  const enter = await this.entry(input, bound.accountId, bound.root);
207
198
  return await enter({
208
199
  orgId: input.orgId,
@@ -231,16 +222,28 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
231
222
  stat: (path) => p.stat(h, path, sig),
232
223
  readFile: (path, maxBytes) => p.readFile(h, path, { maxBytes, signal: sig }),
233
224
  ...(list !== undefined && {
234
- list: (path, limit) => list.call(p, h, path, { limit, limits: { mode: readModeOf(scope) }, signal: sig }),
225
+ list: (path, limit) => list.call(p, h, path, { limit, signal: sig }),
235
226
  }),
236
227
  };
237
228
  try {
238
229
  return await readProjectKnowledge(files, target, {
239
230
  log: (msg, detail) => this.log.info(msg, { ...where, ...detail }),
240
- isDeviceFailure: (e) => sig.aborted || isDeviceFailure(e),
231
+ // a runtime refusing the read's scope refuses every read of it: thrown, so no
232
+ // half-read snapshot is recorded
233
+ isDeviceFailure: (e) => sig.aborted || isDeviceFailure(e) || isSandboxPermissionUnsupportedError(e),
241
234
  });
242
235
  }
243
236
  catch (e) {
237
+ // the device's runtime refused the kernel read's scope: the project is recorded
238
+ // unreadable (the provider's text is logged, never recorded) and the run goes on
239
+ if (isSandboxPermissionUnsupportedError(e) && !sig.aborted) {
240
+ this.log.warn("project knowledge not read: the device refused the read's scope", {
241
+ ...where,
242
+ deviceId,
243
+ reason: e.message,
244
+ });
245
+ return unavailableProject(bound.project, bound.root, projectUnavailable.refused(bound.root));
246
+ }
244
247
  // gate on: a host runtime without restricted enforcement gets no kernel read; the
245
248
  // project is recorded unreadable with the reason and the run goes on
246
249
  if (!(e instanceof KernelReadUnsupported))
@@ -227,6 +227,9 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
227
227
  .set({
228
228
  owner_full_access: snap.fullAccess,
229
229
  outer_network: JSON.stringify(snap.outerNetwork),
230
+ // the device's own sandbox network carries an allowlist snapshot (never wider): the
231
+ // device sandbox reads it, not `outer_network`
232
+ ...(device.network_mode === null && ownNetworkOf(snap.outerNetwork)),
230
233
  permission_migration: JSON.stringify({
231
234
  from: "auto-mode",
232
235
  old: { mode: old.mode, network: old.network },
@@ -257,9 +260,10 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
257
260
  return !snap.fullAccess;
258
261
  if (outer.kind !== "allowlist" || !("network" in scope) || !isExecutionMethod(row.method))
259
262
  return false;
260
- // an execution outside any allowlist (environment networking) is wider than the outer
261
- // allowlist; `none` is narrower; an allowlist must be covered host by host
262
- if (scope.network.kind === "environment")
263
+ // an execution outside any allowlist (environment networking, the open public network)
264
+ // is wider than the outer allowlist; `none` is narrower; an allowlist must be covered
265
+ // host by host
266
+ if (scope.network.kind === "environment" || scope.network.kind === "open-public")
263
267
  return true;
264
268
  if (scope.network.kind !== "allowlist")
265
269
  return false;
@@ -303,6 +307,8 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
303
307
  .set({
304
308
  owner_full_access: narrowed.fullAccess,
305
309
  outer_network: JSON.stringify(narrowed.outerNetwork),
310
+ // a narrower instance narrows the device's own network choice too
311
+ ...ownNetworkOf(narrowed.outerNetwork),
306
312
  })
307
313
  .where("id", "=", deviceId)
308
314
  .execute();
@@ -354,6 +360,7 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
354
360
  "mode",
355
361
  "owner_full_access",
356
362
  "outer_network",
363
+ "network_mode",
357
364
  "permission_reconcile_required",
358
365
  "deleted_at",
359
366
  ])
@@ -405,3 +412,15 @@ CloudPermissionSnapshots = __decorate([
405
412
  __param(9, Inject(SandboxProviders))
406
413
  ], CloudPermissionSnapshots);
407
414
  export { CloudPermissionSnapshots };
415
+ /**
416
+ * The device's own sandbox network columns for an allowlist snapshot, as migrations 0165 and 0167
417
+ * copy them: its hosts as an allowlist, or `none` (closed) for an empty one; nothing for an open
418
+ * one, which follows the org.
419
+ */
420
+ function ownNetworkOf(outer) {
421
+ if (outer.kind !== "allowlist")
422
+ return {};
423
+ return outer.hosts.length === 0
424
+ ? { network_mode: "none", network_hosts: "[]" }
425
+ : { network_mode: "allowlist", network_hosts: JSON.stringify([...outer.hosts]) };
426
+ }