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,1078 @@
1
+ const CHUNK_SIZE = 500;
2
+ export class CortexRepository {
3
+ db;
4
+ constructor(db) {
5
+ this.db = db;
6
+ }
7
+ async upsertFileNode(node) {
8
+ await this.db.run(`INSERT INTO nodes_file (id, path, hash, language, depth_level, last_indexed)
9
+ VALUES ($1, $2, $3, $4, $5, $6)
10
+ ON CONFLICT (id) DO UPDATE SET path = excluded.path, hash = excluded.hash,
11
+ language = excluded.language, depth_level = excluded.depth_level,
12
+ last_indexed = excluded.last_indexed`, node.id, node.path, node.hash, node.language, node.depthLevel, node.lastIndexed ? node.lastIndexed.toISOString() : null);
13
+ }
14
+ async getFileNode(id) {
15
+ const rows = await this.db.all('SELECT * FROM nodes_file WHERE id = $1', id);
16
+ if (rows.length === 0)
17
+ return null;
18
+ return this.mapFileNodeRow(rows[0]);
19
+ }
20
+ async getFilesByMaxDepth(maxDepth) {
21
+ const rows = await this.db.all('SELECT * FROM nodes_file WHERE depth_level < $1', maxDepth);
22
+ return rows.map((r) => this.mapFileNodeRow(r));
23
+ }
24
+ async getAllFileNodes() {
25
+ const rows = await this.db.all('SELECT * FROM nodes_file');
26
+ return rows.map((r) => this.mapFileNodeRow(r));
27
+ }
28
+ async isFileChanged(id, hash) {
29
+ const node = await this.getFileNode(id);
30
+ if (!node)
31
+ return true;
32
+ return node.hash !== hash;
33
+ }
34
+ async insertFunctionNodes(nodes) {
35
+ if (nodes.length === 0)
36
+ return;
37
+ await this.batchInsert(nodes, 14, (node, offset) => ({
38
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7}, $${offset + 8}, $${offset + 9}, $${offset + 10}, $${offset + 11}, $${offset + 12}, $${offset + 13}, $${offset + 14})`,
39
+ params: [
40
+ node.id,
41
+ node.name,
42
+ node.qualifiedName,
43
+ node.filePath,
44
+ node.lineStart,
45
+ node.lineEnd,
46
+ node.isAsync,
47
+ node.isExported,
48
+ node.isEntryPoint,
49
+ node.entryPointScore,
50
+ node.signature,
51
+ node.community,
52
+ node.pageRank,
53
+ node.betweenness,
54
+ ],
55
+ }), `INSERT INTO nodes_function (id, name, qualified_name, file_path, line_start, line_end, is_async, is_exported, is_entry_point, entry_point_score, signature, community, page_rank, betweenness) VALUES`, 'ON CONFLICT (id) DO NOTHING');
56
+ }
57
+ async insertClassNodes(nodes) {
58
+ if (nodes.length === 0)
59
+ return;
60
+ await this.batchInsert(nodes, 10, (node, offset) => ({
61
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7}, $${offset + 8}, $${offset + 9}, $${offset + 10})`,
62
+ params: [
63
+ node.id,
64
+ node.name,
65
+ node.filePath,
66
+ node.lineStart,
67
+ node.lineEnd,
68
+ node.isAbstract,
69
+ node.isExported,
70
+ node.community,
71
+ node.pageRank,
72
+ node.betweenness,
73
+ ],
74
+ }), `INSERT INTO nodes_class (id, name, file_path, line_start, line_end, is_abstract, is_exported, community, page_rank, betweenness) VALUES`, 'ON CONFLICT (id) DO NOTHING');
75
+ }
76
+ async insertMethodNodes(nodes) {
77
+ if (nodes.length === 0)
78
+ return;
79
+ await this.batchInsert(nodes, 13, (node, offset) => ({
80
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7}, $${offset + 8}, $${offset + 9}, $${offset + 10}, $${offset + 11}, $${offset + 12}, $${offset + 13})`,
81
+ params: [
82
+ node.id,
83
+ node.name,
84
+ node.className,
85
+ node.qualifiedName,
86
+ node.filePath,
87
+ node.lineStart,
88
+ node.lineEnd,
89
+ node.visibility,
90
+ node.isStatic,
91
+ node.isAsync,
92
+ node.community,
93
+ node.pageRank,
94
+ node.betweenness,
95
+ ],
96
+ }), `INSERT INTO nodes_method (id, name, class_name, qualified_name, file_path, line_start, line_end, visibility, is_static, is_async, community, page_rank, betweenness) VALUES`, 'ON CONFLICT (id) DO NOTHING');
97
+ }
98
+ async insertInterfaceNodes(nodes) {
99
+ if (nodes.length === 0)
100
+ return;
101
+ await this.batchInsert(nodes, 6, (node, offset) => ({
102
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6})`,
103
+ params: [
104
+ node.id,
105
+ node.name,
106
+ node.filePath,
107
+ node.lineStart,
108
+ node.lineEnd,
109
+ node.isExported,
110
+ ],
111
+ }), `INSERT INTO nodes_interface (id, name, file_path, line_start, line_end, is_exported) VALUES`, 'ON CONFLICT (id) DO NOTHING');
112
+ }
113
+ async insertTypeNodes(nodes) {
114
+ if (nodes.length === 0)
115
+ return;
116
+ await this.batchInsert(nodes, 7, (node, offset) => ({
117
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7})`,
118
+ params: [
119
+ node.id,
120
+ node.name,
121
+ node.kind,
122
+ node.filePath,
123
+ node.lineStart,
124
+ node.lineEnd,
125
+ node.isExported,
126
+ ],
127
+ }), `INSERT INTO nodes_type (id, name, kind, file_path, line_start, line_end, is_exported) VALUES`, 'ON CONFLICT (id) DO NOTHING');
128
+ }
129
+ async insertVariableNodes(nodes) {
130
+ if (nodes.length === 0)
131
+ return;
132
+ await this.batchInsert(nodes, 8, (node, offset) => ({
133
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7}, $${offset + 8})`,
134
+ params: [
135
+ node.id,
136
+ node.name,
137
+ node.scope,
138
+ node.filePath,
139
+ node.lineStart,
140
+ node.lineEnd,
141
+ node.isExported,
142
+ node.inferredType,
143
+ ],
144
+ }), `INSERT INTO nodes_variable (id, name, scope, file_path, line_start, line_end, is_exported, inferred_type) VALUES`, 'ON CONFLICT (id) DO NOTHING');
145
+ }
146
+ async insertModuleNodes(nodes) {
147
+ if (nodes.length === 0)
148
+ return;
149
+ await this.batchInsert(nodes, 3, (node, offset) => ({
150
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3})`,
151
+ params: [node.id, node.path, node.isBarrel],
152
+ }), `INSERT INTO nodes_module (id, path, is_barrel) VALUES`, 'ON CONFLICT (id) DO NOTHING');
153
+ }
154
+ async insertCallsEdges(edges) {
155
+ if (edges.length === 0)
156
+ return;
157
+ await this.batchInsert(edges, 9, (edge, offset) => ({
158
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7}, $${offset + 8}, $${offset + 9})`,
159
+ params: [
160
+ edge.sourceId,
161
+ edge.targetId,
162
+ edge.line,
163
+ edge.confidence,
164
+ edge.isDynamic,
165
+ edge.isAsync,
166
+ edge.isIndirect,
167
+ edge.stage,
168
+ edge.reason,
169
+ ],
170
+ }), `INSERT INTO edges_calls (source_id, target_id, line, confidence, is_dynamic, is_async, is_indirect, stage, reason) VALUES`);
171
+ }
172
+ async insertImportsEdges(edges) {
173
+ if (edges.length === 0)
174
+ return;
175
+ await this.batchInsert(edges, 9, (edge, offset) => ({
176
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7}, $${offset + 8}, $${offset + 9})`,
177
+ params: [
178
+ edge.sourceId,
179
+ edge.targetId,
180
+ edge.line,
181
+ edge.kind,
182
+ edge.originalName,
183
+ edge.alias,
184
+ edge.confidence,
185
+ edge.stage,
186
+ edge.reason,
187
+ ],
188
+ }), `INSERT INTO edges_imports (source_id, target_id, line, kind, original_name, alias, confidence, stage, reason) VALUES`);
189
+ }
190
+ async insertExtendsEdges(edges) {
191
+ if (edges.length === 0)
192
+ return;
193
+ await this.batchInsert(edges, 6, (edge, offset) => ({
194
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6})`,
195
+ params: [
196
+ edge.sourceId,
197
+ edge.targetId,
198
+ edge.line,
199
+ edge.confidence,
200
+ edge.stage,
201
+ edge.reason,
202
+ ],
203
+ }), `INSERT INTO edges_extends (source_id, target_id, line, confidence, stage, reason) VALUES`);
204
+ }
205
+ async insertImplementsEdges(edges) {
206
+ if (edges.length === 0)
207
+ return;
208
+ await this.batchInsert(edges, 6, (edge, offset) => ({
209
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6})`,
210
+ params: [
211
+ edge.sourceId,
212
+ edge.targetId,
213
+ edge.line,
214
+ edge.confidence,
215
+ edge.stage,
216
+ edge.reason,
217
+ ],
218
+ }), `INSERT INTO edges_implements (source_id, target_id, line, confidence, stage, reason) VALUES`);
219
+ }
220
+ async insertContainsEdges(edges) {
221
+ if (edges.length === 0)
222
+ return;
223
+ await this.batchInsert(edges, 5, (edge, offset) => ({
224
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5})`,
225
+ params: [edge.sourceId, edge.targetId, edge.confidence, edge.stage, edge.reason],
226
+ }), `INSERT INTO edges_contains (source_id, target_id, confidence, stage, reason) VALUES`);
227
+ }
228
+ async insertReturnsEdges(edges) {
229
+ if (edges.length === 0)
230
+ return;
231
+ await this.batchInsert(edges, 7, (edge, offset) => ({
232
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7})`,
233
+ params: [
234
+ edge.sourceId,
235
+ edge.targetId,
236
+ edge.line,
237
+ edge.returnType,
238
+ edge.confidence,
239
+ edge.stage,
240
+ edge.reason,
241
+ ],
242
+ }), `INSERT INTO edges_returns (source_id, target_id, line, return_type, confidence, stage, reason) VALUES`);
243
+ }
244
+ async insertReadsEdges(edges) {
245
+ if (edges.length === 0)
246
+ return;
247
+ await this.batchInsert(edges, 7, (edge, offset) => ({
248
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7})`,
249
+ params: [
250
+ edge.sourceId,
251
+ edge.targetId,
252
+ edge.line,
253
+ edge.field,
254
+ edge.confidence,
255
+ edge.stage,
256
+ edge.reason,
257
+ ],
258
+ }), `INSERT INTO edges_reads (source_id, target_id, line, field, confidence, stage, reason) VALUES`);
259
+ }
260
+ async insertWritesEdges(edges) {
261
+ if (edges.length === 0)
262
+ return;
263
+ await this.batchInsert(edges, 7, (edge, offset) => ({
264
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7})`,
265
+ params: [
266
+ edge.sourceId,
267
+ edge.targetId,
268
+ edge.line,
269
+ edge.field,
270
+ edge.confidence,
271
+ edge.stage,
272
+ edge.reason,
273
+ ],
274
+ }), `INSERT INTO edges_writes (source_id, target_id, line, field, confidence, stage, reason) VALUES`);
275
+ }
276
+ async insertFlowsToEdges(edges) {
277
+ if (edges.length === 0)
278
+ return;
279
+ await this.batchInsert(edges, 8, (edge, offset) => ({
280
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6}, $${offset + 7}, $${offset + 8})`,
281
+ params: [
282
+ edge.sourceId,
283
+ edge.targetId,
284
+ edge.parameterIndex,
285
+ edge.transform,
286
+ edge.taintLabel,
287
+ edge.confidence,
288
+ edge.stage,
289
+ edge.reason,
290
+ ],
291
+ }), `INSERT INTO edges_flows_to (source_id, target_id, parameter_index, transform, taint_label, confidence, stage, reason) VALUES`);
292
+ }
293
+ async getFunctionsByFile(filePath) {
294
+ const rows = await this.db.all('SELECT * FROM nodes_function WHERE file_path = $1', filePath);
295
+ return rows.map(this.mapFunctionNodeRow);
296
+ }
297
+ async getClassesByFile(filePath) {
298
+ const rows = await this.db.all('SELECT * FROM nodes_class WHERE file_path = $1', filePath);
299
+ return rows.map(this.mapClassNodeRow);
300
+ }
301
+ async getMethodsByFile(filePath) {
302
+ const rows = await this.db.all('SELECT * FROM nodes_method WHERE file_path = $1', filePath);
303
+ return rows.map(this.mapMethodNodeRow);
304
+ }
305
+ async getInterfacesByFile(filePath) {
306
+ const rows = await this.db.all('SELECT * FROM nodes_interface WHERE file_path = $1', filePath);
307
+ return rows.map(this.mapInterfaceNodeRow);
308
+ }
309
+ async getTypesByFile(filePath) {
310
+ const rows = await this.db.all('SELECT * FROM nodes_type WHERE file_path = $1', filePath);
311
+ return rows.map(this.mapTypeNodeRow);
312
+ }
313
+ async getVariablesByFile(filePath) {
314
+ const rows = await this.db.all('SELECT * FROM nodes_variable WHERE file_path = $1', filePath);
315
+ return rows.map(this.mapVariableNodeRow);
316
+ }
317
+ async deleteCallEdgesBySourceIds(sourceIds) {
318
+ if (sourceIds.length === 0)
319
+ return;
320
+ const placeholders = sourceIds.map((_, i) => `$${i + 1}`).join(', ');
321
+ await this.db.run(`DELETE FROM edges_calls WHERE source_id IN (${placeholders})`, ...sourceIds);
322
+ }
323
+ async getCallsFrom(sourceId) {
324
+ const rows = await this.db.all('SELECT * FROM edges_calls WHERE source_id = $1', sourceId);
325
+ return rows.map(this.mapCallsEdgeRow);
326
+ }
327
+ async getCallsTo(targetId) {
328
+ const rows = await this.db.all('SELECT * FROM edges_calls WHERE target_id = $1', targetId);
329
+ return rows.map(this.mapCallsEdgeRow);
330
+ }
331
+ async getContainedBy(sourceId) {
332
+ const rows = await this.db.all('SELECT * FROM edges_contains WHERE source_id = $1', sourceId);
333
+ return rows.map(this.mapContainsEdgeRow);
334
+ }
335
+ async getImportsFrom(sourceId) {
336
+ const rows = await this.db.all('SELECT * FROM edges_imports WHERE source_id = $1', sourceId);
337
+ return rows.map(this.mapImportsEdgeRow);
338
+ }
339
+ async getImportersOf(targetId) {
340
+ const rows = await this.db.all('SELECT * FROM edges_imports WHERE target_id = $1', targetId);
341
+ return rows.map(this.mapImportsEdgeRow);
342
+ }
343
+ async getImplementsFrom(sourceId) {
344
+ const rows = await this.db.all('SELECT * FROM edges_implements WHERE source_id = $1', sourceId);
345
+ return rows.map(this.mapImplementsEdgeRow);
346
+ }
347
+ async insertTypeConstraints(constraints) {
348
+ if (constraints.length === 0)
349
+ return;
350
+ const seen = new Set();
351
+ const deduped = constraints.filter((c) => {
352
+ const key = `${c.symbolId}\0${c.typeName}\0${c.source}`;
353
+ if (seen.has(key))
354
+ return false;
355
+ seen.add(key);
356
+ return true;
357
+ });
358
+ if (deduped.length === 0)
359
+ return;
360
+ await this.batchInsert(deduped, 6, (c, offset) => ({
361
+ placeholder: `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${offset + 6})`,
362
+ params: [c.symbolId, c.typeName, c.source, c.confidence, c.filePath, c.line],
363
+ }), `INSERT OR IGNORE INTO type_constraints (symbol_id, type_name, source, confidence, file_path, line) VALUES`);
364
+ }
365
+ async getTypeConstraints(symbolId) {
366
+ const rows = await this.db.all('SELECT * FROM type_constraints WHERE symbol_id = $1', symbolId);
367
+ return rows.map(this.mapTypeConstraintRow);
368
+ }
369
+ async getTypeConstraintsByType(typeName) {
370
+ const rows = await this.db.all('SELECT * FROM type_constraints WHERE type_name = $1', typeName);
371
+ return rows.map(this.mapTypeConstraintRow);
372
+ }
373
+ async deleteTypeConstraintsForFile(filePath) {
374
+ await this.db.run('DELETE FROM type_constraints WHERE file_path = $1', filePath);
375
+ }
376
+ async insertGenericInstantiations(insts) {
377
+ if (insts.length === 0)
378
+ return;
379
+ await this.db.exec('BEGIN TRANSACTION');
380
+ try {
381
+ for (const inst of insts) {
382
+ const listLiteral = `[${inst.typeArguments.map((a) => `'${a.replace(/'/g, "''")}'`).join(', ')}]`;
383
+ await this.db.run(`INSERT INTO generic_instantiations (symbol_id, generic_name, type_arguments, file_path, line)
384
+ VALUES ($1, $2, ${listLiteral}::VARCHAR[], $3, $4)`, inst.symbolId, inst.genericName, inst.filePath, inst.line);
385
+ }
386
+ await this.db.exec('COMMIT');
387
+ }
388
+ catch (err) {
389
+ await this.db.exec('ROLLBACK');
390
+ throw err;
391
+ }
392
+ }
393
+ async getGenericInstantiations(symbolId) {
394
+ const rows = await this.db.all('SELECT * FROM generic_instantiations WHERE symbol_id = $1', symbolId);
395
+ return rows.map(this.mapGenericInstantiationRow);
396
+ }
397
+ async deleteGenericInstantiationsForFile(filePath) {
398
+ await this.db.run('DELETE FROM generic_instantiations WHERE file_path = $1', filePath);
399
+ }
400
+ async getFlowsFrom(sourceId) {
401
+ const rows = await this.db.all('SELECT * FROM edges_flows_to WHERE source_id = $1', sourceId);
402
+ return rows.map(this.mapFlowsToEdgeRow);
403
+ }
404
+ async getFlowsTo(targetId) {
405
+ const rows = await this.db.all('SELECT * FROM edges_flows_to WHERE target_id = $1', targetId);
406
+ return rows.map(this.mapFlowsToEdgeRow);
407
+ }
408
+ async getReadsFrom(sourceId) {
409
+ const rows = await this.db.all('SELECT * FROM edges_reads WHERE source_id = $1', sourceId);
410
+ return rows.map(this.mapReadsEdgeRow);
411
+ }
412
+ async getReadsOf(targetId) {
413
+ const rows = await this.db.all('SELECT * FROM edges_reads WHERE target_id = $1', targetId);
414
+ return rows.map(this.mapReadsEdgeRow);
415
+ }
416
+ async getWritesFrom(sourceId) {
417
+ const rows = await this.db.all('SELECT * FROM edges_writes WHERE source_id = $1', sourceId);
418
+ return rows.map(this.mapWritesEdgeRow);
419
+ }
420
+ async getWritesTo(targetId) {
421
+ const rows = await this.db.all('SELECT * FROM edges_writes WHERE target_id = $1', targetId);
422
+ return rows.map(this.mapWritesEdgeRow);
423
+ }
424
+ async getReturnsFrom(sourceId) {
425
+ const rows = await this.db.all('SELECT * FROM edges_returns WHERE source_id = $1', sourceId);
426
+ return rows.map(this.mapReturnsEdgeRow);
427
+ }
428
+ async getReturnsTo(targetId) {
429
+ const rows = await this.db.all('SELECT * FROM edges_returns WHERE target_id = $1', targetId);
430
+ return rows.map(this.mapReturnsEdgeRow);
431
+ }
432
+ async getImplementorsOf(interfaceId) {
433
+ const rows = await this.db.all('SELECT * FROM edges_implements WHERE target_id = $1', interfaceId);
434
+ return rows.map(this.mapImplementsEdgeRow);
435
+ }
436
+ async getReferencesForSymbol(symbolId) {
437
+ const [callers, importers, extenders, implementors] = await Promise.all([
438
+ this.getCallsTo(symbolId),
439
+ this.getImportersOf(symbolId),
440
+ this.db.all('SELECT * FROM edges_extends WHERE target_id = $1', symbolId),
441
+ this.db.all('SELECT * FROM edges_implements WHERE target_id = $1', symbolId),
442
+ ]);
443
+ return {
444
+ callers,
445
+ importers,
446
+ extenders: extenders.map((r) => this.mapExtendsEdgeRow(r)),
447
+ implementors: implementors.map(this.mapImplementsEdgeRow),
448
+ };
449
+ }
450
+ async updateCallEdgeConfidence(sourceId, targetId, confidence, reason) {
451
+ await this.db.run('UPDATE edges_calls SET confidence = $3, reason = $4 WHERE source_id = $1 AND target_id = $2', sourceId, targetId, confidence, reason);
452
+ }
453
+ async updateCallEdgeAsync(sourceId, targetId, isAsync) {
454
+ await this.db.run('UPDATE edges_calls SET is_async = $3 WHERE source_id = $1 AND target_id = $2', sourceId, targetId, isAsync);
455
+ }
456
+ async updateEntryPointScore(functionId, score, isEntryPoint) {
457
+ await this.db.run('UPDATE nodes_function SET entry_point_score = $2, is_entry_point = $3 WHERE id = $1', functionId, score, isEntryPoint);
458
+ }
459
+ async updateVariableType(variableId, inferredType) {
460
+ await this.db.run('UPDATE nodes_variable SET inferred_type = $2 WHERE id = $1', variableId, inferredType);
461
+ }
462
+ async deleteFlowEdgesForFile(filePath) {
463
+ const nodeIds = await this.getNodeIdsForFile(filePath);
464
+ if (nodeIds.length === 0)
465
+ return;
466
+ const placeholders = nodeIds.map((_, i) => `$${i + 1}`).join(', ');
467
+ const flowTables = ['edges_flows_to', 'edges_reads', 'edges_writes', 'edges_returns'];
468
+ for (const table of flowTables) {
469
+ await this.db.run(`DELETE FROM ${table} WHERE source_id IN (${placeholders})`, ...nodeIds);
470
+ }
471
+ }
472
+ async deleteStageEdges(stage, filePath) {
473
+ const edgeTables = [
474
+ 'edges_calls',
475
+ 'edges_imports',
476
+ 'edges_extends',
477
+ 'edges_implements',
478
+ 'edges_contains',
479
+ 'edges_flows_to',
480
+ 'edges_reads',
481
+ 'edges_writes',
482
+ 'edges_returns',
483
+ ];
484
+ if (filePath) {
485
+ const nodeIds = await this.getNodeIdsForFile(filePath);
486
+ if (nodeIds.length === 0)
487
+ return;
488
+ const placeholders = nodeIds.map((_, i) => `$${i + 2}`).join(', ');
489
+ for (const table of edgeTables) {
490
+ await this.db.run(`DELETE FROM ${table} WHERE stage = $1 AND source_id IN (${placeholders})`, stage, ...nodeIds);
491
+ }
492
+ }
493
+ else {
494
+ for (const table of edgeTables) {
495
+ await this.db.run(`DELETE FROM ${table} WHERE stage = $1`, stage);
496
+ }
497
+ }
498
+ }
499
+ async getModuleNode(id) {
500
+ const rows = await this.db.all('SELECT * FROM nodes_module WHERE id = $1', id);
501
+ if (rows.length === 0)
502
+ return null;
503
+ return this.mapModuleNodeRow(rows[0]);
504
+ }
505
+ async deleteFileData(filePath) {
506
+ const nodeIds = await this.getNodeIdsForFile(filePath);
507
+ await this.db.exec('BEGIN TRANSACTION');
508
+ try {
509
+ await this.db.run('DELETE FROM nodes_function WHERE file_path = $1', filePath);
510
+ await this.db.run('DELETE FROM nodes_class WHERE file_path = $1', filePath);
511
+ await this.db.run('DELETE FROM nodes_method WHERE file_path = $1', filePath);
512
+ await this.db.run('DELETE FROM nodes_interface WHERE file_path = $1', filePath);
513
+ await this.db.run('DELETE FROM nodes_type WHERE file_path = $1', filePath);
514
+ await this.db.run('DELETE FROM nodes_variable WHERE file_path = $1', filePath);
515
+ await this.db.run('DELETE FROM nodes_file WHERE path = $1', filePath);
516
+ if (nodeIds.length > 0) {
517
+ const placeholders = nodeIds.map((_, i) => `$${i + 1}`).join(', ');
518
+ const edgeTables = [
519
+ 'edges_calls',
520
+ 'edges_imports',
521
+ 'edges_extends',
522
+ 'edges_implements',
523
+ 'edges_contains',
524
+ 'edges_flows_to',
525
+ 'edges_reads',
526
+ 'edges_writes',
527
+ 'edges_returns',
528
+ ];
529
+ for (const table of edgeTables) {
530
+ await this.db.run(`DELETE FROM ${table} WHERE source_id IN (${placeholders})`, ...nodeIds);
531
+ await this.db.run(`DELETE FROM ${table} WHERE target_id IN (${placeholders})`, ...nodeIds);
532
+ }
533
+ }
534
+ await this.db.exec('COMMIT');
535
+ }
536
+ catch (err) {
537
+ await this.db.exec('ROLLBACK');
538
+ throw err;
539
+ }
540
+ }
541
+ async getNodeIdsForFile(filePath) {
542
+ const rows = await this.db.all(`SELECT id FROM nodes_function WHERE file_path = $1
543
+ UNION ALL
544
+ SELECT id FROM nodes_class WHERE file_path = $1
545
+ UNION ALL
546
+ SELECT id FROM nodes_method WHERE file_path = $1
547
+ UNION ALL
548
+ SELECT id FROM nodes_interface WHERE file_path = $1
549
+ UNION ALL
550
+ SELECT id FROM nodes_type WHERE file_path = $1
551
+ UNION ALL
552
+ SELECT id FROM nodes_variable WHERE file_path = $1
553
+ UNION ALL
554
+ SELECT id FROM nodes_file WHERE path = $1`, filePath);
555
+ return rows.map((r) => r.id);
556
+ }
557
+ async getStats() {
558
+ const rows = await this.db.all(`SELECT
559
+ (SELECT COUNT(*) FROM nodes_file) as files,
560
+ (SELECT COUNT(*) FROM nodes_function) as functions,
561
+ (SELECT COUNT(*) FROM nodes_class) as classes,
562
+ (SELECT COUNT(*) FROM nodes_method) as methods,
563
+ (SELECT COUNT(*) FROM nodes_interface) as interfaces,
564
+ (SELECT COUNT(*) FROM nodes_type) as types,
565
+ (SELECT COUNT(*) FROM nodes_variable) as variables,
566
+ (SELECT COUNT(*) FROM nodes_module) as modules,
567
+ (SELECT COUNT(*) FROM edges_calls) as calls,
568
+ (SELECT COUNT(*) FROM edges_imports) as imports,
569
+ (SELECT COUNT(*) FROM edges_extends) as extends_count,
570
+ (SELECT COUNT(*) FROM edges_implements) as implements_count,
571
+ (SELECT COUNT(*) FROM edges_contains) as contains,
572
+ (SELECT COUNT(*) FROM edges_flows_to) as flows_to,
573
+ (SELECT COUNT(*) FROM edges_reads) as reads,
574
+ (SELECT COUNT(*) FROM edges_writes) as writes,
575
+ (SELECT COUNT(*) FROM edges_returns) as returns,
576
+ (SELECT COUNT(*) FROM type_constraints) as type_constraints,
577
+ (SELECT COUNT(*) FROM generic_instantiations) as generic_instantiations`);
578
+ const row = rows[0];
579
+ return {
580
+ files: Number(row.files),
581
+ functions: Number(row.functions),
582
+ classes: Number(row.classes),
583
+ methods: Number(row.methods),
584
+ interfaces: Number(row.interfaces),
585
+ types: Number(row.types),
586
+ variables: Number(row.variables),
587
+ modules: Number(row.modules),
588
+ calls: Number(row.calls),
589
+ imports: Number(row.imports),
590
+ extends: Number(row.extends_count),
591
+ implements: Number(row.implements_count),
592
+ contains: Number(row.contains),
593
+ flowsTo: Number(row.flows_to),
594
+ reads: Number(row.reads),
595
+ writes: Number(row.writes),
596
+ returns: Number(row.returns),
597
+ typeConstraints: Number(row.type_constraints),
598
+ genericInstantiations: Number(row.generic_instantiations),
599
+ };
600
+ }
601
+ async getAllSymbols() {
602
+ const rows = await this.db.all('SELECT * FROM symbols');
603
+ return rows.map((r) => ({
604
+ id: r.id,
605
+ name: r.name,
606
+ filePath: r.file_path,
607
+ lineStart: r.line_start,
608
+ lineEnd: r.line_end,
609
+ kind: r.kind,
610
+ }));
611
+ }
612
+ async getSymbolById(id) {
613
+ const rows = await this.db.all('SELECT * FROM symbols WHERE id = $1', id);
614
+ if (rows.length === 0)
615
+ return null;
616
+ const r = rows[0];
617
+ return {
618
+ id: r.id,
619
+ name: r.name,
620
+ filePath: r.file_path,
621
+ lineStart: r.line_start,
622
+ lineEnd: r.line_end,
623
+ kind: r.kind,
624
+ };
625
+ }
626
+ async getSymbolByName(name) {
627
+ const rows = await this.db.all('SELECT * FROM symbols WHERE name = $1', name);
628
+ return rows.map((r) => ({
629
+ id: r.id,
630
+ name: r.name,
631
+ filePath: r.file_path,
632
+ lineStart: r.line_start,
633
+ lineEnd: r.line_end,
634
+ kind: r.kind,
635
+ }));
636
+ }
637
+ async getSymbolTable(fileId) {
638
+ const rows = await this.db.all('SELECT * FROM cortex_meta WHERE key = $1', `symbol_table:${fileId}`);
639
+ if (rows.length === 0)
640
+ return null;
641
+ const entries = JSON.parse(rows[0].value);
642
+ return new Map(entries);
643
+ }
644
+ async setSymbolTable(fileId, table) {
645
+ const serialized = JSON.stringify([...table.entries()]);
646
+ await this.db.run(`INSERT INTO cortex_meta (key, value) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET value = excluded.value`, `symbol_table:${fileId}`, serialized);
647
+ }
648
+ async insertFlows(flows) {
649
+ if (flows.length === 0)
650
+ return;
651
+ await this.db.exec('BEGIN TRANSACTION');
652
+ try {
653
+ for (const flow of flows) {
654
+ const listLiteral = `[${flow.nodeIds.map((n) => `'${n.replace(/'/g, "''")}'`).join(', ')}]`;
655
+ await this.db.run(`INSERT INTO cortex_flows (id, name, entry_point_id, node_ids, has_async, has_error_path)
656
+ VALUES ($1, $2, $3, ${listLiteral}::VARCHAR[], $4, $5)
657
+ ON CONFLICT (id) DO UPDATE SET name = excluded.name, node_ids = excluded.node_ids,
658
+ has_async = excluded.has_async, has_error_path = excluded.has_error_path`, flow.id, flow.name, flow.entryPointId, flow.hasAsync, flow.hasErrorPath);
659
+ }
660
+ await this.db.exec('COMMIT');
661
+ }
662
+ catch (err) {
663
+ await this.db.exec('ROLLBACK');
664
+ throw err;
665
+ }
666
+ }
667
+ async getFlowsByEntryPoint(entryPointId) {
668
+ const rows = await this.db.all('SELECT * FROM cortex_flows WHERE entry_point_id = $1', entryPointId);
669
+ return rows.map(this.mapCortexFlowRow);
670
+ }
671
+ async deleteFlowsForFile(filePath) {
672
+ await this.db.run(`DELETE FROM cortex_flows WHERE entry_point_id LIKE 'fn:' || $1 || '%' OR entry_point_id LIKE 'method:' || $1 || '%'`, filePath);
673
+ }
674
+ async batchInsert(items, colCount, mapItem, sqlPrefix, sqlSuffix = '') {
675
+ await this.db.exec('BEGIN TRANSACTION');
676
+ try {
677
+ for (let i = 0; i < items.length; i += CHUNK_SIZE) {
678
+ const chunk = items.slice(i, i + CHUNK_SIZE);
679
+ const placeholders = [];
680
+ const params = [];
681
+ for (let j = 0; j < chunk.length; j++) {
682
+ const offset = j * colCount;
683
+ const mapped = mapItem(chunk[j], offset);
684
+ placeholders.push(mapped.placeholder);
685
+ params.push(...mapped.params);
686
+ }
687
+ await this.db.run(`${sqlPrefix} ${placeholders.join(', ')}${sqlSuffix ? ' ' + sqlSuffix : ''}`, ...params);
688
+ }
689
+ await this.db.exec('COMMIT');
690
+ }
691
+ catch (err) {
692
+ await this.db.exec('ROLLBACK');
693
+ throw err;
694
+ }
695
+ }
696
+ mapFileNodeRow(row) {
697
+ return {
698
+ id: row.id,
699
+ path: row.path,
700
+ hash: row.hash,
701
+ language: row.language,
702
+ depthLevel: row.depth_level,
703
+ lastIndexed: row.last_indexed ? new Date(row.last_indexed) : null,
704
+ };
705
+ }
706
+ mapFunctionNodeRow(row) {
707
+ return {
708
+ id: row.id,
709
+ name: row.name,
710
+ qualifiedName: row.qualified_name,
711
+ filePath: row.file_path,
712
+ lineStart: row.line_start,
713
+ lineEnd: row.line_end,
714
+ isAsync: row.is_async,
715
+ isExported: row.is_exported,
716
+ isEntryPoint: row.is_entry_point,
717
+ entryPointScore: row.entry_point_score,
718
+ signature: row.signature,
719
+ community: row.community,
720
+ pageRank: row.page_rank,
721
+ betweenness: row.betweenness,
722
+ };
723
+ }
724
+ mapClassNodeRow(row) {
725
+ return {
726
+ id: row.id,
727
+ name: row.name,
728
+ filePath: row.file_path,
729
+ lineStart: row.line_start,
730
+ lineEnd: row.line_end,
731
+ isAbstract: row.is_abstract,
732
+ isExported: row.is_exported,
733
+ community: row.community,
734
+ pageRank: row.page_rank,
735
+ betweenness: row.betweenness,
736
+ };
737
+ }
738
+ mapMethodNodeRow(row) {
739
+ return {
740
+ id: row.id,
741
+ name: row.name,
742
+ className: row.class_name,
743
+ qualifiedName: row.qualified_name,
744
+ filePath: row.file_path,
745
+ lineStart: row.line_start,
746
+ lineEnd: row.line_end,
747
+ visibility: row.visibility,
748
+ isStatic: row.is_static,
749
+ isAsync: row.is_async,
750
+ community: row.community,
751
+ pageRank: row.page_rank,
752
+ betweenness: row.betweenness,
753
+ };
754
+ }
755
+ mapInterfaceNodeRow(row) {
756
+ return {
757
+ id: row.id,
758
+ name: row.name,
759
+ filePath: row.file_path,
760
+ lineStart: row.line_start,
761
+ lineEnd: row.line_end,
762
+ isExported: row.is_exported,
763
+ };
764
+ }
765
+ mapTypeNodeRow(row) {
766
+ return {
767
+ id: row.id,
768
+ name: row.name,
769
+ kind: row.kind,
770
+ filePath: row.file_path,
771
+ lineStart: row.line_start,
772
+ lineEnd: row.line_end,
773
+ isExported: row.is_exported,
774
+ };
775
+ }
776
+ mapVariableNodeRow(row) {
777
+ return {
778
+ id: row.id,
779
+ name: row.name,
780
+ scope: row.scope,
781
+ filePath: row.file_path,
782
+ lineStart: row.line_start,
783
+ lineEnd: row.line_end,
784
+ isExported: row.is_exported,
785
+ inferredType: row.inferred_type,
786
+ };
787
+ }
788
+ mapModuleNodeRow(row) {
789
+ return {
790
+ id: row.id,
791
+ path: row.path,
792
+ isBarrel: row.is_barrel,
793
+ };
794
+ }
795
+ mapCallsEdgeRow(row) {
796
+ return {
797
+ sourceId: row.source_id,
798
+ targetId: row.target_id,
799
+ line: row.line,
800
+ confidence: row.confidence,
801
+ isDynamic: row.is_dynamic,
802
+ isAsync: row.is_async,
803
+ isIndirect: row.is_indirect,
804
+ stage: row.stage,
805
+ reason: row.reason,
806
+ };
807
+ }
808
+ mapImportsEdgeRow(row) {
809
+ return {
810
+ sourceId: row.source_id,
811
+ targetId: row.target_id,
812
+ line: row.line,
813
+ kind: row.kind,
814
+ originalName: row.original_name,
815
+ alias: row.alias,
816
+ confidence: row.confidence,
817
+ stage: row.stage,
818
+ reason: row.reason,
819
+ };
820
+ }
821
+ mapExtendsEdgeRow(row) {
822
+ return {
823
+ sourceId: row.source_id,
824
+ targetId: row.target_id,
825
+ line: row.line,
826
+ confidence: row.confidence,
827
+ stage: row.stage,
828
+ reason: row.reason,
829
+ };
830
+ }
831
+ mapImplementsEdgeRow(row) {
832
+ return {
833
+ sourceId: row.source_id,
834
+ targetId: row.target_id,
835
+ line: row.line,
836
+ confidence: row.confidence,
837
+ stage: row.stage,
838
+ reason: row.reason,
839
+ };
840
+ }
841
+ mapContainsEdgeRow(row) {
842
+ return {
843
+ sourceId: row.source_id,
844
+ targetId: row.target_id,
845
+ confidence: row.confidence,
846
+ stage: row.stage,
847
+ reason: row.reason,
848
+ };
849
+ }
850
+ mapFlowsToEdgeRow(row) {
851
+ return {
852
+ sourceId: row.source_id,
853
+ targetId: row.target_id,
854
+ parameterIndex: row.parameter_index,
855
+ transform: row.transform,
856
+ taintLabel: row.taint_label,
857
+ confidence: row.confidence,
858
+ stage: row.stage,
859
+ reason: row.reason,
860
+ };
861
+ }
862
+ mapReadsEdgeRow(row) {
863
+ return {
864
+ sourceId: row.source_id,
865
+ targetId: row.target_id,
866
+ line: row.line,
867
+ field: row.field,
868
+ confidence: row.confidence,
869
+ stage: row.stage,
870
+ reason: row.reason,
871
+ };
872
+ }
873
+ mapWritesEdgeRow(row) {
874
+ return {
875
+ sourceId: row.source_id,
876
+ targetId: row.target_id,
877
+ line: row.line,
878
+ field: row.field,
879
+ confidence: row.confidence,
880
+ stage: row.stage,
881
+ reason: row.reason,
882
+ };
883
+ }
884
+ mapReturnsEdgeRow(row) {
885
+ return {
886
+ sourceId: row.source_id,
887
+ targetId: row.target_id,
888
+ line: row.line,
889
+ returnType: row.return_type,
890
+ confidence: row.confidence,
891
+ stage: row.stage,
892
+ reason: row.reason,
893
+ };
894
+ }
895
+ mapTypeConstraintRow(row) {
896
+ return {
897
+ symbolId: row.symbol_id,
898
+ typeName: row.type_name,
899
+ source: row.source,
900
+ confidence: row.confidence,
901
+ filePath: row.file_path,
902
+ line: row.line,
903
+ };
904
+ }
905
+ mapGenericInstantiationRow(row) {
906
+ const rawArgs = row.type_arguments;
907
+ const typeArguments = Array.isArray(rawArgs)
908
+ ? rawArgs
909
+ : Array.from(rawArgs.items);
910
+ return {
911
+ symbolId: row.symbol_id,
912
+ genericName: row.generic_name,
913
+ typeArguments,
914
+ filePath: row.file_path,
915
+ line: row.line,
916
+ };
917
+ }
918
+ // --- Single-item insert/get methods for topology tests ---
919
+ async insertFunction(node) {
920
+ await this.insertFunctionNodes([node]);
921
+ }
922
+ async getFunction(id) {
923
+ const rows = await this.db.all('SELECT * FROM nodes_function WHERE id = $1', id);
924
+ if (rows.length === 0)
925
+ return null;
926
+ return this.mapFunctionNodeRow(rows[0]);
927
+ }
928
+ async insertClass(node) {
929
+ await this.insertClassNodes([node]);
930
+ }
931
+ async getClass(id) {
932
+ const rows = await this.db.all('SELECT * FROM nodes_class WHERE id = $1', id);
933
+ if (rows.length === 0)
934
+ return null;
935
+ return this.mapClassNodeRow(rows[0]);
936
+ }
937
+ async insertMethod(node) {
938
+ await this.insertMethodNodes([node]);
939
+ }
940
+ async getMethod(id) {
941
+ const rows = await this.db.all('SELECT * FROM nodes_method WHERE id = $1', id);
942
+ if (rows.length === 0)
943
+ return null;
944
+ return this.mapMethodNodeRow(rows[0]);
945
+ }
946
+ async insertFileNode(node) {
947
+ await this.upsertFileNode({
948
+ id: node.id,
949
+ path: node.path,
950
+ hash: null,
951
+ language: node.language,
952
+ depthLevel: node.depthLevel,
953
+ lastIndexed: null,
954
+ });
955
+ }
956
+ // --- Topology write-back methods ---
957
+ async updateNodeMetrics(nodeId, metrics) {
958
+ const table = this.nodeTableForId(nodeId);
959
+ if (!table)
960
+ return;
961
+ await this.db.run(`UPDATE ${table} SET community = $1, page_rank = $2, betweenness = $3 WHERE id = $4`, metrics.community, metrics.pageRank, metrics.betweenness, nodeId);
962
+ }
963
+ async updateNodeMetricsBatch(updates) {
964
+ for (const update of updates) {
965
+ await this.updateNodeMetrics(update.nodeId, update);
966
+ }
967
+ }
968
+ // --- Generic meta CRUD ---
969
+ async getMeta(key) {
970
+ const rows = await this.db.all('SELECT * FROM cortex_meta WHERE key = $1', key);
971
+ if (rows.length === 0)
972
+ return null;
973
+ return rows[0].value;
974
+ }
975
+ async setMeta(key, value) {
976
+ await this.db.run('INSERT INTO cortex_meta (key, value) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET value = excluded.value', key, value);
977
+ }
978
+ // --- Topology queries ---
979
+ async getMaxDepthLevel() {
980
+ const rows = await this.db.all('SELECT MAX(depth_level) as max_depth FROM nodes_file');
981
+ if (rows.length === 0)
982
+ return 0;
983
+ return Number(rows[0].max_depth) || 0;
984
+ }
985
+ async getAllFunctions() {
986
+ const rows = await this.db.all('SELECT * FROM nodes_function');
987
+ return rows.map((r) => this.mapFunctionNodeRow(r));
988
+ }
989
+ async getAllClasses() {
990
+ const rows = await this.db.all('SELECT * FROM nodes_class');
991
+ return rows.map((r) => this.mapClassNodeRow(r));
992
+ }
993
+ async getAllMethods() {
994
+ const rows = await this.db.all('SELECT * FROM nodes_method');
995
+ return rows.map((r) => this.mapMethodNodeRow(r));
996
+ }
997
+ // --- Single-item flow CRUD ---
998
+ async insertFlow(flow) {
999
+ await this.insertFlows([flow]);
1000
+ }
1001
+ async getFlow(id) {
1002
+ const rows = await this.db.all('SELECT * FROM cortex_flows WHERE id = $1', id);
1003
+ if (rows.length === 0)
1004
+ return null;
1005
+ return this.mapCortexFlowRow(rows[0]);
1006
+ }
1007
+ async getAllFlows() {
1008
+ const rows = await this.db.all('SELECT * FROM cortex_flows');
1009
+ return rows.map((r) => this.mapCortexFlowRow(r));
1010
+ }
1011
+ async deleteAllFlows() {
1012
+ await this.db.run('DELETE FROM cortex_flows');
1013
+ }
1014
+ // --- Temporal snapshot CRUD ---
1015
+ async insertTemporalSnapshot(snapshot) {
1016
+ await this.db.run(`INSERT INTO cortex_temporal_snapshots
1017
+ (commit_hash, timestamp, node_counts, edge_counts, community_hash, top_pagerank, hotspot_rankings)
1018
+ VALUES ($1, $2, $3, $4, $5, $6, $7)`, snapshot.commitHash, snapshot.timestamp.toISOString(), JSON.stringify(snapshot.nodeCounts), JSON.stringify(snapshot.edgeCounts), snapshot.communityHash, JSON.stringify(snapshot.topPagerank), JSON.stringify(snapshot.hotspotRankings));
1019
+ }
1020
+ async getTemporalSnapshots(limit) {
1021
+ const rows = await this.db.all('SELECT * FROM cortex_temporal_snapshots ORDER BY timestamp DESC LIMIT $1', limit);
1022
+ return rows.map((r) => this.mapSnapshotRow(r));
1023
+ }
1024
+ // --- Private helpers ---
1025
+ nodeTableForId(nodeId) {
1026
+ if (nodeId.startsWith('fn:'))
1027
+ return 'nodes_function';
1028
+ if (nodeId.startsWith('class:'))
1029
+ return 'nodes_class';
1030
+ if (nodeId.startsWith('method:'))
1031
+ return 'nodes_method';
1032
+ if (nodeId.startsWith('iface:'))
1033
+ return 'nodes_interface';
1034
+ if (nodeId.startsWith('type:'))
1035
+ return 'nodes_type';
1036
+ if (nodeId.startsWith('var:'))
1037
+ return 'nodes_variable';
1038
+ if (nodeId.startsWith('file:'))
1039
+ return 'nodes_file';
1040
+ if (nodeId.startsWith('module:'))
1041
+ return 'nodes_module';
1042
+ return null;
1043
+ }
1044
+ mapCortexFlowRow(row) {
1045
+ const rawIds = row.node_ids;
1046
+ const nodeIds = Array.isArray(rawIds)
1047
+ ? rawIds
1048
+ : Array.from(rawIds.items);
1049
+ return {
1050
+ id: row.id,
1051
+ name: row.name,
1052
+ entryPointId: row.entry_point_id,
1053
+ nodeIds,
1054
+ hasAsync: row.has_async,
1055
+ hasErrorPath: row.has_error_path,
1056
+ };
1057
+ }
1058
+ mapSnapshotRow(row) {
1059
+ return {
1060
+ commitHash: row.commit_hash,
1061
+ timestamp: new Date(row.timestamp),
1062
+ nodeCounts: typeof row.node_counts === 'string'
1063
+ ? JSON.parse(row.node_counts)
1064
+ : row.node_counts,
1065
+ edgeCounts: typeof row.edge_counts === 'string'
1066
+ ? JSON.parse(row.edge_counts)
1067
+ : row.edge_counts,
1068
+ communityHash: row.community_hash,
1069
+ topPagerank: typeof row.top_pagerank === 'string'
1070
+ ? JSON.parse(row.top_pagerank)
1071
+ : row.top_pagerank,
1072
+ hotspotRankings: typeof row.hotspot_rankings === 'string'
1073
+ ? JSON.parse(row.hotspot_rankings)
1074
+ : row.hotspot_rankings,
1075
+ };
1076
+ }
1077
+ }
1078
+ //# sourceMappingURL=repository.js.map