@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,11 +1,11 @@
1
- import { DEFAULT_SANDBOX_ROOTS, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, ToolError, } from "@capybara-hq/plugin-sdk";
1
+ import { classifyAddress, DEFAULT_SANDBOX_ROOTS, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, ToolError, } from "@capybara-hq/plugin-sdk";
2
2
  import { backgroundMaxSeconds, LAUNCH_EXEC_TIMEOUT_MS, managedStartedText, managedTaskArtifactPath, newTaskId, } from "../../../background/launch.js";
3
3
  import { taskReasonText } from "../../../background/render.js";
4
4
  import { isDeviceRequestNotSent } from "../../../local-devices/relay.js";
5
5
  import { isEscalationGrantMissing } from "../../../sandbox/operation-authority-types.js";
6
6
  import { launchRefusedText, operationIdFor } from "../../../sandbox/operation-intents.js";
7
7
  import { ESCALATION_JUSTIFICATION_MAX_CHARS, ESCALATION_RETRY_HINT, SANDBOX_ESCALATED, } from "../../../sandbox/review/permission-candidate.js";
8
- import { clip, display, inSandboxOperations, inToolSandbox, runBudgetNote, runTimeLeftMs, SCOPE_DENIED_TOOL_TEXT, sandboxBaseTimeoutMs, sandboxConversationOf, unavailableWhenNoSandbox, withNotices, } from "./common.js";
8
+ import { clip, display, ESCALATION_GRANT_MISSING_LAUNCH_WHY, inSandboxOperations, inToolSandbox, runBudgetNote, runTimeLeftMs, SCOPE_DENIED_TOOL_TEXT, sandboxBaseTimeoutMs, sandboxConversationOf, unavailableWhenNoSandbox, withNotices, } from "./common.js";
9
9
  import { parseDeviceCode } from "./device-code.js";
10
10
  /** The command timeout in seconds when `timeout` is not given, at most `sandbox.limits.maxCommandSeconds`. */
11
11
  export const BASH_DEFAULT_TIMEOUT_SECONDS = 120;
@@ -55,16 +55,21 @@ const SPEC = {
55
55
  "command exits, and processes it left running are stopped. A background task is lost if the " +
56
56
  "sandbox is suspended (it is suspended after it has been running for a while, " +
57
57
  "sandbox.limits.maxRunningMinutes).\n\n" +
58
- "Commands run inside an OS sandbox that limits which directories they may write and which " +
59
- "hosts they may reach. When the sandbox blocks a command you need (for example 'Operation not " +
60
- "permitted' writing outside the project, or a dev tool that must reach the machine), retry " +
61
- 'that one call with sandbox: "escalated" and a justification saying why; the user or a review ' +
62
- "model decides, and only that call runs outside the sandbox. Do not escalate by default: try " +
63
- "inside the sandbox first. Some devices and organizations do not allow it.\n\n" +
64
- "Network access goes through a proxy set in HTTP_PROXY / HTTPS_PROXY / ALL_PROXY; a tool " +
65
- "that ignores them fails with 'Operation not permitted' or cannot resolve names; such a tool " +
66
- "needs the proxy passed explicitly through its own proxy option. A blocked domain is " +
67
- "reported after the output.",
58
+ "Commands run inside an OS sandbox under every permission profile: it limits which " +
59
+ "directories they may write, keeps private, LAN, loopback and cloud metadata addresses and " +
60
+ "the Docker socket closed, and, when the device's network is an allowlist, limits which " +
61
+ "hosts they may reach. When the sandbox blocks a command you need (for example 'Operation " +
62
+ "not permitted' writing outside the project, a dev server that must listen on a port, or a " +
63
+ 'service on localhost or the LAN), retry that one call with sandbox: "escalated" and a ' +
64
+ "justification saying why; this conversation's permission profile decides (the user, a " +
65
+ "review model, or Full access within the device's limits), and only that call runs outside " +
66
+ "the sandbox. Do not escalate by default: try inside the sandbox first. Some devices and " +
67
+ "organizations do not allow it.\n\n" +
68
+ "Network access goes through a proxy set in HTTP_PROXY / HTTPS_PROXY / ALL_PROXY; HTTP(S)- " +
69
+ "and SOCKS-aware clients work on any port. A tool that ignores them (plain ssh, for example) " +
70
+ "fails with 'Operation not permitted' or cannot resolve names; pass the proxy through its " +
71
+ "own option (for git over ssh, GIT_SSH_COMMAND with a SOCKS ProxyCommand). A blocked domain " +
72
+ "is reported after the output.",
68
73
  inputSchema: {
69
74
  type: "object",
70
75
  properties: {
@@ -91,7 +96,7 @@ const SPEC = {
91
96
  sandbox: {
92
97
  type: "string",
93
98
  enum: [SANDBOX_ESCALATED],
94
- description: 'Set to "escalated" to ask to run this one call outside the OS sandbox (also in the background). Requires justification; the user or a review model approves it first.',
99
+ description: "Set to \"escalated\" to ask to run this one call outside the OS sandbox (also in the background). Requires justification; this conversation's permission profile decides first (the user, a review model, or Full access within the device's limits).",
95
100
  },
96
101
  justification: {
97
102
  type: "string",
@@ -305,7 +310,7 @@ export async function runInBackgroundManaged(deps, ctx, input) {
305
310
  /** Why a managed start was refused, in the kernel's own words (never the provider's message). */
306
311
  function launchRefusedWhy(e) {
307
312
  if (isEscalationGrantMissing(e))
308
- return 'its approval to run outside the sandbox no longer matches (the device, its Full access ceiling or the permission scope changed since it was approved); call Bash again with sandbox: "escalated" and a justification to ask again';
313
+ return ESCALATION_GRANT_MISSING_LAUNCH_WHY;
309
314
  return launchRefusedText(isDeviceRequestNotSent(e)
310
315
  ? "not_sent"
311
316
  : isSandboxScopeDeniedError(e)
@@ -319,33 +324,77 @@ const isRefusal = (e) => !isSandboxOperationOutcomeUnknownError(e) &&
319
324
  (isSandboxScopeDeniedError(e) || isSandboxPermissionUnsupportedError(e));
320
325
  /**
321
326
  * Sandbox-specific signals in a command's output: the EPERM a Seatbelt or Landlock write denial
322
- * gives, the read-only bind of the Linux sandbox, Seatbelt's own deny report, and the sandbox
323
- * proxy refusing a host or a tunnel. A plain "Permission denied" (EACCES) is not one: ssh
324
- * publickey failures, git 403s and file modes print it too.
327
+ * gives, the read-only bind of the Linux sandbox and Seatbelt's own deny report.
328
+ * A plain "Permission denied" (EACCES) is not one: ssh publickey failures, git 403s and file modes
329
+ * print it too.
325
330
  */
326
- const SANDBOX_DENIED_RE = /Operation not permitted|Read-only file system|Sandbox: \S+\(\d+\) deny\(\d+\)|Connection blocked by network allowlist|blocked-by-allowlist|HTTP code 403 from proxy after CONNECT/;
331
+ const SANDBOX_DENIED_RE = /Operation not permitted|Read-only file system|Sandbox: \S+\(\d+\) deny\(\d+\)/;
332
+ /** The sandbox proxy refusing a host or a tunnel (in curl 7's and curl 8's wording). */
333
+ const SANDBOX_PROXY_REFUSED_RE = /Connection blocked by network allowlist|blocked-by-allowlist|HTTP code 403 from proxy after CONNECT|CONNECT tunnel failed, response 403/;
334
+ /**
335
+ * curl's direct connect failure, with the address it dialled. A restricted command never reaches
336
+ * an address in a closed class (private, loopback, link-local, …) directly, so such a failure is
337
+ * the sandbox's: a client that ignored the proxy variables (or `--noproxy`) dialled it itself, and
338
+ * Seatbelt or the network namespace gives no message of its own.
339
+ */
340
+ const DIRECT_CONNECT_FAILED_RE = /Failed to connect to (\S+) port \d+/g;
341
+ const closedAddress = (host) => {
342
+ try {
343
+ return classifyAddress(host.replace(/^\[(.*)\]$/, "$1")) !== "public";
344
+ }
345
+ catch {
346
+ // a name, not an address: curl names the host it was asked for, not where it resolved
347
+ return false;
348
+ }
349
+ };
327
350
  /**
328
351
  * Credential and auth failures: never a reason to run outside the sandbox, so they never get the
329
352
  * escalation hint, whatever else the output says.
330
353
  */
331
354
  const AUTH_FAILURE_RE = /Permission denied \(publickey|Host key verification failed|Authentication failed|authentication required|could not read (?:Username|Password)|Bad credentials|invalid credentials|remote: Permission to \S+ denied|The requested URL returned error: 40[13]|\b401 Unauthorized\b/i;
332
355
  /**
333
- * Whether a finished command failed in a way the OS sandbox may have caused: a host the device
334
- * refused (`network.blocked`) or a sandbox-specific message, and no credential or auth failure.
356
+ * How a finished command failed in a way the OS sandbox may have caused: `network` for a host the
357
+ * device refused (`network.blocked`), the proxy's refusal or a direct connect to a closed address;
358
+ * `other` for a sandbox-specific message; null when neither, or on a credential or auth failure.
335
359
  */
336
- export const sandboxDenied = (r) => {
360
+ export const sandboxDenial = (r) => {
337
361
  if (r.exitCode === null || r.exitCode === 0)
338
- return false;
362
+ return null;
339
363
  const out = `${r.stdout}\n${r.stderr}`;
340
364
  if (AUTH_FAILURE_RE.test(out))
341
- return false;
342
- return (r.network?.blocked.length ?? 0) > 0 || SANDBOX_DENIED_RE.test(out);
365
+ return null;
366
+ if ((r.network?.blocked.length ?? 0) > 0 ||
367
+ SANDBOX_PROXY_REFUSED_RE.test(out) ||
368
+ [...out.matchAll(DIRECT_CONNECT_FAILED_RE)].some((m) => closedAddress(m[1])))
369
+ return "network";
370
+ return SANDBOX_DENIED_RE.test(out) ? "other" : null;
343
371
  };
372
+ /** Whether a finished command failed in a way the OS sandbox may have caused ({@link sandboxDenial}). */
373
+ export const sandboxDenied = (r) => sandboxDenial(r) !== null;
374
+ /**
375
+ * The line a restricted `Bash` result ends with when the OS sandbox may have denied it: what the
376
+ * sandbox closes, then either the invitation to retry escalated (this device and org allow running
377
+ * outside the sandbox) or why that is not possible here and who can change it (the per-layer
378
+ * escalation refusal). Empty for an escalated call, a call without escalation facts, or no signal.
379
+ */
380
+ export function sandboxDenialHint(r, escalation) {
381
+ if (escalation.escalation !== "available" && escalation.refusal === undefined)
382
+ return "";
383
+ const kind = sandboxDenial(r);
384
+ if (kind === null)
385
+ return "";
386
+ const lead = kind === "network"
387
+ ? "\n[sandbox] The OS sandbox may have blocked this command's connection: private and local addresses are closed inside the sandbox, and so is any host the sandbox network does not allow."
388
+ : "\n[sandbox] The OS sandbox may have blocked this command.";
389
+ return escalation.escalation === "available"
390
+ ? `${lead}${ESCALATION_RETRY_HINT}`
391
+ : `${lead} Running it outside the sandbox is not possible here: ${escalation.refusal}.`;
392
+ }
344
393
  /**
345
394
  * {@link SCOPE_DENIED_TOOL_TEXT} followed by {@link ESCALATION_RETRY_HINT}, written out as a literal
346
395
  * for the tool design check (a unit test keeps the two copies equal).
347
396
  */
348
- export const SCOPE_DENIED_ESCALATION_TEXT = 'This operation reaches outside what this conversation\'s permission profile allows on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory or choose a broader permission profile, then retry. If this command must reach outside the sandbox, retry the same Bash call with sandbox: "escalated" and justification: one sentence saying why; the user or the review model decides whether it may run outside the sandbox for this call only.';
397
+ export const SCOPE_DENIED_ESCALATION_TEXT = "This operation reaches outside what this conversation's permission profile allows on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory or choose a broader permission profile, then retry. If this command must reach outside the sandbox, retry the same Bash call with sandbox: \"escalated\" and justification: one sentence saying why; this conversation's permission profile decides whether it may run outside the sandbox for this call only (the user, the review model, or Full access within this device's limits).";
349
398
  /**
350
399
  * A restricted call the scope refused ({@link SCOPE_DENIED_TOOL_TEXT}) where running outside the
351
400
  * sandbox is allowed: the refusal also says the call may be retried escalated.
@@ -421,9 +470,12 @@ export function sandboxBashTool(deps) {
421
470
  : "";
422
471
  const text = formatExec(r, seconds, clamped, workspace) +
423
472
  lowered +
424
- (ctx.sandboxEscalation === "available" && sandboxDenied(r)
425
- ? `\n[sandbox] The OS sandbox may have blocked this command.${ESCALATION_RETRY_HINT}`
426
- : "");
473
+ sandboxDenialHint(r, {
474
+ ...(ctx.sandboxEscalation !== undefined && { escalation: ctx.sandboxEscalation }),
475
+ ...(ctx.sandboxEscalationRefusal !== undefined && {
476
+ refusal: ctx.sandboxEscalationRefusal,
477
+ }),
478
+ });
427
479
  return {
428
480
  content: [{ type: "text", text: withNotices(notices, text) }],
429
481
  isError: r.timedOut || r.exitCode === null,
@@ -87,8 +87,15 @@ export interface SandboxToolDeps {
87
87
  export interface SandboxSession {
88
88
  /** The device the call runs in (path leases are taken on it). */
89
89
  deviceId: string;
90
- /** The mode the device runs at now (auto mode spec §4.1): the file tools' path checks follow it. */
91
- mode: SandboxMode;
90
+ /**
91
+ * What bounds the file tools' paths ({@link checkToolPath}), never the device's tier or its
92
+ * outside-sandbox setting (approval-only profiles: the sandbox is the same under every profile):
93
+ * - `scope`: the operation's admitted scope. On the managed route every native request carries
94
+ * it (project roots plus directory grants, protected paths excluded) and the device enforces
95
+ * it, as for `Bash`, so the kernel checks only a path's shape; legacy auto mode too.
96
+ * - `roots`: the instance's fixed roots (the legacy route in sandbox mode only).
97
+ */
98
+ pathBound: "scope" | "roots";
92
99
  h: SandboxHandle;
93
100
  /** The instance's roots: every path the call builds or checks is under one of them. */
94
101
  roots: SandboxRoots;
@@ -192,11 +199,13 @@ export declare function checkPathShape(path: string, field?: string): void;
192
199
  */
193
200
  export declare function checkPath(path: string, roots: SandboxRoots, field?: string): string;
194
201
  /**
195
- * A file tool's path in the mode the device runs at now (auto mode spec §4.1, decision 1): auto
196
- * mode accepts any clean absolute path on the machine (shape checks only, the review judges a write
197
- * outside the workspace); sandbox mode keeps the roots ({@link checkPath}).
202
+ * A file tool's path under the session's {@link SandboxSession.pathBound}: bounded by the
203
+ * operation's admitted scope, any clean absolute path passes here (shape checks only; the review
204
+ * proposes a directory crossing for a path outside the scope, and the device refuses one the
205
+ * scope does not cover, protected paths included); bounded by the fixed roots, a path must lie
206
+ * under one of them ({@link checkPath}).
198
207
  */
199
- export declare function checkToolPath(path: string, s: Pick<SandboxSession, "roots" | "mode">, field?: string): string;
208
+ export declare function checkToolPath(path: string, s: Pick<SandboxSession, "roots" | "pathBound">, field?: string): string;
200
209
  /**
201
210
  * The shape checks of a file tool's path before the call enters its device: an absolute path gets
202
211
  * {@link checkPathShape}; a relative one (resolved against the working root inside,
@@ -210,8 +219,8 @@ export declare function checkFilePathShape(path: string, field?: string): void;
210
219
  * The result still goes through {@link checkToolPath}.
211
220
  */
212
221
  export declare function resolveToolPath(path: string, s: Pick<SandboxSession, "workingRoot">): string;
213
- /** {@link checkToolPath} for a writing tool: the skills directory stays read-only in both modes. */
214
- export declare function checkToolWritable(path: string, s: Pick<SandboxSession, "roots" | "mode" | "workingRoot">): string;
222
+ /** {@link checkToolPath} for a writing tool: the skills directory stays read-only either way. */
223
+ export declare function checkToolWritable(path: string, s: Pick<SandboxSession, "roots" | "pathBound" | "workingRoot">): string;
215
224
  /** POSIX shell 单引号转义。 */
216
225
  export declare function shellQuote(s: string): string;
217
226
  /**
@@ -231,14 +240,16 @@ export interface PreparationSession {
231
240
  p: SandboxPreparation;
232
241
  }
233
242
  /**
234
- * Full access refused by policy (B-13: `org.*` / `deployment.*`): the organization or the
235
- * platform has it off. The kernel's own message is never shown.
243
+ * Running outside the sandbox refused by policy (B-13): the organization
244
+ * (`org.outside_sandbox_not_allowed`) or the platform (`deployment.*`) has its outside-sandbox
245
+ * setting off. One text per layer; the kernel's own message is never shown.
236
246
  */
237
- export declare const FULL_ACCESS_OFF_BY_POLICY_TOOL_TEXT = "Full access is turned off by your organization's or the platform's policy, so nothing ran. Continue with the Request approval or Approve for me permission profile, or ask an org admin (or a super admin) to allow Full access.";
247
+ export declare const ORG_OUTSIDE_SANDBOX_OFF_TOOL_TEXT = "Running commands outside the sandbox is off in this organization, so nothing ran. Run the command inside the sandbox, or ask an organization admin to allow running outside the sandbox.";
248
+ export declare const PLATFORM_OUTSIDE_SANDBOX_OFF_TOOL_TEXT = "Running commands outside the sandbox is off on this platform, so nothing ran. Run the command inside the sandbox, or ask a super admin to allow running outside the sandbox.";
238
249
  /**
239
- * The device's owner ceiling does not allow Full access (`device.full_access_not_allowed`).
250
+ * The device does not allow running outside the sandbox (`device.outside_sandbox_not_allowed`).
240
251
  */
241
- export declare const FULL_ACCESS_CEILING_TOOL_TEXT = "This device's owner ceiling does not allow Full access, so nothing ran. Ask the device's owner to raise it with `capybara-device ceiling set` on that machine, or continue with the Request approval or Approve for me permission profile.";
252
+ export declare const OUTSIDE_SANDBOX_CEILING_TOOL_TEXT = "This device does not allow running commands outside the sandbox, so nothing ran. Run the command inside the sandbox, or ask the device's owner to allow it on that machine with `capybara-device ceiling set --outside-sandbox on`.";
242
253
  /**
243
254
  * The legacy retirement gate's refusals (`RetirementPendingError`, permission runtime cutover
244
255
  * 8.5): the device's earlier instance may still run background work an earlier version started.
@@ -254,11 +265,19 @@ export declare const RETIREMENT_REPLACE_TOOL_TEXT = "Background work started by
254
265
  */
255
266
  export declare const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside what this conversation's permission profile allows on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory or choose a broader permission profile, then retry.";
256
267
  /** An approved sandbox escalation whose grant no longer matches at admission (nothing ran). */
257
- export declare const ESCALATION_GRANT_MISSING_TEXT = "This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its Full access ceiling or this conversation's permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: \"escalated\" and a justification to ask again, or call it without sandbox to run it inside the sandbox.";
268
+ export declare const ESCALATION_GRANT_MISSING_TEXT = "This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation's permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: \"escalated\" and a justification to ask again, or call it without sandbox to run it inside the sandbox.";
269
+ /** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
270
+ export declare const ESCALATION_GRANT_MISSING_LAUNCH_WHY = "its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: \"escalated\" and a justification to ask again";
258
271
  /** A staged request the machine never got: it reconnected before the request was sent. */
259
272
  export declare const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
260
273
  /** The device cannot enforce the conversation's profile (`SandboxPermissionUnsupportedError`). */
261
274
  export declare const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device cannot enforce this conversation's permission profile, so nothing ran. Ask the user to choose another permission profile for the conversation, or to start a new conversation on a device that supports it.";
275
+ /**
276
+ * A device refused an operation scope as invalid (`SandboxScopeValidationError`): the kernel only
277
+ * sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
278
+ * model's doing; whether anything ran is not proven.
279
+ */
280
+ export declare const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in Capybara itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
262
281
  /** A managed operation whose outcome could not be confirmed (`SandboxOperationOutcomeUnknownError`). */
263
282
  export declare const OUTCOME_UNKNOWN_TOOL_TEXT = "The device may or may not have run this operation: its outcome could not be confirmed. Check the device's state (for example with Read, Glob or TaskList) before retrying, and do not repeat an operation that must not run twice.";
264
283
  export { DEVICE_OF_ANOTHER_ACCOUNT_TEXT } from "./device-owner.js";
@@ -325,6 +344,12 @@ export declare function recordManagedDevicePaths(deps: {
325
344
  * person's project skill invocation) takes its working root from here too.
326
345
  */
327
346
  export declare function sessionWorkingRoot(working: WorkingFacts | null, mode: SandboxMode, workspace: string, reach?: "workspace" | "os-user"): string;
347
+ /**
348
+ * What bounds a session's file-tool paths ({@link SandboxSession.pathBound}): the admitted scope
349
+ * on the managed operation route, under every tier; on the legacy route, the fixed roots unless
350
+ * the device runs in auto mode.
351
+ */
352
+ export declare const sessionPathBound: (operations: boolean, mode: SandboxMode) => SandboxSession["pathBound"];
328
353
  /** The conversation whose device a call uses (the root conversation's for a sub-agent). */
329
354
  export declare const sandboxConversationOf: (ctx: BuiltinCallContext) => string;
330
355
  /**
@@ -1,4 +1,4 @@
1
- import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
1
+ import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, isSandboxScopeValidationError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
2
2
  import { ANONYMOUS_NO_DEVICE, } from "../../../devices/conversation-devices.js";
3
3
  import { canonicalRoot, workingRootOf } from "../../../devices/working-root.js";
4
4
  import { ApiError } from "../../../errors.js";
@@ -142,12 +142,14 @@ export function checkPath(path, roots, field = "path") {
142
142
  return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
143
143
  }
144
144
  /**
145
- * A file tool's path in the mode the device runs at now (auto mode spec §4.1, decision 1): auto
146
- * mode accepts any clean absolute path on the machine (shape checks only, the review judges a write
147
- * outside the workspace); sandbox mode keeps the roots ({@link checkPath}).
145
+ * A file tool's path under the session's {@link SandboxSession.pathBound}: bounded by the
146
+ * operation's admitted scope, any clean absolute path passes here (shape checks only; the review
147
+ * proposes a directory crossing for a path outside the scope, and the device refuses one the
148
+ * scope does not cover, protected paths included); bounded by the fixed roots, a path must lie
149
+ * under one of them ({@link checkPath}).
148
150
  */
149
151
  export function checkToolPath(path, s, field = "path") {
150
- if (s.mode !== "auto")
152
+ if (s.pathBound === "roots")
151
153
  return checkPath(path, s.roots, field);
152
154
  checkPathShape(path, field);
153
155
  return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
@@ -185,11 +187,11 @@ export function resolveToolPath(path, s) {
185
187
  return s.workingRoot;
186
188
  return `${s.workingRoot === "/" ? "" : s.workingRoot}/${segments.join("/")}`;
187
189
  }
188
- /** {@link checkToolPath} for a writing tool: the skills directory stays read-only in both modes. */
190
+ /** {@link checkToolPath} for a writing tool: the skills directory stays read-only either way. */
189
191
  export function checkToolWritable(path, s) {
190
192
  const p = checkToolPath(resolveToolPath(path, s), s, "file_path");
191
193
  if (p === s.roots.skills || p.startsWith(`${s.roots.skills}/`)) {
192
- const where = s.mode === "auto"
194
+ const where = s.pathBound === "scope"
193
195
  ? "pass another path instead"
194
196
  : `pass a path under ${s.roots.workspace} or ${s.roots.tmp} instead`;
195
197
  throw new ToolError(`Path ${clip(p, 200)} is read-only (${s.roots.skills} holds skill files); ${where}.`);
@@ -269,19 +271,16 @@ function legacyPreparationSession(s) {
269
271
  };
270
272
  }
271
273
  /**
272
- * Full access refused by policy (B-13: `org.*` / `deployment.*`): the organization or the
273
- * platform has it off. The kernel's own message is never shown.
274
+ * Running outside the sandbox refused by policy (B-13): the organization
275
+ * (`org.outside_sandbox_not_allowed`) or the platform (`deployment.*`) has its outside-sandbox
276
+ * setting off. One text per layer; the kernel's own message is never shown.
274
277
  */
275
- export const FULL_ACCESS_OFF_BY_POLICY_TOOL_TEXT = "Full access is turned off by your organization's or the platform's policy, so nothing ran. Continue with the Request approval or Approve for me permission profile, or ask an org admin (or a super admin) to allow Full access.";
278
+ export const ORG_OUTSIDE_SANDBOX_OFF_TOOL_TEXT = "Running commands outside the sandbox is off in this organization, so nothing ran. Run the command inside the sandbox, or ask an organization admin to allow running outside the sandbox.";
279
+ export const PLATFORM_OUTSIDE_SANDBOX_OFF_TOOL_TEXT = "Running commands outside the sandbox is off on this platform, so nothing ran. Run the command inside the sandbox, or ask a super admin to allow running outside the sandbox.";
276
280
  /**
277
- * The device's owner ceiling does not allow Full access (`device.full_access_not_allowed`).
281
+ * The device does not allow running outside the sandbox (`device.outside_sandbox_not_allowed`).
278
282
  */
279
- export const FULL_ACCESS_CEILING_TOOL_TEXT = "This device's owner ceiling does not allow Full access, so nothing ran. Ask the device's owner to raise it with `capybara-device ceiling set` on that machine, or continue with the Request approval or Approve for me permission profile.";
280
- /** The full-access refusal codes off by policy (organization and platform). */
281
- const FULL_ACCESS_OFF_BY_POLICY_CODES = new Set([
282
- "org.full_access_not_allowed",
283
- "deployment.full_access_not_allowed",
284
- ]);
283
+ export const OUTSIDE_SANDBOX_CEILING_TOOL_TEXT = "This device does not allow running commands outside the sandbox, so nothing ran. Run the command inside the sandbox, or ask the device's owner to allow it on that machine with `capybara-device ceiling set --outside-sandbox on`.";
285
284
  /**
286
285
  * The legacy retirement gate's refusals (`RetirementPendingError`, permission runtime cutover
287
286
  * 8.5): the device's earlier instance may still run background work an earlier version started.
@@ -307,11 +306,19 @@ function retirementToolText(code) {
307
306
  */
308
307
  export const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside what this conversation's permission profile allows on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory or choose a broader permission profile, then retry.";
309
308
  /** An approved sandbox escalation whose grant no longer matches at admission (nothing ran). */
310
- export const ESCALATION_GRANT_MISSING_TEXT = 'This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its Full access ceiling or this conversation\'s permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: "escalated" and a justification to ask again, or call it without sandbox to run it inside the sandbox.';
309
+ export const ESCALATION_GRANT_MISSING_TEXT = 'This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation\'s permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: "escalated" and a justification to ask again, or call it without sandbox to run it inside the sandbox.';
310
+ /** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
311
+ export const ESCALATION_GRANT_MISSING_LAUNCH_WHY = 'its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: "escalated" and a justification to ask again';
311
312
  /** A staged request the machine never got: it reconnected before the request was sent. */
312
313
  export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
313
314
  /** The device cannot enforce the conversation's profile (`SandboxPermissionUnsupportedError`). */
314
315
  export const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device cannot enforce this conversation's permission profile, so nothing ran. Ask the user to choose another permission profile for the conversation, or to start a new conversation on a device that supports it.";
316
+ /**
317
+ * A device refused an operation scope as invalid (`SandboxScopeValidationError`): the kernel only
318
+ * sends scopes it validated, so this is a kernel invariant break (or a skewed device), never the
319
+ * model's doing; whether anything ran is not proven.
320
+ */
321
+ export const SCOPE_INVALID_TOOL_TEXT = "The device refused this operation as malformed, which points to a problem in Capybara itself, not in the request. Tell the user the device rejected the operation and that it should be reported; do not retry it unchanged.";
315
322
  /** A managed operation whose outcome could not be confirmed (`SandboxOperationOutcomeUnknownError`). */
316
323
  export const OUTCOME_UNKNOWN_TOOL_TEXT = "The device may or may not have run this operation: its outcome could not be confirmed. Check the device's state (for example with Read, Glob or TaskList) before retrying, and do not repeat an operation that must not run twice.";
317
324
  /**
@@ -360,6 +367,12 @@ export function mapSandboxError(e, log) {
360
367
  log?.warn("sandbox escalation grant no longer matches", { err: e });
361
368
  return new ToolError(ESCALATION_GRANT_MISSING_TEXT);
362
369
  }
370
+ if (isSandboxScopeValidationError(e)) {
371
+ log?.warn("kernel invariant broken: the device refused an operation scope as invalid", {
372
+ err: e,
373
+ });
374
+ return new ToolError(SCOPE_INVALID_TOOL_TEXT);
375
+ }
363
376
  if (isSandboxScopeDeniedError(e)) {
364
377
  log?.warn("sandbox operation outside its scope", { err: e });
365
378
  return new ToolError(SCOPE_DENIED_TOOL_TEXT);
@@ -406,10 +419,12 @@ export function mapSandboxError(e, log) {
406
419
  return new ToolError(DEVICE_OFFLINE_TEXT);
407
420
  if (e.code === "device.program_outdated")
408
421
  return new ToolError(DEVICE_OUTDATED_TEXT);
409
- if (e.code === "device.full_access_not_allowed")
410
- return new ToolError(FULL_ACCESS_CEILING_TOOL_TEXT);
411
- if (FULL_ACCESS_OFF_BY_POLICY_CODES.has(e.code))
412
- return new ToolError(FULL_ACCESS_OFF_BY_POLICY_TOOL_TEXT);
422
+ if (e.code === "device.outside_sandbox_not_allowed")
423
+ return new ToolError(OUTSIDE_SANDBOX_CEILING_TOOL_TEXT);
424
+ if (e.code === "org.outside_sandbox_not_allowed")
425
+ return new ToolError(ORG_OUTSIDE_SANDBOX_OFF_TOOL_TEXT);
426
+ if (e.code === "deployment.outside_sandbox_not_allowed")
427
+ return new ToolError(PLATFORM_OUTSIDE_SANDBOX_OFF_TOOL_TEXT);
413
428
  if (e.code === "device.permission_reconcile_required") {
414
429
  return new ToolError(RECONCILE_REQUIRED_TEXT, { kind: "unavailable" });
415
430
  }
@@ -549,11 +564,13 @@ async function inSandboxWith(deps, ctx, fn, operations, stage) {
549
564
  ...(ctx.runId !== undefined && { runId: ctx.runId }),
550
565
  },
551
566
  }, async (h, p, info, signal) => {
552
- // unknown mode: the strict (sandbox) path checks stay (fail closed)
567
+ // unknown mode: the strict (sandbox) working root rule stays (fail closed)
553
568
  const mode = level?.mode ?? "sandbox";
554
569
  const s = {
555
570
  deviceId,
556
- mode,
571
+ // the managed route: the admitted scope of each operation bounds the paths, whatever
572
+ // the device's tier (its outside-sandbox setting decides only escalations)
573
+ pathBound: sessionPathBound(operations, mode),
557
574
  h,
558
575
  roots: info.roots,
559
576
  // a managed call runs in the working root its device context recorded (admission's),
@@ -635,6 +652,12 @@ export function sessionWorkingRoot(working, mode, workspace, reach) {
635
652
  const root = workingRootOf(working.project, { mode, reach, ...working });
636
653
  return root === working.workspace ? workspace : root;
637
654
  }
655
+ /**
656
+ * What bounds a session's file-tool paths ({@link SandboxSession.pathBound}): the admitted scope
657
+ * on the managed operation route, under every tier; on the legacy route, the fixed roots unless
658
+ * the device runs in auto mode.
659
+ */
660
+ export const sessionPathBound = (operations, mode) => (operations || mode === "auto" ? "scope" : "roots");
638
661
  /** The conversation whose device a call uses (the root conversation's for a sub-agent). */
639
662
  export const sandboxConversationOf = (ctx) => ctx.sandboxConversationId ?? ctx.conversationId;
640
663
  /**
@@ -1,7 +1,7 @@
1
1
  import { MEDIA_NAME_MAX_CHARS, ToolError } from "@capybara-hq/plugin-sdk";
2
2
  import { isValidArtifactName } from "../../../conversations/events.js";
3
3
  import { NO_STORAGE, NO_STORAGE_REASON, REPEAT_TEXT, storeArtifacts, } from "../artifacts.js";
4
- import { checkPath, checkPathShape, clip, display, inToolSandbox, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, withNotices, } from "./common.js";
4
+ import { checkPathShape, checkToolPath, clip, display, inToolSandbox, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, withNotices, } from "./common.js";
5
5
  const SPEC = {
6
6
  name: "Deliver",
7
7
  // Display only (the tool row; not in the fingerprint, never sent to the model).
@@ -109,8 +109,11 @@ export function sandboxDeliverTool(deps) {
109
109
  const max = deps.config.get().sandbox.deliverMaxBytes;
110
110
  checkPathShape(input.file_path, "file_path");
111
111
  let path = "";
112
- const { value: data, notices } = await inToolSandbox(deps, ctx, async ({ h, roots, p, signal }) => {
113
- path = checkPath(input.file_path, roots, "file_path");
112
+ const { value: data, notices } = await inToolSandbox(deps, ctx, async (s) => {
113
+ const { h, p, signal } = s;
114
+ // bounded as the other file tools are: the admitted scope (a project file outside the
115
+ // workspace too), the fixed roots only on the legacy route in sandbox mode
116
+ path = checkToolPath(input.file_path, s, "file_path");
114
117
  const st = await p.stat(h, path, signal);
115
118
  if (st === null)
116
119
  throw new ToolError(notFound(path));
@@ -121,7 +124,7 @@ export function sandboxDeliverTool(deps) {
121
124
  const got = await p.readFile(h, path, { maxBytes: max, signal });
122
125
  if (got === null)
123
126
  throw new ToolError(notFound(path));
124
- // 读的过程中文件变大了
127
+ // the file grew while it was read
125
128
  if (got.truncated)
126
129
  throw new ToolError(tooLarge(path, max + 1, max));
127
130
  return got.data;
@@ -97,8 +97,8 @@ export interface ProjectSkillFile {
97
97
  truncated: boolean;
98
98
  }
99
99
  /**
100
- * Reads `<root>/.agents/skills/<name>/SKILL.md` in `s` (the device's mode now, as `Read` checks a
101
- * path: a mode narrowed since the run start reads nothing) and parses it; its name must be its
100
+ * Reads `<root>/.agents/skills/<name>/SKILL.md` in `s` (its path checked as `Read` checks one,
101
+ * {@link checkToolPath}) and parses it; its name must be its
102
102
  * directory's. Shared by `Skill` and a person's invocation (`SkillInvoker`), so both read a
103
103
  * project skill the same way. A problem with the file or its path throws
104
104
  * {@link ProjectSkillReadError}; the sandbox's own failures (offline, lost files, ...) and an abort
@@ -405,8 +405,8 @@ export class ProjectSkillReadError extends Error {
405
405
  }
406
406
  }
407
407
  /**
408
- * Reads `<root>/.agents/skills/<name>/SKILL.md` in `s` (the device's mode now, as `Read` checks a
409
- * path: a mode narrowed since the run start reads nothing) and parses it; its name must be its
408
+ * Reads `<root>/.agents/skills/<name>/SKILL.md` in `s` (its path checked as `Read` checks one,
409
+ * {@link checkToolPath}) and parses it; its name must be its
410
410
  * directory's. Shared by `Skill` and a person's invocation (`SkillInvoker`), so both read a
411
411
  * project skill the same way. A problem with the file or its path throws
412
412
  * {@link ProjectSkillReadError}; the sandbox's own failures (offline, lost files, ...) and an abort
@@ -421,7 +421,8 @@ export async function readProjectSkill(s, root, bare, signal = s.signal) {
421
421
  catch (e) {
422
422
  if (!(e instanceof ToolError))
423
423
  throw e;
424
- throw new ProjectSkillReadError({ kind: "outside_mode", path, mode: s.mode });
424
+ // only the fixed roots refuse a path, and they bound paths only in sandbox mode (legacy route)
425
+ throw new ProjectSkillReadError({ kind: "outside_mode", path, mode: "sandbox" });
425
426
  }
426
427
  let read;
427
428
  try {
@@ -2,7 +2,6 @@ import { KernelDb } from "../infra/database/kernel-db.js";
2
2
  import { TransactionHost } from "../infra/database/transaction-host.js";
3
3
  import { DevicePolicyService } from "../local-devices/device-policy.service.js";
4
4
  import type { DeviceOpResolveData } from "../local-devices/policy-op-jobs.js";
5
- import { ApprovalsService } from "./approvals.service.js";
6
5
  /**
7
6
  * The `device-op-resolve` job (transactional outbox spec §7): records what became of a device
8
7
  * policy op whose outcome its caller did not record (a crash between the call and the resolve
@@ -16,25 +15,20 @@ import { ApprovalsService } from "./approvals.service.js";
16
15
  * its log and its answer), once the op can no longer reach it → applied when the policy it
17
16
  * reports holds the change, else failed (`interrupted`); no answer (`offline`) → `unknown`, left
18
17
  * for the machine's next hello. It never sends the change
19
- * again (a widening after its ask closed is not allowed). An op that answers a network ask
20
- * decides it when applied and the ask is still pending, else leaves it pending with the reason
21
- * (`ApprovalsService.settleFromResolver`).
18
+ * again. No op answers a network ask any more: the deployment never adds a host to a local device
19
+ * (device protocol 4), so a network ask is only ever a run grant and an op only records its outcome.
22
20
  */
23
21
  export declare class DeviceOpResolver {
24
22
  private readonly db;
25
23
  readonly txHost: TransactionHost;
26
24
  private readonly policies;
27
- private readonly approvals;
28
- constructor(db: KernelDb, txHost: TransactionHost, policies: Pick<DevicePolicyService, "outcomeOf" | "settleIn" | "lockMachineDevice">, approvals: Pick<ApprovalsService, "settleFromResolver">);
25
+ constructor(db: KernelDb, txHost: TransactionHost, policies: Pick<DevicePolicyService, "outcomeOf" | "settleIn" | "lockMachineDevice">);
29
26
  resolve(data: DeviceOpResolveData): Promise<void>;
30
27
  /**
31
28
  * The outcome a hello reported; a refusal's message (a hello carries none) is the machine's
32
29
  * answer to `policyStatus` when it is connected.
33
30
  */
34
31
  private reportedResult;
35
- /**
36
- * The resolve transaction: the op's outcome, and the network ask it answers decided or given
37
- * the reason in the same transaction (`ApprovalsService.settleFromResolver`).
38
- */
32
+ /** The resolve transaction: the op's outcome. */
39
33
  private settle;
40
34
  }
@@ -13,7 +13,6 @@ import { TransactionHost, withOrderedLocks } from "../infra/database/transaction
13
13
  import { Transactional } from "../infra/database/transactional.decorator.js";
14
14
  import { DevicePolicyService, } from "../local-devices/device-policy.service.js";
15
15
  import { opVisibleIn, pendingPolicyOpsOf, } from "../local-devices/policy-summary.js";
16
- import { ApprovalsService } from "./approvals.service.js";
17
16
  /**
18
17
  * The `device-op-resolve` job (transactional outbox spec §7): records what became of a device
19
18
  * policy op whose outcome its caller did not record (a crash between the call and the resolve
@@ -27,20 +26,17 @@ import { ApprovalsService } from "./approvals.service.js";
27
26
  * its log and its answer), once the op can no longer reach it → applied when the policy it
28
27
  * reports holds the change, else failed (`interrupted`); no answer (`offline`) → `unknown`, left
29
28
  * for the machine's next hello. It never sends the change
30
- * again (a widening after its ask closed is not allowed). An op that answers a network ask
31
- * decides it when applied and the ask is still pending, else leaves it pending with the reason
32
- * (`ApprovalsService.settleFromResolver`).
29
+ * again. No op answers a network ask any more: the deployment never adds a host to a local device
30
+ * (device protocol 4), so a network ask is only ever a run grant and an op only records its outcome.
33
31
  */
34
32
  let DeviceOpResolver = class DeviceOpResolver {
35
33
  db;
36
34
  txHost;
37
35
  policies;
38
- approvals;
39
- constructor(db, txHost, policies, approvals) {
36
+ constructor(db, txHost, policies) {
40
37
  this.db = db;
41
38
  this.txHost = txHost;
42
39
  this.policies = policies;
43
- this.approvals = approvals;
44
40
  }
45
41
  async resolve(data) {
46
42
  const row = await this.db
@@ -56,7 +52,7 @@ let DeviceOpResolver = class DeviceOpResolver {
56
52
  : statusResult(op, await this.policies.outcomeOf(row.device_id, op.id));
57
53
  // the machine's device lock is the ordered prelude: the settle locks the ask's conversation,
58
54
  // approval and run after it (the global order: permission locks before conversation rows)
59
- await withOrderedLocks(() => this.policies.lockMachineDevice(data.machineId), () => this.settle(data, op.source.approvalId, result));
55
+ await withOrderedLocks(() => this.policies.lockMachineDevice(data.machineId), () => this.settle(data, result));
60
56
  }
61
57
  /**
62
58
  * The outcome a hello reported; a refusal's message (a hello carries none) is the machine's
@@ -73,15 +69,9 @@ let DeviceOpResolver = class DeviceOpResolver {
73
69
  const message = s.outcome === "refused" ? s.message : undefined;
74
70
  return { outcome: "refused", message: (message ?? REFUSED_MESSAGE).slice(0, MAX_MESSAGE) };
75
71
  }
76
- /**
77
- * The resolve transaction: the op's outcome, and the network ask it answers decided or given
78
- * the reason in the same transaction (`ApprovalsService.settleFromResolver`).
79
- */
80
- async settle(data, approvalId, result) {
81
- if (approvalId === null)
82
- await this.policies.settleIn(data, result);
83
- else
84
- await this.approvals.settleFromResolver({ ...data, approvalId }, result);
72
+ /** The resolve transaction: the op's outcome. */
73
+ async settle(data, result) {
74
+ await this.policies.settleIn(data, result);
85
75
  }
86
76
  };
87
77
  __decorate([
@@ -91,8 +81,7 @@ DeviceOpResolver = __decorate([
91
81
  Injectable(),
92
82
  __param(0, Inject(KernelDb)),
93
83
  __param(1, Inject(TransactionHost)),
94
- __param(2, Inject(DevicePolicyService)),
95
- __param(3, Inject(ApprovalsService))
84
+ __param(2, Inject(DevicePolicyService))
96
85
  ], DeviceOpResolver);
97
86
  export { DeviceOpResolver };
98
87
  const REFUSED_MESSAGE = "The device's machine refused the policy change.";