@shareai-lab/kode 2.0.2 → 2.0.3

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 (343) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +649 -25
  3. package/README.zh-CN.md +579 -0
  4. package/cli-acp.js +3 -17
  5. package/cli.js +5 -7
  6. package/dist/chunks/Doctor-M3J7GRTJ.js +12 -0
  7. package/dist/chunks/LogList-ISWZ6DDD.js +121 -0
  8. package/dist/chunks/LogList-ISWZ6DDD.js.map +7 -0
  9. package/dist/chunks/REPL-RQ6LO6S7.js +56 -0
  10. package/dist/chunks/ResumeConversation-6DMVBEGH.js +56 -0
  11. package/dist/chunks/agentLoader-FCRG3TFJ.js +31 -0
  12. package/dist/{agentsValidate-XP3CFN6F.js → chunks/agentsValidate-PEWMYN4Q.js} +97 -69
  13. package/dist/chunks/agentsValidate-PEWMYN4Q.js.map +7 -0
  14. package/dist/{ask-3G5H5KD5.js → chunks/ask-D7SOHJ6Z.js} +36 -44
  15. package/dist/chunks/ask-D7SOHJ6Z.js.map +7 -0
  16. package/dist/chunks/autoUpdater-CNESBOKO.js +19 -0
  17. package/dist/{chunk-EH34V7CY.js → chunks/chunk-2JN5MY67.js} +12 -14
  18. package/dist/chunks/chunk-2JN5MY67.js.map +7 -0
  19. package/dist/chunks/chunk-2QONJ5MG.js +14 -0
  20. package/dist/chunks/chunk-2QONJ5MG.js.map +7 -0
  21. package/dist/chunks/chunk-2WEXPKHH.js +903 -0
  22. package/dist/chunks/chunk-2WEXPKHH.js.map +7 -0
  23. package/dist/{chunk-K2MI4TPB.js → chunks/chunk-3BYE3ME6.js} +717 -792
  24. package/dist/chunks/chunk-3BYE3ME6.js.map +7 -0
  25. package/dist/chunks/chunk-3JDNWX7W.js +1264 -0
  26. package/dist/chunks/chunk-3JDNWX7W.js.map +7 -0
  27. package/dist/chunks/chunk-3OEJVB5A.js +906 -0
  28. package/dist/chunks/chunk-3OEJVB5A.js.map +7 -0
  29. package/dist/chunks/chunk-3TNIOEBO.js +369 -0
  30. package/dist/chunks/chunk-3TNIOEBO.js.map +7 -0
  31. package/dist/chunks/chunk-4A46ZXMJ.js +67 -0
  32. package/dist/chunks/chunk-4A46ZXMJ.js.map +7 -0
  33. package/dist/{chunk-4GAIJGRH.js → chunks/chunk-4ATBQOFO.js} +107 -55
  34. package/dist/chunks/chunk-4ATBQOFO.js.map +7 -0
  35. package/dist/chunks/chunk-4CRUCZR4.js +0 -0
  36. package/dist/{chunk-54DNHKOD.js → chunks/chunk-4EO6SIQY.js} +32 -75
  37. package/dist/chunks/chunk-4EO6SIQY.js.map +7 -0
  38. package/dist/chunks/chunk-53M46S5I.js +64 -0
  39. package/dist/chunks/chunk-53M46S5I.js.map +7 -0
  40. package/dist/{chunk-JC6NCUG5.js → chunks/chunk-54KOYG5C.js} +0 -2
  41. package/dist/{chunk-EZXMVTDU.js → chunks/chunk-6BAS4WY6.js} +29 -45
  42. package/dist/chunks/chunk-6BAS4WY6.js.map +7 -0
  43. package/dist/{chunk-BHGTA6JQ.js → chunks/chunk-6KRRFSDN.js} +4 -6
  44. package/dist/chunks/chunk-6KRRFSDN.js.map +7 -0
  45. package/dist/chunks/chunk-6LJNZK4K.js +39 -0
  46. package/dist/chunks/chunk-6LJNZK4K.js.map +7 -0
  47. package/dist/chunks/chunk-6ZWEOSEI.js +666 -0
  48. package/dist/chunks/chunk-6ZWEOSEI.js.map +7 -0
  49. package/dist/chunks/chunk-77XDJMBP.js +3326 -0
  50. package/dist/chunks/chunk-77XDJMBP.js.map +7 -0
  51. package/dist/chunks/chunk-7RRW4NTB.js +6454 -0
  52. package/dist/chunks/chunk-7RRW4NTB.js.map +7 -0
  53. package/dist/chunks/chunk-7X3TW4JB.js +4520 -0
  54. package/dist/chunks/chunk-7X3TW4JB.js.map +7 -0
  55. package/dist/chunks/chunk-B3MW3YGY.js +1409 -0
  56. package/dist/chunks/chunk-B3MW3YGY.js.map +7 -0
  57. package/dist/chunks/chunk-BBJFHTBC.js +28 -0
  58. package/dist/chunks/chunk-BBJFHTBC.js.map +7 -0
  59. package/dist/chunks/chunk-BHDHXOXB.js +24 -0
  60. package/dist/chunks/chunk-BHDHXOXB.js.map +7 -0
  61. package/dist/{chunk-OZNRLY3E.js → chunks/chunk-BTA7SZ26.js} +152 -223
  62. package/dist/chunks/chunk-BTA7SZ26.js.map +7 -0
  63. package/dist/chunks/chunk-CDGRYGPZ.js +103 -0
  64. package/dist/chunks/chunk-CDGRYGPZ.js.map +7 -0
  65. package/dist/{chunk-S6HRABTA.js → chunks/chunk-CP6E5UG6.js} +1 -4
  66. package/dist/chunks/chunk-CP6E5UG6.js.map +7 -0
  67. package/dist/{chunk-2PMO2FS2.js → chunks/chunk-DQ4JHXMT.js} +462 -424
  68. package/dist/chunks/chunk-DQ4JHXMT.js.map +7 -0
  69. package/dist/chunks/chunk-DXD76CMV.js +208 -0
  70. package/dist/chunks/chunk-DXD76CMV.js.map +7 -0
  71. package/dist/chunks/chunk-GCQCAXJZ.js +0 -0
  72. package/dist/chunks/chunk-GELCZWMB.js +42 -0
  73. package/dist/chunks/chunk-GELCZWMB.js.map +7 -0
  74. package/dist/{chunk-NQLEUHMS.js → chunks/chunk-HJYOH4HC.js} +23 -18
  75. package/dist/chunks/chunk-HJYOH4HC.js.map +7 -0
  76. package/dist/chunks/chunk-HPYNW6TT.js +744 -0
  77. package/dist/chunks/chunk-HPYNW6TT.js.map +7 -0
  78. package/dist/{chunk-2KWKUXLT.js → chunks/chunk-HRJ3ICQK.js} +59 -55
  79. package/dist/chunks/chunk-HRJ3ICQK.js.map +7 -0
  80. package/dist/{chunk-ZQU3TXLC.js → chunks/chunk-IFCIADS3.js} +571 -573
  81. package/dist/chunks/chunk-IFCIADS3.js.map +7 -0
  82. package/dist/chunks/chunk-IN7XZ7BC.js +27 -0
  83. package/dist/chunks/chunk-IN7XZ7BC.js.map +7 -0
  84. package/dist/chunks/chunk-L7P4M4KW.js +193 -0
  85. package/dist/chunks/chunk-L7P4M4KW.js.map +7 -0
  86. package/dist/chunks/chunk-LB6TCPDI.js +0 -0
  87. package/dist/{chunk-3RUXVV4S.js → chunks/chunk-LOCXPQNJ.js} +1 -4
  88. package/dist/{chunk-3RUXVV4S.js.map → chunks/chunk-LOCXPQNJ.js.map} +2 -2
  89. package/dist/{chunk-IE2CG2TV.js → chunks/chunk-LOD5ZHCI.js} +213 -208
  90. package/dist/chunks/chunk-LOD5ZHCI.js.map +7 -0
  91. package/dist/{chunk-S3J2TLV6.js → chunks/chunk-M7P3QNRU.js} +1 -4
  92. package/dist/{chunk-S3J2TLV6.js.map → chunks/chunk-M7P3QNRU.js.map} +2 -2
  93. package/dist/chunks/chunk-PPHLQVL7.js +4234 -0
  94. package/dist/chunks/chunk-PPHLQVL7.js.map +7 -0
  95. package/dist/{chunk-ABLVTESJ.js → chunks/chunk-QAXE37B5.js} +1 -4
  96. package/dist/chunks/chunk-QAXE37B5.js.map +7 -0
  97. package/dist/chunks/chunk-QHQOBUF6.js +60 -0
  98. package/dist/chunks/chunk-QHQOBUF6.js.map +7 -0
  99. package/dist/{chunk-SRZZFAS7.js → chunks/chunk-RPJXO7GG.js} +241 -214
  100. package/dist/chunks/chunk-RPJXO7GG.js.map +7 -0
  101. package/dist/{chunk-NPFOMITO.js → chunks/chunk-SWQV4KSY.js} +1 -4
  102. package/dist/{chunk-NPFOMITO.js.map → chunks/chunk-SWQV4KSY.js.map} +2 -2
  103. package/dist/chunks/chunk-SZLAPULP.js +28 -0
  104. package/dist/chunks/chunk-SZLAPULP.js.map +7 -0
  105. package/dist/{chunk-SDGKPKDK.js → chunks/chunk-T7RB5V5J.js} +23 -25
  106. package/dist/chunks/chunk-T7RB5V5J.js.map +7 -0
  107. package/dist/{chunk-HN4E4UUQ.js → chunks/chunk-TI2CTTMA.js} +25 -17
  108. package/dist/chunks/chunk-TI2CTTMA.js.map +7 -0
  109. package/dist/{chunk-G6I7XROM.js → chunks/chunk-TNGVRTO5.js} +45 -20
  110. package/dist/chunks/chunk-TNGVRTO5.js.map +7 -0
  111. package/dist/chunks/chunk-TNWB3U5Y.js +2077 -0
  112. package/dist/chunks/chunk-TNWB3U5Y.js.map +7 -0
  113. package/dist/chunks/chunk-U2IHWPCU.js +12 -0
  114. package/dist/chunks/chunk-U2IHWPCU.js.map +7 -0
  115. package/dist/{chunk-KAA5BGMQ.js → chunks/chunk-UNOY3VJ2.js} +1 -4
  116. package/dist/{chunk-KAA5BGMQ.js.map → chunks/chunk-UNOY3VJ2.js.map} +2 -2
  117. package/dist/{chunk-3TXNP6HH.js → chunks/chunk-UVDJL6ZZ.js} +97 -58
  118. package/dist/chunks/chunk-UVDJL6ZZ.js.map +7 -0
  119. package/dist/chunks/chunk-VNCW4C2Z.js +13452 -0
  120. package/dist/chunks/chunk-VNCW4C2Z.js.map +7 -0
  121. package/dist/chunks/chunk-W5EGGA44.js +15 -0
  122. package/dist/chunks/chunk-W5EGGA44.js.map +7 -0
  123. package/dist/chunks/chunk-XR2W3MAM.js +1533 -0
  124. package/dist/chunks/chunk-XR2W3MAM.js.map +7 -0
  125. package/dist/{chunk-QYFKRZQC.js → chunks/chunk-YIO5EBMQ.js} +423 -377
  126. package/dist/chunks/chunk-YIO5EBMQ.js.map +7 -0
  127. package/dist/chunks/chunk-ZBVLKZ5V.js +1062 -0
  128. package/dist/chunks/chunk-ZBVLKZ5V.js.map +7 -0
  129. package/dist/{chunk-E6YNABER.js → chunks/chunk-ZCLTZIVP.js} +1 -4
  130. package/dist/chunks/chunk-ZCLTZIVP.js.map +7 -0
  131. package/dist/chunks/client-SILZNM5N.js +42 -0
  132. package/dist/{config-6ZMBCL23.js → chunks/config-25HRTPSP.js} +48 -10
  133. package/dist/chunks/cost-tracker-Z2UZT2J5.js +28 -0
  134. package/dist/{customCommands-DNEJS3ZU.js → chunks/customCommands-TYMYZRG5.js} +11 -8
  135. package/dist/chunks/engine-MRVF6FK6.js +39 -0
  136. package/dist/{env-OFAXZ3XG.js → chunks/env-TJ5NOBEB.js} +7 -5
  137. package/dist/{kodeAgentSessionId-X6XWQW7B.js → chunks/kodeAgentSessionId-VTNISJ2L.js} +2 -4
  138. package/dist/chunks/kodeAgentSessionLoad-YB2RKBGJ.js +15 -0
  139. package/dist/chunks/kodeAgentSessionResume-DZSIVKVA.js +13 -0
  140. package/dist/chunks/kodeAgentStreamJson-X5PLS2S6.js +11 -0
  141. package/dist/{kodeAgentStreamJsonSession-GRWG3SPE.js → chunks/kodeAgentStreamJsonSession-RDXM4XYF.js} +38 -24
  142. package/dist/chunks/kodeAgentStreamJsonSession-RDXM4XYF.js.map +7 -0
  143. package/dist/{chunk-4RTX4AG4.js → chunks/kodeAgentStructuredStdio-SVGDSB4P.js} +14 -9
  144. package/dist/chunks/kodeAgentStructuredStdio-SVGDSB4P.js.map +7 -0
  145. package/dist/{kodeHooks-TDMXFWSO.js → chunks/kodeHooks-RVKYRJHG.js} +11 -9
  146. package/dist/{llm-XVXWYOHK.js → chunks/llm-62N6T5ZT.js} +1734 -1526
  147. package/dist/chunks/llm-62N6T5ZT.js.map +7 -0
  148. package/dist/chunks/llmLazy-ZUSSE3ZA.js +13 -0
  149. package/dist/{mentionProcessor-YD7YXYGF.js → chunks/mentionProcessor-RJW5UPJD.js} +46 -16
  150. package/dist/chunks/mentionProcessor-RJW5UPJD.js.map +7 -0
  151. package/dist/{messages-OFUJSPRV.js → chunks/messages-EEWWLPHN.js} +2 -6
  152. package/dist/chunks/model-5TIEKQPD.js +37 -0
  153. package/dist/{openai-5G5D5Q4B.js → chunks/openai-XXK3YZG4.js} +13 -10
  154. package/dist/{outputStyles-HLDXFQK3.js → chunks/outputStyles-FAJTXN2A.js} +6 -9
  155. package/dist/chunks/permissions-HO7INPWM.js +27 -0
  156. package/dist/{pluginRuntime-FPTKK6NY.js → chunks/pluginRuntime-C7K5ULK2.js} +31 -48
  157. package/dist/chunks/pluginRuntime-C7K5ULK2.js.map +7 -0
  158. package/dist/chunks/pluginValidation-DAM7WRTC.js +20 -0
  159. package/dist/chunks/registry-XYJXMOA5.js +60 -0
  160. package/dist/chunks/responsesStreaming-JNGE2P3D.js +8 -0
  161. package/dist/chunks/runNonTextPrintMode-SVBLCZQX.js +577 -0
  162. package/dist/chunks/runNonTextPrintMode-SVBLCZQX.js.map +7 -0
  163. package/dist/chunks/server-REXXF5IK.js +46 -0
  164. package/dist/{skillMarketplace-PSNKDINM.js → chunks/skillMarketplace-N4HVHNST.js} +8 -6
  165. package/dist/chunks/src-OROQIWP3.js +44 -0
  166. package/dist/chunks/src-QXLGGMUW.js +1647 -0
  167. package/dist/chunks/src-QXLGGMUW.js.map +7 -0
  168. package/dist/{cli-SRV2INSL.js → chunks/src-SSDT6MVP.js} +2659 -3384
  169. package/dist/chunks/src-SSDT6MVP.js.map +7 -0
  170. package/dist/chunks/theme-YBJUIMWK.js +10 -0
  171. package/dist/{toolPermissionContext-65L65VEZ.js → chunks/toolPermissionContext-MOCTRR7N.js} +2 -4
  172. package/dist/chunks/toolPermissionSettings-EV2EJAXL.js +18 -0
  173. package/dist/chunks/toolPermissionSettings-EV2EJAXL.js.map +7 -0
  174. package/dist/chunks/uuid-6577SO6X.js +7 -0
  175. package/dist/chunks/uuid-6577SO6X.js.map +7 -0
  176. package/dist/chunks/webOnlyMode-ALXX7UQY.js +66 -0
  177. package/dist/chunks/webOnlyMode-ALXX7UQY.js.map +7 -0
  178. package/dist/entrypoints/cli.js +10 -0
  179. package/dist/entrypoints/cli.js.map +7 -0
  180. package/dist/entrypoints/daemon.js +10 -0
  181. package/dist/entrypoints/daemon.js.map +7 -0
  182. package/dist/entrypoints/mcp.js +71 -0
  183. package/dist/entrypoints/mcp.js.map +7 -0
  184. package/dist/index.js +6 -7
  185. package/dist/index.js.map +3 -3
  186. package/dist/sdk/client.cjs +391 -0
  187. package/dist/sdk/client.cjs.map +7 -0
  188. package/dist/sdk/client.js +364 -0
  189. package/dist/sdk/client.js.map +7 -0
  190. package/dist/sdk/core.cjs +19932 -0
  191. package/dist/sdk/core.cjs.map +7 -0
  192. package/dist/sdk/core.js +19893 -0
  193. package/dist/sdk/core.js.map +7 -0
  194. package/dist/sdk/daemon-client.cjs +257 -0
  195. package/dist/sdk/daemon-client.cjs.map +7 -0
  196. package/dist/sdk/daemon-client.js +221 -0
  197. package/dist/sdk/daemon-client.js.map +7 -0
  198. package/dist/sdk/protocol.cjs +170 -0
  199. package/dist/sdk/protocol.cjs.map +7 -0
  200. package/dist/sdk/protocol.js +140 -0
  201. package/dist/sdk/protocol.js.map +7 -0
  202. package/dist/sdk/runtime-node.cjs +236 -0
  203. package/dist/sdk/runtime-node.cjs.map +7 -0
  204. package/dist/sdk/runtime-node.js +222 -0
  205. package/dist/sdk/runtime-node.js.map +7 -0
  206. package/dist/sdk/runtime.cjs +17 -0
  207. package/dist/sdk/runtime.cjs.map +7 -0
  208. package/dist/sdk/runtime.js +0 -0
  209. package/dist/sdk/runtime.js.map +7 -0
  210. package/dist/sdk/tools.cjs +30300 -0
  211. package/dist/sdk/tools.cjs.map +7 -0
  212. package/dist/sdk/tools.js +30282 -0
  213. package/dist/sdk/tools.js.map +7 -0
  214. package/dist/webui/assets/index-5hlfByVS.css +1 -0
  215. package/dist/webui/assets/index-BR9lm1lA.js +82 -0
  216. package/dist/webui/index.html +28 -0
  217. package/package.json +93 -22
  218. package/scripts/binary-utils.cjs +12 -4
  219. package/scripts/cli-acp-wrapper.cjs +3 -17
  220. package/scripts/cli-wrapper.cjs +5 -7
  221. package/scripts/postinstall.js +8 -4
  222. package/dist/REPL-GIU4ZIXM.js +0 -42
  223. package/dist/acp-H3VJ77YG.js +0 -1357
  224. package/dist/acp-H3VJ77YG.js.map +0 -7
  225. package/dist/agentsValidate-XP3CFN6F.js.map +0 -7
  226. package/dist/ask-3G5H5KD5.js.map +0 -7
  227. package/dist/autoUpdater-DNRMJWFQ.js +0 -17
  228. package/dist/chunk-2KWKUXLT.js.map +0 -7
  229. package/dist/chunk-2PMO2FS2.js.map +0 -7
  230. package/dist/chunk-3TXNP6HH.js.map +0 -7
  231. package/dist/chunk-4GAIJGRH.js.map +0 -7
  232. package/dist/chunk-4RTX4AG4.js.map +0 -7
  233. package/dist/chunk-54DNHKOD.js.map +0 -7
  234. package/dist/chunk-67PY5IX6.js +0 -34
  235. package/dist/chunk-67PY5IX6.js.map +0 -7
  236. package/dist/chunk-6DRDLOLP.js +0 -2613
  237. package/dist/chunk-6DRDLOLP.js.map +0 -7
  238. package/dist/chunk-7CQVZNQV.js +0 -1609
  239. package/dist/chunk-7CQVZNQV.js.map +0 -7
  240. package/dist/chunk-ABLVTESJ.js.map +0 -7
  241. package/dist/chunk-AIMIPK4B.js +0 -835
  242. package/dist/chunk-AIMIPK4B.js.map +0 -7
  243. package/dist/chunk-BHGTA6JQ.js.map +0 -7
  244. package/dist/chunk-CIG63V4E.js +0 -72
  245. package/dist/chunk-CIG63V4E.js.map +0 -7
  246. package/dist/chunk-E6YNABER.js.map +0 -7
  247. package/dist/chunk-EH34V7CY.js.map +0 -7
  248. package/dist/chunk-EZXMVTDU.js.map +0 -7
  249. package/dist/chunk-FH5CHM6L.js +0 -148
  250. package/dist/chunk-FH5CHM6L.js.map +0 -7
  251. package/dist/chunk-G6I7XROM.js.map +0 -7
  252. package/dist/chunk-HN4E4UUQ.js.map +0 -7
  253. package/dist/chunk-HSPVVDIW.js +0 -30198
  254. package/dist/chunk-HSPVVDIW.js.map +0 -7
  255. package/dist/chunk-IE2CG2TV.js.map +0 -7
  256. package/dist/chunk-K2MI4TPB.js.map +0 -7
  257. package/dist/chunk-MN77D2F7.js +0 -2931
  258. package/dist/chunk-MN77D2F7.js.map +0 -7
  259. package/dist/chunk-NQLEUHMS.js.map +0 -7
  260. package/dist/chunk-OIFQB3S4.js +0 -515
  261. package/dist/chunk-OIFQB3S4.js.map +0 -7
  262. package/dist/chunk-OWTG2W3A.js +0 -164
  263. package/dist/chunk-OWTG2W3A.js.map +0 -7
  264. package/dist/chunk-OZNRLY3E.js.map +0 -7
  265. package/dist/chunk-QYFKRZQC.js.map +0 -7
  266. package/dist/chunk-S6HRABTA.js.map +0 -7
  267. package/dist/chunk-SDGKPKDK.js.map +0 -7
  268. package/dist/chunk-SRZZFAS7.js.map +0 -7
  269. package/dist/chunk-UKHTVRJM.js +0 -47
  270. package/dist/chunk-UKHTVRJM.js.map +0 -7
  271. package/dist/chunk-UYXEDKOZ.js +0 -24
  272. package/dist/chunk-UYXEDKOZ.js.map +0 -7
  273. package/dist/chunk-VBXVYQYY.js +0 -145
  274. package/dist/chunk-VBXVYQYY.js.map +0 -7
  275. package/dist/chunk-WVHORZQ5.js +0 -17
  276. package/dist/chunk-WVHORZQ5.js.map +0 -7
  277. package/dist/chunk-WWUWDNWW.js +0 -49
  278. package/dist/chunk-WWUWDNWW.js.map +0 -7
  279. package/dist/chunk-Z33T5YN5.js +0 -654
  280. package/dist/chunk-Z33T5YN5.js.map +0 -7
  281. package/dist/chunk-ZQU3TXLC.js.map +0 -7
  282. package/dist/cli-SRV2INSL.js.map +0 -7
  283. package/dist/commands-TWH6PGVG.js +0 -46
  284. package/dist/context-JQIOOI4W.js +0 -30
  285. package/dist/costTracker-6SL26FDB.js +0 -19
  286. package/dist/kodeAgentSessionLoad-6N27AC5K.js +0 -18
  287. package/dist/kodeAgentSessionResume-HUSAEO24.js +0 -16
  288. package/dist/kodeAgentStreamJson-NXFN7TXH.js +0 -13
  289. package/dist/kodeAgentStreamJsonSession-GRWG3SPE.js.map +0 -7
  290. package/dist/kodeAgentStructuredStdio-HGWJT7CU.js +0 -10
  291. package/dist/llm-XVXWYOHK.js.map +0 -7
  292. package/dist/llmLazy-7TD5N7XP.js +0 -15
  293. package/dist/loader-AUXIJTY6.js +0 -28
  294. package/dist/mcp-BXJ3K7NZ.js +0 -49
  295. package/dist/mentionProcessor-YD7YXYGF.js.map +0 -7
  296. package/dist/model-KPYCXWBK.js +0 -30
  297. package/dist/pluginRuntime-FPTKK6NY.js.map +0 -7
  298. package/dist/pluginValidation-DSFXZ4GF.js +0 -17
  299. package/dist/prompts-LWLAJRS2.js +0 -48
  300. package/dist/query-HVPWL27C.js +0 -50
  301. package/dist/responsesStreaming-AW344PQO.js +0 -10
  302. package/dist/ripgrep-YOPCY2GO.js +0 -17
  303. package/dist/state-KNRWP3FO.js +0 -16
  304. package/dist/theme-7S2QN2FO.js +0 -14
  305. package/dist/toolPermissionSettings-GPOBH4IV.js +0 -18
  306. package/dist/tools-FZU2FZBD.js +0 -47
  307. package/dist/userInput-VHNBN2MW.js +0 -311
  308. package/dist/userInput-VHNBN2MW.js.map +0 -7
  309. package/dist/uuid-QN2CNKKN.js +0 -9
  310. /package/dist/{REPL-GIU4ZIXM.js.map → chunks/Doctor-M3J7GRTJ.js.map} +0 -0
  311. /package/dist/{autoUpdater-DNRMJWFQ.js.map → chunks/REPL-RQ6LO6S7.js.map} +0 -0
  312. /package/dist/{chunk-JC6NCUG5.js.map → chunks/ResumeConversation-6DMVBEGH.js.map} +0 -0
  313. /package/dist/{commands-TWH6PGVG.js.map → chunks/agentLoader-FCRG3TFJ.js.map} +0 -0
  314. /package/dist/{config-6ZMBCL23.js.map → chunks/autoUpdater-CNESBOKO.js.map} +0 -0
  315. /package/dist/{context-JQIOOI4W.js.map → chunks/chunk-4CRUCZR4.js.map} +0 -0
  316. /package/dist/{costTracker-6SL26FDB.js.map → chunks/chunk-54KOYG5C.js.map} +0 -0
  317. /package/dist/{customCommands-DNEJS3ZU.js.map → chunks/chunk-GCQCAXJZ.js.map} +0 -0
  318. /package/dist/{env-OFAXZ3XG.js.map → chunks/chunk-LB6TCPDI.js.map} +0 -0
  319. /package/dist/{kodeAgentSessionId-X6XWQW7B.js.map → chunks/client-SILZNM5N.js.map} +0 -0
  320. /package/dist/{kodeAgentSessionLoad-6N27AC5K.js.map → chunks/config-25HRTPSP.js.map} +0 -0
  321. /package/dist/{kodeAgentSessionResume-HUSAEO24.js.map → chunks/cost-tracker-Z2UZT2J5.js.map} +0 -0
  322. /package/dist/{kodeAgentStreamJson-NXFN7TXH.js.map → chunks/customCommands-TYMYZRG5.js.map} +0 -0
  323. /package/dist/{kodeAgentStructuredStdio-HGWJT7CU.js.map → chunks/engine-MRVF6FK6.js.map} +0 -0
  324. /package/dist/{kodeHooks-TDMXFWSO.js.map → chunks/env-TJ5NOBEB.js.map} +0 -0
  325. /package/dist/{llmLazy-7TD5N7XP.js.map → chunks/kodeAgentSessionId-VTNISJ2L.js.map} +0 -0
  326. /package/dist/{loader-AUXIJTY6.js.map → chunks/kodeAgentSessionLoad-YB2RKBGJ.js.map} +0 -0
  327. /package/dist/{mcp-BXJ3K7NZ.js.map → chunks/kodeAgentSessionResume-DZSIVKVA.js.map} +0 -0
  328. /package/dist/{messages-OFUJSPRV.js.map → chunks/kodeAgentStreamJson-X5PLS2S6.js.map} +0 -0
  329. /package/dist/{model-KPYCXWBK.js.map → chunks/kodeHooks-RVKYRJHG.js.map} +0 -0
  330. /package/dist/{openai-5G5D5Q4B.js.map → chunks/llmLazy-ZUSSE3ZA.js.map} +0 -0
  331. /package/dist/{outputStyles-HLDXFQK3.js.map → chunks/messages-EEWWLPHN.js.map} +0 -0
  332. /package/dist/{pluginValidation-DSFXZ4GF.js.map → chunks/model-5TIEKQPD.js.map} +0 -0
  333. /package/dist/{prompts-LWLAJRS2.js.map → chunks/openai-XXK3YZG4.js.map} +0 -0
  334. /package/dist/{query-HVPWL27C.js.map → chunks/outputStyles-FAJTXN2A.js.map} +0 -0
  335. /package/dist/{responsesStreaming-AW344PQO.js.map → chunks/permissions-HO7INPWM.js.map} +0 -0
  336. /package/dist/{ripgrep-YOPCY2GO.js.map → chunks/pluginValidation-DAM7WRTC.js.map} +0 -0
  337. /package/dist/{skillMarketplace-PSNKDINM.js.map → chunks/registry-XYJXMOA5.js.map} +0 -0
  338. /package/dist/{state-KNRWP3FO.js.map → chunks/responsesStreaming-JNGE2P3D.js.map} +0 -0
  339. /package/dist/{theme-7S2QN2FO.js.map → chunks/server-REXXF5IK.js.map} +0 -0
  340. /package/dist/{toolPermissionContext-65L65VEZ.js.map → chunks/skillMarketplace-N4HVHNST.js.map} +0 -0
  341. /package/dist/{toolPermissionSettings-GPOBH4IV.js.map → chunks/src-OROQIWP3.js.map} +0 -0
  342. /package/dist/{tools-FZU2FZBD.js.map → chunks/theme-YBJUIMWK.js.map} +0 -0
  343. /package/dist/{uuid-QN2CNKKN.js.map → chunks/toolPermissionContext-MOCTRR7N.js.map} +0 -0
@@ -0,0 +1,1062 @@
1
+ import {
2
+ getSessionPlugins
3
+ } from "./chunk-M7P3QNRU.js";
4
+ import {
5
+ PRODUCT_COMMAND,
6
+ logError,
7
+ logMCPError
8
+ } from "./chunk-3OEJVB5A.js";
9
+ import {
10
+ getCwd
11
+ } from "./chunk-BBJFHTBC.js";
12
+ import {
13
+ addMcprcServerForTesting,
14
+ getCurrentProjectConfig,
15
+ getGlobalConfig,
16
+ getProjectMcpServerDefinitions,
17
+ removeMcprcServerForTesting,
18
+ saveCurrentProjectConfig,
19
+ saveGlobalConfig
20
+ } from "./chunk-XR2W3MAM.js";
21
+
22
+ // packages/core/src/mcp/client/config.ts
23
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
24
+ import { join, resolve } from "node:path";
25
+
26
+ // packages/core/src/utils/json.ts
27
+ function safeParseJSON(json) {
28
+ if (!json) {
29
+ return null;
30
+ }
31
+ try {
32
+ return JSON.parse(json);
33
+ } catch (e) {
34
+ logError(e);
35
+ return null;
36
+ }
37
+ }
38
+
39
+ // packages/core/src/mcp/client/utils.ts
40
+ function isRecord(value) {
41
+ return typeof value === "object" && value !== null && !Array.isArray(value);
42
+ }
43
+ function stripJsonComments(input) {
44
+ let out = "";
45
+ let inString = false;
46
+ let escaped = false;
47
+ let inLineComment = false;
48
+ let inBlockComment = false;
49
+ for (let i = 0; i < input.length; i++) {
50
+ const ch = input[i];
51
+ const next = i + 1 < input.length ? input[i + 1] : "";
52
+ if (inLineComment) {
53
+ if (ch === "\n") {
54
+ inLineComment = false;
55
+ out += ch;
56
+ }
57
+ continue;
58
+ }
59
+ if (inBlockComment) {
60
+ if (ch === "*" && next === "/") {
61
+ inBlockComment = false;
62
+ i++;
63
+ }
64
+ continue;
65
+ }
66
+ if (inString) {
67
+ out += ch;
68
+ if (escaped) {
69
+ escaped = false;
70
+ continue;
71
+ }
72
+ if (ch === "\\") {
73
+ escaped = true;
74
+ continue;
75
+ }
76
+ if (ch === '"') inString = false;
77
+ continue;
78
+ }
79
+ if (ch === '"') {
80
+ inString = true;
81
+ out += ch;
82
+ continue;
83
+ }
84
+ if (ch === "/" && next === "/") {
85
+ inLineComment = true;
86
+ i++;
87
+ continue;
88
+ }
89
+ if (ch === "/" && next === "*") {
90
+ inBlockComment = true;
91
+ i++;
92
+ continue;
93
+ }
94
+ out += ch;
95
+ }
96
+ return out;
97
+ }
98
+ function parseJsonOrJsonc(text) {
99
+ const raw = String(text ?? "");
100
+ if (!raw.trim()) return null;
101
+ try {
102
+ return JSON.parse(raw);
103
+ } catch {
104
+ try {
105
+ return JSON.parse(stripJsonComments(raw));
106
+ } catch {
107
+ return null;
108
+ }
109
+ }
110
+ }
111
+ function expandTemplateString(value, pluginRoot) {
112
+ return value.replace(/\$\{([^}]+)\}/g, (match, key) => {
113
+ const k = String(key ?? "").trim();
114
+ if (!k) return match;
115
+ if (k === "CLAUDE_PLUGIN_ROOT") return pluginRoot;
116
+ const env = process.env[k];
117
+ return env !== void 0 ? env : match;
118
+ });
119
+ }
120
+ function expandTemplateDeep(value, pluginRoot) {
121
+ if (typeof value === "string") return expandTemplateString(value, pluginRoot);
122
+ if (Array.isArray(value))
123
+ return value.map((v) => expandTemplateDeep(v, pluginRoot));
124
+ if (isRecord(value)) {
125
+ const out = {};
126
+ for (const [k, v] of Object.entries(value)) {
127
+ out[k] = expandTemplateDeep(v, pluginRoot);
128
+ }
129
+ return out;
130
+ }
131
+ return value;
132
+ }
133
+
134
+ // packages/core/src/mcp/client/config.ts
135
+ var VALID_SCOPES = ["project", "global", "mcprc", "mcpjson"];
136
+ var EXTERNAL_SCOPES = [
137
+ "project",
138
+ "global",
139
+ "mcprc",
140
+ "mcpjson"
141
+ ];
142
+ function parseEnvVars(rawEnvArgs) {
143
+ const parsedEnv = {};
144
+ if (!rawEnvArgs) return parsedEnv;
145
+ for (const envStr of rawEnvArgs) {
146
+ const [key, ...valueParts] = envStr.split("=");
147
+ if (!key || valueParts.length === 0) {
148
+ throw new Error(
149
+ `Invalid environment variable format: ${envStr}, environment variables should be added as: -e KEY1=value1 -e KEY2=value2`
150
+ );
151
+ }
152
+ parsedEnv[key] = valueParts.join("=");
153
+ }
154
+ return parsedEnv;
155
+ }
156
+ function ensureConfigScope(scope) {
157
+ if (!scope) return "project";
158
+ const scopesToCheck = process.env.USER_TYPE === "external" ? EXTERNAL_SCOPES : VALID_SCOPES;
159
+ if (!scopesToCheck.includes(scope)) {
160
+ throw new Error(
161
+ `Invalid scope: ${scope}. Must be one of: ${scopesToCheck.join(", ")}`
162
+ );
163
+ }
164
+ return scope;
165
+ }
166
+ function listPluginMCPServers() {
167
+ const plugins = getSessionPlugins();
168
+ if (plugins.length === 0) return {};
169
+ const out = {};
170
+ for (const plugin of plugins) {
171
+ const pluginRoot = plugin.rootDir;
172
+ const pluginName = plugin.name;
173
+ const configs = [];
174
+ for (const configPath of plugin.mcpConfigFiles ?? []) {
175
+ try {
176
+ const raw = readFileSync(configPath, "utf8");
177
+ const parsed = parseJsonOrJsonc(raw);
178
+ if (!isRecord(parsed)) continue;
179
+ const maybeNested = parsed["mcpServers"];
180
+ const rawServers = isRecord(maybeNested) ? maybeNested : parsed;
181
+ if (!isRecord(rawServers)) continue;
182
+ const servers = {};
183
+ for (const [name, cfg] of Object.entries(rawServers)) {
184
+ if (!isRecord(cfg)) continue;
185
+ servers[name] = expandTemplateDeep(cfg, pluginRoot);
186
+ }
187
+ configs.push(servers);
188
+ } catch {
189
+ continue;
190
+ }
191
+ }
192
+ if (isRecord(plugin.manifest)) {
193
+ const manifestRaw = plugin.manifest["mcpServers"];
194
+ if (isRecord(manifestRaw)) {
195
+ const maybeNested = manifestRaw["mcpServers"];
196
+ const rawServers = isRecord(maybeNested) ? maybeNested : manifestRaw;
197
+ if (isRecord(rawServers)) {
198
+ const servers = {};
199
+ for (const [name, cfg] of Object.entries(rawServers)) {
200
+ if (!isRecord(cfg)) continue;
201
+ servers[name] = expandTemplateDeep(
202
+ cfg,
203
+ pluginRoot
204
+ );
205
+ }
206
+ configs.push(servers);
207
+ }
208
+ }
209
+ }
210
+ const merged = Object.assign(
211
+ {},
212
+ ...configs
213
+ );
214
+ for (const [serverName, cfg] of Object.entries(merged)) {
215
+ const fullName = `plugin_${pluginName}_${serverName}`;
216
+ out[fullName] = cfg;
217
+ }
218
+ }
219
+ return out;
220
+ }
221
+ function getMcprcServerStatus(serverName) {
222
+ const config = getCurrentProjectConfig();
223
+ if (config.approvedMcprcServers?.includes(serverName)) {
224
+ return "approved";
225
+ }
226
+ if (config.rejectedMcprcServers?.includes(serverName)) {
227
+ return "rejected";
228
+ }
229
+ return "pending";
230
+ }
231
+ function addMcpServer(name, server, scope = "project") {
232
+ if (scope === "mcprc") {
233
+ if (process.env.NODE_ENV === "test") {
234
+ addMcprcServerForTesting(name, server);
235
+ return;
236
+ }
237
+ const mcprcPath = join(getCwd(), ".mcprc");
238
+ let mcprcConfig = {};
239
+ if (existsSync(mcprcPath)) {
240
+ try {
241
+ const mcprcContent = readFileSync(mcprcPath, "utf-8");
242
+ const existingConfig = safeParseJSON(mcprcContent);
243
+ if (isRecord(existingConfig)) {
244
+ mcprcConfig = existingConfig;
245
+ }
246
+ } catch {
247
+ }
248
+ }
249
+ mcprcConfig[name] = server;
250
+ try {
251
+ writeFileSync(mcprcPath, JSON.stringify(mcprcConfig, null, 2), "utf-8");
252
+ } catch (error) {
253
+ throw new Error(`Failed to write to .mcprc: ${error}`);
254
+ }
255
+ return;
256
+ }
257
+ if (scope === "mcpjson") {
258
+ const mcpJsonPath = join(getCwd(), ".mcp.json");
259
+ let config2 = { mcpServers: {} };
260
+ if (existsSync(mcpJsonPath)) {
261
+ try {
262
+ const content = readFileSync(mcpJsonPath, "utf-8");
263
+ const parsed = safeParseJSON(content);
264
+ if (isRecord(parsed)) config2 = parsed;
265
+ } catch {
266
+ }
267
+ }
268
+ const rawServers = config2["mcpServers"];
269
+ const servers = isRecord(rawServers) ? rawServers : {};
270
+ servers[name] = server;
271
+ config2["mcpServers"] = servers;
272
+ try {
273
+ writeFileSync(mcpJsonPath, JSON.stringify(config2, null, 2), "utf-8");
274
+ } catch (error) {
275
+ throw new Error(`Failed to write to .mcp.json: ${error}`);
276
+ }
277
+ return;
278
+ }
279
+ if (scope === "global") {
280
+ const config2 = getGlobalConfig();
281
+ if (!config2.mcpServers) config2.mcpServers = {};
282
+ config2.mcpServers[name] = server;
283
+ saveGlobalConfig(config2);
284
+ return;
285
+ }
286
+ const config = getCurrentProjectConfig();
287
+ if (!config.mcpServers) config.mcpServers = {};
288
+ config.mcpServers[name] = server;
289
+ saveCurrentProjectConfig(config);
290
+ }
291
+ function removeMcpServer(name, scope = "project") {
292
+ if (scope === "mcprc") {
293
+ if (process.env.NODE_ENV === "test") {
294
+ removeMcprcServerForTesting(name);
295
+ return;
296
+ }
297
+ const mcprcPath = join(getCwd(), ".mcprc");
298
+ if (!existsSync(mcprcPath)) {
299
+ throw new Error("No .mcprc file found in this directory");
300
+ }
301
+ const mcprcContent = readFileSync(mcprcPath, "utf-8");
302
+ const parsed = safeParseJSON(mcprcContent);
303
+ if (!isRecord(parsed) || !(name in parsed)) {
304
+ throw new Error(`No MCP server found with name: ${name} in .mcprc`);
305
+ }
306
+ delete parsed[name];
307
+ writeFileSync(mcprcPath, JSON.stringify(parsed, null, 2), "utf-8");
308
+ return;
309
+ }
310
+ if (scope === "mcpjson") {
311
+ const mcpJsonPath = join(getCwd(), ".mcp.json");
312
+ if (!existsSync(mcpJsonPath)) {
313
+ throw new Error("No .mcp.json file found in this directory");
314
+ }
315
+ const content = readFileSync(mcpJsonPath, "utf-8");
316
+ const parsed = safeParseJSON(content);
317
+ if (!isRecord(parsed)) {
318
+ throw new Error("Invalid .mcp.json format");
319
+ }
320
+ const rawServers = parsed["mcpServers"];
321
+ if (!isRecord(rawServers) || !(name in rawServers)) {
322
+ throw new Error(`No MCP server found with name: ${name} in .mcp.json`);
323
+ }
324
+ delete rawServers[name];
325
+ parsed["mcpServers"] = rawServers;
326
+ writeFileSync(mcpJsonPath, JSON.stringify(parsed, null, 2), "utf-8");
327
+ return;
328
+ }
329
+ if (scope === "global") {
330
+ const config2 = getGlobalConfig();
331
+ if (!config2.mcpServers?.[name]) {
332
+ throw new Error(`No MCP server found with name: ${name} in global config`);
333
+ }
334
+ delete config2.mcpServers[name];
335
+ saveGlobalConfig(config2);
336
+ return;
337
+ }
338
+ const config = getCurrentProjectConfig();
339
+ if (!config.mcpServers?.[name]) {
340
+ throw new Error(`No MCP server found with name: ${name} in project config`);
341
+ }
342
+ delete config.mcpServers[name];
343
+ saveCurrentProjectConfig(config);
344
+ }
345
+ function listMCPServers() {
346
+ const pluginServers = listPluginMCPServers();
347
+ const globalConfig = getGlobalConfig();
348
+ const projectFileConfig = getProjectMcpServerDefinitions().servers;
349
+ const projectConfig = getCurrentProjectConfig();
350
+ return {
351
+ ...pluginServers ?? {},
352
+ ...globalConfig.mcpServers ?? {},
353
+ ...projectFileConfig ?? {},
354
+ ...projectConfig.mcpServers ?? {}
355
+ };
356
+ }
357
+ function getMcpServer(name) {
358
+ const projectConfig = getCurrentProjectConfig();
359
+ const projectFileDefinitions = getProjectMcpServerDefinitions();
360
+ const projectFileConfig = projectFileDefinitions.servers;
361
+ const globalConfig = getGlobalConfig();
362
+ if (projectConfig.mcpServers?.[name]) {
363
+ return { ...projectConfig.mcpServers[name], scope: "project" };
364
+ }
365
+ if (projectFileConfig?.[name]) {
366
+ const source = projectFileDefinitions.sources[name];
367
+ const scope = source === ".mcp.json" ? "mcpjson" : "mcprc";
368
+ return { ...projectFileConfig[name], scope };
369
+ }
370
+ if (globalConfig.mcpServers?.[name]) {
371
+ return { ...globalConfig.mcpServers[name], scope: "global" };
372
+ }
373
+ return void 0;
374
+ }
375
+ function parseMcpServersFromCliConfigEntries(options) {
376
+ const out = {};
377
+ for (const rawEntry of options.entries) {
378
+ const entry = String(rawEntry ?? "").trim();
379
+ if (!entry) continue;
380
+ const resolvedPath = resolve(options.projectDir, entry);
381
+ const payload = existsSync(resolvedPath) ? readFileSync(resolvedPath, "utf8") : existsSync(entry) ? readFileSync(entry, "utf8") : entry;
382
+ const parsed = parseJsonOrJsonc(payload);
383
+ if (!isRecord(parsed)) continue;
384
+ const maybeNested = parsed["mcpServers"];
385
+ const rawServers = isRecord(maybeNested) ? maybeNested : parsed;
386
+ if (!isRecord(rawServers)) continue;
387
+ for (const [name, cfg] of Object.entries(rawServers)) {
388
+ if (!isRecord(cfg)) continue;
389
+ out[name] = cfg;
390
+ }
391
+ }
392
+ return out;
393
+ }
394
+
395
+ // packages/core/src/mcp/client/clients.ts
396
+ import { memoize, pickBy } from "lodash-es";
397
+
398
+ // packages/core/src/mcp/client/connection.ts
399
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
400
+ import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
401
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
402
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
403
+ import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
404
+ async function ensureWebSocketGlobal() {
405
+ const global = globalThis;
406
+ if (typeof global.WebSocket === "function") return;
407
+ try {
408
+ const undiciModule = await import("undici");
409
+ const maybeWs = undiciModule.WebSocket;
410
+ if (typeof maybeWs === "function") {
411
+ global.WebSocket = maybeWs;
412
+ }
413
+ } catch {
414
+ }
415
+ }
416
+ function buildStdioEnv(extra) {
417
+ const env = {};
418
+ for (const [key, value] of Object.entries(process.env)) {
419
+ if (typeof value === "string") env[key] = value;
420
+ }
421
+ if (extra) Object.assign(env, extra);
422
+ return env;
423
+ }
424
+ async function connectToServer(name, serverRef) {
425
+ const candidates = await (async () => {
426
+ switch (serverRef.type) {
427
+ case "sse": {
428
+ const ref = serverRef;
429
+ return [
430
+ {
431
+ kind: "sse",
432
+ transport: new SSEClientTransport(new URL(ref.url), {
433
+ ...ref.headers ? { requestInit: { headers: ref.headers } } : {}
434
+ })
435
+ },
436
+ {
437
+ kind: "http",
438
+ transport: new StreamableHTTPClientTransport(new URL(ref.url), {
439
+ ...ref.headers ? { requestInit: { headers: ref.headers } } : {}
440
+ })
441
+ }
442
+ ];
443
+ }
444
+ case "sse-ide": {
445
+ const ref = serverRef;
446
+ return [
447
+ {
448
+ kind: "sse",
449
+ transport: new SSEClientTransport(new URL(ref.url), {
450
+ ...ref.headers ? { requestInit: { headers: ref.headers } } : {}
451
+ })
452
+ }
453
+ ];
454
+ }
455
+ case "http": {
456
+ const ref = serverRef;
457
+ return [
458
+ {
459
+ kind: "http",
460
+ transport: new StreamableHTTPClientTransport(new URL(ref.url), {
461
+ ...ref.headers ? { requestInit: { headers: ref.headers } } : {}
462
+ })
463
+ },
464
+ {
465
+ kind: "sse",
466
+ transport: new SSEClientTransport(new URL(ref.url), {
467
+ ...ref.headers ? { requestInit: { headers: ref.headers } } : {}
468
+ })
469
+ }
470
+ ];
471
+ }
472
+ case "ws": {
473
+ const ref = serverRef;
474
+ await ensureWebSocketGlobal();
475
+ return [
476
+ {
477
+ kind: "ws",
478
+ transport: new WebSocketClientTransport(new URL(ref.url))
479
+ }
480
+ ];
481
+ }
482
+ case "ws-ide": {
483
+ const ref = serverRef;
484
+ let url = ref.url;
485
+ if (ref.authToken) {
486
+ try {
487
+ const parsed = new URL(url);
488
+ if (!parsed.searchParams.has("authToken")) {
489
+ parsed.searchParams.set("authToken", ref.authToken);
490
+ url = parsed.toString();
491
+ }
492
+ } catch {
493
+ }
494
+ }
495
+ await ensureWebSocketGlobal();
496
+ return [
497
+ {
498
+ kind: "ws",
499
+ transport: new WebSocketClientTransport(new URL(url))
500
+ }
501
+ ];
502
+ }
503
+ case "stdio":
504
+ default: {
505
+ const ref = serverRef;
506
+ return [
507
+ {
508
+ kind: "stdio",
509
+ transport: new StdioClientTransport({
510
+ command: ref.command,
511
+ args: ref.args,
512
+ env: buildStdioEnv(ref.env),
513
+ stderr: "pipe"
514
+ })
515
+ }
516
+ ];
517
+ }
518
+ }
519
+ })();
520
+ const rawTimeout = process.env.MCP_CONNECTION_TIMEOUT_MS;
521
+ const parsedTimeout = rawTimeout ? Number.parseInt(rawTimeout, 10) : NaN;
522
+ const connectionTimeoutMs = Number.isFinite(parsedTimeout) ? parsedTimeout : 3e4;
523
+ let lastError;
524
+ for (const candidate of candidates) {
525
+ const client = new Client(
526
+ { name: PRODUCT_COMMAND, version: "0.1.0" },
527
+ { capabilities: {} }
528
+ );
529
+ try {
530
+ const connectPromise = client.connect(candidate.transport);
531
+ if (connectionTimeoutMs > 0) {
532
+ const timeoutPromise = new Promise((_, reject) => {
533
+ const timeoutId = setTimeout(() => {
534
+ reject(
535
+ new Error(
536
+ `Connection to MCP server "${name}" timed out after ${connectionTimeoutMs}ms`
537
+ )
538
+ );
539
+ }, connectionTimeoutMs);
540
+ connectPromise.finally(() => clearTimeout(timeoutId));
541
+ });
542
+ await Promise.race([connectPromise, timeoutPromise]);
543
+ } else {
544
+ await connectPromise;
545
+ }
546
+ if (candidate.kind === "stdio") {
547
+ candidate.transport.stderr?.on("data", (data) => {
548
+ const errorText = data.toString().trim();
549
+ if (errorText) logMCPError(name, `Server stderr: ${errorText}`);
550
+ });
551
+ }
552
+ if (candidates.length > 1 && candidate !== candidates[0]) {
553
+ logMCPError(
554
+ name,
555
+ `Connected using fallback transport "${candidate.kind}". Consider setting the server type explicitly in your MCP config.`
556
+ );
557
+ }
558
+ return client;
559
+ } catch (error) {
560
+ lastError = error;
561
+ try {
562
+ await client.close();
563
+ } catch {
564
+ }
565
+ }
566
+ }
567
+ throw lastError instanceof Error ? lastError : new Error(`Failed to connect to MCP server "${name}"`);
568
+ }
569
+
570
+ // packages/core/src/mcp/client/settings.ts
571
+ function sanitizeMcpIdentifierPart(value) {
572
+ return value.replace(/[^a-zA-Z0-9_-]/g, "_");
573
+ }
574
+ function getMcpServerConnectionBatchSize() {
575
+ const raw = process.env.MCP_SERVER_CONNECTION_BATCH_SIZE;
576
+ const parsed = raw ? Number.parseInt(raw, 10) : Number.NaN;
577
+ if (Number.isFinite(parsed) && parsed > 0 && parsed <= 50) return parsed;
578
+ return 3;
579
+ }
580
+ function getMcpToolTimeoutMs() {
581
+ const raw = process.env.MCP_TOOL_TIMEOUT;
582
+ const parsed = raw ? Number.parseInt(raw, 10) : Number.NaN;
583
+ if (!Number.isFinite(parsed) || parsed <= 0) return null;
584
+ return parsed;
585
+ }
586
+ var IDE_MCP_TOOL_ALLOWLIST = /* @__PURE__ */ new Set([
587
+ "mcp__ide__executeCode",
588
+ "mcp__ide__getDiagnostics"
589
+ ]);
590
+
591
+ // packages/core/src/mcp/client/clients.ts
592
+ var getClients = memoize(async () => {
593
+ if (process.env.CI && process.env.NODE_ENV !== "test") {
594
+ return [];
595
+ }
596
+ const pluginServers = listPluginMCPServers();
597
+ const globalServers = getGlobalConfig().mcpServers ?? {};
598
+ const projectFileServers = getProjectMcpServerDefinitions().servers;
599
+ const projectServers = getCurrentProjectConfig().mcpServers ?? {};
600
+ const approvedProjectFileServers = pickBy(
601
+ projectFileServers,
602
+ (_, name) => getMcprcServerStatus(name) === "approved"
603
+ );
604
+ const allServers = {
605
+ ...pluginServers,
606
+ ...globalServers,
607
+ ...approvedProjectFileServers,
608
+ ...projectServers
609
+ };
610
+ const batchSize = getMcpServerConnectionBatchSize();
611
+ const entries = Object.entries(allServers);
612
+ const results = [];
613
+ for (let i = 0; i < entries.length; i += batchSize) {
614
+ const batch = entries.slice(i, i + batchSize);
615
+ const batchResults = await Promise.all(
616
+ batch.map(async ([name, serverRef]) => {
617
+ try {
618
+ const client = await connectToServer(name, serverRef);
619
+ let capabilities = null;
620
+ try {
621
+ capabilities = client.getServerCapabilities() ?? null;
622
+ } catch {
623
+ capabilities = null;
624
+ }
625
+ return { name, client, capabilities, type: "connected" };
626
+ } catch (error) {
627
+ logMCPError(
628
+ name,
629
+ `Connection failed: ${error instanceof Error ? error.message : String(error)}`
630
+ );
631
+ return { name, type: "failed" };
632
+ }
633
+ })
634
+ );
635
+ results.push(...batchResults);
636
+ }
637
+ return results;
638
+ });
639
+ async function getClientsForCliMcpConfig(options) {
640
+ const projectDir = options.projectDir ?? getCwd();
641
+ const entries = Array.isArray(options.mcpConfig) && options.mcpConfig.length > 0 ? options.mcpConfig : [];
642
+ const strict = options.strictMcpConfig === true;
643
+ if (entries.length === 0 && !strict) {
644
+ return getClients();
645
+ }
646
+ const cliServers = parseMcpServersFromCliConfigEntries({
647
+ entries,
648
+ projectDir
649
+ });
650
+ const pluginServers = strict ? {} : listPluginMCPServers();
651
+ const globalServers = strict ? {} : getGlobalConfig().mcpServers ?? {};
652
+ const projectFileServers = strict ? {} : getProjectMcpServerDefinitions().servers;
653
+ const projectServers = strict ? {} : getCurrentProjectConfig().mcpServers ?? {};
654
+ const approvedProjectFileServers = strict ? {} : pickBy(
655
+ projectFileServers,
656
+ (_, name) => getMcprcServerStatus(name) === "approved"
657
+ );
658
+ const allServers = {
659
+ ...pluginServers ?? {},
660
+ ...globalServers ?? {},
661
+ ...approvedProjectFileServers ?? {},
662
+ ...projectServers ?? {},
663
+ ...cliServers ?? {}
664
+ };
665
+ const batchSize = getMcpServerConnectionBatchSize();
666
+ const entriesToConnect = Object.entries(allServers);
667
+ const results = [];
668
+ for (let i = 0; i < entriesToConnect.length; i += batchSize) {
669
+ const batch = entriesToConnect.slice(i, i + batchSize);
670
+ const batchResults = await Promise.all(
671
+ batch.map(async ([name, serverRef]) => {
672
+ try {
673
+ const client = await connectToServer(name, serverRef);
674
+ let capabilities = null;
675
+ try {
676
+ capabilities = client.getServerCapabilities() ?? null;
677
+ } catch {
678
+ capabilities = null;
679
+ }
680
+ return { name, client, capabilities, type: "connected" };
681
+ } catch (error) {
682
+ logMCPError(
683
+ name,
684
+ `Connection failed: ${error instanceof Error ? error.message : String(error)}`
685
+ );
686
+ return { name, type: "failed" };
687
+ }
688
+ })
689
+ );
690
+ results.push(...batchResults);
691
+ }
692
+ return results;
693
+ }
694
+
695
+ // packages/core/src/mcp/client/tools.ts
696
+ import {
697
+ CallToolResultSchema,
698
+ ListToolsResultSchema
699
+ } from "@modelcontextprotocol/sdk/types.js";
700
+ import { memoize as memoize2 } from "lodash-es";
701
+ import { z } from "zod";
702
+
703
+ // packages/core/src/mcp/client/timeouts.ts
704
+ function createTimeoutSignal(timeoutMs) {
705
+ if (typeof AbortSignal.timeout === "function") {
706
+ return { signal: AbortSignal.timeout(timeoutMs), cleanup: () => {
707
+ } };
708
+ }
709
+ const controller = new AbortController();
710
+ const id = setTimeout(() => controller.abort(), timeoutMs);
711
+ return { signal: controller.signal, cleanup: () => clearTimeout(id) };
712
+ }
713
+ function mergeAbortSignals(signals) {
714
+ const active = signals.filter((s) => !!s);
715
+ if (active.length === 0) return null;
716
+ if (active.length === 1) return { signal: active[0], cleanup: () => {
717
+ } };
718
+ const controller = new AbortController();
719
+ const unsubscribers = [];
720
+ const abort = () => {
721
+ try {
722
+ controller.abort();
723
+ } catch {
724
+ }
725
+ };
726
+ for (const signal of active) {
727
+ if (signal.aborted) {
728
+ abort();
729
+ return { signal: controller.signal, cleanup: () => {
730
+ } };
731
+ }
732
+ signal.addEventListener("abort", abort, { once: true });
733
+ unsubscribers.push(() => {
734
+ try {
735
+ signal.removeEventListener("abort", abort);
736
+ } catch {
737
+ }
738
+ });
739
+ }
740
+ return {
741
+ signal: controller.signal,
742
+ cleanup: () => {
743
+ for (const unsubscribe of unsubscribers) unsubscribe();
744
+ }
745
+ };
746
+ }
747
+
748
+ // packages/core/src/mcp/client/request.ts
749
+ async function requestAll(req, resultSchema, requiredCapability) {
750
+ const timeoutMs = getMcpToolTimeoutMs();
751
+ const clients = await getClients();
752
+ const results = await Promise.allSettled(
753
+ clients.map(async (client) => {
754
+ if (client.type === "failed") return null;
755
+ let timeoutSignal = null;
756
+ let mergedSignal = null;
757
+ try {
758
+ let capabilities = client.capabilities ?? null;
759
+ if (!capabilities) {
760
+ try {
761
+ capabilities = client.client.getServerCapabilities() ?? null;
762
+ } catch {
763
+ capabilities = null;
764
+ }
765
+ client.capabilities = capabilities;
766
+ }
767
+ if (!capabilities?.[requiredCapability]) {
768
+ return null;
769
+ }
770
+ timeoutSignal = timeoutMs ? createTimeoutSignal(timeoutMs) : null;
771
+ mergedSignal = mergeAbortSignals([timeoutSignal?.signal]);
772
+ const options = mergedSignal?.signal ? { signal: mergedSignal.signal } : void 0;
773
+ return {
774
+ client,
775
+ result: await client.client.request(
776
+ req,
777
+ resultSchema,
778
+ options
779
+ )
780
+ };
781
+ } catch (error) {
782
+ logMCPError(
783
+ client.name,
784
+ `Failed to request '${req.method}': ${error instanceof Error ? error.message : String(error)}`
785
+ );
786
+ return null;
787
+ } finally {
788
+ mergedSignal?.cleanup();
789
+ timeoutSignal?.cleanup();
790
+ }
791
+ })
792
+ );
793
+ return results.filter(
794
+ (result) => result.status === "fulfilled"
795
+ ).map((result) => result.value).filter(
796
+ (result) => result !== null
797
+ );
798
+ }
799
+
800
+ // packages/core/src/mcp/client/tools.ts
801
+ function isTextBlock(value) {
802
+ return isRecord(value) && value.type === "text" && typeof value.text === "string";
803
+ }
804
+ function isImageBlock(value) {
805
+ return isRecord(value) && value.type === "image";
806
+ }
807
+ function renderToolUseMessage(input) {
808
+ if (!isRecord(input)) return String(input ?? "");
809
+ return Object.entries(input).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(", ");
810
+ }
811
+ function renderToolResultMessage(output) {
812
+ if (Array.isArray(output)) {
813
+ return output.map((item) => {
814
+ if (!item || typeof item !== "object") return String(item ?? "");
815
+ if (isImageBlock(item)) return "[Image]";
816
+ if (isTextBlock(item)) return item.text;
817
+ return JSON.stringify(item);
818
+ }).join("\n");
819
+ }
820
+ if (!output) return "(No content)";
821
+ return typeof output === "string" ? output : JSON.stringify(output);
822
+ }
823
+ function renderResultForAssistant(content) {
824
+ if (typeof content === "string") return content;
825
+ if (Array.isArray(content)) return content;
826
+ if (!content) return "";
827
+ try {
828
+ return JSON.stringify(content);
829
+ } catch {
830
+ return String(content);
831
+ }
832
+ }
833
+ var getMCPTools = memoize2(async () => {
834
+ const toolsList = await requestAll({ method: "tools/list" }, ListToolsResultSchema, "tools");
835
+ const inputSchema = z.object({}).passthrough();
836
+ return toolsList.flatMap(({ client, result: { tools } }) => {
837
+ const serverPart = sanitizeMcpIdentifierPart(client.name);
838
+ return tools.map((tool) => {
839
+ const toolPart = sanitizeMcpIdentifierPart(tool.name);
840
+ const name = `mcp__${serverPart}__${toolPart}`;
841
+ if (name.startsWith("mcp__ide__") && !IDE_MCP_TOOL_ALLOWLIST.has(name)) {
842
+ return null;
843
+ }
844
+ return {
845
+ name,
846
+ cachedDescription: tool.description ?? "",
847
+ async isEnabled() {
848
+ return true;
849
+ },
850
+ isConcurrencySafe() {
851
+ return tool.annotations?.readOnlyHint ?? false;
852
+ },
853
+ isReadOnly() {
854
+ return tool.annotations?.readOnlyHint ?? false;
855
+ },
856
+ async description() {
857
+ return tool.description ?? "";
858
+ },
859
+ async prompt() {
860
+ return tool.description ?? "";
861
+ },
862
+ inputSchema,
863
+ inputJSONSchema: tool.inputSchema,
864
+ needsPermissions() {
865
+ return true;
866
+ },
867
+ async validateInput() {
868
+ return { result: true };
869
+ },
870
+ renderToolUseMessage,
871
+ renderToolUseRejectedMessage() {
872
+ return null;
873
+ },
874
+ renderToolResultMessage,
875
+ renderResultForAssistant,
876
+ async *call(args, context) {
877
+ const data = await callMcpTool({
878
+ client,
879
+ tool: tool.name,
880
+ args,
881
+ toolUseId: context.toolUseId,
882
+ signal: context.abortController.signal
883
+ });
884
+ yield {
885
+ type: "result",
886
+ data,
887
+ resultForAssistant: data
888
+ };
889
+ },
890
+ userFacingName() {
891
+ const title = tool.annotations?.title || tool.name;
892
+ return `${client.name} - ${title} (MCP)`;
893
+ }
894
+ };
895
+ }).filter((tool) => tool !== null);
896
+ });
897
+ });
898
+ async function callMcpTool({
899
+ client: { client, name },
900
+ tool,
901
+ args,
902
+ toolUseId,
903
+ signal
904
+ }) {
905
+ const timeoutMs = getMcpToolTimeoutMs();
906
+ const timeoutSignal = timeoutMs ? createTimeoutSignal(timeoutMs) : null;
907
+ const merged = mergeAbortSignals([signal, timeoutSignal?.signal]);
908
+ const meta = toolUseId && toolUseId.trim() ? { "claudecode/toolUseId": toolUseId } : void 0;
909
+ try {
910
+ const options = merged?.signal ? { signal: merged.signal } : void 0;
911
+ const rawResult = await client.callTool(
912
+ {
913
+ name: tool,
914
+ arguments: args,
915
+ ...meta ? { _meta: meta } : {}
916
+ },
917
+ CallToolResultSchema,
918
+ options
919
+ );
920
+ const result = CallToolResultSchema.parse(rawResult);
921
+ if (result.isError) {
922
+ const contentText = result.content.find((item) => item.type === "text");
923
+ const extraError = isRecord(rawResult) && typeof rawResult.error === "string" ? rawResult.error : isRecord(result) && typeof result.error === "string" ? result.error : "";
924
+ const message = contentText?.text?.trim() || extraError || `Error calling tool ${tool}`;
925
+ logMCPError(name, `Error calling tool ${tool}: ${message}`);
926
+ throw new Error(message);
927
+ }
928
+ const toolResult = isRecord(rawResult) && rawResult.toolResult !== void 0 ? rawResult.toolResult : isRecord(result) && result.toolResult !== void 0 ? result.toolResult : void 0;
929
+ if (toolResult !== void 0) return String(toolResult);
930
+ if (result.structuredContent !== void 0) {
931
+ return JSON.stringify(result.structuredContent);
932
+ }
933
+ const blocks = [];
934
+ for (const item of result.content) {
935
+ switch (item.type) {
936
+ case "text":
937
+ blocks.push({ type: "text", text: item.text });
938
+ break;
939
+ case "image":
940
+ blocks.push({
941
+ type: "image",
942
+ source: {
943
+ type: "base64",
944
+ data: item.data,
945
+ media_type: item.mimeType
946
+ }
947
+ });
948
+ break;
949
+ default: {
950
+ let text = "";
951
+ try {
952
+ text = JSON.stringify(item);
953
+ } catch {
954
+ text = String(item);
955
+ }
956
+ blocks.push({ type: "text", text });
957
+ break;
958
+ }
959
+ }
960
+ }
961
+ return blocks.length > 0 ? blocks : "(No content)";
962
+ } finally {
963
+ merged?.cleanup();
964
+ timeoutSignal?.cleanup();
965
+ }
966
+ }
967
+
968
+ // packages/core/src/mcp/client/commands.ts
969
+ import { memoize as memoize3, zipObject } from "lodash-es";
970
+ import { ListPromptsResultSchema } from "@modelcontextprotocol/sdk/types.js";
971
+ var getMCPCommands = memoize3(async () => {
972
+ const results = await requestAll({ method: "prompts/list" }, ListPromptsResultSchema, "prompts");
973
+ return results.flatMap(
974
+ ({ client, result }) => result.prompts?.map((prompt) => {
975
+ const serverPart = sanitizeMcpIdentifierPart(client.name);
976
+ const argNames = (prompt.arguments ?? []).map((arg) => arg.name);
977
+ return {
978
+ type: "prompt",
979
+ name: `mcp__${serverPart}__${prompt.name}`,
980
+ description: prompt.description ?? "",
981
+ isEnabled: true,
982
+ isHidden: false,
983
+ progressMessage: "running",
984
+ userFacingName() {
985
+ const title = prompt.title?.trim() || prompt.name;
986
+ return `${client.name}:${title} (MCP)`;
987
+ },
988
+ argNames,
989
+ async getPromptForCommand(args) {
990
+ const argsArray = args.split(" ");
991
+ return await runCommand(
992
+ { name: prompt.name, client },
993
+ zipObject(argNames, argsArray)
994
+ );
995
+ }
996
+ };
997
+ })
998
+ );
999
+ });
1000
+ async function runCommand({ name, client }, args) {
1001
+ try {
1002
+ const result = await client.client.getPrompt({ name, arguments: args });
1003
+ return result.messages.map((message) => {
1004
+ const content = message.content;
1005
+ switch (content.type) {
1006
+ case "text":
1007
+ return {
1008
+ role: message.role,
1009
+ content: [{ type: "text", text: content.text }]
1010
+ };
1011
+ case "image":
1012
+ return {
1013
+ role: message.role,
1014
+ content: [
1015
+ {
1016
+ type: "image",
1017
+ source: {
1018
+ type: "base64",
1019
+ data: content.data,
1020
+ media_type: content.mimeType
1021
+ }
1022
+ }
1023
+ ]
1024
+ };
1025
+ default:
1026
+ return {
1027
+ role: message.role,
1028
+ content: [
1029
+ {
1030
+ type: "text",
1031
+ text: `Unsupported MCP content type ${content.type}`
1032
+ }
1033
+ ]
1034
+ };
1035
+ }
1036
+ });
1037
+ } catch (error) {
1038
+ logMCPError(
1039
+ client.name,
1040
+ `Error running command '${name}': ${error instanceof Error ? error.message : String(error)}`
1041
+ );
1042
+ throw error;
1043
+ }
1044
+ }
1045
+
1046
+ export {
1047
+ safeParseJSON,
1048
+ parseEnvVars,
1049
+ ensureConfigScope,
1050
+ listPluginMCPServers,
1051
+ getMcprcServerStatus,
1052
+ addMcpServer,
1053
+ removeMcpServer,
1054
+ listMCPServers,
1055
+ getMcpServer,
1056
+ parseMcpServersFromCliConfigEntries,
1057
+ getClients,
1058
+ getClientsForCliMcpConfig,
1059
+ getMCPTools,
1060
+ getMCPCommands,
1061
+ runCommand
1062
+ };