ai-first-cli 1.2.3 → 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.
- package/CHANGELOG.md +292 -6
- package/README.md +24 -4
- package/dist/analyzers/symbols.d.ts.map +1 -1
- package/dist/analyzers/symbols.js +9 -7
- package/dist/analyzers/symbols.js.map +1 -1
- package/dist/analyzers/techStack.d.ts.map +1 -1
- package/dist/analyzers/techStack.js +198 -3
- package/dist/analyzers/techStack.js.map +1 -1
- package/dist/commands/ai-first.d.ts.map +1 -1
- package/dist/commands/ai-first.js +14 -13
- package/dist/commands/ai-first.js.map +1 -1
- package/dist/core/analysis/architectureDetector.d.ts +37 -0
- package/dist/core/analysis/architectureDetector.d.ts.map +1 -0
- package/dist/core/analysis/architectureDetector.js +316 -0
- package/dist/core/analysis/architectureDetector.js.map +1 -0
- package/dist/core/analysis/callGraphBuilder.d.ts +37 -0
- package/dist/core/analysis/callGraphBuilder.d.ts.map +1 -0
- package/dist/core/analysis/callGraphBuilder.js +101 -0
- package/dist/core/analysis/callGraphBuilder.js.map +1 -0
- package/dist/core/analysis/dependencyAnalyzer.d.ts +45 -0
- package/dist/core/analysis/dependencyAnalyzer.d.ts.map +1 -0
- package/dist/core/analysis/dependencyAnalyzer.js +98 -0
- package/dist/core/analysis/dependencyAnalyzer.js.map +1 -0
- package/dist/core/analysis/index.d.ts +5 -0
- package/dist/core/analysis/index.d.ts.map +1 -0
- package/dist/core/analysis/index.js +5 -0
- package/dist/core/analysis/index.js.map +1 -0
- package/dist/core/analysis/inheritanceAnalyzer.d.ts +35 -0
- package/dist/core/analysis/inheritanceAnalyzer.d.ts.map +1 -0
- package/dist/core/analysis/inheritanceAnalyzer.js +115 -0
- package/dist/core/analysis/inheritanceAnalyzer.js.map +1 -0
- package/dist/core/ccp.d.ts.map +1 -1
- package/dist/core/ccp.js +3 -2
- package/dist/core/ccp.js.map +1 -1
- package/dist/core/generation/aiContextGenerator.d.ts +71 -0
- package/dist/core/generation/aiContextGenerator.d.ts.map +1 -0
- package/dist/core/generation/aiContextGenerator.js +217 -0
- package/dist/core/generation/aiContextGenerator.js.map +1 -0
- package/dist/core/generation/architectureGenerator.d.ts +17 -0
- package/dist/core/generation/architectureGenerator.d.ts.map +1 -0
- package/dist/core/generation/architectureGenerator.js +160 -0
- package/dist/core/generation/architectureGenerator.js.map +1 -0
- package/dist/core/generation/flowGenerator.d.ts +52 -0
- package/dist/core/generation/flowGenerator.d.ts.map +1 -0
- package/dist/core/generation/flowGenerator.js +164 -0
- package/dist/core/generation/flowGenerator.js.map +1 -0
- package/dist/core/generation/index.d.ts +4 -0
- package/dist/core/generation/index.d.ts.map +1 -0
- package/dist/core/generation/index.js +4 -0
- package/dist/core/generation/index.js.map +1 -0
- package/dist/core/hierarchyGenerator.d.ts.map +1 -1
- package/dist/core/hierarchyGenerator.js +3 -2
- package/dist/core/hierarchyGenerator.js.map +1 -1
- package/dist/core/parsers/index.d.ts +20 -0
- package/dist/core/parsers/index.d.ts.map +1 -0
- package/dist/core/parsers/index.js +76 -0
- package/dist/core/parsers/index.js.map +1 -0
- package/dist/core/parsers/pythonParser.d.ts +37 -0
- package/dist/core/parsers/pythonParser.d.ts.map +1 -0
- package/dist/core/parsers/pythonParser.js +229 -0
- package/dist/core/parsers/pythonParser.js.map +1 -0
- package/dist/core/parsers/typescriptParser.d.ts +54 -0
- package/dist/core/parsers/typescriptParser.d.ts.map +1 -0
- package/dist/core/parsers/typescriptParser.js +291 -0
- package/dist/core/parsers/typescriptParser.js.map +1 -0
- package/dist/core/pipeline.d.ts +42 -0
- package/dist/core/pipeline.d.ts.map +1 -0
- package/dist/core/pipeline.js +172 -0
- package/dist/core/pipeline.js.map +1 -0
- package/dist/core/semanticContexts.js +1 -1
- package/dist/core/semanticContexts.js.map +1 -1
- package/dist/utils/constants.d.ts +46 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +67 -0
- package/dist/utils/constants.js.map +1 -0
- package/package.json +1 -1
- package/run-all-tests.sh +184 -0
- package/src/analyzers/symbols.ts +12 -7
- package/src/analyzers/techStack.ts +203 -3
- package/src/commands/ai-first.ts +14 -13
- package/src/core/analysis/architectureDetector.ts +487 -0
- package/src/core/analysis/callGraphBuilder.ts +158 -0
- package/src/core/analysis/dependencyAnalyzer.ts +167 -0
- package/src/core/analysis/index.ts +28 -0
- package/src/core/analysis/inheritanceAnalyzer.ts +169 -0
- package/src/core/ccp.ts +3 -2
- package/src/core/generation/aiContextGenerator.ts +335 -0
- package/src/core/generation/architectureGenerator.ts +200 -0
- package/src/core/generation/flowGenerator.ts +238 -0
- package/src/core/generation/index.ts +16 -0
- package/src/core/hierarchyGenerator.ts +3 -2
- package/src/core/parsers/index.ts +99 -0
- package/src/core/parsers/pythonParser.ts +302 -0
- package/src/core/parsers/typescriptParser.ts +445 -0
- package/src/core/pipeline.ts +241 -0
- package/src/core/semanticContexts.ts +1 -1
- package/src/utils/constants.ts +78 -0
- package/tests/analysis.test.ts +283 -0
- package/tests/architectureDetector.test.ts +137 -0
- package/tests/generation.test.ts +216 -0
- package/tests/parserRegistry.test.ts +139 -0
- package/tests/pipeline.integration.test.ts +245 -0
- package/tests/pythonParser.test.ts +210 -0
- package/tests/typescriptParser.test.ts +197 -0
- package/.ai-dev/index.db +0 -0
- package/ANALISIS_COMPLETO.md +0 -424
- package/ANALISIS_MEJORAS.md +0 -327
- package/BUGS.md +0 -455
- package/PLAN_MEJORAS.md +0 -216
- package/STATUS_ADAPTADORES +0 -126
- package/TEST_RESULTS.md +0 -198
- package/TEST_RESULTS_COMPARATIVE.md +0 -159
- package/TEST_RESULTS_COMPLETE.md +0 -127
- package/TEST_RESULTS_COMPREHENSIVE.md +0 -208
- package/TEST_RESULTS_PHASE1.md +0 -420
- package/ai/dependencies.json +0 -15
- package/ai/graph/knowledge-graph.json +0 -12
- package/ai-context/ai_context.md +0 -130
- package/ai-context/ai_rules.md +0 -54
- package/ai-context/architecture.md +0 -136
- package/ai-context/cache.json +0 -2349
- package/ai-context/ccp/jira-123/context.json +0 -7
- package/ai-context/context/features/commands.json +0 -18
- package/ai-context/context/features/src.json +0 -61
- package/ai-context/context/features/test-projects.json +0 -69
- package/ai-context/context/flows/account.json +0 -9
- package/ai-context/context/flows/ai-first.json +0 -9
- package/ai-context/context/flows/api.json +0 -9
- package/ai-context/context/flows/auth.json +0 -13
- package/ai-context/context/flows/category.json +0 -12
- package/ai-context/context/flows/comment.json +0 -16
- package/ai-context/context/flows/dashboard.json +0 -9
- package/ai-context/context/flows/doctor.json +0 -9
- package/ai-context/context/flows/explore.json +0 -9
- package/ai-context/context/flows/login.json +0 -9
- package/ai-context/context/flows/opportunity.json +0 -9
- package/ai-context/context/flows/post.json +0 -18
- package/ai-context/context/flows/routes.json +0 -19
- package/ai-context/context/flows/user.json +0 -20
- package/ai-context/context/flows/users.json +0 -9
- package/ai-context/context/flows/views.json +0 -14
- package/ai-context/context/repo.json +0 -56
- package/ai-context/context/utils.json +0 -7
- package/ai-context/conventions.md +0 -53
- package/ai-context/dependencies.json +0 -2978
- package/ai-context/embeddings.json +0 -23828
- package/ai-context/entrypoints.md +0 -42
- package/ai-context/files.json +0 -2944
- package/ai-context/git/commit-activity.json +0 -8646
- package/ai-context/git/recent-features.json +0 -1
- package/ai-context/git/recent-files.json +0 -52
- package/ai-context/git/recent-flows.json +0 -1
- package/ai-context/graph/knowledge-graph.json +0 -44129
- package/ai-context/graph/module-graph.json +0 -866
- package/ai-context/graph/symbol-graph.json +0 -200622
- package/ai-context/graph/symbol-references.json +0 -6778
- package/ai-context/hierarchy.json +0 -20
- package/ai-context/index-state.json +0 -4487
- package/ai-context/index.db +0 -0
- package/ai-context/modules.json +0 -933
- package/ai-context/project.json +0 -30
- package/ai-context/repo_map.json +0 -9116
- package/ai-context/repo_map.md +0 -2061
- package/ai-context/schema.json +0 -5
- package/ai-context/summary.md +0 -47
- package/ai-context/symbols.json +0 -65351
- package/ai-context/tech_stack.md +0 -47
- package/ai-context/tools.json +0 -10
- package/test-projects/django-app/.ai-dev/index.db +0 -0
- package/test-projects/django-app/ai-context/ai_context.md +0 -92
- package/test-projects/django-app/ai-context/ai_rules.md +0 -47
- package/test-projects/django-app/ai-context/architecture.md +0 -57
- package/test-projects/django-app/ai-context/cache.json +0 -169
- package/test-projects/django-app/ai-context/context/flows/views.json +0 -10
- package/test-projects/django-app/ai-context/conventions.md +0 -51
- package/test-projects/django-app/ai-context/dependencies.json +0 -312
- package/test-projects/django-app/ai-context/entrypoints.md +0 -4
- package/test-projects/django-app/ai-context/files.json +0 -209
- package/test-projects/django-app/ai-context/graph/knowledge-graph.json +0 -36
- package/test-projects/django-app/ai-context/graph/module-graph.json +0 -145
- package/test-projects/django-app/ai-context/graph/symbol-graph.json +0 -1488
- package/test-projects/django-app/ai-context/graph/symbol-references.json +0 -1
- package/test-projects/django-app/ai-context/index-state.json +0 -294
- package/test-projects/django-app/ai-context/index.db +0 -0
- package/test-projects/django-app/ai-context/modules.json +0 -35
- package/test-projects/django-app/ai-context/project.json +0 -11
- package/test-projects/django-app/ai-context/repo_map.json +0 -412
- package/test-projects/django-app/ai-context/repo_map.md +0 -105
- package/test-projects/django-app/ai-context/schema.json +0 -5
- package/test-projects/django-app/ai-context/summary.md +0 -15
- package/test-projects/django-app/ai-context/symbols.json +0 -1
- package/test-projects/django-app/ai-context/tech_stack.md +0 -32
- package/test-projects/django-app/ai-context/tools.json +0 -10
- package/test-projects/express-api/ai-context/ai_context.md +0 -112
- package/test-projects/express-api/ai-context/ai_rules.md +0 -50
- package/test-projects/express-api/ai-context/architecture.md +0 -62
- package/test-projects/express-api/ai-context/context/features/controllers.json +0 -13
- package/test-projects/express-api/ai-context/context/features/services.json +0 -13
- package/test-projects/express-api/ai-context/context/flows/auth.json +0 -12
- package/test-projects/express-api/ai-context/context/flows/user.json +0 -13
- package/test-projects/express-api/ai-context/conventions.md +0 -51
- package/test-projects/express-api/ai-context/dependencies.json +0 -54
- package/test-projects/express-api/ai-context/entrypoints.md +0 -17
- package/test-projects/express-api/ai-context/modules.json +0 -30
- package/test-projects/express-api/ai-context/project.json +0 -15
- package/test-projects/express-api/ai-context/repo_map.json +0 -100
- package/test-projects/express-api/ai-context/repo_map.md +0 -36
- package/test-projects/express-api/ai-context/schema.json +0 -5
- package/test-projects/express-api/ai-context/summary.md +0 -14
- package/test-projects/express-api/ai-context/symbols.json +0 -7
- package/test-projects/express-api/ai-context/tech_stack.md +0 -38
- package/test-projects/express-api/ai-context/tools.json +0 -10
- package/test-projects/fastapi-app/.ai-dev/index.db +0 -0
- package/test-projects/fastapi-app/ai-context/ai_context.md +0 -89
- package/test-projects/fastapi-app/ai-context/ai_rules.md +0 -47
- package/test-projects/fastapi-app/ai-context/architecture.md +0 -39
- package/test-projects/fastapi-app/ai-context/cache.json +0 -125
- package/test-projects/fastapi-app/ai-context/conventions.md +0 -51
- package/test-projects/fastapi-app/ai-context/dependencies.json +0 -244
- package/test-projects/fastapi-app/ai-context/entrypoints.md +0 -4
- package/test-projects/fastapi-app/ai-context/files.json +0 -154
- package/test-projects/fastapi-app/ai-context/graph/knowledge-graph.json +0 -15
- package/test-projects/fastapi-app/ai-context/graph/module-graph.json +0 -78
- package/test-projects/fastapi-app/ai-context/graph/symbol-graph.json +0 -1724
- package/test-projects/fastapi-app/ai-context/graph/symbol-references.json +0 -51
- package/test-projects/fastapi-app/ai-context/index-state.json +0 -217
- package/test-projects/fastapi-app/ai-context/index.db +0 -0
- package/test-projects/fastapi-app/ai-context/modules.json +0 -16
- package/test-projects/fastapi-app/ai-context/project.json +0 -9
- package/test-projects/fastapi-app/ai-context/repo_map.json +0 -298
- package/test-projects/fastapi-app/ai-context/repo_map.md +0 -74
- package/test-projects/fastapi-app/ai-context/schema.json +0 -5
- package/test-projects/fastapi-app/ai-context/summary.md +0 -12
- package/test-projects/fastapi-app/ai-context/symbols.json +0 -1
- package/test-projects/fastapi-app/ai-context/tech_stack.md +0 -32
- package/test-projects/fastapi-app/ai-context/tools.json +0 -10
- package/test-projects/flask-app/.ai-dev/index.db +0 -0
- package/test-projects/flask-app/ai-context/ai_context.md +0 -94
- package/test-projects/flask-app/ai-context/ai_rules.md +0 -47
- package/test-projects/flask-app/ai-context/architecture.md +0 -49
- package/test-projects/flask-app/ai-context/cache.json +0 -157
- package/test-projects/flask-app/ai-context/context/features/app.json +0 -25
- package/test-projects/flask-app/ai-context/context/flows/routes.json +0 -14
- package/test-projects/flask-app/ai-context/conventions.md +0 -51
- package/test-projects/flask-app/ai-context/dependencies.json +0 -298
- package/test-projects/flask-app/ai-context/entrypoints.md +0 -4
- package/test-projects/flask-app/ai-context/files.json +0 -194
- package/test-projects/flask-app/ai-context/graph/knowledge-graph.json +0 -60
- package/test-projects/flask-app/ai-context/graph/module-graph.json +0 -95
- package/test-projects/flask-app/ai-context/graph/symbol-graph.json +0 -1448
- package/test-projects/flask-app/ai-context/graph/symbol-references.json +0 -45
- package/test-projects/flask-app/ai-context/index-state.json +0 -273
- package/test-projects/flask-app/ai-context/index.db +0 -0
- package/test-projects/flask-app/ai-context/modules.json +0 -21
- package/test-projects/flask-app/ai-context/project.json +0 -13
- package/test-projects/flask-app/ai-context/repo_map.json +0 -400
- package/test-projects/flask-app/ai-context/repo_map.md +0 -98
- package/test-projects/flask-app/ai-context/schema.json +0 -5
- package/test-projects/flask-app/ai-context/summary.md +0 -13
- package/test-projects/flask-app/ai-context/symbols.json +0 -1
- package/test-projects/flask-app/ai-context/tech_stack.md +0 -32
- package/test-projects/flask-app/ai-context/tools.json +0 -10
- package/test-projects/laravel-app/.ai-dev/index.db +0 -0
- package/test-projects/laravel-app/ai-context/ai_context.md +0 -97
- package/test-projects/laravel-app/ai-context/ai_rules.md +0 -47
- package/test-projects/laravel-app/ai-context/architecture.md +0 -60
- package/test-projects/laravel-app/ai-context/cache.json +0 -161
- package/test-projects/laravel-app/ai-context/context/features/app.json +0 -21
- package/test-projects/laravel-app/ai-context/context/flows/.json +0 -9
- package/test-projects/laravel-app/ai-context/context/flows/category.json +0 -12
- package/test-projects/laravel-app/ai-context/context/flows/comment.json +0 -12
- package/test-projects/laravel-app/ai-context/context/flows/post.json +0 -12
- package/test-projects/laravel-app/ai-context/context/flows/unnamed.json +0 -9
- package/test-projects/laravel-app/ai-context/conventions.md +0 -51
- package/test-projects/laravel-app/ai-context/dependencies.json +0 -6
- package/test-projects/laravel-app/ai-context/entrypoints.md +0 -4
- package/test-projects/laravel-app/ai-context/files.json +0 -199
- package/test-projects/laravel-app/ai-context/graph/knowledge-graph.json +0 -98
- package/test-projects/laravel-app/ai-context/graph/module-graph.json +0 -30
- package/test-projects/laravel-app/ai-context/graph/symbol-graph.json +0 -5
- package/test-projects/laravel-app/ai-context/graph/symbol-references.json +0 -1
- package/test-projects/laravel-app/ai-context/index-state.json +0 -280
- package/test-projects/laravel-app/ai-context/index.db +0 -0
- package/test-projects/laravel-app/ai-context/modules.json +0 -29
- package/test-projects/laravel-app/ai-context/project.json +0 -17
- package/test-projects/laravel-app/ai-context/repo_map.json +0 -419
- package/test-projects/laravel-app/ai-context/repo_map.md +0 -106
- package/test-projects/laravel-app/ai-context/schema.json +0 -5
- package/test-projects/laravel-app/ai-context/summary.md +0 -15
- package/test-projects/laravel-app/ai-context/symbols.json +0 -1
- package/test-projects/laravel-app/ai-context/tech_stack.md +0 -34
- package/test-projects/laravel-app/ai-context/tools.json +0 -10
- package/test-projects/nestjs-backend/.ai-dev/index.db +0 -0
- package/test-projects/nestjs-backend/ai-context/ai_context.md +0 -111
- package/test-projects/nestjs-backend/ai-context/ai_rules.md +0 -52
- package/test-projects/nestjs-backend/ai-context/architecture.md +0 -49
- package/test-projects/nestjs-backend/ai-context/cache.json +0 -169
- package/test-projects/nestjs-backend/ai-context/context/features/src.json +0 -23
- package/test-projects/nestjs-backend/ai-context/context/flows/auth.controller.json +0 -14
- package/test-projects/nestjs-backend/ai-context/context/flows/auth.json +0 -10
- package/test-projects/nestjs-backend/ai-context/context/flows/users..json +0 -10
- package/test-projects/nestjs-backend/ai-context/context/flows/users.controller.json +0 -14
- package/test-projects/nestjs-backend/ai-context/context/flows/users.json +0 -10
- package/test-projects/nestjs-backend/ai-context/conventions.md +0 -52
- package/test-projects/nestjs-backend/ai-context/dependencies.json +0 -152
- package/test-projects/nestjs-backend/ai-context/entrypoints.md +0 -18
- package/test-projects/nestjs-backend/ai-context/files.json +0 -209
- package/test-projects/nestjs-backend/ai-context/graph/knowledge-graph.json +0 -132
- package/test-projects/nestjs-backend/ai-context/graph/module-graph.json +0 -29
- package/test-projects/nestjs-backend/ai-context/graph/symbol-graph.json +0 -304
- package/test-projects/nestjs-backend/ai-context/graph/symbol-references.json +0 -5
- package/test-projects/nestjs-backend/ai-context/index-state.json +0 -294
- package/test-projects/nestjs-backend/ai-context/index.db +0 -0
- package/test-projects/nestjs-backend/ai-context/modules.json +0 -19
- package/test-projects/nestjs-backend/ai-context/project.json +0 -18
- package/test-projects/nestjs-backend/ai-context/repo_map.json +0 -427
- package/test-projects/nestjs-backend/ai-context/repo_map.md +0 -104
- package/test-projects/nestjs-backend/ai-context/schema.json +0 -5
- package/test-projects/nestjs-backend/ai-context/summary.md +0 -13
- package/test-projects/nestjs-backend/ai-context/symbols.json +0 -1
- package/test-projects/nestjs-backend/ai-context/tech_stack.md +0 -38
- package/test-projects/nestjs-backend/ai-context/tools.json +0 -10
- package/test-projects/python-cli/.ai-dev/index.db +0 -0
- package/test-projects/python-cli/ai-context/ai_context.md +0 -95
- package/test-projects/python-cli/ai-context/ai_rules.md +0 -47
- package/test-projects/python-cli/ai-context/architecture.md +0 -55
- package/test-projects/python-cli/ai-context/cache.json +0 -149
- package/test-projects/python-cli/ai-context/context/features/cli.json +0 -16
- package/test-projects/python-cli/ai-context/context/flows/list_.json +0 -9
- package/test-projects/python-cli/ai-context/context/flows/remove_.json +0 -9
- package/test-projects/python-cli/ai-context/conventions.md +0 -51
- package/test-projects/python-cli/ai-context/dependencies.json +0 -66
- package/test-projects/python-cli/ai-context/entrypoints.md +0 -4
- package/test-projects/python-cli/ai-context/files.json +0 -184
- package/test-projects/python-cli/ai-context/graph/knowledge-graph.json +0 -83
- package/test-projects/python-cli/ai-context/graph/module-graph.json +0 -31
- package/test-projects/python-cli/ai-context/graph/symbol-graph.json +0 -358
- package/test-projects/python-cli/ai-context/graph/symbol-references.json +0 -11
- package/test-projects/python-cli/ai-context/index-state.json +0 -259
- package/test-projects/python-cli/ai-context/index.db +0 -0
- package/test-projects/python-cli/ai-context/modules.json +0 -21
- package/test-projects/python-cli/ai-context/project.json +0 -15
- package/test-projects/python-cli/ai-context/repo_map.json +0 -367
- package/test-projects/python-cli/ai-context/repo_map.md +0 -93
- package/test-projects/python-cli/ai-context/schema.json +0 -5
- package/test-projects/python-cli/ai-context/summary.md +0 -14
- package/test-projects/python-cli/ai-context/symbols.json +0 -1
- package/test-projects/python-cli/ai-context/tech_stack.md +0 -32
- package/test-projects/python-cli/ai-context/tools.json +0 -10
- package/test-projects/rails-app/.ai-dev/index.db +0 -0
- package/test-projects/rails-app/ai-context/ai_context.md +0 -94
- package/test-projects/rails-app/ai-context/ai_rules.md +0 -47
- package/test-projects/rails-app/ai-context/architecture.md +0 -49
- package/test-projects/rails-app/ai-context/cache.json +0 -193
- package/test-projects/rails-app/ai-context/context/features/app.json +0 -24
- package/test-projects/rails-app/ai-context/context/features/config.json +0 -13
- package/test-projects/rails-app/ai-context/context/flows/application.json +0 -9
- package/test-projects/rails-app/ai-context/context/flows/application_.json +0 -9
- package/test-projects/rails-app/ai-context/context/flows/comments.json +0 -11
- package/test-projects/rails-app/ai-context/context/flows/comments_.json +0 -11
- package/test-projects/rails-app/ai-context/context/flows/posts.json +0 -11
- package/test-projects/rails-app/ai-context/context/flows/posts_.json +0 -11
- package/test-projects/rails-app/ai-context/context/flows/routes.json +0 -9
- package/test-projects/rails-app/ai-context/context/flows/users.json +0 -11
- package/test-projects/rails-app/ai-context/context/flows/users_.json +0 -11
- package/test-projects/rails-app/ai-context/conventions.md +0 -51
- package/test-projects/rails-app/ai-context/dependencies.json +0 -6
- package/test-projects/rails-app/ai-context/entrypoints.md +0 -4
- package/test-projects/rails-app/ai-context/files.json +0 -239
- package/test-projects/rails-app/ai-context/graph/knowledge-graph.json +0 -130
- package/test-projects/rails-app/ai-context/graph/module-graph.json +0 -27
- package/test-projects/rails-app/ai-context/graph/symbol-graph.json +0 -5
- package/test-projects/rails-app/ai-context/graph/symbol-references.json +0 -1
- package/test-projects/rails-app/ai-context/index-state.json +0 -336
- package/test-projects/rails-app/ai-context/index.db +0 -0
- package/test-projects/rails-app/ai-context/modules.json +0 -26
- package/test-projects/rails-app/ai-context/project.json +0 -22
- package/test-projects/rails-app/ai-context/repo_map.json +0 -486
- package/test-projects/rails-app/ai-context/repo_map.md +0 -117
- package/test-projects/rails-app/ai-context/schema.json +0 -5
- package/test-projects/rails-app/ai-context/summary.md +0 -13
- package/test-projects/rails-app/ai-context/symbols.json +0 -1
- package/test-projects/rails-app/ai-context/tech_stack.md +0 -32
- package/test-projects/rails-app/ai-context/tools.json +0 -10
- package/test-projects/react-app/.ai-dev/index.db +0 -0
- package/test-projects/react-app/ai-context/ai_context.md +0 -96
- package/test-projects/react-app/ai-context/ai_rules.md +0 -49
- package/test-projects/react-app/ai-context/architecture.md +0 -39
- package/test-projects/react-app/ai-context/cache.json +0 -153
- package/test-projects/react-app/ai-context/context/features/src.json +0 -18
- package/test-projects/react-app/ai-context/context/flows/UsersPage.json +0 -14
- package/test-projects/react-app/ai-context/context/flows/dashboard.json +0 -9
- package/test-projects/react-app/ai-context/context/flows/login.json +0 -9
- package/test-projects/react-app/ai-context/context/flows/users.json +0 -9
- package/test-projects/react-app/ai-context/conventions.md +0 -52
- package/test-projects/react-app/ai-context/dependencies.json +0 -128
- package/test-projects/react-app/ai-context/entrypoints.md +0 -4
- package/test-projects/react-app/ai-context/files.json +0 -189
- package/test-projects/react-app/ai-context/graph/knowledge-graph.json +0 -112
- package/test-projects/react-app/ai-context/graph/module-graph.json +0 -31
- package/test-projects/react-app/ai-context/graph/symbol-graph.json +0 -868
- package/test-projects/react-app/ai-context/graph/symbol-references.json +0 -31
- package/test-projects/react-app/ai-context/index-state.json +0 -266
- package/test-projects/react-app/ai-context/index.db +0 -0
- package/test-projects/react-app/ai-context/modules.json +0 -17
- package/test-projects/react-app/ai-context/project.json +0 -16
- package/test-projects/react-app/ai-context/repo_map.json +0 -391
- package/test-projects/react-app/ai-context/repo_map.md +0 -94
- package/test-projects/react-app/ai-context/schema.json +0 -5
- package/test-projects/react-app/ai-context/summary.md +0 -13
- package/test-projects/react-app/ai-context/symbols.json +0 -1
- package/test-projects/react-app/ai-context/tech_stack.md +0 -39
- package/test-projects/react-app/ai-context/tools.json +0 -10
- package/test-projects/salesforce-cli/.ai-dev/index.db +0 -0
- package/test-projects/salesforce-cli/ai-context/ai_context.md +0 -89
- package/test-projects/salesforce-cli/ai-context/ai_rules.md +0 -47
- package/test-projects/salesforce-cli/ai-context/architecture.md +0 -39
- package/test-projects/salesforce-cli/ai-context/cache.json +0 -125
- package/test-projects/salesforce-cli/ai-context/context/features/force-app.json +0 -14
- package/test-projects/salesforce-cli/ai-context/context/flows/account.json +0 -9
- package/test-projects/salesforce-cli/ai-context/context/flows/opportunity.json +0 -9
- package/test-projects/salesforce-cli/ai-context/conventions.md +0 -51
- package/test-projects/salesforce-cli/ai-context/dependencies.json +0 -6
- package/test-projects/salesforce-cli/ai-context/entrypoints.md +0 -4
- package/test-projects/salesforce-cli/ai-context/files.json +0 -154
- package/test-projects/salesforce-cli/ai-context/graph/knowledge-graph.json +0 -64
- package/test-projects/salesforce-cli/ai-context/graph/module-graph.json +0 -13
- package/test-projects/salesforce-cli/ai-context/graph/symbol-graph.json +0 -148
- package/test-projects/salesforce-cli/ai-context/graph/symbol-references.json +0 -1
- package/test-projects/salesforce-cli/ai-context/index-state.json +0 -217
- package/test-projects/salesforce-cli/ai-context/index.db +0 -0
- package/test-projects/salesforce-cli/ai-context/modules.json +0 -12
- package/test-projects/salesforce-cli/ai-context/project.json +0 -14
- package/test-projects/salesforce-cli/ai-context/repo_map.json +0 -328
- package/test-projects/salesforce-cli/ai-context/repo_map.md +0 -80
- package/test-projects/salesforce-cli/ai-context/schema.json +0 -5
- package/test-projects/salesforce-cli/ai-context/summary.md +0 -13
- package/test-projects/salesforce-cli/ai-context/symbols.json +0 -1
- package/test-projects/salesforce-cli/ai-context/tech_stack.md +0 -31
- package/test-projects/salesforce-cli/ai-context/tools.json +0 -10
- package/test-projects/spring-boot-app/.ai-dev/index.db +0 -0
- package/test-projects/spring-boot-app/ai-context/ai_context.md +0 -91
- package/test-projects/spring-boot-app/ai-context/ai_rules.md +0 -48
- package/test-projects/spring-boot-app/ai-context/architecture.md +0 -39
- package/test-projects/spring-boot-app/ai-context/cache.json +0 -173
- package/test-projects/spring-boot-app/ai-context/context/features/src.json +0 -26
- package/test-projects/spring-boot-app/ai-context/context/flows/PostController.json +0 -19
- package/test-projects/spring-boot-app/ai-context/context/flows/UserController.json +0 -19
- package/test-projects/spring-boot-app/ai-context/context/flows/comment.json +0 -11
- package/test-projects/spring-boot-app/ai-context/context/flows/post.json +0 -14
- package/test-projects/spring-boot-app/ai-context/context/flows/user.json +0 -14
- package/test-projects/spring-boot-app/ai-context/conventions.md +0 -52
- package/test-projects/spring-boot-app/ai-context/dependencies.json +0 -326
- package/test-projects/spring-boot-app/ai-context/entrypoints.md +0 -4
- package/test-projects/spring-boot-app/ai-context/files.json +0 -214
- package/test-projects/spring-boot-app/ai-context/graph/knowledge-graph.json +0 -231
- package/test-projects/spring-boot-app/ai-context/graph/module-graph.json +0 -22
- package/test-projects/spring-boot-app/ai-context/graph/symbol-graph.json +0 -794
- package/test-projects/spring-boot-app/ai-context/graph/symbol-references.json +0 -70
- package/test-projects/spring-boot-app/ai-context/index-state.json +0 -301
- package/test-projects/spring-boot-app/ai-context/index.db +0 -0
- package/test-projects/spring-boot-app/ai-context/modules.json +0 -21
- package/test-projects/spring-boot-app/ai-context/project.json +0 -17
- package/test-projects/spring-boot-app/ai-context/repo_map.json +0 -461
- package/test-projects/spring-boot-app/ai-context/repo_map.md +0 -109
- package/test-projects/spring-boot-app/ai-context/schema.json +0 -5
- package/test-projects/spring-boot-app/ai-context/summary.md +0 -12
- package/test-projects/spring-boot-app/ai-context/symbols.json +0 -1
- package/test-projects/spring-boot-app/ai-context/tech_stack.md +0 -32
- package/test-projects/spring-boot-app/ai-context/tools.json +0 -10
|
@@ -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
|
+
});
|