@vybestack/llxprt-code-core 0.1.14 → 0.1.16-hotfix1

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 (465) hide show
  1. package/README.md +90 -2
  2. package/dist/src/code_assist/converter.d.ts +2 -1
  3. package/dist/src/code_assist/converter.js +2 -1
  4. package/dist/src/code_assist/converter.js.map +1 -1
  5. package/dist/src/code_assist/converter.test.js +13 -10
  6. package/dist/src/code_assist/converter.test.js.map +1 -1
  7. package/dist/src/code_assist/oauth2.test.d.ts +1 -1
  8. package/dist/src/code_assist/oauth2.test.js +15 -15
  9. package/dist/src/code_assist/oauth2.test.js.map +1 -1
  10. package/dist/src/code_assist/server.d.ts +2 -2
  11. package/dist/src/code_assist/server.js +4 -4
  12. package/dist/src/code_assist/server.js.map +1 -1
  13. package/dist/src/code_assist/server.test.js +9 -9
  14. package/dist/src/code_assist/server.test.js.map +1 -1
  15. package/dist/src/code_assist/setup.js +1 -1
  16. package/dist/src/code_assist/setup.js.map +1 -1
  17. package/dist/src/code_assist/setup.test.js +2 -2
  18. package/dist/src/code_assist/setup.test.js.map +1 -1
  19. package/dist/src/config/config.d.ts +37 -5
  20. package/dist/src/config/config.js +85 -15
  21. package/dist/src/config/config.js.map +1 -1
  22. package/dist/src/config/config.test.js +33 -0
  23. package/dist/src/config/config.test.js.map +1 -1
  24. package/dist/src/config/flashFallback.test.js +23 -47
  25. package/dist/src/config/flashFallback.test.js.map +1 -1
  26. package/dist/src/config/models.d.ts +1 -0
  27. package/dist/src/config/models.js +1 -0
  28. package/dist/src/config/models.js.map +1 -1
  29. package/dist/src/config/profileManager.d.ts +42 -0
  30. package/dist/src/config/profileManager.js +114 -0
  31. package/dist/src/config/profileManager.js.map +1 -0
  32. package/dist/src/core/client.d.ts +15 -1
  33. package/dist/src/core/client.js +161 -45
  34. package/dist/src/core/client.js.map +1 -1
  35. package/dist/src/core/client.test.js +291 -42
  36. package/dist/src/core/client.test.js.map +1 -1
  37. package/dist/src/core/contentGenerator.d.ts +2 -2
  38. package/dist/src/core/contentGenerator.js +2 -7
  39. package/dist/src/core/contentGenerator.js.map +1 -1
  40. package/dist/src/core/contentGenerator.test.js +6 -2
  41. package/dist/src/core/contentGenerator.test.js.map +1 -1
  42. package/dist/src/core/coreToolScheduler.d.ts +1 -3
  43. package/dist/src/core/coreToolScheduler.js +48 -19
  44. package/dist/src/core/coreToolScheduler.js.map +1 -1
  45. package/dist/src/core/coreToolScheduler.test.js +90 -18
  46. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  47. package/dist/src/core/geminiChat.js +37 -2
  48. package/dist/src/core/geminiChat.js.map +1 -1
  49. package/dist/src/core/geminiChat.test.js +2 -2
  50. package/dist/src/core/geminiChat.test.js.map +1 -1
  51. package/dist/src/core/googleGenAIWrapper.d.ts +21 -0
  52. package/dist/src/core/googleGenAIWrapper.js +36 -0
  53. package/dist/src/core/googleGenAIWrapper.js.map +1 -0
  54. package/dist/src/core/googleGenAIWrapper.test.d.ts +6 -0
  55. package/dist/src/core/googleGenAIWrapper.test.js +104 -0
  56. package/dist/src/core/googleGenAIWrapper.test.js.map +1 -0
  57. package/dist/src/core/logger.d.ts +1 -0
  58. package/dist/src/core/logger.js +22 -8
  59. package/dist/src/core/logger.js.map +1 -1
  60. package/dist/src/core/logger.test.js +60 -9
  61. package/dist/src/core/logger.test.js.map +1 -1
  62. package/dist/src/core/nonInteractiveToolExecutor.js +19 -4
  63. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
  64. package/dist/src/core/nonInteractiveToolExecutor.test.js +8 -3
  65. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  66. package/dist/src/core/prompts-async.test.d.ts +6 -0
  67. package/dist/src/core/prompts-async.test.js +115 -0
  68. package/dist/src/core/prompts-async.test.js.map +1 -0
  69. package/dist/src/core/prompts.d.ts +8 -1
  70. package/dist/src/core/prompts.js +97 -377
  71. package/dist/src/core/prompts.js.map +1 -1
  72. package/dist/src/core/prompts.test.js +46 -192
  73. package/dist/src/core/prompts.test.js.map +1 -1
  74. package/dist/src/core/tokenLimits.d.ts +1 -1
  75. package/dist/src/core/tokenLimits.js +6 -1
  76. package/dist/src/core/tokenLimits.js.map +1 -1
  77. package/dist/src/core/turn.d.ts +5 -1
  78. package/dist/src/core/turn.js +7 -2
  79. package/dist/src/core/turn.js.map +1 -1
  80. package/dist/src/core/turn.test.js +2 -2
  81. package/dist/src/core/turn.test.js.map +1 -1
  82. package/dist/src/ide/detect-ide.d.ts +10 -0
  83. package/dist/src/ide/detect-ide.js +24 -0
  84. package/dist/src/ide/detect-ide.js.map +1 -0
  85. package/dist/src/ide/ide-client.d.ts +19 -7
  86. package/dist/src/ide/ide-client.js +110 -37
  87. package/dist/src/ide/ide-client.js.map +1 -1
  88. package/dist/src/ide/ide-installer.d.ts +15 -0
  89. package/dist/src/ide/ide-installer.js +111 -0
  90. package/dist/src/ide/ide-installer.js.map +1 -0
  91. package/dist/src/ide/ide-installer.test.d.ts +6 -0
  92. package/dist/src/ide/ide-installer.test.js +78 -0
  93. package/dist/src/ide/ide-installer.test.js.map +1 -0
  94. package/dist/src/ide/ideContext.d.ts +212 -107
  95. package/dist/src/ide/ideContext.js +45 -44
  96. package/dist/src/ide/ideContext.js.map +1 -1
  97. package/dist/src/ide/ideContext.test.js +254 -100
  98. package/dist/src/ide/ideContext.test.js.map +1 -1
  99. package/dist/src/index.d.ts +16 -0
  100. package/dist/src/index.js +20 -0
  101. package/dist/src/index.js.map +1 -1
  102. package/dist/src/{providers/IProviderConfig.js → integration-tests/todo-system.test.d.ts} +0 -1
  103. package/dist/src/integration-tests/todo-system.test.js +610 -0
  104. package/dist/src/integration-tests/todo-system.test.js.map +1 -0
  105. package/dist/src/mcp/oauth-provider.d.ts +5 -1
  106. package/dist/src/mcp/oauth-provider.js +39 -14
  107. package/dist/src/mcp/oauth-provider.js.map +1 -1
  108. package/dist/src/mcp/oauth-provider.test.js +11 -10
  109. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  110. package/dist/src/mcp/oauth-token-storage.d.ts +3 -1
  111. package/dist/src/mcp/oauth-token-storage.js +3 -1
  112. package/dist/src/mcp/oauth-token-storage.js.map +1 -1
  113. package/dist/src/mcp/oauth-utils.js +14 -6
  114. package/dist/src/mcp/oauth-utils.js.map +1 -1
  115. package/dist/src/mcp/oauth-utils.test.js +1 -1
  116. package/dist/src/mcp/oauth-utils.test.js.map +1 -1
  117. package/dist/src/parsers/TextToolCallParser.d.ts +1 -0
  118. package/dist/src/parsers/TextToolCallParser.js +45 -3
  119. package/dist/src/parsers/TextToolCallParser.js.map +1 -1
  120. package/dist/src/parsers/TextToolCallParser.multibyte.test.d.ts +1 -0
  121. package/dist/src/parsers/TextToolCallParser.multibyte.test.js +42 -0
  122. package/dist/src/parsers/TextToolCallParser.multibyte.test.js.map +1 -0
  123. package/dist/src/prompt-config/TemplateEngine.d.ts +35 -0
  124. package/dist/src/prompt-config/TemplateEngine.js +149 -0
  125. package/dist/src/prompt-config/TemplateEngine.js.map +1 -0
  126. package/dist/src/prompt-config/TemplateEngine.test.d.ts +1 -0
  127. package/dist/src/prompt-config/TemplateEngine.test.js +494 -0
  128. package/dist/src/prompt-config/TemplateEngine.test.js.map +1 -0
  129. package/dist/src/prompt-config/defaults/compression.md +58 -0
  130. package/dist/src/prompt-config/defaults/core-defaults.d.ts +5 -0
  131. package/dist/src/prompt-config/defaults/core-defaults.js +332 -0
  132. package/dist/src/prompt-config/defaults/core-defaults.js.map +1 -0
  133. package/dist/src/prompt-config/defaults/core.md +267 -0
  134. package/dist/src/prompt-config/defaults/env/git-repository.md +15 -0
  135. package/dist/src/prompt-config/defaults/env/ide-mode.md +3 -0
  136. package/dist/src/prompt-config/defaults/env/macos-seatbelt.md +3 -0
  137. package/dist/src/prompt-config/defaults/env/outside-of-sandbox.md +3 -0
  138. package/dist/src/prompt-config/defaults/env/sandbox.md +3 -0
  139. package/dist/src/prompt-config/defaults/index.d.ts +14 -0
  140. package/dist/src/prompt-config/defaults/index.js +21 -0
  141. package/dist/src/prompt-config/defaults/index.js.map +1 -0
  142. package/dist/src/prompt-config/defaults/provider-defaults.d.ts +5 -0
  143. package/dist/src/prompt-config/defaults/provider-defaults.js +26 -0
  144. package/dist/src/prompt-config/defaults/provider-defaults.js.map +1 -0
  145. package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +10 -0
  146. package/dist/src/prompt-config/defaults/service-defaults.d.ts +5 -0
  147. package/dist/src/prompt-config/defaults/service-defaults.js +52 -0
  148. package/dist/src/prompt-config/defaults/service-defaults.js.map +1 -0
  149. package/dist/src/prompt-config/defaults/tool-defaults.d.ts +5 -0
  150. package/dist/src/prompt-config/defaults/tool-defaults.js +81 -0
  151. package/dist/src/prompt-config/defaults/tool-defaults.js.map +1 -0
  152. package/dist/src/prompt-config/defaults/tools/edit.md +2 -0
  153. package/dist/src/prompt-config/defaults/tools/glob.md +2 -0
  154. package/dist/src/prompt-config/defaults/tools/grep.md +2 -0
  155. package/dist/src/prompt-config/defaults/tools/ls.md +1 -0
  156. package/dist/src/prompt-config/defaults/tools/memory.md +1 -0
  157. package/dist/src/prompt-config/defaults/tools/read-file.md +4 -0
  158. package/dist/src/prompt-config/defaults/tools/read-many-files.md +2 -0
  159. package/dist/src/prompt-config/defaults/tools/shell.md +5 -0
  160. package/dist/src/prompt-config/defaults/tools/todo-read.md +3 -0
  161. package/dist/src/prompt-config/defaults/tools/todo-write.md +50 -0
  162. package/dist/src/prompt-config/defaults/tools/web-fetch.md +3 -0
  163. package/dist/src/prompt-config/defaults/tools/web-search.md +3 -0
  164. package/dist/src/prompt-config/defaults/tools/write-file.md +4 -0
  165. package/dist/src/prompt-config/index.d.ts +16 -0
  166. package/dist/src/prompt-config/index.js +11 -0
  167. package/dist/src/prompt-config/index.js.map +1 -0
  168. package/dist/src/prompt-config/prompt-cache.d.ts +72 -0
  169. package/dist/src/prompt-config/prompt-cache.js +271 -0
  170. package/dist/src/prompt-config/prompt-cache.js.map +1 -0
  171. package/dist/src/prompt-config/prompt-cache.test.d.ts +6 -0
  172. package/dist/src/prompt-config/prompt-cache.test.js +437 -0
  173. package/dist/src/prompt-config/prompt-cache.test.js.map +1 -0
  174. package/dist/src/prompt-config/prompt-installer.d.ts +118 -0
  175. package/dist/src/prompt-config/prompt-installer.js +723 -0
  176. package/dist/src/prompt-config/prompt-installer.js.map +1 -0
  177. package/dist/src/prompt-config/prompt-installer.test.d.ts +7 -0
  178. package/dist/src/prompt-config/prompt-installer.test.js +503 -0
  179. package/dist/src/prompt-config/prompt-installer.test.js.map +1 -0
  180. package/dist/src/prompt-config/prompt-loader.d.ts +49 -0
  181. package/dist/src/prompt-config/prompt-loader.js +331 -0
  182. package/dist/src/prompt-config/prompt-loader.js.map +1 -0
  183. package/dist/src/prompt-config/prompt-loader.test.d.ts +5 -0
  184. package/dist/src/prompt-config/prompt-loader.test.js +413 -0
  185. package/dist/src/prompt-config/prompt-loader.test.js.map +1 -0
  186. package/dist/src/prompt-config/prompt-resolver.d.ts +74 -0
  187. package/dist/src/prompt-config/prompt-resolver.js +600 -0
  188. package/dist/src/prompt-config/prompt-resolver.js.map +1 -0
  189. package/dist/src/prompt-config/prompt-resolver.test.d.ts +1 -0
  190. package/dist/src/prompt-config/prompt-resolver.test.js +529 -0
  191. package/dist/src/prompt-config/prompt-resolver.test.js.map +1 -0
  192. package/dist/src/prompt-config/prompt-service.d.ts +108 -0
  193. package/dist/src/prompt-config/prompt-service.js +435 -0
  194. package/dist/src/prompt-config/prompt-service.js.map +1 -0
  195. package/dist/src/prompt-config/prompt-service.test.d.ts +1 -0
  196. package/dist/src/prompt-config/prompt-service.test.js +811 -0
  197. package/dist/src/prompt-config/prompt-service.test.js.map +1 -0
  198. package/dist/src/prompt-config/types.d.ts +30 -0
  199. package/dist/src/prompt-config/types.js +10 -0
  200. package/dist/src/prompt-config/types.js.map +1 -0
  201. package/dist/src/prompts/mcp-prompts.d.ts +8 -0
  202. package/dist/src/prompts/mcp-prompts.js +13 -0
  203. package/dist/src/prompts/mcp-prompts.js.map +1 -0
  204. package/dist/src/prompts/prompt-registry.d.ts +26 -0
  205. package/dist/src/prompts/prompt-registry.js +47 -0
  206. package/dist/src/prompts/prompt-registry.js.map +1 -0
  207. package/dist/src/providers/IProvider.d.ts +10 -0
  208. package/dist/src/providers/adapters/GeminiCompatibleWrapper.js +24 -9
  209. package/dist/src/providers/adapters/GeminiCompatibleWrapper.js.map +1 -1
  210. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js +1 -1
  211. package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js.map +1 -1
  212. package/dist/src/providers/anthropic/AnthropicProvider.d.ts +14 -1
  213. package/dist/src/providers/anthropic/AnthropicProvider.js +28 -2
  214. package/dist/src/providers/anthropic/AnthropicProvider.js.map +1 -1
  215. package/dist/src/providers/anthropic/AnthropicProvider.modelParams.test.d.ts +1 -0
  216. package/dist/src/providers/anthropic/AnthropicProvider.modelParams.test.js +48 -0
  217. package/dist/src/providers/anthropic/AnthropicProvider.modelParams.test.js.map +1 -0
  218. package/dist/src/providers/anthropic/AnthropicProvider.test.js +2 -1
  219. package/dist/src/providers/anthropic/AnthropicProvider.test.js.map +1 -1
  220. package/dist/src/providers/gemini/GeminiProvider.d.ts +11 -2
  221. package/dist/src/providers/gemini/GeminiProvider.integration.test.js +1 -1
  222. package/dist/src/providers/gemini/GeminiProvider.js +42 -25
  223. package/dist/src/providers/gemini/GeminiProvider.js.map +1 -1
  224. package/dist/src/providers/openai/OpenAIProvider.d.ts +11 -0
  225. package/dist/src/providers/openai/OpenAIProvider.js +141 -24
  226. package/dist/src/providers/openai/OpenAIProvider.js.map +1 -1
  227. package/dist/src/providers/openai/OpenAIProvider.responses.test.js +27 -3
  228. package/dist/src/providers/openai/OpenAIProvider.responses.test.js.map +1 -1
  229. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js +2 -1
  230. package/dist/src/providers/openai/OpenAIProvider.shouldUseResponses.test.js.map +1 -1
  231. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js +1 -1
  232. package/dist/src/providers/openai/OpenAIProvider.stateful.integration.test.js.map +1 -1
  233. package/dist/src/providers/openai/OpenAIProvider.test.js +307 -7
  234. package/dist/src/providers/openai/OpenAIProvider.test.js.map +1 -1
  235. package/dist/src/providers/openai/buildResponsesRequest.js +19 -2
  236. package/dist/src/providers/openai/buildResponsesRequest.js.map +1 -1
  237. package/dist/src/providers/test-utils/providerTestConfig.d.ts +21 -0
  238. package/dist/src/providers/test-utils/providerTestConfig.js +23 -0
  239. package/dist/src/providers/test-utils/providerTestConfig.js.map +1 -0
  240. package/dist/src/providers/types/IProviderConfig.d.ts +6 -0
  241. package/dist/src/services/complexity-analyzer.d.ts +92 -0
  242. package/dist/src/services/complexity-analyzer.js +287 -0
  243. package/dist/src/services/complexity-analyzer.js.map +1 -0
  244. package/dist/src/services/fileDiscoveryService.test.js +101 -60
  245. package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
  246. package/dist/src/services/gitService.test.d.ts +1 -1
  247. package/dist/src/services/gitService.test.js +65 -102
  248. package/dist/src/services/gitService.test.js.map +1 -1
  249. package/dist/src/services/index.d.ts +9 -0
  250. package/dist/src/services/index.js +8 -0
  251. package/dist/src/services/index.js.map +1 -0
  252. package/dist/src/services/loopDetectionService.d.ts +12 -0
  253. package/dist/src/services/loopDetectionService.js +62 -12
  254. package/dist/src/services/loopDetectionService.js.map +1 -1
  255. package/dist/src/services/loopDetectionService.test.js +90 -11
  256. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  257. package/dist/src/services/shellExecutionService.d.ts +34 -0
  258. package/dist/src/services/shellExecutionService.js +121 -0
  259. package/dist/src/services/shellExecutionService.js.map +1 -0
  260. package/dist/src/services/shellExecutionService.multibyte.test.d.ts +6 -0
  261. package/dist/src/services/shellExecutionService.multibyte.test.js +72 -0
  262. package/dist/src/services/shellExecutionService.multibyte.test.js.map +1 -0
  263. package/dist/src/services/shellExecutionService.test.d.ts +6 -0
  264. package/dist/src/services/shellExecutionService.test.js +264 -0
  265. package/dist/src/services/shellExecutionService.test.js.map +1 -0
  266. package/dist/src/services/shellExecutionService.windows.multibyte.test.d.ts +6 -0
  267. package/dist/src/services/shellExecutionService.windows.multibyte.test.js +98 -0
  268. package/dist/src/services/shellExecutionService.windows.multibyte.test.js.map +1 -0
  269. package/dist/src/services/shellExecutionService.windows.test.d.ts +6 -0
  270. package/dist/src/services/shellExecutionService.windows.test.js +79 -0
  271. package/dist/src/services/shellExecutionService.windows.test.js.map +1 -0
  272. package/dist/src/services/todo-reminder-service.d.ts +42 -0
  273. package/dist/src/services/todo-reminder-service.js +77 -0
  274. package/dist/src/services/todo-reminder-service.js.map +1 -0
  275. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +4 -2
  276. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +81 -34
  277. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  278. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +6 -1
  279. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +19 -0
  280. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  281. package/dist/src/telemetry/constants.d.ts +2 -1
  282. package/dist/src/telemetry/constants.js +2 -1
  283. package/dist/src/telemetry/constants.js.map +1 -1
  284. package/dist/src/telemetry/file-exporters.d.ts +2 -2
  285. package/dist/src/telemetry/file-exporters.js +47 -20
  286. package/dist/src/telemetry/file-exporters.js.map +1 -1
  287. package/dist/src/telemetry/index.d.ts +2 -2
  288. package/dist/src/telemetry/index.js +2 -2
  289. package/dist/src/telemetry/index.js.map +1 -1
  290. package/dist/src/telemetry/loggers.d.ts +3 -2
  291. package/dist/src/telemetry/loggers.js +30 -6
  292. package/dist/src/telemetry/loggers.js.map +1 -1
  293. package/dist/src/telemetry/loggers.test.circular.js +2 -0
  294. package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
  295. package/dist/src/telemetry/loggers.test.js +13 -3
  296. package/dist/src/telemetry/loggers.test.js.map +1 -1
  297. package/dist/src/telemetry/sdk.d.ts +1 -1
  298. package/dist/src/telemetry/sdk.js +71 -73
  299. package/dist/src/telemetry/sdk.js.map +1 -1
  300. package/dist/src/telemetry/telemetry.test.js +7 -5
  301. package/dist/src/telemetry/telemetry.test.js.map +1 -1
  302. package/dist/src/telemetry/types.d.ts +19 -4
  303. package/dist/src/telemetry/types.js +30 -4
  304. package/dist/src/telemetry/types.js.map +1 -1
  305. package/dist/src/telemetry/uiTelemetry.test.js +3 -0
  306. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  307. package/dist/src/test-utils/mockWorkspaceContext.d.ts +13 -0
  308. package/dist/src/test-utils/mockWorkspaceContext.js +24 -0
  309. package/dist/src/test-utils/mockWorkspaceContext.js.map +1 -0
  310. package/dist/src/tools/edit.js +29 -4
  311. package/dist/src/tools/edit.js.map +1 -1
  312. package/dist/src/tools/edit.test.js +104 -1
  313. package/dist/src/tools/edit.test.js.map +1 -1
  314. package/dist/src/tools/glob.js +53 -17
  315. package/dist/src/tools/glob.js.map +1 -1
  316. package/dist/src/tools/glob.test.js +32 -6
  317. package/dist/src/tools/glob.test.js.map +1 -1
  318. package/dist/src/tools/grep.d.ts +1 -1
  319. package/dist/src/tools/grep.js +81 -29
  320. package/dist/src/tools/grep.js.map +1 -1
  321. package/dist/src/tools/grep.test.js +76 -9
  322. package/dist/src/tools/grep.test.js.map +1 -1
  323. package/dist/src/tools/ls.js +4 -3
  324. package/dist/src/tools/ls.js.map +1 -1
  325. package/dist/src/tools/ls.test.d.ts +6 -0
  326. package/dist/src/tools/ls.test.js +356 -0
  327. package/dist/src/tools/ls.test.js.map +1 -0
  328. package/dist/src/tools/mcp-client.d.ts +26 -2
  329. package/dist/src/tools/mcp-client.js +96 -32
  330. package/dist/src/tools/mcp-client.js.map +1 -1
  331. package/dist/src/tools/mcp-client.test.js +87 -1
  332. package/dist/src/tools/mcp-client.test.js.map +1 -1
  333. package/dist/src/tools/memoryTool.d.ts +17 -2
  334. package/dist/src/tools/memoryTool.js +130 -13
  335. package/dist/src/tools/memoryTool.js.map +1 -1
  336. package/dist/src/tools/memoryTool.test.js +88 -3
  337. package/dist/src/tools/memoryTool.test.js.map +1 -1
  338. package/dist/src/tools/modifiable-tool.test.js +51 -62
  339. package/dist/src/tools/modifiable-tool.test.js.map +1 -1
  340. package/dist/src/tools/read-file.js +8 -6
  341. package/dist/src/tools/read-file.js.map +1 -1
  342. package/dist/src/tools/read-file.test.js +30 -2
  343. package/dist/src/tools/read-file.test.js.map +1 -1
  344. package/dist/src/tools/read-many-files.js +22 -12
  345. package/dist/src/tools/read-many-files.js.map +1 -1
  346. package/dist/src/tools/read-many-files.test.js +35 -2
  347. package/dist/src/tools/read-many-files.test.js.map +1 -1
  348. package/dist/src/tools/shell.d.ts +8 -3
  349. package/dist/src/tools/shell.js +185 -114
  350. package/dist/src/tools/shell.js.map +1 -1
  351. package/dist/src/tools/shell.multibyte.test.d.ts +6 -0
  352. package/dist/src/tools/shell.multibyte.test.js +74 -0
  353. package/dist/src/tools/shell.multibyte.test.js.map +1 -0
  354. package/dist/src/tools/shell.test.d.ts +1 -1
  355. package/dist/src/tools/shell.test.js +323 -138
  356. package/dist/src/tools/shell.test.js.map +1 -1
  357. package/dist/src/tools/todo-read.d.ts +4 -1
  358. package/dist/src/tools/todo-read.js +136 -20
  359. package/dist/src/tools/todo-read.js.map +1 -1
  360. package/dist/src/tools/todo-read.test.js +10 -6
  361. package/dist/src/tools/todo-read.test.js.map +1 -1
  362. package/dist/src/tools/todo-schemas.d.ts +4 -4
  363. package/dist/src/tools/todo-write.d.ts +3 -0
  364. package/dist/src/tools/todo-write.js +96 -9
  365. package/dist/src/tools/todo-write.js.map +1 -1
  366. package/dist/src/tools/todo-write.test.js +17 -13
  367. package/dist/src/tools/todo-write.test.js.map +1 -1
  368. package/dist/src/tools/tool-context.d.ts +14 -0
  369. package/dist/src/tools/tool-context.js +7 -0
  370. package/dist/src/tools/tool-context.js.map +1 -0
  371. package/dist/src/tools/tool-error.d.ts +22 -0
  372. package/dist/src/tools/tool-error.js +27 -0
  373. package/dist/src/tools/tool-error.js.map +1 -0
  374. package/dist/src/tools/tool-registry.d.ts +4 -1
  375. package/dist/src/tools/tool-registry.js +14 -5
  376. package/dist/src/tools/tool-registry.js.map +1 -1
  377. package/dist/src/tools/tool-registry.test.js +10 -2
  378. package/dist/src/tools/tool-registry.test.js.map +1 -1
  379. package/dist/src/tools/tools.d.ts +16 -1
  380. package/dist/src/tools/tools.js +2 -0
  381. package/dist/src/tools/tools.js.map +1 -1
  382. package/dist/src/tools/web-fetch.js +18 -4
  383. package/dist/src/tools/web-fetch.js.map +1 -1
  384. package/dist/src/tools/write-file.js +5 -3
  385. package/dist/src/tools/write-file.js.map +1 -1
  386. package/dist/src/tools/write-file.test.js +36 -2
  387. package/dist/src/tools/write-file.test.js.map +1 -1
  388. package/dist/src/types/modelParams.d.ts +62 -0
  389. package/dist/src/types/modelParams.js +7 -0
  390. package/dist/src/types/modelParams.js.map +1 -0
  391. package/dist/src/utils/bfsFileSearch.js +51 -27
  392. package/dist/src/utils/bfsFileSearch.js.map +1 -1
  393. package/dist/src/utils/bfsFileSearch.test.js +59 -0
  394. package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
  395. package/dist/src/utils/editCorrector.js +2 -2
  396. package/dist/src/utils/editCorrector.js.map +1 -1
  397. package/dist/src/utils/editor.d.ts +1 -1
  398. package/dist/src/utils/editor.js +9 -0
  399. package/dist/src/utils/editor.js.map +1 -1
  400. package/dist/src/utils/editor.test.js +21 -1
  401. package/dist/src/utils/editor.test.js.map +1 -1
  402. package/dist/src/utils/fileUtils.js +12 -1
  403. package/dist/src/utils/fileUtils.js.map +1 -1
  404. package/dist/src/utils/fileUtils.test.js +29 -1
  405. package/dist/src/utils/fileUtils.test.js.map +1 -1
  406. package/dist/src/utils/flashFallback.integration.test.js +8 -0
  407. package/dist/src/utils/flashFallback.integration.test.js.map +1 -1
  408. package/dist/src/utils/formatters.d.ts +6 -0
  409. package/dist/src/utils/formatters.js +16 -0
  410. package/dist/src/utils/formatters.js.map +1 -0
  411. package/dist/src/utils/memoryDiscovery.d.ts +1 -1
  412. package/dist/src/utils/memoryDiscovery.js +61 -73
  413. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  414. package/dist/src/utils/memoryDiscovery.test.js +4 -3
  415. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  416. package/dist/src/utils/memoryImportProcessor.d.ts +19 -12
  417. package/dist/src/utils/memoryImportProcessor.js +241 -82
  418. package/dist/src/utils/memoryImportProcessor.js.map +1 -1
  419. package/dist/src/utils/memoryImportProcessor.test.js +595 -50
  420. package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
  421. package/dist/src/utils/nextSpeakerChecker.js +12 -27
  422. package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
  423. package/dist/src/utils/nextSpeakerChecker.test.js +8 -4
  424. package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
  425. package/dist/src/utils/retry.d.ts +3 -0
  426. package/dist/src/utils/retry.js.map +1 -1
  427. package/dist/src/utils/retry.test.js.map +1 -1
  428. package/dist/src/utils/sanitization.d.ts +20 -0
  429. package/dist/src/utils/sanitization.js +66 -0
  430. package/dist/src/utils/sanitization.js.map +1 -0
  431. package/dist/src/utils/sanitization.test.d.ts +6 -0
  432. package/dist/src/utils/sanitization.test.js +81 -0
  433. package/dist/src/utils/sanitization.test.js.map +1 -0
  434. package/dist/src/utils/secure-browser-launcher.d.ts +23 -0
  435. package/dist/src/utils/secure-browser-launcher.js +164 -0
  436. package/dist/src/utils/secure-browser-launcher.js.map +1 -0
  437. package/dist/src/utils/secure-browser-launcher.test.d.ts +6 -0
  438. package/dist/src/utils/secure-browser-launcher.test.js +149 -0
  439. package/dist/src/utils/secure-browser-launcher.test.js.map +1 -0
  440. package/dist/src/utils/shell-utils.d.ts +37 -3
  441. package/dist/src/utils/shell-utils.js +110 -47
  442. package/dist/src/utils/shell-utils.js.map +1 -1
  443. package/dist/src/utils/shell-utils.test.js +146 -396
  444. package/dist/src/utils/shell-utils.test.js.map +1 -1
  445. package/dist/src/utils/summarizer.js +2 -2
  446. package/dist/src/utils/summarizer.js.map +1 -1
  447. package/dist/src/utils/textUtils.d.ts +13 -0
  448. package/dist/src/utils/textUtils.js +28 -0
  449. package/dist/src/utils/textUtils.js.map +1 -0
  450. package/dist/src/utils/unicodeUtils.d.ts +44 -0
  451. package/dist/src/utils/unicodeUtils.js +93 -0
  452. package/dist/src/utils/unicodeUtils.js.map +1 -0
  453. package/dist/src/utils/unicodeUtils.test.d.ts +6 -0
  454. package/dist/src/utils/unicodeUtils.test.js +120 -0
  455. package/dist/src/utils/unicodeUtils.test.js.map +1 -0
  456. package/dist/src/utils/workspaceContext.d.ts +47 -0
  457. package/dist/src/utils/workspaceContext.js +106 -0
  458. package/dist/src/utils/workspaceContext.js.map +1 -0
  459. package/dist/src/utils/workspaceContext.test.d.ts +6 -0
  460. package/dist/src/utils/workspaceContext.test.js +209 -0
  461. package/dist/src/utils/workspaceContext.test.js.map +1 -0
  462. package/package.json +3 -2
  463. package/dist/src/providers/IProviderConfig.d.ts +0 -31
  464. package/dist/src/providers/IProviderConfig.js.map +0 -1
  465. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,164 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { execFile } from 'node:child_process';
7
+ import { promisify } from 'node:util';
8
+ import { platform } from 'node:os';
9
+ import { URL } from 'node:url';
10
+ const execFileAsync = promisify(execFile);
11
+ /**
12
+ * Validates that a URL is safe to open in a browser.
13
+ * Only allows HTTP and HTTPS URLs to prevent command injection.
14
+ *
15
+ * @param url The URL to validate
16
+ * @throws Error if the URL is invalid or uses an unsafe protocol
17
+ */
18
+ function validateUrl(url) {
19
+ let parsedUrl;
20
+ try {
21
+ parsedUrl = new URL(url);
22
+ }
23
+ catch (_error) {
24
+ throw new Error(`Invalid URL: ${url}`);
25
+ }
26
+ // Only allow HTTP and HTTPS protocols
27
+ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
28
+ throw new Error(`Unsafe protocol: ${parsedUrl.protocol}. Only HTTP and HTTPS are allowed.`);
29
+ }
30
+ // Additional validation: ensure no newlines or control characters
31
+ // eslint-disable-next-line no-control-regex
32
+ if (/[\r\n\x00-\x1f]/.test(url)) {
33
+ throw new Error('URL contains invalid characters');
34
+ }
35
+ }
36
+ /**
37
+ * Opens a URL in the default browser using platform-specific commands.
38
+ * This implementation avoids shell injection vulnerabilities by:
39
+ * 1. Validating the URL to ensure it's HTTP/HTTPS only
40
+ * 2. Using execFile instead of exec to avoid shell interpretation
41
+ * 3. Passing the URL as an argument rather than constructing a command string
42
+ *
43
+ * @param url The URL to open
44
+ * @throws Error if the URL is invalid or if opening the browser fails
45
+ */
46
+ export async function openBrowserSecurely(url) {
47
+ // Validate the URL first
48
+ validateUrl(url);
49
+ const platformName = platform();
50
+ let command;
51
+ let args;
52
+ switch (platformName) {
53
+ case 'darwin':
54
+ // macOS
55
+ command = 'open';
56
+ args = [url];
57
+ break;
58
+ case 'win32':
59
+ // Windows - use PowerShell with Start-Process
60
+ // This avoids the cmd.exe shell which is vulnerable to injection
61
+ command = 'powershell.exe';
62
+ args = [
63
+ '-NoProfile',
64
+ '-NonInteractive',
65
+ '-WindowStyle',
66
+ 'Hidden',
67
+ '-Command',
68
+ `Start-Process '${url.replace(/'/g, "''")}'`,
69
+ ];
70
+ break;
71
+ case 'linux':
72
+ case 'freebsd':
73
+ case 'openbsd':
74
+ // Linux and BSD variants
75
+ // Try xdg-open first, fall back to other options
76
+ command = 'xdg-open';
77
+ args = [url];
78
+ break;
79
+ default:
80
+ throw new Error(`Unsupported platform: ${platformName}`);
81
+ }
82
+ const options = {
83
+ // Don't inherit parent's environment to avoid potential issues
84
+ env: {
85
+ ...process.env,
86
+ // Ensure we're not in a shell that might interpret special characters
87
+ SHELL: undefined,
88
+ },
89
+ // Detach the browser process so it doesn't block
90
+ detached: true,
91
+ stdio: 'ignore',
92
+ };
93
+ try {
94
+ await execFileAsync(command, args, options);
95
+ }
96
+ catch (error) {
97
+ // For Linux, try fallback commands if xdg-open fails
98
+ if ((platformName === 'linux' ||
99
+ platformName === 'freebsd' ||
100
+ platformName === 'openbsd') &&
101
+ command === 'xdg-open') {
102
+ const fallbackCommands = [
103
+ 'gnome-open',
104
+ 'kde-open',
105
+ 'firefox',
106
+ 'chromium',
107
+ 'google-chrome',
108
+ ];
109
+ for (const fallbackCommand of fallbackCommands) {
110
+ try {
111
+ await execFileAsync(fallbackCommand, [url], options);
112
+ return; // Success!
113
+ }
114
+ catch {
115
+ // Try next command
116
+ continue;
117
+ }
118
+ }
119
+ }
120
+ // Re-throw the error if all attempts failed
121
+ throw new Error(`Failed to open browser: ${error instanceof Error ? error.message : 'Unknown error'}`);
122
+ }
123
+ }
124
+ /**
125
+ * Checks if the current environment should attempt to launch a browser.
126
+ * This is the same logic as in browser.ts for consistency.
127
+ *
128
+ * @returns True if the tool should attempt to launch a browser
129
+ */
130
+ export function shouldLaunchBrowser() {
131
+ // A list of browser names that indicate we should not attempt to open a
132
+ // web browser for the user.
133
+ const browserBlocklist = ['www-browser'];
134
+ const browserEnv = process.env.BROWSER;
135
+ if (browserEnv && browserBlocklist.includes(browserEnv)) {
136
+ return false;
137
+ }
138
+ // Common environment variables used in CI/CD or other non-interactive shells.
139
+ if (process.env.CI || process.env.DEBIAN_FRONTEND === 'noninteractive') {
140
+ return false;
141
+ }
142
+ // The presence of SSH_CONNECTION indicates a remote session.
143
+ // We should not attempt to launch a browser unless a display is explicitly available
144
+ // (checked below for Linux).
145
+ const isSSH = !!process.env.SSH_CONNECTION;
146
+ // On Linux, the presence of a display server is a strong indicator of a GUI.
147
+ if (platform() === 'linux') {
148
+ // These are environment variables that can indicate a running compositor on Linux.
149
+ const displayVariables = ['DISPLAY', 'WAYLAND_DISPLAY', 'MIR_SOCKET'];
150
+ const hasDisplay = displayVariables.some((v) => !!process.env[v]);
151
+ if (!hasDisplay) {
152
+ return false;
153
+ }
154
+ }
155
+ // If in an SSH session on a non-Linux OS (e.g., macOS), don't launch browser.
156
+ // The Linux case is handled above (it's allowed if DISPLAY is set).
157
+ if (isSSH && platform() !== 'linux') {
158
+ return false;
159
+ }
160
+ // For non-Linux OSes, we generally assume a GUI is available
161
+ // unless other signals (like SSH) suggest otherwise.
162
+ return true;
163
+ }
164
+ //# sourceMappingURL=secure-browser-launcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-browser-launcher.js","sourceRoot":"","sources":["../../../src/utils/secure-browser-launcher.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,IAAI,SAAc,CAAC;IAEnB,IAAI,CAAC;QACH,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,sCAAsC;IACtC,IAAI,SAAS,CAAC,QAAQ,KAAK,OAAO,IAAI,SAAS,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CACb,oBAAoB,SAAS,CAAC,QAAQ,oCAAoC,CAC3E,CAAC;IACJ,CAA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AAO,KAAK,CAAC;IACf,CAAC;IAED,6DAA6D;IAC7D,qFAAqF;IACrF,6BAA6B;IAC7B,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAE3C,6EAA6E;IAC7E,IAAI,QAAQ,EAAE,KAAK,OAAO,EAAE,CAAC;QAC3B,mFAAmF;QACnF,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,iBAAiB,EAAE,YAAY,CAAC,CAAC;QACtE,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAClE,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,8EAA8E;IAC9E,oEAAoE;IACpE,IAAI,KAAK,IAAI,QAAQ,EAAE,KAAK,OAAO,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,6DAA6D;IAC7D,qDAAqD;IACrD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export {};
@@ -0,0 +1,149 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
7
+ import { openBrowserSecurely } from './secure-browser-launcher.js';
8
+ // Create mock function using vi.hoisted
9
+ const mockExecFile = vi.hoisted(() => vi.fn());
10
+ // Mock modules
11
+ vi.mock('node:child_process');
12
+ vi.mock('node:util', () => ({
13
+ promisify: () => mockExecFile,
14
+ }));
15
+ describe('secure-browser-launcher', () => {
16
+ let originalPlatform;
17
+ beforeEach(() => {
18
+ vi.clearAllMocks();
19
+ mockExecFile.mockResolvedValue({ stdout: '', stderr: '' });
20
+ originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform');
21
+ });
22
+ afterEach(() => {
23
+ if (originalPlatform) {
24
+ Object.defineProperty(process, 'platform', originalPlatform);
25
+ }
26
+ });
27
+ function setPlatform(platform) {
28
+ Object.defineProperty(process, 'platform', {
29
+ value: platform,
30
+ configurable: true,
31
+ });
32
+ }
33
+ describe('URL validation', () => {
34
+ it('should allow valid HTTP URLs', async () => {
35
+ setPlatform('darwin');
36
+ await openBrowserSecurely('http://example.com');
37
+ expect(mockExecFile).toHaveBeenCalledWith('open', ['http://example.com'], expect.any(Object));
38
+ });
39
+ it('should allow valid HTTPS URLs', async () => {
40
+ setPlatform('darwin');
41
+ await openBrowserSecurely('https://example.com');
42
+ expect(mockExecFile).toHaveBeenCalledWith('open', ['https://example.com'], expect.any(Object));
43
+ });
44
+ it('should reject non-HTTP(S) protocols', async () => {
45
+ await expect(openBrowserSecurely('file:///etc/passwd')).rejects.toThrow('Unsafe protocol');
46
+ await expect(openBrowserSecurely('javascript:alert(1)')).rejects.toThrow('Unsafe protocol');
47
+ await expect(openBrowserSecurely('ftp://example.com')).rejects.toThrow('Unsafe protocol');
48
+ });
49
+ it('should reject invalid URLs', async () => {
50
+ await expect(openBrowserSecurely('not-a-url')).rejects.toThrow('Invalid URL');
51
+ await expect(openBrowserSecurely('')).rejects.toThrow('Invalid URL');
52
+ });
53
+ it('should reject URLs with control characters', async () => {
54
+ await expect(openBrowserSecurely('http://example.com\nmalicious-command')).rejects.toThrow('invalid characters');
55
+ await expect(openBrowserSecurely('http://example.com\rmalicious-command')).rejects.toThrow('invalid characters');
56
+ await expect(openBrowserSecurely('http://example.com\x00')).rejects.toThrow('invalid characters');
57
+ });
58
+ });
59
+ describe('Command injection prevention', () => {
60
+ it('should prevent PowerShell command injection on Windows', async () => {
61
+ setPlatform('win32');
62
+ // The POC from the vulnerability report
63
+ const maliciousUrl = "http://127.0.0.1:8080/?param=example#$(Invoke-Expression([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('Y2FsYy5leGU='))))";
64
+ await openBrowserSecurely(maliciousUrl);
65
+ // Verify that execFile was called (not exec) and the URL is passed safely
66
+ expect(mockExecFile).toHaveBeenCalledWith('powershell.exe', [
67
+ '-NoProfile',
68
+ '-NonInteractive',
69
+ '-WindowStyle',
70
+ 'Hidden',
71
+ '-Command',
72
+ `Start-Process '${maliciousUrl.replace(/'/g, "''")}'`,
73
+ ], expect.any(Object));
74
+ });
75
+ it('should handle URLs with special shell characters safely', async () => {
76
+ setPlatform('darwin');
77
+ const urlsWithSpecialChars = [
78
+ 'http://example.com/path?param=value&other=$value',
79
+ 'http://example.com/path#fragment;command',
80
+ 'http://example.com/$(whoami)',
81
+ 'http://example.com/`command`',
82
+ 'http://example.com/|pipe',
83
+ 'http://example.com/>redirect',
84
+ ];
85
+ for (const url of urlsWithSpecialChars) {
86
+ await openBrowserSecurely(url);
87
+ // Verify the URL is passed as an argument, not interpreted by shell
88
+ expect(mockExecFile).toHaveBeenCalledWith('open', [url], expect.any(Object));
89
+ }
90
+ });
91
+ it('should properly escape single quotes in URLs on Windows', async () => {
92
+ setPlatform('win32');
93
+ const urlWithSingleQuotes = "http://example.com/path?name=O'Brien&test='value'";
94
+ await openBrowserSecurely(urlWithSingleQuotes);
95
+ // Verify that single quotes are escaped by doubling them
96
+ expect(mockExecFile).toHaveBeenCalledWith('powershell.exe', [
97
+ '-NoProfile',
98
+ '-NonInteractive',
99
+ '-WindowStyle',
100
+ 'Hidden',
101
+ '-Command',
102
+ `Start-Process 'http://example.com/path?name=O''Brien&test=''value'''`,
103
+ ], expect.any(Object));
104
+ });
105
+ });
106
+ describe('Platform-specific behavior', () => {
107
+ it('should use correct command on macOS', async () => {
108
+ setPlatform('darwin');
109
+ await openBrowserSecurely('https://example.com');
110
+ expect(mockExecFile).toHaveBeenCalledWith('open', ['https://example.com'], expect.any(Object));
111
+ });
112
+ it('should use PowerShell on Windows', async () => {
113
+ setPlatform('win32');
114
+ await openBrowserSecurely('https://example.com');
115
+ expect(mockExecFile).toHaveBeenCalledWith('powershell.exe', expect.arrayContaining([
116
+ '-Command',
117
+ `Start-Process 'https://example.com'`,
118
+ ]), expect.any(Object));
119
+ });
120
+ it('should use xdg-open on Linux', async () => {
121
+ setPlatform('linux');
122
+ await openBrowserSecurely('https://example.com');
123
+ expect(mockExecFile).toHaveBeenCalledWith('xdg-open', ['https://example.com'], expect.any(Object));
124
+ });
125
+ it('should throw on unsupported platforms', async () => {
126
+ setPlatform('aix');
127
+ await expect(openBrowserSecurely('https://example.com')).rejects.toThrow('Unsupported platform');
128
+ });
129
+ });
130
+ describe('Error handling', () => {
131
+ it('should handle browser launch failures gracefully', async () => {
132
+ setPlatform('darwin');
133
+ mockExecFile.mockRejectedValueOnce(new Error('Command not found'));
134
+ await expect(openBrowserSecurely('https://example.com')).rejects.toThrow('Failed to open browser');
135
+ });
136
+ it('should try fallback browsers on Linux', async () => {
137
+ setPlatform('linux');
138
+ // First call to xdg-open fails
139
+ mockExecFile.mockRejectedValueOnce(new Error('Command not found'));
140
+ // Second call to gnome-open succeeds
141
+ mockExecFile.mockResolvedValueOnce({ stdout: '', stderr: '' });
142
+ await openBrowserSecurely('https://example.com');
143
+ expect(mockExecFile).toHaveBeenCalledTimes(2);
144
+ expect(mockExecFile).toHaveBeenNthCalledWith(1, 'xdg-open', ['https://example.com'], expect.any(Object));
145
+ expect(mockExecFile).toHaveBeenNthCalledWith(2, 'gnome-open', ['https://example.com'], expect.any(Object));
146
+ });
147
+ });
148
+ });
149
+ //# sourceMappingURL=secure-browser-launcher.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-browser-launcher.test.js","sourceRoot":"","sources":["../../../src/utils/secure-browser-launcher.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,M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,MAAM,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;YAEjD,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAC9C,MAAM,CAAC,YAAY,CAAC,CAAC,uBAAuB,CAC1C,CAAC,EACD,UAAU,EACV,CAAC,qBAAqB,CAAC,EACvB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CACnB,CAAC;YACF,MAAM,CAAC,YAAY,CAAC,CAAC,uBAAuB,CAC1C,CAAC,EACD,YAAY,EACZ,CAAC,qBAAqB,CAAC,EACvB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CACnB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -31,12 +31,46 @@ export declare function stripShellWrapper(command: string): string;
31
31
  * @returns true if command substitution would be executed by bash
32
32
  */
33
33
  export declare function detectCommandSubstitution(command: string): boolean;
34
+ /**
35
+ * Checks a shell command against security policies and allowlists.
36
+ *
37
+ * This function operates in one of two modes depending on the presence of
38
+ * the `sessionAllowlist` parameter:
39
+ *
40
+ * 1. **"Default Deny" Mode (sessionAllowlist is provided):** This is the
41
+ * strictest mode, used for user-defined scripts like custom commands.
42
+ * A command is only permitted if it is found on the global `coreTools`
43
+ * allowlist OR the provided `sessionAllowlist`. It must not be on the
44
+ * global `excludeTools` blocklist.
45
+ *
46
+ * 2. **"Default Allow" Mode (sessionAllowlist is NOT provided):** This mode
47
+ * is used for direct tool invocations (e.g., by the model). If a strict
48
+ * global `coreTools` allowlist exists, commands must be on it. Otherwise,
49
+ * any command is permitted as long as it is not on the `excludeTools`
50
+ * blocklist.
51
+ *
52
+ * @param command The shell command string to validate.
53
+ * @param config The application configuration.
54
+ * @param sessionAllowlist A session-level list of approved commands. Its
55
+ * presence activates "Default Deny" mode.
56
+ * @returns An object detailing which commands are not allowed.
57
+ */
58
+ export declare function checkCommandPermissions(command: string, config: Config, sessionAllowlist?: Set<string>): {
59
+ allAllowed: boolean;
60
+ disallowedCommands: string[];
61
+ blockReason?: string;
62
+ isHardDenial?: boolean;
63
+ };
34
64
  /**
35
65
  * Determines whether a given shell command is allowed to execute based on
36
66
  * the tool's configuration including allowlists and blocklists.
37
- * @param command The shell command string to validate
38
- * @param config The application configuration
39
- * @returns An object with 'allowed' boolean and optional 'reason' string if not allowed
67
+ *
68
+ * This function operates in "default allow" mode. It is a wrapper around
69
+ * `checkCommandPermissions`.
70
+ *
71
+ * @param command The shell command string to validate.
72
+ * @param config The application configuration.
73
+ * @returns An object with 'allowed' boolean and optional 'reason' string if not allowed.
40
74
  */
41
75
  export declare function isCommandAllowed(command: string, config: Config): {
42
76
  allowed: boolean;
@@ -157,41 +157,47 @@ export function detectCommandSubstitution(command) {
157
157
  return false;
158
158
  }
159
159
  /**
160
- * Determines whether a given shell command is allowed to execute based on
161
- * the tool's configuration including allowlists and blocklists.
162
- * @param command The shell command string to validate
163
- * @param config The application configuration
164
- * @returns An object with 'allowed' boolean and optional 'reason' string if not allowed
160
+ * Checks a shell command against security policies and allowlists.
161
+ *
162
+ * This function operates in one of two modes depending on the presence of
163
+ * the `sessionAllowlist` parameter:
164
+ *
165
+ * 1. **"Default Deny" Mode (sessionAllowlist is provided):** This is the
166
+ * strictest mode, used for user-defined scripts like custom commands.
167
+ * A command is only permitted if it is found on the global `coreTools`
168
+ * allowlist OR the provided `sessionAllowlist`. It must not be on the
169
+ * global `excludeTools` blocklist.
170
+ *
171
+ * 2. **"Default Allow" Mode (sessionAllowlist is NOT provided):** This mode
172
+ * is used for direct tool invocations (e.g., by the model). If a strict
173
+ * global `coreTools` allowlist exists, commands must be on it. Otherwise,
174
+ * any command is permitted as long as it is not on the `excludeTools`
175
+ * blocklist.
176
+ *
177
+ * @param command The shell command string to validate.
178
+ * @param config The application configuration.
179
+ * @param sessionAllowlist A session-level list of approved commands. Its
180
+ * presence activates "Default Deny" mode.
181
+ * @returns An object detailing which commands are not allowed.
165
182
  */
166
- export function isCommandAllowed(command, config) {
167
- // 0. Disallow command substitution
168
- // Parse the command to check for unquoted/unescaped command substitution
169
- const hasCommandSubstitution = detectCommandSubstitution(command);
170
- if (hasCommandSubstitution) {
183
+ export function checkCommandPermissions(command, config, sessionAllowlist) {
184
+ // Disallow command substitution for security.
185
+ if (detectCommandSubstitution(command)) {
171
186
  return {
172
- allowed: false,
173
- reason: 'Command substitution using $(), <(), or >() is not allowed for security reasons',
187
+ allAllowed: false,
188
+ disallowedCommands: [command],
189
+ blockReason: 'Command substitution using $(), <(), or >() is not allowed for security reasons',
190
+ isHardDenial: true,
174
191
  };
175
192
  }
176
193
  const SHELL_TOOL_NAMES = ['run_shell_command', 'ShellTool'];
177
194
  const normalize = (cmd) => cmd.trim().replace(/\s+/g, ' ');
178
- /**
179
- * Checks if a command string starts with a given prefix, ensuring it's a
180
- * whole word match (i.e., followed by a space or it's an exact match).
181
- * e.g., `isPrefixedBy('npm install', 'npm')` -> true
182
- * e.g., `isPrefixedBy('npm', 'npm')` -> true
183
- * e.g., `isPrefixedBy('npminstall', 'npm')` -> false
184
- */
185
195
  const isPrefixedBy = (cmd, prefix) => {
186
196
  if (!cmd.startsWith(prefix)) {
187
197
  return false;
188
198
  }
189
199
  return cmd.length === prefix.length || cmd[prefix.length] === ' ';
190
200
  };
191
- /**
192
- * Extracts and normalizes shell commands from a list of tool strings.
193
- * e.g., 'ShellTool("ls -l")' becomes 'ls -l'
194
- */
195
201
  const extractCommands = (tools) => tools.flatMap((tool) => {
196
202
  for (const toolName of SHELL_TOOL_NAMES) {
197
203
  if (tool.startsWith(`${toolName}(`) && tool.endsWith(')')) {
@@ -202,42 +208,99 @@ export function isCommandAllowed(command, config) {
202
208
  });
203
209
  const coreTools = config.getCoreTools() || [];
204
210
  const excludeTools = config.getExcludeTools() || [];
205
- // 1. Check if the shell tool is globally disabled.
211
+ const commandsToValidate = splitCommands(command).map(normalize);
212
+ // 1. Blocklist Check (Highest Priority)
206
213
  if (SHELL_TOOL_NAMES.some((name) => excludeTools.includes(name))) {
207
214
  return {
208
- allowed: false,
209
- reason: 'Shell tool is globally disabled in configuration',
215
+ allAllowed: false,
216
+ disallowedCommands: commandsToValidate,
217
+ blockReason: 'Shell tool is globally disabled in configuration',
218
+ isHardDenial: true,
210
219
  };
211
220
  }
212
- const blockedCommands = new Set(extractCommands(excludeTools));
213
- const allowedCommands = new Set(extractCommands(coreTools));
214
- const hasSpecificAllowedCommands = allowedCommands.size > 0;
215
- const isWildcardAllowed = SHELL_TOOL_NAMES.some((name) => coreTools.includes(name));
216
- const commandsToValidate = splitCommands(command).map(normalize);
217
- const blockedCommandsArr = [...blockedCommands];
221
+ const blockedCommands = extractCommands(excludeTools);
218
222
  for (const cmd of commandsToValidate) {
219
- // 2. Check if the command is on the blocklist.
220
- const isBlocked = blockedCommandsArr.some((blocked) => isPrefixedBy(cmd, blocked));
221
- if (isBlocked) {
223
+ if (blockedCommands.some((blocked) => isPrefixedBy(cmd, blocked))) {
224
+ return {
225
+ allAllowed: false,
226
+ disallowedCommands: [cmd],
227
+ blockReason: `Command '${cmd}' is blocked by configuration`,
228
+ isHardDenial: true,
229
+ };
230
+ }
231
+ }
232
+ const globallyAllowedCommands = extractCommands(coreTools);
233
+ const isWildcardAllowed = SHELL_TOOL_NAMES.some((name) => coreTools.includes(name));
234
+ // If there's a global wildcard, all commands are allowed at this point
235
+ // because they have already passed the blocklist check.
236
+ if (isWildcardAllowed) {
237
+ return { allAllowed: true, disallowedCommands: [] };
238
+ }
239
+ if (sessionAllowlist) {
240
+ // "DEFAULT DENY" MODE: A session allowlist is provided.
241
+ // All commands must be in either the session or global allowlist.
242
+ const disallowedCommands = [];
243
+ for (const cmd of commandsToValidate) {
244
+ const isSessionAllowed = [...sessionAllowlist].some((allowed) => isPrefixedBy(cmd, normalize(allowed)));
245
+ if (isSessionAllowed)
246
+ continue;
247
+ const isGloballyAllowed = globallyAllowedCommands.some((allowed) => isPrefixedBy(cmd, allowed));
248
+ if (isGloballyAllowed)
249
+ continue;
250
+ disallowedCommands.push(cmd);
251
+ }
252
+ if (disallowedCommands.length > 0) {
222
253
  return {
223
- allowed: false,
224
- reason: `Command '${cmd}' is blocked by configuration`,
254
+ allAllowed: false,
255
+ disallowedCommands,
256
+ blockReason: `Command(s) not on the global or session allowlist.`,
257
+ isHardDenial: false, // This is a soft denial; confirmation is possible.
225
258
  };
226
259
  }
227
- // 3. If in strict allow-list mode, check if the command is permitted.
228
- const isStrictAllowlist = hasSpecificAllowedCommands && !isWildcardAllowed;
229
- const allowedCommandsArr = [...allowedCommands];
230
- if (isStrictAllowlist) {
231
- const isAllowed = allowedCommandsArr.some((allowed) => isPrefixedBy(cmd, allowed));
232
- if (!isAllowed) {
260
+ }
261
+ else {
262
+ // "DEFAULT ALLOW" MODE: No session allowlist.
263
+ const hasSpecificAllowedCommands = globallyAllowedCommands.length > 0;
264
+ if (hasSpecificAllowedCommands) {
265
+ const disallowedCommands = [];
266
+ for (const cmd of commandsToValidate) {
267
+ const isGloballyAllowed = globallyAllowedCommands.some((allowed) => isPrefixedBy(cmd, allowed));
268
+ if (!isGloballyAllowed) {
269
+ disallowedCommands.push(cmd);
270
+ }
271
+ }
272
+ if (disallowedCommands.length > 0) {
233
273
  return {
234
- allowed: false,
235
- reason: `Command '${cmd}' is not in the allowed commands list`,
274
+ allAllowed: false,
275
+ disallowedCommands,
276
+ blockReason: `Command(s) not in the allowed commands list.`,
277
+ isHardDenial: false, // This is a soft denial.
236
278
  };
237
279
  }
238
280
  }
281
+ // If no specific global allowlist exists, and it passed the blocklist,
282
+ // the command is allowed by default.
283
+ }
284
+ // If all checks for the current mode pass, the command is allowed.
285
+ return { allAllowed: true, disallowedCommands: [] };
286
+ }
287
+ /**
288
+ * Determines whether a given shell command is allowed to execute based on
289
+ * the tool's configuration including allowlists and blocklists.
290
+ *
291
+ * This function operates in "default allow" mode. It is a wrapper around
292
+ * `checkCommandPermissions`.
293
+ *
294
+ * @param command The shell command string to validate.
295
+ * @param config The application configuration.
296
+ * @returns An object with 'allowed' boolean and optional 'reason' string if not allowed.
297
+ */
298
+ export function isCommandAllowed(command, config) {
299
+ // By not providing a sessionAllowlist, we invoke "default allow" behavior.
300
+ const { allAllowed, blockReason } = checkCommandPermissions(command, config);
301
+ if (allAllowed) {
302
+ return { allowed: true };
239
303
  }
240
- // 4. If all checks pass, the command is allowed.
241
- return { allowed: true };
304
+ return { allowed: false, reason: blockReason };
242
305
  }
243
306
  //# sourceMappingURL=shell-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell-utils.js","sourceRoot":"","sources":["../../../src/utils/shell-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,cAAc,GAAG,EAAE,CAAC;IACxB,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAEhC,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5C,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACxC,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QAED,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YACpC,cAAc,GAAG,CAAC,cAAc,CAAC;QACnC,CAAC;aAAM,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAC3C,cAAc,GAAG,C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