@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,238 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import fs from 'node:fs/promises';
7
+ import path from 'node:path';
8
+ import * as Diff from 'diff';
9
+ import { makeRelative, shortenPath } from '../utils/paths.js';
10
+ import { BaseDeclarativeTool, BaseToolInvocation, Kind, ToolConfirmationOutcome, } from './tools.js';
11
+ import { ToolErrorType } from '../types/tool-error.js';
12
+ import { getSpecificMimeType } from '../utils/fileUtils.js';
13
+ import { DEFAULT_CREATE_PATCH_OPTIONS } from '../utils/diffOptions.js';
14
+ import { collectLspDiagnosticsBlock } from '../utils/lsp-diagnostics-helper.js';
15
+ import { validatePathWithinWorkspace } from '../utils/pathValidation.js';
16
+ class DeleteLineRangeToolInvocation extends BaseToolInvocation {
17
+ host;
18
+ ideService;
19
+ lspService;
20
+ constructor(host, ideService, lspService, params, messageBus) {
21
+ super(params, messageBus);
22
+ this.host = host;
23
+ this.ideService = ideService;
24
+ this.lspService = lspService;
25
+ }
26
+ getFilePath() {
27
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- intentional falsy coalescing: empty string paths are invalid, fall back to file_path
28
+ return this.params.absolute_path || this.params.file_path || '';
29
+ }
30
+ getDescription() {
31
+ const relativePath = makeRelative(this.getFilePath(), this.host.getTargetDir());
32
+ return `Delete lines ${this.params.start_line}-${this.params.end_line} from ${shortenPath(relativePath)}`;
33
+ }
34
+ toolLocations() {
35
+ return [{ path: this.getFilePath(), line: this.params.start_line }];
36
+ }
37
+ async shouldConfirmExecute(_abortSignal) {
38
+ const approvalMode = this.host.getApprovalMode();
39
+ if (approvalMode === 'auto' || approvalMode === 'yolo') {
40
+ return false;
41
+ }
42
+ const filePath = this.getFilePath();
43
+ let originalContent;
44
+ try {
45
+ originalContent = await fs.readFile(filePath, 'utf8');
46
+ }
47
+ catch {
48
+ return false;
49
+ }
50
+ const lines = originalContent.split('\n');
51
+ const totalLines = lines.length;
52
+ if (this.params.start_line > totalLines) {
53
+ return false;
54
+ }
55
+ const startIndex = this.params.start_line - 1;
56
+ const count = this.params.end_line - this.params.start_line + 1;
57
+ const newLines = [...lines];
58
+ newLines.splice(startIndex, count);
59
+ const newContent = newLines.join('\n');
60
+ const relativePath = makeRelative(filePath, this.host.getTargetDir());
61
+ const fileName = path.basename(filePath);
62
+ const fileDiff = Diff.createPatch(fileName, originalContent, newContent, 'Current', 'Proposed', DEFAULT_CREATE_PATCH_OPTIONS);
63
+ const ideConfirmation = this.ideService?.getConnectionStatus() === 'connected'
64
+ ? this.ideService.applyDiff({ filePath, diff: newContent })
65
+ : undefined;
66
+ const confirmationDetails = {
67
+ type: 'edit',
68
+ title: `Confirm Delete: ${shortenPath(relativePath)} (lines ${this.params.start_line}-${this.params.end_line})`,
69
+ fileName,
70
+ filePath,
71
+ fileDiff,
72
+ originalContent,
73
+ newContent,
74
+ onConfirm: async (outcome) => {
75
+ if (outcome === ToolConfirmationOutcome.ProceedAlways) {
76
+ this.host.setApprovalMode('auto');
77
+ }
78
+ },
79
+ ideConfirmation,
80
+ };
81
+ return confirmationDetails;
82
+ }
83
+ async execute() {
84
+ const filePath = this.getFilePath();
85
+ let content;
86
+ try {
87
+ content = await fs.readFile(filePath, 'utf8');
88
+ }
89
+ catch (error) {
90
+ const message = error instanceof Error ? error.message : String(error);
91
+ return {
92
+ llmContent: `Error reading file: ${message}`,
93
+ returnDisplay: `Error reading file: ${message}`,
94
+ error: {
95
+ message,
96
+ type: ToolErrorType.FILE_NOT_FOUND,
97
+ },
98
+ };
99
+ }
100
+ const lines = content.split('\n');
101
+ const totalLines = lines.length;
102
+ if (this.params.start_line > totalLines) {
103
+ return {
104
+ llmContent: `Cannot delete lines: start_line ${this.params.start_line} is beyond the total number of lines (${totalLines})`,
105
+ returnDisplay: `Cannot delete lines: start_line ${this.params.start_line} is beyond the total number of lines (${totalLines})`,
106
+ error: {
107
+ message: `start_line ${this.params.start_line} exceeds file length (${totalLines})`,
108
+ type: ToolErrorType.INVALID_TOOL_PARAMS,
109
+ },
110
+ };
111
+ }
112
+ const startIndex = this.params.start_line - 1;
113
+ const count = this.params.end_line - this.params.start_line + 1;
114
+ const deletedContent = lines
115
+ .slice(startIndex, startIndex + count)
116
+ .join('\n');
117
+ lines.splice(startIndex, count);
118
+ const newContent = lines.join('\n');
119
+ try {
120
+ await fs.writeFile(filePath, newContent, 'utf8');
121
+ this.recordMetrics(filePath, count);
122
+ const llmSuccessMessageParts = [
123
+ `Successfully deleted lines ${this.params.start_line}-${this.params.end_line} from ${filePath}`,
124
+ deletedContent,
125
+ ];
126
+ try {
127
+ const diagBlock = this.lspService === undefined
128
+ ? null
129
+ : await collectLspDiagnosticsBlock(this.lspService, this.host, filePath);
130
+ if (diagBlock) {
131
+ llmSuccessMessageParts.push(diagBlock);
132
+ }
133
+ }
134
+ catch {
135
+ // LSP failure must never fail the edit (REQ-GRACE-050, REQ-GRACE-055)
136
+ }
137
+ return {
138
+ llmContent: llmSuccessMessageParts.join('\n\n'),
139
+ returnDisplay: `Deleted ${count} lines (${this.params.start_line}-${this.params.end_line})`,
140
+ };
141
+ }
142
+ catch (error) {
143
+ const message = error instanceof Error ? error.message : String(error);
144
+ return {
145
+ llmContent: `Error writing file: ${message}`,
146
+ returnDisplay: `Error writing file: ${message}`,
147
+ error: {
148
+ message,
149
+ type: ToolErrorType.FILE_WRITE_FAILURE,
150
+ },
151
+ };
152
+ }
153
+ }
154
+ recordMetrics(filePath, linesDeleted) {
155
+ const mimetype = getSpecificMimeType(filePath);
156
+ const extension = path.extname(filePath);
157
+ void linesDeleted;
158
+ void mimetype;
159
+ void extension;
160
+ }
161
+ }
162
+ /**
163
+ * Implementation of the DeleteLineRange tool logic
164
+ */
165
+ export class DeleteLineRangeTool extends BaseDeclarativeTool {
166
+ host;
167
+ ideService;
168
+ lspService;
169
+ static Name = 'delete_line_range';
170
+ constructor(host, ideService, lspService) {
171
+ super(DeleteLineRangeTool.Name, 'DeleteLineRange', `Deletes a specific range of lines from a file. This is the preferred way to delete large blocks, as it avoids using a massive, brittle 'old_string' in the 'replace' tool. Always read the file or use 'get_file_outline' first to get the exact line numbers before deleting.`, Kind.Edit, {
172
+ properties: {
173
+ absolute_path: {
174
+ description: "The absolute path to the file to modify. Must start with '/' and be within the workspace.",
175
+ type: 'string',
176
+ },
177
+ file_path: {
178
+ description: 'Alternative parameter name for absolute_path (for backward compatibility). The absolute path to the file to modify.',
179
+ type: 'string',
180
+ },
181
+ start_line: {
182
+ description: 'The 1-based line number to start deleting from (inclusive).',
183
+ type: 'number',
184
+ minimum: 1,
185
+ },
186
+ end_line: {
187
+ description: 'The 1-based line number to end deleting at (inclusive). Must be >= start_line.',
188
+ type: 'number',
189
+ minimum: 1,
190
+ },
191
+ },
192
+ required: ['start_line', 'end_line'],
193
+ type: 'object',
194
+ });
195
+ this.host = host;
196
+ this.ideService = ideService;
197
+ this.lspService = lspService;
198
+ }
199
+ validateToolParamValues(params) {
200
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- intentional falsy coalescing: empty string paths are invalid
201
+ const filePath = params.absolute_path || params.file_path || '';
202
+ if (filePath.trim() === '') {
203
+ return "Either 'absolute_path' or 'file_path' parameter must be provided and non-empty.";
204
+ }
205
+ if (!path.isAbsolute(filePath)) {
206
+ return `File path must be absolute: ${filePath}`;
207
+ }
208
+ const pathError = validatePathWithinWorkspace(this.host.getWorkspaceRoots(), filePath);
209
+ if (pathError) {
210
+ return pathError;
211
+ }
212
+ if (params.start_line < 1) {
213
+ return 'start_line must be a positive integer (>= 1)';
214
+ }
215
+ if (params.end_line < 1) {
216
+ return 'end_line must be a positive integer (>= 1)';
217
+ }
218
+ if (params.end_line < params.start_line) {
219
+ return 'end_line must be greater than or equal to start_line';
220
+ }
221
+ const fileService = this.host.getFileService();
222
+ if (fileService.shouldLlxprtIgnoreFile(filePath)) {
223
+ return `File path '${filePath}' is ignored by .llxprtignore pattern(s).`;
224
+ }
225
+ return null;
226
+ }
227
+ createInvocation(params, messageBus) {
228
+ const normalizedParams = { ...params };
229
+ if (!normalizedParams.absolute_path && normalizedParams.file_path) {
230
+ normalizedParams.absolute_path = normalizedParams.file_path;
231
+ }
232
+ return new DeleteLineRangeToolInvocation(this.host, this.ideService, this.lspService, normalizedParams, messageBus);
233
+ }
234
+ async execute(params, signal = new AbortController().signal) {
235
+ return this.build(params).execute(signal);
236
+ }
237
+ }
238
+ //# sourceMappingURL=delete_line_range.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete_line_range.js","sourceRoot":"","sources":["../../../src/tools/delete_line_range.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B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MAAM;QAElD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Portions of this code are derived from opencode (https://github.com/sst/opencode)
7
+ * Copyright (c) 2025 opencode
8
+ * Licensed under the MIT License.
9
+ */
10
+ import { BaseDeclarativeTool, type ToolInvocation, type ToolResult } from './tools.js';
11
+ import type { IToolHost, IToolMessageBus } from '../interfaces/index.js';
12
+ export interface DirectWebFetchToolParams {
13
+ url: string;
14
+ format: 'text' | 'markdown' | 'html';
15
+ timeout?: number;
16
+ }
17
+ export declare class DirectWebFetchTool extends BaseDeclarativeTool<DirectWebFetchToolParams, ToolResult> {
18
+ private readonly host;
19
+ static readonly Name = "direct_web_fetch";
20
+ constructor(host: IToolHost);
21
+ protected createInvocation(params: DirectWebFetchToolParams, messageBus: IToolMessageBus): ToolInvocation<DirectWebFetchToolParams, ToolResult>;
22
+ }
@@ -0,0 +1,215 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Portions of this code are derived from opencode (https://github.com/sst/opencode)
7
+ * Copyright (c) 2025 opencode
8
+ * Licensed under the MIT License.
9
+ */
10
+ import { BaseDeclarativeTool, BaseToolInvocation, Kind, } from './tools.js';
11
+ import { DIRECT_WEB_FETCH_TOOL } from '../types/tool-names.js';
12
+ import { ToolErrorType } from '../types/tool-error.js';
13
+ import fetch from 'node-fetch';
14
+ import TurndownService from 'turndown';
15
+ import * as cheerio from 'cheerio';
16
+ import { retryWithBackoff } from '../utils/retry.js';
17
+ import { ensureJsonSafe } from '../utils/unicodeUtils.js';
18
+ const MAX_RESPONSE_SIZE = 5 * 1024 * 1024; // 5MB
19
+ const DEFAULT_TIMEOUT = 30 * 1000; // 30 seconds
20
+ const MAX_TIMEOUT = 120 * 1000; // 2 minutes
21
+ const ACCEPT_HEADERS = {
22
+ markdown: 'text/markdown;q=1.0, text/x-markdown;q=0.9, text/plain;q=0.8, text/html;q=0.7, */*;q=0.1',
23
+ text: 'text/plain;q=1.0, text/markdown;q=0.9, text/html;q=0.8, */*;q=0.1',
24
+ html: 'text/html;q=1.0, application/xhtml+xml;q=0.9, text/plain;q=0.8, text/markdown;q=0.7, */*;q=0.1',
25
+ };
26
+ export class DirectWebFetchTool extends BaseDeclarativeTool {
27
+ host;
28
+ static Name = DIRECT_WEB_FETCH_TOOL;
29
+ constructor(host) {
30
+ super(DirectWebFetchTool.Name, 'DirectWebFetch', 'Fetches content from a specified URL and converts it to the requested format (text, markdown, or html).', Kind.Search, {
31
+ type: 'object',
32
+ properties: {
33
+ url: {
34
+ type: 'string',
35
+ description: 'The URL to fetch content from',
36
+ },
37
+ format: {
38
+ type: 'string',
39
+ enum: ['text', 'markdown', 'html'],
40
+ description: 'The format to return the content in (text, markdown, or html)',
41
+ },
42
+ timeout: {
43
+ type: 'number',
44
+ description: 'Optional timeout in seconds (max 120)',
45
+ },
46
+ },
47
+ required: ['url', 'format'],
48
+ });
49
+ this.host = host;
50
+ }
51
+ createInvocation(params, messageBus) {
52
+ return new DirectWebFetchToolInvocation(this.host, params, messageBus);
53
+ }
54
+ }
55
+ class DirectWebFetchToolInvocation extends BaseToolInvocation {
56
+ constructor(_host, params, messageBus) {
57
+ super(params, messageBus);
58
+ }
59
+ getDescription() {
60
+ return `Fetch content from ${this.params.url}`;
61
+ }
62
+ async execute(signal, _updateOutput) {
63
+ const protocolError = this.validateUrlProtocol();
64
+ if (protocolError)
65
+ return protocolError;
66
+ const controller = new AbortController();
67
+ const timeoutId = setTimeout(() => controller.abort(), this.getTimeoutMs());
68
+ const onAbort = () => controller.abort();
69
+ signal.addEventListener('abort', onAbort);
70
+ try {
71
+ if (signal.aborted)
72
+ return this.createAbortResult();
73
+ const response = await this.fetchResponse(controller.signal);
74
+ const arrayBuffer = await this.readBoundedResponse(response);
75
+ const content = new TextDecoder().decode(arrayBuffer);
76
+ const output = this.convertContent(content,
77
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- Preserve prior empty-string fallback for missing/blank content-type.
78
+ response.headers.get('content-type') || '');
79
+ return {
80
+ llmContent: ensureJsonSafe(output),
81
+ returnDisplay: `Fetched ${this.params.url} as ${this.params.format}`,
82
+ };
83
+ }
84
+ catch (error) {
85
+ return this.createFetchErrorResult(error);
86
+ }
87
+ finally {
88
+ clearTimeout(timeoutId);
89
+ signal.removeEventListener('abort', onAbort);
90
+ }
91
+ }
92
+ validateUrlProtocol() {
93
+ if (this.params.url.startsWith('http://') ||
94
+ this.params.url.startsWith('https://')) {
95
+ return undefined;
96
+ }
97
+ return {
98
+ llmContent: 'URL must start with http:// or https://',
99
+ returnDisplay: 'Invalid URL',
100
+ error: {
101
+ message: 'Invalid URL protocol',
102
+ type: ToolErrorType.INVALID_ARGUMENT,
103
+ },
104
+ };
105
+ }
106
+ getTimeoutMs() {
107
+ return Math.min((this.params.timeout ?? DEFAULT_TIMEOUT / 1000) * 1000, MAX_TIMEOUT);
108
+ }
109
+ createAbortResult() {
110
+ return {
111
+ llmContent: 'Request was aborted before it could start',
112
+ returnDisplay: 'Request aborted',
113
+ error: {
114
+ message: 'Request was aborted before it could start',
115
+ type: ToolErrorType.FETCH_ERROR,
116
+ },
117
+ };
118
+ }
119
+ async fetchResponse(signal) {
120
+ return retryWithBackoff(async () => {
121
+ const resp = await fetch(this.params.url, {
122
+ signal,
123
+ headers: {
124
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
125
+ Accept: ACCEPT_HEADERS[this.params.format],
126
+ 'Accept-Language': 'en-US,en;q=0.9',
127
+ },
128
+ });
129
+ if (!resp.ok) {
130
+ const error = new Error(`Request failed with status code: ${resp.status}`);
131
+ error.status = resp.status;
132
+ throw error;
133
+ }
134
+ return resp;
135
+ }, {
136
+ maxAttempts: 3,
137
+ initialDelayMs: 500,
138
+ retryFetchErrors: true,
139
+ signal,
140
+ });
141
+ }
142
+ async readBoundedResponse(response) {
143
+ const contentLength = response.headers.get('content-length');
144
+ if (contentLength && parseInt(contentLength, 10) > MAX_RESPONSE_SIZE) {
145
+ throw new Error('Response too large (exceeds 5MB limit)');
146
+ }
147
+ const arrayBuffer = await response.arrayBuffer();
148
+ if (arrayBuffer.byteLength > MAX_RESPONSE_SIZE) {
149
+ throw new Error('Response too large (exceeds 5MB limit)');
150
+ }
151
+ return arrayBuffer;
152
+ }
153
+ convertContent(content, contentType) {
154
+ if (this.params.format === 'markdown' &&
155
+ contentType.includes('text/html')) {
156
+ return this.convertHTMLToMarkdown(content);
157
+ }
158
+ if (this.params.format === 'text' && contentType.includes('text/html')) {
159
+ return this.extractTextFromHTML(content);
160
+ }
161
+ return content;
162
+ }
163
+ createFetchErrorResult(error) {
164
+ const errorMessage = this.formatErrorMessage(error);
165
+ return {
166
+ llmContent: `Error fetching URL: ${errorMessage}`,
167
+ returnDisplay: `Error: ${errorMessage}`,
168
+ error: {
169
+ message: errorMessage,
170
+ type: ToolErrorType.FETCH_ERROR,
171
+ },
172
+ };
173
+ }
174
+ formatErrorMessage(error) {
175
+ if (!(error instanceof Error))
176
+ return String(error);
177
+ let errorMessage = error.message;
178
+ const err = error;
179
+ if (this.hasTruthyCause(err)) {
180
+ const causeMessage = err.cause instanceof Error ? err.cause.message : String(err.cause);
181
+ errorMessage += `: ${causeMessage}`;
182
+ }
183
+ return errorMessage;
184
+ }
185
+ hasTruthyCause(error) {
186
+ if (!('cause' in error))
187
+ return false;
188
+ return this.isTruthyCause(error.cause);
189
+ }
190
+ isTruthyCause(cause) {
191
+ if (cause === undefined || cause === null)
192
+ return false;
193
+ if (cause === false || cause === 0 || cause === '')
194
+ return false;
195
+ return !Number.isNaN(cause);
196
+ }
197
+ extractTextFromHTML(html) {
198
+ const $ = cheerio.load(html);
199
+ // Remove scripts, styles, etc.
200
+ $('script, style, noscript, iframe, object, embed').remove();
201
+ return $.text().trim();
202
+ }
203
+ convertHTMLToMarkdown(html) {
204
+ const turndownService = new TurndownService({
205
+ headingStyle: 'atx',
206
+ hr: '---',
207
+ bulletListMarker: '-',
208
+ codeBlockStyle: 'fenced',
209
+ emDelimiter: '*',
210
+ });
211
+ turndownService.remove(['script', 'style', 'meta', 'link']);
212
+ return turndownService.turndown(html);
213
+ }
214
+ }
215
+ //# sourceMappingURL=direct-web-fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-web-fetch.js","sourceRoot":"","sources":["../../../src/tools/direct-web-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,IAAI,GAGL,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvD,OAAO,KAA2B,MAAM,YAAY,CAAC;AACrD,OAAO,eAAe,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,MAAM;AACjD,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAChD,MAAM,WAAW,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,YAAY;AAC5C,MAAM,cAAc,GAAuD;IACzE,QAAQ,EACN,0FAA0F;IAC5F,IAAI,EAAE,mEAAmE;IACzE,IAAI,EAAE,gGAAgG;CACvG,CAAC;AAQF,MAAM,OAAO,kBAAm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AC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAEO,qBAAqB,CAAC,IAAY;QACxC,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC;YAC1C,YAAY,EAAE,KAAK;YACnB,EAAE,EAAE,KAAK;YACT,gBAAgB,EAAE,GAAG;YACrB,cAAc,EAAE,QAAQ;YACxB,WAAW,EAAE,GAAG;SACjB,CAAC,CAAC;QACH,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QAC5D,OAAO,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;CACF"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { IToolHost } from '../interfaces/index.js';
7
+ import { EmojiFilter } from '../utils/EmojiFilter.js';
8
+ import { ToolErrorType } from '../types/tool-error.js';
9
+ import type { EditToolParams } from './edit.js';
10
+ /**
11
+ * Counts occurrences of oldString that start within the line range
12
+ * [replaceLine, replaceLine+1) — i.e., occurrences whose start position
13
+ * falls on the specified 1-based line number.
14
+ * Returns 0 if replaceLine is out of range.
15
+ */
16
+ export declare function countLineGuardedOccurrences(currentContent: string, oldString: string, replaceLine: number): number;
17
+ /**
18
+ * Applies replacement of oldString with newString, but only for occurrences
19
+ * whose start position falls within the line range [replaceLine, replaceLine+1).
20
+ * Replaces up to expectedReplacements eligible occurrences.
21
+ * Returns the resulting content string.
22
+ *
23
+ * Deterministic approach: collect all eligible match offsets from the original
24
+ * content first, then build the output string from original content slices.
25
+ * This avoids the stale-bounds bug that arises when searching a mutated result
26
+ * string with offsets computed from the original content.
27
+ */
28
+ export declare function applyLineGuardedReplacement(currentContent: string, oldString: string, newString: string, expectedReplacements: number, replaceLine: number): string;
29
+ /**
30
+ * Gets emoji filter instance based on configuration
31
+ */
32
+ export declare function getEmojiFilter(host: IToolHost): EmojiFilter;
33
+ /**
34
+ * Applies a replacement to content.
35
+ */
36
+ export declare function applyReplacement(currentContent: string | null, oldString: string, newString: string, isNewFile: boolean, expectedReplacements?: number): string;
37
+ /**
38
+ * Error information for edit operations.
39
+ */
40
+ export interface EditErrorInfo {
41
+ display: string;
42
+ raw: string;
43
+ type: ToolErrorType;
44
+ }
45
+ /**
46
+ * Builds the error object when zero occurrences are found.
47
+ */
48
+ export declare function buildNoOccurrenceError(filteredParams: EditToolParams, currentContent: string | null, filePath: string): EditErrorInfo;
49
+ /**
50
+ * Validates the edit parameters after reading file content and builds the
51
+ * appropriate error object if any validation fails.
52
+ */
53
+ export declare function validateEditState(filteredParams: EditToolParams, currentContent: string | null, fileExists: boolean, filePath: string, occurrences: number, expectedReplacements: number, finalOldString: string, finalNewString: string): EditErrorInfo | undefined;