@machina.ai/cell-cli-core 1.0.13-rc9 → 1.0.21-rc1

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 (484) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.js +3 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/package.json +12 -4
  5. package/dist/src/code_assist/converter.d.ts +6 -3
  6. package/dist/src/code_assist/converter.js +4 -2
  7. package/dist/src/code_assist/converter.js.map +1 -1
  8. package/dist/src/code_assist/converter.test.js +61 -11
  9. package/dist/src/code_assist/converter.test.js.map +1 -1
  10. package/dist/src/code_assist/oauth2.d.ts +1 -0
  11. package/dist/src/code_assist/oauth2.js +43 -18
  12. package/dist/src/code_assist/oauth2.js.map +1 -1
  13. package/dist/src/code_assist/oauth2.test.js +142 -9
  14. package/dist/src/code_assist/oauth2.test.js.map +1 -1
  15. package/dist/src/code_assist/server.d.ts +2 -2
  16. package/dist/src/code_assist/server.js +5 -5
  17. package/dist/src/code_assist/server.js.map +1 -1
  18. package/dist/src/code_assist/server.test.js +13 -10
  19. package/dist/src/code_assist/server.test.js.map +1 -1
  20. package/dist/src/code_assist/setup.js +49 -18
  21. package/dist/src/code_assist/setup.js.map +1 -1
  22. package/dist/src/code_assist/setup.test.js +115 -9
  23. package/dist/src/code_assist/setup.test.js.map +1 -1
  24. package/dist/src/config/config.d.ts +71 -13
  25. package/dist/src/config/config.js +154 -41
  26. package/dist/src/config/config.js.map +1 -1
  27. package/dist/src/config/config.test.js +206 -21
  28. package/dist/src/config/config.test.js.map +1 -1
  29. package/dist/src/config/flashFallback.test.js +19 -47
  30. package/dist/src/config/flashFallback.test.js.map +1 -1
  31. package/dist/src/config/models.d.ts +1 -0
  32. package/dist/src/config/models.js +1 -0
  33. package/dist/src/config/models.js.map +1 -1
  34. package/dist/src/core/client.d.ts +15 -16
  35. package/dist/src/core/client.js +247 -104
  36. package/dist/src/core/client.js.map +1 -1
  37. package/dist/src/core/client.test.js +798 -49
  38. package/dist/src/core/client.test.js.map +1 -1
  39. package/dist/src/core/contentGenerator.d.ts +2 -2
  40. package/dist/src/core/contentGenerator.js +23 -21
  41. package/dist/src/core/contentGenerator.js.map +1 -1
  42. package/dist/src/core/contentGenerator.test.js +30 -126
  43. package/dist/src/core/contentGenerator.test.js.map +1 -1
  44. package/dist/src/core/coreToolScheduler.d.ts +23 -10
  45. package/dist/src/core/coreToolScheduler.js +201 -77
  46. package/dist/src/core/coreToolScheduler.js.map +1 -1
  47. package/dist/src/core/coreToolScheduler.test.js +322 -94
  48. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  49. package/dist/src/core/geminiChat.d.ts +8 -6
  50. package/dist/src/core/geminiChat.js +49 -51
  51. package/dist/src/core/geminiChat.js.map +1 -1
  52. package/dist/src/core/geminiChat.test.js +2 -2
  53. package/dist/src/core/geminiChat.test.js.map +1 -1
  54. package/dist/src/core/geminiRequest.js +2 -37
  55. package/dist/src/core/geminiRequest.js.map +1 -1
  56. package/dist/src/core/logger.d.ts +24 -1
  57. package/dist/src/core/logger.js +128 -4
  58. package/dist/src/core/logger.js.map +1 -1
  59. package/dist/src/core/logger.test.js +157 -11
  60. package/dist/src/core/logger.test.js.map +1 -1
  61. package/dist/src/core/loggingContentGenerator.d.ts +25 -0
  62. package/dist/src/core/loggingContentGenerator.js +95 -0
  63. package/dist/src/core/loggingContentGenerator.js.map +1 -0
  64. package/dist/src/core/nonInteractiveToolExecutor.js +39 -4
  65. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
  66. package/dist/src/core/nonInteractiveToolExecutor.test.js +85 -62
  67. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  68. package/dist/src/core/prompts.js +43 -19
  69. package/dist/src/core/prompts.js.map +1 -1
  70. package/dist/src/core/prompts.test.js +118 -1
  71. package/dist/src/core/prompts.test.js.map +1 -1
  72. package/dist/src/core/subagent.d.ts +230 -0
  73. package/dist/src/core/subagent.js +447 -0
  74. package/dist/src/core/subagent.js.map +1 -0
  75. package/dist/src/core/subagent.test.js +515 -0
  76. package/dist/src/core/subagent.test.js.map +1 -0
  77. package/dist/src/core/tokenLimits.js +1 -0
  78. package/dist/src/core/tokenLimits.js.map +1 -1
  79. package/dist/src/core/turn.d.ts +3 -0
  80. package/dist/src/core/turn.js +4 -0
  81. package/dist/src/core/turn.js.map +1 -1
  82. package/dist/src/core/turn.test.js +4 -0
  83. package/dist/src/core/turn.test.js.map +1 -1
  84. package/dist/src/generated/git-commit.d.ts +7 -0
  85. package/dist/src/generated/git-commit.js +10 -0
  86. package/dist/src/generated/git-commit.js.map +1 -0
  87. package/dist/src/ide/constants.d.ts +6 -0
  88. package/dist/src/ide/constants.js +7 -0
  89. package/dist/src/ide/constants.js.map +1 -0
  90. package/dist/src/ide/detect-ide.d.ts +20 -0
  91. package/dist/src/ide/detect-ide.js +86 -0
  92. package/dist/src/ide/detect-ide.js.map +1 -0
  93. package/dist/src/ide/detect-ide.test.js +65 -0
  94. package/dist/src/ide/detect-ide.test.js.map +1 -0
  95. package/dist/src/ide/ide-client.d.ts +63 -0
  96. package/dist/src/ide/ide-client.js +320 -0
  97. package/dist/src/ide/ide-client.js.map +1 -0
  98. package/dist/src/ide/ide-client.test.d.ts +6 -0
  99. package/dist/src/ide/ide-client.test.js +43 -0
  100. package/dist/src/ide/ide-client.test.js.map +1 -0
  101. package/dist/src/ide/ide-installer.d.ts +14 -0
  102. package/dist/src/ide/ide-installer.js +98 -0
  103. package/dist/src/ide/ide-installer.js.map +1 -0
  104. package/dist/src/ide/ide-installer.test.d.ts +6 -0
  105. package/dist/src/ide/ide-installer.test.js +53 -0
  106. package/dist/src/ide/ide-installer.test.js.map +1 -0
  107. package/dist/src/ide/ideContext.d.ts +374 -0
  108. package/dist/src/ide/ideContext.js +147 -0
  109. package/dist/src/ide/ideContext.js.map +1 -0
  110. package/dist/src/ide/ideContext.test.d.ts +6 -0
  111. package/dist/src/ide/ideContext.test.js +265 -0
  112. package/dist/src/ide/ideContext.test.js.map +1 -0
  113. package/dist/src/ide/process-utils.d.ts +14 -0
  114. package/dist/src/ide/process-utils.js +57 -0
  115. package/dist/src/ide/process-utils.js.map +1 -0
  116. package/dist/src/index.d.ts +17 -1
  117. package/dist/src/index.js +20 -1
  118. package/dist/src/index.js.map +1 -1
  119. package/dist/src/mcp/google-auth-provider.d.ts +23 -0
  120. package/dist/src/mcp/google-auth-provider.js +72 -0
  121. package/dist/src/mcp/google-auth-provider.js.map +1 -0
  122. package/dist/src/mcp/google-auth-provider.test.d.ts +6 -0
  123. package/dist/src/mcp/google-auth-provider.test.js +89 -0
  124. package/dist/src/mcp/google-auth-provider.test.js.map +1 -0
  125. package/dist/src/mcp/oauth-provider.d.ts +6 -2
  126. package/dist/src/mcp/oauth-provider.js +208 -53
  127. package/dist/src/mcp/oauth-provider.js.map +1 -1
  128. package/dist/src/mcp/oauth-provider.test.js +222 -70
  129. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  130. package/dist/src/mcp/oauth-token-storage.d.ts +3 -1
  131. package/dist/src/mcp/oauth-token-storage.js +3 -1
  132. package/dist/src/mcp/oauth-token-storage.js.map +1 -1
  133. package/dist/src/mcp/oauth-utils.d.ts +3 -1
  134. package/dist/src/mcp/oauth-utils.js +52 -14
  135. package/dist/src/mcp/oauth-utils.js.map +1 -1
  136. package/dist/src/mcp/oauth-utils.test.js +18 -3
  137. package/dist/src/mcp/oauth-utils.test.js.map +1 -1
  138. package/dist/src/mocks/msw.d.ts +6 -0
  139. package/dist/src/mocks/msw.js +8 -0
  140. package/dist/src/mocks/msw.js.map +1 -0
  141. package/dist/src/prompts/mcp-prompts.d.ts +8 -0
  142. package/dist/src/prompts/mcp-prompts.js +13 -0
  143. package/dist/src/prompts/mcp-prompts.js.map +1 -0
  144. package/dist/src/prompts/prompt-registry.d.ts +34 -0
  145. package/dist/src/prompts/prompt-registry.js +63 -0
  146. package/dist/src/prompts/prompt-registry.js.map +1 -0
  147. package/dist/src/services/chatRecordingService.d.ts +150 -0
  148. package/dist/src/services/chatRecordingService.js +318 -0
  149. package/dist/src/services/chatRecordingService.js.map +1 -0
  150. package/dist/src/services/chatRecordingService.test.d.ts +6 -0
  151. package/dist/src/services/chatRecordingService.test.js +288 -0
  152. package/dist/src/services/chatRecordingService.test.js.map +1 -0
  153. package/dist/src/services/fileDiscoveryService.test.js +101 -60
  154. package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
  155. package/dist/src/services/fileSystemService.d.ts +31 -0
  156. package/dist/src/services/fileSystemService.js +18 -0
  157. package/dist/src/services/fileSystemService.js.map +1 -0
  158. package/dist/src/services/fileSystemService.test.d.ts +6 -0
  159. package/dist/src/services/fileSystemService.test.js +41 -0
  160. package/dist/src/services/fileSystemService.test.js.map +1 -0
  161. package/dist/src/services/gitService.test.js +67 -86
  162. package/dist/src/services/gitService.test.js.map +1 -1
  163. package/dist/src/services/loopDetectionService.d.ts +51 -5
  164. package/dist/src/services/loopDetectionService.js +152 -45
  165. package/dist/src/services/loopDetectionService.js.map +1 -1
  166. package/dist/src/services/loopDetectionService.test.js +286 -89
  167. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  168. package/dist/src/services/shellExecutionService.d.ts +70 -0
  169. package/dist/src/services/shellExecutionService.js +175 -0
  170. package/dist/src/services/shellExecutionService.js.map +1 -0
  171. package/dist/src/services/shellExecutionService.test.d.ts +6 -0
  172. package/dist/src/services/shellExecutionService.test.js +282 -0
  173. package/dist/src/services/shellExecutionService.test.js.map +1 -0
  174. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +81 -9
  175. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +356 -182
  176. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  177. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +17 -0
  178. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +342 -0
  179. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -0
  180. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +19 -2
  181. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +51 -9
  182. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  183. package/dist/src/telemetry/constants.d.ts +4 -0
  184. package/dist/src/telemetry/constants.js +4 -0
  185. package/dist/src/telemetry/constants.js.map +1 -1
  186. package/dist/src/telemetry/file-exporters.d.ts +28 -0
  187. package/dist/src/telemetry/file-exporters.js +62 -0
  188. package/dist/src/telemetry/file-exporters.js.map +1 -0
  189. package/dist/src/telemetry/index.d.ts +2 -2
  190. package/dist/src/telemetry/index.js +2 -2
  191. package/dist/src/telemetry/index.js.map +1 -1
  192. package/dist/src/telemetry/integration.test.circular.js +1 -0
  193. package/dist/src/telemetry/integration.test.circular.js.map +1 -1
  194. package/dist/src/telemetry/loggers.d.ts +6 -1
  195. package/dist/src/telemetry/loggers.js +87 -6
  196. package/dist/src/telemetry/loggers.js.map +1 -1
  197. package/dist/src/telemetry/loggers.test.circular.js +9 -2
  198. package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
  199. package/dist/src/telemetry/loggers.test.js +51 -11
  200. package/dist/src/telemetry/loggers.test.js.map +1 -1
  201. package/dist/src/telemetry/metrics.d.ts +7 -2
  202. package/dist/src/telemetry/metrics.js +26 -6
  203. package/dist/src/telemetry/metrics.js.map +1 -1
  204. package/dist/src/telemetry/metrics.test.js +81 -1
  205. package/dist/src/telemetry/metrics.test.js.map +1 -1
  206. package/dist/src/telemetry/sdk.d.ts +1 -1
  207. package/dist/src/telemetry/sdk.js +77 -30
  208. package/dist/src/telemetry/sdk.js.map +1 -1
  209. package/dist/src/telemetry/sdk.test.d.ts +6 -0
  210. package/dist/src/telemetry/sdk.test.js +82 -0
  211. package/dist/src/telemetry/sdk.test.js.map +1 -0
  212. package/dist/src/telemetry/telemetry.test.js +2 -2
  213. package/dist/src/telemetry/telemetry.test.js.map +1 -1
  214. package/dist/src/telemetry/tool-call-decision.d.ts +13 -0
  215. package/dist/src/telemetry/tool-call-decision.js +29 -0
  216. package/dist/src/telemetry/tool-call-decision.js.map +1 -0
  217. package/dist/src/telemetry/types.d.ts +74 -18
  218. package/dist/src/telemetry/types.js +110 -32
  219. package/dist/src/telemetry/types.js.map +1 -1
  220. package/dist/src/telemetry/uiTelemetry.d.ts +8 -1
  221. package/dist/src/telemetry/uiTelemetry.js +17 -2
  222. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  223. package/dist/src/telemetry/uiTelemetry.test.js +60 -10
  224. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  225. package/dist/src/test-utils/config.d.ts +16 -0
  226. package/dist/src/test-utils/config.js +32 -0
  227. package/dist/src/test-utils/config.js.map +1 -0
  228. package/dist/src/test-utils/mockWorkspaceContext.d.ts +13 -0
  229. package/dist/src/test-utils/mockWorkspaceContext.js +24 -0
  230. package/dist/src/test-utils/mockWorkspaceContext.js.map +1 -0
  231. package/dist/src/test-utils/tools.d.ts +44 -0
  232. package/dist/src/test-utils/tools.js +105 -0
  233. package/dist/src/test-utils/tools.js.map +1 -0
  234. package/dist/src/tools/diffOptions.d.ts +2 -0
  235. package/dist/src/tools/diffOptions.js +28 -0
  236. package/dist/src/tools/diffOptions.js.map +1 -1
  237. package/dist/src/tools/diffOptions.test.d.ts +6 -0
  238. package/dist/src/tools/diffOptions.test.js +119 -0
  239. package/dist/src/tools/diffOptions.test.js.map +1 -0
  240. package/dist/src/tools/edit.d.ts +10 -34
  241. package/dist/src/tools/edit.js +171 -131
  242. package/dist/src/tools/edit.js.map +1 -1
  243. package/dist/src/tools/edit.test.js +220 -43
  244. package/dist/src/tools/edit.test.js.map +1 -1
  245. package/dist/src/tools/glob.d.ts +4 -11
  246. package/dist/src/tools/glob.js +129 -97
  247. package/dist/src/tools/glob.js.map +1 -1
  248. package/dist/src/tools/glob.test.js +73 -17
  249. package/dist/src/tools/glob.test.js.map +1 -1
  250. package/dist/src/tools/grep.d.ts +5 -37
  251. package/dist/src/tools/grep.js +175 -100
  252. package/dist/src/tools/grep.js.map +1 -1
  253. package/dist/src/tools/grep.test.js +112 -28
  254. package/dist/src/tools/grep.test.js.map +1 -1
  255. package/dist/src/tools/ls.d.ts +4 -23
  256. package/dist/src/tools/ls.js +77 -78
  257. package/dist/src/tools/ls.js.map +1 -1
  258. package/dist/src/tools/ls.test.d.ts +6 -0
  259. package/dist/src/tools/ls.test.js +384 -0
  260. package/dist/src/tools/ls.test.js.map +1 -0
  261. package/dist/src/tools/mcp-client-manager.d.ts +38 -0
  262. package/dist/src/tools/mcp-client-manager.js +74 -0
  263. package/dist/src/tools/mcp-client-manager.js.map +1 -0
  264. package/dist/src/tools/mcp-client-manager.test.d.ts +6 -0
  265. package/dist/src/tools/mcp-client-manager.test.js +39 -0
  266. package/dist/src/tools/mcp-client-manager.test.js.map +1 -0
  267. package/dist/src/tools/mcp-client.d.ts +86 -4
  268. package/dist/src/tools/mcp-client.js +730 -59
  269. package/dist/src/tools/mcp-client.js.map +1 -1
  270. package/dist/src/tools/mcp-client.test.js +295 -22
  271. package/dist/src/tools/mcp-client.test.js.map +1 -1
  272. package/dist/src/tools/mcp-tool.d.ts +6 -13
  273. package/dist/src/tools/mcp-tool.js +163 -76
  274. package/dist/src/tools/mcp-tool.js.map +1 -1
  275. package/dist/src/tools/mcp-tool.test.js +400 -29
  276. package/dist/src/tools/mcp-tool.test.js.map +1 -1
  277. package/dist/src/tools/memoryTool.d.ts +14 -3
  278. package/dist/src/tools/memoryTool.js +159 -40
  279. package/dist/src/tools/memoryTool.js.map +1 -1
  280. package/dist/src/tools/memoryTool.test.js +116 -11
  281. package/dist/src/tools/memoryTool.test.js.map +1 -1
  282. package/dist/src/tools/modifiable-tool.d.ts +9 -6
  283. package/dist/src/tools/modifiable-tool.js +6 -3
  284. package/dist/src/tools/modifiable-tool.js.map +1 -1
  285. package/dist/src/tools/modifiable-tool.test.js +63 -74
  286. package/dist/src/tools/modifiable-tool.test.js.map +1 -1
  287. package/dist/src/tools/read-file.d.ts +4 -6
  288. package/dist/src/tools/read-file.js +100 -53
  289. package/dist/src/tools/read-file.js.map +1 -1
  290. package/dist/src/tools/read-file.test.js +238 -111
  291. package/dist/src/tools/read-file.test.js.map +1 -1
  292. package/dist/src/tools/read-many-files.d.ts +3 -6
  293. package/dist/src/tools/read-many-files.js +232 -157
  294. package/dist/src/tools/read-many-files.js.map +1 -1
  295. package/dist/src/tools/read-many-files.test.js +231 -34
  296. package/dist/src/tools/read-many-files.test.js.map +1 -1
  297. package/dist/src/tools/shell.d.ts +6 -28
  298. package/dist/src/tools/shell.js +249 -366
  299. package/dist/src/tools/shell.js.map +1 -1
  300. package/dist/src/tools/shell.test.js +305 -384
  301. package/dist/src/tools/shell.test.js.map +1 -1
  302. package/dist/src/tools/tool-error.d.ts +27 -0
  303. package/dist/src/tools/tool-error.js +32 -0
  304. package/dist/src/tools/tool-error.js.map +1 -0
  305. package/dist/src/tools/tool-registry.d.ts +38 -23
  306. package/dist/src/tools/tool-registry.js +127 -99
  307. package/dist/src/tools/tool-registry.js.map +1 -1
  308. package/dist/src/tools/tool-registry.test.js +37 -212
  309. package/dist/src/tools/tool-registry.test.js.map +1 -1
  310. package/dist/src/tools/tools.d.ts +145 -92
  311. package/dist/src/tools/tools.js +188 -61
  312. package/dist/src/tools/tools.js.map +1 -1
  313. package/dist/src/tools/tools.test.d.ts +6 -0
  314. package/dist/src/tools/tools.test.js +206 -0
  315. package/dist/src/tools/tools.test.js.map +1 -0
  316. package/dist/src/tools/web-fetch.d.ts +4 -7
  317. package/dist/src/tools/web-fetch.js +58 -64
  318. package/dist/src/tools/web-fetch.js.map +1 -1
  319. package/dist/src/tools/web-fetch.test.js +8 -4
  320. package/dist/src/tools/web-fetch.test.js.map +1 -1
  321. package/dist/src/tools/web-search.d.ts +4 -5
  322. package/dist/src/tools/web-search.js +47 -51
  323. package/dist/src/tools/web-search.js.map +1 -1
  324. package/dist/src/tools/web-search.test.d.ts +6 -0
  325. package/dist/src/tools/web-search.test.js +139 -0
  326. package/dist/src/tools/web-search.test.js.map +1 -0
  327. package/dist/src/tools/write-file.d.ts +20 -11
  328. package/dist/src/tools/write-file.js +198 -141
  329. package/dist/src/tools/write-file.js.map +1 -1
  330. package/dist/src/tools/write-file.test.js +190 -76
  331. package/dist/src/tools/write-file.test.js.map +1 -1
  332. package/dist/src/utils/bfsFileSearch.js +51 -27
  333. package/dist/src/utils/bfsFileSearch.js.map +1 -1
  334. package/dist/src/utils/bfsFileSearch.test.js +137 -136
  335. package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
  336. package/dist/src/utils/browser.js +4 -3
  337. package/dist/src/utils/browser.js.map +1 -1
  338. package/dist/src/utils/editCorrector.js +23 -24
  339. package/dist/src/utils/editCorrector.js.map +1 -1
  340. package/dist/src/utils/editor.d.ts +2 -2
  341. package/dist/src/utils/editor.js +23 -6
  342. package/dist/src/utils/editor.js.map +1 -1
  343. package/dist/src/utils/editor.test.js +67 -15
  344. package/dist/src/utils/editor.test.js.map +1 -1
  345. package/dist/src/utils/environmentContext.d.ts +21 -0
  346. package/dist/src/utils/environmentContext.js +90 -0
  347. package/dist/src/utils/environmentContext.js.map +1 -0
  348. package/dist/src/utils/environmentContext.test.d.ts +6 -0
  349. package/dist/src/utils/environmentContext.test.js +140 -0
  350. package/dist/src/utils/environmentContext.test.js.map +1 -0
  351. package/dist/src/utils/errorParsing.d.ts +8 -0
  352. package/dist/src/utils/errorParsing.js +93 -0
  353. package/dist/src/utils/errorParsing.js.map +1 -0
  354. package/dist/src/utils/errorParsing.test.d.ts +6 -0
  355. package/dist/src/utils/errorParsing.test.js +172 -0
  356. package/dist/src/utils/errorParsing.test.js.map +1 -0
  357. package/dist/src/utils/errorReporting.d.ts +1 -1
  358. package/dist/src/utils/errorReporting.js +2 -2
  359. package/dist/src/utils/errorReporting.js.map +1 -1
  360. package/dist/src/utils/errorReporting.test.js +44 -38
  361. package/dist/src/utils/errorReporting.test.js.map +1 -1
  362. package/dist/src/utils/fileUtils.d.ts +9 -1
  363. package/dist/src/utils/fileUtils.js +27 -13
  364. package/dist/src/utils/fileUtils.js.map +1 -1
  365. package/dist/src/utils/fileUtils.test.js +61 -18
  366. package/dist/src/utils/fileUtils.test.js.map +1 -1
  367. package/dist/src/utils/filesearch/crawlCache.d.ts +25 -0
  368. package/dist/src/utils/filesearch/crawlCache.js +57 -0
  369. package/dist/src/utils/filesearch/crawlCache.js.map +1 -0
  370. package/dist/src/utils/filesearch/crawlCache.test.d.ts +6 -0
  371. package/dist/src/utils/filesearch/crawlCache.test.js +103 -0
  372. package/dist/src/utils/filesearch/crawlCache.test.js.map +1 -0
  373. package/dist/src/utils/filesearch/crawler.d.ts +15 -0
  374. package/dist/src/utils/filesearch/crawler.js +50 -0
  375. package/dist/src/utils/filesearch/crawler.js.map +1 -0
  376. package/dist/src/utils/filesearch/crawler.test.d.ts +6 -0
  377. package/dist/src/utils/filesearch/crawler.test.js +468 -0
  378. package/dist/src/utils/filesearch/crawler.test.js.map +1 -0
  379. package/dist/src/utils/filesearch/fileSearch.d.ts +37 -0
  380. package/dist/src/utils/filesearch/fileSearch.js +186 -0
  381. package/dist/src/utils/filesearch/fileSearch.js.map +1 -0
  382. package/dist/src/utils/filesearch/fileSearch.test.d.ts +6 -0
  383. package/dist/src/utils/filesearch/fileSearch.test.js +552 -0
  384. package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -0
  385. package/dist/src/utils/filesearch/ignore.d.ts +42 -0
  386. package/dist/src/utils/filesearch/ignore.js +106 -0
  387. package/dist/src/utils/filesearch/ignore.js.map +1 -0
  388. package/dist/src/utils/filesearch/ignore.test.d.ts +6 -0
  389. package/dist/src/utils/filesearch/ignore.test.js +144 -0
  390. package/dist/src/utils/filesearch/ignore.test.js.map +1 -0
  391. package/dist/src/utils/filesearch/result-cache.d.ts +33 -0
  392. package/dist/src/utils/filesearch/result-cache.js +59 -0
  393. package/dist/src/utils/filesearch/result-cache.js.map +1 -0
  394. package/dist/src/utils/filesearch/result-cache.test.d.ts +6 -0
  395. package/dist/src/utils/filesearch/result-cache.test.js +46 -0
  396. package/dist/src/utils/filesearch/result-cache.test.js.map +1 -0
  397. package/dist/src/utils/flashFallback.integration.test.js +6 -0
  398. package/dist/src/utils/flashFallback.integration.test.js.map +1 -1
  399. package/dist/src/utils/formatters.d.ts +6 -0
  400. package/dist/src/utils/formatters.js +16 -0
  401. package/dist/src/utils/formatters.js.map +1 -0
  402. package/dist/src/utils/getFolderStructure.test.js +11 -13
  403. package/dist/src/utils/getFolderStructure.test.js.map +1 -1
  404. package/dist/src/utils/gitIgnoreParser.js +5 -11
  405. package/dist/src/utils/gitIgnoreParser.js.map +1 -1
  406. package/dist/src/utils/gitIgnoreParser.test.js +58 -61
  407. package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
  408. package/dist/src/utils/memoryDiscovery.d.ts +1 -1
  409. package/dist/src/utils/memoryDiscovery.js +76 -83
  410. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  411. package/dist/src/utils/memoryDiscovery.test.js +122 -372
  412. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  413. package/dist/src/utils/memoryImportProcessor.d.ts +19 -12
  414. package/dist/src/utils/memoryImportProcessor.js +240 -85
  415. package/dist/src/utils/memoryImportProcessor.js.map +1 -1
  416. package/dist/src/utils/memoryImportProcessor.test.js +593 -51
  417. package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
  418. package/dist/src/utils/nextSpeakerChecker.js +4 -25
  419. package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
  420. package/dist/src/utils/partUtils.d.ts +14 -0
  421. package/dist/src/utils/partUtils.js +65 -0
  422. package/dist/src/utils/partUtils.js.map +1 -0
  423. package/dist/src/utils/partUtils.test.d.ts +6 -0
  424. package/dist/src/utils/partUtils.test.js +130 -0
  425. package/dist/src/utils/partUtils.test.js.map +1 -0
  426. package/dist/src/utils/paths.d.ts +18 -2
  427. package/dist/src/utils/paths.js +39 -7
  428. package/dist/src/utils/paths.js.map +1 -1
  429. package/dist/src/utils/paths.test.d.ts +6 -0
  430. package/dist/src/utils/paths.test.js +225 -0
  431. package/dist/src/utils/paths.test.js.map +1 -0
  432. package/dist/src/utils/quotaErrorDetection.d.ts +1 -5
  433. package/dist/src/utils/quotaErrorDetection.js.map +1 -1
  434. package/dist/src/utils/retry.d.ts +3 -0
  435. package/dist/src/utils/retry.js.map +1 -1
  436. package/dist/src/utils/retry.test.js.map +1 -1
  437. package/dist/src/utils/schemaValidator.d.ts +1 -8
  438. package/dist/src/utils/schemaValidator.js +1 -32
  439. package/dist/src/utils/schemaValidator.js.map +1 -1
  440. package/dist/src/utils/secure-browser-launcher.d.ts +23 -0
  441. package/dist/src/utils/secure-browser-launcher.js +165 -0
  442. package/dist/src/utils/secure-browser-launcher.js.map +1 -0
  443. package/dist/src/utils/secure-browser-launcher.test.d.ts +6 -0
  444. package/dist/src/utils/secure-browser-launcher.test.js +149 -0
  445. package/dist/src/utils/secure-browser-launcher.test.js.map +1 -0
  446. package/dist/src/utils/shell-utils.d.ts +117 -0
  447. package/dist/src/utils/shell-utils.js +376 -0
  448. package/dist/src/utils/shell-utils.js.map +1 -0
  449. package/dist/src/utils/shell-utils.test.d.ts +6 -0
  450. package/dist/src/utils/shell-utils.test.js +328 -0
  451. package/dist/src/utils/shell-utils.test.js.map +1 -0
  452. package/dist/src/utils/summarizer.js +3 -32
  453. package/dist/src/utils/summarizer.js.map +1 -1
  454. package/dist/src/utils/systemEncoding.js +1 -1
  455. package/dist/src/utils/systemEncoding.js.map +1 -1
  456. package/dist/src/utils/systemEncoding.test.js +23 -23
  457. package/dist/src/utils/systemEncoding.test.js.map +1 -1
  458. package/dist/src/utils/textUtils.d.ts +13 -0
  459. package/dist/src/utils/textUtils.js +28 -0
  460. package/dist/src/utils/textUtils.js.map +1 -0
  461. package/dist/src/utils/user_account.js +58 -48
  462. package/dist/src/utils/user_account.js.map +1 -1
  463. package/dist/src/utils/user_account.test.js +76 -9
  464. package/dist/src/utils/user_account.test.js.map +1 -1
  465. package/dist/src/utils/workspaceContext.d.ts +66 -0
  466. package/dist/src/utils/workspaceContext.js +165 -0
  467. package/dist/src/utils/workspaceContext.js.map +1 -0
  468. package/dist/src/utils/workspaceContext.test.d.ts +6 -0
  469. package/dist/src/utils/workspaceContext.test.js +293 -0
  470. package/dist/src/utils/workspaceContext.test.js.map +1 -0
  471. package/dist/tsconfig.tsbuildinfo +1 -1
  472. package/package.json +14 -3
  473. package/dist/src/core/geminiRequest.test.js +0 -72
  474. package/dist/src/core/geminiRequest.test.js.map +0 -1
  475. package/dist/src/core/modelCheck.d.ts +0 -14
  476. package/dist/src/core/modelCheck.js +0 -62
  477. package/dist/src/core/modelCheck.js.map +0 -1
  478. package/dist/src/services/ideContext.d.ts +0 -178
  479. package/dist/src/services/ideContext.js +0 -105
  480. package/dist/src/services/ideContext.js.map +0 -1
  481. package/dist/src/services/ideContext.test.js +0 -111
  482. package/dist/src/services/ideContext.test.js.map +0 -1
  483. /package/dist/src/core/{geminiRequest.test.d.ts → subagent.test.d.ts} +0 -0
  484. /package/dist/src/{services/ideContext.test.d.ts → ide/detect-ide.test.d.ts} +0 -0
@@ -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,CAA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right 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,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,wCAAwC;AACxC,MAAM,YAAY,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAE/C,eAAe;AACf,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAC9B,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1B,SAAS,EAAE,GAAG,EAAE,CAAC,YAAY;CAC9B,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,IAAI,gBAAgD,CAAC;IAErD,UAAU,CAAC,GAAG,EAAE;QACd,EAAE,CAAC,aAAa,EAAE,CAAC;QACnB,YAAY,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;QAC3D,gBAAgB,GAAG,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,gBAAgB,EAAE,CAAC;YACrB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAC/D,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CAAC,OAAO,CACtE,wBAAwB,CACzB,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;YACrD,WAAW,CAAC,OAAO,CAAC,CAAC;YAErB,+BAA+B;YAC/B,YAAY,CAAC,qBAAqB,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;YACnE,qCAAqC;YACrC,YAAY,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;YAE/D,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"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Config } from '../config/config.js';
7
+ /**
8
+ * An identifier for the shell type.
9
+ */
10
+ export type ShellType = 'cmd' | 'powershell' | 'bash';
11
+ /**
12
+ * Defines the configuration required to execute a command string within a specific shell.
13
+ */
14
+ export interface ShellConfiguration {
15
+ /** The path or name of the shell executable (e.g., 'bash', 'cmd.exe'). */
16
+ executable: string;
17
+ /**
18
+ * The arguments required by the shell to execute a subsequent string argument.
19
+ */
20
+ argsPrefix: string[];
21
+ /** An identifier for the shell type. */
22
+ shell: ShellType;
23
+ }
24
+ /**
25
+ * Determines the appropriate shell configuration for the current platform.
26
+ *
27
+ * This ensures we can execute command strings predictably and securely across platforms
28
+ * using the `spawn(executable, [...argsPrefix, commandString], { shell: false })` pattern.
29
+ *
30
+ * @returns The ShellConfiguration for the current environment.
31
+ */
32
+ export declare function getShellConfiguration(): ShellConfiguration;
33
+ /**
34
+ * Export the platform detection constant for use in process management (e.g., killing processes).
35
+ */
36
+ export declare const isWindows: () => boolean;
37
+ /**
38
+ * Escapes a string so that it can be safely used as a single argument
39
+ * in a shell command, preventing command injection.
40
+ *
41
+ * @param arg The argument string to escape.
42
+ * @param shell The type of shell the argument is for.
43
+ * @returns The shell-escaped string.
44
+ */
45
+ export declare function escapeShellArg(arg: string, shell: ShellType): string;
46
+ /**
47
+ * Splits a shell command into a list of individual commands, respecting quotes.
48
+ * This is used to separate chained commands (e.g., using &&, ||, ;).
49
+ * @param command The shell command string to parse
50
+ * @returns An array of individual command strings
51
+ */
52
+ export declare function splitCommands(command: string): string[];
53
+ /**
54
+ * Extracts the root command from a given shell command string.
55
+ * This is used to identify the base command for permission checks.
56
+ * @param command The shell command string to parse
57
+ * @returns The root command name, or undefined if it cannot be determined
58
+ * @example getCommandRoot("ls -la /tmp") returns "ls"
59
+ * @example getCommandRoot("git status && npm test") returns "git"
60
+ */
61
+ export declare function getCommandRoot(command: string): string | undefined;
62
+ export declare function getCommandRoots(command: string): string[];
63
+ export declare function stripShellWrapper(command: string): string;
64
+ /**
65
+ * Detects command substitution patterns in a shell command, following bash quoting rules:
66
+ * - Single quotes ('): Everything literal, no substitution possible
67
+ * - Double quotes ("): Command substitution with $() and backticks unless escaped with \
68
+ * - No quotes: Command substitution with $(), <(), and backticks
69
+ * @param command The shell command string to check
70
+ * @returns true if command substitution would be executed by bash
71
+ */
72
+ export declare function detectCommandSubstitution(command: string): boolean;
73
+ /**
74
+ * Checks a shell command against security policies and allowlists.
75
+ *
76
+ * This function operates in one of two modes depending on the presence of
77
+ * the `sessionAllowlist` parameter:
78
+ *
79
+ * 1. **"Default Deny" Mode (sessionAllowlist is provided):** This is the
80
+ * strictest mode, used for user-defined scripts like custom commands.
81
+ * A command is only permitted if it is found on the global `coreTools`
82
+ * allowlist OR the provided `sessionAllowlist`. It must not be on the
83
+ * global `excludeTools` blocklist.
84
+ *
85
+ * 2. **"Default Allow" Mode (sessionAllowlist is NOT provided):** This mode
86
+ * is used for direct tool invocations (e.g., by the model). If a strict
87
+ * global `coreTools` allowlist exists, commands must be on it. Otherwise,
88
+ * any command is permitted as long as it is not on the `excludeTools`
89
+ * blocklist.
90
+ *
91
+ * @param command The shell command string to validate.
92
+ * @param config The application configuration.
93
+ * @param sessionAllowlist A session-level list of approved commands. Its
94
+ * presence activates "Default Deny" mode.
95
+ * @returns An object detailing which commands are not allowed.
96
+ */
97
+ export declare function checkCommandPermissions(command: string, config: Config, sessionAllowlist?: Set<string>): {
98
+ allAllowed: boolean;
99
+ disallowedCommands: string[];
100
+ blockReason?: string;
101
+ isHardDenial?: boolean;
102
+ };
103
+ /**
104
+ * Determines whether a given shell command is allowed to execute based on
105
+ * the tool's configuration including allowlists and blocklists.
106
+ *
107
+ * This function operates in "default allow" mode. It is a wrapper around
108
+ * `checkCommandPermissions`.
109
+ *
110
+ * @param command The shell command string to validate.
111
+ * @param config The application configuration.
112
+ * @returns An object with 'allowed' boolean and optional 'reason' string if not allowed.
113
+ */
114
+ export declare function isCommandAllowed(command: string, config: Config): {
115
+ allowed: boolean;
116
+ reason?: string;
117
+ };
@@ -0,0 +1,376 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import os from 'os';
7
+ import { quote } from 'shell-quote';
8
+ /**
9
+ * Determines the appropriate shell configuration for the current platform.
10
+ *
11
+ * This ensures we can execute command strings predictably and securely across platforms
12
+ * using the `spawn(executable, [...argsPrefix, commandString], { shell: false })` pattern.
13
+ *
14
+ * @returns The ShellConfiguration for the current environment.
15
+ */
16
+ export function getShellConfiguration() {
17
+ if (isWindows()) {
18
+ const comSpec = process.env['ComSpec'] || 'cmd.exe';
19
+ const executable = comSpec.toLowerCase();
20
+ if (executable.endsWith('powershell.exe') ||
21
+ executable.endsWith('pwsh.exe')) {
22
+ // For PowerShell, the arguments are different.
23
+ // -NoProfile: Speeds up startup.
24
+ // -Command: Executes the following command.
25
+ return {
26
+ executable: comSpec,
27
+ argsPrefix: ['-NoProfile', '-Command'],
28
+ shell: 'powershell',
29
+ };
30
+ }
31
+ // Default to cmd.exe for anything else on Windows.
32
+ // Flags for CMD:
33
+ // /d: Skip execution of AutoRun commands.
34
+ // /s: Modifies the treatment of the command string (important for quoting).
35
+ // /c: Carries out the command specified by the string and then terminates.
36
+ return {
37
+ executable: comSpec,
38
+ argsPrefix: ['/d', '/s', '/c'],
39
+ shell: 'cmd',
40
+ };
41
+ }
42
+ // Unix-like systems (Linux, macOS)
43
+ return { executable: 'bash', argsPrefix: ['-c'], shell: 'bash' };
44
+ }
45
+ /**
46
+ * Export the platform detection constant for use in process management (e.g., killing processes).
47
+ */
48
+ export const isWindows = () => os.platform() === 'win32';
49
+ /**
50
+ * Escapes a string so that it can be safely used as a single argument
51
+ * in a shell command, preventing command injection.
52
+ *
53
+ * @param arg The argument string to escape.
54
+ * @param shell The type of shell the argument is for.
55
+ * @returns The shell-escaped string.
56
+ */
57
+ export function escapeShellArg(arg, shell) {
58
+ if (!arg) {
59
+ return '';
60
+ }
61
+ switch (shell) {
62
+ case 'powershell':
63
+ // For PowerShell, wrap in single quotes and escape internal single quotes by doubling them.
64
+ return `'${arg.replace(/'/g, "''")}'`;
65
+ case 'cmd':
66
+ // Simple Windows escaping for cmd.exe: wrap in double quotes and escape inner double quotes.
67
+ return `"${arg.replace(/"/g, '""')}"`;
68
+ case 'bash':
69
+ default:
70
+ // POSIX shell escaping using shell-quote.
71
+ return quote([arg]);
72
+ }
73
+ }
74
+ /**
75
+ * Splits a shell command into a list of individual commands, respecting quotes.
76
+ * This is used to separate chained commands (e.g., using &&, ||, ;).
77
+ * @param command The shell command string to parse
78
+ * @returns An array of individual command strings
79
+ */
80
+ export function splitCommands(command) {
81
+ const commands = [];
82
+ let currentCommand = '';
83
+ let inSingleQuotes = false;
84
+ let inDoubleQuotes = false;
85
+ let i = 0;
86
+ while (i < command.length) {
87
+ const char = command[i];
88
+ const nextChar = command[i + 1];
89
+ if (char === '\\' && i < command.length - 1) {
90
+ currentCommand += char + command[i + 1];
91
+ i += 2;
92
+ continue;
93
+ }
94
+ if (char === "'" && !inDoubleQuotes) {
95
+ inSingleQuotes = !inSingleQuotes;
96
+ }
97
+ else if (char === '"' && !inSingleQuotes) {
98
+ inDoubleQuotes = !inDoubleQuotes;
99
+ }
100
+ if (!inSingleQuotes && !inDoubleQuotes) {
101
+ if ((char === '&' && nextChar === '&') ||
102
+ (char === '|' && nextChar === '|')) {
103
+ commands.push(currentCommand.trim());
104
+ currentCommand = '';
105
+ i++; // Skip the next character
106
+ }
107
+ else if (char === ';' || char === '&' || char === '|') {
108
+ commands.push(currentCommand.trim());
109
+ currentCommand = '';
110
+ }
111
+ else {
112
+ currentCommand += char;
113
+ }
114
+ }
115
+ else {
116
+ currentCommand += char;
117
+ }
118
+ i++;
119
+ }
120
+ if (currentCommand.trim()) {
121
+ commands.push(currentCommand.trim());
122
+ }
123
+ return commands.filter(Boolean); // Filter out any empty strings
124
+ }
125
+ /**
126
+ * Extracts the root command from a given shell command string.
127
+ * This is used to identify the base command for permission checks.
128
+ * @param command The shell command string to parse
129
+ * @returns The root command name, or undefined if it cannot be determined
130
+ * @example getCommandRoot("ls -la /tmp") returns "ls"
131
+ * @example getCommandRoot("git status && npm test") returns "git"
132
+ */
133
+ export function getCommandRoot(command) {
134
+ const trimmedCommand = command.trim();
135
+ if (!trimmedCommand) {
136
+ return undefined;
137
+ }
138
+ // This regex is designed to find the first "word" of a command,
139
+ // while respecting quotes. It looks for a sequence of non-whitespace
140
+ // characters that are not inside quotes.
141
+ const match = trimmedCommand.match(/^"([^"]+)"|^'([^']+)'|^(\S+)/);
142
+ if (match) {
143
+ // The first element in the match array is the full match.
144
+ // The subsequent elements are the capture groups.
145
+ // We prefer a captured group because it will be unquoted.
146
+ const commandRoot = match[1] || match[2] || match[3];
147
+ if (commandRoot) {
148
+ // If the command is a path, return the last component.
149
+ return commandRoot.split(/[\\/]/).pop();
150
+ }
151
+ }
152
+ return undefined;
153
+ }
154
+ export function getCommandRoots(command) {
155
+ if (!command) {
156
+ return [];
157
+ }
158
+ return splitCommands(command)
159
+ .map((c) => getCommandRoot(c))
160
+ .filter((c) => !!c);
161
+ }
162
+ export function stripShellWrapper(command) {
163
+ const pattern = /^\s*(?:sh|bash|zsh|cmd.exe)\s+(?:\/c|-c)\s+/;
164
+ const match = command.match(pattern);
165
+ if (match) {
166
+ let newCommand = command.substring(match[0].length).trim();
167
+ if ((newCommand.startsWith('"') && newCommand.endsWith('"')) ||
168
+ (newCommand.startsWith("'") && newCommand.endsWith("'"))) {
169
+ newCommand = newCommand.substring(1, newCommand.length - 1);
170
+ }
171
+ return newCommand;
172
+ }
173
+ return command.trim();
174
+ }
175
+ /**
176
+ * Detects command substitution patterns in a shell command, following bash quoting rules:
177
+ * - Single quotes ('): Everything literal, no substitution possible
178
+ * - Double quotes ("): Command substitution with $() and backticks unless escaped with \
179
+ * - No quotes: Command substitution with $(), <(), and backticks
180
+ * @param command The shell command string to check
181
+ * @returns true if command substitution would be executed by bash
182
+ */
183
+ export function detectCommandSubstitution(command) {
184
+ let inSingleQuotes = false;
185
+ let inDoubleQuotes = false;
186
+ let inBackticks = false;
187
+ let i = 0;
188
+ while (i < command.length) {
189
+ const char = command[i];
190
+ const nextChar = command[i + 1];
191
+ // Handle escaping - only works outside single quotes
192
+ if (char === '\\' && !inSingleQuotes) {
193
+ i += 2; // Skip the escaped character
194
+ continue;
195
+ }
196
+ // Handle quote state changes
197
+ if (char === "'" && !inDoubleQuotes && !inBackticks) {
198
+ inSingleQuotes = !inSingleQuotes;
199
+ }
200
+ else if (char === '"' && !inSingleQuotes && !inBackticks) {
201
+ inDoubleQuotes = !inDoubleQuotes;
202
+ }
203
+ else if (char === '`' && !inSingleQuotes) {
204
+ // Backticks work outside single quotes (including in double quotes)
205
+ inBackticks = !inBackticks;
206
+ }
207
+ // Check for command substitution patterns that would be executed
208
+ if (!inSingleQuotes) {
209
+ // $(...) command substitution - works in double quotes and unquoted
210
+ if (char === '$' && nextChar === '(') {
211
+ return true;
212
+ }
213
+ // <(...) process substitution - works unquoted only (not in double quotes)
214
+ if (char === '<' && nextChar === '(' && !inDoubleQuotes && !inBackticks) {
215
+ return true;
216
+ }
217
+ // Backtick command substitution - check for opening backtick
218
+ // (We track the state above, so this catches the start of backtick substitution)
219
+ if (char === '`' && !inBackticks) {
220
+ return true;
221
+ }
222
+ }
223
+ i++;
224
+ }
225
+ return false;
226
+ }
227
+ /**
228
+ * Checks a shell command against security policies and allowlists.
229
+ *
230
+ * This function operates in one of two modes depending on the presence of
231
+ * the `sessionAllowlist` parameter:
232
+ *
233
+ * 1. **"Default Deny" Mode (sessionAllowlist is provided):** This is the
234
+ * strictest mode, used for user-defined scripts like custom commands.
235
+ * A command is only permitted if it is found on the global `coreTools`
236
+ * allowlist OR the provided `sessionAllowlist`. It must not be on the
237
+ * global `excludeTools` blocklist.
238
+ *
239
+ * 2. **"Default Allow" Mode (sessionAllowlist is NOT provided):** This mode
240
+ * is used for direct tool invocations (e.g., by the model). If a strict
241
+ * global `coreTools` allowlist exists, commands must be on it. Otherwise,
242
+ * any command is permitted as long as it is not on the `excludeTools`
243
+ * blocklist.
244
+ *
245
+ * @param command The shell command string to validate.
246
+ * @param config The application configuration.
247
+ * @param sessionAllowlist A session-level list of approved commands. Its
248
+ * presence activates "Default Deny" mode.
249
+ * @returns An object detailing which commands are not allowed.
250
+ */
251
+ export function checkCommandPermissions(command, config, sessionAllowlist) {
252
+ // Disallow command substitution for security.
253
+ if (detectCommandSubstitution(command)) {
254
+ return {
255
+ allAllowed: false,
256
+ disallowedCommands: [command],
257
+ blockReason: 'Command substitution using $(), <(), or >() is not allowed for security reasons',
258
+ isHardDenial: true,
259
+ };
260
+ }
261
+ const SHELL_TOOL_NAMES = ['run_shell_command', 'ShellTool'];
262
+ const normalize = (cmd) => cmd.trim().replace(/\s+/g, ' ');
263
+ const isPrefixedBy = (cmd, prefix) => {
264
+ if (!cmd.startsWith(prefix)) {
265
+ return false;
266
+ }
267
+ return cmd.length === prefix.length || cmd[prefix.length] === ' ';
268
+ };
269
+ const extractCommands = (tools) => tools.flatMap((tool) => {
270
+ for (const toolName of SHELL_TOOL_NAMES) {
271
+ if (tool.startsWith(`${toolName}(`) && tool.endsWith(')')) {
272
+ return [normalize(tool.slice(toolName.length + 1, -1))];
273
+ }
274
+ }
275
+ return [];
276
+ });
277
+ const coreTools = config.getCoreTools() || [];
278
+ const excludeTools = config.getExcludeTools() || [];
279
+ const commandsToValidate = splitCommands(command).map(normalize);
280
+ // 1. Blocklist Check (Highest Priority)
281
+ if (SHELL_TOOL_NAMES.some((name) => excludeTools.includes(name))) {
282
+ return {
283
+ allAllowed: false,
284
+ disallowedCommands: commandsToValidate,
285
+ blockReason: 'Shell tool is globally disabled in configuration',
286
+ isHardDenial: true,
287
+ };
288
+ }
289
+ const blockedCommands = extractCommands(excludeTools);
290
+ for (const cmd of commandsToValidate) {
291
+ if (blockedCommands.some((blocked) => isPrefixedBy(cmd, blocked))) {
292
+ return {
293
+ allAllowed: false,
294
+ disallowedCommands: [cmd],
295
+ blockReason: `Command '${cmd}' is blocked by configuration`,
296
+ isHardDenial: true,
297
+ };
298
+ }
299
+ }
300
+ const globallyAllowedCommands = extractCommands(coreTools);
301
+ const isWildcardAllowed = SHELL_TOOL_NAMES.some((name) => coreTools.includes(name));
302
+ // If there's a global wildcard, all commands are allowed at this point
303
+ // because they have already passed the blocklist check.
304
+ if (isWildcardAllowed) {
305
+ return { allAllowed: true, disallowedCommands: [] };
306
+ }
307
+ if (sessionAllowlist) {
308
+ // "DEFAULT DENY" MODE: A session allowlist is provided.
309
+ // All commands must be in either the session or global allowlist.
310
+ const disallowedCommands = [];
311
+ for (const cmd of commandsToValidate) {
312
+ const isSessionAllowed = [...sessionAllowlist].some((allowed) => isPrefixedBy(cmd, normalize(allowed)));
313
+ if (isSessionAllowed)
314
+ continue;
315
+ const isGloballyAllowed = globallyAllowedCommands.some((allowed) => isPrefixedBy(cmd, allowed));
316
+ if (isGloballyAllowed)
317
+ continue;
318
+ disallowedCommands.push(cmd);
319
+ }
320
+ if (disallowedCommands.length > 0) {
321
+ return {
322
+ allAllowed: false,
323
+ disallowedCommands,
324
+ blockReason: `Command(s) not on the global or session allowlist. Disallowed commands: ${disallowedCommands
325
+ .map((c) => JSON.stringify(c))
326
+ .join(', ')}`,
327
+ isHardDenial: false, // This is a soft denial; confirmation is possible.
328
+ };
329
+ }
330
+ }
331
+ else {
332
+ // "DEFAULT ALLOW" MODE: No session allowlist.
333
+ const hasSpecificAllowedCommands = globallyAllowedCommands.length > 0;
334
+ if (hasSpecificAllowedCommands) {
335
+ const disallowedCommands = [];
336
+ for (const cmd of commandsToValidate) {
337
+ const isGloballyAllowed = globallyAllowedCommands.some((allowed) => isPrefixedBy(cmd, allowed));
338
+ if (!isGloballyAllowed) {
339
+ disallowedCommands.push(cmd);
340
+ }
341
+ }
342
+ if (disallowedCommands.length > 0) {
343
+ return {
344
+ allAllowed: false,
345
+ disallowedCommands,
346
+ blockReason: `Command(s) not in the allowed commands list. Disallowed commands: ${disallowedCommands.map((c) => JSON.stringify(c)).join(', ')}`,
347
+ isHardDenial: false, // This is a soft denial.
348
+ };
349
+ }
350
+ }
351
+ // If no specific global allowlist exists, and it passed the blocklist,
352
+ // the command is allowed by default.
353
+ }
354
+ // If all checks for the current mode pass, the command is allowed.
355
+ return { allAllowed: true, disallowedCommands: [] };
356
+ }
357
+ /**
358
+ * Determines whether a given shell command is allowed to execute based on
359
+ * the tool's configuration including allowlists and blocklists.
360
+ *
361
+ * This function operates in "default allow" mode. It is a wrapper around
362
+ * `checkCommandPermissions`.
363
+ *
364
+ * @param command The shell command string to validate.
365
+ * @param config The application configuration.
366
+ * @returns An object with 'allowed' boolean and optional 'reason' string if not allowed.
367
+ */
368
+ export function isCommandAllowed(command, config) {
369
+ // By not providing a sessionAllowlist, we invoke "default allow" behavior.
370
+ const { allAllowed, blockReason } = checkCommandPermissions(command, config);
371
+ if (allAllowed) {
372
+ return { allowed: true };
373
+ }
374
+ return { allowed: false, reason: blockReason };
375
+ }
376
+ //# sourceMappingURL=shell-utils.js.map