distill-mcp 0.6.0-beta

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 (440) hide show
  1. package/bin/cli.js +133 -0
  2. package/dist/analytics/session-tracker.d.ts +74 -0
  3. package/dist/analytics/session-tracker.d.ts.map +1 -0
  4. package/dist/analytics/session-tracker.js +123 -0
  5. package/dist/ast/benchmark.test.d.ts +7 -0
  6. package/dist/ast/benchmark.test.d.ts.map +1 -0
  7. package/dist/ast/benchmark.test.js +175 -0
  8. package/dist/ast/go/index.d.ts +9 -0
  9. package/dist/ast/go/index.d.ts.map +1 -0
  10. package/dist/ast/go/index.js +8 -0
  11. package/dist/ast/go/parser.d.ts +31 -0
  12. package/dist/ast/go/parser.d.ts.map +1 -0
  13. package/dist/ast/go/parser.js +428 -0
  14. package/dist/ast/go/parser.test.d.ts +5 -0
  15. package/dist/ast/go/parser.test.d.ts.map +1 -0
  16. package/dist/ast/go/parser.test.js +241 -0
  17. package/dist/ast/go/queries.d.ts +51 -0
  18. package/dist/ast/go/queries.d.ts.map +1 -0
  19. package/dist/ast/go/queries.js +114 -0
  20. package/dist/ast/go/utils.d.ts +66 -0
  21. package/dist/ast/go/utils.d.ts.map +1 -0
  22. package/dist/ast/go/utils.js +140 -0
  23. package/dist/ast/index.d.ts +39 -0
  24. package/dist/ast/index.d.ts.map +1 -0
  25. package/dist/ast/index.js +245 -0
  26. package/dist/ast/php/index.d.ts +9 -0
  27. package/dist/ast/php/index.d.ts.map +1 -0
  28. package/dist/ast/php/index.js +8 -0
  29. package/dist/ast/php/parser.d.ts +31 -0
  30. package/dist/ast/php/parser.d.ts.map +1 -0
  31. package/dist/ast/php/parser.js +388 -0
  32. package/dist/ast/php/parser.test.d.ts +5 -0
  33. package/dist/ast/php/parser.test.d.ts.map +1 -0
  34. package/dist/ast/php/parser.test.js +328 -0
  35. package/dist/ast/php/queries.d.ts +61 -0
  36. package/dist/ast/php/queries.d.ts.map +1 -0
  37. package/dist/ast/php/queries.js +117 -0
  38. package/dist/ast/php/utils.d.ts +83 -0
  39. package/dist/ast/php/utils.d.ts.map +1 -0
  40. package/dist/ast/php/utils.js +246 -0
  41. package/dist/ast/python/index.d.ts +9 -0
  42. package/dist/ast/python/index.d.ts.map +1 -0
  43. package/dist/ast/python/index.js +8 -0
  44. package/dist/ast/python/parser.d.ts +32 -0
  45. package/dist/ast/python/parser.d.ts.map +1 -0
  46. package/dist/ast/python/parser.js +422 -0
  47. package/dist/ast/python/parser.test.d.ts +5 -0
  48. package/dist/ast/python/parser.test.d.ts.map +1 -0
  49. package/dist/ast/python/parser.test.js +186 -0
  50. package/dist/ast/python/queries.d.ts +73 -0
  51. package/dist/ast/python/queries.d.ts.map +1 -0
  52. package/dist/ast/python/queries.js +137 -0
  53. package/dist/ast/python/utils.d.ts +63 -0
  54. package/dist/ast/python/utils.d.ts.map +1 -0
  55. package/dist/ast/python/utils.js +159 -0
  56. package/dist/ast/quick-scan.d.ts +40 -0
  57. package/dist/ast/quick-scan.d.ts.map +1 -0
  58. package/dist/ast/quick-scan.js +287 -0
  59. package/dist/ast/rust/index.d.ts +9 -0
  60. package/dist/ast/rust/index.d.ts.map +1 -0
  61. package/dist/ast/rust/index.js +8 -0
  62. package/dist/ast/rust/parser.d.ts +31 -0
  63. package/dist/ast/rust/parser.d.ts.map +1 -0
  64. package/dist/ast/rust/parser.js +416 -0
  65. package/dist/ast/rust/parser.test.d.ts +5 -0
  66. package/dist/ast/rust/parser.test.d.ts.map +1 -0
  67. package/dist/ast/rust/parser.test.js +329 -0
  68. package/dist/ast/rust/queries.d.ts +66 -0
  69. package/dist/ast/rust/queries.d.ts.map +1 -0
  70. package/dist/ast/rust/queries.js +132 -0
  71. package/dist/ast/rust/utils.d.ts +91 -0
  72. package/dist/ast/rust/utils.d.ts.map +1 -0
  73. package/dist/ast/rust/utils.js +254 -0
  74. package/dist/ast/swift/index.d.ts +10 -0
  75. package/dist/ast/swift/index.d.ts.map +1 -0
  76. package/dist/ast/swift/index.js +8 -0
  77. package/dist/ast/swift/parser.d.ts +31 -0
  78. package/dist/ast/swift/parser.d.ts.map +1 -0
  79. package/dist/ast/swift/parser.js +554 -0
  80. package/dist/ast/swift/parser.test.d.ts +5 -0
  81. package/dist/ast/swift/parser.test.d.ts.map +1 -0
  82. package/dist/ast/swift/parser.test.js +398 -0
  83. package/dist/ast/swift/queries.d.ts +71 -0
  84. package/dist/ast/swift/queries.d.ts.map +1 -0
  85. package/dist/ast/swift/queries.js +137 -0
  86. package/dist/ast/swift/utils.d.ts +94 -0
  87. package/dist/ast/swift/utils.d.ts.map +1 -0
  88. package/dist/ast/swift/utils.js +411 -0
  89. package/dist/ast/types.d.ts +96 -0
  90. package/dist/ast/types.d.ts.map +1 -0
  91. package/dist/ast/types.js +21 -0
  92. package/dist/ast/typescript.d.ts +24 -0
  93. package/dist/ast/typescript.d.ts.map +1 -0
  94. package/dist/ast/typescript.js +357 -0
  95. package/dist/cache/file-hash.d.ts +33 -0
  96. package/dist/cache/file-hash.d.ts.map +1 -0
  97. package/dist/cache/file-hash.js +59 -0
  98. package/dist/cache/index.d.ts +9 -0
  99. package/dist/cache/index.d.ts.map +1 -0
  100. package/dist/cache/index.js +8 -0
  101. package/dist/cache/smart-cache.d.ts +68 -0
  102. package/dist/cache/smart-cache.d.ts.map +1 -0
  103. package/dist/cache/smart-cache.js +266 -0
  104. package/dist/cache/types.d.ts +102 -0
  105. package/dist/cache/types.d.ts.map +1 -0
  106. package/dist/cache/types.js +6 -0
  107. package/dist/cli/analyze.d.ts +43 -0
  108. package/dist/cli/analyze.d.ts.map +1 -0
  109. package/dist/cli/analyze.js +250 -0
  110. package/dist/cli/doctor.d.ts +2 -0
  111. package/dist/cli/doctor.d.ts.map +1 -0
  112. package/dist/cli/doctor.js +127 -0
  113. package/dist/cli/hooks.d.ts +14 -0
  114. package/dist/cli/hooks.d.ts.map +1 -0
  115. package/dist/cli/hooks.js +229 -0
  116. package/dist/cli/index.d.ts +5 -0
  117. package/dist/cli/index.d.ts.map +1 -0
  118. package/dist/cli/index.js +4 -0
  119. package/dist/cli/setup.d.ts +10 -0
  120. package/dist/cli/setup.d.ts.map +1 -0
  121. package/dist/cli/setup.js +117 -0
  122. package/dist/cli/utils.d.ts +30 -0
  123. package/dist/cli/utils.d.ts.map +1 -0
  124. package/dist/cli/utils.js +116 -0
  125. package/dist/compressors/config.d.ts +9 -0
  126. package/dist/compressors/config.d.ts.map +1 -0
  127. package/dist/compressors/config.js +183 -0
  128. package/dist/compressors/conversation.d.ts +109 -0
  129. package/dist/compressors/conversation.d.ts.map +1 -0
  130. package/dist/compressors/conversation.js +404 -0
  131. package/dist/compressors/diff.d.ts +35 -0
  132. package/dist/compressors/diff.d.ts.map +1 -0
  133. package/dist/compressors/diff.js +389 -0
  134. package/dist/compressors/generic.d.ts +9 -0
  135. package/dist/compressors/generic.d.ts.map +1 -0
  136. package/dist/compressors/generic.js +188 -0
  137. package/dist/compressors/index.d.ts +31 -0
  138. package/dist/compressors/index.d.ts.map +1 -0
  139. package/dist/compressors/index.js +82 -0
  140. package/dist/compressors/logs.d.ts +9 -0
  141. package/dist/compressors/logs.d.ts.map +1 -0
  142. package/dist/compressors/logs.js +245 -0
  143. package/dist/compressors/multifile.d.ts +106 -0
  144. package/dist/compressors/multifile.d.ts.map +1 -0
  145. package/dist/compressors/multifile.js +498 -0
  146. package/dist/compressors/semantic.d.ts +33 -0
  147. package/dist/compressors/semantic.d.ts.map +1 -0
  148. package/dist/compressors/semantic.js +233 -0
  149. package/dist/compressors/stacktrace.d.ts +9 -0
  150. package/dist/compressors/stacktrace.d.ts.map +1 -0
  151. package/dist/compressors/stacktrace.js +259 -0
  152. package/dist/compressors/types.d.ts +146 -0
  153. package/dist/compressors/types.d.ts.map +1 -0
  154. package/dist/compressors/types.js +6 -0
  155. package/dist/config/output-config.d.ts +56 -0
  156. package/dist/config/output-config.d.ts.map +1 -0
  157. package/dist/config/output-config.js +78 -0
  158. package/dist/index.d.ts +21 -0
  159. package/dist/index.d.ts.map +1 -0
  160. package/dist/index.js +27 -0
  161. package/dist/middleware/chain.d.ts +49 -0
  162. package/dist/middleware/chain.d.ts.map +1 -0
  163. package/dist/middleware/chain.js +126 -0
  164. package/dist/middleware/index.d.ts +4 -0
  165. package/dist/middleware/index.d.ts.map +1 -0
  166. package/dist/middleware/index.js +3 -0
  167. package/dist/middleware/logging.d.ts +8 -0
  168. package/dist/middleware/logging.d.ts.map +1 -0
  169. package/dist/middleware/logging.js +71 -0
  170. package/dist/middleware/types.d.ts +58 -0
  171. package/dist/middleware/types.d.ts.map +1 -0
  172. package/dist/middleware/types.js +7 -0
  173. package/dist/parsers/eslint.d.ts +8 -0
  174. package/dist/parsers/eslint.d.ts.map +1 -0
  175. package/dist/parsers/eslint.js +132 -0
  176. package/dist/parsers/generic.d.ts +8 -0
  177. package/dist/parsers/generic.d.ts.map +1 -0
  178. package/dist/parsers/generic.js +234 -0
  179. package/dist/parsers/index.d.ts +34 -0
  180. package/dist/parsers/index.d.ts.map +1 -0
  181. package/dist/parsers/index.js +216 -0
  182. package/dist/parsers/types.d.ts +84 -0
  183. package/dist/parsers/types.d.ts.map +1 -0
  184. package/dist/parsers/types.js +6 -0
  185. package/dist/parsers/typescript.d.ts +8 -0
  186. package/dist/parsers/typescript.d.ts.map +1 -0
  187. package/dist/parsers/typescript.js +107 -0
  188. package/dist/pipelines/definitions.d.ts +50 -0
  189. package/dist/pipelines/definitions.d.ts.map +1 -0
  190. package/dist/pipelines/definitions.js +206 -0
  191. package/dist/sandbox/executor.d.ts +12 -0
  192. package/dist/sandbox/executor.d.ts.map +1 -0
  193. package/dist/sandbox/executor.js +191 -0
  194. package/dist/sandbox/index.d.ts +11 -0
  195. package/dist/sandbox/index.d.ts.map +1 -0
  196. package/dist/sandbox/index.js +9 -0
  197. package/dist/sandbox/sandbox.test.d.ts +7 -0
  198. package/dist/sandbox/sandbox.test.d.ts.map +1 -0
  199. package/dist/sandbox/sandbox.test.js +202 -0
  200. package/dist/sandbox/sdk/analyze.d.ts +36 -0
  201. package/dist/sandbox/sdk/analyze.d.ts.map +1 -0
  202. package/dist/sandbox/sdk/analyze.js +413 -0
  203. package/dist/sandbox/sdk/analyze.test.d.ts +7 -0
  204. package/dist/sandbox/sdk/analyze.test.d.ts.map +1 -0
  205. package/dist/sandbox/sdk/analyze.test.js +191 -0
  206. package/dist/sandbox/sdk/code.d.ts +20 -0
  207. package/dist/sandbox/sdk/code.d.ts.map +1 -0
  208. package/dist/sandbox/sdk/code.js +104 -0
  209. package/dist/sandbox/sdk/compress.d.ts +23 -0
  210. package/dist/sandbox/sdk/compress.d.ts.map +1 -0
  211. package/dist/sandbox/sdk/compress.js +107 -0
  212. package/dist/sandbox/sdk/conversation.d.ts +148 -0
  213. package/dist/sandbox/sdk/conversation.d.ts.map +1 -0
  214. package/dist/sandbox/sdk/conversation.js +177 -0
  215. package/dist/sandbox/sdk/files.d.ts +29 -0
  216. package/dist/sandbox/sdk/files.d.ts.map +1 -0
  217. package/dist/sandbox/sdk/files.js +41 -0
  218. package/dist/sandbox/sdk/git.d.ts +37 -0
  219. package/dist/sandbox/sdk/git.d.ts.map +1 -0
  220. package/dist/sandbox/sdk/git.js +313 -0
  221. package/dist/sandbox/sdk/git.test.d.ts +8 -0
  222. package/dist/sandbox/sdk/git.test.d.ts.map +1 -0
  223. package/dist/sandbox/sdk/git.test.js +160 -0
  224. package/dist/sandbox/sdk/index.d.ts +16 -0
  225. package/dist/sandbox/sdk/index.d.ts.map +1 -0
  226. package/dist/sandbox/sdk/index.js +15 -0
  227. package/dist/sandbox/sdk/multifile.d.ts +63 -0
  228. package/dist/sandbox/sdk/multifile.d.ts.map +1 -0
  229. package/dist/sandbox/sdk/multifile.js +130 -0
  230. package/dist/sandbox/sdk/pipeline.d.ts +16 -0
  231. package/dist/sandbox/sdk/pipeline.d.ts.map +1 -0
  232. package/dist/sandbox/sdk/pipeline.js +454 -0
  233. package/dist/sandbox/sdk/pipeline.test.d.ts +7 -0
  234. package/dist/sandbox/sdk/pipeline.test.d.ts.map +1 -0
  235. package/dist/sandbox/sdk/pipeline.test.js +197 -0
  236. package/dist/sandbox/sdk/search.d.ts +36 -0
  237. package/dist/sandbox/sdk/search.d.ts.map +1 -0
  238. package/dist/sandbox/sdk/search.js +338 -0
  239. package/dist/sandbox/sdk/search.test.d.ts +7 -0
  240. package/dist/sandbox/sdk/search.test.d.ts.map +1 -0
  241. package/dist/sandbox/sdk/search.test.js +183 -0
  242. package/dist/sandbox/sdk/utils.d.ts +18 -0
  243. package/dist/sandbox/sdk/utils.d.ts.map +1 -0
  244. package/dist/sandbox/sdk/utils.js +24 -0
  245. package/dist/sandbox/security/code-analyzer.d.ts +15 -0
  246. package/dist/sandbox/security/code-analyzer.d.ts.map +1 -0
  247. package/dist/sandbox/security/code-analyzer.js +87 -0
  248. package/dist/sandbox/security/index.d.ts +6 -0
  249. package/dist/sandbox/security/index.d.ts.map +1 -0
  250. package/dist/sandbox/security/index.js +5 -0
  251. package/dist/sandbox/security/path-validator.d.ts +23 -0
  252. package/dist/sandbox/security/path-validator.d.ts.map +1 -0
  253. package/dist/sandbox/security/path-validator.js +113 -0
  254. package/dist/sandbox/types.d.ts +577 -0
  255. package/dist/sandbox/types.d.ts.map +1 -0
  256. package/dist/sandbox/types.js +14 -0
  257. package/dist/server.d.ts +36 -0
  258. package/dist/server.d.ts.map +1 -0
  259. package/dist/server.js +133 -0
  260. package/dist/summarizers/build-logs.d.ts +11 -0
  261. package/dist/summarizers/build-logs.d.ts.map +1 -0
  262. package/dist/summarizers/build-logs.js +234 -0
  263. package/dist/summarizers/generic.d.ts +11 -0
  264. package/dist/summarizers/generic.d.ts.map +1 -0
  265. package/dist/summarizers/generic.js +93 -0
  266. package/dist/summarizers/index.d.ts +20 -0
  267. package/dist/summarizers/index.d.ts.map +1 -0
  268. package/dist/summarizers/index.js +43 -0
  269. package/dist/summarizers/server-logs.d.ts +11 -0
  270. package/dist/summarizers/server-logs.d.ts.map +1 -0
  271. package/dist/summarizers/server-logs.js +215 -0
  272. package/dist/summarizers/test-logs.d.ts +11 -0
  273. package/dist/summarizers/test-logs.d.ts.map +1 -0
  274. package/dist/summarizers/test-logs.js +258 -0
  275. package/dist/summarizers/types.d.ts +146 -0
  276. package/dist/summarizers/types.d.ts.map +1 -0
  277. package/dist/summarizers/types.js +21 -0
  278. package/dist/tools/analyze-build-output.d.ts +30 -0
  279. package/dist/tools/analyze-build-output.d.ts.map +1 -0
  280. package/dist/tools/analyze-build-output.js +45 -0
  281. package/dist/tools/analyze-context.d.ts +23 -0
  282. package/dist/tools/analyze-context.d.ts.map +1 -0
  283. package/dist/tools/analyze-context.js +78 -0
  284. package/dist/tools/auto-optimize.d.ts +9 -0
  285. package/dist/tools/auto-optimize.d.ts.map +1 -0
  286. package/dist/tools/auto-optimize.js +191 -0
  287. package/dist/tools/code-execute.d.ts +9 -0
  288. package/dist/tools/code-execute.d.ts.map +1 -0
  289. package/dist/tools/code-execute.js +84 -0
  290. package/dist/tools/code-skeleton.d.ts +33 -0
  291. package/dist/tools/code-skeleton.d.ts.map +1 -0
  292. package/dist/tools/code-skeleton.js +206 -0
  293. package/dist/tools/compress-context.d.ts +33 -0
  294. package/dist/tools/compress-context.d.ts.map +1 -0
  295. package/dist/tools/compress-context.js +64 -0
  296. package/dist/tools/context-budget.d.ts +43 -0
  297. package/dist/tools/context-budget.d.ts.map +1 -0
  298. package/dist/tools/context-budget.js +260 -0
  299. package/dist/tools/context-budget.test.d.ts +5 -0
  300. package/dist/tools/context-budget.test.d.ts.map +1 -0
  301. package/dist/tools/context-budget.test.js +219 -0
  302. package/dist/tools/conversation-compress.d.ts +46 -0
  303. package/dist/tools/conversation-compress.d.ts.map +1 -0
  304. package/dist/tools/conversation-compress.js +78 -0
  305. package/dist/tools/conversation-memory.d.ts +75 -0
  306. package/dist/tools/conversation-memory.d.ts.map +1 -0
  307. package/dist/tools/conversation-memory.js +289 -0
  308. package/dist/tools/deduplicate-errors.d.ts +30 -0
  309. package/dist/tools/deduplicate-errors.d.ts.map +1 -0
  310. package/dist/tools/deduplicate-errors.js +72 -0
  311. package/dist/tools/detect-retry-loop.d.ts +40 -0
  312. package/dist/tools/detect-retry-loop.d.ts.map +1 -0
  313. package/dist/tools/detect-retry-loop.js +212 -0
  314. package/dist/tools/diff-compress.d.ts +40 -0
  315. package/dist/tools/diff-compress.d.ts.map +1 -0
  316. package/dist/tools/diff-compress.js +94 -0
  317. package/dist/tools/discover-tools.d.ts +11 -0
  318. package/dist/tools/discover-tools.d.ts.map +1 -0
  319. package/dist/tools/discover-tools.js +163 -0
  320. package/dist/tools/dynamic-loader.d.ts +131 -0
  321. package/dist/tools/dynamic-loader.d.ts.map +1 -0
  322. package/dist/tools/dynamic-loader.js +378 -0
  323. package/dist/tools/dynamic-loader.test.d.ts +10 -0
  324. package/dist/tools/dynamic-loader.test.d.ts.map +1 -0
  325. package/dist/tools/dynamic-loader.test.js +164 -0
  326. package/dist/tools/lazy-mcp.d.ts +31 -0
  327. package/dist/tools/lazy-mcp.d.ts.map +1 -0
  328. package/dist/tools/lazy-mcp.js +151 -0
  329. package/dist/tools/lazy-mcp.test.d.ts +10 -0
  330. package/dist/tools/lazy-mcp.test.d.ts.map +1 -0
  331. package/dist/tools/lazy-mcp.test.js +172 -0
  332. package/dist/tools/multifile-compress.d.ts +36 -0
  333. package/dist/tools/multifile-compress.d.ts.map +1 -0
  334. package/dist/tools/multifile-compress.js +223 -0
  335. package/dist/tools/optimization-tips.d.ts +18 -0
  336. package/dist/tools/optimization-tips.d.ts.map +1 -0
  337. package/dist/tools/optimization-tips.js +133 -0
  338. package/dist/tools/registry.d.ts +70 -0
  339. package/dist/tools/registry.d.ts.map +1 -0
  340. package/dist/tools/registry.js +169 -0
  341. package/dist/tools/semantic-compress.d.ts +39 -0
  342. package/dist/tools/semantic-compress.d.ts.map +1 -0
  343. package/dist/tools/semantic-compress.js +113 -0
  344. package/dist/tools/semantic-compress.test.d.ts +5 -0
  345. package/dist/tools/semantic-compress.test.d.ts.map +1 -0
  346. package/dist/tools/semantic-compress.test.js +182 -0
  347. package/dist/tools/session-stats.d.ts +34 -0
  348. package/dist/tools/session-stats.d.ts.map +1 -0
  349. package/dist/tools/session-stats.js +194 -0
  350. package/dist/tools/set-output-config.d.ts +38 -0
  351. package/dist/tools/set-output-config.d.ts.map +1 -0
  352. package/dist/tools/set-output-config.js +122 -0
  353. package/dist/tools/smart-cache-tool.d.ts +38 -0
  354. package/dist/tools/smart-cache-tool.d.ts.map +1 -0
  355. package/dist/tools/smart-cache-tool.js +224 -0
  356. package/dist/tools/smart-file-read.d.ts +52 -0
  357. package/dist/tools/smart-file-read.d.ts.map +1 -0
  358. package/dist/tools/smart-file-read.js +481 -0
  359. package/dist/tools/smart-pipeline.d.ts +40 -0
  360. package/dist/tools/smart-pipeline.d.ts.map +1 -0
  361. package/dist/tools/smart-pipeline.js +295 -0
  362. package/dist/tools/summarize-logs.d.ts +36 -0
  363. package/dist/tools/summarize-logs.d.ts.map +1 -0
  364. package/dist/tools/summarize-logs.js +184 -0
  365. package/dist/tools/token-budget.test.d.ts +11 -0
  366. package/dist/tools/token-budget.test.d.ts.map +1 -0
  367. package/dist/tools/token-budget.test.js +275 -0
  368. package/dist/utils/bm25.d.ts +86 -0
  369. package/dist/utils/bm25.d.ts.map +1 -0
  370. package/dist/utils/bm25.js +153 -0
  371. package/dist/utils/bm25.test.d.ts +5 -0
  372. package/dist/utils/bm25.test.d.ts.map +1 -0
  373. package/dist/utils/bm25.test.js +156 -0
  374. package/dist/utils/command-normalizer.d.ts +39 -0
  375. package/dist/utils/command-normalizer.d.ts.map +1 -0
  376. package/dist/utils/command-normalizer.js +90 -0
  377. package/dist/utils/content-detector.d.ts +27 -0
  378. package/dist/utils/content-detector.d.ts.map +1 -0
  379. package/dist/utils/content-detector.js +127 -0
  380. package/dist/utils/embeddings.d.ts +54 -0
  381. package/dist/utils/embeddings.d.ts.map +1 -0
  382. package/dist/utils/embeddings.js +97 -0
  383. package/dist/utils/embeddings.test.d.ts +8 -0
  384. package/dist/utils/embeddings.test.d.ts.map +1 -0
  385. package/dist/utils/embeddings.test.js +96 -0
  386. package/dist/utils/error-normalizer.d.ts +39 -0
  387. package/dist/utils/error-normalizer.d.ts.map +1 -0
  388. package/dist/utils/error-normalizer.js +233 -0
  389. package/dist/utils/hybrid-search.d.ts +79 -0
  390. package/dist/utils/hybrid-search.d.ts.map +1 -0
  391. package/dist/utils/hybrid-search.js +146 -0
  392. package/dist/utils/hybrid-search.test.d.ts +5 -0
  393. package/dist/utils/hybrid-search.test.d.ts.map +1 -0
  394. package/dist/utils/hybrid-search.test.js +172 -0
  395. package/dist/utils/index.d.ts +13 -0
  396. package/dist/utils/index.d.ts.map +1 -0
  397. package/dist/utils/index.js +12 -0
  398. package/dist/utils/language-detector.d.ts +27 -0
  399. package/dist/utils/language-detector.d.ts.map +1 -0
  400. package/dist/utils/language-detector.js +94 -0
  401. package/dist/utils/log-parser.d.ts +46 -0
  402. package/dist/utils/log-parser.d.ts.map +1 -0
  403. package/dist/utils/log-parser.js +287 -0
  404. package/dist/utils/output-estimator.d.ts +54 -0
  405. package/dist/utils/output-estimator.d.ts.map +1 -0
  406. package/dist/utils/output-estimator.js +119 -0
  407. package/dist/utils/output-estimator.test.d.ts +5 -0
  408. package/dist/utils/output-estimator.test.d.ts.map +1 -0
  409. package/dist/utils/output-estimator.test.js +115 -0
  410. package/dist/utils/output-similarity.d.ts +48 -0
  411. package/dist/utils/output-similarity.d.ts.map +1 -0
  412. package/dist/utils/output-similarity.js +140 -0
  413. package/dist/utils/project-detector.d.ts +16 -0
  414. package/dist/utils/project-detector.d.ts.map +1 -0
  415. package/dist/utils/project-detector.js +119 -0
  416. package/dist/utils/segment-scorer.d.ts +99 -0
  417. package/dist/utils/segment-scorer.d.ts.map +1 -0
  418. package/dist/utils/segment-scorer.js +148 -0
  419. package/dist/utils/signature-grouper.d.ts +58 -0
  420. package/dist/utils/signature-grouper.d.ts.map +1 -0
  421. package/dist/utils/signature-grouper.js +185 -0
  422. package/dist/utils/tfidf.d.ts +45 -0
  423. package/dist/utils/tfidf.d.ts.map +1 -0
  424. package/dist/utils/tfidf.js +204 -0
  425. package/dist/utils/tfidf.test.d.ts +5 -0
  426. package/dist/utils/tfidf.test.d.ts.map +1 -0
  427. package/dist/utils/tfidf.test.js +115 -0
  428. package/dist/utils/token-counter.d.ts +35 -0
  429. package/dist/utils/token-counter.d.ts.map +1 -0
  430. package/dist/utils/token-counter.js +83 -0
  431. package/dist/utils/toon-serializer.d.ts +120 -0
  432. package/dist/utils/toon-serializer.d.ts.map +1 -0
  433. package/dist/utils/toon-serializer.js +472 -0
  434. package/dist/utils/toon-serializer.test.d.ts +7 -0
  435. package/dist/utils/toon-serializer.test.d.ts.map +1 -0
  436. package/dist/utils/toon-serializer.test.js +290 -0
  437. package/package.json +63 -0
  438. package/scripts/install.ps1 +133 -0
  439. package/scripts/install.sh +183 -0
  440. package/scripts/pre-commit-hook.sh +86 -0
@@ -0,0 +1,428 @@
1
+ /**
2
+ * Go Tree-sitter Parser
3
+ *
4
+ * AST parser for Go using Tree-sitter for accurate code analysis.
5
+ */
6
+ import Parser from "web-tree-sitter";
7
+ import { readFileSync } from "fs";
8
+ import { createRequire } from "module";
9
+ import { join, dirname } from "path";
10
+ import { fileURLToPath } from "url";
11
+ import { createEmptyStructure } from "../types.js";
12
+ import { extractGoDoc, getFunctionSignature, getMethodSignature, getTypeSignature, isExported, getReceiverType, createCodeElement, getImportPath, getImportName, getImportAlias, } from "./utils.js";
13
+ // Singleton for lazy initialization
14
+ let parserInstance = null;
15
+ let goLanguage = null;
16
+ let initPromise = null;
17
+ /**
18
+ * Get the path to the Go WASM file
19
+ */
20
+ function getGoWasmPath() {
21
+ const require = createRequire(import.meta.url);
22
+ try {
23
+ const wasmDir = dirname(require.resolve("tree-sitter-wasms/package.json"));
24
+ return join(wasmDir, "out", "tree-sitter-go.wasm");
25
+ }
26
+ catch {
27
+ const __dirname = dirname(fileURLToPath(import.meta.url));
28
+ return join(__dirname, "..", "..", "..", "node_modules", "tree-sitter-wasms", "out", "tree-sitter-go.wasm");
29
+ }
30
+ }
31
+ /**
32
+ * Initialize Tree-sitter and load Go language
33
+ */
34
+ async function initParser() {
35
+ if (parserInstance && goLanguage)
36
+ return;
37
+ if (initPromise) {
38
+ await initPromise;
39
+ return;
40
+ }
41
+ initPromise = (async () => {
42
+ await Parser.init();
43
+ parserInstance = new Parser();
44
+ const wasmPath = getGoWasmPath();
45
+ // Read WASM file as buffer for reliable loading in all environments
46
+ const wasmBuffer = readFileSync(wasmPath);
47
+ goLanguage = await Parser.Language.load(wasmBuffer);
48
+ parserInstance.setLanguage(goLanguage);
49
+ })();
50
+ await initPromise;
51
+ }
52
+ /**
53
+ * Check if a node is at package level
54
+ */
55
+ function isPackageLevel(node) {
56
+ return node.parent?.type === "source_file";
57
+ }
58
+ /**
59
+ * Parse Go content and extract structure
60
+ */
61
+ export function parseGo(content) {
62
+ if (!parserInstance || !goLanguage) {
63
+ initParser().catch(() => { });
64
+ return createEmptyStructure("go", content.split("\n").length);
65
+ }
66
+ const tree = parserInstance.parse(content);
67
+ if (!tree) {
68
+ return createEmptyStructure("go", content.split("\n").length);
69
+ }
70
+ return extractStructure(tree, content);
71
+ }
72
+ /**
73
+ * Async version of parseGo
74
+ */
75
+ export async function parseGoAsync(content) {
76
+ await initParser();
77
+ if (!parserInstance) {
78
+ return createEmptyStructure("go", content.split("\n").length);
79
+ }
80
+ const tree = parserInstance.parse(content);
81
+ if (!tree) {
82
+ return createEmptyStructure("go", content.split("\n").length);
83
+ }
84
+ return extractStructure(tree, content);
85
+ }
86
+ /**
87
+ * Extract file structure from parsed tree
88
+ */
89
+ function extractStructure(tree, content) {
90
+ const lines = content.split("\n");
91
+ const structure = createEmptyStructure("go", lines.length);
92
+ const rootNode = tree.rootNode;
93
+ walkNode(rootNode, structure, lines);
94
+ return structure;
95
+ }
96
+ /**
97
+ * Recursively walk the AST and extract code elements
98
+ */
99
+ function walkNode(node, structure, lines) {
100
+ switch (node.type) {
101
+ case "import_declaration": {
102
+ // Handle both single and grouped imports
103
+ for (const child of node.namedChildren) {
104
+ if (child.type === "import_spec") {
105
+ processImportSpec(child, structure);
106
+ }
107
+ else if (child.type === "import_spec_list") {
108
+ for (const spec of child.namedChildren) {
109
+ if (spec.type === "import_spec") {
110
+ processImportSpec(spec, structure);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ return;
116
+ }
117
+ case "function_declaration": {
118
+ const nameNode = node.childForFieldName("name");
119
+ const name = nameNode?.text ?? "unknown";
120
+ structure.functions.push(createCodeElement("function", name, node, {
121
+ signature: getFunctionSignature(node),
122
+ documentation: extractGoDoc(node, lines),
123
+ isExported: isExported(name),
124
+ }));
125
+ return;
126
+ }
127
+ case "method_declaration": {
128
+ const nameNode = node.childForFieldName("name");
129
+ const name = nameNode?.text ?? "unknown";
130
+ const receiverType = getReceiverType(node);
131
+ structure.functions.push(createCodeElement("method", name, node, {
132
+ signature: getMethodSignature(node),
133
+ documentation: extractGoDoc(node, lines),
134
+ isExported: isExported(name),
135
+ parent: receiverType,
136
+ }));
137
+ return;
138
+ }
139
+ case "type_declaration": {
140
+ // Process type specs inside
141
+ for (const child of node.namedChildren) {
142
+ if (child.type === "type_spec") {
143
+ processTypeSpec(child, structure, lines);
144
+ }
145
+ }
146
+ return;
147
+ }
148
+ case "var_declaration": {
149
+ if (isPackageLevel(node)) {
150
+ for (const child of node.namedChildren) {
151
+ if (child.type === "var_spec") {
152
+ const nameNode = child.childForFieldName("name");
153
+ const name = nameNode?.text ?? "";
154
+ if (name) {
155
+ structure.variables.push(createCodeElement("variable", name, node, {
156
+ signature: `var ${name}`,
157
+ documentation: extractGoDoc(node, lines),
158
+ isExported: isExported(name),
159
+ }));
160
+ }
161
+ }
162
+ }
163
+ }
164
+ return;
165
+ }
166
+ case "const_declaration": {
167
+ if (isPackageLevel(node)) {
168
+ for (const child of node.namedChildren) {
169
+ if (child.type === "const_spec") {
170
+ const nameNode = child.childForFieldName("name");
171
+ const name = nameNode?.text ?? "";
172
+ if (name) {
173
+ structure.variables.push(createCodeElement("variable", name, node, {
174
+ signature: `const ${name}`,
175
+ documentation: extractGoDoc(node, lines),
176
+ isExported: isExported(name),
177
+ }));
178
+ }
179
+ }
180
+ }
181
+ }
182
+ return;
183
+ }
184
+ }
185
+ // Walk children
186
+ for (const child of node.children) {
187
+ walkNode(child, structure, lines);
188
+ }
189
+ }
190
+ /**
191
+ * Process an import spec
192
+ */
193
+ function processImportSpec(node, structure) {
194
+ const importPath = getImportPath(node);
195
+ const alias = getImportAlias(node);
196
+ const name = alias ?? getImportName(importPath);
197
+ structure.imports.push(createCodeElement("import", name, node, {
198
+ signature: alias ? `import ${alias} "${importPath}"` : `import "${importPath}"`,
199
+ }));
200
+ }
201
+ /**
202
+ * Process a type spec (struct, interface, alias)
203
+ */
204
+ function processTypeSpec(node, structure, lines) {
205
+ const nameNode = node.childForFieldName("name");
206
+ const typeNode = node.childForFieldName("type");
207
+ const name = nameNode?.text ?? "unknown";
208
+ if (!typeNode)
209
+ return;
210
+ if (typeNode.type === "struct_type") {
211
+ structure.classes.push(createCodeElement("class", name, node, {
212
+ signature: getTypeSignature(node, "struct"),
213
+ documentation: extractGoDoc(node.parent ?? node, lines),
214
+ isExported: isExported(name),
215
+ }));
216
+ }
217
+ else if (typeNode.type === "interface_type") {
218
+ structure.interfaces.push(createCodeElement("interface", name, node, {
219
+ signature: getTypeSignature(node, "interface"),
220
+ documentation: extractGoDoc(node.parent ?? node, lines),
221
+ isExported: isExported(name),
222
+ }));
223
+ }
224
+ else {
225
+ // Type alias
226
+ structure.types.push(createCodeElement("type", name, node, {
227
+ signature: `type ${name} ${typeNode.text}`,
228
+ documentation: extractGoDoc(node.parent ?? node, lines),
229
+ isExported: isExported(name),
230
+ }));
231
+ }
232
+ }
233
+ /**
234
+ * Extract a specific element from Go code
235
+ */
236
+ export async function extractGoElement(content, target, options) {
237
+ const structure = await parseGoAsync(content);
238
+ let element;
239
+ switch (target.type) {
240
+ case "function":
241
+ case "method":
242
+ element = structure.functions.find((f) => f.name === target.name);
243
+ break;
244
+ case "class":
245
+ element = structure.classes.find((c) => c.name === target.name);
246
+ break;
247
+ case "interface":
248
+ element = structure.interfaces.find((i) => i.name === target.name);
249
+ break;
250
+ case "type":
251
+ element = structure.types.find((t) => t.name === target.name);
252
+ break;
253
+ case "variable":
254
+ element = structure.variables.find((v) => v.name === target.name);
255
+ break;
256
+ }
257
+ if (!element) {
258
+ return null;
259
+ }
260
+ const lines = content.split("\n");
261
+ // Find start line (include documentation if requested)
262
+ let startLine = element.startLine;
263
+ if (options.includeComments && element.documentation) {
264
+ for (let i = element.startLine - 2; i >= 0; i--) {
265
+ const line = lines[i]?.trim() ?? "";
266
+ if (line.startsWith("//")) {
267
+ startLine = i + 1;
268
+ }
269
+ else if (line === "") {
270
+ continue;
271
+ }
272
+ else {
273
+ break;
274
+ }
275
+ }
276
+ }
277
+ const extractedLines = lines.slice(startLine - 1, element.endLine);
278
+ const extractedCode = extractedLines.join("\n");
279
+ // Find related imports
280
+ const relatedImports = [];
281
+ if (options.includeImports) {
282
+ for (const imp of structure.imports) {
283
+ if (extractedCode.includes(imp.name)) {
284
+ const importLine = lines[imp.startLine - 1];
285
+ if (importLine && !relatedImports.includes(importLine)) {
286
+ relatedImports.push(importLine);
287
+ }
288
+ }
289
+ }
290
+ }
291
+ return {
292
+ content: extractedCode,
293
+ elements: [element],
294
+ relatedImports,
295
+ startLine,
296
+ endLine: element.endLine,
297
+ };
298
+ }
299
+ /**
300
+ * Search for elements matching a query
301
+ */
302
+ export async function searchGoElements(content, query) {
303
+ const structure = await parseGoAsync(content);
304
+ const queryLower = query.toLowerCase();
305
+ const results = [];
306
+ const allElements = [
307
+ ...structure.functions,
308
+ ...structure.classes,
309
+ ...structure.interfaces,
310
+ ...structure.types,
311
+ ...structure.variables,
312
+ ];
313
+ for (const element of allElements) {
314
+ if (element.name.toLowerCase().includes(queryLower) ||
315
+ element.signature?.toLowerCase().includes(queryLower) ||
316
+ element.documentation?.toLowerCase().includes(queryLower)) {
317
+ results.push(element);
318
+ }
319
+ }
320
+ return results;
321
+ }
322
+ /**
323
+ * LanguageParser implementation for Go
324
+ */
325
+ export const goTreeSitterParser = {
326
+ languages: ["go"],
327
+ parse(content, _options) {
328
+ if (!parserInstance || !goLanguage) {
329
+ initParser().catch(() => { });
330
+ return parseGo(content);
331
+ }
332
+ return parseGo(content);
333
+ },
334
+ extractElement(content, target, options) {
335
+ if (!parserInstance || !goLanguage) {
336
+ initParser().catch(() => { });
337
+ return null;
338
+ }
339
+ const structure = parseGo(content);
340
+ let element;
341
+ switch (target.type) {
342
+ case "function":
343
+ case "method":
344
+ element = structure.functions.find((f) => f.name === target.name);
345
+ break;
346
+ case "class":
347
+ element = structure.classes.find((c) => c.name === target.name);
348
+ break;
349
+ case "interface":
350
+ element = structure.interfaces.find((i) => i.name === target.name);
351
+ break;
352
+ case "type":
353
+ element = structure.types.find((t) => t.name === target.name);
354
+ break;
355
+ case "variable":
356
+ element = structure.variables.find((v) => v.name === target.name);
357
+ break;
358
+ }
359
+ if (!element)
360
+ return null;
361
+ const lines = content.split("\n");
362
+ let startLine = element.startLine;
363
+ if (options.includeComments && element.documentation) {
364
+ for (let i = element.startLine - 2; i >= 0; i--) {
365
+ const line = lines[i]?.trim() ?? "";
366
+ if (line.startsWith("//")) {
367
+ startLine = i + 1;
368
+ }
369
+ else if (line === "") {
370
+ continue;
371
+ }
372
+ else {
373
+ break;
374
+ }
375
+ }
376
+ }
377
+ const extractedLines = lines.slice(startLine - 1, element.endLine);
378
+ const extractedCode = extractedLines.join("\n");
379
+ const relatedImports = [];
380
+ if (options.includeImports) {
381
+ for (const imp of structure.imports) {
382
+ if (extractedCode.includes(imp.name)) {
383
+ const importLine = lines[imp.startLine - 1];
384
+ if (importLine && !relatedImports.includes(importLine)) {
385
+ relatedImports.push(importLine);
386
+ }
387
+ }
388
+ }
389
+ }
390
+ return {
391
+ content: extractedCode,
392
+ elements: [element],
393
+ relatedImports,
394
+ startLine,
395
+ endLine: element.endLine,
396
+ };
397
+ },
398
+ searchElements(content, query) {
399
+ if (!parserInstance || !goLanguage) {
400
+ initParser().catch(() => { });
401
+ return [];
402
+ }
403
+ const structure = parseGo(content);
404
+ const queryLower = query.toLowerCase();
405
+ const results = [];
406
+ const allElements = [
407
+ ...structure.functions,
408
+ ...structure.classes,
409
+ ...structure.interfaces,
410
+ ...structure.types,
411
+ ...structure.variables,
412
+ ];
413
+ for (const element of allElements) {
414
+ if (element.name.toLowerCase().includes(queryLower) ||
415
+ element.signature?.toLowerCase().includes(queryLower) ||
416
+ element.documentation?.toLowerCase().includes(queryLower)) {
417
+ results.push(element);
418
+ }
419
+ }
420
+ return results;
421
+ },
422
+ };
423
+ /**
424
+ * Initialize the Go parser
425
+ */
426
+ export async function initGoParser() {
427
+ await initParser();
428
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Go Tree-sitter Parser Tests
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=parser.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.test.d.ts","sourceRoot":"","sources":["../../../src/ast/go/parser.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Go Tree-sitter Parser Tests
3
+ */
4
+ import { describe, it, expect, beforeAll } from "vitest";
5
+ import { goTreeSitterParser, parseGoAsync, initGoParser, } from "./parser.js";
6
+ // Sample Go code for testing
7
+ const SAMPLE_GO = `
8
+ package main
9
+
10
+ import (
11
+ "fmt"
12
+ "net/http"
13
+ "encoding/json"
14
+ )
15
+
16
+ // MaxSize is the maximum allowed size
17
+ const MaxSize = 100
18
+
19
+ // Debug enables debug mode
20
+ var Debug = false
21
+
22
+ // User represents a user in the system
23
+ type User struct {
24
+ Name string
25
+ Age int
26
+ }
27
+
28
+ // Greet returns a greeting message
29
+ func (u *User) Greet() string {
30
+ return fmt.Sprintf("Hello, %s!", u.Name)
31
+ }
32
+
33
+ // FetchData fetches user data
34
+ func (u User) FetchData() map[string]interface{} {
35
+ return map[string]interface{}{
36
+ "name": u.Name,
37
+ "age": u.Age,
38
+ }
39
+ }
40
+
41
+ // AdminUser is a user with admin privileges
42
+ type AdminUser struct {
43
+ User
44
+ Permissions []string
45
+ }
46
+
47
+ // HasPermission checks if admin has a permission
48
+ func (a *AdminUser) HasPermission(perm string) bool {
49
+ for _, p := range a.Permissions {
50
+ if p == perm {
51
+ return true
52
+ }
53
+ }
54
+ return false
55
+ }
56
+
57
+ // Handler defines HTTP handler interface
58
+ type Handler interface {
59
+ ServeHTTP(w http.ResponseWriter, r *http.Request)
60
+ }
61
+
62
+ // CalculateSum calculates the sum of numbers
63
+ func CalculateSum(numbers []int) int {
64
+ sum := 0
65
+ for _, n := range numbers {
66
+ sum += n
67
+ }
68
+ return sum
69
+ }
70
+
71
+ // privateFunc is unexported
72
+ func privateFunc() {
73
+ // internal function
74
+ }
75
+
76
+ // main is the entry point
77
+ func main() {
78
+ fmt.Println("Hello, World!")
79
+ }
80
+ `;
81
+ describe("Go Tree-sitter Parser", () => {
82
+ beforeAll(async () => {
83
+ await initGoParser();
84
+ });
85
+ describe("parseGoAsync", () => {
86
+ it("should parse imports correctly", async () => {
87
+ const structure = await parseGoAsync(SAMPLE_GO);
88
+ expect(structure.language).toBe("go");
89
+ expect(structure.imports.length).toBeGreaterThanOrEqual(3);
90
+ const importNames = structure.imports.map((i) => i.name);
91
+ expect(importNames).toContain("fmt");
92
+ expect(importNames).toContain("http");
93
+ expect(importNames).toContain("json");
94
+ });
95
+ it("should parse functions correctly", async () => {
96
+ const structure = await parseGoAsync(SAMPLE_GO);
97
+ const funcNames = structure.functions.map((f) => f.name);
98
+ expect(funcNames).toContain("CalculateSum");
99
+ expect(funcNames).toContain("privateFunc");
100
+ expect(funcNames).toContain("main");
101
+ });
102
+ it("should detect exported functions", async () => {
103
+ const structure = await parseGoAsync(SAMPLE_GO);
104
+ const calcSum = structure.functions.find((f) => f.name === "CalculateSum");
105
+ expect(calcSum?.isExported).toBe(true);
106
+ const privateFunc = structure.functions.find((f) => f.name === "privateFunc");
107
+ expect(privateFunc?.isExported).toBe(false);
108
+ });
109
+ it("should parse methods correctly", async () => {
110
+ const structure = await parseGoAsync(SAMPLE_GO);
111
+ const methods = structure.functions.filter((f) => f.type === "method");
112
+ expect(methods.length).toBeGreaterThanOrEqual(3);
113
+ const methodNames = methods.map((m) => m.name);
114
+ expect(methodNames).toContain("Greet");
115
+ expect(methodNames).toContain("FetchData");
116
+ expect(methodNames).toContain("HasPermission");
117
+ });
118
+ it("should track receiver type for methods", async () => {
119
+ const structure = await parseGoAsync(SAMPLE_GO);
120
+ const greet = structure.functions.find((f) => f.name === "Greet");
121
+ expect(greet?.parent).toBe("User");
122
+ const hasPermission = structure.functions.find((f) => f.name === "HasPermission");
123
+ expect(hasPermission?.parent).toBe("AdminUser");
124
+ });
125
+ it("should parse structs as classes", async () => {
126
+ const structure = await parseGoAsync(SAMPLE_GO);
127
+ expect(structure.classes.length).toBeGreaterThanOrEqual(2);
128
+ const classNames = structure.classes.map((c) => c.name);
129
+ expect(classNames).toContain("User");
130
+ expect(classNames).toContain("AdminUser");
131
+ });
132
+ it("should detect exported structs", async () => {
133
+ const structure = await parseGoAsync(SAMPLE_GO);
134
+ const user = structure.classes.find((c) => c.name === "User");
135
+ expect(user?.isExported).toBe(true);
136
+ });
137
+ it("should parse interfaces", async () => {
138
+ const structure = await parseGoAsync(SAMPLE_GO);
139
+ expect(structure.interfaces.length).toBeGreaterThanOrEqual(1);
140
+ const interfaceNames = structure.interfaces.map((i) => i.name);
141
+ expect(interfaceNames).toContain("Handler");
142
+ });
143
+ it("should extract doc comments", async () => {
144
+ const structure = await parseGoAsync(SAMPLE_GO);
145
+ const userStruct = structure.classes.find((c) => c.name === "User");
146
+ expect(userStruct?.documentation).toContain("represents a user");
147
+ const calcSum = structure.functions.find((f) => f.name === "CalculateSum");
148
+ expect(calcSum?.documentation).toContain("calculates the sum");
149
+ });
150
+ it("should parse package-level variables", async () => {
151
+ const structure = await parseGoAsync(SAMPLE_GO);
152
+ const varNames = structure.variables.map((v) => v.name);
153
+ expect(varNames).toContain("Debug");
154
+ });
155
+ it("should parse constants", async () => {
156
+ const structure = await parseGoAsync(SAMPLE_GO);
157
+ const varNames = structure.variables.map((v) => v.name);
158
+ expect(varNames).toContain("MaxSize");
159
+ });
160
+ it("should return correct line numbers", async () => {
161
+ const structure = await parseGoAsync(SAMPLE_GO);
162
+ const userStruct = structure.classes.find((c) => c.name === "User");
163
+ expect(userStruct?.startLine).toBeGreaterThan(0);
164
+ expect(userStruct?.endLine).toBeGreaterThan(userStruct?.startLine ?? 0);
165
+ });
166
+ });
167
+ describe("LanguageParser interface", () => {
168
+ it("should implement parse() method", () => {
169
+ const structure = goTreeSitterParser.parse(SAMPLE_GO);
170
+ expect(structure).toBeDefined();
171
+ expect(structure.language).toBe("go");
172
+ });
173
+ it("should implement extractElement() method", async () => {
174
+ await initGoParser();
175
+ const result = goTreeSitterParser.extractElement(SAMPLE_GO, { type: "function", name: "CalculateSum" }, { includeImports: true, includeComments: true });
176
+ expect(result).not.toBeNull();
177
+ expect(result?.content).toContain("func CalculateSum");
178
+ expect(result?.elements[0]?.name).toBe("CalculateSum");
179
+ });
180
+ it("should extract methods by name", async () => {
181
+ await initGoParser();
182
+ const result = goTreeSitterParser.extractElement(SAMPLE_GO, { type: "method", name: "Greet" }, { includeImports: false, includeComments: true });
183
+ expect(result).not.toBeNull();
184
+ expect(result?.content).toContain("func (u *User) Greet");
185
+ });
186
+ it("should implement searchElements() method", async () => {
187
+ await initGoParser();
188
+ const results = goTreeSitterParser.searchElements(SAMPLE_GO, "user");
189
+ expect(results.length).toBeGreaterThan(0);
190
+ const names = results.map((r) => r.name.toLowerCase());
191
+ expect(names.some((n) => n.includes("user"))).toBe(true);
192
+ });
193
+ it("should return null for non-existent elements", async () => {
194
+ await initGoParser();
195
+ const result = goTreeSitterParser.extractElement(SAMPLE_GO, { type: "function", name: "NonExistentFunc" }, { includeImports: false, includeComments: false });
196
+ expect(result).toBeNull();
197
+ });
198
+ });
199
+ describe("Edge cases", () => {
200
+ it("should handle empty content", async () => {
201
+ const structure = await parseGoAsync("");
202
+ expect(structure.language).toBe("go");
203
+ expect(structure.totalLines).toBe(1);
204
+ expect(structure.functions).toHaveLength(0);
205
+ });
206
+ it("should handle single import", async () => {
207
+ const code = `
208
+ package main
209
+
210
+ import "fmt"
211
+
212
+ func main() {}
213
+ `;
214
+ const structure = await parseGoAsync(code);
215
+ expect(structure.imports.length).toBeGreaterThanOrEqual(1);
216
+ });
217
+ it("should handle import with alias", async () => {
218
+ const code = `
219
+ package main
220
+
221
+ import (
222
+ f "fmt"
223
+ . "strings"
224
+ _ "database/sql"
225
+ )
226
+ `;
227
+ const structure = await parseGoAsync(code);
228
+ expect(structure.imports.length).toBeGreaterThanOrEqual(3);
229
+ });
230
+ it("should handle type aliases", async () => {
231
+ const code = `
232
+ package main
233
+
234
+ type MyInt int
235
+ type MyString = string
236
+ `;
237
+ const structure = await parseGoAsync(code);
238
+ expect(structure.types.length).toBeGreaterThanOrEqual(1);
239
+ });
240
+ });
241
+ });