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