@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
@@ -1,1357 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { createRequire as __kodeCreateRequire } from "node:module";
3
- const require = __kodeCreateRequire(import.meta.url);
4
- import {
5
- ensurePackagedRuntimeEnv
6
- } from "./chunk-WWUWDNWW.js";
7
- import {
8
- getTools
9
- } from "./chunk-6DRDLOLP.js";
10
- import {
11
- getCommands,
12
- getSystemPrompt,
13
- grantReadPermissionForOriginalDir,
14
- hasPermissionsToUseTool,
15
- query
16
- } from "./chunk-HSPVVDIW.js";
17
- import "./chunk-NQLEUHMS.js";
18
- import {
19
- getClients
20
- } from "./chunk-7CQVZNQV.js";
21
- import "./chunk-4GAIJGRH.js";
22
- import "./chunk-2PMO2FS2.js";
23
- import "./chunk-G6I7XROM.js";
24
- import "./chunk-3TXNP6HH.js";
25
- import "./chunk-KAA5BGMQ.js";
26
- import "./chunk-3RUXVV4S.js";
27
- import "./chunk-K2MI4TPB.js";
28
- import "./chunk-NPFOMITO.js";
29
- import "./chunk-54DNHKOD.js";
30
- import "./chunk-ZQU3TXLC.js";
31
- import "./chunk-67PY5IX6.js";
32
- import "./chunk-OWTG2W3A.js";
33
- import "./chunk-SRZZFAS7.js";
34
- import {
35
- loadToolPermissionContextFromDisk,
36
- persistToolPermissionUpdateToDisk
37
- } from "./chunk-EH34V7CY.js";
38
- import "./chunk-VBXVYQYY.js";
39
- import {
40
- applyToolPermissionContextUpdates
41
- } from "./chunk-S6HRABTA.js";
42
- import "./chunk-IE2CG2TV.js";
43
- import "./chunk-E6YNABER.js";
44
- import "./chunk-OZNRLY3E.js";
45
- import "./chunk-UKHTVRJM.js";
46
- import "./chunk-S3J2TLV6.js";
47
- import {
48
- createAssistantMessage,
49
- createUserMessage
50
- } from "./chunk-2KWKUXLT.js";
51
- import "./chunk-Z33T5YN5.js";
52
- import {
53
- getContext
54
- } from "./chunk-OIFQB3S4.js";
55
- import "./chunk-SDGKPKDK.js";
56
- import {
57
- enableConfigs
58
- } from "./chunk-AIMIPK4B.js";
59
- import "./chunk-UYXEDKOZ.js";
60
- import {
61
- initDebugLogger
62
- } from "./chunk-QYFKRZQC.js";
63
- import {
64
- PRODUCT_COMMAND,
65
- getKodeBaseDir,
66
- initSentry,
67
- logError,
68
- setCwd,
69
- setOriginalCwd
70
- } from "./chunk-MN77D2F7.js";
71
- import {
72
- MACRO
73
- } from "./chunk-FH5CHM6L.js";
74
- import "./chunk-EZXMVTDU.js";
75
- import "./chunk-JC6NCUG5.js";
76
-
77
- // src/acp/jsonrpc.ts
78
- import { format } from "node:util";
79
- var JsonRpcError = class extends Error {
80
- code;
81
- data;
82
- constructor(code, message, data) {
83
- super(message);
84
- this.code = code;
85
- this.data = data;
86
- }
87
- };
88
- var JSONRPC_VERSION = "2.0";
89
- function isObject(value) {
90
- return typeof value === "object" && value !== null && !Array.isArray(value);
91
- }
92
- function safeStringify(value) {
93
- try {
94
- return JSON.stringify(value);
95
- } catch {
96
- return format(value);
97
- }
98
- }
99
- function makeErrorResponse(id, code, message, data) {
100
- return {
101
- jsonrpc: JSONRPC_VERSION,
102
- id,
103
- error: data === void 0 ? { code, message } : { code, message, data }
104
- };
105
- }
106
- function normalizeId(id) {
107
- return typeof id === "string" || typeof id === "number" ? id : null;
108
- }
109
- var JsonRpcPeer = class {
110
- handlers = /* @__PURE__ */ new Map();
111
- pending = /* @__PURE__ */ new Map();
112
- nextId = 1;
113
- sendLine = null;
114
- setSend(send) {
115
- this.sendLine = send;
116
- }
117
- registerMethod(method, handler) {
118
- this.handlers.set(method, handler);
119
- }
120
- async handleIncoming(payload) {
121
- if (Array.isArray(payload)) {
122
- const responses = [];
123
- for (const item of payload) {
124
- const r = await this.handleIncomingOne(item);
125
- if (r) responses.push(r);
126
- }
127
- if (responses.length > 0) {
128
- this.sendRaw(responses);
129
- }
130
- return;
131
- }
132
- const response = await this.handleIncomingOne(payload);
133
- if (response) this.sendRaw(response);
134
- }
135
- async handleIncomingOne(payload) {
136
- if (!isObject(payload)) {
137
- return makeErrorResponse(null, -32600, "Invalid Request");
138
- }
139
- const jsonrpc = payload.jsonrpc;
140
- if (jsonrpc !== JSONRPC_VERSION) {
141
- return makeErrorResponse(normalizeId(payload.id), -32600, "Invalid Request");
142
- }
143
- const hasMethod = typeof payload.method === "string" && payload.method.length > 0;
144
- const hasId = typeof payload.id === "string" || typeof payload.id === "number";
145
- if (!hasMethod && hasId && ("result" in payload || "error" in payload)) {
146
- this.handleResponse(payload);
147
- return null;
148
- }
149
- if (!hasMethod) {
150
- return makeErrorResponse(normalizeId(payload.id), -32600, "Invalid Request");
151
- }
152
- const method = String(payload.method);
153
- const params = "params" in payload ? payload.params : void 0;
154
- const id = hasId ? payload.id : null;
155
- const handler = this.handlers.get(method);
156
- if (!handler) {
157
- if (id === null) return null;
158
- return makeErrorResponse(id, -32601, `Method not found: ${method}`);
159
- }
160
- if (id === null) {
161
- try {
162
- await handler(params);
163
- } catch {
164
- }
165
- return null;
166
- }
167
- try {
168
- const result = await handler(params);
169
- return { jsonrpc: JSONRPC_VERSION, id, result: result ?? null };
170
- } catch (err) {
171
- if (err instanceof JsonRpcError) {
172
- return makeErrorResponse(id, err.code, err.message, err.data);
173
- }
174
- const message = err instanceof Error ? err.message : safeStringify(err);
175
- return makeErrorResponse(id, -32603, message);
176
- }
177
- }
178
- handleResponse(msg) {
179
- const id = normalizeId(msg.id);
180
- if (id === null) return;
181
- const pending = this.pending.get(id);
182
- if (!pending) return;
183
- this.pending.delete(id);
184
- if (pending.timeoutId) clearTimeout(pending.timeoutId);
185
- if (msg && typeof msg === "object" && "error" in msg && msg.error) {
186
- const e = msg.error;
187
- const code = typeof e.code === "number" ? e.code : -32603;
188
- const message = typeof e.message === "string" ? e.message : "Unknown error";
189
- pending.reject(new JsonRpcError(code, message, e.data));
190
- return;
191
- }
192
- pending.resolve(msg.result);
193
- }
194
- sendNotification(method, params) {
195
- this.sendRaw({ jsonrpc: JSONRPC_VERSION, method, ...params !== void 0 ? { params } : {} });
196
- }
197
- sendRequest(args) {
198
- const id = this.nextId++;
199
- const timeoutMs = args.timeoutMs;
200
- const p = new Promise((resolve2, reject) => {
201
- const entry = { resolve: resolve2, reject, abort: args.signal };
202
- if (timeoutMs && Number.isFinite(timeoutMs) && timeoutMs > 0) {
203
- entry.timeoutId = setTimeout(() => {
204
- this.pending.delete(id);
205
- reject(new JsonRpcError(-32e3, `Request timed out: ${args.method}`));
206
- }, timeoutMs);
207
- }
208
- if (args.signal) {
209
- const onAbort = () => {
210
- this.pending.delete(id);
211
- if (entry.timeoutId) clearTimeout(entry.timeoutId);
212
- reject(new JsonRpcError(-32e3, `Request aborted: ${args.method}`));
213
- };
214
- if (args.signal.aborted) {
215
- onAbort();
216
- return;
217
- }
218
- args.signal.addEventListener("abort", onAbort, { once: true });
219
- }
220
- this.pending.set(id, entry);
221
- });
222
- this.sendRaw({
223
- jsonrpc: JSONRPC_VERSION,
224
- id,
225
- method: args.method,
226
- ...args.params !== void 0 ? { params: args.params } : {}
227
- });
228
- return p;
229
- }
230
- sendRaw(obj) {
231
- const send = this.sendLine;
232
- if (!send) {
233
- throw new Error("JsonRpcPeer send() not configured");
234
- }
235
- const line = JSON.stringify(obj);
236
- send(line);
237
- }
238
- };
239
-
240
- // src/acp/stdioTransport.ts
241
- import readline from "node:readline";
242
- var StdioTransport = class {
243
- constructor(peer2, opts) {
244
- this.peer = peer2;
245
- this.opts = opts;
246
- }
247
- rl = null;
248
- pending = /* @__PURE__ */ new Set();
249
- start() {
250
- if (this.rl) return;
251
- this.peer.setSend(this.opts.writeLine);
252
- this.rl = readline.createInterface({
253
- input: process.stdin,
254
- crlfDelay: Infinity
255
- });
256
- this.rl.on("line", (line) => {
257
- const trimmed = line.trim();
258
- if (!trimmed) return;
259
- try {
260
- const payload = JSON.parse(trimmed);
261
- const p = this.peer.handleIncoming(payload).catch(() => {
262
- });
263
- this.pending.add(p);
264
- void p.finally(() => this.pending.delete(p));
265
- } catch (err) {
266
- this.opts.writeLine(
267
- JSON.stringify({
268
- jsonrpc: "2.0",
269
- id: null,
270
- error: { code: -32700, message: "Parse error" }
271
- })
272
- );
273
- }
274
- });
275
- this.rl.on("close", () => {
276
- void (async () => {
277
- const pending = Array.from(this.pending);
278
- if (pending.length > 0) {
279
- await Promise.allSettled(pending);
280
- }
281
- process.exit(0);
282
- })();
283
- });
284
- }
285
- stop() {
286
- this.rl?.close();
287
- this.rl = null;
288
- }
289
- };
290
-
291
- // src/acp/stdoutGuard.ts
292
- import { format as format2 } from "node:util";
293
- function writeTo(write, chunk, encoding, cb) {
294
- if (typeof encoding === "function") {
295
- return write(chunk, void 0, encoding);
296
- }
297
- return write(chunk, encoding, cb);
298
- }
299
- function installStdoutGuard() {
300
- const originalStdoutWrite = process.stdout.write.bind(process.stdout);
301
- const originalStderrWrite = process.stderr.write.bind(process.stderr);
302
- const originalConsoleLog = console.log.bind(console);
303
- const originalConsoleInfo = console.info.bind(console);
304
- const originalConsoleDebug = console.debug.bind(console);
305
- const originalConsoleWarn = console.warn.bind(console);
306
- const originalConsoleError = console.error.bind(console);
307
- const writeAcpLine2 = (line) => {
308
- writeTo(originalStdoutWrite, `${line}
309
- `);
310
- };
311
- const writeLogToStderr = (...args) => {
312
- writeTo(originalStderrWrite, `${format2(...args)}
313
- `);
314
- };
315
- console.log = writeLogToStderr;
316
- console.info = writeLogToStderr;
317
- console.debug = writeLogToStderr;
318
- console.warn = writeLogToStderr;
319
- console.error = writeLogToStderr;
320
- process.stdout.write = ((chunk, encoding, cb) => {
321
- return writeTo(originalStderrWrite, chunk, encoding, cb);
322
- });
323
- const restore = () => {
324
- process.stdout.write = originalStdoutWrite;
325
- console.log = originalConsoleLog;
326
- console.info = originalConsoleInfo;
327
- console.debug = originalConsoleDebug;
328
- console.warn = originalConsoleWarn;
329
- console.error = originalConsoleError;
330
- };
331
- return { writeAcpLine: writeAcpLine2, restore, originalStdoutWrite };
332
- }
333
-
334
- // src/acp/kodeAcpAgent.ts
335
- import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
336
- import { isAbsolute, join, resolve } from "node:path";
337
- import { nanoid } from "nanoid";
338
-
339
- // src/acp/protocol.ts
340
- var ACP_PROTOCOL_VERSION = 1;
341
-
342
- // src/acp/kodeAcpAgent.ts
343
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
344
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
345
- import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
346
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
347
- function asJsonObject(value) {
348
- if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
349
- try {
350
- JSON.stringify(value);
351
- return value;
352
- } catch {
353
- return void 0;
354
- }
355
- }
356
- function toolKindForName(toolName) {
357
- switch (toolName) {
358
- case "Read":
359
- return "read";
360
- case "Write":
361
- case "Edit":
362
- case "MultiEdit":
363
- case "NotebookEdit":
364
- return "edit";
365
- case "Grep":
366
- case "Glob":
367
- return "search";
368
- case "Bash":
369
- case "TaskOutput":
370
- case "KillShell":
371
- return "execute";
372
- case "SwitchModel":
373
- return "switch_mode";
374
- default:
375
- return "other";
376
- }
377
- }
378
- function titleForToolCall(toolName, input) {
379
- if (toolName === "Read" && typeof input.file_path === "string") {
380
- return `Read ${input.file_path}`;
381
- }
382
- if ((toolName === "Write" || toolName === "Edit" || toolName === "MultiEdit") && typeof input.file_path === "string") {
383
- return `${toolName} ${input.file_path}`;
384
- }
385
- if (toolName === "Bash" && typeof input.command === "string") {
386
- const cmd = input.command.trim().replace(/\s+/g, " ");
387
- const clipped = cmd.length > 120 ? `${cmd.slice(0, 117)}...` : cmd;
388
- return `Run ${clipped}`;
389
- }
390
- return toolName;
391
- }
392
- function blocksToText(blocks) {
393
- const parts = [];
394
- for (const block of blocks) {
395
- if (!block || typeof block !== "object") continue;
396
- switch (block.type) {
397
- case "text": {
398
- const text = typeof block.text === "string" ? block.text : "";
399
- if (text) parts.push(text);
400
- break;
401
- }
402
- case "resource": {
403
- const resource = block.resource || {};
404
- const uri = typeof resource.uri === "string" ? resource.uri : "";
405
- const mimeType = typeof resource.mimeType === "string" && resource.mimeType ? resource.mimeType : "text/plain";
406
- if (typeof resource.text === "string") {
407
- parts.push(
408
- [
409
- "",
410
- `@resource ${uri} (${mimeType})`,
411
- "```",
412
- resource.text,
413
- "```"
414
- ].join("\n")
415
- );
416
- } else if (typeof resource.blob === "string") {
417
- parts.push(
418
- [
419
- "",
420
- `@resource ${uri} (${mimeType}) [base64]`,
421
- resource.blob
422
- ].join("\n")
423
- );
424
- } else if (uri) {
425
- parts.push(`@resource ${uri} (${mimeType})`);
426
- }
427
- break;
428
- }
429
- case "resource_link": {
430
- const uri = typeof block.uri === "string" ? block.uri : "";
431
- const name = typeof block.name === "string" ? block.name : "";
432
- const title = typeof block.title === "string" ? block.title : "";
433
- const description = typeof block.description === "string" ? block.description : "";
434
- parts.push(
435
- [
436
- "",
437
- `@resource_link ${name || uri}`,
438
- ...title ? [title] : [],
439
- ...description ? [description] : [],
440
- ...uri ? [uri] : []
441
- ].join("\n")
442
- );
443
- break;
444
- }
445
- case "image":
446
- case "audio": {
447
- break;
448
- }
449
- default:
450
- break;
451
- }
452
- }
453
- return parts.join("\n").trim();
454
- }
455
- function extractAssistantText(msg) {
456
- const blocks = Array.isArray(msg?.message?.content) ? msg.message.content : [];
457
- const texts = [];
458
- for (const b of blocks) {
459
- if (!b || typeof b !== "object") continue;
460
- if (b.type === "text" && typeof b.text === "string") texts.push(b.text);
461
- if (b.type === "thinking" && typeof b.thinking === "string") texts.push(b.thinking);
462
- }
463
- return texts.join("").trim();
464
- }
465
- function extractToolResults(msg) {
466
- const content = msg?.message?.content;
467
- const blocks = Array.isArray(content) ? content : [];
468
- const out = [];
469
- for (const b of blocks) {
470
- if (!b || typeof b !== "object") continue;
471
- if (b.type !== "tool_result") continue;
472
- const toolUseId = typeof b.tool_use_id === "string" ? b.tool_use_id : "";
473
- const isError = Boolean(b.is_error);
474
- const raw = b.content;
475
- const text = typeof raw === "string" ? raw : Array.isArray(raw) ? raw.filter((x) => x && typeof x === "object" && x.type === "text").map((x) => String(x.text ?? "")).join("") : "";
476
- if (toolUseId) out.push({ toolUseId, isError, content: text });
477
- }
478
- return out;
479
- }
480
- var ACP_SESSION_STORE_VERSION = 1;
481
- var MAX_DIFF_FILE_BYTES = 512e3;
482
- var MAX_DIFF_TEXT_CHARS = 4e5;
483
- function getProjectDirSlug(cwd) {
484
- return cwd.replace(/[^a-zA-Z0-9]/g, "-");
485
- }
486
- function sanitizeSessionId(sessionId) {
487
- return sessionId.replace(/[^a-zA-Z0-9_-]/g, "_");
488
- }
489
- function getAcpSessionDir(cwd) {
490
- return join(getKodeBaseDir(), getProjectDirSlug(cwd), "acp-sessions");
491
- }
492
- function getAcpSessionFilePath(cwd, sessionId) {
493
- return join(getAcpSessionDir(cwd), `${sanitizeSessionId(sessionId)}.json`);
494
- }
495
- function readTextFileForDiff(filePath) {
496
- try {
497
- const stats = statSync(filePath);
498
- if (!stats.isFile()) return null;
499
- if (stats.size > MAX_DIFF_FILE_BYTES) return null;
500
- return readFileSync(filePath, "utf8");
501
- } catch {
502
- return null;
503
- }
504
- }
505
- function truncateDiffText(text) {
506
- if (text.length <= MAX_DIFF_TEXT_CHARS) return text;
507
- return `${text.slice(0, MAX_DIFF_TEXT_CHARS)}
508
-
509
- [truncated ${text.length - MAX_DIFF_TEXT_CHARS} chars]`;
510
- }
511
- function persistAcpSessionToDisk(session) {
512
- try {
513
- const dir = getAcpSessionDir(session.cwd);
514
- mkdirSync(dir, { recursive: true });
515
- const payload = {
516
- version: ACP_SESSION_STORE_VERSION,
517
- sessionId: session.sessionId,
518
- cwd: session.cwd,
519
- mcpServers: session.mcpServers,
520
- messages: session.messages,
521
- toolPermissionContext: session.toolPermissionContext,
522
- readFileTimestamps: session.readFileTimestamps,
523
- responseState: session.responseState,
524
- currentModeId: session.currentModeId
525
- };
526
- const path = getAcpSessionFilePath(session.cwd, session.sessionId);
527
- writeFileSync(path, JSON.stringify(payload, null, 2), "utf8");
528
- } catch (e) {
529
- logError(e);
530
- }
531
- }
532
- function loadAcpSessionFromDisk(cwd, sessionId) {
533
- try {
534
- const path = getAcpSessionFilePath(cwd, sessionId);
535
- if (!existsSync(path)) return null;
536
- const raw = readFileSync(path, "utf8");
537
- const parsed = JSON.parse(raw);
538
- if (!parsed || typeof parsed !== "object") return null;
539
- if (parsed.sessionId !== sessionId) return null;
540
- if (typeof parsed.cwd !== "string" || parsed.cwd !== cwd) return null;
541
- if (!Array.isArray(parsed.messages)) return null;
542
- return parsed;
543
- } catch {
544
- return null;
545
- }
546
- }
547
- async function connectAcpMcpServers(mcpServers) {
548
- if (!Array.isArray(mcpServers) || mcpServers.length === 0) return [];
549
- const rawTimeout = process.env.MCP_CONNECTION_TIMEOUT_MS;
550
- const parsedTimeout = rawTimeout ? Number.parseInt(rawTimeout, 10) : NaN;
551
- const timeoutMs = Number.isFinite(parsedTimeout) ? parsedTimeout : 3e4;
552
- const results = [];
553
- const connectWithTimeout = async (client, transport2, name) => {
554
- const connectPromise = client.connect(transport2);
555
- if (timeoutMs > 0) {
556
- const timeoutPromise = new Promise((_, reject) => {
557
- const timeoutId = setTimeout(() => {
558
- reject(new Error(`Connection to MCP server "${name}" timed out after ${timeoutMs}ms`));
559
- }, timeoutMs);
560
- connectPromise.then(
561
- () => clearTimeout(timeoutId),
562
- () => clearTimeout(timeoutId)
563
- );
564
- });
565
- await Promise.race([connectPromise, timeoutPromise]);
566
- } else {
567
- await connectPromise;
568
- }
569
- };
570
- for (const server of mcpServers) {
571
- const serverType = typeof server?.type === "string" ? String(server.type) : "stdio";
572
- const name = typeof server?.name === "string" ? String(server.name) : "";
573
- if (!name) {
574
- results.push({ name: "<invalid>", type: "failed" });
575
- continue;
576
- }
577
- const candidates = [];
578
- if (serverType === "http" || serverType === "sse") {
579
- const url = typeof server?.url === "string" ? String(server.url) : "";
580
- if (!url) {
581
- results.push({ name, type: "failed" });
582
- continue;
583
- }
584
- let parsedUrl;
585
- try {
586
- parsedUrl = new URL(url);
587
- } catch (e) {
588
- logError(e);
589
- results.push({ name, type: "failed" });
590
- continue;
591
- }
592
- const headerList = Array.isArray(server?.headers) ? server.headers : [];
593
- const headers = {};
594
- for (const h of headerList) {
595
- if (!h || typeof h !== "object") continue;
596
- const k = typeof h.name === "string" ? String(h.name) : "";
597
- const val = typeof h.value === "string" ? String(h.value) : "";
598
- if (k) headers[k] = val;
599
- }
600
- const requestInit = Object.keys(headers).length > 0 ? { requestInit: { headers } } : {};
601
- if (serverType === "http") {
602
- candidates.push(
603
- { kind: "http", transport: new StreamableHTTPClientTransport(parsedUrl, requestInit) },
604
- { kind: "sse", transport: new SSEClientTransport(parsedUrl, requestInit) }
605
- );
606
- } else {
607
- candidates.push(
608
- { kind: "sse", transport: new SSEClientTransport(parsedUrl, requestInit) },
609
- { kind: "http", transport: new StreamableHTTPClientTransport(parsedUrl, requestInit) }
610
- );
611
- }
612
- } else {
613
- const command = typeof server?.command === "string" ? String(server.command) : "";
614
- const args = Array.isArray(server?.args) ? server.args.map((a) => String(a)) : [];
615
- const envList = Array.isArray(server?.env) ? server.env : [];
616
- if (!command) {
617
- results.push({ name, type: "failed" });
618
- continue;
619
- }
620
- const envFromParams = {};
621
- for (const v of envList) {
622
- if (!v || typeof v !== "object") continue;
623
- const k = typeof v.name === "string" ? String(v.name) : "";
624
- const val = typeof v.value === "string" ? String(v.value) : "";
625
- if (k) envFromParams[k] = val;
626
- }
627
- candidates.push({
628
- kind: "stdio",
629
- transport: new StdioClientTransport({
630
- command,
631
- args,
632
- env: { ...process.env, ...envFromParams },
633
- stderr: "pipe"
634
- })
635
- });
636
- }
637
- let lastError;
638
- for (const candidate of candidates) {
639
- const client = new Client(
640
- { name: PRODUCT_COMMAND, version: MACRO.VERSION || "0.0.0" },
641
- { capabilities: {} }
642
- );
643
- try {
644
- await connectWithTimeout(client, candidate.transport, name);
645
- let capabilities = null;
646
- try {
647
- capabilities = client.getServerCapabilities();
648
- } catch {
649
- capabilities = null;
650
- }
651
- results.push({ name, client, capabilities, type: "connected" });
652
- lastError = null;
653
- break;
654
- } catch (e) {
655
- lastError = e;
656
- try {
657
- await client.close();
658
- } catch {
659
- }
660
- }
661
- }
662
- if (lastError) {
663
- logError(lastError);
664
- results.push({ name, type: "failed" });
665
- }
666
- }
667
- return results;
668
- }
669
- function mergeMcpClients(base, extra) {
670
- const map = /* @__PURE__ */ new Map();
671
- for (const c of base) map.set(c.name, c);
672
- for (const c of extra) map.set(c.name, c);
673
- return Array.from(map.values());
674
- }
675
- var KodeAcpAgent = class {
676
- constructor(peer2) {
677
- this.peer = peer2;
678
- this.registerMethods();
679
- }
680
- clientCapabilities = {};
681
- sessions = /* @__PURE__ */ new Map();
682
- registerMethods() {
683
- this.peer.registerMethod("initialize", this.handleInitialize.bind(this));
684
- this.peer.registerMethod("authenticate", this.handleAuthenticate.bind(this));
685
- this.peer.registerMethod("session/new", this.handleSessionNew.bind(this));
686
- this.peer.registerMethod("session/load", this.handleSessionLoad.bind(this));
687
- this.peer.registerMethod("session/prompt", this.handleSessionPrompt.bind(this));
688
- this.peer.registerMethod("session/set_mode", this.handleSessionSetMode.bind(this));
689
- this.peer.registerMethod("session/cancel", this.handleSessionCancel.bind(this));
690
- }
691
- async handleInitialize(params) {
692
- const p = params ?? {};
693
- const protocolVersion = typeof p.protocolVersion === "number" ? p.protocolVersion : ACP_PROTOCOL_VERSION;
694
- this.clientCapabilities = p.clientCapabilities && typeof p.clientCapabilities === "object" ? p.clientCapabilities : {};
695
- return {
696
- protocolVersion: ACP_PROTOCOL_VERSION,
697
- agentCapabilities: {
698
- loadSession: true,
699
- promptCapabilities: {
700
- image: false,
701
- audio: false,
702
- embeddedContext: true,
703
- embeddedContent: true
704
- },
705
- mcpCapabilities: {
706
- http: true,
707
- sse: true
708
- }
709
- },
710
- agentInfo: {
711
- name: "kode",
712
- title: "Kode",
713
- version: MACRO.VERSION || "0.0.0"
714
- },
715
- authMethods: []
716
- };
717
- }
718
- async handleAuthenticate(_params) {
719
- return {};
720
- }
721
- async handleSessionNew(params) {
722
- const p = params ?? {};
723
- const cwd = typeof p.cwd === "string" ? p.cwd : "";
724
- if (!cwd) {
725
- throw new JsonRpcError(-32602, "Missing required param: cwd");
726
- }
727
- if (!isAbsolute(cwd)) {
728
- throw new JsonRpcError(-32602, `cwd must be an absolute path: ${cwd}`);
729
- }
730
- setOriginalCwd(cwd);
731
- await setCwd(cwd);
732
- grantReadPermissionForOriginalDir();
733
- const mcpServers = Array.isArray(p.mcpServers) ? p.mcpServers : [];
734
- const [commands, tools, ctx, systemPrompt, configuredMcpClients] = await Promise.all([
735
- getCommands(),
736
- getTools(),
737
- getContext(),
738
- getSystemPrompt({ disableSlashCommands: false }),
739
- getClients().catch(() => [])
740
- ]);
741
- const acpMcpClients = await connectAcpMcpServers(mcpServers);
742
- const mcpClients = mergeMcpClients(configuredMcpClients, acpMcpClients);
743
- const toolPermissionContext = loadToolPermissionContextFromDisk({
744
- projectDir: cwd,
745
- includeKodeProjectConfig: true,
746
- isBypassPermissionsModeAvailable: true
747
- });
748
- const sessionId = `sess_${nanoid()}`;
749
- const session = {
750
- sessionId,
751
- cwd,
752
- mcpServers,
753
- mcpClients,
754
- commands,
755
- tools,
756
- systemPrompt,
757
- context: ctx,
758
- messages: [],
759
- toolPermissionContext,
760
- readFileTimestamps: {},
761
- responseState: {},
762
- currentModeId: toolPermissionContext.mode ?? "default",
763
- activeAbortController: null,
764
- toolCalls: /* @__PURE__ */ new Map()
765
- };
766
- this.sessions.set(sessionId, session);
767
- this.sendAvailableCommands(session);
768
- this.sendCurrentMode(session);
769
- persistAcpSessionToDisk(session);
770
- return {
771
- sessionId,
772
- modes: this.getModeState(session)
773
- };
774
- }
775
- async handleSessionLoad(params) {
776
- const p = params ?? {};
777
- const sessionId = typeof p.sessionId === "string" ? p.sessionId : "";
778
- const cwd = typeof p.cwd === "string" ? p.cwd : "";
779
- if (!sessionId) throw new JsonRpcError(-32602, "Missing required param: sessionId");
780
- if (!cwd) throw new JsonRpcError(-32602, "Missing required param: cwd");
781
- if (!isAbsolute(cwd)) {
782
- throw new JsonRpcError(-32602, `cwd must be an absolute path: ${cwd}`);
783
- }
784
- setOriginalCwd(cwd);
785
- await setCwd(cwd);
786
- grantReadPermissionForOriginalDir();
787
- const persisted = loadAcpSessionFromDisk(cwd, sessionId);
788
- if (!persisted) {
789
- throw new JsonRpcError(-32602, `Session not found: ${sessionId}`);
790
- }
791
- const mcpServers = Array.isArray(p.mcpServers) ? p.mcpServers : [];
792
- const [commands, tools, ctx, systemPrompt, configuredMcpClients] = await Promise.all([
793
- getCommands(),
794
- getTools(),
795
- getContext(),
796
- getSystemPrompt({ disableSlashCommands: false }),
797
- getClients().catch(() => [])
798
- ]);
799
- const acpMcpClients = await connectAcpMcpServers(mcpServers);
800
- const mcpClients = mergeMcpClients(configuredMcpClients, acpMcpClients);
801
- const toolPermissionContext = loadToolPermissionContextFromDisk({
802
- projectDir: cwd,
803
- includeKodeProjectConfig: true,
804
- isBypassPermissionsModeAvailable: true
805
- });
806
- const currentModeId = typeof persisted.currentModeId === "string" && persisted.currentModeId ? persisted.currentModeId : toolPermissionContext.mode ?? "default";
807
- toolPermissionContext.mode = currentModeId;
808
- const session = {
809
- sessionId,
810
- cwd,
811
- mcpServers,
812
- mcpClients,
813
- commands,
814
- tools,
815
- systemPrompt,
816
- context: ctx,
817
- messages: Array.isArray(persisted.messages) ? persisted.messages : [],
818
- toolPermissionContext,
819
- readFileTimestamps: persisted.readFileTimestamps && typeof persisted.readFileTimestamps === "object" ? persisted.readFileTimestamps : {},
820
- responseState: persisted.responseState && typeof persisted.responseState === "object" ? persisted.responseState : {},
821
- currentModeId,
822
- activeAbortController: null,
823
- toolCalls: /* @__PURE__ */ new Map()
824
- };
825
- this.sessions.set(sessionId, session);
826
- this.sendAvailableCommands(session);
827
- this.sendCurrentMode(session);
828
- this.replayConversation(session);
829
- return { modes: this.getModeState(session) };
830
- }
831
- async handleSessionSetMode(params) {
832
- const p = params ?? {};
833
- const sessionId = typeof p.sessionId === "string" ? p.sessionId : "";
834
- const modeId = typeof p.modeId === "string" ? p.modeId : "";
835
- const session = this.sessions.get(sessionId);
836
- if (!session) throw new JsonRpcError(-32602, `Session not found: ${sessionId}`);
837
- const allowed = new Set(this.getModeState(session).availableModes.map((m) => m.id));
838
- if (!allowed.has(modeId)) {
839
- throw new JsonRpcError(-32602, `Unknown modeId: ${modeId}`);
840
- }
841
- session.currentModeId = modeId;
842
- session.toolPermissionContext.mode = modeId;
843
- this.sendCurrentMode(session);
844
- persistAcpSessionToDisk(session);
845
- return {};
846
- }
847
- async handleSessionCancel(params) {
848
- const p = params ?? {};
849
- const sessionId = typeof p.sessionId === "string" ? p.sessionId : "";
850
- const session = this.sessions.get(sessionId);
851
- if (!session) return;
852
- session.activeAbortController?.abort();
853
- }
854
- async handleSessionPrompt(params) {
855
- const p = params ?? {};
856
- const sessionId = typeof p.sessionId === "string" ? p.sessionId : "";
857
- const blocks = Array.isArray(p.prompt) ? p.prompt : Array.isArray(p.content) ? p.content : [];
858
- const session = this.sessions.get(sessionId);
859
- if (!session) throw new JsonRpcError(-32602, `Session not found: ${sessionId}`);
860
- if (session.activeAbortController) {
861
- throw new JsonRpcError(-32e3, `Session already has an active prompt: ${sessionId}`);
862
- }
863
- setOriginalCwd(session.cwd);
864
- await setCwd(session.cwd);
865
- grantReadPermissionForOriginalDir();
866
- const promptText = blocksToText(blocks);
867
- const userMsg = createUserMessage(promptText);
868
- const baseMessages = [...session.messages, userMsg];
869
- session.messages.push(userMsg);
870
- if (process.env.KODE_ACP_ECHO === "1") {
871
- await this.handleKodeMessage(session, createAssistantMessage(promptText));
872
- persistAcpSessionToDisk(session);
873
- return { stopReason: "end_turn" };
874
- }
875
- const abortController = new AbortController();
876
- session.activeAbortController = abortController;
877
- const canUseTool = this.createAcpCanUseTool(session);
878
- const options = {
879
- commands: session.commands,
880
- tools: session.tools,
881
- verbose: false,
882
- safeMode: false,
883
- forkNumber: 0,
884
- messageLogName: session.sessionId,
885
- maxThinkingTokens: 0,
886
- persistSession: false,
887
- toolPermissionContext: session.toolPermissionContext,
888
- mcpClients: session.mcpClients,
889
- shouldAvoidPermissionPrompts: false
890
- };
891
- let stopReason = "end_turn";
892
- try {
893
- for await (const m of query(baseMessages, session.systemPrompt, session.context, canUseTool, {
894
- options,
895
- abortController,
896
- messageId: void 0,
897
- readFileTimestamps: session.readFileTimestamps,
898
- setToolJSX: () => {
899
- },
900
- agentId: "main",
901
- responseState: session.responseState
902
- })) {
903
- if (abortController.signal.aborted) {
904
- stopReason = "cancelled";
905
- }
906
- await this.handleKodeMessage(session, m);
907
- }
908
- if (abortController.signal.aborted) stopReason = "cancelled";
909
- } catch (err) {
910
- if (abortController.signal.aborted) {
911
- stopReason = "cancelled";
912
- } else {
913
- logError(err);
914
- const msg = err instanceof Error ? err.message : String(err);
915
- this.sendAgentMessage(session.sessionId, msg);
916
- stopReason = "end_turn";
917
- }
918
- } finally {
919
- session.activeAbortController = null;
920
- persistAcpSessionToDisk(session);
921
- }
922
- return { stopReason };
923
- }
924
- async handleKodeMessage(session, m) {
925
- if (!m || typeof m !== "object") return;
926
- if (m.type === "assistant") {
927
- session.messages.push(m);
928
- const blocks = Array.isArray(m.message?.content) ? m.message.content : [];
929
- for (const b of blocks) {
930
- if (!b || typeof b !== "object") continue;
931
- if (b.type === "text" && typeof b.text === "string") {
932
- this.sendAgentMessage(session.sessionId, b.text);
933
- } else if (b.type === "thinking" && typeof b.thinking === "string") {
934
- this.sendAgentThought(session.sessionId, b.thinking);
935
- } else if (b.type === "tool_use") {
936
- const toolUseId = typeof b.id === "string" ? b.id : "";
937
- const toolName = typeof b.name === "string" ? b.name : "";
938
- const input = b.input && typeof b.input === "object" && !Array.isArray(b.input) ? b.input : {};
939
- if (!toolUseId || !toolName) continue;
940
- const kind = toolKindForName(toolName);
941
- const title = titleForToolCall(toolName, input);
942
- session.toolCalls.set(toolUseId, {
943
- title,
944
- kind,
945
- status: "pending",
946
- rawInput: asJsonObject(input)
947
- });
948
- this.peer.sendNotification("session/update", {
949
- sessionId: session.sessionId,
950
- update: {
951
- sessionUpdate: "tool_call",
952
- toolCallId: toolUseId,
953
- title,
954
- kind,
955
- status: "pending",
956
- rawInput: asJsonObject(input)
957
- }
958
- });
959
- }
960
- }
961
- return;
962
- }
963
- if (m.type === "progress") {
964
- const toolCallId = m.toolUseID;
965
- const existing = session.toolCalls.get(toolCallId);
966
- const title = existing?.title ?? "Tool";
967
- const kind = existing?.kind ?? "other";
968
- if (!existing || existing.status === "pending") {
969
- session.toolCalls.set(toolCallId, {
970
- title,
971
- kind,
972
- status: "in_progress",
973
- rawInput: existing?.rawInput
974
- });
975
- this.sendToolCallUpdate(session.sessionId, {
976
- toolCallId,
977
- status: "in_progress"
978
- });
979
- }
980
- const text = extractAssistantText(m.content);
981
- if (text) {
982
- this.sendToolCallUpdate(session.sessionId, {
983
- toolCallId,
984
- content: [
985
- {
986
- type: "content",
987
- content: { type: "text", text }
988
- }
989
- ]
990
- });
991
- }
992
- return;
993
- }
994
- if (m.type === "user") {
995
- const toolResults = extractToolResults(m);
996
- if (toolResults.length === 0) {
997
- session.messages.push(m);
998
- return;
999
- }
1000
- for (const tr of toolResults) {
1001
- const existing = session.toolCalls.get(tr.toolUseId);
1002
- const title = existing?.title ?? "Tool";
1003
- const kind = existing?.kind ?? "other";
1004
- if (!existing || existing.status === "pending") {
1005
- session.toolCalls.set(tr.toolUseId, {
1006
- title,
1007
- kind,
1008
- status: "in_progress",
1009
- rawInput: existing?.rawInput
1010
- });
1011
- this.sendToolCallUpdate(session.sessionId, {
1012
- toolCallId: tr.toolUseId,
1013
- status: "in_progress"
1014
- });
1015
- }
1016
- const status = tr.isError ? "failed" : "completed";
1017
- session.toolCalls.set(tr.toolUseId, {
1018
- title,
1019
- kind,
1020
- status,
1021
- rawInput: existing?.rawInput
1022
- });
1023
- const rawOutput = asJsonObject(m.toolUseResult?.data);
1024
- const content = [];
1025
- const diffContent = status === "completed" ? this.buildDiffContentForToolResult(session, tr.toolUseId, rawOutput) : null;
1026
- if (diffContent) content.push(diffContent);
1027
- if (tr.content) {
1028
- content.push({ type: "content", content: { type: "text", text: tr.content } });
1029
- }
1030
- this.sendToolCallUpdate(session.sessionId, {
1031
- toolCallId: tr.toolUseId,
1032
- status,
1033
- ...content.length > 0 ? { content } : {},
1034
- ...rawOutput ? { rawOutput } : {}
1035
- });
1036
- }
1037
- session.messages.push(m);
1038
- return;
1039
- }
1040
- }
1041
- createAcpCanUseTool(session) {
1042
- const timeoutMs = (() => {
1043
- const raw = process.env.KODE_ACP_PERMISSION_TIMEOUT_MS;
1044
- const parsed = raw ? Number(raw) : NaN;
1045
- return Number.isFinite(parsed) && parsed > 0 ? parsed : 3e4;
1046
- })();
1047
- return async (tool, input, toolUseContext, assistantMessage) => {
1048
- const toolUseId = typeof toolUseContext?.toolUseId === "string" && toolUseContext.toolUseId ? toolUseContext.toolUseId : `call_${nanoid()}`;
1049
- const base = await hasPermissionsToUseTool(tool, input, toolUseContext, assistantMessage);
1050
- if (base.result === true) {
1051
- this.captureFileSnapshotForTool(session, toolUseId, tool.name, input);
1052
- return base;
1053
- }
1054
- const denied = base;
1055
- if (denied.shouldPromptUser === false) {
1056
- return { result: false, message: denied.message };
1057
- }
1058
- const title = titleForToolCall(tool.name, input);
1059
- const kind = toolKindForName(tool.name);
1060
- if (!session.toolCalls.has(toolUseId)) {
1061
- session.toolCalls.set(toolUseId, { title, kind, status: "pending", rawInput: asJsonObject(input) });
1062
- this.peer.sendNotification("session/update", {
1063
- sessionId: session.sessionId,
1064
- update: {
1065
- sessionUpdate: "tool_call",
1066
- toolCallId: toolUseId,
1067
- title,
1068
- kind,
1069
- status: "pending",
1070
- rawInput: asJsonObject(input)
1071
- }
1072
- });
1073
- }
1074
- const options = [
1075
- { optionId: "allow_once", name: "Allow once", kind: "allow_once" },
1076
- { optionId: "reject_once", name: "Reject", kind: "reject_once" }
1077
- ];
1078
- if (Array.isArray(denied.suggestions) && denied.suggestions.length > 0) {
1079
- options.splice(1, 0, {
1080
- optionId: "allow_always",
1081
- name: "Allow always (remember)",
1082
- kind: "allow_always"
1083
- });
1084
- }
1085
- try {
1086
- const response = await this.peer.sendRequest({
1087
- method: "session/request_permission",
1088
- params: {
1089
- sessionId: session.sessionId,
1090
- toolCall: {
1091
- toolCallId: toolUseId,
1092
- title,
1093
- kind,
1094
- status: "pending",
1095
- content: [
1096
- {
1097
- type: "content",
1098
- content: { type: "text", text: denied.message }
1099
- }
1100
- ],
1101
- rawInput: asJsonObject(input)
1102
- },
1103
- options
1104
- },
1105
- signal: toolUseContext.abortController.signal,
1106
- timeoutMs
1107
- });
1108
- const outcome = response?.outcome;
1109
- if (!outcome || outcome.outcome === "cancelled") {
1110
- toolUseContext.abortController.abort();
1111
- return { result: false, message: denied.message, shouldPromptUser: false };
1112
- }
1113
- if (outcome.outcome === "selected" && outcome.optionId === "allow_once") {
1114
- this.captureFileSnapshotForTool(session, toolUseId, tool.name, input);
1115
- return { result: true };
1116
- }
1117
- if (outcome.outcome === "selected" && outcome.optionId === "allow_always") {
1118
- const suggestions = Array.isArray(denied.suggestions) ? denied.suggestions : [];
1119
- if (suggestions.length > 0) {
1120
- const next = applyToolPermissionContextUpdates(session.toolPermissionContext, suggestions);
1121
- session.toolPermissionContext = next;
1122
- if (toolUseContext?.options) toolUseContext.options.toolPermissionContext = next;
1123
- for (const update of suggestions) {
1124
- try {
1125
- persistToolPermissionUpdateToDisk({ update, projectDir: session.cwd });
1126
- } catch (e) {
1127
- logError(e);
1128
- }
1129
- }
1130
- }
1131
- this.captureFileSnapshotForTool(session, toolUseId, tool.name, input);
1132
- return { result: true };
1133
- }
1134
- return { result: false, message: denied.message };
1135
- } catch (e) {
1136
- const msg = e instanceof Error ? e.message : String(e);
1137
- return { result: false, message: `Permission prompt failed: ${msg}`, shouldPromptUser: false };
1138
- }
1139
- };
1140
- }
1141
- captureFileSnapshotForTool(session, toolUseId, toolName, input) {
1142
- if (toolName !== "Write" && toolName !== "MultiEdit") return;
1143
- const filePath = input && typeof input === "object" ? String(input.file_path ?? "") : "";
1144
- if (!filePath) return;
1145
- const absPath = isAbsolute(filePath) ? filePath : resolve(session.cwd, filePath);
1146
- const oldContent = existsSync(absPath) ? readTextFileForDiff(absPath) : "";
1147
- if (oldContent === null) return;
1148
- const existing = session.toolCalls.get(toolUseId);
1149
- if (existing) {
1150
- existing.fileSnapshot = { path: absPath, content: oldContent };
1151
- session.toolCalls.set(toolUseId, existing);
1152
- return;
1153
- }
1154
- session.toolCalls.set(toolUseId, {
1155
- title: toolName,
1156
- kind: toolKindForName(toolName),
1157
- status: "pending",
1158
- rawInput: asJsonObject(input),
1159
- fileSnapshot: { path: absPath, content: oldContent }
1160
- });
1161
- }
1162
- buildDiffContentForToolResult(session, toolUseId, rawOutput) {
1163
- const existing = session.toolCalls.get(toolUseId);
1164
- if (!existing || existing.kind !== "edit") return null;
1165
- const inputFilePath = typeof existing.rawInput?.file_path === "string" ? existing.rawInput.file_path : rawOutput && typeof rawOutput.filePath === "string" ? String(rawOutput.filePath) : "";
1166
- if (!inputFilePath) return null;
1167
- const absPath = isAbsolute(inputFilePath) ? inputFilePath : resolve(session.cwd, inputFilePath);
1168
- const oldText = rawOutput && typeof rawOutput.originalFile === "string" ? String(rawOutput.originalFile) : existing.fileSnapshot && existing.fileSnapshot.path === absPath ? existing.fileSnapshot.content : void 0;
1169
- if (oldText === void 0) return null;
1170
- const newTextFromDisk = readTextFileForDiff(absPath);
1171
- const newTextFromOutput = rawOutput && typeof rawOutput.content === "string" ? String(rawOutput.content) : null;
1172
- const newText = newTextFromDisk ?? newTextFromOutput;
1173
- if (newText === null) return null;
1174
- return {
1175
- type: "diff",
1176
- path: absPath,
1177
- oldText: truncateDiffText(oldText),
1178
- newText: truncateDiffText(newText)
1179
- };
1180
- }
1181
- replayConversation(session) {
1182
- session.toolCalls.clear();
1183
- for (const m of session.messages) {
1184
- if (!m || typeof m !== "object") continue;
1185
- if (m.type === "assistant") {
1186
- const blocks = Array.isArray(m.message?.content) ? m.message.content : [];
1187
- for (const b of blocks) {
1188
- if (!b || typeof b !== "object") continue;
1189
- if (b.type === "text" && typeof b.text === "string") {
1190
- this.sendAgentMessage(session.sessionId, b.text);
1191
- } else if (b.type === "thinking" && typeof b.thinking === "string") {
1192
- this.sendAgentThought(session.sessionId, b.thinking);
1193
- } else if (b.type === "tool_use") {
1194
- const toolUseId = typeof b.id === "string" ? b.id : "";
1195
- const toolName = typeof b.name === "string" ? b.name : "";
1196
- const input = b.input && typeof b.input === "object" && !Array.isArray(b.input) ? b.input : {};
1197
- if (!toolUseId || !toolName) continue;
1198
- if (!session.toolCalls.has(toolUseId)) {
1199
- const kind = toolKindForName(toolName);
1200
- const title = titleForToolCall(toolName, input);
1201
- session.toolCalls.set(toolUseId, {
1202
- title,
1203
- kind,
1204
- status: "pending",
1205
- rawInput: asJsonObject(input)
1206
- });
1207
- this.peer.sendNotification("session/update", {
1208
- sessionId: session.sessionId,
1209
- update: {
1210
- sessionUpdate: "tool_call",
1211
- toolCallId: toolUseId,
1212
- title,
1213
- kind,
1214
- status: "pending",
1215
- rawInput: asJsonObject(input)
1216
- }
1217
- });
1218
- }
1219
- }
1220
- }
1221
- continue;
1222
- }
1223
- if (m.type === "user") {
1224
- const content = m?.message?.content;
1225
- if (typeof content === "string" && content.trim()) {
1226
- this.sendUserMessage(session.sessionId, content);
1227
- }
1228
- const toolResults = extractToolResults(m);
1229
- if (toolResults.length === 0) continue;
1230
- for (const tr of toolResults) {
1231
- const existing = session.toolCalls.get(tr.toolUseId);
1232
- const title = existing?.title ?? "Tool";
1233
- const kind = existing?.kind ?? "other";
1234
- if (!existing) {
1235
- session.toolCalls.set(tr.toolUseId, { title, kind, status: "pending" });
1236
- this.peer.sendNotification("session/update", {
1237
- sessionId: session.sessionId,
1238
- update: {
1239
- sessionUpdate: "tool_call",
1240
- toolCallId: tr.toolUseId,
1241
- title,
1242
- kind,
1243
- status: "pending"
1244
- }
1245
- });
1246
- }
1247
- const status = tr.isError ? "failed" : "completed";
1248
- const contentBlocks = [];
1249
- if (tr.content) {
1250
- contentBlocks.push({ type: "content", content: { type: "text", text: tr.content } });
1251
- }
1252
- const rawOutput = asJsonObject(m.toolUseResult?.data);
1253
- this.sendToolCallUpdate(session.sessionId, {
1254
- toolCallId: tr.toolUseId,
1255
- status,
1256
- ...contentBlocks.length > 0 ? { content: contentBlocks } : {},
1257
- ...rawOutput ? { rawOutput } : {}
1258
- });
1259
- session.toolCalls.set(tr.toolUseId, {
1260
- title,
1261
- kind,
1262
- status,
1263
- rawInput: existing?.rawInput
1264
- });
1265
- }
1266
- }
1267
- }
1268
- }
1269
- getModeState(session) {
1270
- const availableModes = [
1271
- { id: "default", name: "Default", description: "Normal permissions (prompt when needed)" },
1272
- { id: "acceptEdits", name: "Accept Edits", description: "Auto-approve safe file edits" },
1273
- { id: "plan", name: "Plan", description: "Read-only planning mode" },
1274
- { id: "dontAsk", name: "Don't Ask", description: "Auto-deny permission prompts" },
1275
- { id: "bypassPermissions", name: "Bypass", description: "Bypass permission prompts (dangerous)" }
1276
- ];
1277
- const currentModeId = availableModes.some((m) => m.id === session.currentModeId) ? session.currentModeId : "default";
1278
- return { currentModeId, availableModes };
1279
- }
1280
- sendAvailableCommands(session) {
1281
- const availableCommands = session.commands.filter((c) => !c.isHidden).map((c) => ({
1282
- name: c.userFacingName(),
1283
- description: c.description,
1284
- ...c.argumentHint ? { input: { hint: c.argumentHint } } : {}
1285
- }));
1286
- this.peer.sendNotification("session/update", {
1287
- sessionId: session.sessionId,
1288
- update: {
1289
- sessionUpdate: "available_commands_update",
1290
- availableCommands
1291
- }
1292
- });
1293
- }
1294
- sendCurrentMode(session) {
1295
- this.peer.sendNotification("session/update", {
1296
- sessionId: session.sessionId,
1297
- update: {
1298
- sessionUpdate: "current_mode_update",
1299
- currentModeId: session.currentModeId
1300
- }
1301
- });
1302
- }
1303
- sendUserMessage(sessionId, text) {
1304
- if (!text) return;
1305
- this.peer.sendNotification("session/update", {
1306
- sessionId,
1307
- update: {
1308
- sessionUpdate: "user_message_chunk",
1309
- content: { type: "text", text }
1310
- }
1311
- });
1312
- }
1313
- sendAgentMessage(sessionId, text) {
1314
- if (!text) return;
1315
- this.peer.sendNotification("session/update", {
1316
- sessionId,
1317
- update: {
1318
- sessionUpdate: "agent_message_chunk",
1319
- content: { type: "text", text }
1320
- }
1321
- });
1322
- }
1323
- sendAgentThought(sessionId, text) {
1324
- if (!text) return;
1325
- this.peer.sendNotification("session/update", {
1326
- sessionId,
1327
- update: {
1328
- sessionUpdate: "agent_thought_chunk",
1329
- content: { type: "text", text }
1330
- }
1331
- });
1332
- }
1333
- sendToolCallUpdate(sessionId, update) {
1334
- this.peer.sendNotification("session/update", {
1335
- sessionId,
1336
- update: {
1337
- sessionUpdate: "tool_call_update",
1338
- ...update
1339
- }
1340
- });
1341
- }
1342
- };
1343
-
1344
- // src/entrypoints/acp.ts
1345
- initSentry();
1346
- ensurePackagedRuntimeEnv();
1347
- var { writeAcpLine } = installStdoutGuard();
1348
- initDebugLogger();
1349
- try {
1350
- enableConfigs();
1351
- } catch (e) {
1352
- logError(e);
1353
- }
1354
- var peer = new JsonRpcPeer();
1355
- new KodeAcpAgent(peer);
1356
- var transport = new StdioTransport(peer, { writeLine: writeAcpLine });
1357
- transport.start();