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
package/src/commands/ai-first.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { generateIndex, IncrementalIndexer, EXAMPLE_QUERIES } from "../core/inde
|
|
|
8
8
|
import { generateAIContext } from "../core/aiContextGenerator.js";
|
|
9
9
|
import { generateHierarchy } from "../core/hierarchyGenerator.js";
|
|
10
10
|
import { ensureDir, writeFile } from "../utils/fileUtils.js";
|
|
11
|
+
import { AI_CONTEXT_DIR, getIndexDbPath, getHierarchyPath } from "../utils/constants.js";
|
|
11
12
|
import { analyzeArchitecture, generateArchitectureFile } from "../analyzers/architecture.js";
|
|
12
13
|
import { detectTechStack, generateTechStackFile } from "../analyzers/techStack.js";
|
|
13
14
|
import { discoverEntrypoints, generateEntrypointsFile } from "../analyzers/entrypoints.js";
|
|
@@ -416,7 +417,7 @@ Usage: ai-first index [options]
|
|
|
416
417
|
|
|
417
418
|
Options:
|
|
418
419
|
-r, --root <dir> Root directory to scan (default: current directory)
|
|
419
|
-
-o, --output <path> Output path for index.db (default: ./ai/index.db)
|
|
420
|
+
-o, --output <path> Output path for index.db (default: ./ai-context/index.db)
|
|
420
421
|
-s, --semantic Force semantic indexing
|
|
421
422
|
-h, --help Show help message
|
|
422
423
|
|
|
@@ -435,7 +436,7 @@ Example queries (for AI agents):
|
|
|
435
436
|
}
|
|
436
437
|
|
|
437
438
|
if (!outputPath) {
|
|
438
|
-
outputPath =
|
|
439
|
+
outputPath = getIndexDbPath(rootDir);
|
|
439
440
|
}
|
|
440
441
|
|
|
441
442
|
const aiDir = path.join(rootDir, "ai-context");
|
|
@@ -489,7 +490,7 @@ Example queries (for AI agents):
|
|
|
489
490
|
const modules: Record<string, { path: string; files: string[] }> = {};
|
|
490
491
|
for (const file of scanResult.files) {
|
|
491
492
|
const parts = file.relativePath.split('/');
|
|
492
|
-
if (parts.length > 1 && parts[0] !== 'ai') {
|
|
493
|
+
if (parts.length > 1 && parts[0] !== AI_CONTEXT_DIR && parts[0] !== 'ai') {
|
|
493
494
|
if (!modules[parts[0]]) modules[parts[0]] = { path: parts[0], files: [] };
|
|
494
495
|
modules[parts[0]].files.push(file.relativePath);
|
|
495
496
|
}
|
|
@@ -543,7 +544,7 @@ Example queries (for AI agents):
|
|
|
543
544
|
|
|
544
545
|
const initSqlJs = (await import("sql.js")).default;
|
|
545
546
|
const SQL = await initSqlJs();
|
|
546
|
-
const dbPath = outputPath ||
|
|
547
|
+
const dbPath = outputPath || getIndexDbPath(rootDir);
|
|
547
548
|
let db: Database;
|
|
548
549
|
if (fs.existsSync(dbPath)) {
|
|
549
550
|
const fileBuffer = fs.readFileSync(dbPath);
|
|
@@ -577,7 +578,7 @@ Example queries (for AI agents):
|
|
|
577
578
|
// Watch command - incremental indexing
|
|
578
579
|
args.shift();
|
|
579
580
|
let rootDir = process.cwd();
|
|
580
|
-
let outputPath =
|
|
581
|
+
let outputPath = getIndexDbPath(rootDir);
|
|
581
582
|
let semanticMode = false;
|
|
582
583
|
let debounceMs = 300;
|
|
583
584
|
|
|
@@ -605,7 +606,7 @@ Usage: ai-first watch [options]
|
|
|
605
606
|
|
|
606
607
|
Options:
|
|
607
608
|
-r, --root <dir> Root directory to watch (default: current directory)
|
|
608
|
-
-o, --output <path> Output path for index.db (default: ./ai/index.db)
|
|
609
|
+
-o, --output <path> Output path for index.db (default: ./ai-context/index.db)
|
|
609
610
|
-d, --debounce <ms> Debounce delay in ms (default: 300)
|
|
610
611
|
-h, --help Show help message
|
|
611
612
|
|
|
@@ -701,7 +702,7 @@ Arguments:
|
|
|
701
702
|
|
|
702
703
|
Options:
|
|
703
704
|
-r, --root <dir> Root directory (default: current directory)
|
|
704
|
-
-o, --output <dir> Output directory (default: ./ai)
|
|
705
|
+
-o, --output <dir> Output directory (default: ./ai-context)
|
|
705
706
|
-d, --depth <n> Graph traversal depth (default: 1)
|
|
706
707
|
-m, --max-symbols <n> Max related symbols (default: 50)
|
|
707
708
|
-f, --format <fmt> Output format: json, markdown, text (default: json)
|
|
@@ -781,7 +782,7 @@ Examples:
|
|
|
781
782
|
// Summarize command - generate hierarchical repository summaries
|
|
782
783
|
args.shift();
|
|
783
784
|
let rootDir = process.cwd();
|
|
784
|
-
let outputPath =
|
|
785
|
+
let outputPath = getHierarchyPath(rootDir);
|
|
785
786
|
|
|
786
787
|
for (let i = 0; i < args.length; i++) {
|
|
787
788
|
const arg = args[i];
|
|
@@ -803,7 +804,7 @@ Usage: ai-first summarize [options]
|
|
|
803
804
|
|
|
804
805
|
Options:
|
|
805
806
|
-r, --root <dir> Root directory (default: current directory)
|
|
806
|
-
-o, --output <path> Output path (default: ./ai/hierarchy.json)
|
|
807
|
+
-o, --output <path> Output path (default: ./ai-context/hierarchy.json)
|
|
807
808
|
-h, --help Show help message
|
|
808
809
|
|
|
809
810
|
Output:
|
|
@@ -834,7 +835,7 @@ Output:
|
|
|
834
835
|
args.shift();
|
|
835
836
|
const queryType = args.shift();
|
|
836
837
|
let rootDir = process.cwd();
|
|
837
|
-
let dbPath =
|
|
838
|
+
let dbPath = getIndexDbPath(rootDir);
|
|
838
839
|
|
|
839
840
|
for (let i = 0; i < args.length; i++) {
|
|
840
841
|
const arg = args[i];
|
|
@@ -842,7 +843,7 @@ Output:
|
|
|
842
843
|
case "--root":
|
|
843
844
|
case "-r":
|
|
844
845
|
rootDir = args[++i];
|
|
845
|
-
dbPath =
|
|
846
|
+
dbPath = getIndexDbPath(rootDir);
|
|
846
847
|
break;
|
|
847
848
|
case "--db":
|
|
848
849
|
case "-d":
|
|
@@ -867,7 +868,7 @@ Subcommands:
|
|
|
867
868
|
|
|
868
869
|
Options:
|
|
869
870
|
-r, --root <dir> Root directory (default: current directory)
|
|
870
|
-
-d, --db <path> Database path (default: ./ai/index.db)
|
|
871
|
+
-d, --db <path> Database path (default: ./ai-context/index.db)
|
|
871
872
|
-h, --help Show help message
|
|
872
873
|
`);
|
|
873
874
|
process.exit(0);
|
|
@@ -1111,7 +1112,7 @@ Commands:
|
|
|
1111
1112
|
|
|
1112
1113
|
Options:
|
|
1113
1114
|
-r, --root <dir> Root directory to scan (default: current directory)
|
|
1114
|
-
-o, --output <dir> Output directory (default: ./ai)
|
|
1115
|
+
-o, --output <dir> Output directory (default: ./ai-context)
|
|
1115
1116
|
-h, --help Show help message
|
|
1116
1117
|
`);
|
|
1117
1118
|
process.exit(0);
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
export interface ArchitecturePattern {
|
|
2
|
+
name: string;
|
|
3
|
+
confidence: number;
|
|
4
|
+
evidence: string[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface Layer {
|
|
8
|
+
name: string;
|
|
9
|
+
files: string[];
|
|
10
|
+
symbols: string[];
|
|
11
|
+
responsibility: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ArchitectureAnalysis {
|
|
15
|
+
primary: ArchitecturePattern | null;
|
|
16
|
+
secondary: ArchitecturePattern[];
|
|
17
|
+
layers: Layer[];
|
|
18
|
+
entryPoints: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface PatternMatcher {
|
|
22
|
+
name: string;
|
|
23
|
+
analyze(
|
|
24
|
+
symbols: Array<{
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
file: string;
|
|
29
|
+
}>,
|
|
30
|
+
dependencyGraph: {
|
|
31
|
+
edges: Array<{ from: string; to: string; type: string }>;
|
|
32
|
+
}
|
|
33
|
+
): { confidence: number; evidence: string[] };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class ArchitectureDetector {
|
|
37
|
+
private patterns: PatternMatcher[] = [
|
|
38
|
+
{
|
|
39
|
+
name: "MVC (Model-View-Controller)",
|
|
40
|
+
analyze: (symbols, graph) => {
|
|
41
|
+
const evidence: string[] = [];
|
|
42
|
+
let score = 0;
|
|
43
|
+
|
|
44
|
+
const controllers = symbols.filter(
|
|
45
|
+
(s) =>
|
|
46
|
+
s.name.toLowerCase().includes("controller") ||
|
|
47
|
+
s.file.toLowerCase().includes("controller")
|
|
48
|
+
);
|
|
49
|
+
const models = symbols.filter(
|
|
50
|
+
(s) =>
|
|
51
|
+
s.name.toLowerCase().includes("model") ||
|
|
52
|
+
s.file.toLowerCase().includes("model")
|
|
53
|
+
);
|
|
54
|
+
const views = symbols.filter(
|
|
55
|
+
(s) =>
|
|
56
|
+
s.name.toLowerCase().includes("view") ||
|
|
57
|
+
s.file.toLowerCase().includes("view")
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (controllers.length > 0) {
|
|
61
|
+
evidence.push(`Found ${controllers.length} controllers`);
|
|
62
|
+
score += 0.3;
|
|
63
|
+
}
|
|
64
|
+
if (models.length > 0) {
|
|
65
|
+
evidence.push(`Found ${models.length} models`);
|
|
66
|
+
score += 0.3;
|
|
67
|
+
}
|
|
68
|
+
if (views.length > 0) {
|
|
69
|
+
evidence.push(`Found ${views.length} views`);
|
|
70
|
+
score += 0.2;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const controllerToModel = graph.edges.some(
|
|
74
|
+
(e) =>
|
|
75
|
+
e.from.toLowerCase().includes("controller") &&
|
|
76
|
+
e.to.toLowerCase().includes("model")
|
|
77
|
+
);
|
|
78
|
+
if (controllerToModel) {
|
|
79
|
+
evidence.push("Controllers import Models");
|
|
80
|
+
score += 0.2;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { confidence: Math.min(score, 1), evidence };
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "Layered Architecture",
|
|
88
|
+
analyze: (symbols, graph) => {
|
|
89
|
+
const evidence: string[] = [];
|
|
90
|
+
let score = 0;
|
|
91
|
+
|
|
92
|
+
const layers = {
|
|
93
|
+
api: symbols.filter(
|
|
94
|
+
(s) =>
|
|
95
|
+
s.name.toLowerCase().includes("controller") ||
|
|
96
|
+
s.name.toLowerCase().includes("route") ||
|
|
97
|
+
s.name.toLowerCase().includes("handler") ||
|
|
98
|
+
s.file.toLowerCase().includes("controller") ||
|
|
99
|
+
s.file.toLowerCase().includes("routes")
|
|
100
|
+
),
|
|
101
|
+
service: symbols.filter(
|
|
102
|
+
(s) =>
|
|
103
|
+
s.name.toLowerCase().includes("service") ||
|
|
104
|
+
s.name.toLowerCase().includes("usecase") ||
|
|
105
|
+
s.file.toLowerCase().includes("service") ||
|
|
106
|
+
s.file.toLowerCase().includes("usecase")
|
|
107
|
+
),
|
|
108
|
+
data: symbols.filter(
|
|
109
|
+
(s) =>
|
|
110
|
+
s.name.toLowerCase().includes("repository") ||
|
|
111
|
+
s.name.toLowerCase().includes("dao") ||
|
|
112
|
+
s.name.toLowerCase().includes("model") ||
|
|
113
|
+
s.file.toLowerCase().includes("repository") ||
|
|
114
|
+
s.file.toLowerCase().includes("model")
|
|
115
|
+
),
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
if (layers.api.length > 0) {
|
|
119
|
+
evidence.push(`API layer: ${layers.api.length} components`);
|
|
120
|
+
score += 0.25;
|
|
121
|
+
}
|
|
122
|
+
if (layers.service.length > 0) {
|
|
123
|
+
evidence.push(`Service layer: ${layers.service.length} components`);
|
|
124
|
+
score += 0.25;
|
|
125
|
+
}
|
|
126
|
+
if (layers.data.length > 0) {
|
|
127
|
+
evidence.push(`Data layer: ${layers.data.length} components`);
|
|
128
|
+
score += 0.25;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const hasFlow =
|
|
132
|
+
layers.api.some((api) =>
|
|
133
|
+
graph.edges.some(
|
|
134
|
+
(e) =>
|
|
135
|
+
e.from === api.id &&
|
|
136
|
+
layers.service.some((s) => s.id === e.to)
|
|
137
|
+
)
|
|
138
|
+
) ||
|
|
139
|
+
layers.service.some((svc) =>
|
|
140
|
+
graph.edges.some(
|
|
141
|
+
(e) =>
|
|
142
|
+
e.from === svc.id &&
|
|
143
|
+
layers.data.some((d) => d.id === e.to)
|
|
144
|
+
)
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
if (hasFlow) {
|
|
148
|
+
evidence.push("Layer flow detected: API → Service → Data");
|
|
149
|
+
score += 0.25;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return { confidence: Math.min(score, 1), evidence };
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "Clean Architecture",
|
|
157
|
+
analyze: (symbols, graph) => {
|
|
158
|
+
const evidence: string[] = [];
|
|
159
|
+
let score = 0;
|
|
160
|
+
|
|
161
|
+
const entities = symbols.filter(
|
|
162
|
+
(s) =>
|
|
163
|
+
s.file.toLowerCase().includes("entity") ||
|
|
164
|
+
s.file.toLowerCase().includes("domain")
|
|
165
|
+
);
|
|
166
|
+
const useCases = symbols.filter(
|
|
167
|
+
(s) =>
|
|
168
|
+
s.file.toLowerCase().includes("usecase") ||
|
|
169
|
+
s.file.toLowerCase().includes("interactor")
|
|
170
|
+
);
|
|
171
|
+
const interfaces = symbols.filter(
|
|
172
|
+
(s) =>
|
|
173
|
+
s.file.toLowerCase().includes("interface") ||
|
|
174
|
+
s.file.toLowerCase().includes("adapter")
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
if (entities.length > 0) {
|
|
178
|
+
evidence.push(`Entities layer: ${entities.length} components`);
|
|
179
|
+
score += 0.3;
|
|
180
|
+
}
|
|
181
|
+
if (useCases.length > 0) {
|
|
182
|
+
evidence.push(`Use Cases layer: ${useCases.length} components`);
|
|
183
|
+
score += 0.3;
|
|
184
|
+
}
|
|
185
|
+
if (interfaces.length > 0) {
|
|
186
|
+
evidence.push(`Interface Adapters: ${interfaces.length} components`);
|
|
187
|
+
score += 0.2;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const dependencyRule =
|
|
191
|
+
!graph.edges.some(
|
|
192
|
+
(e) =>
|
|
193
|
+
entities.some((ent) => ent.id === e.from) &&
|
|
194
|
+
useCases.some((uc) => uc.id === e.to)
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
if (dependencyRule && entities.length > 0) {
|
|
198
|
+
evidence.push("Dependency Rule: Entities have no external dependencies");
|
|
199
|
+
score += 0.2;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return { confidence: Math.min(score, 1), evidence };
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: "Hexagonal Architecture (Ports & Adapters)",
|
|
207
|
+
analyze: (symbols, graph) => {
|
|
208
|
+
const evidence: string[] = [];
|
|
209
|
+
let score = 0;
|
|
210
|
+
|
|
211
|
+
const ports = symbols.filter(
|
|
212
|
+
(s) =>
|
|
213
|
+
s.name.toLowerCase().includes("port") ||
|
|
214
|
+
s.file.toLowerCase().includes("port")
|
|
215
|
+
);
|
|
216
|
+
const adapters = symbols.filter(
|
|
217
|
+
(s) =>
|
|
218
|
+
s.name.toLowerCase().includes("adapter") ||
|
|
219
|
+
s.file.toLowerCase().includes("adapter")
|
|
220
|
+
);
|
|
221
|
+
const domain = symbols.filter(
|
|
222
|
+
(s) =>
|
|
223
|
+
s.file.toLowerCase().includes("domain") ||
|
|
224
|
+
(!s.file.toLowerCase().includes("adapter") &&
|
|
225
|
+
!s.file.toLowerCase().includes("port"))
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
if (ports.length > 0) {
|
|
229
|
+
evidence.push(`Ports: ${ports.length} interfaces`);
|
|
230
|
+
score += 0.3;
|
|
231
|
+
}
|
|
232
|
+
if (adapters.length > 0) {
|
|
233
|
+
evidence.push(`Adapters: ${adapters.length} implementations`);
|
|
234
|
+
score += 0.3;
|
|
235
|
+
}
|
|
236
|
+
if (domain.length > 0) {
|
|
237
|
+
evidence.push(`Domain: ${domain.length} components`);
|
|
238
|
+
score += 0.2;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const portImplementations = adapters.some((adapter) =>
|
|
242
|
+
graph.edges.some(
|
|
243
|
+
(e) =>
|
|
244
|
+
e.from === adapter.id &&
|
|
245
|
+
ports.some((p) => e.to.includes(p.name))
|
|
246
|
+
)
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
if (portImplementations) {
|
|
250
|
+
evidence.push("Adapters implement Ports");
|
|
251
|
+
score += 0.2;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return { confidence: Math.min(score, 1), evidence };
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "Microservices",
|
|
259
|
+
analyze: (symbols, graph) => {
|
|
260
|
+
const evidence: string[] = [];
|
|
261
|
+
let score = 0;
|
|
262
|
+
|
|
263
|
+
const services = symbols.filter(
|
|
264
|
+
(s) =>
|
|
265
|
+
s.name.toLowerCase().includes("service") ||
|
|
266
|
+
s.file.toLowerCase().includes("service")
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
const independentServices = services.filter((svc) => {
|
|
270
|
+
const dependencies = graph.edges.filter((e) => e.from === svc.id);
|
|
271
|
+
return dependencies.length <= 3;
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
if (services.length >= 3) {
|
|
275
|
+
evidence.push(`Found ${services.length} services`);
|
|
276
|
+
score += 0.3;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (independentServices.length / services.length > 0.5) {
|
|
280
|
+
evidence.push("Services are loosely coupled");
|
|
281
|
+
score += 0.3;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const noCycles = this.hasNoCircularDependencies(graph);
|
|
285
|
+
if (noCycles && services.length > 0) {
|
|
286
|
+
evidence.push("No circular dependencies between services");
|
|
287
|
+
score += 0.2;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return { confidence: Math.min(score, 1), evidence };
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
];
|
|
294
|
+
|
|
295
|
+
detect(
|
|
296
|
+
symbols: Array<{
|
|
297
|
+
id: string;
|
|
298
|
+
name: string;
|
|
299
|
+
type: string;
|
|
300
|
+
file: string;
|
|
301
|
+
}>,
|
|
302
|
+
dependencyGraph: {
|
|
303
|
+
edges: Array<{ from: string; to: string; type: string }>;
|
|
304
|
+
}
|
|
305
|
+
): ArchitectureAnalysis {
|
|
306
|
+
const results: ArchitecturePattern[] = [];
|
|
307
|
+
|
|
308
|
+
for (const pattern of this.patterns) {
|
|
309
|
+
const result = pattern.analyze(symbols, dependencyGraph);
|
|
310
|
+
if (result.confidence > 0.3) {
|
|
311
|
+
results.push({
|
|
312
|
+
name: pattern.name,
|
|
313
|
+
confidence: result.confidence,
|
|
314
|
+
evidence: result.evidence,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
results.sort((a, b) => b.confidence - a.confidence);
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
primary: results[0] || null,
|
|
323
|
+
secondary: results.slice(1),
|
|
324
|
+
layers: this.detectLayers(symbols),
|
|
325
|
+
entryPoints: this.detectEntryPoints(symbols),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
private detectLayers(
|
|
330
|
+
symbols: Array<{
|
|
331
|
+
id: string;
|
|
332
|
+
name: string;
|
|
333
|
+
type: string;
|
|
334
|
+
file: string;
|
|
335
|
+
}>
|
|
336
|
+
): Layer[] {
|
|
337
|
+
const layers: Layer[] = [];
|
|
338
|
+
|
|
339
|
+
const apiLayer = {
|
|
340
|
+
name: "API / Presentation",
|
|
341
|
+
files: [] as string[],
|
|
342
|
+
symbols: [] as string[],
|
|
343
|
+
responsibility: "HTTP request handling, routing, validation",
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const serviceLayer = {
|
|
347
|
+
name: "Service / Business Logic",
|
|
348
|
+
files: [] as string[],
|
|
349
|
+
symbols: [] as string[],
|
|
350
|
+
responsibility: "Business rules, use cases, workflows",
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const dataLayer = {
|
|
354
|
+
name: "Data / Persistence",
|
|
355
|
+
files: [] as string[],
|
|
356
|
+
symbols: [] as string[],
|
|
357
|
+
responsibility: "Database access, queries, caching",
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
for (const symbol of symbols) {
|
|
361
|
+
const name = symbol.name.toLowerCase();
|
|
362
|
+
const file = symbol.file.toLowerCase();
|
|
363
|
+
|
|
364
|
+
if (
|
|
365
|
+
name.includes("controller") ||
|
|
366
|
+
name.includes("route") ||
|
|
367
|
+
name.includes("handler") ||
|
|
368
|
+
name.includes("endpoint") ||
|
|
369
|
+
file.includes("controller") ||
|
|
370
|
+
file.includes("routes") ||
|
|
371
|
+
file.includes("api")
|
|
372
|
+
) {
|
|
373
|
+
if (!apiLayer.files.includes(symbol.file)) {
|
|
374
|
+
apiLayer.files.push(symbol.file);
|
|
375
|
+
}
|
|
376
|
+
apiLayer.symbols.push(symbol.id);
|
|
377
|
+
} else if (
|
|
378
|
+
name.includes("service") ||
|
|
379
|
+
name.includes("usecase") ||
|
|
380
|
+
name.includes("manager") ||
|
|
381
|
+
name.includes("handler") ||
|
|
382
|
+
file.includes("service") ||
|
|
383
|
+
file.includes("usecase") ||
|
|
384
|
+
file.includes("business")
|
|
385
|
+
) {
|
|
386
|
+
if (!serviceLayer.files.includes(symbol.file)) {
|
|
387
|
+
serviceLayer.files.push(symbol.file);
|
|
388
|
+
}
|
|
389
|
+
serviceLayer.symbols.push(symbol.id);
|
|
390
|
+
} else if (
|
|
391
|
+
name.includes("repository") ||
|
|
392
|
+
name.includes("dao") ||
|
|
393
|
+
name.includes("model") ||
|
|
394
|
+
name.includes("entity") ||
|
|
395
|
+
file.includes("repository") ||
|
|
396
|
+
file.includes("model") ||
|
|
397
|
+
file.includes("data") ||
|
|
398
|
+
file.includes("db")
|
|
399
|
+
) {
|
|
400
|
+
if (!dataLayer.files.includes(symbol.file)) {
|
|
401
|
+
dataLayer.files.push(symbol.file);
|
|
402
|
+
}
|
|
403
|
+
dataLayer.symbols.push(symbol.id);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (apiLayer.symbols.length > 0) layers.push(apiLayer);
|
|
408
|
+
if (serviceLayer.symbols.length > 0) layers.push(serviceLayer);
|
|
409
|
+
if (dataLayer.symbols.length > 0) layers.push(dataLayer);
|
|
410
|
+
|
|
411
|
+
return layers;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
private detectEntryPoints(
|
|
415
|
+
symbols: Array<{
|
|
416
|
+
id: string;
|
|
417
|
+
name: string;
|
|
418
|
+
type: string;
|
|
419
|
+
file: string;
|
|
420
|
+
}>
|
|
421
|
+
): string[] {
|
|
422
|
+
const entryPoints: string[] = [];
|
|
423
|
+
|
|
424
|
+
const patterns = [
|
|
425
|
+
/main$/i,
|
|
426
|
+
/index$/i,
|
|
427
|
+
/init$/i,
|
|
428
|
+
/start$/i,
|
|
429
|
+
/server$/i,
|
|
430
|
+
/app$/i,
|
|
431
|
+
/bootstrap$/i,
|
|
432
|
+
/handler$/i,
|
|
433
|
+
/controller$/i,
|
|
434
|
+
];
|
|
435
|
+
|
|
436
|
+
for (const symbol of symbols) {
|
|
437
|
+
const name = symbol.name.toLowerCase();
|
|
438
|
+
const file = symbol.file.toLowerCase();
|
|
439
|
+
|
|
440
|
+
if (
|
|
441
|
+
patterns.some((p) => p.test(name)) ||
|
|
442
|
+
file.includes("main.") ||
|
|
443
|
+
file.includes("index.") ||
|
|
444
|
+
file.includes("app.") ||
|
|
445
|
+
file.includes("server.")
|
|
446
|
+
) {
|
|
447
|
+
entryPoints.push(symbol.id);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return [...new Set(entryPoints)];
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
private hasNoCircularDependencies(graph: {
|
|
455
|
+
edges: Array<{ from: string; to: string; type: string }>;
|
|
456
|
+
}): boolean {
|
|
457
|
+
const nodes = [...new Set(graph.edges.flatMap((e) => [e.from, e.to]))];
|
|
458
|
+
const visited = new Set<string>();
|
|
459
|
+
const recursionStack = new Set<string>();
|
|
460
|
+
|
|
461
|
+
const dfs = (node: string): boolean => {
|
|
462
|
+
if (recursionStack.has(node)) return false;
|
|
463
|
+
if (visited.has(node)) return true;
|
|
464
|
+
|
|
465
|
+
visited.add(node);
|
|
466
|
+
recursionStack.add(node);
|
|
467
|
+
|
|
468
|
+
const outgoing = graph.edges.filter((e) => e.from === node);
|
|
469
|
+
for (const edge of outgoing) {
|
|
470
|
+
if (!dfs(edge.to)) return false;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
recursionStack.delete(node);
|
|
474
|
+
return true;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
for (const node of nodes) {
|
|
478
|
+
if (!visited.has(node)) {
|
|
479
|
+
if (!dfs(node)) return false;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export const architectureDetector = new ArchitectureDetector();
|