@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,249 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Edit calculation logic for ast-edit tool.
7
+ * Contains calculateEdit, validation, and helper functions.
8
+ */
9
+ /* eslint-disable complexity, sonarjs/cognitive-complexity -- Phase 5: legacy core boundary retained while larger decomposition continues. */
10
+ import { promises as fsPromises } from 'fs';
11
+ import * as path from 'path';
12
+ import { parse } from '@ast-grep/napi';
13
+ import { ToolErrorType } from '../../types/tool-error.js';
14
+ import { isNodeError } from '../../utils/errors.js';
15
+ import { LANGUAGE_MAP } from '../../utils/ast-grep-utils.js';
16
+ import { applyReplacement } from './edit-helpers.js';
17
+ /**
18
+ * Calculates the edit to be applied, including validation and freshness checks.
19
+ *
20
+ * @param params - Edit parameters
21
+ * @param host - Tool host interface
22
+ * @param _abortSignal - Abort signal (currently unused)
23
+ * @returns Calculated edit result with validation info
24
+ */
25
+ export async function calculateEdit(params, host, _abortSignal) {
26
+ // Normalize all string parameters to LF for consistent matching
27
+ const normalizedOldString = params.old_string.replace(/\r\n/g, '\n');
28
+ const normalizedNewString = params.new_string.replace(/\r\n/g, '\n');
29
+ const { currentContent, fileExists } = await readFileState(params, host);
30
+ // Freshness Check (moved before old_string validation to ensure it runs first)
31
+ const currentMtime = await getFileLastModified(params.file_path);
32
+ const freshnessError = checkFreshness(params, currentMtime, fileExists, currentContent);
33
+ if (freshnessError) {
34
+ return freshnessError;
35
+ }
36
+ const { occurrences, error, isNewFile } = validateEditParams(params, currentContent, fileExists, normalizedOldString, normalizedNewString);
37
+ const newContent = !error
38
+ ? applyReplacement(currentContent, normalizedOldString, normalizedNewString, isNewFile)
39
+ : (currentContent ?? '');
40
+ const noChangeError = checkNoChange(error, fileExists, currentContent, newContent, params.file_path);
41
+ let astValidation;
42
+ if (!noChangeError) {
43
+ astValidation = validateASTSyntax(params.file_path, newContent);
44
+ }
45
+ return {
46
+ currentContent,
47
+ newContent,
48
+ occurrences,
49
+ error: noChangeError,
50
+ isNewFile,
51
+ astValidation,
52
+ fileFreshness: currentMtime,
53
+ };
54
+ }
55
+ async function readFileState(params, host) {
56
+ let currentContent = null;
57
+ let fileExists = false;
58
+ try {
59
+ const fileSystemService = host.getFileSystemService?.();
60
+ currentContent = fileSystemService?.readTextFile
61
+ ? await fileSystemService.readTextFile(params.file_path)
62
+ : await fsPromises.readFile(params.file_path, 'utf-8');
63
+ currentContent = currentContent.replace(/\r\n/g, '\n');
64
+ fileExists = true;
65
+ }
66
+ catch (err) {
67
+ if (!isNodeError(err) || err.code !== 'ENOENT') {
68
+ throw err;
69
+ }
70
+ fileExists = false;
71
+ }
72
+ return { currentContent, fileExists };
73
+ }
74
+ function checkFreshness(params, currentMtime, fileExists, currentContent) {
75
+ if (
76
+ // eslint-disable-next-line sonarjs/expression-complexity -- Existing structure is intentionally preserved; refactoring this boundary is outside the lint slice.
77
+ params.last_modified != null &&
78
+ ((fileExists && currentMtime == null) ||
79
+ (currentMtime != null && currentMtime > params.last_modified))) {
80
+ return {
81
+ currentContent,
82
+ newContent: currentContent ?? '',
83
+ occurrences: 0,
84
+ error: {
85
+ display: `File has been modified since it was last read. Please read the file again to get the latest content.`,
86
+ raw: JSON.stringify({
87
+ message: `File ${params.file_path} mismatch. Expected mtime <= ${params.last_modified}, but found ${currentMtime}.`,
88
+ current_mtime: currentMtime,
89
+ your_mtime: params.last_modified,
90
+ }),
91
+ type: ToolErrorType.FILE_MODIFIED_CONFLICT,
92
+ },
93
+ isNewFile: false,
94
+ astValidation: undefined,
95
+ fileFreshness: currentMtime,
96
+ };
97
+ }
98
+ return undefined;
99
+ }
100
+ function validateEditParams(params, currentContent, fileExists, normalizedOldString, normalizedNewString) {
101
+ let occurrences = 0;
102
+ let error = undefined;
103
+ let isNewFile = false;
104
+ if (params.old_string === '' && !fileExists) {
105
+ isNewFile = true;
106
+ }
107
+ else if (!fileExists) {
108
+ error = {
109
+ display: `File not found. Cannot apply edit. Use an empty old_string to create a new file.`,
110
+ raw: `File not found: ${params.file_path}`,
111
+ type: ToolErrorType.FILE_NOT_FOUND,
112
+ };
113
+ }
114
+ else if (currentContent !== null) {
115
+ occurrences = countOccurrences(currentContent, normalizedOldString);
116
+ if (occurrences === 0) {
117
+ error = {
118
+ display: `Failed to edit, could not find string to replace.`,
119
+ raw: `Failed to edit, 0 occurrences found for old_string in ${params.file_path}. No edits made.`,
120
+ type: ToolErrorType.EDIT_NO_OCCURRENCE_FOUND,
121
+ };
122
+ }
123
+ else if (normalizedOldString === normalizedNewString) {
124
+ error = {
125
+ display: `No changes to apply. The old_string and new_string are identical.`,
126
+ raw: `No changes to apply. The old_string and new_string are identical in file: ${params.file_path}`,
127
+ type: ToolErrorType.EDIT_NO_CHANGE,
128
+ };
129
+ }
130
+ }
131
+ return { occurrences, error, isNewFile };
132
+ }
133
+ function checkNoChange(error, fileExists, currentContent, newContent, filePath) {
134
+ if (!error && fileExists && currentContent === newContent) {
135
+ return {
136
+ display: 'No changes to apply. The new content is identical to the current content.',
137
+ raw: `No changes to apply. The new content is identical to the current content in file: ${filePath}`,
138
+ type: ToolErrorType.EDIT_NO_CHANGE,
139
+ };
140
+ }
141
+ return error;
142
+ }
143
+ /**
144
+ * Counts occurrences that will be replaced (0 or 1).
145
+ * Returns 0/1 not true count, aligned with String.replace() single-replacement semantics.
146
+ *
147
+ * @param content - File content
148
+ * @param searchString - String to search for
149
+ * @returns 0 if not found, 1 if found
150
+ */
151
+ export function countOccurrences(content, searchString) {
152
+ if (!searchString)
153
+ return 0;
154
+ // Since applyReplacement uses String.replace (single replacement),
155
+ // count occurrences that will actually be replaced (0 or 1)
156
+ return content.includes(searchString) ? 1 : 0;
157
+ }
158
+ /**
159
+ * Validates AST syntax for the given file path and content.
160
+ * Inspects the tree-sitter parse tree for ERROR nodes and zero-width
161
+ * phantom nodes (MISSING tokens inserted by error recovery) rather than
162
+ * relying on thrown exceptions (tree-sitter is error-recovering and
163
+ * never throws on syntax errors).
164
+ *
165
+ * @param filePath - File path (used to detect language)
166
+ * @param content - File content to validate
167
+ * @returns Validation result
168
+ */
169
+ export function validateASTSyntax(filePath, content) {
170
+ const extension = path.extname(filePath).substring(1).toLowerCase();
171
+ const lang = LANGUAGE_MAP[extension];
172
+ if (!lang) {
173
+ return { valid: true, errors: [] };
174
+ }
175
+ try {
176
+ const tree = parse(lang, content);
177
+ const root = tree.root();
178
+ // Check for explicit ERROR nodes (garbled/unparseable tokens)
179
+ const errorNode = root.find({ rule: { kind: 'ERROR' } });
180
+ if (errorNode) {
181
+ const pos = errorNode.range().start;
182
+ return {
183
+ valid: false,
184
+ errors: [
185
+ `Syntax error at line ${pos.line + 1}, column ${pos.column + 1}`,
186
+ ],
187
+ };
188
+ }
189
+ // Check for zero-width phantom nodes (MISSING tokens from error recovery).
190
+ // Tree-sitter inserts these when expected delimiters are absent (e.g., missing }).
191
+ // ast-grep doesn't expose isMissing() or kind:'MISSING', but zero-width leaf
192
+ // nodes in non-empty content reliably indicate recovered syntax errors.
193
+ if (content.length > 0) {
194
+ const missingNode = findZeroWidthNode(root);
195
+ if (missingNode) {
196
+ return {
197
+ valid: false,
198
+ errors: [
199
+ `Syntax error at line ${missingNode.line + 1}, column ${missingNode.column + 1}`,
200
+ ],
201
+ };
202
+ }
203
+ }
204
+ return { valid: true, errors: [] };
205
+ }
206
+ catch (error) {
207
+ return {
208
+ valid: false,
209
+ errors: [error instanceof Error ? error.message : String(error)],
210
+ };
211
+ }
212
+ }
213
+ /**
214
+ * Walks the parse tree to find zero-width leaf nodes, which indicate
215
+ * MISSING tokens inserted by tree-sitter's error recovery (e.g., a phantom
216
+ * closing brace). Skips the root node to avoid false positives on empty content.
217
+ */
218
+ function findZeroWidthNode(node) {
219
+ for (const child of node.children()) {
220
+ const range = child.range();
221
+ if (range.start.index === range.end.index && child.isLeaf()) {
222
+ return { line: range.start.line, column: range.start.column };
223
+ }
224
+ const found = findZeroWidthNode(child);
225
+ if (found)
226
+ return found;
227
+ }
228
+ return null;
229
+ }
230
+ /**
231
+ * Gets the last modified timestamp of a file.
232
+ * Returns null if file doesn't exist.
233
+ *
234
+ * @param filePath - Path to the file
235
+ * @returns Timestamp in milliseconds or null
236
+ */
237
+ export async function getFileLastModified(filePath) {
238
+ try {
239
+ const stats = await fsPromises.stat(filePath);
240
+ return stats.mtime.getTime();
241
+ }
242
+ catch (error) {
243
+ if (isNodeError(error) && error.code === 'ENOENT') {
244
+ return null;
245
+ }
246
+ throw error;
247
+ }
248
+ }
249
+ //# sourceMappingURL=edit-calculator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit-calculator.js","sourceRoot":"","sources":["../../../../src/tools/ast-edit/edit-calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6IAA6I;AAE7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QACxB,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Edit helper functions for ast-edit tool.
7
+ */
8
+ /**
9
+ * Applies a replacement to file content.
10
+ * This is the core replacement logic used by ASTEditTool.
11
+ *
12
+ * NOTE: This differs from edit.ts applyReplacement - they are intentionally separate.
13
+ * edit.ts supports multiple occurrences and fuzzy matching; ast-edit.ts uses simple single-replace.
14
+ * These are different domain behaviors and must NOT be unified.
15
+ *
16
+ * @param currentContent - The current file content (null if file doesn't exist)
17
+ * @param oldString - The string to replace
18
+ * @param newString - The replacement string
19
+ * @param isNewFile - Whether this is a new file creation
20
+ * @returns The modified content
21
+ */
22
+ export declare function applyReplacement(currentContent: string | null, oldString: string, newString: string, isNewFile: boolean): string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Edit helper functions for ast-edit tool.
7
+ */
8
+ /**
9
+ * Applies a replacement to file content.
10
+ * This is the core replacement logic used by ASTEditTool.
11
+ *
12
+ * NOTE: This differs from edit.ts applyReplacement - they are intentionally separate.
13
+ * edit.ts supports multiple occurrences and fuzzy matching; ast-edit.ts uses simple single-replace.
14
+ * These are different domain behaviors and must NOT be unified.
15
+ *
16
+ * @param currentContent - The current file content (null if file doesn't exist)
17
+ * @param oldString - The string to replace
18
+ * @param newString - The replacement string
19
+ * @param isNewFile - Whether this is a new file creation
20
+ * @returns The modified content
21
+ */
22
+ export function applyReplacement(currentContent, oldString, newString, isNewFile) {
23
+ if (isNewFile) {
24
+ return newString;
25
+ }
26
+ if (currentContent === null) {
27
+ return oldString === '' ? newString : '';
28
+ }
29
+ if (oldString === '') {
30
+ return currentContent;
31
+ }
32
+ // For single replacement, use callback form to treat newString literally
33
+ // (avoids $&, $$, $1 etc. being interpreted as special replacement patterns)
34
+ return currentContent.replace(oldString, () => newString);
35
+ }
36
+ //# sourceMappingURL=edit-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit-helpers.js","sourceRoot":"","sources":["../../../../src/tools/ast-edit/edit-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAC9B,cAA6B,EAC7B,SAAiB,EACjB,SAAiB,EACjB,SAAkB;IAElB,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3C,CAAC;IACD,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;QACrB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,yEAAyE;IACzE,6EAA6E;IAC7E,OAAO,cAAc,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Import } from './types.js';
7
+ /**
8
+ * Detects the programming language from a file path based on its extension.
9
+ * @param filePath - The file path to analyze
10
+ * @returns The detected language (e.g., 'typescript', 'python') or 'unknown'
11
+ */
12
+ export declare function detectLanguage(filePath: string): string;
13
+ /**
14
+ * Extracts import statements from source code.
15
+ * @param content - The source code content
16
+ * @param language - The programming language (typescript, javascript, python, etc.)
17
+ * @returns Array of import declarations with module paths and imported items
18
+ */
19
+ export declare function extractImports(content: string, language: string): Import[];
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import * as path from 'path';
7
+ import { ASTConfig } from './ast-config.js';
8
+ import { KEYWORDS, REGEX } from './constants.js';
9
+ /**
10
+ * Detects the programming language from a file path based on its extension.
11
+ * @param filePath - The file path to analyze
12
+ * @returns The detected language (e.g., 'typescript', 'python') or 'unknown'
13
+ */
14
+ export function detectLanguage(filePath) {
15
+ const extension = path.extname(filePath).substring(1);
16
+ return (ASTConfig.SUPPORTED_LANGUAGES[extension] || 'unknown');
17
+ }
18
+ /**
19
+ * Extracts import statements from source code.
20
+ * @param content - The source code content
21
+ * @param language - The programming language (typescript, javascript, python, etc.)
22
+ * @returns Array of import declarations with module paths and imported items
23
+ */
24
+ export function extractImports(content, language) {
25
+ const imports = [];
26
+ const lines = content.split('\n');
27
+ lines.forEach((line, index) => {
28
+ const trimmed = line.trim();
29
+ if ((language === 'typescript' || language === 'javascript') &&
30
+ trimmed.startsWith(KEYWORDS.IMPORT)) {
31
+ imports.push({
32
+ module: extractImportModule(trimmed),
33
+ items: extractImportItems(trimmed),
34
+ line: index + 1,
35
+ });
36
+ }
37
+ else if (language === 'python' &&
38
+ (trimmed.startsWith(KEYWORDS.IMPORT) || trimmed.startsWith(KEYWORDS.FROM))) {
39
+ imports.push({
40
+ module: extractPythonImportModule(trimmed),
41
+ items: extractPythonImportItems(trimmed),
42
+ line: index + 1,
43
+ });
44
+ }
45
+ });
46
+ return imports;
47
+ }
48
+ /**
49
+ * Extracts the module path from an import statement.
50
+ * @param line - The import statement line
51
+ * @returns The module path or 'unknown' if not found
52
+ */
53
+ function extractImportModule(line) {
54
+ const match = line.match(REGEX.IMPORT_MODULE);
55
+ return match ? match[1] : 'unknown';
56
+ }
57
+ /**
58
+ * Extracts the list of imported items from an import statement.
59
+ * @param line - The import statement line
60
+ * @returns Array of imported item names
61
+ */
62
+ function extractImportItems(line) {
63
+ // Extract the contents of the first { ... } block using index scanning to
64
+ // avoid polynomial backtracking on braces-heavy input.
65
+ const open = line.indexOf('{');
66
+ if (open !== -1) {
67
+ const close = line.indexOf('}', open + 1);
68
+ if (close > open + 1) {
69
+ return line
70
+ .slice(open + 1, close)
71
+ .split(',')
72
+ .map((item) => item.trim());
73
+ }
74
+ }
75
+ return [];
76
+ }
77
+ /**
78
+ * Extracts the module path from a Python import statement.
79
+ * Handles: `import os`, `from pathlib import Path`, `from os.path import join`
80
+ */
81
+ function extractPythonImportModule(line) {
82
+ // eslint-disable-next-line sonarjs/regular-expr -- Static regex reviewed for lint hardening; behavior preserved.
83
+ const fromMatch = line.match(/^from\s+([\w.]+)\s+import/);
84
+ if (fromMatch) {
85
+ return fromMatch[1];
86
+ }
87
+ // eslint-disable-next-line sonarjs/regular-expr -- Static regex reviewed for lint hardening; behavior preserved.
88
+ const importMatch = line.match(/^import\s+([\w.]+)/);
89
+ if (importMatch) {
90
+ return importMatch[1];
91
+ }
92
+ return 'unknown';
93
+ }
94
+ /**
95
+ * Strips a trailing ` as <alias>` from a single import item using linear token
96
+ * scanning (avoids regex backtracking on whitespace-heavy input).
97
+ * Example: `join as j` -> `join`.
98
+ */
99
+ function stripImportAlias(item) {
100
+ const tokens = item.split(/\s+/);
101
+ if (tokens.length >= 3 &&
102
+ tokens[tokens.length - 2] === 'as' &&
103
+ /^\w+$/.test(tokens[tokens.length - 1])) {
104
+ return tokens.slice(0, tokens.length - 2).join(' ');
105
+ }
106
+ return item;
107
+ }
108
+ /**
109
+ * Extracts imported items from a Python import statement.
110
+ * Handles: `from typing import List, Dict`, `from os.path import join, exists`
111
+ */
112
+ function extractPythonImportItems(line) {
113
+ // eslint-disable-next-line sonarjs/regular-expr -- Static regex reviewed for lint hardening; behavior preserved.
114
+ const fromImportMatch = line.match(/^from\s+[\w.]+\s+import\s+(.+)/);
115
+ if (fromImportMatch) {
116
+ return fromImportMatch[1]
117
+ .split(',')
118
+ .map((item) => stripImportAlias(item.trim()))
119
+ .filter((item) => item);
120
+ }
121
+ return [];
122
+ }
123
+ //# sourceMappingURL=language-analysis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-analysis.js","sourceRoot":"","sources":["../../../../src/tools/ast-edit/language-analysis.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGjD;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACtD,OAAO,CACL,SAAS,CAAC,mBAAmB,CAC3B,SAAuD,CACxD,IAAI,SAAS,CACf,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,QAAgB;IAC9D,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAElC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IACE,CAAC,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,YAAY,CAAC;YACxD,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,EACnC,CAAC;YACD,OAAO,CAAC,IAAI,CAAC;gBACX,MAAM,EAAE,mBAAmB,CAAC,OAAO,CAAC;gBACpC,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC;gBAClC,IAAI,EAAE,KAAK,GAAG,CAAC;aAChB,CAAC,CAAC;QACL,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CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Local context analysis functions for AST parsing and code snippet collection.
7
+ */
8
+ import type { ASTNode, CodeSnippet, Declaration, FunctionInfo, ClassInfo, VariableInfo, ASTContext } from './types.js';
9
+ /**
10
+ * Parse AST from content using basic line-by-line analysis.
11
+ * @param content - Source code content
12
+ * @param language - Programming language
13
+ * @returns Array of AST nodes
14
+ */
15
+ export declare function parseAST(content: string, language: string): Promise<ASTNode[]>;
16
+ /**
17
+ * Extract AST nodes from content by analyzing significant lines.
18
+ * @param content - Source code content
19
+ * @param language - Programming language
20
+ * @returns Array of AST nodes
21
+ */
22
+ export declare function extractASTNodes(content: string, language: string): ASTNode[];
23
+ /**
24
+ * Collect code snippets from content, filtering out comments and short lines.
25
+ * @param content - Source code content
26
+ * @returns Array of code snippets sorted by relevance
27
+ */
28
+ export declare function collectSnippets(content: string): CodeSnippet[];
29
+ /**
30
+ * Build language-specific context by extracting functions, classes, and variables.
31
+ * @param content - Source code content
32
+ * @param language - Programming language
33
+ * @returns Language context with extracted elements
34
+ */
35
+ export declare function buildLanguageContext(content: string, language: string): ASTContext['languageContext'];
36
+ /**
37
+ * Check if a line is significant (non-comment, non-empty).
38
+ * @param line - Source code line
39
+ * @param _language - Programming language (unused but kept for signature compatibility)
40
+ * @returns True if the line is significant
41
+ */
42
+ export declare function isSignificantLine(line: string, _language: string): boolean;
43
+ /**
44
+ * Infer the AST node type from a line of code.
45
+ * @param line - Source code line
46
+ * @param _language - Programming language (unused but kept for signature compatibility)
47
+ * @returns Node type (function, class, control, return, statement)
48
+ */
49
+ export declare function inferNodeType(line: string, _language: string): string;
50
+ /**
51
+ * Calculate the relevance score of a code line.
52
+ * @param line - Source code line
53
+ * @returns Relevance score
54
+ */
55
+ export declare function calculateRelevance(line: string): number;
56
+ /**
57
+ * Extract function declarations from content using regex.
58
+ * @param content - Source code content
59
+ * @param _language - Programming language
60
+ * @returns Array of function information
61
+ */
62
+ export declare function extractFunctions(content: string, _language: string): FunctionInfo[];
63
+ /**
64
+ * Extract class declarations from content using regex.
65
+ * @param content - Source code content
66
+ * @param _language - Programming language
67
+ * @returns Array of class information
68
+ */
69
+ export declare function extractClasses(content: string, _language: string): ClassInfo[];
70
+ /**
71
+ * Extract variable declarations from content using regex.
72
+ * @param content - Source code content
73
+ * @param _language - Programming language
74
+ * @returns Array of variable information
75
+ */
76
+ export declare function extractVariables(content: string, _language: string): VariableInfo[];
77
+ /**
78
+ * Optimize context collection by gathering declaration and local snippets.
79
+ * @param declarations - Array of declarations
80
+ * @param content - Source code content
81
+ * @param _workspaceRoot - Workspace root path (unused but kept for signature compatibility)
82
+ * @returns Optimized array of code snippets
83
+ */
84
+ export declare function optimizeContextCollection(declarations: Declaration[], content: string, _workspaceRoot: string): CodeSnippet[];