cgraphx 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (936) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +243 -0
  3. package/dist/.claude-template/commands/my-commit.md +9 -0
  4. package/dist/.claude-template/commands/my-query.md +4 -0
  5. package/dist/.claude-template/hooks/context-monitor/context-monitor.cjs +216 -0
  6. package/dist/.claude-template/plugins/claude-hud/dist/claude-config-dir.d.ts +4 -0
  7. package/dist/.claude-template/plugins/claude-hud/dist/claude-config-dir.d.ts.map +1 -0
  8. package/dist/.claude-template/plugins/claude-hud/dist/claude-config-dir.js +24 -0
  9. package/dist/.claude-template/plugins/claude-hud/dist/claude-config-dir.js.map +1 -0
  10. package/dist/.claude-template/plugins/claude-hud/dist/config-reader.d.ts +8 -0
  11. package/dist/.claude-template/plugins/claude-hud/dist/config-reader.d.ts.map +1 -0
  12. package/dist/.claude-template/plugins/claude-hud/dist/config-reader.js +204 -0
  13. package/dist/.claude-template/plugins/claude-hud/dist/config-reader.js.map +1 -0
  14. package/dist/.claude-template/plugins/claude-hud/dist/config.d.ts +46 -0
  15. package/dist/.claude-template/plugins/claude-hud/dist/config.d.ts.map +1 -0
  16. package/dist/.claude-template/plugins/claude-hud/dist/config.js +220 -0
  17. package/dist/.claude-template/plugins/claude-hud/dist/config.js.map +1 -0
  18. package/dist/.claude-template/plugins/claude-hud/dist/constants.d.ts +10 -0
  19. package/dist/.claude-template/plugins/claude-hud/dist/constants.d.ts.map +1 -0
  20. package/dist/.claude-template/plugins/claude-hud/dist/constants.js +10 -0
  21. package/dist/.claude-template/plugins/claude-hud/dist/constants.js.map +1 -0
  22. package/dist/.claude-template/plugins/claude-hud/dist/debug.d.ts +6 -0
  23. package/dist/.claude-template/plugins/claude-hud/dist/debug.d.ts.map +1 -0
  24. package/dist/.claude-template/plugins/claude-hud/dist/debug.js +15 -0
  25. package/dist/.claude-template/plugins/claude-hud/dist/debug.js.map +1 -0
  26. package/dist/.claude-template/plugins/claude-hud/dist/extra-cmd.d.ts +23 -0
  27. package/dist/.claude-template/plugins/claude-hud/dist/extra-cmd.d.ts.map +1 -0
  28. package/dist/.claude-template/plugins/claude-hud/dist/extra-cmd.js +103 -0
  29. package/dist/.claude-template/plugins/claude-hud/dist/extra-cmd.js.map +1 -0
  30. package/dist/.claude-template/plugins/claude-hud/dist/git.d.ts +16 -0
  31. package/dist/.claude-template/plugins/claude-hud/dist/git.d.ts.map +1 -0
  32. package/dist/.claude-template/plugins/claude-hud/dist/git.js +86 -0
  33. package/dist/.claude-template/plugins/claude-hud/dist/git.js.map +1 -0
  34. package/dist/.claude-template/plugins/claude-hud/dist/index.d.ts +24 -0
  35. package/dist/.claude-template/plugins/claude-hud/dist/index.d.ts.map +1 -0
  36. package/dist/.claude-template/plugins/claude-hud/dist/index.js +97 -0
  37. package/dist/.claude-template/plugins/claude-hud/dist/index.js.map +1 -0
  38. package/dist/.claude-template/plugins/claude-hud/dist/render/agents-line.d.ts +3 -0
  39. package/dist/.claude-template/plugins/claude-hud/dist/render/agents-line.d.ts.map +1 -0
  40. package/dist/.claude-template/plugins/claude-hud/dist/render/agents-line.js +44 -0
  41. package/dist/.claude-template/plugins/claude-hud/dist/render/agents-line.js.map +1 -0
  42. package/dist/.claude-template/plugins/claude-hud/dist/render/colors.d.ts +12 -0
  43. package/dist/.claude-template/plugins/claude-hud/dist/render/colors.d.ts.map +1 -0
  44. package/dist/.claude-template/plugins/claude-hud/dist/render/colors.js +58 -0
  45. package/dist/.claude-template/plugins/claude-hud/dist/render/colors.js.map +1 -0
  46. package/dist/.claude-template/plugins/claude-hud/dist/render/index.d.ts +3 -0
  47. package/dist/.claude-template/plugins/claude-hud/dist/render/index.d.ts.map +1 -0
  48. package/dist/.claude-template/plugins/claude-hud/dist/render/index.js +379 -0
  49. package/dist/.claude-template/plugins/claude-hud/dist/render/index.js.map +1 -0
  50. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/environment.d.ts +3 -0
  51. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/environment.d.ts.map +1 -0
  52. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/environment.js +30 -0
  53. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/environment.js.map +1 -0
  54. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/identity.d.ts +3 -0
  55. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/identity.d.ts.map +1 -0
  56. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/identity.js +52 -0
  57. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/identity.js.map +1 -0
  58. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/index.d.ts +5 -0
  59. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/index.d.ts.map +1 -0
  60. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/index.js +5 -0
  61. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/index.js.map +1 -0
  62. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/project.d.ts +3 -0
  63. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/project.d.ts.map +1 -0
  64. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/project.js +74 -0
  65. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/project.js.map +1 -0
  66. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/usage.d.ts +3 -0
  67. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/usage.d.ts.map +1 -0
  68. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/usage.js +92 -0
  69. package/dist/.claude-template/plugins/claude-hud/dist/render/lines/usage.js.map +1 -0
  70. package/dist/.claude-template/plugins/claude-hud/dist/render/session-line.d.ts +7 -0
  71. package/dist/.claude-template/plugins/claude-hud/dist/render/session-line.d.ts.map +1 -0
  72. package/dist/.claude-template/plugins/claude-hud/dist/render/session-line.js +247 -0
  73. package/dist/.claude-template/plugins/claude-hud/dist/render/session-line.js.map +1 -0
  74. package/dist/.claude-template/plugins/claude-hud/dist/render/todos-line.d.ts +3 -0
  75. package/dist/.claude-template/plugins/claude-hud/dist/render/todos-line.d.ts.map +1 -0
  76. package/dist/.claude-template/plugins/claude-hud/dist/render/todos-line.js +25 -0
  77. package/dist/.claude-template/plugins/claude-hud/dist/render/todos-line.js.map +1 -0
  78. package/dist/.claude-template/plugins/claude-hud/dist/render/tools-line.d.ts +3 -0
  79. package/dist/.claude-template/plugins/claude-hud/dist/render/tools-line.d.ts.map +1 -0
  80. package/dist/.claude-template/plugins/claude-hud/dist/render/tools-line.js +43 -0
  81. package/dist/.claude-template/plugins/claude-hud/dist/render/tools-line.js.map +1 -0
  82. package/dist/.claude-template/plugins/claude-hud/dist/speed-tracker.d.ts +7 -0
  83. package/dist/.claude-template/plugins/claude-hud/dist/speed-tracker.d.ts.map +1 -0
  84. package/dist/.claude-template/plugins/claude-hud/dist/speed-tracker.js +62 -0
  85. package/dist/.claude-template/plugins/claude-hud/dist/speed-tracker.js.map +1 -0
  86. package/dist/.claude-template/plugins/claude-hud/dist/stdin.d.ts +9 -0
  87. package/dist/.claude-template/plugins/claude-hud/dist/stdin.d.ts.map +1 -0
  88. package/dist/.claude-template/plugins/claude-hud/dist/stdin.js +136 -0
  89. package/dist/.claude-template/plugins/claude-hud/dist/stdin.js.map +1 -0
  90. package/dist/.claude-template/plugins/claude-hud/dist/transcript.d.ts +3 -0
  91. package/dist/.claude-template/plugins/claude-hud/dist/transcript.d.ts.map +1 -0
  92. package/dist/.claude-template/plugins/claude-hud/dist/transcript.js +189 -0
  93. package/dist/.claude-template/plugins/claude-hud/dist/transcript.js.map +1 -0
  94. package/dist/.claude-template/plugins/claude-hud/dist/types.d.ts +79 -0
  95. package/dist/.claude-template/plugins/claude-hud/dist/types.d.ts.map +1 -0
  96. package/dist/.claude-template/plugins/claude-hud/dist/types.js +5 -0
  97. package/dist/.claude-template/plugins/claude-hud/dist/types.js.map +1 -0
  98. package/dist/.claude-template/plugins/claude-hud/dist/usage-api.d.ts +59 -0
  99. package/dist/.claude-template/plugins/claude-hud/dist/usage-api.d.ts.map +1 -0
  100. package/dist/.claude-template/plugins/claude-hud/dist/usage-api.js +733 -0
  101. package/dist/.claude-template/plugins/claude-hud/dist/usage-api.js.map +1 -0
  102. package/dist/.claude-template/skills/cgraphx/SKILL.md +143 -0
  103. package/dist/.claude-template/skills/cgraphx/agent-prompt.md +56 -0
  104. package/dist/.claude-template/skills/clarify-requirements/SKILL.md +425 -0
  105. package/dist/.claude-template/skills/code-impact-api/SKILL.md +143 -0
  106. package/dist/.claude-template/skills/code-impact-api/agent-prompt.md +51 -0
  107. package/dist/.claude-template/skills/code-impact-docgen/SKILL.md +366 -0
  108. package/dist/.claude-template/skills/code-impact-docgen/template-business-html.md +242 -0
  109. package/dist/.claude-template/skills/code-impact-docgen/template-business-md.md +107 -0
  110. package/dist/.claude-template/skills/code-impact-docgen/template-technical-html.md +205 -0
  111. package/dist/.claude-template/skills/code-impact-docgen/template-technical-md.md +155 -0
  112. package/dist/.claude-template/skills/code-impact-init/SKILL.md +800 -0
  113. package/dist/.claude-template/skills/code-impact-markdown/SKILL.md +345 -0
  114. package/dist/.claude-template/skills/code-impact-markdown/template-guide.md +68 -0
  115. package/dist/.claude-template/skills/code-impact-markdown/template-memory.md +82 -0
  116. package/dist/.claude-template/skills/code-impact-markdown/template-runbook.md +58 -0
  117. package/dist/.claude-template/skills/db-query/SKILL.md +166 -0
  118. package/dist/.claude-template/skills/db-query/agent-prompt.md +55 -0
  119. package/dist/.claude-template/skills/developer-timeline/SKILL.md +302 -0
  120. package/dist/.claude-template/skills/developer-timeline/demo-single-page-report.html +657 -0
  121. package/dist/.claude-template/skills/implementation/SKILL.md +136 -0
  122. package/dist/.claude-template/skills/subagent-implement/SKILL.md +225 -0
  123. package/dist/.claude-template/skills/subagent-implement/implementer-prompt.md +127 -0
  124. package/dist/.claude-template/skills/subagent-implement/quality-reviewer-prompt.md +130 -0
  125. package/dist/.claude-template/skills/subagent-implement/spec-reviewer-prompt.md +112 -0
  126. package/dist/.claude-template/skills/write-plan/SKILL.md +322 -0
  127. package/dist/.claude-template/skills/write-plan/plan-document-reviewer-prompt.md +134 -0
  128. package/dist/.claude-template/skills/write-prd/SKILL.md +242 -0
  129. package/dist/.claude-template/skills/write-spec/SKILL.md +278 -0
  130. package/dist/bin/codegraph.d.ts +26 -0
  131. package/dist/bin/codegraph.d.ts.map +1 -0
  132. package/dist/bin/codegraph.js +2014 -0
  133. package/dist/bin/codegraph.js.map +1 -0
  134. package/dist/bin/fatal-handler.d.ts +20 -0
  135. package/dist/bin/fatal-handler.d.ts.map +1 -0
  136. package/dist/bin/fatal-handler.js +118 -0
  137. package/dist/bin/fatal-handler.js.map +1 -0
  138. package/dist/bin/node-version-check.d.ts +51 -0
  139. package/dist/bin/node-version-check.d.ts.map +1 -0
  140. package/dist/bin/node-version-check.js +114 -0
  141. package/dist/bin/node-version-check.js.map +1 -0
  142. package/dist/bin/uninstall.d.ts +14 -0
  143. package/dist/bin/uninstall.d.ts.map +1 -0
  144. package/dist/bin/uninstall.js +36 -0
  145. package/dist/bin/uninstall.js.map +1 -0
  146. package/dist/context/formatter.d.ts +30 -0
  147. package/dist/context/formatter.d.ts.map +1 -0
  148. package/dist/context/formatter.js +263 -0
  149. package/dist/context/formatter.js.map +1 -0
  150. package/dist/context/index.d.ts +119 -0
  151. package/dist/context/index.d.ts.map +1 -0
  152. package/dist/context/index.js +1296 -0
  153. package/dist/context/index.js.map +1 -0
  154. package/dist/context/markers.d.ts +19 -0
  155. package/dist/context/markers.d.ts.map +1 -0
  156. package/dist/context/markers.js +22 -0
  157. package/dist/context/markers.js.map +1 -0
  158. package/dist/db/index.d.ts +122 -0
  159. package/dist/db/index.d.ts.map +1 -0
  160. package/dist/db/index.js +296 -0
  161. package/dist/db/index.js.map +1 -0
  162. package/dist/db/migrations.d.ts +44 -0
  163. package/dist/db/migrations.d.ts.map +1 -0
  164. package/dist/db/migrations.js +140 -0
  165. package/dist/db/migrations.js.map +1 -0
  166. package/dist/db/queries.d.ts +401 -0
  167. package/dist/db/queries.d.ts.map +1 -0
  168. package/dist/db/queries.js +1591 -0
  169. package/dist/db/queries.js.map +1 -0
  170. package/dist/db/schema.sql +152 -0
  171. package/dist/db/sqlite-adapter.d.ts +53 -0
  172. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  173. package/dist/db/sqlite-adapter.js +117 -0
  174. package/dist/db/sqlite-adapter.js.map +1 -0
  175. package/dist/dbquery/cli.d.ts +17 -0
  176. package/dist/dbquery/cli.d.ts.map +1 -0
  177. package/dist/dbquery/cli.js +229 -0
  178. package/dist/dbquery/cli.js.map +1 -0
  179. package/dist/dbquery/config.d.ts +38 -0
  180. package/dist/dbquery/config.d.ts.map +1 -0
  181. package/dist/dbquery/config.js +244 -0
  182. package/dist/dbquery/config.js.map +1 -0
  183. package/dist/dbquery/constants.d.ts +40 -0
  184. package/dist/dbquery/constants.d.ts.map +1 -0
  185. package/dist/dbquery/constants.js +65 -0
  186. package/dist/dbquery/constants.js.map +1 -0
  187. package/dist/dbquery/drivers/mysql.d.ts +15 -0
  188. package/dist/dbquery/drivers/mysql.d.ts.map +1 -0
  189. package/dist/dbquery/drivers/mysql.js +102 -0
  190. package/dist/dbquery/drivers/mysql.js.map +1 -0
  191. package/dist/dbquery/drivers/postgres.d.ts +16 -0
  192. package/dist/dbquery/drivers/postgres.d.ts.map +1 -0
  193. package/dist/dbquery/drivers/postgres.js +105 -0
  194. package/dist/dbquery/drivers/postgres.js.map +1 -0
  195. package/dist/dbquery/errors.d.ts +40 -0
  196. package/dist/dbquery/errors.d.ts.map +1 -0
  197. package/dist/dbquery/errors.js +85 -0
  198. package/dist/dbquery/errors.js.map +1 -0
  199. package/dist/dbquery/executor.d.ts +30 -0
  200. package/dist/dbquery/executor.d.ts.map +1 -0
  201. package/dist/dbquery/executor.js +243 -0
  202. package/dist/dbquery/executor.js.map +1 -0
  203. package/dist/dbquery/format.d.ts +18 -0
  204. package/dist/dbquery/format.d.ts.map +1 -0
  205. package/dist/dbquery/format.js +174 -0
  206. package/dist/dbquery/format.js.map +1 -0
  207. package/dist/dbquery/index.d.ts +10 -0
  208. package/dist/dbquery/index.d.ts.map +1 -0
  209. package/dist/dbquery/index.js +23 -0
  210. package/dist/dbquery/index.js.map +1 -0
  211. package/dist/dbquery/init.d.ts +33 -0
  212. package/dist/dbquery/init.d.ts.map +1 -0
  213. package/dist/dbquery/init.js +125 -0
  214. package/dist/dbquery/init.js.map +1 -0
  215. package/dist/dbquery/logging.d.ts +22 -0
  216. package/dist/dbquery/logging.d.ts.map +1 -0
  217. package/dist/dbquery/logging.js +140 -0
  218. package/dist/dbquery/logging.js.map +1 -0
  219. package/dist/dbquery/mcp-tools.d.ts +29 -0
  220. package/dist/dbquery/mcp-tools.d.ts.map +1 -0
  221. package/dist/dbquery/mcp-tools.js +206 -0
  222. package/dist/dbquery/mcp-tools.js.map +1 -0
  223. package/dist/dbquery/queries.d.ts +31 -0
  224. package/dist/dbquery/queries.d.ts.map +1 -0
  225. package/dist/dbquery/queries.js +160 -0
  226. package/dist/dbquery/queries.js.map +1 -0
  227. package/dist/dbquery/safety.d.ts +35 -0
  228. package/dist/dbquery/safety.d.ts.map +1 -0
  229. package/dist/dbquery/safety.js +306 -0
  230. package/dist/dbquery/safety.js.map +1 -0
  231. package/dist/dbquery/types.d.ts +152 -0
  232. package/dist/dbquery/types.d.ts.map +1 -0
  233. package/dist/dbquery/types.js +10 -0
  234. package/dist/dbquery/types.js.map +1 -0
  235. package/dist/directory.d.ts +147 -0
  236. package/dist/directory.d.ts.map +1 -0
  237. package/dist/directory.js +523 -0
  238. package/dist/directory.js.map +1 -0
  239. package/dist/errors.d.ts +136 -0
  240. package/dist/errors.d.ts.map +1 -0
  241. package/dist/errors.js +219 -0
  242. package/dist/errors.js.map +1 -0
  243. package/dist/extraction/astro-extractor.d.ts +79 -0
  244. package/dist/extraction/astro-extractor.d.ts.map +1 -0
  245. package/dist/extraction/astro-extractor.js +320 -0
  246. package/dist/extraction/astro-extractor.js.map +1 -0
  247. package/dist/extraction/dfm-extractor.d.ts +31 -0
  248. package/dist/extraction/dfm-extractor.d.ts.map +1 -0
  249. package/dist/extraction/dfm-extractor.js +151 -0
  250. package/dist/extraction/dfm-extractor.js.map +1 -0
  251. package/dist/extraction/extraction-version.d.ts +25 -0
  252. package/dist/extraction/extraction-version.d.ts.map +1 -0
  253. package/dist/extraction/extraction-version.js +28 -0
  254. package/dist/extraction/extraction-version.js.map +1 -0
  255. package/dist/extraction/function-ref.d.ts +118 -0
  256. package/dist/extraction/function-ref.d.ts.map +1 -0
  257. package/dist/extraction/function-ref.js +727 -0
  258. package/dist/extraction/function-ref.js.map +1 -0
  259. package/dist/extraction/generated-detection.d.ts +30 -0
  260. package/dist/extraction/generated-detection.d.ts.map +1 -0
  261. package/dist/extraction/generated-detection.js +83 -0
  262. package/dist/extraction/generated-detection.js.map +1 -0
  263. package/dist/extraction/grammars.d.ts +114 -0
  264. package/dist/extraction/grammars.d.ts.map +1 -0
  265. package/dist/extraction/grammars.js +477 -0
  266. package/dist/extraction/grammars.js.map +1 -0
  267. package/dist/extraction/index.d.ts +175 -0
  268. package/dist/extraction/index.d.ts.map +1 -0
  269. package/dist/extraction/index.js +1887 -0
  270. package/dist/extraction/index.js.map +1 -0
  271. package/dist/extraction/languages/c-cpp.d.ts +12 -0
  272. package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  273. package/dist/extraction/languages/c-cpp.js +275 -0
  274. package/dist/extraction/languages/c-cpp.js.map +1 -0
  275. package/dist/extraction/languages/csharp.d.ts +25 -0
  276. package/dist/extraction/languages/csharp.d.ts.map +1 -0
  277. package/dist/extraction/languages/csharp.js +175 -0
  278. package/dist/extraction/languages/csharp.js.map +1 -0
  279. package/dist/extraction/languages/dart.d.ts +3 -0
  280. package/dist/extraction/languages/dart.d.ts.map +1 -0
  281. package/dist/extraction/languages/dart.js +374 -0
  282. package/dist/extraction/languages/dart.js.map +1 -0
  283. package/dist/extraction/languages/go.d.ts +3 -0
  284. package/dist/extraction/languages/go.d.ts.map +1 -0
  285. package/dist/extraction/languages/go.js +111 -0
  286. package/dist/extraction/languages/go.js.map +1 -0
  287. package/dist/extraction/languages/index.d.ts +10 -0
  288. package/dist/extraction/languages/index.d.ts.map +1 -0
  289. package/dist/extraction/languages/index.js +53 -0
  290. package/dist/extraction/languages/index.js.map +1 -0
  291. package/dist/extraction/languages/java.d.ts +3 -0
  292. package/dist/extraction/languages/java.d.ts.map +1 -0
  293. package/dist/extraction/languages/java.js +315 -0
  294. package/dist/extraction/languages/java.js.map +1 -0
  295. package/dist/extraction/languages/javascript.d.ts +3 -0
  296. package/dist/extraction/languages/javascript.d.ts.map +1 -0
  297. package/dist/extraction/languages/javascript.js +106 -0
  298. package/dist/extraction/languages/javascript.js.map +1 -0
  299. package/dist/extraction/languages/kotlin.d.ts +3 -0
  300. package/dist/extraction/languages/kotlin.d.ts.map +1 -0
  301. package/dist/extraction/languages/kotlin.js +379 -0
  302. package/dist/extraction/languages/kotlin.js.map +1 -0
  303. package/dist/extraction/languages/lua.d.ts +3 -0
  304. package/dist/extraction/languages/lua.d.ts.map +1 -0
  305. package/dist/extraction/languages/lua.js +150 -0
  306. package/dist/extraction/languages/lua.js.map +1 -0
  307. package/dist/extraction/languages/luau.d.ts +3 -0
  308. package/dist/extraction/languages/luau.d.ts.map +1 -0
  309. package/dist/extraction/languages/luau.js +37 -0
  310. package/dist/extraction/languages/luau.js.map +1 -0
  311. package/dist/extraction/languages/objc.d.ts +3 -0
  312. package/dist/extraction/languages/objc.d.ts.map +1 -0
  313. package/dist/extraction/languages/objc.js +175 -0
  314. package/dist/extraction/languages/objc.js.map +1 -0
  315. package/dist/extraction/languages/pascal.d.ts +3 -0
  316. package/dist/extraction/languages/pascal.d.ts.map +1 -0
  317. package/dist/extraction/languages/pascal.js +77 -0
  318. package/dist/extraction/languages/pascal.js.map +1 -0
  319. package/dist/extraction/languages/php.d.ts +3 -0
  320. package/dist/extraction/languages/php.d.ts.map +1 -0
  321. package/dist/extraction/languages/php.js +196 -0
  322. package/dist/extraction/languages/php.js.map +1 -0
  323. package/dist/extraction/languages/python.d.ts +3 -0
  324. package/dist/extraction/languages/python.d.ts.map +1 -0
  325. package/dist/extraction/languages/python.js +56 -0
  326. package/dist/extraction/languages/python.js.map +1 -0
  327. package/dist/extraction/languages/r.d.ts +3 -0
  328. package/dist/extraction/languages/r.d.ts.map +1 -0
  329. package/dist/extraction/languages/r.js +314 -0
  330. package/dist/extraction/languages/r.js.map +1 -0
  331. package/dist/extraction/languages/ruby.d.ts +3 -0
  332. package/dist/extraction/languages/ruby.d.ts.map +1 -0
  333. package/dist/extraction/languages/ruby.js +149 -0
  334. package/dist/extraction/languages/ruby.js.map +1 -0
  335. package/dist/extraction/languages/rust.d.ts +3 -0
  336. package/dist/extraction/languages/rust.d.ts.map +1 -0
  337. package/dist/extraction/languages/rust.js +142 -0
  338. package/dist/extraction/languages/rust.js.map +1 -0
  339. package/dist/extraction/languages/scala.d.ts +3 -0
  340. package/dist/extraction/languages/scala.d.ts.map +1 -0
  341. package/dist/extraction/languages/scala.js +209 -0
  342. package/dist/extraction/languages/scala.js.map +1 -0
  343. package/dist/extraction/languages/swift.d.ts +3 -0
  344. package/dist/extraction/languages/swift.d.ts.map +1 -0
  345. package/dist/extraction/languages/swift.js +152 -0
  346. package/dist/extraction/languages/swift.js.map +1 -0
  347. package/dist/extraction/languages/typescript.d.ts +16 -0
  348. package/dist/extraction/languages/typescript.d.ts.map +1 -0
  349. package/dist/extraction/languages/typescript.js +167 -0
  350. package/dist/extraction/languages/typescript.js.map +1 -0
  351. package/dist/extraction/liquid-extractor.d.ts +59 -0
  352. package/dist/extraction/liquid-extractor.d.ts.map +1 -0
  353. package/dist/extraction/liquid-extractor.js +357 -0
  354. package/dist/extraction/liquid-extractor.js.map +1 -0
  355. package/dist/extraction/mybatis-extractor.d.ts +48 -0
  356. package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
  357. package/dist/extraction/mybatis-extractor.js +198 -0
  358. package/dist/extraction/mybatis-extractor.js.map +1 -0
  359. package/dist/extraction/parse-worker.d.ts +8 -0
  360. package/dist/extraction/parse-worker.d.ts.map +1 -0
  361. package/dist/extraction/parse-worker.js +97 -0
  362. package/dist/extraction/parse-worker.js.map +1 -0
  363. package/dist/extraction/razor-extractor.d.ts +42 -0
  364. package/dist/extraction/razor-extractor.d.ts.map +1 -0
  365. package/dist/extraction/razor-extractor.js +285 -0
  366. package/dist/extraction/razor-extractor.js.map +1 -0
  367. package/dist/extraction/svelte-extractor.d.ts +56 -0
  368. package/dist/extraction/svelte-extractor.d.ts.map +1 -0
  369. package/dist/extraction/svelte-extractor.js +275 -0
  370. package/dist/extraction/svelte-extractor.js.map +1 -0
  371. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  372. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  373. package/dist/extraction/tree-sitter-helpers.js +152 -0
  374. package/dist/extraction/tree-sitter-helpers.js.map +1 -0
  375. package/dist/extraction/tree-sitter-types.d.ts +239 -0
  376. package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  377. package/dist/extraction/tree-sitter-types.js +10 -0
  378. package/dist/extraction/tree-sitter-types.js.map +1 -0
  379. package/dist/extraction/tree-sitter.d.ts +647 -0
  380. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  381. package/dist/extraction/tree-sitter.js +5592 -0
  382. package/dist/extraction/tree-sitter.js.map +1 -0
  383. package/dist/extraction/vue-extractor.d.ts +51 -0
  384. package/dist/extraction/vue-extractor.d.ts.map +1 -0
  385. package/dist/extraction/vue-extractor.js +254 -0
  386. package/dist/extraction/vue-extractor.js.map +1 -0
  387. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  388. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  389. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  390. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  391. package/dist/extraction/wasm/tree-sitter-r.wasm +0 -0
  392. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  393. package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
  394. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
  395. package/dist/extraction/wasm-runtime-flags.js +106 -0
  396. package/dist/extraction/wasm-runtime-flags.js.map +1 -0
  397. package/dist/graph/index.d.ts +8 -0
  398. package/dist/graph/index.d.ts.map +1 -0
  399. package/dist/graph/index.js +13 -0
  400. package/dist/graph/index.js.map +1 -0
  401. package/dist/graph/queries.d.ts +106 -0
  402. package/dist/graph/queries.d.ts.map +1 -0
  403. package/dist/graph/queries.js +339 -0
  404. package/dist/graph/queries.js.map +1 -0
  405. package/dist/graph/traversal.d.ts +127 -0
  406. package/dist/graph/traversal.d.ts.map +1 -0
  407. package/dist/graph/traversal.js +540 -0
  408. package/dist/graph/traversal.js.map +1 -0
  409. package/dist/index.d.ts +563 -0
  410. package/dist/index.d.ts.map +1 -0
  411. package/dist/index.js +1041 -0
  412. package/dist/index.js.map +1 -0
  413. package/dist/installer/claude-assets.d.ts +45 -0
  414. package/dist/installer/claude-assets.d.ts.map +1 -0
  415. package/dist/installer/claude-assets.js +144 -0
  416. package/dist/installer/claude-assets.js.map +1 -0
  417. package/dist/installer/config-writer.d.ts +28 -0
  418. package/dist/installer/config-writer.d.ts.map +1 -0
  419. package/dist/installer/config-writer.js +91 -0
  420. package/dist/installer/config-writer.js.map +1 -0
  421. package/dist/installer/index.d.ts +101 -0
  422. package/dist/installer/index.d.ts.map +1 -0
  423. package/dist/installer/index.js +692 -0
  424. package/dist/installer/index.js.map +1 -0
  425. package/dist/installer/instructions-template.d.ts +41 -0
  426. package/dist/installer/instructions-template.d.ts.map +1 -0
  427. package/dist/installer/instructions-template.js +53 -0
  428. package/dist/installer/instructions-template.js.map +1 -0
  429. package/dist/installer/targets/antigravity.d.ts +57 -0
  430. package/dist/installer/targets/antigravity.d.ts.map +1 -0
  431. package/dist/installer/targets/antigravity.js +308 -0
  432. package/dist/installer/targets/antigravity.js.map +1 -0
  433. package/dist/installer/targets/claude.d.ts +66 -0
  434. package/dist/installer/targets/claude.d.ts.map +1 -0
  435. package/dist/installer/targets/claude.js +564 -0
  436. package/dist/installer/targets/claude.js.map +1 -0
  437. package/dist/installer/targets/codex.d.ts +18 -0
  438. package/dist/installer/targets/codex.d.ts.map +1 -0
  439. package/dist/installer/targets/codex.js +185 -0
  440. package/dist/installer/targets/codex.js.map +1 -0
  441. package/dist/installer/targets/cursor.d.ts +35 -0
  442. package/dist/installer/targets/cursor.d.ts.map +1 -0
  443. package/dist/installer/targets/cursor.js +254 -0
  444. package/dist/installer/targets/cursor.js.map +1 -0
  445. package/dist/installer/targets/gemini.d.ts +26 -0
  446. package/dist/installer/targets/gemini.d.ts.map +1 -0
  447. package/dist/installer/targets/gemini.js +165 -0
  448. package/dist/installer/targets/gemini.js.map +1 -0
  449. package/dist/installer/targets/hermes.d.ts +18 -0
  450. package/dist/installer/targets/hermes.d.ts.map +1 -0
  451. package/dist/installer/targets/hermes.js +359 -0
  452. package/dist/installer/targets/hermes.js.map +1 -0
  453. package/dist/installer/targets/kiro.d.ts +27 -0
  454. package/dist/installer/targets/kiro.d.ts.map +1 -0
  455. package/dist/installer/targets/kiro.js +178 -0
  456. package/dist/installer/targets/kiro.js.map +1 -0
  457. package/dist/installer/targets/opencode.d.ts +38 -0
  458. package/dist/installer/targets/opencode.d.ts.map +1 -0
  459. package/dist/installer/targets/opencode.js +288 -0
  460. package/dist/installer/targets/opencode.js.map +1 -0
  461. package/dist/installer/targets/registry.d.ts +35 -0
  462. package/dist/installer/targets/registry.d.ts.map +1 -0
  463. package/dist/installer/targets/registry.js +91 -0
  464. package/dist/installer/targets/registry.js.map +1 -0
  465. package/dist/installer/targets/shared.d.ts +101 -0
  466. package/dist/installer/targets/shared.d.ts.map +1 -0
  467. package/dist/installer/targets/shared.js +264 -0
  468. package/dist/installer/targets/shared.js.map +1 -0
  469. package/dist/installer/targets/toml.d.ts +52 -0
  470. package/dist/installer/targets/toml.d.ts.map +1 -0
  471. package/dist/installer/targets/toml.js +147 -0
  472. package/dist/installer/targets/toml.js.map +1 -0
  473. package/dist/installer/targets/types.d.ts +108 -0
  474. package/dist/installer/targets/types.d.ts.map +1 -0
  475. package/dist/installer/targets/types.js +16 -0
  476. package/dist/installer/targets/types.js.map +1 -0
  477. package/dist/markdown/cli.d.ts +16 -0
  478. package/dist/markdown/cli.d.ts.map +1 -0
  479. package/dist/markdown/cli.js +533 -0
  480. package/dist/markdown/cli.js.map +1 -0
  481. package/dist/markdown/constants.d.ts +22 -0
  482. package/dist/markdown/constants.d.ts.map +1 -0
  483. package/dist/markdown/constants.js +71 -0
  484. package/dist/markdown/constants.js.map +1 -0
  485. package/dist/markdown/dedup.d.ts +20 -0
  486. package/dist/markdown/dedup.d.ts.map +1 -0
  487. package/dist/markdown/dedup.js +64 -0
  488. package/dist/markdown/dedup.js.map +1 -0
  489. package/dist/markdown/errors.d.ts +22 -0
  490. package/dist/markdown/errors.d.ts.map +1 -0
  491. package/dist/markdown/errors.js +45 -0
  492. package/dist/markdown/errors.js.map +1 -0
  493. package/dist/markdown/extractor.d.ts +43 -0
  494. package/dist/markdown/extractor.d.ts.map +1 -0
  495. package/dist/markdown/extractor.js +152 -0
  496. package/dist/markdown/extractor.js.map +1 -0
  497. package/dist/markdown/frontmatter-parser.d.ts +47 -0
  498. package/dist/markdown/frontmatter-parser.d.ts.map +1 -0
  499. package/dist/markdown/frontmatter-parser.js +199 -0
  500. package/dist/markdown/frontmatter-parser.js.map +1 -0
  501. package/dist/markdown/indexer.d.ts +34 -0
  502. package/dist/markdown/indexer.d.ts.map +1 -0
  503. package/dist/markdown/indexer.js +256 -0
  504. package/dist/markdown/indexer.js.map +1 -0
  505. package/dist/markdown/mcp-tools.d.ts +33 -0
  506. package/dist/markdown/mcp-tools.d.ts.map +1 -0
  507. package/dist/markdown/mcp-tools.js +300 -0
  508. package/dist/markdown/mcp-tools.js.map +1 -0
  509. package/dist/markdown/query.d.ts +108 -0
  510. package/dist/markdown/query.d.ts.map +1 -0
  511. package/dist/markdown/query.js +570 -0
  512. package/dist/markdown/query.js.map +1 -0
  513. package/dist/markdown/schema-bootstrap.d.ts +40 -0
  514. package/dist/markdown/schema-bootstrap.d.ts.map +1 -0
  515. package/dist/markdown/schema-bootstrap.js +85 -0
  516. package/dist/markdown/schema-bootstrap.js.map +1 -0
  517. package/dist/markdown/schema.sql +124 -0
  518. package/dist/markdown/store.d.ts +77 -0
  519. package/dist/markdown/store.d.ts.map +1 -0
  520. package/dist/markdown/store.js +194 -0
  521. package/dist/markdown/store.js.map +1 -0
  522. package/dist/markdown/summary-extractor.d.ts +22 -0
  523. package/dist/markdown/summary-extractor.d.ts.map +1 -0
  524. package/dist/markdown/summary-extractor.js +66 -0
  525. package/dist/markdown/summary-extractor.js.map +1 -0
  526. package/dist/markdown/types.d.ts +159 -0
  527. package/dist/markdown/types.d.ts.map +1 -0
  528. package/dist/markdown/types.js +9 -0
  529. package/dist/markdown/types.js.map +1 -0
  530. package/dist/markdown/validator.d.ts +44 -0
  531. package/dist/markdown/validator.d.ts.map +1 -0
  532. package/dist/markdown/validator.js +95 -0
  533. package/dist/markdown/validator.js.map +1 -0
  534. package/dist/mcp/daemon-manager.d.ts +42 -0
  535. package/dist/mcp/daemon-manager.d.ts.map +1 -0
  536. package/dist/mcp/daemon-manager.js +129 -0
  537. package/dist/mcp/daemon-manager.js.map +1 -0
  538. package/dist/mcp/daemon-paths.d.ts +46 -0
  539. package/dist/mcp/daemon-paths.d.ts.map +1 -0
  540. package/dist/mcp/daemon-paths.js +125 -0
  541. package/dist/mcp/daemon-paths.js.map +1 -0
  542. package/dist/mcp/daemon-registry.d.ts +47 -0
  543. package/dist/mcp/daemon-registry.d.ts.map +1 -0
  544. package/dist/mcp/daemon-registry.js +229 -0
  545. package/dist/mcp/daemon-registry.js.map +1 -0
  546. package/dist/mcp/daemon.d.ts +220 -0
  547. package/dist/mcp/daemon.d.ts.map +1 -0
  548. package/dist/mcp/daemon.js +637 -0
  549. package/dist/mcp/daemon.js.map +1 -0
  550. package/dist/mcp/dynamic-boundaries.d.ts +41 -0
  551. package/dist/mcp/dynamic-boundaries.d.ts.map +1 -0
  552. package/dist/mcp/dynamic-boundaries.js +359 -0
  553. package/dist/mcp/dynamic-boundaries.js.map +1 -0
  554. package/dist/mcp/engine.d.ts +105 -0
  555. package/dist/mcp/engine.d.ts.map +1 -0
  556. package/dist/mcp/engine.js +278 -0
  557. package/dist/mcp/engine.js.map +1 -0
  558. package/dist/mcp/index.d.ts +113 -0
  559. package/dist/mcp/index.d.ts.map +1 -0
  560. package/dist/mcp/index.js +499 -0
  561. package/dist/mcp/index.js.map +1 -0
  562. package/dist/mcp/liveness-watchdog.d.ts +18 -0
  563. package/dist/mcp/liveness-watchdog.d.ts.map +1 -0
  564. package/dist/mcp/liveness-watchdog.js +207 -0
  565. package/dist/mcp/liveness-watchdog.js.map +1 -0
  566. package/dist/mcp/ppid-watchdog.d.ts +44 -0
  567. package/dist/mcp/ppid-watchdog.d.ts.map +1 -0
  568. package/dist/mcp/ppid-watchdog.js +27 -0
  569. package/dist/mcp/ppid-watchdog.js.map +1 -0
  570. package/dist/mcp/proxy.d.ts +87 -0
  571. package/dist/mcp/proxy.d.ts.map +1 -0
  572. package/dist/mcp/proxy.js +641 -0
  573. package/dist/mcp/proxy.js.map +1 -0
  574. package/dist/mcp/server-instructions.d.ts +34 -0
  575. package/dist/mcp/server-instructions.d.ts.map +1 -0
  576. package/dist/mcp/server-instructions.js +106 -0
  577. package/dist/mcp/server-instructions.js.map +1 -0
  578. package/dist/mcp/session.d.ts +79 -0
  579. package/dist/mcp/session.d.ts.map +1 -0
  580. package/dist/mcp/session.js +330 -0
  581. package/dist/mcp/session.js.map +1 -0
  582. package/dist/mcp/stdin-teardown.d.ts +27 -0
  583. package/dist/mcp/stdin-teardown.d.ts.map +1 -0
  584. package/dist/mcp/stdin-teardown.js +49 -0
  585. package/dist/mcp/stdin-teardown.js.map +1 -0
  586. package/dist/mcp/tools.d.ts +547 -0
  587. package/dist/mcp/tools.d.ts.map +1 -0
  588. package/dist/mcp/tools.js +4122 -0
  589. package/dist/mcp/tools.js.map +1 -0
  590. package/dist/mcp/transport.d.ts +188 -0
  591. package/dist/mcp/transport.d.ts.map +1 -0
  592. package/dist/mcp/transport.js +359 -0
  593. package/dist/mcp/transport.js.map +1 -0
  594. package/dist/mcp/version.d.ts +19 -0
  595. package/dist/mcp/version.d.ts.map +1 -0
  596. package/dist/mcp/version.js +71 -0
  597. package/dist/mcp/version.js.map +1 -0
  598. package/dist/project-config.d.ts +36 -0
  599. package/dist/project-config.d.ts.map +1 -0
  600. package/dist/project-config.js +235 -0
  601. package/dist/project-config.js.map +1 -0
  602. package/dist/reasoning/config.d.ts +45 -0
  603. package/dist/reasoning/config.d.ts.map +1 -0
  604. package/dist/reasoning/config.js +171 -0
  605. package/dist/reasoning/config.js.map +1 -0
  606. package/dist/reasoning/credentials.d.ts +5 -0
  607. package/dist/reasoning/credentials.d.ts.map +1 -0
  608. package/dist/reasoning/credentials.js +83 -0
  609. package/dist/reasoning/credentials.js.map +1 -0
  610. package/dist/reasoning/login.d.ts +21 -0
  611. package/dist/reasoning/login.d.ts.map +1 -0
  612. package/dist/reasoning/login.js +85 -0
  613. package/dist/reasoning/login.js.map +1 -0
  614. package/dist/reasoning/reasoner.d.ts +43 -0
  615. package/dist/reasoning/reasoner.d.ts.map +1 -0
  616. package/dist/reasoning/reasoner.js +308 -0
  617. package/dist/reasoning/reasoner.js.map +1 -0
  618. package/dist/resolution/c-fnptr-synthesizer.d.ts +33 -0
  619. package/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -0
  620. package/dist/resolution/c-fnptr-synthesizer.js +352 -0
  621. package/dist/resolution/c-fnptr-synthesizer.js.map +1 -0
  622. package/dist/resolution/callback-synthesizer.d.ts +15 -0
  623. package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
  624. package/dist/resolution/callback-synthesizer.js +2926 -0
  625. package/dist/resolution/callback-synthesizer.js.map +1 -0
  626. package/dist/resolution/frameworks/astro.d.ts +9 -0
  627. package/dist/resolution/frameworks/astro.d.ts.map +1 -0
  628. package/dist/resolution/frameworks/astro.js +169 -0
  629. package/dist/resolution/frameworks/astro.js.map +1 -0
  630. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  631. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  632. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  633. package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  634. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  635. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  636. package/dist/resolution/frameworks/csharp.js +241 -0
  637. package/dist/resolution/frameworks/csharp.js.map +1 -0
  638. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  639. package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
  640. package/dist/resolution/frameworks/drupal.js +367 -0
  641. package/dist/resolution/frameworks/drupal.js.map +1 -0
  642. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  643. package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
  644. package/dist/resolution/frameworks/expo-modules.js +148 -0
  645. package/dist/resolution/frameworks/expo-modules.js.map +1 -0
  646. package/dist/resolution/frameworks/express.d.ts +8 -0
  647. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  648. package/dist/resolution/frameworks/express.js +308 -0
  649. package/dist/resolution/frameworks/express.js.map +1 -0
  650. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  651. package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
  652. package/dist/resolution/frameworks/fabric.js +354 -0
  653. package/dist/resolution/frameworks/fabric.js.map +1 -0
  654. package/dist/resolution/frameworks/go.d.ts +8 -0
  655. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  656. package/dist/resolution/frameworks/go.js +161 -0
  657. package/dist/resolution/frameworks/go.js.map +1 -0
  658. package/dist/resolution/frameworks/goframe.d.ts +41 -0
  659. package/dist/resolution/frameworks/goframe.d.ts.map +1 -0
  660. package/dist/resolution/frameworks/goframe.js +112 -0
  661. package/dist/resolution/frameworks/goframe.js.map +1 -0
  662. package/dist/resolution/frameworks/index.d.ts +50 -0
  663. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  664. package/dist/resolution/frameworks/index.js +169 -0
  665. package/dist/resolution/frameworks/index.js.map +1 -0
  666. package/dist/resolution/frameworks/java.d.ts +8 -0
  667. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  668. package/dist/resolution/frameworks/java.js +509 -0
  669. package/dist/resolution/frameworks/java.js.map +1 -0
  670. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  671. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  672. package/dist/resolution/frameworks/laravel.js +257 -0
  673. package/dist/resolution/frameworks/laravel.js.map +1 -0
  674. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  675. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  676. package/dist/resolution/frameworks/nestjs.js +698 -0
  677. package/dist/resolution/frameworks/nestjs.js.map +1 -0
  678. package/dist/resolution/frameworks/play.d.ts +19 -0
  679. package/dist/resolution/frameworks/play.d.ts.map +1 -0
  680. package/dist/resolution/frameworks/play.js +111 -0
  681. package/dist/resolution/frameworks/play.js.map +1 -0
  682. package/dist/resolution/frameworks/python.d.ts +10 -0
  683. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  684. package/dist/resolution/frameworks/python.js +400 -0
  685. package/dist/resolution/frameworks/python.js.map +1 -0
  686. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  687. package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
  688. package/dist/resolution/frameworks/react-native.js +410 -0
  689. package/dist/resolution/frameworks/react-native.js.map +1 -0
  690. package/dist/resolution/frameworks/react.d.ts +8 -0
  691. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  692. package/dist/resolution/frameworks/react.js +334 -0
  693. package/dist/resolution/frameworks/react.js.map +1 -0
  694. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  695. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  696. package/dist/resolution/frameworks/ruby.js +302 -0
  697. package/dist/resolution/frameworks/ruby.js.map +1 -0
  698. package/dist/resolution/frameworks/rust.d.ts +8 -0
  699. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  700. package/dist/resolution/frameworks/rust.js +304 -0
  701. package/dist/resolution/frameworks/rust.js.map +1 -0
  702. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  703. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  704. package/dist/resolution/frameworks/svelte.js +253 -0
  705. package/dist/resolution/frameworks/svelte.js.map +1 -0
  706. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  707. package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
  708. package/dist/resolution/frameworks/swift-objc.js +252 -0
  709. package/dist/resolution/frameworks/swift-objc.js.map +1 -0
  710. package/dist/resolution/frameworks/swift.d.ts +10 -0
  711. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  712. package/dist/resolution/frameworks/swift.js +400 -0
  713. package/dist/resolution/frameworks/swift.js.map +1 -0
  714. package/dist/resolution/frameworks/vue.d.ts +9 -0
  715. package/dist/resolution/frameworks/vue.d.ts.map +1 -0
  716. package/dist/resolution/frameworks/vue.js +303 -0
  717. package/dist/resolution/frameworks/vue.js.map +1 -0
  718. package/dist/resolution/go-module.d.ts +26 -0
  719. package/dist/resolution/go-module.d.ts.map +1 -0
  720. package/dist/resolution/go-module.js +78 -0
  721. package/dist/resolution/go-module.js.map +1 -0
  722. package/dist/resolution/goframe-synthesizer.d.ts +28 -0
  723. package/dist/resolution/goframe-synthesizer.d.ts.map +1 -0
  724. package/dist/resolution/goframe-synthesizer.js +158 -0
  725. package/dist/resolution/goframe-synthesizer.js.map +1 -0
  726. package/dist/resolution/import-resolver.d.ts +78 -0
  727. package/dist/resolution/import-resolver.d.ts.map +1 -0
  728. package/dist/resolution/import-resolver.js +1849 -0
  729. package/dist/resolution/import-resolver.js.map +1 -0
  730. package/dist/resolution/index.d.ts +196 -0
  731. package/dist/resolution/index.d.ts.map +1 -0
  732. package/dist/resolution/index.js +1328 -0
  733. package/dist/resolution/index.js.map +1 -0
  734. package/dist/resolution/lru-cache.d.ts +24 -0
  735. package/dist/resolution/lru-cache.d.ts.map +1 -0
  736. package/dist/resolution/lru-cache.js +62 -0
  737. package/dist/resolution/lru-cache.js.map +1 -0
  738. package/dist/resolution/name-matcher.d.ts +93 -0
  739. package/dist/resolution/name-matcher.d.ts.map +1 -0
  740. package/dist/resolution/name-matcher.js +1212 -0
  741. package/dist/resolution/name-matcher.js.map +1 -0
  742. package/dist/resolution/path-aliases.d.ts +68 -0
  743. package/dist/resolution/path-aliases.d.ts.map +1 -0
  744. package/dist/resolution/path-aliases.js +238 -0
  745. package/dist/resolution/path-aliases.js.map +1 -0
  746. package/dist/resolution/strip-comments.d.ts +27 -0
  747. package/dist/resolution/strip-comments.d.ts.map +1 -0
  748. package/dist/resolution/strip-comments.js +443 -0
  749. package/dist/resolution/strip-comments.js.map +1 -0
  750. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  751. package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
  752. package/dist/resolution/swift-objc-bridge.js +256 -0
  753. package/dist/resolution/swift-objc-bridge.js.map +1 -0
  754. package/dist/resolution/types.d.ts +233 -0
  755. package/dist/resolution/types.d.ts.map +1 -0
  756. package/dist/resolution/types.js +8 -0
  757. package/dist/resolution/types.js.map +1 -0
  758. package/dist/resolution/workspace-packages.d.ts +48 -0
  759. package/dist/resolution/workspace-packages.d.ts.map +1 -0
  760. package/dist/resolution/workspace-packages.js +208 -0
  761. package/dist/resolution/workspace-packages.js.map +1 -0
  762. package/dist/search/query-parser.d.ts +57 -0
  763. package/dist/search/query-parser.d.ts.map +1 -0
  764. package/dist/search/query-parser.js +177 -0
  765. package/dist/search/query-parser.js.map +1 -0
  766. package/dist/search/query-utils.d.ts +87 -0
  767. package/dist/search/query-utils.d.ts.map +1 -0
  768. package/dist/search/query-utils.js +449 -0
  769. package/dist/search/query-utils.js.map +1 -0
  770. package/dist/sync/git-hooks.d.ts +45 -0
  771. package/dist/sync/git-hooks.d.ts.map +1 -0
  772. package/dist/sync/git-hooks.js +225 -0
  773. package/dist/sync/git-hooks.js.map +1 -0
  774. package/dist/sync/index.d.ts +19 -0
  775. package/dist/sync/index.d.ts.map +1 -0
  776. package/dist/sync/index.js +35 -0
  777. package/dist/sync/index.js.map +1 -0
  778. package/dist/sync/watch-policy.d.ts +48 -0
  779. package/dist/sync/watch-policy.d.ts.map +1 -0
  780. package/dist/sync/watch-policy.js +124 -0
  781. package/dist/sync/watch-policy.js.map +1 -0
  782. package/dist/sync/watcher.d.ts +350 -0
  783. package/dist/sync/watcher.d.ts.map +1 -0
  784. package/dist/sync/watcher.js +811 -0
  785. package/dist/sync/watcher.js.map +1 -0
  786. package/dist/sync/worktree.d.ts +54 -0
  787. package/dist/sync/worktree.d.ts.map +1 -0
  788. package/dist/sync/worktree.js +137 -0
  789. package/dist/sync/worktree.js.map +1 -0
  790. package/dist/telemetry/index.d.ts +143 -0
  791. package/dist/telemetry/index.d.ts.map +1 -0
  792. package/dist/telemetry/index.js +541 -0
  793. package/dist/telemetry/index.js.map +1 -0
  794. package/dist/timeline/bash-semantics.d.ts +52 -0
  795. package/dist/timeline/bash-semantics.d.ts.map +1 -0
  796. package/dist/timeline/bash-semantics.js +376 -0
  797. package/dist/timeline/bash-semantics.js.map +1 -0
  798. package/dist/timeline/cli.d.ts +50 -0
  799. package/dist/timeline/cli.d.ts.map +1 -0
  800. package/dist/timeline/cli.js +367 -0
  801. package/dist/timeline/cli.js.map +1 -0
  802. package/dist/timeline/constants.d.ts +62 -0
  803. package/dist/timeline/constants.d.ts.map +1 -0
  804. package/dist/timeline/constants.js +73 -0
  805. package/dist/timeline/constants.js.map +1 -0
  806. package/dist/timeline/errors.d.ts +27 -0
  807. package/dist/timeline/errors.d.ts.map +1 -0
  808. package/dist/timeline/errors.js +51 -0
  809. package/dist/timeline/errors.js.map +1 -0
  810. package/dist/timeline/hook-runner.d.ts +36 -0
  811. package/dist/timeline/hook-runner.d.ts.map +1 -0
  812. package/dist/timeline/hook-runner.js +61 -0
  813. package/dist/timeline/hook-runner.js.map +1 -0
  814. package/dist/timeline/hooks.d.ts +45 -0
  815. package/dist/timeline/hooks.d.ts.map +1 -0
  816. package/dist/timeline/hooks.js +364 -0
  817. package/dist/timeline/hooks.js.map +1 -0
  818. package/dist/timeline/index.d.ts +12 -0
  819. package/dist/timeline/index.d.ts.map +1 -0
  820. package/dist/timeline/index.js +28 -0
  821. package/dist/timeline/index.js.map +1 -0
  822. package/dist/timeline/indexer.d.ts +37 -0
  823. package/dist/timeline/indexer.d.ts.map +1 -0
  824. package/dist/timeline/indexer.js +76 -0
  825. package/dist/timeline/indexer.js.map +1 -0
  826. package/dist/timeline/installer.d.ts +33 -0
  827. package/dist/timeline/installer.d.ts.map +1 -0
  828. package/dist/timeline/installer.js +255 -0
  829. package/dist/timeline/installer.js.map +1 -0
  830. package/dist/timeline/payload.d.ts +31 -0
  831. package/dist/timeline/payload.d.ts.map +1 -0
  832. package/dist/timeline/payload.js +58 -0
  833. package/dist/timeline/payload.js.map +1 -0
  834. package/dist/timeline/post-tool-summary.d.ts +29 -0
  835. package/dist/timeline/post-tool-summary.d.ts.map +1 -0
  836. package/dist/timeline/post-tool-summary.js +190 -0
  837. package/dist/timeline/post-tool-summary.js.map +1 -0
  838. package/dist/timeline/recorder.d.ts +36 -0
  839. package/dist/timeline/recorder.d.ts.map +1 -0
  840. package/dist/timeline/recorder.js +42 -0
  841. package/dist/timeline/recorder.js.map +1 -0
  842. package/dist/timeline/schema-bootstrap.d.ts +42 -0
  843. package/dist/timeline/schema-bootstrap.d.ts.map +1 -0
  844. package/dist/timeline/schema-bootstrap.js +81 -0
  845. package/dist/timeline/schema-bootstrap.js.map +1 -0
  846. package/dist/timeline/schema.sql +37 -0
  847. package/dist/timeline/store.d.ts +69 -0
  848. package/dist/timeline/store.d.ts.map +1 -0
  849. package/dist/timeline/store.js +429 -0
  850. package/dist/timeline/store.js.map +1 -0
  851. package/dist/timeline/types.d.ts +78 -0
  852. package/dist/timeline/types.d.ts.map +1 -0
  853. package/dist/timeline/types.js +9 -0
  854. package/dist/timeline/types.js.map +1 -0
  855. package/dist/types.d.ts +392 -0
  856. package/dist/types.d.ts.map +1 -0
  857. package/dist/types.js +81 -0
  858. package/dist/types.js.map +1 -0
  859. package/dist/ui/glyphs.d.ts +42 -0
  860. package/dist/ui/glyphs.d.ts.map +1 -0
  861. package/dist/ui/glyphs.js +78 -0
  862. package/dist/ui/glyphs.js.map +1 -0
  863. package/dist/ui/shimmer-progress.d.ts +11 -0
  864. package/dist/ui/shimmer-progress.d.ts.map +1 -0
  865. package/dist/ui/shimmer-progress.js +90 -0
  866. package/dist/ui/shimmer-progress.js.map +1 -0
  867. package/dist/ui/shimmer-worker.d.ts +2 -0
  868. package/dist/ui/shimmer-worker.d.ts.map +1 -0
  869. package/dist/ui/shimmer-worker.js +118 -0
  870. package/dist/ui/shimmer-worker.js.map +1 -0
  871. package/dist/ui/types.d.ts +17 -0
  872. package/dist/ui/types.d.ts.map +1 -0
  873. package/dist/ui/types.js +3 -0
  874. package/dist/ui/types.js.map +1 -0
  875. package/dist/upgrade/index.d.ts +132 -0
  876. package/dist/upgrade/index.d.ts.map +1 -0
  877. package/dist/upgrade/index.js +498 -0
  878. package/dist/upgrade/index.js.map +1 -0
  879. package/dist/utils.d.ts +224 -0
  880. package/dist/utils.d.ts.map +1 -0
  881. package/dist/utils.js +583 -0
  882. package/dist/utils.js.map +1 -0
  883. package/package.json +60 -0
  884. package/scripts/add-lang/bench.sh +60 -0
  885. package/scripts/add-lang/check-grammar.mjs +75 -0
  886. package/scripts/add-lang/dump-ast.mjs +103 -0
  887. package/scripts/add-lang/verify-extraction.mjs +70 -0
  888. package/scripts/agent-eval/ab-adoption.sh +91 -0
  889. package/scripts/agent-eval/ab-hook.sh +86 -0
  890. package/scripts/agent-eval/ab-impl.sh +78 -0
  891. package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -0
  892. package/scripts/agent-eval/ab-sufficiency.sh +78 -0
  893. package/scripts/agent-eval/arms-F.sh +21 -0
  894. package/scripts/agent-eval/arms-matrix.sh +37 -0
  895. package/scripts/agent-eval/audit.sh +68 -0
  896. package/scripts/agent-eval/bench-readme.sh +28 -0
  897. package/scripts/agent-eval/bench-why-repo.sh +22 -0
  898. package/scripts/agent-eval/block-read-hook.sh +19 -0
  899. package/scripts/agent-eval/hook-settings.json +15 -0
  900. package/scripts/agent-eval/itrun.sh +120 -0
  901. package/scripts/agent-eval/offload-eval-3arm.sh +72 -0
  902. package/scripts/agent-eval/offload-eval-cost.mjs +133 -0
  903. package/scripts/agent-eval/offload-eval-effort.mjs +108 -0
  904. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -0
  905. package/scripts/agent-eval/offload-eval-frontload.sh +47 -0
  906. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -0
  907. package/scripts/agent-eval/offload-eval-hook.mjs +84 -0
  908. package/scripts/agent-eval/offload-eval-judge.mjs +103 -0
  909. package/scripts/agent-eval/offload-eval-matrix.sh +20 -0
  910. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -0
  911. package/scripts/agent-eval/offload-eval-refs1.sh +50 -0
  912. package/scripts/agent-eval/offload-eval-setup.sh +24 -0
  913. package/scripts/agent-eval/offload-eval-styles.sh +72 -0
  914. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -0
  915. package/scripts/agent-eval/offload-eval.md +76 -0
  916. package/scripts/agent-eval/parse-arms.mjs +116 -0
  917. package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
  918. package/scripts/agent-eval/parse-run.mjs +45 -0
  919. package/scripts/agent-eval/parse-session.mjs +93 -0
  920. package/scripts/agent-eval/probe-context.mjs +21 -0
  921. package/scripts/agent-eval/probe-explore.mjs +40 -0
  922. package/scripts/agent-eval/probe-node.mjs +20 -0
  923. package/scripts/agent-eval/probe-sweep.mjs +119 -0
  924. package/scripts/agent-eval/probe-trace.mjs +20 -0
  925. package/scripts/agent-eval/redirect-read-hook.sh +38 -0
  926. package/scripts/agent-eval/run-agent.sh +34 -0
  927. package/scripts/agent-eval/run-all.sh +69 -0
  928. package/scripts/agent-eval/run-arms.sh +56 -0
  929. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  930. package/scripts/build-bundle.sh +118 -0
  931. package/scripts/extract-release-notes.mjs +130 -0
  932. package/scripts/local-install.sh +41 -0
  933. package/scripts/npm-sdk.js +75 -0
  934. package/scripts/npm-shim.js +246 -0
  935. package/scripts/pack-npm.sh +118 -0
  936. package/scripts/prepare-release.mjs +270 -0
@@ -0,0 +1,2014 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * cgraphx CLI
5
+ *
6
+ * Command-line interface for cgraphx code intelligence.
7
+ *
8
+ * Usage:
9
+ * cgraphx Run interactive installer (when no args)
10
+ * cgraphx install Run interactive installer
11
+ * cgraphx uninstall Remove cgraphx from your agents
12
+ * cgraphx init [path] Initialize cgraphx in a project
13
+ * cgraphx uninit [path] Remove cgraphx from a project
14
+ * cgraphx index [path] Index all files in the project
15
+ * cgraphx sync [path] Sync changes since last index
16
+ * cgraphx status [path] Show index status
17
+ * cgraphx query <search> Search for symbols
18
+ * cgraphx files [options] Show project file structure
19
+ * cgraphx context <task> Build context for a task
20
+ * cgraphx callers <symbol> Find what calls a function/method
21
+ * cgraphx callees <symbol> Find what a function/method calls
22
+ * cgraphx impact <symbol> Analyze what code is affected by changing a symbol
23
+ * cgraphx affected [files] Find test files affected by changes
24
+ * cgraphx upgrade [version] Update cgraphx to the latest release
25
+ */
26
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ var desc = Object.getOwnPropertyDescriptor(m, k);
29
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
30
+ desc = { enumerable: true, get: function() { return m[k]; } };
31
+ }
32
+ Object.defineProperty(o, k2, desc);
33
+ }) : (function(o, m, k, k2) {
34
+ if (k2 === undefined) k2 = k;
35
+ o[k2] = m[k];
36
+ }));
37
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
38
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
39
+ }) : function(o, v) {
40
+ o["default"] = v;
41
+ });
42
+ var __importStar = (this && this.__importStar) || (function () {
43
+ var ownKeys = function(o) {
44
+ ownKeys = Object.getOwnPropertyNames || function (o) {
45
+ var ar = [];
46
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
47
+ return ar;
48
+ };
49
+ return ownKeys(o);
50
+ };
51
+ return function (mod) {
52
+ if (mod && mod.__esModule) return mod;
53
+ var result = {};
54
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
55
+ __setModuleDefault(result, mod);
56
+ return result;
57
+ };
58
+ })();
59
+ Object.defineProperty(exports, "__esModule", { value: true });
60
+ const commander_1 = require("commander");
61
+ const path = __importStar(require("path"));
62
+ const fs = __importStar(require("fs"));
63
+ const directory_1 = require("../directory");
64
+ const worktree_1 = require("../sync/worktree");
65
+ const shimmer_progress_1 = require("../ui/shimmer-progress");
66
+ const glyphs_1 = require("../ui/glyphs");
67
+ const node_version_check_1 = require("./node-version-check");
68
+ const fatal_handler_1 = require("./fatal-handler");
69
+ const wasm_runtime_flags_1 = require("../extraction/wasm-runtime-flags");
70
+ const extraction_version_1 = require("../extraction/extraction-version");
71
+ const telemetry_1 = require("../telemetry");
72
+ const cli_1 = require("../markdown/cli");
73
+ const cli_2 = require("../dbquery/cli");
74
+ const cli_3 = require("../timeline/cli");
75
+ const upgrade_1 = require("../upgrade");
76
+ // Lazy-load heavy modules (CodeGraph, runInstaller) to keep CLI startup fast.
77
+ async function loadCodeGraph() {
78
+ try {
79
+ return await Promise.resolve().then(() => __importStar(require('../index')));
80
+ }
81
+ catch (err) {
82
+ const msg = err instanceof Error ? err.message : String(err);
83
+ console.error(`\x1b[31m${(0, glyphs_1.getGlyphs)().err}\x1b[0m Failed to load cgraphx modules.`);
84
+ console.error(`\n Node: ${process.version} Platform: ${process.platform} ${process.arch}`);
85
+ console.error(`\n Error: ${msg}`);
86
+ console.error(`\n Try reinstalling with: npm install -g ${upgrade_1.NPM_PACKAGE}\n`);
87
+ process.exit(1);
88
+ }
89
+ }
90
+ // Dynamic import helper — tsc compiles import() to require() in CJS mode,
91
+ // which fails for ESM-only packages. This bypasses the transformation.
92
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
93
+ const importESM = new Function('specifier', 'return import(specifier)');
94
+ // Block cgraphx on Node.js 25.x — V8's turboshaft WASM JIT has a Zone
95
+ // allocator bug that reliably crashes when compiling tree-sitter
96
+ // grammars (see #54, #81, #140). The previous behaviour was a soft
97
+ // console.warn that scrolls off-screen before the OOM crash 30 seconds
98
+ // later, leading to a steady stream of "what is this OOM" reports.
99
+ // Node 25.x hard-exits (known V8 turboshaft Zone OOM, #81). Node 26+ is
100
+ // unverified but not blocked — the launcher's --liftoff-only flag keeps
101
+ // tree-sitter on the Liftoff baseline compiler, away from the turboshaft
102
+ // path where the bug lives, so the same crash should not fire. We still
103
+ // warn loudly so users know they're off the verified track.
104
+ const nodeVersion = process.versions.node;
105
+ const nodeMajor = parseInt(nodeVersion.split('.')[0] ?? '0', 10);
106
+ if (nodeMajor === 25) {
107
+ process.stderr.write((0, node_version_check_1.buildNode25BlockBanner)(nodeVersion) + '\n');
108
+ if (!process.env.CGRAPHX_ALLOW_UNSAFE_NODE) {
109
+ process.exit(1);
110
+ }
111
+ // Override active — banner shown for visibility, continuing.
112
+ }
113
+ else if (nodeMajor >= 26) {
114
+ process.stderr.write((0, node_version_check_1.buildNodeUntestedBanner)(nodeVersion) + '\n');
115
+ // No exit — warning only.
116
+ }
117
+ // Enforce the supported Node floor. `engines` in package.json only *warns* on
118
+ // install (unless engine-strict), so hard-block here to actually keep users off
119
+ // unsupported versions. Mirrors the 25+ block above. See package.json `engines`.
120
+ if (nodeMajor < node_version_check_1.MIN_NODE_MAJOR) {
121
+ process.stderr.write((0, node_version_check_1.buildNodeTooOldBanner)(nodeVersion) + '\n');
122
+ if (!process.env.CGRAPHX_ALLOW_UNSAFE_NODE) {
123
+ process.exit(1);
124
+ }
125
+ // Override active — banner shown for visibility, continuing.
126
+ }
127
+ // Re-exec with V8's `--liftoff-only` if it isn't already set, so tree-sitter's
128
+ // large WASM grammars never hit the turboshaft Zone OOM (`Fatal process out of
129
+ // memory: Zone`) on Node >= 22. No-op under the bundled launcher, which already
130
+ // passes the flag. Must run before any grammar (in the parse worker, which
131
+ // inherits this process's flags) is compiled. See ../extraction/wasm-runtime-flags.
132
+ (0, wasm_runtime_flags_1.relaunchWithWasmRuntimeFlagsIfNeeded)(__filename);
133
+ // Last-resort fatal handlers: log a bounded line and exit non-zero. A fault
134
+ // that reaches here escaped every boundary, so the process is in an undefined
135
+ // state — keeping it alive is what let the detached MCP daemon orphan and pin a
136
+ // CPU core with no recovery (#799, #850). Installed before the command branch
137
+ // so it also covers a synchronous throw during startup. See ./fatal-handler.
138
+ (0, fatal_handler_1.installFatalHandlers)();
139
+ // Check if running with no arguments - run installer
140
+ if (process.argv.length === 2) {
141
+ Promise.resolve().then(() => __importStar(require('../installer'))).then(({ runInstaller }) => runInstaller()).catch((err) => {
142
+ console.error('Installation failed:', err instanceof Error ? err.message : String(err));
143
+ process.exit(1);
144
+ });
145
+ }
146
+ else {
147
+ // Normal CLI flow
148
+ main();
149
+ }
150
+ function main() {
151
+ const program = new commander_1.Command();
152
+ // Version from package.json
153
+ const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf-8'));
154
+ // Make the version trivial to reach. commander's `.version()` (below) wires up
155
+ // `--version` and `-V`; intercept the spellings it can't — lowercase `-v` and
156
+ // single-dash `-version` — before any parsing. (commander's version short flag
157
+ // is the capital `-V`, and its parser rejects a multi-character single-dash
158
+ // flag.) The bare `cgraphx version` subcommand is registered further down so
159
+ // the affordance also shows up in `cgraphx --help`.
160
+ const firstArg = process.argv[2];
161
+ if (firstArg === '-v' || firstArg === '-version') {
162
+ console.log(packageJson.version);
163
+ return;
164
+ }
165
+ // =============================================================================
166
+ // ANSI Color Helpers (avoid chalk ESM issues)
167
+ // =============================================================================
168
+ const colors = {
169
+ reset: '\x1b[0m',
170
+ bold: '\x1b[1m',
171
+ dim: '\x1b[2m',
172
+ red: '\x1b[31m',
173
+ green: '\x1b[32m',
174
+ yellow: '\x1b[33m',
175
+ blue: '\x1b[34m',
176
+ cyan: '\x1b[36m',
177
+ white: '\x1b[37m',
178
+ gray: '\x1b[90m',
179
+ };
180
+ const chalk = {
181
+ bold: (s) => `${colors.bold}${s}${colors.reset}`,
182
+ dim: (s) => `${colors.dim}${s}${colors.reset}`,
183
+ red: (s) => `${colors.red}${s}${colors.reset}`,
184
+ green: (s) => `${colors.green}${s}${colors.reset}`,
185
+ yellow: (s) => `${colors.yellow}${s}${colors.reset}`,
186
+ blue: (s) => `${colors.blue}${s}${colors.reset}`,
187
+ cyan: (s) => `${colors.cyan}${s}${colors.reset}`,
188
+ white: (s) => `${colors.white}${s}${colors.reset}`,
189
+ gray: (s) => `${colors.gray}${s}${colors.reset}`,
190
+ };
191
+ program
192
+ .name('cgraphx')
193
+ .description('Code intelligence and knowledge graph for any codebase')
194
+ .version(packageJson.version);
195
+ // Anonymous usage telemetry (see TELEMETRY.md): record the invoked subcommand
196
+ // NAME only — never arguments or paths. Counts buffer locally; network sends
197
+ // piggyback on commands that run long anyway (quick commands only append to
198
+ // the local buffer at exit, costing nothing).
199
+ // install/uninstall are absent on purpose: the installer flushes at its own
200
+ // end, AFTER its consent prompt — a flush here would fire the first-run
201
+ // notice before the user ever sees the toggle.
202
+ const TELEMETRY_FLUSH_COMMANDS = new Set(['init', 'uninit', 'index', 'sync', 'upgrade']);
203
+ program.hook('preAction', (_thisCommand, actionCommand) => {
204
+ try {
205
+ // The detached daemon re-invokes `serve --mcp` internally — not a user action.
206
+ if (process.env.CGRAPHX_DAEMON_INTERNAL)
207
+ return;
208
+ const name = actionCommand.name();
209
+ if (name === 'telemetry')
210
+ return; // managing telemetry is not usage
211
+ (0, telemetry_1.getTelemetry)().recordUsage('cli_command', name, true);
212
+ if (TELEMETRY_FLUSH_COMMANDS.has(name))
213
+ (0, telemetry_1.getTelemetry)().maybeFlush();
214
+ }
215
+ catch {
216
+ /* telemetry must never break the CLI */
217
+ }
218
+ });
219
+ // =============================================================================
220
+ // Helper Functions
221
+ // =============================================================================
222
+ /**
223
+ * Resolve project path from argument or current directory
224
+ * Walks up parent directories to find nearest initialized cgraphx project
225
+ * (must have .cgraphx/cgraphx.db, not just .cgraphx/lessons.db)
226
+ */
227
+ function resolveProjectPath(pathArg) {
228
+ const absolutePath = path.resolve(pathArg || process.cwd());
229
+ // If exact path is initialized (has cgraphx.db), use it
230
+ if ((0, directory_1.isInitialized)(absolutePath)) {
231
+ return absolutePath;
232
+ }
233
+ // Walk up to find nearest parent with cgraphx initialized
234
+ // Note: findNearestCodeGraphRoot finds any .cgraphx folder, but we need one with cgraphx.db
235
+ let current = absolutePath;
236
+ const root = path.parse(current).root;
237
+ while (current !== root) {
238
+ const parent = path.dirname(current);
239
+ if (parent === current)
240
+ break;
241
+ current = parent;
242
+ if ((0, directory_1.isInitialized)(current)) {
243
+ return current;
244
+ }
245
+ }
246
+ // Not found - return original path (will fail later with helpful error)
247
+ return absolutePath;
248
+ }
249
+ /**
250
+ * Format a number with commas
251
+ */
252
+ function formatNumber(n) {
253
+ return n.toLocaleString();
254
+ }
255
+ /**
256
+ * Format duration in milliseconds to human readable
257
+ */
258
+ function formatDuration(ms) {
259
+ if (ms < 1000) {
260
+ return `${ms}ms`;
261
+ }
262
+ const seconds = ms / 1000;
263
+ if (seconds < 60) {
264
+ return `${seconds.toFixed(1)}s`;
265
+ }
266
+ const minutes = Math.floor(seconds / 60);
267
+ const remainingSeconds = seconds % 60;
268
+ return `${minutes}m ${remainingSeconds.toFixed(0)}s`;
269
+ }
270
+ // Shimmer progress renderer (runs in a worker thread for smooth animation)
271
+ // Imported at top of file from '../ui/shimmer-progress'
272
+ /**
273
+ * Create a plain-text progress callback for --verbose mode.
274
+ * No animations, no ANSI tricks — just timestamped lines to stdout.
275
+ */
276
+ function createVerboseProgress() {
277
+ let lastPhase = '';
278
+ let lastPct = -1;
279
+ const startTime = Date.now();
280
+ return (progress) => {
281
+ const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
282
+ if (progress.phase !== lastPhase) {
283
+ lastPhase = progress.phase;
284
+ lastPct = -1;
285
+ console.log(`[${elapsed}s] Phase: ${progress.phase}`);
286
+ }
287
+ if (progress.total > 0) {
288
+ const pct = Math.floor((progress.current / progress.total) * 100);
289
+ // Log every 5% to keep output manageable
290
+ if (pct >= lastPct + 5 || progress.current === progress.total) {
291
+ lastPct = pct;
292
+ console.log(`[${elapsed}s] ${progress.current}/${progress.total} (${pct}%)${progress.currentFile ? ` ${(0, glyphs_1.getGlyphs)().dash} ${progress.currentFile}` : ''}`);
293
+ }
294
+ }
295
+ else if (progress.current > 0) {
296
+ // Scanning phase (no total yet) — log periodically
297
+ if (progress.current % 1000 === 0 || progress.current === 1) {
298
+ console.log(`[${elapsed}s] ${formatNumber(progress.current)} files found`);
299
+ }
300
+ }
301
+ };
302
+ }
303
+ /**
304
+ * Print success message
305
+ */
306
+ function success(message) {
307
+ console.log(chalk.green((0, glyphs_1.getGlyphs)().ok) + ' ' + message);
308
+ }
309
+ /**
310
+ * Print error message
311
+ */
312
+ function error(message) {
313
+ console.error(chalk.red((0, glyphs_1.getGlyphs)().err) + ' ' + message);
314
+ }
315
+ /**
316
+ * Print info message
317
+ */
318
+ function info(message) {
319
+ console.log(chalk.blue((0, glyphs_1.getGlyphs)().info) + ' ' + message);
320
+ }
321
+ /**
322
+ * Print warning message
323
+ */
324
+ function warn(message) {
325
+ console.log(chalk.yellow((0, glyphs_1.getGlyphs)().warn) + ' ' + message);
326
+ }
327
+ /**
328
+ * Print indexing results using clack log methods
329
+ */
330
+ function printIndexResult(clack, result, projectPath) {
331
+ const hasErrors = result.filesErrored > 0;
332
+ // Surface non-file-level failures (e.g. lock-acquisition failure
333
+ // when another indexer is running) before the file-count branches.
334
+ // Without this the CLI falls through to "No files found to index",
335
+ // which is actively misleading — the index DID run, it just couldn't
336
+ // get the lock.
337
+ //
338
+ // If success is false but no severity:'error' entry exists in
339
+ // `result.errors` (degenerate case — shouldn't happen in practice
340
+ // but worth guarding because the result shape is plumbed through
341
+ // multiple call sites), fall back to a generic message rather than
342
+ // continuing to the misleading "No files found" branch or throwing.
343
+ if (!result.success && !hasErrors && result.filesIndexed === 0) {
344
+ const generic = result.errors.find((e) => e.severity === 'error');
345
+ clack.log.error(generic?.message ?? `Indexing failed ${(0, glyphs_1.getGlyphs)().dash} no further details available`);
346
+ return;
347
+ }
348
+ if (result.filesIndexed > 0) {
349
+ if (hasErrors) {
350
+ clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files (${formatNumber(result.filesErrored)} could not be parsed)`);
351
+ }
352
+ else {
353
+ clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files`);
354
+ }
355
+ clack.log.info(`${formatNumber(result.nodesCreated)} nodes, ${formatNumber(result.edgesCreated)} edges in ${formatDuration(result.durationMs)}`);
356
+ }
357
+ else if (hasErrors) {
358
+ clack.log.error(`Indexing failed ${(0, glyphs_1.getGlyphs)().dash} all ${formatNumber(result.filesErrored)} files had errors`);
359
+ }
360
+ else {
361
+ clack.log.warn('No files found to index');
362
+ }
363
+ if (hasErrors) {
364
+ const errorsByCode = new Map();
365
+ for (const err of result.errors) {
366
+ if (err.severity === 'error') {
367
+ const code = err.code || 'unknown';
368
+ errorsByCode.set(code, (errorsByCode.get(code) || 0) + 1);
369
+ }
370
+ }
371
+ const codeLabels = {
372
+ parse_error: 'files failed to parse',
373
+ read_error: 'files could not be read',
374
+ size_exceeded: 'files exceeded size limit',
375
+ path_traversal: 'blocked paths',
376
+ unsupported_language: 'unsupported language',
377
+ parser_error: 'parser initialization failures',
378
+ };
379
+ const breakdown = Array.from(errorsByCode)
380
+ .map(([code, count]) => `${formatNumber(count)} ${codeLabels[code] || code}`)
381
+ .join('\n');
382
+ clack.note(breakdown, 'Error breakdown');
383
+ if (projectPath) {
384
+ writeErrorLog(projectPath, result.errors);
385
+ clack.log.info('See .cgraphx/errors.log for details');
386
+ }
387
+ if (result.filesIndexed > 0) {
388
+ clack.log.info(`The index is fully usable ${(0, glyphs_1.getGlyphs)().dash} only the failed files are missing.`);
389
+ }
390
+ }
391
+ else if (projectPath) {
392
+ const logPath = path.join((0, directory_1.getCodeGraphDir)(projectPath), 'errors.log');
393
+ if (fs.existsSync(logPath)) {
394
+ fs.unlinkSync(logPath);
395
+ }
396
+ }
397
+ }
398
+ /**
399
+ * Write detailed error log to .cgraphx/errors.log
400
+ */
401
+ function writeErrorLog(projectPath, errors) {
402
+ const cgDir = (0, directory_1.getCodeGraphDir)(projectPath);
403
+ if (!fs.existsSync(cgDir))
404
+ return;
405
+ const logPath = path.join(cgDir, 'errors.log');
406
+ // Group errors by file path
407
+ const errorsByFile = new Map();
408
+ const noFileErrors = [];
409
+ for (const err of errors) {
410
+ if (err.severity !== 'error')
411
+ continue;
412
+ if (err.filePath) {
413
+ let list = errorsByFile.get(err.filePath);
414
+ if (!list) {
415
+ list = [];
416
+ errorsByFile.set(err.filePath, list);
417
+ }
418
+ list.push({ message: err.message, code: err.code });
419
+ }
420
+ else {
421
+ noFileErrors.push({ message: err.message, code: err.code });
422
+ }
423
+ }
424
+ const lines = [
425
+ `cgraphx Error Log - ${new Date().toISOString()}`,
426
+ `${errorsByFile.size} files with errors`,
427
+ '',
428
+ ];
429
+ for (const [filePath, fileErrors] of errorsByFile) {
430
+ for (const err of fileErrors) {
431
+ lines.push(`${filePath}: ${err.message}`);
432
+ }
433
+ }
434
+ for (const err of noFileErrors) {
435
+ lines.push(err.message);
436
+ }
437
+ fs.writeFileSync(logPath, lines.join('\n') + '\n');
438
+ }
439
+ /**
440
+ * Telemetry for a completed full index (see TELEMETRY.md). The bounded flush
441
+ * keeps init/index responsive (these commands just ran for seconds anyway)
442
+ * while delivering the event promptly.
443
+ */
444
+ async function recordIndexTelemetry(cg, result) {
445
+ (0, telemetry_1.recordIndexEvent)(cg, result);
446
+ await (0, telemetry_1.getTelemetry)().flushNow();
447
+ }
448
+ // =============================================================================
449
+ // Commands
450
+ // =============================================================================
451
+ /**
452
+ * cgraphx init [path]
453
+ */
454
+ program
455
+ .command('init [path]')
456
+ .description('Initialize cgraphx in a project directory and build the initial index')
457
+ .option('-i, --index', 'Deprecated: indexing now runs by default; flag accepted for backward compatibility')
458
+ .option('-f, --force', 'Initialize even if the path looks like your home directory or a filesystem root')
459
+ .option('-v, --verbose', 'Show detailed worker lifecycle and memory info')
460
+ .action(async (pathArg, options) => {
461
+ const projectPath = path.resolve(pathArg || process.cwd());
462
+ const clack = await importESM('@clack/prompts');
463
+ clack.intro('Initializing cgraphx');
464
+ try {
465
+ // Refuse to index your home directory / a filesystem root — it pulls in
466
+ // caches, other projects, and your whole tree (a multi-GB index + watcher
467
+ // churn, and on pre-1.0 macOS a machine-crashing fd blowup, #845).
468
+ const unsafe = (0, directory_1.unsafeIndexRootReason)(projectPath);
469
+ if (unsafe && !options.force) {
470
+ clack.log.error(`Refusing to initialize in ${projectPath} — it looks like ${unsafe}.`);
471
+ clack.log.info('Run this inside a specific project directory, or pass --force if you really mean to index everything under it.');
472
+ clack.outro('');
473
+ process.exitCode = 1;
474
+ return;
475
+ }
476
+ if ((0, directory_1.isInitialized)(projectPath)) {
477
+ clack.log.warn(`Already initialized in ${projectPath}`);
478
+ clack.log.info('Use "cgraphx index" to re-index or "cgraphx sync" to update');
479
+ try {
480
+ const { offerWatchFallback } = await Promise.resolve().then(() => __importStar(require('../installer')));
481
+ await offerWatchFallback(clack, projectPath);
482
+ }
483
+ catch { /* non-fatal */ }
484
+ clack.outro('');
485
+ return;
486
+ }
487
+ const { default: CodeGraph } = await loadCodeGraph();
488
+ const cg = await CodeGraph.init(projectPath, { index: false });
489
+ clack.log.success(`Initialized in ${projectPath}`);
490
+ // Indexing runs by default now. The legacy -i/--index flag is still
491
+ // accepted (so existing muscle memory and scripts don't break) but is a
492
+ // no-op — initializing always builds the initial index.
493
+ let result;
494
+ if (options.verbose) {
495
+ result = await cg.indexAll({
496
+ onProgress: createVerboseProgress(),
497
+ verbose: true,
498
+ });
499
+ }
500
+ else {
501
+ process.stdout.write(`${colors.dim}${(0, glyphs_1.getGlyphs)().rail}${colors.reset}\n`);
502
+ const progress = (0, shimmer_progress_1.createShimmerProgress)();
503
+ result = await cg.indexAll({
504
+ onProgress: progress.onProgress,
505
+ });
506
+ await progress.stop();
507
+ }
508
+ printIndexResult(clack, result, projectPath);
509
+ await recordIndexTelemetry(cg, result);
510
+ try {
511
+ const { offerWatchFallback } = await Promise.resolve().then(() => __importStar(require('../installer')));
512
+ await offerWatchFallback(clack, projectPath);
513
+ }
514
+ catch { /* non-fatal */ }
515
+ clack.outro('Done');
516
+ cg.destroy();
517
+ }
518
+ catch (err) {
519
+ clack.log.error(`Failed: ${err instanceof Error ? err.message : String(err)}`);
520
+ process.exit(1);
521
+ }
522
+ });
523
+ /**
524
+ * cgraphx uninit [path]
525
+ */
526
+ program
527
+ .command('uninit [path]')
528
+ .description('Remove cgraphx from a project (deletes .cgraphx/ directory)')
529
+ .option('-f, --force', 'Skip confirmation prompt')
530
+ .action(async (pathArg, options) => {
531
+ const projectPath = resolveProjectPath(pathArg);
532
+ try {
533
+ if (!(0, directory_1.isInitialized)(projectPath)) {
534
+ warn(`cgraphx is not initialized in ${projectPath}`);
535
+ return;
536
+ }
537
+ if (!options.force) {
538
+ // Confirm with user
539
+ const readline = await Promise.resolve().then(() => __importStar(require('readline')));
540
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
541
+ const answer = await new Promise((resolve) => {
542
+ rl.question(chalk.yellow(`${(0, glyphs_1.getGlyphs)().warn} This will permanently delete all cgraphx data. Continue? (y/N) `), resolve);
543
+ });
544
+ rl.close();
545
+ if (answer.toLowerCase() !== 'y') {
546
+ info('Cancelled');
547
+ return;
548
+ }
549
+ }
550
+ const { default: CodeGraph } = await loadCodeGraph();
551
+ const cg = CodeGraph.openSync(projectPath);
552
+ cg.uninitialize();
553
+ // Clean up any git sync hooks we installed (no-op if none / not a repo).
554
+ try {
555
+ const { removeGitSyncHook } = await Promise.resolve().then(() => __importStar(require('../sync/git-hooks')));
556
+ const removed = removeGitSyncHook(projectPath);
557
+ if (removed.installed.length > 0) {
558
+ info(`Removed git ${removed.installed.join(', ')} sync hook${removed.installed.length > 1 ? 's' : ''}`);
559
+ }
560
+ }
561
+ catch { /* non-fatal */ }
562
+ success(`Removed cgraphx from ${projectPath}`);
563
+ // Churn signal — and flush now, since after an uninit there may be no
564
+ // "next run" to deliver it.
565
+ try {
566
+ (0, telemetry_1.getTelemetry)().recordLifecycle('uninstall', {});
567
+ await (0, telemetry_1.getTelemetry)().flushNow();
568
+ }
569
+ catch { /* non-fatal */ }
570
+ }
571
+ catch (err) {
572
+ error(`Failed to uninitialize: ${err instanceof Error ? err.message : String(err)}`);
573
+ process.exit(1);
574
+ }
575
+ });
576
+ /**
577
+ * cgraphx index [path]
578
+ */
579
+ program
580
+ .command('index [path]')
581
+ .description('Rebuild the full index from scratch (same result as a fresh init)')
582
+ .option('-f, --force', 'Index even if the path looks like your home directory or a filesystem root')
583
+ .option('-q, --quiet', 'Suppress progress output')
584
+ .option('-v, --verbose', 'Show detailed worker lifecycle and memory info')
585
+ .action(async (pathArg, options) => {
586
+ const projectPath = resolveProjectPath(pathArg);
587
+ try {
588
+ // Don't (re)index your home directory / a filesystem root (#845). --force
589
+ // doubles as the override.
590
+ const unsafe = (0, directory_1.unsafeIndexRootReason)(projectPath);
591
+ if (unsafe && !options.force) {
592
+ error(`Refusing to index ${projectPath} — it looks like ${unsafe}. Pass --force to override.`);
593
+ process.exit(1);
594
+ }
595
+ if (!(0, directory_1.isInitialized)(projectPath)) {
596
+ error(`cgraphx not initialized in ${projectPath}`);
597
+ info('Run "cgraphx init" first');
598
+ process.exit(1);
599
+ }
600
+ const { default: CodeGraph } = await loadCodeGraph();
601
+ const cg = await CodeGraph.open(projectPath);
602
+ if (options.quiet) {
603
+ // Quiet mode: no UI, just run. `index` is a full re-index, so clear the
604
+ // existing graph and rebuild from scratch (see the note below — #874).
605
+ cg.clear();
606
+ const result = await cg.indexAll();
607
+ if (!result.success)
608
+ process.exit(1);
609
+ cg.destroy();
610
+ return;
611
+ }
612
+ const clack = await importESM('@clack/prompts');
613
+ clack.intro('Indexing project');
614
+ // `index` is a FULL re-index: clear the existing graph and rebuild it from
615
+ // scratch so the result is identical to a fresh `init`. Without the clear,
616
+ // indexAll() skips every unchanged file by its content hash and reports
617
+ // "0 nodes, 0 edges" against the already-populated graph — which reads as
618
+ // "index wiped my index" (#874). For fast incremental updates use `sync`.
619
+ cg.clear();
620
+ let result;
621
+ if (options.verbose) {
622
+ result = await cg.indexAll({
623
+ onProgress: createVerboseProgress(),
624
+ verbose: true,
625
+ });
626
+ }
627
+ else {
628
+ process.stdout.write(`${colors.dim}${(0, glyphs_1.getGlyphs)().rail}${colors.reset}\n`);
629
+ const progress = (0, shimmer_progress_1.createShimmerProgress)();
630
+ result = await cg.indexAll({
631
+ onProgress: progress.onProgress,
632
+ });
633
+ await progress.stop();
634
+ }
635
+ printIndexResult(clack, result, projectPath);
636
+ await recordIndexTelemetry(cg, result);
637
+ if (!result.success) {
638
+ process.exit(1);
639
+ }
640
+ clack.outro('Done');
641
+ cg.destroy();
642
+ }
643
+ catch (err) {
644
+ error(`Failed to index: ${err instanceof Error ? err.message : String(err)}`);
645
+ process.exit(1);
646
+ }
647
+ });
648
+ /**
649
+ * cgraphx sync [path]
650
+ */
651
+ program
652
+ .command('sync [path]')
653
+ .description('Sync changes since last index')
654
+ .option('-q, --quiet', 'Suppress output (for git hooks)')
655
+ .action(async (pathArg, options) => {
656
+ const projectPath = resolveProjectPath(pathArg);
657
+ try {
658
+ if (!(0, directory_1.isInitialized)(projectPath)) {
659
+ if (!options.quiet) {
660
+ error(`cgraphx not initialized in ${projectPath}`);
661
+ }
662
+ process.exit(1);
663
+ }
664
+ const { default: CodeGraph } = await loadCodeGraph();
665
+ const cg = await CodeGraph.open(projectPath);
666
+ if (options.quiet) {
667
+ await cg.sync();
668
+ cg.destroy();
669
+ return;
670
+ }
671
+ const clack = await importESM('@clack/prompts');
672
+ clack.intro('Syncing cgraphx');
673
+ process.stdout.write(`${colors.dim}${(0, glyphs_1.getGlyphs)().rail}${colors.reset}\n`);
674
+ const progress = (0, shimmer_progress_1.createShimmerProgress)();
675
+ const result = await cg.sync({
676
+ onProgress: progress.onProgress,
677
+ });
678
+ await progress.stop();
679
+ const totalChanges = result.filesAdded + result.filesModified + result.filesRemoved;
680
+ if (totalChanges === 0) {
681
+ clack.log.info('Already up to date');
682
+ }
683
+ else {
684
+ clack.log.success(`Synced ${formatNumber(totalChanges)} changed files`);
685
+ const details = [];
686
+ if (result.filesAdded > 0)
687
+ details.push(`Added: ${result.filesAdded}`);
688
+ if (result.filesModified > 0)
689
+ details.push(`Modified: ${result.filesModified}`);
690
+ if (result.filesRemoved > 0)
691
+ details.push(`Removed: ${result.filesRemoved}`);
692
+ clack.log.info(`${details.join(', ')} ${(0, glyphs_1.getGlyphs)().dash} ${formatNumber(result.nodesUpdated)} nodes in ${formatDuration(result.durationMs)}`);
693
+ }
694
+ clack.outro('Done');
695
+ cg.destroy();
696
+ }
697
+ catch (err) {
698
+ if (!options.quiet) {
699
+ error(`Failed to sync: ${err instanceof Error ? err.message : String(err)}`);
700
+ }
701
+ process.exit(1);
702
+ }
703
+ });
704
+ /**
705
+ * cgraphx status [path]
706
+ */
707
+ program
708
+ .command('status [path]')
709
+ .description('Show index status and statistics')
710
+ .option('-j, --json', 'Output as JSON')
711
+ .action(async (pathArg, options) => {
712
+ const projectPath = resolveProjectPath(pathArg);
713
+ // The directory the user actually ran from, before walking up to the index
714
+ // root. Used to detect when the resolved index lives in a different git
715
+ // working tree (e.g. a nested worktree borrowing the main checkout's index).
716
+ const startPath = path.resolve(pathArg || process.cwd());
717
+ const worktreeMismatch = (0, worktree_1.detectWorktreeIndexMismatch)(startPath, projectPath);
718
+ try {
719
+ if (!(0, directory_1.isInitialized)(projectPath)) {
720
+ if (options.json) {
721
+ console.log(JSON.stringify({
722
+ initialized: false,
723
+ version: packageJson.version,
724
+ projectPath,
725
+ indexPath: (0, directory_1.getCodeGraphDir)(projectPath),
726
+ lastIndexed: null,
727
+ }));
728
+ return;
729
+ }
730
+ console.log(chalk.bold('\ncgraphx Status\n'));
731
+ info(`Project: ${projectPath}`);
732
+ warn('Not initialized');
733
+ info('Run "cgraphx init" to initialize');
734
+ return;
735
+ }
736
+ const { default: CodeGraph } = await loadCodeGraph();
737
+ const cg = await CodeGraph.open(projectPath);
738
+ const stats = cg.getStats();
739
+ const changes = cg.getChangedFiles();
740
+ const backend = cg.getBackend();
741
+ const journalMode = cg.getJournalMode();
742
+ const buildInfo = cg.getIndexBuildInfo();
743
+ const reindexRecommended = cg.isIndexStale();
744
+ // JSON output mode
745
+ if (options.json) {
746
+ const lastIndexedMs = cg.getLastIndexedAt();
747
+ console.log(JSON.stringify({
748
+ initialized: true,
749
+ version: packageJson.version,
750
+ projectPath,
751
+ indexPath: (0, directory_1.getCodeGraphDir)(projectPath),
752
+ lastIndexed: lastIndexedMs != null ? new Date(lastIndexedMs).toISOString() : null,
753
+ fileCount: stats.fileCount,
754
+ nodeCount: stats.nodeCount,
755
+ edgeCount: stats.edgeCount,
756
+ dbSizeBytes: stats.dbSizeBytes,
757
+ backend,
758
+ journalMode,
759
+ nodesByKind: stats.nodesByKind,
760
+ languages: Object.entries(stats.filesByLanguage).filter(([, count]) => count > 0).map(([lang]) => lang),
761
+ pendingChanges: {
762
+ added: changes.added.length,
763
+ modified: changes.modified.length,
764
+ removed: changes.removed.length,
765
+ },
766
+ worktreeMismatch: worktreeMismatch
767
+ ? { worktreeRoot: worktreeMismatch.worktreeRoot, indexRoot: worktreeMismatch.indexRoot }
768
+ : null,
769
+ index: {
770
+ builtWithVersion: buildInfo.version,
771
+ builtWithExtractionVersion: buildInfo.extractionVersion,
772
+ currentExtractionVersion: extraction_version_1.EXTRACTION_VERSION,
773
+ reindexRecommended,
774
+ },
775
+ }));
776
+ cg.destroy();
777
+ return;
778
+ }
779
+ console.log(chalk.bold('\ncgraphx Status\n'));
780
+ // Project info
781
+ console.log(chalk.cyan('Project:'), projectPath);
782
+ if (worktreeMismatch) {
783
+ warn((0, worktree_1.worktreeMismatchWarning)(worktreeMismatch));
784
+ }
785
+ console.log();
786
+ // Index stats
787
+ console.log(chalk.bold('Index Statistics:'));
788
+ console.log(` Files: ${formatNumber(stats.fileCount)}`);
789
+ console.log(` Nodes: ${formatNumber(stats.nodeCount)}`);
790
+ console.log(` Edges: ${formatNumber(stats.edgeCount)}`);
791
+ console.log(` DB Size: ${(stats.dbSizeBytes / 1024 / 1024).toFixed(2)} MB`);
792
+ // Surface the active SQLite backend (node:sqlite — Node's built-in real
793
+ // SQLite, full WAL + FTS5, no native build).
794
+ const backendLabel = chalk.green(`node:sqlite ${(0, glyphs_1.getGlyphs)().dash} built-in (full WAL)`);
795
+ console.log(` Backend: ${backendLabel}`);
796
+ // Effective journal mode: 'wal' means concurrent reads never block on a
797
+ // writer; anything else means they can ("database is locked"). node:sqlite
798
+ // supports WAL everywhere, so a non-wal mode means the filesystem can't
799
+ // (network mounts, WSL2 /mnt). See issue #238.
800
+ const journalLabel = journalMode === 'wal'
801
+ ? chalk.green('wal')
802
+ : chalk.yellow(`${journalMode || 'unknown'} ${(0, glyphs_1.getGlyphs)().dash} WAL inactive; reads can block on writes`);
803
+ console.log(` Journal: ${journalLabel}`);
804
+ console.log();
805
+ // Node breakdown
806
+ console.log(chalk.bold('Nodes by Kind:'));
807
+ const nodesByKind = Object.entries(stats.nodesByKind)
808
+ .filter(([, count]) => count > 0)
809
+ .sort((a, b) => b[1] - a[1]);
810
+ for (const [kind, count] of nodesByKind) {
811
+ console.log(` ${kind.padEnd(15)} ${formatNumber(count)}`);
812
+ }
813
+ console.log();
814
+ // Language breakdown
815
+ console.log(chalk.bold('Files by Language:'));
816
+ const filesByLang = Object.entries(stats.filesByLanguage)
817
+ .filter(([, count]) => count > 0)
818
+ .sort((a, b) => b[1] - a[1]);
819
+ for (const [lang, count] of filesByLang) {
820
+ console.log(` ${lang.padEnd(15)} ${formatNumber(count)}`);
821
+ }
822
+ console.log();
823
+ // Pending changes
824
+ const totalChanges = changes.added.length + changes.modified.length + changes.removed.length;
825
+ if (totalChanges > 0) {
826
+ console.log(chalk.bold('Pending Changes:'));
827
+ if (changes.added.length > 0) {
828
+ console.log(` Added: ${changes.added.length} files`);
829
+ }
830
+ if (changes.modified.length > 0) {
831
+ console.log(` Modified: ${changes.modified.length} files`);
832
+ }
833
+ if (changes.removed.length > 0) {
834
+ console.log(` Removed: ${changes.removed.length} files`);
835
+ }
836
+ info('Run "cgraphx sync" to update the index');
837
+ }
838
+ else {
839
+ success('Index is up to date');
840
+ }
841
+ console.log();
842
+ // Re-index hint: the index was built by an older engine than the one now
843
+ // running, so a rebuild would add data a migration can't backfill.
844
+ if (reindexRecommended) {
845
+ const builtWith = buildInfo.version ? `v${buildInfo.version.replace(/^v/, '')}` : 'an earlier version';
846
+ warn(`Index was built by ${builtWith}; re-index to pick up this engine's improvements.`);
847
+ info('Run "cgraphx index" (full rebuild) or "cgraphx sync"');
848
+ console.log();
849
+ }
850
+ cg.destroy();
851
+ }
852
+ catch (err) {
853
+ error(`Failed to get status: ${err instanceof Error ? err.message : String(err)}`);
854
+ process.exit(1);
855
+ }
856
+ });
857
+ /**
858
+ * cgraphx query <search>
859
+ */
860
+ program
861
+ .command('query <search>')
862
+ .description('Search for symbols in the codebase')
863
+ .option('-p, --path <path>', 'Project path')
864
+ .option('-l, --limit <number>', 'Maximum results', '10')
865
+ .option('-k, --kind <kind>', 'Filter by node kind (function, class, etc.)')
866
+ .option('-j, --json', 'Output as JSON')
867
+ .action(async (search, options) => {
868
+ const projectPath = resolveProjectPath(options.path);
869
+ try {
870
+ if (!(0, directory_1.isInitialized)(projectPath)) {
871
+ error(`cgraphx not initialized in ${projectPath}`);
872
+ process.exit(1);
873
+ }
874
+ const { default: CodeGraph } = await loadCodeGraph();
875
+ const cg = await CodeGraph.open(projectPath);
876
+ const limit = parseInt(options.limit || '10', 10);
877
+ const rawResults = cg.searchNodes(search, {
878
+ limit,
879
+ kinds: options.kind ? [options.kind] : undefined,
880
+ });
881
+ // Mirror the MCP search down-rank so the CLI also surfaces the
882
+ // hand-written implementation before protobuf/gRPC scaffolding
883
+ // when both share a name. See extraction/generated-detection.ts.
884
+ const { isGeneratedFile } = await Promise.resolve().then(() => __importStar(require('../extraction/generated-detection')));
885
+ const results = [...rawResults].sort((a, b) => {
886
+ const aGen = isGeneratedFile(a.node.filePath) ? 1 : 0;
887
+ const bGen = isGeneratedFile(b.node.filePath) ? 1 : 0;
888
+ return aGen - bGen;
889
+ });
890
+ if (options.json) {
891
+ console.log(JSON.stringify(results, null, 2));
892
+ }
893
+ else {
894
+ if (results.length === 0) {
895
+ info(`No results found for "${search}"`);
896
+ }
897
+ else {
898
+ console.log(chalk.bold(`\nSearch Results for "${search}":\n`));
899
+ for (const result of results) {
900
+ const node = result.node;
901
+ const location = `${node.filePath}:${node.startLine}`;
902
+ const score = chalk.dim(`(${(result.score * 100).toFixed(0)}%)`);
903
+ console.log(chalk.cyan(node.kind.padEnd(12)) +
904
+ chalk.white(node.name) +
905
+ ' ' + score);
906
+ console.log(chalk.dim(` ${location}`));
907
+ if (node.signature) {
908
+ console.log(chalk.dim(` ${node.signature}`));
909
+ }
910
+ console.log();
911
+ }
912
+ }
913
+ }
914
+ cg.destroy();
915
+ }
916
+ catch (err) {
917
+ error(`Search failed: ${err instanceof Error ? err.message : String(err)}`);
918
+ process.exit(1);
919
+ }
920
+ });
921
+ /**
922
+ * cgraphx explore <query...>
923
+ *
924
+ * The CLI face of the MCP codegraph_explore tool — same handler, same
925
+ * output (source of the relevant symbols grouped by file + the call path
926
+ * among them). Exists so agents WITHOUT the MCP tools — Task-tool
927
+ * subagents (which don't inherit MCP tools, #704) and non-MCP harnesses —
928
+ * can reach the graph through a plain shell command.
929
+ */
930
+ program
931
+ .command('explore <query...>')
932
+ .description('Explore an area: relevant symbols\' source + call paths in one shot (same output as the codegraph_explore MCP tool)')
933
+ .option('-p, --path <path>', 'Project path')
934
+ .option('--max-files <number>', 'Maximum number of files to include source from')
935
+ .action(async (queryParts, options) => {
936
+ const projectPath = resolveProjectPath(options.path);
937
+ try {
938
+ if (!(0, directory_1.isInitialized)(projectPath)) {
939
+ error(`cgraphx isn't available here — no .cgraphx/ index exists in ${projectPath}. If you are an AI agent: continue with your usual tools; indexing is the user's decision, do not run it yourself. (The project owner can enable cgraphx with 'cgraphx init'.)`);
940
+ process.exit(1);
941
+ }
942
+ const { default: CodeGraph } = await loadCodeGraph();
943
+ const cg = await CodeGraph.open(projectPath);
944
+ const { ToolHandler } = await Promise.resolve().then(() => __importStar(require('../mcp/tools')));
945
+ const handler = new ToolHandler(cg);
946
+ const args = { query: queryParts.join(' ') };
947
+ if (options.maxFiles)
948
+ args.maxFiles = parseInt(options.maxFiles, 10);
949
+ const result = await handler.execute('codegraph_explore', args);
950
+ console.log(result.content[0]?.text ?? '');
951
+ cg.destroy();
952
+ if (result.isError)
953
+ process.exit(1);
954
+ }
955
+ catch (err) {
956
+ error(`Explore failed: ${err instanceof Error ? err.message : String(err)}`);
957
+ process.exit(1);
958
+ }
959
+ });
960
+ /**
961
+ * cgraphx prompt-hook (hidden)
962
+ *
963
+ * A Claude Code `UserPromptSubmit` hook entry point. Reads `{prompt, cwd}` JSON
964
+ * on stdin; for a structural/flow/impact prompt it runs `codegraph_explore` on
965
+ * the indexed project and prints the result to stdout, which Claude injects into
966
+ * the agent's context — so the agent's reflex grep/read has nothing left to find
967
+ * and reliably uses cgraphx (the adoption problem). Installed by the installer
968
+ * into Claude's settings.json (opt-in, default-yes).
969
+ *
970
+ * LOAD-BEARING: this must NEVER break the user's prompt. Every failure path —
971
+ * kill-switch, non-structural prompt, no index, engine error — exits 0 with no
972
+ * output. The only effect is additive context when it can confidently provide it.
973
+ */
974
+ program
975
+ .command('prompt-hook', { hidden: true })
976
+ .description('Claude UserPromptSubmit hook: inject cgraphx context for structural prompts (reads {prompt,cwd} JSON on stdin)')
977
+ .action(async () => {
978
+ try {
979
+ // Kill-switch: lets a user disable the nudge without uninstalling /
980
+ // editing settings.json (CI, low-power machines, personal preference).
981
+ if (process.env.CGRAPHX_NO_PROMPT_HOOK === '1' || process.env.CGRAPHX_PROMPT_HOOK === '0')
982
+ return;
983
+ if (process.stdin.isTTY)
984
+ return; // invoked by hand, no piped payload
985
+ const raw = await new Promise((resolve) => {
986
+ let data = '';
987
+ process.stdin.setEncoding('utf8');
988
+ process.stdin.on('data', (c) => { data += c; });
989
+ process.stdin.on('end', () => resolve(data));
990
+ process.stdin.on('error', () => resolve(data));
991
+ });
992
+ let input = {};
993
+ try {
994
+ input = JSON.parse(raw);
995
+ }
996
+ catch {
997
+ return;
998
+ }
999
+ const prompt = String(input.prompt || '');
1000
+ // Gate: only structural / flow / impact / where-how prompts get context.
1001
+ // A cheap regex keeps every other prompt ("fix this typo") a zero-cost
1002
+ // no-op so we never add latency where there's no structural answer to give.
1003
+ const STRUCTURAL = /\b(how|where|trace|flow|path|reach(?:es|ed)?|call(?:s|ed|er|ers|ee)?|depend|impact|affect|wired?|connect|implement|architect|structure|breaks?|what calls|why does)\b/i;
1004
+ if (!prompt || !STRUCTURAL.test(prompt))
1005
+ return;
1006
+ // Decide what to inject, shaped by WHERE the index(es) are: the nearest
1007
+ // indexed ancestor of cwd, or — when cwd is an un-indexed workspace root
1008
+ // whose indexed project(s) live in sub-dirs (the monorepo case, #964) —
1009
+ // the sub-project the prompt points at, plus a `projectPath` nudge for any
1010
+ // others. Without the down-scan the hook injected nothing at a monorepo
1011
+ // root (it only walked up), so the validated adoption lever never fired
1012
+ // exactly where the agent most needs it.
1013
+ const plan = (0, directory_1.planFrontload)(String(input.cwd || process.cwd()), prompt);
1014
+ if (!plan.exploreRoot && plan.nudgeProjects.length === 0)
1015
+ return; // nothing reachable — the agent's normal tools apply
1016
+ // A "pass projectPath" line for indexed sub-projects we did NOT front-load.
1017
+ // Follow-up codegraph_explore calls against a sub-project (cwd isn't its
1018
+ // index root) need an explicit projectPath, so spell it out.
1019
+ const nudge = (projects, lead) => `${lead}\n${projects.map((p) => ` - projectPath: "${p}"`).join('\n')}\n`;
1020
+ if (plan.exploreRoot) {
1021
+ const { default: CodeGraph } = await loadCodeGraph();
1022
+ const cg = await CodeGraph.open(plan.exploreRoot);
1023
+ try {
1024
+ const { ToolHandler } = await Promise.resolve().then(() => __importStar(require('../mcp/tools')));
1025
+ const handler = new ToolHandler(cg);
1026
+ const result = await handler.execute('codegraph_explore', { query: prompt });
1027
+ const text = result.content[0]?.text ?? '';
1028
+ if (!result.isError && text.trim()) {
1029
+ // Cap the injection so a large-repo explore can't flood the prompt.
1030
+ const MAX = 16000;
1031
+ const body = text.length > MAX ? `${text.slice(0, MAX)}\n…(truncated; call codegraph_explore for the rest)` : text;
1032
+ // For a front-loaded SUB-project, a follow-up explore needs its path.
1033
+ const more = plan.viaSubScan
1034
+ ? `call codegraph_explore with projectPath: "${plan.exploreRoot}" for more`
1035
+ : 'call codegraph_explore for more';
1036
+ const others = plan.nudgeProjects.length
1037
+ ? `\n${nudge(plan.nudgeProjects, 'Other indexed projects in this workspace — pass projectPath to query them:')}`
1038
+ : '';
1039
+ process.stdout.write(`<codegraph_context note="Structural context from cgraphx for this prompt — treat returned source as already read; ${more}.">\n${body}${others}\n</codegraph_context>\n`);
1040
+ }
1041
+ }
1042
+ finally {
1043
+ cg.destroy();
1044
+ }
1045
+ }
1046
+ else {
1047
+ // Several indexed sub-projects, none a clear match — don't guess; tell
1048
+ // the agent they exist and how to query one.
1049
+ process.stdout.write(`<codegraph_context note="cgraphx is available for this workspace's indexed sub-projects — query one by passing projectPath to codegraph_explore.">\n` +
1050
+ nudge(plan.nudgeProjects, "This workspace's cgraphx indexes live in sub-projects. To use cgraphx, call codegraph_explore with the projectPath of the relevant one:") +
1051
+ `</codegraph_context>\n`);
1052
+ }
1053
+ }
1054
+ catch {
1055
+ // Degradable by contract: never surface an error to the prompt pipeline.
1056
+ }
1057
+ });
1058
+ /**
1059
+ * cgraphx node <name>
1060
+ *
1061
+ * The CLI face of the MCP codegraph_node tool: one symbol's source +
1062
+ * caller/callee trail, or a whole file with line numbers + dependents
1063
+ * (Read-parity). Same subagent/non-MCP rationale as `explore`.
1064
+ */
1065
+ program
1066
+ .command('node <name>')
1067
+ .description('One symbol\'s source + caller/callee trail, or read a file with line numbers + dependents (same output as the codegraph_node MCP tool)')
1068
+ .option('-p, --path <path>', 'Project path')
1069
+ .option('-f, --file <file>', 'Treat as file mode (or disambiguate a symbol to this file)')
1070
+ .option('--offset <number>', 'File mode: 1-based start line')
1071
+ .option('--limit <number>', 'File mode: maximum lines')
1072
+ .option('--symbols-only', 'File mode: just the symbol map + dependents')
1073
+ .action(async (name, options) => {
1074
+ const projectPath = resolveProjectPath(options.path);
1075
+ try {
1076
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1077
+ error(`cgraphx isn't available here — no .cgraphx/ index exists in ${projectPath}. If you are an AI agent: continue with your usual tools; indexing is the user's decision, do not run it yourself. (The project owner can enable cgraphx with 'cgraphx init'.)`);
1078
+ process.exit(1);
1079
+ }
1080
+ const { default: CodeGraph } = await loadCodeGraph();
1081
+ const cg = await CodeGraph.open(projectPath);
1082
+ const { ToolHandler } = await Promise.resolve().then(() => __importStar(require('../mcp/tools')));
1083
+ const handler = new ToolHandler(cg);
1084
+ // A name with a path separator is a file read; otherwise a symbol
1085
+ // (use --file for basename-only file reads or to pin an overload).
1086
+ // Both separators: Windows users type src\auth\session.ts. Symbols
1087
+ // never contain either ('/' isn't an identifier char anywhere we
1088
+ // index; C++ scope is '::', JS members '.').
1089
+ const args = {};
1090
+ if (options.file) {
1091
+ args.file = options.file;
1092
+ if (name && name !== options.file)
1093
+ args.symbol = name;
1094
+ }
1095
+ else if (name.includes('/') || name.includes('\\')) {
1096
+ args.file = name.replace(/\\/g, '/');
1097
+ }
1098
+ else {
1099
+ args.symbol = name;
1100
+ args.includeCode = true;
1101
+ }
1102
+ if (options.offset)
1103
+ args.offset = parseInt(options.offset, 10);
1104
+ if (options.limit)
1105
+ args.limit = parseInt(options.limit, 10);
1106
+ if (options.symbolsOnly)
1107
+ args.symbolsOnly = true;
1108
+ const result = await handler.execute('codegraph_node', args);
1109
+ console.log(result.content[0]?.text ?? '');
1110
+ cg.destroy();
1111
+ if (result.isError)
1112
+ process.exit(1);
1113
+ }
1114
+ catch (err) {
1115
+ error(`Node lookup failed: ${err instanceof Error ? err.message : String(err)}`);
1116
+ process.exit(1);
1117
+ }
1118
+ });
1119
+ /**
1120
+ * cgraphx files [path]
1121
+ */
1122
+ program
1123
+ .command('files')
1124
+ .description('Show project file structure from the index')
1125
+ .option('-p, --path <path>', 'Project path')
1126
+ .option('--filter <dir>', 'Filter to files under this directory')
1127
+ .option('--pattern <glob>', 'Filter files matching this glob pattern')
1128
+ .option('--format <format>', 'Output format (tree, flat, grouped)', 'tree')
1129
+ .option('--max-depth <number>', 'Maximum directory depth for tree format')
1130
+ .option('--no-metadata', 'Hide file metadata (language, symbol count)')
1131
+ .option('-j, --json', 'Output as JSON')
1132
+ .action(async (options) => {
1133
+ const projectPath = resolveProjectPath(options.path);
1134
+ try {
1135
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1136
+ error(`cgraphx not initialized in ${projectPath}`);
1137
+ process.exit(1);
1138
+ }
1139
+ const { default: CodeGraph } = await loadCodeGraph();
1140
+ const cg = await CodeGraph.open(projectPath);
1141
+ let files = cg.getFiles();
1142
+ if (files.length === 0) {
1143
+ info('No files indexed. Run "cgraphx index" first.');
1144
+ cg.destroy();
1145
+ return;
1146
+ }
1147
+ // Filter by path prefix
1148
+ if (options.filter) {
1149
+ const filter = options.filter;
1150
+ files = files.filter(f => f.path.startsWith(filter) || f.path.startsWith('./' + filter));
1151
+ }
1152
+ // Filter by glob pattern
1153
+ if (options.pattern) {
1154
+ const regex = globToRegex(options.pattern);
1155
+ files = files.filter(f => regex.test(f.path));
1156
+ }
1157
+ if (files.length === 0) {
1158
+ info('No files found matching the criteria.');
1159
+ cg.destroy();
1160
+ return;
1161
+ }
1162
+ // JSON output
1163
+ if (options.json) {
1164
+ const output = files.map(f => ({
1165
+ path: f.path,
1166
+ language: f.language,
1167
+ nodeCount: f.nodeCount,
1168
+ size: f.size,
1169
+ }));
1170
+ console.log(JSON.stringify(output, null, 2));
1171
+ cg.destroy();
1172
+ return;
1173
+ }
1174
+ const includeMetadata = options.metadata !== false;
1175
+ const format = options.format || 'tree';
1176
+ const maxDepth = options.maxDepth ? parseInt(options.maxDepth, 10) : undefined;
1177
+ // Format output
1178
+ switch (format) {
1179
+ case 'flat':
1180
+ console.log(chalk.bold(`\nFiles (${files.length}):\n`));
1181
+ for (const file of files.sort((a, b) => a.path.localeCompare(b.path))) {
1182
+ if (includeMetadata) {
1183
+ console.log(` ${file.path} ${chalk.dim(`(${file.language}, ${file.nodeCount} symbols)`)}`);
1184
+ }
1185
+ else {
1186
+ console.log(` ${file.path}`);
1187
+ }
1188
+ }
1189
+ break;
1190
+ case 'grouped':
1191
+ console.log(chalk.bold(`\nFiles by Language (${files.length} total):\n`));
1192
+ const byLang = new Map();
1193
+ for (const file of files) {
1194
+ const existing = byLang.get(file.language) || [];
1195
+ existing.push(file);
1196
+ byLang.set(file.language, existing);
1197
+ }
1198
+ const sortedLangs = [...byLang.entries()].sort((a, b) => b[1].length - a[1].length);
1199
+ for (const [lang, langFiles] of sortedLangs) {
1200
+ console.log(chalk.cyan(`${lang} (${langFiles.length}):`));
1201
+ for (const file of langFiles.sort((a, b) => a.path.localeCompare(b.path))) {
1202
+ if (includeMetadata) {
1203
+ console.log(` ${file.path} ${chalk.dim(`(${file.nodeCount} symbols)`)}`);
1204
+ }
1205
+ else {
1206
+ console.log(` ${file.path}`);
1207
+ }
1208
+ }
1209
+ console.log();
1210
+ }
1211
+ break;
1212
+ case 'tree':
1213
+ default:
1214
+ console.log(chalk.bold(`\nProject Structure (${files.length} files):\n`));
1215
+ printFileTree(files, includeMetadata, maxDepth, chalk);
1216
+ break;
1217
+ }
1218
+ console.log();
1219
+ cg.destroy();
1220
+ }
1221
+ catch (err) {
1222
+ error(`Failed to list files: ${err instanceof Error ? err.message : String(err)}`);
1223
+ process.exit(1);
1224
+ }
1225
+ });
1226
+ /**
1227
+ * Normalize a user-supplied file path to the project-relative, forward-slash
1228
+ * form cgraphx stores in the index. Accepts an absolute path, a `./`-prefixed
1229
+ * path, or Windows back-slashes; an empty string when the input is blank. Used
1230
+ * by `cgraphx affected` so `./src/x.ts`, `/abs/repo/src/x.ts`, and
1231
+ * `src/x.ts` all match the same indexed file. (#825)
1232
+ */
1233
+ function normalizeIndexPath(filePath, projectPath) {
1234
+ let f = filePath.trim();
1235
+ if (!f)
1236
+ return '';
1237
+ if (path.isAbsolute(f))
1238
+ f = path.relative(projectPath, f);
1239
+ // Collapse `.`/`..` segments, then force forward slashes and drop a leading
1240
+ // `./` (path.normalize already strips it on POSIX; explicit for Windows).
1241
+ f = path.normalize(f).replace(/\\/g, '/').replace(/^\.\//, '');
1242
+ return f;
1243
+ }
1244
+ /**
1245
+ * Convert glob pattern to regex
1246
+ */
1247
+ function globToRegex(pattern) {
1248
+ const escaped = pattern
1249
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
1250
+ .replace(/\*\*/g, '{{GLOBSTAR}}')
1251
+ .replace(/\*/g, '[^/]*')
1252
+ .replace(/\?/g, '[^/]')
1253
+ .replace(/\{\{GLOBSTAR\}\}/g, '.*');
1254
+ return new RegExp(escaped);
1255
+ }
1256
+ /**
1257
+ * Print files as a tree
1258
+ */
1259
+ function printFileTree(files, includeMetadata, maxDepth, chalk) {
1260
+ const root = { name: '', children: new Map() };
1261
+ for (const file of files) {
1262
+ const parts = file.path.split('/');
1263
+ let current = root;
1264
+ for (let i = 0; i < parts.length; i++) {
1265
+ const part = parts[i];
1266
+ if (!part)
1267
+ continue;
1268
+ if (!current.children.has(part)) {
1269
+ current.children.set(part, { name: part, children: new Map() });
1270
+ }
1271
+ current = current.children.get(part);
1272
+ if (i === parts.length - 1) {
1273
+ current.file = { language: file.language, nodeCount: file.nodeCount };
1274
+ }
1275
+ }
1276
+ }
1277
+ const renderNode = (node, prefix, isLast, depth) => {
1278
+ if (maxDepth !== undefined && depth > maxDepth)
1279
+ return;
1280
+ const glyphs = (0, glyphs_1.getGlyphs)();
1281
+ const connector = isLast ? glyphs.treeLast : glyphs.treeBranch;
1282
+ const childPrefix = isLast ? ' ' : glyphs.treePipe;
1283
+ if (node.name) {
1284
+ let line = prefix + connector + node.name;
1285
+ if (node.file && includeMetadata) {
1286
+ line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`);
1287
+ }
1288
+ console.log(line);
1289
+ }
1290
+ const children = [...node.children.values()];
1291
+ children.sort((a, b) => {
1292
+ const aIsDir = a.children.size > 0 && !a.file;
1293
+ const bIsDir = b.children.size > 0 && !b.file;
1294
+ if (aIsDir !== bIsDir)
1295
+ return aIsDir ? -1 : 1;
1296
+ return a.name.localeCompare(b.name);
1297
+ });
1298
+ for (let i = 0; i < children.length; i++) {
1299
+ const child = children[i];
1300
+ const nextPrefix = node.name ? prefix + childPrefix : prefix;
1301
+ renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
1302
+ }
1303
+ };
1304
+ renderNode(root, '', true, 0);
1305
+ }
1306
+ /**
1307
+ * cgraphx daemon — interactive manager for the background daemons. Arrow keys
1308
+ * to pick one (the current project's daemon floats to the top, auto-selected),
1309
+ * enter to stop it. Falls back to a plain list when output isn't a TTY.
1310
+ */
1311
+ program
1312
+ .command('daemon')
1313
+ .aliases(['daemons'])
1314
+ .description('Manage running cgraphx background daemons — pick one and press enter to stop it')
1315
+ .action(async () => {
1316
+ const { listDaemons, stopDaemonAt, stopAllDaemons } = await Promise.resolve().then(() => __importStar(require('../mcp/daemon-registry')));
1317
+ const { runDaemonPicker } = await Promise.resolve().then(() => __importStar(require('../mcp/daemon-manager')));
1318
+ const daemons = listDaemons();
1319
+ if (daemons.length === 0) {
1320
+ info('No cgraphx daemons running.');
1321
+ return;
1322
+ }
1323
+ // No TTY (piped / CI / non-interactive) — can't do arrow-key selection, so
1324
+ // just print what's running instead of crashing on a prompt with no input.
1325
+ if (!process.stdout.isTTY || !process.stdin.isTTY) {
1326
+ for (const d of daemons) {
1327
+ console.log(`pid ${d.pid} v${d.version} up ${formatDuration(Date.now() - d.startedAt)} ${d.root}`);
1328
+ }
1329
+ return;
1330
+ }
1331
+ // The current project's daemon floats to the top and is pre-selected.
1332
+ let cwdRoot = null;
1333
+ const found = (0, directory_1.findNearestCodeGraphRoot)(process.cwd());
1334
+ if (found) {
1335
+ try {
1336
+ cwdRoot = fs.realpathSync(found);
1337
+ }
1338
+ catch {
1339
+ cwdRoot = found;
1340
+ }
1341
+ }
1342
+ const clack = await importESM('@clack/prompts');
1343
+ clack.intro('cgraphx daemons');
1344
+ await runDaemonPicker({
1345
+ list: listDaemons,
1346
+ stop: stopDaemonAt,
1347
+ stopAll: stopAllDaemons,
1348
+ cwdRoot,
1349
+ now: () => Date.now(),
1350
+ select: (opts) => clack.select(opts),
1351
+ isCancel: (v) => clack.isCancel(v),
1352
+ note: (m) => clack.log.success(m),
1353
+ done: (m) => clack.outro(m),
1354
+ });
1355
+ });
1356
+ /**
1357
+ * cgraphx serve
1358
+ */
1359
+ program
1360
+ // Hidden from `--help`: this is the stdio entry point an AI agent launches
1361
+ // for itself (the installer wires `args: ['serve','--mcp']` into every
1362
+ // agent's MCP config), not a command a human runs. It still works when
1363
+ // invoked — hiding only removes it from the listing. See the interactive-TTY
1364
+ // guard below, which explains this to anyone who runs it by hand.
1365
+ .command('serve', { hidden: true })
1366
+ .description('Start cgraphx as an MCP server for AI assistants')
1367
+ .option('-p, --path <path>', 'Project path (optional for MCP mode, uses rootUri from client)')
1368
+ .option('--mcp', 'Run as MCP server (stdio transport)')
1369
+ .option('--no-watch', 'Disable the file watcher (no auto-sync; useful on slow filesystems like WSL2 /mnt drives)')
1370
+ .action(async (options) => {
1371
+ const projectPath = options.path ? resolveProjectPath(options.path) : undefined;
1372
+ // Commander sets watch=false when --no-watch is passed. Route it through
1373
+ // the same env-var chokepoint the watcher and MCP server already honor.
1374
+ if (options.watch === false) {
1375
+ process.env.CGRAPHX_NO_WATCH = '1';
1376
+ }
1377
+ try {
1378
+ if (options.mcp) {
1379
+ // `serve --mcp` is the stdio MCP server an AI agent launches for itself,
1380
+ // not a command to run by hand. A human in a terminal would otherwise
1381
+ // see it hang waiting for JSON-RPC on stdin, which reads as broken. If
1382
+ // stdin is an interactive TTY, explain instead of hanging. The agent's
1383
+ // pipe and the detached daemon both have a non-TTY stdin, so this only
1384
+ // ever fires for a person who typed it.
1385
+ if (process.stdin.isTTY && !process.env.CGRAPHX_DAEMON_INTERNAL) {
1386
+ console.error(chalk.bold('\ncgraphx MCP server\n'));
1387
+ console.error("This is the MCP server your AI agent (Claude Code, Cursor, Codex, opencode, …)");
1388
+ console.error("starts automatically — you don't run it yourself.");
1389
+ console.error(`\nIt's already wired up by ${chalk.cyan('cgraphx install')}. To check on things:`);
1390
+ console.error(` ${chalk.cyan('cgraphx status')} ${chalk.dim('— is this project indexed and healthy?')}`);
1391
+ console.error(` ${chalk.cyan('cgraphx daemon')} ${chalk.dim('— list or stop background MCP servers')}`);
1392
+ console.error(chalk.dim('\n(Running it directly only does something when an MCP client drives it over stdin.)'));
1393
+ return;
1394
+ }
1395
+ // Start MCP server - it handles initialization lazily based on rootUri from client
1396
+ const { MCPServer } = await Promise.resolve().then(() => __importStar(require('../mcp/index')));
1397
+ const server = new MCPServer(projectPath);
1398
+ await server.start();
1399
+ // Server will run until terminated
1400
+ }
1401
+ else {
1402
+ // Default: show info about MCP mode.
1403
+ // Use stderr so stdout stays clean for any piped/stdio usage.
1404
+ console.error(chalk.bold('\ncgraphx MCP Server\n'));
1405
+ console.error(chalk.blue((0, glyphs_1.getGlyphs)().info) + ' Use --mcp flag to start the MCP server');
1406
+ console.error('\nTo use with Claude Code, add to your MCP configuration:');
1407
+ console.error(chalk.dim(`
1408
+ {
1409
+ "mcpServers": {
1410
+ "cgraphx": {
1411
+ "command": "cgraphx",
1412
+ "args": ["serve", "--mcp"]
1413
+ }
1414
+ }
1415
+ }
1416
+ `));
1417
+ console.error('Available tools:');
1418
+ console.error(chalk.cyan(' codegraph_explore') + ' - Primary: source of the relevant symbols for any question');
1419
+ console.error(chalk.cyan(' codegraph_search') + ' - Search for code symbols');
1420
+ console.error(chalk.cyan(' codegraph_callers') + ' - Find callers of a symbol');
1421
+ console.error(chalk.cyan(' codegraph_callees') + ' - Find what a symbol calls');
1422
+ console.error(chalk.cyan(' codegraph_impact') + ' - Analyze impact of changes');
1423
+ console.error(chalk.cyan(' codegraph_node') + ' - Get symbol details');
1424
+ console.error(chalk.cyan(' codegraph_files') + ' - Get project file structure');
1425
+ console.error(chalk.cyan(' codegraph_status') + ' - Get index status');
1426
+ }
1427
+ }
1428
+ catch (err) {
1429
+ error(`Failed to start server: ${err instanceof Error ? err.message : String(err)}`);
1430
+ process.exit(1);
1431
+ }
1432
+ });
1433
+ /**
1434
+ * cgraphx unlock [path]
1435
+ */
1436
+ program
1437
+ .command('unlock [path]')
1438
+ .description('Remove a stale lock file that is blocking indexing')
1439
+ .action(async (pathArg) => {
1440
+ const projectPath = resolveProjectPath(pathArg);
1441
+ try {
1442
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1443
+ error(`cgraphx not initialized in ${projectPath}`);
1444
+ return;
1445
+ }
1446
+ const lockPath = path.join((0, directory_1.getCodeGraphDir)(projectPath), 'cgraphx.lock');
1447
+ if (!fs.existsSync(lockPath)) {
1448
+ info(`No lock file found ${(0, glyphs_1.getGlyphs)().dash} nothing to do`);
1449
+ return;
1450
+ }
1451
+ fs.unlinkSync(lockPath);
1452
+ success('Removed lock file. You can now run indexing again.');
1453
+ }
1454
+ catch (err) {
1455
+ error(`Failed to remove lock: ${err instanceof Error ? err.message : String(err)}`);
1456
+ process.exit(1);
1457
+ }
1458
+ });
1459
+ /**
1460
+ * cgraphx callers <symbol>
1461
+ *
1462
+ * CLI parity with the MCP graph tools (codegraph_callers/callees/impact) so the
1463
+ * traversal queries work in scripts, CI, and git hooks without a running MCP
1464
+ * server.
1465
+ */
1466
+ program
1467
+ .command('callers <symbol>')
1468
+ .description('Find all functions/methods that call a specific symbol')
1469
+ .option('-p, --path <path>', 'Project path')
1470
+ .option('-l, --limit <number>', 'Maximum results', '20')
1471
+ .option('-j, --json', 'Output as JSON')
1472
+ .action(async (symbol, options) => {
1473
+ const projectPath = resolveProjectPath(options.path);
1474
+ try {
1475
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1476
+ error(`cgraphx not initialized in ${projectPath}`);
1477
+ process.exit(1);
1478
+ }
1479
+ const { default: CodeGraph } = await loadCodeGraph();
1480
+ const cg = await CodeGraph.open(projectPath);
1481
+ const limit = parseInt(options.limit || '20', 10);
1482
+ const matches = cg.searchNodes(symbol, { limit: 50 });
1483
+ if (matches.length === 0) {
1484
+ info(`Symbol "${symbol}" not found`);
1485
+ cg.destroy();
1486
+ return;
1487
+ }
1488
+ const seen = new Set();
1489
+ const allCallers = [];
1490
+ for (const match of matches) {
1491
+ const exactMatch = match.node.name === symbol || match.node.name.endsWith(`.${symbol}`) || match.node.name.endsWith(`::${symbol}`);
1492
+ if (!exactMatch && matches.length > 1)
1493
+ continue;
1494
+ for (const c of cg.getCallers(match.node.id)) {
1495
+ if (!seen.has(c.node.id)) {
1496
+ seen.add(c.node.id);
1497
+ allCallers.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1498
+ }
1499
+ }
1500
+ }
1501
+ // Fallback: if exact filter removed everything, use the top match
1502
+ if (allCallers.length === 0 && matches[0]) {
1503
+ for (const c of cg.getCallers(matches[0].node.id)) {
1504
+ if (!seen.has(c.node.id)) {
1505
+ seen.add(c.node.id);
1506
+ allCallers.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1507
+ }
1508
+ }
1509
+ }
1510
+ const limited = allCallers.slice(0, limit);
1511
+ if (options.json) {
1512
+ console.log(JSON.stringify({ symbol, callers: limited }, null, 2));
1513
+ }
1514
+ else if (limited.length === 0) {
1515
+ info(`No callers found for "${symbol}"`);
1516
+ }
1517
+ else {
1518
+ console.log(chalk.bold(`\nCallers of "${symbol}" (${limited.length}):\n`));
1519
+ for (const node of limited) {
1520
+ const loc = node.startLine ? `:${node.startLine}` : '';
1521
+ console.log(chalk.cyan(node.kind.padEnd(12)) +
1522
+ chalk.white(node.name));
1523
+ console.log(chalk.dim(` ${node.filePath}${loc}`));
1524
+ console.log();
1525
+ }
1526
+ }
1527
+ cg.destroy();
1528
+ }
1529
+ catch (err) {
1530
+ error(`callers failed: ${err instanceof Error ? err.message : String(err)}`);
1531
+ process.exit(1);
1532
+ }
1533
+ });
1534
+ /**
1535
+ * cgraphx callees <symbol>
1536
+ */
1537
+ program
1538
+ .command('callees <symbol>')
1539
+ .description('Find all functions/methods that a specific symbol calls')
1540
+ .option('-p, --path <path>', 'Project path')
1541
+ .option('-l, --limit <number>', 'Maximum results', '20')
1542
+ .option('-j, --json', 'Output as JSON')
1543
+ .action(async (symbol, options) => {
1544
+ const projectPath = resolveProjectPath(options.path);
1545
+ try {
1546
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1547
+ error(`cgraphx not initialized in ${projectPath}`);
1548
+ process.exit(1);
1549
+ }
1550
+ const { default: CodeGraph } = await loadCodeGraph();
1551
+ const cg = await CodeGraph.open(projectPath);
1552
+ const limit = parseInt(options.limit || '20', 10);
1553
+ const matches = cg.searchNodes(symbol, { limit: 50 });
1554
+ if (matches.length === 0) {
1555
+ info(`Symbol "${symbol}" not found`);
1556
+ cg.destroy();
1557
+ return;
1558
+ }
1559
+ const seen = new Set();
1560
+ const allCallees = [];
1561
+ for (const match of matches) {
1562
+ const exactMatch = match.node.name === symbol || match.node.name.endsWith(`.${symbol}`) || match.node.name.endsWith(`::${symbol}`);
1563
+ if (!exactMatch && matches.length > 1)
1564
+ continue;
1565
+ for (const c of cg.getCallees(match.node.id)) {
1566
+ if (!seen.has(c.node.id)) {
1567
+ seen.add(c.node.id);
1568
+ allCallees.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1569
+ }
1570
+ }
1571
+ }
1572
+ if (allCallees.length === 0 && matches[0]) {
1573
+ for (const c of cg.getCallees(matches[0].node.id)) {
1574
+ if (!seen.has(c.node.id)) {
1575
+ seen.add(c.node.id);
1576
+ allCallees.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1577
+ }
1578
+ }
1579
+ }
1580
+ const limited = allCallees.slice(0, limit);
1581
+ if (options.json) {
1582
+ console.log(JSON.stringify({ symbol, callees: limited }, null, 2));
1583
+ }
1584
+ else if (limited.length === 0) {
1585
+ info(`No callees found for "${symbol}"`);
1586
+ }
1587
+ else {
1588
+ console.log(chalk.bold(`\nCallees of "${symbol}" (${limited.length}):\n`));
1589
+ for (const node of limited) {
1590
+ const loc = node.startLine ? `:${node.startLine}` : '';
1591
+ console.log(chalk.cyan(node.kind.padEnd(12)) +
1592
+ chalk.white(node.name));
1593
+ console.log(chalk.dim(` ${node.filePath}${loc}`));
1594
+ console.log();
1595
+ }
1596
+ }
1597
+ cg.destroy();
1598
+ }
1599
+ catch (err) {
1600
+ error(`callees failed: ${err instanceof Error ? err.message : String(err)}`);
1601
+ process.exit(1);
1602
+ }
1603
+ });
1604
+ /**
1605
+ * cgraphx impact <symbol>
1606
+ */
1607
+ program
1608
+ .command('impact <symbol>')
1609
+ .description('Analyze what code is affected by changing a symbol')
1610
+ .option('-p, --path <path>', 'Project path')
1611
+ .option('-d, --depth <number>', 'Traversal depth', '2')
1612
+ .option('-j, --json', 'Output as JSON')
1613
+ .action(async (symbol, options) => {
1614
+ const projectPath = resolveProjectPath(options.path);
1615
+ try {
1616
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1617
+ error(`cgraphx not initialized in ${projectPath}`);
1618
+ process.exit(1);
1619
+ }
1620
+ const { default: CodeGraph } = await loadCodeGraph();
1621
+ const cg = await CodeGraph.open(projectPath);
1622
+ const depth = Math.min(Math.max(parseInt(options.depth || '2', 10), 1), 10);
1623
+ const matches = cg.searchNodes(symbol, { limit: 50 });
1624
+ if (matches.length === 0) {
1625
+ info(`Symbol "${symbol}" not found`);
1626
+ cg.destroy();
1627
+ return;
1628
+ }
1629
+ // Merge impact subgraphs across all exact-matching symbols
1630
+ const mergedNodes = new Map();
1631
+ const seenEdges = new Set();
1632
+ let edgeCount = 0;
1633
+ for (const match of matches) {
1634
+ const exactMatch = match.node.name === symbol || match.node.name.endsWith(`.${symbol}`) || match.node.name.endsWith(`::${symbol}`);
1635
+ if (!exactMatch && matches.length > 1)
1636
+ continue;
1637
+ const impact = cg.getImpactRadius(match.node.id, depth);
1638
+ for (const [id, n] of impact.nodes) {
1639
+ mergedNodes.set(id, { name: n.name, kind: n.kind, filePath: n.filePath, startLine: n.startLine });
1640
+ }
1641
+ for (const e of impact.edges) {
1642
+ const key = `${e.source}->${e.target}:${e.kind}`;
1643
+ if (!seenEdges.has(key)) {
1644
+ seenEdges.add(key);
1645
+ edgeCount++;
1646
+ }
1647
+ }
1648
+ }
1649
+ // Fallback to top match if exact filter removed everything
1650
+ if (mergedNodes.size === 0 && matches[0]) {
1651
+ const impact = cg.getImpactRadius(matches[0].node.id, depth);
1652
+ for (const [id, n] of impact.nodes) {
1653
+ mergedNodes.set(id, { name: n.name, kind: n.kind, filePath: n.filePath, startLine: n.startLine });
1654
+ }
1655
+ edgeCount = impact.edges.length;
1656
+ }
1657
+ if (options.json) {
1658
+ console.log(JSON.stringify({
1659
+ symbol,
1660
+ depth,
1661
+ nodeCount: mergedNodes.size,
1662
+ edgeCount,
1663
+ affected: Array.from(mergedNodes.values()),
1664
+ }, null, 2));
1665
+ }
1666
+ else if (mergedNodes.size === 0) {
1667
+ info(`No affected symbols found for "${symbol}"`);
1668
+ }
1669
+ else {
1670
+ console.log(chalk.bold(`\nImpact of changing "${symbol}" — ${mergedNodes.size} affected symbols:\n`));
1671
+ // Group by file
1672
+ const byFile = new Map();
1673
+ for (const node of mergedNodes.values()) {
1674
+ const list = byFile.get(node.filePath) || [];
1675
+ list.push({ name: node.name, kind: node.kind, startLine: node.startLine });
1676
+ byFile.set(node.filePath, list);
1677
+ }
1678
+ for (const [file, nodes] of byFile) {
1679
+ console.log(chalk.cyan(file));
1680
+ for (const node of nodes) {
1681
+ const loc = node.startLine ? `:${node.startLine}` : '';
1682
+ console.log(` ${chalk.dim(node.kind.padEnd(12))}${node.name}${chalk.dim(loc)}`);
1683
+ }
1684
+ console.log();
1685
+ }
1686
+ }
1687
+ cg.destroy();
1688
+ }
1689
+ catch (err) {
1690
+ error(`impact failed: ${err instanceof Error ? err.message : String(err)}`);
1691
+ process.exit(1);
1692
+ }
1693
+ });
1694
+ /**
1695
+ * cgraphx affected [files...]
1696
+ *
1697
+ * Find test files affected by the given source files.
1698
+ * Traces dependency edges transitively to find test files that depend on changed code.
1699
+ *
1700
+ * Usage:
1701
+ * git diff --name-only | cgraphx affected --stdin
1702
+ * cgraphx affected src/lib/components/Editor.svelte src/routes/+page.svelte
1703
+ */
1704
+ program
1705
+ .command('affected [files...]')
1706
+ .description('Find test files affected by changed source files')
1707
+ .option('-p, --path <path>', 'Project path')
1708
+ .option('--stdin', 'Read file list from stdin (one per line)')
1709
+ .option('-d, --depth <number>', 'Max dependency traversal depth', '5')
1710
+ .option('-f, --filter <glob>', 'Custom glob filter for test files (e.g. "e2e/*.spec.ts")')
1711
+ .option('-j, --json', 'Output as JSON')
1712
+ .option('-q, --quiet', 'Only output file paths, no decoration')
1713
+ .action(async (fileArgs, options) => {
1714
+ const projectPath = resolveProjectPath(options.path);
1715
+ try {
1716
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1717
+ error(`cgraphx not initialized in ${projectPath}`);
1718
+ process.exit(1);
1719
+ }
1720
+ // Collect changed files from args or stdin
1721
+ let changedFiles = [...(fileArgs || [])];
1722
+ if (options.stdin) {
1723
+ const stdinData = fs.readFileSync(0, 'utf-8');
1724
+ const stdinFiles = stdinData.split('\n').map(f => f.trim()).filter(Boolean);
1725
+ changedFiles.push(...stdinFiles);
1726
+ }
1727
+ // Normalize inputs to the project-relative, forward-slash form the index
1728
+ // stores. Without this, `affected ./src/x.ts`, an absolute path (what a
1729
+ // wrapping script often passes), or a Windows back-slash path silently
1730
+ // matches nothing and reports 0 affected tests. (#825)
1731
+ changedFiles = changedFiles
1732
+ .map((f) => normalizeIndexPath(f, projectPath))
1733
+ .filter(Boolean);
1734
+ if (changedFiles.length === 0) {
1735
+ if (!options.quiet)
1736
+ info('No files provided. Use file arguments or --stdin.');
1737
+ process.exit(0);
1738
+ }
1739
+ const { default: CodeGraph } = await loadCodeGraph();
1740
+ const cg = await CodeGraph.open(projectPath);
1741
+ const maxDepth = parseInt(options.depth || '5', 10);
1742
+ // Common test file patterns
1743
+ const defaultTestPatterns = [
1744
+ /\.spec\./,
1745
+ /\.test\./,
1746
+ /\/__tests__\//,
1747
+ /\/tests?\//,
1748
+ /\/e2e\//,
1749
+ /\/spec\//,
1750
+ ];
1751
+ // Custom filter pattern
1752
+ let customFilter = null;
1753
+ if (options.filter) {
1754
+ // Convert glob to regex: ** → .+, * → [^/]*, . → \.
1755
+ const regex = options.filter
1756
+ .replace(/[+[\]{}()^$|\\]/g, '\\$&')
1757
+ .replace(/\./g, '\\.')
1758
+ .replace(/\*\*/g, '.+')
1759
+ .replace(/\*/g, '[^/]*');
1760
+ customFilter = new RegExp(regex);
1761
+ }
1762
+ function isTestFile(filePath) {
1763
+ if (customFilter)
1764
+ return customFilter.test(filePath);
1765
+ return defaultTestPatterns.some(p => p.test(filePath));
1766
+ }
1767
+ // BFS to find all transitive dependents of changed files, filtered to test files
1768
+ const affectedTests = new Set();
1769
+ const allDependents = new Set();
1770
+ for (const file of changedFiles) {
1771
+ // If the changed file is itself a test file, include it
1772
+ if (isTestFile(file)) {
1773
+ affectedTests.add(file);
1774
+ continue;
1775
+ }
1776
+ // BFS through dependents
1777
+ const queue = [{ file, depth: 0 }];
1778
+ const visited = new Set();
1779
+ visited.add(file);
1780
+ while (queue.length > 0) {
1781
+ const current = queue.shift();
1782
+ if (current.depth >= maxDepth)
1783
+ continue;
1784
+ const dependents = cg.getFileDependents(current.file);
1785
+ for (const dep of dependents) {
1786
+ if (visited.has(dep))
1787
+ continue;
1788
+ visited.add(dep);
1789
+ allDependents.add(dep);
1790
+ if (isTestFile(dep)) {
1791
+ affectedTests.add(dep);
1792
+ }
1793
+ else {
1794
+ queue.push({ file: dep, depth: current.depth + 1 });
1795
+ }
1796
+ }
1797
+ }
1798
+ }
1799
+ const sortedTests = Array.from(affectedTests).sort();
1800
+ // Output
1801
+ if (options.json) {
1802
+ console.log(JSON.stringify({
1803
+ changedFiles,
1804
+ affectedTests: sortedTests,
1805
+ totalDependentsTraversed: allDependents.size,
1806
+ }, null, 2));
1807
+ }
1808
+ else if (options.quiet) {
1809
+ for (const t of sortedTests)
1810
+ console.log(t);
1811
+ }
1812
+ else {
1813
+ if (sortedTests.length === 0) {
1814
+ info('No test files affected by the changed files.');
1815
+ }
1816
+ else {
1817
+ console.log(chalk.bold(`\nAffected test files (${sortedTests.length}):\n`));
1818
+ for (const t of sortedTests) {
1819
+ console.log(' ' + chalk.cyan(t));
1820
+ }
1821
+ console.log();
1822
+ }
1823
+ }
1824
+ cg.destroy();
1825
+ }
1826
+ catch (err) {
1827
+ error(`Affected analysis failed: ${err instanceof Error ? err.message : String(err)}`);
1828
+ process.exit(1);
1829
+ }
1830
+ });
1831
+ /**
1832
+ * cgraphx install
1833
+ */
1834
+ program
1835
+ .command('install')
1836
+ .description('Install cgraphx MCP server into one or more agents (Claude Code, Cursor, Codex CLI, opencode, Hermes Agent)')
1837
+ .option('-t, --target <ids>', 'Target agent(s): comma-separated ids, or "auto"|"all"|"none". Default: prompt')
1838
+ .option('-l, --location <where>', 'Install location: "global" or "local". Default: prompt')
1839
+ .option('-y, --yes', 'Non-interactive: defaults to --location=global --target=auto, auto-allow on')
1840
+ .option('--no-permissions', 'Skip writing the auto-allow permissions list (Claude Code only)')
1841
+ .option('--print-config <id>', 'Print MCP config snippet for the named agent and exit (no file writes)')
1842
+ .action(async (opts) => {
1843
+ if (opts.printConfig) {
1844
+ const { getTarget, listTargetIds } = await Promise.resolve().then(() => __importStar(require('../installer/targets/registry')));
1845
+ const target = getTarget(opts.printConfig);
1846
+ if (!target) {
1847
+ const known = listTargetIds().join(', ');
1848
+ error(`Unknown target "${opts.printConfig}". Known: ${known}.`);
1849
+ process.exit(1);
1850
+ }
1851
+ const loc = (opts.location === 'local' ? 'local' : 'global');
1852
+ process.stdout.write(target.printConfig(loc));
1853
+ return;
1854
+ }
1855
+ const { runInstallerWithOptions } = await Promise.resolve().then(() => __importStar(require('../installer')));
1856
+ if (opts.location && opts.location !== 'global' && opts.location !== 'local') {
1857
+ error(`--location must be "global" or "local" (got "${opts.location}").`);
1858
+ process.exit(1);
1859
+ }
1860
+ try {
1861
+ // Commander's `--no-permissions` makes `opts.permissions === false`;
1862
+ // omitting the flag leaves it `true` (the positive-form default).
1863
+ // We MUST treat the default-true as "user did not override — let
1864
+ // the orchestrator prompt" and only forward an explicit `false`
1865
+ // (or `true` when --yes implies it). Otherwise the auto-allow
1866
+ // prompt is silently skipped on every interactive run.
1867
+ const explicitNoPermissions = opts.permissions === false;
1868
+ const autoAllow = explicitNoPermissions
1869
+ ? false
1870
+ : opts.yes
1871
+ ? true
1872
+ : undefined;
1873
+ await runInstallerWithOptions({
1874
+ target: opts.target,
1875
+ location: opts.location,
1876
+ autoAllow,
1877
+ yes: opts.yes,
1878
+ });
1879
+ }
1880
+ catch (err) {
1881
+ error(err instanceof Error ? err.message : String(err));
1882
+ process.exit(1);
1883
+ }
1884
+ });
1885
+ /**
1886
+ * cgraphx uninstall
1887
+ *
1888
+ * Inverse of `install`. Removes the codegraph MCP server entry,
1889
+ * instructions block, and permissions from every agent (or a
1890
+ * `--target` subset). Prompts global-vs-local when not given. Does NOT
1891
+ * delete the `.cgraphx/` index — that's `cgraphx uninit`.
1892
+ */
1893
+ program
1894
+ .command('uninstall')
1895
+ .description('Remove cgraphx from your agents (Claude Code, Cursor, Codex CLI, opencode, Hermes Agent)')
1896
+ .option('-t, --target <ids>', 'Target agent(s): comma-separated ids, or "all". Default: all')
1897
+ .option('-l, --location <where>', 'Uninstall location: "global" or "local". Default: prompt')
1898
+ .option('-y, --yes', 'Non-interactive: defaults to --location=global --target=all')
1899
+ .action(async (opts) => {
1900
+ const { runUninstaller } = await Promise.resolve().then(() => __importStar(require('../installer')));
1901
+ if (opts.location && opts.location !== 'global' && opts.location !== 'local') {
1902
+ error(`--location must be "global" or "local" (got "${opts.location}").`);
1903
+ process.exit(1);
1904
+ }
1905
+ try {
1906
+ await runUninstaller({
1907
+ target: opts.target,
1908
+ location: opts.location,
1909
+ yes: opts.yes,
1910
+ });
1911
+ }
1912
+ catch (err) {
1913
+ error(err instanceof Error ? err.message : String(err));
1914
+ process.exit(1);
1915
+ }
1916
+ });
1917
+ /**
1918
+ * cgraphx telemetry [on|off|status]
1919
+ */
1920
+ program
1921
+ .command('telemetry [action]')
1922
+ .description('Show or change anonymous usage telemetry (status, on, off)')
1923
+ .action((action) => {
1924
+ const t = (0, telemetry_1.getTelemetry)();
1925
+ if (action === 'on' || action === 'off') {
1926
+ t.setEnabled(action === 'on', 'cli');
1927
+ if (action === 'on') {
1928
+ success('Telemetry enabled — anonymous usage stats only (no code, paths, or names).');
1929
+ }
1930
+ else {
1931
+ success('Telemetry disabled. Buffered, unsent data was deleted.');
1932
+ }
1933
+ const effective = t.getStatus();
1934
+ if (effective.decidedBy === 'DO_NOT_TRACK' || effective.decidedBy === 'CGRAPHX_TELEMETRY') {
1935
+ warn(`The ${effective.decidedBy} environment variable overrides this choice — ` +
1936
+ `effective state right now: ${effective.enabled ? 'enabled' : 'disabled'}.`);
1937
+ }
1938
+ return;
1939
+ }
1940
+ if (action !== undefined && action !== 'status') {
1941
+ error(`Unknown action: ${action} (expected status, on, or off)`);
1942
+ process.exit(1);
1943
+ }
1944
+ const s = t.getStatus();
1945
+ const decidedBy = {
1946
+ DO_NOT_TRACK: 'DO_NOT_TRACK environment variable',
1947
+ CGRAPHX_TELEMETRY: 'CGRAPHX_TELEMETRY environment variable',
1948
+ config: 'your saved choice',
1949
+ default: 'default',
1950
+ };
1951
+ console.log(`\nTelemetry: ${s.enabled ? chalk.green('enabled') : chalk.yellow('disabled')} ${chalk.dim(`(${decidedBy[s.decidedBy]})`)}`);
1952
+ console.log(`Machine ID: ${s.machineId ?? chalk.dim('(random UUID, created on first use)')}`);
1953
+ console.log(`Config: ${s.configPath}`);
1954
+ console.log(chalk.dim(`\nExactly what is collected (and never collected): ${telemetry_1.TELEMETRY_DOCS}\n`));
1955
+ });
1956
+ /**
1957
+ * cgraphx upgrade [version]
1958
+ *
1959
+ * Self-update, however cgraphx was installed (bundle via install.sh/.ps1,
1960
+ * npm-global, npx, or a source checkout). See ../upgrade for the detection and
1961
+ * per-method upgrade logic.
1962
+ */
1963
+ program
1964
+ .command('upgrade [version]')
1965
+ .description('Update cgraphx to the latest release (or a specific version)')
1966
+ .option('--check', 'Check whether an update is available without installing')
1967
+ .option('-f, --force', 'Reinstall even if already on the target version')
1968
+ .action(async (versionArg, options) => {
1969
+ const up = await Promise.resolve().then(() => __importStar(require('../upgrade')));
1970
+ const method = up.detectInstallMethod({
1971
+ filename: __filename,
1972
+ platform: process.platform,
1973
+ cwd: process.cwd(),
1974
+ });
1975
+ const pin = versionArg || process.env.CGRAPHX_VERSION || undefined;
1976
+ const code = await up.runUpgrade({ version: pin, check: options.check, force: options.force }, {
1977
+ currentVersion: packageJson.version,
1978
+ method,
1979
+ resolveLatest: () => up.resolveLatestVersion(),
1980
+ run: up.defaultRun,
1981
+ hasCommand: up.hasCommand,
1982
+ log: (m) => console.log(m),
1983
+ warn: (m) => warn(m),
1984
+ error: (m) => error(m),
1985
+ platform: process.platform,
1986
+ });
1987
+ process.exit(code);
1988
+ });
1989
+ /**
1990
+ * cgraphx version
1991
+ *
1992
+ * The bare-noun form of `--version`. commander already provides `--version`
1993
+ * and `-V`, and the `-v` / `-version` spellings are intercepted before parse
1994
+ * (see top of main). This subcommand makes `cgraphx version` work and lists
1995
+ * the version affordance in `cgraphx --help`.
1996
+ */
1997
+ program
1998
+ .command('version')
1999
+ .description('Print the installed cgraphx version (also: -v, --version)')
2000
+ .action(() => {
2001
+ console.log(packageJson.version);
2002
+ });
2003
+ // Markdown knowledge base subsystem (independent of the code graph).
2004
+ // Registration is a single function call so the docs command group stays
2005
+ // isolated in src/markdown/cli.ts — see docs/features/2026-06-26-docs-knowledge-base/.
2006
+ (0, cli_1.registerDocsCommands)(program);
2007
+ // db-query subsystem — isolated in src/dbquery/cli.ts.
2008
+ (0, cli_2.registerDbCommands)(program);
2009
+ // timeline subsystem — isolated in src/timeline/cli.ts.
2010
+ (0, cli_3.registerTimelineCommands)(program);
2011
+ // Parse and run
2012
+ program.parse();
2013
+ } // end main()
2014
+ //# sourceMappingURL=codegraph.js.map