@kkvcrobatz107/codegraph 0.9.6-pkm.1

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 (501) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +595 -0
  3. package/dist/bin/codegraph.d.ts +25 -0
  4. package/dist/bin/codegraph.d.ts.map +1 -0
  5. package/dist/bin/codegraph.js +1563 -0
  6. package/dist/bin/codegraph.js.map +1 -0
  7. package/dist/bin/node-version-check.d.ts +37 -0
  8. package/dist/bin/node-version-check.d.ts.map +1 -0
  9. package/dist/bin/node-version-check.js +79 -0
  10. package/dist/bin/node-version-check.js.map +1 -0
  11. package/dist/bin/uninstall.d.ts +14 -0
  12. package/dist/bin/uninstall.d.ts.map +1 -0
  13. package/dist/bin/uninstall.js +36 -0
  14. package/dist/bin/uninstall.js.map +1 -0
  15. package/dist/context/formatter.d.ts +30 -0
  16. package/dist/context/formatter.d.ts.map +1 -0
  17. package/dist/context/formatter.js +244 -0
  18. package/dist/context/formatter.js.map +1 -0
  19. package/dist/context/index.d.ts +110 -0
  20. package/dist/context/index.d.ts.map +1 -0
  21. package/dist/context/index.js +1169 -0
  22. package/dist/context/index.js.map +1 -0
  23. package/dist/db/index.d.ts +101 -0
  24. package/dist/db/index.d.ts.map +1 -0
  25. package/dist/db/index.js +251 -0
  26. package/dist/db/index.js.map +1 -0
  27. package/dist/db/migrations.d.ts +44 -0
  28. package/dist/db/migrations.d.ts.map +1 -0
  29. package/dist/db/migrations.js +131 -0
  30. package/dist/db/migrations.js.map +1 -0
  31. package/dist/db/queries.d.ts +281 -0
  32. package/dist/db/queries.d.ts.map +1 -0
  33. package/dist/db/queries.js +1300 -0
  34. package/dist/db/queries.js.map +1 -0
  35. package/dist/db/schema.sql +151 -0
  36. package/dist/db/sqlite-adapter.d.ts +46 -0
  37. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  38. package/dist/db/sqlite-adapter.js +114 -0
  39. package/dist/db/sqlite-adapter.js.map +1 -0
  40. package/dist/directory.d.ts +57 -0
  41. package/dist/directory.d.ts.map +1 -0
  42. package/dist/directory.js +264 -0
  43. package/dist/directory.js.map +1 -0
  44. package/dist/errors.d.ts +136 -0
  45. package/dist/errors.d.ts.map +1 -0
  46. package/dist/errors.js +219 -0
  47. package/dist/errors.js.map +1 -0
  48. package/dist/extraction/dfm-extractor.d.ts +31 -0
  49. package/dist/extraction/dfm-extractor.d.ts.map +1 -0
  50. package/dist/extraction/dfm-extractor.js +151 -0
  51. package/dist/extraction/dfm-extractor.js.map +1 -0
  52. package/dist/extraction/grammars.d.ts +90 -0
  53. package/dist/extraction/grammars.d.ts.map +1 -0
  54. package/dist/extraction/grammars.js +407 -0
  55. package/dist/extraction/grammars.js.map +1 -0
  56. package/dist/extraction/index.d.ts +138 -0
  57. package/dist/extraction/index.d.ts.map +1 -0
  58. package/dist/extraction/index.js +1378 -0
  59. package/dist/extraction/index.js.map +1 -0
  60. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  61. package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  62. package/dist/extraction/languages/c-cpp.js +171 -0
  63. package/dist/extraction/languages/c-cpp.js.map +1 -0
  64. package/dist/extraction/languages/csharp.d.ts +3 -0
  65. package/dist/extraction/languages/csharp.d.ts.map +1 -0
  66. package/dist/extraction/languages/csharp.js +73 -0
  67. package/dist/extraction/languages/csharp.js.map +1 -0
  68. package/dist/extraction/languages/dart.d.ts +3 -0
  69. package/dist/extraction/languages/dart.d.ts.map +1 -0
  70. package/dist/extraction/languages/dart.js +192 -0
  71. package/dist/extraction/languages/dart.js.map +1 -0
  72. package/dist/extraction/languages/go.d.ts +3 -0
  73. package/dist/extraction/languages/go.d.ts.map +1 -0
  74. package/dist/extraction/languages/go.js +70 -0
  75. package/dist/extraction/languages/go.js.map +1 -0
  76. package/dist/extraction/languages/index.d.ts +10 -0
  77. package/dist/extraction/languages/index.d.ts.map +1 -0
  78. package/dist/extraction/languages/index.js +51 -0
  79. package/dist/extraction/languages/index.js.map +1 -0
  80. package/dist/extraction/languages/java.d.ts +3 -0
  81. package/dist/extraction/languages/java.d.ts.map +1 -0
  82. package/dist/extraction/languages/java.js +70 -0
  83. package/dist/extraction/languages/java.js.map +1 -0
  84. package/dist/extraction/languages/javascript.d.ts +3 -0
  85. package/dist/extraction/languages/javascript.d.ts.map +1 -0
  86. package/dist/extraction/languages/javascript.js +90 -0
  87. package/dist/extraction/languages/javascript.js.map +1 -0
  88. package/dist/extraction/languages/kotlin.d.ts +3 -0
  89. package/dist/extraction/languages/kotlin.d.ts.map +1 -0
  90. package/dist/extraction/languages/kotlin.js +259 -0
  91. package/dist/extraction/languages/kotlin.js.map +1 -0
  92. package/dist/extraction/languages/lua.d.ts +3 -0
  93. package/dist/extraction/languages/lua.d.ts.map +1 -0
  94. package/dist/extraction/languages/lua.js +150 -0
  95. package/dist/extraction/languages/lua.js.map +1 -0
  96. package/dist/extraction/languages/luau.d.ts +3 -0
  97. package/dist/extraction/languages/luau.d.ts.map +1 -0
  98. package/dist/extraction/languages/luau.js +37 -0
  99. package/dist/extraction/languages/luau.js.map +1 -0
  100. package/dist/extraction/languages/objc.d.ts +3 -0
  101. package/dist/extraction/languages/objc.d.ts.map +1 -0
  102. package/dist/extraction/languages/objc.js +133 -0
  103. package/dist/extraction/languages/objc.js.map +1 -0
  104. package/dist/extraction/languages/pascal.d.ts +3 -0
  105. package/dist/extraction/languages/pascal.d.ts.map +1 -0
  106. package/dist/extraction/languages/pascal.js +66 -0
  107. package/dist/extraction/languages/pascal.js.map +1 -0
  108. package/dist/extraction/languages/php.d.ts +3 -0
  109. package/dist/extraction/languages/php.d.ts.map +1 -0
  110. package/dist/extraction/languages/php.js +107 -0
  111. package/dist/extraction/languages/php.js.map +1 -0
  112. package/dist/extraction/languages/python.d.ts +3 -0
  113. package/dist/extraction/languages/python.d.ts.map +1 -0
  114. package/dist/extraction/languages/python.js +56 -0
  115. package/dist/extraction/languages/python.js.map +1 -0
  116. package/dist/extraction/languages/ruby.d.ts +3 -0
  117. package/dist/extraction/languages/ruby.d.ts.map +1 -0
  118. package/dist/extraction/languages/ruby.js +114 -0
  119. package/dist/extraction/languages/ruby.js.map +1 -0
  120. package/dist/extraction/languages/rust.d.ts +3 -0
  121. package/dist/extraction/languages/rust.d.ts.map +1 -0
  122. package/dist/extraction/languages/rust.js +109 -0
  123. package/dist/extraction/languages/rust.js.map +1 -0
  124. package/dist/extraction/languages/scala.d.ts +3 -0
  125. package/dist/extraction/languages/scala.d.ts.map +1 -0
  126. package/dist/extraction/languages/scala.js +139 -0
  127. package/dist/extraction/languages/scala.js.map +1 -0
  128. package/dist/extraction/languages/swift.d.ts +3 -0
  129. package/dist/extraction/languages/swift.d.ts.map +1 -0
  130. package/dist/extraction/languages/swift.js +91 -0
  131. package/dist/extraction/languages/swift.js.map +1 -0
  132. package/dist/extraction/languages/typescript.d.ts +3 -0
  133. package/dist/extraction/languages/typescript.d.ts.map +1 -0
  134. package/dist/extraction/languages/typescript.js +129 -0
  135. package/dist/extraction/languages/typescript.js.map +1 -0
  136. package/dist/extraction/liquid-extractor.d.ts +52 -0
  137. package/dist/extraction/liquid-extractor.d.ts.map +1 -0
  138. package/dist/extraction/liquid-extractor.js +313 -0
  139. package/dist/extraction/liquid-extractor.js.map +1 -0
  140. package/dist/extraction/mybatis-extractor.d.ts +48 -0
  141. package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
  142. package/dist/extraction/mybatis-extractor.js +198 -0
  143. package/dist/extraction/mybatis-extractor.js.map +1 -0
  144. package/dist/extraction/parse-worker.d.ts +8 -0
  145. package/dist/extraction/parse-worker.d.ts.map +1 -0
  146. package/dist/extraction/parse-worker.js +94 -0
  147. package/dist/extraction/parse-worker.js.map +1 -0
  148. package/dist/extraction/svelte-extractor.d.ts +56 -0
  149. package/dist/extraction/svelte-extractor.d.ts.map +1 -0
  150. package/dist/extraction/svelte-extractor.js +272 -0
  151. package/dist/extraction/svelte-extractor.js.map +1 -0
  152. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  153. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  154. package/dist/extraction/tree-sitter-helpers.js +103 -0
  155. package/dist/extraction/tree-sitter-helpers.js.map +1 -0
  156. package/dist/extraction/tree-sitter-types.d.ts +193 -0
  157. package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  158. package/dist/extraction/tree-sitter-types.js +10 -0
  159. package/dist/extraction/tree-sitter-types.js.map +1 -0
  160. package/dist/extraction/tree-sitter.d.ts +291 -0
  161. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  162. package/dist/extraction/tree-sitter.js +2961 -0
  163. package/dist/extraction/tree-sitter.js.map +1 -0
  164. package/dist/extraction/vue-extractor.d.ts +36 -0
  165. package/dist/extraction/vue-extractor.d.ts.map +1 -0
  166. package/dist/extraction/vue-extractor.js +163 -0
  167. package/dist/extraction/vue-extractor.js.map +1 -0
  168. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  169. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  170. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  171. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  172. package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
  173. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
  174. package/dist/extraction/wasm-runtime-flags.js +105 -0
  175. package/dist/extraction/wasm-runtime-flags.js.map +1 -0
  176. package/dist/graph/index.d.ts +8 -0
  177. package/dist/graph/index.d.ts.map +1 -0
  178. package/dist/graph/index.js +13 -0
  179. package/dist/graph/index.js.map +1 -0
  180. package/dist/graph/queries.d.ts +106 -0
  181. package/dist/graph/queries.d.ts.map +1 -0
  182. package/dist/graph/queries.js +366 -0
  183. package/dist/graph/queries.js.map +1 -0
  184. package/dist/graph/traversal.d.ts +127 -0
  185. package/dist/graph/traversal.d.ts.map +1 -0
  186. package/dist/graph/traversal.js +528 -0
  187. package/dist/graph/traversal.js.map +1 -0
  188. package/dist/index.d.ts +460 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +863 -0
  191. package/dist/index.js.map +1 -0
  192. package/dist/installer/claude-md-template.d.ts +14 -0
  193. package/dist/installer/claude-md-template.d.ts.map +1 -0
  194. package/dist/installer/claude-md-template.js +21 -0
  195. package/dist/installer/claude-md-template.js.map +1 -0
  196. package/dist/installer/config-writer.d.ts +29 -0
  197. package/dist/installer/config-writer.d.ts.map +1 -0
  198. package/dist/installer/config-writer.js +111 -0
  199. package/dist/installer/config-writer.js.map +1 -0
  200. package/dist/installer/index.d.ts +117 -0
  201. package/dist/installer/index.d.ts.map +1 -0
  202. package/dist/installer/index.js +528 -0
  203. package/dist/installer/index.js.map +1 -0
  204. package/dist/installer/instructions-template.d.ts +28 -0
  205. package/dist/installer/instructions-template.d.ts.map +1 -0
  206. package/dist/installer/instructions-template.js +65 -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 +307 -0
  211. package/dist/installer/targets/antigravity.js.map +1 -0
  212. package/dist/installer/targets/claude.d.ts +47 -0
  213. package/dist/installer/targets/claude.d.ts.map +1 -0
  214. package/dist/installer/targets/claude.js +401 -0
  215. package/dist/installer/targets/claude.js.map +1 -0
  216. package/dist/installer/targets/codex.d.ts +18 -0
  217. package/dist/installer/targets/codex.d.ts.map +1 -0
  218. package/dist/installer/targets/codex.js +185 -0
  219. package/dist/installer/targets/codex.js.map +1 -0
  220. package/dist/installer/targets/cursor.d.ts +35 -0
  221. package/dist/installer/targets/cursor.d.ts.map +1 -0
  222. package/dist/installer/targets/cursor.js +283 -0
  223. package/dist/installer/targets/cursor.js.map +1 -0
  224. package/dist/installer/targets/gemini.d.ts +26 -0
  225. package/dist/installer/targets/gemini.d.ts.map +1 -0
  226. package/dist/installer/targets/gemini.js +165 -0
  227. package/dist/installer/targets/gemini.js.map +1 -0
  228. package/dist/installer/targets/hermes.d.ts +18 -0
  229. package/dist/installer/targets/hermes.d.ts.map +1 -0
  230. package/dist/installer/targets/hermes.js +359 -0
  231. package/dist/installer/targets/hermes.js.map +1 -0
  232. package/dist/installer/targets/kiro.d.ts +27 -0
  233. package/dist/installer/targets/kiro.d.ts.map +1 -0
  234. package/dist/installer/targets/kiro.js +196 -0
  235. package/dist/installer/targets/kiro.js.map +1 -0
  236. package/dist/installer/targets/opencode.d.ts +30 -0
  237. package/dist/installer/targets/opencode.d.ts.map +1 -0
  238. package/dist/installer/targets/opencode.js +235 -0
  239. package/dist/installer/targets/opencode.js.map +1 -0
  240. package/dist/installer/targets/registry.d.ts +35 -0
  241. package/dist/installer/targets/registry.d.ts.map +1 -0
  242. package/dist/installer/targets/registry.js +91 -0
  243. package/dist/installer/targets/registry.js.map +1 -0
  244. package/dist/installer/targets/shared.d.ts +77 -0
  245. package/dist/installer/targets/shared.d.ts.map +1 -0
  246. package/dist/installer/targets/shared.js +246 -0
  247. package/dist/installer/targets/shared.js.map +1 -0
  248. package/dist/installer/targets/toml.d.ts +52 -0
  249. package/dist/installer/targets/toml.d.ts.map +1 -0
  250. package/dist/installer/targets/toml.js +147 -0
  251. package/dist/installer/targets/toml.js.map +1 -0
  252. package/dist/installer/targets/types.d.ts +116 -0
  253. package/dist/installer/targets/types.d.ts.map +1 -0
  254. package/dist/installer/targets/types.js +16 -0
  255. package/dist/installer/targets/types.js.map +1 -0
  256. package/dist/mcp/daemon-paths.d.ts +46 -0
  257. package/dist/mcp/daemon-paths.d.ts.map +1 -0
  258. package/dist/mcp/daemon-paths.js +125 -0
  259. package/dist/mcp/daemon-paths.js.map +1 -0
  260. package/dist/mcp/daemon.d.ts +161 -0
  261. package/dist/mcp/daemon.d.ts.map +1 -0
  262. package/dist/mcp/daemon.js +403 -0
  263. package/dist/mcp/daemon.js.map +1 -0
  264. package/dist/mcp/engine.d.ts +100 -0
  265. package/dist/mcp/engine.d.ts.map +1 -0
  266. package/dist/mcp/engine.js +291 -0
  267. package/dist/mcp/engine.js.map +1 -0
  268. package/dist/mcp/index.d.ts +109 -0
  269. package/dist/mcp/index.d.ts.map +1 -0
  270. package/dist/mcp/index.js +470 -0
  271. package/dist/mcp/index.js.map +1 -0
  272. package/dist/mcp/proxy.d.ts +46 -0
  273. package/dist/mcp/proxy.d.ts.map +1 -0
  274. package/dist/mcp/proxy.js +276 -0
  275. package/dist/mcp/proxy.js.map +1 -0
  276. package/dist/mcp/server-instructions.d.ts +19 -0
  277. package/dist/mcp/server-instructions.d.ts.map +1 -0
  278. package/dist/mcp/server-instructions.js +73 -0
  279. package/dist/mcp/server-instructions.js.map +1 -0
  280. package/dist/mcp/session.d.ts +67 -0
  281. package/dist/mcp/session.d.ts.map +1 -0
  282. package/dist/mcp/session.js +276 -0
  283. package/dist/mcp/session.js.map +1 -0
  284. package/dist/mcp/tools.d.ts +385 -0
  285. package/dist/mcp/tools.d.ts.map +1 -0
  286. package/dist/mcp/tools.js +2545 -0
  287. package/dist/mcp/tools.js.map +1 -0
  288. package/dist/mcp/transport.d.ts +188 -0
  289. package/dist/mcp/transport.d.ts.map +1 -0
  290. package/dist/mcp/transport.js +343 -0
  291. package/dist/mcp/transport.js.map +1 -0
  292. package/dist/mcp/version.d.ts +19 -0
  293. package/dist/mcp/version.d.ts.map +1 -0
  294. package/dist/mcp/version.js +71 -0
  295. package/dist/mcp/version.js.map +1 -0
  296. package/dist/resolution/callback-synthesizer.d.ts +10 -0
  297. package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
  298. package/dist/resolution/callback-synthesizer.js +924 -0
  299. package/dist/resolution/callback-synthesizer.js.map +1 -0
  300. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  301. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  302. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  303. package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  304. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  305. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  306. package/dist/resolution/frameworks/csharp.js +241 -0
  307. package/dist/resolution/frameworks/csharp.js.map +1 -0
  308. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  309. package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
  310. package/dist/resolution/frameworks/drupal.js +367 -0
  311. package/dist/resolution/frameworks/drupal.js.map +1 -0
  312. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  313. package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
  314. package/dist/resolution/frameworks/expo-modules.js +143 -0
  315. package/dist/resolution/frameworks/expo-modules.js.map +1 -0
  316. package/dist/resolution/frameworks/express.d.ts +8 -0
  317. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  318. package/dist/resolution/frameworks/express.js +308 -0
  319. package/dist/resolution/frameworks/express.js.map +1 -0
  320. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  321. package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
  322. package/dist/resolution/frameworks/fabric.js +354 -0
  323. package/dist/resolution/frameworks/fabric.js.map +1 -0
  324. package/dist/resolution/frameworks/go.d.ts +8 -0
  325. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  326. package/dist/resolution/frameworks/go.js +161 -0
  327. package/dist/resolution/frameworks/go.js.map +1 -0
  328. package/dist/resolution/frameworks/index.d.ts +48 -0
  329. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  330. package/dist/resolution/frameworks/index.js +161 -0
  331. package/dist/resolution/frameworks/index.js.map +1 -0
  332. package/dist/resolution/frameworks/java.d.ts +8 -0
  333. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  334. package/dist/resolution/frameworks/java.js +504 -0
  335. package/dist/resolution/frameworks/java.js.map +1 -0
  336. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  337. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  338. package/dist/resolution/frameworks/laravel.js +257 -0
  339. package/dist/resolution/frameworks/laravel.js.map +1 -0
  340. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  341. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  342. package/dist/resolution/frameworks/nestjs.js +698 -0
  343. package/dist/resolution/frameworks/nestjs.js.map +1 -0
  344. package/dist/resolution/frameworks/play.d.ts +19 -0
  345. package/dist/resolution/frameworks/play.d.ts.map +1 -0
  346. package/dist/resolution/frameworks/play.js +111 -0
  347. package/dist/resolution/frameworks/play.js.map +1 -0
  348. package/dist/resolution/frameworks/python.d.ts +10 -0
  349. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  350. package/dist/resolution/frameworks/python.js +396 -0
  351. package/dist/resolution/frameworks/python.js.map +1 -0
  352. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  353. package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
  354. package/dist/resolution/frameworks/react-native.js +360 -0
  355. package/dist/resolution/frameworks/react-native.js.map +1 -0
  356. package/dist/resolution/frameworks/react.d.ts +8 -0
  357. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  358. package/dist/resolution/frameworks/react.js +365 -0
  359. package/dist/resolution/frameworks/react.js.map +1 -0
  360. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  361. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  362. package/dist/resolution/frameworks/ruby.js +302 -0
  363. package/dist/resolution/frameworks/ruby.js.map +1 -0
  364. package/dist/resolution/frameworks/rust.d.ts +8 -0
  365. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  366. package/dist/resolution/frameworks/rust.js +304 -0
  367. package/dist/resolution/frameworks/rust.js.map +1 -0
  368. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  369. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  370. package/dist/resolution/frameworks/svelte.js +249 -0
  371. package/dist/resolution/frameworks/svelte.js.map +1 -0
  372. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  373. package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
  374. package/dist/resolution/frameworks/swift-objc.js +252 -0
  375. package/dist/resolution/frameworks/swift-objc.js.map +1 -0
  376. package/dist/resolution/frameworks/swift.d.ts +10 -0
  377. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  378. package/dist/resolution/frameworks/swift.js +400 -0
  379. package/dist/resolution/frameworks/swift.js.map +1 -0
  380. package/dist/resolution/frameworks/vue.d.ts +9 -0
  381. package/dist/resolution/frameworks/vue.d.ts.map +1 -0
  382. package/dist/resolution/frameworks/vue.js +306 -0
  383. package/dist/resolution/frameworks/vue.js.map +1 -0
  384. package/dist/resolution/go-module.d.ts +26 -0
  385. package/dist/resolution/go-module.d.ts.map +1 -0
  386. package/dist/resolution/go-module.js +78 -0
  387. package/dist/resolution/go-module.js.map +1 -0
  388. package/dist/resolution/import-resolver.d.ts +68 -0
  389. package/dist/resolution/import-resolver.d.ts.map +1 -0
  390. package/dist/resolution/import-resolver.js +1231 -0
  391. package/dist/resolution/import-resolver.js.map +1 -0
  392. package/dist/resolution/index.d.ts +116 -0
  393. package/dist/resolution/index.d.ts.map +1 -0
  394. package/dist/resolution/index.js +878 -0
  395. package/dist/resolution/index.js.map +1 -0
  396. package/dist/resolution/lru-cache.d.ts +24 -0
  397. package/dist/resolution/lru-cache.d.ts.map +1 -0
  398. package/dist/resolution/lru-cache.js +62 -0
  399. package/dist/resolution/lru-cache.js.map +1 -0
  400. package/dist/resolution/name-matcher.d.ts +32 -0
  401. package/dist/resolution/name-matcher.d.ts.map +1 -0
  402. package/dist/resolution/name-matcher.js +596 -0
  403. package/dist/resolution/name-matcher.js.map +1 -0
  404. package/dist/resolution/path-aliases.d.ts +68 -0
  405. package/dist/resolution/path-aliases.d.ts.map +1 -0
  406. package/dist/resolution/path-aliases.js +238 -0
  407. package/dist/resolution/path-aliases.js.map +1 -0
  408. package/dist/resolution/strip-comments.d.ts +27 -0
  409. package/dist/resolution/strip-comments.d.ts.map +1 -0
  410. package/dist/resolution/strip-comments.js +441 -0
  411. package/dist/resolution/strip-comments.js.map +1 -0
  412. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  413. package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
  414. package/dist/resolution/swift-objc-bridge.js +256 -0
  415. package/dist/resolution/swift-objc-bridge.js.map +1 -0
  416. package/dist/resolution/types.d.ts +209 -0
  417. package/dist/resolution/types.d.ts.map +1 -0
  418. package/dist/resolution/types.js +8 -0
  419. package/dist/resolution/types.js.map +1 -0
  420. package/dist/search/query-parser.d.ts +57 -0
  421. package/dist/search/query-parser.d.ts.map +1 -0
  422. package/dist/search/query-parser.js +177 -0
  423. package/dist/search/query-parser.js.map +1 -0
  424. package/dist/search/query-utils.d.ts +53 -0
  425. package/dist/search/query-utils.d.ts.map +1 -0
  426. package/dist/search/query-utils.js +350 -0
  427. package/dist/search/query-utils.js.map +1 -0
  428. package/dist/sync/git-hooks.d.ts +45 -0
  429. package/dist/sync/git-hooks.d.ts.map +1 -0
  430. package/dist/sync/git-hooks.js +223 -0
  431. package/dist/sync/git-hooks.js.map +1 -0
  432. package/dist/sync/index.d.ts +19 -0
  433. package/dist/sync/index.d.ts.map +1 -0
  434. package/dist/sync/index.js +35 -0
  435. package/dist/sync/index.js.map +1 -0
  436. package/dist/sync/watch-policy.d.ts +48 -0
  437. package/dist/sync/watch-policy.d.ts.map +1 -0
  438. package/dist/sync/watch-policy.js +124 -0
  439. package/dist/sync/watch-policy.js.map +1 -0
  440. package/dist/sync/watcher.d.ts +191 -0
  441. package/dist/sync/watcher.d.ts.map +1 -0
  442. package/dist/sync/watcher.js +398 -0
  443. package/dist/sync/watcher.js.map +1 -0
  444. package/dist/sync/worktree.d.ts +54 -0
  445. package/dist/sync/worktree.d.ts.map +1 -0
  446. package/dist/sync/worktree.js +136 -0
  447. package/dist/sync/worktree.js.map +1 -0
  448. package/dist/types.d.ts +369 -0
  449. package/dist/types.d.ts.map +1 -0
  450. package/dist/types.js +78 -0
  451. package/dist/types.js.map +1 -0
  452. package/dist/ui/glyphs.d.ts +42 -0
  453. package/dist/ui/glyphs.d.ts.map +1 -0
  454. package/dist/ui/glyphs.js +78 -0
  455. package/dist/ui/glyphs.js.map +1 -0
  456. package/dist/ui/shimmer-progress.d.ts +11 -0
  457. package/dist/ui/shimmer-progress.d.ts.map +1 -0
  458. package/dist/ui/shimmer-progress.js +90 -0
  459. package/dist/ui/shimmer-progress.js.map +1 -0
  460. package/dist/ui/shimmer-worker.d.ts +2 -0
  461. package/dist/ui/shimmer-worker.d.ts.map +1 -0
  462. package/dist/ui/shimmer-worker.js +118 -0
  463. package/dist/ui/shimmer-worker.js.map +1 -0
  464. package/dist/ui/types.d.ts +17 -0
  465. package/dist/ui/types.d.ts.map +1 -0
  466. package/dist/ui/types.js +3 -0
  467. package/dist/ui/types.js.map +1 -0
  468. package/dist/utils.d.ts +205 -0
  469. package/dist/utils.d.ts.map +1 -0
  470. package/dist/utils.js +549 -0
  471. package/dist/utils.js.map +1 -0
  472. package/package.json +59 -0
  473. package/scripts/add-lang/bench.sh +60 -0
  474. package/scripts/add-lang/check-grammar.mjs +75 -0
  475. package/scripts/add-lang/dump-ast.mjs +103 -0
  476. package/scripts/add-lang/verify-extraction.mjs +70 -0
  477. package/scripts/agent-eval/arms-F.sh +21 -0
  478. package/scripts/agent-eval/arms-matrix.sh +37 -0
  479. package/scripts/agent-eval/audit.sh +68 -0
  480. package/scripts/agent-eval/bench-readme.sh +28 -0
  481. package/scripts/agent-eval/block-read-hook.sh +19 -0
  482. package/scripts/agent-eval/hook-settings.json +15 -0
  483. package/scripts/agent-eval/itrun.sh +107 -0
  484. package/scripts/agent-eval/parse-arms.mjs +116 -0
  485. package/scripts/agent-eval/parse-bench-readme.mjs +67 -0
  486. package/scripts/agent-eval/parse-run.mjs +45 -0
  487. package/scripts/agent-eval/parse-session.mjs +93 -0
  488. package/scripts/agent-eval/probe-context.mjs +21 -0
  489. package/scripts/agent-eval/probe-explore.mjs +40 -0
  490. package/scripts/agent-eval/probe-node.mjs +20 -0
  491. package/scripts/agent-eval/probe-trace.mjs +20 -0
  492. package/scripts/agent-eval/run-agent.sh +34 -0
  493. package/scripts/agent-eval/run-all.sh +67 -0
  494. package/scripts/agent-eval/run-arms.sh +56 -0
  495. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  496. package/scripts/build-bundle.sh +118 -0
  497. package/scripts/extract-release-notes.mjs +130 -0
  498. package/scripts/local-install.sh +41 -0
  499. package/scripts/npm-shim.js +246 -0
  500. package/scripts/pack-npm.sh +95 -0
  501. package/scripts/prepare-release.mjs +270 -0
@@ -0,0 +1,1563 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * CodeGraph CLI
5
+ *
6
+ * Command-line interface for CodeGraph code intelligence.
7
+ *
8
+ * Usage:
9
+ * codegraph Run interactive installer (when no args)
10
+ * codegraph install Run interactive installer
11
+ * codegraph uninstall Remove CodeGraph from your agents
12
+ * codegraph init [path] Initialize CodeGraph in a project
13
+ * codegraph uninit [path] Remove CodeGraph from a project
14
+ * codegraph index [path] Index all files in the project
15
+ * codegraph sync [path] Sync changes since last index
16
+ * codegraph status [path] Show index status
17
+ * codegraph query <search> Search for symbols
18
+ * codegraph files [options] Show project file structure
19
+ * codegraph context <task> Build context for a task
20
+ * codegraph callers <symbol> Find what calls a function/method
21
+ * codegraph callees <symbol> Find what a function/method calls
22
+ * codegraph impact <symbol> Analyze what code is affected by changing a symbol
23
+ * codegraph affected [files] Find test files affected by changes
24
+ */
25
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ var desc = Object.getOwnPropertyDescriptor(m, k);
28
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
29
+ desc = { enumerable: true, get: function() { return m[k]; } };
30
+ }
31
+ Object.defineProperty(o, k2, desc);
32
+ }) : (function(o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ o[k2] = m[k];
35
+ }));
36
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
37
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
38
+ }) : function(o, v) {
39
+ o["default"] = v;
40
+ });
41
+ var __importStar = (this && this.__importStar) || (function () {
42
+ var ownKeys = function(o) {
43
+ ownKeys = Object.getOwnPropertyNames || function (o) {
44
+ var ar = [];
45
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
46
+ return ar;
47
+ };
48
+ return ownKeys(o);
49
+ };
50
+ return function (mod) {
51
+ if (mod && mod.__esModule) return mod;
52
+ var result = {};
53
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
54
+ __setModuleDefault(result, mod);
55
+ return result;
56
+ };
57
+ })();
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ const commander_1 = require("commander");
60
+ const path = __importStar(require("path"));
61
+ const fs = __importStar(require("fs"));
62
+ const directory_1 = require("../directory");
63
+ const worktree_1 = require("../sync/worktree");
64
+ const shimmer_progress_1 = require("../ui/shimmer-progress");
65
+ const glyphs_1 = require("../ui/glyphs");
66
+ const node_version_check_1 = require("./node-version-check");
67
+ const wasm_runtime_flags_1 = require("../extraction/wasm-runtime-flags");
68
+ // Lazy-load heavy modules (CodeGraph, runInstaller) to keep CLI startup fast.
69
+ async function loadCodeGraph() {
70
+ try {
71
+ return await Promise.resolve().then(() => __importStar(require('../index')));
72
+ }
73
+ catch (err) {
74
+ const msg = err instanceof Error ? err.message : String(err);
75
+ console.error(`\x1b[31m${(0, glyphs_1.getGlyphs)().err}\x1b[0m Failed to load CodeGraph modules.`);
76
+ console.error(`\n Node: ${process.version} Platform: ${process.platform} ${process.arch}`);
77
+ console.error(`\n Error: ${msg}`);
78
+ console.error('\n Try reinstalling with: npm install -g @colbymchenry/codegraph\n');
79
+ process.exit(1);
80
+ }
81
+ }
82
+ // Dynamic import helper — tsc compiles import() to require() in CJS mode,
83
+ // which fails for ESM-only packages. This bypasses the transformation.
84
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
85
+ const importESM = new Function('specifier', 'return import(specifier)');
86
+ // Block CodeGraph on Node.js 25.x — V8's turboshaft WASM JIT has a Zone
87
+ // allocator bug that reliably crashes when compiling tree-sitter
88
+ // grammars (see #54, #81, #140). The previous behaviour was a soft
89
+ // console.warn that scrolls off-screen before the OOM crash 30 seconds
90
+ // later, leading to a steady stream of "what is this OOM" reports.
91
+ // Hard-exit before any WASM work; allow override via env var for users
92
+ // who patched V8 themselves or want to test a future fix.
93
+ const nodeVersion = process.versions.node;
94
+ const nodeMajor = parseInt(nodeVersion.split('.')[0] ?? '0', 10);
95
+ if (nodeMajor >= 25) {
96
+ process.stderr.write((0, node_version_check_1.buildNode25BlockBanner)(nodeVersion) + '\n');
97
+ if (!process.env.CODEGRAPH_ALLOW_UNSAFE_NODE) {
98
+ process.exit(1);
99
+ }
100
+ // Override active — banner shown for visibility, continuing.
101
+ }
102
+ // Enforce the supported Node floor. `engines` in package.json only *warns* on
103
+ // install (unless engine-strict), so hard-block here to actually keep users off
104
+ // unsupported versions. Mirrors the 25+ block above. See package.json `engines`.
105
+ if (nodeMajor < node_version_check_1.MIN_NODE_MAJOR) {
106
+ process.stderr.write((0, node_version_check_1.buildNodeTooOldBanner)(nodeVersion) + '\n');
107
+ if (!process.env.CODEGRAPH_ALLOW_UNSAFE_NODE) {
108
+ process.exit(1);
109
+ }
110
+ // Override active — banner shown for visibility, continuing.
111
+ }
112
+ // Re-exec with V8's `--liftoff-only` if it isn't already set, so tree-sitter's
113
+ // large WASM grammars never hit the turboshaft Zone OOM (`Fatal process out of
114
+ // memory: Zone`) on Node >= 22. No-op under the bundled launcher, which already
115
+ // passes the flag. Must run before any grammar (in the parse worker, which
116
+ // inherits this process's flags) is compiled. See ../extraction/wasm-runtime-flags.
117
+ (0, wasm_runtime_flags_1.relaunchWithWasmRuntimeFlagsIfNeeded)(__filename);
118
+ // Check if running with no arguments - run installer
119
+ if (process.argv.length === 2) {
120
+ Promise.resolve().then(() => __importStar(require('../installer'))).then(({ runInstaller }) => runInstaller()).catch((err) => {
121
+ console.error('Installation failed:', err instanceof Error ? err.message : String(err));
122
+ process.exit(1);
123
+ });
124
+ }
125
+ else {
126
+ // Normal CLI flow
127
+ main();
128
+ }
129
+ process.on('uncaughtException', (error) => {
130
+ console.error('[CodeGraph] Uncaught exception:', error);
131
+ });
132
+ process.on('unhandledRejection', (reason) => {
133
+ console.error('[CodeGraph] Unhandled rejection:', reason);
134
+ });
135
+ function main() {
136
+ const program = new commander_1.Command();
137
+ // Version from package.json
138
+ const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf-8'));
139
+ // =============================================================================
140
+ // ANSI Color Helpers (avoid chalk ESM issues)
141
+ // =============================================================================
142
+ const colors = {
143
+ reset: '\x1b[0m',
144
+ bold: '\x1b[1m',
145
+ dim: '\x1b[2m',
146
+ red: '\x1b[31m',
147
+ green: '\x1b[32m',
148
+ yellow: '\x1b[33m',
149
+ blue: '\x1b[34m',
150
+ cyan: '\x1b[36m',
151
+ white: '\x1b[37m',
152
+ gray: '\x1b[90m',
153
+ };
154
+ const chalk = {
155
+ bold: (s) => `${colors.bold}${s}${colors.reset}`,
156
+ dim: (s) => `${colors.dim}${s}${colors.reset}`,
157
+ red: (s) => `${colors.red}${s}${colors.reset}`,
158
+ green: (s) => `${colors.green}${s}${colors.reset}`,
159
+ yellow: (s) => `${colors.yellow}${s}${colors.reset}`,
160
+ blue: (s) => `${colors.blue}${s}${colors.reset}`,
161
+ cyan: (s) => `${colors.cyan}${s}${colors.reset}`,
162
+ white: (s) => `${colors.white}${s}${colors.reset}`,
163
+ gray: (s) => `${colors.gray}${s}${colors.reset}`,
164
+ };
165
+ program
166
+ .name('codegraph')
167
+ .description('Code intelligence and knowledge graph for any codebase')
168
+ .version(packageJson.version);
169
+ // =============================================================================
170
+ // Helper Functions
171
+ // =============================================================================
172
+ /**
173
+ * Resolve project path from argument or current directory
174
+ * Walks up parent directories to find nearest initialized CodeGraph project
175
+ * (must have .codegraph/codegraph.db, not just .codegraph/lessons.db)
176
+ */
177
+ function resolveProjectPath(pathArg) {
178
+ const absolutePath = path.resolve(pathArg || process.cwd());
179
+ // If exact path is initialized (has codegraph.db), use it
180
+ if ((0, directory_1.isInitialized)(absolutePath)) {
181
+ return absolutePath;
182
+ }
183
+ // Walk up to find nearest parent with CodeGraph initialized
184
+ // Note: findNearestCodeGraphRoot finds any .codegraph folder, but we need one with codegraph.db
185
+ let current = absolutePath;
186
+ const root = path.parse(current).root;
187
+ while (current !== root) {
188
+ const parent = path.dirname(current);
189
+ if (parent === current)
190
+ break;
191
+ current = parent;
192
+ if ((0, directory_1.isInitialized)(current)) {
193
+ return current;
194
+ }
195
+ }
196
+ // Not found - return original path (will fail later with helpful error)
197
+ return absolutePath;
198
+ }
199
+ /**
200
+ * Format a number with commas
201
+ */
202
+ function formatNumber(n) {
203
+ return n.toLocaleString();
204
+ }
205
+ /**
206
+ * Format duration in milliseconds to human readable
207
+ */
208
+ function formatDuration(ms) {
209
+ if (ms < 1000) {
210
+ return `${ms}ms`;
211
+ }
212
+ const seconds = ms / 1000;
213
+ if (seconds < 60) {
214
+ return `${seconds.toFixed(1)}s`;
215
+ }
216
+ const minutes = Math.floor(seconds / 60);
217
+ const remainingSeconds = seconds % 60;
218
+ return `${minutes}m ${remainingSeconds.toFixed(0)}s`;
219
+ }
220
+ // Shimmer progress renderer (runs in a worker thread for smooth animation)
221
+ // Imported at top of file from '../ui/shimmer-progress'
222
+ /**
223
+ * Create a plain-text progress callback for --verbose mode.
224
+ * No animations, no ANSI tricks — just timestamped lines to stdout.
225
+ */
226
+ function createVerboseProgress() {
227
+ let lastPhase = '';
228
+ let lastPct = -1;
229
+ const startTime = Date.now();
230
+ return (progress) => {
231
+ const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
232
+ if (progress.phase !== lastPhase) {
233
+ lastPhase = progress.phase;
234
+ lastPct = -1;
235
+ console.log(`[${elapsed}s] Phase: ${progress.phase}`);
236
+ }
237
+ if (progress.total > 0) {
238
+ const pct = Math.floor((progress.current / progress.total) * 100);
239
+ // Log every 5% to keep output manageable
240
+ if (pct >= lastPct + 5 || progress.current === progress.total) {
241
+ lastPct = pct;
242
+ console.log(`[${elapsed}s] ${progress.current}/${progress.total} (${pct}%)${progress.currentFile ? ` ${(0, glyphs_1.getGlyphs)().dash} ${progress.currentFile}` : ''}`);
243
+ }
244
+ }
245
+ else if (progress.current > 0) {
246
+ // Scanning phase (no total yet) — log periodically
247
+ if (progress.current % 1000 === 0 || progress.current === 1) {
248
+ console.log(`[${elapsed}s] ${formatNumber(progress.current)} files found`);
249
+ }
250
+ }
251
+ };
252
+ }
253
+ /**
254
+ * Print success message
255
+ */
256
+ function success(message) {
257
+ console.log(chalk.green((0, glyphs_1.getGlyphs)().ok) + ' ' + message);
258
+ }
259
+ /**
260
+ * Print error message
261
+ */
262
+ function error(message) {
263
+ console.error(chalk.red((0, glyphs_1.getGlyphs)().err) + ' ' + message);
264
+ }
265
+ /**
266
+ * Print info message
267
+ */
268
+ function info(message) {
269
+ console.log(chalk.blue((0, glyphs_1.getGlyphs)().info) + ' ' + message);
270
+ }
271
+ /**
272
+ * Print warning message
273
+ */
274
+ function warn(message) {
275
+ console.log(chalk.yellow((0, glyphs_1.getGlyphs)().warn) + ' ' + message);
276
+ }
277
+ /**
278
+ * Print indexing results using clack log methods
279
+ */
280
+ function printIndexResult(clack, result, projectPath) {
281
+ const hasErrors = result.filesErrored > 0;
282
+ // Surface non-file-level failures (e.g. lock-acquisition failure
283
+ // when another indexer is running) before the file-count branches.
284
+ // Without this the CLI falls through to "No files found to index",
285
+ // which is actively misleading — the index DID run, it just couldn't
286
+ // get the lock.
287
+ //
288
+ // If success is false but no severity:'error' entry exists in
289
+ // `result.errors` (degenerate case — shouldn't happen in practice
290
+ // but worth guarding because the result shape is plumbed through
291
+ // multiple call sites), fall back to a generic message rather than
292
+ // continuing to the misleading "No files found" branch or throwing.
293
+ if (!result.success && !hasErrors && result.filesIndexed === 0) {
294
+ const generic = result.errors.find((e) => e.severity === 'error');
295
+ clack.log.error(generic?.message ?? `Indexing failed ${(0, glyphs_1.getGlyphs)().dash} no further details available`);
296
+ return;
297
+ }
298
+ if (result.filesIndexed > 0) {
299
+ if (hasErrors) {
300
+ clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files (${formatNumber(result.filesErrored)} could not be parsed)`);
301
+ }
302
+ else {
303
+ clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files`);
304
+ }
305
+ clack.log.info(`${formatNumber(result.nodesCreated)} nodes, ${formatNumber(result.edgesCreated)} edges in ${formatDuration(result.durationMs)}`);
306
+ }
307
+ else if (hasErrors) {
308
+ clack.log.error(`Indexing failed ${(0, glyphs_1.getGlyphs)().dash} all ${formatNumber(result.filesErrored)} files had errors`);
309
+ }
310
+ else {
311
+ clack.log.warn('No files found to index');
312
+ }
313
+ if (hasErrors) {
314
+ const errorsByCode = new Map();
315
+ for (const err of result.errors) {
316
+ if (err.severity === 'error') {
317
+ const code = err.code || 'unknown';
318
+ errorsByCode.set(code, (errorsByCode.get(code) || 0) + 1);
319
+ }
320
+ }
321
+ const codeLabels = {
322
+ parse_error: 'files failed to parse',
323
+ read_error: 'files could not be read',
324
+ size_exceeded: 'files exceeded size limit',
325
+ path_traversal: 'blocked paths',
326
+ unsupported_language: 'unsupported language',
327
+ parser_error: 'parser initialization failures',
328
+ };
329
+ const breakdown = Array.from(errorsByCode)
330
+ .map(([code, count]) => `${formatNumber(count)} ${codeLabels[code] || code}`)
331
+ .join('\n');
332
+ clack.note(breakdown, 'Error breakdown');
333
+ if (projectPath) {
334
+ writeErrorLog(projectPath, result.errors);
335
+ clack.log.info('See .codegraph/errors.log for details');
336
+ }
337
+ if (result.filesIndexed > 0) {
338
+ clack.log.info(`The index is fully usable ${(0, glyphs_1.getGlyphs)().dash} only the failed files are missing.`);
339
+ }
340
+ }
341
+ else if (projectPath) {
342
+ const logPath = path.join((0, directory_1.getCodeGraphDir)(projectPath), 'errors.log');
343
+ if (fs.existsSync(logPath)) {
344
+ fs.unlinkSync(logPath);
345
+ }
346
+ }
347
+ }
348
+ /**
349
+ * Write detailed error log to knowledge/codegraph/errors.log
350
+ */
351
+ function writeErrorLog(projectPath, errors) {
352
+ const cgDir = (0, directory_1.getCodeGraphDir)(projectPath);
353
+ if (!fs.existsSync(cgDir))
354
+ return;
355
+ const logPath = path.join(cgDir, 'errors.log');
356
+ // Group errors by file path
357
+ const errorsByFile = new Map();
358
+ const noFileErrors = [];
359
+ for (const err of errors) {
360
+ if (err.severity !== 'error')
361
+ continue;
362
+ if (err.filePath) {
363
+ let list = errorsByFile.get(err.filePath);
364
+ if (!list) {
365
+ list = [];
366
+ errorsByFile.set(err.filePath, list);
367
+ }
368
+ list.push({ message: err.message, code: err.code });
369
+ }
370
+ else {
371
+ noFileErrors.push({ message: err.message, code: err.code });
372
+ }
373
+ }
374
+ const lines = [
375
+ `CodeGraph Error Log - ${new Date().toISOString()}`,
376
+ `${errorsByFile.size} files with errors`,
377
+ '',
378
+ ];
379
+ for (const [filePath, fileErrors] of errorsByFile) {
380
+ for (const err of fileErrors) {
381
+ lines.push(`${filePath}: ${err.message}`);
382
+ }
383
+ }
384
+ for (const err of noFileErrors) {
385
+ lines.push(err.message);
386
+ }
387
+ fs.writeFileSync(logPath, lines.join('\n') + '\n');
388
+ }
389
+ // =============================================================================
390
+ // Commands
391
+ // =============================================================================
392
+ /**
393
+ * codegraph init [path]
394
+ */
395
+ program
396
+ .command('init [path]')
397
+ .description('Initialize CodeGraph in a project directory')
398
+ .option('-i, --index', 'Run initial indexing after initialization')
399
+ .option('-v, --verbose', 'Show detailed worker lifecycle and memory info')
400
+ .action(async (pathArg, options) => {
401
+ const projectPath = path.resolve(pathArg || process.cwd());
402
+ const clack = await importESM('@clack/prompts');
403
+ clack.intro('Initializing CodeGraph');
404
+ try {
405
+ if ((0, directory_1.isInitialized)(projectPath)) {
406
+ clack.log.warn(`Already initialized in ${projectPath}`);
407
+ clack.log.info('Use "codegraph index" to re-index or "codegraph sync" to update');
408
+ // Re-run agent surface wiring so re-running `init` is the
409
+ // documented way to recover a project that's missing its
410
+ // Cursor rules file (or future per-agent project surfaces).
411
+ try {
412
+ const { wireProjectSurfacesForGlobalAgents } = await Promise.resolve().then(() => __importStar(require('../installer')));
413
+ for (const { target, file } of wireProjectSurfacesForGlobalAgents()) {
414
+ clack.log.success(`${target.displayName}: ${file.action} ${file.path}`);
415
+ }
416
+ }
417
+ catch { /* non-fatal */ }
418
+ try {
419
+ const { offerWatchFallback } = await Promise.resolve().then(() => __importStar(require('../installer')));
420
+ await offerWatchFallback(clack, projectPath);
421
+ }
422
+ catch { /* non-fatal */ }
423
+ clack.outro('');
424
+ return;
425
+ }
426
+ const { default: CodeGraph } = await loadCodeGraph();
427
+ const cg = await CodeGraph.init(projectPath, { index: false });
428
+ clack.log.success(`Initialized in ${projectPath}`);
429
+ // Bootstrap project-local surfaces for any agent that's
430
+ // configured globally (Cursor needs ./.cursor/rules/codegraph.mdc
431
+ // to actually prefer codegraph over native grep). Silent when
432
+ // there's nothing to write.
433
+ try {
434
+ const { wireProjectSurfacesForGlobalAgents } = await Promise.resolve().then(() => __importStar(require('../installer')));
435
+ for (const { target, file } of wireProjectSurfacesForGlobalAgents()) {
436
+ clack.log.success(`${target.displayName}: ${file.action} ${file.path}`);
437
+ }
438
+ }
439
+ catch (err) {
440
+ const msg = err instanceof Error ? err.message : String(err);
441
+ clack.log.warn(`Skipped wiring project-local agent surfaces: ${msg}`);
442
+ }
443
+ if (options.index) {
444
+ let result;
445
+ if (options.verbose) {
446
+ result = await cg.indexAll({
447
+ onProgress: createVerboseProgress(),
448
+ verbose: true,
449
+ });
450
+ }
451
+ else {
452
+ process.stdout.write(`${colors.dim}${(0, glyphs_1.getGlyphs)().rail}${colors.reset}\n`);
453
+ const progress = (0, shimmer_progress_1.createShimmerProgress)();
454
+ result = await cg.indexAll({
455
+ onProgress: progress.onProgress,
456
+ });
457
+ await progress.stop();
458
+ }
459
+ printIndexResult(clack, result, projectPath);
460
+ }
461
+ else {
462
+ clack.log.info('Run "codegraph index" to index the project');
463
+ }
464
+ try {
465
+ const { offerWatchFallback } = await Promise.resolve().then(() => __importStar(require('../installer')));
466
+ await offerWatchFallback(clack, projectPath);
467
+ }
468
+ catch { /* non-fatal */ }
469
+ clack.outro('Done');
470
+ cg.destroy();
471
+ }
472
+ catch (err) {
473
+ clack.log.error(`Failed: ${err instanceof Error ? err.message : String(err)}`);
474
+ process.exit(1);
475
+ }
476
+ });
477
+ /**
478
+ * codegraph uninit [path]
479
+ */
480
+ program
481
+ .command('uninit [path]')
482
+ .description('Remove CodeGraph from a project (deletes .codegraph/ directory)')
483
+ .option('-f, --force', 'Skip confirmation prompt')
484
+ .action(async (pathArg, options) => {
485
+ const projectPath = resolveProjectPath(pathArg);
486
+ try {
487
+ if (!(0, directory_1.isInitialized)(projectPath)) {
488
+ warn(`CodeGraph is not initialized in ${projectPath}`);
489
+ return;
490
+ }
491
+ if (!options.force) {
492
+ // Confirm with user
493
+ const readline = await Promise.resolve().then(() => __importStar(require('readline')));
494
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
495
+ const answer = await new Promise((resolve) => {
496
+ rl.question(chalk.yellow(`${(0, glyphs_1.getGlyphs)().warn} This will permanently delete all CodeGraph data. Continue? (y/N) `), resolve);
497
+ });
498
+ rl.close();
499
+ if (answer.toLowerCase() !== 'y') {
500
+ info('Cancelled');
501
+ return;
502
+ }
503
+ }
504
+ const { default: CodeGraph } = await loadCodeGraph();
505
+ const cg = CodeGraph.openSync(projectPath);
506
+ cg.uninitialize();
507
+ // Clean up any git sync hooks we installed (no-op if none / not a repo).
508
+ try {
509
+ const { removeGitSyncHook } = await Promise.resolve().then(() => __importStar(require('../sync/git-hooks')));
510
+ const removed = removeGitSyncHook(projectPath);
511
+ if (removed.installed.length > 0) {
512
+ info(`Removed git ${removed.installed.join(', ')} sync hook${removed.installed.length > 1 ? 's' : ''}`);
513
+ }
514
+ }
515
+ catch { /* non-fatal */ }
516
+ success(`Removed CodeGraph from ${projectPath}`);
517
+ }
518
+ catch (err) {
519
+ error(`Failed to uninitialize: ${err instanceof Error ? err.message : String(err)}`);
520
+ process.exit(1);
521
+ }
522
+ });
523
+ /**
524
+ * codegraph index [path]
525
+ */
526
+ program
527
+ .command('index [path]')
528
+ .description('Index all files in the project')
529
+ .option('-f, --force', 'Force full re-index even if already indexed')
530
+ .option('-q, --quiet', 'Suppress progress output')
531
+ .option('-v, --verbose', 'Show detailed worker lifecycle and memory info')
532
+ .action(async (pathArg, options) => {
533
+ const projectPath = resolveProjectPath(pathArg);
534
+ try {
535
+ if (!(0, directory_1.isInitialized)(projectPath)) {
536
+ error(`CodeGraph not initialized in ${projectPath}`);
537
+ info('Run "codegraph init" first');
538
+ process.exit(1);
539
+ }
540
+ const { default: CodeGraph } = await loadCodeGraph();
541
+ const cg = await CodeGraph.open(projectPath);
542
+ if (options.quiet) {
543
+ // Quiet mode: no UI, just run
544
+ if (options.force)
545
+ cg.clear();
546
+ const result = await cg.indexAll();
547
+ if (!result.success)
548
+ process.exit(1);
549
+ cg.destroy();
550
+ return;
551
+ }
552
+ const clack = await importESM('@clack/prompts');
553
+ clack.intro('Indexing project');
554
+ if (options.force) {
555
+ cg.clear();
556
+ clack.log.info('Cleared existing index');
557
+ }
558
+ let result;
559
+ if (options.verbose) {
560
+ result = await cg.indexAll({
561
+ onProgress: createVerboseProgress(),
562
+ verbose: true,
563
+ });
564
+ }
565
+ else {
566
+ process.stdout.write(`${colors.dim}${(0, glyphs_1.getGlyphs)().rail}${colors.reset}\n`);
567
+ const progress = (0, shimmer_progress_1.createShimmerProgress)();
568
+ result = await cg.indexAll({
569
+ onProgress: progress.onProgress,
570
+ });
571
+ await progress.stop();
572
+ }
573
+ printIndexResult(clack, result, projectPath);
574
+ if (!result.success) {
575
+ process.exit(1);
576
+ }
577
+ clack.outro('Done');
578
+ cg.destroy();
579
+ }
580
+ catch (err) {
581
+ error(`Failed to index: ${err instanceof Error ? err.message : String(err)}`);
582
+ process.exit(1);
583
+ }
584
+ });
585
+ /**
586
+ * codegraph sync [path]
587
+ */
588
+ program
589
+ .command('sync [path]')
590
+ .description('Sync changes since last index')
591
+ .option('-q, --quiet', 'Suppress output (for git hooks)')
592
+ .action(async (pathArg, options) => {
593
+ const projectPath = resolveProjectPath(pathArg);
594
+ try {
595
+ if (!(0, directory_1.isInitialized)(projectPath)) {
596
+ if (!options.quiet) {
597
+ error(`CodeGraph not initialized in ${projectPath}`);
598
+ }
599
+ process.exit(1);
600
+ }
601
+ const { default: CodeGraph } = await loadCodeGraph();
602
+ const cg = await CodeGraph.open(projectPath);
603
+ if (options.quiet) {
604
+ await cg.sync();
605
+ cg.destroy();
606
+ return;
607
+ }
608
+ const clack = await importESM('@clack/prompts');
609
+ clack.intro('Syncing CodeGraph');
610
+ process.stdout.write(`${colors.dim}${(0, glyphs_1.getGlyphs)().rail}${colors.reset}\n`);
611
+ const progress = (0, shimmer_progress_1.createShimmerProgress)();
612
+ const result = await cg.sync({
613
+ onProgress: progress.onProgress,
614
+ });
615
+ await progress.stop();
616
+ const totalChanges = result.filesAdded + result.filesModified + result.filesRemoved;
617
+ if (totalChanges === 0) {
618
+ clack.log.info('Already up to date');
619
+ }
620
+ else {
621
+ clack.log.success(`Synced ${formatNumber(totalChanges)} changed files`);
622
+ const details = [];
623
+ if (result.filesAdded > 0)
624
+ details.push(`Added: ${result.filesAdded}`);
625
+ if (result.filesModified > 0)
626
+ details.push(`Modified: ${result.filesModified}`);
627
+ if (result.filesRemoved > 0)
628
+ details.push(`Removed: ${result.filesRemoved}`);
629
+ clack.log.info(`${details.join(', ')} ${(0, glyphs_1.getGlyphs)().dash} ${formatNumber(result.nodesUpdated)} nodes in ${formatDuration(result.durationMs)}`);
630
+ }
631
+ clack.outro('Done');
632
+ cg.destroy();
633
+ }
634
+ catch (err) {
635
+ if (!options.quiet) {
636
+ error(`Failed to sync: ${err instanceof Error ? err.message : String(err)}`);
637
+ }
638
+ process.exit(1);
639
+ }
640
+ });
641
+ /**
642
+ * codegraph status [path]
643
+ */
644
+ program
645
+ .command('status [path]')
646
+ .description('Show index status and statistics')
647
+ .option('-j, --json', 'Output as JSON')
648
+ .action(async (pathArg, options) => {
649
+ const projectPath = resolveProjectPath(pathArg);
650
+ // The directory the user actually ran from, before walking up to the index
651
+ // root. Used to detect when the resolved index lives in a different git
652
+ // working tree (e.g. a nested worktree borrowing the main checkout's index).
653
+ const startPath = path.resolve(pathArg || process.cwd());
654
+ const worktreeMismatch = (0, worktree_1.detectWorktreeIndexMismatch)(startPath, projectPath);
655
+ try {
656
+ if (!(0, directory_1.isInitialized)(projectPath)) {
657
+ if (options.json) {
658
+ console.log(JSON.stringify({ initialized: false, projectPath }));
659
+ return;
660
+ }
661
+ console.log(chalk.bold('\nCodeGraph Status\n'));
662
+ info(`Project: ${projectPath}`);
663
+ warn('Not initialized');
664
+ info('Run "codegraph init" to initialize');
665
+ return;
666
+ }
667
+ const { default: CodeGraph } = await loadCodeGraph();
668
+ const cg = await CodeGraph.open(projectPath);
669
+ const stats = cg.getStats();
670
+ const changes = cg.getChangedFiles();
671
+ const backend = cg.getBackend();
672
+ const journalMode = cg.getJournalMode();
673
+ // JSON output mode
674
+ if (options.json) {
675
+ console.log(JSON.stringify({
676
+ initialized: true,
677
+ projectPath,
678
+ fileCount: stats.fileCount,
679
+ nodeCount: stats.nodeCount,
680
+ edgeCount: stats.edgeCount,
681
+ dbSizeBytes: stats.dbSizeBytes,
682
+ backend,
683
+ journalMode,
684
+ nodesByKind: stats.nodesByKind,
685
+ languages: Object.entries(stats.filesByLanguage).filter(([, count]) => count > 0).map(([lang]) => lang),
686
+ pendingChanges: {
687
+ added: changes.added.length,
688
+ modified: changes.modified.length,
689
+ removed: changes.removed.length,
690
+ },
691
+ worktreeMismatch: worktreeMismatch
692
+ ? { worktreeRoot: worktreeMismatch.worktreeRoot, indexRoot: worktreeMismatch.indexRoot }
693
+ : null,
694
+ }));
695
+ cg.destroy();
696
+ return;
697
+ }
698
+ console.log(chalk.bold('\nCodeGraph Status\n'));
699
+ // Project info
700
+ console.log(chalk.cyan('Project:'), projectPath);
701
+ if (worktreeMismatch) {
702
+ warn((0, worktree_1.worktreeMismatchWarning)(worktreeMismatch));
703
+ }
704
+ console.log();
705
+ // Index stats
706
+ console.log(chalk.bold('Index Statistics:'));
707
+ console.log(` Files: ${formatNumber(stats.fileCount)}`);
708
+ console.log(` Nodes: ${formatNumber(stats.nodeCount)}`);
709
+ console.log(` Edges: ${formatNumber(stats.edgeCount)}`);
710
+ console.log(` DB Size: ${(stats.dbSizeBytes / 1024 / 1024).toFixed(2)} MB`);
711
+ // Surface the active SQLite backend (node:sqlite — Node's built-in real
712
+ // SQLite, full WAL + FTS5, no native build).
713
+ const backendLabel = chalk.green(`node:sqlite ${(0, glyphs_1.getGlyphs)().dash} built-in (full WAL)`);
714
+ console.log(` Backend: ${backendLabel}`);
715
+ // Effective journal mode: 'wal' means concurrent reads never block on a
716
+ // writer; anything else means they can ("database is locked"). node:sqlite
717
+ // supports WAL everywhere, so a non-wal mode means the filesystem can't
718
+ // (network mounts, WSL2 /mnt). See issue #238.
719
+ const journalLabel = journalMode === 'wal'
720
+ ? chalk.green('wal')
721
+ : chalk.yellow(`${journalMode || 'unknown'} ${(0, glyphs_1.getGlyphs)().dash} WAL inactive; reads can block on writes`);
722
+ console.log(` Journal: ${journalLabel}`);
723
+ console.log();
724
+ // Node breakdown
725
+ console.log(chalk.bold('Nodes by Kind:'));
726
+ const nodesByKind = Object.entries(stats.nodesByKind)
727
+ .filter(([, count]) => count > 0)
728
+ .sort((a, b) => b[1] - a[1]);
729
+ for (const [kind, count] of nodesByKind) {
730
+ console.log(` ${kind.padEnd(15)} ${formatNumber(count)}`);
731
+ }
732
+ console.log();
733
+ // Language breakdown
734
+ console.log(chalk.bold('Files by Language:'));
735
+ const filesByLang = Object.entries(stats.filesByLanguage)
736
+ .filter(([, count]) => count > 0)
737
+ .sort((a, b) => b[1] - a[1]);
738
+ for (const [lang, count] of filesByLang) {
739
+ console.log(` ${lang.padEnd(15)} ${formatNumber(count)}`);
740
+ }
741
+ console.log();
742
+ // Pending changes
743
+ const totalChanges = changes.added.length + changes.modified.length + changes.removed.length;
744
+ if (totalChanges > 0) {
745
+ console.log(chalk.bold('Pending Changes:'));
746
+ if (changes.added.length > 0) {
747
+ console.log(` Added: ${changes.added.length} files`);
748
+ }
749
+ if (changes.modified.length > 0) {
750
+ console.log(` Modified: ${changes.modified.length} files`);
751
+ }
752
+ if (changes.removed.length > 0) {
753
+ console.log(` Removed: ${changes.removed.length} files`);
754
+ }
755
+ info('Run "codegraph sync" to update the index');
756
+ }
757
+ else {
758
+ success('Index is up to date');
759
+ }
760
+ console.log();
761
+ cg.destroy();
762
+ }
763
+ catch (err) {
764
+ error(`Failed to get status: ${err instanceof Error ? err.message : String(err)}`);
765
+ process.exit(1);
766
+ }
767
+ });
768
+ /**
769
+ * codegraph query <search>
770
+ */
771
+ program
772
+ .command('query <search>')
773
+ .description('Search for symbols in the codebase')
774
+ .option('-p, --path <path>', 'Project path')
775
+ .option('-l, --limit <number>', 'Maximum results', '10')
776
+ .option('-k, --kind <kind>', 'Filter by node kind (function, class, etc.)')
777
+ .option('-j, --json', 'Output as JSON')
778
+ .action(async (search, options) => {
779
+ const projectPath = resolveProjectPath(options.path);
780
+ try {
781
+ if (!(0, directory_1.isInitialized)(projectPath)) {
782
+ error(`CodeGraph not initialized in ${projectPath}`);
783
+ process.exit(1);
784
+ }
785
+ const { default: CodeGraph } = await loadCodeGraph();
786
+ const cg = await CodeGraph.open(projectPath);
787
+ const limit = parseInt(options.limit || '10', 10);
788
+ const results = cg.searchNodes(search, {
789
+ limit,
790
+ kinds: options.kind ? [options.kind] : undefined,
791
+ });
792
+ if (options.json) {
793
+ console.log(JSON.stringify(results, null, 2));
794
+ }
795
+ else {
796
+ if (results.length === 0) {
797
+ info(`No results found for "${search}"`);
798
+ }
799
+ else {
800
+ console.log(chalk.bold(`\nSearch Results for "${search}":\n`));
801
+ for (const result of results) {
802
+ const node = result.node;
803
+ const location = `${node.filePath}:${node.startLine}`;
804
+ const score = chalk.dim(`(${(result.score * 100).toFixed(0)}%)`);
805
+ console.log(chalk.cyan(node.kind.padEnd(12)) +
806
+ chalk.white(node.name) +
807
+ ' ' + score);
808
+ console.log(chalk.dim(` ${location}`));
809
+ if (node.signature) {
810
+ console.log(chalk.dim(` ${node.signature}`));
811
+ }
812
+ console.log();
813
+ }
814
+ }
815
+ }
816
+ cg.destroy();
817
+ }
818
+ catch (err) {
819
+ error(`Search failed: ${err instanceof Error ? err.message : String(err)}`);
820
+ process.exit(1);
821
+ }
822
+ });
823
+ /**
824
+ * codegraph files [path]
825
+ */
826
+ program
827
+ .command('files')
828
+ .description('Show project file structure from the index')
829
+ .option('-p, --path <path>', 'Project path')
830
+ .option('--filter <dir>', 'Filter to files under this directory')
831
+ .option('--pattern <glob>', 'Filter files matching this glob pattern')
832
+ .option('--format <format>', 'Output format (tree, flat, grouped)', 'tree')
833
+ .option('--max-depth <number>', 'Maximum directory depth for tree format')
834
+ .option('--no-metadata', 'Hide file metadata (language, symbol count)')
835
+ .option('-j, --json', 'Output as JSON')
836
+ .action(async (options) => {
837
+ const projectPath = resolveProjectPath(options.path);
838
+ try {
839
+ if (!(0, directory_1.isInitialized)(projectPath)) {
840
+ error(`CodeGraph not initialized in ${projectPath}`);
841
+ process.exit(1);
842
+ }
843
+ const { default: CodeGraph } = await loadCodeGraph();
844
+ const cg = await CodeGraph.open(projectPath);
845
+ let files = cg.getFiles();
846
+ if (files.length === 0) {
847
+ info('No files indexed. Run "codegraph index" first.');
848
+ cg.destroy();
849
+ return;
850
+ }
851
+ // Filter by path prefix
852
+ if (options.filter) {
853
+ const filter = options.filter;
854
+ files = files.filter(f => f.path.startsWith(filter) || f.path.startsWith('./' + filter));
855
+ }
856
+ // Filter by glob pattern
857
+ if (options.pattern) {
858
+ const regex = globToRegex(options.pattern);
859
+ files = files.filter(f => regex.test(f.path));
860
+ }
861
+ if (files.length === 0) {
862
+ info('No files found matching the criteria.');
863
+ cg.destroy();
864
+ return;
865
+ }
866
+ // JSON output
867
+ if (options.json) {
868
+ const output = files.map(f => ({
869
+ path: f.path,
870
+ language: f.language,
871
+ nodeCount: f.nodeCount,
872
+ size: f.size,
873
+ }));
874
+ console.log(JSON.stringify(output, null, 2));
875
+ cg.destroy();
876
+ return;
877
+ }
878
+ const includeMetadata = options.metadata !== false;
879
+ const format = options.format || 'tree';
880
+ const maxDepth = options.maxDepth ? parseInt(options.maxDepth, 10) : undefined;
881
+ // Format output
882
+ switch (format) {
883
+ case 'flat':
884
+ console.log(chalk.bold(`\nFiles (${files.length}):\n`));
885
+ for (const file of files.sort((a, b) => a.path.localeCompare(b.path))) {
886
+ if (includeMetadata) {
887
+ console.log(` ${file.path} ${chalk.dim(`(${file.language}, ${file.nodeCount} symbols)`)}`);
888
+ }
889
+ else {
890
+ console.log(` ${file.path}`);
891
+ }
892
+ }
893
+ break;
894
+ case 'grouped':
895
+ console.log(chalk.bold(`\nFiles by Language (${files.length} total):\n`));
896
+ const byLang = new Map();
897
+ for (const file of files) {
898
+ const existing = byLang.get(file.language) || [];
899
+ existing.push(file);
900
+ byLang.set(file.language, existing);
901
+ }
902
+ const sortedLangs = [...byLang.entries()].sort((a, b) => b[1].length - a[1].length);
903
+ for (const [lang, langFiles] of sortedLangs) {
904
+ console.log(chalk.cyan(`${lang} (${langFiles.length}):`));
905
+ for (const file of langFiles.sort((a, b) => a.path.localeCompare(b.path))) {
906
+ if (includeMetadata) {
907
+ console.log(` ${file.path} ${chalk.dim(`(${file.nodeCount} symbols)`)}`);
908
+ }
909
+ else {
910
+ console.log(` ${file.path}`);
911
+ }
912
+ }
913
+ console.log();
914
+ }
915
+ break;
916
+ case 'tree':
917
+ default:
918
+ console.log(chalk.bold(`\nProject Structure (${files.length} files):\n`));
919
+ printFileTree(files, includeMetadata, maxDepth, chalk);
920
+ break;
921
+ }
922
+ console.log();
923
+ cg.destroy();
924
+ }
925
+ catch (err) {
926
+ error(`Failed to list files: ${err instanceof Error ? err.message : String(err)}`);
927
+ process.exit(1);
928
+ }
929
+ });
930
+ /**
931
+ * Convert glob pattern to regex
932
+ */
933
+ function globToRegex(pattern) {
934
+ const escaped = pattern
935
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
936
+ .replace(/\*\*/g, '{{GLOBSTAR}}')
937
+ .replace(/\*/g, '[^/]*')
938
+ .replace(/\?/g, '[^/]')
939
+ .replace(/\{\{GLOBSTAR\}\}/g, '.*');
940
+ return new RegExp(escaped);
941
+ }
942
+ /**
943
+ * Print files as a tree
944
+ */
945
+ function printFileTree(files, includeMetadata, maxDepth, chalk) {
946
+ const root = { name: '', children: new Map() };
947
+ for (const file of files) {
948
+ const parts = file.path.split('/');
949
+ let current = root;
950
+ for (let i = 0; i < parts.length; i++) {
951
+ const part = parts[i];
952
+ if (!part)
953
+ continue;
954
+ if (!current.children.has(part)) {
955
+ current.children.set(part, { name: part, children: new Map() });
956
+ }
957
+ current = current.children.get(part);
958
+ if (i === parts.length - 1) {
959
+ current.file = { language: file.language, nodeCount: file.nodeCount };
960
+ }
961
+ }
962
+ }
963
+ const renderNode = (node, prefix, isLast, depth) => {
964
+ if (maxDepth !== undefined && depth > maxDepth)
965
+ return;
966
+ const glyphs = (0, glyphs_1.getGlyphs)();
967
+ const connector = isLast ? glyphs.treeLast : glyphs.treeBranch;
968
+ const childPrefix = isLast ? ' ' : glyphs.treePipe;
969
+ if (node.name) {
970
+ let line = prefix + connector + node.name;
971
+ if (node.file && includeMetadata) {
972
+ line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`);
973
+ }
974
+ console.log(line);
975
+ }
976
+ const children = [...node.children.values()];
977
+ children.sort((a, b) => {
978
+ const aIsDir = a.children.size > 0 && !a.file;
979
+ const bIsDir = b.children.size > 0 && !b.file;
980
+ if (aIsDir !== bIsDir)
981
+ return aIsDir ? -1 : 1;
982
+ return a.name.localeCompare(b.name);
983
+ });
984
+ for (let i = 0; i < children.length; i++) {
985
+ const child = children[i];
986
+ const nextPrefix = node.name ? prefix + childPrefix : prefix;
987
+ renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
988
+ }
989
+ };
990
+ renderNode(root, '', true, 0);
991
+ }
992
+ /**
993
+ * codegraph context <task>
994
+ */
995
+ program
996
+ .command('context <task>')
997
+ .description('Build context for a task (outputs markdown)')
998
+ .option('-p, --path <path>', 'Project path')
999
+ .option('-n, --max-nodes <number>', 'Maximum nodes to include', '50')
1000
+ .option('-c, --max-code <number>', 'Maximum code blocks', '10')
1001
+ .option('--no-code', 'Exclude code blocks')
1002
+ .option('-f, --format <format>', 'Output format (markdown, json)', 'markdown')
1003
+ .action(async (task, options) => {
1004
+ const projectPath = resolveProjectPath(options.path);
1005
+ try {
1006
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1007
+ error(`CodeGraph not initialized in ${projectPath}`);
1008
+ process.exit(1);
1009
+ }
1010
+ const { default: CodeGraph } = await loadCodeGraph();
1011
+ const cg = await CodeGraph.open(projectPath);
1012
+ const context = await cg.buildContext(task, {
1013
+ maxNodes: parseInt(options.maxNodes || '50', 10),
1014
+ maxCodeBlocks: parseInt(options.maxCode || '10', 10),
1015
+ includeCode: options.code !== false,
1016
+ format: options.format,
1017
+ });
1018
+ // Output the context
1019
+ console.log(context);
1020
+ cg.destroy();
1021
+ }
1022
+ catch (err) {
1023
+ error(`Failed to build context: ${err instanceof Error ? err.message : String(err)}`);
1024
+ process.exit(1);
1025
+ }
1026
+ });
1027
+ /**
1028
+ * codegraph serve
1029
+ */
1030
+ program
1031
+ .command('serve')
1032
+ .description('Start CodeGraph as an MCP server for AI assistants')
1033
+ .option('-p, --path <path>', 'Project path (optional for MCP mode, uses rootUri from client)')
1034
+ .option('--mcp', 'Run as MCP server (stdio transport)')
1035
+ .option('--no-watch', 'Disable the file watcher (no auto-sync; useful on slow filesystems like WSL2 /mnt drives)')
1036
+ .action(async (options) => {
1037
+ const projectPath = options.path ? resolveProjectPath(options.path) : undefined;
1038
+ // Commander sets watch=false when --no-watch is passed. Route it through
1039
+ // the same env-var chokepoint the watcher and MCP server already honor.
1040
+ if (options.watch === false) {
1041
+ process.env.CODEGRAPH_NO_WATCH = '1';
1042
+ }
1043
+ try {
1044
+ if (options.mcp) {
1045
+ // Start MCP server - it handles initialization lazily based on rootUri from client
1046
+ const { MCPServer } = await Promise.resolve().then(() => __importStar(require('../mcp/index')));
1047
+ const server = new MCPServer(projectPath);
1048
+ await server.start();
1049
+ // Server will run until terminated
1050
+ }
1051
+ else {
1052
+ // Default: show info about MCP mode.
1053
+ // Use stderr so stdout stays clean for any piped/stdio usage.
1054
+ console.error(chalk.bold('\nCodeGraph MCP Server\n'));
1055
+ console.error(chalk.blue((0, glyphs_1.getGlyphs)().info) + ' Use --mcp flag to start the MCP server');
1056
+ console.error('\nTo use with Claude Code, add to your MCP configuration:');
1057
+ console.error(chalk.dim(`
1058
+ {
1059
+ "mcpServers": {
1060
+ "codegraph": {
1061
+ "command": "codegraph",
1062
+ "args": ["serve", "--mcp"]
1063
+ }
1064
+ }
1065
+ }
1066
+ `));
1067
+ console.error('Available tools:');
1068
+ console.error(chalk.cyan(' codegraph_search') + ' - Search for code symbols');
1069
+ console.error(chalk.cyan(' codegraph_context') + ' - Build context for a task');
1070
+ console.error(chalk.cyan(' codegraph_callers') + ' - Find callers of a symbol');
1071
+ console.error(chalk.cyan(' codegraph_callees') + ' - Find what a symbol calls');
1072
+ console.error(chalk.cyan(' codegraph_impact') + ' - Analyze impact of changes');
1073
+ console.error(chalk.cyan(' codegraph_node') + ' - Get symbol details');
1074
+ console.error(chalk.cyan(' codegraph_files') + ' - Get project file structure');
1075
+ console.error(chalk.cyan(' codegraph_status') + ' - Get index status');
1076
+ }
1077
+ }
1078
+ catch (err) {
1079
+ error(`Failed to start server: ${err instanceof Error ? err.message : String(err)}`);
1080
+ process.exit(1);
1081
+ }
1082
+ });
1083
+ /**
1084
+ * codegraph unlock [path]
1085
+ */
1086
+ program
1087
+ .command('unlock [path]')
1088
+ .description('Remove a stale lock file that is blocking indexing')
1089
+ .action(async (pathArg) => {
1090
+ const projectPath = resolveProjectPath(pathArg);
1091
+ try {
1092
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1093
+ error(`CodeGraph not initialized in ${projectPath}`);
1094
+ return;
1095
+ }
1096
+ const lockPath = path.join((0, directory_1.getCodeGraphDir)(projectPath), 'codegraph.lock');
1097
+ if (!fs.existsSync(lockPath)) {
1098
+ info(`No lock file found ${(0, glyphs_1.getGlyphs)().dash} nothing to do`);
1099
+ return;
1100
+ }
1101
+ fs.unlinkSync(lockPath);
1102
+ success('Removed lock file. You can now run indexing again.');
1103
+ }
1104
+ catch (err) {
1105
+ error(`Failed to remove lock: ${err instanceof Error ? err.message : String(err)}`);
1106
+ process.exit(1);
1107
+ }
1108
+ });
1109
+ /**
1110
+ * codegraph callers <symbol>
1111
+ *
1112
+ * CLI parity with the MCP graph tools (codegraph_callers/callees/impact) so the
1113
+ * traversal queries work in scripts, CI, and git hooks without a running MCP
1114
+ * server.
1115
+ */
1116
+ program
1117
+ .command('callers <symbol>')
1118
+ .description('Find all functions/methods that call a specific symbol')
1119
+ .option('-p, --path <path>', 'Project path')
1120
+ .option('-l, --limit <number>', 'Maximum results', '20')
1121
+ .option('-j, --json', 'Output as JSON')
1122
+ .action(async (symbol, options) => {
1123
+ const projectPath = resolveProjectPath(options.path);
1124
+ try {
1125
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1126
+ error(`CodeGraph not initialized in ${projectPath}`);
1127
+ process.exit(1);
1128
+ }
1129
+ const { default: CodeGraph } = await loadCodeGraph();
1130
+ const cg = await CodeGraph.open(projectPath);
1131
+ const limit = parseInt(options.limit || '20', 10);
1132
+ const matches = cg.searchNodes(symbol, { limit: 50 });
1133
+ if (matches.length === 0) {
1134
+ info(`Symbol "${symbol}" not found`);
1135
+ cg.destroy();
1136
+ return;
1137
+ }
1138
+ const seen = new Set();
1139
+ const allCallers = [];
1140
+ for (const match of matches) {
1141
+ const exactMatch = match.node.name === symbol || match.node.name.endsWith(`.${symbol}`) || match.node.name.endsWith(`::${symbol}`);
1142
+ if (!exactMatch && matches.length > 1)
1143
+ continue;
1144
+ for (const c of cg.getCallers(match.node.id)) {
1145
+ if (!seen.has(c.node.id)) {
1146
+ seen.add(c.node.id);
1147
+ allCallers.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1148
+ }
1149
+ }
1150
+ }
1151
+ // Fallback: if exact filter removed everything, use the top match
1152
+ if (allCallers.length === 0 && matches[0]) {
1153
+ for (const c of cg.getCallers(matches[0].node.id)) {
1154
+ if (!seen.has(c.node.id)) {
1155
+ seen.add(c.node.id);
1156
+ allCallers.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1157
+ }
1158
+ }
1159
+ }
1160
+ const limited = allCallers.slice(0, limit);
1161
+ if (options.json) {
1162
+ console.log(JSON.stringify({ symbol, callers: limited }, null, 2));
1163
+ }
1164
+ else if (limited.length === 0) {
1165
+ info(`No callers found for "${symbol}"`);
1166
+ }
1167
+ else {
1168
+ console.log(chalk.bold(`\nCallers of "${symbol}" (${limited.length}):\n`));
1169
+ for (const node of limited) {
1170
+ const loc = node.startLine ? `:${node.startLine}` : '';
1171
+ console.log(chalk.cyan(node.kind.padEnd(12)) +
1172
+ chalk.white(node.name));
1173
+ console.log(chalk.dim(` ${node.filePath}${loc}`));
1174
+ console.log();
1175
+ }
1176
+ }
1177
+ cg.destroy();
1178
+ }
1179
+ catch (err) {
1180
+ error(`callers failed: ${err instanceof Error ? err.message : String(err)}`);
1181
+ process.exit(1);
1182
+ }
1183
+ });
1184
+ /**
1185
+ * codegraph callees <symbol>
1186
+ */
1187
+ program
1188
+ .command('callees <symbol>')
1189
+ .description('Find all functions/methods that a specific symbol calls')
1190
+ .option('-p, --path <path>', 'Project path')
1191
+ .option('-l, --limit <number>', 'Maximum results', '20')
1192
+ .option('-j, --json', 'Output as JSON')
1193
+ .action(async (symbol, options) => {
1194
+ const projectPath = resolveProjectPath(options.path);
1195
+ try {
1196
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1197
+ error(`CodeGraph not initialized in ${projectPath}`);
1198
+ process.exit(1);
1199
+ }
1200
+ const { default: CodeGraph } = await loadCodeGraph();
1201
+ const cg = await CodeGraph.open(projectPath);
1202
+ const limit = parseInt(options.limit || '20', 10);
1203
+ const matches = cg.searchNodes(symbol, { limit: 50 });
1204
+ if (matches.length === 0) {
1205
+ info(`Symbol "${symbol}" not found`);
1206
+ cg.destroy();
1207
+ return;
1208
+ }
1209
+ const seen = new Set();
1210
+ const allCallees = [];
1211
+ for (const match of matches) {
1212
+ const exactMatch = match.node.name === symbol || match.node.name.endsWith(`.${symbol}`) || match.node.name.endsWith(`::${symbol}`);
1213
+ if (!exactMatch && matches.length > 1)
1214
+ continue;
1215
+ for (const c of cg.getCallees(match.node.id)) {
1216
+ if (!seen.has(c.node.id)) {
1217
+ seen.add(c.node.id);
1218
+ allCallees.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1219
+ }
1220
+ }
1221
+ }
1222
+ if (allCallees.length === 0 && matches[0]) {
1223
+ for (const c of cg.getCallees(matches[0].node.id)) {
1224
+ if (!seen.has(c.node.id)) {
1225
+ seen.add(c.node.id);
1226
+ allCallees.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1227
+ }
1228
+ }
1229
+ }
1230
+ const limited = allCallees.slice(0, limit);
1231
+ if (options.json) {
1232
+ console.log(JSON.stringify({ symbol, callees: limited }, null, 2));
1233
+ }
1234
+ else if (limited.length === 0) {
1235
+ info(`No callees found for "${symbol}"`);
1236
+ }
1237
+ else {
1238
+ console.log(chalk.bold(`\nCallees of "${symbol}" (${limited.length}):\n`));
1239
+ for (const node of limited) {
1240
+ const loc = node.startLine ? `:${node.startLine}` : '';
1241
+ console.log(chalk.cyan(node.kind.padEnd(12)) +
1242
+ chalk.white(node.name));
1243
+ console.log(chalk.dim(` ${node.filePath}${loc}`));
1244
+ console.log();
1245
+ }
1246
+ }
1247
+ cg.destroy();
1248
+ }
1249
+ catch (err) {
1250
+ error(`callees failed: ${err instanceof Error ? err.message : String(err)}`);
1251
+ process.exit(1);
1252
+ }
1253
+ });
1254
+ /**
1255
+ * codegraph impact <symbol>
1256
+ */
1257
+ program
1258
+ .command('impact <symbol>')
1259
+ .description('Analyze what code is affected by changing a symbol')
1260
+ .option('-p, --path <path>', 'Project path')
1261
+ .option('-d, --depth <number>', 'Traversal depth', '2')
1262
+ .option('-j, --json', 'Output as JSON')
1263
+ .action(async (symbol, options) => {
1264
+ const projectPath = resolveProjectPath(options.path);
1265
+ try {
1266
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1267
+ error(`CodeGraph not initialized in ${projectPath}`);
1268
+ process.exit(1);
1269
+ }
1270
+ const { default: CodeGraph } = await loadCodeGraph();
1271
+ const cg = await CodeGraph.open(projectPath);
1272
+ const depth = Math.min(Math.max(parseInt(options.depth || '2', 10), 1), 10);
1273
+ const matches = cg.searchNodes(symbol, { limit: 50 });
1274
+ if (matches.length === 0) {
1275
+ info(`Symbol "${symbol}" not found`);
1276
+ cg.destroy();
1277
+ return;
1278
+ }
1279
+ // Merge impact subgraphs across all exact-matching symbols
1280
+ const mergedNodes = new Map();
1281
+ const seenEdges = new Set();
1282
+ let edgeCount = 0;
1283
+ for (const match of matches) {
1284
+ const exactMatch = match.node.name === symbol || match.node.name.endsWith(`.${symbol}`) || match.node.name.endsWith(`::${symbol}`);
1285
+ if (!exactMatch && matches.length > 1)
1286
+ continue;
1287
+ const impact = cg.getImpactRadius(match.node.id, depth);
1288
+ for (const [id, n] of impact.nodes) {
1289
+ mergedNodes.set(id, { name: n.name, kind: n.kind, filePath: n.filePath, startLine: n.startLine });
1290
+ }
1291
+ for (const e of impact.edges) {
1292
+ const key = `${e.source}->${e.target}:${e.kind}`;
1293
+ if (!seenEdges.has(key)) {
1294
+ seenEdges.add(key);
1295
+ edgeCount++;
1296
+ }
1297
+ }
1298
+ }
1299
+ // Fallback to top match if exact filter removed everything
1300
+ if (mergedNodes.size === 0 && matches[0]) {
1301
+ const impact = cg.getImpactRadius(matches[0].node.id, depth);
1302
+ for (const [id, n] of impact.nodes) {
1303
+ mergedNodes.set(id, { name: n.name, kind: n.kind, filePath: n.filePath, startLine: n.startLine });
1304
+ }
1305
+ edgeCount = impact.edges.length;
1306
+ }
1307
+ if (options.json) {
1308
+ console.log(JSON.stringify({
1309
+ symbol,
1310
+ depth,
1311
+ nodeCount: mergedNodes.size,
1312
+ edgeCount,
1313
+ affected: Array.from(mergedNodes.values()),
1314
+ }, null, 2));
1315
+ }
1316
+ else if (mergedNodes.size === 0) {
1317
+ info(`No affected symbols found for "${symbol}"`);
1318
+ }
1319
+ else {
1320
+ console.log(chalk.bold(`\nImpact of changing "${symbol}" — ${mergedNodes.size} affected symbols:\n`));
1321
+ // Group by file
1322
+ const byFile = new Map();
1323
+ for (const node of mergedNodes.values()) {
1324
+ const list = byFile.get(node.filePath) || [];
1325
+ list.push({ name: node.name, kind: node.kind, startLine: node.startLine });
1326
+ byFile.set(node.filePath, list);
1327
+ }
1328
+ for (const [file, nodes] of byFile) {
1329
+ console.log(chalk.cyan(file));
1330
+ for (const node of nodes) {
1331
+ const loc = node.startLine ? `:${node.startLine}` : '';
1332
+ console.log(` ${chalk.dim(node.kind.padEnd(12))}${node.name}${chalk.dim(loc)}`);
1333
+ }
1334
+ console.log();
1335
+ }
1336
+ }
1337
+ cg.destroy();
1338
+ }
1339
+ catch (err) {
1340
+ error(`impact failed: ${err instanceof Error ? err.message : String(err)}`);
1341
+ process.exit(1);
1342
+ }
1343
+ });
1344
+ /**
1345
+ * codegraph affected [files...]
1346
+ *
1347
+ * Find test files affected by the given source files.
1348
+ * Traces dependency edges transitively to find test files that depend on changed code.
1349
+ *
1350
+ * Usage:
1351
+ * git diff --name-only | codegraph affected --stdin
1352
+ * codegraph affected src/lib/components/Editor.svelte src/routes/+page.svelte
1353
+ */
1354
+ program
1355
+ .command('affected [files...]')
1356
+ .description('Find test files affected by changed source files')
1357
+ .option('-p, --path <path>', 'Project path')
1358
+ .option('--stdin', 'Read file list from stdin (one per line)')
1359
+ .option('-d, --depth <number>', 'Max dependency traversal depth', '5')
1360
+ .option('-f, --filter <glob>', 'Custom glob filter for test files (e.g. "e2e/*.spec.ts")')
1361
+ .option('-j, --json', 'Output as JSON')
1362
+ .option('-q, --quiet', 'Only output file paths, no decoration')
1363
+ .action(async (fileArgs, options) => {
1364
+ const projectPath = resolveProjectPath(options.path);
1365
+ try {
1366
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1367
+ error(`CodeGraph not initialized in ${projectPath}`);
1368
+ process.exit(1);
1369
+ }
1370
+ // Collect changed files from args or stdin
1371
+ let changedFiles = [...(fileArgs || [])];
1372
+ if (options.stdin) {
1373
+ const stdinData = fs.readFileSync(0, 'utf-8');
1374
+ const stdinFiles = stdinData.split('\n').map(f => f.trim()).filter(Boolean);
1375
+ changedFiles.push(...stdinFiles);
1376
+ }
1377
+ if (changedFiles.length === 0) {
1378
+ if (!options.quiet)
1379
+ info('No files provided. Use file arguments or --stdin.');
1380
+ process.exit(0);
1381
+ }
1382
+ const { default: CodeGraph } = await loadCodeGraph();
1383
+ const cg = await CodeGraph.open(projectPath);
1384
+ const maxDepth = parseInt(options.depth || '5', 10);
1385
+ // Common test file patterns
1386
+ const defaultTestPatterns = [
1387
+ /\.spec\./,
1388
+ /\.test\./,
1389
+ /\/__tests__\//,
1390
+ /\/tests?\//,
1391
+ /\/e2e\//,
1392
+ /\/spec\//,
1393
+ ];
1394
+ // Custom filter pattern
1395
+ let customFilter = null;
1396
+ if (options.filter) {
1397
+ // Convert glob to regex: ** → .+, * → [^/]*, . → \.
1398
+ const regex = options.filter
1399
+ .replace(/[+[\]{}()^$|\\]/g, '\\$&')
1400
+ .replace(/\./g, '\\.')
1401
+ .replace(/\*\*/g, '.+')
1402
+ .replace(/\*/g, '[^/]*');
1403
+ customFilter = new RegExp(regex);
1404
+ }
1405
+ function isTestFile(filePath) {
1406
+ if (customFilter)
1407
+ return customFilter.test(filePath);
1408
+ return defaultTestPatterns.some(p => p.test(filePath));
1409
+ }
1410
+ // BFS to find all transitive dependents of changed files, filtered to test files
1411
+ const affectedTests = new Set();
1412
+ const allDependents = new Set();
1413
+ for (const file of changedFiles) {
1414
+ // If the changed file is itself a test file, include it
1415
+ if (isTestFile(file)) {
1416
+ affectedTests.add(file);
1417
+ continue;
1418
+ }
1419
+ // BFS through dependents
1420
+ const queue = [{ file, depth: 0 }];
1421
+ const visited = new Set();
1422
+ visited.add(file);
1423
+ while (queue.length > 0) {
1424
+ const current = queue.shift();
1425
+ if (current.depth >= maxDepth)
1426
+ continue;
1427
+ const dependents = cg.getFileDependents(current.file);
1428
+ for (const dep of dependents) {
1429
+ if (visited.has(dep))
1430
+ continue;
1431
+ visited.add(dep);
1432
+ allDependents.add(dep);
1433
+ if (isTestFile(dep)) {
1434
+ affectedTests.add(dep);
1435
+ }
1436
+ else {
1437
+ queue.push({ file: dep, depth: current.depth + 1 });
1438
+ }
1439
+ }
1440
+ }
1441
+ }
1442
+ const sortedTests = Array.from(affectedTests).sort();
1443
+ // Output
1444
+ if (options.json) {
1445
+ console.log(JSON.stringify({
1446
+ changedFiles,
1447
+ affectedTests: sortedTests,
1448
+ totalDependentsTraversed: allDependents.size,
1449
+ }, null, 2));
1450
+ }
1451
+ else if (options.quiet) {
1452
+ for (const t of sortedTests)
1453
+ console.log(t);
1454
+ }
1455
+ else {
1456
+ if (sortedTests.length === 0) {
1457
+ info('No test files affected by the changed files.');
1458
+ }
1459
+ else {
1460
+ console.log(chalk.bold(`\nAffected test files (${sortedTests.length}):\n`));
1461
+ for (const t of sortedTests) {
1462
+ console.log(' ' + chalk.cyan(t));
1463
+ }
1464
+ console.log();
1465
+ }
1466
+ }
1467
+ cg.destroy();
1468
+ }
1469
+ catch (err) {
1470
+ error(`Affected analysis failed: ${err instanceof Error ? err.message : String(err)}`);
1471
+ process.exit(1);
1472
+ }
1473
+ });
1474
+ /**
1475
+ * codegraph install
1476
+ */
1477
+ program
1478
+ .command('install')
1479
+ .description('Install codegraph MCP server into one or more agents (Claude Code, Cursor, Codex CLI, opencode, Hermes Agent)')
1480
+ .option('-t, --target <ids>', 'Target agent(s): comma-separated ids, or "auto"|"all"|"none". Default: prompt')
1481
+ .option('-l, --location <where>', 'Install location: "global" or "local". Default: prompt')
1482
+ .option('-y, --yes', 'Non-interactive: defaults to --location=global --target=auto, auto-allow on')
1483
+ .option('--no-permissions', 'Skip writing the auto-allow permissions list (Claude Code only)')
1484
+ .option('--print-config <id>', 'Print MCP config snippet for the named agent and exit (no file writes)')
1485
+ .action(async (opts) => {
1486
+ if (opts.printConfig) {
1487
+ const { getTarget, listTargetIds } = await Promise.resolve().then(() => __importStar(require('../installer/targets/registry')));
1488
+ const target = getTarget(opts.printConfig);
1489
+ if (!target) {
1490
+ const known = listTargetIds().join(', ');
1491
+ error(`Unknown target "${opts.printConfig}". Known: ${known}.`);
1492
+ process.exit(1);
1493
+ }
1494
+ const loc = (opts.location === 'local' ? 'local' : 'global');
1495
+ process.stdout.write(target.printConfig(loc));
1496
+ return;
1497
+ }
1498
+ const { runInstallerWithOptions } = await Promise.resolve().then(() => __importStar(require('../installer')));
1499
+ if (opts.location && opts.location !== 'global' && opts.location !== 'local') {
1500
+ error(`--location must be "global" or "local" (got "${opts.location}").`);
1501
+ process.exit(1);
1502
+ }
1503
+ try {
1504
+ // Commander's `--no-permissions` makes `opts.permissions === false`;
1505
+ // omitting the flag leaves it `true` (the positive-form default).
1506
+ // We MUST treat the default-true as "user did not override — let
1507
+ // the orchestrator prompt" and only forward an explicit `false`
1508
+ // (or `true` when --yes implies it). Otherwise the auto-allow
1509
+ // prompt is silently skipped on every interactive run.
1510
+ const explicitNoPermissions = opts.permissions === false;
1511
+ const autoAllow = explicitNoPermissions
1512
+ ? false
1513
+ : opts.yes
1514
+ ? true
1515
+ : undefined;
1516
+ await runInstallerWithOptions({
1517
+ target: opts.target,
1518
+ location: opts.location,
1519
+ autoAllow,
1520
+ yes: opts.yes,
1521
+ });
1522
+ }
1523
+ catch (err) {
1524
+ error(err instanceof Error ? err.message : String(err));
1525
+ process.exit(1);
1526
+ }
1527
+ });
1528
+ /**
1529
+ * codegraph uninstall
1530
+ *
1531
+ * Inverse of `install`. Removes the codegraph MCP server entry,
1532
+ * instructions block, and permissions from every agent (or a
1533
+ * `--target` subset). Prompts global-vs-local when not given. Does NOT
1534
+ * delete the `.codegraph/` index — that's `codegraph uninit`.
1535
+ */
1536
+ program
1537
+ .command('uninstall')
1538
+ .description('Remove codegraph from your agents (Claude Code, Cursor, Codex CLI, opencode, Hermes Agent)')
1539
+ .option('-t, --target <ids>', 'Target agent(s): comma-separated ids, or "all". Default: all')
1540
+ .option('-l, --location <where>', 'Uninstall location: "global" or "local". Default: prompt')
1541
+ .option('-y, --yes', 'Non-interactive: defaults to --location=global --target=all')
1542
+ .action(async (opts) => {
1543
+ const { runUninstaller } = await Promise.resolve().then(() => __importStar(require('../installer')));
1544
+ if (opts.location && opts.location !== 'global' && opts.location !== 'local') {
1545
+ error(`--location must be "global" or "local" (got "${opts.location}").`);
1546
+ process.exit(1);
1547
+ }
1548
+ try {
1549
+ await runUninstaller({
1550
+ target: opts.target,
1551
+ location: opts.location,
1552
+ yes: opts.yes,
1553
+ });
1554
+ }
1555
+ catch (err) {
1556
+ error(err instanceof Error ? err.message : String(err));
1557
+ process.exit(1);
1558
+ }
1559
+ });
1560
+ // Parse and run
1561
+ program.parse();
1562
+ } // end main()
1563
+ //# sourceMappingURL=codegraph.js.map