@vybestack/llxprt-code-tools 0.10.0-nightly.260613.1adad3b34

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 (364) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +294 -0
  3. package/dist/.last_build +0 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +2 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/src/__tests__/fixtures/filesystem-tool-fixtures.d.ts +29 -0
  8. package/dist/src/__tests__/fixtures/filesystem-tool-fixtures.js +30 -0
  9. package/dist/src/__tests__/fixtures/filesystem-tool-fixtures.js.map +1 -0
  10. package/dist/src/__tests__/fixtures/key-storage-fixtures.d.ts +39 -0
  11. package/dist/src/__tests__/fixtures/key-storage-fixtures.js +53 -0
  12. package/dist/src/__tests__/fixtures/key-storage-fixtures.js.map +1 -0
  13. package/dist/src/__tests__/fixtures/provider-formatting-fixtures.d.ts +140 -0
  14. package/dist/src/__tests__/fixtures/provider-formatting-fixtures.js +157 -0
  15. package/dist/src/__tests__/fixtures/provider-formatting-fixtures.js.map +1 -0
  16. package/dist/src/__tests__/red-test-helpers.d.ts +14 -0
  17. package/dist/src/__tests__/red-test-helpers.js +18 -0
  18. package/dist/src/__tests__/red-test-helpers.js.map +1 -0
  19. package/dist/src/formatters/IToolFormatter.d.ts +84 -0
  20. package/dist/src/formatters/IToolFormatter.js +6 -0
  21. package/dist/src/formatters/IToolFormatter.js.map +1 -0
  22. package/dist/src/formatters/ToolFormatter.d.ts +94 -0
  23. package/dist/src/formatters/ToolFormatter.js +379 -0
  24. package/dist/src/formatters/ToolFormatter.js.map +1 -0
  25. package/dist/src/formatters/ToolIdStrategy.d.ts +79 -0
  26. package/dist/src/formatters/ToolIdStrategy.js +173 -0
  27. package/dist/src/formatters/ToolIdStrategy.js.map +1 -0
  28. package/dist/src/formatters/doubleEscapeUtils.d.ts +46 -0
  29. package/dist/src/formatters/doubleEscapeUtils.js +223 -0
  30. package/dist/src/formatters/doubleEscapeUtils.js.map +1 -0
  31. package/dist/src/formatters/index.d.ts +21 -0
  32. package/dist/src/formatters/index.js +12 -0
  33. package/dist/src/formatters/index.js.map +1 -0
  34. package/dist/src/formatters/toolIdNormalization.d.ts +28 -0
  35. package/dist/src/formatters/toolIdNormalization.js +97 -0
  36. package/dist/src/formatters/toolIdNormalization.js.map +1 -0
  37. package/dist/src/formatters/toolNameUtils.d.ts +43 -0
  38. package/dist/src/formatters/toolNameUtils.js +143 -0
  39. package/dist/src/formatters/toolNameUtils.js.map +1 -0
  40. package/dist/src/index.d.ts +88 -0
  41. package/dist/src/index.js +68 -0
  42. package/dist/src/index.js.map +1 -0
  43. package/dist/src/interfaces/IAsyncTaskService.d.ts +57 -0
  44. package/dist/src/interfaces/IAsyncTaskService.js +6 -0
  45. package/dist/src/interfaces/IAsyncTaskService.js.map +1 -0
  46. package/dist/src/interfaces/IIdeService.d.ts +62 -0
  47. package/dist/src/interfaces/IIdeService.js +6 -0
  48. package/dist/src/interfaces/IIdeService.js.map +1 -0
  49. package/dist/src/interfaces/ILspService.d.ts +54 -0
  50. package/dist/src/interfaces/ILspService.js +6 -0
  51. package/dist/src/interfaces/ILspService.js.map +1 -0
  52. package/dist/src/interfaces/IMcpToolService.d.ts +47 -0
  53. package/dist/src/interfaces/IMcpToolService.js +6 -0
  54. package/dist/src/interfaces/IMcpToolService.js.map +1 -0
  55. package/dist/src/interfaces/IPromptRegistryService.d.ts +51 -0
  56. package/dist/src/interfaces/IPromptRegistryService.js +6 -0
  57. package/dist/src/interfaces/IPromptRegistryService.js.map +1 -0
  58. package/dist/src/interfaces/ISettingsService.d.ts +50 -0
  59. package/dist/src/interfaces/ISettingsService.js +6 -0
  60. package/dist/src/interfaces/ISettingsService.js.map +1 -0
  61. package/dist/src/interfaces/IShellExecutionService.d.ts +55 -0
  62. package/dist/src/interfaces/IShellExecutionService.js +6 -0
  63. package/dist/src/interfaces/IShellExecutionService.js.map +1 -0
  64. package/dist/src/interfaces/IShellToolHost.d.ts +176 -0
  65. package/dist/src/interfaces/IShellToolHost.js +6 -0
  66. package/dist/src/interfaces/IShellToolHost.js.map +1 -0
  67. package/dist/src/interfaces/ISkillService.d.ts +69 -0
  68. package/dist/src/interfaces/ISkillService.js +6 -0
  69. package/dist/src/interfaces/ISkillService.js.map +1 -0
  70. package/dist/src/interfaces/IStorageService.d.ts +42 -0
  71. package/dist/src/interfaces/IStorageService.js +6 -0
  72. package/dist/src/interfaces/IStorageService.js.map +1 -0
  73. package/dist/src/interfaces/ISubagentService.d.ts +112 -0
  74. package/dist/src/interfaces/ISubagentService.js +6 -0
  75. package/dist/src/interfaces/ISubagentService.js.map +1 -0
  76. package/dist/src/interfaces/ITaskToolHost.d.ts +185 -0
  77. package/dist/src/interfaces/ITaskToolHost.js +6 -0
  78. package/dist/src/interfaces/ITaskToolHost.js.map +1 -0
  79. package/dist/src/interfaces/ITodoService.d.ts +79 -0
  80. package/dist/src/interfaces/ITodoService.js +6 -0
  81. package/dist/src/interfaces/ITodoService.js.map +1 -0
  82. package/dist/src/interfaces/IToolHost.d.ts +91 -0
  83. package/dist/src/interfaces/IToolHost.js +6 -0
  84. package/dist/src/interfaces/IToolHost.js.map +1 -0
  85. package/dist/src/interfaces/IToolKeyStorage.d.ts +62 -0
  86. package/dist/src/interfaces/IToolKeyStorage.js +6 -0
  87. package/dist/src/interfaces/IToolKeyStorage.js.map +1 -0
  88. package/dist/src/interfaces/IToolMessageBus.d.ts +63 -0
  89. package/dist/src/interfaces/IToolMessageBus.js +6 -0
  90. package/dist/src/interfaces/IToolMessageBus.js.map +1 -0
  91. package/dist/src/interfaces/IToolRegistryHost.d.ts +43 -0
  92. package/dist/src/interfaces/IToolRegistryHost.js +6 -0
  93. package/dist/src/interfaces/IToolRegistryHost.js.map +1 -0
  94. package/dist/src/interfaces/IWebSearchService.d.ts +16 -0
  95. package/dist/src/interfaces/IWebSearchService.js +7 -0
  96. package/dist/src/interfaces/IWebSearchService.js.map +1 -0
  97. package/dist/src/interfaces/index.d.ts +33 -0
  98. package/dist/src/interfaces/index.js +6 -0
  99. package/dist/src/interfaces/index.js.map +1 -0
  100. package/dist/src/tools/activate-skill.d.ts +26 -0
  101. package/dist/src/tools/activate-skill.js +121 -0
  102. package/dist/src/tools/activate-skill.js.map +1 -0
  103. package/dist/src/tools/apply-patch.d.ts +65 -0
  104. package/dist/src/tools/apply-patch.js +528 -0
  105. package/dist/src/tools/apply-patch.js.map +1 -0
  106. package/dist/src/tools/ast-edit/ast-config.d.ts +67 -0
  107. package/dist/src/tools/ast-edit/ast-config.js +72 -0
  108. package/dist/src/tools/ast-edit/ast-config.js.map +1 -0
  109. package/dist/src/tools/ast-edit/ast-edit-invocation.d.ts +40 -0
  110. package/dist/src/tools/ast-edit/ast-edit-invocation.js +410 -0
  111. package/dist/src/tools/ast-edit/ast-edit-invocation.js.map +1 -0
  112. package/dist/src/tools/ast-edit/ast-query-extractor.d.ts +21 -0
  113. package/dist/src/tools/ast-edit/ast-query-extractor.js +178 -0
  114. package/dist/src/tools/ast-edit/ast-query-extractor.js.map +1 -0
  115. package/dist/src/tools/ast-edit/ast-read-file-invocation.d.ts +26 -0
  116. package/dist/src/tools/ast-edit/ast-read-file-invocation.js +149 -0
  117. package/dist/src/tools/ast-edit/ast-read-file-invocation.js.map +1 -0
  118. package/dist/src/tools/ast-edit/constants.d.ts +30 -0
  119. package/dist/src/tools/ast-edit/constants.js +36 -0
  120. package/dist/src/tools/ast-edit/constants.js.map +1 -0
  121. package/dist/src/tools/ast-edit/context-collector.d.ts +25 -0
  122. package/dist/src/tools/ast-edit/context-collector.js +115 -0
  123. package/dist/src/tools/ast-edit/context-collector.js.map +1 -0
  124. package/dist/src/tools/ast-edit/context-optimizer.d.ts +29 -0
  125. package/dist/src/tools/ast-edit/context-optimizer.js +86 -0
  126. package/dist/src/tools/ast-edit/context-optimizer.js.map +1 -0
  127. package/dist/src/tools/ast-edit/cross-file-analyzer.d.ts +41 -0
  128. package/dist/src/tools/ast-edit/cross-file-analyzer.js +294 -0
  129. package/dist/src/tools/ast-edit/cross-file-analyzer.js.map +1 -0
  130. package/dist/src/tools/ast-edit/edit-calculator.d.ts +71 -0
  131. package/dist/src/tools/ast-edit/edit-calculator.js +249 -0
  132. package/dist/src/tools/ast-edit/edit-calculator.js.map +1 -0
  133. package/dist/src/tools/ast-edit/edit-helpers.d.ts +22 -0
  134. package/dist/src/tools/ast-edit/edit-helpers.js +36 -0
  135. package/dist/src/tools/ast-edit/edit-helpers.js.map +1 -0
  136. package/dist/src/tools/ast-edit/language-analysis.d.ts +19 -0
  137. package/dist/src/tools/ast-edit/language-analysis.js +123 -0
  138. package/dist/src/tools/ast-edit/language-analysis.js.map +1 -0
  139. package/dist/src/tools/ast-edit/local-context-analyzer.d.ts +84 -0
  140. package/dist/src/tools/ast-edit/local-context-analyzer.js +267 -0
  141. package/dist/src/tools/ast-edit/local-context-analyzer.js.map +1 -0
  142. package/dist/src/tools/ast-edit/repository-context-provider.d.ts +22 -0
  143. package/dist/src/tools/ast-edit/repository-context-provider.js +139 -0
  144. package/dist/src/tools/ast-edit/repository-context-provider.js.map +1 -0
  145. package/dist/src/tools/ast-edit/types.d.ts +155 -0
  146. package/dist/src/tools/ast-edit/types.js +7 -0
  147. package/dist/src/tools/ast-edit/types.js.map +1 -0
  148. package/dist/src/tools/ast-edit/workspace-context-provider.d.ts +22 -0
  149. package/dist/src/tools/ast-edit/workspace-context-provider.js +39 -0
  150. package/dist/src/tools/ast-edit/workspace-context-provider.js.map +1 -0
  151. package/dist/src/tools/ast-edit.d.ts +43 -0
  152. package/dist/src/tools/ast-edit.js +183 -0
  153. package/dist/src/tools/ast-edit.js.map +1 -0
  154. package/dist/src/tools/ast-grep.d.ts +22 -0
  155. package/dist/src/tools/ast-grep.js +291 -0
  156. package/dist/src/tools/ast-grep.js.map +1 -0
  157. package/dist/src/tools/check-async-tasks.d.ts +46 -0
  158. package/dist/src/tools/check-async-tasks.js +241 -0
  159. package/dist/src/tools/check-async-tasks.js.map +1 -0
  160. package/dist/src/tools/codesearch.d.ts +25 -0
  161. package/dist/src/tools/codesearch.js +153 -0
  162. package/dist/src/tools/codesearch.js.map +1 -0
  163. package/dist/src/tools/delete_line_range.d.ts +41 -0
  164. package/dist/src/tools/delete_line_range.js +238 -0
  165. package/dist/src/tools/delete_line_range.js.map +1 -0
  166. package/dist/src/tools/direct-web-fetch.d.ts +22 -0
  167. package/dist/src/tools/direct-web-fetch.js +215 -0
  168. package/dist/src/tools/direct-web-fetch.js.map +1 -0
  169. package/dist/src/tools/edit-utils.d.ts +53 -0
  170. package/dist/src/tools/edit-utils.js +250 -0
  171. package/dist/src/tools/edit-utils.js.map +1 -0
  172. package/dist/src/tools/edit.d.ts +70 -0
  173. package/dist/src/tools/edit.js +816 -0
  174. package/dist/src/tools/edit.js.map +1 -0
  175. package/dist/src/tools/exa-web-search.d.ts +27 -0
  176. package/dist/src/tools/exa-web-search.js +153 -0
  177. package/dist/src/tools/exa-web-search.js.map +1 -0
  178. package/dist/src/tools/glob.d.ts +55 -0
  179. package/dist/src/tools/glob.js +284 -0
  180. package/dist/src/tools/glob.js.map +1 -0
  181. package/dist/src/tools/google-web-fetch.d.ts +34 -0
  182. package/dist/src/tools/google-web-fetch.js +417 -0
  183. package/dist/src/tools/google-web-fetch.js.map +1 -0
  184. package/dist/src/tools/google-web-search-invocation.d.ts +53 -0
  185. package/dist/src/tools/google-web-search-invocation.js +180 -0
  186. package/dist/src/tools/google-web-search-invocation.js.map +1 -0
  187. package/dist/src/tools/google-web-search.d.ts +16 -0
  188. package/dist/src/tools/google-web-search.js +34 -0
  189. package/dist/src/tools/google-web-search.js.map +1 -0
  190. package/dist/src/tools/grep.d.ts +56 -0
  191. package/dist/src/tools/grep.js +883 -0
  192. package/dist/src/tools/grep.js.map +1 -0
  193. package/dist/src/tools/insert_at_line.d.ts +41 -0
  194. package/dist/src/tools/insert_at_line.js +287 -0
  195. package/dist/src/tools/insert_at_line.js.map +1 -0
  196. package/dist/src/tools/list-subagents.d.ts +31 -0
  197. package/dist/src/tools/list-subagents.js +122 -0
  198. package/dist/src/tools/list-subagents.js.map +1 -0
  199. package/dist/src/tools/ls.d.ts +71 -0
  200. package/dist/src/tools/ls.js +238 -0
  201. package/dist/src/tools/ls.js.map +1 -0
  202. package/dist/src/tools/memoryTool.d.ts +66 -0
  203. package/dist/src/tools/memoryTool.js +435 -0
  204. package/dist/src/tools/memoryTool.js.map +1 -0
  205. package/dist/src/tools/modifiable-tool.d.ts +37 -0
  206. package/dist/src/tools/modifiable-tool.js +120 -0
  207. package/dist/src/tools/modifiable-tool.js.map +1 -0
  208. package/dist/src/tools/read-file.d.ts +49 -0
  209. package/dist/src/tools/read-file.js +279 -0
  210. package/dist/src/tools/read-file.js.map +1 -0
  211. package/dist/src/tools/read-many-files.d.ts +60 -0
  212. package/dist/src/tools/read-many-files.js +529 -0
  213. package/dist/src/tools/read-many-files.js.map +1 -0
  214. package/dist/src/tools/read_line_range.d.ts +47 -0
  215. package/dist/src/tools/read_line_range.js +248 -0
  216. package/dist/src/tools/read_line_range.js.map +1 -0
  217. package/dist/src/tools/ripGrep.d.ts +41 -0
  218. package/dist/src/tools/ripGrep.js +395 -0
  219. package/dist/src/tools/ripGrep.js.map +1 -0
  220. package/dist/src/tools/shell.d.ts +60 -0
  221. package/dist/src/tools/shell.js +735 -0
  222. package/dist/src/tools/shell.js.map +1 -0
  223. package/dist/src/tools/structural-analysis.d.ts +27 -0
  224. package/dist/src/tools/structural-analysis.js +1089 -0
  225. package/dist/src/tools/structural-analysis.js.map +1 -0
  226. package/dist/src/tools/stubs.d.ts +10 -0
  227. package/dist/src/tools/stubs.js +6 -0
  228. package/dist/src/tools/stubs.js.map +1 -0
  229. package/dist/src/tools/task.d.ts +41 -0
  230. package/dist/src/tools/task.js +195 -0
  231. package/dist/src/tools/task.js.map +1 -0
  232. package/dist/src/tools/todo-events.d.ts +22 -0
  233. package/dist/src/tools/todo-events.js +24 -0
  234. package/dist/src/tools/todo-events.js.map +1 -0
  235. package/dist/src/tools/todo-pause.d.ts +29 -0
  236. package/dist/src/tools/todo-pause.js +172 -0
  237. package/dist/src/tools/todo-pause.js.map +1 -0
  238. package/dist/src/tools/todo-read.d.ts +18 -0
  239. package/dist/src/tools/todo-read.js +98 -0
  240. package/dist/src/tools/todo-read.js.map +1 -0
  241. package/dist/src/tools/todo-store.d.ts +35 -0
  242. package/dist/src/tools/todo-store.js +124 -0
  243. package/dist/src/tools/todo-store.js.map +1 -0
  244. package/dist/src/tools/todo-write.d.ts +29 -0
  245. package/dist/src/tools/todo-write.js +366 -0
  246. package/dist/src/tools/todo-write.js.map +1 -0
  247. package/dist/src/tools/tool-registry.d.ts +156 -0
  248. package/dist/src/tools/tool-registry.js +623 -0
  249. package/dist/src/tools/tool-registry.js.map +1 -0
  250. package/dist/src/tools/tools.d.ts +403 -0
  251. package/dist/src/tools/tools.js +519 -0
  252. package/dist/src/tools/tools.js.map +1 -0
  253. package/dist/src/tools/write-file.d.ts +45 -0
  254. package/dist/src/tools/write-file.js +320 -0
  255. package/dist/src/tools/write-file.js.map +1 -0
  256. package/dist/src/types/index.d.ts +17 -0
  257. package/dist/src/types/index.js +9 -0
  258. package/dist/src/types/index.js.map +1 -0
  259. package/dist/src/types/provider-content-types.d.ts +56 -0
  260. package/dist/src/types/provider-content-types.js +6 -0
  261. package/dist/src/types/provider-content-types.js.map +1 -0
  262. package/dist/src/types/todo-schemas.d.ts +263 -0
  263. package/dist/src/types/todo-schemas.js +32 -0
  264. package/dist/src/types/todo-schemas.js.map +1 -0
  265. package/dist/src/types/tool-confirmation-types.d.ts +34 -0
  266. package/dist/src/types/tool-confirmation-types.js +29 -0
  267. package/dist/src/types/tool-confirmation-types.js.map +1 -0
  268. package/dist/src/types/tool-context.d.ts +31 -0
  269. package/dist/src/types/tool-context.js +6 -0
  270. package/dist/src/types/tool-context.js.map +1 -0
  271. package/dist/src/types/tool-error.d.ts +69 -0
  272. package/dist/src/types/tool-error.js +94 -0
  273. package/dist/src/types/tool-error.js.map +1 -0
  274. package/dist/src/types/tool-names.d.ts +57 -0
  275. package/dist/src/types/tool-names.js +64 -0
  276. package/dist/src/types/tool-names.js.map +1 -0
  277. package/dist/src/utils/EmojiFilter.d.ts +134 -0
  278. package/dist/src/utils/EmojiFilter.js +370 -0
  279. package/dist/src/utils/EmojiFilter.js.map +1 -0
  280. package/dist/src/utils/ast-grep-utils.d.ts +42 -0
  281. package/dist/src/utils/ast-grep-utils.js +140 -0
  282. package/dist/src/utils/ast-grep-utils.js.map +1 -0
  283. package/dist/src/utils/debugLogger.d.ts +11 -0
  284. package/dist/src/utils/debugLogger.js +16 -0
  285. package/dist/src/utils/debugLogger.js.map +1 -0
  286. package/dist/src/utils/diffOptions.d.ts +14 -0
  287. package/dist/src/utils/diffOptions.js +46 -0
  288. package/dist/src/utils/diffOptions.js.map +1 -0
  289. package/dist/src/utils/editor.d.ts +39 -0
  290. package/dist/src/utils/editor.js +212 -0
  291. package/dist/src/utils/editor.js.map +1 -0
  292. package/dist/src/utils/ensure-dirs.d.ts +10 -0
  293. package/dist/src/utils/ensure-dirs.js +16 -0
  294. package/dist/src/utils/ensure-dirs.js.map +1 -0
  295. package/dist/src/utils/errors.d.ts +59 -0
  296. package/dist/src/utils/errors.js +178 -0
  297. package/dist/src/utils/errors.js.map +1 -0
  298. package/dist/src/utils/fetch.d.ts +11 -0
  299. package/dist/src/utils/fetch.js +74 -0
  300. package/dist/src/utils/fetch.js.map +1 -0
  301. package/dist/src/utils/fileUtils.d.ts +32 -0
  302. package/dist/src/utils/fileUtils.js +363 -0
  303. package/dist/src/utils/fileUtils.js.map +1 -0
  304. package/dist/src/utils/fuzzy-replacer.d.ts +61 -0
  305. package/dist/src/utils/fuzzy-replacer.js +492 -0
  306. package/dist/src/utils/fuzzy-replacer.js.map +1 -0
  307. package/dist/src/utils/gitLineChanges.d.ts +12 -0
  308. package/dist/src/utils/gitLineChanges.js +171 -0
  309. package/dist/src/utils/gitLineChanges.js.map +1 -0
  310. package/dist/src/utils/gitUtils.d.ts +6 -0
  311. package/dist/src/utils/gitUtils.js +31 -0
  312. package/dist/src/utils/gitUtils.js.map +1 -0
  313. package/dist/src/utils/lsp-diagnostics-helper.d.ts +27 -0
  314. package/dist/src/utils/lsp-diagnostics-helper.js +62 -0
  315. package/dist/src/utils/lsp-diagnostics-helper.js.map +1 -0
  316. package/dist/src/utils/mediaUtils.d.ts +38 -0
  317. package/dist/src/utils/mediaUtils.js +22 -0
  318. package/dist/src/utils/mediaUtils.js.map +1 -0
  319. package/dist/src/utils/pathValidation.d.ts +7 -0
  320. package/dist/src/utils/pathValidation.js +39 -0
  321. package/dist/src/utils/pathValidation.js.map +1 -0
  322. package/dist/src/utils/paths.d.ts +7 -0
  323. package/dist/src/utils/paths.js +158 -0
  324. package/dist/src/utils/paths.js.map +1 -0
  325. package/dist/src/utils/resolveTextSearchTarget.d.ts +17 -0
  326. package/dist/src/utils/resolveTextSearchTarget.js +45 -0
  327. package/dist/src/utils/resolveTextSearchTarget.js.map +1 -0
  328. package/dist/src/utils/retry.d.ts +17 -0
  329. package/dist/src/utils/retry.js +185 -0
  330. package/dist/src/utils/retry.js.map +1 -0
  331. package/dist/src/utils/ripgrepPathResolver.d.ts +23 -0
  332. package/dist/src/utils/ripgrepPathResolver.js +179 -0
  333. package/dist/src/utils/ripgrepPathResolver.js.map +1 -0
  334. package/dist/src/utils/safeJsonStringify.d.ts +9 -0
  335. package/dist/src/utils/safeJsonStringify.js +21 -0
  336. package/dist/src/utils/safeJsonStringify.js.map +1 -0
  337. package/dist/src/utils/schemaValidator.d.ts +13 -0
  338. package/dist/src/utils/schemaValidator.js +275 -0
  339. package/dist/src/utils/schemaValidator.js.map +1 -0
  340. package/dist/src/utils/terminalSerializer.d.ts +33 -0
  341. package/dist/src/utils/terminalSerializer.js +6 -0
  342. package/dist/src/utils/terminalSerializer.js.map +1 -0
  343. package/dist/src/utils/todoContextTracker.d.ts +12 -0
  344. package/dist/src/utils/todoContextTracker.js +28 -0
  345. package/dist/src/utils/todoContextTracker.js.map +1 -0
  346. package/dist/src/utils/todoFormatter.d.ts +24 -0
  347. package/dist/src/utils/todoFormatter.js +157 -0
  348. package/dist/src/utils/todoFormatter.js.map +1 -0
  349. package/dist/src/utils/todoReminderService.d.ts +22 -0
  350. package/dist/src/utils/todoReminderService.js +43 -0
  351. package/dist/src/utils/todoReminderService.js.map +1 -0
  352. package/dist/src/utils/tool-key-storage-facade.d.ts +32 -0
  353. package/dist/src/utils/tool-key-storage-facade.js +56 -0
  354. package/dist/src/utils/tool-key-storage-facade.js.map +1 -0
  355. package/dist/src/utils/tool-key-storage-types.d.ts +56 -0
  356. package/dist/src/utils/tool-key-storage-types.js +56 -0
  357. package/dist/src/utils/tool-key-storage-types.js.map +1 -0
  358. package/dist/src/utils/toolOutputLimiter.d.ts +29 -0
  359. package/dist/src/utils/toolOutputLimiter.js +107 -0
  360. package/dist/src/utils/toolOutputLimiter.js.map +1 -0
  361. package/dist/src/utils/unicodeUtils.d.ts +55 -0
  362. package/dist/src/utils/unicodeUtils.js +129 -0
  363. package/dist/src/utils/unicodeUtils.js.map +1 -0
  364. package/package.json +75 -0
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export function isNodeError(error) {
7
+ return error instanceof Error && 'code' in error;
8
+ }
9
+ export function getErrorMessage(error) {
10
+ if (error instanceof Error) {
11
+ return error.message;
12
+ }
13
+ try {
14
+ return String(error);
15
+ }
16
+ catch {
17
+ return 'Failed to get error details';
18
+ }
19
+ }
20
+ export class FatalError extends Error {
21
+ exitCode;
22
+ constructor(message, exitCode) {
23
+ super(message);
24
+ this.exitCode = exitCode;
25
+ }
26
+ }
27
+ export class FatalAuthenticationError extends FatalError {
28
+ constructor(message) {
29
+ super(message, 41);
30
+ }
31
+ }
32
+ export class FatalInputError extends FatalError {
33
+ constructor(message) {
34
+ super(message, 42);
35
+ }
36
+ }
37
+ export class FatalSandboxError extends FatalError {
38
+ constructor(message) {
39
+ super(message, 44);
40
+ }
41
+ }
42
+ export class FatalConfigError extends FatalError {
43
+ constructor(message) {
44
+ super(message, 52);
45
+ }
46
+ }
47
+ export class FatalTurnLimitedError extends FatalError {
48
+ constructor(message) {
49
+ super(message, 53);
50
+ }
51
+ }
52
+ export class FatalToolExecutionError extends FatalError {
53
+ constructor(message) {
54
+ super(message, 54);
55
+ }
56
+ }
57
+ export class FatalCancellationError extends FatalError {
58
+ constructor(message) {
59
+ super(message, 130);
60
+ }
61
+ }
62
+ export class ForbiddenError extends Error {
63
+ }
64
+ export class UnauthorizedError extends Error {
65
+ }
66
+ export class BadRequestError extends Error {
67
+ }
68
+ export class NotYetImplemented extends Error {
69
+ constructor(message = 'This feature is not yet implemented') {
70
+ super(message);
71
+ this.name = 'NotYetImplemented';
72
+ }
73
+ }
74
+ export function toFriendlyError(error) {
75
+ if (error !== null &&
76
+ error !== undefined &&
77
+ typeof error === 'object' &&
78
+ 'response' in error) {
79
+ const gaxiosError = error;
80
+ const data = parseResponseData(gaxiosError);
81
+ if (data?.error?.message !== undefined &&
82
+ data.error.message !== '' &&
83
+ typeof data.error.code === 'number') {
84
+ switch (data.error.code) {
85
+ case 400:
86
+ return new BadRequestError(data.error.message);
87
+ case 401:
88
+ return new UnauthorizedError(data.error.message);
89
+ case 403:
90
+ // It's import to pass the message here since it might
91
+ // explain the cause like "the cloud project you're
92
+ // using doesn't have code assist enabled".
93
+ return new ForbiddenError(data.error.message);
94
+ default:
95
+ }
96
+ }
97
+ }
98
+ return error;
99
+ }
100
+ function parseResponseData(error) {
101
+ // Inexplicably, Gaxios sometimes doesn't JSONify the response data.
102
+ if (typeof error.response?.data === 'string') {
103
+ try {
104
+ return JSON.parse(error.response.data);
105
+ }
106
+ catch {
107
+ return undefined;
108
+ }
109
+ }
110
+ return error.response?.data;
111
+ }
112
+ /**
113
+ * Checks if an error is a 401 authentication error.
114
+ * Uses structured error properties from MCP SDK errors first.
115
+ *
116
+ * @plan PLAN-20250219-GMERGE021.R3.P03
117
+ * @requirement REQ-GMERGE021-R3-002
118
+ */
119
+ export function isAuthenticationError(error) {
120
+ if (error == null || typeof error !== 'object') {
121
+ return false;
122
+ }
123
+ // MCP SDK errors (SseError, StreamableHTTPError) carry numeric 'code'
124
+ if ('code' in error) {
125
+ const errorCode = error.code;
126
+ if (errorCode === 401) {
127
+ return true;
128
+ }
129
+ }
130
+ // Class identity check
131
+ if (error instanceof UnauthorizedError) {
132
+ return true;
133
+ }
134
+ // Cross-realm duck-typing (check both constructor name and error name)
135
+ if (error instanceof Error &&
136
+ (error.constructor.name === 'UnauthorizedError' ||
137
+ error.name === 'UnauthorizedError')) {
138
+ return true;
139
+ }
140
+ // Anchored message pattern — must not match '401' appearing in model names, IDs, etc.
141
+ const message = getErrorMessage(error);
142
+ if (/\bHTTP 401\b/.test(message) ||
143
+ /\bstatus 401\b/i.test(message) ||
144
+ /\b401 Unauthorized\b/i.test(message)) {
145
+ return true;
146
+ }
147
+ return false;
148
+ }
149
+ /**
150
+ * Checks if an error is a 404 Not Found error with proper detection.
151
+ * Uses typed error checking first, falls back to anchored pattern matching.
152
+ * Avoids false positives from strings like "port 40404" or "code 4040".
153
+ *
154
+ * @param error - The error to check
155
+ * @returns True if the error is a 404 error
156
+ */
157
+ export function is404Error(error) {
158
+ if (error == null || typeof error !== 'object') {
159
+ return false;
160
+ }
161
+ // MCP SDK errors (SseError, StreamableHTTPError) carry numeric 'code'
162
+ if ('code' in error) {
163
+ const errorCode = error.code;
164
+ if (errorCode === 404) {
165
+ return true;
166
+ }
167
+ }
168
+ // Anchored message pattern — must not match '404' appearing in ports, IDs, etc.
169
+ const message = getErrorMessage(error);
170
+ if (/\bHTTP 404\b/i.test(message) ||
171
+ /\bstatus[:\s]+404\b/i.test(message) ||
172
+ /\b404 Not Found\b/i.test(message) ||
173
+ /\bNot Found\b/.test(message)) {
174
+ return true;
175
+ }
176
+ return false;
177
+ }
178
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,6BAA6B,CAAC;IACvC,CAAC;AACH,CAAC;AAED,MAAM,OAAO,UAAW,SAAQ,KAAK;IAGxB;IAFX,YACE,OAAe,EACN,QAAgB;QAEzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,aAAQ,GAAR,QAAQ,CAAQ;IAG3B,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,UAAU;IACtD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrB,CAAC;CACF;AACD,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrB,CAAC;CACF;AACD,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrB,CAAC;CACF;AACD,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrB,CAAC;CACF;AACD,MAAM,OAAO,qBAAsB,SAAQ,UAAU;IACnD,YAAY,OAAe;Q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,IAAI,CAAC;IACd,CAAC;IAED,sFAAsF;IACtF,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACvC,IACE,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;QAC5B,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC;QAC/B,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,EACrC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,sEAAsE;IACtE,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;QACpB,MAAM,SAAS,GAAI,KAA2B,CAAC,IAAI,CAAC;QACpD,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,gFAAgF;IAChF,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACvC,IACE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC;QAC7B,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC;QACpC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC;QAClC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,EAC7B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export declare class FetchError extends Error {
7
+ code?: string | undefined;
8
+ constructor(message: string, code?: string | undefined);
9
+ }
10
+ export declare function isPrivateIp(url: string): boolean;
11
+ export declare function fetchWithTimeout(url: string, timeout: number, signal?: AbortSignal, init?: RequestInit): Promise<Response>;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { getErrorMessage, isNodeError } from './errors.js';
7
+ import { URL } from 'node:url';
8
+ const PRIVATE_IP_RANGES = [
9
+ /^10\./,
10
+ /^127\./,
11
+ /^172\.(1[6-9]|2[0-9]|3[0-1])\./,
12
+ /^192\.168\./,
13
+ /^::1$/,
14
+ /^fc00:/,
15
+ /^fe80:/,
16
+ ];
17
+ export class FetchError extends Error {
18
+ code;
19
+ constructor(message, code) {
20
+ super(message);
21
+ this.code = code;
22
+ this.name = 'FetchError';
23
+ }
24
+ }
25
+ export function isPrivateIp(url) {
26
+ try {
27
+ const hostname = new URL(url).hostname;
28
+ return PRIVATE_IP_RANGES.some((range) => range.test(hostname));
29
+ }
30
+ catch {
31
+ // Invalid URL - not a private IP
32
+ return false;
33
+ }
34
+ }
35
+ export async function fetchWithTimeout(url, timeout, signal, init) {
36
+ const controller = new AbortController();
37
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
38
+ const onAbort = () => {
39
+ clearTimeout(timeoutId);
40
+ controller.abort();
41
+ };
42
+ // If an external signal is provided, listen to it
43
+ if (signal) {
44
+ if (signal.aborted) {
45
+ clearTimeout(timeoutId);
46
+ controller.abort();
47
+ }
48
+ else {
49
+ signal.addEventListener('abort', onAbort);
50
+ }
51
+ }
52
+ try {
53
+ const response = await fetch(url, { ...init, signal: controller.signal });
54
+ return response;
55
+ }
56
+ catch (error) {
57
+ if ((isNodeError(error) && error.code === 'ABORT_ERR') ||
58
+ (error instanceof Error && error.name === 'AbortError')) {
59
+ // Check if it was our timeout or the external signal
60
+ if (signal?.aborted === true) {
61
+ throw new FetchError('Request aborted by user', 'ABORT_ERR');
62
+ }
63
+ throw new FetchError(`Request timed out after ${timeout}ms`, 'ETIMEDOUT');
64
+ }
65
+ throw new FetchError(getErrorMessage(error));
66
+ }
67
+ finally {
68
+ clearTimeout(timeoutId);
69
+ if (signal) {
70
+ signal.removeEventListener('abort', onAbort);
71
+ }
72
+ }
73
+ }
74
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,iBAAiB,GAAG;IACxB,OAAO;IACP,QAAQ;IACR,gCAAgC;IAChC,aAAa;IACb,OAAO;IACP,QAAQ;IACR,QAAQ;CACT,CAAC;AAEF,MAAM,OAAO,UAAW,SAAQ,KAAK;IAG1B;IAFT,YACE,OAAe,EACR,IAAa;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFR,SAAI,GAAJ,IAAI,CAAS;QAGpB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;QACvC,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjE,CAAC;IAAC,MAAM,CAAC;QACP,iCAAiC;QACjC,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAW,EACX,OAAe,EACf,MAAoB,EACpB,IAAkB;IAElB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;I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C;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { type PartUnion } from '@google/genai';
7
+ import { ToolErrorType } from '../types/tool-error.js';
8
+ export declare const DEFAULT_MAX_LINES_TEXT_FILE = 2000;
9
+ export declare const DEFAULT_ENCODING: BufferEncoding;
10
+ type UnicodeEncoding = 'utf8' | 'utf16le' | 'utf16be' | 'utf32le' | 'utf32be';
11
+ interface BOMInfo {
12
+ encoding: UnicodeEncoding;
13
+ bomLength: number;
14
+ }
15
+ /** Detect a Unicode BOM (Byte Order Mark) if present. */
16
+ export declare function detectBOM(buf: Buffer): BOMInfo | null;
17
+ export declare function readFileWithEncoding(filePath: string): Promise<string>;
18
+ export declare function getSpecificMimeType(filePath: string): string | undefined;
19
+ export declare function isBinaryFile(filePath: string): Promise<boolean>;
20
+ export declare function detectFileType(filePath: string): Promise<'text' | 'image' | 'pdf' | 'audio' | 'video' | 'binary' | 'svg'>;
21
+ export interface ProcessedFileReadResult {
22
+ llmContent: PartUnion;
23
+ returnDisplay: string;
24
+ error?: string;
25
+ errorType?: ToolErrorType;
26
+ isTruncated?: boolean;
27
+ originalLineCount?: number;
28
+ linesShown?: [number, number];
29
+ }
30
+ export declare function countLines(lines: string[]): number;
31
+ export declare function processSingleFileContent(filePath: string, rootDirectory: string, offset?: number, limit?: number): Promise<ProcessedFileReadResult>;
32
+ export {};
@@ -0,0 +1,363 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import mime from 'mime-types';
9
+ import { ToolErrorType } from '../types/tool-error.js';
10
+ import { debugLogger } from './debugLogger.js';
11
+ // Constants for text file processing
12
+ export const DEFAULT_MAX_LINES_TEXT_FILE = 2000;
13
+ const MAX_LINE_LENGTH_TEXT_FILE = 2000;
14
+ // Default values for encoding and separator format
15
+ export const DEFAULT_ENCODING = 'utf-8';
16
+ const BINARY_EXTENSIONS = [
17
+ '.exe',
18
+ '.dll',
19
+ '.so',
20
+ '.dylib',
21
+ '.bin',
22
+ '.dat',
23
+ '.wasm',
24
+ '.zip',
25
+ '.tar',
26
+ '.gz',
27
+ '.bz2',
28
+ '.7z',
29
+ '.rar',
30
+ '.jpg',
31
+ '.jpeg',
32
+ '.png',
33
+ '.gif',
34
+ '.bmp',
35
+ '.webp',
36
+ '.ico',
37
+ '.mp3',
38
+ '.mp4',
39
+ '.avi',
40
+ '.mov',
41
+ '.wav',
42
+ '.flac',
43
+ '.ogg',
44
+ '.pdf',
45
+ ];
46
+ /** Detect a Unicode BOM (Byte Order Mark) if present. */
47
+ export function detectBOM(buf) {
48
+ if (buf.length >= 4) {
49
+ if (buf[0] === 0xff &&
50
+ buf[1] === 0xfe &&
51
+ buf[2] === 0x00 &&
52
+ buf[3] === 0x00) {
53
+ return { encoding: 'utf32le', bomLength: 4 };
54
+ }
55
+ if (buf[0] === 0x00 &&
56
+ buf[1] === 0x00 &&
57
+ buf[2] === 0xfe &&
58
+ buf[3] === 0xff) {
59
+ return { encoding: 'utf32be', bomLength: 4 };
60
+ }
61
+ }
62
+ if (buf.length >= 3 &&
63
+ buf[0] === 0xef &&
64
+ buf[1] === 0xbb &&
65
+ buf[2] === 0xbf) {
66
+ return { encoding: 'utf8', bomLength: 3 };
67
+ }
68
+ if (buf.length >= 2) {
69
+ if (buf[0] === 0xff &&
70
+ buf[1] === 0xfe &&
71
+ (buf.length < 4 || buf[2] !== 0x00 || buf[3] !== 0x00)) {
72
+ return { encoding: 'utf16le', bomLength: 2 };
73
+ }
74
+ if (buf[0] === 0xfe && buf[1] === 0xff) {
75
+ return { encoding: 'utf16be', bomLength: 2 };
76
+ }
77
+ }
78
+ return null;
79
+ }
80
+ function decodeUTF16BE(buf) {
81
+ if (buf.length === 0)
82
+ return '';
83
+ const swapped = Buffer.from(buf);
84
+ swapped.swap16();
85
+ return swapped.toString('utf16le');
86
+ }
87
+ function decodeUTF32(buf, littleEndian) {
88
+ if (buf.length < 4)
89
+ return '';
90
+ const usable = buf.length - (buf.length % 4);
91
+ let out = '';
92
+ for (let i = 0; i < usable; i += 4) {
93
+ const cp = littleEndian
94
+ ? (buf[i] |
95
+ (buf[i + 1] << 8) |
96
+ (buf[i + 2] << 16) |
97
+ (buf[i + 3] << 24)) >>>
98
+ 0
99
+ : (buf[i + 3] |
100
+ (buf[i + 2] << 8) |
101
+ (buf[i + 1] << 16) |
102
+ (buf[i] << 24)) >>>
103
+ 0;
104
+ if (cp <= 0x10ffff && !(cp >= 0xd800 && cp <= 0xdfff)) {
105
+ out += String.fromCodePoint(cp);
106
+ }
107
+ else {
108
+ out += '\uFFFD';
109
+ }
110
+ }
111
+ return out;
112
+ }
113
+ export async function readFileWithEncoding(filePath) {
114
+ const full = await fs.promises.readFile(filePath);
115
+ if (full.length === 0)
116
+ return '';
117
+ const bom = detectBOM(full);
118
+ if (!bom) {
119
+ return full.toString('utf8');
120
+ }
121
+ const content = full.subarray(bom.bomLength);
122
+ switch (bom.encoding) {
123
+ case 'utf8':
124
+ return content.toString('utf8');
125
+ case 'utf16le':
126
+ return content.toString('utf16le');
127
+ case 'utf16be':
128
+ return decodeUTF16BE(content);
129
+ case 'utf32le':
130
+ return decodeUTF32(content, true);
131
+ case 'utf32be':
132
+ return decodeUTF32(content, false);
133
+ }
134
+ }
135
+ export function getSpecificMimeType(filePath) {
136
+ const lookedUpMime = mime.lookup(filePath);
137
+ return typeof lookedUpMime === 'string' ? lookedUpMime : undefined;
138
+ }
139
+ export async function isBinaryFile(filePath) {
140
+ let fh = null;
141
+ try {
142
+ fh = await fs.promises.open(filePath, 'r');
143
+ const stats = await fh.stat();
144
+ const fileSize = stats.size;
145
+ if (fileSize === 0)
146
+ return false;
147
+ const sampleSize = Math.min(4096, fileSize);
148
+ const buf = Buffer.alloc(sampleSize);
149
+ const { bytesRead } = await fh.read(buf, 0, sampleSize, 0);
150
+ if (bytesRead === 0)
151
+ return false;
152
+ const bom = detectBOM(buf.subarray(0, Math.min(4, bytesRead)));
153
+ if (bom)
154
+ return false;
155
+ let nonPrintableCount = 0;
156
+ for (let i = 0; i < bytesRead; i++) {
157
+ if (buf[i] === 0)
158
+ return true;
159
+ if (buf[i] < 9 || (buf[i] > 13 && buf[i] < 32)) {
160
+ nonPrintableCount++;
161
+ }
162
+ }
163
+ return nonPrintableCount / bytesRead > 0.3;
164
+ }
165
+ catch (error) {
166
+ debugLogger.warn(`Failed to check if file is binary: ${filePath}`, error instanceof Error ? error.message : String(error));
167
+ return false;
168
+ }
169
+ finally {
170
+ if (fh) {
171
+ try {
172
+ await fh.close();
173
+ }
174
+ catch (closeError) {
175
+ debugLogger.warn(`Failed to close file handle for: ${filePath}`, closeError instanceof Error ? closeError.message : String(closeError));
176
+ }
177
+ }
178
+ }
179
+ }
180
+ export async function detectFileType(filePath) {
181
+ const ext = path.extname(filePath).toLowerCase();
182
+ if (['.ts', '.mts', '.cts', '.tsx'].includes(ext)) {
183
+ return 'text';
184
+ }
185
+ if (ext === '.svg') {
186
+ return 'svg';
187
+ }
188
+ const lookedUpMimeType = mime.lookup(filePath);
189
+ if (typeof lookedUpMimeType === 'string' && lookedUpMimeType !== '') {
190
+ if (lookedUpMimeType.startsWith('image/'))
191
+ return 'image';
192
+ if (lookedUpMimeType.startsWith('audio/'))
193
+ return 'audio';
194
+ if (lookedUpMimeType.startsWith('video/'))
195
+ return 'video';
196
+ if (lookedUpMimeType === 'application/pdf')
197
+ return 'pdf';
198
+ }
199
+ if (BINARY_EXTENSIONS.includes(ext)) {
200
+ return 'binary';
201
+ }
202
+ if (await isBinaryFile(filePath)) {
203
+ return 'binary';
204
+ }
205
+ return 'text';
206
+ }
207
+ export function countLines(lines) {
208
+ return lines.length > 0 && lines[lines.length - 1] === ''
209
+ ? lines.length - 1
210
+ : lines.length;
211
+ }
212
+ function validateFileAccess(filePath) {
213
+ if (!fs.existsSync(filePath)) {
214
+ return {
215
+ llmContent: 'Could not read file because no file was found at the specified path.',
216
+ returnDisplay: 'File not found.',
217
+ error: `File not found: ${filePath}`,
218
+ errorType: ToolErrorType.FILE_NOT_FOUND,
219
+ };
220
+ }
221
+ return null;
222
+ }
223
+ function validateNotDirectory(filePath, stats) {
224
+ if (stats.isDirectory()) {
225
+ return {
226
+ llmContent: 'Could not read file because the provided path is a directory, not a file.',
227
+ returnDisplay: 'Path is a directory.',
228
+ error: `Path is a directory, not a file: ${filePath}`,
229
+ errorType: ToolErrorType.TARGET_IS_DIRECTORY,
230
+ };
231
+ }
232
+ return null;
233
+ }
234
+ function validateFileSize(filePath, stats) {
235
+ const fileSizeInMB = stats.size / (1024 * 1024);
236
+ if (fileSizeInMB > 20) {
237
+ return {
238
+ llmContent: 'File size exceeds the 20MB limit.',
239
+ returnDisplay: 'File size exceeds the 20MB limit.',
240
+ error: `File size exceeds the 20MB limit: ${filePath} (${fileSizeInMB.toFixed(2)}MB)`,
241
+ errorType: ToolErrorType.FILE_TOO_LARGE,
242
+ };
243
+ }
244
+ return null;
245
+ }
246
+ function processBinaryFile(relativePathForDisplay) {
247
+ return {
248
+ llmContent: `Cannot display content of binary file: ${relativePathForDisplay}`,
249
+ returnDisplay: `Skipped binary file: ${relativePathForDisplay}`,
250
+ };
251
+ }
252
+ async function processSvgFile(filePath, relativePathForDisplay, stats) {
253
+ const svgMaxSizeBytes = 1 * 1024 * 1024;
254
+ if (stats.size > svgMaxSizeBytes) {
255
+ return {
256
+ llmContent: `Cannot display content of SVG file larger than 1MB: ${relativePathForDisplay}`,
257
+ returnDisplay: `Skipped large SVG file (>1MB): ${relativePathForDisplay}`,
258
+ };
259
+ }
260
+ const content = await readFileWithEncoding(filePath);
261
+ return {
262
+ llmContent: content,
263
+ returnDisplay: `Read SVG as text: ${relativePathForDisplay}`,
264
+ };
265
+ }
266
+ async function processTextFile(filePath, relativePathForDisplay, offset, limit) {
267
+ const content = await readFileWithEncoding(filePath);
268
+ const lines = content.split('\n');
269
+ const originalLineCount = countLines(lines);
270
+ const startLine = offset !== undefined && !Number.isNaN(offset) ? offset : 0;
271
+ const effectiveLimit = limit ?? DEFAULT_MAX_LINES_TEXT_FILE;
272
+ const endLine = Math.min(startLine + effectiveLimit, originalLineCount);
273
+ const actualStartLine = Math.min(startLine, originalLineCount);
274
+ const selectedLines = lines.slice(actualStartLine, endLine);
275
+ const formattedLines = selectedLines.map((line) => line.length > MAX_LINE_LENGTH_TEXT_FILE
276
+ ? line.substring(0, MAX_LINE_LENGTH_TEXT_FILE) + '... [truncated]'
277
+ : line);
278
+ const linesWereTruncatedInLength = selectedLines.some((line) => line.length > MAX_LINE_LENGTH_TEXT_FILE);
279
+ const contentRangeTruncated = startLine > 0 || endLine < originalLineCount;
280
+ const isTruncated = contentRangeTruncated || linesWereTruncatedInLength;
281
+ const llmContent = formattedLines.join('\n');
282
+ let returnDisplay = '';
283
+ if (contentRangeTruncated) {
284
+ returnDisplay = `Read lines ${actualStartLine + 1}-${endLine} of ${originalLineCount} from ${relativePathForDisplay}`;
285
+ if (linesWereTruncatedInLength) {
286
+ returnDisplay += ' (some lines were shortened)';
287
+ }
288
+ }
289
+ else if (linesWereTruncatedInLength) {
290
+ returnDisplay = `Read all ${originalLineCount} lines from ${relativePathForDisplay} (some lines were shortened)`;
291
+ }
292
+ return {
293
+ llmContent,
294
+ returnDisplay,
295
+ isTruncated,
296
+ originalLineCount,
297
+ linesShown: [actualStartLine + 1, endLine],
298
+ };
299
+ }
300
+ async function processMediaFile(filePath, relativePathForDisplay, fileType) {
301
+ const contentBuffer = await fs.promises.readFile(filePath);
302
+ const base64Data = contentBuffer.toString('base64');
303
+ const mimeTypeRaw = mime.lookup(filePath);
304
+ const mimeType = typeof mimeTypeRaw === 'string' && mimeTypeRaw !== ''
305
+ ? mimeTypeRaw
306
+ : 'application/octet-stream';
307
+ return {
308
+ llmContent: {
309
+ inlineData: {
310
+ data: base64Data,
311
+ mimeType,
312
+ },
313
+ },
314
+ returnDisplay: `Read ${fileType} file: ${relativePathForDisplay}`,
315
+ };
316
+ }
317
+ async function processFileByType(filePath, relativePathForDisplay, fileType, stats, offset, limit) {
318
+ switch (fileType) {
319
+ case 'binary':
320
+ return processBinaryFile(relativePathForDisplay);
321
+ case 'svg':
322
+ return processSvgFile(filePath, relativePathForDisplay, stats);
323
+ case 'text':
324
+ return processTextFile(filePath, relativePathForDisplay, offset, limit);
325
+ case 'image':
326
+ case 'pdf':
327
+ case 'audio':
328
+ case 'video':
329
+ return processMediaFile(filePath, relativePathForDisplay, fileType);
330
+ }
331
+ }
332
+ export async function processSingleFileContent(filePath, rootDirectory, offset, limit) {
333
+ try {
334
+ const accessError = validateFileAccess(filePath);
335
+ if (accessError)
336
+ return accessError;
337
+ const stats = await fs.promises.stat(filePath);
338
+ const dirError = validateNotDirectory(filePath, stats);
339
+ if (dirError)
340
+ return dirError;
341
+ const sizeError = validateFileSize(filePath, stats);
342
+ if (sizeError)
343
+ return sizeError;
344
+ const fileType = await detectFileType(filePath);
345
+ const relativePathForDisplay = path
346
+ .relative(rootDirectory, filePath)
347
+ .replace(/\\/g, '/');
348
+ return await processFileByType(filePath, relativePathForDisplay, fileType, stats, offset, limit);
349
+ }
350
+ catch (error) {
351
+ const errorMessage = error instanceof Error ? error.message : String(error);
352
+ const displayPath = path
353
+ .relative(rootDirectory, filePath)
354
+ .replace(/\\/g, '/');
355
+ return {
356
+ llmContent: `Error reading file ${displayPath}: ${errorMessage}`,
357
+ returnDisplay: `Error reading file ${displayPath}: ${errorMessage}`,
358
+ error: `Error reading file ${filePath}: ${errorMessage}`,
359
+ errorType: ToolErrorType.READ_CONTENT_FAILURE,
360
+ };
361
+ }
362
+ }
363
+ //# sourceMappingURL=fileUtils.js.map