@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,445 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { builtinModules, createRequire } from "node:module";
3
- import { dirname, resolve } from "node:path";
4
- /**
5
- * Bootstrap script for the plugin sandbox subprocess.
6
- *
7
- * This file runs inside an isolated Node.js child process spawned by
8
- * {@link SubprocessSandbox}. It receives RPC calls over IPC and dynamically
9
- * imports plugin modules, wiring up their contributions (tools, commands,
10
- * shortcuts, flags, renderers, providers) and lifecycle hooks.
11
- *
12
- * Because it executes in a separate process it must be self-contained — no
13
- * imports from the rest of the codebase are allowed.
14
- */
15
-
16
- import { fileURLToPath } from "node:url";
17
- import createJiti from "jiti";
18
-
19
- // ---------------------------------------------------------------------------
20
- // Types (intentionally minimal – mirrors only what the RPC protocol needs)
21
- // ---------------------------------------------------------------------------
22
-
23
- interface PluginTool {
24
- name: string;
25
- description?: string;
26
- inputSchema?: unknown;
27
- timeoutMs?: number;
28
- retryable?: boolean;
29
- execute: (input: unknown, context: unknown) => Promise<unknown>;
30
- }
31
-
32
- interface PluginCommand {
33
- name: string;
34
- description?: string;
35
- handler?: (input: string) => Promise<string>;
36
- }
37
-
38
- interface PluginShortcut {
39
- name: string;
40
- value: string;
41
- description?: string;
42
- }
43
-
44
- interface PluginFlag {
45
- name: string;
46
- description?: string;
47
- defaultValue?: boolean | string | number;
48
- }
49
-
50
- interface PluginMessageRenderer {
51
- name: string;
52
- render: (message: unknown) => string;
53
- }
54
-
55
- interface PluginProvider {
56
- name: string;
57
- description?: string;
58
- metadata?: Record<string, unknown>;
59
- }
60
-
61
- interface PluginApi {
62
- registerTool(tool: PluginTool): void;
63
- registerCommand(command: PluginCommand): void;
64
- registerShortcut(shortcut: PluginShortcut): void;
65
- registerFlag(flag: PluginFlag): void;
66
- registerMessageRenderer(renderer: PluginMessageRenderer): void;
67
- registerProvider(provider: PluginProvider): void;
68
- }
69
-
70
- interface PluginModule {
71
- name: string;
72
- manifest: Record<string, unknown>;
73
- setup?: (api: PluginApi) => void | Promise<void>;
74
- [hookName: string]: unknown;
75
- }
76
-
77
- interface ContributionDescriptor {
78
- id: string;
79
- name: string;
80
- description?: string;
81
- inputSchema?: unknown;
82
- timeoutMs?: number;
83
- retryable?: boolean;
84
- value?: string;
85
- defaultValue?: boolean | string | number;
86
- metadata?: Record<string, unknown>;
87
- }
88
-
89
- interface PluginDescriptor {
90
- pluginId: string;
91
- name: string;
92
- manifest: Record<string, unknown>;
93
- contributions: {
94
- tools: ContributionDescriptor[];
95
- commands: ContributionDescriptor[];
96
- shortcuts: ContributionDescriptor[];
97
- flags: ContributionDescriptor[];
98
- messageRenderers: ContributionDescriptor[];
99
- providers: ContributionDescriptor[];
100
- };
101
- }
102
-
103
- interface PluginState {
104
- plugin: PluginModule;
105
- handlers: {
106
- tools: Map<string, PluginTool["execute"]>;
107
- commands: Map<string, NonNullable<PluginCommand["handler"]>>;
108
- messageRenderers: Map<string, PluginMessageRenderer["render"]>;
109
- };
110
- }
111
-
112
- function isObject(value: unknown): value is Record<string, unknown> {
113
- return typeof value === "object" && value !== null;
114
- }
115
-
116
- function assertValidPluginModule(
117
- plugin: unknown,
118
- pluginPath: string,
119
- ): asserts plugin is PluginModule {
120
- if (!isObject(plugin)) {
121
- throw new Error(`Invalid plugin module: ${pluginPath}`);
122
- }
123
- if (typeof plugin.name !== "string" || !plugin.name) {
124
- throw new Error(`Invalid plugin name: ${pluginPath}`);
125
- }
126
- if (!isObject(plugin.manifest)) {
127
- throw new Error(`Invalid plugin manifest: ${pluginPath}`);
128
- }
129
- }
130
-
131
- // ---------------------------------------------------------------------------
132
- // State
133
- // ---------------------------------------------------------------------------
134
-
135
- let pluginCounter = 0;
136
- const pluginState = new Map<string, PluginState>();
137
- const MODULE_DIR = dirname(fileURLToPath(import.meta.url));
138
- const WORKSPACE_ALIASES = collectWorkspaceAliases(MODULE_DIR);
139
- const BUILTIN_MODULES = new Set(
140
- builtinModules.flatMap((id) => [id, id.replace(/^node:/, "")]),
141
- );
142
-
143
- // ---------------------------------------------------------------------------
144
- // IPC helpers
145
- // ---------------------------------------------------------------------------
146
-
147
- function toErrorPayload(error: unknown): { message: string; stack?: string } {
148
- const message = error instanceof Error ? error.message : String(error);
149
- const stack = error instanceof Error ? error.stack : undefined;
150
- return { message, stack };
151
- }
152
-
153
- function sendResponse(
154
- id: string,
155
- ok: boolean,
156
- result: unknown,
157
- error?: { message: string; stack?: string },
158
- ): void {
159
- if (!process.send) return;
160
- process.send({ type: "response", id, ok, result, error });
161
- }
162
-
163
- function emitEvent(name: string, payload?: unknown): void {
164
- if (!process.send) return;
165
- process.send({ type: "event", name, payload });
166
- }
167
-
168
- // Expose event emitter to plugins.
169
- (globalThis as Record<string, unknown>).__clinePluginHost = { emitEvent };
170
-
171
- // ---------------------------------------------------------------------------
172
- // Helpers
173
- // ---------------------------------------------------------------------------
174
-
175
- function sanitizeObject(value: unknown): Record<string, unknown> {
176
- if (!value || typeof value !== "object") return {};
177
- return value as Record<string, unknown>;
178
- }
179
-
180
- function makeId(pluginId: string, prefix: string): string {
181
- return `${pluginId}_${prefix}_${Math.random().toString(36).slice(2, 10)}`;
182
- }
183
-
184
- function getPlugin(pluginId: string): PluginState {
185
- const state = pluginState.get(pluginId);
186
- if (!state) {
187
- throw new Error(`Unknown sandbox plugin id: ${pluginId}`);
188
- }
189
- return state;
190
- }
191
-
192
- function collectWorkspaceAliases(startDir: string): Record<string, string> {
193
- const root = resolve(startDir, "..", "..", "..", "..");
194
- const aliases: Record<string, string> = {};
195
- const candidates: Record<string, string> = {
196
- "@clinebot/agents": resolve(root, "packages/agents/src/index.ts"),
197
- "@clinebot/core": resolve(root, "packages/core/src/index.node.ts"),
198
- "@clinebot/llms": resolve(root, "packages/llms/src/index.ts"),
199
- "@clinebot/rpc": resolve(root, "packages/rpc/src/index.ts"),
200
- "@clinebot/scheduler": resolve(root, "packages/scheduler/src/index.ts"),
201
- "@clinebot/shared": resolve(root, "packages/shared/src/index.ts"),
202
- "@clinebot/shared/storage": resolve(
203
- root,
204
- "packages/shared/src/storage/index.ts",
205
- ),
206
- "@clinebot/shared/db": resolve(root, "packages/shared/src/db/index.ts"),
207
- };
208
- for (const [key, value] of Object.entries(candidates)) {
209
- if (existsSync(value)) {
210
- aliases[key] = value;
211
- }
212
- }
213
- return aliases;
214
- }
215
-
216
- function collectPluginImportAliases(
217
- pluginPath: string,
218
- ): Record<string, string> {
219
- const pluginRequire = createRequire(pluginPath);
220
- const aliases: Record<string, string> = {};
221
- for (const [specifier, sourcePath] of Object.entries(WORKSPACE_ALIASES)) {
222
- try {
223
- pluginRequire.resolve(specifier);
224
- continue;
225
- } catch {
226
- // Use the workspace source only when the plugin package does not provide
227
- // its own installed SDK dependency.
228
- }
229
- aliases[specifier] = sourcePath;
230
- }
231
- return aliases;
232
- }
233
-
234
- async function importPluginModule(
235
- pluginPath: string,
236
- ): Promise<Record<string, unknown>> {
237
- const aliases = collectPluginImportAliases(pluginPath);
238
- const jiti = createJiti(pluginPath, {
239
- alias: aliases,
240
- cache: false,
241
- requireCache: false,
242
- esmResolve: true,
243
- interopDefault: false,
244
- nativeModules: [...BUILTIN_MODULES],
245
- transformModules: Object.keys(aliases),
246
- });
247
- return (await jiti.import(pluginPath, {})) as Record<string, unknown>;
248
- }
249
-
250
- // ---------------------------------------------------------------------------
251
- // RPC methods
252
- // ---------------------------------------------------------------------------
253
-
254
- async function initialize(args: {
255
- pluginPaths?: string[];
256
- exportName?: string;
257
- }): Promise<PluginDescriptor[]> {
258
- const descriptors: PluginDescriptor[] = [];
259
- const exportName = args.exportName || "plugin";
260
-
261
- for (const pluginPath of args.pluginPaths || []) {
262
- const moduleExports = await importPluginModule(pluginPath);
263
- const plugin = (moduleExports.default ??
264
- moduleExports[exportName]) as unknown;
265
- assertValidPluginModule(plugin, pluginPath);
266
-
267
- const pluginId = `plugin_${++pluginCounter}`;
268
- const contributions: PluginDescriptor["contributions"] = {
269
- tools: [],
270
- commands: [],
271
- shortcuts: [],
272
- flags: [],
273
- messageRenderers: [],
274
- providers: [],
275
- };
276
- const handlers: PluginState["handlers"] = {
277
- tools: new Map(),
278
- commands: new Map(),
279
- messageRenderers: new Map(),
280
- };
281
-
282
- const api: PluginApi = {
283
- registerTool: (tool) => {
284
- const id = makeId(pluginId, "tool");
285
- handlers.tools.set(id, tool.execute);
286
- contributions.tools.push({
287
- id,
288
- name: tool.name,
289
- description: tool.description,
290
- inputSchema: tool.inputSchema,
291
- timeoutMs: tool.timeoutMs,
292
- retryable: tool.retryable,
293
- });
294
- },
295
- registerCommand: (command) => {
296
- const id = makeId(pluginId, "command");
297
- if (typeof command.handler === "function") {
298
- handlers.commands.set(id, command.handler);
299
- }
300
- contributions.commands.push({
301
- id,
302
- name: command.name,
303
- description: command.description,
304
- });
305
- },
306
- registerShortcut: (shortcut) => {
307
- contributions.shortcuts.push({
308
- id: makeId(pluginId, "shortcut"),
309
- name: shortcut.name,
310
- value: shortcut.value,
311
- description: shortcut.description,
312
- });
313
- },
314
- registerFlag: (flag) => {
315
- contributions.flags.push({
316
- id: makeId(pluginId, "flag"),
317
- name: flag.name,
318
- description: flag.description,
319
- defaultValue: flag.defaultValue,
320
- });
321
- },
322
- registerMessageRenderer: (renderer) => {
323
- const id = makeId(pluginId, "renderer");
324
- handlers.messageRenderers.set(id, renderer.render);
325
- contributions.messageRenderers.push({ id, name: renderer.name });
326
- },
327
- registerProvider: (provider) => {
328
- contributions.providers.push({
329
- id: makeId(pluginId, "provider"),
330
- name: provider.name,
331
- description: provider.description,
332
- metadata: sanitizeObject(provider.metadata),
333
- });
334
- },
335
- };
336
-
337
- if (typeof plugin.setup === "function") {
338
- await plugin.setup(api);
339
- }
340
-
341
- pluginState.set(pluginId, { plugin, handlers });
342
- descriptors.push({
343
- pluginId,
344
- name: plugin.name,
345
- manifest: plugin.manifest,
346
- contributions,
347
- });
348
- }
349
-
350
- return descriptors;
351
- }
352
-
353
- async function invokeHook(args: {
354
- pluginId: string;
355
- hookName: string;
356
- payload: unknown;
357
- }): Promise<unknown> {
358
- const state = getPlugin(args.pluginId);
359
- const handler = state.plugin[args.hookName];
360
- if (typeof handler !== "function") {
361
- return undefined;
362
- }
363
- return await (handler as (payload: unknown) => Promise<unknown>)(
364
- args.payload,
365
- );
366
- }
367
-
368
- async function executeTool(args: {
369
- pluginId: string;
370
- contributionId: string;
371
- input: unknown;
372
- context: unknown;
373
- }): Promise<unknown> {
374
- const state = getPlugin(args.pluginId);
375
- const handler = state.handlers.tools.get(args.contributionId);
376
- if (typeof handler !== "function") {
377
- throw new Error("Unknown sandbox tool contribution");
378
- }
379
- return await handler(args.input, args.context);
380
- }
381
-
382
- async function executeCommand(args: {
383
- pluginId: string;
384
- contributionId: string;
385
- input: string;
386
- }): Promise<string> {
387
- const state = getPlugin(args.pluginId);
388
- const handler = state.handlers.commands.get(args.contributionId);
389
- if (typeof handler !== "function") {
390
- return "";
391
- }
392
- return await handler(args.input);
393
- }
394
-
395
- async function renderMessage(args: {
396
- pluginId: string;
397
- contributionId: string;
398
- message: unknown;
399
- }): Promise<string> {
400
- const state = getPlugin(args.pluginId);
401
- const handler = state.handlers.messageRenderers.get(args.contributionId);
402
- if (typeof handler !== "function") {
403
- return "";
404
- }
405
- return await handler(args.message);
406
- }
407
-
408
- // ---------------------------------------------------------------------------
409
- // Message dispatch
410
- // ---------------------------------------------------------------------------
411
-
412
- const methods: Record<string, (args: never) => Promise<unknown>> = {
413
- initialize,
414
- invokeHook,
415
- executeTool,
416
- executeCommand,
417
- renderMessage,
418
- };
419
-
420
- process.on(
421
- "message",
422
- async (message: {
423
- type: string;
424
- id: string;
425
- method: string;
426
- args?: unknown;
427
- }) => {
428
- if (!message || message.type !== "call") {
429
- return;
430
- }
431
- const method = methods[message.method];
432
- if (!method) {
433
- sendResponse(message.id, false, undefined, {
434
- message: `Unknown method: ${String(message.method)}`,
435
- });
436
- return;
437
- }
438
- try {
439
- const result = await method((message.args || {}) as never);
440
- sendResponse(message.id, true, result);
441
- } catch (error) {
442
- sendResponse(message.id, false, undefined, toErrorPayload(error));
443
- }
444
- },
445
- );