@vybestack/llxprt-code-core 0.1.19-beta → 0.1.19

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 (540) hide show
  1. package/README.md +49 -2
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.js +6 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/auth/anthropic-device-flow.d.ts +53 -0
  6. package/dist/src/auth/anthropic-device-flow.js +208 -0
  7. package/dist/src/auth/anthropic-device-flow.js.map +1 -0
  8. package/dist/src/auth/precedence.d.ts +55 -0
  9. package/dist/src/auth/precedence.js +211 -0
  10. package/dist/src/auth/precedence.js.map +1 -0
  11. package/dist/src/auth/qwen-device-flow.d.ts +45 -0
  12. package/dist/src/auth/qwen-device-flow.js +179 -0
  13. package/dist/src/auth/qwen-device-flow.js.map +1 -0
  14. package/dist/src/auth/token-store.d.ts +66 -0
  15. package/dist/src/auth/token-store.js +151 -0
  16. package/dist/src/auth/token-store.js.map +1 -0
  17. package/dist/src/auth/types.d.ts +130 -0
  18. package/dist/src/auth/types.js +60 -0
  19. package/dist/src/auth/types.js.map +1 -0
  20. package/dist/src/code_assist/converter.d.ts +2 -2
  21. package/dist/src/code_assist/converter.js +1 -1
  22. package/dist/src/code_assist/converter.js.map +1 -1
  23. package/dist/src/config/config.d.ts +7 -1
  24. package/dist/src/config/config.js +46 -5
  25. package/dist/src/config/config.js.map +1 -1
  26. package/dist/src/config/endpoints.d.ts +60 -0
  27. package/dist/src/config/endpoints.js +126 -0
  28. package/dist/src/config/endpoints.js.map +1 -0
  29. package/dist/src/config/profileManager.d.ts +14 -4
  30. package/dist/src/config/profileManager.js +90 -11
  31. package/dist/src/config/profileManager.js.map +1 -1
  32. package/dist/src/core/client.d.ts +5 -2
  33. package/dist/src/core/client.js +164 -44
  34. package/dist/src/core/client.js.map +1 -1
  35. package/dist/src/core/contentGenerator.d.ts +4 -1
  36. package/dist/src/core/contentGenerator.js +3 -0
  37. package/dist/src/core/contentGenerator.js.map +1 -1
  38. package/dist/src/core/loggingContentGenerator.d.ts +5 -0
  39. package/dist/src/core/loggingContentGenerator.js +9 -1
  40. package/dist/src/core/loggingContentGenerator.js.map +1 -1
  41. package/dist/src/core/subagent.js +12 -10
  42. package/dist/src/core/subagent.js.map +1 -1
  43. package/dist/src/ide/detect-ide.d.ts +10 -2
  44. package/dist/src/ide/detect-ide.js +48 -5
  45. package/dist/src/ide/detect-ide.js.map +1 -1
  46. package/dist/src/ide/ide-client.js +22 -15
  47. package/dist/src/ide/ide-client.js.map +1 -1
  48. package/dist/src/index.d.ts +10 -1
  49. package/dist/src/index.js +10 -1
  50. package/dist/src/index.js.map +1 -1
  51. package/dist/src/prompt-config/defaults/core-defaults.d.ts +1 -1
  52. package/dist/src/prompt-config/defaults/core-defaults.js +21 -326
  53. package/dist/src/prompt-config/defaults/core-defaults.js.map +1 -1
  54. package/dist/src/prompt-config/defaults/core.md +1 -1
  55. package/dist/src/prompt-config/defaults/provider-defaults.d.ts +1 -1
  56. package/dist/src/prompt-config/defaults/provider-defaults.js +16 -19
  57. package/dist/src/prompt-config/defaults/provider-defaults.js.map +1 -1
  58. package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +273 -10
  59. package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/gemini-2-5-flash/core.md +278 -0
  60. package/dist/src/prompt-config/defaults/tool-defaults.d.ts +1 -1
  61. package/dist/src/prompt-config/defaults/tool-defaults.js +27 -75
  62. package/dist/src/prompt-config/defaults/tool-defaults.js.map +1 -1
  63. package/dist/src/prompt-config/defaults/tools/read-file.md +1 -1
  64. package/dist/src/providers/BaseProvider.d.ts +149 -0
  65. package/dist/src/providers/BaseProvider.js +315 -0
  66. package/dist/src/providers/BaseProvider.js.map +1 -0
  67. package/dist/src/providers/IProvider.d.ts +1 -0
  68. package/dist/src/providers/LoggingProviderWrapper.d.ts +1 -0
  69. package/dist/src/providers/LoggingProviderWrapper.js +3 -0
  70. package/dist/src/providers/LoggingProviderWrapper.js.map +1 -1
  71. package/dist/src/providers/ProviderManager.d.ts +0 -1
  72. package/dist/src/providers/ProviderManager.js +23 -14
  73. package/dist/src/providers/ProviderManager.js.map +1 -1
  74. package/dist/src/providers/anthropic/AnthropicProvider.d.ts +20 -6
  75. package/dist/src/providers/anthropic/AnthropicProvider.js +173 -27
  76. package/dist/src/providers/anthropic/AnthropicProvider.js.map +1 -1
  77. package/dist/src/providers/gemini/GeminiProvider.d.ts +20 -7
  78. package/dist/src/providers/gemini/GeminiProvider.js +182 -147
  79. package/dist/src/providers/gemini/GeminiProvider.js.map +1 -1
  80. package/dist/src/providers/openai/OpenAIProvider.d.ts +53 -6
  81. package/dist/src/providers/openai/OpenAIProvider.js +373 -40
  82. package/dist/src/providers/openai/OpenAIProvider.js.map +1 -1
  83. package/dist/src/providers/openai/RESPONSES_API_MODELS.d.ts +1 -1
  84. package/dist/src/providers/openai/RESPONSES_API_MODELS.js +1 -0
  85. package/dist/src/providers/openai/RESPONSES_API_MODELS.js.map +1 -1
  86. package/dist/src/providers/openai/syntheticToolResponses.d.ts +52 -0
  87. package/dist/src/providers/openai/syntheticToolResponses.js +129 -0
  88. package/dist/src/providers/openai/syntheticToolResponses.js.map +1 -0
  89. package/dist/src/services/loopDetectionService.js +4 -5
  90. package/dist/src/services/loopDetectionService.js.map +1 -1
  91. package/dist/src/settings/SettingsService.d.ts +32 -0
  92. package/dist/src/settings/SettingsService.js +204 -0
  93. package/dist/src/settings/SettingsService.js.map +1 -0
  94. package/dist/src/settings/settingsServiceInstance.d.ts +12 -0
  95. package/dist/src/settings/settingsServiceInstance.js +24 -0
  96. package/dist/src/settings/settingsServiceInstance.js.map +1 -0
  97. package/dist/src/settings/types.d.ts +141 -0
  98. package/dist/src/settings/types.js +5 -0
  99. package/dist/src/settings/types.js.map +1 -0
  100. package/dist/src/tools/edit.js +6 -7
  101. package/dist/src/tools/edit.js.map +1 -1
  102. package/dist/src/tools/glob.js +7 -8
  103. package/dist/src/tools/glob.js.map +1 -1
  104. package/dist/src/tools/grep.js +6 -7
  105. package/dist/src/tools/grep.js.map +1 -1
  106. package/dist/src/tools/ls.js +9 -10
  107. package/dist/src/tools/ls.js.map +1 -1
  108. package/dist/src/tools/mcp-tool.d.ts +3 -8
  109. package/dist/src/tools/mcp-tool.js +5 -18
  110. package/dist/src/tools/mcp-tool.js.map +1 -1
  111. package/dist/src/tools/memoryTool.js +4 -5
  112. package/dist/src/tools/memoryTool.js.map +1 -1
  113. package/dist/src/tools/read-file.js +5 -6
  114. package/dist/src/tools/read-file.js.map +1 -1
  115. package/dist/src/tools/read-many-files.js +17 -18
  116. package/dist/src/tools/read-many-files.js.map +1 -1
  117. package/dist/src/tools/shell.js +8 -9
  118. package/dist/src/tools/shell.js.map +1 -1
  119. package/dist/src/tools/tool-registry.d.ts +1 -15
  120. package/dist/src/tools/tool-registry.js +4 -72
  121. package/dist/src/tools/tool-registry.js.map +1 -1
  122. package/dist/src/tools/tools.d.ts +6 -6
  123. package/dist/src/tools/tools.js +2 -2
  124. package/dist/src/tools/tools.js.map +1 -1
  125. package/dist/src/tools/web-fetch.js +3 -4
  126. package/dist/src/tools/web-fetch.js.map +1 -1
  127. package/dist/src/tools/web-search.js +3 -4
  128. package/dist/src/tools/web-search.js.map +1 -1
  129. package/dist/src/tools/write-file.js +4 -5
  130. package/dist/src/tools/write-file.js.map +1 -1
  131. package/dist/src/utils/editCorrector.js +8 -9
  132. package/dist/src/utils/editCorrector.js.map +1 -1
  133. package/dist/src/utils/nextSpeakerChecker.js +3 -4
  134. package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
  135. package/dist/src/utils/schemaValidator.d.ts +1 -9
  136. package/dist/src/utils/schemaValidator.js +1 -109
  137. package/dist/src/utils/schemaValidator.js.map +1 -1
  138. package/package.json +4 -2
  139. package/dist/src/code_assist/converter.test.d.ts +0 -6
  140. package/dist/src/code_assist/converter.test.js +0 -279
  141. package/dist/src/code_assist/converter.test.js.map +0 -1
  142. package/dist/src/code_assist/oauth2.test.d.ts +0 -6
  143. package/dist/src/code_assist/oauth2.test.js +0 -370
  144. package/dist/src/code_assist/oauth2.test.js.map +0 -1
  145. package/dist/src/code_assist/server.test.d.ts +0 -6
  146. package/dist/src/code_assist/server.test.js +0 -134
  147. package/dist/src/code_assist/server.test.js.map +0 -1
  148. package/dist/src/code_assist/setup.test.d.ts +0 -6
  149. package/dist/src/code_assist/setup.test.js +0 -65
  150. package/dist/src/code_assist/setup.test.js.map +0 -1
  151. package/dist/src/config/config.alwaysAllow.test.d.ts +0 -6
  152. package/dist/src/config/config.alwaysAllow.test.js +0 -84
  153. package/dist/src/config/config.alwaysAllow.test.js.map +0 -1
  154. package/dist/src/config/config.ephemeral.test.d.ts +0 -6
  155. package/dist/src/config/config.ephemeral.test.js +0 -152
  156. package/dist/src/config/config.ephemeral.test.js.map +0 -1
  157. package/dist/src/config/config.test.d.ts +0 -6
  158. package/dist/src/config/config.test.js +0 -369
  159. package/dist/src/config/config.test.js.map +0 -1
  160. package/dist/src/config/flashFallback.test.d.ts +0 -6
  161. package/dist/src/config/flashFallback.test.js +0 -91
  162. package/dist/src/config/flashFallback.test.js.map +0 -1
  163. package/dist/src/core/client.test.d.ts +0 -6
  164. package/dist/src/core/client.test.js +0 -1322
  165. package/dist/src/core/client.test.js.map +0 -1
  166. package/dist/src/core/contentGenerator.test.d.ts +0 -6
  167. package/dist/src/core/contentGenerator.test.js +0 -103
  168. package/dist/src/core/contentGenerator.test.js.map +0 -1
  169. package/dist/src/core/coreToolScheduler.test.d.ts +0 -6
  170. package/dist/src/core/coreToolScheduler.test.js +0 -637
  171. package/dist/src/core/coreToolScheduler.test.js.map +0 -1
  172. package/dist/src/core/geminiChat.test.d.ts +0 -6
  173. package/dist/src/core/geminiChat.test.js +0 -425
  174. package/dist/src/core/geminiChat.test.js.map +0 -1
  175. package/dist/src/core/googleGenAIWrapper.test.d.ts +0 -6
  176. package/dist/src/core/googleGenAIWrapper.test.js +0 -104
  177. package/dist/src/core/googleGenAIWrapper.test.js.map +0 -1
  178. package/dist/src/core/logger.test.d.ts +0 -6
  179. package/dist/src/core/logger.test.js +0 -467
  180. package/dist/src/core/logger.test.js.map +0 -1
  181. package/dist/src/core/nonInteractiveToolExecutor.test.d.ts +0 -6
  182. package/dist/src/core/nonInteractiveToolExecutor.test.js +0 -165
  183. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +0 -1
  184. package/dist/src/core/prompts-async.test.d.ts +0 -6
  185. package/dist/src/core/prompts-async.test.js +0 -115
  186. package/dist/src/core/prompts-async.test.js.map +0 -1
  187. package/dist/src/core/prompts.test.d.ts +0 -6
  188. package/dist/src/core/prompts.test.js +0 -68
  189. package/dist/src/core/prompts.test.js.map +0 -1
  190. package/dist/src/core/subagent.test.d.ts +0 -6
  191. package/dist/src/core/subagent.test.js +0 -519
  192. package/dist/src/core/subagent.test.js.map +0 -1
  193. package/dist/src/core/tokenLimits.test.d.ts +0 -6
  194. package/dist/src/core/tokenLimits.test.js +0 -66
  195. package/dist/src/core/tokenLimits.test.js.map +0 -1
  196. package/dist/src/core/turn.test.d.ts +0 -6
  197. package/dist/src/core/turn.test.js +0 -366
  198. package/dist/src/core/turn.test.js.map +0 -1
  199. package/dist/src/hooks/tool-render-suppression-hook.test.d.ts +0 -6
  200. package/dist/src/hooks/tool-render-suppression-hook.test.js +0 -59
  201. package/dist/src/hooks/tool-render-suppression-hook.test.js.map +0 -1
  202. package/dist/src/ide/ide-installer.test.d.ts +0 -6
  203. package/dist/src/ide/ide-installer.test.js +0 -55
  204. package/dist/src/ide/ide-installer.test.js.map +0 -1
  205. package/dist/src/ide/ideContext.test.d.ts +0 -6
  206. package/dist/src/ide/ideContext.test.js +0 -265
  207. package/dist/src/ide/ideContext.test.js.map +0 -1
  208. package/dist/src/index.test.d.ts +0 -6
  209. package/dist/src/index.test.js +0 -12
  210. package/dist/src/index.test.js.map +0 -1
  211. package/dist/src/integration-tests/todo-system.test.d.ts +0 -6
  212. package/dist/src/integration-tests/todo-system.test.js +0 -46
  213. package/dist/src/integration-tests/todo-system.test.js.map +0 -1
  214. package/dist/src/mcp/google-auth-provider.test.d.ts +0 -6
  215. package/dist/src/mcp/google-auth-provider.test.js +0 -54
  216. package/dist/src/mcp/google-auth-provider.test.js.map +0 -1
  217. package/dist/src/mcp/oauth-provider.test.d.ts +0 -6
  218. package/dist/src/mcp/oauth-provider.test.js +0 -602
  219. package/dist/src/mcp/oauth-provider.test.js.map +0 -1
  220. package/dist/src/mcp/oauth-token-storage.test.d.ts +0 -6
  221. package/dist/src/mcp/oauth-token-storage.test.js +0 -205
  222. package/dist/src/mcp/oauth-token-storage.test.js.map +0 -1
  223. package/dist/src/mcp/oauth-utils.test.d.ts +0 -6
  224. package/dist/src/mcp/oauth-utils.test.js +0 -144
  225. package/dist/src/mcp/oauth-utils.test.js.map +0 -1
  226. package/dist/src/parsers/TextToolCallParser.multibyte.test.d.ts +0 -1
  227. package/dist/src/parsers/TextToolCallParser.multibyte.test.js +0 -42
  228. package/dist/src/parsers/TextToolCallParser.multibyte.test.js.map +0 -1
  229. package/dist/src/parsers/TextToolCallParser.test.d.ts +0 -1
  230. package/dist/src/parsers/TextToolCallParser.test.js +0 -225
  231. package/dist/src/parsers/TextToolCallParser.test.js.map +0 -1
  232. package/dist/src/prompt-config/TemplateEngine.test.d.ts +0 -1
  233. package/dist/src/prompt-config/TemplateEngine.test.js +0 -494
  234. package/dist/src/prompt-config/TemplateEngine.test.js.map +0 -1
  235. package/dist/src/prompt-config/prompt-cache.test.d.ts +0 -6
  236. package/dist/src/prompt-config/prompt-cache.test.js +0 -437
  237. package/dist/src/prompt-config/prompt-cache.test.js.map +0 -1
  238. package/dist/src/prompt-config/prompt-installer.test.d.ts +0 -7
  239. package/dist/src/prompt-config/prompt-installer.test.js +0 -503
  240. package/dist/src/prompt-config/prompt-installer.test.js.map +0 -1
  241. package/dist/src/prompt-config/prompt-loader.test.d.ts +0 -5
  242. package/dist/src/prompt-config/prompt-loader.test.js +0 -413
  243. package/dist/src/prompt-config/prompt-loader.test.js.map +0 -1
  244. package/dist/src/prompt-config/prompt-resolver.test.d.ts +0 -1
  245. package/dist/src/prompt-config/prompt-resolver.test.js +0 -529
  246. package/dist/src/prompt-config/prompt-resolver.test.js.map +0 -1
  247. package/dist/src/prompt-config/prompt-service.test.d.ts +0 -1
  248. package/dist/src/prompt-config/prompt-service.test.js +0 -811
  249. package/dist/src/prompt-config/prompt-service.test.js.map +0 -1
  250. package/dist/src/providers/ProviderManager.gemini-switch.test.d.ts +0 -6
  251. package/dist/src/providers/ProviderManager.gemini-switch.test.js +0 -57
  252. package/dist/src/providers/ProviderManager.gemini-switch.test.js.map +0 -1
  253. package/dist/src/providers/ProviderManager.test.d.ts +0 -6
  254. package/dist/src/providers/ProviderManager.test.js +0 -284
  255. package/dist/src/providers/ProviderManager.test.js.map +0 -1
  256. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.d.ts +0 -6
  257. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js +0 -273
  258. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js.map +0 -1
  259. package/dist/src/providers/anthropic/AnthropicProvider.modelParams.test.d.ts +0 -1
  260. package/dist/src/providers/anthropic/AnthropicProvider.modelParams.test.js +0 -48
  261. package/dist/src/providers/anthropic/AnthropicProvider.modelParams.test.js.map +0 -1
  262. package/dist/src/providers/anthropic/AnthropicProvider.test.d.ts +0 -1
  263. package/dist/src/providers/anthropic/AnthropicProvider.test.js +0 -487
  264. package/dist/src/providers/anthropic/AnthropicProvider.test.js.map +0 -1
  265. package/dist/src/providers/gemini/GeminiProvider.integration.test.d.ts +0 -6
  266. package/dist/src/providers/gemini/GeminiProvider.integration.test.js +0 -126
  267. package/dist/src/providers/gemini/GeminiProvider.integration.test.js.map +0 -1
  268. package/dist/src/providers/gemini/GeminiProvider.test.d.ts +0 -6
  269. package/dist/src/providers/gemini/GeminiProvider.test.js +0 -136
  270. package/dist/src/providers/gemini/GeminiProvider.test.js.map +0 -1
  271. package/dist/src/providers/integration/multi-provider.integration.test.d.ts +0 -6
  272. package/dist/src/providers/integration/multi-provider.integration.test.js +0 -292
  273. package/dist/src/providers/integration/multi-provider.integration.test.js.map +0 -1
  274. package/dist/src/providers/openai/ConversationCache.accumTokens.test.d.ts +0 -1
  275. package/dist/src/providers/openai/ConversationCache.accumTokens.test.js +0 -97
  276. package/dist/src/providers/openai/ConversationCache.accumTokens.test.js.map +0 -1
  277. package/dist/src/providers/openai/ConversationCache.test.d.ts +0 -1
  278. package/dist/src/providers/openai/ConversationCache.test.js +0 -113
  279. package/dist/src/providers/openai/ConversationCache.test.js.map +0 -1
  280. package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.d.ts +0 -1
  281. package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.js +0 -189
  282. package/dist/src/providers/openai/OpenAIProvider.callResponses.stateless.test.js.map +0 -1
  283. package/dist/src/providers/openai/OpenAIProvider.integration.test.d.ts +0 -6
  284. package/dist/src/providers/openai/OpenAIProvider.integration.test.js +0 -125
  285. package/dist/src/providers/openai/OpenAIProvider.integration.test.js.map +0 -1
  286. package/dist/src/providers/openai/OpenAIProvider.responses.test.d.ts +0 -1
  287. package/dist/src/providers/openai/OpenAIProvider.responses.test.js +0 -350
  288. package/dist/src/providers/openai/OpenAIProvider.responses.test.js.map +0 -1
  289. package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.d.ts +0 -1
  290. package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.js +0 -213
  291. package/dist/src/providers/openai/OpenAIProvider.responsesIntegration.test.js.map +0 -1
  292. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.d.ts +0 -1
  293. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js +0 -59
  294. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js.map +0 -1
  295. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.d.ts +0 -6
  296. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js +0 -105
  297. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js.map +0 -1
  298. package/dist/src/providers/openai/OpenAIProvider.switch.test.d.ts +0 -1
  299. package/dist/src/providers/openai/OpenAIProvider.switch.test.js +0 -256
  300. package/dist/src/providers/openai/OpenAIProvider.switch.test.js.map +0 -1
  301. package/dist/src/providers/openai/OpenAIProvider.test.d.ts +0 -16
  302. package/dist/src/providers/openai/OpenAIProvider.test.js +0 -620
  303. package/dist/src/providers/openai/OpenAIProvider.test.js.map +0 -1
  304. package/dist/src/providers/openai/ResponsesContextTrim.integration.test.d.ts +0 -1
  305. package/dist/src/providers/openai/ResponsesContextTrim.integration.test.js +0 -210
  306. package/dist/src/providers/openai/ResponsesContextTrim.integration.test.js.map +0 -1
  307. package/dist/src/providers/openai/__tests__/formatArrayResponse.test.d.ts +0 -1
  308. package/dist/src/providers/openai/__tests__/formatArrayResponse.test.js +0 -65
  309. package/dist/src/providers/openai/__tests__/formatArrayResponse.test.js.map +0 -1
  310. package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.d.ts +0 -1
  311. package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.js +0 -129
  312. package/dist/src/providers/openai/buildResponsesRequest.stripToolCalls.test.js.map +0 -1
  313. package/dist/src/providers/openai/buildResponsesRequest.test.d.ts +0 -1
  314. package/dist/src/providers/openai/buildResponsesRequest.test.js +0 -406
  315. package/dist/src/providers/openai/buildResponsesRequest.test.js.map +0 -1
  316. package/dist/src/providers/openai/buildResponsesRequest.undefined.test.d.ts +0 -1
  317. package/dist/src/providers/openai/buildResponsesRequest.undefined.test.js +0 -50
  318. package/dist/src/providers/openai/buildResponsesRequest.undefined.test.js.map +0 -1
  319. package/dist/src/providers/openai/estimateRemoteTokens.test.d.ts +0 -1
  320. package/dist/src/providers/openai/estimateRemoteTokens.test.js +0 -125
  321. package/dist/src/providers/openai/estimateRemoteTokens.test.js.map +0 -1
  322. package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.d.ts +0 -1
  323. package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.js +0 -192
  324. package/dist/src/providers/openai/parseResponsesStream.responsesToolCalls.test.js.map +0 -1
  325. package/dist/src/providers/openai/parseResponsesStream.test.d.ts +0 -1
  326. package/dist/src/providers/openai/parseResponsesStream.test.js +0 -151
  327. package/dist/src/providers/openai/parseResponsesStream.test.js.map +0 -1
  328. package/dist/src/services/fileDiscoveryService.test.d.ts +0 -6
  329. package/dist/src/services/fileDiscoveryService.test.js +0 -143
  330. package/dist/src/services/fileDiscoveryService.test.js.map +0 -1
  331. package/dist/src/services/gitService.test.d.ts +0 -6
  332. package/dist/src/services/gitService.test.js +0 -209
  333. package/dist/src/services/gitService.test.js.map +0 -1
  334. package/dist/src/services/loopDetectionService.test.d.ts +0 -6
  335. package/dist/src/services/loopDetectionService.test.js +0 -484
  336. package/dist/src/services/loopDetectionService.test.js.map +0 -1
  337. package/dist/src/services/shellExecutionService.multibyte.test.d.ts +0 -6
  338. package/dist/src/services/shellExecutionService.multibyte.test.js +0 -72
  339. package/dist/src/services/shellExecutionService.multibyte.test.js.map +0 -1
  340. package/dist/src/services/shellExecutionService.test.d.ts +0 -6
  341. package/dist/src/services/shellExecutionService.test.js +0 -272
  342. package/dist/src/services/shellExecutionService.test.js.map +0 -1
  343. package/dist/src/services/shellExecutionService.windows.multibyte.test.d.ts +0 -6
  344. package/dist/src/services/shellExecutionService.windows.multibyte.test.js +0 -98
  345. package/dist/src/services/shellExecutionService.windows.multibyte.test.js.map +0 -1
  346. package/dist/src/services/shellExecutionService.windows.test.d.ts +0 -6
  347. package/dist/src/services/shellExecutionService.windows.test.js +0 -79
  348. package/dist/src/services/shellExecutionService.windows.test.js.map +0 -1
  349. package/dist/src/services/tool-call-tracker-service.test.d.ts +0 -6
  350. package/dist/src/services/tool-call-tracker-service.test.js +0 -99
  351. package/dist/src/services/tool-call-tracker-service.test.js.map +0 -1
  352. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +0 -6
  353. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +0 -187
  354. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +0 -1
  355. package/dist/src/telemetry/loggers.test.d.ts +0 -6
  356. package/dist/src/telemetry/loggers.test.js +0 -573
  357. package/dist/src/telemetry/loggers.test.js.map +0 -1
  358. package/dist/src/telemetry/metrics.test.d.ts +0 -6
  359. package/dist/src/telemetry/metrics.test.js +0 -212
  360. package/dist/src/telemetry/metrics.test.js.map +0 -1
  361. package/dist/src/telemetry/telemetry.test.d.ts +0 -6
  362. package/dist/src/telemetry/telemetry.test.js +0 -54
  363. package/dist/src/telemetry/telemetry.test.js.map +0 -1
  364. package/dist/src/telemetry/uiTelemetry.test.d.ts +0 -6
  365. package/dist/src/telemetry/uiTelemetry.test.js +0 -518
  366. package/dist/src/telemetry/uiTelemetry.test.js.map +0 -1
  367. package/dist/src/tools/ToolFormatter.test.d.ts +0 -16
  368. package/dist/src/tools/ToolFormatter.test.js +0 -349
  369. package/dist/src/tools/ToolFormatter.test.js.map +0 -1
  370. package/dist/src/tools/ToolFormatter.toResponsesTool.test.d.ts +0 -1
  371. package/dist/src/tools/ToolFormatter.toResponsesTool.test.js +0 -241
  372. package/dist/src/tools/ToolFormatter.toResponsesTool.test.js.map +0 -1
  373. package/dist/src/tools/diffOptions.test.d.ts +0 -6
  374. package/dist/src/tools/diffOptions.test.js +0 -119
  375. package/dist/src/tools/diffOptions.test.js.map +0 -1
  376. package/dist/src/tools/edit.test.d.ts +0 -6
  377. package/dist/src/tools/edit.test.js +0 -689
  378. package/dist/src/tools/edit.test.js.map +0 -1
  379. package/dist/src/tools/glob.test.d.ts +0 -6
  380. package/dist/src/tools/glob.test.js +0 -332
  381. package/dist/src/tools/glob.test.js.map +0 -1
  382. package/dist/src/tools/grep.test.d.ts +0 -6
  383. package/dist/src/tools/grep.test.js +0 -272
  384. package/dist/src/tools/grep.test.js.map +0 -1
  385. package/dist/src/tools/ls.test.d.ts +0 -6
  386. package/dist/src/tools/ls.test.js +0 -357
  387. package/dist/src/tools/ls.test.js.map +0 -1
  388. package/dist/src/tools/mcp-client.test.d.ts +0 -6
  389. package/dist/src/tools/mcp-client.test.js +0 -617
  390. package/dist/src/tools/mcp-client.test.js.map +0 -1
  391. package/dist/src/tools/mcp-tool.test.d.ts +0 -6
  392. package/dist/src/tools/mcp-tool.test.js +0 -501
  393. package/dist/src/tools/mcp-tool.test.js.map +0 -1
  394. package/dist/src/tools/memoryTool.test.d.ts +0 -6
  395. package/dist/src/tools/memoryTool.test.js +0 -266
  396. package/dist/src/tools/memoryTool.test.js.map +0 -1
  397. package/dist/src/tools/modifiable-tool.test.d.ts +0 -6
  398. package/dist/src/tools/modifiable-tool.test.js +0 -193
  399. package/dist/src/tools/modifiable-tool.test.js.map +0 -1
  400. package/dist/src/tools/read-file.test.d.ts +0 -6
  401. package/dist/src/tools/read-file.test.js +0 -319
  402. package/dist/src/tools/read-file.test.js.map +0 -1
  403. package/dist/src/tools/read-many-files.test.d.ts +0 -6
  404. package/dist/src/tools/read-many-files.test.js +0 -644
  405. package/dist/src/tools/read-many-files.test.js.map +0 -1
  406. package/dist/src/tools/shell.multibyte.test.d.ts +0 -6
  407. package/dist/src/tools/shell.multibyte.test.js +0 -75
  408. package/dist/src/tools/shell.multibyte.test.js.map +0 -1
  409. package/dist/src/tools/shell.test.d.ts +0 -6
  410. package/dist/src/tools/shell.test.js +0 -367
  411. package/dist/src/tools/shell.test.js.map +0 -1
  412. package/dist/src/tools/todo-pause.spec.d.ts +0 -6
  413. package/dist/src/tools/todo-pause.spec.js +0 -287
  414. package/dist/src/tools/todo-pause.spec.js.map +0 -1
  415. package/dist/src/tools/todo-read.test.d.ts +0 -6
  416. package/dist/src/tools/todo-read.test.js +0 -162
  417. package/dist/src/tools/todo-read.test.js.map +0 -1
  418. package/dist/src/tools/todo-schemas.test.d.ts +0 -6
  419. package/dist/src/tools/todo-schemas.test.js +0 -341
  420. package/dist/src/tools/todo-schemas.test.js.map +0 -1
  421. package/dist/src/tools/todo-store.test.d.ts +0 -6
  422. package/dist/src/tools/todo-store.test.js +0 -169
  423. package/dist/src/tools/todo-store.test.js.map +0 -1
  424. package/dist/src/tools/todo-write.test.d.ts +0 -6
  425. package/dist/src/tools/todo-write.test.js +0 -226
  426. package/dist/src/tools/todo-write.test.js.map +0 -1
  427. package/dist/src/tools/tool-registry.test.d.ts +0 -6
  428. package/dist/src/tools/tool-registry.test.js +0 -468
  429. package/dist/src/tools/tool-registry.test.js.map +0 -1
  430. package/dist/src/tools/tools.test.d.ts +0 -6
  431. package/dist/src/tools/tools.test.js +0 -117
  432. package/dist/src/tools/tools.test.js.map +0 -1
  433. package/dist/src/tools/web-fetch.integration.test.d.ts +0 -6
  434. package/dist/src/tools/web-fetch.integration.test.js +0 -532
  435. package/dist/src/tools/web-fetch.integration.test.js.map +0 -1
  436. package/dist/src/tools/web-search.test.d.ts +0 -6
  437. package/dist/src/tools/web-search.test.js +0 -230
  438. package/dist/src/tools/web-search.test.js.map +0 -1
  439. package/dist/src/tools/write-file.test.d.ts +0 -6
  440. package/dist/src/tools/write-file.test.js +0 -465
  441. package/dist/src/tools/write-file.test.js.map +0 -1
  442. package/dist/src/utils/bfsFileSearch.test.d.ts +0 -6
  443. package/dist/src/utils/bfsFileSearch.test.js +0 -191
  444. package/dist/src/utils/bfsFileSearch.test.js.map +0 -1
  445. package/dist/src/utils/editCorrector.test.d.ts +0 -6
  446. package/dist/src/utils/editCorrector.test.js +0 -564
  447. package/dist/src/utils/editCorrector.test.js.map +0 -1
  448. package/dist/src/utils/editor.test.d.ts +0 -6
  449. package/dist/src/utils/editor.test.js +0 -445
  450. package/dist/src/utils/editor.test.js.map +0 -1
  451. package/dist/src/utils/environmentContext.test.d.ts +0 -6
  452. package/dist/src/utils/environmentContext.test.js +0 -139
  453. package/dist/src/utils/environmentContext.test.js.map +0 -1
  454. package/dist/src/utils/errorReporting.test.d.ts +0 -6
  455. package/dist/src/utils/errorReporting.test.js +0 -130
  456. package/dist/src/utils/errorReporting.test.js.map +0 -1
  457. package/dist/src/utils/fileUtils.test.d.ts +0 -6
  458. package/dist/src/utils/fileUtils.test.js +0 -363
  459. package/dist/src/utils/fileUtils.test.js.map +0 -1
  460. package/dist/src/utils/filesearch/crawlCache.test.d.ts +0 -6
  461. package/dist/src/utils/filesearch/crawlCache.test.js +0 -103
  462. package/dist/src/utils/filesearch/crawlCache.test.js.map +0 -1
  463. package/dist/src/utils/filesearch/fileSearch.test.d.ts +0 -6
  464. package/dist/src/utils/filesearch/fileSearch.test.js +0 -654
  465. package/dist/src/utils/filesearch/fileSearch.test.js.map +0 -1
  466. package/dist/src/utils/filesearch/ignore.test.d.ts +0 -6
  467. package/dist/src/utils/filesearch/ignore.test.js +0 -57
  468. package/dist/src/utils/filesearch/ignore.test.js.map +0 -1
  469. package/dist/src/utils/filesearch/result-cache.test.d.ts +0 -6
  470. package/dist/src/utils/filesearch/result-cache.test.js +0 -47
  471. package/dist/src/utils/filesearch/result-cache.test.js.map +0 -1
  472. package/dist/src/utils/flashFallback.integration.test.d.ts +0 -6
  473. package/dist/src/utils/flashFallback.integration.test.js +0 -120
  474. package/dist/src/utils/flashFallback.integration.test.js.map +0 -1
  475. package/dist/src/utils/generateContentResponseUtilities.test.d.ts +0 -6
  476. package/dist/src/utils/generateContentResponseUtilities.test.js +0 -273
  477. package/dist/src/utils/generateContentResponseUtilities.test.js.map +0 -1
  478. package/dist/src/utils/getFolderStructure.test.d.ts +0 -6
  479. package/dist/src/utils/getFolderStructure.test.js +0 -282
  480. package/dist/src/utils/getFolderStructure.test.js.map +0 -1
  481. package/dist/src/utils/gitIgnoreParser.test.d.ts +0 -6
  482. package/dist/src/utils/gitIgnoreParser.test.js +0 -154
  483. package/dist/src/utils/gitIgnoreParser.test.js.map +0 -1
  484. package/dist/src/utils/memoryDiscovery.test.d.ts +0 -6
  485. package/dist/src/utils/memoryDiscovery.test.js +0 -181
  486. package/dist/src/utils/memoryDiscovery.test.js.map +0 -1
  487. package/dist/src/utils/memoryImportProcessor.test.d.ts +0 -6
  488. package/dist/src/utils/memoryImportProcessor.test.js +0 -715
  489. package/dist/src/utils/memoryImportProcessor.test.js.map +0 -1
  490. package/dist/src/utils/nextSpeakerChecker.test.d.ts +0 -6
  491. package/dist/src/utils/nextSpeakerChecker.test.js +0 -172
  492. package/dist/src/utils/nextSpeakerChecker.test.js.map +0 -1
  493. package/dist/src/utils/partUtils.test.d.ts +0 -6
  494. package/dist/src/utils/partUtils.test.js +0 -130
  495. package/dist/src/utils/partUtils.test.js.map +0 -1
  496. package/dist/src/utils/paths.test.d.ts +0 -6
  497. package/dist/src/utils/paths.test.js +0 -153
  498. package/dist/src/utils/paths.test.js.map +0 -1
  499. package/dist/src/utils/retry.test.d.ts +0 -6
  500. package/dist/src/utils/retry.test.js +0 -322
  501. package/dist/src/utils/retry.test.js.map +0 -1
  502. package/dist/src/utils/safeJsonStringify.test.d.ts +0 -6
  503. package/dist/src/utils/safeJsonStringify.test.js +0 -61
  504. package/dist/src/utils/safeJsonStringify.test.js.map +0 -1
  505. package/dist/src/utils/sanitization.test.d.ts +0 -6
  506. package/dist/src/utils/sanitization.test.js +0 -81
  507. package/dist/src/utils/sanitization.test.js.map +0 -1
  508. package/dist/src/utils/schemaValidator.test.d.ts +0 -6
  509. package/dist/src/utils/schemaValidator.test.js +0 -146
  510. package/dist/src/utils/schemaValidator.test.js.map +0 -1
  511. package/dist/src/utils/secure-browser-launcher.test.d.ts +0 -6
  512. package/dist/src/utils/secure-browser-launcher.test.js +0 -149
  513. package/dist/src/utils/secure-browser-launcher.test.js.map +0 -1
  514. package/dist/src/utils/shell-utils.shellReplacement.test.d.ts +0 -6
  515. package/dist/src/utils/shell-utils.shellReplacement.test.js +0 -149
  516. package/dist/src/utils/shell-utils.shellReplacement.test.js.map +0 -1
  517. package/dist/src/utils/shell-utils.test.d.ts +0 -6
  518. package/dist/src/utils/shell-utils.test.js +0 -200
  519. package/dist/src/utils/shell-utils.test.js.map +0 -1
  520. package/dist/src/utils/summarizer.test.d.ts +0 -6
  521. package/dist/src/utils/summarizer.test.js +0 -131
  522. package/dist/src/utils/summarizer.test.js.map +0 -1
  523. package/dist/src/utils/systemEncoding.test.d.ts +0 -6
  524. package/dist/src/utils/systemEncoding.test.js +0 -368
  525. package/dist/src/utils/systemEncoding.test.js.map +0 -1
  526. package/dist/src/utils/toolOutputLimiter.test.d.ts +0 -6
  527. package/dist/src/utils/toolOutputLimiter.test.js +0 -164
  528. package/dist/src/utils/toolOutputLimiter.test.js.map +0 -1
  529. package/dist/src/utils/unicodeUtils.test.d.ts +0 -6
  530. package/dist/src/utils/unicodeUtils.test.js +0 -120
  531. package/dist/src/utils/unicodeUtils.test.js.map +0 -1
  532. package/dist/src/utils/user_account.test.d.ts +0 -6
  533. package/dist/src/utils/user_account.test.js +0 -153
  534. package/dist/src/utils/user_account.test.js.map +0 -1
  535. package/dist/src/utils/user_id.test.d.ts +0 -6
  536. package/dist/src/utils/user_id.test.js +0 -21
  537. package/dist/src/utils/user_id.test.js.map +0 -1
  538. package/dist/src/utils/workspaceContext.test.d.ts +0 -6
  539. package/dist/src/utils/workspaceContext.test.js +0 -209
  540. package/dist/src/utils/workspaceContext.test.js.map +0 -1
@@ -1,689 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- /* eslint-disable @typescript-eslint/no-explicit-any */
7
- const mockEnsureCorrectEdit = vi.hoisted(() => vi.fn());
8
- const mockGenerateJson = vi.hoisted(() => vi.fn());
9
- const mockOpenDiff = vi.hoisted(() => vi.fn());
10
- import { IDEConnectionStatus } from '../ide/ide-client.js';
11
- vi.mock('../utils/editCorrector.js', () => ({
12
- ensureCorrectEdit: mockEnsureCorrectEdit,
13
- }));
14
- vi.mock('../core/client.js', () => ({
15
- GeminiClient: vi.fn().mockImplementation(() => ({
16
- generateJson: mockGenerateJson,
17
- })),
18
- }));
19
- vi.mock('../utils/editor.js', () => ({
20
- openDiff: mockOpenDiff,
21
- }));
22
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
23
- import { applyReplacement, EditTool } from './edit.js';
24
- import { ToolConfirmationOutcome } from './tools.js';
25
- import { ToolErrorType } from './tool-error.js';
26
- import path from 'path';
27
- import fs from 'fs';
28
- import os from 'os';
29
- import { ApprovalMode } from '../config/config.js';
30
- import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
31
- describe('EditTool', () => {
32
- let tool;
33
- let tempDir;
34
- let rootDir;
35
- let mockConfig;
36
- let geminiClient;
37
- beforeEach(() => {
38
- vi.restoreAllMocks();
39
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'edit-tool-test-'));
40
- rootDir = path.join(tempDir, 'root');
41
- fs.mkdirSync(rootDir);
42
- geminiClient = {
43
- generateJson: mockGenerateJson, // mockGenerateJson is already defined and hoisted
44
- };
45
- mockConfig = {
46
- getGeminiClient: vi.fn().mockReturnValue(geminiClient),
47
- getTargetDir: () => rootDir,
48
- getApprovalMode: vi.fn(),
49
- setApprovalMode: vi.fn(),
50
- getWorkspaceContext: () => createMockWorkspaceContext(rootDir),
51
- getIdeClient: () => undefined,
52
- getIdeMode: () => false,
53
- getIdeModeFeature: () => false,
54
- // getGeminiConfig: () => ({ apiKey: 'test-api-key' }), // This was not a real Config method
55
- // Add other properties/methods of Config if EditTool uses them
56
- // Minimal other methods to satisfy Config type if needed by EditTool constructor or other direct uses:
57
- getApiKey: () => 'test-api-key',
58
- getModel: () => 'test-model',
59
- getSandbox: () => false,
60
- getDebugMode: () => false,
61
- getQuestion: () => undefined,
62
- getFullContext: () => false,
63
- getToolDiscoveryCommand: () => undefined,
64
- getToolCallCommand: () => undefined,
65
- getMcpServerCommand: () => undefined,
66
- getMcpServers: () => undefined,
67
- getUserAgent: () => 'test-agent',
68
- getUserMemory: () => '',
69
- setUserMemory: vi.fn(),
70
- getLlxprtMdFileCount: () => 0,
71
- setLlxprtMdFileCount: vi.fn(),
72
- getConversationLoggingEnabled: () => false,
73
- getToolRegistry: () => ({}), // Minimal mock for ToolRegistry
74
- };
75
- // Reset mocks before each test
76
- mockConfig.getApprovalMode.mockClear();
77
- // Default to not skipping confirmation
78
- mockConfig.getApprovalMode.mockReturnValue(ApprovalMode.DEFAULT);
79
- // Reset mocks and set default implementation for ensureCorrectEdit
80
- mockEnsureCorrectEdit.mockReset();
81
- mockEnsureCorrectEdit.mockImplementation(async (_, currentContent, params) => {
82
- let occurrences = 0;
83
- if (params.old_string && currentContent) {
84
- // Simple string counting for the mock
85
- let index = currentContent.indexOf(params.old_string);
86
- while (index !== -1) {
87
- occurrences++;
88
- index = currentContent.indexOf(params.old_string, index + 1);
89
- }
90
- }
91
- else if (params.old_string === '') {
92
- occurrences = 0; // Creating a new file
93
- }
94
- return Promise.resolve({ params, occurrences });
95
- });
96
- // Default mock for generateJson to return the snippet unchanged
97
- mockGenerateJson.mockReset();
98
- mockGenerateJson.mockImplementation(async (contents, schema) => {
99
- // The problematic_snippet is the last part of the user's content
100
- const userContent = contents.find((c) => c.role === 'user');
101
- let promptText = '';
102
- if (userContent && userContent.parts) {
103
- promptText = userContent.parts
104
- .filter((p) => typeof p.text === 'string')
105
- .map((p) => p.text)
106
- .join('\n');
107
- }
108
- const snippetMatch = promptText.match(/Problematic target snippet:\n```\n([\s\S]*?)\n```/);
109
- const problematicSnippet = snippetMatch && snippetMatch[1] ? snippetMatch[1] : '';
110
- if (schema.properties?.corrected_target_snippet) {
111
- return Promise.resolve({
112
- corrected_target_snippet: problematicSnippet,
113
- });
114
- }
115
- if (schema.properties?.corrected_new_string) {
116
- // For new_string correction, we might need more sophisticated logic,
117
- // but for now, returning original is a safe default if not specified by a test.
118
- const originalNewStringMatch = promptText.match(/original_new_string \(what was intended to replace original_old_string\):\n```\n([\s\S]*?)\n```/);
119
- const originalNewString = originalNewStringMatch && originalNewStringMatch[1]
120
- ? originalNewStringMatch[1]
121
- : '';
122
- return Promise.resolve({ corrected_new_string: originalNewString });
123
- }
124
- return Promise.resolve({}); // Default empty object if schema doesn't match
125
- });
126
- tool = new EditTool(mockConfig);
127
- });
128
- afterEach(() => {
129
- fs.rmSync(tempDir, { recursive: true, force: true });
130
- });
131
- describe('applyReplacement', () => {
132
- // Test the exported applyReplacement function
133
- it('should return newString if isNewFile is true', () => {
134
- expect(applyReplacement(null, 'old', 'new', true)).toBe('new');
135
- expect(applyReplacement('existing', 'old', 'new', true)).toBe('new');
136
- });
137
- it('should return newString if currentContent is null and oldString is empty (defensive)', () => {
138
- expect(applyReplacement(null, '', 'new', false)).toBe('new');
139
- });
140
- it('should return empty string if currentContent is null and oldString is not empty (defensive)', () => {
141
- expect(applyReplacement(null, 'old', 'new', false)).toBe('');
142
- });
143
- it('should replace oldString with newString in currentContent', () => {
144
- expect(applyReplacement('hello old world old', 'old', 'new', false)).toBe('hello new world new');
145
- });
146
- it('should return currentContent if oldString is empty and not a new file', () => {
147
- expect(applyReplacement('hello world', '', 'new', false)).toBe('hello world');
148
- });
149
- });
150
- describe('validateToolParams', () => {
151
- it('should return null for valid params', () => {
152
- const params = {
153
- file_path: path.join(rootDir, 'test.txt'),
154
- old_string: 'old',
155
- new_string: 'new',
156
- };
157
- // No error should be thrown when building with valid params
158
- expect(() => tool.build(params)).not.toThrow();
159
- });
160
- it('should return error for relative path', () => {
161
- const params = {
162
- file_path: 'test.txt',
163
- old_string: 'old',
164
- new_string: 'new',
165
- };
166
- expect(() => tool.build(params)).toThrow(/File path must be absolute/);
167
- });
168
- it('should return error for path outside root', () => {
169
- const params = {
170
- file_path: path.join(tempDir, 'outside-root.txt'),
171
- old_string: 'old',
172
- new_string: 'new',
173
- };
174
- expect(() => tool.build(params)).toThrow(/File path must be within one of the workspace directories/);
175
- });
176
- });
177
- describe('shouldConfirmExecute', () => {
178
- const testFile = 'edit_me.txt';
179
- let filePath;
180
- beforeEach(() => {
181
- filePath = path.join(rootDir, testFile);
182
- });
183
- it('should return false if params are invalid', async () => {
184
- const params = {
185
- file_path: 'relative.txt',
186
- old_string: 'old',
187
- new_string: 'new',
188
- };
189
- // Invalid params should throw during build
190
- expect(() => tool.build(params)).toThrow(/File path must be absolute/);
191
- });
192
- it('should request confirmation for valid edit', async () => {
193
- fs.writeFileSync(filePath, 'some old content here');
194
- const params = {
195
- file_path: filePath,
196
- old_string: 'old',
197
- new_string: 'new',
198
- };
199
- // ensureCorrectEdit will be called by shouldConfirmExecute
200
- mockEnsureCorrectEdit.mockResolvedValueOnce({ params, occurrences: 1 });
201
- const invocation = tool.build(params);
202
- const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
203
- expect(confirmation).toEqual(expect.objectContaining({
204
- title: `Confirm Edit: ${testFile}`,
205
- fileName: testFile,
206
- fileDiff: expect.any(String),
207
- }));
208
- });
209
- it('should return false if old_string is not found (ensureCorrectEdit returns 0)', async () => {
210
- fs.writeFileSync(filePath, 'some content here');
211
- const params = {
212
- file_path: filePath,
213
- old_string: 'not_found',
214
- new_string: 'new',
215
- };
216
- mockEnsureCorrectEdit.mockResolvedValueOnce({ params, occurrences: 0 });
217
- const invocation = tool.build(params);
218
- expect(await invocation.shouldConfirmExecute(new AbortController().signal)).toBe(false);
219
- });
220
- it('should return false if multiple occurrences of old_string are found (ensureCorrectEdit returns > 1)', async () => {
221
- fs.writeFileSync(filePath, 'old old content here');
222
- const params = {
223
- file_path: filePath,
224
- old_string: 'old',
225
- new_string: 'new',
226
- };
227
- mockEnsureCorrectEdit.mockResolvedValueOnce({ params, occurrences: 2 });
228
- const invocation = tool.build(params);
229
- expect(await invocation.shouldConfirmExecute(new AbortController().signal)).toBe(false);
230
- });
231
- it('should request confirmation for creating a new file (empty old_string)', async () => {
232
- const newFileName = 'new_file.txt';
233
- const newFilePath = path.join(rootDir, newFileName);
234
- const params = {
235
- file_path: newFilePath,
236
- old_string: '',
237
- new_string: 'new file content',
238
- };
239
- // ensureCorrectEdit might not be called if old_string is empty,
240
- // as shouldConfirmExecute handles this for diff generation.
241
- // If it is called, it should return 0 occurrences for a new file.
242
- mockEnsureCorrectEdit.mockResolvedValueOnce({ params, occurrences: 0 });
243
- const invocation = tool.build(params);
244
- const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
245
- expect(confirmation).toEqual(expect.objectContaining({
246
- title: `Confirm Edit: ${newFileName}`,
247
- fileName: newFileName,
248
- fileDiff: expect.any(String),
249
- }));
250
- });
251
- it('should use corrected params from ensureCorrectEdit for diff generation', async () => {
252
- const originalContent = 'This is the original string to be replaced.';
253
- const originalOldString = 'original string';
254
- const originalNewString = 'new string';
255
- const correctedOldString = 'original string to be replaced'; // More specific
256
- const correctedNewString = 'completely new string'; // Different replacement
257
- const expectedFinalContent = 'This is the completely new string.';
258
- fs.writeFileSync(filePath, originalContent);
259
- const params = {
260
- file_path: filePath,
261
- old_string: originalOldString,
262
- new_string: originalNewString,
263
- };
264
- // The main beforeEach already calls mockEnsureCorrectEdit.mockReset()
265
- // Set a specific mock for this test case
266
- let mockCalled = false;
267
- mockEnsureCorrectEdit.mockImplementationOnce(async (_, content, p, client) => {
268
- mockCalled = true;
269
- expect(content).toBe(originalContent);
270
- expect(p).toBe(params);
271
- expect(client).toBe(geminiClient);
272
- return {
273
- params: {
274
- file_path: filePath,
275
- old_string: correctedOldString,
276
- new_string: correctedNewString,
277
- },
278
- occurrences: 1,
279
- };
280
- });
281
- const invocation = tool.build(params);
282
- const confirmation = (await invocation.shouldConfirmExecute(new AbortController().signal));
283
- expect(mockCalled).toBe(true); // Check if the mock implementation was run
284
- // expect(mockEnsureCorrectEdit).toHaveBeenCalledWith(originalContent, params, expect.anything()); // Keep this commented for now
285
- expect(confirmation).toEqual(expect.objectContaining({
286
- title: `Confirm Edit: ${testFile}`,
287
- fileName: testFile,
288
- }));
289
- // Check that the diff is based on the corrected strings leading to the new state
290
- expect(confirmation.fileDiff).toContain(`-${originalContent}`);
291
- expect(confirmation.fileDiff).toContain(`+${expectedFinalContent}`);
292
- // Verify that applying the correctedOldString and correctedNewString to originalContent
293
- // indeed produces the expectedFinalContent, which is what the diff should reflect.
294
- const patchedContent = originalContent.replace(correctedOldString, // This was the string identified by ensureCorrectEdit for replacement
295
- correctedNewString);
296
- expect(patchedContent).toBe(expectedFinalContent);
297
- });
298
- });
299
- describe('execute', () => {
300
- const testFile = 'execute_me.txt';
301
- let filePath;
302
- beforeEach(() => {
303
- filePath = path.join(rootDir, testFile);
304
- // Default for execute tests, can be overridden
305
- mockEnsureCorrectEdit.mockImplementation(async (_, content, params) => {
306
- let occurrences = 0;
307
- if (params.old_string && content) {
308
- let index = content.indexOf(params.old_string);
309
- while (index !== -1) {
310
- occurrences++;
311
- index = content.indexOf(params.old_string, index + 1);
312
- }
313
- }
314
- else if (params.old_string === '') {
315
- occurrences = 0;
316
- }
317
- return { params, occurrences };
318
- });
319
- });
320
- it('should return error if params are invalid', async () => {
321
- const params = {
322
- file_path: 'relative.txt',
323
- old_string: 'old',
324
- new_string: 'new',
325
- };
326
- // Invalid params should throw during build
327
- expect(() => tool.build(params)).toThrow(/File path must be absolute/);
328
- });
329
- it('should edit an existing file and return diff with fileName', async () => {
330
- const initialContent = 'This is some old text.';
331
- const newContent = 'This is some new text.'; // old -> new
332
- fs.writeFileSync(filePath, initialContent, 'utf8');
333
- const params = {
334
- file_path: filePath,
335
- old_string: 'old',
336
- new_string: 'new',
337
- };
338
- // Specific mock for this test's execution path in calculateEdit
339
- // ensureCorrectEdit is NOT called by calculateEdit, only by shouldConfirmExecute
340
- // So, the default mockEnsureCorrectEdit should correctly return 1 occurrence for 'old' in initialContent
341
- // Simulate confirmation by setting shouldAlwaysEdit
342
- tool.shouldAlwaysEdit = true;
343
- const invocation = tool.build(params);
344
- const result = await invocation.execute(new AbortController().signal);
345
- tool.shouldAlwaysEdit = false; // Reset for other tests
346
- expect(result.llmContent).toMatch(/Successfully modified file/);
347
- expect(fs.readFileSync(filePath, 'utf8')).toBe(newContent);
348
- const display = result.returnDisplay;
349
- expect(display.fileDiff).toMatch(initialContent);
350
- expect(display.fileDiff).toMatch(newContent);
351
- expect(display.fileName).toBe(testFile);
352
- });
353
- it('should create a new file if old_string is empty and file does not exist, and return created message', async () => {
354
- const newFileName = 'brand_new_file.txt';
355
- const newFilePath = path.join(rootDir, newFileName);
356
- const fileContent = 'Content for the new file.';
357
- const params = {
358
- file_path: newFilePath,
359
- old_string: '',
360
- new_string: fileContent,
361
- };
362
- mockConfig.getApprovalMode.mockReturnValueOnce(ApprovalMode.AUTO_EDIT);
363
- const invocation = tool.build(params);
364
- const result = await invocation.execute(new AbortController().signal);
365
- expect(result.llmContent).toMatch(/Created new file/);
366
- expect(fs.existsSync(newFilePath)).toBe(true);
367
- expect(fs.readFileSync(newFilePath, 'utf8')).toBe(fileContent);
368
- expect(result.returnDisplay).toBe(`Created ${newFileName}`);
369
- });
370
- it('should return error if old_string is not found in file', async () => {
371
- fs.writeFileSync(filePath, 'Some content.', 'utf8');
372
- const params = {
373
- file_path: filePath,
374
- old_string: 'nonexistent',
375
- new_string: 'replacement',
376
- };
377
- // The default mockEnsureCorrectEdit will return 0 occurrences for 'nonexistent'
378
- const invocation = tool.build(params);
379
- const result = await invocation.execute(new AbortController().signal);
380
- expect(result.llmContent).toMatch(/0 occurrences found for old_string in/);
381
- expect(result.returnDisplay).toMatch(/Failed to edit, could not find the string to replace./);
382
- });
383
- it('should return error if multiple occurrences of old_string are found', async () => {
384
- fs.writeFileSync(filePath, 'multiple old old strings', 'utf8');
385
- const params = {
386
- file_path: filePath,
387
- old_string: 'old',
388
- new_string: 'new',
389
- };
390
- // The default mockEnsureCorrectEdit will return 2 occurrences for 'old'
391
- const invocation = tool.build(params);
392
- const result = await invocation.execute(new AbortController().signal);
393
- expect(result.llmContent).toMatch(/Expected 1 occurrence but found 2 for old_string in file/);
394
- expect(result.returnDisplay).toMatch(/Failed to edit, expected 1 occurrence but found 2/);
395
- });
396
- it('should successfully replace multiple occurrences when expected_replacements specified', async () => {
397
- fs.writeFileSync(filePath, 'old text old text old text', 'utf8');
398
- const params = {
399
- file_path: filePath,
400
- old_string: 'old',
401
- new_string: 'new',
402
- expected_replacements: 3,
403
- };
404
- // Simulate confirmation by setting shouldAlwaysEdit
405
- tool.shouldAlwaysEdit = true;
406
- const invocation = tool.build(params);
407
- const result = await invocation.execute(new AbortController().signal);
408
- tool.shouldAlwaysEdit = false; // Reset for other tests
409
- expect(result.llmContent).toMatch(/Successfully modified file/);
410
- expect(fs.readFileSync(filePath, 'utf8')).toBe('new text new text new text');
411
- const display = result.returnDisplay;
412
- expect(display.fileDiff).toMatch(/old text old text old text/);
413
- expect(display.fileDiff).toMatch(/new text new text new text/);
414
- expect(display.fileName).toBe(testFile);
415
- });
416
- it('should return error if expected_replacements does not match actual occurrences', async () => {
417
- fs.writeFileSync(filePath, 'old text old text', 'utf8');
418
- const params = {
419
- file_path: filePath,
420
- old_string: 'old',
421
- new_string: 'new',
422
- expected_replacements: 3, // Expecting 3 but only 2 exist
423
- };
424
- const invocation = tool.build(params);
425
- const result = await invocation.execute(new AbortController().signal);
426
- expect(result.llmContent).toMatch(/Expected 3 occurrences but found 2 for old_string in file/);
427
- expect(result.returnDisplay).toMatch(/Failed to edit, expected 3 occurrences but found 2/);
428
- });
429
- it('should return error if trying to create a file that already exists (empty old_string)', async () => {
430
- fs.writeFileSync(filePath, 'Existing content', 'utf8');
431
- const params = {
432
- file_path: filePath,
433
- old_string: '',
434
- new_string: 'new content',
435
- };
436
- const invocation = tool.build(params);
437
- const result = await invocation.execute(new AbortController().signal);
438
- expect(result.llmContent).toMatch(/File already exists, cannot create/);
439
- expect(result.returnDisplay).toMatch(/Attempted to create a file that already exists/);
440
- });
441
- it('should include modification message when proposed content is modified', async () => {
442
- const initialContent = 'This is some old text.';
443
- fs.writeFileSync(filePath, initialContent, 'utf8');
444
- const params = {
445
- file_path: filePath,
446
- old_string: 'old',
447
- new_string: 'new',
448
- modified_by_user: true,
449
- };
450
- mockConfig.getApprovalMode.mockReturnValueOnce(ApprovalMode.AUTO_EDIT);
451
- const invocation = tool.build(params);
452
- const result = await invocation.execute(new AbortController().signal);
453
- expect(result.llmContent).toMatch(/User modified the `new_string` content/);
454
- });
455
- it('should not include modification message when proposed content is not modified', async () => {
456
- const initialContent = 'This is some old text.';
457
- fs.writeFileSync(filePath, initialContent, 'utf8');
458
- const params = {
459
- file_path: filePath,
460
- old_string: 'old',
461
- new_string: 'new',
462
- modified_by_user: false,
463
- };
464
- mockConfig.getApprovalMode.mockReturnValueOnce(ApprovalMode.AUTO_EDIT);
465
- const invocation = tool.build(params);
466
- const result = await invocation.execute(new AbortController().signal);
467
- expect(result.llmContent).not.toMatch(/User modified the `new_string` content/);
468
- });
469
- it('should not include modification message when modified_by_user is not provided', async () => {
470
- const initialContent = 'This is some old text.';
471
- fs.writeFileSync(filePath, initialContent, 'utf8');
472
- const params = {
473
- file_path: filePath,
474
- old_string: 'old',
475
- new_string: 'new',
476
- };
477
- mockConfig.getApprovalMode.mockReturnValueOnce(ApprovalMode.AUTO_EDIT);
478
- const invocation = tool.build(params);
479
- const result = await invocation.execute(new AbortController().signal);
480
- expect(result.llmContent).not.toMatch(/User modified the `new_string` content/);
481
- });
482
- it('should return error if old_string and new_string are identical', async () => {
483
- const initialContent = 'This is some identical text.';
484
- fs.writeFileSync(filePath, initialContent, 'utf8');
485
- const params = {
486
- file_path: filePath,
487
- old_string: 'identical',
488
- new_string: 'identical',
489
- };
490
- const invocation = tool.build(params);
491
- const result = await invocation.execute(new AbortController().signal);
492
- expect(result.llmContent).toMatch(/No changes to apply/);
493
- expect(result.returnDisplay).toMatch(/No changes to apply/);
494
- });
495
- });
496
- describe('Error Scenarios', () => {
497
- const testFile = 'error_test.txt';
498
- let filePath;
499
- beforeEach(() => {
500
- filePath = path.join(rootDir, testFile);
501
- });
502
- it('should return FILE_NOT_FOUND error', async () => {
503
- const params = {
504
- file_path: filePath,
505
- old_string: 'any',
506
- new_string: 'new',
507
- };
508
- const invocation = tool.build(params);
509
- const result = await invocation.execute(new AbortController().signal);
510
- expect(result.error?.type).toBe(ToolErrorType.FILE_NOT_FOUND);
511
- });
512
- it('should return ATTEMPT_TO_CREATE_EXISTING_FILE error', async () => {
513
- fs.writeFileSync(filePath, 'existing content', 'utf8');
514
- const params = {
515
- file_path: filePath,
516
- old_string: '',
517
- new_string: 'new content',
518
- };
519
- const invocation = tool.build(params);
520
- const result = await invocation.execute(new AbortController().signal);
521
- expect(result.error?.type).toBe(ToolErrorType.ATTEMPT_TO_CREATE_EXISTING_FILE);
522
- });
523
- it('should return NO_OCCURRENCE_FOUND error', async () => {
524
- fs.writeFileSync(filePath, 'content', 'utf8');
525
- const params = {
526
- file_path: filePath,
527
- old_string: 'not-found',
528
- new_string: 'new',
529
- };
530
- const invocation = tool.build(params);
531
- const result = await invocation.execute(new AbortController().signal);
532
- expect(result.error?.type).toBe(ToolErrorType.EDIT_NO_OCCURRENCE_FOUND);
533
- });
534
- it('should return EXPECTED_OCCURRENCE_MISMATCH error', async () => {
535
- fs.writeFileSync(filePath, 'one one two', 'utf8');
536
- const params = {
537
- file_path: filePath,
538
- old_string: 'one',
539
- new_string: 'new',
540
- expected_replacements: 3,
541
- };
542
- const invocation = tool.build(params);
543
- const result = await invocation.execute(new AbortController().signal);
544
- expect(result.error?.type).toBe(ToolErrorType.EDIT_EXPECTED_OCCURRENCE_MISMATCH);
545
- });
546
- it('should return NO_CHANGE error', async () => {
547
- fs.writeFileSync(filePath, 'content', 'utf8');
548
- const params = {
549
- file_path: filePath,
550
- old_string: 'content',
551
- new_string: 'content',
552
- };
553
- const invocation = tool.build(params);
554
- const result = await invocation.execute(new AbortController().signal);
555
- expect(result.error?.type).toBe(ToolErrorType.EDIT_NO_CHANGE);
556
- });
557
- it('should return INVALID_PARAMETERS error for relative path', async () => {
558
- const params = {
559
- file_path: 'relative/path.txt',
560
- old_string: 'a',
561
- new_string: 'b',
562
- };
563
- // Invalid params should throw during build
564
- expect(() => tool.build(params)).toThrow(/File path must be absolute/);
565
- });
566
- it('should return FILE_WRITE_FAILURE on write error', async () => {
567
- fs.writeFileSync(filePath, 'content', 'utf8');
568
- // Make file readonly to trigger a write error
569
- fs.chmodSync(filePath, '444');
570
- const params = {
571
- file_path: filePath,
572
- old_string: 'content',
573
- new_string: 'new content',
574
- };
575
- const invocation = tool.build(params);
576
- const result = await invocation.execute(new AbortController().signal);
577
- expect(result.error?.type).toBe(ToolErrorType.FILE_WRITE_FAILURE);
578
- });
579
- });
580
- describe('getDescription', () => {
581
- it('should return "No file changes to..." if old_string and new_string are the same', () => {
582
- const testFileName = 'test.txt';
583
- const params = {
584
- file_path: path.join(rootDir, testFileName),
585
- old_string: 'identical_string',
586
- new_string: 'identical_string',
587
- };
588
- // shortenPath will be called internally, resulting in just the file name
589
- const invocation = tool.build(params);
590
- expect(invocation.getDescription()).toBe(`No file changes to ${testFileName}`);
591
- });
592
- it('should return a snippet of old and new strings if they are different', () => {
593
- const testFileName = 'test.txt';
594
- const params = {
595
- file_path: path.join(rootDir, testFileName),
596
- old_string: 'this is the old string value',
597
- new_string: 'this is the new string value',
598
- };
599
- // shortenPath will be called internally, resulting in just the file name
600
- // The snippets are truncated at 30 chars + '...'
601
- const invocation = tool.build(params);
602
- expect(invocation.getDescription()).toBe(`${testFileName}: this is the old string value => this is the new string value`);
603
- });
604
- it('should handle very short strings correctly in the description', () => {
605
- const testFileName = 'short.txt';
606
- const params = {
607
- file_path: path.join(rootDir, testFileName),
608
- old_string: 'old',
609
- new_string: 'new',
610
- };
611
- const invocation = tool.build(params);
612
- expect(invocation.getDescription()).toBe(`${testFileName}: old => new`);
613
- });
614
- it('should truncate long strings in the description', () => {
615
- const testFileName = 'long.txt';
616
- const params = {
617
- file_path: path.join(rootDir, testFileName),
618
- old_string: 'this is a very long old string that will definitely be truncated',
619
- new_string: 'this is a very long new string that will also be truncated',
620
- };
621
- const invocation = tool.build(params);
622
- expect(invocation.getDescription()).toBe(`${testFileName}: this is a very long old string... => this is a very long new string...`);
623
- });
624
- });
625
- describe('workspace boundary validation', () => {
626
- it('should validate paths are within workspace root', () => {
627
- const validPath = {
628
- file_path: path.join(rootDir, 'file.txt'),
629
- old_string: 'old',
630
- new_string: 'new',
631
- };
632
- // Valid params should not throw
633
- expect(() => tool.build(validPath)).not.toThrow();
634
- });
635
- it('should reject paths outside workspace root', () => {
636
- const invalidPath = {
637
- file_path: '/etc/passwd',
638
- old_string: 'root',
639
- new_string: 'hacked',
640
- };
641
- expect(() => tool.build(invalidPath)).toThrow(/File path must be within one of the workspace directories/);
642
- });
643
- });
644
- describe('IDE mode', () => {
645
- const testFile = 'edit_me.txt';
646
- let filePath;
647
- let ideClient;
648
- beforeEach(() => {
649
- filePath = path.join(rootDir, testFile);
650
- ideClient = {
651
- openDiff: vi.fn(),
652
- getConnectionStatus: vi.fn().mockReturnValue({
653
- status: IDEConnectionStatus.Connected,
654
- }),
655
- };
656
- mockConfig.getIdeMode = () => true;
657
- mockConfig.getIdeModeFeature = () => true;
658
- mockConfig.getIdeClient = () => ideClient;
659
- });
660
- it('should call ideClient.openDiff and update params on confirmation', async () => {
661
- const initialContent = 'some old content here';
662
- const newContent = 'some new content here';
663
- const modifiedContent = 'some modified content here';
664
- fs.writeFileSync(filePath, initialContent);
665
- const params = {
666
- file_path: filePath,
667
- old_string: 'old',
668
- new_string: 'new',
669
- };
670
- mockEnsureCorrectEdit.mockResolvedValueOnce({
671
- params: { ...params, old_string: 'old', new_string: 'new' },
672
- occurrences: 1,
673
- });
674
- ideClient.openDiff.mockResolvedValueOnce({
675
- status: 'accepted',
676
- content: modifiedContent,
677
- });
678
- const invocation = tool.build(params);
679
- const confirmation = await invocation.shouldConfirmExecute(new AbortController().signal);
680
- expect(ideClient.openDiff).toHaveBeenCalledWith(filePath, newContent);
681
- if (confirmation && 'onConfirm' in confirmation) {
682
- await confirmation.onConfirm(ToolConfirmationOutcome.ProceedOnce);
683
- }
684
- expect(params.old_string).toBe(initialContent);
685
- expect(params.new_string).toBe(modifiedContent);
686
- });
687
- });
688
- });
689
- //# sourceMappingURL=edit.test.js.map