@puku-ai/sdk 4.0.1 → 4.0.2

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 (582) hide show
  1. package/dist/index.d.ts +26 -0
  2. package/dist/index.js +32 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/vendor/_vendor/partial-json-parser/parser.d.ts +2 -0
  5. package/dist/vendor/_vendor/partial-json-parser/parser.js +223 -0
  6. package/dist/vendor/_vendor/partial-json-parser/parser.js.map +1 -0
  7. package/dist/vendor/api-promise.d.ts +2 -0
  8. package/dist/vendor/api-promise.js +3 -0
  9. package/dist/vendor/api-promise.js.map +1 -0
  10. package/dist/vendor/client.d.ts +399 -0
  11. package/dist/vendor/client.js +976 -0
  12. package/dist/vendor/client.js.map +1 -0
  13. package/dist/vendor/core/api-promise.d.ts +49 -0
  14. package/dist/vendor/core/api-promise.js +77 -0
  15. package/dist/vendor/core/api-promise.js.map +1 -0
  16. package/dist/vendor/core/api.d.ts +10 -0
  17. package/dist/vendor/core/api.js +2 -0
  18. package/dist/vendor/core/api.js.map +1 -0
  19. package/dist/vendor/core/credentials.d.ts +130 -0
  20. package/dist/vendor/core/credentials.js +274 -0
  21. package/dist/vendor/core/credentials.js.map +1 -0
  22. package/dist/vendor/core/error.d.ts +82 -0
  23. package/dist/vendor/core/error.js +140 -0
  24. package/dist/vendor/core/error.js.map +1 -0
  25. package/dist/vendor/core/middleware.d.ts +153 -0
  26. package/dist/vendor/core/middleware.js +168 -0
  27. package/dist/vendor/core/middleware.js.map +1 -0
  28. package/dist/vendor/core/pagination.d.ts +121 -0
  29. package/dist/vendor/core/pagination.js +207 -0
  30. package/dist/vendor/core/pagination.js.map +1 -0
  31. package/dist/vendor/core/resource.d.ts +5 -0
  32. package/dist/vendor/core/resource.js +8 -0
  33. package/dist/vendor/core/resource.js.map +1 -0
  34. package/dist/vendor/core/streaming.d.ts +41 -0
  35. package/dist/vendor/core/streaming.js +342 -0
  36. package/dist/vendor/core/streaming.js.map +1 -0
  37. package/dist/vendor/core/uploads.d.ts +2 -0
  38. package/dist/vendor/core/uploads.js +2 -0
  39. package/dist/vendor/core/uploads.js.map +1 -0
  40. package/dist/vendor/error.d.ts +2 -0
  41. package/dist/vendor/error.js +3 -0
  42. package/dist/vendor/error.js.map +1 -0
  43. package/dist/vendor/helpers/beta/environments.d.ts +22 -0
  44. package/dist/vendor/helpers/beta/environments.js +23 -0
  45. package/dist/vendor/helpers/beta/environments.js.map +1 -0
  46. package/dist/vendor/helpers/beta/json-schema.d.ts +36 -0
  47. package/dist/vendor/helpers/beta/json-schema.js +53 -0
  48. package/dist/vendor/helpers/beta/json-schema.js.map +1 -0
  49. package/dist/vendor/helpers/beta/mcp.d.ts +302 -0
  50. package/dist/vendor/helpers/beta/mcp.js +406 -0
  51. package/dist/vendor/helpers/beta/mcp.js.map +1 -0
  52. package/dist/vendor/helpers/beta/memory.d.ts +10 -0
  53. package/dist/vendor/helpers/beta/memory.js +15 -0
  54. package/dist/vendor/helpers/beta/memory.js.map +1 -0
  55. package/dist/vendor/helpers/beta/standard-schema.d.ts +44 -0
  56. package/dist/vendor/helpers/beta/standard-schema.js +54 -0
  57. package/dist/vendor/helpers/beta/standard-schema.js.map +1 -0
  58. package/dist/vendor/helpers/beta/zod.d.ts +32 -0
  59. package/dist/vendor/helpers/beta/zod.js +52 -0
  60. package/dist/vendor/helpers/beta/zod.js.map +1 -0
  61. package/dist/vendor/helpers/index.d.ts +2 -0
  62. package/dist/vendor/helpers/index.js +3 -0
  63. package/dist/vendor/helpers/index.js.map +1 -0
  64. package/dist/vendor/helpers/json-schema.d.ts +17 -0
  65. package/dist/vendor/helpers/json-schema.js +34 -0
  66. package/dist/vendor/helpers/json-schema.js.map +1 -0
  67. package/dist/vendor/helpers/zod.d.ts +12 -0
  68. package/dist/vendor/helpers/zod.js +42 -0
  69. package/dist/vendor/helpers/zod.js.map +1 -0
  70. package/dist/vendor/index.d.ts +16 -0
  71. package/dist/vendor/index.js +23 -0
  72. package/dist/vendor/index.js.map +1 -0
  73. package/dist/vendor/internal/builtin-types.d.ts +72 -0
  74. package/dist/vendor/internal/builtin-types.js +3 -0
  75. package/dist/vendor/internal/builtin-types.js.map +1 -0
  76. package/dist/vendor/internal/constants.d.ts +4 -0
  77. package/dist/vendor/internal/constants.js +10 -0
  78. package/dist/vendor/internal/constants.js.map +1 -0
  79. package/dist/vendor/internal/decoders/jsonl.d.ts +9 -0
  80. package/dist/vendor/internal/decoders/jsonl.js +37 -0
  81. package/dist/vendor/internal/decoders/jsonl.js.map +1 -0
  82. package/dist/vendor/internal/decoders/line.d.ts +16 -0
  83. package/dist/vendor/internal/decoders/line.js +105 -0
  84. package/dist/vendor/internal/decoders/line.js.map +1 -0
  85. package/dist/vendor/internal/detect-platform.d.ts +14 -0
  86. package/dist/vendor/internal/detect-platform.js +155 -0
  87. package/dist/vendor/internal/detect-platform.js.map +1 -0
  88. package/dist/vendor/internal/errors.d.ts +2 -0
  89. package/dist/vendor/internal/errors.js +38 -0
  90. package/dist/vendor/internal/errors.js.map +1 -0
  91. package/dist/vendor/internal/file-store.d.ts +135 -0
  92. package/dist/vendor/internal/file-store.js +529 -0
  93. package/dist/vendor/internal/file-store.js.map +1 -0
  94. package/dist/vendor/internal/headers.d.ts +28 -0
  95. package/dist/vendor/internal/headers.js +114 -0
  96. package/dist/vendor/internal/headers.js.map +1 -0
  97. package/dist/vendor/internal/message-stream-utils.d.ts +9 -0
  98. package/dist/vendor/internal/message-stream-utils.js +30 -0
  99. package/dist/vendor/internal/message-stream-utils.js.map +1 -0
  100. package/dist/vendor/internal/node.browser.d.ts +8 -0
  101. package/dist/vendor/internal/node.browser.js +19 -0
  102. package/dist/vendor/internal/node.browser.js.map +1 -0
  103. package/dist/vendor/internal/node.d.ts +13 -0
  104. package/dist/vendor/internal/node.js +14 -0
  105. package/dist/vendor/internal/node.js.map +1 -0
  106. package/dist/vendor/internal/parse.d.ts +17 -0
  107. package/dist/vendor/internal/parse.js +62 -0
  108. package/dist/vendor/internal/parse.js.map +1 -0
  109. package/dist/vendor/internal/qs/formats.d.ts +6 -0
  110. package/dist/vendor/internal/qs/formats.js +9 -0
  111. package/dist/vendor/internal/qs/formats.js.map +1 -0
  112. package/dist/vendor/internal/qs/index.d.ts +9 -0
  113. package/dist/vendor/internal/qs/index.js +10 -0
  114. package/dist/vendor/internal/qs/index.js.map +1 -0
  115. package/dist/vendor/internal/qs/stringify.d.ts +2 -0
  116. package/dist/vendor/internal/qs/stringify.js +274 -0
  117. package/dist/vendor/internal/qs/stringify.js.map +1 -0
  118. package/dist/vendor/internal/qs/types.d.ts +56 -0
  119. package/dist/vendor/internal/qs/types.js +2 -0
  120. package/dist/vendor/internal/qs/types.js.map +1 -0
  121. package/dist/vendor/internal/qs/utils.d.ts +14 -0
  122. package/dist/vendor/internal/qs/utils.js +217 -0
  123. package/dist/vendor/internal/qs/utils.js.map +1 -0
  124. package/dist/vendor/internal/request-options.d.ts +126 -0
  125. package/dist/vendor/internal/request-options.js +27 -0
  126. package/dist/vendor/internal/request-options.js.map +1 -0
  127. package/dist/vendor/internal/request-signal.d.ts +3 -0
  128. package/dist/vendor/internal/request-signal.js +45 -0
  129. package/dist/vendor/internal/request-signal.js.map +1 -0
  130. package/dist/vendor/internal/shim-types.d.ts +16 -0
  131. package/dist/vendor/internal/shim-types.js +3 -0
  132. package/dist/vendor/internal/shim-types.js.map +1 -0
  133. package/dist/vendor/internal/shims.d.ts +25 -0
  134. package/dist/vendor/internal/shims.js +85 -0
  135. package/dist/vendor/internal/shims.js.map +1 -0
  136. package/dist/vendor/internal/stainless-helper-header.d.ts +59 -0
  137. package/dist/vendor/internal/stainless-helper-header.js +83 -0
  138. package/dist/vendor/internal/stainless-helper-header.js.map +1 -0
  139. package/dist/vendor/internal/stream-utils.d.ts +7 -0
  140. package/dist/vendor/internal/stream-utils.js +35 -0
  141. package/dist/vendor/internal/stream-utils.js.map +1 -0
  142. package/dist/vendor/internal/to-file.d.ts +44 -0
  143. package/dist/vendor/internal/to-file.js +93 -0
  144. package/dist/vendor/internal/to-file.js.map +1 -0
  145. package/dist/vendor/internal/types.d.ts +62 -0
  146. package/dist/vendor/internal/types.js +3 -0
  147. package/dist/vendor/internal/types.js.map +1 -0
  148. package/dist/vendor/internal/uploads.d.ts +41 -0
  149. package/dist/vendor/internal/uploads.js +139 -0
  150. package/dist/vendor/internal/uploads.js.map +1 -0
  151. package/dist/vendor/internal/utils/abort.d.ts +11 -0
  152. package/dist/vendor/internal/utils/abort.js +22 -0
  153. package/dist/vendor/internal/utils/abort.js.map +1 -0
  154. package/dist/vendor/internal/utils/async-queue.d.ts +30 -0
  155. package/dist/vendor/internal/utils/async-queue.js +66 -0
  156. package/dist/vendor/internal/utils/async-queue.js.map +1 -0
  157. package/dist/vendor/internal/utils/backoff.d.ts +22 -0
  158. package/dist/vendor/internal/utils/backoff.js +36 -0
  159. package/dist/vendor/internal/utils/backoff.js.map +1 -0
  160. package/dist/vendor/internal/utils/base64.d.ts +2 -0
  161. package/dist/vendor/internal/utils/base64.js +33 -0
  162. package/dist/vendor/internal/utils/base64.js.map +1 -0
  163. package/dist/vendor/internal/utils/bytes.d.ts +3 -0
  164. package/dist/vendor/internal/utils/bytes.js +26 -0
  165. package/dist/vendor/internal/utils/bytes.js.map +1 -0
  166. package/dist/vendor/internal/utils/env.d.ts +8 -0
  167. package/dist/vendor/internal/utils/env.js +18 -0
  168. package/dist/vendor/internal/utils/env.js.map +1 -0
  169. package/dist/vendor/internal/utils/log.d.ts +46 -0
  170. package/dist/vendor/internal/utils/log.js +105 -0
  171. package/dist/vendor/internal/utils/log.js.map +1 -0
  172. package/dist/vendor/internal/utils/path.d.ts +14 -0
  173. package/dist/vendor/internal/utils/path.js +74 -0
  174. package/dist/vendor/internal/utils/path.js.map +1 -0
  175. package/dist/vendor/internal/utils/promise.d.ts +10 -0
  176. package/dist/vendor/internal/utils/promise.js +15 -0
  177. package/dist/vendor/internal/utils/promise.js.map +1 -0
  178. package/dist/vendor/internal/utils/query.d.ts +1 -0
  179. package/dist/vendor/internal/utils/query.js +6 -0
  180. package/dist/vendor/internal/utils/query.js.map +1 -0
  181. package/dist/vendor/internal/utils/sleep.d.ts +9 -0
  182. package/dist/vendor/internal/utils/sleep.js +24 -0
  183. package/dist/vendor/internal/utils/sleep.js.map +1 -0
  184. package/dist/vendor/internal/utils/time.d.ts +2 -0
  185. package/dist/vendor/internal/utils/time.js +5 -0
  186. package/dist/vendor/internal/utils/time.js.map +1 -0
  187. package/dist/vendor/internal/utils/uuid.d.ts +4 -0
  188. package/dist/vendor/internal/utils/uuid.js +15 -0
  189. package/dist/vendor/internal/utils/uuid.js.map +1 -0
  190. package/dist/vendor/internal/utils/values.d.ts +24 -0
  191. package/dist/vendor/internal/utils/values.js +106 -0
  192. package/dist/vendor/internal/utils/values.js.map +1 -0
  193. package/dist/vendor/internal/utils.d.ts +7 -0
  194. package/dist/vendor/internal/utils.js +9 -0
  195. package/dist/vendor/internal/utils.js.map +1 -0
  196. package/dist/vendor/lib/BetaMessageStream.d.ts +123 -0
  197. package/dist/vendor/lib/BetaMessageStream.js +662 -0
  198. package/dist/vendor/lib/BetaMessageStream.js.map +1 -0
  199. package/dist/vendor/lib/MessageStream.d.ts +122 -0
  200. package/dist/vendor/lib/MessageStream.js +609 -0
  201. package/dist/vendor/lib/MessageStream.js.map +1 -0
  202. package/dist/vendor/lib/beta-parser.d.ts +36 -0
  203. package/dist/vendor/lib/beta-parser.js +75 -0
  204. package/dist/vendor/lib/beta-parser.js.map +1 -0
  205. package/dist/vendor/lib/credentials/credential-chain.d.ts +38 -0
  206. package/dist/vendor/lib/credentials/credential-chain.js +208 -0
  207. package/dist/vendor/lib/credentials/credential-chain.js.map +1 -0
  208. package/dist/vendor/lib/credentials/identity-token.d.ts +10 -0
  209. package/dist/vendor/lib/credentials/identity-token.js +35 -0
  210. package/dist/vendor/lib/credentials/identity-token.js.map +1 -0
  211. package/dist/vendor/lib/credentials/oidc-federation.d.ts +39 -0
  212. package/dist/vendor/lib/credentials/oidc-federation.js +79 -0
  213. package/dist/vendor/lib/credentials/oidc-federation.js.map +1 -0
  214. package/dist/vendor/lib/credentials/token-cache.d.ts +53 -0
  215. package/dist/vendor/lib/credentials/token-cache.js +110 -0
  216. package/dist/vendor/lib/credentials/token-cache.js.map +1 -0
  217. package/dist/vendor/lib/credentials/types.d.ts +95 -0
  218. package/dist/vendor/lib/credentials/types.js +226 -0
  219. package/dist/vendor/lib/credentials/types.js.map +1 -0
  220. package/dist/vendor/lib/credentials/user-oauth.d.ts +20 -0
  221. package/dist/vendor/lib/credentials/user-oauth.js +94 -0
  222. package/dist/vendor/lib/credentials/user-oauth.js.map +1 -0
  223. package/dist/vendor/lib/credentials.d.ts +3 -0
  224. package/dist/vendor/lib/credentials.js +3 -0
  225. package/dist/vendor/lib/credentials.js.map +1 -0
  226. package/dist/vendor/lib/environments/index.d.ts +3 -0
  227. package/dist/vendor/lib/environments/index.js +4 -0
  228. package/dist/vendor/lib/environments/index.js.map +1 -0
  229. package/dist/vendor/lib/environments/poller.d.ts +94 -0
  230. package/dist/vendor/lib/environments/poller.js +218 -0
  231. package/dist/vendor/lib/environments/poller.js.map +1 -0
  232. package/dist/vendor/lib/environments/worker.d.ts +226 -0
  233. package/dist/vendor/lib/environments/worker.js +572 -0
  234. package/dist/vendor/lib/environments/worker.js.map +1 -0
  235. package/dist/vendor/lib/helper-client.d.ts +30 -0
  236. package/dist/vendor/lib/helper-client.js +55 -0
  237. package/dist/vendor/lib/helper-client.js.map +1 -0
  238. package/dist/vendor/lib/middleware.d.ts +97 -0
  239. package/dist/vendor/lib/middleware.js +775 -0
  240. package/dist/vendor/lib/middleware.js.map +1 -0
  241. package/dist/vendor/lib/parser.d.ts +31 -0
  242. package/dist/vendor/lib/parser.js +62 -0
  243. package/dist/vendor/lib/parser.js.map +1 -0
  244. package/dist/vendor/lib/sessions/accumulate.d.ts +22 -0
  245. package/dist/vendor/lib/sessions/accumulate.js +42 -0
  246. package/dist/vendor/lib/sessions/accumulate.js.map +1 -0
  247. package/dist/vendor/lib/standard-schema.d.ts +130 -0
  248. package/dist/vendor/lib/standard-schema.js +41 -0
  249. package/dist/vendor/lib/standard-schema.js.map +1 -0
  250. package/dist/vendor/lib/tools/BetaRunnableTool.d.ts +48 -0
  251. package/dist/vendor/lib/tools/BetaRunnableTool.js +26 -0
  252. package/dist/vendor/lib/tools/BetaRunnableTool.js.map +1 -0
  253. package/dist/vendor/lib/tools/BetaToolRunner.d.ts +160 -0
  254. package/dist/vendor/lib/tools/BetaToolRunner.js +497 -0
  255. package/dist/vendor/lib/tools/BetaToolRunner.js.map +1 -0
  256. package/dist/vendor/lib/tools/CompactionControl.d.ts +29 -0
  257. package/dist/vendor/lib/tools/CompactionControl.js +25 -0
  258. package/dist/vendor/lib/tools/CompactionControl.js.map +1 -0
  259. package/dist/vendor/lib/tools/SessionToolRunner.d.ts +178 -0
  260. package/dist/vendor/lib/tools/SessionToolRunner.js +737 -0
  261. package/dist/vendor/lib/tools/SessionToolRunner.js.map +1 -0
  262. package/dist/vendor/lib/tools/ToolError.d.ts +32 -0
  263. package/dist/vendor/lib/tools/ToolError.js +43 -0
  264. package/dist/vendor/lib/tools/ToolError.js.map +1 -0
  265. package/dist/vendor/lib/transform-json-schema.d.ts +2 -0
  266. package/dist/vendor/lib/transform-json-schema.js +111 -0
  267. package/dist/vendor/lib/transform-json-schema.js.map +1 -0
  268. package/dist/vendor/pagination.d.ts +2 -0
  269. package/dist/vendor/pagination.js +3 -0
  270. package/dist/vendor/pagination.js.map +1 -0
  271. package/dist/vendor/resource.d.ts +2 -0
  272. package/dist/vendor/resource.js +3 -0
  273. package/dist/vendor/resource.js.map +1 -0
  274. package/dist/vendor/resources/beta/agents/agents.d.ts +1128 -0
  275. package/dist/vendor/resources/beta/agents/agents.js +123 -0
  276. package/dist/vendor/resources/beta/agents/agents.js.map +1 -0
  277. package/dist/vendor/resources/beta/agents/index.d.ts +2 -0
  278. package/dist/vendor/resources/beta/agents/index.js +4 -0
  279. package/dist/vendor/resources/beta/agents/index.js.map +1 -0
  280. package/dist/vendor/resources/beta/agents/versions.d.ts +32 -0
  281. package/dist/vendor/resources/beta/agents/versions.js +32 -0
  282. package/dist/vendor/resources/beta/agents/versions.js.map +1 -0
  283. package/dist/vendor/resources/beta/agents.d.ts +1 -0
  284. package/dist/vendor/resources/beta/agents.js +3 -0
  285. package/dist/vendor/resources/beta/agents.js.map +1 -0
  286. package/dist/vendor/resources/beta/beta.d.ts +131 -0
  287. package/dist/vendor/resources/beta/beta.js +69 -0
  288. package/dist/vendor/resources/beta/beta.js.map +1 -0
  289. package/dist/vendor/resources/beta/deployment-runs.d.ts +305 -0
  290. package/dist/vendor/resources/beta/deployment-runs.js +51 -0
  291. package/dist/vendor/resources/beta/deployment-runs.js.map +1 -0
  292. package/dist/vendor/resources/beta/deployments.d.ts +698 -0
  293. package/dist/vendor/resources/beta/deployments.js +192 -0
  294. package/dist/vendor/resources/beta/deployments.js.map +1 -0
  295. package/dist/vendor/resources/beta/dreams.d.ts +335 -0
  296. package/dist/vendor/resources/beta/dreams.js +112 -0
  297. package/dist/vendor/resources/beta/dreams.js.map +1 -0
  298. package/dist/vendor/resources/beta/environments/environments.d.ts +432 -0
  299. package/dist/vendor/resources/beta/environments/environments.js +142 -0
  300. package/dist/vendor/resources/beta/environments/environments.js.map +1 -0
  301. package/dist/vendor/resources/beta/environments/index.d.ts +2 -0
  302. package/dist/vendor/resources/beta/environments/index.js +4 -0
  303. package/dist/vendor/resources/beta/environments/index.js.map +1 -0
  304. package/dist/vendor/resources/beta/environments/work.d.ts +500 -0
  305. package/dist/vendor/resources/beta/environments/work.js +251 -0
  306. package/dist/vendor/resources/beta/environments/work.js.map +1 -0
  307. package/dist/vendor/resources/beta/environments.d.ts +1 -0
  308. package/dist/vendor/resources/beta/environments.js +3 -0
  309. package/dist/vendor/resources/beta/environments.js.map +1 -0
  310. package/dist/vendor/resources/beta/files.d.ts +190 -0
  311. package/dist/vendor/resources/beta/files.js +120 -0
  312. package/dist/vendor/resources/beta/files.js.map +1 -0
  313. package/dist/vendor/resources/beta/index.d.ts +17 -0
  314. package/dist/vendor/resources/beta/index.js +19 -0
  315. package/dist/vendor/resources/beta/index.js.map +1 -0
  316. package/dist/vendor/resources/beta/memory-stores/index.d.ts +3 -0
  317. package/dist/vendor/resources/beta/memory-stores/index.js +5 -0
  318. package/dist/vendor/resources/beta/memory-stores/index.js.map +1 -0
  319. package/dist/vendor/resources/beta/memory-stores/memories.d.ts +346 -0
  320. package/dist/vendor/resources/beta/memory-stores/memories.js +126 -0
  321. package/dist/vendor/resources/beta/memory-stores/memories.js.map +1 -0
  322. package/dist/vendor/resources/beta/memory-stores/memory-stores.d.ts +230 -0
  323. package/dist/vendor/resources/beta/memory-stores/memory-stores.js +137 -0
  324. package/dist/vendor/resources/beta/memory-stores/memory-stores.js.map +1 -0
  325. package/dist/vendor/resources/beta/memory-stores/memory-versions.d.ts +252 -0
  326. package/dist/vendor/resources/beta/memory-stores/memory-versions.js +77 -0
  327. package/dist/vendor/resources/beta/memory-stores/memory-versions.js.map +1 -0
  328. package/dist/vendor/resources/beta/memory-stores.d.ts +1 -0
  329. package/dist/vendor/resources/beta/memory-stores.js +3 -0
  330. package/dist/vendor/resources/beta/memory-stores.js.map +1 -0
  331. package/dist/vendor/resources/beta/messages/batches.d.ts +685 -0
  332. package/dist/vendor/resources/beta/messages/batches.js +203 -0
  333. package/dist/vendor/resources/beta/messages/batches.js.map +1 -0
  334. package/dist/vendor/resources/beta/messages/index.d.ts +3 -0
  335. package/dist/vendor/resources/beta/messages/index.js +5 -0
  336. package/dist/vendor/resources/beta/messages/index.js.map +1 -0
  337. package/dist/vendor/resources/beta/messages/messages.d.ts +5376 -0
  338. package/dist/vendor/resources/beta/messages/messages.js +158 -0
  339. package/dist/vendor/resources/beta/messages/messages.js.map +1 -0
  340. package/dist/vendor/resources/beta/messages.d.ts +1 -0
  341. package/dist/vendor/resources/beta/messages.js +3 -0
  342. package/dist/vendor/resources/beta/messages.js.map +1 -0
  343. package/dist/vendor/resources/beta/models.d.ts +217 -0
  344. package/dist/vendor/resources/beta/models.js +56 -0
  345. package/dist/vendor/resources/beta/models.js.map +1 -0
  346. package/dist/vendor/resources/beta/organization/api-keys.d.ts +176 -0
  347. package/dist/vendor/resources/beta/organization/api-keys.js +52 -0
  348. package/dist/vendor/resources/beta/organization/api-keys.js.map +1 -0
  349. package/dist/vendor/resources/beta/organization/compliance-settings.d.ts +73 -0
  350. package/dist/vendor/resources/beta/organization/compliance-settings.js +48 -0
  351. package/dist/vendor/resources/beta/organization/compliance-settings.js.map +1 -0
  352. package/dist/vendor/resources/beta/organization/external-keys.d.ts +271 -0
  353. package/dist/vendor/resources/beta/organization/external-keys.js +115 -0
  354. package/dist/vendor/resources/beta/organization/external-keys.js.map +1 -0
  355. package/dist/vendor/resources/beta/organization/federation/federation.d.ts +13 -0
  356. package/dist/vendor/resources/beta/organization/federation/federation.js +13 -0
  357. package/dist/vendor/resources/beta/organization/federation/federation.js.map +1 -0
  358. package/dist/vendor/resources/beta/organization/federation/index.d.ts +3 -0
  359. package/dist/vendor/resources/beta/organization/federation/index.js +5 -0
  360. package/dist/vendor/resources/beta/organization/federation/index.js.map +1 -0
  361. package/dist/vendor/resources/beta/organization/federation/issuers.d.ts +352 -0
  362. package/dist/vendor/resources/beta/organization/federation/issuers.js +165 -0
  363. package/dist/vendor/resources/beta/organization/federation/issuers.js.map +1 -0
  364. package/dist/vendor/resources/beta/organization/federation/rules/index.d.ts +2 -0
  365. package/dist/vendor/resources/beta/organization/federation/rules/index.js +4 -0
  366. package/dist/vendor/resources/beta/organization/federation/rules/index.js.map +1 -0
  367. package/dist/vendor/resources/beta/organization/federation/rules/rules.d.ts +467 -0
  368. package/dist/vendor/resources/beta/organization/federation/rules/rules.js +190 -0
  369. package/dist/vendor/resources/beta/organization/federation/rules/rules.js.map +1 -0
  370. package/dist/vendor/resources/beta/organization/federation/rules/workspaces.d.ts +123 -0
  371. package/dist/vendor/resources/beta/organization/federation/rules/workspaces.js +110 -0
  372. package/dist/vendor/resources/beta/organization/federation/rules/workspaces.js.map +1 -0
  373. package/dist/vendor/resources/beta/organization/federation/rules.d.ts +1 -0
  374. package/dist/vendor/resources/beta/organization/federation/rules.js +3 -0
  375. package/dist/vendor/resources/beta/organization/federation/rules.js.map +1 -0
  376. package/dist/vendor/resources/beta/organization/federation.d.ts +1 -0
  377. package/dist/vendor/resources/beta/organization/federation.js +3 -0
  378. package/dist/vendor/resources/beta/organization/federation.js.map +1 -0
  379. package/dist/vendor/resources/beta/organization/index.d.ts +10 -0
  380. package/dist/vendor/resources/beta/organization/index.js +12 -0
  381. package/dist/vendor/resources/beta/organization/index.js.map +1 -0
  382. package/dist/vendor/resources/beta/organization/invites.d.ts +161 -0
  383. package/dist/vendor/resources/beta/organization/invites.js +72 -0
  384. package/dist/vendor/resources/beta/organization/invites.js.map +1 -0
  385. package/dist/vendor/resources/beta/organization/organization.d.ts +72 -0
  386. package/dist/vendor/resources/beta/organization/organization.js +54 -0
  387. package/dist/vendor/resources/beta/organization/organization.js.map +1 -0
  388. package/dist/vendor/resources/beta/organization/rate-limits.d.ts +76 -0
  389. package/dist/vendor/resources/beta/organization/rate-limits.js +27 -0
  390. package/dist/vendor/resources/beta/organization/rate-limits.js.map +1 -0
  391. package/dist/vendor/resources/beta/organization/service-accounts/index.d.ts +2 -0
  392. package/dist/vendor/resources/beta/organization/service-accounts/index.js +4 -0
  393. package/dist/vendor/resources/beta/organization/service-accounts/index.js.map +1 -0
  394. package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.d.ts +257 -0
  395. package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.js +166 -0
  396. package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.js.map +1 -0
  397. package/dist/vendor/resources/beta/organization/service-accounts/workspaces.d.ts +140 -0
  398. package/dist/vendor/resources/beta/organization/service-accounts/workspaces.js +121 -0
  399. package/dist/vendor/resources/beta/organization/service-accounts/workspaces.js.map +1 -0
  400. package/dist/vendor/resources/beta/organization/service-accounts.d.ts +1 -0
  401. package/dist/vendor/resources/beta/organization/service-accounts.js +3 -0
  402. package/dist/vendor/resources/beta/organization/service-accounts.js.map +1 -0
  403. package/dist/vendor/resources/beta/organization/users.d.ts +123 -0
  404. package/dist/vendor/resources/beta/organization/users.js +63 -0
  405. package/dist/vendor/resources/beta/organization/users.js.map +1 -0
  406. package/dist/vendor/resources/beta/organization/workspaces/index.d.ts +4 -0
  407. package/dist/vendor/resources/beta/organization/workspaces/index.js +6 -0
  408. package/dist/vendor/resources/beta/organization/workspaces/index.js.map +1 -0
  409. package/dist/vendor/resources/beta/organization/workspaces/members.d.ts +134 -0
  410. package/dist/vendor/resources/beta/organization/workspaces/members.js +98 -0
  411. package/dist/vendor/resources/beta/organization/workspaces/members.js.map +1 -0
  412. package/dist/vendor/resources/beta/organization/workspaces/rate-limits.d.ts +82 -0
  413. package/dist/vendor/resources/beta/organization/workspaces/rate-limits.js +30 -0
  414. package/dist/vendor/resources/beta/organization/workspaces/rate-limits.js.map +1 -0
  415. package/dist/vendor/resources/beta/organization/workspaces/service-accounts.d.ts +209 -0
  416. package/dist/vendor/resources/beta/organization/workspaces/service-accounts.js +185 -0
  417. package/dist/vendor/resources/beta/organization/workspaces/service-accounts.js.map +1 -0
  418. package/dist/vendor/resources/beta/organization/workspaces/workspaces.d.ts +302 -0
  419. package/dist/vendor/resources/beta/organization/workspaces/workspaces.js +104 -0
  420. package/dist/vendor/resources/beta/organization/workspaces/workspaces.js.map +1 -0
  421. package/dist/vendor/resources/beta/organization/workspaces.d.ts +1 -0
  422. package/dist/vendor/resources/beta/organization/workspaces.js +3 -0
  423. package/dist/vendor/resources/beta/organization/workspaces.js.map +1 -0
  424. package/dist/vendor/resources/beta/organization.d.ts +1 -0
  425. package/dist/vendor/resources/beta/organization.js +3 -0
  426. package/dist/vendor/resources/beta/organization.js.map +1 -0
  427. package/dist/vendor/resources/beta/sessions/events.d.ts +1513 -0
  428. package/dist/vendor/resources/beta/sessions/events.js +115 -0
  429. package/dist/vendor/resources/beta/sessions/events.js.map +1 -0
  430. package/dist/vendor/resources/beta/sessions/index.d.ts +4 -0
  431. package/dist/vendor/resources/beta/sessions/index.js +6 -0
  432. package/dist/vendor/resources/beta/sessions/index.js.map +1 -0
  433. package/dist/vendor/resources/beta/sessions/resources.d.ts +227 -0
  434. package/dist/vendor/resources/beta/sessions/resources.js +128 -0
  435. package/dist/vendor/resources/beta/sessions/resources.js.map +1 -0
  436. package/dist/vendor/resources/beta/sessions/sessions.d.ts +866 -0
  437. package/dist/vendor/resources/beta/sessions/sessions.js +150 -0
  438. package/dist/vendor/resources/beta/sessions/sessions.js.map +1 -0
  439. package/dist/vendor/resources/beta/sessions/threads/events.d.ts +77 -0
  440. package/dist/vendor/resources/beta/sessions/threads/events.js +57 -0
  441. package/dist/vendor/resources/beta/sessions/threads/events.js.map +1 -0
  442. package/dist/vendor/resources/beta/sessions/threads/index.d.ts +2 -0
  443. package/dist/vendor/resources/beta/sessions/threads/index.js +4 -0
  444. package/dist/vendor/resources/beta/sessions/threads/index.js.map +1 -0
  445. package/dist/vendor/resources/beta/sessions/threads/threads.d.ts +195 -0
  446. package/dist/vendor/resources/beta/sessions/threads/threads.js +80 -0
  447. package/dist/vendor/resources/beta/sessions/threads/threads.js.map +1 -0
  448. package/dist/vendor/resources/beta/sessions/threads.d.ts +1 -0
  449. package/dist/vendor/resources/beta/sessions/threads.js +3 -0
  450. package/dist/vendor/resources/beta/sessions/threads.js.map +1 -0
  451. package/dist/vendor/resources/beta/sessions.d.ts +1 -0
  452. package/dist/vendor/resources/beta/sessions.js +3 -0
  453. package/dist/vendor/resources/beta/sessions.js.map +1 -0
  454. package/dist/vendor/resources/beta/skills/index.d.ts +2 -0
  455. package/dist/vendor/resources/beta/skills/index.js +4 -0
  456. package/dist/vendor/resources/beta/skills/index.js.map +1 -0
  457. package/dist/vendor/resources/beta/skills/skills.d.ts +178 -0
  458. package/dist/vendor/resources/beta/skills/skills.js +96 -0
  459. package/dist/vendor/resources/beta/skills/skills.js.map +1 -0
  460. package/dist/vendor/resources/beta/skills/versions.d.ts +181 -0
  461. package/dist/vendor/resources/beta/skills/versions.js +125 -0
  462. package/dist/vendor/resources/beta/skills/versions.js.map +1 -0
  463. package/dist/vendor/resources/beta/skills.d.ts +1 -0
  464. package/dist/vendor/resources/beta/skills.js +3 -0
  465. package/dist/vendor/resources/beta/skills.js.map +1 -0
  466. package/dist/vendor/resources/beta/tunnels/certificates.d.ts +162 -0
  467. package/dist/vendor/resources/beta/tunnels/certificates.js +125 -0
  468. package/dist/vendor/resources/beta/tunnels/certificates.js.map +1 -0
  469. package/dist/vendor/resources/beta/tunnels/index.d.ts +2 -0
  470. package/dist/vendor/resources/beta/tunnels/index.js +4 -0
  471. package/dist/vendor/resources/beta/tunnels/index.js.map +1 -0
  472. package/dist/vendor/resources/beta/tunnels/tunnels.d.ts +211 -0
  473. package/dist/vendor/resources/beta/tunnels/tunnels.js +173 -0
  474. package/dist/vendor/resources/beta/tunnels/tunnels.js.map +1 -0
  475. package/dist/vendor/resources/beta/tunnels.d.ts +1 -0
  476. package/dist/vendor/resources/beta/tunnels.js +3 -0
  477. package/dist/vendor/resources/beta/tunnels.js.map +1 -0
  478. package/dist/vendor/resources/beta/user-profiles.d.ts +244 -0
  479. package/dist/vendor/resources/beta/user-profiles.js +114 -0
  480. package/dist/vendor/resources/beta/user-profiles.js.map +1 -0
  481. package/dist/vendor/resources/beta/vaults/credentials.d.ts +715 -0
  482. package/dist/vendor/resources/beta/vaults/credentials.js +173 -0
  483. package/dist/vendor/resources/beta/vaults/credentials.js.map +1 -0
  484. package/dist/vendor/resources/beta/vaults/index.d.ts +2 -0
  485. package/dist/vendor/resources/beta/vaults/index.js +4 -0
  486. package/dist/vendor/resources/beta/vaults/index.js.map +1 -0
  487. package/dist/vendor/resources/beta/vaults/vaults.d.ts +191 -0
  488. package/dist/vendor/resources/beta/vaults/vaults.js +141 -0
  489. package/dist/vendor/resources/beta/vaults/vaults.js.map +1 -0
  490. package/dist/vendor/resources/beta/vaults.d.ts +1 -0
  491. package/dist/vendor/resources/beta/vaults.js +3 -0
  492. package/dist/vendor/resources/beta/vaults.js.map +1 -0
  493. package/dist/vendor/resources/beta/webhooks.d.ts +464 -0
  494. package/dist/vendor/resources/beta/webhooks.js +29 -0
  495. package/dist/vendor/resources/beta/webhooks.js.map +1 -0
  496. package/dist/vendor/resources/beta.d.ts +1 -0
  497. package/dist/vendor/resources/beta.js +3 -0
  498. package/dist/vendor/resources/beta.js.map +1 -0
  499. package/dist/vendor/resources/completions.d.ts +172 -0
  500. package/dist/vendor/resources/completions.js +19 -0
  501. package/dist/vendor/resources/completions.js.map +1 -0
  502. package/dist/vendor/resources/files.d.ts +104 -0
  503. package/dist/vendor/resources/files.js +48 -0
  504. package/dist/vendor/resources/files.js.map +1 -0
  505. package/dist/vendor/resources/index.d.ts +7 -0
  506. package/dist/vendor/resources/index.js +9 -0
  507. package/dist/vendor/resources/index.js.map +1 -0
  508. package/dist/vendor/resources/messages/batches.d.ts +312 -0
  509. package/dist/vendor/resources/messages/batches.js +157 -0
  510. package/dist/vendor/resources/messages/batches.js.map +1 -0
  511. package/dist/vendor/resources/messages/index.d.ts +2 -0
  512. package/dist/vendor/resources/messages/index.js +4 -0
  513. package/dist/vendor/resources/messages/index.js.map +1 -0
  514. package/dist/vendor/resources/messages/messages.d.ts +3886 -0
  515. package/dist/vendor/resources/messages/messages.js +130 -0
  516. package/dist/vendor/resources/messages/messages.js.map +1 -0
  517. package/dist/vendor/resources/messages.d.ts +1 -0
  518. package/dist/vendor/resources/messages.js +3 -0
  519. package/dist/vendor/resources/messages.js.map +1 -0
  520. package/dist/vendor/resources/models.d.ts +196 -0
  521. package/dist/vendor/resources/models.js +41 -0
  522. package/dist/vendor/resources/models.js.map +1 -0
  523. package/dist/vendor/resources/shared.d.ts +43 -0
  524. package/dist/vendor/resources/shared.js +3 -0
  525. package/dist/vendor/resources/shared.js.map +1 -0
  526. package/dist/vendor/resources/skills/index.d.ts +2 -0
  527. package/dist/vendor/resources/skills/index.js +4 -0
  528. package/dist/vendor/resources/skills/index.js.map +1 -0
  529. package/dist/vendor/resources/skills/skills.d.ts +128 -0
  530. package/dist/vendor/resources/skills/skills.js +36 -0
  531. package/dist/vendor/resources/skills/skills.js.map +1 -0
  532. package/dist/vendor/resources/skills/versions.d.ts +103 -0
  533. package/dist/vendor/resources/skills/versions.js +37 -0
  534. package/dist/vendor/resources/skills/versions.js.map +1 -0
  535. package/dist/vendor/resources/skills.d.ts +1 -0
  536. package/dist/vendor/resources/skills.js +3 -0
  537. package/dist/vendor/resources/skills.js.map +1 -0
  538. package/dist/vendor/resources/top-level.d.ts +1 -0
  539. package/dist/vendor/resources/top-level.js +3 -0
  540. package/dist/vendor/resources/top-level.js.map +1 -0
  541. package/dist/vendor/resources.d.ts +1 -0
  542. package/dist/vendor/resources.js +2 -0
  543. package/dist/vendor/resources.js.map +1 -0
  544. package/dist/vendor/streaming.d.ts +2 -0
  545. package/dist/vendor/streaming.js +3 -0
  546. package/dist/vendor/streaming.js.map +1 -0
  547. package/dist/vendor/tools/agent-toolset/fs-util.d.ts +74 -0
  548. package/dist/vendor/tools/agent-toolset/fs-util.js +184 -0
  549. package/dist/vendor/tools/agent-toolset/fs-util.js.map +1 -0
  550. package/dist/vendor/tools/agent-toolset/memories.d.ts +172 -0
  551. package/dist/vendor/tools/agent-toolset/memories.js +910 -0
  552. package/dist/vendor/tools/agent-toolset/memories.js.map +1 -0
  553. package/dist/vendor/tools/agent-toolset/node.browser.d.ts +80 -0
  554. package/dist/vendor/tools/agent-toolset/node.browser.js +129 -0
  555. package/dist/vendor/tools/agent-toolset/node.browser.js.map +1 -0
  556. package/dist/vendor/tools/agent-toolset/node.d.ts +191 -0
  557. package/dist/vendor/tools/agent-toolset/node.js +886 -0
  558. package/dist/vendor/tools/agent-toolset/node.js.map +1 -0
  559. package/dist/vendor/tools/agent-toolset/skills.d.ts +73 -0
  560. package/dist/vendor/tools/agent-toolset/skills.js +320 -0
  561. package/dist/vendor/tools/agent-toolset/skills.js.map +1 -0
  562. package/dist/vendor/tools/agent-toolset/sync-interval.d.ts +18 -0
  563. package/dist/vendor/tools/agent-toolset/sync-interval.js +25 -0
  564. package/dist/vendor/tools/agent-toolset/sync-interval.js.map +1 -0
  565. package/dist/vendor/tools/memory/node.browser.d.ts +26 -0
  566. package/dist/vendor/tools/memory/node.browser.js +44 -0
  567. package/dist/vendor/tools/memory/node.browser.js.map +1 -0
  568. package/dist/vendor/tools/memory/node.d.ts +17 -0
  569. package/dist/vendor/tools/memory/node.js +327 -0
  570. package/dist/vendor/tools/memory/node.js.map +1 -0
  571. package/dist/vendor/uploads.d.ts +2 -0
  572. package/dist/vendor/uploads.js +3 -0
  573. package/dist/vendor/uploads.js.map +1 -0
  574. package/dist/vendor/version.d.ts +1 -0
  575. package/dist/vendor/version.js +2 -0
  576. package/dist/vendor/version.js.map +1 -0
  577. package/package.json +7 -14
  578. package/sdk.cjs +2 -2
  579. package/sdk.cjs.map +2 -2
  580. package/sdk.d.ts +1 -1
  581. package/sdk.mjs +2 -2
  582. package/sdk.mjs.map +3 -3
@@ -0,0 +1,886 @@
1
+ /**
2
+ * Node implementation of the `agent_toolset_20260401` tools — `bash`, `read`,
3
+ * `write`, `edit`, `glob`, `grep` — plus the workdir/skills
4
+ * {@link AgentToolContext}.
5
+ *
6
+ * This mirrors `@puku-ai/sdk/tools/memory/node`: it is the explicit,
7
+ * Node-only entry point for these implementations. Importing it pulls in
8
+ * `node:child_process`, `node:fs`, etc., so it is kept separate from the rest of
9
+ * the SDK — depending on it is an opt-in.
10
+ *
11
+ * **Node 22+ is required** for this module: the `glob` tool uses the native
12
+ * `fs.glob`, added in Node 22. The rest of the SDK still supports Node 18+; only
13
+ * the agent toolset has this requirement.
14
+ *
15
+ * The result of {@link betaAgentToolset20260401} is a plain `BetaRunnableTool[]`;
16
+ * hand it to any tool runner — `client.beta.messages.toolRunner({ …, tools })`
17
+ * for the Messages API, or `client.beta.sessions.events.toolRunner({ …, tools })`
18
+ * for a managed-agents session:
19
+ *
20
+ * ```ts
21
+ * import { betaAgentToolset20260401 } from '@puku-ai/sdk/tools/agent-toolset/node';
22
+ *
23
+ * const tools = betaAgentToolset20260401({ workdir: '/work' });
24
+ * const tools2 = betaAgentToolset20260401({ workdir: '/work' }).filter((t) => t.name !== 'bash');
25
+ * ```
26
+ *
27
+ * Trust model: the file tools confine to `workdir` plus any `allowedRoots`
28
+ * (symlink-aware) and are safe without a sandbox; `bash` is unrestricted and
29
+ * should run inside one. See {@link AgentToolContext}.
30
+ */
31
+ import * as fs from 'node:fs/promises';
32
+ import * as fssync from 'node:fs';
33
+ import * as path from 'node:path';
34
+ import * as cp from 'node:child_process';
35
+ import * as crypto from 'node:crypto';
36
+ import * as readline from 'node:readline';
37
+ import { PukuError } from '../../core/error.js';
38
+ import { ToolError } from '../../lib/tools/ToolError.js';
39
+ import { betaTool } from '../../helpers/beta/json-schema.js';
40
+ import { promiseWithResolvers } from '../../internal/utils/promise.js';
41
+ import { atomicWriteFile, canonicalize, confineToRoot, containingRoot, DIR_CREATE_MODE, fsErrorMessage, isWithin, } from './fs-util.js';
42
+ export { setupSkills, extractSkillArchive } from './skills.js';
43
+ export { SessionMemoryStores, SessionMemoryError, DEFAULT_MEMORY_SYNC_INTERVAL_MS, MIN_MEMORY_SYNC_INTERVAL_MS, MEMORY_FLUSH_TIMEOUT_MS, MARKER_PATH, } from './memories.js';
44
+ const BASH_OUTPUT_LIMIT = 100 * 1024;
45
+ const BASH_DEFAULT_TIMEOUT_MS = 120_000;
46
+ // Default size cap for the read/edit tools (both load the whole file into
47
+ // memory) when AgentToolContext.maxFileBytes is unset. The reject-vs-truncate
48
+ // behaviour remains a separate question pending CMA validation.
49
+ const DEFAULT_MAX_FILE_BYTES = 256 * 1024;
50
+ const READ_STREAM_CHUNK_BYTES = 64 * 1024;
51
+ const NEWLINE = Buffer.from('\n');
52
+ const GREP_OUTPUT_LIMIT = 100 * 1024;
53
+ const GREP_MAX_LINE_LENGTH = 2000;
54
+ const GLOB_RESULT_LIMIT = 200;
55
+ /**
56
+ * A bash command exceeded its `timeoutMs`. Carries the timeout so a caller can
57
+ * tell it apart from an abort without matching on the message text.
58
+ */
59
+ export class BashTimeoutError extends PukuError {
60
+ timeoutMs;
61
+ constructor(timeoutMs) {
62
+ super(`bash command timed out after ${timeoutMs}ms`);
63
+ this.name = 'BashTimeoutError';
64
+ this.timeoutMs = timeoutMs;
65
+ }
66
+ }
67
+ const ANSI_RE = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
68
+ const fsGlob = fs.glob;
69
+ function resolveMaxBytes(configured) {
70
+ return configured === undefined ? DEFAULT_MAX_FILE_BYTES : configured;
71
+ }
72
+ /**
73
+ * Throw when the deprecated {@link AgentToolContext.unrestrictedPaths} was
74
+ * passed at all. Nothing else reads that property.
75
+ */
76
+ function rejectUnrestrictedPaths(value) {
77
+ if (value === undefined)
78
+ return;
79
+ throw new PukuError('The `unrestrictedPaths` option you passed to the agent toolset (AgentToolContext) is no longer ' +
80
+ "supported. The toolset's file tools (read, write, edit, glob, grep) are now always confined to " +
81
+ 'the working directory plus the directories listed in `allowedRoots`. Remove `unrestrictedPaths` ' +
82
+ 'from your context; to let the file tools reach any other directory, add it to `allowedRoots`.');
83
+ }
84
+ /**
85
+ * Returns the `agent_toolset_20260401` implementations bound to `ctx`. The
86
+ * result is a plain array of `BetaRunnableTool`; filter or extend it before
87
+ * handing it to a tool runner:
88
+ *
89
+ * ```ts
90
+ * const tools = [...betaAgentToolset20260401(ctx), myCustomTool];
91
+ * const tools = betaAgentToolset20260401(ctx).filter((t) => t.name !== 'grep');
92
+ * ```
93
+ *
94
+ * Concurrency note: `client.beta.sessions.events.toolRunner` dispatches a
95
+ * session's tool calls serially (the sessions API delivers one `agent.tool_use`
96
+ * at a time). `client.beta.messages.toolRunner` runs a turn's `tool.run` calls
97
+ * via `Promise.all`. The toolset below is safe under either model —
98
+ * {@link betaBashTool} serializes its persistent shell internally and the FS
99
+ * tools are independent per call — but {@link betaEditTool}/{@link betaWriteTool}
100
+ * cannot synchronize concurrent writes to the *same* file across processes, so a
101
+ * multi-edit turn touching one path is still subject to inherent FS lost-update
102
+ * races. Custom tools that close over mutable state should do their own queueing.
103
+ */
104
+ export function betaAgentToolset20260401(ctx) {
105
+ return [
106
+ betaBashTool(ctx),
107
+ betaReadTool(ctx),
108
+ betaWriteTool(ctx),
109
+ betaEditTool(ctx),
110
+ betaGlobTool(ctx),
111
+ betaGrepTool(ctx),
112
+ ];
113
+ }
114
+ /**
115
+ * Resolve `p` against `ctx.workdir`; reject results outside `ctx.workdir` and
116
+ * `ctx.allowedRoots`. Absolute and relative inputs go through the same
117
+ * canonicalise-then-contain check — an absolute path that lands inside a
118
+ * permitted root is accepted, only paths that resolve *outside* all of them
119
+ * are rejected. Every symlink in `p` (including the leaf, even a dangling one)
120
+ * is resolved before the check, and the resolved path is what the tool then
121
+ * operates on, so a symlink inside the workdir that points outside it can
122
+ * neither pass the check nor be followed afterwards. See the trust model on
123
+ * {@link AgentToolContext}.
124
+ *
125
+ * Residual TOCTOU: a component could still be swapped for a symlink between this
126
+ * call and the eventual `fs` operation. Closing that fully needs per-component
127
+ * `O_NOFOLLOW`/`openat`, which Node does not expose ergonomically; the same
128
+ * residual exposure exists in `tools/memory/node` and is why a sandbox is still
129
+ * recommended for the toolset as a whole.
130
+ */
131
+ export async function resolvePath(ctx, p) {
132
+ rejectUnrestrictedPaths(ctx.unrestrictedPaths);
133
+ return confineToRoot(ctx.workdir, p, { allowedRoots: ctx.allowedRoots ?? [] });
134
+ }
135
+ /**
136
+ * The read-only root `target` falls under, or `undefined`. `target` arrives
137
+ * fully canonicalized (from {@link resolvePath}), so each root is
138
+ * canonicalized too — a root recorded through a symlinked workdir must still
139
+ * match the resolved write target.
140
+ */
141
+ function readOnlyRootFor(ctx, target) {
142
+ return containingRoot(ctx.readOnlyRoots ?? [], target);
143
+ }
144
+ // ---- bash ----------------------------------------------------------------
145
+ /**
146
+ * Build the environment for the spawned bash shell. The runner process holds
147
+ * PukuAI credentials in `PUKU_*` env vars — the API key, the auth token,
148
+ * and the per-work session token among them. `bash` runs an unrestricted shell,
149
+ * so any command the agent runs could read those straight out of `process.env`;
150
+ * strip the whole `PUKU_*` namespace from the child's environment.
151
+ * Everything else (PATH, HOME, locale, …) is passed through unchanged.
152
+ *
153
+ * Passing an explicit `env` to {@link AgentToolContext} does NOT add to this
154
+ * default — it FULLY REPLACES it. The provided mapping becomes the entire bash
155
+ * environment verbatim; nothing here is merged in, so callers who want the
156
+ * scrubbed process environment plus extras must build that mapping themselves.
157
+ */
158
+ function scrubbedShellEnv() {
159
+ const env = {};
160
+ for (const [key, value] of Object.entries(process.env)) {
161
+ if (key.startsWith('PUKU_'))
162
+ continue;
163
+ env[key] = value;
164
+ }
165
+ return env;
166
+ }
167
+ /**
168
+ * A persistent /bin/bash process. State (cwd, env, background jobs) survives
169
+ * across exec() calls. Uses pipes rather than a PTY so input is never echoed.
170
+ */
171
+ export class BashSession {
172
+ #proc;
173
+ #buf = '';
174
+ #truncated = false;
175
+ #closed = false;
176
+ // While a command is in flight, the resolver to fire once its sentinel lands
177
+ // in `#buf` (or once the shell dies). Event-driven: no polling loop.
178
+ #waiting = null;
179
+ constructor(dir, env = scrubbedShellEnv()) {
180
+ this.#proc = cp.spawn('/bin/bash', ['--noprofile', '--norc'], {
181
+ cwd: dir,
182
+ // `env` is the full base environment (the scrubbed process env by
183
+ // default, or the verbatim replacement from `AgentToolContext.env`).
184
+ // PS1/PS2/TERM are shell-control settings BashSession always applies so
185
+ // the pipe-based sentinel exec parsing works — not part of the
186
+ // user-facing environment.
187
+ env: { ...env, PS1: '', PS2: '', TERM: 'dumb' },
188
+ stdio: ['pipe', 'pipe', 'pipe'],
189
+ detached: true,
190
+ });
191
+ this.#proc.stdout.setEncoding('utf8');
192
+ this.#proc.stderr.setEncoding('utf8');
193
+ this.#proc.stdout.on('data', (d) => this.#append(d));
194
+ this.#proc.stderr.on('data', (d) => this.#append(d));
195
+ this.#proc.once('close', () => {
196
+ this.#closed = true;
197
+ // Wake any in-flight exec so it fails fast instead of waiting for its deadline.
198
+ const w = this.#waiting;
199
+ this.#waiting = null;
200
+ w?.resolve();
201
+ });
202
+ }
203
+ /** Whether the underlying shell process has exited. */
204
+ get closed() {
205
+ return this.#closed;
206
+ }
207
+ // Cap the buffer during accumulation so a command that streams unboundedly
208
+ // can't OOM the runner. Keeps the tail so the sentinel stays detectable.
209
+ // Also resolves the in-flight exec the instant its sentinel is buffered.
210
+ #append(d) {
211
+ this.#buf += d;
212
+ if (this.#buf.length > BASH_OUTPUT_LIMIT) {
213
+ this.#buf = this.#buf.slice(this.#buf.length - BASH_OUTPUT_LIMIT);
214
+ this.#truncated = true;
215
+ }
216
+ if (this.#waiting && this.#buf.indexOf(this.#waiting.sentinel) >= 0) {
217
+ const w = this.#waiting;
218
+ this.#waiting = null;
219
+ w.resolve();
220
+ }
221
+ }
222
+ async exec(command, opts = {}) {
223
+ if (this.#closed) {
224
+ throw new PukuError('bash session terminated');
225
+ }
226
+ const timeoutMs = opts.timeoutMs ?? BASH_DEFAULT_TIMEOUT_MS;
227
+ const signal = opts.signal;
228
+ // Reject with the signal's own reason, so a caller telling a user cancel
229
+ // apart from an `AbortSignal.timeout()` sees the platform's name intact.
230
+ signal?.throwIfAborted();
231
+ this.#buf = '';
232
+ this.#truncated = false;
233
+ // Per-call nonce so a command that prints a fixed marker can't spoof the
234
+ // exit-code framing. The `''` split keeps the literal out of what we write
235
+ // to stdin — only the shell's printf reassembles it.
236
+ const sentinel = `__ANT_CMD_${crypto.randomUUID()}_DONE__`;
237
+ const sentinelSplit = `${sentinel.slice(0, 8)}''${sentinel.slice(8)}`;
238
+ // </dev/null: a stdin-reading command (`cat`, `read`) gets EOF instead of
239
+ // blocking on the shared pipe until the timeout.
240
+ const wrapped = `{ ${command}\n} </dev/null 2>&1; printf '\\n${sentinelSplit}%d\\n' $?\n`;
241
+ this.#proc.stdin.write(wrapped);
242
+ if (this.#buf.indexOf(sentinel) < 0) {
243
+ // Park until the sentinel lands, the deadline passes, the caller aborts,
244
+ // or the shell dies — whichever comes first. `#append` (and the `close`
245
+ // handler) resolve `sentinelSeen`; the deadline / abort reject.
246
+ const { promise: sentinelSeen, resolve } = promiseWithResolvers();
247
+ this.#waiting = { sentinel, resolve };
248
+ let timer;
249
+ let onAbort;
250
+ try {
251
+ await Promise.race([
252
+ sentinelSeen,
253
+ new Promise((_, reject) => {
254
+ timer = setTimeout(() => reject(new BashTimeoutError(timeoutMs)), timeoutMs);
255
+ }),
256
+ new Promise((_, reject) => {
257
+ if (!signal)
258
+ return;
259
+ onAbort = () => reject(signal.reason);
260
+ signal.addEventListener('abort', onAbort, { once: true });
261
+ }),
262
+ ]);
263
+ }
264
+ finally {
265
+ if (timer)
266
+ clearTimeout(timer);
267
+ if (onAbort && signal)
268
+ signal.removeEventListener('abort', onAbort);
269
+ this.#waiting = null;
270
+ }
271
+ }
272
+ const idx = this.#buf.indexOf(sentinel);
273
+ if (idx < 0) {
274
+ // The shell closed (or was killed) before emitting the sentinel.
275
+ throw new PukuError('bash session terminated');
276
+ }
277
+ const tail = this.#buf.slice(idx + sentinel.length);
278
+ const m = tail.match(/^(-?\d+)/);
279
+ const exitCode = m ? parseInt(m[1], 10) : -1;
280
+ let out = this.#buf.slice(0, idx).replace(ANSI_RE, '').replace(/\n+$/, '');
281
+ if (this.#truncated) {
282
+ out = `[output truncated]\n${out}`;
283
+ }
284
+ return { output: out, exitCode };
285
+ }
286
+ close() {
287
+ if (this.#closed)
288
+ return;
289
+ this.#closed = true;
290
+ const w = this.#waiting;
291
+ this.#waiting = null;
292
+ w?.resolve();
293
+ this.#proc.stdout.destroy();
294
+ this.#proc.stderr.destroy();
295
+ this.#proc.stdin.destroy();
296
+ try {
297
+ // Negative PID targets the process group so foreground jobs (e.g. a
298
+ // hung sleep) die with the shell.
299
+ process.kill(-this.#proc.pid, 'SIGKILL');
300
+ }
301
+ catch {
302
+ this.#proc.kill('SIGKILL');
303
+ }
304
+ this.#proc.unref();
305
+ }
306
+ }
307
+ export function betaBashTool(ctx) {
308
+ rejectUnrestrictedPaths(ctx.unrestrictedPaths);
309
+ let session;
310
+ // Concurrent run() callers chain onto this promise so writes to the shared
311
+ // shell's stdin can't interleave (which would corrupt the sentinel-match
312
+ // exit-code parsing in BashSession.exec). Each call replaces `tail` with a
313
+ // promise that resolves only after its own exec settles.
314
+ let tail = Promise.resolve();
315
+ return betaTool({
316
+ name: 'bash',
317
+ description: 'Run a bash command in a persistent shell. State (cwd, env vars) persists across calls.',
318
+ inputSchema: {
319
+ type: 'object',
320
+ properties: {
321
+ command: { type: 'string', description: 'The command to run' },
322
+ restart: { type: 'boolean', description: 'Restart the persistent shell before running' },
323
+ timeout_ms: { type: 'integer', description: 'Per-call timeout in milliseconds' },
324
+ },
325
+ },
326
+ run: async ({ command, restart, timeout_ms }, context) => {
327
+ const prev = tail;
328
+ const gate = promiseWithResolvers();
329
+ tail = gate.promise;
330
+ // Swallow prior rejections — earlier callers got their own error path;
331
+ // we just need to wait for the shell to be free.
332
+ try {
333
+ await prev;
334
+ }
335
+ catch {
336
+ // ignore
337
+ }
338
+ try {
339
+ if (restart) {
340
+ session?.close();
341
+ session = undefined;
342
+ }
343
+ if (!command) {
344
+ if (restart)
345
+ return 'bash session restarted';
346
+ throw new ToolError('bash: command is required');
347
+ }
348
+ session ??= new BashSession(ctx.workdir, ctx.env);
349
+ try {
350
+ const { output, exitCode } = await session.exec(command, {
351
+ timeoutMs: timeout_ms ?? BASH_DEFAULT_TIMEOUT_MS,
352
+ signal: context?.signal,
353
+ });
354
+ if (exitCode !== 0)
355
+ throw new ToolError(output || `exit ${exitCode}`);
356
+ return output;
357
+ }
358
+ catch (e) {
359
+ if (e instanceof ToolError)
360
+ throw e;
361
+ // Timeout, abort, or terminated: the still-running command will emit
362
+ // a stale sentinel, so discard this session and let the next call
363
+ // start fresh.
364
+ session.close();
365
+ session = undefined;
366
+ throw new ToolError(`bash: ${e instanceof Error ? e.message : String(e)}`);
367
+ }
368
+ }
369
+ finally {
370
+ gate.resolve();
371
+ }
372
+ },
373
+ close: () => {
374
+ session?.close();
375
+ session = undefined;
376
+ },
377
+ });
378
+ }
379
+ // ---- fs ------------------------------------------------------------------
380
+ export function betaReadTool(ctx) {
381
+ rejectUnrestrictedPaths(ctx.unrestrictedPaths);
382
+ return betaTool({
383
+ name: 'read',
384
+ description: 'Read a UTF-8 text file relative to the workdir.',
385
+ inputSchema: {
386
+ type: 'object',
387
+ properties: {
388
+ file_path: { type: 'string' },
389
+ view_range: {
390
+ type: 'array',
391
+ items: { type: 'integer' },
392
+ description: '[start_line, end_line] 1-indexed inclusive',
393
+ },
394
+ },
395
+ required: ['file_path'],
396
+ },
397
+ run: async ({ file_path, view_range }) => {
398
+ if (!file_path)
399
+ throw new ToolError('read: file_path is required');
400
+ const abs = await resolvePath(ctx, file_path);
401
+ if (view_range?.length && view_range.length !== 2) {
402
+ throw new ToolError('read: view_range must be [start_line, end_line]');
403
+ }
404
+ let data;
405
+ try {
406
+ // stat() before any open(): the size cap stops a multi-GB file from
407
+ // OOM'ing the runner, and isFile() rejects FIFOs/devices/dirs without
408
+ // opening them (open() on an unconnected FIFO blocks indefinitely).
409
+ const st = await fs.stat(abs);
410
+ if (!st.isFile()) {
411
+ throw new ToolError(`read: ${file_path} is not a regular file`);
412
+ }
413
+ const limit = resolveMaxBytes(ctx.maxFileBytes);
414
+ if (limit !== null && st.size > limit) {
415
+ if (!view_range?.length) {
416
+ throw new ToolError(`read: ${file_path} is ${st.size} bytes, exceeds ${limit}-byte limit. ` +
417
+ 'Use the view_range parameter to read specific line ranges, e.g. view_range: [1, 500].');
418
+ }
419
+ const [startLine, endLine] = view_range;
420
+ return await readRangeStreaming(abs, file_path, startLine, endLine, limit);
421
+ }
422
+ data = await fs.readFile(abs, 'utf8');
423
+ }
424
+ catch (e) {
425
+ if (e instanceof ToolError)
426
+ throw e;
427
+ throw new ToolError(`read: ${fsErrorMessage(e, file_path)}`);
428
+ }
429
+ if (!view_range?.length)
430
+ return data;
431
+ const [startLine, endLine] = view_range;
432
+ const lines = data.split('\n');
433
+ const start = Math.max(0, startLine - 1);
434
+ const end = endLine > 0 ? endLine : lines.length;
435
+ return lines.slice(start, end).join('\n');
436
+ },
437
+ });
438
+ }
439
+ /** Returns lines `[startLine, endLine]` of the file at `abs`, capping the selected bytes at `limit`. */
440
+ async function readRangeStreaming(abs, filePath, startLine, endLine, limit) {
441
+ const lines = new LineRangeCollector(filePath, startLine, endLine, limit);
442
+ if (lines.rangeIsEmpty())
443
+ return '';
444
+ // Byte chunks rather than readline: a single huge line must never be buffered
445
+ // whole, so memory stays bounded by `limit` plus one chunk.
446
+ const stream = fssync.createReadStream(abs, { highWaterMark: READ_STREAM_CHUNK_BYTES });
447
+ try {
448
+ for await (const chunk of stream) {
449
+ lines.collectFrom(chunk);
450
+ if (lines.rangeIsCollected())
451
+ break;
452
+ }
453
+ }
454
+ finally {
455
+ stream.destroy();
456
+ }
457
+ return lines.text();
458
+ }
459
+ /** Collects the bytes of lines `[startLine, endLine]` from consecutive file chunks, capped at `limit`. */
460
+ class LineRangeCollector {
461
+ #filePath;
462
+ #startLine;
463
+ #endLine;
464
+ #start;
465
+ #end;
466
+ #limit;
467
+ #line = 0;
468
+ #collected = [];
469
+ #collectedBytes = 0;
470
+ constructor(filePath, startLine, endLine, limit) {
471
+ this.#filePath = filePath;
472
+ this.#startLine = startLine;
473
+ this.#endLine = endLine;
474
+ this.#start = Math.max(0, startLine - 1);
475
+ this.#end = endLine > 0 ? endLine : Infinity;
476
+ this.#limit = limit;
477
+ }
478
+ rangeIsEmpty() {
479
+ return this.#end <= this.#start;
480
+ }
481
+ rangeIsCollected() {
482
+ return this.#line >= this.#end;
483
+ }
484
+ collectFrom(chunk) {
485
+ let lineStart = 0;
486
+ while (lineStart < chunk.length && !this.rangeIsCollected()) {
487
+ const newline = chunk.indexOf(0x0a, lineStart);
488
+ const lineEnd = newline < 0 ? chunk.length : newline;
489
+ if (this.#line >= this.#start) {
490
+ this.#collect(chunk.subarray(lineStart, lineEnd), newline >= 0);
491
+ }
492
+ if (newline < 0)
493
+ break;
494
+ this.#line++;
495
+ lineStart = newline + 1;
496
+ }
497
+ }
498
+ #collect(lineBytes, newlineTerminated) {
499
+ this.#collected.push(lineBytes);
500
+ this.#collectedBytes += lineBytes.length;
501
+ if (newlineTerminated && this.#line + 1 < this.#end) {
502
+ this.#collected.push(NEWLINE);
503
+ this.#collectedBytes += NEWLINE.length;
504
+ }
505
+ if (this.#collectedBytes > this.#limit)
506
+ throw this.#overLimitError();
507
+ }
508
+ #overLimitError() {
509
+ if (this.#end - this.#start === 1) {
510
+ return new ToolError(`read: line ${this.#start + 1} of ${this.#filePath} alone exceeds ${this.#limit}-byte limit. ` +
511
+ 'The read tool cannot return part of a line, so view_range cannot narrow this further.');
512
+ }
513
+ return new ToolError(`read: view_range [${this.#startLine}, ${this.#endLine}] of ${this.#filePath} exceeds ${this.#limit}-byte limit. ` +
514
+ 'Narrow the view_range to read a smaller portion.');
515
+ }
516
+ text() {
517
+ return Buffer.concat(this.#collected, this.#collectedBytes).toString('utf8');
518
+ }
519
+ }
520
+ export function betaWriteTool(ctx) {
521
+ rejectUnrestrictedPaths(ctx.unrestrictedPaths);
522
+ return betaTool({
523
+ name: 'write',
524
+ description: 'Write a UTF-8 text file relative to the workdir, creating parent directories as needed.',
525
+ inputSchema: {
526
+ type: 'object',
527
+ properties: { file_path: { type: 'string' }, content: { type: 'string' } },
528
+ required: ['file_path', 'content'],
529
+ },
530
+ run: async ({ file_path, content }) => {
531
+ if (!file_path)
532
+ throw new ToolError('write: file_path is required');
533
+ const abs = await resolvePath(ctx, file_path);
534
+ const ro = await readOnlyRootFor(ctx, abs);
535
+ if (ro !== undefined) {
536
+ throw new ToolError(`write: ${file_path} is inside read-only directory ${ro}`);
537
+ }
538
+ try {
539
+ await fs.mkdir(path.dirname(abs), { recursive: true, mode: DIR_CREATE_MODE });
540
+ await atomicWriteFile(abs, content ?? '');
541
+ }
542
+ catch (e) {
543
+ throw new ToolError(`write: ${fsErrorMessage(e, file_path)}`);
544
+ }
545
+ return `wrote ${Buffer.byteLength(content ?? '')} bytes to ${file_path}`;
546
+ },
547
+ });
548
+ }
549
+ export function betaEditTool(ctx) {
550
+ rejectUnrestrictedPaths(ctx.unrestrictedPaths);
551
+ return betaTool({
552
+ name: 'edit',
553
+ description: 'Replace old_string with new_string in a file. old_string must be unique unless replace_all.',
554
+ inputSchema: {
555
+ type: 'object',
556
+ properties: {
557
+ file_path: { type: 'string' },
558
+ old_string: { type: 'string' },
559
+ new_string: { type: 'string' },
560
+ replace_all: { type: 'boolean' },
561
+ },
562
+ required: ['file_path', 'old_string', 'new_string'],
563
+ },
564
+ run: async ({ file_path, old_string, new_string, replace_all }) => {
565
+ if (!file_path)
566
+ throw new ToolError('edit: file_path is required');
567
+ if (!old_string)
568
+ throw new ToolError('edit: old_string is required');
569
+ const abs = await resolvePath(ctx, file_path);
570
+ const ro = await readOnlyRootFor(ctx, abs);
571
+ if (ro !== undefined) {
572
+ throw new ToolError(`edit: ${file_path} is inside read-only directory ${ro}`);
573
+ }
574
+ let data;
575
+ try {
576
+ // stat() before any open() — same guard as `read`: the size cap stops a
577
+ // multi-GB file from OOM'ing the runner, and isFile() rejects
578
+ // FIFOs/devices/dirs without opening them (open() on an unconnected FIFO
579
+ // blocks indefinitely). The edit path is model-controlled, so it needs
580
+ // the same bound `read` already has.
581
+ const st = await fs.stat(abs);
582
+ if (!st.isFile()) {
583
+ throw new ToolError(`edit: ${file_path} is not a regular file`);
584
+ }
585
+ const limit = resolveMaxBytes(ctx.maxFileBytes);
586
+ if (limit !== null && st.size > limit) {
587
+ throw new ToolError(`edit: ${file_path} is ${st.size} bytes, exceeds ${limit}-byte limit. ` +
588
+ 'The edit tool loads the whole file and cannot modify a file this large.');
589
+ }
590
+ data = await fs.readFile(abs, 'utf8');
591
+ }
592
+ catch (e) {
593
+ if (e instanceof ToolError)
594
+ throw e;
595
+ throw new ToolError(`edit: ${fsErrorMessage(e, file_path)}`);
596
+ }
597
+ const count = data.split(old_string).length - 1;
598
+ if (count === 0)
599
+ throw new ToolError(`edit: old_string not found in ${file_path}`);
600
+ let updated;
601
+ if (replace_all) {
602
+ updated = data.split(old_string).join(new_string);
603
+ }
604
+ else {
605
+ if (count > 1)
606
+ throw new ToolError(`edit: old_string appears ${count} times in ${file_path} (must be unique)`);
607
+ // Callback form so `$&`/`$1`/`` $` `` in new_string are inserted
608
+ // literally instead of expanded as replacement patterns.
609
+ updated = data.replace(old_string, () => new_string);
610
+ }
611
+ try {
612
+ await atomicWriteFile(abs, updated);
613
+ }
614
+ catch (e) {
615
+ throw new ToolError(`edit: write: ${fsErrorMessage(e, file_path)}`);
616
+ }
617
+ return `edited ${file_path} (${replace_all ? count : 1} replacement(s))`;
618
+ },
619
+ });
620
+ }
621
+ // ---- search --------------------------------------------------------------
622
+ /**
623
+ * Best-effort: stops `fs.glob` from walking out of the root via a literal or
624
+ * brace-expanded `..`. The realpath post-filter in {@link betaGlobTool} is the
625
+ * boundary; this only avoids the walk.
626
+ */
627
+ function patternCanAscend(pattern) {
628
+ return pattern.split(/[\\/{},]/).includes('..');
629
+ }
630
+ export function betaGlobTool(ctx) {
631
+ rejectUnrestrictedPaths(ctx.unrestrictedPaths);
632
+ return betaTool({
633
+ name: 'glob',
634
+ description: 'Match files under the workdir against a glob pattern. Results are mtime-sorted, newest first.',
635
+ inputSchema: {
636
+ type: 'object',
637
+ properties: {
638
+ pattern: { type: 'string' },
639
+ path: { type: 'string', description: 'Directory to search in. Defaults to the workdir.' },
640
+ },
641
+ required: ['pattern'],
642
+ },
643
+ run: async ({ pattern, path: searchPath }) => {
644
+ if (!pattern)
645
+ throw new ToolError('glob: pattern is required');
646
+ if (path.isAbsolute(pattern)) {
647
+ throw new ToolError('glob: absolute pattern not permitted; pass a relative pattern (and optionally path)');
648
+ }
649
+ if (patternCanAscend(pattern)) {
650
+ throw new ToolError('glob: ".." is not permitted in the pattern');
651
+ }
652
+ const root = searchPath ? await resolvePath(ctx, searchPath) : path.resolve(ctx.workdir);
653
+ // Compare canonical against canonical: a workdir that is itself a
654
+ // symlink would otherwise falsely reject every realpath'd match below.
655
+ const realRoot = searchPath ? root : await canonicalize(root);
656
+ const matches = [];
657
+ // Bounds the walk for patterns that match, or brace-expand into,
658
+ // enormous trees.
659
+ let remaining = WALK_MAX_ENTRIES;
660
+ try {
661
+ // Native `fs.glob` (Node 22+). `exclude` prunes the noisy dirs the
662
+ // legacy walker skipped; only regular files are collected.
663
+ for await (const entry of fsGlob(pattern, {
664
+ cwd: root,
665
+ withFileTypes: true,
666
+ exclude: (d) => d.name === '.git' || d.name === 'node_modules',
667
+ })) {
668
+ if (remaining-- <= 0)
669
+ break;
670
+ if (!entry.isFile())
671
+ continue;
672
+ const full = path.join(entry.parentPath, entry.name);
673
+ // Drop any match that resolves outside the search root. A pattern
674
+ // that *names* a symlinked directory (the model controls the
675
+ // pattern, and the bash tool in the same session can plant the
676
+ // link) makes `fs.glob` descend through it and report entries with
677
+ // the raw parent path, so a lexical check on `full` alone would
678
+ // pass `root/link_out/secret` even though it lives outside the
679
+ // jail. Resolve-failure (ELOOP, EACCES, a racing unlink) is a deny.
680
+ let real;
681
+ try {
682
+ real = await fs.realpath(full);
683
+ }
684
+ catch {
685
+ continue;
686
+ }
687
+ if (!isWithin(realRoot, real))
688
+ continue;
689
+ let mtime = 0;
690
+ try {
691
+ mtime = (await fs.stat(full)).mtimeMs;
692
+ }
693
+ catch {
694
+ // unreadable — keep it in the list with mtime 0
695
+ }
696
+ matches.push({ path: full, mtime });
697
+ }
698
+ }
699
+ catch (e) {
700
+ throw new ToolError(`glob: ${e instanceof Error ? e.message : String(e)}`);
701
+ }
702
+ if (matches.length === 0)
703
+ return 'no matches';
704
+ matches.sort((a, b) => b.mtime - a.mtime);
705
+ return matches
706
+ .slice(0, GLOB_RESULT_LIMIT)
707
+ .map((m) => m.path)
708
+ .join('\n');
709
+ },
710
+ });
711
+ }
712
+ export function betaGrepTool(ctx) {
713
+ rejectUnrestrictedPaths(ctx.unrestrictedPaths);
714
+ return betaTool({
715
+ name: 'grep',
716
+ description: 'Search file contents for a regex. Uses ripgrep if available, otherwise a built-in walker.',
717
+ inputSchema: {
718
+ type: 'object',
719
+ properties: { pattern: { type: 'string' }, path: { type: 'string' } },
720
+ required: ['pattern'],
721
+ },
722
+ run: async ({ pattern, path: p }, context) => {
723
+ if (!pattern)
724
+ throw new ToolError('grep: pattern is required');
725
+ let searchPath = path.resolve(ctx.workdir);
726
+ if (p)
727
+ searchPath = await resolvePath(ctx, p);
728
+ const rg = await findRg();
729
+ return rg ?
730
+ runRipgrep(rg, pattern, searchPath, context?.signal)
731
+ : runWalkGrep(pattern, searchPath, context?.signal);
732
+ },
733
+ });
734
+ }
735
+ function runRipgrep(rg, pattern, searchPath, signal) {
736
+ return new Promise((resolve, reject) => {
737
+ const proc = cp.spawn(rg, ['-n', '--no-heading', '-e', pattern, '--', searchPath], {
738
+ ...(signal ? { signal } : {}),
739
+ });
740
+ let out = '';
741
+ let errOut = '';
742
+ let truncated = false;
743
+ proc.stdout.on('data', (d) => {
744
+ if (truncated)
745
+ return;
746
+ out += d;
747
+ if (out.length > GREP_OUTPUT_LIMIT) {
748
+ truncated = true;
749
+ out = out.slice(0, GREP_OUTPUT_LIMIT);
750
+ proc.kill('SIGKILL');
751
+ }
752
+ });
753
+ proc.stderr.on('data', (d) => (errOut += d));
754
+ proc.on('close', (code) => {
755
+ if (signal?.aborted)
756
+ return reject(new ToolError('grep: aborted'));
757
+ if (truncated)
758
+ return resolve(out + `\n[output truncated at ${GREP_OUTPUT_LIMIT} bytes]`);
759
+ if (code === 0)
760
+ return resolve(out);
761
+ if (code === 1)
762
+ return resolve('no matches');
763
+ reject(new ToolError(`grep: rg failed: ${errOut || `exit ${code}`}`));
764
+ });
765
+ proc.on('error', (e) => {
766
+ if (signal?.aborted)
767
+ return reject(new ToolError('grep: aborted'));
768
+ reject(new ToolError(`grep: rg failed: ${e.message}`));
769
+ });
770
+ });
771
+ }
772
+ async function runWalkGrep(pattern, root, signal) {
773
+ let re;
774
+ try {
775
+ re = new RegExp(pattern);
776
+ }
777
+ catch (e) {
778
+ throw new ToolError(`grep: invalid regex: ${e instanceof Error ? e.message : String(e)}`);
779
+ }
780
+ const hits = [];
781
+ let budget = GREP_OUTPUT_LIMIT;
782
+ const push = (line) => {
783
+ budget -= line.length + 1;
784
+ if (budget < 0) {
785
+ hits.push(`[output truncated at ${GREP_OUTPUT_LIMIT} bytes]`);
786
+ return false;
787
+ }
788
+ hits.push(line);
789
+ return true;
790
+ };
791
+ const stat = await fs.stat(root).catch(() => null);
792
+ if (stat?.isFile()) {
793
+ await grepFile(root, re, push);
794
+ }
795
+ else {
796
+ await walk(root, '', (rel) => grepFile(path.join(root, rel), re, push), signal);
797
+ }
798
+ if (signal?.aborted)
799
+ throw new ToolError('grep: aborted');
800
+ if (hits.length === 0)
801
+ return 'no matches';
802
+ return hits.join('\n');
803
+ }
804
+ async function grepFile(file, re, push) {
805
+ const stream = fssync.createReadStream(file, { encoding: 'utf8' });
806
+ const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
807
+ let i = 0;
808
+ try {
809
+ for await (const line of rl) {
810
+ i++;
811
+ // Cap line length: `pattern` is model-supplied and JS regexes backtrack,
812
+ // so a pathological pattern against a very long line is a ReDoS.
813
+ if (line.length > GREP_MAX_LINE_LENGTH)
814
+ continue;
815
+ if (re.test(line) && !push(`${file}:${i}:${line}`))
816
+ return false;
817
+ }
818
+ }
819
+ catch {
820
+ // unreadable / binary
821
+ }
822
+ finally {
823
+ stream.destroy();
824
+ }
825
+ return true;
826
+ }
827
+ // ---- utils ---------------------------------------------------------------
828
+ const WALK_MAX_DEPTH = 40;
829
+ const WALK_MAX_ENTRIES = 50_000;
830
+ /**
831
+ * Bounded recursive walk. `fn` may return `false` to abort. Only real
832
+ * directories are descended into and only real files are handed to `fn` —
833
+ * symlinks (and devices/fifos/sockets) are skipped entirely so a symlink inside
834
+ * the root cannot be followed out of it.
835
+ */
836
+ async function walk(root, rel, fn, signal) {
837
+ let remaining = WALK_MAX_ENTRIES;
838
+ async function inner(rel, depth) {
839
+ if (depth > WALK_MAX_DEPTH)
840
+ return true;
841
+ if (signal?.aborted)
842
+ return false;
843
+ let entries;
844
+ try {
845
+ entries = await fs.readdir(path.join(root, rel), { withFileTypes: true });
846
+ }
847
+ catch {
848
+ return true;
849
+ }
850
+ for (const e of entries) {
851
+ if (e.name === '.git' || e.name === 'node_modules')
852
+ continue;
853
+ if (remaining-- <= 0)
854
+ return false;
855
+ if (signal?.aborted)
856
+ return false;
857
+ const childRel = rel ? path.join(rel, e.name) : e.name;
858
+ if (e.isDirectory()) {
859
+ if (!(await inner(childRel, depth + 1)))
860
+ return false;
861
+ }
862
+ else if (e.isFile()) {
863
+ if ((await fn(childRel)) === false)
864
+ return false;
865
+ }
866
+ // Symlinks, devices, fifos and sockets are intentionally skipped.
867
+ }
868
+ return true;
869
+ }
870
+ await inner(rel, 0);
871
+ }
872
+ async function findRg() {
873
+ const dirs = (process.env['PATH'] ?? '').split(path.delimiter);
874
+ for (const d of dirs) {
875
+ const candidate = path.join(d, 'rg');
876
+ try {
877
+ await fs.access(candidate, fssync.constants.X_OK);
878
+ return candidate;
879
+ }
880
+ catch {
881
+ // not here
882
+ }
883
+ }
884
+ return null;
885
+ }
886
+ //# sourceMappingURL=node.js.map