@capybara-hq/kernel 0.1.0-rc.40 → 0.1.0-rc.42

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 (326) hide show
  1. package/bootstrap.json +10 -1
  2. package/dist/admin/admin.schemas.d.ts +6 -0
  3. package/dist/admin/org-network.service.d.ts +3 -1
  4. package/dist/admin/org-network.service.js +10 -2
  5. package/dist/app.d.ts +4 -0
  6. package/dist/app.js +2 -0
  7. package/dist/background/finish.d.ts +9 -1
  8. package/dist/background/finish.js +57 -4
  9. package/dist/background/launch.d.ts +23 -0
  10. package/dist/background/launch.js +55 -1
  11. package/dist/background/managed-output.d.ts +110 -0
  12. package/dist/background/managed-output.js +219 -0
  13. package/dist/background/managed.d.ts +52 -0
  14. package/dist/background/managed.js +128 -0
  15. package/dist/background/poll.job.d.ts +35 -1
  16. package/dist/background/poll.job.js +174 -9
  17. package/dist/background/render.js +1 -0
  18. package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
  19. package/dist/background/retire-legacy-tasks.job.js +149 -0
  20. package/dist/background/session.d.ts +15 -5
  21. package/dist/background/session.js +22 -6
  22. package/dist/background/stop.d.ts +35 -5
  23. package/dist/background/stop.js +94 -8
  24. package/dist/background/store.d.ts +110 -3
  25. package/dist/background/store.js +205 -3
  26. package/dist/background/tasks.service.d.ts +18 -1
  27. package/dist/background/tasks.service.js +99 -9
  28. package/dist/catalog/marketplaces.service.d.ts +1 -1
  29. package/dist/channels/cards.js +1 -1
  30. package/dist/channels/inbound.js +2 -0
  31. package/dist/channels/phrases.d.ts +4 -0
  32. package/dist/channels/phrases.js +4 -0
  33. package/dist/config/load.d.ts +18 -0
  34. package/dist/config/load.js +39 -1
  35. package/dist/config/permission-migration.d.ts +26 -0
  36. package/dist/config/permission-migration.js +64 -0
  37. package/dist/config/schema.d.ts +1 -1
  38. package/dist/config/schema.js +11 -10
  39. package/dist/conversations/conversations.controller.d.ts +1 -1
  40. package/dist/conversations/conversations.controller.js +1 -1
  41. package/dist/conversations/conversations.module.js +12 -0
  42. package/dist/conversations/conversations.service.d.ts +11 -2
  43. package/dist/conversations/conversations.service.js +97 -27
  44. package/dist/conversations/event-log.d.ts +1 -1
  45. package/dist/conversations/event-log.js +10 -2
  46. package/dist/conversations/events.d.ts +304 -4
  47. package/dist/conversations/events.js +279 -29
  48. package/dist/conversations/permission-profile-store.d.ts +50 -0
  49. package/dist/conversations/permission-profile-store.js +67 -0
  50. package/dist/conversations/permission-profile-store.module.d.ts +2 -0
  51. package/dist/conversations/permission-profile-store.module.js +19 -0
  52. package/dist/conversations/permission-profiles.controller.d.ts +84 -0
  53. package/dist/conversations/permission-profiles.controller.js +105 -0
  54. package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
  55. package/dist/conversations/permission-profiles.schemas.js +23 -0
  56. package/dist/conversations/permission-profiles.service.d.ts +56 -0
  57. package/dist/conversations/permission-profiles.service.js +179 -0
  58. package/dist/db/kernel-schema.d.ts +238 -3
  59. package/dist/devices/access.js +1 -1
  60. package/dist/devices/access.module.d.ts +2 -0
  61. package/dist/devices/access.module.js +19 -0
  62. package/dist/devices/conversation-devices.d.ts +8 -29
  63. package/dist/devices/conversation-devices.js +37 -73
  64. package/dist/devices/device-projects.service.d.ts +26 -28
  65. package/dist/devices/device-projects.service.js +123 -127
  66. package/dist/devices/devices.controller.js +3 -1
  67. package/dist/devices/devices.module.js +11 -9
  68. package/dist/devices/devices.service.d.ts +116 -8
  69. package/dist/devices/devices.service.js +252 -20
  70. package/dist/devices/dto.d.ts +16 -0
  71. package/dist/devices/dto.js +34 -6
  72. package/dist/devices/errors.d.ts +8 -0
  73. package/dist/devices/errors.js +10 -0
  74. package/dist/devices/project-rules.d.ts +44 -0
  75. package/dist/devices/project-rules.js +27 -0
  76. package/dist/devices/working-root.d.ts +6 -0
  77. package/dist/devices/working-root.js +12 -1
  78. package/dist/errors.d.ts +31 -0
  79. package/dist/errors.js +31 -0
  80. package/dist/evals/reconstruct.d.ts +19 -2
  81. package/dist/evals/reconstruct.js +40 -2
  82. package/dist/evals/recorded-permission-context.d.ts +77 -0
  83. package/dist/evals/recorded-permission-context.js +151 -0
  84. package/dist/evals/recorded-tools.d.ts +10 -1
  85. package/dist/evals/recorded-tools.js +27 -3
  86. package/dist/evals/run-replay.d.ts +8 -2
  87. package/dist/evals/run-replay.js +18 -2
  88. package/dist/evals/trajectory.d.ts +1 -1
  89. package/dist/evals/worker.d.ts +10 -1
  90. package/dist/evals/worker.js +23 -14
  91. package/dist/http/api.module.js +2 -0
  92. package/dist/identity/accounts.d.ts +14 -1
  93. package/dist/identity/accounts.js +61 -5
  94. package/dist/identity/identity.module.js +2 -0
  95. package/dist/identity/settings.d.ts +28 -12
  96. package/dist/identity/settings.js +89 -33
  97. package/dist/index.d.ts +6 -0
  98. package/dist/index.js +5 -0
  99. package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
  100. package/dist/infra/cli/kernel-cli.module.js +5 -2
  101. package/dist/infra/cli/permission-cutover.d.ts +59 -0
  102. package/dist/infra/cli/permission-cutover.js +107 -0
  103. package/dist/infra/config/kernel-config.service.d.ts +2 -2
  104. package/dist/infra/config/kernel-config.service.js +31 -11
  105. package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
  106. package/dist/infra/database/startup-activation-transaction.js +242 -0
  107. package/dist/infra/database/transaction-host.d.ts +47 -0
  108. package/dist/infra/database/transaction-host.js +119 -0
  109. package/dist/infra/database/xact-lock.d.ts +1 -0
  110. package/dist/infra/database/xact-lock.js +6 -0
  111. package/dist/infra/outbox/registry.d.ts +39 -0
  112. package/dist/infra/outbox/registry.js +18 -0
  113. package/dist/kernel.module.js +2 -0
  114. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  115. package/dist/lifecycle/kernel-lifecycle.js +55 -28
  116. package/dist/local-devices/device-auth.js +1 -1
  117. package/dist/local-devices/device-policy.service.d.ts +35 -5
  118. package/dist/local-devices/device-policy.service.js +188 -13
  119. package/dist/local-devices/instance-bindings.d.ts +82 -0
  120. package/dist/local-devices/instance-bindings.js +304 -0
  121. package/dist/local-devices/keys.d.ts +5 -0
  122. package/dist/local-devices/keys.js +5 -0
  123. package/dist/local-devices/local-device-gateway.d.ts +19 -4
  124. package/dist/local-devices/local-device-gateway.js +185 -17
  125. package/dist/local-devices/local-device-provider.d.ts +42 -7
  126. package/dist/local-devices/local-device-provider.js +185 -10
  127. package/dist/local-devices/local-devices.module.d.ts +17 -2
  128. package/dist/local-devices/local-devices.module.js +49 -8
  129. package/dist/local-devices/machines.d.ts +35 -12
  130. package/dist/local-devices/machines.js +203 -8
  131. package/dist/local-devices/network-grants.js +3 -3
  132. package/dist/local-devices/network-grants.module.d.ts +2 -0
  133. package/dist/local-devices/network-grants.module.js +14 -0
  134. package/dist/local-devices/owner-report.d.ts +79 -0
  135. package/dist/local-devices/owner-report.js +155 -0
  136. package/dist/local-devices/owner-reports.d.ts +48 -0
  137. package/dist/local-devices/owner-reports.js +190 -0
  138. package/dist/local-devices/policy-summary.d.ts +24 -1
  139. package/dist/local-devices/policy-summary.js +48 -0
  140. package/dist/local-devices/relay.d.ts +82 -6
  141. package/dist/local-devices/relay.js +187 -16
  142. package/dist/local-devices/targets.d.ts +16 -1
  143. package/dist/local-devices/targets.js +35 -2
  144. package/dist/orgs/cloud-network-setting.d.ts +33 -0
  145. package/dist/orgs/cloud-network-setting.js +47 -0
  146. package/dist/orgs/offboarding.d.ts +3 -1
  147. package/dist/orgs/offboarding.js +8 -2
  148. package/dist/orgs/org-lock.d.ts +10 -4
  149. package/dist/orgs/org-lock.js +10 -4
  150. package/dist/orgs/orgs.service.d.ts +3 -1
  151. package/dist/orgs/orgs.service.js +8 -2
  152. package/dist/orgs/settings.controller.d.ts +4 -1
  153. package/dist/orgs/settings.controller.js +3 -3
  154. package/dist/orgs/settings.service.d.ts +48 -56
  155. package/dist/orgs/settings.service.js +144 -101
  156. package/dist/overrides.d.ts +6 -1
  157. package/dist/overrides.js +2 -0
  158. package/dist/platform/exclusions.js +20 -0
  159. package/dist/platform/ops/admin.ops.js +14 -11
  160. package/dist/platform/ops/agent-skills.ops.js +2 -0
  161. package/dist/platform/ops/devices.ops.js +10 -2
  162. package/dist/platform/ops/org-settings.ops.js +6 -6
  163. package/dist/platform/ops/orgs.ops.js +1 -0
  164. package/dist/roles/worker.module.js +4 -0
  165. package/dist/runtime/context/build.d.ts +3 -1
  166. package/dist/runtime/context/build.js +19 -3
  167. package/dist/runtime/context/compaction.js +5 -0
  168. package/dist/runtime/context/device-paths.d.ts +9 -2
  169. package/dist/runtime/context/device-paths.js +20 -0
  170. package/dist/runtime/context/permission-profile.d.ts +46 -0
  171. package/dist/runtime/context/permission-profile.js +194 -0
  172. package/dist/runtime/maintenance.d.ts +7 -1
  173. package/dist/runtime/maintenance.js +43 -15
  174. package/dist/runtime/model-call.d.ts +32 -0
  175. package/dist/runtime/model-call.js +67 -0
  176. package/dist/runtime/permission-context-errors.d.ts +39 -0
  177. package/dist/runtime/permission-context-errors.js +67 -0
  178. package/dist/runtime/permission-context.service.d.ts +60 -0
  179. package/dist/runtime/permission-context.service.js +286 -0
  180. package/dist/runtime/project/knowledge.d.ts +7 -2
  181. package/dist/runtime/project/knowledge.js +5 -2
  182. package/dist/runtime/project/knowledge.service.d.ts +17 -2
  183. package/dist/runtime/project/knowledge.service.js +76 -12
  184. package/dist/runtime/run-execution.d.ts +4 -1
  185. package/dist/runtime/run-execution.js +14 -5
  186. package/dist/runtime/run-steps.d.ts +11 -3
  187. package/dist/runtime/run-steps.js +27 -4
  188. package/dist/runtime/runtime.module.js +11 -0
  189. package/dist/sandbox/attachments-path.d.ts +15 -0
  190. package/dist/sandbox/attachments-path.js +15 -0
  191. package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
  192. package/dist/sandbox/cloud-permission-snapshot.js +407 -0
  193. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
  194. package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
  195. package/dist/sandbox/held-operations.d.ts +39 -0
  196. package/dist/sandbox/held-operations.js +119 -0
  197. package/dist/sandbox/jobs.d.ts +14 -3
  198. package/dist/sandbox/jobs.js +20 -2
  199. package/dist/sandbox/kernel-read.d.ts +55 -0
  200. package/dist/sandbox/kernel-read.js +57 -0
  201. package/dist/sandbox/legacy-retirement.d.ts +336 -0
  202. package/dist/sandbox/legacy-retirement.js +1063 -0
  203. package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
  204. package/dist/sandbox/legacy-retirement.module.js +25 -0
  205. package/dist/sandbox/managed-device-context.d.ts +94 -0
  206. package/dist/sandbox/managed-device-context.js +308 -0
  207. package/dist/sandbox/managed-device-context.module.d.ts +6 -0
  208. package/dist/sandbox/managed-device-context.module.js +33 -0
  209. package/dist/sandbox/modes.d.ts +56 -8
  210. package/dist/sandbox/modes.js +92 -8
  211. package/dist/sandbox/operation-authority-types.d.ts +8 -0
  212. package/dist/sandbox/operation-authority-types.js +32 -0
  213. package/dist/sandbox/operation-authority.d.ts +145 -0
  214. package/dist/sandbox/operation-authority.js +783 -0
  215. package/dist/sandbox/operation-authority.module.d.ts +2 -0
  216. package/dist/sandbox/operation-authority.module.js +29 -0
  217. package/dist/sandbox/operation-intents.d.ts +206 -0
  218. package/dist/sandbox/operation-intents.js +1252 -0
  219. package/dist/sandbox/operation-intents.module.d.ts +2 -0
  220. package/dist/sandbox/operation-intents.module.js +21 -0
  221. package/dist/sandbox/operation-payloads.d.ts +33 -0
  222. package/dist/sandbox/operation-payloads.js +332 -0
  223. package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
  224. package/dist/sandbox/operation-reconcile.job.js +247 -0
  225. package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
  226. package/dist/sandbox/permission-authority-epochs.js +83 -0
  227. package/dist/sandbox/permission-authority-lock.d.ts +38 -0
  228. package/dist/sandbox/permission-authority-lock.js +147 -0
  229. package/dist/sandbox/permission-authority.module.d.ts +9 -0
  230. package/dist/sandbox/permission-authority.module.js +55 -0
  231. package/dist/sandbox/permission-availability.d.ts +18 -0
  232. package/dist/sandbox/permission-availability.js +19 -0
  233. package/dist/sandbox/permission-call-grants.d.ts +34 -0
  234. package/dist/sandbox/permission-call-grants.js +349 -0
  235. package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
  236. package/dist/sandbox/permission-call-grants.module.js +21 -0
  237. package/dist/sandbox/permission-call-types.d.ts +82 -0
  238. package/dist/sandbox/permission-call-types.js +1 -0
  239. package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
  240. package/dist/sandbox/permission-ceiling-writes.js +223 -0
  241. package/dist/sandbox/permission-config-publication.d.ts +76 -0
  242. package/dist/sandbox/permission-config-publication.js +339 -0
  243. package/dist/sandbox/permission-context-types.d.ts +64 -0
  244. package/dist/sandbox/permission-context-types.js +24 -0
  245. package/dist/sandbox/permission-facts.d.ts +206 -0
  246. package/dist/sandbox/permission-facts.js +627 -0
  247. package/dist/sandbox/permission-facts.module.d.ts +2 -0
  248. package/dist/sandbox/permission-facts.module.js +20 -0
  249. package/dist/sandbox/permission-instance-writes.d.ts +90 -0
  250. package/dist/sandbox/permission-instance-writes.js +305 -0
  251. package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
  252. package/dist/sandbox/permission-runtime-reports.js +354 -0
  253. package/dist/sandbox/permission-transitions.d.ts +31 -0
  254. package/dist/sandbox/permission-transitions.js +155 -0
  255. package/dist/sandbox/platform-full-access.d.ts +128 -0
  256. package/dist/sandbox/platform-full-access.js +210 -0
  257. package/dist/sandbox/providers.d.ts +22 -0
  258. package/dist/sandbox/providers.js +10 -2
  259. package/dist/sandbox/providers.module.d.ts +2 -0
  260. package/dist/sandbox/providers.module.js +19 -0
  261. package/dist/sandbox/request-not-sent.d.ts +13 -0
  262. package/dist/sandbox/request-not-sent.js +13 -0
  263. package/dist/sandbox/review/classifier.d.ts +2 -0
  264. package/dist/sandbox/review/classifier.js +8 -0
  265. package/dist/sandbox/review/permission-candidate.d.ts +12 -0
  266. package/dist/sandbox/review/permission-candidate.js +129 -0
  267. package/dist/sandbox/review/review.service.d.ts +4 -1
  268. package/dist/sandbox/review/review.service.js +19 -5
  269. package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
  270. package/dist/sandbox/sandbox-file-reader.js +51 -7
  271. package/dist/sandbox/sandbox.module.js +26 -6
  272. package/dist/sandbox/sandbox.service.d.ts +230 -34
  273. package/dist/sandbox/sandbox.service.js +1368 -199
  274. package/dist/sandbox/unreachable.js +17 -3
  275. package/dist/sandbox/use-context.d.ts +17 -0
  276. package/dist/sandbox/use-context.js +1 -0
  277. package/dist/skills/invoke.d.ts +27 -4
  278. package/dist/skills/invoke.js +72 -7
  279. package/dist/tools/approvals.controller.d.ts +1 -0
  280. package/dist/tools/approvals.schemas.d.ts +1 -0
  281. package/dist/tools/approvals.schemas.js +3 -1
  282. package/dist/tools/approvals.service.d.ts +23 -10
  283. package/dist/tools/approvals.service.js +104 -26
  284. package/dist/tools/builtins/builtin-tools.d.ts +16 -2
  285. package/dist/tools/builtins/builtin-tools.js +38 -10
  286. package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
  287. package/dist/tools/builtins/sandbox/bash.js +201 -5
  288. package/dist/tools/builtins/sandbox/common.d.ts +92 -20
  289. package/dist/tools/builtins/sandbox/common.js +201 -17
  290. package/dist/tools/builtins/sandbox/deliver.js +2 -2
  291. package/dist/tools/builtins/sandbox/edit.js +2 -2
  292. package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
  293. package/dist/tools/builtins/sandbox/glob.js +2 -2
  294. package/dist/tools/builtins/sandbox/grep.js +2 -2
  295. package/dist/tools/builtins/sandbox/read.js +2 -2
  296. package/dist/tools/builtins/sandbox/task-list.js +7 -1
  297. package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
  298. package/dist/tools/builtins/sandbox/task-output.js +172 -0
  299. package/dist/tools/builtins/sandbox/task-stop.js +25 -3
  300. package/dist/tools/builtins/sandbox/write.js +2 -2
  301. package/dist/tools/builtins/skill-load.js +9 -6
  302. package/dist/tools/device-op-resolver.d.ts +1 -1
  303. package/dist/tools/device-op-resolver.js +13 -3
  304. package/dist/tools/permission-approval-jobs.d.ts +18 -0
  305. package/dist/tools/permission-approval-jobs.js +92 -0
  306. package/dist/tools/pipeline.d.ts +17 -2
  307. package/dist/tools/pipeline.js +300 -19
  308. package/dist/tools/registry.d.ts +9 -0
  309. package/dist/tools/tools.module.js +12 -0
  310. package/package.json +4 -3
  311. package/src/migrations/0146_permission_authority_epochs.sql +6 -0
  312. package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
  313. package/src/migrations/0148_first_message_request_hash.sql +2 -0
  314. package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
  315. package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
  316. package/src/migrations/0151_starting_execution_grants.sql +8 -0
  317. package/src/migrations/0152_background_launch_identity.sql +66 -0
  318. package/src/migrations/0153_background_cancel_requester.sql +13 -0
  319. package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
  320. package/src/migrations/0155_device_instance_generations.sql +30 -0
  321. package/src/migrations/0156_device_owner_report.sql +7 -0
  322. package/src/migrations/0157_legacy_retirement.sql +116 -0
  323. package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
  324. package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
  325. package/dist/sandbox/platform-auto-mode.d.ts +0 -63
  326. package/dist/sandbox/platform-auto-mode.js +0 -63
@@ -1,10 +1,14 @@
1
- import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
1
+ import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, SandboxScopeDeniedError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
2
2
  import { ANONYMOUS_NO_DEVICE, } from "../../../devices/conversation-devices.js";
3
- import { workingRootOf } from "../../../devices/working-root.js";
3
+ import { canonicalRoot, workingRootOf } from "../../../devices/working-root.js";
4
4
  import { ApiError } from "../../../errors.js";
5
+ import { InstanceBindingError } from "../../../local-devices/instance-bindings.js";
5
6
  import { AUTO_MODE_NOT_ALLOWED_TEXT } from "../../../local-devices/local-device-provider.js";
7
+ import { isDeviceRequestNotSent } from "../../../local-devices/relay.js";
6
8
  import { devicePathsChange } from "../../../runtime/context/device-paths.js";
9
+ import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot, } from "../../../sandbox/attachments-path.js";
7
10
  import { SandboxPathBusyError } from "../../../sandbox/leases.js";
11
+ import { MANAGED_DEVICE_CONTEXT_FAILED_TEXT, MANAGED_DEVICE_CONTEXT_STALE_TEXT, MANAGED_DEVICE_CONTEXT_UNAVAILABLE_TEXT, ManagedDeviceContextFailed, ManagedDeviceContextStale, ManagedDeviceContextUnavailable, } from "../../../sandbox/managed-device-context.js";
8
12
  import { SandboxLockLostError, } from "../../../sandbox/sandbox.service.js";
9
13
  import { SandboxProviderUnreachableError } from "../../../sandbox/unreachable.js";
10
14
  // ---- 模型可见文案(英文) ----
@@ -61,15 +65,7 @@ export const SANDBOX_OPEN_NETWORK_REFUSED_TEXT = "The cloud sandbox provider ref
61
65
  /** A cloud provider failed to create the device's sandbox otherwise (`sandbox.create_failed`). */
62
66
  export const SANDBOX_CREATE_FAILED_TEXT = "The cloud sandbox provider could not create this device's sandbox, so nothing ran in it. Retry once; if it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's settings (Admin console → Extensions).";
63
67
  const LOCK_LOST_TEXT = "The sandbox operation was interrupted because the sandbox lock was lost; check the sandbox state and retry.";
64
- /** The directory of attachments in the device (each conversation has a subdirectory). */
65
- export const attachmentsRoot = (roots) => `${roots.workspace}/attachments`;
66
- /** {@link attachmentsRoot} of an instance with the default roots. */
67
- export const ATTACHMENTS_ROOT = attachmentsRoot(DEFAULT_SANDBOX_ROOTS);
68
- /**
69
- * One conversation's attachment directory: the first 12 hex digits of the root conversation's
70
- * UUID, so conversations sharing a device do not overwrite each other's files.
71
- */
72
- export const attachmentsDir = (roots, rootConversationId) => `${attachmentsRoot(roots)}/${rootConversationId.replaceAll("-", "").slice(0, 12)}`;
68
+ export { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot };
73
69
  /** 附件文件名的上限(UTF-8 字节,常见文件系统单个文件名上限 255 字节,留出 `-N` 后缀的余量)。 */
74
70
  export const ATTACHMENT_NAME_MAX_BYTES = 200;
75
71
  /**
@@ -258,11 +254,55 @@ export function assignAttachmentNames(items, used) {
258
254
  }
259
255
  return out;
260
256
  }
257
+ /** Temporary protocol-2 binding; removed with the active caller cutover in Task8. */
258
+ function legacyPreparationSession(s) {
259
+ return {
260
+ deviceId: s.deviceId,
261
+ roots: s.roots,
262
+ signal: s.signal,
263
+ p: {
264
+ readFile: (path, opts) => s.p.readFile(s.h, path, opts),
265
+ writeFile: (path, data, signal) => s.p.writeFile(s.h, path, data, signal),
266
+ stat: (path, signal) => s.p.stat(s.h, path, signal),
267
+ },
268
+ };
269
+ }
261
270
  /**
262
271
  * A machine that reports auto mode while the organization allows only sandbox mode (auto mode
263
272
  * spec §4.3): the kernel's refusal text plus what the model can do.
264
273
  */
265
274
  const AUTO_MODE_TOOL_TEXT = `${AUTO_MODE_NOT_ALLOWED_TEXT} Ask the user to switch it on the machine, or to start a new conversation on another device.`;
275
+ /**
276
+ * Full access refused by policy (B-13: `org.*` / `deployment.*`, old and renamed codes): the
277
+ * organization or the platform has it off. The kernel's own message is never shown.
278
+ */
279
+ 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.";
280
+ /**
281
+ * The device's owner ceiling does not allow Full access (`device.full_access_not_allowed`).
282
+ */
283
+ 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.";
284
+ /**
285
+ * The full-access refusal codes off by policy: the renamed ones (W5-P3b) and the old organization
286
+ * and platform names until that rename lands; `device.auto_mode_not_allowed` keeps its machine
287
+ * text ({@link AUTO_MODE_TOOL_TEXT}).
288
+ */
289
+ const FULL_ACCESS_OFF_BY_POLICY_CODES = new Set([
290
+ "org.full_access_not_allowed",
291
+ "deployment.full_access_not_allowed",
292
+ "org.auto_mode_not_allowed",
293
+ "deployment.auto_mode_not_allowed",
294
+ ]);
295
+ /**
296
+ * A managed operation outside the admitted scope (`SandboxScopeDeniedError`): fixed text, never
297
+ * the refusal's own message (a provider may write it).
298
+ */
299
+ 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.";
300
+ /** A staged request the machine never got: it reconnected before the request was sent. */
301
+ 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.";
302
+ /** The device cannot enforce the conversation's profile (`SandboxPermissionUnsupportedError`). */
303
+ 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.";
304
+ /** A managed operation whose outcome could not be confirmed (`SandboxOperationOutcomeUnknownError`). */
305
+ 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.";
266
306
  /**
267
307
  * Sandbox service errors → actionable text for the model; anything else is returned unchanged
268
308
  * (the pipeline reports a generic tool failure). A provider that cannot be reached becomes a
@@ -270,7 +310,31 @@ const AUTO_MODE_TOOL_TEXT = `${AUTO_MODE_NOT_ALLOWED_TEXT} Ask the user to switc
270
310
  * error is logged to `log` as a warning (the pipeline logs only errors it did not get as a
271
311
  * `ToolError`).
272
312
  */
313
+ const RECONCILE_REQUIRED_TEXT = "This device's sandbox limits must be established again before it runs anything, so nothing ran. Ask the person to reset the device's files on the devices page, then retry, or to start a new conversation on another device.";
314
+ const INSTANCE_BINDING_TEXT = "The device's machine has not confirmed its current instance, so nothing ran. Ask the person to restart capybara-device on that machine (updating it if it is outdated), then retry, or to start a new conversation on another device.";
273
315
  export function mapSandboxError(e, log) {
316
+ if (e instanceof ManagedDeviceContextStale)
317
+ return new ToolError(MANAGED_DEVICE_CONTEXT_STALE_TEXT, { kind: "unavailable" });
318
+ if (e instanceof ManagedDeviceContextUnavailable)
319
+ return new ToolError(MANAGED_DEVICE_CONTEXT_UNAVAILABLE_TEXT, { kind: "unavailable" });
320
+ if (e instanceof ManagedDeviceContextFailed)
321
+ return new ToolError(MANAGED_DEVICE_CONTEXT_FAILED_TEXT, { kind: "unavailable" });
322
+ // the managed route's typed refusals (unknown first: it never proves the operation had no effect)
323
+ if (isSandboxOperationOutcomeUnknownError(e)) {
324
+ log?.warn("sandbox operation outcome unknown", { err: e });
325
+ return new ToolError(OUTCOME_UNKNOWN_TOOL_TEXT, { kind: "unavailable" });
326
+ }
327
+ // kernel-typed, before the scope refusal it extends: nothing was sent, a retry is safe
328
+ if (isDeviceRequestNotSent(e))
329
+ return new ToolError(DEVICE_REQUEST_NOT_SENT_TOOL_TEXT, { kind: "unavailable" });
330
+ if (isSandboxScopeDeniedError(e)) {
331
+ log?.warn("sandbox operation outside its scope", { err: e });
332
+ return new ToolError(SCOPE_DENIED_TOOL_TEXT);
333
+ }
334
+ if (isSandboxPermissionUnsupportedError(e)) {
335
+ log?.warn("sandbox permission profile unsupported", { err: e });
336
+ return new ToolError(PERMISSION_UNSUPPORTED_TOOL_TEXT);
337
+ }
274
338
  if (e instanceof SandboxProviderUnreachableError) {
275
339
  log?.warn("sandbox provider unreachable", { failure: e.failure, err: e.cause });
276
340
  if (e.failure === "connect") {
@@ -308,6 +372,13 @@ export function mapSandboxError(e, log) {
308
372
  return new ToolError(DEVICE_OUTDATED_TEXT);
309
373
  if (e.code === "device.auto_mode_not_allowed")
310
374
  return new ToolError(AUTO_MODE_TOOL_TEXT);
375
+ if (e.code === "device.full_access_not_allowed")
376
+ return new ToolError(FULL_ACCESS_CEILING_TOOL_TEXT);
377
+ if (FULL_ACCESS_OFF_BY_POLICY_CODES.has(e.code))
378
+ return new ToolError(FULL_ACCESS_OFF_BY_POLICY_TOOL_TEXT);
379
+ if (e.code === "device.permission_reconcile_required") {
380
+ return new ToolError(RECONCILE_REQUIRED_TEXT, { kind: "unavailable" });
381
+ }
311
382
  if (e.code === "sandbox.open_network_refused") {
312
383
  return new ToolError(SANDBOX_OPEN_NETWORK_REFUSED_TEXT);
313
384
  }
@@ -319,6 +390,10 @@ export function mapSandboxError(e, log) {
319
390
  return new ToolError(FILES_GONE_TEXT);
320
391
  if (e instanceof DeviceProtocolError)
321
392
  return new ToolError(deviceProtocolText(e.message));
393
+ if (e instanceof InstanceBindingError) {
394
+ log?.warn("device instance binding failed", { err: e });
395
+ return new ToolError(INSTANCE_BINDING_TEXT, { kind: "unavailable" });
396
+ }
322
397
  if (e instanceof SandboxLockLostError)
323
398
  return new ToolError(LOCK_LOST_TEXT);
324
399
  if (e instanceof SandboxPathBusyError)
@@ -337,19 +412,96 @@ export function mapSandboxError(e, log) {
337
412
  * ({@link recordDevicePaths}).
338
413
  */
339
414
  export async function inSandbox(deps, ctx, fn) {
415
+ return inSandboxWith(deps, ctx, fn, false);
416
+ }
417
+ /**
418
+ * The device entry of every builtin tool (B-17): once the one activation gate is on (the managed
419
+ * writer required, {@link SandboxToolDeps.managedDeviceContextRequired}) the managed operation
420
+ * route ({@link inSandboxOperations}: the marked device paths recorded before the callback, every
421
+ * provider call a managed operation); otherwise the legacy route ({@link inSandbox}), unchanged.
422
+ */
423
+ export async function inToolSandbox(deps, ctx, fn) {
424
+ return deps.managedDeviceContextRequired
425
+ ? inSandboxOperations(deps, ctx, fn)
426
+ : inSandbox(deps, ctx, fn);
427
+ }
428
+ export async function inSandboxOperations(deps, ctx, fn, stage) {
429
+ return inSandboxWith(deps, ctx, fn, true, stage);
430
+ }
431
+ /**
432
+ * Trusted copy callbacks only receive preparation's three methods. Once the activation gate is on
433
+ * the copy is a trusted preparation on the managed route ({@link inSandboxOperationPreparation},
434
+ * scoped to `roots`, after the marked device paths); otherwise the protocol-2 binding.
435
+ */
436
+ export async function inSandboxPreparation(deps, ctx, purpose, roots, fn) {
437
+ if (deps.managedDeviceContextRequired)
438
+ return inSandboxOperationPreparation(deps, ctx, purpose, roots, fn);
439
+ return inSandbox(deps, ctx, (s) => fn(legacyPreparationSession(s)));
440
+ }
441
+ /** The trusted-copy entry on the managed route ({@link inSandboxPreparation} once activated). */
442
+ export async function inSandboxOperationPreparation(deps, ctx, purpose, roots, fn) {
443
+ let value;
444
+ return inSandboxOperations(deps, ctx, async () => value, {
445
+ purpose,
446
+ roots,
447
+ run: async (s) => {
448
+ value = await fn(s);
449
+ },
450
+ });
451
+ }
452
+ async function inSandboxWith(deps, ctx, fn, operations, stage) {
340
453
  try {
454
+ // once activated, only the managed route runs: a legacy route refuses before entering, so v1
455
+ // permission context never sits next to old-mode device_paths; a managed route never runs
456
+ // without its writer, so no preparation or user callback can run unrecorded
457
+ if (!operations && deps.managedDeviceContextRequired)
458
+ throw new ManagedDeviceContextFailed("refused");
459
+ const managed = operations ? managedWriter(deps) : undefined;
341
460
  const deviceId = await deps.devices.forTool(ctx.orgId, sandboxConversationOf(ctx));
342
461
  // the mode once per call: the path checks follow it and the device_paths event records it;
343
462
  // the working facts (workspace, home, project snapshot) are read as the review reads them
344
463
  // a call the review covered runs in the working root it was reviewed against: never read again
345
464
  const reviewed = ctx.reviewedWorkingRoot;
346
- const [level, working] = await Promise.all([
465
+ const [level, reach, working] = await Promise.all([
347
466
  deps.devices.modeLevel?.(ctx.orgId, deviceId) ?? null,
467
+ deps.devices.projectReach?.(ctx.orgId, deviceId),
348
468
  reviewed !== undefined
349
469
  ? null
350
470
  : (deps.devices.workingFacts?.(ctx.orgId, sandboxConversationOf(ctx), ctx.conversationId, deviceId) ?? null),
351
471
  ]);
352
- return await deps.sandbox.withSandbox({
472
+ const enter = operations
473
+ ? (use, call, signal) => {
474
+ const claim = ctx.executionClaim;
475
+ if (!claim || !ctx.runId || claim.runId !== ctx.runId || !deps.sandbox.withOperations)
476
+ throw new SandboxScopeDeniedError("The tool has no current server execution claim");
477
+ return deps.sandbox.withOperations(use, {
478
+ claim,
479
+ callId: ctx.callId,
480
+ deadlineMs: Math.min(ctx.runDeadline ?? Infinity, Date.now() + 30000),
481
+ ...(managed && { contextEvidence: true }),
482
+ beforeUser: async (staging, info, sig) => {
483
+ // the held instance's device paths, recorded before any preparation or user callback
484
+ if (managed) {
485
+ // no installed binding to describe the held instance: unavailable, not stale
486
+ if (!info.contextEvidence)
487
+ throw new ManagedDeviceContextUnavailable();
488
+ // B-18: the review judged the call against a root (the workspace included);
489
+ // held evidence of another root is stale, refused before anything is recorded
490
+ // or run
491
+ const against = ctx.reviewedAgainstRoot ?? reviewed;
492
+ if (against !== undefined &&
493
+ canonicalRoot(against) !== canonicalRoot(info.contextEvidence.workingRoot))
494
+ throw new ManagedDeviceContextStale();
495
+ await recordManagedDevicePaths({ managedDeviceContext: managed }, ctx, info.contextEvidence, sig);
496
+ }
497
+ if (stage)
498
+ await staging.prepare(stage.purpose, stage.roots(info.roots), (p, signal) => stage.run({ deviceId, roots: info.roots, p, signal }));
499
+ sig.throwIfAborted();
500
+ },
501
+ }, call, signal);
502
+ }
503
+ : deps.sandbox.withSandbox.bind(deps.sandbox);
504
+ return await enter({
353
505
  orgId: ctx.orgId,
354
506
  deviceId,
355
507
  // a sub-agent is told when another holder rebuilt the shared instance (final review m5)
@@ -368,11 +520,17 @@ export async function inSandbox(deps, ctx, fn) {
368
520
  mode,
369
521
  h,
370
522
  roots: info.roots,
371
- workingRoot: reviewed ?? sessionWorkingRoot(working, mode, info.roots.workspace),
523
+ // a managed call runs in the working root its device context recorded (admission's),
524
+ // which a reviewed call's root equals (checked before the callback, B-18)
525
+ workingRoot: (managed ? info.contextEvidence?.workingRoot : undefined) ??
526
+ reviewed ??
527
+ sessionWorkingRoot(working, mode, info.roots.workspace, reach),
372
528
  p,
373
529
  signal,
374
530
  };
375
- await recordDevicePaths(deps, ctx, info.roots, level ?? null);
531
+ // the legacy writer only on unactivated routes: a managed call recorded before preparation
532
+ if (!managed)
533
+ await recordDevicePaths(deps, ctx, info.roots, level ?? null);
376
534
  const notices = [];
377
535
  if (info.filesReset)
378
536
  notices.push(sandboxFilesResetNotice(info.roots));
@@ -387,6 +545,32 @@ export async function inSandbox(deps, ctx, fn) {
387
545
  throw mapSandboxError(e, deps.log);
388
546
  }
389
547
  }
548
+ /**
549
+ * The managed writer of an operations route: the injected one, or none while dormant. Once the
550
+ * paired activation requires it, a missing writer refuses the call before anything is entered.
551
+ */
552
+ function managedWriter(deps) {
553
+ if (deps.managedDeviceContext)
554
+ return deps.managedDeviceContext;
555
+ if (deps.managedDeviceContextRequired)
556
+ throw new ManagedDeviceContextFailed("refused");
557
+ return undefined;
558
+ }
559
+ /**
560
+ * Records the managed device paths of the held instance `held` into the calling conversation (a
561
+ * sub-agent: its own log) for this call's run and actor: a thin delegator to the managed writer,
562
+ * which owns the transaction and all validation (permission context replay spec B3).
563
+ */
564
+ export async function recordManagedDevicePaths(deps, ctx, held, signal) {
565
+ if (ctx.runId === undefined)
566
+ throw new ManagedDeviceContextFailed("refused");
567
+ await deps.managedDeviceContext.record({
568
+ orgId: ctx.orgId,
569
+ conversationId: ctx.conversationId,
570
+ runId: ctx.runId,
571
+ accountId: ctx.accountId,
572
+ }, held, signal);
573
+ }
390
574
  /**
391
575
  * Environments spec §13.1, ruling R22; auto mode spec §4.2: the calling conversation's log (the
392
576
  * log its model reads; a sub-agent's own too) gets a `device_paths` event on its first sandbox
@@ -409,10 +593,10 @@ async function recordDevicePaths(deps, ctx, roots, level) {
409
593
  * workspace (`workspace`), where the call really runs. Every session built outside `inSandbox` (a
410
594
  * person's project skill invocation) takes its working root from here too.
411
595
  */
412
- export function sessionWorkingRoot(working, mode, workspace) {
596
+ export function sessionWorkingRoot(working, mode, workspace, reach) {
413
597
  if (working === null)
414
598
  return workspace;
415
- const root = workingRootOf(working.project, { mode, ...working });
599
+ const root = workingRootOf(working.project, { mode, reach, ...working });
416
600
  return root === working.workspace ? workspace : root;
417
601
  }
418
602
  /** The conversation whose device a call uses (the root conversation's for a sub-agent). */
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import { ExtensionPointUnavailableError, MEDIA_NAME_MAX_CHARS, ToolError, } from "@capybara-hq/plugin-sdk";
3
3
  import { isValidArtifactName } from "../../../conversations/events.js";
4
4
  import { ApiError } from "../../../errors.js";
5
- import { checkPath, checkPathShape, clip, display, inSandbox, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, withNotices, } from "./common.js";
5
+ import { checkPath, checkPathShape, clip, display, inToolSandbox, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, withNotices, } from "./common.js";
6
6
  const SPEC = {
7
7
  name: "Deliver",
8
8
  // Display only (the tool row; not in the fingerprint, never sent to the model).
@@ -111,7 +111,7 @@ export function sandboxDeliverTool(deps) {
111
111
  const max = deps.config.get().sandbox.deliverMaxBytes;
112
112
  checkPathShape(input.file_path, "file_path");
113
113
  let path = "";
114
- const { value: data, notices } = await inSandbox(deps, ctx, async ({ h, roots, p, signal }) => {
114
+ const { value: data, notices } = await inToolSandbox(deps, ctx, async ({ h, roots, p, signal }) => {
115
115
  path = checkPath(input.file_path, roots, "file_path");
116
116
  const st = await p.stat(h, path, signal);
117
117
  if (st === null)
@@ -1,6 +1,6 @@
1
1
  import { ToolError } from "@capybara-hq/plugin-sdk";
2
2
  import { lineDiff, viewPath } from "../../view.js";
3
- import { checkFilePathShape, checkToolWritable, clip, display, inSandbox, looksBinary, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, withNotices, withPathLease, } from "./common.js";
3
+ import { checkFilePathShape, checkToolWritable, clip, display, inToolSandbox, looksBinary, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, withNotices, withPathLease, } from "./common.js";
4
4
  import { assertReadAndUnchanged, FileGuardError, fileStateOf, guardResult, keepGuardRefusal, normalizeSandboxPath, recordedFile, } from "./file-state.js";
5
5
  import { READ_MAX_BYTES } from "./read.js";
6
6
  /** 可编辑的最大文件(字节):更大的用 Bash 处理。 */
@@ -59,7 +59,7 @@ export function sandboxEditTool(deps) {
59
59
  checkFilePathShape(input.file_path);
60
60
  let path = "";
61
61
  // a read-before-write refusal is the guard working: a result with the guard view
62
- const ran = await inSandbox(deps, ctx, (s) => {
62
+ const ran = await inToolSandbox(deps, ctx, (s) => {
63
63
  const { deviceId, h, p, signal } = s;
64
64
  path = checkToolWritable(input.file_path, s);
65
65
  // read, replace, write: one holder at a time per file
@@ -1,6 +1,6 @@
1
- import { isFileSystemGoneError, isSandboxGoneError, ToolError, } from "@capybara-hq/plugin-sdk";
1
+ import { isFileSystemGoneError, isSandboxGoneError, isSandboxOperationOutcomeUnknownError, isSandboxPermissionUnsupportedError, isSandboxScopeDeniedError, ToolError, } from "@capybara-hq/plugin-sdk";
2
2
  import { ApiError } from "../../../errors.js";
3
- import { assignAttachmentNames, attachmentsDir, clip, display, inSandbox, sandboxBaseTimeoutMs, sandboxConversationOf, unavailableWhenNoSandbox, withNotices, } from "./common.js";
3
+ import { assignAttachmentNames, attachmentsDir, clip, display, inSandboxPreparation, sandboxBaseTimeoutMs, sandboxConversationOf, unavailableWhenNoSandbox, withNotices, } from "./common.js";
4
4
  const SPEC = {
5
5
  name: "FetchAttachment",
6
6
  // Display only (the tool row; not in the fingerprint, never sent to the model).
@@ -84,7 +84,9 @@ export function sandboxFetchAttachmentTool(deps) {
84
84
  const name = assigned.get(attachment.id);
85
85
  if (name === undefined)
86
86
  throw new ToolError(unknownFileText(file, list));
87
- const { value, notices } = await inSandbox(deps, ctx, async ({ h, roots, p, signal }) => {
87
+ // a trusted copy: the preparation entry (scoped to the attachments directory), so the
88
+ // managed route stages it like a skill copy once the permission runtime is active
89
+ const { value, notices } = await inSandboxPreparation(deps, ctx, "attachments", (roots) => [attachmentsDir(roots, conv)], async ({ roots, p, signal }) => {
88
90
  const path = `${attachmentsDir(roots, conv)}/${name}`;
89
91
  let bytes;
90
92
  try {
@@ -92,7 +94,7 @@ export function sandboxFetchAttachmentTool(deps) {
92
94
  if (opened === null)
93
95
  throw new ToolError(goneText(name));
94
96
  bytes = new Uint8Array(await new Response(opened.body).arrayBuffer());
95
- await p.writeFile(h, path, bytes, signal);
97
+ await p.writeFile(path, bytes, signal);
96
98
  }
97
99
  catch (e) {
98
100
  // an abort (timeout / lost lock / stopped run) and a gone device or instance go to
@@ -100,6 +102,11 @@ export function sandboxFetchAttachmentTool(deps) {
100
102
  // internal address)
101
103
  if (signal.aborted || isSandboxGoneError(e) || isFileSystemGoneError(e))
102
104
  throw e;
105
+ // a managed route's typed refusal too: mapSandboxError gives its fixed text
106
+ if (isSandboxScopeDeniedError(e) ||
107
+ isSandboxPermissionUnsupportedError(e) ||
108
+ isSandboxOperationOutcomeUnknownError(e))
109
+ throw e;
103
110
  if (e instanceof ToolError)
104
111
  throw e;
105
112
  if (e instanceof ApiError && e.code === "storage.unavailable") {
@@ -1,5 +1,5 @@
1
1
  import { ToolError } from "@capybara-hq/plugin-sdk";
2
- import { checkPathShape, checkToolPath, clip, display, inSandbox, sandboxBaseTimeoutMs, searchTimeoutMs, unavailableWhenNoSandbox, withNotices, } from "./common.js";
2
+ import { checkPathShape, checkToolPath, clip, display, inToolSandbox, sandboxBaseTimeoutMs, searchTimeoutMs, unavailableWhenNoSandbox, withNotices, } from "./common.js";
3
3
  import { compileGlob, GlobPatternError } from "./glob-match.js";
4
4
  /** 最多列出的文件数。 */
5
5
  const MAX_RESULTS = 1000;
@@ -62,7 +62,7 @@ export function sandboxGlobTool(deps) {
62
62
  if (given !== undefined)
63
63
  checkPathShape(given);
64
64
  let dir = "";
65
- const { value: files, notices } = await inSandbox(deps, ctx, async (s) => {
65
+ const { value: files, notices } = await inToolSandbox(deps, ctx, async (s) => {
66
66
  const { h, p, signal } = s;
67
67
  // default: the working root (a bound project's root, else the workspace)
68
68
  dir = checkToolPath(input.path ?? s.workingRoot, s);
@@ -1,5 +1,5 @@
1
1
  import { ToolError } from "@capybara-hq/plugin-sdk";
2
- import { checkPathShape, checkToolPath, clip, display, inSandbox, sandboxBaseTimeoutMs, searchTimeoutMs, shellQuote, unavailableWhenNoSandbox, withNotices, } from "./common.js";
2
+ import { checkPathShape, checkToolPath, clip, display, inToolSandbox, sandboxBaseTimeoutMs, searchTimeoutMs, shellQuote, unavailableWhenNoSandbox, withNotices, } from "./common.js";
3
3
  /** The most output entries (lines, files or counts) returned in one call, whatever `head_limit` says. */
4
4
  const MAX_MATCHES = 500;
5
5
  /** `head_limit` when the model gives none. */
@@ -163,7 +163,7 @@ export function sandboxGrepTool(deps) {
163
163
  if (g.path !== undefined)
164
164
  checkPathShape(g.path);
165
165
  let path = "";
166
- const { value, notices } = await inSandbox(deps, ctx, async (s) => {
166
+ const { value, notices } = await inToolSandbox(deps, ctx, async (s) => {
167
167
  const { h, p, signal } = s;
168
168
  // default: the working root (a bound project's root, else the workspace)
169
169
  path = checkToolPath(g.path ?? s.workingRoot, s);
@@ -1,6 +1,6 @@
1
1
  import { ToolError } from "@capybara-hq/plugin-sdk";
2
2
  import { viewPath } from "../../view.js";
3
- import { checkFilePathShape, checkToolPath, clip, display, inSandbox, looksBinary, resolveToolPath, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, withNotices, } from "./common.js";
3
+ import { checkFilePathShape, checkToolPath, clip, display, inToolSandbox, looksBinary, resolveToolPath, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, withNotices, } from "./common.js";
4
4
  import { normalizeSandboxPath, recordedFile } from "./file-state.js";
5
5
  /** 不给 `limit` 时一次读的行数。 */
6
6
  const DEFAULT_LIMIT = 2000;
@@ -86,7 +86,7 @@ export function sandboxReadTool(deps) {
86
86
  const { offset = 1, limit = DEFAULT_LIMIT } = input;
87
87
  checkFilePathShape(input.file_path);
88
88
  let path = "";
89
- const { value, notices } = await inSandbox(deps, ctx, async (s) => {
89
+ const { value, notices } = await inToolSandbox(deps, ctx, async (s) => {
90
90
  const { h, p, signal } = s;
91
91
  path = checkToolPath(resolveToolPath(input.file_path, s), s, "file_path");
92
92
  const st = await p.stat(h, path, signal);
@@ -1,4 +1,5 @@
1
1
  import { formatElapsed, lostReasonText } from "../../../background/render.js";
2
+ import { isManagedTask } from "../../../background/store.js";
2
3
  import { clip, display, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, } from "./common.js";
3
4
  import { outputFile, taskEnv } from "./task-output.js";
4
5
  /** How many finished background tasks (and finished sub-agents) `TaskList` lists at most. */
@@ -43,9 +44,14 @@ function taskState(task, now) {
43
44
  return `${s}, after ${elapsed}`;
44
45
  }
45
46
  function taskEntry(task, now) {
46
- const output = task.sandboxCreatedAt === null && task.status !== "running"
47
+ let output = task.sandboxCreatedAt === null && task.status !== "running"
47
48
  ? "none (the command never started)"
48
49
  : outputFile(task);
50
+ // a managed task's artifact is told only once its start was acknowledged
51
+ if (isManagedTask(task) && task.executionRef === null) {
52
+ output =
53
+ task.status === "running" ? "none yet (the task is still starting)" : "none (not started)";
54
+ }
49
55
  return `- ${task.id} ${taskState(task, now)}: ${JSON.stringify(task.description)}\n Output: ${output}`;
50
56
  }
51
57
  const ACTIVE_AGENT = new Set(["queued", "running", "waiting"]);
@@ -1,5 +1,5 @@
1
1
  import { type SandboxHandle } from "@capybara-hq/plugin-sdk";
2
- import type { BackgroundTaskRow } from "../../../background/store.js";
2
+ import { type BackgroundTaskRow } from "../../../background/store.js";
3
3
  import type { HeldProvider, IfRunningResult, SandboxService } from "../../../sandbox/sandbox.service.js";
4
4
  import type { BuiltinCallContext, BuiltinTool } from "../../registry.js";
5
5
  import { type SandboxToolDeps } from "./common.js";