@clinebot/core 0.0.20 → 0.0.22

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 +8 -6
  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,317 +0,0 @@
1
- import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import type { AgentConfig, Tool, ToolContext } from "@clinebot/agents";
5
- import { describe, expect, it } from "vitest";
6
- import { loadSandboxedPlugins } from "./plugin-sandbox";
7
-
8
- function createApiCapture() {
9
- const tools: Tool[] = [];
10
- const api = {
11
- registerTool: (tool: Tool) => tools.push(tool),
12
- registerCommand: () => {},
13
- registerShortcut: () => {},
14
- registerFlag: () => {},
15
- registerMessageRenderer: () => {},
16
- registerProvider: () => {},
17
- };
18
- return { tools, api };
19
- }
20
-
21
- describe("plugin-sandbox", () => {
22
- it("runs plugin hooks and tool contributions in sandbox process", async () => {
23
- const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-"));
24
- try {
25
- const pluginPath = join(dir, "plugin.mjs");
26
- await writeFile(
27
- pluginPath,
28
- [
29
- "export default {",
30
- " name: 'sandbox-test',",
31
- " manifest: { capabilities: ['hooks','tools'], hookStages: ['input'] },",
32
- " setup(api) {",
33
- " api.registerTool({",
34
- " name: 'sandbox_echo',",
35
- " description: 'echo',",
36
- " inputSchema: { type: 'object', properties: { value: { type: 'string' } }, required: ['value'] },",
37
- " execute: async (input) => ({ echoed: input.value }),",
38
- " });",
39
- " },",
40
- " onInput(ctx) { return { overrideInput: String(ctx.input || '').toUpperCase() }; }",
41
- "};",
42
- ].join("\n"),
43
- "utf8",
44
- );
45
-
46
- const sandboxed = await loadSandboxedPlugins({
47
- pluginPaths: [pluginPath],
48
- });
49
- try {
50
- expect(sandboxed.extensions).toBeDefined();
51
- const extension = sandboxed.extensions?.[0];
52
- expect(extension?.name).toBe("sandbox-test");
53
- type AgentExtensionInputContext = Parameters<
54
- NonNullable<NonNullable<AgentConfig["extensions"]>[number]["onInput"]>
55
- >[0];
56
- const inputContext: AgentExtensionInputContext = {
57
- agentId: "agent-1",
58
- conversationId: "conv-1",
59
- parentAgentId: null,
60
- mode: "run",
61
- input: "hello",
62
- };
63
- const control = await extension?.onInput?.(inputContext);
64
- expect(control?.overrideInput).toBe("HELLO");
65
-
66
- const { tools, api } = createApiCapture();
67
- await extension?.setup?.(api);
68
- expect(tools.map((tool) => tool.name)).toContain("sandbox_echo");
69
- const echoTool = tools.find((tool) => tool.name === "sandbox_echo");
70
- expect(echoTool).toBeDefined();
71
- const result = await echoTool?.execute({ value: "ok" }, {
72
- agentId: "agent-1",
73
- conversationId: "conv-1",
74
- iteration: 1,
75
- } as ToolContext);
76
- expect(result).toEqual({ echoed: "ok" });
77
- } finally {
78
- await sandboxed.shutdown();
79
- }
80
- } finally {
81
- await rm(dir, { recursive: true, force: true });
82
- }
83
- });
84
-
85
- it("enforces hook timeout and cancels sandbox process", async () => {
86
- const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-timeout-"));
87
- try {
88
- const pluginPath = join(dir, "plugin-timeout.mjs");
89
- await writeFile(
90
- pluginPath,
91
- [
92
- "export default {",
93
- " name: 'sandbox-timeout',",
94
- " manifest: { capabilities: ['hooks'], hookStages: ['input'] },",
95
- " onInput() { return new Promise(() => {}); }",
96
- "};",
97
- ].join("\n"),
98
- "utf8",
99
- );
100
-
101
- const sandboxed = await loadSandboxedPlugins({
102
- pluginPaths: [pluginPath],
103
- hookTimeoutMs: 50,
104
- });
105
- const extension = sandboxed.extensions?.[0];
106
- await expect(
107
- extension?.onInput?.({
108
- agentId: "agent-1",
109
- conversationId: "conv-1",
110
- parentAgentId: null,
111
- mode: "run",
112
- input: "hello",
113
- }),
114
- ).rejects.toThrow(/timed out/i);
115
- await sandboxed.shutdown();
116
- } finally {
117
- await rm(dir, { recursive: true, force: true });
118
- }
119
- });
120
-
121
- it("forwards sandbox plugin events to the host", async () => {
122
- const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-events-"));
123
- try {
124
- const pluginPath = join(dir, "plugin-events.mjs");
125
- await writeFile(
126
- pluginPath,
127
- [
128
- "export default {",
129
- " name: 'sandbox-events',",
130
- " manifest: { capabilities: ['tools'] },",
131
- " setup(api) {",
132
- " api.registerTool({",
133
- " name: 'emit_event',",
134
- " description: 'emit host event',",
135
- " inputSchema: { type: 'object', properties: { value: { type: 'string' } }, required: ['value'] },",
136
- " execute: async (input) => {",
137
- " globalThis.__clinePluginHost?.emitEvent?.('test_event', { value: input.value });",
138
- " return { ok: true };",
139
- " },",
140
- " });",
141
- " },",
142
- "};",
143
- ].join("\n"),
144
- "utf8",
145
- );
146
-
147
- const events: Array<{ name: string; payload?: unknown }> = [];
148
- const sandboxed = await loadSandboxedPlugins({
149
- pluginPaths: [pluginPath],
150
- onEvent: (event) => {
151
- events.push(event);
152
- },
153
- });
154
- try {
155
- const extension = sandboxed.extensions?.[0];
156
- const { tools, api } = createApiCapture();
157
- await extension?.setup?.(api);
158
- const tool = tools.find((entry) => entry.name === "emit_event");
159
- await tool?.execute({ value: "hello" }, {
160
- agentId: "agent-1",
161
- conversationId: "conv-1",
162
- iteration: 1,
163
- } as ToolContext);
164
- expect(events).toEqual([
165
- {
166
- name: "test_event",
167
- payload: { value: "hello" },
168
- },
169
- ]);
170
- } finally {
171
- await sandboxed.shutdown();
172
- }
173
- } finally {
174
- await rm(dir, { recursive: true, force: true });
175
- }
176
- });
177
-
178
- it("loads TypeScript plugins in the sandbox process", async () => {
179
- const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-ts-"));
180
- try {
181
- const pluginPath = join(dir, "plugin-ts.ts");
182
- await writeFile(
183
- pluginPath,
184
- [
185
- "const TOOL_NAME: string = 'sandbox_ts_echo';",
186
- "export default {",
187
- " name: 'sandbox-ts',",
188
- " manifest: { capabilities: ['tools'] },",
189
- " setup(api) {",
190
- " api.registerTool({",
191
- " name: TOOL_NAME,",
192
- " description: 'echo',",
193
- " inputSchema: { type: 'object', properties: { value: { type: 'string' } }, required: ['value'] },",
194
- " execute: async (input) => ({ echoed: input.value }),",
195
- " });",
196
- " },",
197
- "};",
198
- ].join("\n"),
199
- "utf8",
200
- );
201
-
202
- const sandboxed = await loadSandboxedPlugins({
203
- pluginPaths: [pluginPath],
204
- });
205
- try {
206
- const extension = sandboxed.extensions?.[0];
207
- expect(extension?.name).toBe("sandbox-ts");
208
- const { tools, api } = createApiCapture();
209
- await extension?.setup?.(api);
210
- const tool = tools.find((entry) => entry.name === "sandbox_ts_echo");
211
- expect(tool).toBeDefined();
212
- const result = await tool?.execute({ value: "ok" }, {
213
- agentId: "agent-1",
214
- conversationId: "conv-1",
215
- iteration: 1,
216
- } as ToolContext);
217
- expect(result).toEqual({ echoed: "ok" });
218
- } finally {
219
- await sandboxed.shutdown();
220
- }
221
- } finally {
222
- await rm(dir, { recursive: true, force: true });
223
- }
224
- });
225
-
226
- it("resolves plugin-local dependencies in the sandbox process", async () => {
227
- const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-deps-"));
228
- try {
229
- const depDir = join(dir, "node_modules", "sandbox-local-dep");
230
- await mkdir(depDir, { recursive: true });
231
- await writeFile(
232
- join(depDir, "package.json"),
233
- JSON.stringify({
234
- name: "sandbox-local-dep",
235
- type: "module",
236
- exports: "./index.js",
237
- }),
238
- "utf8",
239
- );
240
- await writeFile(
241
- join(depDir, "index.js"),
242
- "export const depName = 'sandbox-local-dep';\n",
243
- "utf8",
244
- );
245
- const pluginPath = join(dir, "plugin-dep.ts");
246
- await writeFile(
247
- pluginPath,
248
- [
249
- "import { depName } from 'sandbox-local-dep';",
250
- "export default {",
251
- " name: depName,",
252
- " manifest: { capabilities: ['tools'] },",
253
- "};",
254
- ].join("\n"),
255
- "utf8",
256
- );
257
-
258
- const sandboxed = await loadSandboxedPlugins({
259
- pluginPaths: [pluginPath],
260
- });
261
- try {
262
- expect(sandboxed.extensions?.[0]?.name).toBe("sandbox-local-dep");
263
- } finally {
264
- await sandboxed.shutdown();
265
- }
266
- } finally {
267
- await rm(dir, { recursive: true, force: true });
268
- }
269
- });
270
-
271
- it("prefers plugin-installed SDK packages in the sandbox process", async () => {
272
- const dir = await mkdtemp(join(tmpdir(), "core-plugin-sandbox-sdk-"));
273
- try {
274
- const depDir = join(dir, "node_modules", "@clinebot", "shared");
275
- await mkdir(depDir, { recursive: true });
276
- await writeFile(
277
- join(depDir, "package.json"),
278
- JSON.stringify({
279
- name: "@clinebot/shared",
280
- type: "module",
281
- exports: "./index.js",
282
- }),
283
- "utf8",
284
- );
285
- await writeFile(
286
- join(depDir, "index.js"),
287
- "export const sdkMarker = 'sandbox-plugin-installed-sdk';\n",
288
- "utf8",
289
- );
290
- const pluginPath = join(dir, "plugin-sdk.ts");
291
- await writeFile(
292
- pluginPath,
293
- [
294
- "import { sdkMarker } from '@clinebot/shared';",
295
- "export default {",
296
- " name: sdkMarker,",
297
- " manifest: { capabilities: ['tools'] },",
298
- "};",
299
- ].join("\n"),
300
- "utf8",
301
- );
302
-
303
- const sandboxed = await loadSandboxedPlugins({
304
- pluginPaths: [pluginPath],
305
- });
306
- try {
307
- expect(sandboxed.extensions?.[0]?.name).toBe(
308
- "sandbox-plugin-installed-sdk",
309
- );
310
- } finally {
311
- await sandboxed.shutdown();
312
- }
313
- } finally {
314
- await rm(dir, { recursive: true, force: true });
315
- }
316
- });
317
- });
@@ -1,341 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import type { AgentConfig, Tool } from "@clinebot/agents";
5
- import { SubprocessSandbox } from "../runtime/sandbox/subprocess-sandbox";
6
-
7
- export interface PluginSandboxOptions {
8
- pluginPaths: string[];
9
- exportName?: string;
10
- importTimeoutMs?: number;
11
- hookTimeoutMs?: number;
12
- contributionTimeoutMs?: number;
13
- onEvent?: (event: { name: string; payload?: unknown }) => void;
14
- }
15
-
16
- type AgentExtension = NonNullable<AgentConfig["extensions"]>[number];
17
- type AgentExtensionApi = Parameters<NonNullable<AgentExtension["setup"]>>[0];
18
- type HookStage =
19
- | "input"
20
- | "runtime_event"
21
- | "session_start"
22
- | "before_agent_start"
23
- | "tool_call_before"
24
- | "tool_call_after"
25
- | "turn_end"
26
- | "session_shutdown"
27
- | "error";
28
-
29
- type SandboxedContributionDescriptor = {
30
- id: string;
31
- name: string;
32
- description?: string;
33
- inputSchema?: unknown;
34
- timeoutMs?: number;
35
- retryable?: boolean;
36
- value?: string;
37
- defaultValue?: boolean | string | number;
38
- metadata?: Record<string, unknown>;
39
- };
40
-
41
- type SandboxedPluginDescriptor = {
42
- pluginId: string;
43
- name: string;
44
- manifest: AgentExtension["manifest"];
45
- contributions: {
46
- tools: SandboxedContributionDescriptor[];
47
- commands: SandboxedContributionDescriptor[];
48
- shortcuts: SandboxedContributionDescriptor[];
49
- flags: SandboxedContributionDescriptor[];
50
- messageRenderers: SandboxedContributionDescriptor[];
51
- providers: SandboxedContributionDescriptor[];
52
- };
53
- };
54
-
55
- /**
56
- * Resolve the bootstrap for the sandbox subprocess.
57
- *
58
- * In production (bundled), the compiled `.js` file lives next to this module
59
- * and can be passed directly as a file to spawn. In development/test
60
- * (unbundled, where only the `.ts` source exists), we load the TypeScript
61
- * bootstrap through jiti from an inline script.
62
- */
63
- function resolveBootstrap(): { file: string } | { script: string } {
64
- const dir = dirname(fileURLToPath(import.meta.url));
65
- // In dev, the bootstrap sits next to this file in src/agents/.
66
- // In production, the main bundle is at dist/ but bootstrap is at dist/agents/.
67
- const candidates = [
68
- join(dir, "plugin-sandbox-bootstrap.js"),
69
- join(dir, "agents", "plugin-sandbox-bootstrap.js"),
70
- ];
71
- for (const candidate of candidates) {
72
- if (existsSync(candidate)) return { file: candidate };
73
- }
74
- const tsPath = join(dir, "plugin-sandbox-bootstrap.ts");
75
- return {
76
- script: [
77
- "const createJiti = require('jiti');",
78
- `const jiti = createJiti(${JSON.stringify(tsPath)}, { cache: false, requireCache: false, esmResolve: true, interopDefault: false });`,
79
- `Promise.resolve(jiti.import(${JSON.stringify(tsPath)}, {})).catch((error) => {`,
80
- " console.error(error);",
81
- " process.exitCode = 1;",
82
- "});",
83
- ].join("\n"),
84
- };
85
- }
86
-
87
- const BOOTSTRAP = resolveBootstrap();
88
-
89
- /**
90
- * Map from hook stage names in the manifest to the property name on AgentExtension
91
- * and the corresponding hook method name inside the sandbox subprocess.
92
- */
93
- const HOOK_BINDINGS: Array<{
94
- stage: HookStage;
95
- extensionKey: keyof AgentExtension;
96
- sandboxHookName: string;
97
- }> = [
98
- { stage: "input", extensionKey: "onInput", sandboxHookName: "onInput" },
99
- {
100
- stage: "session_start",
101
- extensionKey: "onSessionStart",
102
- sandboxHookName: "onSessionStart",
103
- },
104
- {
105
- stage: "before_agent_start",
106
- extensionKey: "onBeforeAgentStart",
107
- sandboxHookName: "onBeforeAgentStart",
108
- },
109
- {
110
- stage: "tool_call_before",
111
- extensionKey: "onToolCall",
112
- sandboxHookName: "onToolCall",
113
- },
114
- {
115
- stage: "tool_call_after",
116
- extensionKey: "onToolResult",
117
- sandboxHookName: "onToolResult",
118
- },
119
- {
120
- stage: "turn_end",
121
- extensionKey: "onAgentEnd",
122
- sandboxHookName: "onAgentEnd",
123
- },
124
- {
125
- stage: "session_shutdown",
126
- extensionKey: "onSessionShutdown",
127
- sandboxHookName: "onSessionShutdown",
128
- },
129
- {
130
- stage: "runtime_event",
131
- extensionKey: "onRuntimeEvent",
132
- sandboxHookName: "onRuntimeEvent",
133
- },
134
- { stage: "error", extensionKey: "onError", sandboxHookName: "onError" },
135
- ];
136
-
137
- function hasHookStage(extension: AgentExtension, stage: HookStage): boolean {
138
- return extension.manifest.hookStages?.includes(stage) === true;
139
- }
140
-
141
- function withTimeoutFallback(
142
- timeoutMs: number | undefined,
143
- fallback: number,
144
- ): number {
145
- return typeof timeoutMs === "number" && timeoutMs > 0 ? timeoutMs : fallback;
146
- }
147
-
148
- export async function loadSandboxedPlugins(
149
- options: PluginSandboxOptions,
150
- ): Promise<{
151
- extensions: AgentConfig["extensions"];
152
- shutdown: () => Promise<void>;
153
- }> {
154
- const sandbox = new SubprocessSandbox({
155
- name: "plugin-sandbox",
156
- ...("file" in BOOTSTRAP
157
- ? { bootstrapFile: BOOTSTRAP.file }
158
- : { bootstrapScript: BOOTSTRAP.script }),
159
- onEvent: options.onEvent,
160
- });
161
- const importTimeoutMs = withTimeoutFallback(options.importTimeoutMs, 4000);
162
- const hookTimeoutMs = withTimeoutFallback(options.hookTimeoutMs, 3000);
163
- const contributionTimeoutMs = withTimeoutFallback(
164
- options.contributionTimeoutMs,
165
- 5000,
166
- );
167
-
168
- let descriptors: SandboxedPluginDescriptor[];
169
- try {
170
- descriptors = await sandbox.call<SandboxedPluginDescriptor[]>(
171
- "initialize",
172
- {
173
- pluginPaths: options.pluginPaths,
174
- exportName: options.exportName,
175
- },
176
- { timeoutMs: importTimeoutMs },
177
- );
178
- } catch (error) {
179
- await sandbox.shutdown().catch(() => {
180
- // Best-effort cleanup when sandbox initialization fails.
181
- });
182
- throw error;
183
- }
184
-
185
- const extensions: NonNullable<AgentConfig["extensions"]> = descriptors.map(
186
- (descriptor) => {
187
- const extension: AgentExtension = {
188
- name: descriptor.name,
189
- manifest: descriptor.manifest,
190
- setup: (api: AgentExtensionApi) => {
191
- registerTools(api, sandbox, descriptor, contributionTimeoutMs);
192
- registerCommands(api, sandbox, descriptor, contributionTimeoutMs);
193
- registerSimpleContributions(api, descriptor);
194
- },
195
- };
196
-
197
- bindHooks(extension, sandbox, descriptor.pluginId, hookTimeoutMs);
198
-
199
- return extension;
200
- },
201
- );
202
-
203
- return {
204
- extensions,
205
- shutdown: async () => {
206
- await sandbox.shutdown();
207
- },
208
- };
209
- }
210
-
211
- // ---------------------------------------------------------------------------
212
- // Contribution registration helpers
213
- // ---------------------------------------------------------------------------
214
-
215
- function registerTools(
216
- api: AgentExtensionApi,
217
- sandbox: SubprocessSandbox,
218
- descriptor: SandboxedPluginDescriptor,
219
- timeoutMs: number,
220
- ): void {
221
- for (const td of descriptor.contributions.tools) {
222
- const tool: Tool = {
223
- name: td.name,
224
- description: td.description ?? "",
225
- inputSchema: (td.inputSchema ?? {
226
- type: "object",
227
- properties: {},
228
- }) as Tool["inputSchema"],
229
- timeoutMs: td.timeoutMs,
230
- retryable: td.retryable,
231
- execute: async (input: unknown, context: unknown) =>
232
- await sandbox.call(
233
- "executeTool",
234
- {
235
- pluginId: descriptor.pluginId,
236
- contributionId: td.id,
237
- input,
238
- context,
239
- },
240
- { timeoutMs },
241
- ),
242
- };
243
- api.registerTool(tool);
244
- }
245
- }
246
-
247
- function registerCommands(
248
- api: AgentExtensionApi,
249
- sandbox: SubprocessSandbox,
250
- descriptor: SandboxedPluginDescriptor,
251
- timeoutMs: number,
252
- ): void {
253
- for (const cd of descriptor.contributions.commands) {
254
- api.registerCommand({
255
- name: cd.name,
256
- description: cd.description,
257
- handler: async (input: string) =>
258
- await sandbox.call<string>(
259
- "executeCommand",
260
- {
261
- pluginId: descriptor.pluginId,
262
- contributionId: cd.id,
263
- input,
264
- },
265
- { timeoutMs },
266
- ),
267
- });
268
- }
269
- }
270
-
271
- function registerSimpleContributions(
272
- api: AgentExtensionApi,
273
- descriptor: SandboxedPluginDescriptor,
274
- ): void {
275
- for (const sd of descriptor.contributions.shortcuts) {
276
- api.registerShortcut({
277
- name: sd.name,
278
- value: sd.value ?? "",
279
- description: sd.description,
280
- });
281
- }
282
-
283
- for (const fd of descriptor.contributions.flags) {
284
- api.registerFlag({
285
- name: fd.name,
286
- description: fd.description,
287
- defaultValue: fd.defaultValue,
288
- });
289
- }
290
-
291
- for (const rd of descriptor.contributions.messageRenderers) {
292
- api.registerMessageRenderer({
293
- name: rd.name,
294
- render: () => `[sandbox renderer ${rd.name} requires async bridge]`,
295
- });
296
- }
297
-
298
- for (const pd of descriptor.contributions.providers) {
299
- api.registerProvider({
300
- name: pd.name,
301
- description: pd.description,
302
- metadata: pd.metadata,
303
- });
304
- }
305
- }
306
-
307
- function makeHookHandler(
308
- sandbox: SubprocessSandbox,
309
- pluginId: string,
310
- hookName: string,
311
- timeoutMs: number,
312
- ): (payload: unknown) => Promise<unknown> {
313
- return async (payload: unknown) =>
314
- await sandbox.call(
315
- "invokeHook",
316
- { pluginId, hookName, payload },
317
- { timeoutMs },
318
- );
319
- }
320
-
321
- function bindHooks(
322
- extension: AgentExtension,
323
- sandbox: SubprocessSandbox,
324
- pluginId: string,
325
- hookTimeoutMs: number,
326
- ): void {
327
- for (const { stage, extensionKey, sandboxHookName } of HOOK_BINDINGS) {
328
- if (hasHookStage(extension, stage)) {
329
- const handler = makeHookHandler(
330
- sandbox,
331
- pluginId,
332
- sandboxHookName,
333
- hookTimeoutMs,
334
- );
335
- // Each hook property on AgentExtension accepts (payload: unknown) => Promise<unknown>.
336
- // TypeScript cannot narrow a union of optional callback keys via computed access,
337
- // so we use Object.assign to set the property safely.
338
- Object.assign(extension, { [extensionKey]: handler });
339
- }
340
- }
341
- }