@mastra/core 1.6.0 → 1.7.0

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 (453) hide show
  1. package/CHANGELOG.md +236 -0
  2. package/dist/agent/agent.d.ts +6 -0
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/index.cjs +8 -8
  5. package/dist/agent/index.js +1 -1
  6. package/dist/{chunk-VJWRJWSC.cjs → chunk-2X66GWF5.cjs} +94 -16
  7. package/dist/chunk-2X66GWF5.cjs.map +1 -0
  8. package/dist/{chunk-YM6245EM.js → chunk-6OXW5E2O.js} +3 -3
  9. package/dist/{chunk-YM6245EM.js.map → chunk-6OXW5E2O.js.map} +1 -1
  10. package/dist/{chunk-XWZAKKFT.cjs → chunk-6QBN6MZY.cjs} +14 -14
  11. package/dist/{chunk-XWZAKKFT.cjs.map → chunk-6QBN6MZY.cjs.map} +1 -1
  12. package/dist/{chunk-AYHSPIT6.cjs → chunk-7UAJ6LMR.cjs} +820 -259
  13. package/dist/chunk-7UAJ6LMR.cjs.map +1 -0
  14. package/dist/{chunk-RZNHRIM7.cjs → chunk-A72NTLFT.cjs} +5 -5
  15. package/dist/{chunk-RZNHRIM7.cjs.map → chunk-A72NTLFT.cjs.map} +1 -1
  16. package/dist/{chunk-EEU5NHHU.js → chunk-DFCRXDVK.js} +3 -3
  17. package/dist/{chunk-EEU5NHHU.js.map → chunk-DFCRXDVK.js.map} +1 -1
  18. package/dist/{chunk-5K45E5VE.js → chunk-GPJGPARM.js} +3 -2
  19. package/dist/chunk-GPJGPARM.js.map +1 -0
  20. package/dist/{chunk-LNKS4TJ6.cjs → chunk-HB6T4554.cjs} +8 -7
  21. package/dist/chunk-HB6T4554.cjs.map +1 -0
  22. package/dist/{chunk-DGS2KGDI.js → chunk-KUXNBWN7.js} +6 -5
  23. package/dist/chunk-KUXNBWN7.js.map +1 -0
  24. package/dist/{chunk-IHDE4CJV.js → chunk-QSHV7GPT.js} +89 -12
  25. package/dist/chunk-QSHV7GPT.js.map +1 -0
  26. package/dist/{chunk-3U3XFMGJ.cjs → chunk-QTAS3HND.cjs} +13 -8
  27. package/dist/chunk-QTAS3HND.cjs.map +1 -0
  28. package/dist/{chunk-RHKNKJNM.js → chunk-QWTB53GS.js} +4 -4
  29. package/dist/{chunk-RHKNKJNM.js.map → chunk-QWTB53GS.js.map} +1 -1
  30. package/dist/{chunk-4WG5K4CK.js → chunk-R4N65TLG.js} +7 -7
  31. package/dist/{chunk-4WG5K4CK.js.map → chunk-R4N65TLG.js.map} +1 -1
  32. package/dist/{chunk-5VQPSWPG.cjs → chunk-RABITNTG.cjs} +48 -48
  33. package/dist/{chunk-5VQPSWPG.cjs.map → chunk-RABITNTG.cjs.map} +1 -1
  34. package/dist/{chunk-TVPANHLE.cjs → chunk-SBOHDNIZ.cjs} +3 -2
  35. package/dist/chunk-SBOHDNIZ.cjs.map +1 -0
  36. package/dist/{chunk-MWGGSA5Q.js → chunk-T6GAM3SQ.js} +10 -5
  37. package/dist/chunk-T6GAM3SQ.js.map +1 -0
  38. package/dist/{chunk-TL2TTA4X.cjs → chunk-YQG7NBPR.cjs} +9 -9
  39. package/dist/{chunk-TL2TTA4X.cjs.map → chunk-YQG7NBPR.cjs.map} +1 -1
  40. package/dist/{chunk-XB3DA67Q.js → chunk-ZSBM2SVU.js} +818 -259
  41. package/dist/chunk-ZSBM2SVU.js.map +1 -0
  42. package/dist/datasets/experiment/scorer.d.ts.map +1 -1
  43. package/dist/datasets/index.cjs +17 -17
  44. package/dist/datasets/index.js +2 -2
  45. package/dist/evals/index.cjs +20 -20
  46. package/dist/evals/index.js +3 -3
  47. package/dist/evals/scoreTraces/index.cjs +7 -6
  48. package/dist/evals/scoreTraces/index.cjs.map +1 -1
  49. package/dist/evals/scoreTraces/index.js +4 -3
  50. package/dist/evals/scoreTraces/index.js.map +1 -1
  51. package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
  52. package/dist/harness/harness.d.ts +21 -1
  53. package/dist/harness/harness.d.ts.map +1 -1
  54. package/dist/harness/index.cjs +422 -5
  55. package/dist/harness/index.cjs.map +1 -1
  56. package/dist/harness/index.d.ts +2 -1
  57. package/dist/harness/index.d.ts.map +1 -1
  58. package/dist/harness/index.js +418 -3
  59. package/dist/harness/index.js.map +1 -1
  60. package/dist/harness/types.d.ts +151 -0
  61. package/dist/harness/types.d.ts.map +1 -1
  62. package/dist/index.cjs +2 -2
  63. package/dist/index.js +1 -1
  64. package/dist/loop/index.cjs +12 -12
  65. package/dist/loop/index.js +1 -1
  66. package/dist/loop/test-utils/tools.d.ts.map +1 -1
  67. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  68. package/dist/mastra/hooks.d.ts.map +1 -1
  69. package/dist/mastra/index.cjs +2 -2
  70. package/dist/mastra/index.js +1 -1
  71. package/dist/memory/index.cjs +14 -14
  72. package/dist/memory/index.js +1 -1
  73. package/dist/processor-provider/index.cjs +10 -10
  74. package/dist/processor-provider/index.js +1 -1
  75. package/dist/processors/index.cjs +45 -41
  76. package/dist/processors/index.js +1 -1
  77. package/dist/processors/processors/index.d.ts +1 -0
  78. package/dist/processors/processors/index.d.ts.map +1 -1
  79. package/dist/processors/processors/workspace-instructions.d.ts +50 -0
  80. package/dist/processors/processors/workspace-instructions.d.ts.map +1 -0
  81. package/dist/relevance/index.cjs +3 -3
  82. package/dist/relevance/index.js +1 -1
  83. package/dist/storage/constants.cjs +56 -56
  84. package/dist/storage/constants.d.ts.map +1 -1
  85. package/dist/storage/constants.js +1 -1
  86. package/dist/storage/index.cjs +160 -160
  87. package/dist/storage/index.js +2 -2
  88. package/dist/storage/types.d.ts +2 -0
  89. package/dist/storage/types.d.ts.map +1 -1
  90. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
  91. package/dist/stream/base/output.d.ts.map +1 -1
  92. package/dist/stream/index.cjs +8 -8
  93. package/dist/stream/index.js +1 -1
  94. package/dist/tool-loop-agent/index.cjs +4 -4
  95. package/dist/tool-loop-agent/index.js +1 -1
  96. package/dist/vector/index.cjs +7 -7
  97. package/dist/vector/index.js +1 -1
  98. package/dist/workflows/evented/index.cjs +10 -10
  99. package/dist/workflows/evented/index.js +1 -1
  100. package/dist/workflows/index.cjs +25 -25
  101. package/dist/workflows/index.js +1 -1
  102. package/dist/workspace/constants/index.d.ts +2 -0
  103. package/dist/workspace/constants/index.d.ts.map +1 -1
  104. package/dist/workspace/errors.d.ts +1 -1
  105. package/dist/workspace/errors.d.ts.map +1 -1
  106. package/dist/workspace/filesystem/composite-filesystem.d.ts +4 -1
  107. package/dist/workspace/filesystem/composite-filesystem.d.ts.map +1 -1
  108. package/dist/workspace/filesystem/file-write-lock.d.ts +35 -0
  109. package/dist/workspace/filesystem/file-write-lock.d.ts.map +1 -0
  110. package/dist/workspace/filesystem/filesystem.d.ts +5 -1
  111. package/dist/workspace/filesystem/filesystem.d.ts.map +1 -1
  112. package/dist/workspace/filesystem/index.d.ts +1 -0
  113. package/dist/workspace/filesystem/index.d.ts.map +1 -1
  114. package/dist/workspace/filesystem/local-filesystem.d.ts +17 -1
  115. package/dist/workspace/filesystem/local-filesystem.d.ts.map +1 -1
  116. package/dist/workspace/index.cjs +72 -64
  117. package/dist/workspace/index.d.ts +3 -2
  118. package/dist/workspace/index.d.ts.map +1 -1
  119. package/dist/workspace/index.js +1 -1
  120. package/dist/workspace/lifecycle.d.ts +1 -9
  121. package/dist/workspace/lifecycle.d.ts.map +1 -1
  122. package/dist/workspace/sandbox/index.d.ts +2 -0
  123. package/dist/workspace/sandbox/index.d.ts.map +1 -1
  124. package/dist/workspace/sandbox/local-process-manager.d.ts +18 -0
  125. package/dist/workspace/sandbox/local-process-manager.d.ts.map +1 -0
  126. package/dist/workspace/sandbox/local-sandbox.d.ts +49 -35
  127. package/dist/workspace/sandbox/local-sandbox.d.ts.map +1 -1
  128. package/dist/workspace/sandbox/mastra-sandbox.d.ts +45 -11
  129. package/dist/workspace/sandbox/mastra-sandbox.d.ts.map +1 -1
  130. package/dist/workspace/sandbox/native-sandbox/bubblewrap.d.ts +2 -3
  131. package/dist/workspace/sandbox/native-sandbox/bubblewrap.d.ts.map +1 -1
  132. package/dist/workspace/sandbox/native-sandbox/seatbelt.d.ts +2 -3
  133. package/dist/workspace/sandbox/native-sandbox/seatbelt.d.ts.map +1 -1
  134. package/dist/workspace/sandbox/native-sandbox/wrapper.d.ts +4 -5
  135. package/dist/workspace/sandbox/native-sandbox/wrapper.d.ts.map +1 -1
  136. package/dist/workspace/sandbox/process-manager/index.d.ts +4 -0
  137. package/dist/workspace/sandbox/process-manager/index.d.ts.map +1 -0
  138. package/dist/workspace/sandbox/process-manager/process-handle.d.ts +107 -0
  139. package/dist/workspace/sandbox/process-manager/process-handle.d.ts.map +1 -0
  140. package/dist/workspace/sandbox/process-manager/process-manager.d.ts +59 -0
  141. package/dist/workspace/sandbox/process-manager/process-manager.d.ts.map +1 -0
  142. package/dist/workspace/sandbox/process-manager/types.d.ts +24 -0
  143. package/dist/workspace/sandbox/process-manager/types.d.ts.map +1 -0
  144. package/dist/workspace/sandbox/sandbox.d.ts +38 -2
  145. package/dist/workspace/sandbox/sandbox.d.ts.map +1 -1
  146. package/dist/workspace/sandbox/types.d.ts +9 -2
  147. package/dist/workspace/sandbox/types.d.ts.map +1 -1
  148. package/dist/workspace/sandbox/utils.d.ts +7 -0
  149. package/dist/workspace/sandbox/utils.d.ts.map +1 -0
  150. package/dist/workspace/tools/execute-command.d.ts +53 -2
  151. package/dist/workspace/tools/execute-command.d.ts.map +1 -1
  152. package/dist/workspace/tools/get-process-output.d.ts +6 -0
  153. package/dist/workspace/tools/get-process-output.d.ts.map +1 -0
  154. package/dist/workspace/tools/index.d.ts +4 -1
  155. package/dist/workspace/tools/index.d.ts.map +1 -1
  156. package/dist/workspace/tools/kill-process.d.ts +4 -0
  157. package/dist/workspace/tools/kill-process.d.ts.map +1 -0
  158. package/dist/workspace/tools/output-helpers.d.ts +21 -0
  159. package/dist/workspace/tools/output-helpers.d.ts.map +1 -0
  160. package/dist/workspace/tools/tools.d.ts.map +1 -1
  161. package/dist/workspace/types.d.ts +31 -0
  162. package/dist/workspace/types.d.ts.map +1 -1
  163. package/dist/workspace/utils.d.ts +11 -0
  164. package/dist/workspace/utils.d.ts.map +1 -0
  165. package/dist/workspace/workspace.d.ts +36 -0
  166. package/dist/workspace/workspace.d.ts.map +1 -1
  167. package/package.json +7 -7
  168. package/dist/chunk-3U3XFMGJ.cjs.map +0 -1
  169. package/dist/chunk-5K45E5VE.js.map +0 -1
  170. package/dist/chunk-AYHSPIT6.cjs.map +0 -1
  171. package/dist/chunk-DGS2KGDI.js.map +0 -1
  172. package/dist/chunk-IHDE4CJV.js.map +0 -1
  173. package/dist/chunk-LNKS4TJ6.cjs.map +0 -1
  174. package/dist/chunk-MWGGSA5Q.js.map +0 -1
  175. package/dist/chunk-TVPANHLE.cjs.map +0 -1
  176. package/dist/chunk-VJWRJWSC.cjs.map +0 -1
  177. package/dist/chunk-XB3DA67Q.js.map +0 -1
  178. package/dist/docs/SKILL.md +0 -301
  179. package/dist/docs/assets/SOURCE_MAP.json +0 -1413
  180. package/dist/docs/references/docs-agents-adding-voice.md +0 -353
  181. package/dist/docs/references/docs-agents-agent-approval.md +0 -377
  182. package/dist/docs/references/docs-agents-agent-memory.md +0 -212
  183. package/dist/docs/references/docs-agents-guardrails.md +0 -382
  184. package/dist/docs/references/docs-agents-network-approval.md +0 -275
  185. package/dist/docs/references/docs-agents-networks.md +0 -290
  186. package/dist/docs/references/docs-agents-overview.md +0 -309
  187. package/dist/docs/references/docs-agents-processors.md +0 -632
  188. package/dist/docs/references/docs-agents-structured-output.md +0 -271
  189. package/dist/docs/references/docs-agents-using-tools.md +0 -214
  190. package/dist/docs/references/docs-evals-custom-scorers.md +0 -519
  191. package/dist/docs/references/docs-evals-overview.md +0 -146
  192. package/dist/docs/references/docs-evals-running-in-ci.md +0 -106
  193. package/dist/docs/references/docs-mcp-overview.md +0 -370
  194. package/dist/docs/references/docs-mcp-publishing-mcp-server.md +0 -95
  195. package/dist/docs/references/docs-memory-memory-processors.md +0 -316
  196. package/dist/docs/references/docs-memory-observational-memory.md +0 -246
  197. package/dist/docs/references/docs-memory-overview.md +0 -45
  198. package/dist/docs/references/docs-memory-semantic-recall.md +0 -272
  199. package/dist/docs/references/docs-memory-storage.md +0 -261
  200. package/dist/docs/references/docs-memory-working-memory.md +0 -400
  201. package/dist/docs/references/docs-observability-datasets-overview.md +0 -188
  202. package/dist/docs/references/docs-observability-datasets-running-experiments.md +0 -266
  203. package/dist/docs/references/docs-observability-logging.md +0 -99
  204. package/dist/docs/references/docs-observability-overview.md +0 -70
  205. package/dist/docs/references/docs-observability-tracing-bridges-otel.md +0 -209
  206. package/dist/docs/references/docs-observability-tracing-exporters-arize.md +0 -274
  207. package/dist/docs/references/docs-observability-tracing-exporters-braintrust.md +0 -111
  208. package/dist/docs/references/docs-observability-tracing-exporters-cloud.md +0 -129
  209. package/dist/docs/references/docs-observability-tracing-exporters-datadog.md +0 -187
  210. package/dist/docs/references/docs-observability-tracing-exporters-default.md +0 -211
  211. package/dist/docs/references/docs-observability-tracing-exporters-laminar.md +0 -100
  212. package/dist/docs/references/docs-observability-tracing-exporters-langfuse.md +0 -217
  213. package/dist/docs/references/docs-observability-tracing-exporters-langsmith.md +0 -202
  214. package/dist/docs/references/docs-observability-tracing-exporters-otel.md +0 -479
  215. package/dist/docs/references/docs-observability-tracing-exporters-posthog.md +0 -148
  216. package/dist/docs/references/docs-observability-tracing-overview.md +0 -1114
  217. package/dist/docs/references/docs-rag-chunking-and-embedding.md +0 -183
  218. package/dist/docs/references/docs-rag-graph-rag.md +0 -215
  219. package/dist/docs/references/docs-rag-overview.md +0 -72
  220. package/dist/docs/references/docs-rag-retrieval.md +0 -521
  221. package/dist/docs/references/docs-rag-vector-databases.md +0 -648
  222. package/dist/docs/references/docs-server-auth-auth0.md +0 -222
  223. package/dist/docs/references/docs-server-auth-clerk.md +0 -132
  224. package/dist/docs/references/docs-server-auth-composite-auth.md +0 -234
  225. package/dist/docs/references/docs-server-auth-custom-auth-provider.md +0 -513
  226. package/dist/docs/references/docs-server-auth-firebase.md +0 -272
  227. package/dist/docs/references/docs-server-auth-jwt.md +0 -110
  228. package/dist/docs/references/docs-server-auth-simple-auth.md +0 -178
  229. package/dist/docs/references/docs-server-auth-supabase.md +0 -117
  230. package/dist/docs/references/docs-server-auth-workos.md +0 -190
  231. package/dist/docs/references/docs-server-custom-adapters.md +0 -374
  232. package/dist/docs/references/docs-server-custom-api-routes.md +0 -267
  233. package/dist/docs/references/docs-server-mastra-client.md +0 -243
  234. package/dist/docs/references/docs-server-mastra-server.md +0 -71
  235. package/dist/docs/references/docs-server-middleware.md +0 -228
  236. package/dist/docs/references/docs-server-request-context.md +0 -478
  237. package/dist/docs/references/docs-streaming-events.md +0 -247
  238. package/dist/docs/references/docs-streaming-tool-streaming.md +0 -178
  239. package/dist/docs/references/docs-streaming-workflow-streaming.md +0 -109
  240. package/dist/docs/references/docs-voice-overview.md +0 -979
  241. package/dist/docs/references/docs-voice-speech-to-speech.md +0 -103
  242. package/dist/docs/references/docs-voice-speech-to-text.md +0 -80
  243. package/dist/docs/references/docs-voice-text-to-speech.md +0 -84
  244. package/dist/docs/references/docs-workflows-agents-and-tools.md +0 -170
  245. package/dist/docs/references/docs-workflows-control-flow.md +0 -823
  246. package/dist/docs/references/docs-workflows-error-handling.md +0 -360
  247. package/dist/docs/references/docs-workflows-human-in-the-loop.md +0 -213
  248. package/dist/docs/references/docs-workflows-overview.md +0 -372
  249. package/dist/docs/references/docs-workflows-snapshots.md +0 -238
  250. package/dist/docs/references/docs-workflows-suspend-and-resume.md +0 -205
  251. package/dist/docs/references/docs-workflows-time-travel.md +0 -309
  252. package/dist/docs/references/docs-workflows-workflow-state.md +0 -181
  253. package/dist/docs/references/docs-workspace-filesystem.md +0 -162
  254. package/dist/docs/references/docs-workspace-overview.md +0 -239
  255. package/dist/docs/references/docs-workspace-sandbox.md +0 -63
  256. package/dist/docs/references/docs-workspace-search.md +0 -219
  257. package/dist/docs/references/docs-workspace-skills.md +0 -126
  258. package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +0 -140
  259. package/dist/docs/references/reference-agents-agent.md +0 -142
  260. package/dist/docs/references/reference-agents-generate.md +0 -174
  261. package/dist/docs/references/reference-agents-generateLegacy.md +0 -176
  262. package/dist/docs/references/reference-agents-getDefaultGenerateOptions.md +0 -36
  263. package/dist/docs/references/reference-agents-getDefaultOptions.md +0 -34
  264. package/dist/docs/references/reference-agents-getDefaultStreamOptions.md +0 -36
  265. package/dist/docs/references/reference-agents-getDescription.md +0 -21
  266. package/dist/docs/references/reference-agents-getInstructions.md +0 -34
  267. package/dist/docs/references/reference-agents-getLLM.md +0 -37
  268. package/dist/docs/references/reference-agents-getMemory.md +0 -34
  269. package/dist/docs/references/reference-agents-getModel.md +0 -34
  270. package/dist/docs/references/reference-agents-getTools.md +0 -29
  271. package/dist/docs/references/reference-agents-getVoice.md +0 -34
  272. package/dist/docs/references/reference-agents-listAgents.md +0 -35
  273. package/dist/docs/references/reference-agents-listScorers.md +0 -34
  274. package/dist/docs/references/reference-agents-listTools.md +0 -34
  275. package/dist/docs/references/reference-agents-listWorkflows.md +0 -34
  276. package/dist/docs/references/reference-agents-network.md +0 -134
  277. package/dist/docs/references/reference-ai-sdk-chat-route.md +0 -82
  278. package/dist/docs/references/reference-ai-sdk-network-route.md +0 -74
  279. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +0 -232
  280. package/dist/docs/references/reference-ai-sdk-with-mastra.md +0 -59
  281. package/dist/docs/references/reference-ai-sdk-workflow-route.md +0 -79
  282. package/dist/docs/references/reference-auth-auth0.md +0 -73
  283. package/dist/docs/references/reference-auth-clerk.md +0 -36
  284. package/dist/docs/references/reference-auth-firebase.md +0 -80
  285. package/dist/docs/references/reference-auth-jwt.md +0 -26
  286. package/dist/docs/references/reference-auth-supabase.md +0 -33
  287. package/dist/docs/references/reference-auth-workos.md +0 -84
  288. package/dist/docs/references/reference-client-js-agents.md +0 -438
  289. package/dist/docs/references/reference-configuration.md +0 -749
  290. package/dist/docs/references/reference-core-addGateway.md +0 -42
  291. package/dist/docs/references/reference-core-getAgent.md +0 -21
  292. package/dist/docs/references/reference-core-getAgentById.md +0 -21
  293. package/dist/docs/references/reference-core-getDeployer.md +0 -22
  294. package/dist/docs/references/reference-core-getGateway.md +0 -38
  295. package/dist/docs/references/reference-core-getGatewayById.md +0 -41
  296. package/dist/docs/references/reference-core-getLogger.md +0 -22
  297. package/dist/docs/references/reference-core-getMCPServer.md +0 -45
  298. package/dist/docs/references/reference-core-getMCPServerById.md +0 -53
  299. package/dist/docs/references/reference-core-getMemory.md +0 -50
  300. package/dist/docs/references/reference-core-getScorer.md +0 -54
  301. package/dist/docs/references/reference-core-getScorerById.md +0 -54
  302. package/dist/docs/references/reference-core-getServer.md +0 -22
  303. package/dist/docs/references/reference-core-getStorage.md +0 -22
  304. package/dist/docs/references/reference-core-getStoredAgentById.md +0 -89
  305. package/dist/docs/references/reference-core-getTelemetry.md +0 -22
  306. package/dist/docs/references/reference-core-getVector.md +0 -22
  307. package/dist/docs/references/reference-core-getWorkflow.md +0 -40
  308. package/dist/docs/references/reference-core-listAgents.md +0 -21
  309. package/dist/docs/references/reference-core-listGateways.md +0 -40
  310. package/dist/docs/references/reference-core-listLogs.md +0 -38
  311. package/dist/docs/references/reference-core-listLogsByRunId.md +0 -36
  312. package/dist/docs/references/reference-core-listMCPServers.md +0 -51
  313. package/dist/docs/references/reference-core-listMemory.md +0 -56
  314. package/dist/docs/references/reference-core-listScorers.md +0 -29
  315. package/dist/docs/references/reference-core-listStoredAgents.md +0 -93
  316. package/dist/docs/references/reference-core-listVectors.md +0 -22
  317. package/dist/docs/references/reference-core-listWorkflows.md +0 -21
  318. package/dist/docs/references/reference-core-mastra-class.md +0 -66
  319. package/dist/docs/references/reference-core-mastra-model-gateway.md +0 -153
  320. package/dist/docs/references/reference-core-setLogger.md +0 -26
  321. package/dist/docs/references/reference-core-setStorage.md +0 -27
  322. package/dist/docs/references/reference-datasets-addItem.md +0 -35
  323. package/dist/docs/references/reference-datasets-addItems.md +0 -33
  324. package/dist/docs/references/reference-datasets-compareExperiments.md +0 -48
  325. package/dist/docs/references/reference-datasets-create.md +0 -49
  326. package/dist/docs/references/reference-datasets-dataset.md +0 -78
  327. package/dist/docs/references/reference-datasets-datasets-manager.md +0 -84
  328. package/dist/docs/references/reference-datasets-delete.md +0 -23
  329. package/dist/docs/references/reference-datasets-deleteExperiment.md +0 -25
  330. package/dist/docs/references/reference-datasets-deleteItem.md +0 -25
  331. package/dist/docs/references/reference-datasets-deleteItems.md +0 -27
  332. package/dist/docs/references/reference-datasets-get.md +0 -29
  333. package/dist/docs/references/reference-datasets-getDetails.md +0 -45
  334. package/dist/docs/references/reference-datasets-getExperiment.md +0 -28
  335. package/dist/docs/references/reference-datasets-getItem.md +0 -31
  336. package/dist/docs/references/reference-datasets-getItemHistory.md +0 -29
  337. package/dist/docs/references/reference-datasets-list.md +0 -29
  338. package/dist/docs/references/reference-datasets-listExperimentResults.md +0 -37
  339. package/dist/docs/references/reference-datasets-listExperiments.md +0 -31
  340. package/dist/docs/references/reference-datasets-listItems.md +0 -44
  341. package/dist/docs/references/reference-datasets-listVersions.md +0 -31
  342. package/dist/docs/references/reference-datasets-startExperiment.md +0 -60
  343. package/dist/docs/references/reference-datasets-startExperimentAsync.md +0 -41
  344. package/dist/docs/references/reference-datasets-update.md +0 -46
  345. package/dist/docs/references/reference-datasets-updateItem.md +0 -36
  346. package/dist/docs/references/reference-evals-answer-relevancy.md +0 -105
  347. package/dist/docs/references/reference-evals-answer-similarity.md +0 -99
  348. package/dist/docs/references/reference-evals-bias.md +0 -120
  349. package/dist/docs/references/reference-evals-completeness.md +0 -137
  350. package/dist/docs/references/reference-evals-content-similarity.md +0 -101
  351. package/dist/docs/references/reference-evals-context-precision.md +0 -196
  352. package/dist/docs/references/reference-evals-create-scorer.md +0 -270
  353. package/dist/docs/references/reference-evals-faithfulness.md +0 -114
  354. package/dist/docs/references/reference-evals-hallucination.md +0 -220
  355. package/dist/docs/references/reference-evals-keyword-coverage.md +0 -128
  356. package/dist/docs/references/reference-evals-mastra-scorer.md +0 -123
  357. package/dist/docs/references/reference-evals-run-evals.md +0 -138
  358. package/dist/docs/references/reference-evals-scorer-utils.md +0 -330
  359. package/dist/docs/references/reference-evals-textual-difference.md +0 -113
  360. package/dist/docs/references/reference-evals-tone-consistency.md +0 -119
  361. package/dist/docs/references/reference-evals-toxicity.md +0 -123
  362. package/dist/docs/references/reference-harness-harness-class.md +0 -645
  363. package/dist/docs/references/reference-logging-pino-logger.md +0 -117
  364. package/dist/docs/references/reference-memory-deleteMessages.md +0 -40
  365. package/dist/docs/references/reference-memory-memory-class.md +0 -147
  366. package/dist/docs/references/reference-memory-observational-memory.md +0 -565
  367. package/dist/docs/references/reference-observability-tracing-bridges-otel.md +0 -131
  368. package/dist/docs/references/reference-observability-tracing-configuration.md +0 -178
  369. package/dist/docs/references/reference-observability-tracing-exporters-console-exporter.md +0 -138
  370. package/dist/docs/references/reference-observability-tracing-exporters-datadog.md +0 -116
  371. package/dist/docs/references/reference-observability-tracing-instances.md +0 -109
  372. package/dist/docs/references/reference-observability-tracing-interfaces.md +0 -749
  373. package/dist/docs/references/reference-observability-tracing-processors-sensitive-data-filter.md +0 -144
  374. package/dist/docs/references/reference-observability-tracing-spans.md +0 -224
  375. package/dist/docs/references/reference-processors-batch-parts-processor.md +0 -61
  376. package/dist/docs/references/reference-processors-language-detector.md +0 -81
  377. package/dist/docs/references/reference-processors-message-history-processor.md +0 -85
  378. package/dist/docs/references/reference-processors-moderation-processor.md +0 -104
  379. package/dist/docs/references/reference-processors-pii-detector.md +0 -107
  380. package/dist/docs/references/reference-processors-processor-interface.md +0 -525
  381. package/dist/docs/references/reference-processors-prompt-injection-detector.md +0 -71
  382. package/dist/docs/references/reference-processors-semantic-recall-processor.md +0 -123
  383. package/dist/docs/references/reference-processors-system-prompt-scrubber.md +0 -80
  384. package/dist/docs/references/reference-processors-token-limiter-processor.md +0 -113
  385. package/dist/docs/references/reference-processors-tool-call-filter.md +0 -85
  386. package/dist/docs/references/reference-processors-tool-search-processor.md +0 -113
  387. package/dist/docs/references/reference-processors-unicode-normalizer.md +0 -62
  388. package/dist/docs/references/reference-processors-working-memory-processor.md +0 -154
  389. package/dist/docs/references/reference-rag-database-config.md +0 -264
  390. package/dist/docs/references/reference-rag-embeddings.md +0 -92
  391. package/dist/docs/references/reference-server-mastra-server.md +0 -298
  392. package/dist/docs/references/reference-server-register-api-route.md +0 -249
  393. package/dist/docs/references/reference-storage-cloudflare-d1.md +0 -218
  394. package/dist/docs/references/reference-storage-composite.md +0 -235
  395. package/dist/docs/references/reference-storage-lance.md +0 -131
  396. package/dist/docs/references/reference-storage-libsql.md +0 -135
  397. package/dist/docs/references/reference-storage-mongodb.md +0 -262
  398. package/dist/docs/references/reference-storage-mssql.md +0 -155
  399. package/dist/docs/references/reference-storage-overview.md +0 -121
  400. package/dist/docs/references/reference-storage-postgresql.md +0 -529
  401. package/dist/docs/references/reference-storage-upstash.md +0 -160
  402. package/dist/docs/references/reference-streaming-ChunkType.md +0 -292
  403. package/dist/docs/references/reference-streaming-agents-MastraModelOutput.md +0 -182
  404. package/dist/docs/references/reference-streaming-agents-streamLegacy.md +0 -142
  405. package/dist/docs/references/reference-streaming-workflows-observeStream.md +0 -42
  406. package/dist/docs/references/reference-streaming-workflows-resumeStream.md +0 -61
  407. package/dist/docs/references/reference-streaming-workflows-stream.md +0 -88
  408. package/dist/docs/references/reference-streaming-workflows-timeTravelStream.md +0 -142
  409. package/dist/docs/references/reference-templates-overview.md +0 -194
  410. package/dist/docs/references/reference-tools-create-tool.md +0 -237
  411. package/dist/docs/references/reference-tools-graph-rag-tool.md +0 -185
  412. package/dist/docs/references/reference-tools-mcp-client.md +0 -962
  413. package/dist/docs/references/reference-tools-mcp-server.md +0 -1275
  414. package/dist/docs/references/reference-tools-vector-query-tool.md +0 -459
  415. package/dist/docs/references/reference-vectors-libsql.md +0 -305
  416. package/dist/docs/references/reference-vectors-mongodb.md +0 -295
  417. package/dist/docs/references/reference-vectors-pg.md +0 -408
  418. package/dist/docs/references/reference-vectors-upstash.md +0 -294
  419. package/dist/docs/references/reference-voice-composite-voice.md +0 -121
  420. package/dist/docs/references/reference-voice-mastra-voice.md +0 -313
  421. package/dist/docs/references/reference-voice-voice.addInstructions.md +0 -56
  422. package/dist/docs/references/reference-voice-voice.addTools.md +0 -67
  423. package/dist/docs/references/reference-voice-voice.connect.md +0 -94
  424. package/dist/docs/references/reference-voice-voice.events.md +0 -37
  425. package/dist/docs/references/reference-voice-voice.listen.md +0 -164
  426. package/dist/docs/references/reference-voice-voice.on.md +0 -111
  427. package/dist/docs/references/reference-voice-voice.speak.md +0 -157
  428. package/dist/docs/references/reference-workflows-run-methods-cancel.md +0 -86
  429. package/dist/docs/references/reference-workflows-run-methods-restart.md +0 -33
  430. package/dist/docs/references/reference-workflows-run-methods-resume.md +0 -59
  431. package/dist/docs/references/reference-workflows-run-methods-start.md +0 -58
  432. package/dist/docs/references/reference-workflows-run-methods-startAsync.md +0 -67
  433. package/dist/docs/references/reference-workflows-run-methods-timeTravel.md +0 -142
  434. package/dist/docs/references/reference-workflows-run.md +0 -59
  435. package/dist/docs/references/reference-workflows-step.md +0 -119
  436. package/dist/docs/references/reference-workflows-workflow-methods-branch.md +0 -25
  437. package/dist/docs/references/reference-workflows-workflow-methods-commit.md +0 -17
  438. package/dist/docs/references/reference-workflows-workflow-methods-create-run.md +0 -63
  439. package/dist/docs/references/reference-workflows-workflow-methods-dountil.md +0 -25
  440. package/dist/docs/references/reference-workflows-workflow-methods-dowhile.md +0 -25
  441. package/dist/docs/references/reference-workflows-workflow-methods-foreach.md +0 -118
  442. package/dist/docs/references/reference-workflows-workflow-methods-map.md +0 -93
  443. package/dist/docs/references/reference-workflows-workflow-methods-parallel.md +0 -21
  444. package/dist/docs/references/reference-workflows-workflow-methods-sleep.md +0 -35
  445. package/dist/docs/references/reference-workflows-workflow-methods-sleepUntil.md +0 -35
  446. package/dist/docs/references/reference-workflows-workflow-methods-then.md +0 -21
  447. package/dist/docs/references/reference-workflows-workflow.md +0 -157
  448. package/dist/docs/references/reference-workspace-filesystem.md +0 -202
  449. package/dist/docs/references/reference-workspace-local-filesystem.md +0 -327
  450. package/dist/docs/references/reference-workspace-local-sandbox.md +0 -285
  451. package/dist/docs/references/reference-workspace-sandbox.md +0 -81
  452. package/dist/docs/references/reference-workspace-workspace-class.md +0 -226
  453. package/dist/docs/references/reference.md +0 -276
@@ -9,10 +9,11 @@ import picomatch from 'picomatch';
9
9
  import * as crypto from 'crypto';
10
10
  import { createHash } from 'crypto';
11
11
  import matter from 'gray-matter';
12
- import * as childProcess from 'child_process';
13
- import { execFileSync } from 'child_process';
14
12
  import * as os from 'os';
15
13
  import os__default from 'os';
14
+ import * as childProcess from 'child_process';
15
+ import { execFileSync } from 'child_process';
16
+ import { Readable, Writable } from 'stream';
16
17
  import { createRequire } from 'module';
17
18
  import { z } from 'zod';
18
19
 
@@ -450,13 +451,13 @@ var CompositeFilesystem = class {
450
451
  * Get instructions describing the mounted filesystems.
451
452
  * Used by agents to understand available storage locations.
452
453
  */
453
- getInstructions() {
454
+ getInstructions(_opts) {
454
455
  const mountDescriptions = Array.from(this._mounts.entries()).map(([mountPath, fs5]) => {
455
456
  const name = fs5.displayName || fs5.provider;
456
457
  const access2 = fs5.readOnly ? "(read-only)" : "(read-write)";
457
458
  return `- ${mountPath}: ${name} ${access2}`;
458
459
  }).join("\n");
459
- return `Mounted filesystems:
460
+ return `Filesystem mount points:
460
461
  ${mountDescriptions}`;
461
462
  }
462
463
  };
@@ -628,6 +629,14 @@ var MastraFilesystem = class extends MastraBase {
628
629
  async destroy() {
629
630
  }
630
631
  };
632
+
633
+ // src/workspace/utils.ts
634
+ function resolveInstructions(override, getDefault, requestContext) {
635
+ if (typeof override === "string") return override;
636
+ const defaultInstructions = getDefault();
637
+ if (override === void 0) return defaultInstructions;
638
+ return override({ defaultInstructions, requestContext });
639
+ }
631
640
  function isEnoentError(error) {
632
641
  return error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT";
633
642
  }
@@ -768,6 +777,7 @@ var LocalFilesystem = class extends MastraFilesystem {
768
777
  _basePath;
769
778
  _contained;
770
779
  _allowedPaths;
780
+ _instructionsOverride;
771
781
  /**
772
782
  * The absolute base path on disk where files are stored.
773
783
  * Useful for understanding how workspace paths map to disk paths.
@@ -806,6 +816,7 @@ var LocalFilesystem = class extends MastraFilesystem {
806
816
  this._contained = options.contained ?? true;
807
817
  this.readOnly = options.readOnly;
808
818
  this._allowedPaths = (options.allowedPaths ?? []).map((p) => nodePath.resolve(p));
819
+ this._instructionsOverride = options.instructions;
809
820
  }
810
821
  generateId() {
811
822
  return `local-fs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
@@ -1268,7 +1279,10 @@ var LocalFilesystem = class extends MastraFilesystem {
1268
1279
  }
1269
1280
  };
1270
1281
  }
1271
- getInstructions() {
1282
+ getInstructions(opts) {
1283
+ return resolveInstructions(this._instructionsOverride, () => this._getDefaultInstructions(), opts?.requestContext);
1284
+ }
1285
+ _getDefaultInstructions() {
1272
1286
  const allowedNote = this._allowedPaths.length > 0 ? ` Additionally, the following paths outside basePath are accessible: ${this._allowedPaths.join(", ")}.` : "";
1273
1287
  if (this._contained) {
1274
1288
  return `Local filesystem at "${this.basePath}". Files at workspace path "/foo" are stored at "${this.basePath}/foo" on disk.${allowedNote}`;
@@ -1316,6 +1330,57 @@ var InMemoryFileReadTracker = class {
1316
1330
  return normalized.replace(/\/$/, "") || "/";
1317
1331
  }
1318
1332
  };
1333
+ var InMemoryFileWriteLock = class {
1334
+ queues = /* @__PURE__ */ new Map();
1335
+ timeoutMs;
1336
+ constructor(opts) {
1337
+ this.timeoutMs = opts?.timeoutMs ?? 3e4;
1338
+ }
1339
+ get size() {
1340
+ return this.queues.size;
1341
+ }
1342
+ withLock(filePath, fn) {
1343
+ const key = this.normalizePath(filePath);
1344
+ const currentQueue = this.queues.get(key) ?? Promise.resolve();
1345
+ let resolve3;
1346
+ let reject;
1347
+ const resultPromise = new Promise((res, rej) => {
1348
+ resolve3 = res;
1349
+ reject = rej;
1350
+ });
1351
+ const queuePromise = currentQueue.catch(() => {
1352
+ }).then(async () => {
1353
+ let timeoutId;
1354
+ try {
1355
+ const result = await Promise.race([
1356
+ fn(),
1357
+ new Promise((_, rej) => {
1358
+ timeoutId = setTimeout(
1359
+ () => rej(new Error(`write-lock timeout on "${key}" after ${this.timeoutMs}ms`)),
1360
+ this.timeoutMs
1361
+ );
1362
+ })
1363
+ ]);
1364
+ clearTimeout(timeoutId);
1365
+ resolve3(result);
1366
+ } catch (error) {
1367
+ clearTimeout(timeoutId);
1368
+ reject(error);
1369
+ }
1370
+ });
1371
+ this.queues.set(key, queuePromise);
1372
+ void queuePromise.finally(() => {
1373
+ if (this.queues.get(key) === queuePromise) {
1374
+ this.queues.delete(key);
1375
+ }
1376
+ });
1377
+ return resultPromise;
1378
+ }
1379
+ normalizePath(pathStr) {
1380
+ const normalized = nodePath.posix.normalize(pathStr.replace(/\\/g, "/").replace(/^\/\/+/, "/"));
1381
+ return normalized.replace(/\/+$/, "") || "/";
1382
+ }
1383
+ };
1319
1384
  var GLOB_CHARS = /[*?{}[\]]/;
1320
1385
  function isGlobPattern(input) {
1321
1386
  return GLOB_CHARS.test(input);
@@ -1695,8 +1760,16 @@ var MountManager = class {
1695
1760
  }
1696
1761
  };
1697
1762
 
1763
+ // src/workspace/sandbox/utils.ts
1764
+ function shellQuote(arg) {
1765
+ if (/^[a-zA-Z0-9._\-\/=:@]+$/.test(arg)) return arg;
1766
+ return `'${arg.replace(/'/g, "'\\''")}'`;
1767
+ }
1768
+
1698
1769
  // src/workspace/sandbox/mastra-sandbox.ts
1699
1770
  var MastraSandbox = class extends MastraBase {
1771
+ /** Process manager */
1772
+ processes;
1700
1773
  /** Mount manager - automatically created if subclass implements mount() */
1701
1774
  mounts;
1702
1775
  // ---------------------------------------------------------------------------
@@ -1723,6 +1796,21 @@ var MastraSandbox = class extends MastraBase {
1723
1796
  logger: this.logger
1724
1797
  });
1725
1798
  }
1799
+ if (options.processes) {
1800
+ const pm = options.processes;
1801
+ pm.sandbox = this;
1802
+ this.processes = pm;
1803
+ if (!this.executeCommand) {
1804
+ this.executeCommand = async (command, args, opts) => {
1805
+ const fullCommand = args?.length ? `${command} ${args.map((a) => shellQuote(a)).join(" ")}` : command;
1806
+ this.logger.debug(`[${this.name}] Executing: ${fullCommand}`, { cwd: opts?.cwd });
1807
+ const handle = await pm.spawn(fullCommand, opts ?? {});
1808
+ const result = await handle.wait();
1809
+ this.logger.debug(`[${this.name}] Exit code: ${result.exitCode} (${result.executionTimeMs}ms)`);
1810
+ return { ...result, command: fullCommand };
1811
+ };
1812
+ }
1813
+ }
1726
1814
  }
1727
1815
  // ---------------------------------------------------------------------------
1728
1816
  // Lifecycle Wrappers (race-condition-safe)
@@ -1809,6 +1897,12 @@ var MastraSandbox = class extends MastraBase {
1809
1897
  * ```
1810
1898
  */
1811
1899
  async ensureRunning() {
1900
+ if (this.status === "destroyed") {
1901
+ throw new SandboxNotReadyError(this.id);
1902
+ }
1903
+ if (this.status === "destroying" || this.status === "stopping") {
1904
+ return;
1905
+ }
1812
1906
  if (this.status !== "running") {
1813
1907
  await this._start();
1814
1908
  }
@@ -1874,6 +1968,10 @@ var MastraSandbox = class extends MastraBase {
1874
1968
  if (this.status === "destroyed") {
1875
1969
  return;
1876
1970
  }
1971
+ if (this.status === "pending") {
1972
+ this.status = "destroyed";
1973
+ return;
1974
+ }
1877
1975
  if (this._startPromise) await this._startPromise.catch(() => {
1878
1976
  });
1879
1977
  if (this._stopPromise) await this._stopPromise.catch(() => {
@@ -3959,6 +4057,25 @@ var Workspace = class {
3959
4057
  getToolsConfig() {
3960
4058
  return this._config.tools;
3961
4059
  }
4060
+ /**
4061
+ * Update the per-tool configuration for this workspace.
4062
+ * Takes effect on the next `createWorkspaceTools()` call.
4063
+ *
4064
+ * @example
4065
+ * ```typescript
4066
+ * // Disable write tools for read-only mode
4067
+ * workspace.setToolsConfig({
4068
+ * mastra_workspace_write_file: { enabled: false },
4069
+ * mastra_workspace_edit_file: { enabled: false },
4070
+ * });
4071
+ *
4072
+ * // Re-enable all tools
4073
+ * workspace.setToolsConfig(undefined);
4074
+ * ```
4075
+ */
4076
+ setToolsConfig(config) {
4077
+ this._config.tools = config;
4078
+ }
3962
4079
  /**
3963
4080
  * Access skills stored in this workspace.
3964
4081
  * Skills are SKILL.md files discovered from the configured skillPaths.
@@ -4197,10 +4314,58 @@ var Workspace = class {
4197
4314
  }
4198
4315
  return info;
4199
4316
  }
4317
+ /**
4318
+ * Get human-readable instructions describing the workspace environment.
4319
+ *
4320
+ * When both a sandbox with mounts and a filesystem exist, each mount path
4321
+ * is classified as sandbox-accessible (state === 'mounted') or
4322
+ * workspace-only (pending / mounting / error / unsupported). When there's
4323
+ * no sandbox or no mounts, falls back to provider-level instructions.
4324
+ *
4325
+ * @param opts - Optional options including request context for per-request customisation
4326
+ * @returns Combined instructions string (may be empty)
4327
+ */
4328
+ getInstructions(opts) {
4329
+ const parts = [];
4330
+ const sandboxInstructions = this._sandbox?.getInstructions?.(opts);
4331
+ if (sandboxInstructions) parts.push(sandboxInstructions);
4332
+ const mountEntries = this._sandbox?.mounts?.entries;
4333
+ if (mountEntries && mountEntries.size > 0) {
4334
+ const sandboxAccessible = [];
4335
+ const workspaceOnly = [];
4336
+ for (const [mountPath, entry] of mountEntries) {
4337
+ const fsName = entry.filesystem.displayName || entry.filesystem.provider;
4338
+ const access2 = entry.filesystem.readOnly ? "read-only" : "read-write";
4339
+ if (entry.state === "mounted") {
4340
+ sandboxAccessible.push(` - ${mountPath}: ${fsName} (${access2})`);
4341
+ } else {
4342
+ workspaceOnly.push(` - ${mountPath}: ${fsName} (${access2})`);
4343
+ }
4344
+ }
4345
+ if (sandboxAccessible.length) {
4346
+ parts.push(`Sandbox-mounted filesystems (accessible in shell commands):
4347
+ ${sandboxAccessible.join("\n")}`);
4348
+ }
4349
+ if (workspaceOnly.length) {
4350
+ parts.push(
4351
+ `Workspace-only filesystems (use file tools, NOT available in shell commands):
4352
+ ${workspaceOnly.join("\n")}`
4353
+ );
4354
+ }
4355
+ } else {
4356
+ const fsInstructions = this._fs?.getInstructions?.(opts);
4357
+ if (fsInstructions) parts.push(fsInstructions);
4358
+ }
4359
+ return parts.join("\n\n");
4360
+ }
4200
4361
  /**
4201
4362
  * Get information about how filesystem and sandbox paths relate.
4202
4363
  * Useful for understanding how to access workspace files from sandbox code.
4203
4364
  *
4365
+ * @deprecated Use {@link getInstructions} instead. `getInstructions()` is
4366
+ * mount-state-aware and feeds into the system message via
4367
+ * `WorkspaceInstructionsProcessor`.
4368
+ *
4204
4369
  * @returns PathContext with paths and instructions from providers
4205
4370
  */
4206
4371
  getPathContext() {
@@ -4236,6 +4401,274 @@ var Workspace = class {
4236
4401
  }
4237
4402
  }
4238
4403
  };
4404
+ var ProcessHandle = class {
4405
+ /** The command that was spawned (set by the process manager) */
4406
+ command;
4407
+ /**
4408
+ * Wait for the process to finish and return the result.
4409
+ *
4410
+ * Optionally pass `onStdout`/`onStderr` callbacks to stream output chunks
4411
+ * while waiting. The callbacks are automatically removed when `wait()`
4412
+ * resolves, so there's no cleanup needed by the caller.
4413
+ *
4414
+ * Subclasses implement `wait()` with platform-specific logic — the base
4415
+ * constructor wraps it to handle the optional streaming callbacks.
4416
+ */
4417
+ async wait(_options) {
4418
+ throw new Error(`${this.constructor.name} must implement wait()`);
4419
+ }
4420
+ _stdout = "";
4421
+ _stderr = "";
4422
+ _stdoutListeners = /* @__PURE__ */ new Set();
4423
+ _stderrListeners = /* @__PURE__ */ new Set();
4424
+ _reader;
4425
+ _writer;
4426
+ constructor(options) {
4427
+ if (options?.onStdout) this._stdoutListeners.add(options.onStdout);
4428
+ if (options?.onStderr) this._stderrListeners.add(options.onStderr);
4429
+ const implWait = this.wait.bind(this);
4430
+ this.wait = async (waitOptions) => {
4431
+ if (waitOptions?.onStdout) this._stdoutListeners.add(waitOptions.onStdout);
4432
+ if (waitOptions?.onStderr) this._stderrListeners.add(waitOptions.onStderr);
4433
+ try {
4434
+ return await implWait();
4435
+ } finally {
4436
+ if (waitOptions?.onStdout) this._stdoutListeners.delete(waitOptions.onStdout);
4437
+ if (waitOptions?.onStderr) this._stderrListeners.delete(waitOptions.onStderr);
4438
+ }
4439
+ };
4440
+ }
4441
+ /** Accumulated stdout so far */
4442
+ get stdout() {
4443
+ return this._stdout;
4444
+ }
4445
+ /** Accumulated stderr so far */
4446
+ get stderr() {
4447
+ return this._stderr;
4448
+ }
4449
+ /**
4450
+ * Emit stdout data — accumulates, dispatches to user callback, and pushes to reader stream.
4451
+ * @internal Called by subclasses and process managers to dispatch transport data.
4452
+ */
4453
+ emitStdout(data) {
4454
+ this._stdout += data;
4455
+ for (const listener of this._stdoutListeners) listener(data);
4456
+ this._reader?.push(data);
4457
+ }
4458
+ /**
4459
+ * Emit stderr data — accumulates and dispatches to user callback.
4460
+ * @internal Called by subclasses and process managers to dispatch transport data.
4461
+ */
4462
+ emitStderr(data) {
4463
+ this._stderr += data;
4464
+ for (const listener of this._stderrListeners) listener(data);
4465
+ }
4466
+ /** Readable stream of stdout (for use with StreamMessageReader, pipes, etc.) */
4467
+ get reader() {
4468
+ if (!this._reader) {
4469
+ this._reader = new Readable({ read() {
4470
+ } });
4471
+ void this.wait().then(
4472
+ () => this._reader.push(null),
4473
+ () => this._reader.push(null)
4474
+ );
4475
+ }
4476
+ return this._reader;
4477
+ }
4478
+ /** Writable stream to stdin (for use with StreamMessageWriter, pipes, etc.) */
4479
+ get writer() {
4480
+ if (!this._writer) {
4481
+ this._writer = new Writable({
4482
+ write: (chunk, _encoding, cb) => {
4483
+ this.sendStdin(chunk.toString()).then(() => cb(), cb);
4484
+ }
4485
+ });
4486
+ }
4487
+ return this._writer;
4488
+ }
4489
+ };
4490
+
4491
+ // src/workspace/sandbox/process-manager/process-manager.ts
4492
+ var SandboxProcessManager = class {
4493
+ /**
4494
+ * The sandbox this process manager belongs to.
4495
+ * Set automatically by MastraSandbox when processes are passed into the constructor.
4496
+ * @internal
4497
+ */
4498
+ sandbox;
4499
+ env;
4500
+ /** Tracked process handles keyed by PID. Populated by spawn(), used by get()/kill(). */
4501
+ _tracked = /* @__PURE__ */ new Map();
4502
+ /** PIDs that have been read after exit and should not be re-discovered by subclass fallbacks. */
4503
+ _dismissed = /* @__PURE__ */ new Set();
4504
+ constructor({ env = {} } = {}) {
4505
+ this.env = env;
4506
+ const impl = {
4507
+ spawn: this.spawn.bind(this),
4508
+ list: this.list.bind(this),
4509
+ get: this.get.bind(this)
4510
+ };
4511
+ this.spawn = async (...args) => {
4512
+ await this.sandbox.ensureRunning();
4513
+ const handle = await impl.spawn(...args);
4514
+ handle.command = args[0];
4515
+ return handle;
4516
+ };
4517
+ this.list = async () => {
4518
+ await this.sandbox.ensureRunning();
4519
+ return impl.list();
4520
+ };
4521
+ this.get = async (...args) => {
4522
+ await this.sandbox.ensureRunning();
4523
+ if (this._dismissed.has(args[0])) return void 0;
4524
+ const handle = await impl.get(...args);
4525
+ if (handle?.exitCode !== void 0) {
4526
+ this._tracked.delete(handle.pid);
4527
+ this._dismissed.add(handle.pid);
4528
+ }
4529
+ return handle;
4530
+ };
4531
+ }
4532
+ /** Spawn a process. */
4533
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4534
+ async spawn(command, options = {}) {
4535
+ throw new Error(`${this.constructor.name} must implement spawn()`);
4536
+ }
4537
+ /** List all tracked processes. */
4538
+ async list() {
4539
+ throw new Error(`${this.constructor.name} must implement list()`);
4540
+ }
4541
+ /** Get a handle to a process by PID. Subclasses can override for fallback behavior. */
4542
+ async get(pid) {
4543
+ return this._tracked.get(pid);
4544
+ }
4545
+ /** Kill a process by PID. Returns true if killed, false if not found. */
4546
+ async kill(pid) {
4547
+ const handle = await this.get(pid);
4548
+ if (!handle) return false;
4549
+ const killed = await handle.kill();
4550
+ if (killed) {
4551
+ await handle.wait().catch(() => {
4552
+ });
4553
+ }
4554
+ this._tracked.delete(pid);
4555
+ this._dismissed.add(pid);
4556
+ return killed;
4557
+ }
4558
+ };
4559
+
4560
+ // src/workspace/sandbox/local-process-manager.ts
4561
+ var LocalProcessHandle = class extends ProcessHandle {
4562
+ pid;
4563
+ exitCode;
4564
+ proc;
4565
+ waitPromise;
4566
+ startTime;
4567
+ constructor(proc, startTime, options) {
4568
+ super(options);
4569
+ if (!proc.pid) {
4570
+ throw new Error("Process has no PID - it may have failed to spawn");
4571
+ }
4572
+ this.pid = proc.pid;
4573
+ this.proc = proc;
4574
+ this.startTime = startTime;
4575
+ let timedOut = false;
4576
+ const timeoutId = options?.timeout ? setTimeout(() => {
4577
+ timedOut = true;
4578
+ try {
4579
+ process.kill(-this.pid, "SIGTERM");
4580
+ } catch {
4581
+ proc.kill("SIGTERM");
4582
+ }
4583
+ }, options.timeout) : void 0;
4584
+ this.waitPromise = new Promise((resolve3) => {
4585
+ proc.on("close", (code, signal) => {
4586
+ if (timeoutId) clearTimeout(timeoutId);
4587
+ if (timedOut) {
4588
+ const timeoutMsg = `
4589
+ Process timed out after ${options.timeout}ms`;
4590
+ this.emitStderr(timeoutMsg);
4591
+ this.exitCode = 124;
4592
+ } else {
4593
+ this.exitCode = signal && code === null ? 128 : code ?? 0;
4594
+ }
4595
+ resolve3({
4596
+ success: this.exitCode === 0,
4597
+ exitCode: this.exitCode,
4598
+ stdout: this.stdout,
4599
+ stderr: this.stderr,
4600
+ executionTimeMs: Date.now() - this.startTime,
4601
+ killed: signal !== null,
4602
+ timedOut
4603
+ });
4604
+ });
4605
+ proc.on("error", (err) => {
4606
+ if (timeoutId) clearTimeout(timeoutId);
4607
+ this.emitStderr(err.message);
4608
+ this.exitCode = 1;
4609
+ resolve3({
4610
+ success: false,
4611
+ exitCode: 1,
4612
+ stdout: this.stdout,
4613
+ stderr: this.stderr,
4614
+ executionTimeMs: Date.now() - this.startTime
4615
+ });
4616
+ });
4617
+ });
4618
+ proc.stdout?.on("data", (data) => {
4619
+ this.emitStdout(data.toString());
4620
+ });
4621
+ proc.stderr?.on("data", (data) => {
4622
+ this.emitStderr(data.toString());
4623
+ });
4624
+ }
4625
+ async wait() {
4626
+ return this.waitPromise;
4627
+ }
4628
+ async kill() {
4629
+ if (this.exitCode !== void 0) return false;
4630
+ try {
4631
+ process.kill(-this.pid, "SIGKILL");
4632
+ return true;
4633
+ } catch {
4634
+ return this.proc.kill("SIGKILL");
4635
+ }
4636
+ }
4637
+ async sendStdin(data) {
4638
+ if (this.exitCode !== void 0) {
4639
+ throw new Error(`Process ${this.pid} has already exited with code ${this.exitCode}`);
4640
+ }
4641
+ if (!this.proc.stdin) {
4642
+ throw new Error(`Process ${this.pid} does not have stdin available`);
4643
+ }
4644
+ return new Promise((resolve3, reject) => {
4645
+ this.proc.stdin.write(data, (err) => err ? reject(err) : resolve3());
4646
+ });
4647
+ }
4648
+ };
4649
+ var LocalProcessManager = class extends SandboxProcessManager {
4650
+ async spawn(command, options = {}) {
4651
+ const cwd = options.cwd ?? this.sandbox.workingDirectory;
4652
+ const env = this.sandbox.buildEnv(options.env);
4653
+ const wrapped = this.sandbox.wrapCommandForIsolation(command);
4654
+ const proc = childProcess.spawn(wrapped.command, wrapped.args, {
4655
+ cwd,
4656
+ env,
4657
+ shell: this.sandbox.isolation === "none",
4658
+ detached: true
4659
+ });
4660
+ const handle = new LocalProcessHandle(proc, Date.now(), options);
4661
+ this._tracked.set(handle.pid, handle);
4662
+ return handle;
4663
+ }
4664
+ async list() {
4665
+ return Array.from(this._tracked.values()).map((handle) => ({
4666
+ pid: handle.pid,
4667
+ running: handle.exitCode === void 0,
4668
+ exitCode: handle.exitCode
4669
+ }));
4670
+ }
4671
+ };
4239
4672
  function commandExists(command) {
4240
4673
  try {
4241
4674
  execFileSync("which", [command], { stdio: "ignore" });
@@ -4376,10 +4809,10 @@ function generateSeatbeltProfile(workspacePath, config) {
4376
4809
  }
4377
4810
  return lines.join("\n");
4378
4811
  }
4379
- function buildSeatbeltCommand(command, args, profile) {
4812
+ function buildSeatbeltCommand(command, profile) {
4380
4813
  return {
4381
4814
  command: "sandbox-exec",
4382
- args: ["-p", profile, command, ...args]
4815
+ args: ["-p", profile, "sh", "-c", command]
4383
4816
  };
4384
4817
  }
4385
4818
 
@@ -4401,11 +4834,11 @@ var DEFAULT_READONLY_BINDS = [
4401
4834
  "/etc/ld.so.cache",
4402
4835
  "/etc/localtime"
4403
4836
  ];
4404
- function buildBwrapCommand(command, args, workspacePath, config) {
4837
+ function buildBwrapCommand(command, workspacePath, config) {
4405
4838
  if (config.bwrapArgs && config.bwrapArgs.length > 0) {
4406
4839
  return {
4407
4840
  command: "bwrap",
4408
- args: [...config.bwrapArgs, "--", command, ...args]
4841
+ args: [...config.bwrapArgs, "--", "sh", "-c", command]
4409
4842
  };
4410
4843
  }
4411
4844
  const bwrapArgs = [];
@@ -4424,8 +4857,8 @@ function buildBwrapCommand(command, args, workspacePath, config) {
4424
4857
  bwrapArgs.push("--ro-bind", path4, path4);
4425
4858
  }
4426
4859
  if (config.allowSystemBinaries !== false) {
4427
- const nodePath3 = process.execPath;
4428
- const nodeDir = nodePath3.substring(0, nodePath3.lastIndexOf("/"));
4860
+ const nodePath4 = process.execPath;
4861
+ const nodeDir = nodePath4.substring(0, nodePath4.lastIndexOf("/"));
4429
4862
  if (!DEFAULT_READONLY_BINDS.some((p) => nodeDir.startsWith(p))) {
4430
4863
  bwrapArgs.push("--ro-bind", nodeDir, nodeDir);
4431
4864
  }
@@ -4438,7 +4871,7 @@ function buildBwrapCommand(command, args, workspacePath, config) {
4438
4871
  }
4439
4872
  bwrapArgs.push("--chdir", workspacePath);
4440
4873
  bwrapArgs.push("--die-with-parent");
4441
- bwrapArgs.push("--", command, ...args);
4874
+ bwrapArgs.push("--", "sh", "-c", command);
4442
4875
  return {
4443
4876
  command: "bwrap",
4444
4877
  args: bwrapArgs
@@ -4446,141 +4879,59 @@ function buildBwrapCommand(command, args, workspacePath, config) {
4446
4879
  }
4447
4880
 
4448
4881
  // src/workspace/sandbox/native-sandbox/wrapper.ts
4449
- function wrapCommand(command, args, options) {
4882
+ function wrapCommand(command, options) {
4450
4883
  switch (options.backend) {
4451
4884
  case "seatbelt": {
4452
4885
  const profile = options.seatbeltProfile ?? generateSeatbeltProfile(options.workspacePath, options.config);
4453
- return buildSeatbeltCommand(command, args, profile);
4886
+ return buildSeatbeltCommand(command, profile);
4454
4887
  }
4455
4888
  case "bwrap": {
4456
- return buildBwrapCommand(command, args, options.workspacePath, options.config);
4889
+ return buildBwrapCommand(command, options.workspacePath, options.config);
4457
4890
  }
4458
4891
  case "none":
4459
4892
  default:
4460
- return { command, args };
4893
+ return { command, args: [] };
4461
4894
  }
4462
4895
  }
4463
4896
 
4464
4897
  // src/workspace/sandbox/local-sandbox.ts
4465
- function execWithStreaming(command, args, options) {
4466
- const { timeout, onStdout, onStderr, cwd, env, ...spawnOptions } = options;
4467
- return new Promise((resolve3, reject) => {
4468
- const proc = childProcess.spawn(command, args, { cwd, env, ...spawnOptions });
4469
- let stdout = "";
4470
- let stderr = "";
4471
- let killed = false;
4472
- const timeoutId = timeout ? setTimeout(() => {
4473
- killed = true;
4474
- proc.kill("SIGTERM");
4475
- }, timeout) : void 0;
4476
- proc.stdout.on("data", (data) => {
4477
- const str = data.toString();
4478
- stdout += str;
4479
- onStdout?.(str);
4480
- });
4481
- proc.stderr.on("data", (data) => {
4482
- const str = data.toString();
4483
- stderr += str;
4484
- onStderr?.(str);
4485
- });
4486
- proc.on("error", (err) => {
4487
- if (timeoutId) clearTimeout(timeoutId);
4488
- const errorMsg = err.message;
4489
- stderr += errorMsg;
4490
- onStderr?.(errorMsg);
4491
- reject(err);
4492
- });
4493
- proc.on("close", (code, signal) => {
4494
- if (timeoutId) clearTimeout(timeoutId);
4495
- if (killed) {
4496
- const timeoutMsg = `
4497
- Process timed out after ${timeout}ms`;
4498
- onStderr?.(timeoutMsg);
4499
- resolve3({ stdout, stderr: stderr + timeoutMsg, exitCode: 124 });
4500
- } else if (signal) {
4501
- const signalMsg = `
4502
- Process terminated by ${signal}`;
4503
- onStderr?.(signalMsg);
4504
- resolve3({ stdout, stderr: stderr + signalMsg, exitCode: 128 });
4505
- } else {
4506
- resolve3({ stdout, stderr, exitCode: code ?? 0 });
4507
- }
4508
- });
4509
- });
4510
- }
4511
4898
  var LocalSandbox = class extends MastraSandbox {
4512
4899
  id;
4513
4900
  name = "LocalSandbox";
4514
4901
  provider = "local";
4515
4902
  status = "pending";
4516
- _workingDirectory;
4903
+ workingDirectory;
4904
+ isolation;
4517
4905
  env;
4518
- timeout;
4519
- _isolation;
4520
4906
  _nativeSandboxConfig;
4521
4907
  _seatbeltProfile;
4522
4908
  _seatbeltProfilePath;
4523
4909
  _sandboxFolderPath;
4524
4910
  _userProvidedProfilePath = false;
4525
4911
  _createdAt;
4526
- /**
4527
- * The working directory where commands are executed.
4528
- */
4529
- get workingDirectory() {
4530
- return this._workingDirectory;
4531
- }
4532
- /**
4533
- * The isolation backend being used.
4534
- */
4535
- get isolation() {
4536
- return this._isolation;
4537
- }
4538
- /**
4539
- * Detect the best available isolation backend for this platform.
4540
- * Returns detection result with backend recommendation and availability.
4541
- *
4542
- * @example
4543
- * ```typescript
4544
- * const result = LocalSandbox.detectIsolation();
4545
- * const sandbox = new LocalSandbox({
4546
- * isolation: result.available ? result.backend : 'none',
4547
- * });
4548
- * ```
4549
- */
4550
- static detectIsolation() {
4551
- return detectIsolation();
4552
- }
4912
+ _instructionsOverride;
4553
4913
  constructor(options = {}) {
4554
- super({ ...options, name: "LocalSandbox" });
4555
- this.id = options.id ?? this.generateId();
4556
- this._createdAt = /* @__PURE__ */ new Date();
4557
- this._workingDirectory = options.workingDirectory ?? nodePath.join(process.cwd(), ".sandbox");
4558
- this.env = options.env ?? {};
4559
- this.timeout = options.timeout;
4560
- this._nativeSandboxConfig = options.nativeSandbox ?? {};
4561
4914
  const requestedIsolation = options.isolation ?? "none";
4562
4915
  if (requestedIsolation !== "none" && !isIsolationAvailable(requestedIsolation)) {
4563
4916
  const detection = detectIsolation();
4564
4917
  throw new IsolationUnavailableError(requestedIsolation, detection.message);
4565
4918
  }
4566
- this._isolation = requestedIsolation;
4567
- }
4568
- generateId() {
4569
- return `local-sandbox-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
4570
- }
4571
- /**
4572
- * Build the environment object for execution.
4573
- * Always includes PATH by default (needed for finding executables).
4574
- * Merges the sandbox's configured env with any additional env from the command.
4575
- */
4576
- buildEnv(additionalEnv) {
4577
- return {
4578
- PATH: process.env.PATH,
4579
- // Always include PATH for finding executables
4580
- ...this.env,
4581
- ...additionalEnv
4582
- };
4919
+ super({
4920
+ ...options,
4921
+ name: "LocalSandbox",
4922
+ processes: new LocalProcessManager({ env: options.env ?? {} })
4923
+ });
4924
+ this.id = options.id ?? this.generateId();
4925
+ this._createdAt = /* @__PURE__ */ new Date();
4926
+ this.workingDirectory = options.workingDirectory ?? nodePath.join(process.cwd(), ".sandbox");
4927
+ this.env = options.env ?? {};
4928
+ this._nativeSandboxConfig = options.nativeSandbox ?? {};
4929
+ this.isolation = requestedIsolation;
4930
+ this._instructionsOverride = options.instructions;
4583
4931
  }
4932
+ // ---------------------------------------------------------------------------
4933
+ // Lifecycle
4934
+ // ---------------------------------------------------------------------------
4584
4935
  /**
4585
4936
  * Start the local sandbox.
4586
4937
  * Creates working directory and sets up seatbelt profile if using macOS isolation.
@@ -4588,11 +4939,11 @@ var LocalSandbox = class extends MastraSandbox {
4588
4939
  */
4589
4940
  async start() {
4590
4941
  this.logger.debug("[LocalSandbox] Starting sandbox", {
4591
- workingDirectory: this._workingDirectory,
4592
- isolation: this._isolation
4942
+ workingDirectory: this.workingDirectory,
4943
+ isolation: this.isolation
4593
4944
  });
4594
4945
  await fs2.mkdir(this.workingDirectory, { recursive: true });
4595
- if (this._isolation === "seatbelt") {
4946
+ if (this.isolation === "seatbelt") {
4596
4947
  const userProvidedPath = this._nativeSandboxConfig.seatbeltProfilePath;
4597
4948
  if (userProvidedPath) {
4598
4949
  this._seatbeltProfilePath = userProvidedPath;
@@ -4616,14 +4967,14 @@ var LocalSandbox = class extends MastraSandbox {
4616
4967
  await fs2.writeFile(this._seatbeltProfilePath, this._seatbeltProfile, "utf-8");
4617
4968
  }
4618
4969
  }
4619
- this.logger.debug("[LocalSandbox] Sandbox started", { workingDirectory: this._workingDirectory });
4970
+ this.logger.debug("[LocalSandbox] Sandbox started", { workingDirectory: this.workingDirectory });
4620
4971
  }
4621
4972
  /**
4622
4973
  * Stop the local sandbox.
4623
4974
  * Status management is handled by the base class.
4624
4975
  */
4625
4976
  async stop() {
4626
- this.logger.debug("[LocalSandbox] Stopping sandbox", { workingDirectory: this._workingDirectory });
4977
+ this.logger.debug("[LocalSandbox] Stopping sandbox", { workingDirectory: this.workingDirectory });
4627
4978
  }
4628
4979
  /**
4629
4980
  * Destroy the local sandbox and clean up resources.
@@ -4631,7 +4982,9 @@ var LocalSandbox = class extends MastraSandbox {
4631
4982
  * Status management is handled by the base class.
4632
4983
  */
4633
4984
  async destroy() {
4634
- this.logger.debug("[LocalSandbox] Destroying sandbox", { workingDirectory: this._workingDirectory });
4985
+ this.logger.debug("[LocalSandbox] Destroying sandbox", { workingDirectory: this.workingDirectory });
4986
+ const procs = await this.processes.list();
4987
+ await Promise.all(procs.map((p) => this.processes.kill(p.pid)));
4635
4988
  if (this._seatbeltProfilePath && !this._userProvidedProfilePath) {
4636
4989
  try {
4637
4990
  await fs2.unlink(this._seatbeltProfilePath);
@@ -4649,6 +5002,7 @@ var LocalSandbox = class extends MastraSandbox {
4649
5002
  this._sandboxFolderPath = void 0;
4650
5003
  }
4651
5004
  }
5005
+ /** @deprecated Use `status === 'running'` instead. */
4652
5006
  async isReady() {
4653
5007
  return this.status === "running";
4654
5008
  }
@@ -4667,8 +5021,8 @@ var LocalSandbox = class extends MastraSandbox {
4667
5021
  workingDirectory: this.workingDirectory,
4668
5022
  platform: os.platform(),
4669
5023
  nodeVersion: process.version,
4670
- isolation: this._isolation,
4671
- isolationConfig: this._isolation !== "none" ? {
5024
+ isolation: this.isolation,
5025
+ isolationConfig: this.isolation !== "none" ? {
4672
5026
  allowNetwork: this._nativeSandboxConfig.allowNetwork ?? false,
4673
5027
  readOnlyPaths: this._nativeSandboxConfig.readOnlyPaths,
4674
5028
  readWritePaths: this._nativeSandboxConfig.readWritePaths
@@ -4676,63 +5030,61 @@ var LocalSandbox = class extends MastraSandbox {
4676
5030
  }
4677
5031
  };
4678
5032
  }
4679
- getInstructions() {
4680
- if (this.workingDirectory) {
4681
- return `Local command execution. Working directory: "${this.workingDirectory}".`;
4682
- }
4683
- return "Local command execution on the host machine.";
5033
+ getInstructions(opts) {
5034
+ return resolveInstructions(this._instructionsOverride, () => this._getDefaultInstructions(), opts?.requestContext);
5035
+ }
5036
+ _getDefaultInstructions() {
5037
+ return `Local command execution. Working directory: "${this.workingDirectory}".`;
5038
+ }
5039
+ // ---------------------------------------------------------------------------
5040
+ // Internal Utils
5041
+ // ---------------------------------------------------------------------------
5042
+ generateId() {
5043
+ return `local-sandbox-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
5044
+ }
5045
+ /**
5046
+ * Build the environment object for execution.
5047
+ * Always includes PATH by default (needed for finding executables).
5048
+ * Merges the sandbox's configured env with any additional env from the command.
5049
+ * @internal Used by LocalProcessManager.
5050
+ */
5051
+ buildEnv(additionalEnv) {
5052
+ return {
5053
+ PATH: process.env.PATH,
5054
+ // Always include PATH for finding executables
5055
+ ...this.env,
5056
+ ...additionalEnv
5057
+ };
4684
5058
  }
4685
5059
  /**
4686
5060
  * Wrap a command with the configured isolation backend.
5061
+ * @internal Used by LocalProcessManager for background process isolation.
4687
5062
  */
4688
- wrapCommandForIsolation(command, args) {
4689
- if (this._isolation === "none") {
4690
- return { command, args };
5063
+ wrapCommandForIsolation(command) {
5064
+ if (this.isolation === "none") {
5065
+ return { command, args: [] };
4691
5066
  }
4692
- return wrapCommand(command, args, {
4693
- backend: this._isolation,
5067
+ return wrapCommand(command, {
5068
+ backend: this.isolation,
4694
5069
  workspacePath: this.workingDirectory,
4695
5070
  seatbeltProfile: this._seatbeltProfile,
4696
5071
  config: this._nativeSandboxConfig
4697
5072
  });
4698
5073
  }
4699
- async executeCommand(command, args = [], options = {}) {
4700
- this.logger.debug("[LocalSandbox] Executing command", { command, args, cwd: options.cwd ?? this.workingDirectory });
4701
- await this.ensureRunning();
4702
- const startTime = Date.now();
4703
- const wrapped = this.wrapCommandForIsolation(command, args);
4704
- try {
4705
- const result = await execWithStreaming(wrapped.command, wrapped.args, {
4706
- cwd: options.cwd ?? this.workingDirectory,
4707
- timeout: options.timeout ?? this.timeout ?? 3e4,
4708
- env: this.buildEnv(options.env),
4709
- onStdout: options.onStdout,
4710
- onStderr: options.onStderr
4711
- });
4712
- const commandResult = {
4713
- success: result.exitCode === 0,
4714
- stdout: result.stdout,
4715
- stderr: result.stderr,
4716
- exitCode: result.exitCode,
4717
- executionTimeMs: Date.now() - startTime
4718
- };
4719
- this.logger.debug("[LocalSandbox] Command completed", {
4720
- command,
4721
- exitCode: commandResult.exitCode,
4722
- executionTimeMs: commandResult.executionTimeMs
4723
- });
4724
- return commandResult;
4725
- } catch (error) {
4726
- const executionTimeMs = Date.now() - startTime;
4727
- this.logger.error("[LocalSandbox] Command failed", { command, error, executionTimeMs });
4728
- return {
4729
- success: false,
4730
- stdout: "",
4731
- stderr: error instanceof Error ? error.message : String(error),
4732
- exitCode: 1,
4733
- executionTimeMs
4734
- };
4735
- }
5074
+ /**
5075
+ * Detect the best available isolation backend for this platform.
5076
+ * Returns detection result with backend recommendation and availability.
5077
+ *
5078
+ * @example
5079
+ * ```typescript
5080
+ * const result = LocalSandbox.detectIsolation();
5081
+ * const sandbox = new LocalSandbox({
5082
+ * isolation: result.available ? result.backend : 'none',
5083
+ * });
5084
+ * ```
5085
+ */
5086
+ static detectIsolation() {
5087
+ return detectIsolation();
4736
5088
  }
4737
5089
  };
4738
5090
 
@@ -4751,7 +5103,9 @@ var WORKSPACE_TOOLS = {
4751
5103
  AST_EDIT: `${WORKSPACE_TOOLS_PREFIX}_ast_edit`
4752
5104
  },
4753
5105
  SANDBOX: {
4754
- EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command`
5106
+ EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command`,
5107
+ GET_PROCESS_OUTPUT: `${WORKSPACE_TOOLS_PREFIX}_get_process_output`,
5108
+ KILL_PROCESS: `${WORKSPACE_TOOLS_PREFIX}_kill_process`
4755
5109
  },
4756
5110
  SEARCH: {
4757
5111
  SEARCH: `${WORKSPACE_TOOLS_PREFIX}_search`,
@@ -5164,81 +5518,144 @@ Usage:
5164
5518
  }
5165
5519
  }
5166
5520
  });
5167
- var executeCommandTool = createTool({
5168
- id: WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND,
5169
- description: `Execute a shell command in the workspace sandbox.
5170
5521
 
5171
- Usage:
5172
- - Verify parent directories exist before running commands that create files or directories.
5173
- - Always quote file paths that contain spaces (e.g., cd "/path/with spaces").
5174
- - Use the timeout parameter to limit execution time. Behavior when omitted depends on the sandbox provider.
5175
- - Optionally use cwd to override the working directory. Commands run from the sandbox default if omitted.`,
5176
- inputSchema: z.object({
5177
- command: z.string().describe('The command to execute (e.g., "ls", "npm", "python")'),
5178
- args: z.array(z.string()).nullish().default([]).describe("Arguments to pass to the command"),
5179
- timeout: z.number().nullish().describe("Maximum execution time in milliseconds. Example: 60000 for 1 minute."),
5180
- cwd: z.string().nullish().describe("Working directory for the command")
5181
- }),
5182
- execute: async ({ command, args, timeout, cwd }, context) => {
5183
- const { sandbox } = requireSandbox(context);
5184
- if (!sandbox.executeCommand) {
5185
- throw new SandboxFeatureNotSupportedError("executeCommand");
5522
+ // src/workspace/tools/output-helpers.ts
5523
+ var DEFAULT_TAIL_LINES = 200;
5524
+ var MAX_OUTPUT_CHARS = 3e4;
5525
+ function applyTail(output, tail) {
5526
+ if (!output) return output;
5527
+ const n = Math.abs(tail ?? DEFAULT_TAIL_LINES);
5528
+ if (n === 0) return output;
5529
+ const trailingNewline = output.endsWith("\n");
5530
+ const lines = (trailingNewline ? output.slice(0, -1) : output).split("\n");
5531
+ if (lines.length <= n) return output;
5532
+ const sliced = lines.slice(-n).join("\n");
5533
+ const body = trailingNewline ? sliced + "\n" : sliced;
5534
+ return `[showing last ${n} of ${lines.length} lines]
5535
+ ${body}`;
5536
+ }
5537
+ function applyCharLimit(output, limit = MAX_OUTPUT_CHARS) {
5538
+ if (!output || output.length <= limit) return output;
5539
+ const truncated = output.slice(-limit);
5540
+ return `[output truncated: showing last ${limit} of ${output.length} characters]
5541
+ ${truncated}`;
5542
+ }
5543
+ function truncateOutput(output, tail, charLimit) {
5544
+ return applyCharLimit(applyTail(output, tail), charLimit);
5545
+ }
5546
+
5547
+ // src/workspace/tools/execute-command.ts
5548
+ var executeCommandInputSchema = z.object({
5549
+ command: z.string().describe('The shell command to execute (e.g., "npm install", "ls -la src/", "cat file.txt | grep error")'),
5550
+ timeout: z.number().nullish().describe("Maximum execution time in milliseconds. Example: 60000 for 1 minute."),
5551
+ cwd: z.string().nullish().describe("Working directory for the command"),
5552
+ tail: z.number().nullish().describe(
5553
+ `For foreground commands: limit output to the last N lines, similar to tail -n. Defaults to ${DEFAULT_TAIL_LINES}. Use 0 for no limit.`
5554
+ )
5555
+ });
5556
+ var executeCommandWithBackgroundSchema = executeCommandInputSchema.extend({
5557
+ background: z.boolean().optional().describe(
5558
+ "Run the command in the background. Returns a PID immediately instead of waiting for completion. Use get_process_output to check on it later."
5559
+ )
5560
+ });
5561
+ async function executeCommand(input, context) {
5562
+ const { command, timeout, cwd, tail } = input;
5563
+ const background = input.background;
5564
+ const { sandbox } = requireSandbox(context);
5565
+ await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND);
5566
+ const toolCallId = context?.agent?.toolCallId;
5567
+ if (background) {
5568
+ if (!sandbox.processes) {
5569
+ throw new SandboxFeatureNotSupportedError("processes");
5186
5570
  }
5187
- await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND);
5188
- const toolCallId = context?.agent?.toolCallId;
5189
- const startedAt = Date.now();
5190
- let stdout = "";
5191
- let stderr = "";
5192
- try {
5193
- const result = await sandbox.executeCommand(command, args ?? [], {
5194
- timeout: timeout ?? void 0,
5195
- cwd: cwd ?? void 0,
5196
- onStdout: async (data) => {
5197
- stdout += data;
5198
- await context?.writer?.custom({
5199
- type: "data-sandbox-stdout",
5200
- data: { output: data, timestamp: Date.now(), toolCallId }
5201
- });
5202
- },
5203
- onStderr: async (data) => {
5204
- stderr += data;
5205
- await context?.writer?.custom({
5206
- type: "data-sandbox-stderr",
5207
- data: { output: data, timestamp: Date.now(), toolCallId }
5208
- });
5209
- }
5210
- });
5211
- await context?.writer?.custom({
5212
- type: "data-sandbox-exit",
5213
- data: {
5214
- exitCode: result.exitCode,
5215
- success: result.success,
5216
- executionTimeMs: result.executionTimeMs,
5217
- toolCallId
5218
- }
5219
- });
5220
- if (!result.success) {
5221
- const parts = [result.stdout, result.stderr].filter(Boolean);
5222
- parts.push(`Exit code: ${result.exitCode}`);
5223
- return parts.join("\n");
5571
+ const handle = await sandbox.processes.spawn(command, {
5572
+ cwd: cwd ?? void 0,
5573
+ timeout: timeout ?? void 0
5574
+ });
5575
+ return `Started background process (PID: ${handle.pid})`;
5576
+ }
5577
+ if (!sandbox.executeCommand) {
5578
+ throw new SandboxFeatureNotSupportedError("executeCommand");
5579
+ }
5580
+ const startedAt = Date.now();
5581
+ let stdout = "";
5582
+ let stderr = "";
5583
+ try {
5584
+ const result = await sandbox.executeCommand(command, [], {
5585
+ timeout: timeout ?? void 0,
5586
+ cwd: cwd ?? void 0,
5587
+ onStdout: async (data) => {
5588
+ stdout += data;
5589
+ await context?.writer?.custom({
5590
+ type: "data-sandbox-stdout",
5591
+ data: { output: data, timestamp: Date.now(), toolCallId }
5592
+ });
5593
+ },
5594
+ onStderr: async (data) => {
5595
+ stderr += data;
5596
+ await context?.writer?.custom({
5597
+ type: "data-sandbox-stderr",
5598
+ data: { output: data, timestamp: Date.now(), toolCallId }
5599
+ });
5224
5600
  }
5225
- return result.stdout || "(no output)";
5226
- } catch (error) {
5227
- await context?.writer?.custom({
5228
- type: "data-sandbox-exit",
5229
- data: {
5230
- exitCode: -1,
5231
- success: false,
5232
- executionTimeMs: Date.now() - startedAt,
5233
- toolCallId
5234
- }
5235
- });
5236
- const parts = [stdout, stderr].filter(Boolean);
5237
- const errorMessage = error instanceof Error ? error.message : String(error);
5238
- parts.push(`Error: ${errorMessage}`);
5601
+ });
5602
+ await context?.writer?.custom({
5603
+ type: "data-sandbox-exit",
5604
+ data: {
5605
+ exitCode: result.exitCode,
5606
+ success: result.success,
5607
+ executionTimeMs: result.executionTimeMs,
5608
+ toolCallId
5609
+ }
5610
+ });
5611
+ if (!result.success) {
5612
+ const parts = [truncateOutput(result.stdout, tail), truncateOutput(result.stderr, tail)].filter(Boolean);
5613
+ parts.push(`Exit code: ${result.exitCode}`);
5239
5614
  return parts.join("\n");
5240
5615
  }
5616
+ return truncateOutput(result.stdout, tail) || "(no output)";
5617
+ } catch (error) {
5618
+ await context?.writer?.custom({
5619
+ type: "data-sandbox-exit",
5620
+ data: {
5621
+ exitCode: -1,
5622
+ success: false,
5623
+ executionTimeMs: Date.now() - startedAt,
5624
+ toolCallId
5625
+ }
5626
+ });
5627
+ const parts = [truncateOutput(stdout, tail), truncateOutput(stderr, tail)].filter(Boolean);
5628
+ const errorMessage = error instanceof Error ? error.message : String(error);
5629
+ parts.push(`Error: ${errorMessage}`);
5630
+ return parts.join("\n");
5241
5631
  }
5632
+ }
5633
+ var baseDescription = `Execute a shell command in the workspace sandbox.
5634
+
5635
+ Examples:
5636
+ "npm install && npm run build"
5637
+ "ls -la src/"
5638
+ "cat config.json | jq '.database'"
5639
+ "cd /app && python main.py"
5640
+
5641
+ Usage:
5642
+ - Commands run in a shell, so pipes, redirects, and chaining (&&, ||, ;) all work.
5643
+ - Always quote file paths that contain spaces (e.g., cd "/path/with spaces").
5644
+ - Use the timeout parameter to limit execution time. Behavior when omitted depends on the sandbox provider.
5645
+ - Optionally use cwd to override the working directory. Commands run from the sandbox default if omitted.`;
5646
+ var executeCommandTool = createTool({
5647
+ id: WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND,
5648
+ description: baseDescription,
5649
+ inputSchema: executeCommandInputSchema,
5650
+ execute: executeCommand
5651
+ });
5652
+ var executeCommandWithBackgroundTool = createTool({
5653
+ id: WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND,
5654
+ description: `${baseDescription}
5655
+
5656
+ Set background: true to run long-running commands (dev servers, watchers) without blocking. You'll get a PID to track the process.`,
5657
+ inputSchema: executeCommandWithBackgroundSchema,
5658
+ execute: executeCommand
5242
5659
  });
5243
5660
  var fileStatTool = createTool({
5244
5661
  id: WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT,
@@ -5264,6 +5681,82 @@ var fileStatTool = createTool({
5264
5681
  }
5265
5682
  }
5266
5683
  });
5684
+ var getProcessOutputTool = createTool({
5685
+ id: WORKSPACE_TOOLS.SANDBOX.GET_PROCESS_OUTPUT,
5686
+ description: `Get the current output (stdout, stderr) and status of a background process by its PID.
5687
+
5688
+ Use this after starting a background command with execute_command (background: true) to check if the process is still running and read its output.`,
5689
+ inputSchema: z.object({
5690
+ pid: z.number().describe("The process ID returned when the background command was started"),
5691
+ tail: z.number().optional().describe(
5692
+ `Number of lines to return, similar to tail -n. Positive or negative returns last N lines from end. Defaults to ${DEFAULT_TAIL_LINES}. Use 0 for no limit.`
5693
+ ),
5694
+ wait: z.boolean().optional().describe(
5695
+ "If true, block until the process exits and return the final output. Useful for short-lived background commands where you want to wait for the result."
5696
+ )
5697
+ }),
5698
+ execute: async ({ pid, tail, wait: shouldWait }, context) => {
5699
+ const { sandbox } = requireSandbox(context);
5700
+ if (!sandbox.processes) {
5701
+ throw new SandboxFeatureNotSupportedError("processes");
5702
+ }
5703
+ await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.GET_PROCESS_OUTPUT);
5704
+ const toolCallId = context?.agent?.toolCallId;
5705
+ const handle = await sandbox.processes.get(pid);
5706
+ if (!handle) {
5707
+ return `No background process found with PID ${pid}.`;
5708
+ }
5709
+ if (handle.command) {
5710
+ await context?.writer?.custom({
5711
+ type: "data-sandbox-command",
5712
+ data: { command: handle.command, pid, toolCallId }
5713
+ });
5714
+ }
5715
+ if (shouldWait && handle.exitCode === void 0) {
5716
+ const result = await handle.wait({
5717
+ onStdout: context?.writer ? async (data) => {
5718
+ await context.writer.custom({
5719
+ type: "data-sandbox-stdout",
5720
+ data: { output: data, timestamp: Date.now(), toolCallId }
5721
+ });
5722
+ } : void 0,
5723
+ onStderr: context?.writer ? async (data) => {
5724
+ await context.writer.custom({
5725
+ type: "data-sandbox-stderr",
5726
+ data: { output: data, timestamp: Date.now(), toolCallId }
5727
+ });
5728
+ } : void 0
5729
+ });
5730
+ await context?.writer?.custom({
5731
+ type: "data-sandbox-exit",
5732
+ data: {
5733
+ exitCode: result.exitCode,
5734
+ success: result.success,
5735
+ executionTimeMs: result.executionTimeMs,
5736
+ toolCallId
5737
+ }
5738
+ });
5739
+ }
5740
+ const running = handle.exitCode === void 0;
5741
+ const stdout = truncateOutput(handle.stdout, tail);
5742
+ const stderr = truncateOutput(handle.stderr, tail);
5743
+ if (!stdout && !stderr) {
5744
+ return "(no output yet)";
5745
+ }
5746
+ const parts = [];
5747
+ if (stdout && stderr) {
5748
+ parts.push("stdout:", stdout, "", "stderr:", stderr);
5749
+ } else if (stdout) {
5750
+ parts.push(stdout);
5751
+ } else {
5752
+ parts.push("stderr:", stderr);
5753
+ }
5754
+ if (!running) {
5755
+ parts.push("", `Exit code: ${handle.exitCode}`);
5756
+ }
5757
+ return parts.join("\n");
5758
+ }
5759
+ });
5267
5760
  var grepTool = createTool({
5268
5761
  id: WORKSPACE_TOOLS.FILESYSTEM.GREP,
5269
5762
  description: `Search file contents using a regex pattern. Walks the filesystem and returns matching lines with file paths and line numbers.
@@ -5420,6 +5913,55 @@ var indexContentTool = createTool({
5420
5913
  return `Indexed ${path4}`;
5421
5914
  }
5422
5915
  });
5916
+ var KILL_TAIL_LINES = 50;
5917
+ var killProcessTool = createTool({
5918
+ id: WORKSPACE_TOOLS.SANDBOX.KILL_PROCESS,
5919
+ description: `Kill a background process by its PID.
5920
+
5921
+ Use this to stop a long-running background process that was started with execute_command (background: true). Returns the last ${KILL_TAIL_LINES} lines of output.`,
5922
+ inputSchema: z.object({
5923
+ pid: z.number().describe("The process ID of the background process to kill")
5924
+ }),
5925
+ execute: async ({ pid }, context) => {
5926
+ const { sandbox } = requireSandbox(context);
5927
+ if (!sandbox.processes) {
5928
+ throw new SandboxFeatureNotSupportedError("processes");
5929
+ }
5930
+ await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.SANDBOX.KILL_PROCESS);
5931
+ const toolCallId = context?.agent?.toolCallId;
5932
+ const handle = await sandbox.processes.get(pid);
5933
+ if (handle?.command) {
5934
+ await context?.writer?.custom({
5935
+ type: "data-sandbox-command",
5936
+ data: { command: handle.command, pid, toolCallId }
5937
+ });
5938
+ }
5939
+ const killed = await sandbox.processes.kill(pid);
5940
+ if (!killed) {
5941
+ await context?.writer?.custom({
5942
+ type: "data-sandbox-exit",
5943
+ data: { exitCode: handle?.exitCode ?? -1, success: false, killed: false, toolCallId }
5944
+ });
5945
+ return `Process ${pid} was not found or had already exited.`;
5946
+ }
5947
+ await context?.writer?.custom({
5948
+ type: "data-sandbox-exit",
5949
+ data: { exitCode: handle?.exitCode ?? 137, success: false, killed: true, toolCallId }
5950
+ });
5951
+ const parts = [`Process ${pid} has been killed.`];
5952
+ if (handle) {
5953
+ const stdout = handle.stdout ? truncateOutput(handle.stdout, KILL_TAIL_LINES) : "";
5954
+ const stderr = handle.stderr ? truncateOutput(handle.stderr, KILL_TAIL_LINES) : "";
5955
+ if (stdout) {
5956
+ parts.push("", "--- stdout (last output) ---", stdout);
5957
+ }
5958
+ if (stderr) {
5959
+ parts.push("", "--- stderr (last output) ---", stderr);
5960
+ }
5961
+ }
5962
+ return parts.join("\n");
5963
+ }
5964
+ });
5423
5965
 
5424
5966
  // src/workspace/tools/tree-formatter.ts
5425
5967
  var BRANCH = "\u251C\u2500\u2500 ";
@@ -5754,10 +6296,22 @@ function wrapWithReadTracker(tool, workspace, readTracker, config, mode) {
5754
6296
  }
5755
6297
  };
5756
6298
  }
6299
+ function wrapWithWriteLock(tool, writeLock) {
6300
+ return {
6301
+ ...tool,
6302
+ execute: async (input, context = {}) => {
6303
+ if (!input.path) {
6304
+ throw new Error("wrapWithWriteLock: input.path is required");
6305
+ }
6306
+ return writeLock.withLock(input.path, () => tool.execute(input, context));
6307
+ }
6308
+ };
6309
+ }
5757
6310
  function createWorkspaceTools(workspace) {
5758
6311
  const tools = {};
5759
6312
  const toolsConfig = workspace.getToolsConfig();
5760
6313
  const isReadOnly = workspace.filesystem?.readOnly ?? false;
6314
+ const writeLock = new InMemoryFileWriteLock();
5761
6315
  let readTracker;
5762
6316
  const writeFileConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE);
5763
6317
  const editFileConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE);
@@ -5769,31 +6323,39 @@ function createWorkspaceTools(workspace) {
5769
6323
  const config = resolveToolConfig(toolsConfig, name);
5770
6324
  if (!config.enabled) return;
5771
6325
  if (opts?.requireWrite && isReadOnly) return;
6326
+ let wrapped;
5772
6327
  if (readTracker && opts?.readTrackerMode) {
5773
- tools[name] = wrapWithReadTracker(tool, workspace, readTracker, config, opts.readTrackerMode);
6328
+ wrapped = wrapWithReadTracker(tool, workspace, readTracker, config, opts.readTrackerMode);
5774
6329
  } else {
5775
- tools[name] = wrapTool(tool, workspace, config);
6330
+ wrapped = wrapTool(tool, workspace, config);
6331
+ }
6332
+ if (opts?.useWriteLock) {
6333
+ wrapped = wrapWithWriteLock(wrapped, writeLock);
5776
6334
  }
6335
+ tools[name] = wrapped;
5777
6336
  };
5778
6337
  if (workspace.filesystem) {
5779
6338
  addTool(WORKSPACE_TOOLS.FILESYSTEM.READ_FILE, readFileTool, { readTrackerMode: "read" });
5780
6339
  addTool(WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE, writeFileTool, {
5781
6340
  requireWrite: true,
5782
- readTrackerMode: "write"
6341
+ readTrackerMode: "write",
6342
+ useWriteLock: true
5783
6343
  });
5784
6344
  addTool(WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE, editFileTool, {
5785
6345
  requireWrite: true,
5786
- readTrackerMode: "write"
6346
+ readTrackerMode: "write",
6347
+ useWriteLock: true
5787
6348
  });
5788
6349
  addTool(WORKSPACE_TOOLS.FILESYSTEM.LIST_FILES, listFilesTool);
5789
- addTool(WORKSPACE_TOOLS.FILESYSTEM.DELETE, deleteFileTool, { requireWrite: true });
6350
+ addTool(WORKSPACE_TOOLS.FILESYSTEM.DELETE, deleteFileTool, { requireWrite: true, useWriteLock: true });
5790
6351
  addTool(WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT, fileStatTool);
5791
6352
  addTool(WORKSPACE_TOOLS.FILESYSTEM.MKDIR, mkdirTool, { requireWrite: true });
5792
6353
  addTool(WORKSPACE_TOOLS.FILESYSTEM.GREP, grepTool);
5793
6354
  if (isAstGrepAvailable()) {
5794
6355
  addTool(WORKSPACE_TOOLS.FILESYSTEM.AST_EDIT, astEditTool, {
5795
6356
  requireWrite: true,
5796
- readTrackerMode: "write"
6357
+ readTrackerMode: "write",
6358
+ useWriteLock: true
5797
6359
  });
5798
6360
  }
5799
6361
  }
@@ -5804,20 +6366,17 @@ function createWorkspaceTools(workspace) {
5804
6366
  if (workspace.sandbox) {
5805
6367
  const executeCommandConfig = resolveToolConfig(toolsConfig, WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND);
5806
6368
  if (workspace.sandbox.executeCommand && executeCommandConfig.enabled) {
5807
- const pathContext = workspace.getPathContext();
5808
- const pathInfo = pathContext.instructions ? `
5809
-
5810
- ${pathContext.instructions}` : "";
5811
- const description = pathInfo ? `${executeCommandTool.description}${pathInfo}` : executeCommandTool.description;
5812
- tools[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND] = {
5813
- ...wrapTool(executeCommandTool, workspace, executeCommandConfig),
5814
- description
5815
- };
6369
+ const baseTool = workspace.sandbox.processes ? executeCommandWithBackgroundTool : executeCommandTool;
6370
+ tools[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND] = wrapTool(baseTool, workspace, executeCommandConfig);
6371
+ }
6372
+ if (workspace.sandbox.processes) {
6373
+ addTool(WORKSPACE_TOOLS.SANDBOX.GET_PROCESS_OUTPUT, getProcessOutputTool);
6374
+ addTool(WORKSPACE_TOOLS.SANDBOX.KILL_PROCESS, killProcessTool);
5816
6375
  }
5817
6376
  }
5818
6377
  return tools;
5819
6378
  }
5820
6379
 
5821
- export { BM25Index, CompositeFilesystem, CompositeVersionedSkillSource, DirectoryNotEmptyError, DirectoryNotFoundError, FileExistsError, FileNotFoundError, FileReadRequiredError, FilesystemError, FilesystemNotAvailableError, FilesystemNotMountableError, FilesystemNotReadyError, IsDirectoryError, IsolationUnavailableError, LocalFilesystem, LocalSandbox, LocalSkillSource, MastraFilesystem, MastraSandbox, MountError, MountManager, MountNotSupportedError, NotDirectoryError, PermissionError, SandboxError, SandboxExecutionError, SandboxFeatureNotSupportedError, SandboxNotAvailableError, SandboxNotReadyError, SandboxTimeoutError, SearchNotAvailableError, VersionedSkillSource, WORKSPACE_TOOLS, WORKSPACE_TOOLS_PREFIX, Workspace, WorkspaceError, WorkspaceNotAvailableError, WorkspaceNotReadyError, WorkspaceReadOnlyError, callLifecycle, collectSkillForPublish, createGlobMatcher, createWorkspaceTools, deleteFileTool, detectIsolation, editFileTool, executeCommandTool, extractGlobBase, extractLines, fileStatTool, getRecommendedIsolation, indexContentTool, isGlobPattern, isIsolationAvailable, listFilesTool, matchGlob, mkdirTool, publishSkillFromSource, readFileTool, requireFilesystem, requireSandbox, requireWorkspace, resolveToolConfig, searchTool, writeFileTool };
5822
- //# sourceMappingURL=chunk-XB3DA67Q.js.map
5823
- //# sourceMappingURL=chunk-XB3DA67Q.js.map
6380
+ export { BM25Index, CompositeFilesystem, CompositeVersionedSkillSource, DirectoryNotEmptyError, DirectoryNotFoundError, FileExistsError, FileNotFoundError, FileReadRequiredError, FilesystemError, FilesystemNotAvailableError, FilesystemNotMountableError, FilesystemNotReadyError, IsDirectoryError, IsolationUnavailableError, LocalFilesystem, LocalSandbox, LocalSkillSource, MastraFilesystem, MastraSandbox, MountError, MountManager, MountNotSupportedError, NotDirectoryError, PermissionError, ProcessHandle, SandboxError, SandboxExecutionError, SandboxFeatureNotSupportedError, SandboxNotAvailableError, SandboxNotReadyError, SandboxProcessManager, SandboxTimeoutError, SearchNotAvailableError, VersionedSkillSource, WORKSPACE_TOOLS, WORKSPACE_TOOLS_PREFIX, Workspace, WorkspaceError, WorkspaceNotAvailableError, WorkspaceNotReadyError, WorkspaceReadOnlyError, callLifecycle, collectSkillForPublish, createGlobMatcher, createWorkspaceTools, deleteFileTool, detectIsolation, editFileTool, executeCommandTool, extractGlobBase, extractLines, fileStatTool, getRecommendedIsolation, indexContentTool, isGlobPattern, isIsolationAvailable, listFilesTool, matchGlob, mkdirTool, publishSkillFromSource, readFileTool, requireFilesystem, requireSandbox, requireWorkspace, resolveToolConfig, searchTool, writeFileTool };
6381
+ //# sourceMappingURL=chunk-ZSBM2SVU.js.map
6382
+ //# sourceMappingURL=chunk-ZSBM2SVU.js.map