@clinebot/core 0.0.20 → 0.0.21

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 (356) hide show
  1. package/dist/account/cline-account-service.d.ts +3 -2
  2. package/dist/account/cline-account-service.d.ts.map +1 -0
  3. package/dist/account/index.d.ts +1 -0
  4. package/dist/account/index.d.ts.map +1 -0
  5. package/dist/account/rpc.d.ts +1 -0
  6. package/dist/account/rpc.d.ts.map +1 -0
  7. package/dist/account/types.d.ts +1 -0
  8. package/dist/account/types.d.ts.map +1 -0
  9. package/dist/agents/agent-config-loader.d.ts +1 -0
  10. package/dist/agents/agent-config-loader.d.ts.map +1 -0
  11. package/dist/agents/agent-config-parser.d.ts +1 -0
  12. package/dist/agents/agent-config-parser.d.ts.map +1 -0
  13. package/dist/agents/hooks-config-loader.d.ts +1 -0
  14. package/dist/agents/hooks-config-loader.d.ts.map +1 -0
  15. package/dist/agents/index.d.ts +1 -0
  16. package/dist/agents/index.d.ts.map +1 -0
  17. package/dist/agents/plugin-config-loader.d.ts +1 -0
  18. package/dist/agents/plugin-config-loader.d.ts.map +1 -0
  19. package/dist/agents/plugin-loader.d.ts +1 -0
  20. package/dist/agents/plugin-loader.d.ts.map +1 -0
  21. package/dist/agents/plugin-sandbox.d.ts +1 -0
  22. package/dist/agents/plugin-sandbox.d.ts.map +1 -0
  23. package/dist/agents/unified-config-file-watcher.d.ts +1 -0
  24. package/dist/agents/unified-config-file-watcher.d.ts.map +1 -0
  25. package/dist/agents/user-instruction-config-loader.d.ts +1 -0
  26. package/dist/agents/user-instruction-config-loader.d.ts.map +1 -0
  27. package/dist/auth/client.d.ts +1 -0
  28. package/dist/auth/client.d.ts.map +1 -0
  29. package/dist/auth/cline.d.ts +1 -0
  30. package/dist/auth/cline.d.ts.map +1 -0
  31. package/dist/auth/codex.d.ts +1 -0
  32. package/dist/auth/codex.d.ts.map +1 -0
  33. package/dist/auth/oca.d.ts +1 -0
  34. package/dist/auth/oca.d.ts.map +1 -0
  35. package/dist/auth/server.d.ts +1 -0
  36. package/dist/auth/server.d.ts.map +1 -0
  37. package/dist/auth/types.d.ts +1 -0
  38. package/dist/auth/types.d.ts.map +1 -0
  39. package/dist/auth/utils.d.ts +1 -0
  40. package/dist/auth/utils.d.ts.map +1 -0
  41. package/dist/chat/chat-schema.d.ts +13 -12
  42. package/dist/chat/chat-schema.d.ts.map +1 -0
  43. package/dist/index.d.ts +3 -1
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.node.d.ts +2 -0
  46. package/dist/index.node.d.ts.map +1 -0
  47. package/dist/index.node.js +303 -302
  48. package/dist/input/file-indexer.d.ts +1 -0
  49. package/dist/input/file-indexer.d.ts.map +1 -0
  50. package/dist/input/index.d.ts +1 -0
  51. package/dist/input/index.d.ts.map +1 -0
  52. package/dist/input/mention-enricher.d.ts +1 -0
  53. package/dist/input/mention-enricher.d.ts.map +1 -0
  54. package/dist/mcp/config-loader.d.ts +1 -0
  55. package/dist/mcp/config-loader.d.ts.map +1 -0
  56. package/dist/mcp/index.d.ts +1 -0
  57. package/dist/mcp/index.d.ts.map +1 -0
  58. package/dist/mcp/manager.d.ts +1 -0
  59. package/dist/mcp/manager.d.ts.map +1 -0
  60. package/dist/mcp/types.d.ts +1 -0
  61. package/dist/mcp/types.d.ts.map +1 -0
  62. package/dist/providers/local-provider-registry.d.ts +36 -0
  63. package/dist/providers/local-provider-registry.d.ts.map +1 -0
  64. package/dist/providers/local-provider-service.d.ts +2 -1
  65. package/dist/providers/local-provider-service.d.ts.map +1 -0
  66. package/dist/runtime/commands.d.ts +1 -0
  67. package/dist/runtime/commands.d.ts.map +1 -0
  68. package/dist/runtime/hook-file-hooks.d.ts +1 -0
  69. package/dist/runtime/hook-file-hooks.d.ts.map +1 -0
  70. package/dist/runtime/rules.d.ts +1 -0
  71. package/dist/runtime/rules.d.ts.map +1 -0
  72. package/dist/runtime/runtime-builder.d.ts +1 -0
  73. package/dist/runtime/runtime-builder.d.ts.map +1 -0
  74. package/dist/runtime/sandbox/subprocess-sandbox.d.ts +1 -0
  75. package/dist/runtime/sandbox/subprocess-sandbox.d.ts.map +1 -0
  76. package/dist/runtime/session-runtime.d.ts +2 -0
  77. package/dist/runtime/session-runtime.d.ts.map +1 -0
  78. package/dist/runtime/skills.d.ts +1 -0
  79. package/dist/runtime/skills.d.ts.map +1 -0
  80. package/dist/runtime/tool-approval.d.ts +1 -0
  81. package/dist/runtime/tool-approval.d.ts.map +1 -0
  82. package/dist/runtime/workflows.d.ts +1 -0
  83. package/dist/runtime/workflows.d.ts.map +1 -0
  84. package/dist/session/default-session-manager.d.ts +4 -0
  85. package/dist/session/default-session-manager.d.ts.map +1 -0
  86. package/dist/session/file-session-service.d.ts +1 -0
  87. package/dist/session/file-session-service.d.ts.map +1 -0
  88. package/dist/session/rpc-session-service.d.ts +1 -0
  89. package/dist/session/rpc-session-service.d.ts.map +1 -0
  90. package/dist/session/rpc-spawn-lease.d.ts +1 -0
  91. package/dist/session/rpc-spawn-lease.d.ts.map +1 -0
  92. package/dist/session/runtime-oauth-token-manager.d.ts +1 -0
  93. package/dist/session/runtime-oauth-token-manager.d.ts.map +1 -0
  94. package/dist/session/session-agent-events.d.ts +20 -1
  95. package/dist/session/session-agent-events.d.ts.map +1 -0
  96. package/dist/session/session-artifacts.d.ts +1 -0
  97. package/dist/session/session-artifacts.d.ts.map +1 -0
  98. package/dist/session/session-config-builder.d.ts +1 -0
  99. package/dist/session/session-config-builder.d.ts.map +1 -0
  100. package/dist/session/session-graph.d.ts +1 -0
  101. package/dist/session/session-graph.d.ts.map +1 -0
  102. package/dist/session/session-host.d.ts +1 -0
  103. package/dist/session/session-host.d.ts.map +1 -0
  104. package/dist/session/session-manager.d.ts +1 -0
  105. package/dist/session/session-manager.d.ts.map +1 -0
  106. package/dist/session/session-manifest.d.ts +2 -1
  107. package/dist/session/session-manifest.d.ts.map +1 -0
  108. package/dist/session/session-service.d.ts +1 -0
  109. package/dist/session/session-service.d.ts.map +1 -0
  110. package/dist/session/session-team-coordination.d.ts +1 -0
  111. package/dist/session/session-team-coordination.d.ts.map +1 -0
  112. package/dist/session/session-telemetry.d.ts +3 -1
  113. package/dist/session/session-telemetry.d.ts.map +1 -0
  114. package/dist/session/sqlite-rpc-session-backend.d.ts +1 -0
  115. package/dist/session/sqlite-rpc-session-backend.d.ts.map +1 -0
  116. package/dist/session/unified-session-persistence-service.d.ts +1 -0
  117. package/dist/session/unified-session-persistence-service.d.ts.map +1 -0
  118. package/dist/session/utils/helpers.d.ts +1 -0
  119. package/dist/session/utils/helpers.d.ts.map +1 -0
  120. package/dist/session/utils/types.d.ts +1 -0
  121. package/dist/session/utils/types.d.ts.map +1 -0
  122. package/dist/session/utils/usage.d.ts +1 -0
  123. package/dist/session/utils/usage.d.ts.map +1 -0
  124. package/dist/session/workspace-manager.d.ts +1 -0
  125. package/dist/session/workspace-manager.d.ts.map +1 -0
  126. package/dist/session/workspace-manifest.d.ts +1 -0
  127. package/dist/session/workspace-manifest.d.ts.map +1 -0
  128. package/dist/storage/file-team-store.d.ts +1 -0
  129. package/dist/storage/file-team-store.d.ts.map +1 -0
  130. package/dist/storage/provider-settings-legacy-migration.d.ts +1 -0
  131. package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -0
  132. package/dist/storage/provider-settings-manager.d.ts +1 -0
  133. package/dist/storage/provider-settings-manager.d.ts.map +1 -0
  134. package/dist/storage/sqlite-session-store.d.ts +1 -0
  135. package/dist/storage/sqlite-session-store.d.ts.map +1 -0
  136. package/dist/storage/sqlite-team-store.d.ts +1 -0
  137. package/dist/storage/sqlite-team-store.d.ts.map +1 -0
  138. package/dist/storage/team-store.d.ts +1 -0
  139. package/dist/storage/team-store.d.ts.map +1 -0
  140. package/dist/team/index.d.ts +1 -0
  141. package/dist/team/index.d.ts.map +1 -0
  142. package/dist/team/projections.d.ts +1 -0
  143. package/dist/team/projections.d.ts.map +1 -0
  144. package/dist/telemetry/ITelemetryAdapter.d.ts +1 -0
  145. package/dist/telemetry/ITelemetryAdapter.d.ts.map +1 -0
  146. package/dist/telemetry/LoggerTelemetryAdapter.d.ts +1 -0
  147. package/dist/telemetry/LoggerTelemetryAdapter.d.ts.map +1 -0
  148. package/dist/telemetry/OpenTelemetryAdapter.d.ts +1 -0
  149. package/dist/telemetry/OpenTelemetryAdapter.d.ts.map +1 -0
  150. package/dist/telemetry/OpenTelemetryProvider.d.ts +1 -0
  151. package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -0
  152. package/dist/telemetry/TelemetryService.d.ts +1 -0
  153. package/dist/telemetry/TelemetryService.d.ts.map +1 -0
  154. package/dist/telemetry/core-events.d.ts +55 -22
  155. package/dist/telemetry/core-events.d.ts.map +1 -0
  156. package/dist/telemetry/opentelemetry.d.ts +1 -0
  157. package/dist/telemetry/opentelemetry.d.ts.map +1 -0
  158. package/dist/tools/constants.d.ts +1 -0
  159. package/dist/tools/constants.d.ts.map +1 -0
  160. package/dist/tools/definitions.d.ts +8 -1
  161. package/dist/tools/definitions.d.ts.map +1 -0
  162. package/dist/tools/executors/apply-patch-parser.d.ts +1 -0
  163. package/dist/tools/executors/apply-patch-parser.d.ts.map +1 -0
  164. package/dist/tools/executors/apply-patch.d.ts +1 -0
  165. package/dist/tools/executors/apply-patch.d.ts.map +1 -0
  166. package/dist/tools/executors/bash.d.ts +2 -1
  167. package/dist/tools/executors/bash.d.ts.map +1 -0
  168. package/dist/tools/executors/editor.d.ts +1 -0
  169. package/dist/tools/executors/editor.d.ts.map +1 -0
  170. package/dist/tools/executors/file-read.d.ts +1 -0
  171. package/dist/tools/executors/file-read.d.ts.map +1 -0
  172. package/dist/tools/executors/index.d.ts +14 -7
  173. package/dist/tools/executors/index.d.ts.map +1 -0
  174. package/dist/tools/executors/search.d.ts +1 -0
  175. package/dist/tools/executors/search.d.ts.map +1 -0
  176. package/dist/tools/executors/web-fetch.d.ts +1 -0
  177. package/dist/tools/executors/web-fetch.d.ts.map +1 -0
  178. package/dist/tools/helpers.d.ts +15 -0
  179. package/dist/tools/helpers.d.ts.map +1 -0
  180. package/dist/tools/index.d.ts +2 -1
  181. package/dist/tools/index.d.ts.map +1 -0
  182. package/dist/tools/model-tool-routing.d.ts +1 -0
  183. package/dist/tools/model-tool-routing.d.ts.map +1 -0
  184. package/dist/tools/presets.d.ts +1 -0
  185. package/dist/tools/presets.d.ts.map +1 -0
  186. package/dist/tools/schemas.d.ts +41 -0
  187. package/dist/tools/schemas.d.ts.map +1 -0
  188. package/dist/tools/types.d.ts +3 -2
  189. package/dist/tools/types.d.ts.map +1 -0
  190. package/dist/types/common.d.ts +1 -0
  191. package/dist/types/common.d.ts.map +1 -0
  192. package/dist/types/config.d.ts +1 -0
  193. package/dist/types/config.d.ts.map +1 -0
  194. package/dist/types/events.d.ts +1 -0
  195. package/dist/types/events.d.ts.map +1 -0
  196. package/dist/types/provider-settings.d.ts +1 -0
  197. package/dist/types/provider-settings.d.ts.map +1 -0
  198. package/dist/types/sessions.d.ts +1 -0
  199. package/dist/types/sessions.d.ts.map +1 -0
  200. package/dist/types/storage.d.ts +1 -0
  201. package/dist/types/storage.d.ts.map +1 -0
  202. package/dist/types/workspace.d.ts +1 -0
  203. package/dist/types/workspace.d.ts.map +1 -0
  204. package/dist/types.d.ts +1 -0
  205. package/dist/types.d.ts.map +1 -0
  206. package/package.json +6 -4
  207. package/src/account/cline-account-service.test.ts +0 -101
  208. package/src/account/cline-account-service.ts +0 -287
  209. package/src/account/index.ts +0 -22
  210. package/src/account/rpc.test.ts +0 -62
  211. package/src/account/rpc.ts +0 -172
  212. package/src/account/types.ts +0 -98
  213. package/src/agents/agent-config-loader.test.ts +0 -236
  214. package/src/agents/agent-config-loader.ts +0 -108
  215. package/src/agents/agent-config-parser.ts +0 -198
  216. package/src/agents/hooks-config-loader.test.ts +0 -20
  217. package/src/agents/hooks-config-loader.ts +0 -118
  218. package/src/agents/index.ts +0 -85
  219. package/src/agents/plugin-config-loader.test.ts +0 -140
  220. package/src/agents/plugin-config-loader.ts +0 -97
  221. package/src/agents/plugin-loader.test.ts +0 -228
  222. package/src/agents/plugin-loader.ts +0 -172
  223. package/src/agents/plugin-sandbox-bootstrap.ts +0 -445
  224. package/src/agents/plugin-sandbox.test.ts +0 -317
  225. package/src/agents/plugin-sandbox.ts +0 -341
  226. package/src/agents/unified-config-file-watcher.test.ts +0 -196
  227. package/src/agents/unified-config-file-watcher.ts +0 -483
  228. package/src/agents/user-instruction-config-loader.test.ts +0 -158
  229. package/src/agents/user-instruction-config-loader.ts +0 -438
  230. package/src/auth/client.test.ts +0 -40
  231. package/src/auth/client.ts +0 -25
  232. package/src/auth/cline.test.ts +0 -130
  233. package/src/auth/cline.ts +0 -420
  234. package/src/auth/codex.test.ts +0 -170
  235. package/src/auth/codex.ts +0 -491
  236. package/src/auth/oca.test.ts +0 -215
  237. package/src/auth/oca.ts +0 -573
  238. package/src/auth/server.ts +0 -216
  239. package/src/auth/types.ts +0 -81
  240. package/src/auth/utils.test.ts +0 -128
  241. package/src/auth/utils.ts +0 -247
  242. package/src/chat/chat-schema.ts +0 -82
  243. package/src/index.node.ts +0 -285
  244. package/src/index.ts +0 -211
  245. package/src/input/file-indexer.d.ts +0 -11
  246. package/src/input/file-indexer.test.ts +0 -127
  247. package/src/input/file-indexer.ts +0 -327
  248. package/src/input/index.ts +0 -7
  249. package/src/input/mention-enricher.test.ts +0 -85
  250. package/src/input/mention-enricher.ts +0 -122
  251. package/src/mcp/config-loader.test.ts +0 -238
  252. package/src/mcp/config-loader.ts +0 -219
  253. package/src/mcp/index.ts +0 -26
  254. package/src/mcp/manager.test.ts +0 -106
  255. package/src/mcp/manager.ts +0 -262
  256. package/src/mcp/types.ts +0 -88
  257. package/src/providers/local-provider-service.ts +0 -608
  258. package/src/runtime/commands.test.ts +0 -98
  259. package/src/runtime/commands.ts +0 -83
  260. package/src/runtime/hook-file-hooks.test.ts +0 -237
  261. package/src/runtime/hook-file-hooks.ts +0 -859
  262. package/src/runtime/index.ts +0 -37
  263. package/src/runtime/rules.ts +0 -34
  264. package/src/runtime/runtime-builder.team-persistence.test.ts +0 -202
  265. package/src/runtime/runtime-builder.test.ts +0 -371
  266. package/src/runtime/runtime-builder.ts +0 -589
  267. package/src/runtime/runtime-parity.test.ts +0 -143
  268. package/src/runtime/sandbox/subprocess-sandbox.ts +0 -231
  269. package/src/runtime/session-runtime.ts +0 -46
  270. package/src/runtime/skills.ts +0 -44
  271. package/src/runtime/tool-approval.ts +0 -104
  272. package/src/runtime/workflows.test.ts +0 -119
  273. package/src/runtime/workflows.ts +0 -45
  274. package/src/session/default-session-manager.e2e.test.ts +0 -384
  275. package/src/session/default-session-manager.test.ts +0 -1741
  276. package/src/session/default-session-manager.ts +0 -1233
  277. package/src/session/file-session-service.ts +0 -280
  278. package/src/session/index.ts +0 -42
  279. package/src/session/rpc-session-service.ts +0 -107
  280. package/src/session/rpc-spawn-lease.test.ts +0 -49
  281. package/src/session/rpc-spawn-lease.ts +0 -122
  282. package/src/session/runtime-oauth-token-manager.test.ts +0 -137
  283. package/src/session/runtime-oauth-token-manager.ts +0 -272
  284. package/src/session/session-agent-events.ts +0 -159
  285. package/src/session/session-artifacts.ts +0 -106
  286. package/src/session/session-config-builder.ts +0 -113
  287. package/src/session/session-graph.ts +0 -92
  288. package/src/session/session-host.test.ts +0 -29
  289. package/src/session/session-host.ts +0 -242
  290. package/src/session/session-manager.ts +0 -69
  291. package/src/session/session-manifest.ts +0 -29
  292. package/src/session/session-service.team-persistence.test.ts +0 -48
  293. package/src/session/session-service.ts +0 -673
  294. package/src/session/session-team-coordination.ts +0 -229
  295. package/src/session/session-telemetry.ts +0 -95
  296. package/src/session/sqlite-rpc-session-backend.ts +0 -303
  297. package/src/session/unified-session-persistence-service.test.ts +0 -85
  298. package/src/session/unified-session-persistence-service.ts +0 -996
  299. package/src/session/utils/helpers.ts +0 -139
  300. package/src/session/utils/types.ts +0 -57
  301. package/src/session/utils/usage.ts +0 -32
  302. package/src/session/workspace-manager.ts +0 -98
  303. package/src/session/workspace-manifest.ts +0 -100
  304. package/src/storage/artifact-store.ts +0 -1
  305. package/src/storage/file-team-store.ts +0 -257
  306. package/src/storage/index.ts +0 -11
  307. package/src/storage/provider-settings-legacy-migration.test.ts +0 -307
  308. package/src/storage/provider-settings-legacy-migration.ts +0 -689
  309. package/src/storage/provider-settings-manager.test.ts +0 -145
  310. package/src/storage/provider-settings-manager.ts +0 -150
  311. package/src/storage/session-store.ts +0 -1
  312. package/src/storage/sqlite-session-store.ts +0 -275
  313. package/src/storage/sqlite-team-store.ts +0 -454
  314. package/src/storage/team-store.ts +0 -40
  315. package/src/team/index.ts +0 -4
  316. package/src/team/projections.ts +0 -285
  317. package/src/telemetry/ITelemetryAdapter.ts +0 -94
  318. package/src/telemetry/LoggerTelemetryAdapter.test.ts +0 -42
  319. package/src/telemetry/LoggerTelemetryAdapter.ts +0 -114
  320. package/src/telemetry/OpenTelemetryAdapter.test.ts +0 -157
  321. package/src/telemetry/OpenTelemetryAdapter.ts +0 -348
  322. package/src/telemetry/OpenTelemetryProvider.test.ts +0 -113
  323. package/src/telemetry/OpenTelemetryProvider.ts +0 -322
  324. package/src/telemetry/TelemetryService.test.ts +0 -134
  325. package/src/telemetry/TelemetryService.ts +0 -141
  326. package/src/telemetry/core-events.ts +0 -344
  327. package/src/telemetry/opentelemetry.ts +0 -20
  328. package/src/tools/constants.ts +0 -35
  329. package/src/tools/definitions.test.ts +0 -658
  330. package/src/tools/definitions.ts +0 -726
  331. package/src/tools/executors/apply-patch-parser.ts +0 -520
  332. package/src/tools/executors/apply-patch.ts +0 -359
  333. package/src/tools/executors/bash.ts +0 -205
  334. package/src/tools/executors/editor.test.ts +0 -35
  335. package/src/tools/executors/editor.ts +0 -219
  336. package/src/tools/executors/file-read.test.ts +0 -49
  337. package/src/tools/executors/file-read.ts +0 -110
  338. package/src/tools/executors/index.ts +0 -75
  339. package/src/tools/executors/search.ts +0 -278
  340. package/src/tools/executors/web-fetch.ts +0 -259
  341. package/src/tools/index.ts +0 -168
  342. package/src/tools/model-tool-routing.test.ts +0 -86
  343. package/src/tools/model-tool-routing.ts +0 -132
  344. package/src/tools/presets.test.ts +0 -62
  345. package/src/tools/presets.ts +0 -168
  346. package/src/tools/schemas.ts +0 -284
  347. package/src/tools/types.ts +0 -328
  348. package/src/types/common.ts +0 -14
  349. package/src/types/config.ts +0 -84
  350. package/src/types/events.ts +0 -74
  351. package/src/types/index.ts +0 -24
  352. package/src/types/provider-settings.ts +0 -43
  353. package/src/types/sessions.ts +0 -16
  354. package/src/types/storage.ts +0 -64
  355. package/src/types/workspace.ts +0 -7
  356. package/src/types.ts +0 -128
@@ -1,726 +0,0 @@
1
- /**
2
- * Default Tool Definitions
3
- *
4
- * Factory functions for creating the default tools.
5
- */
6
-
7
- import { createTool, type Tool } from "@clinebot/agents";
8
- import { validateWithZod, zodToJsonSchema } from "@clinebot/shared";
9
- import {
10
- type ApplyPatchInput,
11
- ApplyPatchInputSchema,
12
- ApplyPatchInputUnionSchema,
13
- type AskQuestionInput,
14
- AskQuestionInputSchema,
15
- type EditFileInput,
16
- EditFileInputSchema,
17
- type FetchWebContentInput,
18
- FetchWebContentInputSchema,
19
- INPUT_ARG_CHAR_LIMIT,
20
- type ReadFileRequest,
21
- type ReadFilesInput,
22
- ReadFilesInputSchema,
23
- ReadFilesInputUnionSchema,
24
- type RunCommandsInput,
25
- RunCommandsInputSchema,
26
- RunCommandsInputUnionSchema,
27
- type SearchCodebaseInput,
28
- SearchCodebaseInputSchema,
29
- SearchCodebaseUnionInputSchema,
30
- type SkillsInput,
31
- SkillsInputSchema,
32
- } from "./schemas.js";
33
- import type {
34
- ApplyPatchExecutor,
35
- AskQuestionExecutor,
36
- BashExecutor,
37
- CreateDefaultToolsOptions,
38
- DefaultToolsConfig,
39
- EditorExecutor,
40
- FileReadExecutor,
41
- SearchExecutor,
42
- SkillsExecutorWithMetadata,
43
- ToolOperationResult,
44
- WebFetchExecutor,
45
- } from "./types.js";
46
-
47
- // =============================================================================
48
- // Helper Functions
49
- // =============================================================================
50
-
51
- /**
52
- * Format an error into a string message
53
- */
54
- function formatError(error: unknown): string {
55
- if (error instanceof Error) {
56
- return error.message;
57
- }
58
- return String(error);
59
- }
60
-
61
- function getEditorSizeError(input: EditFileInput): string | null {
62
- if (
63
- typeof input.old_text === "string" &&
64
- input.old_text.length > INPUT_ARG_CHAR_LIMIT
65
- ) {
66
- return `Editor input too large: old_text was ${input.old_text.length} characters, exceeding the recommended limit of ${INPUT_ARG_CHAR_LIMIT}. Split the edit into smaller tool calls so later tool calls are less likely to be truncated or time out.`;
67
- }
68
-
69
- if (input.new_text.length > INPUT_ARG_CHAR_LIMIT) {
70
- return `Editor input too large: new_text was ${input.new_text.length} characters, exceeding the recommended limit of ${INPUT_ARG_CHAR_LIMIT}. Split the edit into smaller tool calls so later tool calls are less likely to be truncated or time out.`;
71
- }
72
-
73
- return null;
74
- }
75
-
76
- /**
77
- * Create a timeout-wrapped promise
78
- */
79
- function withTimeout<T>(
80
- promise: Promise<T>,
81
- ms: number,
82
- message: string,
83
- ): Promise<T> {
84
- return Promise.race([
85
- promise,
86
- new Promise<never>((_, reject) => {
87
- setTimeout(() => reject(new Error(message)), ms);
88
- }),
89
- ]);
90
- }
91
-
92
- function normalizeReadFileRequests(input: unknown): ReadFileRequest[] {
93
- const validate = validateWithZod(ReadFilesInputUnionSchema, input);
94
-
95
- if (typeof validate === "string") {
96
- return [{ path: validate }];
97
- }
98
-
99
- if (Array.isArray(validate)) {
100
- return validate.map((value) =>
101
- typeof value === "string" ? { path: value } : value,
102
- );
103
- }
104
-
105
- if ("files" in validate) {
106
- const files = Array.isArray(validate.files)
107
- ? validate.files
108
- : [validate.files];
109
- return files;
110
- }
111
-
112
- if ("file_paths" in validate) {
113
- const filePaths = Array.isArray(validate.file_paths)
114
- ? validate.file_paths
115
- : [validate.file_paths];
116
- return filePaths.map((filePath) => ({ path: filePath }));
117
- }
118
-
119
- return [validate];
120
- }
121
-
122
- function formatReadFileQuery(request: ReadFileRequest): string {
123
- const { path, start_line, end_line } = request;
124
- if (start_line == null && end_line == null) {
125
- return path;
126
- }
127
- const start = start_line ?? 1;
128
- const end = end_line ?? "EOF";
129
- return `${path}:${start}-${end}`;
130
- }
131
-
132
- // =============================================================================
133
- // Tool Factory Functions
134
- // =============================================================================
135
-
136
- /**
137
- * Create the read_files tool
138
- *
139
- * Reads the content of one or more files from the filesystem.
140
- */
141
- export function createReadFilesTool(
142
- executor: FileReadExecutor,
143
- config: Pick<DefaultToolsConfig, "fileReadTimeoutMs"> = {},
144
- ): Tool<ReadFilesInput, ToolOperationResult[]> {
145
- const timeoutMs = config.fileReadTimeoutMs ?? 10000;
146
-
147
- return createTool<ReadFilesInput, ToolOperationResult[]>({
148
- name: "read_files",
149
- description:
150
- "Read the full content of text files at the provided absolute paths, or return only an inclusive one-based line range when start_line/end_line are provided. " +
151
- "Returns file contents or error messages for each path.",
152
- inputSchema: zodToJsonSchema(ReadFilesInputSchema),
153
- timeoutMs: timeoutMs * 2, // Account for multiple files
154
- retryable: true,
155
- maxRetries: 1,
156
- execute: async (input, context) => {
157
- const requests = normalizeReadFileRequests(input);
158
-
159
- return Promise.all(
160
- requests.map(async (request): Promise<ToolOperationResult> => {
161
- try {
162
- const content = await withTimeout(
163
- executor(request, context),
164
- timeoutMs,
165
- `File read timed out after ${timeoutMs}ms`,
166
- );
167
- return {
168
- query: formatReadFileQuery(request),
169
- result: content,
170
- success: true,
171
- };
172
- } catch (error) {
173
- const msg = formatError(error);
174
- return {
175
- query: formatReadFileQuery(request),
176
- result: "",
177
- error: `Error reading file: ${msg}`,
178
- success: false,
179
- };
180
- }
181
- }),
182
- );
183
- },
184
- });
185
- }
186
-
187
- /**
188
- * Create the search_codebase tool
189
- *
190
- * Performs regex pattern searches across the codebase.
191
- */
192
- export function createSearchTool(
193
- executor: SearchExecutor,
194
- config: Pick<DefaultToolsConfig, "cwd" | "searchTimeoutMs"> = {},
195
- ): Tool<SearchCodebaseInput, ToolOperationResult[]> {
196
- const timeoutMs = config.searchTimeoutMs ?? 30000;
197
- const cwd = config.cwd ?? process.cwd();
198
-
199
- return createTool<SearchCodebaseInput, ToolOperationResult[]>({
200
- name: "search_codebase",
201
- description:
202
- "Perform regex pattern searches across the codebase. " +
203
- "Supports multiple parallel searches. " +
204
- "Use for finding code patterns, function definitions, class names, imports, etc.",
205
- inputSchema: zodToJsonSchema(SearchCodebaseInputSchema),
206
- timeoutMs: timeoutMs * 2,
207
- retryable: true,
208
- maxRetries: 1,
209
- execute: async (input, context) => {
210
- // Validate input with Zod schema
211
- const validate = validateWithZod(SearchCodebaseUnionInputSchema, input);
212
- const queries = Array.isArray(validate)
213
- ? validate
214
- : typeof validate === "object"
215
- ? Array.isArray(validate.queries)
216
- ? validate.queries
217
- : [validate.queries]
218
- : [validate];
219
-
220
- return Promise.all(
221
- queries.map(async (query): Promise<ToolOperationResult> => {
222
- try {
223
- const results = await withTimeout(
224
- executor(query, cwd, context),
225
- timeoutMs,
226
- `Search timed out after ${timeoutMs}ms`,
227
- );
228
- // Check if results contain matches
229
- const hasResults =
230
- results.length > 0 && !results.includes("No results found");
231
- return {
232
- query,
233
- result: results,
234
- success: hasResults,
235
- };
236
- } catch (error) {
237
- const msg = formatError(error);
238
- return {
239
- query,
240
- result: "",
241
- error: `Search failed: ${msg}`,
242
- success: false,
243
- };
244
- }
245
- }),
246
- );
247
- },
248
- });
249
- }
250
-
251
- /**
252
- * Create the run_commands tool
253
- *
254
- * Executes shell commands in the project directory.
255
- */
256
- export function createBashTool(
257
- executor: BashExecutor,
258
- config: Pick<DefaultToolsConfig, "cwd" | "bashTimeoutMs"> = {},
259
- ): Tool<RunCommandsInput, ToolOperationResult[]> {
260
- const timeoutMs = config.bashTimeoutMs ?? 30000;
261
- const cwd = config.cwd ?? process.cwd();
262
-
263
- return createTool<RunCommandsInput, ToolOperationResult[]>({
264
- name: "run_commands",
265
- description:
266
- "Run shell commands at the root of the project. " +
267
- "Use for listing files, checking git status, running builds, executing tests, etc. " +
268
- "Commands should be properly shell-escaped.",
269
- inputSchema: zodToJsonSchema(RunCommandsInputSchema),
270
- timeoutMs: timeoutMs * 2,
271
- retryable: false, // Shell commands often have side effects
272
- maxRetries: 0,
273
- execute: async (input, context) => {
274
- const validate = validateWithZod(RunCommandsInputUnionSchema, input);
275
- const commands = Array.isArray(validate)
276
- ? validate
277
- : typeof validate === "object"
278
- ? Array.isArray(validate.commands)
279
- ? validate.commands
280
- : [validate.commands]
281
- : [validate];
282
-
283
- return Promise.all(
284
- commands.map(async (command): Promise<ToolOperationResult> => {
285
- try {
286
- const output = await withTimeout(
287
- executor(command, cwd, context),
288
- timeoutMs,
289
- `Command timed out after ${timeoutMs}ms`,
290
- );
291
- return {
292
- query: command,
293
- result: output,
294
- success: true,
295
- };
296
- } catch (error) {
297
- const msg = formatError(error);
298
- return {
299
- query: command,
300
- result: "",
301
- error: `Command failed: ${msg}`,
302
- success: false,
303
- };
304
- }
305
- }),
306
- );
307
- },
308
- });
309
- }
310
-
311
- /**
312
- * Create the fetch_web_content tool
313
- *
314
- * Fetches content from URLs and analyzes them using provided prompts.
315
- */
316
- export function createWebFetchTool(
317
- executor: WebFetchExecutor,
318
- config: Pick<DefaultToolsConfig, "webFetchTimeoutMs"> = {},
319
- ): Tool<FetchWebContentInput, ToolOperationResult[]> {
320
- const timeoutMs = config.webFetchTimeoutMs ?? 30000;
321
-
322
- return createTool<FetchWebContentInput, ToolOperationResult[]>({
323
- name: "fetch_web_content",
324
- description:
325
- "Fetch content from URLs and analyze them using the provided prompts. " +
326
- "Use for retrieving documentation, API references, or any web content. " +
327
- "Each request includes a URL and a prompt describing what information to extract.",
328
- inputSchema: zodToJsonSchema(FetchWebContentInputSchema),
329
- timeoutMs: timeoutMs * 2,
330
- retryable: true,
331
- maxRetries: 2,
332
- execute: async (input, context) => {
333
- // Validate input with Zod schema
334
- const validatedInput = validateWithZod(FetchWebContentInputSchema, input);
335
-
336
- return Promise.all(
337
- validatedInput.requests.map(
338
- async (request): Promise<ToolOperationResult> => {
339
- try {
340
- const content = await withTimeout(
341
- executor(request.url, request.prompt, context),
342
- timeoutMs,
343
- `Web fetch timed out after ${timeoutMs}ms`,
344
- );
345
- return {
346
- query: request.url,
347
- result: content,
348
- success: true,
349
- };
350
- } catch (error) {
351
- const msg = formatError(error);
352
- return {
353
- query: request.url,
354
- result: "",
355
- error: `Error fetching web content: ${msg}`,
356
- success: false,
357
- };
358
- }
359
- },
360
- ),
361
- );
362
- },
363
- });
364
- }
365
-
366
- const APPLY_PATCH_TOOL_DESC = `This is a custom utility that makes it more convenient to add, remove, move, or edit code in a single file. \`apply_patch\` effectively allows you to execute a diff/patch against a file, but the format of the diff specification is unique to this task, so pay careful attention to these instructions. To use the \`apply_patch\` command, you should pass a message of the following structure as "input":
367
-
368
- %%bash
369
- apply_patch <<"EOF"
370
- *** Begin Patch
371
- [YOUR_PATCH]
372
- *** End Patch
373
- EOF
374
-
375
- Where [YOUR_PATCH] is the actual content of your patch, specified in the following V4A diff format.
376
-
377
- *** [ACTION] File: [path/to/file] -> ACTION can be one of Add, Update, or Delete.
378
-
379
- In a Add File section, every line of the new file (including blank/empty lines) MUST start with a \`+\` prefix. Do not include any unprefixed lines inside an Add section
380
- In a Update/Delete section, repeat the following for each snippet of code that needs to be changed:
381
- [context_before] -> See below for further instructions on context.
382
- - [old_code] -> Precede the old code with a minus sign.
383
- + [new_code] -> Precede the new, replacement code with a plus sign.
384
- [context_after] -> See below for further instructions on context.
385
-
386
- For instructions on [context_before] and [context_after]:
387
- - By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.
388
- - If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:
389
- @@ class BaseClass
390
- [3 lines of pre-context]
391
- - [old_code]
392
- + [new_code]
393
- [3 lines of post-context]
394
-
395
- - If a code block is repeated so many times in a class or function such that even a single @@ statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple \`@@\` statements to jump to the right context. For instance:
396
-
397
- @@ class BaseClass
398
- @@ def method():
399
- [3 lines of pre-context]
400
- - [old_code]
401
- + [new_code]
402
- [3 lines of post-context]
403
-
404
- Note, then, that we do not use line numbers in this diff format, as the context is enough to uniquely identify code. An example of a message that you might pass as "input" to this function, in order to apply a patch, is shown below.
405
-
406
- %%bash
407
- apply_patch <<"EOF"
408
- *** Begin Patch
409
- *** Update File: pygorithm/searching/binary_search.py
410
- @@ class BaseClass
411
- @@ def search():
412
- - pass
413
- + raise NotImplementedError()
414
-
415
- @@ class Subclass
416
- @@ def search():
417
- - pass
418
- + raise NotImplementedError()
419
-
420
- *** End Patch
421
- EOF`;
422
-
423
- /**
424
- * Create the apply_patch tool
425
- *
426
- * Applies the legacy Cline patch format to one or more files.
427
- */
428
- export function createApplyPatchTool(
429
- executor: ApplyPatchExecutor,
430
- config: Pick<DefaultToolsConfig, "cwd" | "applyPatchTimeoutMs"> = {},
431
- ): Tool<ApplyPatchInput, ToolOperationResult> {
432
- const timeoutMs = config.applyPatchTimeoutMs ?? 30000;
433
- const cwd = config.cwd ?? process.cwd();
434
-
435
- return createTool<ApplyPatchInput, ToolOperationResult>({
436
- name: "apply_patch",
437
- description: APPLY_PATCH_TOOL_DESC,
438
- inputSchema: zodToJsonSchema(ApplyPatchInputSchema),
439
- timeoutMs,
440
- retryable: false,
441
- maxRetries: 0,
442
- execute: async (input, context) => {
443
- const validate = validateWithZod(ApplyPatchInputUnionSchema, input);
444
- const patchInput =
445
- typeof validate === "string" ? validate : validate.input;
446
-
447
- try {
448
- const result = await withTimeout(
449
- executor({ input: patchInput }, cwd, context),
450
- timeoutMs,
451
- `apply_patch timed out after ${timeoutMs}ms`,
452
- );
453
-
454
- return {
455
- query: "apply_patch",
456
- result,
457
- success: true,
458
- };
459
- } catch (error) {
460
- const msg = formatError(error);
461
- return {
462
- query: "apply_patch",
463
- result: "",
464
- error: `apply_patch failed: ${msg}`,
465
- success: false,
466
- };
467
- }
468
- },
469
- });
470
- }
471
-
472
- /**
473
- * Create the editor tool
474
- *
475
- * Supports controlled filesystem edits with create, replace, and insert commands.
476
- */
477
- export function createEditorTool(
478
- executor: EditorExecutor,
479
- config: Pick<DefaultToolsConfig, "cwd" | "editorTimeoutMs"> = {},
480
- ): Tool<EditFileInput, ToolOperationResult> {
481
- const timeoutMs = config.editorTimeoutMs ?? 30000;
482
- const cwd = config.cwd ?? process.cwd();
483
-
484
- return createTool<EditFileInput, ToolOperationResult>({
485
- name: "editor",
486
- description:
487
- "An editor for controlled filesystem edits on the text file at the provided path. " +
488
- "Provide `insert_line` to insert `new_text` at a specific line number. " +
489
- "Otherwise, the tool replaces `old_text` with `new_text`, or creates the file with `new_text` if file does not exist. " +
490
- "Use this tools for making small, precise edits to existing files or creating new files over shell commands.",
491
-
492
- inputSchema: zodToJsonSchema(EditFileInputSchema),
493
- timeoutMs,
494
- retryable: false, // Editing operations are stateful and should not auto-retry
495
- maxRetries: 0,
496
- execute: async (input, context) => {
497
- const validatedInput = validateWithZod(EditFileInputSchema, input);
498
- const operation = validatedInput.insert_line == null ? "edit" : "insert";
499
- const sizeError = getEditorSizeError(validatedInput);
500
-
501
- if (sizeError) {
502
- return {
503
- query: `${operation}:${validatedInput.path}`,
504
- result: "",
505
- error: sizeError,
506
- success: false,
507
- };
508
- }
509
-
510
- try {
511
- const result = await withTimeout(
512
- executor(validatedInput, cwd, context),
513
- timeoutMs,
514
- `Editor operation timed out after ${timeoutMs}ms`,
515
- );
516
-
517
- return {
518
- query: `${operation}:${validatedInput.path}`,
519
- result,
520
- success: true,
521
- };
522
- } catch (error) {
523
- const msg = formatError(error);
524
- return {
525
- query: `${operation}:${validatedInput.path}`,
526
- result: "",
527
- error: `Editor operation failed: ${msg}`,
528
- success: false,
529
- };
530
- }
531
- },
532
- });
533
- }
534
-
535
- /**
536
- * Create the skills tool
537
- *
538
- * Invokes a configured skill by name and optional arguments.
539
- */
540
- export function createSkillsTool(
541
- executor: SkillsExecutorWithMetadata,
542
- config: Pick<DefaultToolsConfig, "skillsTimeoutMs"> = {},
543
- ): Tool<SkillsInput, string> {
544
- const timeoutMs = config.skillsTimeoutMs ?? 15000;
545
-
546
- const baseDescription =
547
- "Execute a skill within the main conversation. " +
548
- "When users ask you to perform tasks, check if any available skills match. " +
549
- "When users reference a slash command, invoke it with this tool. " +
550
- 'Input: `skill` (required) and optional `args`. Example: `skill: "pdf"`, `skill: "commit", args: "-m \\"Fix bug\\""`, `skill: "review-pr", args: "123"`, `skill: "ms-office-suite:pdf"`. ' +
551
- "When a skill matches the user's request, invoking this tool is a blocking requirement before any other response. " +
552
- "Never mention a skill without invoking this tool.";
553
-
554
- const tool = createTool<SkillsInput, string>({
555
- name: "skills",
556
- description: baseDescription,
557
- inputSchema: zodToJsonSchema(SkillsInputSchema),
558
- timeoutMs,
559
- retryable: false,
560
- maxRetries: 0,
561
- execute: async (input, context) => {
562
- const validatedInput = validateWithZod(SkillsInputSchema, input);
563
- return withTimeout(
564
- executor(
565
- validatedInput.skill,
566
- validatedInput.args || undefined,
567
- context,
568
- ),
569
- timeoutMs,
570
- `Skills operation timed out after ${timeoutMs}ms`,
571
- );
572
- },
573
- });
574
-
575
- Object.defineProperty(tool, "description", {
576
- get() {
577
- const skills = executor.configuredSkills
578
- ?.filter((s) => !s.disabled)
579
- .map((s) => s.name);
580
- if (skills && skills.length > 0) {
581
- return `${baseDescription} Available skills: ${skills.join(", ")}.`;
582
- }
583
- return baseDescription;
584
- },
585
- enumerable: true,
586
- configurable: true,
587
- });
588
-
589
- return tool;
590
- }
591
-
592
- /**
593
- * Create the ask_question tool
594
- *
595
- * Asks the user a single clarifying question with 2-5 selectable options.
596
- */
597
- export function createAskQuestionTool(
598
- executor: AskQuestionExecutor,
599
- config: Pick<DefaultToolsConfig, "askQuestionTimeoutMs"> = {},
600
- ): Tool<AskQuestionInput, string> {
601
- const timeoutMs = config.askQuestionTimeoutMs ?? 15000;
602
-
603
- return createTool<AskQuestionInput, string>({
604
- name: "ask_question",
605
- description:
606
- "Ask user a question for clarifying or gathering information needed to complete the task. " +
607
- "For example, ask the user clarifying questions about a key implementation decision. " +
608
- "You should only ask one question. " +
609
- "Provide an array of 2-5 options for the user to choose from. " +
610
- "Never include an option to toggle to Act mode.",
611
- inputSchema: zodToJsonSchema(AskQuestionInputSchema),
612
- timeoutMs,
613
- retryable: false,
614
- maxRetries: 0,
615
- execute: async (input, context) => {
616
- const validatedInput = validateWithZod(AskQuestionInputSchema, input);
617
- return withTimeout(
618
- executor(validatedInput.question, validatedInput.options, context),
619
- timeoutMs,
620
- `ask_question timed out after ${timeoutMs}ms`,
621
- );
622
- },
623
- });
624
- }
625
-
626
- // =============================================================================
627
- // Default Tools Factory
628
- // =============================================================================
629
-
630
- /**
631
- * Create a set of default tools for an agent
632
- *
633
- * This function creates the default tools based on the provided configuration
634
- * and executors. Only tools that are enabled AND have an executor provided
635
- * will be included in the returned array.
636
- *
637
- * @example
638
- * ```typescript
639
- * import { Agent } from "@clinebot/agents"
640
- * import { createDefaultTools } from "@clinebot/core/node"
641
- * import * as fs from "fs/promises"
642
- * import { exec } from "child_process"
643
- *
644
- * const tools = createDefaultTools({
645
- * executors: {
646
- * readFile: async ({ path }) => fs.readFile(path, "utf-8"),
647
- * bash: async (cmd, cwd) => {
648
- * return new Promise((resolve, reject) => {
649
- * exec(cmd, { cwd }, (err, stdout, stderr) => {
650
- * if (err) reject(new Error(stderr || err.message))
651
- * else resolve(stdout)
652
- * })
653
- * })
654
- * },
655
- * },
656
- * enableReadFiles: true,
657
- * enableBash: true,
658
- * enableSearch: false, // Disabled
659
- * enableWebFetch: false, // Disabled
660
- * cwd: "/path/to/project",
661
- * })
662
- *
663
- * const agent = new Agent({
664
- * // ... provider config
665
- * tools,
666
- * })
667
- * ```
668
- */
669
- export function createDefaultTools(options: CreateDefaultToolsOptions): Tool[] {
670
- const {
671
- executors,
672
- enableReadFiles = true,
673
- enableSearch = true,
674
- enableBash = true,
675
- enableWebFetch = true,
676
- enableApplyPatch = false,
677
- enableEditor = true,
678
- enableSkills = true,
679
- enableAskQuestion = true,
680
- ...config
681
- } = options;
682
-
683
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
684
- const tools: Tool<any, any>[] = [];
685
-
686
- // Add read_files tool if enabled and executor provided
687
- if (enableReadFiles && executors.readFile) {
688
- tools.push(createReadFilesTool(executors.readFile, config));
689
- }
690
-
691
- // Add search_codebase tool if enabled and executor provided
692
- if (enableSearch && executors.search) {
693
- tools.push(createSearchTool(executors.search, config));
694
- }
695
-
696
- // Add run_commands tool if enabled and executor provided
697
- if (enableBash && executors.bash) {
698
- tools.push(createBashTool(executors.bash, config));
699
- }
700
-
701
- // Add fetch_web_content tool if enabled and executor provided
702
- if (enableWebFetch && executors.webFetch) {
703
- tools.push(createWebFetchTool(executors.webFetch, config));
704
- }
705
-
706
- // Add editor tool if enabled and executor provided,
707
- // else check if apply_patch tool is enabled and executor provided
708
- // NOTE: Do not enable two similar tools at the same time.
709
- if (enableEditor && executors.editor) {
710
- tools.push(createEditorTool(executors.editor, config));
711
- } else if (enableApplyPatch && executors.applyPatch) {
712
- tools.push(createApplyPatchTool(executors.applyPatch, config));
713
- }
714
-
715
- // Add skills tool if enabled and executor provided
716
- if (enableSkills && executors.skills) {
717
- tools.push(createSkillsTool(executors.skills, config));
718
- }
719
-
720
- // Add ask_question tool if enabled and executor provided
721
- if (enableAskQuestion && executors.askQuestion) {
722
- tools.push(createAskQuestionTool(executors.askQuestion, config));
723
- }
724
-
725
- return tools;
726
- }