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