symbiote-cli 0.1.0

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 (451) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bin/symbiote.d.ts +3 -0
  3. package/dist/bin/symbiote.d.ts.map +1 -0
  4. package/dist/bin/symbiote.js +202 -0
  5. package/dist/bin/symbiote.js.map +1 -0
  6. package/dist/bin/synapse.d.ts +3 -0
  7. package/dist/bin/synapse.d.ts.map +1 -0
  8. package/dist/bin/synapse.js +369 -0
  9. package/dist/bin/synapse.js.map +1 -0
  10. package/dist/src/brain/embeddings.d.ts +9 -0
  11. package/dist/src/brain/embeddings.d.ts.map +1 -0
  12. package/dist/src/brain/embeddings.js +24 -0
  13. package/dist/src/brain/embeddings.js.map +1 -0
  14. package/dist/src/brain/health/constraint-checker.d.ts +16 -0
  15. package/dist/src/brain/health/constraint-checker.d.ts.map +1 -0
  16. package/dist/src/brain/health/constraint-checker.js +93 -0
  17. package/dist/src/brain/health/constraint-checker.js.map +1 -0
  18. package/dist/src/brain/health/coupling-analyzer.d.ts +9 -0
  19. package/dist/src/brain/health/coupling-analyzer.d.ts.map +1 -0
  20. package/dist/src/brain/health/coupling-analyzer.js +105 -0
  21. package/dist/src/brain/health/coupling-analyzer.js.map +1 -0
  22. package/dist/src/brain/health/cycle-detector.d.ts +12 -0
  23. package/dist/src/brain/health/cycle-detector.d.ts.map +1 -0
  24. package/dist/src/brain/health/cycle-detector.js +79 -0
  25. package/dist/src/brain/health/cycle-detector.js.map +1 -0
  26. package/dist/src/brain/health/dead-code-detector.d.ts +9 -0
  27. package/dist/src/brain/health/dead-code-detector.d.ts.map +1 -0
  28. package/dist/src/brain/health/dead-code-detector.js +72 -0
  29. package/dist/src/brain/health/dead-code-detector.js.map +1 -0
  30. package/dist/src/brain/health/history.d.ts +21 -0
  31. package/dist/src/brain/health/history.d.ts.map +1 -0
  32. package/dist/src/brain/health/history.js +35 -0
  33. package/dist/src/brain/health/history.js.map +1 -0
  34. package/dist/src/brain/health/index.d.ts +25 -0
  35. package/dist/src/brain/health/index.d.ts.map +1 -0
  36. package/dist/src/brain/health/index.js +76 -0
  37. package/dist/src/brain/health/index.js.map +1 -0
  38. package/dist/src/brain/health/scorer.d.ts +19 -0
  39. package/dist/src/brain/health/scorer.d.ts.map +1 -0
  40. package/dist/src/brain/health/scorer.js +47 -0
  41. package/dist/src/brain/health/scorer.js.map +1 -0
  42. package/dist/src/brain/health/types.d.ts +67 -0
  43. package/dist/src/brain/health/types.d.ts.map +1 -0
  44. package/dist/src/brain/health/types.js +2 -0
  45. package/dist/src/brain/health/types.js.map +1 -0
  46. package/dist/src/brain/health.d.ts +30 -0
  47. package/dist/src/brain/health.d.ts.map +1 -0
  48. package/dist/src/brain/health.js +147 -0
  49. package/dist/src/brain/health.js.map +1 -0
  50. package/dist/src/brain/index.d.ts +3 -0
  51. package/dist/src/brain/index.d.ts.map +1 -0
  52. package/dist/src/brain/index.js +3 -0
  53. package/dist/src/brain/index.js.map +1 -0
  54. package/dist/src/brain/intent.d.ts +31 -0
  55. package/dist/src/brain/intent.d.ts.map +1 -0
  56. package/dist/src/brain/intent.js +120 -0
  57. package/dist/src/brain/intent.js.map +1 -0
  58. package/dist/src/commands/dna.d.ts +2 -0
  59. package/dist/src/commands/dna.d.ts.map +1 -0
  60. package/dist/src/commands/dna.js +128 -0
  61. package/dist/src/commands/dna.js.map +1 -0
  62. package/dist/src/commands/hooks.d.ts +6 -0
  63. package/dist/src/commands/hooks.d.ts.map +1 -0
  64. package/dist/src/commands/hooks.js +210 -0
  65. package/dist/src/commands/hooks.js.map +1 -0
  66. package/dist/src/commands/impact.d.ts +2 -0
  67. package/dist/src/commands/impact.d.ts.map +1 -0
  68. package/dist/src/commands/impact.js +50 -0
  69. package/dist/src/commands/impact.js.map +1 -0
  70. package/dist/src/commands/index.d.ts +9 -0
  71. package/dist/src/commands/index.d.ts.map +1 -0
  72. package/dist/src/commands/index.js +9 -0
  73. package/dist/src/commands/index.js.map +1 -0
  74. package/dist/src/commands/init.d.ts +2 -0
  75. package/dist/src/commands/init.d.ts.map +1 -0
  76. package/dist/src/commands/init.js +132 -0
  77. package/dist/src/commands/init.js.map +1 -0
  78. package/dist/src/commands/install.d.ts +2 -0
  79. package/dist/src/commands/install.d.ts.map +1 -0
  80. package/dist/src/commands/install.js +67 -0
  81. package/dist/src/commands/install.js.map +1 -0
  82. package/dist/src/commands/mcp.d.ts +2 -0
  83. package/dist/src/commands/mcp.d.ts.map +1 -0
  84. package/dist/src/commands/mcp.js +51 -0
  85. package/dist/src/commands/mcp.js.map +1 -0
  86. package/dist/src/commands/scan.d.ts +2 -0
  87. package/dist/src/commands/scan.d.ts.map +1 -0
  88. package/dist/src/commands/scan.js +46 -0
  89. package/dist/src/commands/scan.js.map +1 -0
  90. package/dist/src/commands/serve.d.ts +2 -0
  91. package/dist/src/commands/serve.d.ts.map +1 -0
  92. package/dist/src/commands/serve.js +93 -0
  93. package/dist/src/commands/serve.js.map +1 -0
  94. package/dist/src/commands/shared.d.ts +11 -0
  95. package/dist/src/commands/shared.d.ts.map +1 -0
  96. package/dist/src/commands/shared.js +137 -0
  97. package/dist/src/commands/shared.js.map +1 -0
  98. package/dist/src/commands/unbond.d.ts +2 -0
  99. package/dist/src/commands/unbond.d.ts.map +1 -0
  100. package/dist/src/commands/unbond.js +29 -0
  101. package/dist/src/commands/unbond.js.map +1 -0
  102. package/dist/src/core/algorithms.d.ts +19 -0
  103. package/dist/src/core/algorithms.d.ts.map +1 -0
  104. package/dist/src/core/algorithms.js +98 -0
  105. package/dist/src/core/algorithms.js.map +1 -0
  106. package/dist/src/core/embeddings.d.ts +12 -0
  107. package/dist/src/core/embeddings.d.ts.map +1 -0
  108. package/dist/src/core/embeddings.js +64 -0
  109. package/dist/src/core/embeddings.js.map +1 -0
  110. package/dist/src/core/git-impact.d.ts +25 -0
  111. package/dist/src/core/git-impact.d.ts.map +1 -0
  112. package/dist/src/core/git-impact.js +97 -0
  113. package/dist/src/core/git-impact.js.map +1 -0
  114. package/dist/src/core/graph-builder.d.ts +5 -0
  115. package/dist/src/core/graph-builder.d.ts.map +1 -0
  116. package/dist/src/core/graph-builder.js +88 -0
  117. package/dist/src/core/graph-builder.js.map +1 -0
  118. package/dist/src/core/graph.d.ts +34 -0
  119. package/dist/src/core/graph.d.ts.map +1 -0
  120. package/dist/src/core/graph.js +95 -0
  121. package/dist/src/core/graph.js.map +1 -0
  122. package/dist/src/core/impact.d.ts +22 -0
  123. package/dist/src/core/impact.d.ts.map +1 -0
  124. package/dist/src/core/impact.js +68 -0
  125. package/dist/src/core/impact.js.map +1 -0
  126. package/dist/src/core/languages.d.ts +4 -0
  127. package/dist/src/core/languages.d.ts.map +1 -0
  128. package/dist/src/core/languages.js +59 -0
  129. package/dist/src/core/languages.js.map +1 -0
  130. package/dist/src/core/parser.d.ts +16 -0
  131. package/dist/src/core/parser.d.ts.map +1 -0
  132. package/dist/src/core/parser.js +689 -0
  133. package/dist/src/core/parser.js.map +1 -0
  134. package/dist/src/core/scanner.d.ts +26 -0
  135. package/dist/src/core/scanner.d.ts.map +1 -0
  136. package/dist/src/core/scanner.js +87 -0
  137. package/dist/src/core/scanner.js.map +1 -0
  138. package/dist/src/core/search.d.ts +34 -0
  139. package/dist/src/core/search.d.ts.map +1 -0
  140. package/dist/src/core/search.js +146 -0
  141. package/dist/src/core/search.js.map +1 -0
  142. package/dist/src/core/types.d.ts +29 -0
  143. package/dist/src/core/types.d.ts.map +1 -0
  144. package/dist/src/core/types.js +12 -0
  145. package/dist/src/core/types.js.map +1 -0
  146. package/dist/src/cortex/engine.d.ts +10 -0
  147. package/dist/src/cortex/engine.d.ts.map +1 -0
  148. package/dist/src/cortex/engine.js +93 -0
  149. package/dist/src/cortex/engine.js.map +1 -0
  150. package/dist/src/cortex/index.d.ts +13 -0
  151. package/dist/src/cortex/index.d.ts.map +1 -0
  152. package/dist/src/cortex/index.js +12 -0
  153. package/dist/src/cortex/index.js.map +1 -0
  154. package/dist/src/cortex/patterns.d.ts +63 -0
  155. package/dist/src/cortex/patterns.d.ts.map +1 -0
  156. package/dist/src/cortex/patterns.js +242 -0
  157. package/dist/src/cortex/patterns.js.map +1 -0
  158. package/dist/src/cortex/pgq-queries.d.ts +11 -0
  159. package/dist/src/cortex/pgq-queries.d.ts.map +1 -0
  160. package/dist/src/cortex/pgq-queries.js +23 -0
  161. package/dist/src/cortex/pgq-queries.js.map +1 -0
  162. package/dist/src/cortex/pgq.d.ts +5 -0
  163. package/dist/src/cortex/pgq.d.ts.map +1 -0
  164. package/dist/src/cortex/pgq.js +54 -0
  165. package/dist/src/cortex/pgq.js.map +1 -0
  166. package/dist/src/cortex/real-time-enrichment.d.ts +20 -0
  167. package/dist/src/cortex/real-time-enrichment.d.ts.map +1 -0
  168. package/dist/src/cortex/real-time-enrichment.js +96 -0
  169. package/dist/src/cortex/real-time-enrichment.js.map +1 -0
  170. package/dist/src/cortex/repository.d.ts +231 -0
  171. package/dist/src/cortex/repository.d.ts.map +1 -0
  172. package/dist/src/cortex/repository.js +1078 -0
  173. package/dist/src/cortex/repository.js.map +1 -0
  174. package/dist/src/cortex/schema.d.ts +9 -0
  175. package/dist/src/cortex/schema.d.ts.map +1 -0
  176. package/dist/src/cortex/schema.js +364 -0
  177. package/dist/src/cortex/schema.js.map +1 -0
  178. package/dist/src/cortex/stage-0-structure.d.ts +7 -0
  179. package/dist/src/cortex/stage-0-structure.d.ts.map +1 -0
  180. package/dist/src/cortex/stage-0-structure.js +119 -0
  181. package/dist/src/cortex/stage-0-structure.js.map +1 -0
  182. package/dist/src/cortex/stage-1-symbols.d.ts +7 -0
  183. package/dist/src/cortex/stage-1-symbols.d.ts.map +1 -0
  184. package/dist/src/cortex/stage-1-symbols.js +605 -0
  185. package/dist/src/cortex/stage-1-symbols.js.map +1 -0
  186. package/dist/src/cortex/stage-2-resolution.d.ts +7 -0
  187. package/dist/src/cortex/stage-2-resolution.d.ts.map +1 -0
  188. package/dist/src/cortex/stage-2-resolution.js +469 -0
  189. package/dist/src/cortex/stage-2-resolution.js.map +1 -0
  190. package/dist/src/cortex/stage-3-callgraph.d.ts +7 -0
  191. package/dist/src/cortex/stage-3-callgraph.d.ts.map +1 -0
  192. package/dist/src/cortex/stage-3-callgraph.js +323 -0
  193. package/dist/src/cortex/stage-3-callgraph.js.map +1 -0
  194. package/dist/src/cortex/stage-4-types.d.ts +7 -0
  195. package/dist/src/cortex/stage-4-types.d.ts.map +1 -0
  196. package/dist/src/cortex/stage-4-types.js +462 -0
  197. package/dist/src/cortex/stage-4-types.js.map +1 -0
  198. package/dist/src/cortex/stage-5-flow.d.ts +7 -0
  199. package/dist/src/cortex/stage-5-flow.d.ts.map +1 -0
  200. package/dist/src/cortex/stage-5-flow.js +702 -0
  201. package/dist/src/cortex/stage-5-flow.js.map +1 -0
  202. package/dist/src/cortex/stage-6-topology.d.ts +15 -0
  203. package/dist/src/cortex/stage-6-topology.d.ts.map +1 -0
  204. package/dist/src/cortex/stage-6-topology.js +382 -0
  205. package/dist/src/cortex/stage-6-topology.js.map +1 -0
  206. package/dist/src/cortex/stage-7-intelligence.d.ts +34 -0
  207. package/dist/src/cortex/stage-7-intelligence.d.ts.map +1 -0
  208. package/dist/src/cortex/stage-7-intelligence.js +258 -0
  209. package/dist/src/cortex/stage-7-intelligence.js.map +1 -0
  210. package/dist/src/cortex/topology-types.d.ts +78 -0
  211. package/dist/src/cortex/topology-types.d.ts.map +1 -0
  212. package/dist/src/cortex/topology-types.js +2 -0
  213. package/dist/src/cortex/topology-types.js.map +1 -0
  214. package/dist/src/cortex/types.d.ts +250 -0
  215. package/dist/src/cortex/types.d.ts.map +1 -0
  216. package/dist/src/cortex/types.js +2 -0
  217. package/dist/src/cortex/types.js.map +1 -0
  218. package/dist/src/dna/embeddings.d.ts +10 -0
  219. package/dist/src/dna/embeddings.d.ts.map +1 -0
  220. package/dist/src/dna/embeddings.js +46 -0
  221. package/dist/src/dna/embeddings.js.map +1 -0
  222. package/dist/src/dna/engine.d.ts +30 -0
  223. package/dist/src/dna/engine.d.ts.map +1 -0
  224. package/dist/src/dna/engine.js +254 -0
  225. package/dist/src/dna/engine.js.map +1 -0
  226. package/dist/src/dna/index.d.ts +5 -0
  227. package/dist/src/dna/index.d.ts.map +1 -0
  228. package/dist/src/dna/index.js +5 -0
  229. package/dist/src/dna/index.js.map +1 -0
  230. package/dist/src/dna/storage.d.ts +19 -0
  231. package/dist/src/dna/storage.d.ts.map +1 -0
  232. package/dist/src/dna/storage.js +112 -0
  233. package/dist/src/dna/storage.js.map +1 -0
  234. package/dist/src/dna/types.d.ts +38 -0
  235. package/dist/src/dna/types.d.ts.map +1 -0
  236. package/dist/src/dna/types.js +114 -0
  237. package/dist/src/dna/types.js.map +1 -0
  238. package/dist/src/events/bus.d.ts +10 -0
  239. package/dist/src/events/bus.d.ts.map +1 -0
  240. package/dist/src/events/bus.js +36 -0
  241. package/dist/src/events/bus.js.map +1 -0
  242. package/dist/src/events/ipc.d.ts +3 -0
  243. package/dist/src/events/ipc.d.ts.map +1 -0
  244. package/dist/src/events/ipc.js +25 -0
  245. package/dist/src/events/ipc.js.map +1 -0
  246. package/dist/src/events/session.d.ts +21 -0
  247. package/dist/src/events/session.d.ts.map +1 -0
  248. package/dist/src/events/session.js +39 -0
  249. package/dist/src/events/session.js.map +1 -0
  250. package/dist/src/events/types.d.ts +15 -0
  251. package/dist/src/events/types.d.ts.map +1 -0
  252. package/dist/src/events/types.js +26 -0
  253. package/dist/src/events/types.js.map +1 -0
  254. package/dist/src/hooks/attention.d.ts +26 -0
  255. package/dist/src/hooks/attention.d.ts.map +1 -0
  256. package/dist/src/hooks/attention.js +90 -0
  257. package/dist/src/hooks/attention.js.map +1 -0
  258. package/dist/src/hooks/handlers/post-tool-use-failure.d.ts +20 -0
  259. package/dist/src/hooks/handlers/post-tool-use-failure.d.ts.map +1 -0
  260. package/dist/src/hooks/handlers/post-tool-use-failure.js +60 -0
  261. package/dist/src/hooks/handlers/post-tool-use-failure.js.map +1 -0
  262. package/dist/src/hooks/handlers/post-tool-use.d.ts +22 -0
  263. package/dist/src/hooks/handlers/post-tool-use.d.ts.map +1 -0
  264. package/dist/src/hooks/handlers/post-tool-use.js +96 -0
  265. package/dist/src/hooks/handlers/post-tool-use.js.map +1 -0
  266. package/dist/src/hooks/handlers/pre-compact.d.ts +17 -0
  267. package/dist/src/hooks/handlers/pre-compact.d.ts.map +1 -0
  268. package/dist/src/hooks/handlers/pre-compact.js +28 -0
  269. package/dist/src/hooks/handlers/pre-compact.js.map +1 -0
  270. package/dist/src/hooks/handlers/pre-tool-use.d.ts +32 -0
  271. package/dist/src/hooks/handlers/pre-tool-use.d.ts.map +1 -0
  272. package/dist/src/hooks/handlers/pre-tool-use.js +219 -0
  273. package/dist/src/hooks/handlers/pre-tool-use.js.map +1 -0
  274. package/dist/src/hooks/handlers/session-end.d.ts +18 -0
  275. package/dist/src/hooks/handlers/session-end.d.ts.map +1 -0
  276. package/dist/src/hooks/handlers/session-end.js +42 -0
  277. package/dist/src/hooks/handlers/session-end.js.map +1 -0
  278. package/dist/src/hooks/handlers/session-start.d.ts +25 -0
  279. package/dist/src/hooks/handlers/session-start.d.ts.map +1 -0
  280. package/dist/src/hooks/handlers/session-start.js +61 -0
  281. package/dist/src/hooks/handlers/session-start.js.map +1 -0
  282. package/dist/src/hooks/handlers/stop.d.ts +21 -0
  283. package/dist/src/hooks/handlers/stop.d.ts.map +1 -0
  284. package/dist/src/hooks/handlers/stop.js +40 -0
  285. package/dist/src/hooks/handlers/stop.js.map +1 -0
  286. package/dist/src/hooks/handlers/subagent-start.d.ts +17 -0
  287. package/dist/src/hooks/handlers/subagent-start.d.ts.map +1 -0
  288. package/dist/src/hooks/handlers/subagent-start.js +48 -0
  289. package/dist/src/hooks/handlers/subagent-start.js.map +1 -0
  290. package/dist/src/hooks/handlers/user-prompt-submit.d.ts +12 -0
  291. package/dist/src/hooks/handlers/user-prompt-submit.d.ts.map +1 -0
  292. package/dist/src/hooks/handlers/user-prompt-submit.js +31 -0
  293. package/dist/src/hooks/handlers/user-prompt-submit.js.map +1 -0
  294. package/dist/src/hooks/index.d.ts +14 -0
  295. package/dist/src/hooks/index.d.ts.map +1 -0
  296. package/dist/src/hooks/index.js +13 -0
  297. package/dist/src/hooks/index.js.map +1 -0
  298. package/dist/src/hooks/post-tool-use.d.ts +12 -0
  299. package/dist/src/hooks/post-tool-use.d.ts.map +1 -0
  300. package/dist/src/hooks/post-tool-use.js +33 -0
  301. package/dist/src/hooks/post-tool-use.js.map +1 -0
  302. package/dist/src/hooks/pre-tool-use.d.ts +24 -0
  303. package/dist/src/hooks/pre-tool-use.d.ts.map +1 -0
  304. package/dist/src/hooks/pre-tool-use.js +117 -0
  305. package/dist/src/hooks/pre-tool-use.js.map +1 -0
  306. package/dist/src/hooks/session-store.d.ts +55 -0
  307. package/dist/src/hooks/session-store.d.ts.map +1 -0
  308. package/dist/src/hooks/session-store.js +69 -0
  309. package/dist/src/hooks/session-store.js.map +1 -0
  310. package/dist/src/hooks/types.d.ts +67 -0
  311. package/dist/src/hooks/types.d.ts.map +1 -0
  312. package/dist/src/hooks/types.js +28 -0
  313. package/dist/src/hooks/types.js.map +1 -0
  314. package/dist/src/index.d.ts +16 -0
  315. package/dist/src/index.d.ts.map +1 -0
  316. package/dist/src/index.js +16 -0
  317. package/dist/src/index.js.map +1 -0
  318. package/dist/src/init/agent-connector.d.ts +43 -0
  319. package/dist/src/init/agent-connector.d.ts.map +1 -0
  320. package/dist/src/init/agent-connector.js +338 -0
  321. package/dist/src/init/agent-connector.js.map +1 -0
  322. package/dist/src/init/dna-bootstrap.d.ts +10 -0
  323. package/dist/src/init/dna-bootstrap.d.ts.map +1 -0
  324. package/dist/src/init/dna-bootstrap.js +32 -0
  325. package/dist/src/init/dna-bootstrap.js.map +1 -0
  326. package/dist/src/init/index.d.ts +29 -0
  327. package/dist/src/init/index.d.ts.map +1 -0
  328. package/dist/src/init/index.js +81 -0
  329. package/dist/src/init/index.js.map +1 -0
  330. package/dist/src/init/overview-generator.d.ts +5 -0
  331. package/dist/src/init/overview-generator.d.ts.map +1 -0
  332. package/dist/src/init/overview-generator.js +85 -0
  333. package/dist/src/init/overview-generator.js.map +1 -0
  334. package/dist/src/init/parsers/eslint-config.d.ts +10 -0
  335. package/dist/src/init/parsers/eslint-config.d.ts.map +1 -0
  336. package/dist/src/init/parsers/eslint-config.js +50 -0
  337. package/dist/src/init/parsers/eslint-config.js.map +1 -0
  338. package/dist/src/init/parsers/markdown-rules.d.ts +3 -0
  339. package/dist/src/init/parsers/markdown-rules.d.ts.map +1 -0
  340. package/dist/src/init/parsers/markdown-rules.js +90 -0
  341. package/dist/src/init/parsers/markdown-rules.js.map +1 -0
  342. package/dist/src/init/parsers/package-json.d.ts +17 -0
  343. package/dist/src/init/parsers/package-json.d.ts.map +1 -0
  344. package/dist/src/init/parsers/package-json.js +75 -0
  345. package/dist/src/init/parsers/package-json.js.map +1 -0
  346. package/dist/src/init/parsers/prettier-config.d.ts +16 -0
  347. package/dist/src/init/parsers/prettier-config.d.ts.map +1 -0
  348. package/dist/src/init/parsers/prettier-config.js +30 -0
  349. package/dist/src/init/parsers/prettier-config.js.map +1 -0
  350. package/dist/src/init/parsers/tsconfig.d.ts +32 -0
  351. package/dist/src/init/parsers/tsconfig.d.ts.map +1 -0
  352. package/dist/src/init/parsers/tsconfig.js +64 -0
  353. package/dist/src/init/parsers/tsconfig.js.map +1 -0
  354. package/dist/src/init/parsers/types.d.ts +27 -0
  355. package/dist/src/init/parsers/types.d.ts.map +1 -0
  356. package/dist/src/init/parsers/types.js +2 -0
  357. package/dist/src/init/parsers/types.js.map +1 -0
  358. package/dist/src/init/project-analyzer.d.ts +3 -0
  359. package/dist/src/init/project-analyzer.d.ts.map +1 -0
  360. package/dist/src/init/project-analyzer.js +102 -0
  361. package/dist/src/init/project-analyzer.js.map +1 -0
  362. package/dist/src/init/rule-importer.d.ts +3 -0
  363. package/dist/src/init/rule-importer.d.ts.map +1 -0
  364. package/dist/src/init/rule-importer.js +101 -0
  365. package/dist/src/init/rule-importer.js.map +1 -0
  366. package/dist/src/mcp/context.d.ts +43 -0
  367. package/dist/src/mcp/context.d.ts.map +1 -0
  368. package/dist/src/mcp/context.js +167 -0
  369. package/dist/src/mcp/context.js.map +1 -0
  370. package/dist/src/mcp/http-api.d.ts +10 -0
  371. package/dist/src/mcp/http-api.d.ts.map +1 -0
  372. package/dist/src/mcp/http-api.js +580 -0
  373. package/dist/src/mcp/http-api.js.map +1 -0
  374. package/dist/src/mcp/index.d.ts +8 -0
  375. package/dist/src/mcp/index.d.ts.map +1 -0
  376. package/dist/src/mcp/index.js +8 -0
  377. package/dist/src/mcp/index.js.map +1 -0
  378. package/dist/src/mcp/resources.d.ts +5 -0
  379. package/dist/src/mcp/resources.d.ts.map +1 -0
  380. package/dist/src/mcp/resources.js +78 -0
  381. package/dist/src/mcp/resources.js.map +1 -0
  382. package/dist/src/mcp/server.d.ts +6 -0
  383. package/dist/src/mcp/server.d.ts.map +1 -0
  384. package/dist/src/mcp/server.js +265 -0
  385. package/dist/src/mcp/server.js.map +1 -0
  386. package/dist/src/mcp/tool-response.d.ts +6 -0
  387. package/dist/src/mcp/tool-response.d.ts.map +1 -0
  388. package/dist/src/mcp/tool-response.js +19 -0
  389. package/dist/src/mcp/tool-response.js.map +1 -0
  390. package/dist/src/mcp/tools/architecture-tools.d.ts +15 -0
  391. package/dist/src/mcp/tools/architecture-tools.d.ts.map +1 -0
  392. package/dist/src/mcp/tools/architecture-tools.js +56 -0
  393. package/dist/src/mcp/tools/architecture-tools.js.map +1 -0
  394. package/dist/src/mcp/tools/dna-tools.d.ts +21 -0
  395. package/dist/src/mcp/tools/dna-tools.d.ts.map +1 -0
  396. package/dist/src/mcp/tools/dna-tools.js +15 -0
  397. package/dist/src/mcp/tools/dna-tools.js.map +1 -0
  398. package/dist/src/mcp/tools/graph-tools.d.ts +49 -0
  399. package/dist/src/mcp/tools/graph-tools.d.ts.map +1 -0
  400. package/dist/src/mcp/tools/graph-tools.js +45 -0
  401. package/dist/src/mcp/tools/graph-tools.js.map +1 -0
  402. package/dist/src/mcp/tools/health-tools.d.ts +5 -0
  403. package/dist/src/mcp/tools/health-tools.d.ts.map +1 -0
  404. package/dist/src/mcp/tools/health-tools.js +7 -0
  405. package/dist/src/mcp/tools/health-tools.js.map +1 -0
  406. package/dist/src/mcp/tools/impact-tools.d.ts +21 -0
  407. package/dist/src/mcp/tools/impact-tools.d.ts.map +1 -0
  408. package/dist/src/mcp/tools/impact-tools.js +23 -0
  409. package/dist/src/mcp/tools/impact-tools.js.map +1 -0
  410. package/dist/src/mcp/tools/intent-tools.d.ts +32 -0
  411. package/dist/src/mcp/tools/intent-tools.d.ts.map +1 -0
  412. package/dist/src/mcp/tools/intent-tools.js +77 -0
  413. package/dist/src/mcp/tools/intent-tools.js.map +1 -0
  414. package/dist/src/mcp/tools/project-tools.d.ts +53 -0
  415. package/dist/src/mcp/tools/project-tools.d.ts.map +1 -0
  416. package/dist/src/mcp/tools/project-tools.js +91 -0
  417. package/dist/src/mcp/tools/project-tools.js.map +1 -0
  418. package/dist/src/mcp/tools/rename-tool.d.ts +25 -0
  419. package/dist/src/mcp/tools/rename-tool.d.ts.map +1 -0
  420. package/dist/src/mcp/tools/rename-tool.js +106 -0
  421. package/dist/src/mcp/tools/rename-tool.js.map +1 -0
  422. package/dist/src/mcp/tools/trace-tools.d.ts +4 -0
  423. package/dist/src/mcp/tools/trace-tools.d.ts.map +1 -0
  424. package/dist/src/mcp/tools/trace-tools.js +268 -0
  425. package/dist/src/mcp/tools/trace-tools.js.map +1 -0
  426. package/dist/src/storage/db.d.ts +13 -0
  427. package/dist/src/storage/db.d.ts.map +1 -0
  428. package/dist/src/storage/db.js +230 -0
  429. package/dist/src/storage/db.js.map +1 -0
  430. package/dist/src/storage/repository.d.ts +54 -0
  431. package/dist/src/storage/repository.d.ts.map +1 -0
  432. package/dist/src/storage/repository.js +257 -0
  433. package/dist/src/storage/repository.js.map +1 -0
  434. package/dist/src/utils/config.d.ts +18 -0
  435. package/dist/src/utils/config.d.ts.map +1 -0
  436. package/dist/src/utils/config.js +93 -0
  437. package/dist/src/utils/config.js.map +1 -0
  438. package/dist/src/utils/files.d.ts +3 -0
  439. package/dist/src/utils/files.d.ts.map +1 -0
  440. package/dist/src/utils/files.js +52 -0
  441. package/dist/src/utils/files.js.map +1 -0
  442. package/dist/src/utils/strings.d.ts +2 -0
  443. package/dist/src/utils/strings.d.ts.map +1 -0
  444. package/dist/src/utils/strings.js +11 -0
  445. package/dist/src/utils/strings.js.map +1 -0
  446. package/dist/tsconfig.tsbuildinfo +1 -0
  447. package/hooks/post-tool-use.sh +37 -0
  448. package/hooks/pre-tool-use.sh +43 -0
  449. package/hooks/session-start.sh +67 -0
  450. package/package.json +103 -0
  451. package/skills/symbiote-init/SKILL.md +104 -0
@@ -0,0 +1,689 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { createRequire } from 'node:module';
4
+ import { detectLanguage, getGrammar } from './languages.js';
5
+ const cjsRequire = createRequire(import.meta.url);
6
+ const Parser = cjsRequire('tree-sitter');
7
+ const JS_TS_CONFIG = {
8
+ functionTypes: new Set([
9
+ 'function_declaration',
10
+ 'function',
11
+ 'arrow_function',
12
+ 'generator_function',
13
+ 'generator_function_declaration',
14
+ ]),
15
+ classTypes: new Set(['class_declaration', 'class']),
16
+ methodTypes: new Set(['method_definition', 'public_field_definition']),
17
+ interfaceTypes: new Set(['interface_declaration']),
18
+ typeAliasTypes: new Set(['type_alias_declaration']),
19
+ enumTypes: new Set(['enum_declaration']),
20
+ importTypes: new Set(['import_statement']),
21
+ callTypes: new Set(['call_expression', 'new_expression']),
22
+ importSourceField: 'source',
23
+ extensions: [
24
+ '.ts',
25
+ '.tsx',
26
+ '.js',
27
+ '.jsx',
28
+ '.mjs',
29
+ '/index.ts',
30
+ '/index.tsx',
31
+ '/index.js',
32
+ '/index.jsx',
33
+ ],
34
+ };
35
+ const PYTHON_CONFIG = {
36
+ functionTypes: new Set(['function_definition']),
37
+ classTypes: new Set(['class_definition']),
38
+ methodTypes: new Set(['function_definition']),
39
+ interfaceTypes: new Set(),
40
+ typeAliasTypes: new Set(),
41
+ enumTypes: new Set(),
42
+ importTypes: new Set(['import_statement', 'import_from_statement']),
43
+ callTypes: new Set(['call']),
44
+ importSourceField: 'module_name',
45
+ extensions: ['.py', '/__init__.py'],
46
+ };
47
+ const GO_CONFIG = {
48
+ functionTypes: new Set(['function_declaration', 'method_declaration']),
49
+ classTypes: new Set(),
50
+ methodTypes: new Set(),
51
+ interfaceTypes: new Set(),
52
+ typeAliasTypes: new Set(),
53
+ enumTypes: new Set(),
54
+ importTypes: new Set(['import_declaration']),
55
+ callTypes: new Set(['call_expression']),
56
+ importSourceField: 'path',
57
+ extensions: ['.go'],
58
+ };
59
+ const RUST_CONFIG = {
60
+ functionTypes: new Set(['function_item']),
61
+ classTypes: new Set(['struct_item']),
62
+ methodTypes: new Set(['function_item']),
63
+ interfaceTypes: new Set(['trait_item']),
64
+ typeAliasTypes: new Set(['type_item']),
65
+ enumTypes: new Set(['enum_item']),
66
+ importTypes: new Set(['use_declaration']),
67
+ callTypes: new Set(['call_expression']),
68
+ importSourceField: 'argument',
69
+ extensions: ['.rs'],
70
+ };
71
+ const JAVA_CONFIG = {
72
+ functionTypes: new Set(),
73
+ classTypes: new Set(['class_declaration']),
74
+ methodTypes: new Set(['method_declaration', 'constructor_declaration']),
75
+ interfaceTypes: new Set(['interface_declaration']),
76
+ typeAliasTypes: new Set(),
77
+ enumTypes: new Set(['enum_declaration']),
78
+ importTypes: new Set(['import_declaration']),
79
+ callTypes: new Set(['method_invocation', 'object_creation_expression']),
80
+ importSourceField: '',
81
+ extensions: ['.java'],
82
+ };
83
+ const RUBY_CONFIG = {
84
+ functionTypes: new Set(['method']),
85
+ classTypes: new Set(['class', 'module']),
86
+ methodTypes: new Set(['method', 'singleton_method']),
87
+ interfaceTypes: new Set(),
88
+ typeAliasTypes: new Set(),
89
+ enumTypes: new Set(),
90
+ importTypes: new Set(),
91
+ callTypes: new Set(['call', 'method_call']),
92
+ importSourceField: '',
93
+ extensions: ['.rb'],
94
+ };
95
+ const PHP_CONFIG = {
96
+ functionTypes: new Set(['function_definition']),
97
+ classTypes: new Set(['class_declaration']),
98
+ methodTypes: new Set(['method_declaration']),
99
+ interfaceTypes: new Set(['interface_declaration']),
100
+ typeAliasTypes: new Set(),
101
+ enumTypes: new Set(['enum_declaration']),
102
+ importTypes: new Set(['namespace_use_declaration']),
103
+ callTypes: new Set(['function_call_expression', 'member_call_expression']),
104
+ importSourceField: '',
105
+ extensions: ['.php'],
106
+ };
107
+ const C_CPP_CONFIG = {
108
+ functionTypes: new Set(['function_definition']),
109
+ classTypes: new Set(['class_specifier']),
110
+ methodTypes: new Set(['function_definition']),
111
+ interfaceTypes: new Set(),
112
+ typeAliasTypes: new Set(),
113
+ enumTypes: new Set(),
114
+ importTypes: new Set(['preproc_include']),
115
+ callTypes: new Set(['call_expression']),
116
+ importSourceField: 'path',
117
+ extensions: ['.c', '.h', '.cpp', '.cc', '.hpp'],
118
+ };
119
+ const LANGUAGE_CONFIGS = {
120
+ javascript: JS_TS_CONFIG,
121
+ typescript: JS_TS_CONFIG,
122
+ tsx: JS_TS_CONFIG,
123
+ python: PYTHON_CONFIG,
124
+ go: GO_CONFIG,
125
+ rust: RUST_CONFIG,
126
+ java: JAVA_CONFIG,
127
+ ruby: RUBY_CONFIG,
128
+ php: PHP_CONFIG,
129
+ c: C_CPP_CONFIG,
130
+ cpp: C_CPP_CONFIG,
131
+ };
132
+ const resolveCache = new Map();
133
+ export function parseFile(filePath, content) {
134
+ if (!content && !fs.existsSync(filePath))
135
+ return null;
136
+ const language = detectLanguage(filePath);
137
+ if (!language)
138
+ return null;
139
+ const grammar = getGrammar(language);
140
+ if (!grammar)
141
+ return null;
142
+ const source = content ?? fs.readFileSync(filePath, 'utf-8');
143
+ const parser = new Parser();
144
+ parser.setLanguage(grammar);
145
+ const tree = parser.parse(source);
146
+ const config = LANGUAGE_CONFIGS[language] ?? JS_TS_CONFIG;
147
+ const nodes = [];
148
+ const edges = [];
149
+ const lineCount = tree.rootNode.endPosition.row + 1;
150
+ nodes.push({
151
+ id: `file:${filePath}`,
152
+ type: 'file',
153
+ name: path.basename(filePath),
154
+ filePath,
155
+ lineStart: 1,
156
+ lineEnd: lineCount,
157
+ });
158
+ extractNodes(tree.rootNode, filePath, language, config, nodes);
159
+ extractImports(tree.rootNode, filePath, language, config, edges);
160
+ const symbolTable = buildSymbolTable(tree.rootNode, filePath, language, config);
161
+ extractImportBindings(symbolTable, filePath, edges);
162
+ extractCalls(tree.rootNode, filePath, config, nodes, symbolTable, edges);
163
+ for (const node of nodes) {
164
+ if (node.type !== 'file') {
165
+ edges.push({
166
+ sourceId: `file:${filePath}`,
167
+ targetId: node.id,
168
+ type: 'contains',
169
+ });
170
+ }
171
+ }
172
+ return { filePath, language, nodes, edges, symbolTable };
173
+ }
174
+ function extractNodes(root, filePath, language, config, nodes) {
175
+ const cursor = root.walk();
176
+ let reachedRoot = false;
177
+ while (!reachedRoot) {
178
+ const node = cursor.currentNode;
179
+ if (config.functionTypes.has(node.type)) {
180
+ const insideClass = isInsideClass(node, config);
181
+ if (!insideClass) {
182
+ const name = getFunctionName(node, language);
183
+ if (name) {
184
+ nodes.push({
185
+ id: `fn:${filePath}:${name}`,
186
+ type: 'function',
187
+ name,
188
+ filePath,
189
+ lineStart: node.startPosition.row + 1,
190
+ lineEnd: node.endPosition.row + 1,
191
+ });
192
+ }
193
+ }
194
+ }
195
+ if (config.interfaceTypes.has(node.type)) {
196
+ const name = node.childForFieldName('name')?.text;
197
+ if (name) {
198
+ nodes.push({
199
+ id: `interface:${filePath}:${name}`,
200
+ type: 'interface',
201
+ name,
202
+ filePath,
203
+ lineStart: node.startPosition.row + 1,
204
+ lineEnd: node.endPosition.row + 1,
205
+ });
206
+ }
207
+ }
208
+ if (config.typeAliasTypes.has(node.type)) {
209
+ const name = node.childForFieldName('name')?.text;
210
+ if (name) {
211
+ nodes.push({
212
+ id: `type:${filePath}:${name}`,
213
+ type: 'type_alias',
214
+ name,
215
+ filePath,
216
+ lineStart: node.startPosition.row + 1,
217
+ lineEnd: node.endPosition.row + 1,
218
+ });
219
+ }
220
+ }
221
+ if (config.enumTypes.has(node.type)) {
222
+ const name = node.childForFieldName('name')?.text;
223
+ if (name) {
224
+ nodes.push({
225
+ id: `enum:${filePath}:${name}`,
226
+ type: 'enum',
227
+ name,
228
+ filePath,
229
+ lineStart: node.startPosition.row + 1,
230
+ lineEnd: node.endPosition.row + 1,
231
+ });
232
+ }
233
+ }
234
+ if (config.classTypes.has(node.type)) {
235
+ const name = getClassName(node, language);
236
+ if (name) {
237
+ nodes.push({
238
+ id: `class:${filePath}:${name}`,
239
+ type: 'class',
240
+ name,
241
+ filePath,
242
+ lineStart: node.startPosition.row + 1,
243
+ lineEnd: node.endPosition.row + 1,
244
+ });
245
+ extractMethods(node, filePath, name, language, config, nodes);
246
+ }
247
+ }
248
+ if ((language === 'c' || language === 'cpp') && node.type === 'type_definition') {
249
+ const declarator = node.childForFieldName('declarator');
250
+ if (declarator?.type === 'type_identifier') {
251
+ const hasStruct = node.children.some((c) => c.type === 'struct_specifier');
252
+ const hasEnum = node.children.some((c) => c.type === 'enum_specifier');
253
+ const nodeType = hasStruct ? 'class' : hasEnum ? 'enum' : 'type_alias';
254
+ const prefix = hasStruct ? 'class' : hasEnum ? 'enum' : 'type';
255
+ nodes.push({
256
+ id: `${prefix}:${filePath}:${declarator.text}`,
257
+ type: nodeType,
258
+ name: declarator.text,
259
+ filePath,
260
+ lineStart: node.startPosition.row + 1,
261
+ lineEnd: node.endPosition.row + 1,
262
+ });
263
+ }
264
+ }
265
+ if (language === 'go' && node.type === 'type_declaration') {
266
+ for (const spec of node.children) {
267
+ if (spec.type === 'type_spec') {
268
+ const name = spec.childForFieldName('name')?.text;
269
+ const typeNode = spec.childForFieldName('type');
270
+ if (name && typeNode) {
271
+ if (typeNode.type === 'struct_type') {
272
+ nodes.push({
273
+ id: `class:${filePath}:${name}`,
274
+ type: 'class',
275
+ name,
276
+ filePath,
277
+ lineStart: spec.startPosition.row + 1,
278
+ lineEnd: spec.endPosition.row + 1,
279
+ });
280
+ }
281
+ else if (typeNode.type === 'interface_type') {
282
+ nodes.push({
283
+ id: `interface:${filePath}:${name}`,
284
+ type: 'interface',
285
+ name,
286
+ filePath,
287
+ lineStart: spec.startPosition.row + 1,
288
+ lineEnd: spec.endPosition.row + 1,
289
+ });
290
+ }
291
+ }
292
+ }
293
+ }
294
+ }
295
+ if (cursor.gotoFirstChild())
296
+ continue;
297
+ if (cursor.gotoNextSibling())
298
+ continue;
299
+ while (true) {
300
+ if (!cursor.gotoParent()) {
301
+ reachedRoot = true;
302
+ break;
303
+ }
304
+ if (cursor.gotoNextSibling())
305
+ break;
306
+ }
307
+ }
308
+ }
309
+ function isInsideClass(node, config) {
310
+ let parent = node.parent;
311
+ while (parent) {
312
+ if (config.classTypes.has(parent.type))
313
+ return true;
314
+ if (parent.type === 'impl_item')
315
+ return true;
316
+ parent = parent.parent;
317
+ }
318
+ return false;
319
+ }
320
+ function extractMethods(classNode, filePath, className, language, config, nodes) {
321
+ const body = classNode.childForFieldName('body') ?? findClassBody(classNode);
322
+ if (!body)
323
+ return;
324
+ for (const child of body.children) {
325
+ if (config.methodTypes.has(child.type)) {
326
+ const name = getFunctionName(child, language);
327
+ if (name) {
328
+ nodes.push({
329
+ id: `method:${filePath}:${className}.${name}`,
330
+ type: 'method',
331
+ name: `${className}.${name}`,
332
+ filePath,
333
+ lineStart: child.startPosition.row + 1,
334
+ lineEnd: child.endPosition.row + 1,
335
+ });
336
+ }
337
+ }
338
+ }
339
+ }
340
+ function findClassBody(node) {
341
+ for (const child of node.children) {
342
+ if (child.type === 'class_body' ||
343
+ child.type === 'block' ||
344
+ child.type === 'declaration_list' ||
345
+ child.type === 'field_declaration_list') {
346
+ return child;
347
+ }
348
+ }
349
+ return null;
350
+ }
351
+ function extractImports(root, filePath, language, config, edges) {
352
+ for (const child of root.children) {
353
+ if (!config.importTypes.has(child.type))
354
+ continue;
355
+ const importPath = extractImportPath(child, language, config);
356
+ if (importPath) {
357
+ edges.push({
358
+ sourceId: `file:${filePath}`,
359
+ targetId: `file:${resolveImportPath(filePath, importPath, config)}`,
360
+ type: 'imports',
361
+ });
362
+ }
363
+ }
364
+ }
365
+ function extractImportPath(node, language, config) {
366
+ if (language === 'python') {
367
+ if (node.type === 'import_from_statement') {
368
+ const moduleName = node.childForFieldName('module_name');
369
+ return moduleName?.text ?? null;
370
+ }
371
+ if (node.type === 'import_statement') {
372
+ const name = node.childForFieldName('name');
373
+ return name?.text ?? null;
374
+ }
375
+ return null;
376
+ }
377
+ if (language === 'c' || language === 'cpp') {
378
+ const pathNode = node.childForFieldName('path');
379
+ if (pathNode)
380
+ return pathNode.text.replace(/[<>"]/g, '');
381
+ return null;
382
+ }
383
+ if (language === 'java') {
384
+ for (const child of node.children) {
385
+ if (child.type === 'scoped_identifier')
386
+ return child.text;
387
+ }
388
+ return null;
389
+ }
390
+ if (language === 'go') {
391
+ for (const child of node.children) {
392
+ if (child.type === 'import_spec_list') {
393
+ for (const spec of child.children) {
394
+ if (spec.type === 'import_spec') {
395
+ const pathNode = spec.childForFieldName('path');
396
+ if (pathNode)
397
+ return pathNode.text.replace(/"/g, '');
398
+ }
399
+ }
400
+ }
401
+ if (child.type === 'import_spec') {
402
+ const pathNode = child.childForFieldName('path');
403
+ if (pathNode)
404
+ return pathNode.text.replace(/"/g, '');
405
+ }
406
+ }
407
+ return null;
408
+ }
409
+ if (language === 'rust') {
410
+ const arg = node.childForFieldName('argument');
411
+ if (arg)
412
+ return arg.text.replace(/::\{.*\}$/, '');
413
+ return null;
414
+ }
415
+ if (config.importSourceField) {
416
+ const source = node.childForFieldName(config.importSourceField);
417
+ if (source)
418
+ return source.text.replace(/['"]/g, '');
419
+ }
420
+ return null;
421
+ }
422
+ function getFunctionName(node, language) {
423
+ const nameNode = node.childForFieldName('name');
424
+ if (nameNode && nameNode.type !== 'ERROR')
425
+ return nameNode.text;
426
+ if (language === 'c' || language === 'cpp') {
427
+ const declarator = node.childForFieldName('declarator');
428
+ if (declarator) {
429
+ const inner = declarator.childForFieldName('declarator');
430
+ if (inner) {
431
+ if (inner.type === 'identifier')
432
+ return inner.text;
433
+ const deepest = inner.childForFieldName('declarator');
434
+ if (deepest?.type === 'identifier')
435
+ return deepest.text;
436
+ }
437
+ if (declarator.type === 'identifier')
438
+ return declarator.text;
439
+ }
440
+ }
441
+ const parent = node.parent;
442
+ if (parent?.type === 'variable_declarator') {
443
+ const name = parent.childForFieldName('name');
444
+ if (name)
445
+ return name.text;
446
+ }
447
+ return null;
448
+ }
449
+ function getClassName(node, _language) {
450
+ const nameNode = node.childForFieldName('name');
451
+ if (nameNode)
452
+ return nameNode.text;
453
+ for (const child of node.children) {
454
+ if (child.type === 'type_identifier' || child.type === 'identifier') {
455
+ return child.text;
456
+ }
457
+ }
458
+ return null;
459
+ }
460
+ function extractCalls(root, filePath, config, nodes, symbolTable, edges) {
461
+ const fnScopes = new Map(nodes
462
+ .filter((n) => n.type === 'function' || n.type === 'method')
463
+ .map((n) => [n.id, { lineStart: n.lineStart, lineEnd: n.lineEnd, id: n.id }]));
464
+ const cursor = root.walk();
465
+ let done = false;
466
+ while (!done) {
467
+ const node = cursor.currentNode;
468
+ if (config.callTypes.has(node.type)) {
469
+ if (node.type === 'new_expression' || node.type === 'object_creation_expression') {
470
+ const nameNode = node.childForFieldName('constructor') ?? node.childForFieldName('type');
471
+ if (nameNode) {
472
+ const caller = findEnclosingFunction(node, filePath, fnScopes);
473
+ if (caller) {
474
+ const entry = symbolTable.get(nameNode.text);
475
+ const target = entry
476
+ ? `class:${entry.resolvedSourcePath}:${entry.originalName}`
477
+ : `class:${filePath}:${nameNode.text}`;
478
+ edges.push({ sourceId: caller, targetId: target, type: 'calls' });
479
+ }
480
+ }
481
+ }
482
+ else {
483
+ const info = resolveCallExpression(node, filePath, fnScopes);
484
+ if (info) {
485
+ const targetId = resolveCallTarget(info, filePath, symbolTable);
486
+ if (targetId) {
487
+ edges.push({ sourceId: info.callerNodeId, targetId, type: 'calls' });
488
+ }
489
+ }
490
+ }
491
+ }
492
+ if (cursor.gotoFirstChild())
493
+ continue;
494
+ if (cursor.gotoNextSibling())
495
+ continue;
496
+ while (true) {
497
+ if (!cursor.gotoParent()) {
498
+ done = true;
499
+ break;
500
+ }
501
+ if (cursor.gotoNextSibling())
502
+ break;
503
+ }
504
+ }
505
+ }
506
+ function findEnclosingFunction(node, filePath, fnScopes) {
507
+ const line = node.startPosition.row + 1;
508
+ let best = null;
509
+ let bestSize = Infinity;
510
+ for (const [, fn] of fnScopes) {
511
+ if (line >= fn.lineStart && line <= fn.lineEnd) {
512
+ const size = fn.lineEnd - fn.lineStart;
513
+ if (size < bestSize) {
514
+ bestSize = size;
515
+ best = fn.id;
516
+ }
517
+ }
518
+ }
519
+ return best ?? `file:${filePath}`;
520
+ }
521
+ function resolveCallExpression(node, filePath, fnScopes) {
522
+ const fnField = node.childForFieldName('function') ??
523
+ node.childForFieldName('name') ??
524
+ node.childForFieldName('method');
525
+ if (!fnField)
526
+ return null;
527
+ const callerNodeId = findEnclosingFunction(node, filePath, fnScopes);
528
+ if (!callerNodeId)
529
+ return null;
530
+ if (fnField.type === 'member_expression' ||
531
+ fnField.type === 'attribute' ||
532
+ fnField.type === 'selector_expression' ||
533
+ fnField.type === 'field_expression') {
534
+ const property = fnField.childForFieldName('property') ??
535
+ fnField.childForFieldName('attribute') ??
536
+ fnField.childForFieldName('field');
537
+ if (!property)
538
+ return null;
539
+ return {
540
+ callerNodeId,
541
+ calledName: property.text,
542
+ isMethodCall: true,
543
+ objectName: fnField.childForFieldName('object')?.text,
544
+ };
545
+ }
546
+ if (fnField.type === 'identifier' || fnField.type === 'scoped_identifier') {
547
+ return { callerNodeId, calledName: fnField.text, isMethodCall: false };
548
+ }
549
+ return null;
550
+ }
551
+ function resolveCallTarget(call, filePath, symbolTable) {
552
+ if (call.isMethodCall && call.objectName) {
553
+ const entry = symbolTable.get(call.objectName);
554
+ if (entry) {
555
+ return `method:${entry.resolvedSourcePath}:${entry.originalName}.${call.calledName}`;
556
+ }
557
+ return `method:${filePath}:${call.objectName}.${call.calledName}`;
558
+ }
559
+ const entry = symbolTable.get(call.calledName);
560
+ if (entry)
561
+ return `fn:${entry.resolvedSourcePath}:${entry.originalName}`;
562
+ return `fn:${filePath}:${call.calledName}`;
563
+ }
564
+ function buildSymbolTable(root, filePath, language, config) {
565
+ const table = new Map();
566
+ for (const child of root.children) {
567
+ if (!config.importTypes.has(child.type))
568
+ continue;
569
+ const importPath = extractImportPath(child, language, config);
570
+ if (!importPath)
571
+ continue;
572
+ const resolvedPath = resolveImportPath(filePath, importPath, config);
573
+ if (language === 'javascript' || language === 'typescript' || language === 'tsx') {
574
+ buildJsSymbolTable(child, importPath, resolvedPath, table);
575
+ }
576
+ else if (language === 'python') {
577
+ buildPythonSymbolTable(child, importPath, resolvedPath, table);
578
+ }
579
+ }
580
+ return table;
581
+ }
582
+ function buildJsSymbolTable(importNode, importPath, resolvedPath, table) {
583
+ const importClause = importNode.children.find((c) => c.type === 'import_clause');
584
+ if (!importClause)
585
+ return;
586
+ for (const clause of importClause.children) {
587
+ if (clause.type === 'named_imports') {
588
+ for (const spec of clause.children) {
589
+ if (spec.type !== 'import_specifier')
590
+ continue;
591
+ const nameNode = spec.childForFieldName('name');
592
+ const aliasNode = spec.childForFieldName('alias');
593
+ if (!nameNode)
594
+ continue;
595
+ const originalName = nameNode.text;
596
+ const localName = aliasNode?.text ?? originalName;
597
+ table.set(localName, {
598
+ localName,
599
+ originalName,
600
+ sourcePath: importPath,
601
+ resolvedSourcePath: resolvedPath,
602
+ });
603
+ }
604
+ }
605
+ if (clause.type === 'identifier') {
606
+ table.set(clause.text, {
607
+ localName: clause.text,
608
+ originalName: 'default',
609
+ sourcePath: importPath,
610
+ resolvedSourcePath: resolvedPath,
611
+ });
612
+ }
613
+ }
614
+ }
615
+ function buildPythonSymbolTable(importNode, importPath, resolvedPath, table) {
616
+ if (importNode.type !== 'import_from_statement')
617
+ return;
618
+ for (const child of importNode.children) {
619
+ if (child.type === 'dotted_name' && child !== importNode.childForFieldName('module_name')) {
620
+ const aliasNode = child.parent?.children.find((c) => c.type === 'aliased_import');
621
+ const localName = aliasNode?.childForFieldName('alias')?.text ?? child.text;
622
+ table.set(localName, {
623
+ localName,
624
+ originalName: child.text,
625
+ sourcePath: importPath,
626
+ resolvedSourcePath: resolvedPath,
627
+ });
628
+ }
629
+ if (child.type === 'aliased_import') {
630
+ const nameNode = child.childForFieldName('name');
631
+ const aliasNode = child.childForFieldName('alias');
632
+ if (nameNode) {
633
+ const localName = aliasNode?.text ?? nameNode.text;
634
+ table.set(localName, {
635
+ localName,
636
+ originalName: nameNode.text,
637
+ sourcePath: importPath,
638
+ resolvedSourcePath: resolvedPath,
639
+ });
640
+ }
641
+ }
642
+ }
643
+ }
644
+ function extractImportBindings(symbolTable, filePath, edges) {
645
+ for (const [, entry] of symbolTable) {
646
+ const prefix = guessNodePrefix(entry.originalName);
647
+ edges.push({
648
+ sourceId: `file:${filePath}`,
649
+ targetId: `${prefix}:${entry.resolvedSourcePath}:${entry.originalName}`,
650
+ type: 'imports_symbol',
651
+ });
652
+ }
653
+ }
654
+ function guessNodePrefix(name) {
655
+ if (!name || name === 'default')
656
+ return 'fn';
657
+ if (name[0] === name[0].toUpperCase() && name[0] !== name[0].toLowerCase())
658
+ return 'class';
659
+ return 'fn';
660
+ }
661
+ function resolveImportPath(fromFile, importPath, config) {
662
+ if (!importPath.startsWith('.'))
663
+ return importPath;
664
+ const cacheKey = `${fromFile}:${importPath}`;
665
+ const cached = resolveCache.get(cacheKey);
666
+ if (cached)
667
+ return cached;
668
+ const dir = path.dirname(fromFile);
669
+ const resolved = path.resolve(dir, importPath);
670
+ if (fs.existsSync(resolved)) {
671
+ resolveCache.set(cacheKey, resolved);
672
+ return resolved;
673
+ }
674
+ for (const ext of config.extensions) {
675
+ const withExt = resolved + ext;
676
+ if (fs.existsSync(withExt)) {
677
+ resolveCache.set(cacheKey, withExt);
678
+ return withExt;
679
+ }
680
+ }
681
+ const stripped = resolved.replace(/\.js$/, '.ts');
682
+ if (stripped !== resolved && fs.existsSync(stripped)) {
683
+ resolveCache.set(cacheKey, stripped);
684
+ return stripped;
685
+ }
686
+ resolveCache.set(cacheKey, resolved);
687
+ return resolved;
688
+ }
689
+ //# sourceMappingURL=parser.js.map