operon-agents-core 0.1.0-alpha.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 (511) hide show
  1. package/LICENSE +55 -0
  2. package/README.md +7 -0
  3. package/dist/agent/agent.d.ts +65 -0
  4. package/dist/agent/agent.js +39 -0
  5. package/dist/agent/compose-hooks.d.ts +13 -0
  6. package/dist/agent/compose-hooks.js +197 -0
  7. package/dist/agent/concurrency.d.ts +22 -0
  8. package/dist/agent/concurrency.js +70 -0
  9. package/dist/agent/context-report.d.ts +60 -0
  10. package/dist/agent/context-report.js +45 -0
  11. package/dist/agent/graph.d.ts +48 -0
  12. package/dist/agent/graph.js +129 -0
  13. package/dist/agent/guardrail.d.ts +105 -0
  14. package/dist/agent/guardrail.js +314 -0
  15. package/dist/agent/handoff-executor.d.ts +21 -0
  16. package/dist/agent/handoff-executor.js +95 -0
  17. package/dist/agent/handoff.d.ts +42 -0
  18. package/dist/agent/handoff.js +70 -0
  19. package/dist/agent/index.d.ts +25 -0
  20. package/dist/agent/index.js +19 -0
  21. package/dist/agent/instruction-context.d.ts +33 -0
  22. package/dist/agent/instruction-context.js +100 -0
  23. package/dist/agent/pause.d.ts +12 -0
  24. package/dist/agent/pause.js +82 -0
  25. package/dist/agent/profile-builtins.d.ts +8 -0
  26. package/dist/agent/profile-builtins.js +130 -0
  27. package/dist/agent/profiles.d.ts +94 -0
  28. package/dist/agent/profiles.js +264 -0
  29. package/dist/agent/recovery.d.ts +10 -0
  30. package/dist/agent/recovery.js +151 -0
  31. package/dist/agent/run-support.d.ts +79 -0
  32. package/dist/agent/run-support.js +211 -0
  33. package/dist/agent/runner.d.ts +246 -0
  34. package/dist/agent/runner.js +786 -0
  35. package/dist/agent/session.d.ts +363 -0
  36. package/dist/agent/session.js +937 -0
  37. package/dist/agent/subagent-tools.d.ts +18 -0
  38. package/dist/agent/subagent-tools.js +650 -0
  39. package/dist/agent/subagent.d.ts +56 -0
  40. package/dist/agent/subagent.js +50 -0
  41. package/dist/agent/toolset.d.ts +24 -0
  42. package/dist/agent/toolset.js +112 -0
  43. package/dist/agent/workflow/index.d.ts +9 -0
  44. package/dist/agent/workflow/index.js +8 -0
  45. package/dist/agent/workflow/journal.d.ts +180 -0
  46. package/dist/agent/workflow/journal.js +224 -0
  47. package/dist/agent/workflow/manager.d.ts +27 -0
  48. package/dist/agent/workflow/manager.js +33 -0
  49. package/dist/agent/workflow/parse.d.ts +17 -0
  50. package/dist/agent/workflow/parse.js +174 -0
  51. package/dist/agent/workflow/prompt.d.ts +8 -0
  52. package/dist/agent/workflow/prompt.js +84 -0
  53. package/dist/agent/workflow/runtime.d.ts +64 -0
  54. package/dist/agent/workflow/runtime.js +380 -0
  55. package/dist/agent/workflow/sandbox.d.ts +35 -0
  56. package/dist/agent/workflow/sandbox.js +90 -0
  57. package/dist/agent/workflow/snapshot.d.ts +36 -0
  58. package/dist/agent/workflow/snapshot.js +9 -0
  59. package/dist/agent/workflow/structured.d.ts +35 -0
  60. package/dist/agent/workflow/structured.js +79 -0
  61. package/dist/agent/workflow/tool.d.ts +14 -0
  62. package/dist/agent/workflow/tool.js +569 -0
  63. package/dist/agent/workflow/types.d.ts +100 -0
  64. package/dist/agent/workflow/types.js +17 -0
  65. package/dist/agent/worktree.d.ts +38 -0
  66. package/dist/agent/worktree.js +56 -0
  67. package/dist/capabilities/assembler.d.ts +39 -0
  68. package/dist/capabilities/assembler.js +171 -0
  69. package/dist/capabilities/background/agent-task.d.ts +51 -0
  70. package/dist/capabilities/background/agent-task.js +101 -0
  71. package/dist/capabilities/background/command-task.d.ts +43 -0
  72. package/dist/capabilities/background/command-task.js +86 -0
  73. package/dist/capabilities/background/index.d.ts +20 -0
  74. package/dist/capabilities/background/index.js +57 -0
  75. package/dist/capabilities/background/manager.d.ts +194 -0
  76. package/dist/capabilities/background/manager.js +1131 -0
  77. package/dist/capabilities/background/persist-disk.d.ts +17 -0
  78. package/dist/capabilities/background/persist-disk.js +66 -0
  79. package/dist/capabilities/background/persist.d.ts +61 -0
  80. package/dist/capabilities/background/persist.js +117 -0
  81. package/dist/capabilities/background/question-task.d.ts +32 -0
  82. package/dist/capabilities/background/question-task.js +56 -0
  83. package/dist/capabilities/background/registrar.d.ts +12 -0
  84. package/dist/capabilities/background/registrar.js +9 -0
  85. package/dist/capabilities/background/swappable-sink.d.ts +20 -0
  86. package/dist/capabilities/background/swappable-sink.js +20 -0
  87. package/dist/capabilities/background/task.d.ts +114 -0
  88. package/dist/capabilities/background/task.js +20 -0
  89. package/dist/capabilities/background/tools.d.ts +6 -0
  90. package/dist/capabilities/background/tools.js +190 -0
  91. package/dist/capabilities/background/workflow-task.d.ts +48 -0
  92. package/dist/capabilities/background/workflow-task.js +91 -0
  93. package/dist/capabilities/capability-state.d.ts +13 -0
  94. package/dist/capabilities/capability-state.js +37 -0
  95. package/dist/capabilities/capability.d.ts +145 -0
  96. package/dist/capabilities/capability.js +2 -0
  97. package/dist/capabilities/compaction/full.d.ts +27 -0
  98. package/dist/capabilities/compaction/full.js +155 -0
  99. package/dist/capabilities/compaction/index.d.ts +17 -0
  100. package/dist/capabilities/compaction/index.js +145 -0
  101. package/dist/capabilities/compaction/instruction.d.ts +2 -0
  102. package/dist/capabilities/compaction/instruction.js +31 -0
  103. package/dist/capabilities/compaction/micro.d.ts +17 -0
  104. package/dist/capabilities/compaction/micro.js +57 -0
  105. package/dist/capabilities/compaction/service.d.ts +28 -0
  106. package/dist/capabilities/compaction/service.js +52 -0
  107. package/dist/capabilities/compaction/strategy.d.ts +43 -0
  108. package/dist/capabilities/compaction/strategy.js +116 -0
  109. package/dist/capabilities/compaction/tokens.d.ts +5 -0
  110. package/dist/capabilities/compaction/tokens.js +28 -0
  111. package/dist/capabilities/goal/goal-store.d.ts +69 -0
  112. package/dist/capabilities/goal/goal-store.js +172 -0
  113. package/dist/capabilities/goal/index.d.ts +6 -0
  114. package/dist/capabilities/goal/index.js +31 -0
  115. package/dist/capabilities/goal/injector.d.ts +9 -0
  116. package/dist/capabilities/goal/injector.js +79 -0
  117. package/dist/capabilities/goal/tools.d.ts +6 -0
  118. package/dist/capabilities/goal/tools.js +86 -0
  119. package/dist/capabilities/index.d.ts +25 -0
  120. package/dist/capabilities/index.js +22 -0
  121. package/dist/capabilities/injection.d.ts +44 -0
  122. package/dist/capabilities/injection.js +112 -0
  123. package/dist/capabilities/plan/index.d.ts +6 -0
  124. package/dist/capabilities/plan/index.js +25 -0
  125. package/dist/capabilities/plan/injector.d.ts +13 -0
  126. package/dist/capabilities/plan/injector.js +83 -0
  127. package/dist/capabilities/plan/plan-mode.d.ts +38 -0
  128. package/dist/capabilities/plan/plan-mode.js +113 -0
  129. package/dist/capabilities/plan/policies.d.ts +6 -0
  130. package/dist/capabilities/plan/policies.js +89 -0
  131. package/dist/capabilities/plan/tools.d.ts +15 -0
  132. package/dist/capabilities/plan/tools.js +87 -0
  133. package/dist/capabilities/skills/flow-provider.d.ts +6 -0
  134. package/dist/capabilities/skills/flow-provider.js +50 -0
  135. package/dist/capabilities/skills/index.d.ts +43 -0
  136. package/dist/capabilities/skills/index.js +48 -0
  137. package/dist/capabilities/skills/injector.d.ts +11 -0
  138. package/dist/capabilities/skills/injector.js +27 -0
  139. package/dist/capabilities/skills/parser.d.ts +36 -0
  140. package/dist/capabilities/skills/parser.js +334 -0
  141. package/dist/capabilities/skills/registry.d.ts +33 -0
  142. package/dist/capabilities/skills/registry.js +118 -0
  143. package/dist/capabilities/skills/scanner.d.ts +26 -0
  144. package/dist/capabilities/skills/scanner.js +154 -0
  145. package/dist/capabilities/skills/service.d.ts +39 -0
  146. package/dist/capabilities/skills/service.js +68 -0
  147. package/dist/capabilities/skills/skill-tool.d.ts +13 -0
  148. package/dist/capabilities/skills/skill-tool.js +72 -0
  149. package/dist/capabilities/skills/types.d.ts +62 -0
  150. package/dist/capabilities/skills/types.js +26 -0
  151. package/dist/capabilities/task/index.d.ts +23 -0
  152. package/dist/capabilities/task/index.js +38 -0
  153. package/dist/capabilities/task/injector.d.ts +9 -0
  154. package/dist/capabilities/task/injector.js +62 -0
  155. package/dist/capabilities/task/persist-disk.d.ts +19 -0
  156. package/dist/capabilities/task/persist-disk.js +84 -0
  157. package/dist/capabilities/task/persist.d.ts +52 -0
  158. package/dist/capabilities/task/persist.js +84 -0
  159. package/dist/capabilities/task/task-store.d.ts +44 -0
  160. package/dist/capabilities/task/task-store.js +106 -0
  161. package/dist/capabilities/task/tools.d.ts +12 -0
  162. package/dist/capabilities/task/tools.js +164 -0
  163. package/dist/capabilities/todo/index.d.ts +8 -0
  164. package/dist/capabilities/todo/index.js +21 -0
  165. package/dist/capabilities/todo/injector.d.ts +9 -0
  166. package/dist/capabilities/todo/injector.js +68 -0
  167. package/dist/capabilities/todo/todo-store.d.ts +19 -0
  168. package/dist/capabilities/todo/todo-store.js +36 -0
  169. package/dist/capabilities/todo/tools.d.ts +6 -0
  170. package/dist/capabilities/todo/tools.js +70 -0
  171. package/dist/capabilities/tool-provider.d.ts +12 -0
  172. package/dist/capabilities/tool-provider.js +20 -0
  173. package/dist/capabilities/user-hooks/engine.d.ts +22 -0
  174. package/dist/capabilities/user-hooks/engine.js +105 -0
  175. package/dist/capabilities/user-hooks/index.d.ts +13 -0
  176. package/dist/capabilities/user-hooks/index.js +126 -0
  177. package/dist/capabilities/user-hooks/types.d.ts +26 -0
  178. package/dist/capabilities/user-hooks/types.js +19 -0
  179. package/dist/capabilities/workflow/index.d.ts +16 -0
  180. package/dist/capabilities/workflow/index.js +15 -0
  181. package/dist/commands/index.d.ts +31 -0
  182. package/dist/commands/index.js +318 -0
  183. package/dist/config/config-store.d.ts +29 -0
  184. package/dist/config/config-store.js +103 -0
  185. package/dist/config/file-source.d.ts +40 -0
  186. package/dist/config/file-source.js +78 -0
  187. package/dist/config/flags.d.ts +13 -0
  188. package/dist/config/flags.js +25 -0
  189. package/dist/config/index.d.ts +17 -0
  190. package/dist/config/index.js +10 -0
  191. package/dist/config/merge.d.ts +5 -0
  192. package/dist/config/merge.js +57 -0
  193. package/dist/config/model-catalog.d.ts +17 -0
  194. package/dist/config/model-catalog.js +37 -0
  195. package/dist/config/paths.d.ts +31 -0
  196. package/dist/config/paths.js +28 -0
  197. package/dist/config/provider-manager.d.ts +57 -0
  198. package/dist/config/provider-manager.js +344 -0
  199. package/dist/config/resolver.d.ts +40 -0
  200. package/dist/config/resolver.js +52 -0
  201. package/dist/config/schema.d.ts +389 -0
  202. package/dist/config/schema.js +132 -0
  203. package/dist/events/events.d.ts +348 -0
  204. package/dist/events/events.js +146 -0
  205. package/dist/events/index.d.ts +10 -0
  206. package/dist/events/index.js +5 -0
  207. package/dist/events/projection.d.ts +207 -0
  208. package/dist/events/projection.js +438 -0
  209. package/dist/events/publisher.d.ts +48 -0
  210. package/dist/events/publisher.js +404 -0
  211. package/dist/events/redacting-sink.d.ts +11 -0
  212. package/dist/events/redacting-sink.js +31 -0
  213. package/dist/home.d.ts +16 -0
  214. package/dist/home.js +20 -0
  215. package/dist/index.d.ts +22 -0
  216. package/dist/index.js +22 -0
  217. package/dist/internal.d.ts +33 -0
  218. package/dist/internal.js +29 -0
  219. package/dist/llm/auth.d.ts +22 -0
  220. package/dist/llm/auth.js +112 -0
  221. package/dist/llm/capability.d.ts +13 -0
  222. package/dist/llm/capability.js +45 -0
  223. package/dist/llm/define-model.d.ts +110 -0
  224. package/dist/llm/define-model.js +252 -0
  225. package/dist/llm/errors.d.ts +33 -0
  226. package/dist/llm/errors.js +154 -0
  227. package/dist/llm/index.d.ts +14 -0
  228. package/dist/llm/index.js +8 -0
  229. package/dist/llm/model.d.ts +43 -0
  230. package/dist/llm/model.js +9 -0
  231. package/dist/llm/retry.d.ts +35 -0
  232. package/dist/llm/retry.js +160 -0
  233. package/dist/llm/runtime.d.ts +25 -0
  234. package/dist/llm/runtime.js +38 -0
  235. package/dist/logging/diagnostics.d.ts +21 -0
  236. package/dist/logging/diagnostics.js +46 -0
  237. package/dist/logging/index.d.ts +11 -0
  238. package/dist/logging/index.js +7 -0
  239. package/dist/logging/logger.d.ts +25 -0
  240. package/dist/logging/logger.js +54 -0
  241. package/dist/logging/paths.d.ts +11 -0
  242. package/dist/logging/paths.js +20 -0
  243. package/dist/logging/policy.d.ts +5 -0
  244. package/dist/logging/policy.js +19 -0
  245. package/dist/logging/redact.d.ts +10 -0
  246. package/dist/logging/redact.js +95 -0
  247. package/dist/logging/sinks.d.ts +67 -0
  248. package/dist/logging/sinks.js +117 -0
  249. package/dist/loop/context.d.ts +69 -0
  250. package/dist/loop/context.js +129 -0
  251. package/dist/loop/errors.d.ts +8 -0
  252. package/dist/loop/errors.js +27 -0
  253. package/dist/loop/events.d.ts +14 -0
  254. package/dist/loop/events.js +2 -0
  255. package/dist/loop/index.d.ts +10 -0
  256. package/dist/loop/index.js +7 -0
  257. package/dist/loop/interruption.d.ts +118 -0
  258. package/dist/loop/interruption.js +191 -0
  259. package/dist/loop/run-turn.d.ts +54 -0
  260. package/dist/loop/run-turn.js +203 -0
  261. package/dist/loop/scheduler.d.ts +18 -0
  262. package/dist/loop/scheduler.js +71 -0
  263. package/dist/loop/steer.d.ts +122 -0
  264. package/dist/loop/steer.js +209 -0
  265. package/dist/loop/tool-call.d.ts +41 -0
  266. package/dist/loop/tool-call.js +326 -0
  267. package/dist/loop/turn-step.d.ts +57 -0
  268. package/dist/loop/turn-step.js +298 -0
  269. package/dist/loop/types.d.ts +217 -0
  270. package/dist/loop/types.js +2 -0
  271. package/dist/loop/usage.d.ts +6 -0
  272. package/dist/loop/usage.js +44 -0
  273. package/dist/mcp/auth-tool.d.ts +12 -0
  274. package/dist/mcp/auth-tool.js +92 -0
  275. package/dist/mcp/capability.d.ts +7 -0
  276. package/dist/mcp/capability.js +91 -0
  277. package/dist/mcp/config-loader.d.ts +28 -0
  278. package/dist/mcp/config-loader.js +115 -0
  279. package/dist/mcp/filter.d.ts +18 -0
  280. package/dist/mcp/filter.js +35 -0
  281. package/dist/mcp/index.d.ts +23 -0
  282. package/dist/mcp/index.js +13 -0
  283. package/dist/mcp/manager.d.ts +51 -0
  284. package/dist/mcp/manager.js +412 -0
  285. package/dist/mcp/mock-transport.d.ts +40 -0
  286. package/dist/mcp/mock-transport.js +68 -0
  287. package/dist/mcp/oauth/callback-server.d.ts +14 -0
  288. package/dist/mcp/oauth/callback-server.js +122 -0
  289. package/dist/mcp/oauth/index.d.ts +9 -0
  290. package/dist/mcp/oauth/index.js +5 -0
  291. package/dist/mcp/oauth/provider.d.ts +39 -0
  292. package/dist/mcp/oauth/provider.js +121 -0
  293. package/dist/mcp/oauth/service.d.ts +34 -0
  294. package/dist/mcp/oauth/service.js +130 -0
  295. package/dist/mcp/oauth/store.d.ts +40 -0
  296. package/dist/mcp/oauth/store.js +134 -0
  297. package/dist/mcp/output.d.ts +12 -0
  298. package/dist/mcp/output.js +110 -0
  299. package/dist/mcp/provider.d.ts +7 -0
  300. package/dist/mcp/provider.js +56 -0
  301. package/dist/mcp/sdk-transport.d.ts +25 -0
  302. package/dist/mcp/sdk-transport.js +228 -0
  303. package/dist/mcp/server.d.ts +77 -0
  304. package/dist/mcp/server.js +120 -0
  305. package/dist/mcp/tool-naming.d.ts +4 -0
  306. package/dist/mcp/tool-naming.js +26 -0
  307. package/dist/mcp/types.d.ts +75 -0
  308. package/dist/mcp/types.js +2 -0
  309. package/dist/net/index.d.ts +3 -0
  310. package/dist/net/index.js +2 -0
  311. package/dist/net/proxy.d.ts +16 -0
  312. package/dist/net/proxy.js +42 -0
  313. package/dist/permission/auto-approver/index.d.ts +3 -0
  314. package/dist/permission/auto-approver/index.js +3 -0
  315. package/dist/permission/auto-approver/llm-auto-approver.d.ts +53 -0
  316. package/dist/permission/auto-approver/llm-auto-approver.js +122 -0
  317. package/dist/permission/auto-approver/prompts-data.d.ts +9 -0
  318. package/dist/permission/auto-approver/prompts-data.js +155 -0
  319. package/dist/permission/auto-approver/prompts.d.ts +18 -0
  320. package/dist/permission/auto-approver/prompts.js +40 -0
  321. package/dist/permission/auto-approver/transcript.d.ts +22 -0
  322. package/dist/permission/auto-approver/transcript.js +75 -0
  323. package/dist/permission/auto-approver/xml.d.ts +5 -0
  324. package/dist/permission/auto-approver/xml.js +25 -0
  325. package/dist/permission/index.d.ts +7 -0
  326. package/dist/permission/index.js +5 -0
  327. package/dist/permission/manager.d.ts +74 -0
  328. package/dist/permission/manager.js +162 -0
  329. package/dist/permission/matches-rule.d.ts +27 -0
  330. package/dist/permission/matches-rule.js +54 -0
  331. package/dist/permission/policies.d.ts +14 -0
  332. package/dist/permission/policies.js +233 -0
  333. package/dist/permission/types.d.ts +84 -0
  334. package/dist/permission/types.js +2 -0
  335. package/dist/plugins/archive.d.ts +3 -0
  336. package/dist/plugins/archive.js +58 -0
  337. package/dist/plugins/github-resolver.d.ts +13 -0
  338. package/dist/plugins/github-resolver.js +20 -0
  339. package/dist/plugins/hooks.d.ts +28 -0
  340. package/dist/plugins/hooks.js +296 -0
  341. package/dist/plugins/index.d.ts +23 -0
  342. package/dist/plugins/index.js +23 -0
  343. package/dist/plugins/injector.d.ts +11 -0
  344. package/dist/plugins/injector.js +32 -0
  345. package/dist/plugins/manager.d.ts +37 -0
  346. package/dist/plugins/manager.js +330 -0
  347. package/dist/plugins/manifest.d.ts +9 -0
  348. package/dist/plugins/manifest.js +234 -0
  349. package/dist/plugins/marketplace.d.ts +85 -0
  350. package/dist/plugins/marketplace.js +205 -0
  351. package/dist/plugins/source.d.ts +23 -0
  352. package/dist/plugins/source.js +87 -0
  353. package/dist/plugins/store.d.ts +20 -0
  354. package/dist/plugins/store.js +30 -0
  355. package/dist/plugins/types.d.ts +118 -0
  356. package/dist/plugins/types.js +5 -0
  357. package/dist/protocol/index.d.ts +4 -0
  358. package/dist/protocol/index.js +2 -0
  359. package/dist/protocol/tool-schema.d.ts +6 -0
  360. package/dist/protocol/tool-schema.js +2 -0
  361. package/dist/store/blob-store.d.ts +45 -0
  362. package/dist/store/blob-store.js +120 -0
  363. package/dist/store/catalog-store.d.ts +32 -0
  364. package/dist/store/catalog-store.js +73 -0
  365. package/dist/store/disk-store.d.ts +58 -0
  366. package/dist/store/disk-store.js +369 -0
  367. package/dist/store/index.d.ts +23 -0
  368. package/dist/store/index.js +15 -0
  369. package/dist/store/lock.d.ts +86 -0
  370. package/dist/store/lock.js +104 -0
  371. package/dist/store/log-store.d.ts +89 -0
  372. package/dist/store/log-store.js +296 -0
  373. package/dist/store/migrate.d.ts +26 -0
  374. package/dist/store/migrate.js +32 -0
  375. package/dist/store/origin.d.ts +89 -0
  376. package/dist/store/origin.js +16 -0
  377. package/dist/store/pg.d.ts +90 -0
  378. package/dist/store/pg.js +344 -0
  379. package/dist/store/redacting-store.d.ts +21 -0
  380. package/dist/store/redacting-store.js +46 -0
  381. package/dist/store/redis.d.ts +89 -0
  382. package/dist/store/redis.js +370 -0
  383. package/dist/store/repository.d.ts +150 -0
  384. package/dist/store/repository.js +508 -0
  385. package/dist/store/session-catalog.d.ts +32 -0
  386. package/dist/store/session-catalog.js +117 -0
  387. package/dist/store/storage.d.ts +27 -0
  388. package/dist/store/storage.js +54 -0
  389. package/dist/store/store.d.ts +262 -0
  390. package/dist/store/store.js +129 -0
  391. package/dist/store/workdir-key.d.ts +4 -0
  392. package/dist/store/workdir-key.js +28 -0
  393. package/dist/tool/access.d.ts +37 -0
  394. package/dist/tool/access.js +79 -0
  395. package/dist/tool/ask.d.ts +22 -0
  396. package/dist/tool/ask.js +38 -0
  397. package/dist/tool/background.d.ts +109 -0
  398. package/dist/tool/background.js +39 -0
  399. package/dist/tool/builtin/ask-user-question.d.ts +2 -0
  400. package/dist/tool/builtin/ask-user-question.js +175 -0
  401. package/dist/tool/builtin/bash.d.ts +2 -0
  402. package/dist/tool/builtin/bash.js +407 -0
  403. package/dist/tool/builtin/edit.d.ts +2 -0
  404. package/dist/tool/builtin/edit.js +202 -0
  405. package/dist/tool/builtin/glob.d.ts +3 -0
  406. package/dist/tool/builtin/glob.js +260 -0
  407. package/dist/tool/builtin/grep.d.ts +2 -0
  408. package/dist/tool/builtin/grep.js +574 -0
  409. package/dist/tool/builtin/line-endings.d.ts +10 -0
  410. package/dist/tool/builtin/line-endings.js +41 -0
  411. package/dist/tool/builtin/read.d.ts +28 -0
  412. package/dist/tool/builtin/read.js +498 -0
  413. package/dist/tool/builtin/write.d.ts +2 -0
  414. package/dist/tool/builtin/write.js +179 -0
  415. package/dist/tool/define.d.ts +46 -0
  416. package/dist/tool/define.js +45 -0
  417. package/dist/tool/file-freshness.d.ts +81 -0
  418. package/dist/tool/file-freshness.js +67 -0
  419. package/dist/tool/filesystem-tools.d.ts +16 -0
  420. package/dist/tool/filesystem-tools.js +19 -0
  421. package/dist/tool/git-context.d.ts +20 -0
  422. package/dist/tool/git-context.js +114 -0
  423. package/dist/tool/index.d.ts +37 -0
  424. package/dist/tool/index.js +34 -0
  425. package/dist/tool/machine-base.d.ts +138 -0
  426. package/dist/tool/machine-base.js +388 -0
  427. package/dist/tool/machine-local.d.ts +35 -0
  428. package/dist/tool/machine-local.js +316 -0
  429. package/dist/tool/machine-null.d.ts +36 -0
  430. package/dist/tool/machine-null.js +64 -0
  431. package/dist/tool/machine-ssh.d.ts +86 -0
  432. package/dist/tool/machine-ssh.js +576 -0
  433. package/dist/tool/machine.d.ts +333 -0
  434. package/dist/tool/machine.js +15 -0
  435. package/dist/tool/policies/path-access.d.ts +48 -0
  436. package/dist/tool/policies/path-access.js +186 -0
  437. package/dist/tool/policies/sensitive.d.ts +3 -0
  438. package/dist/tool/policies/sensitive.js +60 -0
  439. package/dist/tool/questions.d.ts +40 -0
  440. package/dist/tool/questions.js +8 -0
  441. package/dist/tool/search/activation.d.ts +13 -0
  442. package/dist/tool/search/activation.js +31 -0
  443. package/dist/tool/search/deferral.d.ts +37 -0
  444. package/dist/tool/search/deferral.js +128 -0
  445. package/dist/tool/search/search-tool.d.ts +9 -0
  446. package/dist/tool/search/search-tool.js +62 -0
  447. package/dist/tool/shell-env.d.ts +9 -0
  448. package/dist/tool/shell-env.js +34 -0
  449. package/dist/tool/support/bash-destructive.d.ts +24 -0
  450. package/dist/tool/support/bash-destructive.js +63 -0
  451. package/dist/tool/support/bash-paths.d.ts +7 -0
  452. package/dist/tool/support/bash-paths.js +247 -0
  453. package/dist/tool/support/bash-read-only.d.ts +8 -0
  454. package/dist/tool/support/bash-read-only.js +165 -0
  455. package/dist/tool/support/bash-rule-match.d.ts +20 -0
  456. package/dist/tool/support/bash-rule-match.js +191 -0
  457. package/dist/tool/support/file-type.d.ts +10 -0
  458. package/dist/tool/support/file-type.js +149 -0
  459. package/dist/tool/support/git-worktree.d.ts +10 -0
  460. package/dist/tool/support/git-worktree.js +63 -0
  461. package/dist/tool/support/image-compress.d.ts +69 -0
  462. package/dist/tool/support/image-compress.js +265 -0
  463. package/dist/tool/support/machine-ops.d.ts +34 -0
  464. package/dist/tool/support/machine-ops.js +34 -0
  465. package/dist/tool/support/path-glob-match.d.ts +12 -0
  466. package/dist/tool/support/path-glob-match.js +84 -0
  467. package/dist/tool/support/result-builder.d.ts +27 -0
  468. package/dist/tool/support/result-builder.js +108 -0
  469. package/dist/tool/support/rg-locator.d.ts +20 -0
  470. package/dist/tool/support/rg-locator.js +42 -0
  471. package/dist/tool/support/ripgrep-run.d.ts +65 -0
  472. package/dist/tool/support/ripgrep-run.js +40 -0
  473. package/dist/tool/support/rule-match.d.ts +6 -0
  474. package/dist/tool/support/rule-match.js +23 -0
  475. package/dist/tool/support/tool-path.d.ts +8 -0
  476. package/dist/tool/support/tool-path.js +28 -0
  477. package/dist/tool/support/workspace.d.ts +5 -0
  478. package/dist/tool/support/workspace.js +2 -0
  479. package/dist/tool/types.d.ts +131 -0
  480. package/dist/tool/types.js +2 -0
  481. package/dist/tool/web/fetch-url.d.ts +4 -0
  482. package/dist/tool/web/fetch-url.js +61 -0
  483. package/dist/tool/web/index.d.ts +11 -0
  484. package/dist/tool/web/index.js +7 -0
  485. package/dist/tool/web/providers/direct-fetch.d.ts +33 -0
  486. package/dist/tool/web/providers/direct-fetch.js +198 -0
  487. package/dist/tool/web/providers/firecrawl.d.ts +16 -0
  488. package/dist/tool/web/providers/firecrawl.js +59 -0
  489. package/dist/tool/web/providers/tavily.d.ts +14 -0
  490. package/dist/tool/web/providers/tavily.js +43 -0
  491. package/dist/tool/web/types.d.ts +41 -0
  492. package/dist/tool/web/types.js +7 -0
  493. package/dist/tool/web/web-search.d.ts +4 -0
  494. package/dist/tool/web/web-search.js +68 -0
  495. package/dist/tool/workspace-spec.d.ts +74 -0
  496. package/dist/tool/workspace-spec.js +177 -0
  497. package/dist/tracing/bridge.d.ts +7 -0
  498. package/dist/tracing/bridge.js +171 -0
  499. package/dist/tracing/index.d.ts +9 -0
  500. package/dist/tracing/index.js +5 -0
  501. package/dist/tracing/otel.d.ts +38 -0
  502. package/dist/tracing/otel.js +221 -0
  503. package/dist/tracing/processor.d.ts +47 -0
  504. package/dist/tracing/processor.js +94 -0
  505. package/dist/tracing/spans.d.ts +94 -0
  506. package/dist/tracing/spans.js +56 -0
  507. package/dist/ui/ai-sdk.d.ts +114 -0
  508. package/dist/ui/ai-sdk.js +175 -0
  509. package/dist/ui/index.d.ts +2 -0
  510. package/dist/ui/index.js +2 -0
  511. package/package.json +101 -0
@@ -0,0 +1,61 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "../define.js";
3
+ import { ToolAccesses } from "../access.js";
4
+ import { WebToolError } from "./types.js";
5
+ const DEFAULT_MAX_LENGTH = 50_000;
6
+ const FetchURLInput = z.object({
7
+ url: z.string().url().describe("The URL to fetch content from."),
8
+ max_length: z
9
+ .number()
10
+ .int()
11
+ .min(1)
12
+ .optional()
13
+ .describe(`Truncate the returned content to this many characters (default ${DEFAULT_MAX_LENGTH}).`),
14
+ });
15
+ export function fetchUrlTool(provider) {
16
+ return defineTool({
17
+ name: "FetchURL",
18
+ description: "Fetch a single URL and return its main content as text/markdown. Use after WebSearch, or " +
19
+ "for a known link. Returns the extracted readable body, not raw HTML.",
20
+ params: FetchURLInput,
21
+ resolve: (args) => ({
22
+ accesses: ToolAccesses.none(),
23
+ approvalRule: "FetchURL",
24
+ matchesRule: (rulePattern) => ruleMatchesUrl(rulePattern, args.url),
25
+ display: { title: `Fetching ${args.url}` },
26
+ run: async (ctx) => {
27
+ try {
28
+ const result = await provider.fetch(args.url, { signal: ctx.signal });
29
+ const limit = args.max_length ?? DEFAULT_MAX_LENGTH;
30
+ const body = result.content.length > limit ? `${result.content.slice(0, limit)}\n\n…[truncated]` : result.content;
31
+ const header = result.title ? `# ${result.title}\nURL: ${result.url}\n\n` : `URL: ${result.url}\n\n`;
32
+ return { content: [{ type: "text", text: header + body }] };
33
+ }
34
+ catch (error) {
35
+ return { content: [{ type: "text", text: errorText(error) }], isError: true };
36
+ }
37
+ },
38
+ }),
39
+ });
40
+ }
41
+ function ruleMatchesUrl(pattern, url) {
42
+ const m = /^FetchURL\((.*)\)$/.exec(pattern);
43
+ if (!m)
44
+ return false;
45
+ const subject = m[1];
46
+ if (subject === "*" || subject === url)
47
+ return true;
48
+ // Bare-host rule (e.g. "example.com") matches the URL's host.
49
+ try {
50
+ return new URL(url).host === subject;
51
+ }
52
+ catch {
53
+ return false;
54
+ }
55
+ }
56
+ function errorText(error) {
57
+ if (error instanceof WebToolError)
58
+ return error.message;
59
+ return `Fetch failed: ${error instanceof Error ? error.message : String(error)}`;
60
+ }
61
+ //# sourceMappingURL=fetch-url.js.map
@@ -0,0 +1,11 @@
1
+ export type { WebSearchResult, WebSearchOptions, WebSearchProvider, UrlFetchResult, UrlFetchOptions, UrlFetchProvider, } from "./types.ts";
2
+ export { WebToolError } from "./types.ts";
3
+ export { webSearchTool } from "./web-search.ts";
4
+ export { fetchUrlTool } from "./fetch-url.ts";
5
+ export { FirecrawlProvider } from "./providers/firecrawl.ts";
6
+ export type { FirecrawlProviderOptions } from "./providers/firecrawl.ts";
7
+ export { TavilySearchProvider } from "./providers/tavily.ts";
8
+ export type { TavilyProviderOptions } from "./providers/tavily.ts";
9
+ export { DirectFetchProvider } from "./providers/direct-fetch.ts";
10
+ export type { DirectFetchProviderOptions } from "./providers/direct-fetch.ts";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ export { WebToolError } from "./types.js";
2
+ export { webSearchTool } from "./web-search.js";
3
+ export { fetchUrlTool } from "./fetch-url.js";
4
+ export { FirecrawlProvider } from "./providers/firecrawl.js";
5
+ export { TavilySearchProvider } from "./providers/tavily.js";
6
+ export { DirectFetchProvider } from "./providers/direct-fetch.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,33 @@
1
+ import { type UrlFetchOptions, type UrlFetchProvider, type UrlFetchResult } from "../types.ts";
2
+ export interface DirectFetchProviderOptions {
3
+ readonly userAgent?: string;
4
+ readonly fetchImpl?: typeof fetch;
5
+ readonly maxBytes?: number;
6
+ readonly timeoutMs?: number;
7
+ readonly allowPrivateAddresses?: boolean;
8
+ }
9
+ export declare class DirectFetchProvider implements UrlFetchProvider {
10
+ private readonly userAgent;
11
+ private readonly fetchImpl;
12
+ private readonly maxBytes;
13
+ private readonly timeoutMs;
14
+ private readonly allowPrivate;
15
+ constructor(options?: DirectFetchProviderOptions);
16
+ fetch(url: string, options?: UrlFetchOptions): Promise<UrlFetchResult>;
17
+ /**
18
+ * Walks the redirect chain by hand, re-checking every hop.
19
+ *
20
+ * `fetch` follows redirects on its own, and doing so silently defeats both guards this
21
+ * provider has. The private-address check runs once, before the request — so a public URL
22
+ * that redirects to `169.254.169.254` sails straight through to the cloud metadata endpoint.
23
+ * And the caller's permission was granted for the ORIGINAL host, so a trusted domain with an
24
+ * open redirect becomes a way to fetch somewhere the user never approved.
25
+ *
26
+ * A cross-host redirect is not followed but reported, naming the destination. Following it
27
+ * would launder the approval; failing silently would leave the model guessing why a URL it
28
+ * can see in a browser returns nothing. Told where it leads, the model can fetch that URL
29
+ * directly — which goes through permissions again, as it should.
30
+ */
31
+ private fetchFollowingSafeRedirects;
32
+ }
33
+ //# sourceMappingURL=direct-fetch.d.ts.map
@@ -0,0 +1,198 @@
1
+ import { WebToolError, } from "../types.js";
2
+ const DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36";
3
+ const DEFAULT_MAX_BYTES = 10 * 1024 * 1024;
4
+ const DEFAULT_TIMEOUT_MS = 60_000;
5
+ /** Redirect chains longer than this are a loop or a tarpit, not a site reorganizing itself. */
6
+ const MAX_REDIRECTS = 10;
7
+ /** Past this a URL is a payload, not an address; browsers stop caring around here too. */
8
+ const MAX_URL_LENGTH = 2000;
9
+ export class DirectFetchProvider {
10
+ userAgent;
11
+ fetchImpl;
12
+ maxBytes;
13
+ timeoutMs;
14
+ allowPrivate;
15
+ constructor(options = {}) {
16
+ this.userAgent = options.userAgent ?? DEFAULT_USER_AGENT;
17
+ this.fetchImpl = options.fetchImpl ?? fetch;
18
+ this.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
19
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
20
+ this.allowPrivate = options.allowPrivateAddresses ?? false;
21
+ }
22
+ async fetch(url, options) {
23
+ const maxBytes = options?.maxBytes ?? this.maxBytes;
24
+ const timeoutMs = options?.timeoutMs ?? this.timeoutMs;
25
+ // One deadline for the whole chain. Per-hop timeouts would let a redirect loop stall for
26
+ // MAX_REDIRECTS × timeout while each individual hop looked responsive.
27
+ const deadline = AbortSignal.timeout(timeoutMs);
28
+ const signal = options?.signal === undefined ? deadline : AbortSignal.any([options.signal, deadline]);
29
+ const { response, finalUrl } = await this.fetchFollowingSafeRedirects(url, signal, timeoutMs);
30
+ if (response.status >= 400) {
31
+ throw new WebToolError(`Fetch returned HTTP ${String(response.status)} ${response.statusText} for ${finalUrl}.`);
32
+ }
33
+ const declared = Number(response.headers.get("content-length") ?? "");
34
+ if (Number.isFinite(declared) && declared > maxBytes) {
35
+ throw new WebToolError(`Response too large (${String(declared)} bytes > ${String(maxBytes)}).`);
36
+ }
37
+ const raw = await response.text();
38
+ if (raw.length > maxBytes)
39
+ throw new WebToolError(`Response too large (${String(raw.length)} bytes > ${String(maxBytes)}).`);
40
+ const contentType = (response.headers.get("content-type") ?? "").toLowerCase();
41
+ if (contentType.includes("text/plain") || contentType.includes("text/markdown")) {
42
+ return { url: finalUrl, content: raw.trim(), kind: contentType.includes("markdown") ? "markdown" : "text" };
43
+ }
44
+ const { title, text } = extractFromHtml(raw);
45
+ if (text.length === 0)
46
+ throw new WebToolError(`No meaningful text content found at ${finalUrl}.`);
47
+ return { url: finalUrl, content: text, kind: "text", ...(title !== undefined ? { title } : {}) };
48
+ }
49
+ /**
50
+ * Walks the redirect chain by hand, re-checking every hop.
51
+ *
52
+ * `fetch` follows redirects on its own, and doing so silently defeats both guards this
53
+ * provider has. The private-address check runs once, before the request — so a public URL
54
+ * that redirects to `169.254.169.254` sails straight through to the cloud metadata endpoint.
55
+ * And the caller's permission was granted for the ORIGINAL host, so a trusted domain with an
56
+ * open redirect becomes a way to fetch somewhere the user never approved.
57
+ *
58
+ * A cross-host redirect is not followed but reported, naming the destination. Following it
59
+ * would launder the approval; failing silently would leave the model guessing why a URL it
60
+ * can see in a browser returns nothing. Told where it leads, the model can fetch that URL
61
+ * directly — which goes through permissions again, as it should.
62
+ */
63
+ async fetchFollowingSafeRedirects(startUrl, signal, timeoutMs) {
64
+ let current = startUrl;
65
+ for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
66
+ assertSafeTarget(current, this.allowPrivate);
67
+ let response;
68
+ try {
69
+ response = await this.fetchImpl(current, {
70
+ headers: { "user-agent": this.userAgent, accept: "text/html,text/plain,text/markdown,*/*" },
71
+ redirect: "manual",
72
+ signal,
73
+ });
74
+ }
75
+ catch (error) {
76
+ if (signal.aborted && error?.name === "TimeoutError") {
77
+ throw new WebToolError(`Fetch timed out after ${String(timeoutMs)}ms for ${current}.`);
78
+ }
79
+ throw new WebToolError(`Fetch failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
80
+ }
81
+ if (!isRedirectStatus(response.status))
82
+ return { response, finalUrl: current };
83
+ const location = response.headers.get("location");
84
+ if (location === null || location.length === 0) {
85
+ throw new WebToolError(`${current} returned HTTP ${String(response.status)} with no Location header.`);
86
+ }
87
+ let next;
88
+ try {
89
+ next = new URL(location, current).toString();
90
+ }
91
+ catch {
92
+ throw new WebToolError(`${current} redirected to an invalid URL: ${location}`);
93
+ }
94
+ if (!isPermittedRedirect(current, next)) {
95
+ throw new WebToolError(`${current} redirects to ${next}, a different origin. Not following it automatically — ` +
96
+ `fetch that URL directly if you meant to go there.`);
97
+ }
98
+ current = next;
99
+ }
100
+ throw new WebToolError(`More than ${String(MAX_REDIRECTS)} redirects starting at ${startUrl}.`);
101
+ }
102
+ }
103
+ function isRedirectStatus(status) {
104
+ return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
105
+ }
106
+ /**
107
+ * Same scheme, same port, same host — `www.` may be added or dropped, and the path may change.
108
+ *
109
+ * Anything looser reopens the hole: a redirect to a sibling subdomain is still a redirect to a
110
+ * host the user did not approve, and credentials in the target (`https://user:pass@host/`) are
111
+ * refused outright since they are never part of a legitimate redirect.
112
+ */
113
+ function isPermittedRedirect(fromUrl, toUrl) {
114
+ let from;
115
+ let to;
116
+ try {
117
+ from = new URL(fromUrl);
118
+ to = new URL(toUrl);
119
+ }
120
+ catch {
121
+ return false;
122
+ }
123
+ if (from.protocol !== to.protocol)
124
+ return false;
125
+ if (from.port !== to.port)
126
+ return false;
127
+ if (to.username.length > 0 || to.password.length > 0)
128
+ return false;
129
+ const stripWww = (host) => host.replace(/^www\./, "");
130
+ return stripWww(from.hostname.toLowerCase()) === stripWww(to.hostname.toLowerCase());
131
+ }
132
+ /** Runs on every hop of a redirect chain, not just the URL the caller supplied. */
133
+ function assertSafeTarget(url, allowPrivate) {
134
+ if (url.length > MAX_URL_LENGTH) {
135
+ throw new WebToolError(`URL is longer than ${String(MAX_URL_LENGTH)} characters.`);
136
+ }
137
+ let parsed;
138
+ try {
139
+ parsed = new URL(url);
140
+ }
141
+ catch {
142
+ throw new WebToolError(`Invalid URL: ${url}`);
143
+ }
144
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
145
+ throw new WebToolError(`Unsupported URL scheme "${parsed.protocol}" (only http/https).`);
146
+ }
147
+ if (allowPrivate)
148
+ return;
149
+ const host = parsed.hostname.toLowerCase();
150
+ if (isPrivateHost(host)) {
151
+ throw new WebToolError(`Refusing to fetch a private/loopback address: ${host}.`);
152
+ }
153
+ }
154
+ function isPrivateHost(host) {
155
+ if (host === "localhost" || host.endsWith(".localhost"))
156
+ return true;
157
+ // IPv6 loopback / ULA / link-local.
158
+ if (host === "::1" || host.startsWith("fc") || host.startsWith("fd") || host.startsWith("fe80"))
159
+ return true;
160
+ const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
161
+ if (!v4)
162
+ return false;
163
+ const [a, b] = [Number(v4[1]), Number(v4[2])];
164
+ if (a === 127 || a === 10 || a === 0)
165
+ return true; // loopback / RFC1918 / "this host"
166
+ if (a === 169 && b === 254)
167
+ return true; // link-local (cloud metadata)
168
+ if (a === 192 && b === 168)
169
+ return true; // RFC1918
170
+ if (a === 172 && b >= 16 && b <= 31)
171
+ return true; // RFC1918
172
+ return false;
173
+ }
174
+ function extractFromHtml(html) {
175
+ const titleMatch = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
176
+ const title = titleMatch ? decodeEntities(titleMatch[1]).trim() : undefined;
177
+ const text = decodeEntities(html
178
+ .replace(/<script[\s\S]*?<\/script>/gi, " ")
179
+ .replace(/<style[\s\S]*?<\/style>/gi, " ")
180
+ .replace(/<!--[\s\S]*?-->/g, " ")
181
+ .replace(/<\/(p|div|li|h[1-6]|br|tr|section|article)>/gi, "\n")
182
+ .replace(/<[^>]+>/g, " "))
183
+ .replace(/[ \t]+/g, " ")
184
+ .replace(/\n{3,}/g, "\n\n")
185
+ .trim();
186
+ return { ...(title !== undefined && title.length > 0 ? { title } : {}), text };
187
+ }
188
+ function decodeEntities(s) {
189
+ return s
190
+ .replace(/&nbsp;/g, " ")
191
+ .replace(/&amp;/g, "&")
192
+ .replace(/&lt;/g, "<")
193
+ .replace(/&gt;/g, ">")
194
+ .replace(/&quot;/g, '"')
195
+ .replace(/&#39;/g, "'")
196
+ .replace(/&#x27;/g, "'");
197
+ }
198
+ //# sourceMappingURL=direct-fetch.js.map
@@ -0,0 +1,16 @@
1
+ import { type UrlFetchOptions, type UrlFetchProvider, type UrlFetchResult, type WebSearchOptions, type WebSearchProvider, type WebSearchResult } from "../types.ts";
2
+ export interface FirecrawlProviderOptions {
3
+ readonly apiKey: string;
4
+ readonly baseUrl?: string;
5
+ readonly fetchImpl?: typeof fetch;
6
+ }
7
+ export declare class FirecrawlProvider implements WebSearchProvider, UrlFetchProvider {
8
+ private readonly apiKey;
9
+ private readonly baseUrl;
10
+ private readonly fetchImpl;
11
+ constructor(options: FirecrawlProviderOptions);
12
+ search(query: string, options?: WebSearchOptions): Promise<readonly WebSearchResult[]>;
13
+ fetch(url: string, options?: UrlFetchOptions): Promise<UrlFetchResult>;
14
+ private post;
15
+ }
16
+ //# sourceMappingURL=firecrawl.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { WebToolError, } from "../types.js";
2
+ export class FirecrawlProvider {
3
+ apiKey;
4
+ baseUrl;
5
+ fetchImpl;
6
+ constructor(options) {
7
+ if (!options.apiKey)
8
+ throw new WebToolError("Firecrawl provider requires an apiKey.");
9
+ this.apiKey = options.apiKey;
10
+ this.baseUrl = (options.baseUrl ?? "https://api.firecrawl.dev").replace(/\/+$/, "");
11
+ this.fetchImpl = options.fetchImpl ?? fetch;
12
+ }
13
+ async search(query, options) {
14
+ const body = { query };
15
+ if (options?.limit !== undefined)
16
+ body.limit = options.limit;
17
+ if (options?.includeContent === true)
18
+ body.scrapeOptions = { formats: ["markdown"] };
19
+ const json = await this.post("/v1/search", body, options?.signal);
20
+ return (json.data ?? []).map((item) => ({
21
+ title: item.title ?? item.url ?? "(untitled)",
22
+ url: item.url ?? "",
23
+ snippet: item.description ?? "",
24
+ ...(item.markdown !== undefined ? { content: item.markdown } : {}),
25
+ }));
26
+ }
27
+ async fetch(url, options) {
28
+ const json = await this.post("/v1/scrape", { url, formats: ["markdown"] }, options?.signal);
29
+ const markdown = json.data?.markdown;
30
+ if (markdown === undefined || markdown.length === 0) {
31
+ throw new WebToolError(`Firecrawl returned no content for ${url}.`);
32
+ }
33
+ return {
34
+ url,
35
+ content: markdown,
36
+ kind: "markdown",
37
+ ...(json.data?.metadata?.title !== undefined ? { title: json.data.metadata.title } : {}),
38
+ };
39
+ }
40
+ async post(path, body, signal) {
41
+ let res;
42
+ try {
43
+ res = await this.fetchImpl(`${this.baseUrl}${path}`, {
44
+ method: "POST",
45
+ headers: { authorization: `Bearer ${this.apiKey}`, "content-type": "application/json" },
46
+ body: JSON.stringify(body),
47
+ signal,
48
+ });
49
+ }
50
+ catch (error) {
51
+ throw new WebToolError(`Firecrawl request failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
52
+ }
53
+ if (!res.ok) {
54
+ throw new WebToolError(`Firecrawl returned HTTP ${res.status} ${res.statusText}.`);
55
+ }
56
+ return (await res.json());
57
+ }
58
+ }
59
+ //# sourceMappingURL=firecrawl.js.map
@@ -0,0 +1,14 @@
1
+ import { type WebSearchOptions, type WebSearchProvider, type WebSearchResult } from "../types.ts";
2
+ export interface TavilyProviderOptions {
3
+ readonly apiKey: string;
4
+ readonly baseUrl?: string;
5
+ readonly fetchImpl?: typeof fetch;
6
+ }
7
+ export declare class TavilySearchProvider implements WebSearchProvider {
8
+ private readonly apiKey;
9
+ private readonly baseUrl;
10
+ private readonly fetchImpl;
11
+ constructor(options: TavilyProviderOptions);
12
+ search(query: string, options?: WebSearchOptions): Promise<readonly WebSearchResult[]>;
13
+ }
14
+ //# sourceMappingURL=tavily.d.ts.map
@@ -0,0 +1,43 @@
1
+ import { WebToolError, } from "../types.js";
2
+ export class TavilySearchProvider {
3
+ apiKey;
4
+ baseUrl;
5
+ fetchImpl;
6
+ constructor(options) {
7
+ if (!options.apiKey)
8
+ throw new WebToolError("Tavily provider requires an apiKey.");
9
+ this.apiKey = options.apiKey;
10
+ this.baseUrl = (options.baseUrl ?? "https://api.tavily.com").replace(/\/+$/, "");
11
+ this.fetchImpl = options.fetchImpl ?? fetch;
12
+ }
13
+ async search(query, options) {
14
+ const body = { api_key: this.apiKey, query };
15
+ if (options?.limit !== undefined)
16
+ body.max_results = options.limit;
17
+ if (options?.includeContent === true)
18
+ body.include_raw_content = true;
19
+ let res;
20
+ try {
21
+ res = await this.fetchImpl(`${this.baseUrl}/search`, {
22
+ method: "POST",
23
+ headers: { "content-type": "application/json" },
24
+ body: JSON.stringify(body),
25
+ signal: options?.signal,
26
+ });
27
+ }
28
+ catch (error) {
29
+ throw new WebToolError(`Tavily request failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
30
+ }
31
+ if (!res.ok)
32
+ throw new WebToolError(`Tavily returned HTTP ${res.status} ${res.statusText}.`);
33
+ const json = (await res.json());
34
+ return (json.results ?? []).map((item) => ({
35
+ title: item.title ?? item.url ?? "(untitled)",
36
+ url: item.url ?? "",
37
+ snippet: item.content ?? "",
38
+ ...(item.published_date !== undefined ? { date: item.published_date } : {}),
39
+ ...(options?.includeContent === true && item.raw_content !== undefined ? { content: item.raw_content } : {}),
40
+ }));
41
+ }
42
+ }
43
+ //# sourceMappingURL=tavily.js.map
@@ -0,0 +1,41 @@
1
+ export interface WebSearchResult {
2
+ readonly title: string;
3
+ readonly url: string;
4
+ readonly snippet: string;
5
+ readonly date?: string;
6
+ readonly content?: string;
7
+ }
8
+ export interface WebSearchOptions {
9
+ readonly limit?: number;
10
+ readonly includeContent?: boolean;
11
+ readonly signal?: AbortSignal;
12
+ }
13
+ export interface WebSearchProvider {
14
+ search(query: string, options?: WebSearchOptions): Promise<readonly WebSearchResult[]>;
15
+ }
16
+ export interface UrlFetchResult {
17
+ /**
18
+ * The URL the content actually came from. Not necessarily the one that was requested — a
19
+ * fetch may follow redirects, and reporting the original would hide where the bytes are
20
+ * really from, which is exactly what makes an open redirect useful to an attacker.
21
+ */
22
+ readonly url: string;
23
+ readonly content: string;
24
+ readonly kind: "markdown" | "text" | "html";
25
+ readonly title?: string;
26
+ }
27
+ export interface UrlFetchOptions {
28
+ readonly maxBytes?: number;
29
+ /** Deadline for the whole fetch, redirects included. */
30
+ readonly timeoutMs?: number;
31
+ readonly signal?: AbortSignal;
32
+ }
33
+ export interface UrlFetchProvider {
34
+ fetch(url: string, options?: UrlFetchOptions): Promise<UrlFetchResult>;
35
+ }
36
+ export declare class WebToolError extends Error {
37
+ constructor(message: string, options?: {
38
+ cause?: unknown;
39
+ });
40
+ }
41
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,7 @@
1
+ export class WebToolError extends Error {
2
+ constructor(message, options) {
3
+ super(message, options);
4
+ this.name = "WebToolError";
5
+ }
6
+ }
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,4 @@
1
+ import type { Tool } from "../types.ts";
2
+ import { type WebSearchProvider } from "./types.ts";
3
+ export declare function webSearchTool(provider: WebSearchProvider): Tool;
4
+ //# sourceMappingURL=web-search.d.ts.map
@@ -0,0 +1,68 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "../define.js";
3
+ import { ToolAccesses } from "../access.js";
4
+ import { WebToolError } from "./types.js";
5
+ const WebSearchInput = z.object({
6
+ query: z.string().min(1).describe("The query text to search for."),
7
+ limit: z
8
+ .number()
9
+ .int()
10
+ .min(1)
11
+ .max(20)
12
+ .optional()
13
+ .describe("Number of results (default 5). Prefer a more concrete query over a large limit."),
14
+ include_content: z
15
+ .boolean()
16
+ .optional()
17
+ .describe("Include each page's full content. Token-heavy; avoid with a large limit."),
18
+ });
19
+ export function webSearchTool(provider) {
20
+ return defineTool({
21
+ name: "WebSearch",
22
+ description: "Search the web and return ranked results (title, URL, snippet). Use it for current facts, " +
23
+ "documentation, or to find pages to FetchURL. Set include_content to pull full page text.",
24
+ params: WebSearchInput,
25
+ resolve: (args) => {
26
+ const preview = args.query.length > 40 ? `${args.query.slice(0, 40)}…` : args.query;
27
+ return {
28
+ accesses: ToolAccesses.none(),
29
+ approvalRule: "WebSearch",
30
+ display: { title: `Searching: ${preview}` },
31
+ run: async (ctx) => {
32
+ try {
33
+ const results = await provider.search(args.query, {
34
+ limit: args.limit,
35
+ includeContent: args.include_content,
36
+ signal: ctx.signal,
37
+ });
38
+ return { content: [{ type: "text", text: formatResults(results) }] };
39
+ }
40
+ catch (error) {
41
+ return { content: [{ type: "text", text: errorText(error) }], isError: true };
42
+ }
43
+ },
44
+ };
45
+ },
46
+ });
47
+ }
48
+ function formatResults(results) {
49
+ if (results.length === 0)
50
+ return "No search results found.";
51
+ const blocks = [];
52
+ for (const r of results) {
53
+ const lines = [`Title: ${r.title}`];
54
+ if (r.date)
55
+ lines.push(`Date: ${r.date}`);
56
+ lines.push(`URL: ${r.url}`, `Snippet: ${r.snippet}`);
57
+ if (r.content)
58
+ lines.push("", r.content);
59
+ blocks.push(lines.join("\n"));
60
+ }
61
+ return blocks.join("\n\n---\n\n");
62
+ }
63
+ function errorText(error) {
64
+ if (error instanceof WebToolError)
65
+ return error.message;
66
+ return `Web search failed: ${error instanceof Error ? error.message : String(error)}`;
67
+ }
68
+ //# sourceMappingURL=web-search.js.map
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Declarative workspace preparation: describe what a workspace should CONTAIN, and let this
3
+ * materialize it. The whole implementation is a recursive descent over a small entry union.
4
+ *
5
+ * Deliberately smaller than a general sandbox manifest format. Omitted, because a coding
6
+ * workspace does not need them: bucket mounts (rclone/FUSE), users/groups/permission bits,
7
+ * secret-store environment references, and cross-language serialization compatibility. Those
8
+ * are where nearly all the size of such formats goes. Add one only when a real need appears.
9
+ *
10
+ * Written against `Machine`, so it works on local, SSH and sandbox backends alike rather than
11
+ * being reimplemented per vendor.
12
+ */
13
+ import type { Machine } from "./machine.ts";
14
+ export type WorkspaceEntry = {
15
+ readonly type: "dir";
16
+ readonly children?: Readonly<Record<string, WorkspaceEntry>>;
17
+ } | {
18
+ readonly type: "file";
19
+ readonly content: string;
20
+ readonly lineEndings?: "LF" | "CRLF";
21
+ } | {
22
+ readonly type: "host_file";
23
+ readonly src: string;
24
+ } | {
25
+ readonly type: "host_dir";
26
+ readonly src: string;
27
+ } | {
28
+ readonly type: "git_repo";
29
+ readonly repo: string;
30
+ readonly ref?: string;
31
+ /** Shallow by default; full history is rarely what an agent needs. */
32
+ readonly depth?: number;
33
+ };
34
+ export interface WorkspaceSpec {
35
+ /** Absolute root every entry path is relative to. */
36
+ readonly root: string;
37
+ readonly entries: Readonly<Record<string, WorkspaceEntry>>;
38
+ }
39
+ export interface MaterializeOptions {
40
+ /** Reads host files for `host_file`/`host_dir`. Omit to reject those entries. */
41
+ readonly hostReader?: HostReader;
42
+ readonly signal?: AbortSignal;
43
+ /** Per-command timeout for `git_repo` clones. */
44
+ readonly gitTimeoutMs?: number;
45
+ }
46
+ /** Host-side filesystem access, injected so this module needs no `node:fs` import. */
47
+ export interface HostReader {
48
+ readFile(path: string): Promise<Buffer>;
49
+ /** Relative paths of every file beneath `dir`, recursively. */
50
+ listFiles(dir: string): Promise<readonly string[]>;
51
+ }
52
+ export declare class WorkspaceMaterializeError extends Error {
53
+ readonly path: string;
54
+ constructor(message: string, path: string, options?: {
55
+ cause?: unknown;
56
+ });
57
+ }
58
+ /**
59
+ * Create everything the spec declares. Entries are materialized in declaration order so a
60
+ * later entry may depend on an earlier one (config written into a freshly cloned repo).
61
+ */
62
+ export declare function materializeWorkspace(machine: Machine, spec: WorkspaceSpec, options?: MaterializeOptions): Promise<void>;
63
+ /**
64
+ * Render a spec as a tree, for telling a MODEL what its workspace contains.
65
+ *
66
+ * An agent dropped into a prepared workspace otherwise has to discover it by listing
67
+ * directories — several tool calls to learn what the host already knew declaratively. This
68
+ * describes the DECLARED shape, not the live filesystem: it is cheap (no I/O) and it stays
69
+ * honest about that, since anything the agent creates later will not appear here.
70
+ */
71
+ export declare function describeWorkspace(spec: WorkspaceSpec, options?: {
72
+ maxLines?: number;
73
+ }): string;
74
+ //# sourceMappingURL=workspace-spec.d.ts.map