@vybestack/llxprt-code-core 0.1.19-alpha → 0.1.19-gamma

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