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
@@ -0,0 +1,335 @@
1
+ import { ArchitectureAnalysis } from "../analysis/architectureDetector.js";
2
+
3
+ export interface EnrichedContext {
4
+ project: {
5
+ name: string;
6
+ type: string;
7
+ description: string;
8
+ };
9
+ architecture: {
10
+ pattern: string;
11
+ confidence: number;
12
+ layers: Array<{
13
+ name: string;
14
+ components: string[];
15
+ responsibility: string;
16
+ }>;
17
+ };
18
+ techStack: {
19
+ languages: string[];
20
+ frameworks: string[];
21
+ libraries: string[];
22
+ };
23
+ entryPoints: Array<{
24
+ name: string;
25
+ file: string;
26
+ description: string;
27
+ }>;
28
+ flows: Array<{
29
+ name: string;
30
+ description: string;
31
+ files: string[];
32
+ dependencies: string[];
33
+ }>;
34
+ metrics: {
35
+ totalFiles: number;
36
+ totalSymbols: number;
37
+ totalDependencies: number;
38
+ averageComplexity: number;
39
+ };
40
+ }
41
+
42
+ export class AIContextGenerator {
43
+ generate(analysis: {
44
+ architecture: ArchitectureAnalysis;
45
+ symbols: Array<{
46
+ id: string;
47
+ name: string;
48
+ type: string;
49
+ file: string;
50
+ }>;
51
+ dependencies: {
52
+ totalDependencies: number;
53
+ dependencies: Array<{
54
+ source: string;
55
+ target: string;
56
+ type: string;
57
+ }>;
58
+ };
59
+ projectName: string;
60
+ }): string {
61
+ const enriched = this.enrichAnalysis(analysis);
62
+ return this.renderMarkdown(enriched);
63
+ }
64
+
65
+ private enrichAnalysis(analysis: {
66
+ architecture: ArchitectureAnalysis;
67
+ symbols: Array<{
68
+ id: string;
69
+ name: string;
70
+ type: string;
71
+ file: string;
72
+ }>;
73
+ dependencies: {
74
+ totalDependencies: number;
75
+ dependencies: Array<{
76
+ source: string;
77
+ target: string;
78
+ type: string;
79
+ }>;
80
+ };
81
+ projectName: string;
82
+ }): EnrichedContext {
83
+ const uniqueFiles = [...new Set(analysis.symbols.map((s) => s.file))];
84
+ const uniqueTypes = [...new Set(analysis.symbols.map((s) => s.type))];
85
+
86
+ return {
87
+ project: {
88
+ name: analysis.projectName,
89
+ type: this.detectProjectType(analysis),
90
+ description: this.generateDescription(analysis),
91
+ },
92
+ architecture: {
93
+ pattern: analysis.architecture.primary?.name || "Unknown",
94
+ confidence: analysis.architecture.primary?.confidence || 0,
95
+ layers: analysis.architecture.layers.map((layer) => ({
96
+ name: layer.name,
97
+ components: layer.symbols.slice(0, 10),
98
+ responsibility: layer.responsibility,
99
+ })),
100
+ },
101
+ techStack: {
102
+ languages: this.extractLanguages(uniqueFiles),
103
+ frameworks: this.detectFrameworks(analysis),
104
+ libraries: this.detectLibraries(analysis),
105
+ },
106
+ entryPoints: analysis.architecture.entryPoints.slice(0, 5).map((ep) => ({
107
+ name: ep.split("#")[1] || ep,
108
+ file: ep.split("#")[0] || ep,
109
+ description: this.describeEntryPoint(ep),
110
+ })),
111
+ flows: this.extractFlows(analysis),
112
+ metrics: {
113
+ totalFiles: uniqueFiles.length,
114
+ totalSymbols: analysis.symbols.length,
115
+ totalDependencies: analysis.dependencies.totalDependencies,
116
+ averageComplexity: this.calculateComplexity(analysis),
117
+ },
118
+ };
119
+ }
120
+
121
+ private renderMarkdown(context: EnrichedContext): string {
122
+ return `# AI Context: ${context.project.name}
123
+
124
+ ## Project Overview
125
+
126
+ **Type**: ${context.project.type}
127
+ **Description**: ${context.project.description}
128
+
129
+ ## Architecture
130
+
131
+ ### Pattern: ${context.architecture.pattern}
132
+ **Confidence**: ${(context.architecture.confidence * 100).toFixed(0)}%
133
+
134
+ ### Layers
135
+
136
+ ${context.architecture.layers
137
+ .map(
138
+ (layer) => `#### ${layer.name}
139
+ **Responsibility**: ${layer.responsibility}
140
+
141
+ **Key Components**:
142
+ ${layer.components.map((c) => `- \`${c}\``).join("\n")}
143
+ `
144
+ )
145
+ .join("\n")}
146
+
147
+ ## Tech Stack
148
+
149
+ ### Languages
150
+ ${context.techStack.languages.map((l) => `- ${l}`).join("\n")}
151
+
152
+ ### Frameworks
153
+ ${context.techStack.frameworks.map((f) => `- ${f}`).join("\n")}
154
+
155
+ ### Key Libraries
156
+ ${context.techStack.libraries.slice(0, 10).map((l) => `- ${l}`).join("\n")}
157
+
158
+ ## Entry Points
159
+
160
+ ${context.entryPoints
161
+ .map(
162
+ (ep) => `### ${ep.name}
163
+ - **File**: \`${ep.file}\`
164
+ - **Description**: ${ep.description}
165
+ `
166
+ )
167
+ .join("\n")}
168
+
169
+ ## Business Flows
170
+
171
+ ${context.flows
172
+ .map(
173
+ (flow) => `### ${flow.name}
174
+ ${flow.description}
175
+
176
+ **Files involved**:
177
+ ${flow.files.map((f) => `- \`${f}\``).join("\n")}
178
+
179
+ **Dependencies**:
180
+ ${flow.dependencies.slice(0, 5).map((d) => `- ${d}`).join("\n")}
181
+ `
182
+ )
183
+ .join("\n")}
184
+
185
+ ## Metrics
186
+
187
+ | Metric | Value |
188
+ |--------|-------|
189
+ | Total Files | ${context.metrics.totalFiles} |
190
+ | Total Symbols | ${context.metrics.totalSymbols} |
191
+ | Total Dependencies | ${context.metrics.totalDependencies} |
192
+ | Average Complexity | ${context.metrics.averageComplexity.toFixed(2)} |
193
+
194
+ ## Getting Started for AI
195
+
196
+ 1. **Read architecture.md** for detailed structure
197
+ 2. **Check context/flows/** for business logic understanding
198
+ 3. **See symbols.json** for complete API reference
199
+ 4. **Review dependencies.json** for module relationships
200
+
201
+ ---
202
+ *Generated by ai-first-cli v2.0 with semantic analysis*
203
+ `;
204
+ }
205
+
206
+ private detectProjectType(analysis: {
207
+ symbols: Array<{ type: string; file: string }>;
208
+ }): string {
209
+ const hasControllers = analysis.symbols.some(
210
+ (s) => s.type === "class" && s.file.includes("controller")
211
+ );
212
+ const hasComponents = analysis.symbols.some(
213
+ (s) => s.type === "class" && s.file.includes("component")
214
+ );
215
+ const hasRoutes = analysis.symbols.some((s) => s.file.includes("route"));
216
+
217
+ if (hasComponents) return "Frontend Application (React/Vue/Angular)";
218
+ if (hasControllers && hasRoutes) return "REST API / Web Service";
219
+ if (hasControllers) return "MVC Web Application";
220
+ return "Generic Application";
221
+ }
222
+
223
+ private generateDescription(analysis: {
224
+ architecture: ArchitectureAnalysis;
225
+ symbols: Array<{ type: string }>;
226
+ }): string {
227
+ const patterns = analysis.architecture.primary
228
+ ? [analysis.architecture.primary.name]
229
+ : [];
230
+ patterns.push(...analysis.architecture.secondary.map((s) => s.name));
231
+
232
+ const classes = analysis.symbols.filter((s) => s.type === "class").length;
233
+ const functions = analysis.symbols.filter((s) => s.type === "function").length;
234
+
235
+ return `A ${patterns.join(" / ")} application with ${classes} classes and ${functions} functions organized in ${analysis.architecture.layers.length} architectural layers.`;
236
+ }
237
+
238
+ private extractLanguages(files: string[]): string[] {
239
+ const extensions = files.map((f) => f.split(".").pop() || "");
240
+ const langMap: Record<string, string> = {
241
+ ts: "TypeScript",
242
+ tsx: "TypeScript (React)",
243
+ js: "JavaScript",
244
+ jsx: "JavaScript (React)",
245
+ py: "Python",
246
+ java: "Java",
247
+ go: "Go",
248
+ rs: "Rust",
249
+ php: "PHP",
250
+ rb: "Ruby",
251
+ };
252
+
253
+ return [...new Set(extensions.map((e) => langMap[e] || e).filter(Boolean))];
254
+ }
255
+
256
+ private detectFrameworks(analysis: {
257
+ symbols: Array<{ name: string; file: string }>;
258
+ }): string[] {
259
+ const frameworks: string[] = [];
260
+ const check = (pattern: string, name: string) => {
261
+ if (
262
+ analysis.symbols.some(
263
+ (s) => s.name.includes(pattern) || s.file.includes(pattern.toLowerCase())
264
+ )
265
+ ) {
266
+ frameworks.push(name);
267
+ }
268
+ };
269
+
270
+ check("Controller", "NestJS / Express");
271
+ check("Component", "React / Vue / Angular");
272
+ check("Service", "Angular / NestJS");
273
+ check("Model", "Django / Rails / Laravel");
274
+ check("View", "Django / Rails");
275
+ check("Route", "Express / Fastify");
276
+
277
+ return [...new Set(frameworks)];
278
+ }
279
+
280
+ private detectLibraries(analysis: {
281
+ dependencies: { dependencies: Array<{ target: string }> };
282
+ }): string[] {
283
+ const imports = analysis.dependencies.dependencies.map((d) => d.target);
284
+ return [...new Set(imports)].slice(0, 20);
285
+ }
286
+
287
+ private describeEntryPoint(entryPoint: string): string {
288
+ const name = entryPoint.split("#")[1] || entryPoint;
289
+ const file = entryPoint.split("#")[0] || entryPoint;
290
+
291
+ if (name.toLowerCase().includes("main")) return "Application entry point";
292
+ if (name.toLowerCase().includes("server")) return "Server bootstrap";
293
+ if (name.toLowerCase().includes("app")) return "Main application setup";
294
+ if (file.includes("controller")) return "API endpoint handler";
295
+ if (file.includes("route")) return "Route definition";
296
+ return "Entry point";
297
+ }
298
+
299
+ private extractFlows(analysis: {
300
+ architecture: ArchitectureAnalysis;
301
+ symbols: Array<{ id: string; name: string; file: string; type: string }>;
302
+ }): EnrichedContext["flows"] {
303
+ const flows: EnrichedContext["flows"] = [];
304
+
305
+ const entryPoints = analysis.architecture.entryPoints;
306
+ for (const ep of entryPoints.slice(0, 5)) {
307
+ const epName = ep.split("#")[1] || ep;
308
+ const epFile = ep.split("#")[0] || ep;
309
+
310
+ const relatedFiles = analysis.symbols
311
+ .filter((s) => s.file.includes(epName.toLowerCase().replace(/controller|handler/g, "")))
312
+ .map((s) => s.file);
313
+
314
+ flows.push({
315
+ name: epName,
316
+ description: `Business flow starting at ${epName}`,
317
+ files: [...new Set([epFile, ...relatedFiles])].slice(0, 5),
318
+ dependencies: [],
319
+ });
320
+ }
321
+
322
+ return flows;
323
+ }
324
+
325
+ private calculateComplexity(analysis: {
326
+ symbols: Array<{ type: string }>;
327
+ dependencies: { dependencies: Array<unknown> };
328
+ }): number {
329
+ const symbolCount = analysis.symbols.length;
330
+ const depCount = analysis.dependencies.dependencies.length;
331
+ return symbolCount > 0 ? depCount / symbolCount : 0;
332
+ }
333
+ }
334
+
335
+ export const aiContextGenerator = new AIContextGenerator();
@@ -0,0 +1,200 @@
1
+ import { ArchitectureAnalysis } from "../analysis/architectureDetector.js";
2
+
3
+ export class ArchitectureGenerator {
4
+ generate(
5
+ analysis: ArchitectureAnalysis,
6
+ dependencyGraph: {
7
+ nodes: string[];
8
+ edges: Array<{ from: string; to: string; type: string }>;
9
+ }
10
+ ): string {
11
+ return `# Architecture
12
+
13
+ ## Pattern: ${analysis.primary?.name || "Unknown"}
14
+
15
+ **Confidence**: ${((analysis.primary?.confidence || 0) * 100).toFixed(0)}%
16
+
17
+ ### Evidence
18
+ ${analysis.primary?.evidence.map((e) => `- ${e}`).join("\n") || "- No strong pattern detected"}
19
+
20
+ ${analysis.secondary.length > 0 ? `
21
+ ### Secondary Patterns
22
+ ${analysis.secondary.map((p) => `- **${p.name}** (${(p.confidence * 100).toFixed(0)}%)`).join("\n")}
23
+ ` : ""}
24
+
25
+ ## Architecture Diagram
26
+
27
+ \`\`\`
28
+ ${this.generateAsciiDiagram(analysis)}
29
+ \`\`\`
30
+
31
+ ## Layer Overview
32
+
33
+ | Layer | Components | Responsibility |
34
+ |-------|------------|----------------|
35
+ ${analysis.layers.map((layer) => `| ${layer.name} | ${layer.symbols.length} | ${layer.responsibility} |`).join("\n")}
36
+
37
+ ## Mermaid Diagram
38
+
39
+ \`\`\`mermaid
40
+ ${this.generateMermaidDiagram(analysis, dependencyGraph)}
41
+ \`\`\`
42
+
43
+ ## Entry Points
44
+
45
+ ${analysis.entryPoints.slice(0, 10).map((ep) => `- \`${ep}\``).join("\n")}
46
+
47
+ ## Module Dependencies
48
+
49
+ \`\`\`mermaid
50
+ graph TD
51
+ ${this.generateDependencyGraph(dependencyGraph)}
52
+ \`\`\`
53
+
54
+ ## Recommendations
55
+
56
+ ${this.generateRecommendations(analysis)}
57
+
58
+ ---
59
+ *Generated by ai-first-cli v2.0*
60
+ `;
61
+ }
62
+
63
+ private generateAsciiDiagram(analysis: ArchitectureAnalysis): string {
64
+ const layers = analysis.layers;
65
+ if (layers.length === 0) return "No layers detected";
66
+
67
+ let diagram = "";
68
+ const maxWidth = 50;
69
+
70
+ for (let i = 0; i < layers.length; i++) {
71
+ const layer = layers[i];
72
+ const title = ` ${layer.name} `;
73
+ const padding = Math.max(0, (maxWidth - title.length) / 2);
74
+ const leftPad = "─".repeat(Math.floor(padding));
75
+ const rightPad = "─".repeat(Math.ceil(padding));
76
+
77
+ diagram += `┌${leftPad}${title}${rightPad}┐\n`;
78
+
79
+ const components = layer.symbols.slice(0, 3);
80
+ for (const component of components) {
81
+ const name = component.split("#")[1] || component;
82
+ const line = `│ • ${name.padEnd(maxWidth - 4)}│`;
83
+ diagram += `${line}\n`;
84
+ }
85
+
86
+ if (layer.symbols.length > 3) {
87
+ diagram += `│ ... and ${layer.symbols.length - 3} more${"".padEnd(maxWidth - 15)}│\n`;
88
+ }
89
+
90
+ diagram += `└${"─".repeat(maxWidth)}┘\n`;
91
+
92
+ if (i < layers.length - 1) {
93
+ diagram += `${" ".repeat(maxWidth / 2)}↓\n`;
94
+ }
95
+ }
96
+
97
+ return diagram;
98
+ }
99
+
100
+ private generateMermaidDiagram(
101
+ analysis: ArchitectureAnalysis,
102
+ dependencyGraph: {
103
+ nodes: string[];
104
+ edges: Array<{ from: string; to: string; type: string }>;
105
+ }
106
+ ): string {
107
+ const lines: string[] = [];
108
+ lines.push("graph TD");
109
+
110
+ const subgraphs = new Map<string, string[]>();
111
+
112
+ for (const layer of analysis.layers) {
113
+ const nodeIds: string[] = [];
114
+ for (const symbol of layer.symbols.slice(0, 5)) {
115
+ const id = symbol.replace(/[^a-zA-Z0-9]/g, "_");
116
+ const name = symbol.split("#")[1] || symbol;
117
+ nodeIds.push(id);
118
+ lines.push(` ${id}[${name}]`);
119
+ }
120
+ subgraphs.set(layer.name, nodeIds);
121
+ }
122
+
123
+ for (const [layerName, nodeIds] of subgraphs) {
124
+ if (nodeIds.length > 0) {
125
+ lines.push(` subgraph ${layerName}`);
126
+ for (const id of nodeIds) {
127
+ lines.push(` ${id}`);
128
+ }
129
+ lines.push(` end`);
130
+ }
131
+ }
132
+
133
+ const addedEdges = new Set<string>();
134
+ for (const edge of dependencyGraph.edges.slice(0, 10)) {
135
+ const from = edge.from.replace(/[^a-zA-Z0-9]/g, "_");
136
+ const to = edge.to.replace(/[^a-zA-Z0-9]/g, "_");
137
+ const edgeKey = `${from}-->${to}`;
138
+ if (!addedEdges.has(edgeKey)) {
139
+ lines.push(` ${from}-->${to}`);
140
+ addedEdges.add(edgeKey);
141
+ }
142
+ }
143
+
144
+ return lines.join("\n");
145
+ }
146
+
147
+ private generateDependencyGraph(dependencyGraph: {
148
+ nodes: string[];
149
+ edges: Array<{ from: string; to: string; type: string }>;
150
+ }): string {
151
+ const lines: string[] = [];
152
+ const added = new Set<string>();
153
+
154
+ for (const edge of dependencyGraph.edges.slice(0, 15)) {
155
+ const from = edge.from.replace(/[^a-zA-Z0-9]/g, "_");
156
+ const to = edge.to.replace(/[^a-zA-Z0-9]/g, "_");
157
+ const key = `${from}-->${to}`;
158
+
159
+ if (!added.has(key)) {
160
+ const label = edge.type === "import" ? "" : `|${edge.type}|`;
161
+ lines.push(` ${from}[${edge.from}] -->${label} ${to}[${edge.to}]`);
162
+ added.add(key);
163
+ }
164
+ }
165
+
166
+ return lines.join("\n");
167
+ }
168
+
169
+ private generateRecommendations(analysis: ArchitectureAnalysis): string {
170
+ const recommendations: string[] = [];
171
+
172
+ if (!analysis.primary) {
173
+ recommendations.push("- Consider adopting a well-defined architectural pattern");
174
+ }
175
+
176
+ if (analysis.layers.length === 0) {
177
+ recommendations.push("- No clear layer separation detected. Consider organizing code into layers");
178
+ } else if (analysis.layers.length < 3) {
179
+ recommendations.push("- Consider adding more separation of concerns (currently only " + analysis.layers.length + " layers)");
180
+ }
181
+
182
+ if (analysis.entryPoints.length === 0) {
183
+ recommendations.push("- No clear entry points found. Define main functions or controllers");
184
+ } else if (analysis.entryPoints.length > 10) {
185
+ recommendations.push("- Many entry points detected. Consider consolidating");
186
+ }
187
+
188
+ if (analysis.secondary.length > 2) {
189
+ recommendations.push("- Multiple patterns detected. Consider simplifying architecture");
190
+ }
191
+
192
+ if (recommendations.length === 0) {
193
+ return "- Architecture looks well-structured. Keep the consistency as the project grows.";
194
+ }
195
+
196
+ return recommendations.join("\n");
197
+ }
198
+ }
199
+
200
+ export const architectureGenerator = new ArchitectureGenerator();