@stupidloud/codegraph 0.7.7

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 (340) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +482 -0
  3. package/dist/bin/codegraph.d.ts +21 -0
  4. package/dist/bin/codegraph.d.ts.map +1 -0
  5. package/dist/bin/codegraph.js +1296 -0
  6. package/dist/bin/codegraph.js.map +1 -0
  7. package/dist/bin/node-version-check.d.ts +17 -0
  8. package/dist/bin/node-version-check.d.ts.map +1 -0
  9. package/dist/bin/node-version-check.js +39 -0
  10. package/dist/bin/node-version-check.js.map +1 -0
  11. package/dist/bin/uninstall.d.ts +14 -0
  12. package/dist/bin/uninstall.d.ts.map +1 -0
  13. package/dist/bin/uninstall.js +148 -0
  14. package/dist/bin/uninstall.js.map +1 -0
  15. package/dist/config.d.ts +51 -0
  16. package/dist/config.d.ts.map +1 -0
  17. package/dist/config.js +342 -0
  18. package/dist/config.js.map +1 -0
  19. package/dist/context/formatter.d.ts +30 -0
  20. package/dist/context/formatter.d.ts.map +1 -0
  21. package/dist/context/formatter.js +244 -0
  22. package/dist/context/formatter.js.map +1 -0
  23. package/dist/context/index.d.ts +99 -0
  24. package/dist/context/index.d.ts.map +1 -0
  25. package/dist/context/index.js +1075 -0
  26. package/dist/context/index.js.map +1 -0
  27. package/dist/db/index.d.ts +72 -0
  28. package/dist/db/index.d.ts.map +1 -0
  29. package/dist/db/index.js +200 -0
  30. package/dist/db/index.js.map +1 -0
  31. package/dist/db/migrations.d.ts +44 -0
  32. package/dist/db/migrations.d.ts.map +1 -0
  33. package/dist/db/migrations.js +160 -0
  34. package/dist/db/migrations.js.map +1 -0
  35. package/dist/db/queries.d.ts +253 -0
  36. package/dist/db/queries.d.ts.map +1 -0
  37. package/dist/db/queries.js +1202 -0
  38. package/dist/db/queries.js.map +1 -0
  39. package/dist/db/schema.sql +169 -0
  40. package/dist/db/sqlite-adapter.d.ts +52 -0
  41. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  42. package/dist/db/sqlite-adapter.js +237 -0
  43. package/dist/db/sqlite-adapter.js.map +1 -0
  44. package/dist/directory.d.ts +57 -0
  45. package/dist/directory.d.ts.map +1 -0
  46. package/dist/directory.js +264 -0
  47. package/dist/directory.js.map +1 -0
  48. package/dist/errors.d.ts +136 -0
  49. package/dist/errors.d.ts.map +1 -0
  50. package/dist/errors.js +219 -0
  51. package/dist/errors.js.map +1 -0
  52. package/dist/extraction/dfm-extractor.d.ts +31 -0
  53. package/dist/extraction/dfm-extractor.d.ts.map +1 -0
  54. package/dist/extraction/dfm-extractor.js +151 -0
  55. package/dist/extraction/dfm-extractor.js.map +1 -0
  56. package/dist/extraction/grammars.d.ts +78 -0
  57. package/dist/extraction/grammars.d.ts.map +1 -0
  58. package/dist/extraction/grammars.js +322 -0
  59. package/dist/extraction/grammars.js.map +1 -0
  60. package/dist/extraction/index.d.ts +130 -0
  61. package/dist/extraction/index.d.ts.map +1 -0
  62. package/dist/extraction/index.js +1279 -0
  63. package/dist/extraction/index.js.map +1 -0
  64. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  65. package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  66. package/dist/extraction/languages/c-cpp.js +126 -0
  67. package/dist/extraction/languages/c-cpp.js.map +1 -0
  68. package/dist/extraction/languages/csharp.d.ts +3 -0
  69. package/dist/extraction/languages/csharp.d.ts.map +1 -0
  70. package/dist/extraction/languages/csharp.js +72 -0
  71. package/dist/extraction/languages/csharp.js.map +1 -0
  72. package/dist/extraction/languages/dart.d.ts +3 -0
  73. package/dist/extraction/languages/dart.d.ts.map +1 -0
  74. package/dist/extraction/languages/dart.js +192 -0
  75. package/dist/extraction/languages/dart.js.map +1 -0
  76. package/dist/extraction/languages/go.d.ts +3 -0
  77. package/dist/extraction/languages/go.d.ts.map +1 -0
  78. package/dist/extraction/languages/go.js +58 -0
  79. package/dist/extraction/languages/go.js.map +1 -0
  80. package/dist/extraction/languages/index.d.ts +10 -0
  81. package/dist/extraction/languages/index.d.ts.map +1 -0
  82. package/dist/extraction/languages/index.js +45 -0
  83. package/dist/extraction/languages/index.js.map +1 -0
  84. package/dist/extraction/languages/java.d.ts +3 -0
  85. package/dist/extraction/languages/java.d.ts.map +1 -0
  86. package/dist/extraction/languages/java.js +64 -0
  87. package/dist/extraction/languages/java.js.map +1 -0
  88. package/dist/extraction/languages/javascript.d.ts +3 -0
  89. package/dist/extraction/languages/javascript.d.ts.map +1 -0
  90. package/dist/extraction/languages/javascript.js +90 -0
  91. package/dist/extraction/languages/javascript.js.map +1 -0
  92. package/dist/extraction/languages/kotlin.d.ts +3 -0
  93. package/dist/extraction/languages/kotlin.d.ts.map +1 -0
  94. package/dist/extraction/languages/kotlin.js +253 -0
  95. package/dist/extraction/languages/kotlin.js.map +1 -0
  96. package/dist/extraction/languages/pascal.d.ts +3 -0
  97. package/dist/extraction/languages/pascal.d.ts.map +1 -0
  98. package/dist/extraction/languages/pascal.js +66 -0
  99. package/dist/extraction/languages/pascal.js.map +1 -0
  100. package/dist/extraction/languages/php.d.ts +3 -0
  101. package/dist/extraction/languages/php.d.ts.map +1 -0
  102. package/dist/extraction/languages/php.js +107 -0
  103. package/dist/extraction/languages/php.js.map +1 -0
  104. package/dist/extraction/languages/python.d.ts +3 -0
  105. package/dist/extraction/languages/python.d.ts.map +1 -0
  106. package/dist/extraction/languages/python.js +56 -0
  107. package/dist/extraction/languages/python.js.map +1 -0
  108. package/dist/extraction/languages/ruby.d.ts +3 -0
  109. package/dist/extraction/languages/ruby.d.ts.map +1 -0
  110. package/dist/extraction/languages/ruby.js +114 -0
  111. package/dist/extraction/languages/ruby.js.map +1 -0
  112. package/dist/extraction/languages/rust.d.ts +3 -0
  113. package/dist/extraction/languages/rust.d.ts.map +1 -0
  114. package/dist/extraction/languages/rust.js +109 -0
  115. package/dist/extraction/languages/rust.js.map +1 -0
  116. package/dist/extraction/languages/scala.d.ts +3 -0
  117. package/dist/extraction/languages/scala.d.ts.map +1 -0
  118. package/dist/extraction/languages/scala.js +139 -0
  119. package/dist/extraction/languages/scala.js.map +1 -0
  120. package/dist/extraction/languages/swift.d.ts +3 -0
  121. package/dist/extraction/languages/swift.d.ts.map +1 -0
  122. package/dist/extraction/languages/swift.js +91 -0
  123. package/dist/extraction/languages/swift.js.map +1 -0
  124. package/dist/extraction/languages/typescript.d.ts +3 -0
  125. package/dist/extraction/languages/typescript.d.ts.map +1 -0
  126. package/dist/extraction/languages/typescript.js +129 -0
  127. package/dist/extraction/languages/typescript.js.map +1 -0
  128. package/dist/extraction/liquid-extractor.d.ts +52 -0
  129. package/dist/extraction/liquid-extractor.d.ts.map +1 -0
  130. package/dist/extraction/liquid-extractor.js +313 -0
  131. package/dist/extraction/liquid-extractor.js.map +1 -0
  132. package/dist/extraction/parse-worker.d.ts +8 -0
  133. package/dist/extraction/parse-worker.d.ts.map +1 -0
  134. package/dist/extraction/parse-worker.js +94 -0
  135. package/dist/extraction/parse-worker.js.map +1 -0
  136. package/dist/extraction/svelte-extractor.d.ts +56 -0
  137. package/dist/extraction/svelte-extractor.d.ts.map +1 -0
  138. package/dist/extraction/svelte-extractor.js +272 -0
  139. package/dist/extraction/svelte-extractor.js.map +1 -0
  140. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  141. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  142. package/dist/extraction/tree-sitter-helpers.js +103 -0
  143. package/dist/extraction/tree-sitter-helpers.js.map +1 -0
  144. package/dist/extraction/tree-sitter-types.d.ts +179 -0
  145. package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  146. package/dist/extraction/tree-sitter-types.js +10 -0
  147. package/dist/extraction/tree-sitter-types.js.map +1 -0
  148. package/dist/extraction/tree-sitter.d.ts +233 -0
  149. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  150. package/dist/extraction/tree-sitter.js +2393 -0
  151. package/dist/extraction/tree-sitter.js.map +1 -0
  152. package/dist/extraction/vue-extractor.d.ts +36 -0
  153. package/dist/extraction/vue-extractor.d.ts.map +1 -0
  154. package/dist/extraction/vue-extractor.js +163 -0
  155. package/dist/extraction/vue-extractor.js.map +1 -0
  156. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  157. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  158. package/dist/graph/index.d.ts +8 -0
  159. package/dist/graph/index.d.ts.map +1 -0
  160. package/dist/graph/index.js +13 -0
  161. package/dist/graph/index.js.map +1 -0
  162. package/dist/graph/queries.d.ts +106 -0
  163. package/dist/graph/queries.d.ts.map +1 -0
  164. package/dist/graph/queries.js +366 -0
  165. package/dist/graph/queries.js.map +1 -0
  166. package/dist/graph/traversal.d.ts +127 -0
  167. package/dist/graph/traversal.d.ts.map +1 -0
  168. package/dist/graph/traversal.js +493 -0
  169. package/dist/graph/traversal.js.map +1 -0
  170. package/dist/index.d.ts +504 -0
  171. package/dist/index.d.ts.map +1 -0
  172. package/dist/index.js +982 -0
  173. package/dist/index.js.map +1 -0
  174. package/dist/installer/claude-md-template.d.ts +10 -0
  175. package/dist/installer/claude-md-template.d.ts.map +1 -0
  176. package/dist/installer/claude-md-template.js +46 -0
  177. package/dist/installer/claude-md-template.js.map +1 -0
  178. package/dist/installer/config-writer.d.ts +36 -0
  179. package/dist/installer/config-writer.d.ts.map +1 -0
  180. package/dist/installer/config-writer.js +304 -0
  181. package/dist/installer/config-writer.js.map +1 -0
  182. package/dist/installer/index.d.ts +12 -0
  183. package/dist/installer/index.d.ts.map +1 -0
  184. package/dist/installer/index.js +201 -0
  185. package/dist/installer/index.js.map +1 -0
  186. package/dist/mcp/index.d.ts +82 -0
  187. package/dist/mcp/index.d.ts.map +1 -0
  188. package/dist/mcp/index.js +330 -0
  189. package/dist/mcp/index.js.map +1 -0
  190. package/dist/mcp/server-instructions.d.ts +19 -0
  191. package/dist/mcp/server-instructions.d.ts.map +1 -0
  192. package/dist/mcp/server-instructions.js +59 -0
  193. package/dist/mcp/server-instructions.js.map +1 -0
  194. package/dist/mcp/tools.d.ts +187 -0
  195. package/dist/mcp/tools.d.ts.map +1 -0
  196. package/dist/mcp/tools.js +1250 -0
  197. package/dist/mcp/tools.js.map +1 -0
  198. package/dist/mcp/transport.d.ts +89 -0
  199. package/dist/mcp/transport.d.ts.map +1 -0
  200. package/dist/mcp/transport.js +170 -0
  201. package/dist/mcp/transport.js.map +1 -0
  202. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  203. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  204. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  205. package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  206. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  207. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  208. package/dist/resolution/frameworks/csharp.js +213 -0
  209. package/dist/resolution/frameworks/csharp.js.map +1 -0
  210. package/dist/resolution/frameworks/express.d.ts +8 -0
  211. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  212. package/dist/resolution/frameworks/express.js +225 -0
  213. package/dist/resolution/frameworks/express.js.map +1 -0
  214. package/dist/resolution/frameworks/go.d.ts +8 -0
  215. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  216. package/dist/resolution/frameworks/go.js +158 -0
  217. package/dist/resolution/frameworks/go.js.map +1 -0
  218. package/dist/resolution/frameworks/index.d.ts +41 -0
  219. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  220. package/dist/resolution/frameworks/index.js +129 -0
  221. package/dist/resolution/frameworks/index.js.map +1 -0
  222. package/dist/resolution/frameworks/java.d.ts +8 -0
  223. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  224. package/dist/resolution/frameworks/java.js +177 -0
  225. package/dist/resolution/frameworks/java.js.map +1 -0
  226. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  227. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  228. package/dist/resolution/frameworks/laravel.js +248 -0
  229. package/dist/resolution/frameworks/laravel.js.map +1 -0
  230. package/dist/resolution/frameworks/python.d.ts +10 -0
  231. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  232. package/dist/resolution/frameworks/python.js +278 -0
  233. package/dist/resolution/frameworks/python.js.map +1 -0
  234. package/dist/resolution/frameworks/react.d.ts +8 -0
  235. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  236. package/dist/resolution/frameworks/react.js +272 -0
  237. package/dist/resolution/frameworks/react.js.map +1 -0
  238. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  239. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  240. package/dist/resolution/frameworks/ruby.js +198 -0
  241. package/dist/resolution/frameworks/ruby.js.map +1 -0
  242. package/dist/resolution/frameworks/rust.d.ts +8 -0
  243. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  244. package/dist/resolution/frameworks/rust.js +207 -0
  245. package/dist/resolution/frameworks/rust.js.map +1 -0
  246. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  247. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  248. package/dist/resolution/frameworks/svelte.js +249 -0
  249. package/dist/resolution/frameworks/svelte.js.map +1 -0
  250. package/dist/resolution/frameworks/swift.d.ts +10 -0
  251. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  252. package/dist/resolution/frameworks/swift.js +376 -0
  253. package/dist/resolution/frameworks/swift.js.map +1 -0
  254. package/dist/resolution/frameworks/vue.d.ts +9 -0
  255. package/dist/resolution/frameworks/vue.d.ts.map +1 -0
  256. package/dist/resolution/frameworks/vue.js +306 -0
  257. package/dist/resolution/frameworks/vue.js.map +1 -0
  258. package/dist/resolution/import-resolver.d.ts +40 -0
  259. package/dist/resolution/import-resolver.d.ts.map +1 -0
  260. package/dist/resolution/import-resolver.js +663 -0
  261. package/dist/resolution/import-resolver.js.map +1 -0
  262. package/dist/resolution/index.d.ts +106 -0
  263. package/dist/resolution/index.d.ts.map +1 -0
  264. package/dist/resolution/index.js +709 -0
  265. package/dist/resolution/index.js.map +1 -0
  266. package/dist/resolution/name-matcher.d.ts +32 -0
  267. package/dist/resolution/name-matcher.d.ts.map +1 -0
  268. package/dist/resolution/name-matcher.js +384 -0
  269. package/dist/resolution/name-matcher.js.map +1 -0
  270. package/dist/resolution/path-aliases.d.ts +68 -0
  271. package/dist/resolution/path-aliases.d.ts.map +1 -0
  272. package/dist/resolution/path-aliases.js +238 -0
  273. package/dist/resolution/path-aliases.js.map +1 -0
  274. package/dist/resolution/strip-comments.d.ts +27 -0
  275. package/dist/resolution/strip-comments.d.ts.map +1 -0
  276. package/dist/resolution/strip-comments.js +441 -0
  277. package/dist/resolution/strip-comments.js.map +1 -0
  278. package/dist/resolution/types.d.ts +172 -0
  279. package/dist/resolution/types.d.ts.map +1 -0
  280. package/dist/resolution/types.js +8 -0
  281. package/dist/resolution/types.js.map +1 -0
  282. package/dist/search/query-parser.d.ts +57 -0
  283. package/dist/search/query-parser.d.ts.map +1 -0
  284. package/dist/search/query-parser.js +177 -0
  285. package/dist/search/query-parser.js.map +1 -0
  286. package/dist/search/query-utils.d.ts +53 -0
  287. package/dist/search/query-utils.d.ts.map +1 -0
  288. package/dist/search/query-utils.js +347 -0
  289. package/dist/search/query-utils.js.map +1 -0
  290. package/dist/sync/index.d.ts +13 -0
  291. package/dist/sync/index.d.ts.map +1 -0
  292. package/dist/sync/index.js +17 -0
  293. package/dist/sync/index.js.map +1 -0
  294. package/dist/sync/watcher.d.ts +81 -0
  295. package/dist/sync/watcher.d.ts.map +1 -0
  296. package/dist/sync/watcher.js +184 -0
  297. package/dist/sync/watcher.js.map +1 -0
  298. package/dist/types.d.ts +438 -0
  299. package/dist/types.d.ts.map +1 -0
  300. package/dist/types.js +263 -0
  301. package/dist/types.js.map +1 -0
  302. package/dist/ui/shimmer-progress.d.ts +11 -0
  303. package/dist/ui/shimmer-progress.d.ts.map +1 -0
  304. package/dist/ui/shimmer-progress.js +90 -0
  305. package/dist/ui/shimmer-progress.js.map +1 -0
  306. package/dist/ui/shimmer-worker.d.ts +2 -0
  307. package/dist/ui/shimmer-worker.d.ts.map +1 -0
  308. package/dist/ui/shimmer-worker.js +112 -0
  309. package/dist/ui/shimmer-worker.js.map +1 -0
  310. package/dist/ui/types.d.ts +17 -0
  311. package/dist/ui/types.d.ts.map +1 -0
  312. package/dist/ui/types.js +3 -0
  313. package/dist/ui/types.js.map +1 -0
  314. package/dist/utils.d.ts +205 -0
  315. package/dist/utils.d.ts.map +1 -0
  316. package/dist/utils.js +549 -0
  317. package/dist/utils.js.map +1 -0
  318. package/dist/vectors/embedder.d.ts +121 -0
  319. package/dist/vectors/embedder.d.ts.map +1 -0
  320. package/dist/vectors/embedder.js +237 -0
  321. package/dist/vectors/embedder.js.map +1 -0
  322. package/dist/vectors/index.d.ts +9 -0
  323. package/dist/vectors/index.d.ts.map +1 -0
  324. package/dist/vectors/index.js +20 -0
  325. package/dist/vectors/index.js.map +1 -0
  326. package/dist/vectors/manager.d.ts +124 -0
  327. package/dist/vectors/manager.d.ts.map +1 -0
  328. package/dist/vectors/manager.js +322 -0
  329. package/dist/vectors/manager.js.map +1 -0
  330. package/dist/vectors/search.d.ts +143 -0
  331. package/dist/vectors/search.d.ts.map +1 -0
  332. package/dist/vectors/search.js +460 -0
  333. package/dist/vectors/search.js.map +1 -0
  334. package/dist/visualizer/public/index.html +1994 -0
  335. package/dist/visualizer/server.d.ts +46 -0
  336. package/dist/visualizer/server.d.ts.map +1 -0
  337. package/dist/visualizer/server.js +491 -0
  338. package/dist/visualizer/server.js.map +1 -0
  339. package/package.json +60 -0
  340. package/scripts/patch-tree-sitter-dart.js +112 -0
package/dist/index.js ADDED
@@ -0,0 +1,982 @@
1
+ "use strict";
2
+ /**
3
+ * CodeGraph
4
+ *
5
+ * A local-first code intelligence system that builds a semantic
6
+ * knowledge graph from any codebase.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
42
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.CodeGraph = exports.MCPServer = exports.FileWatcher = exports.MemoryMonitor = exports.throttle = exports.debounce = exports.processInBatches = exports.FileLock = exports.Mutex = exports.defaultLogger = exports.silentLogger = exports.getLogger = exports.setLogger = exports.ConfigError = exports.VectorError = exports.SearchError = exports.DatabaseError = exports.ParseError = exports.FileError = exports.CodeGraphError = exports.loadAllGrammars = exports.loadGrammarsForLanguages = exports.initGrammars = exports.getSupportedLanguages = exports.isGrammarLoaded = exports.isLanguageSupported = exports.detectLanguage = exports.CODEGRAPH_DIR = exports.findNearestCodeGraphRoot = exports.isInitialized = exports.getCodeGraphDir = exports.getConfigPath = exports.getDatabasePath = void 0;
46
+ const path = __importStar(require("path"));
47
+ const db_1 = require("./db");
48
+ const queries_1 = require("./db/queries");
49
+ const config_1 = require("./config");
50
+ const directory_1 = require("./directory");
51
+ const extraction_1 = require("./extraction");
52
+ const resolution_1 = require("./resolution");
53
+ const graph_1 = require("./graph");
54
+ const vectors_1 = require("./vectors");
55
+ const context_1 = require("./context");
56
+ const utils_1 = require("./utils");
57
+ const sync_1 = require("./sync");
58
+ // Re-export types for consumers
59
+ __exportStar(require("./types"), exports);
60
+ var db_2 = require("./db");
61
+ Object.defineProperty(exports, "getDatabasePath", { enumerable: true, get: function () { return db_2.getDatabasePath; } });
62
+ var config_2 = require("./config");
63
+ Object.defineProperty(exports, "getConfigPath", { enumerable: true, get: function () { return config_2.getConfigPath; } });
64
+ var directory_2 = require("./directory");
65
+ Object.defineProperty(exports, "getCodeGraphDir", { enumerable: true, get: function () { return directory_2.getCodeGraphDir; } });
66
+ Object.defineProperty(exports, "isInitialized", { enumerable: true, get: function () { return directory_2.isInitialized; } });
67
+ Object.defineProperty(exports, "findNearestCodeGraphRoot", { enumerable: true, get: function () { return directory_2.findNearestCodeGraphRoot; } });
68
+ Object.defineProperty(exports, "CODEGRAPH_DIR", { enumerable: true, get: function () { return directory_2.CODEGRAPH_DIR; } });
69
+ var extraction_2 = require("./extraction");
70
+ Object.defineProperty(exports, "detectLanguage", { enumerable: true, get: function () { return extraction_2.detectLanguage; } });
71
+ Object.defineProperty(exports, "isLanguageSupported", { enumerable: true, get: function () { return extraction_2.isLanguageSupported; } });
72
+ Object.defineProperty(exports, "isGrammarLoaded", { enumerable: true, get: function () { return extraction_2.isGrammarLoaded; } });
73
+ Object.defineProperty(exports, "getSupportedLanguages", { enumerable: true, get: function () { return extraction_2.getSupportedLanguages; } });
74
+ Object.defineProperty(exports, "initGrammars", { enumerable: true, get: function () { return extraction_2.initGrammars; } });
75
+ Object.defineProperty(exports, "loadGrammarsForLanguages", { enumerable: true, get: function () { return extraction_2.loadGrammarsForLanguages; } });
76
+ Object.defineProperty(exports, "loadAllGrammars", { enumerable: true, get: function () { return extraction_2.loadAllGrammars; } });
77
+ var errors_1 = require("./errors");
78
+ Object.defineProperty(exports, "CodeGraphError", { enumerable: true, get: function () { return errors_1.CodeGraphError; } });
79
+ Object.defineProperty(exports, "FileError", { enumerable: true, get: function () { return errors_1.FileError; } });
80
+ Object.defineProperty(exports, "ParseError", { enumerable: true, get: function () { return errors_1.ParseError; } });
81
+ Object.defineProperty(exports, "DatabaseError", { enumerable: true, get: function () { return errors_1.DatabaseError; } });
82
+ Object.defineProperty(exports, "SearchError", { enumerable: true, get: function () { return errors_1.SearchError; } });
83
+ Object.defineProperty(exports, "VectorError", { enumerable: true, get: function () { return errors_1.VectorError; } });
84
+ Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return errors_1.ConfigError; } });
85
+ Object.defineProperty(exports, "setLogger", { enumerable: true, get: function () { return errors_1.setLogger; } });
86
+ Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return errors_1.getLogger; } });
87
+ Object.defineProperty(exports, "silentLogger", { enumerable: true, get: function () { return errors_1.silentLogger; } });
88
+ Object.defineProperty(exports, "defaultLogger", { enumerable: true, get: function () { return errors_1.defaultLogger; } });
89
+ var utils_2 = require("./utils");
90
+ Object.defineProperty(exports, "Mutex", { enumerable: true, get: function () { return utils_2.Mutex; } });
91
+ Object.defineProperty(exports, "FileLock", { enumerable: true, get: function () { return utils_2.FileLock; } });
92
+ Object.defineProperty(exports, "processInBatches", { enumerable: true, get: function () { return utils_2.processInBatches; } });
93
+ Object.defineProperty(exports, "debounce", { enumerable: true, get: function () { return utils_2.debounce; } });
94
+ Object.defineProperty(exports, "throttle", { enumerable: true, get: function () { return utils_2.throttle; } });
95
+ Object.defineProperty(exports, "MemoryMonitor", { enumerable: true, get: function () { return utils_2.MemoryMonitor; } });
96
+ var sync_2 = require("./sync");
97
+ Object.defineProperty(exports, "FileWatcher", { enumerable: true, get: function () { return sync_2.FileWatcher; } });
98
+ var mcp_1 = require("./mcp");
99
+ Object.defineProperty(exports, "MCPServer", { enumerable: true, get: function () { return mcp_1.MCPServer; } });
100
+ /**
101
+ * Main CodeGraph class
102
+ *
103
+ * Provides the primary interface for interacting with the code knowledge graph.
104
+ */
105
+ class CodeGraph {
106
+ db;
107
+ queries;
108
+ config;
109
+ projectRoot;
110
+ orchestrator;
111
+ resolver;
112
+ graphManager;
113
+ traverser;
114
+ vectorManager = null;
115
+ contextBuilder;
116
+ // Mutex for preventing concurrent indexing operations (in-process)
117
+ indexMutex = new utils_1.Mutex();
118
+ // File lock for preventing concurrent writes across processes (CLI, MCP, git hooks)
119
+ fileLock;
120
+ // File watcher for auto-sync on file changes
121
+ watcher = null;
122
+ constructor(db, queries, config, projectRoot) {
123
+ this.db = db;
124
+ this.queries = queries;
125
+ this.config = config;
126
+ this.projectRoot = projectRoot;
127
+ this.fileLock = new utils_1.FileLock(path.join(projectRoot, '.codegraph', 'codegraph.lock'));
128
+ this.orchestrator = new extraction_1.ExtractionOrchestrator(projectRoot, config, queries);
129
+ this.resolver = (0, resolution_1.createResolver)(projectRoot, queries);
130
+ this.graphManager = new graph_1.GraphQueryManager(queries);
131
+ this.traverser = new graph_1.GraphTraverser(queries);
132
+ this.vectorManager = this.createConfiguredVectorManager();
133
+ this.contextBuilder = (0, context_1.createContextBuilder)(projectRoot, queries, this.traverser, this.vectorManager);
134
+ }
135
+ isSemanticSearchEnabled() {
136
+ return this.config.semanticSearch?.enabled === true;
137
+ }
138
+ createConfiguredVectorManager() {
139
+ if (!this.isSemanticSearchEnabled()) {
140
+ return null;
141
+ }
142
+ const semantic = this.config.semanticSearch;
143
+ return (0, vectors_1.createVectorManager)(this.db.getDb(), this.queries, {
144
+ embedder: {
145
+ apiKey: semantic.apiKey,
146
+ modelId: semantic.model,
147
+ outputDimensionality: semantic.outputDimensionality,
148
+ },
149
+ batchSize: semantic.batchSize,
150
+ });
151
+ }
152
+ // ===========================================================================
153
+ // Lifecycle Methods
154
+ // ===========================================================================
155
+ /**
156
+ * Initialize a new CodeGraph project
157
+ *
158
+ * Creates the .CodeGraph directory, database, and configuration.
159
+ *
160
+ * @param projectRoot - Path to the project root directory
161
+ * @param options - Initialization options
162
+ * @returns A new CodeGraph instance
163
+ */
164
+ static async init(projectRoot, options = {}) {
165
+ await (0, extraction_1.initGrammars)();
166
+ const resolvedRoot = path.resolve(projectRoot);
167
+ // Check if already initialized
168
+ if ((0, directory_1.isInitialized)(resolvedRoot)) {
169
+ throw new Error(`CodeGraph already initialized in ${resolvedRoot}`);
170
+ }
171
+ // Create directory structure
172
+ (0, directory_1.createDirectory)(resolvedRoot);
173
+ // Create and save configuration
174
+ const config = (0, config_1.createDefaultConfig)(resolvedRoot);
175
+ if (options.config) {
176
+ Object.assign(config, options.config);
177
+ }
178
+ (0, config_1.saveConfig)(resolvedRoot, config);
179
+ // Initialize database
180
+ const dbPath = (0, db_1.getDatabasePath)(resolvedRoot);
181
+ const db = db_1.DatabaseConnection.initialize(dbPath);
182
+ const queries = new queries_1.QueryBuilder(db.getDb());
183
+ const instance = new CodeGraph(db, queries, config, resolvedRoot);
184
+ // Run initial indexing if requested
185
+ if (options.index) {
186
+ await instance.indexAll({ onProgress: options.onProgress });
187
+ }
188
+ return instance;
189
+ }
190
+ /**
191
+ * Initialize synchronously (without indexing)
192
+ */
193
+ static initSync(projectRoot, options = {}) {
194
+ const resolvedRoot = path.resolve(projectRoot);
195
+ // Check if already initialized
196
+ if ((0, directory_1.isInitialized)(resolvedRoot)) {
197
+ throw new Error(`CodeGraph already initialized in ${resolvedRoot}`);
198
+ }
199
+ // Create directory structure
200
+ (0, directory_1.createDirectory)(resolvedRoot);
201
+ // Create and save configuration
202
+ const config = (0, config_1.createDefaultConfig)(resolvedRoot);
203
+ if (options.config) {
204
+ Object.assign(config, options.config);
205
+ }
206
+ (0, config_1.saveConfig)(resolvedRoot, config);
207
+ // Initialize database
208
+ const dbPath = (0, db_1.getDatabasePath)(resolvedRoot);
209
+ const db = db_1.DatabaseConnection.initialize(dbPath);
210
+ const queries = new queries_1.QueryBuilder(db.getDb());
211
+ return new CodeGraph(db, queries, config, resolvedRoot);
212
+ }
213
+ /**
214
+ * Open an existing CodeGraph project
215
+ *
216
+ * @param projectRoot - Path to the project root directory
217
+ * @param options - Open options
218
+ * @returns A CodeGraph instance
219
+ */
220
+ static async open(projectRoot, options = {}) {
221
+ await (0, extraction_1.initGrammars)();
222
+ const resolvedRoot = path.resolve(projectRoot);
223
+ // Check if initialized
224
+ if (!(0, directory_1.isInitialized)(resolvedRoot)) {
225
+ throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
226
+ }
227
+ // Validate directory structure
228
+ const validation = (0, directory_1.validateDirectory)(resolvedRoot);
229
+ if (!validation.valid) {
230
+ throw new Error(`Invalid CodeGraph directory: ${validation.errors.join(', ')}`);
231
+ }
232
+ // Load configuration
233
+ const config = (0, config_1.loadConfig)(resolvedRoot);
234
+ // Open database
235
+ const dbPath = (0, db_1.getDatabasePath)(resolvedRoot);
236
+ const db = db_1.DatabaseConnection.open(dbPath);
237
+ const queries = new queries_1.QueryBuilder(db.getDb());
238
+ const instance = new CodeGraph(db, queries, config, resolvedRoot);
239
+ // Sync if requested
240
+ if (options.sync) {
241
+ await instance.sync();
242
+ }
243
+ return instance;
244
+ }
245
+ /**
246
+ * Open synchronously (without sync)
247
+ */
248
+ static openSync(projectRoot) {
249
+ const resolvedRoot = path.resolve(projectRoot);
250
+ // Check if initialized
251
+ if (!(0, directory_1.isInitialized)(resolvedRoot)) {
252
+ throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
253
+ }
254
+ // Validate directory structure
255
+ const validation = (0, directory_1.validateDirectory)(resolvedRoot);
256
+ if (!validation.valid) {
257
+ throw new Error(`Invalid CodeGraph directory: ${validation.errors.join(', ')}`);
258
+ }
259
+ // Load configuration
260
+ const config = (0, config_1.loadConfig)(resolvedRoot);
261
+ // Open database
262
+ const dbPath = (0, db_1.getDatabasePath)(resolvedRoot);
263
+ const db = db_1.DatabaseConnection.open(dbPath);
264
+ const queries = new queries_1.QueryBuilder(db.getDb());
265
+ return new CodeGraph(db, queries, config, resolvedRoot);
266
+ }
267
+ /**
268
+ * Check if a directory has been initialized as a CodeGraph project
269
+ */
270
+ static isInitialized(projectRoot) {
271
+ return (0, directory_1.isInitialized)(path.resolve(projectRoot));
272
+ }
273
+ /**
274
+ * Close the CodeGraph instance and release resources
275
+ */
276
+ close() {
277
+ this.unwatch();
278
+ // Release file lock if held
279
+ this.fileLock.release();
280
+ // Dispose vector manager before closing the database.
281
+ if (this.vectorManager) {
282
+ this.vectorManager.dispose();
283
+ this.vectorManager = null;
284
+ }
285
+ this.db.close();
286
+ }
287
+ // ===========================================================================
288
+ // Configuration
289
+ // ===========================================================================
290
+ /**
291
+ * Get the current configuration
292
+ */
293
+ getConfig() {
294
+ return { ...this.config };
295
+ }
296
+ /**
297
+ * Update configuration
298
+ */
299
+ updateConfig(updates) {
300
+ Object.assign(this.config, updates);
301
+ (0, config_1.saveConfig)(this.projectRoot, this.config);
302
+ // Recreate orchestrator and resolver with new config
303
+ this.orchestrator = new extraction_1.ExtractionOrchestrator(this.projectRoot, this.config, this.queries);
304
+ this.resolver = (0, resolution_1.createResolver)(this.projectRoot, this.queries);
305
+ this.vectorManager = this.createConfiguredVectorManager();
306
+ this.contextBuilder = (0, context_1.createContextBuilder)(this.projectRoot, this.queries, this.traverser, this.vectorManager);
307
+ }
308
+ /**
309
+ * Get the project root directory
310
+ */
311
+ getProjectRoot() {
312
+ return this.projectRoot;
313
+ }
314
+ // ===========================================================================
315
+ // Indexing
316
+ // ===========================================================================
317
+ /**
318
+ * Index all files in the project
319
+ *
320
+ * Uses a mutex to prevent concurrent indexing operations.
321
+ */
322
+ async indexAll(options = {}) {
323
+ return this.indexMutex.withLock(async () => {
324
+ try {
325
+ this.fileLock.acquire();
326
+ }
327
+ catch {
328
+ return { success: false, filesIndexed: 0, filesSkipped: 0, filesErrored: 0, nodesCreated: 0, edgesCreated: 0, errors: [{ message: 'Could not acquire file lock - another process may be indexing', severity: 'error' }], durationMs: 0 };
329
+ }
330
+ try {
331
+ const result = await this.orchestrator.indexAll(options.onProgress, options.signal, options.verbose);
332
+ // Resolve references to create call/import/extends edges
333
+ if (result.success && result.filesIndexed > 0) {
334
+ // Get count without loading all refs into memory
335
+ const unresolvedCount = this.queries.getUnresolvedReferencesCount();
336
+ options.onProgress?.({
337
+ phase: 'resolving',
338
+ current: 0,
339
+ total: unresolvedCount,
340
+ });
341
+ await this.resolveReferencesBatched((current, total) => {
342
+ options.onProgress?.({
343
+ phase: 'resolving',
344
+ current,
345
+ total,
346
+ });
347
+ });
348
+ }
349
+ if (result.success && this.isSemanticSearchEnabled()) {
350
+ await this.updateSemanticIndex(options.onProgress);
351
+ }
352
+ return result;
353
+ }
354
+ finally {
355
+ this.fileLock.release();
356
+ }
357
+ });
358
+ }
359
+ /**
360
+ * Index specific files
361
+ *
362
+ * Uses a mutex to prevent concurrent indexing operations.
363
+ */
364
+ async indexFiles(filePaths) {
365
+ return this.indexMutex.withLock(async () => {
366
+ try {
367
+ this.fileLock.acquire();
368
+ }
369
+ catch {
370
+ return { success: false, filesIndexed: 0, filesSkipped: 0, filesErrored: 0, nodesCreated: 0, edgesCreated: 0, errors: [{ message: 'Could not acquire file lock - another process may be indexing', severity: 'error' }], durationMs: 0 };
371
+ }
372
+ try {
373
+ return this.orchestrator.indexFiles(filePaths);
374
+ }
375
+ finally {
376
+ this.fileLock.release();
377
+ }
378
+ });
379
+ }
380
+ /**
381
+ * Sync with current file state (incremental update)
382
+ *
383
+ * Uses a mutex to prevent concurrent indexing operations.
384
+ */
385
+ async sync(options = {}) {
386
+ return this.indexMutex.withLock(async () => {
387
+ try {
388
+ this.fileLock.acquire();
389
+ }
390
+ catch {
391
+ return { filesChecked: 0, filesAdded: 0, filesModified: 0, filesRemoved: 0, nodesUpdated: 0, durationMs: 0 };
392
+ }
393
+ try {
394
+ const result = await this.orchestrator.sync(options.onProgress);
395
+ // Resolve references if files were updated
396
+ if (result.filesAdded > 0 || result.filesModified > 0) {
397
+ if (result.changedFilePaths) {
398
+ // Scope resolution to changed files (git fast path — bounded set)
399
+ const unresolvedRefs = this.queries.getUnresolvedReferencesByFiles(result.changedFilePaths);
400
+ options.onProgress?.({
401
+ phase: 'resolving',
402
+ current: 0,
403
+ total: unresolvedRefs.length,
404
+ });
405
+ this.resolver.resolveAndPersist(unresolvedRefs, (current, total) => {
406
+ options.onProgress?.({
407
+ phase: 'resolving',
408
+ current,
409
+ total,
410
+ });
411
+ });
412
+ }
413
+ else {
414
+ // No git info — use batched resolution to avoid OOM
415
+ const unresolvedCount = this.queries.getUnresolvedReferencesCount();
416
+ options.onProgress?.({
417
+ phase: 'resolving',
418
+ current: 0,
419
+ total: unresolvedCount,
420
+ });
421
+ await this.resolveReferencesBatched((current, total) => {
422
+ options.onProgress?.({
423
+ phase: 'resolving',
424
+ current,
425
+ total,
426
+ });
427
+ });
428
+ }
429
+ }
430
+ if (this.isSemanticSearchEnabled()) {
431
+ await this.updateSemanticIndex(options.onProgress);
432
+ }
433
+ return result;
434
+ }
435
+ finally {
436
+ this.fileLock.release();
437
+ }
438
+ });
439
+ }
440
+ async updateSemanticIndex(onProgress) {
441
+ await this.initializeEmbeddings();
442
+ this.vectorManager?.deleteStaleVectors();
443
+ const total = this.getSemanticEligibleNodeCount();
444
+ onProgress?.({
445
+ phase: 'embedding',
446
+ current: 0,
447
+ total,
448
+ });
449
+ await this.generateEmbeddings((progress) => {
450
+ onProgress?.({
451
+ phase: 'embedding',
452
+ current: progress.current,
453
+ total: progress.total,
454
+ currentFile: progress.nodeName,
455
+ });
456
+ });
457
+ }
458
+ getSemanticEligibleNodeCount() {
459
+ const stats = this.queries.getStats();
460
+ const kinds = [
461
+ 'function',
462
+ 'method',
463
+ 'class',
464
+ 'interface',
465
+ 'type_alias',
466
+ 'module',
467
+ 'component',
468
+ ];
469
+ return kinds.reduce((sum, kind) => sum + (stats.nodesByKind[kind] ?? 0), 0);
470
+ }
471
+ async initializeSemanticSearchForQuery() {
472
+ if (!this.isSemanticSearchEnabled() || !this.vectorManager || this.vectorManager.isInitialized()) {
473
+ return;
474
+ }
475
+ // Avoid a query embedding API call when the project has no document vectors.
476
+ if (this.vectorManager.getStats().totalVectors === 0) {
477
+ return;
478
+ }
479
+ await this.vectorManager.initialize();
480
+ }
481
+ /**
482
+ * Check if an indexing operation is currently in progress
483
+ */
484
+ isIndexing() {
485
+ return this.indexMutex.isLocked();
486
+ }
487
+ // ===========================================================================
488
+ // File Watching
489
+ // ===========================================================================
490
+ /**
491
+ * Start watching for file changes and auto-syncing.
492
+ *
493
+ * Uses native OS file events (FSEvents on macOS, inotify on Linux 19+,
494
+ * ReadDirectoryChangesW on Windows) with debouncing to avoid thrashing.
495
+ *
496
+ * @param options - Watch options (debounce delay, callbacks)
497
+ * @returns true if watching started successfully
498
+ */
499
+ watch(options = {}) {
500
+ if (this.watcher?.isActive())
501
+ return true;
502
+ this.watcher = new sync_1.FileWatcher(this.projectRoot, this.config, async () => {
503
+ const result = await this.sync();
504
+ const filesChanged = result.filesAdded + result.filesModified + result.filesRemoved;
505
+ return { filesChanged, durationMs: result.durationMs };
506
+ }, options);
507
+ return this.watcher.start();
508
+ }
509
+ /**
510
+ * Stop watching for file changes.
511
+ */
512
+ unwatch() {
513
+ if (this.watcher) {
514
+ this.watcher.stop();
515
+ this.watcher = null;
516
+ }
517
+ }
518
+ /**
519
+ * Check if the file watcher is active.
520
+ */
521
+ isWatching() {
522
+ return this.watcher?.isActive() ?? false;
523
+ }
524
+ /**
525
+ * Get files that have changed since last index
526
+ */
527
+ getChangedFiles() {
528
+ return this.orchestrator.getChangedFiles();
529
+ }
530
+ /**
531
+ * Extract nodes and edges from source code (without storing)
532
+ */
533
+ extractFromSource(filePath, source) {
534
+ return (0, extraction_1.extractFromSource)(filePath, source);
535
+ }
536
+ // ===========================================================================
537
+ // Reference Resolution
538
+ // ===========================================================================
539
+ /**
540
+ * Resolve unresolved references and create edges
541
+ *
542
+ * This method takes unresolved references from extraction and attempts
543
+ * to resolve them using multiple strategies:
544
+ * - Framework-specific patterns (React, Express, Laravel)
545
+ * - Import-based resolution
546
+ * - Name-based symbol matching
547
+ */
548
+ resolveReferences(onProgress) {
549
+ // Get all unresolved references from the database
550
+ const unresolvedRefs = this.queries.getUnresolvedReferences();
551
+ return this.resolver.resolveAndPersist(unresolvedRefs, onProgress);
552
+ }
553
+ /**
554
+ * Resolve references in batches to keep memory bounded on large codebases.
555
+ * Processes chunks of unresolved refs, persisting results after each batch.
556
+ */
557
+ async resolveReferencesBatched(onProgress) {
558
+ return this.resolver.resolveAndPersistBatched(onProgress);
559
+ }
560
+ /**
561
+ * Get detected frameworks in the project
562
+ */
563
+ getDetectedFrameworks() {
564
+ return this.resolver.getDetectedFrameworks();
565
+ }
566
+ /**
567
+ * Re-initialize the resolver (useful after adding new files)
568
+ */
569
+ reinitializeResolver() {
570
+ this.resolver.initialize();
571
+ }
572
+ // ===========================================================================
573
+ // Graph Statistics
574
+ // ===========================================================================
575
+ /**
576
+ * Get statistics about the knowledge graph
577
+ */
578
+ getStats() {
579
+ const stats = this.queries.getStats();
580
+ stats.dbSizeBytes = this.db.getSize();
581
+ return stats;
582
+ }
583
+ /**
584
+ * Active SQLite backend for this project's connection. `wasm` means
585
+ * the native better-sqlite3 install failed and the WASM fallback is
586
+ * serving requests at 5-10x the latency. Surfaced via `codegraph
587
+ * status` and the `codegraph_status` MCP tool.
588
+ */
589
+ getBackend() {
590
+ return this.db.getBackend();
591
+ }
592
+ // ===========================================================================
593
+ // Node Operations
594
+ // ===========================================================================
595
+ /**
596
+ * Get a node by ID
597
+ */
598
+ getNode(id) {
599
+ return this.queries.getNodeById(id);
600
+ }
601
+ /**
602
+ * Get all nodes in a file
603
+ */
604
+ getNodesInFile(filePath) {
605
+ return this.queries.getNodesByFile(filePath);
606
+ }
607
+ /**
608
+ * Get all nodes of a specific kind
609
+ */
610
+ getNodesByKind(kind) {
611
+ return this.queries.getNodesByKind(kind);
612
+ }
613
+ /**
614
+ * Search nodes by text
615
+ */
616
+ searchNodes(query, options) {
617
+ return this.queries.searchNodes(query, options);
618
+ }
619
+ // ===========================================================================
620
+ // Edge Operations
621
+ // ===========================================================================
622
+ /**
623
+ * Get outgoing edges from a node
624
+ */
625
+ getOutgoingEdges(nodeId) {
626
+ return this.queries.getOutgoingEdges(nodeId);
627
+ }
628
+ /**
629
+ * Get incoming edges to a node
630
+ */
631
+ getIncomingEdges(nodeId) {
632
+ return this.queries.getIncomingEdges(nodeId);
633
+ }
634
+ // ===========================================================================
635
+ // File Operations
636
+ // ===========================================================================
637
+ /**
638
+ * Get a file record by path
639
+ */
640
+ getFile(filePath) {
641
+ return this.queries.getFileByPath(filePath);
642
+ }
643
+ /**
644
+ * Get all tracked files
645
+ */
646
+ getFiles() {
647
+ return this.queries.getAllFiles();
648
+ }
649
+ // ===========================================================================
650
+ // Graph Query Methods
651
+ // ===========================================================================
652
+ /**
653
+ * Get the context for a node (ancestors, children, references)
654
+ *
655
+ * Returns comprehensive context about a node including its containment
656
+ * hierarchy, children, incoming/outgoing references, type information,
657
+ * and relevant imports.
658
+ *
659
+ * @param nodeId - ID of the focal node
660
+ * @returns Context object with all related information
661
+ */
662
+ getContext(nodeId) {
663
+ return this.graphManager.getContext(nodeId);
664
+ }
665
+ /**
666
+ * Traverse the graph from a starting node
667
+ *
668
+ * Uses breadth-first search by default. Supports filtering by edge types,
669
+ * node types, and traversal direction.
670
+ *
671
+ * @param startId - Starting node ID
672
+ * @param options - Traversal options
673
+ * @returns Subgraph containing traversed nodes and edges
674
+ */
675
+ traverse(startId, options) {
676
+ return this.traverser.traverseBFS(startId, options);
677
+ }
678
+ /**
679
+ * Get the call graph for a function
680
+ *
681
+ * Returns both callers (functions that call this function) and
682
+ * callees (functions called by this function) up to the specified depth.
683
+ *
684
+ * @param nodeId - ID of the function/method node
685
+ * @param depth - Maximum depth in each direction (default: 2)
686
+ * @returns Subgraph containing the call graph
687
+ */
688
+ getCallGraph(nodeId, depth = 2) {
689
+ return this.traverser.getCallGraph(nodeId, depth);
690
+ }
691
+ /**
692
+ * Get the type hierarchy for a class/interface
693
+ *
694
+ * Returns both ancestors (types this extends/implements) and
695
+ * descendants (types that extend/implement this).
696
+ *
697
+ * @param nodeId - ID of the class/interface node
698
+ * @returns Subgraph containing the type hierarchy
699
+ */
700
+ getTypeHierarchy(nodeId) {
701
+ return this.traverser.getTypeHierarchy(nodeId);
702
+ }
703
+ /**
704
+ * Find all usages of a symbol
705
+ *
706
+ * Returns all nodes that reference the specified symbol through
707
+ * any edge type (calls, references, type_of, etc.).
708
+ *
709
+ * @param nodeId - ID of the symbol node
710
+ * @returns Array of nodes and edges that reference this symbol
711
+ */
712
+ findUsages(nodeId) {
713
+ return this.traverser.findUsages(nodeId);
714
+ }
715
+ /**
716
+ * Get callers of a function/method
717
+ *
718
+ * @param nodeId - ID of the function/method node
719
+ * @param maxDepth - Maximum depth to traverse (default: 1)
720
+ * @returns Array of nodes that call this function
721
+ */
722
+ getCallers(nodeId, maxDepth = 1) {
723
+ return this.traverser.getCallers(nodeId, maxDepth);
724
+ }
725
+ /**
726
+ * Get callees of a function/method
727
+ *
728
+ * @param nodeId - ID of the function/method node
729
+ * @param maxDepth - Maximum depth to traverse (default: 1)
730
+ * @returns Array of nodes called by this function
731
+ */
732
+ getCallees(nodeId, maxDepth = 1) {
733
+ return this.traverser.getCallees(nodeId, maxDepth);
734
+ }
735
+ /**
736
+ * Calculate the impact radius of a node
737
+ *
738
+ * Returns all nodes that could be affected by changes to this node.
739
+ *
740
+ * @param nodeId - ID of the node
741
+ * @param maxDepth - Maximum depth to traverse (default: 3)
742
+ * @returns Subgraph containing potentially impacted nodes
743
+ */
744
+ getImpactRadius(nodeId, maxDepth = 3) {
745
+ return this.traverser.getImpactRadius(nodeId, maxDepth);
746
+ }
747
+ /**
748
+ * Find the shortest path between two nodes
749
+ *
750
+ * @param fromId - Starting node ID
751
+ * @param toId - Target node ID
752
+ * @param edgeKinds - Edge types to consider (all if empty)
753
+ * @returns Array of nodes and edges forming the path, or null if no path exists
754
+ */
755
+ findPath(fromId, toId, edgeKinds) {
756
+ return this.traverser.findPath(fromId, toId, edgeKinds);
757
+ }
758
+ /**
759
+ * Get ancestors of a node in the containment hierarchy
760
+ *
761
+ * @param nodeId - ID of the node
762
+ * @returns Array of ancestor nodes from immediate parent to root
763
+ */
764
+ getAncestors(nodeId) {
765
+ return this.traverser.getAncestors(nodeId);
766
+ }
767
+ /**
768
+ * Get immediate children of a node
769
+ *
770
+ * @param nodeId - ID of the node
771
+ * @returns Array of child nodes
772
+ */
773
+ getChildren(nodeId) {
774
+ return this.traverser.getChildren(nodeId);
775
+ }
776
+ /**
777
+ * Get dependencies of a file
778
+ *
779
+ * @param filePath - Path to the file
780
+ * @returns Array of file paths this file depends on
781
+ */
782
+ getFileDependencies(filePath) {
783
+ return this.graphManager.getFileDependencies(filePath);
784
+ }
785
+ /**
786
+ * Get dependents of a file
787
+ *
788
+ * @param filePath - Path to the file
789
+ * @returns Array of file paths that depend on this file
790
+ */
791
+ getFileDependents(filePath) {
792
+ return this.graphManager.getFileDependents(filePath);
793
+ }
794
+ /**
795
+ * Find circular dependencies in the codebase
796
+ *
797
+ * @returns Array of cycles, each cycle is an array of file paths
798
+ */
799
+ findCircularDependencies() {
800
+ return this.graphManager.findCircularDependencies();
801
+ }
802
+ /**
803
+ * Find dead code (unreferenced symbols)
804
+ *
805
+ * @param kinds - Node kinds to check (default: functions, methods, classes)
806
+ * @returns Array of unreferenced nodes
807
+ */
808
+ findDeadCode(kinds) {
809
+ return this.graphManager.findDeadCode(kinds);
810
+ }
811
+ /**
812
+ * Get complexity metrics for a node
813
+ *
814
+ * @param nodeId - ID of the node
815
+ * @returns Object containing various complexity metrics
816
+ */
817
+ getNodeMetrics(nodeId) {
818
+ return this.graphManager.getNodeMetrics(nodeId);
819
+ }
820
+ // ===========================================================================
821
+ // Semantic Search (Vector Embeddings)
822
+ // ===========================================================================
823
+ /**
824
+ * Initialize the embedding system
825
+ *
826
+ * This validates Gemini configuration and initializes the local vector
827
+ * search system. Must be called before using semantic search.
828
+ */
829
+ async initializeEmbeddings() {
830
+ if (!this.vectorManager) {
831
+ this.vectorManager = this.createConfiguredVectorManager();
832
+ if (!this.vectorManager) {
833
+ throw new Error('Semantic search is not enabled in CodeGraph config');
834
+ }
835
+ }
836
+ await this.vectorManager.initialize();
837
+ }
838
+ /**
839
+ * Check if embeddings are initialized
840
+ */
841
+ isEmbeddingsInitialized() {
842
+ return this.vectorManager?.isInitialized() ?? false;
843
+ }
844
+ /**
845
+ * Generate embeddings for all eligible nodes
846
+ *
847
+ * @param onProgress - Optional progress callback
848
+ * @returns Number of nodes embedded
849
+ */
850
+ async generateEmbeddings(onProgress) {
851
+ if (!this.vectorManager) {
852
+ await this.initializeEmbeddings();
853
+ }
854
+ return this.vectorManager.embedAllNodes(onProgress);
855
+ }
856
+ /**
857
+ * Semantic search using embeddings
858
+ *
859
+ * Searches for code nodes semantically similar to the query.
860
+ * Requires embeddings to be initialized first.
861
+ *
862
+ * @param query - Natural language search query
863
+ * @param limit - Maximum number of results (default: 10)
864
+ * @returns Array of search results with similarity scores
865
+ */
866
+ async semanticSearch(query, limit = 10) {
867
+ if (!this.vectorManager || !this.vectorManager.isInitialized()) {
868
+ throw new Error('Embeddings not initialized. Call initializeEmbeddings() first.');
869
+ }
870
+ return this.vectorManager.search(query, { limit });
871
+ }
872
+ /**
873
+ * Find similar code blocks
874
+ *
875
+ * Finds nodes semantically similar to a given node.
876
+ * Requires embeddings to be initialized first.
877
+ *
878
+ * @param nodeId - ID of the node to find similar nodes for
879
+ * @param limit - Maximum number of results (default: 10)
880
+ * @returns Array of similar nodes with similarity scores
881
+ */
882
+ async findSimilar(nodeId, limit = 10) {
883
+ if (!this.vectorManager || !this.vectorManager.isInitialized()) {
884
+ throw new Error('Embeddings not initialized. Call initializeEmbeddings() first.');
885
+ }
886
+ return this.vectorManager.findSimilar(nodeId, { limit });
887
+ }
888
+ /**
889
+ * Get vector embedding statistics
890
+ */
891
+ getEmbeddingStats() {
892
+ if (!this.vectorManager) {
893
+ return null;
894
+ }
895
+ return this.vectorManager.getStats();
896
+ }
897
+ // ===========================================================================
898
+ // Context Building
899
+ // ===========================================================================
900
+ /**
901
+ * Get the source code for a node
902
+ *
903
+ * Reads the file and extracts the code between startLine and endLine.
904
+ *
905
+ * @param nodeId - ID of the node
906
+ * @returns Code string or null if not found
907
+ */
908
+ async getCode(nodeId) {
909
+ return this.contextBuilder.getCode(nodeId);
910
+ }
911
+ /**
912
+ * Find relevant subgraph for a query
913
+ *
914
+ * Combines semantic search with graph traversal to find the most
915
+ * relevant nodes and their relationships for a given query.
916
+ *
917
+ * @param query - Natural language query describing the task
918
+ * @param options - Search and traversal options
919
+ * @returns Subgraph of relevant nodes and edges
920
+ */
921
+ async findRelevantContext(query, options) {
922
+ await this.initializeSemanticSearchForQuery();
923
+ // Update context builder with current vector manager
924
+ this.contextBuilder = (0, context_1.createContextBuilder)(this.projectRoot, this.queries, this.traverser, this.vectorManager);
925
+ return this.contextBuilder.findRelevantContext(query, options);
926
+ }
927
+ /**
928
+ * Build context for a task
929
+ *
930
+ * Creates comprehensive context by:
931
+ * 1. Running semantic search to find entry points
932
+ * 2. Expanding the graph around entry points
933
+ * 3. Extracting code blocks for key nodes
934
+ * 4. Formatting output for Claude
935
+ *
936
+ * @param input - Task description (string or {title, description})
937
+ * @param options - Build options (maxNodes, includeCode, format, etc.)
938
+ * @returns TaskContext object or formatted string (markdown/JSON)
939
+ */
940
+ async buildContext(input, options) {
941
+ await this.initializeSemanticSearchForQuery();
942
+ // Update context builder with current vector manager
943
+ this.contextBuilder = (0, context_1.createContextBuilder)(this.projectRoot, this.queries, this.traverser, this.vectorManager);
944
+ return this.contextBuilder.buildContext(input, options);
945
+ }
946
+ // ===========================================================================
947
+ // Database Management
948
+ // ===========================================================================
949
+ /**
950
+ * Optimize the database (vacuum and analyze)
951
+ */
952
+ optimize() {
953
+ this.db.optimize();
954
+ }
955
+ /**
956
+ * Clear all data from the graph
957
+ */
958
+ clear() {
959
+ this.queries.clear();
960
+ }
961
+ /**
962
+ * Alias for close() for backwards compatibility.
963
+ * @deprecated Use close() instead
964
+ */
965
+ destroy() {
966
+ this.close();
967
+ }
968
+ /**
969
+ * Completely remove CodeGraph from the project.
970
+ * This closes the database and deletes the .CodeGraph directory.
971
+ *
972
+ * WARNING: This permanently deletes all CodeGraph data for the project.
973
+ */
974
+ uninitialize() {
975
+ this.close();
976
+ (0, directory_1.removeDirectory)(this.projectRoot);
977
+ }
978
+ }
979
+ exports.CodeGraph = CodeGraph;
980
+ // Default export
981
+ exports.default = CodeGraph;
982
+ //# sourceMappingURL=index.js.map