@vizalice/codegraph 1.5.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 (821) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +872 -0
  3. package/dist/bin/codegraph.d.ts +26 -0
  4. package/dist/bin/codegraph.d.ts.map +1 -0
  5. package/dist/bin/codegraph.js +2324 -0
  6. package/dist/bin/codegraph.js.map +1 -0
  7. package/dist/bin/command-supervision.d.ts +49 -0
  8. package/dist/bin/command-supervision.d.ts.map +1 -0
  9. package/dist/bin/command-supervision.js +95 -0
  10. package/dist/bin/command-supervision.js.map +1 -0
  11. package/dist/bin/fatal-handler.d.ts +20 -0
  12. package/dist/bin/fatal-handler.d.ts.map +1 -0
  13. package/dist/bin/fatal-handler.js +118 -0
  14. package/dist/bin/fatal-handler.js.map +1 -0
  15. package/dist/bin/node-version-check.d.ts +37 -0
  16. package/dist/bin/node-version-check.d.ts.map +1 -0
  17. package/dist/bin/node-version-check.js +79 -0
  18. package/dist/bin/node-version-check.js.map +1 -0
  19. package/dist/bin/uninstall.d.ts +14 -0
  20. package/dist/bin/uninstall.d.ts.map +1 -0
  21. package/dist/bin/uninstall.js +36 -0
  22. package/dist/bin/uninstall.js.map +1 -0
  23. package/dist/context/formatter.d.ts +36 -0
  24. package/dist/context/formatter.d.ts.map +1 -0
  25. package/dist/context/formatter.js +269 -0
  26. package/dist/context/formatter.js.map +1 -0
  27. package/dist/context/index.d.ts +119 -0
  28. package/dist/context/index.d.ts.map +1 -0
  29. package/dist/context/index.js +1333 -0
  30. package/dist/context/index.js.map +1 -0
  31. package/dist/context/markers.d.ts +19 -0
  32. package/dist/context/markers.d.ts.map +1 -0
  33. package/dist/context/markers.js +22 -0
  34. package/dist/context/markers.js.map +1 -0
  35. package/dist/db/index.d.ts +378 -0
  36. package/dist/db/index.d.ts.map +1 -0
  37. package/dist/db/index.js +831 -0
  38. package/dist/db/index.js.map +1 -0
  39. package/dist/db/migrations.d.ts +44 -0
  40. package/dist/db/migrations.d.ts.map +1 -0
  41. package/dist/db/migrations.js +236 -0
  42. package/dist/db/migrations.js.map +1 -0
  43. package/dist/db/queries.d.ts +705 -0
  44. package/dist/db/queries.d.ts.map +1 -0
  45. package/dist/db/queries.js +2435 -0
  46. package/dist/db/queries.js.map +1 -0
  47. package/dist/db/schema.sql +207 -0
  48. package/dist/db/sqlite-adapter.d.ts +55 -0
  49. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  50. package/dist/db/sqlite-adapter.js +135 -0
  51. package/dist/db/sqlite-adapter.js.map +1 -0
  52. package/dist/db/wal-valve.d.ts +119 -0
  53. package/dist/db/wal-valve.d.ts.map +1 -0
  54. package/dist/db/wal-valve.js +290 -0
  55. package/dist/db/wal-valve.js.map +1 -0
  56. package/dist/directory.d.ts +183 -0
  57. package/dist/directory.d.ts.map +1 -0
  58. package/dist/directory.js +797 -0
  59. package/dist/directory.js.map +1 -0
  60. package/dist/errors.d.ts +136 -0
  61. package/dist/errors.d.ts.map +1 -0
  62. package/dist/errors.js +219 -0
  63. package/dist/errors.js.map +1 -0
  64. package/dist/extraction/astro-extractor.d.ts +79 -0
  65. package/dist/extraction/astro-extractor.d.ts.map +1 -0
  66. package/dist/extraction/astro-extractor.js +320 -0
  67. package/dist/extraction/astro-extractor.js.map +1 -0
  68. package/dist/extraction/cfml-extractor.d.ts +107 -0
  69. package/dist/extraction/cfml-extractor.d.ts.map +1 -0
  70. package/dist/extraction/cfml-extractor.js +494 -0
  71. package/dist/extraction/cfml-extractor.js.map +1 -0
  72. package/dist/extraction/dfm-extractor.d.ts +31 -0
  73. package/dist/extraction/dfm-extractor.d.ts.map +1 -0
  74. package/dist/extraction/dfm-extractor.js +151 -0
  75. package/dist/extraction/dfm-extractor.js.map +1 -0
  76. package/dist/extraction/extraction-version.d.ts +25 -0
  77. package/dist/extraction/extraction-version.d.ts.map +1 -0
  78. package/dist/extraction/extraction-version.js +28 -0
  79. package/dist/extraction/extraction-version.js.map +1 -0
  80. package/dist/extraction/function-ref.d.ts +118 -0
  81. package/dist/extraction/function-ref.d.ts.map +1 -0
  82. package/dist/extraction/function-ref.js +733 -0
  83. package/dist/extraction/function-ref.js.map +1 -0
  84. package/dist/extraction/generated-detection.d.ts +66 -0
  85. package/dist/extraction/generated-detection.d.ts.map +1 -0
  86. package/dist/extraction/generated-detection.js +248 -0
  87. package/dist/extraction/generated-detection.js.map +1 -0
  88. package/dist/extraction/grammars.d.ts +138 -0
  89. package/dist/extraction/grammars.d.ts.map +1 -0
  90. package/dist/extraction/grammars.js +694 -0
  91. package/dist/extraction/grammars.js.map +1 -0
  92. package/dist/extraction/index.d.ts +308 -0
  93. package/dist/extraction/index.d.ts.map +1 -0
  94. package/dist/extraction/index.js +2711 -0
  95. package/dist/extraction/index.js.map +1 -0
  96. package/dist/extraction/kernel/decode.d.ts +9 -0
  97. package/dist/extraction/kernel/decode.d.ts.map +1 -0
  98. package/dist/extraction/kernel/decode.js +162 -0
  99. package/dist/extraction/kernel/decode.js.map +1 -0
  100. package/dist/extraction/kernel/index.d.ts +64 -0
  101. package/dist/extraction/kernel/index.d.ts.map +1 -0
  102. package/dist/extraction/kernel/index.js +279 -0
  103. package/dist/extraction/kernel/index.js.map +1 -0
  104. package/dist/extraction/kernel/layout.d.ts +101 -0
  105. package/dist/extraction/kernel/layout.d.ts.map +1 -0
  106. package/dist/extraction/kernel/layout.js +104 -0
  107. package/dist/extraction/kernel/layout.js.map +1 -0
  108. package/dist/extraction/kernel/loader.d.ts +103 -0
  109. package/dist/extraction/kernel/loader.d.ts.map +1 -0
  110. package/dist/extraction/kernel/loader.js +146 -0
  111. package/dist/extraction/kernel/loader.js.map +1 -0
  112. package/dist/extraction/languages/arkts.d.ts +3 -0
  113. package/dist/extraction/languages/arkts.d.ts.map +1 -0
  114. package/dist/extraction/languages/arkts.js +127 -0
  115. package/dist/extraction/languages/arkts.js.map +1 -0
  116. package/dist/extraction/languages/c-cpp.d.ts +124 -0
  117. package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  118. package/dist/extraction/languages/c-cpp.js +1689 -0
  119. package/dist/extraction/languages/c-cpp.js.map +1 -0
  120. package/dist/extraction/languages/cfquery.d.ts +12 -0
  121. package/dist/extraction/languages/cfquery.d.ts.map +1 -0
  122. package/dist/extraction/languages/cfquery.js +28 -0
  123. package/dist/extraction/languages/cfquery.js.map +1 -0
  124. package/dist/extraction/languages/cfscript.d.ts +3 -0
  125. package/dist/extraction/languages/cfscript.d.ts.map +1 -0
  126. package/dist/extraction/languages/cfscript.js +73 -0
  127. package/dist/extraction/languages/cfscript.js.map +1 -0
  128. package/dist/extraction/languages/cobol.d.ts +33 -0
  129. package/dist/extraction/languages/cobol.d.ts.map +1 -0
  130. package/dist/extraction/languages/cobol.js +499 -0
  131. package/dist/extraction/languages/cobol.js.map +1 -0
  132. package/dist/extraction/languages/csharp.d.ts +25 -0
  133. package/dist/extraction/languages/csharp.d.ts.map +1 -0
  134. package/dist/extraction/languages/csharp.js +175 -0
  135. package/dist/extraction/languages/csharp.js.map +1 -0
  136. package/dist/extraction/languages/dart.d.ts +3 -0
  137. package/dist/extraction/languages/dart.d.ts.map +1 -0
  138. package/dist/extraction/languages/dart.js +374 -0
  139. package/dist/extraction/languages/dart.js.map +1 -0
  140. package/dist/extraction/languages/erlang.d.ts +3 -0
  141. package/dist/extraction/languages/erlang.d.ts.map +1 -0
  142. package/dist/extraction/languages/erlang.js +350 -0
  143. package/dist/extraction/languages/erlang.js.map +1 -0
  144. package/dist/extraction/languages/go.d.ts +3 -0
  145. package/dist/extraction/languages/go.d.ts.map +1 -0
  146. package/dist/extraction/languages/go.js +111 -0
  147. package/dist/extraction/languages/go.js.map +1 -0
  148. package/dist/extraction/languages/index.d.ts +10 -0
  149. package/dist/extraction/languages/index.d.ts.map +1 -0
  150. package/dist/extraction/languages/index.js +71 -0
  151. package/dist/extraction/languages/index.js.map +1 -0
  152. package/dist/extraction/languages/java.d.ts +3 -0
  153. package/dist/extraction/languages/java.d.ts.map +1 -0
  154. package/dist/extraction/languages/java.js +315 -0
  155. package/dist/extraction/languages/java.js.map +1 -0
  156. package/dist/extraction/languages/javascript.d.ts +3 -0
  157. package/dist/extraction/languages/javascript.d.ts.map +1 -0
  158. package/dist/extraction/languages/javascript.js +106 -0
  159. package/dist/extraction/languages/javascript.js.map +1 -0
  160. package/dist/extraction/languages/kotlin.d.ts +3 -0
  161. package/dist/extraction/languages/kotlin.d.ts.map +1 -0
  162. package/dist/extraction/languages/kotlin.js +379 -0
  163. package/dist/extraction/languages/kotlin.js.map +1 -0
  164. package/dist/extraction/languages/lua.d.ts +3 -0
  165. package/dist/extraction/languages/lua.d.ts.map +1 -0
  166. package/dist/extraction/languages/lua.js +150 -0
  167. package/dist/extraction/languages/lua.js.map +1 -0
  168. package/dist/extraction/languages/luau.d.ts +3 -0
  169. package/dist/extraction/languages/luau.d.ts.map +1 -0
  170. package/dist/extraction/languages/luau.js +37 -0
  171. package/dist/extraction/languages/luau.js.map +1 -0
  172. package/dist/extraction/languages/nix.d.ts +3 -0
  173. package/dist/extraction/languages/nix.d.ts.map +1 -0
  174. package/dist/extraction/languages/nix.js +294 -0
  175. package/dist/extraction/languages/nix.js.map +1 -0
  176. package/dist/extraction/languages/objc.d.ts +3 -0
  177. package/dist/extraction/languages/objc.d.ts.map +1 -0
  178. package/dist/extraction/languages/objc.js +179 -0
  179. package/dist/extraction/languages/objc.js.map +1 -0
  180. package/dist/extraction/languages/pascal.d.ts +3 -0
  181. package/dist/extraction/languages/pascal.d.ts.map +1 -0
  182. package/dist/extraction/languages/pascal.js +77 -0
  183. package/dist/extraction/languages/pascal.js.map +1 -0
  184. package/dist/extraction/languages/php.d.ts +3 -0
  185. package/dist/extraction/languages/php.d.ts.map +1 -0
  186. package/dist/extraction/languages/php.js +196 -0
  187. package/dist/extraction/languages/php.js.map +1 -0
  188. package/dist/extraction/languages/python.d.ts +3 -0
  189. package/dist/extraction/languages/python.d.ts.map +1 -0
  190. package/dist/extraction/languages/python.js +56 -0
  191. package/dist/extraction/languages/python.js.map +1 -0
  192. package/dist/extraction/languages/r.d.ts +3 -0
  193. package/dist/extraction/languages/r.d.ts.map +1 -0
  194. package/dist/extraction/languages/r.js +314 -0
  195. package/dist/extraction/languages/r.js.map +1 -0
  196. package/dist/extraction/languages/ruby.d.ts +3 -0
  197. package/dist/extraction/languages/ruby.d.ts.map +1 -0
  198. package/dist/extraction/languages/ruby.js +149 -0
  199. package/dist/extraction/languages/ruby.js.map +1 -0
  200. package/dist/extraction/languages/rust.d.ts +3 -0
  201. package/dist/extraction/languages/rust.d.ts.map +1 -0
  202. package/dist/extraction/languages/rust.js +145 -0
  203. package/dist/extraction/languages/rust.js.map +1 -0
  204. package/dist/extraction/languages/scala.d.ts +3 -0
  205. package/dist/extraction/languages/scala.d.ts.map +1 -0
  206. package/dist/extraction/languages/scala.js +209 -0
  207. package/dist/extraction/languages/scala.js.map +1 -0
  208. package/dist/extraction/languages/solidity.d.ts +3 -0
  209. package/dist/extraction/languages/solidity.d.ts.map +1 -0
  210. package/dist/extraction/languages/solidity.js +293 -0
  211. package/dist/extraction/languages/solidity.js.map +1 -0
  212. package/dist/extraction/languages/swift.d.ts +3 -0
  213. package/dist/extraction/languages/swift.d.ts.map +1 -0
  214. package/dist/extraction/languages/swift.js +152 -0
  215. package/dist/extraction/languages/swift.js.map +1 -0
  216. package/dist/extraction/languages/terraform.d.ts +3 -0
  217. package/dist/extraction/languages/terraform.d.ts.map +1 -0
  218. package/dist/extraction/languages/terraform.js +641 -0
  219. package/dist/extraction/languages/terraform.js.map +1 -0
  220. package/dist/extraction/languages/typescript.d.ts +16 -0
  221. package/dist/extraction/languages/typescript.d.ts.map +1 -0
  222. package/dist/extraction/languages/typescript.js +167 -0
  223. package/dist/extraction/languages/typescript.js.map +1 -0
  224. package/dist/extraction/languages/vbnet.d.ts +11 -0
  225. package/dist/extraction/languages/vbnet.d.ts.map +1 -0
  226. package/dist/extraction/languages/vbnet.js +141 -0
  227. package/dist/extraction/languages/vbnet.js.map +1 -0
  228. package/dist/extraction/liquid-extractor.d.ts +59 -0
  229. package/dist/extraction/liquid-extractor.d.ts.map +1 -0
  230. package/dist/extraction/liquid-extractor.js +357 -0
  231. package/dist/extraction/liquid-extractor.js.map +1 -0
  232. package/dist/extraction/mybatis-extractor.d.ts +68 -0
  233. package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
  234. package/dist/extraction/mybatis-extractor.js +300 -0
  235. package/dist/extraction/mybatis-extractor.js.map +1 -0
  236. package/dist/extraction/parse-pool.d.ts +160 -0
  237. package/dist/extraction/parse-pool.d.ts.map +1 -0
  238. package/dist/extraction/parse-pool.js +402 -0
  239. package/dist/extraction/parse-pool.js.map +1 -0
  240. package/dist/extraction/parse-worker.d.ts +8 -0
  241. package/dist/extraction/parse-worker.d.ts.map +1 -0
  242. package/dist/extraction/parse-worker.js +138 -0
  243. package/dist/extraction/parse-worker.js.map +1 -0
  244. package/dist/extraction/razor-extractor.d.ts +42 -0
  245. package/dist/extraction/razor-extractor.d.ts.map +1 -0
  246. package/dist/extraction/razor-extractor.js +285 -0
  247. package/dist/extraction/razor-extractor.js.map +1 -0
  248. package/dist/extraction/store-worker.d.ts +24 -0
  249. package/dist/extraction/store-worker.d.ts.map +1 -0
  250. package/dist/extraction/store-worker.js +139 -0
  251. package/dist/extraction/store-worker.js.map +1 -0
  252. package/dist/extraction/store-writer.d.ts +63 -0
  253. package/dist/extraction/store-writer.d.ts.map +1 -0
  254. package/dist/extraction/store-writer.js +174 -0
  255. package/dist/extraction/store-writer.js.map +1 -0
  256. package/dist/extraction/svelte-extractor.d.ts +56 -0
  257. package/dist/extraction/svelte-extractor.d.ts.map +1 -0
  258. package/dist/extraction/svelte-extractor.js +275 -0
  259. package/dist/extraction/svelte-extractor.js.map +1 -0
  260. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  261. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  262. package/dist/extraction/tree-sitter-helpers.js +153 -0
  263. package/dist/extraction/tree-sitter-helpers.js.map +1 -0
  264. package/dist/extraction/tree-sitter-types.d.ts +260 -0
  265. package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  266. package/dist/extraction/tree-sitter-types.js +10 -0
  267. package/dist/extraction/tree-sitter-types.js.map +1 -0
  268. package/dist/extraction/tree-sitter.d.ts +728 -0
  269. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  270. package/dist/extraction/tree-sitter.js +6676 -0
  271. package/dist/extraction/tree-sitter.js.map +1 -0
  272. package/dist/extraction/vue-extractor.d.ts +51 -0
  273. package/dist/extraction/vue-extractor.d.ts.map +1 -0
  274. package/dist/extraction/vue-extractor.js +254 -0
  275. package/dist/extraction/vue-extractor.js.map +1 -0
  276. package/dist/extraction/wasm/tree-sitter-arkts.wasm +0 -0
  277. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  278. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  279. package/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
  280. package/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
  281. package/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
  282. package/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
  283. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  284. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  285. package/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
  286. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  287. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  288. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  289. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  290. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  291. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  292. package/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
  293. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  294. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  295. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  296. package/dist/extraction/wasm/tree-sitter-r.wasm +0 -0
  297. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  298. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  299. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  300. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  301. package/dist/extraction/wasm/tree-sitter-terraform.wasm +0 -0
  302. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  303. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  304. package/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
  305. package/dist/extraction/wasm-runtime-flags.d.ts +53 -0
  306. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
  307. package/dist/extraction/wasm-runtime-flags.js +130 -0
  308. package/dist/extraction/wasm-runtime-flags.js.map +1 -0
  309. package/dist/graph/index.d.ts +8 -0
  310. package/dist/graph/index.d.ts.map +1 -0
  311. package/dist/graph/index.js +13 -0
  312. package/dist/graph/index.js.map +1 -0
  313. package/dist/graph/queries.d.ts +106 -0
  314. package/dist/graph/queries.d.ts.map +1 -0
  315. package/dist/graph/queries.js +341 -0
  316. package/dist/graph/queries.js.map +1 -0
  317. package/dist/graph/traversal.d.ts +127 -0
  318. package/dist/graph/traversal.d.ts.map +1 -0
  319. package/dist/graph/traversal.js +599 -0
  320. package/dist/graph/traversal.js.map +1 -0
  321. package/dist/index.d.ts +677 -0
  322. package/dist/index.d.ts.map +1 -0
  323. package/dist/index.js +1718 -0
  324. package/dist/index.js.map +1 -0
  325. package/dist/installer/beta-signup.d.ts +54 -0
  326. package/dist/installer/beta-signup.d.ts.map +1 -0
  327. package/dist/installer/beta-signup.js +178 -0
  328. package/dist/installer/beta-signup.js.map +1 -0
  329. package/dist/installer/config-writer.d.ts +28 -0
  330. package/dist/installer/config-writer.d.ts.map +1 -0
  331. package/dist/installer/config-writer.js +91 -0
  332. package/dist/installer/config-writer.js.map +1 -0
  333. package/dist/installer/index.d.ts +144 -0
  334. package/dist/installer/index.d.ts.map +1 -0
  335. package/dist/installer/index.js +634 -0
  336. package/dist/installer/index.js.map +1 -0
  337. package/dist/installer/instructions-template.d.ts +41 -0
  338. package/dist/installer/instructions-template.d.ts.map +1 -0
  339. package/dist/installer/instructions-template.js +53 -0
  340. package/dist/installer/instructions-template.js.map +1 -0
  341. package/dist/installer/targets/antigravity.d.ts +57 -0
  342. package/dist/installer/targets/antigravity.d.ts.map +1 -0
  343. package/dist/installer/targets/antigravity.js +308 -0
  344. package/dist/installer/targets/antigravity.js.map +1 -0
  345. package/dist/installer/targets/claude.d.ts +62 -0
  346. package/dist/installer/targets/claude.d.ts.map +1 -0
  347. package/dist/installer/targets/claude.js +486 -0
  348. package/dist/installer/targets/claude.js.map +1 -0
  349. package/dist/installer/targets/codex.d.ts +18 -0
  350. package/dist/installer/targets/codex.d.ts.map +1 -0
  351. package/dist/installer/targets/codex.js +185 -0
  352. package/dist/installer/targets/codex.js.map +1 -0
  353. package/dist/installer/targets/copilot-cli.d.ts +32 -0
  354. package/dist/installer/targets/copilot-cli.d.ts.map +1 -0
  355. package/dist/installer/targets/copilot-cli.js +209 -0
  356. package/dist/installer/targets/copilot-cli.js.map +1 -0
  357. package/dist/installer/targets/copilot-jetbrains.d.ts +42 -0
  358. package/dist/installer/targets/copilot-jetbrains.d.ts.map +1 -0
  359. package/dist/installer/targets/copilot-jetbrains.js +238 -0
  360. package/dist/installer/targets/copilot-jetbrains.js.map +1 -0
  361. package/dist/installer/targets/copilot-vscode.d.ts +47 -0
  362. package/dist/installer/targets/copilot-vscode.d.ts.map +1 -0
  363. package/dist/installer/targets/copilot-vscode.js +219 -0
  364. package/dist/installer/targets/copilot-vscode.js.map +1 -0
  365. package/dist/installer/targets/cursor.d.ts +35 -0
  366. package/dist/installer/targets/cursor.d.ts.map +1 -0
  367. package/dist/installer/targets/cursor.js +254 -0
  368. package/dist/installer/targets/cursor.js.map +1 -0
  369. package/dist/installer/targets/dsh.d.ts +97 -0
  370. package/dist/installer/targets/dsh.d.ts.map +1 -0
  371. package/dist/installer/targets/dsh.js +358 -0
  372. package/dist/installer/targets/dsh.js.map +1 -0
  373. package/dist/installer/targets/gemini.d.ts +26 -0
  374. package/dist/installer/targets/gemini.d.ts.map +1 -0
  375. package/dist/installer/targets/gemini.js +165 -0
  376. package/dist/installer/targets/gemini.js.map +1 -0
  377. package/dist/installer/targets/hermes.d.ts +18 -0
  378. package/dist/installer/targets/hermes.d.ts.map +1 -0
  379. package/dist/installer/targets/hermes.js +359 -0
  380. package/dist/installer/targets/hermes.js.map +1 -0
  381. package/dist/installer/targets/kiro.d.ts +27 -0
  382. package/dist/installer/targets/kiro.d.ts.map +1 -0
  383. package/dist/installer/targets/kiro.js +178 -0
  384. package/dist/installer/targets/kiro.js.map +1 -0
  385. package/dist/installer/targets/opencode.d.ts +38 -0
  386. package/dist/installer/targets/opencode.d.ts.map +1 -0
  387. package/dist/installer/targets/opencode.js +288 -0
  388. package/dist/installer/targets/opencode.js.map +1 -0
  389. package/dist/installer/targets/registry.d.ts +35 -0
  390. package/dist/installer/targets/registry.d.ts.map +1 -0
  391. package/dist/installer/targets/registry.js +101 -0
  392. package/dist/installer/targets/registry.js.map +1 -0
  393. package/dist/installer/targets/shared.d.ts +132 -0
  394. package/dist/installer/targets/shared.d.ts.map +1 -0
  395. package/dist/installer/targets/shared.js +314 -0
  396. package/dist/installer/targets/shared.js.map +1 -0
  397. package/dist/installer/targets/toml.d.ts +53 -0
  398. package/dist/installer/targets/toml.d.ts.map +1 -0
  399. package/dist/installer/targets/toml.js +226 -0
  400. package/dist/installer/targets/toml.js.map +1 -0
  401. package/dist/installer/targets/types.d.ts +109 -0
  402. package/dist/installer/targets/types.d.ts.map +1 -0
  403. package/dist/installer/targets/types.js +16 -0
  404. package/dist/installer/targets/types.js.map +1 -0
  405. package/dist/installer/targets/zcode.d.ts +106 -0
  406. package/dist/installer/targets/zcode.d.ts.map +1 -0
  407. package/dist/installer/targets/zcode.js +451 -0
  408. package/dist/installer/targets/zcode.js.map +1 -0
  409. package/dist/mcp/daemon-manager.d.ts +42 -0
  410. package/dist/mcp/daemon-manager.d.ts.map +1 -0
  411. package/dist/mcp/daemon-manager.js +129 -0
  412. package/dist/mcp/daemon-manager.js.map +1 -0
  413. package/dist/mcp/daemon-paths.d.ts +73 -0
  414. package/dist/mcp/daemon-paths.d.ts.map +1 -0
  415. package/dist/mcp/daemon-paths.js +165 -0
  416. package/dist/mcp/daemon-paths.js.map +1 -0
  417. package/dist/mcp/daemon-registry.d.ts +47 -0
  418. package/dist/mcp/daemon-registry.d.ts.map +1 -0
  419. package/dist/mcp/daemon-registry.js +233 -0
  420. package/dist/mcp/daemon-registry.js.map +1 -0
  421. package/dist/mcp/daemon.d.ts +290 -0
  422. package/dist/mcp/daemon.d.ts.map +1 -0
  423. package/dist/mcp/daemon.js +862 -0
  424. package/dist/mcp/daemon.js.map +1 -0
  425. package/dist/mcp/dynamic-boundaries.d.ts +41 -0
  426. package/dist/mcp/dynamic-boundaries.d.ts.map +1 -0
  427. package/dist/mcp/dynamic-boundaries.js +360 -0
  428. package/dist/mcp/dynamic-boundaries.js.map +1 -0
  429. package/dist/mcp/early-ppid.d.ts +26 -0
  430. package/dist/mcp/early-ppid.d.ts.map +1 -0
  431. package/dist/mcp/early-ppid.js +29 -0
  432. package/dist/mcp/early-ppid.js.map +1 -0
  433. package/dist/mcp/engine.d.ts +122 -0
  434. package/dist/mcp/engine.d.ts.map +1 -0
  435. package/dist/mcp/engine.js +350 -0
  436. package/dist/mcp/engine.js.map +1 -0
  437. package/dist/mcp/explore-dedup.d.ts +137 -0
  438. package/dist/mcp/explore-dedup.d.ts.map +1 -0
  439. package/dist/mcp/explore-dedup.js +236 -0
  440. package/dist/mcp/explore-dedup.js.map +1 -0
  441. package/dist/mcp/explore-diagnostics.d.ts +287 -0
  442. package/dist/mcp/explore-diagnostics.d.ts.map +1 -0
  443. package/dist/mcp/explore-diagnostics.js +555 -0
  444. package/dist/mcp/explore-diagnostics.js.map +1 -0
  445. package/dist/mcp/explore-session-state.d.ts +217 -0
  446. package/dist/mcp/explore-session-state.d.ts.map +1 -0
  447. package/dist/mcp/explore-session-state.js +322 -0
  448. package/dist/mcp/explore-session-state.js.map +1 -0
  449. package/dist/mcp/index.d.ts +137 -0
  450. package/dist/mcp/index.d.ts.map +1 -0
  451. package/dist/mcp/index.js +554 -0
  452. package/dist/mcp/index.js.map +1 -0
  453. package/dist/mcp/liveness-watchdog.d.ts +35 -0
  454. package/dist/mcp/liveness-watchdog.d.ts.map +1 -0
  455. package/dist/mcp/liveness-watchdog.js +269 -0
  456. package/dist/mcp/liveness-watchdog.js.map +1 -0
  457. package/dist/mcp/ppid-watchdog.d.ts +62 -0
  458. package/dist/mcp/ppid-watchdog.d.ts.map +1 -0
  459. package/dist/mcp/ppid-watchdog.js +64 -0
  460. package/dist/mcp/ppid-watchdog.js.map +1 -0
  461. package/dist/mcp/proxy.d.ts +87 -0
  462. package/dist/mcp/proxy.d.ts.map +1 -0
  463. package/dist/mcp/proxy.js +672 -0
  464. package/dist/mcp/proxy.js.map +1 -0
  465. package/dist/mcp/query-pool.d.ts +108 -0
  466. package/dist/mcp/query-pool.d.ts.map +1 -0
  467. package/dist/mcp/query-pool.js +315 -0
  468. package/dist/mcp/query-pool.js.map +1 -0
  469. package/dist/mcp/query-worker.d.ts +24 -0
  470. package/dist/mcp/query-worker.d.ts.map +1 -0
  471. package/dist/mcp/query-worker.js +87 -0
  472. package/dist/mcp/query-worker.js.map +1 -0
  473. package/dist/mcp/server-instructions.d.ts +34 -0
  474. package/dist/mcp/server-instructions.d.ts.map +1 -0
  475. package/dist/mcp/server-instructions.js +111 -0
  476. package/dist/mcp/server-instructions.js.map +1 -0
  477. package/dist/mcp/session.d.ts +109 -0
  478. package/dist/mcp/session.d.ts.map +1 -0
  479. package/dist/mcp/session.js +375 -0
  480. package/dist/mcp/session.js.map +1 -0
  481. package/dist/mcp/startup-handshake.d.ts +44 -0
  482. package/dist/mcp/startup-handshake.d.ts.map +1 -0
  483. package/dist/mcp/startup-handshake.js +73 -0
  484. package/dist/mcp/startup-handshake.js.map +1 -0
  485. package/dist/mcp/stdin-teardown.d.ts +27 -0
  486. package/dist/mcp/stdin-teardown.d.ts.map +1 -0
  487. package/dist/mcp/stdin-teardown.js +49 -0
  488. package/dist/mcp/stdin-teardown.js.map +1 -0
  489. package/dist/mcp/tools.d.ts +862 -0
  490. package/dist/mcp/tools.d.ts.map +1 -0
  491. package/dist/mcp/tools.js +6526 -0
  492. package/dist/mcp/tools.js.map +1 -0
  493. package/dist/mcp/transport.d.ts +188 -0
  494. package/dist/mcp/transport.d.ts.map +1 -0
  495. package/dist/mcp/transport.js +377 -0
  496. package/dist/mcp/transport.js.map +1 -0
  497. package/dist/mcp/version.d.ts +19 -0
  498. package/dist/mcp/version.d.ts.map +1 -0
  499. package/dist/mcp/version.js +71 -0
  500. package/dist/mcp/version.js.map +1 -0
  501. package/dist/project-config.d.ts +94 -0
  502. package/dist/project-config.d.ts.map +1 -0
  503. package/dist/project-config.js +374 -0
  504. package/dist/project-config.js.map +1 -0
  505. package/dist/prompt-hook-output.d.ts +23 -0
  506. package/dist/prompt-hook-output.d.ts.map +1 -0
  507. package/dist/prompt-hook-output.js +35 -0
  508. package/dist/prompt-hook-output.js.map +1 -0
  509. package/dist/resolution/c-fnptr-synthesizer.d.ts +6 -0
  510. package/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -0
  511. package/dist/resolution/c-fnptr-synthesizer.js +1506 -0
  512. package/dist/resolution/c-fnptr-synthesizer.js.map +1 -0
  513. package/dist/resolution/callback-synthesizer.d.ts +59 -0
  514. package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
  515. package/dist/resolution/callback-synthesizer.js +4030 -0
  516. package/dist/resolution/callback-synthesizer.js.map +1 -0
  517. package/dist/resolution/cooperative-yield.d.ts +40 -0
  518. package/dist/resolution/cooperative-yield.d.ts.map +1 -0
  519. package/dist/resolution/cooperative-yield.js +44 -0
  520. package/dist/resolution/cooperative-yield.js.map +1 -0
  521. package/dist/resolution/frameworks/astro.d.ts +9 -0
  522. package/dist/resolution/frameworks/astro.d.ts.map +1 -0
  523. package/dist/resolution/frameworks/astro.js +169 -0
  524. package/dist/resolution/frameworks/astro.js.map +1 -0
  525. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  526. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  527. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  528. package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  529. package/dist/resolution/frameworks/cics.d.ts +20 -0
  530. package/dist/resolution/frameworks/cics.d.ts.map +1 -0
  531. package/dist/resolution/frameworks/cics.js +90 -0
  532. package/dist/resolution/frameworks/cics.js.map +1 -0
  533. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  534. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  535. package/dist/resolution/frameworks/csharp.js +241 -0
  536. package/dist/resolution/frameworks/csharp.js.map +1 -0
  537. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  538. package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
  539. package/dist/resolution/frameworks/drupal.js +367 -0
  540. package/dist/resolution/frameworks/drupal.js.map +1 -0
  541. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  542. package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
  543. package/dist/resolution/frameworks/expo-modules.js +148 -0
  544. package/dist/resolution/frameworks/expo-modules.js.map +1 -0
  545. package/dist/resolution/frameworks/express.d.ts +8 -0
  546. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  547. package/dist/resolution/frameworks/express.js +308 -0
  548. package/dist/resolution/frameworks/express.js.map +1 -0
  549. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  550. package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
  551. package/dist/resolution/frameworks/fabric.js +354 -0
  552. package/dist/resolution/frameworks/fabric.js.map +1 -0
  553. package/dist/resolution/frameworks/go.d.ts +8 -0
  554. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  555. package/dist/resolution/frameworks/go.js +184 -0
  556. package/dist/resolution/frameworks/go.js.map +1 -0
  557. package/dist/resolution/frameworks/goframe.d.ts +41 -0
  558. package/dist/resolution/frameworks/goframe.d.ts.map +1 -0
  559. package/dist/resolution/frameworks/goframe.js +112 -0
  560. package/dist/resolution/frameworks/goframe.js.map +1 -0
  561. package/dist/resolution/frameworks/index.d.ts +50 -0
  562. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  563. package/dist/resolution/frameworks/index.js +175 -0
  564. package/dist/resolution/frameworks/index.js.map +1 -0
  565. package/dist/resolution/frameworks/java.d.ts +8 -0
  566. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  567. package/dist/resolution/frameworks/java.js +517 -0
  568. package/dist/resolution/frameworks/java.js.map +1 -0
  569. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  570. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  571. package/dist/resolution/frameworks/laravel.js +257 -0
  572. package/dist/resolution/frameworks/laravel.js.map +1 -0
  573. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  574. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  575. package/dist/resolution/frameworks/nestjs.js +698 -0
  576. package/dist/resolution/frameworks/nestjs.js.map +1 -0
  577. package/dist/resolution/frameworks/play.d.ts +19 -0
  578. package/dist/resolution/frameworks/play.d.ts.map +1 -0
  579. package/dist/resolution/frameworks/play.js +111 -0
  580. package/dist/resolution/frameworks/play.js.map +1 -0
  581. package/dist/resolution/frameworks/python.d.ts +10 -0
  582. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  583. package/dist/resolution/frameworks/python.js +400 -0
  584. package/dist/resolution/frameworks/python.js.map +1 -0
  585. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  586. package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
  587. package/dist/resolution/frameworks/react-native.js +410 -0
  588. package/dist/resolution/frameworks/react-native.js.map +1 -0
  589. package/dist/resolution/frameworks/react.d.ts +8 -0
  590. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  591. package/dist/resolution/frameworks/react.js +334 -0
  592. package/dist/resolution/frameworks/react.js.map +1 -0
  593. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  594. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  595. package/dist/resolution/frameworks/ruby.js +302 -0
  596. package/dist/resolution/frameworks/ruby.js.map +1 -0
  597. package/dist/resolution/frameworks/rust.d.ts +8 -0
  598. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  599. package/dist/resolution/frameworks/rust.js +304 -0
  600. package/dist/resolution/frameworks/rust.js.map +1 -0
  601. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  602. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  603. package/dist/resolution/frameworks/svelte.js +253 -0
  604. package/dist/resolution/frameworks/svelte.js.map +1 -0
  605. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  606. package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
  607. package/dist/resolution/frameworks/swift-objc.js +252 -0
  608. package/dist/resolution/frameworks/swift-objc.js.map +1 -0
  609. package/dist/resolution/frameworks/swift.d.ts +10 -0
  610. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  611. package/dist/resolution/frameworks/swift.js +400 -0
  612. package/dist/resolution/frameworks/swift.js.map +1 -0
  613. package/dist/resolution/frameworks/terraform.d.ts +38 -0
  614. package/dist/resolution/frameworks/terraform.d.ts.map +1 -0
  615. package/dist/resolution/frameworks/terraform.js +277 -0
  616. package/dist/resolution/frameworks/terraform.js.map +1 -0
  617. package/dist/resolution/frameworks/vue.d.ts +9 -0
  618. package/dist/resolution/frameworks/vue.d.ts.map +1 -0
  619. package/dist/resolution/frameworks/vue.js +303 -0
  620. package/dist/resolution/frameworks/vue.js.map +1 -0
  621. package/dist/resolution/go-module.d.ts +26 -0
  622. package/dist/resolution/go-module.d.ts.map +1 -0
  623. package/dist/resolution/go-module.js +78 -0
  624. package/dist/resolution/go-module.js.map +1 -0
  625. package/dist/resolution/goframe-synthesizer.d.ts +29 -0
  626. package/dist/resolution/goframe-synthesizer.d.ts.map +1 -0
  627. package/dist/resolution/goframe-synthesizer.js +163 -0
  628. package/dist/resolution/goframe-synthesizer.js.map +1 -0
  629. package/dist/resolution/import-resolver.d.ts +84 -0
  630. package/dist/resolution/import-resolver.d.ts.map +1 -0
  631. package/dist/resolution/import-resolver.js +2134 -0
  632. package/dist/resolution/import-resolver.js.map +1 -0
  633. package/dist/resolution/index.d.ts +343 -0
  634. package/dist/resolution/index.d.ts.map +1 -0
  635. package/dist/resolution/index.js +2339 -0
  636. package/dist/resolution/index.js.map +1 -0
  637. package/dist/resolution/lru-cache.d.ts +24 -0
  638. package/dist/resolution/lru-cache.d.ts.map +1 -0
  639. package/dist/resolution/lru-cache.js +62 -0
  640. package/dist/resolution/lru-cache.js.map +1 -0
  641. package/dist/resolution/memory-budget.d.ts +48 -0
  642. package/dist/resolution/memory-budget.d.ts.map +1 -0
  643. package/dist/resolution/memory-budget.js +162 -0
  644. package/dist/resolution/memory-budget.js.map +1 -0
  645. package/dist/resolution/name-matcher.d.ts +123 -0
  646. package/dist/resolution/name-matcher.d.ts.map +1 -0
  647. package/dist/resolution/name-matcher.js +2134 -0
  648. package/dist/resolution/name-matcher.js.map +1 -0
  649. package/dist/resolution/path-aliases.d.ts +68 -0
  650. package/dist/resolution/path-aliases.d.ts.map +1 -0
  651. package/dist/resolution/path-aliases.js +238 -0
  652. package/dist/resolution/path-aliases.js.map +1 -0
  653. package/dist/resolution/resolver-pool.d.ts +106 -0
  654. package/dist/resolution/resolver-pool.d.ts.map +1 -0
  655. package/dist/resolution/resolver-pool.js +344 -0
  656. package/dist/resolution/resolver-pool.js.map +1 -0
  657. package/dist/resolution/resolver-worker.d.ts +17 -0
  658. package/dist/resolution/resolver-worker.d.ts.map +1 -0
  659. package/dist/resolution/resolver-worker.js +141 -0
  660. package/dist/resolution/resolver-worker.js.map +1 -0
  661. package/dist/resolution/strip-comments.d.ts +27 -0
  662. package/dist/resolution/strip-comments.d.ts.map +1 -0
  663. package/dist/resolution/strip-comments.js +492 -0
  664. package/dist/resolution/strip-comments.js.map +1 -0
  665. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  666. package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
  667. package/dist/resolution/swift-objc-bridge.js +256 -0
  668. package/dist/resolution/swift-objc-bridge.js.map +1 -0
  669. package/dist/resolution/types.d.ts +265 -0
  670. package/dist/resolution/types.d.ts.map +1 -0
  671. package/dist/resolution/types.js +8 -0
  672. package/dist/resolution/types.js.map +1 -0
  673. package/dist/resolution/workspace-packages.d.ts +58 -0
  674. package/dist/resolution/workspace-packages.d.ts.map +1 -0
  675. package/dist/resolution/workspace-packages.js +346 -0
  676. package/dist/resolution/workspace-packages.js.map +1 -0
  677. package/dist/search/identifier-segments.d.ts +60 -0
  678. package/dist/search/identifier-segments.d.ts.map +1 -0
  679. package/dist/search/identifier-segments.js +176 -0
  680. package/dist/search/identifier-segments.js.map +1 -0
  681. package/dist/search/query-parser.d.ts +57 -0
  682. package/dist/search/query-parser.d.ts.map +1 -0
  683. package/dist/search/query-parser.js +177 -0
  684. package/dist/search/query-parser.js.map +1 -0
  685. package/dist/search/query-utils.d.ts +87 -0
  686. package/dist/search/query-utils.d.ts.map +1 -0
  687. package/dist/search/query-utils.js +450 -0
  688. package/dist/search/query-utils.js.map +1 -0
  689. package/dist/sync/git-hooks.d.ts +45 -0
  690. package/dist/sync/git-hooks.d.ts.map +1 -0
  691. package/dist/sync/git-hooks.js +227 -0
  692. package/dist/sync/git-hooks.js.map +1 -0
  693. package/dist/sync/index.d.ts +19 -0
  694. package/dist/sync/index.d.ts.map +1 -0
  695. package/dist/sync/index.js +35 -0
  696. package/dist/sync/index.js.map +1 -0
  697. package/dist/sync/watch-policy.d.ts +48 -0
  698. package/dist/sync/watch-policy.d.ts.map +1 -0
  699. package/dist/sync/watch-policy.js +124 -0
  700. package/dist/sync/watch-policy.js.map +1 -0
  701. package/dist/sync/watcher.d.ts +379 -0
  702. package/dist/sync/watcher.d.ts.map +1 -0
  703. package/dist/sync/watcher.js +921 -0
  704. package/dist/sync/watcher.js.map +1 -0
  705. package/dist/sync/worktree.d.ts +63 -0
  706. package/dist/sync/worktree.d.ts.map +1 -0
  707. package/dist/sync/worktree.js +182 -0
  708. package/dist/sync/worktree.js.map +1 -0
  709. package/dist/telemetry/index.d.ts +143 -0
  710. package/dist/telemetry/index.d.ts.map +1 -0
  711. package/dist/telemetry/index.js +541 -0
  712. package/dist/telemetry/index.js.map +1 -0
  713. package/dist/types.d.ts +465 -0
  714. package/dist/types.d.ts.map +1 -0
  715. package/dist/types.js +117 -0
  716. package/dist/types.js.map +1 -0
  717. package/dist/ui/color.d.ts +21 -0
  718. package/dist/ui/color.d.ts.map +1 -0
  719. package/dist/ui/color.js +42 -0
  720. package/dist/ui/color.js.map +1 -0
  721. package/dist/ui/glyphs.d.ts +67 -0
  722. package/dist/ui/glyphs.d.ts.map +1 -0
  723. package/dist/ui/glyphs.js +125 -0
  724. package/dist/ui/glyphs.js.map +1 -0
  725. package/dist/ui/shimmer-progress.d.ts +11 -0
  726. package/dist/ui/shimmer-progress.d.ts.map +1 -0
  727. package/dist/ui/shimmer-progress.js +164 -0
  728. package/dist/ui/shimmer-progress.js.map +1 -0
  729. package/dist/ui/shimmer-worker.d.ts +2 -0
  730. package/dist/ui/shimmer-worker.d.ts.map +1 -0
  731. package/dist/ui/shimmer-worker.js +126 -0
  732. package/dist/ui/shimmer-worker.js.map +1 -0
  733. package/dist/ui/types.d.ts +15 -0
  734. package/dist/ui/types.d.ts.map +1 -0
  735. package/dist/ui/types.js +3 -0
  736. package/dist/ui/types.js.map +1 -0
  737. package/dist/upgrade/index.d.ts +171 -0
  738. package/dist/upgrade/index.d.ts.map +1 -0
  739. package/dist/upgrade/index.js +659 -0
  740. package/dist/upgrade/index.js.map +1 -0
  741. package/dist/upgrade/remove-binary.d.ts +87 -0
  742. package/dist/upgrade/remove-binary.d.ts.map +1 -0
  743. package/dist/upgrade/remove-binary.js +289 -0
  744. package/dist/upgrade/remove-binary.js.map +1 -0
  745. package/dist/upgrade/update-check.d.ts +92 -0
  746. package/dist/upgrade/update-check.d.ts.map +1 -0
  747. package/dist/upgrade/update-check.js +258 -0
  748. package/dist/upgrade/update-check.js.map +1 -0
  749. package/dist/utils.d.ts +224 -0
  750. package/dist/utils.d.ts.map +1 -0
  751. package/dist/utils.js +583 -0
  752. package/dist/utils.js.map +1 -0
  753. package/package.json +61 -0
  754. package/scripts/add-lang/bench.sh +60 -0
  755. package/scripts/add-lang/check-grammar.mjs +75 -0
  756. package/scripts/add-lang/dump-ast.mjs +103 -0
  757. package/scripts/add-lang/verify-extraction.mjs +70 -0
  758. package/scripts/agent-eval/ab-adoption.sh +91 -0
  759. package/scripts/agent-eval/ab-hook.sh +86 -0
  760. package/scripts/agent-eval/ab-impl.sh +78 -0
  761. package/scripts/agent-eval/ab-new-vs-baseline.sh +161 -0
  762. package/scripts/agent-eval/ab-sufficiency.sh +78 -0
  763. package/scripts/agent-eval/allocation-fixtures.json +344 -0
  764. package/scripts/agent-eval/arms-F.sh +21 -0
  765. package/scripts/agent-eval/arms-matrix.sh +37 -0
  766. package/scripts/agent-eval/audit.sh +68 -0
  767. package/scripts/agent-eval/bench-readme.sh +48 -0
  768. package/scripts/agent-eval/bench-why-repo.sh +22 -0
  769. package/scripts/agent-eval/block-read-hook.sh +19 -0
  770. package/scripts/agent-eval/compare-arms.mjs +209 -0
  771. package/scripts/agent-eval/diff-index-drift.mjs +102 -0
  772. package/scripts/agent-eval/hook-settings.json +15 -0
  773. package/scripts/agent-eval/itrun.sh +120 -0
  774. package/scripts/agent-eval/no-cli-shim.sh +96 -0
  775. package/scripts/agent-eval/offload-eval-3arm.sh +72 -0
  776. package/scripts/agent-eval/offload-eval-cost.mjs +133 -0
  777. package/scripts/agent-eval/offload-eval-effort.mjs +108 -0
  778. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -0
  779. package/scripts/agent-eval/offload-eval-frontload.sh +47 -0
  780. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -0
  781. package/scripts/agent-eval/offload-eval-hook.mjs +84 -0
  782. package/scripts/agent-eval/offload-eval-judge.mjs +103 -0
  783. package/scripts/agent-eval/offload-eval-matrix.sh +20 -0
  784. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -0
  785. package/scripts/agent-eval/offload-eval-refs1.sh +50 -0
  786. package/scripts/agent-eval/offload-eval-setup.sh +24 -0
  787. package/scripts/agent-eval/offload-eval-styles.sh +72 -0
  788. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -0
  789. package/scripts/agent-eval/offload-eval.md +76 -0
  790. package/scripts/agent-eval/parse-arms.mjs +116 -0
  791. package/scripts/agent-eval/parse-bench-readme.mjs +238 -0
  792. package/scripts/agent-eval/parse-run.mjs +1401 -0
  793. package/scripts/agent-eval/parse-session.mjs +130 -0
  794. package/scripts/agent-eval/probe-allocation.mjs +335 -0
  795. package/scripts/agent-eval/probe-context.mjs +21 -0
  796. package/scripts/agent-eval/probe-decl-only.mjs +198 -0
  797. package/scripts/agent-eval/probe-explore.mjs +40 -0
  798. package/scripts/agent-eval/probe-factory-closure.mjs +147 -0
  799. package/scripts/agent-eval/probe-file-spend.mjs +195 -0
  800. package/scripts/agent-eval/probe-named-symbol.mjs +163 -0
  801. package/scripts/agent-eval/probe-node.mjs +20 -0
  802. package/scripts/agent-eval/probe-suite-envelope.mjs +124 -0
  803. package/scripts/agent-eval/probe-sweep.mjs +119 -0
  804. package/scripts/agent-eval/probe-trace.mjs +20 -0
  805. package/scripts/agent-eval/redirect-read-hook.sh +38 -0
  806. package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
  807. package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
  808. package/scripts/agent-eval/run-agent.sh +34 -0
  809. package/scripts/agent-eval/run-all.sh +149 -0
  810. package/scripts/agent-eval/run-arms.sh +56 -0
  811. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  812. package/scripts/build-bundle.sh +145 -0
  813. package/scripts/build-kernel.sh +87 -0
  814. package/scripts/dump-graph.mjs +57 -0
  815. package/scripts/extract-release-notes.mjs +130 -0
  816. package/scripts/kernel-parity.mjs +283 -0
  817. package/scripts/local-install.sh +41 -0
  818. package/scripts/npm-sdk.js +75 -0
  819. package/scripts/npm-shim.js +279 -0
  820. package/scripts/pack-npm.sh +123 -0
  821. package/scripts/prepare-release.mjs +270 -0
package/dist/index.js ADDED
@@ -0,0 +1,1718 @@
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.LockUnavailableError = 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.QueryBuilder = exports.DatabaseConnection = exports.getDatabasePath = void 0;
46
+ const path = __importStar(require("path"));
47
+ const db_1 = require("./db");
48
+ const wal_valve_1 = require("./db/wal-valve");
49
+ const queries_1 = require("./db/queries");
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 context_1 = require("./context");
55
+ const utils_1 = require("./utils");
56
+ const sync_1 = require("./sync");
57
+ const extraction_version_1 = require("./extraction/extraction-version");
58
+ const directory_2 = require("./directory");
59
+ const query_utils_1 = require("./search/query-utils");
60
+ const version_1 = require("./mcp/version");
61
+ const identifier_segments_1 = require("./search/identifier-segments");
62
+ const cooperative_yield_1 = require("./resolution/cooperative-yield");
63
+ const resolver_pool_1 = require("./resolution/resolver-pool");
64
+ // Re-export types for consumers
65
+ __exportStar(require("./types"), exports);
66
+ // Storage building blocks for embedded/SDK consumers that drive the graph
67
+ // directly (open a DB, run prepared queries) rather than through the CodeGraph
68
+ // facade. Exposed from the package entry so they no longer require deep imports
69
+ // into dist/ (issue #354).
70
+ var db_2 = require("./db");
71
+ Object.defineProperty(exports, "getDatabasePath", { enumerable: true, get: function () { return db_2.getDatabasePath; } });
72
+ Object.defineProperty(exports, "DatabaseConnection", { enumerable: true, get: function () { return db_2.DatabaseConnection; } });
73
+ var queries_2 = require("./db/queries");
74
+ Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return queries_2.QueryBuilder; } });
75
+ var directory_3 = require("./directory");
76
+ Object.defineProperty(exports, "getCodeGraphDir", { enumerable: true, get: function () { return directory_3.getCodeGraphDir; } });
77
+ Object.defineProperty(exports, "isInitialized", { enumerable: true, get: function () { return directory_3.isInitialized; } });
78
+ Object.defineProperty(exports, "findNearestCodeGraphRoot", { enumerable: true, get: function () { return directory_3.findNearestCodeGraphRoot; } });
79
+ Object.defineProperty(exports, "CODEGRAPH_DIR", { enumerable: true, get: function () { return directory_3.CODEGRAPH_DIR; } });
80
+ var extraction_2 = require("./extraction");
81
+ Object.defineProperty(exports, "detectLanguage", { enumerable: true, get: function () { return extraction_2.detectLanguage; } });
82
+ Object.defineProperty(exports, "isLanguageSupported", { enumerable: true, get: function () { return extraction_2.isLanguageSupported; } });
83
+ Object.defineProperty(exports, "isGrammarLoaded", { enumerable: true, get: function () { return extraction_2.isGrammarLoaded; } });
84
+ Object.defineProperty(exports, "getSupportedLanguages", { enumerable: true, get: function () { return extraction_2.getSupportedLanguages; } });
85
+ Object.defineProperty(exports, "initGrammars", { enumerable: true, get: function () { return extraction_2.initGrammars; } });
86
+ Object.defineProperty(exports, "loadGrammarsForLanguages", { enumerable: true, get: function () { return extraction_2.loadGrammarsForLanguages; } });
87
+ Object.defineProperty(exports, "loadAllGrammars", { enumerable: true, get: function () { return extraction_2.loadAllGrammars; } });
88
+ var errors_1 = require("./errors");
89
+ Object.defineProperty(exports, "CodeGraphError", { enumerable: true, get: function () { return errors_1.CodeGraphError; } });
90
+ Object.defineProperty(exports, "FileError", { enumerable: true, get: function () { return errors_1.FileError; } });
91
+ Object.defineProperty(exports, "ParseError", { enumerable: true, get: function () { return errors_1.ParseError; } });
92
+ Object.defineProperty(exports, "DatabaseError", { enumerable: true, get: function () { return errors_1.DatabaseError; } });
93
+ Object.defineProperty(exports, "SearchError", { enumerable: true, get: function () { return errors_1.SearchError; } });
94
+ Object.defineProperty(exports, "VectorError", { enumerable: true, get: function () { return errors_1.VectorError; } });
95
+ Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return errors_1.ConfigError; } });
96
+ Object.defineProperty(exports, "setLogger", { enumerable: true, get: function () { return errors_1.setLogger; } });
97
+ Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return errors_1.getLogger; } });
98
+ Object.defineProperty(exports, "silentLogger", { enumerable: true, get: function () { return errors_1.silentLogger; } });
99
+ Object.defineProperty(exports, "defaultLogger", { enumerable: true, get: function () { return errors_1.defaultLogger; } });
100
+ var utils_2 = require("./utils");
101
+ Object.defineProperty(exports, "Mutex", { enumerable: true, get: function () { return utils_2.Mutex; } });
102
+ Object.defineProperty(exports, "FileLock", { enumerable: true, get: function () { return utils_2.FileLock; } });
103
+ Object.defineProperty(exports, "processInBatches", { enumerable: true, get: function () { return utils_2.processInBatches; } });
104
+ Object.defineProperty(exports, "debounce", { enumerable: true, get: function () { return utils_2.debounce; } });
105
+ Object.defineProperty(exports, "throttle", { enumerable: true, get: function () { return utils_2.throttle; } });
106
+ Object.defineProperty(exports, "MemoryMonitor", { enumerable: true, get: function () { return utils_2.MemoryMonitor; } });
107
+ var sync_2 = require("./sync");
108
+ Object.defineProperty(exports, "FileWatcher", { enumerable: true, get: function () { return sync_2.FileWatcher; } });
109
+ Object.defineProperty(exports, "LockUnavailableError", { enumerable: true, get: function () { return sync_2.LockUnavailableError; } });
110
+ var mcp_1 = require("./mcp");
111
+ Object.defineProperty(exports, "MCPServer", { enumerable: true, get: function () { return mcp_1.MCPServer; } });
112
+ /**
113
+ * Main CodeGraph class
114
+ *
115
+ * Provides the primary interface for interacting with the code knowledge graph.
116
+ */
117
+ class CodeGraph {
118
+ db;
119
+ queries;
120
+ projectRoot;
121
+ // Assigned via wireLayers() from the constructor (and again on reopen) — the
122
+ // `!` tells TS these are definitely set even though the assignment is one
123
+ // method call away from the constructor body.
124
+ orchestrator;
125
+ resolver;
126
+ graphManager;
127
+ traverser;
128
+ contextBuilder;
129
+ // Mutex for preventing concurrent indexing operations (in-process)
130
+ indexMutex = new utils_1.Mutex();
131
+ // File lock for preventing concurrent writes across processes (CLI, MCP, git hooks)
132
+ fileLock;
133
+ // File watcher for auto-sync on file changes
134
+ watcher = null;
135
+ constructor(db, queries, projectRoot) {
136
+ this.db = db;
137
+ this.queries = queries;
138
+ this.projectRoot = projectRoot;
139
+ this.fileLock = new utils_1.FileLock(path.join((0, directory_2.getCodeGraphDir)(projectRoot), 'codegraph.lock'));
140
+ this.wireLayers();
141
+ }
142
+ /**
143
+ * (Re)build the query/extraction/graph layers over the current `this.queries`
144
+ * (which wraps `this.db`). Factored out of the constructor so `reopenIfReplaced`
145
+ * can rebuild them against a fresh connection without duplicating the wiring.
146
+ * The path-based `fileLock` is independent of the DB handle, so it stays put.
147
+ */
148
+ wireLayers() {
149
+ // Down-weight the project name as a query term in search ranking — it names
150
+ // the whole repo, not a symbol, so it has no discriminative value (#720).
151
+ try {
152
+ this.queries.setProjectNameTokens((0, query_utils_1.deriveProjectNameTokens)(this.projectRoot));
153
+ }
154
+ catch {
155
+ // Best-effort: ranking still works without it.
156
+ }
157
+ this.orchestrator = new extraction_1.ExtractionOrchestrator(this.projectRoot, this.queries);
158
+ this.resolver = (0, resolution_1.createResolver)(this.projectRoot, this.queries);
159
+ this.graphManager = new graph_1.GraphQueryManager(this.queries);
160
+ this.traverser = new graph_1.GraphTraverser(this.queries);
161
+ this.contextBuilder = (0, context_1.createContextBuilder)(this.projectRoot, this.queries, this.traverser);
162
+ }
163
+ /**
164
+ * Heal a stale database handle in place. If `.codegraph/` was removed and
165
+ * recreated at the SAME path while this instance held the DB open — a git
166
+ * worktree removed and re-added, or `rm -rf .codegraph` + `codegraph init` —
167
+ * our open fd points at the now-unlinked inode and can never see the new
168
+ * index, so every query returns the pre-removal snapshot until the process
169
+ * restarts (#925). When that's detected, open the live file at the same path,
170
+ * rebuild the query layers, and swap them IN PLACE, so every holder of this
171
+ * instance (the MCP daemon's default project, cached projectPath connections)
172
+ * heals without a restart. Returns true iff it reopened.
173
+ *
174
+ * POSIX-only in practice: `isReplacedOnDisk` never fires on Windows (an open
175
+ * file can't be unlinked there, and st_ino is unreliable).
176
+ */
177
+ reopenIfReplaced() {
178
+ if (!this.db.isReplacedOnDisk())
179
+ return false;
180
+ const dbPath = this.db.getPath();
181
+ // Open the live file FIRST — if that throws (e.g. mid-recreate), the old
182
+ // handle stays in place and the caller retries on the next query, rather
183
+ // than leaving this instance with no connection at all.
184
+ const fresh = db_1.DatabaseConnection.open(dbPath);
185
+ const stale = this.db;
186
+ this.db = fresh;
187
+ this.queries = new queries_1.QueryBuilder(fresh.getDb());
188
+ this.wireLayers();
189
+ // Releasing the dead handle also frees the leaked db/-wal/-shm fds that were
190
+ // pinning the unlinked inode (#925).
191
+ try {
192
+ stale.close();
193
+ }
194
+ catch { /* the old inode is gone; closing just frees fds */ }
195
+ return true;
196
+ }
197
+ // ===========================================================================
198
+ // Lifecycle Methods
199
+ // ===========================================================================
200
+ /**
201
+ * Initialize a new CodeGraph project
202
+ *
203
+ * Creates the .CodeGraph directory, database, and configuration.
204
+ *
205
+ * @param projectRoot - Path to the project root directory
206
+ * @param options - Initialization options
207
+ * @returns A new CodeGraph instance
208
+ */
209
+ static async init(projectRoot, options = {}) {
210
+ await (0, extraction_1.initGrammars)();
211
+ const resolvedRoot = path.resolve(projectRoot);
212
+ // Check if already initialized
213
+ if ((0, directory_1.isInitialized)(resolvedRoot)) {
214
+ throw new Error(`CodeGraph already initialized in ${resolvedRoot}`);
215
+ }
216
+ // Create directory structure
217
+ (0, directory_1.createDirectory)(resolvedRoot);
218
+ // Initialize database
219
+ const dbPath = (0, db_1.getDatabasePath)(resolvedRoot);
220
+ const db = db_1.DatabaseConnection.initialize(dbPath);
221
+ const queries = new queries_1.QueryBuilder(db.getDb());
222
+ const instance = new CodeGraph(db, queries, resolvedRoot);
223
+ // Run initial indexing if requested
224
+ if (options.index) {
225
+ await instance.indexAll({ onProgress: options.onProgress });
226
+ }
227
+ return instance;
228
+ }
229
+ /**
230
+ * Initialize synchronously (without indexing)
231
+ */
232
+ static initSync(projectRoot) {
233
+ const resolvedRoot = path.resolve(projectRoot);
234
+ // Check if already initialized
235
+ if ((0, directory_1.isInitialized)(resolvedRoot)) {
236
+ throw new Error(`CodeGraph already initialized in ${resolvedRoot}`);
237
+ }
238
+ // Create directory structure
239
+ (0, directory_1.createDirectory)(resolvedRoot);
240
+ // Initialize database
241
+ const dbPath = (0, db_1.getDatabasePath)(resolvedRoot);
242
+ const db = db_1.DatabaseConnection.initialize(dbPath);
243
+ const queries = new queries_1.QueryBuilder(db.getDb());
244
+ return new CodeGraph(db, queries, resolvedRoot);
245
+ }
246
+ /**
247
+ * Open an existing CodeGraph project
248
+ *
249
+ * @param projectRoot - Path to the project root directory
250
+ * @param options - Open options
251
+ * @returns A CodeGraph instance
252
+ */
253
+ static async open(projectRoot, options = {}) {
254
+ await (0, extraction_1.initGrammars)();
255
+ const resolvedRoot = path.resolve(projectRoot);
256
+ // Check if initialized
257
+ if (!(0, directory_1.isInitialized)(resolvedRoot)) {
258
+ throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
259
+ }
260
+ // Validate directory structure
261
+ const validation = (0, directory_1.validateDirectory)(resolvedRoot);
262
+ if (!validation.valid) {
263
+ throw new Error(`Invalid CodeGraph directory: ${validation.errors.join(', ')}`);
264
+ }
265
+ // Open database
266
+ const dbPath = (0, db_1.getDatabasePath)(resolvedRoot);
267
+ const db = db_1.DatabaseConnection.open(dbPath);
268
+ const queries = new queries_1.QueryBuilder(db.getDb());
269
+ const instance = new CodeGraph(db, queries, resolvedRoot);
270
+ // Sync if requested
271
+ if (options.sync) {
272
+ await instance.sync();
273
+ }
274
+ return instance;
275
+ }
276
+ /**
277
+ * Rebuild the project's database from scratch and return a fresh, empty
278
+ * instance — the "same result as a fresh init" semantics that `codegraph
279
+ * index` documents.
280
+ *
281
+ * Unlike `open()` followed by `clear()`, this DISCARDS the existing
282
+ * `.codegraph/codegraph.db` (and its `-wal`/`-shm` sidecars) before
283
+ * re-initializing, instead of opening the old database and DELETE-ing every
284
+ * row. On a large or pre-fix poisoned index — e.g. an old graph that scanned
285
+ * an ignored gitlink corpus (#1065) into ~1.6M nodes with a multi-GB WAL —
286
+ * the per-row `nodes_fts` delete-trigger churn blocks the main thread long
287
+ * enough to trip the #850 liveness watchdog before indexing even starts, so a
288
+ * full re-index could never recover the bad state (#1067). Discarding the
289
+ * files is O(1) regardless of size, reclaims the disk, and sidesteps opening
290
+ * (and running migrations against) the poisoned database entirely.
291
+ */
292
+ static async recreate(projectRoot) {
293
+ await (0, extraction_1.initGrammars)();
294
+ const resolvedRoot = path.resolve(projectRoot);
295
+ // Check if initialized — recreate REBUILDS an existing project; it is not a
296
+ // first-time `init`.
297
+ if (!(0, directory_1.isInitialized)(resolvedRoot)) {
298
+ throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
299
+ }
300
+ const dbPath = (0, db_1.getDatabasePath)(resolvedRoot);
301
+ try {
302
+ (0, db_1.removeDatabaseFiles)(dbPath);
303
+ }
304
+ catch (err) {
305
+ // POSIX unlinks an open file fine; this fires mainly on Windows when a
306
+ // live daemon/MCP server still holds the database. Turn the raw EBUSY into
307
+ // an actionable instruction instead of a generic failure.
308
+ const reason = err instanceof Error ? err.message : String(err);
309
+ throw new Error(`Could not rebuild the index — the database file is in use (${reason}). ` +
310
+ `Stop any running CodeGraph MCP server/daemon for this project and retry, ` +
311
+ `or remove the ${(0, directory_2.getCodeGraphDir)(resolvedRoot)} directory and run "codegraph init".`);
312
+ }
313
+ // Re-create an empty, freshly-schema'd database at the same path.
314
+ const db = db_1.DatabaseConnection.initialize(dbPath);
315
+ const queries = new queries_1.QueryBuilder(db.getDb());
316
+ return new CodeGraph(db, queries, resolvedRoot);
317
+ }
318
+ /**
319
+ * Open synchronously (without sync)
320
+ */
321
+ static openSync(projectRoot) {
322
+ const resolvedRoot = path.resolve(projectRoot);
323
+ // Check if initialized
324
+ if (!(0, directory_1.isInitialized)(resolvedRoot)) {
325
+ throw new Error(`CodeGraph not initialized in ${resolvedRoot}. Run init() first.`);
326
+ }
327
+ // Validate directory structure
328
+ const validation = (0, directory_1.validateDirectory)(resolvedRoot);
329
+ if (!validation.valid) {
330
+ throw new Error(`Invalid CodeGraph directory: ${validation.errors.join(', ')}`);
331
+ }
332
+ // Open database
333
+ const dbPath = (0, db_1.getDatabasePath)(resolvedRoot);
334
+ const db = db_1.DatabaseConnection.open(dbPath);
335
+ const queries = new queries_1.QueryBuilder(db.getDb());
336
+ return new CodeGraph(db, queries, resolvedRoot);
337
+ }
338
+ /**
339
+ * Check if a directory has been initialized as a CodeGraph project
340
+ */
341
+ static isInitialized(projectRoot) {
342
+ return (0, directory_1.isInitialized)(path.resolve(projectRoot));
343
+ }
344
+ /**
345
+ * Close the CodeGraph instance and release resources
346
+ */
347
+ close() {
348
+ this.unwatch();
349
+ // Release file lock if held
350
+ this.fileLock.release();
351
+ this.db.close();
352
+ }
353
+ /**
354
+ * Get the project root directory
355
+ */
356
+ getProjectRoot() {
357
+ return this.projectRoot;
358
+ }
359
+ // ===========================================================================
360
+ // Indexing
361
+ // ===========================================================================
362
+ /**
363
+ * Index all files in the project
364
+ *
365
+ * Uses a mutex to prevent concurrent indexing operations.
366
+ */
367
+ async indexAll(options = {}) {
368
+ return this.indexMutex.withLock(async () => {
369
+ try {
370
+ this.fileLock.acquire();
371
+ }
372
+ catch {
373
+ 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 };
374
+ }
375
+ // Defer WAL auto-checkpointing for the whole bulk run (#1231): the
376
+ // default 1000-page interval re-writes hot pages into the main DB file
377
+ // over and over — ~95% of all disk I/O during a bulk index, and a
378
+ // 19+min → 45s difference on HDD-class storage. The valve bounds WAL
379
+ // growth by backfilling PASSIVEly on a worker thread (never blocking
380
+ // the writer or the #850 watchdog heartbeat); runMaintenance below does
381
+ // the final fold-up before the interval is restored in the finally.
382
+ // Kill switch: CODEGRAPH_NO_WAL_DEFER=1. Non-WAL journal modes (some
383
+ // network filesystems) have no WAL to defer — skip.
384
+ // Fast-init: on a COMPLETELY fresh DB, trade crash-durability for speed
385
+ // during the bulk build (journal in memory, no fsync). Safe because the
386
+ // DB is disposable until the index completes — index_state stays
387
+ // 'indexing' and a crashed init is re-run from scratch; existing DBs
388
+ // (re-index/sync) never take this path. Kill switch:
389
+ // CODEGRAPH_NO_FAST_INIT=1 (same pattern as CODEGRAPH_NO_WAL_DEFER).
390
+ const freshDb = this.queries.getNodeAndEdgeCount().nodes === 0;
391
+ const fastInit = process.env.CODEGRAPH_NO_FAST_INIT !== '1' && freshDb;
392
+ if (fastInit) {
393
+ try {
394
+ this.db.getDb().pragma('journal_mode = MEMORY');
395
+ this.db.getDb().pragma('synchronous = OFF');
396
+ }
397
+ catch { /* keep WAL */ }
398
+ }
399
+ const deferWal = !fastInit && process.env.CODEGRAPH_NO_WAL_DEFER !== '1' && this.db.getJournalMode() === 'wal';
400
+ let walValve = null;
401
+ let priorAutocheckpoint = 1000;
402
+ // Set when the fastInit+pool path below defers autocheckpointing, so the
403
+ // finally knows to restore the interval on that path too.
404
+ let restoreAutocheckpoint = false;
405
+ if (deferWal) {
406
+ priorAutocheckpoint = this.db.getWalAutocheckpoint();
407
+ this.db.setWalAutocheckpoint(0);
408
+ walValve = new wal_valve_1.WalCheckpointValve(this.db, (0, wal_valve_1.resolveWalValveMb)(process.env.CODEGRAPH_WAL_VALVE_MB, this.db.getDbFileSizeBytes()), undefined, options.verbose ? (m) => console.log(`[wal-valve] ${m}`) : undefined);
409
+ walValve.start();
410
+ }
411
+ try {
412
+ const before = this.queries.getNodeAndEdgeCount();
413
+ // Mark the index as in-flight BEFORE any writes: a run killed
414
+ // mid-index (OOM, SIGKILL, the #850 liveness watchdog) leaves this
415
+ // marker behind, so `codegraph status` can tell a truncated index
416
+ // from a completed one instead of silently serving partial results.
417
+ try {
418
+ this.queries.setMetadata('index_state', 'indexing');
419
+ }
420
+ catch { /* metadata is advisory */ }
421
+ // Segment vocabulary starts empty and is repopulated by the node write
422
+ // path as every file (re-)indexes below — so a full index is also the
423
+ // orphan-cleanup pass for names deleted since the last one.
424
+ try {
425
+ this.queries.clearNameSegmentVocab();
426
+ }
427
+ catch { /* vocab is advisory — never fail an index over it */ }
428
+ // Bulk FTS mode for the mass-insert phase: drop the per-row FTS sync
429
+ // triggers, rebuild nodes_fts once from the nodes table afterwards.
430
+ // Crash inside the window is healed on the next DatabaseConnection.open.
431
+ this.db.beginBulkNodeLoad();
432
+ // Fresh-init only: also drop the parse-lane secondary indexes for the
433
+ // mass insert (the store-writer's B-tree-maintenance floor, plan §4d)
434
+ // and rebuild each in one scan afterwards. Incremental runs keep them
435
+ // — they delete per-file rows mid-phase through the file_path indexes.
436
+ if (freshDb)
437
+ this.db.beginBulkParseLoad();
438
+ let result;
439
+ try {
440
+ result = await this.orchestrator.indexAll(options.onProgress, options.signal, options.verbose, walValve ? () => walValve.backpressure() : undefined,
441
+ // Store-writer offload is fresh-DB-only: with any pre-existing
442
+ // data the store path must read (existing-file checks, cross-file
443
+ // edge snapshots) and delete, which belongs on one thread.
444
+ freshDb ? { dbPath: this.db.getPath(), fastInit } : null);
445
+ }
446
+ finally {
447
+ if (freshDb) {
448
+ const tIdx = Date.now();
449
+ await this.db.endBulkParseLoad();
450
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
451
+ console.error(`[phase-timing] parse-index-rebuild: ${Date.now() - tIdx}ms`);
452
+ }
453
+ const tFts = Date.now();
454
+ this.db.endBulkNodeLoad();
455
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
456
+ console.error(`[phase-timing] fts-rebuild: ${Date.now() - tFts}ms`);
457
+ }
458
+ // Fold the parse phase's WAL BEFORE the first post-parse reads
459
+ // (resolver re-init and resolution both read on the main thread):
460
+ // paging a bulk-write-sized WAL there is what blew the #850
461
+ // watchdog's 60s window in the #1231 repro. Off-thread + awaited,
462
+ // so the event loop keeps turning.
463
+ if (walValve)
464
+ await walValve.foldNow();
465
+ // Re-detect frameworks now that the index is populated. The resolver
466
+ // is constructed with createResolver() before any files exist, so
467
+ // framework resolvers whose detect() consults the indexed file list
468
+ // (e.g. UIKit/SwiftUI scanning for imports, swift-objc-bridge looking
469
+ // for both Swift and ObjC files) all return false on that initial pass
470
+ // and silently drop themselves. Re-initializing here gives them a
471
+ // chance to see the actual project before resolution runs.
472
+ if (result.success && result.filesIndexed > 0) {
473
+ const tReinit = Date.now();
474
+ this.resolver.initialize();
475
+ // Cross-file finalization (e.g. NestJS RouterModule prefixes). Runs
476
+ // before resolution so updated names show up in subsequent reads.
477
+ this.resolver.runPostExtract();
478
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
479
+ console.error(`[phase-timing] resolver-reinit: ${Date.now() - tReinit}ms`);
480
+ }
481
+ // Resolve references to create call/import/extends edges
482
+ if (result.success && result.filesIndexed > 0) {
483
+ // Get count without loading all refs into memory
484
+ const unresolvedCount = this.queries.getUnresolvedReferencesCount();
485
+ // Fast-init leaves the DB in memory-journal (rollback) mode, where
486
+ // the parallel resolver pool's read connections would contend with
487
+ // the main writer's exclusive commits. When the pool will actually
488
+ // run (enough pending refs), restore WAL BEFORE resolution so
489
+ // readers never block the writer; otherwise stay in the fast mode
490
+ // until the finally — sequential resolution has no readers.
491
+ if (fastInit && unresolvedCount >= (0, resolver_pool_1.minRefsForPool)()) {
492
+ try {
493
+ this.db.getDb().pragma('synchronous = NORMAL');
494
+ this.db.getDb().pragma('journal_mode = WAL');
495
+ // Defer auto-checkpointing for the resolution phase, same
496
+ // rationale as the deferWal path above: at the default 1000-page
497
+ // interval, the persist loop's edge inserts + ref deletes make
498
+ // SQLite re-write hot B-tree pages into the main DB file inline
499
+ // on the writer over and over (#1231's pathology — measured as
500
+ // ~58% of the resolution phase on a 255k-ref repo). The valve
501
+ // bounds WAL growth off-thread; runMaintenance does the final
502
+ // fold and the finally restores the interval.
503
+ priorAutocheckpoint = this.db.getWalAutocheckpoint();
504
+ this.db.setWalAutocheckpoint(0);
505
+ restoreAutocheckpoint = true;
506
+ walValve = new wal_valve_1.WalCheckpointValve(this.db, undefined, undefined, options.verbose ? (m) => console.log(`[wal-valve] ${m}`) : undefined);
507
+ walValve.start();
508
+ }
509
+ catch { /* keep current mode; resolution still works sequentially */ }
510
+ }
511
+ options.onProgress?.({
512
+ phase: 'resolving',
513
+ current: 0,
514
+ total: unresolvedCount,
515
+ });
516
+ const tResolve = Date.now();
517
+ await this.resolveReferencesBatched((current, total) => {
518
+ options.onProgress?.({
519
+ phase: 'resolving',
520
+ current,
521
+ total,
522
+ });
523
+ }, (done, totalPasses) => {
524
+ options.onProgress?.({
525
+ phase: 'linking',
526
+ current: done,
527
+ total: totalPasses,
528
+ });
529
+ }, walValve ? () => walValve.backpressure() : undefined);
530
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
531
+ console.error(`[phase-timing] resolution: ${Date.now() - tResolve}ms`);
532
+ // Second pass: chained calls whose method lives on a supertype the
533
+ // receiver conforms to (protocol-extension / inherited / default-
534
+ // interface). Needs the implements/extends edges the main pass just
535
+ // built, so it runs after resolution (#750).
536
+ const tChained = Date.now();
537
+ await this.resolver.resolveChainedCallsViaConformance();
538
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
539
+ console.error(`[synth-timing] chainedConformance: ${Date.now() - tChained}ms`);
540
+ // Same lifecycle for `this.<member>` callback registrations whose
541
+ // member is inherited from a supertype (#808).
542
+ const tDeferred = Date.now();
543
+ await this.resolver.resolveDeferredThisMemberRefs();
544
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
545
+ console.error(`[synth-timing] deferredThisMember: ${Date.now() - tDeferred}ms`);
546
+ }
547
+ // Refresh planner stats + checkpoint the WAL after bulk writes.
548
+ // Off-thread (worker connection): on a multi-GB index this is minutes
549
+ // of IO, and inline it starved the #850 watchdog AFTER a fully
550
+ // successful index. Never load-bearing for correctness.
551
+ if (result.success && result.filesIndexed > 0) {
552
+ const tMaint = Date.now();
553
+ // Quiesce the valve first so its in-flight checkpoint and the
554
+ // maintenance checkpoint don't contend for the checkpointer lock
555
+ // (the loser would silently no-op and leave the WAL unfolded).
556
+ if (walValve) {
557
+ walValve.stop();
558
+ await walValve.drain();
559
+ }
560
+ await this.db.runMaintenance();
561
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
562
+ console.error(`[phase-timing] maintenance: ${Date.now() - tMaint}ms`);
563
+ }
564
+ // The orchestrator only sees extraction-phase counts; resolution and
565
+ // synthesizer edges (often >50% of the graph on JVM repos) come later.
566
+ // Recompute against the DB so the CLI summary reports the true totals.
567
+ if (result.success && result.filesIndexed > 0) {
568
+ const tCount = Date.now();
569
+ const after = this.queries.getNodeAndEdgeCount();
570
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
571
+ console.error(`[phase-timing] count-recompute: ${Date.now() - tCount}ms`);
572
+ result.nodesCreated = after.nodes - before.nodes;
573
+ result.edgesCreated = after.edges - before.edges;
574
+ }
575
+ // Stamp the index with the engine that built it, so `codegraph status`
576
+ // and `codegraph upgrade` can recommend a re-index when the running
577
+ // engine produces richer extraction than the one on disk. Only on a
578
+ // real full index — a sync touches a subset, so it must NOT advance the
579
+ // extraction stamp (the bulk would still be stale). See extraction-version.ts.
580
+ if (result.success && result.filesIndexed > 0) {
581
+ try {
582
+ this.queries.setMetadata('indexed_with_version', version_1.CodeGraphPackageVersion);
583
+ this.queries.setMetadata('indexed_with_extraction_version', String(extraction_version_1.EXTRACTION_VERSION));
584
+ }
585
+ catch { /* metadata is advisory — never fail an index over it */ }
586
+ }
587
+ // Reconcile the scan's ground truth against what the pipeline
588
+ // accounted for. A shortfall means files were silently dropped
589
+ // (observed in the wild: a run under heavy load came up 37 files
590
+ // short with no error) — record it and tell the user, don't let the
591
+ // index pass as complete.
592
+ try {
593
+ if (!result.success) {
594
+ this.queries.setMetadata('index_state', 'failed');
595
+ }
596
+ else {
597
+ const accounted = result.filesIndexed + result.filesSkipped + result.filesErrored;
598
+ const discovered = result.filesDiscovered;
599
+ const shortfall = discovered !== undefined ? discovered - accounted : 0;
600
+ if (discovered !== undefined && shortfall > 0) {
601
+ this.queries.setMetadata('index_state', 'partial');
602
+ this.queries.setMetadata('index_files_discovered', String(discovered));
603
+ this.queries.setMetadata('index_files_accounted', String(accounted));
604
+ result.errors.push({
605
+ message: `Index is missing ${shortfall} of ${discovered} discovered files (indexed ${result.filesIndexed}, skipped ${result.filesSkipped}, errored ${result.filesErrored}). The index is PARTIAL — re-run \`codegraph index\`.`,
606
+ severity: 'warning',
607
+ code: 'index_partial',
608
+ });
609
+ }
610
+ else {
611
+ this.queries.setMetadata('index_state', 'complete');
612
+ if (discovered !== undefined) {
613
+ this.queries.setMetadata('index_files_discovered', String(discovered));
614
+ this.queries.setMetadata('index_files_accounted', String(accounted));
615
+ }
616
+ }
617
+ }
618
+ }
619
+ catch { /* metadata is advisory — never fail an index over it */ }
620
+ return result;
621
+ }
622
+ finally {
623
+ // Restore the auto-checkpoint interval AFTER the fold-up above so the
624
+ // next ordinary write doesn't inherit a giant inline checkpoint. On
625
+ // the error path the WAL may still be large; correctness is unchanged
626
+ // (SQLite replays the WAL on the next open) and the follow-up write
627
+ // that folds it is the known cost of a failed run.
628
+ if (walValve) {
629
+ walValve.stop();
630
+ await walValve.drain();
631
+ }
632
+ if (deferWal || restoreAutocheckpoint) {
633
+ try {
634
+ this.db.setWalAutocheckpoint(priorAutocheckpoint);
635
+ }
636
+ catch { /* connection may be closing */ }
637
+ }
638
+ if (fastInit) {
639
+ // Back to the durable defaults; journal_mode=WAL folds the MEMORY
640
+ // journal state into a normal WAL-mode database file.
641
+ try {
642
+ this.db.getDb().pragma('synchronous = NORMAL');
643
+ this.db.getDb().pragma('journal_mode = WAL');
644
+ }
645
+ catch { /* connection may be closing */ }
646
+ }
647
+ this.fileLock.release();
648
+ }
649
+ });
650
+ }
651
+ /**
652
+ * Index specific files
653
+ *
654
+ * Uses a mutex to prevent concurrent indexing operations.
655
+ */
656
+ async indexFiles(filePaths) {
657
+ return this.indexMutex.withLock(async () => {
658
+ try {
659
+ this.fileLock.acquire();
660
+ }
661
+ catch {
662
+ 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 };
663
+ }
664
+ try {
665
+ return this.orchestrator.indexFiles(filePaths);
666
+ }
667
+ finally {
668
+ this.fileLock.release();
669
+ }
670
+ });
671
+ }
672
+ /**
673
+ * Sync with current file state (incremental update)
674
+ *
675
+ * Uses a mutex to prevent concurrent indexing operations.
676
+ */
677
+ async sync(options = {}) {
678
+ return this.indexMutex.withLock(async () => {
679
+ try {
680
+ this.fileLock.acquire();
681
+ }
682
+ catch {
683
+ return { filesChecked: 0, filesAdded: 0, filesModified: 0, filesRemoved: 0, nodesUpdated: 0, durationMs: 0 };
684
+ }
685
+ // Defer WAL auto-checkpointing for the whole incremental run, exactly
686
+ // as indexAll does for the bulk path (#1231): sync's store loop and its
687
+ // resolution passes churn the same FTS + secondary-index hot pages, and
688
+ // at the default 1000-page cadence the inline checkpoints re-write them
689
+ // over and over — on HDD-class storage a 7-file sync took 2 minutes at
690
+ // 0-2% CPU (#1248). The cost scales with the EXISTING database size,
691
+ // not the change size, so small syncs on big indexes hurt most. The
692
+ // valve bounds WAL growth off-thread; runMaintenance at the end does
693
+ // the final fold-up before the interval is restored in the finally.
694
+ // Same kill switch as indexAll: CODEGRAPH_NO_WAL_DEFER=1. Idle valve
695
+ // cost is one timer, so watcher-frequency syncs stay cheap.
696
+ const deferWal = process.env.CODEGRAPH_NO_WAL_DEFER !== '1' && this.db.getJournalMode() === 'wal';
697
+ let walValve = null;
698
+ let priorAutocheckpoint = 1000;
699
+ if (deferWal) {
700
+ priorAutocheckpoint = this.db.getWalAutocheckpoint();
701
+ this.db.setWalAutocheckpoint(0);
702
+ walValve = new wal_valve_1.WalCheckpointValve(this.db, (0, wal_valve_1.resolveWalValveMb)(process.env.CODEGRAPH_WAL_VALVE_MB, this.db.getDbFileSizeBytes()), undefined, options.verbose ? (m) => console.log(`[wal-valve] ${m}`) : undefined);
703
+ walValve.start();
704
+ }
705
+ try {
706
+ // Captured BEFORE the sync runs: the sync's own incremental writes
707
+ // populate vocab rows for the files it touches, so an end-of-sync
708
+ // emptiness check would see "non-empty" and skip the backfill forever,
709
+ // leaving every unchanged file's names unsegmented.
710
+ const vocabWasEmpty = (() => {
711
+ try {
712
+ return this.queries.isNameSegmentVocabEmpty();
713
+ }
714
+ catch {
715
+ return false;
716
+ }
717
+ })();
718
+ const result = await this.orchestrator.sync(options.onProgress, options.paths);
719
+ // Fold the store phase's WAL BEFORE the post-store reads below
720
+ // (resolution reads on the main thread) — same rationale as
721
+ // indexAll's fold between store and resolution.
722
+ if (walValve)
723
+ await walValve.foldNow();
724
+ // Cross-file finalization (e.g. NestJS RouterModule prefixes). Run on
725
+ // every sync that touched files so edits to `app.module.ts` propagate
726
+ // to controllers in unchanged files. The pass is idempotent and cheap
727
+ // (regex over *.module.ts only).
728
+ if (result.filesAdded > 0 || result.filesModified > 0) {
729
+ this.resolver.runPostExtract();
730
+ }
731
+ else if (result.filesRemoved > 0) {
732
+ // A pure-removal sync still resolves refs below — the deletion path
733
+ // resurrects the removed file's incoming edges as pending refs
734
+ // (#1240 removal case) and the orphan sweep consumes them. In a
735
+ // long-lived process (daemon) the resolver's name caches were
736
+ // warmed against the pre-removal graph; drop them so resolution
737
+ // sees the post-removal state. (runPostExtract above clears caches
738
+ // itself, so the changed-files branch is already covered.)
739
+ this.resolver.clearCaches();
740
+ }
741
+ // Resolve references if files were updated
742
+ const filesChanged = result.filesAdded > 0 || result.filesModified > 0;
743
+ if (filesChanged) {
744
+ if (result.changedFilePaths) {
745
+ // Scope resolution to changed files (git fast path — bounded set)
746
+ const tRefLoad = Date.now();
747
+ const unresolvedRefs = this.queries.getUnresolvedReferencesByFiles(result.changedFilePaths);
748
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
749
+ console.error(`[phase-timing] sync-ref-load: ${Date.now() - tRefLoad}ms (${unresolvedRefs.length} refs)`);
750
+ options.onProgress?.({
751
+ phase: 'resolving',
752
+ current: 0,
753
+ total: unresolvedRefs.length,
754
+ });
755
+ this.resolver.resolveAndPersist(unresolvedRefs, (current, total) => {
756
+ options.onProgress?.({
757
+ phase: 'resolving',
758
+ current,
759
+ total,
760
+ });
761
+ });
762
+ // Retry previously-failed refs the changed files may now satisfy
763
+ // (#1240). Scoped resolution above only re-resolves refs FROM the
764
+ // changed files — but when a changed file gains an export/symbol,
765
+ // refs in UNCHANGED files that failed against the old graph can
766
+ // now resolve, and nothing else ever revisits them (their rows
767
+ // were parked as status='failed' by an earlier completed pass).
768
+ // Look them up by the symbol names the changed files now carry
769
+ // and re-resolve just that set. On a sync where no failed ref
770
+ // matches, this is one indexed lookup.
771
+ const tRetry = Date.now();
772
+ const retryable = this.queries.getRetryableFailedReferences(this.queries.getNodeNamesByFiles(result.changedFilePaths));
773
+ if (retryable.length > 0) {
774
+ options.onProgress?.({
775
+ phase: 'resolving',
776
+ current: 0,
777
+ total: retryable.length,
778
+ });
779
+ await this.resolver.resolveAndPersistListYielding(retryable);
780
+ options.onProgress?.({
781
+ phase: 'resolving',
782
+ current: retryable.length,
783
+ total: retryable.length,
784
+ });
785
+ }
786
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS)
787
+ console.error(`[phase-timing] sync-failed-ref-retry: ${Date.now() - tRetry}ms (${retryable.length} refs)`);
788
+ }
789
+ else {
790
+ // No git info — use batched resolution to avoid OOM
791
+ const unresolvedCount = this.queries.getUnresolvedReferencesCount();
792
+ options.onProgress?.({
793
+ phase: 'resolving',
794
+ current: 0,
795
+ total: unresolvedCount,
796
+ });
797
+ await this.resolveReferencesBatched((current, total) => {
798
+ options.onProgress?.({
799
+ phase: 'resolving',
800
+ current,
801
+ total,
802
+ });
803
+ }, (done, totalPasses) => {
804
+ options.onProgress?.({
805
+ phase: 'linking',
806
+ current: done,
807
+ total: totalPasses,
808
+ });
809
+ });
810
+ }
811
+ }
812
+ // Re-open resolution edges this sync may have invalidated ELSEWHERE in
813
+ // the repo (CG-33). Everything above re-resolves references in the
814
+ // changed files; this covers the opposite direction — references in
815
+ // files the sync never touched whose answer depended on a definition
816
+ // that just appeared or disappeared. Without it a synced index never
817
+ // converges to a full rebuild: measured at 4.3% of distinct edges wrong
818
+ // on codegraph's own index, in both directions, mostly `calls`. The
819
+ // resurrected refs are pending rows, so the orphan sweep immediately
820
+ // below is what resolves them — batched, yielding, multi-pass, exactly
821
+ // as a full index resolves.
822
+ //
823
+ // `definitionDelta` is empty for a body-only edit, so the overwhelmingly
824
+ // common sync pays one branch. CODEGRAPH_NO_REBIND=1 disables it.
825
+ if (result.definitionDelta && process.env.CODEGRAPH_NO_REBIND !== '1') {
826
+ const tRebind = Date.now();
827
+ const rebound = this.orchestrator.resurrectStaleResolutionEdges(result.definitionDelta, result.changedFilePaths ?? []);
828
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS) {
829
+ console.error(`[phase-timing] sync-rebind: ${Date.now() - tRebind}ms (${result.definitionDelta.length} changed names, ${rebound} edges re-opened)`);
830
+ }
831
+ }
832
+ // Orphan sweep (#1187). A resolution pass that dies mid-run — the #850
833
+ // daemon liveness watchdog's SIGKILL (#1122), Ctrl-C, a crash — leaves
834
+ // the refs it never reached in unresolved_refs, and the git-scoped fast
835
+ // path above never revisits them (it reads only the changed files'
836
+ // rows). Those files' call edges were then missing PERMANENTLY, with
837
+ // nothing to see except a too-small blast radius, until a full
838
+ // re-index. A completed pass takes every row it processed out of the
839
+ // PENDING set (resolved rows are deleted, unresolvable ones parked as
840
+ // status='failed' for the #1240 retry above), so any pending row now
841
+ // is such an orphan — or a row from an older engine's scoped pass.
842
+ // Grind them down with the batched resolver; this also makes a bare
843
+ // `codegraph sync` the recovery command for a wedged index. On a
844
+ // healthy index this is one COUNT query.
845
+ const orphanCount = this.queries.getUnresolvedReferencesCount();
846
+ if (orphanCount > 0) {
847
+ options.onProgress?.({
848
+ phase: 'resolving',
849
+ current: 0,
850
+ total: orphanCount,
851
+ });
852
+ await this.resolveReferencesBatched((current, total) => {
853
+ options.onProgress?.({
854
+ phase: 'resolving',
855
+ current,
856
+ total,
857
+ });
858
+ }, (done, totalPasses) => {
859
+ options.onProgress?.({
860
+ phase: 'linking',
861
+ current: done,
862
+ total: totalPasses,
863
+ });
864
+ });
865
+ }
866
+ if (filesChanged || orphanCount > 0) {
867
+ // Second pass: chained calls whose method lives on a supertype the
868
+ // receiver conforms to (protocol-extension / inherited). Needs the
869
+ // implements/extends edges built above (#750).
870
+ await this.resolver.resolveChainedCallsViaConformance();
871
+ // Same lifecycle for `this.<member>` callback registrations whose
872
+ // member is inherited from a supertype (#808).
873
+ await this.resolver.resolveDeferredThisMemberRefs();
874
+ }
875
+ // Refresh planner stats + checkpoint the WAL after bulk writes.
876
+ // Off-thread — see indexAll's call site.
877
+ if (filesChanged || result.filesRemoved > 0 || orphanCount > 0) {
878
+ await this.db.runMaintenance();
879
+ }
880
+ // Heal the segment vocabulary on indexes built before the table
881
+ // existed (upgrade path): incremental writes above only cover changed
882
+ // files, so a vocab that was empty when this sync STARTED means the
883
+ // bulk was never segmented — backfill it (INSERT OR IGNORE, so the
884
+ // rows the sync just wrote are fine). Batched + yielding — sync can
885
+ // run on the daemon's liveness-watchdog thread (#850/#1091).
886
+ try {
887
+ if (vocabWasEmpty && this.queries.getNodeAndEdgeCount().nodes > 0) {
888
+ await this.rebuildNameSegmentVocab();
889
+ }
890
+ }
891
+ catch { /* vocab is advisory — never fail a sync over it */ }
892
+ return result;
893
+ }
894
+ finally {
895
+ // Mirror indexAll's teardown: stop the valve, then restore the
896
+ // auto-checkpoint interval (runMaintenance above already folded the
897
+ // WAL on the success path; on the error path SQLite replays it on
898
+ // the next open).
899
+ if (walValve) {
900
+ walValve.stop();
901
+ await walValve.drain();
902
+ }
903
+ if (deferWal) {
904
+ try {
905
+ this.db.setWalAutocheckpoint(priorAutocheckpoint);
906
+ }
907
+ catch { /* connection may be closing */ }
908
+ }
909
+ this.fileLock.release();
910
+ }
911
+ });
912
+ }
913
+ /**
914
+ * Check if an indexing operation is currently in progress
915
+ */
916
+ isIndexing() {
917
+ return this.indexMutex.isLocked();
918
+ }
919
+ // ===========================================================================
920
+ // File Watching
921
+ // ===========================================================================
922
+ /**
923
+ * Start watching for file changes and auto-syncing.
924
+ *
925
+ * Uses native OS file events (FSEvents on macOS, inotify on Linux 19+,
926
+ * ReadDirectoryChangesW on Windows) with debouncing to avoid thrashing.
927
+ *
928
+ * @param options - Watch options (debounce delay, callbacks)
929
+ * @returns true if watching started successfully
930
+ */
931
+ watch(options = {}) {
932
+ if (this.watcher?.isActive())
933
+ return true;
934
+ this.watcher = new sync_1.FileWatcher(this.projectRoot, async (paths) => {
935
+ const result = await this.sync({ paths });
936
+ // sync() returns this exact zero-shape iff it failed to acquire the
937
+ // file lock (a real empty sync always has filesChecked > 0 because
938
+ // scanDirectory ran). Surface that to the watcher as a typed error
939
+ // so it keeps pendingFiles + reschedules instead of clearing them
940
+ // (#449).
941
+ if (result.filesChecked === 0 && result.durationMs === 0) {
942
+ throw new sync_1.LockUnavailableError();
943
+ }
944
+ const filesChanged = result.filesAdded + result.filesModified + result.filesRemoved;
945
+ return { filesChanged, durationMs: result.durationMs };
946
+ }, options);
947
+ return this.watcher.start();
948
+ }
949
+ /**
950
+ * Stop watching for file changes.
951
+ */
952
+ unwatch() {
953
+ if (this.watcher) {
954
+ this.watcher.stop();
955
+ this.watcher = null;
956
+ }
957
+ }
958
+ /**
959
+ * Check if the file watcher is active.
960
+ */
961
+ isWatching() {
962
+ return this.watcher?.isActive() ?? false;
963
+ }
964
+ /**
965
+ * True once live watching has permanently degraded (OS watch-resource
966
+ * exhaustion, or a write lock held past the retry budget) and auto-sync is
967
+ * disabled until the next {@link watch} call. Distinct from `!isWatching()`:
968
+ * a stopped/never-started watcher is inactive but NOT degraded. MCP tools use
969
+ * this to surface a whole-index "results may be stale" notice, since
970
+ * `getPendingFiles()` goes empty once watching stops (#876).
971
+ */
972
+ isWatcherDegraded() {
973
+ return this.watcher?.isDegraded() ?? false;
974
+ }
975
+ /** The reason live watching degraded, or null if it is healthy (#876). */
976
+ getWatcherDegradedReason() {
977
+ return this.watcher?.getDegradedReason() ?? null;
978
+ }
979
+ /**
980
+ * Files seen by the file watcher since the last successful sync —
981
+ * the per-file "stale" signal MCP tools attach to responses so an agent
982
+ * can fall back to {@link Read} for just the affected file without
983
+ * waiting for a debounced sync to complete (issue #403).
984
+ *
985
+ * Returns an empty list when the watcher isn't active, or no events have
986
+ * arrived. Each entry includes `firstSeenMs` and `lastSeenMs` (wall-clock
987
+ * `Date.now()` values) so callers can render "edited Nms ago", plus an
988
+ * `indexing` flag indicating whether the in-flight sync (if any) will
989
+ * absorb that file.
990
+ */
991
+ getPendingFiles() {
992
+ return this.watcher?.getPendingFiles() ?? [];
993
+ }
994
+ /**
995
+ * Resolves once the file watcher has installed its watch set. Useful for
996
+ * tests that need a deterministic boundary before asserting on
997
+ * `getPendingFiles()`. Resolves immediately when no watcher is active.
998
+ */
999
+ waitUntilWatcherReady(timeoutMs) {
1000
+ return this.watcher ? this.watcher.waitUntilReady(timeoutMs) : Promise.resolve();
1001
+ }
1002
+ /**
1003
+ * Get files that have changed since last index
1004
+ */
1005
+ getChangedFiles() {
1006
+ return this.orchestrator.getChangedFiles();
1007
+ }
1008
+ /**
1009
+ * Most recent index timestamp (ms since epoch) across all tracked files, or
1010
+ * null when nothing is indexed yet. Lets library consumers check index
1011
+ * freshness without shelling out to `codegraph status --json`. (#329)
1012
+ */
1013
+ getLastIndexedAt() {
1014
+ return this.queries.getLastIndexedAt();
1015
+ }
1016
+ /**
1017
+ * Completeness of the last full index run. `'complete'` is the only good
1018
+ * state. `'indexing'` after the fact means a run was killed mid-index (OOM,
1019
+ * SIGKILL, liveness watchdog) and the on-disk index is truncated;
1020
+ * `'partial'` means the run finished but silently dropped files
1021
+ * (discovered > indexed+skipped+errored); `'failed'` means it reported
1022
+ * failure. `null` = index predates this marker. Surfaced by
1023
+ * `codegraph status`.
1024
+ */
1025
+ getIndexState() {
1026
+ const raw = this.queries.getMetadata('index_state');
1027
+ return raw === 'indexing' || raw === 'complete' || raw === 'partial' || raw === 'failed'
1028
+ ? raw
1029
+ : null;
1030
+ }
1031
+ /**
1032
+ * Which engine built the current index: the package version + extraction
1033
+ * version stamped at the last full `indexAll`. Either field is null for an
1034
+ * index built before stamping existed (treated as stale). See
1035
+ * `extraction-version.ts` and `isIndexStale()`.
1036
+ */
1037
+ getIndexBuildInfo() {
1038
+ const version = this.queries.getMetadata('indexed_with_version');
1039
+ const ev = this.queries.getMetadata('indexed_with_extraction_version');
1040
+ const parsed = ev != null ? parseInt(ev, 10) : NaN;
1041
+ return { version, extractionVersion: Number.isFinite(parsed) ? parsed : null };
1042
+ }
1043
+ /**
1044
+ * True when the on-disk index was built by an engine whose extraction is
1045
+ * older than the one now running — i.e. a re-index would add data a migration
1046
+ * can't backfill. False when there's no index yet (nothing to refresh) or the
1047
+ * stamp is current. This is the signal behind `codegraph status`'s re-index
1048
+ * hint and `codegraph upgrade`'s reminder.
1049
+ */
1050
+ isIndexStale() {
1051
+ if (this.queries.getLastIndexedAt() == null)
1052
+ return false;
1053
+ const { extractionVersion } = this.getIndexBuildInfo();
1054
+ return extractionVersion == null || extractionVersion < extraction_version_1.EXTRACTION_VERSION;
1055
+ }
1056
+ /**
1057
+ * Extract nodes and edges from source code (without storing)
1058
+ */
1059
+ extractFromSource(filePath, source) {
1060
+ return (0, extraction_1.extractFromSource)(filePath, source);
1061
+ }
1062
+ // ===========================================================================
1063
+ // Reference Resolution
1064
+ // ===========================================================================
1065
+ /**
1066
+ * Resolve unresolved references and create edges
1067
+ *
1068
+ * This method takes unresolved references from extraction and attempts
1069
+ * to resolve them using multiple strategies:
1070
+ * - Framework-specific patterns (React, Express, Laravel)
1071
+ * - Import-based resolution
1072
+ * - Name-based symbol matching
1073
+ */
1074
+ resolveReferences(onProgress) {
1075
+ // Get all unresolved references from the database
1076
+ const unresolvedRefs = this.queries.getUnresolvedReferences();
1077
+ return this.resolver.resolveAndPersist(unresolvedRefs, onProgress);
1078
+ }
1079
+ /**
1080
+ * Resolve references in batches to keep memory bounded on large codebases.
1081
+ * Processes chunks of unresolved refs, persisting results after each batch.
1082
+ */
1083
+ async resolveReferencesBatched(onProgress, onSynthesisProgress,
1084
+ // The WAL valve's writer-side backstop, threaded into the batch loop's
1085
+ // pool-idle boundaries. Without it the valve's only lever during
1086
+ // resolution is timer-driven passive checkpoints, which the pool's
1087
+ // continuous reads keep perpetually partial — the WAL then accretes the
1088
+ // whole phase's write volume (22GB on a 4.6GB DB at kernel scale).
1089
+ backpressure) {
1090
+ return this.resolver.resolveAndPersistBatched(onProgress, undefined, onSynthesisProgress, {
1091
+ dbPath: this.db.getPath(),
1092
+ // Bulk-edge-load hooks: on big runs the resolver drops the non-unique
1093
+ // edge indexes for the batch loop and recreates them before synthesis
1094
+ // (which reads kind-keyed). Concurrent readers (a daemon serving this
1095
+ // project mid-index) stay CORRECT during the window — target/kind reads
1096
+ // just degrade to scans until the recreate.
1097
+ bulkEdgeLoad: {
1098
+ begin: () => this.db.beginBulkEdgeLoad(),
1099
+ end: () => this.db.endBulkEdgeLoad(),
1100
+ },
1101
+ refIndexLoad: {
1102
+ begin: () => this.db.beginBulkRefLoad(),
1103
+ end: () => this.db.endBulkRefLoad(),
1104
+ },
1105
+ backpressure,
1106
+ });
1107
+ }
1108
+ /**
1109
+ * References extracted but never attempted by a resolution pass. Zero on a
1110
+ * healthy index — a completed pass consumes every pending row (resolving it
1111
+ * or parking it as failed, #1240). Non-zero at rest means a pass was
1112
+ * interrupted mid-run (killed indexer, crash — #1187), so some files' call
1113
+ * edges are missing; the next `sync` sweeps them.
1114
+ */
1115
+ getPendingReferenceCount() {
1116
+ return this.queries.getUnresolvedReferencesCount();
1117
+ }
1118
+ /**
1119
+ * Get detected frameworks in the project
1120
+ */
1121
+ getDetectedFrameworks() {
1122
+ return this.resolver.getDetectedFrameworks();
1123
+ }
1124
+ /**
1125
+ * Re-initialize the resolver (useful after adding new files)
1126
+ */
1127
+ reinitializeResolver() {
1128
+ this.resolver.initialize();
1129
+ }
1130
+ // ===========================================================================
1131
+ // Graph Statistics
1132
+ // ===========================================================================
1133
+ /**
1134
+ * Get statistics about the knowledge graph
1135
+ */
1136
+ getStats() {
1137
+ const stats = this.queries.getStats();
1138
+ stats.dbSizeBytes = this.db.getSize();
1139
+ stats.walSizeBytes = this.db.getWalSizeBytes();
1140
+ return stats;
1141
+ }
1142
+ /**
1143
+ * Active SQLite backend for this project's connection (`node-sqlite` — Node's
1144
+ * built-in real-SQLite module). Surfaced via `codegraph status` and the
1145
+ * `codegraph_status` MCP tool alongside the effective journal mode.
1146
+ */
1147
+ getBackend() {
1148
+ return this.db.getBackend();
1149
+ }
1150
+ /**
1151
+ * The journal mode actually in effect ('wal', 'delete', …). 'wal' means
1152
+ * readers never block on a concurrent writer; anything else means they can,
1153
+ * which is the precondition for the "database is locked" failures in issue
1154
+ * #238. Surfaced via `codegraph status` and the `codegraph_status` MCP tool.
1155
+ */
1156
+ getJournalMode() {
1157
+ return this.db.getJournalMode();
1158
+ }
1159
+ // ===========================================================================
1160
+ // Node Operations
1161
+ // ===========================================================================
1162
+ /**
1163
+ * Get a node by ID
1164
+ */
1165
+ getNode(id) {
1166
+ return this.queries.getNodeById(id);
1167
+ }
1168
+ /**
1169
+ * Get all nodes in a file
1170
+ */
1171
+ getNodesInFile(filePath) {
1172
+ return this.queries.getNodesByFile(filePath);
1173
+ }
1174
+ /**
1175
+ * Get all nodes of a specific kind
1176
+ */
1177
+ getNodesByKind(kind) {
1178
+ return this.queries.getNodesByKind(kind);
1179
+ }
1180
+ /**
1181
+ * Get ALL nodes with an exact name (direct index lookup, not FTS-ranked/capped).
1182
+ * Used to enumerate every overload of a heavily-overloaded name so the specific
1183
+ * definition the caller wants is never dropped below a search cut.
1184
+ */
1185
+ getNodesByName(name) {
1186
+ return this.queries.getNodesByName(name);
1187
+ }
1188
+ /** Nodes whose name starts with `prefix` (index range scan, capped). */
1189
+ getNodesByNamePrefix(prefix, limit = 20) {
1190
+ return this.queries.getNodesByNamePrefix(prefix, limit);
1191
+ }
1192
+ /**
1193
+ * Nodes whose name CONTAINS `substring` (LIKE scan, ASCII-case-insensitive,
1194
+ * shortest-first). The camel-infix lookup FTS can't do — `profileInfo`
1195
+ * inside `getProfileInfoV2` is one FTS token (#1196).
1196
+ */
1197
+ getNodesByNameSubstring(substring, options = {}) {
1198
+ return this.queries
1199
+ .findNodesByNameSubstring(substring, options)
1200
+ .map((r) => r.node);
1201
+ }
1202
+ /**
1203
+ * Search nodes by text
1204
+ */
1205
+ searchNodes(query, options) {
1206
+ return this.queries.searchNodes(query, options);
1207
+ }
1208
+ /**
1209
+ * Graph-derived prompt matching for the front-load hook's MEDIUM tier:
1210
+ * which indexed symbols do these prose words name? "state machine des
1211
+ * commandes" → `OrderStateMachine`, in any human language whose technical
1212
+ * nouns are Latin script — no keyword list involved.
1213
+ *
1214
+ * Precision comes from the repo's own naming statistics, not vocabulary:
1215
+ * - CO-OCCURRENCE: ≥2 words that are segments of the SAME name ("state" +
1216
+ * "machine" → OrderStateMachine) is strong evidence and always qualifies.
1217
+ * - RARITY: a single matched word qualifies only when its segment is
1218
+ * discriminative here (≤ {@link SEGMENT_RARITY_CEILING} distinct names) —
1219
+ * "checkout" in a shop backend yes, "state" in a react app no.
1220
+ * Every candidate is re-verified against `nodes` before being returned
1221
+ * (vocab rows are proposals; deletions leave orphans by design), so a
1222
+ * returned symbol is guaranteed to exist right now.
1223
+ */
1224
+ getSegmentMatches(words, limit = 6) {
1225
+ if (words.length === 0)
1226
+ return [];
1227
+ // Variant → original word (plural folding), for coverage accounting.
1228
+ const variantToWord = new Map();
1229
+ for (const word of words) {
1230
+ for (const variant of (0, identifier_segments_1.segmentLookupVariants)(word)) {
1231
+ if (!variantToWord.has(variant))
1232
+ variantToWord.set(variant, word);
1233
+ }
1234
+ }
1235
+ const variants = [...variantToWord.keys()];
1236
+ // Tier A: co-occurrence. The SQL folds variants back to their original
1237
+ // word (#1146), so minWords=2 means two distinct PROMPT WORDS — a name
1238
+ // matching both `service` and `services` can't tie with (or crowd past
1239
+ // the LIMIT) a genuine two-word match. The JS re-check below recomputes
1240
+ // the fold from live segments as the honesty layer.
1241
+ const variantPairs = [...variantToWord.entries()].map(([segment, word]) => ({ segment, word }));
1242
+ const candidates = [];
1243
+ for (const hit of this.queries.getSegmentCoOccurrence(variantPairs, 2, 24)) {
1244
+ const matched = this.wordsMatchingName(hit.name, variantToWord);
1245
+ if (matched.size >= 2)
1246
+ candidates.push({ name: hit.name, matchedWords: matched });
1247
+ }
1248
+ // Tier B: single rare word. Only when co-occurrence found nothing — a
1249
+ // co-occurring name is categorically stronger evidence — and under
1250
+ // stricter rules, because one word is thin: the word must be ≥5 chars
1251
+ // (measured FPs: "this", "typo"); the segment must appear in AT LEAST TWO
1252
+ // names (a concept the codebase is about clusters across names —
1253
+ // CheckoutService/CheckoutController — while a prose coincidence is a
1254
+ // singleton: measured FP "deploy to PRODUCTION" → the one name
1255
+ // matchesNonProductionDir); and the candidate name must have ≥2 segments
1256
+ // (a bare common verb matching a bare function name — "write" → `write` —
1257
+ // is prose coincidence, not the user naming a symbol).
1258
+ if (candidates.length === 0) {
1259
+ const singleWordVariants = variants.filter((v) => variantToWord.get(v).length >= 5);
1260
+ const counts = this.queries.getSegmentNameCounts(singleWordVariants);
1261
+ const rare = [...counts.entries()]
1262
+ .filter(([, n]) => n >= 2 && n <= CodeGraph.SEGMENT_RARITY_CEILING)
1263
+ .sort((a, b) => a[1] - b[1])
1264
+ .slice(0, 2);
1265
+ for (const [variant] of rare) {
1266
+ const word = variantToWord.get(variant);
1267
+ for (const name of this.queries.getNamesForSegment(variant, 12)) {
1268
+ if ((0, identifier_segments_1.splitIdentifierSegments)(name).length < 2)
1269
+ continue;
1270
+ candidates.push({ name, matchedWords: new Set([word]) });
1271
+ }
1272
+ }
1273
+ }
1274
+ // Verify against nodes (the honesty gate) and pick a representative
1275
+ // definition per name. A name whose only nodes are file/import kind has
1276
+ // no real definition to point at — surfacing the import statement instead
1277
+ // reads as a matched symbol but isn't one (#1144) — so it's skipped, the
1278
+ // same way an orphaned vocab row is. (Import names no longer enter the
1279
+ // vocab at write time, but rows written before that exclusion persist
1280
+ // until the next full index.)
1281
+ const out = [];
1282
+ const seen = new Set();
1283
+ candidates.sort((a, b) => b.matchedWords.size - a.matchedWords.size || a.name.length - b.name.length);
1284
+ for (const candidate of candidates) {
1285
+ if (out.length >= limit)
1286
+ break;
1287
+ if (seen.has(candidate.name))
1288
+ continue;
1289
+ seen.add(candidate.name);
1290
+ const nodes = this.queries.getNodesByName(candidate.name);
1291
+ if (nodes.length === 0)
1292
+ continue; // orphaned vocab row — name no longer exists
1293
+ const rep = nodes.find((n) => n.kind !== 'file' && n.kind !== 'import');
1294
+ if (!rep)
1295
+ continue; // no real definition — don't surface an import/file as one
1296
+ out.push({
1297
+ name: candidate.name,
1298
+ kind: rep.kind,
1299
+ filePath: rep.filePath,
1300
+ startLine: rep.startLine ?? 0,
1301
+ matchedWords: [...candidate.matchedWords].sort(),
1302
+ });
1303
+ }
1304
+ return out;
1305
+ }
1306
+ /** A single word ("state") can match hundreds of names in a big repo — that
1307
+ * is noise, not signal. Ceiling for the single-word tier; co-occurrence is
1308
+ * exempt because two words on one name is already discriminative. */
1309
+ static SEGMENT_RARITY_CEILING = 25;
1310
+ /** Which of the prompt's original words match `name`'s segments (via
1311
+ * variants). Segments are recomputed in JS — a name-keyed vocab lookup
1312
+ * would scan the (segment, name) primary key. */
1313
+ wordsMatchingName(name, variantToWord) {
1314
+ const segments = new Set((0, identifier_segments_1.splitIdentifierSegments)(name));
1315
+ const matched = new Set();
1316
+ for (const [variant, word] of variantToWord) {
1317
+ if (segments.has(variant))
1318
+ matched.add(word);
1319
+ }
1320
+ return matched;
1321
+ }
1322
+ /**
1323
+ * One-shot upgrade heal for callers that open the graph WITHOUT syncing —
1324
+ * concretely the prompt hook, whose MEDIUM tier reads the segment
1325
+ * vocabulary: a database migrated from before the vocab table existed
1326
+ * starts with it empty, and the only other backfill lives inside `sync()`,
1327
+ * which such callers never run (#1142). Returns true when the vocab is
1328
+ * usable (already populated — the overwhelmingly common one-SELECT case —
1329
+ * or healed here); false when it isn't (empty graph, or another process
1330
+ * holds the index lock — that process's own sync heals it).
1331
+ */
1332
+ async healSegmentVocabIfEmpty() {
1333
+ const empty = (() => {
1334
+ try {
1335
+ return this.queries.isNameSegmentVocabEmpty();
1336
+ }
1337
+ catch {
1338
+ return false;
1339
+ }
1340
+ })();
1341
+ if (!empty)
1342
+ return true;
1343
+ if (this.queries.getNodeAndEdgeCount().nodes === 0)
1344
+ return false;
1345
+ return this.indexMutex.withLock(async () => {
1346
+ try {
1347
+ this.fileLock.acquire();
1348
+ }
1349
+ catch {
1350
+ return false; // an index/sync is running — it backfills the vocab itself
1351
+ }
1352
+ try {
1353
+ if (!this.queries.isNameSegmentVocabEmpty())
1354
+ return true; // raced: healed meanwhile
1355
+ await this.rebuildNameSegmentVocab();
1356
+ return true;
1357
+ }
1358
+ finally {
1359
+ this.fileLock.release();
1360
+ }
1361
+ });
1362
+ }
1363
+ /**
1364
+ * Rebuild the segment vocabulary from the current graph, batched and
1365
+ * yielding — the upgrade-heal path for indexes built before the vocab table
1366
+ * existed. Runs inside the index mutex/lock (sync and
1367
+ * healSegmentVocabIfEmpty hold them).
1368
+ */
1369
+ async rebuildNameSegmentVocab() {
1370
+ const maybeYield = (0, cooperative_yield_1.createYielder)();
1371
+ const BATCH = 2000;
1372
+ for (let offset = 0;; offset += BATCH) {
1373
+ const names = this.queries.getDistinctNodeNames(BATCH, offset);
1374
+ if (names.length === 0)
1375
+ break;
1376
+ this.queries.insertNameSegmentsBatch(names);
1377
+ await maybeYield();
1378
+ }
1379
+ }
1380
+ /**
1381
+ * Normalized project-name tokens (go.mod / package.json / repo dir) used to
1382
+ * down-weight the non-discriminative project name in search ranking (#720).
1383
+ * Exposed so explore can exclude it from the PascalCase type-disambiguation
1384
+ * bias, which would otherwise pull overloaded tokens toward whichever stack
1385
+ * embeds the project name.
1386
+ */
1387
+ getProjectNameTokens() {
1388
+ return this.queries.getProjectNameTokens();
1389
+ }
1390
+ /**
1391
+ * Find the project's "primary route file" — the file with the densest
1392
+ * concentration of framework-emitted `route` nodes (≥3 routes, ≥30%
1393
+ * of all non-test routes). Used to inline the routing config in
1394
+ * `codegraph_explore` responses on small realworld template repos
1395
+ * (rails-realworld, laravel-realworld, drupal-admintoolbar, …) where
1396
+ * Glob+Read of `routes.rb`/`urls.py`/etc. otherwise beats codegraph.
1397
+ */
1398
+ getTopRouteFile() {
1399
+ return this.queries.getTopRouteFile();
1400
+ }
1401
+ /**
1402
+ * Build a URL → handler routing manifest from the index. Each entry
1403
+ * pairs a route node (URL + method) with its handler function/method
1404
+ * via the `references` edge that framework resolvers emit. Returns
1405
+ * null when fewer than 3 valid (non-test) routes exist.
1406
+ */
1407
+ getRoutingManifest(limit) {
1408
+ return this.queries.getRoutingManifest(limit);
1409
+ }
1410
+ // ===========================================================================
1411
+ // Edge Operations
1412
+ // ===========================================================================
1413
+ /**
1414
+ * Get outgoing edges from a node
1415
+ */
1416
+ getOutgoingEdges(nodeId) {
1417
+ return this.queries.getOutgoingEdges(nodeId);
1418
+ }
1419
+ /**
1420
+ * Get incoming edges to a node
1421
+ */
1422
+ getIncomingEdges(nodeId) {
1423
+ return this.queries.getIncomingEdges(nodeId);
1424
+ }
1425
+ // ===========================================================================
1426
+ // File Operations
1427
+ // ===========================================================================
1428
+ /**
1429
+ * Get a file record by path
1430
+ */
1431
+ getFile(filePath) {
1432
+ return this.queries.getFileByPath(filePath);
1433
+ }
1434
+ /**
1435
+ * Get all tracked files
1436
+ */
1437
+ getFiles() {
1438
+ return this.queries.getAllFiles();
1439
+ }
1440
+ /**
1441
+ * A `(path) => boolean` generated-file test over a BOUNDED candidate list,
1442
+ * unioning the index-time content-banner flag with the filename convention
1443
+ * (#1500). One query up front, O(1) per call after — built for use inside a
1444
+ * ranking comparator, where re-querying per comparison would be quadratic.
1445
+ *
1446
+ * Pass every path you might ask about; a path outside the list falls back to
1447
+ * the filename check alone.
1448
+ */
1449
+ generatedFilePredicate(filePaths) {
1450
+ return this.queries.generatedPredicateFor(filePaths);
1451
+ }
1452
+ /**
1453
+ * A `(path) => boolean` ambient-declaration test over a BOUNDED candidate
1454
+ * list: true for a file that declares nothing but types, originates no call
1455
+ * edge, and that nothing in the index depends on — an ambient `.d.ts` of
1456
+ * global shims, vendored typings, module augmentation (CG-28). Structural
1457
+ * rather than extension-based, and deliberately narrow: see
1458
+ * `QueryBuilder.getAmbientDeclarationPathsAmong` for why each condition is
1459
+ * there, in particular why a `types.ts` the codebase imports is NOT flagged.
1460
+ */
1461
+ ambientDeclarationFilePredicate(filePaths) {
1462
+ return this.queries.ambientDeclarationPredicateFor(filePaths);
1463
+ }
1464
+ /** How many indexed files are flagged tool-generated. Reported by `status`. */
1465
+ getGeneratedFileCount() {
1466
+ return this.queries.countGeneratedFiles();
1467
+ }
1468
+ // ===========================================================================
1469
+ // Graph Query Methods
1470
+ // ===========================================================================
1471
+ /**
1472
+ * Get the context for a node (ancestors, children, references)
1473
+ *
1474
+ * Returns comprehensive context about a node including its containment
1475
+ * hierarchy, children, incoming/outgoing references, type information,
1476
+ * and relevant imports.
1477
+ *
1478
+ * @param nodeId - ID of the focal node
1479
+ * @returns Context object with all related information
1480
+ */
1481
+ getContext(nodeId) {
1482
+ return this.graphManager.getContext(nodeId);
1483
+ }
1484
+ /**
1485
+ * Traverse the graph from a starting node
1486
+ *
1487
+ * Uses breadth-first search by default. Supports filtering by edge types,
1488
+ * node types, and traversal direction.
1489
+ *
1490
+ * @param startId - Starting node ID
1491
+ * @param options - Traversal options
1492
+ * @returns Subgraph containing traversed nodes and edges
1493
+ */
1494
+ traverse(startId, options) {
1495
+ return this.traverser.traverseBFS(startId, options);
1496
+ }
1497
+ /**
1498
+ * Get the call graph for a function
1499
+ *
1500
+ * Returns both callers (functions that call this function) and
1501
+ * callees (functions called by this function) up to the specified depth.
1502
+ *
1503
+ * @param nodeId - ID of the function/method node
1504
+ * @param depth - Maximum depth in each direction (default: 2)
1505
+ * @returns Subgraph containing the call graph
1506
+ */
1507
+ getCallGraph(nodeId, depth = 2) {
1508
+ return this.traverser.getCallGraph(nodeId, depth);
1509
+ }
1510
+ /**
1511
+ * Get the type hierarchy for a class/interface
1512
+ *
1513
+ * Returns both ancestors (types this extends/implements) and
1514
+ * descendants (types that extend/implement this).
1515
+ *
1516
+ * @param nodeId - ID of the class/interface node
1517
+ * @returns Subgraph containing the type hierarchy
1518
+ */
1519
+ getTypeHierarchy(nodeId) {
1520
+ return this.traverser.getTypeHierarchy(nodeId);
1521
+ }
1522
+ /**
1523
+ * Find all usages of a symbol
1524
+ *
1525
+ * Returns all nodes that reference the specified symbol through
1526
+ * any edge type (calls, references, type_of, etc.).
1527
+ *
1528
+ * @param nodeId - ID of the symbol node
1529
+ * @returns Array of nodes and edges that reference this symbol
1530
+ */
1531
+ findUsages(nodeId) {
1532
+ return this.traverser.findUsages(nodeId);
1533
+ }
1534
+ /**
1535
+ * Get callers of a function/method
1536
+ *
1537
+ * @param nodeId - ID of the function/method node
1538
+ * @param maxDepth - Maximum depth to traverse (default: 1)
1539
+ * @returns Array of nodes that call this function
1540
+ */
1541
+ getCallers(nodeId, maxDepth = 1) {
1542
+ return this.traverser.getCallers(nodeId, maxDepth);
1543
+ }
1544
+ /**
1545
+ * Get callees of a function/method
1546
+ *
1547
+ * @param nodeId - ID of the function/method node
1548
+ * @param maxDepth - Maximum depth to traverse (default: 1)
1549
+ * @returns Array of nodes called by this function
1550
+ */
1551
+ getCallees(nodeId, maxDepth = 1) {
1552
+ return this.traverser.getCallees(nodeId, maxDepth);
1553
+ }
1554
+ /**
1555
+ * Calculate the impact radius of a node
1556
+ *
1557
+ * Returns all nodes that could be affected by changes to this node.
1558
+ *
1559
+ * @param nodeId - ID of the node
1560
+ * @param maxDepth - Maximum depth to traverse (default: 3)
1561
+ * @returns Subgraph containing potentially impacted nodes
1562
+ */
1563
+ getImpactRadius(nodeId, maxDepth = 3) {
1564
+ return this.traverser.getImpactRadius(nodeId, maxDepth);
1565
+ }
1566
+ /**
1567
+ * Find the shortest path between two nodes
1568
+ *
1569
+ * @param fromId - Starting node ID
1570
+ * @param toId - Target node ID
1571
+ * @param edgeKinds - Edge types to consider (all if empty)
1572
+ * @returns Array of nodes and edges forming the path, or null if no path exists
1573
+ */
1574
+ findPath(fromId, toId, edgeKinds) {
1575
+ return this.traverser.findPath(fromId, toId, edgeKinds);
1576
+ }
1577
+ /**
1578
+ * Get ancestors of a node in the containment hierarchy
1579
+ *
1580
+ * @param nodeId - ID of the node
1581
+ * @returns Array of ancestor nodes from immediate parent to root
1582
+ */
1583
+ getAncestors(nodeId) {
1584
+ return this.traverser.getAncestors(nodeId);
1585
+ }
1586
+ /**
1587
+ * Get immediate children of a node
1588
+ *
1589
+ * @param nodeId - ID of the node
1590
+ * @returns Array of child nodes
1591
+ */
1592
+ getChildren(nodeId) {
1593
+ return this.traverser.getChildren(nodeId);
1594
+ }
1595
+ /**
1596
+ * Get dependencies of a file
1597
+ *
1598
+ * @param filePath - Path to the file
1599
+ * @returns Array of file paths this file depends on
1600
+ */
1601
+ getFileDependencies(filePath) {
1602
+ return this.graphManager.getFileDependencies(filePath);
1603
+ }
1604
+ /**
1605
+ * Get dependents of a file
1606
+ *
1607
+ * @param filePath - Path to the file
1608
+ * @returns Array of file paths that depend on this file
1609
+ */
1610
+ getFileDependents(filePath) {
1611
+ return this.graphManager.getFileDependents(filePath);
1612
+ }
1613
+ /**
1614
+ * Find circular dependencies in the codebase
1615
+ *
1616
+ * @returns Array of cycles, each cycle is an array of file paths
1617
+ */
1618
+ findCircularDependencies() {
1619
+ return this.graphManager.findCircularDependencies();
1620
+ }
1621
+ /**
1622
+ * Find dead code (unreferenced symbols)
1623
+ *
1624
+ * @param kinds - Node kinds to check (default: functions, methods, classes)
1625
+ * @returns Array of unreferenced nodes
1626
+ */
1627
+ findDeadCode(kinds) {
1628
+ return this.graphManager.findDeadCode(kinds);
1629
+ }
1630
+ /**
1631
+ * Get complexity metrics for a node
1632
+ *
1633
+ * @param nodeId - ID of the node
1634
+ * @returns Object containing various complexity metrics
1635
+ */
1636
+ getNodeMetrics(nodeId) {
1637
+ return this.graphManager.getNodeMetrics(nodeId);
1638
+ }
1639
+ // ===========================================================================
1640
+ // Context Building
1641
+ // ===========================================================================
1642
+ /**
1643
+ * Get the source code for a node
1644
+ *
1645
+ * Reads the file and extracts the code between startLine and endLine.
1646
+ *
1647
+ * @param nodeId - ID of the node
1648
+ * @returns Code string or null if not found
1649
+ */
1650
+ async getCode(nodeId) {
1651
+ return this.contextBuilder.getCode(nodeId);
1652
+ }
1653
+ /**
1654
+ * Find relevant subgraph for a query
1655
+ *
1656
+ * Combines semantic search with graph traversal to find the most
1657
+ * relevant nodes and their relationships for a given query.
1658
+ *
1659
+ * @param query - Natural language query describing the task
1660
+ * @param options - Search and traversal options
1661
+ * @returns Subgraph of relevant nodes and edges
1662
+ */
1663
+ async findRelevantContext(query, options) {
1664
+ return this.contextBuilder.findRelevantContext(query, options);
1665
+ }
1666
+ /**
1667
+ * Build context for a task
1668
+ *
1669
+ * Creates comprehensive context by:
1670
+ * 1. Running FTS search to find entry points
1671
+ * 2. Expanding the graph around entry points
1672
+ * 3. Extracting code blocks for key nodes
1673
+ * 4. Formatting output for Claude
1674
+ *
1675
+ * @param input - Task description (string or {title, description})
1676
+ * @param options - Build options (maxNodes, includeCode, format, etc.)
1677
+ * @returns TaskContext object or formatted string (markdown/JSON)
1678
+ */
1679
+ async buildContext(input, options) {
1680
+ return this.contextBuilder.buildContext(input, options);
1681
+ }
1682
+ // ===========================================================================
1683
+ // Database Management
1684
+ // ===========================================================================
1685
+ /**
1686
+ * Optimize the database (vacuum and analyze)
1687
+ */
1688
+ optimize() {
1689
+ this.db.optimize();
1690
+ }
1691
+ /**
1692
+ * Clear all data from the graph
1693
+ */
1694
+ clear() {
1695
+ this.queries.clear();
1696
+ }
1697
+ /**
1698
+ * Alias for close() for backwards compatibility.
1699
+ * @deprecated Use close() instead
1700
+ */
1701
+ destroy() {
1702
+ this.close();
1703
+ }
1704
+ /**
1705
+ * Completely remove CodeGraph from the project.
1706
+ * This closes the database and deletes the .CodeGraph directory.
1707
+ *
1708
+ * WARNING: This permanently deletes all CodeGraph data for the project.
1709
+ */
1710
+ uninitialize() {
1711
+ this.close();
1712
+ (0, directory_1.removeDirectory)(this.projectRoot);
1713
+ }
1714
+ }
1715
+ exports.CodeGraph = CodeGraph;
1716
+ // Default export
1717
+ exports.default = CodeGraph;
1718
+ //# sourceMappingURL=index.js.map