@tyvm/knowhow 0.0.47 → 0.0.48

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 (459) hide show
  1. package/benchmarks/results/27b0a06/2025-09-27/xai/xai-grok-code-fast-1.json +2909 -0
  2. package/benchmarks/results/4057aed/2025-08-14/anthropic/anthropic-claude-sonnet-4-20250514.json +1671 -0
  3. package/jest.config.js +2 -2
  4. package/package.json +8 -3
  5. package/src/agents/base/base.ts +30 -24
  6. package/src/agents/patcher/patcher.ts +26 -5
  7. package/src/agents/tools/agentCall.ts +4 -2
  8. package/src/agents/tools/aiClient.ts +3 -11
  9. package/src/agents/tools/ast/astAppendNode.ts +90 -0
  10. package/src/agents/tools/ast/astDeleteNode.ts +88 -0
  11. package/src/agents/tools/ast/astEditNode.ts +95 -0
  12. package/src/agents/tools/ast/astGetPathForLine.ts +73 -0
  13. package/src/agents/tools/ast/astListPaths.ts +66 -0
  14. package/src/agents/tools/ast/index.ts +7 -0
  15. package/src/agents/tools/callPlugin.ts +8 -2
  16. package/src/agents/tools/embeddingSearch.ts +2 -1
  17. package/src/agents/tools/execCommand.ts +239 -94
  18. package/src/agents/tools/fileSearch.ts +15 -17
  19. package/src/agents/tools/index.ts +1 -0
  20. package/src/agents/tools/language/definitions.ts +10 -2
  21. package/src/agents/tools/language/index.ts +3 -2
  22. package/src/agents/tools/lintFile.ts +4 -2
  23. package/src/agents/tools/list.ts +203 -62
  24. package/src/agents/tools/patch.ts +48 -14
  25. package/src/agents/tools/readBlocks.ts +34 -0
  26. package/src/agents/tools/readFile.ts +23 -0
  27. package/src/agents/tools/stringReplace.ts +33 -9
  28. package/src/agents/tools/writeFile.ts +55 -0
  29. package/src/agents/tools/ycmd/server.ts +14 -4
  30. package/src/chat/CliChatService.ts +6 -1
  31. package/src/chat/modules/AgentModule.ts +107 -64
  32. package/src/chat/modules/AskModule.ts +0 -1
  33. package/src/chat/modules/SetupModule.ts +4 -4
  34. package/src/chat/modules/SystemModule.ts +28 -5
  35. package/src/chat/types.ts +2 -0
  36. package/src/chat-old.ts +2 -2
  37. package/src/clients/anthropic.ts +22 -1
  38. package/src/clients/openai.ts +1 -1
  39. package/src/clients/xai.ts +15 -5
  40. package/src/config.ts +17 -5
  41. package/src/dataset/diffs/generate.ts +2 -2
  42. package/src/dataset/diffs/jsonl.ts +0 -1
  43. package/src/embeddings.ts +6 -4
  44. package/src/index.ts +11 -5
  45. package/src/plugins/GitPlugin.ts +530 -0
  46. package/src/plugins/LinterPlugin.ts +89 -0
  47. package/src/plugins/PluginBase.ts +4 -2
  48. package/src/plugins/asana.ts +4 -2
  49. package/src/plugins/downloader/plugin.ts +5 -2
  50. package/src/plugins/embedding.ts +24 -4
  51. package/src/plugins/figma.ts +7 -3
  52. package/src/plugins/github.ts +4 -2
  53. package/src/plugins/jira.ts +4 -2
  54. package/src/plugins/language.ts +134 -27
  55. package/src/plugins/linear.ts +4 -2
  56. package/src/plugins/notion.ts +4 -2
  57. package/src/plugins/plugins.ts +27 -16
  58. package/src/plugins/tree-sitter/editor.ts +369 -0
  59. package/src/plugins/tree-sitter/lang-packs/index.ts +23 -0
  60. package/src/plugins/tree-sitter/lang-packs/java.ts +59 -0
  61. package/src/plugins/tree-sitter/lang-packs/javascript.ts +57 -0
  62. package/src/plugins/tree-sitter/lang-packs/python.ts +45 -0
  63. package/src/plugins/tree-sitter/lang-packs/types.ts +79 -0
  64. package/src/plugins/tree-sitter/lang-packs/typescript.ts +49 -0
  65. package/src/plugins/tree-sitter/parser.ts +444 -0
  66. package/src/plugins/tree-sitter/simple-paths.ts +467 -0
  67. package/src/plugins/types.ts +11 -0
  68. package/src/plugins/url.ts +5 -3
  69. package/src/plugins/vim.ts +8 -5
  70. package/src/processors/CustomVariables.ts +19 -7
  71. package/src/processors/TokenCompressor.ts +13 -13
  72. package/src/processors/ToolResponseCache.ts +15 -6
  73. package/src/services/EmbeddingService.ts +18 -9
  74. package/src/services/EventService.ts +80 -0
  75. package/src/services/Mcp.ts +5 -0
  76. package/src/services/S3.ts +4 -3
  77. package/src/services/Tools.ts +125 -53
  78. package/src/services/index.ts +16 -11
  79. package/src/services/types.ts +3 -3
  80. package/src/types.ts +7 -2
  81. package/src/worker.ts +14 -1
  82. package/test-comprehensive.ts +31 -0
  83. package/tests/clients/AIClient.test.ts +490 -0
  84. package/tests/manual/agent-events/run-test.ts +203 -0
  85. package/tests/{integration → manual/file-edits}/figma.test.ts +1 -1
  86. package/tests/{integration → manual/file-edits}/fileblocks/readwrite.test.ts +7 -3
  87. package/tests/{integration → manual/file-edits}/patching.test.ts +11 -8
  88. package/tests/plugins/language/languagePlugin-content-triggers.test.ts +332 -0
  89. package/tests/plugins/language/languagePlugin-integration.test.ts +456 -0
  90. package/tests/plugins/language/languagePlugin.test.ts +363 -0
  91. package/tests/processors/Base64ImageDetector.test.ts +403 -0
  92. package/tests/processors/CustomVariables.test.ts +430 -0
  93. package/tests/processors/HarmonyToolProcessor.test.ts +490 -0
  94. package/tests/processors/TokenCompressor.test.ts +391 -0
  95. package/tests/processors/ToolResponseCache.test.ts +688 -0
  96. package/tests/services/Tools.test.ts +1339 -0
  97. package/tests/test.spec.ts +162 -117
  98. package/tests/tree-sitter/editor.test.ts +113 -0
  99. package/tests/tree-sitter/invalid.test.ts +299 -0
  100. package/tests/tree-sitter/paths/common-edits.test.ts +564 -0
  101. package/tests/tree-sitter/paths/debug-exact-position.test.ts +44 -0
  102. package/tests/tree-sitter/paths/debug-line-indexing.test.ts +49 -0
  103. package/tests/tree-sitter/paths/debug-paths.test.ts +90 -0
  104. package/tests/tree-sitter/paths/paths.test.ts +170 -0
  105. package/tests/tree-sitter/paths/simple-paths.test.ts +367 -0
  106. package/tests/tree-sitter/sample-after.ts +48 -0
  107. package/tests/tree-sitter/sample-before.ts +25 -0
  108. package/tests/tree-sitter/test-files/completely-broken.ts +7 -0
  109. package/tests/tree-sitter/test-files/duplicate-braces.ts +39 -0
  110. package/tests/tree-sitter/test-files/invalid-nesting.ts +39 -0
  111. package/tests/tree-sitter/test-files/malformed-signature.ts +39 -0
  112. package/tests/tree-sitter/test-files/mismatched-parens.ts +39 -0
  113. package/tests/tree-sitter/test-files/missing-semicolon.ts +39 -0
  114. package/tests/tree-sitter/test-files/partially-broken.ts +20 -0
  115. package/tests/tree-sitter/test-files/specific-errors.ts +14 -0
  116. package/tests/tree-sitter/test-files/unclosed-string.ts +39 -0
  117. package/tests/tree-sitter/tree-sitter.test.ts +251 -0
  118. package/ts_build/package.json +8 -3
  119. package/ts_build/src/agents/base/base.d.ts +2 -2
  120. package/ts_build/src/agents/base/base.js +24 -20
  121. package/ts_build/src/agents/base/base.js.map +1 -1
  122. package/ts_build/src/agents/patcher/patcher.js +26 -5
  123. package/ts_build/src/agents/patcher/patcher.js.map +1 -1
  124. package/ts_build/src/agents/tools/agentCall.js +2 -1
  125. package/ts_build/src/agents/tools/agentCall.js.map +1 -1
  126. package/ts_build/src/agents/tools/aiClient.d.ts +7 -8
  127. package/ts_build/src/agents/tools/aiClient.js.map +1 -1
  128. package/ts_build/src/agents/tools/ast/astAppendNode.d.ts +1 -0
  129. package/ts_build/src/agents/tools/ast/astAppendNode.js +96 -0
  130. package/ts_build/src/agents/tools/ast/astAppendNode.js.map +1 -0
  131. package/ts_build/src/agents/tools/ast/astDeleteNode.d.ts +1 -0
  132. package/ts_build/src/agents/tools/ast/astDeleteNode.js +94 -0
  133. package/ts_build/src/agents/tools/ast/astDeleteNode.js.map +1 -0
  134. package/ts_build/src/agents/tools/ast/astEditNode.d.ts +1 -0
  135. package/ts_build/src/agents/tools/ast/astEditNode.js +96 -0
  136. package/ts_build/src/agents/tools/ast/astEditNode.js.map +1 -0
  137. package/ts_build/src/agents/tools/ast/astGetPathForLine.d.ts +1 -0
  138. package/ts_build/src/agents/tools/ast/astGetPathForLine.js +78 -0
  139. package/ts_build/src/agents/tools/ast/astGetPathForLine.js.map +1 -0
  140. package/ts_build/src/agents/tools/ast/astListPaths.d.ts +1 -0
  141. package/ts_build/src/agents/tools/ast/astListPaths.js +78 -0
  142. package/ts_build/src/agents/tools/ast/astListPaths.js.map +1 -0
  143. package/ts_build/src/agents/tools/ast/index.d.ts +5 -0
  144. package/ts_build/src/agents/tools/ast/index.js +14 -0
  145. package/ts_build/src/agents/tools/ast/index.js.map +1 -0
  146. package/ts_build/src/agents/tools/astAppendNode.d.ts +1 -0
  147. package/ts_build/src/agents/tools/astAppendNode.js +98 -0
  148. package/ts_build/src/agents/tools/astAppendNode.js.map +1 -0
  149. package/ts_build/src/agents/tools/astDeleteNode.d.ts +1 -0
  150. package/ts_build/src/agents/tools/astDeleteNode.js +95 -0
  151. package/ts_build/src/agents/tools/astDeleteNode.js.map +1 -0
  152. package/ts_build/src/agents/tools/astEditNode.d.ts +1 -0
  153. package/ts_build/src/agents/tools/astEditNode.js +98 -0
  154. package/ts_build/src/agents/tools/astEditNode.js.map +1 -0
  155. package/ts_build/src/agents/tools/astGetPathForLine.d.ts +1 -0
  156. package/ts_build/src/agents/tools/astGetPathForLine.js +89 -0
  157. package/ts_build/src/agents/tools/astGetPathForLine.js.map +1 -0
  158. package/ts_build/src/agents/tools/astListPaths.d.ts +1 -0
  159. package/ts_build/src/agents/tools/astListPaths.js +82 -0
  160. package/ts_build/src/agents/tools/astListPaths.js.map +1 -0
  161. package/ts_build/src/agents/tools/callPlugin.js +4 -2
  162. package/ts_build/src/agents/tools/callPlugin.js.map +1 -1
  163. package/ts_build/src/agents/tools/embeddingSearch.js +3 -2
  164. package/ts_build/src/agents/tools/embeddingSearch.js.map +1 -1
  165. package/ts_build/src/agents/tools/execCommand.d.ts +2 -2
  166. package/ts_build/src/agents/tools/execCommand.js +201 -67
  167. package/ts_build/src/agents/tools/execCommand.js.map +1 -1
  168. package/ts_build/src/agents/tools/fileSearch.d.ts +1 -1
  169. package/ts_build/src/agents/tools/fileSearch.js +11 -15
  170. package/ts_build/src/agents/tools/fileSearch.js.map +1 -1
  171. package/ts_build/src/agents/tools/github/index.d.ts +1 -1
  172. package/ts_build/src/agents/tools/index.d.ts +1 -0
  173. package/ts_build/src/agents/tools/index.js +1 -0
  174. package/ts_build/src/agents/tools/index.js.map +1 -1
  175. package/ts_build/src/agents/tools/language/definitions.js +11 -2
  176. package/ts_build/src/agents/tools/language/definitions.js.map +1 -1
  177. package/ts_build/src/agents/tools/language/index.js +4 -3
  178. package/ts_build/src/agents/tools/language/index.js.map +1 -1
  179. package/ts_build/src/agents/tools/lintFile.js +4 -2
  180. package/ts_build/src/agents/tools/lintFile.js.map +1 -1
  181. package/ts_build/src/agents/tools/list.js +185 -49
  182. package/ts_build/src/agents/tools/list.js.map +1 -1
  183. package/ts_build/src/agents/tools/patch.js +33 -10
  184. package/ts_build/src/agents/tools/patch.js.map +1 -1
  185. package/ts_build/src/agents/tools/readBlocks.js +23 -0
  186. package/ts_build/src/agents/tools/readBlocks.js.map +1 -1
  187. package/ts_build/src/agents/tools/readFile.js +14 -0
  188. package/ts_build/src/agents/tools/readFile.js.map +1 -1
  189. package/ts_build/src/agents/tools/stringReplace.js +19 -2
  190. package/ts_build/src/agents/tools/stringReplace.js.map +1 -1
  191. package/ts_build/src/agents/tools/writeFile.js +40 -0
  192. package/ts_build/src/agents/tools/writeFile.js.map +1 -1
  193. package/ts_build/src/agents/tools/ycmd/server.js +5 -0
  194. package/ts_build/src/agents/tools/ycmd/server.js.map +1 -1
  195. package/ts_build/src/chat/CliChatService.d.ts +1 -0
  196. package/ts_build/src/chat/CliChatService.js +6 -2
  197. package/ts_build/src/chat/CliChatService.js.map +1 -1
  198. package/ts_build/src/chat/modules/AgentModule.d.ts +5 -1
  199. package/ts_build/src/chat/modules/AgentModule.js +53 -31
  200. package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
  201. package/ts_build/src/chat/modules/AskModule.js.map +1 -1
  202. package/ts_build/src/chat/modules/SetupModule.js +4 -3
  203. package/ts_build/src/chat/modules/SetupModule.js.map +1 -1
  204. package/ts_build/src/chat/modules/SystemModule.js +19 -4
  205. package/ts_build/src/chat/modules/SystemModule.js.map +1 -1
  206. package/ts_build/src/chat/modules/index.d.ts +5 -0
  207. package/ts_build/src/chat/modules/index.js +14 -0
  208. package/ts_build/src/chat/modules/index.js.map +1 -0
  209. package/ts_build/src/chat/types.d.ts +2 -0
  210. package/ts_build/src/chat-old.js +3 -3
  211. package/ts_build/src/chat-old.js.map +1 -1
  212. package/ts_build/src/clients/anthropic.d.ts +1 -0
  213. package/ts_build/src/clients/anthropic.js +22 -1
  214. package/ts_build/src/clients/anthropic.js.map +1 -1
  215. package/ts_build/src/clients/openai.js +1 -1
  216. package/ts_build/src/clients/openai.js.map +1 -1
  217. package/ts_build/src/clients/xai.d.ts +7 -0
  218. package/ts_build/src/clients/xai.js +13 -4
  219. package/ts_build/src/clients/xai.js.map +1 -1
  220. package/ts_build/src/config.js +14 -3
  221. package/ts_build/src/config.js.map +1 -1
  222. package/ts_build/src/dataset/diffs/generate.js +2 -2
  223. package/ts_build/src/dataset/diffs/generate.js.map +1 -1
  224. package/ts_build/src/dataset/diffs/jsonl.js.map +1 -1
  225. package/ts_build/src/embeddings.js +7 -9
  226. package/ts_build/src/embeddings.js.map +1 -1
  227. package/ts_build/src/index.js +10 -10
  228. package/ts_build/src/index.js.map +1 -1
  229. package/ts_build/src/plugins/GitPlugin.d.ts +39 -0
  230. package/ts_build/src/plugins/GitPlugin.js +439 -0
  231. package/ts_build/src/plugins/GitPlugin.js.map +1 -0
  232. package/ts_build/src/plugins/LinterPlugin.d.ts +15 -0
  233. package/ts_build/src/plugins/LinterPlugin.js +65 -0
  234. package/ts_build/src/plugins/LinterPlugin.js.map +1 -0
  235. package/ts_build/src/plugins/PluginBase.d.ts +4 -3
  236. package/ts_build/src/plugins/PluginBase.js +3 -3
  237. package/ts_build/src/plugins/PluginBase.js.map +1 -1
  238. package/ts_build/src/plugins/asana.d.ts +3 -1
  239. package/ts_build/src/plugins/asana.js +3 -2
  240. package/ts_build/src/plugins/asana.js.map +1 -1
  241. package/ts_build/src/plugins/downloader/plugin.d.ts +3 -1
  242. package/ts_build/src/plugins/downloader/plugin.js +3 -2
  243. package/ts_build/src/plugins/downloader/plugin.js.map +1 -1
  244. package/ts_build/src/plugins/embedding.d.ts +5 -1
  245. package/ts_build/src/plugins/embedding.js +15 -3
  246. package/ts_build/src/plugins/embedding.js.map +1 -1
  247. package/ts_build/src/plugins/figma.d.ts +3 -1
  248. package/ts_build/src/plugins/figma.js +28 -4
  249. package/ts_build/src/plugins/figma.js.map +1 -1
  250. package/ts_build/src/plugins/github.d.ts +3 -1
  251. package/ts_build/src/plugins/github.js +3 -2
  252. package/ts_build/src/plugins/github.js.map +1 -1
  253. package/ts_build/src/plugins/jira.d.ts +3 -1
  254. package/ts_build/src/plugins/jira.js +3 -2
  255. package/ts_build/src/plugins/jira.js.map +1 -1
  256. package/ts_build/src/plugins/language.d.ts +7 -4
  257. package/ts_build/src/plugins/language.js +85 -20
  258. package/ts_build/src/plugins/language.js.map +1 -1
  259. package/ts_build/src/plugins/linear.d.ts +3 -1
  260. package/ts_build/src/plugins/linear.js +3 -2
  261. package/ts_build/src/plugins/linear.js.map +1 -1
  262. package/ts_build/src/plugins/notion.d.ts +3 -1
  263. package/ts_build/src/plugins/notion.js +3 -2
  264. package/ts_build/src/plugins/notion.js.map +1 -1
  265. package/ts_build/src/plugins/plugins.d.ts +4 -3
  266. package/ts_build/src/plugins/plugins.js +24 -14
  267. package/ts_build/src/plugins/plugins.js.map +1 -1
  268. package/ts_build/src/plugins/tree-sitter/editor.d.ts +34 -0
  269. package/ts_build/src/plugins/tree-sitter/editor.js +218 -0
  270. package/ts_build/src/plugins/tree-sitter/editor.js.map +1 -0
  271. package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.d.ts +29 -0
  272. package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js +538 -0
  273. package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js.map +1 -0
  274. package/ts_build/src/plugins/tree-sitter/human-readable-paths.d.ts +22 -0
  275. package/ts_build/src/plugins/tree-sitter/human-readable-paths.js +332 -0
  276. package/ts_build/src/plugins/tree-sitter/human-readable-paths.js.map +1 -0
  277. package/ts_build/src/plugins/tree-sitter/lang-packs/index.d.ts +8 -0
  278. package/ts_build/src/plugins/tree-sitter/lang-packs/index.js +26 -0
  279. package/ts_build/src/plugins/tree-sitter/lang-packs/index.js.map +1 -0
  280. package/ts_build/src/plugins/tree-sitter/lang-packs/java.d.ts +2 -0
  281. package/ts_build/src/plugins/tree-sitter/lang-packs/java.js +61 -0
  282. package/ts_build/src/plugins/tree-sitter/lang-packs/java.js.map +1 -0
  283. package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.d.ts +2 -0
  284. package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js +59 -0
  285. package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js.map +1 -0
  286. package/ts_build/src/plugins/tree-sitter/lang-packs/python.d.ts +2 -0
  287. package/ts_build/src/plugins/tree-sitter/lang-packs/python.js +47 -0
  288. package/ts_build/src/plugins/tree-sitter/lang-packs/python.js.map +1 -0
  289. package/ts_build/src/plugins/tree-sitter/lang-packs/types.d.ts +43 -0
  290. package/ts_build/src/plugins/tree-sitter/lang-packs/types.js +3 -0
  291. package/ts_build/src/plugins/tree-sitter/lang-packs/types.js.map +1 -0
  292. package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.d.ts +2 -0
  293. package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js +50 -0
  294. package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js.map +1 -0
  295. package/ts_build/src/plugins/tree-sitter/parser.d.ts +75 -0
  296. package/ts_build/src/plugins/tree-sitter/parser.js +306 -0
  297. package/ts_build/src/plugins/tree-sitter/parser.js.map +1 -0
  298. package/ts_build/src/plugins/tree-sitter/simple-paths.d.ts +22 -0
  299. package/ts_build/src/plugins/tree-sitter/simple-paths.js +332 -0
  300. package/ts_build/src/plugins/tree-sitter/simple-paths.js.map +1 -0
  301. package/ts_build/src/plugins/types.d.ts +10 -0
  302. package/ts_build/src/plugins/url.d.ts +3 -2
  303. package/ts_build/src/plugins/url.js +3 -2
  304. package/ts_build/src/plugins/url.js.map +1 -1
  305. package/ts_build/src/plugins/vim.d.ts +4 -2
  306. package/ts_build/src/plugins/vim.js +6 -8
  307. package/ts_build/src/plugins/vim.js.map +1 -1
  308. package/ts_build/src/processors/CustomVariables.js +12 -3
  309. package/ts_build/src/processors/CustomVariables.js.map +1 -1
  310. package/ts_build/src/processors/TokenCompressor.js +8 -11
  311. package/ts_build/src/processors/TokenCompressor.js.map +1 -1
  312. package/ts_build/src/processors/ToolResponseCache.d.ts +2 -2
  313. package/ts_build/src/processors/ToolResponseCache.js +12 -2
  314. package/ts_build/src/processors/ToolResponseCache.js.map +1 -1
  315. package/ts_build/src/services/EmbeddingService.d.ts +10 -1
  316. package/ts_build/src/services/EmbeddingService.js +12 -12
  317. package/ts_build/src/services/EmbeddingService.js.map +1 -1
  318. package/ts_build/src/services/EventService.d.ts +7 -0
  319. package/ts_build/src/services/EventService.js +49 -0
  320. package/ts_build/src/services/EventService.js.map +1 -1
  321. package/ts_build/src/services/Mcp.js +8 -0
  322. package/ts_build/src/services/Mcp.js.map +1 -1
  323. package/ts_build/src/services/S3.js +4 -3
  324. package/ts_build/src/services/S3.js.map +1 -1
  325. package/ts_build/src/services/Tools.d.ts +1 -0
  326. package/ts_build/src/services/Tools.js +97 -35
  327. package/ts_build/src/services/Tools.js.map +1 -1
  328. package/ts_build/src/services/index.d.ts +4 -5
  329. package/ts_build/src/services/index.js +14 -9
  330. package/ts_build/src/services/index.js.map +1 -1
  331. package/ts_build/src/services/types.js +3 -3
  332. package/ts_build/src/services/types.js.map +1 -1
  333. package/ts_build/src/types.d.ts +7 -1
  334. package/ts_build/src/types.js +4 -0
  335. package/ts_build/src/types.js.map +1 -1
  336. package/ts_build/src/worker.js +12 -1
  337. package/ts_build/src/worker.js.map +1 -1
  338. package/ts_build/tests/clients/AIClient.test.d.ts +1 -0
  339. package/ts_build/tests/clients/AIClient.test.js +377 -0
  340. package/ts_build/tests/clients/AIClient.test.js.map +1 -0
  341. package/ts_build/tests/languagePlugin.test.js +217 -11
  342. package/ts_build/tests/languagePlugin.test.js.map +1 -1
  343. package/ts_build/tests/manual/agent-events/event-handler-reliability.test.d.ts +1 -0
  344. package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js +315 -0
  345. package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js.map +1 -0
  346. package/ts_build/tests/manual/agent-events/run-test.d.ts +2 -0
  347. package/ts_build/tests/manual/agent-events/run-test.js +148 -0
  348. package/ts_build/tests/manual/agent-events/run-test.js.map +1 -0
  349. package/ts_build/tests/manual/file-edits/figma.test.d.ts +1 -0
  350. package/ts_build/tests/manual/file-edits/figma.test.js +47 -0
  351. package/ts_build/tests/manual/file-edits/figma.test.js.map +1 -0
  352. package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.d.ts +1 -0
  353. package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js +100 -0
  354. package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js.map +1 -0
  355. package/ts_build/tests/manual/file-edits/patching.test.d.ts +1 -0
  356. package/ts_build/tests/manual/file-edits/patching.test.js +119 -0
  357. package/ts_build/tests/manual/file-edits/patching.test.js.map +1 -0
  358. package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.d.ts +1 -0
  359. package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js +277 -0
  360. package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js.map +1 -0
  361. package/ts_build/tests/plugins/language/languagePlugin-integration.test.d.ts +1 -0
  362. package/ts_build/tests/plugins/language/languagePlugin-integration.test.js +331 -0
  363. package/ts_build/tests/plugins/language/languagePlugin-integration.test.js.map +1 -0
  364. package/ts_build/tests/plugins/language/languagePlugin.test.d.ts +1 -0
  365. package/ts_build/tests/plugins/language/languagePlugin.test.js +286 -0
  366. package/ts_build/tests/plugins/language/languagePlugin.test.js.map +1 -0
  367. package/ts_build/tests/processors/Base64ImageDetector.test.d.ts +1 -0
  368. package/ts_build/tests/processors/Base64ImageDetector.test.js +351 -0
  369. package/ts_build/tests/processors/Base64ImageDetector.test.js.map +1 -0
  370. package/ts_build/tests/processors/CustomVariables.test.d.ts +1 -0
  371. package/ts_build/tests/processors/CustomVariables.test.js +351 -0
  372. package/ts_build/tests/processors/CustomVariables.test.js.map +1 -0
  373. package/ts_build/tests/processors/HarmonyToolProcessor.test.d.ts +1 -0
  374. package/ts_build/tests/processors/HarmonyToolProcessor.test.js +382 -0
  375. package/ts_build/tests/processors/HarmonyToolProcessor.test.js.map +1 -0
  376. package/ts_build/tests/processors/TokenCompressor.test.d.ts +1 -0
  377. package/ts_build/tests/processors/TokenCompressor.test.js +300 -0
  378. package/ts_build/tests/processors/TokenCompressor.test.js.map +1 -0
  379. package/ts_build/tests/processors/ToolResponseCache.test.d.ts +1 -0
  380. package/ts_build/tests/processors/ToolResponseCache.test.js +539 -0
  381. package/ts_build/tests/processors/ToolResponseCache.test.js.map +1 -0
  382. package/ts_build/tests/services/Plugins/plugin-event-integration.test.d.ts +1 -0
  383. package/ts_build/tests/services/Plugins/plugin-event-integration.test.js +232 -0
  384. package/ts_build/tests/services/Plugins/plugin-event-integration.test.js.map +1 -0
  385. package/ts_build/tests/services/Tools.test.d.ts +1 -0
  386. package/ts_build/tests/services/Tools.test.js +1059 -0
  387. package/ts_build/tests/services/Tools.test.js.map +1 -0
  388. package/ts_build/tests/test.spec.js +110 -68
  389. package/ts_build/tests/test.spec.js.map +1 -1
  390. package/ts_build/tests/tree-sitter/editor.test.d.ts +1 -0
  391. package/ts_build/tests/tree-sitter/editor.test.js +85 -0
  392. package/ts_build/tests/tree-sitter/editor.test.js.map +1 -0
  393. package/ts_build/tests/tree-sitter/invalid.test.d.ts +1 -0
  394. package/ts_build/tests/tree-sitter/invalid.test.js +198 -0
  395. package/ts_build/tests/tree-sitter/invalid.test.js.map +1 -0
  396. package/ts_build/tests/tree-sitter/paths/common-edits.test.d.ts +1 -0
  397. package/ts_build/tests/tree-sitter/paths/common-edits.test.js +347 -0
  398. package/ts_build/tests/tree-sitter/paths/common-edits.test.js.map +1 -0
  399. package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.d.ts +1 -0
  400. package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js +35 -0
  401. package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js.map +1 -0
  402. package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.d.ts +1 -0
  403. package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js +38 -0
  404. package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js.map +1 -0
  405. package/ts_build/tests/tree-sitter/paths/debug-paths.test.d.ts +1 -0
  406. package/ts_build/tests/tree-sitter/paths/debug-paths.test.js +74 -0
  407. package/ts_build/tests/tree-sitter/paths/debug-paths.test.js.map +1 -0
  408. package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.d.ts +1 -0
  409. package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js +302 -0
  410. package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js.map +1 -0
  411. package/ts_build/tests/tree-sitter/paths/paths.test.d.ts +1 -0
  412. package/ts_build/tests/tree-sitter/paths/paths.test.js +116 -0
  413. package/ts_build/tests/tree-sitter/paths/paths.test.js.map +1 -0
  414. package/ts_build/tests/tree-sitter/paths/simple-paths.test.d.ts +1 -0
  415. package/ts_build/tests/tree-sitter/paths/simple-paths.test.js +302 -0
  416. package/ts_build/tests/tree-sitter/paths/simple-paths.test.js.map +1 -0
  417. package/ts_build/tests/tree-sitter/sample-after.d.ts +11 -0
  418. package/ts_build/tests/tree-sitter/sample-after.js +44 -0
  419. package/ts_build/tests/tree-sitter/sample-after.js.map +1 -0
  420. package/ts_build/tests/tree-sitter/sample-before.d.ts +9 -0
  421. package/ts_build/tests/tree-sitter/sample-before.js +28 -0
  422. package/ts_build/tests/tree-sitter/sample-before.js.map +1 -0
  423. package/ts_build/tests/tree-sitter/test-files/completely-broken.d.ts +2 -0
  424. package/ts_build/tests/tree-sitter/test-files/completely-broken.js +17 -0
  425. package/ts_build/tests/tree-sitter/test-files/completely-broken.js.map +1 -0
  426. package/ts_build/tests/tree-sitter/test-files/duplicate-braces.d.ts +8 -0
  427. package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js +38 -0
  428. package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js.map +1 -0
  429. package/ts_build/tests/tree-sitter/test-files/invalid-nesting.d.ts +8 -0
  430. package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js +38 -0
  431. package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js.map +1 -0
  432. package/ts_build/tests/tree-sitter/test-files/malformed-signature.d.ts +8 -0
  433. package/ts_build/tests/tree-sitter/test-files/malformed-signature.js +38 -0
  434. package/ts_build/tests/tree-sitter/test-files/malformed-signature.js.map +1 -0
  435. package/ts_build/tests/tree-sitter/test-files/mismatched-parens.d.ts +10 -0
  436. package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js +38 -0
  437. package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js.map +1 -0
  438. package/ts_build/tests/tree-sitter/test-files/missing-semicolon.d.ts +8 -0
  439. package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js +38 -0
  440. package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js.map +1 -0
  441. package/ts_build/tests/tree-sitter/test-files/partially-broken.d.ts +6 -0
  442. package/ts_build/tests/tree-sitter/test-files/partially-broken.js +20 -0
  443. package/ts_build/tests/tree-sitter/test-files/partially-broken.js.map +1 -0
  444. package/ts_build/tests/tree-sitter/test-files/specific-errors.d.ts +7 -0
  445. package/ts_build/tests/tree-sitter/test-files/specific-errors.js +14 -0
  446. package/ts_build/tests/tree-sitter/test-files/specific-errors.js.map +1 -0
  447. package/ts_build/tests/tree-sitter/test-files/unclosed-string.d.ts +8 -0
  448. package/ts_build/tests/tree-sitter/test-files/unclosed-string.js +38 -0
  449. package/ts_build/tests/tree-sitter/test-files/unclosed-string.js.map +1 -0
  450. package/ts_build/tests/tree-sitter/tree-sitter.test.d.ts +1 -0
  451. package/ts_build/tests/tree-sitter/tree-sitter.test.js +185 -0
  452. package/ts_build/tests/tree-sitter/tree-sitter.test.js.map +1 -0
  453. package/tsconfig.json +2 -1
  454. package/tests/languagePlugin.test.ts +0 -74
  455. /package/src/chat/modules/{index.js → index.ts} +0 -0
  456. /package/tests/{integration → manual/file-edits}/patching/input.txt +0 -0
  457. /package/tests/{integration → manual/file-edits}/patching/output.txt +0 -0
  458. /package/tests/{integration → manual/file-edits}/patching/patch.txt +0 -0
  459. /package/tests/{integration → manual/file-edits}/patching/unseen.txt +0 -0
@@ -0,0 +1,369 @@
1
+ import {
2
+ LanguageAgnosticParser,
3
+ PathLocation,
4
+ SyntaxNode,
5
+ Tree,
6
+ } from "./parser";
7
+ import { SimplePathResolver, SimplePathMatch } from "./simple-paths";
8
+ import { readFileSync } from "fs";
9
+ import { createPatch } from "diff";
10
+
11
+ export class TreeEditor {
12
+ private parser: LanguageAgnosticParser;
13
+ private originalText: string;
14
+ public tree: Tree; // Made public for debugging
15
+ private pathResolver: SimplePathResolver;
16
+
17
+ constructor(
18
+ parser: LanguageAgnosticParser,
19
+ sourceCode: string,
20
+ originalText?: string,
21
+ existingTree?: Tree
22
+ ) {
23
+ this.parser = parser;
24
+ this.originalText = originalText || sourceCode;
25
+ this.tree = existingTree || parser.parseString(sourceCode);
26
+ this.pathResolver = new SimplePathResolver(parser);
27
+ }
28
+
29
+ private createModified(newText: string): TreeEditor {
30
+ return new TreeEditor(this.parser, newText, this.originalText);
31
+ }
32
+
33
+ static fromFile(
34
+ parser: LanguageAgnosticParser,
35
+ filePath: string
36
+ ): TreeEditor {
37
+ const sourceCode = readFileSync(filePath, "utf8");
38
+ return new TreeEditor(parser, sourceCode);
39
+ }
40
+
41
+ static fromTree(parser: LanguageAgnosticParser, tree: Tree): TreeEditor {
42
+ const sourceCode = tree.rootNode.text;
43
+ return new TreeEditor(parser, sourceCode, sourceCode, tree);
44
+ }
45
+
46
+ addLines(path: string, content: string, afterLine?: number): TreeEditor {
47
+ const lines = this.getCurrentText().split("\n");
48
+ const insertIndex = afterLine !== undefined ? afterLine : lines.length;
49
+
50
+ const contentLines = content.split("\n");
51
+ lines.splice(insertIndex, 0, ...contentLines);
52
+
53
+ const newText = lines.join("\n");
54
+ return this.createModified(newText);
55
+ }
56
+
57
+ removeLines(startLine: number, endLine?: number): TreeEditor {
58
+ const lines = this.getCurrentText().split("\n");
59
+ const end = endLine !== undefined ? endLine : startLine;
60
+
61
+ lines.splice(startLine, end - startLine + 1);
62
+
63
+ const newText = lines.join("\n");
64
+ return this.createModified(newText);
65
+ }
66
+
67
+ updateLine(lineNumber: number, newContent: string): TreeEditor {
68
+ const lines = this.getCurrentText().split("\n");
69
+
70
+ if (lineNumber >= 0 && lineNumber < lines.length) {
71
+ lines[lineNumber] = newContent;
72
+ }
73
+
74
+ const newText = lines.join("\n");
75
+ return this.createModified(newText);
76
+ }
77
+
78
+ updateNodeByPath(path: string, newContent: string): TreeEditor {
79
+ // Find the node by path
80
+ const node = this.resolvePathToNode(path);
81
+ if (!node) {
82
+ throw new Error(`Node not found at path: ${path}`);
83
+ }
84
+
85
+ const currentText = this.getCurrentText();
86
+ const lines = currentText.split("\n");
87
+
88
+ // Replace the node's text with new content
89
+ const startLine = node.startPosition.row;
90
+ const endLine = node.endPosition.row;
91
+ const startCol = node.startPosition.column;
92
+ const endCol = node.endPosition.column;
93
+
94
+ if (startLine === endLine) {
95
+ // Single line replacement
96
+ const line = lines[startLine];
97
+ lines[startLine] =
98
+ line.substring(0, startCol) + newContent + line.substring(endCol);
99
+ } else {
100
+ // Multi-line replacement
101
+ const firstLine = lines[startLine].substring(0, startCol) + newContent;
102
+ const lastLine = lines[endLine].substring(endCol);
103
+
104
+ // Remove lines between start and end
105
+ lines.splice(startLine, endLine - startLine + 1, firstLine + lastLine);
106
+ }
107
+
108
+ const newText = lines.join("\n");
109
+ return this.createModified(newText);
110
+ }
111
+
112
+ /**
113
+ * Delete a node by path (sets content to empty string)
114
+ */
115
+ deleteNodeByPath(path: string): TreeEditor {
116
+ return this.updateNodeByPath(path, "");
117
+ }
118
+
119
+ /**
120
+ * Update a node using simple path like "ClassName.methodName"
121
+ */
122
+ updateNodeBySimplePath(simplePath: string, newContent: string): TreeEditor {
123
+ return this.updateNodeByPath(simplePath, newContent);
124
+ }
125
+
126
+ /**
127
+ * Find nodes using simple paths
128
+ */
129
+ findNodesBySimplePath(simplePath: string): SimplePathMatch[] {
130
+ return this.pathResolver.findBySimplePath(this.tree, simplePath);
131
+ }
132
+
133
+ /**
134
+ * Get all available simple paths in the current tree
135
+ */
136
+ getAllSimplePaths(): string[] {
137
+ return this.pathResolver.getAllSimplePaths(this.tree);
138
+ }
139
+
140
+ /**
141
+ * Try to resolve a path that could be either simple or programmatic format
142
+ * Returns the matching node or null if not found
143
+ */
144
+ private resolvePathToNode(path: string): SyntaxNode | null {
145
+ // First try simple path
146
+ const simpleMatches = this.pathResolver.findBySimplePath(this.tree, path);
147
+ if (simpleMatches.length > 0) {
148
+ if (simpleMatches.length > 1) {
149
+ throw new Error(
150
+ `Multiple nodes found for path: ${path}. Found: ${simpleMatches
151
+ .map((m) => m.description)
152
+ .join(", ")}`
153
+ );
154
+ }
155
+ return simpleMatches[0].node;
156
+ }
157
+
158
+ // Then try programmatic path
159
+ return this.findNodeByPath(path);
160
+ }
161
+
162
+ /**
163
+ * Insert content before nodes of specified types within a parent path
164
+ * @param parentPath - Path to the parent node (simple or programmatic)
165
+ * @param content - Content to insert
166
+ * @param beforeKinds - Array of node types to insert before (e.g., ['method_definition', 'constructor_definition'])
167
+ * @returns Modified TreeEditor
168
+ */
169
+ insertBefore(
170
+ parentPath: string,
171
+ content: string,
172
+ beforeKinds: string[]
173
+ ): TreeEditor {
174
+ const parentNode = this.resolvePathToNode(parentPath);
175
+ if (!parentNode) {
176
+ throw new Error(`No nodes found for path: ${parentPath}`);
177
+ }
178
+
179
+ const bodyNode = this.parser.getBodyNode(parentNode);
180
+ if (!bodyNode) {
181
+ throw new Error(`Cannot find body node for path: ${parentPath}`);
182
+ }
183
+
184
+ // Find the first child that matches any of the beforeTypes
185
+ for (const child of bodyNode.children) {
186
+ if (beforeKinds.includes(this.parser.nodeKind(child))) {
187
+ return this.addLines("", content, child.startPosition.row);
188
+ }
189
+ }
190
+
191
+ // If no matching types found, append to the parent
192
+ return this.appendChild(parentPath, content);
193
+ }
194
+
195
+ /**
196
+ * Find the body node of a class, function, or describe block
197
+ */
198
+ /**
199
+ * Append content to a parent node
200
+ * @param parentPath - Path to parent node (empty string for root level)
201
+ * @param content - Content to append
202
+ */
203
+ appendChild(parentPath: string, content: string): TreeEditor {
204
+ if (parentPath === "") {
205
+ // Append to the end of the file
206
+ const current = this.getCurrentText();
207
+ const newText = current + "\n\n" + content;
208
+ return this.createModified(newText);
209
+ }
210
+
211
+ const parentNode = this.resolvePathToNode(parentPath);
212
+ if (!parentNode) {
213
+ throw new Error(`No nodes found for path: ${parentPath}`);
214
+ }
215
+
216
+ const bodyNode = this.parser.getBodyNode(parentNode);
217
+ if (!bodyNode) {
218
+ throw new Error(`Cannot find body node for path: ${parentPath}`);
219
+ }
220
+
221
+ // Find the insertion point (before the closing brace)
222
+ const currentText = this.getCurrentText();
223
+ const lines = currentText.split("\n");
224
+
225
+ // Find the line with the closing brace of the body
226
+ const endLine = bodyNode.endPosition.row;
227
+ const endCol = bodyNode.endPosition.column;
228
+
229
+ // Insert content before the closing brace, with proper indentation
230
+ const insertLine = endLine;
231
+
232
+ // Detect if content is already properly indented by checking the first non-empty line
233
+ const contentLines = content.split("\n");
234
+ const firstNonEmptyLine = contentLines.find((line) => line.trim() !== "");
235
+ const isAlreadyIndented =
236
+ firstNonEmptyLine && firstNonEmptyLine.startsWith(" ");
237
+
238
+ const indentedContent = contentLines
239
+ .map((line, index) => {
240
+ if (line.trim() === "") return line; // Keep empty lines as-is
241
+
242
+ if (isAlreadyIndented) {
243
+ // Content is already indented, use as-is
244
+ return line;
245
+ } else {
246
+ // Add base indentation for unindented content
247
+ return " " + line;
248
+ }
249
+ })
250
+ .join("\n");
251
+
252
+ lines.splice(insertLine, 0, indentedContent);
253
+
254
+ const newText = lines.join("\n");
255
+ return this.createModified(newText);
256
+ }
257
+
258
+ /**
259
+ * Add a method to a class
260
+ * @param className - Name of the class
261
+ * @param methodContent - Content of the method to add
262
+ */
263
+ addMethodToClass(className: string, methodContent: string): TreeEditor {
264
+ return this.appendChild(className, methodContent);
265
+ }
266
+
267
+ /**
268
+ * Add a property to a class
269
+ * @param className - Name of the class
270
+ * @param propertyContent - Content of the property to add
271
+ */
272
+ addPropertyToClass(className: string, propertyContent: string): TreeEditor {
273
+ return this.insertBefore(className, propertyContent, [
274
+ "method",
275
+ "constructor",
276
+ ]);
277
+ }
278
+
279
+ /**
280
+ * Append content to any block type using simple block syntax
281
+ * @param blockPath - Block path like describe("name"), beforeEach(), test("should work")
282
+ * @param content - Content to append to the block
283
+ */
284
+ appendToBlock(blockPath: string, content: string): TreeEditor {
285
+ return this.appendChild(blockPath, content);
286
+ }
287
+
288
+ /**
289
+ * Update the entire content of a block's callback function
290
+ * @param blockPath - Block path like describe("name"), beforeEach(), test("should work")
291
+ * @param content - New content to replace the block's body
292
+ */
293
+ updateBlock(blockPath: string, content: string): TreeEditor {
294
+ return this.updateNodeByPath(blockPath, content);
295
+ }
296
+
297
+ /**
298
+ * Delete an entire block
299
+ * @param blockPath - Block path like describe("name"), beforeEach(), test("should work")
300
+ */
301
+ deleteBlock(blockPath: string): TreeEditor {
302
+ return this.deleteNodeByPath(blockPath);
303
+ }
304
+
305
+ /**
306
+ * Helper method to get all nodes in the tree
307
+ */
308
+ private getAllNodes(node: SyntaxNode): SyntaxNode[] {
309
+ const nodes: SyntaxNode[] = [node];
310
+ for (let i = 0; i < node.childCount; i++) {
311
+ const child = node.child(i);
312
+ if (child) {
313
+ nodes.push(...this.getAllNodes(child));
314
+ }
315
+ }
316
+ return nodes;
317
+ }
318
+
319
+ findPathsForLine(tree: Tree, searchText: string): PathLocation[] {
320
+ return this.parser.findPathsForLine(tree, searchText);
321
+ }
322
+
323
+ findNodeByPath(path: string): SyntaxNode | null {
324
+ const parts = path.split("/");
325
+ if (parts.length === 0) return null;
326
+ let current = this.tree.rootNode;
327
+
328
+ for (const part of parts) {
329
+ const match = part.match(/^(.+)\[(\d+)\]$/);
330
+ if (!match) return null;
331
+
332
+ const [, nodeType, indexStr] = match;
333
+ const index = parseInt(indexStr, 10);
334
+
335
+ if (
336
+ index >= current.children.length ||
337
+ current.children[index].type !== nodeType
338
+ ) {
339
+ return null;
340
+ }
341
+
342
+ current = current.children[index];
343
+ }
344
+
345
+ return current;
346
+ }
347
+
348
+ getCurrentText(): string {
349
+ if (!this.tree || !this.tree.rootNode) {
350
+ throw new Error("Failed to parse source code. Tree:" + this.tree);
351
+ }
352
+
353
+ return this.tree.rootNode.text;
354
+ }
355
+
356
+ getTree(): Tree {
357
+ return this.tree;
358
+ }
359
+
360
+ generateDiff(): string {
361
+ return createPatch(
362
+ "original",
363
+ this.originalText,
364
+ this.getCurrentText(),
365
+ "original",
366
+ "modified"
367
+ );
368
+ }
369
+ }
@@ -0,0 +1,23 @@
1
+ export { LanguagePackConfig } from "./types";
2
+ export { javascriptLanguagePack } from "./javascript";
3
+ export { typescriptLanguagePack } from "./typescript";
4
+ export { pythonLanguagePack } from "./python";
5
+ export { javaLanguagePack } from "./java";
6
+
7
+ import { LanguagePackConfig } from "./types";
8
+ import { javascriptLanguagePack } from "./javascript";
9
+ import { typescriptLanguagePack } from "./typescript";
10
+ import { pythonLanguagePack } from "./python";
11
+ import { javaLanguagePack } from "./java";
12
+
13
+ // Language pack registry
14
+ export const languagePacks: Record<string, LanguagePackConfig> = {
15
+ javascript: javascriptLanguagePack,
16
+ typescript: typescriptLanguagePack,
17
+ python: pythonLanguagePack,
18
+ java: javaLanguagePack,
19
+ };
20
+
21
+ export function getLanguagePack(language: string): LanguagePackConfig | undefined {
22
+ return languagePacks[language.toLowerCase()];
23
+ }
@@ -0,0 +1,59 @@
1
+ import { LanguagePackConfig } from "./types";
2
+
3
+ export const javaLanguagePack: LanguagePackConfig = {
4
+ language: "java",
5
+ queries: {
6
+ classes: `
7
+ (class_declaration name: (identifier) @name) @class
8
+ (interface_declaration name: (identifier) @name) @class
9
+ (enum_declaration name: (identifier) @name) @class
10
+ `,
11
+ methods: `
12
+ (method_declaration name: (identifier) @name) @method
13
+ (constructor_declaration name: (identifier) @name) @method
14
+ `,
15
+ properties: `
16
+ (field_declaration
17
+ declarator: (variable_declarator
18
+ name: (identifier) @name
19
+ )
20
+ ) @property
21
+ `,
22
+ blocks: `
23
+ (method_invocation
24
+ name: (identifier) @callee
25
+ arguments: (argument_list (string_literal) @name? . (_)*)
26
+ ) @block
27
+ (annotation
28
+ name: (identifier) @callee
29
+ arguments: (annotation_argument_list (string_literal) @name? . (_)*)
30
+ ) @block
31
+ `,
32
+ },
33
+ kindMap: {
34
+ class_declaration: "class",
35
+ interface_declaration: "class",
36
+ enum_declaration: "class",
37
+ class: "class",
38
+ method_declaration: "method",
39
+ constructor_declaration: "method",
40
+ field_declaration: "property",
41
+ method_invocation: "block",
42
+ annotation: "block",
43
+ class_body: "body",
44
+ block: "body",
45
+ },
46
+ bodyMap: {
47
+ class_declaration: [{ kind: "child", nodeType: "class_body" }],
48
+ interface_declaration: [{ kind: "child", nodeType: "class_body" }],
49
+ enum_declaration: [{ kind: "child", nodeType: "class_body" }],
50
+ class: [{ kind: "child", nodeType: "class_body" }],
51
+ method_declaration: [{ kind: "functionBody" }],
52
+ constructor_declaration: [{ kind: "functionBody" }],
53
+ method_invocation: [{ kind: "callCallbackBody" }],
54
+ annotation: [{ kind: "callCallbackBody" }],
55
+ class_body: [{ kind: "self" }],
56
+ block: [{ kind: "self" }],
57
+ },
58
+ stringUnwrapHint: "java-like",
59
+ };
@@ -0,0 +1,57 @@
1
+ import { LanguagePackConfig } from "./types";
2
+
3
+ export const javascriptLanguagePack: LanguagePackConfig = {
4
+ language: "javascript",
5
+ queries: {
6
+ classes: `
7
+ (class_declaration name: (identifier) @name) @class
8
+ `,
9
+ methods: `
10
+ (method_definition name: (property_identifier) @name) @method
11
+ (function_declaration name: (identifier) @name) @method
12
+ (function_expression name: (identifier) @name) @method
13
+ (variable_declarator name: (identifier) @name value: (arrow_function)) @method
14
+ `,
15
+ properties: `
16
+ (public_field_definition name: (property_identifier) @name) @property
17
+ `,
18
+ blocks: `
19
+ (call_expression
20
+ function: [
21
+ (identifier) @callee
22
+ (member_expression object: (identifier) @callee property: (property_identifier))
23
+ ]
24
+ arguments: (arguments
25
+ [
26
+ (string (string_fragment) @name)
27
+ (template_string (string_fragment) @name)
28
+ (template_string) @name
29
+ ]? . (_)*)
30
+ ) @block
31
+ `,
32
+ },
33
+ kindMap: {
34
+ class_declaration: "class",
35
+ method_definition: "method",
36
+ constructor_definition: "constructor",
37
+ method_signature: "method",
38
+ function_declaration: "function",
39
+ function_expression: "function",
40
+ arrow_function: "function",
41
+ public_field_definition: "property",
42
+ class_body: "body",
43
+ statement_block: "body",
44
+ call_expression: "block",
45
+ },
46
+ bodyMap: {
47
+ class_declaration: [{ kind: "child", nodeType: "class_body" }],
48
+ method_definition: [{ kind: "functionBody" }],
49
+ function_declaration: [{ kind: "functionBody" }],
50
+ function_expression: [{ kind: "functionBody" }],
51
+ arrow_function: [{ kind: "functionBody" }],
52
+ call_expression: [{ kind: "callCallbackBody" }],
53
+ class_body: [{ kind: "self" }],
54
+ statement_block: [{ kind: "self" }],
55
+ },
56
+ stringUnwrapHint: "js-like",
57
+ };
@@ -0,0 +1,45 @@
1
+ import { LanguagePackConfig } from "./types";
2
+
3
+ export const pythonLanguagePack: LanguagePackConfig = {
4
+ language: "python",
5
+ queries: {
6
+ classes: `
7
+ (class_definition name: (identifier) @name) @class
8
+ `,
9
+ methods: `
10
+ (function_definition name: (identifier) @name) @method
11
+ `,
12
+ properties: `
13
+ (assignment
14
+ left: (attribute attribute: (identifier) @name)
15
+ ) @property
16
+ (assignment
17
+ left: (identifier) @name
18
+ ) @property
19
+ `,
20
+ blocks: `
21
+ (call
22
+ function: (identifier) @callee
23
+ arguments: (argument_list (string) @name? . (_)*)
24
+ ) @block
25
+ `,
26
+ },
27
+ kindMap: {
28
+ class_definition: "class",
29
+ class: "class",
30
+ function_definition: "method",
31
+ assignment: "property",
32
+ call: "block",
33
+ block: "body",
34
+ suite: "body",
35
+ },
36
+ bodyMap: {
37
+ class_definition: [{ kind: "child", nodeType: "block" }],
38
+ class: [{ kind: "child", nodeType: "block" }],
39
+ function_definition: [{ kind: "functionBody" }],
40
+ call: [{ kind: "callCallbackBody" }],
41
+ block: [{ kind: "self" }],
42
+ suite: [{ kind: "self" }],
43
+ },
44
+ stringUnwrapHint: "python-like",
45
+ };
@@ -0,0 +1,79 @@
1
+ import { SyntaxNode } from "../parser";
2
+
3
+ /**
4
+ * Capture types for tree-sitter queries used in language packs
5
+ */
6
+ export type CaptureType =
7
+ | "@decl.class" // Class declarations
8
+ | "@decl.method" // Method declarations
9
+ | "@decl.property" // Property declarations
10
+ | "@block" // Generic blocks (describe, test, etc.)
11
+ | "@callee" // Function being called (for blocks)
12
+ | "@name"; // Name/identifier of a construct
13
+
14
+ /**
15
+ * Result of a tree-sitter query match
16
+ */
17
+ export interface QueryMatch {
18
+ node: SyntaxNode;
19
+ captures: Record<CaptureType, SyntaxNode[]>;
20
+ }
21
+
22
+ /**
23
+ * Match result for human-readable path resolution
24
+ */
25
+ export interface SimplePathMatch {
26
+ node: SyntaxNode;
27
+ path: string;
28
+ simplePath: string;
29
+ description: string;
30
+ }
31
+
32
+ /**
33
+ * Normalized node kinds for language-agnostic processing
34
+ */
35
+ export type NormalizedKind = "class" | "constructor" | "method" | "function" | "property" | "body" | "block" | "unknown";
36
+
37
+ /**
38
+ * Rules for finding body nodes
39
+ */
40
+ export type BodyRule =
41
+ | { kind: "self" } // The node itself is the body
42
+ | { kind: "child"; nodeType: string } // Look for child with specific type
43
+ | { kind: "field"; field: string } // Look for named field
44
+ | { kind: "functionBody" } // Special handling for function bodies
45
+ | { kind: "callCallbackBody" }; // Special handling for callback bodies
46
+
47
+ /**
48
+ * Language pack for declarative language support
49
+ */
50
+ export interface LanguagePackConfig {
51
+ /** Language identifier */
52
+ language: string;
53
+
54
+ /** Tree-sitter queries for different constructs */
55
+ queries: {
56
+ classes?: string;
57
+ methods?: string;
58
+ properties?: string;
59
+ blocks?: string;
60
+ };
61
+
62
+ /** Map from raw node types to normalized kinds */
63
+ kindMap: Record<string, NormalizedKind>;
64
+
65
+ /** Map from node types to body resolution rules */
66
+ bodyMap: Record<string, BodyRule[]>;
67
+
68
+ /** Hint for string unwrapping behavior */
69
+ stringUnwrapHint?: string;
70
+ }
71
+
72
+ /**
73
+ * Registry of language packs
74
+ */
75
+ export interface LanguagePackRegistry {
76
+ get(language: string): LanguagePackConfig | undefined;
77
+ register(pack: LanguagePackConfig): void;
78
+ list(): string[];
79
+ }
@@ -0,0 +1,49 @@
1
+ import { LanguagePackConfig } from "./types";
2
+ import { javascriptLanguagePack } from "./javascript";
3
+
4
+ export const typescriptLanguagePack: LanguagePackConfig = {
5
+ language: "typescript",
6
+ queries: {
7
+ classes: `
8
+ (class_declaration name: (type_identifier) @name) @class
9
+ (interface_declaration name: (type_identifier) @name) @class
10
+ (type_alias_declaration name: (type_identifier) @name) @class
11
+ `,
12
+ methods: `
13
+ (method_definition name: (property_identifier) @name) @method
14
+ (function_declaration name: (identifier) @name) @method
15
+ (function_expression name: (identifier) @name) @method
16
+ (variable_declarator name: (identifier) @name value: (arrow_function)) @method
17
+ (method_signature name: (property_identifier) @name) @method
18
+ (construct_signature) @method
19
+ (call_signature) @method
20
+ `,
21
+ properties: `
22
+ (public_field_definition name: (property_identifier) @name) @property
23
+ (property_signature name: (property_identifier) @name) @property
24
+ (index_signature) @property
25
+ `,
26
+ blocks: javascriptLanguagePack.queries.blocks,
27
+ },
28
+ kindMap: {
29
+ ...javascriptLanguagePack.kindMap,
30
+ interface_declaration: "class",
31
+ type_alias_declaration: "class",
32
+ method_signature: "method",
33
+ construct_signature: "method",
34
+ call_signature: "method",
35
+ property_signature: "property",
36
+ index_signature: "property",
37
+ object_type: "body",
38
+ interface_body: "body",
39
+ },
40
+ bodyMap: {
41
+ ...javascriptLanguagePack.bodyMap,
42
+ // TypeScript-specific body mappings
43
+ interface_declaration: [{ kind: "child", nodeType: "object_type" }],
44
+ type_alias_declaration: [{ kind: "field", field: "value" }],
45
+ object_type: [{ kind: "self" }],
46
+ interface_body: [{ kind: "self" }],
47
+ },
48
+ stringUnwrapHint: "js-like",
49
+ };