ai-first-cli 1.2.2 → 1.3.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 (475) hide show
  1. package/CHANGELOG.md +292 -6
  2. package/README.md +24 -4
  3. package/dist/analyzers/symbols.d.ts.map +1 -1
  4. package/dist/analyzers/symbols.js +9 -7
  5. package/dist/analyzers/symbols.js.map +1 -1
  6. package/dist/analyzers/techStack.d.ts.map +1 -1
  7. package/dist/analyzers/techStack.js +198 -3
  8. package/dist/analyzers/techStack.js.map +1 -1
  9. package/dist/commands/ai-first.d.ts.map +1 -1
  10. package/dist/commands/ai-first.js +14 -13
  11. package/dist/commands/ai-first.js.map +1 -1
  12. package/dist/core/adapters/baseAdapter.d.ts +1 -1
  13. package/dist/core/adapters/baseAdapter.d.ts.map +1 -1
  14. package/dist/core/adapters/baseAdapter.js +50 -12
  15. package/dist/core/adapters/baseAdapter.js.map +1 -1
  16. package/dist/core/analysis/architectureDetector.d.ts +37 -0
  17. package/dist/core/analysis/architectureDetector.d.ts.map +1 -0
  18. package/dist/core/analysis/architectureDetector.js +316 -0
  19. package/dist/core/analysis/architectureDetector.js.map +1 -0
  20. package/dist/core/analysis/callGraphBuilder.d.ts +37 -0
  21. package/dist/core/analysis/callGraphBuilder.d.ts.map +1 -0
  22. package/dist/core/analysis/callGraphBuilder.js +101 -0
  23. package/dist/core/analysis/callGraphBuilder.js.map +1 -0
  24. package/dist/core/analysis/dependencyAnalyzer.d.ts +45 -0
  25. package/dist/core/analysis/dependencyAnalyzer.d.ts.map +1 -0
  26. package/dist/core/analysis/dependencyAnalyzer.js +98 -0
  27. package/dist/core/analysis/dependencyAnalyzer.js.map +1 -0
  28. package/dist/core/analysis/index.d.ts +5 -0
  29. package/dist/core/analysis/index.d.ts.map +1 -0
  30. package/dist/core/analysis/index.js +5 -0
  31. package/dist/core/analysis/index.js.map +1 -0
  32. package/dist/core/analysis/inheritanceAnalyzer.d.ts +35 -0
  33. package/dist/core/analysis/inheritanceAnalyzer.d.ts.map +1 -0
  34. package/dist/core/analysis/inheritanceAnalyzer.js +115 -0
  35. package/dist/core/analysis/inheritanceAnalyzer.js.map +1 -0
  36. package/dist/core/ccp.d.ts.map +1 -1
  37. package/dist/core/ccp.js +3 -2
  38. package/dist/core/ccp.js.map +1 -1
  39. package/dist/core/generation/aiContextGenerator.d.ts +71 -0
  40. package/dist/core/generation/aiContextGenerator.d.ts.map +1 -0
  41. package/dist/core/generation/aiContextGenerator.js +217 -0
  42. package/dist/core/generation/aiContextGenerator.js.map +1 -0
  43. package/dist/core/generation/architectureGenerator.d.ts +17 -0
  44. package/dist/core/generation/architectureGenerator.d.ts.map +1 -0
  45. package/dist/core/generation/architectureGenerator.js +160 -0
  46. package/dist/core/generation/architectureGenerator.js.map +1 -0
  47. package/dist/core/generation/flowGenerator.d.ts +52 -0
  48. package/dist/core/generation/flowGenerator.d.ts.map +1 -0
  49. package/dist/core/generation/flowGenerator.js +164 -0
  50. package/dist/core/generation/flowGenerator.js.map +1 -0
  51. package/dist/core/generation/index.d.ts +4 -0
  52. package/dist/core/generation/index.d.ts.map +1 -0
  53. package/dist/core/generation/index.js +4 -0
  54. package/dist/core/generation/index.js.map +1 -0
  55. package/dist/core/hierarchyGenerator.d.ts.map +1 -1
  56. package/dist/core/hierarchyGenerator.js +3 -2
  57. package/dist/core/hierarchyGenerator.js.map +1 -1
  58. package/dist/core/parsers/index.d.ts +20 -0
  59. package/dist/core/parsers/index.d.ts.map +1 -0
  60. package/dist/core/parsers/index.js +76 -0
  61. package/dist/core/parsers/index.js.map +1 -0
  62. package/dist/core/parsers/pythonParser.d.ts +37 -0
  63. package/dist/core/parsers/pythonParser.d.ts.map +1 -0
  64. package/dist/core/parsers/pythonParser.js +229 -0
  65. package/dist/core/parsers/pythonParser.js.map +1 -0
  66. package/dist/core/parsers/typescriptParser.d.ts +54 -0
  67. package/dist/core/parsers/typescriptParser.d.ts.map +1 -0
  68. package/dist/core/parsers/typescriptParser.js +291 -0
  69. package/dist/core/parsers/typescriptParser.js.map +1 -0
  70. package/dist/core/pipeline.d.ts +42 -0
  71. package/dist/core/pipeline.d.ts.map +1 -0
  72. package/dist/core/pipeline.js +172 -0
  73. package/dist/core/pipeline.js.map +1 -0
  74. package/dist/core/semanticContexts.d.ts.map +1 -1
  75. package/dist/core/semanticContexts.js +23 -61
  76. package/dist/core/semanticContexts.js.map +1 -1
  77. package/dist/utils/constants.d.ts +46 -0
  78. package/dist/utils/constants.d.ts.map +1 -0
  79. package/dist/utils/constants.js +67 -0
  80. package/dist/utils/constants.js.map +1 -0
  81. package/install.sh +143 -17
  82. package/package.json +1 -1
  83. package/run-all-tests.sh +184 -0
  84. package/src/analyzers/symbols.ts +12 -7
  85. package/src/analyzers/techStack.ts +203 -3
  86. package/src/commands/ai-first.ts +14 -13
  87. package/src/core/adapters/baseAdapter.ts +61 -12
  88. package/src/core/analysis/architectureDetector.ts +487 -0
  89. package/src/core/analysis/callGraphBuilder.ts +158 -0
  90. package/src/core/analysis/dependencyAnalyzer.ts +167 -0
  91. package/src/core/analysis/index.ts +28 -0
  92. package/src/core/analysis/inheritanceAnalyzer.ts +169 -0
  93. package/src/core/ccp.ts +3 -2
  94. package/src/core/generation/aiContextGenerator.ts +335 -0
  95. package/src/core/generation/architectureGenerator.ts +200 -0
  96. package/src/core/generation/flowGenerator.ts +238 -0
  97. package/src/core/generation/index.ts +16 -0
  98. package/src/core/hierarchyGenerator.ts +3 -2
  99. package/src/core/parsers/index.ts +99 -0
  100. package/src/core/parsers/pythonParser.ts +302 -0
  101. package/src/core/parsers/typescriptParser.ts +445 -0
  102. package/src/core/pipeline.ts +241 -0
  103. package/src/core/semanticContexts.ts +25 -67
  104. package/src/utils/constants.ts +78 -0
  105. package/tests/analysis.test.ts +283 -0
  106. package/tests/architectureDetector.test.ts +137 -0
  107. package/tests/generation.test.ts +216 -0
  108. package/tests/parserRegistry.test.ts +139 -0
  109. package/tests/pipeline.integration.test.ts +245 -0
  110. package/tests/pythonParser.test.ts +210 -0
  111. package/tests/typescriptParser.test.ts +197 -0
  112. package/.ai-dev/index.db +0 -0
  113. package/ANALISIS_COMPLETO.md +0 -424
  114. package/ANALISIS_MEJORAS.md +0 -327
  115. package/BUGS.md +0 -455
  116. package/PLAN_MEJORAS.md +0 -216
  117. package/STATUS_ADAPTADORES +0 -126
  118. package/TEST_RESULTS.md +0 -198
  119. package/TEST_RESULTS_COMPARATIVE.md +0 -159
  120. package/TEST_RESULTS_COMPLETE.md +0 -127
  121. package/TEST_RESULTS_COMPREHENSIVE.md +0 -208
  122. package/TEST_RESULTS_PHASE1.md +0 -420
  123. package/ai-context/ai_context.md +0 -130
  124. package/ai-context/ai_rules.md +0 -54
  125. package/ai-context/architecture.md +0 -136
  126. package/ai-context/cache.json +0 -2349
  127. package/ai-context/ccp/jira-123/context.json +0 -7
  128. package/ai-context/context/features/commands.json +0 -18
  129. package/ai-context/context/features/src.json +0 -61
  130. package/ai-context/context/features/test-projects.json +0 -69
  131. package/ai-context/context/flows/account.json +0 -9
  132. package/ai-context/context/flows/ai-first.json +0 -9
  133. package/ai-context/context/flows/api.json +0 -9
  134. package/ai-context/context/flows/auth.json +0 -13
  135. package/ai-context/context/flows/category.json +0 -12
  136. package/ai-context/context/flows/comment.json +0 -16
  137. package/ai-context/context/flows/dashboard.json +0 -9
  138. package/ai-context/context/flows/doctor.json +0 -9
  139. package/ai-context/context/flows/explore.json +0 -9
  140. package/ai-context/context/flows/login.json +0 -9
  141. package/ai-context/context/flows/opportunity.json +0 -9
  142. package/ai-context/context/flows/post.json +0 -18
  143. package/ai-context/context/flows/routes.json +0 -19
  144. package/ai-context/context/flows/user.json +0 -20
  145. package/ai-context/context/flows/users.json +0 -9
  146. package/ai-context/context/flows/views.json +0 -14
  147. package/ai-context/context/repo.json +0 -56
  148. package/ai-context/context/utils.json +0 -7
  149. package/ai-context/conventions.md +0 -53
  150. package/ai-context/dependencies.json +0 -2946
  151. package/ai-context/embeddings.json +0 -23828
  152. package/ai-context/entrypoints.md +0 -42
  153. package/ai-context/files.json +0 -2944
  154. package/ai-context/git/commit-activity.json +0 -8646
  155. package/ai-context/git/recent-features.json +0 -1
  156. package/ai-context/git/recent-files.json +0 -52
  157. package/ai-context/git/recent-flows.json +0 -1
  158. package/ai-context/graph/knowledge-graph.json +0 -44314
  159. package/ai-context/graph/module-graph.json +0 -866
  160. package/ai-context/graph/symbol-graph.json +0 -200622
  161. package/ai-context/graph/symbol-references.json +0 -6778
  162. package/ai-context/hierarchy.json +0 -20
  163. package/ai-context/index-state.json +0 -4340
  164. package/ai-context/index.db +0 -0
  165. package/ai-context/modules.json +0 -532
  166. package/ai-context/project.json +0 -30
  167. package/ai-context/repo_map.json +0 -5818
  168. package/ai-context/repo_map.md +0 -1327
  169. package/ai-context/schema.json +0 -5
  170. package/ai-context/summary.md +0 -42
  171. package/ai-context/symbols.json +0 -7
  172. package/ai-context/tech_stack.md +0 -46
  173. package/ai-context/tools.json +0 -10
  174. package/test-projects/django-app/.ai-dev/index.db +0 -0
  175. package/test-projects/django-app/ai-context/ai_context.md +0 -92
  176. package/test-projects/django-app/ai-context/ai_rules.md +0 -47
  177. package/test-projects/django-app/ai-context/architecture.md +0 -57
  178. package/test-projects/django-app/ai-context/cache.json +0 -169
  179. package/test-projects/django-app/ai-context/context/flows/views.json +0 -10
  180. package/test-projects/django-app/ai-context/conventions.md +0 -51
  181. package/test-projects/django-app/ai-context/dependencies.json +0 -312
  182. package/test-projects/django-app/ai-context/entrypoints.md +0 -4
  183. package/test-projects/django-app/ai-context/files.json +0 -209
  184. package/test-projects/django-app/ai-context/graph/knowledge-graph.json +0 -36
  185. package/test-projects/django-app/ai-context/graph/module-graph.json +0 -145
  186. package/test-projects/django-app/ai-context/graph/symbol-graph.json +0 -1488
  187. package/test-projects/django-app/ai-context/graph/symbol-references.json +0 -1
  188. package/test-projects/django-app/ai-context/index-state.json +0 -294
  189. package/test-projects/django-app/ai-context/index.db +0 -0
  190. package/test-projects/django-app/ai-context/modules.json +0 -35
  191. package/test-projects/django-app/ai-context/project.json +0 -11
  192. package/test-projects/django-app/ai-context/repo_map.json +0 -412
  193. package/test-projects/django-app/ai-context/repo_map.md +0 -105
  194. package/test-projects/django-app/ai-context/schema.json +0 -5
  195. package/test-projects/django-app/ai-context/summary.md +0 -15
  196. package/test-projects/django-app/ai-context/symbols.json +0 -1
  197. package/test-projects/django-app/ai-context/tech_stack.md +0 -32
  198. package/test-projects/django-app/ai-context/tools.json +0 -10
  199. package/test-projects/express-api/ai-context/ai_context.md +0 -112
  200. package/test-projects/express-api/ai-context/ai_rules.md +0 -50
  201. package/test-projects/express-api/ai-context/architecture.md +0 -62
  202. package/test-projects/express-api/ai-context/context/features/controllers.json +0 -13
  203. package/test-projects/express-api/ai-context/context/features/services.json +0 -13
  204. package/test-projects/express-api/ai-context/context/flows/auth.json +0 -12
  205. package/test-projects/express-api/ai-context/context/flows/user.json +0 -13
  206. package/test-projects/express-api/ai-context/conventions.md +0 -51
  207. package/test-projects/express-api/ai-context/dependencies.json +0 -54
  208. package/test-projects/express-api/ai-context/entrypoints.md +0 -17
  209. package/test-projects/express-api/ai-context/modules.json +0 -30
  210. package/test-projects/express-api/ai-context/project.json +0 -15
  211. package/test-projects/express-api/ai-context/repo_map.json +0 -100
  212. package/test-projects/express-api/ai-context/repo_map.md +0 -36
  213. package/test-projects/express-api/ai-context/schema.json +0 -5
  214. package/test-projects/express-api/ai-context/summary.md +0 -14
  215. package/test-projects/express-api/ai-context/symbols.json +0 -7
  216. package/test-projects/express-api/ai-context/tech_stack.md +0 -38
  217. package/test-projects/express-api/ai-context/tools.json +0 -10
  218. package/test-projects/fastapi-app/.ai-dev/index.db +0 -0
  219. package/test-projects/fastapi-app/ai-context/ai_context.md +0 -89
  220. package/test-projects/fastapi-app/ai-context/ai_rules.md +0 -47
  221. package/test-projects/fastapi-app/ai-context/architecture.md +0 -39
  222. package/test-projects/fastapi-app/ai-context/cache.json +0 -125
  223. package/test-projects/fastapi-app/ai-context/conventions.md +0 -51
  224. package/test-projects/fastapi-app/ai-context/dependencies.json +0 -244
  225. package/test-projects/fastapi-app/ai-context/entrypoints.md +0 -4
  226. package/test-projects/fastapi-app/ai-context/files.json +0 -154
  227. package/test-projects/fastapi-app/ai-context/graph/knowledge-graph.json +0 -15
  228. package/test-projects/fastapi-app/ai-context/graph/module-graph.json +0 -78
  229. package/test-projects/fastapi-app/ai-context/graph/symbol-graph.json +0 -1724
  230. package/test-projects/fastapi-app/ai-context/graph/symbol-references.json +0 -51
  231. package/test-projects/fastapi-app/ai-context/index-state.json +0 -217
  232. package/test-projects/fastapi-app/ai-context/index.db +0 -0
  233. package/test-projects/fastapi-app/ai-context/modules.json +0 -16
  234. package/test-projects/fastapi-app/ai-context/project.json +0 -9
  235. package/test-projects/fastapi-app/ai-context/repo_map.json +0 -298
  236. package/test-projects/fastapi-app/ai-context/repo_map.md +0 -74
  237. package/test-projects/fastapi-app/ai-context/schema.json +0 -5
  238. package/test-projects/fastapi-app/ai-context/summary.md +0 -12
  239. package/test-projects/fastapi-app/ai-context/symbols.json +0 -1
  240. package/test-projects/fastapi-app/ai-context/tech_stack.md +0 -32
  241. package/test-projects/fastapi-app/ai-context/tools.json +0 -10
  242. package/test-projects/flask-app/.ai-dev/index.db +0 -0
  243. package/test-projects/flask-app/ai-context/ai_context.md +0 -94
  244. package/test-projects/flask-app/ai-context/ai_rules.md +0 -47
  245. package/test-projects/flask-app/ai-context/architecture.md +0 -49
  246. package/test-projects/flask-app/ai-context/cache.json +0 -157
  247. package/test-projects/flask-app/ai-context/context/features/app.json +0 -25
  248. package/test-projects/flask-app/ai-context/context/flows/routes.json +0 -14
  249. package/test-projects/flask-app/ai-context/conventions.md +0 -51
  250. package/test-projects/flask-app/ai-context/dependencies.json +0 -298
  251. package/test-projects/flask-app/ai-context/entrypoints.md +0 -4
  252. package/test-projects/flask-app/ai-context/files.json +0 -194
  253. package/test-projects/flask-app/ai-context/graph/knowledge-graph.json +0 -60
  254. package/test-projects/flask-app/ai-context/graph/module-graph.json +0 -95
  255. package/test-projects/flask-app/ai-context/graph/symbol-graph.json +0 -1448
  256. package/test-projects/flask-app/ai-context/graph/symbol-references.json +0 -45
  257. package/test-projects/flask-app/ai-context/index-state.json +0 -273
  258. package/test-projects/flask-app/ai-context/index.db +0 -0
  259. package/test-projects/flask-app/ai-context/modules.json +0 -21
  260. package/test-projects/flask-app/ai-context/project.json +0 -13
  261. package/test-projects/flask-app/ai-context/repo_map.json +0 -400
  262. package/test-projects/flask-app/ai-context/repo_map.md +0 -98
  263. package/test-projects/flask-app/ai-context/schema.json +0 -5
  264. package/test-projects/flask-app/ai-context/summary.md +0 -13
  265. package/test-projects/flask-app/ai-context/symbols.json +0 -1
  266. package/test-projects/flask-app/ai-context/tech_stack.md +0 -32
  267. package/test-projects/flask-app/ai-context/tools.json +0 -10
  268. package/test-projects/laravel-app/.ai-dev/index.db +0 -0
  269. package/test-projects/laravel-app/ai-context/ai_context.md +0 -97
  270. package/test-projects/laravel-app/ai-context/ai_rules.md +0 -47
  271. package/test-projects/laravel-app/ai-context/architecture.md +0 -60
  272. package/test-projects/laravel-app/ai-context/cache.json +0 -161
  273. package/test-projects/laravel-app/ai-context/context/features/app.json +0 -21
  274. package/test-projects/laravel-app/ai-context/context/flows/.json +0 -9
  275. package/test-projects/laravel-app/ai-context/context/flows/category.json +0 -12
  276. package/test-projects/laravel-app/ai-context/context/flows/comment.json +0 -12
  277. package/test-projects/laravel-app/ai-context/context/flows/post.json +0 -12
  278. package/test-projects/laravel-app/ai-context/context/flows/unnamed.json +0 -9
  279. package/test-projects/laravel-app/ai-context/conventions.md +0 -51
  280. package/test-projects/laravel-app/ai-context/dependencies.json +0 -6
  281. package/test-projects/laravel-app/ai-context/entrypoints.md +0 -4
  282. package/test-projects/laravel-app/ai-context/files.json +0 -199
  283. package/test-projects/laravel-app/ai-context/graph/knowledge-graph.json +0 -98
  284. package/test-projects/laravel-app/ai-context/graph/module-graph.json +0 -30
  285. package/test-projects/laravel-app/ai-context/graph/symbol-graph.json +0 -5
  286. package/test-projects/laravel-app/ai-context/graph/symbol-references.json +0 -1
  287. package/test-projects/laravel-app/ai-context/index-state.json +0 -280
  288. package/test-projects/laravel-app/ai-context/index.db +0 -0
  289. package/test-projects/laravel-app/ai-context/modules.json +0 -29
  290. package/test-projects/laravel-app/ai-context/project.json +0 -17
  291. package/test-projects/laravel-app/ai-context/repo_map.json +0 -419
  292. package/test-projects/laravel-app/ai-context/repo_map.md +0 -106
  293. package/test-projects/laravel-app/ai-context/schema.json +0 -5
  294. package/test-projects/laravel-app/ai-context/summary.md +0 -15
  295. package/test-projects/laravel-app/ai-context/symbols.json +0 -1
  296. package/test-projects/laravel-app/ai-context/tech_stack.md +0 -34
  297. package/test-projects/laravel-app/ai-context/tools.json +0 -10
  298. package/test-projects/nestjs-backend/.ai-dev/index.db +0 -0
  299. package/test-projects/nestjs-backend/ai-context/ai_context.md +0 -111
  300. package/test-projects/nestjs-backend/ai-context/ai_rules.md +0 -52
  301. package/test-projects/nestjs-backend/ai-context/architecture.md +0 -49
  302. package/test-projects/nestjs-backend/ai-context/cache.json +0 -169
  303. package/test-projects/nestjs-backend/ai-context/context/features/src.json +0 -23
  304. package/test-projects/nestjs-backend/ai-context/context/flows/auth.controller.json +0 -14
  305. package/test-projects/nestjs-backend/ai-context/context/flows/auth.json +0 -10
  306. package/test-projects/nestjs-backend/ai-context/context/flows/users..json +0 -10
  307. package/test-projects/nestjs-backend/ai-context/context/flows/users.controller.json +0 -14
  308. package/test-projects/nestjs-backend/ai-context/context/flows/users.json +0 -10
  309. package/test-projects/nestjs-backend/ai-context/conventions.md +0 -52
  310. package/test-projects/nestjs-backend/ai-context/dependencies.json +0 -152
  311. package/test-projects/nestjs-backend/ai-context/entrypoints.md +0 -18
  312. package/test-projects/nestjs-backend/ai-context/files.json +0 -209
  313. package/test-projects/nestjs-backend/ai-context/graph/knowledge-graph.json +0 -132
  314. package/test-projects/nestjs-backend/ai-context/graph/module-graph.json +0 -29
  315. package/test-projects/nestjs-backend/ai-context/graph/symbol-graph.json +0 -304
  316. package/test-projects/nestjs-backend/ai-context/graph/symbol-references.json +0 -5
  317. package/test-projects/nestjs-backend/ai-context/index-state.json +0 -294
  318. package/test-projects/nestjs-backend/ai-context/index.db +0 -0
  319. package/test-projects/nestjs-backend/ai-context/modules.json +0 -19
  320. package/test-projects/nestjs-backend/ai-context/project.json +0 -18
  321. package/test-projects/nestjs-backend/ai-context/repo_map.json +0 -427
  322. package/test-projects/nestjs-backend/ai-context/repo_map.md +0 -104
  323. package/test-projects/nestjs-backend/ai-context/schema.json +0 -5
  324. package/test-projects/nestjs-backend/ai-context/summary.md +0 -13
  325. package/test-projects/nestjs-backend/ai-context/symbols.json +0 -1
  326. package/test-projects/nestjs-backend/ai-context/tech_stack.md +0 -38
  327. package/test-projects/nestjs-backend/ai-context/tools.json +0 -10
  328. package/test-projects/python-cli/.ai-dev/index.db +0 -0
  329. package/test-projects/python-cli/ai-context/ai_context.md +0 -95
  330. package/test-projects/python-cli/ai-context/ai_rules.md +0 -47
  331. package/test-projects/python-cli/ai-context/architecture.md +0 -55
  332. package/test-projects/python-cli/ai-context/cache.json +0 -149
  333. package/test-projects/python-cli/ai-context/context/features/cli.json +0 -16
  334. package/test-projects/python-cli/ai-context/context/flows/list_.json +0 -9
  335. package/test-projects/python-cli/ai-context/context/flows/remove_.json +0 -9
  336. package/test-projects/python-cli/ai-context/conventions.md +0 -51
  337. package/test-projects/python-cli/ai-context/dependencies.json +0 -66
  338. package/test-projects/python-cli/ai-context/entrypoints.md +0 -4
  339. package/test-projects/python-cli/ai-context/files.json +0 -184
  340. package/test-projects/python-cli/ai-context/graph/knowledge-graph.json +0 -83
  341. package/test-projects/python-cli/ai-context/graph/module-graph.json +0 -31
  342. package/test-projects/python-cli/ai-context/graph/symbol-graph.json +0 -358
  343. package/test-projects/python-cli/ai-context/graph/symbol-references.json +0 -11
  344. package/test-projects/python-cli/ai-context/index-state.json +0 -259
  345. package/test-projects/python-cli/ai-context/index.db +0 -0
  346. package/test-projects/python-cli/ai-context/modules.json +0 -21
  347. package/test-projects/python-cli/ai-context/project.json +0 -15
  348. package/test-projects/python-cli/ai-context/repo_map.json +0 -367
  349. package/test-projects/python-cli/ai-context/repo_map.md +0 -93
  350. package/test-projects/python-cli/ai-context/schema.json +0 -5
  351. package/test-projects/python-cli/ai-context/summary.md +0 -14
  352. package/test-projects/python-cli/ai-context/symbols.json +0 -1
  353. package/test-projects/python-cli/ai-context/tech_stack.md +0 -32
  354. package/test-projects/python-cli/ai-context/tools.json +0 -10
  355. package/test-projects/rails-app/.ai-dev/index.db +0 -0
  356. package/test-projects/rails-app/ai-context/ai_context.md +0 -94
  357. package/test-projects/rails-app/ai-context/ai_rules.md +0 -47
  358. package/test-projects/rails-app/ai-context/architecture.md +0 -49
  359. package/test-projects/rails-app/ai-context/cache.json +0 -193
  360. package/test-projects/rails-app/ai-context/context/features/app.json +0 -24
  361. package/test-projects/rails-app/ai-context/context/features/config.json +0 -13
  362. package/test-projects/rails-app/ai-context/context/flows/application.json +0 -9
  363. package/test-projects/rails-app/ai-context/context/flows/application_.json +0 -9
  364. package/test-projects/rails-app/ai-context/context/flows/comments.json +0 -11
  365. package/test-projects/rails-app/ai-context/context/flows/comments_.json +0 -11
  366. package/test-projects/rails-app/ai-context/context/flows/posts.json +0 -11
  367. package/test-projects/rails-app/ai-context/context/flows/posts_.json +0 -11
  368. package/test-projects/rails-app/ai-context/context/flows/routes.json +0 -9
  369. package/test-projects/rails-app/ai-context/context/flows/users.json +0 -11
  370. package/test-projects/rails-app/ai-context/context/flows/users_.json +0 -11
  371. package/test-projects/rails-app/ai-context/conventions.md +0 -51
  372. package/test-projects/rails-app/ai-context/dependencies.json +0 -6
  373. package/test-projects/rails-app/ai-context/entrypoints.md +0 -4
  374. package/test-projects/rails-app/ai-context/files.json +0 -239
  375. package/test-projects/rails-app/ai-context/graph/knowledge-graph.json +0 -130
  376. package/test-projects/rails-app/ai-context/graph/module-graph.json +0 -27
  377. package/test-projects/rails-app/ai-context/graph/symbol-graph.json +0 -5
  378. package/test-projects/rails-app/ai-context/graph/symbol-references.json +0 -1
  379. package/test-projects/rails-app/ai-context/index-state.json +0 -336
  380. package/test-projects/rails-app/ai-context/index.db +0 -0
  381. package/test-projects/rails-app/ai-context/modules.json +0 -26
  382. package/test-projects/rails-app/ai-context/project.json +0 -22
  383. package/test-projects/rails-app/ai-context/repo_map.json +0 -486
  384. package/test-projects/rails-app/ai-context/repo_map.md +0 -117
  385. package/test-projects/rails-app/ai-context/schema.json +0 -5
  386. package/test-projects/rails-app/ai-context/summary.md +0 -13
  387. package/test-projects/rails-app/ai-context/symbols.json +0 -1
  388. package/test-projects/rails-app/ai-context/tech_stack.md +0 -32
  389. package/test-projects/rails-app/ai-context/tools.json +0 -10
  390. package/test-projects/react-app/.ai-dev/index.db +0 -0
  391. package/test-projects/react-app/ai-context/ai_context.md +0 -96
  392. package/test-projects/react-app/ai-context/ai_rules.md +0 -49
  393. package/test-projects/react-app/ai-context/architecture.md +0 -39
  394. package/test-projects/react-app/ai-context/cache.json +0 -153
  395. package/test-projects/react-app/ai-context/context/features/src.json +0 -18
  396. package/test-projects/react-app/ai-context/context/flows/UsersPage.json +0 -14
  397. package/test-projects/react-app/ai-context/context/flows/dashboard.json +0 -9
  398. package/test-projects/react-app/ai-context/context/flows/login.json +0 -9
  399. package/test-projects/react-app/ai-context/context/flows/users.json +0 -9
  400. package/test-projects/react-app/ai-context/conventions.md +0 -52
  401. package/test-projects/react-app/ai-context/dependencies.json +0 -128
  402. package/test-projects/react-app/ai-context/entrypoints.md +0 -4
  403. package/test-projects/react-app/ai-context/files.json +0 -189
  404. package/test-projects/react-app/ai-context/graph/knowledge-graph.json +0 -112
  405. package/test-projects/react-app/ai-context/graph/module-graph.json +0 -31
  406. package/test-projects/react-app/ai-context/graph/symbol-graph.json +0 -868
  407. package/test-projects/react-app/ai-context/graph/symbol-references.json +0 -31
  408. package/test-projects/react-app/ai-context/index-state.json +0 -266
  409. package/test-projects/react-app/ai-context/index.db +0 -0
  410. package/test-projects/react-app/ai-context/modules.json +0 -17
  411. package/test-projects/react-app/ai-context/project.json +0 -16
  412. package/test-projects/react-app/ai-context/repo_map.json +0 -391
  413. package/test-projects/react-app/ai-context/repo_map.md +0 -94
  414. package/test-projects/react-app/ai-context/schema.json +0 -5
  415. package/test-projects/react-app/ai-context/summary.md +0 -13
  416. package/test-projects/react-app/ai-context/symbols.json +0 -1
  417. package/test-projects/react-app/ai-context/tech_stack.md +0 -39
  418. package/test-projects/react-app/ai-context/tools.json +0 -10
  419. package/test-projects/salesforce-cli/.ai-dev/index.db +0 -0
  420. package/test-projects/salesforce-cli/ai-context/ai_context.md +0 -89
  421. package/test-projects/salesforce-cli/ai-context/ai_rules.md +0 -47
  422. package/test-projects/salesforce-cli/ai-context/architecture.md +0 -39
  423. package/test-projects/salesforce-cli/ai-context/cache.json +0 -125
  424. package/test-projects/salesforce-cli/ai-context/context/features/force-app.json +0 -14
  425. package/test-projects/salesforce-cli/ai-context/context/flows/account.json +0 -9
  426. package/test-projects/salesforce-cli/ai-context/context/flows/opportunity.json +0 -9
  427. package/test-projects/salesforce-cli/ai-context/conventions.md +0 -51
  428. package/test-projects/salesforce-cli/ai-context/dependencies.json +0 -6
  429. package/test-projects/salesforce-cli/ai-context/entrypoints.md +0 -4
  430. package/test-projects/salesforce-cli/ai-context/files.json +0 -154
  431. package/test-projects/salesforce-cli/ai-context/graph/knowledge-graph.json +0 -64
  432. package/test-projects/salesforce-cli/ai-context/graph/module-graph.json +0 -13
  433. package/test-projects/salesforce-cli/ai-context/graph/symbol-graph.json +0 -148
  434. package/test-projects/salesforce-cli/ai-context/graph/symbol-references.json +0 -1
  435. package/test-projects/salesforce-cli/ai-context/index-state.json +0 -217
  436. package/test-projects/salesforce-cli/ai-context/index.db +0 -0
  437. package/test-projects/salesforce-cli/ai-context/modules.json +0 -12
  438. package/test-projects/salesforce-cli/ai-context/project.json +0 -14
  439. package/test-projects/salesforce-cli/ai-context/repo_map.json +0 -328
  440. package/test-projects/salesforce-cli/ai-context/repo_map.md +0 -80
  441. package/test-projects/salesforce-cli/ai-context/schema.json +0 -5
  442. package/test-projects/salesforce-cli/ai-context/summary.md +0 -13
  443. package/test-projects/salesforce-cli/ai-context/symbols.json +0 -1
  444. package/test-projects/salesforce-cli/ai-context/tech_stack.md +0 -31
  445. package/test-projects/salesforce-cli/ai-context/tools.json +0 -10
  446. package/test-projects/spring-boot-app/.ai-dev/index.db +0 -0
  447. package/test-projects/spring-boot-app/ai-context/ai_context.md +0 -91
  448. package/test-projects/spring-boot-app/ai-context/ai_rules.md +0 -48
  449. package/test-projects/spring-boot-app/ai-context/architecture.md +0 -39
  450. package/test-projects/spring-boot-app/ai-context/cache.json +0 -173
  451. package/test-projects/spring-boot-app/ai-context/context/features/src.json +0 -26
  452. package/test-projects/spring-boot-app/ai-context/context/flows/PostController.json +0 -19
  453. package/test-projects/spring-boot-app/ai-context/context/flows/UserController.json +0 -19
  454. package/test-projects/spring-boot-app/ai-context/context/flows/comment.json +0 -11
  455. package/test-projects/spring-boot-app/ai-context/context/flows/post.json +0 -14
  456. package/test-projects/spring-boot-app/ai-context/context/flows/user.json +0 -14
  457. package/test-projects/spring-boot-app/ai-context/conventions.md +0 -52
  458. package/test-projects/spring-boot-app/ai-context/dependencies.json +0 -326
  459. package/test-projects/spring-boot-app/ai-context/entrypoints.md +0 -4
  460. package/test-projects/spring-boot-app/ai-context/files.json +0 -214
  461. package/test-projects/spring-boot-app/ai-context/graph/knowledge-graph.json +0 -231
  462. package/test-projects/spring-boot-app/ai-context/graph/module-graph.json +0 -22
  463. package/test-projects/spring-boot-app/ai-context/graph/symbol-graph.json +0 -794
  464. package/test-projects/spring-boot-app/ai-context/graph/symbol-references.json +0 -70
  465. package/test-projects/spring-boot-app/ai-context/index-state.json +0 -301
  466. package/test-projects/spring-boot-app/ai-context/index.db +0 -0
  467. package/test-projects/spring-boot-app/ai-context/modules.json +0 -21
  468. package/test-projects/spring-boot-app/ai-context/project.json +0 -17
  469. package/test-projects/spring-boot-app/ai-context/repo_map.json +0 -461
  470. package/test-projects/spring-boot-app/ai-context/repo_map.md +0 -109
  471. package/test-projects/spring-boot-app/ai-context/schema.json +0 -5
  472. package/test-projects/spring-boot-app/ai-context/summary.md +0 -12
  473. package/test-projects/spring-boot-app/ai-context/symbols.json +0 -1
  474. package/test-projects/spring-boot-app/ai-context/tech_stack.md +0 -32
  475. package/test-projects/spring-boot-app/ai-context/tools.json +0 -10
@@ -1,6 +1,7 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
  import { ensureDir, writeFile, readJsonFile } from "../utils/fileUtils.js";
4
+ import { DEFAULT_ADAPTER, type AnalysisAdapter } from "./adapters/baseAdapter.js";
4
5
 
5
6
  export interface Feature {
6
7
  name: string;
@@ -23,77 +24,31 @@ export interface SemanticContexts {
23
24
  flows: Flow[];
24
25
  }
25
26
 
26
- // ============================================================
27
- // CONFIGURATION - Feature Detection Rules
28
- // ============================================================
27
+ // Use DEFAULT_ADAPTER which has universal patterns for ALL languages/frameworks
28
+ const ADAPTER = DEFAULT_ADAPTER;
29
+
30
+ const CANDIDATE_ROOTS = ADAPTER.featureRoots;
31
+ const IGNORED_FOLDERS = new Set(ADAPTER.ignoredFolders);
32
+ const ENTRYPOINT_PATTERNS = ADAPTER.entrypointPatterns;
33
+ const FLOW_ENTRY_PATTERNS = ADAPTER.flowEntrypointPatterns;
34
+ const FLOW_EXCLUDE = new Set(ADAPTER.flowExcludePatterns);
35
+
36
+ const LAYER_PATTERNS: Record<string, string[]> = {};
37
+ for (const layer of ADAPTER.layerRules) {
38
+ LAYER_PATTERNS[layer.name] = layer.patterns;
39
+ }
29
40
 
30
- // 1. Candidate roots - scan inside these directories
31
- const CANDIDATE_ROOTS = [
32
- "src", "app", "packages", "services", "modules", "features",
33
- // MVC patterns - for projects without src/ prefix
34
- "controllers", "routes", "handlers", "views", "pages"
35
- ];
36
-
37
- // 2. Ignore folders - these are technical, not business features
38
- const IGNORED_FOLDERS = new Set([
39
- "utils",
40
- "helpers",
41
- "types",
42
- "interfaces",
43
- "constants",
44
- "config",
45
- "dto",
46
- "common",
47
- "shared"
48
- ]);
49
-
50
- // 3. Entrypoint patterns - files that indicate a business feature
51
- const ENTRYPOINT_PATTERNS = [
52
- "controller",
53
- "route",
54
- "handler",
55
- "command",
56
- "service"
57
- ];
58
-
59
- // 4. Flow-specific patterns
60
- const FLOW_ENTRY_PATTERNS = [
61
- "controller", "route", "handler", "command",
62
- // Frontend patterns
63
- "page", "screen", "view", "component"
64
- ];
65
-
66
- // 5. Flow exclusion patterns
67
- const FLOW_EXCLUDE = new Set([
68
- "repository", "repo", "utils", "helper", "model", "entity",
69
- "dto", "type", "interface", "constant", "config"
70
- ]);
71
-
72
- // 6. Layer detection
73
- const LAYER_PATTERNS: Record<string, string[]> = {
74
- api: ["controller", "handler", "route", "router", "api", "endpoint"],
75
- service: ["service", "services", "usecase", "interactor"],
76
- data: ["repository", "repo", "dal", "dao", "data", "persistence"],
77
- domain: ["model", "entity", "schema", "domain"],
78
- util: ["util", "helper", "lib", "common"]
79
- };
80
-
81
- const LAYER_PRIORITY: Record<string, number> = {
82
- api: 1, controller: 1, handler: 1, route: 1, router: 1,
83
- service: 2, usecase: 2, interactor: 2,
84
- data: 3, repository: 3, repo: 3, dal: 3, dao: 3, persistence: 3,
85
- model: 4, entity: 4, domain: 4,
86
- };
41
+ const LAYER_PRIORITY: Record<string, number> = {};
42
+ for (const layer of ADAPTER.layerRules) {
43
+ for (const pattern of layer.patterns) {
44
+ LAYER_PRIORITY[pattern] = layer.priority;
45
+ }
46
+ }
87
47
 
88
48
  const MAX_FLOW_DEPTH = 5;
89
49
  const MAX_FLOW_FILES = 30;
90
50
 
91
- // Supported source file extensions
92
- const SOURCE_EXTENSIONS = new Set([
93
- ".ts", ".tsx", ".js", ".jsx", ".py", ".java", ".kt", ".go", ".rs", ".rb", ".php", ".cs", ".vue", ".svelte",
94
- // Salesforce/Apex
95
- ".cls", ".trigger", ".apex", ".object"
96
- ]);
51
+ const SOURCE_EXTENSIONS = new Set(ADAPTER.supportedExtensions);
97
52
 
98
53
  // ============================================================
99
54
  // HELPER FUNCTIONS
@@ -145,7 +100,7 @@ function getLayer(filePath: string): string {
145
100
  );
146
101
 
147
102
  for (const [layer, patterns] of Object.entries(LAYER_PATTERNS)) {
148
- if (parts.some(s => patterns.includes(s))) {
103
+ if (parts.some(s => patterns.some(p => s.includes(p)))) {
149
104
  return layer;
150
105
  }
151
106
  }
@@ -304,6 +259,9 @@ export function generateFeatures(
304
259
  // Extract feature name from path - get the last segment
305
260
  const featureName = mod.path.split("/").pop() || moduleName;
306
261
 
262
+ // Skip ignored folders (utils, helpers, types, etc.)
263
+ if (isIgnoredFolder(featureName)) continue;
264
+
307
265
  features.push({
308
266
  name: featureName,
309
267
  path: mod.path,
@@ -0,0 +1,78 @@
1
+ import path from "path";
2
+
3
+ /**
4
+ * Constantes centralizadas para rutas del sistema ai-first-cli
5
+ *
6
+ * Esta migración de ai/ a ai-context/ fue realizada para estandarizar
7
+ * la arquitectura y evitar inconsistencias entre comandos.
8
+ */
9
+
10
+ // Directorio principal de contexto (arquitectura nueva)
11
+ export const AI_CONTEXT_DIR = "ai-context";
12
+
13
+ // Directorio legacy (para compatibilidad hacia atrás)
14
+ export const AI_LEGACY_DIR = "ai";
15
+
16
+ /**
17
+ * Obtiene la ruta completa al directorio ai-context/
18
+ */
19
+ export function getAiContextDir(rootDir: string): string {
20
+ return path.join(rootDir, AI_CONTEXT_DIR);
21
+ }
22
+
23
+ /**
24
+ * Obtiene la ruta completa al archivo index.db
25
+ */
26
+ export function getIndexDbPath(rootDir: string): string {
27
+ return path.join(rootDir, AI_CONTEXT_DIR, "index.db");
28
+ }
29
+
30
+ /**
31
+ * Obtiene la ruta completa al archivo hierarchy.json
32
+ */
33
+ export function getHierarchyPath(rootDir: string): string {
34
+ return path.join(rootDir, AI_CONTEXT_DIR, "hierarchy.json");
35
+ }
36
+
37
+ /**
38
+ * Obtiene la ruta al directorio ccp/
39
+ */
40
+ export function getCcpDir(rootDir: string): string {
41
+ return path.join(rootDir, AI_CONTEXT_DIR, "ccp");
42
+ }
43
+
44
+ /**
45
+ * Obtiene la ruta completa a un archivo CCP específico
46
+ */
47
+ export function getCcpPath(rootDir: string, name: string): string {
48
+ return path.join(rootDir, AI_CONTEXT_DIR, "ccp", name, "context.json");
49
+ }
50
+
51
+ /**
52
+ * Obtiene la ruta al directorio de features
53
+ */
54
+ export function getFeaturesDir(rootDir: string): string {
55
+ return path.join(rootDir, AI_CONTEXT_DIR, "context", "features");
56
+ }
57
+
58
+ /**
59
+ * Obtiene la ruta al directorio de flows
60
+ */
61
+ export function getFlowsDir(rootDir: string): string {
62
+ return path.join(rootDir, AI_CONTEXT_DIR, "context", "flows");
63
+ }
64
+
65
+ /**
66
+ * Obtiene la ruta al directorio graph/
67
+ */
68
+ export function getGraphDir(rootDir: string): string {
69
+ return path.join(rootDir, AI_CONTEXT_DIR, "graph");
70
+ }
71
+
72
+ /**
73
+ * Verifica si una ruta corresponde al directorio ai-context/ o ai/ legacy
74
+ * Util para excluir estos directorios del análisis
75
+ */
76
+ export function isAiDirectory(dirName: string): boolean {
77
+ return dirName === AI_CONTEXT_DIR || dirName === AI_LEGACY_DIR;
78
+ }
@@ -0,0 +1,283 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ dependencyAnalyzer,
4
+ callGraphBuilder,
5
+ inheritanceAnalyzer,
6
+ } from "../src/core/analysis/index.js";
7
+
8
+ describe("Dependency Analyzer", () => {
9
+ it("should analyze imports", () => {
10
+ const filePath = "src/auth/service.ts";
11
+ const imports = [
12
+ { name: "express", module: "express", isDefault: true },
13
+ { name: "User", module: "./user.model", isDefault: false },
14
+ ];
15
+ const exports = ["AuthService"];
16
+
17
+ const relations = dependencyAnalyzer.analyzeImports(filePath, imports, exports);
18
+
19
+ expect(relations).toHaveLength(3);
20
+
21
+ const expressImport = relations.find((r) => r.to === "express");
22
+ expect(expressImport).toBeDefined();
23
+ expect(expressImport?.type).toBe("import");
24
+ expect(expressImport?.isDefault).toBe(true);
25
+
26
+ const userImport = relations.find((r) => r.to === "./user.model");
27
+ expect(userImport?.symbols).toContain("User");
28
+
29
+ const authExport = relations.find((r) => r.type === "export");
30
+ expect(authExport?.symbols).toContain("AuthService");
31
+ });
32
+
33
+ it("should build dependency graph", () => {
34
+ const files = [
35
+ {
36
+ filePath: "src/auth.ts",
37
+ imports: [{ name: "User", module: "./user", isDefault: false }],
38
+ exports: ["AuthService"],
39
+ },
40
+ {
41
+ filePath: "src/user.ts",
42
+ imports: [{ name: "db", module: "./db", isDefault: true }],
43
+ exports: ["User", "UserRepository"],
44
+ },
45
+ ];
46
+
47
+ const graph = dependencyAnalyzer.buildDependencyGraph(files);
48
+
49
+ expect(graph.nodes).toHaveLength(2);
50
+ expect(graph.nodes).toContain("src/auth.ts");
51
+ expect(graph.nodes).toContain("src/user.ts");
52
+ expect(graph.edges.length).toBeGreaterThanOrEqual(3);
53
+ });
54
+
55
+ it("should detect circular dependencies", () => {
56
+ const graph = dependencyAnalyzer.buildDependencyGraph([
57
+ {
58
+ filePath: "src/a.ts",
59
+ imports: [{ name: "B", module: "src/b.ts", isDefault: false }],
60
+ exports: ["A"],
61
+ },
62
+ {
63
+ filePath: "src/b.ts",
64
+ imports: [{ name: "C", module: "src/c.ts", isDefault: false }],
65
+ exports: ["B"],
66
+ },
67
+ {
68
+ filePath: "src/c.ts",
69
+ imports: [{ name: "A", module: "src/a.ts", isDefault: false }],
70
+ exports: ["C"],
71
+ },
72
+ ]);
73
+
74
+ const cycles = dependencyAnalyzer.detectCircularDependencies(graph);
75
+ expect(cycles.length).toBeGreaterThan(0);
76
+ });
77
+
78
+ it("should calculate metrics", () => {
79
+ const graph = dependencyAnalyzer.buildDependencyGraph([
80
+ {
81
+ filePath: "src/a.ts",
82
+ imports: [
83
+ { name: "utils", module: "./utils", isDefault: true },
84
+ { name: "helper", module: "./helper", isDefault: false },
85
+ ],
86
+ exports: ["A"],
87
+ },
88
+ {
89
+ filePath: "src/b.ts",
90
+ imports: [{ name: "utils", module: "./utils", isDefault: true }],
91
+ exports: ["B"],
92
+ },
93
+ ]);
94
+
95
+ const metrics = dependencyAnalyzer.calculateMetrics(graph);
96
+
97
+ expect(metrics.totalFiles).toBe(2);
98
+ expect(metrics.totalImports).toBe(3);
99
+ expect(metrics.avgImportsPerFile).toBe(1.5);
100
+ expect(metrics.mostImported[0].module).toBe("./utils");
101
+ expect(metrics.mostImported[0].count).toBe(2);
102
+ });
103
+ });
104
+
105
+ describe("Call Graph Builder", () => {
106
+ it("should build call graph", () => {
107
+ const symbols = [
108
+ { id: "src/a.ts#main", name: "main", file: "src/a.ts", type: "function" },
109
+ { id: "src/a.ts#helper", name: "helper", file: "src/a.ts", type: "function" },
110
+ { id: "src/b.ts#utils", name: "utils", file: "src/b.ts", type: "function" },
111
+ ];
112
+
113
+ const calls = [
114
+ {
115
+ caller: "src/a.ts#main",
116
+ callee: "src/a.ts#helper",
117
+ line: 10,
118
+ character: 5,
119
+ },
120
+ {
121
+ caller: "src/a.ts#helper",
122
+ callee: "src/b.ts#utils",
123
+ line: 20,
124
+ character: 8,
125
+ },
126
+ ];
127
+
128
+ const graph = callGraphBuilder.buildCallGraph(symbols, calls);
129
+
130
+ expect(graph.nodes).toHaveLength(3);
131
+ expect(graph.edges).toHaveLength(2);
132
+
133
+ const mainCalls = graph.callsByFunction.get("src/a.ts#main");
134
+ expect(mainCalls).toHaveLength(1);
135
+ expect(mainCalls?.[0].callee).toBe("src/a.ts#helper");
136
+ });
137
+
138
+ it("should find unused functions", () => {
139
+ const graph = callGraphBuilder.buildCallGraph(
140
+ [
141
+ { id: "src/a.ts#main", name: "main", file: "src/a.ts", type: "function" },
142
+ { id: "src/a.ts#used", name: "used", file: "src/a.ts", type: "function" },
143
+ { id: "src/a.ts#unused", name: "unused", file: "src/a.ts", type: "function" },
144
+ ],
145
+ [
146
+ {
147
+ caller: "src/a.ts#main",
148
+ callee: "src/a.ts#used",
149
+ line: 10,
150
+ character: 5,
151
+ },
152
+ ]
153
+ );
154
+
155
+ const unused = callGraphBuilder.findUnusedFunctions(graph);
156
+ expect(unused).toContain("src/a.ts#unused");
157
+ expect(unused).not.toContain("src/a.ts#main");
158
+ expect(unused).not.toContain("src/a.ts#used");
159
+ });
160
+
161
+ it("should get call chain", () => {
162
+ const graph = callGraphBuilder.buildCallGraph(
163
+ [
164
+ { id: "main", name: "main", file: "main.ts", type: "function" },
165
+ { id: "a", name: "a", file: "a.ts", type: "function" },
166
+ { id: "b", name: "b", file: "b.ts", type: "function" },
167
+ { id: "c", name: "c", file: "c.ts", type: "function" },
168
+ ],
169
+ [
170
+ { caller: "main", callee: "a", line: 1, character: 1 },
171
+ { caller: "a", callee: "b", line: 2, character: 2 },
172
+ { caller: "b", callee: "c", line: 3, character: 3 },
173
+ ]
174
+ );
175
+
176
+ const chain = callGraphBuilder.getCallChain(graph, "main", 5);
177
+ expect(chain).toContain("main");
178
+ expect(chain).toContain("a");
179
+ expect(chain).toContain("b");
180
+ expect(chain).toContain("c");
181
+ });
182
+ });
183
+
184
+ describe("Inheritance Analyzer", () => {
185
+ it("should build inheritance hierarchy", () => {
186
+ const symbols = [
187
+ {
188
+ id: "Animal",
189
+ name: "Animal",
190
+ type: "class",
191
+ heritage: {},
192
+ },
193
+ {
194
+ id: "Dog",
195
+ name: "Dog",
196
+ type: "class",
197
+ heritage: { extends: ["Animal"] },
198
+ },
199
+ {
200
+ id: "Cat",
201
+ name: "Cat",
202
+ type: "class",
203
+ heritage: { extends: ["Animal"] },
204
+ },
205
+ {
206
+ id: "IAnimal",
207
+ name: "IAnimal",
208
+ type: "interface",
209
+ heritage: {},
210
+ },
211
+ {
212
+ id: "DogWithInterface",
213
+ name: "DogWithInterface",
214
+ type: "class",
215
+ heritage: { extends: ["Animal"], implements: ["IAnimal"] },
216
+ },
217
+ ];
218
+
219
+ const graph = inheritanceAnalyzer.buildHierarchy(symbols);
220
+
221
+ expect(graph.nodes).toHaveLength(5);
222
+ expect(graph.edges).toHaveLength(4);
223
+
224
+ const dogExtends = graph.edges.filter((e) => e.child === "Dog" && e.type === "extends");
225
+ expect(dogExtends).toHaveLength(1);
226
+ expect(dogExtends[0].parent).toBe("Animal");
227
+
228
+ const implementsEdge = graph.edges.find((e) => e.type === "implements");
229
+ expect(implementsEdge).toBeDefined();
230
+ });
231
+
232
+ it("should get ancestors", () => {
233
+ const graph = inheritanceAnalyzer.buildHierarchy([
234
+ { id: "A", name: "A", type: "class", heritage: {} },
235
+ { id: "B", name: "B", type: "class", heritage: { extends: ["A"] } },
236
+ { id: "C", name: "C", type: "class", heritage: { extends: ["B"] } },
237
+ ]);
238
+
239
+ const ancestors = inheritanceAnalyzer.getAncestors(graph, "C");
240
+ expect(ancestors).toContain("B");
241
+ expect(ancestors).toContain("A");
242
+ });
243
+
244
+ it("should get descendants", () => {
245
+ const graph = inheritanceAnalyzer.buildHierarchy([
246
+ { id: "A", name: "A", type: "class", heritage: {} },
247
+ { id: "B", name: "B", type: "class", heritage: { extends: ["A"] } },
248
+ { id: "C", name: "C", type: "class", heritage: { extends: ["B"] } },
249
+ { id: "D", name: "D", type: "class", heritage: { extends: ["A"] } },
250
+ ]);
251
+
252
+ const descendants = inheritanceAnalyzer.getDescendants(graph, "A");
253
+ expect(descendants).toContain("B");
254
+ expect(descendants).toContain("C");
255
+ expect(descendants).toContain("D");
256
+ });
257
+
258
+ it("should calculate inheritance depth", () => {
259
+ const graph = inheritanceAnalyzer.buildHierarchy([
260
+ { id: "A", name: "A", type: "class", heritage: {} },
261
+ { id: "B", name: "B", type: "class", heritage: { extends: ["A"] } },
262
+ { id: "C", name: "C", type: "class", heritage: { extends: ["B"] } },
263
+ ]);
264
+
265
+ const depths = inheritanceAnalyzer.detectInheritanceDepth(graph);
266
+ expect(depths.get("A")).toBe(0);
267
+ expect(depths.get("B")).toBe(1);
268
+ expect(depths.get("C")).toBe(2);
269
+ });
270
+
271
+ it("should find base classes", () => {
272
+ const graph = inheritanceAnalyzer.buildHierarchy([
273
+ { id: "A", name: "A", type: "class", heritage: {} },
274
+ { id: "B", name: "B", type: "class", heritage: { extends: ["A"] } },
275
+ { id: "C", name: "C", type: "class", heritage: {} },
276
+ ]);
277
+
278
+ const baseClasses = inheritanceAnalyzer.findBaseClasses(graph);
279
+ expect(baseClasses).toContain("A");
280
+ expect(baseClasses).toContain("C");
281
+ expect(baseClasses).not.toContain("B");
282
+ });
283
+ });
@@ -0,0 +1,137 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { architectureDetector } from "../src/core/analysis/architectureDetector.js";
3
+
4
+ describe("Architecture Detector", () => {
5
+ it("should detect MVC pattern", () => {
6
+ const symbols = [
7
+ { id: "src/controllers/user.ts#UserController", name: "UserController", type: "class", file: "src/controllers/user.ts" },
8
+ { id: "src/models/user.ts#User", name: "User", type: "class", file: "src/models/user.ts" },
9
+ { id: "src/views/user.html#UserView", name: "UserView", type: "class", file: "src/views/user.html" },
10
+ ];
11
+
12
+ const graph = {
13
+ edges: [
14
+ { from: "src/controllers/user.ts#UserController", to: "src/models/user.ts#User", type: "import" },
15
+ ],
16
+ };
17
+
18
+ const result = architectureDetector.detect(symbols, graph);
19
+
20
+ expect(result.primary).not.toBeNull();
21
+ expect(result.primary?.name).toContain("MVC");
22
+ expect(result.primary?.confidence).toBeGreaterThan(0.5);
23
+ expect(result.primary?.evidence.length).toBeGreaterThan(0);
24
+ });
25
+
26
+ it("should detect Layered Architecture", () => {
27
+ const symbols = [
28
+ { id: "src/api/controller.ts#ApiController", name: "ApiController", type: "class", file: "src/api/controller.ts" },
29
+ { id: "src/services/user.ts#UserService", name: "UserService", type: "class", file: "src/services/user.ts" },
30
+ { id: "src/repositories/user.ts#UserRepository", name: "UserRepository", type: "class", file: "src/repositories/user.ts" },
31
+ ];
32
+
33
+ const graph = {
34
+ edges: [
35
+ { from: "src/api/controller.ts#ApiController", to: "src/services/user.ts#UserService", type: "import" },
36
+ { from: "src/services/user.ts#UserService", to: "src/repositories/user.ts#UserRepository", type: "import" },
37
+ ],
38
+ };
39
+
40
+ const result = architectureDetector.detect(symbols, graph);
41
+
42
+ expect(result.layers.length).toBeGreaterThanOrEqual(2);
43
+
44
+ const apiLayer = result.layers.find(l => l.name.includes("API"));
45
+ expect(apiLayer).toBeDefined();
46
+ expect(apiLayer?.symbols).toContain("src/api/controller.ts#ApiController");
47
+
48
+ const serviceLayer = result.layers.find(l => l.name.includes("Service"));
49
+ expect(serviceLayer).toBeDefined();
50
+ expect(serviceLayer?.symbols).toContain("src/services/user.ts#UserService");
51
+ });
52
+
53
+ it("should detect Clean Architecture", () => {
54
+ const symbols = [
55
+ { id: "src/domain/entity.ts#User", name: "User", type: "class", file: "src/domain/entity.ts" },
56
+ { id: "src/usecases/create.ts#CreateUserUseCase", name: "CreateUserUseCase", type: "class", file: "src/usecases/create.ts" },
57
+ { id: "src/interfaces/controller.ts#UserController", name: "UserController", type: "class", file: "src/interfaces/controller.ts" },
58
+ ];
59
+
60
+ const graph = {
61
+ edges: [
62
+ { from: "src/usecases/create.ts#CreateUserUseCase", to: "src/domain/entity.ts#User", type: "import" },
63
+ ],
64
+ };
65
+
66
+ const result = architectureDetector.detect(symbols, graph);
67
+
68
+ const cleanArch = result.secondary.find(p => p.name.includes("Clean"));
69
+ expect(cleanArch || result.primary?.name.includes("Clean")).toBeTruthy();
70
+ });
71
+
72
+ it("should detect entry points", () => {
73
+ const symbols = [
74
+ { id: "src/main.ts#main", name: "main", type: "function", file: "src/main.ts" },
75
+ { id: "src/index.ts#bootstrap", name: "bootstrap", type: "function", file: "src/index.ts" },
76
+ { id: "src/utils/helper.ts#helper", name: "helper", type: "function", file: "src/utils/helper.ts" },
77
+ ];
78
+
79
+ const graph = { edges: [] };
80
+
81
+ const result = architectureDetector.detect(symbols, graph);
82
+
83
+ expect(result.entryPoints).toContain("src/main.ts#main");
84
+ expect(result.entryPoints).toContain("src/index.ts#bootstrap");
85
+ expect(result.entryPoints).not.toContain("src/utils/helper.ts#helper");
86
+ });
87
+
88
+ it("should detect multiple patterns", () => {
89
+ const symbols = [
90
+ { id: "src/controllers/home.ts#HomeController", name: "HomeController", type: "class", file: "src/controllers/home.ts" },
91
+ { id: "src/models/user.ts#User", name: "User", type: "class", file: "src/models/user.ts" },
92
+ { id: "src/services/auth.ts#AuthService", name: "AuthService", type: "class", file: "src/services/auth.ts" },
93
+ { id: "src/repositories/user.ts#UserRepository", name: "UserRepository", type: "class", file: "src/repositories/user.ts" },
94
+ ];
95
+
96
+ const graph = {
97
+ edges: [
98
+ { from: "src/controllers/home.ts#HomeController", to: "src/services/auth.ts#AuthService", type: "import" },
99
+ { from: "src/services/auth.ts#AuthService", to: "src/repositories/user.ts#UserRepository", type: "import" },
100
+ ],
101
+ };
102
+
103
+ const result = architectureDetector.detect(symbols, graph);
104
+
105
+ expect(result.secondary.length).toBeGreaterThan(0);
106
+ const totalPatterns = (result.primary ? 1 : 0) + result.secondary.length;
107
+ expect(totalPatterns).toBeGreaterThanOrEqual(1);
108
+ });
109
+
110
+ it("should return empty analysis for unknown patterns", () => {
111
+ const symbols = [
112
+ { id: "src/utils/helper.ts#helper", name: "helper", type: "function", file: "src/utils/helper.ts" },
113
+ ];
114
+
115
+ const graph = { edges: [] };
116
+
117
+ const result = architectureDetector.detect(symbols, graph);
118
+
119
+ expect(result.primary).toBeNull();
120
+ expect(result.layers.length).toBe(0);
121
+ });
122
+
123
+ it("should detect API layer components", () => {
124
+ const symbols = [
125
+ { id: "src/routes/user.ts#userRoutes", name: "userRoutes", type: "const", file: "src/routes/user.ts" },
126
+ { id: "src/handlers/auth.ts#authHandler", name: "authHandler", type: "function", file: "src/handlers/auth.ts" },
127
+ ];
128
+
129
+ const graph = { edges: [] };
130
+
131
+ const result = architectureDetector.detect(symbols, graph);
132
+
133
+ const apiLayer = result.layers.find(l => l.name.includes("API"));
134
+ expect(apiLayer).toBeDefined();
135
+ expect(apiLayer?.symbols.length).toBeGreaterThanOrEqual(1);
136
+ });
137
+ });