@machina.ai/cell-cli-core 1.0.21-rc4 → 1.4.0-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 (505) hide show
  1. package/dist/index.d.ts +6 -2
  2. package/dist/index.js +6 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/package.json +25 -11
  5. package/dist/src/code_assist/codeAssist.d.ts +6 -3
  6. package/dist/src/code_assist/codeAssist.js +12 -0
  7. package/dist/src/code_assist/codeAssist.js.map +1 -1
  8. package/dist/src/code_assist/converter.d.ts +3 -1
  9. package/dist/src/code_assist/converter.js +37 -5
  10. package/dist/src/code_assist/converter.js.map +1 -1
  11. package/dist/src/code_assist/converter.test.js +83 -0
  12. package/dist/src/code_assist/converter.test.js.map +1 -1
  13. package/dist/src/code_assist/oauth2.d.ts +2 -1
  14. package/dist/src/code_assist/oauth2.js +85 -49
  15. package/dist/src/code_assist/oauth2.js.map +1 -1
  16. package/dist/src/code_assist/oauth2.test.js +317 -15
  17. package/dist/src/code_assist/oauth2.test.js.map +1 -1
  18. package/dist/src/code_assist/server.d.ts +5 -5
  19. package/dist/src/code_assist/server.js +1 -1
  20. package/dist/src/code_assist/server.js.map +1 -1
  21. package/dist/src/code_assist/setup.d.ts +1 -1
  22. package/dist/src/code_assist/setup.js +1 -1
  23. package/dist/src/code_assist/setup.js.map +1 -1
  24. package/dist/src/code_assist/setup.test.js.map +1 -1
  25. package/dist/src/config/config.d.ts +53 -15
  26. package/dist/src/config/config.js +127 -47
  27. package/dist/src/config/config.js.map +1 -1
  28. package/dist/src/config/config.test.js +151 -6
  29. package/dist/src/config/config.test.js.map +1 -1
  30. package/dist/src/config/models.d.ts +1 -0
  31. package/dist/src/config/models.js +2 -0
  32. package/dist/src/config/models.js.map +1 -1
  33. package/dist/src/config/storage.d.ts +32 -0
  34. package/dist/src/config/storage.js +90 -0
  35. package/dist/src/config/storage.js.map +1 -0
  36. package/dist/src/config/storage.test.js +43 -0
  37. package/dist/src/config/storage.test.js.map +1 -0
  38. package/dist/src/core/client.d.ts +21 -11
  39. package/dist/src/core/client.js +83 -26
  40. package/dist/src/core/client.js.map +1 -1
  41. package/dist/src/core/client.test.js +398 -88
  42. package/dist/src/core/client.test.js.map +1 -1
  43. package/dist/src/core/contentGenerator.d.ts +6 -6
  44. package/dist/src/core/contentGenerator.js +4 -3
  45. package/dist/src/core/contentGenerator.js.map +1 -1
  46. package/dist/src/core/contentGenerator.test.js.map +1 -1
  47. package/dist/src/core/coreToolScheduler.d.ts +14 -5
  48. package/dist/src/core/coreToolScheduler.js +120 -49
  49. package/dist/src/core/coreToolScheduler.js.map +1 -1
  50. package/dist/src/core/coreToolScheduler.test.js +383 -72
  51. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  52. package/dist/src/core/geminiChat.d.ts +48 -15
  53. package/dist/src/core/geminiChat.js +327 -154
  54. package/dist/src/core/geminiChat.js.map +1 -1
  55. package/dist/src/core/geminiChat.test.js +1041 -257
  56. package/dist/src/core/geminiChat.test.js.map +1 -1
  57. package/dist/src/core/geminiRequest.js +1 -0
  58. package/dist/src/core/geminiRequest.js.map +1 -1
  59. package/dist/src/core/logger.d.ts +4 -2
  60. package/dist/src/core/logger.js +4 -3
  61. package/dist/src/core/logger.js.map +1 -1
  62. package/dist/src/core/logger.test.js +19 -18
  63. package/dist/src/core/logger.test.js.map +1 -1
  64. package/dist/src/core/loggingContentGenerator.d.ts +3 -3
  65. package/dist/src/core/loggingContentGenerator.js +11 -9
  66. package/dist/src/core/loggingContentGenerator.js.map +1 -1
  67. package/dist/src/core/nonInteractiveToolExecutor.d.ts +3 -5
  68. package/dist/src/core/nonInteractiveToolExecutor.js +15 -123
  69. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
  70. package/dist/src/core/nonInteractiveToolExecutor.test.js +116 -90
  71. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  72. package/dist/src/core/prompts.js +8 -7
  73. package/dist/src/core/prompts.js.map +1 -1
  74. package/dist/src/core/prompts.test.js +21 -21
  75. package/dist/src/core/prompts.test.js.map +1 -1
  76. package/dist/src/core/subagent.d.ts +24 -18
  77. package/dist/src/core/subagent.js +126 -89
  78. package/dist/src/core/subagent.js.map +1 -1
  79. package/dist/src/core/subagent.test.js +51 -35
  80. package/dist/src/core/subagent.test.js.map +1 -1
  81. package/dist/src/core/turn.d.ts +33 -8
  82. package/dist/src/core/turn.js +59 -14
  83. package/dist/src/core/turn.js.map +1 -1
  84. package/dist/src/core/turn.test.js +349 -90
  85. package/dist/src/core/turn.test.js.map +1 -1
  86. package/dist/src/generated/git-commit.d.ts +2 -2
  87. package/dist/src/generated/git-commit.js +2 -2
  88. package/dist/src/generated/git-commit.js.map +1 -1
  89. package/dist/src/ide/constants.d.ts +1 -1
  90. package/dist/src/ide/constants.js +1 -1
  91. package/dist/src/ide/constants.js.map +1 -1
  92. package/dist/src/ide/detect-ide.d.ts +8 -3
  93. package/dist/src/ide/detect-ide.js +29 -11
  94. package/dist/src/ide/detect-ide.js.map +1 -1
  95. package/dist/src/ide/detect-ide.test.js +96 -52
  96. package/dist/src/ide/detect-ide.test.js.map +1 -1
  97. package/dist/src/ide/ide-client.d.ts +18 -9
  98. package/dist/src/ide/ide-client.js +151 -33
  99. package/dist/src/ide/ide-client.js.map +1 -1
  100. package/dist/src/ide/ide-client.test.js +147 -25
  101. package/dist/src/ide/ide-client.test.js.map +1 -1
  102. package/dist/src/ide/ide-installer.d.ts +1 -1
  103. package/dist/src/ide/ide-installer.js +31 -22
  104. package/dist/src/ide/ide-installer.js.map +1 -1
  105. package/dist/src/ide/ide-installer.test.js +82 -22
  106. package/dist/src/ide/ide-installer.test.js.map +1 -1
  107. package/dist/src/ide/ideContext.d.ts +12 -0
  108. package/dist/src/ide/ideContext.js +1 -0
  109. package/dist/src/ide/ideContext.js.map +1 -1
  110. package/dist/src/ide/process-utils.d.ts +13 -6
  111. package/dist/src/ide/process-utils.js +142 -35
  112. package/dist/src/ide/process-utils.js.map +1 -1
  113. package/dist/src/ide/process-utils.test.js +158 -0
  114. package/dist/src/ide/process-utils.test.js.map +1 -0
  115. package/dist/src/index.d.ts +12 -2
  116. package/dist/src/index.js +11 -1
  117. package/dist/src/index.js.map +1 -1
  118. package/dist/src/mcp/google-auth-provider.d.ts +3 -3
  119. package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
  120. package/dist/src/mcp/oauth-provider.d.ts +13 -13
  121. package/dist/src/mcp/oauth-provider.js +32 -31
  122. package/dist/src/mcp/oauth-provider.js.map +1 -1
  123. package/dist/src/mcp/oauth-provider.test.js +75 -36
  124. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  125. package/dist/src/mcp/oauth-token-storage.d.ts +9 -31
  126. package/dist/src/mcp/oauth-token-storage.js +10 -13
  127. package/dist/src/mcp/oauth-token-storage.js.map +1 -1
  128. package/dist/src/mcp/oauth-token-storage.test.js +30 -27
  129. package/dist/src/mcp/oauth-token-storage.test.js.map +1 -1
  130. package/dist/src/mcp/oauth-utils.d.ts +9 -1
  131. package/dist/src/mcp/oauth-utils.js +41 -27
  132. package/dist/src/mcp/oauth-utils.js.map +1 -1
  133. package/dist/src/mcp/oauth-utils.test.js +41 -1
  134. package/dist/src/mcp/oauth-utils.test.js.map +1 -1
  135. package/dist/src/mcp/token-storage/base-token-storage.d.ts +19 -0
  136. package/dist/src/mcp/token-storage/base-token-storage.js +36 -0
  137. package/dist/src/mcp/token-storage/base-token-storage.js.map +1 -0
  138. package/dist/src/mcp/token-storage/base-token-storage.test.d.ts +6 -0
  139. package/dist/src/mcp/token-storage/base-token-storage.test.js +160 -0
  140. package/dist/src/mcp/token-storage/base-token-storage.test.js.map +1 -0
  141. package/dist/src/mcp/token-storage/file-token-storage.d.ts +24 -0
  142. package/dist/src/mcp/token-storage/file-token-storage.js +144 -0
  143. package/dist/src/mcp/token-storage/file-token-storage.js.map +1 -0
  144. package/dist/src/mcp/token-storage/file-token-storage.test.d.ts +6 -0
  145. package/dist/src/mcp/token-storage/file-token-storage.test.js +235 -0
  146. package/dist/src/mcp/token-storage/file-token-storage.test.js.map +1 -0
  147. package/dist/src/mcp/token-storage/hybrid-token-storage.d.ts +23 -0
  148. package/dist/src/mcp/token-storage/hybrid-token-storage.js +78 -0
  149. package/dist/src/mcp/token-storage/hybrid-token-storage.js.map +1 -0
  150. package/dist/src/mcp/token-storage/hybrid-token-storage.test.d.ts +6 -0
  151. package/dist/src/mcp/token-storage/hybrid-token-storage.test.js +193 -0
  152. package/dist/src/mcp/token-storage/hybrid-token-storage.test.js.map +1 -0
  153. package/dist/src/mcp/token-storage/keychain-token-storage.d.ts +31 -0
  154. package/dist/src/mcp/token-storage/keychain-token-storage.js +190 -0
  155. package/dist/src/mcp/token-storage/keychain-token-storage.js.map +1 -0
  156. package/dist/src/mcp/token-storage/keychain-token-storage.test.d.ts +6 -0
  157. package/dist/src/mcp/token-storage/keychain-token-storage.test.js +254 -0
  158. package/dist/src/mcp/token-storage/keychain-token-storage.test.js.map +1 -0
  159. package/dist/src/mcp/token-storage/types.d.ts +38 -0
  160. package/dist/src/mcp/token-storage/types.js +11 -0
  161. package/dist/src/mcp/token-storage/types.js.map +1 -0
  162. package/dist/src/prompts/mcp-prompts.d.ts +2 -2
  163. package/dist/src/prompts/prompt-registry.d.ts +1 -1
  164. package/dist/src/services/chatRecordingService.d.ts +6 -13
  165. package/dist/src/services/chatRecordingService.js +31 -19
  166. package/dist/src/services/chatRecordingService.js.map +1 -1
  167. package/dist/src/services/chatRecordingService.test.js +64 -25
  168. package/dist/src/services/chatRecordingService.test.js.map +1 -1
  169. package/dist/src/services/fileDiscoveryService.js +1 -1
  170. package/dist/src/services/fileDiscoveryService.js.map +1 -1
  171. package/dist/src/services/fileDiscoveryService.test.js +3 -3
  172. package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
  173. package/dist/src/services/fileSystemService.js +1 -1
  174. package/dist/src/services/fileSystemService.js.map +1 -1
  175. package/dist/src/services/fileSystemService.test.js +1 -1
  176. package/dist/src/services/fileSystemService.test.js.map +1 -1
  177. package/dist/src/services/gitService.d.ts +3 -1
  178. package/dist/src/services/gitService.js +21 -12
  179. package/dist/src/services/gitService.js.map +1 -1
  180. package/dist/src/services/gitService.test.js +22 -19
  181. package/dist/src/services/gitService.test.js.map +1 -1
  182. package/dist/src/services/loopDetectionService.d.ts +3 -2
  183. package/dist/src/services/loopDetectionService.js +28 -4
  184. package/dist/src/services/loopDetectionService.js.map +1 -1
  185. package/dist/src/services/loopDetectionService.test.js +23 -1
  186. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  187. package/dist/src/services/shellExecutionService.d.ts +8 -10
  188. package/dist/src/services/shellExecutionService.js +292 -135
  189. package/dist/src/services/shellExecutionService.js.map +1 -1
  190. package/dist/src/services/shellExecutionService.test.js +277 -42
  191. package/dist/src/services/shellExecutionService.test.js.map +1 -1
  192. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +18 -4
  193. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +171 -11
  194. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  195. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +103 -11
  196. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
  197. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +31 -1
  198. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +75 -0
  199. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  200. package/dist/src/telemetry/constants.d.ts +9 -0
  201. package/dist/src/telemetry/constants.js +9 -0
  202. package/dist/src/telemetry/constants.js.map +1 -1
  203. package/dist/src/telemetry/file-exporters.d.ts +5 -4
  204. package/dist/src/telemetry/file-exporters.js +1 -1
  205. package/dist/src/telemetry/file-exporters.js.map +1 -1
  206. package/dist/src/telemetry/index.d.ts +5 -2
  207. package/dist/src/telemetry/index.js +3 -2
  208. package/dist/src/telemetry/index.js.map +1 -1
  209. package/dist/src/telemetry/loggers.d.ts +8 -2
  210. package/dist/src/telemetry/loggers.js +130 -2
  211. package/dist/src/telemetry/loggers.js.map +1 -1
  212. package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
  213. package/dist/src/telemetry/loggers.test.js +105 -9
  214. package/dist/src/telemetry/loggers.test.js.map +1 -1
  215. package/dist/src/telemetry/metrics.d.ts +15 -4
  216. package/dist/src/telemetry/metrics.js +46 -8
  217. package/dist/src/telemetry/metrics.js.map +1 -1
  218. package/dist/src/telemetry/metrics.test.js +5 -25
  219. package/dist/src/telemetry/metrics.test.js.map +1 -1
  220. package/dist/src/telemetry/sdk.d.ts +1 -1
  221. package/dist/src/telemetry/sdk.js +3 -3
  222. package/dist/src/telemetry/sdk.js.map +1 -1
  223. package/dist/src/telemetry/telemetry-utils.d.ts +6 -0
  224. package/dist/src/telemetry/telemetry-utils.js +14 -0
  225. package/dist/src/telemetry/telemetry-utils.js.map +1 -0
  226. package/dist/src/telemetry/telemetry-utils.test.d.ts +6 -0
  227. package/dist/src/telemetry/telemetry-utils.test.js +40 -0
  228. package/dist/src/telemetry/telemetry-utils.test.js.map +1 -0
  229. package/dist/src/telemetry/types.d.ts +61 -6
  230. package/dist/src/telemetry/types.js +105 -4
  231. package/dist/src/telemetry/types.js.map +1 -1
  232. package/dist/src/telemetry/uiTelemetry.d.ts +2 -2
  233. package/dist/src/telemetry/uiTelemetry.js +5 -5
  234. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  235. package/dist/src/telemetry/uiTelemetry.test.js +20 -16
  236. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  237. package/dist/src/test-utils/config.d.ts +2 -1
  238. package/dist/src/test-utils/config.js.map +1 -1
  239. package/dist/src/test-utils/index.d.ts +6 -0
  240. package/dist/src/test-utils/index.js +7 -0
  241. package/dist/src/test-utils/index.js.map +1 -0
  242. package/dist/src/test-utils/mock-tool.d.ts +41 -0
  243. package/dist/src/test-utils/mock-tool.js +51 -0
  244. package/dist/src/test-utils/mock-tool.js.map +1 -0
  245. package/dist/src/test-utils/mockWorkspaceContext.d.ts +1 -1
  246. package/dist/src/test-utils/tools.d.ts +3 -2
  247. package/dist/src/test-utils/tools.js.map +1 -1
  248. package/dist/src/tools/diffOptions.d.ts +1 -1
  249. package/dist/src/tools/diffOptions.js +21 -13
  250. package/dist/src/tools/diffOptions.js.map +1 -1
  251. package/dist/src/tools/diffOptions.test.js +58 -22
  252. package/dist/src/tools/diffOptions.test.js.map +1 -1
  253. package/dist/src/tools/edit.d.ts +6 -5
  254. package/dist/src/tools/edit.js +47 -36
  255. package/dist/src/tools/edit.js.map +1 -1
  256. package/dist/src/tools/edit.test.js +77 -12
  257. package/dist/src/tools/edit.test.js.map +1 -1
  258. package/dist/src/tools/glob.d.ts +3 -2
  259. package/dist/src/tools/glob.js +17 -6
  260. package/dist/src/tools/glob.js.map +1 -1
  261. package/dist/src/tools/glob.test.js +29 -4
  262. package/dist/src/tools/glob.test.js.map +1 -1
  263. package/dist/src/tools/grep.d.ts +3 -2
  264. package/dist/src/tools/grep.js +35 -15
  265. package/dist/src/tools/grep.js.map +1 -1
  266. package/dist/src/tools/grep.test.js +26 -3
  267. package/dist/src/tools/grep.test.js.map +1 -1
  268. package/dist/src/tools/ls.d.ts +3 -2
  269. package/dist/src/tools/ls.js +12 -7
  270. package/dist/src/tools/ls.js.map +1 -1
  271. package/dist/src/tools/ls.test.js +7 -2
  272. package/dist/src/tools/ls.test.js.map +1 -1
  273. package/dist/src/tools/mcp-client-manager.d.ts +8 -6
  274. package/dist/src/tools/mcp-client-manager.js +30 -5
  275. package/dist/src/tools/mcp-client-manager.js.map +1 -1
  276. package/dist/src/tools/mcp-client-manager.test.js +20 -1
  277. package/dist/src/tools/mcp-client-manager.test.js.map +1 -1
  278. package/dist/src/tools/mcp-client.d.ts +18 -11
  279. package/dist/src/tools/mcp-client.js +67 -57
  280. package/dist/src/tools/mcp-client.js.map +1 -1
  281. package/dist/src/tools/mcp-client.test.js +29 -4
  282. package/dist/src/tools/mcp-client.test.js.map +1 -1
  283. package/dist/src/tools/mcp-tool.d.ts +6 -4
  284. package/dist/src/tools/mcp-tool.js +21 -11
  285. package/dist/src/tools/mcp-tool.js.map +1 -1
  286. package/dist/src/tools/mcp-tool.test.js +49 -12
  287. package/dist/src/tools/mcp-tool.test.js.map +1 -1
  288. package/dist/src/tools/memoryTool.d.ts +4 -3
  289. package/dist/src/tools/memoryTool.js +15 -38
  290. package/dist/src/tools/memoryTool.js.map +1 -1
  291. package/dist/src/tools/memoryTool.test.js +24 -12
  292. package/dist/src/tools/memoryTool.test.js.map +1 -1
  293. package/dist/src/tools/modifiable-tool.d.ts +2 -2
  294. package/dist/src/tools/modifiable-tool.js +3 -3
  295. package/dist/src/tools/modifiable-tool.js.map +1 -1
  296. package/dist/src/tools/modifiable-tool.test.js +4 -4
  297. package/dist/src/tools/modifiable-tool.test.js.map +1 -1
  298. package/dist/src/tools/read-file.d.ts +3 -2
  299. package/dist/src/tools/read-file.js +12 -34
  300. package/dist/src/tools/read-file.js.map +1 -1
  301. package/dist/src/tools/read-file.test.js +9 -6
  302. package/dist/src/tools/read-file.test.js.map +1 -1
  303. package/dist/src/tools/read-many-files.d.ts +3 -2
  304. package/dist/src/tools/read-many-files.js +35 -58
  305. package/dist/src/tools/read-many-files.js.map +1 -1
  306. package/dist/src/tools/read-many-files.test.js +64 -11
  307. package/dist/src/tools/read-many-files.test.js.map +1 -1
  308. package/dist/src/tools/ripGrep.d.ts +47 -0
  309. package/dist/src/tools/ripGrep.js +368 -0
  310. package/dist/src/tools/ripGrep.js.map +1 -0
  311. package/dist/src/tools/ripGrep.test.d.ts +6 -0
  312. package/dist/src/tools/ripGrep.test.js +874 -0
  313. package/dist/src/tools/ripGrep.test.js.map +1 -0
  314. package/dist/src/tools/shell.d.ts +3 -2
  315. package/dist/src/tools/shell.js +30 -25
  316. package/dist/src/tools/shell.js.map +1 -1
  317. package/dist/src/tools/shell.test.js +34 -25
  318. package/dist/src/tools/shell.test.js.map +1 -1
  319. package/dist/src/tools/smart-edit.d.ts +73 -0
  320. package/dist/src/tools/smart-edit.js +607 -0
  321. package/dist/src/tools/smart-edit.js.map +1 -0
  322. package/dist/src/tools/smart-edit.test.d.ts +6 -0
  323. package/dist/src/tools/smart-edit.test.js +405 -0
  324. package/dist/src/tools/smart-edit.test.js.map +1 -0
  325. package/dist/src/tools/tool-error.d.ts +17 -1
  326. package/dist/src/tools/tool-error.js +26 -0
  327. package/dist/src/tools/tool-error.js.map +1 -1
  328. package/dist/src/tools/tool-registry.d.ts +10 -4
  329. package/dist/src/tools/tool-registry.js +19 -7
  330. package/dist/src/tools/tool-registry.js.map +1 -1
  331. package/dist/src/tools/tool-registry.test.js +86 -3
  332. package/dist/src/tools/tool-registry.test.js.map +1 -1
  333. package/dist/src/tools/tools.d.ts +15 -9
  334. package/dist/src/tools/tools.js +12 -0
  335. package/dist/src/tools/tools.js.map +1 -1
  336. package/dist/src/tools/tools.test.js +1 -2
  337. package/dist/src/tools/tools.test.js.map +1 -1
  338. package/dist/src/tools/web-fetch.d.ts +3 -2
  339. package/dist/src/tools/web-fetch.js +14 -10
  340. package/dist/src/tools/web-fetch.js.map +1 -1
  341. package/dist/src/tools/web-fetch.test.js +55 -16
  342. package/dist/src/tools/web-fetch.test.js.map +1 -1
  343. package/dist/src/tools/web-search.d.ts +4 -3
  344. package/dist/src/tools/web-search.js +31 -8
  345. package/dist/src/tools/web-search.js.map +1 -1
  346. package/dist/src/tools/web-search.test.js +69 -1
  347. package/dist/src/tools/web-search.test.js.map +1 -1
  348. package/dist/src/tools/write-file.d.ts +4 -3
  349. package/dist/src/tools/write-file.js +14 -14
  350. package/dist/src/tools/write-file.js.map +1 -1
  351. package/dist/src/tools/write-file.test.js +14 -14
  352. package/dist/src/tools/write-file.test.js.map +1 -1
  353. package/dist/src/utils/bfsFileSearch.d.ts +2 -2
  354. package/dist/src/utils/bfsFileSearch.js +2 -2
  355. package/dist/src/utils/bfsFileSearch.js.map +1 -1
  356. package/dist/src/utils/bfsFileSearch.test.js +3 -3
  357. package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
  358. package/dist/src/utils/editCorrector.d.ts +2 -2
  359. package/dist/src/utils/editCorrector.js +1 -1
  360. package/dist/src/utils/editCorrector.js.map +1 -1
  361. package/dist/src/utils/editCorrector.test.js +3 -3
  362. package/dist/src/utils/editCorrector.test.js.map +1 -1
  363. package/dist/src/utils/editor.js +2 -2
  364. package/dist/src/utils/editor.js.map +1 -1
  365. package/dist/src/utils/editor.test.js +2 -2
  366. package/dist/src/utils/editor.test.js.map +1 -1
  367. package/dist/src/utils/environmentContext.d.ts +2 -2
  368. package/dist/src/utils/environmentContext.js +1 -1
  369. package/dist/src/utils/environmentContext.js.map +1 -1
  370. package/dist/src/utils/environmentContext.test.js +1 -1
  371. package/dist/src/utils/environmentContext.test.js.map +1 -1
  372. package/dist/src/utils/errorReporting.d.ts +1 -1
  373. package/dist/src/utils/errors.d.ts +19 -0
  374. package/dist/src/utils/errors.js +32 -0
  375. package/dist/src/utils/errors.js.map +1 -1
  376. package/dist/src/utils/fetch.js +1 -1
  377. package/dist/src/utils/fetch.js.map +1 -1
  378. package/dist/src/utils/fileUtils.d.ts +23 -12
  379. package/dist/src/utils/fileUtils.js +160 -79
  380. package/dist/src/utils/fileUtils.js.map +1 -1
  381. package/dist/src/utils/fileUtils.test.js +314 -21
  382. package/dist/src/utils/fileUtils.test.js.map +1 -1
  383. package/dist/src/utils/filesearch/crawler.d.ts +1 -1
  384. package/dist/src/utils/filesearch/crawler.test.js +2 -2
  385. package/dist/src/utils/filesearch/crawler.test.js.map +1 -1
  386. package/dist/src/utils/filesearch/fileSearch.d.ts +1 -0
  387. package/dist/src/utils/filesearch/fileSearch.js +14 -9
  388. package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
  389. package/dist/src/utils/filesearch/fileSearch.test.js +90 -0
  390. package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -1
  391. package/dist/src/utils/generateContentResponseUtilities.d.ts +1 -2
  392. package/dist/src/utils/generateContentResponseUtilities.js +1 -13
  393. package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
  394. package/dist/src/utils/generateContentResponseUtilities.test.js +2 -40
  395. package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -1
  396. package/dist/src/utils/getFolderStructure.d.ts +2 -2
  397. package/dist/src/utils/getFolderStructure.js +2 -2
  398. package/dist/src/utils/getFolderStructure.js.map +1 -1
  399. package/dist/src/utils/getFolderStructure.test.js +13 -13
  400. package/dist/src/utils/getFolderStructure.test.js.map +1 -1
  401. package/dist/src/utils/getPty.d.ts +19 -0
  402. package/dist/src/utils/getPty.js +23 -0
  403. package/dist/src/utils/getPty.js.map +1 -0
  404. package/dist/src/utils/gitIgnoreParser.d.ts +1 -0
  405. package/dist/src/utils/gitIgnoreParser.js +104 -13
  406. package/dist/src/utils/gitIgnoreParser.js.map +1 -1
  407. package/dist/src/utils/gitIgnoreParser.test.js +69 -3
  408. package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
  409. package/dist/src/utils/gitUtils.js +2 -2
  410. package/dist/src/utils/gitUtils.js.map +1 -1
  411. package/dist/src/utils/ide-trust.d.ts +10 -0
  412. package/dist/src/utils/ide-trust.js +14 -0
  413. package/dist/src/utils/ide-trust.js.map +1 -0
  414. package/dist/src/utils/ignorePatterns.d.ts +103 -0
  415. package/dist/src/utils/ignorePatterns.js +220 -0
  416. package/dist/src/utils/ignorePatterns.js.map +1 -0
  417. package/dist/src/utils/ignorePatterns.test.d.ts +6 -0
  418. package/dist/src/utils/ignorePatterns.test.js +250 -0
  419. package/dist/src/utils/ignorePatterns.test.js.map +1 -0
  420. package/dist/src/utils/installationManager.d.ts +16 -0
  421. package/dist/src/utils/installationManager.js +50 -0
  422. package/dist/src/utils/installationManager.js.map +1 -0
  423. package/dist/src/utils/installationManager.test.d.ts +6 -0
  424. package/dist/src/utils/installationManager.test.js +83 -0
  425. package/dist/src/utils/installationManager.test.js.map +1 -0
  426. package/dist/src/utils/language-detection.d.ts +6 -0
  427. package/dist/src/utils/language-detection.js +101 -0
  428. package/dist/src/utils/language-detection.js.map +1 -0
  429. package/dist/src/utils/llm-edit-fixer.d.ts +25 -0
  430. package/dist/src/utils/llm-edit-fixer.js +112 -0
  431. package/dist/src/utils/llm-edit-fixer.js.map +1 -0
  432. package/dist/src/utils/memoryDiscovery.d.ts +7 -6
  433. package/dist/src/utils/memoryDiscovery.js +68 -33
  434. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  435. package/dist/src/utils/memoryDiscovery.test.js +76 -20
  436. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  437. package/dist/src/utils/memoryImportProcessor.js +2 -2
  438. package/dist/src/utils/memoryImportProcessor.js.map +1 -1
  439. package/dist/src/utils/memoryImportProcessor.test.js +2 -141
  440. package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
  441. package/dist/src/utils/messageInspectors.d.ts +1 -1
  442. package/dist/src/utils/nextSpeakerChecker.d.ts +2 -2
  443. package/dist/src/utils/nextSpeakerChecker.test.js +33 -0
  444. package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
  445. package/dist/src/utils/partUtils.d.ts +22 -1
  446. package/dist/src/utils/partUtils.js +68 -0
  447. package/dist/src/utils/partUtils.js.map +1 -1
  448. package/dist/src/utils/partUtils.test.js +112 -1
  449. package/dist/src/utils/partUtils.test.js.map +1 -1
  450. package/dist/src/utils/pathReader.d.ts +17 -0
  451. package/dist/src/utils/pathReader.js +92 -0
  452. package/dist/src/utils/pathReader.js.map +1 -0
  453. package/dist/src/utils/pathReader.test.d.ts +6 -0
  454. package/dist/src/utils/pathReader.test.js +363 -0
  455. package/dist/src/utils/pathReader.test.js.map +1 -0
  456. package/dist/src/utils/paths.d.ts +1 -18
  457. package/dist/src/utils/paths.js +3 -29
  458. package/dist/src/utils/paths.js.map +1 -1
  459. package/dist/src/utils/quotaErrorDetection.d.ts +1 -1
  460. package/dist/src/utils/retry.test.js +4 -1
  461. package/dist/src/utils/retry.test.js.map +1 -1
  462. package/dist/src/utils/schemaValidator.js +4 -0
  463. package/dist/src/utils/schemaValidator.js.map +1 -1
  464. package/dist/src/utils/session.js +1 -1
  465. package/dist/src/utils/session.js.map +1 -1
  466. package/dist/src/utils/shell-utils.d.ts +1 -1
  467. package/dist/src/utils/shell-utils.js +23 -29
  468. package/dist/src/utils/shell-utils.js.map +1 -1
  469. package/dist/src/utils/shell-utils.test.js +7 -0
  470. package/dist/src/utils/shell-utils.test.js.map +1 -1
  471. package/dist/src/utils/summarizer.d.ts +2 -2
  472. package/dist/src/utils/summarizer.test.js.map +1 -1
  473. package/dist/src/utils/systemEncoding.js +2 -2
  474. package/dist/src/utils/systemEncoding.js.map +1 -1
  475. package/dist/src/utils/systemEncoding.test.js +2 -2
  476. package/dist/src/utils/systemEncoding.test.js.map +1 -1
  477. package/dist/src/utils/tool-utils.d.ts +19 -0
  478. package/dist/src/utils/tool-utils.js +58 -0
  479. package/dist/src/utils/tool-utils.js.map +1 -0
  480. package/dist/src/utils/tool-utils.test.d.ts +6 -0
  481. package/dist/src/utils/tool-utils.test.js +61 -0
  482. package/dist/src/utils/tool-utils.test.js.map +1 -0
  483. package/dist/src/utils/userAccountManager.d.ts +20 -0
  484. package/dist/src/utils/userAccountManager.js +114 -0
  485. package/dist/src/utils/userAccountManager.js.map +1 -0
  486. package/dist/src/utils/userAccountManager.test.d.ts +6 -0
  487. package/dist/src/utils/{user_account.test.js → userAccountManager.test.js} +33 -30
  488. package/dist/src/utils/userAccountManager.test.js.map +1 -0
  489. package/dist/src/utils/workspaceContext.js +13 -7
  490. package/dist/src/utils/workspaceContext.js.map +1 -1
  491. package/dist/src/utils/workspaceContext.test.js +41 -16
  492. package/dist/src/utils/workspaceContext.test.js.map +1 -1
  493. package/dist/tsconfig.tsbuildinfo +1 -1
  494. package/package.json +27 -13
  495. package/dist/src/utils/user_account.d.ts +0 -9
  496. package/dist/src/utils/user_account.js +0 -109
  497. package/dist/src/utils/user_account.js.map +0 -1
  498. package/dist/src/utils/user_account.test.js.map +0 -1
  499. package/dist/src/utils/user_id.d.ts +0 -11
  500. package/dist/src/utils/user_id.js +0 -49
  501. package/dist/src/utils/user_id.js.map +0 -1
  502. package/dist/src/utils/user_id.test.js +0 -21
  503. package/dist/src/utils/user_id.test.js.map +0 -1
  504. /package/dist/src/{utils/user_account.test.d.ts → config/storage.test.d.ts} +0 -0
  505. /package/dist/src/{utils/user_id.test.d.ts → ide/process-utils.test.d.ts} +0 -0
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import * as fs from 'node:fs';
7
+ import { randomUUID } from 'node:crypto';
8
+ import * as path from 'node:path';
9
+ import { Storage } from '../config/storage.js';
10
+ export class InstallationManager {
11
+ getInstallationIdPath() {
12
+ return Storage.getInstallationIdPath();
13
+ }
14
+ readInstallationIdFromFile() {
15
+ const installationIdFile = this.getInstallationIdPath();
16
+ if (fs.existsSync(installationIdFile)) {
17
+ const installationid = fs
18
+ .readFileSync(installationIdFile, 'utf-8')
19
+ .trim();
20
+ return installationid || null;
21
+ }
22
+ return null;
23
+ }
24
+ writeInstallationIdToFile(installationId) {
25
+ const installationIdFile = this.getInstallationIdPath();
26
+ const dir = path.dirname(installationIdFile);
27
+ fs.mkdirSync(dir, { recursive: true });
28
+ fs.writeFileSync(installationIdFile, installationId, 'utf-8');
29
+ }
30
+ /**
31
+ * Retrieves the installation ID from a file, creating it if it doesn't exist.
32
+ * This ID is used for unique user installation tracking.
33
+ * @returns A UUID string for the user.
34
+ */
35
+ getInstallationId() {
36
+ try {
37
+ let installationId = this.readInstallationIdFromFile();
38
+ if (!installationId) {
39
+ installationId = randomUUID();
40
+ this.writeInstallationIdToFile(installationId);
41
+ }
42
+ return installationId;
43
+ }
44
+ catch (error) {
45
+ console.error('Error accessing installation ID file, generating ephemeral ID:', error);
46
+ return '123456789';
47
+ }
48
+ }
49
+ }
50
+ //# sourceMappingURL=installationManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installationManager.js","sourceRoot":"","sources":["../../../src/utils/installationManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,MAAM,OAAO,mBAAmB;IACtB,qBAAqB;QAC3B,OAAO,OAAO,CAAC,qBAAqB,EAAE,CAAC;IACzC,CAAC;IAEO,0BAA0B;QAChC,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACxD,IAAI,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACtC,MAAM,cAAc,GAAG,EAAE;iBACtB,YAAY,CAAC,kBAAkB,EAAE,OAAO,CAAC;iBACzC,IAAI,EAAE,CAAC;YACV,OAAO,cAAc,IAAI,IAAI,CAAC;QAChC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,yBAAyB,CAAC,cAAsB;QACtD,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACxD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAC7C,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,EAAE,CAAC,aAAa,CAAC,kBAAkB,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;IAED;;;;OAIG;IACH,iBAAiB;QACf,IAAI,CAAC;YACH,IAAI,cAAc,GAAG,IAAI,CAAC,0BAA0B,EAAE,CAAC;YAEvD,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,cAAc,GAAG,UAAU,EAAE,CAAC;gBAC9B,IAAI,CAAC,yBAAyB,CAAC,cAAc,CAAC,CAAC;YACjD,CAAC;YAED,OAAO,cAAc,CAAC;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,gEAAgE,EAChE,KAAK,CACN,CAAC;YACF,OAAO,WAAW,CAAC;QACrB,CAAC;IACH,CAAC;CACF"}
@@ -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,83 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
7
+ import { InstallationManager } from './installationManager.js';
8
+ import * as fs from 'node:fs';
9
+ import * as os from 'node:os';
10
+ import path from 'node:path';
11
+ import { randomUUID } from 'node:crypto';
12
+ vi.mock('node:fs', async (importOriginal) => {
13
+ const actual = await importOriginal();
14
+ return {
15
+ ...actual,
16
+ readFileSync: vi.fn(actual.readFileSync),
17
+ existsSync: vi.fn(actual.existsSync),
18
+ };
19
+ });
20
+ vi.mock('os', async (importOriginal) => {
21
+ const os = await importOriginal();
22
+ return {
23
+ ...os,
24
+ homedir: vi.fn(),
25
+ };
26
+ });
27
+ vi.mock('crypto', async (importOriginal) => {
28
+ const crypto = await importOriginal();
29
+ return {
30
+ ...crypto,
31
+ randomUUID: vi.fn(),
32
+ };
33
+ });
34
+ describe('InstallationManager', () => {
35
+ let tempHomeDir;
36
+ let installationManager;
37
+ const installationIdFile = () => path.join(tempHomeDir, '.cell-cli', 'installation_id');
38
+ beforeEach(() => {
39
+ tempHomeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gemini-cli-test-home-'));
40
+ os.homedir.mockReturnValue(tempHomeDir);
41
+ installationManager = new InstallationManager();
42
+ });
43
+ afterEach(() => {
44
+ fs.rmSync(tempHomeDir, { recursive: true, force: true });
45
+ vi.clearAllMocks();
46
+ });
47
+ describe('getInstallationId', () => {
48
+ it('should create and write a new installation ID if one does not exist', () => {
49
+ const newId = 'new-uuid-123';
50
+ randomUUID.mockReturnValue(newId);
51
+ const installationId = installationManager.getInstallationId();
52
+ expect(installationId).toBe(newId);
53
+ expect(fs.existsSync(installationIdFile())).toBe(true);
54
+ expect(fs.readFileSync(installationIdFile(), 'utf-8')).toBe(newId);
55
+ });
56
+ it('should read an existing installation ID from a file', () => {
57
+ const existingId = 'existing-uuid-123';
58
+ fs.mkdirSync(path.dirname(installationIdFile()), { recursive: true });
59
+ fs.writeFileSync(installationIdFile(), existingId);
60
+ const installationId = installationManager.getInstallationId();
61
+ expect(installationId).toBe(existingId);
62
+ });
63
+ it('should return the same ID on subsequent calls', () => {
64
+ const firstId = installationManager.getInstallationId();
65
+ const secondId = installationManager.getInstallationId();
66
+ expect(secondId).toBe(firstId);
67
+ });
68
+ it('should handle read errors and return a fallback ID', () => {
69
+ vi.mocked(fs.existsSync).mockReturnValueOnce(true);
70
+ const readSpy = vi.mocked(fs.readFileSync);
71
+ readSpy.mockImplementationOnce(() => {
72
+ throw new Error('Read error');
73
+ });
74
+ const consoleErrorSpy = vi
75
+ .spyOn(console, 'error')
76
+ .mockImplementation(() => { });
77
+ const id = installationManager.getInstallationId();
78
+ expect(id).toBe('123456789');
79
+ expect(consoleErrorSpy).toHaveBeenCalled();
80
+ });
81
+ });
82
+ });
83
+ //# sourceMappingURL=installationManager.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installationManager.test.js","sourceRoot":"","sources":["../../../src/utils/installationManager.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BA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Apache-2.0
5
+ */
6
+ export declare function getLanguageFromFilePath(filePath: string): string | undefined;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import * as path from 'node:path';
7
+ const extensionToLanguageMap = {
8
+ '.ts': 'TypeScript',
9
+ '.js': 'JavaScript',
10
+ '.mjs': 'JavaScript',
11
+ '.cjs': 'JavaScript',
12
+ '.jsx': 'JavaScript',
13
+ '.tsx': 'TypeScript',
14
+ '.py': 'Python',
15
+ '.java': 'Java',
16
+ '.go': 'Go',
17
+ '.rb': 'Ruby',
18
+ '.php': 'PHP',
19
+ '.phtml': 'PHP',
20
+ '.cs': 'C#',
21
+ '.cpp': 'C++',
22
+ '.cxx': 'C++',
23
+ '.cc': 'C++',
24
+ '.c': 'C',
25
+ '.h': 'C/C++',
26
+ '.hpp': 'C++',
27
+ '.swift': 'Swift',
28
+ '.kt': 'Kotlin',
29
+ '.rs': 'Rust',
30
+ '.m': 'Objective-C',
31
+ '.mm': 'Objective-C',
32
+ '.pl': 'Perl',
33
+ '.pm': 'Perl',
34
+ '.lua': 'Lua',
35
+ '.r': 'R',
36
+ '.scala': 'Scala',
37
+ '.sc': 'Scala',
38
+ '.sh': 'Shell',
39
+ '.ps1': 'PowerShell',
40
+ '.bat': 'Batch',
41
+ '.cmd': 'Batch',
42
+ '.sql': 'SQL',
43
+ '.html': 'HTML',
44
+ '.htm': 'HTML',
45
+ '.css': 'CSS',
46
+ '.less': 'Less',
47
+ '.sass': 'Sass',
48
+ '.scss': 'Sass',
49
+ '.json': 'JSON',
50
+ '.xml': 'XML',
51
+ '.yaml': 'YAML',
52
+ '.yml': 'YAML',
53
+ '.md': 'Markdown',
54
+ '.markdown': 'Markdown',
55
+ '.dockerfile': 'Dockerfile',
56
+ '.vim': 'Vim script',
57
+ '.vb': 'Visual Basic',
58
+ '.fs': 'F#',
59
+ '.clj': 'Clojure',
60
+ '.cljs': 'Clojure',
61
+ '.dart': 'Dart',
62
+ '.ex': 'Elixir',
63
+ '.erl': 'Erlang',
64
+ '.hs': 'Haskell',
65
+ '.lisp': 'Lisp',
66
+ '.rkt': 'Racket',
67
+ '.groovy': 'Groovy',
68
+ '.jl': 'Julia',
69
+ '.tex': 'LaTeX',
70
+ '.ino': 'Arduino',
71
+ '.asm': 'Assembly',
72
+ '.s': 'Assembly',
73
+ '.toml': 'TOML',
74
+ '.vue': 'Vue',
75
+ '.svelte': 'Svelte',
76
+ '.gohtml': 'Go Template',
77
+ '.hbs': 'Handlebars',
78
+ '.ejs': 'EJS',
79
+ '.erb': 'ERB',
80
+ '.jsp': 'JSP',
81
+ '.dockerignore': 'Docker',
82
+ '.gitignore': 'Git',
83
+ '.npmignore': 'npm',
84
+ '.editorconfig': 'EditorConfig',
85
+ '.prettierrc': 'Prettier',
86
+ '.eslintrc': 'ESLint',
87
+ '.babelrc': 'Babel',
88
+ '.tsconfig': 'TypeScript',
89
+ '.flow': 'Flow',
90
+ '.graphql': 'GraphQL',
91
+ '.proto': 'Protocol Buffers',
92
+ };
93
+ export function getLanguageFromFilePath(filePath) {
94
+ const extension = path.extname(filePath).toLowerCase();
95
+ if (extension) {
96
+ return extensionToLanguageMap[extension];
97
+ }
98
+ const filename = path.basename(filePath).toLowerCase();
99
+ return extensionToLanguageMap[`.${filename}`];
100
+ }
101
+ //# sourceMappingURL=language-detection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-detection.js","sourceRoot":"","sources":["../../../src/utils/language-detection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,sBAAsB,GAA8B;IACxD,KAAK,EAAE,YAAY;IACnB,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,QAAQ;IACf,OA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;IACnB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,OAAO;IACf,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,UAAU;IAClB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,aAAa;IACxB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;IACb,eAAe,EAAE,QAAQ;IACzB,YAAY,EAAE,KAAK;IACnB,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,cAAc;IAC/B,aAAa,EAAE,UAAU;IACzB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,OAAO;IACnB,WAAW,EAAE,YAAY;IACzB,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,SAAS;IACrB,QAAQ,EAAE,kBAAkB;CAC7B,CAAC;AAEF,MAAM,UAAU,uBAAuB,CAAC,QAAgB;IACtD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACvD,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACvD,OAAO,sBAAsB,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { type GeminiClient } from '../core/client.js';
7
+ export interface SearchReplaceEdit {
8
+ search: string;
9
+ replace: string;
10
+ noChangesRequired: boolean;
11
+ explanation: string;
12
+ }
13
+ /**
14
+ * Attempts to fix a failed edit by using an LLM to generate a new search and replace pair.
15
+ * @param instruction The instruction for what needs to be done.
16
+ * @param old_string The original string to be replaced.
17
+ * @param new_string The original replacement string.
18
+ * @param error The error that occurred during the initial edit.
19
+ * @param current_content The current content of the file.
20
+ * @param geminiClient The Gemini client to use for the LLM call.
21
+ * @param abortSignal An abort signal to cancel the operation.
22
+ * @returns A new search and replace pair.
23
+ */
24
+ export declare function FixLLMEditWithInstruction(instruction: string, old_string: string, new_string: string, error: string, current_content: string, geminiClient: GeminiClient, abortSignal: AbortSignal): Promise<SearchReplaceEdit>;
25
+ export declare function resetLlmEditFixerCaches_TEST_ONLY(): void;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Type } from '@google/genai';
7
+ import {} from '../core/client.js';
8
+ import { LruCache } from './LruCache.js';
9
+ import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
10
+ const MAX_CACHE_SIZE = 50;
11
+ const EDIT_SYS_PROMPT = `
12
+ You are an expert code-editing assistant specializing in debugging and correcting failed search-and-replace operations.
13
+
14
+ # Primary Goal
15
+ Your task is to analyze a failed edit attempt and provide a corrected \`search\` string that will match the text in the file precisely. The correction should be as minimal as possible, staying very close to the original, failed \`search\` string. Do NOT invent a completely new edit based on the instruction; your job is to fix the provided parameters.
16
+
17
+ It is important that you do no try to figure out if the instruction is correct. DO NOT GIVE ADVICE. Your only goal here is to do your best to perform the search and replace task!
18
+
19
+ # Input Context
20
+ You will be given:
21
+ 1. The high-level instruction for the original edit.
22
+ 2. The exact \`search\` and \`replace\` strings that failed.
23
+ 3. The error message that was produced.
24
+ 4. The full content of the source file.
25
+
26
+ # Rules for Correction
27
+ 1. **Minimal Correction:** Your new \`search\` string must be a close variation of the original. Focus on fixing issues like whitespace, indentation, line endings, or small contextual differences.
28
+ 2. **Explain the Fix:** Your \`explanation\` MUST state exactly why the original \`search\` failed and how your new \`search\` string resolves that specific failure. (e.g., "The original search failed due to incorrect indentation; the new search corrects the indentation to match the source file.").
29
+ 3. **Preserve the \`replace\` String:** Do NOT modify the \`replace\` string unless the instruction explicitly requires it and it was the source of the error. Your primary focus is fixing the \`search\` string.
30
+ 4. **No Changes Case:** CRUCIAL: if the change is already present in the file, set \`noChangesRequired\` to True and explain why in the \`explanation\`. It is crucial that you only do this if the changes outline in \`replace\` are alredy in the file and suits the instruction!!
31
+ 5. **Exactness:** The final \`search\` field must be the EXACT literal text from the file. Do not escape characters.
32
+ `;
33
+ const EDIT_USER_PROMPT = `
34
+ # Goal of the Original Edit
35
+ <instruction>
36
+ {instruction}
37
+ </instruction>
38
+
39
+ # Failed Attempt Details
40
+ - **Original \`search\` parameter (failed):**
41
+ <search>
42
+ {old_string}
43
+ </search>
44
+ - **Original \`replace\` parameter:**
45
+ <replace>
46
+ {new_string}
47
+ </replace>
48
+ - **Error Encountered:**
49
+ <error>
50
+ {error}
51
+ </error>
52
+
53
+ # Full File Content
54
+ <file_content>
55
+ {current_content}
56
+ </file_content>
57
+
58
+ # Your Task
59
+ Based on the error and the file content, provide a corrected \`search\` string that will succeed. Remember to keep your correction minimal and explain the precise reason for the failure in your \`explanation\`.
60
+ `;
61
+ const SearchReplaceEditSchema = {
62
+ type: Type.OBJECT,
63
+ properties: {
64
+ explanation: { type: Type.STRING },
65
+ search: { type: Type.STRING },
66
+ replace: { type: Type.STRING },
67
+ noChangesRequired: { type: Type.BOOLEAN },
68
+ },
69
+ required: ['search', 'replace', 'explanation'],
70
+ };
71
+ const editCorrectionWithInstructionCache = new LruCache(MAX_CACHE_SIZE);
72
+ /**
73
+ * Attempts to fix a failed edit by using an LLM to generate a new search and replace pair.
74
+ * @param instruction The instruction for what needs to be done.
75
+ * @param old_string The original string to be replaced.
76
+ * @param new_string The original replacement string.
77
+ * @param error The error that occurred during the initial edit.
78
+ * @param current_content The current content of the file.
79
+ * @param geminiClient The Gemini client to use for the LLM call.
80
+ * @param abortSignal An abort signal to cancel the operation.
81
+ * @returns A new search and replace pair.
82
+ */
83
+ export async function FixLLMEditWithInstruction(instruction, old_string, new_string, error, current_content, geminiClient, abortSignal) {
84
+ const cacheKey = `${instruction}---${old_string}---${new_string}--${current_content}--${error}`;
85
+ const cachedResult = editCorrectionWithInstructionCache.get(cacheKey);
86
+ if (cachedResult) {
87
+ return cachedResult;
88
+ }
89
+ const userPrompt = EDIT_USER_PROMPT.replace('{instruction}', instruction)
90
+ .replace('{old_string}', old_string)
91
+ .replace('{new_string}', new_string)
92
+ .replace('{error}', error)
93
+ .replace('{current_content}', current_content);
94
+ const contents = [
95
+ {
96
+ role: 'user',
97
+ parts: [
98
+ {
99
+ text: `${EDIT_SYS_PROMPT}
100
+ ${userPrompt}`,
101
+ },
102
+ ],
103
+ },
104
+ ];
105
+ const result = (await geminiClient.generateJson(contents, SearchReplaceEditSchema, abortSignal, DEFAULT_GEMINI_FLASH_MODEL));
106
+ editCorrectionWithInstructionCache.set(cacheKey, result);
107
+ return result;
108
+ }
109
+ export function resetLlmEditFixerCaches_TEST_ONLY() {
110
+ editCorrectionWithInstructionCache.clear();
111
+ }
112
+ //# sourceMappingURL=llm-edit-fixer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-edit-fixer.js","sourceRoot":"","sources":["../../../src/utils/llm-edit-fixer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAgB,IAAI,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAqB,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAEjE,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;CAqBvB,CAAC;AAEF,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BxB,CAAC;AASF,MAAM,uBAAuB,GAAG;IAC9B,IAAI,EAA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,MAAM,GAAG,CAAC,MAAM,YAAY,CAAC,YAAY,CAC7C,QAAQ,EACR,uBAAuB,EACvB,WAAW,EACX,0BAA0B,CAC3B,CAAiC,CAAC;IAEnC,kCAAkC,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,iCAAiC;IAC/C,kCAAkC,CAAC,KAAK,EAAE,CAAC;AAC7C,CAAC"}
@@ -3,13 +3,14 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
7
- import { FileFilteringOptions } from '../config/config.js';
6
+ import type { FileDiscoveryService } from '../services/fileDiscoveryService.js';
7
+ import type { FileFilteringOptions } from '../config/config.js';
8
+ export interface LoadServerHierarchicalMemoryResponse {
9
+ memoryContent: string;
10
+ fileCount: number;
11
+ }
8
12
  /**
9
13
  * Loads hierarchical GEMINI.md files and concatenates their content.
10
14
  * This function is intended for use by the server.
11
15
  */
12
- export declare function loadServerHierarchicalMemory(currentWorkingDirectory: string, includeDirectoriesToReadGemini: readonly string[], debugMode: boolean, fileService: FileDiscoveryService, extensionContextFilePaths?: string[], importFormat?: 'flat' | 'tree', fileFilteringOptions?: FileFilteringOptions, maxDirs?: number): Promise<{
13
- memoryContent: string;
14
- fileCount: number;
15
- }>;
16
+ export declare function loadServerHierarchicalMemory(currentWorkingDirectory: string, includeDirectoriesToReadGemini: readonly string[], debugMode: boolean, fileService: FileDiscoveryService, extensionContextFilePaths: string[] | undefined, folderTrust: boolean, importFormat?: 'flat' | 'tree', fileFilteringOptions?: FileFilteringOptions, maxDirs?: number): Promise<LoadServerHierarchicalMemoryResponse>;
@@ -3,14 +3,15 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import * as fs from 'fs/promises';
7
- import * as fsSync from 'fs';
8
- import * as path from 'path';
9
- import { homedir } from 'os';
6
+ import * as fs from 'node:fs/promises';
7
+ import * as fsSync from 'node:fs';
8
+ import * as path from 'node:path';
9
+ import { homedir } from 'node:os';
10
10
  import { bfsFileSearch } from './bfsFileSearch.js';
11
- import { GEMINI_CONFIG_DIR, getAllGeminiMdFilenames, } from '../tools/memoryTool.js';
11
+ import { getAllGeminiMdFilenames } from '../tools/memoryTool.js';
12
12
  import { processImports } from './memoryImportProcessor.js';
13
- import { DEFAULT_MEMORY_FILE_FILTERING_OPTIONS, } from '../config/config.js';
13
+ import { DEFAULT_MEMORY_FILE_FILTERING_OPTIONS } from '../config/config.js';
14
+ import { CELL_DIR } from './paths.js';
14
15
  // Simple console logger, similar to the one previously in CLI's config.ts
15
16
  // TODO: Integrate with a more robust server-side logger if available/appropriate.
16
17
  const logger = {
@@ -58,24 +59,40 @@ async function findProjectRoot(startDir) {
58
59
  currentDir = parentDir;
59
60
  }
60
61
  }
61
- async function getGeminiMdFilePathsInternal(currentWorkingDirectory, includeDirectoriesToReadGemini, userHomePath, debugMode, fileService, extensionContextFilePaths = [], fileFilteringOptions, maxDirs) {
62
+ async function getGeminiMdFilePathsInternal(currentWorkingDirectory, includeDirectoriesToReadGemini, userHomePath, debugMode, fileService, extensionContextFilePaths = [], folderTrust, fileFilteringOptions, maxDirs) {
62
63
  const dirs = new Set([
63
64
  ...includeDirectoriesToReadGemini,
64
65
  currentWorkingDirectory,
65
66
  ]);
66
- const paths = [];
67
- for (const dir of dirs) {
68
- const pathsByDir = await getGeminiMdFilePathsInternalForEachDir(dir, userHomePath, debugMode, fileService, extensionContextFilePaths, fileFilteringOptions, maxDirs);
69
- paths.push(...pathsByDir);
67
+ // Process directories in parallel with concurrency limit to prevent EMFILE errors
68
+ const CONCURRENT_LIMIT = 10;
69
+ const dirsArray = Array.from(dirs);
70
+ const pathsArrays = [];
71
+ for (let i = 0; i < dirsArray.length; i += CONCURRENT_LIMIT) {
72
+ const batch = dirsArray.slice(i, i + CONCURRENT_LIMIT);
73
+ const batchPromises = batch.map((dir) => getGeminiMdFilePathsInternalForEachDir(dir, userHomePath, debugMode, fileService, extensionContextFilePaths, folderTrust, fileFilteringOptions, maxDirs));
74
+ const batchResults = await Promise.allSettled(batchPromises);
75
+ for (const result of batchResults) {
76
+ if (result.status === 'fulfilled') {
77
+ pathsArrays.push(result.value);
78
+ }
79
+ else {
80
+ const error = result.reason;
81
+ const message = error instanceof Error ? error.message : String(error);
82
+ logger.error(`Error discovering files in directory: ${message}`);
83
+ // Continue processing other directories
84
+ }
85
+ }
70
86
  }
87
+ const paths = pathsArrays.flat();
71
88
  return Array.from(new Set(paths));
72
89
  }
73
- async function getGeminiMdFilePathsInternalForEachDir(dir, userHomePath, debugMode, fileService, extensionContextFilePaths = [], fileFilteringOptions, maxDirs) {
90
+ async function getGeminiMdFilePathsInternalForEachDir(dir, userHomePath, debugMode, fileService, extensionContextFilePaths = [], folderTrust, fileFilteringOptions, maxDirs) {
74
91
  const allPaths = new Set();
75
92
  const geminiMdFilenames = getAllGeminiMdFilenames();
76
93
  for (const geminiMdFilename of geminiMdFilenames) {
77
94
  const resolvedHome = path.resolve(userHomePath);
78
- const globalMemoryPath = path.join(resolvedHome, GEMINI_CONFIG_DIR, geminiMdFilename);
95
+ const globalMemoryPath = path.join(resolvedHome, CELL_DIR, geminiMdFilename);
79
96
  // This part that finds the global file always runs.
80
97
  try {
81
98
  await fs.access(globalMemoryPath, fsSync.constants.R_OK);
@@ -88,7 +105,7 @@ async function getGeminiMdFilePathsInternalForEachDir(dir, userHomePath, debugMo
88
105
  }
89
106
  // FIX: Only perform the workspace search (upward and downward scans)
90
107
  // if a valid currentWorkingDirectory is provided.
91
- if (dir) {
108
+ if (dir && folderTrust) {
92
109
  const resolvedCwd = path.resolve(dir);
93
110
  if (debugMode)
94
111
  logger.debug(`Searching for ${geminiMdFilename} starting from CWD: ${resolvedCwd}`);
@@ -101,7 +118,7 @@ async function getGeminiMdFilePathsInternalForEachDir(dir, userHomePath, debugMo
101
118
  ? path.dirname(projectRoot)
102
119
  : path.dirname(resolvedHome);
103
120
  while (currentDir && currentDir !== path.dirname(currentDir)) {
104
- if (currentDir === path.join(resolvedHome, GEMINI_CONFIG_DIR)) {
121
+ if (currentDir === path.join(resolvedHome, CELL_DIR)) {
105
122
  break;
106
123
  }
107
124
  const potentialPath = path.join(currentDir, geminiMdFilename);
@@ -147,25 +164,43 @@ async function getGeminiMdFilePathsInternalForEachDir(dir, userHomePath, debugMo
147
164
  return finalPaths;
148
165
  }
149
166
  async function readGeminiMdFiles(filePaths, debugMode, importFormat = 'tree') {
167
+ // Process files in parallel with concurrency limit to prevent EMFILE errors
168
+ const CONCURRENT_LIMIT = 20; // Higher limit for file reads as they're typically faster
150
169
  const results = [];
151
- for (const filePath of filePaths) {
152
- try {
153
- const content = await fs.readFile(filePath, 'utf-8');
154
- // Process imports in the content
155
- const processedResult = await processImports(content, path.dirname(filePath), debugMode, undefined, undefined, importFormat);
156
- results.push({ filePath, content: processedResult.content });
157
- if (debugMode)
158
- logger.debug(`Successfully read and processed imports: ${filePath} (Length: ${processedResult.content.length})`);
159
- }
160
- catch (error) {
161
- const isTestEnv = process.env['NODE_ENV'] === 'test' || process.env['VITEST'];
162
- if (!isTestEnv) {
170
+ for (let i = 0; i < filePaths.length; i += CONCURRENT_LIMIT) {
171
+ const batch = filePaths.slice(i, i + CONCURRENT_LIMIT);
172
+ const batchPromises = batch.map(async (filePath) => {
173
+ try {
174
+ const content = await fs.readFile(filePath, 'utf-8');
175
+ // Process imports in the content
176
+ const processedResult = await processImports(content, path.dirname(filePath), debugMode, undefined, undefined, importFormat);
177
+ if (debugMode)
178
+ logger.debug(`Successfully read and processed imports: ${filePath} (Length: ${processedResult.content.length})`);
179
+ return { filePath, content: processedResult.content };
180
+ }
181
+ catch (error) {
182
+ const isTestEnv = process.env['NODE_ENV'] === 'test' || process.env['VITEST'];
183
+ if (!isTestEnv) {
184
+ const message = error instanceof Error ? error.message : String(error);
185
+ logger.warn(`Warning: Could not read ${getAllGeminiMdFilenames()} file at ${filePath}. Error: ${message}`);
186
+ }
187
+ if (debugMode)
188
+ logger.debug(`Failed to read: ${filePath}`);
189
+ return { filePath, content: null }; // Still include it with null content
190
+ }
191
+ });
192
+ const batchResults = await Promise.allSettled(batchPromises);
193
+ for (const result of batchResults) {
194
+ if (result.status === 'fulfilled') {
195
+ results.push(result.value);
196
+ }
197
+ else {
198
+ // This case shouldn't happen since we catch all errors above,
199
+ // but handle it for completeness
200
+ const error = result.reason;
163
201
  const message = error instanceof Error ? error.message : String(error);
164
- logger.warn(`Warning: Could not read ${getAllGeminiMdFilenames()} file at ${filePath}. Error: ${message}`);
202
+ logger.error(`Unexpected error processing file: ${message}`);
165
203
  }
166
- results.push({ filePath, content: null }); // Still include it with null content
167
- if (debugMode)
168
- logger.debug(`Failed to read: ${filePath}`);
169
204
  }
170
205
  }
171
206
  return results;
@@ -192,13 +227,13 @@ currentWorkingDirectoryForDisplay) {
192
227
  * Loads hierarchical GEMINI.md files and concatenates their content.
193
228
  * This function is intended for use by the server.
194
229
  */
195
- export async function loadServerHierarchicalMemory(currentWorkingDirectory, includeDirectoriesToReadGemini, debugMode, fileService, extensionContextFilePaths = [], importFormat = 'tree', fileFilteringOptions, maxDirs = 200) {
230
+ export async function loadServerHierarchicalMemory(currentWorkingDirectory, includeDirectoriesToReadGemini, debugMode, fileService, extensionContextFilePaths = [], folderTrust, importFormat = 'tree', fileFilteringOptions, maxDirs = 200) {
196
231
  if (debugMode)
197
232
  logger.debug(`Loading server hierarchical memory for CWD: ${currentWorkingDirectory} (importFormat: ${importFormat})`);
198
233
  // For the server, homedir() refers to the server process's home.
199
234
  // This is consistent with how MemoryTool already finds the global path.
200
235
  const userHomePath = homedir();
201
- const filePaths = await getGeminiMdFilePathsInternal(currentWorkingDirectory, includeDirectoriesToReadGemini, userHomePath, debugMode, fileService, extensionContextFilePaths, fileFilteringOptions || DEFAULT_MEMORY_FILE_FILTERING_OPTIONS, maxDirs);
236
+ const filePaths = await getGeminiMdFilePathsInternal(currentWorkingDirectory, includeDirectoriesToReadGemini, userHomePath, debugMode, fileService, extensionContextFilePaths, folderTrust, fileFilteringOptions || DEFAULT_MEMORY_FILE_FILTERING_OPTIONS, maxDirs);
202
237
  if (filePaths.length === 0) {
203
238
  if (debugMode)
204
239
  logger.debug('No GEMINI.md files found in hierarchy of the workspace.');