codegraph-java 0.1.0

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